@shawnstack/quickforge 1.4.0 → 1.4.1
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 -12
- package/dist/assets/{AgentProfilesPage-C79teCgh.js → AgentProfilesPage-CNK5PxA3.js} +1 -1
- package/dist/assets/ChatPanelHost-FqPQwwMO.js +217 -0
- package/dist/assets/PluginsPage-BCu1Ept0.js +1 -0
- package/dist/assets/{ScheduledTasksPage-C047y3p3.js → ScheduledTasksPage-Bx04rjui.js} +2 -2
- package/dist/assets/SharedConversationPage-55vX9sqe.js +1 -0
- package/dist/assets/TerminalDock-DLN_pLkJ.js +2 -0
- package/dist/assets/WorkspaceInspector-DoemHHnY.js +3 -0
- package/dist/assets/{WorkspaceReaderDialog-bTeERaGd.js → WorkspaceReaderDialog-C6xUHBCw.js} +2 -2
- package/dist/assets/{icons-Dsc5yL3l.js → icons-BWtivFsx.js} +1 -1
- package/dist/assets/index-CxOHP41X.css +3 -0
- package/dist/assets/index-Dcf73EL8.js +895 -0
- package/dist/assets/{monaco-DG4TcBMc.js → monaco-evITXh-m.js} +1 -1
- package/dist/assets/{react-vendor-CiCXOLb5.js → react-vendor-Mthyt1p4.js} +1 -1
- package/dist/index.html +4 -4
- package/package.json +1 -1
- package/server/agent-manager.mjs +85 -13
- package/server/approval-store.mjs +13 -1
- package/server/auto-compaction.mjs +29 -73
- package/server/context-usage.mjs +108 -0
- package/server/custom-commands.mjs +145 -28
- package/server/mcp/registry.mjs +40 -0
- package/server/routes/agent.mjs +1 -1
- package/server/routes/mcp.mjs +7 -1
- package/server/routes/project.mjs +32 -2
- package/server/routes/shared-conversation.mjs +1 -1
- package/server/storage.mjs +1 -0
- package/server/subagents.mjs +8 -6
- package/server/system-prompt.mjs +2 -2
- package/server/tools/definitions.mjs +1 -1
- package/dist/assets/ChatPanelHost-BjdIshtX.js +0 -195
- package/dist/assets/PluginsPage-Dt7Iiddo.js +0 -1
- package/dist/assets/SharedConversationPage-8X8kfztQ.js +0 -1
- package/dist/assets/TerminalDock-CEuJNf0m.js +0 -2
- package/dist/assets/WorkspaceInspector-BIa5gLVs.js +0 -3
- package/dist/assets/index-CPAWYhzz.css +0 -3
- package/dist/assets/index-YTL26wyJ.js +0 -814
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# 速构 QuickForge
|
|
2
2
|
|
|
3
3
|
<p align="center">
|
|
4
|
-
<img alt="Version" src="https://img.shields.io/badge/version-1.4.
|
|
4
|
+
<img alt="Version" src="https://img.shields.io/badge/version-1.4.1-blue" />
|
|
5
5
|
<img alt="License" src="https://img.shields.io/badge/license-MIT-green" />
|
|
6
6
|
<img alt="Node" src="https://img.shields.io/badge/node-%3E%3D20-brightgreen" />
|
|
7
7
|
<img alt="React" src="https://img.shields.io/badge/react-19-61DAFB?logo=react" />
|
|
@@ -49,7 +49,7 @@ QuickForge 是一个运行在本机的 AI 对话与研发辅助工具。它保
|
|
|
49
49
|
| MCP 集成 | 支持 stdio、SSE、Streamable HTTP (`http`) MCP Server,并将外部工具以命名空间形式注入到 Agent。 |
|
|
50
50
|
| 自定义指令 | 自动合并 `~/.claude/CLAUDE.md`、`~/.opencode/AGENTS.md`、`~/.quickforge/AGENTS.md` 以及项目 `CLAUDE.md`、`AGENTS.md`、`.opencode/AGENTS.md`、`.quickforge/AGENTS.md`。 |
|
|
51
51
|
| Agent Skills | 支持 Claude、opencode、共享、QuickForge 项目级和内置 Skills,用于加载专门的工作流说明、参考资料和工具使用规范。 |
|
|
52
|
-
| 自定义命令 | 支持 `/plan`、`/review`、`/compact`、`/clear`
|
|
52
|
+
| 自定义命令 | 支持 `/plan`、`/review`、`/compact`、`/clear`、`/help` 等内置命令,也可从用户级 `~/.quickforge/commands/` 或项目 `.claude/commands/`、`.opencode/commands/`、`.ai/commands/` 加载自定义命令。`/help` 一键查看全部可用命令;`/plan <任务>` 只生成执行计划,本轮禁止写文件、改文件和运行命令,可调用受同样只读边界约束的 subagent 辅助调研;`/review [范围]` 用于提交前自检待提交代码,本轮禁止编辑文件。同名命令优先级:项目目录 > 用户级目录 > 插件命令。 |
|
|
53
53
|
| 会话工作流 | 支持流式回复、复制、回滚、分支、草稿恢复、会话搜索、上下文用量提示和长对话压缩。 |
|
|
54
54
|
| 定时任务 | 支持创建、编辑、手动触发、查看历史,并为任务选择模型与参数。 |
|
|
55
55
|
| 对话分享 | 支持创建分享链接、只读/可操作权限、可选密码保护,以及撤销分享。 |
|
|
@@ -70,7 +70,7 @@ QuickForge 的工具能力很直接,因此也需要谨慎使用:
|
|
|
70
70
|
#### 从 npm 安装
|
|
71
71
|
|
|
72
72
|
```bash
|
|
73
|
-
npm install -g @shawnstack/quickforge@1.4.
|
|
73
|
+
npm install -g @shawnstack/quickforge@1.4.1
|
|
74
74
|
qf
|
|
75
75
|
|
|
76
76
|
# CLI 工具
|
|
@@ -84,17 +84,17 @@ qf update
|
|
|
84
84
|
当前版本的离线包:
|
|
85
85
|
|
|
86
86
|
```text
|
|
87
|
-
package-offline/shawnstack-quickforge-1.4.
|
|
87
|
+
package-offline/shawnstack-quickforge-1.4.1.tgz
|
|
88
88
|
```
|
|
89
89
|
|
|
90
90
|
在安装了 Node.js 20+ 和 npm 的机器上执行:
|
|
91
91
|
|
|
92
92
|
```bash
|
|
93
|
-
npm install -g ./package-offline/shawnstack-quickforge-1.4.
|
|
93
|
+
npm install -g ./package-offline/shawnstack-quickforge-1.4.1.tgz
|
|
94
94
|
qf
|
|
95
95
|
```
|
|
96
96
|
|
|
97
|
-
该包由 `v1.4.
|
|
97
|
+
该包由 `v1.4.1` 标签生成,包含 QuickForge 运行时资源,依赖由 npm 安装。
|
|
98
98
|
|
|
99
99
|
### 本地开发
|
|
100
100
|
|
|
@@ -213,7 +213,7 @@ It is not meant to replace your IDE or promise fully autonomous software develop
|
|
|
213
213
|
| MCP integration | Supports stdio, SSE, and Streamable HTTP (`http`) MCP servers. External tools are injected with namespaced tool names. |
|
|
214
214
|
| Custom instructions | Automatically merges `~/.claude/CLAUDE.md`, `~/.opencode/AGENTS.md`, `~/.quickforge/AGENTS.md`, and project `CLAUDE.md`, `AGENTS.md`, `.opencode/AGENTS.md`, `.quickforge/AGENTS.md`. |
|
|
215
215
|
| Agent Skills | Supports Claude, opencode, shared, QuickForge project-level, and bundled Skills for specialized workflows, references, and tool-use instructions. |
|
|
216
|
-
| Custom commands | Includes built-in commands such as `/plan`, `/review`, `/compact`, and `/
|
|
216
|
+
| Custom commands | Includes built-in commands such as `/plan`, `/review`, `/compact`, `/clear`, and `/help`, and can load custom commands from user-level `~/.quickforge/commands/` or project `.claude/commands/`, `.opencode/commands/`, `.ai/commands/`, or configured directories. `/help` lists all available commands; `/plan <task>` drafts an implementation plan without edits or commands, and may call subagents under the same read-only boundary; `/review [scope]` performs a pre-commit self-review without editing files. Precedence: project directories > user-level > plugins. |
|
|
217
217
|
| Conversation workflow | Streaming responses, copy, rollback, fork, draft recovery, search, context usage indicator, and conversation compaction. |
|
|
218
218
|
| Scheduled tasks | Create, edit, manually trigger, and inspect tasks, with model and parameter selection per task. |
|
|
219
219
|
| Conversation sharing | Share conversations with read-only or operate permissions, optional password protection, and revocation support. |
|
|
@@ -234,7 +234,7 @@ QuickForge intentionally exposes powerful local capabilities, so the boundaries
|
|
|
234
234
|
#### npm
|
|
235
235
|
|
|
236
236
|
```bash
|
|
237
|
-
npm install -g @shawnstack/quickforge@1.4.
|
|
237
|
+
npm install -g @shawnstack/quickforge@1.4.1
|
|
238
238
|
qf
|
|
239
239
|
|
|
240
240
|
# CLI utilities
|
|
@@ -245,20 +245,20 @@ qf update
|
|
|
245
245
|
|
|
246
246
|
#### Offline tarball
|
|
247
247
|
|
|
248
|
-
The offline release package for `v1.4.
|
|
248
|
+
The offline release package for `v1.4.1` is:
|
|
249
249
|
|
|
250
250
|
```text
|
|
251
|
-
package-offline/shawnstack-quickforge-1.4.
|
|
251
|
+
package-offline/shawnstack-quickforge-1.4.1.tgz
|
|
252
252
|
```
|
|
253
253
|
|
|
254
254
|
Install it on a machine with Node.js 20+ and npm:
|
|
255
255
|
|
|
256
256
|
```bash
|
|
257
|
-
npm install -g ./package-offline/shawnstack-quickforge-1.4.
|
|
257
|
+
npm install -g ./package-offline/shawnstack-quickforge-1.4.1.tgz
|
|
258
258
|
qf
|
|
259
259
|
```
|
|
260
260
|
|
|
261
|
-
The package was generated from tag `v1.4.
|
|
261
|
+
The package was generated from tag `v1.4.1` and includes QuickForge runtime assets and installs dependencies with npm.
|
|
262
262
|
|
|
263
263
|
### Local development
|
|
264
264
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{it as t,nt as n,s as r}from"./icons-Dsc5yL3l.js";import{n as i}from"./react-vendor-CiCXOLb5.js";import{E as a,O as o,S as s,T as c,b as l,v as u,x as d,y as f}from"./index-YTL26wyJ.js";var p=e(t(),1),m=i();function h(){return{name:``,label:``,description:``,systemPrompt:``,allowedTools:[`read_file`,`grep_files`],maxRuntimeMs:`1800000`,maxToolCalls:`300`,enabledAsSubagent:!0}}function g(e){return{name:e.name,label:e.label,description:e.description??``,systemPrompt:e.systemPrompt??``,allowedTools:e.allowedTools??[],maxRuntimeMs:String(e.maxRuntimeMs??18e5),maxToolCalls:String(e.maxToolCalls??300),enabledAsSubagent:e.enabledAsSubagent}}function _(e){return{name:e.name.trim().toLowerCase(),label:e.label.trim(),description:e.description.trim(),systemPrompt:e.systemPrompt.trim(),allowedTools:e.allowedTools,maxRuntimeMs:Number(e.maxRuntimeMs||18e5),maxToolCalls:Number(e.maxToolCalls||300),enabledAsSubagent:e.enabledAsSubagent}}function v(e){return!!(e.name.trim()&&e.label.trim()&&e.allowedTools.length>0)}async function y(e,t){let n=await fetch(e,{...t,headers:{"content-type":`application/json`,...t?.headers}}),r=await n.json().catch(()=>null);if(!n.ok)throw Error(r?.error||`请求失败`);return r}function b(){let[e,t]=(0,p.useState)([]),[i,b]=(0,p.useState)([]),[x,S]=(0,p.useState)(!1),[C,w]=(0,p.useState)(null),[T,E]=(0,p.useState)(()=>h()),[D,O]=(0,p.useState)(!1),[k,A]=(0,p.useState)(``),[j,M]=(0,p.useState)(!1),[N,P]=(0,p.useState)(),[F,I]=(0,p.useState)(`off`),[L,R]=(0,p.useState)(``);async function z(){let[e,n]=await Promise.all([y(`/api/agent-profiles`),y(`/api/agent-profiles/available-tools`)]);t(e.agents),b(n.tools)}(0,p.useEffect)(()=>{let e=!1;async function n(){try{let[n,r]=await Promise.all([y(`/api/agent-profiles`),y(`/api/agent-profiles/available-tools`)]);if(e)return;t(n.agents),b(r.tools)}catch(t){e||R(t instanceof Error?t.message:o(`requestFailed`))}}return n(),()=>{e=!0}},[]),(0,p.useEffect)(()=>{let e=!1;async function t(){try{let t=await l(),n=await f(t),r=await d(t),i=r.model??await s(t)??n[0];if(e)return;P(i),I(r.thinkingLevel??u(i))}catch{}}return t(),()=>{e=!0}},[]);let B=(0,p.useMemo)(()=>e.find(e=>e.id===C)??null,[e,C]);function V(e,t){E(n=>({...n,[e]:t}))}function H(e){E(t=>({...t,allowedTools:t.allowedTools.includes(e)?t.allowedTools.filter(t=>t!==e):[...t.allowedTools,e]}))}function U(){w(null),E(h()),A(``),R(``),S(!0)}function W(e){w(e.id),E(g(e)),A(``),R(``),S(!0)}function G(){D||j||(S(!1),w(null),E(h()),A(``))}async function K(){let e=k.trim();if(!e){R(o(`aiFillAgentInputRequired`));return}if(!N){R(o(`aiFillAgentNoModel`));return}M(!0),R(``);try{let t=await y(`/api/agent-profiles/ai-fill`,{method:`POST`,body:JSON.stringify({instruction:e,model:N,thinkingLevel:F})});E(e=>({...e,name:t.agent.name,label:t.agent.label,description:t.agent.description,systemPrompt:t.agent.systemPrompt}))}catch(e){R(e instanceof Error?e.message:o(`aiFillAgentFailed`))}finally{M(!1)}}async function q(){if(v(T)){O(!0),R(``);try{let e=_(T);C?await y(`/api/agent-profiles/${encodeURIComponent(C)}`,{method:`PATCH`,body:JSON.stringify(e)}):await y(`/api/agent-profiles`,{method:`POST`,body:JSON.stringify(e)}),G(),await z()}catch(e){R(e instanceof Error?e.message:o(`requestFailed`))}finally{O(!1)}}}async function J(e){if(!e.builtin&&await c({description:o(`confirmDeleteAgent`),confirmLabel:o(`confirmDelete`),cancelLabel:o(`cancel`),variant:`destructive`})){R(``);try{await y(`/api/agent-profiles/${encodeURIComponent(e.id)}`,{method:`DELETE`}),await z()}catch(e){R(e instanceof Error?e.message:o(`requestFailed`))}}}return(0,m.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden bg-background`,children:[(0,m.jsx)(`div`,{className:`border-b border-border px-6 py-5`,children:(0,m.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,m.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,m.jsx)(`div`,{className:`flex size-10 items-center justify-center rounded-2xl bg-primary/10 text-primary`,children:(0,m.jsx)(n,{className:`size-5`})}),(0,m.jsxs)(`div`,{children:[(0,m.jsx)(`h1`,{className:`text-lg font-semibold text-foreground`,children:o(`agentsTab`)}),(0,m.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:o(`agentsDescription`)})]})]}),(0,m.jsx)(a,{onClick:U,children:o(`createAgent`)})]})}),(0,m.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-6`,children:(0,m.jsxs)(`div`,{className:`mx-auto max-w-5xl space-y-5`,children:[L&&!x?(0,m.jsx)(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive`,children:L}):null,(0,m.jsx)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:e.map(e=>(0,m.jsxs)(`div`,{className:`rounded-2xl border border-border bg-card p-4 shadow-sm`,children:[(0,m.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,m.jsxs)(`div`,{className:`min-w-0`,children:[(0,m.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,m.jsx)(`h3`,{className:`truncate text-base font-semibold text-foreground`,children:e.label}),e.builtin?(0,m.jsx)(`span`,{className:`rounded-full bg-primary/10 px-2 py-0.5 text-xs text-primary`,children:o(`builtinAgent`)}):null,e.enabledAsSubagent?(0,m.jsx)(`span`,{className:`rounded-full bg-emerald-500/10 px-2 py-0.5 text-xs text-emerald-700`,children:o(`enabledAsSubagent`)}):null]}),(0,m.jsx)(`p`,{className:`mt-1 font-mono text-xs text-muted-foreground`,children:e.name}),(0,m.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:e.description||o(`noDescription`)})]}),(0,m.jsxs)(`div`,{className:`flex shrink-0 gap-1`,children:[(0,m.jsx)(a,{variant:`outline`,size:`sm`,disabled:e.builtin,onClick:()=>W(e),children:o(`editTask`)}),(0,m.jsx)(a,{variant:`destructive`,size:`sm`,disabled:e.builtin,onClick:()=>void J(e),children:o(`delete`)})]})]}),(0,m.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-1`,children:e.allowedTools.map(e=>(0,m.jsx)(`span`,{className:`rounded-full bg-muted px-2 py-0.5 font-mono text-xs text-muted-foreground`,children:e},e))}),(0,m.jsxs)(`div`,{className:`mt-3 grid gap-2 border-t border-border pt-3 text-xs text-muted-foreground sm:grid-cols-2`,children:[(0,m.jsxs)(`span`,{children:[o(`maxRuntimeMs`),e.maxRuntimeMs??`-`]}),(0,m.jsxs)(`span`,{children:[o(`maxToolCalls`),e.maxToolCalls??`-`]})]})]},e.id))})]})}),x?(0,m.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,onMouseDown:e=>{e.target===e.currentTarget&&G()},children:(0,m.jsxs)(`div`,{className:`flex max-h-[90vh] w-full max-w-3xl flex-col overflow-hidden rounded-2xl border border-border bg-background shadow-2xl`,onMouseDown:e=>e.stopPropagation(),children:[(0,m.jsxs)(`div`,{className:`shrink-0 border-b border-border px-5 py-4`,children:[(0,m.jsx)(`h2`,{className:`text-base font-semibold text-foreground`,children:o(B?`editAgent`:`createAgent`)}),B?.builtin?(0,m.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:o(`builtinAgentReadonly`)}):null]}),(0,m.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-5 py-4`,children:(0,m.jsxs)(`div`,{className:`space-y-4`,children:[(0,m.jsxs)(`div`,{className:`rounded-2xl border border-border bg-muted/20 p-3`,children:[(0,m.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 text-sm font-medium text-foreground`,children:[(0,m.jsx)(r,{className:`size-4 text-primary`}),o(`aiFillAgent`)]}),(0,m.jsx)(`p`,{className:`mb-2 text-xs text-muted-foreground`,children:o(`aiFillAgentDescription`)}),(0,m.jsx)(`textarea`,{className:`min-h-20 w-full resize-y rounded-xl border border-input bg-background px-3 py-2 text-sm outline-none transition-colors placeholder:text-muted-foreground/65 focus:border-ring disabled:opacity-60`,value:k,disabled:!!B?.builtin||j,onChange:e=>A(e.target.value),placeholder:o(`aiFillAgentPlaceholder`)}),(0,m.jsx)(`div`,{className:`mt-2 flex justify-end`,children:(0,m.jsxs)(a,{variant:`outline`,size:`sm`,onClick:()=>void K(),disabled:!!B?.builtin||j||!k.trim(),children:[(0,m.jsx)(r,{className:`mr-1 size-3.5`}),o(j?`aiFillAgentLoading`:`aiFillAgent`)]})})]}),(0,m.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,m.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[o(`agentName`),(0,m.jsx)(`input`,{className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring disabled:opacity-60`,value:T.name,disabled:!!B?.builtin,onChange:e=>V(`name`,e.target.value),placeholder:`reviewer`})]}),(0,m.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[o(`agentLabel`),(0,m.jsx)(`input`,{className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring disabled:opacity-60`,value:T.label,disabled:!!B?.builtin,onChange:e=>V(`label`,e.target.value),placeholder:o(`agentLabelPlaceholder`)})]})]}),(0,m.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[o(`agentDescription`),(0,m.jsx)(`input`,{className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring disabled:opacity-60`,value:T.description,disabled:!!B?.builtin,onChange:e=>V(`description`,e.target.value)})]}),(0,m.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[o(`agentSystemPrompt`),(0,m.jsx)(`textarea`,{className:`mt-1 min-h-36 w-full resize-y rounded-xl border border-input bg-background px-3 py-2 text-sm outline-none focus:border-ring disabled:opacity-60`,value:T.systemPrompt,disabled:!!B?.builtin,onChange:e=>V(`systemPrompt`,e.target.value)})]}),(0,m.jsxs)(`div`,{children:[(0,m.jsx)(`div`,{className:`mb-2 text-sm font-medium text-foreground`,children:o(`allowedTools`)}),(0,m.jsx)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:i.map(e=>(0,m.jsxs)(`label`,{className:`flex items-start gap-2 rounded-xl border border-border bg-muted/20 p-3 text-sm disabled:opacity-60`,children:[(0,m.jsx)(`input`,{type:`checkbox`,className:`mt-1`,disabled:!!B?.builtin,checked:T.allowedTools.includes(e.name),onChange:()=>H(e.name)}),(0,m.jsxs)(`span`,{children:[(0,m.jsx)(`span`,{className:`font-medium text-foreground`,children:e.label}),(0,m.jsx)(`span`,{className:`ml-2 font-mono text-xs text-muted-foreground`,children:e.name}),e.riskLevel===`dangerous`?(0,m.jsx)(`span`,{className:`ml-2 rounded-full bg-amber-500/10 px-2 py-0.5 text-xs text-amber-700`,children:o(`highRiskTool`)}):null,(0,m.jsx)(`span`,{className:`mt-1 block text-xs text-muted-foreground`,children:e.description})]})]},e.name))})]}),(0,m.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,m.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[o(`maxRuntimeMs`),(0,m.jsx)(`input`,{type:`number`,className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring disabled:opacity-60`,value:T.maxRuntimeMs,disabled:!!B?.builtin,onChange:e=>V(`maxRuntimeMs`,e.target.value)})]}),(0,m.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[o(`maxToolCalls`),(0,m.jsx)(`input`,{type:`number`,className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring disabled:opacity-60`,value:T.maxToolCalls,disabled:!!B?.builtin,onChange:e=>V(`maxToolCalls`,e.target.value)})]})]}),(0,m.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-foreground`,children:[(0,m.jsx)(`input`,{type:`checkbox`,checked:T.enabledAsSubagent,disabled:!!B?.builtin,onChange:e=>V(`enabledAsSubagent`,e.target.checked)}),o(`enabledAsSubagent`)]}),L?(0,m.jsx)(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive`,children:L}):null]})}),(0,m.jsx)(`div`,{className:`shrink-0 border-t border-border px-5 py-4`,children:(0,m.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,m.jsx)(a,{variant:`outline`,onClick:G,disabled:D||j,children:o(`cancel`)}),(0,m.jsx)(a,{onClick:q,disabled:D||j||!!B?.builtin||!v(T),children:o(`save`)})]})})]})}):null]})}export{b as AgentProfilesPage};
|
|
1
|
+
import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{ct as t,s as n,ut as r}from"./icons-BWtivFsx.js";import{n as i}from"./react-vendor-Mthyt1p4.js";import{E as a,O as o,S as s,T as c,b as l,v as u,x as d,y as f}from"./index-Dcf73EL8.js";var p=e(r(),1),m=i();function h(){return{name:``,label:``,description:``,systemPrompt:``,allowedTools:[`read_file`,`grep_files`],maxRuntimeMs:`1800000`,maxToolCalls:`300`,enabledAsSubagent:!0}}function g(e){return{name:e.name,label:e.label,description:e.description??``,systemPrompt:e.systemPrompt??``,allowedTools:e.allowedTools??[],maxRuntimeMs:String(e.maxRuntimeMs??18e5),maxToolCalls:String(e.maxToolCalls??300),enabledAsSubagent:e.enabledAsSubagent}}function _(e){return{name:e.name.trim().toLowerCase(),label:e.label.trim(),description:e.description.trim(),systemPrompt:e.systemPrompt.trim(),allowedTools:e.allowedTools,maxRuntimeMs:Number(e.maxRuntimeMs||18e5),maxToolCalls:Number(e.maxToolCalls||300),enabledAsSubagent:e.enabledAsSubagent}}function v(e){return!!(e.name.trim()&&e.label.trim()&&e.allowedTools.length>0)}async function y(e,t){let n=await fetch(e,{...t,headers:{"content-type":`application/json`,...t?.headers}}),r=await n.json().catch(()=>null);if(!n.ok)throw Error(r?.error||`请求失败`);return r}function b(){let[e,r]=(0,p.useState)([]),[i,b]=(0,p.useState)([]),[x,S]=(0,p.useState)(!1),[C,w]=(0,p.useState)(null),[T,E]=(0,p.useState)(()=>h()),[D,O]=(0,p.useState)(!1),[k,A]=(0,p.useState)(``),[j,M]=(0,p.useState)(!1),[N,P]=(0,p.useState)(),[F,I]=(0,p.useState)(`off`),[L,R]=(0,p.useState)(``);async function z(){let[e,t]=await Promise.all([y(`/api/agent-profiles`),y(`/api/agent-profiles/available-tools`)]);r(e.agents),b(t.tools)}(0,p.useEffect)(()=>{let e=!1;async function t(){try{let[t,n]=await Promise.all([y(`/api/agent-profiles`),y(`/api/agent-profiles/available-tools`)]);if(e)return;r(t.agents),b(n.tools)}catch(t){e||R(t instanceof Error?t.message:o(`requestFailed`))}}return t(),()=>{e=!0}},[]),(0,p.useEffect)(()=>{let e=!1;async function t(){try{let t=await l(),n=await f(t),r=await d(t),i=r.model??await s(t)??n[0];if(e)return;P(i),I(r.thinkingLevel??u(i))}catch{}}return t(),()=>{e=!0}},[]);let B=(0,p.useMemo)(()=>e.find(e=>e.id===C)??null,[e,C]);function V(e,t){E(n=>({...n,[e]:t}))}function H(e){E(t=>({...t,allowedTools:t.allowedTools.includes(e)?t.allowedTools.filter(t=>t!==e):[...t.allowedTools,e]}))}function U(){w(null),E(h()),A(``),R(``),S(!0)}function W(e){w(e.id),E(g(e)),A(``),R(``),S(!0)}function G(){D||j||(S(!1),w(null),E(h()),A(``))}async function K(){let e=k.trim();if(!e){R(o(`aiFillAgentInputRequired`));return}if(!N){R(o(`aiFillAgentNoModel`));return}M(!0),R(``);try{let t=await y(`/api/agent-profiles/ai-fill`,{method:`POST`,body:JSON.stringify({instruction:e,model:N,thinkingLevel:F})});E(e=>({...e,name:t.agent.name,label:t.agent.label,description:t.agent.description,systemPrompt:t.agent.systemPrompt}))}catch(e){R(e instanceof Error?e.message:o(`aiFillAgentFailed`))}finally{M(!1)}}async function q(){if(v(T)){O(!0),R(``);try{let e=_(T);C?await y(`/api/agent-profiles/${encodeURIComponent(C)}`,{method:`PATCH`,body:JSON.stringify(e)}):await y(`/api/agent-profiles`,{method:`POST`,body:JSON.stringify(e)}),G(),await z()}catch(e){R(e instanceof Error?e.message:o(`requestFailed`))}finally{O(!1)}}}async function J(e){if(!e.builtin&&await c({description:o(`confirmDeleteAgent`),confirmLabel:o(`confirmDelete`),cancelLabel:o(`cancel`),variant:`destructive`})){R(``);try{await y(`/api/agent-profiles/${encodeURIComponent(e.id)}`,{method:`DELETE`}),await z()}catch(e){R(e instanceof Error?e.message:o(`requestFailed`))}}}return(0,m.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden bg-background`,children:[(0,m.jsx)(`div`,{className:`border-b border-border px-6 py-5`,children:(0,m.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,m.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,m.jsx)(`div`,{className:`flex size-10 items-center justify-center rounded-2xl bg-primary/10 text-primary`,children:(0,m.jsx)(t,{className:`size-5`})}),(0,m.jsxs)(`div`,{children:[(0,m.jsx)(`h1`,{className:`text-lg font-semibold text-foreground`,children:o(`agentsTab`)}),(0,m.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:o(`agentsDescription`)})]})]}),(0,m.jsx)(a,{onClick:U,children:o(`createAgent`)})]})}),(0,m.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-6`,children:(0,m.jsxs)(`div`,{className:`mx-auto max-w-5xl space-y-5`,children:[L&&!x?(0,m.jsx)(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive`,children:L}):null,(0,m.jsx)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:e.map(e=>(0,m.jsxs)(`div`,{className:`rounded-2xl border border-border bg-card p-4 shadow-sm`,children:[(0,m.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,m.jsxs)(`div`,{className:`min-w-0`,children:[(0,m.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,m.jsx)(`h3`,{className:`truncate text-base font-semibold text-foreground`,children:e.label}),e.builtin?(0,m.jsx)(`span`,{className:`rounded-full bg-primary/10 px-2 py-0.5 text-xs text-primary`,children:o(`builtinAgent`)}):null,e.enabledAsSubagent?(0,m.jsx)(`span`,{className:`rounded-full bg-emerald-500/10 px-2 py-0.5 text-xs text-emerald-700`,children:o(`enabledAsSubagent`)}):null]}),(0,m.jsx)(`p`,{className:`mt-1 font-mono text-xs text-muted-foreground`,children:e.name}),(0,m.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:e.description||o(`noDescription`)})]}),(0,m.jsxs)(`div`,{className:`flex shrink-0 gap-1`,children:[(0,m.jsx)(a,{variant:`outline`,size:`sm`,disabled:e.builtin,onClick:()=>W(e),children:o(`editTask`)}),(0,m.jsx)(a,{variant:`destructive`,size:`sm`,disabled:e.builtin,onClick:()=>void J(e),children:o(`delete`)})]})]}),(0,m.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-1`,children:e.allowedTools.map(e=>(0,m.jsx)(`span`,{className:`rounded-full bg-muted px-2 py-0.5 font-mono text-xs text-muted-foreground`,children:e},e))}),(0,m.jsxs)(`div`,{className:`mt-3 grid gap-2 border-t border-border pt-3 text-xs text-muted-foreground sm:grid-cols-2`,children:[(0,m.jsxs)(`span`,{children:[o(`maxRuntimeMs`),e.maxRuntimeMs??`-`]}),(0,m.jsxs)(`span`,{children:[o(`maxToolCalls`),e.maxToolCalls??`-`]})]})]},e.id))})]})}),x?(0,m.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,onMouseDown:e=>{e.target===e.currentTarget&&G()},children:(0,m.jsxs)(`div`,{className:`flex max-h-[90vh] w-full max-w-3xl flex-col overflow-hidden rounded-2xl border border-border bg-background shadow-2xl`,onMouseDown:e=>e.stopPropagation(),children:[(0,m.jsxs)(`div`,{className:`shrink-0 border-b border-border px-5 py-4`,children:[(0,m.jsx)(`h2`,{className:`text-base font-semibold text-foreground`,children:o(B?`editAgent`:`createAgent`)}),B?.builtin?(0,m.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:o(`builtinAgentReadonly`)}):null]}),(0,m.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-5 py-4`,children:(0,m.jsxs)(`div`,{className:`space-y-4`,children:[(0,m.jsxs)(`div`,{className:`rounded-2xl border border-border bg-muted/20 p-3`,children:[(0,m.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 text-sm font-medium text-foreground`,children:[(0,m.jsx)(n,{className:`size-4 text-primary`}),o(`aiFillAgent`)]}),(0,m.jsx)(`p`,{className:`mb-2 text-xs text-muted-foreground`,children:o(`aiFillAgentDescription`)}),(0,m.jsx)(`textarea`,{className:`min-h-20 w-full resize-y rounded-xl border border-input bg-background px-3 py-2 text-sm outline-none transition-colors placeholder:text-muted-foreground/65 focus:border-ring disabled:opacity-60`,value:k,disabled:!!B?.builtin||j,onChange:e=>A(e.target.value),placeholder:o(`aiFillAgentPlaceholder`)}),(0,m.jsx)(`div`,{className:`mt-2 flex justify-end`,children:(0,m.jsxs)(a,{variant:`outline`,size:`sm`,onClick:()=>void K(),disabled:!!B?.builtin||j||!k.trim(),children:[(0,m.jsx)(n,{className:`mr-1 size-3.5`}),o(j?`aiFillAgentLoading`:`aiFillAgent`)]})})]}),(0,m.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,m.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[o(`agentName`),(0,m.jsx)(`input`,{className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring disabled:opacity-60`,value:T.name,disabled:!!B?.builtin,onChange:e=>V(`name`,e.target.value),placeholder:`reviewer`})]}),(0,m.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[o(`agentLabel`),(0,m.jsx)(`input`,{className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring disabled:opacity-60`,value:T.label,disabled:!!B?.builtin,onChange:e=>V(`label`,e.target.value),placeholder:o(`agentLabelPlaceholder`)})]})]}),(0,m.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[o(`agentDescription`),(0,m.jsx)(`input`,{className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring disabled:opacity-60`,value:T.description,disabled:!!B?.builtin,onChange:e=>V(`description`,e.target.value)})]}),(0,m.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[o(`agentSystemPrompt`),(0,m.jsx)(`textarea`,{className:`mt-1 min-h-36 w-full resize-y rounded-xl border border-input bg-background px-3 py-2 text-sm outline-none focus:border-ring disabled:opacity-60`,value:T.systemPrompt,disabled:!!B?.builtin,onChange:e=>V(`systemPrompt`,e.target.value)})]}),(0,m.jsxs)(`div`,{children:[(0,m.jsx)(`div`,{className:`mb-2 text-sm font-medium text-foreground`,children:o(`allowedTools`)}),(0,m.jsx)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:i.map(e=>(0,m.jsxs)(`label`,{className:`flex items-start gap-2 rounded-xl border border-border bg-muted/20 p-3 text-sm disabled:opacity-60`,children:[(0,m.jsx)(`input`,{type:`checkbox`,className:`mt-1`,disabled:!!B?.builtin,checked:T.allowedTools.includes(e.name),onChange:()=>H(e.name)}),(0,m.jsxs)(`span`,{children:[(0,m.jsx)(`span`,{className:`font-medium text-foreground`,children:e.label}),(0,m.jsx)(`span`,{className:`ml-2 font-mono text-xs text-muted-foreground`,children:e.name}),e.riskLevel===`dangerous`?(0,m.jsx)(`span`,{className:`ml-2 rounded-full bg-amber-500/10 px-2 py-0.5 text-xs text-amber-700`,children:o(`highRiskTool`)}):null,(0,m.jsx)(`span`,{className:`mt-1 block text-xs text-muted-foreground`,children:e.description})]})]},e.name))})]}),(0,m.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,m.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[o(`maxRuntimeMs`),(0,m.jsx)(`input`,{type:`number`,className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring disabled:opacity-60`,value:T.maxRuntimeMs,disabled:!!B?.builtin,onChange:e=>V(`maxRuntimeMs`,e.target.value)})]}),(0,m.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[o(`maxToolCalls`),(0,m.jsx)(`input`,{type:`number`,className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring disabled:opacity-60`,value:T.maxToolCalls,disabled:!!B?.builtin,onChange:e=>V(`maxToolCalls`,e.target.value)})]})]}),(0,m.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-foreground`,children:[(0,m.jsx)(`input`,{type:`checkbox`,checked:T.enabledAsSubagent,disabled:!!B?.builtin,onChange:e=>V(`enabledAsSubagent`,e.target.checked)}),o(`enabledAsSubagent`)]}),L?(0,m.jsx)(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive`,children:L}):null]})}),(0,m.jsx)(`div`,{className:`shrink-0 border-t border-border px-5 py-4`,children:(0,m.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,m.jsx)(a,{variant:`outline`,onClick:G,disabled:D||j,children:o(`cancel`)}),(0,m.jsx)(a,{onClick:q,disabled:D||j||!!B?.builtin||!v(T),children:o(`save`)})]})})]})}):null]})}export{b as AgentProfilesPage};
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{I as t,ut as n}from"./icons-BWtivFsx.js";import{n as r,t as i}from"./react-vendor-Mthyt1p4.js";import{d as a,p as o,t as s}from"./lit-vendor-Dr3cpBGF.js";import{c,l,s as u}from"./pi-web-ui-CBet4bMl.js";import{t as d}from"./logger-B65Akg8A.js";import{O as f,d as p,f as m,l as h,m as g,n as _,u as v}from"./index-Dcf73EL8.js";import{t as y}from"./plugin-api-YfYj_Bd7.js";var b=e(n(),1),x={maxHeight:`28rem`,overflow:`auto`,border:`1px solid color-mix(in oklab, var(--border) 75%, transparent)`,borderRadius:`0.75rem`,background:`color-mix(in oklab, var(--muted) 28%, transparent)`,fontFamily:`ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace`,fontSize:`0.78rem`,lineHeight:`1.45`},S={minHeight:`1.35em`,padding:`0 0.75rem`,whiteSpace:`pre`},C={display:`inline-flex`,alignItems:`center`,borderRadius:`999px`,padding:`0.05rem 0.45rem`,fontFamily:`ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace`,fontSize:`0.72rem`,fontWeight:`650`};function w(e){if(e==null)return``;if(typeof e==`string`)try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}try{return JSON.stringify(e,null,2)}catch{return String(e)}}function T(e){return e?.content?.filter(e=>e.type===`text`).map(e=>e.text??``).join(`
|
|
2
|
+
`)??``}function E(e){return!!(e&&typeof e==`object`&&!Array.isArray(e))}function D(e,t){if(e.running===!0||t)return`Status: running`;let n=[e.timedOut?`timed out`:null,e.aborted?`aborted`:null].filter(Boolean),r=n.length?` (${n.join(`, `)})`:``;return`Exit code: ${e.code??`unknown`}${typeof e.signal==`string`&&e.signal?`, signal: ${e.signal}`:``}${r}`}function O(e,t,n){let r=E(t)?t:void 0,i=typeof r?.command==`string`?r.command:typeof e?.command==`string`?e.command:``;if(!i||!r)return``;let a=typeof r?.stdout_preview==`string`?r.stdout_preview:typeof r?.stdout==`string`?r.stdout:``,o=typeof r?.stderr_preview==`string`?r.stderr_preview:typeof r?.stderr==`string`?r.stderr:``,s=!!(a||o),c=r.running===!0||r.code!==void 0||r.signal!==void 0||r.timedOut===!0||r.aborted===!0;return!s&&!c&&!n?``:[`Command: ${i}`,D(r,n),``,`STDOUT:`,a||`(empty)`,``,`STDERR:`,o||`(empty)`].join(`
|
|
3
|
+
`)}function k(e,t,n,r){return T(n)||(e===`run_command`?O(t,n?.details,r):``)}function A(e,t){return E(e)&&typeof e[t]==`string`?e[t]:``}function j(e,t,n){if(!t&&!n?.details)return``;if(e===`run_command`&&typeof t?.command==`string`)return t.command;if(e===`grep_files`){let e=typeof t?.query==`string`&&t.query?t.query:A(n?.details,`query`),r=typeof t?.path==`string`&&t.path?t.path:A(n?.details,`path`)||`.`,i=t?.regex||E(n?.details)&&E(n.details.searchOptions)&&n.details.searchOptions.regex?`regex`:`text`,a=r&&r!==`.`?` in ${r}`:` in current workspace`;return e?`${i}: ${e}${a}`:`searching${a}`}return e===`activate_skill`&&typeof t?.name==`string`?t.name:e===`read_skill_resource`&&typeof t?.path==`string`||t&&`path`in t&&typeof t.path==`string`?t.path:t&&`query`in t&&typeof t.query==`string`?t.query:t&&`search_query`in t&&typeof t.search_query==`string`?t.search_query:``}function ee(e){if(!e||typeof e!=`object`)return;let t=e.diff;if(!t||typeof t!=`object`)return;let n=t;return typeof n.text==`string`?n:void 0}function te(e){if(!e||typeof e!=`object`)return e;let t=e,n=t.diff;if(!n||typeof n!=`object`)return e;let{text:r,...i}=n;return{...t,diff:i}}function ne(e){if(!e||typeof e!=`object`)return{};let t=e;return{sessionId:typeof t.sessionId==`string`?t.sessionId:void 0,toolCallId:typeof t.toolCallId==`string`?t.toolCallId:void 0}}async function M(e,t,n){let r=n.getAttribute(`aria-label`)||f(`terminateCommand`);n.disabled=!0,n.setAttribute(`aria-label`,f(`commandTerminateRequested`)),n.setAttribute(`title`,f(`commandTerminateRequested`));try{let n=await fetch(`/api/agents/${encodeURIComponent(e)}/abort-tool`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({toolCallId:t})});if(!n.ok)throw Error(`HTTP ${n.status}`)}catch{n.disabled=!1,n.setAttribute(`aria-label`,r),n.setAttribute(`title`,f(`terminateCommandTitle`))}}function N(e){return e.startsWith(`+++`)||e.startsWith(`---`)?`quickforge-diff-file`:e.startsWith(`@@`)?`quickforge-diff-hunk`:e.startsWith(`+`)?`quickforge-diff-add`:e.startsWith(`-`)?`quickforge-diff-del`:`quickforge-diff-context`}function P(e){return e.startsWith(`+++`)||e.startsWith(`---`)?{...S,background:`color-mix(in oklab, var(--muted) 48%, transparent)`,color:`color-mix(in oklab, var(--muted-foreground) 88%, transparent)`}:e.startsWith(`@@`)?{...S,background:`color-mix(in oklab, rgb(37 99 235) 10%, transparent)`,color:`rgb(37 99 235)`}:e.startsWith(`+`)?{...S,background:`color-mix(in oklab, rgb(34 197 94) 16%, transparent)`,color:`rgb(22 101 52)`}:e.startsWith(`-`)?{...S,background:`color-mix(in oklab, rgb(239 68 68) 14%, transparent)`,color:`rgb(153 27 27)`}:{...S,color:`var(--foreground)`}}function F(e){let t=e.text?.split(`
|
|
4
|
+
`)??[],n=Number(e.addedLines??0),r=Number(e.removedLines??0);return o`
|
|
5
|
+
<div>
|
|
6
|
+
<div class="mb-1 flex items-center gap-2 text-xs font-medium text-muted-foreground">
|
|
7
|
+
<span>Diff</span>
|
|
8
|
+
<span
|
|
9
|
+
class="quickforge-diff-badge quickforge-diff-badge-add"
|
|
10
|
+
style=${s({...C,background:`color-mix(in oklab, rgb(34 197 94) 16%, transparent)`,color:`rgb(22 101 52)`})}
|
|
11
|
+
>+${n}</span>
|
|
12
|
+
<span
|
|
13
|
+
class="quickforge-diff-badge quickforge-diff-badge-del"
|
|
14
|
+
style=${s({...C,background:`color-mix(in oklab, rgb(239 68 68) 14%, transparent)`,color:`rgb(153 27 27)`})}
|
|
15
|
+
>-${r}</span>
|
|
16
|
+
${e.truncated?o`<span class="text-muted-foreground/80">truncated</span>`:a}
|
|
17
|
+
</div>
|
|
18
|
+
<div class="quickforge-diff-block" style=${s(x)}>${t.map(e=>o`
|
|
19
|
+
<div class=${N(e)} style=${s(P(e))}>${e||` `}</div>
|
|
20
|
+
`)}</div>
|
|
21
|
+
</div>
|
|
22
|
+
`}function I(e){if(!Number.isFinite(e)||e<0)return``;if(e<1e3)return`${Math.max(0,Math.round(e))}ms`;let t=e/1e3;return t<10?`${t.toFixed(1)}s`:t<60?`${Math.round(t)}s`:`${Math.floor(t/60)}m ${Math.floor(t%60).toString().padStart(2,`0`)}s`}function L(e){if(e){if(typeof e.durationMs==`number`)return e.durationMs;if(typeof e.startedAt==`number`)return Date.now()-e.startedAt}}var R=class extends HTMLElement{timer;static get observedAttributes(){return[`duration-ms`,`running`,`started-at`]}connectedCallback(){this.render(),this.syncTimer()}disconnectedCallback(){this.stopTimer()}attributeChangedCallback(){this.render(),this.syncTimer()}readNumberAttribute(e){let t=this.getAttribute(e);if(t===null||t.trim()===``)return;let n=Number(t);return Number.isFinite(n)&&n>=0?n:void 0}syncTimer(){this.getAttribute(`running`)===`true`&&this.readNumberAttribute(`duration-ms`)===void 0?this.timer||=setInterval(()=>this.render(),500):this.stopTimer()}stopTimer(){this.timer&&=(clearInterval(this.timer),void 0)}render(){let e=this.readNumberAttribute(`duration-ms`),t=this.readNumberAttribute(`started-at`),n=e===void 0?t!==void 0&&t>0?Date.now()-t:0:e;this.textContent=I(n)}};customElements.get(`quickforge-elapsed-time`)||customElements.define(`quickforge-elapsed-time`,R);function z(e,t){return L(e)===void 0?a:o`
|
|
23
|
+
<quickforge-elapsed-time
|
|
24
|
+
class="text-xs text-muted-foreground/70"
|
|
25
|
+
started-at=${String(e?.startedAt??``)}
|
|
26
|
+
duration-ms=${typeof e?.durationMs==`number`?String(e.durationMs):``}
|
|
27
|
+
running=${String(t===`running`)}
|
|
28
|
+
></quickforge-elapsed-time>
|
|
29
|
+
`}function B(){return`text-emerald-600 dark:text-emerald-500`}function re(e){let t=`quickforge-tool-type-icon shrink-0 ${B()}`;return e===`edit_file`?o`<svg class=${t} xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/><path d="M18.4 2.6a2.1 2.1 0 0 1 3 3L12 15l-4 1 1-4Z"/></svg>`:e===`write_file`?o`<svg class=${t} xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8Z"/><path d="M14 2v6h6"/><path d="M12 18v-6"/><path d="M9 15h6"/></svg>`:e===`read_file`?o`<svg class=${t} xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8Z"/><path d="M14 2v6h6"/><path d="M16 13H8"/><path d="M16 17H8"/><path d="M10 9H8"/></svg>`:e===`grep_files`?o`<svg class=${t} xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/></svg>`:e===`read_skill_resource`?o`<svg class=${t} xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 7v14"/><path d="M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3Z"/></svg>`:e===`run_command`?o`<svg class=${t} xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polyline points="4 17 10 11 4 5"/><line x1="12" x2="20" y1="19" y2="19"/></svg>`:e===`run_subagent`?o`<svg class=${t} xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 3 4 7l8 4 8-4-8-4Z"/><path d="m4 12 8 4 8-4"/><path d="m4 17 8 4 8-4"/></svg>`:e===`activate_skill`?o`<svg class=${t} xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9.9 2.1 8.5 8.5 2.1 9.9l6.4 1.4 1.4 6.4 1.4-6.4 6.4-1.4-6.4-1.4Z"/><path d="M19 15v4"/><path d="M21 17h-4"/></svg>`:o`<svg class=${t} xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.8-3.8a6 6 0 0 1-7.9 7.9l-6.9 6.9a2.1 2.1 0 0 1-3-3l6.9-6.9a6 6 0 0 1 7.9-7.9Z"/></svg>`}function ie(e){return e===`error`?`text-destructive`:e===`running`?`text-primary animate-spin`:e===`done`?`text-emerald-600 dark:text-emerald-500`:`text-muted-foreground/70`}function ae(e){let t=`quickforge-tool-status-icon shrink-0 ${ie(e)}`,n=f(e);return e===`running`?o`<svg class=${t} xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" role="img" aria-label=${n}><path d="M21 12a9 9 0 1 1-6.2-8.6"/></svg>`:e===`done`?o`<svg class=${t} xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" role="img" aria-label=${n}><path d="M22 11.1V12a10 10 0 1 1-5.9-9.1"/><path d="m9 11 3 3L22 4"/></svg>`:e===`error`?o`<svg class=${t} xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" role="img" aria-label=${n}><circle cx="12" cy="12" r="10"/><path d="m15 9-6 6"/><path d="m9 9 6 6"/></svg>`:o`<svg class=${t} xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" role="img" aria-label=${n}><circle cx="12" cy="12" r="10"/><circle cx="12" cy="12" r="2" fill="currentColor" stroke="none"/></svg>`}function V(e,t){return o`
|
|
30
|
+
<span class="shrink-0 inline-flex items-center gap-1.5" title=${f(e)}>
|
|
31
|
+
${ae(e)}${z(t,e)}
|
|
32
|
+
</span>
|
|
33
|
+
`}function oe(e,t,n){if(e!==`run_command`||t!==`running`)return a;let{sessionId:r,toolCallId:i}=ne(n);return!r||!i?a:o`
|
|
34
|
+
<button
|
|
35
|
+
type="button"
|
|
36
|
+
class="shrink-0 inline-flex size-5 items-center justify-center text-foreground transition-opacity hover:opacity-70 disabled:cursor-not-allowed disabled:opacity-40"
|
|
37
|
+
title=${f(`terminateCommandTitle`)}
|
|
38
|
+
aria-label=${f(`terminateCommandTitle`)}
|
|
39
|
+
@click=${e=>{e.preventDefault(),e.stopPropagation(),M(r,i,e.currentTarget)}}
|
|
40
|
+
><svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="7" y="7" width="10" height="10" rx="2.4"/></svg></button>
|
|
41
|
+
`}function se(e,t){return E(t)&&typeof t.label==`string`&&t.label?t.label:e===`general`?f(`subagentGeneral`):e===`explore`?f(`subagentExplore`):e||f(`runSubagent`)}function ce(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function H(e){return Array.isArray(e)?e:[]}function le(e){let t=new Set,n=[];for(let r of e){if(!E(r)||r.role!==`assistant`||!Array.isArray(r.content))continue;let e=r.content.filter(e=>E(e)&&e.type===`toolCall`);if(e.length!==0){for(let n of e)E(n)&&typeof n.id==`string`&&t.add(n.id);n.push({...r,content:e,usage:void 0})}}let r=e.filter(e=>E(e)&&e.role===`toolResult`&&typeof e.toolCallId==`string`&&t.has(e.toolCallId));return[...n,...r]}var U=new Map,ue=100;function de(e,t){if(e){if(!U.has(e)&&U.size>=ue){let e=U.keys().next().value;e&&U.delete(e)}U.set(e,t)}}var fe=class{render(e,t,n){let r=t?.isError?`error`:n?`running`:t?`done`:`called`,i=g(t?.details),s=E(t?.details)?t.details:void 0,c=typeof e?.subagent==`string`?e.subagent:typeof s?.subagent==`string`?s.subagent:``,l=se(c,s),u=typeof e?.task==`string`?e.task:``,d=typeof e?.context==`string`?e.context:``,p=typeof e?.expectedOutput==`string`?e.expectedOutput:``,m=typeof s?.toolCalls==`number`?s.toolCalls:void 0,_=ce(s?.allowedTools),v=H(s?.messages),y=H(s?.tools),b=new Set(ce(s?.pendingToolCalls)),x=h(),S=x.showToolDetails?v:le(v),C=x.showToolDetails?w(e):``,D=x.showToolDetails?w(t?.details):``,O=T(t),k=typeof s?.sessionId==`string`?s.sessionId:`${c}:${u}`,A=U.get(k)??x.expandToolsByDefault,j=r===`running`?f(`subagentRunning`,{name:l}):r===`done`?f(`subagentCompleted`,{name:l}):r===`error`?f(`subagentFailed`,{name:l}):f(`runSubagent`);return{isCustom:!1,content:o`
|
|
42
|
+
<details class="group/tool quickforge-subagent-tool" ?open=${A} @toggle=${e=>de(k,e.currentTarget.open)}>
|
|
43
|
+
<summary class="flex cursor-pointer list-none items-center gap-2 text-sm text-muted-foreground select-none">
|
|
44
|
+
<svg class="shrink-0 transition-transform group-open/tool:rotate-90" xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m9 18 6-6-6-6"/></svg>
|
|
45
|
+
${re(`run_subagent`)}
|
|
46
|
+
<span class="min-w-0 flex-1 truncate">${j}${u?o`<span class="text-muted-foreground/70"> · ${u}</span>`:``}</span>
|
|
47
|
+
${V(r,i)}
|
|
48
|
+
</summary>
|
|
49
|
+
<div class="mt-3 space-y-3">
|
|
50
|
+
${x.showToolDetails?o`<div class="quickforge-subagent-summary rounded-lg border border-border/75 bg-muted/20 px-3 py-2.5 text-sm">
|
|
51
|
+
<div class="flex flex-wrap items-center gap-x-3 gap-y-1 text-muted-foreground">
|
|
52
|
+
<span class="font-medium text-foreground/85">${l}</span>
|
|
53
|
+
${m===void 0?a:o`<span>${f(`subagentToolCalls`)}: ${m}</span>`}
|
|
54
|
+
${i?o`<span>${z(i,r)}</span>`:a}
|
|
55
|
+
</div>
|
|
56
|
+
${u?o`<div class="mt-2 text-muted-foreground/85"><span class="font-medium text-foreground/75">${f(`subagentTask`)}:</span> ${u}</div>`:a}
|
|
57
|
+
${d?o`<div class="mt-1 text-xs text-muted-foreground/70"><span class="font-medium">${f(`subagentContext`)}:</span> ${d}</div>`:a}
|
|
58
|
+
${p?o`<div class="mt-1 text-xs text-muted-foreground/70"><span class="font-medium">${f(`subagentExpectedOutput`)}:</span> ${p}</div>`:a}
|
|
59
|
+
${_.length>0?o`<div class="mt-2 flex flex-wrap gap-1.5">${_.map(e=>o`<span class="rounded-full bg-background/80 px-2 py-0.5 text-[11px] text-muted-foreground/80">${e}</span>`)}</div>`:a}
|
|
60
|
+
</div>`:a}
|
|
61
|
+
${S.length>0?o`<div class="quickforge-subagent-trace rounded-lg border border-border/70 bg-background/60 p-2.5"><message-list .messages=${S} .tools=${y} .pendingToolCalls=${b} .isStreaming=${r===`running`}></message-list></div>`:a}
|
|
62
|
+
${O?o`<div><div class="mb-1 text-xs font-medium text-muted-foreground">${f(`subagentResult`)}</div><code-block .code=${O} language="text"></code-block></div>`:a}
|
|
63
|
+
${C?o`<div><div class="mb-1 text-xs font-medium text-muted-foreground">${f(`input`)}</div><code-block .code=${C} language="json"></code-block></div>`:a}
|
|
64
|
+
${D?o`<div><div class="mb-1 text-xs font-medium text-muted-foreground">${f(`details`)}</div><code-block .code=${D} language="json"></code-block></div>`:a}
|
|
65
|
+
</div>
|
|
66
|
+
</details>
|
|
67
|
+
`}}},pe=class{toolName;labelKey;constructor(e,t){this.toolName=e,this.labelKey=t}render(e,t,n){let r=t?.isError?`error`:n?`running`:t?`done`:`called`,i=g(t?.details),a=j(this.toolName,e,t),s=h(),c=s.showToolDetails,l=s.expandToolsByDefault,u=c?w(e):``,d=k(this.toolName,e,t,n),p=ee(t?.details),m=c?w(p?te(t?.details):t?.details):``,_=t?.isError?`error`:`default`;return{isCustom:!1,content:o`
|
|
68
|
+
<details class="group/tool" ?open=${l}>
|
|
69
|
+
<summary class="flex cursor-pointer list-none items-center gap-2 text-sm text-muted-foreground select-none">
|
|
70
|
+
<svg class="shrink-0 transition-transform group-open/tool:rotate-90" xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m9 18 6-6-6-6"/></svg>
|
|
71
|
+
${re(this.toolName)}
|
|
72
|
+
<span class="min-w-0 flex-1 truncate">${f(this.labelKey)}${a?o`<span class="text-muted-foreground/70"> · ${a}</span>`:``}</span>
|
|
73
|
+
${oe(this.toolName,r,t?.details)}
|
|
74
|
+
${V(r,i)}
|
|
75
|
+
</summary>
|
|
76
|
+
<div class="mt-3 space-y-3">
|
|
77
|
+
${u?o`<div><div class="mb-1 text-xs font-medium text-muted-foreground">${f(`input`)}</div><code-block .code=${u} language="json"></code-block></div>`:``}
|
|
78
|
+
${d?o`<div><div class="mb-1 text-xs font-medium text-muted-foreground">${f(`output`)}</div>${this.toolName===`run_command`?o`<console-block .content=${d} .variant=${_}></console-block>`:o`<code-block .code=${d} language="text"></code-block>`}</div>`:``}
|
|
79
|
+
${p?F(p):``}
|
|
80
|
+
${m?o`<div><div class="mb-1 text-xs font-medium text-muted-foreground">${f(`details`)}</div><code-block .code=${m} language="json"></code-block></div>`:``}
|
|
81
|
+
</div>
|
|
82
|
+
</details>
|
|
83
|
+
`}}};function me(e){if(!e.startsWith(`mcp__`))return null;let t=e.slice(5),n=t.indexOf(`__`);return n<=0||n>=t.length-2?null:{serverName:t.slice(0,n),toolName:t.slice(n+2)}}function W(e,t){let n=me(e),r=E(t)?t:void 0,i=typeof r?.server==`string`&&r.server?r.server:n?.serverName??``,a=typeof r?.tool==`string`&&r.tool?r.tool:n?.toolName??e;return n||r?.mcp===!0?{serverName:i,toolName:a}:null}function he(e){if(!e)return`text`;try{return JSON.parse(e),`json`}catch{return`text`}}var ge=class{toolName;label;constructor(e,t){this.toolName=e,this.label=t}render(e,t,n){let r=t?.isError?`error`:n?`running`:t?`done`:`called`,i=g(t?.details),s=W(this.toolName,t?.details)??me(this.toolName),c=s?.serverName??``,l=s?.toolName??this.toolName,u=j(this.toolName,e,t),d=h(),p=w(e),m=k(this.toolName,e,t,n),_=d.showToolDetails?w(t?.details):``,v=this.label&&this.label!==l?`${this.label} (${l})`:l;return{isCustom:!1,content:o`
|
|
84
|
+
<details class="group/tool quickforge-mcp-tool" ?open=${d.expandToolsByDefault}>
|
|
85
|
+
<summary class="flex cursor-pointer list-none items-center gap-2 text-sm text-muted-foreground select-none">
|
|
86
|
+
<svg class="shrink-0 transition-transform group-open/tool:rotate-90" xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m9 18 6-6-6-6"/></svg>
|
|
87
|
+
${re(this.toolName)}
|
|
88
|
+
<span class="min-w-0 flex-1 truncate">MCP${c?o`<span class="text-muted-foreground/70"> · ${c}</span>`:a}<span class="text-muted-foreground/70"> · ${v}</span>${u?o`<span class="text-muted-foreground/70"> · ${u}</span>`:a}</span>
|
|
89
|
+
${V(r,i)}
|
|
90
|
+
</summary>
|
|
91
|
+
<div class="mt-3 space-y-3">
|
|
92
|
+
${p?o`<div><div class="mb-1 text-xs font-medium text-muted-foreground">${f(`input`)}</div><code-block .code=${p} language="json"></code-block></div>`:a}
|
|
93
|
+
${m?o`<div><div class="mb-1 text-xs font-medium text-muted-foreground">${f(`output`)}</div><code-block .code=${m} language=${he(m)}></code-block></div>`:a}
|
|
94
|
+
${_?o`<div><div class="mb-1 text-xs font-medium text-muted-foreground">${f(`details`)}</div><code-block .code=${_} language="json"></code-block></div>`:a}
|
|
95
|
+
</div>
|
|
96
|
+
</details>
|
|
97
|
+
`}}},_e=new Set;function G(e){for(let t of e){if(!E(t)||typeof t.name!=`string`||!me(t.name)||_e.has(t.name))continue;let e=typeof t.label==`string`?t.label:typeof t.description==`string`?t.description.replace(/^\[MCP:[^\]]+\]\s*/,``):void 0;l(t.name,new ge(t.name,e)),_e.add(t.name)}}for(let[e,t]of[[`read_file`,`readFile`],[`grep_files`,`searchFiles`],[`write_file`,`writeFile`],[`edit_file`,`editFile`],[`run_command`,`runCommand`],[`activate_skill`,`activateSkill`],[`read_skill_resource`,`readSkillResource`]])l(e,new pe(e,t));l(`run_subagent`,new fe);function ve(e=[]){return G(e),e}function K(e,t){let n=document.createElement(`template`);n.innerHTML=t;let r=n.content.firstElementChild;if(!r)return;let i=e.querySelector(`svg`);i?i.replaceWith(r):e.appendChild(r)}function q(e,t){let n=document.createElement(`template`);n.innerHTML=t;let r=Array.from(n.content.children);for(let t of Array.from(e.children))t.remove();for(let t of r)e.appendChild(t)}var ye=()=>({text:``,attachments:[]}),J=e=>e.text.length>0||(e.attachments?.length??0)>0;function Y(e){try{return JSON.stringify(e)}catch{return``}}function be(e){let t=String(e||``);if(!t)return 0;let n=t.match(/[\u3400-\u9fff\uf900-\ufaff]/g)?.length??0,r=Math.max(0,t.length-n);return Math.ceil(n+r/3.5)}function xe(e){return e?typeof e==`string`?e:Array.isArray(e)?e.map(e=>{if(!e||typeof e!=`object`)return xe(e);let t=e;return t.type===`text`?typeof t.text==`string`?t.text:``:t.type===`thinking`?typeof t.thinking==`string`?t.thinking:``:t.type===`image`?`[image:${typeof t.mimeType==`string`?t.mimeType:`unknown`}]`:t.type===`toolCall`?`[toolCall:${typeof t.name==`string`?t.name:`unknown`}] ${Y(t.arguments)}`:Y(t)}).filter(Boolean).join(`
|
|
98
|
+
`):typeof e==`object`?Y(e):String(e):``}function Se(e){let t=[e.role??``,xe(e.content)];return e.toolName&&t.push(e.toolName),e.toolCallId&&t.push(e.toolCallId),e.attachments!==void 0&&t.push(Y(e.attachments)),be(t.filter(Boolean).join(`
|
|
99
|
+
`))}function Ce(e,t,n=[]){return be(e)+t.reduce((e,t)=>e+Se(t),0)+be(Y(n))}function we(e){if(typeof e.timestamp==`number`)return e.timestamp;if(typeof e.timestamp==`string`){let t=Date.parse(e.timestamp);return Number.isNaN(t)?0:t}return 0}function Te(e){return e.role===`user`&&xe(e.content).includes(`<compact_summary>`)}function Ee(e){let t=0;for(let n of e)Te(n)&&(t=Math.max(t,we(n)));return t}function De(e,t,n,r=[],i){let a=Ee(t),o=t.reduce((e,t)=>{let n=t.usage;return t.role!==`assistant`||!n||a>0&&we(t)<=a?e:n},void 0),s=o?.input??o?.totalTokens??0,c=Ce(e,t,r),l=Number.isFinite(Number(s))&&Number(s)>0,u=l?Number(s):c,d=u,f=l?`provider`:`estimated`,p=Math.max(0,Number(i)||4096),m=d+p,h=n>0?Math.round(m/n*1e3)/10:0,g=Math.round(142-142*Math.min(100,Math.max(0,h))/100);return{contextWindow:n,usedTokens:d,totalTokens:m,inputTokens:u,estimatedInputTokens:c,knownInputTokens:l?Number(s):0,inputTokenSource:f,reservedOutputTokens:p,percent:h,color:`hsl(${g} 72% 45%)`}}function X(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${Math.round(e/1e3)}K`:String(e)}function Oe({panel:e}){let t=!0,n,r=0,i,a=-1/0,o=-1/0,s,c=()=>e.querySelector(`agent-interface .overflow-y-auto`),l=e=>e.scrollHeight-e.scrollTop-e.clientHeight<=80,u=t=>{e.querySelector(`agent-interface`)?.setAutoScroll?.(t)},d=()=>{let e=Math.max(a,o);return window.performance.now()-e<=500},f=()=>{n!==void 0&&(window.cancelAnimationFrame(n),n=void 0),t=!1,u(!1)},p=()=>{a=window.performance.now(),f()},m=()=>{o=window.performance.now()},h=()=>{let e=c();!e||!t||(e.scrollTop=e.scrollHeight,r=e.scrollTop)},g=()=>{n===void 0&&(n=window.requestAnimationFrame(()=>{n=void 0,h(),window.requestAnimationFrame(h)}))},_=()=>{t=!0,u(!0),g()},v=()=>{let e=c();if(!e)return;let n=e.scrollTop,i=n<r-1,a=i&&d();if(i&&t&&!a&&!l(e)){r=n,g();return}a?f():l(e)&&(t=!0,u(!0)),r=n},y=e=>{e.deltaY<0&&p()},b=e=>{e.target===e.currentTarget&&m()},x=e=>{(e.key===`ArrowUp`||e.key===`PageUp`||e.key===`Home`)&&p()},S=e=>{i=e.touches[0]?.clientY},C=e=>{let t=e.touches[0]?.clientY;t===void 0||i===void 0||(t>i+1&&p(),i=t)};return{get isEnabled(){return t},enable:_,disable:f,scheduleScrollToBottom:g,setup:()=>{let n=c();if(!n||s)return;r=n.scrollTop,n.addEventListener(`scroll`,v,{passive:!0}),n.addEventListener(`wheel`,y,{passive:!0}),n.addEventListener(`pointerdown`,b,{passive:!0}),n.addEventListener(`keydown`,x),n.addEventListener(`touchstart`,S,{passive:!0}),n.addEventListener(`touchmove`,C,{passive:!0}),s=new ResizeObserver(()=>{t&&g()}),s.observe(n);let i=n.querySelector(`.max-w-3xl`);i&&s.observe(i);let a=e.querySelector(`.quickforge-composer-dock`);a&&s.observe(a),_()},cleanup:()=>{let e=c();e?.removeEventListener(`scroll`,v),e?.removeEventListener(`wheel`,y),e?.removeEventListener(`pointerdown`,b),e?.removeEventListener(`keydown`,x),e?.removeEventListener(`touchstart`,S),e?.removeEventListener(`touchmove`,C),s?.disconnect(),s=void 0,n!==void 0&&(window.cancelAnimationFrame(n),n=void 0)}}}function ke({panel:e,getCustomCommands:t,restoreDraftIntoComposer:n}){let r=e=>`/${e.name}${e.argumentHint?` ${e.argumentHint}`:``}`,i=()=>[{name:`plan`,description:f(`planCommandDescription`),argumentHint:`[task]`},{name:`review`,description:f(`reviewCommandDescription`),argumentHint:`[scope]`},{name:`compact`,description:f(`compactCommandDescription`),argumentHint:``},{name:`clear`,description:f(`clearCommandDescription`),argumentHint:``},{name:`help`,description:f(`helpCommandDescription`),argumentHint:``}],a=()=>{let n=(e.querySelector(`.quickforge-command-suggestions`)?.querySelector(`.quickforge-command-suggestion-item`))?.dataset.quickforgeCommandName;if(n)return[...i(),...t()].find(e=>e.name===n)},o=()=>{let t=e.querySelector(`.quickforge-command-suggestions`);t?.__quickforgeDismissHandler&&(document.removeEventListener(`pointerdown`,t.__quickforgeDismissHandler,!0),t.__quickforgeDismissHandler=void 0),t?.remove()},s=t=>{let r=e.querySelector(`message-editor`),i=`/${t.name}${t.argumentHint?` `:``}`;n({text:i,attachments:[]});let a=r?.querySelector(`textarea`);a?.focus(),a&&(a.selectionStart=i.length,a.selectionEnd=i.length),o()};return{update:n=>{let a=e.querySelector(`message-editor`),c=n??a?.value??a?.querySelector(`textarea`)?.value??``,l=a?.querySelector(`textarea`),u=e.querySelector(`.quickforge-command-suggestions`);if(!a||!l||!c.startsWith(`/`)){u?.remove();return}let d=c.slice(1).trim().toLowerCase(),p=t(),m=[...i(),...p].filter(e=>e.name.includes(d)||e.description?.toLowerCase().includes(d));if(m.length===0){u?.remove();return}let h=u??document.createElement(`div`);h.className=`quickforge-command-suggestions`,h.setAttribute(`role`,`listbox`),h.innerHTML=``;let g=document.createElement(`div`);g.className=`quickforge-command-suggestions-header`,g.textContent=f(p.length?`customCommandsHint`:`customCommandsEmptyHint`),h.append(g);for(let e of m){let t=document.createElement(`button`);t.type=`button`,t.className=`quickforge-command-suggestion-item`,t.dataset.quickforgeCommandName=e.name,t.setAttribute(`role`,`option`),t.innerHTML=`
|
|
100
|
+
<span class="quickforge-command-suggestion-name"></span>
|
|
101
|
+
<span class="quickforge-command-suggestion-description"></span>
|
|
102
|
+
`,t.querySelector(`.quickforge-command-suggestion-name`).textContent=r(e),t.querySelector(`.quickforge-command-suggestion-description`).textContent=e.description??``,t.onpointerdown=t=>{t.preventDefault(),t.stopPropagation(),s(e)},h.append(t)}u||a.parentElement?.insertBefore(h,a),h.__quickforgeDismissHandler||(h.__quickforgeDismissHandler=e=>{h.contains(e.target)||a.contains(e.target)||o()},document.addEventListener(`pointerdown`,h.__quickforgeDismissHandler,!0))},remove:o,setupTextareaHandler:e=>{let t=e?.querySelector(`textarea`);if(!t)return;let n=t;n.__quickforgeCommandCompleteHandler&&n.removeEventListener(`keydown`,n.__quickforgeCommandCompleteHandler,!0),n.__quickforgeCommandCompleteHandler=t=>{if(t.isComposing||t.key===`Process`)return;if(t.key===`Enter`&&t.shiftKey){t.stopImmediatePropagation();return}if(t.key!==`Tab`||!(e?.value??n.value??``).startsWith(`/`)||t.shiftKey)return;let r=a();r&&(t.preventDefault(),t.stopPropagation(),s(r))},n.addEventListener(`keydown`,n.__quickforgeCommandCompleteHandler,!0)},cleanupTextareaHandler:()=>{let t=e.querySelector(`message-editor textarea`);t?.__quickforgeCommandCompleteHandler&&t.removeEventListener(`keydown`,t.__quickforgeCommandCompleteHandler,!0)}}}var Ae={plugin:`
|
|
103
|
+
<svg viewBox="0 0 20 20" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round">
|
|
104
|
+
<path d="M7.4 3.2h5.2a1.2 1.2 0 0 1 1.2 1.2v2.1h.9a2.1 2.1 0 1 1 0 4.2h-.9v2.1a1.2 1.2 0 0 1-1.2 1.2h-2.1v.7a2.1 2.1 0 1 1-4.2 0V14H4.4a1.2 1.2 0 0 1-1.2-1.2V9.9h.8a1.8 1.8 0 1 0 0-3.6h-.8V4.4a1.2 1.2 0 0 1 1.2-1.2h2.1v-.8a1.8 1.8 0 1 1 3.6 0v.8Z" />
|
|
105
|
+
</svg>`,document:`
|
|
106
|
+
<svg viewBox="0 0 20 20" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.65" stroke-linecap="round" stroke-linejoin="round">
|
|
107
|
+
<path d="M5.4 2.8h6.1L15.8 7v10.2H5.4z" />
|
|
108
|
+
<path d="M11.4 2.9V7h4.1" />
|
|
109
|
+
<path d="M7.6 10.2h5" />
|
|
110
|
+
<path d="M7.6 13h4.3" />
|
|
111
|
+
</svg>`,spreadsheet:`
|
|
112
|
+
<svg viewBox="0 0 20 20" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.65" stroke-linecap="round" stroke-linejoin="round">
|
|
113
|
+
<rect x="3.4" y="4" width="13.2" height="12.2" rx="1.5" />
|
|
114
|
+
<path d="M3.4 8h13.2" />
|
|
115
|
+
<path d="M7.8 4v12.2" />
|
|
116
|
+
<path d="M12.2 4v12.2" />
|
|
117
|
+
<path d="M3.4 12h13.2" />
|
|
118
|
+
</svg>`,presentation:`
|
|
119
|
+
<svg viewBox="0 0 20 20" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.65" stroke-linecap="round" stroke-linejoin="round">
|
|
120
|
+
<path d="M3 4.2h14" />
|
|
121
|
+
<rect x="4.2" y="4.2" width="11.6" height="8.4" rx="1.2" />
|
|
122
|
+
<path d="M10 12.6v3.2" />
|
|
123
|
+
<path d="m7.2 17 2.8-1.2 2.8 1.2" />
|
|
124
|
+
<path d="M7.1 9.5 9 7.7l1.5 1.3 2.4-2.5" />
|
|
125
|
+
</svg>`,skill:`
|
|
126
|
+
<svg viewBox="0 0 20 20" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round">
|
|
127
|
+
<path d="M4.2 3.2h4.4A2.4 2.4 0 0 1 11 5.6v11a2.4 2.4 0 0 0-2.4-2.4H4.2V3.2Z" />
|
|
128
|
+
<path d="M11 5.6a2.4 2.4 0 0 1 2.4-2.4h2.4v11.1h-2.4A2.4 2.4 0 0 0 11 16.7" />
|
|
129
|
+
</svg>`,tool:`
|
|
130
|
+
<svg viewBox="0 0 20 20" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
|
|
131
|
+
<path d="M12.8 3.5a4.2 4.2 0 0 0 4 5.5l-7.6 7.6a2.2 2.2 0 0 1-3.1-3.1l7.6-7.6a4.2 4.2 0 0 0-5.5-4" />
|
|
132
|
+
</svg>`,command:`
|
|
133
|
+
<svg viewBox="0 0 20 20" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
|
|
134
|
+
<path d="m5 6 4 4-4 4" />
|
|
135
|
+
<path d="M10.5 14h4.5" />
|
|
136
|
+
</svg>`};function je(e){return e.split(/[-_/\\]+/).filter(Boolean).map(e=>e&&`${e[0].toUpperCase()}${e.slice(1)}`).join(` `)}function Me(e){switch(e.name){case`openai-documents`:return{label:f(`pluginOpenaiDocumentsName`),description:f(`pluginOpenaiDocumentsDescription`),mention:`Documents`,iconKind:`document`};case`openai-spreadsheets`:return{label:f(`pluginOpenaiSpreadsheetsName`),description:f(`pluginOpenaiSpreadsheetsDescription`),mention:`Spreadsheets`,iconKind:`spreadsheet`};case`openai-presentations`:return{label:f(`pluginOpenaiPresentationsName`),description:f(`pluginOpenaiPresentationsDescription`),mention:`Presentations`,iconKind:`presentation`};default:return null}}function Ne(e){let t=Me(e);return t?t.label:(e.displayName||je(e.name.replace(/^openai-/,``))).replace(/^OpenAI\s+/i,``)}function Pe(e){let t=Me(e),n=t?.label??Ne(e),r=t?.mention??n.replace(/\s+/g,``);return[{type:`plugin`,iconKind:t?.iconKind??`plugin`,pluginName:e.name,name:e.name,label:n,mention:r,insertText:r,description:t?.description??e.description}]}function Fe(e,t){let n=e.slice(0,t),r=/(^|\s)@([^\s@]*)$/.exec(n);if(!r)return null;let i=r[1]?.length??0;return{start:n.length-r[0].length+i,end:t,query:r[2]??``}}function Ie(e){let t=new Set,n=/(^|\s)@([\p{L}\p{N}_-]+)/gu,r;for(;r=n.exec(e);)t.add((r[2]||``).toLowerCase());return t}function Le({panel:e,restoreDraftIntoComposer:t,onSelectionChange:n}){let r=[],i=null,a=new Map,o=()=>n?.([...a.values()]),s=()=>i||(i=y().then(e=>{r=(e.plugins??[]).filter(e=>e.enabled&&e.status===`loaded`)}).catch(()=>{r=[]}).finally(()=>{i=null}),i);s();let c=()=>r.flatMap(Pe),l=()=>{let t=(e.querySelector(`.quickforge-capability-suggestions`)?.querySelector(`.quickforge-capability-suggestion-item`))?.dataset.quickforgeCapabilityKey;if(t)return c().find(e=>Re(e)===t)},u=()=>{let t=e.querySelector(`.quickforge-capability-suggestions`);t?.__quickforgeDismissHandler&&(document.removeEventListener(`pointerdown`,t.__quickforgeDismissHandler,!0),t.__quickforgeDismissHandler=void 0),t?.remove()},d=(n,r)=>{let i=e.querySelector(`message-editor`),s=i?.querySelector(`textarea`),c=i?.value??s?.value??``,l=s?.selectionStart??c.length,d=r??Fe(c,l),f=`@${n.insertText}`,p=d?`${c.slice(0,d.start)}${f} ${c.slice(d.end)}`:`${c}${c.endsWith(` `)||c.length===0?``:` `}${f} `,m=d?d.start+f.length+1:p.length;a.set(Re(n),n),o(),t({text:p,attachments:i?.attachments?[...i.attachments]:[]});let h=i?.querySelector(`textarea`);h?.focus(),h&&(h.selectionStart=m,h.selectionEnd=m),u()},p=e=>{let t=()=>{let t=c().find(t=>t.insertText===e);t&&d(t)};if(r.length===0){s().then(t);return}t()},m=t=>{let n=e.querySelector(`message-editor`),i=n?.querySelector(`textarea`),a=t??n?.value??i?.value??``,o=Fe(a,i?.selectionStart??a.length),l=e.querySelector(`.quickforge-capability-suggestions`);if(!n||!i||!o){l?.remove();return}r.length===0&&s().then(()=>m(t));let p=o.query.toLowerCase(),h=c().filter(e=>[e.label,e.name,e.pluginName,e.description].filter(Boolean).join(` `).toLowerCase().includes(p)).slice(0,8);if(h.length===0){l?.remove();return}let g=l??document.createElement(`div`);g.className=`quickforge-capability-suggestions`,g.setAttribute(`role`,`listbox`),g.innerHTML=``;let _=document.createElement(`div`);_.className=`quickforge-capability-suggestions-header`,_.textContent=f(`pluginMentionHeader`),g.append(_);for(let e of h){let t=document.createElement(`button`);t.type=`button`,t.className=`quickforge-capability-suggestion-item`,t.dataset.quickforgeCapabilityKey=Re(e),t.dataset.quickforgePluginName=e.pluginName,t.setAttribute(`role`,`option`),t.innerHTML=`
|
|
137
|
+
<span class="quickforge-capability-suggestion-icon quickforge-capability-suggestion-icon-${e.iconKind}">${Ae[e.iconKind]}</span>
|
|
138
|
+
<span class="quickforge-capability-suggestion-main">
|
|
139
|
+
<span class="quickforge-capability-suggestion-line">
|
|
140
|
+
<span class="quickforge-capability-suggestion-name"></span>
|
|
141
|
+
</span>
|
|
142
|
+
<span class="quickforge-capability-suggestion-description"></span>
|
|
143
|
+
</span>
|
|
144
|
+
`,t.querySelector(`.quickforge-capability-suggestion-name`).textContent=e.label,t.querySelector(`.quickforge-capability-suggestion-description`).textContent=e.description??e.pluginName,t.onpointerdown=t=>{t.preventDefault(),t.stopPropagation(),d(e,o)},g.append(t)}l||n.parentElement?.insertBefore(g,n),g.__quickforgeDismissHandler||(g.__quickforgeDismissHandler=e=>{g.contains(e.target)||n.contains(e.target)||u()},document.addEventListener(`pointerdown`,g.__quickforgeDismissHandler,!0))};return{update:m,remove:u,setupTextareaHandler:e=>{let t=e?.querySelector(`textarea`);if(!t)return;let n=t;n.__quickforgeCapabilityCompleteHandler&&n.removeEventListener(`keydown`,n.__quickforgeCapabilityCompleteHandler,!0),n.__quickforgeCapabilityCompleteHandler=t=>{if(t.isComposing||t.key===`Process`)return;if(t.key===`Escape`){u();return}if(t.key!==`Tab`&&t.key!==`Enter`)return;let r=e?.value??n.value??``,i=Fe(r,n.selectionStart??r.length);if(!i||t.shiftKey)return;let a=l();a&&(t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),d(a,i))},n.addEventListener(`keydown`,n.__quickforgeCapabilityCompleteHandler,!0)},cleanupTextareaHandler:()=>{let t=e.querySelector(`message-editor textarea`);t?.__quickforgeCapabilityCompleteHandler&&t.removeEventListener(`keydown`,t.__quickforgeCapabilityCompleteHandler,!0)},consumeSelectedCapabilities:e=>{let t=Ie(e),n=[...a.values()].filter(e=>t.has(e.mention.toLowerCase())),r=c().filter(e=>t.has(e.insertText.toLowerCase())||t.has(e.label.replace(/\s+/g,``).toLowerCase())),i=new Map;for(let e of[...n,...r])i.set(Re(e),e);return a=new Map,o(),[...i.values()].slice(0,4)},insertBuiltinPluginMention:p}}function Re(e){return`${e.type}:${e.pluginName}:${e.name}`}var ze=i();function Be(e){return`hsl(${Math.round(142-142*Math.min(100,Math.max(0,e))/100)} 72% 45%)`}function Ve(e,t){let n=Number(e.inputTokens)||0,r=Math.max(0,Number(e.knownInputTokens??e.providerContextTokens)||0),i=Math.max(0,Number(e.estimatedInputTokens)||0),a=Math.max(0,Number(e.reservedOutputTokens)||0),o=Math.max(0,Number(e.totalTokens)||n+a),s=Number.isFinite(Number(e.percent))?Number(e.percent):0,c=e.inputTokenSource??(r>0?`provider`:`estimated`);return{contextWindow:Math.max(0,Number(e.contextWindow)||t),usedTokens:Math.max(0,Number(e.usedTokens)||n),totalTokens:o,inputTokens:n,estimatedInputTokens:i,knownInputTokens:r,inputTokenSource:c,reservedOutputTokens:a,percent:s,color:e.color||Be(s),isCompacted:e.isCompacted,compactedUpToIndex:e.compactedUpToIndex,originalMessageCount:e.originalMessageCount,effectiveMessageCount:e.effectiveMessageCount,breakdown:e.breakdown}}function He(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`)}function Ue(e){let t=Math.max(0,Number(e)||0);return t>0?X(t):null}function We({usage:e,contextWindow:t,serverCalculated:n,compacted:r}){let i=e.inputTokenSource===`provider`?`provider context`:e.inputTokenSource===`mixed`?`provider/local mixed context`:`estimated context`,a=[`Context used: ${e.percent}% (${X(e.totalTokens)} / ${X(t)} tokens)`,`Input/context: ${X(e.inputTokens)} (${i})`,`Local estimate: ${X(e.estimatedInputTokens)}`],o=e.breakdown;return o&&(a.push(` System prompt: ${Ue(o.systemPromptTokens)??`0`}`,` Tools schema: ${Ue(o.toolsTokens)??`0`}`,` Messages: ${Ue(o.messagesTokens)??`0`}`),(o.providerUsageTokens||o.trailingTokens)&&a.push(` Provider usage baseline: ${Ue(o.providerUsageTokens)??`0`}`,` Trailing messages after usage: ${Ue(o.trailingTokens)??`0`}`)),a.push(`Reserved output: ${X(e.reservedOutputTokens)}`),n&&a.push(`Source: server calculated via pi-agent-core/pi-ai`),a.push(r?`Scope: compacted model context, not full visible chat history`:`Scope: full model context`),r&&e.originalMessageCount!==void 0&&e.effectiveMessageCount!==void 0&&a.push(`Messages: ${e.effectiveMessageCount} effective / ${e.originalMessageCount} visible`),e.knownInputTokens&&e.knownInputTokens>0&&a.push(`Provider context tokens: ${X(e.knownInputTokens)}`),a.join(`
|
|
145
|
+
`)}function Ge(e,t){if(!t){e.removeAttribute(`role`),e.removeAttribute(`tabindex`),e.style.cursor=``;return}e.setAttribute(`role`,`button`),e.tabIndex=0,e.style.cursor=`pointer`,!e.dataset.quickforgeGitBranchBound&&(e.dataset.quickforgeGitBranchBound=`true`,e.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),t()}),e.addEventListener(`keydown`,e=>{e.key!==`Enter`&&e.key!==` `||(e.preventDefault(),e.stopPropagation(),t())}))}var Ke=(0,ze.renderToStaticMarkup)((0,b.createElement)(t,{size:13,strokeWidth:2,"aria-hidden":!0,style:{flex:`0 0 auto`}}));function qe({panel:e,getSystemPrompt:t,getMessages:n,getContextWindow:r,getTools:i,getMaxTokens:a,getEffectiveMessages:o,getServerContextUsage:s,getGitBranch:c,onGitBranchClick:l,renderInline:u=!0,onDisplayChange:d}){return{update:()=>{let f=r(),p=n(),m=o?.()??p,h=e.querySelector(`.quickforge-context-usage`),g=e.querySelector(`.quickforge-context-usage-label`),_=e.querySelector(`.quickforge-git-branch-inline`),v=u?e.querySelector(`message-editor`)?.parentElement?.querySelector(`.ml-auto.items-center`):null,y=c?.()?.trim()||void 0,b={gitBranch:y};if(!u)_?.remove(),h?.remove(),g?.remove();else if(y&&v){let e=`${Ke}<span style="max-width: 8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">${He(y)}</span>`,t=`Git branch: ${y}`;if(_)_.dataset.quickforgeGitBranch!==y&&(_.innerHTML=e,_.dataset.quickforgeGitBranch=y),_.title=t,_.setAttribute(`aria-label`,t),Ge(_,l);else{let n=document.createElement(`span`);n.className=`quickforge-git-branch-inline`,n.dataset.quickforgeGitBranch=y,n.title=t,n.setAttribute(`aria-label`,t),n.innerHTML=e,n.style.cssText=[`display: inline-flex`,`align-items: center`,`gap: 0.25rem`,`max-width: 10rem`,`color: hsl(var(--muted-foreground))`,`font-size: 12px`,`line-height: 1`,`font-weight: 500`].join(`;`),Ge(n,l),v.prepend(n)}}else _?.remove();if(!f)return u&&(h?.remove(),g?.remove()),d?.(b),b;let x=s?.(),S=m.length>0,C=x?Ve(x,f):S?De(t(),m,f,i?.()??[],a?.()):{contextWindow:f,usedTokens:0,totalTokens:0,inputTokens:0,estimatedInputTokens:0,inputTokenSource:`estimated`,reservedOutputTokens:0,percent:0,color:`hsl(142 72% 45%)`},w=C.contextWindow||f,T=!!C.isCompacted||m!==p,E=We({usage:C,contextWindow:w,serverCalculated:!!x,compacted:T});if(b.context={percent:C.percent,color:C.color,label:`${C.percent}% · ${X(C.totalTokens)} / ${X(w)} tokens`,title:E},d?.(b),!u||!v)return h?.remove(),g?.remove(),b;let D=Math.min(100,Math.max(0,C.percent)),O=`conic-gradient(${C.color} ${D*3.6}deg, rgb(229 231 235) 0deg)`,k=h??document.createElement(`span`);k.className=`quickforge-context-usage`,k.title=E,k.setAttribute(`aria-label`,E),k.style.cssText=[`position: relative`,`display: inline-flex`,`width: 14px`,`height: 14px`,`flex: 0 0 auto`,`border-radius: 9999px`,`background: ${O}`,`vertical-align: middle`,`box-shadow: 0 0 0 1px rgb(0 0 0 / 0.06)`].join(`;`);let A=k.firstElementChild;A||(A=document.createElement(`span`),k.append(A)),A.style.cssText=[`position: absolute`,`inset: 3px`,`border-radius: 9999px`,`background: hsl(var(--background))`].join(`;`);let j=k.nextElementSibling;return j?.classList.contains(`quickforge-context-usage-label`)||(j=document.createElement(`span`),j.className=`quickforge-context-usage-label`,j.style.cssText=`color: hsl(var(--muted-foreground)); font-size: 12px; line-height: 1;`),j.textContent=`${C.percent}%`,j.title=E,j.setAttribute(`aria-label`,E),h?k.nextElementSibling!==j&&k.after(j):(v.prepend(j),v.prepend(k)),b}}}var Je=`<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect width="14" height="14" x="8" y="8" rx="2" ry="2"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/></svg>`,Ye=`<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M20 6 9 17l-5-5"/></svg>`,Xe=`<svg xmlns="http://www.w3.org/2000/svg" width="17" height="17" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9 14 4 9l5-5"/><path d="M4 9h10.5a5.5 5.5 0 0 1 0 11H11"/></svg>`,Ze=`<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="18" r="3"/><circle cx="6" cy="6" r="3"/><circle cx="18" cy="6" r="3"/><path d="M18 9v1a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2V9"/><path d="M12 12v3"/></svg>`,Qe=`<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polygon points="6 3 20 12 6 21 6 3"/></svg>`,$e=`<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 2v6h-6"/><path d="M3 12a9 9 0 0 1 15.36-5.64L21 9"/><path d="M3 22v-6h6"/><path d="M21 12a9 9 0 0 1-15.36 5.64L3 15"/></svg>`,et=`<svg class="quickforge-plan-mode-icon" xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 6h1"/><path d="M4 12h1"/><path d="M4 18h1"/><path d="M9 6h11"/><path d="M9 12h11"/><path d="M9 18h11"/></svg>`,tt=`<svg class="quickforge-plan-remove-icon" xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>`,nt=`<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 5v14"/><path d="M5 12h14"/></svg>`,rt=`<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"/></svg>`,it=`<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M7.5 4.5h5a1.5 1.5 0 0 1 1.5 1.5v2h1a2.5 2.5 0 0 1 0 5h-1v2a1.5 1.5 0 0 1-1.5 1.5h-2v1a2.5 2.5 0 0 1-5 0v-1h-2A1.5 1.5 0 0 1 2 15.5v-3h1a2 2 0 1 0 0-4H2v-2A1.5 1.5 0 0 1 3.5 5h2v-1a2.5 2.5 0 0 1 5 0v.5Z"/></svg>`,at=`<svg viewBox="0 0 20 20" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.65" stroke-linecap="round" stroke-linejoin="round"><path d="M5.4 2.8h6.1L15.8 7v10.2H5.4z"/><path d="M11.4 2.9V7h4.1"/><path d="M7.6 10.2h5"/><path d="M7.6 13h4.3"/></svg>`,ot=`<svg viewBox="0 0 20 20" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.65" stroke-linecap="round" stroke-linejoin="round"><rect x="3.4" y="4" width="13.2" height="12.2" rx="1.5"/><path d="M3.4 8h13.2"/><path d="M7.8 4v12.2"/><path d="M12.2 4v12.2"/><path d="M3.4 12h13.2"/></svg>`,st=`<svg viewBox="0 0 20 20" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.65" stroke-linecap="round" stroke-linejoin="round"><path d="M3 4.2h14"/><rect x="4.2" y="4.2" width="11.6" height="8.4" rx="1.2"/><path d="M10 12.6v3.2"/><path d="m7.2 17 2.8-1.2 2.8 1.2"/><path d="M7.1 9.5 9 7.7l1.5 1.3 2.4-2.5"/></svg>`;function ct(e,t,n){let r=f(`copied`),i=Number(e.dataset.quickforgeCopyFeedbackTimer);i&&window.clearTimeout(i),K(e,Ye),e.title=r,e.setAttribute(`aria-label`,r),e.style.color=`rgb(5 150 105)`;let a=window.setTimeout(()=>{K(e,n),e.title=t,e.setAttribute(`aria-label`,t),e.style.color=``,delete e.dataset.quickforgeCopyFeedbackTimer},1200);e.dataset.quickforgeCopyFeedbackTimer=String(a)}function lt(e,t,n,r){let i=document.createElement(`button`);return i.type=`button`,i.dataset.quickforgeAction=e,i.title=t,i.setAttribute(`aria-label`,t),K(i,n),i.className=`pointer-events-auto inline-flex size-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-transparent hover:text-foreground disabled:cursor-not-allowed disabled:opacity-40`,i.onclick=e=>{e.stopPropagation(),r(i)},i}function ut(e){e.querySelectorAll(`.quickforge-rollback-popover`).forEach(e=>{e.quickforgeCleanup?.(),(e.closest(`.quickforge-rollback-action`)?.querySelector(`button[data-quickforge-action="rollback"]`))?.setAttribute(`aria-expanded`,`false`),e.remove()})}function dt(e){let{panel:t,button:n,messageIndex:r,title:i,description:a,onConfirm:o}=e,s=n.closest(`.quickforge-rollback-action`);if(!s||n.disabled)return;if(s.querySelector(`.quickforge-rollback-popover`)){ut(t);return}ut(t);let c=document.createElement(`div`);c.className=`quickforge-rollback-popover`,c.setAttribute(`role`,`dialog`),c.setAttribute(`aria-label`,i),c.tabIndex=-1;let l=document.createElement(`div`);l.className=`quickforge-rollback-popover-arrow`;let u=document.createElement(`div`);u.className=`quickforge-rollback-popover-title`,u.textContent=i;let d=document.createElement(`div`);d.className=`quickforge-rollback-popover-description`,d.textContent=a;let p=document.createElement(`div`);p.className=`quickforge-rollback-popover-footer`;let m=document.createElement(`button`);m.type=`button`,m.className=`quickforge-rollback-popover-cancel`,m.textContent=f(`cancel`);let h=document.createElement(`button`);h.type=`button`,h.className=`quickforge-rollback-popover-confirm`,h.textContent=f(`confirmRollback`),p.append(m,h),c.append(l,u,d,p);let g=()=>ut(t),_=e=>{let t=e.target;!t||c.contains(t)||n.contains(t)||g()},v=e=>{e.key===`Escape`&&(e.preventDefault(),g())};c.quickforgeCleanup=()=>{document.removeEventListener(`pointerdown`,_,!0),document.removeEventListener(`keydown`,v)},c.addEventListener(`pointerdown`,e=>e.stopPropagation()),c.addEventListener(`click`,e=>e.stopPropagation()),m.addEventListener(`click`,g),h.addEventListener(`click`,async()=>{h.disabled=!0,m.disabled=!0,h.textContent=f(`rollingBack`);try{await o(r)}finally{g()}}),s.append(c),n.setAttribute(`aria-expanded`,`true`),document.addEventListener(`pointerdown`,_,!0),document.addEventListener(`keydown`,v),window.requestAnimationFrame(()=>h.focus())}function ft(e){let t=document.createElement(`span`);t.className=`quickforge-rollback-action`;let n=lt(`rollback`,f(`rollback`),Xe,t=>{dt({panel:e.panel,button:t,messageIndex:e.messageIndex,title:e.title,description:e.description,onConfirm:e.onConfirm})});return n.disabled=e.isDisabled,n.setAttribute(`aria-haspopup`,`dialog`),n.setAttribute(`aria-expanded`,`false`),t.append(n),t}var pt=new Set([`bash`,`sh`,`shell`,`zsh`,`fish`,`cmd`,`bat`,`batch`,`powershell`,`ps1`,`terminal`,`console`]),mt=/\b(rm\s+-rf|sudo|chmod\b|chown\b|npm\s+publish|pnpm\s+publish|yarn\s+publish|git\s+push|curl\b[^\n|;]*\|\s*(sh|bash)|wget\b[^\n|;]*\|\s*(sh|bash))\b/i;function ht(e){return e.role===`user`||e.role===`user-with-attachments`||e.role===`assistant`}function gt(e){return e.role===`user`||e.role===`user-with-attachments`}function _t(e){return e.role===`assistant`?v(e).trim().length>0:!1}function vt(e){return e.querySelector(`message-list`)}function yt(e){let t=vt(e);return t?Array.from(t.querySelectorAll(`user-message, assistant-message`)).filter(e=>e.closest(`message-list`)===t):[]}function bt(e){if(typeof e.getDecodedCode==`function`)try{return e.getDecodedCode()}catch{}let t=typeof e.code==`string`?e.code:e.getAttribute(`code`)??``;if(!t)return``;try{return decodeURIComponent(escape(window.atob(t)))}catch{return t}}function xt(e){return e.replace(/\r\n/g,`
|
|
146
|
+
`).split(`
|
|
147
|
+
`).map(e=>e.replace(/^\s*\$\s+/,``).replace(/^\s*>\s+/,``).replace(/^\s*PS\s+[^>\n]+>\s+/i,``)).join(`
|
|
148
|
+
`).trim()}function St(e){return e.split(`
|
|
149
|
+
`).map(e=>e.trim()).filter(Boolean).length}function Ct(e){let t=String(e.language??e.getAttribute(`language`)??``).trim().toLowerCase();return pt.has(t)}function wt(e,t){e.querySelectorAll(`assistant-message markdown-block code-block`).forEach(e=>{let n=e.querySelector(`[data-quickforge-action="execute-markdown-command"]`);if(!Ct(e)){n?.remove(),delete e.dataset.quickforgeCommand;return}let r;if(n&&e.dataset.quickforgeCommand!==void 0){if(n.disabled===t)return;r=e.dataset.quickforgeCommand}else r=xt(bt(e));if(!r){n?.remove(),delete e.dataset.quickforgeCommand;return}e.dataset.quickforgeCommand=r;let i=f(`executeInTerminal`),a=n??lt(`execute-markdown-command`,i,Qe,()=>{let t=xt(bt(e));t&&window.dispatchEvent(new CustomEvent(`quickforge:execute-markdown-command`,{detail:{command:t,confirm:St(t)>1,dangerous:mt.test(t)}}))});if(a.title=i,a.setAttribute(`aria-label`,i),a.disabled=t,a.className=`pointer-events-auto inline-flex size-8 items-center justify-center rounded-md text-emerald-600 transition-colors hover:bg-emerald-500/10 hover:text-emerald-700 disabled:cursor-not-allowed disabled:opacity-40 dark:text-emerald-400 dark:hover:text-emerald-300`,!n){let t=e.querySelector(`:scope > div > div:first-child`),n=t?.querySelector(`copy-button`);if(t&&n){let e=document.createElement(`div`);e.className=`flex items-center gap-1`,n.before(e),e.appendChild(n),e.appendChild(a)}}})}function Tt(e,t,n,r){let i=yt(e),a=0;for(let e=0;e<t.length;e++)if(ht(t[e])){if(e===n){let e=i[a];if(e){r.nextElementSibling!==e&&e.before(r);return}break}a+=1}let o=e.querySelector(`message-list`);o&&o.firstElementChild!==r&&o.prepend(r)}function Et(e){let t=e,n=t?.role===`assistant`?v(t):m(t);return(n.match(/<compact_summary>\s*([\s\S]*?)\s*<\/compact_summary>/i)?.[1]??n).trim()}function Dt(e,t,n=!1){let r=e.querySelector(`.quickforge-context-compaction-details`),i=e.querySelector(`.quickforge-context-compaction-summary`),a=e.querySelector(`.quickforge-context-compaction-toggle-label`),o=e.querySelector(`[data-quickforge-action="copy-compact-summary"]`);r&&(r.open=n);let s=()=>{a&&r&&(a.textContent=r.open?f(`contextCompactedHideSummary`):f(`contextCompactedViewSummary`))};i&&!i.dataset.quickforgeCompactionBound&&(i.dataset.quickforgeCompactionBound=`true`,i.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),r&&(r.open=!r.open,s())})),r&&!r.dataset.quickforgeCompactionBound&&(r.dataset.quickforgeCompactionBound=`true`,r.addEventListener(`toggle`,s)),s(),o&&(o.onclick=async e=>{e.preventDefault(),e.stopPropagation(),await p(t),ct(o,f(`contextCompactedCopySummary`),Je)})}function Ot(e){let{panel:t,getMessages:n,getContextCompaction:r}=e,i=r(),a=n(),o=t.querySelector(`.quickforge-context-compaction-notice`);if(!i||a.length===0){o?.remove();return}let s=Math.min(a.length,Math.max(0,Number(i.compactedUpToIndex)||0));if(s<=0){o?.remove();return}let c=i.summaryMessage?Et(i.summaryMessage):``,l=o?.querySelector(`.quickforge-context-compaction-details`)?.open??!1,u=o??document.createElement(`div`),d=u.dataset.summaryText??``,p=u.dataset.hasSummary===`true`,m=!o||d!==c||p!==!!c;u.className=`quickforge-context-compaction-notice`,u.dataset.tailStart=String(s),u.dataset.summaryText=c,u.dataset.hasSummary=String(!!c),u.title=f(`contextCompactedTooltip`),u.setAttribute(`aria-label`,f(`contextCompactedTooltip`)),m&&(u.innerHTML=c?`
|
|
150
|
+
<details class="quickforge-context-compaction-details">
|
|
151
|
+
<summary class="quickforge-context-compaction-summary">
|
|
152
|
+
<div class="quickforge-context-compaction-line"></div>
|
|
153
|
+
<div class="quickforge-context-compaction-pill">
|
|
154
|
+
<span class="quickforge-context-compaction-dot" aria-hidden="true"></span>
|
|
155
|
+
<span><strong>${$(f(`contextCompactedLabel`))}</strong> · ${$(f(`contextCompactedTimelineLabel`))} · <span class="quickforge-context-compaction-toggle-label"></span></span>
|
|
156
|
+
</div>
|
|
157
|
+
<div class="quickforge-context-compaction-line"></div>
|
|
158
|
+
</summary>
|
|
159
|
+
<div class="quickforge-context-compaction-card">
|
|
160
|
+
<div class="quickforge-context-compaction-card-header">
|
|
161
|
+
<span>${$(f(`contextCompactedSummaryTitle`))}</span>
|
|
162
|
+
<button type="button" class="quickforge-context-compaction-copy" data-quickforge-action="copy-compact-summary">${Je}<span>${$(f(`contextCompactedCopySummary`))}</span></button>
|
|
163
|
+
</div>
|
|
164
|
+
<pre class="quickforge-context-compaction-text">${$(c)}</pre>
|
|
165
|
+
</div>
|
|
166
|
+
</details>
|
|
167
|
+
`:`
|
|
168
|
+
<div class="quickforge-context-compaction-summary" role="separator">
|
|
169
|
+
<div class="quickforge-context-compaction-line"></div>
|
|
170
|
+
<div class="quickforge-context-compaction-pill">
|
|
171
|
+
<span class="quickforge-context-compaction-dot" aria-hidden="true"></span>
|
|
172
|
+
<span><strong>${$(f(`contextCompactedLabel`))}</strong> · ${$(f(`contextCompactedTimelineLabel`))}</span>
|
|
173
|
+
</div>
|
|
174
|
+
<div class="quickforge-context-compaction-line"></div>
|
|
175
|
+
</div>
|
|
176
|
+
`),c&&Dt(u,c,l),Tt(t,a,s,u)}var kt=`.quickforge-assistant-waiting`;function At(e){e.querySelectorAll(kt).forEach(e=>e.remove())}function jt(e){let t=e.querySelectorAll(`thinking-block, tool-message`);for(let e of t)if(!e.closest(`.quickforge-process-body`))return!0;let n=e.querySelectorAll(`markdown-block, code-block`);for(let e of n)if(!e.closest(`.quickforge-process-body`)&&(e.textContent??``).trim().length>0)return!0;let r=e.cloneNode(!0);return r.querySelectorAll(`.quickforge-message-actions`).forEach(e=>e.remove()),r.querySelectorAll(`.quickforge-process-body`).forEach(e=>e.remove()),(r.textContent??``).trim().length>0}function Mt(e){let{panel:t,getMessages:n,isStreaming:r,isActive:i}=e,a=t.querySelector(kt);if(!r()||!i)return At(t),!1;let o=vt(t),s=n(),c=s.map((e,t)=>({message:e,index:t})).filter(({message:e})=>ht(e)),l=(()=>{for(let e=c.length-1;e>=0;e--)if(gt(c[e].message))return e;return-1})();if(!o||l<0)return a?.remove(),!1;let u=c[l],d=s.slice(u.index+1).some(_t),p=yt(t),m=p[l],h=p.slice(l+1).some(e=>e.matches(`assistant-message`)&&jt(e));if(!m||d||h)return a?.remove(),!1;let g=a??document.createElement(`div`);return g.className=`quickforge-assistant-waiting`,g.setAttribute(`role`,`status`),g.setAttribute(`aria-live`,`polite`),g.setAttribute(`aria-label`,f(`assistantWaitingAriaLabel`)),a||(g.innerHTML=`
|
|
177
|
+
<div class="quickforge-assistant-waiting-dots" aria-hidden="true">
|
|
178
|
+
<span></span>
|
|
179
|
+
<span></span>
|
|
180
|
+
<span></span>
|
|
181
|
+
</div>
|
|
182
|
+
`),g.previousElementSibling!==m&&m.after(g),!0}function Nt(e){let{panel:t,getMessages:n,isStreaming:r,onCopyAnswer:i,onRollbackFromMessage:a,onRetryFromMessage:o,onForkFromMessage:s,onOpenLocalFilePath:c,disableFork:l,readOnly:u=!1,enableTerminalCommandActions:d=!0,rollbackConfirmTitle:p=f(`rollbackConfirmTitle`),rollbackConfirmDescription:h=f(`rollbackConfirm`)}=e,g=n().map((e,t)=>({message:e,index:t})).filter(({message:e})=>e.role===`user`||e.role===`user-with-attachments`||e.role===`assistant`),_=(()=>{for(let e=g.length-1;e>=0;e--)if(g[e].message.role!==`assistant`)return g[e]})(),y=yt(t),b=e=>{let t=f(`copy`);return lt(`copy`,t,Je,async n=>{let r=e();if(r)try{await i(r),ct(n,t,Je)}catch{}})};y.forEach((e,i)=>{let d=g[i];if(!d)return;e.classList.add(`group`,`relative`),e.classList.toggle(`quickforge-assistant-message`,d.message.role===`assistant`),e.classList.toggle(`quickforge-user-message`,d.message.role!==`assistant`),d.message.role===`assistant`&&c&&Vt(e,d.message,c);let y=`quickforge-message-actions pointer-events-none mt-1 flex gap-1 opacity-0 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100 ${d.message.role===`assistant`?`px-4 justify-start`:`mx-4 justify-end`}`,x=e.querySelector(`.quickforge-message-actions`);if(x?.dataset.quickforgeLayout===`message-bottom`){x.className=y,x.parentElement===e&&x!==e.lastElementChild&&e.append(x),u&&ut(t),x.querySelectorAll(`button[data-quickforge-action="rollback"], button[data-quickforge-action="retry"], button[data-quickforge-action="fork"]`).forEach(e=>{if(u){e.closest(`.quickforge-rollback-action`)?.remove(),e.remove();return}e.disabled=r()}),r()&&ut(t);let n=x.querySelector(`button[data-quickforge-action="retry"]`),i=!u&&_&&d.index===_.index&&d.message.role!==`assistant`;if(n&&!i)n.remove();else if(!n&&i){let e=lt(`retry`,f(`retry`),$e,()=>{o(d.index)});e.disabled=r(),x.append(e)}return}x?.remove();let S=document.createElement(`div`);if(S.dataset.quickforgeLayout=`message-bottom`,S.className=y,d.message.role===`assistant`){let e=v(d.message);if(!e)return;let t=b(()=>{let t=n()[d.index];return t?v(t):e});if(S.append(t),!u&&!l){let e=lt(`fork`,f(`forkConversation`),Ze,()=>{s(d.index)});e.disabled=r(),S.append(e)}}else{let e=m(d.message);if(e){let t=b(()=>{let t=n()[d.index];return t?m(t):e});S.append(t)}if(!u){let e=ft({panel:t,messageIndex:d.index,isDisabled:r(),title:p,description:h,onConfirm:a});S.append(e)}if(!u&&_&&d.index===_.index){let e=lt(`retry`,f(`retry`),$e,()=>{o(d.index)});e.disabled=r(),S.append(e)}}e.append(S)}),Tn(t,r()),d?wt(t,r()):t.querySelectorAll(`[data-quickforge-action="execute-markdown-command"]`).forEach(e=>e.remove())}var Pt=/[A-Za-z]:[\\/][^\s"'<>`]+|(?:\/Users|\/home|\/workspace|\/mnt|\/Volumes)\/[^\s"'<>`]+/g,Ft=new Set([`.`,`,`,`;`,`:`,`!`,`?`,`)`,`]`,`}`,`>`,`。`,`,`,`;`,`:`,`!`,`?`,`)`,`】`,`》`]),It=[`pre`,`code`,`a`,`button`,`textarea`,`input`,`select`,`thinking-block`,`tool-message`,`.quickforge-file-path-link`,`.quickforge-message-actions`,`.quickforge-process-group`,`.quickforge-approval-card`].join(`,`);function Lt(e){let t=e.length;for(;t>0&&Ft.has(e[t-1]);)--t;return{path:e.slice(0,t),suffix:e.slice(t)}}function Rt(e,t){let n=document.createElement(`button`);return n.type=`button`,n.className=`quickforge-file-path-link`,n.dataset.quickforgeFilePath=e,n.textContent=e,n.title=`Open file`,n.setAttribute(`aria-label`,`Open file ${e}`),n.onclick=n=>{n.preventDefault(),n.stopPropagation(),t(e)},n}function zt(e){let t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,{acceptNode(e){let t=e.textContent??``;if(!Pt.test(t))return NodeFilter.FILTER_REJECT;Pt.lastIndex=0;let n=e.parentElement;return!n||n.closest(It)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}}),r=n.nextNode();for(;r;)t.push(r),r=n.nextNode();return t}function Bt(e,t){let n=e.textContent??``;Pt.lastIndex=0;let r,i=0,a=document.createDocumentFragment(),o=!1;for(;r=Pt.exec(n);){let e=r[0],{path:s,suffix:c}=Lt(e);if(!s)continue;let l=r.index,u=l+e.length;l>i&&a.append(document.createTextNode(n.slice(i,l))),a.append(Rt(s,t)),c&&a.append(document.createTextNode(c)),i=u,o=!0}o&&(i<n.length&&a.append(document.createTextNode(n.slice(i))),e.replaceWith(a))}function Vt(e,t,n){let r=Array.from(e.querySelectorAll(`markdown-block`)),i=r.reduce((e,t)=>e+(t.textContent?.length??0),0),a=v(t).length,o=`${String(t.timestamp??``)}:${a}:${r.length}:${i}`;e.dataset.quickforgeLocalPathSignature!==o&&(r.forEach(e=>{zt(e).forEach(e=>Bt(e,n))}),e.dataset.quickforgeLocalPathSignature=o)}var Ht=`.quickforge-process-group`,Z=`.quickforge-process-body`,Ut=`thinking-block, tool-message, streaming-message-container`,Wt=`thinking-block, tool-message, markdown-block, streaming-message-container`,Gt=`data-quickforge-process-final-summary`,Kt=`data-quickforge-process-folded`,qt=500,Jt=new WeakMap;function Yt(e){let t=Jt.get(e);return t||(t=new Map,Jt.set(e,t)),t}function Xt(e,t,n){let r=Yt(e);if(r.set(t,n),r.size<=qt)return;let i=r.keys().next().value;i&&r.delete(i)}function Zt(e,t){return`turn:${t}:started:${tn(e[0]?.message?.timestamp)??`unknown`}`}function Qt(e,t,n){let r=t.dataset.quickforgeProcessKey;t.dataset.quickforgeProcessKey=n;let i=Yt(e).get(n);if(i!==void 0){t.dataset.expanded=String(i);return}t.dataset.expanded=r===n&&t.dataset.expanded===`true`?`true`:`false`}function $t(e){return!!(e&&typeof e==`object`&&!Array.isArray(e))}function en(e){return typeof e==`number`&&Number.isFinite(e)?e:void 0}function tn(e){if(typeof e==`number`&&Number.isFinite(e))return e;if(typeof e==`string`){let t=e.trim();if(!t)return;let n=Number(t);if(Number.isFinite(n))return n;let r=Date.parse(t);return Number.isNaN(r)?void 0:r}}function nn(e){if(!$t(e))return;let t=e.details;if(!$t(t))return;let n=t.quickforgeTiming;if($t(n))return{startedAt:en(n.startedAt),finishedAt:en(n.finishedAt),durationMs:en(n.durationMs)}}function rn(e){let t=nn(e.result);if(t?.finishedAt!==void 0)return t.finishedAt;if(t?.startedAt!==void 0&&t.durationMs!==void 0)return t.startedAt+t.durationMs}function an(e){return nn(e.result)?.startedAt}function on(e){if(e===void 0||e<1e3)return``;let t=Math.max(1,Math.round(e/1e3)),n=Math.floor(t/60),r=t%60;return n>0?`${n}m ${r}s`:`${r}s`}function sn(e,t,n,r){let i=r,a=[...e].reverse().find(e=>e.message?.stopReason)?.message?.stopReason,o=Array.from(t.querySelectorAll(`tool-message`)),s=[...e.map(e=>tn(e.message?.timestamp)),...o.map(an)].filter(e=>e!==void 0),c=o.map(rn).filter(e=>e!==void 0),l=s.length>0?Math.min(...s):void 0,u=c.length>0?Math.max(...c):void 0;if(i)u=Date.now();else{let e=tn(n.dataset.quickforgeFinishedAt);e!==void 0&&e>0?u=e:(u??=Date.now(),n.dataset.quickforgeFinishedAt=String(u))}let d=l!==void 0&&u!==void 0?on(Math.max(0,u-l)):``,p=f(a===`error`?`processFailed`:a===`aborted`?`processAborted`:i?`processing`:`processed`);return d?`${p} ${d}`:p}function cn(e){let t=e.querySelector(`${Wt}, ${Ht}`);return t?.closest(`.px-4.flex.flex-col`)??t?.parentElement??null}function ln(){let e=document.createElement(`div`);e.className=`quickforge-process-group`,e.dataset.expanded=`false`;let t=document.createElement(`button`);t.type=`button`,t.className=`quickforge-process-summary`,t.innerHTML=`
|
|
183
|
+
<span class="quickforge-process-label"></span>
|
|
184
|
+
<span class="quickforge-process-chevron" aria-hidden="true">
|
|
185
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m9 18 6-6-6-6"/></svg>
|
|
186
|
+
</span>
|
|
187
|
+
`;let n=document.createElement(`div`);return n.className=`quickforge-process-body`,e.append(t,n),e}function un(e){let t=e.querySelector(Ht);if(t)return t;let n=cn(e);if(!n)return null;let r=ln();return n.insertBefore(r,n.firstElementChild),r}function dn(e,t,n,r,i){Qt(e,r,t);let a=r.querySelector(Z),o=r.querySelector(`.quickforge-process-summary`),s=r.querySelector(`.quickforge-process-label`);if(!a||!o||!s)return;let c=sn(n,a,r,i);s.textContent!==c&&(s.textContent=c);let l=r.dataset.expanded===`true`;o.setAttribute(`aria-expanded`,String(l)),o.setAttribute(`aria-label`,f(l?`collapseProcess`:`expandProcess`)),o.onclick=n=>{n.preventDefault(),n.stopPropagation();let i=r.dataset.expanded!==`true`;r.dataset.expanded=String(i),Xt(e,t,i),o.setAttribute(`aria-expanded`,String(i)),o.setAttribute(`aria-label`,f(i?`collapseProcess`:`expandProcess`))}}function fn(e){return Array.from(e.querySelectorAll(`markdown-block`)).filter(e=>!e.closest(Ut))}function pn(e){let t=e.filter(e=>(e.textContent??``).trim().length>0);return t[t.length-1]??e[e.length-1]??null}function Q(e,t,n){if(n){e.hasAttribute(t)||e.setAttribute(t,`true`);return}e.hasAttribute(t)&&e.removeAttribute(t)}function mn(e,t){if(t)return null;let n=fn(e);return pn(n.filter(e=>e.hasAttribute(Gt)))||pn(n.filter(e=>!e.closest(Z)))||pn(n)}function hn(e,t){fn(e).forEach(e=>{e===t?(Q(e,Gt,!0),Q(e,Kt,!1)):Q(e,Gt,!1)})}function gn(e){return e.length>1||e.some(e=>!!e.querySelector(Ut))}function _n(e,t,n){return e===t?!1:e.tagName.toLowerCase()===`markdown-block`?n:!0}function vn(e,t,n){return e.some(e=>Array.from(e.querySelectorAll(Wt)).some(e=>_n(e,t,n)))}function yn(e,t){return t?.closest(Z)?(e.after(t),Q(t,Kt,!1),Q(t,Gt,!0),!0):!1}function bn(e){return(e.querySelector(Z)?.childElementCount??0)>0}function xn(e){for(let t of e)t.classList.remove(`quickforge-process-source-empty`),t.querySelectorAll(Ht).forEach(e=>{let t=e.querySelector(Z);t&&Array.from(t.children).forEach(t=>{t instanceof HTMLElement&&(Q(t,Kt,!1),Q(t,Gt,!1)),e.parentElement?.insertBefore(t,e)}),e.remove()}),fn(t).forEach(e=>{Q(e,Kt,!1),Q(e,Gt,!1)})}function Sn(e,t,n,r){let i=t.querySelector(Z);if(!i)return!1;let a=!1;for(let o of e)o.querySelectorAll(Ht).forEach(e=>{let n=e.querySelector(Z);n&&n!==i&&Array.from(n.children).forEach(e=>{i.append(e),a=!0}),e!==t&&e.remove()}),o.querySelectorAll(Wt).forEach(e=>{_n(e,n,r)&&(e.closest(Z)||(Q(e,Kt,!0),i.append(e),a=!0))});return yn(t,n),a||bn(t)}function Cn(e,t){for(let n of e){if(n===t){n.classList.remove(`quickforge-process-source-empty`);continue}let e=!!n.querySelector(`markdown-block, thinking-block, tool-message, .quickforge-process-group, .quickforge-approval-card`);n.classList.toggle(`quickforge-process-source-empty`,!e)}}function wn(e,t,n,r){if(t.length===0)return;let i=t[t.length-1],a=Zt(t,r),o=i.querySelector(Ht);if(n){o&&xn(t);return}let s=gn(t),c=s?mn(i,n):null;if(s&&hn(i,c),!vn(t,c,s)){o&&(yn(o,c),xn(t));return}let l=un(i);if(l){if(!Sn(t,l,c,s)||!bn(l)){l.remove();return}dn(e,a,t,l,n),Cn(t,i)}}function Tn(e,t){let n=yt(e),r=n[n.length-1]?.tagName.toLowerCase()===`assistant-message`,i=[],a=[];for(let e of n){if(e.tagName.toLowerCase()===`user-message`){a.length>0&&i.push(a),a=[];continue}a.push(e)}a.length>0&&i.push(a),i.forEach((n,a)=>{wn(e,n,t&&r&&a===i.length-1,a)})}function En(e){switch(e){case`low`:return f(`thinkingLow`);case`medium`:return f(`thinkingMedium`);case`high`:return f(`thinkingHigh`);case`xhigh`:return f(`thinkingXHigh`);default:return f(`thinkingOff`)}}function Dn(e,t){let n=e,r=n?.currentModel;t.querySelector(`[data-quickforge-thinking-badge]`)?.remove();let i=Array.from(t.querySelectorAll(`button:not(.quickforge-yolo-inline):not(.quickforge-plan-inline)`)).find(e=>!!(r?.id&&e.textContent?.includes(r.id)));i&&(i.classList.add(`quickforge-model-trigger`),r?.reasoning?i.dataset.quickforgeThinkingLevel=`· ${En(n?.thinkingLevel)}`:delete i.dataset.quickforgeThinkingLevel)}function On(e,t,n){let r=e?.querySelector(`textarea`);if(!r)return;let i=r;i.__quickforgePlanModeHandler&&i.removeEventListener(`keydown`,i.__quickforgePlanModeHandler,!0),i.__quickforgePlanModeHandler=e=>{e.isComposing||e.key===`Process`||e.key!==`Tab`||!e.shiftKey||(e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation(),n())},i.addEventListener(`keydown`,i.__quickforgePlanModeHandler,!0),e&&(e.dataset.quickforgePlanMode=String(t))}var kn=[{mention:`Documents`,nameKey:`pluginOpenaiDocumentsName`,descriptionKey:`pluginOpenaiDocumentsDescription`,pluginName:`openai-documents`,icon:at},{mention:`Spreadsheets`,nameKey:`pluginOpenaiSpreadsheetsName`,descriptionKey:`pluginOpenaiSpreadsheetsDescription`,pluginName:`openai-spreadsheets`,icon:ot},{mention:`Presentations`,nameKey:`pluginOpenaiPresentationsName`,descriptionKey:`pluginOpenaiPresentationsDescription`,pluginName:`openai-presentations`,icon:st}];function An(e){let t=e.querySelector(`.quickforge-plus-popover`);t?.__quickforgeDismissHandler&&(document.removeEventListener(`pointerdown`,t.__quickforgeDismissHandler,!0),t.__quickforgeDismissHandler=void 0),t?.remove(),e.querySelector(`.quickforge-plus-inline`)?.setAttribute(`aria-expanded`,`false`)}function jn(e,t){e.querySelectorAll(`.quickforge-native-attachment-hidden`).forEach(e=>{t.contains(e)||e.classList.remove(`quickforge-native-attachment-hidden`)})}function Mn(e){return e.querySelector(`.quickforge-native-attachment-hidden`)||Array.from(e.querySelectorAll(`button`)).find(e=>!e.classList.contains(`quickforge-plus-inline`)&&!e.classList.contains(`quickforge-yolo-inline`)&&!e.classList.contains(`quickforge-plan-inline`))}function Nn(e,t){let n=e.querySelector(`input[type="file"]`);if(n){n.click();return}Mn(t)?.click()}function Pn({className:e,icon:t,label:n,description:r,pluginName:i,onSelect:a}){let o=document.createElement(`button`);o.type=`button`,o.className=`quickforge-plus-popover-item${e?` ${e}`:``}`,i&&(o.dataset.quickforgePluginName=i),o.innerHTML=`
|
|
188
|
+
<span class="quickforge-plus-popover-item-icon">${t}</span>
|
|
189
|
+
<span class="quickforge-plus-popover-item-main">
|
|
190
|
+
<span class="quickforge-plus-popover-item-label"></span>
|
|
191
|
+
${r?`<span class="quickforge-plus-popover-item-description"></span>`:``}
|
|
192
|
+
</span>
|
|
193
|
+
`,o.querySelector(`.quickforge-plus-popover-item-label`).textContent=n;let s=o.querySelector(`.quickforge-plus-popover-item-description`);return s&&r&&(s.textContent=r),o.onpointerdown=e=>{e.preventDefault(),e.stopPropagation(),a()},o}function Fn(e,t){let{panel:n,editor:r,leftControls:i,insertBuiltinPluginMention:a,removeCommandSuggestions:o,removeCapabilitySuggestions:s}=e;o(),s();let c=n.querySelector(`.quickforge-plus-popover`)??document.createElement(`div`);c.className=`quickforge-plus-popover`,c.setAttribute(`role`,`menu`),c.innerHTML=``;let l=document.createElement(`div`);if(l.className=`quickforge-plus-popover-header`,l.textContent=f(t===`plugins`?`composerAddPlugins`:`composerAddMenu`),c.append(l),t===`main`)c.append(Pn({icon:rt,label:f(`composerAddAttachment`),onSelect:()=>{An(n),Nn(r,i)}}),Pn({icon:it,label:f(`composerAddPlugins`),onSelect:()=>Fn(e,`plugins`)}));else{let t=Pn({className:`quickforge-plus-popover-back`,icon:`<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m15 18-6-6 6-6"/></svg>`,label:f(`composerAddBack`),onSelect:()=>Fn(e,`main`)});c.append(t);for(let e of kn)c.append(Pn({icon:e.icon,label:f(e.nameKey),description:f(e.descriptionKey),pluginName:e.pluginName,onSelect:()=>{a(e.mention),An(n)}}))}c.isConnected||r.parentElement?.insertBefore(c,r),c.__quickforgeDismissHandler&&document.removeEventListener(`pointerdown`,c.__quickforgeDismissHandler,!0),c.__quickforgeDismissHandler=e=>{let t=e.target;c.contains(t)||n.querySelector(`.quickforge-plus-inline`)?.contains(t)||An(n)},document.addEventListener(`pointerdown`,c.__quickforgeDismissHandler,!0),n.querySelector(`.quickforge-plus-inline`)?.setAttribute(`aria-expanded`,`true`)}function In(e){let{panel:t,editor:n,leftControls:r}=e;jn(n,r),Mn(r)?.classList.add(`quickforge-native-attachment-hidden`);let i=r.querySelector(`.quickforge-plus-inline`),a=n=>{n.type=`button`,q(n,nt),n.title=f(`composerAddMenu`),n.setAttribute(`aria-label`,f(`composerAddMenu`)),n.setAttribute(`aria-haspopup`,`menu`),n.setAttribute(`aria-expanded`,t.querySelector(`.quickforge-plus-popover`)?`true`:`false`),n.className=`quickforge-plus-inline inline-flex h-8 w-8 items-center justify-center rounded-md border border-transparent text-muted-foreground`,n.onpointerdown=n=>{n.preventDefault(),n.stopPropagation(),t.querySelector(`.quickforge-plus-popover`)?An(t):Fn(e,`main`)},n.onclick=e=>{e.preventDefault(),e.stopPropagation()}};if(i){a(i);return}let o=document.createElement(`button`);a(o),r.prepend(o)}function Ln(e){let{panel:t,isStreaming:n,abort:r,yoloMode:i,planMode:a,workspaceToolsEnabled:o,readOnly:s,allowModelControls:c,onToggleYoloMode:l,onTogglePlanMode:u,onInput:d,onFilesChange:p,removeCommandSuggestions:m,updateCommandSuggestions:h,setupCommandTextareaHandler:g,removeCapabilitySuggestions:_,updateCapabilitySuggestions:v,setupCapabilityTextareaHandler:y,insertBuiltinPluginMention:b,onBeforeSend:x}=e,S=t.querySelector(`message-editor`);S?.classList.add(`quickforge-composer`),S?.parentElement?.classList.add(`quickforge-composer-shell`),S?.parentElement?.parentElement?.classList.add(`quickforge-composer-dock`);let C=S?.querySelector(`textarea`);if(C&&(C.placeholder=f(`composerPlaceholder`)),s){t.querySelector(`.quickforge-composer-dock`)?.remove();return}if(S){S.onInput=e=>{d(e),h(e),v(e)},S.onFilesChange=e=>{p(e?[...e]:[])};let e=S.onSend;e&&e!==S.__quickforgePlanWrappedOnSend&&(S.__quickforgePlanBaseOnSend=e);let t=S.__quickforgePlanBaseOnSend;if(t){let e=(e,n)=>{let r=String(e??``);r.trim().length>0&&x?.(r),m(),_(),t(r,n)};S.__quickforgePlanWrappedOnSend=e,S.onSend=e}h(),v()}g(S),y(S),On(S,a,u);let w=t.querySelector(`agent-interface`);if(w){let e=w.enableModelSelector!==c;w.enableModelSelector=c,w.enableThinkingSelector=!1,e&&w.requestUpdate?.()}let T=S?.querySelectorAll(`.flex.gap-2.items-center`),E=T?.[0],D=T?.[T.length-1];if(!D)return;Dn(S,D);let O=D.querySelector(`button:last-child`);if(O){let e=()=>{O.__quickforgeStopHandler&&=(O.removeEventListener(`pointerdown`,O.__quickforgeStopHandler,!0),O.removeEventListener(`click`,O.__quickforgeStopHandler,!0),void 0)};if(n())O.disabled=!1,O.classList.remove(`quickforge-send-button`),O.classList.add(`quickforge-stop-button`),O.title=`Stop`,O.setAttribute(`aria-label`,`Stop`),delete O.dataset.quickforgeSendIcon,K(O,`<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><rect x="6" y="6" width="12" height="12" rx="2"/></svg>`),O.__quickforgeStopHandler||(O.__quickforgeStopHandler=e=>{e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation(),m(),r()},O.addEventListener(`pointerdown`,O.__quickforgeStopHandler,!0),O.addEventListener(`click`,O.__quickforgeStopHandler,!0));else if(e(),O.classList.remove(`quickforge-stop-button`),O.classList.add(`quickforge-send-button`),O.dataset.quickforgeSendIcon!==`arrow-up`){O.dataset.quickforgeSendIcon=`arrow-up`,K(O,`<svg xmlns="http://www.w3.org/2000/svg" width="17" height="17" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 19V5"/><path d="m5 12 7-7 7 7"/></svg>`);let e=O.querySelector(`svg`)?.parentElement;e&&e!==O&&e.style.transform&&(e.style.transform=``)}}if(!E){t.querySelector(`.quickforge-plus-inline`)?.remove(),An(t),t.querySelector(`.quickforge-yolo-inline`)?.remove(),t.querySelector(`.quickforge-plan-inline`)?.remove();return}S&&In({panel:t,editor:S,leftControls:E,insertBuiltinPluginMention:b,removeCommandSuggestions:m,removeCapabilitySuggestions:_});let k=f(`planModeEnabledTitle`),A=`${et}${tt}<span>${f(`planModeLabel`)}</span>`,j=e=>{e.preventDefault(),e.stopPropagation(),u()},ee=e=>{e.key!==`Enter`&&e.key!==` `||j(e)},te=t.querySelector(`.quickforge-plan-inline`),ne=e=>{q(e,A),e.title=k,e.setAttribute(`aria-label`,k),e.setAttribute(`aria-pressed`,String(a)),e.className=`quickforge-plan-inline inline-flex h-8 items-center justify-center gap-1.5 rounded-md border border-transparent px-2 text-xs font-medium text-muted-foreground`,e.onpointerdown=j,e.onclick=e=>{e.preventDefault(),e.stopPropagation()},e.onkeydown=ee};if(!a)te?.remove();else if(te)ne(te);else{let e=document.createElement(`button`);e.type=`button`,ne(e);let t=E.querySelector(`.quickforge-yolo-inline`);t?E.insertBefore(e,t.nextSibling):E.append(e)}if(!o){t.querySelector(`.quickforge-yolo-inline`)?.remove();return}let M=i?`<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 3 19 6v5c0 4.5-2.8 8.4-7 10-4.2-1.6-7-5.5-7-10V6l7-3Z"/><path d="m9 12 2 2 4-4"/></svg>`:`<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 3 19 6v5c0 4.5-2.8 8.4-7 10-4.2-1.6-7-5.5-7-10V6l7-3Z"/><path d="M9 12h6"/></svg>`,N=`quickforge-yolo-inline inline-flex h-8 items-center justify-center rounded-md border border-transparent px-2 text-xs font-medium ${i?`bg-emerald-500/10 text-emerald-700 dark:text-emerald-400`:`text-muted-foreground`}`,P=f(i?`yoloEnabledTitle`:`yoloDisabledTitle`),F=e=>{e.preventDefault(),e.stopPropagation(),l()},I=e=>{e.key!==`Enter`&&e.key!==` `||F(e)},L=t.querySelector(`.quickforge-yolo-inline`);if(L){let e=L.getAttribute(`aria-pressed`),t=String(i);e!==t&&(q(L,M),L.setAttribute(`aria-pressed`,t),L.className=N),L.title!==P&&(L.title=P,L.setAttribute(`aria-label`,P)),L.onpointerdown=F,L.onclick=e=>{e.preventDefault(),e.stopPropagation()},L.onkeydown=I;let n=E.querySelector(`.quickforge-plan-inline`);n&&L.nextSibling!==n&&E.insertBefore(n,L.nextSibling);return}let R=document.createElement(`button`);R.type=`button`,q(R,M),R.title=P,R.setAttribute(`aria-label`,P),R.setAttribute(`aria-pressed`,String(i)),R.className=N,R.onpointerdown=F,R.onclick=e=>{e.preventDefault(),e.stopPropagation()},R.onkeydown=I,E.append(R);let z=E.querySelector(`.quickforge-plan-inline`);z&&E.insertBefore(z,R.nextSibling)}function Rn(e){let t=e.querySelector(`message-editor`),n=t?.querySelector(`textarea`);return{text:t?.value??n?.value??``,attachments:t?.attachments?[...t.attachments]:[]}}function zn(e,t,n){let r=Rn(e);J(r)?t.set(n,r):t.delete(n)}function Bn(e,t,n,r){if(!J(t))return;let i={text:t.text,attachments:t.attachments?[...t.attachments]:[]},a=()=>{let t=e.querySelector(`message-editor`),n=t?.querySelector(`textarea`);t&&(t.value=i.text,t.attachments=i.attachments,t.requestUpdate?.(),t.onInput?.(i.text),t.onFilesChange?.(i.attachments)),n&&(n.value=i.text,n.dispatchEvent(new Event(`input`,{bubbles:!0})),n.focus())};e.querySelector(`agent-interface`)?.setInput?.(i.text,i.attachments),a(),requestAnimationFrame(a),window.setTimeout(a,0),n.set(r,i)}var Vn=`.quickforge-approval-card`;function Hn(e){if(!e.startsWith(`mcp__`))return null;let t=e.slice(5),n=t.indexOf(`__`);return n<=0||n>=t.length-2?null:{serverName:t.slice(0,n),toolName:t.slice(n+2)}}function Un(e,t){return typeof t.summary==`string`?t.summary:e===`run_command`&&typeof t.command==`string`?t.command:e===`activate_skill`&&typeof t.name==`string`?t.name:e===`read_skill_resource`&&typeof t.path==`string`||typeof t.path==`string`?t.path:typeof t.query==`string`?t.query:typeof t.name==`string`?t.name:``}function Wn(e,t){let n=Un(e,t);return`
|
|
194
|
+
${n?`<div class="text-xs text-muted-foreground mb-1">${$(f(`toolArgsSummary`))}: ${$(n)}</div>`:``}
|
|
195
|
+
<div class="text-xs bg-background border rounded p-2 text-muted-foreground">${$(f(`toolDetailsHidden`))}</div>
|
|
196
|
+
`}function Gn(e,t,n,r,i){let{panel:a,onApprove:o,onReject:s}=e;if(a.querySelector(`.quickforge-approval-card[data-tool-call-id="${CSS.escape(n)}"]`))return;Kn(a);let c=document.createElement(`div`);c.className=`quickforge-approval-card pointer-events-auto mb-4 mx-4 rounded-lg border border-amber-300 dark:border-amber-700 bg-amber-50 dark:bg-amber-950/30 p-4`,c.dataset.toolCallId=n;let l=Hn(t),u=l?`MCP · ${l.serverName} · ${l.toolName}`:t,d=i?.type===`subagent`?i.label||i.subagent||`Subagent`:``,p=document.createElement(`div`);if(p.className=`flex items-center gap-2 mb-3 text-sm font-medium text-amber-800 dark:text-amber-300`,p.innerHTML=`<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>`,p.append(` ${d?f(`subagentToolApprovalWaiting`,{source:d,toolName:u}):f(`toolApprovalWaiting`,{toolName:u})}`),c.append(p),d){let e=document.createElement(`div`);e.className=`mb-3 rounded-md border border-amber-200/80 bg-background/65 px-2.5 py-1.5 text-xs text-amber-800/85 dark:border-amber-800/70 dark:text-amber-200/85`,e.textContent=f(`toolApprovalSourceSubagent`,{source:d}),c.append(e)}let m=document.createElement(`div`);m.className=`quickforge-approval-preview mb-3`;let g=h().showToolDetails;if(l)m.innerHTML=`
|
|
197
|
+
<div class="rounded-md border bg-background/70 p-2 text-xs text-muted-foreground">
|
|
198
|
+
<div><span class="font-medium text-foreground">Source:</span> MCP</div>
|
|
199
|
+
<div><span class="font-medium text-foreground">Server:</span> ${$(l.serverName)}</div>
|
|
200
|
+
<div><span class="font-medium text-foreground">Tool:</span> ${$(l.toolName)}</div>
|
|
201
|
+
</div>
|
|
202
|
+
${g?`<pre class="mt-2 text-xs bg-background border rounded p-2 max-h-40 overflow-auto font-mono whitespace-pre-wrap">${$(JSON.stringify(r,null,2))}</pre>`:Wn(t,r)}
|
|
203
|
+
`;else if(t===`write_file`){let e=String(r.path??``),t=String(r.content??``),n=t.length>800;m.innerHTML=`
|
|
204
|
+
<div class="text-xs text-muted-foreground mb-1">📁 ${$(e)}</div>
|
|
205
|
+
<pre class="text-xs bg-background border rounded p-2 max-h-40 overflow-auto font-mono whitespace-pre-wrap">${qn(t.slice(0,800))}${n?`\n${$(f(`toolApprovalTruncated`))}`:``}</pre>
|
|
206
|
+
`}else if(t===`edit_file`){let e=String(r.path??``),t=Jn(String(r.oldText??``),String(r.newText??``));m.innerHTML=`
|
|
207
|
+
<div class="text-xs text-muted-foreground mb-1">📁 ${$(e)}</div>
|
|
208
|
+
<pre class="text-xs bg-background border rounded p-2 max-h-40 overflow-auto font-mono whitespace-pre-wrap">${t}</pre>
|
|
209
|
+
`}else if(t===`run_command`){let e=String(r.command??``);m.innerHTML=`
|
|
210
|
+
<div class="text-xs text-muted-foreground mb-1">⏱️ ${f(`toolApprovalTimeout`)}: ${$(`30m`)}</div>
|
|
211
|
+
<pre class="text-xs bg-background border rounded p-2 max-h-40 overflow-auto font-mono whitespace-pre-wrap">$ ${$(e)}</pre>
|
|
212
|
+
`}else typeof r.description==`string`?m.innerHTML=`<div class="text-xs bg-background border rounded p-2 text-muted-foreground">${$(r.description)}</div>`:m.innerHTML=g?`<pre class="text-xs bg-background border rounded p-2 max-h-40 overflow-auto font-mono whitespace-pre-wrap">${$(JSON.stringify(r,null,2))}</pre>`:Wn(t,r);c.append(m);let _=document.createElement(`div`);_.className=`mb-2 hidden text-xs text-red-700 dark:text-red-400`,c.append(_);let v=document.createElement(`div`);v.className=`flex items-center gap-2`;let y=e=>{x.disabled=e,S.disabled=e,x.classList.toggle(`opacity-60`,e),S.classList.toggle(`opacity-60`,e),x.textContent=f(e?`toolApprovalSubmitting`:`toolApprovalAccept`)},b=async e=>{_.classList.add(`hidden`),_.textContent=``,y(!0);try{await e()}catch(e){_.textContent=e instanceof Error?e.message:f(`toolApprovalFailed`),_.classList.remove(`hidden`),y(!1)}},x=document.createElement(`button`);x.type=`button`,x.className=`inline-flex items-center gap-1.5 rounded-md bg-emerald-600 px-3 py-1.5 text-xs font-medium text-white hover:bg-emerald-700 transition-colors cursor-pointer disabled:cursor-not-allowed`,x.textContent=f(`toolApprovalAccept`),x.addEventListener(`click`,e=>{e.stopPropagation(),e.preventDefault(),b(o)});let S=document.createElement(`button`);S.type=`button`,S.className=`inline-flex items-center gap-1.5 rounded-md border border-red-300 dark:border-red-700 px-3 py-1.5 text-xs font-medium text-red-700 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-950/30 transition-colors cursor-pointer disabled:cursor-not-allowed`,S.textContent=f(`toolApprovalReject`),S.addEventListener(`click`,e=>{e.stopPropagation(),e.preventDefault(),b(s)}),v.append(x,S),c.append(v);let C=a.querySelector(`message-list`);C?C.append(c):a.querySelector(`agent-interface`)?.append(c),c.scrollIntoView({behavior:`smooth`,block:`end`})}function Kn(e){e.querySelectorAll(Vn).forEach(e=>e.remove())}function $(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`)}function qn(e){return e.split(`
|
|
213
|
+
`).map(e=>{let t=$(e);return e.startsWith(`+`)?`<span style="color:rgb(22 101 52);background:rgba(34,197,94,.14);display:block;">${t}</span>`:e.startsWith(`-`)?`<span style="color:rgb(153 27 27);background:rgba(239,68,68,.12);display:block;">${t}</span>`:e.startsWith(`@@`)?`<span style="color:rgb(37 99 235);background:rgba(37,99,235,.10);display:block;">${t}</span>`:`<span style="display:block;">${t||` `}</span>`}).join(`
|
|
214
|
+
`)}function Jn(e,t){let n=e.split(`
|
|
215
|
+
`),r=t.split(`
|
|
216
|
+
`),i=[];for(let e of n)i.push(`<span style="color:rgb(153 27 27);background:rgba(239,68,68,.12);display:block;">- ${$(e)}</span>`);for(let e of r)i.push(`<span style="color:rgb(22 101 52);background:rgba(34,197,94,.14);display:block;">+ ${$(e)}</span>`);return i.join(`
|
|
217
|
+
`)}function Yn(e){return!!(e&&typeof e==`object`&&!Array.isArray(e))}function Xn(e,t){let n=e[t];return typeof n==`string`&&n.trim()?n:void 0}function Zn(e){for(let t=e.length-1;t>=0;--t)if(e[t]?.role===`user`)return t;return-1}function Qn(e){return[e.source,e.path??``,e.command??``,e.outputFile??``,e.toolCallId??``].join(`\0`)}function $n(e){if(!e?.length)return[];let t=Zn(e),n=e.slice(Math.max(0,t+1)),r=new Set,i=[];for(let e of n){if(e.role!==`toolResult`)continue;let t=typeof e.toolName==`string`?e.toolName:``,n=Yn(e.details)?e.details:void 0,a=typeof e.toolCallId==`string`?e.toolCallId:void 0;if(!n)continue;let o;if(t===`write_file`||t===`edit_file`){let e=Xn(n,`path`);e&&(o={source:t,confidence:`high`,path:e,toolCallId:a})}else if(t===`run_command`){let e=Xn(n,`command`),t=Xn(n,`outputFile`);(e||t)&&(o={source:`run_command`,confidence:`low`,command:e,outputFile:t,toolCallId:a})}if(!o)continue;let s=Qn(o);r.has(s)||(r.add(s),i.push({id:`${i.length}:${s}`,...o}))}return i}var er=`composer-drafts:v1`;function tr(e){return!!(e&&!e.startsWith(`pending-`))}function nr(e){return tr(e.sessionId)?`session:${e.sessionId}`:e.scope===`project`&&e.projectId?`new:project:${e.projectId}`:`new:global`}function rr(e){if(!e||typeof e!=`object`||Array.isArray(e))return{};let t={};for(let[n,r]of Object.entries(e)){if(!r||typeof r!=`object`||Array.isArray(r))continue;let e=r;typeof e.text==`string`&&(t[n]={text:e.text,updatedAt:typeof e.updatedAt==`string`?e.updatedAt:new Date().toISOString(),scope:e.scope===`project`?`project`:e.scope===`global`?`global`:void 0,projectId:typeof e.projectId==`string`?e.projectId:void 0,sessionId:typeof e.sessionId==`string`?e.sessionId:void 0})}return t}async function ir(e){return rr(await e.settings.get(er))}async function ar(e,t){let n=(await ir(e))[t];if(!(!n||n.text.length===0))return{text:n.text,attachments:[]}}async function or(e,t,n,r){let i=n.text??``;if(i.length===0){await sr(e,t);return}let a=await ir(e);a[t]={text:i,updatedAt:new Date().toISOString(),scope:r.scope,projectId:r.scope===`project`?r.projectId:void 0,sessionId:tr(r.sessionId)?r.sessionId:void 0},await e.settings.set(er,a)}async function sr(e,t){let n=await ir(e);Object.prototype.hasOwnProperty.call(n,t)&&(delete n[t],await e.settings.set(er,n))}var cr=r();function lr(e){let t=e.state.contextCompaction;if(!t?.summaryMessage)return e.state.messages;let n=e.state.messages,r=Math.min(n.length,Math.max(0,Number(t.compactedUpToIndex)||0));return[t.summaryMessage,...n.slice(r)]}function ur({agent:e,onModelSelect:t,revision:n,yoloMode:r,workspaceToolsEnabled:i,project:a,projectId:o,chatScope:s=`global`,storage:l=null,onToggleYoloMode:p,onRollbackFromMessage:m,onRetryFromMessage:h,onCopyAnswer:g,onForkFromMessage:v,onApproveToolCall:y,onRejectToolCall:x,onApproveAutoCompact:S,onRejectAutoCompact:C,onOpenWorkspaceGitChanges:w,onOpenLocalFilePath:T,onArtifactsChange:E,onContextUsageDisplayChange:D,restoredDraft:O,disableFork:k=!1,readOnly:A=!1,bypassClientApiKeyCheck:j=!1,allowModelControls:ee=!0,rollbackConfirmTitle:te,rollbackConfirmDescription:ne}){let M=(0,b.useRef)(null),N=(0,b.useRef)(void 0),P=(0,b.useRef)(void 0),F=(0,b.useRef)(new Map),I=(0,b.useRef)(l),L=(0,b.useRef)([]),R=(0,b.useRef)(void 0),z=(0,b.useRef)(new Set),B=(0,b.useRef)(void 0),re=(0,b.useRef)(``),[ie,ae]=(0,b.useState)(),[V,oe]=(0,b.useState)(!1),se=(0,b.useCallback)(()=>oe(e=>!e),[]),ce=(0,b.useCallback)(()=>oe(!1),[]);(0,b.useEffect)(()=>{e?.setPlanMode?.(V,V?ce:void 0)},[e,V,ce]);let H=(0,b.useCallback)(()=>{B.current&&=(window.clearTimeout(B.current),void 0)},[]);(0,b.useEffect)(()=>{I.current=l},[l]);let le=(0,b.useMemo)(()=>({sessionId:e?.sessionId,scope:s,projectId:o}),[e?.sessionId,s,o]),U=nr(le),ue=(0,b.useRef)(le),de=(0,b.useRef)(U);(0,b.useEffect)(()=>{ue.current=le,de.current=U},[le,U]),(0,b.useEffect)(()=>()=>{H()},[H]);let fe=(0,b.useCallback)((e,t,n)=>{let r=I.current;if(r){if(t.text.length===0){sr(r,e).catch(e=>d.error(`Failed to clear composer draft:`,e));return}or(r,e,t,n).catch(e=>d.error(`Failed to save composer draft:`,e))}},[]),pe=(0,b.useCallback)((e,t,n)=>{B.current&&window.clearTimeout(B.current),B.current=window.setTimeout(()=>{B.current=void 0,fe(e,t,n)},400)},[fe]),me=(0,b.useCallback)((e,t=de.current,n=ue.current)=>{let r=Rn(e);J(r)?F.current.set(t,r):F.current.delete(t),fe(t,r,n)},[fe]),W=(0,b.useRef)({onCopyAnswer:g,onRollbackFromMessage:m,onRetryFromMessage:h,onForkFromMessage:v,onToggleYoloMode:p,onTogglePlanMode:se,onApproveToolCall:y,onRejectToolCall:x,onApproveAutoCompact:S,onRejectAutoCompact:C,onOpenWorkspaceGitChanges:w,onOpenLocalFilePath:T,onArtifactsChange:E,onContextUsageDisplayChange:D,onModelSelect:t,yoloMode:r,planMode:V,workspaceToolsEnabled:i,disableFork:k,readOnly:A,allowModelControls:ee,bypassClientApiKeyCheck:j,rollbackConfirmTitle:te,rollbackConfirmDescription:ne,gitBranch:ie});(0,b.useEffect)(()=>{W.current={onCopyAnswer:g,onRollbackFromMessage:m,onRetryFromMessage:h,onForkFromMessage:v,onToggleYoloMode:p,onTogglePlanMode:se,onApproveToolCall:y,onRejectToolCall:x,onApproveAutoCompact:S,onRejectAutoCompact:C,onOpenWorkspaceGitChanges:w,onOpenLocalFilePath:T,onArtifactsChange:E,onContextUsageDisplayChange:D,onModelSelect:t,yoloMode:r,planMode:V,workspaceToolsEnabled:i,disableFork:k,readOnly:A,allowModelControls:ee,bypassClientApiKeyCheck:j,rollbackConfirmTitle:te,rollbackConfirmDescription:ne,gitBranch:ie},P.current=O});let he=a?.id??o;(0,b.useEffect)(()=>{let e=!1;return queueMicrotask(()=>{if(!e){if(!he){ae(void 0);return}_(he).then(t=>{e||ae(t.isGitRepository?t.branch:void 0)}).catch(t=>{e||(d.warn(`Failed to load git branch:`,t),ae(void 0))})}}),()=>{e=!0}},[he,n]);let ge=(0,b.useRef)(null),_e=(0,b.useRef)(null),G=(0,b.useRef)(null),K=(0,b.useRef)(null),q=(0,b.useRef)(null);(0,b.useEffect)(()=>{let e=!1;return a?.id?(fetch(`/api/project/commands?projectId=${encodeURIComponent(a.id)}`,{cache:`no-store`}).then(e=>e.ok?e.json():{commands:[]}).then(t=>{e||(L.current=Array.isArray(t.commands)?t.commands:[],G.current?.())}).catch(()=>{e||(L.current=[],G.current?.())}),()=>{e=!0}):(L.current=[],()=>{e=!0})},[a?.id,n]);let Y=(e,t,n,r,i=!1)=>{if(t.sessionId&&t.sessionId!==n||!J(t)||!i&&z.current.has(t.id))return;let a=()=>{if(!i&&z.current.has(t.id))return;let n=e.querySelector(`message-editor`),a=n?{text:n.value??n.querySelector(`textarea`)?.value??``,attachments:n.attachments?[...n.attachments]:[]}:F.current.get(r),o=R.current;(o?.id!==t.id||!J(a??ye())||a?.text===o.text)&&(Bn(e,t,F.current,r),R.current={id:t.id,text:t.text})};a(),window.requestAnimationFrame(a);for(let e of[0,50,150,300,600])window.setTimeout(a,e);e.querySelector(`agent-interface`)?.updateComplete?.then(a)};return(0,b.useEffect)(()=>{if(!M.current||!e)return;let t=new c;oe(!1);let n=e.sessionId,r=de.current,i=ue.current,a=!1,o,s=!1,l=e.state.isStreaming,p=!1,m=Oe({panel:t});_e.current=m;let h=ke({panel:t,getCustomCommands:()=>L.current,getComposerDrafts:()=>F.current,sessionId:r,setComposerDrafts:e=>{F.current=e},restoreDraftIntoComposer:e=>{Bn(t,e,F.current,r),pe(r,e,i)}}),g=Le({panel:t,restoreDraftIntoComposer:e=>{Bn(t,e,F.current,r),pe(r,e,i)}}),_=qe({panel:t,getSystemPrompt:()=>e.state.systemPrompt,getMessages:()=>e.state.messages,getEffectiveMessages:()=>lr(e),getContextWindow:()=>e.state.model?.contextWindow??0,getTools:()=>e.state.tools,getMaxTokens:()=>e.state.model?.maxTokens,getServerContextUsage:()=>e.state.contextUsage??null,getGitBranch:()=>W.current.gitBranch,onGitBranchClick:()=>W.current.onOpenWorkspaceGitChanges?.(),renderInline:!1,onDisplayChange:t=>W.current.onContextUsageDisplayChange?.(e.sessionId,t)}),v=e=>{s=!1;let n=t.querySelector(`message-editor`),a={text:e,attachments:n?.attachments?[...n.attachments]:[]};J(a)?F.current.set(r,a):F.current.delete(r),pe(r,a,i)},y=e=>{s=!1;let n=t.querySelector(`message-editor`),a=n?.querySelector(`textarea`),o={text:n?.value??a?.value??``,attachments:e?[...e]:[]};J(o)?F.current.set(r,o):F.current.delete(r),pe(r,o,i);let c=t.querySelector(`agent-interface`);c?.requestUpdate?.(),window.requestAnimationFrame(()=>G.current?.()),c?.updateComplete?.then(()=>G.current?.())},b=()=>{e.state.isStreaming?t.dataset.quickforgeAgentStreaming=`true`:delete t.dataset.quickforgeAgentStreaming},x=()=>{if(a||!t.isConnected)return;b();let n=W.current,r=$n(e.state.messages),i=JSON.stringify(r.map(e=>[e.source,e.path,e.command,e.outputFile,e.confidence]));i!==re.current&&(re.current=i,n.onArtifactsChange?.(r));try{Nt({panel:t,getMessages:()=>e.state.messages,isStreaming:()=>e.state.isStreaming,onCopyAnswer:n.onCopyAnswer,onRollbackFromMessage:n.onRollbackFromMessage,onRetryFromMessage:n.onRetryFromMessage,onForkFromMessage:n.onForkFromMessage,onOpenLocalFilePath:n.onOpenLocalFilePath,disableFork:n.disableFork,readOnly:n.readOnly,enableTerminalCommandActions:!n.readOnly,rollbackConfirmTitle:n.rollbackConfirmTitle,rollbackConfirmDescription:n.rollbackConfirmDescription}),Ot({panel:t,getMessages:()=>e.state.messages,getContextCompaction:()=>e.state.contextCompaction??null}),Mt({panel:t,getMessages:()=>e.state.messages,isStreaming:()=>e.state.isStreaming,isActive:l})}catch{}try{Ln({panel:t,isStreaming:()=>e.state.isStreaming,abort:()=>e.abort(),yoloMode:n.yoloMode,planMode:n.planMode,workspaceToolsEnabled:n.workspaceToolsEnabled,readOnly:n.readOnly,allowModelControls:n.allowModelControls,onToggleYoloMode:n.onToggleYoloMode,onTogglePlanMode:n.onTogglePlanMode,onInput:v,onFilesChange:y,removeCommandSuggestions:h.remove,updateCommandSuggestions:h.update,setupCommandTextareaHandler:h.setupTextareaHandler,removeCapabilitySuggestions:g.remove,updateCapabilitySuggestions:g.update,setupCapabilityTextareaHandler:g.setupTextareaHandler,insertBuiltinPluginMention:g.insertBuiltinPluginMention,onBeforeSend:t=>{let n=g.consumeSelectedCapabilities(t);e.setNextPromptCapabilities?.(n)}})}catch{}let o=K.current;if(o&&o.sessionId===e.sessionId){let e=o.toolCallId;Gn({panel:t,onApprove:async()=>{await W.current.onApproveToolCall(e),K.current=null,Kn(t)},onReject:async()=>{await W.current.onRejectToolCall(e),K.current=null,Kn(t)}},o.toolName,e,o.args,o.source)}else{let n=q.current;if(n&&n.sessionId===e.sessionId){let e=n.approvalId;Gn({panel:t,onApprove:async()=>{await W.current.onApproveAutoCompact?.(e),q.current=null,Kn(t)},onReject:async()=>{await W.current.onRejectAutoCompact?.(e),q.current=null,Kn(t)}},f(`contextManagement`),e,{percent:n.usage?.percent??0,threshold:n.thresholdPercent??0,keepRecentTurns:n.keepRecentTurns??2,summary:f(`autoCompactApprovalWaiting`,{percent:n.usage?.percent??0,threshold:n.thresholdPercent??0}),description:f(`autoCompactApprovalPreview`,{keepRecentTurns:n.keepRecentTurns??2})})}else Kn(t)}_.update(),m.setup(),m.isEnabled&&m.scheduleScrollToBottom()},S=!1,C,w=!1,T,E=()=>{T===void 0&&(T=window.requestAnimationFrame(()=>{T=void 0,w=!1}))},D=()=>{if(!a){w=!0;try{x()}finally{E()}}},O=()=>{S||(S=!0,C=window.requestAnimationFrame(()=>{C=void 0,S=!1,D()}))};ge.current=D;let k=()=>{p||(p=!0,window.requestAnimationFrame(()=>{if(p=!1,a)return;b();let e=t.querySelector(`agent-interface`);e?.requestUpdate?.(),G.current?.(),e?.updateComplete?.then(()=>G.current?.()),m.isEnabled&&m.scheduleScrollToBottom()}))};G.current=O,t.setAgent(e,{onApiKeyRequired:W.current.bypassClientApiKeyCheck?async()=>!0:e=>u.prompt(e),onBeforeSend:()=>{let e=P.current;e&&z.current.add(e.id),H(),s=!0,h.remove(),F.current.delete(r);let t=I.current;t&&sr(t,r).catch(e=>d.error(`Failed to clear composer draft:`,e)),m.enable()},onModelSelect:W.current.onModelSelect,toolsFactory:()=>ve(e.state.tools)}).then(()=>{if(a)return;let e=P.current,i=i=>{a||(e&&N.current!==e.id?(N.current=e.id,Y(t,e,n,r)):Bn(t,i??F.current.get(r)??ye(),F.current,r))};if(e&&N.current!==e.id)i();else{let e=F.current.get(r);e?i(e):I.current?ar(I.current,r).then(e=>i(e)).catch(e=>d.error(`Failed to load composer draft:`,e)):i()}o=new MutationObserver(()=>{w||O()}),o.observe(t,{childList:!0,subtree:!0}),window.requestAnimationFrame(()=>{a||D()})}),M.current.replaceChildren(t);let A=e.subscribe(i=>{if(i.type===`agent_start`&&(l=!0,b(),G.current?.(),m.enable(),K.current?.sessionId===e.sessionId&&(K.current=null),q.current?.sessionId===e.sessionId&&(q.current=null)),i.type===`message_start`||i.type===`message_update`||i.type===`message_end`||i.type===`turn_end`||i.type===`agent_end`){b();let e=i.message;(i.type===`message_update`||e?.role===`assistant`)&&(l=!1),G.current?.(),m.isEnabled&&m.scheduleScrollToBottom()}if(i.type===`messages_replaced`){let e=P.current;e&&N.current===e.id&&Y(t,e,n,r)}let a=i.type;if(a===`tool_execution_start`||a===`tool_execution_end`){b();let e=t.querySelector(`agent-interface`);e?.requestUpdate?.(),G.current?.(),window.requestAnimationFrame(()=>G.current?.()),e?.updateComplete?.then(()=>G.current?.()),m.isEnabled&&m.scheduleScrollToBottom()}if(a===`tool_execution_update`&&k(),i.type===`agent_end`&&(l=!1,b(),G.current?.(),K.current?.sessionId===e.sessionId&&(K.current=null,G.current?.()),q.current?.sessionId===e.sessionId&&(q.current=null,G.current?.())),a===`auto_compact_completed`||a===`messages_replaced`){let e=t.querySelector(`agent-interface`);e?.requestUpdate?.(),G.current?.(),window.requestAnimationFrame(()=>G.current?.()),e?.updateComplete?.then(()=>G.current?.())}if(a===`auto_compact_failed`&&d.warn(f(`autoCompactFailed`)),i.type===`tool_approval_required`){let e=i;K.current={toolCallId:e.toolCallId,toolName:e.toolName,args:e.args,sessionId:e.sessionId,source:e.source},G.current?.()}if(i.type===`auto_compact_approval_required`){let e=i;q.current={approvalId:e.approvalId,usage:e.usage,thresholdPercent:e.thresholdPercent,keepRecentTurns:e.keepRecentTurns,sessionId:e.sessionId},G.current?.()}});return()=>{if(s){H(),F.current.delete(r);let e=I.current;e&&sr(e,r).catch(e=>d.error(`Failed to clear composer draft:`,e))}else zn(t,F.current,r),me(t,r,i);h.remove(),h.cleanupTextareaHandler(),g.remove(),g.cleanupTextareaHandler(),a=!0,m.cleanup(),_e.current=null,A(),o?.disconnect(),C!==void 0&&window.cancelAnimationFrame(C),T!==void 0&&window.cancelAnimationFrame(T),ge.current=null,t.remove()}},[e,H,me,pe]),(0,b.useEffect)(()=>{ge.current?.(),(M.current?.querySelector(`agent-interface`))?.requestUpdate?.()},[r,V,i,ie,k,A,ee,n]),(0,b.useEffect)(()=>{let t=P.current;if(!t||!M.current)return;let n=e?.sessionId??``;if(t.sessionId&&t.sessionId!==n)return;let r=M.current.querySelector(`pi-chat-panel`);r&&(N.current=t.id,Y(r,t,n,de.current,!0))},[O,e]),(0,cr.jsx)(`div`,{ref:M,className:`min-h-0 flex-1 overflow-hidden`})}export{ur as ChatPanelHost};
|