@chainingintention/pi-web-cn 1.202606.10 → 1.202606.12
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.
- package/README.md +12 -5
- package/dist/cli.js +14 -2
- package/dist/cli.js.map +1 -1
- package/dist/client/assets/{CodeViewer-YNyWxbqH.js → CodeViewer-BKljKDuK.js} +1 -1
- package/dist/client/assets/{TerminalPanel-B9UStXy9.js → TerminalPanel-DeDTQWls.js} +1 -1
- package/dist/client/assets/index-BuVYTYo8.js +2315 -0
- package/dist/client/index.html +1 -1
- package/dist/config.js +28 -3
- package/dist/config.js.map +1 -1
- package/dist/pi-web-plugins/updates/package.json +1 -1
- package/dist/pi-web-plugins/updates/pi-web-plugin.js +61 -71
- package/dist/pi-web-plugins/updates/updatesLogic.js +65 -0
- package/dist/server/app.js +14 -6
- package/dist/server/app.js.map +1 -1
- package/dist/server/index.js +2 -2
- package/dist/server/index.js.map +1 -1
- package/dist/server/machines/machinePluginProxyRoutes.js +8 -0
- package/dist/server/machines/machinePluginProxyRoutes.js.map +1 -1
- package/dist/server/machines/machineRoutes.js +6 -0
- package/dist/server/machines/machineRoutes.js.map +1 -1
- package/dist/server/machines/machineService.js +97 -5
- package/dist/server/machines/machineService.js.map +1 -1
- package/dist/server/piWebPluginService.js +24 -4
- package/dist/server/piWebPluginService.js.map +1 -1
- package/dist/server/piWebStatus.js +149 -45
- package/dist/server/piWebStatus.js.map +1 -1
- package/dist/server/piWebStatusCache.js +32 -0
- package/dist/server/piWebStatusCache.js.map +1 -0
- package/dist/server/sessiond/sessionProxyRoutes.js +15 -1
- package/dist/server/sessiond/sessionProxyRoutes.js.map +1 -1
- package/dist/server/sessiond.js +20 -8
- package/dist/server/sessiond.js.map +1 -1
- package/dist/server/sessions/attachmentService.js +61 -0
- package/dist/server/sessions/attachmentService.js.map +1 -0
- package/dist/server/sessions/oauthLoginFlowService.js +7 -0
- package/dist/server/sessions/oauthLoginFlowService.js.map +1 -1
- package/dist/server/sessions/piSessionManagerGateway.js +96 -0
- package/dist/server/sessions/piSessionManagerGateway.js.map +1 -0
- package/dist/server/sessions/piSessionService.js +211 -383
- package/dist/server/sessions/piSessionService.js.map +1 -1
- package/dist/server/sessions/sessionArchiveStore.js +16 -2
- package/dist/server/sessions/sessionArchiveStore.js.map +1 -1
- package/dist/server/sessions/sessionRoutes.js +156 -43
- package/dist/server/sessions/sessionRoutes.js.map +1 -1
- package/dist/server/terminals/terminalRoutes.js +10 -4
- package/dist/server/terminals/terminalRoutes.js.map +1 -1
- package/dist/server/workingDirectory.js +44 -0
- package/dist/server/workingDirectory.js.map +1 -0
- package/dist/server/workspaces/fileSuggestions.js +96 -16
- package/dist/server/workspaces/fileSuggestions.js.map +1 -1
- package/dist/shared/apiTypes.d.ts +81 -4
- package/dist/shared/apiTypes.js +5 -1
- package/dist/shared/apiTypes.js.map +1 -1
- package/dist/shared/capabilities.js +27 -0
- package/dist/shared/capabilities.js.map +1 -0
- package/dist/shared/federatedRoutes.js +3 -0
- package/dist/shared/federatedRoutes.js.map +1 -1
- package/dist/shared/piWebStatusParsing.js +28 -0
- package/dist/shared/piWebStatusParsing.js.map +1 -1
- package/dist/shared/promptAttachments.js +73 -0
- package/dist/shared/promptAttachments.js.map +1 -0
- package/dist/shared/thinkingLevels.d.ts +27 -0
- package/dist/shared/thinkingLevels.js +31 -0
- package/dist/shared/thinkingLevels.js.map +1 -0
- package/dist/shared/workspaceDeletion.js +1 -1
- package/dist/shared/workspaceDeletion.js.map +1 -1
- package/docs/plugins.md +14 -7
- package/package.json +23 -13
- package/dist/client/assets/index-BH7nkPuT.js +0 -2172
- package/dist/server/sessions/managementPermissionSystem.js +0 -94
- package/dist/server/sessions/managementPermissionSystem.js.map +0 -1
|
@@ -0,0 +1,2315 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/CodeViewer-BKljKDuK.js","assets/vendor-editor-core-B4Sq6exx.js","assets/vendor-editor-languages-DznYbTkJ.js","assets/vendor-editor-legacy-B4QLsWF8.js","assets/TerminalPanel-DeDTQWls.js","assets/vendor-terminal-DjQ08hXu.js","assets/vendor-terminal-DDGTF8rc.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{Q as Po,w as st,J as Hi,R as Ka,S as Va,G as Ga,U as Ja,V as Qa,A as Za,W as Xa,X as Ya,Y as ec,Z as Ro,x as Io,_ as tc}from"./vendor-editor-core-B4Sq6exx.js";import{m as ic,i as sc,d as oc}from"./vendor-editor-languages-DznYbTkJ.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 ii=globalThis,Fs=ii.ShadowRoot&&(ii.ShadyCSS===void 0||ii.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,Ns=Symbol(),Co=new WeakMap;let dn=class{constructor(t,i,s){if(this._$cssResult$=!0,s!==Ns)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(Fs&&t===void 0){const s=i!==void 0&&i.length===1;s&&(t=Co.get(i)),t===void 0&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),s&&Co.set(i,t))}return t}toString(){return this.cssText}};const rc=e=>new dn(typeof e=="string"?e:e+"",void 0,Ns),O=(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 dn(i,e,Ns)},nc=(e,t)=>{if(Fs)e.adoptedStyleSheets=t.map(i=>i instanceof CSSStyleSheet?i:i.styleSheet);else for(const i of t){const s=document.createElement("style"),o=ii.litNonce;o!==void 0&&s.setAttribute("nonce",o),s.textContent=i.cssText,e.appendChild(s)}},To=Fs?e=>e:e=>e instanceof CSSStyleSheet?(t=>{let i="";for(const s of t.cssRules)i+=s.cssText;return rc(i)})(e):e;const{is:ac,defineProperty:cc,getOwnPropertyDescriptor:lc,getOwnPropertyNames:dc,getOwnPropertySymbols:pc,getPrototypeOf:hc}=Object,Ai=globalThis,Mo=Ai.trustedTypes,uc=Mo?Mo.emptyScript:"",fc=Ai.reactiveElementPolyfillSupport,It=(e,t)=>e,li={toAttribute(e,t){switch(t){case Boolean:e=e?uc: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}},zs=(e,t)=>!ac(e,t),Ao={attribute:!0,type:String,converter:li,reflect:!1,useDefault:!1,hasChanged:zs};Symbol.metadata??=Symbol("metadata"),Ai.litPropertyMetadata??=new WeakMap;let nt=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=Ao){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&&cc(this.prototype,t,o)}}static getPropertyDescriptor(t,i,s){const{get:o,set:r}=lc(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)??Ao}static _$Ei(){if(this.hasOwnProperty(It("elementProperties")))return;const t=hc(this);t.finalize(),t.l!==void 0&&(this.l=[...t.l]),this.elementProperties=new Map(t.elementProperties)}static finalize(){if(this.hasOwnProperty(It("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(It("properties"))){const i=this.properties,s=[...dc(i),...pc(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(To(o))}else t!==void 0&&i.push(To(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 nc(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:li).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:li;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??zs)(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){}};nt.elementStyles=[],nt.shadowRootOptions={mode:"open"},nt[It("elementProperties")]=new Map,nt[It("finalized")]=new Map,fc?.({ReactiveElement:nt}),(Ai.reactiveElementVersions??=[]).push("2.1.2");const Bs=globalThis,Eo=e=>e,di=Bs.trustedTypes,Do=di?di.createPolicy("lit-html",{createHTML:e=>e}):void 0,pn="$lit$",ze=`lit$${Math.random().toFixed(9).slice(2)}$`,hn="?"+ze,gc=`<${hn}>`,Je=document,Mt=()=>Je.createComment(""),At=e=>e===null||typeof e!="object"&&typeof e!="function",Us=Array.isArray,mc=e=>Us(e)||typeof e?.[Symbol.iterator]=="function",qi=`[
|
|
3
|
+
\f\r]`,mt=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,Wo=/-->/g,Oo=/>/g,Ue=RegExp(`>|${qi}(?:([^\\s"'>=/]+)(${qi}*=${qi}*(?:[^
|
|
4
|
+
\f\r"'\`<>=]|("|')|))|$)`,"g"),_o=/'/g,Lo=/"/g,un=/^(?:script|style|textarea|title)$/i,fn=e=>(t,...i)=>({_$litType$:e,strings:t,values:i}),c=fn(1),ue=fn(2),Be=Symbol.for("lit-noChange"),F=Symbol.for("lit-nothing"),jo=new WeakMap,Ve=Je.createTreeWalker(Je,129);function gn(e,t){if(!Us(e)||!e.hasOwnProperty("raw"))throw Error("invalid template strings array");return Do!==void 0?Do.createHTML(t):t}const vc=(e,t)=>{const i=e.length-1,s=[];let o,r=t===2?"<svg>":t===3?"<math>":"",n=mt;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===mt?u[1]==="!--"?n=Wo:u[1]!==void 0?n=Oo:u[2]!==void 0?(un.test(u[2])&&(o=RegExp("</"+u[2],"g")),n=Ue):u[3]!==void 0&&(n=Ue):n===Ue?u[0]===">"?(n=o??mt,h=-1):u[1]===void 0?h=-2:(h=n.lastIndex-u[2].length,p=u[1],n=u[3]===void 0?Ue:u[3]==='"'?Lo:_o):n===Lo||n===_o?n=Ue:n===Wo||n===Oo?n=mt:(n=Ue,o=void 0);const w=n===Ue&&e[a+1].startsWith("/>")?" ":"";r+=n===mt?l+gc:h>=0?(s.push(p),l.slice(0,h)+pn+l.slice(h)+ze+w):l+ze+(h===-2?a:w)}return[gn(e,r+(e[i]||"<?>")+(t===2?"</svg>":t===3?"</math>":"")),s]};class Et{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]=vc(t,i);if(this.el=Et.createElement(p,s),Ve.currentNode=this.el.content,i===2||i===3){const h=this.el.content.firstChild;h.replaceWith(...h.childNodes)}for(;(o=Ve.nextNode())!==null&&l.length<a;){if(o.nodeType===1){if(o.hasAttributes())for(const h of o.getAttributeNames())if(h.endsWith(pn)){const g=u[n++],w=o.getAttribute(h).split(ze),P=/([.?@])?(.*)/.exec(g);l.push({type:1,index:r,name:P[2],strings:w,ctor:P[1]==="."?wc:P[1]==="?"?yc:P[1]==="@"?Sc:Ei}),o.removeAttribute(h)}else h.startsWith(ze)&&(l.push({type:6,index:r}),o.removeAttribute(h));if(un.test(o.tagName)){const h=o.textContent.split(ze),g=h.length-1;if(g>0){o.textContent=di?di.emptyScript:"";for(let w=0;w<g;w++)o.append(h[w],Mt()),Ve.nextNode(),l.push({type:2,index:++r});o.append(h[g],Mt())}}}else if(o.nodeType===8)if(o.data===hn)l.push({type:2,index:r});else{let h=-1;for(;(h=o.data.indexOf(ze,h+1))!==-1;)l.push({type:7,index:r}),h+=ze.length-1}r++}}static createElement(t,i){const s=Je.createElement("template");return s.innerHTML=t,s}}function ct(e,t,i=e,s){if(t===Be)return t;let o=s!==void 0?i._$Co?.[s]:i._$Cl;const r=At(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=ct(e,o._$AS(e,t.values),o,s)),t}class bc{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??Je).importNode(i,!0);Ve.currentNode=o;let r=Ve.nextNode(),n=0,a=0,l=s[0];for(;l!==void 0;){if(n===l.index){let p;l.type===2?p=new pt(r,r.nextSibling,this,t):l.type===1?p=new l.ctor(r,l.name,l.strings,this,t):l.type===6&&(p=new xc(r,this,t)),this._$AV.push(p),l=s[++a]}n!==l?.index&&(r=Ve.nextNode(),n++)}return Ve.currentNode=Je,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 pt{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=ct(this,t,i),At(t)?t===F||t==null||t===""?(this._$AH!==F&&this._$AR(),this._$AH=F):t!==this._$AH&&t!==Be&&this._(t):t._$litType$!==void 0?this.$(t):t.nodeType!==void 0?this.T(t):mc(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&&At(this._$AH)?this._$AA.nextSibling.data=t:this.T(Je.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=Et.createElement(gn(s.h,s.h[0]),this.options)),s);if(this._$AH?._$AD===o)this._$AH.p(i);else{const r=new bc(o,this),n=r.u(this.options);r.p(i),this.T(n),this._$AH=r}}_$AC(t){let i=jo.get(t.strings);return i===void 0&&jo.set(t.strings,i=new Et(t)),i}k(t){Us(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 pt(this.O(Mt()),this.O(Mt()),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=Eo(t).nextSibling;Eo(t).remove(),t=s}}setConnected(t){this._$AM===void 0&&(this._$Cv=t,this._$AP?.(t))}}let Ei=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=ct(this,t,i,0),n=!At(t)||t!==this._$AH&&t!==Be,n&&(this._$AH=t);else{const a=t;let l,p;for(t=r[0],l=0;l<r.length-1;l++)p=ct(this,a[s+l],i,l),p===Be&&(p=this._$AH[l]),n||=!At(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??"")}},wc=class extends Ei{constructor(){super(...arguments),this.type=3}j(t){this.element[this.name]=t===F?void 0:t}},yc=class extends Ei{constructor(){super(...arguments),this.type=4}j(t){this.element.toggleAttribute(this.name,!!t&&t!==F)}},Sc=class extends Ei{constructor(t,i,s,o,r){super(t,i,s,o,r),this.type=5}_$AI(t,i=this){if((t=ct(this,t,i,0)??F)===Be)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)}};class xc{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){ct(this,t)}}const kc={I:pt},$c=Bs.litHtmlPolyfillSupport;$c?.(Et,pt),(Bs.litHtmlVersions??=[]).push("3.3.2");const Pc=(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 pt(t.insertBefore(Mt(),r),r,void 0,i??{})}return o._$AI(e),o};const Hs=globalThis;let M=class extends nt{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=Pc(i,this.renderRoot,this.renderOptions)}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(!0)}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(!1)}render(){return Be}};M._$litElement$=!0,M.finalized=!0,Hs.litElementHydrateSupport?.({LitElement:M});const Rc=Hs.litElementPolyfillSupport;Rc?.({LitElement:M});(Hs.litElementVersions??=[]).push("4.2.2");const D=e=>(t,i)=>{i!==void 0?i.addInitializer(()=>{customElements.define(e,t)}):customElements.define(e,t)};const Ic={attribute:!0,type:String,converter:li,reflect:!1,hasChanged:zs},Cc=(e=Ic,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"?Cc(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 y(e){return d({...e,state:!0,attribute:!1})}const Tc=(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 Tc(i,s,{get(){return r(this)}})}}function mn(e,t=Ac()){if(t===void 0)return e;const i=Mc(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 Mc(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 Ac(){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(mn(e),{...i,headers:s});if(!o.ok){const n=await o.json().catch(()=>({}));throw new Error(Ec(n)??o.statusText)}const r=await o.json();return t(r)}function Ec(e){if(Dc(e))return typeof e.error=="string"?e.error:void 0}function Dc(e){return typeof e=="object"&&e!==null}const lt={sessionsDeleteArchived:"sessions.deleteArchived",sessionsReload:"sessions.reload",promptAttachments:"prompt.attachments"},Wc=Object.values(lt),Oc=new Set(Wc);function _c(e){return typeof e=="string"&&Oc.has(e)}function Dt(e,t){return e?.capabilities?.includes(t)===!0}function Ct(e){return typeof e=="object"&&e!==null}function b(e){if(!Ct(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 W(e,t){const i=e[t];if(typeof i!="boolean")throw new Error(`Expected boolean field: ${t}`);return i}function N(e){return t=>{if(!Array.isArray(t))throw new Error("Expected array response");return t.map(e)}}function Lc(e){if(!Array.isArray(e))throw new Error("Expected array response");return e}function jc(e,t){if(!Array.isArray(e)||!e.every(i=>typeof i=="string"))throw new Error(`Expected string array field: ${t}`);return e}function Fc(e){if(Array.isArray(e))return{messages:e,start:0,total:e.length};const t=b(e);return{messages:Lc(t.messages),start:se(t,"start"),total:se(t,"total")}}function Nc(e){const t=b(e);return N(vn)(t.machines)}function vn(e){const t=b(e),i=Uc(t,"kind"),s=$(t,"baseUrl"),o=bn(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 zc(e){const t=b(e),i=bn(t,"status"),s=$(t,"error");return{machineId:m(t,"machineId"),ok:W(t,"ok"),checkedAt:m(t,"checkedAt"),...i===void 0?{}:{status:i},...t.web===void 0?{}:{web:pi(t.web)},...t.sessiond===void 0?{}:{sessiond:pi(t.sessiond)},...s===void 0?{}:{error:s}}}function Bc(e){const t=b(e),i=$(t,"error");return{machineId:m(t,"machineId"),ok:W(t,"ok"),checkedAt:m(t,"checkedAt"),...S("packageName",$(t,"packageName")),...S("generatedAt",$(t,"generatedAt")),...t.components===void 0?{}:{components:Sn(t.components)},...t.capabilities===void 0?{}:{capabilities:qs(t.capabilities)},...i===void 0?{}:{error:i}}}function Uc(e,t){const i=m(e,t);if(i!=="local"&&i!=="remote")throw new Error(`Expected machine kind field: ${t}`);return i}function bn(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 Fo(e){const t=b(e);return{id:m(t,"id"),name:m(t,"name"),path:m(t,"path"),createdAt:m(t,"createdAt")}}function Hc(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:W(t,"isMain"),isGitRepo:W(t,"isGitRepo"),isGitWorktree:W(t,"isGitWorktree")}}function bs(e){const t=b(e);return{path:m(t,"path"),size:se(t,"size"),modifiedAt:m(t,"modifiedAt")}}function Ki(e){const t=b(e);return{path:m(t,"path")}}function No(e){const t=b(e);if(t.deleted!==!0)throw new Error("Expected deleted response");return{deleted:!0,path:m(t,"path")}}function ws(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 vt(e){const t=b(e);return{sessionId:m(t,"sessionId"),isStreaming:W(t,"isStreaming"),isCompacting:W(t,"isCompacting"),isBashRunning:W(t,"isBashRunning"),pendingMessageCount:se(t,"pendingMessageCount"),queuedMessages:t.queuedMessages===void 0?[]:N(qc)(t.queuedMessages),...S("messageCount",Re(t,"messageCount")),tokens:Kc(t.tokens),cost:se(t,"cost"),...Jc(t.model),...cl(t.contextUsage),...S("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"),...S("imageCount",Re(t,"imageCount"))}}function Kc(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 wn(e){const t=b(e);return{...S("provider",$(t,"provider")),...S("id",$(t,"id")),...S("name",$(t,"name")),...S("contextWindow",Re(t,"contextWindow")),...S("reasoning",t.reasoning),...S("input",Vc(t.input))}}function Vc(e){if(e!==void 0){if(!Array.isArray(e))throw new Error("Invalid model input");return e.map(Gc)}}function Gc(e){if(e==="text"||e==="image")return e;throw new Error("Invalid model input")}function Jc(e){return e===void 0?{}:{model:wn(e)}}function Qc(e){const t=b(e);return{models:N(wn)(t.models)}}function Zc(e){if(typeof e!="string")throw new Error("Invalid thinking level");return e}function Xc(e){const t=b(e);return{levels:N(Zc)(t.levels)}}function Yc(e){if(e!=="oauth"&&e!=="api_key")throw new Error("Invalid auth type");return e}function el(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 tl(e){const t=b(e),i=t.source===void 0?void 0:el(t.source);return{configured:W(t,"configured"),...S("source",i),...S("label",$(t,"label"))}}function il(e){const t=b(e);return{id:m(t,"id"),name:m(t,"name"),authType:Yc(t.authType),status:tl(t.status)}}function sl(e){const t=b(e);return{providers:N(il)(t.providers)}}function qt(e){const t=b(e);return{flowId:m(t,"flowId"),providerId:m(t,"providerId"),providerName:m(t,"providerName"),status:ol(t.status),progress:N(s=>{if(typeof s!="string")throw new Error("Expected progress item string");return s})(t.progress),...S("error",$(t,"error")),...S("auth",rl(t.auth)),...S("prompt",nl(t.prompt)),...S("select",al(t.select))}}function ol(e){if(e!=="running"&&e!=="complete"&&e!=="error"&&e!=="cancelled")throw new Error("Invalid OAuth flow status");return e}function rl(e){if(e===void 0)return;const t=b(e);return{url:m(t,"url"),...S("instructions",$(t,"instructions"))}}function nl(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,...S("placeholder",$(t,"placeholder")),...t.allowEmpty===!0?{allowEmpty:!0}:{}}}function al(e){if(e===void 0)return;const t=b(e);return{requestId:m(t,"requestId"),message:m(t,"message"),options:N(kn)(t.options)}}function cl(e){if(e===void 0)return{};const t=b(e);return{contextUsage:{tokens:Vo(t,"tokens"),contextWindow:se(t,"contextWindow"),percent:Vo(t,"percent")}}}function ll(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,...S("description",$(t,"description"))}}function yn(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 dl(e){const t=b(e);return{path:m(t,"path"),entries:N(pl)(t.entries),scannedAt:m(t,"scannedAt"),truncated:W(t,"truncated")}}function pl(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,...S("size",Re(t,"size")),...S("modifiedAt",$(t,"modifiedAt"))}}function hl(e){const t=b(e),i=m(t,"encoding");if(i!=="utf8")throw new Error("Invalid file encoding");return{path:m(t,"path"),...S("language",$(t,"language")),...S("mediaType",ul(t.mediaType)),...S("mimeType",$(t,"mimeType")),encoding:i,size:se(t,"size"),modifiedAt:m(t,"modifiedAt"),content:m(t,"content"),truncated:W(t,"truncated"),binary:W(t,"binary")}}function ul(e){if(e!==void 0){if(e!=="image")throw new Error("Invalid file media type");return e}}function fl(e){const t=b(e);return{isGitRepo:W(t,"isGitRepo"),hash:m(t,"hash"),...S("branch",$(t,"branch")),...S("upstream",$(t,"upstream")),...S("ahead",Re(t,"ahead")),...S("behind",Re(t,"behind")),files:N(gl)(t.files)}}function gl(e){const t=b(e);return{path:m(t,"path"),...S("oldPath",$(t,"oldPath")),index:zo(t.index),workingTree:zo(t.workingTree)}}function zo(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 ml(e){const t=b(e);return{...S("path",$(t,"path")),staged:W(t,"staged"),hash:m(t,"hash"),diff:m(t,"diff"),truncated:W(t,"truncated")}}function Vi(e){const t=b(e);return{id:m(t,"id"),cwd:m(t,"cwd"),name:m(t,"name"),createdAt:m(t,"createdAt"),exited:W(t,"exited"),...S("exitCode",Re(t,"exitCode")),...S("commandRunId",$(t,"commandRunId"))}}function Tt(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:vl(t.status),...S("exitCode",Re(t,"exitCode")),createdAt:m(t,"createdAt"),...S("startedAt",$(t,"startedAt")),...S("completedAt",$(t,"completedAt")),metadata:bl(t.metadata,"metadata")}}function vl(e){if(e!=="queued"&&e!=="running"&&e!=="succeeded"&&e!=="failed")throw new Error("Invalid terminal command run status");return e}function bl(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 wl(e){const t=b(e);return{cwd:m(t,"cwd"),hasSessionActivity:W(t,"hasSessionActivity"),hasTerminalActivity:W(t,"hasTerminalActivity"),updatedAt:m(t,"updatedAt")}}function yl(e){const t=b(e);return{workspaces:N(wl)(t.workspaces),generatedAt:m(t,"generatedAt")}}function Bo(e){const t=b(e);return{path:m(t,"path"),exists:W(t,"exists"),config:Uo(t.config),effectiveConfig:Uo(t.effectiveConfig),envOverrides:$l(t.envOverrides)}}function Uo(e){const t=b(e);return{...S("host",$(t,"host")),...S("port",Re(t,"port")),...S("allowedHosts",Sl(t.allowedHosts)),...S("shortcuts",xl(t.shortcuts)),...S("plugins",kl(t.plugins))}}function Sl(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 xl(e){if(e!==void 0){if(!Ct(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 kl(e){if(e!==void 0){if(!Ct(e)||Array.isArray(e))throw new Error("Invalid PI WEB plugins field");return Object.fromEntries(Object.entries(e).map(([t,i])=>{if(!Ct(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&&(!Ct(o)||Array.isArray(o)))throw new Error("Invalid PI WEB plugin settings field");return[t,i]}))}}function $l(e){const t=b(e);return{host:W(t,"host"),port:W(t,"port"),allowedHosts:W(t,"allowedHosts")}}function Pl(e){const t=b(e);return{plugins:N(Rl)(t.plugins)}}function Rl(e){const t=b(e);return{id:m(t,"id"),module:m(t,"module"),source:m(t,"source"),scope:Il(t.scope),machineSpecific:Cl(t.machineSpecific,"machineSpecific")??!1,enabled:W(t,"enabled")}}function Il(e){if(e!=="bundled"&&e!=="local"&&e!=="user"&&e!=="project")throw new Error("Invalid PI WEB plugin scope");return e}function Cl(e,t){if(e!==void 0){if(typeof e!="boolean")throw new Error(`Expected optional boolean field: ${t}`);return e}}function Tl(e){const t=b(e);return{packageName:m(t,"packageName"),generatedAt:m(t,"generatedAt"),components:Al(t.components),release:Dl(t.release),commands:Wl(t.commands),messages:N(Ol)(t.messages)}}function Ml(e){const t=b(e);return{packageName:m(t,"packageName"),generatedAt:m(t,"generatedAt"),components:Sn(t.components),capabilities:qs(t.capabilities)}}function Al(e){const t=b(e);return{web:pi(t.web),sessiond:pi(t.sessiond)}}function Sn(e){const t=b(e);return{web:Ho(t.web),sessiond:Ho(t.sessiond)}}function Ho(e){const t=b(e);return{component:xn(t.component),label:m(t,"label"),...S("runtimeVersion",$(t,"runtimeVersion")),available:W(t,"available"),capabilities:qs(t.capabilities),...S("error",$(t,"error"))}}function pi(e){const t=b(e);return{component:xn(t.component),label:m(t,"label"),...S("runtimeVersion",$(t,"runtimeVersion")),...S("installedVersion",$(t,"installedVersion")),stale:W(t,"stale"),available:W(t,"available"),...S("installation",El(t.installation)),...S("error",$(t,"error"))}}function El(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,...S("path",$(t,"path")),...S("source",$(t,"source")),...s===void 0?{}:{scope:s},...S("npmRoot",$(t,"npmRoot"))}}function Dl(e){const t=b(e);return{packageName:m(t,"packageName"),...S("latestVersion",$(t,"latestVersion")),updateAvailable:W(t,"updateAvailable"),...S("checkedAt",$(t,"checkedAt")),...t.skipped===!0?{skipped:!0}:{},...S("error",$(t,"error"))}}function Wl(e){const t=b(e);return{...S("update",$(t,"update")),...S("restart",$(t,"restart")),...S("restartWeb",$(t,"restartWeb")),...S("restartSessiond",$(t,"restartSessiond")),...S("status",$(t,"status"))}}function Ol(e){const t=b(e);return{id:m(t,"id"),severity:_l(t.severity),title:m(t,"title"),body:m(t,"body"),...S("command",$(t,"command"))}}function xn(e){if(e!=="web"&&e!=="sessiond")throw new Error("Invalid PI WEB service component");return e}function qs(e){if(!Array.isArray(e)||!e.every(_c))throw new Error("Invalid PI WEB capabilities");return e}function _l(e){if(e!=="info"&&e!=="warning"&&e!=="error")throw new Error("Invalid PI WEB status severity");return e}function qo(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:N(kn)(t.options)};if(i==="done")return{type:i,...S("message",$(t,"message")),...Ll(t.session),...S("promptDraft",$(t,"promptDraft"))};throw new Error("Invalid command result type")}function kn(e){const t=b(e);return{value:m(t,"value"),label:m(t,"label"),...S("description",$(t,"description"))}}function Ll(e){return e===void 0?{}:{session:ws(e)}}function Kt(e){if(b(e).accepted!==!0)throw new Error("Expected accepted response");return{accepted:!0}}function jl(e){const t=b(e);return N(Fl)(t.attachments)}function Fl(e){const t=b(e);return{path:m(t,"path"),mimeType:m(t,"mimeType"),size:se(t,"size")}}function ys(e){if(b(e).closed!==!0)throw new Error("Expected closed response");return{closed:!0}}function Nl(e){if(b(e).aborted!==!0)throw new Error("Expected aborted response");return{aborted:!0}}function zl(e){if(b(e).stopped!==!0)throw new Error("Expected stopped response");return{stopped:!0}}function Ko(e){const t=b(e);if(t.archived!==!0)throw new Error("Expected archived response");const i=t.sessionIds===void 0?void 0:jc(t.sessionIds,"sessionIds"),s=Re(t,"archivedCount"),o=Re(t,"skippedAlreadyArchivedCount");return{archived:!0,...i===void 0?{}:{sessionIds:i},...s===void 0?{}:{archivedCount:s},...o===void 0?{}:{skippedAlreadyArchivedCount:o}}}function Bl(e){if(b(e).restored!==!0)throw new Error("Expected restored response");return{restored:!0}}function Ul(e){if(b(e).deleted!==!0)throw new Error("Expected deleted response");return{deleted:!0}}function Hl(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 Re(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 Vo(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 S(e,t){return t===void 0?{}:{[e]:t}}function Kl(e){return typeof e=="string"?e:e.id}function Vl(e){return typeof e=="string"?void 0:e.cwd}function Gl(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 Jl(e,t,i="local"){const s=new URLSearchParams,o=Vl(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(Kl(e))}/messages${r===""?"":`?${r}`}`}function Ql(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 $n(e,t,i,s){const o=new URLSearchParams;o.set("path",i);const r=`/api/machines/${encodeURIComponent(s?.machineId??"local")}`;return mn(`${r}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}/file/download?${o.toString()}`)}const R=(e="local")=>`/api/machines/${encodeURIComponent(e)}`;function Zl(e){return typeof e=="string"?e:e.id}function Pn(e){return typeof e=="string"?void 0:e.cwd}function Rn(e,t="local"){return`${R(t)}/sessions/${encodeURIComponent(Zl(e))}`}function V(e,t,i="local"){return`${Rn(e,i)}/${t}`}function Vt(e,t,i="local"){return`${V(e,t,i)}${In(e)}`}function Xl(e,t="local"){return`${Rn(e,t)}${In(e)}`}function In(e){const t=Pn(e);return t===void 0||t===""?"":`?${new URLSearchParams({cwd:t}).toString()}`}function J(e,t={}){const i=Pn(e);return JSON.stringify(i===void 0||i===""?t:{cwd:i,...t})}const Cn={piWebStatus:(e="local")=>v(e==="local"?"/api/pi-web/status":`${R(e)}/pi-web/status`,Tl),piWebRuntime:()=>v("/api/pi-web/runtime",Ml)},Yl={machines:()=>v("/api/machines",Nc),addMachine:e=>v("/api/machines",vn,{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`,zc),runtime:e=>v(`/api/machines/${encodeURIComponent(e)}/runtime`,Bc)},hi={config:()=>v("/api/config",Bo),saveConfig:e=>v("/api/config",Bo,{method:"PUT",body:JSON.stringify({config:e})})},Ss={plugins:()=>v("/api/plugins",Pl)},Tn={workspaceActivity:(e="local")=>v(`${R(e)}/activity`,yl)},ed={projects:(e="local")=>v(`${R(e)}/projects`,N(Fo)),addProject:(e,t,i,s="local")=>v(`${R(s)}/projects`,Fo,{method:"POST",body:JSON.stringify({path:e,name:t,create:i})}),closeProject:(e,t="local")=>v(`${R(t)}/projects/${encodeURIComponent(e)}`,ys,{method:"DELETE"}),projectDirectories:(e,t="local")=>v(`${R(t)}/project-directories?q=${encodeURIComponent(e)}`,N(yn))},xs={workspaces:(e,t="local")=>v(`${R(t)}/projects/${e}/workspaces`,N(Hc)),deleteWorkspace:(e,t,i="local")=>v(`${R(i)}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}`,Tt,{method:"DELETE"}),workspaceTree:(e,t,i="",s="local")=>v(`${R(s)}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}/tree?path=${encodeURIComponent(i)}`,dl),workspaceFile:(e,t,i,s="local")=>v(`${R(s)}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}/file?path=${encodeURIComponent(i)}`,hl),uploadWorkspaceFile:async(e,t,i,s,o="local")=>o==="local"?nd(e,t,i,s):v(`${R(o)}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}/file`,bs,{method:"POST",body:JSON.stringify({path:i,contentBase64:await od(s)})}),createWorkspaceFile:(e,t,i,s="local")=>v(`${R(s)}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}/file`,bs,{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`,Ki,{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)}`,No,{method:"DELETE"}),createWorkspaceDirectory:(e,t,i,s="local")=>v(`${R(s)}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}/directory`,Ki,{method:"POST",body:JSON.stringify({path:i})}),moveWorkspaceDirectory:(e,t,i,s,o="local")=>v(`${R(o)}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}/directory`,Ki,{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)}`,No,{method:"DELETE"}),workspaceDownloadUrl:(e,t,i,s="local")=>$n(e,t,i,{machineId:s}),downloadWorkspaceFile:(e,t,i,s="local")=>ad(e,t,i,s)},td={sessions:(e,t="local")=>v(`${R(t)}/sessions?cwd=${encodeURIComponent(e)}`,N(ws)),startSession:(e,t="local")=>v(`${R(t)}/sessions`,ws,{method:"POST",body:JSON.stringify({cwd:e})}),messages:(e,t,i="local")=>v(Jl(e,t,i),Fc),status:(e,t="local")=>v(Vt(e,"status",t),vt),models:(e,t="local")=>v(Vt(e,"models",t),Qc),setModel:(e,t,i,s="local")=>v(V(e,"model",s),vt,{method:"POST",body:J(e,{provider:t,modelId:i})}),cycleModel:(e,t,i="local")=>v(V(e,"model/cycle",i),vt,{method:"POST",body:J(e,{direction:t})}),thinkingLevels:(e,t="local")=>v(Vt(e,"thinking-levels",t),Xc),setThinkingLevel:(e,t,i="local")=>v(V(e,"thinking-level",i),vt,{method:"POST",body:J(e,{level:t})}),cycleThinkingLevel:(e,t="local")=>v(V(e,"thinking-level/cycle",t),vt,{method:"POST",body:J(e)}),commands:(e,t="local")=>v(Vt(e,"commands",t),N(ll)),prompt:(e,t,i,s="local",o)=>v(V(e,"prompt",s),Kt,{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),jl,{method:"POST",body:J(e,{attachments:t,...s===void 0?{}:{folder:s}})}),shell:(e,t,i="local")=>v(V(e,"shell",i),Kt,{method:"POST",body:J(e,{text:t})}),runCommand:(e,t,i="local")=>v(V(e,"commands/run",i),qo,{method:"POST",body:J(e,{text:t})}),respondToCommand:(e,t,i,s="local")=>v(V(e,"commands/respond",s),qo,{method:"POST",body:J(e,{requestId:t,value:i})}),abort:(e,t="local")=>v(V(e,"abort",t),Nl,{method:"POST",body:J(e)}),stop:(e,t="local")=>v(V(e,"stop",t),zl,{method:"POST",body:J(e)}),archive:(e,t="local")=>v(V(e,"archive",t),Ko,{method:"POST",body:J(e)}),archiveWithDescendants:(e,t="local")=>v(V(e,"archive-tree",t),Ko,{method:"POST",body:J(e)}),restore:(e,t="local")=>v(V(e,"restore",t),Bl,{method:"POST",body:J(e)}),deleteArchived:(e,t="local")=>v(Xl(e,t),Ul,{method:"DELETE"}),detachParent:(e,t="local")=>v(V(e,"detach-parent",t),Hl,{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}`}`,sl)},saveApiKey:(e,t,i="local")=>v(`${R(i)}/auth/api-key`,Kt,{method:"POST",body:JSON.stringify({providerId:e,key:t})}),logoutProvider:(e,t="local")=>v(`${R(t)}/auth/logout`,Kt,{method:"POST",body:JSON.stringify({providerId:e})}),startOAuthLogin:(e,t="local")=>v(`${R(t)}/auth/oauth`,qt,{method:"POST",body:JSON.stringify({providerId:e})}),oauthFlow:(e,t="local")=>v(`${R(t)}/auth/oauth/${encodeURIComponent(e)}`,qt),respondOAuthFlow:(e,t,i,s="local")=>v(`${R(s)}/auth/oauth/${encodeURIComponent(e)}/respond`,qt,{method:"POST",body:JSON.stringify({requestId:t,value:i})}),cancelOAuthFlow:(e,t="local")=>v(`${R(t)}/auth/oauth/${encodeURIComponent(e)}/cancel`,qt,{method:"POST"})},at={terminals:(e,t,i="local")=>v(`${R(i)}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}/terminals`,N(Vi)),startTerminal:(e,t,i,s="local")=>v(`${R(s)}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}/terminals`,Vi,{method:"POST",body:JSON.stringify(i??{})}),closeWorkspaceTerminals:(e,t,i="local")=>v(`${R(i)}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}/terminals`,ys,{method:"DELETE"}),closeTerminal:(e,t,i,s="local")=>v(`${R(s)}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}/terminals/${encodeURIComponent(i)}`,ys,{method:"DELETE"}),continueTerminal:(e,t,i,s="local")=>v(`${R(s)}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}/terminals/${encodeURIComponent(i)}/continue`,Vi,{method:"POST"}),runTerminalCommand:(e,t,i="local")=>v(`${R(i)}/projects/${encodeURIComponent(t.workspace.projectId)}/workspaces/${encodeURIComponent(t.workspace.id)}/terminal-command-runs`,Tt,{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${sd(e)}`,N(Tt)),getCommandRun:(e,t="local")=>id(e,t),cancelCommandRun:(e,t="local")=>v(`${R(t)}/terminal-command-runs/${encodeURIComponent(e)}/cancel`,Tt,{method:"POST"})};async function id(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(Ks(s)??i.statusText)}return Tt(await i.json())}}function sd(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 Ks(e){if(!cd(e))return;const t=e.error;return typeof t=="string"?t:void 0}async function od(e){return rd(await e.arrayBuffer())}function rd(e){const t=new Uint8Array(e);let i="";for(const s of t)i+=String.fromCharCode(s);return btoa(i)}async function nd(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(Ks(n)??r.statusText)}return bs(await r.json())}async function ad(e,t,i,s){const o=await fetch($n(e,t,i,{machineId:s}));if(!o.ok){const p=await o.json().catch(()=>({}));throw new Error(Ks(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 cd(e){return typeof e=="object"&&e!==null}const ld={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()}`,N(yn))}},dd={gitStatus:(e,t,i="local")=>v(`${R(i)}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}/git/status`,fl),gitDiff:(e,t,i,s="local")=>v(Gl(s,e,t,i),ml)},z={...Cn,...Yl,...hi,...Ss,...Tn,...ed,...xs,...td,...at,...ld,...dd};function pd(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(`${Gs()}${Vs(t)}/sessions/${encodeURIComponent(o)}/events${s}`)}function Nw(e,t,i,s,o="local"){const r=s===void 0?"":`?cols=${encodeURIComponent(String(s.cols))}&rows=${encodeURIComponent(String(s.rows))}`;return new WebSocket(`${Gs()}${Vs(o)}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}/terminals/${encodeURIComponent(i)}/socket${r}`)}function hd(e="local"){return new WebSocket(`${Gs()}${Vs(e)}/events`)}function Vs(e){return`/api/machines/${encodeURIComponent(e)}`}function Gs(){return`${location.protocol==="https:"?"wss:":"ws:"}//${location.host}`}function si(){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 ud(){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 Qe(e,t){return t?.phase==="active"||e?.isStreaming===!0||e?.isBashRunning===!0||e?.isCompacting===!0||(e?.pendingMessageCount??0)>0}function Mn(e){return e!==void 0&&(e.hasSessionActivity||e.hasTerminalActivity)}const An="local";function Gi(e,t){return`${e}:${t}`}function En(e,t){return`${e}:${t}`}function f(e){return e.selectedMachine?.id??An}class fd{constructor(t,i,s={}){this.getState=t,this.setState=i,this.api=s.api??Tn}async refresh(t=f(this.getState())){this.applyMachineActivitySnapshot(t,gd(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=md(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 gd(e){const t={};for(const i of e.workspaces)Mn(i)&&(t[i.cwd]=i);return t}function md(e,t){const i={...e};return Mn(t)?(i[t.cwd]=t,i):Object.fromEntries(Object.entries(i).filter(([s])=>s!==t.cwd))}class vd{constructor(t,i,s,o={}){this.getState=t,this.setState=i,this.applyStatus=s,this.api=o.api??z,this.pollIntervalMs=o.pollIntervalMs??1e3}dispose(){this.stopPolling()}handleSlashCommand(t){const i=bd(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 bd(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 _t(e){return e.replaceAll(":",".")}function wd(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 Ji(e,t){const i=wd(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));yd(o,s)}function yd(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 Gt=_t("core:workspace.files");class Sd{constructor(t,i,s,o={}){this.getState=t,this.setState=i,this.updateUrl=s,this.api=o.api??z}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(Go(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:xd(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(Gt,"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(Gt,"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(Go(o)){this.setState({selectedFilePath:void 0,selectedFileContent:void 0,error:""}),le(Gt,"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=kd(this.getState()),n=[];for(const l of t){const p=Pd(r,$d(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());Qi(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());Qi(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===""||Qi(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(Gt,"file",void 0,{replace:!0}),this.updateUrl({replace:!0})}}function Go(e){const t=String(e);return t.includes("Path does not exist")||t.includes("ENOENT")||t.includes("no such file or directory")}function xd(e,t){return Object.fromEntries(Object.entries(e).filter(([i])=>i!==t))}function kd(e){const t=e.selectedFilePath;if(t===void 0||t==="")return"";if(Dn(e.fileTree,e.expandedDirs,t)?.type==="directory")return t;const s=t.lastIndexOf("/");return s===-1?"":t.slice(0,s)}function Qi(e){const t=e.selectedFilePath;return t===void 0?"file":Dn(e.fileTree,e.expandedDirs,t)?.type==="directory"?"directory":"file"}function Dn(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 $d(e){return e.name.split(/[\\/]+/u).filter(t=>t!=="").at(-1)??e.name}function Pd(e,t){return e===""?t:`${e}/${t}`}const Jo=_t("core:workspace.git");class Rd{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 z.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(Jo,"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(Jo,"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([z.gitDiff(i.id,s.id,{path:t},f(this.getState())),z.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 Id{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 z.machines(),s=await this.selectInitialMachine(i,t),o=new Set(i.map(r=>r.id));this.setState({machines:i,selectedMachine:s,machineActivities:Qo(this.getState().machineActivities,o),machineRuntimes:Qo(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,...si()}),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 z.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 z.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:Zi(this.getState().machineStatuses,t.id),machineRuntimes:Zi(this.getState().machineRuntimes,t.id),machineActivities:Zi(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 z.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 z.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 z.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=>z.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=>z.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 Zi(e,t){return Object.fromEntries(Object.entries(e).filter(([i])=>i!==t))}function Qo(e,t){return Object.fromEntries(Object.entries(e).filter(([i])=>t.has(i)))}class Cd{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 z.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 z.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 z.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 ks="pi-web:cached-new-sessions:v1",Td="browserCachedNew",ht="local";function Lt(){try{return typeof localStorage>"u"?void 0:localStorage}catch{return}}function Zo(e,t=ht,i=Lt()){if(e.messageCount!==0||e.archived===!0)return;const s=Js(i).filter(o=>o.id!==e.id||o.machineId!==t);Qs([$s(e,t),...s],i)}function $s(e,t=ht){return{...e,browserCachedNew:!0,machineId:t}}function Xo(e,t=ht,i=Lt()){const s=Js(i).filter(o=>o.id!==e||o.machineId!==t);Qs(s,i)}function Md(e,t,i=ht,s=Lt()){const o=new Set(t.map(l=>l.id)),r=Js(s),n=r.filter(l=>l.machineId!==i||!o.has(l.id));return n.length!==r.length&&Qs(n,s),[...n.filter(l=>l.machineId===i&&l.cwd===e),...t]}function ee(e){return e===void 0?!1:Dd(e)&&e.browserCachedNew===!0}function Ad(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:ht},...e.archived===!0?{archived:!0}:{},...e.archivedAt===void 0?{}:{archivedAt:e.archivedAt}}}function Js(e=Lt()){try{const t=e?.getItem(ks);if(t==null||t==="")return[];const i=JSON.parse(t);return Array.isArray(i)?i.flatMap(s=>Ed(s)):[]}catch{return[]}}function Qs(e,t=Lt()){try{e.length===0?t?.removeItem(ks):t?.setItem(ks,JSON.stringify(e))}catch{}}function Ed(e){if(!Wd(e))return[];const t=ot(e,"id"),i=ot(e,"path"),s=ot(e,"cwd"),o=ot(e,"created"),r=ot(e,"modified"),n=ot(e,"firstMessage"),a=Od(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=Xi(e,"name"),p=Xi(e,"parentSessionPath"),u=Xi(e,"machineId")??ht;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 Dd(e){return Td in e}function Wd(e){return typeof e=="object"&&e!==null}function ot(e,t){const i=e[t];return typeof i=="string"?i:void 0}function Xi(e,t){const i=e[t];return i===void 0||typeof i!="string"?void 0:i}function Od(e,t){const i=e[t];return typeof i=="number"?i:void 0}function _d(e){return Xd(e.flatMap(Zs)).filter(t=>t.parts.length>0)}function Pe(e,t){return{role:e,parts:[{type:"text",text:t}]}}function bt(e,t){const i=Hd(t);return i===void 0?e:{...e,meta:i}}function Ld(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,Pe(t,i)]}function jd(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 Zs(e){if(Nd(e))return[e];if(E(e,"role")==="bashExecution")return[bt(Vd(e),e)];const t=Gd(E(e,"role")),i=Jd(ge(e,"content"),e),s=t==="user"?zd(i):void 0;if(s!==void 0)return s.map(p=>bt(p,e));const o=Ud(e);if(t==="tool")return[bt({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?[bt({role:n,parts:r,...o===void 0?{}:{source:o}},e)]:[],l=Fd(e);return l===void 0?a:[...a,bt(l,e)]}function Fd(e){if(E(e,"role")!=="assistant"||E(e,"stopReason")!=="error")return;const t=E(e,"errorMessage")?.trim();return Pe("system",`Model response failed: ${t===void 0||t===""?"The model returned an error.":t}`)}function Nd(e){const t=E(e,"role");return(t==="user"||t==="assistant"||t==="tool"||t==="system"||t==="bash"||t==="skill")&&Array.isArray(ge(e,"parts"))}function zd(e){if(e.length!==1||e[0]?.type!=="text")return;const t=Bd(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 Bd(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 Ud(e){const t=E(e,"source");if(t==="compaction"||t==="branch_summary")return t}function Hd(e){const t=qd(ge(e,"timestamp")),i=Kd(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 Kd(e){if(E(e,"role")!=="assistant")return;const t=E(e,"provider"),i=E(e,"model"),s=E(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 Vd(e){const t=E(e,"command")??"",i=oi(e,"excludeFromContext")===!0?["excluded from context","",`$ ${t}`]:[`$ ${t}`],s=ge(e,"output");s!=null&&i.push("",fi(s));const o=ge(e,"exitCode");o!=null&&i.push("",`exit ${fi(o)}`),oi(e,"cancelled")===!0&&i.push("","cancelled"),oi(e,"truncated")===!0&&i.push("","output truncated");const r=E(e,"fullOutputPath");return r!==void 0&&r!==""&&i.push("",`full output: ${r}`),{role:"bash",parts:[{type:"text",text:i.join(`
|
|
5
|
+
`)}]}}function Gd(e){return e==="assistant"?"assistant":e==="user"?"user":e==="toolResult"?"tool":"system"}function Jd(e,t){return typeof e=="string"?e!==""?[{type:"text",text:e}]:[]:Array.isArray(e)?e.flatMap(i=>{const s=E(i,"type"),o=E(i,"text");if(s==="text")return o!==void 0&&o!==""?[{type:"text",text:o}]:[];if(s==="thinking"){const r=E(i,"thinking")??o;return r!==void 0&&r!==""?[{type:"thinking",text:r}]:[]}if(s==="toolCall"){const r=E(i,"name")??"tool",n=ge(i,"arguments"),a=r==="read"?Zd(E(n,"path")):void 0;if(a!==void 0)return[{type:"skillRead",...a}];const l=E(i,"id");return[{type:"toolCall",...l===void 0?{}:{toolCallId:l},toolName:r,summary:jt(n),...n===void 0?{}:{args:n}}]}if(s==="image"){const r=E(i,"data"),n=E(i,"mimeType");return r!==void 0&&r!==""&&n!==void 0&&n!==""?[{type:"image",mimeType:n,data:r}]:[{type:"text",text:"[image]"}]}return Yo(i)}).map(i=>i.type==="text"&&E(t,"role")==="toolResult"?Qd(i.text,t):i):Yo(e)}function Qd(e,t){const i=E(t,"toolCallId"),s=ge(t,"content"),o=ge(t,"details");return{type:"toolResult",...i===void 0?{}:{toolCallId:i},toolName:E(t,"toolName")??"tool",text:e,...s===void 0?{}:{content:s},...o===void 0?{}:{details:o},isError:oi(t,"isError")===!0}}function Zd(e){if(e===void 0||e==="")return;const t=e.replace(/\\/g,"/");if(!t.endsWith("/SKILL.md")&&t!=="SKILL.md")return;const i=t.split("/").at(-2);if(!(i===void 0||i===""))return{name:i,path:e}}function Xd(e){const t=[],i=new Map;for(const s of e){let o=[];const r={...s.source===void 0?{}:{source:s.source},...s.meta===void 0?{}:{meta:s.meta}},n=()=>{o.length!==0&&(t.push({role:s.role,parts:o,...r}),o=[])};for(const a of s.parts){if(a.type==="toolCall"){n();const l=Yd(a),p=t.length;t.push({role:"tool",parts:[l],...r}),l.toolCallId!==void 0&&i.set(l.toolCallId,{lineIndex:p,partIndex:0});continue}if(a.type==="toolResult"){const l=a.toolCallId===void 0?void 0:i.get(a.toolCallId);if(l!==void 0&&ep(t,l,a)){i.delete(a.toolCallId??"");continue}}o.push(a)}n()}return t}function Yd(e){return{type:"toolExecution",...e.toolCallId===void 0?{}:{toolCallId:e.toolCallId},toolName:e.toolName,summary:e.summary,...e.args===void 0?{}:{args:e.args},status:"pending"}}function ep(e,t,i){const s=e[t.lineIndex],o=s?.parts[t.partIndex];if(s===void 0||o?.type!=="toolExecution")return!1;const r=ui(i.details)??o.preview,n={...o,status:i.isError?"error":"success",resultText:i.text,...i.content===void 0?{}:{content:i.content},...i.details===void 0?{}:{details:i.details},...r===void 0?{}:{preview:r}};return e[t.lineIndex]={...s,parts:[...s.parts.slice(0,t.partIndex),n,...s.parts.slice(t.partIndex+1)]},!0}function ui(e){const t=ge(e,"preview");if(!Xs(t))return;const i=E(t,"diff"),s=E(t,"error"),o=ip(t,"firstChangedLine");if(!(i===void 0&&s===void 0&&o===void 0))return{...i===void 0?{}:{diff:i},...s===void 0?{}:{error:s},...o===void 0?{}:{firstChangedLine:o}}}function Yo(e){return e==null?[]:typeof e=="object"?[{type:"text",text:jt(e)}]:[{type:"text",text:fi(e)}]}function jt(e){if(!Xs(e))return fi(e);const t=E(e,"command");if(t!==void 0)return t;const i=E(e,"path");if(i!==void 0)return i;if(typeof e.oldText=="string"&&typeof e.newText=="string")return"edit text replacement";const s=e.edits;return Array.isArray(s)?`${String(s.length)} edit${s.length===1?"":"s"}`:Object.entries(e).filter(([,r])=>r!=null).slice(0,3).map(([r,n])=>`${r}: ${tp(n)}`).join(" · ")}function tp(e){return typeof e=="string"?e.length>80?`${e.slice(0,77)}…`:e:typeof e=="number"||typeof e=="boolean"?String(e):Array.isArray(e)?`${String(e.length)} item${e.length===1?"":"s"}`:typeof e=="object"&&e!==null?"object":""}function Xs(e){return typeof e=="object"&&e!==null}function ge(e,t){return Xs(e)?e[t]:void 0}function E(e,t){const i=ge(e,t);return typeof i=="string"?i:void 0}function oi(e,t){const i=ge(e,t);return typeof i=="boolean"?i:void 0}function ip(e,t){const i=ge(e,t);return typeof i=="number"&&Number.isFinite(i)?i:void 0}function fi(e){return e==null?"":typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"||typeof e=="bigint"?String(e):""}const sp="pi-web:prompt-draft:";function gi(e){return`${sp}${e}`}function Di(){try{return typeof localStorage>"u"?void 0:localStorage}catch{return}}function Wn(e,t=Di()){try{return t?.getItem(gi(e))??""}catch{return""}}function mi(e,t,i=Di()){try{t?i?.setItem(gi(e),t):i?.removeItem(gi(e))}catch{}}function Ys(e,t=Di()){try{t?.removeItem(gi(e))}catch{}}function op(e,t,i=Di()){const s=Wn(e,i);s!==""&&(mi(t,s,i),Ys(e,i))}function rp(e,t){return Pe("bash",`${t===!0?`不加入上下文
|
|
6
|
+
|
|
7
|
+
`:""}$ ${e}`)}function np(e,t){const i=e.at(-1),s=i?.parts.at(-1);if(i?.role!=="bash"||s?.type!=="text")return[...e,Pe("bash",t)];const o=cp(s.text)?"":`
|
|
8
|
+
|
|
9
|
+
`;return[...e.slice(0,-1),{...i,parts:[...i.parts.slice(0,-1),{...s,text:s.text+o+t}]}]}function ap(e,t){const i=e.at(-1),s=i?.parts.at(-1);if(i?.role!=="bash"||s?.type!=="text")return e;const o=[];return!s.text.includes(`
|
|
10
|
+
|
|
11
|
+
`)&&(t.output===void 0||t.output==="")&&o.push("(no output)"),t.isError===!0&&o.push(t.output??"Bash 命令失败"),t.exitCode!=null&&o.push(`exit ${String(t.exitCode)}`),t.cancelled===!0&&o.push("cancelled"),t.truncated===!0&&o.push("output truncated"),t.fullOutputPath!==void 0&&t.fullOutputPath!==""&&o.push(`完整输出:${t.fullOutputPath}`),o.length===0?e:[...e.slice(0,-1),{...i,parts:[...i.parts.slice(0,-1),{...s,text:`${s.text}
|
|
12
|
+
|
|
13
|
+
${o.join(`
|
|
14
|
+
`)}`}]}]}function cp(e){const t=e.lastIndexOf(`
|
|
15
|
+
|
|
16
|
+
`),i=e.lastIndexOf("$ ");return t>i}function lp(e,t){if(t.type==="message.append")return yp(e,t.message);if(t.type==="assistant.delta")return Ld(e,"assistant",t.text);if(t.type==="assistant.thinking.delta")return jd(e,t.text);if(t.type==="tool.start")return fp(e,t);if(t.type==="tool.update")return _n(e,t.toolCallId,i=>gp(i,t));if(t.type==="tool.end")return On(e,t.toolCallId,t.toolName,jt(t.content),t.text,t.isError,t.content,t.details);if(t.type==="shell.start")return[...e,rp(t.command,t.excludeFromContext)];if(t.type==="shell.chunk")return np(e,t.chunk);if(t.type==="shell.end")return ap(e,t);if(t.type==="command.output")return[...e,Pe(t.level==="error"?"system":"tool",t.message)];if(t.type==="session.error")return[...e,Pe("system",t.message)];if(t.type==="message.end")return t.message===void 0?void 0:dp(e,t.message)}function dp(e,t){const i=mp(t);if(i!==void 0)return On(e,i.toolCallId,i.toolName,jt(i.content),i.text,i.isError,i.content,i.details);const s=Zs(t);if(s.length===0)return;const o=s.map(r=>r.role==="assistant"?hp(r):r).filter(r=>r.parts.length>0);return o.length===0?e:o.reduce((r,n)=>pp(r,n),e)}function pp(e,t){const i=vp(e,t);if(i>=0)return[...e.slice(0,i),t,...e.slice(i+1)];const s=e.at(-1);return s?.role!==t.role?[...e,t]:t.role==="assistant"||wp(s,t)?[...e.slice(0,-1),t]:[...e,t]}function hp(e){return{...e,parts:e.parts.filter(t=>t.type!=="toolCall")}}function up(e){if(e===void 0||e==="")return;const t=e.replace(/\\/g,"/");if(!t.endsWith("/SKILL.md")&&t!=="SKILL.md")return;const i=t.split("/").at(-2);if(!(i===void 0||i===""))return{name:i,path:e}}function fp(e,t){const i=t.toolName==="read"?up(Ge(t.args,"path")):void 0;if(i!==void 0)return Sp(e,{role:"skill",parts:[{type:"skillRead",...i}]});const s={type:"toolExecution",...t.toolCallId===""?{}:{toolCallId:t.toolCallId},toolName:t.toolName,summary:t.summary||jt(t.args),...t.args===void 0?{}:{args:t.args},status:"running"};return[...e,{role:"tool",parts:[s]}]}function gp(e,t){const i=ui(t.details)??e.preview;return{...e,status:e.status==="pending"?"running":e.status,...t.text===""?{}:{resultText:t.text},...t.content===void 0?{}:{content:t.content},...t.details===void 0?{}:{details:t.details},...i===void 0?{}:{preview:i}}}function On(e,t,i,s,o,r,n,a){const l=_n(e,t,h=>{const g=ui(a)??h.preview;return{...h,status:r?"error":"success",resultText:o,...n===void 0?{}:{content:n},...a===void 0?{}:{details:a},...g===void 0?{}:{preview:g}}});if(l!==e)return l;const p=ui(a),u={type:"toolExecution",...t===void 0||t===""?{}:{toolCallId:t},toolName:i,summary:s,status:r?"error":"success",resultText:o,...n===void 0?{}:{content:n},...a===void 0?{}:{details:a},...p===void 0?{}:{preview:p}};return[...e,{role:"tool",parts:[u]}]}function _n(e,t,i){if(t===void 0||t==="")return e;for(let s=e.length-1;s>=0;s--){const o=e[s];if(o===void 0)continue;const r=o.parts.findIndex(l=>l.type==="toolExecution"&&l.toolCallId===t);if(r<0)continue;const n=o.parts[r];if(n?.type!=="toolExecution")continue;const a={...o,parts:[...o.parts.slice(0,r),i(n),...o.parts.slice(r+1)]};return[...e.slice(0,s),a,...e.slice(s+1)]}return e}function mp(e){if(Ge(e,"role")!=="toolResult")return;const t=Ge(e,"toolCallId"),i=bi(e,"content");return{...t===void 0?{}:{toolCallId:t},toolName:Ge(e,"toolName")??"tool",text:Ln(i),isError:kp(e,"isError")===!0,content:i,details:bi(e,"details")}}function Ln(e){if(typeof e=="string")return e;if(Array.isArray(e))return e.map(Ln).filter(t=>t!=="").join(`
|
|
17
|
+
`);if(typeof e=="object"&&e!==null){const t=Ge(e,"text")??Ge(e,"content")??Ge(e,"output");if(t!==void 0)return t}return""}function vp(e,t){const i=vi(t);if(i.length===0)return-1;for(let s=e.length-1;s>=0;s--){const o=e[s];if(o?.role!=="skill")continue;const r=vi(o);if(jn(r,i))return s}return-1}function vi(e){return e===void 0?[]:e.parts.filter(t=>t.type==="skillRead")}function jn(e,t){return e.length===t.length&&e.every((i,s)=>bp(i,t[s]))}function bp(e,t){return t===void 0?!1:er(e.path)===er(t.path)||e.name===t.name}function er(e){return e.replace(/\\/g,"/")}function wp(e,t){return tr(e)===tr(t)}function tr(e){return e.parts.filter(t=>t.type==="text").map(t=>t.text).join(`
|
|
18
|
+
|
|
19
|
+
`)}function yp(e,t){const i=Zs(t);return i.length===0?e:[...e,...i]}function Sp(e,t){const i=e.at(-1);return t.role==="skill"&&jn(vi(i),vi(t))?e:i?.role===t.role&&t.role!=="skill"?[...e.slice(0,-1),{...i,parts:[...i.parts,...t.parts]}]:[...e,t]}function xp(e){return typeof e=="object"&&e!==null}function bi(e,t){return xp(e)?e[t]:void 0}function Ge(e,t){const i=bi(e,t);return typeof i=="string"?i:void 0}function kp(e,t){const i=bi(e,t);return typeof i=="boolean"?i:void 0}const $p="pi-web:chat-history:v2:",Pp=1800*1e3;function Rp(e){try{const t=sessionStorage.getItem(wi(e));if(t===null||t==="")return;const i=JSON.parse(t);if(!Ep(i))return;if(Date.now()-i.savedAt>Pp){sessionStorage.removeItem(wi(e));return}return{messages:i.messages,start:i.start,total:i.total}}catch{return}}function Ip(e,t){try{sessionStorage.setItem(wi(e),JSON.stringify({...t,savedAt:Date.now()}))}catch{}}function Cp(e){try{sessionStorage.removeItem(wi(e))}catch{}}function Tp(e,t){if(e===void 0||!Ps(e))return t;if(!Ps(t))return e;if(Mp(e,t))return t;const i=Math.min(e.start,t.start),s=Math.max(e.start+e.messages.length,t.start+t.messages.length),o=new Array(s-i);return ir(o,i,e),ir(o,i,t),Ap(o)?t:{start:i,total:Math.max(e.total,t.total),messages:o}}function Mp(e,t){return e.total>t.total&&e.start===0&&t.start===0&&t.messages.length===t.total}function Ap(e){for(let t=0;t<e.length;t+=1)if(!(t in e)||e[t]===void 0)return!0;return!1}function ir(e,t,i){i.messages.forEach((s,o)=>{e[i.start-t+o]=s})}function wi(e){return`${$p}${e}`}function Ep(e){if(typeof e!="object"||e===null||!("messages"in e)||!("start"in e)||!("total"in e)||!("savedAt"in e))return!1;const{messages:t,start:i,total:s,savedAt:o}=e;return Array.isArray(t)&&typeof i=="number"&&typeof s=="number"&&typeof o=="number"&&Ps({messages:t,start:i,total:s})}function Ps(e){return Number.isInteger(e.start)&&Number.isInteger(e.total)&&e.start>=0&&e.total>=e.start&&e.messages.length<=e.total-e.start&&!e.messages.some(Dp)}function Dp(e){return typeof e=="object"&&e!==null&&"role"in e&&"parts"in e&&!("content"in e)&&typeof e.role=="string"&&Array.isArray(e.parts)}const Wp={read:Rp,write:Ip,remove:Cp};class Op{constructor(t=Wp){this.cache=t,this.rawHistoryPages=new Map}cachedView(t){return sr(this.rawHistoryPage(t))}mergeHistory(t,i){const s=Tp(this.rawHistoryPage(t),i);return this.rawHistoryPages.set(t,s),this.cache.write(t,s),sr(s)}applyLiveEvent(t,i){return lp(t,i)}discard(t){this.rawHistoryPages.delete(t),this.cache.remove?.(t)}rawHistoryPage(t){const i=this.rawHistoryPages.get(t)??this.cache.read(t);return i!==void 0&&this.rawHistoryPages.set(t,i),i}}function sr(e){const t=e?.start??0;return{messages:_d(e?.messages??[]),messagePageStart:t,messagePageEnd:t+(e?.messages.length??0),messagePageTotal:e?.total??0}}function Fn(e,t=e.length){const i=e.slice(0,t),s=_p(i,t);if(s!==void 0)return s;const o=Lp(i,t);if(o!==void 0)return o;const r=Math.max(i.lastIndexOf(" "),i.lastIndexOf(`
|
|
20
|
+
`))+1,n=i.slice(r);if(i.slice(0,r).endsWith("@ "))return{kind:"file",query:n,from:r-2,to:t,fileScope:"all",allPrefix:"@ "};if(n.startsWith("/")&&r===0)return{kind:"command",query:n.slice(1),from:r,to:t};if(n.startsWith("!@"))return{kind:"file",query:n.slice(2),from:r,to:t,fileScope:"all",allPrefix:"!@"};if(n.startsWith("@"))return{kind:"file",query:n.slice(1),from:r,to:t,fileScope:"tracked"}}function Nn(e,t,i){const s=i??"@";return!t&&!e.includes(" ")?`${s}${e}`:`${s}"${e}"`}function _p(e,t){const i=e.lastIndexOf('"');if(i===-1)return;const s=e.slice(0,i);if(s.endsWith("!@"))return{kind:"file",query:e.slice(i+1),from:s.length-2,to:t,fileScope:"all",allPrefix:"!@",quoted:!0};if(s.endsWith("@"))return{kind:"file",query:e.slice(i+1),from:s.length-1,to:t,fileScope:"tracked",quoted:!0};if(s.endsWith("@ "))return{kind:"file",query:e.slice(i+1),from:s.length-2,to:t,fileScope:"all",allPrefix:"@ ",quoted:!0}}function Lp(e,t){const i=e.lastIndexOf(`
|
|
21
|
+
`)+1,s=e.slice(i),o=or(s,"@ "),r=or(s,"!@"),n=Math.max(o,r);if(n===-1)return;const a=n===r?"!@":"@ ",l=i+n,p=l+a.length;return{kind:"file",query:e.slice(p),from:l,to:t,fileScope:"all",allPrefix:a}}function or(e,t){for(let i=e.lastIndexOf(t);i>=0;i=e.lastIndexOf(t,i-1))if(i===0||jp(e[i-1]))return i;return-1}function jp(e){return e===" "||e===" "}function eo(e){const t=e.trimStart();return t.startsWith("!@")?{kind:"file"}:t.startsWith("!")?{kind:"shell",excludeFromContext:t.startsWith("!!")}:Np(e).startsWith("/")?{kind:"command"}:Fn(e)?.kind==="file"?{kind:"file"}:{kind:"normal"}}function Fp(e){return eo(e).kind==="shell"}function Np(e){const t=Math.max(e.lastIndexOf(" "),e.lastIndexOf(`
|
|
22
|
+
`))+1;return e.slice(t)}class zp{constructor(){this.reconnectDelay=500,this.shouldReconnect=!1,this.hasOpened=!1,this.machineId="local"}connect(t,i,s,o="local"){this.close(),this.machineId=o,this.session=t,this.onEvent=i,this.onReconnect=s,this.shouldReconnect=!0,this.open()}setHandler(t){this.onEvent=t}close(){this.shouldReconnect=!1,window.clearTimeout(this.reconnectTimer),Bn(this.socket),this.socket=void 0,this.session=void 0,this.onEvent=void 0,this.onReconnect=void 0,this.hasOpened=!1,this.machineId="local"}open(){if(this.session===void 0||this.session.id===""||this.session.cwd===""||!this.shouldReconnect)return;const t=pd(this.session,this.machineId);this.socket=t,t.onopen=()=>{this.reconnectDelay=500,this.hasOpened&&this.onReconnect?.(),this.hasOpened=!0},t.onmessage=i=>{this.handleMessage(i.data)},t.onerror=()=>{t.close()},t.onclose=()=>{this.socket===t&&(this.socket=void 0),this.scheduleReconnect()}}scheduleReconnect(){if(!this.shouldReconnect)return;window.clearTimeout(this.reconnectTimer);const t=this.reconnectDelay;this.reconnectDelay=Math.min(this.reconnectDelay*1.6,5e3),this.reconnectTimer=window.setTimeout(()=>{this.open()},t)}async handleMessage(t){const i=await zn(t);Bp(i)&&this.onEvent?.(i)}}class rr{constructor(){this.reconnectDelay=500,this.shouldReconnect=!1,this.machineId="local"}connect(t,i,s="local"){this.close(),this.machineId=s,this.onEvent=t,this.onOpen=i,this.shouldReconnect=!0,this.open()}close(){this.shouldReconnect=!1,window.clearTimeout(this.reconnectTimer),Bn(this.socket),this.socket=void 0,this.onEvent=void 0,this.onOpen=void 0,this.machineId="local"}open(){if(!this.shouldReconnect)return;const t=hd(this.machineId);this.socket=t,t.onopen=()=>{this.reconnectDelay=500,this.onOpen?.()},t.onmessage=i=>{this.handleMessage(i.data)},t.onerror=()=>{t.close()},t.onclose=()=>{this.socket===t&&(this.socket=void 0),this.scheduleReconnect()}}scheduleReconnect(){if(!this.shouldReconnect)return;window.clearTimeout(this.reconnectTimer);const t=this.reconnectDelay;this.reconnectDelay=Math.min(this.reconnectDelay*1.6,5e3),this.reconnectTimer=window.setTimeout(()=>{this.open()},t)}async handleMessage(t){const i=await zn(t);Hp(i)&&this.onEvent?.(i)}}function Bp(e){const t=to(e);return["message.append","assistant.delta","assistant.thinking.delta","tool.start","tool.update","tool.end","shell.start","shell.chunk","shell.end","agent.start","agent.end","message.end","status.update","activity.update","command.output","session.error","session.name","pi.event"].includes(t)}function Up(e){const t=to(e);return t==="status.update"||t==="activity.update"||t==="session.name"}function Hp(e){const t=to(e);return Up(e)||t==="terminal.created"||t==="terminal.exited"||t==="terminal.closed"||t==="workspace.activity"}function to(e){if(typeof e!="object"||e===null||!("type"in e))return"";const t=e.type;return typeof t=="string"?t:""}async function zn(e){try{return typeof e=="string"?JSON.parse(e):e instanceof Blob?JSON.parse(await e.text()):e instanceof ArrayBuffer?JSON.parse(new TextDecoder().decode(e)):void 0}catch{return}}function Bn(e){if(e!==void 0){if(e.onmessage=null,e.onerror=null,e.onclose=null,e.readyState===WebSocket.CONNECTING){e.onopen=()=>{e.close()};return}e.close()}}function Ft(){try{return typeof sessionStorage>"u"?void 0:sessionStorage}catch{return}}class Wi{constructor(t,i,s=Ft()){this.storageKey=t,this.storage=s,this.values=new Map;for(const[o,r]of qp(t,i,s))this.values.set(o,r)}get(t){return this.values.get(t)}set(t,i){this.values.set(t,i),this.save()}delete(t){this.values.delete(t),this.save()}entries(){return[...this.values.entries()]}save(){try{if(this.values.size===0){this.storage?.removeItem(this.storageKey);return}const t={version:1,entries:[...this.values.entries()]};this.storage?.setItem(this.storageKey,JSON.stringify(t))}catch{}}}function io(e){return typeof e=="string"&&e!==""?e:void 0}function qp(e,t,i){try{const s=i?.getItem(e);if(s==null||s==="")return[];const o=JSON.parse(s);if(!Kp(o))return[];const r=[];for(const n of o.entries){const a=n[0],l=t(n[1]);l!==void 0&&r.push([a,l])}return r}catch{return[]}}function Kp(e){return!Vp(e)||e.version!==1||!Array.isArray(e.entries)?!1:e.entries.every(t=>Array.isArray(t)&&t.length===2&&typeof t[0]=="string"&&t[0]!=="")}function Vp(e){return typeof e=="object"&&e!==null}class Gp{constructor(){this.sessionIdsByCwd=new Map}latestSessionId(t){return this.sessionIdsByCwd.get(t)}rememberSession(t){this.sessionIdsByCwd.set(t.cwd,t.id)}forgetWorkspace(t){this.sessionIdsByCwd.delete(t)}}const Jp="pi-web:session-selection:v1";class Qp{constructor(t=Ft()){this.sessionIdsByCwd=new Wi(Jp,io,t)}latestSessionId(t){return this.sessionIdsByCwd.get(t)}rememberSession(t){this.sessionIdsByCwd.set(t.cwd,t.id)}forgetWorkspace(t){this.sessionIdsByCwd.delete(t)}}function Zp(e,t){const i=t?.targetSessionId;if(i!==void 0&&i!=="")return Yp(e,i);const s=t?.latestSessionId;return s!==void 0&&s!==""?e.find(o=>o.id===s)??e.find(o=>o.archived!==!0):e.find(o=>o.archived!==!0)}function Xp(e,t){return t?.archived!==!0?!1:!e.some(i=>i.archived!==!0)}function Yp(e,t){return e.find(i=>i.id===t||i.id.startsWith(t))}function eh(e,t,i){return Rs(e,[t],i)}function Rs(e,t,i){const s=new Set(t);return e.map(o=>s.has(o.id)?{...o,archived:!0,archivedAt:i}:o)}function th(e,t,i){return Is(e,t,[i])}function Is(e,t,i){if(t===void 0||!i.includes(t))return{type:"unchanged"};const s=new Set(i),o=e.find(r=>!s.has(r.id)&&r.archived!==!0);return o===void 0?{type:"clear"}:{type:"select",session:o}}const wt=100;class ih{constructor(t,i,s,o=new Gp,r={}){this.getState=t,this.setState=i,this.updateUrl=s,this.sessionSelection=o,this.selectionSeq=0,this.pendingTranscriptEvents=[],this.socket=r.socket??new zp,this.api=r.api??z,this.transcripts=r.transcripts??new Op}applyGlobalEvent(t){t.type==="status.update"?this.applyStatus(t.status):t.type==="activity.update"?this.applyActivity(t.activity):this.applySessionName(t.sessionId,t.name)}dispose(){this.socket.close(),this.clearPendingTranscriptEvents()}clearActiveSession(){this.selectionSeq+=1,this.socket.close(),this.catchupStreamSessionId=void 0,this.clearPendingTranscriptEvents(),this.setState({selectedSession:void 0,messages:[],messagePageStart:0,messagePageEnd:0,messagePageTotal:0,isLoadingEarlierMessages:!1,isReceivingPartialStream:!1,status:void 0,activity:void 0,availableThinkingLevels:[]})}deselectSession(t){const i=this.getState(),s=i.selectedSession?.cwd??i.selectedWorkspace?.path;t?.forgetRememberedSelection===!0&&s!==void 0&&this.sessionSelection.forgetWorkspace(this.workspaceSelectionKey(s)),this.clearActiveSession(),t?.updateUrl!==!1&&this.updateUrl()}clearSelectionAfterArchivedCollapse(){const t=this.getState();Xp(t.sessions,t.selectedSession)&&this.deselectSession({forgetRememberedSelection:!0})}async startSession(){const t=this.getState().selectedWorkspace;if(t)try{const i=f(this.getState()),s=await this.api.startSession(t.path,i);Zo(s,i);const o=$s(s,i);this.setState({sessions:[o,...this.getState().sessions]}),await this.selectSession(o)}catch(i){this.setState({error:String(i)})}}preferredSession(t,i,s){return Zp(i,{targetSessionId:s,latestSessionId:this.sessionSelection.latestSessionId(this.workspaceSelectionKey(t))})}async selectSession(t,i){this.sessionSelection.rememberSession({...t,cwd:this.workspaceSelectionKey(t.cwd)});const s=++this.selectionSeq;this.socket.close(),this.catchupStreamSessionId=void 0,this.clearPendingTranscriptEvents();const o=this.sessionCacheKey(t.id),r=this.transcripts.cachedView(o);this.setState({selectedSession:t,...r,isLoadingEarlierMessages:!1,isReceivingPartialStream:!1,status:t.archived===!0?void 0:this.getState().sessionStatuses[t.id],activity:t.archived===!0?void 0:this.getState().sessionActivities[t.id]});try{if(t.archived===!0){const h=await this.api.messages(t,{limit:wt},f(this.getState()));if(s!==this.selectionSeq||this.getState().selectedSession?.id!==t.id)return;const g=this.transcripts.mergeHistory(o,h);this.setState({...g,isLoadingEarlierMessages:!1,isReceivingPartialStream:!1,status:void 0,activity:void 0}),i?.updateUrl!==!1&&this.updateUrl();return}const n=[];this.socket.connect(t,h=>n.push(h),()=>{this.refreshSelectedSession(t.id)},f(this.getState()));const[a,l]=await Promise.all([this.api.messages(t,{limit:wt},f(this.getState())),this.api.status(t,f(this.getState()))]);if(s!==this.selectionSeq||this.getState().selectedSession?.id!==t.id)return;const p=this.transcripts.mergeHistory(o,a),u=l.isStreaming;this.catchupStreamSessionId=u?t.id:void 0,this.setState({...p,isLoadingEarlierMessages:!1,isReceivingPartialStream:u,status:l,activity:this.getState().sessionActivities[t.id],availableThinkingLevels:[]}),this.applyStatus(l),this.refreshAvailableThinkingLevels();for(const h of n)this.applyEvent(h);this.socket.setHandler(h=>{this.applyEvent(h)}),i?.updateUrl!==!1&&this.updateUrl()}catch(n){if(s!==this.selectionSeq||this.getState().selectedSession?.id!==t.id)return;if(ee(t)&&ph(n)){await this.recreateCachedNewSession(t,i);return}this.setState({error:String(n)})}}async loadEarlierMessages(){const t=this.getState(),i=t.selectedSession;if(!(!i||t.isLoadingEarlierMessages||t.messagePageStart<=0)){this.setState({isLoadingEarlierMessages:!0});try{const s=await this.api.messages(i,{before:t.messagePageStart,limit:wt},f(this.getState()));if(this.getState().selectedSession?.id!==i.id)return;const o=this.transcripts.mergeHistory(this.sessionCacheKey(i.id),s);this.setState(o)}catch(s){this.setState({error:String(s)})}finally{this.getState().selectedSession?.id===i.id&&this.setState({isLoadingEarlierMessages:!1})}}}async send(t,i,s,o="inline"){const r=t.trim(),n=s!==void 0&&s.length>0;if(!n&&r.startsWith("/"))return this.runCommand(t);if(!n&&Fp(t))return this.runShell(t);const a=this.getState().selectedSession;if(!a||a.archived===!0)return;const l=a.id,p=f(this.getState());n&&this.markSendingPrompt(l,!0);try{if(n&&o==="folder"){const h=(await this.api.saveAttachments(a,s,p)).map(w=>Nn(w.path,!1)).join(" "),g=t===""?h:`${t}
|
|
23
|
+
|
|
24
|
+
${h}`;await this.api.prompt(a,g,i,p)}else await this.api.prompt(a,t,i,p,s);this.markCachedNewSessionPersisted(a)}catch(u){this.setState({error:String(u)})}finally{n&&this.markSendingPrompt(l,!1)}}markSendingPrompt(t,i){const s=this.getState().sendingPrompts;i?s[t]!==!0&&this.setState({sendingPrompts:{...s,[t]:!0}}):t in s&&this.setState({sendingPrompts:Un(s,t)})}async runShell(t){const i=this.getState().selectedSession;if(!(!i||i.archived===!0)){this.setState({messages:[...this.getState().messages,Pe("user",t)]});try{await this.api.shell(i,t,f(this.getState())),this.markCachedNewSessionPersisted(i)}catch(s){this.setState({messages:[...this.getState().messages,Pe("system",String(s))],error:String(s)})}}}async runCommand(t){const i=this.getState().selectedSession;if(!(!i||i.archived===!0)){this.setState({messages:[...this.getState().messages,Pe("user",t)]});try{this.applyCommandResult(await this.api.runCommand(i,t,f(this.getState()))),this.markCachedNewSessionPersisted(i)}catch(s){this.setState({messages:[...this.getState().messages,Pe("system",String(s))],error:String(s)})}}}async respondToCommand(t,i){const s=this.getState().selectedSession;if(s){this.setState({commandDialog:void 0});try{this.applyCommandResult(await this.api.respondToCommand(s,t,i,f(this.getState())))}catch(o){this.setState({error:String(o)})}}}cancelCommand(){this.setState({commandDialog:void 0})}applySessionStatus(t){this.applyStatus(t)}async archiveSession(t=this.getState().selectedSession){if(t){if(ee(t)){await this.deleteCachedNewSession(t);return}try{await this.api.archive(t,f(this.getState()));const i=this.getState(),s=eh(i.sessions,t.id,new Date().toISOString()),o=th(s,i.selectedSession?.id,t.id);this.setState({sessions:s}),o.type==="select"?await this.selectSession(o.session):o.type==="clear"&&this.deselectSession({forgetRememberedSelection:!0})}catch(i){this.setState({error:String(i)})}}}async archiveSessionWithDescendants(t=this.getState().selectedSession){if(!(!t||ee(t)))try{const i=await this.api.archiveWithDescendants(t,f(this.getState())),s=i.sessionIds!==void 0&&i.sessionIds.length>0?i.sessionIds:[t.id],o=this.getState(),r=Rs(o.sessions,s,new Date().toISOString()),n=Is(r,o.selectedSession?.id,s);this.setState({sessions:r}),n.type==="select"?await this.selectSession(n.session):n.type==="clear"&&this.deselectSession({forgetRememberedSelection:!0})}catch(i){this.setState({error:String(i)})}}async archiveSessions(t){const i=nr(t).filter(n=>n.archived!==!0&&!ee(n));if(i.length===0)return;const s=f(this.getState()),o=await Promise.allSettled(i.map(async n=>(await this.api.archive(n,s),n.id))),r=ar(o);if(r.length>0){const n=this.getState(),a=Rs(n.sessions,r,new Date().toISOString()),l=Is(a,n.selectedSession?.id,r);this.setState({sessions:a}),l.type==="select"?await this.selectSession(l.session):l.type==="clear"&&this.deselectSession({forgetRememberedSelection:!0})}this.applyBulkSessionError("Archive",o)}async deleteArchivedSessions(t){const i=nr(t).filter(a=>a.archived===!0);if(i.length===0)return;const s=f(this.getState()),o=this.getState().machineRuntimes[s];if(o?.ok!==!0||!Dt(o,lt.sessionsDeleteArchived)){this.setState({error:"Deleting archived sessions requires an updated Pi-Web runtime on this machine."});return}const r=await Promise.allSettled(i.map(async a=>(await this.api.deleteArchived(a,s),a.id))),n=ar(r);if(n.length>0){const a=new Set(n),l=this.getState(),p=l.sessions.filter(u=>!a.has(u.id));if(this.setState({sessions:p}),l.selectedSession!==void 0&&a.has(l.selectedSession.id)){const u=p.find(h=>h.archived!==!0)??p[0];u!==void 0?await this.selectSession(u):this.deselectSession({forgetRememberedSelection:!0})}}this.applyBulkSessionError("Delete",r)}async deleteCachedNewSession(t=this.getState().selectedSession){if(!ee(t))return;this.api.stop(t,f(this.getState())).catch(()=>{}),Xo(t.id,f(this.getState())),Ys(this.sessionCacheKey(t.id));const i=this.getState().sessions.filter(o=>o.id!==t.id);if(this.setState({sessions:i}),this.getState().selectedSession?.id!==t.id)return;const s=i.find(o=>o.archived!==!0)??i[0];s!==void 0?await this.selectSession(s):(this.clearActiveSession(),this.updateUrl())}async restoreSession(t=this.getState().selectedSession){if(t)try{await this.api.restore(t,f(this.getState()));const i={...t};delete i.archived,delete i.archivedAt,this.replaceSession(i),this.getState().selectedSession?.id===i.id&&await this.selectSession(i)}catch(i){this.setState({error:String(i)})}}async reloadSession(t=this.getState().selectedSession){if(t===void 0||ee(t)||t.archived===!0)return;const i=f(this.getState()),s=this.getState().machineRuntimes[i];if(s?.ok!==!0||!Dt(s,lt.sessionsReload)){this.setState({error:"Reloading sessions requires an updated Pi-Web runtime on this machine."});return}try{await this.api.reloadSession(t.id,i),this.transcripts.discard(this.sessionCacheKey(t.id)),this.getState().selectedSession?.id===t.id&&await this.selectSession(t,{updateUrl:!1})}catch(o){this.setState({error:String(o)})}}async detachParent(t=this.getState().selectedSession){if(t?.parentSessionPath!==void 0)try{await this.api.detachParent(t,f(this.getState()));const i={...t};delete i.parentSessionPath,this.replaceSession(i)}catch(i){this.setState({error:String(i)})}}async listModels(){const t=this.getState().selectedSession;if(!t||t.archived===!0)return[];try{return(await this.api.models(t,f(this.getState()))).models}catch(i){return this.setState({error:String(i)}),[]}}async setModel(t,i){const s=this.getState().selectedSession;if(!(!s||s.archived===!0))try{this.applyStatus(await this.api.setModel(s,t,i,f(this.getState()))),await this.refreshAvailableThinkingLevels()}catch(o){this.setState({error:String(o)})}}async cycleModel(t){const i=this.getState().selectedSession;if(!(!i||i.archived===!0))try{this.applyStatus(await this.api.cycleModel(i,t,f(this.getState()))),await this.refreshAvailableThinkingLevels()}catch(s){this.setState({error:String(s)})}}async listThinkingLevels(){const t=this.getState().selectedSession;if(!t||t.archived===!0)return[];try{return(await this.api.thinkingLevels(t,f(this.getState()))).levels}catch(i){return this.setState({error:String(i)}),[]}}async refreshAvailableThinkingLevels(){const t=this.getState().selectedSession;if(!t||t.archived===!0){this.getState().availableThinkingLevels.length>0&&this.setState({availableThinkingLevels:[]});return}const i=await this.listThinkingLevels();this.getState().selectedSession?.id===t.id&&this.setState({availableThinkingLevels:i})}async setThinkingLevel(t){const i=this.getState().selectedSession;if(!(!i||i.archived===!0))try{this.applyStatus(await this.api.setThinkingLevel(i,t,f(this.getState())))}catch(s){this.setState({error:String(s)})}}async cycleThinkingLevel(){const t=this.getState().selectedSession;if(!(!t||t.archived===!0))try{this.applyStatus(await this.api.cycleThinkingLevel(t,f(this.getState())))}catch(i){this.setState({error:String(i)})}}async stopActiveWork(){const t=this.getState().selectedSession;if(t)try{await this.api.abort(t,f(this.getState()))}catch(i){this.setState({error:String(i)})}}async refreshSelectedSession(t=this.getState().selectedSession?.id){const i=this.getState().selectedSession;if(!(t===void 0||i?.id!==t||i.archived===!0))try{this.flushPendingTranscriptEvents();const[s,o]=await Promise.all([this.api.messages(i,{limit:wt},f(this.getState())),this.api.status(i,f(this.getState()))]);if(this.getState().selectedSession?.id!==t)return;const r=this.transcripts.mergeHistory(this.sessionCacheKey(t),s);this.setState({...r,status:o,activity:this.getState().sessionActivities[t],isReceivingPartialStream:o.isStreaming}),this.applyStatus(o)}catch(s){this.getState().selectedSession?.id===t&&this.setState({error:String(s)})}}applyBulkSessionError(t,i){const s=oh(i);s.length!==0&&this.setState({error:`${t} failed for ${String(s.length)} session${s.length===1?"":"s"}: ${s.join("; ")}`})}sessionCacheKey(t){return En(f(this.getState()),t)}workspaceSelectionKey(t){return`${f(this.getState())}:${t}`}replaceSession(t){const i=this.getState().selectedSession;this.setState({sessions:this.getState().sessions.map(s=>s.id===t.id?t:s),selectedSession:i?.id===t.id?t:i})}async recreateCachedNewSession(t,i){try{const s=f(this.getState()),o=await this.api.startSession(t.cwd,s);Zo(o,s),op(this.sessionCacheKey(t.id),this.sessionCacheKey(o.id)),Xo(t.id,s);const r=$s(o,s);this.setState({sessions:[r,...this.getState().sessions.filter(n=>n.id!==t.id)],error:""}),await this.selectSession(r,{updateUrl:!1}),this.updateUrl(i?.updateUrl===!1?{replace:!0}:void 0)}catch(s){this.setState({error:String(s)})}}markCachedNewSessionPersisted(t){if(!ee(t))return;const i=this.getState().sessions.find(s=>s.id===t.id)??t;this.replaceSession(Ad(i))}applyCommandResult(t){if(t.type==="select"){this.setState({commandDialog:t});return}const i=(t.type==="unsupported",t.message);if(i!==void 0&&i!==""&&this.setState({messages:[...this.getState().messages,Pe(t.type==="unsupported"?"system":"tool",i)]}),t.type==="done"&&t.session){t.promptDraft!==void 0&&mi(this.sessionCacheKey(t.session.id),t.promptDraft);const s=this.getState().selectedSession,o=[t.session,...this.getState().sessions.filter(r=>r.id!==t.session?.id)];this.setState({sessions:o,selectedSession:s?.id===t.session.id?t.session:s}),s?.id!==t.session.id&&this.selectSession(t.session)}}applyActivity(t){this.setState({sessionActivities:{...this.getState().sessionActivities,[t.sessionId]:t},activity:this.getState().selectedSession?.id===t.sessionId?t:this.getState().activity})}applyStatus(t){const i=this.getState(),s=i.sessionActivities[t.sessionId]?.phase==="active"&&!Qe(t);this.setState({sessionStatuses:{...i.sessionStatuses,[t.sessionId]:t},...ch(i,t.sessionId,t.messageCount),...s?{sessionActivities:sh(i.sessionActivities,t.sessionId)}:{},status:i.selectedSession?.id===t.sessionId?t:i.status,activity:i.selectedSession?.id===t.sessionId&&s?void 0:i.activity}),this.catchupStreamSessionId===t.sessionId&&!t.isStreaming&&this.finishStreamCatchup(t.sessionId)}applySessionName(t,i){const s=r=>{if(r.id!==t)return r;const n={...r};return i===void 0||i===""?delete n.name:n.name=i,n},o=this.getState().selectedSession;this.setState({sessions:this.getState().sessions.map(s),selectedSession:o===void 0?void 0:s(o)})}applyEvent(t){const i=this.getState().selectedSession?.id;if(this.catchupStreamSessionId!==void 0&&this.catchupStreamSessionId===i){if(t.type==="message.end"||t.type==="agent.end"){this.finishStreamCatchup(this.catchupStreamSessionId);return}if(lh(t))return}if(dh(t)){this.queueTranscriptEvent(t);return}this.flushPendingTranscriptEvents();const s=this.transcripts.applyLiveEvent(this.getState().messages,t);s?this.setState({messages:s}):t.type==="status.update"?this.applyStatus(t.status):t.type==="activity.update"?this.applyActivity(t.activity):t.type==="session.name"&&this.applySessionName(t.sessionId,t.name)}queueTranscriptEvent(t){this.pendingTranscriptEvents.push(t),this.pendingTranscriptFrame===void 0&&(this.pendingTranscriptFrame=requestAnimationFrame(()=>{this.pendingTranscriptFrame=void 0,this.flushPendingTranscriptEvents()}))}flushPendingTranscriptEvents(){if(this.pendingTranscriptEvents.length===0)return;const t=this.pendingTranscriptEvents;this.pendingTranscriptEvents=[];let i=this.getState().messages;for(const s of t)i=this.transcripts.applyLiveEvent(i,s)??i;i!==this.getState().messages&&this.setState({messages:i})}clearPendingTranscriptEvents(){this.pendingTranscriptEvents=[],this.pendingTranscriptFrame!==void 0&&(cancelAnimationFrame(this.pendingTranscriptFrame),this.pendingTranscriptFrame=void 0)}finishStreamCatchup(t){this.catchupStreamSessionId===t&&(this.catchupStreamSessionId=void 0,this.getState().selectedSession?.id===t&&this.setState({isReceivingPartialStream:!1}),this.refreshMessages(t))}async refreshMessages(t){try{const i=this.getState().selectedSession;if(i?.id!==t)return;const s=await this.api.messages(i,{limit:wt},f(this.getState()));if(this.getState().selectedSession?.id!==t)return;this.setState(this.transcripts.mergeHistory(this.sessionCacheKey(t),s))}catch(i){this.getState().selectedSession?.id===t&&this.setState({error:String(i)})}}}function sh(e,t){return Un(e,t)}function Un(e,t){return Object.fromEntries(Object.entries(e).filter(([i])=>i!==t))}function nr(e){const t=new Set,i=[];for(const s of e)t.has(s.id)||(t.add(s.id),i.push(s));return i}function ar(e){return e.filter(rh).map(t=>t.value)}function oh(e){return e.filter(nh).map(t=>ah(t.reason))}function rh(e){return e.status==="fulfilled"}function nh(e){return e.status==="rejected"}function ah(e){return e instanceof Error?e.message:String(e)}function ch(e,t,i){if(i===void 0)return{};const o=e.sessions.some(n=>n.id===t&&n.messageCount!==i)?e.sessions.map(n=>n.id===t?{...n,messageCount:i}:n):void 0,r=e.selectedSession?.id===t&&e.selectedSession.messageCount!==i?{...e.selectedSession,messageCount:i}:e.selectedSession;return{...o===void 0?{}:{sessions:o},...r!==e.selectedSession?{selectedSession:r}:{}}}function lh(e){return["message.append","assistant.delta","assistant.thinking.delta","tool.start","tool.update","tool.end","shell.start","shell.chunk","shell.end","command.output","session.error"].includes(e.type)}function dh(e){return e.type==="assistant.delta"||e.type==="assistant.thinking.delta"||e.type==="shell.chunk"}function ph(e){return e instanceof Error&&e.message.toLowerCase().includes("session not found")}class hh{constructor(){this.workspaceIdsByProject=new Map}latestWorkspaceId(t){return this.workspaceIdsByProject.get(t)}rememberWorkspace(t){this.workspaceIdsByProject.set(t.projectId,t.id)}forgetProject(t){this.workspaceIdsByProject.delete(t)}}const uh="pi-web:workspace-selection:v1";class fh{constructor(t=Ft()){this.workspaceIdsByProject=new Wi(uh,io,t)}latestWorkspaceId(t){return this.workspaceIdsByProject.get(t)}rememberWorkspace(t){this.workspaceIdsByProject.set(t.projectId,t.id)}forgetProject(t){this.workspaceIdsByProject.delete(t)}}function gh(e,t){const i=t?.targetWorkspaceId;if(i!==void 0&&i!=="")return e.find(o=>o.id===i);const s=t?.latestWorkspaceId;return s!==void 0&&s!==""?e.find(o=>o.id===s)??e[0]:e[0]}class mh{constructor(t,i,s,o,r=new hh,n={}){this.getState=t,this.setState=i,this.updateUrl=s,this.sessions=o,this.workspaceSelection=r,this.api=n.api??z}clearSelection(t){this.sessions.clearActiveSession(),this.setState({selectedProject:void 0,selectedWorkspace:void 0,workspaces:[],isLoadingWorkspaces:!1,...si()}),t?.updateUrl!==!1&&this.updateUrl()}forgetProject(t){this.workspaceSelection.forgetProject(Gi(f(this.getState()),t));const i=Object.fromEntries(Object.entries(this.getState().workspacesByProjectId).filter(([s])=>s!==t));this.setState({workspacesByProjectId:i})}async selectProject(t,i){const s=f(this.getState());this.sessions.clearActiveSession(),this.setState({selectedProject:t,selectedWorkspace:void 0,workspaces:[],isLoadingWorkspaces:!0,...si()});try{const o=await this.api.workspaces(t.id,s);if(f(this.getState())!==s||this.getState().selectedProject?.id!==t.id)return;this.setState({workspaces:o,workspacesByProjectId:{...this.getState().workspacesByProjectId,[t.id]:o},isLoadingWorkspaces:!1});const r=gh(o,{targetWorkspaceId:i?.workspaceId,latestWorkspaceId:this.workspaceSelection.latestWorkspaceId(Gi(s,t.id))});r?await this.selectWorkspace(r,{sessionId:i?.sessionId,updateUrl:i?.updateUrl}):i?.updateUrl!==!1&&this.updateUrl()}catch(o){f(this.getState())===s&&this.getState().selectedProject?.id===t.id&&this.setState({error:String(o),isLoadingWorkspaces:!1})}}async selectWorkspace(t,i){const s=f(this.getState());this.workspaceSelection.rememberWorkspace({...t,projectId:Gi(s,t.projectId)}),this.sessions.clearActiveSession(),this.setState({selectedWorkspace:t,isLoadingWorkspaces:!1,...si()});try{const o=Md(t.path,await this.api.sessions(t.path,s),s);if(f(this.getState())!==s||this.getState().selectedWorkspace?.id!==t.id||this.getState().selectedProject?.id!==t.projectId)return;this.setState({sessions:o});const r=this.sessions.preferredSession(t.path,o,i?.sessionId);r?await this.sessions.selectSession(r,{updateUrl:i?.updateUrl}):i?.updateUrl!==!1&&this.updateUrl()}catch(o){f(this.getState())===s&&this.getState().selectedWorkspace?.id===t.id&&this.setState({error:String(o)})}}async refreshProjectWorkspaces(t){const i=this.getState().projects.find(o=>o.id===t);if(i===void 0)throw new Error("Project not found");const s=await this.api.workspaces(i.id,f(this.getState()));return this.applyProjectWorkspaces(i.id,s),s}async refreshAfterWorkspaceDeleted(t,i){const s=await this.refreshProjectWorkspaces(t),o=this.getState();if(o.selectedProject?.id!==t||o.selectedWorkspace?.id!==i)return;const r=bh(s);r!==void 0?await this.selectWorkspace(r):this.clearSelection()}applyProjectWorkspaces(t,i){const s=this.getState(),o={...s.workspacesByProjectId,[t]:i};s.selectedProject?.id===t?this.setState({workspaces:i,workspacesByProjectId:o}):this.setState({workspacesByProjectId:o})}}function vh(e){return e!==void 0&&e.isGitWorktree&&!e.isMain}function bh(e){return e.find(t=>t.isMain)??e[0]}const wh="pi-web:machine-navigation:v1";class yh{constructor(t=Ft()){this.snapshotsByMachine=new Wi(wh,xh,t)}latest(t){const i=this.snapshotsByMachine.get(t);return i?.machineId===t?dr(i):void 0}remember(t){this.snapshotsByMachine.set(t.machineId,dr(t))}forget(t){this.snapshotsByMachine.delete(t)}}function Sh(e){return{machineId:e,surface:{}}}function cr(e){const t=e.selectedWorkspace!==void 0;return{machineId:e.selectedMachine?.id??An,projectId:e.selectedProject?.id,workspaceId:e.selectedWorkspace?.id,sessionId:e.selectedSession?.id,tool:e.workspaceTool,view:e.mainView,surface:{selectedFilePath:t?e.selectedFilePath:void 0,selectedDiffPath:t?e.selectedDiffPath:void 0,selectedTerminalId:t?e.selectedTerminalId:void 0}}}function lr(e){return{machineId:e.machineId,projectId:e.projectId,workspaceId:e.workspaceId,sessionId:e.sessionId,tool:e.tool,view:e.view==="navigation"?void 0:e.view}}function dr(e){return{...e,surface:{...e.surface}}}function xh(e){if(!qn(e))return;const t=Oe(e,"machineId");if(t===void 0)return;const i=Hn(Oe(e,"tool")),s=$h(Oe(e,"view"));return{machineId:t,projectId:Oe(e,"projectId"),workspaceId:Oe(e,"workspaceId"),sessionId:Oe(e,"sessionId"),...i===void 0?{}:{tool:i},...s===void 0?{}:{view:s},surface:kh(e.surface)}}function kh(e){return qn(e)?{selectedFilePath:Oe(e,"selectedFilePath"),selectedDiffPath:Oe(e,"selectedDiffPath"),selectedTerminalId:Oe(e,"selectedTerminalId")}:{}}function $h(e){return e==="navigation"||e==="chat"?e:Hn(e)}function Hn(e){return Ph(e)?e:void 0}function Ph(e){return e!==void 0&&/^[a-z][a-z0-9.-]*:[a-z][a-z0-9.-]*$/u.test(e)}function Oe(e,t){const i=e[t];return typeof i=="string"&&i!==""?i:void 0}function qn(e){return typeof e=="object"&&e!==null}const Rh="pi-web:terminal-selection:v1";class Ih{constructor(t=Ft()){this.terminalIdsByCwd=new Wi(Rh,io,t)}latestTerminalId(t){return this.terminalIdsByCwd.get(t)}rememberTerminal(t,i){this.terminalIdsByCwd.set(t,i)}forgetWorkspace(t){this.terminalIdsByCwd.delete(t)}forgetTerminal(t){for(const[i,s]of this.terminalIdsByCwd.entries())s===t&&this.terminalIdsByCwd.delete(i)}}function zw(e,t){const i=t?.targetTerminalId;if(i!==void 0&&i!=="")return e.find(o=>o.id===i);const s=t?.latestTerminalId;return s!==void 0&&s!==""?e.find(o=>o.id===s)??e.find(o=>!o.exited)??e[0]:e.find(o=>!o.exited)??e[0]}function Bw(e){return e.find(t=>!t.exited)??e[0]}const Kn=1200,Ch=["mod","alt","shift"];class Th{constructor(){this.pendingTokens=[]}handle(t,i,s={}){const o=Gn(t);if(o===void 0)return!1;const r=so(i,s.shortcuts,{enabledOnly:!0}).filter(n=>n.active).map(n=>({action:n.action,tokens:n.tokens}));if(this.pendingTokens.length>0){if(this.handleSequence([...this.pendingTokens,o],r))return!0;if(this.clearPending(),!Wt(o))return!1}else if(!Wt(o))return!1;return this.handleSequence([o],r)}reset(){this.clearPending()}handleSequence(t,i){const s=i.find(r=>Fh(r.tokens,t));return s!==void 0?(this.clearPending(),s.action.run(),!0):i.some(r=>oo(r.tokens,t))?(this.setPending(t),!0):!1}setPending(t){this.clearPending(),this.pendingTokens=t,this.pendingTimer=globalThis.setTimeout(()=>{this.pendingTokens=[],this.pendingTimer=void 0},Kn)}clearPending(){this.pendingTokens=[],this.pendingTimer!==void 0&&(globalThis.clearTimeout(this.pendingTimer),this.pendingTimer=void 0)}}function so(e,t,i={}){const s=e.flatMap((p,u)=>{if(i.enabledOnly===!0&&p.enabled===!1)return[];const h=Mh(p,t,u);return h===void 0?[]:[h]}),o=new Map;for(const p of s)o.set(p.key,[...o.get(p.key)??[],p]);const r=new Map;for(const p of o.values()){const u=[...p].sort(Cs)[0];u!==void 0&&r.set(u.key,u)}const n=[...r.values()].sort(Dh),a=new Map,l=new Map;for(const p of s){const u=r.get(p.key);if(u===void 0)continue;const h=Wh(u,n)??u;l.set(p,h),p!==h&&a.set(h,[...a.get(h)??[],p])}return s.map(p=>{const u=l.get(p),h=u===p,g=u===void 0||h?void 0:pr(u),w=h?[...a.get(p)??[]].sort(Cs).map(pr):[];return{...p,active:h,shadows:w,...g===void 0?{}:{shadowedBy:g}}}).sort((p,u)=>p.order-u.order)}function Yi(e){return Jn(e,{requireFirstChordActivator:!0})}function Vn(e){const t=Jn(e,{requireFirstChordActivator:!1});return t.ok?t.tokens:[]}function ri(e){return Vn(e).map(t=>t.split("+").map(Zn).join("+")).join(" ")}function Gn(e){if(e.isComposing)return;const t=Lh(e.key);if(t===void 0)return;const i=[];return(e.metaKey||e.ctrlKey)&&i.push("mod"),e.altKey&&i.push("alt"),e.shiftKey&&i.push("shift"),i.push(t),i.join("+")}function Wt(e){return e.split("+").includes("mod")||e.split("+").includes("alt")}function Mh(e,t,i){const s=Ah(e.id,t);if(s===null)return;const o=s??e.shortcut;if(o===void 0||o==="")return;const r=Vn(o),n=r[0];if(!(n===void 0||!Wt(n)))return{action:e,shortcut:r.join(" "),source:s===void 0?"default":"custom",tokens:r,key:Eh(r),order:i}}function Ah(e,t){if(!(t===void 0||!Object.hasOwn(t,e)))return t[e]}function Eh(e){return e.join("\0")}function pr(e){return{action:e.action,shortcut:e.shortcut,source:e.source}}function Cs(e,t){return hr(e.source)-hr(t.source)||ur(e.action.id,t.action.id)||ur(e.action.title,t.action.title)||e.order-t.order}function Dh(e,t){return e.tokens.length-t.tokens.length||Cs(e,t)}function Wh(e,t){return t.find(i=>i!==e&&i.tokens.length<e.tokens.length&&oo(e.tokens,i.tokens))}function hr(e){switch(e){case"custom":return 0;case"default":return 1}}function ur(e,t){return e<t?-1:e>t?1:0}function Jn(e,t){const i=e.trim().toLowerCase().replace(/\s*\+\s*/gu,"+");if(i==="")return{ok:!1,message:"Enter a shortcut, choose None, or reset to the default."};const s=[],o=i.split(/\s+/u).filter(r=>r!=="");for(const[r,n]of o.entries()){const a=Oh(n);if(!a.ok)return a;if(r===0&&t.requireFirstChordActivator&&!Wt(a.token))return{ok:!1,message:"Shortcuts must start with Ctrl/⌘ or Alt so normal typing is not captured."};s.push(a.token)}return{ok:!0,shortcut:s.join(" "),tokens:s}}function Oh(e){const t=e.split("+").filter(r=>r!=="");if(t.length===0)return{ok:!1,message:"Shortcut chords must include a key."};const i=new Set;let s;for(const r of t){const n=_h(r);if(n!==void 0){if(i.has(n))return{ok:!1,message:`Shortcut has duplicate ${Zn(n)} modifiers.`};i.add(n);continue}const a=Qn(r);if(a===void 0)return{ok:!1,message:`Unsupported shortcut key: ${r}`};if(s!==void 0)return{ok:!1,message:"Each shortcut chord can include only one non-modifier key."};s=a}return s===void 0?{ok:!1,message:"Shortcut chords must include a key."}:{ok:!0,token:[...Ch.filter(r=>i.has(r)),s].join("+")}}function _h(e){switch(e){case"mod":case"meta":case"cmd":case"command":case"ctrl":case"control":case"primary":return"mod";case"alt":case"option":case"opt":return"alt";case"shift":return"shift";default:return}}function Qn(e){const t=jh(e);if(t!==void 0)return t;if(/^f(?:[1-9]|1[0-9]|2[0-4])$/u.test(e)||e.length===1)return e}function Lh(e){if(e===" ")return"space";const t=e.toLowerCase();return Qn(t)}function jh(e){switch(e){case" ":case"spacebar":case"space":return"space";case"esc":case"escape":return"escape";case"return":case"enter":return"enter";case"del":case"delete":return"delete";case"backspace":return"backspace";case"tab":return"tab";case"up":case"arrowup":return"arrowup";case"down":case"arrowdown":return"arrowdown";case"left":case"arrowleft":return"arrowleft";case"right":case"arrowright":return"arrowright";case"pageup":case"pagedown":case"home":case"end":return e;case"+":case"plus":return"plus";case"period":case"dot":return".";case"comma":return",";case"slash":return"/";case"backslash":return"\\";case"minus":return"-";default:return}}function Zn(e){return e==="mod"?fr()?"⌘":"Ctrl":e==="shift"?"Shift":e==="alt"?fr()?"⌥":"Alt":e==="enter"?"Enter":e==="escape"?"Esc":e==="space"?"Space":e==="tab"?"Tab":e==="backspace"?"Backspace":e==="delete"?"Delete":e==="arrowup"?"↑":e==="arrowdown"?"↓":e==="arrowleft"?"←":e==="arrowright"?"→":e==="pageup"?"PageUp":e==="pagedown"?"PageDown":e==="home"?"Home":e==="end"?"End":e==="plus"?"+":/^f(?:[1-9]|1[0-9]|2[0-4])$/u.test(e)||e.length===1?e.toUpperCase():`${e.charAt(0).toUpperCase()}${e.slice(1)}`}function Fh(e,t){return e.length===t.length&&oo(e,t)}function oo(e,t){return t.every((i,s)=>e[s]===i)}function fr(){return typeof navigator<"u"&&navigator.userAgent.toLowerCase().includes("mac")}const ro="themes:classic",Nh="themes:pi-web-dark",zh={themeId:Nh,auto:!0},Xn="pi-web-app-theme",Bh=["--pi-bg","--pi-surface","--pi-surface-hover","--pi-terminal-bg","--pi-terminal-text","--pi-border","--pi-border-muted","--pi-text","--pi-text-secondary","--pi-text-bright","--pi-muted","--pi-dim","--pi-accent","--pi-accent-border","--pi-selection-bg","--pi-success","--pi-success-border","--pi-success-bg","--pi-success-surface","--pi-success-ring","--pi-warning","--pi-warning-border","--pi-warning-surface","--pi-danger","--pi-purple","--pi-purple-border","--pi-purple-surface","--pi-overlay","--pi-shadow-soft","--pi-shadow","--pi-shadow-strong","--pi-bg-overlay-soft","--pi-bg-overlay","--pi-success-bg-overlay","--pi-terminal-selection"],Uh=/^[a-z][a-z0-9.-]*:[a-z][a-z0-9.-]*$/u;function Hh(){try{const e=window.localStorage.getItem(Xn);return e===null?void 0:Jh(e)}catch{return}}function qh(e){try{window.localStorage.setItem(Xn,JSON.stringify(e))}catch{}}function Kh(e){const t=document.documentElement;t.dataset.piWebTheme=e.id,t.style.colorScheme=e.colorScheme;for(const i of Bh){const s=e.tokens[i];typeof s=="string"&&s!==""?t.style.setProperty(i,s):t.style.removeProperty(i)}}function Vh(e){const t=Gh(e.themes,e.fallbackThemeId??ro),i=e.themes.find(n=>n.id===e.preference.themeId)??t;if(i===void 0)return{selectedTheme:void 0,activeTheme:void 0,selectedThemePair:void 0,fallbackTheme:t};const s=Yn(e.themePairs,i.id);if(!e.preference.auto||s===void 0)return{selectedTheme:i,activeTheme:i,selectedThemePair:s,fallbackTheme:t};const o=e.prefersLight?s.light:s.dark,r=e.themes.find(n=>n.id===o)??i;return{selectedTheme:i,activeTheme:r,selectedThemePair:s,fallbackTheme:t}}function Gh(e,t=ro){return e.find(i=>i.id===t)??e[0]}function Yn(e,t){return e.find(i=>i.light===t||i.dark===t)}function Jh(e){const t=e.trim();if(t!=="")try{const i=JSON.parse(t);return Qh(i)?i:void 0}catch{return}}function Qh(e){if(!Zh(e))return!1;const t=e.themeId,i=e.auto;return Xh(t)&&typeof i=="boolean"}function Zh(e){return typeof e=="object"&&e!==null}function Xh(e){return typeof e=="string"&&Uh.test(e)}const Yh="management";function eu(e){return tu(iu())===Yh}function tu(e){if(e===void 0||e==="")return;const t=new URLSearchParams(e).get("embed")?.trim();return t===""?void 0:t}function iu(){return typeof window>"u"?void 0:window.location.search}const su="workspace.delete",ou="pi.operation",ru="target.workspaceId";function nu(e){return{...e===void 0?{}:{projectId:e},metadata:{[ou]:su}}}function au(e){const t={};for(const i of e){const s=Ts(i);if(s===void 0)continue;const o=t[s];(o===void 0||i.createdAt.localeCompare(o.createdAt)>=0)&&(t[s]=i)}return t}function cu(e){return Object.entries(e).filter(([,t])=>yi(t)).map(([t])=>t)}function ea(e,t){if(t===void 0)return!1;const i=e.workspaceDeletionRuns[t.id];return i!==void 0&&yi(i)}function Ts(e){return e.metadata[ru]}function yi(e){return e.status==="queued"||e.status==="running"}function gr(){return[{id:"actions.show",title:"显示操作",description:"打开命令面板",shortcut:"mod+k",group:"通用",run:e=>{e.openActionPalette()}},{id:"prompt.focus",title:"聚焦提示词输入框",description:"将键盘焦点移动到消息编辑器",shortcut:"mod+g c",group:"通用",enabled:e=>e.state.selectedSession!==void 0,run:e=>{e.focusPrompt()}},{id:"machine.add",title:"添加机器",description:"注册另一个可从当前网关访问的 PI WEB 运行时",group:"机器",run:e=>e.addMachine()},{id:"machine.refresh",title:"刷新所选机器",description:"检查所选 PI WEB 运行时是否在线",group:"机器",run:e=>e.refreshSelectedMachine()},{id:"machine.open",title:"打开所选机器的 PI WEB",description:"在新标签页中直接打开所选远程 PI WEB",group:"机器",enabled:e=>e.state.selectedMachine?.kind==="remote"&&e.state.selectedMachine.baseUrl!==void 0,run:e=>e.openSelectedMachine()},{id:"machine.remove",title:"移除所选机器",description:"从当前网关移除所选远程机器",group:"机器",enabled:e=>e.state.selectedMachine?.kind==="remote",run:e=>e.removeSelectedMachine()},{id:"project.add",title:"添加项目",group:"项目",run:e=>e.addProject()},{id:"auth.login",title:"配置提供商认证",description:"运行 /login,但不将认证绑定到某个会话",group:"通用",run:e=>e.configureAuth()},{id:"auth.logout",title:"移除提供商认证",description:"针对已保存的 pi 凭据运行 /logout",group:"通用",run:e=>e.logoutAuth()},{id:"theme.select",title:"选择主题",description:"选择 PI WEB 颜色主题",group:"偏好设置",run:e=>{e.openThemePicker()}},{id:"settings.open",title:"打开设置",description:"管理 PI WEB 配置和键盘快捷键",shortcut:"mod+,",group:"偏好设置",run:e=>{e.piWebUnstable?.openSettings?.()}},{id:"app.reload-page",title:"完整重载页面",description:"重新加载 PI WEB 浏览器页面",group:"通用",run:e=>{e.reloadPage()}},{id:"view.chat",title:"转到聊天",shortcut:"mod+1",group:"导航",run:e=>{e.focusPrompt()}},{id:"view.files",title:"转到文件",shortcut:"mod+2",group:"导航",enabled:yt,run:e=>{e.selectMainView("core:workspace.files")}},{id:"view.git",title:"转到 Git",shortcut:"mod+3",group:"导航",enabled:mr,run:e=>{e.selectMainView("core:workspace.git")}},{id:"view.terminal",title:"转到终端",shortcut:"mod+4",group:"导航",enabled:yt,run:e=>{e.selectMainView("core:workspace.terminal")}},{id:"workspace.refresh-files",title:"刷新文件",shortcut:"mod+shift+f",group:"工作区",enabled:yt,run:e=>e.refreshFiles()},{id:"workspace.refresh-git",title:"刷新 Git",shortcut:"mod+shift+g",group:"工作区",enabled:mr,run:e=>e.refreshGit()},{id:"workspace.refresh-current",title:"刷新当前面板",shortcut:"mod+shift+r",group:"工作区",enabled:yt,run:e=>e.state.workspaceTool==="core:workspace.git"&&e.state.selectedWorkspace?.isGitRepo===!0?e.refreshGit():e.refreshFiles()},{id:"workspace.delete",title:"删除工作区",description:"移除所选 Git worktree",group:"工作区",enabled:lu,run:e=>e.deleteWorkspace()},{id:"session.start",title:"启动会话",shortcut:"mod+enter",group:"会话",enabled:yt,run:e=>e.startSession()},{id:"session.archive",title:"归档会话",description:"归档所选会话",group:"会话",enabled:du,run:e=>e.archiveSession()},{id:"session.reload",title:"Reload Session",description:"Re-read the selected session from disk to pick up entries written by another process",group:"Session",enabled:hu,run:e=>e.reloadSession()},{id:"session.delete",title:"删除新会话",description:"删除所选浏览器缓存的新会话",group:"会话",enabled:pu,run:e=>e.deleteCachedNewSession()},{id:"session.stop",title:"停止活动工作",shortcut:"mod+.",group:"会话",enabled:e=>e.state.selectedSession!==void 0&&Qe(e.state.status,e.state.activity),run:e=>e.stopActiveWork()}]}function yt(e){return e.state.selectedWorkspace!==void 0}function mr(e){return e.state.selectedWorkspace?.isGitRepo===!0}function lu(e){const t=e.state.selectedWorkspace;return t!==void 0&&t.isGitWorktree&&!t.isMain&&!ea(e.state,t)}function du(e){const t=e.state.selectedSession;return t!==void 0&&t.archived!==!0&&!ee(t)}function pu(e){return ee(e.state.selectedSession)}function hu(e){const t=e.state.selectedSession;if(t===void 0||t.archived===!0||ee(t))return!1;const i=e.state.machineRuntimes[f(e.state)];return i?.ok!==!0||!Dt(i,lt.sessionsReload)?!1:!Qe(e.state.status,e.state.activity)}const uu="modulepreload",fu=function(e){return"/"+e},vr={},ta=function(t,i,s){let o=Promise.resolve();if(i&&i.length>0){let l=function(p){return Promise.all(p.map(u=>Promise.resolve(u).then(h=>({status:"fulfilled",value:h}),h=>({status:"rejected",reason:h}))))};document.getElementsByTagName("link");const n=document.querySelector("meta[property=csp-nonce]"),a=n?.nonce||n?.getAttribute("nonce");o=l(i.map(p=>{if(p=fu(p),p in vr)return;vr[p]=!0;const u=p.endsWith(".css"),h=u?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${p}"]${h}`))return;const g=document.createElement("link");if(g.rel=u?"stylesheet":uu,u||(g.as="script"),g.crossOrigin="",g.href=p,a&&g.setAttribute("nonce",a),document.head.appendChild(g),u)return new Promise((w,P)=>{g.addEventListener("load",w),g.addEventListener("error",()=>P(new Error(`Unable to preload CSS for ${p}`)))})}))}function r(n){const a=new Event("vite:preloadError",{cancelable:!0});if(a.payload=n,window.dispatchEvent(a),!a.defaultPrevented)throw n}return o.then(n=>{for(const a of n||[])a.status==="rejected"&&r(a.reason);return t().catch(r)})},gu=10*1024*1024,mu="10 MB";function vu(e){return typeof e!="string"?c`<span class="tab-custom-icon" aria-hidden="true">${e}</span>`:ni(e)}function ni(e){switch(e){case"navigation":return ue`
|
|
25
|
+
<svg class="tab-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false">
|
|
26
|
+
<circle cx="6" cy="7" r="1.5"></circle>
|
|
27
|
+
<path d="M10 7h8"></path>
|
|
28
|
+
<circle cx="6" cy="12" r="1.5"></circle>
|
|
29
|
+
<path d="M10 12h8"></path>
|
|
30
|
+
<circle cx="6" cy="17" r="1.5"></circle>
|
|
31
|
+
<path d="M10 17h8"></path>
|
|
32
|
+
</svg>
|
|
33
|
+
`;case"chat":return ue`
|
|
34
|
+
<svg class="tab-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false">
|
|
35
|
+
<path d="M7 5h10a3 3 0 0 1 3 3v5a3 3 0 0 1-3 3h-6l-5 4v-4H7a3 3 0 0 1-3-3V8a3 3 0 0 1 3-3Z"></path>
|
|
36
|
+
<path d="M8 9h8"></path>
|
|
37
|
+
<path d="M8 13h5"></path>
|
|
38
|
+
</svg>
|
|
39
|
+
`;case"files":return ue`
|
|
40
|
+
<svg class="tab-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false">
|
|
41
|
+
<path d="M3 7a2 2 0 0 1 2-2h4l2 2.5h8a2 2 0 0 1 2 2V17a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2Z"></path>
|
|
42
|
+
</svg>
|
|
43
|
+
`;case"git":return ue`
|
|
44
|
+
<svg class="tab-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false">
|
|
45
|
+
<circle cx="6" cy="6" r="2"></circle>
|
|
46
|
+
<circle cx="18" cy="6" r="2"></circle>
|
|
47
|
+
<circle cx="12" cy="18" r="2"></circle>
|
|
48
|
+
<path d="M8 6h6"></path>
|
|
49
|
+
<path d="M6 8v2a6 6 0 0 0 6 6"></path>
|
|
50
|
+
<path d="M18 8v2a6 6 0 0 1-6 6"></path>
|
|
51
|
+
</svg>
|
|
52
|
+
`;case"terminal":return ue`
|
|
53
|
+
<svg class="tab-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false">
|
|
54
|
+
<rect x="3" y="5" width="18" height="14" rx="2"></rect>
|
|
55
|
+
<path d="m7 10 3 3-3 3"></path>
|
|
56
|
+
<path d="M12 16h5"></path>
|
|
57
|
+
</svg>
|
|
58
|
+
`}}function br(){return[{id:"workspace.files",title:"文件",icon:ni("files"),order:10,render:bu},{id:"workspace.git",title:"Git",icon:ni("git"),order:20,visible:({workspace:e})=>e.isGitRepo,render:Mu},{id:"workspace.terminal",title:"终端",icon:ni("terminal"),order:30,badge:e=>e.activeTerminalCount>0?e.activeTerminalCount:void 0,render:Tu}]}function bu(e){const t=e.machine.kind==="local";return c`
|
|
59
|
+
<section class="toolbar">
|
|
60
|
+
<strong>文件</strong>
|
|
61
|
+
${e.fileTreeStale?c`<span class="stale">过期</span>`:null}
|
|
62
|
+
<div class="toolbar-actions">
|
|
63
|
+
<button @click=${e.onRefreshFiles}>刷新</button>
|
|
64
|
+
<button @click=${()=>{Su(e)}}>新建文件</button>
|
|
65
|
+
<button @click=${()=>{xu(e)}}>新建目录</button>
|
|
66
|
+
${e.selectedFilePath===void 0?null:c`
|
|
67
|
+
${Nt(e)==="file"?c`<button @click=${()=>{e.onDownloadSelectedFile()}}>下载</button>`:null}
|
|
68
|
+
<button @click=${()=>{ku(e)}}>移动</button>
|
|
69
|
+
<button class="danger" @click=${()=>{$u(e)}}>删除</button>
|
|
70
|
+
`}
|
|
71
|
+
${t?c`
|
|
72
|
+
<label class="file-upload-button" role="button" tabindex="0" aria-label="上传文件" @keydown=${wu}>
|
|
73
|
+
上传
|
|
74
|
+
<input type="file" multiple hidden @change=${i=>{yu(e,i)}} />
|
|
75
|
+
</label>
|
|
76
|
+
`:c`<span class="file-upload-button disabled" title="远端机器暂不支持上传" aria-disabled="true">上传</span>`}
|
|
77
|
+
</div>
|
|
78
|
+
</section>
|
|
79
|
+
<section class="split">
|
|
80
|
+
<div class="list tree">
|
|
81
|
+
${e.fileTree.length===0?c`<p class="muted">尚未加载文件。</p>`:e.fileTree.map(i=>ia(e,i,0))}
|
|
82
|
+
</div>
|
|
83
|
+
<div class="viewer">
|
|
84
|
+
${Iu(e)}
|
|
85
|
+
</div>
|
|
86
|
+
</section>
|
|
87
|
+
`}function wu(e){if(e.key!=="Enter"&&e.key!==" ")return;e.preventDefault();const t=e.currentTarget;if(!(t instanceof HTMLElement))return;const i=t.querySelector("input[type='file']");i instanceof HTMLInputElement&&i.click()}function yu(e,t){const i=t.currentTarget;!(i instanceof HTMLInputElement)||i.files===null||(e.onUploadFiles(Array.from(i.files)),i.value="")}function Su(e){const t=window.prompt("新建文件路径",sa(e,"new-file.txt"));t===null||t.trim()===""||e.onCreateFile(t.trim())}function xu(e){const t=window.prompt("新建目录路径",sa(e,"new-folder"));t===null||t.trim()===""||e.onCreateDirectory(t.trim())}function ku(e){const t=e.selectedFilePath;if(t===void 0||t==="")return;const i=window.prompt(Nt(e)==="directory"?"移动或重命名目录到":"移动或重命名文件到",t);i===null||i.trim()===""||i.trim()===t||e.onMoveSelectedPath(i.trim())}function $u(e){const t=e.selectedFilePath;if(t===void 0||t==="")return;const i=Nt(e)==="directory"?"空目录":"文件";window.confirm(`删除${i} ${t}?`)&&e.onDeleteSelectedPath()}function ia(e,t,i){const s=e.expandedDirs[t.path],o=s!==void 0,r=e.selectedFilePath===t.path;return c`
|
|
88
|
+
<button class=${r?"row selected":"row"} style=${`--depth:${String(i)}`} @click=${()=>{Pu(e,t)}}>
|
|
89
|
+
<span>${t.type==="directory"?o?"▾":"▸":"·"}</span>
|
|
90
|
+
<span>${t.name}</span>
|
|
91
|
+
</button>
|
|
92
|
+
${o?s.map(n=>ia(e,n,i+1)):null}
|
|
93
|
+
`}function Pu(e,t){t.type==="directory"?(e.onSelectDirectory(t.path),e.onExpandDir(t.path)):e.onSelectFile(t.path)}function Nt(e){const t=e.selectedFilePath;return t===void 0?"file":Ru(e,t)?.type??"file"}function sa(e,t){const i=e.selectedFilePath;if(i===void 0||i==="")return t;if(Nt(e)==="directory")return`${i}/${t}`;const s=i.lastIndexOf("/");return s===-1?t:`${i.slice(0,s)}/${t}`}function Ru(e,t){const i=e.fileTree.find(s=>s.path===t);if(i!==void 0)return i;for(const s of Object.values(e.expandedDirs)){const o=s.find(r=>r.path===t);if(o!==void 0)return o}}function Iu(e){const t=e.selectedFileContent;return e.selectedFilePath===void 0||e.selectedFilePath===""?c`<p class="muted">请选择文件。</p>`:Nt(e)==="directory"?c`<p class="muted">已选择目录 ${e.selectedFilePath}。</p>`:t===void 0?c`<p class="muted">正在加载 ${e.selectedFilePath}…</p>`:t.mediaType==="image"?Cu(e,t):t.binary?c`<p class="muted">二进制文件:${t.path} · ${Ms(t.size)}</p>`:(oa(),c`
|
|
94
|
+
<div class="viewer-header"><strong>${t.path}</strong><small>${t.language??"文本"}${t.truncated?" · 已截断":""}</small></div>
|
|
95
|
+
<code-viewer .content=${t.content} .language=${t.language}></code-viewer>
|
|
96
|
+
`)}function Cu(e,t){const i=`${t.mimeType??"image"} · ${Ms(t.size)}`;if(t.size>gu)return c`
|
|
97
|
+
<div class="viewer-header"><strong>${t.path}</strong><small>${i}</small></div>
|
|
98
|
+
<p class="muted">图片过大,无法预览:${Ms(t.size)} · 限制 ${mu}</p>
|
|
99
|
+
`;const s=Ql(e.workspace.projectId,e.workspace.id,t.path,{modifiedAt:t.modifiedAt,machineId:e.machine.id});return c`
|
|
100
|
+
<div class="viewer-header"><strong>${t.path}</strong><small>${i}</small></div>
|
|
101
|
+
<div class="image-preview">
|
|
102
|
+
<img src=${s} alt=${t.path} decoding="async" />
|
|
103
|
+
</div>
|
|
104
|
+
`}function Tu(e){return Du(),c`<terminal-panel .workspace=${e.workspace} .machineId=${e.machine.id} .selectedTerminalId=${e.selectedTerminalId} .autoStart=${e.terminalAutoStart} .onSelectTerminal=${e.onSelectTerminal}></terminal-panel>`}function Mu(e){const t=e.gitStatus;return c`
|
|
105
|
+
<section class="toolbar">
|
|
106
|
+
<strong>Git</strong>
|
|
107
|
+
${e.gitStale?c`<span class="stale">过期</span>`:null}
|
|
108
|
+
<button @click=${e.onRefreshGit}>刷新</button>
|
|
109
|
+
</section>
|
|
110
|
+
<section class="split">
|
|
111
|
+
<div class="list">
|
|
112
|
+
${t===void 0?c`<p class="muted">尚未加载状态。</p>`:t.isGitRepo?c`
|
|
113
|
+
<p class="summary">${Wu(t)}</p>
|
|
114
|
+
${t.files.length===0?c`<p class="muted">没有变更。</p>`:t.files.map(i=>c`
|
|
115
|
+
<button class="row ${e.selectedDiffPath===i.path?"selected":""}" @click=${()=>{e.onSelectDiff(i.path)}}>
|
|
116
|
+
<span>${Ou(i.index,i.workingTree)}</span>
|
|
117
|
+
<span>${i.path}</span>
|
|
118
|
+
</button>
|
|
119
|
+
`)}
|
|
120
|
+
`:c`<p class="muted">不是 Git 仓库。</p>`}
|
|
121
|
+
</div>
|
|
122
|
+
<div class="viewer">
|
|
123
|
+
${Au(e)}
|
|
124
|
+
</div>
|
|
125
|
+
</section>
|
|
126
|
+
`}function Au(e){if(e.selectedDiffPath===void 0||e.selectedDiffPath==="")return c`<p class="muted">请选择一个已变更文件。</p>`;const t=e.selectedDiff,i=e.selectedStagedDiff;if(t===void 0||i===void 0)return c`<p class="muted">正在加载 diff…</p>`;const s=[i,t].filter(o=>o.diff!=="");return s.length===0?c`<p class="muted">没有 staged 或 unstaged diff。</p>`:c`
|
|
127
|
+
<div class=${s.length===1?"diffs single":"diffs"}>
|
|
128
|
+
${s.map(o=>Eu(o))}
|
|
129
|
+
</div>
|
|
130
|
+
`}function Eu(e){return oa(),c`
|
|
131
|
+
<section class="diff-section">
|
|
132
|
+
<div class="viewer-header"><strong>${e.path??"diff"}</strong><small>${e.staged?"已暂存":"未暂存"}${e.truncated?" · 已截断":""}</small></div>
|
|
133
|
+
<code-viewer .content=${e.diff} .language=${"diff"}></code-viewer>
|
|
134
|
+
</section>
|
|
135
|
+
`}function oa(){ta(()=>import("./CodeViewer-BKljKDuK.js"),__vite__mapDeps([0,1,2,3]))}function Du(){ta(()=>import("./TerminalPanel-DeDTQWls.js"),__vite__mapDeps([4,5,6,1,2]))}function Wu(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 Ou(e,t){return(t!=="unmodified"?t:e).slice(0,1).toUpperCase()}function Ms(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`${es(t)} KB`;const i=t/1024;return i<1024?`${es(i)} MB`:`${es(i/1024)} GB`}function es(e){return e>=10?String(Math.round(e)):e.toFixed(1)}const _u={apiVersion:1,name:"PI WEB 核心",activate:()=>{const e=!eu();return{contributions:{actions:e?gr():gr().filter(t=>t.id!=="view.terminal"),workspacePanels:e?br():br().filter(t=>t.id!=="workspace.terminal")}}}},Lu={"--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"},ju={"--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"},Fu={"--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"},Nu={apiVersion:1,name:"PI WEB 主题",activate:()=>({contributions:{themes:[{id:"pi-web-dark",name:"PI WEB 深色",description:"PI WEB 深色配色。",order:10,colorScheme:"dark",tokens:ju},{id:"pi-web-light",name:"PI WEB 浅色",description:"PI WEB 浅色配色。",order:20,colorScheme:"light",tokens:Fu},{id:"classic",name:"PI WEB 经典",description:"原始 PI WEB 深色配色。",order:30,colorScheme:"dark",tokens:Lu}],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 Bu(e){return zu.test(e)}const Uu="machine.";function Hu(e,t){if(e==="")throw new Error("Machine id is required");if(!Bu(t))throw new Error(`Invalid PI WEB plugin id: ${t}`);return`${Uu}${qu(e)}.${t}`}function qu(e){return[...new TextEncoder().encode(e)].map(t=>t.toString(16).padStart(2,"0")).join("")}async function wr(e="/pi-web-plugins/manifest.json",t={}){const i=await Ku(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=Ju(n,r);s.push({id:t.machineId===void 0?o.id:Hu(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 Ku(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 Vu(await t.json())}}function Vu(e){if(!Si(e)||!Array.isArray(e.plugins))throw new Error("Invalid plugin manifest");return{plugins:e.plugins.map(t=>{if(!Si(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:Gu(t.machineSpecific)}})}}function Gu(e){if(e===void 0)return!1;if(typeof e!="boolean")throw new Error("Invalid plugin manifest entry");return e}function Ju(e,t){if(!Si(e))throw new Error(`Plugin module ${t} did not export an object`);const i=e.default;if(!Qu(i))throw new Error(`Plugin module ${t} default export is not a PiWebPlugin`);return i}function Qu(e){return Si(e)&&e.apiVersion===1&&typeof e.name=="string"&&typeof e.activate=="function"}function Si(e){return typeof e=="object"&&e!==null}const Zu=/^[a-z][a-z0-9.-]*$/u,Xu=/^[a-z][a-z0-9.-]*$/u,ra=new WeakMap,na=new WeakMap;class Yu{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&&of(this.remoteMachineSpecificPluginIds,t.sourcePluginId,t.machineId)}shouldLoadRemotePlugin(t,i=!1){return!this.gatewayPluginIds.has(t)||this.gatewayMachineSpecificPluginIds.has(t)||i}getActions(t){const i=nf(t);return this.actions.filter(s=>this.isContributionActive(s.pluginId,s.machineId,i,s.sourcePluginId)).map(s=>{const o=ef(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?.(ts(l,t))??!0),...n===void 0?{}:{badge:l=>this.isContributionActive(t,s,l.machine.id,o)?n(ts(l,t)):void 0},render:l=>i.render(ts(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(!Zu.test(t))throw new Error(`Invalid plugin id: ${t}`)}validateLocalId(t){if(!Xu.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}: ${rf(i)}`);return i}}function ef(e,t){return ra.get(e)?.(t)??e}function ts(e,t){return na.get(e)?.(t)??e}function tf(e,t){return ra.set(e,t),e}function sf(e,t){return na.set(e,t),e}function of(e,t,i){const s=e.get(t);s===void 0?e.set(t,new Set([i])):s.add(i)}function rf(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 nf(e){return e.state.selectedMachine?.id??"local"}const af=["(display-mode: standalone)","(display-mode: fullscreen)","(display-mode: minimal-ui)"];function cf(){return typeof window>"u"||!("matchMedia"in window)?[]:af.map(e=>window.matchMedia(e))}function yr(e,t=lf()){return e.some(i=>i.matches)||df(t)}function lf(){return typeof navigator>"u"?void 0:navigator}function df(e){return e!==void 0&&"standalone"in e&&e.standalone===!0}const pf=250;class hf{constructor(t=uf()){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()},pf)}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 uf(){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 ff="(max-width: 760px)";class gf{constructor(t,i={}){this.host=t,this.onMobileNavigationMediaChange=s=>{this.isMobileNavigationLayout!==s.matches&&(this.isMobileNavigationLayout=s.matches,this.host.requestUpdate())},this.onPwaDisplayModeChange=()=>{const s=yr(this.pwaDisplayModeMedia);this.isPwaDisplayMode!==s&&(this.isPwaDisplayMode=s,this.host.requestUpdate())},t.addController(this),this.mobileNavigationMedia=i.mobileNavigationMedia??mf(),this.pwaDisplayModeMedia=i.pwaDisplayModeMedia??cf(),this.viewportPositionRepairer=i.viewportPositionRepairer??new hf,this.isMobileNavigationLayout=this.mobileNavigationMedia?.matches??!1,this.isPwaDisplayMode=yr(this.pwaDisplayModeMedia)}hostConnected(){this.mobileNavigationMedia?.addEventListener("change",this.onMobileNavigationMediaChange);for(const t of this.pwaDisplayModeMedia)t.addEventListener("change",this.onPwaDisplayModeChange)}hostDisconnected(){this.mobileNavigationMedia?.removeEventListener("change",this.onMobileNavigationMediaChange);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.isMobileNavigationLayout?"navigation":"chat"}repairViewportPosition(){this.viewportPositionRepairer.repair(this.shouldRepairViewportPosition())}shouldRepairViewportPosition(){return this.isMobileNavigationLayout||this.isPwaDisplayMode}}function mf(){if(!(typeof window>"u"||!("matchMedia"in window)))return window.matchMedia(ff)}const xi=["machines","projects","workspaces","sessions"];function vf(e){return e.selectedProject===void 0?"projects":e.selectedWorkspace===void 0?"workspaces":"sessions"}function no(e,t){if(e!=="none")return e??vf(t)}function bf(e,t){return t.isMobileLayout?no(t.expanded,t.state)!==e:t.collapsedSections?.includes(e)??!1}function wf(e,t,i){return no(e,i.state)===t?"none":t}function yf(e,t,i){return i?t:e}function Sf(e,t){const i=new Set(e);return i.has(t)?i.delete(t):i.add(t),$f(i)}function xf(e){return xi[xi.indexOf(e)+1]}class kf{constructor(t,i,s){this.host=t,this.getState=i,this.isMobileLayout=s,this.collapsedSections=[],t.addController(this)}hostConnected(){}expandedSection(){return no(this.expanded,this.getState())}isCollapsed(t){return bf(t,{isMobileLayout:this.isMobileLayout(),expanded:this.expanded,state:this.getState(),collapsedSections:this.collapsedSections})}toggle(t){if(this.isMobileLayout()){this.setExpanded(wf(this.expanded,t,{state:this.getState()}));return}this.setCollapsedSections(Sf(this.collapsedSections,t))}expand(t){if(this.isMobileLayout()){this.setExpanded(yf(this.expanded,t,!0));return}this.setCollapsedSections(this.collapsedSections.filter(i=>i!==t))}advanceAfterSelection(t){if(!this.isMobileLayout())return;const i=xf(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){Pf(this.collapsedSections,t)||(this.collapsedSections=t,this.host.requestUpdate())}}function $f(e){const t=new Set(e);return xi.filter(i=>t.has(i))}function Pf(e,t){return e.length===t.length&&e.every((i,s)=>i===t[s])}class Rf{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",aa(t),...this.navigationPanelCollapsed?["navigation-panel-collapsed"]:[],...this.workspacePanelCollapsed?["workspace-panel-collapsed"]:[]].join(" ")}}function aa(e){return e==="navigation"?"navigation-view":e==="chat"?"chat-view":"workspace-view"}const As="pi-web:panel-sizes:v1",If={navigation:{minWidth:180,maxWidth:4096,defaultWidth:340,keyboardStep:24,largeKeyboardStep:72},workspace:{minWidth:240,maxWidth:4096,defaultWidth:480,keyboardStep:24,largeKeyboardStep:72}};class Cf{constructor(t,i={}){this.host=t,t.addController(this),this.storage=i.storage??ao(),this.panelSizes=Ef(this.storage)}hostConnected(){}constraints(t){return zt(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=Of(this.panelSizes,t,o),s.persist!==!1&&this.persistPanelSizes(),this.host.requestUpdate())}resetPanel(t,i={}){this.storedPanelWidth(t)!==void 0&&(this.panelSizes=_f(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(){Df(this.panelSizes,this.storage)}shellStyle(t={}){const i=[];return this.panelSizes.navigationPanelWidth!==void 0&&i.push(`--navigation-panel-size: ${xr(fe("navigation",this.panelSizes.navigationPanelWidth,t.navigation))};`),this.panelSizes.workspacePanelWidth!==void 0&&i.push(`--workspace-panel-size: ${xr(fe("workspace",this.panelSizes.workspacePanelWidth,t.workspace))};`),i.join(" ")}storedPanelWidth(t){return t==="navigation"?this.panelSizes.navigationPanelWidth:this.panelSizes.workspacePanelWidth}}function zt(e){return If[e]}function Tf(e,t,i){return e==="navigation"?i-t:t-i}function Mf(e,t,i,s,o=zt(e)){return fe(e,t+Tf(e,i,s),o)}function Af(e,t,i,s={}){const o=s.constraints??zt(e);if(i==="Home")return o.minWidth;if(i==="End")return o.maxWidth;const r=s.largeStep===!0?o.largeKeyboardStep:o.keyboardStep,n=Lf(e,i,r);if(n!==void 0)return fe(e,t+n,o)}function fe(e,t,i=zt(e)){return Number.isFinite(t)?Math.round(Math.min(Math.max(t,i.minWidth),i.maxWidth)):i.defaultWidth}function Ef(e=ao()){try{const t=e?.getItem(As);if(t==null||t==="")return{};const i=JSON.parse(t);return Wf(i)}catch{return{}}}function Df(e,t=ao()){if(t!==void 0)try{if(e.navigationPanelWidth===void 0&&e.workspacePanelWidth===void 0){t.removeItem(As);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(As,JSON.stringify(i))}catch{}}function Wf(e){if(!jf(e)||e.version!==1)return{};const t={},i=Sr(e.navigationPanelWidth),s=Sr(e.workspacePanelWidth);return i!==void 0&&(t.navigationPanelWidth=fe("navigation",i)),s!==void 0&&(t.workspacePanelWidth=fe("workspace",s)),t}function Sr(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}function Of(e,t,i){return t==="navigation"?{...e,navigationPanelWidth:i}:{...e,workspacePanelWidth:i}}function _f(e,t){return t==="navigation"?e.workspacePanelWidth===void 0?{}:{workspacePanelWidth:e.workspacePanelWidth}:e.navigationPanelWidth===void 0?{}:{navigationPanelWidth:e.navigationPanelWidth}}function Lf(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 xr(e){return`${String(Math.round(e))}px`}function ao(){try{return typeof window>"u"?void 0:window.localStorage}catch{return}}function jf(e){return typeof e=="object"&&e!==null}function kr(){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:Ff(e.get("tool")),view:Nf(e.get("view"))}}function is(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 Ff(e){return e==="files"?"core:workspace.files":e==="git"?"core:workspace.git":ca(e)?e:void 0}function Nf(e){return e==="chat"?"chat":e==="files"?"core:workspace.files":e==="git"?"core:workspace.git":ca(e)?e:void 0}function ca(e){return e!==null&&/^[a-z][a-z0-9.-]*:[a-z][a-z0-9.-]*$/u.test(e)}function $r(){return zf(new URLSearchParams(window.location.search).get("settings"))}function ss(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 zf(e){if(e==="general")return"general";if(e==="plugins")return"plugins";if(e==="shortcuts"||e==="keyboard"||e==="keyboard-shortcuts")return"shortcuts"}function Bf(e,t){return t===void 0?e:e.map(i=>Hf(i,t))}function Uf(e,t){const i=new Set(so(e,t,{enabledOnly:!0}).filter(s=>s.active).map(s=>s.action.id));return Bf(e,t).map(s=>s.shortcut!==void 0&&!i.has(s.id)?la(s):s)}function Hf(e,t){if(!Object.hasOwn(t,e.id))return e;const i=t[e.id];return i===void 0?e:i===null?la(e):{...e,shortcut:i}}function la(e){const t={...e};return delete t.shortcut,t}function qf(e,t){const i=t.api??at,s=t.pollIntervalMs??1e3,o=t.setTimeout??Vf(),r=t.clearTimeout??Gf();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:Kf(a,i,s,o,r)}},listCommandRuns:n=>i.listCommandRuns(n),getCommandRun:n=>i.getCommandRun(n),open:n=>{t.openTerminal(void 0,n)}}}function Kf(e,t,i,s,o){return Pr(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&&Pr(g)){p(g);return}a=s(h,i)}).catch(u)};a=s(h,i)})}function Pr(e){return e.status==="succeeded"||e.status==="failed"}function Vf(){return(e,t)=>globalThis.setTimeout(e,t)}function Gf(){return e=>{globalThis.clearTimeout(e)}}function Jf(e,t){return t[e.path]}function Qf(e){if(e?.hasSessionActivity===!0)return"session";if(e?.hasTerminalActivity===!0)return"terminal"}function Zf(e,t,i){return pa(Xf(e,t,i))}function da(e){return pa(Object.values(e??{}))}function pa(e){if(e.some(t=>t.hasSessionActivity))return"session";if(e.some(t=>t.hasTerminalActivity))return"terminal"}function Xf(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 Jt=0,Yf=120;function Bt(e,t={}){if(typeof HTMLElement>"u"||typeof window>"u"||!(e instanceof HTMLElement))return"";const i=e.getBoundingClientRect(),s=t.constrainTo==="viewport"?ha():eg(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-Jt,g=i.top-l-Jt;return[...h<Yf&&g>h?[`bottom: ${rt(r-i.top+Jt)};`,`max-height: ${rt(Math.max(0,g))};`]:[`top: ${rt(i.bottom+Jt)};`,`max-height: ${rt(Math.max(0,h))};`],`right: ${rt(Math.max(0,o-u))};`,`max-width: ${rt(Math.max(0,u-n))};`].join(" ")}function eg(e){const t=e.getRootNode();return typeof ShadowRoot<"u"&&t instanceof ShadowRoot&&t.host instanceof HTMLElement?t.host.getBoundingClientRect():ha()}function ha(){return{top:0,right:window.innerWidth,bottom:window.innerHeight,left:0}}function rt(e){return`${String(Math.round(e))}px`}function ua(e,t="活跃"){if(e!==void 0)return c`<span class=${`activity-indicator ${e}`} role="img" aria-label=${t} title=${t}></span>`}function Oi(e,t="Active"){const i=ua(e,t);if(i!==void 0)return c`<span class="action-activity">${i}</span>`}const tg=["a[href]","button","input","select","textarea","summary","[role='button']","[role='link']","[contenteditable='true']"].join(",");function fa(e){return e.composedPath().some(t=>ig(t,tg))}function ig(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 _i(e,t){fa(e)||t()}function Li(e,t){return fa(e)?!1:e.key==="Enter"||e.key===" "?(e.preventDefault(),t.activate(),!0):e.key==="ArrowUp"?He(e,()=>{Rr(e.currentTarget,-1)}):e.key==="ArrowDown"?He(e,()=>{Rr(e.currentTarget,1)}):e.key==="Home"?He(e,()=>{Ir(e.currentTarget,0)}):e.key==="End"?He(e,()=>{Ir(e.currentTarget,-1)}):e.key==="ArrowLeft"&&t.previousSection!==void 0?He(e,t.previousSection):e.key==="ArrowRight"&&t.nextSection!==void 0?He(e,t.nextSection):e.key==="Escape"&&t.cancel!==void 0?He(e,t.cancel):!1}function ji(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 He(e,t){return e.preventDefault(),e.stopPropagation?.(),t(),!0}function Rr(e,t){const i=ma(e),s=va(e);if(s===void 0||i.length===0)return;const o=i.indexOf(s);o<0||ga(i,o+t)}function Ir(e,t){const i=ma(e);i.length!==0&&ga(i,t<0?i.length-1:t)}function ga(e,t){const i=e[Math.min(Math.max(t,0),e.length-1)];i?.focus(),i?.scrollIntoView({block:"nearest"})}function ma(e){const t=va(e)?.getRootNode();return t===void 0||!sg(t)?[]:Array.from(t.querySelectorAll(".action-row"))}function sg(e){return typeof Document<"u"&&e instanceof Document||typeof DocumentFragment<"u"&&e instanceof DocumentFragment}function va(e){if(!(typeof HTMLElement>"u"||!(e instanceof HTMLElement)))return e.closest(".action-row")??void 0}const og=O`
|
|
136
|
+
/* Mobile browsers already subtract browser controls from 100dvh; reserve bottom safe area only in standalone PWA modes. */
|
|
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
|
+
:host([pwa-display-mode]) { --pi-app-safe-area-bottom: env(safe-area-inset-bottom); }
|
|
139
|
+
@media (display-mode: standalone), (display-mode: fullscreen), (display-mode: minimal-ui) {
|
|
140
|
+
:host { --pi-app-safe-area-bottom: env(safe-area-inset-bottom); }
|
|
141
|
+
}
|
|
142
|
+
.shell { --navigation-panel-size: 340px; --workspace-panel-size: minmax(360px, 42vw); --navigation-panel-width: var(--navigation-panel-size); --workspace-panel-width: var(--workspace-panel-size); display: grid; grid-template-columns: var(--navigation-panel-width) 1px minmax(320px, 1fr) 1px var(--workspace-panel-width); height: 100%; min-height: 0; }
|
|
143
|
+
aside { grid-column: 1; display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
|
|
144
|
+
aside app-navigation-panel { flex: 1 1 auto; min-height: 0; }
|
|
145
|
+
header { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px; border-bottom: 1px solid var(--pi-border); }
|
|
146
|
+
.header-actions { display: flex; align-items: center; gap: 8px; }
|
|
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
|
+
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; }
|
|
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
|
+
.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
|
+
.context-bar::before { left: 0; background: linear-gradient(90deg, color-mix(in srgb, var(--pi-shadow-strong) 55%, transparent) 0%, transparent 100%); }
|
|
153
|
+
.context-bar::after { right: 0; background: linear-gradient(270deg, color-mix(in srgb, var(--pi-shadow-strong) 55%, transparent) 0%, transparent 100%); }
|
|
154
|
+
.context-bar.can-scroll-left::before, .context-bar.can-scroll-right::after { opacity: 1; }
|
|
155
|
+
.context-bar-label { display: none; }
|
|
156
|
+
.context-items { flex: 1 1 auto; min-width: 0; display: flex; align-items: stretch; gap: 5px; margin: 0; padding: 0 8px; list-style: none; overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain; scroll-padding-inline: 8px; scrollbar-width: thin; }
|
|
157
|
+
.context-bar.has-context-actions .context-items { padding-right: 52px; scroll-padding-inline: 8px 52px; }
|
|
158
|
+
.context-item { flex: 0 0 auto; min-width: 0; display: flex; }
|
|
159
|
+
.context-actions { position: absolute; top: 6px; right: 0; bottom: 6px; z-index: 3; display: flex; align-items: center; padding: 0 8px 0 0; pointer-events: none; }
|
|
160
|
+
.context-actions::after { content: ""; position: absolute; top: 0; right: 0; bottom: 0; z-index: 0; width: 26px; background: var(--pi-bg); pointer-events: none; }
|
|
161
|
+
.context-chip { flex: 0 0 auto; min-width: 0; display: inline-flex; align-items: baseline; gap: 5px; border: 1px solid var(--pi-border-muted); border-radius: 999px; background: var(--pi-surface); color: var(--pi-text); padding: 4px 8px; font: inherit; text-align: left; }
|
|
162
|
+
.context-chip:hover { background: var(--pi-surface-hover); }
|
|
163
|
+
.context-chip:focus-visible { outline: 2px solid var(--pi-accent); outline-offset: 2px; }
|
|
164
|
+
.context-chip.empty { border-style: dashed; color: var(--pi-muted); }
|
|
165
|
+
.context-kind { display: none; }
|
|
166
|
+
.context-value { min-width: 0; overflow: visible; text-overflow: clip; white-space: nowrap; }
|
|
167
|
+
app-mobile-main-tabs { display: none; }
|
|
168
|
+
.mobile-tabs-frame { position: relative; display: none; flex: 0 0 auto; min-width: 0; border-bottom: 1px solid var(--pi-border); background: var(--pi-bg); }
|
|
169
|
+
.mobile-tabs-frame::before, .mobile-tabs-frame::after { content: ""; position: absolute; top: 0; bottom: 0; z-index: 2; width: 20px; opacity: 0; pointer-events: none; transition: opacity .15s ease; }
|
|
170
|
+
.mobile-tabs-frame::before { left: 0; background: linear-gradient(90deg, color-mix(in srgb, var(--pi-shadow-strong) 55%, transparent) 0%, transparent 100%); }
|
|
171
|
+
.mobile-tabs-frame::after { right: 0; background: linear-gradient(270deg, color-mix(in srgb, var(--pi-shadow-strong) 55%, transparent) 0%, transparent 100%); }
|
|
172
|
+
.mobile-tabs-frame.can-scroll-left::before, .mobile-tabs-frame.can-scroll-right::after { opacity: 1; }
|
|
173
|
+
.mobile-tabs { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: 6px; padding: 8px; overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain; scrollbar-width: thin; }
|
|
174
|
+
.mobile-tabs button { flex: 0 0 auto; white-space: nowrap; }
|
|
175
|
+
.mobile-navigation-tab, .mobile-navigation-panel { display: none; }
|
|
176
|
+
.mobile-tabs button.selected { border-color: var(--pi-accent); background: var(--pi-selection-bg); }
|
|
177
|
+
.tab-badge { display: inline-block; min-width: 14px; margin-left: 4px; border: 1px solid var(--pi-success-border); border-radius: 999px; background: var(--pi-success-surface); color: var(--pi-success); padding: 0 5px; font-size: 11px; line-height: 16px; text-align: center; }
|
|
178
|
+
.navigation-panel-edge, .workspace-panel-edge { min-width: 0; min-height: 0; display: flex; align-items: center; justify-content: center; overflow: visible; background: var(--pi-border-muted); z-index: 2; }
|
|
179
|
+
.navigation-panel-edge { grid-column: 2; }
|
|
180
|
+
.workspace-panel-edge { grid-column: 4; }
|
|
181
|
+
.navigation-panel-edge-button, .workspace-panel-edge-button { position: relative; z-index: 1; box-sizing: border-box; display: grid; place-items: center; width: 18px; height: 48px; padding: 0; border: 1px solid var(--pi-border-muted); border-radius: 999px; background: var(--pi-bg); color: var(--pi-muted); opacity: .75; cursor: pointer; }
|
|
182
|
+
.navigation-panel-edge-button:hover, .navigation-panel-edge-button:focus-visible, .workspace-panel-edge-button:hover, .workspace-panel-edge-button:focus-visible { color: var(--pi-text); background: var(--pi-surface-hover); opacity: 1; }
|
|
183
|
+
.shell.navigation-panel-collapsed .navigation-panel-edge-button { transform: translateX(calc(50% - .5px)); }
|
|
184
|
+
.shell.workspace-panel-collapsed .workspace-panel-edge-button { transform: translateX(calc(-50% + .5px)); }
|
|
185
|
+
.navigation-panel-edge-icon, .workspace-panel-edge-icon { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
|
|
186
|
+
workspace-panel { grid-column: 5; min-width: 0; min-height: 0; overflow: hidden; }
|
|
187
|
+
@media (min-width: 1181px) {
|
|
188
|
+
.shell.navigation-panel-collapsed { --navigation-panel-width: 0px; }
|
|
189
|
+
.shell.navigation-panel-collapsed > aside { display: none; }
|
|
190
|
+
.shell.workspace-panel-collapsed { --workspace-panel-width: 0px; }
|
|
191
|
+
.shell.workspace-panel-collapsed > workspace-panel { display: none; }
|
|
192
|
+
}
|
|
193
|
+
@media (max-width: 1180px) {
|
|
194
|
+
.shell { grid-template-columns: var(--navigation-panel-width) 1px minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
|
|
195
|
+
.shell.navigation-panel-collapsed { --navigation-panel-width: 0px; }
|
|
196
|
+
.shell.navigation-panel-collapsed > aside { display: none; }
|
|
197
|
+
aside { grid-row: 1 / 3; }
|
|
198
|
+
.navigation-panel-edge { grid-row: 1 / 3; }
|
|
199
|
+
main { grid-column: 3; grid-row: 1 / 3; }
|
|
200
|
+
app-mobile-main-tabs { display: block; flex: 0 0 auto; min-width: 0; }
|
|
201
|
+
.mobile-tabs-frame { display: flex; }
|
|
202
|
+
.shell.workspace-view main { grid-row: 1; min-height: auto; }
|
|
203
|
+
.shell.workspace-view > workspace-panel { grid-column: 3; grid-row: 2; display: flex; border-left: 0; }
|
|
204
|
+
.shell:not(.workspace-view) > workspace-panel { display: none; }
|
|
205
|
+
.workspace-panel-edge { display: none; }
|
|
206
|
+
main.workspace-view chat-view, main.workspace-view prompt-editor, main.workspace-view status-bar,
|
|
207
|
+
main.workspace-view .empty { display: none; }
|
|
208
|
+
main.workspace-view { overflow: hidden; }
|
|
209
|
+
}
|
|
210
|
+
@media (max-width: 760px) {
|
|
211
|
+
.shell { grid-template-columns: minmax(0, 1fr); }
|
|
212
|
+
aside, .navigation-panel-edge { display: none; }
|
|
213
|
+
main, .shell.workspace-view > workspace-panel { grid-column: 1; }
|
|
214
|
+
.context-bar { display: flex; }
|
|
215
|
+
.mobile-navigation-tab { display: block; }
|
|
216
|
+
main.navigation-view chat-view, main.navigation-view prompt-editor, main.navigation-view status-bar,
|
|
217
|
+
main.navigation-view .empty { display: none; }
|
|
218
|
+
main.navigation-view .mobile-navigation-panel { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
|
|
219
|
+
main.navigation-view .mobile-navigation-panel app-navigation-panel { flex: 1 1 auto; min-height: 0; }
|
|
220
|
+
main.navigation-view .mobile-navigation-panel project-list,
|
|
221
|
+
main.navigation-view .mobile-navigation-panel workspace-list,
|
|
222
|
+
main.navigation-view .mobile-navigation-panel session-list { flex: 1 1 auto; max-height: none; min-height: 0; overflow: hidden; }
|
|
223
|
+
main.navigation-view .mobile-navigation-panel project-list[collapsed],
|
|
224
|
+
main.navigation-view .mobile-navigation-panel workspace-list[collapsed],
|
|
225
|
+
main.navigation-view .mobile-navigation-panel session-list[collapsed] { flex: 0 0 auto; min-height: auto; overflow: hidden; }
|
|
226
|
+
}
|
|
227
|
+
status-bar { flex: 0 0 auto; }
|
|
228
|
+
chat-view { flex: 1 1 auto; min-height: 0; overflow: hidden; }
|
|
229
|
+
prompt-editor { flex: 0 0 auto; }
|
|
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
|
+
.empty { margin: auto; color: var(--pi-muted); }
|
|
232
|
+
.error { padding: 10px 16px; border-bottom: 1px solid var(--pi-border); color: var(--pi-danger); }
|
|
233
|
+
`,rg=O`
|
|
234
|
+
:host { display: flex; flex-direction: column; min-height: 0; color: var(--pi-text); background: var(--pi-bg); font: 13px system-ui, sans-serif; container-type: inline-size; }
|
|
235
|
+
header { flex: 0 0 auto; min-width: 0; border-bottom: 1px solid var(--pi-border); }
|
|
236
|
+
.workspace-header-scroll-frame { position: relative; min-width: 0; background: var(--pi-bg); }
|
|
237
|
+
.workspace-header-scroll-frame::before, .workspace-header-scroll-frame::after { content: ""; position: absolute; top: 0; bottom: 0; z-index: 2; width: 18px; opacity: 0; pointer-events: none; transition: opacity .15s ease; }
|
|
238
|
+
.workspace-header-scroll-frame::before { left: 0; background: linear-gradient(90deg, color-mix(in srgb, var(--pi-shadow-strong) 55%, transparent) 0%, transparent 100%); }
|
|
239
|
+
.workspace-header-scroll-frame::after { right: 0; background: linear-gradient(270deg, color-mix(in srgb, var(--pi-shadow-strong) 55%, transparent) 0%, transparent 100%); }
|
|
240
|
+
.workspace-header-scroll-frame.can-scroll-left::before, .workspace-header-scroll-frame.can-scroll-right::after { opacity: 1; }
|
|
241
|
+
.workspace-header-strip { display: flex; justify-content: space-between; align-items: center; gap: 8px; min-width: 0; padding: 8px; overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain; scrollbar-width: thin; }
|
|
242
|
+
.tabs { flex: 0 0 auto; display: flex; gap: 6px; align-items: center; }
|
|
243
|
+
.tabs button { flex: 0 0 auto; white-space: nowrap; }
|
|
244
|
+
.tabs button.icon-tab { min-width: 34px; }
|
|
245
|
+
button { display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--pi-border); border-radius: 7px; background: var(--pi-surface); color: var(--pi-text); padding: 5px 7px; cursor: pointer; }
|
|
246
|
+
button.selected { border-color: var(--pi-accent); background: var(--pi-selection-bg); }
|
|
247
|
+
.tab-icon { flex: 0 0 auto; width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
|
|
248
|
+
.tab-custom-icon { flex: 0 0 auto; width: 16px; height: 16px; display: inline-grid; place-items: center; color: currentColor; pointer-events: none; }
|
|
249
|
+
.tab-custom-icon svg { width: 16px; height: 16px; pointer-events: none; }
|
|
250
|
+
.tab-label { min-width: 0; }
|
|
251
|
+
.tab-badge { flex: 0 0 auto; display: inline-block; min-width: 14px; border: 1px solid var(--pi-success-border); border-radius: 999px; background: var(--pi-success-surface); color: var(--pi-success); padding: 0 5px; font-size: 11px; line-height: 16px; text-align: center; }
|
|
252
|
+
@container (max-width: 430px) {
|
|
253
|
+
.tabs button.icon-tab { justify-content: center; padding-inline: 7px; }
|
|
254
|
+
.tabs button.icon-tab .tab-label { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0; }
|
|
255
|
+
}
|
|
256
|
+
.panel-content { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; overflow: auto; }
|
|
257
|
+
.empty-state { box-sizing: border-box; width: min(100%, 380px); margin: auto; padding: 24px; display: grid; gap: 8px; color: var(--pi-muted); text-align: center; }
|
|
258
|
+
.empty-state h2 { margin: 0; color: var(--pi-text); font-size: 15px; line-height: 1.3; }
|
|
259
|
+
.empty-state p { margin: 0; line-height: 1.45; }
|
|
260
|
+
small, .muted { color: var(--pi-muted); }
|
|
261
|
+
@media (max-width: 1180px) { header { display: none; } }
|
|
262
|
+
.workspace-label { min-width: 0; display: inline-flex; align-items: baseline; gap: 5px; max-width: 100%; overflow: hidden; white-space: nowrap; }
|
|
263
|
+
.workspace-label-base, .workspace-label-item, .workspace-label-render { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
|
|
264
|
+
.workspace-label-item, .workspace-label-render, .workspace-label-separator { color: var(--pi-muted); }
|
|
265
|
+
.workspace-label-link { color: var(--pi-accent); text-decoration: none; }
|
|
266
|
+
.workspace-label-link:hover, .workspace-label-link:focus { text-decoration: underline; }
|
|
267
|
+
.toolbar { flex: 0 0 auto; display: flex; align-items: center; gap: 8px; padding: 8px; border-bottom: 1px solid var(--pi-border-muted); }
|
|
268
|
+
.toolbar > button { margin-left: auto; }
|
|
269
|
+
.toolbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
|
|
270
|
+
.file-upload-button { display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--pi-border); border-radius: 7px; background: var(--pi-surface); color: var(--pi-text); padding: 5px 7px; cursor: pointer; user-select: none; }
|
|
271
|
+
.file-upload-button:hover, .file-upload-button:focus-visible { background: var(--pi-surface-hover); }
|
|
272
|
+
.file-upload-button.disabled { opacity: .5; cursor: not-allowed; }
|
|
273
|
+
.stale { border: 1px solid var(--pi-warning-border); border-radius: 999px; color: var(--pi-warning); padding: 1px 6px; font-size: 12px; }
|
|
274
|
+
.split { flex: 1 1 auto; min-height: 0; display: grid; grid-template-rows: minmax(160px, 34%) minmax(0, 1fr); }
|
|
275
|
+
.list { min-height: 0; overflow: auto; border-bottom: 1px solid var(--pi-border); padding: 6px; }
|
|
276
|
+
.row { display: grid; grid-template-columns: 18px minmax(0, 1fr); gap: 4px; width: 100%; border: 0; border-radius: 5px; background: transparent; text-align: left; padding: 4px 6px 4px calc(6px + var(--depth, 0) * 14px); }
|
|
277
|
+
.row:hover, .row.selected { background: var(--pi-selection-bg); }
|
|
278
|
+
.row span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
279
|
+
.summary { margin: 4px 6px 8px; color: var(--pi-muted); }
|
|
280
|
+
.viewer { min-height: 0; overflow: auto; display: flex; flex-direction: column; }
|
|
281
|
+
.diffs { flex: 1 1 auto; min-height: 0; overflow: auto; display: grid; grid-template-rows: minmax(120px, 1fr) minmax(120px, 1fr); }
|
|
282
|
+
.diffs.single { grid-template-rows: minmax(0, 1fr); }
|
|
283
|
+
.diff-section { min-height: 0; display: flex; flex-direction: column; border-bottom: 1px solid var(--pi-border); }
|
|
284
|
+
.diff-section:last-child { border-bottom: 0; }
|
|
285
|
+
.viewer-header { position: sticky; top: 0; display: flex; justify-content: space-between; gap: 8px; padding: 8px; border-bottom: 1px solid var(--pi-border-muted); background: var(--pi-bg); }
|
|
286
|
+
.viewer-header strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
287
|
+
code-viewer { flex: 1 1 auto; min-height: 0; }
|
|
288
|
+
.image-preview { flex: 1 1 auto; min-height: 0; box-sizing: border-box; display: flex; align-items: center; justify-content: center; overflow: auto; padding: 16px; }
|
|
289
|
+
.image-preview img { display: block; max-width: 100%; max-height: 100%; object-fit: contain; border: 1px solid var(--pi-border-muted); border-radius: 8px; background-color: var(--pi-surface); background-image: linear-gradient(45deg, color-mix(in srgb, var(--pi-border-muted) 45%, transparent) 25%, transparent 25%), linear-gradient(-45deg, color-mix(in srgb, var(--pi-border-muted) 45%, transparent) 25%, transparent 25%), linear-gradient(45deg, transparent 75%, color-mix(in srgb, var(--pi-border-muted) 45%, transparent) 75%), linear-gradient(-45deg, transparent 75%, color-mix(in srgb, var(--pi-border-muted) 45%, transparent) 75%); background-position: 0 0, 0 8px, 8px -8px, -8px 0; background-size: 16px 16px; box-shadow: 0 8px 24px var(--pi-shadow-soft); }
|
|
290
|
+
pre { margin: 0; padding: 10px; overflow: auto; font: 12px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
|
|
291
|
+
p { margin: 10px; }
|
|
292
|
+
`,Fi=O`
|
|
293
|
+
:host { display: flex; flex-direction: column; min-height: 0; overflow: hidden; color: var(--pi-text); font: 14px system-ui, sans-serif; }
|
|
294
|
+
:host([collapsed]) { flex: 0 0 auto; min-height: auto; overflow: hidden; }
|
|
295
|
+
section { box-sizing: border-box; flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; padding: 10px; }
|
|
296
|
+
h2 { flex: 0 0 auto; display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 0 0 8px; color: var(--pi-muted); font-size: 12px; text-transform: uppercase; }
|
|
297
|
+
.list-body { flex: 1 1 auto; min-height: 0; overflow: auto; }
|
|
298
|
+
button { border: 1px solid var(--pi-border); border-radius: 8px; background: var(--pi-surface); color: var(--pi-text); padding: 7px 9px; cursor: pointer; }
|
|
299
|
+
section > button { display: block; width: 100%; text-align: left; margin: 6px 0; }
|
|
300
|
+
.subheading { margin-top: 14px; }
|
|
301
|
+
.section-toggle { display: flex; flex: 1 1 auto; min-width: 0; align-items: center; justify-content: space-between; gap: 8px; width: 100%; border: 0; background: transparent; color: inherit; padding: 0; font: inherit; text-align: left; text-transform: inherit; }
|
|
302
|
+
.section-toggle span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
303
|
+
.section-title { display: grid; gap: 2px; min-width: 0; }
|
|
304
|
+
.section-toggle .section-selected { display: block; color: var(--pi-text); font-size: 12px; font-weight: 600; line-height: 1.25; text-transform: none; }
|
|
305
|
+
.section-toggle .section-count { flex: 0 0 auto; display: inline; color: var(--pi-muted); font-size: inherit; }
|
|
306
|
+
.section-toggle small { display: inline; color: inherit; font-size: inherit; }
|
|
307
|
+
.action-row { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) auto; margin: 6px 0; cursor: pointer; }
|
|
308
|
+
.action-row:focus-visible { outline: 2px solid var(--pi-accent); outline-offset: 2px; border-radius: 8px; }
|
|
309
|
+
.action-row.selected .action-main, .action-row.selected .action-menu-toggle { border-color: var(--pi-accent); background: var(--pi-selection-bg); }
|
|
310
|
+
.action-row.archived .action-main { color: var(--pi-muted); }
|
|
311
|
+
.action-main { position: relative; box-sizing: border-box; min-width: 0; width: 100%; border: 1px solid var(--pi-border); border-top-right-radius: 0; border-bottom-right-radius: 0; border-top-left-radius: 8px; border-bottom-left-radius: 8px; background: var(--pi-surface); color: var(--pi-text); padding: 7px 22px 7px calc(9px + var(--depth, 0) * 16px); text-align: left; }
|
|
312
|
+
.action-name { display: -webkit-box; max-height: 2.5em; overflow: hidden; overflow-wrap: anywhere; line-height: 1.25; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
|
|
313
|
+
.action-row:not(.selected):hover .action-main { background: var(--pi-surface-hover); }
|
|
314
|
+
.workspace-row .action-main { border-radius: 8px 0 0 8px; }
|
|
315
|
+
.workspace-primary { min-width: 0; display: flex; align-items: baseline; gap: 6px; }
|
|
316
|
+
.workspace-primary-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
317
|
+
.workspace-status { flex: 0 0 auto; color: var(--pi-warning); font-size: 12px; }
|
|
318
|
+
.workspace-secondary { margin-top: 3px; }
|
|
319
|
+
.workspace-menu-panel { width: max-content; min-width: min(120px, calc(100vw - 16px)); padding: 8px; }
|
|
320
|
+
.workspace-menu-actions { margin: 0 0 8px; padding-bottom: 8px; border-bottom: 1px solid var(--pi-border-muted); }
|
|
321
|
+
.workspace-menu-actions button.danger { color: var(--pi-danger); }
|
|
322
|
+
.workspace-menu-actions button.danger:hover, .workspace-menu-actions button.danger:focus { background: color-mix(in srgb, var(--pi-danger) 14%, transparent); }
|
|
323
|
+
.workspace-menu-details { display: grid; gap: 6px; margin: 0; }
|
|
324
|
+
.workspace-detail-row { display: grid; grid-template-columns: minmax(58px, max-content) minmax(0, 1fr); gap: 8px; align-items: baseline; }
|
|
325
|
+
.workspace-detail-row dt { color: var(--pi-muted); font-size: 12px; white-space: normal; }
|
|
326
|
+
.workspace-detail-row dd { min-width: 0; margin: 0; overflow-wrap: anywhere; white-space: normal; }
|
|
327
|
+
.tree-marker { color: var(--pi-dim); margin-right: 5px; }
|
|
328
|
+
.badge { display: inline-block; margin-left: 5px; border: 1px solid var(--pi-border); border-radius: 999px; color: var(--pi-muted); padding: 0 5px; font-size: 11px; font-weight: 400; }
|
|
329
|
+
.action-activity { position: absolute; top: 5px; right: 6px; z-index: 1; display: grid; place-items: center; width: 10px; height: 10px; }
|
|
330
|
+
.action-activity .activity-indicator { margin: 0; vertical-align: 0; }
|
|
331
|
+
.activity-indicator { display: inline-block; width: 7px; height: 7px; margin-right: 6px; background: var(--pi-success); animation: pulse 1s ease-in-out infinite; vertical-align: 1px; }
|
|
332
|
+
.activity-indicator.session { border-radius: 50%; background: var(--pi-success); }
|
|
333
|
+
.activity-indicator.terminal { border-radius: 2px; background: var(--pi-accent); }
|
|
334
|
+
/* Client-side sending (upload in flight); distinct from server activity, which propagates to workspace/machine rows. */
|
|
335
|
+
.activity-indicator.sending { border-radius: 50%; background: var(--pi-warning); }
|
|
336
|
+
.action-menu { position: relative; align-self: stretch; }
|
|
337
|
+
.action-menu-toggle { display: grid; place-items: center; height: 100%; min-width: 32px; padding: 0; color: var(--pi-muted); border-left: 0; border-top-left-radius: 0; border-bottom-left-radius: 0; }
|
|
338
|
+
.action-menu-toggle:hover { color: var(--pi-text); background: var(--pi-surface-hover); }
|
|
339
|
+
.action-menu-panel { position: fixed; z-index: 50; box-sizing: border-box; min-width: min(120px, calc(100vw - 16px)); overflow: auto; padding: 4px; border: 1px solid var(--pi-border); border-radius: 8px; background: var(--pi-surface); box-shadow: 0 8px 24px var(--pi-shadow); overflow-wrap: anywhere; }
|
|
340
|
+
.action-menu-panel button { display: block; width: 100%; text-align: left; white-space: normal; overflow-wrap: anywhere; border: 0; background: transparent; color: var(--pi-text); }
|
|
341
|
+
.action-menu-panel button:hover { background: var(--pi-selection-bg); }
|
|
342
|
+
button.selected { border-color: var(--pi-accent); background: var(--pi-selection-bg); }
|
|
343
|
+
button:disabled { opacity: .5; cursor: not-allowed; }
|
|
344
|
+
small { display: block; color: var(--pi-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
345
|
+
.workspace-label { min-width: 0; display: inline-flex; align-items: baseline; gap: 5px; max-width: 100%; overflow: hidden; white-space: nowrap; }
|
|
346
|
+
.workspace-label-base, .workspace-label-item, .workspace-label-render { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
|
|
347
|
+
.workspace-label-item, .workspace-label-render, .workspace-label-separator { color: var(--pi-muted); }
|
|
348
|
+
.workspace-label-link { color: var(--pi-accent); text-decoration: none; }
|
|
349
|
+
.workspace-label-link:hover, .workspace-label-link:focus { text-decoration: underline; }
|
|
350
|
+
.workspace-detail-row .workspace-label { overflow: visible; white-space: normal; flex-wrap: wrap; }
|
|
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
|
+
@keyframes pulse { 0%, 100% { transform: scale(.75); opacity: .55; } 50% { transform: scale(1.2); opacity: 1; } }
|
|
353
|
+
`,ng=O`
|
|
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; }
|
|
356
|
+
.chat { height: 100%; min-height: 0; overflow: auto; overflow-anchor: none; padding: 26px 16px 64px; box-sizing: border-box; }
|
|
357
|
+
.scroll-marker { display: block; height: 0; overflow: hidden; pointer-events: none; }
|
|
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); }
|
|
359
|
+
.activity-dock.active { border-color: var(--pi-success-border); color: var(--pi-success); background: var(--pi-success-bg-overlay); }
|
|
360
|
+
.activity-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
361
|
+
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; opacity: .45; flex: 0 0 auto; }
|
|
362
|
+
.activity-dock.active .dot { animation: pulse 1s ease-in-out infinite; opacity: 1; }
|
|
363
|
+
.msg { max-width: 100%; min-width: 0; box-sizing: border-box; margin: 0 0 14px; padding: 12px; border: 1px solid var(--pi-border); border-left: 3px solid var(--pi-border); border-radius: 10px; background: var(--pi-surface); overflow: visible; }
|
|
364
|
+
.msg.assistant { border-left-color: var(--pi-text-secondary); background: var(--pi-surface); }
|
|
365
|
+
.msg.user { border-color: var(--pi-accent-border); border-left: 3px solid var(--pi-accent); background: var(--pi-selection-bg); }
|
|
366
|
+
.msg.tool { border-color: var(--pi-warning-border); background: var(--pi-warning-surface); color: var(--pi-warning); }
|
|
367
|
+
.msg.tool-execution-shell { padding: 0; border: 0; background: transparent; color: var(--pi-text); }
|
|
368
|
+
.msg.system { color: var(--pi-danger); }
|
|
369
|
+
.msg.bash { border-color: var(--pi-success); background: var(--pi-success-bg); }
|
|
370
|
+
.msg.skill { border-color: var(--pi-purple-border); background: var(--pi-purple-surface); }
|
|
371
|
+
.msg.event-group { padding: 0; border-color: var(--pi-border); background: var(--pi-bg); color: var(--pi-muted); }
|
|
372
|
+
.msg.event-group.live { border-color: var(--pi-success-border); background: var(--pi-success-bg); }
|
|
373
|
+
.msg.event-group > summary { position: sticky; top: -26px; z-index: 5; display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 9px 9px 0 0; border-bottom: 1px solid var(--pi-border-muted); background: var(--pi-bg); color: var(--pi-muted); }
|
|
374
|
+
.msg.event-group.live > summary { border-bottom-color: var(--pi-success-border); background: var(--pi-success-bg); color: var(--pi-success); }
|
|
375
|
+
.msg.event-group > summary .label { margin: 0; }
|
|
376
|
+
.group-body { padding: 0 12px 12px; }
|
|
377
|
+
.chat-image { margin: 0; }
|
|
378
|
+
.chat-image img { display: block; max-width: min(100%, 420px); max-height: 320px; object-fit: contain; border: 1px solid var(--pi-border-muted); border-radius: 8px; background: var(--pi-bg); }
|
|
379
|
+
.group-msg { max-width: 100%; min-width: 0; box-sizing: border-box; padding: 10px 0; border-top: 1px solid var(--pi-border-muted); color: var(--pi-text); overflow: visible; }
|
|
380
|
+
.group-msg.tool { color: var(--pi-warning); }
|
|
381
|
+
.group-msg.tool-execution-shell { color: var(--pi-text); }
|
|
382
|
+
.group-msg.system { color: var(--pi-danger); }
|
|
383
|
+
.group-msg.bash { color: var(--pi-success); }
|
|
384
|
+
.history-boundary { position: relative; z-index: 5; display: grid; gap: 3px; justify-items: center; margin: 0 0 14px; color: var(--pi-muted); font-size: 12px; text-align: center; }
|
|
385
|
+
.history-load-button { border: 1px solid var(--pi-border); border-radius: 999px; background: var(--pi-surface); color: var(--pi-text-secondary); padding: 5px 12px; font: 12px system-ui, sans-serif; cursor: pointer; }
|
|
386
|
+
.history-load-button:hover, .history-load-button:focus { border-color: var(--pi-accent); color: var(--pi-text-bright); }
|
|
387
|
+
.history-load-button:disabled { cursor: default; opacity: .55; }
|
|
388
|
+
.queued-messages { max-width: 100%; min-width: 0; box-sizing: border-box; display: grid; gap: 8px; margin: 0 0 14px; padding: 12px; border: 1px solid var(--pi-warning-border); border-radius: 10px; background: var(--pi-warning-surface); color: var(--pi-text); overflow: hidden; }
|
|
389
|
+
.queued-header { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
|
|
390
|
+
.queued-header strong { color: var(--pi-warning); }
|
|
391
|
+
.queued-header small { color: var(--pi-muted); }
|
|
392
|
+
.queued-message { display: grid; gap: 4px; padding-top: 8px; border-top: 1px solid var(--pi-border); }
|
|
393
|
+
.queued-message:first-of-type { padding-top: 0; border-top: 0; }
|
|
394
|
+
.queued-kind { color: var(--pi-muted); font-size: 12px; text-transform: uppercase; }
|
|
395
|
+
.session-activity { max-width: 100%; min-width: 0; box-sizing: border-box; display: grid; gap: 4px; margin: 0 0 14px; padding: 12px; border: 1px solid var(--pi-border); border-radius: 10px; background: var(--pi-surface); color: var(--pi-text); overflow: hidden; }
|
|
396
|
+
.session-activity.compacting { border-color: var(--pi-purple-border); background: var(--pi-purple-surface); }
|
|
397
|
+
.session-activity.receiving { border-color: var(--pi-success-border); background: var(--pi-success-bg); }
|
|
398
|
+
.session-activity strong { color: var(--pi-purple); }
|
|
399
|
+
.session-activity.receiving strong { color: var(--pi-success); }
|
|
400
|
+
.session-activity span, .session-activity small { color: var(--pi-muted); }
|
|
401
|
+
.history-boundary small { color: var(--pi-dim); }
|
|
402
|
+
.msg-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 22px; margin-bottom: 8px; }
|
|
403
|
+
.msg > .msg-header { position: sticky; top: -26px; z-index: 4; margin: -12px -12px 8px; padding: 7px 10px 6px; border-radius: 9px 9px 0 0; border-bottom: 1px solid color-mix(in srgb, var(--pi-border-muted) 35%, transparent); background: var(--pi-surface); box-shadow: 0 8px 18px var(--pi-shadow-soft); }
|
|
404
|
+
.msg.user > .msg-header { border-bottom-color: color-mix(in srgb, var(--pi-accent-border) 35%, transparent); background: var(--pi-selection-bg); }
|
|
405
|
+
.msg.assistant > .msg-header .label { color: var(--pi-text-secondary); }
|
|
406
|
+
.msg.user > .msg-header .label { color: var(--pi-accent); }
|
|
407
|
+
.msg.tool > .msg-header { border-bottom-color: color-mix(in srgb, var(--pi-warning-border) 35%, transparent); background: var(--pi-warning-surface); }
|
|
408
|
+
.msg.bash > .msg-header { border-bottom-color: color-mix(in srgb, var(--pi-success) 35%, transparent); background: var(--pi-success-bg); }
|
|
409
|
+
.msg.skill > .msg-header { border-bottom-color: color-mix(in srgb, var(--pi-purple-border) 35%, transparent); background: var(--pi-purple-surface); }
|
|
410
|
+
.group-msg > .msg-header { position: sticky; top: -26px; z-index: 4; margin: -10px 0 8px; padding: 7px 0 6px; border-bottom: 1px solid color-mix(in srgb, var(--pi-border-muted) 35%, transparent); background: var(--pi-bg); }
|
|
411
|
+
.msg-header-trailing { min-width: 0; display: inline-flex; align-items: baseline; justify-content: flex-end; gap: 8px; }
|
|
412
|
+
.msg-actions { display: inline-flex; gap: 6px; opacity: 0; transition: opacity .12s ease; }
|
|
413
|
+
.msg-action { display: inline-grid; place-items: center; width: 24px; height: 24px; border: 1px solid var(--pi-border); border-radius: 6px; background: var(--pi-surface); color: var(--pi-muted); padding: 0; font: 14px system-ui, sans-serif; line-height: 1; cursor: pointer; }
|
|
414
|
+
.msg-action:hover, .msg-action:focus { color: var(--pi-text); border-color: var(--pi-accent); }
|
|
415
|
+
.msg:hover > .msg-header .msg-actions, .msg:focus-within > .msg-header .msg-actions, .group-msg:hover > .msg-header .msg-actions, .group-msg:focus-within > .msg-header .msg-actions { opacity: 1; }
|
|
416
|
+
.label { display: block; color: var(--pi-muted); font-size: 12px; text-transform: uppercase; }
|
|
417
|
+
.msg-header .label { margin: 0; }
|
|
418
|
+
.msg-meta { min-width: 0; opacity: .28; border: 0; background: transparent; color: var(--pi-dim); padding: 0; font: 11px system-ui, sans-serif; text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: opacity .12s ease, max-width .12s ease; cursor: pointer; user-select: text; -webkit-user-select: text; }
|
|
419
|
+
.msg:hover > .msg-header .msg-meta, .msg:focus-within > .msg-header .msg-meta, .group-msg:hover > .msg-header .msg-meta, .group-msg:focus-within > .msg-header .msg-meta, .msg-meta:focus, .msg-meta.expanded { opacity: 1; }
|
|
420
|
+
.msg-meta:focus { outline: 1px solid var(--pi-border); outline-offset: 3px; border-radius: 4px; }
|
|
421
|
+
@media (hover: none) {
|
|
422
|
+
.msg-actions { opacity: 1; }
|
|
423
|
+
.msg-meta { opacity: .75; max-width: 26px; }
|
|
424
|
+
.msg-meta::before { content: "ⓘ"; font-size: 13px; }
|
|
425
|
+
.msg-meta:focus, .msg-meta.expanded { opacity: 1; max-width: 75%; }
|
|
426
|
+
.msg-meta:focus::before, .msg-meta.expanded::before { content: ""; }
|
|
427
|
+
}
|
|
428
|
+
formatted-text.part { display: block; }
|
|
429
|
+
.part { max-width: 100%; min-width: 0; box-sizing: border-box; overflow: visible; }
|
|
430
|
+
.part + .part { margin-top: 10px; }
|
|
431
|
+
.tool-line { color: var(--pi-warning); }
|
|
432
|
+
.summary { color: var(--pi-muted); margin-left: 6px; }
|
|
433
|
+
.part:is(details) { border-top: 1px solid var(--pi-border); padding-top: 8px; }
|
|
434
|
+
.part > formatted-text { display: block; max-width: 100%; min-width: 0; overflow: visible; }
|
|
435
|
+
.skill-invocation, .skill-read { border: 1px solid var(--pi-border); border-radius: 8px; background: var(--pi-surface); padding: 8px 10px; }
|
|
436
|
+
.skill-invocation > summary, .skill-read > strong { color: var(--pi-purple); }
|
|
437
|
+
.skill-invocation > small, .skill-read > small { display: block; margin: 6px 0 0; color: var(--pi-muted); }
|
|
438
|
+
summary { cursor: pointer; color: var(--pi-muted); }
|
|
439
|
+
pre { margin: 6px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; }
|
|
440
|
+
.shell-output { color: var(--pi-text); font: 13px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; line-height: 1.45; }
|
|
441
|
+
@keyframes pulse { 0%, 100% { transform: scale(.75); opacity: .55; } 50% { transform: scale(1.2); opacity: 1; } }
|
|
442
|
+
`,ag=O`
|
|
443
|
+
:host { display: block; }
|
|
444
|
+
.formatted { white-space: normal; overflow-wrap: anywhere; line-height: 1.45; }
|
|
445
|
+
p, ul, ol, pre, blockquote, table, .code-block-wrapper { margin: 0 0 10px; }
|
|
446
|
+
:is(p, ul, ol, pre, blockquote, table, .code-block-wrapper):last-child { margin-bottom: 0; }
|
|
447
|
+
ul, ol { padding-left: 22px; }
|
|
448
|
+
li + li { margin-top: 3px; }
|
|
449
|
+
code { border: 1px solid var(--pi-border); border-radius: 4px; background: var(--pi-bg); padding: 1px 4px; font: 13px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
|
|
450
|
+
.code-block-wrapper { position: relative; }
|
|
451
|
+
.code-block-wrapper pre { margin: 0; padding-right: 40px; }
|
|
452
|
+
pre { border: 1px solid var(--pi-border); border-radius: 8px; background: var(--pi-bg); padding: 10px; overflow-x: auto; overflow-y: hidden; }
|
|
453
|
+
pre code { border: 0; padding: 0; background: transparent; }
|
|
454
|
+
.code-copy-button { position: absolute; top: 6px; right: 6px; z-index: 1; display: inline-grid; place-items: center; width: 24px; height: 24px; border: 1px solid var(--pi-border); border-radius: 6px; background: var(--pi-surface); color: var(--pi-muted); padding: 0; font: 14px system-ui, sans-serif; line-height: 1; cursor: pointer; }
|
|
455
|
+
.code-copy-button:hover, .code-copy-button:focus { color: var(--pi-text); border-color: var(--pi-accent); }
|
|
456
|
+
blockquote { border-left: 3px solid var(--pi-border); padding-left: 10px; color: var(--pi-muted); }
|
|
457
|
+
a { color: var(--pi-accent); }
|
|
458
|
+
h1, h2, h3, h4 { margin: 14px 0 8px; line-height: 1.2; }
|
|
459
|
+
h1:first-child, h2:first-child, h3:first-child, h4:first-child { margin-top: 0; }
|
|
460
|
+
h1 { font-size: 20px; }
|
|
461
|
+
h2 { font-size: 17px; }
|
|
462
|
+
h3 { font-size: 15px; }
|
|
463
|
+
h4 { font-size: 14px; }
|
|
464
|
+
table { border-collapse: collapse; display: block; overflow-x: auto; overflow-y: hidden; }
|
|
465
|
+
th, td { border: 1px solid var(--pi-border); padding: 4px 8px; }
|
|
466
|
+
th { background: var(--pi-surface); }
|
|
467
|
+
`,cg=O`
|
|
468
|
+
:host { display: block; color: var(--pi-muted); font: 12px system-ui, sans-serif; }
|
|
469
|
+
.bar { display: flex; justify-content: flex-end; gap: 12px; align-items: center; min-width: 0; padding: 7px 12px; border-top: 1px solid var(--pi-border); background: var(--pi-bg); white-space: nowrap; overflow: hidden; }
|
|
470
|
+
span { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
|
|
471
|
+
.activity { display: inline-flex; align-items: center; gap: 6px; color: var(--pi-muted); }
|
|
472
|
+
.activity.active { color: var(--pi-success); }
|
|
473
|
+
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .45; flex: 0 0 auto; }
|
|
474
|
+
.activity.active .dot { animation: pulse 1s ease-in-out infinite; opacity: 1; }
|
|
475
|
+
.muted { color: var(--pi-dim); }
|
|
476
|
+
@keyframes pulse { 0%, 100% { transform: scale(.75); opacity: .55; } 50% { transform: scale(1.2); opacity: 1; } }
|
|
477
|
+
`,lg=O`
|
|
478
|
+
:host { display: block; }
|
|
479
|
+
.menu { position: absolute; left: 0; right: 0; bottom: calc(100% + 6px); z-index: 10; max-height: 260px; overflow: auto; border: 1px solid var(--pi-border); border-radius: 8px; background: var(--pi-surface); box-shadow: 0 10px 30px var(--pi-shadow); }
|
|
480
|
+
button { display: grid; grid-template-columns: minmax(120px, 1fr) auto; gap: 4px 10px; width: 100%; border: 0; border-bottom: 1px solid var(--pi-border); border-radius: 0; background: transparent; color: var(--pi-text); padding: 8px 10px; text-align: left; cursor: pointer; }
|
|
481
|
+
button:last-child { border-bottom: 0; }
|
|
482
|
+
button.selected, button:hover { background: var(--pi-selection-bg); }
|
|
483
|
+
span { color: var(--pi-muted); font-size: 12px; }
|
|
484
|
+
small { grid-column: 1 / -1; color: var(--pi-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
485
|
+
`,ba=O`
|
|
486
|
+
:host { position: fixed; inset: 0; z-index: 10; color: var(--pi-text); font: 14px system-ui, sans-serif; }
|
|
487
|
+
.backdrop { display: grid; place-items: center; width: 100%; height: 100%; background: var(--pi-overlay); }
|
|
488
|
+
section { width: min(720px, calc(100vw - 40px)); max-height: min(640px, calc(100vh - 40px)); display: flex; flex-direction: column; border: 1px solid var(--pi-border); border-radius: 12px; background: var(--pi-bg); box-shadow: 0 20px 60px var(--pi-shadow-strong); overflow: hidden; }
|
|
489
|
+
header { display: flex; align-items: center; justify-content: space-between; padding: 12px; border-bottom: 1px solid var(--pi-border); }
|
|
490
|
+
.options { min-height: 0; overflow: auto; outline: none; }
|
|
491
|
+
button { border: 0; background: transparent; color: var(--pi-text); cursor: pointer; }
|
|
492
|
+
header button { font-size: 20px; color: var(--pi-muted); }
|
|
493
|
+
input { margin: 10px 12px; border: 1px solid var(--pi-border); border-radius: 8px; background: var(--pi-bg); color: var(--pi-text); font: 14px system-ui, sans-serif; padding: 8px 10px; outline: none; }
|
|
494
|
+
input:focus { border-color: var(--pi-accent); }
|
|
495
|
+
.options button { display: block; width: 100%; padding: 10px 12px; border-bottom: 1px solid var(--pi-border-muted); text-align: left; }
|
|
496
|
+
.options button.selected, .options button:hover { background: var(--pi-selection-bg); }
|
|
497
|
+
small { display: block; margin-top: 4px; color: var(--pi-muted); }
|
|
498
|
+
.empty { padding: 24px; color: var(--pi-muted); text-align: center; }
|
|
499
|
+
`,dg=O`
|
|
500
|
+
:host { position: fixed; inset: 0; z-index: 20; color: var(--pi-text); font: 14px system-ui, sans-serif; }
|
|
501
|
+
.backdrop { --palette-top: min(12dvh, 90px); --palette-bottom: max(20px, env(safe-area-inset-bottom)); display: grid; align-items: start; justify-items: center; width: 100%; height: 100dvh; background: var(--pi-overlay); padding: var(--palette-top) 20px var(--palette-bottom); box-sizing: border-box; overflow: hidden; }
|
|
502
|
+
section { width: min(720px, 100%); max-height: min(640px, calc(100dvh - var(--palette-top) - var(--palette-bottom))); display: flex; flex-direction: column; border: 1px solid var(--pi-border); border-radius: 12px; background: var(--pi-bg); box-shadow: 0 20px 60px var(--pi-shadow-strong); overflow: hidden; }
|
|
503
|
+
header { display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 10px; border-bottom: 1px solid var(--pi-border); }
|
|
504
|
+
input { min-width: 0; border: 0; outline: none; background: transparent; color: var(--pi-text); font: 16px system-ui, sans-serif; padding: 8px; }
|
|
505
|
+
input::placeholder { color: var(--pi-dim); }
|
|
506
|
+
button { border: 0; background: transparent; color: var(--pi-text); cursor: pointer; }
|
|
507
|
+
header button { color: var(--pi-muted); font-size: 22px; padding: 2px 8px; }
|
|
508
|
+
.options { flex: 1 1 auto; min-height: 0; overflow: auto; }
|
|
509
|
+
.options button { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 3px 12px; width: 100%; padding: 10px 12px; border-bottom: 1px solid var(--pi-border-muted); text-align: left; }
|
|
510
|
+
.options button.selected, .options button:hover { background: var(--pi-selection-bg); }
|
|
511
|
+
.main { min-width: 0; }
|
|
512
|
+
strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
513
|
+
small { display: block; color: var(--pi-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
514
|
+
.group { grid-column: 1 / -1; font-size: 12px; }
|
|
515
|
+
kbd { align-self: center; border: 1px solid var(--pi-border); border-radius: 6px; background: var(--pi-surface); color: var(--pi-muted); padding: 2px 6px; font: 12px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: nowrap; }
|
|
516
|
+
.empty { padding: 24px; color: var(--pi-muted); text-align: center; }
|
|
517
|
+
`,pg=O`
|
|
518
|
+
:host { position: relative; z-index: 5; display: block; color: var(--pi-text); font: 14px system-ui, sans-serif; }
|
|
519
|
+
footer { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; padding: 12px; border-top: 1px solid var(--pi-border); }
|
|
520
|
+
footer.shell-mode { border-top-color: var(--pi-success); background: var(--pi-success-bg); }
|
|
521
|
+
.editor-wrap { position: relative; min-width: 0; }
|
|
522
|
+
.actions { display: flex; gap: 8px; align-items: center; justify-content: flex-end; flex-wrap: nowrap; white-space: nowrap; }
|
|
523
|
+
.compact-status { display: flex; min-width: 0; align-items: center; gap: 6px; color: var(--pi-muted); font-size: 12px; flex: 1 1 0; }
|
|
524
|
+
.compact-status > button { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
|
|
525
|
+
.select-model { max-width: min(42vw, 320px); }
|
|
526
|
+
.icon-button { flex: 0 0 auto; display: inline-grid; place-items: center; width: 36px; height: 36px; padding: 0; }
|
|
527
|
+
.icon-button .prompt-action-icon, .icon-button .prompt-thinking-gauge { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
|
|
528
|
+
.icon-button .prompt-action-icon-filled { fill: currentColor; stroke: none; }
|
|
529
|
+
.send-button:not(:disabled) { color: var(--pi-accent, var(--pi-text)); }
|
|
530
|
+
.stop-button:not(:disabled) { color: var(--pi-danger); }
|
|
531
|
+
.select-thinking .prompt-thinking-gauge .gauge-bar { fill: currentColor; stroke: none; opacity: .28; }
|
|
532
|
+
.select-thinking .prompt-thinking-gauge .gauge-bar-active { opacity: 1; }
|
|
533
|
+
.editor-attach { position: absolute; right: 8px; bottom: 8px; z-index: 2; width: 30px; height: 30px; }
|
|
534
|
+
.editor-attach .prompt-action-icon { width: 16px; height: 16px; }
|
|
535
|
+
textarea, .markdown-editor .cm-editor { box-sizing: border-box; width: 100%; min-height: 54px; max-height: 220px; resize: none; overflow: hidden; border-radius: 8px; border: 1px solid var(--pi-border); background: var(--pi-bg); color: var(--pi-text); font: 16px/1.4 system-ui, sans-serif; }
|
|
536
|
+
textarea { overflow-y: auto; padding: 8px; }
|
|
537
|
+
.markdown-editor .cm-scroller { max-height: 220px; overflow-y: auto; font-family: system-ui, sans-serif; line-height: 1.4; }
|
|
538
|
+
.markdown-editor .cm-content { min-height: 38px; padding: 8px 44px 8px 8px; caret-color: var(--pi-text); }
|
|
539
|
+
.markdown-editor .cm-line { padding: 0; }
|
|
540
|
+
.markdown-editor .cm-placeholder { color: var(--pi-dim); }
|
|
541
|
+
.markdown-editor .cm-focused { outline: none; }
|
|
542
|
+
.shell-mode textarea, .shell-mode .markdown-editor .cm-editor { border-color: var(--pi-success); box-shadow: 0 0 0 1px var(--pi-success-ring); }
|
|
543
|
+
.mode-hint { position: absolute; right: 46px; bottom: 8px; max-width: calc(100% - 54px); border: 1px solid var(--pi-success-border); border-radius: 999px; background: var(--pi-success-surface); color: var(--pi-success); padding: 2px 8px; font-size: 12px; pointer-events: none; }
|
|
544
|
+
.attachments { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 8px; }
|
|
545
|
+
.attachment-chip { position: relative; width: 56px; height: 56px; border: 1px solid var(--pi-border); border-radius: 8px; overflow: hidden; background: var(--pi-bg); }
|
|
546
|
+
.attachment-chip img { width: 100%; height: 100%; object-fit: cover; display: block; }
|
|
547
|
+
.attachment-remove { position: absolute; top: 1px; right: 1px; width: 18px; height: 18px; padding: 0; line-height: 16px; border-radius: 50%; border: 1px solid var(--pi-border); background: var(--pi-surface); color: var(--pi-text); font-size: 13px; cursor: pointer; }
|
|
548
|
+
.attachment-delivery select { border: 1px solid var(--pi-border); border-radius: 8px; background: var(--pi-surface); color: var(--pi-text); padding: 5px 7px; font: 12px system-ui, sans-serif; }
|
|
549
|
+
.attachment-error { flex-basis: 100%; color: var(--pi-danger); font-size: 12px; }
|
|
550
|
+
button { border: 1px solid var(--pi-border); border-radius: 8px; background: var(--pi-surface); color: var(--pi-text); padding: 7px 9px; cursor: pointer; }
|
|
551
|
+
button:disabled, textarea:disabled, .markdown-editor-disabled .cm-editor { opacity: .5; cursor: not-allowed; }
|
|
552
|
+
@media (max-width: 640px) {
|
|
553
|
+
footer { gap: 8px; padding: 8px; }
|
|
554
|
+
.actions { gap: 6px; }
|
|
555
|
+
.compact-status { flex: 1 1 220px; gap: 4px; }
|
|
556
|
+
.select-model { max-width: min(58vw, 260px); }
|
|
557
|
+
button { padding: 6px 8px; }
|
|
558
|
+
}
|
|
559
|
+
@media (max-width: 430px) {
|
|
560
|
+
.compact-status { flex-basis: 170px; font-size: 11px; }
|
|
561
|
+
.select-model { max-width: 48vw; }
|
|
562
|
+
button { padding: 5px 7px; }
|
|
563
|
+
.icon-button { width: 34px; height: 34px; }
|
|
564
|
+
}
|
|
565
|
+
`;var hg=Object.defineProperty,ug=Object.getOwnPropertyDescriptor,ce=(e,t,i,s)=>{for(var o=s>1?void 0:s?ug(t,i):t,r=e.length-1,n;r>=0;r--)(n=e[r])&&(o=(s?n(t,i,o):n(o))||o);return s&&o&&hg(t,i,o),o};let Z=class extends M{constructor(){super(...arguments),this.machines=[],this.statuses={},this.activities={},this.collapsible=!1,this.collapsed=!1,this.menuStyle="",this.onDocumentClick=e=>{e.composedPath().includes(this)||(this.openMenuMachineId=void 0)}}connectedCallback(){super.connectedCallback(),document.addEventListener("click",this.onDocumentClick)}disconnectedCallback(){document.removeEventListener("click",this.onDocumentClick),super.disconnectedCallback()}updated(e){e.has("machines")&&this.openMenuMachineId!==void 0&&!this.machines.some(t=>t.id===this.openMenuMachineId)&&(this.openMenuMachineId=void 0),e.has("collapsed")&&this.collapsed&&(this.openMenuMachineId=void 0)}async focusSelectedOrFirst(){return await this.updateComplete,ji(this.renderRoot,{fallbackSelector:".section-toggle"})}render(){return c`
|
|
566
|
+
<section>
|
|
567
|
+
<h2>${this.renderHeading()}</h2>
|
|
568
|
+
${this.collapsed?null:c`
|
|
569
|
+
<div class="list-body">
|
|
570
|
+
${this.machines.map(e=>this.renderMachine(e))}
|
|
571
|
+
</div>
|
|
572
|
+
`}
|
|
573
|
+
</section>
|
|
574
|
+
`}renderMachine(e){const t=this.statuses[e.id]?.status??e.status??"unknown",i=t==="online"?"在线":t==="offline"?"离线":t==="error"?"错误":"未知",s=wa(e)&&this.onRemove!==void 0;return c`
|
|
575
|
+
<div
|
|
576
|
+
class=${`action-row machine-row ${this.selected?.id===e.id?"selected":""} ${s?"":"no-actions"}`}
|
|
577
|
+
tabindex="0"
|
|
578
|
+
title=${e.baseUrl??e.name}
|
|
579
|
+
@click=${o=>{_i(o,()=>this.onSelect?.(e))}}
|
|
580
|
+
@keydown=${o=>{this.handleMachineKeydown(o,e)}}
|
|
581
|
+
>
|
|
582
|
+
<div class="action-main">
|
|
583
|
+
<span class="action-name machine-primary">${this.renderActivity(e)}<span class="machine-primary-label">${e.name}</span></span><small>${e.kind==="local"?"本机 Pi Web":e.baseUrl??"远程 Pi Web"} · ${i}</small>
|
|
584
|
+
</div>
|
|
585
|
+
${s?this.renderMachineMenu(e):null}
|
|
586
|
+
</div>
|
|
587
|
+
`}renderActivity(e){const t=this.statuses[e.id]?.status??e.status;if(t==="offline"||t==="error")return;const i=da(this.activities[e.id]);return Oi(i,i==="terminal"?"机器终端活跃":"机器活跃")}renderMachineMenu(e){const t=this.openMenuMachineId===e.id,i=fg(e.id);return c`
|
|
588
|
+
<div class="action-menu">
|
|
589
|
+
<button
|
|
590
|
+
class="action-menu-toggle"
|
|
591
|
+
title="机器操作"
|
|
592
|
+
aria-label=${`${e.name} 的操作`}
|
|
593
|
+
aria-expanded=${String(t)}
|
|
594
|
+
aria-controls=${i}
|
|
595
|
+
@click=${s=>{s.stopPropagation(),this.toggleMenu(e.id,s.currentTarget)}}
|
|
596
|
+
>⋯</button>
|
|
597
|
+
${t?c`
|
|
598
|
+
<div class="action-menu-panel machine-menu-panel" id=${i} style=${this.menuStyle} @click=${s=>{s.stopPropagation()}}>
|
|
599
|
+
<button class="danger" title=${`移除 ${e.name}`} @click=${()=>{this.removeMachine(e)}}>移除</button>
|
|
600
|
+
</div>
|
|
601
|
+
`:null}
|
|
602
|
+
</div>
|
|
603
|
+
`}renderHeading(){if(!this.collapsible)return"机器";const e=this.selected?.name??"未选择机器",t=this.selected?.baseUrl??e;return c`<button class="section-toggle" aria-expanded=${String(!this.collapsed)} @click=${()=>{this.onToggleCollapsed?.()}}><span class="section-title"><span class="section-name">${this.collapsed?"▸":"▾"} 机器</span>${this.collapsed?c`<small class="section-selected" title=${t}>${e}</small>`:null}</span><small class="section-count">${this.machines.length}</small></button>`}toggleMenu(e,t){if(this.openMenuMachineId===e){this.openMenuMachineId=void 0;return}this.menuStyle=Bt(t,{constrainTo:"viewport"}),this.openMenuMachineId=e}removeMachine(e){this.openMenuMachineId=void 0,this.onRemove?.(e)}handleMachineKeydown(e,t){if(e.key==="Escape"&&this.openMenuMachineId===t.id){e.preventDefault(),e.stopPropagation(),this.openMenuMachineId=void 0;return}Li(e,{activate:()=>this.onSelect?.(t),nextSection:this.onFocusNextSection===void 0?void 0:()=>{this.onFocusNextSection?.()},cancel:this.onCancelKeyboardNavigation===void 0?void 0:()=>{this.onCancelKeyboardNavigation?.()}})}};Z.styles=[Fi,O`
|
|
604
|
+
.machine-row.no-actions .action-main { border-radius: 8px; }
|
|
605
|
+
.machine-primary { display: flex; align-items: baseline; gap: 6px; }
|
|
606
|
+
.machine-primary-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
|
|
607
|
+
.machine-menu-panel button.danger { color: var(--pi-danger); }
|
|
608
|
+
.machine-menu-panel button.danger:hover, .machine-menu-panel button.danger:focus { background: color-mix(in srgb, var(--pi-danger) 14%, transparent); }
|
|
609
|
+
`];ce([d({attribute:!1})],Z.prototype,"machines",2);ce([d({attribute:!1})],Z.prototype,"selected",2);ce([d({attribute:!1})],Z.prototype,"statuses",2);ce([d({attribute:!1})],Z.prototype,"activities",2);ce([d({type:Boolean,reflect:!0})],Z.prototype,"collapsible",2);ce([d({type:Boolean,reflect:!0})],Z.prototype,"collapsed",2);ce([d({attribute:!1})],Z.prototype,"onSelect",2);ce([d({attribute:!1})],Z.prototype,"onRemove",2);ce([d({attribute:!1})],Z.prototype,"onToggleCollapsed",2);ce([d({attribute:!1})],Z.prototype,"onFocusNextSection",2);ce([d({attribute:!1})],Z.prototype,"onCancelKeyboardNavigation",2);ce([y()],Z.prototype,"openMenuMachineId",2);ce([y()],Z.prototype,"menuStyle",2);Z=ce([D("machine-list")],Z);function wa(e){return e.kind==="remote"}function fg(e){return`machine-menu-${e.replace(/[^a-zA-Z0-9_-]/g,"-")}`}var gg=Object.defineProperty,mg=Object.getOwnPropertyDescriptor,ie=(e,t,i,s)=>{for(var o=s>1?void 0:s?mg(t,i):t,r=e.length-1,n;r>=0;r--)(n=e[r])&&(o=(s?n(t,i,o):n(o))||o);return s&&o&&gg(t,i,o),o};let G=class extends M{constructor(){super(...arguments),this.projects=[],this.activities={},this.workspacesByProjectId={},this.collapsible=!1,this.collapsed=!1,this.menuStyle="",this.onDocumentClick=e=>{e.composedPath().includes(this)||(this.openMenuProjectId=void 0)}}connectedCallback(){super.connectedCallback(),document.addEventListener("click",this.onDocumentClick)}disconnectedCallback(){document.removeEventListener("click",this.onDocumentClick),super.disconnectedCallback()}updated(e){e.has("projects")&&this.openMenuProjectId!==void 0&&!this.projects.some(t=>t.id===this.openMenuProjectId)&&(this.openMenuProjectId=void 0),e.has("collapsed")&&this.collapsed&&(this.openMenuProjectId=void 0)}async focusSelectedOrFirst(){return await this.updateComplete,ji(this.renderRoot,{fallbackSelector:".section-toggle"})}render(){return c`
|
|
610
|
+
<section>
|
|
611
|
+
<h2>${this.renderHeading()}</h2>
|
|
612
|
+
${this.collapsed?null:c`
|
|
613
|
+
<div class="list-body">
|
|
614
|
+
${this.projects.length===0?c`
|
|
615
|
+
<div class="empty-list" role="status">
|
|
616
|
+
<strong>暂无可访问项目</strong>
|
|
617
|
+
<small>请先在 AI 平台手动创建项目,然后刷新此页面。</small>
|
|
618
|
+
</div>
|
|
619
|
+
`:this.projects.map(e=>c`
|
|
620
|
+
<div
|
|
621
|
+
class=${`action-row ${this.selected?.id===e.id?"selected":""}`}
|
|
622
|
+
tabindex="0"
|
|
623
|
+
title=${e.path}
|
|
624
|
+
@click=${t=>{_i(t,()=>this.onSelect?.(e))}}
|
|
625
|
+
@keydown=${t=>{this.handleProjectKeydown(t,e)}}
|
|
626
|
+
>
|
|
627
|
+
<div class="action-main">
|
|
628
|
+
<span class="action-name">${e.name}</span><small>${e.path}</small>
|
|
629
|
+
${this.renderActivity(e)}
|
|
630
|
+
</div>
|
|
631
|
+
<div class="action-menu">
|
|
632
|
+
<button class="action-menu-toggle" title="项目操作" aria-label=${`${e.name} 的操作`} @click=${t=>{t.stopPropagation(),this.toggleMenu(e.id,t.currentTarget)}}>⋯</button>
|
|
633
|
+
${this.openMenuProjectId===e.id?c`
|
|
634
|
+
<div class="action-menu-panel" style=${this.menuStyle}>
|
|
635
|
+
<button title="关闭项目" @click=${()=>{this.close(e)}}>关闭</button>
|
|
636
|
+
</div>
|
|
637
|
+
`:null}
|
|
638
|
+
</div>
|
|
639
|
+
</div>
|
|
640
|
+
`)}
|
|
641
|
+
</div>
|
|
642
|
+
`}
|
|
643
|
+
</section>
|
|
644
|
+
`}handleProjectKeydown(e,t){Li(e,{activate:()=>this.onSelect?.(t),previousSection:this.onFocusPreviousSection===void 0?void 0:()=>{this.onFocusPreviousSection?.()},nextSection:this.onFocusNextSection===void 0?void 0:()=>{this.onFocusNextSection?.()},cancel:this.onCancelKeyboardNavigation===void 0?void 0:()=>{this.onCancelKeyboardNavigation?.()}})}renderHeading(){if(!this.collapsible)return"项目";const e=this.selected?.name??"未选择项目",t=this.selected?.path??e;return c`<button class="section-toggle" aria-expanded=${String(!this.collapsed)} @click=${()=>{this.onToggleCollapsed?.()}}><span class="section-title"><span class="section-name">${this.collapsed?"▸":"▾"} 项目</span>${this.collapsed?c`<small class="section-selected" title=${t}>${e}</small>`:null}</span><small class="section-count">${this.projects.length}</small></button>`}renderActivity(e){const t=Zf(e,this.workspacesByProjectId[e.id]??[],this.activities);return Oi(t,t==="terminal"?"项目终端活跃":"项目活跃")}toggleMenu(e,t){if(this.openMenuProjectId===e){this.openMenuProjectId=void 0;return}this.menuStyle=Bt(t,{constrainTo:"viewport"}),this.openMenuProjectId=e}close(e){this.openMenuProjectId=void 0,confirm(`关闭 ${e.name}?
|
|
645
|
+
|
|
646
|
+
这只会从 PI WEB 中移除它,不会修改项目文件夹。`)&&this.onClose?.(e)}};G.styles=Fi;ie([d({attribute:!1})],G.prototype,"projects",2);ie([d({attribute:!1})],G.prototype,"selected",2);ie([d({attribute:!1})],G.prototype,"activities",2);ie([d({attribute:!1})],G.prototype,"workspacesByProjectId",2);ie([d({type:Boolean,reflect:!0})],G.prototype,"collapsible",2);ie([d({type:Boolean,reflect:!0})],G.prototype,"collapsed",2);ie([d({attribute:!1})],G.prototype,"onSelect",2);ie([d({attribute:!1})],G.prototype,"onClose",2);ie([d({attribute:!1})],G.prototype,"onToggleCollapsed",2);ie([d({attribute:!1})],G.prototype,"onFocusPreviousSection",2);ie([d({attribute:!1})],G.prototype,"onFocusNextSection",2);ie([d({attribute:!1})],G.prototype,"onCancelKeyboardNavigation",2);ie([y()],G.prototype,"openMenuProjectId",2);ie([y()],G.prototype,"menuStyle",2);G=ie([D("project-list")],G);function Cr(e=[]){return e.map((t,i)=>c`${i===0?null:c`<span class="workspace-label-separator">·</span>`}${vg(t)}`)}function vg(e){if(e.type==="render")return c`<span class="workspace-label-render">${e.render()}</span>`;if(e.type==="link"&&bg(e.href)){const t=e.target??"_blank",i=t==="_blank"?"noopener noreferrer":void 0;return c`<a class="workspace-label-item workspace-label-link" href=${e.href} title=${e.title??e.text} target=${t} rel=${i??void 0}>${e.text}</a>`}return c`<span class="workspace-label-item" title=${e.title??e.text}>${e.text}</span>`}function bg(e){const t=e.trim().toLowerCase();return t!==""&&!t.startsWith("javascript:")&&!t.startsWith("data:")}var wg=Object.defineProperty,yg=Object.getOwnPropertyDescriptor,X=(e,t,i,s)=>{for(var o=s>1?void 0:s?yg(t,i):t,r=e.length-1,n;r>=0;r--)(n=e[r])&&(o=(s?n(t,i,o):n(o))||o);return s&&o&&wg(t,i,o),o};let q=class extends M{constructor(){super(...arguments),this.workspaces=[],this.collapsible=!1,this.collapsed=!1,this.workspaceLabelItems=()=>[],this.activities={},this.deletingWorkspaceIds=[],this.menuStyle="",this.onDocumentClick=e=>{e.composedPath().includes(this)||(this.openMenuWorkspaceId=void 0)}}connectedCallback(){super.connectedCallback(),document.addEventListener("click",this.onDocumentClick)}disconnectedCallback(){document.removeEventListener("click",this.onDocumentClick),super.disconnectedCallback()}updated(e){e.has("workspaces")&&this.openMenuWorkspaceId!==void 0&&!this.workspaces.some(t=>t.id===this.openMenuWorkspaceId)&&(this.openMenuWorkspaceId=void 0),e.has("collapsed")&&this.collapsed&&(this.openMenuWorkspaceId=void 0),(e.has("selected")||e.has("workspaces")||e.has("collapsed"))&&!this.collapsed&&this.scrollSelectedIntoView()}async focusSelectedOrFirst(){return await this.updateComplete,ji(this.renderRoot,{fallbackSelector:".section-toggle"})}render(){return c`
|
|
647
|
+
<section>
|
|
648
|
+
<h2>${this.renderHeading()}</h2>
|
|
649
|
+
${this.collapsed?null:c`
|
|
650
|
+
<div class="list-body">
|
|
651
|
+
${this.workspaces.map(e=>{const t=Sg(e),i=this.workspaceLabelItems(e);return c`
|
|
652
|
+
<div
|
|
653
|
+
class=${`action-row workspace-row ${this.selected?.id===e.id?"selected":""}`}
|
|
654
|
+
tabindex="0"
|
|
655
|
+
title=${t}
|
|
656
|
+
@click=${s=>{_i(s,()=>this.onSelect?.(e))}}
|
|
657
|
+
@keydown=${s=>{this.handleWorkspaceKeydown(s,e)}}
|
|
658
|
+
>
|
|
659
|
+
<div class="action-main">
|
|
660
|
+
${this.renderWorkspaceMain(t,i,e)}
|
|
661
|
+
</div>
|
|
662
|
+
${this.renderWorkspaceMenu(t,i,e)}
|
|
663
|
+
</div>
|
|
664
|
+
`})}
|
|
665
|
+
</div>
|
|
666
|
+
`}
|
|
667
|
+
</section>
|
|
668
|
+
`}renderHeading(){if(!this.collapsible)return"工作区";const e=this.selected===void 0?"未选择工作区":`${this.selected.label}${this.selected.isMain?" · 主工作区":""} · ${this.selected.path}`,t=this.selected?.path??e;return c`<button class="section-toggle" aria-expanded=${String(!this.collapsed)} @click=${()=>{this.onToggleCollapsed?.()}}><span class="section-title"><span class="section-name">${this.collapsed?"▸":"▾"} 工作区</span>${this.collapsed?c`<small class="section-selected" title=${t}>${e}</small>`:null}</span><small class="section-count">${this.workspaces.length}</small></button>`}renderActivity(e){const t=Qf(Jf(e,this.activities));return Oi(t,t==="terminal"?"工作区终端活跃":"工作区活跃")}renderWorkspaceMain(e,t,i){return c`
|
|
669
|
+
<span class="workspace-primary">
|
|
670
|
+
<span class="workspace-primary-label">${e}</span>
|
|
671
|
+
${this.isDeleting(i)?c`<span class="workspace-status">正在删除…</span>`:null}
|
|
672
|
+
</span>
|
|
673
|
+
${t.length===0?null:c`
|
|
674
|
+
<small class="workspace-secondary">
|
|
675
|
+
<span class="workspace-label">${Cr(t)}</span>
|
|
676
|
+
</small>
|
|
677
|
+
`}
|
|
678
|
+
${this.renderActivity(i)}
|
|
679
|
+
`}renderWorkspaceMenu(e,t,i){const s=this.openMenuWorkspaceId===i.id,o=kg(i.id);return c`
|
|
680
|
+
<div class="action-menu">
|
|
681
|
+
<button
|
|
682
|
+
class="action-menu-toggle"
|
|
683
|
+
title="工作区操作和详情"
|
|
684
|
+
aria-label=${`${e} 的操作和详情`}
|
|
685
|
+
aria-expanded=${String(s)}
|
|
686
|
+
aria-controls=${o}
|
|
687
|
+
@click=${r=>{r.stopPropagation(),this.toggleMenu(i.id,r.currentTarget)}}
|
|
688
|
+
>⋯</button>
|
|
689
|
+
${s?c`
|
|
690
|
+
<div class="action-menu-panel workspace-menu-panel" id=${o} style=${this.menuStyle} @click=${r=>{r.stopPropagation()}}>
|
|
691
|
+
${this.renderWorkspaceActions(i)}
|
|
692
|
+
${this.renderWorkspaceDetails(e,t,i)}
|
|
693
|
+
</div>
|
|
694
|
+
`:null}
|
|
695
|
+
</div>
|
|
696
|
+
`}renderWorkspaceActions(e){if(!xg(e))return;const t=this.isDeleting(e);return c`
|
|
697
|
+
<div class="workspace-menu-actions">
|
|
698
|
+
<button class="danger" title=${t?"正在删除工作区":"删除工作区"} ?disabled=${t} @click=${()=>{this.delete(e)}}>${t?"正在删除…":"删除工作区"}</button>
|
|
699
|
+
</div>
|
|
700
|
+
`}renderWorkspaceDetails(e,t,i){return c`
|
|
701
|
+
<dl class="workspace-menu-details">
|
|
702
|
+
<div class="workspace-detail-row">
|
|
703
|
+
<dt>${i.branch===void 0?"工作区":"分支"}</dt>
|
|
704
|
+
<dd>${e}</dd>
|
|
705
|
+
</div>
|
|
706
|
+
<div class="workspace-detail-row">
|
|
707
|
+
<dt>路径</dt>
|
|
708
|
+
<dd title=${i.path}>${i.path}</dd>
|
|
709
|
+
</div>
|
|
710
|
+
${t.length===0?null:c`
|
|
711
|
+
<div class="workspace-detail-row">
|
|
712
|
+
<dt>详情</dt>
|
|
713
|
+
<dd><span class="workspace-label">${Cr(t)}</span></dd>
|
|
714
|
+
</div>
|
|
715
|
+
`}
|
|
716
|
+
</dl>
|
|
717
|
+
`}delete(e){this.isDeleting(e)||(this.openMenuWorkspaceId=void 0,this.onDelete?.(e))}isDeleting(e){return this.deletingWorkspaceIds.includes(e.id)}toggleMenu(e,t){if(this.openMenuWorkspaceId===e){this.openMenuWorkspaceId=void 0;return}this.menuStyle=Bt(t,{constrainTo:"viewport"}),this.openMenuWorkspaceId=e}handleWorkspaceKeydown(e,t){if(e.key==="Escape"&&this.openMenuWorkspaceId===t.id){e.preventDefault(),e.stopPropagation(),this.openMenuWorkspaceId=void 0;return}Li(e,{activate:()=>this.onSelect?.(t),previousSection:this.onFocusPreviousSection===void 0?void 0:()=>{this.onFocusPreviousSection?.()},nextSection:this.onFocusNextSection===void 0?void 0:()=>{this.onFocusNextSection?.()},cancel:this.onCancelKeyboardNavigation===void 0?void 0:()=>{this.onCancelKeyboardNavigation?.()}})}scrollSelectedIntoView(){this.renderRoot.querySelector(".action-row.selected")?.scrollIntoView({block:"nearest"})}};q.styles=Fi;X([d({attribute:!1})],q.prototype,"workspaces",2);X([d({attribute:!1})],q.prototype,"selected",2);X([d({type:Boolean,reflect:!0})],q.prototype,"collapsible",2);X([d({type:Boolean,reflect:!0})],q.prototype,"collapsed",2);X([d({attribute:!1})],q.prototype,"workspaceLabelItems",2);X([d({attribute:!1})],q.prototype,"activities",2);X([d({attribute:!1})],q.prototype,"deletingWorkspaceIds",2);X([d({attribute:!1})],q.prototype,"onSelect",2);X([d({attribute:!1})],q.prototype,"onDelete",2);X([d({attribute:!1})],q.prototype,"onToggleCollapsed",2);X([d({attribute:!1})],q.prototype,"onFocusPreviousSection",2);X([d({attribute:!1})],q.prototype,"onFocusNextSection",2);X([d({attribute:!1})],q.prototype,"onCancelKeyboardNavigation",2);X([y()],q.prototype,"openMenuWorkspaceId",2);X([y()],q.prototype,"menuStyle",2);q=X([D("workspace-list")],q);function Sg(e){return`${e.branch??e.label}${e.isMain?" · 主工作区":""}`}function xg(e){return e.isGitWorktree&&!e.isMain}function kg(e){return`workspace-menu-${e.replace(/[^a-zA-Z0-9_-]/g,"-")}`}var $g=Object.defineProperty,Pg=Object.getOwnPropertyDescriptor,T=(e,t,i,s)=>{for(var o=s>1?void 0:s?Pg(t,i):t,r=e.length-1,n;r>=0;r--)(n=e[r])&&(o=(s?n(t,i,o):n(o))||o);return s&&o&&$g(t,i,o),o};function St(e){return e.name!==void 0&&e.name!==""?e.name:e.firstMessage!==""?e.firstMessage:e.id.slice(0,8)}let I=class extends M{constructor(){super(...arguments),this.sessions=[],this.statuses={},this.activities={},this.sending={},this.canStart=!1,this.canDeleteArchived=!1,this.canReload=!1,this.archivedDeleteUnavailableMessage="请更新并重启此机器上的 Pi-Web 后再删除已归档会话。",this.collapsible=!1,this.collapsed=!1,this.menuStyle="",this.archivedExpanded=!1,this.selectionScopes=new Set,this.selectedSessionIds=new Set,this.onDocumentClick=e=>{e.composedPath().includes(this)||(this.openMenuSessionId=void 0)}}connectedCallback(){super.connectedCallback(),document.addEventListener("click",this.onDocumentClick)}disconnectedCallback(){document.removeEventListener("click",this.onDocumentClick),super.disconnectedCallback()}updated(e){e.has("sessions")&&(this.openMenuSessionId!==void 0&&!this.sessions.some(i=>i.id===this.openMenuSessionId)&&(this.openMenuSessionId=void 0),this.sessions.some(i=>i.archived===!0)||(this.archivedExpanded=!1),this.pruneSelectedSessionIds()),e.has("collapsed")&&this.collapsed&&(this.openMenuSessionId=void 0);const t=e.get("selected");if(e.has("selected")&&this.selected?.archived===!0&&(t?.id!==this.selected.id||t.archived!==!0)&&!this.archivedExpanded){this.archivedExpanded=!0,this.updateComplete.then(()=>{this.scrollSelectedIntoView()});return}(e.has("selected")||e.has("sessions")||e.has("collapsed"))&&!this.collapsed&&this.scrollSelectedIntoView()}async focusSelectedOrFirst(){return await this.updateComplete,ji(this.renderRoot,{fallbackSelector:".section-toggle, h2 button:not([disabled])"})}render(){const e=Cg(this.sessions),t=new Set(e.map(r=>r.session.id)),i=e.map(r=>r.session).filter(r=>xt(r)==="current"),s=ya(this.sessions.filter(r=>r.archived===!0&&!t.has(r.id))),o=Rg(this.sessions);return c`
|
|
718
|
+
<section>
|
|
719
|
+
${this.renderHeading(e.length+s.length,i)}
|
|
720
|
+
${this.collapsed?null:c`
|
|
721
|
+
<div class="list-body">
|
|
722
|
+
${this.renderCurrentSelectionToolbar(i)}
|
|
723
|
+
${e.map(r=>this.renderSession(r,o.get(r.session.id)??0,"current"))}
|
|
724
|
+
${s.length>0?c`
|
|
725
|
+
${this.renderArchivedHeading(s.map(r=>r.session))}
|
|
726
|
+
${this.archivedExpanded?c`
|
|
727
|
+
${this.renderArchivedSelectionToolbar(s.map(r=>r.session))}
|
|
728
|
+
${s.map(r=>this.renderSession(r,o.get(r.session.id)??0,"archived"))}
|
|
729
|
+
`:null}
|
|
730
|
+
`:null}
|
|
731
|
+
</div>
|
|
732
|
+
`}
|
|
733
|
+
</section>
|
|
734
|
+
`}renderHeading(e,t){if(!this.collapsible)return c`
|
|
735
|
+
<h2>
|
|
736
|
+
会话
|
|
737
|
+
${this.renderCurrentSelectionButton(t)}
|
|
738
|
+
<button ?disabled=${!this.canStart} @click=${()=>this.onStart?.()}>+</button>
|
|
739
|
+
</h2>
|
|
740
|
+
`;const i=this.selected===void 0?"未选择会话":St(this.selected),s=this.selected?.path??i;return c`
|
|
741
|
+
<h2>
|
|
742
|
+
<button class="section-toggle" aria-expanded=${String(!this.collapsed)} @click=${()=>{this.onToggleCollapsed?.()}}><span class="section-title"><span class="section-name">${this.collapsed?"▸":"▾"} 会话</span>${this.collapsed?c`<small class="section-selected" title=${s}>${i}</small>`:null}</span></button>
|
|
743
|
+
${this.renderCurrentSelectionButton(t)}
|
|
744
|
+
<small class="section-count">${e}</small>
|
|
745
|
+
<button ?disabled=${!this.canStart} @click=${o=>{o.stopPropagation(),this.onStart?.()}}>+</button>
|
|
746
|
+
</h2>
|
|
747
|
+
`}renderCurrentSelectionButton(e){if(this.collapsed||e.length===0)return null;const t=this.selectionScopes.has("current");return c`<button class="bulk-select-entry ${t?"selected":""}" title=${t?"关闭当前会话选择":"选择当前会话"} aria-label=${t?"关闭当前会话选择":"选择当前会话"} aria-expanded=${String(t)} aria-pressed=${String(t)} @click=${i=>{i.stopPropagation(),this.toggleSelection("current",e)}}>☑</button>`}renderArchivedHeading(e){const t=this.selectionScopes.has("archived");return c`
|
|
748
|
+
<h2 class="subheading">
|
|
749
|
+
<button class="section-toggle" aria-expanded=${String(this.archivedExpanded)} @click=${()=>{this.toggleArchived()}}><span>${this.archivedExpanded?"▾":"▸"} 已归档</span></button>
|
|
750
|
+
${this.archivedExpanded?c`<button class="bulk-select-entry ${t?"selected":""}" title=${t?"关闭已归档会话选择":"选择已归档会话"} aria-label=${t?"关闭已归档会话选择":"选择已归档会话"} aria-expanded=${String(t)} aria-pressed=${String(t)} @click=${()=>{this.toggleSelection("archived",e)}}>☑</button>`:null}
|
|
751
|
+
<small class="section-count">${e.length}</small>
|
|
752
|
+
</h2>
|
|
753
|
+
`}renderCurrentSelectionToolbar(e){if(e.length===0||!this.selectionScopes.has("current"))return null;const t=this.selectedSessions("current"),i=t.filter(r=>!ee(r)),s=e.length>0&&e.every(r=>this.selectedSessionIds.has(r.id)),o=e.filter(r=>this.selectedSessionIds.has(r.id)).length;return c`
|
|
754
|
+
<div class="bulk-row selecting">
|
|
755
|
+
<button ?disabled=${e.length===0} @click=${()=>{this.toggleVisibleSelection(e,!s)}}>${s?"清除可见":"选择可见"}</button>
|
|
756
|
+
<small>${t.length} 已选${o!==t.length?c` · ${o} 可见`:null}</small>
|
|
757
|
+
<button ?disabled=${i.length===0} @click=${()=>{this.archiveSelectedCurrent()}}>归档所选</button>
|
|
758
|
+
<button @click=${()=>{this.clearSelection("current")}}>清除</button>
|
|
759
|
+
<button @click=${()=>{this.closeSelection("current")}}>完成</button>
|
|
760
|
+
</div>
|
|
761
|
+
`}renderArchivedSelectionToolbar(e){if(e.length===0||!this.selectionScopes.has("archived"))return null;const t=this.selectedSessions("archived"),i=e.length>0&&e.every(o=>this.selectedSessionIds.has(o.id)),s=e.filter(o=>this.selectedSessionIds.has(o.id)).length;return c`
|
|
762
|
+
<div class="bulk-row selecting">
|
|
763
|
+
<button ?disabled=${e.length===0} @click=${()=>{this.toggleVisibleSelection(e,!i)}}>${i?"清除可见":"选择可见"}</button>
|
|
764
|
+
<small>${t.length} 已选${s!==t.length?c` · ${s} 可见`:null}</small>
|
|
765
|
+
<button class="danger" title=${this.canDeleteArchived?"永久删除所选已归档会话":this.archivedDeleteUnavailableMessage} ?disabled=${t.length===0||!this.canDeleteArchived} @click=${()=>{this.confirmDeleteSelectedArchived()}}>删除所选</button>
|
|
766
|
+
<button @click=${()=>{this.clearSelection("archived")}}>清除</button>
|
|
767
|
+
<button @click=${()=>{this.closeSelection("archived")}}>完成</button>
|
|
768
|
+
${this.canDeleteArchived?null:c`<small class="capability-hint">${this.archivedDeleteUnavailableMessage}</small>`}
|
|
769
|
+
</div>
|
|
770
|
+
`}renderSession(e,t,i){const{session:s}=e,o=Math.min(e.depth,2),r=xt(s)===i,n=this.selectionScopes.has(i),a=n&&r,l=a&&this.selectedSessionIds.has(s.id);return c`
|
|
771
|
+
<div
|
|
772
|
+
class="action-row ${this.selected?.id===s.id?"selected":""} ${l?"bulk-selected":""} ${s.archived===!0?"archived":""} ${n?"selecting":""}"
|
|
773
|
+
style=${`--depth:${String(o)}`}
|
|
774
|
+
tabindex="0"
|
|
775
|
+
title=${s.path}
|
|
776
|
+
@click=${p=>{_i(p,()=>{this.activateSessionRow(s,i)})}}
|
|
777
|
+
@keydown=${p=>{this.handleSessionKeydown(p,s,i)}}
|
|
778
|
+
>
|
|
779
|
+
<div class="action-main ${n?"selecting":""}">
|
|
780
|
+
${a?c`<input class="session-checkbox" type="checkbox" aria-label=${`选择 ${St(s)}`} .checked=${l} @click=${p=>{p.stopPropagation()}} @change=${()=>{this.toggleSelected(s.id)}}>`:null}
|
|
781
|
+
<span class="action-name">${e.depth>0?c`<span class="tree-marker">↳</span>`:null}${St(s)}${e.depth>2?c` <span class="badge">深度 ${e.depth}</span>`:null}${e.hasMissingParent?c` <span class="badge">父会话不可用</span>`:null}</span><small>${this.renderSessionMetaPrefix(s)}${String(s.messageCount)} 条消息</small>
|
|
782
|
+
${this.renderActivity(s)}
|
|
783
|
+
</div>
|
|
784
|
+
<div class="action-menu">
|
|
785
|
+
<button class="action-menu-toggle" title="会话操作" @click=${p=>{p.stopPropagation(),this.toggleMenu(s.id,p.currentTarget)}}>⋯</button>
|
|
786
|
+
${this.openMenuSessionId===s.id?c`
|
|
787
|
+
<div class="action-menu-panel" style=${this.menuStyle}>
|
|
788
|
+
${ee(s)?c`<button title="删除浏览器缓存的新会话" @click=${()=>{this.openMenuSessionId=void 0,this.onDelete?.(s)}}>删除</button>`:s.archived===!0?c`
|
|
789
|
+
<button title="恢复会话" @click=${()=>{this.openMenuSessionId=void 0,this.onRestore?.(s)}}>恢复</button>
|
|
790
|
+
<button class="danger" title=${this.canDeleteArchived?"永久删除已归档会话":this.archivedDeleteUnavailableMessage} ?disabled=${!this.canDeleteArchived} @click=${()=>{this.openMenuSessionId=void 0,this.confirmDeleteArchived(s)}}>删除已归档会话</button>
|
|
791
|
+
`:c`
|
|
792
|
+
${this.canReload?c`<button title=${Qe(this.statuses[s.id],this.activities[s.id])?"当前会话活动结束后才能重新加载":"从磁盘重新加载会话"} ?disabled=${Qe(this.statuses[s.id],this.activities[s.id])} @click=${()=>{this.openMenuSessionId=void 0,this.onReload?.(s)}}>重新加载</button>`:null}
|
|
793
|
+
${s.parentSessionPath!==void 0?c`<button title="从父会话分离" @click=${()=>{this.openMenuSessionId=void 0,this.onDetachParent?.(s)}}>从父会话分离</button>`:null}
|
|
794
|
+
<button title="归档会话" @click=${()=>{this.openMenuSessionId=void 0,this.onArchive?.(s)}}>归档</button>
|
|
795
|
+
${t>0?c`<button title="归档此会话及其后代会话" @click=${()=>{this.openMenuSessionId=void 0,this.confirmArchiveWithDescendants(s,t)}}>连同后代归档(${t})</button>`:null}
|
|
796
|
+
`}
|
|
797
|
+
</div>
|
|
798
|
+
`:null}
|
|
799
|
+
</div>
|
|
800
|
+
</div>
|
|
801
|
+
`}handleSessionKeydown(e,t,i){Li(e,{activate:()=>{this.activateSessionRow(t,i)},previousSection:this.onFocusPreviousSection===void 0?void 0:()=>{this.onFocusPreviousSection?.()},nextSection:this.onFocusNextSection===void 0?void 0:()=>{this.onFocusNextSection?.()},cancel:this.onCancelKeyboardNavigation===void 0?void 0:()=>{this.onCancelKeyboardNavigation?.()}})}activateSessionRow(e,t){if(this.selectionScopes.has(t)&&xt(e)===t){this.toggleSelected(e.id);return}this.onSelect?.(e)}confirmArchiveWithDescendants(e,t){confirm(`归档“${St(e)}”及其 ${String(t)} 个后代会话?`)&&this.onArchiveWithDescendants?.(e)}confirmDeleteArchived(e){this.canDeleteArchived&&confirm(`永久删除已归档会话“${St(e)}”?此操作无法撤销。`)&&this.onDeleteArchived?.(e)}confirmDeleteSelectedArchived(){if(!this.canDeleteArchived)return;const e=this.selectedSessions("archived");e.length!==0&&confirm(`永久删除 ${String(e.length)} 个所选已归档会话?此操作无法撤销。`)&&(this.selectedSessionIds=os(this.selectedSessionIds,e.map(t=>t.id)),this.onDeleteArchivedMany?.(e))}archiveSelectedCurrent(){const e=this.selectedSessions("current").filter(t=>!ee(t));this.selectedSessionIds=os(this.selectedSessionIds,e.map(t=>t.id)),this.onArchiveMany?.(e)}toggleSelection(e,t){if(this.selectionScopes.has(e)){this.closeSelection(e);return}this.startSelection(e,t)}startSelection(e,t){this.selectionScopes=new Set([...this.selectionScopes,e]);const i=t.length===1?t[0]:void 0;i!==void 0&&(this.selectedSessionIds=new Set([...this.selectedSessionIds,i.id]))}closeSelection(e){this.selectionScopes=new Set([...this.selectionScopes].filter(t=>t!==e)),this.clearSelection(e)}clearSelection(e){const t=this.sessions.filter(i=>xt(i)===e).map(i=>i.id);this.selectedSessionIds=os(this.selectedSessionIds,t)}toggleSelected(e){const t=new Set(this.selectedSessionIds);t.has(e)?t.delete(e):t.add(e),this.selectedSessionIds=t}toggleVisibleSelection(e,t){const i=new Set(this.selectedSessionIds);for(const s of e)t?i.add(s.id):i.delete(s.id);this.selectedSessionIds=i}selectedSessions(e){return this.sessions.filter(t=>this.selectedSessionIds.has(t.id)&&xt(t)===e)}pruneSelectedSessionIds(){const e=new Set(this.sessions.map(i=>i.id)),t=new Set([...this.selectedSessionIds].filter(i=>e.has(i)));t.size!==this.selectedSessionIds.size&&(this.selectedSessionIds=t),this.selectionScopes.has("archived")&&!this.sessions.some(i=>i.archived===!0)&&this.closeSelection("archived"),this.selectionScopes.has("current")&&!this.sessions.some(i=>i.archived!==!0)&&this.closeSelection("current")}toggleMenu(e,t){if(this.openMenuSessionId===e){this.openMenuSessionId=void 0;return}this.menuStyle=Bt(t,{constrainTo:"viewport"}),this.openMenuSessionId=e}toggleArchived(){this.archivedExpanded=!this.archivedExpanded,this.archivedExpanded||(this.openMenuSessionId=void 0,this.selectionScopes.has("archived")&&this.closeSelection("archived"),this.onArchivedCollapsed?.())}scrollSelectedIntoView(){this.renderRoot.querySelector(".action-row.selected")?.scrollIntoView({block:"nearest"})}renderSessionMetaPrefix(e){return ee(e)?"新建 · ":e.archived===!0?"只读 · ":""}renderActivity(e){const t=Ig(e,this.statuses[e.id],this.activities[e.id],this.sending[e.id]===!0);return Oi(t,t==="sending"?"正在发送消息":"会话活跃")}};I.styles=[Fi,O`
|
|
802
|
+
h2 { min-height: 30px; }
|
|
803
|
+
h2 > .section-count { flex: 0 0 auto; display: inline; color: var(--pi-muted); font-size: inherit; }
|
|
804
|
+
.bulk-select-entry { box-sizing: border-box; flex: 0 0 auto; display: inline-grid; place-items: center; width: 30px; height: 30px; padding: 0; font-size: 13px; line-height: 1; text-transform: none; }
|
|
805
|
+
.bulk-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 0 0 6px; }
|
|
806
|
+
.bulk-row button { padding: 5px 7px; font-size: 12px; }
|
|
807
|
+
.bulk-row small { display: inline; min-width: 0; color: var(--pi-muted); }
|
|
808
|
+
.bulk-row .capability-hint { flex: 1 0 100%; color: var(--pi-warning); }
|
|
809
|
+
.bulk-row.selecting { padding: 6px; border: 1px solid var(--pi-border-muted); border-radius: 8px; background: color-mix(in srgb, var(--pi-surface) 65%, transparent); }
|
|
810
|
+
button.danger, .action-menu-panel button.danger { color: var(--pi-danger); }
|
|
811
|
+
button.danger:hover, .action-menu-panel button.danger:hover { background: color-mix(in srgb, var(--pi-danger) 14%, transparent); }
|
|
812
|
+
.action-row.bulk-selected .action-main { border-color: var(--pi-accent); box-shadow: inset 3px 0 0 var(--pi-accent); }
|
|
813
|
+
.action-main.selecting { padding-left: calc(32px + var(--depth, 0) * 16px); }
|
|
814
|
+
.session-checkbox { position: absolute; top: 9px; left: calc(8px + var(--depth, 0) * 16px); z-index: 2; margin: 0; }
|
|
815
|
+
`];T([d({attribute:!1})],I.prototype,"sessions",2);T([d({attribute:!1})],I.prototype,"statuses",2);T([d({attribute:!1})],I.prototype,"activities",2);T([d({attribute:!1})],I.prototype,"sending",2);T([d({attribute:!1})],I.prototype,"selected",2);T([d({type:Boolean})],I.prototype,"canStart",2);T([d({type:Boolean})],I.prototype,"canDeleteArchived",2);T([d({type:Boolean})],I.prototype,"canReload",2);T([d({type:String})],I.prototype,"archivedDeleteUnavailableMessage",2);T([d({type:Boolean,reflect:!0})],I.prototype,"collapsible",2);T([d({type:Boolean,reflect:!0})],I.prototype,"collapsed",2);T([d({attribute:!1})],I.prototype,"onSelect",2);T([d({attribute:!1})],I.prototype,"onStart",2);T([d({attribute:!1})],I.prototype,"onToggleCollapsed",2);T([d({attribute:!1})],I.prototype,"onArchivedCollapsed",2);T([d({attribute:!1})],I.prototype,"onFocusPreviousSection",2);T([d({attribute:!1})],I.prototype,"onFocusNextSection",2);T([d({attribute:!1})],I.prototype,"onCancelKeyboardNavigation",2);T([d({attribute:!1})],I.prototype,"onArchive",2);T([d({attribute:!1})],I.prototype,"onArchiveWithDescendants",2);T([d({attribute:!1})],I.prototype,"onArchiveMany",2);T([d({attribute:!1})],I.prototype,"onRestore",2);T([d({attribute:!1})],I.prototype,"onDelete",2);T([d({attribute:!1})],I.prototype,"onDeleteArchived",2);T([d({attribute:!1})],I.prototype,"onDeleteArchivedMany",2);T([d({attribute:!1})],I.prototype,"onDetachParent",2);T([d({attribute:!1})],I.prototype,"onReload",2);T([y()],I.prototype,"openMenuSessionId",2);T([y()],I.prototype,"menuStyle",2);T([y()],I.prototype,"archivedExpanded",2);T([y()],I.prototype,"selectionScopes",2);T([y()],I.prototype,"selectedSessionIds",2);I=T([D("session-list")],I);function xt(e){return e.archived===!0?"archived":"current"}function os(e,t){const i=new Set(t);return new Set([...e].filter(s=>!i.has(s)))}function Rg(e){const t=new Map;for(const s of e){if(s.parentSessionPath===void 0)continue;const o=t.get(s.parentSessionPath)??[];o.push(s),t.set(s.parentSessionPath,o)}const i=(s,o)=>{if(o.has(s.path))return 0;const r=new Set(o);r.add(s.path);let n=0;for(const a of t.get(s.path)??[])r.has(a.path)||(a.archived!==!0&&(n+=1),n+=i(a,r));return n};return new Map(e.map(s=>[s.id,i(s,new Set)]))}function Ig(e,t,i,s){if(!(ee(e)||e.archived===!0))return s?"sending":Qe(t,i)?"session":void 0}function Cg(e){const t=new Map(e.map(s=>[s.path,s])),i=new Set;for(const s of e){if(s.archived===!0)continue;i.add(s.id);let o=s.parentSessionPath;const r=new Set([s.path]);for(;o!==void 0&&!r.has(o);){r.add(o);const n=t.get(o);if(n===void 0)break;i.add(n.id),o=n.parentSessionPath}}return ya(e.filter(s=>i.has(s.id)))}function ya(e){const t=new Map(e.map(n=>[n.path,n])),i=new Map,s=[];for(const n of e){const a=n.parentSessionPath,l=a===void 0?void 0:t.get(a);if(l===void 0){s.push(n);continue}const p=i.get(l.path)??[];p.push(n),i.set(l.path,p)}const o=[],r=(n,a,l)=>{if(l.has(n.path))return;const p=n.parentSessionPath;o.push({session:n,depth:a,hasMissingParent:p!==void 0&&!t.has(p)});const u=new Set(l);u.add(n.path);for(const h of i.get(n.path)??[])r(h,a+1,u)};for(const n of s)r(n,0,new Set);return o}const co={CHILD:2,ELEMENT:6},lo=e=>(...t)=>({_$litDirective$:e,values:t});let po=class{constructor(t){}get _$AU(){return this._$AM._$AU}_$AT(t,i,s){this._$Ct=t,this._$AM=i,this._$Ci=s}_$AS(t,i){return this.update(t,i)}update(t,i){return this.render(...i)}};const{I:Tg}=kc,Tr=e=>e,Mr=()=>document.createComment(""),kt=(e,t,i)=>{const s=e._$AA.parentNode,o=t===void 0?e._$AB:t._$AA;if(i===void 0){const r=s.insertBefore(Mr(),o),n=s.insertBefore(Mr(),o);i=new Tg(r,n,e,e.options)}else{const r=i._$AB.nextSibling,n=i._$AM,a=n!==e;if(a){let l;i._$AQ?.(e),i._$AM=e,i._$AP!==void 0&&(l=e._$AU)!==n._$AU&&i._$AP(l)}if(r!==o||a){let l=i._$AA;for(;l!==r;){const p=Tr(l).nextSibling;Tr(s).insertBefore(l,o),l=p}}}return i},qe=(e,t,i=e)=>(e._$AI(t,i),e),Mg={},Ag=(e,t=Mg)=>e._$AH=t,Eg=e=>e._$AH,rs=e=>{e._$AR(),e._$AA.remove()};const Ar=(e,t,i)=>{const s=new Map;for(let o=t;o<=i;o++)s.set(e[o],o);return s},Dg=lo(class extends po{constructor(e){if(super(e),e.type!==co.CHILD)throw Error("repeat() can only be used in text expressions")}dt(e,t,i){let s;i===void 0?i=t:t!==void 0&&(s=t);const o=[],r=[];let n=0;for(const a of e)o[n]=s?s(a,n):n,r[n]=i(a,n),n++;return{values:r,keys:o}}render(e,t,i){return this.dt(e,t,i).values}update(e,[t,i,s]){const o=Eg(e),{values:r,keys:n}=this.dt(t,i,s);if(!Array.isArray(o))return this.ut=n,r;const a=this.ut??=[],l=[];let p,u,h=0,g=o.length-1,w=0,P=r.length-1;for(;h<=g&&w<=P;)if(o[h]===null)h++;else if(o[g]===null)g--;else if(a[h]===n[w])l[w]=qe(o[h],r[w]),h++,w++;else if(a[g]===n[P])l[P]=qe(o[g],r[P]),g--,P--;else if(a[h]===n[P])l[P]=qe(o[h],r[P]),kt(e,l[P+1],o[h]),h++,P--;else if(a[g]===n[w])l[w]=qe(o[g],r[w]),kt(e,o[h],o[g]),g--,w++;else if(p===void 0&&(p=Ar(n,w,P),u=Ar(a,h,g)),p.has(a[h]))if(p.has(a[g])){const H=u.get(n[w]),it=H!==void 0?o[H]:null;if(it===null){const ft=kt(e,o[h]);qe(ft,r[w]),l[w]=ft}else l[w]=qe(it,r[w]),kt(e,o[h],it),o[H]=null;w++}else rs(o[g]),g--;else rs(o[h]),h++;for(;w<=P;){const H=kt(e,l[P+1]);qe(H,r[w]),l[w++]=H}for(;h<=g;){const H=o[h++];H!==null&&rs(H)}return this.ut=n,Ag(e,l),Be}}),Wg="pi-web:chat-groups:",Og={read(e){try{if(typeof localStorage>"u")return;const t=localStorage.getItem(Er(e));return t===null||t===""?void 0:Lg(JSON.parse(t))}catch{return}},write(e,t){try{if(typeof localStorage>"u")return;localStorage.setItem(Er(e),JSON.stringify(t))}catch{}}};class _g{constructor(t=Og){this.storage=t,this.sessionId="",this.openGroupKeys=new Set,this.closedDefaultOpenGroupKeys=new Set}syncSession(t){if(this.sessionId===t)return;this.sessionId=t;const i=t===""?void 0:this.storage.read(t);this.openGroupKeys=new Set(i?.open??[]),this.closedDefaultOpenGroupKeys=new Set(i?.closedDefaultOpen??[])}isOpen(t,i){return i?!this.closedDefaultOpenGroupKeys.has(t):this.openGroupKeys.has(t)}applyToggle(t,i,s){const o=this.isOpen(t,s),r=new Set(this.openGroupKeys),n=new Set(this.closedDefaultOpenGroupKeys);return s?(r.delete(t),i?n.delete(t):n.add(t)):(n.delete(t),i?r.add(t):r.delete(t)),(s?!n.has(t):r.has(t))===o&&Dr(r,this.openGroupKeys)&&Dr(n,this.closedDefaultOpenGroupKeys)?!1:(this.openGroupKeys=r,this.closedDefaultOpenGroupKeys=n,this.persist(),!0)}snapshot(){return{open:[...this.openGroupKeys],closedDefaultOpen:[...this.closedDefaultOpenGroupKeys]}}persist(){this.sessionId!==""&&this.storage.write(this.sessionId,this.snapshot())}}function Er(e){return`${Wg}${e}`}function Lg(e){if(Array.isArray(e))return{open:ns(e),closedDefaultOpen:[]};if(jg(e))return{open:Array.isArray(e.open)?ns(e.open):[],closedDefaultOpen:Array.isArray(e.closedDefaultOpen)?ns(e.closedDefaultOpen):[]}}function ns(e){return e.filter(t=>typeof t=="string")}function Dr(e,t){if(e.size!==t.size)return!1;for(const i of e)if(!t.has(i))return!1;return!0}function jg(e){return typeof e=="object"&&e!==null}function Fg(e,t=0){const i=[];let s=[],o=0;const r=(a,l)=>{s.length||(o=l),s.push(a)},n=()=>{s.length&&(i.push({kind:"group",messages:s,startIndex:o,endIndex:o+s.length-1}),s=[])};return e.forEach((a,l)=>{const p=a.parts.filter(w=>Wr(a,w)),u=a.parts.filter(w=>!Wr(a,w)),h=t+l,g={...a.source===void 0?{}:{source:a.source},...a.meta===void 0?{}:{meta:a.meta}};if(u.length&&r({role:a.role,parts:u,...g},h),p.length){n();const w=p.every(P=>P.type==="skillRead")?"skill":a.role;i.push({kind:"message",message:{role:w,parts:p,...g},index:h})}}),n(),i}function Ng(e){if(e.every(s=>s.source==="compaction"))return`${String(e.length)} 条历史压缩摘要`;if(e.every(s=>s.source==="branch_summary"))return`${String(e.length)} 条分支摘要`;const t=e.reduce((s,o)=>(s[o.role]=(s[o.role]??0)+1,s),{}),i=Object.entries(t).map(([s,o])=>`${String(o)} ${zg(s)}`).join(" · ");return`${String(e.length)} 个事件${i!==""?` · ${i}`:""}`}function zg(e){return e==="user"?"用户":e==="assistant"?"助手":e==="system"?"系统":e==="tool"?"工具":e==="toolResult"?"工具结果":e==="bash"?"Shell":e==="skill"?"技能":e}function Wr(e,t){return e.source==="compaction"||e.source==="branch_summary"?!1:t.type==="skillInvocation"||t.type==="skillRead"?!0:t.type==="text"&&(e.role==="user"||e.role==="assistant"||e.role==="system"||e.role==="bash")}const Bg=30;function Ug(e,t){const i=qg(Gg(e,t)),s={distanceFromBottom:e.scrollHeight-e.scrollTop};return i===void 0?s:{...s,markerId:i.id,markerOffset:i.offset}}function Hg(e,t,i){if(i!==void 0&&t.markerOffset!==void 0){const s=i.getBoundingClientRect().top-e.getBoundingClientRect().top;e.scrollTop+=Kg(s,t.markerOffset);return}e.scrollTop=Vg(e.scrollHeight,t.distanceFromBottom)}function qg(e){let t,i=Number.NEGATIVE_INFINITY,s,o=Number.POSITIVE_INFINITY;for(const r of e)r.offset<=0&&r.offset>=i?(t=r,i=r.offset):r.offset>0&&r.offset<o&&(s=r,o=r.offset);return t??s}function Kg(e,t){return e-t}function Vg(e,t){return Math.max(0,e-t)}function Gg(e,t){const i=e.getBoundingClientRect().top;return t.flatMap(s=>{const o=s.dataset.markerId;return o===void 0?[]:[{id:o,offset:s.getBoundingClientRect().top-i}]})}const Jg=600,Qg=1;function Zg(e){return!e.hasMore||e.loadingMore||!e.canRequest||e.clientHeight<=0?!1:Xg(e)||Yg(e)}function Xg(e){return e.scrollTop<(e.topThreshold??Math.max(Jg,e.clientHeight))}function Yg(e){return e.scrollHeight<=e.clientHeight+Qg}const em="pi-web:chat-scroll:",tm=180,im=48,sm=2,om={getItem(e){return typeof localStorage>"u"?null:localStorage.getItem(e)},setItem(e,t){typeof localStorage>"u"||localStorage.setItem(e,t)},removeItem(e){typeof localStorage>"u"||localStorage.removeItem(e)}},rm={setTimeout(e,t){return window.setTimeout(e,t)},clearTimeout(e){window.clearTimeout(e)}};class nm{constructor(t=om,i=rm){this.storage=t,this.scheduler=i}dispose(){this.clearScheduledSave()}clearScheduledSave(){this.saveTimer!==void 0&&(this.scheduler.clearTimeout(this.saveTimer),this.saveTimer=void 0)}scheduleSave(t,i,s=tm){this.clearScheduledSave(),this.saveTimer=this.scheduler.setTimeout(()=>{this.saveTimer=void 0,i(t)},s)}savePosition(t,i,s,o=sm){if(t===""||i===void 0||!cs(i))return"skipped";try{if(xa(i,o)){const a={mode:"bottom"};return this.storage.setItem(as(t),JSON.stringify(a)),"saved"}const r=lm(i,s);if(r===void 0)return"skipped";const n=cm(i,r);return this.storage.setItem(as(t),JSON.stringify(n)),"saved"}catch{return"skipped"}}restorePosition(t,i,s,o){const r=this.readPosition(t);return r===void 0?this.scrollToBottom(i):this.restoreExplicitPosition(r,i,s,o)}restoreExplicitPosition(t,i,s,o){if(t.mode==="bottom")return this.scrollToBottom(i);if(i===void 0||!cs(i))return{status:"skipped"};const r=dm(s,t.anchorId);if(r===void 0)return o?.fallbackToBottom===!1?{status:"missing",position:t}:this.scrollToBottom(i);const n=i.getBoundingClientRect().top,a=r.getBoundingClientRect().top-n;return i.scrollTop+=a-t.offset,{status:"restored"}}readPosition(t){if(t!=="")try{const i=this.storage.getItem(as(t));if(i===null||i==="")return;const s=JSON.parse(i);return am(s)?s:void 0}catch{return}}scrollToBottom(t){return t===void 0||!cs(t)?{status:"skipped"}:(t.scrollTop=t.scrollHeight,{status:"bottom"})}}function as(e){return`${em}${e}`}function am(e){return typeof e!="object"||e===null||!("mode"in e)?!1:e.mode==="bottom"?!0:e.mode==="anchor"&&"anchorId"in e&&typeof e.anchorId=="string"&&e.anchorId!==""&&"offset"in e&&typeof e.offset=="number"}function cs(e){return e.clientHeight>0&&e.scrollHeight>0}function Sa(e){return e.scrollHeight-e.scrollTop-e.clientHeight}function xa(e,t=im){return Sa(e)<t}function cm(e,t){const i=e.getBoundingClientRect().top;return{mode:"anchor",anchorId:ho(t)??"",offset:t.getBoundingClientRect().top-i}}function lm(e,t){const i=e.getBoundingClientRect();let s,o=Number.NEGATIVE_INFINITY,r,n=Number.POSITIVE_INFINITY;for(const a of t){if(ho(a)===void 0)continue;const l=a.getBoundingClientRect();if(l.bottom<=l.top||l.bottom<i.top||l.top>i.bottom)continue;const p=l.top-i.top;p<=0&&p>=o?(s=a,o=p):p>0&&p<n&&(r=a,n=p)}return s??r}function Or(e,t){const i=e.getBoundingClientRect();return t.find(s=>{const o=s.getBoundingClientRect();return o.bottom>=i.top&&o.top<=i.bottom})}function dm(e,t){return e.find(i=>ho(i)===t)}function ho(e){return e.dataset.scrollAnchorId!==void 0&&e.dataset.scrollAnchorId!==""?e.dataset.scrollAnchorId:void 0}var pm=Object.defineProperty,hm=Object.getOwnPropertyDescriptor,uo=(e,t,i,s)=>{for(var o=s>1?void 0:s?hm(t,i):t,r=e.length-1,n;r>=0;r--)(n=e[r])&&(o=(s?n(t,i,o):n(o))||o);return s&&o&&pm(t,i,o),o};let Ot=class extends M{constructor(){super(...arguments),this.positionPercent=0,this.loadedPercent=100}render(){const e=_r(this.positionPercent),t=_r(this.loadedPercent),i=`消息位置:约在会话 ${String(Math.round(e))}% 处。已加载 ${String(Math.round(t))}% 的消息。`;return c`
|
|
816
|
+
<div
|
|
817
|
+
class="meter"
|
|
818
|
+
style=${`--position:${e.toFixed(2)}%;`}
|
|
819
|
+
role="meter"
|
|
820
|
+
aria-label=${i}
|
|
821
|
+
aria-valuemin="0"
|
|
822
|
+
aria-valuemax="100"
|
|
823
|
+
aria-valuenow=${String(Math.round(e))}
|
|
824
|
+
title=${i}
|
|
825
|
+
>
|
|
826
|
+
<div class="track" aria-hidden="true">
|
|
827
|
+
<div class="progress"></div>
|
|
828
|
+
<div class="marker"></div>
|
|
829
|
+
</div>
|
|
830
|
+
</div>
|
|
831
|
+
`}};Ot.styles=O`
|
|
832
|
+
:host { position: absolute; top: -4px; left: 16px; right: 16px; z-index: 6; display: block; height: 12px; opacity: .58; transition: opacity .15s ease; }
|
|
833
|
+
:host(:hover), :host(:focus-within) { opacity: .92; }
|
|
834
|
+
.meter { height: 100%; }
|
|
835
|
+
.track { position: relative; height: 4px; margin-top: 4px; border-radius: 999px; background: color-mix(in srgb, var(--pi-border-muted) 34%, transparent); box-shadow: 0 0 0 1px color-mix(in srgb, var(--pi-bg) 55%, transparent); }
|
|
836
|
+
.progress { position: absolute; left: 0; width: var(--position); top: 0; bottom: 0; border-radius: 999px; background: color-mix(in srgb, var(--pi-accent) 42%, var(--pi-border-muted)); }
|
|
837
|
+
.marker { position: absolute; left: var(--position); top: 50%; width: 10px; height: 10px; border: 2px solid var(--pi-bg); border-radius: 50%; background: var(--pi-accent); box-shadow: 0 2px 8px var(--pi-shadow); transform: translate(-50%, -50%); }
|
|
838
|
+
`;uo([d({type:Number})],Ot.prototype,"positionPercent",2);uo([d({type:Number})],Ot.prototype,"loadedPercent",2);Ot=uo([D("conversation-meter")],Ot);function _r(e){return Number.isFinite(e)?Math.min(100,Math.max(0,e)):0}class Es extends po{constructor(t){if(super(t),this.it=F,t.type!==co.CHILD)throw Error(this.constructor.directiveName+"() can only be used in child bindings")}render(t){if(t===F||t==null)return this._t=void 0,this.it=t;if(t===Be)return t;if(typeof t!="string")throw Error(this.constructor.directiveName+"() called with a non-string value");if(t===this.it)return this._t;this.it=t;const i=[t];return i.raw=i,this._t={_$litType$:this.constructor.resultType,strings:i,values:[]}}}Es.directiveName="unsafeHTML",Es.resultType=1;const um=lo(Es);function fo(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var Ye=fo();function ka(e){Ye=e}var Ke={exec:()=>null};function C(e,t=""){let i=typeof e=="string"?e:e.source,s={replace:(o,r)=>{let n=typeof r=="string"?r:r.source;return n=n.replace(Q.caret,"$1"),i=i.replace(o,n),s},getRegex:()=>new RegExp(i,t)};return s}var fm=((e="")=>{try{return!!new RegExp("(?<=1)(?<!1)"+e)}catch{return!1}})(),Q={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:e=>new RegExp(`^( {0,3}${e})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}#`),htmlBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}<(?:[a-z].*>|!--)`,"i"),blockquoteBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}>`)},gm=/^(?:[ \t]*(?:\n|$))+/,mm=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,vm=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,Ut=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,bm=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,go=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,$a=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,Pa=C($a).replace(/bull/g,go).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,"").getRegex(),wm=C($a).replace(/bull/g,go).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),mo=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,ym=/^[^\n]+/,vo=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,Sm=C(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",vo).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),xm=C(/^(bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,go).getRegex(),Ni="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",bo=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,km=C("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))","i").replace("comment",bo).replace("tag",Ni).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),Ra=C(mo).replace("hr",Ut).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Ni).getRegex(),$m=C(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",Ra).getRegex(),wo={blockquote:$m,code:mm,def:Sm,fences:vm,heading:bm,hr:Ut,html:km,lheading:Pa,list:xm,newline:gm,paragraph:Ra,table:Ke,text:ym},Lr=C("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",Ut).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3} )[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Ni).getRegex(),Pm={...wo,lheading:wm,table:Lr,paragraph:C(mo).replace("hr",Ut).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",Lr).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Ni).getRegex()},Rm={...wo,html:C(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",bo).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:Ke,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:C(mo).replace("hr",Ut).replace("heading",` *#{1,6} *[^
|
|
839
|
+
]`).replace("lheading",Pa).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},Im=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,Cm=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,Ia=/^( {2,}|\\)\n(?!\s*$)/,Tm=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,ut=/[\p{P}\p{S}]/u,zi=/[\s\p{P}\p{S}]/u,yo=/[^\s\p{P}\p{S}]/u,Mm=C(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,zi).getRegex(),Ca=/(?!~)[\p{P}\p{S}]/u,Am=/(?!~)[\s\p{P}\p{S}]/u,Em=/(?:[^\s\p{P}\p{S}]|~)/u,Dm=C(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",fm?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),Ta=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,Wm=C(Ta,"u").replace(/punct/g,ut).getRegex(),Om=C(Ta,"u").replace(/punct/g,Ca).getRegex(),Ma="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",_m=C(Ma,"gu").replace(/notPunctSpace/g,yo).replace(/punctSpace/g,zi).replace(/punct/g,ut).getRegex(),Lm=C(Ma,"gu").replace(/notPunctSpace/g,Em).replace(/punctSpace/g,Am).replace(/punct/g,Ca).getRegex(),jm=C("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,yo).replace(/punctSpace/g,zi).replace(/punct/g,ut).getRegex(),Fm=C(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,ut).getRegex(),Nm="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",zm=C(Nm,"gu").replace(/notPunctSpace/g,yo).replace(/punctSpace/g,zi).replace(/punct/g,ut).getRegex(),Bm=C(/\\(punct)/,"gu").replace(/punct/g,ut).getRegex(),Um=C(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),Hm=C(bo).replace("(?:-->|$)","-->").getRegex(),qm=C("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",Hm).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),ki=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/,Km=C(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label",ki).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),Aa=C(/^!?\[(label)\]\[(ref)\]/).replace("label",ki).replace("ref",vo).getRegex(),Ea=C(/^!?\[(ref)\](?:\[\])?/).replace("ref",vo).getRegex(),Vm=C("reflink|nolink(?!\\()","g").replace("reflink",Aa).replace("nolink",Ea).getRegex(),jr=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,So={_backpedal:Ke,anyPunctuation:Bm,autolink:Um,blockSkip:Dm,br:Ia,code:Cm,del:Ke,delLDelim:Ke,delRDelim:Ke,emStrongLDelim:Wm,emStrongRDelimAst:_m,emStrongRDelimUnd:jm,escape:Im,link:Km,nolink:Ea,punctuation:Mm,reflink:Aa,reflinkSearch:Vm,tag:qm,text:Tm,url:Ke},Gm={...So,link:C(/^!?\[(label)\]\((.*?)\)/).replace("label",ki).getRegex(),reflink:C(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",ki).getRegex()},Ds={...So,emStrongRDelimAst:Lm,emStrongLDelim:Om,delLDelim:Fm,delRDelim:zm,url:C(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",jr).replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,text:C(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol",jr).getRegex()},Jm={...Ds,br:C(Ia).replace("{2,}","*").getRegex(),text:C(Ds.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},Qt={normal:wo,gfm:Pm,pedantic:Rm},$t={normal:So,gfm:Ds,breaks:Jm,pedantic:Gm},Qm={"&":"&","<":"<",">":">",'"':""","'":"'"},Fr=e=>Qm[e];function Ae(e,t){if(t){if(Q.escapeTest.test(e))return e.replace(Q.escapeReplace,Fr)}else if(Q.escapeTestNoEncode.test(e))return e.replace(Q.escapeReplaceNoEncode,Fr);return e}function Nr(e){try{e=encodeURI(e).replace(Q.percentDecode,"%")}catch{return null}return e}function zr(e,t){let i=e.replace(Q.findPipe,(r,n,a)=>{let l=!1,p=n;for(;--p>=0&&a[p]==="\\";)l=!l;return l?"|":" |"}),s=i.split(Q.splitPipe),o=0;if(s[0].trim()||s.shift(),s.length>0&&!s.at(-1)?.trim()&&s.pop(),t)if(s.length>t)s.splice(t);else for(;s.length<t;)s.push("");for(;o<s.length;o++)s[o]=s[o].trim().replace(Q.slashPipe,"|");return s}function Ne(e,t,i){let s=e.length;if(s===0)return"";let o=0;for(;o<s&&e.charAt(s-o-1)===t;)o++;return e.slice(0,s-o)}function Br(e){let t=e.split(`
|
|
840
|
+
`),i=t.length-1;for(;i>=0&&Q.blankLine.test(t[i]);)i--;return t.length-i<=2?e:t.slice(0,i+1).join(`
|
|
841
|
+
`)}function Zm(e,t){if(e.indexOf(t[1])===-1)return-1;let i=0;for(let s=0;s<e.length;s++)if(e[s]==="\\")s++;else if(e[s]===t[0])i++;else if(e[s]===t[1]&&(i--,i<0))return s;return i>0?-2:-1}function Xm(e,t=0){let i=t,s="";for(let o of e)if(o===" "){let r=4-i%4;s+=" ".repeat(r),i+=r}else s+=o,i++;return s}function Ur(e,t,i,s,o){let r=t.href,n=t.title||null,a=e[1].replace(o.other.outputLinkReplace,"$1");s.state.inLink=!0;let l={type:e[0].charAt(0)==="!"?"image":"link",raw:i,href:r,title:n,text:a,tokens:s.inlineTokens(a)};return s.state.inLink=!1,l}function Ym(e,t,i){let s=e.match(i.other.indentCodeCompensation);if(s===null)return t;let o=s[1];return t.split(`
|
|
842
|
+
`).map(r=>{let n=r.match(i.other.beginningSpace);if(n===null)return r;let[a]=n;return a.length>=o.length?r.slice(o.length):r}).join(`
|
|
843
|
+
`)}var $i=class{options;rules;lexer;constructor(e){this.options=e||Ye}space(e){let t=this.rules.block.newline.exec(e);if(t&&t[0].length>0)return{type:"space",raw:t[0]}}code(e){let t=this.rules.block.code.exec(e);if(t){let i=this.options.pedantic?t[0]:Br(t[0]),s=i.replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:i,codeBlockStyle:"indented",text:s}}}fences(e){let t=this.rules.block.fences.exec(e);if(t){let i=t[0],s=Ym(i,t[3]||"",this.rules);return{type:"code",raw:i,lang:t[2]?t[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):t[2],text:s}}}heading(e){let t=this.rules.block.heading.exec(e);if(t){let i=t[2].trim();if(this.rules.other.endingHash.test(i)){let s=Ne(i,"#");(this.options.pedantic||!s||this.rules.other.endingSpaceChar.test(s))&&(i=s.trim())}return{type:"heading",raw:Ne(t[0],`
|
|
844
|
+
`),depth:t[1].length,text:i,tokens:this.lexer.inline(i)}}}hr(e){let t=this.rules.block.hr.exec(e);if(t)return{type:"hr",raw:Ne(t[0],`
|
|
845
|
+
`)}}blockquote(e){let t=this.rules.block.blockquote.exec(e);if(t){let i=Ne(t[0],`
|
|
846
|
+
`).split(`
|
|
847
|
+
`),s="",o="",r=[];for(;i.length>0;){let n=!1,a=[],l;for(l=0;l<i.length;l++)if(this.rules.other.blockquoteStart.test(i[l]))a.push(i[l]),n=!0;else if(!n)a.push(i[l]);else break;i=i.slice(l);let p=a.join(`
|
|
848
|
+
`),u=p.replace(this.rules.other.blockquoteSetextReplace,`
|
|
849
|
+
$1`).replace(this.rules.other.blockquoteSetextReplace2,"");s=s?`${s}
|
|
850
|
+
${p}`:p,o=o?`${o}
|
|
851
|
+
${u}`:u;let h=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(u,r,!0),this.lexer.state.top=h,i.length===0)break;let g=r.at(-1);if(g?.type==="code")break;if(g?.type==="blockquote"){let w=g,P=w.raw+`
|
|
852
|
+
`+i.join(`
|
|
853
|
+
`),H=this.blockquote(P);r[r.length-1]=H,s=s.substring(0,s.length-w.raw.length)+H.raw,o=o.substring(0,o.length-w.text.length)+H.text;break}else if(g?.type==="list"){let w=g,P=w.raw+`
|
|
854
|
+
`+i.join(`
|
|
855
|
+
`),H=this.list(P);r[r.length-1]=H,s=s.substring(0,s.length-g.raw.length)+H.raw,o=o.substring(0,o.length-w.raw.length)+H.raw,i=P.substring(r.at(-1).raw.length).split(`
|
|
856
|
+
`);continue}}return{type:"blockquote",raw:s,tokens:r,text:o}}}list(e){let t=this.rules.block.list.exec(e);if(t){let i=t[1].trim(),s=i.length>1,o={type:"list",raw:"",ordered:s,start:s?+i.slice(0,-1):"",loose:!1,items:[]};i=s?`\\d{1,9}\\${i.slice(-1)}`:`\\${i}`,this.options.pedantic&&(i=s?i:"[*+-]");let r=this.rules.other.listItemRegex(i),n=!1;for(;e;){let l=!1,p="",u="";if(!(t=r.exec(e))||this.rules.block.hr.test(e))break;p=t[0],e=e.substring(p.length);let h=Xm(t[2].split(`
|
|
857
|
+
`,1)[0],t[1].length),g=e.split(`
|
|
858
|
+
`,1)[0],w=!h.trim(),P=0;if(this.options.pedantic?(P=2,u=h.trimStart()):w?P=t[1].length+1:(P=h.search(this.rules.other.nonSpaceChar),P=P>4?1:P,u=h.slice(P),P+=t[1].length),w&&this.rules.other.blankLine.test(g)&&(p+=g+`
|
|
859
|
+
`,e=e.substring(g.length+1),l=!0),!l){let H=this.rules.other.nextBulletRegex(P),it=this.rules.other.hrRegex(P),ft=this.rules.other.fencesBeginRegex(P),$o=this.rules.other.headingBeginRegex(P),Ha=this.rules.other.htmlBeginRegex(P),qa=this.rules.other.blockquoteBeginRegex(P);for(;e;){let Ui=e.split(`
|
|
860
|
+
`,1)[0],gt;if(g=Ui,this.options.pedantic?(g=g.replace(this.rules.other.listReplaceNesting," "),gt=g):gt=g.replace(this.rules.other.tabCharGlobal," "),ft.test(g)||$o.test(g)||Ha.test(g)||qa.test(g)||H.test(g)||it.test(g))break;if(gt.search(this.rules.other.nonSpaceChar)>=P||!g.trim())u+=`
|
|
861
|
+
`+gt.slice(P);else{if(w||h.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||ft.test(h)||$o.test(h)||it.test(h))break;u+=`
|
|
862
|
+
`+g}w=!g.trim(),p+=Ui+`
|
|
863
|
+
`,e=e.substring(Ui.length+1),h=gt.slice(P)}}o.loose||(n?o.loose=!0:this.rules.other.doubleBlankLine.test(p)&&(n=!0)),o.items.push({type:"list_item",raw:p,task:!!this.options.gfm&&this.rules.other.listIsTask.test(u),loose:!1,text:u,tokens:[]}),o.raw+=p}let a=o.items.at(-1);if(a)a.raw=a.raw.trimEnd(),a.text=a.text.trimEnd();else return;o.raw=o.raw.trimEnd();for(let l of o.items){this.lexer.state.top=!1,l.tokens=this.lexer.blockTokens(l.text,[]);let p=l.tokens[0];if(l.task&&(p?.type==="text"||p?.type==="paragraph")){l.text=l.text.replace(this.rules.other.listReplaceTask,""),p.raw=p.raw.replace(this.rules.other.listReplaceTask,""),p.text=p.text.replace(this.rules.other.listReplaceTask,"");for(let h=this.lexer.inlineQueue.length-1;h>=0;h--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[h].src)){this.lexer.inlineQueue[h].src=this.lexer.inlineQueue[h].src.replace(this.rules.other.listReplaceTask,"");break}let u=this.rules.other.listTaskCheckbox.exec(l.raw);if(u){let h={type:"checkbox",raw:u[0]+" ",checked:u[0]!=="[ ]"};l.checked=h.checked,o.loose?l.tokens[0]&&["paragraph","text"].includes(l.tokens[0].type)&&"tokens"in l.tokens[0]&&l.tokens[0].tokens?(l.tokens[0].raw=h.raw+l.tokens[0].raw,l.tokens[0].text=h.raw+l.tokens[0].text,l.tokens[0].tokens.unshift(h)):l.tokens.unshift({type:"paragraph",raw:h.raw,text:h.raw,tokens:[h]}):l.tokens.unshift(h)}}else l.task&&(l.task=!1);if(!o.loose){let u=l.tokens.filter(g=>g.type==="space"),h=u.length>0&&u.some(g=>this.rules.other.anyLine.test(g.raw));o.loose=h}}if(o.loose)for(let l of o.items){l.loose=!0;for(let p of l.tokens)p.type==="text"&&(p.type="paragraph")}return o}}html(e){let t=this.rules.block.html.exec(e);if(t){let i=Br(t[0]);return{type:"html",block:!0,raw:i,pre:t[1]==="pre"||t[1]==="script"||t[1]==="style",text:i}}}def(e){let t=this.rules.block.def.exec(e);if(t){let i=t[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),s=t[2]?t[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",o=t[3]?t[3].substring(1,t[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):t[3];return{type:"def",tag:i,raw:Ne(t[0],`
|
|
864
|
+
`),href:s,title:o}}}table(e){let t=this.rules.block.table.exec(e);if(!t||!this.rules.other.tableDelimiter.test(t[2]))return;let i=zr(t[1]),s=t[2].replace(this.rules.other.tableAlignChars,"").split("|"),o=t[3]?.trim()?t[3].replace(this.rules.other.tableRowBlankLine,"").split(`
|
|
865
|
+
`):[],r={type:"table",raw:Ne(t[0],`
|
|
866
|
+
`),header:[],align:[],rows:[]};if(i.length===s.length){for(let n of s)this.rules.other.tableAlignRight.test(n)?r.align.push("right"):this.rules.other.tableAlignCenter.test(n)?r.align.push("center"):this.rules.other.tableAlignLeft.test(n)?r.align.push("left"):r.align.push(null);for(let n=0;n<i.length;n++)r.header.push({text:i[n],tokens:this.lexer.inline(i[n]),header:!0,align:r.align[n]});for(let n of o)r.rows.push(zr(n,r.header.length).map((a,l)=>({text:a,tokens:this.lexer.inline(a),header:!1,align:r.align[l]})));return r}}lheading(e){let t=this.rules.block.lheading.exec(e);if(t){let i=t[1].trim();return{type:"heading",raw:Ne(t[0],`
|
|
867
|
+
`),depth:t[2].charAt(0)==="="?1:2,text:i,tokens:this.lexer.inline(i)}}}paragraph(e){let t=this.rules.block.paragraph.exec(e);if(t){let i=t[1].charAt(t[1].length-1)===`
|
|
868
|
+
`?t[1].slice(0,-1):t[1];return{type:"paragraph",raw:t[0],text:i,tokens:this.lexer.inline(i)}}}text(e){let t=this.rules.block.text.exec(e);if(t)return{type:"text",raw:t[0],text:t[0],tokens:this.lexer.inline(t[0])}}escape(e){let t=this.rules.inline.escape.exec(e);if(t)return{type:"escape",raw:t[0],text:t[1]}}tag(e){let t=this.rules.inline.tag.exec(e);if(t)return!this.lexer.state.inLink&&this.rules.other.startATag.test(t[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(t[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(t[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(t[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:t[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:t[0]}}link(e){let t=this.rules.inline.link.exec(e);if(t){let i=t[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(i)){if(!this.rules.other.endAngleBracket.test(i))return;let r=Ne(i.slice(0,-1),"\\");if((i.length-r.length)%2===0)return}else{let r=Zm(t[2],"()");if(r===-2)return;if(r>-1){let n=(t[0].indexOf("!")===0?5:4)+t[1].length+r;t[2]=t[2].substring(0,r),t[0]=t[0].substring(0,n).trim(),t[3]=""}}let s=t[2],o="";if(this.options.pedantic){let r=this.rules.other.pedanticHrefTitle.exec(s);r&&(s=r[1],o=r[3])}else o=t[3]?t[3].slice(1,-1):"";return s=s.trim(),this.rules.other.startAngleBracket.test(s)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(i)?s=s.slice(1):s=s.slice(1,-1)),Ur(t,{href:s&&s.replace(this.rules.inline.anyPunctuation,"$1"),title:o&&o.replace(this.rules.inline.anyPunctuation,"$1")},t[0],this.lexer,this.rules)}}reflink(e,t){let i;if((i=this.rules.inline.reflink.exec(e))||(i=this.rules.inline.nolink.exec(e))){let s=(i[2]||i[1]).replace(this.rules.other.multipleSpaceGlobal," "),o=t[s.toLowerCase()];if(!o){let r=i[0].charAt(0);return{type:"text",raw:r,text:r}}return Ur(i,o,i[0],this.lexer,this.rules)}}emStrong(e,t,i=""){let s=this.rules.inline.emStrongLDelim.exec(e);if(!(!s||!s[1]&&!s[2]&&!s[3]&&!s[4]||s[4]&&i.match(this.rules.other.unicodeAlphaNumeric))&&(!(s[1]||s[3])||!i||this.rules.inline.punctuation.exec(i))){let o=[...s[0]].length-1,r,n,a=o,l=0,p=s[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(p.lastIndex=0,t=t.slice(-1*e.length+o);(s=p.exec(t))!==null;){if(r=s[1]||s[2]||s[3]||s[4]||s[5]||s[6],!r)continue;if(n=[...r].length,s[3]||s[4]){a+=n;continue}else if((s[5]||s[6])&&o%3&&!((o+n)%3)){l+=n;continue}if(a-=n,a>0)continue;n=Math.min(n,n+a+l);let u=[...s[0]][0].length,h=e.slice(0,o+s.index+u+n);if(Math.min(o,n)%2){let w=h.slice(1,-1);return{type:"em",raw:h,text:w,tokens:this.lexer.inlineTokens(w)}}let g=h.slice(2,-2);return{type:"strong",raw:h,text:g,tokens:this.lexer.inlineTokens(g)}}}}codespan(e){let t=this.rules.inline.code.exec(e);if(t){let i=t[2].replace(this.rules.other.newLineCharGlobal," "),s=this.rules.other.nonSpaceChar.test(i),o=this.rules.other.startingSpaceChar.test(i)&&this.rules.other.endingSpaceChar.test(i);return s&&o&&(i=i.substring(1,i.length-1)),{type:"codespan",raw:t[0],text:i}}}br(e){let t=this.rules.inline.br.exec(e);if(t)return{type:"br",raw:t[0]}}del(e,t,i=""){let s=this.rules.inline.delLDelim.exec(e);if(s&&(!s[1]||!i||this.rules.inline.punctuation.exec(i))){let o=[...s[0]].length-1,r,n,a=o,l=this.rules.inline.delRDelim;for(l.lastIndex=0,t=t.slice(-1*e.length+o);(s=l.exec(t))!==null;){if(r=s[1]||s[2]||s[3]||s[4]||s[5]||s[6],!r||(n=[...r].length,n!==o))continue;if(s[3]||s[4]){a+=n;continue}if(a-=n,a>0)continue;n=Math.min(n,n+a);let p=[...s[0]][0].length,u=e.slice(0,o+s.index+p+n),h=u.slice(o,-o);return{type:"del",raw:u,text:h,tokens:this.lexer.inlineTokens(h)}}}}autolink(e){let t=this.rules.inline.autolink.exec(e);if(t){let i,s;return t[2]==="@"?(i=t[1],s="mailto:"+i):(i=t[1],s=i),{type:"link",raw:t[0],text:i,href:s,tokens:[{type:"text",raw:i,text:i}]}}}url(e){let t;if(t=this.rules.inline.url.exec(e)){let i,s;if(t[2]==="@")i=t[0],s="mailto:"+i;else{let o;do o=t[0],t[0]=this.rules.inline._backpedal.exec(t[0])?.[0]??"";while(o!==t[0]);i=t[0],t[1]==="www."?s="http://"+t[0]:s=t[0]}return{type:"link",raw:t[0],text:i,href:s,tokens:[{type:"text",raw:i,text:i}]}}}inlineText(e){let t=this.rules.inline.text.exec(e);if(t){let i=this.lexer.state.inRawBlock;return{type:"text",raw:t[0],text:t[0],escaped:i}}}},ke=class Ws{tokens;options;state;inlineQueue;tokenizer;constructor(t){this.tokens=[],this.tokens.links=Object.create(null),this.options=t||Ye,this.options.tokenizer=this.options.tokenizer||new $i,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};let i={other:Q,block:Qt.normal,inline:$t.normal};this.options.pedantic?(i.block=Qt.pedantic,i.inline=$t.pedantic):this.options.gfm&&(i.block=Qt.gfm,this.options.breaks?i.inline=$t.breaks:i.inline=$t.gfm),this.tokenizer.rules=i}static get rules(){return{block:Qt,inline:$t}}static lex(t,i){return new Ws(i).lex(t)}static lexInline(t,i){return new Ws(i).inlineTokens(t)}lex(t){t=t.replace(Q.carriageReturn,`
|
|
869
|
+
`),this.blockTokens(t,this.tokens);for(let i=0;i<this.inlineQueue.length;i++){let s=this.inlineQueue[i];this.inlineTokens(s.src,s.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(t,i=[],s=!1){this.tokenizer.lexer=this,this.options.pedantic&&(t=t.replace(Q.tabCharGlobal," ").replace(Q.spaceLine,""));let o=1/0;for(;t;){if(t.length<o)o=t.length;else{this.infiniteLoopError(t.charCodeAt(0));break}let r;if(this.options.extensions?.block?.some(a=>(r=a.call({lexer:this},t,i))?(t=t.substring(r.raw.length),i.push(r),!0):!1))continue;if(r=this.tokenizer.space(t)){t=t.substring(r.raw.length);let a=i.at(-1);r.raw.length===1&&a!==void 0?a.raw+=`
|
|
870
|
+
`:i.push(r);continue}if(r=this.tokenizer.code(t)){t=t.substring(r.raw.length);let a=i.at(-1);a?.type==="paragraph"||a?.type==="text"?(a.raw+=(a.raw.endsWith(`
|
|
871
|
+
`)?"":`
|
|
872
|
+
`)+r.raw,a.text+=`
|
|
873
|
+
`+r.text,this.inlineQueue.at(-1).src=a.text):i.push(r);continue}if(r=this.tokenizer.fences(t)){t=t.substring(r.raw.length),i.push(r);continue}if(r=this.tokenizer.heading(t)){t=t.substring(r.raw.length),i.push(r);continue}if(r=this.tokenizer.hr(t)){t=t.substring(r.raw.length),i.push(r);continue}if(r=this.tokenizer.blockquote(t)){t=t.substring(r.raw.length),i.push(r);continue}if(r=this.tokenizer.list(t)){t=t.substring(r.raw.length),i.push(r);continue}if(r=this.tokenizer.html(t)){t=t.substring(r.raw.length),i.push(r);continue}if(r=this.tokenizer.def(t)){t=t.substring(r.raw.length);let a=i.at(-1);a?.type==="paragraph"||a?.type==="text"?(a.raw+=(a.raw.endsWith(`
|
|
874
|
+
`)?"":`
|
|
875
|
+
`)+r.raw,a.text+=`
|
|
876
|
+
`+r.raw,this.inlineQueue.at(-1).src=a.text):this.tokens.links[r.tag]||(this.tokens.links[r.tag]={href:r.href,title:r.title},i.push(r));continue}if(r=this.tokenizer.table(t)){t=t.substring(r.raw.length),i.push(r);continue}if(r=this.tokenizer.lheading(t)){t=t.substring(r.raw.length),i.push(r);continue}let n=t;if(this.options.extensions?.startBlock){let a=1/0,l=t.slice(1),p;this.options.extensions.startBlock.forEach(u=>{p=u.call({lexer:this},l),typeof p=="number"&&p>=0&&(a=Math.min(a,p))}),a<1/0&&a>=0&&(n=t.substring(0,a+1))}if(this.state.top&&(r=this.tokenizer.paragraph(n))){let a=i.at(-1);s&&a?.type==="paragraph"?(a.raw+=(a.raw.endsWith(`
|
|
877
|
+
`)?"":`
|
|
878
|
+
`)+r.raw,a.text+=`
|
|
879
|
+
`+r.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=a.text):i.push(r),s=n.length!==t.length,t=t.substring(r.raw.length);continue}if(r=this.tokenizer.text(t)){t=t.substring(r.raw.length);let a=i.at(-1);a?.type==="text"?(a.raw+=(a.raw.endsWith(`
|
|
880
|
+
`)?"":`
|
|
881
|
+
`)+r.raw,a.text+=`
|
|
882
|
+
`+r.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=a.text):i.push(r);continue}if(t){this.infiniteLoopError(t.charCodeAt(0));break}}return this.state.top=!0,i}inline(t,i=[]){return this.inlineQueue.push({src:t,tokens:i}),i}inlineTokens(t,i=[]){this.tokenizer.lexer=this;let s=t,o=null;if(this.tokens.links){let p=Object.keys(this.tokens.links);if(p.length>0)for(;(o=this.tokenizer.rules.inline.reflinkSearch.exec(s))!==null;)p.includes(o[0].slice(o[0].lastIndexOf("[")+1,-1))&&(s=s.slice(0,o.index)+"["+"a".repeat(o[0].length-2)+"]"+s.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(o=this.tokenizer.rules.inline.anyPunctuation.exec(s))!==null;)s=s.slice(0,o.index)+"++"+s.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);let r;for(;(o=this.tokenizer.rules.inline.blockSkip.exec(s))!==null;)r=o[2]?o[2].length:0,s=s.slice(0,o.index+r)+"["+"a".repeat(o[0].length-r-2)+"]"+s.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);s=this.options.hooks?.emStrongMask?.call({lexer:this},s)??s;let n=!1,a="",l=1/0;for(;t;){if(t.length<l)l=t.length;else{this.infiniteLoopError(t.charCodeAt(0));break}n||(a=""),n=!1;let p;if(this.options.extensions?.inline?.some(h=>(p=h.call({lexer:this},t,i))?(t=t.substring(p.raw.length),i.push(p),!0):!1))continue;if(p=this.tokenizer.escape(t)){t=t.substring(p.raw.length),i.push(p);continue}if(p=this.tokenizer.tag(t)){t=t.substring(p.raw.length),i.push(p);continue}if(p=this.tokenizer.link(t)){t=t.substring(p.raw.length),i.push(p);continue}if(p=this.tokenizer.reflink(t,this.tokens.links)){t=t.substring(p.raw.length);let h=i.at(-1);p.type==="text"&&h?.type==="text"?(h.raw+=p.raw,h.text+=p.text):i.push(p);continue}if(p=this.tokenizer.emStrong(t,s,a)){t=t.substring(p.raw.length),i.push(p);continue}if(p=this.tokenizer.codespan(t)){t=t.substring(p.raw.length),i.push(p);continue}if(p=this.tokenizer.br(t)){t=t.substring(p.raw.length),i.push(p);continue}if(p=this.tokenizer.del(t,s,a)){t=t.substring(p.raw.length),i.push(p);continue}if(p=this.tokenizer.autolink(t)){t=t.substring(p.raw.length),i.push(p);continue}if(!this.state.inLink&&(p=this.tokenizer.url(t))){t=t.substring(p.raw.length),i.push(p);continue}let u=t;if(this.options.extensions?.startInline){let h=1/0,g=t.slice(1),w;this.options.extensions.startInline.forEach(P=>{w=P.call({lexer:this},g),typeof w=="number"&&w>=0&&(h=Math.min(h,w))}),h<1/0&&h>=0&&(u=t.substring(0,h+1))}if(p=this.tokenizer.inlineText(u)){t=t.substring(p.raw.length),p.raw.slice(-1)!=="_"&&(a=p.raw.slice(-1)),n=!0;let h=i.at(-1);h?.type==="text"?(h.raw+=p.raw,h.text+=p.text):i.push(p);continue}if(t){this.infiniteLoopError(t.charCodeAt(0));break}}return i}infiniteLoopError(t){let i="Infinite loop on byte: "+t;if(this.options.silent)console.error(i);else throw new Error(i)}},Pi=class{options;parser;constructor(e){this.options=e||Ye}space(e){return""}code({text:e,lang:t,escaped:i}){let s=(t||"").match(Q.notSpaceStart)?.[0],o=e.replace(Q.endingNewline,"")+`
|
|
883
|
+
`;return s?'<pre><code class="language-'+Ae(s)+'">'+(i?o:Ae(o,!0))+`</code></pre>
|
|
884
|
+
`:"<pre><code>"+(i?o:Ae(o,!0))+`</code></pre>
|
|
885
|
+
`}blockquote({tokens:e}){return`<blockquote>
|
|
886
|
+
${this.parser.parse(e)}</blockquote>
|
|
887
|
+
`}html({text:e}){return e}def(e){return""}heading({tokens:e,depth:t}){return`<h${t}>${this.parser.parseInline(e)}</h${t}>
|
|
888
|
+
`}hr(e){return`<hr>
|
|
889
|
+
`}list(e){let t=e.ordered,i=e.start,s="";for(let n=0;n<e.items.length;n++){let a=e.items[n];s+=this.listitem(a)}let o=t?"ol":"ul",r=t&&i!==1?' start="'+i+'"':"";return"<"+o+r+`>
|
|
890
|
+
`+s+"</"+o+`>
|
|
891
|
+
`}listitem(e){return`<li>${this.parser.parse(e.tokens)}</li>
|
|
892
|
+
`}checkbox({checked:e}){return"<input "+(e?'checked="" ':"")+'disabled="" type="checkbox"> '}paragraph({tokens:e}){return`<p>${this.parser.parseInline(e)}</p>
|
|
893
|
+
`}table(e){let t="",i="";for(let o=0;o<e.header.length;o++)i+=this.tablecell(e.header[o]);t+=this.tablerow({text:i});let s="";for(let o=0;o<e.rows.length;o++){let r=e.rows[o];i="";for(let n=0;n<r.length;n++)i+=this.tablecell(r[n]);s+=this.tablerow({text:i})}return s&&(s=`<tbody>${s}</tbody>`),`<table>
|
|
894
|
+
<thead>
|
|
895
|
+
`+t+`</thead>
|
|
896
|
+
`+s+`</table>
|
|
897
|
+
`}tablerow({text:e}){return`<tr>
|
|
898
|
+
${e}</tr>
|
|
899
|
+
`}tablecell(e){let t=this.parser.parseInline(e.tokens),i=e.header?"th":"td";return(e.align?`<${i} align="${e.align}">`:`<${i}>`)+t+`</${i}>
|
|
900
|
+
`}strong({tokens:e}){return`<strong>${this.parser.parseInline(e)}</strong>`}em({tokens:e}){return`<em>${this.parser.parseInline(e)}</em>`}codespan({text:e}){return`<code>${Ae(e,!0)}</code>`}br(e){return"<br>"}del({tokens:e}){return`<del>${this.parser.parseInline(e)}</del>`}link({href:e,title:t,tokens:i}){let s=this.parser.parseInline(i),o=Nr(e);if(o===null)return s;e=o;let r='<a href="'+e+'"';return t&&(r+=' title="'+Ae(t)+'"'),r+=">"+s+"</a>",r}image({href:e,title:t,text:i,tokens:s}){s&&(i=this.parser.parseInline(s,this.parser.textRenderer));let o=Nr(e);if(o===null)return Ae(i);e=o;let r=`<img src="${e}" alt="${Ae(i)}"`;return t&&(r+=` title="${Ae(t)}"`),r+=">",r}text(e){return"tokens"in e&&e.tokens?this.parser.parseInline(e.tokens):"escaped"in e&&e.escaped?e.text:Ae(e.text)}},xo=class{strong({text:e}){return e}em({text:e}){return e}codespan({text:e}){return e}del({text:e}){return e}html({text:e}){return e}text({text:e}){return e}link({text:e}){return""+e}image({text:e}){return""+e}br(){return""}checkbox({raw:e}){return e}},$e=class Os{options;renderer;textRenderer;constructor(t){this.options=t||Ye,this.options.renderer=this.options.renderer||new Pi,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new xo}static parse(t,i){return new Os(i).parse(t)}static parseInline(t,i){return new Os(i).parseInline(t)}parse(t){this.renderer.parser=this;let i="";for(let s=0;s<t.length;s++){let o=t[s];if(this.options.extensions?.renderers?.[o.type]){let n=o,a=this.options.extensions.renderers[n.type].call({parser:this},n);if(a!==!1||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(n.type)){i+=a||"";continue}}let r=o;switch(r.type){case"space":{i+=this.renderer.space(r);break}case"hr":{i+=this.renderer.hr(r);break}case"heading":{i+=this.renderer.heading(r);break}case"code":{i+=this.renderer.code(r);break}case"table":{i+=this.renderer.table(r);break}case"blockquote":{i+=this.renderer.blockquote(r);break}case"list":{i+=this.renderer.list(r);break}case"checkbox":{i+=this.renderer.checkbox(r);break}case"html":{i+=this.renderer.html(r);break}case"def":{i+=this.renderer.def(r);break}case"paragraph":{i+=this.renderer.paragraph(r);break}case"text":{i+=this.renderer.text(r);break}default:{let n='Token with "'+r.type+'" type was not found.';if(this.options.silent)return console.error(n),"";throw new Error(n)}}}return i}parseInline(t,i=this.renderer){this.renderer.parser=this;let s="";for(let o=0;o<t.length;o++){let r=t[o];if(this.options.extensions?.renderers?.[r.type]){let a=this.options.extensions.renderers[r.type].call({parser:this},r);if(a!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(r.type)){s+=a||"";continue}}let n=r;switch(n.type){case"escape":{s+=i.text(n);break}case"html":{s+=i.html(n);break}case"link":{s+=i.link(n);break}case"image":{s+=i.image(n);break}case"checkbox":{s+=i.checkbox(n);break}case"strong":{s+=i.strong(n);break}case"em":{s+=i.em(n);break}case"codespan":{s+=i.codespan(n);break}case"br":{s+=i.br(n);break}case"del":{s+=i.del(n);break}case"text":{s+=i.text(n);break}default:{let a='Token with "'+n.type+'" type was not found.';if(this.options.silent)return console.error(a),"";throw new Error(a)}}}return s}},Rt=class{options;block;constructor(e){this.options=e||Ye}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(e){return e}postprocess(e){return e}processAllTokens(e){return e}emStrongMask(e){return e}provideLexer(e=this.block){return e?ke.lex:ke.lexInline}provideParser(e=this.block){return e?$e.parse:$e.parseInline}},ev=class{defaults=fo();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=$e;Renderer=Pi;TextRenderer=xo;Lexer=ke;Tokenizer=$i;Hooks=Rt;constructor(...e){this.use(...e)}walkTokens(e,t){let i=[];for(let s of e)switch(i=i.concat(t.call(this,s)),s.type){case"table":{let o=s;for(let r of o.header)i=i.concat(this.walkTokens(r.tokens,t));for(let r of o.rows)for(let n of r)i=i.concat(this.walkTokens(n.tokens,t));break}case"list":{let o=s;i=i.concat(this.walkTokens(o.items,t));break}default:{let o=s;this.defaults.extensions?.childTokens?.[o.type]?this.defaults.extensions.childTokens[o.type].forEach(r=>{let n=o[r].flat(1/0);i=i.concat(this.walkTokens(n,t))}):o.tokens&&(i=i.concat(this.walkTokens(o.tokens,t)))}}return i}use(...e){let t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach(i=>{let s={...i};if(s.async=this.defaults.async||s.async||!1,i.extensions&&(i.extensions.forEach(o=>{if(!o.name)throw new Error("extension name required");if("renderer"in o){let r=t.renderers[o.name];r?t.renderers[o.name]=function(...n){let a=o.renderer.apply(this,n);return a===!1&&(a=r.apply(this,n)),a}:t.renderers[o.name]=o.renderer}if("tokenizer"in o){if(!o.level||o.level!=="block"&&o.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");let r=t[o.level];r?r.unshift(o.tokenizer):t[o.level]=[o.tokenizer],o.start&&(o.level==="block"?t.startBlock?t.startBlock.push(o.start):t.startBlock=[o.start]:o.level==="inline"&&(t.startInline?t.startInline.push(o.start):t.startInline=[o.start]))}"childTokens"in o&&o.childTokens&&(t.childTokens[o.name]=o.childTokens)}),s.extensions=t),i.renderer){let o=this.defaults.renderer||new Pi(this.defaults);for(let r in i.renderer){if(!(r in o))throw new Error(`renderer '${r}' does not exist`);if(["options","parser"].includes(r))continue;let n=r,a=i.renderer[n],l=o[n];o[n]=(...p)=>{let u=a.apply(o,p);return u===!1&&(u=l.apply(o,p)),u||""}}s.renderer=o}if(i.tokenizer){let o=this.defaults.tokenizer||new $i(this.defaults);for(let r in i.tokenizer){if(!(r in o))throw new Error(`tokenizer '${r}' does not exist`);if(["options","rules","lexer"].includes(r))continue;let n=r,a=i.tokenizer[n],l=o[n];o[n]=(...p)=>{let u=a.apply(o,p);return u===!1&&(u=l.apply(o,p)),u}}s.tokenizer=o}if(i.hooks){let o=this.defaults.hooks||new Rt;for(let r in i.hooks){if(!(r in o))throw new Error(`hook '${r}' does not exist`);if(["options","block"].includes(r))continue;let n=r,a=i.hooks[n],l=o[n];Rt.passThroughHooks.has(r)?o[n]=p=>{if(this.defaults.async&&Rt.passThroughHooksRespectAsync.has(r))return(async()=>{let h=await a.call(o,p);return l.call(o,h)})();let u=a.call(o,p);return l.call(o,u)}:o[n]=(...p)=>{if(this.defaults.async)return(async()=>{let h=await a.apply(o,p);return h===!1&&(h=await l.apply(o,p)),h})();let u=a.apply(o,p);return u===!1&&(u=l.apply(o,p)),u}}s.hooks=o}if(i.walkTokens){let o=this.defaults.walkTokens,r=i.walkTokens;s.walkTokens=function(n){let a=[];return a.push(r.call(this,n)),o&&(a=a.concat(o.call(this,n))),a}}this.defaults={...this.defaults,...s}}),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return ke.lex(e,t??this.defaults)}parser(e,t){return $e.parse(e,t??this.defaults)}parseMarkdown(e){return(t,i)=>{let s={...i},o={...this.defaults,...s},r=this.onError(!!o.silent,!!o.async);if(this.defaults.async===!0&&s.async===!1)return r(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof t>"u"||t===null)return r(new Error("marked(): input parameter is undefined or null"));if(typeof t!="string")return r(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(t)+", string expected"));if(o.hooks&&(o.hooks.options=o,o.hooks.block=e),o.async)return(async()=>{let n=o.hooks?await o.hooks.preprocess(t):t,a=await(o.hooks?await o.hooks.provideLexer(e):e?ke.lex:ke.lexInline)(n,o),l=o.hooks?await o.hooks.processAllTokens(a):a;o.walkTokens&&await Promise.all(this.walkTokens(l,o.walkTokens));let p=await(o.hooks?await o.hooks.provideParser(e):e?$e.parse:$e.parseInline)(l,o);return o.hooks?await o.hooks.postprocess(p):p})().catch(r);try{o.hooks&&(t=o.hooks.preprocess(t));let n=(o.hooks?o.hooks.provideLexer(e):e?ke.lex:ke.lexInline)(t,o);o.hooks&&(n=o.hooks.processAllTokens(n)),o.walkTokens&&this.walkTokens(n,o.walkTokens);let a=(o.hooks?o.hooks.provideParser(e):e?$e.parse:$e.parseInline)(n,o);return o.hooks&&(a=o.hooks.postprocess(a)),a}catch(n){return r(n)}}}onError(e,t){return i=>{if(i.message+=`
|
|
901
|
+
Please report this to https://github.com/markedjs/marked.`,e){let s="<p>An error occurred:</p><pre>"+Ae(i.message+"",!0)+"</pre>";return t?Promise.resolve(s):s}if(t)return Promise.reject(i);throw i}}},Ze=new ev;function A(e,t){return Ze.parse(e,t)}A.options=A.setOptions=function(e){return Ze.setOptions(e),A.defaults=Ze.defaults,ka(A.defaults),A};A.getDefaults=fo;A.defaults=Ye;A.use=function(...e){return Ze.use(...e),A.defaults=Ze.defaults,ka(A.defaults),A};A.walkTokens=function(e,t){return Ze.walkTokens(e,t)};A.parseInline=Ze.parseInline;A.Parser=$e;A.parser=$e.parse;A.Renderer=Pi;A.TextRenderer=xo;A.Lexer=ke;A.lexer=ke.lex;A.Tokenizer=$i;A.Hooks=Rt;A.parse=A;A.options;A.setOptions;A.use;A.walkTokens;A.parseInline;$e.parse;ke.lex;const Da=new A.Renderer;Da.html=({text:e})=>sv(e);const tv=300,Pt=new Map;function iv(e){const t=Pt.get(e);if(t!==void 0)return t;const i=A.parse(e,{async:!1,breaks:!0,gfm:!0,renderer:Da}),s=ov(i);if(Pt.set(e,s),Pt.size>tv){const o=Pt.keys().next().value;o!==void 0&&Pt.delete(o)}return s}function sv(e){return e.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">")}function ov(e){const t=document.createElement("template");return t.innerHTML=e,t.content.querySelectorAll("script, style, iframe, object, embed").forEach(i=>{i.remove()}),t.content.querySelectorAll("*").forEach(i=>{for(const s of[...i.attributes]){const o=s.name.toLowerCase();o.startsWith("on")&&i.removeAttribute(s.name),(o==="href"||o==="src")&&!rv(s.value)&&i.removeAttribute(s.name)}i.tagName==="A"&&(i.setAttribute("target","_blank"),i.setAttribute("rel","noreferrer noopener"))}),t.innerHTML}function rv(e){if(e.startsWith("#")||e.startsWith("/"))return!0;try{return["http:","https:","mailto:"].includes(new URL(e).protocol)}catch{return!1}}var nv=Object.defineProperty,av=Object.getOwnPropertyDescriptor,Wa=(e,t,i,s)=>{for(var o=s>1?void 0:s?av(t,i):t,r=e.length-1,n;r>=0;r--)(n=e[r])&&(o=(s?n(t,i,o):n(o))||o);return s&&o&&nv(t,i,o),o};let Ri=class extends M{constructor(){super(...arguments),this.text="",this.onFormattedClick=e=>{if(!(e.target instanceof Element))return;const t=e.target.closest(".code-copy-button");if(!(t instanceof HTMLButtonElement))return;const i=t.closest(".code-block-wrapper");if(!(i instanceof HTMLElement))return;const s=i.querySelector("pre code");s instanceof HTMLElement&&this.copyCode(s.textContent,t)}}render(){return c`<div class="formatted" @click=${this.onFormattedClick}>${um(iv(this.text))}</div>`}updated(){this.enhanceCodeBlocks()}enhanceCodeBlocks(){this.renderRoot.querySelectorAll("pre").forEach(e=>{if(!(e instanceof HTMLPreElement)||e.parentElement?.classList.contains("code-block-wrapper")===!0||!(e.querySelector("code")instanceof HTMLElement))return;const i=document.createElement("div");i.className="code-block-wrapper";const s=document.createElement("button");s.type="button",s.className="code-copy-button",s.title="复制代码块",s.setAttribute("aria-label","复制代码块");const o=document.createElement("span");o.setAttribute("aria-hidden","true"),o.textContent="⧉",s.append(o),e.before(i),i.append(e,s)})}async copyCode(e,t){const i=await cv(e);this.setCopyButtonState(t,i?"copied":"failed"),window.setTimeout(()=>{this.setCopyButtonState(t,"idle")},1200)}setCopyButtonState(e,t){const i=e.querySelector("span");i!==null&&(i.textContent=t==="copied"?"✓":"⧉");const s=t==="copied"?"已复制代码块":t==="failed"?"复制代码块失败":"复制代码块";e.title=s,e.setAttribute("aria-label",s)}};Ri.styles=ag;Wa([d()],Ri.prototype,"text",2);Ri=Wa([D("formatted-text")],Ri);async function cv(e){try{return await navigator.clipboard.writeText(e),!0}catch{return!1}}var lv=Object.defineProperty,dv=Object.getOwnPropertyDescriptor,Ht=(e,t,i,s)=>{for(var o=s>1?void 0:s?dv(t,i):t,r=e.length-1,n;r>=0;r--)(n=e[r])&&(o=(s?n(t,i,o):n(o))||o);return s&&o&&lv(t,i,o),o};const Hr=180;let Xe=class extends M{constructor(){super(...arguments),this.showFullDiff=!1,this.copied=!1,this.diffOpen=!0}render(){const e=this.execution;if(e===void 0)return null;const t=e.toolName==="edit",i=pv(e.args),s=hv(e.details),o=e.preview,r=s??o?.diff,n=r===void 0?void 0:uv(r),a=s!==void 0&&o?.diff!==void 0&&s!==o.diff,l=e.status==="error"?e.resultText:o?.error,p=r===void 0?e.resultText:void 0;return c`
|
|
902
|
+
<section class=${`tool-card ${e.status}`}>
|
|
903
|
+
<div class="tool-header">
|
|
904
|
+
<div class="tool-title">
|
|
905
|
+
<span class="status-icon" aria-hidden="true">${gv(e.status)}</span>
|
|
906
|
+
<strong>${e.toolName}</strong>
|
|
907
|
+
${i===void 0?c`<span class="summary">${e.summary}</span>`:c`<span class="path">${i}</span>`}
|
|
908
|
+
</div>
|
|
909
|
+
<div class="tool-meta">
|
|
910
|
+
${qr(e)===void 0?null:c`<span>${qr(e)}</span>`}
|
|
911
|
+
${n===void 0?null:c`<span class="diff-stats"><b class="added">+${n.added}</b><span>/</span><b class="removed">-${n.removed}</b></span>`}
|
|
912
|
+
<span class="status-label">${mv(e.status)}</span>
|
|
913
|
+
</div>
|
|
914
|
+
</div>
|
|
915
|
+
|
|
916
|
+
${a?c`<p class="notice">实际应用的 diff 与预览不同。</p>`:null}
|
|
917
|
+
${l===void 0||l===""?null:c`<pre class="error-text">${l}</pre>`}
|
|
918
|
+
${r===void 0?this.renderTextBody(p,e.status==="error"):this.renderDiffBody(r,s===void 0?"预览 diff":"已应用 diff")}
|
|
919
|
+
${!t&&r===void 0&&(p===void 0||p==="")?c`<p class="muted">${e.summary}</p>`:null}
|
|
920
|
+
</section>
|
|
921
|
+
`}renderTextBody(e,t){return e===void 0||e===""?null:c`
|
|
922
|
+
<details class="text-body" ?open=${t}>
|
|
923
|
+
<summary>结果</summary>
|
|
924
|
+
<pre>${e}</pre>
|
|
925
|
+
</details>
|
|
926
|
+
`}renderDiffBody(e,t){const i=e.split(`
|
|
927
|
+
`),s=!this.showFullDiff&&i.length>Hr,o=s?i.slice(0,Hr):i;return c`
|
|
928
|
+
<details class="diff-details" ?open=${this.diffOpen} @toggle=${r=>{this.onDiffToggle(r)}}>
|
|
929
|
+
<summary>
|
|
930
|
+
<span>${t}</span>
|
|
931
|
+
<small>${String(i.length)} 行</small>
|
|
932
|
+
</summary>
|
|
933
|
+
<div class="diff-toolbar">
|
|
934
|
+
<span>${s?`显示 ${String(o.length)} / ${String(i.length)} 行`:"完整 diff"}</span>
|
|
935
|
+
<button type="button" @click=${()=>{this.copyDiff(e)}}>${this.copied?"已复制":"复制 diff"}</button>
|
|
936
|
+
</div>
|
|
937
|
+
<pre class="diff" aria-label=${t}><code class="diff-content">${o.map(r=>c`<span class=${fv(r)}>${r}</span>`)}</code></pre>
|
|
938
|
+
${s?c`
|
|
939
|
+
<button class="show-more" type="button" @click=${()=>{this.showFullDiff=!0}}>
|
|
940
|
+
显示全部 ${String(i.length)} 行 diff
|
|
941
|
+
</button>
|
|
942
|
+
`:null}
|
|
943
|
+
</details>
|
|
944
|
+
`}onDiffToggle(e){const t=e.currentTarget;t instanceof HTMLDetailsElement&&(this.diffOpen=t.open)}async copyDiff(e){try{await navigator.clipboard.writeText(e),this.copied=!0,window.setTimeout(()=>{this.copied=!1},1200)}catch{this.copied=!1}}};Xe.styles=O`
|
|
945
|
+
:host { display: block; width: 100%; max-width: 100%; min-width: 0; color: var(--pi-text); }
|
|
946
|
+
.tool-card { display: grid; gap: 8px; width: 100%; max-width: 100%; min-width: 0; box-sizing: border-box; overflow: hidden; border: 1px solid var(--pi-border); border-radius: 8px; background: var(--pi-bg); padding: 9px; color: var(--pi-text); }
|
|
947
|
+
.tool-card.running, .tool-card.pending { border-color: var(--pi-warning-border); background: var(--pi-warning-surface); }
|
|
948
|
+
.tool-card.success { border-color: var(--pi-success-border); background: var(--pi-success-bg); }
|
|
949
|
+
.tool-card.error { border-color: var(--pi-danger); background: color-mix(in srgb, var(--pi-danger) 10%, var(--pi-bg)); }
|
|
950
|
+
.tool-header { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; min-width: 0; }
|
|
951
|
+
.tool-title { display: inline-flex; align-items: baseline; gap: 7px; min-width: 0; }
|
|
952
|
+
.status-icon { flex: 0 0 auto; color: var(--pi-muted); }
|
|
953
|
+
strong { color: var(--pi-text); }
|
|
954
|
+
.path, .summary { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--pi-accent); font: 13px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
|
|
955
|
+
.summary { color: var(--pi-muted); font-family: inherit; }
|
|
956
|
+
.tool-meta { flex: 0 0 auto; display: inline-flex; align-items: baseline; gap: 8px; color: var(--pi-muted); font-size: 12px; }
|
|
957
|
+
.diff-stats { display: inline-flex; gap: 3px; }
|
|
958
|
+
.added, .diff .added { color: var(--pi-success); }
|
|
959
|
+
.removed, .diff .removed { color: var(--pi-danger); }
|
|
960
|
+
.status-label { text-transform: uppercase; letter-spacing: .04em; color: var(--pi-muted); }
|
|
961
|
+
.notice { margin: 0; color: var(--pi-warning); }
|
|
962
|
+
.muted { margin: 0; color: var(--pi-muted); }
|
|
963
|
+
.error-text { margin: 0; border: 1px solid var(--pi-danger); border-radius: 7px; background: color-mix(in srgb, var(--pi-danger) 10%, var(--pi-bg)); color: var(--pi-danger); padding: 8px; white-space: pre-wrap; overflow-wrap: anywhere; font: 12px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
|
|
964
|
+
.text-body { border-top: 1px solid var(--pi-border-muted); padding-top: 6px; }
|
|
965
|
+
.text-body pre { margin: 6px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; font: 12px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; color: var(--pi-text); }
|
|
966
|
+
.diff-details { min-width: 0; max-width: 100%; border-top: 1px solid var(--pi-border-muted); padding-top: 6px; }
|
|
967
|
+
.diff-details > summary { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; min-width: 0; color: var(--pi-muted); cursor: pointer; }
|
|
968
|
+
.diff-details > summary span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
969
|
+
.diff-details > summary small { flex: 0 0 auto; color: var(--pi-dim); }
|
|
970
|
+
.diff-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; margin-top: 8px; color: var(--pi-muted); font-size: 12px; }
|
|
971
|
+
.diff-toolbar span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
972
|
+
button { border: 1px solid var(--pi-border); border-radius: 6px; background: var(--pi-surface); color: var(--pi-text); padding: 3px 7px; font: 12px system-ui, sans-serif; cursor: pointer; }
|
|
973
|
+
button:hover, button:focus { border-color: var(--pi-accent); }
|
|
974
|
+
.diff { box-sizing: border-box; width: 100%; max-width: 100%; min-width: 0; margin: 0; overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain; border: 1px solid var(--pi-border-muted); border-radius: 7px; background: var(--pi-bg); padding: 8px 0; color: var(--pi-muted); font: 12px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; line-height: 1.45; }
|
|
975
|
+
.diff-content { display: block; width: max-content; min-width: 100%; }
|
|
976
|
+
.diff span { display: block; min-height: 1.45em; padding: 0 8px; white-space: pre; }
|
|
977
|
+
.diff .context { color: var(--pi-muted); }
|
|
978
|
+
.diff .hunk { color: var(--pi-accent); }
|
|
979
|
+
.diff .file { color: var(--pi-dim); }
|
|
980
|
+
.diff .meta { color: var(--pi-dim); }
|
|
981
|
+
.diff .added { background: color-mix(in srgb, var(--pi-success) 12%, transparent); }
|
|
982
|
+
.diff .removed { background: color-mix(in srgb, var(--pi-danger) 12%, transparent); }
|
|
983
|
+
.show-more { justify-self: start; }
|
|
984
|
+
`;Ht([d({attribute:!1})],Xe.prototype,"execution",2);Ht([y()],Xe.prototype,"showFullDiff",2);Ht([y()],Xe.prototype,"copied",2);Ht([y()],Xe.prototype,"diffOpen",2);Xe=Ht([D("tool-execution-view")],Xe);function pv(e){return _s(e,"path")??_s(e,"file_path")}function qr(e){if(e.toolName!=="edit")return;const t=ai(e.args,"edits");if(Array.isArray(t))return`${String(t.length)} 处编辑`;if(typeof ai(e.args,"oldText")=="string"&&typeof ai(e.args,"newText")=="string")return"1 处编辑"}function hv(e){return _s(e,"diff")}function uv(e){let t=0,i=0;for(const s of e.split(`
|
|
985
|
+
`))Oa(s)?t++:_a(s)&&i++;return{added:t,removed:i}}function fv(e){return Oa(e)?"added":_a(e)?"removed":e.startsWith("@@")?"hunk":e.startsWith("+++")||e.startsWith("---")?"file":e.startsWith("diff ")||e.startsWith("index ")?"meta":"context"}function Oa(e){return e.startsWith("+")&&!e.startsWith("+++")}function _a(e){return e.startsWith("-")&&!e.startsWith("---")}function gv(e){return e==="success"?"✓":e==="error"?"✖":e==="running"?"●":"○"}function mv(e){return e==="success"?"完成":e==="error"?"失败":e==="running"?"运行中":"等待中"}function vv(e){return typeof e=="object"&&e!==null}function ai(e,t){return vv(e)?e[t]:void 0}function _s(e,t){const i=ai(e,t);return typeof i=="string"?i:void 0}var bv=Object.defineProperty,wv=Object.getOwnPropertyDescriptor,U=(e,t,i,s)=>{for(var o=s>1?void 0:s?wv(t,i):t,r=e.length-1,n;r>=0;r--)(n=e[r])&&(o=(s?n(t,i,o):n(o))||o);return s&&o&&bv(t,i,o),o};const yv=new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}),Sv=new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"medium"}),ls=["你打开此会话时助手已经在回复。完整答案很快会显示。","当前标签页接入得稍晚,完整回复准备好后会显示。","助手已先开始回复,完整答案到达后会显示。","正在等待完整回复,避免显示不完整内容。","回复仍在生成中,完整答案即将显示。","正在同步这次回复,稍后会显示完整版本。"],xv={active:"活跃","agent running":"助手运行中","bash complete":"Shell 已完成","bash failed":"Shell 失败","compaction complete":"压缩已完成","compaction failed":"压缩失败",compacting:"正在压缩","duplicate queued message ignored":"已忽略重复排队消息",error:"错误",idle:"空闲","message complete":"消息已完成","message queued":"消息已排队","message queued during compaction":"压缩期间消息已排队","message started":"消息已开始","prompt accepted":"提示已接受",queued:"已排队","receiving response":"正在接收回复","running bash":"Shell 运行中","running tool":"工具运行中","steering queued":"引导已排队",stopped:"已停止","tool complete":"工具已完成","tool failed":"工具失败","turn complete":"回合已完成"};function Kr(){return ls[Math.floor(Math.random()*ls.length)]??ls[0]}function Vr(e){return ci(e,0,100)}function ci(e,t,i){return Number.isFinite(e)?Math.min(i,Math.max(t,e)):t}let L=class extends M{constructor(){super(...arguments),this.messages=[],this.sessionId="",this.messageStart=0,this.messageEnd=0,this.messageTotal=0,this.hasMore=!1,this.loadingMore=!1,this.isReceivingPartialStream=!1,this.isSendingPrompt=!1,this.isCompacting=!1,this.pendingMessageCount=0,this.pinnedToBottom=!0,this.disclosures=new _g,this.scrollController=new nm,this.suppressScrollSave=!1,this.suppressLoadMoreRequests=!1,this.groupedMessagesStart=0,this.groupedMessagesCache=[],this.messageMetaCache=new WeakMap,this.messageCopyTextCache=new WeakMap,this.lastScrollTop=0,this.lastClientHeight=0,this.prependRestoreToken=0,this.loadMoreRequested=!1,this.onViewportResize=()=>{this.pinnedToBottom?this.scrollToBottom():this.lastClientHeight=this.chat?.clientHeight??0},this.onPageHide=()=>{this.saveScrollPosition()}}connectedCallback(){super.connectedCallback(),window.addEventListener("resize",this.onViewportResize),window.addEventListener("pagehide",this.onPageHide),window.visualViewport?.addEventListener("resize",this.onViewportResize)}firstUpdated(){this.lastClientHeight=this.chat?.clientHeight??0}disconnectedCallback(){this.saveScrollPosition(),this.scrollController.dispose(),this.prependRestoreToken+=1,this.restoreScrollFrame!==void 0&&cancelAnimationFrame(this.restoreScrollFrame),this.loadMoreCheckFrame!==void 0&&cancelAnimationFrame(this.loadMoreCheckFrame),this.scrollToBottomFrame!==void 0&&cancelAnimationFrame(this.scrollToBottomFrame),this.conversationRailFrame!==void 0&&cancelAnimationFrame(this.conversationRailFrame),window.removeEventListener("resize",this.onViewportResize),window.removeEventListener("pagehide",this.onPageHide),window.visualViewport?.removeEventListener("resize",this.onViewportResize),super.disconnectedCallback()}savePreviousSessionScrollPosition(e){typeof e!="string"||e===""||e===this.sessionId||this.saveScrollPosition(e)}prepareSessionUiState(){this.disclosures.syncSession(this.sessionId),this.scrollController.clearScheduledSave(),this.suppressScrollSave=!1,this.suppressLoadMoreRequests=!1,this.pendingScrollRestoreSessionId=void 0,this.pendingScrollRestorePosition=void 0,this.prependRestoreToken+=1,this.restoreScrollFrame!==void 0&&(cancelAnimationFrame(this.restoreScrollFrame),this.restoreScrollFrame=void 0)}willUpdate(e){e.has("sessionId")&&(this.savePreviousSessionScrollPosition(e.get("sessionId")),this.prepareSessionUiState()),(e.has("isReceivingPartialStream")||e.has("sessionId")&&this.isReceivingPartialStream)&&this.syncPartialStreamNoticeBody(),e.has("messages")&&(this.pinnedToBottom=this.pinnedToBottom&&(this.didChatHeightChange()||this.isNearBottom()))}update(e){const t=this.isPrependingMessages(e)?this.capturePrependScrollAnchor():void 0;super.update(e),t!==void 0&&this.restorePrependScrollAnchor(t)}updated(e){e.has("loadingMore")&&!this.loadingMore&&(this.loadMoreRequested=!1),e.has("hasMore")&&!this.hasMore&&(this.loadMoreRequested=!1),e.has("sessionId")&&this.restoreScrollPosition(),!e.has("sessionId")&&e.has("messages")&&this.pinnedToBottom&&this.scrollToBottom(),(e.has("messages")||e.has("messageStart")||e.has("messageTotal")||e.has("hasMore")||e.has("loadingMore"))&&this.scheduleConversationRailUpdate(),(e.has("messages")||e.has("messageStart")||e.has("hasMore")||e.has("loadingMore"))&&this.continuePendingScrollRestore(),(e.has("messages")||e.has("hasMore")||e.has("loadingMore"))&&this.requestLoadMoreIfNeeded()}render(){const e=this.groupedMessages();return c`
|
|
986
|
+
<div class="chat-wrap">
|
|
987
|
+
${this.renderConversationRail()}
|
|
988
|
+
<div class="chat" @scroll=${()=>{this.onScroll()}} @wheel=${t=>{this.onWheel(t)}} @touchstart=${t=>{this.onTouchStart(t)}} @touchmove=${t=>{this.onTouchMove(t)}}>
|
|
989
|
+
${this.renderHistoryBoundary()}
|
|
990
|
+
${Dg(e,t=>t.kind==="message"?this.messageAnchorKey(t.index):this.groupRenderKey(t.startIndex),(t,i)=>t.kind==="message"?this.renderMessage(t.message,t.index):this.renderMessageGroup(t.messages,t.startIndex,t.endIndex,this.isLiveTailGroup(e,i)))}
|
|
991
|
+
${this.renderQueuedMessages()}
|
|
992
|
+
${this.renderSessionActivity()}
|
|
993
|
+
</div>
|
|
994
|
+
${this.renderActivityDock()}
|
|
995
|
+
</div>
|
|
996
|
+
`}groupedMessages(){return this.groupedMessagesInput===this.messages&&this.groupedMessagesStart===this.messageStart?this.groupedMessagesCache:(this.groupedMessagesInput=this.messages,this.groupedMessagesStart=this.messageStart,this.groupedMessagesCache=Fg(this.messages,this.messageStart),this.groupedMessagesCache)}isLiveTailGroup(e,t){return t===e.length-1&&this.isSessionLive()}isSessionLive(){return this.isSendingPrompt||this.status?.isStreaming===!0||this.status?.isCompacting===!0||this.status?.isBashRunning===!0||this.activity?.phase==="active"}renderActivityDock(){if(this.isSendingPrompt)return c`
|
|
997
|
+
<div class="activity-dock active" aria-live="polite">
|
|
998
|
+
<span class="dot"></span>
|
|
999
|
+
<span class="activity-text">Sending your message…</span>
|
|
1000
|
+
</div>
|
|
1001
|
+
`;const e=this.activityState();if(e===void 0)return null;const t=e!=="idle"||this.activity?.phase==="active";return c`
|
|
1002
|
+
<div class=${t?"activity-dock active":"activity-dock"} aria-live="polite">
|
|
1003
|
+
<span class="dot"></span>
|
|
1004
|
+
<span class="activity-text">${this.activityText(e)}</span>
|
|
1005
|
+
</div>
|
|
1006
|
+
`}renderQueuedMessages(){const e=this.status?.queuedMessages??[];return e.length===0?null:c`
|
|
1007
|
+
<aside class="queued-messages" aria-live="polite">
|
|
1008
|
+
<div class="queued-header">
|
|
1009
|
+
<strong>排队消息</strong>
|
|
1010
|
+
<small>${e.length} 条待处理 · 停止会清空队列</small>
|
|
1011
|
+
</div>
|
|
1012
|
+
${e.map((t,i)=>c`
|
|
1013
|
+
<div class="queued-message">
|
|
1014
|
+
<span class="queued-kind">${t.kind==="steer"?"引导":"跟进"} ${String(i+1)}</span>
|
|
1015
|
+
${t.imageCount!==void 0&&t.imageCount>0?c`<small>含 ${t.imageCount} 张图片</small>`:null}
|
|
1016
|
+
<formatted-text .text=${t.text}></formatted-text>
|
|
1017
|
+
</div>
|
|
1018
|
+
`)}
|
|
1019
|
+
</aside>
|
|
1020
|
+
`}renderSessionActivity(){return this.isReceivingPartialStream?c`
|
|
1021
|
+
<aside class="session-activity receiving" aria-live="polite">
|
|
1022
|
+
<strong>正在同步…</strong>
|
|
1023
|
+
<span>${this.currentPartialStreamNoticeBody()}</span>
|
|
1024
|
+
</aside>
|
|
1025
|
+
`:this.isCompacting?c`
|
|
1026
|
+
<aside class="session-activity compacting" aria-live="polite">
|
|
1027
|
+
<strong>正在压缩历史…</strong>
|
|
1028
|
+
<span>助手正在总结早前上下文。压缩完成前,新提示会排队等待。</span>
|
|
1029
|
+
${this.pendingMessageCount>0?c`<small>${this.pendingMessageCount} 条消息已排队</small>`:null}
|
|
1030
|
+
</aside>
|
|
1031
|
+
`:null}syncPartialStreamNoticeBody(){this.partialStreamNoticeBody=this.isReceivingPartialStream?Kr():void 0}currentPartialStreamNoticeBody(){return this.partialStreamNoticeBody??=Kr(),this.partialStreamNoticeBody}activityState(){const e=this.status;return e===void 0?this.activity?.label:e.isCompacting?"compacting":e.isBashRunning?"bash":e.isStreaming?"running":e.pendingMessageCount>0?"queued":"idle"}activityText(e){const t=this.activity;if(t===void 0||e!=="idle"&&t.phase==="idle")return ds(e);const i=ds(t.label);return t.detail!==void 0&&t.detail!==""?`${i}: ${t.detail}`:i}renderConversationRail(){if(!this.messages.length||this.messageTotal<=0)return null;const e=this.conversationDisplayTotal(),t=this.conversationPositionPercent(e),i=this.hasMore?Vr(this.messages.length/e*100):100;return c`<conversation-meter .positionPercent=${t} .loadedPercent=${i}></conversation-meter>`}conversationDisplayTotal(){return!this.hasMore&&this.messageStart===0?Math.max(1,this.messages.length):Math.max(1,this.messageTotal,this.messageStart+this.messages.length)}conversationPositionPercent(e=this.conversationDisplayTotal()){if(e<=1)return 100;const t=this.pinnedToBottom?this.messageStart+this.messages.length-1:this.messageStart,i=ci(this.currentConversationIndex??t,0,e-1);return Vr(i/(e-1)*100)}renderHistoryBoundary(){const e=this.historyRangeLabel();return this.loadingMore?c`<div class="history-boundary"><span>正在加载更早的消息…</span>${e}</div>`:this.hasMore?c`
|
|
1032
|
+
<div class="history-boundary">
|
|
1033
|
+
<button type="button" class="history-load-button" ?disabled=${this.loadMoreRequested} @click=${()=>{this.requestLoadMore()}}>加载更早的消息</button>
|
|
1034
|
+
<span>向上滚动加载更早的消息</span>
|
|
1035
|
+
${e}
|
|
1036
|
+
</div>
|
|
1037
|
+
`:this.messages.length?c`<div class="history-boundary"><span>会话开始</span>${e}</div>`:null}historyRangeLabel(){if(!this.messages.length||this.messageTotal<=0)return null;const e=this.messageStart+1,t=this.loadedRawMessageEnd(),i=Math.max(this.messageTotal,t);return c`<small>显示消息 ${e}–${t} / ${i}</small>`}loadedRawMessageEnd(){return Math.max(this.messageEnd,this.messageStart+this.messages.length)}renderMessage(e,t){const i=this.isToolExecutionOnlyMessage(e);return c`
|
|
1038
|
+
${this.renderScrollMarker(this.messageScrollMarkerId(t))}
|
|
1039
|
+
<article class=${i?"msg tool-execution-shell":`msg ${e.role}`} data-index=${t} data-scroll-anchor-id=${this.messageAnchorKey(t)}>
|
|
1040
|
+
${i?null:this.renderMessageHeader(e,String(t))}
|
|
1041
|
+
${e.parts.map(s=>this.renderPart(s,e))}
|
|
1042
|
+
</article>
|
|
1043
|
+
`}isToolExecutionOnlyMessage(e){return e.role==="tool"&&e.parts.length>0&&e.parts.every(t=>t.type==="toolExecution")}renderMessageGroup(e,t,i,s){const o=this.groupDisclosureKey(t,i,s),r=this.disclosures.isOpen(o,s);return c`
|
|
1044
|
+
${this.renderScrollMarker(this.groupScrollMarkerId(i))}
|
|
1045
|
+
<details class=${s?"msg event-group live":"msg event-group"} data-index=${t} data-scroll-anchor-id=${this.groupAnchorKey(t)} ?open=${r} @toggle=${n=>{this.onGroupToggle(o,n,s)}}>
|
|
1046
|
+
<summary>
|
|
1047
|
+
<b class="label">${s?"实时事件":"事件"}</b>
|
|
1048
|
+
<span>${Ng(e)}</span>
|
|
1049
|
+
</summary>
|
|
1050
|
+
<div class="group-body">
|
|
1051
|
+
${e.map((n,a)=>{const l=this.isToolExecutionOnlyMessage(n);return c`
|
|
1052
|
+
<section class=${l?"group-msg tool-execution-shell":`group-msg ${n.role}`} data-index=${t+a} data-scroll-anchor-id=${this.eventAnchorKey(t+a)}>
|
|
1053
|
+
${l?null:this.renderMessageHeader(n,`${String(t)}:${String(a)}`)}
|
|
1054
|
+
${n.parts.map(p=>this.renderPart(p,n))}
|
|
1055
|
+
</section>
|
|
1056
|
+
`})}
|
|
1057
|
+
</div>
|
|
1058
|
+
</details>
|
|
1059
|
+
`}renderScrollMarker(e){return c`<span class="scroll-marker" data-marker-id=${e} aria-hidden="true"></span>`}renderMessageHeader(e,t){const i=this.messageMetaLabel(e),s=this.expandedMetaKey===t;return c`
|
|
1060
|
+
<div class="msg-header">
|
|
1061
|
+
<b class="label">${Gr(e.role)}</b>
|
|
1062
|
+
<div class="msg-header-trailing">
|
|
1063
|
+
${this.renderMessageActions(e,t)}
|
|
1064
|
+
<span class=${s?"msg-meta expanded":"msg-meta"} role="button" tabindex="0" title=${i.full} aria-label=${i.full} aria-expanded=${String(s)} @click=${()=>{this.expandedMetaKey=s?void 0:t}} @keydown=${o=>{this.onMetaKeydown(o,t,s)}}>${i.short}</span>
|
|
1065
|
+
</div>
|
|
1066
|
+
</div>
|
|
1067
|
+
`}renderMessageActions(e,t){if(!this.isCopyableMessage(e))return null;const i=this.copiedMessageKey===t;return c`
|
|
1068
|
+
<div class="msg-actions" aria-label="消息操作">
|
|
1069
|
+
<button type="button" class="msg-action" title=${i?"已复制":"复制消息"} aria-label=${`${i?"已复制":"复制"}${Gr(e.role)}消息`} @click=${s=>{this.copyMessage(e,t,s)}}>
|
|
1070
|
+
<span aria-hidden="true">${i?"✓":"⧉"}</span>
|
|
1071
|
+
</button>
|
|
1072
|
+
</div>
|
|
1073
|
+
`}onMetaKeydown(e,t,i){e.key!=="Enter"&&e.key!==" "||(e.preventDefault(),this.expandedMetaKey=i?void 0:t)}isCopyableMessage(e){return(e.role==="user"||e.role==="assistant")&&this.messageCopyText(e)!==""}messageCopyText(e){const t=this.messageCopyTextCache.get(e);if(t!==void 0)return t;const i=e.parts.filter(s=>s.type==="text").map(s=>s.text.trim()).filter(s=>s!=="").join(`
|
|
1074
|
+
|
|
1075
|
+
`);return this.messageCopyTextCache.set(e,i),i}async copyMessage(e,t,i){i.stopPropagation(),await this.writeClipboard(this.messageCopyText(e))&&(this.copiedMessageKey=t,window.setTimeout(()=>{this.copiedMessageKey===t&&(this.copiedMessageKey=void 0)},1200))}async writeClipboard(e){try{return await navigator.clipboard.writeText(e),!0}catch{return!1}}messageMetaLabel(e){const t=this.messageMetaCache.get(e);if(t!==void 0)return t;const i=e.meta?.timestamp,s=this.modelLabel(e);if(i===void 0&&s===void 0){const l={short:"无信息",full:"没有可用的 Pi 消息元数据"};return this.messageMetaCache.set(e,l),l}const o=i===void 0?void 0:this.formatTimestamp(i),r=[o?.short,s].filter(l=>l!==void 0&&l!==""),n=[o?.full,s===void 0?void 0:`模型:${s}`].filter(l=>l!==void 0&&l!==""),a={short:r.join(" · "),full:n.join(" · ")};return this.messageMetaCache.set(e,a),a}formatTimestamp(e){const t=new Date(e);if(Number.isFinite(t.getTime()))return{short:yv.format(t),full:Sv.format(t)}}modelLabel(e){const t=e.meta?.model;if(t===void 0)return;const i=t.responseId??t.id;return i===void 0||i===""?t.provider:t.provider!==void 0&&t.provider!==""?`${t.provider}/${i}`:i}renderPart(e,t){return e.type==="text"&&t?.role==="bash"?c`<pre class="part shell-output">${e.text}</pre>`:e.type==="text"?c`<formatted-text class="part" .text=${e.text}></formatted-text>`:e.type==="image"?c`<figure class="part chat-image"><img src=${`data:${e.mimeType};base64,${e.data}`} alt="用户上传的图片" loading="lazy"></figure>`:e.type==="thinking"?c`<details class="part"><summary>思考</summary><formatted-text .text=${e.text}></formatted-text></details>`:e.type==="skillInvocation"?c`
|
|
1076
|
+
<details class="part skill-invocation">
|
|
1077
|
+
<summary><b>[技能]</b> ${e.name}</summary>
|
|
1078
|
+
<small>${e.location}</small>
|
|
1079
|
+
<formatted-text .text=${e.content}></formatted-text>
|
|
1080
|
+
</details>
|
|
1081
|
+
`:e.type==="skillRead"?c`
|
|
1082
|
+
<div class="part skill-read">
|
|
1083
|
+
<strong>已加载 ${e.name}</strong>
|
|
1084
|
+
<small>读取 ${e.path}</small>
|
|
1085
|
+
</div>
|
|
1086
|
+
`:e.type==="toolCall"?c`<div class="part tool-line">▶ ${e.toolName}<span class="summary">${e.summary}</span></div>`:e.type==="toolExecution"?c`<tool-execution-view class="part" .execution=${e}></tool-execution-view>`:e.type==="toolResult"?c`
|
|
1087
|
+
<details class="part" ?open=${e.isError}>
|
|
1088
|
+
<summary>${e.isError?"✖":"✓"} ${e.toolName} 结果</summary>
|
|
1089
|
+
<formatted-text .text=${e.text}></formatted-text>
|
|
1090
|
+
</details>
|
|
1091
|
+
`:null}onGroupToggle(e,t,i){const s=t.currentTarget;s instanceof HTMLDetailsElement&&this.disclosures.applyToggle(e,s.open,i)&&this.requestUpdate()}onScroll(){this.requestLoadMoreIfNeeded(),this.updatePinnedToBottomFromScroll(),this.scheduleConversationRailUpdate(),this.suppressScrollSave||this.scheduleScrollPositionSave()}onWheel(e){e.deltaY<0&&this.canScrollUp()&&(this.pinnedToBottom=!1)}onTouchStart(e){this.touchStartY=e.touches[0]?.clientY}onTouchMove(e){const t=e.touches[0]?.clientY;this.touchStartY!==void 0&&t!==void 0&&t>this.touchStartY&&this.canScrollUp()&&(this.pinnedToBottom=!1)}updatePinnedToBottomFromScroll(){const e=this.chat;if(!e)return;const t=this.didChatHeightChange(),i=this.pinnedToBottom,s=e.scrollTop<this.lastScrollTop;if(t&&i){this.lastClientHeight=e.clientHeight,this.scrollToBottom();return}this.isAtBottom()?this.pinnedToBottom=!0:s?this.pinnedToBottom=!1:this.pinnedToBottom=this.isNearBottom(),this.lastScrollTop=e.scrollTop,this.lastClientHeight=e.clientHeight}didChatHeightChange(){const e=this.chat;return e!==void 0&&this.lastClientHeight!==0&&e.clientHeight!==this.lastClientHeight}isPrependingMessages(e){const t=e.get("messageStart");return typeof t=="number"&&this.messageStart<t}requestLoadMoreIfNeeded(){this.loadMoreCheckFrame===void 0&&(this.loadMoreCheckFrame=requestAnimationFrame(()=>{if(this.loadMoreCheckFrame=void 0,this.suppressLoadMoreRequests)return;const e=this.chat;e&&Zg({hasMore:this.hasMore,loadingMore:this.loadingMore||this.loadMoreRequested,canRequest:this.onLoadMore!==void 0,scrollTop:e.scrollTop,scrollHeight:e.scrollHeight,clientHeight:e.clientHeight})&&this.requestLoadMore()}))}requestLoadMore(){this.loadMoreRequested||!this.hasMore||this.loadingMore||this.onLoadMore===void 0||(this.loadMoreRequested=!0,this.onLoadMore())}isNearBottom(){const e=this.chat;return e?xa(e):!0}isAtBottom(){const e=this.chat;return e?Sa(e)<2:!0}canScrollUp(){const e=this.chat;return e!==void 0&&e.scrollTop>0}scrollToBottom(){this.scrollToBottomFrame===void 0&&(this.scrollToBottomFrame=requestAnimationFrame(()=>{this.scrollToBottomFrame=void 0;const e=this.chat;e&&this.withSuppressedScrollSave(()=>{e.scrollTop=e.scrollHeight,this.lastScrollTop=e.scrollTop,this.lastClientHeight=e.clientHeight})}))}restoreScrollPosition(){const e=this.sessionId;this.restoreScrollFrame!==void 0&&cancelAnimationFrame(this.restoreScrollFrame),this.restoreScrollFrame=requestAnimationFrame(()=>{this.restoreScrollFrame=void 0,this.sessionId===e&&this.withSuppressedScrollSave(()=>{const t=this.scrollController.restorePosition(e,this.chat,this.scrollAnchorElements(),{fallbackToBottom:this.shouldFallbackToBottomForMissingAnchor()});this.handleScrollRestoreResult(e,t)})})}continuePendingScrollRestore(){const e=this.pendingScrollRestoreSessionId,t=this.pendingScrollRestorePosition;e===void 0||t===void 0||e!==this.sessionId||this.restoreScrollFrame!==void 0||(this.restoreScrollFrame=requestAnimationFrame(()=>{this.restoreScrollFrame=void 0,this.sessionId===e&&this.withSuppressedScrollSave(()=>{const i=this.scrollController.restoreExplicitPosition(t,this.chat,this.scrollAnchorElements(),{fallbackToBottom:this.shouldFallbackToBottomForMissingAnchor()});this.handleScrollRestoreResult(e,i)})}))}handleScrollRestoreResult(e,t){if(this.syncScrollMetrics(),t.status!=="missing"){this.updatePinnedToBottomAfterRestore(t.status),(t.status==="restored"||t.status==="bottom")&&this.cancelPrependRestore(),this.pendingScrollRestoreSessionId=void 0,this.pendingScrollRestorePosition=void 0;return}this.pinnedToBottom=!1,this.pendingScrollRestoreSessionId=e,this.pendingScrollRestorePosition=t.position;const i=this.chat;i===void 0||!this.hasMore||this.loadingMore||(i.scrollTop=0,this.syncScrollMetrics(),this.requestLoadMore())}shouldFallbackToBottomForMissingAnchor(){return!this.hasMore&&!this.isReceivingPartialStream}updatePinnedToBottomAfterRestore(e){e==="bottom"?this.pinnedToBottom=!0:e==="restored"&&(this.pinnedToBottom=this.isNearBottom())}syncScrollMetrics(){const e=this.chat;e!==void 0&&(this.lastScrollTop=e.scrollTop,this.lastClientHeight=e.clientHeight)}cancelPrependRestore(){this.prependRestoreToken+=1,this.suppressLoadMoreRequests=!1}capturePrependScrollAnchor(){const e=this.chat;if(e)return Ug(e,this.scrollMarkers())}restorePrependScrollAnchor(e){if(!this.chat||!e)return;this.suppressLoadMoreRequests=!0,this.suppressScrollSave=!0;const t=this.prependRestoreToken+1;this.prependRestoreToken=t;let i=0;const s=()=>{const o=this.chat;if(!(!o||t!==this.prependRestoreToken)){if(Hg(o,e,e.markerId===void 0?void 0:this.scrollMarkerAt(e.markerId)),this.lastScrollTop=o.scrollTop,i+=1,i<Bg){requestAnimationFrame(s);return}requestAnimationFrame(()=>{t===this.prependRestoreToken&&(this.suppressScrollSave=!1,this.suppressLoadMoreRequests=!1)})}};s()}saveScrollPosition(e=this.sessionId){e&&this.scrollController.savePosition(e,this.chat,this.scrollAnchorElements())}scheduleScrollPositionSave(){const e=this.sessionId;this.scrollController.scheduleSave(e,t=>{this.sessionId===t&&this.saveScrollPosition(t)})}scheduleConversationRailUpdate(){this.conversationRailFrame===void 0&&(this.conversationRailFrame=requestAnimationFrame(()=>{this.conversationRailFrame=void 0,this.updateConversationRailPosition()}))}updateConversationRailPosition(){if(!this.messages.length||this.messageTotal<=0){this.currentConversationIndex=void 0;return}const e=this.conversationDisplayTotal(),t=this.firstVisibleArticle(),i=Number(t?.dataset.index);if(Number.isFinite(i)){this.currentConversationIndex=ci(i,0,Math.max(0,e-1));return}this.currentConversationIndex=ci(this.pinnedToBottom?this.messageStart+this.messages.length-1:this.messageStart,0,Math.max(0,e-1))}scrollMarkers(){return Array.from(this.renderRoot.querySelectorAll(".scroll-marker"))}scrollMarkerAt(e){return this.scrollMarkers().find(t=>t.dataset.markerId===e)}firstVisibleArticle(){const e=this.chat;if(e===void 0)return;const t=Array.from(this.renderRoot.querySelectorAll("article.msg"));return Or(e,t)??Or(e,this.articles())}articles(){return Array.from(this.renderRoot.querySelectorAll("article.msg, details.msg"))}scrollAnchorElements(){return Array.from(this.renderRoot.querySelectorAll("[data-scroll-anchor-id]"))}withSuppressedScrollSave(e){this.suppressScrollSave=!0,e(),requestAnimationFrame(()=>{requestAnimationFrame(()=>{this.suppressScrollSave=!1})})}groupDisclosureKey(e,t,i){return i?`${this.sessionId}:live:${String(e)}`:`${this.sessionId}:${String(t)}`}messageAnchorKey(e){return`m:${String(e)}`}groupRenderKey(e){return`g:${String(e)}`}groupAnchorKey(e){return`g:${String(e)}`}eventAnchorKey(e){return`e:${String(e)}`}messageScrollMarkerId(e){return`m:${String(e)}`}groupScrollMarkerId(e){return`g:${String(e)}`}};L.styles=ng;U([d({attribute:!1})],L.prototype,"messages",2);U([d()],L.prototype,"sessionId",2);U([d({type:Number})],L.prototype,"messageStart",2);U([d({type:Number})],L.prototype,"messageEnd",2);U([d({type:Number})],L.prototype,"messageTotal",2);U([d({type:Boolean})],L.prototype,"hasMore",2);U([d({type:Boolean})],L.prototype,"loadingMore",2);U([d({type:Boolean})],L.prototype,"isReceivingPartialStream",2);U([d({type:Boolean})],L.prototype,"isSendingPrompt",2);U([d({type:Boolean})],L.prototype,"isCompacting",2);U([d({type:Number})],L.prototype,"pendingMessageCount",2);U([d({attribute:!1})],L.prototype,"status",2);U([d({attribute:!1})],L.prototype,"activity",2);U([d({attribute:!1})],L.prototype,"onLoadMore",2);U([B(".chat")],L.prototype,"chat",2);U([y()],L.prototype,"pinnedToBottom",2);U([y()],L.prototype,"expandedMetaKey",2);U([y()],L.prototype,"copiedMessageKey",2);U([y()],L.prototype,"currentConversationIndex",2);U([y()],L.prototype,"loadMoreRequested",2);L=U([D("chat-view")],L);function Gr(e){return e==="user"?"用户":e==="assistant"?"助手":e==="system"?"系统":e==="tool"?"工具":e==="toolResult"?"工具结果":e==="bash"?"Shell":e==="skill"?"技能":e}function ds(e){return e==="bash"?"Shell 运行中":e==="running"?"运行中":xv[e]??e}const kv=["image/jpeg","image/png","image/gif","image/webp"],$v=new Set(kv);function Pv(e){return typeof e=="string"&&$v.has(e)}function Rv(e){switch(e){case"image/jpeg":return"jpg";case"image/png":return"png";case"image/gif":return"gif";case"image/webp":return"webp";default:return"bin"}}const Iv="Only PNG, JPEG, GIF, and WebP images are supported.",Cv="Failed to read an attachment.";async function Tv(e,t){const i=[];let s;for(const o of e){if(!Pv(o.type)){s=Iv;continue}try{const r=await t(o);i.push({name:Mv(o),mimeType:o.type,data:r,size:o.size})}catch{s=Cv}}return{attachments:i,...s===void 0?{}:{error:s}}}function Mv(e){return e.name!==""?e.name:`pasted-image.${Rv(e.type)}`}const La="pi-web:attachment-delivery";function ja(){try{return typeof localStorage>"u"?void 0:localStorage}catch{return}}function Av(e=ja()){try{return e?.getItem(La)==="folder"?"folder":"inline"}catch{return"inline"}}function Ev(e,t=ja()){try{t?.setItem(La,e)}catch{}}function Dv(){return ue`
|
|
1092
|
+
<svg class="prompt-action-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false">
|
|
1093
|
+
<path d="M20 11.5 12.5 19a4 4 0 0 1-5.66-5.66l7.07-7.07a2.5 2.5 0 0 1 3.54 3.54l-7.07 7.07a1 1 0 0 1-1.42-1.42l6.37-6.36"></path>
|
|
1094
|
+
</svg>
|
|
1095
|
+
`}function Fa(){return ue`
|
|
1096
|
+
<svg class="prompt-action-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false">
|
|
1097
|
+
<path d="M21 3 13.5 21l-2-8.5L3 10.5Z"></path>
|
|
1098
|
+
<path d="M21 3 11.5 12.5"></path>
|
|
1099
|
+
</svg>
|
|
1100
|
+
`}function Wv(){return ue`
|
|
1101
|
+
<svg class="prompt-action-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false">
|
|
1102
|
+
<path d="M4 7h11"></path>
|
|
1103
|
+
<path d="M4 12h7"></path>
|
|
1104
|
+
<path d="M4 17h7"></path>
|
|
1105
|
+
<path d="m15 14 5 3-5 3z"></path>
|
|
1106
|
+
</svg>
|
|
1107
|
+
`}function Ov(){return Fa()}function _v(){return ue`
|
|
1108
|
+
<svg class="prompt-action-icon prompt-action-icon-filled" viewBox="0 0 24 24" aria-hidden="true" focusable="false">
|
|
1109
|
+
<rect x="6.5" y="6.5" width="11" height="11" rx="2"></rect>
|
|
1110
|
+
</svg>
|
|
1111
|
+
`}function Lv(e){const t=Math.max(e.total,1),i=t>1?1.2:0,s=3,n=(21-s-i*(t-1))/t,a=Array.from({length:t},(l,p)=>{const u=s+p*(n+i),h=4+(p+1)/t*12,g=20-h,w=p<e.filled;return ue`<rect class=${w?"gauge-bar gauge-bar-active":"gauge-bar"} x=${u} y=${g} width=${n} height=${h} rx="1"></rect>`});return ue`
|
|
1112
|
+
<svg class="prompt-thinking-gauge" viewBox="0 0 24 24" aria-hidden="true" focusable="false">
|
|
1113
|
+
${a}
|
|
1114
|
+
</svg>
|
|
1115
|
+
`}const jv=["off","minimal","low","medium","high","xhigh"];function Ls(e){return e===void 0||e===""?"off":e}function Fv(e,t){const i=t.length>=2?t:jv,s=i.length-1,o=Ls(e),r=i.indexOf(o),n=r<=0?0:Math.min(r,s);return{total:s,filled:n}}class Nv extends po{constructor(t){super(t),this.wasSelected=!1,this.isElementPart=t.type===co.ELEMENT}update(t,[i,s]){if(!this.isElementPart)throw new Error("scrollWhenSelected must be used on an element");if(i&&(!this.wasSelected||s!==this.previousKey)){const o="element"in t?t.element:void 0;requestAnimationFrame(()=>{o instanceof HTMLElement&&o.scrollIntoView({block:"nearest"})})}this.wasSelected=i,this.previousKey=s}render(t,i){}}const ko=lo(Nv);var zv=Object.defineProperty,Bv=Object.getOwnPropertyDescriptor,Bi=(e,t,i,s)=>{for(var o=s>1?void 0:s?Bv(t,i):t,r=e.length-1,n;r>=0;r--)(n=e[r])&&(o=(s?n(t,i,o):n(o))||o);return s&&o&&zv(t,i,o),o};let dt=class extends M{constructor(){super(...arguments),this.items=[],this.selectedIndex=0}render(){return this.items.length?c`
|
|
1116
|
+
<div class="menu">
|
|
1117
|
+
${this.items.map((e,t)=>c`
|
|
1118
|
+
<button class=${t===this.selectedIndex?"selected":""} ${ko(t===this.selectedIndex,e)} @mousedown=${i=>{i.preventDefault(),this.onPick?.(e)}}>
|
|
1119
|
+
<strong>${e.insertText}</strong>
|
|
1120
|
+
<span>${e.detail}</span>
|
|
1121
|
+
${e.description!==void 0&&e.description!==""?c`<small>${e.description}</small>`:null}
|
|
1122
|
+
</button>
|
|
1123
|
+
`)}
|
|
1124
|
+
</div>
|
|
1125
|
+
`:null}};dt.styles=lg;Bi([d({attribute:!1})],dt.prototype,"items",2);Bi([d({type:Number})],dt.prototype,"selectedIndex",2);Bi([d({attribute:!1})],dt.prototype,"onPick",2);dt=Bi([D("autocomplete-menu")],dt);var Uv=Object.defineProperty,Hv=Object.getOwnPropertyDescriptor,j=(e,t,i,s)=>{for(var o=s>1?void 0:s?Hv(t,i):t,r=e.length-1,n;r>=0;r--)(n=e[r])&&(o=(s?n(t,i,o):n(o))||o);return s&&o&&Uv(t,i,o),o};let _=class extends M{constructor(){super(...arguments),this.disabled=!1,this.machineId="local",this.canSteer=!1,this.isCompacting=!1,this.canStop=!1,this.sending=!1,this.availableThinkingLevels=[],this.draft="",this.completions=[],this.selectedIndex=0,this.attachments=[],this.attachmentDelivery=Av(),this.attachmentError=void 0,this.attachmentSeq=0,this.requestVersion=0,this.editableCompartment=new Po,this.readOnlyCompartment=new Po}willUpdate(e){if(!e.has("sessionId")&&!e.has("machineId"))return;const t=e.has("sessionId")?e.get("sessionId"):this.sessionId,i=e.has("machineId")?e.get("machineId"):this.machineId,s=Zt(i,t);s!==void 0&&mi(s,this.draft);const o=Zt(this.machineId,this.sessionId);this.draft=o!==void 0?Wn(o):"",this.completions=[],this.selectedIndex=0}firstUpdated(){this.createEditor()}updated(e){e.has("disabled")&&this.updateEditorDisabledState(),(e.has("draft")||e.has("sessionId")||e.has("machineId"))&&this.syncEditorDoc()}disconnectedCallback(){this.editor?.destroy(),this.editor=void 0,super.disconnectedCallback()}render(){const e=eo(this.draft),t=e.kind==="shell",i=this.canSteer||this.isCompacting,s=this.disabled||this.sending;return c`
|
|
1126
|
+
<footer class=${t?"shell-mode":""} @paste=${o=>{this.handlePaste(o)}} @dragover=${o=>{this.handleDragOver(o)}} @drop=${o=>{this.handleDrop(o)}}>
|
|
1127
|
+
<div class="editor-wrap">
|
|
1128
|
+
<div class=${`markdown-editor${this.disabled?" markdown-editor-disabled":""}`} aria-label="给 pi 发送消息" aria-disabled=${this.disabled?"true":"false"}></div>
|
|
1129
|
+
<input class="attachment-input" type="file" accept="image/png,image/jpeg,image/gif,image/webp" multiple hidden @change=${o=>{this.handleFileInput(o)}} />
|
|
1130
|
+
<button class="editor-attach icon-button" ?disabled=${s} title="Attach images" aria-label="Attach images" @click=${()=>{this.attachmentInput?.click()}}>${Dv()}</button>
|
|
1131
|
+
${t?c`<div class="mode-hint">Shell command${e.excludeFromContext?" · excluded from context":""}</div>`:null}
|
|
1132
|
+
${this.isCompacting&&!t?c`<div class="mode-hint">Compacting history · message will be queued</div>`:null}
|
|
1133
|
+
${this.renderAttachments()}
|
|
1134
|
+
<autocomplete-menu .items=${this.completions} .selectedIndex=${this.selectedIndex} .onPick=${o=>{this.pick(o)}}></autocomplete-menu>
|
|
1135
|
+
</div>
|
|
1136
|
+
<div class="actions">
|
|
1137
|
+
${this.renderCompactStatus()}
|
|
1138
|
+
<button class="icon-button send-button" ?disabled=${s} title=${i?"当前活动结束后排队发送":"发送"} aria-label=${i?"排队发送":"发送"} @click=${()=>{this.send("followUp")}}>${i?Wv():Fa()}</button>
|
|
1139
|
+
${this.canSteer&&!this.isCompacting?c`<button class="icon-button steer-button" ?disabled=${s} title="Steer the current response before the next model call" aria-label="Steer current response" @click=${()=>{this.send("steer")}}>${Ov()}</button>`:null}
|
|
1140
|
+
<button class="icon-button stop-button" ?disabled=${this.disabled||!this.canStop} title=${this.canStop?"停止当前工作并清空排队消息":"当前没有运行任务"} aria-label="停止" @click=${()=>this.onStop?.()}>${_v()}</button>
|
|
1141
|
+
</div>
|
|
1142
|
+
</footer>
|
|
1143
|
+
`}focusInput(){this.editor?.focus()}renderCompactStatus(){const e=this.status;if(e===void 0)return null;const t=e.model?.id??"no model",i=e.model?.provider!==void 0&&e.model.provider!==""?`${e.model.provider}/`:"";return c`
|
|
1144
|
+
<div class="compact-status" aria-label="Session status">
|
|
1145
|
+
<button class="select-model" title="Select model" @click=${()=>this.onSelectModel?.()}>${i}${t}</button>
|
|
1146
|
+
<button class="select-thinking icon-button" title=${`Thinking level: ${Ls(e.thinkingLevel)}`} aria-label=${`Thinking level: ${Ls(e.thinkingLevel)}`} @click=${()=>this.onSelectThinking?.()}>${Lv(Fv(e.thinkingLevel,this.availableThinkingLevels))}</button>
|
|
1147
|
+
</div>
|
|
1148
|
+
`}renderAttachments(){return this.attachments.length===0&&this.attachmentError===void 0?null:c`
|
|
1149
|
+
<div class="attachments" aria-label="Pending attachments">
|
|
1150
|
+
${this.attachments.map(e=>c`
|
|
1151
|
+
<div class="attachment-chip" title=${e.name}>
|
|
1152
|
+
<img src=${`data:${e.mimeType};base64,${e.data}`} alt=${e.name} />
|
|
1153
|
+
<button type="button" class="attachment-remove" title="Remove attachment" aria-label=${`Remove ${e.name}`} @click=${()=>{this.removeAttachment(e.id)}}>×</button>
|
|
1154
|
+
</div>
|
|
1155
|
+
`)}
|
|
1156
|
+
${this.attachments.length>0?c`
|
|
1157
|
+
<label class="attachment-delivery" title="How attachments are delivered to the agent">
|
|
1158
|
+
<select .value=${this.attachmentDelivery} @change=${e=>{this.changeDelivery(e)}}>
|
|
1159
|
+
<option value="inline">Attach to message</option>
|
|
1160
|
+
<option value="folder">Save to .pi-web/paste</option>
|
|
1161
|
+
</select>
|
|
1162
|
+
</label>
|
|
1163
|
+
`:null}
|
|
1164
|
+
${this.attachmentError!==void 0?c`<div class="attachment-error">${this.attachmentError}</div>`:null}
|
|
1165
|
+
</div>
|
|
1166
|
+
`}changeDelivery(e){e.target instanceof HTMLSelectElement&&(this.attachmentDelivery=e.target.value==="folder"?"folder":"inline",Ev(this.attachmentDelivery))}removeAttachment(e){this.attachments=this.attachments.filter(t=>t.id!==e)}async handlePaste(e){const t=Jr(e.clipboardData);t.length!==0&&(e.preventDefault(),await this.addAttachmentFiles(t))}handleDragOver(e){e.dataTransfer!==null&&Array.from(e.dataTransfer.items).some(t=>t.kind==="file"&&t.type.startsWith("image/"))&&e.preventDefault()}async handleDrop(e){const t=Jr(e.dataTransfer);t.length!==0&&(e.preventDefault(),await this.addAttachmentFiles(t))}async handleFileInput(e){if(!(e.target instanceof HTMLInputElement)||e.target.files===null)return;const t=Array.from(e.target.files);e.target.value="",await this.addAttachmentFiles(t)}async addAttachmentFiles(e){this.attachmentError=void 0;const{attachments:t,error:i}=await Tv(e,Vv);t.length>0&&(this.attachments=[...this.attachments,...t.map(s=>({id:`attachment-${String(++this.attachmentSeq)}`,...s}))]),i!==void 0&&(this.attachmentError=i)}currentAttachments(){return this.attachments.map(e=>({kind:"image",mimeType:e.mimeType,data:e.data,name:e.name}))}createEditor(){!this.editorHost||this.editor!==void 0||(this.editor=new st({parent:this.editorHost,state:Hi.create({doc:this.draft,extensions:[Ka(),ic(),Va(),Ga.of(" "),Ja(tc,{fallback:!0}),st.lineWrapping,st.contentAttributes.of(e=>Qv(e.state.sliceDoc(0,e.state.selection.main.head))),Qa("给 pi 发送消息... 使用 / 输入命令,@ 输入已跟踪文件,@ 空格显示所有文件"),this.editableCompartment.of(st.editable.of(!this.disabled)),this.readOnlyCompartment.of(Hi.readOnly.of(this.disabled)),st.updateListener.of(e=>{e.docChanged&&this.updateDraft(e.state.doc.toString())}),Za.of([{key:"ArrowDown",run:()=>this.moveCompletion(1)},{key:"ArrowUp",run:()=>this.moveCompletion(-1)},{key:"Escape",run:()=>this.closeCompletions()},{key:"Enter",run:()=>this.handleEditorEnter()},{key:"Shift-Enter",run:e=>sc(e)||ec(e)},{key:"Tab",run:e=>this.handleEditorTab(e)},{key:"Shift-Tab",run:e=>Ro.shift?.(e)??!1},{key:"Backspace",run:e=>oc(e)},...Xa,...Ya])]})}))}syncEditorDoc(){const e=this.editor;if(!e)return;const t=e.state.doc.toString();t!==this.draft&&e.dispatch({changes:{from:0,to:t.length,insert:this.draft},selection:Io.cursor(this.draft.length)})}updateEditorDisabledState(){this.editor?.dispatch({effects:[this.editableCompartment.reconfigure(st.editable.of(!this.disabled)),this.readOnlyCompartment.reconfigure(Hi.readOnly.of(this.disabled))]})}updateDraft(e){this.draft=e;const t=Zt(this.machineId,this.sessionId);t!==void 0&&mi(t,this.draft),this.refreshCompletions()}async refreshCompletions(){const e=this.currentTrigger(),t=++this.requestVersion;if(this.selectedIndex=0,e===void 0){this.completions=[];return}if(e.kind==="command"&&this.sessionId!==void 0&&this.sessionId!==""&&this.cwd!==void 0&&this.cwd!==""){const i=await z.commands({id:this.sessionId,cwd:this.cwd},this.machineId).catch(qv);if(t!==this.requestVersion)return;this.completions=i.filter(s=>s.name.toLowerCase().includes(e.query.toLowerCase())).slice(0,12).map(s=>({kind:"command",replaceFrom:e.from,replaceTo:e.to,insertText:`/${s.name}`,detail:s.source,...s.description===void 0?{}:{description:s.description}}))}else if(e.kind==="file"&&this.cwd!==void 0&&this.cwd!==""){const i=await z.files(this.cwd,e.query,{scope:e.fileScope,machineId:this.machineId}).catch(Kv);if(t!==this.requestVersion)return;this.completions=i.slice(0,12).map(s=>{const o=Nn(s.path,e.quoted===!0,s.path.endsWith("/")?e.allPrefix:void 0);return{kind:"file",replaceFrom:e.from,replaceTo:e.to,insertText:o,detail:s.kind,...s.path.endsWith("/")&&o.endsWith('"')?{cursorOffset:o.length-1}:{}}})}}currentTrigger(){return Fn(this.draft,this.editor?.state.selection.main.head??this.draft.length)}moveCompletion(e){return this.completions.length?(this.selectedIndex=(this.selectedIndex+e+this.completions.length)%this.completions.length,!0):!1}closeCompletions(){return this.completions.length?(this.completions=[],!0):!1}handleEditorEnter(){if(this.completions.length){const e=this.completions[this.selectedIndex];return e!==void 0&&this.pick(e),!0}return this.send(this.canSteer||this.isCompacting?"followUp":void 0),!0}handleEditorTab(e){if(this.completions.length){const i=this.completions[this.selectedIndex];return i!==void 0&&this.pick(i),!0}return this.currentTrigger()?.kind==="file"?(this.refreshCompletions(),!0):Ro.run?.(e)??!1}pick(e){const t=this.editor;if(!t)return;const i=e.kind==="file"&&(e.insertText.endsWith("/")||e.cursorOffset!==void 0)?"":" ",s=e.replaceFrom+(e.cursorOffset??e.insertText.length)+i.length,o=e.insertText.endsWith('"')&&this.draft.slice(e.replaceTo).startsWith('"')?e.replaceTo+1:e.replaceTo;t.dispatch({changes:{from:e.replaceFrom,to:o,insert:`${e.insertText}${i}`},selection:Io.cursor(s),scrollIntoView:!0}),this.completions=[]}send(e){if(this.disabled||this.sending)return;const t=this.draft.trim(),i=this.attachments;if(t===""&&i.length===0)return;const s=this.canSteer||this.isCompacting?e:void 0,o=i.length>0?this.currentAttachments():void 0,r=this.attachmentDelivery;this.resetComposer(),this.onSend?.(t,s,o,o===void 0?void 0:r)}resetComposer(){this.draft="";const e=Zt(this.machineId,this.sessionId);e!==void 0&&Ys(e),this.completions=[],this.attachments=[],this.attachmentError=void 0}};_.styles=pg;j([d({type:Boolean})],_.prototype,"disabled",2);j([d()],_.prototype,"sessionId",2);j([d()],_.prototype,"cwd",2);j([d()],_.prototype,"machineId",2);j([d({type:Boolean})],_.prototype,"canSteer",2);j([d({type:Boolean})],_.prototype,"isCompacting",2);j([d({type:Boolean})],_.prototype,"canStop",2);j([d({attribute:!1})],_.prototype,"status",2);j([d({type:Boolean})],_.prototype,"sending",2);j([d({attribute:!1})],_.prototype,"onSend",2);j([d({attribute:!1})],_.prototype,"onStop",2);j([d({attribute:!1})],_.prototype,"onSelectModel",2);j([d({attribute:!1})],_.prototype,"onSelectThinking",2);j([d({attribute:!1})],_.prototype,"availableThinkingLevels",2);j([B(".markdown-editor")],_.prototype,"editorHost",2);j([B(".attachment-input")],_.prototype,"attachmentInput",2);j([y()],_.prototype,"draft",2);j([y()],_.prototype,"completions",2);j([y()],_.prototype,"selectedIndex",2);j([y()],_.prototype,"attachments",2);j([y()],_.prototype,"attachmentDelivery",2);j([y()],_.prototype,"attachmentError",2);_=j([D("prompt-editor")],_);function Zt(e,t){if(!(typeof e!="string"||e==="")&&!(typeof t!="string"||t===""))return En(e,t)}function qv(){return[]}function Kv(){return[]}function Jr(e){return e===null?[]:Array.from(e.files).filter(t=>t.type.startsWith("image/"))}function Vv(e){return new Promise((t,i)=>{const s=new FileReader;s.onerror=()=>{i(s.error??new Error("Failed to read file"))},s.onload=()=>{const o=s.result;if(typeof o!="string"){i(new Error("Unexpected file reader result"));return}const r=o.indexOf(",");t(r===-1?o:o.slice(r+1))},s.readAsDataURL(e)})}const Gv={spellcheck:"true",autocorrect:"on",autocapitalize:"sentences",writingsuggestions:"true"},Jv={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false"};function Qv(e){return eo(e).kind==="normal"?Gv:Jv}function Xt(e){return Number.isFinite(e)?e<1e3?Math.round(e).toString():e<1e4?`${(e/1e3).toFixed(1)}k`:e<1e6?`${String(Math.round(e/1e3))}k`:e<1e7?`${(e/1e6).toFixed(1)}M`:`${String(Math.round(e/1e6))}M`:"0"}function Zv(e){return!Number.isFinite(e)||e===0?"$0":e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}var Xv=Object.defineProperty,Yv=Object.getOwnPropertyDescriptor,Na=(e,t,i,s)=>{for(var o=s>1?void 0:s?Yv(t,i):t,r=e.length-1,n;r>=0;r--)(n=e[r])&&(o=(s?n(t,i,o):n(o))||o);return s&&o&&Xv(t,i,o),o};let Ii=class extends M{render(){const e=this.status;if(e===void 0)return c`<div class="bar muted">暂无会话状态</div>`;const t=e.contextUsage,i=t?t.percent==null?`上下文 ${Xt(t.contextWindow)}`:`${t.percent.toFixed(1)}%/${Xt(t.contextWindow)}`:"上下文未知",s=e.tokens;return c`
|
|
1167
|
+
<div class="bar">
|
|
1168
|
+
<span>↑${Xt(s.input)}</span>
|
|
1169
|
+
<span>↓${Xt(s.output)}</span>
|
|
1170
|
+
<span class="context">${i}</span>
|
|
1171
|
+
<span>${Zv(e.cost)}</span>
|
|
1172
|
+
${e.pendingMessageCount>0?c`<span>${String(e.pendingMessageCount)} 条排队</span>`:null}
|
|
1173
|
+
</div>
|
|
1174
|
+
`}};Ii.styles=cg;Na([d({attribute:!1})],Ii.prototype,"status",2);Ii=Na([D("status-bar")],Ii);var eb=Object.defineProperty,tb=Object.getOwnPropertyDescriptor,je=(e,t,i,s)=>{for(var o=s>1?void 0:s?tb(t,i):t,r=e.length-1,n;r>=0;r--)(n=e[r])&&(o=(s?n(t,i,o):n(o))||o);return s&&o&&eb(t,i,o),o};let Ie=class extends M{constructor(){super(...arguments),this.title="选择",this.searchable=!1,this.options=[],this.selectedIndex=0,this.query=""}render(){const e=this.filteredOptions();return c`
|
|
1175
|
+
<div class="backdrop" @mousedown=${()=>this.onCancel?.()}>
|
|
1176
|
+
<section @mousedown=${t=>{t.stopPropagation()}}>
|
|
1177
|
+
<header>
|
|
1178
|
+
<strong>${this.title}</strong>
|
|
1179
|
+
<button @click=${()=>this.onCancel?.()}>×</button>
|
|
1180
|
+
</header>
|
|
1181
|
+
${this.searchable?c`<input placeholder="搜索" .value=${this.query} @input=${t=>{this.handleSearchInput(t)}} @keydown=${t=>{this.handleKeyDown(t)}}>`:null}
|
|
1182
|
+
<div class="options" @keydown=${t=>{this.handleKeyDown(t)}} tabindex="0">
|
|
1183
|
+
${e.map((t,i)=>c`
|
|
1184
|
+
<button class=${i===this.selectedIndex?"selected":""} ${ko(i===this.selectedIndex,t.value)} @click=${()=>this.onPick?.(t.value)}>
|
|
1185
|
+
<span>${t.label}</span>
|
|
1186
|
+
${t.description!==void 0&&t.description!==""?c`<small>${t.description}</small>`:null}
|
|
1187
|
+
</button>
|
|
1188
|
+
`)}
|
|
1189
|
+
${e.length===0?c`<div class="empty">没有匹配选项</div>`:null}
|
|
1190
|
+
</div>
|
|
1191
|
+
</section>
|
|
1192
|
+
</div>
|
|
1193
|
+
`}firstUpdated(){this.selectInitialValue(),this.renderRoot.querySelector(this.searchable?"input":".options")?.focus()}selectInitialValue(){if(this.selectedValue===void 0)return;const e=this.filteredOptions().findIndex(t=>t.value===this.selectedValue);e>=0&&(this.selectedIndex=e)}handleSearchInput(e){e.target instanceof HTMLInputElement&&(this.query=e.target.value,this.selectedIndex=0)}filteredOptions(){const e=this.query.trim().toLowerCase();return e===""?this.options:this.options.filter(t=>`${t.label} ${t.description??""} ${t.value}`.toLowerCase().includes(e))}handleKeyDown(e){const t=this.filteredOptions();if(e.key==="Escape")e.preventDefault(),this.onCancel?.();else if(e.key==="ArrowDown")e.preventDefault(),t.length>0&&(this.selectedIndex=(this.selectedIndex+1)%t.length);else if(e.key==="ArrowUp")e.preventDefault(),t.length>0&&(this.selectedIndex=(this.selectedIndex-1+t.length)%t.length);else if(e.key==="Enter"){e.preventDefault();const i=t[this.selectedIndex];i&&this.onPick?.(i.value)}}};Ie.styles=ba;je([d()],Ie.prototype,"title",2);je([d({type:Boolean})],Ie.prototype,"searchable",2);je([d({attribute:!1})],Ie.prototype,"options",2);je([d({attribute:!1})],Ie.prototype,"selectedValue",2);je([d({attribute:!1})],Ie.prototype,"onPick",2);je([d({attribute:!1})],Ie.prototype,"onCancel",2);je([y()],Ie.prototype,"selectedIndex",2);je([y()],Ie.prototype,"query",2);Ie=je([D("command-picker")],Ie);var ib=Object.defineProperty,sb=Object.getOwnPropertyDescriptor,et=(e,t,i,s)=>{for(var o=s>1?void 0:s?sb(t,i):t,r=e.length-1,n;r>=0;r--)(n=e[r])&&(o=(s?n(t,i,o):n(o))||o);return s&&o&&ib(t,i,o),o};let _e=class extends M{constructor(){super(...arguments),this.actions=[],this.queryText="",this.selectedIndex=0}render(){const e=this.filteredActions();return c`
|
|
1194
|
+
<div class="backdrop" @mousedown=${()=>this.onCancel?.()}>
|
|
1195
|
+
<section @mousedown=${t=>{t.stopPropagation()}} @keydown=${t=>{this.handleKeyDown(t)}}>
|
|
1196
|
+
<header>
|
|
1197
|
+
<input
|
|
1198
|
+
.value=${this.queryText}
|
|
1199
|
+
placeholder="搜索操作..."
|
|
1200
|
+
@input=${t=>{t.target instanceof HTMLInputElement&&(this.queryText=t.target.value,this.selectedIndex=0)}}
|
|
1201
|
+
>
|
|
1202
|
+
<button title="关闭" @click=${()=>this.onCancel?.()}>×</button>
|
|
1203
|
+
</header>
|
|
1204
|
+
<div class="options">
|
|
1205
|
+
${e.length===0?c`<div class="empty">未找到操作。</div>`:e.map((t,i)=>c`
|
|
1206
|
+
<button class=${i===this.selectedIndex?"selected":""} ${ko(i===this.selectedIndex,t.id)} @click=${()=>{this.run(t)}}>
|
|
1207
|
+
<span class="main">
|
|
1208
|
+
<strong>${t.title}</strong>
|
|
1209
|
+
${t.description!==void 0&&t.description!==""?c`<small>${t.description}</small>`:null}
|
|
1210
|
+
</span>
|
|
1211
|
+
${t.shortcut!==void 0?c`<kbd>${ri(t.shortcut)}</kbd>`:null}
|
|
1212
|
+
${t.group!==void 0&&t.group!==""?c`<small class="group">${t.group}</small>`:null}
|
|
1213
|
+
</button>
|
|
1214
|
+
`)}
|
|
1215
|
+
</div>
|
|
1216
|
+
</section>
|
|
1217
|
+
</div>
|
|
1218
|
+
`}firstUpdated(){this.input?.focus()}updated(e){if(!e.has("actions")&&!e.has("queryText"))return;const t=Math.max(0,this.filteredActions().length-1);this.selectedIndex>t&&(this.selectedIndex=t)}filteredActions(){const e=this.queryText.trim().toLowerCase();return this.actions.filter(t=>t.enabled!==!1).filter(t=>e===""?!0:[t.title,t.description??"",t.group??"",t.shortcut??""].join(" ").toLowerCase().includes(e))}handleKeyDown(e){const t=this.filteredActions();if(e.key==="Escape")e.preventDefault(),this.onCancel?.();else if(e.key==="ArrowDown")e.preventDefault(),t.length>0&&(this.selectedIndex=(this.selectedIndex+1)%t.length);else if(e.key==="ArrowUp")e.preventDefault(),t.length>0&&(this.selectedIndex=(this.selectedIndex-1+t.length)%t.length);else if(e.key==="Enter"){e.preventDefault();const i=t[this.selectedIndex];i!==void 0&&this.run(i)}}run(e){this.onRun?.(e)}};_e.styles=dg;et([d({attribute:!1})],_e.prototype,"actions",2);et([d({attribute:!1})],_e.prototype,"onRun",2);et([d({attribute:!1})],_e.prototype,"onCancel",2);et([B("input")],_e.prototype,"input",2);et([y()],_e.prototype,"queryText",2);et([y()],_e.prototype,"selectedIndex",2);_e=et([D("action-palette")],_e);var ob=Object.defineProperty,rb=Object.getOwnPropertyDescriptor,we=(e,t,i,s)=>{for(var o=s>1?void 0:s?rb(t,i):t,r=e.length-1,n;r>=0;r--)(n=e[r])&&(o=(s?n(t,i,o):n(o))||o);return s&&o&&ob(t,i,o),o};let oe=class extends M{render(){const e=this.state;return e===void 0?null:c`
|
|
1219
|
+
<div class="backdrop" @mousedown=${()=>{this.cancel()}}>
|
|
1220
|
+
<section @mousedown=${t=>{t.stopPropagation()}} @keydown=${t=>{this.handleKeyDown(t)}}>
|
|
1221
|
+
<header>
|
|
1222
|
+
<strong>${this.dialogTitle(e)}</strong>
|
|
1223
|
+
<button title="关闭" @click=${()=>{this.cancel()}}>×</button>
|
|
1224
|
+
</header>
|
|
1225
|
+
${this.renderBody(e)}
|
|
1226
|
+
</section>
|
|
1227
|
+
</div>
|
|
1228
|
+
`}updated(){this.focusInputIfNeeded()}dialogTitle(e){switch(e.step){case"method":return"配置提供商认证";case"providers":return e.authType===void 0?"选择提供商认证":e.authType==="oauth"?"选择订阅提供商":"选择 API key 提供商";case"apiKey":return`${e.provider.name} 的 API key`;case"oauth":return`登录 ${e.flow.providerName}`;case"logout":return"移除已保存的提供商认证"}}renderBody(e){switch(e.step){case"method":return c`
|
|
1229
|
+
<div class="options">
|
|
1230
|
+
<button @click=${()=>{this.onChooseMethod?.("oauth")}}><span>使用订阅</span><small>ChatGPT Plus/Pro、Claude Pro/Max 或 GitHub Copilot</small></button>
|
|
1231
|
+
<button @click=${()=>{this.onChooseMethod?.("api_key")}}><span>使用 API key</span><small>将 API key 存入 pi auth.json</small></button>
|
|
1232
|
+
</div>
|
|
1233
|
+
`;case"providers":return c`<div class="options">${e.providers.length===0?c`<div class="empty">没有可用提供商。</div>`:e.providers.map(t=>this.renderProviderButton(t))}</div>`;case"apiKey":return c`
|
|
1234
|
+
<div class="form">
|
|
1235
|
+
<p>输入 <strong>${e.provider.name}</strong> 的 API key。它会由 pi 存入 <code>auth.json</code>。</p>
|
|
1236
|
+
<input type="password" autocomplete="off" placeholder="API key" .value=${e.value} @input=${t=>{t.target instanceof HTMLInputElement&&this.onApiKeyInput?.(t.target.value)}}>
|
|
1237
|
+
${e.error!==void 0&&e.error!==""?c`<div class="error-text">${e.error}</div>`:null}
|
|
1238
|
+
<div class="actions"><button @click=${()=>{this.cancel()}}>取消</button><button class="primary" ?disabled=${e.saving===!0} @click=${()=>{this.onSaveApiKey?.()}}>${e.saving===!0?"正在保存…":"保存 API key"}</button></div>
|
|
1239
|
+
</div>
|
|
1240
|
+
`;case"oauth":return this.renderOAuth(e);case"logout":return c`<div class="options">${e.providers.length===0?c`<div class="empty">没有已保存的凭据。环境变量和 models.json 设置不会变化。</div>`:e.providers.map(t=>c`
|
|
1241
|
+
<button @click=${()=>{this.onLogoutProvider?.(t.id)}}><span>${t.name}</span><small>${t.id} · ${Qr(t.authType)}</small></button>
|
|
1242
|
+
`)}</div>`}}renderProviderButton(e){return c`
|
|
1243
|
+
<button @click=${()=>{this.onSelectProvider?.(e.id,e.authType)}}>
|
|
1244
|
+
<span>${e.name}${e.status.source!==void 0?c` <em>${ab(e)}</em>`:null}</span>
|
|
1245
|
+
<small>${e.id} · ${Qr(e.authType)}</small>
|
|
1246
|
+
</button>
|
|
1247
|
+
`}renderOAuth(e){const t=e.flow,i=t.prompt,s=t.select;return c`
|
|
1248
|
+
<div class="form">
|
|
1249
|
+
${t.auth!==void 0?c`
|
|
1250
|
+
<p>打开此授权链接:</p>
|
|
1251
|
+
<p><a href=${t.auth.url} target="_blank" rel="noreferrer">${t.auth.url}</a></p>
|
|
1252
|
+
${t.auth.instructions!==void 0?c`<p class="warning">${t.auth.instructions}</p>`:null}
|
|
1253
|
+
`:c`<p>正在启动登录流程…</p>`}
|
|
1254
|
+
${t.progress.length>0?c`<ul class="progress">${t.progress.map(o=>c`<li>${o}</li>`)}</ul>`:null}
|
|
1255
|
+
${i!==void 0?c`
|
|
1256
|
+
<label>${i.message}</label>
|
|
1257
|
+
<input .value=${e.inputValue??""} placeholder=${i.placeholder??""} @input=${o=>{o.target instanceof HTMLInputElement&&this.onOAuthInput?.(o.target.value)}}>
|
|
1258
|
+
<div class="actions"><button @click=${()=>{this.onOAuthCancel?.()}}>取消</button><button class="primary" ?disabled=${e.responding===!0} @click=${()=>{this.onOAuthRespond?.()}}>提交</button></div>
|
|
1259
|
+
`:null}
|
|
1260
|
+
${s!==void 0?c`
|
|
1261
|
+
<p>${s.message}</p>
|
|
1262
|
+
<div class="inline-options">${s.options.map(o=>c`<button @click=${()=>{this.onOAuthRespond?.(o.value)}}>${o.label}</button>`)}</div>
|
|
1263
|
+
`:null}
|
|
1264
|
+
${e.error!==void 0&&e.error!==""?c`<div class="error-text">${e.error}</div>`:null}
|
|
1265
|
+
${t.status==="error"||t.status==="cancelled"?c`<div class="error-text">${t.error??cb(t.status)}</div><div class="actions"><button @click=${()=>{this.cancel()}}>关闭</button></div>`:null}
|
|
1266
|
+
${i===void 0&&s===void 0&&t.status==="running"?c`<div class="actions"><button @click=${()=>{this.onOAuthCancel?.()}}>取消</button></div>`:null}
|
|
1267
|
+
</div>
|
|
1268
|
+
`}focusInputIfNeeded(){const e=nb(this.state);if(e===void 0){this.lastFocusedInputKey=void 0;return}e!==this.lastFocusedInputKey&&(this.lastFocusedInputKey=e,this.input?.focus())}handleKeyDown(e){if(e.key==="Escape"){e.preventDefault(),this.cancel();return}if(e.key!=="Enter")return;const t=this.state;t?.step==="apiKey"?(e.preventDefault(),this.onSaveApiKey?.()):t?.step==="oauth"&&t.flow.prompt!==void 0&&(e.preventDefault(),this.onOAuthRespond?.())}cancel(){this.state?.step==="oauth"?this.onOAuthCancel?.():this.onCancel?.()}};oe.styles=[ba,O`
|
|
1269
|
+
.form { display: grid; gap: 12px; padding: 14px; overflow: auto; }
|
|
1270
|
+
.form p { margin: 0; color: var(--pi-text-secondary); overflow-wrap: anywhere; }
|
|
1271
|
+
.form a { color: var(--pi-accent); overflow-wrap: anywhere; }
|
|
1272
|
+
.form code { border: 1px solid var(--pi-border); border-radius: 4px; background: var(--pi-surface); padding: 1px 4px; }
|
|
1273
|
+
label { color: var(--pi-muted); }
|
|
1274
|
+
.actions { display: flex; justify-content: flex-end; gap: 8px; }
|
|
1275
|
+
.actions button, .inline-options button { border: 1px solid var(--pi-border); border-radius: 8px; background: var(--pi-surface); color: var(--pi-text); padding: 7px 9px; }
|
|
1276
|
+
.actions button.primary { border-color: var(--pi-success-border); background: var(--pi-success-surface); color: var(--pi-success); }
|
|
1277
|
+
.actions button:disabled { opacity: .6; cursor: wait; }
|
|
1278
|
+
.warning { color: var(--pi-warning); }
|
|
1279
|
+
.error-text { color: var(--pi-danger); }
|
|
1280
|
+
.progress { margin: 0; padding-left: 18px; color: var(--pi-muted); }
|
|
1281
|
+
.inline-options { display: grid; gap: 8px; }
|
|
1282
|
+
em { color: var(--pi-success); font-style: normal; font-size: 12px; }
|
|
1283
|
+
`];we([d({attribute:!1})],oe.prototype,"state",2);we([d({attribute:!1})],oe.prototype,"onChooseMethod",2);we([d({attribute:!1})],oe.prototype,"onSelectProvider",2);we([d({attribute:!1})],oe.prototype,"onApiKeyInput",2);we([d({attribute:!1})],oe.prototype,"onSaveApiKey",2);we([d({attribute:!1})],oe.prototype,"onLogoutProvider",2);we([d({attribute:!1})],oe.prototype,"onOAuthInput",2);we([d({attribute:!1})],oe.prototype,"onOAuthRespond",2);we([d({attribute:!1})],oe.prototype,"onOAuthCancel",2);we([d({attribute:!1})],oe.prototype,"onCancel",2);we([B("input")],oe.prototype,"input",2);oe=we([D("auth-dialog")],oe);function Qr(e){return e==="oauth"?"订阅":"API key"}function nb(e){if(e?.step==="apiKey")return`api-key:${e.provider.authType}:${e.provider.id}`;if(e?.step==="oauth"&&e.flow.prompt!==void 0)return`oauth:${e.flow.flowId}:${e.flow.prompt.requestId}`}function ab(e){if(e.status.source===void 0)return"";switch(e.status.source){case"stored":return"✓ 已配置";case"environment":return`✓ 环境变量${e.status.label===void 0?"":`: ${e.status.label}`}`;case"runtime":return"✓ 运行时";case"fallback":return"✓ 自定义 key";case"models_json_key":return"✓ models.json key";case"models_json_command":return"✓ models.json command";default:return""}}function cb(e){return e==="cancelled"?"已取消":e==="error"?"错误":e}var lb=Object.defineProperty,db=Object.getOwnPropertyDescriptor,Ee=(e,t,i,s)=>{for(var o=s>1?void 0:s?db(t,i):t,r=e.length-1,n;r>=0;r--)(n=e[r])&&(o=(s?n(t,i,o):n(o))||o);return s&&o&&lb(t,i,o),o};let me=class extends M{constructor(){super(...arguments),this.machineId="local",this.path="",this.createMissing=!0,this.suggestions=[],this.selected=0,this.loading=!1,this.requestId=0}connectedCallback(){super.connectedCallback(),this.loadSuggestions()}firstUpdated(){this.pathInput?.focus()}async loadSuggestions(){const e=++this.requestId;this.loading=!0;try{const t=await z.projectDirectories(this.path,this.machineId);if(e!==this.requestId)return;this.suggestions=t,this.selected=Math.min(this.selected,Math.max(0,t.length-1))}catch{e===this.requestId&&(this.suggestions=[])}finally{e===this.requestId&&(this.loading=!1)}}setPath(e){this.path=e,this.selected=0,this.loadSuggestions()}pick(e){this.setPath(e.path)}submit(){this.path.trim()!==""&&this.onSubmit?.(this.path,this.createMissing)}onPathInput(e){e.target instanceof HTMLInputElement&&this.setPath(e.target.value)}onCreateMissingChange(e){e.target instanceof HTMLInputElement&&(this.createMissing=e.target.checked)}onKeyDown(e){if(e.key==="Escape")e.preventDefault(),this.onCancel?.();else if(e.key==="Enter")e.preventDefault(),this.submit();else if(e.key==="ArrowDown")e.preventDefault(),this.selected=Math.min(this.selected+1,Math.max(0,this.suggestions.length-1));else if(e.key==="ArrowUp")e.preventDefault(),this.selected=Math.max(0,this.selected-1);else if(e.key==="Tab"){const t=this.suggestions[this.selected];if(t===void 0)return;e.preventDefault(),this.pick(t)}}render(){return c`
|
|
1284
|
+
<div class="backdrop" @click=${()=>this.onCancel?.()}>
|
|
1285
|
+
<section @click=${e=>{e.stopPropagation()}}>
|
|
1286
|
+
<header>
|
|
1287
|
+
<strong>添加项目</strong>
|
|
1288
|
+
<button @click=${()=>{this.onCancel?.()}} aria-label="关闭">×</button>
|
|
1289
|
+
</header>
|
|
1290
|
+
<div class="body">
|
|
1291
|
+
<label>
|
|
1292
|
+
项目文件夹
|
|
1293
|
+
<input .value=${this.path} @input=${e=>{this.onPathInput(e)}} @keydown=${e=>{this.onKeyDown(e)}} placeholder="/path/to/project or ~/code/project" autofocus />
|
|
1294
|
+
</label>
|
|
1295
|
+
<div class="suggestions">
|
|
1296
|
+
${this.loading?c`<div class="hint">正在加载文件夹…</div>`:null}
|
|
1297
|
+
${this.suggestions.map((e,t)=>c`
|
|
1298
|
+
<button class=${t===this.selected?"selected":""} @click=${()=>{this.pick(e)}}>
|
|
1299
|
+
${e.path}
|
|
1300
|
+
</button>
|
|
1301
|
+
`)}
|
|
1302
|
+
${!this.loading&&this.suggestions.length===0?c`<div class="hint">没有匹配的文件夹。输入新路径即可创建。</div>`:null}
|
|
1303
|
+
</div>
|
|
1304
|
+
<label class="check">
|
|
1305
|
+
<input type="checkbox" .checked=${this.createMissing} @change=${e=>{this.onCreateMissingChange(e)}} />
|
|
1306
|
+
如果文件夹不存在则创建
|
|
1307
|
+
</label>
|
|
1308
|
+
</div>
|
|
1309
|
+
<footer>
|
|
1310
|
+
<button @click=${()=>{this.onCancel?.()}}>取消</button>
|
|
1311
|
+
<button class="primary" ?disabled=${this.path.trim()===""} @click=${()=>{this.submit()}}>添加项目</button>
|
|
1312
|
+
</footer>
|
|
1313
|
+
</section>
|
|
1314
|
+
</div>
|
|
1315
|
+
`}};me.styles=O`
|
|
1316
|
+
:host { position: fixed; inset: 0; z-index: 30; color: var(--pi-text); font: 14px system-ui, sans-serif; }
|
|
1317
|
+
.backdrop { display: grid; place-items: start center; width: 100%; height: 100%; padding-top: min(12vh, 90px); box-sizing: border-box; background: var(--pi-overlay); }
|
|
1318
|
+
section { width: min(720px, calc(100vw - 40px)); max-height: min(700px, calc(100vh - 40px)); display: flex; flex-direction: column; border: 1px solid var(--pi-border); border-radius: 12px; background: var(--pi-bg); box-shadow: 0 20px 60px var(--pi-shadow-strong); overflow: hidden; }
|
|
1319
|
+
header, footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px; border-bottom: 1px solid var(--pi-border); }
|
|
1320
|
+
footer { border-top: 1px solid var(--pi-border); border-bottom: 0; justify-content: end; }
|
|
1321
|
+
.body { display: grid; gap: 12px; padding: 12px; min-height: 0; }
|
|
1322
|
+
label { display: grid; gap: 6px; color: var(--pi-muted); }
|
|
1323
|
+
input[type="text"], input:not([type]) { box-sizing: border-box; width: 100%; border: 1px solid var(--pi-border); border-radius: 8px; background: var(--pi-bg); color: var(--pi-text); padding: 9px; font: 14px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
|
|
1324
|
+
.check { display: flex; grid-template-columns: auto 1fr; align-items: center; color: var(--pi-text); }
|
|
1325
|
+
.suggestions { min-height: 90px; max-height: 320px; overflow: auto; border: 1px solid var(--pi-border); border-radius: 8px; background: var(--pi-surface); }
|
|
1326
|
+
.suggestions button { display: block; width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border: 0; border-bottom: 1px solid var(--pi-border); border-radius: 0; background: transparent; color: var(--pi-text); padding: 8px 10px; text-align: left; font: 13px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
|
|
1327
|
+
.suggestions button.selected, .suggestions button:hover { background: var(--pi-selection-bg); }
|
|
1328
|
+
.hint { padding: 12px; color: var(--pi-muted); }
|
|
1329
|
+
button { border: 1px solid var(--pi-border); border-radius: 8px; background: var(--pi-surface); color: var(--pi-text); padding: 7px 9px; cursor: pointer; }
|
|
1330
|
+
header button { border: 0; background: transparent; color: var(--pi-muted); font-size: 22px; padding: 0 8px; }
|
|
1331
|
+
.primary { border-color: var(--pi-success-border); background: var(--pi-success-border); }
|
|
1332
|
+
button:disabled { opacity: .5; cursor: not-allowed; }
|
|
1333
|
+
`;Ee([d({attribute:!1})],me.prototype,"onSubmit",2);Ee([d({attribute:!1})],me.prototype,"onCancel",2);Ee([d()],me.prototype,"machineId",2);Ee([y()],me.prototype,"path",2);Ee([y()],me.prototype,"createMissing",2);Ee([y()],me.prototype,"suggestions",2);Ee([y()],me.prototype,"selected",2);Ee([y()],me.prototype,"loading",2);Ee([B("input")],me.prototype,"pathInput",2);me=Ee([D("project-dialog")],me);var pb=Object.defineProperty,hb=Object.getOwnPropertyDescriptor,De=(e,t,i,s)=>{for(var o=s>1?void 0:s?hb(t,i):t,r=e.length-1,n;r>=0;r--)(n=e[r])&&(o=(s?n(t,i,o):n(o))||o);return s&&o&&pb(t,i,o),o};let ve=class extends M{constructor(){super(...arguments),this.error="",this.url="",this.name="",this.token="",this.submitting=!1,this.nameEdited=!1,this.previousSuggestedName=""}firstUpdated(){this.urlInput?.focus()}handleUrlInput(e){if(!(e.target instanceof HTMLInputElement))return;const t=e.target.value,i=ub(t);(!this.nameEdited||this.name.trim()===""||this.name===this.previousSuggestedName)&&(this.name=i),this.previousSuggestedName=i,this.url=t}handleNameInput(e){e.target instanceof HTMLInputElement&&(this.nameEdited=!0,this.name=e.target.value)}handleTokenInput(e){e.target instanceof HTMLInputElement&&(this.token=e.target.value)}handleKeyDown(e){if(e.key==="Escape"){e.preventDefault(),this.onCancel?.();return}e.key==="Enter"&&e.target instanceof HTMLInputElement&&e.target.name==="baseUrl"&&ps(this.url)===void 0&&(e.preventDefault(),this.updateComplete.then(()=>{this.nameInput?.focus(),this.nameInput?.select()}))}handleSubmit(e){e.preventDefault(),this.submit()}async submit(){const e=this.validInput();if(!(e===void 0||this.submitting)){this.submitting=!0;try{await this.onSubmit?.(e)}finally{this.isConnected&&(this.submitting=!1)}}}validInput(){const e=this.url.trim(),t=this.name.trim();if(e===""||t===""||ps(e)!==void 0)return;const i=this.token.trim();return{name:t,baseUrl:e,...i===""?{}:{token:i}}}render(){const e=this.url.trim()!=="",t=e?ps(this.url):void 0,i=this.validInput()!==void 0&&!this.submitting;return c`
|
|
1334
|
+
<div class="backdrop" @click=${()=>this.onCancel?.()}>
|
|
1335
|
+
<section @click=${s=>{s.stopPropagation()}}>
|
|
1336
|
+
<form @submit=${s=>{this.handleSubmit(s)}} @keydown=${s=>{this.handleKeyDown(s)}}>
|
|
1337
|
+
<header>
|
|
1338
|
+
<strong>添加机器</strong>
|
|
1339
|
+
<button type="button" @click=${()=>{this.onCancel?.()}} aria-label="关闭">×</button>
|
|
1340
|
+
</header>
|
|
1341
|
+
<div class="body">
|
|
1342
|
+
${this.error===""?null:c`<div class="dialog-error" role="alert">${this.error}</div>`}
|
|
1343
|
+
<label>
|
|
1344
|
+
远程 PI WEB URL
|
|
1345
|
+
<input name="baseUrl" type="url" .value=${this.url} @input=${s=>{this.handleUrlInput(s)}} placeholder="http://dev-box.local:8504" autocomplete="url" inputmode="url" autofocus />
|
|
1346
|
+
</label>
|
|
1347
|
+
<small class=${t===void 0?"hint":"field-error"}>${t??"先输入可访问的基础 URL,包含 http:// 或 https://。"}</small>
|
|
1348
|
+
${e?c`
|
|
1349
|
+
<label>
|
|
1350
|
+
机器名称
|
|
1351
|
+
<input name="name" type="text" .value=${this.name} @input=${s=>{this.handleNameInput(s)}} placeholder=${this.previousSuggestedName||"开发机"} autocomplete="off" />
|
|
1352
|
+
</label>
|
|
1353
|
+
<small class="hint">根据 URL 自动建议。可以改成更友好的侧栏名称。</small>
|
|
1354
|
+
<label>
|
|
1355
|
+
Bearer token <span class="optional">可选</span>
|
|
1356
|
+
<input name="token" type="password" .value=${this.token} @input=${s=>{this.handleTokenInput(s)}} placeholder="如果远程机器不需要 token,可留空" autocomplete="off" />
|
|
1357
|
+
</label>
|
|
1358
|
+
<small class="hint">只粘贴 token 值;PI WEB 会通过 Authorization: Bearer 请求头发送。</small>
|
|
1359
|
+
`:c`<p class="hint intro">输入 URL 后,PI WEB 会建议机器名称,并允许添加可选的 bearer token。</p>`}
|
|
1360
|
+
</div>
|
|
1361
|
+
<footer>
|
|
1362
|
+
<button type="button" @click=${()=>{this.onCancel?.()}}>取消</button>
|
|
1363
|
+
<button class="primary" type="submit" ?disabled=${!i}>${this.submitting?"正在添加…":"添加机器"}</button>
|
|
1364
|
+
</footer>
|
|
1365
|
+
</form>
|
|
1366
|
+
</section>
|
|
1367
|
+
</div>
|
|
1368
|
+
`}};ve.styles=O`
|
|
1369
|
+
:host { position: fixed; inset: 0; z-index: 30; color: var(--pi-text); font: 14px system-ui, sans-serif; }
|
|
1370
|
+
.backdrop { display: grid; place-items: start center; width: 100%; height: 100%; padding-top: min(12vh, 90px); box-sizing: border-box; background: var(--pi-overlay); }
|
|
1371
|
+
section { width: min(560px, calc(100vw - 40px)); max-height: min(640px, calc(100vh - 40px)); border: 1px solid var(--pi-border); border-radius: 12px; background: var(--pi-bg); box-shadow: 0 20px 60px var(--pi-shadow-strong); overflow: hidden; }
|
|
1372
|
+
form { display: flex; flex-direction: column; max-height: inherit; min-height: 0; }
|
|
1373
|
+
header, footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px; border-bottom: 1px solid var(--pi-border); }
|
|
1374
|
+
footer { border-top: 1px solid var(--pi-border); border-bottom: 0; justify-content: end; }
|
|
1375
|
+
.body { display: grid; gap: 8px; padding: 12px; min-height: 0; overflow: auto; }
|
|
1376
|
+
label { display: grid; gap: 6px; color: var(--pi-muted); }
|
|
1377
|
+
input { box-sizing: border-box; width: 100%; border: 1px solid var(--pi-border); border-radius: 8px; background: var(--pi-bg); color: var(--pi-text); padding: 9px; font: 14px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
|
|
1378
|
+
input:focus-visible { outline: 2px solid var(--pi-accent); outline-offset: 1px; }
|
|
1379
|
+
.hint { color: var(--pi-muted); }
|
|
1380
|
+
.intro { margin: 4px 0 0; line-height: 1.4; }
|
|
1381
|
+
.optional { color: var(--pi-muted); font-weight: 400; }
|
|
1382
|
+
.field-error { color: var(--pi-danger); }
|
|
1383
|
+
.dialog-error { border: 1px solid var(--pi-danger); border-radius: 8px; background: color-mix(in srgb, var(--pi-danger) 10%, transparent); color: var(--pi-danger); padding: 9px; line-height: 1.35; }
|
|
1384
|
+
button { border: 1px solid var(--pi-border); border-radius: 8px; background: var(--pi-surface); color: var(--pi-text); padding: 7px 9px; cursor: pointer; }
|
|
1385
|
+
header button { border: 0; background: transparent; color: var(--pi-muted); font-size: 22px; padding: 0 8px; }
|
|
1386
|
+
.primary { border-color: var(--pi-success-border); background: var(--pi-success-border); }
|
|
1387
|
+
button:disabled { opacity: .5; cursor: not-allowed; }
|
|
1388
|
+
`;De([d({attribute:!1})],ve.prototype,"onSubmit",2);De([d({attribute:!1})],ve.prototype,"onCancel",2);De([d()],ve.prototype,"error",2);De([y()],ve.prototype,"url",2);De([y()],ve.prototype,"name",2);De([y()],ve.prototype,"token",2);De([y()],ve.prototype,"submitting",2);De([B("input[name='baseUrl']")],ve.prototype,"urlInput",2);De([B("input[name='name']")],ve.prototype,"nameInput",2);ve=De([D("machine-dialog")],ve);function ub(e){const t=e.trim();if(t==="")return"";const i=Zr(t)??Zr(`http://${t.replace(/^\/+/u,"")}`);return i!==void 0&&i.hostname!==""?i.hostname.replace(/^\[(.*)\]$/u,"$1"):fb(t)}function ps(e){const t=e.trim();if(t==="")return"必须填写远程 PI WEB URL。";let i;try{i=new URL(t)}catch{return"请输入包含 http:// 或 https:// 的有效 URL。"}if(i.protocol!=="http:"&&i.protocol!=="https:")return"请使用 http:// 或 https:// URL。";if(i.username!==""||i.password!=="")return"机器 URL 中不要包含凭据。";if(i.search!==""||i.hash!=="")return"不要包含查询字符串或片段。"}function Zr(e){try{const t=new URL(e);return t.protocol==="http:"||t.protocol==="https:"?t:void 0}catch{return}}function fb(e){const t=e.replace(/^[a-z][a-z\d+.-]*:\/\//iu,""),s=t.slice(t.lastIndexOf("@")+1).split(/[/?#]/u)[0]??"";return s.startsWith("[")&&s.includes("]")?s.slice(1,s.indexOf("]")):s.replace(/:\d+$/u,"")}function gb(){return{host:"",port:"",allowedHostsMode:"list",allowedHostsText:""}}function mb(e){return{host:e.host??"",port:e.port===void 0?"":String(e.port),allowedHostsMode:e.allowedHosts===!0?"all":"list",allowedHostsText:Array.isArray(e.allowedHosts)?e.allowedHosts.join(`
|
|
1389
|
+
`):""}}function vb(e,t={}){const i={...t.shortcuts===void 0?{}:{shortcuts:t.shortcuts},...t.plugins===void 0?{}:{plugins:t.plugins}},s=e.host.trim(),o=e.port.trim();if(s!==""&&(i.host=s),o!==""){const r=Number(o);if(!Number.isInteger(r)||r<1||r>65535)throw new Error("端口必须是 1 到 65535 之间的整数。");i.port=r}return i.allowedHosts=e.allowedHostsMode==="all"?!0:bb(e.allowedHostsText),i}function bb(e){return e.split(/[\n,]/u).map(t=>t.trim()).filter(t=>t!=="")}var wb=Object.defineProperty,yb=Object.getOwnPropertyDescriptor,We=(e,t,i,s)=>{for(var o=s>1?void 0:s?yb(t,i):t,r=e.length-1,n;r>=0;r--)(n=e[r])&&(o=(s?n(t,i,o):n(o))||o);return s&&o&&wb(t,i,o),o};let be=class extends M{constructor(){super(...arguments),this.loading=!1,this.saving=!1,this.error="",this.savedMessage="",this.draft=gb(),this.localError=""}willUpdate(e){e.has("configResponse")&&this.configResponse!==void 0&&(this.draft=mb(this.configResponse.config),this.localError="")}render(){const e=this.configResponse;return c`
|
|
1390
|
+
<div class="section-heading">
|
|
1391
|
+
<div>
|
|
1392
|
+
<h2>通用配置</h2>
|
|
1393
|
+
<p>更新 PI WEB 正在使用的 JSON 配置文件。Host 和端口会立即保存,但需要重启 Web 服务后,运行中的服务器才会绑定到新地址。</p>
|
|
1394
|
+
</div>
|
|
1395
|
+
<button class="secondary" ?disabled=${this.loading} @click=${()=>{this.onReload?.()}}>重新加载</button>
|
|
1396
|
+
</div>
|
|
1397
|
+
${this.renderMessages()}
|
|
1398
|
+
${e===void 0&&this.loading?c`<div class="loading-card">正在加载配置…</div>`:c`
|
|
1399
|
+
<div class="config-path-card">
|
|
1400
|
+
<span>配置文件</span>
|
|
1401
|
+
<code>${e?.path??"未知"}</code>
|
|
1402
|
+
<small>${e?.exists===!0?"已有文件":"保存时会创建此文件"}</small>
|
|
1403
|
+
</div>
|
|
1404
|
+
<form class="config-form" @submit=${t=>{this.saveConfig(t)}}>
|
|
1405
|
+
<label class="field">
|
|
1406
|
+
<span class="field-heading">
|
|
1407
|
+
<span>Host</span>
|
|
1408
|
+
${this.renderOverrideBadge("host")}
|
|
1409
|
+
</span>
|
|
1410
|
+
<input .value=${this.draft.host} placeholder="127.0.0.1" autocomplete="off" spellcheck="false" @input=${t=>{this.updateDraft({host:Xr(t)})}}>
|
|
1411
|
+
<small>Web 服务器应绑定的地址。留空则使用 PI WEB 默认值。</small>
|
|
1412
|
+
</label>
|
|
1413
|
+
|
|
1414
|
+
<label class="field">
|
|
1415
|
+
<span class="field-heading">
|
|
1416
|
+
<span>Port</span>
|
|
1417
|
+
${this.renderOverrideBadge("port")}
|
|
1418
|
+
</span>
|
|
1419
|
+
<input .value=${this.draft.port} inputmode="numeric" pattern="[0-9]*" placeholder="8504" autocomplete="off" @input=${t=>{this.updateDraft({port:Xr(t)})}}>
|
|
1420
|
+
<small>TCP 端口,范围 1 到 65535。留空则使用 PI WEB 默认值。</small>
|
|
1421
|
+
</label>
|
|
1422
|
+
|
|
1423
|
+
<div class="field">
|
|
1424
|
+
<span class="field-heading">
|
|
1425
|
+
<span>允许的 hosts</span>
|
|
1426
|
+
${this.renderOverrideBadge("allowedHosts")}
|
|
1427
|
+
</span>
|
|
1428
|
+
<select .value=${this.draft.allowedHostsMode} @change=${t=>{this.updateDraft({allowedHostsMode:xb(t)==="all"?"all":"list"})}}>
|
|
1429
|
+
<option value="list">仅允许列出的 hosts</option>
|
|
1430
|
+
<option value="all">允许所有 host</option>
|
|
1431
|
+
</select>
|
|
1432
|
+
<textarea .value=${this.draft.allowedHostsText} ?disabled=${this.draft.allowedHostsMode==="all"} rows="4" placeholder="example.local 192.168.1.20" spellcheck="false" @input=${t=>{this.updateDraft({allowedHostsText:kb(t)})}}></textarea>
|
|
1433
|
+
<small>每行输入一个 host,或选择“允许所有 host”写入 <code>true</code>。</small>
|
|
1434
|
+
</div>
|
|
1435
|
+
|
|
1436
|
+
${this.renderEffectiveConfig()}
|
|
1437
|
+
|
|
1438
|
+
<footer class="form-actions">
|
|
1439
|
+
<button class="primary" ?disabled=${this.loading||this.saving}>${this.saving?"正在保存…":"保存配置"}</button>
|
|
1440
|
+
</footer>
|
|
1441
|
+
</form>
|
|
1442
|
+
`}
|
|
1443
|
+
`}renderMessages(){const e=this.localError||this.error;return e!==""?c`<div class="message error-message">${e}</div>`:this.savedMessage!==""?c`<div class="message success-message">${this.savedMessage}</div>`:null}renderOverrideBadge(e){return this.configResponse?.envOverrides[e]!==!0?null:c`<span class="override-badge">环境变量覆盖</span>`}renderEffectiveConfig(){const e=this.configResponse?.effectiveConfig??{};return c`
|
|
1444
|
+
<section class="effective-card" aria-label="最终生效配置摘要">
|
|
1445
|
+
<h3>环境变量覆盖后的生效配置</h3>
|
|
1446
|
+
<dl>
|
|
1447
|
+
<div><dt>Host</dt><dd>${e.host??c`<span class="muted">默认 127.0.0.1</span>`}</dd></div>
|
|
1448
|
+
<div><dt>端口</dt><dd>${e.port??c`<span class="muted">默认 8504</span>`}</dd></div>
|
|
1449
|
+
<div><dt>允许的 hosts</dt><dd>${Sb(e.allowedHosts)}</dd></div>
|
|
1450
|
+
</dl>
|
|
1451
|
+
</section>
|
|
1452
|
+
`}async saveConfig(e){e.preventDefault(),this.localError="";try{await this.onSave?.(vb(this.draft,this.configResponse?.config??{}))}catch(t){this.localError=$b(t)}}updateDraft(e){this.draft={...this.draft,...e},this.localError=""}};be.styles=O`
|
|
1453
|
+
:host { display: block; }
|
|
1454
|
+
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
|
|
1455
|
+
.section-heading > div { display: grid; gap: 6px; min-width: 0; }
|
|
1456
|
+
h2, h3, p { margin: 0; }
|
|
1457
|
+
h2 { font-size: 17px; line-height: 1.25; }
|
|
1458
|
+
h3 { font-size: 13px; line-height: 1.3; }
|
|
1459
|
+
p { color: var(--pi-muted); line-height: 1.45; }
|
|
1460
|
+
button, input, select, textarea { font: inherit; }
|
|
1461
|
+
button { border: 1px solid var(--pi-border); border-radius: 8px; background: var(--pi-surface); color: var(--pi-text); padding: 7px 9px; cursor: pointer; }
|
|
1462
|
+
button:disabled { opacity: .55; cursor: not-allowed; }
|
|
1463
|
+
.secondary { flex: 0 0 auto; }
|
|
1464
|
+
.message, .loading-card, .config-path-card, .effective-card { border: 1px solid var(--pi-border); border-radius: 10px; background: var(--pi-surface); padding: 12px; }
|
|
1465
|
+
.message { margin-bottom: 12px; }
|
|
1466
|
+
.error-message { border-color: var(--pi-danger); color: var(--pi-danger); background: color-mix(in srgb, var(--pi-danger) 10%, var(--pi-surface)); }
|
|
1467
|
+
.success-message { border-color: var(--pi-success-border); color: var(--pi-success); background: var(--pi-success-surface); }
|
|
1468
|
+
.loading-card { color: var(--pi-muted); }
|
|
1469
|
+
.config-path-card { display: grid; gap: 5px; margin-bottom: 14px; }
|
|
1470
|
+
.config-path-card span, .field-heading, dt { color: var(--pi-muted); font-size: 12px; font-weight: 700; text-transform: uppercase; }
|
|
1471
|
+
code { border: 1px solid var(--pi-border-muted); border-radius: 5px; background: var(--pi-bg); padding: 1px 4px; color: var(--pi-text); font: 12px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; overflow-wrap: anywhere; }
|
|
1472
|
+
.config-path-card small, .field small { color: var(--pi-muted); }
|
|
1473
|
+
.config-form { display: grid; gap: 14px; }
|
|
1474
|
+
.field { display: grid; gap: 7px; }
|
|
1475
|
+
.field-heading { display: flex; align-items: center; gap: 8px; }
|
|
1476
|
+
input, select, textarea { box-sizing: border-box; width: 100%; min-width: 0; border: 1px solid var(--pi-border); border-radius: 8px; background: var(--pi-bg); color: var(--pi-text); padding: 9px 10px; outline: none; }
|
|
1477
|
+
input:focus, select:focus, textarea:focus { border-color: var(--pi-accent); box-shadow: 0 0 0 1px var(--pi-accent-border); }
|
|
1478
|
+
textarea { resize: vertical; min-height: 94px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
|
|
1479
|
+
textarea:disabled { opacity: .55; }
|
|
1480
|
+
.override-badge { border: 1px solid var(--pi-warning-border); border-radius: 999px; color: var(--pi-warning); background: var(--pi-warning-surface); padding: 2px 7px; font-size: 11px; font-weight: 600; text-transform: none; }
|
|
1481
|
+
.effective-card { display: grid; gap: 10px; }
|
|
1482
|
+
.effective-card dl { display: grid; gap: 8px; margin: 0; }
|
|
1483
|
+
.effective-card dl > div { display: grid; grid-template-columns: 130px minmax(0, 1fr); gap: 12px; align-items: baseline; }
|
|
1484
|
+
dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
|
|
1485
|
+
.muted { color: var(--pi-muted); }
|
|
1486
|
+
.form-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 2px; }
|
|
1487
|
+
.primary { border-color: var(--pi-accent); background: var(--pi-selection-bg); color: var(--pi-text-bright); }
|
|
1488
|
+
|
|
1489
|
+
@media (max-width: 760px) {
|
|
1490
|
+
.section-heading { display: grid; gap: 12px; }
|
|
1491
|
+
.section-heading .secondary { justify-self: start; }
|
|
1492
|
+
.effective-card dl > div { grid-template-columns: minmax(0, 1fr); gap: 3px; }
|
|
1493
|
+
}
|
|
1494
|
+
`;We([d({attribute:!1})],be.prototype,"configResponse",2);We([d({type:Boolean})],be.prototype,"loading",2);We([d({type:Boolean})],be.prototype,"saving",2);We([d()],be.prototype,"error",2);We([d()],be.prototype,"savedMessage",2);We([d({attribute:!1})],be.prototype,"onReload",2);We([d({attribute:!1})],be.prototype,"onSave",2);We([y()],be.prototype,"draft",2);We([y()],be.prototype,"localError",2);be=We([D("settings-general-panel")],be);function Sb(e){return e===!0?"任意 host":Array.isArray(e)?e.length===0?c`<span class="muted">未列出</span>`:e.join(", "):c`<span class="muted">未设置</span>`}function Xr(e){return e.target instanceof HTMLInputElement?e.target.value:""}function xb(e){return e.target instanceof HTMLSelectElement?e.target.value:""}function kb(e){return e.target instanceof HTMLTextAreaElement?e.target.value:""}function $b(e){return e instanceof Error?e.message:String(e)}var Pb=Object.defineProperty,Rb=Object.getOwnPropertyDescriptor,Fe=(e,t,i,s)=>{for(var o=s>1?void 0:s?Rb(t,i):t,r=e.length-1,n;r>=0;r--)(n=e[r])&&(o=(s?n(t,i,o):n(o))||o);return s&&o&&Pb(t,i,o),o};let Ce=class extends M{constructor(){super(...arguments),this.loading=!1,this.saving=!1,this.error="",this.savedMessage=""}render(){const e=this.pluginsResponse?.plugins??[];return c`
|
|
1495
|
+
<div class="section-heading">
|
|
1496
|
+
<div>
|
|
1497
|
+
<h2>插件</h2>
|
|
1498
|
+
<p>启用或禁用已发现的 PI WEB 插件。更改会在重新加载浏览器标签页后生效;当前页面已加载的插件代码不会被卸载。</p>
|
|
1499
|
+
</div>
|
|
1500
|
+
<button class="secondary" ?disabled=${this.loading} @click=${()=>{this.onReload?.()}}>重新加载</button>
|
|
1501
|
+
</div>
|
|
1502
|
+
${this.renderMessages()}
|
|
1503
|
+
<div class="plugin-note">配置键:<code>plugins</code>。除非条目将 <code>enabled</code> 设置为 <code>false</code>,插件默认启用。</div>
|
|
1504
|
+
${this.loading&&e.length===0?c`<div class="loading-card">正在加载插件…</div>`:e.length===0?c`<div class="loading-card">未发现外部或内置插件。</div>`:c`
|
|
1505
|
+
<div class="plugin-list">
|
|
1506
|
+
${e.map(t=>this.renderPlugin(t))}
|
|
1507
|
+
</div>
|
|
1508
|
+
`}
|
|
1509
|
+
`}renderMessages(){return this.error!==""?c`<div class="message error-message">${this.error}</div>`:this.savedMessage!==""?c`<div class="message success-message">${this.savedMessage} 重新加载浏览器标签页以应用插件更改。</div>`:null}renderPlugin(e){const t=this.configResponse?.config.plugins?.[e.id],i=t?.enabled===!1?"配置已禁用":t?.enabled===!0?"配置已启用":"默认启用";return c`
|
|
1510
|
+
<article class=${`plugin-card${e.enabled?"":" disabled"}`}>
|
|
1511
|
+
<div class="plugin-main">
|
|
1512
|
+
<strong>${e.id}</strong>
|
|
1513
|
+
<small>${e.source} · ${e.scope}${e.machineSpecific?" · machine-specific":""}</small>
|
|
1514
|
+
<small>${i}</small>
|
|
1515
|
+
</div>
|
|
1516
|
+
<label class="toggle">
|
|
1517
|
+
<input type="checkbox" .checked=${e.enabled} ?disabled=${this.saving} @change=${s=>{this.togglePlugin(e,s)}}>
|
|
1518
|
+
<span>${e.enabled?"已启用":"已禁用"}</span>
|
|
1519
|
+
</label>
|
|
1520
|
+
</article>
|
|
1521
|
+
`}async togglePlugin(e,t){const i=t.target instanceof HTMLInputElement?t.target.checked:e.enabled;await this.onTogglePlugin?.(e.id,i)}};Ce.styles=O`
|
|
1522
|
+
:host { display: block; }
|
|
1523
|
+
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
|
|
1524
|
+
.section-heading > div { display: grid; gap: 6px; min-width: 0; }
|
|
1525
|
+
h2, p { margin: 0; }
|
|
1526
|
+
h2 { font-size: 17px; line-height: 1.25; }
|
|
1527
|
+
p { color: var(--pi-muted); line-height: 1.45; }
|
|
1528
|
+
button, input { font: inherit; }
|
|
1529
|
+
button { border: 1px solid var(--pi-border); border-radius: 8px; background: var(--pi-surface); color: var(--pi-text); padding: 7px 9px; cursor: pointer; }
|
|
1530
|
+
button:disabled, input:disabled { opacity: .55; cursor: not-allowed; }
|
|
1531
|
+
.secondary { flex: 0 0 auto; }
|
|
1532
|
+
.message, .loading-card, .plugin-note, .plugin-card { border: 1px solid var(--pi-border); border-radius: 10px; background: var(--pi-surface); padding: 12px; }
|
|
1533
|
+
.message { margin-bottom: 12px; }
|
|
1534
|
+
.error-message { border-color: var(--pi-danger); color: var(--pi-danger); background: color-mix(in srgb, var(--pi-danger) 10%, var(--pi-surface)); }
|
|
1535
|
+
.success-message { border-color: var(--pi-success-border); color: var(--pi-success); background: var(--pi-success-surface); }
|
|
1536
|
+
.loading-card, .plugin-note { color: var(--pi-muted); }
|
|
1537
|
+
.plugin-note { margin-bottom: 14px; }
|
|
1538
|
+
code { border: 1px solid var(--pi-border-muted); border-radius: 5px; background: var(--pi-bg); padding: 1px 4px; color: var(--pi-text); font: 12px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; overflow-wrap: anywhere; }
|
|
1539
|
+
.plugin-list { display: grid; gap: 10px; }
|
|
1540
|
+
.plugin-card { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: center; }
|
|
1541
|
+
.plugin-card.disabled { opacity: .75; }
|
|
1542
|
+
.plugin-main { min-width: 0; display: grid; gap: 3px; }
|
|
1543
|
+
.plugin-main strong, .plugin-main small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
1544
|
+
.plugin-main small { color: var(--pi-muted); }
|
|
1545
|
+
.toggle { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }
|
|
1546
|
+
.toggle input { width: 18px; height: 18px; accent-color: var(--pi-accent); }
|
|
1547
|
+
|
|
1548
|
+
@media (max-width: 760px) {
|
|
1549
|
+
.section-heading { display: grid; gap: 12px; }
|
|
1550
|
+
.section-heading .secondary { justify-self: start; }
|
|
1551
|
+
.plugin-card { grid-template-columns: minmax(0, 1fr); align-items: start; }
|
|
1552
|
+
.toggle { justify-self: start; }
|
|
1553
|
+
}
|
|
1554
|
+
`;Fe([d({attribute:!1})],Ce.prototype,"pluginsResponse",2);Fe([d({attribute:!1})],Ce.prototype,"configResponse",2);Fe([d({type:Boolean})],Ce.prototype,"loading",2);Fe([d({type:Boolean})],Ce.prototype,"saving",2);Fe([d()],Ce.prototype,"error",2);Fe([d()],Ce.prototype,"savedMessage",2);Fe([d({attribute:!1})],Ce.prototype,"onReload",2);Fe([d({attribute:!1})],Ce.prototype,"onTogglePlugin",2);Ce=Fe([D("settings-plugins-panel")],Ce);var Ib=Object.defineProperty,Cb=Object.getOwnPropertyDescriptor,ye=(e,t,i,s)=>{for(var o=s>1?void 0:s?Cb(t,i):t,r=e.length-1,n;r>=0;r--)(n=e[r])&&(o=(s?n(t,i,o):n(o))||o);return s&&o&&Ib(t,i,o),o};const Yr={capture:!0};let re=class extends M{constructor(){super(...arguments),this.actions=[],this.loading=!1,this.saving=!1,this.error="",this.savedMessage="",this.drafts={},this.localError="",this.recordingListenerActive=!1,this.onRecordKeyDown=e=>{const t=this.recording;if(t===void 0)return;if(e.preventDefault(),e.stopPropagation(),e.key==="Escape"){this.stopRecording();return}const i=Gn(e);if(i===void 0){this.localError="Press a letter, number, punctuation, function, or navigation key. Press Esc to cancel recording.";return}if(t.tokens.length===0&&!Wt(i)){this.localError="Start shortcuts with Ctrl/⌘ or Alt so normal typing is not captured.";return}const s=[...t.tokens,i];this.localError="",this.drafts={[t.actionId]:s.join(" ")},this.recording={actionId:t.actionId,tokens:s},this.armRecordingTimer()}}willUpdate(e){e.has("configResponse")&&this.configResponse!==void 0&&(this.drafts={},this.localError="",this.stopRecording())}disconnectedCallback(){this.stopRecording(),super.disconnectedCallback()}render(){const e=Eb(this.actions),t=this.shortcutResolutions();return c`
|
|
1555
|
+
<div class="section-heading">
|
|
1556
|
+
<div>
|
|
1557
|
+
<h2>键盘快捷键</h2>
|
|
1558
|
+
<p>按操作编辑应用快捷键。输入 <code>mod+k</code> 或 <code>mod+g p</code> 这类快捷键,也可以从键盘录制、设为无或恢复默认。快捷键冲突时,自定义快捷键优先于默认值;同级按 action id 排序,较短快捷键会遮蔽相同前缀的较长序列。</p>
|
|
1559
|
+
</div>
|
|
1560
|
+
<button class="secondary" ?disabled=${this.loading} @click=${()=>{this.onReload?.()}}>Reload</button>
|
|
1561
|
+
</div>
|
|
1562
|
+
${this.renderMessages()}
|
|
1563
|
+
${this.configResponse===void 0&&this.loading?c`<div class="loading-card">正在加载快捷键…</div>`:c`
|
|
1564
|
+
<div class="config-path-card">
|
|
1565
|
+
<span>配置文件</span>
|
|
1566
|
+
<code>${this.configResponse?.path??"未知"}</code>
|
|
1567
|
+
<small>快捷键覆盖项保存在 <code>shortcuts</code> 下。值为 <code>null</code> 时会禁用该操作快捷键。</small>
|
|
1568
|
+
</div>
|
|
1569
|
+
${e.length===0?c`<div class="loading-card">没有已注册操作。</div>`:e.map(i=>c`
|
|
1570
|
+
<section class="shortcut-group">
|
|
1571
|
+
<h3>${i.name}</h3>
|
|
1572
|
+
<div class="shortcut-list">
|
|
1573
|
+
${i.actions.map(s=>this.renderShortcutRow(s,t.get(s.id)))}
|
|
1574
|
+
</div>
|
|
1575
|
+
</section>
|
|
1576
|
+
`)}
|
|
1577
|
+
`}
|
|
1578
|
+
`}renderMessages(){const e=this.localError||this.error;return e!==""?c`<div class="message error-message">${e}</div>`:this.savedMessage!==""?c`<div class="message success-message">${this.savedMessage}</div>`:null}renderShortcutRow(e,t){const i=this.configResponse?.config.shortcuts,s=Ci(e.id,i),o=_b(e,i),r=this.shortcutInputText(e),n=r.trim()===""?void 0:Yi(r),a=n?.ok===!0?n.shortcut:Ob(e,i),l=s!==void 0,p=this.drafts[e.id]!==void 0,u=p&&r.trim()!==""?"custom":o,h=this.recordingHint(e.id),g=Ab(t);return c`
|
|
1579
|
+
<article class=${Tb(t)}>
|
|
1580
|
+
<div class="shortcut-main">
|
|
1581
|
+
<strong>${e.title}</strong>
|
|
1582
|
+
${e.description!==void 0&&e.description!==""?c`<small>${e.description}</small>`:null}
|
|
1583
|
+
<small class="shortcut-id">${e.id}</small>
|
|
1584
|
+
<small>${e.shortcut!==void 0&&e.shortcut!==""?c`Default: <kbd>${ri(e.shortcut)}</kbd>`:"No default shortcut"}</small>
|
|
1585
|
+
</div>
|
|
1586
|
+
<div class="shortcut-editor">
|
|
1587
|
+
<div class="shortcut-status">
|
|
1588
|
+
${a!==void 0&&a!==""?c`<kbd>${ri(a)}</kbd>`:c`<span class="unassigned">${o==="disabled"?"已禁用":"未分配"}</span>`}
|
|
1589
|
+
<small class=${u}>${Lb(u)}${p?" · 未保存":""}</small>
|
|
1590
|
+
${g===void 0?null:c`<small class=${Mb(t)}>${g}</small>`}
|
|
1591
|
+
</div>
|
|
1592
|
+
<label class="shortcut-input-label">
|
|
1593
|
+
<span>快捷键</span>
|
|
1594
|
+
<input
|
|
1595
|
+
class="shortcut-input"
|
|
1596
|
+
data-action-id=${e.id}
|
|
1597
|
+
.value=${r}
|
|
1598
|
+
placeholder=${e.shortcut??"mod+k"}
|
|
1599
|
+
autocomplete="off"
|
|
1600
|
+
autocapitalize="off"
|
|
1601
|
+
spellcheck="false"
|
|
1602
|
+
?disabled=${this.saving}
|
|
1603
|
+
@input=${w=>{this.updateDraft(e.id,jb(w))}}
|
|
1604
|
+
>
|
|
1605
|
+
</label>
|
|
1606
|
+
${h!==""?c`<small class="recording-hint">${h}</small>`:null}
|
|
1607
|
+
<div class="shortcut-actions">
|
|
1608
|
+
<button class="primary" ?disabled=${this.loading||this.saving||!p||r.trim()===""} @click=${()=>{this.saveShortcut(e)}}>保存</button>
|
|
1609
|
+
<button ?disabled=${this.loading||this.saving} @click=${()=>{this.toggleRecording(e.id)}}>${this.recording?.actionId===e.id?"取消录制":"录制"}</button>
|
|
1610
|
+
<button ?disabled=${this.loading||this.saving||s===null} @click=${()=>{this.setShortcutNone(e.id)}}>无</button>
|
|
1611
|
+
<button ?disabled=${this.loading||this.saving||!l} @click=${()=>{this.resetShortcut(e.id)}}>重置</button>
|
|
1612
|
+
</div>
|
|
1613
|
+
</div>
|
|
1614
|
+
</article>
|
|
1615
|
+
`}shortcutInputText(e){const t=this.drafts[e.id];if(t!==void 0)return t;const i=Ci(e.id,this.configResponse?.config.shortcuts);return i===null?"":i??e.shortcut??""}recordingHint(e){const t=this.recording;return t?.actionId!==e?"":t.tokens.length===0?"Recording: press Ctrl/⌘ or Alt with a key. Press Esc to cancel.":`Recording: ${ri(t.tokens.join(" "))}. Press another key to add a sequence, or wait to finish.`}updateDraft(e,t){this.drafts={[e]:t},this.localError=""}async saveShortcut(e){this.stopRecording();const t=this.shortcutInputText(e).trim(),i=Yi(t);if(!i.ok){this.localError=i.message;return}this.localError="",await this.saveShortcutPreference(e.id,i.shortcut)}async setShortcutNone(e){this.stopRecording(),this.localError="",await this.saveShortcutPreference(e,null)}async resetShortcut(e){this.stopRecording(),this.localError="",await this.saveShortcutPreference(e,void 0)}async saveShortcutPreference(e,t){const i={...this.configResponse?.config??{}},s=i.shortcuts??{},o=t===void 0?Wb(s,e):{...s,[e]:t};Object.keys(o).length===0?delete i.shortcuts:i.shortcuts=o,await this.onSave?.(i)}shortcutResolutions(){return new Map(so(this.actions,this.previewShortcutConfig(),{enabledOnly:!0}).map(e=>[e.action.id,e]))}previewShortcutConfig(){const e={...this.configResponse?.config.shortcuts??{}};for(const[t,i]of Object.entries(this.drafts)){const s=i.trim();if(s==="")continue;const o=Yi(s);o.ok&&(e[t]=o.shortcut)}return Object.keys(e).length===0?void 0:e}async toggleRecording(e){if(this.recording?.actionId===e){this.stopRecording();return}this.stopRecording(),this.localError="",this.recording={actionId:e,tokens:[]},this.ensureRecordingListener(),await this.updateComplete,this.focusShortcutInput(e)}focusShortcutInput(e){for(const t of this.renderRoot.querySelectorAll(".shortcut-input"))if(t.dataset.actionId===e){t.focus(),t.select();return}}armRecordingTimer(){this.clearRecordingTimer(),this.recordingTimer=window.setTimeout(()=>{this.recordingTimer=void 0,this.stopRecording()},Kn)}stopRecording(){this.clearRecordingTimer(),this.removeRecordingListener(),this.recording=void 0}clearRecordingTimer(){this.recordingTimer!==void 0&&(window.clearTimeout(this.recordingTimer),this.recordingTimer=void 0)}ensureRecordingListener(){this.recordingListenerActive||(window.addEventListener("keydown",this.onRecordKeyDown,Yr),this.recordingListenerActive=!0)}removeRecordingListener(){this.recordingListenerActive&&(window.removeEventListener("keydown",this.onRecordKeyDown,Yr),this.recordingListenerActive=!1)}};re.styles=O`
|
|
1616
|
+
:host { display: block; }
|
|
1617
|
+
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
|
|
1618
|
+
.section-heading > div { display: grid; gap: 6px; min-width: 0; }
|
|
1619
|
+
h2, h3, p { margin: 0; }
|
|
1620
|
+
h2 { font-size: 17px; line-height: 1.25; }
|
|
1621
|
+
h3 { font-size: 13px; line-height: 1.3; }
|
|
1622
|
+
p { color: var(--pi-muted); line-height: 1.45; }
|
|
1623
|
+
button, input { font: inherit; }
|
|
1624
|
+
button { border: 1px solid var(--pi-border); border-radius: 8px; background: var(--pi-surface); color: var(--pi-text); padding: 7px 9px; cursor: pointer; }
|
|
1625
|
+
button:disabled, input:disabled { opacity: .55; cursor: not-allowed; }
|
|
1626
|
+
.primary { border-color: var(--pi-accent); background: var(--pi-selection-bg); color: var(--pi-text-bright); }
|
|
1627
|
+
.secondary { flex: 0 0 auto; }
|
|
1628
|
+
.message, .loading-card, .config-path-card { border: 1px solid var(--pi-border); border-radius: 10px; background: var(--pi-surface); padding: 12px; }
|
|
1629
|
+
.message { margin-bottom: 12px; }
|
|
1630
|
+
.error-message { border-color: var(--pi-danger); color: var(--pi-danger); background: color-mix(in srgb, var(--pi-danger) 10%, var(--pi-surface)); }
|
|
1631
|
+
.success-message { border-color: var(--pi-success-border); color: var(--pi-success); background: var(--pi-success-surface); }
|
|
1632
|
+
.loading-card, .config-path-card { color: var(--pi-muted); }
|
|
1633
|
+
.config-path-card { display: grid; gap: 5px; margin-bottom: 14px; }
|
|
1634
|
+
.config-path-card span { color: var(--pi-muted); font-size: 12px; font-weight: 700; text-transform: uppercase; }
|
|
1635
|
+
code { border: 1px solid var(--pi-border-muted); border-radius: 5px; background: var(--pi-bg); padding: 1px 4px; color: var(--pi-text); font: 12px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; overflow-wrap: anywhere; }
|
|
1636
|
+
.shortcut-group { margin: 0 0 16px; }
|
|
1637
|
+
.shortcut-group h3 { margin: 0 0 8px; color: var(--pi-muted); font-size: 12px; text-transform: uppercase; }
|
|
1638
|
+
.shortcut-list { border: 1px solid var(--pi-border); border-radius: 10px; overflow: hidden; }
|
|
1639
|
+
.shortcut-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(360px, 48%); gap: 14px; align-items: start; padding: 12px; border-bottom: 1px solid var(--pi-border-muted); background: var(--pi-surface); }
|
|
1640
|
+
.shortcut-row.shadowed { background: color-mix(in srgb, var(--pi-warning) 5%, var(--pi-surface)); }
|
|
1641
|
+
.shortcut-row.shadowing { background: color-mix(in srgb, var(--pi-accent) 5%, var(--pi-surface)); }
|
|
1642
|
+
.shortcut-row:last-child { border-bottom: 0; }
|
|
1643
|
+
.shortcut-main { min-width: 0; display: grid; gap: 4px; }
|
|
1644
|
+
.shortcut-main strong, .shortcut-main small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
1645
|
+
.shortcut-main small { color: var(--pi-muted); }
|
|
1646
|
+
.shortcut-id { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
|
|
1647
|
+
.shortcut-editor { min-width: 0; display: grid; gap: 8px; }
|
|
1648
|
+
.shortcut-status { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
|
|
1649
|
+
.shortcut-status small { color: var(--pi-muted); font-size: 11px; }
|
|
1650
|
+
.shortcut-status small.custom { color: var(--pi-accent); }
|
|
1651
|
+
.shortcut-status small.disabled { color: var(--pi-warning); }
|
|
1652
|
+
.shortcut-status small.conflict { border: 1px solid currentColor; border-radius: 999px; padding: 2px 7px; }
|
|
1653
|
+
.shortcut-status small.conflict.shadowing { color: var(--pi-accent); }
|
|
1654
|
+
.shortcut-status small.conflict.shadowed { color: var(--pi-warning); }
|
|
1655
|
+
.shortcut-input-label { min-width: 0; display: grid; gap: 5px; }
|
|
1656
|
+
.shortcut-input-label span { color: var(--pi-muted); font-size: 11px; font-weight: 700; text-transform: uppercase; }
|
|
1657
|
+
input { box-sizing: border-box; width: 100%; min-width: 0; border: 1px solid var(--pi-border); border-radius: 8px; background: var(--pi-bg); color: var(--pi-text); padding: 8px 9px; outline: none; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
|
|
1658
|
+
input:focus { border-color: var(--pi-accent); box-shadow: 0 0 0 1px var(--pi-accent-border); }
|
|
1659
|
+
.shortcut-actions { display: flex; justify-content: flex-end; gap: 7px; flex-wrap: wrap; }
|
|
1660
|
+
kbd { border: 1px solid var(--pi-border); border-radius: 6px; background: var(--pi-bg); color: var(--pi-text-secondary); padding: 3px 7px; font: 12px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: nowrap; }
|
|
1661
|
+
.unassigned { color: var(--pi-muted); font-size: 12px; }
|
|
1662
|
+
.recording-hint { color: var(--pi-accent); font-size: 12px; }
|
|
1663
|
+
|
|
1664
|
+
@media (max-width: 760px) {
|
|
1665
|
+
.section-heading { display: grid; gap: 12px; }
|
|
1666
|
+
.section-heading .secondary { justify-self: start; }
|
|
1667
|
+
.shortcut-row { grid-template-columns: minmax(0, 1fr); align-items: start; }
|
|
1668
|
+
.shortcut-status, .shortcut-actions { justify-content: flex-start; }
|
|
1669
|
+
}
|
|
1670
|
+
`;ye([d({attribute:!1})],re.prototype,"actions",2);ye([d({attribute:!1})],re.prototype,"configResponse",2);ye([d({type:Boolean})],re.prototype,"loading",2);ye([d({type:Boolean})],re.prototype,"saving",2);ye([d()],re.prototype,"error",2);ye([d()],re.prototype,"savedMessage",2);ye([d({attribute:!1})],re.prototype,"onReload",2);ye([d({attribute:!1})],re.prototype,"onSave",2);ye([y()],re.prototype,"drafts",2);ye([y()],re.prototype,"localError",2);ye([y()],re.prototype,"recording",2);re=ye([D("settings-shortcuts-panel")],re);function Tb(e){return e?.active===!1?"shortcut-row shadowed":e?.active===!0&&e.shadows.length>0?"shortcut-row shadowing":"shortcut-row"}function Mb(e){return e?.active===!1?"conflict shadowed":"conflict shadowing"}function Ab(e){if(e===void 0)return;if(!e.active)return`Shadowed by ${e.shadowedBy?.action.title??"another action"}`;const t=e.shadows.length;if(t===0)return;const i=e.shadows.slice(0,2).map(o=>o.action.title).join(", "),s=t>2?`, +${String(t-2)} more`:"";return`Shadows ${String(t)} ${t===1?"action":"actions"}: ${i}${s}`}function Eb(e){const t=new Map;for(const i of[...e].sort(Db)){const s=i.group??"其他";t.set(s,[...t.get(s)??[],i])}return[...t.entries()].map(([i,s])=>({name:i,actions:s}))}function Db(e,t){return(e.group??"其他").localeCompare(t.group??"其他")||e.title.localeCompare(t.title)}function Ci(e,t){if(!(t===void 0||!Object.hasOwn(t,e)))return t[e]}function Wb(e,t){return Object.fromEntries(Object.entries(e).filter(([i])=>i!==t))}function Ob(e,t){const i=Ci(e.id,t);if(i!==null)return i??e.shortcut}function _b(e,t){const i=Ci(e.id,t);return i===null?"disabled":i!==void 0?"custom":e.shortcut===void 0||e.shortcut===""?"unassigned":"default"}function Lb(e){switch(e){case"default":return"默认";case"custom":return"配置覆盖";case"disabled":return"配置禁用";case"unassigned":return"无默认值"}}function jb(e){return e.target instanceof HTMLInputElement?e.target.value:""}var Fb=Object.defineProperty,Nb=Object.getOwnPropertyDescriptor,Se=(e,t,i,s)=>{for(var o=s>1?void 0:s?Nb(t,i):t,r=e.length-1,n;r>=0;r--)(n=e[r])&&(o=(s?n(t,i,o):n(o))||o);return s&&o&&Fb(t,i,o),o};let ne=class extends M{constructor(){super(...arguments),this.section="general",this.actions=[],this.loading=!0,this.saving=!1,this.error="",this.savedMessage=""}connectedCallback(){super.connectedCallback(),this.loadConfig()}disconnectedCallback(){this.savedMessageTimer!==void 0&&window.clearTimeout(this.savedMessageTimer),this.savedMessageTimer=void 0,super.disconnectedCallback()}render(){return c`
|
|
1671
|
+
<div class="backdrop" @mousedown=${()=>this.onClose?.()}>
|
|
1672
|
+
<section class="settings-shell" role="dialog" aria-modal="true" aria-label="PI WEB 设置" @mousedown=${e=>{e.stopPropagation()}} @keydown=${e=>{this.handleKeyDown(e)}}>
|
|
1673
|
+
<header class="settings-header">
|
|
1674
|
+
<div>
|
|
1675
|
+
<span class="eyebrow">设置</span>
|
|
1676
|
+
<h1>PI WEB</h1>
|
|
1677
|
+
</div>
|
|
1678
|
+
<button class="close-button" title="关闭设置" aria-label="关闭设置" @click=${()=>this.onClose?.()}>×</button>
|
|
1679
|
+
</header>
|
|
1680
|
+
<div class="settings-body">
|
|
1681
|
+
<nav class="settings-nav" aria-label="设置分区">
|
|
1682
|
+
${this.renderNavButton("general","通用","服务器配置")}
|
|
1683
|
+
${this.renderNavButton("plugins","插件","启用和禁用")}
|
|
1684
|
+
${this.renderNavButton("shortcuts","键盘","快捷键")}
|
|
1685
|
+
</nav>
|
|
1686
|
+
<main class="settings-content">
|
|
1687
|
+
${this.renderActiveSection()}
|
|
1688
|
+
</main>
|
|
1689
|
+
</div>
|
|
1690
|
+
</section>
|
|
1691
|
+
</div>
|
|
1692
|
+
`}renderActiveSection(){return this.section==="shortcuts"?c`
|
|
1693
|
+
<settings-shortcuts-panel
|
|
1694
|
+
.actions=${this.actions}
|
|
1695
|
+
.configResponse=${this.configResponse}
|
|
1696
|
+
.loading=${this.loading}
|
|
1697
|
+
.saving=${this.saving}
|
|
1698
|
+
.error=${this.error}
|
|
1699
|
+
.savedMessage=${this.savedMessage}
|
|
1700
|
+
.onReload=${()=>this.loadConfig()}
|
|
1701
|
+
.onSave=${e=>this.saveConfig(e)}
|
|
1702
|
+
></settings-shortcuts-panel>
|
|
1703
|
+
`:this.section==="plugins"?c`
|
|
1704
|
+
<settings-plugins-panel
|
|
1705
|
+
.configResponse=${this.configResponse}
|
|
1706
|
+
.pluginsResponse=${this.pluginsResponse}
|
|
1707
|
+
.loading=${this.loading}
|
|
1708
|
+
.saving=${this.saving}
|
|
1709
|
+
.error=${this.error}
|
|
1710
|
+
.savedMessage=${this.savedMessage}
|
|
1711
|
+
.onReload=${()=>this.loadConfig()}
|
|
1712
|
+
.onTogglePlugin=${(e,t)=>this.togglePlugin(e,t)}
|
|
1713
|
+
></settings-plugins-panel>
|
|
1714
|
+
`:c`
|
|
1715
|
+
<settings-general-panel
|
|
1716
|
+
.configResponse=${this.configResponse}
|
|
1717
|
+
.loading=${this.loading}
|
|
1718
|
+
.saving=${this.saving}
|
|
1719
|
+
.error=${this.error}
|
|
1720
|
+
.savedMessage=${this.savedMessage}
|
|
1721
|
+
.onReload=${()=>this.loadConfig()}
|
|
1722
|
+
.onSave=${e=>this.saveConfig(e)}
|
|
1723
|
+
></settings-general-panel>
|
|
1724
|
+
`}renderNavButton(e,t,i){const s=this.section===e;return c`
|
|
1725
|
+
<button class=${s?"selected":""} aria-current=${s?"page":"false"} @click=${()=>{this.navigate(e)}}>
|
|
1726
|
+
<strong>${t}</strong>
|
|
1727
|
+
<small>${i}</small>
|
|
1728
|
+
</button>
|
|
1729
|
+
`}navigate(e){this.onNavigate?.(e)}async loadConfig(){this.loading=!0,this.error="";try{const[e,t]=await Promise.all([hi.config(),Ss.plugins()]);this.configResponse=e,this.pluginsResponse=t}catch(e){this.error=`加载设置失败:${hs(e)}`}finally{this.loading=!1}}async togglePlugin(e,t){const i=this.configResponse?.config??{},s=i.plugins??{},o=s[e]??{};await this.saveConfig({...i,plugins:{...s,[e]:{...o,enabled:t}}}),await this.refreshPlugins()}async saveConfig(e){if(!this.saving){this.saving=!0,this.error="",this.savedMessage="";try{const t=await hi.saveConfig(e);this.configResponse=t,this.onConfigSaved?.(t.config),this.showSavedMessage()}catch(t){this.error=`保存配置失败:${hs(t)}`}finally{this.saving=!1}}}async refreshPlugins(){try{this.pluginsResponse=await Ss.plugins()}catch(e){this.error=`刷新插件失败:${hs(e)}`}}showSavedMessage(){this.savedMessage="配置已保存。",this.savedMessageTimer!==void 0&&window.clearTimeout(this.savedMessageTimer),this.savedMessageTimer=window.setTimeout(()=>{this.savedMessage==="配置已保存。"&&(this.savedMessage=""),this.savedMessageTimer=void 0},3e3)}handleKeyDown(e){e.key==="Escape"&&(e.preventDefault(),e.stopPropagation(),this.onClose?.())}};ne.styles=O`
|
|
1730
|
+
:host { position: fixed; inset: 0; z-index: 30; color: var(--pi-text); font: 14px system-ui, sans-serif; }
|
|
1731
|
+
.backdrop { box-sizing: border-box; width: 100%; height: 100dvh; display: grid; place-items: center; padding: max(20px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left)); background: var(--pi-overlay); overflow: hidden; }
|
|
1732
|
+
.settings-shell { width: min(980px, 100%); max-height: min(760px, 100%); min-height: min(620px, 100%); display: grid; grid-template-rows: auto minmax(0, 1fr); border: 1px solid var(--pi-border); border-radius: 14px; background: var(--pi-bg); box-shadow: 0 20px 60px var(--pi-shadow-strong); overflow: hidden; }
|
|
1733
|
+
.settings-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--pi-border); }
|
|
1734
|
+
.eyebrow { display: block; color: var(--pi-muted); font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
|
|
1735
|
+
h1 { margin: 0; font-size: 20px; line-height: 1.2; }
|
|
1736
|
+
button { border: 1px solid var(--pi-border); border-radius: 8px; background: var(--pi-surface); color: var(--pi-text); padding: 7px 9px; font: inherit; cursor: pointer; }
|
|
1737
|
+
.close-button { width: 34px; height: 34px; display: grid; place-items: center; border: 0; background: transparent; color: var(--pi-muted); padding: 0; font-size: 24px; }
|
|
1738
|
+
.close-button:hover, .close-button:focus { color: var(--pi-text); background: var(--pi-surface-hover); }
|
|
1739
|
+
.settings-body { min-height: 0; display: grid; grid-template-columns: 220px minmax(0, 1fr); }
|
|
1740
|
+
.settings-nav { min-height: 0; padding: 10px; border-right: 1px solid var(--pi-border); background: var(--pi-surface); overflow: auto; }
|
|
1741
|
+
.settings-nav button { display: grid; gap: 2px; width: 100%; margin: 0 0 6px; text-align: left; border-color: transparent; background: transparent; }
|
|
1742
|
+
.settings-nav button:hover, .settings-nav button:focus { background: var(--pi-surface-hover); }
|
|
1743
|
+
.settings-nav button.selected { border-color: var(--pi-accent); background: var(--pi-selection-bg); }
|
|
1744
|
+
.settings-nav small { color: var(--pi-muted); }
|
|
1745
|
+
.settings-content { min-width: 0; min-height: 0; overflow: auto; padding: 18px; }
|
|
1746
|
+
|
|
1747
|
+
@media (max-width: 760px) {
|
|
1748
|
+
.backdrop { padding: 0; place-items: stretch; }
|
|
1749
|
+
.settings-shell { width: 100%; height: 100dvh; max-height: none; min-height: 0; border: 0; border-radius: 0; }
|
|
1750
|
+
.settings-header { padding: max(12px, env(safe-area-inset-top)) 12px 12px; }
|
|
1751
|
+
.settings-body { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
|
|
1752
|
+
.settings-nav { display: flex; gap: 8px; padding: 8px; border-right: 0; border-bottom: 1px solid var(--pi-border); overflow-x: auto; overflow-y: hidden; }
|
|
1753
|
+
.settings-nav button { flex: 0 0 auto; width: auto; min-width: 128px; margin: 0; }
|
|
1754
|
+
.settings-content { padding: 14px 12px calc(18px + env(safe-area-inset-bottom)); }
|
|
1755
|
+
}
|
|
1756
|
+
`;Se([d({attribute:!1})],ne.prototype,"section",2);Se([d({attribute:!1})],ne.prototype,"actions",2);Se([d({attribute:!1})],ne.prototype,"onNavigate",2);Se([d({attribute:!1})],ne.prototype,"onClose",2);Se([d({attribute:!1})],ne.prototype,"onConfigSaved",2);Se([y()],ne.prototype,"configResponse",2);Se([y()],ne.prototype,"pluginsResponse",2);Se([y()],ne.prototype,"loading",2);Se([y()],ne.prototype,"saving",2);Se([y()],ne.prototype,"error",2);Se([y()],ne.prototype,"savedMessage",2);ne=Se([D("settings-dialog")],ne);function hs(e){return e instanceof Error?e.message:String(e)}var zb=Object.defineProperty,Bb=Object.getOwnPropertyDescriptor,Te=(e,t,i,s)=>{for(var o=s>1?void 0:s?Bb(t,i):t,r=e.length-1,n;r>=0;r--)(n=e[r])&&(o=(s?n(t,i,o):n(o))||o);return s&&o&&zb(t,i,o),o};let de=class extends M{constructor(){super(...arguments),this.tool="core:workspace.files",this.panels=[],this.hideToolTabs=!1,this.onSelectTool=()=>{},this.workspaceHeaderCanScrollLeft=!1,this.workspaceHeaderCanScrollRight=!1,this.onWorkspaceHeaderScroll=()=>{this.updateWorkspaceHeaderScrollState()}}firstUpdated(){this.observeWorkspaceHeaderStrip(),this.updateWorkspaceHeaderScrollState()}updated(){this.observeWorkspaceHeaderStrip(),this.updateWorkspaceHeaderScrollState()}disconnectedCallback(){this.workspaceHeaderResizeObserver?.disconnect(),this.workspaceHeaderResizeObserver=void 0,this.observedWorkspaceHeaderStrip=void 0,super.disconnectedCallback()}render(){if(this.workspace===void 0)return this.renderEmptyState(this.emptyState??{title:"选择工作区",body:"选择工作区来查看文件、Git 或终端。"});const t=this.panelContext;if(t===void 0)return this.renderEmptyState({title:"工作区工具不可用",body:"请尝试重新选择工作区。"});const i=this.panels,s=i.find(o=>o.id===this.tool)??i[0];return c`
|
|
1757
|
+
${this.hideToolTabs?null:c`
|
|
1758
|
+
<header>
|
|
1759
|
+
<div class=${this.workspaceHeaderFrameClass()}>
|
|
1760
|
+
<div class="workspace-header-strip" @scroll=${this.onWorkspaceHeaderScroll}>
|
|
1761
|
+
<div class="tabs">
|
|
1762
|
+
${i.map(o=>{const r=s?.id===o.id,n=o.badge?.(t),a=this.panelTabAriaLabel(o,n);return c`
|
|
1763
|
+
<button class=${this.panelTabClass(o,r)} title=${a} aria-label=${a} aria-pressed=${String(r)} @click=${()=>{this.onSelectTool(o.id)}}>
|
|
1764
|
+
${this.renderPanelTabContent(o,n)}
|
|
1765
|
+
</button>
|
|
1766
|
+
`})}
|
|
1767
|
+
</div>
|
|
1768
|
+
</div>
|
|
1769
|
+
</div>
|
|
1770
|
+
</header>
|
|
1771
|
+
`}
|
|
1772
|
+
${s===void 0?this.renderEmptyState({title:"没有可用的工作区工具",body:"此工作区没有可用工具。"}):c`
|
|
1773
|
+
<div class="panel-content">
|
|
1774
|
+
${s.render(t)}
|
|
1775
|
+
</div>
|
|
1776
|
+
`}
|
|
1777
|
+
`}panelTabClass(e,t){return[...e.icon===void 0?[]:["icon-tab"],...t?["selected"]:[]].join(" ")}panelTabAriaLabel(e,t){if(typeof t!="string"&&typeof t!="number")return e.title;const i=String(t).trim();return i===""?e.title:`${e.title}, ${i}`}renderPanelTabContent(e,t){return c`
|
|
1778
|
+
${e.icon===void 0?null:c`<span class="tab-custom-icon" aria-hidden="true">${e.icon}</span>`}
|
|
1779
|
+
<span class="tab-label">${e.title}</span>
|
|
1780
|
+
${this.isEmptyBadge(t)?null:c`<span class="tab-badge">${t}</span>`}
|
|
1781
|
+
`}isEmptyBadge(e){return e===void 0||e===""}renderEmptyState(e){return c`
|
|
1782
|
+
<section class="empty-state" role="status">
|
|
1783
|
+
<h2>${e.title}</h2>
|
|
1784
|
+
${e.body===void 0?null:c`<p>${e.body}</p>`}
|
|
1785
|
+
</section>
|
|
1786
|
+
`}workspaceHeaderFrameClass(){return`workspace-header-scroll-frame${this.workspaceHeaderCanScrollLeft?" can-scroll-left":""}${this.workspaceHeaderCanScrollRight?" can-scroll-right":""}`}observeWorkspaceHeaderStrip(){const e=this.workspaceHeaderStripElement();this.observedWorkspaceHeaderStrip!==e&&(this.workspaceHeaderResizeObserver?.disconnect(),this.observedWorkspaceHeaderStrip=e,this.workspaceHeaderResizeObserver=void 0,!(e===void 0||typeof ResizeObserver>"u")&&(this.workspaceHeaderResizeObserver=new ResizeObserver(()=>{this.updateWorkspaceHeaderScrollState()}),this.workspaceHeaderResizeObserver.observe(e)))}updateWorkspaceHeaderScrollState(){const e=this.workspaceHeaderStripElement(),t=e===void 0?0:Math.max(0,e.scrollWidth-e.clientWidth),i=e!==void 0&&e.scrollLeft>1,s=e!==void 0&&t-e.scrollLeft>1;this.workspaceHeaderCanScrollLeft!==i&&(this.workspaceHeaderCanScrollLeft=i),this.workspaceHeaderCanScrollRight!==s&&(this.workspaceHeaderCanScrollRight=s)}workspaceHeaderStripElement(){const e=this.workspaceHeaderStrip;return e instanceof HTMLElement?e:void 0}};de.styles=rg;Te([d({attribute:!1})],de.prototype,"workspace",2);Te([d({attribute:!1})],de.prototype,"panelContext",2);Te([d({attribute:!1})],de.prototype,"emptyState",2);Te([d()],de.prototype,"tool",2);Te([d({attribute:!1})],de.prototype,"panels",2);Te([d({type:Boolean})],de.prototype,"hideToolTabs",2);Te([d({attribute:!1})],de.prototype,"onSelectTool",2);Te([B(".workspace-header-strip")],de.prototype,"workspaceHeaderStrip",2);Te([y()],de.prototype,"workspaceHeaderCanScrollLeft",2);Te([y()],de.prototype,"workspaceHeaderCanScrollRight",2);de=Te([D("workspace-panel")],de);var Ub=Object.defineProperty,Hb=Object.getOwnPropertyDescriptor,xe=(e,t,i,s)=>{for(var o=s>1?void 0:s?Hb(t,i):t,r=e.length-1,n;r>=0;r--)(n=e[r])&&(o=(s?n(t,i,o):n(o))||o);return s&&o&&Ub(t,i,o),o};let ae=class extends M{constructor(){super(...arguments),this.machines=[],this.canScrollLeft=!1,this.canScrollRight=!1,this.onContextScroll=()=>{this.updateScrollState()}}disconnectedCallback(){this.contextItemsResizeObserver?.disconnect(),this.contextItemsResizeObserver=void 0,this.observedContextItems=void 0,super.disconnectedCallback()}firstUpdated(){this.observeContextItems(),this.updateScrollState()}updated(){this.observeContextItems(),this.updateScrollState()}render(){const e=qb(this.machines),t=Kb(this.machine),i=Gb(this.project),s=Qb(this.workspace),o=Xb(this.session);return c`
|
|
1787
|
+
<nav class=${this.contextBarClass()} aria-label="当前位置">
|
|
1788
|
+
<span class="context-bar-label">位置</span>
|
|
1789
|
+
<ol class="context-items" @scroll=${this.onContextScroll}>
|
|
1790
|
+
${e?c`
|
|
1791
|
+
<li class="context-item">
|
|
1792
|
+
<button type="button" class=${this.machine===void 0?"context-chip empty":"context-chip"} title=${Vb(this.machine)} aria-label=${`机器:${t}。打开机器选择。`} @click=${()=>{this.onOpenSection?.("machines")}}>
|
|
1793
|
+
<span class="context-kind">机器</span>
|
|
1794
|
+
<span class="context-value">${t}</span>
|
|
1795
|
+
</button>
|
|
1796
|
+
</li>
|
|
1797
|
+
`:null}
|
|
1798
|
+
<li class="context-item">
|
|
1799
|
+
<button type="button" class=${this.project===void 0?"context-chip empty":"context-chip"} title=${Jb(this.project)} aria-label=${`项目:${i}。打开项目选择。`} @click=${()=>{this.onOpenSection?.("projects")}}>
|
|
1800
|
+
<span class="context-kind">项目</span>
|
|
1801
|
+
<span class="context-value">${i}</span>
|
|
1802
|
+
</button>
|
|
1803
|
+
</li>
|
|
1804
|
+
<li class="context-item">
|
|
1805
|
+
<button type="button" class=${this.workspace===void 0?"context-chip empty":"context-chip"} title=${Zb(this.workspace)} aria-label=${`工作区:${s}。打开工作区选择。`} @click=${()=>{this.onOpenSection?.("workspaces")}}>
|
|
1806
|
+
<span class="context-kind">工作区</span>
|
|
1807
|
+
<span class="context-value">${s}</span>
|
|
1808
|
+
</button>
|
|
1809
|
+
</li>
|
|
1810
|
+
<li class="context-item">
|
|
1811
|
+
<button type="button" class=${this.session===void 0?"context-chip empty":"context-chip"} title=${Yb(this.session)} aria-label=${`会话:${o}。打开会话选择。`} @click=${()=>{this.onOpenSection?.("sessions")}}>
|
|
1812
|
+
<span class="context-kind">会话</span>
|
|
1813
|
+
<span class="context-value">${o}</span>
|
|
1814
|
+
</button>
|
|
1815
|
+
</li>
|
|
1816
|
+
</ol>
|
|
1817
|
+
${this.hasContextActions()?c`<div class="context-actions">${this.renderActionsButton()}${this.refreshControl}</div>`:null}
|
|
1818
|
+
</nav>
|
|
1819
|
+
`}renderActionsButton(){return this.onShowActions===void 0?null:c`
|
|
1820
|
+
<button type="button" class="context-action-button" title="显示操作" aria-label="显示操作" @click=${e=>{e.stopPropagation(),this.onShowActions?.()}}>
|
|
1821
|
+
<svg class="context-action-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false">
|
|
1822
|
+
<path d="M13 2 4 14h7l-1 8 10-13h-7V2Z"></path>
|
|
1823
|
+
</svg>
|
|
1824
|
+
</button>
|
|
1825
|
+
`}contextBarClass(){const e=["context-bar"];return this.hasContextActions()&&e.push("has-context-actions"),this.refreshControl!==void 0&&this.onShowActions!==void 0&&e.push("has-context-actions-double"),this.canScrollLeft&&e.push("can-scroll-left"),this.canScrollRight&&e.push("can-scroll-right"),e.join(" ")}hasContextActions(){return this.refreshControl!==void 0||this.onShowActions!==void 0}observeContextItems(){const e=this.contextItemsElement();this.observedContextItems!==e&&(this.contextItemsResizeObserver?.disconnect(),this.observedContextItems=e,this.contextItemsResizeObserver=void 0,!(e===void 0||typeof ResizeObserver>"u")&&(this.contextItemsResizeObserver=new ResizeObserver(()=>{this.updateScrollState()}),this.contextItemsResizeObserver.observe(e)))}updateScrollState(){const e=this.contextItemsElement(),t=e===void 0?0:Math.max(0,e.scrollWidth-e.clientWidth),i=e!==void 0&&e.scrollLeft>1,s=e!==void 0&&t-e.scrollLeft>1;this.canScrollLeft!==i&&(this.canScrollLeft=i),this.canScrollRight!==s&&(this.canScrollRight=s)}contextItemsElement(){const e=this.contextItems;return e instanceof HTMLElement?e:void 0}};ae.styles=O`
|
|
1826
|
+
/* Keep the refresh menu in this shadow tree above the following mobile tab strip. */
|
|
1827
|
+
:host { position: relative; z-index: 20; flex: 0 0 auto; min-width: 0; }
|
|
1828
|
+
.context-bar { position: relative; flex: 0 0 auto; min-width: 0; display: flex; align-items: center; gap: 0; padding: 6px 0; border-bottom: 1px solid var(--pi-border-muted); background: var(--pi-bg); }
|
|
1829
|
+
.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; }
|
|
1830
|
+
.context-bar::before { left: 0; background: linear-gradient(90deg, color-mix(in srgb, var(--pi-shadow-strong) 55%, transparent) 0%, transparent 100%); }
|
|
1831
|
+
.context-bar::after { right: 0; background: linear-gradient(270deg, color-mix(in srgb, var(--pi-shadow-strong) 55%, transparent) 0%, transparent 100%); }
|
|
1832
|
+
.context-bar.can-scroll-left::before, .context-bar.can-scroll-right::after { opacity: 1; }
|
|
1833
|
+
.context-bar-label { display: none; }
|
|
1834
|
+
.context-items { flex: 1 1 auto; min-width: 0; display: flex; align-items: stretch; gap: 5px; margin: 0; padding: 0 8px; list-style: none; overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain; scroll-padding-inline: 8px; scrollbar-width: thin; }
|
|
1835
|
+
.context-bar.has-context-actions .context-items { padding-right: 58px; scroll-padding-inline: 8px 58px; }
|
|
1836
|
+
.context-bar.has-context-actions-double .context-items { padding-right: 102px; scroll-padding-inline: 8px 102px; }
|
|
1837
|
+
.context-item { flex: 0 0 auto; min-width: 0; display: flex; }
|
|
1838
|
+
.context-actions { position: absolute; top: 6px; right: 0; bottom: 6px; z-index: 3; display: flex; align-items: center; gap: 6px; padding: 0 8px; background: var(--pi-bg); pointer-events: none; }
|
|
1839
|
+
.context-actions::before { content: ""; position: absolute; top: 0; bottom: 0; left: -24px; z-index: 0; width: 24px; background: linear-gradient(90deg, transparent, var(--pi-bg)); pointer-events: none; }
|
|
1840
|
+
app-refresh-control, .context-action-button { position: relative; z-index: 1; pointer-events: auto; }
|
|
1841
|
+
.context-action-button { box-sizing: border-box; width: 36px; height: 36px; display: grid; place-items: center; border: 1px solid var(--pi-border); border-radius: 999px; background: var(--pi-surface); color: var(--pi-text); padding: 0; line-height: 1; }
|
|
1842
|
+
.context-action-button:hover, .context-action-button:focus-visible { border-color: var(--pi-accent); background: var(--pi-selection-bg); }
|
|
1843
|
+
.context-action-icon { width: 18px; height: 18px; fill: currentColor; pointer-events: none; }
|
|
1844
|
+
.context-chip { flex: 0 0 auto; min-width: 0; display: inline-flex; align-items: baseline; gap: 5px; border: 1px solid var(--pi-border-muted); border-radius: 999px; background: var(--pi-surface); color: var(--pi-text); padding: 4px 8px; font: inherit; text-align: left; }
|
|
1845
|
+
.context-chip:hover { background: var(--pi-surface-hover); }
|
|
1846
|
+
.context-chip:focus-visible { outline: 2px solid var(--pi-accent); outline-offset: 2px; }
|
|
1847
|
+
.context-chip.empty { border-style: dashed; color: var(--pi-muted); }
|
|
1848
|
+
.context-kind { display: none; }
|
|
1849
|
+
.context-value { min-width: 0; overflow: visible; text-overflow: clip; white-space: nowrap; }
|
|
1850
|
+
button { cursor: pointer; }
|
|
1851
|
+
`;xe([d({attribute:!1})],ae.prototype,"machines",2);xe([d({attribute:!1})],ae.prototype,"machine",2);xe([d({attribute:!1})],ae.prototype,"project",2);xe([d({attribute:!1})],ae.prototype,"workspace",2);xe([d({attribute:!1})],ae.prototype,"session",2);xe([d({attribute:!1})],ae.prototype,"refreshControl",2);xe([d({attribute:!1})],ae.prototype,"onOpenSection",2);xe([d({attribute:!1})],ae.prototype,"onShowActions",2);xe([B(".context-items")],ae.prototype,"contextItems",2);xe([y()],ae.prototype,"canScrollLeft",2);xe([y()],ae.prototype,"canScrollRight",2);ae=xe([D("app-context-bar")],ae);function qb(e){return e.length>1}function Kb(e){return e===void 0?"未选择机器":`${e.name}${e.kind==="remote"?" · 远程":""}`}function Vb(e){return e===void 0?"未选择机器":e.baseUrl??e.name}function Gb(e){return e?.name??"未选择项目"}function Jb(e){return e===void 0?"未选择项目":`${e.name} — ${e.path}`}function Qb(e){return e===void 0?"未选择工作区":`${e.label}${e.isMain?" · 主工作区":""} · ${e.path}`}function Zb(e){return e===void 0?"未选择工作区":`${e.label}${e.isMain?" · 主工作区":""} — ${e.path}`}function Xb(e){const t=e?.name?.trim(),i=e?.firstMessage.trim();return t!==void 0&&t!==""?t:i!==void 0&&i!==""?i:e?.id.slice(0,8)??"未选择会话"}function Yb(e){return e===void 0?"未选择会话":e.path}var ew=Object.defineProperty,tw=Object.getOwnPropertyDescriptor,tt=(e,t,i,s)=>{for(var o=s>1?void 0:s?tw(t,i):t,r=e.length-1,n;r>=0;r--)(n=e[r])&&(o=(s?n(t,i,o):n(o))||o);return s&&o&&ew(t,i,o),o};let Le=class extends M{constructor(){super(...arguments),this.tabs=[],this.selectedView="chat",this.canScrollLeft=!1,this.canScrollRight=!1,this.onMobileTabsScroll=()=>{this.updateScrollState()}}disconnectedCallback(){this.mobileTabsResizeObserver?.disconnect(),this.mobileTabsResizeObserver=void 0,this.observedMobileTabs=void 0,super.disconnectedCallback()}firstUpdated(){this.observeMobileTabs(),this.updateScrollState()}updated(){this.observeMobileTabs(),this.updateScrollState()}render(){const e=this.fallbackLabels();return c`
|
|
1852
|
+
<div class=${this.frameClass()}>
|
|
1853
|
+
<div class="mobile-tabs" @scroll=${this.onMobileTabsScroll}>
|
|
1854
|
+
${this.tabs.map(t=>{const i=this.selectedView===t.id;return c`
|
|
1855
|
+
<button class=${this.tabClass(t)} title=${t.label} aria-label=${this.tabAriaLabel(t)} aria-pressed=${String(i)} @click=${()=>{this.onSelect?.(t.id)}}>
|
|
1856
|
+
${this.renderTabMark(t,e)}
|
|
1857
|
+
<span class="tab-label">${t.label}</span>
|
|
1858
|
+
${this.isEmptyBadge(t.badge)?null:c`<span class="tab-badge">${t.badge}</span>`}
|
|
1859
|
+
</button>
|
|
1860
|
+
`})}
|
|
1861
|
+
</div>
|
|
1862
|
+
</div>
|
|
1863
|
+
`}frameClass(){return`mobile-tabs-frame${this.canScrollLeft?" can-scroll-left":""}${this.canScrollRight?" can-scroll-right":""}`}tabClass(e){return[...e.className===void 0?[]:[e.className],...this.selectedView===e.id?["selected"]:[]].join(" ")}tabAriaLabel(e){if(typeof e.badge!="string"&&typeof e.badge!="number")return e.label;const t=String(e.badge).trim();return t===""?e.label:`${e.label}, ${t}`}isEmptyBadge(e){return e===void 0||e===""}renderTabMark(e,t){return e.icon===void 0?c`<span class="tab-fallback" aria-hidden="true">${t.get(e.id)??this.initialsLabel(e.label)}</span>`:vu(e.icon)}fallbackLabels(){const e=this.tabs.filter(s=>s.icon===void 0),t=new Map;for(const s of e){const o=this.initialsLabel(s.label);t.set(o,(t.get(o)??0)+1)}const i=new Map;for(const s of e){const o=this.initialsLabel(s.label);i.set(s.id,(t.get(o)??0)>1?this.fullFallbackLabel(s.label):o)}return i}initialsLabel(e){const i=(e.match(/[\p{L}\p{N}]+/gu)??[]).map(s=>Array.from(s)[0]??"").join("").toLocaleUpperCase();return i===""?"?":i}fullFallbackLabel(e){const t=e.trim();return t===""?"?":t}observeMobileTabs(){const e=this.mobileTabsElement();this.observedMobileTabs!==e&&(this.mobileTabsResizeObserver?.disconnect(),this.observedMobileTabs=e,this.mobileTabsResizeObserver=void 0,!(e===void 0||typeof ResizeObserver>"u")&&(this.mobileTabsResizeObserver=new ResizeObserver(()=>{this.updateScrollState()}),this.mobileTabsResizeObserver.observe(e)))}updateScrollState(){const e=this.mobileTabsElement(),t=e===void 0?0:Math.max(0,e.scrollWidth-e.clientWidth),i=e!==void 0&&e.scrollLeft>1,s=e!==void 0&&t-e.scrollLeft>1;this.canScrollLeft!==i&&(this.canScrollLeft=i),this.canScrollRight!==s&&(this.canScrollRight=s)}mobileTabsElement(){const e=this.mobileTabs;return e instanceof HTMLElement?e:void 0}};Le.styles=O`
|
|
1864
|
+
:host { flex: 0 0 auto; min-width: 0; }
|
|
1865
|
+
.mobile-tabs-frame { position: relative; display: flex; flex: 0 0 auto; min-width: 0; border-bottom: 1px solid var(--pi-border); background: var(--pi-bg); }
|
|
1866
|
+
.mobile-tabs-frame::before, .mobile-tabs-frame::after { content: ""; position: absolute; top: 0; bottom: 0; z-index: 2; width: 20px; opacity: 0; pointer-events: none; transition: opacity .15s ease; }
|
|
1867
|
+
.mobile-tabs-frame::before { left: 0; background: linear-gradient(90deg, color-mix(in srgb, var(--pi-shadow-strong) 55%, transparent) 0%, transparent 100%); }
|
|
1868
|
+
.mobile-tabs-frame::after { right: 0; background: linear-gradient(270deg, color-mix(in srgb, var(--pi-shadow-strong) 55%, transparent) 0%, transparent 100%); }
|
|
1869
|
+
.mobile-tabs-frame.can-scroll-left::before, .mobile-tabs-frame.can-scroll-right::after { opacity: 1; }
|
|
1870
|
+
.mobile-tabs { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: 6px; padding: 8px; overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain; scrollbar-width: thin; }
|
|
1871
|
+
.mobile-tabs button { flex: 0 0 auto; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
|
|
1872
|
+
.mobile-tabs .navigation-tab { display: none; }
|
|
1873
|
+
.mobile-tabs button.selected { border-color: var(--pi-accent); background: var(--pi-selection-bg); }
|
|
1874
|
+
.tab-icon { flex: 0 0 auto; width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
|
|
1875
|
+
.tab-custom-icon { flex: 0 0 auto; width: 18px; height: 18px; display: inline-grid; place-items: center; color: currentColor; pointer-events: none; }
|
|
1876
|
+
.tab-custom-icon svg { width: 18px; height: 18px; pointer-events: none; }
|
|
1877
|
+
.tab-fallback { display: none; font-weight: 650; letter-spacing: .01em; pointer-events: none; }
|
|
1878
|
+
.tab-label { min-width: 0; }
|
|
1879
|
+
.tab-badge { flex: 0 0 auto; display: inline-block; min-width: 14px; margin-left: 0; border: 1px solid var(--pi-success-border); border-radius: 999px; background: var(--pi-success-surface); color: var(--pi-success); padding: 0 5px; font-size: 11px; line-height: 16px; text-align: center; }
|
|
1880
|
+
button { border: 1px solid var(--pi-border); border-radius: 8px; background: var(--pi-surface); color: var(--pi-text); padding: 7px 9px; cursor: pointer; }
|
|
1881
|
+
@media (max-width: 760px) {
|
|
1882
|
+
.mobile-tabs { gap: 4px; padding: 6px 8px; }
|
|
1883
|
+
.mobile-tabs button { min-width: 40px; height: 36px; justify-content: center; gap: 4px; padding: 0 8px; }
|
|
1884
|
+
.mobile-tabs .navigation-tab { display: inline-flex; }
|
|
1885
|
+
.tab-fallback { display: inline-block; }
|
|
1886
|
+
.tab-label { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0; }
|
|
1887
|
+
.tab-badge { min-width: 13px; padding: 0 4px; font-size: 10px; line-height: 13px; }
|
|
1888
|
+
}
|
|
1889
|
+
`;tt([d({attribute:!1})],Le.prototype,"tabs",2);tt([d({attribute:!1})],Le.prototype,"selectedView",2);tt([d({attribute:!1})],Le.prototype,"onSelect",2);tt([B(".mobile-tabs")],Le.prototype,"mobileTabs",2);tt([y()],Le.prototype,"canScrollLeft",2);tt([y()],Le.prototype,"canScrollRight",2);Le=tt([D("app-mobile-main-tabs")],Le);var iw=Object.defineProperty,sw=Object.getOwnPropertyDescriptor,he=(e,t,i,s)=>{for(var o=s>1?void 0:s?sw(t,i):t,r=e.length-1,n;r>=0;r--)(n=e[r])&&(o=(s?n(t,i,o):n(o))||o);return s&&o&&iw(t,i,o),o};let te=class extends M{constructor(){super(...arguments),this.machines=[],this.statuses={},this.activities={},this.open=!1,this.menuStyle="",this.actionMenuStyle="",this.onDocumentClick=e=>{e.composedPath().includes(this)||(this.open=!1,this.openActionsMachineId=void 0)}}connectedCallback(){super.connectedCallback(),document.addEventListener("click",this.onDocumentClick)}disconnectedCallback(){document.removeEventListener("click",this.onDocumentClick),super.disconnectedCallback()}updated(e){e.has("machines")&&this.open&&this.selectedMachine()===void 0&&(this.open=!1),e.has("machines")&&this.openActionsMachineId!==void 0&&!this.machines.some(t=>t.id===this.openActionsMachineId)&&(this.openActionsMachineId=void 0)}async focusSelectedOrFirst(){const e=this.switcherButton();return e===null?!1:await this.openMenuAndFocusOption(e)}render(){const e=this.selectedMachine();if(e===void 0)return null;const t=us(e,this.statuses),i=e.name;return c`
|
|
1890
|
+
<div class="machine-switcher">
|
|
1891
|
+
<button
|
|
1892
|
+
type="button"
|
|
1893
|
+
class="machine-switcher-button"
|
|
1894
|
+
title=${tn(e)}
|
|
1895
|
+
aria-label=${`Machine: ${i}. Switch machine.`}
|
|
1896
|
+
aria-expanded=${String(this.open)}
|
|
1897
|
+
@click=${s=>{this.toggleMenu(s.currentTarget)}}
|
|
1898
|
+
@keydown=${s=>{this.handleSwitcherButtonKeydown(s)}}
|
|
1899
|
+
>
|
|
1900
|
+
${this.renderActivity(e)}
|
|
1901
|
+
<span class="machine-switcher-text">
|
|
1902
|
+
<span class="machine-switcher-kicker">Machine</span>
|
|
1903
|
+
<span class="machine-switcher-label">${i}</span>
|
|
1904
|
+
</span>
|
|
1905
|
+
<span class=${`machine-status ${t}`}>${en(t)}</span>
|
|
1906
|
+
<span class="machine-chevron" aria-hidden="true">▾</span>
|
|
1907
|
+
</button>
|
|
1908
|
+
${this.open?c`
|
|
1909
|
+
<div class="machine-switcher-menu" style=${this.menuStyle} @click=${s=>{s.stopPropagation()}}>
|
|
1910
|
+
${this.machines.map(s=>this.renderMachineOption(s))}
|
|
1911
|
+
</div>
|
|
1912
|
+
`:null}
|
|
1913
|
+
</div>
|
|
1914
|
+
`}renderMachineOption(e){const t=this.selected?.id===e.id,i=us(e,this.statuses),s=wa(e)&&this.onRemove!==void 0,o=this.openActionsMachineId===e.id;return c`
|
|
1915
|
+
<div class=${`machine-option ${t?"selected":""} ${s?"":"no-actions"}`}>
|
|
1916
|
+
<button
|
|
1917
|
+
type="button"
|
|
1918
|
+
class="machine-option-main"
|
|
1919
|
+
title=${tn(e)}
|
|
1920
|
+
data-machine-id=${e.id}
|
|
1921
|
+
@click=${()=>{this.select(e)}}
|
|
1922
|
+
@keydown=${r=>{this.handleMachineOptionKeydown(r)}}
|
|
1923
|
+
>
|
|
1924
|
+
<span class="machine-option-name">${this.renderActivity(e)}<span>${e.name}</span></span>
|
|
1925
|
+
<small>${e.kind==="local"?"Local Pi Web":e.baseUrl??"Remote Pi Web"} · ${en(i)}</small>
|
|
1926
|
+
</button>
|
|
1927
|
+
${s?c`
|
|
1928
|
+
<div class="machine-option-actions">
|
|
1929
|
+
<button
|
|
1930
|
+
type="button"
|
|
1931
|
+
class="machine-option-actions-toggle"
|
|
1932
|
+
title="Machine actions"
|
|
1933
|
+
aria-label=${`Actions for ${e.name}`}
|
|
1934
|
+
aria-expanded=${String(o)}
|
|
1935
|
+
@click=${r=>{r.stopPropagation(),this.toggleActionsMenu(e.id,r.currentTarget)}}
|
|
1936
|
+
>⋯</button>
|
|
1937
|
+
${o?c`
|
|
1938
|
+
<div class="machine-option-actions-panel" style=${this.actionMenuStyle} @click=${r=>{r.stopPropagation()}}>
|
|
1939
|
+
<button class="danger" title=${`Remove ${e.name}`} @click=${()=>{this.removeMachine(e)}}>Remove</button>
|
|
1940
|
+
</div>
|
|
1941
|
+
`:null}
|
|
1942
|
+
</div>
|
|
1943
|
+
`:null}
|
|
1944
|
+
</div>
|
|
1945
|
+
`}renderActivity(e){const t=us(e,this.statuses);if(t==="offline"||t==="error")return;const i=da(this.activities[e.id]);return ua(i,i==="terminal"?"Machine terminal active":"Machine active")}selectedMachine(){return this.selected??this.machines.find(e=>e.id==="local")??this.machines[0]}switcherButton(){return this.renderRoot.querySelector(".machine-switcher-button")}handleSwitcherButtonKeydown(e){if(e.key==="ArrowDown"||e.key==="ArrowUp"){e.preventDefault(),e.stopPropagation(),this.openMenuAndFocusOption(e.currentTarget);return}if(e.key==="ArrowRight"&&this.onFocusNextSection!==void 0){e.preventDefault(),e.stopPropagation(),this.onFocusNextSection();return}e.key==="Escape"&&this.onCancelKeyboardNavigation!==void 0&&(e.preventDefault(),e.stopPropagation(),this.onCancelKeyboardNavigation())}handleMachineOptionKeydown(e){if(e.key==="ArrowUp"){this.focusRelativeMachineOption(e.currentTarget,-1,e);return}if(e.key==="ArrowDown"){this.focusRelativeMachineOption(e.currentTarget,1,e);return}if(e.key==="Home"){this.focusIndexedMachineOption(0,e);return}if(e.key==="End"){this.focusIndexedMachineOption(-1,e);return}if(e.key==="ArrowRight"&&this.onFocusNextSection!==void 0){e.preventDefault(),e.stopPropagation(),this.open=!1,this.onFocusNextSection();return}(e.key==="ArrowLeft"||e.key==="Escape")&&(e.preventDefault(),e.stopPropagation(),this.open=!1,this.updateComplete.then(()=>{this.focusSwitcherButton()}))}toggleMenu(e){this.menuStyle=sn(e),this.open=!this.open,this.openActionsMachineId=void 0}focusSwitcherButton(){const e=this.switcherButton();return e===null?!1:(e.focus(),!0)}async openMenuAndFocusOption(e){return this.menuStyle=sn(e),this.open=!0,this.openActionsMachineId=void 0,await this.updateComplete,this.focusSelectedMachineOption()}focusSelectedMachineOption(){const e=this.renderRoot.querySelector(".machine-option.selected .machine-option-main"),t=this.machineOptionButtons()[0],i=e??t;return i===void 0?!1:(i.focus(),i.scrollIntoView({block:"nearest"}),!0)}focusRelativeMachineOption(e,t,i){i.preventDefault(),i.stopPropagation();const s=this.machineOptionButtons();if(s.length===0||!(e instanceof HTMLElement))return;const o=s.indexOf(e);o<0||this.focusMachineOptionAt(o+t)}focusIndexedMachineOption(e,t){t.preventDefault(),t.stopPropagation(),this.focusMachineOptionAt(e<0?this.machineOptionButtons().length-1:e)}focusMachineOptionAt(e){const t=this.machineOptionButtons(),i=t[Math.min(Math.max(e,0),t.length-1)];i?.focus(),i?.scrollIntoView({block:"nearest"})}machineOptionButtons(){return Array.from(this.renderRoot.querySelectorAll(".machine-option-main"))}toggleActionsMenu(e,t){if(this.openActionsMachineId===e){this.openActionsMachineId=void 0;return}this.actionMenuStyle=Bt(t,{constrainTo:"viewport"}),this.openActionsMachineId=e}select(e){this.open=!1,this.openActionsMachineId=void 0,this.onSelect?.(e)}removeMachine(e){this.open=!1,this.openActionsMachineId=void 0,this.onRemove?.(e)}};te.styles=O`
|
|
1946
|
+
:host { min-width: 0; display: block; }
|
|
1947
|
+
.machine-switcher { min-width: 0; }
|
|
1948
|
+
.machine-switcher-button { box-sizing: border-box; width: 100%; min-width: 0; display: flex; align-items: center; gap: 6px; border: 1px solid var(--pi-border); border-radius: 999px; background: var(--pi-surface); color: var(--pi-text); padding: 5px 8px; cursor: pointer; text-align: left; }
|
|
1949
|
+
.machine-switcher-button:hover, .machine-switcher-button:focus-visible { border-color: var(--pi-accent); background: var(--pi-selection-bg); }
|
|
1950
|
+
.machine-switcher-text { flex: 1 1 auto; min-width: 0; display: grid; gap: 1px; }
|
|
1951
|
+
.machine-switcher-kicker { color: var(--pi-muted); font-size: 10px; line-height: 1; text-transform: uppercase; letter-spacing: .02em; }
|
|
1952
|
+
.machine-switcher-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; font-weight: 600; line-height: 1.2; }
|
|
1953
|
+
.machine-status { flex: 0 0 auto; color: var(--pi-muted); font-size: 11px; }
|
|
1954
|
+
.machine-status.online { color: var(--pi-success); }
|
|
1955
|
+
.machine-status.offline, .machine-status.error { color: var(--pi-danger); }
|
|
1956
|
+
.machine-chevron { flex: 0 0 auto; color: var(--pi-muted); font-size: 11px; }
|
|
1957
|
+
.activity-indicator { flex: 0 0 auto; display: inline-block; width: 7px; height: 7px; background: var(--pi-success); animation: pulse 1s ease-in-out infinite; }
|
|
1958
|
+
.activity-indicator.session { border-radius: 50%; background: var(--pi-success); }
|
|
1959
|
+
.activity-indicator.terminal { border-radius: 2px; background: var(--pi-accent); }
|
|
1960
|
+
.activity-indicator.sending { border-radius: 50%; background: var(--pi-warning); }
|
|
1961
|
+
.machine-switcher-menu { position: fixed; z-index: 10000; box-sizing: border-box; min-width: min(280px, calc(100vw - 16px)); overflow: auto; padding: 4px; border: 1px solid var(--pi-border); border-radius: 10px; background: var(--pi-surface); box-shadow: 0 8px 24px var(--pi-shadow); }
|
|
1962
|
+
.machine-option { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px; align-items: stretch; margin: 2px 0; }
|
|
1963
|
+
.machine-option.no-actions { grid-template-columns: minmax(0, 1fr); }
|
|
1964
|
+
.machine-option-main, .machine-option-actions-toggle, .machine-option-actions-panel button { border: 0; border-radius: 7px; background: transparent; color: var(--pi-text); cursor: pointer; }
|
|
1965
|
+
.machine-option-main { min-width: 0; display: grid; gap: 2px; padding: 7px 8px; text-align: left; }
|
|
1966
|
+
.machine-option-name { min-width: 0; display: flex; align-items: baseline; gap: 6px; }
|
|
1967
|
+
.machine-option-name span:last-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
1968
|
+
.machine-option-main small { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--pi-muted); }
|
|
1969
|
+
.machine-option-actions { position: relative; align-self: stretch; }
|
|
1970
|
+
.machine-option-actions-toggle { display: grid; place-items: center; height: 100%; min-width: 32px; padding: 0; color: var(--pi-muted); }
|
|
1971
|
+
.machine-option-actions-panel { position: fixed; z-index: 10001; box-sizing: border-box; min-width: min(120px, calc(100vw - 16px)); overflow: auto; padding: 4px; border: 1px solid var(--pi-border); border-radius: 8px; background: var(--pi-surface); box-shadow: 0 8px 24px var(--pi-shadow); }
|
|
1972
|
+
.machine-option-actions-panel button { display: block; width: 100%; padding: 7px 9px; text-align: left; white-space: nowrap; }
|
|
1973
|
+
.machine-option-actions-panel button.danger { color: var(--pi-danger); }
|
|
1974
|
+
.machine-option-main:hover, .machine-option-main:focus-visible, .machine-option-actions-toggle:hover, .machine-option-actions-toggle:focus-visible, .machine-option.selected .machine-option-main { background: var(--pi-selection-bg); }
|
|
1975
|
+
.machine-option-actions-panel button:hover, .machine-option-actions-panel button:focus-visible { background: var(--pi-selection-bg); }
|
|
1976
|
+
.machine-option-actions-panel button.danger:hover, .machine-option-actions-panel button.danger:focus-visible { background: color-mix(in srgb, var(--pi-danger) 14%, transparent); }
|
|
1977
|
+
@keyframes pulse { 0%, 100% { opacity: .55; } 50% { opacity: 1; } }
|
|
1978
|
+
`;he([d({attribute:!1})],te.prototype,"machines",2);he([d({attribute:!1})],te.prototype,"selected",2);he([d({attribute:!1})],te.prototype,"statuses",2);he([d({attribute:!1})],te.prototype,"activities",2);he([d({attribute:!1})],te.prototype,"onSelect",2);he([d({attribute:!1})],te.prototype,"onRemove",2);he([d({attribute:!1})],te.prototype,"onFocusNextSection",2);he([d({attribute:!1})],te.prototype,"onCancelKeyboardNavigation",2);he([y()],te.prototype,"open",2);he([y()],te.prototype,"menuStyle",2);he([y()],te.prototype,"openActionsMachineId",2);he([y()],te.prototype,"actionMenuStyle",2);te=he([D("machine-switcher")],te);function us(e,t){return t[e.id]?.status??e.status??"unknown"}function en(e){return e==="online"?"online":e==="offline"?"offline":e==="error"?"error":"unknown"}function tn(e){return e.baseUrl??e.name}function sn(e){if(typeof HTMLElement>"u"||typeof window>"u"||!(e instanceof HTMLElement))return"";const t=e.getBoundingClientRect(),i=8,s=Math.min(280,Math.max(0,window.innerWidth-i*2)),o=Math.min(Math.max(i,t.left),Math.max(i,window.innerWidth-i-s)),r=Math.max(0,window.innerHeight-t.bottom-i);return[`top: ${Yt(t.bottom)};`,`left: ${Yt(o)};`,`width: ${Yt(s)};`,`max-height: ${Yt(r)};`].join(" ")}function Yt(e){return`${String(Math.round(e))}px`}var ow=Object.defineProperty,rw=Object.getOwnPropertyDescriptor,k=(e,t,i,s)=>{for(var o=s>1?void 0:s?rw(t,i):t,r=e.length-1,n;r>=0;r--)(n=e[r])&&(o=(s?n(t,i,o):n(o))||o);return s&&o&&ow(t,i,o),o};let x=class extends M{constructor(){super(...arguments),this.machines=[],this.machineStatuses={},this.machineActivities={},this.projects=[],this.workspaces=[],this.sessions=[],this.workspaceActivities={},this.sessionActivities={},this.sessionStatuses={},this.sendingPrompts={},this.workspacesByProjectId={},this.deletingWorkspaceIds=[],this.workspaceLabelItems=()=>[],this.collapsible=!1,this.compact=!1,this.machinesCollapsed=!1,this.projectsCollapsed=!1,this.workspacesCollapsed=!1,this.sessionsCollapsed=!1,this.canStartSession=!1,this.canDeleteArchivedSessions=!1,this.canReloadSessions=!1,this.archivedDeleteUnavailableMessage="Update and restart Pi-Web on this machine to delete archived sessions."}async focusSection(e){switch(await this.updateComplete,e){case"machines":return await this.focusNavigableSection(this.compact?this.machineList:this.machineSwitcher);case"projects":return await this.focusNavigableSection(this.projectList);case"workspaces":return await this.focusNavigableSection(this.workspaceList);case"sessions":return await this.focusNavigableSection(this.sessionList)}}render(){return c`
|
|
1979
|
+
<header>
|
|
1980
|
+
<strong>PI WEB</strong>
|
|
1981
|
+
${Ti(this.machines)?c`
|
|
1982
|
+
<machine-switcher
|
|
1983
|
+
.machines=${this.machines}
|
|
1984
|
+
.selected=${this.selectedMachine}
|
|
1985
|
+
.statuses=${this.machineStatuses}
|
|
1986
|
+
.activities=${this.machineActivities}
|
|
1987
|
+
.onSelect=${e=>this.onSelectMachine?.(e)}
|
|
1988
|
+
.onRemove=${e=>this.onRemoveMachine?.(e)}
|
|
1989
|
+
.onFocusNextSection=${()=>{this.focusNextFrom("machines")}}
|
|
1990
|
+
.onCancelKeyboardNavigation=${()=>{this.cancelKeyboardNavigation()}}
|
|
1991
|
+
></machine-switcher>
|
|
1992
|
+
`:null}
|
|
1993
|
+
<div class="header-actions">
|
|
1994
|
+
${this.refreshControl}
|
|
1995
|
+
<button title="显示操作" aria-label="显示操作" @click=${()=>{this.onShowActions?.()}}>操作</button>
|
|
1996
|
+
</div>
|
|
1997
|
+
</header>
|
|
1998
|
+
${this.compact&&Ti(this.machines)?c`
|
|
1999
|
+
<machine-list
|
|
2000
|
+
.machines=${this.machines}
|
|
2001
|
+
.selected=${this.selectedMachine}
|
|
2002
|
+
.statuses=${this.machineStatuses}
|
|
2003
|
+
.activities=${this.machineActivities}
|
|
2004
|
+
.collapsible=${this.collapsible}
|
|
2005
|
+
.collapsed=${this.machinesCollapsed}
|
|
2006
|
+
.onToggleCollapsed=${()=>{this.onToggleMachines?.()}}
|
|
2007
|
+
.onSelect=${e=>this.onSelectMachine?.(e)}
|
|
2008
|
+
.onRemove=${e=>this.onRemoveMachine?.(e)}
|
|
2009
|
+
.onFocusNextSection=${()=>{this.focusNextFrom("machines")}}
|
|
2010
|
+
.onCancelKeyboardNavigation=${()=>{this.cancelKeyboardNavigation()}}
|
|
2011
|
+
></machine-list>
|
|
2012
|
+
`:null}
|
|
2013
|
+
<project-list
|
|
2014
|
+
.projects=${this.projects}
|
|
2015
|
+
.selected=${this.selectedProject}
|
|
2016
|
+
.activities=${this.workspaceActivities}
|
|
2017
|
+
.workspacesByProjectId=${this.workspacesByProjectId}
|
|
2018
|
+
.collapsible=${this.collapsible}
|
|
2019
|
+
.collapsed=${this.projectsCollapsed}
|
|
2020
|
+
.onToggleCollapsed=${()=>{this.onToggleProjects?.()}}
|
|
2021
|
+
.onSelect=${e=>this.onSelectProject?.(e)}
|
|
2022
|
+
.onClose=${e=>this.onCloseProject?.(e)}
|
|
2023
|
+
.onFocusPreviousSection=${()=>{this.focusPreviousFrom("projects")}}
|
|
2024
|
+
.onFocusNextSection=${()=>{this.focusNextFrom("projects")}}
|
|
2025
|
+
.onCancelKeyboardNavigation=${()=>{this.cancelKeyboardNavigation()}}
|
|
2026
|
+
></project-list>
|
|
2027
|
+
<workspace-list
|
|
2028
|
+
.workspaces=${this.workspaces}
|
|
2029
|
+
.selected=${this.selectedWorkspace}
|
|
2030
|
+
.activities=${this.workspaceActivities}
|
|
2031
|
+
.deletingWorkspaceIds=${this.deletingWorkspaceIds}
|
|
2032
|
+
.collapsible=${this.collapsible}
|
|
2033
|
+
.collapsed=${this.workspacesCollapsed}
|
|
2034
|
+
.workspaceLabelItems=${this.workspaceLabelItems}
|
|
2035
|
+
.onToggleCollapsed=${()=>{this.onToggleWorkspaces?.()}}
|
|
2036
|
+
.onSelect=${e=>this.onSelectWorkspace?.(e)}
|
|
2037
|
+
.onDelete=${e=>this.onDeleteWorkspace?.(e)}
|
|
2038
|
+
.onFocusPreviousSection=${()=>{this.focusPreviousFrom("workspaces")}}
|
|
2039
|
+
.onFocusNextSection=${()=>{this.focusNextFrom("workspaces")}}
|
|
2040
|
+
.onCancelKeyboardNavigation=${()=>{this.cancelKeyboardNavigation()}}
|
|
2041
|
+
></workspace-list>
|
|
2042
|
+
<session-list
|
|
2043
|
+
.sessions=${this.sessions}
|
|
2044
|
+
.statuses=${this.sessionStatuses}
|
|
2045
|
+
.activities=${this.sessionActivities}
|
|
2046
|
+
.sending=${this.sendingPrompts}
|
|
2047
|
+
.selected=${this.selectedSession}
|
|
2048
|
+
.canStart=${this.canStartSession}
|
|
2049
|
+
.canDeleteArchived=${this.canDeleteArchivedSessions}
|
|
2050
|
+
.canReload=${this.canReloadSessions}
|
|
2051
|
+
.archivedDeleteUnavailableMessage=${this.archivedDeleteUnavailableMessage}
|
|
2052
|
+
.collapsible=${this.collapsible}
|
|
2053
|
+
.collapsed=${this.sessionsCollapsed}
|
|
2054
|
+
.onToggleCollapsed=${()=>{this.onToggleSessions?.()}}
|
|
2055
|
+
.onArchivedCollapsed=${()=>this.onArchivedCollapsed?.()}
|
|
2056
|
+
.onStart=${()=>this.onStartSession?.()}
|
|
2057
|
+
.onSelect=${e=>this.onSelectSession?.(e)}
|
|
2058
|
+
.onArchive=${e=>this.onArchiveSession?.(e)}
|
|
2059
|
+
.onArchiveWithDescendants=${e=>this.onArchiveSessionWithDescendants?.(e)}
|
|
2060
|
+
.onArchiveMany=${e=>this.onArchiveSessions?.(e)}
|
|
2061
|
+
.onRestore=${e=>this.onRestoreSession?.(e)}
|
|
2062
|
+
.onDelete=${e=>this.onDeleteCachedNewSession?.(e)}
|
|
2063
|
+
.onDeleteArchived=${e=>this.onDeleteArchivedSession?.(e)}
|
|
2064
|
+
.onDeleteArchivedMany=${e=>this.onDeleteArchivedSessions?.(e)}
|
|
2065
|
+
.onDetachParent=${e=>this.onDetachParentSession?.(e)}
|
|
2066
|
+
.onReload=${e=>this.onReloadSession?.(e)}
|
|
2067
|
+
.onFocusPreviousSection=${()=>{this.focusPreviousFrom("sessions")}}
|
|
2068
|
+
.onFocusNextSection=${()=>{this.focusNextFrom("sessions")}}
|
|
2069
|
+
.onCancelKeyboardNavigation=${()=>{this.cancelKeyboardNavigation()}}
|
|
2070
|
+
></session-list>
|
|
2071
|
+
`}async focusNavigableSection(e){return e===void 0?!1:await e.focusSelectedOrFirst()}focusPreviousFrom(e){const t=nw(e,this.machines);t!==void 0&&this.onFocusNavigationTarget?.(t)}focusNextFrom(e){this.onFocusNavigationTarget?.(aw(e,this.machines))}cancelKeyboardNavigation(){this.onCancelKeyboardNavigation?.()}};x.styles=O`
|
|
2072
|
+
:host { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
|
|
2073
|
+
:host([compact]) { flex: 1 1 auto; }
|
|
2074
|
+
header { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px; border-bottom: 1px solid var(--pi-border); }
|
|
2075
|
+
header strong { flex: 0 0 auto; }
|
|
2076
|
+
machine-switcher { flex: 1 1 auto; min-width: 0; }
|
|
2077
|
+
:host([compact]) header { display: none; }
|
|
2078
|
+
.header-actions { flex: 0 0 auto; display: flex; align-items: center; gap: 8px; }
|
|
2079
|
+
machine-list, project-list, workspace-list { flex: 0 0 auto; max-height: 26%; min-height: 0; overflow: hidden; border-bottom: 1px solid var(--pi-border-muted); }
|
|
2080
|
+
session-list { flex: 1 1 auto; min-height: 0; overflow: hidden; }
|
|
2081
|
+
machine-list[collapsed],
|
|
2082
|
+
project-list[collapsed],
|
|
2083
|
+
workspace-list[collapsed],
|
|
2084
|
+
session-list[collapsed] { flex: 0 0 auto; min-height: auto; overflow: hidden; }
|
|
2085
|
+
:host([compact]) machine-list,
|
|
2086
|
+
:host([compact]) project-list,
|
|
2087
|
+
:host([compact]) workspace-list,
|
|
2088
|
+
:host([compact]) session-list { flex: 1 1 auto; max-height: none; min-height: 0; overflow: hidden; }
|
|
2089
|
+
:host([compact]) machine-list[collapsed],
|
|
2090
|
+
:host([compact]) project-list[collapsed],
|
|
2091
|
+
:host([compact]) workspace-list[collapsed],
|
|
2092
|
+
:host([compact]) session-list[collapsed] { flex: 0 0 auto; min-height: auto; overflow: hidden; }
|
|
2093
|
+
button { border: 1px solid var(--pi-border); border-radius: 8px; background: var(--pi-surface); color: var(--pi-text); padding: 7px 9px; cursor: pointer; }
|
|
2094
|
+
`;k([d({attribute:!1})],x.prototype,"machines",2);k([d({attribute:!1})],x.prototype,"selectedMachine",2);k([d({attribute:!1})],x.prototype,"machineStatuses",2);k([d({attribute:!1})],x.prototype,"machineActivities",2);k([d({attribute:!1})],x.prototype,"projects",2);k([d({attribute:!1})],x.prototype,"selectedProject",2);k([d({attribute:!1})],x.prototype,"workspaces",2);k([d({attribute:!1})],x.prototype,"selectedWorkspace",2);k([d({attribute:!1})],x.prototype,"sessions",2);k([d({attribute:!1})],x.prototype,"selectedSession",2);k([d({attribute:!1})],x.prototype,"workspaceActivities",2);k([d({attribute:!1})],x.prototype,"sessionActivities",2);k([d({attribute:!1})],x.prototype,"sessionStatuses",2);k([d({attribute:!1})],x.prototype,"sendingPrompts",2);k([d({attribute:!1})],x.prototype,"workspacesByProjectId",2);k([d({attribute:!1})],x.prototype,"deletingWorkspaceIds",2);k([d({attribute:!1})],x.prototype,"workspaceLabelItems",2);k([d({attribute:!1})],x.prototype,"refreshControl",2);k([d({type:Boolean,reflect:!0})],x.prototype,"collapsible",2);k([d({type:Boolean,reflect:!0})],x.prototype,"compact",2);k([d({type:Boolean})],x.prototype,"machinesCollapsed",2);k([d({type:Boolean})],x.prototype,"projectsCollapsed",2);k([d({type:Boolean})],x.prototype,"workspacesCollapsed",2);k([d({type:Boolean})],x.prototype,"sessionsCollapsed",2);k([d({type:Boolean})],x.prototype,"canStartSession",2);k([d({type:Boolean})],x.prototype,"canDeleteArchivedSessions",2);k([d({type:Boolean})],x.prototype,"canReloadSessions",2);k([d({type:String})],x.prototype,"archivedDeleteUnavailableMessage",2);k([d({attribute:!1})],x.prototype,"onShowActions",2);k([d({attribute:!1})],x.prototype,"onToggleMachines",2);k([d({attribute:!1})],x.prototype,"onToggleProjects",2);k([d({attribute:!1})],x.prototype,"onToggleWorkspaces",2);k([d({attribute:!1})],x.prototype,"onToggleSessions",2);k([d({attribute:!1})],x.prototype,"onSelectProject",2);k([d({attribute:!1})],x.prototype,"onCloseProject",2);k([d({attribute:!1})],x.prototype,"onSelectWorkspace",2);k([d({attribute:!1})],x.prototype,"onDeleteWorkspace",2);k([d({attribute:!1})],x.prototype,"onStartSession",2);k([d({attribute:!1})],x.prototype,"onSelectSession",2);k([d({attribute:!1})],x.prototype,"onArchiveSession",2);k([d({attribute:!1})],x.prototype,"onArchiveSessionWithDescendants",2);k([d({attribute:!1})],x.prototype,"onArchiveSessions",2);k([d({attribute:!1})],x.prototype,"onRestoreSession",2);k([d({attribute:!1})],x.prototype,"onDeleteCachedNewSession",2);k([d({attribute:!1})],x.prototype,"onDeleteArchivedSession",2);k([d({attribute:!1})],x.prototype,"onDeleteArchivedSessions",2);k([d({attribute:!1})],x.prototype,"onDetachParentSession",2);k([d({attribute:!1})],x.prototype,"onReloadSession",2);k([d({attribute:!1})],x.prototype,"onArchivedCollapsed",2);k([d({attribute:!1})],x.prototype,"onSelectMachine",2);k([d({attribute:!1})],x.prototype,"onRemoveMachine",2);k([d({attribute:!1})],x.prototype,"onFocusNavigationTarget",2);k([d({attribute:!1})],x.prototype,"onCancelKeyboardNavigation",2);k([B("machine-list")],x.prototype,"machineList",2);k([B("machine-switcher")],x.prototype,"machineSwitcher",2);k([B("project-list")],x.prototype,"projectList",2);k([B("workspace-list")],x.prototype,"workspaceList",2);k([B("session-list")],x.prototype,"sessionList",2);x=k([D("app-navigation-panel")],x);function Ti(e){return e.length>1}function nw(e,t){const i=za(t);return i[i.indexOf(e)-1]}function aw(e,t){const i=za(t);return i[i.indexOf(e)+1]??"chat"}function za(e){return xi.filter(t=>t!=="machines"||Ti(e))}var cw=Object.defineProperty,lw=Object.getOwnPropertyDescriptor,Y=(e,t,i,s)=>{for(var o=s>1?void 0:s?lw(t,i):t,r=e.length-1,n;r>=0;r--)(n=e[r])&&(o=(s?n(t,i,o):n(o))||o);return s&&o&&cw(t,i,o),o};const dw=new Set(["ArrowLeft","ArrowRight","Home","End"]),pw=420,hw=4;let K=class extends M{constructor(){super(...arguments),this.side="navigation",this.collapsed=!1,this.resizable=!1,this.controls="",this.resizeLabel="调整面板宽度",this.expandLabel="展开面板",this.collapseLabel="折叠面板",this.lastTapAt=0}disconnectedCallback(){this.finishActiveResize(),super.disconnectedCallback()}render(){const e=this.collapsed?this.expandLabel:this.collapseLabel;return c`
|
|
2095
|
+
${this.renderResizeHandle()}
|
|
2096
|
+
<button
|
|
2097
|
+
type="button"
|
|
2098
|
+
class="edge-button"
|
|
2099
|
+
title=${e}
|
|
2100
|
+
aria-label=${e}
|
|
2101
|
+
aria-controls=${this.controls}
|
|
2102
|
+
aria-expanded=${String(!this.collapsed)}
|
|
2103
|
+
@click=${()=>{this.onToggle?.()}}
|
|
2104
|
+
>${this.renderIcon()}</button>
|
|
2105
|
+
`}renderResizeHandle(){if(!this.resizable)return F;const e=this.resizeConstraints();return c`
|
|
2106
|
+
<div
|
|
2107
|
+
class="resize-handle"
|
|
2108
|
+
role="separator"
|
|
2109
|
+
tabindex="0"
|
|
2110
|
+
aria-label=${this.resizeLabel}
|
|
2111
|
+
title=${`${this.resizeLabel}。双击或双击轻触可重置。`}
|
|
2112
|
+
aria-controls=${this.controls}
|
|
2113
|
+
aria-orientation="vertical"
|
|
2114
|
+
aria-valuemin=${String(e.minWidth)}
|
|
2115
|
+
aria-valuemax=${String(e.maxWidth)}
|
|
2116
|
+
aria-valuenow=${this.resizeAriaValueNow()}
|
|
2117
|
+
@pointerdown=${t=>{this.onResizePointerDown(t)}}
|
|
2118
|
+
@pointermove=${t=>{this.onResizePointerMove(t)}}
|
|
2119
|
+
@pointerup=${t=>{this.onResizePointerUp(t)}}
|
|
2120
|
+
@pointercancel=${t=>{this.onResizePointerCancel(t)}}
|
|
2121
|
+
@dblclick=${t=>{this.onResizeDoubleClick(t)}}
|
|
2122
|
+
@keydown=${t=>{this.onResizeKeyDown(t)}}
|
|
2123
|
+
></div>
|
|
2124
|
+
`}resizeAriaValueNow(){return this.panelWidth===void 0?F:String(Math.round(this.panelWidth))}renderIcon(){const t=this.iconDirection()==="left"?"M15 18l-6-6 6-6":"M9 18l6-6-6-6";return c`<svg class="edge-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d=${t}/></svg>`}iconDirection(){return this.side==="navigation"?this.collapsed?"right":"left":this.collapsed?"left":"right"}onResizePointerDown(e){if(!this.resizable||e.button!==0)return;const t=e.currentTarget;if(!(t instanceof HTMLElement))return;const i=this.resizeStartWidth();i!==void 0&&(e.preventDefault(),e.stopPropagation(),t.setPointerCapture(e.pointerId),this.activeResize={pointerId:e.pointerId,startClientX:e.clientX,startWidth:i,handle:t,moved:!1},this.toggleAttribute("resizing",!0))}onResizePointerMove(e){const t=this.activeResize;t?.pointerId===e.pointerId&&(e.preventDefault(),!(Math.abs(e.clientX-t.startClientX)<=hw)&&(t.moved=!0,this.commitPanelWidth(Mf(this.side,t.startWidth,t.startClientX,e.clientX,this.resizeConstraints()))))}onResizePointerUp(e){const t=this.activeResize;t?.pointerId===e.pointerId&&(e.preventDefault(),this.finishActiveResize(),t.moved||this.registerTapForReset())}onResizePointerCancel(e){this.activeResize?.pointerId===e.pointerId&&this.finishActiveResize()}onResizeDoubleClick(e){e.preventDefault(),e.stopPropagation(),this.resetPanelSize()}onResizeKeyDown(e){if(!this.resizable||!dw.has(e.key))return;const t=this.resizeStartWidth();if(t===void 0)return;const i=Af(this.side,t,e.key,{largeStep:e.shiftKey,constraints:this.resizeConstraints()});i!==void 0&&(e.preventDefault(),e.stopPropagation(),this.commitPanelWidth(i),this.onResizeEnd?.())}registerTapForReset(){const e=Date.now();if(e-this.lastTapAt<=pw){this.lastTapAt=0,this.resetPanelSize();return}this.lastTapAt=e}resetPanelSize(){this.finishActiveResize(),this.onReset?.()}resizeStartWidth(){const e=this.onResizeStart?.()??this.panelWidth;if(e!==void 0)return fe(this.side,e,this.resizeConstraints())}commitPanelWidth(e){this.onResize?.(fe(this.side,e,this.resizeConstraints()))}finishActiveResize(){const e=this.activeResize;if(e!==void 0){try{e.handle.releasePointerCapture(e.pointerId)}catch{}this.activeResize=void 0,this.toggleAttribute("resizing",!1),this.onResizeEnd?.()}}resizeConstraints(){const e=zt(this.side);return{...e,minWidth:this.minWidth??e.minWidth,maxWidth:this.maxWidth??e.maxWidth}}};K.styles=O`
|
|
2125
|
+
:host { position: relative; min-width: 0; min-height: 0; display: flex; align-items: center; justify-content: center; overflow: visible; background: var(--pi-border-muted); z-index: 2; }
|
|
2126
|
+
:host([side="navigation"]) { grid-column: 2; }
|
|
2127
|
+
:host([side="workspace"]) { grid-column: 4; }
|
|
2128
|
+
.resize-handle { position: absolute; inset: 0 -6px; z-index: 0; cursor: col-resize; touch-action: none; outline: none; }
|
|
2129
|
+
.resize-handle::after { content: ""; position: absolute; top: 0; bottom: 0; left: 50%; width: 1px; transform: translateX(-50%); background: transparent; transition: width .12s ease, background .12s ease, opacity .12s ease; }
|
|
2130
|
+
.resize-handle:hover::after, .resize-handle:focus-visible::after, :host([resizing]) .resize-handle::after { width: 3px; background: var(--pi-accent); opacity: .72; }
|
|
2131
|
+
.edge-button { position: relative; z-index: 1; box-sizing: border-box; display: grid; place-items: center; width: 18px; height: 48px; padding: 0; border: 1px solid var(--pi-border-muted); border-radius: 999px; background: var(--pi-bg); color: var(--pi-muted); opacity: .75; cursor: pointer; }
|
|
2132
|
+
.edge-button:hover, .edge-button:focus-visible { color: var(--pi-text); background: var(--pi-surface-hover); opacity: 1; }
|
|
2133
|
+
:host([side="navigation"][collapsed]) .edge-button { transform: translateX(calc(50% - .5px)); }
|
|
2134
|
+
:host([side="workspace"][collapsed]) .edge-button { transform: translateX(calc(-50% + .5px)); }
|
|
2135
|
+
.edge-icon { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
|
|
2136
|
+
@media (max-width: 1180px) {
|
|
2137
|
+
:host([side="navigation"]) { grid-row: 1 / 3; }
|
|
2138
|
+
:host([side="workspace"]) { display: none; }
|
|
2139
|
+
}
|
|
2140
|
+
@media (max-width: 760px) {
|
|
2141
|
+
:host([side="navigation"]) { display: none; }
|
|
2142
|
+
}
|
|
2143
|
+
`;Y([d({reflect:!0})],K.prototype,"side",2);Y([d({type:Boolean,reflect:!0})],K.prototype,"collapsed",2);Y([d({type:Boolean})],K.prototype,"resizable",2);Y([d({type:Number})],K.prototype,"panelWidth",2);Y([d({type:Number})],K.prototype,"minWidth",2);Y([d({type:Number})],K.prototype,"maxWidth",2);Y([d()],K.prototype,"controls",2);Y([d()],K.prototype,"resizeLabel",2);Y([d()],K.prototype,"expandLabel",2);Y([d()],K.prototype,"collapseLabel",2);Y([d({attribute:!1})],K.prototype,"onToggle",2);Y([d({attribute:!1})],K.prototype,"onResizeStart",2);Y([d({attribute:!1})],K.prototype,"onResize",2);Y([d({attribute:!1})],K.prototype,"onResizeEnd",2);Y([d({attribute:!1})],K.prototype,"onReset",2);K=Y([D("app-panel-edge-control")],K);var uw=Object.defineProperty,fw=Object.getOwnPropertyDescriptor,Ba=(e,t,i,s)=>{for(var o=s>1?void 0:s?fw(t,i):t,r=e.length-1,n;r>=0;r--)(n=e[r])&&(o=(s?n(t,i,o):n(o))||o);return s&&o&&uw(t,i,o),o};let Mi=class extends M{constructor(){super(...arguments),this.onReloadClick=e=>{e.stopPropagation(),this.onReload?.()}}render(){const e="完整重载页面";return c`
|
|
2144
|
+
<button
|
|
2145
|
+
class="app-refresh-button"
|
|
2146
|
+
title=${e}
|
|
2147
|
+
aria-label=${e}
|
|
2148
|
+
@click=${this.onReloadClick}
|
|
2149
|
+
>${this.renderRefreshIcon()}</button>
|
|
2150
|
+
`}renderRefreshIcon(){return c`
|
|
2151
|
+
<svg class="app-refresh-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false">
|
|
2152
|
+
<path d="M20 6v5h-5"></path>
|
|
2153
|
+
<path d="M4 18v-5h5"></path>
|
|
2154
|
+
<path d="M18.2 9A7 7 0 0 0 6.1 6.8L4 9"></path>
|
|
2155
|
+
<path d="M5.8 15a7 7 0 0 0 12.1 2.2L20 15"></path>
|
|
2156
|
+
</svg>
|
|
2157
|
+
`}};Mi.styles=O`
|
|
2158
|
+
:host { position: relative; z-index: 1; display: flex; align-items: center; pointer-events: auto; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
|
|
2159
|
+
:host, :host * { -webkit-user-select: none; user-select: none; }
|
|
2160
|
+
.app-refresh-button { box-sizing: border-box; width: 36px; height: 36px; display: grid; place-items: center; border: 1px solid var(--pi-border); border-radius: 999px; background: var(--pi-surface); color: var(--pi-text); padding: 0; line-height: 1; cursor: pointer; touch-action: manipulation; -webkit-touch-callout: none; }
|
|
2161
|
+
.app-refresh-icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
|
|
2162
|
+
`;Ba([d({attribute:!1})],Mi.prototype,"onReload",2);Mi=Ba([D("app-refresh-control")],Mi);var gw=Object.defineProperty,mw=Object.getOwnPropertyDescriptor,Me=(e,t,i,s)=>{for(var o=s>1?void 0:s?mw(t,i):t,r=e.length-1,n;r>=0;r--)(n=e[r])&&(o=(s?n(t,i,o):n(o))||o);return s&&o&&gw(t,i,o),o};const vw=900*1e3,bw=750,js=[1e3,3e3,8e3,15e3,3e4],on={capture:!0},fs="auto:on",rn="auto:off",ei="theme:",gs=_t("core:workspace.files"),ms=_t("core:workspace.git"),ti=_t("core:workspace.terminal"),ww=320,yw=2,Sw="(min-width: 1181px)";let pe=class extends M{constructor(){super(...arguments),this.state=ud(),this.sessions=new ih(()=>this.state,e=>{this.setState(e)},()=>{this.updateUrl()},new Qp),this.activity=new fd(()=>this.state,e=>{this.setState(e)}),this.auth=new vd(()=>this.state,e=>{this.setState(e)},e=>{this.sessions.applySessionStatus(e)}),this.workspaces=new mh(()=>this.state,e=>{this.setState(e)},()=>{this.updateUrl()},this.sessions,new fh),this.projects=new Cd(()=>this.state,e=>{this.setState(e)},this.workspaces),this.machines=new Id(()=>this.state,e=>{this.setState(e)},()=>{this.updateUrl()},this.projects),this.files=new Sd(()=>this.state,e=>{this.setState(e)},()=>{this.updateUrl()}),this.git=new Rd(()=>this.state,e=>{this.setState(e)},()=>{this.updateUrl()}),this.keyboard=new Th,this.realtime=new rr,this.machineActivitySockets=new Map,this.activeTerminalIds=new Set,this.machineNavigation=new yh,this.terminalSelection=new Ih,this.appShell=new gf(this),this.panelCollapse=new Rf(this),this.panelResize=new Cf(this),this.navigationSections=new kf(this,()=>this.state,()=>this.appShell.isMobileNavigationLayout),this.systemLightThemeMedia=typeof window<"u"&&"matchMedia"in window?window.matchMedia("(prefers-color-scheme: light)"):void 0,this.refreshingWorkspaceDeletionRuns=!1,this.handledWorkspaceDeletionRunIds=new Set,this.terminalCommandRunRuntimes=new Map,this.machineNavigationRestoreSeq=0,this.routeRestoreSeq=0,this.routeRestoreDepth=0,this.remoteRouteRestoreAttempt=0,this.remoteRouteRestoreInProgress=!1,this.plugins=xw(),this.loadedMachinePluginIds=new Set,this.machinePluginLoadPromises=new Map,this.themePreference=Hh()??zh,this.activeThemeId=ro,this.isRefreshingApp=!1,this.settingsSection=$r(),this.shortcutConfig={},this.onPopState=()=>{this.withChatScrollTransition(async()=>{this.restoreSettingsRoute(),await this.restoreRoute(!1)})},this.onPageShow=()=>{this.appShell.repairViewportPosition(),this.retryPendingRemoteRouteRestoreSoon()},this.onFocus=()=>{this.appShell.repairViewportPosition(),this.sessions.refreshSelectedSession(),this.schedulePiWebStatusRefresh(),this.refreshMachineActivities(),this.refreshWorkspaceDeletionRuns(),this.retryPendingRemoteRouteRestoreSoon()},this.onVisibilityChange=()=>{document.visibilityState==="visible"&&(this.appShell.repairViewportPosition(),this.sessions.refreshSelectedSession(),this.schedulePiWebStatusRefresh(),this.refreshMachineActivities(),this.refreshWorkspaceDeletionRuns(),this.retryPendingRemoteRouteRestoreSoon())},this.onSystemLightThemeChange=()=>{this.themePreference.auto&&this.applyPreferredTheme(!1)},this.onKeyDown=e=>{this.settingsSection===void 0&&this.keyboard.handle(e,this.getDefaultActions(),{shortcuts:this.shortcutConfig})&&(e.preventDefault(),e.stopPropagation())}}get routeRestoreInProgress(){return this.routeRestoreDepth>0}willUpdate(){this.toggleAttribute("pwa-display-mode",this.appShell.isPwaDisplayMode)}connectedCallback(){super.connectedCallback(),window.addEventListener("popstate",this.onPopState),window.addEventListener("pageshow",this.onPageShow),window.addEventListener("focus",this.onFocus),document.addEventListener("visibilitychange",this.onVisibilityChange),window.addEventListener("keydown",this.onKeyDown,on),this.systemLightThemeMedia?.addEventListener("change",this.onSystemLightThemeChange),this.applyPreferredTheme(!1),this.connectRealtime(),this.piWebStatusTimer=window.setInterval(()=>{this.schedulePiWebStatusRefresh()},vw),this.refreshWorkspaceActivity(),this.loadClientConfig(),this.ensureGatewayPluginsLoaded(),this.loadProjectsAndRestoreRoute().finally(()=>{this.schedulePiWebStatusRefresh()})}disconnectedCallback(){window.removeEventListener("popstate",this.onPopState),window.removeEventListener("pageshow",this.onPageShow),window.removeEventListener("focus",this.onFocus),document.removeEventListener("visibilitychange",this.onVisibilityChange),window.removeEventListener("keydown",this.onKeyDown,on),this.systemLightThemeMedia?.removeEventListener("change",this.onSystemLightThemeChange),this.keyboard.reset(),this.auth.dispose(),this.sessions.dispose(),this.realtime.close(),this.closeMachineActivitySockets(),this.git.dispose(),this.piWebStatusTimer!==void 0&&window.clearInterval(this.piWebStatusTimer),this.piWebStatusTimer=void 0,this.clearScheduledPiWebStatusRefresh(),this.workspaceDeletionPollTimer!==void 0&&window.clearInterval(this.workspaceDeletionPollTimer),this.workspaceDeletionPollTimer=void 0,this.clearPendingRemoteRouteRestore(),super.disconnectedCallback()}setState(e){if(!Pw(this.state,e))return;const t=this.state;this.state={...this.state,...e},this.handleActivityTransition(t,this.state),this.handleWorkspaceChange(t,this.state),this.handleMachineChange(t,this.state),kw(t,this.state)&&this.syncMachineActivitySubscriptions()}async loadProjectsAndRestoreRoute(){this.restoreSettingsRoute();const e=kr();await this.machines.loadMachines(e.machineId);const t=this.routeForSelectedMachine(e),i=this.state.machineStatuses[t.machineId??"local"];t!==e&&this.replaceRouteAndClearWorkspaceQuery(t),await this.projects.loadProjects(),await this.withChatScrollTransition(()=>this.restoreRouteFor(t,!1)),this.shouldDeferRemoteRouteRestore(t,i)?this.deferRemoteRouteRestore(t):(this.clearPendingRemoteRouteRestore(),this.rememberCurrentMachineNavigation()),await this.refreshWorkspaceDeletionRuns()}schedulePiWebStatusRefresh(e=bw){this.clearScheduledPiWebStatusRefresh(),this.piWebStatusDeferredTimer=window.setTimeout(()=>{this.piWebStatusDeferredTimer=void 0,this.refreshPiWebStatus()},e)}clearScheduledPiWebStatusRefresh(){this.piWebStatusDeferredTimer!==void 0&&(window.clearTimeout(this.piWebStatusDeferredTimer),this.piWebStatusDeferredTimer=void 0)}async refreshPiWebStatus(){const e=f(this.state);try{const t=await Cn.piWebStatus(e);f(this.state)===e&&this.setState({piWebStatus:t})}catch(t){f(this.state)===e&&this.setState({piWebStatus:void 0}),console.warn(`Failed to refresh PI WEB status for ${e}`,t)}}async refreshWorkspaceActivity(e=f(this.state)){try{await this.activity.refresh(e)}catch(t){console.warn(`Failed to refresh workspace activity for ${e}`,t)}}async refreshMachineActivities(){const e=this.state.machines.length===0?[f(this.state)]:this.state.machines.filter(t=>Ua(t,this.state.machineStatuses[t.id])).map(t=>t.id);await Promise.all(e.map(t=>this.refreshWorkspaceActivity(t)))}async loadClientConfig(){try{this.applyClientConfig((await hi.config()).config)}catch(e){console.warn("Failed to load PI WEB config",e)}}applyClientConfig(e){this.shortcutConfig=e.shortcuts??{}}async refreshAppData(){if(!this.isRefreshingApp){this.isRefreshingApp=!0;try{await Promise.all([this.sessions.refreshSelectedSession(),this.refreshMachineActivities(),this.loadClientConfig(),this.refreshWorkspaceDeletionRuns(),this.refreshCurrentWorkspaceSurface()]),this.schedulePiWebStatusRefresh()}finally{this.isRefreshingApp=!1}}}async refreshCurrentWorkspaceSurface(){const e=this.state.selectedWorkspace,t=this.state.mainView!=="chat"&&this.state.mainView!=="navigation"?this.state.mainView:this.state.workspaceTool;t==="core:workspace.files"?await this.files.refreshFiles():t==="core:workspace.git"?await this.git.refreshGit():t==="core:workspace.terminal"&&e!==void 0&&await this.refreshActiveTerminals(e)}hardReloadApp(){window.location.reload()}async restoreRoute(e){await this.restoreRouteFor(kr(),e),this.rememberCurrentMachineNavigation()}async restoreRouteFor(e,t,i=this.readWorkspaceRouteSurface(e),s){const o=f(this.state),r=e.projectId===void 0||e.projectId===""?cn():i,n=++this.routeRestoreSeq;this.routeRestoreDepth+=1,this.restoringRouteTerminalId=r.selectedTerminalId;try{await this.restoreRouteMachine(e,!1);const a=this.loadPluginsForSelectedMachine();if(e.tool?.startsWith("machine.")===!0&&await a,!this.isCurrentRouteRestore(n))return;if(this.setState({workspaceTool:e.tool??this.state.workspaceTool,mainView:s??e.view??this.defaultRouteView(),selectedFilePath:r.selectedFilePath,selectedDiffPath:r.selectedDiffPath,selectedTerminalId:r.selectedTerminalId}),e.projectId===void 0||e.projectId===""){t&&this.updateUrl();return}if(this.routeMatchesCurrentSelection(e)){r.selectedTerminalId!==void 0&&this.rememberSelectedTerminal(r.selectedTerminalId),await this.refreshRestoredWorkspaceTool(e.tool,r.selectedFilePath),this.git.updatePolling(),t&&this.updateUrl();return}const l=this.state.projects.find(p=>p.id===e.projectId);if(!l){this.setState({selectedFilePath:void 0,selectedDiffPath:void 0,selectedTerminalId:void 0}),t&&this.updateUrl();return}if(await this.workspaces.selectProject(l,{workspaceId:e.workspaceId,sessionId:e.sessionId,updateUrl:!1}),!this.isCurrentRouteRestore(n))return;this.setState({selectedFilePath:r.selectedFilePath,selectedDiffPath:r.selectedDiffPath,selectedTerminalId:r.selectedTerminalId}),r.selectedTerminalId!==void 0&&this.rememberSelectedTerminal(r.selectedTerminalId),await this.refreshRestoredWorkspaceTool(e.tool,r.selectedFilePath),this.git.updatePolling(),t&&this.updateUrl()}finally{this.routeRestoreDepth=Math.max(0,this.routeRestoreDepth-1),this.routeRestoreDepth===0&&(this.restoringRouteTerminalId=void 0),f(this.state)!==o&&this.schedulePiWebStatusRefresh()}}isCurrentRouteRestore(e){return e===this.routeRestoreSeq}readWorkspaceRouteSurface(e){return e.projectId===void 0||e.projectId===""?cn():{selectedFilePath:Ji(gs,"file"),selectedDiffPath:Ji(ms,"diff"),selectedTerminalId:Ji(ti,"terminal")}}routeForSelectedMachine(e){const t=this.state.selectedMachine?.id??"local";return(e.machineId??"local")===t?e:{machineId:t,projectId:void 0,workspaceId:void 0,sessionId:void 0,tool:void 0,view:void 0}}replaceRouteAndClearWorkspaceQuery(e){is(e,{replace:!0}),le(gs,"file",void 0,{replace:!0}),le(ms,"diff",void 0,{replace:!0}),le(ti,"terminal",void 0,{replace:!0})}shouldDeferRemoteRouteRestore(e,t=this.state.machineStatuses[e.machineId??"local"]){const i=e.machineId??"local",s=this.state.selectedMachine;return i==="local"||s?.id!==i||s.kind!=="remote"||t?.ok!==!1?!1:e.projectId===void 0||e.projectId===""?this.state.projects.length===0:this.state.selectedProject?.id!==e.projectId}deferRemoteRouteRestore(e){this.pendingRemoteRouteRestore=e,this.remoteRouteRestoreAttempt=0,this.setRemoteRouteRestoreMessage(e),this.schedulePendingRemoteRouteRestore()}retryPendingRemoteRouteRestoreSoon(){this.pendingRemoteRouteRestore!==void 0&&this.schedulePendingRemoteRouteRestore(0)}schedulePendingRemoteRouteRestore(e=Iw(this.remoteRouteRestoreAttempt)){this.pendingRemoteRouteRestore!==void 0&&(this.clearPendingRemoteRouteRestoreTimer(),this.remoteRouteRestoreTimer=window.setTimeout(()=>{this.remoteRouteRestoreTimer=void 0,this.retryPendingRemoteRouteRestore()},e))}async retryPendingRemoteRouteRestore(){if(this.remoteRouteRestoreInProgress)return;const e=this.pendingRemoteRouteRestore;if(e!==void 0){if(!this.pendingRemoteRouteRestoreStillCurrent(e)){this.clearPendingRemoteRouteRestore();return}this.remoteRouteRestoreInProgress=!0;try{const t=e.machineId??"local",i=await this.machines.refreshMachineHealth(t);if(!this.pendingRemoteRouteRestoreStillCurrent(e))return;if(i?.ok!==!0){this.scheduleNextRemoteRouteRestoreAttempt(e);return}if(await this.machines.refreshMachineRuntime(t),!this.pendingRemoteRouteRestoreStillCurrent(e)||(await this.projects.loadProjects(),!this.pendingRemoteRouteRestoreStillCurrent(e)))return;if(this.state.error!==""){this.scheduleNextRemoteRouteRestoreAttempt(e);return}if(await this.withChatScrollTransition(()=>this.restoreRouteFor(e,!1)),!this.pendingRemoteRouteRestoreStillCurrent(e))return;this.clearPendingRemoteRouteRestore(),this.rememberCurrentMachineNavigation(),await this.refreshWorkspaceDeletionRuns()}finally{this.remoteRouteRestoreInProgress=!1}}}scheduleNextRemoteRouteRestoreAttempt(e){if(this.remoteRouteRestoreAttempt+=1,this.remoteRouteRestoreAttempt>=js.length){this.setRemoteRouteRestoreMessage(e,{exhausted:!0}),this.clearPendingRemoteRouteRestore();return}this.setRemoteRouteRestoreMessage(e),this.schedulePendingRemoteRouteRestore()}setRemoteRouteRestoreMessage(e,t={}){const i=e.machineId??"local",s=this.state.machines.find(a=>a.id===i)?.name??this.state.selectedMachine?.name??"Remote machine",r=this.state.machineStatuses[i]?.error??(this.state.error===""?void 0:this.state.error),n=t.exhausted===!0?`${s} is still unavailable.`:`${s} is unavailable; reconnecting…`;this.setState({error:`${n}${r===void 0?"":` ${r}`}`})}pendingRemoteRouteRestoreStillCurrent(e){const t=e.machineId??"local";return t!=="local"&&this.pendingRemoteRouteRestore===e&&this.state.selectedMachine?.id===t&&this.state.machines.some(i=>i.id===t)}clearPendingRemoteRouteRestore(){this.clearPendingRemoteRouteRestoreTimer(),this.pendingRemoteRouteRestore=void 0,this.remoteRouteRestoreAttempt=0}clearPendingRemoteRouteRestoreTimer(){this.remoteRouteRestoreTimer!==void 0&&(window.clearTimeout(this.remoteRouteRestoreTimer),this.remoteRouteRestoreTimer=void 0)}async restoreRouteMachine(e,t){const i=e.machineId??"local";if(this.state.selectedMachine?.id===i)return;const s=this.state.machines.find(o=>o.id===i);s!==void 0&&await this.machines.selectMachine(s,{updateUrl:t})}routeMatchesCurrentSelection(e){return(e.machineId??"local")===(this.state.selectedMachine?.id??"local")&&e.workspaceId!==void 0&&e.workspaceId!==""&&this.state.selectedProject?.id===e.projectId&&this.state.selectedWorkspace?.id===e.workspaceId&&this.state.selectedSession?.id===e.sessionId}async refreshRestoredWorkspaceTool(e,t){e==="core:workspace.files"&&await this.files.refreshFiles(),e==="core:workspace.files"&&t!==void 0&&await this.files.restoreFile(t),e==="core:workspace.git"&&await this.git.refreshGit()}async withChatScrollTransition(e){this.chatView?.saveScrollPosition(),await e(),await this.updateComplete,await this.chatView?.updateComplete,await vs(),this.chatView?.restoreScrollPosition(),this.shouldAutoFocusPrompt()&&this.promptEditor?.focusInput()}shouldAutoFocusPrompt(){return this.appShell.shouldAutoFocusPrompt()}async withChatPrependTransition(e){await e(),await this.updateComplete,await this.chatView?.updateComplete}defaultRouteView(){return this.appShell.defaultRouteView()}updateUrl(e){this.rememberCurrentMachineNavigation(),is({machineId:this.state.selectedMachine?.id,projectId:this.state.selectedProject?.id,workspaceId:this.state.selectedWorkspace?.id,sessionId:this.state.selectedSession?.id,tool:this.state.workspaceTool,view:this.state.mainView==="navigation"?void 0:this.state.mainView},e),this.syncWorkspaceRouteSurfaceToUrl()}rememberCurrentMachineNavigation(){this.machineNavigation.remember(cr(this.state))}syncWorkspaceRouteSurfaceToUrl(){this.writeWorkspaceRouteSurfaceToUrl(cr(this.state).surface)}writeMachineNavigationSnapshotToUrl(e,t){is(lr(e),t),this.writeWorkspaceRouteSurfaceToUrl(e.surface)}writeWorkspaceRouteSurfaceToUrl(e){le(gs,"file",e.selectedFilePath,{replace:!0}),le(ms,"diff",e.selectedDiffPath,{replace:!0}),le(ti,"terminal",e.selectedTerminalId,{replace:!0})}async selectMachineWithMemory(e,t={}){if(this.state.selectedMachine?.id===e.id)return;t.rememberCurrent!==!1&&!this.routeRestoreInProgress&&this.rememberCurrentMachineNavigation();const i=++this.machineNavigationRestoreSeq,s=this.machineNavigation.latest(e.id)??Sh(e.id);if(await this.restoreRouteFor(lr(s),!1,s.surface,s.view),!(i!==this.machineNavigationRestoreSeq||this.state.selectedMachine?.id!==e.id)){if(this.shouldPreserveUnrestoredMachineNavigation(s)){this.machineNavigation.remember(s),this.writeMachineNavigationSnapshotToUrl(s);return}this.updateUrl()}}shouldPreserveUnrestoredMachineNavigation(e){return e.projectId!==void 0&&this.state.selectedProject?.id!==e.projectId&&this.state.error!==""}openWorkspaceTool(e){e==="core:workspace.terminal"&&(this.terminalAutoStartWorkspaceId=this.state.selectedWorkspace?.id),this.setState({workspaceTool:e,mainView:e}),this.updateUrl(),this.refreshSelectedWorkspaceTool(e),this.git.updatePolling()}openTerminal(e){e?.terminalId!==void 0&&this.selectTerminal(e.terminalId,{replace:!0}),this.openWorkspaceTool("core:workspace.terminal")}terminalCommandRunsForOrigin(e,t=f(this.state)){const i=ln(t,e),s=this.terminalCommandRunRuntimes.get(i);if(s!==void 0)return s;const o=qf(e,{api:{runTerminalCommand:(r,n)=>at.runTerminalCommand(r,n,t),listCommandRuns:r=>at.listCommandRuns(r,t),getCommandRun:r=>at.getCommandRun(r,t)},openTerminal:(r,n)=>{this.openRuntimeTerminal(t,r,n)}});return this.terminalCommandRunRuntimes.set(i,o),o}async openRuntimeTerminal(e,t,i){if((f(this.state)!==e||t!==void 0&&(this.state.selectedWorkspace?.id!==t.id||this.state.selectedProject?.id!==t.projectId))&&(this.routeRestoreInProgress||this.rememberCurrentMachineNavigation(),await this.restoreRouteFor({machineId:e,projectId:t?.projectId,workspaceId:t?.id,sessionId:void 0,tool:"core:workspace.terminal",view:"core:workspace.terminal"},!1,{selectedTerminalId:i?.terminalId},"core:workspace.terminal"),f(this.state)!==e)){this.setState({error:"Machine not found for terminal command run"});return}this.openTerminal(i)}selectTerminal(e,t){this.rememberSelectedTerminal(e),this.setState({selectedTerminalId:e}),this.rememberCurrentMachineNavigation(),this.writeSelectedTerminalToUrl(e,t)}rememberSelectedTerminal(e){const t=this.state.selectedWorkspace;t!==void 0&&(e===void 0?this.terminalSelection.forgetWorkspace(this.terminalWorkspaceKey(t)):this.terminalSelection.rememberTerminal(this.terminalWorkspaceKey(t),e))}writeSelectedTerminalToUrl(e,t){le(ti,"terminal",e,t)}terminalWorkspaceKey(e){return`${f(this.state)}:${e.path}`}selectMainView(e){if(e!=="navigation"&&e!=="chat"){this.openWorkspaceTool(e);return}this.setState({mainView:e}),this.updateUrl(),this.git.updatePolling()}openSettings(e="general"){this.settingsSection=e,ss(e)}closeSettings(){this.settingsSection=void 0,ss(void 0)}navigateSettings(e){this.settingsSection=e,ss(e)}restoreSettingsRoute(){this.settingsSection=$r()}handleWorkspaceChange(e,t){if(e.selectedWorkspace?.id===t.selectedWorkspace?.id)return;this.terminalAutoStartWorkspaceId=void 0,this.activeTerminalIds.clear();const i=this.routeRestoreInProgress?this.restoringRouteTerminalId:t.selectedWorkspace===void 0?void 0:this.terminalSelection.latestTerminalId(this.terminalWorkspaceKey(t.selectedWorkspace));this.setState({activeTerminalCount:0,selectedTerminalId:i}),this.routeRestoreInProgress||(this.rememberCurrentMachineNavigation(),this.writeSelectedTerminalToUrl(i,{replace:!0})),t.selectedWorkspace!==void 0&&(this.refreshActiveTerminals(t.selectedWorkspace),this.refreshWorkspaceDeletionRuns(),this.refreshSelectedWorkspaceTool(t.workspaceTool),this.git.updatePolling())}connectRealtime(){this.realtime.connect(e=>{this.handleRealtimeEvent(e)},()=>{const e=this.state.selectedWorkspace;e!==void 0&&this.refreshActiveTerminals(e),this.refreshWorkspaceActivity()},f(this.state))}syncMachineActivitySubscriptions(){const e=this.machineActivitySubscriptionIds();for(const[t,i]of this.machineActivitySockets.entries())e.has(t)||(i.close(),this.machineActivitySockets.delete(t));for(const t of e){if(this.machineActivitySockets.has(t))continue;const i=new rr;i.connect(s=>{this.handleMachineActivityEvent(t,s)},()=>{this.refreshWorkspaceActivity(t)},t),this.machineActivitySockets.set(t,i)}}closeMachineActivitySockets(){for(const e of this.machineActivitySockets.values())e.close();this.machineActivitySockets.clear()}machineActivitySubscriptionIds(){const e=f(this.state);return new Set(this.state.machines.filter(t=>t.id!==e).filter(t=>$w(t,this.state.machineStatuses[t.id])).map(t=>t.id))}handleMachineActivityEvent(e,t){t.type==="workspace.activity"&&this.activity.applyWorkspaceActivity(t.activity,e)}handleRealtimeEvent(e){e.type==="workspace.activity"?this.activity.applyWorkspaceActivity(e.activity):Rw(e)?(this.applyTerminalEvent(e),e.type==="terminal.exited"&&this.refreshWorkspaceDeletionRuns()):this.sessions.applyGlobalEvent(e)}applyTerminalEvent(e){const t=this.state.selectedWorkspace;t===void 0||(e.type==="terminal.closed"?e.cwd:e.terminal.cwd)!==t.path||(e.type==="terminal.created"&&!e.terminal.exited?this.activeTerminalIds.add(e.terminal.id):this.activeTerminalIds.delete(e.type==="terminal.closed"?e.terminalId:e.terminal.id),e.type==="terminal.closed"&&(this.terminalSelection.forgetTerminal(e.terminalId),this.state.selectedTerminalId===e.terminalId&&this.selectTerminal(void 0,{replace:!0})),this.setState({activeTerminalCount:this.activeTerminalIds.size}))}async refreshActiveTerminals(e){const t=f(this.state);try{const i=await at.terminals(e.projectId,e.id,t);if(f(this.state)!==t||this.state.selectedWorkspace?.id!==e.id)return;this.activeTerminalIds.clear();for(const s of i)s.exited||this.activeTerminalIds.add(s.id);this.setState({activeTerminalCount:this.activeTerminalIds.size})}catch(i){this.setState({error:String(i)})}}handleActivityTransition(e,t){const i=an(e),s=an(t);i&&!s&&(this.setState({fileTreeStale:!0,gitStale:!0}),this.refreshSelectedWorkspaceTool(this.state.workspaceTool))}handleMachineChange(e,t){if((e.selectedMachine?.id??"local")===(t.selectedMachine?.id??"local"))return;(this.pendingRemoteRouteRestore?.machineId??"local")!==(t.selectedMachine?.id??"local")&&this.clearPendingRemoteRouteRestore(),this.sessions.clearActiveSession(),this.realtime.close(),this.connectRealtime(),this.activeTerminalIds.clear(),this.setState({piWebStatus:void 0}),this.git.updatePolling(),this.loadPluginsForSelectedMachine()}refreshSelectedWorkspaceTool(e){e==="core:workspace.files"&&this.files.refreshFiles(),e==="core:workspace.git"&&this.git.refreshGit()}renderWorkspacePanel(){const e=this.state.selectedWorkspace,t=e===void 0?void 0:this.createWorkspacePanelContext(e),i=e===void 0?this.workspacePanelEmptyState():void 0;return c`
|
|
2163
|
+
<workspace-panel
|
|
2164
|
+
id="workspace-panel"
|
|
2165
|
+
.workspace=${e}
|
|
2166
|
+
.panelContext=${t}
|
|
2167
|
+
.emptyState=${i}
|
|
2168
|
+
.tool=${this.state.workspaceTool}
|
|
2169
|
+
.panels=${this.visibleWorkspacePanels()}
|
|
2170
|
+
.onSelectTool=${s=>{this.openWorkspaceTool(s)}}
|
|
2171
|
+
></workspace-panel>
|
|
2172
|
+
`}renderNavigationPanelEdgeControl(){const e=this.resizablePanelConstraints("navigation");return c`
|
|
2173
|
+
<app-panel-edge-control
|
|
2174
|
+
side="navigation"
|
|
2175
|
+
controls="navigation-panel"
|
|
2176
|
+
resizeLabel="Resize navigation panel"
|
|
2177
|
+
expandLabel="Expand navigation panel"
|
|
2178
|
+
collapseLabel="Collapse navigation panel"
|
|
2179
|
+
.collapsed=${this.panelCollapse.navigationPanelCollapsed}
|
|
2180
|
+
.resizable=${!this.appShell.isMobileNavigationLayout}
|
|
2181
|
+
.panelWidth=${this.panelResize.panelWidth("navigation")}
|
|
2182
|
+
.minWidth=${e.minWidth}
|
|
2183
|
+
.maxWidth=${e.maxWidth}
|
|
2184
|
+
.onToggle=${()=>{this.panelCollapse.toggleNavigationPanel()}}
|
|
2185
|
+
.onResizeStart=${()=>this.startPanelResize("navigation")}
|
|
2186
|
+
.onResize=${t=>{this.panelResize.resizePanel("navigation",t,{persist:!1})}}
|
|
2187
|
+
.onResizeEnd=${()=>{this.panelResize.persistPanelSizes()}}
|
|
2188
|
+
.onReset=${()=>{this.resetResizablePanel("navigation")}}
|
|
2189
|
+
></app-panel-edge-control>
|
|
2190
|
+
`}renderWorkspacePanelEdgeControl(){const e=this.resizablePanelConstraints("workspace");return c`
|
|
2191
|
+
<app-panel-edge-control
|
|
2192
|
+
side="workspace"
|
|
2193
|
+
controls="workspace-panel"
|
|
2194
|
+
resizeLabel="Resize workspace panel"
|
|
2195
|
+
expandLabel="Expand workspace panel"
|
|
2196
|
+
collapseLabel="Collapse workspace panel"
|
|
2197
|
+
.collapsed=${this.panelCollapse.workspacePanelCollapsed}
|
|
2198
|
+
.resizable=${!this.appShell.isMobileNavigationLayout}
|
|
2199
|
+
.panelWidth=${this.panelResize.panelWidth("workspace")}
|
|
2200
|
+
.minWidth=${e.minWidth}
|
|
2201
|
+
.maxWidth=${e.maxWidth}
|
|
2202
|
+
.onToggle=${()=>{this.panelCollapse.toggleWorkspacePanel()}}
|
|
2203
|
+
.onResizeStart=${()=>this.startPanelResize("workspace")}
|
|
2204
|
+
.onResize=${t=>{this.panelResize.resizePanel("workspace",t,{persist:!1})}}
|
|
2205
|
+
.onResizeEnd=${()=>{this.panelResize.persistPanelSizes()}}
|
|
2206
|
+
.onReset=${()=>{this.resetResizablePanel("workspace")}}
|
|
2207
|
+
></app-panel-edge-control>
|
|
2208
|
+
`}startPanelResize(e){return e==="navigation"?this.panelCollapse.expandNavigationPanel():this.panelCollapse.expandWorkspacePanel(),this.measuredPanelWidth(e)??this.panelResize.panelWidth(e)}resizablePanelConstraints(e){const t=this.panelResize.constraints(e);return{...t,maxWidth:this.resizablePanelMaxWidth(e,t)}}resizablePanelMaxWidth(e,t){const i=this.getBoundingClientRect().width||(typeof window>"u"?0:window.innerWidth);if(i<=0)return t.maxWidth;const s=this.oppositeResizablePanelWidth(e),o=Math.floor(i-s-yw-ww);return Math.max(t.minWidth,Math.min(t.maxWidth,o))}oppositeResizablePanelWidth(e){const t=e==="navigation"?"workspace":"navigation";return this.isResizablePanelCollapsedOrStacked(t)?0:this.measuredPanelWidth(t)??this.panelResize.panelWidth(t)}isResizablePanelCollapsedOrStacked(e){return e==="navigation"?this.panelCollapse.navigationPanelCollapsed:this.panelCollapse.workspacePanelCollapsed||!this.isDesktopSideBySideLayout()}isDesktopSideBySideLayout(){return typeof window>"u"||!("matchMedia"in window)?!0:window.matchMedia(Sw).matches}measuredPanelWidth(e){const i=(e==="navigation"?this.navigationPanelFrame:this.workspacePanelFrame)?.getBoundingClientRect().width;return i===void 0||i<=0?void 0:i}resetResizablePanel(e){this.panelResize.resetPanel(e)}resetResizablePanels(){this.panelResize.resetPanels()}canDeleteArchivedSessions(){const e=this.selectedMachineRuntime();return e?.ok===!0&&Dt(e,lt.sessionsDeleteArchived)}canReloadSessions(){const e=this.selectedMachineRuntime();return e?.ok===!0&&Dt(e,lt.sessionsReload)}archivedDeleteUnavailableMessage(){return`Update and restart Pi-Web on ${this.state.selectedMachine?.name??"this machine"} to delete archived sessions.`}selectedMachineRuntime(){return this.state.machineRuntimes[f(this.state)]}renderNavigationPanel(){return c`
|
|
2209
|
+
<app-navigation-panel
|
|
2210
|
+
.machines=${this.state.machines}
|
|
2211
|
+
.selectedMachine=${this.state.selectedMachine}
|
|
2212
|
+
.machineStatuses=${this.state.machineStatuses}
|
|
2213
|
+
.machineActivities=${this.state.machineActivities}
|
|
2214
|
+
.machinesCollapsed=${this.navigationSections.isCollapsed("machines")}
|
|
2215
|
+
.onToggleMachines=${()=>{this.navigationSections.toggle("machines")}}
|
|
2216
|
+
.onSelectMachine=${e=>this.selectNavigationItem("machines","projects",()=>this.selectMachineWithMemory(e))}
|
|
2217
|
+
.onRemoveMachine=${e=>{this.removeMachine(e)}}
|
|
2218
|
+
.projects=${this.state.projects}
|
|
2219
|
+
.selectedProject=${this.state.selectedProject}
|
|
2220
|
+
.workspaceActivities=${this.state.workspaceActivities}
|
|
2221
|
+
.workspacesByProjectId=${this.state.workspacesByProjectId}
|
|
2222
|
+
.workspaces=${this.state.workspaces}
|
|
2223
|
+
.selectedWorkspace=${this.state.selectedWorkspace}
|
|
2224
|
+
.deletingWorkspaceIds=${cu(this.state.workspaceDeletionRuns)}
|
|
2225
|
+
.sessions=${this.state.sessions}
|
|
2226
|
+
.sessionStatuses=${this.state.sessionStatuses}
|
|
2227
|
+
.sessionActivities=${this.state.sessionActivities}
|
|
2228
|
+
.sendingPrompts=${this.state.sendingPrompts}
|
|
2229
|
+
.selectedSession=${this.state.selectedSession}
|
|
2230
|
+
.canStartSession=${!!this.state.selectedWorkspace}
|
|
2231
|
+
.canDeleteArchivedSessions=${this.canDeleteArchivedSessions()}
|
|
2232
|
+
.canReloadSessions=${this.canReloadSessions()}
|
|
2233
|
+
.archivedDeleteUnavailableMessage=${this.archivedDeleteUnavailableMessage()}
|
|
2234
|
+
.collapsible=${!0}
|
|
2235
|
+
.compact=${this.appShell.isMobileNavigationLayout}
|
|
2236
|
+
.projectsCollapsed=${this.navigationSections.isCollapsed("projects")}
|
|
2237
|
+
.workspacesCollapsed=${this.navigationSections.isCollapsed("workspaces")}
|
|
2238
|
+
.sessionsCollapsed=${this.navigationSections.isCollapsed("sessions")}
|
|
2239
|
+
.workspaceLabelItems=${e=>this.workspaceLabelItems(e)}
|
|
2240
|
+
.refreshControl=${this.appShell.shouldShowAppRefreshInHeader()?this.renderAppRefresh():void 0}
|
|
2241
|
+
.onShowActions=${()=>{this.setState({actionPaletteOpen:!0})}}
|
|
2242
|
+
.onToggleProjects=${()=>{this.navigationSections.toggle("projects")}}
|
|
2243
|
+
.onToggleWorkspaces=${()=>{this.navigationSections.toggle("workspaces")}}
|
|
2244
|
+
.onToggleSessions=${()=>{this.navigationSections.toggle("sessions")}}
|
|
2245
|
+
.onSelectProject=${e=>this.selectNavigationItem("projects","workspaces",()=>this.workspaces.selectProject(e))}
|
|
2246
|
+
.onCloseProject=${e=>this.projects.closeProject(e.id)}
|
|
2247
|
+
.onSelectWorkspace=${e=>this.selectNavigationItem("workspaces","sessions",()=>this.workspaces.selectWorkspace(e))}
|
|
2248
|
+
.onDeleteWorkspace=${e=>{this.deleteWorkspace(e)}}
|
|
2249
|
+
.onArchivedCollapsed=${()=>{this.sessions.clearSelectionAfterArchivedCollapse()}}
|
|
2250
|
+
.onStartSession=${()=>this.selectNavigationItem("sessions","chat",()=>this.sessions.startSession())}
|
|
2251
|
+
.onSelectSession=${e=>this.selectNavigationItem("sessions","chat",()=>this.sessions.selectSession(e))}
|
|
2252
|
+
.onArchiveSession=${e=>this.sessions.archiveSession(e)}
|
|
2253
|
+
.onArchiveSessionWithDescendants=${e=>this.sessions.archiveSessionWithDescendants(e)}
|
|
2254
|
+
.onArchiveSessions=${e=>this.sessions.archiveSessions(e)}
|
|
2255
|
+
.onRestoreSession=${e=>this.selectNavigationItem("sessions","chat",()=>this.sessions.restoreSession(e))}
|
|
2256
|
+
.onDeleteCachedNewSession=${e=>this.sessions.deleteCachedNewSession(e)}
|
|
2257
|
+
.onDeleteArchivedSession=${e=>this.sessions.deleteArchivedSessions([e])}
|
|
2258
|
+
.onDeleteArchivedSessions=${e=>this.sessions.deleteArchivedSessions(e)}
|
|
2259
|
+
.onDetachParentSession=${e=>this.sessions.detachParent(e)}
|
|
2260
|
+
.onReloadSession=${e=>this.sessions.reloadSession(e)}
|
|
2261
|
+
.onFocusNavigationTarget=${e=>{this.focusNavigationTarget(e)}}
|
|
2262
|
+
.onCancelKeyboardNavigation=${()=>{this.focusChatComposer()}}
|
|
2263
|
+
></app-navigation-panel>
|
|
2264
|
+
`}openNavigationSection(e){this.navigationSections.open(e,()=>{this.selectMainView("navigation")})}async selectNavigationItem(e,t,i){await this.withChatScrollTransition(async()=>{this.navigationSections.advanceAfterSelection(e),await i()}),await this.focusNavigationTarget(t)}async focusNavigationTarget(e){if(e==="chat"){await this.focusChatComposer();return}await this.focusNavigationSection(e)}async focusNavigationSection(e){if(e==="machines"&&!Ti(this.state.machines)){await this.focusNavigationSection("projects");return}this.panelCollapse.expandNavigationPanel(),this.appShell.isMobileNavigationLayout&&this.selectMainView("navigation"),this.navigationSections.expand(e),await this.updateComplete,await vs(),await this.navigationPanel?.focusSection(e)}async focusChatComposer(){this.state.mainView!=="chat"&&this.selectMainView("chat"),await this.updateComplete,await vs(),this.promptEditor?.focusInput()}visibleWorkspacePanels(){const e=this.state.selectedWorkspace;if(e===void 0)return[];const t=this.createWorkspacePanelContext(e);return this.plugins.getWorkspacePanels().filter(i=>i.visible?.(t)??!0)}workspacePanelEmptyState(){const e=this.state.selectedProject;return this.state.isLoadingProjects?{title:"Loading projects…",body:"Looking for projects you have added to PI WEB."}:e===void 0?this.state.projects.length===0?{title:"No projects yet",body:"Use Actions → Add Project to add a folder. Workspace tools will appear here after you choose a workspace."}:{title:"选择项目",body:"从侧边栏选择一个项目,然后选择工作区来查看文件、Git 或终端。"}:this.state.isLoadingWorkspaces?{title:"Loading workspaces…",body:`Preparing workspace tools for ${e.name}.`}:this.state.workspaces.length===0?{title:"No workspaces found",body:`${e.name} does not have any available workspaces. Try selecting the project again or re-adding it.`}:{title:"Select a workspace",body:`Choose a workspace in ${e.name} to inspect files, Git, or terminals.`}}sessionEmptyMessage(){return this.state.isLoadingProjects?"正在加载项目…":this.state.selectedWorkspace!==void 0?"Select or start a session.":this.state.selectedProject!==void 0?"Select a workspace to start a session.":this.state.projects.length===0?"Add a project to start a session.":"选择项目和工作区以开始会话。"}mobilePanelBadge(e){const t=this.state.selectedWorkspace;if(t!==void 0)return e.badge?.(this.createWorkspacePanelContext(t))}mobilePanelIcon(e){switch(e.id){case"core:workspace.files":return"files";case"core:workspace.git":return"git";case"core:workspace.terminal":return"terminal";default:return}}workspaceLabelItems(e){return this.plugins.getWorkspaceLabelItems(this.createWorkspaceLabelContext(e))}createWorkspaceLabelContext(e){const t=nn(this.state);return{machine:t,workspace:e,state:this.state,files:this.createWorkspaceFiles(e,t.id),host:this.createWorkspaceHost()}}createWorkspaceFiles(e,t){return{readFile:i=>xs.workspaceFile(e.projectId,e.id,i,t)}}createWorkspaceHost(){return{requestRender:()=>{this.requestUpdate()}}}createWorkspacePanelContext(e){const t=nn(this.state),i=t.id,s=o=>{const r=this.terminalCommandRunsForOrigin(o,i);return sf({machine:t,workspace:e,state:this.state,files:this.createWorkspaceFiles(e,i),terminal:{open:n=>{this.openRuntimeTerminal(i,e,n)},runCommand:n=>r.runCommand({...n,workspace:e})},openTerminal:n=>{this.openRuntimeTerminal(i,e,n)},host:this.createWorkspaceHost(),piWebUnstable:{terminalCommandRuns:r},fileTree:this.state.fileTree,expandedDirs:this.state.expandedDirs,selectedFilePath:this.state.selectedFilePath,selectedFileContent:this.state.selectedFileContent,fileTreeStale:this.state.fileTreeStale,gitStatus:this.state.gitStatus,selectedDiffPath:this.state.selectedDiffPath,selectedDiff:this.state.selectedDiff,selectedStagedDiff:this.state.selectedStagedDiff,gitStale:this.state.gitStale,activeTerminalCount:this.state.activeTerminalCount,selectedTerminalId:this.state.selectedTerminalId,terminalAutoStart:this.terminalAutoStartWorkspaceId===e.id,onRefreshFiles:()=>{this.files.refreshFiles()},onUploadFiles:n=>{this.files.uploadFiles(n)},onCreateFile:n=>{this.files.createFile(n)},onCreateDirectory:n=>{this.files.createDirectory(n)},onMoveSelectedPath:n=>{this.files.moveSelectedPath(n)},onDeleteSelectedPath:()=>{this.files.deleteSelectedPath()},onDownloadSelectedFile:()=>{this.files.downloadSelectedFile()},onExpandDir:n=>{this.files.expandDir(n)},onSelectDirectory:n=>{this.files.selectDirectory(n)},onSelectFile:n=>{this.files.selectFile(n)},onRefreshGit:()=>{this.git.refreshGit()},onSelectDiff:n=>{this.git.selectDiff(n)},onSelectTerminal:(n,a)=>{this.selectTerminal(n,a)}},s)};return s("core")}getActions(){return Uf(this.getDefaultActions(),this.shortcutConfig)}getDefaultActions(){return[...this.plugins.getActions(this.createPluginRuntimeContext()),...this.navigationFocusActions(),...this.panelLayoutActions()]}panelLayoutActions(){return[{id:"app.layout.reset-navigation-panel-size",title:"重置导航面板宽度",description:"将导航面板恢复为默认宽度",group:"视图",run:()=>{this.resetResizablePanel("navigation")}},{id:"app.layout.reset-workspace-panel-size",title:"重置工作区面板宽度",description:"将工作区面板恢复为默认宽度",group:"视图",run:()=>{this.resetResizablePanel("workspace")}},{id:"app.layout.reset-panel-sizes",title:"重置面板宽度",description:"将所有侧边面板恢复为默认宽度",group:"视图",run:()=>{this.resetResizablePanels()}}]}navigationFocusActions(){return[{id:"app.navigation.focus-machines",title:"聚焦机器",description:"将键盘焦点移到机器选择器",shortcut:"mod+g m",group:"导航",run:()=>this.focusNavigationSection("machines")},{id:"app.navigation.focus-projects",title:"聚焦项目",description:"将键盘焦点移到项目列表",shortcut:"mod+g p",group:"导航",run:()=>this.focusNavigationSection("projects")},{id:"app.navigation.focus-workspaces",title:"聚焦工作区",description:"将键盘焦点移到工作区列表",shortcut:"mod+g w",group:"导航",run:()=>this.focusNavigationSection("workspaces")},{id:"app.navigation.focus-sessions",title:"聚焦会话",description:"将键盘焦点移到会话列表",shortcut:"mod+g s",group:"导航",run:()=>this.focusNavigationSection("sessions")}]}ensureGatewayPluginsLoaded(){return this.gatewayPluginLoadPromise??=this.loadExternalPlugins(),this.gatewayPluginLoadPromise}async loadExternalPlugins(){await this.registerExternalPlugins("PI WEB plugins",()=>wr())}async loadPluginsForSelectedMachine(){const e=this.state.selectedMachine;e?.kind==="remote"&&await this.loadPluginsForMachine(e)}async loadPluginsForMachine(e){if(await this.ensureGatewayPluginsLoaded(),e.kind!=="remote"||this.loadedMachinePluginIds.has(e.id))return;const t=this.machinePluginLoadPromises.get(e.id);if(t!==void 0)return t;const i=this.registerExternalPlugins(`PI WEB plugins from ${e.name}`,()=>wr(`/api/machines/${encodeURIComponent(e.id)}/pi-web-plugins/manifest.json`,{machineId:e.id,shouldLoadPlugin:s=>this.plugins.shouldLoadRemotePlugin(s.id,s.machineSpecific)})).then(s=>{s&&this.loadedMachinePluginIds.add(e.id)}).finally(()=>{this.machinePluginLoadPromises.delete(e.id)});this.machinePluginLoadPromises.set(e.id,i),await i}async registerExternalPlugins(e,t){try{const i=await t();for(const s of i)try{this.plugins.register(s)}catch(o){console.warn(`Failed to register PI WEB plugin ${s.id}`,o)}return this.applyPreferredTheme(!1),this.requestUpdate(),!0}catch(i){return console.warn(`Failed to load ${e}`,i),!1}}createPluginRuntimeContext(){const e=t=>tf({state:this.state,piWebUnstable:{terminalCommandRuns:this.terminalCommandRunsForOrigin(t),openSettings:i=>{this.openSettings(i)}},openActionPalette:()=>{this.setState({actionPaletteOpen:!0})},focusPrompt:()=>{this.focusChatComposer()},addProject:()=>{this.setState({projectDialogOpen:!0})},addMachine:()=>{this.openMachineDialog()},refreshSelectedMachine:async()=>{await Promise.all([this.machines.refreshMachineHealth(),this.machines.refreshMachineRuntime()])},removeSelectedMachine:()=>this.removeMachine(),openSelectedMachine:()=>{this.openSelectedMachine()},configureAuth:()=>this.auth.openLogin(),logoutAuth:()=>this.auth.openLogout(),openThemePicker:()=>{this.openThemeDialog()},selectMainView:i=>{this.selectMainView(i)},selectWorkspaceTool:i=>{this.openWorkspaceTool(i)},openTerminal:i=>{this.openTerminal(i)},refreshFiles:()=>this.files.refreshFiles(),refreshGit:()=>this.git.refreshGit(),refreshAppData:()=>this.refreshAppData(),reloadPage:()=>{this.hardReloadApp()},deleteWorkspace:i=>this.deleteWorkspace(i),startSession:()=>this.withChatScrollTransition(()=>this.sessions.startSession()),archiveSession:()=>this.sessions.archiveSession(),reloadSession:()=>this.sessions.reloadSession(),deleteCachedNewSession:()=>this.sessions.deleteCachedNewSession(),stopActiveWork:()=>this.sessions.stopActiveWork()},e);return e("core")}async deleteWorkspace(e=this.state.selectedWorkspace){if(e===void 0)return;if(!vh(e)){this.setState({error:"Only secondary Git worktrees can be deleted"});return}if(ea(this.state,e))return;const t=e.branch??e.label;if(!confirm(`Delete workspace ${t}?
|
|
2265
|
+
|
|
2266
|
+
This will run git worktree remove and delete:
|
|
2267
|
+
${e.path}
|
|
2268
|
+
|
|
2269
|
+
The Git branch will not be deleted.`))return;const s=f(this.state);try{const o=await xs.deleteWorkspace(e.projectId,e.id,s);if(f(this.state)!==s)return;this.recordWorkspaceDeletionRun(o,s);const r=await this.workspaceForCommandRun(o);if(f(this.state)!==s)return;r!==void 0&&this.openRuntimeTerminal(s,r,{terminalId:o.terminalId})}catch(o){f(this.state)===s&&this.setState({error:`Failed to start workspace deletion: ${Cw(o)}`})}}async workspaceForCommandRun(e){let t=this.state.selectedProject?.id===e.projectId?this.state.workspaces:this.state.workspacesByProjectId[e.projectId];return(t===void 0||t.length===0)&&(t=await this.workspaces.refreshProjectWorkspaces(e.projectId)),t.find(i=>i.id===e.workspaceId)}recordWorkspaceDeletionRun(e,t){if(f(this.state)!==t)return;const i=Ts(e);i!==void 0&&(this.setState({workspaceDeletionRuns:{...this.state.workspaceDeletionRuns,[i]:e}}),this.updateWorkspaceDeletionPolling())}async refreshWorkspaceDeletionRuns(){if(this.refreshingWorkspaceDeletionRuns)return;const e=f(this.state),t=this.state.selectedProject;if(t===void 0){this.setState({workspaceDeletionRuns:{}}),this.updateWorkspaceDeletionPolling();return}this.refreshingWorkspaceDeletionRuns=!0;try{const i=await this.terminalCommandRunsForOrigin("core",e).listCommandRuns(nu(t.id));if(f(this.state)!==e)return;const s=au(i);this.setState({workspaceDeletionRuns:s});for(const o of Object.values(s))yi(o)||await this.handleCompletedWorkspaceDeletionRun(o,e)}catch(i){console.warn("Failed to refresh workspace deletion runs",i)}finally{this.refreshingWorkspaceDeletionRuns=!1,this.updateWorkspaceDeletionPolling()}}updateWorkspaceDeletionPolling(){const e=Object.values(this.state.workspaceDeletionRuns).some(yi);if(e&&this.workspaceDeletionPollTimer===void 0){this.workspaceDeletionPollTimer=window.setInterval(()=>{this.refreshWorkspaceDeletionRuns()},1e3);return}!e&&this.workspaceDeletionPollTimer!==void 0&&(window.clearInterval(this.workspaceDeletionPollTimer),this.workspaceDeletionPollTimer=void 0)}async handleCompletedWorkspaceDeletionRun(e,t=f(this.state)){if(f(this.state)!==t)return;const i=ln(t,e.id);if(this.handledWorkspaceDeletionRunIds.has(i))return;const s=Ts(e);if(s!==void 0){if(this.handledWorkspaceDeletionRunIds.add(i),e.status==="succeeded"){if(await this.workspaces.refreshAfterWorkspaceDeleted(e.projectId,s),f(this.state)!==t)return;this.setState({workspaceDeletionRuns:Tw(this.state.workspaceDeletionRuns,s)}),this.updateWorkspaceDeletionPolling();return}e.status==="failed"&&(this.setState({error:"Workspace deletion failed. See terminal output."}),this.updateWorkspaceDeletionPolling())}}openMachineDialog(){this.setState({machineDialogOpen:!0,error:""})}async submitMachineDialog(e){await this.machines.addMachine(e)!==void 0&&(this.setState({machineDialogOpen:!1}),this.schedulePiWebStatusRefresh())}async removeMachine(e=this.state.selectedMachine){if(e===void 0||e.kind==="local"||!window.confirm(`Remove ${e.name}?
|
|
2270
|
+
|
|
2271
|
+
This only removes it from this PI WEB gateway.`))return;const t=this.state.selectedMachine?.id===e.id;t&&this.rememberCurrentMachineNavigation();const i=await this.machines.deleteMachine(e,{selectFallback:!t});this.state.machines.some(s=>s.id===e.id)||this.machineNavigation.forget(e.id),t&&i!==void 0&&await this.selectMachineWithMemory(i,{rememberCurrent:!1})}openSelectedMachine(){const e=this.state.selectedMachine;e?.kind!=="remote"||e.baseUrl===void 0||window.open(e.baseUrl,"_blank","noopener,noreferrer")}runAction(e){Promise.resolve().then(()=>e.run()).catch(t=>{const i=t instanceof Error?t.message:String(t);console.warn(`Action failed: ${e.id}`,t),this.setState({error:`Action failed: ${i}`})})}async openModelDialog(){const e=await this.sessions.listModels(),t=this.state.status?.model?.provider,i=this.state.status?.model?.id;this.setState({modelDialog:{title:"选择模型",...t!==void 0&&i!==void 0?{selectedValue:`${t}/${i}`}:{},options:e.map(s=>{const o=s.provider??"",r=s.id??"",n=o===t&&r===i;return{value:`${o}/${r}`,label:`${r}${n?" ✓ 当前":""}`,description:o}})}})}async pickModel(e){this.setState({modelDialog:void 0});const t=e.indexOf("/");t<=0||await this.sessions.setModel(e.slice(0,t),e.slice(t+1))}openThemeDialog(){const e=this.plugins.getThemes(),t=this.resolveCurrentThemePreference(e),i=t.selectedTheme?.id,s=this.themePreference.auto?rn:fs;this.setState({themeDialog:{title:"选择主题",selectedValue:i===void 0?s:`${ei}${i}`,options:[{value:s,label:`Auto ${this.themePreference.auto?"✓ on":"off"}`,description:this.autoThemeDescription(t)},...e.map(o=>({value:`${ei}${o.id}`,label:this.themeOptionLabel(o,i),description:this.themeOptionDescription(o)}))]}})}pickTheme(e){if(this.setState({themeDialog:void 0}),e===fs||e===rn){const s=this.resolveCurrentThemePreference().selectedTheme?.id;if(s===void 0)return;this.themePreference={themeId:s,auto:e===fs},this.applyPreferredTheme(!0);return}if(!e.startsWith(ei))return;const t=e.slice(ei.length),i=this.plugins.getThemes().find(s=>s.id===t);i!==void 0&&(this.themePreference={themeId:i.id,auto:this.themePreference.auto},this.applyPreferredTheme(!0))}applyPreferredTheme(e){const t=this.resolveCurrentThemePreference().activeTheme;t!==void 0&&(this.activeThemeId=t.id,Kh(t),e&&qh(this.themePreference))}resolveCurrentThemePreference(e=this.plugins.getThemes()){return Vh({themes:e,themePairs:this.plugins.getThemePairs(),preference:this.themePreference,prefersLight:this.systemPrefersLight()})}themePairForTheme(e){return Yn(this.plugins.getThemePairs(),e)}systemPrefersLight(){return this.systemLightThemeMedia?.matches??!1}autoThemeDescription(e){return!this.themePreference.auto||e.selectedTheme===void 0?"Follow the system light/dark preference when the selected theme has a pair.":e.selectedThemePair===void 0?"On, but the selected theme has no light/dark pair, so it will stay selected.":`On · ${e.selectedThemePair.name} follows the system ${this.systemPrefersLight()?"light":"dark"} preference.`}themeOptionLabel(e,t){const i=[...e.id===t?["selected"]:[],...e.id===this.activeThemeId&&e.id!==t?["active"]:[]];return i.length===0?e.name:`${e.name} ✓ ${i.join(" · ")}`}themeOptionDescription(e){const t=[e.colorScheme];return this.themePairForTheme(e.id)!==void 0&&t.push("auto pair"),e.description!==void 0&&t.push(e.description),t.join(" · ")}async openThinkingDialog(){const e=await this.sessions.listThinkingLevels(),t=this.state.status?.thinkingLevel??"off";this.setState({thinkingDialog:{title:"选择思考级别",selectedValue:t,options:e.map(i=>{const s=Mw(i);return{value:i,label:`${i}${i===t?" ✓ 当前":""}`,...s===void 0?{}:{description:s}}})}})}async pickThinking(e){this.setState({thinkingDialog:void 0}),e!==""&&await this.sessions.setThinkingLevel(e)}sendPrompt(e,t,i,s){!(i!==void 0&&i.length>0)&&t===void 0&&this.auth.handleSlashCommand(e)||this.sessions.send(e,t,i,s)}renderContextBar(){return this.appShell.isMobileNavigationLayout?c`
|
|
2272
|
+
<app-context-bar
|
|
2273
|
+
.machines=${this.state.machines}
|
|
2274
|
+
.machine=${this.state.selectedMachine}
|
|
2275
|
+
.project=${this.state.selectedProject}
|
|
2276
|
+
.workspace=${this.state.selectedWorkspace}
|
|
2277
|
+
.session=${this.state.selectedSession}
|
|
2278
|
+
.refreshControl=${this.appShell.shouldShowAppRefreshInContextBar()?this.renderAppRefresh():void 0}
|
|
2279
|
+
.onOpenSection=${e=>{this.openNavigationSection(e)}}
|
|
2280
|
+
.onShowActions=${()=>{this.setState({actionPaletteOpen:!0})}}
|
|
2281
|
+
></app-context-bar>
|
|
2282
|
+
`:null}renderMobileMainTabs(){return c`
|
|
2283
|
+
<app-mobile-main-tabs
|
|
2284
|
+
.tabs=${this.mobileMainTabs()}
|
|
2285
|
+
.selectedView=${this.state.mainView}
|
|
2286
|
+
.onSelect=${e=>{this.selectMainView(e)}}
|
|
2287
|
+
></app-mobile-main-tabs>
|
|
2288
|
+
`}mobileMainTabs(){return[{id:"navigation",label:"会话",icon:"navigation",className:"navigation-tab"},{id:"chat",label:"聊天",icon:"chat"},...this.visibleWorkspacePanels().map(e=>{const t=e.icon??this.mobilePanelIcon(e);return{id:e.id,label:e.title,...t===void 0?{}:{icon:t},badge:this.mobilePanelBadge(e)}})]}renderAppRefresh(){return c`<app-refresh-control .onReload=${()=>{this.hardReloadApp()}}></app-refresh-control>`}render(){const e=this.state;return c`
|
|
2289
|
+
<div class=${this.panelCollapse.shellClass(e.mainView)} style=${this.panelResize.shellStyle({navigation:this.resizablePanelConstraints("navigation"),workspace:this.resizablePanelConstraints("workspace")})}>
|
|
2290
|
+
<aside id="navigation-panel">${this.appShell.isMobileNavigationLayout?null:this.renderNavigationPanel()}</aside>
|
|
2291
|
+
${this.renderNavigationPanelEdgeControl()}
|
|
2292
|
+
<main class=${aa(e.mainView)}>
|
|
2293
|
+
${this.renderContextBar()}
|
|
2294
|
+
${this.renderMobileMainTabs()}
|
|
2295
|
+
${e.error?c`<div class="error">${e.error}</div>`:null}
|
|
2296
|
+
<div class="mobile-navigation-panel">${this.appShell.isMobileNavigationLayout?this.renderNavigationPanel():null}</div>
|
|
2297
|
+
${e.selectedSession?c`
|
|
2298
|
+
<chat-view .sessionId=${e.selectedSession.id} .messages=${e.messages} .messageStart=${e.messagePageStart} .messageEnd=${e.messagePageEnd} .messageTotal=${e.messagePageTotal} .hasMore=${e.messagePageStart>0} .loadingMore=${e.isLoadingEarlierMessages} .isReceivingPartialStream=${e.isReceivingPartialStream} .isSendingPrompt=${e.sendingPrompts[e.selectedSession.id]===!0} .isCompacting=${e.status?.isCompacting===!0} .pendingMessageCount=${e.status?.pendingMessageCount??0} .status=${e.status} .activity=${e.activity} .onLoadMore=${()=>this.withChatPrependTransition(()=>this.sessions.loadEarlierMessages())}></chat-view>
|
|
2299
|
+
<prompt-editor .sessionId=${e.selectedSession.id} .cwd=${e.selectedWorkspace?.path} .machineId=${f(e)} .disabled=${e.selectedSession.archived===!0} .canSteer=${e.status?.isStreaming===!0} .isCompacting=${e.status?.isCompacting===!0} .canStop=${e.status?.isStreaming===!0||e.status?.isBashRunning===!0||e.status?.isCompacting===!0||(e.status?.pendingMessageCount??0)>0} .status=${e.status} .availableThinkingLevels=${e.availableThinkingLevels} .sending=${e.sendingPrompts[e.selectedSession.id]===!0} .onSend=${(t,i,s,o)=>{this.sendPrompt(t,i,s,o)}} .onStop=${()=>this.sessions.stopActiveWork()} .onSelectModel=${()=>{this.openModelDialog()}} .onSelectThinking=${()=>{this.openThinkingDialog()}}></prompt-editor>
|
|
2300
|
+
<status-bar .status=${e.status}></status-bar>
|
|
2301
|
+
${e.commandDialog!==void 0?c`<command-picker .title=${e.commandDialog.title} .options=${e.commandDialog.options} .onPick=${t=>this.sessions.respondToCommand(e.commandDialog?.requestId??"",t)} .onCancel=${()=>{this.sessions.cancelCommand()}}></command-picker>`:null}
|
|
2302
|
+
${e.modelDialog!==void 0?c`<command-picker title=${e.modelDialog.title} .searchable=${!0} .options=${e.modelDialog.options} .selectedValue=${e.modelDialog.selectedValue} .onPick=${t=>{this.pickModel(t)}} .onCancel=${()=>{this.setState({modelDialog:void 0})}}></command-picker>`:null}
|
|
2303
|
+
${e.thinkingDialog!==void 0?c`<command-picker title=${e.thinkingDialog.title} .options=${e.thinkingDialog.options} .selectedValue=${e.thinkingDialog.selectedValue} .onPick=${t=>{this.pickThinking(t)}} .onCancel=${()=>{this.setState({thinkingDialog:void 0})}}></command-picker>`:null}
|
|
2304
|
+
${e.authDialog!==void 0?c`<auth-dialog .state=${e.authDialog} .onChooseMethod=${t=>{this.auth.chooseLoginMethod(t)}} .onSelectProvider=${(t,i)=>{this.auth.selectLoginProvider(t,i)}} .onApiKeyInput=${t=>{this.auth.updateApiKey(t)}} .onSaveApiKey=${()=>{this.auth.saveApiKey()}} .onLogoutProvider=${t=>{this.auth.logoutProvider(t)}} .onOAuthInput=${t=>{this.auth.updateOAuthInput(t)}} .onOAuthRespond=${t=>{this.auth.respondOAuth(t)}} .onOAuthCancel=${()=>{this.auth.cancelOAuth()}} .onCancel=${()=>{this.auth.closeDialog()}}></auth-dialog>`:null}
|
|
2305
|
+
`:c`<div class="empty">${this.sessionEmptyMessage()}</div>`}
|
|
2306
|
+
</main>
|
|
2307
|
+
${this.renderWorkspacePanelEdgeControl()}
|
|
2308
|
+
${this.renderWorkspacePanel()}
|
|
2309
|
+
${e.actionPaletteOpen?c`<action-palette .actions=${this.getActions()} .onRun=${t=>{this.setState({actionPaletteOpen:!1}),this.runAction(t)}} .onCancel=${()=>{this.setState({actionPaletteOpen:!1})}}></action-palette>`:null}
|
|
2310
|
+
${e.projectDialogOpen?c`<project-dialog .machineId=${f(e)} .onSubmit=${(t,i)=>this.projects.addProject(t,i)} .onCancel=${()=>{this.setState({projectDialogOpen:!1})}}></project-dialog>`:null}
|
|
2311
|
+
${e.machineDialogOpen?c`<machine-dialog .error=${e.error} .onSubmit=${t=>this.submitMachineDialog(t)} .onCancel=${()=>{this.setState({machineDialogOpen:!1})}}></machine-dialog>`:null}
|
|
2312
|
+
${e.themeDialog!==void 0?c`<command-picker title=${e.themeDialog.title} .options=${e.themeDialog.options} .selectedValue=${e.themeDialog.selectedValue} .onPick=${t=>{this.pickTheme(t)}} .onCancel=${()=>{this.setState({themeDialog:void 0})}}></command-picker>`:null}
|
|
2313
|
+
${this.settingsSection!==void 0?c`<settings-dialog .section=${this.settingsSection} .actions=${this.getDefaultActions()} .onNavigate=${t=>{this.navigateSettings(t)}} .onClose=${()=>{this.closeSettings()}} .onConfigSaved=${t=>{this.applyClientConfig(t)}}></settings-dialog>`:null}
|
|
2314
|
+
</div>
|
|
2315
|
+
`}};pe.styles=og;Me([y()],pe.prototype,"state",2);Me([B("chat-view")],pe.prototype,"chatView",2);Me([B("prompt-editor")],pe.prototype,"promptEditor",2);Me([B("app-navigation-panel")],pe.prototype,"navigationPanel",2);Me([B("#navigation-panel")],pe.prototype,"navigationPanelFrame",2);Me([B("#workspace-panel")],pe.prototype,"workspacePanelFrame",2);Me([y()],pe.prototype,"activeThemeId",2);Me([y()],pe.prototype,"isRefreshingApp",2);Me([y()],pe.prototype,"settingsSection",2);Me([y()],pe.prototype,"shortcutConfig",2);pe=Me([D("pi-web-app")],pe);function xw(){const e=new Yu;return e.register({id:"core",plugin:_u}),e.register({id:"themes",plugin:Nu}),e}function nn(e){const t=e.selectedMachine;return t!==void 0?{id:t.id,name:t.name,kind:t.kind}:{id:"local",name:"local",kind:"local"}}function kw(e,t){return e.machines!==t.machines||e.machineStatuses!==t.machineStatuses||(e.selectedMachine?.id??"local")!==(t.selectedMachine?.id??"local")}function $w(e,t){return Ua(e,t)}function Ua(e,t){if(e.kind==="local")return!0;const i=t?.status??e.status;return i===void 0||i==="unknown"||i==="online"}function Pw(e,t){return Object.entries(t).some(([i,s])=>Reflect.get(e,i)!==s)}function an(e){return Qe(e.status,e.activity)}function Rw(e){return e.type==="terminal.created"||e.type==="terminal.exited"||e.type==="terminal.closed"}function cn(){return{}}function ln(e,t){return JSON.stringify([e,t])}function Iw(e){const t=Math.min(e,js.length-1);return js[t]??3e4}function Cw(e){return e instanceof Error?e.message:String(e)}function Tw(e,t){return Object.fromEntries(Object.entries(e).filter(([i])=>i!==t))}function vs(){return new Promise(e=>requestAnimationFrame(()=>{e()}))}function Mw(e){switch(e){case"off":return"No reasoning";case"minimal":return"Very brief reasoning (~1k tokens)";case"low":return"Light reasoning (~2k tokens)";case"medium":return"Moderate reasoning (~8k tokens)";case"high":return"Deep reasoning (~16k tokens)";case"xhigh":return"Maximum reasoning (~32k tokens)";default:return}}export{O as a,c as b,at as c,Bw as d,B as e,Nw as f,M as i,d as n,y as r,zw as s,D as t};
|