@chainingintention/pi-web-cn 1.202606.12 → 1.202606.13
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 +2 -2
- package/dist/client/assets/{CodeViewer-BKljKDuK.js → CodeViewer-D5OA_6r4.js} +1 -1
- package/dist/client/assets/{TerminalPanel-DeDTQWls.js → TerminalPanel-kfPHfhUe.js} +9 -9
- package/dist/client/assets/{index-BuVYTYo8.js → index-MmspRbMF.js} +358 -270
- package/dist/client/index.html +1 -1
- package/dist/config.js +26 -0
- package/dist/config.js.map +1 -1
- package/dist/pi-web-plugins/updates/updatesLogic.js +13 -13
- package/dist/pi-web-plugins/workspace-tasks/tasksPanelElement.js +1 -5
- package/dist/server/configRoutes.js +10 -0
- package/dist/server/configRoutes.js.map +1 -1
- package/dist/server/sessiond.js +15 -2
- package/dist/server/sessiond.js.map +1 -1
- package/dist/server/sessions/attachmentService.js +2 -2
- package/dist/server/sessions/attachmentService.js.map +1 -1
- package/dist/server/sessions/builtinCommands.js +21 -21
- package/dist/server/sessions/builtinCommands.js.map +1 -1
- package/dist/server/sessions/oauthLoginFlowService.js +15 -15
- package/dist/server/sessions/oauthLoginFlowService.js.map +1 -1
- package/dist/server/sessions/piSessionService.js +71 -33
- package/dist/server/sessions/piSessionService.js.map +1 -1
- package/dist/server/sessions/sessionCommandService.js +32 -28
- package/dist/server/sessions/sessionCommandService.js.map +1 -1
- package/dist/server/sessions/sessionRoutes.js +2 -2
- package/dist/server/sessions/sessionRoutes.js.map +1 -1
- package/dist/server/sessions/spawnSessionTool.js +36 -0
- package/dist/server/sessions/spawnSessionTool.js.map +1 -0
- package/dist/server/sessions/spawnTargetResolver.js +36 -0
- package/dist/server/sessions/spawnTargetResolver.js.map +1 -0
- package/dist/shared/apiTypes.d.ts +7 -1
- package/docs/plugins.md +3 -3
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -110,7 +110,7 @@ PI WEB keeps its own state intentionally small:
|
|
|
110
110
|
|
|
111
111
|
## Machine federation
|
|
112
112
|
|
|
113
|
-
The Machines section lets one PI WEB instance act as a gateway to other PI WEB runtimes. Register a remote machine from **Actions → Add Machine** with the remote PI WEB base URL, for example a URL reachable over NetBird, Tailscale, WireGuard, an SSH tunnel, or a trusted reverse proxy. The browser continues talking to the local PI WEB origin; project, workspace, file, git, session, activity, and terminal HTTP/WebSocket traffic is proxied server-to-server. See the [Fleet guide](https://pi-web.dev/machines
|
|
113
|
+
The Machines section lets one PI WEB instance act as a gateway to other PI WEB runtimes. Register a remote machine from **Actions → Add Machine** with the remote PI WEB base URL, for example a URL reachable over NetBird, Tailscale, WireGuard, an SSH tunnel, or a trusted reverse proxy. The browser continues talking to the local PI WEB origin; project, workspace, file, git, session, activity, and terminal HTTP/WebSocket traffic is proxied server-to-server. See the [Fleet guide](https://pi-web.dev/machines) for setup, trust model, and troubleshooting details.
|
|
114
114
|
|
|
115
115
|
Remote model-provider credentials and OAuth state stay on the target machine. API-key provider configuration can be proxied, but OAuth login should be completed by opening the remote PI WEB directly. Register remote machines only when you trust the endpoint and the network path: adding a machine gives this PI WEB server permission to contact that URL with the optional bearer token you configured.
|
|
116
116
|
|
|
@@ -124,7 +124,7 @@ A useful prompt for AI agents:
|
|
|
124
124
|
|
|
125
125
|
```text
|
|
126
126
|
Build a PI WEB plugin for this project. Goal: <describe the UI behavior>.
|
|
127
|
-
Before coding, read https://pi-web.dev/plugins
|
|
127
|
+
Before coding, read https://pi-web.dev/plugins and https://pi-web.dev/plugins.md.
|
|
128
128
|
Create it under ~/.pi-web/plugins/<plugin-id> using the documented PI WEB v1 plugin API.
|
|
129
129
|
Validate with /pi-web-plugins/manifest.json and explain reload/debug steps.
|
|
130
130
|
Do not modify PI WEB itself.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{w as a,J as p,$ as h,A as m,X as g,U as f,_ as v,a0 as b}from"./vendor-editor-core-B4Sq6exx.js";import{g as y,r as w,p as C,h as x,c as j,m as _,j as k,a as u}from"./vendor-editor-languages-DznYbTkJ.js";import{d as E}from"./vendor-editor-legacy-B4QLsWF8.js";import{i as H,b as O,a as S,n as d,e as P,t as L}from"./index-
|
|
1
|
+
import{w as a,J as p,$ as h,A as m,X as g,U as f,_ as v,a0 as b}from"./vendor-editor-core-B4Sq6exx.js";import{g as y,r as w,p as C,h as x,c as j,m as _,j as k,a as u}from"./vendor-editor-languages-DznYbTkJ.js";import{d as E}from"./vendor-editor-legacy-B4QLsWF8.js";import{i as H,b as O,a as S,n as d,e as P,t as L}from"./index-MmspRbMF.js";var D=Object.defineProperty,F=Object.getOwnPropertyDescriptor,i=(e,o,n,s)=>{for(var t=s>1?void 0:s?F(o,n):o,c=e.length-1,l;c>=0;c--)(l=e[c])&&(t=(s?l(o,n,t):l(t))||t);return s&&t&&D(o,n,t),t};let r=class extends H{constructor(){super(...arguments),this.content=""}firstUpdated(){this.recreateEditor()}updated(e){(e.has("content")||e.has("language"))&&this.recreateEditor()}disconnectedCallback(){this.view?.destroy(),this.view=void 0,super.disconnectedCallback()}render(){return O`<div class="host"></div>`}recreateEditor(){this.editorHost&&(this.view?.destroy(),this.view=new a({parent:this.editorHost,state:p.create({doc:this.content,extensions:[h(),m.of(g),f(v,{fallback:!0}),p.readOnly.of(!0),a.editable.of(!1),a.lineWrapping,M,...R(this.language)]})}))}};r.styles=S`
|
|
2
2
|
:host { display: block; min-height: 0; height: 100%; }
|
|
3
3
|
.host { height: 100%; min-height: 0; overflow: auto; }
|
|
4
4
|
`;i([d()],r.prototype,"content",2);i([d()],r.prototype,"language",2);i([P(".host")],r.prototype,"editorHost",2);r=i([L("code-viewer")],r);const M=a.theme({"&":{height:"100%",color:"var(--pi-text)",backgroundColor:"var(--pi-bg)",fontSize:"12px"},".cm-scroller":{fontFamily:"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",lineHeight:"1.45"},".cm-gutters":{backgroundColor:"var(--pi-bg)",color:"var(--pi-dim)",borderRight:"1px solid var(--pi-border-muted)"},".cm-activeLineGutter":{backgroundColor:"transparent"},".cm-activeLine":{backgroundColor:"transparent"},".cm-content":{caretColor:"transparent"},"&.cm-focused":{outline:"none"}});function R(e){if(e===void 0)return[];switch(e){case"typescript":return[u({typescript:!0})];case"javascript":return[u()];case"json":return[k()];case"markdown":return[_()];case"css":return[j()];case"html":return[x()];case"python":return[C()];case"rust":return[w()];case"go":return[y()];case"diff":return[b.define(E)];default:return[]}}export{r as CodeViewer};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import{a as E,n as m,i as
|
|
1
|
+
import{a as E,n as m,i as K,b as l,t as R,c as h,s as D,d as w,f as _,e as F,r as c}from"./index-MmspRbMF.js";import{D as T,o as S}from"./vendor-terminal-DjQ08hXu.js";import"./vendor-editor-core-B4Sq6exx.js";import"./vendor-editor-languages-DznYbTkJ.js";const $="pi-web.terminal.softKeys",N="(pointer: coarse), (max-width: 760px)";function z(e,t){return e??t}function V(e){if(e==="true")return!0;if(e==="false")return!1}function P(){return typeof window<"u"&&"matchMedia"in window?window.matchMedia(N):void 0}function M(e){return e?.matches===!0}function j(e=P()){return z(O(),M(e))}function B(){return O()!==void 0}function O(e=A()){if(e!==void 0)try{return V(e.getItem($))}catch{return}}function H(e,t=A()){if(t!==void 0)try{t.setItem($,String(e))}catch{}}function A(){if(!(typeof window>"u"))try{return window.localStorage}catch{return}}const U=[{id:"escape",label:"Esc",ariaLabel:"Escape",title:"发送 Escape"},{id:"tab",label:"Tab",ariaLabel:"Tab",title:"发送 Tab"},{id:"ctrl-c",label:"Ctrl+C",ariaLabel:"Control C",title:"中断前台进程"},{id:"ctrl-d",label:"Ctrl+D",ariaLabel:"Control D",title:"发送 EOF / 关闭输入"},{id:"ctrl-z",label:"Ctrl+Z",ariaLabel:"Control Z",title:"挂起前台进程"},{id:"ctrl-l",label:"Ctrl+L",ariaLabel:"Control L",title:"清屏 / 重绘终端"},{id:"ctrl-r",label:"Ctrl+R",ariaLabel:"Control R",title:"反向搜索历史"},{id:"ctrl-u",label:"Ctrl+U",ariaLabel:"Control U",title:"删除到行首"},{id:"ctrl-w",label:"Ctrl+W",ariaLabel:"Control W",title:"删除上一个单词"},{id:"arrow-left",label:"←",ariaLabel:"左箭头",title:"向左移动"},{id:"arrow-up",label:"↑",ariaLabel:"上箭头",title:"向上移动 / 上一条命令"},{id:"arrow-down",label:"↓",ariaLabel:"下箭头",title:"向下移动 / 下一条命令"},{id:"arrow-right",label:"→",ariaLabel:"右箭头",title:"向右移动"},{id:"home",label:"Home",ariaLabel:"Home",title:"移动到开头"},{id:"end",label:"End",ariaLabel:"End",title:"移动到末尾"},{id:"page-up",label:"PgUp",ariaLabel:"向上翻页",title:"向上翻页"},{id:"page-down",label:"PgDn",ariaLabel:"向下翻页",title:"向下翻页"},{id:"delete",label:"Del",ariaLabel:"Delete",title:"向前删除"},{id:"backspace",label:"⌫",ariaLabel:"Backspace",title:"退格"},{id:"meta-backward-word",label:"M-B",ariaLabel:"Meta B",title:"向后移动一个单词"},{id:"meta-forward-word",label:"M-F",ariaLabel:"Meta F",title:"向前移动一个单词"}],d="\x1B",q="";function Y(e,t){switch(e){case"escape":return d;case"tab":return" ";case"ctrl-c":return p("c");case"ctrl-d":return p("d");case"ctrl-z":return p("z");case"ctrl-l":return p("l");case"ctrl-r":return p("r");case"ctrl-u":return p("u");case"ctrl-w":return p("w");case"arrow-left":return b("D",t);case"arrow-up":return b("A",t);case"arrow-down":return b("B",t);case"arrow-right":return b("C",t);case"home":return x("H",t);case"end":return x("F",t);case"page-up":return`${d}[5~`;case"page-down":return`${d}[6~`;case"delete":return`${d}[3~`;case"backspace":return q;case"meta-backward-word":return`${d}b`;case"meta-forward-word":return`${d}f`}}function p(e){return String.fromCharCode(e.toUpperCase().charCodeAt(0)-64)}function b(e,t){return t?.applicationCursorKeysMode===!0?`${d}O${e}`:`${d}[${e}`}function x(e,t){return t?.applicationCursorKeysMode===!0?`${d}O${e}`:`${d}[${e}`}var W=Object.defineProperty,X=Object.getOwnPropertyDescriptor,g=(e,t,i,n)=>{for(var r=n>1?void 0:n?X(t,i):t,a=e.length-1,u;a>=0;a--)(u=e[a])&&(r=(n?u(t,i,r):u(r))||r);return n&&r&&W(t,i,r),r};const J=8,Z=500;let f=class extends K{constructor(){super(...arguments),this.refocusOnClick=!0,this.onInput=()=>{},this.lastPointerFinishedAt=0}sendSoftKey(e,t){this.onInput(Y(e.id,this.modes),t)}onSoftKeyPointerDown(e,t){e.pointerType==="mouse"&&e.button!==0||(e.preventDefault(),this.pointerStart={pointerId:e.pointerId,key:t,clientX:e.clientX,clientY:e.clientY})}onSoftKeyPointerMove(e){const t=this.pointerStart;t?.pointerId===e.pointerId&&I(t,e)&&this.finishSoftKeyPointer()}onSoftKeyPointerUp(e,t){const i=this.pointerStart;i?.pointerId===e.pointerId&&(e.preventDefault(),this.finishSoftKeyPointer(),!(i.key.id!==t.id||I(i,e))&&this.sendSoftKey(t,{refocus:e.pointerType==="mouse"}))}onSoftKeyPointerCancel(e){this.pointerStart?.pointerId===e.pointerId&&this.finishSoftKeyPointer()}finishSoftKeyPointer(){this.pointerStart=void 0,this.lastPointerFinishedAt=Date.now()}onSoftKeyClick(e,t){if(Date.now()-this.lastPointerFinishedAt<Z){e.preventDefault();return}this.sendSoftKey(t,{refocus:this.refocusOnClick})}render(){return l`
|
|
2
2
|
<div class="terminal-soft-keys" role="toolbar" aria-label="终端快捷键">
|
|
3
|
-
${
|
|
3
|
+
${U.map(e=>l`
|
|
4
4
|
<button
|
|
5
5
|
type="button"
|
|
6
6
|
class="soft-key"
|
|
@@ -20,10 +20,10 @@ import{a as E,n as m,i as R,b as l,t as K,c as h,s as L,d as w,f as _,e as F,r a
|
|
|
20
20
|
.terminal-soft-keys::-webkit-scrollbar { display: none; }
|
|
21
21
|
button { display: inline-flex; align-items: center; gap: 6px; flex: 0 0 auto; max-width: none; min-height: 34px; border: 1px solid var(--pi-border); border-radius: 7px; background: var(--pi-surface); color: var(--pi-text); padding: 6px 9px; font: 12px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; cursor: pointer; touch-action: pan-x; -webkit-touch-callout: none; user-select: none; }
|
|
22
22
|
button:disabled { opacity: .5; cursor: not-allowed; }
|
|
23
|
-
`;
|
|
24
|
-
[进程已退出${
|
|
25
|
-
[终端错误:${
|
|
26
|
-
[终端错误:${
|
|
23
|
+
`;g([m({attribute:!1})],f.prototype,"modes",2);g([m({type:Boolean})],f.prototype,"refocusOnClick",2);g([m({attribute:!1})],f.prototype,"onInput",2);f=g([R("terminal-soft-keys")],f);function I(e,t){return Math.hypot(t.clientX-e.clientX,t.clientY-e.clientY)>J}var G=Object.defineProperty,Q=Object.getOwnPropertyDescriptor,s=(e,t,i,n)=>{for(var r=n>1?void 0:n?Q(t,i):t,a=e.length-1,u;a>=0;a--)(u=e[a])&&(r=(n?u(t,i,r):u(r))||r);return n&&r&&G(t,i,r),r};const ee={cursorBlink:!0,convertEol:!0,fontFamily:"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",fontSize:13},te={cols:100,rows:30},ie=1e3;let o=class extends K{constructor(){super(...arguments),this.machineId="local",this.autoStart=!1,this.onSelectTerminal=()=>{},this.terminals=[],this.commandRuns=[],this.loading=!1,this.visible=!1,this.cancellingRunIds=[],this.continuingTerminalIds=[],this.defaultSoftKeysEnvironment=!1,this.softKeysEnabled=j(),this.suppressTerminalInput=!1,this.softKeysDefaultEnvironmentMedia=P(),this.softKeysPreferenceStored=B(),this.onSoftKeysDefaultEnvironmentChange=()=>{this.syncDefaultSoftKeysEnvironment()}}connectedCallback(){super.connectedCallback(),this.syncDefaultSoftKeysEnvironment(),this.softKeysDefaultEnvironmentMedia?.addEventListener("change",this.onSoftKeysDefaultEnvironmentChange),this.themeObserver=new MutationObserver(()=>{this.applyTerminalTheme()}),this.themeObserver.observe(document.documentElement,{attributes:!0,attributeFilter:["class","style","data-theme"]})}firstUpdated(){this.intersectionObserver=new IntersectionObserver(e=>{this.visible=e[0]?.isIntersecting===!0}),this.intersectionObserver.observe(this)}disconnectedCallback(){this.intersectionObserver?.disconnect(),this.intersectionObserver=void 0,this.themeObserver?.disconnect(),this.themeObserver=void 0,this.softKeysDefaultEnvironmentMedia?.removeEventListener("change",this.onSoftKeysDefaultEnvironmentChange),this.updateCommandRunPolling(!1),this.disposeTerminalView(),super.disconnectedCallback()}syncDefaultSoftKeysEnvironment(){const e=M(this.softKeysDefaultEnvironmentMedia),t=this.softKeysEnabled;this.defaultSoftKeysEnvironment=e,this.softKeysPreferenceStored||(this.softKeysEnabled=e),this.softKeysEnabled!==t&&this.scheduleFitAndNotify()}scheduleFitAndNotify(){this.updateComplete.then(()=>{this.fitAndNotify()})}willUpdate(e){const t=this.workspace===void 0?void 0:JSON.stringify([this.machineId,this.workspace.path]);if(t!==this.observedWorkspaceScope){this.observedWorkspaceScope=t,this.loadedCwd=void 0,this.autoStartConsumedCwd=void 0,this.terminals=[],this.commandRuns=[],this.selectedId=void 0,this.cancellingRunIds=[],this.continuingTerminalIds=[],this.updateCommandRunPolling(!1),this.disposeTerminalView();return}if(e.has("selectedTerminalId")){if(e.get("selectedTerminalId")!==void 0&&this.selectedTerminalId===void 0){this.loadedCwd=void 0,this.selectTerminalIdInView(void 0);return}this.applyRequestedTerminalSelection()}}updated(e){this.visible?this.hasPendingCommandRuns()&&this.updateCommandRunPolling(!0):this.updateCommandRunPolling(!1),this.loadVisibleWorkspaceTerminals(),e.has("selectedTerminalId")&&this.shouldReloadForRequestedTerminal()&&this.loadTerminals(),this.ensureTerminalView()}loadVisibleWorkspaceTerminals(){const e=this.workspace?.path;!this.visible||e===void 0||e===this.loadedCwd||(this.loadedCwd=e,this.loadTerminals())}async loadTerminals(){this.loading=!0,this.error=void 0;try{const e=this.workspace;if(e===void 0)return;const t=this.consumeAutoStart(),[i,n]=await Promise.all([h.terminals(e.projectId,e.id,this.machineId),h.listCommandRuns({projectId:e.projectId,workspaceId:e.id},this.machineId)]);this.terminals=i,this.commandRuns=n,this.selectPreferredLoadedTerminal({replaceUrl:!0}),this.updateCommandRunPolling(this.hasPendingCommandRuns(n)),i.length===0&&t&&await this.startTerminal()}catch(e){this.error=e instanceof Error?e.message:String(e)}finally{this.loading=!1}}applyRequestedTerminalSelection(){this.selectedTerminalId!==void 0&&!this.terminals.some(e=>e.id===this.selectedTerminalId)||this.selectPreferredLoadedTerminal({replaceUrl:!0})}consumeAutoStart(){const e=this.workspace?.path;return!this.autoStart||e===void 0||this.autoStartConsumedCwd===e?!1:(this.autoStartConsumedCwd=e,!0)}shouldReloadForRequestedTerminal(){const e=this.workspace?.path;return this.visible&&e!==void 0&&e===this.loadedCwd&&this.selectedTerminalId!==void 0&&!this.loading&&!this.terminals.some(t=>t.id===this.selectedTerminalId)}selectPreferredLoadedTerminal(e){let t=D(this.terminals,{targetTerminalId:this.selectedTerminalId});t===void 0&&this.selectedTerminalId!==void 0&&(t=w(this.terminals)),this.selectTerminalIdInView(t?.id),(t?.id!==this.selectedTerminalId||t===void 0&&this.selectedTerminalId!==void 0)&&this.onSelectTerminal(t?.id,{replace:e?.replaceUrl===!0})}selectTerminalIdInView(e){this.selectedId!==e&&(this.selectedId=e,this.disposeTerminalView())}async startTerminal(){if(this.workspace!==void 0){this.error=void 0;try{const e=this.measureTerminalSize()??te,t=await h.startTerminal(this.workspace.projectId,this.workspace.id,e,this.machineId);this.terminals=[...this.terminals,t],this.selectTerminal(t.id)}catch(e){this.error=e instanceof Error?e.message:String(e)}}}async closeTerminal(e,t){t.stopPropagation();try{if(this.workspace===void 0)return;await h.closeTerminal(this.workspace.projectId,this.workspace.id,e,this.machineId);const i=this.terminals.filter(n=>n.id!==e);if(this.terminals=i,this.selectedId===e||this.selectedTerminalId===e){const n=w(i)?.id;this.selectTerminalIdInView(n),this.onSelectTerminal(n,{replace:!0})}}catch(i){this.error=i instanceof Error?i.message:String(i)}}selectTerminal(e){this.selectedId!==e&&this.selectTerminalIdInView(e),this.onSelectTerminal(e)}selectedTerminalInfo(){return this.terminals.find(e=>e.id===this.selectedId)}selectedCommandRun(){const e=this.selectedTerminalInfo()?.commandRunId;if(e!==void 0)return this.commandRuns.find(t=>t.id===e)}async loadCommandRuns(){const e=this.workspace;if(e!==void 0)try{const t=await h.listCommandRuns({projectId:e.projectId,workspaceId:e.id},this.machineId);this.commandRuns=t,this.cancellingRunIds=this.cancellingRunIds.filter(i=>t.some(n=>n.id===i&&v(n))),this.updateCommandRunPolling(this.hasPendingCommandRuns(t))}catch(t){this.error=t instanceof Error?t.message:String(t)}}updateCommandRunPolling(e){if(e&&this.commandRunPollTimer===void 0){this.commandRunPollTimer=window.setInterval(()=>{this.loadCommandRuns()},ie);return}!e&&this.commandRunPollTimer!==void 0&&(window.clearInterval(this.commandRunPollTimer),this.commandRunPollTimer=void 0)}hasPendingCommandRuns(e=this.commandRuns){return e.some(v)}async cancelCommandRun(e){if(!(!v(e)||this.cancellingRunIds.includes(e.id))){this.error=void 0,this.cancellingRunIds=[...this.cancellingRunIds,e.id];try{await h.cancelCommandRun(e.id,this.machineId),await this.loadCommandRuns()}catch(t){this.error=t instanceof Error?t.message:String(t)}finally{this.cancellingRunIds=this.cancellingRunIds.filter(t=>t!==e.id)}}}async continueTerminal(e){if(!(this.workspace===void 0||this.continuingTerminalIds.includes(e))){this.error=void 0,this.continuingTerminalIds=[...this.continuingTerminalIds,e];try{const t=await h.continueTerminal(this.workspace.projectId,this.workspace.id,e,this.machineId);this.terminals=this.terminals.map(i=>i.id===e?t:i),this.socket===void 0&&this.disposeTerminalView(),this.fitAndNotify(),this.terminal?.focus()}catch(t){this.error=t instanceof Error?t.message:String(t)}finally{this.continuingTerminalIds=this.continuingTerminalIds.filter(t=>t!==e)}}}ensureTerminalView(){const e=this.workspace,t=this.terminalHostElement();if(!this.visible||this.terminal!==void 0||this.selectedId===void 0||t===void 0||e===void 0)return;const i=new T(C(this)),n=new S;i.loadAddon(n),i.open(t),this.terminal=i,this.fitAddon=n,this.resizeObserver=new ResizeObserver(()=>{this.fitAndNotify()}),this.resizeObserver.observe(t),i.onData(a=>{this.suppressTerminalInput||this.sendTerminalInput(a)});const r=this.fitTerminal();this.connectSocket(e.projectId,e.id,this.selectedId,i,r),requestAnimationFrame(()=>{this.fitAndNotify()}),i.focus()}connectSocket(e,t,i,n,r){const a=_(e,t,i,r,this.machineId);a.binaryType="arraybuffer",this.socket=a,a.addEventListener("open",()=>{this.fitAndNotify()}),a.addEventListener("message",u=>{this.handleSocketMessage(u.data,i,n)}),a.addEventListener("close",()=>{this.socket===a&&(this.socket=void 0)})}async handleSocketMessage(e,t,i){try{const n=re(await se(e));n.type==="output"&&this.writeTerminalOutput(i,n.data,n.replay===!0),n.type==="exit"&&(i.writeln(`\r
|
|
24
|
+
[进程已退出${n.exitCode===void 0?"":`,退出码 ${String(n.exitCode)}`}]`),this.terminals=this.terminals.map(r=>r.id===t?{...r,exited:!0,...n.exitCode===void 0?{}:{exitCode:n.exitCode}}:r),this.loadCommandRuns()),n.type==="error"&&i.writeln(`\r
|
|
25
|
+
[终端错误:${n.message}]`)}catch(n){i.writeln(`\r
|
|
26
|
+
[终端错误:${n instanceof Error?n.message:String(n)}]`)}}writeTerminalOutput(e,t,i){if(!i){e.write(t);return}this.suppressTerminalInput=!0,e.write(t,()=>{this.suppressTerminalInput=!1})}fitAndNotify(){const e=this.fitTerminal();e!==void 0&&this.send({type:"resize",...e})}fitTerminal(){if(this.fitAddon===void 0||this.terminal===void 0)return;const e=this.fitAddon.proposeDimensions(),t=k(e);if(t!==void 0)return this.fitAddon.fit(),t}measureTerminalSize(){const e=this.fitTerminal();if(e!==void 0)return e;const t=this.terminalHostElement();if(this.terminal!==void 0||t===void 0)return;const i=new T(C(this)),n=new S;i.loadAddon(n),i.open(t);const r=k(n.proposeDimensions());return i.dispose(),r}terminalHostElement(){const e=this.terminalHost;return e instanceof HTMLDivElement?e:void 0}applyTerminalTheme(){this.terminal!==void 0&&(this.terminal.options.theme=L(this))}sendTerminalInput(e){const t=oe(e);t!==""&&this.send({type:"input",data:t})}sendSoftKeyInput(e,t){this.sendTerminalInput(e),t.refocus&&this.focusTerminal()}focusTerminal(){const e=this.terminal;e!==void 0&&(e.focus(),requestAnimationFrame(()=>{e.focus()}))}send(e){this.socket?.readyState===WebSocket.OPEN&&this.socket.send(JSON.stringify(e))}disposeTerminalView(){this.resizeObserver?.disconnect(),this.resizeObserver=void 0,this.socket?.close(),this.socket=void 0,this.terminal?.dispose(),this.terminal=void 0,this.fitAddon=void 0}renderCommandRunNotice(){const e=this.selectedCommandRun();if(e===void 0)return null;const t=this.selectedTerminalInfo();if(v(e)){const i=this.cancellingRunIds.includes(e.id);return l`
|
|
27
27
|
<section class="command-run-notice running">
|
|
28
28
|
<div>
|
|
29
29
|
<strong>${e.title}</strong>
|
|
@@ -35,13 +35,13 @@ import{a as E,n as m,i as R,b as l,t as K,c as h,s as L,d as w,f as _,e as F,r a
|
|
|
35
35
|
`}if(t?.exited===!0){const i=this.continuingTerminalIds.includes(t.id);return l`
|
|
36
36
|
<section class=${`command-run-notice ${e.status}`}>
|
|
37
37
|
<div>
|
|
38
|
-
<strong>${
|
|
38
|
+
<strong>${ne(e)}</strong>
|
|
39
39
|
<p>输出已保留。可继续进入 shell 查看或运行后续命令。</p>
|
|
40
40
|
<code>${e.command}</code>
|
|
41
41
|
</div>
|
|
42
42
|
<button ?disabled=${i} @click=${()=>{this.continueTerminal(t.id)}}>${i?"正在启动 shell…":"在 shell 中继续"}</button>
|
|
43
43
|
</section>
|
|
44
|
-
`}return null}selectedTerminalAcceptsInput(){const e=this.selectedTerminalInfo();return e!==void 0&&!e.exited}shouldShowSoftKeys(){return this.selectedTerminalAcceptsInput()&&this.softKeysEnabled}shouldShowSoftKeysToggle(){return this.selectedTerminalAcceptsInput()}toggleSoftKeys(){this.softKeysEnabled=!this.softKeysEnabled,this.softKeysPreferenceStored=!0,
|
|
44
|
+
`}return null}selectedTerminalAcceptsInput(){const e=this.selectedTerminalInfo();return e!==void 0&&!e.exited}shouldShowSoftKeys(){return this.selectedTerminalAcceptsInput()&&this.softKeysEnabled}shouldShowSoftKeysToggle(){return this.selectedTerminalAcceptsInput()}toggleSoftKeys(){this.softKeysEnabled=!this.softKeysEnabled,this.softKeysPreferenceStored=!0,H(this.softKeysEnabled),this.scheduleFitAndNotify()}renderSoftKeysToggle(){return this.shouldShowSoftKeysToggle()?l`
|
|
45
45
|
<button
|
|
46
46
|
type="button"
|
|
47
47
|
class=${this.softKeysEnabled?"soft-keys-toggle selected":"soft-keys-toggle"}
|
|
@@ -119,4 +119,4 @@ import{a as E,n as m,i as R,b as l,t as K,c as h,s as L,d as w,f as _,e as F,r a
|
|
|
119
119
|
.error { flex: 0 0 auto; margin: 0; padding: 8px; color: var(--pi-danger); border-bottom: 1px solid var(--pi-border); background: var(--pi-surface); }
|
|
120
120
|
.muted { margin: 10px; color: var(--pi-muted); }
|
|
121
121
|
.xterm { height: 100%; }
|
|
122
|
-
`;s([m({attribute:!1})],o.prototype,"workspace",2);s([m()],o.prototype,"machineId",2);s([m({attribute:!1})],o.prototype,"selectedTerminalId",2);s([m({type:Boolean})],o.prototype,"autoStart",2);s([m({attribute:!1})],o.prototype,"onSelectTerminal",2);s([F(".terminal-host")],o.prototype,"terminalHost",2);s([c()],o.prototype,"terminals",2);s([c()],o.prototype,"commandRuns",2);s([c()],o.prototype,"selectedId",2);s([c()],o.prototype,"loading",2);s([c()],o.prototype,"error",2);s([c()],o.prototype,"visible",2);s([c()],o.prototype,"cancellingRunIds",2);s([c()],o.prototype,"continuingTerminalIds",2);s([c()],o.prototype,"defaultSoftKeysEnvironment",2);s([c()],o.prototype,"softKeysEnabled",2);o=s([
|
|
122
|
+
`;s([m({attribute:!1})],o.prototype,"workspace",2);s([m()],o.prototype,"machineId",2);s([m({attribute:!1})],o.prototype,"selectedTerminalId",2);s([m({type:Boolean})],o.prototype,"autoStart",2);s([m({attribute:!1})],o.prototype,"onSelectTerminal",2);s([F(".terminal-host")],o.prototype,"terminalHost",2);s([c()],o.prototype,"terminals",2);s([c()],o.prototype,"commandRuns",2);s([c()],o.prototype,"selectedId",2);s([c()],o.prototype,"loading",2);s([c()],o.prototype,"error",2);s([c()],o.prototype,"visible",2);s([c()],o.prototype,"cancellingRunIds",2);s([c()],o.prototype,"continuingTerminalIds",2);s([c()],o.prototype,"defaultSoftKeysEnvironment",2);s([c()],o.prototype,"softKeysEnabled",2);o=s([R("terminal-panel")],o);function v(e){return e.status==="queued"||e.status==="running"}function ne(e){return e.status==="succeeded"?`命令已成功${e.exitCode===void 0?"":`,退出码 ${String(e.exitCode)}`}`:`命令失败${e.exitCode===void 0?"":`,退出码 ${String(e.exitCode)}`}`}function re(e){const t=JSON.parse(e);if(!le(t))return{type:"error",message:"无效的终端消息"};const i=t;return i.type==="output"&&typeof i.data=="string"?{type:"output",data:i.data,...typeof i.replay=="boolean"?{replay:i.replay}:{}}:i.type==="exit"?{type:"exit",...typeof i.exitCode=="number"?{exitCode:i.exitCode}:{}}:i.type==="error"&&typeof i.message=="string"?{type:"error",message:i.message}:{type:"error",message:"无效的终端消息"}}function oe(e){return e.replaceAll("\x1B[I","").replaceAll("\x1B[O","")}async function se(e){return typeof e=="string"?e:e instanceof ArrayBuffer?new TextDecoder().decode(e):e instanceof Blob?await e.text():String(e)}function C(e){return{...ee,theme:L(e)}}function L(e){return{background:y(e,"--pi-terminal-bg","#05070a"),foreground:y(e,"--pi-terminal-text","#e6edf3"),cursor:y(e,"--pi-accent","#58a6ff"),selectionBackground:y(e,"--pi-terminal-selection","#264f78")}}function y(e,t,i){const n=getComputedStyle(e).getPropertyValue(t).trim();return n===""?i:n}function k(e){if(!(e===void 0||!ae(e.cols,e.rows)))return{cols:Math.floor(e.cols),rows:Math.floor(e.rows)}}function ae(e,t){return Number.isFinite(e)&&Number.isFinite(t)&&e>0&&t>0}function le(e){return typeof e=="object"&&e!==null}export{o as TerminalPanel,oe as filterTerminalInput};
|