@kafca/agentdock 0.1.47 → 0.1.49
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 +6 -0
- package/dist/renderer/assets/{Badge-BYREM3t3.js → Badge-DXjx3T4U.js} +1 -1
- package/dist/renderer/assets/{Chat-Dtb5X7sB.js → Chat-BdLcSBda.js} +1 -1
- package/dist/renderer/assets/{ChatMarkdown-_slLloCh.js → ChatMarkdown-CSc8mfpv.js} +1 -1
- package/dist/renderer/assets/{Config-pHichs7H.js → Config-b5NK6ZGX.js} +2 -2
- package/dist/renderer/assets/{CronList-CJQMeCjz.js → CronList-B4vdtNHN.js} +1 -1
- package/dist/renderer/assets/{Dashboard-CY77Imde.js → Dashboard-BItoWTOa.js} +2 -2
- package/dist/renderer/assets/{EmptyState-DCqmct2y.js → EmptyState-DUDyUsLL.js} +1 -1
- package/dist/renderer/assets/{KnowledgeDetail-DFrxa-pv.js → KnowledgeDetail-WWH6KxiG.js} +2 -2
- package/dist/renderer/assets/{KnowledgeHome-DL-vAfrH.js → KnowledgeHome-Dn-NmRxu.js} +2 -2
- package/dist/renderer/assets/{Logs-jw9Uv590.js → Logs-4zMv4FvK.js} +1 -1
- package/dist/renderer/assets/{Modal-ChSm7tk6.js → Modal-BYTZpyD2.js} +3 -3
- package/dist/renderer/assets/{MonitorList-DrEwyS71.js → MonitorList-DzcwVuQO.js} +1 -1
- package/dist/renderer/assets/{Page-DhD-zgMU.js → Page-B0lex3w0.js} +1 -1
- package/dist/renderer/assets/{ProjectDetail-BVSjpfpL.js → ProjectDetail-zhmSLySm.js} +2 -2
- package/dist/renderer/assets/{ProjectList-CHGbTJjk.js → ProjectList-DZr7agnE.js} +1 -1
- package/dist/renderer/assets/{Select-rHs9CSam.js → Select-CybeCWXZ.js} +1 -1
- package/dist/renderer/assets/SessionChat-DfsXUkfX.js +1 -0
- package/dist/renderer/assets/{SessionList-Mr1uAnRW.js → SessionList-BHzY2T_K.js} +1 -1
- package/dist/renderer/assets/ThreadChat-BB_Y2SLO.js +28 -0
- package/dist/renderer/assets/{Workspace-MRRg8ndJ.js → Workspace-COip3Zy2.js} +1 -1
- package/dist/renderer/assets/{arrow-left-BU2NB2LA.js → arrow-left-SFlZE8SW.js} +1 -1
- package/dist/renderer/assets/{book-open-D-TGvWwa.js → book-open-CENFRKvo.js} +1 -1
- package/dist/renderer/assets/{bot-IYNh8tH5.js → bot-DeqZUVXX.js} +1 -1
- package/dist/renderer/assets/{check-CCZ0JO_S.js → check-BNBksd9W.js} +1 -1
- package/dist/renderer/assets/{chevron-down-00bRZi15.js → chevron-down-BOhwopXd.js} +1 -1
- package/dist/renderer/assets/{circle-CpQ8x4k_.js → circle-BTT_e1ZT.js} +1 -1
- package/dist/renderer/assets/{desktop-D0k2aGSj.js → desktop-D88Gquih.js} +1 -1
- package/dist/renderer/assets/{funnel-UbcrCBCp.js → funnel-Btin4gwi.js} +1 -1
- package/dist/renderer/assets/{heart-DvLsV7tL.js → heart-BCqqkImr.js} +1 -1
- package/dist/renderer/assets/index-CjCuR6DI.css +11 -0
- package/dist/renderer/assets/{index-B2L4G-b_.js → index-DvKeLUQ8.js} +2 -2
- package/dist/renderer/assets/{index-dy-g2Bh4.js → index-on-scaWG.js} +9 -9
- package/dist/renderer/assets/{pencil-qBYOgW5M.js → pencil-BHu_seP7.js} +1 -1
- package/dist/renderer/assets/{play-Dn6b4AGj.js → play-BoIfwVcE.js} +1 -1
- package/dist/renderer/assets/{plus-CaApUwEm.js → plus-_5sDk2H8.js} +1 -1
- package/dist/renderer/assets/projects-BR_Y3Dov.js +1 -0
- package/dist/renderer/assets/{save-CN6yvTfD.js → save-Bn9HUt7T.js} +1 -1
- package/dist/renderer/assets/{search-Dn2MxYiO.js → search-BOU1rpMw.js} +1 -1
- package/dist/renderer/assets/{server-DpcVLHeh.js → server-BKF47usT.js} +1 -1
- package/dist/renderer/assets/{session-utils-DnD2Q_y1.js → session-utils-B4vjXX1q.js} +1 -1
- package/dist/renderer/assets/{sessions-eK5D4FLt.js → sessions-CtFBPvOB.js} +1 -1
- package/dist/renderer/assets/{shield-check-DSSJkacw.js → shield-check-Q1O3wIT4.js} +1 -1
- package/dist/renderer/assets/{trash-2-DmYJlEvO.js → trash-2-CANqI4Db.js} +1 -1
- package/dist/renderer/assets/{user-Cvf_uiyQ.js → user-DTURDktb.js} +1 -1
- package/dist/renderer/assets/{wifi-off-CCTloj-V.js → wifi-off-YfCo8Dbk.js} +1 -1
- package/dist/renderer/index.html +2 -2
- package/dist-electron/packages/core-sdk/src/index.js +4 -0
- package/dist-electron/services/local-ai-core/src/acp/local-core-acp-session-coordinator.js +51 -6
- package/dist-electron/services/local-ai-core/src/acp/store/local-core-acp-store.js +3 -0
- package/dist-electron/services/local-ai-core/src/acp/store/platform-store.js +13 -5
- package/dist-electron/services/local-ai-core/src/acp/store/schema.js +1 -0
- package/dist-electron/services/local-ai-core/src/acp/store/thread-store.js +3 -0
- package/dist-electron/services/local-ai-core/src/channel/shared/base-channel-gateway.js +4 -1
- package/dist-electron/services/local-ai-core/src/channel/shared/session-command-runtime.js +14 -3
- package/dist-electron/services/local-ai-core/src/router/workspace-router.js +10 -3
- package/dist-electron/services/local-ai-core/src/runtime/handlers/thread-handler.js +4 -0
- package/dist-electron/services/local-ai-core/src/runtime/server-routes.js +3 -0
- package/dist-electron/services/local-ai-core/src/scheduler/channel-execution-policy.js +3 -1
- package/dist-electron/services/local-ai-core/src/scheduler/lark-execution-policies.js +2 -1
- package/dist-electron/services/local-ai-core/src/scheduler/lark-schedule-adapter.js +10 -1
- package/dist-electron/services/local-ai-core/src/scheduler/weixin-execution-policies.js +2 -1
- package/dist-electron/services/local-ai-core/src/scheduler/weixin-schedule-adapter.js +10 -1
- package/dist-electron/services/local-ai-core/src/thread/thread-command-service.js +23 -2
- package/dist-electron/services/local-ai-core/src/thread/thread-slash-command-dispatcher.js +1 -0
- package/dist-electron/src/pages/Threads/thread-chat-model.js +2 -0
- package/dist-electron/tests/electron/workspace-task-store.test.js +22 -3
- package/dist-electron/tests/integration/local-core-refactor.test.js +253 -0
- package/dist-electron/tests/integration/local-core-routes.test.js +45 -0
- package/package.json +2 -2
- package/dist/renderer/assets/SessionChat-CDc2FNMA.js +0 -1
- package/dist/renderer/assets/ThreadChat-Detu5UfN.js +0 -23
- package/dist/renderer/assets/index-CO4fGqmv.css +0 -11
- package/dist/renderer/assets/projects-BwF5RlNV.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e,C as m,g as a}from"./index-
|
|
1
|
+
import{j as e,C as m,g as a}from"./index-on-scaWG.js";function u({title:s,description:r,actions:t}){return e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"text-2xl font-semibold tracking-tight text-foreground",children:s}),r?e.jsx("p",{className:"mt-1 max-w-3xl text-sm leading-6 text-muted-foreground",children:r}):null]}),t?e.jsx("div",{className:"flex shrink-0 flex-wrap gap-2",children:t}):null]})}function o({title:s,description:r,actions:t,children:l,className:d,bodyClassName:n}){return e.jsxs(m,{className:a("p-0",d),children:[(s||r||t)&&e.jsxs("div",{className:"flex flex-col gap-3 border-b px-5 py-4 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[s?e.jsx("h2",{className:"text-sm font-semibold text-foreground",children:s}):null,r?e.jsx("p",{className:"mt-1 text-sm leading-5 text-muted-foreground",children:r}):null]}),t?e.jsx("div",{className:"flex shrink-0 flex-wrap gap-2",children:t}):null]}),e.jsx("div",{className:a("p-5",n),children:l})]})}const x={neutral:"border-border bg-muted text-muted-foreground",success:"border-primary/20 bg-primary/10 text-primary",warning:"border-amber-200 bg-amber-50 text-amber-700 dark:border-amber-400/20 dark:bg-amber-500/10 dark:text-amber-200",danger:"border-destructive/20 bg-destructive/10 text-destructive dark:text-red-200",info:"border-blue-200 bg-blue-50 text-blue-700 dark:border-blue-400/20 dark:bg-blue-500/10 dark:text-blue-200"};function b({children:s,tone:r="neutral"}){return e.jsx("span",{className:a("inline-flex items-center rounded-full border px-2.5 py-1 text-xs font-medium",x[r]),children:s})}export{u as P,o as S,b as a};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{c as oe,
|
|
1
|
+
import{c as oe,D as M,u as we,E as Ne,r as c,j as s,L as Se,B as h,Z as Ce,g as Y,C as w,I as j,G as ke,H as Pe}from"./index-on-scaWG.js";import{B as A}from"./Badge-DXjx3T4U.js";import{M as ee}from"./Modal-BYTZpyD2.js";import{S as se}from"./Select-CybeCWXZ.js";import{E as ae}from"./EmptyState-DUDyUsLL.js";import{P as ze,S as B}from"./Page-B0lex3w0.js";import{g as Ie}from"./projects-BR_Y3Dov.js";import{d as Ae,c as P,h as Ee,f as E,j as Me}from"./desktop-D88Gquih.js";import{D as T,e as Le}from"./desktop-JQkhNOF4.js";import{A as $e}from"./arrow-left-SFlZE8SW.js";import{S as He}from"./shield-check-Q1O3wIT4.js";import{H as te}from"./heart-BCqqkImr.js";import{P as Re,S as De}from"./save-Bn9HUt7T.js";import{P as Be}from"./plus-_5sDk2H8.js";import{C as Te}from"./check-BNBksd9W.js";import{T as Fe}from"./trash-2-CANqI4Db.js";import{P as Oe}from"./play-BoIfwVcE.js";import"./index-DvKeLUQ8.js";import"./chevron-down-BOhwopXd.js";/**
|
|
2
2
|
* @license lucide-react v0.487.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -8,4 +8,4 @@ import{c as oe,A as M,u as we,D as Ne,r as c,j as s,L as Se,B as h,Z as Ce,g as
|
|
|
8
8
|
*
|
|
9
9
|
* This source code is licensed under the ISC license.
|
|
10
10
|
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
-
*/const Ge=[["rect",{x:"14",y:"4",width:"4",height:"16",rx:"1",key:"zuxfzm"}],["rect",{x:"6",y:"4",width:"4",height:"16",rx:"1",key:"1okwgv"}]],Je=oe("pause",Ge),Ke=e=>M.get(`/projects/${e}/heartbeat`),Ze=e=>M.post(`/projects/${e}/heartbeat/pause`),Ve=e=>M.post(`/projects/${e}/heartbeat/resume`),We=e=>M.post(`/projects/${e}/heartbeat/run`),Xe=(e,r)=>M.post(`/projects/${e}/heartbeat/interval`,{minutes:r});function F(e){return JSON.parse(JSON.stringify(e||{}))}function Qe(e,r){var i,o,d;const n=(i=e==null?void 0:e.projects)==null?void 0:i.find(m=>m.name===r);return String(((d=(o=n==null?void 0:n.agent)==null?void 0:o.options)==null?void 0:d.provider_id)||"")}function re(e,r,n){var f;const i=F(e),o=Array.isArray(i.projects)?i.projects:[],d=o.findIndex(_=>_.name===r);if(d<0)throw new Error(`Project not found in config: ${r}`);const m=o[d];return o[d]={...m,agent:{...m.agent,options:{...((f=m.agent)==null?void 0:f.options)||{},provider_id:n}}},i.projects=o,i}function Ye(e,r,n){var f;const i=F(e),o=Array.isArray(i.projects)?i.projects:[],d=o.findIndex(_=>_.name===r);if(d<0)throw new Error(`Project not found in config: ${r}`);const m=o[d];return o[d]={...m,agent:{...m.agent,options:{...((f=m.agent)==null?void 0:f.options)||{},model:n}}},i.projects=o,i}function es(e,r){const n=F(e),i=Array.isArray(n.projects)?n.projects:[];return n.projects=i.map(o=>{var d,m,f;return((m=(d=o.agent)==null?void 0:d.options)==null?void 0:m.provider_id)!==r?o:{...o,agent:{...o.agent,options:{...((f=o.agent)==null?void 0:f.options)||{},provider_id:""}}}}),n}const l={enabled:!1,provider_id:T,runtime_image_id:Le("pi").id,server_url:"http://127.0.0.1:8080",image:"agentdock/pi-acp:local",acp_port:"8080",state_scope:"project",timeout_seconds:"7200",sandbox_lifecycle:"per_thread",idle_seconds:"900",warm_pool_size:"0",cpu:"1000m",memory:"2Gi",workspace_mount_path:"/workspace",state_mount_path:"/agent-state"};function ss(e){const r=new Set,n=String((e==null?void 0:e.model)||"").trim();n&&r.add(n);for(const i of(e==null?void 0:e.models)||[]){const o=String((i==null?void 0:i.model)||"").trim();o&&r.add(o)}return[...r]}function ws(){var K,Z;const{t:e}=we(),{name:r}=Ne(),[n,i]=c.useState("overview"),[o,d]=c.useState(null),[m,f]=c.useState([]),[_,ne]=c.useState(""),[u,ie]=c.useState(null),[O,le]=c.useState([]),[ce,de]=c.useState(""),[me,U]=c.useState(!0),[g,b]=c.useState(l),[xe,q]=c.useState(!1),[G,x]=c.useState(""),[he,L]=c.useState(!1),[v,z]=c.useState({name:"",api_key:"",base_url:"",model:""}),[pe,$]=c.useState(!1),[J,fe]=c.useState("30"),p=c.useCallback(async()=>{var a,t,N,y,S;if(r)try{U(!0);const[C,A,V,W]=await Promise.allSettled([Ae(r),Ie(),Ke(r),P()]);C.status==="fulfilled"&&d(C.value);const X=A.status==="fulfilled"?A.value.providers||[]:[];if(A.status==="fulfilled"&&f(X),V.status==="fulfilled"&&ie(V.value),W.status==="fulfilled"){const R=W.value.parsed,k=(a=R==null?void 0:R.projects)==null?void 0:a.find(H=>H.name===r),Q=Qe(R,r),D=X.find(H=>H.id===Q);ne(Q),le(ss(D)),de(String(((N=(t=k==null?void 0:k.agent)==null?void 0:t.options)==null?void 0:N.model)||(D==null?void 0:D.model)||"")),b(as((S=(y=k==null?void 0:k.agent)==null?void 0:y.options)==null?void 0:S.sandbox))}}finally{U(!1)}},[r]);c.useEffect(()=>{p();const a=()=>p();return window.addEventListener("cc:refresh",a),()=>window.removeEventListener("cc:refresh",a)},[p]);const ue=async()=>{if(!(!r||!v.name)){x("");try{const a=await Ee(v),t=await P();if(!t.parsed)throw new Error("Config file is unavailable.");await E(re(t.parsed,r,a.id)),L(!1),z({name:"",api_key:"",base_url:"",model:""}),x("Provider created."),await p()}catch(a){x(a instanceof Error?a.message:String(a))}}},ge=async a=>{if(r){x("");try{const t=await P();if(!t.parsed)throw new Error("Config file is unavailable.");await E(re(t.parsed,r,a)),x("Provider selected."),await p()}catch(t){x(t instanceof Error?t.message:String(t))}}},ve=async a=>{if(r){x("");try{const t=await P();if(!t.parsed)throw new Error("Config file is unavailable.");await E(es(t.parsed,a)),await Me(a),x("Provider removed."),await p()}catch(t){x(t instanceof Error?t.message:String(t))}}},je=async a=>{if(r){x("");try{const t=await P();if(!t.parsed)throw new Error("Config file is unavailable.");await E(Ye(t.parsed,r,a)),x("Model selected."),await p()}catch(t){x(t instanceof Error?t.message:String(t))}}},be=async()=>{r&&(await Xe(r,parseInt(J)),$(!1),p())},_e=[{key:"overview",icon:qe},{key:"providers",icon:Ce},{key:"sandbox",icon:Re},{key:"heartbeat",icon:te}],ye=async()=>{var a;if(r){q(!0),x("");try{const N=(await P()).parsed||{},y=Array.isArray(N.projects)?[...N.projects]:[],S=y.findIndex(A=>A.name===r);if(S<0)throw new Error(`Project not found in config: ${r}`);const C=y[S];y[S]={...C,agent:{...C.agent,options:{...((a=C.agent)==null?void 0:a.options)||{},sandbox:ts(g)}}},await E({...N,projects:y}),x("Sandbox settings saved."),await p()}catch(t){x((t==null?void 0:t.message)||String(t))}finally{q(!1)}}};return me&&!o?s.jsx("div",{className:"flex items-center justify-center h-64 text-muted-foreground animate-pulse",children:"Loading..."}):s.jsxs("div",{className:"space-y-6 animate-fade-in",children:[s.jsx(ze,{title:r,description:"Project overview, providers, and heartbeat status. Low-frequency settings are no longer editable in the daily UI.",actions:s.jsx(Se,{to:"/projects",children:s.jsxs(h,{variant:"secondary",size:"sm",children:[s.jsx($e,{size:14})," Back"]})})}),o?s.jsxs("div",{className:"app-toolbar flex flex-wrap items-center gap-2",children:[s.jsx(I,{variant:"info",children:o.agent_type}),s.jsx(I,{variant:o.heartbeat_enabled?"success":"secondary",children:o.heartbeat_enabled?"heartbeat on":"heartbeat off"}),s.jsxs("span",{className:"text-xs text-muted-foreground",children:[o.sessions_count," sessions"]})]}):null,G?s.jsx("div",{role:"status",className:"rounded-lg border border-primary/20 bg-primary/10 px-4 py-3 text-sm text-primary",children:G}):null,s.jsx("div",{className:"flex gap-2 overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:_e.map(({key:a,icon:t})=>s.jsxs("button",{onClick:()=>i(a),className:Y("app-segment flex items-center gap-2",n===a?"app-segment-active":"app-segment-idle"),children:[s.jsx(t,{size:16}),e(`projects.tabs.${a}`)]},a))}),n==="overview"&&o&&s.jsxs("div",{className:"space-y-4",children:[s.jsx(B,{className:"app-panel",title:e("projects.platforms"),children:s.jsx("div",{className:"flex flex-wrap gap-2",children:(K=o.platforms)==null?void 0:K.map(a=>s.jsxs(I,{variant:a.connected?"success":"danger",children:[s.jsx(De,{size:12,className:"mr-1"})," ",a.type," ",a.connected?"✓":"✗"]},a.type))})}),s.jsxs(B,{className:"app-panel",title:e("sessions.title"),children:[s.jsxs("p",{className:"text-sm text-muted-foreground",children:[o.sessions_count," ",e("nav.sessions").toLowerCase()]}),((Z=o.active_session_keys)==null?void 0:Z.length)>0&&s.jsx("div",{className:"mt-2 flex flex-wrap gap-1",children:o.active_session_keys.map(a=>s.jsx(I,{variant:"default",children:a},a))})]})]}),n==="providers"&&s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"flex justify-between items-center",children:[s.jsx("h3",{className:"text-sm font-semibold text-foreground",children:e("providers.title")}),s.jsxs(h,{size:"sm",onClick:()=>L(!0),children:[s.jsx(Be,{size:14})," ",e("providers.add")]})]}),m.length===0?s.jsx(ae,{message:e("common.noData")}):s.jsx("div",{className:"space-y-2",children:m.map(a=>s.jsx(w,{className:"app-panel",children:s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"font-medium text-foreground",children:a.name}),a.id===_&&s.jsx(I,{variant:"success",children:e("providers.active")})]}),s.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[a.model," ",a.base_url?`· ${a.base_url}`:""]})]}),s.jsxs("div",{className:"flex gap-2",children:[a.id!==_&&s.jsxs(h,{size:"sm",variant:"secondary",onClick:()=>{ge(a.id)},children:[s.jsx(Te,{size:14})," ",e("providers.activate")]}),a.id!==_&&s.jsx(h,{size:"sm",variant:"danger",onClick:()=>{ve(a.id)},children:s.jsx(Fe,{size:14})})]})]})},a.id))}),O.length>0&&s.jsxs(w,{children:[s.jsx("h3",{className:"text-sm font-semibold text-foreground mb-3",children:e("providers.models")}),s.jsx("div",{className:"flex flex-wrap gap-2",children:O.map(a=>s.jsx("button",{onClick:()=>{je(a)},className:Y("px-3 py-1.5 rounded-lg text-xs font-medium transition-all",a===ce?"bg-primary/15 text-primary border border-primary/30":"bg-secondary text-secondary-foreground hover:bg-secondary/80"),children:a},a))})]}),s.jsx(ee,{open:he,onClose:()=>L(!1),title:e("providers.add"),children:s.jsxs("div",{className:"space-y-3",children:[s.jsx(j,{label:e("providers.name"),value:v.name,onChange:a=>z({...v,name:a.target.value})}),s.jsx(j,{label:"API Key",type:"password",value:v.api_key,onChange:a=>z({...v,api_key:a.target.value})}),s.jsx(j,{label:e("providers.baseUrl"),value:v.base_url,onChange:a=>z({...v,base_url:a.target.value}),placeholder:"https://api.example.com"}),s.jsx(j,{label:e("providers.model"),value:v.model,onChange:a=>z({...v,model:a.target.value})}),s.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[s.jsx(h,{variant:"secondary",onClick:()=>L(!1),children:e("common.cancel")}),s.jsx(h,{onClick:ue,children:e("providers.add")})]})]})})]}),n==="sandbox"&&s.jsx(B,{title:"Sandbox",description:"Run this project agent inside an OpenSandbox container.",actions:s.jsxs(h,{size:"sm",onClick:()=>void ye(),loading:xe,children:[s.jsx(He,{size:14})," Save"]}),children:s.jsxs("div",{className:"space-y-4",children:[s.jsxs("label",{className:"flex items-center gap-3 text-sm font-medium text-foreground",children:[s.jsx("input",{type:"checkbox",className:"h-4 w-4 rounded border-border",checked:g.enabled,onChange:a=>b(t=>({...t,enabled:a.target.checked}))}),"Enable sandbox mode"]}),g.enabled?s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"grid grid-cols-1 gap-3 md:grid-cols-2",children:[s.jsxs(se,{label:"State scope",value:g.state_scope,onChange:a=>b(t=>({...t,state_scope:a.target.value})),children:[s.jsx("option",{value:"user",children:"User"}),s.jsx("option",{value:"project",children:"Project"}),s.jsx("option",{value:"thread",children:"Thread"}),s.jsx("option",{value:"run",children:"Run"})]}),s.jsx(j,{label:"Timeout seconds",type:"number",value:g.timeout_seconds,onChange:a=>b(t=>({...t,timeout_seconds:a.target.value}))}),s.jsxs(se,{label:"Sandbox lifecycle",value:g.sandbox_lifecycle,onChange:a=>b(t=>({...t,sandbox_lifecycle:a.target.value})),children:[s.jsx("option",{value:"per_thread",children:"Keep warm per thread"}),s.jsx("option",{value:"per_run",children:"Close after each run"})]}),s.jsx(j,{label:"Idle seconds",type:"number",value:g.idle_seconds,onChange:a=>b(t=>({...t,idle_seconds:a.target.value}))}),s.jsx(j,{label:"Warm pool",type:"number",value:g.warm_pool_size,onChange:a=>b(t=>({...t,warm_pool_size:a.target.value}))}),s.jsx(j,{label:"CPU",value:g.cpu,onChange:a=>b(t=>({...t,cpu:a.target.value}))}),s.jsx(j,{label:"Memory",value:g.memory,onChange:a=>b(t=>({...t,memory:a.target.value}))})]}),s.jsx("p",{className:"text-sm text-muted-foreground",children:"OpenSandbox URL, API key env, image, ACP port, and sandbox mount paths are resolved from the global sandbox provider and runtime image registry."})]}):s.jsx("p",{className:"text-sm text-muted-foreground",children:"Local bundled runtime execution is active for this project."})]})}),n==="heartbeat"&&s.jsxs("div",{className:"space-y-4",children:[u?s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[s.jsxs(w,{children:[s.jsx("p",{className:"text-xs text-muted-foreground",children:e("heartbeat.status")}),s.jsx("p",{className:"text-lg font-bold text-foreground mt-1",children:u.paused?e("heartbeat.paused"):e("heartbeat.running")})]}),s.jsxs(w,{children:[s.jsx("p",{className:"text-xs text-muted-foreground",children:e("heartbeat.interval")}),s.jsxs("p",{className:"text-lg font-bold text-foreground mt-1",children:[u.interval_mins,"m"]})]}),s.jsxs(w,{children:[s.jsx("p",{className:"text-xs text-muted-foreground",children:e("heartbeat.runCount")}),s.jsx("p",{className:"text-lg font-bold text-foreground mt-1",children:u.run_count})]}),s.jsxs(w,{children:[s.jsx("p",{className:"text-xs text-muted-foreground",children:e("heartbeat.errorCount")}),s.jsx("p",{className:"text-lg font-bold text-foreground mt-1",children:u.error_count})]})]}),s.jsx(w,{children:s.jsxs("div",{className:"space-y-2 text-sm",children:[s.jsxs("p",{className:"text-muted-foreground",children:[e("heartbeat.lastRun"),": ",s.jsx("span",{className:"text-foreground",children:ke(u.last_run)})]}),s.jsxs("p",{className:"text-muted-foreground",children:[e("heartbeat.skippedBusy"),": ",s.jsx("span",{className:"text-foreground",children:u.skipped_busy})]}),u.last_error&&s.jsx("p",{className:"text-destructive",children:u.last_error})]})}),s.jsxs("div",{className:"flex gap-2",children:[u.paused?s.jsxs(h,{onClick:()=>{Ve(r).then(p)},children:[s.jsx(Oe,{size:14})," ",e("heartbeat.resume")]}):s.jsxs(h,{variant:"secondary",onClick:()=>{Ze(r).then(p)},children:[s.jsx(Je,{size:14})," ",e("heartbeat.pause")]}),s.jsxs(h,{variant:"secondary",onClick:()=>{We(r).then(p)},children:[s.jsx(te,{size:14})," ",e("heartbeat.trigger")]}),s.jsxs(h,{variant:"secondary",onClick:()=>$(!0),children:[s.jsx(Pe,{size:14})," ",e("heartbeat.setInterval")]})]})]}):s.jsx(ae,{message:e("common.noData")}),s.jsx(ee,{open:pe,onClose:()=>$(!1),title:e("heartbeat.setInterval"),children:s.jsxs("div",{className:"space-y-3",children:[s.jsx(j,{label:`${e("heartbeat.interval")} (min)`,type:"number",value:J,onChange:a=>fe(a.target.value)}),s.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[s.jsx(h,{variant:"secondary",onClick:()=>$(!1),children:e("common.cancel")}),s.jsx(h,{onClick:be,children:e("common.save")})]})]})})]})]})}function as(e){return{enabled:!!(e!=null&&e.enabled),provider_id:(e==null?void 0:e.provider_id)||T,runtime_image_id:(e==null?void 0:e.runtime_image_id)||l.runtime_image_id,server_url:(e==null?void 0:e.server_url)||l.server_url,image:(e==null?void 0:e.image)||l.image,acp_port:String((e==null?void 0:e.acp_port)||l.acp_port),state_scope:(e==null?void 0:e.state_scope)||l.state_scope,timeout_seconds:String((e==null?void 0:e.timeout_seconds)||l.timeout_seconds),sandbox_lifecycle:(e==null?void 0:e.sandbox_lifecycle)||l.sandbox_lifecycle,idle_seconds:String((e==null?void 0:e.idle_seconds)||l.idle_seconds),warm_pool_size:String((e==null?void 0:e.warm_pool_size)??l.warm_pool_size),cpu:(e==null?void 0:e.cpu)||l.cpu,memory:(e==null?void 0:e.memory)||l.memory,workspace_mount_path:(e==null?void 0:e.workspace_mount_path)||l.workspace_mount_path,state_mount_path:(e==null?void 0:e.state_mount_path)||l.state_mount_path}}function ts(e){return{enabled:e.enabled,provider_id:e.provider_id.trim()||T,runtime_image_id:e.runtime_image_id.trim()||l.runtime_image_id,state_scope:e.state_scope,timeout_seconds:Number(e.timeout_seconds)||Number(l.timeout_seconds),sandbox_lifecycle:e.sandbox_lifecycle,idle_seconds:Number(e.idle_seconds)||Number(l.idle_seconds),warm_pool_size:Math.max(0,Number(e.warm_pool_size)||0),cpu:e.cpu.trim()||l.cpu,memory:e.memory.trim()||l.memory}}export{ws as default};
|
|
11
|
+
*/const Ge=[["rect",{x:"14",y:"4",width:"4",height:"16",rx:"1",key:"zuxfzm"}],["rect",{x:"6",y:"4",width:"4",height:"16",rx:"1",key:"1okwgv"}]],Je=oe("pause",Ge),Ke=e=>M.get(`/projects/${e}/heartbeat`),Ze=e=>M.post(`/projects/${e}/heartbeat/pause`),Ve=e=>M.post(`/projects/${e}/heartbeat/resume`),We=e=>M.post(`/projects/${e}/heartbeat/run`),Xe=(e,r)=>M.post(`/projects/${e}/heartbeat/interval`,{minutes:r});function F(e){return JSON.parse(JSON.stringify(e||{}))}function Qe(e,r){var i,o,d;const n=(i=e==null?void 0:e.projects)==null?void 0:i.find(m=>m.name===r);return String(((d=(o=n==null?void 0:n.agent)==null?void 0:o.options)==null?void 0:d.provider_id)||"")}function re(e,r,n){var f;const i=F(e),o=Array.isArray(i.projects)?i.projects:[],d=o.findIndex(_=>_.name===r);if(d<0)throw new Error(`Project not found in config: ${r}`);const m=o[d];return o[d]={...m,agent:{...m.agent,options:{...((f=m.agent)==null?void 0:f.options)||{},provider_id:n}}},i.projects=o,i}function Ye(e,r,n){var f;const i=F(e),o=Array.isArray(i.projects)?i.projects:[],d=o.findIndex(_=>_.name===r);if(d<0)throw new Error(`Project not found in config: ${r}`);const m=o[d];return o[d]={...m,agent:{...m.agent,options:{...((f=m.agent)==null?void 0:f.options)||{},model:n}}},i.projects=o,i}function es(e,r){const n=F(e),i=Array.isArray(n.projects)?n.projects:[];return n.projects=i.map(o=>{var d,m,f;return((m=(d=o.agent)==null?void 0:d.options)==null?void 0:m.provider_id)!==r?o:{...o,agent:{...o.agent,options:{...((f=o.agent)==null?void 0:f.options)||{},provider_id:""}}}}),n}const l={enabled:!1,provider_id:T,runtime_image_id:Le("pi").id,server_url:"http://127.0.0.1:8080",image:"agentdock/pi-acp:local",acp_port:"8080",state_scope:"project",timeout_seconds:"7200",sandbox_lifecycle:"per_thread",idle_seconds:"900",warm_pool_size:"0",cpu:"1000m",memory:"2Gi",workspace_mount_path:"/workspace",state_mount_path:"/agent-state"};function ss(e){const r=new Set,n=String((e==null?void 0:e.model)||"").trim();n&&r.add(n);for(const i of(e==null?void 0:e.models)||[]){const o=String((i==null?void 0:i.model)||"").trim();o&&r.add(o)}return[...r]}function ws(){var K,Z;const{t:e}=we(),{name:r}=Ne(),[n,i]=c.useState("overview"),[o,d]=c.useState(null),[m,f]=c.useState([]),[_,ne]=c.useState(""),[u,ie]=c.useState(null),[O,le]=c.useState([]),[ce,de]=c.useState(""),[me,U]=c.useState(!0),[g,b]=c.useState(l),[xe,q]=c.useState(!1),[G,x]=c.useState(""),[he,L]=c.useState(!1),[v,z]=c.useState({name:"",api_key:"",base_url:"",model:""}),[pe,$]=c.useState(!1),[J,fe]=c.useState("30"),p=c.useCallback(async()=>{var a,t,N,y,S;if(r)try{U(!0);const[C,I,V,W]=await Promise.allSettled([Ie(r),Ae(),Ke(r),P()]);C.status==="fulfilled"&&d(C.value);const X=I.status==="fulfilled"?I.value.providers||[]:[];if(I.status==="fulfilled"&&f(X),V.status==="fulfilled"&&ie(V.value),W.status==="fulfilled"){const H=W.value.parsed,k=(a=H==null?void 0:H.projects)==null?void 0:a.find(D=>D.name===r),Q=Qe(H,r),R=X.find(D=>D.id===Q);ne(Q),le(ss(R)),de(String(((N=(t=k==null?void 0:k.agent)==null?void 0:t.options)==null?void 0:N.model)||(R==null?void 0:R.model)||"")),b(as((S=(y=k==null?void 0:k.agent)==null?void 0:y.options)==null?void 0:S.sandbox))}}finally{U(!1)}},[r]);c.useEffect(()=>{p();const a=()=>p();return window.addEventListener("cc:refresh",a),()=>window.removeEventListener("cc:refresh",a)},[p]);const ue=async()=>{if(!(!r||!v.name)){x("");try{const a=await Ee(v),t=await P();if(!t.parsed)throw new Error("Config file is unavailable.");await E(re(t.parsed,r,a.id)),L(!1),z({name:"",api_key:"",base_url:"",model:""}),x("Provider created."),await p()}catch(a){x(a instanceof Error?a.message:String(a))}}},ge=async a=>{if(r){x("");try{const t=await P();if(!t.parsed)throw new Error("Config file is unavailable.");await E(re(t.parsed,r,a)),x("Provider selected."),await p()}catch(t){x(t instanceof Error?t.message:String(t))}}},ve=async a=>{if(r){x("");try{const t=await P();if(!t.parsed)throw new Error("Config file is unavailable.");await E(es(t.parsed,a)),await Me(a),x("Provider removed."),await p()}catch(t){x(t instanceof Error?t.message:String(t))}}},je=async a=>{if(r){x("");try{const t=await P();if(!t.parsed)throw new Error("Config file is unavailable.");await E(Ye(t.parsed,r,a)),x("Model selected."),await p()}catch(t){x(t instanceof Error?t.message:String(t))}}},be=async()=>{r&&(await Xe(r,parseInt(J)),$(!1),p())},_e=[{key:"overview",icon:qe},{key:"providers",icon:Ce},{key:"sandbox",icon:He},{key:"heartbeat",icon:te}],ye=async()=>{var a;if(r){q(!0),x("");try{const N=(await P()).parsed||{},y=Array.isArray(N.projects)?[...N.projects]:[],S=y.findIndex(I=>I.name===r);if(S<0)throw new Error(`Project not found in config: ${r}`);const C=y[S];y[S]={...C,agent:{...C.agent,options:{...((a=C.agent)==null?void 0:a.options)||{},sandbox:ts(g)}}},await E({...N,projects:y}),x("Sandbox settings saved."),await p()}catch(t){x((t==null?void 0:t.message)||String(t))}finally{q(!1)}}};return me&&!o?s.jsx("div",{className:"flex items-center justify-center h-64 text-muted-foreground animate-pulse",children:"Loading..."}):s.jsxs("div",{className:"space-y-6 animate-fade-in",children:[s.jsx(ze,{title:r,description:"Project overview, providers, and heartbeat status. Low-frequency settings are no longer editable in the daily UI.",actions:s.jsx(Se,{to:"/projects",children:s.jsxs(h,{variant:"secondary",size:"sm",children:[s.jsx($e,{size:14})," Back"]})})}),o?s.jsxs("div",{className:"app-toolbar flex flex-wrap items-center gap-2",children:[s.jsx(A,{variant:"info",children:o.agent_type}),s.jsx(A,{variant:o.heartbeat_enabled?"success":"secondary",children:o.heartbeat_enabled?"heartbeat on":"heartbeat off"}),s.jsxs("span",{className:"text-xs text-muted-foreground",children:[o.sessions_count," sessions"]})]}):null,G?s.jsx("div",{role:"status",className:"rounded-lg border border-primary/20 bg-primary/10 px-4 py-3 text-sm text-primary",children:G}):null,s.jsx("div",{className:"flex gap-2 overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:_e.map(({key:a,icon:t})=>s.jsxs("button",{onClick:()=>i(a),className:Y("app-segment flex items-center gap-2",n===a?"app-segment-active":"app-segment-idle"),children:[s.jsx(t,{size:16}),e(`projects.tabs.${a}`)]},a))}),n==="overview"&&o&&s.jsxs("div",{className:"space-y-4",children:[s.jsx(B,{className:"app-panel",title:e("projects.platforms"),children:s.jsx("div",{className:"flex flex-wrap gap-2",children:(K=o.platforms)==null?void 0:K.map(a=>s.jsxs(A,{variant:a.connected?"success":"danger",children:[s.jsx(Re,{size:12,className:"mr-1"})," ",a.type," ",a.connected?"✓":"✗"]},a.type))})}),s.jsxs(B,{className:"app-panel",title:e("sessions.title"),children:[s.jsxs("p",{className:"text-sm text-muted-foreground",children:[o.sessions_count," ",e("nav.sessions").toLowerCase()]}),((Z=o.active_session_keys)==null?void 0:Z.length)>0&&s.jsx("div",{className:"mt-2 flex flex-wrap gap-1",children:o.active_session_keys.map(a=>s.jsx(A,{variant:"default",children:a},a))})]})]}),n==="providers"&&s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"flex justify-between items-center",children:[s.jsx("h3",{className:"text-sm font-semibold text-foreground",children:e("providers.title")}),s.jsxs(h,{size:"sm",onClick:()=>L(!0),children:[s.jsx(Be,{size:14})," ",e("providers.add")]})]}),m.length===0?s.jsx(ae,{message:e("common.noData")}):s.jsx("div",{className:"space-y-2",children:m.map(a=>s.jsx(w,{className:"app-panel",children:s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"font-medium text-foreground",children:a.name}),a.id===_&&s.jsx(A,{variant:"success",children:e("providers.active")})]}),s.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[a.model," ",a.base_url?`· ${a.base_url}`:""]})]}),s.jsxs("div",{className:"flex gap-2",children:[a.id!==_&&s.jsxs(h,{size:"sm",variant:"secondary",onClick:()=>{ge(a.id)},children:[s.jsx(Te,{size:14})," ",e("providers.activate")]}),a.id!==_&&s.jsx(h,{size:"sm",variant:"danger",onClick:()=>{ve(a.id)},children:s.jsx(Fe,{size:14})})]})]})},a.id))}),O.length>0&&s.jsxs(w,{children:[s.jsx("h3",{className:"text-sm font-semibold text-foreground mb-3",children:e("providers.models")}),s.jsx("div",{className:"flex flex-wrap gap-2",children:O.map(a=>s.jsx("button",{onClick:()=>{je(a)},className:Y("px-3 py-1.5 rounded-lg text-xs font-medium transition-all",a===ce?"bg-primary/15 text-primary border border-primary/30":"bg-secondary text-secondary-foreground hover:bg-secondary/80"),children:a},a))})]}),s.jsx(ee,{open:he,onClose:()=>L(!1),title:e("providers.add"),children:s.jsxs("div",{className:"space-y-3",children:[s.jsx(j,{label:e("providers.name"),value:v.name,onChange:a=>z({...v,name:a.target.value})}),s.jsx(j,{label:"API Key",type:"password",value:v.api_key,onChange:a=>z({...v,api_key:a.target.value})}),s.jsx(j,{label:e("providers.baseUrl"),value:v.base_url,onChange:a=>z({...v,base_url:a.target.value}),placeholder:"https://api.example.com"}),s.jsx(j,{label:e("providers.model"),value:v.model,onChange:a=>z({...v,model:a.target.value})}),s.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[s.jsx(h,{variant:"secondary",onClick:()=>L(!1),children:e("common.cancel")}),s.jsx(h,{onClick:ue,children:e("providers.add")})]})]})})]}),n==="sandbox"&&s.jsx(B,{title:"Sandbox",description:"Run this project agent inside an OpenSandbox container.",actions:s.jsxs(h,{size:"sm",onClick:()=>void ye(),loading:xe,children:[s.jsx(De,{size:14})," Save"]}),children:s.jsxs("div",{className:"space-y-4",children:[s.jsxs("label",{className:"flex items-center gap-3 text-sm font-medium text-foreground",children:[s.jsx("input",{type:"checkbox",className:"h-4 w-4 rounded border-border",checked:g.enabled,onChange:a=>b(t=>({...t,enabled:a.target.checked}))}),"Enable sandbox mode"]}),g.enabled?s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"grid grid-cols-1 gap-3 md:grid-cols-2",children:[s.jsxs(se,{label:"State scope",value:g.state_scope,onChange:a=>b(t=>({...t,state_scope:a.target.value})),children:[s.jsx("option",{value:"user",children:"User"}),s.jsx("option",{value:"project",children:"Project"}),s.jsx("option",{value:"thread",children:"Thread"}),s.jsx("option",{value:"run",children:"Run"})]}),s.jsx(j,{label:"Timeout seconds",type:"number",value:g.timeout_seconds,onChange:a=>b(t=>({...t,timeout_seconds:a.target.value}))}),s.jsxs(se,{label:"Sandbox lifecycle",value:g.sandbox_lifecycle,onChange:a=>b(t=>({...t,sandbox_lifecycle:a.target.value})),children:[s.jsx("option",{value:"per_thread",children:"Keep warm per thread"}),s.jsx("option",{value:"per_run",children:"Close after each run"})]}),s.jsx(j,{label:"Idle seconds",type:"number",value:g.idle_seconds,onChange:a=>b(t=>({...t,idle_seconds:a.target.value}))}),s.jsx(j,{label:"Warm pool",type:"number",value:g.warm_pool_size,onChange:a=>b(t=>({...t,warm_pool_size:a.target.value}))}),s.jsx(j,{label:"CPU",value:g.cpu,onChange:a=>b(t=>({...t,cpu:a.target.value}))}),s.jsx(j,{label:"Memory",value:g.memory,onChange:a=>b(t=>({...t,memory:a.target.value}))})]}),s.jsx("p",{className:"text-sm text-muted-foreground",children:"OpenSandbox URL, API key env, image, ACP port, and sandbox mount paths are resolved from the global sandbox provider and runtime image registry."})]}):s.jsx("p",{className:"text-sm text-muted-foreground",children:"Local bundled runtime execution is active for this project."})]})}),n==="heartbeat"&&s.jsxs("div",{className:"space-y-4",children:[u?s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[s.jsxs(w,{children:[s.jsx("p",{className:"text-xs text-muted-foreground",children:e("heartbeat.status")}),s.jsx("p",{className:"text-lg font-bold text-foreground mt-1",children:u.paused?e("heartbeat.paused"):e("heartbeat.running")})]}),s.jsxs(w,{children:[s.jsx("p",{className:"text-xs text-muted-foreground",children:e("heartbeat.interval")}),s.jsxs("p",{className:"text-lg font-bold text-foreground mt-1",children:[u.interval_mins,"m"]})]}),s.jsxs(w,{children:[s.jsx("p",{className:"text-xs text-muted-foreground",children:e("heartbeat.runCount")}),s.jsx("p",{className:"text-lg font-bold text-foreground mt-1",children:u.run_count})]}),s.jsxs(w,{children:[s.jsx("p",{className:"text-xs text-muted-foreground",children:e("heartbeat.errorCount")}),s.jsx("p",{className:"text-lg font-bold text-foreground mt-1",children:u.error_count})]})]}),s.jsx(w,{children:s.jsxs("div",{className:"space-y-2 text-sm",children:[s.jsxs("p",{className:"text-muted-foreground",children:[e("heartbeat.lastRun"),": ",s.jsx("span",{className:"text-foreground",children:ke(u.last_run)})]}),s.jsxs("p",{className:"text-muted-foreground",children:[e("heartbeat.skippedBusy"),": ",s.jsx("span",{className:"text-foreground",children:u.skipped_busy})]}),u.last_error&&s.jsx("p",{className:"text-destructive",children:u.last_error})]})}),s.jsxs("div",{className:"flex gap-2",children:[u.paused?s.jsxs(h,{onClick:()=>{Ve(r).then(p)},children:[s.jsx(Oe,{size:14})," ",e("heartbeat.resume")]}):s.jsxs(h,{variant:"secondary",onClick:()=>{Ze(r).then(p)},children:[s.jsx(Je,{size:14})," ",e("heartbeat.pause")]}),s.jsxs(h,{variant:"secondary",onClick:()=>{We(r).then(p)},children:[s.jsx(te,{size:14})," ",e("heartbeat.trigger")]}),s.jsxs(h,{variant:"secondary",onClick:()=>$(!0),children:[s.jsx(Pe,{size:14})," ",e("heartbeat.setInterval")]})]})]}):s.jsx(ae,{message:e("common.noData")}),s.jsx(ee,{open:pe,onClose:()=>$(!1),title:e("heartbeat.setInterval"),children:s.jsxs("div",{className:"space-y-3",children:[s.jsx(j,{label:`${e("heartbeat.interval")} (min)`,type:"number",value:J,onChange:a=>fe(a.target.value)}),s.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[s.jsx(h,{variant:"secondary",onClick:()=>$(!1),children:e("common.cancel")}),s.jsx(h,{onClick:be,children:e("common.save")})]})]})})]})]})}function as(e){return{enabled:!!(e!=null&&e.enabled),provider_id:(e==null?void 0:e.provider_id)||T,runtime_image_id:(e==null?void 0:e.runtime_image_id)||l.runtime_image_id,server_url:(e==null?void 0:e.server_url)||l.server_url,image:(e==null?void 0:e.image)||l.image,acp_port:String((e==null?void 0:e.acp_port)||l.acp_port),state_scope:(e==null?void 0:e.state_scope)||l.state_scope,timeout_seconds:String((e==null?void 0:e.timeout_seconds)||l.timeout_seconds),sandbox_lifecycle:(e==null?void 0:e.sandbox_lifecycle)||l.sandbox_lifecycle,idle_seconds:String((e==null?void 0:e.idle_seconds)||l.idle_seconds),warm_pool_size:String((e==null?void 0:e.warm_pool_size)??l.warm_pool_size),cpu:(e==null?void 0:e.cpu)||l.cpu,memory:(e==null?void 0:e.memory)||l.memory,workspace_mount_path:(e==null?void 0:e.workspace_mount_path)||l.workspace_mount_path,state_mount_path:(e==null?void 0:e.state_mount_path)||l.state_mount_path}}function ts(e){return{enabled:e.enabled,provider_id:e.provider_id.trim()||T,runtime_image_id:e.runtime_image_id.trim()||l.runtime_image_id,state_scope:e.state_scope,timeout_seconds:Number(e.timeout_seconds)||Number(l.timeout_seconds),sandbox_lifecycle:e.sandbox_lifecycle,idle_seconds:Number(e.idle_seconds)||Number(l.idle_seconds),warm_pool_size:Math.max(0,Number(e.warm_pool_size)||0),cpu:e.cpu.trim()||l.cpu,memory:e.memory.trim()||l.memory}}export{ws as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{u as x,r,j as e,F as f,L as j,C as p}from"./index-
|
|
1
|
+
import{u as x,r,j as e,F as f,L as j,C as p}from"./index-on-scaWG.js";import{B as l}from"./Badge-DXjx3T4U.js";import{E as u}from"./EmptyState-DUDyUsLL.js";import{P as h}from"./Page-B0lex3w0.js";import{l as g}from"./projects-BR_Y3Dov.js";import{S as v,A as b}from"./server-BKF47usT.js";import{H as y}from"./heart-BCqqkImr.js";function C(){const{t}=x(),[a,d]=r.useState([]),[m,i]=r.useState(!0),n=r.useCallback(async()=>{try{i(!0);const s=await g();d(s.projects||[])}finally{i(!1)}},[]);return r.useEffect(()=>{n();const s=()=>n();return window.addEventListener("cc:refresh",s),()=>window.removeEventListener("cc:refresh",s)},[n]),m&&a.length===0?e.jsx("div",{className:"flex items-center justify-center h-64 text-muted-foreground animate-pulse",children:"Loading..."}):a.length===0?e.jsx(u,{message:t("projects.noProjects"),icon:f}):e.jsxs("div",{className:"space-y-6 animate-fade-in",children:[e.jsx(h,{title:t("nav.projects"),description:"Project summaries with provider, platform, and session status."}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4",children:a.map(s=>{var o;return e.jsx(j,{to:`/projects/${s.name}`,children:e.jsxs(p,{hover:!0,className:"app-panel h-full",children:[e.jsxs("div",{className:"flex items-start justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"flex h-9 w-9 items-center justify-center rounded-full bg-primary/10 text-primary",children:e.jsx(v,{size:18})}),e.jsx("h3",{className:"font-semibold text-foreground",children:s.name})]}),e.jsx(b,{size:16,className:"text-muted-foreground/45"})]}),e.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-3",children:[e.jsx(l,{variant:"info",children:s.agent_type}),(o=s.platforms)==null?void 0:o.map(c=>e.jsx(l,{children:c},c))]}),e.jsxs("div",{className:"mt-4 flex items-center justify-between rounded-[16px] bg-black/[0.035] px-3 py-2 text-xs text-muted-foreground dark:bg-white/[0.05]",children:[e.jsxs("span",{children:[s.sessions_count," ",t("nav.sessions").toLowerCase()]}),s.heartbeat_enabled&&e.jsxs("span",{className:"flex items-center gap-1 text-primary",children:[e.jsx(y,{size:12})," ",t("heartbeat.title")]})]})]})},s.name)})})]})}export{C as default};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{c as jn,
|
|
1
|
+
import{c as jn,A as he,aP as Y,j as S,r as p,g as vt}from"./index-on-scaWG.js";import{c as ct,a as Je,r as lt,P as z,u as J,b as kt,d as yt,e as at,f as $,g as kn,h as Hn,i as Vn,R as Bn,F as Wn,D as Fn}from"./index-DvKeLUQ8.js";import{C as St}from"./chevron-down-BOhwopXd.js";import{C as $n}from"./check-BNBksd9W.js";/**
|
|
2
2
|
* @license lucide-react v0.487.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{u as C,E as z,r,j as e,L as S,B as g,g as b,T as B}from"./index-on-scaWG.js";import{B as j}from"./Badge-DXjx3T4U.js";import{g as E,a as L}from"./sessions-CtFBPvOB.js";import{C as A,A as I}from"./ChatMarkdown-CSc8mfpv.js";import{A as M}from"./arrow-left-SFlZE8SW.js";import{C as R}from"./circle-BTT_e1ZT.js";import{W as y,R as T}from"./wifi-off-YfCo8Dbk.js";import{B as U}from"./bot-DeqZUVXX.js";import{U as W}from"./user-DTURDktb.js";import"./check-BNBksd9W.js";function J(){var p;const{t:a}=C(),{project:i,id:l}=z(),[s,v]=r.useState(null),[d,m]=r.useState(""),[c,x]=r.useState(!1),[w,f]=r.useState(!0),u=r.useRef(null),o=r.useCallback(async()=>{if(!(!i||!l))try{f(!0);const t=await E(i,l,200);v(t)}finally{f(!1)}},[i,l]);r.useEffect(()=>{o()},[o]),r.useEffect(()=>{var t;(t=u.current)==null||t.scrollIntoView({behavior:"smooth"})},[s==null?void 0:s.history]);const h=async()=>{if(!d.trim()||!i||!s)return;const t=d.trim();m(""),x(!0);try{await L(i,{session_key:s.session_key,message:t}),setTimeout(o,1500)}finally{x(!1)}},N=t=>{t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),h())};return w&&!s?e.jsx("div",{className:"flex items-center justify-center h-64 text-muted-foreground animate-pulse",children:"Loading..."}):e.jsxs("div",{className:"flex flex-col h-[calc(100vh-8rem)] animate-fade-in",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-slate-200/80 pb-4 dark:border-white/[0.08]",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(S,{to:"/sessions",className:"p-2 rounded-md hover:bg-accent/10 transition-colors",children:e.jsx(M,{size:18,className:"text-muted-foreground"})}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"text-[1.4rem] font-semibold text-foreground",children:(s==null?void 0:s.name)||l}),s!=null&&s.live?e.jsxs("span",{className:"flex items-center gap-1 rounded-full bg-primary/10 px-2 py-0.5 text-[10px] text-primary",children:[e.jsx(R,{size:5,className:"fill-current"})," live"]}):e.jsxs("span",{className:"flex items-center gap-1 text-[10px] text-muted-foreground bg-muted px-1.5 py-0.5 rounded-full",children:[e.jsx(y,{size:9})," ",a("sessions.offline")]})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[e.jsx(j,{children:i}),(s==null?void 0:s.platform)&&e.jsx(j,{variant:"info",children:s.platform}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s==null?void 0:s.session_key})]})]})]}),e.jsxs(g,{size:"sm",variant:"ghost",onClick:o,children:[e.jsx(T,{size:14})," ",a("common.refresh")]})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto py-6",children:[(!(s!=null&&s.history)||s.history.length===0)&&e.jsx("p",{className:"text-center text-sm text-muted-foreground py-12",children:a("sessions.noMessages")}),e.jsx("div",{className:"mx-auto max-w-4xl space-y-5",children:(p=s==null?void 0:s.history)==null?void 0:p.map((t,k)=>{const n=t.role==="user";return e.jsxs("div",{className:b("flex gap-3",n?"justify-end":"justify-start"),children:[!n&&e.jsx("div",{className:"mt-1 flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-primary/10 dark:bg-white/[0.06]",children:e.jsx(U,{size:16,className:"text-primary"})}),e.jsx("div",{className:b("rounded-[20px] px-5 py-3.5 text-sm",n?"chat-user-glass max-w-[70%] rounded-br-sm text-slate-950 dark:text-slate-50":"max-w-[78%] rounded-bl-sm border border-slate-200 bg-[#fbfbfd] text-card-foreground dark:border-white/[0.08] dark:bg-white/[0.04]"),children:e.jsx(A,{content:t.content,isUser:n})}),n&&e.jsx("div",{className:"mt-1 flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-muted dark:bg-white/[0.08]",children:e.jsx(W,{size:16,className:"text-muted-foreground"})})]},k)})}),e.jsx("div",{ref:u})]}),e.jsx("div",{className:"border-t pt-4",children:s!=null&&s.live?e.jsx("div",{className:"mx-auto max-w-4xl",children:e.jsxs("div",{className:"relative",children:[e.jsx(B,{value:d,onChange:t=>m(t.target.value),onKeyDown:N,placeholder:a("sessions.messageInput"),rows:2,className:"min-h-[88px] rounded-[22px] border-gray-200 bg-[#fbfbfd] px-4 pb-14 pt-3 text-[15px] leading-6 dark:border-white/[0.08] dark:bg-[rgba(255,255,255,0.04)] sm:min-h-[96px] sm:px-5 sm:pt-4",disabled:c}),e.jsx(g,{onClick:h,disabled:c||!d.trim(),size:"icon","aria-label":a("sessions.messageInput"),className:"absolute bottom-3 right-3 h-10 w-10 rounded-full bg-primary px-0 text-white shadow-none hover:bg-[#0071e3] disabled:bg-slate-300 disabled:text-white disabled:opacity-100 dark:bg-primary dark:text-white dark:hover:bg-[#2997ff] dark:disabled:bg-white/20 dark:disabled:text-white/55 sm:h-11 sm:w-11",children:c?e.jsxs("svg",{className:"animate-spin h-4 w-4",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4",fill:"none"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}):e.jsx(I,{size:20,strokeWidth:2.2})})]})}):e.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 text-sm text-muted-foreground bg-muted rounded-lg",children:[e.jsx(y,{size:14}),e.jsx("span",{children:a("sessions.notLiveHint")})]})})]})}export{J as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{u as v,r as n,j as s,M as x,L as N,C as w}from"./index-
|
|
1
|
+
import{u as v,r as n,j as s,M as x,L as N,C as w}from"./index-on-scaWG.js";import{B as f}from"./Badge-DXjx3T4U.js";import{S as y}from"./Select-CybeCWXZ.js";import{E as _}from"./EmptyState-DUDyUsLL.js";import{P as S}from"./Page-B0lex3w0.js";import{l as C}from"./projects-BR_Y3Dov.js";import{l as k}from"./sessions-CtFBPvOB.js";import{F as L}from"./funnel-Btin4gwi.js";import{C as M}from"./circle-BTT_e1ZT.js";import{U as P}from"./user-DTURDktb.js";import{B as b}from"./bot-DeqZUVXX.js";import"./index-DvKeLUQ8.js";import"./chevron-down-BOhwopXd.js";import"./check-BNBksd9W.js";function E(t,o){if(!t)return"";const m=Date.now()-new Date(t).getTime(),i=Math.floor(m/6e4);if(i<1)return o("sessions.justNow");if(i<60)return`${i}m`;const c=Math.floor(i/60);return c<24?`${c}h`:`${Math.floor(c/24)}d`}function K(){const{t}=v(),[o,m]=n.useState([]),[i,c]=n.useState([]),[l,j]=n.useState(""),[h,u]=n.useState(!0),d=n.useCallback(async()=>{u(!0);try{const{projects:e}=await C();c(e||[]);const a=await Promise.all((e||[]).map(async r=>{try{const{sessions:g}=await k(r.name);return{project:r.name,sessions:g||[]}}catch{return{project:r.name,sessions:[]}}}));m(a)}finally{u(!1)}},[]);n.useEffect(()=>{d();const e=()=>d();return window.addEventListener("cc:refresh",e),()=>window.removeEventListener("cc:refresh",e)},[d]);const p=n.useMemo(()=>(l?o.filter(a=>a.project===l):o).flatMap(a=>a.sessions.map(r=>({...r,_project:a.project}))).sort((a,r)=>(r.updated_at||r.created_at||"").localeCompare(a.updated_at||a.created_at||"")),[o,l]);return h&&o.length===0?s.jsx("div",{className:"flex items-center justify-center h-64 text-muted-foreground animate-pulse",children:"Loading..."}):s.jsxs("div",{className:"space-y-4 animate-fade-in",children:[s.jsx(S,{title:t("sessions.title"),description:"Browse recent conversations across projects."}),s.jsxs("div",{className:"app-toolbar flex items-center gap-3",children:[s.jsx(L,{size:16,className:"text-muted-foreground"}),s.jsxs(y,{value:l,onChange:e=>j(e.target.value),className:"w-auto min-w-48",children:[s.jsx("option",{value:"",children:t("sessions.allProjects")}),i.map(e=>s.jsx("option",{value:e.name,children:e.name},e.name))]}),s.jsxs("span",{className:"text-xs text-muted-foreground",children:[p.length," ",t("nav.sessions").toLowerCase()]})]}),p.length===0?s.jsx(_,{message:t("sessions.noSessions"),icon:x}):s.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4 gap-3",children:p.map(e=>s.jsx(N,{to:`/sessions/${encodeURIComponent(e._project)}/${encodeURIComponent(e.id)}`,children:s.jsxs(w,{hover:!0,className:"group app-panel relative h-full p-4",children:[s.jsxs("div",{className:"flex items-start justify-between gap-2 mb-2",children:[s.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[s.jsx(x,{size:14,className:e.live?"text-primary shrink-0":"text-muted-foreground shrink-0"}),s.jsx("span",{className:"text-sm font-medium text-foreground truncate",children:e.name||e.user_name||e.id.slice(0,8)}),e.live&&s.jsx(M,{size:5,className:"fill-primary text-primary shrink-0"})]}),s.jsx("span",{className:"text-[10px] text-muted-foreground shrink-0 mt-0.5",children:E(e.updated_at||e.created_at,t)})]}),s.jsx("div",{className:"mb-2.5 min-h-[2.5rem]",children:e.last_message?s.jsxs("p",{className:"text-xs text-muted-foreground line-clamp-2 leading-relaxed",children:[e.last_message.role==="user"?s.jsx(P,{size:10,className:"inline mr-1 -mt-0.5 opacity-60"}):s.jsx(b,{size:10,className:"inline mr-1 -mt-0.5 opacity-60"}),e.last_message.content.replace(/\n/g," ").slice(0,100)]}):s.jsx("p",{className:"text-xs text-muted-foreground italic",children:t("sessions.noMessages")})}),s.jsxs("div",{className:"mt-3 flex items-center gap-1.5 flex-wrap rounded-[16px] bg-black/[0.035] px-3 py-2 dark:bg-white/[0.05]",children:[s.jsx(f,{children:e._project}),e.platform&&s.jsx(f,{variant:"info",children:e.platform}),s.jsxs("span",{className:"text-[10px] text-muted-foreground ml-auto",children:[e.history_count," msgs"]})]})]})},`${e._project}-${e.id}`))})]})}export{K as default};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import{c as fe,j as t,g as Y,B as X,r as o,W as vt,h as Oe,I as _e,T as Nt,i as Ve,k as Ct,m as St,l as Mt,s as Kt,n as Je,o as Ae,p as ze,q as Xe,t as Lt,v as _t,w as At,x as zt,y as It,z as Pt}from"./index-on-scaWG.js";import{n as Tt,i as $t,a as Ee,b as Dt,s as Bt,w as Me}from"./desktop-JQkhNOF4.js";import{C as Ut,A as Ot}from"./ChatMarkdown-CSc8mfpv.js";import{C as Ye}from"./check-BNBksd9W.js";import{C as ve}from"./circle-BTT_e1ZT.js";import{B as Et}from"./bot-DeqZUVXX.js";import{U as Rt}from"./user-DTURDktb.js";import{C as Ft}from"./chevron-down-BOhwopXd.js";import{S as Ht}from"./shield-check-Q1O3wIT4.js";import{s as Wt,g as Vt,o as Jt,b as Xt,u as Yt}from"./desktop-D88Gquih.js";import{t as Gt,L as Ke}from"./session-utils-B4vjXX1q.js";import{R as Qt,W as Zt}from"./wifi-off-YfCo8Dbk.js";import{X as Ge,M as Re}from"./Modal-BYTZpyD2.js";import{S as qt}from"./search-BOU1rpMw.js";import{P as er}from"./pencil-BHu_seP7.js";import{T as tr}from"./trash-2-CANqI4Db.js";import"./index-DvKeLUQ8.js";/**
|
|
2
|
+
* @license lucide-react v0.487.0 - ISC
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the ISC license.
|
|
5
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/const rr=[["ellipse",{cx:"12",cy:"5",rx:"9",ry:"3",key:"msslwz"}],["path",{d:"M3 5V19A9 3 0 0 0 21 19V5",key:"1wlel7"}],["path",{d:"M3 12A9 3 0 0 0 21 12",key:"mv7ke4"}]],ar=fe("database",rr);/**
|
|
7
|
+
* @license lucide-react v0.487.0 - ISC
|
|
8
|
+
*
|
|
9
|
+
* This source code is licensed under the ISC license.
|
|
10
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
+
*/const sr=[["path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z",key:"1lielz"}],["path",{d:"M12 7v6",key:"lw1j43"}],["path",{d:"M9 10h6",key:"9gxzsh"}]],Qe=fe("message-square-plus",sr);/**
|
|
12
|
+
* @license lucide-react v0.487.0 - ISC
|
|
13
|
+
*
|
|
14
|
+
* This source code is licensed under the ISC license.
|
|
15
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
+
*/const nr=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}]],ir=fe("panel-left",nr);/**
|
|
17
|
+
* @license lucide-react v0.487.0 - ISC
|
|
18
|
+
*
|
|
19
|
+
* This source code is licensed under the ISC license.
|
|
20
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
21
|
+
*/const or=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}]],lr=fe("shield",or);/**
|
|
22
|
+
* @license lucide-react v0.487.0 - ISC
|
|
23
|
+
*
|
|
24
|
+
* This source code is licensed under the ISC license.
|
|
25
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
26
|
+
*/const dr=[["polyline",{points:"4 17 10 11 4 5",key:"akl6gq"}],["line",{x1:"12",x2:"20",y1:"19",y2:"19",key:"q2wloq"}]],cr=fe("terminal",dr),ur=9e4;function he(e){return e==="thought"||e==="plan"||e==="tool"||e==="status"||e==="permission"}function Le(e){return e==="awaiting_input"}function je(e,r,s){if(r)return e.find(n=>n.id===r);if(s)return e.find(n=>n.preview&&n.turnKey===s)}function mr(e,r,s,n){return!e.preview||e.role!=="assistant"||!s||e.turnKey!==s||he(n)||he(e.bridgeKind)?!1:!!(r&&(e.content===r||!e.bridgeKind||e.bridgeKind==="assistant"))}function pr(e){const r=String(e.event.replyCtx||"").trim();if(!r)return!0;const s=String(e.activeRunId||"").trim(),n=e.pendingTurn;if(n&&n.sessionKey===e.event.sessionKey){const i=String(n.runId||"").trim();if(i)return r===i;const l=String(n.supersededRunId||"").trim();if(l&&r===l)return!1}return!s||r===s}function xr(e,r){let s=!1;const n=e.map(i=>!i.preview||r&&i.turnKey!==r?i:(s=!0,{...i,preview:!1,previewPlainText:!1}));return s?n:e}function hr(e,r){if(!r)return e;const s=e.filter(l=>l.turnKey===r&&!l.preview);if(s.length===0)return e;const n=[...s].reverse().find(l=>!he(l.bridgeKind)),i=n==null?void 0:n.id;return e.map(l=>l.turnKey!==r||l.preview?l:{...l,kind:i&&l.id===i?"final":"progress"})}function Ze(e){if(!e)return"";const r=e.match(/\[User Message\]\s*([\s\S]*?)\s*\[\/User Message\]/);return r?r[1]||"":e}function fr(e){return e.map((r,s)=>({id:r.id||`${s}-${r.timestamp||r.role}`,role:r.role==="user"?"user":r.role==="system"?"system":"assistant",content:r.role==="user"?Ze(r.content):r.content,toolCall:r.toolCall,bridgeKind:r.bridgeKind,bridgeStatus:r.bridgeStatus,kind:r.kind==="progress"||r.kind==="system"?"progress":"final",order:s,timestamp:r.timestamp}))}function qe(e){return{id:e.id,project:e.workspaceId,name:e.title,live:e.live,createdAt:e.createdAt,updatedAt:e.updatedAt,excerpt:Ze(e.excerpt),agentType:e.agentType,agentMode:e.agentMode,bridgeSessionKey:e.bridgeSessionKey}}function et(e){return[...e].sort((r,s)=>r.live!==s.live?r.live?-1:1:(s.updatedAt||s.createdAt||"").localeCompare(r.updatedAt||r.createdAt||""))}function br(e,r){return r?[e.name,e.excerpt,e.bridgeSessionKey||""].join(" ").toLowerCase().includes(r):!0}function Fe(e){return[...e].sort((r,s)=>{if(r.order!==s.order)return r.order-s.order;const n=r.timestamp?new Date(r.timestamp).getTime():Number.NaN,i=s.timestamp?new Date(s.timestamp).getTime():Number.NaN,l=Number.isFinite(n),c=Number.isFinite(i);return l&&c&&n!==i?n-i:r.id.localeCompare(s.id)})}function He(e){if(!e)return"";const r=new Date(e);return Number.isNaN(r.getTime())?"":new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit",second:"2-digit"}).format(r)}function gr(e){switch(e){case"starting":return"启动中";case"api_ready":return"服务就绪";case"error":return"运行异常";default:return"未启动"}}function wr(e){if(!(e!=null&&e.startsWith("desktop:")))return"";const[,r=""]=e.split(":");return r}function kr(e){return Array.isArray(e)?e.map(r=>Array.isArray(r)?r.map(s=>Tt(s)).filter(s=>!!s):[]).filter(r=>r.length>0):[]}function tt(e,r,s){const n=e.filter(i=>i.project!==r);return n.push({project:r,sessions:s}),n.sort((i,l)=>i.project.localeCompare(l.project))}function yr(e,r,s){var l;const n=((l=e.find(c=>c.project===r))==null?void 0:l.sessions)||[],i=et([s,...n.filter(c=>c.id!==s.id)]);return tt(e,r,i)}function jr(e){return e.some(r=>r.some(s=>$t(s)))}function vr(e,r){return e==="stopping"?"Stopping current task…":e==="error"?"":e==="awaiting_input"?"Agent is waiting for your reply.":e==="permission_submitted"?"Permission sent. Waiting for the agent to continue…":e==="awaiting_permission"?"Waiting for your permission response.":r?"Agent is typing…":e==="running"?"Task is running…":""}function Nr(e){return e==="running"||e==="awaiting_permission"||e==="permission_submitted"||e==="stopping"}function Cr(e){return e!=="idle"&&e!=="awaiting_input"&&e!=="error"}function Sr(e){return e!=="awaiting_input"&&e!=="awaiting_permission"&&e!=="permission_submitted"&&e!=="stopping"}const Mr="Permission sent. Waiting for the agent to continue…";function Kr(e){return!(e.actionMode==="permission"&&e.actionInteractive)}function Lr(e,r){return(r==null?void 0:r.id)===e.id?!0:e.role!=="user"&&e.actionMode==="permission"&&!!e.actionInteractive}function _r(e){var s;if(!e.id||e.role!=="assistant"||e.actionMode!=="permission"||!e.content)return null;const r=((s=e.actions)==null?void 0:s.filter(n=>n.length>0))||[];return r.length===0?null:{id:e.id,content:e.content,actions:r,actionReplyCtx:e.actionReplyCtx,actionPending:e.actionPending,actionStatus:e.actionStatus,actionMode:"permission",actionInteractive:!0}}function Ar(e){return{...e,actions:[],actionPending:!1,actionStatus:Mr}}function zr(e,r){return e.role==="system"?!1:Lr({id:e.id,role:e.role,actionMode:e.actionMode,actionInteractive:e.actionInteractive},r)}function Ir(e){var s;if(!e)return null;const r=e.status.trim()||"running";return{title:e.name.trim()||"Tool call",status:r,output:e.output||"",label:e.label||(/^running$/i.test(r)?"工具调用":"工具结果"),subtitle:((s=e.detail)==null?void 0:s.trim())||Pr(e.input)}}function Pr(e){if(!e||typeof e!="object")return typeof e=="string"&&e.trim()?e.trim():void 0;const r=e;for(const n of["command","cmd","path","file","query"]){const i=r[n];if(typeof i=="string"&&i.trim())return i.trim()}const s=Object.entries(r).filter(([,n])=>n!=null&&n!=="").slice(0,2).map(([n,i])=>`${n}: ${typeof i=="string"?i:JSON.stringify(i)}`);return s.length>0?s.join(", "):void 0}function Tr(e){var r;return e.bridgeKind==="tool"&&((r=e.toolCall)==null?void 0:r.status.trim().toLowerCase())==="running"&&!e.toolCall.output.trim()}function $r(e){return e.label==="工具结果"&&!!e.output.trim()}function Dr(e){const r=e.split(`
|
|
27
|
+
`).map(c=>c.trim()).filter(Boolean),s=r.findIndex(c=>c.includes("若按钮没有显示")),n=s>=0?r.slice(0,s):r,i=n[0]||"等待工具确认",l=n.slice(1).filter(c=>!c.includes("请选择一个选项继续执行"));return{title:i,bodyLines:l}}function rt(e,r){return e.map(s=>{const n=r.find(i=>i.id===s);return{id:s,name:(n==null?void 0:n.name)||s,fileCount:(n==null?void 0:n.fileCount)||0}})}function Br(e,r){const s=r.trim().toLowerCase();return s?e.filter(n=>[n.name,n.description,n.id].join(" ").toLowerCase().includes(s)):e}function Ur(e,r){const s=new Set(r);return[...e].sort((n,i)=>{const l=s.has(n.id),c=s.has(i.id);return l!==c?l?-1:1:n.name.localeCompare(i.name,"zh-CN")})}function Or(e,r){return r?e.filter(s=>s.project===r):e}function Er(e,r){return r&&!e.includes(r)?[r,...e]:e}function Rr(e){return e.some(r=>r.sessions.length>0)}function Fr(e){return e?{id:e.id,content:e.content,actions:e.actions,actionReplyCtx:e.actionReplyCtx,actionPending:e.actionPending,actionStatus:e.actionStatus,actionMode:"permission",actionInteractive:!0}:null}function Hr(e,r){return e.kind==="progress"&&Tr(e)?!1:!zr(e,r)}function Wr(e){return e.serviceRunning?e.transportReady?e.taskState==="awaiting_input"?"Agent 正在等待你的回复,可直接继续输入。":e.taskInputLocked?"任务正在运行,点击停止可中断当前执行。":e.sendPlaceholder:e.waitingRuntimePlaceholder:e.startFirstPlaceholder}function Vr(e){return!!(e.draft.trim()&&e.serviceRunning&&e.transportReady&&!e.sending&&e.selectedProject)}function Jr({card:e}){const r=e.status.toLowerCase()==="completed",[s,n]=o.useState(()=>!$r(e)),i=!!e.output.trim();return t.jsxs("div",{className:"overflow-hidden rounded-[18px] border border-slate-200 bg-[#f5f5f7] dark:border-white/[0.08] dark:bg-[#111214]",children:[t.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-slate-200/80 px-4 py-3 dark:border-white/[0.06]",children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[t.jsx("span",{className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-full bg-primary/10 text-primary dark:text-primary",children:t.jsx(vt,{size:14})}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"truncate text-sm font-semibold text-slate-800 dark:text-slate-100",children:e.title}),t.jsxs("p",{className:"mt-0.5 flex items-center gap-1.5 text-[11px] text-slate-500 dark:text-slate-400",children:[t.jsx(cr,{size:12}),t.jsx("span",{className:"truncate",children:e.subtitle||e.label})]})]})]}),t.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[t.jsx("span",{className:Y("rounded-full px-2.5 py-1 text-[10px] font-medium uppercase tracking-[0.12em]",r?"bg-primary/10 text-primary dark:text-primary":"bg-amber-500/10 text-amber-700 dark:text-amber-300"),children:e.status}),i?t.jsx("button",{type:"button","aria-expanded":s,"aria-label":s?"折叠工具结果":"展开工具结果","data-testid":"desktop-tool-result-toggle",onClick:()=>n(l=>!l),className:"flex h-7 w-7 items-center justify-center rounded-full border border-slate-200 bg-white text-slate-500 transition hover:border-slate-300 hover:text-slate-700 dark:border-white/[0.08] dark:bg-white/[0.05] dark:text-slate-300 dark:hover:bg-white/[0.08]",children:s?t.jsx(Ft,{size:14}):t.jsx(Oe,{size:14})}):null]})]}),s?t.jsx("pre",{className:"max-h-72 overflow-auto whitespace-pre-wrap break-words px-4 py-3 font-mono text-[12px] leading-5 text-slate-700 [scrollbar-gutter:stable] dark:text-slate-200",children:e.output||"无输出"}):t.jsxs("button",{type:"button",onClick:()=>n(!0),className:"flex w-full items-center gap-2 px-4 py-3 text-left text-xs text-slate-500 transition hover:bg-slate-100/70 dark:text-slate-400 dark:hover:bg-white/[0.04]",children:[t.jsx(Oe,{size:14}),t.jsx("span",{className:"truncate",children:"工具结果已折叠"})]})]})}function Xr({card:e,className:r,testId:s="desktop-chat-permission-card",loading:n,onAction:i}){const l=Dr(e.content);return t.jsxs("div",{"data-testid":s,className:Y("overflow-hidden rounded-[18px] border border-amber-200 bg-[#fff8eb] dark:border-amber-400/20 dark:bg-amber-500/10",r),children:[t.jsx("div",{className:"flex items-center justify-between gap-3 border-b border-amber-200/80 px-4 py-3 dark:border-amber-400/15",children:t.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[t.jsx("span",{className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-full bg-amber-100 text-amber-700 dark:bg-amber-400/15 dark:text-amber-200",children:t.jsx(Ht,{size:14})}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"truncate text-sm font-semibold text-amber-950 dark:text-amber-50",children:l.title}),t.jsx("p",{className:"mt-0.5 text-[11px] text-amber-700/80 dark:text-amber-100/70",children:"权限响应"})]})]})}),l.bodyLines.length>0?t.jsx("div",{className:"space-y-2 px-4 py-3 text-sm leading-6 text-amber-950 dark:text-amber-50",children:l.bodyLines.map((c,f)=>t.jsx("p",{className:"break-words",children:c},`${e.id}-permission-line-${f}`))}):null,e.actionStatus?t.jsx("p",{className:"border-t border-amber-200/80 px-4 py-3 text-xs text-amber-700 dark:border-amber-400/15 dark:text-amber-100",children:e.actionStatus}):null,e.actions.length>0?t.jsx("div",{className:"flex flex-wrap gap-2 border-t border-amber-200/80 px-4 py-3 dark:border-amber-400/15",children:e.actions.flat().map(c=>t.jsx(X,{size:"sm",variant:"secondary",onClick:()=>i(c),disabled:!!(e.actionPending||n),loading:n,className:"rounded-full border border-amber-300 bg-white text-amber-900 hover:bg-amber-100 dark:border-amber-400/30 dark:bg-white/[0.08] dark:text-amber-50 dark:hover:bg-white/[0.12]",children:c.text||c.data},`${e.id}-${c.data||c.text}`))}):null]})}function Yr({message:e,pendingBridgeActionId:r,onAction:s}){const n=e.role==="user",i=e.role==="system",l=!n&&!i&&e.kind==="progress",c=n?null:Ir(e.toolCall),f=!!c;return t.jsxs("div",{className:Y("flex gap-3 sm:gap-4",n?"justify-end":"justify-start"),children:[n?null:t.jsx("div",{className:Y("mt-1 flex shrink-0 items-center justify-center rounded-full text-slate-400 dark:text-slate-500",i?"h-7 w-7 bg-amber-100 text-amber-600 dark:bg-amber-500/12 dark:text-amber-300":l?"h-6 w-6 bg-[#f0f0f0] dark:bg-white/[0.04]":"h-8 w-8 bg-[#f5f5f7] dark:bg-white/[0.06]"),children:i?t.jsx(Ye,{size:14}):l?t.jsx(ve,{size:7,className:"fill-current"}):t.jsx(Et,{size:14})}),t.jsx("div",{"data-testid":"desktop-chat-message","data-role":e.role,"data-kind":e.kind||"final","data-order":String(e.order),"data-timestamp":e.timestamp||"",className:Y("transition-all",n?"max-w-[calc(100%-2.25rem)] sm:max-w-[70%]":f?"max-w-[calc(100%-2.25rem)] sm:max-w-[80%]":l?"max-w-[calc(100%-2.25rem)] sm:max-w-[72%]":"max-w-[calc(100%-2.25rem)] sm:max-w-[78%]"),children:t.jsxs("div",{className:Y("rounded-[20px] px-4 py-3 text-sm",n?"chat-user-glass rounded-br-sm text-slate-950 dark:text-slate-50":i?"rounded-bl-sm border border-amber-200/80 bg-[#fff8eb] text-amber-900 dark:border-amber-400/20 dark:bg-amber-500/10 dark:text-amber-100":l?"rounded-bl-lg bg-[#f5f5f7] text-[13px] leading-6 text-slate-500 dark:bg-white/[0.04] dark:text-slate-400":"rounded-bl-sm border border-slate-200 bg-[#fbfbfd] text-slate-800 dark:border-white/[0.06] dark:bg-white/[0.04] dark:text-slate-100",f&&"bg-transparent p-0 shadow-none dark:bg-transparent"),children:[t.jsxs("div",{className:Y("mb-2 flex items-center gap-2 text-[10px]",n?"justify-end text-slate-500 dark:text-white/55":"text-slate-400 dark:text-slate-500"),children:[i?t.jsx("span",{className:"tracking-[0.14em] text-amber-600 dark:text-amber-300",children:"系统"}):null,l?t.jsx("span",{className:"tracking-[0.14em] text-amber-500 dark:text-amber-300",children:f?"工具":"过程"}):null,He(e.timestamp)?t.jsx("span",{"data-testid":"desktop-chat-message-timestamp",children:He(e.timestamp)}):null]}),!n&&e.preview&&e.previewPlainText?t.jsx("div",{className:"whitespace-pre-wrap break-words text-[13px] leading-6 text-inherit",children:e.content}):c?t.jsx(Jr,{card:c}):t.jsx(Ut,{content:e.content,isUser:n}),!n&&e.actions&&e.actions.length>0?t.jsx("div",{className:"mt-4 space-y-2",children:e.actions.map((m,j)=>t.jsx("div",{className:"flex flex-wrap gap-2",children:m.map(k=>t.jsx(X,{size:"sm",variant:String(k.data||"").includes("deny")?"danger":"secondary",onClick:()=>s(e,k),disabled:!!(e.actionPending||r),loading:r===e.id,"data-testid":"desktop-chat-action-button",className:"rounded-full",children:k.text||k.data},`${e.id}-${k.data||k.text}`))},`${e.id}-actions-${j}`))}):null,!n&&e.actionStatus?t.jsx("p",{className:Y("mt-3 text-xs",e.actionInteractive?"text-slate-500 dark:text-slate-400":"text-amber-700 dark:text-amber-200"),"data-testid":"desktop-chat-action-status",children:e.actionStatus}):null,e.preview?t.jsx("p",{className:"mt-2 text-[10px] uppercase tracking-[0.18em] text-primary dark:text-primary",children:"实时预览"}):null]})}),n?t.jsx("div",{className:"mt-1 flex h-7 w-7 shrink-0 items-center justify-center rounded-full bg-[#f0f0f0] dark:bg-white/[0.08] sm:h-8 sm:w-8",children:t.jsx(Rt,{size:14,className:"text-slate-500 dark:text-slate-300"})}):null]})}function Gr({activeSessionId:e,branding:r,filteredSessionGroups:s,hasVisibleSessions:n,isRuntimeStarting:i,mobileSessionsOpen:l,projects:c,runtime:f,selectedProject:m,serviceRunning:j,sessionSearch:k,showSessionKey:S,visibleProjects:v,onCreateNew:h,onLoadActiveSession:A,onOpenRenameModal:y,onRefreshRuntime:M,setDeleteTarget:F,setMobileSessionsOpen:K,setSelectedProject:L,setSessionSearch:$}){return t.jsxs("aside",{className:Y("min-h-0 flex-col border-r border-slate-200/80 bg-[#fbfbfd] dark:border-white/[0.06] dark:bg-[#111214]",l?"flex":"hidden md:flex","absolute inset-0 z-30 md:static md:z-auto"),children:[t.jsxs("div",{className:"border-b border-slate-200/80 px-4 py-4 dark:border-white/[0.06]",children:[t.jsxs("div",{className:"flex items-start justify-between gap-3",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"text-[11px] font-medium tracking-[0.18em] text-slate-400 dark:text-slate-500",children:"会话导航"}),t.jsx("h2",{className:"mt-2 text-[1.65rem] font-semibold leading-tight text-slate-900 dark:text-white",children:r.chatHeading})]}),t.jsx(X,{size:"sm",variant:"ghost",onClick:()=>void M(),className:"rounded-full border border-slate-200 bg-white text-slate-500 hover:bg-slate-100 dark:border-white/[0.08] dark:bg-white/[0.04] dark:text-slate-300 dark:hover:bg-white/[0.08]",children:t.jsx(Qt,{size:14})}),t.jsx(X,{size:"sm",variant:"ghost",onClick:()=>K(!1),className:"rounded-full border border-slate-200 bg-white text-slate-500 hover:bg-slate-100 dark:border-white/[0.08] dark:bg-white/[0.04] dark:text-slate-300 dark:hover:bg-white/[0.08] md:hidden",children:t.jsx(Ge,{size:14})})]}),t.jsxs("div",{className:"mt-4 space-y-3",children:[t.jsxs("div",{className:"space-y-2",children:[t.jsx("label",{className:"block text-[11px] font-medium tracking-[0.18em] text-slate-400 dark:text-slate-500",children:r.scopeLabel}),t.jsxs("select",{value:m,onChange:C=>L(C.target.value),"data-testid":"desktop-chat-project-select","aria-label":r.scopeLabel,className:"w-full rounded-[18px] border border-slate-200 bg-white px-3 py-2.5 text-sm text-slate-900 outline-none transition focus:border-primary/40 focus:ring-2 focus:ring-primary/10 dark:border-white/[0.08] dark:bg-[#0b1016] dark:text-white",children:[t.jsx("option",{value:"",children:r.scopeSelectPlaceholder}),v.map(C=>t.jsx("option",{value:C,children:C},C))]})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs(X,{size:"md",variant:"secondary",onClick:()=>void h(),"data-testid":"desktop-chat-new-chat",className:"h-11 flex-1 rounded-full border border-slate-200 bg-white text-slate-700 hover:bg-slate-100 dark:border-white/[0.08] dark:bg-white/[0.05] dark:text-slate-100 dark:hover:bg-white/[0.09]",children:[t.jsx(Qe,{size:15}),r.newThreadLabel]}),!j||i?t.jsx(X,{size:"md",onClick:()=>void Wt().then(M),disabled:i||j,"data-testid":"desktop-chat-start-service",className:"h-11 shrink-0 rounded-2xl px-3.5",children:i?r.startingRuntimeLabel:r.startRuntimeLabel}):null]}),t.jsxs("div",{className:"relative",children:[t.jsx(qt,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-400 dark:text-slate-500"}),t.jsx(_e,{value:k,onChange:C=>$(C.target.value),placeholder:r.searchPlaceholder,"aria-label":r.searchPlaceholder,"data-testid":"desktop-chat-session-search",className:"h-11 rounded-[18px] border-slate-200 bg-white pl-9 text-slate-900 placeholder:text-slate-400 dark:border-white/[0.08] dark:bg-[#0b1016] dark:text-white dark:placeholder:text-slate-500"})]}),t.jsx("div",{className:"flex items-center justify-between gap-3 rounded-[18px] border border-slate-200/80 bg-white px-3 py-2 dark:border-white/[0.06] dark:bg-white/[0.03]",children:t.jsxs("span",{className:"inline-flex items-center gap-2 text-xs font-medium text-slate-600 dark:text-slate-300",children:[t.jsx(ve,{size:7,className:Y("fill-current",j?"text-primary":"text-slate-300 dark:text-slate-500")}),j?"服务在线":i?"服务启动中":"服务未启动"]})})]}),f!=null&&f.service.lastError?t.jsx("div",{className:"mt-3 rounded-2xl border border-red-500/20 bg-red-50 px-3 py-2 text-xs text-red-600 dark:bg-red-500/10 dark:text-red-200",children:f.service.lastError}):null,f!=null&&f.pendingRestart?t.jsx("div",{className:"mt-3 rounded-2xl border border-amber-500/20 bg-amber-50 px-3 py-2 text-xs text-amber-700 dark:bg-amber-500/10 dark:text-amber-200",children:r.pendingRestartLabel}):null]}),t.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-3 pb-24 pt-3 [scrollbar-gutter:stable] md:pb-3",children:!m&&!n?t.jsxs("div",{className:"rounded-2xl border border-dashed border-slate-200/80 bg-white/70 px-4 py-6 text-center dark:border-white/[0.07] dark:bg-white/[0.02]",children:[t.jsx("p",{className:"text-sm font-medium text-slate-700 dark:text-slate-200",children:"先选择一个项目"}),t.jsx("p",{className:"mt-2 text-xs leading-5 text-slate-500 dark:text-slate-400",children:"选择项目后展示对应会话列表。"})]}):n?t.jsx("div",{className:"space-y-4",children:s.map(C=>t.jsxs("section",{className:"space-y-2",children:[!m&&C.sessions.length>0?t.jsxs("div",{"data-testid":"desktop-chat-session-group","data-project":C.project,className:"flex items-center justify-between px-2 pt-1",children:[t.jsx("p",{className:"text-[11px] font-medium tracking-[0.08em] text-slate-400 dark:text-slate-500",children:C.project}),t.jsxs("p",{className:"text-[10px] text-slate-400 dark:text-slate-500",children:[C.sessions.length," ",r.collectionLabel]})]}):null,C.sessions.map(a=>t.jsx("div",{"data-testid":"desktop-chat-session-row","data-session-id":a.id,"data-project":C.project,role:"button",tabIndex:0,onClick:()=>{A(C.project,a.id),K(!1)},onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),A(C.project,a.id),K(!1))},className:Y("group relative overflow-hidden rounded-[18px] border px-4 py-3 text-left transition-all duration-200 focus:outline-none focus:ring-2 focus:ring-primary/15",a.id===e?"border-primary/20 bg-primary/5 shadow-[inset_2px_0_0_0_rgba(0,102,204,0.92)] dark:border-primary/25 dark:bg-primary/10":"border-transparent bg-white hover:border-slate-200 hover:bg-[#fcfcfd] dark:bg-white/[0.03] dark:hover:border-white/[0.08] dark:hover:bg-white/[0.05]"),children:t.jsxs("div",{className:"flex items-start justify-between gap-3",children:[t.jsxs("div",{"data-testid":"desktop-chat-session-open","data-session-id":a.id,"data-project":C.project,className:"min-w-0 flex-1",children:[t.jsx("div",{className:"flex items-center gap-2",children:t.jsx("span",{className:"truncate text-sm font-medium text-slate-900 dark:text-white",children:a.name})}),t.jsx("p",{className:"mt-1 text-[11px] text-slate-400 dark:text-slate-500",children:Gt(a.updatedAt||a.createdAt)}),a.excerpt?t.jsx("p",{className:"mt-2 line-clamp-2 text-[11px] leading-5 text-slate-500 dark:text-slate-400",children:a.excerpt.replace(/\n/g," ")}):null,S&&a.bridgeSessionKey?t.jsx("p",{className:"mt-2 truncate text-[11px] text-slate-400 dark:text-slate-500",children:a.bridgeSessionKey}):null]}),t.jsxs("div",{className:"flex items-center gap-1 opacity-0 transition-opacity duration-200 group-hover:opacity-100 focus-within:opacity-100",children:[t.jsx(X,{size:"sm",variant:"ghost",onClick:b=>{b.stopPropagation(),y(C.project,a)},"data-testid":"desktop-chat-session-rename","data-session-id":a.id,"data-project":C.project,className:"text-slate-400 hover:bg-slate-100 hover:text-slate-900 dark:hover:bg-white/[0.08] dark:hover:text-white",children:t.jsx(er,{size:14})}),t.jsx(X,{size:"sm",variant:"ghost",className:"text-red-400 hover:bg-red-50 hover:text-red-600 dark:hover:bg-red-500/10 dark:hover:text-red-200","data-testid":"desktop-chat-session-delete","data-session-id":a.id,"data-project":C.project,onClick:b=>{b.stopPropagation(),F({project:C.project,id:a.id,name:a.name})},children:t.jsx(tr,{size:14})})]})]})},a.id))]},C.project))}):t.jsxs("div",{className:"rounded-2xl border border-dashed border-slate-200/80 bg-white/70 px-4 py-6 text-center dark:border-white/[0.07] dark:bg-white/[0.02]",children:[t.jsx("p",{className:"text-sm font-medium text-slate-700 dark:text-slate-200",children:k.trim()?"没有匹配的会话":"当前还没有桌面会话"}),t.jsx("p",{className:"mt-2 text-xs leading-5 text-slate-500 dark:text-slate-400",children:k.trim()?"换个关键词试试。":"发送第一条消息后,这里会出现新的会话记录。"})]})})]})}const We=[{value:"default",label:"请求批准",tone:"safe"},{value:"bypassPermissions",label:"完全访问",tone:"open"}];function Qr({activeRunId:e,activeAgentMode:r,activeSessionKey:s,availableKnowledgeBases:n,branding:i,composerPermissionCard:l,draft:c,pendingBridgeActionId:f,permissionModeSaving:m,selectedKnowledgeBaseIds:j,selectedProject:k,sending:S,serviceRunning:v,taskInputLocked:h,taskRunning:A,taskState:y,transportReady:M,onBridgeAction:F,onSend:K,onStopTask:L,setActiveAgentMode:$,setDraft:C,setSelectedKnowledgeBaseIds:a}){const[b,z]=o.useState(!1),D=o.useRef(null),[B,I]=o.useState(""),U=rt(j,n),P=Br(n,B),_=Ur(P,j),w=j.length,u=We.some(p=>p.value===r)?r:"default",N=Wr({serviceRunning:v,transportReady:M,taskState:y,taskInputLocked:h,startFirstPlaceholder:i.startFirstPlaceholder,waitingRuntimePlaceholder:i.waitingRuntimePlaceholder,sendPlaceholder:i.sendPlaceholder}),H=Vr({draft:c,serviceRunning:v,transportReady:M,sending:S,selectedProject:k});return o.useEffect(()=>{const p=O=>{var E;(E=D.current)!=null&&E.contains(O.target)||z(!1)};return b&&document.addEventListener("mousedown",p),()=>{document.removeEventListener("mousedown",p)}},[b]),o.useEffect(()=>{if(!b)return;const p=window.requestAnimationFrame(()=>{var E;const O=(E=D.current)==null?void 0:E.querySelector("input");O instanceof HTMLInputElement&&O.focus()});return()=>window.cancelAnimationFrame(p)},[b]),t.jsx("div",{className:"border-t border-slate-200/80 px-3 py-3 dark:border-white/[0.06] sm:px-6",children:t.jsx("div",{className:"mx-auto max-w-4xl rounded-[24px] border border-slate-200 bg-[#fbfbfd] p-2 dark:border-white/[0.08] dark:bg-[#111214] sm:p-2.5",children:l?t.jsx(Xr,{card:l,loading:f===l.id,onAction:p=>void F(l,p),testId:"desktop-chat-composer-permission-card",className:"border-primary/45 bg-white shadow-[0_14px_34px_rgba(0,122,255,0.12)] dark:border-primary/35 dark:bg-[#090d12]"}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"relative",children:[t.jsx(Nt,{"data-testid":"desktop-chat-input",value:c,onChange:p=>C(p.target.value),onKeyDown:p=>{p.key==="Enter"&&!p.shiftKey&&!h&&(p.preventDefault(),K())},rows:3,placeholder:N,"aria-label":N,disabled:!v||!M||S||!k||h,className:"min-h-[104px] rounded-[22px] border-slate-200 bg-white px-4 pb-16 pt-3 text-[15px] leading-6 text-slate-900 placeholder:text-slate-400 focus-visible:ring-primary/15 dark:border-white/[0.08] dark:bg-[#090d12] dark:text-white dark:placeholder:text-slate-500 sm:min-h-[116px] sm:px-5 sm:pt-4"}),A?t.jsxs(X,{variant:"danger",onClick:()=>void L(),disabled:!s&&!e||y==="stopping","data-testid":"desktop-chat-stop-task",className:"absolute bottom-3 right-3 h-11 min-w-11 rounded-full bg-red-50 px-3 text-red-600 shadow-none hover:bg-red-100 dark:bg-red-500/12 dark:text-red-200 dark:hover:bg-red-500/18 sm:h-12 sm:min-w-[118px] sm:px-5",children:[t.jsx(Ke,{size:16,className:"animate-spin"}),t.jsx("span",{className:"hidden sm:inline",children:y==="stopping"?"停止中":"停止任务"})]}):t.jsx(X,{onClick:()=>void K(),disabled:!H,"data-testid":"desktop-chat-send",className:"absolute bottom-3 right-3 h-11 w-11 rounded-full bg-primary px-0 text-white shadow-none hover:bg-[#0071e3] disabled:bg-slate-300 disabled:text-white disabled:opacity-100 dark:bg-primary dark:text-white dark:hover:bg-[#2997ff] dark:disabled:bg-white/20 dark:disabled:text-white/55 sm:h-12 sm:w-12",children:S?t.jsx(Ke,{size:18,className:"animate-spin"}):t.jsx(Ot,{size:22,strokeWidth:2.2})})]}),t.jsxs("div",{className:"mt-2 flex flex-col gap-2 px-1 pr-0 text-[11px] text-slate-500 dark:text-slate-400 sm:flex-row sm:items-center sm:justify-between sm:pr-[4.5rem]",children:[t.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[t.jsxs("div",{className:"inline-flex h-8 shrink-0 items-center gap-1 rounded-full border border-slate-200 bg-white p-1 shadow-sm dark:border-white/[0.08] dark:bg-white/[0.05]",role:"group","aria-label":"权限模式","data-testid":"desktop-chat-permission-mode",children:[t.jsx(lr,{size:13,className:"ml-1 text-amber-500"}),We.map(p=>{const O=u===p.value;return t.jsx("button",{type:"button",disabled:!k||m||A,onClick:()=>$(p.value),"data-testid":`desktop-chat-permission-mode-${p.value}`,className:Y("h-6 rounded-full px-2.5 text-xs font-medium transition-colors",O?p.tone==="open"?"bg-amber-100 text-amber-800 dark:bg-amber-500/18 dark:text-amber-100":"bg-slate-900 text-white dark:bg-white dark:text-slate-950":"text-slate-500 hover:bg-slate-100 hover:text-slate-900 dark:text-slate-300 dark:hover:bg-white/[0.08] dark:hover:text-white","disabled:cursor-not-allowed disabled:opacity-50"),children:p.label},p.value)}),m?t.jsx(Ke,{size:12,className:"mr-1 animate-spin text-slate-400"}):null]}),t.jsxs("div",{className:"relative",ref:D,children:[t.jsxs(X,{size:"sm",variant:"secondary",disabled:!k,onClick:()=>z(p=>!p),"data-testid":"desktop-chat-knowledge-base-toggle",className:"h-8 rounded-full border border-slate-200 bg-white px-2.5 text-xs text-slate-700 shadow-sm hover:bg-slate-100 dark:border-white/[0.08] dark:bg-white/[0.05] dark:text-slate-100 dark:hover:bg-white/[0.1]",children:[t.jsx(ar,{size:13}),w>0?"调整知识库":"选择知识库"]}),b?t.jsxs("div",{className:"animate-float-in absolute bottom-full left-0 z-20 mb-3 w-[min(34rem,calc(100vw-2rem))] max-h-[70dvh] overflow-hidden rounded-[22px] border border-slate-200 bg-white p-3 shadow-[0_18px_45px_rgba(15,23,42,0.12)] dark:border-white/[0.08] dark:bg-[#0c1117]",children:[t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsxs("div",{children:[t.jsx("p",{className:"text-sm font-semibold text-slate-900 dark:text-white",children:"选择知识库"}),t.jsx("p",{className:"text-[11px] text-slate-400",children:"已选项排在前面,方便快速确认范围。"})]}),w>0?t.jsx("button",{type:"button",onClick:()=>void a([]),className:"text-xs text-slate-400 transition-colors hover:text-slate-900 dark:hover:text-white",children:"清空"}):null]}),t.jsx(_e,{value:B,onChange:p=>I(p.target.value),placeholder:"搜索知识库","aria-label":"搜索知识库",className:"mt-3 rounded-[18px] border-slate-200 bg-white text-slate-900 placeholder:text-slate-400 dark:border-white/[0.08] dark:bg-white/[0.04] dark:text-white dark:placeholder:text-slate-500"}),t.jsx("div",{className:"mt-3 max-h-64 space-y-2 overflow-y-auto pr-2 [scrollbar-gutter:stable]",children:_.length===0?t.jsx("div",{className:"rounded-xl border border-dashed border-slate-200 px-3 py-4 text-center text-xs text-slate-500 dark:border-white/[0.08]",children:"没有匹配的知识库"}):_.map(p=>{const O=j.includes(p.id);return t.jsxs("button",{type:"button",onClick:()=>void a(O?j.filter(E=>E!==p.id):[...j,p.id]),"data-testid":"desktop-chat-knowledge-base-select",className:Y("flex w-full items-start gap-3 rounded-[16px] border px-3 py-3 text-left transition-all duration-200",O?"border-primary/25 bg-primary/5 dark:border-primary/30 dark:bg-primary/10":"border-slate-200 bg-white hover:border-slate-300 hover:bg-[#fafafa] dark:border-white/[0.06] dark:bg-white/[0.03] dark:hover:border-white/[0.12] dark:hover:bg-white/[0.05]"),children:[t.jsx("span",{className:Y("mt-0.5 inline-flex h-5 w-5 items-center justify-center rounded-full border text-[10px]",O?"border-primary bg-primary text-white":"border-slate-300 text-transparent dark:border-white/[0.12]"),children:t.jsx(Ye,{size:12})}),t.jsxs("span",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"block truncate text-sm font-medium text-slate-900 dark:text-white",children:p.name}),t.jsxs("span",{className:"mt-1 block text-[11px] text-slate-400",children:[p.fileCount," 文件",p.description?` · ${p.description}`:""]})]})]},p.id)})})]}):null]}),t.jsx("div",{className:"flex min-w-0 items-center gap-2 overflow-x-auto whitespace-nowrap [scrollbar-gutter:stable]",children:U.length===0?t.jsx("span",{className:"text-xs text-slate-400",children:k?"当前未限制知识库范围":"选择项目后可设置知识库范围"}):U.map(p=>t.jsxs("span",{className:"inline-flex shrink-0 items-center gap-2 rounded-full border border-slate-200 bg-white px-2.5 py-1 text-xs text-slate-700 shadow-sm dark:border-white/[0.08] dark:bg-white/[0.05] dark:text-slate-100",children:[t.jsx("span",{className:"max-w-[10rem] truncate",children:p.name}),p.fileCount>0?t.jsxs("span",{className:"text-[10px] text-slate-500",children:[p.fileCount," 文件"]}):null,t.jsx("button",{type:"button",onClick:()=>void a(j.filter(O=>O!==p.id)),className:"text-slate-500 transition-colors hover:text-slate-900 dark:hover:text-white","data-testid":"desktop-chat-knowledge-base-remove","aria-label":`移除 ${p.name}`,children:t.jsx(Ge,{size:12})})]},p.id))})]}),t.jsxs("div",{className:"hidden shrink-0 items-center gap-3 sm:flex",children:[t.jsx("span",{children:"Enter 发送,Shift + Enter 换行"}),t.jsx("span",{children:k?"范围会随当前线程保存":"请先选择项目"})]})]})]})})})}function Zr({deleteTarget:e,pendingSessionAction:r,renameDraft:s,renameTarget:n,onDeleteSession:i,onRenameSession:l,setDeleteTarget:c,setRenameDraft:f,setRenameTarget:m}){return t.jsxs(t.Fragment,{children:[t.jsx(Re,{open:!!n,onClose:()=>m(null),title:"重命名会话",children:t.jsxs("div",{className:"space-y-4",children:[t.jsx(_e,{value:s,onChange:j=>f(j.target.value),onInput:j=>f(j.target.value),placeholder:"输入会话名称","data-testid":"desktop-chat-rename-input"}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx(X,{variant:"secondary",onClick:()=>m(null),"data-testid":"desktop-chat-rename-cancel",children:"取消"}),t.jsx(X,{onClick:()=>void l(),loading:r==="rename",disabled:!s.trim(),"data-testid":"desktop-chat-rename-save",children:"保存名称"})]})]})}),t.jsx(Re,{open:!!e,onClose:()=>c(null),title:"删除会话",children:t.jsxs("div",{className:"space-y-4",children:[t.jsxs("p",{className:"text-sm text-gray-600 dark:text-gray-300",children:["确定删除 ",t.jsx("span",{className:"font-medium text-gray-900 dark:text-white",children:e==null?void 0:e.name})," 吗?这会移除该会话的本地保存记录。"]}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx(X,{variant:"secondary",onClick:()=>c(null),"data-testid":"desktop-chat-delete-cancel",children:"取消"}),t.jsx(X,{variant:"danger",onClick:()=>void i(),loading:r==="delete","data-testid":"desktop-chat-delete-confirm",children:"删除会话"})]})]})})]})}function at(){return Ve()==="local_core"?{chatTitle:"本地对话",chatHeading:"本地对话",chatDescription:"浏览线程、切换工作区,并与本地 AI Core 保持同步。",scopeLabel:"当前工作区",scopeSelectPlaceholder:"选择工作区",searchPlaceholder:"搜索线程、联系人或消息摘要",startRuntimeLabel:"启动运行时",startingRuntimeLabel:"启动中…",newThreadLabel:"新建线程",pendingRestartLabel:"最新配置已经保存,但当前对话仍在使用旧运行时状态。请重启运行时以应用配置。",emptySelectionLabel:"选择工作区后即可开始对话。",emptyThreadsLabel:"当前还没有线程。",emptySearchLabel:"没有匹配的线程。",collectionLabel:"线程",activeScopeLabel:"当前工作区",activeConversationFallback:"新对话",startConversationLabel:"选择工作区后即可开始聊天。",runtimeOnlineLabel:"运行时在线",runtimeOfflineLabel:"运行时离线",emptyConversationLabel:"发送一条消息,即可在当前工作区创建新线程。",startFirstPlaceholder:"请先启动运行时",waitingRuntimePlaceholder:"正在等待运行时通道连接",sendPlaceholder:"输入一条发给当前线程的消息",permissionUnsupportedLabel:"当前代理无法在此对话中继续交互式审批。请切换到支持的代理,或调整运行时权限后重试。",replyTimeoutLabel:"审批回复已发送,但代理没有继续执行。该请求可能暂不支持本地运行时继续处理。"}:{chatTitle:"桌面对话",chatHeading:"桌面对话",chatDescription:"",scopeLabel:"当前项目",scopeSelectPlaceholder:"选择项目",searchPlaceholder:"搜索会话、用户或消息摘要",startRuntimeLabel:"启动服务",startingRuntimeLabel:"启动中…",newThreadLabel:"新建会话",pendingRestartLabel:"最新配置已经保存,但当前对话仍在使用旧服务状态。请重启桌面服务以应用配置。",emptySelectionLabel:"选择项目后即可开始对话。",emptyThreadsLabel:"当前还没有桌面会话。",emptySearchLabel:"没有匹配的会话。",collectionLabel:"会话",activeScopeLabel:"当前项目",activeConversationFallback:"新桌面对话",startConversationLabel:"选择项目后即可开始聊天。",runtimeOnlineLabel:"桥接在线",runtimeOfflineLabel:"桥接离线",emptyConversationLabel:"发送一条消息,即可在当前项目中创建桌面会话。",startFirstPlaceholder:"请先启动服务",waitingRuntimePlaceholder:"正在等待桌面桥接连接",sendPlaceholder:"输入一条发给桌面通道的消息",permissionUnsupportedLabel:"当前代理无法在桌面对话中继续交互式审批。请切换到支持的代理,或调整代理权限与 work_dir 后重试。",replyTimeoutLabel:"审批回复已发送,但代理没有继续执行。当前代理或请求可能暂不支持桌面续接。"}}function qr({requestedProject:e,selectedProject:r,setSelectedProject:s,clearReplyTimeout:n,updateTaskState:i,setTyping:l}){const[c,f]=o.useState(null),[m,j]=o.useState(!0),k=Ve(),S=k==="electron",v=(c==null?void 0:c.phase)==="api_ready",h=v,A=o.useCallback(async()=>{const y=await Vt();f(y),!y.roles.conversation.lastError&&!r&&!e&&y.settings.defaultProject&&s(y.settings.defaultProject)},[e,r,s]);return o.useEffect(()=>{A().finally(()=>j(!1));const y=Jt(M=>{f(M),(M.phase==="stopped"||M.phase==="error")&&(l(!1),n(),i("idle"))});return()=>{n(),y()}},[n,A,l,i]),o.useMemo(()=>({loading:m,refreshRuntime:A,runtime:c,runtimeProvider:k,serviceRunning:v,showSessionKey:S,transportReady:h}),[m,A,c,k,v,S,h])}function ea({current:e,requested:r,runtimeDefault:s,workspaceIds:n}){return e&&n.includes(e)?e:r&&n.includes(r)?r:s&&n.includes(s)?s:n[0]||""}function ta({activeThreadId:e,requestedWorkspaceId:r,requestedThreadId:s,runtimeDefaultWorkspaceId:n,runtimeProvider:i,searchParams:l,serviceRunning:c,selectedWorkspaceId:f,workspaceIds:m,threadGroups:j,threadSearch:k,setSelectedKnowledgeBaseIds:S,setActiveRunId:v,setActiveSessionAgentType:h,setActiveAgentMode:A,setActiveSessionId:y,setActiveSessionKey:M,setActiveSessionName:F,setBridgeError:K,setMessages:L,setPendingPermissionRequest:$,setProjects:C,setSearchParams:a,setSelectedProject:b,setThreadGroups:z,setTyping:D,applyLocalCoreThreadDetail:B,clearReplyTimeout:I,updateTaskState:U,holdBlankComposerRef:P,lastSessionByProjectRef:_,nextMessageOrderRef:w,pendingTurnRef:u,progressSequenceByTurnRef:N}){const p=o.useMemo(()=>{var x;return((x=j.find(T=>T.project===f))==null?void 0:x.sessions)||[]},[f,j]),O=o.useMemo(()=>{const x=k.trim().toLowerCase();return m.map(T=>{var d;const R=(((d=j.find(g=>g.project===T))==null?void 0:d.sessions)||[]).filter(g=>br(g,x));return{project:T,sessions:R}}).filter(T=>T.sessions.length>0||!x&&T.project===f)},[f,j,k,m]),E=o.useCallback(async x=>{if(!x||!c)return[];const T=et((await Ct(x)).threads.map(d=>qe(d))),R=T.find(d=>d.id===e);return R!=null&&R.agentType&&h(R.agentType),R!=null&&R.agentMode&&A(R.agentMode),z(d=>tt(d,x,T)),T},[e,c,A,h,z,!0]),J=o.useCallback(async(x,T)=>{if(!(!x||!T||!c)){P.current=!1,U("idle"),$(null),D(!1);{const R=await St(T);B(R);return}}},[B,P,_,w,u,N,c,v,A,h,y,M,F,S,L,$,b,z,D,U,!0]),W=o.useCallback(async()=>{if(!c)return C([]),z([]),S([]),[];const x=(await Mt()).workspaces.map(d=>d.id);C(x);const T=ea({current:f,requested:r,runtimeDefault:n,workspaceIds:x}),R=(await Promise.all(x.map(async d=>({project:d,sessions:await E(d)})))).sort((d,g)=>d.project.localeCompare(g.project));return z(R),b(T),R},[E,r,n,f,c,C,S,b,z,!0]);return o.useEffect(()=>{if(!(!c||i!=="local_core"))return Kt(x=>{x.type==="thread.session.activated"&&x.threadId!==e&&E(x.workspaceId).then(()=>J(x.workspaceId,x.threadId))})},[e,J,E,i,c]),o.useEffect(()=>{if(!c){z([]),L([]),$(null),S([]),h(""),v(""),K(""),u.current=null,w.current=0,N.current={},U("idle"),D(!1),I();return}W()},[I,w,u,N,W,c,v,h,K,L,$,S,z,D,U]),o.useEffect(()=>{if(!f||!c||p.find(g=>g.id===e))return;const T=r===f?s:"",R=_.current[f];if(!e&&P.current)return;const d=p.find(g=>g.id===T)||p.find(g=>g.id===R)||p[0];if(d){D(!1),U("idle"),K(""),I(),J(f,d.id);return}D(!1),U("idle"),K(""),I(),y(""),M(""),F(""),h(""),v(""),L([]),u.current=null,w.current=0,N.current={}},[e,I,P,_,J,w,u,N,s,r,f,c,v,h,y,M,F,K,L,D,p,U]),o.useEffect(()=>{if(!f&&!e)return;const x=new URLSearchParams(l);f?x.set("project",f):x.delete("project"),e?x.set("session",e):x.delete("session"),x.toString()!==l.toString()&&a(x,{replace:!0})},[e,l,f,a]),{filteredThreadGroups:O,loadActiveThread:J,refreshThreadsForWorkspace:E,refreshWorkspacesAndThreads:W}}function ra({activeAgentType:e,activeThreadId:r,armReplyTimeout:s,clearActionStatuses:n,clearReplyTimeout:i,reserveNextMessageOrder:l,runtimeProvider:c,selectedWorkspaceId:f,sendAction:m,settlePreviewMessages:j,setActiveRunId:k,setBridgeError:S,setMessages:v,setPendingPermissionRequest:h,setPendingBridgeActionId:A,setTyping:y,updateTaskState:M}){return{handleBridgeAction:o.useCallback(async(L,$)=>{if(!r)return;const C=Ee($.data)||$.data,a=Ee($.data)||$.text||$.data,b=Kr(L),z=!b,D=z?-1:l(),B=`${crypto.randomUUID()}-user-action`;let I=!1,U=!1;A(L.id),v(P=>P.map(_=>_.id===L.id?{..._,actionPending:!0}:_)),h(P=>P&&P.id===L.id?{...P,actionPending:!0}:P);try{b&&(U=!0,v(_=>[..._,{id:B,role:"user",content:a,order:D,timestamp:new Date().toISOString()}]));const P=await m(r,C);k(P.runId),I=!0,S(""),j(L.actionReplyCtx),y(!0),i(),n(),z?(M("permission_submitted","bridge-permission-submitted"),s("permission_continue"),h(null),v(_=>_.map(w=>w.id===L.id?Ar(w):w))):(M("running","bridge-action-submitted"),s())}catch(P){S(P instanceof Error?P.message:"Failed to send permission response."),U&&v(_=>_.filter(w=>w.id!==B)),M(z?"awaiting_permission":"error",z?"bridge-permission-submit-failed":"bridge-action-submit-failed"),y(!1),h(_=>_&&_.id===L.id?{..._,actionPending:!1}:_)}finally{A(null),v(P=>P.map(_=>_.id===L.id?{..._,actionPending:!1,actions:I?_.actions||[]:_.actions}:_))}},[r,s,n,i,l,m,j,k,S,v,h,A,y,M,!0])}}function aa(e){return e==="awaiting_permission"?"awaiting_permission":"idle"}function sa(e,r){return r?"awaiting_permission":e?"awaiting_input":"idle"}function na(e,r){return r?"bridge-buttons-awaiting-permission":e?"bridge-buttons-awaiting-input":"bridge-buttons-idle"}function ia(e){const r=e||"This agent",s=at();return s.permissionUnsupportedLabel.startsWith("This agent")?s.permissionUnsupportedLabel:`${r} ${s.permissionUnsupportedLabel.replace(/^This agent\s+/i,"")}`}function oa(e){return e.type==="typing_stop"||e.type==="buttons"||e.type==="card"?!0:e.type==="reply"&&!he(e.bridgeKind)}function la({activeAgentType:e,activeBridgeSessionKey:r,activeRunId:s,armReplyTimeout:n,clearActionStatuses:i,clearReplyTimeout:l,finalizeTurnMessages:c,nextProgressMessageId:f,pendingTurnRef:m,progressSequenceByTurnRef:j,refreshThreadsForWorkspace:k,reserveAssistantMessageOrder:S,settlePreviewMessages:v,setBridgeError:h,setMessages:A,setPendingPermissionRequest:y,setTyping:M,taskStateRef:F,updateTaskState:K}){const L=Dt(e),$=o.useCallback(a=>{Sr(F.current)&&K("running",a)},[F,K]),C=o.useCallback(a=>{const b=wr(a.sessionKey);if(b&&oa(a)&&k(b),!(!a.sessionKey||a.sessionKey!==r)&&pr({event:a,activeRunId:s,pendingTurn:m.current}))switch(a.type){case"preview_start":if(Le(a.bridgeStatus)){l(),M(!1),m.current=null,i(),K("awaiting_input","bridge-preview-awaiting-input"),y(null),h(""),A(w=>{const u=je(w,a.previewHandle,a.replyCtx),N=(u==null?void 0:u.id)||a.previewHandle||`${a.replyCtx||crypto.randomUUID()}-preview`,H=w.filter(p=>p.id!==N);return H.push({id:N,role:"assistant",content:a.content||"",kind:"progress",bridgeKind:a.bridgeKind,bridgeStatus:a.bridgeStatus,order:(u==null?void 0:u.order)??S(a.sessionKey),timestamp:(u==null?void 0:u.timestamp)||new Date().toISOString(),turnKey:a.replyCtx,preview:!0,previewPlainText:L}),H});break}i(),M(!0),$("bridge-preview-start"),y(null),n(),h(""),A(w=>{const u=je(w,a.previewHandle,a.replyCtx),N=(u==null?void 0:u.id)||a.previewHandle||`${a.replyCtx||crypto.randomUUID()}-preview`,H=w.filter(p=>p.id!==N);return H.push({id:N,role:"assistant",content:a.content||"",kind:"progress",bridgeKind:a.bridgeKind,bridgeStatus:a.bridgeStatus,order:(u==null?void 0:u.order)??S(a.sessionKey),timestamp:(u==null?void 0:u.timestamp)||new Date().toISOString(),turnKey:a.replyCtx,preview:!0,previewPlainText:L}),H});break;case"update_message":if(Le(a.bridgeStatus)){l(),M(!1),m.current=null,i(),K("awaiting_input","bridge-update-awaiting-input"),y(null),h(""),A(w=>{const u=je(w,a.previewHandle,a.replyCtx);return u?w.map(N=>N.id===u.id?{...N,content:a.content||"",bridgeKind:a.bridgeKind,bridgeStatus:a.bridgeStatus,preview:!0,previewPlainText:L}:N):[...w,{id:a.previewHandle||`${a.replyCtx||crypto.randomUUID()}-preview`,role:"assistant",content:a.content||"",kind:"progress",bridgeKind:a.bridgeKind,bridgeStatus:a.bridgeStatus,order:S(a.sessionKey),timestamp:new Date().toISOString(),turnKey:a.replyCtx,preview:!0,previewPlainText:L}]});break}i(),M(!0),$("bridge-update-message"),y(null),n(),h(""),A(w=>{const u=je(w,a.previewHandle,a.replyCtx);return u?w.map(N=>N.id===u.id?{...N,content:a.content||"",bridgeKind:a.bridgeKind,bridgeStatus:a.bridgeStatus,preview:!0,previewPlainText:L}:N):[...w,{id:a.previewHandle||`${a.replyCtx||crypto.randomUUID()}-preview`,role:"assistant",content:a.content||"",kind:"progress",bridgeKind:a.bridgeKind,bridgeStatus:a.bridgeStatus,order:S(a.sessionKey),timestamp:new Date().toISOString(),turnKey:a.replyCtx,preview:!0,previewPlainText:L}]});break;case"delete_message":A(w=>w.filter(u=>u.id!==a.previewHandle));break;case"typing_start":i(),M(!0),$("bridge-typing-start"),y(null),h(""),n();break;case"typing_stop":M(!1),l(),m.current=null,i(),K(aa(F.current),F.current==="awaiting_permission"?"bridge-typing-stop-preserve-permission":"bridge-typing-stop"),v(a.replyCtx),c(a.replyCtx);break;case"reply":{const w=Le(a.bridgeStatus);i(),M(!w),w?(l(),m.current=null,K("awaiting_input","bridge-reply-awaiting-input")):($("bridge-reply"),n()),y(null),h("");const u=a.messageId||f(a.replyCtx);!he(a.bridgeKind)&&a.replyCtx&&delete j.current[a.replyCtx],h(""),A(N=>{const H=N.find(O=>O.id===u),p=new Date().toISOString();return H?N.map(O=>O.id===u?{...O,content:a.content||"",toolCall:a.toolCall,bridgeKind:a.bridgeKind,bridgeStatus:a.bridgeStatus,kind:"progress",timestamp:p,turnKey:a.replyCtx}:O):[...N.filter(O=>!mr(O,a.content,a.replyCtx,a.bridgeKind)),{id:u,role:"assistant",content:a.content||"",toolCall:a.toolCall,bridgeKind:a.bridgeKind,bridgeStatus:a.bridgeStatus,kind:"progress",order:S(a.sessionKey),timestamp:p,turnKey:a.replyCtx}]});break}case"buttons":l(),M(!1),m.current=null,h(""),i(),v(a.replyCtx);const z=`${a.replyCtx||crypto.randomUUID()}-buttons`,D=kr(a.buttonRows||a.buttons),B=jr(D),I=B&&Bt(e),U=B&&!I?[]:D,P=U,_=B&&!I?ia(e):void 0;A(w=>w.find(N=>N.id===z)?w.map(N=>N.id===z?{...N,content:a.content||N.content,actions:P,actionReplyCtx:a.replyCtx,actionPending:!1,actionMode:B?"permission":"generic",actionInteractive:I,bridgeKind:a.bridgeKind,bridgeStatus:a.bridgeStatus,actionStatus:_}:N):[...w,{id:z,role:"assistant",content:a.content||"Permission required before continuing.",kind:"progress",bridgeKind:a.bridgeKind,bridgeStatus:a.bridgeStatus,order:S(a.sessionKey),timestamp:new Date().toISOString(),turnKey:a.replyCtx,actions:P,actionReplyCtx:a.replyCtx,actionPending:!1,actionMode:B?"permission":"generic",actionInteractive:I,actionStatus:_}]),y(w=>{if(!B||!I)return null;const u={id:z,role:"assistant",content:a.content||"Permission required before continuing.",actions:U,actionReplyCtx:a.replyCtx,actionPending:!1,actionMode:"permission",actionStatus:_};return _r(u)||w}),K(sa(D.length>0,I),na(D.length>0,I));break;case"card":l(),M(!1),m.current=null,i(),K("idle","bridge-card"),y(null),v(a.replyCtx),c(a.replyCtx),h(""),A(w=>[...w,{id:`${a.replyCtx||crypto.randomUUID()}-card`,role:"assistant",content:"Interactive card received. Open the session in the standard Sessions view for full controls.",order:S(a.sessionKey),timestamp:new Date().toISOString()}]);break}},[L,e,r,s,n,i,l,c,f,m,j,k,S,v,h,A,y,M,$,K]);o.useEffect(()=>{const a=Xt(b=>{C(b)});return()=>{l(),a()}},[l,C])}function da(e){la({activeAgentType:e.activeAgentType,activeBridgeSessionKey:e.activeBridgeSessionKey,activeRunId:e.activeRunId,armReplyTimeout:e.armReplyTimeout,clearActionStatuses:e.clearActionStatuses,clearReplyTimeout:e.clearReplyTimeout,finalizeTurnMessages:e.finalizeTurnMessages,nextProgressMessageId:e.nextProgressMessageId,pendingTurnRef:e.pendingTurnRef,progressSequenceByTurnRef:e.progressSequenceByTurnRef,refreshThreadsForWorkspace:e.refreshThreadsForWorkspace,reserveAssistantMessageOrder:e.reserveAssistantMessageOrder,settlePreviewMessages:e.settlePreviewMessages,setBridgeError:e.setBridgeError,setMessages:e.setMessages,setPendingPermissionRequest:e.setPendingPermissionRequest,setTyping:e.setTyping,taskStateRef:e.taskStateRef,updateTaskState:e.updateTaskState});const{handleBridgeAction:r}=ra({activeAgentType:e.activeAgentType,activeBridgeSessionKey:e.activeBridgeSessionKey,activeRunId:e.activeRunId,activeThreadId:e.activeThreadId,armReplyTimeout:e.armReplyTimeout,clearActionStatuses:e.clearActionStatuses,clearReplyTimeout:e.clearReplyTimeout,reserveNextMessageOrder:e.reserveNextMessageOrder,runtimeProvider:e.runtimeProvider,selectedWorkspaceId:e.selectedWorkspaceId,sendAction:e.sendAction,settlePreviewMessages:e.settlePreviewMessages,setActiveRunId:e.setActiveRunId,setBridgeError:e.setBridgeError,setMessages:e.setMessages,setPendingPermissionRequest:e.setPendingPermissionRequest,setPendingBridgeActionId:e.setPendingBridgeActionId,setTyping:e.setTyping,updateTaskState:e.updateTaskState,taskStateRef:e.taskStateRef});return{handleBridgeAction:r}}function ca({activeRunId:e,activeThreadId:r,activeBridgeSessionKey:s,activeAgentMode:n,availableKnowledgeBases:i,brandingNewThreadLabel:l,draft:c,loadActiveThread:f,selectedKnowledgeBaseIds:m,runtimeProvider:j,selectedProject:k,taskState:S,updateTaskState:v,applyLocalCoreThreadDetail:h,armReplyTimeout:A,clearReplyTimeout:y,refreshSessionsForProject:M,reserveNextMessageOrder:F,settlePreviewMessages:K,setActiveRunId:L,setActiveSessionId:$,setActiveSessionKey:C,setActiveSessionName:a,setBridgeError:b,setDraft:z,setMessages:D,setPendingPermissionRequest:B,setSending:I,setTyping:U,holdBlankComposerRef:P,lastSessionByProjectRef:_,nextMessageOrderRef:w,pendingTurnRef:u,progressSequenceByTurnRef:N,taskStateRef:H}){const O=o.useCallback(x=>{if(x.trim().startsWith("/"))return x;if(m.length===0)return Me(x);const T=m.map(R=>i.find(d=>d.id===R)).filter(R=>!!R);return T.length===0?Me(x):Me(x,[["[Selected Knowledge Bases]",...T.map(R=>`- id: ${R.id} | name: ${R.name}`),"[/Selected Knowledge Bases]"].join(`
|
|
28
|
+
`)])},[i,m]),E=o.useCallback(async()=>{if(!k)throw new Error("Choose a project first");if(r)return{id:r,sessionKey:s};let x=await Je(k,`${l} ${new Date().toLocaleTimeString()}`);return n&&n!=="default"&&(x=await Ae(x.id,n)),h(x),await M(k),{id:x.id,sessionKey:x.bridgeSessionKey||""}},[s,n,r,h,l,M,k,!0]),J=o.useCallback(async()=>{if(!c.trim()||!k)return;const x=c.trim(),T=S==="awaiting_input",R=T?x:O(x),d=F();z(""),I(!0);try{const g=await E();if(console.info("[desktop-chat] send",{runtimeProvider:j,selectedProject:k,threadId:g.id,sessionKey:g.sessionKey,selectedKnowledgeBaseIds:m}),u.current={sessionKey:g.sessionKey,userOrder:d,runId:T?e:void 0,supersededRunId:T?void 0:e},B(null),D(V=>[...V,{id:`${crypto.randomUUID()}-user`,role:"user",content:x,order:d,timestamp:new Date().toISOString()}]),v("running","send-started"),U(!0),b(""),g.id&&await ze(g.id,m),A(),g.id){const V=T?await Xe(g.id,R):await Lt(g.id,R);L(V.runId),u.current&&u.current.sessionKey===g.sessionKey&&u.current.userOrder===d&&(u.current={...u.current,runId:V.runId})}else throw new Error("Managed desktop thread transport is unavailable.")}catch(g){y(),u.current=null,K(),B(null),U(!1),v("error","send-failed"),b(g instanceof Error?g.message:"Failed to send the message.")}finally{I(!1)}},[e,A,O,y,c,E,S,u,F,m,k,L,b,z,D,B,I,K,U,v,!0]),W=o.useCallback(async()=>{if(!(!k||S==="stopping")){b(""),y(),K(),B(null),U(!1),v("stopping","stop-requested");try{if(e)await _t(e);else throw new Error("No active run to stop.");window.setTimeout(()=>{H.current==="stopping"&&v("idle","stop-timeout-complete")},1500)}catch(x){v("error","stop-failed"),b(x instanceof Error?x.message:"Failed to stop the current task.")}}},[e,y,b,B,K,U,k,S,H,v,!0]);return{handleSend:J,handleStopTask:W}}function ua({activeThreadId:e,brandingNewThreadLabel:r,deleteTarget:s,renameDraft:n,renameTarget:i,runtimeProvider:l,searchParams:c,selectedKnowledgeBaseIds:f,activeAgentMode:m,selectedProject:j,updateTaskState:k,applyLocalCoreThreadDetail:S,clearReplyTimeout:v,refreshSessionsForProject:h,setActiveRunId:A,setActiveSessionAgentType:y,setActiveSessionId:M,setActiveSessionKey:F,setActiveSessionName:K,setBridgeError:L,setDeleteTarget:$,setMessages:C,setPendingPermissionRequest:a,setPendingSessionAction:b,setRenameDraft:z,setRenameTarget:D,setSearchParams:B,setTyping:I,holdBlankComposerRef:U,nextMessageOrderRef:P,pendingTurnRef:_,progressSequenceByTurnRef:w}){const N=l==="local_core",H=o.useCallback(()=>{U.current=!0,M(""),F(""),K(""),y(""),A(""),C([]),a(null),I(!1),k("idle"),L(""),_.current=null,P.current=0,w.current={},v()},[v,U,P,_,w,A,y,M,F,K,L,C,a,I,k]),p=o.useCallback(async()=>{if(j){if(N){b("rename");try{let W=await Je(j,`${r} ${new Date().toLocaleTimeString()}`);if(m&&m!=="default"&&(W=await Ae(W.id,m)),f.length>0){const T=(await ze(W.id,f)).knowledgeBaseIds;W.selectedKnowledgeBaseIds=T}else W.selectedKnowledgeBaseIds=[];await h(j),S(W);const x=new URLSearchParams(c);x.set("project",j),x.set("session",W.id),B(x,{replace:!0})}finally{b(null)}return}H()}},[S,m,r,h,H,c,f,j,b,B,N,!0]),O=o.useCallback((W,x)=>{D({project:W,id:x.id,name:x.name}),z(x.name)},[z,D]),E=o.useCallback(async()=>{if(i){b("rename");try{const W=n.trim();await At(i.id,W),i.id===e&&K(W),await h(i.project),D(null),z("")}finally{b(null)}}},[e,h,n,i,K,b,z,D,!0]),J=o.useCallback(async()=>{if(s){b("delete");try{await zt(s.id),s.id===e&&H(),await h(s.project),$(null)}finally{b(null)}}},[e,s,h,H,$,b,!0]);return{handleCreateNew:p,handleDeleteSession:J,handleRenameSession:E,openRenameModal:O}}function ma({activeRunId:e,activeThreadId:r,activeBridgeSessionKey:s,availableKnowledgeBases:n,brandingNewThreadLabel:i,deleteTarget:l,draft:c,loadActiveThread:f,renameDraft:m,renameTarget:j,runtimeProvider:k,searchParams:S,selectedKnowledgeBaseIds:v,activeAgentMode:h,selectedWorkspaceId:A,taskState:y,updateTaskState:M,applyLocalCoreThreadDetail:F,armReplyTimeout:K,clearReplyTimeout:L,refreshSessionsForProject:$,reserveNextMessageOrder:C,settlePreviewMessages:a,setActiveRunId:b,setActiveSessionAgentType:z,setActiveAgentMode:D,setActiveSessionId:B,setActiveSessionKey:I,setActiveSessionName:U,setBridgeError:P,setDeleteTarget:_,setDraft:w,setMessages:u,setPendingPermissionRequest:N,setPendingSessionAction:H,setRenameDraft:p,setRenameTarget:O,setSearchParams:E,setSending:J,setTyping:W,holdBlankComposerRef:x,lastSessionByProjectRef:T,nextMessageOrderRef:R,pendingTurnRef:d,progressSequenceByTurnRef:g,taskStateRef:V}){const G={runtimeProvider:k,selectedProject:A,updateTaskState:M,applyLocalCoreThreadDetail:F,clearReplyTimeout:L,refreshSessionsForProject:$,setBridgeError:P,setMessages:u,setPendingPermissionRequest:N,setTyping:W,holdBlankComposerRef:x,nextMessageOrderRef:R,pendingTurnRef:d,progressSequenceByTurnRef:g,taskStateRef:V},re={setActiveRunId:b,setActiveSessionAgentType:z,setActiveAgentMode:D,setActiveSessionId:B,setActiveSessionKey:I,setActiveSessionName:U},ae={setDeleteTarget:_,setPendingSessionAction:H,setRenameDraft:p,setRenameTarget:O},q={holdBlankComposerRef:x,lastSessionByProjectRef:T,nextMessageOrderRef:R,pendingTurnRef:d,progressSequenceByTurnRef:g,taskStateRef:V},se={setBridgeError:P,setMessages:u,setPendingPermissionRequest:N,setTyping:W},{handleSend:oe,handleStopTask:Q}=ca({activeRunId:e,activeThreadId:r,activeBridgeSessionKey:s,availableKnowledgeBases:n,brandingNewThreadLabel:i,draft:c,loadActiveThread:f,selectedKnowledgeBaseIds:v,activeAgentMode:h,taskState:y,armReplyTimeout:K,reserveNextMessageOrder:C,settlePreviewMessages:a,setDraft:w,setSending:J,...G,...re,...se,...q}),{handleCreateNew:me,handleDeleteSession:le,handleRenameSession:ne,openRenameModal:ie}=ua({activeThreadId:r,brandingNewThreadLabel:i,deleteTarget:l,renameDraft:m,renameTarget:j,searchParams:S,selectedKnowledgeBaseIds:v,activeAgentMode:h,setSearchParams:E,...G,...re,...ae,...se});return{handleCreateNew:me,handleDeleteSession:le,handleRenameSession:ne,handleSend:oe,handleStopTask:Q,openRenameModal:ie}}function pa({activeThreadId:e,brandingReplyTimeoutLabel:r,setSelectedKnowledgeBaseIds:s,setActiveRunId:n,setActiveSessionAgentType:i,setActiveAgentMode:l,setActiveSessionId:c,setActiveSessionKey:f,setActiveSessionName:m,setBridgeError:j,setSelectedProject:k,setThreadGroups:S}){const[v,h]=o.useState([]),[A,y]=o.useState(null),[M,F]=o.useState(!1),[K,L]=o.useState("idle"),$=o.useRef(null),C=o.useRef("reply"),a=o.useRef({}),b=o.useRef(0),z=o.useRef(null),D=o.useRef(!1),B=o.useRef({}),I=o.useRef("idle"),U=o.useRef(""),P=o.useMemo(()=>Fe(v),[v]),_=Nr(K),w=Cr(K),u=vr(K,M);o.useEffect(()=>{U.current=e},[e]);const N=o.useCallback((d,g="unspecified")=>{const V=I.current;I.current=d,L(d),V!==d&&console.info("[desktop-chat] task_state",{from:V,to:d,reason:g,threadId:U.current})},[]),H=o.useCallback(()=>{$.current&&(window.clearTimeout($.current),$.current=null)},[]),p=o.useCallback((d="reply")=>{H(),C.current=d,$.current=window.setTimeout(()=>{F(!1),z.current=null,y(null),N("idle","reply-timeout"),j(d==="permission_continue"?r:"Agent did not respond in time. Check AgentDock runtime logs or adjust the model/provider.")},ur)},[r,H,j,N]),O=o.useCallback(()=>{h(d=>d.map(g=>g.actionStatus||g.actionPending?{...g,actionPending:!1,actionStatus:void 0}:g))},[]),E=o.useCallback(d=>{h(g=>xr(g,d))},[]),J=o.useCallback(()=>{const d=b.current;return b.current+=1,d},[]),W=o.useCallback(d=>{const g=z.current;if(g&&d&&g.sessionKey===d){const V=g.userOrder+1;b.current<V&&(b.current=V)}return J()},[J]),x=o.useCallback(d=>{const g=d||crypto.randomUUID(),V=(B.current[g]||0)+1;return B.current[g]=V,`${g}-progress-${V}`},[]),T=o.useCallback(d=>{h(g=>hr(g,d))},[]);return{applyLocalCoreThreadDetail:o.useCallback(d=>{a.current[d.workspaceId]=d.id,k(d.workspaceId),c(d.id),f(d.bridgeSessionKey||""),m(d.title),i(d.agentType||""),l(d.agentMode||"default"),n(d.runId||""),s(d.selectedKnowledgeBaseIds||[]),y(d.pendingPermissionRequest||null),S(V=>yr(V,d.workspaceId,qe(d))),D.current=!1,B.current={};const g=fr(d.messages||[]);z.current=null,b.current=g.reduce((V,G)=>Math.max(V,G.order+1),0),h(Fe(g))},[n,l,i,c,f,m,s,k,S,y]),armReplyTimeout:p,clearActionStatuses:O,clearReplyTimeout:H,holdBlankComposerRef:D,lastSessionByProjectRef:a,messages:v,nextMessageOrderRef:b,pendingPermissionRequest:A,finalizeTurnMessages:T,nextProgressMessageId:x,pendingTurnRef:z,progressSequenceByTurnRef:B,renderedMessages:P,reserveAssistantMessageOrder:W,reserveNextMessageOrder:J,setMessages:h,setPendingPermissionRequest:y,settlePreviewMessages:E,setTyping:F,taskHint:u,taskInputLocked:w,taskRunning:_,taskState:K,taskStateRef:I,typing:M,updateTaskState:N}}function xa(){const[e,r]=It(),[s,n]=o.useState([]),[i,l]=o.useState(""),[c,f]=o.useState([]),[m,j]=o.useState(""),[k,S]=o.useState(""),[v,h]=o.useState(""),[A,y]=o.useState(""),[M,F]=o.useState("default"),[K,L]=o.useState(""),[$,C]=o.useState(""),[a,b]=o.useState(""),[z,D]=o.useState([]),[B,I]=o.useState([]),[U,P]=o.useState(null),[_,w]=o.useState(""),[u,N]=o.useState(null),[H,p]=o.useState(null),[O,E]=o.useState(null),[J,W]=o.useState(!1),[x,T]=o.useState(!1),[R,d]=o.useState(""),g=o.useRef(0),V=o.useRef(null),G=e.get("project")||"",re=e.get("session")||"",ae=at(),{applyLocalCoreThreadDetail:q,armReplyTimeout:se,clearActionStatuses:oe,clearReplyTimeout:Q,finalizeTurnMessages:me,holdBlankComposerRef:le,lastSessionByProjectRef:ne,nextMessageOrderRef:ie,nextProgressMessageId:Ne,pendingPermissionRequest:ee,pendingTurnRef:pe,progressSequenceByTurnRef:xe,renderedMessages:Ie,reserveAssistantMessageOrder:st,reserveNextMessageOrder:Pe,setMessages:Ce,setPendingPermissionRequest:Se,settlePreviewMessages:Te,setTyping:be,taskHint:nt,taskInputLocked:it,taskRunning:ot,taskState:$e,taskStateRef:De,typing:lt,updateTaskState:ge}=pa({activeThreadId:m,brandingReplyTimeoutLabel:ae.replyTimeoutLabel,setSelectedKnowledgeBaseIds:I,setActiveRunId:L,setActiveSessionAgentType:y,setActiveAgentMode:F,setActiveSessionId:j,setActiveSessionKey:S,setActiveSessionName:h,setBridgeError:d,setSelectedProject:l,setThreadGroups:f}),{loading:dt,refreshRuntime:ct,runtime:we,runtimeProvider:de,serviceRunning:Be,showSessionKey:ut,transportReady:mt}=qr({requestedProject:G,selectedProject:i,setSelectedProject:l,clearReplyTimeout:Q,updateTaskState:ge,setTyping:be}),{filteredThreadGroups:pt,loadActiveThread:ke,refreshThreadsForWorkspace:ye}=ta({activeThreadId:m,requestedWorkspaceId:G,requestedThreadId:re,runtimeDefaultWorkspaceId:we==null?void 0:we.settings.defaultProject,runtimeProvider:de,searchParams:e,selectedWorkspaceId:i,serviceRunning:Be,workspaceIds:s,threadGroups:c,threadSearch:a,setSelectedKnowledgeBaseIds:I,setActiveRunId:L,setActiveSessionAgentType:y,setActiveAgentMode:F,setActiveSessionId:j,setActiveSessionKey:S,setActiveSessionName:h,setBridgeError:d,setMessages:Ce,setPendingPermissionRequest:Se,setProjects:n,setSearchParams:r,setSelectedProject:l,setThreadGroups:f,setTyping:be,applyLocalCoreThreadDetail:q,clearReplyTimeout:Q,updateTaskState:ge,holdBlankComposerRef:le,lastSessionByProjectRef:ne,nextMessageOrderRef:ie,pendingTurnRef:pe,progressSequenceByTurnRef:xe});o.useEffect(()=>{var Z;(Z=V.current)==null||Z.scrollIntoView({behavior:"smooth"})},[Ie,lt]);const Ue=o.useCallback(async()=>{try{const Z=await Pt();D(Z.bases||[])}catch{D([])}},[de]);o.useEffect(()=>{Ue()},[Ue]);const xt=o.useCallback(async Z=>{const ce=Array.from(new Set(Z.map(ue=>String(ue||"").trim()).filter(Boolean))),te=g.current+1;if(g.current=te,I(ce),!(!i||!m))try{const ue=de==="local_core"?(await ze(m,ce)).knowledgeBaseIds:await Yt(i,m,ce);g.current===te&&I(ue)}catch(ue){g.current===te&&d(ue instanceof Error?ue.message:"Failed to save selected knowledge bases.")}},[m,de,i,d]),ht=o.useCallback(async Z=>{const ce=["default","bypassPermissions"].includes(Z)?Z:"default";if(F(ce),!(!i||!m)){T(!0),d("");try{const te=await Ae(m,ce);q(te),await ye(i)}catch(te){d(te instanceof Error?te.message:"Failed to save permission mode."),await ke(i,m).catch(()=>null)}finally{T(!1)}}},[m,q,ke,ye,i]),{handleBridgeAction:ft}=da({activeAgentType:A,activeThreadId:m,activeRunId:K,activeBridgeSessionKey:k,runtimeProvider:de,selectedWorkspaceId:i,clearActionStatuses:oe,clearReplyTimeout:Q,finalizeTurnMessages:me,nextProgressMessageId:Ne,refreshThreadsForWorkspace:ye,reserveAssistantMessageOrder:st,reserveNextMessageOrder:Pe,settlePreviewMessages:Te,setActiveRunId:L,setBridgeError:d,setMessages:Ce,setPendingBridgeActionId:E,setTyping:be,setPendingPermissionRequest:Se,updateTaskState:ge,armReplyTimeout:se,pendingTurnRef:pe,progressSequenceByTurnRef:xe,sendAction:Xe,taskStateRef:De}),{handleCreateNew:bt,handleDeleteSession:gt,handleRenameSession:wt,handleSend:kt,handleStopTask:yt,openRenameModal:jt}=ma({activeRunId:K,activeThreadId:m,activeBridgeSessionKey:k,availableKnowledgeBases:z,activeAgentMode:M,brandingNewThreadLabel:ae.newThreadLabel,deleteTarget:u,draft:$,loadActiveThread:ke,renameDraft:_,renameTarget:U,runtimeProvider:de,searchParams:e,selectedKnowledgeBaseIds:B,selectedWorkspaceId:i,taskState:$e,updateTaskState:ge,applyLocalCoreThreadDetail:q,armReplyTimeout:se,clearReplyTimeout:Q,refreshSessionsForProject:ye,reserveNextMessageOrder:Pe,settlePreviewMessages:Te,setActiveRunId:L,setActiveSessionAgentType:y,setActiveAgentMode:F,setActiveSessionId:j,setActiveSessionKey:S,setActiveSessionName:h,setBridgeError:d,setDeleteTarget:N,setDraft:C,setMessages:Ce,setPendingPermissionRequest:Se,setPendingSessionAction:p,setRenameDraft:w,setRenameTarget:P,setSearchParams:r,setSending:W,setTyping:be,holdBlankComposerRef:le,lastSessionByProjectRef:ne,nextMessageOrderRef:ie,pendingTurnRef:pe,progressSequenceByTurnRef:xe,taskStateRef:De});return{activeRunId:K,activeAgentMode:M,activeSessionId:m,activeSessionKey:k,activeSessionName:v,bridgeError:R,branding:ae,deleteTarget:u,draft:$,endRef:V,filteredSessionGroups:pt,handleBridgeAction:ft,handleCreateNew:bt,handleDeleteSession:gt,handleRenameSession:wt,handleSend:kt,handleStopTask:yt,availableKnowledgeBases:z,loadActiveSession:ke,loading:dt,openRenameModal:jt,pendingBridgeActionId:O,permissionModeSaving:x,pendingPermissionRequest:ee,pendingSessionAction:H,projects:s,refreshRuntime:ct,renameDraft:_,renameTarget:U,renderedMessages:Ie,runtime:we,sending:J,selectedKnowledgeBaseIds:B,serviceRunning:Be,sessionSearch:a,selectedProject:i,setDeleteTarget:N,setDraft:C,setSelectedKnowledgeBaseIds:xt,setActiveAgentMode:ht,setRenameDraft:w,setRenameTarget:P,setSelectedProject:l,setSessionSearch:b,showSessionKey:ut,taskHint:nt,taskInputLocked:it,taskRunning:ot,taskState:$e,transportReady:mt}}function za(){const[e,r]=o.useState(!1),{activeRunId:s,activeAgentMode:n,activeSessionId:i,activeSessionKey:l,activeSessionName:c,bridgeError:f,branding:m,deleteTarget:j,draft:k,endRef:S,filteredSessionGroups:v,handleBridgeAction:h,handleCreateNew:A,handleDeleteSession:y,handleRenameSession:M,handleSend:F,handleStopTask:K,availableKnowledgeBases:L,loadActiveSession:$,loading:C,openRenameModal:a,pendingBridgeActionId:b,permissionModeSaving:z,pendingPermissionRequest:D,pendingSessionAction:B,projects:I,refreshRuntime:U,renameDraft:P,renameTarget:_,renderedMessages:w,runtime:u,sending:N,selectedKnowledgeBaseIds:H,serviceRunning:p,sessionSearch:O,selectedProject:E,setDeleteTarget:J,setDraft:W,setActiveAgentMode:x,setSelectedKnowledgeBaseIds:T,setRenameDraft:R,setRenameTarget:d,setSelectedProject:g,setSessionSearch:V,showSessionKey:G,taskHint:re,taskInputLocked:ae,taskRunning:q,taskState:se,transportReady:oe}=xa(),Q=o.useMemo(()=>Or(v,E),[v,E]),me=o.useMemo(()=>Er(I,E),[I,E]),le=o.useMemo(()=>Rr(Q),[Q]),ne=o.useMemo(()=>rt(H,L),[L,H]),ie=Fr(D),Ne=(u==null?void 0:u.phase)==="starting";return C?t.jsx("div",{className:"flex h-64 items-center justify-center text-sm text-slate-500 animate-pulse",children:"正在加载桌面对话…"}):t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"relative h-full min-h-0 overflow-hidden border-slate-200/80 bg-[#f5f5f7] animate-fade-in dark:border-white/[0.06] dark:bg-[#0b0d10] md:rounded-[24px] md:border",children:t.jsxs("div",{className:"grid h-full min-h-0 grid-cols-1 md:grid-cols-[288px_minmax(0,1fr)]",children:[t.jsx(Gr,{activeSessionId:i,branding:m,filteredSessionGroups:Q,hasVisibleSessions:le,isRuntimeStarting:Ne,loading:C,mobileSessionsOpen:e,projects:I,runtime:u,selectedProject:E,serviceRunning:p,sessionSearch:O,showSessionKey:G,visibleProjects:me,onCreateNew:()=>void A(),onLoadActiveSession:$,onOpenRenameModal:a,onRefreshRuntime:()=>void U(),setDeleteTarget:J,setMobileSessionsOpen:r,setSelectedProject:g,setSessionSearch:V}),t.jsxs("section",{className:"flex min-h-0 flex-col bg-white dark:bg-[#0b0d10]",children:[t.jsxs("div",{className:"border-b border-slate-200/80 px-4 py-3 dark:border-white/[0.06] sm:px-6 sm:py-4",children:[t.jsxs("div",{className:"flex items-start gap-3",children:[t.jsx(X,{size:"sm",variant:"secondary",onClick:()=>r(!0),className:"mt-0.5 h-9 w-9 shrink-0 rounded-xl px-0 md:hidden","aria-label":"Open sessions",children:t.jsx(ir,{size:16})}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("p",{className:"text-[11px] font-medium tracking-[0.16em] text-slate-400 dark:text-slate-500",children:"当前会话"}),t.jsx("h2",{className:"mt-1 truncate text-[1.75rem] font-semibold leading-tight text-slate-900 dark:text-white sm:mt-2 sm:text-[1.95rem] sm:leading-none","data-testid":"desktop-chat-active-title",children:c||m.activeConversationFallback})]})]}),t.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2 text-xs text-slate-500 dark:text-slate-400",children:[E?t.jsx("span",{className:"inline-flex items-center rounded-full bg-slate-100 px-2.5 py-1 text-[11px] text-slate-600 dark:bg-white/[0.05] dark:text-slate-300",children:E}):null,t.jsx("span",{className:"inline-flex items-center gap-1 rounded-full bg-slate-100 px-2.5 py-1 text-[10px] uppercase tracking-[0.18em] text-slate-500 dark:bg-white/[0.05] dark:text-slate-400",children:gr(u==null?void 0:u.phase)}),oe?t.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-primary/10 px-2.5 py-1 text-primary dark:text-primary",children:[t.jsx(ve,{size:6,className:"fill-current"})," ",m.runtimeOnlineLabel]}):t.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-slate-100 px-2.5 py-1 text-slate-500 dark:bg-white/[0.05] dark:text-slate-400",children:[t.jsx(Zt,{size:12})," ",m.runtimeOfflineLabel]}),G&&l?t.jsx("span",{className:"truncate text-[11px] text-slate-400 dark:text-slate-500",children:l}):null]})]}),t.jsxs("div",{className:"flex-1 overflow-y-auto px-3 py-4 [scrollbar-gutter:stable] sm:px-6 sm:py-5",children:[w.length===0?t.jsx("div",{className:"flex h-full min-h-[18rem] items-center justify-center",children:t.jsxs("div",{className:"w-full max-w-2xl rounded-[24px] border border-slate-200 bg-[#fbfbfd] px-5 py-8 text-center dark:border-white/[0.06] dark:bg-white/[0.03] sm:px-8 sm:py-10",children:[t.jsx("div",{className:"mx-auto flex h-12 w-12 items-center justify-center rounded-full bg-primary/10 text-primary",children:t.jsx(Qe,{size:22})}),t.jsx("h3",{className:"mt-4 text-lg font-semibold text-slate-900 dark:text-white sm:text-xl",children:"开始一段新的桌面对话"}),t.jsx("p",{className:"mx-auto mt-3 max-w-xl text-sm leading-6 text-slate-500 dark:text-slate-400",children:E?`当前项目是 ${E}。直接提问即可创建会话并开始对话。`:"先在左侧选择项目,然后直接输入你的问题。"}),t.jsx("div",{className:"mt-4 flex flex-wrap justify-center gap-2",children:ne.length>0?ne.map(ee=>t.jsx("span",{className:"rounded-full bg-primary/10 px-3 py-1 text-xs text-primary dark:bg-primary/10 dark:text-primary",children:ee.name},ee.id)):t.jsx("span",{className:"rounded-full bg-slate-100 px-3 py-1 text-xs text-slate-500 dark:bg-white/[0.05] dark:text-slate-400",children:"当前未限制知识库范围"})})]})}):t.jsx("div",{className:"mx-auto w-full max-w-4xl space-y-5",children:w.map(ee=>Hr(ee,ie)?t.jsx(Yr,{message:ee,pendingBridgeActionId:b,onAction:(pe,xe)=>void h(pe,xe)},ee.id):null)}),re?t.jsxs("div",{className:"mt-5 flex items-center gap-2 text-sm text-slate-400","data-testid":"desktop-chat-task-hint",children:[t.jsx(ve,{size:8,className:"fill-current animate-pulse"})," ",re]}):null,f?t.jsx("div",{className:"mt-4 rounded-2xl border border-amber-400/20 bg-amber-50 px-3 py-2 text-sm text-amber-800 dark:bg-amber-500/10 dark:text-amber-100","data-testid":"desktop-chat-bridge-error",children:f}):null,t.jsx("div",{ref:S})]}),t.jsx(Qr,{activeRunId:s,activeAgentMode:n,activeSessionKey:l,availableKnowledgeBases:L,branding:m,composerPermissionCard:ie,draft:k,pendingBridgeActionId:b,permissionModeSaving:z,selectedKnowledgeBaseIds:H,selectedProject:E,sending:N,serviceRunning:p,taskInputLocked:ae,taskRunning:q,taskState:se,transportReady:oe,onBridgeAction:h,onSend:F,onStopTask:K,setActiveAgentMode:x,setDraft:W,setSelectedKnowledgeBaseIds:T})]})]})}),t.jsx(Zr,{deleteTarget:j,pendingSessionAction:B,renameDraft:P,renameTarget:_,onDeleteSession:y,onRenameSession:M,setDeleteTarget:J,setRenameDraft:R,setRenameTarget:d})]})}export{za as default};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{c as ft,
|
|
1
|
+
import{c as ft,A as D,j as t,B as T,F as Wt,I as L,S as Kt,y as Xt,r as S}from"./index-on-scaWG.js";import{M as it}from"./Modal-BYTZpyD2.js";import{S as Z}from"./Select-CybeCWXZ.js";import{E as Oe}from"./EmptyState-DUDyUsLL.js";import{S as gt,a as Pe,P as qt}from"./Page-B0lex3w0.js";import{c as Jt,d as Zt,e as es,t as ts,f as Ne,h as ss,i as as,j as ns,k as rs,m as os,n as is,p as lt}from"./desktop-D88Gquih.js";import{c as pt,D as ze,d as ls,e as De,f as Me,g as Ae,h as cs,j as ct,k as dt,l as ds}from"./desktop-JQkhNOF4.js";import{T as Te}from"./trash-2-CANqI4Db.js";import{P as Ce}from"./plus-_5sDk2H8.js";import{B as ms}from"./bot-DeqZUVXX.js";import{P as us,S as we}from"./save-Bn9HUt7T.js";import"./index-DvKeLUQ8.js";import"./chevron-down-BOhwopXd.js";import"./check-BNBksd9W.js";/**
|
|
2
2
|
* @license lucide-react v0.487.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{a3 as l,s as g,a4 as c,a5 as u,a6 as h,a7 as C,a8 as v,a9 as k,aa as p,ab as w,ac as S,ad as P,ae as m,af as L,ag as y,ah as D,ai as R,aj as f,ak as b,al as G,am as Q,an as E,ao as M,ap as B,aq as A,ar as F,as as I,at as W,au as K,av as x,aw as T,ax as $,ay as j,az as U,aA as z,aB as q,aC as _,aD as H,aE as J,aF as N,p as i,m as O,aG as V,aH as X,aI as Y,aJ as Z,aK as ee,aL as te,aM as ae,aN as se,i as ne}from"./index-on-scaWG.js";function n(){if(!window.desktop)throw new Error("Desktop APIs are unavailable in the browser build");return window.desktop}const re={getRuntimeStatus:()=>n().getRuntimeStatus(),startService:()=>n().startService(),stopService:()=>n().stopService(),restartService:()=>n().restartService(),getLogs:e=>n().getLogs(e),listInstalledAgentRuntimes:()=>_().then(e=>e.runtimes),refreshInstalledAgentRuntimes:()=>q().then(e=>e.runtimes),readConfigFile:()=>n().readConfigFile(),saveRawConfigFile:e=>n().saveRawConfigFile(e),saveStructuredConfigFile:e=>n().saveStructuredConfigFile(e),listModelProviders:()=>z(),createModelProvider:e=>U(e),updateModelProvider:(e,t)=>j(e,t),deleteModelProvider:e=>$(e),getThreadKnowledgeBases:(e,t)=>n().getThreadKnowledgeBases(e,t),updateThreadKnowledgeBases:(e,t,a)=>n().updateThreadKnowledgeBases(e,t,a),deleteThreadKnowledgeBases:(e,t)=>n().deleteThreadKnowledgeBases(e,t),saveSettings:e=>n().saveSettings(e),getCapabilitySnapshot:()=>T(),getPluginDiagnostics:()=>x(),listDiagnosticErrors:()=>K().then(e=>e.errors),runDiagnosticsDoctor:()=>W(),runDeploymentDiagnostics:()=>I(),listChannelGateways:e=>F(e).then(t=>t.gateways),getChannelGatewayStatus:(e,t,a)=>A(e,t,a),testChannelConnection:(e,t,a)=>B(e,t,a),enableChannelGateway:(e,t,a)=>M(e,t,a),disableChannelGateway:(e,t,a)=>E(e,t,a),listChannelPendingPairings:(e,t)=>Q(e,t).then(a=>a.pairings),approveChannelPairing:(e,t)=>G(e,t),rejectChannelPairing:(e,t)=>b(e,t),listChannelAuthorizedUsers:(e,t)=>f(e,t).then(a=>a.users),getChannelQrCode:(e,t,a)=>R(e,t,a),checkChannelQrCodeStatus:(e,t,a,r)=>D(e,t,a,r),getWeixinQrCode:(e,t)=>y(e,t),checkWeixinQrCodeStatus:(e,t,a)=>L(e,t,a),getLarkQrCode:(e,t)=>m(e,t),checkLarkQrCodeStatus:(e,t,a)=>P(e,t,a),listLarkGateways:()=>S().then(e=>e.gateways),getLarkGatewayStatus:(e,t)=>w(e,t),testLarkConnection:(e,t)=>p(e,t),enableLarkGateway:(e,t)=>k(e,t),disableLarkGateway:(e,t)=>v(e,t),listLarkPendingPairings:e=>C(e).then(t=>t.pairings),approveLarkPairing:e=>h(e),rejectLarkPairing:e=>u(e),listLarkAuthorizedUsers:e=>c(e).then(t=>t.users),probeWorkspaceStreaming:e=>n().probeWorkspaceStreaming(e),onRuntimeEvent:e=>n().onRuntimeEvent(e),onRuntimeDetectionEvent:e=>g(t=>{(t.type.startsWith("runtime.detect.")||t.type==="runtime.status.changed")&&e(t)}),onBridgeEvent:e=>l(e)},o={getRuntimeStatus:()=>se(),startService:()=>ae(),stopService:()=>te(),restartService:()=>ee(),getLogs:e=>Z(e),listInstalledAgentRuntimes:()=>_().then(e=>e.runtimes),refreshInstalledAgentRuntimes:()=>q().then(e=>e.runtimes),readConfigFile:()=>Y(),saveRawConfigFile:e=>X(e),saveStructuredConfigFile:e=>V(e),listModelProviders:()=>z(),createModelProvider:e=>U(e),updateModelProvider:(e,t)=>j(e,t),deleteModelProvider:e=>$(e),getThreadKnowledgeBases:(e,t)=>O(t).then(a=>a.selectedKnowledgeBaseIds||[]),updateThreadKnowledgeBases:(e,t,a)=>i(t,a).then(r=>r.knowledgeBaseIds),deleteThreadKnowledgeBases:(e,t)=>i(t,[]).then(()=>({deleted:!0})),saveSettings:e=>N(e),getCapabilitySnapshot:()=>T(),getPluginDiagnostics:()=>x(),listDiagnosticErrors:()=>K().then(e=>e.errors),runDiagnosticsDoctor:()=>W(),runDeploymentDiagnostics:()=>I(),listChannelGateways:e=>F(e).then(t=>t.gateways),getChannelGatewayStatus:(e,t,a)=>A(e,t,a),testChannelConnection:(e,t,a)=>B(e,t,a),enableChannelGateway:(e,t,a)=>M(e,t,a),disableChannelGateway:(e,t,a)=>E(e,t,a),listChannelPendingPairings:(e,t)=>Q(e,t).then(a=>a.pairings),approveChannelPairing:(e,t)=>G(e,t),rejectChannelPairing:(e,t)=>b(e,t),listChannelAuthorizedUsers:(e,t)=>f(e,t).then(a=>a.users),getChannelQrCode:(e,t,a)=>R(e,t,a),checkChannelQrCodeStatus:(e,t,a,r)=>D(e,t,a,r),getWeixinQrCode:(e,t)=>y(e,t),checkWeixinQrCodeStatus:(e,t,a)=>L(e,t,a),getLarkQrCode:(e,t)=>m(e,t),checkLarkQrCodeStatus:(e,t,a)=>P(e,t,a),listLarkGateways:()=>S().then(e=>e.gateways),getLarkGatewayStatus:(e,t)=>w(e,t),testLarkConnection:(e,t)=>p(e,t),enableLarkGateway:(e,t)=>k(e,t),disableLarkGateway:(e,t)=>v(e,t),listLarkPendingPairings:e=>C(e).then(t=>t.pairings),approveLarkPairing:e=>h(e),rejectLarkPairing:e=>u(e),listLarkAuthorizedUsers:e=>c(e).then(t=>t.users),probeWorkspaceStreaming:e=>J(e),onRuntimeEvent:e=>H(e),onRuntimeDetectionEvent:e=>g(t=>{(t.type.startsWith("runtime.detect.")||t.type==="runtime.status.changed")&&e(t)}),onBridgeEvent:e=>l(e)};let d=null;function ie(e){return e==="electron"&&window.desktop?re:o}function s(){const e=d||ie(ne());if(!e)throw new Error("Managed desktop APIs are unavailable in this build");return d=e,e}const de=()=>s().getRuntimeStatus(),le=()=>s().startService(),ge=()=>s().listInstalledAgentRuntimes(),ce=()=>s().refreshInstalledAgentRuntimes(),ue=()=>s().readConfigFile(),he=e=>s().saveStructuredConfigFile(e),Ce=()=>s().listModelProviders(),ve=e=>s().createModelProvider(e),ke=(e,t)=>s().updateModelProvider(e,t),pe=e=>s().deleteModelProvider(e),we=(e,t,a)=>s().updateThreadKnowledgeBases(e,t,a),Se=e=>s().saveSettings(e),Pe=()=>s().getPluginDiagnostics(),me=()=>s().listDiagnosticErrors(),Le=()=>s().runDiagnosticsDoctor(),ye=(e,t)=>s().getWeixinQrCode(e,t),De=(e,t,a)=>s().checkWeixinQrCodeStatus(e,t,a),Re=(e,t)=>s().getLarkQrCode(e,t),fe=(e,t,a)=>s().checkLarkQrCodeStatus(e,t,a),be=(e,t)=>s().testLarkConnection(e,t),Ge=(e,t)=>s().enableLarkGateway(e,t),Qe=e=>s().onRuntimeEvent(e),Ee=e=>s().onRuntimeDetectionEvent(e),Me=e=>s().onBridgeEvent(e);export{Ee as a,Me as b,ue as c,Ce as d,Ge as e,he as f,de as g,ve as h,ke as i,pe as j,ye as k,ge as l,Re as m,De as n,Qe as o,fe as p,Pe as q,ce as r,le as s,be as t,we as u,me as v,Se as w,Le as x};
|