@kafca/agentdock 0.1.16 → 0.1.17
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/dist/renderer/assets/{Badge-O6YyBOXO.js → Badge-DXt7cKFc.js} +1 -1
- package/dist/renderer/assets/{Chat-Bb42Xu99.js → Chat-KI72IiDR.js} +2 -2
- package/dist/renderer/assets/{ChatMarkdown-CKIl8nVw.js → ChatMarkdown-BJUbKIWx.js} +3 -3
- package/dist/renderer/assets/Config-Cy7Bghwk.js +16 -0
- package/dist/renderer/assets/CronList-CDLl1ZzX.js +1 -0
- package/dist/renderer/assets/{Dashboard-DIxtJDEV.js → Dashboard-GInRzjlA.js} +2 -2
- package/dist/renderer/assets/{EmptyState-Ce5baC0x.js → EmptyState-Blxa5wT6.js} +1 -1
- package/dist/renderer/assets/{KnowledgeDetail-DKjqGzjI.js → KnowledgeDetail-DG5ACw7Z.js} +2 -2
- package/dist/renderer/assets/{KnowledgeHome-CsYBKv3L.js → KnowledgeHome-Co82W8Gm.js} +3 -3
- package/dist/renderer/assets/Logs-CX-AZ4l9.js +1 -0
- package/dist/renderer/assets/{Modal-JbmTZbCL.js → Modal-BfZUw-Vc.js} +3 -3
- package/dist/renderer/assets/{Page-854R0NMM.js → Page-Bj33TMID.js} +1 -1
- package/dist/renderer/assets/ProjectDetail-Br1_6OXA.js +11 -0
- package/dist/renderer/assets/{ProjectList-mJJeoUcP.js → ProjectList-DtfMApqf.js} +1 -1
- package/dist/renderer/assets/Select-zyP8Fyv-.js +11 -0
- package/dist/renderer/assets/SessionChat-DaU2m8t8.js +1 -0
- package/dist/renderer/assets/SessionList-C5Qm9meA.js +1 -0
- package/dist/renderer/assets/ThreadChat-mXwKVnjn.js +23 -0
- package/dist/renderer/assets/{Workspace-B_sQxTj-.js → Workspace-D33Uehab.js} +2 -2
- package/dist/renderer/assets/{arrow-left-mguKZKTu.js → arrow-left-CHaLGNIO.js} +1 -1
- package/dist/renderer/assets/{book-open-3Awj2zba.js → book-open-ErTuahLF.js} +1 -1
- package/dist/renderer/assets/check-DdHpkvai.js +6 -0
- package/dist/renderer/assets/{circle-BWSc4-qr.js → circle-jGjPqcBV.js} +1 -1
- package/dist/renderer/assets/desktop-DTOHffl0.js +1 -0
- package/dist/renderer/assets/en-CKhCF6St.js +1 -0
- package/dist/renderer/assets/es-C8UBPhxM.js +1 -0
- package/dist/renderer/assets/{funnel-DE2QCcoy.js → funnel-SfDR1vLQ.js} +1 -1
- package/dist/renderer/assets/{heart-B6xi7jGt.js → heart-uLLDdrUQ.js} +1 -1
- package/dist/renderer/assets/index-CTOb2Qbz.js +41 -0
- package/dist/renderer/assets/index-CVrF_DwQ.css +11 -0
- package/dist/renderer/assets/index-DbqC4-hV.js +177 -0
- package/dist/renderer/assets/ja-ChF4vbBL.js +1 -0
- package/dist/renderer/assets/{pencil-BD6oAfUg.js → pencil-CmkSVcVi.js} +1 -1
- package/dist/renderer/assets/{play-C9Ue_X4n.js → play-D4sbHoXa.js} +1 -1
- package/dist/renderer/assets/{plug-CIaRVhae.js → plug-CTnt9Fqi.js} +1 -1
- package/dist/renderer/assets/{plus-BWHFEPZn.js → plus-C88o4pqU.js} +1 -1
- package/dist/renderer/assets/projects-CxhcfuFo.js +1 -0
- package/dist/renderer/assets/{save-DsSaJ2pw.js → save-D8aBjpdR.js} +1 -1
- package/dist/renderer/assets/{search-Ci4i20HH.js → search-CR2u_AT7.js} +1 -1
- package/dist/renderer/assets/{server-07G4ybtv.js → server-DD_yCA3I.js} +1 -1
- package/dist/renderer/assets/{session-utils-D9njomRn.js → session-utils-DzI7rMtW.js} +1 -1
- package/dist/renderer/assets/{sessions-C4c2fLQB.js → sessions-qYxQCCGN.js} +1 -1
- package/dist/renderer/assets/{shield-check-DjJz3hYk.js → shield-check-Du9pUUbm.js} +1 -1
- package/dist/renderer/assets/{trash-2-C5_ZLIsu.js → trash-2-DwMqg4qR.js} +1 -1
- package/dist/renderer/assets/{user-DHBITt1w.js → user-cFDevW5m.js} +1 -1
- package/dist/renderer/assets/{wifi-off-DuwKaMRJ.js → wifi-off-opRy17vp.js} +1 -1
- package/dist/renderer/assets/zh-Dz5FLTBV.js +1 -0
- package/dist/renderer/assets/zh-TW-BtRwreY_.js +1 -0
- package/dist/renderer/index.html +2 -2
- package/dist-electron/electron/local-core-refactor.test.js +150 -0
- package/dist-electron/services/local-ai-core/src/acp/local-core-acp-backend.js +3 -0
- package/dist-electron/services/local-ai-core/src/acp/local-core-acp-turn-coordinator.js +42 -5
- package/dist-electron/services/local-ai-core/src/acp/workspace-acp-permissions.js +19 -1
- package/dist-electron/src/pages/Threads/thread-chat-model.js +3 -3
- package/dist-electron/src/pages/Threads/thread-chat-permission.js +4 -0
- package/dist-electron/src/pages/Threads/thread-chat-permission.test.js +35 -0
- package/package.json +1 -1
- package/dist/renderer/assets/Config-U1HHZNv-.js +0 -16
- package/dist/renderer/assets/CronList-Qfok-TFN.js +0 -1
- package/dist/renderer/assets/Logs-BV93l6f2.js +0 -1
- package/dist/renderer/assets/ProjectDetail-Ct7yASjV.js +0 -11
- package/dist/renderer/assets/SessionChat-CClPXCjv.js +0 -1
- package/dist/renderer/assets/SessionList-Cxilghws.js +0 -1
- package/dist/renderer/assets/ThreadChat-BUFr0IbT.js +0 -23
- package/dist/renderer/assets/index-B2JL40NF.js +0 -232
- package/dist/renderer/assets/index-CJZeKEpW.css +0 -11
- package/dist/renderer/assets/projects-DCdaAlgs.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as t,
|
|
1
|
+
import{j as t,w as a}from"./index-DbqC4-hV.js";const n={default:"border-transparent bg-primary text-primary-foreground shadow hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",success:"border-transparent bg-primary/10 text-primary dark:bg-primary/15 dark:text-primary",warning:"border-transparent bg-amber-100 text-amber-700 dark:bg-amber-500/15 dark:text-amber-200",danger:"border-transparent bg-destructive/10 text-destructive dark:bg-destructive/20 dark:text-red-200",destructive:"border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80",outline:"text-foreground",info:"border-transparent bg-blue-100 text-blue-700 dark:bg-blue-500/15 dark:text-blue-200"};function s({children:r,variant:e="default"}){return t.jsx("span",{className:a("inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",n[e]),children:r})}export{s as B};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{u as ze,
|
|
2
|
-
`)}function as(a){return a.filter(c=>c.role!=="user").length}function ns(a,c){var p;return(p=a.last_message)!=null&&p.content?a.last_message.content.replace(/\n/g," "):c("sessions.noMessages")}function we(a){return(a instanceof Error?a.message:String(a||"")).trim().toLowerCase().includes("no active session found")}function rs(a,c){return(a instanceof Error?a.message:String(a||"")).trim().toLowerCase()?we(a)?c("sessions.sessionUnavailable"):a instanceof Error?a.message:c("sessions.sendFailed"):c("sessions.sendFailed")}function ys(){const{t:a}=ze(),[c,p]=Me(),[se,ke]=r.useState([]),[te,ae]=r.useState({}),[i,G]=r.useState(c.get("project")||""),[j,_]=r.useState([]),[n,h]=r.useState(null),[R,w]=r.useState([]),[J,ne]=r.useState(""),[I,Q]=r.useState(""),[Se,re]=r.useState(!0),[Ne,ie]=r.useState(!1),[Ce,le]=r.useState(!1),[X,oe]=r.useState(!1),[E,P]=r.useState("idle"),[ce,k]=r.useState(""),[T,q]=r.useState(null),[F,Y]=r.useState(""),[z,O]=r.useState(null),[de,H]=r.useState(null),me=r.useRef(null),x=r.useRef({project:"",sessionId:""}),V=r.useRef(null),W=r.useRef(null),b=c.get("project")||"",M=c.get("session")||"",ue=r.useMemo(()=>new Set(Object.values(te)),[te]),S=r.useMemo(()=>{const e=J.trim().toLowerCase();return e?j.filter(t=>He(t,e)):j},[J,j]),D=!!(n&&(n.live||ue.has(n.id))),Ee=!!(i&&D&&I.trim()&&!X&&E!=="sending"&&E!=="activating"&&E!=="polling"),f=r.useCallback((e,t)=>{const l=new URLSearchParams;e&&l.set("project",e),t&&l.set("session",t),p(l,{replace:!0})},[p]),d=r.useCallback((e="idle")=>{V.current&&(window.clearTimeout(V.current),V.current=null),W.current=null,P(e)},[]),xe=r.useCallback(e=>{_(t=>{const l=t.some(o=>o.id===e.id)?t.map(o=>o.id===e.id?{...o,...e}:o):[...t,e];return ve(l)})},[]),fe=r.useCallback(async()=>{re(!0);try{const{projects:e}=await Ke();ke(e||[])}finally{re(!1)}},[]),u=r.useCallback(async e=>{if(!e)return _([]),ae({}),[];ie(!0);try{const{sessions:t,active_keys:l}=await Ue(e),o=ve((t||[]).filter(m=>!es(m.session_key)));return ae(l||{}),x.current.project===e&&_(o),o}finally{ie(!1)}},[]),N=r.useCallback(async(e,t,l)=>{if(!e||!t)return h(null),w([]),null;l!=null&&l.silent||le(!0);try{const o=await $e(e,t,200);return x.current.project!==e||x.current.sessionId!==t||(xe(o),h({id:o.id,project:e,sessionKey:o.session_key,name:o.name||v(o),live:o.live,isDraft:!1,detail:o}),w(ss(o.history)),k("")),o}catch(o){return x.current.project===e&&x.current.sessionId===t&&k(o instanceof Error?o.message:a("sessions.loadFailed")),null}finally{l!=null&&l.silent||le(!1)}},[xe,a]),Z=r.useCallback(e=>{W.current=e,V.current=window.setTimeout(async()=>{const t=W.current;if(!t)return;if(Date.now()-t.startedAt>=Ze){d("timed_out"),k(a("sessions.pollTimeout")),await u(t.project);return}const l=await N(t.project,t.sessionId,{silent:!0});if(!l||!W.current){d(),await u(t.project);return}if(x.current.project!==t.project||x.current.sessionId!==t.sessionId){d();return}const o=ts(l.history),m=as(l.history)>t.assistantCountBefore,g=m&&o===t.lastSignature?t.stableCount+1:0,B={...t,lastSignature:o,stableCount:g};if(m&&g>=2){d(),await u(t.project);return}P("polling"),Z(B)},Ye)},[N,u,d,a]),he=r.useCallback((e,t,l)=>{d(),P("polling"),Z({project:e,sessionId:t,assistantCountBefore:l,stableCount:0,lastSignature:"",startedAt:Date.now()})},[Z,d]),Pe=r.useCallback(async e=>{if(d(),G(e),ne(""),k(""),Q(""),!e){x.current={project:"",sessionId:""},h(null),w([]),_([]),f("");return}x.current={project:e,sessionId:""},h(null),w([]),f(e),await u(e)},[u,d,f]),L=r.useCallback(async e=>{if(e.isDraft||e.live||!e.id)return e;P("activating");try{await qe(e.project,{session_key:e.sessionKey,session_id:e.id}),await u(e.project);const t=await N(e.project,e.id,{silent:!0}),l={...e,live:(t==null?void 0:t.live)??!0,isDraft:!1,detail:t??e.detail,name:(t==null?void 0:t.name)||e.name};return h(l),l}finally{P("idle")}},[N,u]),A=r.useCallback(async(e,t)=>{d(),k(""),x.current={project:e,sessionId:t.id},G(e),f(e,t.id),h({id:t.id,project:e,sessionKey:t.session_key,name:v(t),live:t.live,isDraft:!1,detail:null});const l=await N(e,t.id);l&&!l.live&&await L({id:l.id,project:e,sessionKey:l.session_key,name:l.name||v(l),live:l.live,isDraft:!1,detail:l})},[L,N,d,f]),_e=r.useCallback(async()=>{d(),i&&(await u(i),n!=null&&n.id&&(x.current={project:i,sessionId:n.id},await N(i,n.id)))},[n==null?void 0:n.id,N,u,i,d]),ge=r.useCallback(async()=>{if(!I.trim()||!i)return;if(!D){k(a("sessions.sessionUnavailable"));return}const e=I.trim(),t=`${crypto.randomUUID()}-user`,l={id:t,role:"user",content:e,timestamp:new Date().toISOString()};Q(""),oe(!0),P("sending"),k("");try{const o=n||S[0];if(!o)throw new Error(a("sessions.noAvailableChatTarget"));let m=n&&n.id===o.id?n:{id:o.id,project:i,sessionKey:"session_key"in o?o.session_key:o.sessionKey,name:"session_key"in o?v(o):o.name,live:o.live,isDraft:!1,detail:null};(!n||n.id!==m.id)&&(x.current={project:i,sessionId:m.id},f(i,m.id),h(m)),m=await L(m),w(y=>[...y,l]);try{await be(i,{session_key:m.sessionKey,message:e})}catch(y){if(!we(y)||!m.id)throw y;m=await L({...m,live:!1}),await be(i,{session_key:m.sessionKey,message:e})}const g=m.id;if(!g)throw new Error(a("sessions.createFailed"));const B=R.filter(y=>y.role!=="user").length;x.current={project:i,sessionId:g},h(y=>y&&{...y,id:g,isDraft:!1}),f(i,g),he(i,g,B),await u(i)}catch(o){d(),w(g=>g.filter(B=>B.id!==t));const m=rs(o,a);k(m)}finally{oe(!1)}},[n,D,L,I,S,R,u,i,he,d,a,f]),Re=r.useCallback(async()=>{if(!(!T||!i||!F.trim())){H("rename");try{await Fe(i,T.id,{name:F.trim()});const t=(await u(i)).find(l=>l.id===T.id);t&&(n==null?void 0:n.id)===t.id&&h(l=>l&&{...l,name:v(t)}),q(null),Y("")}finally{H(null)}}},[n==null?void 0:n.id,u,F,T,i]),Ie=r.useCallback(async()=>{if(!(!z||!i)){H("delete");try{await Oe(i,z.id);const e=await u(i);(n==null?void 0:n.id)===z.id&&(d(),x.current={project:i,sessionId:""},h(null),w([]),f(i)),e.length===0&&w([]),O(null)}finally{H(null)}}},[n==null?void 0:n.id,z,u,i,d,f]);r.useEffect(()=>{fe()},[fe]),r.useEffect(()=>{b&&(i&&i===b||G(b))},[b,i]),r.useEffect(()=>{if(!i){_([]);return}x.current.project=i,u(i)},[u,i]),r.useEffect(()=>{!i||M||n!=null&&n.id||S.length===0||A(i,S[0])},[n==null?void 0:n.id,S,A,M,i]),r.useEffect(()=>{if(!b||!M||i!==b)return;const e=j.find(t=>t.id===M);if(!e){j.length>0&&f(b,j[0].id);return}(n==null?void 0:n.id)!==e.id&&A(b,e)},[n==null?void 0:n.id,A,b,M,i,j,f]),r.useEffect(()=>{var e;(e=me.current)==null||e.scrollIntoView({behavior:"smooth"})},[R]),r.useEffect(()=>()=>d(),[d]);const Te=(n==null?void 0:n.name)||a("sessions.activeChat");return s.jsxs("div",{className:"grid min-h-[calc(100vh-8rem)] grid-cols-1 gap-4 xl:grid-cols-[22rem_minmax(0,1fr)] animate-fade-in",children:[s.jsxs(ye,{className:"flex flex-col gap-4 p-4 xl:h-[calc(100vh-8rem)] xl:overflow-hidden",children:[s.jsx("div",{className:"flex items-center gap-3",children:s.jsxs("div",{className:"flex-1",children:[s.jsx("p",{className:"text-xs font-medium uppercase tracking-[0.2em] text-gray-400",children:a("sessions.selectProject")}),s.jsxs("select",{value:i,onChange:e=>void Pe(e.target.value),className:"mt-2 w-full rounded-xl border border-gray-300/90 bg-white/90 px-3 py-2 text-sm text-gray-900 transition-all focus:border-accent focus:outline-none focus:ring-2 focus:ring-accent/45 dark:border-white/[0.1] dark:bg-[rgba(0,0,0,0.45)] dark:text-white",children:[s.jsx("option",{value:"",children:a("sessions.allProjects")}),se.map(e=>s.jsx("option",{value:e.name,children:e.name},e.name))]})]})}),s.jsxs("div",{className:"relative",children:[s.jsx(pe,{value:J,onChange:e=>ne(e.target.value),placeholder:a("common.search"),className:"pl-9","aria-label":a("common.search")}),s.jsx(We,{size:16,className:"pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-gray-400"})]}),s.jsxs("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden",children:[s.jsxs("div",{className:"mb-3 flex items-center justify-between text-xs text-gray-500 dark:text-gray-400",children:[s.jsx("span",{children:a("sessions.historyTitle")}),s.jsx("span",{children:S.length})]}),s.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto space-y-2 pr-1",children:Se?s.jsx("div",{className:"flex h-32 items-center justify-center text-gray-400",children:s.jsx($,{className:"animate-spin",size:18})}):i?Ne&&j.length===0?s.jsx("div",{className:"flex h-32 items-center justify-center text-gray-400",children:s.jsx($,{className:"animate-spin",size:18})}):j.length===0?s.jsx(U,{message:a("sessions.noSessions"),icon:K}):S.length===0?s.jsx(U,{message:a("sessions.noSessions"),icon:K}):S.map(e=>{const t=e.id===(n==null?void 0:n.id);return s.jsxs("div",{className:ee("rounded-2xl border p-3 transition-all",t?"border-accent/45 bg-accent/10 shadow-[0_0_20px_-12px_rgba(139,92,246,0.55)]":"border-gray-200/80 bg-white/70 hover:border-accent/30 dark:border-white/[0.08] dark:bg-white/[0.03]"),children:[s.jsxs("button",{type:"button",onClick:()=>void A(i,e),className:"w-full text-left","data-testid":"web-chat-session-open",children:[s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"truncate text-sm font-medium text-gray-900 dark:text-white",children:v(e)}),e.live||ue.has(e.id)?s.jsx("span",{className:"rounded-full bg-violet-50 px-2 py-0.5 text-[10px] text-violet-600 dark:bg-violet-950/20 dark:text-violet-300",children:"live"}):s.jsx("span",{className:"rounded-full bg-gray-100 px-2 py-0.5 text-[10px] text-gray-400 dark:bg-white/[0.06] dark:text-gray-500",children:"history"})]}),s.jsx("p",{className:"mt-1 truncate text-xs text-gray-500 dark:text-gray-400",children:Ve(e.updated_at||e.created_at,a("sessions.justNow"))})]}),s.jsx("span",{className:"shrink-0 text-[10px] text-gray-400",children:e.history_count})]}),s.jsx("p",{className:"mt-2 line-clamp-2 text-xs text-gray-500 dark:text-gray-400",children:ns(e,a)})]}),s.jsxs("div",{className:"mt-3 flex items-center justify-end gap-1",children:[s.jsx(C,{size:"sm",variant:"ghost",onClick:()=>{q({id:e.id,name:v(e)}),Y(v(e))},"data-testid":"web-chat-session-rename",children:s.jsx(Ge,{size:14})}),s.jsx(C,{size:"sm",variant:"ghost",onClick:()=>O({id:e.id,name:v(e)}),"data-testid":"web-chat-session-delete",children:s.jsx(Je,{size:14})})]})]},e.id)}):s.jsx(U,{message:a("sessions.projectRequired"),icon:K})})]})]}),s.jsxs(ye,{className:"flex min-h-[32rem] flex-col p-0 xl:h-[calc(100vh-8rem)]",children:[s.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-gray-200/80 px-5 py-4 dark:border-white/[0.08]",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("h2",{className:"truncate text-lg font-semibold text-gray-900 dark:text-white",children:Te})}),s.jsx("p",{className:"mt-1 truncate text-sm text-gray-500 dark:text-gray-400",children:n?n.project:a("sessions.sendHint")})]}),s.jsxs(C,{size:"sm",variant:"secondary",onClick:()=>void _e(),"data-testid":"web-chat-refresh",children:[s.jsx(De,{size:14})," ",a("common.refresh")]})]}),s.jsx("div",{className:"flex-1 overflow-y-auto px-5 py-5",children:i?Ce?s.jsx("div",{className:"flex h-full items-center justify-center text-gray-400",children:s.jsx($,{className:"animate-spin",size:22})}):R.length===0?s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsx(U,{message:a(n?"sessions.noMessages":"sessions.sendHint"),icon:K})}):s.jsxs("div",{className:"space-y-5",children:[R.map(e=>{const t=e.role==="user";return s.jsxs("div",{className:ee("flex gap-3",t?"justify-end":"justify-start"),children:[!t&&s.jsx("div",{className:"mt-1 flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-accent/10",children:s.jsx(Qe,{size:16,className:"text-accent"})}),s.jsx("div",{className:ee("max-w-[85%] rounded-2xl px-5 py-3.5 text-sm",t?"bg-accent text-white rounded-br-md":"border border-gray-200 bg-white text-gray-900 shadow-sm dark:border-white/[0.08] dark:bg-[rgba(0,0,0,0.42)] dark:text-gray-100 rounded-bl-md"),children:s.jsx(Ae,{content:e.content,isUser:t})}),t&&s.jsx("div",{className:"mt-1 flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-gray-200 dark:bg-white/[0.08]",children:s.jsx(Xe,{size:16,className:"text-gray-500 dark:text-gray-300"})})]},e.id)}),s.jsx("div",{ref:me})]}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsx(U,{message:a("sessions.emptySelection"),icon:K})})}),s.jsxs("div",{className:"border-t border-gray-200/80 px-5 py-4 dark:border-white/[0.08]",children:[ce&&s.jsx("div",{className:"mb-3 rounded-xl border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-600 dark:border-red-900/40 dark:bg-red-950/20 dark:text-red-300",children:ce}),E==="polling"&&s.jsxs("div",{className:"mb-3 flex items-center gap-2 text-sm text-gray-500 dark:text-gray-400",children:[s.jsx($,{size:14,className:"animate-spin"}),s.jsx("span",{children:a("sessions.waitingForReply")})]}),E==="activating"&&s.jsxs("div",{className:"mb-3 flex items-center gap-2 text-sm text-gray-500 dark:text-gray-400",children:[s.jsx($,{size:14,className:"animate-spin"}),s.jsx("span",{children:a("sessions.preparingChat")})]}),s.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-end",children:[s.jsx("div",{className:"flex-1",children:s.jsx(Le,{value:I,onChange:e=>Q(e.target.value),onKeyDown:e=>{e.key==="Enter"&&!e.shiftKey&&(e.preventDefault(),ge())},rows:3,placeholder:a(i?"sessions.messageInput":"sessions.projectRequired"),disabled:!i||!D||X||E==="polling"||E==="activating","data-testid":"web-chat-input"})}),s.jsxs(C,{onClick:()=>void ge(),disabled:!Ee,loading:X,size:"lg",className:"sm:self-stretch","data-testid":"web-chat-send",children:[s.jsx(Be,{size:16})," ",a("sessions.send")]})]}),!D&&n&&s.jsx("div",{className:"mt-3 rounded-xl border border-gray-200 bg-gray-50 px-4 py-3 text-sm text-gray-500 dark:border-white/[0.08] dark:bg-white/[0.03] dark:text-gray-400",children:a("sessions.notLiveHint")})]})]}),s.jsx(je,{open:!!T,onClose:()=>q(null),title:a("sessions.renameTitle"),children:s.jsxs("div",{className:"space-y-4",children:[s.jsx(pe,{value:F,onChange:e=>Y(e.target.value),placeholder:a("sessions.renamePlaceholder"),"data-testid":"web-chat-rename-input"}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(C,{variant:"secondary",onClick:()=>q(null),children:a("common.cancel")}),s.jsx(C,{onClick:()=>void Re(),loading:de==="rename","data-testid":"web-chat-rename-save",children:a("common.save")})]})]})}),s.jsx(je,{open:!!z,onClose:()=>O(null),title:a("sessions.deleteConfirmTitle"),children:s.jsxs("div",{className:"space-y-4",children:[s.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:a("sessions.deleteConfirmBody")}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(C,{variant:"secondary",onClick:()=>O(null),children:a("common.cancel")}),s.jsx(C,{variant:"danger",onClick:()=>void Ie(),loading:de==="delete","data-testid":"web-chat-delete-confirm",children:a("common.delete")})]})]})})]})}export{ys as default};
|
|
1
|
+
import{u as ze,t as Me,r,j as s,C as ye,I as pe,M as K,B as C,w as ee,R as De,T as Le}from"./index-DbqC4-hV.js";import{M as je}from"./Modal-BfZUw-Vc.js";import{E as U}from"./EmptyState-Blxa5wT6.js";import{C as Ae,S as Be}from"./ChatMarkdown-BJUbKIWx.js";import{l as Ke}from"./projects-CxhcfuFo.js";import{l as Ue,g as $e,s as qe,a as be,r as Fe,d as Oe}from"./sessions-qYxQCCGN.js";import{s as He,a as ve,b as v,L as $,t as Ve}from"./session-utils-DzI7rMtW.js";import{S as We}from"./search-CR2u_AT7.js";import{P as Ge}from"./pencil-CmkSVcVi.js";import{T as Je}from"./trash-2-DwMqg4qR.js";import{B as Qe,U as Xe}from"./user-cFDevW5m.js";import"./index-CTOb2Qbz.js";import"./check-DdHpkvai.js";const Ye=1500,Ze=9e4;function es(a){return String(a||"").startsWith("web:")}function ss(a){return(a||[]).map((c,p)=>({id:`${c.timestamp||p}-${c.role}-${p}`,role:c.role==="user"?"user":"assistant",content:c.content,timestamp:c.timestamp,kind:c.kind}))}function ts(a){return a.map(c=>`${c.role}:${c.kind||"final"}:${c.timestamp||""}:${c.content}`).join(`
|
|
2
|
+
`)}function as(a){return a.filter(c=>c.role!=="user").length}function ns(a,c){var p;return(p=a.last_message)!=null&&p.content?a.last_message.content.replace(/\n/g," "):c("sessions.noMessages")}function we(a){return(a instanceof Error?a.message:String(a||"")).trim().toLowerCase().includes("no active session found")}function rs(a,c){return(a instanceof Error?a.message:String(a||"")).trim().toLowerCase()?we(a)?c("sessions.sessionUnavailable"):a instanceof Error?a.message:c("sessions.sendFailed"):c("sessions.sendFailed")}function js(){const{t:a}=ze(),[c,p]=Me(),[se,ke]=r.useState([]),[te,ae]=r.useState({}),[i,G]=r.useState(c.get("project")||""),[j,_]=r.useState([]),[n,h]=r.useState(null),[R,w]=r.useState([]),[J,ne]=r.useState(""),[I,Q]=r.useState(""),[Se,re]=r.useState(!0),[Ne,ie]=r.useState(!1),[Ce,le]=r.useState(!1),[X,oe]=r.useState(!1),[E,P]=r.useState("idle"),[ce,k]=r.useState(""),[T,q]=r.useState(null),[F,Y]=r.useState(""),[z,O]=r.useState(null),[de,H]=r.useState(null),me=r.useRef(null),x=r.useRef({project:"",sessionId:""}),V=r.useRef(null),W=r.useRef(null),b=c.get("project")||"",M=c.get("session")||"",ue=r.useMemo(()=>new Set(Object.values(te)),[te]),S=r.useMemo(()=>{const e=J.trim().toLowerCase();return e?j.filter(t=>He(t,e)):j},[J,j]),D=!!(n&&(n.live||ue.has(n.id))),Ee=!!(i&&D&&I.trim()&&!X&&E!=="sending"&&E!=="activating"&&E!=="polling"),f=r.useCallback((e,t)=>{const l=new URLSearchParams;e&&l.set("project",e),t&&l.set("session",t),p(l,{replace:!0})},[p]),d=r.useCallback((e="idle")=>{V.current&&(window.clearTimeout(V.current),V.current=null),W.current=null,P(e)},[]),xe=r.useCallback(e=>{_(t=>{const l=t.some(o=>o.id===e.id)?t.map(o=>o.id===e.id?{...o,...e}:o):[...t,e];return ve(l)})},[]),fe=r.useCallback(async()=>{re(!0);try{const{projects:e}=await Ke();ke(e||[])}finally{re(!1)}},[]),u=r.useCallback(async e=>{if(!e)return _([]),ae({}),[];ie(!0);try{const{sessions:t,active_keys:l}=await Ue(e),o=ve((t||[]).filter(m=>!es(m.session_key)));return ae(l||{}),x.current.project===e&&_(o),o}finally{ie(!1)}},[]),N=r.useCallback(async(e,t,l)=>{if(!e||!t)return h(null),w([]),null;l!=null&&l.silent||le(!0);try{const o=await $e(e,t,200);return x.current.project!==e||x.current.sessionId!==t||(xe(o),h({id:o.id,project:e,sessionKey:o.session_key,name:o.name||v(o),live:o.live,isDraft:!1,detail:o}),w(ss(o.history)),k("")),o}catch(o){return x.current.project===e&&x.current.sessionId===t&&k(o instanceof Error?o.message:a("sessions.loadFailed")),null}finally{l!=null&&l.silent||le(!1)}},[xe,a]),Z=r.useCallback(e=>{W.current=e,V.current=window.setTimeout(async()=>{const t=W.current;if(!t)return;if(Date.now()-t.startedAt>=Ze){d("timed_out"),k(a("sessions.pollTimeout")),await u(t.project);return}const l=await N(t.project,t.sessionId,{silent:!0});if(!l||!W.current){d(),await u(t.project);return}if(x.current.project!==t.project||x.current.sessionId!==t.sessionId){d();return}const o=ts(l.history),m=as(l.history)>t.assistantCountBefore,g=m&&o===t.lastSignature?t.stableCount+1:0,B={...t,lastSignature:o,stableCount:g};if(m&&g>=2){d(),await u(t.project);return}P("polling"),Z(B)},Ye)},[N,u,d,a]),he=r.useCallback((e,t,l)=>{d(),P("polling"),Z({project:e,sessionId:t,assistantCountBefore:l,stableCount:0,lastSignature:"",startedAt:Date.now()})},[Z,d]),Pe=r.useCallback(async e=>{if(d(),G(e),ne(""),k(""),Q(""),!e){x.current={project:"",sessionId:""},h(null),w([]),_([]),f("");return}x.current={project:e,sessionId:""},h(null),w([]),f(e),await u(e)},[u,d,f]),L=r.useCallback(async e=>{if(e.isDraft||e.live||!e.id)return e;P("activating");try{await qe(e.project,{session_key:e.sessionKey,session_id:e.id}),await u(e.project);const t=await N(e.project,e.id,{silent:!0}),l={...e,live:(t==null?void 0:t.live)??!0,isDraft:!1,detail:t??e.detail,name:(t==null?void 0:t.name)||e.name};return h(l),l}finally{P("idle")}},[N,u]),A=r.useCallback(async(e,t)=>{d(),k(""),x.current={project:e,sessionId:t.id},G(e),f(e,t.id),h({id:t.id,project:e,sessionKey:t.session_key,name:v(t),live:t.live,isDraft:!1,detail:null});const l=await N(e,t.id);l&&!l.live&&await L({id:l.id,project:e,sessionKey:l.session_key,name:l.name||v(l),live:l.live,isDraft:!1,detail:l})},[L,N,d,f]),_e=r.useCallback(async()=>{d(),i&&(await u(i),n!=null&&n.id&&(x.current={project:i,sessionId:n.id},await N(i,n.id)))},[n==null?void 0:n.id,N,u,i,d]),ge=r.useCallback(async()=>{if(!I.trim()||!i)return;if(!D){k(a("sessions.sessionUnavailable"));return}const e=I.trim(),t=`${crypto.randomUUID()}-user`,l={id:t,role:"user",content:e,timestamp:new Date().toISOString()};Q(""),oe(!0),P("sending"),k("");try{const o=n||S[0];if(!o)throw new Error(a("sessions.noAvailableChatTarget"));let m=n&&n.id===o.id?n:{id:o.id,project:i,sessionKey:"session_key"in o?o.session_key:o.sessionKey,name:"session_key"in o?v(o):o.name,live:o.live,isDraft:!1,detail:null};(!n||n.id!==m.id)&&(x.current={project:i,sessionId:m.id},f(i,m.id),h(m)),m=await L(m),w(y=>[...y,l]);try{await be(i,{session_key:m.sessionKey,message:e})}catch(y){if(!we(y)||!m.id)throw y;m=await L({...m,live:!1}),await be(i,{session_key:m.sessionKey,message:e})}const g=m.id;if(!g)throw new Error(a("sessions.createFailed"));const B=R.filter(y=>y.role!=="user").length;x.current={project:i,sessionId:g},h(y=>y&&{...y,id:g,isDraft:!1}),f(i,g),he(i,g,B),await u(i)}catch(o){d(),w(g=>g.filter(B=>B.id!==t));const m=rs(o,a);k(m)}finally{oe(!1)}},[n,D,L,I,S,R,u,i,he,d,a,f]),Re=r.useCallback(async()=>{if(!(!T||!i||!F.trim())){H("rename");try{await Fe(i,T.id,{name:F.trim()});const t=(await u(i)).find(l=>l.id===T.id);t&&(n==null?void 0:n.id)===t.id&&h(l=>l&&{...l,name:v(t)}),q(null),Y("")}finally{H(null)}}},[n==null?void 0:n.id,u,F,T,i]),Ie=r.useCallback(async()=>{if(!(!z||!i)){H("delete");try{await Oe(i,z.id);const e=await u(i);(n==null?void 0:n.id)===z.id&&(d(),x.current={project:i,sessionId:""},h(null),w([]),f(i)),e.length===0&&w([]),O(null)}finally{H(null)}}},[n==null?void 0:n.id,z,u,i,d,f]);r.useEffect(()=>{fe()},[fe]),r.useEffect(()=>{b&&(i&&i===b||G(b))},[b,i]),r.useEffect(()=>{if(!i){_([]);return}x.current.project=i,u(i)},[u,i]),r.useEffect(()=>{!i||M||n!=null&&n.id||S.length===0||A(i,S[0])},[n==null?void 0:n.id,S,A,M,i]),r.useEffect(()=>{if(!b||!M||i!==b)return;const e=j.find(t=>t.id===M);if(!e){j.length>0&&f(b,j[0].id);return}(n==null?void 0:n.id)!==e.id&&A(b,e)},[n==null?void 0:n.id,A,b,M,i,j,f]),r.useEffect(()=>{var e;(e=me.current)==null||e.scrollIntoView({behavior:"smooth"})},[R]),r.useEffect(()=>()=>d(),[d]);const Te=(n==null?void 0:n.name)||a("sessions.activeChat");return s.jsxs("div",{className:"grid min-h-[calc(100vh-8rem)] grid-cols-1 gap-4 xl:grid-cols-[22rem_minmax(0,1fr)] animate-fade-in",children:[s.jsxs(ye,{className:"flex flex-col gap-4 p-4 xl:h-[calc(100vh-8rem)] xl:overflow-hidden",children:[s.jsx("div",{className:"flex items-center gap-3",children:s.jsxs("div",{className:"flex-1",children:[s.jsx("p",{className:"text-xs font-medium uppercase tracking-[0.2em] text-gray-400",children:a("sessions.selectProject")}),s.jsxs("select",{value:i,onChange:e=>void Pe(e.target.value),className:"mt-2 w-full rounded-xl border border-gray-300/90 bg-white/90 px-3 py-2 text-sm text-gray-900 transition-all focus:border-accent focus:outline-none focus:ring-2 focus:ring-accent/45 dark:border-white/[0.1] dark:bg-[rgba(0,0,0,0.45)] dark:text-white",children:[s.jsx("option",{value:"",children:a("sessions.allProjects")}),se.map(e=>s.jsx("option",{value:e.name,children:e.name},e.name))]})]})}),s.jsxs("div",{className:"relative",children:[s.jsx(pe,{value:J,onChange:e=>ne(e.target.value),placeholder:a("common.search"),className:"pl-9","aria-label":a("common.search")}),s.jsx(We,{size:16,className:"pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-gray-400"})]}),s.jsxs("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden",children:[s.jsxs("div",{className:"mb-3 flex items-center justify-between text-xs text-gray-500 dark:text-gray-400",children:[s.jsx("span",{children:a("sessions.historyTitle")}),s.jsx("span",{children:S.length})]}),s.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto space-y-2 pr-1",children:Se?s.jsx("div",{className:"flex h-32 items-center justify-center text-gray-400",children:s.jsx($,{className:"animate-spin",size:18})}):i?Ne&&j.length===0?s.jsx("div",{className:"flex h-32 items-center justify-center text-gray-400",children:s.jsx($,{className:"animate-spin",size:18})}):j.length===0?s.jsx(U,{message:a("sessions.noSessions"),icon:K}):S.length===0?s.jsx(U,{message:a("sessions.noSessions"),icon:K}):S.map(e=>{const t=e.id===(n==null?void 0:n.id);return s.jsxs("div",{className:ee("rounded-2xl border p-3 transition-all",t?"border-accent/45 bg-accent/10 shadow-[0_0_20px_-12px_rgba(139,92,246,0.55)]":"border-gray-200/80 bg-white/70 hover:border-accent/30 dark:border-white/[0.08] dark:bg-white/[0.03]"),children:[s.jsxs("button",{type:"button",onClick:()=>void A(i,e),className:"w-full text-left","data-testid":"web-chat-session-open",children:[s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"truncate text-sm font-medium text-gray-900 dark:text-white",children:v(e)}),e.live||ue.has(e.id)?s.jsx("span",{className:"rounded-full bg-violet-50 px-2 py-0.5 text-[10px] text-violet-600 dark:bg-violet-950/20 dark:text-violet-300",children:"live"}):s.jsx("span",{className:"rounded-full bg-gray-100 px-2 py-0.5 text-[10px] text-gray-400 dark:bg-white/[0.06] dark:text-gray-500",children:"history"})]}),s.jsx("p",{className:"mt-1 truncate text-xs text-gray-500 dark:text-gray-400",children:Ve(e.updated_at||e.created_at,a("sessions.justNow"))})]}),s.jsx("span",{className:"shrink-0 text-[10px] text-gray-400",children:e.history_count})]}),s.jsx("p",{className:"mt-2 line-clamp-2 text-xs text-gray-500 dark:text-gray-400",children:ns(e,a)})]}),s.jsxs("div",{className:"mt-3 flex items-center justify-end gap-1",children:[s.jsx(C,{size:"sm",variant:"ghost",onClick:()=>{q({id:e.id,name:v(e)}),Y(v(e))},"data-testid":"web-chat-session-rename",children:s.jsx(Ge,{size:14})}),s.jsx(C,{size:"sm",variant:"ghost",onClick:()=>O({id:e.id,name:v(e)}),"data-testid":"web-chat-session-delete",children:s.jsx(Je,{size:14})})]})]},e.id)}):s.jsx(U,{message:a("sessions.projectRequired"),icon:K})})]})]}),s.jsxs(ye,{className:"flex min-h-[32rem] flex-col p-0 xl:h-[calc(100vh-8rem)]",children:[s.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-gray-200/80 px-5 py-4 dark:border-white/[0.08]",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("h2",{className:"truncate text-lg font-semibold text-gray-900 dark:text-white",children:Te})}),s.jsx("p",{className:"mt-1 truncate text-sm text-gray-500 dark:text-gray-400",children:n?n.project:a("sessions.sendHint")})]}),s.jsxs(C,{size:"sm",variant:"secondary",onClick:()=>void _e(),"data-testid":"web-chat-refresh",children:[s.jsx(De,{size:14})," ",a("common.refresh")]})]}),s.jsx("div",{className:"flex-1 overflow-y-auto px-5 py-5",children:i?Ce?s.jsx("div",{className:"flex h-full items-center justify-center text-gray-400",children:s.jsx($,{className:"animate-spin",size:22})}):R.length===0?s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsx(U,{message:a(n?"sessions.noMessages":"sessions.sendHint"),icon:K})}):s.jsxs("div",{className:"space-y-5",children:[R.map(e=>{const t=e.role==="user";return s.jsxs("div",{className:ee("flex gap-3",t?"justify-end":"justify-start"),children:[!t&&s.jsx("div",{className:"mt-1 flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-accent/10",children:s.jsx(Qe,{size:16,className:"text-accent"})}),s.jsx("div",{className:ee("max-w-[85%] rounded-2xl px-5 py-3.5 text-sm",t?"bg-accent text-white rounded-br-md":"border border-gray-200 bg-white text-gray-900 shadow-sm dark:border-white/[0.08] dark:bg-[rgba(0,0,0,0.42)] dark:text-gray-100 rounded-bl-md"),children:s.jsx(Ae,{content:e.content,isUser:t})}),t&&s.jsx("div",{className:"mt-1 flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-gray-200 dark:bg-white/[0.08]",children:s.jsx(Xe,{size:16,className:"text-gray-500 dark:text-gray-300"})})]},e.id)}),s.jsx("div",{ref:me})]}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsx(U,{message:a("sessions.emptySelection"),icon:K})})}),s.jsxs("div",{className:"border-t border-gray-200/80 px-5 py-4 dark:border-white/[0.08]",children:[ce&&s.jsx("div",{className:"mb-3 rounded-xl border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-600 dark:border-red-900/40 dark:bg-red-950/20 dark:text-red-300",children:ce}),E==="polling"&&s.jsxs("div",{className:"mb-3 flex items-center gap-2 text-sm text-gray-500 dark:text-gray-400",children:[s.jsx($,{size:14,className:"animate-spin"}),s.jsx("span",{children:a("sessions.waitingForReply")})]}),E==="activating"&&s.jsxs("div",{className:"mb-3 flex items-center gap-2 text-sm text-gray-500 dark:text-gray-400",children:[s.jsx($,{size:14,className:"animate-spin"}),s.jsx("span",{children:a("sessions.preparingChat")})]}),s.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-end",children:[s.jsx("div",{className:"flex-1",children:s.jsx(Le,{value:I,onChange:e=>Q(e.target.value),onKeyDown:e=>{e.key==="Enter"&&!e.shiftKey&&(e.preventDefault(),ge())},rows:3,placeholder:a(i?"sessions.messageInput":"sessions.projectRequired"),disabled:!i||!D||X||E==="polling"||E==="activating","data-testid":"web-chat-input"})}),s.jsxs(C,{onClick:()=>void ge(),disabled:!Ee,loading:X,size:"lg",className:"sm:self-stretch","data-testid":"web-chat-send",children:[s.jsx(Be,{size:16})," ",a("sessions.send")]})]}),!D&&n&&s.jsx("div",{className:"mt-3 rounded-xl border border-gray-200 bg-gray-50 px-4 py-3 text-sm text-gray-500 dark:border-white/[0.08] dark:bg-white/[0.03] dark:text-gray-400",children:a("sessions.notLiveHint")})]})]}),s.jsx(je,{open:!!T,onClose:()=>q(null),title:a("sessions.renameTitle"),children:s.jsxs("div",{className:"space-y-4",children:[s.jsx(pe,{value:F,onChange:e=>Y(e.target.value),placeholder:a("sessions.renamePlaceholder"),"data-testid":"web-chat-rename-input"}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(C,{variant:"secondary",onClick:()=>q(null),children:a("common.cancel")}),s.jsx(C,{onClick:()=>void Re(),loading:de==="rename","data-testid":"web-chat-rename-save",children:a("common.save")})]})]})}),s.jsx(je,{open:!!z,onClose:()=>O(null),title:a("sessions.deleteConfirmTitle"),children:s.jsxs("div",{className:"space-y-4",children:[s.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:a("sessions.deleteConfirmBody")}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(C,{variant:"secondary",onClick:()=>O(null),children:a("common.cancel")}),s.jsx(C,{variant:"danger",onClick:()=>void Ie(),loading:de==="delete","data-testid":"web-chat-delete-confirm",children:a("common.delete")})]})]})})]})}export{js as default};
|