pi-web-ui 0.103.1 → 0.103.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,28 @@
1
1
  import { SUBAGENT_PROMPT_SNAPSHOT_CAP } from "./agent-formatters.js";
2
+ /** 子代理是否处于活跃(流式运行中或首轮投递启动中)状态。
3
+ * #589:名额与可见性解耦——仅活跃(非终态)子代理占用 MAX_SUBAGENTS 并发名额;
4
+ * 已结束(done / canceled / error)的子代理保留在左栏供用户审阅追溯,不再占名额。 */
5
+ export function isSubagentActive(conv) {
6
+ if (!conv.isSubagent)
7
+ return false;
8
+ if (conv.promptInFlight)
9
+ return true;
10
+ try {
11
+ return Boolean(conv.session.isStreaming);
12
+ }
13
+ catch {
14
+ return false;
15
+ }
16
+ }
17
+ /** 统计当前占用并发名额的活跃子代理数(含正在创建 runtime 的在途 spawn,不含已终态子代理,#589)。 */
18
+ export function countActiveSubagents(convs, spawningCount = 0) {
19
+ let count = Math.max(0, Math.floor(spawningCount));
20
+ for (const c of convs) {
21
+ if (isSubagentActive(c))
22
+ count++;
23
+ }
24
+ return count;
25
+ }
2
26
  /** 子代理最近一次运行的结局:最后一条 assistant 消息的 errorMessage / stopReason。
3
27
  * 报错 > 中止 > 正常,三者互斥;无 assistant 消息时返回空。 */
