pi-web-ui 0.89.0 → 0.90.0
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/CHANGELOG.md +39 -1
- package/dist/server/agent-service.js +106 -23
- package/dist/server/auth-cookie.js +23 -0
- package/dist/server/client-state.js +13 -0
- package/dist/server/composer-drafts.js +20 -2
- package/dist/server/dsh/dsh-agent-service.js +14 -8
- package/dist/server/file-archives.js +258 -0
- package/dist/server/file-transfer-routes.js +113 -0
- package/dist/server/files-service.js +22 -3
- package/dist/server/index.js +115 -24
- package/dist/server/marker-service.js +3 -1
- package/dist/server/plugins.js +12 -4
- package/dist/server/queue-utils.js +16 -0
- package/dist/server/schedule-agent-tool.js +240 -0
- package/dist/server/scheduler-tasks.js +9 -0
- package/dist/server/settings-service.js +68 -1
- package/dist/server/tool-manager.js +11 -1
- package/dist/server/update-check.js +10 -6
- package/dist/server/webui-context.js +4 -0
- package/dist/server/ws-unknown-types.js +44 -0
- package/package.json +5 -2
- package/web/dist/assets/TerminalPanel-BDbdLhpT.js +6 -0
- package/web/dist/assets/index-1f_DP8S3.js +380 -0
- package/web/dist/assets/index-DeUwDA-C.css +10 -0
- package/web/dist/index.html +2 -2
- package/web/dist/assets/TerminalPanel-BOUmN3uu.js +0 -6
- package/web/dist/assets/index-3XU67qMh.js +0 -376
- package/web/dist/assets/index-B-gdvWtW.css +0 -10
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* 预设存取 + 何时需要 reload」,真正动 runtime 的 session.reload() 走宿主回调
|
|
7
7
|
* (reloadSession 里还会刷新斜杠命令目录)。
|
|
8
8
|
*/
|
|
9
|
-
import { existsSync, readdirSync } from "node:fs";
|
|
9
|
+
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
10
10
|
import { basename, dirname, join } from "node:path";
|
|
11
11
|
import { fileURLToPath } from "node:url";
|
|
12
12
|
import { extensionKey, normalizeDisabledPluginTools, normalizeRetryMaxAttempts, normalizeSkillList, normalizeUiLayout, } from "./client-state.js";
|
|
@@ -105,15 +105,65 @@ export class SettingsService {
|
|
|
105
105
|
}
|
|
106
106
|
return false;
|
|
107
107
|
}
|
|
108
|
+
/** 判断某个扩展 id 是否仍存在(loader 之外的兜底,供禁用残留清理用):
|
|
109
|
+
* npm: 包 → 任一 npm 根还有目录,或还列在任一 settings.json packages 里
|
|
110
|
+
* (只删了 node_modules 但配置还在 = 保守保留,等下次 loader 同步);
|
|
111
|
+
* 路径型 → 文件/目录任一存在。空串一律不存在。 */
|
|
112
|
+
extensionStillOnDisk(id) {
|
|
113
|
+
if (!id)
|
|
114
|
+
return false;
|
|
115
|
+
if (id.startsWith("npm:")) {
|
|
116
|
+
const pkg = id.slice(4);
|
|
117
|
+
if (!pkg)
|
|
118
|
+
return false;
|
|
119
|
+
const cwd = this.host.cwd();
|
|
120
|
+
const agentDir = this.host.agentDir();
|
|
121
|
+
for (const npmRoot of [join(agentDir, "npm", "node_modules"), join(cwd, ".pi", "npm", "node_modules")]) {
|
|
122
|
+
try {
|
|
123
|
+
if (existsSync(join(npmRoot, pkg)))
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
catch { }
|
|
127
|
+
}
|
|
128
|
+
return this.packageStillListed(pkg);
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
return existsSync(id);
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/** 包名是否还列在全局/项目 settings.json 的 packages 里(文件缺失/坏 JSON 当没列)。 */
|
|
138
|
+
packageStillListed(pkg) {
|
|
139
|
+
const wanted = `npm:${pkg}`;
|
|
140
|
+
for (const file of [join(this.host.agentDir(), "settings.json"), join(this.host.cwd(), ".pi", "settings.json")]) {
|
|
141
|
+
try {
|
|
142
|
+
const parsed = JSON.parse(readFileSync(file, "utf8"));
|
|
143
|
+
if (!Array.isArray(parsed?.packages))
|
|
144
|
+
continue;
|
|
145
|
+
for (const entry of parsed.packages) {
|
|
146
|
+
if (typeof entry !== "string")
|
|
147
|
+
continue;
|
|
148
|
+
if (entry === wanted || entry === pkg)
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
catch { }
|
|
153
|
+
}
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
108
156
|
push() {
|
|
109
157
|
const disabledSkills = new Set(this.settings.disabledSkills);
|
|
110
158
|
const reviewDisabledSkills = new Set(this.settings.reviewDisabledSkills);
|
|
111
159
|
const disabledExts = new Set(this.settings.disabledExtensions);
|
|
112
160
|
let loadedSkillNames = null;
|
|
161
|
+
let loadedExtNames = null;
|
|
113
162
|
try {
|
|
114
163
|
const loadedSkills = this.host.getSession().resourceLoader.getSkills().skills;
|
|
115
164
|
const loadedExts = this.host.getSession().resourceLoader.getExtensions().extensions;
|
|
116
165
|
loadedSkillNames = new Set(loadedSkills.map((s) => s.name));
|
|
166
|
+
loadedExtNames = new Set(loadedExts.map((e) => extensionKey(e)));
|
|
117
167
|
// Prune entries that no longer exist on disk AND aren't disabled
|
|
118
168
|
// (e.g. a skill/extension file was deleted). Disabled entries are
|
|
119
169
|
// kept so they can be re-enabled even when filtered out of the loader.
|
|
@@ -179,6 +229,18 @@ export class SettingsService {
|
|
|
179
229
|
// Disabled entries that still exist on disk are re-added (with the
|
|
180
230
|
// last-known description) so they can be re-enabled; entries whose
|
|
181
231
|
// source file was deleted are dropped instead of being resurrected.
|
|
232
|
+
// disabledExtensions 同理:已卸载(loader 里没有、磁盘/配置里也没有)的扩展
|
|
233
|
+
// 从禁用记录里剔除并持久化 —— 否则卸载过的扩展以“已禁用”灰条永生(issue #192)。
|
|
234
|
+
// loadedExtNames 非 null 即 session 就绪;取不到(catch 分支)时保守跳过。
|
|
235
|
+
if (loadedExtNames !== null) {
|
|
236
|
+
const staleExts = this.settings.disabledExtensions.filter((id) => !loadedExtNames.has(id) && !this.extensionStillOnDisk(id));
|
|
237
|
+
if (staleExts.length > 0) {
|
|
238
|
+
this.settings.disabledExtensions = this.settings.disabledExtensions.filter((n) => !staleExts.includes(n));
|
|
239
|
+
this.host.stateStore.saveSettings(this.host.clientId, {
|
|
240
|
+
disabledExtensions: this.settings.disabledExtensions,
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
}
|
|
182
244
|
for (const name of this.settings.disabledSkills) {
|
|
183
245
|
if (this.knownSkills.has(name))
|
|
184
246
|
continue;
|
|
@@ -186,8 +248,12 @@ export class SettingsService {
|
|
|
186
248
|
continue;
|
|
187
249
|
this.knownSkills.set(name, { name, description: "", enabled: false });
|
|
188
250
|
}
|
|
251
|
+
// (上面的 stale 清理已把卸载项移出禁用记录;这里再按磁盘挡一次,
|
|
252
|
+
// session 未就绪跳过清理时也不复活幽灵。)
|
|
189
253
|
for (const id of this.settings.disabledExtensions) {
|
|
190
254
|
if (!this.knownExtensions.has(id)) {
|
|
255
|
+
if (!this.extensionStillOnDisk(id))
|
|
256
|
+
continue;
|
|
191
257
|
this.knownExtensions.set(id, {
|
|
192
258
|
id,
|
|
193
259
|
name: id.startsWith("npm:") ? id : basename(id),
|
|
@@ -630,6 +696,7 @@ export class SettingsService {
|
|
|
630
696
|
this.host.emit({ type: "notice", level: "info", text: "设置已应用", textEn: "Settings applied" });
|
|
631
697
|
}
|
|
632
698
|
catch (err) {
|
|
699
|
+
console.error(`[settings] apply reload failed (client ${this.host.clientId}):`, err);
|
|
633
700
|
this.host.emit({
|
|
634
701
|
type: "notice",
|
|
635
702
|
level: "error",
|
|
@@ -50,9 +50,14 @@ export const BROWSER_PAGE_TOOL_NAME = "browser_page";
|
|
|
50
50
|
/** 别的对话读取工具(定义见 conversation-read-tool.ts):运行中对话(含子代理)+
|
|
51
51
|
* 历史会话转录,只读。 */
|
|
52
52
|
export const CONVERSATION_READ_TOOL_NAME = "conversation_read";
|
|
53
|
+
/** 定时任务工具(定义见 schedule-agent-tool.ts):创建/查看/取消内置调度任务,
|
|
54
|
+
* 到期自动唤醒发起对话执行 prompt 并汇报。 */
|
|
55
|
+
export const SCHEDULE_TASK_TOOL_NAME = "schedule_task";
|
|
56
|
+
export const SCHEDULE_LIST_TOOL_NAME = "schedule_list";
|
|
57
|
+
export const SCHEDULE_CANCEL_TOOL_NAME = "schedule_cancel";
|
|
53
58
|
/** 旧工具名(持久化迁移用;新代码一律用 MARKERS_LIST_TOOL_NAME)。 */
|
|
54
59
|
export const LEGACY_MARKERS_LIST_TOOL_NAME = "markers_list";
|
|
55
|
-
/** 可开关的 Agent 工具总目录(共
|
|
60
|
+
/** 可开关的 Agent 工具总目录(共 23 个;bash 本体与 SDK 内置 edit/read
|
|
56
61
|
* 不进目录——关了 agent 就残了,不给关)。 */
|
|
57
62
|
export const AGENT_TOOL_CATALOG = [
|
|
58
63
|
...TERMINAL_TOOL_NAMES.map((name) => ({
|
|
@@ -76,6 +81,11 @@ export const AGENT_TOOL_CATALOG = [
|
|
|
76
81
|
{ name: BROWSER_PAGE_TOOL_NAME, group: "other", defaultOn: false, dshVisible: false },
|
|
77
82
|
// 只读别的对话(含子代理实时消息与历史转录),默认开;DSH 引擎没有该 customTool。
|
|
78
83
|
{ name: CONVERSATION_READ_TOOL_NAME, group: "other", defaultOn: true, dshVisible: false },
|
|
84
|
+
// 定时/延时唤醒:默认开(不打开 AI 根本不知道能定时;60s 间隔底线+面板可随时取消),
|
|
85
|
+
// DSH 引擎没有该 customTool(走 goal-rpc,无 customTool 注册面)。
|
|
86
|
+
{ name: SCHEDULE_TASK_TOOL_NAME, group: "other", defaultOn: true, dshVisible: false },
|
|
87
|
+
{ name: SCHEDULE_LIST_TOOL_NAME, group: "other", defaultOn: true, dshVisible: false },
|
|
88
|
+
{ name: SCHEDULE_CANCEL_TOOL_NAME, group: "other", defaultOn: true, dshVisible: false },
|
|
79
89
|
];
|
|
80
90
|
const KNOWN_NAMES = new Set(AGENT_TOOL_CATALOG.map((t) => t.name));
|
|
81
91
|
/** 是否为本表登记的可开关工具(未知名一律 false,不抛错)。 */
|
|
@@ -265,12 +265,16 @@ function readSettingsPackagesFile(file) {
|
|
|
265
265
|
function readGitCloneNameVersion(installDir) {
|
|
266
266
|
try {
|
|
267
267
|
const pkg = JSON.parse(readFileSync(join(installDir, "package.json"), "utf8"));
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
268
|
+
// Name and version fall back independently: a clone with a version but
|
|
269
|
+
// no usable name still reports its version (name falls back to the
|
|
270
|
+
// source shorthand at the call site), and vice versa.
|
|
271
|
+
return {
|
|
272
|
+
...(typeof pkg.name === "string" && pkg.name ? { name: pkg.name } : {}),
|
|
273
|
+
...(typeof pkg.version === "string" && pkg.version ? { version: pkg.version } : {}),
|
|
274
|
+
};
|
|
271
275
|
}
|
|
272
276
|
catch {
|
|
273
|
-
return
|
|
277
|
+
return {};
|
|
274
278
|
}
|
|
275
279
|
}
|
|
276
280
|
/**
|
|
@@ -301,8 +305,8 @@ export function listGitExtensions(agentDir, projectCwd, env = process.env) {
|
|
|
301
305
|
const installDir = join(gitRoot, parsed.host, ...parsed.path.split("/"));
|
|
302
306
|
const nv = readGitCloneNameVersion(installDir);
|
|
303
307
|
out.push({
|
|
304
|
-
name: nv
|
|
305
|
-
version: nv
|
|
308
|
+
name: nv.name ?? parsed.shorthand,
|
|
309
|
+
version: nv.version ?? "?",
|
|
306
310
|
kind: "git-extension",
|
|
307
311
|
source: parsed.shorthand,
|
|
308
312
|
installDir,
|
|
@@ -104,6 +104,10 @@ export class WebUIContext {
|
|
|
104
104
|
}
|
|
105
105
|
this.push();
|
|
106
106
|
};
|
|
107
|
+
/** Whether any widgets are mounted — the 2s poll skips refresh when false. */
|
|
108
|
+
hasWidgets() {
|
|
109
|
+
return this.widgets.size > 0;
|
|
110
|
+
}
|
|
107
111
|
/** Re-render all widgets and push when content changed (polled + on demand). */
|
|
108
112
|
refresh() {
|
|
109
113
|
let changed = false;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unknown inbound WS message-type counter —— 独立成模块是为了可单测
|
|
3
|
+
* (`server/index.ts` 起 WS + SDK,不适合在单测里 import)。
|
|
4
|
+
*
|
|
5
|
+
* 背景:`dispatch` 的 `switch (msg.type)` 的 `default:` 分支原来是空的,
|
|
6
|
+
* 版本错位(旧前端/新服务端)或插件发错 type 时静默丢弃,只能抓包排查。
|
|
7
|
+
* 这里只做计数 + 节流 warn,不改变任何已知类型的行为。
|
|
8
|
+
*/
|
|
9
|
+
/** 同一 type 两次 warn 之间最小间隔(防刷屏),可单测覆盖。 */
|
|
10
|
+
export const UNKNOWN_WS_WARN_INTERVAL_MS = 60_000;
|
|
11
|
+
/** 未知 type 种类上限:type 字符串远端可控,无上限则内存无界增长。
|
|
12
|
+
* 超限后的新 type 不再建 key,只进溢出计数。 */
|
|
13
|
+
export const MAX_UNKNOWN_WS_TYPES = 500;
|
|
14
|
+
const counts = new Map();
|
|
15
|
+
const lastWarnAt = new Map();
|
|
16
|
+
let overflowed = 0;
|
|
17
|
+
/**
|
|
18
|
+
* 记录一次未知 type,计数永远 +1;同一 type 在 `UNKNOWN_WS_WARN_INTERVAL_MS`
|
|
19
|
+
* 内只返回一次 `warn: true`(调用方决定是否 `console.warn`)。
|
|
20
|
+
*/
|
|
21
|
+
export function recordUnknownWsType(type, now = Date.now()) {
|
|
22
|
+
if (!counts.has(type) && counts.size >= MAX_UNKNOWN_WS_TYPES) {
|
|
23
|
+
overflowed++;
|
|
24
|
+
return { count: overflowed, warn: false };
|
|
25
|
+
}
|
|
26
|
+
const count = (counts.get(type) ?? 0) + 1;
|
|
27
|
+
counts.set(type, count);
|
|
28
|
+
const last = lastWarnAt.get(type) ?? -Infinity;
|
|
29
|
+
if (now - last >= UNKNOWN_WS_WARN_INTERVAL_MS) {
|
|
30
|
+
lastWarnAt.set(type, now);
|
|
31
|
+
return { count, warn: true };
|
|
32
|
+
}
|
|
33
|
+
return { count, warn: false };
|
|
34
|
+
}
|
|
35
|
+
/** 只读快照(排障用,返回拷贝,调用方改不动内部表)。 */
|
|
36
|
+
export function unknownWsCounts() {
|
|
37
|
+
return new Map(counts);
|
|
38
|
+
}
|
|
39
|
+
/** 单测隔离用。 */
|
|
40
|
+
export function resetUnknownWsTypes() {
|
|
41
|
+
counts.clear();
|
|
42
|
+
lastWarnAt.clear();
|
|
43
|
+
overflowed = 0;
|
|
44
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-web-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.90.0",
|
|
4
4
|
"description": "Web chat interface for the pi coding agent, powered by the pi SDK (@earendil-works/pi-coding-agent) — one-command run, Docker/systemd/launchd deployable",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -103,8 +103,10 @@
|
|
|
103
103
|
"remark-breaks": "^4.0.0",
|
|
104
104
|
"remark-gfm": "^4.0.0",
|
|
105
105
|
"remark-math": "^6.0.0",
|
|
106
|
+
"tar": "^7.5.22",
|
|
106
107
|
"typebox": "^1.3.14",
|
|
107
|
-
"ws": "^8.18.0"
|
|
108
|
+
"ws": "^8.18.0",
|
|
109
|
+
"yauzl": "^3.4.0"
|
|
108
110
|
},
|
|
109
111
|
"devDependencies": {
|
|
110
112
|
"@types/compression": "^1.8.1",
|
|
@@ -113,6 +115,7 @@
|
|
|
113
115
|
"@types/react": "^18.3.12",
|
|
114
116
|
"@types/react-dom": "^18.3.1",
|
|
115
117
|
"@types/ws": "^8.5.13",
|
|
118
|
+
"@types/yauzl": "^3.4.0",
|
|
116
119
|
"@vitejs/plugin-react": "^4.3.4",
|
|
117
120
|
"concurrently": "^9.1.0",
|
|
118
121
|
"cross-env": "^10.1.0",
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{a as l,j as t}from"./markdown-D3PKeHAZ.js";import{u as z,b as L,T as q,a as p,c as se,F as G,d as re,r as J,e as ae,f as U,g as ie,h as le,i as oe,j as ce,k as me}from"./index-1f_DP8S3.js";import{l as ge}from"./index-1f_DP8S3.js";import{D as de,o as ue}from"./xterm-B96xOxS9.js";import"./react-w24rH0km.js";function fe(n){let o=null;return{clean:n.replace(/\r?\n?\[pi-term-exit:(-?\d+)\]\r?\n?/g,(k,r)=>(o=Number(r),`\r
|
|
2
|
+
`)).replace(/\r?\n?\x1b\[90m\[(?:进程已退出,退出码 |Process exited with code )-?\d+\]\x1b\[0m\r?\n?/g,`\r
|
|
3
|
+
`),exitCode:o}}function pe({conversationId:n,terminalId:o,command:h,cwd:k,title:r,agentBash:N,active:u,running:j,exitCode:w,register:R}){const C=l.useRef(null),y=l.useRef(null),{locale:T}=z(),c=l.useRef(T);c.current=T;const v=h?JSON.stringify(h):"",F=l.useRef(j===!1);l.useEffect(()=>{const m=C.current;if(!m)return;const a=new de({theme:L(),fontFamily:'"SF Mono", "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace',fontSize:13,cursorBlink:!0,scrollback:8e3}),b=new ue;a.loadAddon(b),a.open(m),y.current={term:a,fit:b},u&&a.focus();const g=()=>{a.options.theme=L()};window.addEventListener(q,g),a.attachCustomKeyEventHandler(d=>{if(d.type!=="keydown")return!0;const _=d.key?.toLowerCase();if((d.ctrlKey||d.metaKey)&&_==="v")return!1;if(d.ctrlKey&&!d.shiftKey&&!d.altKey&&_==="c"&&a.hasSelection()){const B=a.textarea;return B&&(B.value=a.getSelection(),B.select()),!1}return!0});const $=R(n,o,{write:d=>a.write(fe(d).clean),dispose:()=>a.dispose()}),A=()=>{try{b.fit(),p({type:"terminal_resize",terminalId:o,conversationId:n,cols:a.cols,rows:a.rows})}catch{}},I=requestAnimationFrame(()=>{try{b.fit()}catch{}F.current||(h?p({type:"run_command",terminalId:o,conversationId:n,command:h,cols:a.cols,rows:a.rows}):p({type:"terminal_create",terminalId:o,title:r,locale:c.current,agentBash:N,conversationId:n,cwd:k,cols:a.cols,rows:a.rows}))}),S=a.onData(d=>{p({type:"terminal_input",terminalId:o,conversationId:n,data:d})});let E=null;return typeof ResizeObserver<"u"&&(E=new ResizeObserver(()=>{m.offsetWidth>0&&m.offsetHeight>0&&A()}),E.observe(m)),()=>{cancelAnimationFrame(I),S.dispose(),window.removeEventListener(q,g),E?.disconnect(),$(),a.dispose(),y.current=null}},[n,o,v,R]),l.useEffect(()=>{if(!u)return;const m=requestAnimationFrame(()=>{const a=y.current;if(a){try{a.fit.fit(),p({type:"terminal_resize",terminalId:o,conversationId:n,cols:a.term.cols,rows:a.term.rows})}catch{}a.term.focus()}});return()=>cancelAnimationFrame(m)},[u]);const{t:D}=z(),x=l.useRef(void 0);return l.useEffect(()=>{if(j===x.current||(x.current=j,j!==!1))return;const m=y.current;m&&m.term.write(`\r
|
|
4
|
+
\x1B[90m${D("exitBanner",{code:w??""})}\x1B[0m\r
|
|
5
|
+
`)},[j,o,w]),t.jsx("div",{ref:C,className:`term-xterm ${u?"":"hidden"}`})}const X={name:"",command:"",cwd:"${pwd}"};function Ne({chat:n,terminal:o,uiTerminalToolbar:h,onUiAction:k}){const r=se(),[N,u]=l.useState(null),[j,w]=l.useState(!1),[R,C]=l.useState(!1),[y,T]=l.useState(null),[c,v]=l.useState(X),[F,D]=l.useState(null),x=l.useRef(null),[m,a]=l.useState(!0),[b,g]=l.useState(null),[$,A]=l.useState("");l.useEffect(()=>{n.terminals.length===0?u(null):n.terminals.some(e=>e.id===N)||u(n.terminals[n.terminals.length-1].id)},[n.terminals,N]),l.useEffect(()=>{n.terminalActiveId&&(u(n.terminalActiveId),w(!1))},[n.terminalActiveId]),l.useEffect(()=>()=>{x.current&&clearTimeout(x.current)},[]);const I=n.terminals.filter(e=>!e.agentBash),S=n.terminals.filter(e=>e.agentBash),E=e=>{if(!n.ready)return;const s=me(),i=n.activeConversationId||n.state?.conversationId||"";o.create({...e,id:s,conversationId:i,cols:e.cols??80,rows:e.rows??24,running:!0,exitCode:null}),u(s),w(!1)},d=()=>E({title:r("terminalTitle",{n:I.length+1}),cwd:n.state?.cwd??""}),_=e=>{const s=e.name||e.command,i=n.terminals.find(f=>f.title===s);if(i){o.restart(i.id),u(i.id),p({type:"run_command",terminalId:i.id,conversationId:i.conversationId,command:e,cols:80,rows:24});return}E({title:s,cwd:n.state?.cwd??"",command:e})},B=e=>{const s=n.terminals.find(i=>i.id===e);if(s&&p({type:"terminal_kill",terminalId:e,conversationId:s.conversationId}),o.close(e),N===e){const i=n.terminals.filter(f=>f.id!==e);u(i.length>0?i[i.length-1].id:null)}},M=e=>t.jsxs("div",{className:`term-tab ${e.id===N?"active":""}`,children:[t.jsxs("button",{type:"button",className:"term-tab-main",title:`${e.cwd}${e.command?`
|
|
6
|
+
> ${e.command.command}`:""}`,onClick:()=>{b||(u(e.id),w(!1))},children:[t.jsx("span",{className:`term-tab-dot ${e.running?"run":"exit"}`}),t.jsxs("span",{className:"term-tab-title",children:[b===e.id?t.jsx("input",{autoFocus:!0,className:"term-tab-rename-input",value:$,placeholder:e.title,onClick:s=>s.stopPropagation(),onChange:s=>A(s.target.value),onKeyDown:s=>{if(s.stopPropagation(),s.key==="Enter"&&!s.nativeEvent.isComposing){const i=$.trim();i&&p({type:"rename_terminal",terminalId:e.id,conversationId:e.conversationId,title:i}),g(null)}else s.key==="Escape"&&g(null)},onBlur:()=>g(null)}):e.title,!e.running&&t.jsx("span",{className:"term-tab-exit",children:r("exited",{code:e.exitCode===null?"":` ${e.exitCode}`})})]})]}),t.jsx("button",{type:"button",className:"term-tab-close term-tab-rename",title:r("renameTerminal"),onClick:s=>{s.stopPropagation(),A(e.title),g(e.id)},children:t.jsx(U,{})}),t.jsx("button",{type:"button",className:"term-tab-close",title:r("closeTerminal"),onClick:()=>B(e.id),children:t.jsx(ce,{})})]},e.id),Q=()=>{C(!0),T(null),v(X)},V=e=>{const s=n.commands[e];s&&(C(!1),T(e),v({name:s.name,command:s.command,cwd:s.cwd??""}))},O=()=>{C(!1),T(null)},K=()=>{const e=c.name.trim(),s=c.command.trim();if(!e||!s)return;const i=c.cwd.trim(),f={name:e,command:s,cwd:i||void 0},ee=R?[...n.commands,f]:y!==null?n.commands.map((te,ne)=>ne===y?f:te):n.commands;p({type:"save_commands",commands:ee}),O()},W=e=>{if(F===e){const s=n.commands.filter((i,f)=>f!==e);p({type:"save_commands",commands:s}),D(null),x.current&&clearTimeout(x.current)}else D(e),x.current&&clearTimeout(x.current),x.current=setTimeout(()=>D(null),2500)},Y=R||y!==null,Z=h===void 0?["host:term-cmd-refresh","host:term-cmd-new","host:term-tab-new"].map(e=>({id:e,source:"host"})):h.filter(e=>!e.hidden),P=(e,s)=>{const i=new Set(e);return Z.filter(f=>i.has(f.id)||s&&f.source!=="host")},H={"host:term-cmd-refresh":t.jsx("button",{type:"button",className:"panel-refresh",title:r("rerun"),onClick:()=>p({type:"list_commands"}),children:t.jsx(re,{})}),"host:term-cmd-new":t.jsx("button",{type:"button",className:"panel-new",title:r("newCommand"),onClick:Q,children:t.jsx(G,{})}),"host:term-tab-new":t.jsx("button",{type:"button",className:"panel-new",title:r("newTerminal"),onClick:d,children:t.jsx(G,{})})};return t.jsxs("div",{className:"terminal-view",children:[t.jsxs("aside",{className:`term-side term-commands ${j?"open":""}`,children:[t.jsxs("div",{className:"panel-header",children:[t.jsx("span",{className:"panel-title",children:r("commands")}),t.jsx("div",{className:"panel-header-actions",children:J(P(["host:term-cmd-refresh","host:term-cmd-new"],!1),H,k)})]}),t.jsx("div",{className:"panel-body",children:Y?t.jsxs("div",{className:"cmd-form",children:[t.jsx("label",{htmlFor:"cmd-name",children:r("name")}),t.jsx("input",{id:"cmd-name",className:"cmd-input",value:c.name,placeholder:r("exampleName"),autoFocus:!0,onChange:e=>v({...c,name:e.target.value})}),t.jsx("label",{htmlFor:"cmd-command",children:r("command")}),t.jsx("input",{id:"cmd-command",className:"cmd-input",value:c.command,placeholder:r("exampleCommand"),onChange:e=>v({...c,command:e.target.value}),onKeyDown:e=>{e.key==="Enter"&&!e.nativeEvent.isComposing&&K()}}),t.jsxs("label",{htmlFor:"cmd-cwd",children:[r("directory")," ",t.jsx("span",{className:"cmd-hint",children:r("cwdHint")})]}),t.jsx("input",{id:"cmd-cwd",className:"cmd-input",value:c.cwd,placeholder:"${pwd}",onChange:e=>v({...c,cwd:e.target.value}),onKeyDown:e=>{e.key==="Enter"&&!e.nativeEvent.isComposing&&K()}}),t.jsxs("div",{className:"cmd-form-actions",children:[t.jsx("button",{type:"button",className:"btn",onClick:O,children:r("cancel")}),t.jsx("button",{type:"button",className:"btn primary",disabled:!c.name.trim()||!c.command.trim(),onClick:K,children:r("save")})]})]}):t.jsxs(t.Fragment,{children:[n.commands.length===0&&t.jsx("div",{className:"panel-empty",children:r("noCommands")}),n.commands.map((e,s)=>t.jsxs("div",{className:"cmd-item",children:[t.jsx("button",{type:"button",className:"cmd-run",title:r("clickToRun"),onClick:()=>_(e),children:t.jsx(ae,{})}),t.jsxs("button",{type:"button",className:"cmd-main",title:r("clickToRun"),onClick:()=>_(e),children:[t.jsx("span",{className:"cmd-name",children:e.name}),t.jsx("span",{className:"cmd-command",children:e.command}),e.cwd&&t.jsx("span",{className:"cmd-cwd",children:e.cwd})]}),t.jsx("button",{type:"button",className:"cmd-act",title:r("edit"),onClick:()=>V(s),children:t.jsx(U,{})}),t.jsx("button",{type:"button",className:`cmd-act del ${F===s?"confirm":""}`,title:r("delete"),onClick:()=>W(s),children:F===s?r("confirmQ"):t.jsx(ie,{})})]},s))]})}),t.jsxs("div",{className:"term-tabs-block",children:[t.jsxs("div",{className:"panel-header",children:[t.jsx("span",{className:"panel-title",children:r("terminal")}),J(P(["host:term-tab-new"],!0),H,k)]}),t.jsxs("div",{className:"panel-body",children:[n.terminals.length===0&&t.jsx("div",{className:"panel-empty",children:r("noTerminal")}),I.map(M),S.length>0&&t.jsxs("div",{className:"term-folder",children:[t.jsxs("button",{type:"button",className:`term-folder-header ${m?"open":""}`,title:r("aiBashGroup"),onClick:()=>a(e=>!e),children:[t.jsx("span",{className:"term-folder-caret",children:m?"▾":"▸"}),t.jsx("span",{className:"term-folder-title",children:r("aiBashGroup")}),t.jsx("span",{className:"term-folder-count",children:S.length})]}),m&&t.jsx("div",{className:"term-folder-body",children:S.map(M)})]})]})]})]}),t.jsxs("div",{className:"term-main",children:[j&&t.jsx("div",{className:"drawer-backdrop",onClick:()=>w(!1)}),t.jsx("button",{type:"button",className:"term-side-toggle",title:r("commands"),onClick:()=>w(e=>!e),children:t.jsx(le,{})}),n.terminals.length===0?t.jsxs("div",{className:"term-empty",children:[t.jsx(oe,{className:"term-empty-icon"}),t.jsx("div",{className:"term-empty-title",children:r("builtinTerminal")}),t.jsx("div",{className:"term-empty-sub",children:r("termEmptySub")})]}):n.terminals.map(e=>t.jsx(pe,{conversationId:e.conversationId,terminalId:e.id,command:e.command,cwd:e.cwd,title:e.title,agentBash:e.agentBash,active:e.id===N,running:e.running,exitCode:e.exitCode,register:o.register},`${e.conversationId}:${e.id}`))]})]})}export{Ne as TerminalPanel,ge as renderSlotToolbar};
|