4
28
  export function subagentRunOutcome(conv) {
@@ -39,7 +63,14 @@ export function roleOutcomeOf(conv) {
39
63
  }
40
64
  /** 序列化对话为前端可消费的子代理快照 */
41
65
  export function toSubagentSnapshot(conv) {
42
- const streaming = conv.session.isStreaming;
66
+ let sessionStreaming = false;
67
+ try {
68
+ sessionStreaming = Boolean(conv.session.isStreaming);
69
+ }
70
+ catch {
71
+ sessionStreaming = false;
72
+ }
73
+ const streaming = Boolean(sessionStreaming || conv.promptInFlight);
43
74
  const { error, canceled } = subagentRunOutcome(conv);
44
75
  const state = streaming ? "running" : canceled ? "canceled" : "done";
45
76
  let messageCount = 0;
@@ -29,14 +29,22 @@ export function stripAnsi(s) {
29
29
  export const mockThemeProxy = new Proxy({
30
30
  fg: (_color, text) => text,
31
31
  bold: (text) => text,
32
+ italic: (text) => text,
33
+ underline: (text) => text,
34
+ inverse: (text) => text,
32
35
  strikethrough: (text) => text,
33
36
  dim: (text) => text,
34
37
  }, {
35
38
  get(target, prop) {
36
39
  if (prop in target)
37
40
  return target[prop];
38
- // Unknown theme methods → no-op passthrough.
39
- return (_arg, text) => (text !== undefined ? text : "");
41
+ // Unknown theme methods → no-op passthrough。文本永远是**最后一个**参数
42
+ // (`decorate(text)` 与 `color(token, text)` 两种形态都存在),不能假设它固定在第二位,
43
+ // 否则像 `italic(text)` 这类单参数装饰器会把包住的正文整段丢成空串。
44
+ return (...args) => {
45
+ const text = args[args.length - 1];
46
+ return typeof text === "string" ? text : "";
47
+ };
40
48
  },
41
49
  });
42
50
  /** Mock TUI: any method call is a safe no-op. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-web-ui",
3
- "version": "0.103.1",
3
+ "version": "0.103.3",
4
4
  "description": "Just open your browser to get all your work done — browser cockpit for AI coding agents (chat, code, files, terminal, Git in one tab)",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -80,6 +80,17 @@
80
80
  "source": "xing-shuyin/pi-web-ui/plugins/wechat-ilink",
81
81
  "homepage": "https://github.com/xing-shuyin/pi-web-ui/tree/main/plugins/wechat-ilink"
82
82
  },
83
+ {
84
+ "id": "feishu",
85
+ "name": "飞书",
86
+ "nameEn": "Feishu",
87
+ "icon": "🐦",
88
+ "iconSvg": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path d=\"M21 4L10 14\"/><path d=\"M21 4l-6.5 16-4.5-6-6-4.5L21 4z\"/></svg>",
89
+ "description": "飞书工作台:群聊与单聊会话列表 / 消息收发、回复、撤回与表情回应 / 自定义机器人 Webhook 卡片推送 / 新消息轮询提醒 / AI 飞书工具(密钥加密落盘,零外部依赖)。",
90
+ "descriptionEn": "Feishu (Lark) workspace: list chats, read/send/reply/recall messages, emoji reactions, custom bot webhook cards, background polling, and AI feishu tool (encrypted secret storage, zero extra dependencies).",
91
+ "source": "xing-shuyin/pi-web-ui/plugins/feishu",
92
+ "homepage": "https://github.com/xing-shuyin/pi-web-ui/tree/main/plugins/feishu"
93
+ },
83
94
  {
84
95
  "id": "voice-input",
85
96
  "name": "语音输入",
@@ -1,3 +1,3 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,t as n}from"./react-CR5VJ85Q.js";import{n as r,t as i}from"./xterm-Cf5xxe4g.js";import{a,c as o,d as s,f as c,g as l,h as u,i as d,l as f,m as p,o as m,p as h,r as g,s as _,t as v,u as y}from"./index-Pl0V0tEL.js";var b=e(t(),1);function x(e,t){return Math.abs(t)>10&&Math.abs(t)>Math.abs(e)*1.2}function S(e,t){return e-t}var C=n();function w(e){let t=null;return{clean:e.replace(/\r?\n?\[pi-term-exit:(-?\d+)\]\r?\n?/g,(e,n)=>(t=Number(n),`\r
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,t as n}from"./react-CR5VJ85Q.js";import{n as r,t as i}from"./xterm-Cf5xxe4g.js";import{a,c as o,d as s,f as c,g as l,h as u,i as d,l as f,m as p,o as m,p as h,r as g,s as _,t as v,u as y}from"./index-Dt7CQ_Z6.js";var b=e(t(),1);function x(e,t){return Math.abs(t)>10&&Math.abs(t)>Math.abs(e)*1.2}function S(e,t){return e-t}var C=n();function w(e){let t=null;return{clean:e.replace(/\r?\n?\[pi-term-exit:(-?\d+)\]\r?\n?/g,(e,n)=>(t=Number(n),`\r
2
2
  `)).replace(/\r?\n?\x1b\[90m\[(?:进程已退出,退出码 |Process exited with code )-?\d+\]\x1b\[0m\r?\n?/g,`\r
3
3
  `),exitCode:t}}function T({conversationId:e,terminalId:t,command:n,cwd:o,title:s,agentBash:c,active:l,running:u,exitCode:f,register:p}){let h=(0,b.useRef)(null),_=(0,b.useRef)(null),{locale:v}=m(),y=(0,b.useRef)(v);y.current=v;let T=n?JSON.stringify(n):``,E=(0,b.useRef)(u===!1);(0,b.useEffect)(()=>{let u=h.current;if(!u)return;let f=new r({theme:d(),fontFamily:`"SF Mono", "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace`,fontSize:13,cursorBlink:!0,scrollback:8e3}),m=new i;f.loadAddon(m),f.open(u),_.current={term:f,fit:m},l&&f.focus();let v=()=>{f.options.theme=d()};window.addEventListener(g,v),f.attachCustomKeyEventHandler(e=>{if(e.type!==`keydown`)return!0;let t=e.key?.toLowerCase();if((e.ctrlKey||e.metaKey)&&t===`v`)return!1;if(e.ctrlKey&&!e.shiftKey&&!e.altKey&&t===`c`&&f.hasSelection()){let e=f.textarea;return e&&(e.value=f.getSelection(),e.select()),!1}return!0});let b=p(e,t,{write:e=>f.write(w(e).clean),dispose:()=>f.dispose()}),C=()=>{try{m.fit(),a({type:`terminal_resize`,terminalId:t,conversationId:e,cols:f.cols,rows:f.rows})}catch{}},T=requestAnimationFrame(()=>{try{m.fit()}catch{}E.current||a(n?{type:`run_command`,terminalId:t,conversationId:e,command:n,cols:f.cols,rows:f.rows}:{type:`terminal_create`,terminalId:t,title:s,locale:y.current,agentBash:c,conversationId:e,cwd:o,cols:f.cols,rows:f.rows})}),D=f.onData(n=>{a({type:`terminal_input`,terminalId:t,conversationId:e,data:n})}),O=f.element,k=null,A=0,j=0,M=0,N=!1,P=e=>{if(e.touches.length!==1){k=null,N=!1;return}let t=e.touches[0];k=t.identifier,A=t.clientX,j=t.clientY,M=t.clientY,N=!1},F=e=>{if(k===null||e.touches.length!==1)return;let t=e.touches[0];if(t.identifier!==k)return;if(!N){if(!x(t.clientX-A,t.clientY-j))return;N=!0}e.preventDefault();let n=S(M,t.clientY);M=t.clientY,n!==0&&typeof WheelEvent<`u`&&(u.querySelector(`.xterm-viewport`)??O)?.dispatchEvent(new WheelEvent(`wheel`,{bubbles:!0,cancelable:!0,deltaY:n,deltaMode:0,clientX:t.clientX,clientY:t.clientY}))},I=e=>{if(k!==null){if(e.touches.length>0){k=null,N=!1;return}k=null,N=!1}};O?.addEventListener(`touchstart`,P,{passive:!0}),O?.addEventListener(`touchmove`,F,{passive:!1}),O?.addEventListener(`touchend`,I),O?.addEventListener(`touchcancel`,I);let L=null;return typeof ResizeObserver<`u`&&(L=new ResizeObserver(()=>{u.offsetWidth>0&&u.offsetHeight>0&&C()}),L.observe(u)),()=>{cancelAnimationFrame(T),D.dispose(),O?.removeEventListener(`touchstart`,P),O?.removeEventListener(`touchmove`,F),O?.removeEventListener(`touchend`,I),O?.removeEventListener(`touchcancel`,I),window.removeEventListener(g,v),L?.disconnect(),b(),f.dispose(),_.current=null}},[e,t,T,p]),(0,b.useEffect)(()=>{if(!l)return;let n=requestAnimationFrame(()=>{let n=_.current;if(n){try{n.fit.fit(),a({type:`terminal_resize`,terminalId:t,conversationId:e,cols:n.term.cols,rows:n.term.rows})}catch{}n.term.focus()}});return()=>cancelAnimationFrame(n)},[l]);let{t:D}=m(),O=(0,b.useRef)(void 0);return(0,b.useEffect)(()=>{if(u===O.current||(O.current=u,u!==!1))return;let e=_.current;e&&e.term.write(`\r\n\x1b[90m${D(`exitBanner`,{code:f??``})}\x1b[0m\r\n`)},[u,t,f]),(0,C.jsx)(`div`,{ref:h,className:`term-xterm ${l?``:`hidden`}`})}var E={name:``,command:``,cwd:"${pwd}"};function D({chat:e,terminal:t,uiTerminalToolbar:n,onUiAction:r}){let i=_(),[d,m]=(0,b.useState)(null),[g,x]=(0,b.useState)(!1),[S,w]=(0,b.useState)(!1),[D,O]=(0,b.useState)(null),[k,A]=(0,b.useState)(E),[j,M]=(0,b.useState)(null),N=(0,b.useRef)(null),[P,F]=(0,b.useState)(!0),[I,L]=(0,b.useState)(null),[R,z]=(0,b.useState)(``);(0,b.useEffect)(()=>{e.terminals.length===0?m(null):e.terminals.some(e=>e.id===d)||m(e.terminals[e.terminals.length-1].id)},[e.terminals,d]),(0,b.useEffect)(()=>{e.terminalActiveId&&(m(e.terminalActiveId),x(!1))},[e.terminalActiveId]),(0,b.useEffect)(()=>()=>{N.current&&clearTimeout(N.current)},[]);let B=e.terminals.filter(e=>!e.agentBash),V=e.terminals.filter(e=>e.agentBash),H=n=>{if(!e.ready)return;let r=o(),i=e.activeConversationId||e.state?.conversationId||``;t.create({...n,id:r,conversationId:i,cols:n.cols??80,rows:n.rows??24,running:!0,exitCode:null}),m(r),x(!1)},U=()=>H({title:i(`terminalTitle`,{n:B.length+1}),cwd:e.state?.cwd??``}),W=n=>{let r=n.name||n.command,i=e.terminals.find(e=>e.title===r);if(i){t.restart(i.id),m(i.id),a({type:`run_command`,terminalId:i.id,conversationId:i.conversationId,command:n,cols:80,rows:24});return}H({title:r,cwd:e.state?.cwd??``,command:n})},G=n=>{let r=e.terminals.find(e=>e.id===n);if(r&&a({type:`terminal_kill`,terminalId:n,conversationId:r.conversationId}),t.close(n),d===n){let t=e.terminals.filter(e=>e.id!==n);m(t.length>0?t[t.length-1].id:null)}},K=e=>(0,C.jsxs)(`div`,{className:`term-tab ${e.id===d?`active`:``}`,children:[(0,C.jsxs)(`button`,{type:`button`,className:`term-tab-main`,title:`${e.cwd}${e.command?`\n> ${e.command.command}`:``}`,onClick:()=>{I||(m(e.id),x(!1))},children:[(0,C.jsx)(`span`,{className:`term-tab-dot ${e.running?`run`:`exit`}`}),(0,C.jsxs)(`span`,{className:`term-tab-title`,children:[I===e.id?(0,C.jsx)(`input`,{autoFocus:!0,className:`term-tab-rename-input`,value:R,placeholder:e.title,onClick:e=>e.stopPropagation(),onChange:e=>z(e.target.value),onKeyDown:t=>{if(t.stopPropagation(),t.key===`Enter`&&!t.nativeEvent.isComposing){let t=R.trim();t&&a({type:`rename_terminal`,terminalId:e.id,conversationId:e.conversationId,title:t}),L(null)}else t.key===`Escape`&&L(null)},onBlur:()=>L(null)}):e.title,!e.running&&(0,C.jsx)(`span`,{className:`term-tab-exit`,children:i(`exited`,{code:e.exitCode===null?``:` ${e.exitCode}`})})]})]}),(0,C.jsx)(`button`,{type:`button`,className:`term-tab-close term-tab-rename`,title:i(`renameTerminal`),onClick:t=>{t.stopPropagation(),z(e.title),L(e.id)},children:(0,C.jsx)(f,{})}),(0,C.jsx)(`button`,{type:`button`,className:`term-tab-close`,title:i(`closeTerminal`),onClick:()=>G(e.id),children:(0,C.jsx)(l,{})})]},e.id),q=()=>{w(!0),O(null),A(E)},ee=t=>{let n=e.commands[t];n&&(w(!1),O(t),A({name:n.name,command:n.command,cwd:n.cwd??``}))},J=()=>{w(!1),O(null)},Y=()=>{let t=k.name.trim(),n=k.command.trim();if(!t||!n)return;let r={name:t,command:n,cwd:k.cwd.trim()||void 0},i=S?[...e.commands,r]:D===null?e.commands:e.commands.map((e,t)=>t===D?r:e);a({type:`save_commands`,commands:i}),J()},te=t=>{if(j===t){let n=e.commands.filter((e,n)=>n!==t);a({type:`save_commands`,commands:n}),M(null),N.current&&clearTimeout(N.current)}else M(t),N.current&&clearTimeout(N.current),N.current=setTimeout(()=>M(null),2500)},ne=S||D!==null,X=n===void 0?[`host:term-cmd-refresh`,`host:term-cmd-new`,`host:term-tab-new`].map(e=>({id:e,source:`host`})):n.filter(e=>!e.hidden),Z=(e,t)=>{let n=new Set(e);return X.filter(e=>n.has(e.id)||t&&e.source!==`host`)},Q=(e,t)=>{let n=X.find(t=>t.id===e);return n?.labelExplicit?n.label:t},$={"host:term-cmd-refresh":(0,C.jsx)(`button`,{type:`button`,className:`panel-refresh`,title:Q(`host:term-cmd-refresh`,i(`rerun`)),onClick:()=>a({type:`list_commands`}),children:(0,C.jsx)(h,{})}),"host:term-cmd-new":(0,C.jsx)(`button`,{type:`button`,className:`panel-new`,title:Q(`host:term-cmd-new`,i(`newCommand`)),onClick:q,children:(0,C.jsx)(c,{})}),"host:term-tab-new":(0,C.jsx)(`button`,{type:`button`,className:`panel-new`,title:Q(`host:term-tab-new`,i(`newTerminal`)),onClick:U,children:(0,C.jsx)(c,{})})};return(0,C.jsxs)(`div`,{className:`terminal-view`,children:[(0,C.jsxs)(`aside`,{className:`term-side term-commands ${g?`open`:``}`,children:[(0,C.jsxs)(`div`,{className:`panel-header`,children:[(0,C.jsx)(`span`,{className:`panel-title`,children:i(`commands`)}),(0,C.jsx)(`div`,{className:`panel-header-actions`,children:v(Z([`host:term-cmd-refresh`,`host:term-cmd-new`],!1),$,r)})]}),(0,C.jsx)(`div`,{className:`panel-body`,children:ne?(0,C.jsxs)(`div`,{className:`cmd-form`,children:[(0,C.jsx)(`label`,{htmlFor:`cmd-name`,children:i(`name`)}),(0,C.jsx)(`input`,{id:`cmd-name`,className:`cmd-input`,value:k.name,placeholder:i(`exampleName`),autoFocus:!0,onChange:e=>A({...k,name:e.target.value})}),(0,C.jsx)(`label`,{htmlFor:`cmd-command`,children:i(`command`)}),(0,C.jsx)(`input`,{id:`cmd-command`,className:`cmd-input`,value:k.command,placeholder:i(`exampleCommand`),onChange:e=>A({...k,command:e.target.value}),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&Y()}}),(0,C.jsxs)(`label`,{htmlFor:`cmd-cwd`,children:[i(`directory`),` `,(0,C.jsx)(`span`,{className:`cmd-hint`,children:i(`cwdHint`)})]}),(0,C.jsx)(`input`,{id:`cmd-cwd`,className:`cmd-input`,value:k.cwd,placeholder:"${pwd}",onChange:e=>A({...k,cwd:e.target.value}),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&Y()}}),(0,C.jsxs)(`div`,{className:`cmd-form-actions`,children:[(0,C.jsx)(`button`,{type:`button`,className:`btn`,onClick:J,children:i(`cancel`)}),(0,C.jsx)(`button`,{type:`button`,className:`btn primary`,disabled:!k.name.trim()||!k.command.trim(),onClick:Y,children:i(`save`)})]})]}):(0,C.jsxs)(C.Fragment,{children:[e.commands.length===0&&(0,C.jsx)(`div`,{className:`panel-empty`,children:i(`noCommands`)}),e.commands.map((e,t)=>(0,C.jsxs)(`div`,{className:`cmd-item`,children:[(0,C.jsx)(`button`,{type:`button`,className:`cmd-run`,title:i(`clickToRun`),onClick:()=>W(e),children:(0,C.jsx)(s,{})}),(0,C.jsxs)(`button`,{type:`button`,className:`cmd-main`,title:i(`clickToRun`),onClick:()=>W(e),children:[(0,C.jsx)(`span`,{className:`cmd-name`,children:e.name}),(0,C.jsx)(`span`,{className:`cmd-command`,children:e.command}),e.cwd&&(0,C.jsx)(`span`,{className:`cmd-cwd`,children:e.cwd})]}),(0,C.jsx)(`button`,{type:`button`,className:`cmd-act`,title:i(`edit`),onClick:()=>ee(t),children:(0,C.jsx)(f,{})}),(0,C.jsx)(`button`,{type:`button`,className:`cmd-act del ${j===t?`confirm`:``}`,title:i(`delete`),onClick:()=>te(t),children:j===t?i(`confirmQ`):(0,C.jsx)(u,{})})]},t))]})}),(0,C.jsxs)(`div`,{className:`term-tabs-block`,children:[(0,C.jsxs)(`div`,{className:`panel-header`,children:[(0,C.jsx)(`span`,{className:`panel-title`,children:i(`terminal`)}),v(Z([`host:term-tab-new`],!0),$,r)]}),(0,C.jsxs)(`div`,{className:`panel-body`,children:[e.terminals.length===0&&(0,C.jsx)(`div`,{className:`panel-empty`,children:i(`noTerminal`)}),B.map(K),V.length>0&&(0,C.jsxs)(`div`,{className:`term-folder`,children:[(0,C.jsxs)(`button`,{type:`button`,className:`term-folder-header ${P?`open`:``}`,title:i(`aiBashGroup`),onClick:()=>F(e=>!e),children:[(0,C.jsx)(`span`,{className:`term-folder-caret`,children:P?`▾`:`▸`}),(0,C.jsx)(`span`,{className:`term-folder-title`,children:i(`aiBashGroup`)}),(0,C.jsx)(`span`,{className:`term-folder-count`,children:V.length})]}),P&&(0,C.jsx)(`div`,{className:`term-folder-body`,children:V.map(K)})]})]})]})]}),(0,C.jsxs)(`div`,{className:`term-main`,children:[g&&(0,C.jsx)(`div`,{className:`drawer-backdrop`,onClick:()=>x(!1)}),(0,C.jsx)(`button`,{type:`button`,className:`term-side-toggle`,title:i(`commands`),onClick:()=>x(e=>!e),children:(0,C.jsx)(y,{})}),e.terminals.length===0?(0,C.jsxs)(`div`,{className:`term-empty`,children:[(0,C.jsx)(p,{className:`term-empty-icon`}),(0,C.jsx)(`div`,{className:`term-empty-title`,children:i(`builtinTerminal`)}),(0,C.jsx)(`div`,{className:`term-empty-sub`,children:i(`termEmptySub`)})]}):e.terminals.map(e=>(0,C.jsx)(T,{conversationId:e.conversationId,terminalId:e.id,command:e.command,cwd:e.cwd,title:e.title,agentBash:e.agentBash,active:e.id===d,running:e.running,exitCode:e.exitCode,register:t.register},`${e.conversationId}:${e.id}`))]})]})}export{D as TerminalPanel};