limixbot 0.3.146 → 0.3.148
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/assets/{ActivityPanel-DTqdgF9v.js → ActivityPanel-F9d7zvpT.js} +1 -1
- package/dist/assets/{App-FkCoivKo.js → App-BgdjoCaG.js} +101 -101
- package/dist/assets/{AppEventEditor-hBLRTJCh.js → AppEventEditor-CbDxf3ao.js} +1 -1
- package/dist/assets/{BotSettingsDialog-0CLALU4h.js → BotSettingsDialog-B-yEj47w.js} +1 -1
- package/dist/assets/{BrowserPanel-BjqIxdsD.js → BrowserPanel-BDo5f1Jm.js} +1 -1
- package/dist/assets/{BrowserProfilesManager-C2DEX5Dz.js → BrowserProfilesManager-BAzvLmnn.js} +1 -1
- package/dist/assets/{CloudAddDialog-Ce6eiErj.js → CloudAddDialog-LRUAy-7y.js} +1 -1
- package/dist/assets/{ComputerFilesPane-CUls-HDE.js → ComputerFilesPane-Bp9DOa3Y.js} +1 -1
- package/dist/assets/{ComputerPanel-CY6rmF7p.js → ComputerPanel-BocEhfqe.js} +2 -2
- package/dist/assets/{DataPanel-BMItjksI.js → DataPanel-C8nr8Ajt.js} +1 -1
- package/dist/assets/{GrokMoveDialog-BjIt7fo_.js → GrokMoveDialog-d8kG3z3l.js} +1 -1
- package/dist/assets/{InspectorPanel-Be9J8vTL.js → InspectorPanel-D0n9O2Sh.js} +1 -1
- package/dist/assets/{KeyboardShortcutsModal-CJhaJp59.js → KeyboardShortcutsModal-DVhBpOOB.js} +1 -1
- package/dist/assets/{KnowledgePanel-BsdqL7-z.js → KnowledgePanel-BifuCuZi.js} +1 -1
- package/dist/assets/{LimixResizeHandles-DKdU_JFS.js → LimixResizeHandles-Co-9OI_G.js} +1 -1
- package/dist/assets/{LiveDesktop-QudEVPsj.js → LiveDesktop-CDBbQAjn.js} +1 -1
- package/dist/assets/{LocalVmWorkspace-Cs2BgRNV.js → LocalVmWorkspace-D_NB8bZ5.js} +1 -1
- package/dist/assets/{MacLocalControl-Cq3ZxYZY.js → MacLocalControl-DU5oNvcq.js} +1 -1
- package/dist/assets/{MarkdownFilePreview-CVTDyg_G.js → MarkdownFilePreview-DfMNn9qG.js} +1 -1
- package/dist/assets/{NewBotDialog-aItvxrvB.js → NewBotDialog-JyiygOxT.js} +1 -1
- package/dist/assets/{PhoneAppDialog-8-dgtBhp.js → PhoneAppDialog-DKYpfRuQ.js} +1 -1
- package/dist/assets/{PluginsPanel-DVS8g955.js → PluginsPanel-sPLPWkdl.js} +1 -1
- package/dist/assets/{ProIntroduction-DV0pDAEU.js → ProIntroduction-Cq3nswpJ.js} +1 -1
- package/dist/assets/{RemoteAgentSettingsPanel-CNlzF4Cp.js → RemoteAgentSettingsPanel-DuYzU2nQ.js} +1 -1
- package/dist/assets/{RoomPanel-Cc_GKn6x.js → RoomPanel-vXOP5sr5.js} +1 -1
- package/dist/assets/{RoutinesPage-DOBkHlRF.js → RoutinesPage-CY3YGT8X.js} +1 -1
- package/dist/assets/SettingsModal-B-mRTq4f.js +20 -0
- package/dist/assets/{ShareTeamDialog-CSlDvD9U.js → ShareTeamDialog-DVidCcmp.js} +1 -1
- package/dist/assets/{SignedInSites-D-0eKIyP.js → SignedInSites-RCz33HaF.js} +1 -1
- package/dist/assets/{TeamLibraryPanel-DM76EFJx.js → TeamLibraryPanel-DlCtaa3S.js} +1 -1
- package/dist/assets/{TeamMapPage-DhrPVbXJ.js → TeamMapPage-CF4keIXL.js} +1 -1
- package/dist/assets/{TriggersPage-DjSUS5gg.js → TriggersPage-Bngst1v9.js} +1 -1
- package/dist/assets/{VisibilitySection-DwI5DSDK.js → VisibilitySection-PkgvzaLZ.js} +1 -1
- package/dist/assets/{WebhookTrigger-DZqMzEbP.js → WebhookTrigger-DEoEYgVK.js} +1 -1
- package/dist/assets/{WorksOnGrid-CDTdX4z9.js → WorksOnGrid-RadKXaob.js} +1 -1
- package/dist/assets/{core-DBsdXcHm.js → core-DK9jR4up.js} +1 -1
- package/dist/assets/{import-name-DRn9LvPS.js → import-name-C3ytLH-g.js} +1 -1
- package/dist/assets/{index-CaQlk_HV.js → index-BQM4L4RU.js} +2 -2
- package/dist/assets/{index-Cnv_eiqT.js → index-ZJsaQ9Ga.js} +1 -1
- package/dist/assets/{new-bot-LJs5i8O5.js → new-bot-CG838Ldv.js} +1 -1
- package/dist/assets/{org-library-B4fn4bHb.js → org-library-ByuDQUvu.js} +1 -1
- package/dist/assets/{package-format-CbAOdMeR.js → package-format-DQXSLHZJ.js} +1 -1
- package/dist/assets/{remote-desktop-panel-0Aj0_kDX.js → remote-desktop-panel-D-0l80ko.js} +1 -1
- package/dist/index.html +1 -1
- package/dist-server/index.js +6 -5
- package/dist-server/package.json +1 -1
- package/dist-server/server/cloud-send-arrived.js +21 -3
- package/package.json +1 -1
- package/dist/assets/SettingsModal-B7Qc3XzL.js +0 -20
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{r as f,j as o,t as d,d as te,a as j,ad as ne,X as se,l as J,ae as re}from"./styles-DO3EUxm2.js";import{bp as ae,bq as ie,br as oe,b3 as D,bs as ce,bt as le,bu as ue,u as de,aj as pe,l as me,bv as fe,bw as xe}from"./App-
|
|
1
|
+
import{r as f,j as o,t as d,d as te,a as j,ad as ne,X as se,l as J,ae as re}from"./styles-DO3EUxm2.js";import{bp as ae,bq as ie,br as oe,b3 as D,bs as ce,bt as le,bu as ue,u as de,aj as pe,l as me,bv as fe,bw as xe}from"./App-BgdjoCaG.js";import{C as he,L as ge,K as ye,u as be}from"./PlacesRail-tZyNm-l3.js";import{R as ke,C as $e}from"./MenuMotion-B0aZnuh_.js";import"./index-BQM4L4RU.js";import"./monitor-zecPzfR5.js";const $=(e,n=120)=>e.length>n?`${e.slice(0,n-1)}…`:e,v=e=>e.replace(/\s+/g," ").trim(),F=119;function H(e,n){const a=e?{...e}:{text:"",pendingSpace:!1,overflow:!1};if(a.overflow)return a;for(const i of n){if(/\s/.test(i)){a.text&&(a.pendingSpace=!0);continue}if(a.pendingSpace){if(a.text.length>=F){a.overflow=!0;break}a.text+=" ",a.pendingSpace=!1}if(a.text.length>=F){a.overflow=!0;break}a.text+=i}return a}const B=e=>`${e.text}${e.overflow?"…":""}`;function ve(e){switch(e.type){case"session.started":return{summary:`session ${e.sessionId??"(none)"}${e.model?` · ${e.model}`:""}`,tone:"plain"};case"session.exited":return{summary:`session exited${e.reason?` · ${e.reason}`:""}`,tone:"plain"};case"turn.started":return{summary:`turn started${e.turnId?` · ${e.turnId.slice(0,8)}`:""}`,tone:"boundary"};case"turn.retrying":return{summary:`retrying (${e.reason}) · attempt ${e.attempt} · ${Math.round(e.delayMs/1e3)}s`,tone:"plain"};case"turn.completed":{const n=[e.ok?"turn ok":"turn failed"];return e.stopReason&&n.push(e.stopReason),typeof e.cost=="number"&&n.push(ae(e.cost,4)),e.denials?.length&&n.push(`${e.denials.length} denied`),{summary:n.join(" · "),tone:e.ok?"boundary":"error"}}case"turn.wait_started":return{summary:`waiting for ${e.resource.startsWith("browser:")?"browser":"computer"} — ${e.holder?`${e.holder.name}${e.holder.task?` (${e.holder.task})`:""}`:"holder unknown"}`,tone:"plain"};case"turn.wait_ended":{const n=Math.round(e.waitedMs/1e3),a=e.waitedMs<1e3?"under a second":`${n}s`;return e.outcome==="acquired"?{summary:`${e.resource.startsWith("browser:")?"browser":"computer"} acquired after ${a}`,tone:"boundary"}:e.outcome==="parked"?{summary:`computer wait parked after ${a}`,tone:"plain"}:e.outcome==="gave_up"?{summary:`computer wait gave up after ${a}`,tone:"error"}:{summary:`computer wait stopped after ${a}`,tone:"plain"}}case"item.started":return{summary:`${e.itemType}${e.title?`: ${$(v(e.title))}`:" started"}`,tone:"plain"};case"item.updated":return{summary:`${e.itemType} updated${typeof e.tokens=="number"?` · ${e.tokens} tok`:""}`,tone:"plain"};case"turn.progress":return{summary:`live: ${[e.activity,e.tool,e.file,typeof e.bytes=="number"?`${e.bytes} bytes`:void 0].filter(Boolean).join(" · ")}`,tone:"plain"};case"item.completed":return e.itemType==="assistant_text"?{summary:`assistant: ${$(v(e.text))}`,tone:"plain"}:e.itemType==="assistant_image"?{summary:"assistant image generated",tone:"plain"}:{summary:`tool ${e.ok?"ok":"failed"}`,tone:e.ok?"plain":"error"};case"content.delta":return{summary:`${e.streamKind}: ${$(v(e.delta))}`,tone:"plain"};case"request.opened":return{summary:`${e.requestType}${e.origin==="output"?" (agent-composed)":""}: ${e.tool} — ${$(v(e.summary))}`,tone:"plain"};case"request.resolved":return{summary:`resolved ${e.behavior} · ${e.source}`,tone:"plain"};case"thread.token-usage.updated":return{summary:`tokens in ${e.input} · out ${e.output}`,tone:"plain"};case"runtime.error":return{summary:`${e.setup?"setup: ":""}${$(v(e.message))}`,tone:"error"};case"runtime.notice":return{summary:`notice: ${$(v(e.message))}`,tone:"plain"};default:return{summary:e.type,tone:"plain"}}}function we(e){const n=e.msg;if(!n||typeof n!="object")return String(e.msg);const a=typeof n.method=="string"?n.method:void 0,i=typeof n.type=="string"?n.type:void 0,s=n.id!==void 0?` #${String(n.id)}`:"";if(a)return`${a}${s}`;if(typeof n.event=="string"){const t=n.result?.status;return typeof t=="string"?`${n.event} · ${t}`:n.event}if(i){const t=n.message,x=typeof t?.role=="string"?` · ${t.role}`:"",l=typeof n.subtype=="string"?` · ${n.subtype}`:"";return`${i}${l}${x}`}return n.result!==void 0?`result${s}`:n.error!==void 0?`error${s}`:$(v(JSON.stringify(n)))}function U(e){const n=[];for(const[a,i]of e.entries()){if(i.kind==="native"){n.push({key:`n${a}`,kind:"native",at:i.at,tag:i.data.dir==="out"?"→ out":"← in",summary:`${i.data.source} · ${we(i.data)}`,tone:"plain",data:i.data,count:1});continue}const s=i.data,t=n.at(-1);if(s.type==="content.delta"&&t?.kind==="runtime"&&t.tag==="content.delta"&&t.data[0]?.type==="content.delta"&&t.data[0].streamKind===s.streamKind){const y=t.data;y.push(s),t.count=y.length,t.preview=H(t.preview,s.delta),t.summary=`${s.streamKind}: ${B(t.preview)}`;continue}const{summary:x,tone:l}=ve(s),u=s.type==="content.delta"?H(void 0,s.delta):void 0,b=s.type==="content.delta"?s.streamKind:void 0;n.push({key:s.eventId||`r${a}`,kind:"runtime",at:i.at,tag:s.type,summary:u&&b?`${b}: ${B(u)}`:x,tone:l,data:s.type==="content.delta"?[s]:s,count:1,preview:u})}return n}function je(e){const n=new Date(e);if(Number.isNaN(n.getTime()))return"--:--:--";const a=String(n.getHours()).padStart(2,"0"),i=String(n.getMinutes()).padStart(2,"0"),s=String(n.getSeconds()).padStart(2,"0"),t=String(n.getMilliseconds()).padStart(3,"0");return`${a}:${i}:${s}.${t}`}function Se(e,n){const a=ie(e,n),i=[];let s=!1;for(const t of e)if(t.kind==="text"&&t.role==="user"&&t.text?.trim())i.push({id:t.id,at:t.at,label:s?"User input":"Task started",state:"observed",kind:"task"}),s=!0;else if(t.kind==="activity"&&t.tool){const x=oe(t.tool.name),l=t.tool.ok===!1||x!==null;i.push({id:t.id,at:t.at,label:D(x??t.tool.name),...t.tool.summary?{command:D(t.tool.summary)}:{},state:l?"failed":t.tool.ok===!0?"complete":a.has(t.id)?"running":"unverified",kind:"tool"})}else t.kind==="screen"?i.push({id:t.id,at:t.at,label:"Screen observed",state:"observed",kind:"screen"}):t.kind==="text"&&t.role==="bot"&&t.text?.trim()&&i.push({id:t.id,at:t.at,label:"Response recorded",state:"complete",kind:"result"});return i}function Ne(e){return D(e.map(n=>`[${new Date(n.at).toISOString()}] ${n.state} · ${n.label}${n.command?`
|
|
2
2
|
${n.command}`:""}`).join(`
|
|
3
3
|
`))}const Ie={running:"inspector.run.running",complete:"inspector.run.complete",failed:"inspector.run.failed",observed:"inspector.run.observed",unverified:"inspector.run.unverified"};function Te({events:e}){const[n,a]=f.useState("idle"),i=e.slice(-200),s=async()=>{const t=await ye(Ne(i));t!=="empty"&&a(t)};return o.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto",children:[o.jsxs("div",{className:"flex items-start gap-3 px-4 py-3",children:[o.jsx("p",{className:"min-w-0 flex-1 text-[12px] leading-relaxed text-ink-secondary",children:d("inspector.run.hint")}),i.length>0&&o.jsx("button",{type:"button",onClick:()=>{s()},"aria-label":d("inspector.run.copy"),title:d("inspector.run.copy"),className:"rounded-md p-1.5 text-ink-secondary hover:bg-raised hover:text-ink focus-visible:outline-2 focus-visible:outline-accent",children:n==="copied"?o.jsx(te,{size:14}):o.jsx(he,{size:14})})]}),n!=="idle"&&o.jsx("p",{role:"status",className:"px-4 pb-2 text-[12px] text-ink-secondary",children:d(n==="copied"?"inspector.run.copied":"inspector.run.copyFailed")}),e.length>i.length&&o.jsx("p",{className:"px-4 pb-2 text-[12px] text-ink-secondary",children:d("inspector.run.recent",{count:i.length})}),i.length===0?o.jsx("p",{className:"px-4 py-6 text-[13px] text-ink-secondary",children:d("inspector.run.empty")}):o.jsx("ol",{"aria-label":d("inspector.run.title"),className:"px-4 pb-4",children:i.map(t=>{const x=t.state==="failed"?ce:t.state==="complete"?le:t.state==="running"?ge:ue,l=t.kind==="task"?d("inspector.run.userInput"):t.kind==="screen"?d("inspector.run.screen"):t.kind==="result"?d("inspector.run.response"):t.label;return o.jsxs("li",{className:"border-t border-hairline/30 py-3",children:[o.jsxs("div",{className:"flex items-start gap-2 text-[12px]",children:[o.jsx(x,{size:14,"aria-hidden":"true",className:j("mt-0.5 shrink-0",t.state==="failed"?"text-danger":t.state==="running"?"animate-spin text-accent":"text-ink-secondary")}),o.jsx("span",{className:"min-w-0 flex-1 break-words font-medium text-ink",children:l}),o.jsx("time",{dateTime:new Date(t.at).toISOString(),className:"shrink-0 tabular-nums text-ink-secondary",children:ne(t.at)})]}),t.command&&o.jsx("pre",{className:"mt-2 whitespace-pre-wrap break-all rounded-lg bg-inset p-2 font-mono text-[12px] leading-relaxed text-ink",children:t.command}),t.kind==="tool"&&o.jsx("p",{className:j("mt-1 pl-[22px] text-[11px]",t.state==="failed"?"text-danger":"text-ink-secondary"),children:d(Ie[t.state])})]},t.id)})})]})}const K=400,T=new WeakMap;function X(e){const n={runtime:0,native:0},a=[];for(let i=e.length-1;i>=0;i--){const s=e[i];++n[s.kind]<=K&&a.push(s)}return a.length===e.length?e:a.reverse()}function G(e,n){if(!n.length)return e;const a=e??{entries:[],total:{runtime:0,native:0}},i=new Set(a.entries.flatMap(u=>u.kind==="runtime"?[u.data.eventId]:[])),s=[];for(const u of n)i.has(u.eventId)||(i.add(u.eventId),s.push({kind:"runtime",at:u.createdAt,data:u}));if(!s.length)return e;const t=X([...a.entries,...s]),x=new Set([...T.get(a)??[],...s.map(u=>u.data.eventId)]),l={entries:t,total:{...a.total,runtime:a.total.runtime+s.length}};return T.set(l,new Set(t.flatMap(u=>u.kind==="runtime"&&x.has(u.data.eventId)?[u.data.eventId]:[]))),l}function Re(e,n){const a={...n,entries:X(n.entries)};if(!e)return a;const i=e.entries.flatMap(m=>m.kind==="runtime"?[m.data]:[]),s=T.get(e)??new Set,t=a.entries.filter(m=>m.kind==="runtime"),x=new Set(t.map(m=>m.data.eventId)),l=i.findLastIndex(m=>x.has(m.eventId)),u=t.at(-1)?.at,b=(l>=0?i.slice(l+1):i.filter(m=>u===void 0||m.createdAt>=u)).filter(m=>s.has(m.eventId)),y=G(a,b),R={...y,total:{...y.total,runtime:Math.max(e.total.runtime,y.total.runtime)}};return T.set(R,T.get(y)??new Set),R}const Ce=e=>J()==="en"?d(e):xe(d(e));function qe({bot:e}){const{dispatch:n}=de(),{dragProps:a}=be(),i=e.threadId,[s,t]=f.useState("run"),x=f.useMemo(()=>Se(pe(e),e),[e]),[l,u]=f.useState(null),[b,y]=f.useState(null),[R,m]=f.useState(()=>new Set),E=f.useRef(null),z=f.useRef(!0),S=f.useRef(null),C=f.useRef(()=>{}),L=f.useCallback(async()=>{S.current?.abort();const r=new AbortController;S.current=r;try{const c=await fetch(`/api/threads/${i}/events?limit=${K}`,{signal:r.signal});if(!c.ok)throw new Error(`${c.status}`);const p=await c.json();if(r.signal.aborted)return;u(h=>Re(h,p)),m(h=>new Set([...h].filter(M=>M.startsWith("runtime:")))),y(null)}catch(c){if(r.signal.aborted)return;y(c instanceof Error?c.message:String(c))}finally{S.current===r&&(S.current=null)}},[i]);f.useEffect(()=>(u(null),m(new Set),z.current=!0,()=>S.current?.abort()),[L]),f.useEffect(()=>{let r=!0,c=null,p=0,h=!1;const M=[];let N=[],w=null;const q=()=>{w&&clearTimeout(w),w=null;const g=N;N=[],g.length&&u(k=>G(k,g))},W=g=>{N.push(g),N.length>=K?q():w??=setTimeout(q,16)},Y=()=>{for(const g of M.splice(0))W(g)},Z=async()=>{q();const g=++p;h=!0,await L(),!(!r||g!==p)&&(h=!1,Y())},I=()=>{Z()};C.current=I;const ee=me({onMissedFrames:I,onFrame:g=>{if(g.kind!=="runtime")return;const k=g.event;k.threadId===i&&(h?M.push(k):W(k),(k.type==="turn.completed"||k.type==="runtime.error")&&(c&&clearTimeout(c),c=setTimeout(I,400)))}});return I(),()=>{r=!1,C.current===I&&(C.current=()=>{}),ee(),c&&clearTimeout(c),w&&clearTimeout(w),N=[]}},[i,L]);const A=f.useMemo(()=>l?l.entries.filter(r=>s==="raw"?r.kind==="native":r.kind==="runtime"):[],[l,s]),O=f.useMemo(()=>U(A),[A]);f.useEffect(()=>{const r=new Set(["runtime","native"].flatMap(c=>U(l?.entries.filter(p=>p.kind===c)??[]).map(p=>`${p.kind}:${p.key}`)));m(c=>{const p=new Set([...c].filter(h=>r.has(h)));return p.size===c.size?c:p})},[l]),f.useEffect(()=>{const r=E.current;r&&z.current&&(r.scrollTop=r.scrollHeight)},[l,O.length,s]);const V=()=>{const r=E.current;r&&(z.current=r.scrollHeight-r.scrollTop-r.clientHeight<40)},Q=r=>m(c=>{const p=new Set(c);return p.has(r)?p.delete(r):p.add(r),p}),_=A.length,P=s==="raw"?l?.total.native??0:l?.total.runtime??0;return o.jsxs("aside",{"aria-label":d("inspector.title"),className:"animate-panel-in absolute inset-0 z-40 flex h-full min-w-0 flex-col border-l border-hairline/40 bg-panel md:static md:z-auto md:w-[min(460px,45vw)] md:shrink-0",children:[o.jsxs("div",{...a,className:"flex items-center justify-between px-4 py-3",children:[o.jsxs("span",{className:"flex items-center gap-2 text-[15px] font-semibold text-ink",children:[o.jsx(fe,{size:16,className:"text-ink-secondary"})," ",d("inspector.title")]}),o.jsx("button",{onClick:()=>n({type:"toggleInspector",open:!1}),"aria-label":d("inspector.close"),title:d("inspector.close"),className:"rounded-md p-1 text-ink-secondary hover:bg-raised hover:text-ink",children:o.jsx(se,{size:18})})]}),o.jsxs("div",{className:"flex items-center gap-2 border-b border-hairline/40 px-4 pb-3",children:[o.jsx("div",{role:"tablist","aria-label":d("inspector.views"),className:"flex rounded-lg bg-inset p-0.5",onKeyDown:r=>{const c=Array.from(r.currentTarget.querySelectorAll('[role="tab"]')),p=c.indexOf(document.activeElement),h=r.key==="ArrowRight"?(p+1)%c.length:r.key==="ArrowLeft"?(p+c.length-1)%c.length:r.key==="Home"?0:r.key==="End"?c.length-1:-1;h<0||(r.preventDefault(),c[h].focus(),c[h].click())},children:["run","events","raw"].map(r=>o.jsx("button",{type:"button",role:"tab",id:`inspector-tab-${r}`,"aria-selected":s===r,"aria-controls":`inspector-panel-${r}`,tabIndex:s===r?0:-1,onClick:()=>t(r),className:j("rounded-md px-2.5 py-1 text-[12px] font-medium",J()==="en"&&"capitalize",s===r?"bg-raised text-ink":"text-ink-secondary hover:text-ink"),children:Ce(r==="run"?"inspector.run.title":r==="events"?"inspector.tab.events":"inspector.tab.raw")},r))}),s!=="run"&&o.jsx("span",{className:"ml-auto text-[11px] text-ink-secondary",children:l?_<P?d("inspector.entries.lastOf",{shown:_,total:P}):d("inspector.entries.count",{count:_}):d("inspector.entries.loading")}),s!=="run"&&o.jsx("button",{onClick:()=>C.current(),className:"rounded-md p-1 text-ink-secondary hover:bg-raised hover:text-ink",title:d("inspector.reload"),children:o.jsx(ke,{size:14})})]}),o.jsx("div",{role:"tabpanel",id:`inspector-panel-${s}`,"aria-labelledby":`inspector-tab-${s}`,tabIndex:0,className:"flex min-h-0 flex-1 flex-col outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-accent/60",children:s==="run"?o.jsx(Te,{events:x},i):o.jsxs("div",{ref:E,onScroll:V,className:"min-h-0 flex-1 overflow-y-auto font-mono text-[12px]",children:[b&&o.jsx("div",{className:"px-4 py-3 text-danger",children:d("inspector.loadFailed",{error:b})}),l&&O.length===0&&!b&&o.jsx("div",{className:"px-4 py-6 text-ink-secondary",children:d(s==="raw"?"inspector.emptyRaw":"inspector.emptyEvents")}),O.map(r=>o.jsx(Me,{row:r,open:R.has(`${r.kind}:${r.key}`),onToggle:()=>Q(`${r.kind}:${r.key}`)},r.key))]})})]})}function Me({row:e,open:n,onToggle:a}){return o.jsxs("div",{className:j("border-b border-hairline/20",e.tone==="boundary"&&"bg-raised/40",e.tone==="error"&&"bg-danger/10"),children:[o.jsxs("button",{onClick:a,className:"flex w-full items-start gap-2 px-3 py-1.5 text-left hover:bg-raised/60",children:[o.jsx("span",{className:"mt-[1px] shrink-0 text-ink-secondary",children:n?o.jsx(re,{size:12}):o.jsx($e,{size:12})}),o.jsx("span",{className:"shrink-0 tabular-nums text-ink-secondary",children:je(e.at)}),o.jsxs("span",{className:j("shrink-0 rounded px-1 text-[11px]",e.kind==="native"?"bg-accent/15 text-accent":e.tone==="error"?"bg-danger/20 text-danger":"bg-inset text-ink-secondary"),children:[e.tag,e.count>1?` ×${e.count}`:""]}),o.jsx("span",{className:j("min-w-0 flex-1 truncate",e.tone==="error"?"text-danger":"text-ink"),children:e.summary})]}),n&&o.jsx("pre",{className:"max-h-[50vh] overflow-auto whitespace-pre-wrap break-all border-t border-hairline/20 bg-app px-3 py-2 text-[11px] leading-relaxed text-ink",children:JSON.stringify(e.data,null,2)})]})}export{qe as InspectorPanel};
|
package/dist/assets/{KeyboardShortcutsModal-CJhaJp59.js → KeyboardShortcutsModal-DVhBpOOB.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as c,j as e,t as s,X as h,S as m}from"./styles-DO3EUxm2.js";import{i as b,b as f,f as y,s as j,c as g,d as k,e as v}from"./App-
|
|
1
|
+
import{r as c,j as e,t as s,X as h,S as m}from"./styles-DO3EUxm2.js";import{i as b,b as f,f as y,s as j,c as g,d as k,e as v}from"./App-BgdjoCaG.js";import{K as N}from"./MenuMotion-B0aZnuh_.js";import"./index-BQM4L4RU.js";import"./PlacesRail-tZyNm-l3.js";import"./monitor-zecPzfR5.js";function w({item:r,isMac:n}){const a=k(r,n);return e.jsxs("div",{className:"flex items-center justify-between gap-4 py-1.5",children:[e.jsx("span",{className:"text-[13px] text-ink",children:v(r)}),e.jsx("div",{className:"flex shrink-0 items-center gap-1",children:a.map((o,i)=>e.jsx("kbd",{className:"inline-flex min-w-[22px] items-center justify-center rounded-md border border-hairline/60 bg-control px-1.5 py-0.5 font-mono text-[12px] font-semibold text-ink shadow-xs",children:o},i))})]})}function D({open:r,onClose:n}){const[a,o]=c.useState(""),i=c.useRef(null),l=c.useRef(null),d=b(),p=f();if(c.useLayoutEffect(()=>{const t=i.current;if(!(!r||!t))return o(""),t.showModal(),l.current?.focus(),()=>t.close()},[r]),!r)return null;const x=y(j(p),a,d);return e.jsx("dialog",{ref:i,"aria-labelledby":"shortcuts-dialog-title",className:"m-auto w-[min(500px,calc(100%-32px))] max-h-[85vh] overflow-hidden rounded-2xl border border-hairline/50 bg-panel p-0 text-ink shadow-2xl backdrop:bg-black/60 backdrop:backdrop-blur-xs",onCancel:t=>{t.preventDefault(),n()},onKeyDown:t=>t.stopPropagation(),onMouseDown:t=>t.stopPropagation(),children:e.jsxs("div",{className:"flex max-h-[85vh] flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-hairline/40 px-5 py-4",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"flex size-8 shrink-0 items-center justify-center rounded-lg bg-accent/15 text-accent",children:e.jsx(N,{size:18})}),e.jsxs("div",{children:[e.jsx("h2",{id:"shortcuts-dialog-title",className:"text-[16px] font-semibold text-ink",children:s("shortcuts.title")}),e.jsx("p",{className:"text-[12px] text-ink-secondary",children:s("shortcuts.subtitle")})]})]}),e.jsx("button",{type:"button",onClick:n,"aria-label":s("shortcuts.close"),className:"rounded-lg p-1.5 text-ink-secondary hover:bg-raised hover:text-ink",children:e.jsx(h,{size:18})})]}),e.jsx("div",{className:"border-b border-hairline/30 px-5 py-2.5",children:e.jsxs("div",{className:"flex items-center gap-2 rounded-xl border border-hairline/40 bg-inset px-3 py-1.5 focus-within:border-focus",children:[e.jsx(m,{size:14,className:"shrink-0 text-ink-secondary"}),e.jsx("input",{ref:l,value:a,onChange:t=>o(t.target.value),placeholder:s("shortcuts.searchPlaceholder"),"aria-label":s("shortcuts.search"),className:"w-full bg-transparent text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none"})]})}),e.jsx("div",{className:"flex-1 overflow-y-auto px-5 py-3 space-y-4",children:x.length===0?e.jsx("div",{className:"py-8 text-center text-[13px] text-ink-secondary",children:s("shortcuts.noMatch",{query:a})}):x.map(t=>e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wider text-ink-tertiary",children:g(t)}),e.jsx("div",{className:"divide-y divide-hairline/20 rounded-xl bg-card/40 px-3 py-1 border border-hairline/30",children:t.items.map(u=>e.jsx(w,{item:u,isMac:d},u.id))})]},t.category))}),e.jsxs("div",{className:"flex items-center justify-between border-t border-hairline/40 bg-card/30 px-5 py-2.5 text-[12px] text-ink-secondary",children:[e.jsxs("span",{children:[s("shortcuts.openHintBefore")," ",e.jsx("kbd",{className:"rounded bg-control px-1 py-0.5 font-mono text-[11px]",children:"?"})," ",s("shortcuts.openHintAfter")]}),e.jsx("button",{type:"button",onClick:n,className:"ui-button ui-button-md",children:s("common.done")})]})]})})}export{D as KeyboardShortcutsModal};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as Q,r as h,j as e,S as $,C as Y}from"./styles-DO3EUxm2.js";import{j as B,x as t,ab as Z,af as J,K as ee,bV as te,u as se,bE as V,ah as ne,G as ae,bG as ie,bW as re,bX as ce,S as oe}from"./App-FkCoivKo.js";import{P as le}from"./PlacesRail-tZyNm-l3.js";import{R as de}from"./MenuMotion-B0aZnuh_.js";import"./index-CaQlk_HV.js";import"./monitor-zecPzfR5.js";const ue=[["path",{d:"M14 17H5",key:"gfn3mx"}],["path",{d:"M19 7h-9",key:"6i9tg"}],["circle",{cx:"17",cy:"17",r:"3",key:"18b49y"}],["circle",{cx:"7",cy:"7",r:"3",key:"dfmy0x"}]],he=Q("settings-2",ue);function P(s){return"/api/bots/"+encodeURIComponent(s)+"/knowledge/"}function me(s){return h.useCallback((n,i={},l)=>B(P(s)+n,{method:"POST",body:JSON.stringify(i),signal:l}),[s])}function I(s){const n=s?.status,i=s instanceof Error?s.message:"",l={"No offline snapshot for this source.":"Nguồn này chưa có bản HTML ngoại tuyến.","Document changed on disk. Index it before editing.":"Tệp đã được sửa bên ngoài. Hãy cập nhật chỉ mục rồi mở lại tài liệu.","A shared link needs a shared target.":"Tài liệu dùng chung chỉ có thể liên kết đến tài liệu dùng chung.","Memory access is disabled for this caller.":"Quyền truy cập bộ nhớ của bot đang tắt.","Vault quota reached.":"Kho đã đạt giới hạn dung lượng.","Invalid Canvas JSON.":"Nội dung Canvas phải là JSON hợp lệ.","A Base needs a views list.":"Tệp Bases phải có danh sách views.","Untrusted instructions cannot become a memory.":"Nội dung có dấu hiệu chứa chỉ dẫn ngoài nguồn tin cậy nên chưa được lưu vào bộ nhớ."};return Object.hasOwn(l,i)?t(l[i],i):n===403?t("Bạn không có quyền thực hiện thao tác này.","You do not have permission for this action."):n===400?t("Dữ liệu đầu vào không hợp lệ. Kiểm tra định dạng và giới hạn của trường.",i):n===404?t("Không tìm thấy mục này hoặc bạn không có quyền mở.",i):n===409?t("Dữ liệu đã thay đổi. Hãy mở lại bản mới nhất trước khi lưu.","The data changed. Open the latest version before saving."):n===413?t("Dữ liệu vượt giới hạn dung lượng.",i):n===429?t("Đã đạt giới hạn yêu cầu. Hãy thử lại sau một phút.",i):n&&n>=500?t("Máy chủ chưa thể hoàn tất thao tác.",i):s instanceof Error?s.message:t("Không thể hoàn tất thao tác.","The operation could not be completed.")}function _(){const s=h.useRef(!1),[n,i]=h.useState(!1),[l,c]=h.useState("");return{run:async o=>{if(!s.current){s.current=!0,i(!0),c("");try{await o()}catch(m){c(I(m))}finally{s.current=!1,i(!1)}}},busy:n,error:l}}function L(s){const[n,i]=h.useState();return h.useEffect(()=>{const l=new AbortController;return s(l.signal).then(c=>{l.signal.aborted||i({load:s,value:c})}).catch(c=>{l.signal.aborted||i({load:s,error:I(c)})}),()=>l.abort()},[s]),n?.load===s?n:void 0}const y="inline-flex items-center justify-center gap-1.5 rounded-lg bg-control px-3 py-1.5 text-sm font-medium text-ink enabled:hover:bg-raised-hover disabled:opacity-45",D="inline-flex items-center justify-center gap-1.5 rounded-lg bg-ink px-3 py-1.5 text-sm font-medium text-app disabled:opacity-45",C="w-full min-w-0 rounded-lg border border-hairline bg-control px-3 py-2 text-sm text-ink",w="space-y-3 rounded-xl border border-hairline bg-menu p-4",j="text-xs leading-5 text-ink-secondary",F=s=>({verified:t("Đã duyệt","Verified"),rejected:t("Đã từ chối","Rejected"),unverified:t("Chưa kiểm duyệt","Awaiting review")})[s],E=25,pe=`<meta http-equiv="Content-Security-Policy" content="default-src 'none'; base-uri 'none'; form-action 'none'">`;function xe({call:s,settings:n}){const[i,l]=h.useState(""),[c,r]=h.useState(""),[o,m]=h.useState(""),[g,b]=h.useState(!1),[x,v]=h.useState(0),[u,f]=h.useState(0),a=L(h.useCallback(async d=>{const p={limit:E,verified_only:g};if(o){const S=await s("search",{...p,query:o,token_budget:1200},d);return{rows:S.results,tokens:S.estimated_tokens}}return{rows:(await s("list",{...p,offset:x*E},d)).documents,tokens:void 0}},[s,o,g,x,u]));return i?e.jsx(W,{id:i,call:s,settings:n,close:()=>{l(""),f(d=>d+1)}},i):e.jsxs("section",{className:"space-y-3",children:[e.jsxs("form",{className:"flex flex-wrap items-center gap-2",onSubmit:d=>{d.preventDefault(),v(0),m(c.trim()),f(p=>p+1)},children:[e.jsxs("label",{className:"relative min-w-40 flex-1",children:[e.jsx($,{className:"absolute left-3 top-2.5 text-ink-secondary",size:15}),e.jsx("input",{type:"search",maxLength:400,className:C+" pl-9","aria-label":t("Tìm tri thức","Search knowledge"),placeholder:t("Tìm tri thức…","Search knowledge…"),value:c,onChange:d=>r(d.target.value)})]}),e.jsx("button",{className:y,children:t("Tìm","Search")}),n.canWrite&&e.jsxs("button",{type:"button",className:D,onClick:()=>l("new"),children:[e.jsx(le,{size:15}),t("Tạo tài liệu","New document")]})]}),e.jsxs("label",{className:"inline-flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:g,onChange:d=>{b(d.target.checked),v(0)}}),t("Chỉ tài liệu đã duyệt","Verified documents only")]}),a?.error&&e.jsx("p",{role:"alert",className:"text-danger",children:a.error}),!a&&e.jsx("p",{role:"status",className:j,children:t("Đang tải tài liệu…","Loading documents…")}),a?.value&&e.jsxs(e.Fragment,{children:[a.value.tokens!==void 0&&e.jsxs("p",{className:j,children:[t("Token ước tính cho các trích đoạn","Estimated tokens in retrieved snippets")," · ",a.value.tokens]}),!a.value.rows.length&&e.jsx("p",{className:w,children:o||g?t("Không tìm thấy tài liệu phù hợp.","No matching documents."):t("Chưa có tài liệu ở trang này.","No documents on this page.")}),e.jsx("ul",{className:"divide-y divide-hairline",children:a.value.rows.map(d=>e.jsx("li",{children:e.jsxs("button",{type:"button",className:"flex w-full items-start gap-3 rounded-lg px-2 py-3 text-left hover:bg-control",onClick:()=>l(d.document_id),children:[e.jsx(Z,{size:18,className:"mt-0.5 shrink-0 text-ink-secondary"}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block break-words text-sm font-medium",children:d.title}),e.jsxs("span",{className:j,children:["v",d.version," · ",F(d.verification_status),"start_line"in d&&" · "+t("Dòng ","Lines ")+d.start_line+"–"+d.end_line]}),"snippet"in d&&e.jsx("span",{className:"mt-1 block whitespace-pre-wrap break-words text-sm",children:d.snippet})]})]})},d.document_id+("start_line"in d?"-"+d.start_line:"")))}),!o&&(x>0||a.value.rows.length===E)&&e.jsxs("div",{className:"flex justify-between gap-2",children:[e.jsx("button",{className:y,disabled:x===0,onClick:()=>v(d=>d-1),children:t("Trang trước","Previous page")}),e.jsx("button",{className:y,disabled:a.value.rows.length<E,onClick:()=>v(d=>d+1),children:t("Trang sau","Next page")})]})]})]})}function W({id:s,call:n,close:i,settings:l}){const[c,r]=h.useState(0),o=L(h.useCallback(async m=>s==="new"?null:(await n("read",{document_id:s},m)).document,[s,n,c]));return o?.value===void 0?e.jsxs("div",{className:w,children:[e.jsx("button",{className:y,onClick:i,children:t("Danh sách tài liệu","Documents")}),o?.error?e.jsx("p",{role:"alert",children:o.error}):e.jsx("p",{role:"status",children:t("Đang mở…","Opening…")})]}):e.jsx(ge,{doc:o.value,settings:l,call:n,close:i,refresh:()=>r(m=>m+1)},o.value?.version??"new")}function ge({doc:s,settings:n,call:i,close:l,refresh:c}){const[r,o]=h.useState(s?.title??""),[m,g]=h.useState(s?.body??""),[b,x]=h.useState(s?.tags.join(", ")??""),[v,u]=h.useState(s?.format??"md"),[f,a]=h.useState(s?.visibility??"private"),[d,p]=h.useState(!1),[T,S]=h.useState(!1),k=_(),R=n.canWrite&&(!s||s.can_write),K=r!==(s?.title??"")||m!==(s?.body??"")||b!==(s?.tags.join(", ")??""),z=()=>{(!K||window.confirm(t("Bỏ các thay đổi chưa lưu?","Discard unsaved changes?")))&&l()},X=async()=>{const N={title:r,body:m,tags:b.split(",").map(G=>G.trim()).filter(Boolean)};s?(await i("update",{...N,document_id:s.document_id,version:s.version}),c()):(await i("create",{...N,format:v,visibility:f}),l())};return e.jsxs("section",{className:w,children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("button",{type:"button",className:y,disabled:k.busy,onClick:z,children:[e.jsx(Y,{size:15}),t("Danh sách tài liệu","Documents")]}),s&&e.jsxs("span",{className:j,children:["v",s.version," · ",F(s.verification_status)," · ",s.visibility==="shared"?t("Dùng chung","Shared"):t("Riêng tư","Private")]})]}),e.jsxs("form",{className:"space-y-3",onSubmit:N=>{N.preventDefault(),k.run(X)},children:[e.jsxs("label",{className:"block text-sm",children:[t("Tiêu đề","Title"),e.jsx("input",{required:!0,maxLength:180,className:C,value:r,readOnly:!R,onChange:N=>o(N.target.value)})]}),e.jsxs("div",{className:"flex flex-wrap gap-3",children:[e.jsxs("label",{className:"min-w-36 flex-1 text-sm",children:[t("Thẻ (cách nhau bằng dấu phẩy)","Tags (comma-separated)"),e.jsx("input",{className:C,value:b,readOnly:!R,onChange:N=>x(N.target.value)})]}),!s&&e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"text-sm",children:[t("Định dạng","Format"),e.jsxs("select",{className:C,value:v,onChange:N=>u(N.target.value),children:[e.jsx("option",{value:"md",children:"Markdown"}),e.jsx("option",{value:"canvas",children:"JSON Canvas"}),e.jsx("option",{value:"base",children:"Bases"})]})]}),e.jsxs("label",{className:"text-sm",children:[t("Phạm vi","Visibility"),e.jsxs("select",{className:C,value:f,onChange:N=>a(N.target.value),children:[e.jsx("option",{value:"private",children:t("Riêng tư","Private")}),n.shared&&n.canManage&&e.jsx("option",{value:"shared",children:t("Dùng chung","Shared")})]})]})]})]}),e.jsxs("label",{className:"block text-sm",children:[t("Nội dung","Content"),e.jsx("textarea",{required:!0,maxLength:131072,rows:10,className:C+" mt-1 resize-y font-mono",value:m,readOnly:!R,onChange:N=>g(N.target.value)})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[R&&e.jsx("button",{className:D,disabled:!r.trim()||!m.trim()||k.busy||!!s&&!K,children:t("Lưu tài liệu","Save document")}),s&&e.jsx("button",{type:"button",className:y,"aria-expanded":T,onClick:()=>S(N=>!N),children:t("Nguồn, liên kết và lịch sử","Source, links and history")}),s&&R&&e.jsx("button",{type:"button",className:y+" text-danger",disabled:k.busy,onClick:()=>p(N=>!N),children:t("Xóa tài liệu","Delete document")})]})]}),d&&s&&e.jsxs("div",{role:"group",className:"space-y-2 rounded-md border border-danger/50 p-3",children:[e.jsx("p",{className:"text-sm",children:t("Xóa tài liệu này và các mục liên quan trong chỉ mục?","Delete this document and its search index entries?")}),e.jsx("button",{className:y,disabled:k.busy,onClick:()=>p(!1),children:t("Giữ tài liệu","Keep document")})," ",e.jsx("button",{className:y+" text-danger",disabled:k.busy,onClick:()=>{k.run(async()=>{await i("delete",{document_id:s.document_id,version:s.version}),l()})},children:t("Xác nhận xóa","Confirm deletion")})]}),k.error&&e.jsx("p",{role:"alert",className:"text-sm text-danger",children:k.error}),s&&T&&e.jsx(be,{doc:s,call:i,settings:n,disabled:K||k.busy,refresh:c})]})}function be({doc:s,call:n,settings:i,disabled:l,refresh:c}){const r=L(h.useCallback(async a=>{const d={document_id:s.document_id},[p,T,S]=await Promise.all([n("history",d,a),n("backlinks",d,a),s.format==="md"&&s.can_write&&i.canWrite?n("list",{limit:100},a):{documents:[]}]);return{history:p.history,backlinks:T.documents,choices:S.documents.filter(k=>k.document_id!==s.document_id&&(s.visibility!=="shared"||k.visibility==="shared"))}},[n,s.document_id,s.format,s.visibility,s.can_write,i.canWrite])),[o,m]=h.useState(""),[g,b]=h.useState(""),[x,v]=h.useState(),u=_(),f={document_id:s.document_id,version:s.version};return e.jsxs("div",{className:"space-y-3 border-t border-hairline pt-3 text-sm",children:[e.jsxs("p",{className:j,children:["ID · ",s.document_id]}),s.source_url&&e.jsxs("p",{className:"break-all",children:[t("Nguồn","Source")," · ",s.source_url]}),s.warnings?.length>0&&e.jsxs("p",{className:"rounded-lg border border-warning/50 p-2",children:[t("Nội dung có cảnh báo khi kiểm tra","Content flagged during validation")," · ",s.warnings.join(", ")]}),i.canManage&&e.jsx("div",{className:"flex flex-wrap gap-2",children:["verified","rejected","unverified"].filter(a=>a!==s.verification_status).map(a=>e.jsx("button",{className:y,disabled:l||u.busy,onClick:()=>{u.run(async()=>{await n("verify_source",{...f,verification_status:a}),c()})},children:{verified:t("Duyệt tài liệu","Verify document"),rejected:t("Từ chối","Reject"),unverified:t("Chuyển về chờ duyệt","Return to review")}[a]},a))}),i.archive&&s.source_type==="web"&&e.jsx("button",{className:y,disabled:u.busy,onClick:()=>{u.run(async()=>{const a=await n("archive",{document_id:s.document_id});b(a.html)})},children:t("Xem bản lưu ngoại tuyến","View offline archive")}),g&&e.jsx("iframe",{sandbox:"",referrerPolicy:"no-referrer",srcDoc:pe+g,title:t("Bản lưu HTML","Archived HTML"),className:"h-72 w-full rounded-md border border-hairline bg-white"}),r?.error&&e.jsx("p",{role:"alert",className:"text-danger",children:r.error}),r?.value&&e.jsxs(e.Fragment,{children:[e.jsxs("p",{children:[t("Tài liệu liên kết đến đây","Linked from")," · ",r.value.backlinks.map(a=>a.title).join(", ")||t("Chưa có","None")]}),r.value.choices.length>0&&e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("select",{className:C,value:o,"aria-label":t("Tài liệu đích","Target document"),onChange:a=>m(a.target.value),children:[e.jsx("option",{value:"",children:t("Chọn tài liệu liên quan","Choose a related document")}),r.value.choices.map(a=>e.jsx("option",{value:a.document_id,children:a.title},a.document_id))]}),e.jsx("button",{className:y,disabled:!o||l||u.busy,onClick:()=>{u.run(async()=>{await n("link",{...f,target_id:o}),c()})},children:t("Liên kết","Link")})]}),e.jsx("h4",{className:"font-medium",children:t("Lịch sử cập nhật","Revision history")}),e.jsx("ul",{className:"space-y-1",children:r.value.history.map(a=>e.jsx("li",{className:j,children:e.jsxs("button",{type:"button",className:"rounded px-2 py-1 hover:bg-control",disabled:u.busy,onClick:()=>{u.run(async()=>v((await n("read",{document_id:s.document_id,version:a.version})).document))},children:["v",a.version," · ",new Date(a.updated_at).toLocaleString()," · ",a.action]})},a.version))}),x&&e.jsxs("div",{className:w,children:[e.jsxs("p",{className:"font-medium",children:[x.title," · v",x.version]}),e.jsx("pre",{className:"max-h-60 overflow-y-auto whitespace-pre-wrap break-words",children:x.body})]})]}),u.error&&e.jsx("p",{role:"alert",className:"text-danger",children:u.error})]})}const A=2*1024*1024,H=s=>s.length<=260&&/\.(md|base|canvas)$/i.test(s)&&s.split("/").every(n=>!!n&&!n.startsWith(".")&&!n.endsWith(".")&&!n.endsWith(" ")&&!/[\\:<>|?*"]/.test(n)&&Array.from(n).every(i=>i.charCodeAt(0)>=32&&i.charCodeAt(0)!==127)&&!/^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/i.test(n)),O=()=>new Error(t("Tệp kho tri thức không hợp lệ.","Invalid vault file.")),M=()=>new Error(t("Mỗi lần nhập tối đa 64 tệp và 2 MiB. Hãy chọn ít tệp hơn.","Import up to 64 files and 2 MiB at a time. Choose fewer files."));function q(s){if(!Array.isArray(s)||!s.length||s.length>64)throw M();const n=new Set;let i=0;const l=new TextEncoder,c=s.map(r=>{if(!r||typeof r.path!="string"||!H(r.path)||typeof r.content!="string"||!r.content||r.content.length>15e4||n.has(r.path.toLowerCase()))throw O();if(i+=l.encode(r.content).length,i>A)throw M();return n.add(r.path.toLowerCase()),{path:r.path,content:r.content}});if(l.encode(JSON.stringify({files:c,dry_run:!1})).length>2e6)throw M();return c}async function fe(s,n){const i=Array.from(s);if(!n&&i.length===1&&/\.json$/i.test(i[0].name)){if(i[0].size>A*2)throw M();const c=JSON.parse(await i[0].text());if(c?.format!=="limix-knowledge-v1")throw O();return q(c.files)}const l=i.map(c=>({file:c,path:n?c.webkitRelativePath.split("/").slice(1).join("/"):c.name})).filter(({path:c})=>/\.(md|base|canvas)$/i.test(c)&&!c.split("/").some(r=>r.startsWith(".")));if(!l.length||l.length>64||l.reduce((c,r)=>c+r.file.size,0)>A)throw M();return q(await Promise.all(l.map(async({file:c,path:r})=>({path:r,content:await c.text()}))))}async function ve(s){const n=[],i=new Set;let l=0,c=0;for(;;){const{files:r,next_offset:o}=await s("export",{offset:c,limit:25});for(const m of r){if(!H(m.path)||i.has(m.path.toLowerCase())||typeof m.content!="string")throw O();if(l+=new TextEncoder().encode(m.content).length,l>48*1024*1024)throw new Error(t("Bản xuất vượt giới hạn 48 MiB của trình duyệt.","This export exceeds the browser’s 48 MiB limit."));i.add(m.path.toLowerCase()),n.push(m)}if(o==null)break;if(!Number.isSafeInteger(o)||o<=c||o>1e5)throw O();c=o}return n}async function ye(s,n,i){try{throw await s.getDirectoryHandle(n),new Error(t("Thư mục xuất đã tồn tại.","The export directory already exists."))}catch(c){if(!(c instanceof DOMException&&c.name==="NotFoundError"))throw c}const l=await s.getDirectoryHandle(n,{create:!0});for(const c of i){if(!H(c.path))throw O();let r=l;const o=c.path.split("/");for(const b of o.slice(0,-1))r=await r.getDirectoryHandle(b,{create:!0});const g=await(await r.getFileHandle(o.at(-1),{create:!0})).createWritable();try{await g.write(c.content),await g.close()}catch(b){throw await g.abort().catch(()=>{}),b}}}function je({call:s,canWrite:n}){const i=h.useRef(null),l=h.useRef(null),[c,r]=h.useState(),[o,m]=h.useState(""),g=_(),b=window.showDirectoryPicker,x=(u,f)=>{u.files?.length&&(r(void 0),m(""),g.run(async()=>{try{const a=await fe(u.files,f),d=await s("import",{files:a,dry_run:!0});r({files:a,...d})}finally{u.value=""}}))},v=u=>{g.run(async()=>{m("");let f;try{u&&b&&(f=await b.call(window,{mode:"readwrite"}))}catch(p){if(p instanceof DOMException&&p.name==="AbortError")return;throw p}const a=await ve(s);if(!a.length){m(t("Kho chưa có tài liệu để xuất.","There are no documents to export."));return}const d="Limix-Vault-"+crypto.randomUUID().slice(0,8);if(f)m(t("Đang ghi vào thư mục ","Writing to folder ")+d),await ye(f,d,a),m(t("Đã xuất ","Exported ")+a.length+t(" tệp vào "," files to ")+d);else{try{q(a)}catch{throw new Error(t("Kho lớn hơn một gói JSON. Hãy xuất thư mục bằng Chrome hoặc Edge trên máy tính.","This vault exceeds one JSON package. Use directory export in desktop Chrome or Edge."))}const p=new Blob([JSON.stringify({format:"limix-knowledge-v1",files:a})],{type:"application/json"}),T=URL.createObjectURL(p),S=document.createElement("a");S.href=T,S.download=d+".json",S.click(),setTimeout(()=>URL.revokeObjectURL(T),1e3),m(t("Đã tạo gói tải về gồm ","Created a download containing ")+a.length+t(" tệp."," files."))}})};return e.jsxs("section",{className:"space-y-3",children:[n&&e.jsxs("div",{className:w,children:[e.jsx("h4",{className:"font-medium",children:t("Nhập tài liệu Obsidian","Import Obsidian documents")}),e.jsx("p",{className:j,children:t("Chọn Markdown, Canvas, Bases hoặc gói JSON đã xuất. Bạn sẽ xem kết quả kiểm tra trước khi ghi.","Choose Markdown, Canvas, Bases or an exported JSON package. Review the preview before importing.")}),e.jsx("input",{type:"file",hidden:!0,multiple:!0,ref:u=>{i.current=u,u?.setAttribute("webkitdirectory","")},onChange:u=>x(u.currentTarget,!0)}),e.jsx("input",{type:"file",hidden:!0,multiple:!0,accept:".md,.canvas,.base,.json",ref:l,onChange:u=>x(u.currentTarget,!1)}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs("button",{className:y,disabled:g.busy,onClick:()=>i.current?.click(),children:[e.jsx(J,{size:15}),t("Chọn thư mục Vault","Choose vault folder")]}),e.jsx("button",{className:y,disabled:g.busy,onClick:()=>l.current?.click(),children:t("Chọn tệp","Choose files")})]}),c&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("p",{className:"text-sm",children:[t("Sẽ nhập","To import")," · ",c.imported," ",t("Trùng lặp","Duplicates")," · ",c.duplicates]}),e.jsxs("details",{children:[e.jsx("summary",{className:"text-sm",children:t("Xem danh sách tệp","Review file list")}),e.jsx("ul",{className:j,children:c.files.map(u=>e.jsx("li",{children:u.path},u.path))})]}),e.jsx("button",{className:D,disabled:g.busy||!c.imported,onClick:()=>{g.run(async()=>{const u=await s("import",{files:c.files,dry_run:!1});m(t("Đã nhập ","Imported ")+u.imported+t(" tài liệu."," documents.")),r(void 0)})},children:t("Xác nhận nhập","Confirm import")})]})]}),e.jsxs("div",{className:w,children:[e.jsx("h4",{className:"font-medium",children:t("Xuất Vault","Export vault")}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[b&&e.jsxs("button",{className:y,disabled:g.busy,onClick:()=>v(!0),children:[e.jsx(J,{size:15}),t("Xuất thư mục Obsidian","Export Obsidian folder")]}),e.jsxs("button",{className:y,disabled:g.busy,onClick:()=>v(!1),children:[e.jsx(ee,{size:15}),t("Tải gói JSON","Download JSON package")]})]})]}),n&&e.jsxs("div",{className:w,children:[e.jsx("p",{className:j,children:t("Sau khi chỉnh sửa tệp trong thư mục kho bằng ứng dụng khác, cập nhật chỉ mục để tìm kiếm phiên bản mới.","After editing vault files in another app, update the search index to pick up changes.")}),e.jsx("button",{className:y,disabled:g.busy,onClick:()=>{g.run(async()=>{await s("index"),m(t("Đã cập nhật chỉ mục.","Search index updated."))})},children:t("Cập nhật chỉ mục","Update search index")})]}),o&&e.jsx("p",{role:"status",className:"text-sm",children:o}),g.error&&e.jsx("p",{role:"alert",className:"text-danger",children:g.error})]})}function Ne({call:s}){const[n,i]=h.useState(""),[l,c]=h.useState(""),[r,o]=h.useState(),[m,g]=h.useState(""),b=_(),x=u=>{b.run(async()=>{let f;try{f=JSON.parse(l)}catch{throw new Error(t("Các hàng dữ liệu phải là một mảng JSON hợp lệ.","Enter the rows as a valid JSON array."))}const a={template:n,rows:f,dry_run:u};if(u)o((await s("render_template",a)).files);else{const d=await s("render_template",a);o(void 0),g(t("Đã nhập ","Imported ")+d.imported+t(" tài liệu từ mẫu."," documents from this template."))}})},v=()=>{o(void 0),g("")};return e.jsxs("details",{className:w,children:[e.jsx("summary",{className:"cursor-pointer font-medium",children:t("Tạo tài liệu từ mẫu Knap","Create documents from a Knap template")}),e.jsxs("label",{className:"block text-sm",children:[t("Mẫu Markdown","Markdown template"),e.jsx("textarea",{rows:3,className:C+" font-mono",maxLength:8192,placeholder:"# {{ title }}",value:n,disabled:b.busy,onChange:u=>{i(u.target.value),v()}})]}),e.jsxs("label",{className:"block text-sm",children:[t("Các hàng dữ liệu (JSON)","Data rows (JSON)"),e.jsx("textarea",{className:C+" font-mono",rows:3,maxLength:15e4,placeholder:'[{"filename":"report.md","variables":{"title":"Report"}}]',value:l,disabled:b.busy,onChange:u=>{c(u.target.value),v()}})]}),e.jsx("button",{className:y,disabled:!n.trim()||!l.trim()||b.busy,onClick:()=>x(!0),children:t("Xem trước","Preview template")}),r&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("ul",{className:"max-h-60 space-y-2 overflow-y-auto",children:r.map(u=>e.jsxs("li",{children:[e.jsx("p",{className:j,children:u.path}),e.jsx("pre",{className:"whitespace-pre-wrap break-words text-sm",children:u.content})]},u.path))}),e.jsx("button",{className:D,disabled:b.busy||!r.length,onClick:()=>x(!1),children:t("Ghi các tài liệu đã xem","Save reviewed documents")})]}),b.error&&e.jsx("p",{role:"alert",className:"text-sm text-danger",children:b.error}),m&&e.jsx("p",{role:"status",className:"text-sm",children:m})]})}function we({call:s,settings:n}){const[i,l]=h.useState(0),[c,r]=h.useState(""),[o,m]=h.useState(!1),[g,b]=h.useState(""),[x,v]=h.useState(0),[u,f]=h.useState(""),a=_(),d=L(h.useCallback(p=>s("list_sources",{limit:25,offset:25*x},p),[s,i,x]));return g?e.jsx(W,{id:g,settings:n,call:s,close:()=>{b(""),l(p=>p+1)}}):e.jsxs("section",{className:"space-y-3",children:[n.collection&&n.canWrite&&e.jsxs("form",{className:w,onSubmit:p=>{p.preventDefault(),f(""),a.run(async()=>{const T=await s("ingest",{url:c.trim(),archive:n.archive&&o});f(T.archived?t("Đã lưu nguồn và bản HTML ngoại tuyến.","Saved the source and its offline HTML."):t("Đã lưu nguồn.","Source saved.")),r(""),v(0),l(S=>S+1)})},children:[e.jsxs("label",{className:"block text-sm",children:[t("URL nguồn công khai","Public source URL"),e.jsx("input",{required:!0,type:"url",maxLength:2048,className:C,value:c,onChange:p=>r(p.target.value)})]}),n.archive&&e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:o,onChange:p=>m(p.target.checked)}),t("Lưu thêm bản HTML ngoại tuyến","Keep an offline HTML copy")]}),e.jsx("button",{className:D,disabled:a.busy||!c.trim(),children:a.busy?t("Đang thu thập…","Collecting…"):t("Thu thập nguồn","Collect source")})]}),!n.collection&&e.jsx("p",{className:j,children:t("Bật Thu thập website trong Cài đặt để thêm nguồn từ URL.","Enable website collection in Settings to add a source by URL.")}),a.error&&e.jsx("p",{role:"alert",className:"text-danger",children:a.error}),u&&e.jsx("p",{role:"status",className:"text-sm",children:u}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h4",{className:"font-medium",children:t("Nguồn đã lưu","Saved sources")}),e.jsxs("button",{type:"button",className:y,onClick:()=>l(p=>p+1),children:[e.jsx(de,{size:14}),t("Làm mới","Refresh")]})]}),d?.error&&e.jsx("p",{role:"alert",className:"text-danger",children:d.error}),d?.value?.documents.length===0&&e.jsx("p",{className:j,children:t("Chưa có nguồn ở trang này.","No sources on this page.")}),e.jsx("ul",{className:"divide-y divide-hairline",children:d?.value?.documents.map(p=>e.jsx("li",{children:e.jsxs("button",{className:"w-full rounded-lg p-2 text-left hover:bg-control",onClick:()=>b(p.document_id),children:[e.jsx("span",{className:"block break-words text-sm font-medium",children:p.title}),e.jsx("span",{className:j+" block break-all",children:p.source_url}),e.jsxs("span",{className:j,children:[F(p.verification_status)," · v",p.version]})]})},p.document_id))}),(x>0||d?.value?.documents.length===25)&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{className:y,disabled:!x,onClick:()=>v(p=>p-1),children:t("Trang trước","Previous page")}),e.jsx("button",{className:y,disabled:d?.value?.documents.length!==25,onClick:()=>v(p=>p+1),children:t("Trang sau","Next page")})]}),n.collection&&e.jsx(ke,{call:s,canWrite:n.canWrite,active:a.busy,revision:i,onChange:()=>l(p=>p+1)})]})}function U(s){return{new:t("Mới","New"),done:t("Hoàn tất","Completed"),running:t("Đang chạy","Running"),cancelled:t("Đã hủy","Cancelled"),failed:t("Lỗi","Failed"),skipped:t("Bỏ qua","Skipped")}[s]??s}function ke({call:s,canWrite:n,active:i,revision:l,onChange:c}){const[r,o]=h.useState(0),m=_(),g=_();h.useEffect(()=>{if(!i&&!m.busy)return;const x=setInterval(()=>{document.hidden||o(v=>v+1)},3e3);return()=>clearInterval(x)},[i,m.busy]);const b=L(h.useCallback(x=>s("jobs",{},x),[s,l,r]));return e.jsxs("div",{className:w,children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("h4",{className:"font-medium",children:t("Quy trình thu thập","Collection jobs")}),e.jsx("button",{className:y,onClick:()=>o(x=>x+1),children:t("Cập nhật trạng thái","Refresh jobs")})]}),b?.value?.jobs.length===0&&e.jsx("p",{className:j,children:t("Chưa có lần thu thập nào.","No collection jobs yet.")}),b?.value?.jobs.map(x=>e.jsxs("details",{className:"rounded border border-hairline px-2 py-1.5 text-sm",children:[e.jsxs("summary",{className:"cursor-pointer break-all",children:[U(x.status)," · ",x.source_url]}),e.jsx("p",{className:j,children:new Date(x.updated_at).toLocaleString()}),e.jsx("ol",{className:j,children:x.steps.map(v=>e.jsxs("li",{children:[v.stage," · ",U(v.status)," · ",v.attempts]},v.stage))}),n&&x.status==="running"&&e.jsx("button",{className:y,disabled:g.busy,onClick:()=>{g.run(async()=>{await s("cancel",{job_id:x.job_id}),c()})},children:t("Hủy quy trình","Cancel job")}),n&&["failed","cancelled"].includes(x.status)&&e.jsx("button",{className:y,disabled:m.busy,onClick:()=>{m.run(async()=>{await s("ingest",{url:x.source_url,archive:x.archive}),c()})},children:t("Tiếp tục thu thập","Resume collection")})]},x.job_id)),(m.error||g.error||b?.error)&&e.jsx("p",{role:"alert",className:"text-danger",children:m.error||g.error||b?.error})]})}function Ce({call:s}){const n=L(h.useCallback(r=>s("graph",{limit:100},r),[s]));if(n?.error)return e.jsx("p",{role:"alert",children:n.error});if(!n?.value)return e.jsx("p",{role:"status",children:t("Đang đọc liên kết…","Loading links…")});const{nodes:i,edges:l}=n.value,c=new Map(i.map(r=>[r.id,r.title]));return e.jsxs("section",{className:w,children:[e.jsx("h4",{className:"font-medium",children:t("Mạng lưới tri thức","Knowledge graph")}),e.jsxs("p",{className:j,children:[i.length," ",t("tài liệu","documents")," · ",l.length," ",t("liên kết","links")]}),e.jsx("ul",{className:"space-y-2",children:l.map(r=>e.jsxs("li",{className:"flex flex-wrap items-center gap-2 text-sm",children:[e.jsx("span",{children:c.get(r.from)}),e.jsx(te,{size:15,"aria-label":t("Liên kết đến","Links to")}),e.jsx("span",{children:c.get(r.to)})]},r.from+"/"+r.to))}),!l.length&&e.jsx("p",{className:j,children:t("Mở một tài liệu để liên kết tới tài liệu khác trong kho.","Open a document to link it to another document in the vault.")})]})}function Se({call:s,settings:n,openMemory:i}){const[l,c]=h.useState(""),[r,o]=h.useState(""),[m,g]=h.useState(),[b,x]=h.useState(),[v,u]=h.useState(""),f=_();return e.jsxs("section",{className:"space-y-3",children:[e.jsxs("form",{className:w,onSubmit:a=>{a.preventDefault(),f.run(async()=>{const{results:d}=await s("memory_recall",{query:l,limit:12});g(d)})},children:[e.jsxs("label",{className:"block text-sm",children:[t("Tìm trong bộ nhớ","Search memory"),e.jsx("input",{required:!0,type:"search",maxLength:400,className:C,value:l,onChange:a=>c(a.target.value)})]}),e.jsx("button",{className:y,disabled:f.busy||!l.trim(),children:t("Tìm ký ức","Recall")}),m?.length===0&&e.jsx("p",{className:j,children:t("Không tìm thấy ký ức phù hợp.","No matching memories.")}),m?.map((a,d)=>e.jsxs("div",{children:[e.jsx("p",{className:j,children:a.path}),e.jsx("p",{className:"whitespace-pre-wrap break-words text-sm",children:a.snippet})]},a.path+d))]}),n.canWriteMemory&&e.jsxs("form",{className:w,onSubmit:a=>{a.preventDefault(),f.run(async()=>{const d=await s("memory_store",{text:r});o(""),g(void 0),x(void 0),u(d.duplicate?t("Ký ức này đã có.","This memory already exists."):t("Đã ghi vào bộ nhớ của bot.","Saved to the bot’s memory."))})},children:[e.jsxs("label",{className:"block text-sm",children:[t("Thông tin cần ghi nhớ","Fact to remember"),e.jsx("textarea",{required:!0,rows:3,maxLength:1e3,className:C,value:r,onChange:a=>{o(a.target.value),u("")}})]}),e.jsx("button",{className:D,disabled:f.busy||!r.trim(),children:t("Lưu ký ức","Save memory")}),v&&e.jsx("p",{role:"status",className:"text-sm",children:v})]}),e.jsxs("div",{className:w,children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{className:y,disabled:f.busy,onClick:()=>{f.run(async()=>x(await s("memory_consolidate")))},children:t("Rà soát ký ức","Review memories")}),e.jsx("button",{className:y,onClick:i,children:t("Quản lý sổ nhớ của bot","Manage bot memory")})]}),b&&e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-sm",children:[t("Trùng lặp","Duplicates")," · ",b.duplicates," ",t("Hết hạn","Expired")," · ",b.expired," ",t("Có thể mâu thuẫn","Potential conflicts")," · ",b.possible_conflicts.length]}),b.possible_conflicts.map((a,d)=>e.jsxs("p",{className:j,children:[a.first,e.jsx("br",{}),a.second]},d))]})]}),f.error&&e.jsx("p",{role:"alert",className:"text-danger",children:f.error})]})}function Ke(){const{state:s,dispatch:n}=se(),i=s.bots.filter(o=>!o.hidden&&!o.movedTo),[l,c]=h.useState(""),r=i.find(o=>o.id===l);return e.jsxs("section",{"aria-label":t("Kho Tri Thức","Knowledge Vault"),className:"space-y-4 text-ink",children:[e.jsxs("div",{className:"flex flex-wrap items-end justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"flex items-center gap-2 text-xl font-semibold",children:[e.jsx(V,{size:21}),t("Kho Tri Thức","Knowledge Vault")]}),e.jsx("p",{className:"mt-1 text-sm text-ink-secondary",children:t("Chọn bot để quản lý tài liệu, nguồn và bộ nhớ của bot.","Choose a bot to manage its documents, sources and memory.")})]}),e.jsxs("select",{className:C+" sm:w-56","aria-label":t("Chọn bot","Choose a bot"),value:r?.id??"",onChange:o=>c(o.target.value),children:[e.jsx("option",{value:"",children:t("Chọn bot…","Choose a bot…")}),i.map(o=>e.jsx("option",{value:o.id,children:o.name},o.id))]})]}),!i.length&&e.jsx("p",{className:j,children:t("Chưa có bot trong danh sách của bạn.","You have no bots in this workspace.")}),r&&e.jsx(Te,{botId:r.id,openMemory:()=>{n({type:"togglePlugins",open:!1}),ne(n,"memory",{botId:r.id})}},r.id)]})}function Te({botId:s,openMemory:n}){const i=me(s),[l,c]=h.useState(0),r=L(h.useCallback(a=>B(P(s)+"settings",{signal:a}),[s,l])),o=r?.value,m=_(),[g,b]=h.useState("documents"),x=(a,d)=>{m.run(async()=>{await B(P(s)+"settings",{method:"PUT",body:JSON.stringify({[a]:d})}),a==="enabled"&&b("documents"),c(p=>p+1)})};if(r?.error)return e.jsxs("div",{className:w,children:[e.jsx("p",{role:"alert",children:r.error}),e.jsx("button",{className:y,onClick:()=>c(a=>a+1),children:t("Thử lại","Try again")})]});if(!o)return e.jsx("p",{role:"status",className:j,children:t("Đang tải quyền truy cập…","Loading access settings…")});const v=[{id:"documents",label:t("Tài liệu","Documents"),icon:V},{id:"sources",label:t("Nguồn dữ liệu","Sources"),icon:ae},...o.memory?[{id:"memory",label:t("Bộ nhớ AI","AI memory"),icon:ie}]:[],{id:"graph",label:t("Liên kết","Links"),icon:re},{id:"transfer",label:t("Nhập và xuất","Import and export"),icon:ce},{id:"settings",label:t("Cài đặt","Settings"),icon:he}],u=v.some(a=>a.id===g)?g:"documents",f=(a,d,p)=>e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:d}),e.jsx("p",{className:j,children:p})]}),e.jsx(oe,{"aria-label":d,checked:o[a],disabled:!o.canManage||m.busy,onClick:()=>x(a,!o[a])})]},a);return e.jsxs(e.Fragment,{children:[m.error&&e.jsx("p",{role:"alert",className:"text-sm text-danger",children:m.error}),(!o.enabled||u==="settings")&&e.jsxs("div",{className:w,children:[f("enabled",t("Bật Kho Tri Thức cho bot","Enable Knowledge Vault for this bot"),t("Lưu trữ và truy xuất tài liệu trong không gian làm việc này.","Store and retrieve documents in this workspace.")),!o.canManage&&e.jsx("p",{className:j,children:t("Quản trị viên của không gian làm việc có thể thay đổi cài đặt này.","A workspace administrator can change these settings.")})]}),o.enabled&&e.jsxs(e.Fragment,{children:[e.jsx("nav",{"aria-label":t("Chức năng Kho Tri Thức","Knowledge Vault sections"),className:"flex flex-wrap gap-1 border-b border-hairline pb-2",children:v.map(({id:a,label:d,icon:p})=>e.jsxs("button",{type:"button","aria-pressed":u===a,onClick:()=>b(a),className:"inline-flex items-center gap-1.5 rounded-lg px-2.5 py-2 text-sm "+(u===a?"bg-raised font-medium text-ink":"text-ink-secondary hover:bg-control"),children:[e.jsx(p,{size:15}),d]},a))}),u==="documents"&&e.jsx(xe,{call:i,settings:o}),u==="sources"&&e.jsx(we,{call:i,settings:o}),u==="memory"&&e.jsx(Se,{call:i,settings:o,openMemory:n}),u==="graph"&&e.jsx(Ce,{call:i}),u==="transfer"&&e.jsxs(e.Fragment,{children:[e.jsx(je,{call:i,canWrite:o.canWrite}),o.collection&&o.canWrite&&e.jsx(Ne,{call:i})]}),u==="settings"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:w,children:[f("collection",t("Thu thập website","Collect websites"),t("Cho phép nhập nội dung từ một URL công khai.","Allow importing content from a public URL.")),f("archive",t("Lưu bản HTML","Keep HTML archives"),t("Lưu thêm bản xem ngoại tuyến khi thu thập website.","Keep an offline copy when collecting a website.")),f("memory",t("Truy cập bộ nhớ AI","Access AI memory"),t("Dùng bộ nhớ hiện có của bot qua Kho Tri Thức.","Use the bot’s existing memory through Knowledge Vault.")),f("shared",t("Tài liệu dùng chung","Shared documents"),t("Cho phép bot sử dụng tài liệu dùng chung theo quyền được cấp.","Let the bot use shared workspace documents according to its permissions.")),f("semantic",t("Tìm kiếm ngữ nghĩa","Semantic search"),t("Cho phép gửi trích đoạn tới nhà cung cấp embedding đã cấu hình khi tìm kiếm.","Allow search to send excerpts to the configured embedding provider."))]}),e.jsx(_e,{call:i})]})]})]})}function _e({call:s}){const n=L(h.useCallback(l=>s("get_stats",{},l),[s]));if(n?.error)return e.jsx("p",{role:"alert",className:"text-danger",children:n.error});if(!n?.value)return e.jsx("p",{role:"status",className:j,children:t("Đang tính dung lượng…","Loading storage usage…")});const i=n.value;return e.jsx("dl",{className:"grid grid-cols-2 gap-3 sm:grid-cols-4",children:[[t("Tài liệu","Documents"),i.documents],[t("Đã duyệt","Verified"),i.verified],[t("Nguồn","Sources"),i.sources],[t("Dung lượng","Storage"),(i.bytes/1048576).toFixed(2)+" / "+(i.quota_bytes/1048576).toFixed(1)+" MiB"],...i.embedding_requests===void 0?[]:[[t("Lượt gọi embedding","Embedding requests"),i.embedding_requests]],...i.embedding_tokens==null?[]:[[t("Token embedding","Embedding tokens"),i.embedding_tokens]]].map(([l,c])=>e.jsxs("div",{className:"rounded-xl border border-hairline p-3",children:[e.jsx("dt",{className:j,children:l}),e.jsx("dd",{className:"font-medium",children:c})]},l))})}export{Ke as KnowledgePanel};
|
|
1
|
+
import{c as Q,r as h,j as e,S as $,C as Y}from"./styles-DO3EUxm2.js";import{j as B,x as t,ab as Z,af as J,K as ee,bV as te,u as se,bE as V,ah as ne,G as ae,bG as ie,bW as re,bX as ce,S as oe}from"./App-BgdjoCaG.js";import{P as le}from"./PlacesRail-tZyNm-l3.js";import{R as de}from"./MenuMotion-B0aZnuh_.js";import"./index-BQM4L4RU.js";import"./monitor-zecPzfR5.js";const ue=[["path",{d:"M14 17H5",key:"gfn3mx"}],["path",{d:"M19 7h-9",key:"6i9tg"}],["circle",{cx:"17",cy:"17",r:"3",key:"18b49y"}],["circle",{cx:"7",cy:"7",r:"3",key:"dfmy0x"}]],he=Q("settings-2",ue);function P(s){return"/api/bots/"+encodeURIComponent(s)+"/knowledge/"}function me(s){return h.useCallback((n,i={},l)=>B(P(s)+n,{method:"POST",body:JSON.stringify(i),signal:l}),[s])}function I(s){const n=s?.status,i=s instanceof Error?s.message:"",l={"No offline snapshot for this source.":"Nguồn này chưa có bản HTML ngoại tuyến.","Document changed on disk. Index it before editing.":"Tệp đã được sửa bên ngoài. Hãy cập nhật chỉ mục rồi mở lại tài liệu.","A shared link needs a shared target.":"Tài liệu dùng chung chỉ có thể liên kết đến tài liệu dùng chung.","Memory access is disabled for this caller.":"Quyền truy cập bộ nhớ của bot đang tắt.","Vault quota reached.":"Kho đã đạt giới hạn dung lượng.","Invalid Canvas JSON.":"Nội dung Canvas phải là JSON hợp lệ.","A Base needs a views list.":"Tệp Bases phải có danh sách views.","Untrusted instructions cannot become a memory.":"Nội dung có dấu hiệu chứa chỉ dẫn ngoài nguồn tin cậy nên chưa được lưu vào bộ nhớ."};return Object.hasOwn(l,i)?t(l[i],i):n===403?t("Bạn không có quyền thực hiện thao tác này.","You do not have permission for this action."):n===400?t("Dữ liệu đầu vào không hợp lệ. Kiểm tra định dạng và giới hạn của trường.",i):n===404?t("Không tìm thấy mục này hoặc bạn không có quyền mở.",i):n===409?t("Dữ liệu đã thay đổi. Hãy mở lại bản mới nhất trước khi lưu.","The data changed. Open the latest version before saving."):n===413?t("Dữ liệu vượt giới hạn dung lượng.",i):n===429?t("Đã đạt giới hạn yêu cầu. Hãy thử lại sau một phút.",i):n&&n>=500?t("Máy chủ chưa thể hoàn tất thao tác.",i):s instanceof Error?s.message:t("Không thể hoàn tất thao tác.","The operation could not be completed.")}function _(){const s=h.useRef(!1),[n,i]=h.useState(!1),[l,c]=h.useState("");return{run:async o=>{if(!s.current){s.current=!0,i(!0),c("");try{await o()}catch(m){c(I(m))}finally{s.current=!1,i(!1)}}},busy:n,error:l}}function L(s){const[n,i]=h.useState();return h.useEffect(()=>{const l=new AbortController;return s(l.signal).then(c=>{l.signal.aborted||i({load:s,value:c})}).catch(c=>{l.signal.aborted||i({load:s,error:I(c)})}),()=>l.abort()},[s]),n?.load===s?n:void 0}const y="inline-flex items-center justify-center gap-1.5 rounded-lg bg-control px-3 py-1.5 text-sm font-medium text-ink enabled:hover:bg-raised-hover disabled:opacity-45",D="inline-flex items-center justify-center gap-1.5 rounded-lg bg-ink px-3 py-1.5 text-sm font-medium text-app disabled:opacity-45",C="w-full min-w-0 rounded-lg border border-hairline bg-control px-3 py-2 text-sm text-ink",w="space-y-3 rounded-xl border border-hairline bg-menu p-4",j="text-xs leading-5 text-ink-secondary",F=s=>({verified:t("Đã duyệt","Verified"),rejected:t("Đã từ chối","Rejected"),unverified:t("Chưa kiểm duyệt","Awaiting review")})[s],E=25,pe=`<meta http-equiv="Content-Security-Policy" content="default-src 'none'; base-uri 'none'; form-action 'none'">`;function xe({call:s,settings:n}){const[i,l]=h.useState(""),[c,r]=h.useState(""),[o,m]=h.useState(""),[g,b]=h.useState(!1),[x,v]=h.useState(0),[u,f]=h.useState(0),a=L(h.useCallback(async d=>{const p={limit:E,verified_only:g};if(o){const S=await s("search",{...p,query:o,token_budget:1200},d);return{rows:S.results,tokens:S.estimated_tokens}}return{rows:(await s("list",{...p,offset:x*E},d)).documents,tokens:void 0}},[s,o,g,x,u]));return i?e.jsx(W,{id:i,call:s,settings:n,close:()=>{l(""),f(d=>d+1)}},i):e.jsxs("section",{className:"space-y-3",children:[e.jsxs("form",{className:"flex flex-wrap items-center gap-2",onSubmit:d=>{d.preventDefault(),v(0),m(c.trim()),f(p=>p+1)},children:[e.jsxs("label",{className:"relative min-w-40 flex-1",children:[e.jsx($,{className:"absolute left-3 top-2.5 text-ink-secondary",size:15}),e.jsx("input",{type:"search",maxLength:400,className:C+" pl-9","aria-label":t("Tìm tri thức","Search knowledge"),placeholder:t("Tìm tri thức…","Search knowledge…"),value:c,onChange:d=>r(d.target.value)})]}),e.jsx("button",{className:y,children:t("Tìm","Search")}),n.canWrite&&e.jsxs("button",{type:"button",className:D,onClick:()=>l("new"),children:[e.jsx(le,{size:15}),t("Tạo tài liệu","New document")]})]}),e.jsxs("label",{className:"inline-flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:g,onChange:d=>{b(d.target.checked),v(0)}}),t("Chỉ tài liệu đã duyệt","Verified documents only")]}),a?.error&&e.jsx("p",{role:"alert",className:"text-danger",children:a.error}),!a&&e.jsx("p",{role:"status",className:j,children:t("Đang tải tài liệu…","Loading documents…")}),a?.value&&e.jsxs(e.Fragment,{children:[a.value.tokens!==void 0&&e.jsxs("p",{className:j,children:[t("Token ước tính cho các trích đoạn","Estimated tokens in retrieved snippets")," · ",a.value.tokens]}),!a.value.rows.length&&e.jsx("p",{className:w,children:o||g?t("Không tìm thấy tài liệu phù hợp.","No matching documents."):t("Chưa có tài liệu ở trang này.","No documents on this page.")}),e.jsx("ul",{className:"divide-y divide-hairline",children:a.value.rows.map(d=>e.jsx("li",{children:e.jsxs("button",{type:"button",className:"flex w-full items-start gap-3 rounded-lg px-2 py-3 text-left hover:bg-control",onClick:()=>l(d.document_id),children:[e.jsx(Z,{size:18,className:"mt-0.5 shrink-0 text-ink-secondary"}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block break-words text-sm font-medium",children:d.title}),e.jsxs("span",{className:j,children:["v",d.version," · ",F(d.verification_status),"start_line"in d&&" · "+t("Dòng ","Lines ")+d.start_line+"–"+d.end_line]}),"snippet"in d&&e.jsx("span",{className:"mt-1 block whitespace-pre-wrap break-words text-sm",children:d.snippet})]})]})},d.document_id+("start_line"in d?"-"+d.start_line:"")))}),!o&&(x>0||a.value.rows.length===E)&&e.jsxs("div",{className:"flex justify-between gap-2",children:[e.jsx("button",{className:y,disabled:x===0,onClick:()=>v(d=>d-1),children:t("Trang trước","Previous page")}),e.jsx("button",{className:y,disabled:a.value.rows.length<E,onClick:()=>v(d=>d+1),children:t("Trang sau","Next page")})]})]})]})}function W({id:s,call:n,close:i,settings:l}){const[c,r]=h.useState(0),o=L(h.useCallback(async m=>s==="new"?null:(await n("read",{document_id:s},m)).document,[s,n,c]));return o?.value===void 0?e.jsxs("div",{className:w,children:[e.jsx("button",{className:y,onClick:i,children:t("Danh sách tài liệu","Documents")}),o?.error?e.jsx("p",{role:"alert",children:o.error}):e.jsx("p",{role:"status",children:t("Đang mở…","Opening…")})]}):e.jsx(ge,{doc:o.value,settings:l,call:n,close:i,refresh:()=>r(m=>m+1)},o.value?.version??"new")}function ge({doc:s,settings:n,call:i,close:l,refresh:c}){const[r,o]=h.useState(s?.title??""),[m,g]=h.useState(s?.body??""),[b,x]=h.useState(s?.tags.join(", ")??""),[v,u]=h.useState(s?.format??"md"),[f,a]=h.useState(s?.visibility??"private"),[d,p]=h.useState(!1),[T,S]=h.useState(!1),k=_(),R=n.canWrite&&(!s||s.can_write),K=r!==(s?.title??"")||m!==(s?.body??"")||b!==(s?.tags.join(", ")??""),z=()=>{(!K||window.confirm(t("Bỏ các thay đổi chưa lưu?","Discard unsaved changes?")))&&l()},X=async()=>{const N={title:r,body:m,tags:b.split(",").map(G=>G.trim()).filter(Boolean)};s?(await i("update",{...N,document_id:s.document_id,version:s.version}),c()):(await i("create",{...N,format:v,visibility:f}),l())};return e.jsxs("section",{className:w,children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("button",{type:"button",className:y,disabled:k.busy,onClick:z,children:[e.jsx(Y,{size:15}),t("Danh sách tài liệu","Documents")]}),s&&e.jsxs("span",{className:j,children:["v",s.version," · ",F(s.verification_status)," · ",s.visibility==="shared"?t("Dùng chung","Shared"):t("Riêng tư","Private")]})]}),e.jsxs("form",{className:"space-y-3",onSubmit:N=>{N.preventDefault(),k.run(X)},children:[e.jsxs("label",{className:"block text-sm",children:[t("Tiêu đề","Title"),e.jsx("input",{required:!0,maxLength:180,className:C,value:r,readOnly:!R,onChange:N=>o(N.target.value)})]}),e.jsxs("div",{className:"flex flex-wrap gap-3",children:[e.jsxs("label",{className:"min-w-36 flex-1 text-sm",children:[t("Thẻ (cách nhau bằng dấu phẩy)","Tags (comma-separated)"),e.jsx("input",{className:C,value:b,readOnly:!R,onChange:N=>x(N.target.value)})]}),!s&&e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"text-sm",children:[t("Định dạng","Format"),e.jsxs("select",{className:C,value:v,onChange:N=>u(N.target.value),children:[e.jsx("option",{value:"md",children:"Markdown"}),e.jsx("option",{value:"canvas",children:"JSON Canvas"}),e.jsx("option",{value:"base",children:"Bases"})]})]}),e.jsxs("label",{className:"text-sm",children:[t("Phạm vi","Visibility"),e.jsxs("select",{className:C,value:f,onChange:N=>a(N.target.value),children:[e.jsx("option",{value:"private",children:t("Riêng tư","Private")}),n.shared&&n.canManage&&e.jsx("option",{value:"shared",children:t("Dùng chung","Shared")})]})]})]})]}),e.jsxs("label",{className:"block text-sm",children:[t("Nội dung","Content"),e.jsx("textarea",{required:!0,maxLength:131072,rows:10,className:C+" mt-1 resize-y font-mono",value:m,readOnly:!R,onChange:N=>g(N.target.value)})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[R&&e.jsx("button",{className:D,disabled:!r.trim()||!m.trim()||k.busy||!!s&&!K,children:t("Lưu tài liệu","Save document")}),s&&e.jsx("button",{type:"button",className:y,"aria-expanded":T,onClick:()=>S(N=>!N),children:t("Nguồn, liên kết và lịch sử","Source, links and history")}),s&&R&&e.jsx("button",{type:"button",className:y+" text-danger",disabled:k.busy,onClick:()=>p(N=>!N),children:t("Xóa tài liệu","Delete document")})]})]}),d&&s&&e.jsxs("div",{role:"group",className:"space-y-2 rounded-md border border-danger/50 p-3",children:[e.jsx("p",{className:"text-sm",children:t("Xóa tài liệu này và các mục liên quan trong chỉ mục?","Delete this document and its search index entries?")}),e.jsx("button",{className:y,disabled:k.busy,onClick:()=>p(!1),children:t("Giữ tài liệu","Keep document")})," ",e.jsx("button",{className:y+" text-danger",disabled:k.busy,onClick:()=>{k.run(async()=>{await i("delete",{document_id:s.document_id,version:s.version}),l()})},children:t("Xác nhận xóa","Confirm deletion")})]}),k.error&&e.jsx("p",{role:"alert",className:"text-sm text-danger",children:k.error}),s&&T&&e.jsx(be,{doc:s,call:i,settings:n,disabled:K||k.busy,refresh:c})]})}function be({doc:s,call:n,settings:i,disabled:l,refresh:c}){const r=L(h.useCallback(async a=>{const d={document_id:s.document_id},[p,T,S]=await Promise.all([n("history",d,a),n("backlinks",d,a),s.format==="md"&&s.can_write&&i.canWrite?n("list",{limit:100},a):{documents:[]}]);return{history:p.history,backlinks:T.documents,choices:S.documents.filter(k=>k.document_id!==s.document_id&&(s.visibility!=="shared"||k.visibility==="shared"))}},[n,s.document_id,s.format,s.visibility,s.can_write,i.canWrite])),[o,m]=h.useState(""),[g,b]=h.useState(""),[x,v]=h.useState(),u=_(),f={document_id:s.document_id,version:s.version};return e.jsxs("div",{className:"space-y-3 border-t border-hairline pt-3 text-sm",children:[e.jsxs("p",{className:j,children:["ID · ",s.document_id]}),s.source_url&&e.jsxs("p",{className:"break-all",children:[t("Nguồn","Source")," · ",s.source_url]}),s.warnings?.length>0&&e.jsxs("p",{className:"rounded-lg border border-warning/50 p-2",children:[t("Nội dung có cảnh báo khi kiểm tra","Content flagged during validation")," · ",s.warnings.join(", ")]}),i.canManage&&e.jsx("div",{className:"flex flex-wrap gap-2",children:["verified","rejected","unverified"].filter(a=>a!==s.verification_status).map(a=>e.jsx("button",{className:y,disabled:l||u.busy,onClick:()=>{u.run(async()=>{await n("verify_source",{...f,verification_status:a}),c()})},children:{verified:t("Duyệt tài liệu","Verify document"),rejected:t("Từ chối","Reject"),unverified:t("Chuyển về chờ duyệt","Return to review")}[a]},a))}),i.archive&&s.source_type==="web"&&e.jsx("button",{className:y,disabled:u.busy,onClick:()=>{u.run(async()=>{const a=await n("archive",{document_id:s.document_id});b(a.html)})},children:t("Xem bản lưu ngoại tuyến","View offline archive")}),g&&e.jsx("iframe",{sandbox:"",referrerPolicy:"no-referrer",srcDoc:pe+g,title:t("Bản lưu HTML","Archived HTML"),className:"h-72 w-full rounded-md border border-hairline bg-white"}),r?.error&&e.jsx("p",{role:"alert",className:"text-danger",children:r.error}),r?.value&&e.jsxs(e.Fragment,{children:[e.jsxs("p",{children:[t("Tài liệu liên kết đến đây","Linked from")," · ",r.value.backlinks.map(a=>a.title).join(", ")||t("Chưa có","None")]}),r.value.choices.length>0&&e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("select",{className:C,value:o,"aria-label":t("Tài liệu đích","Target document"),onChange:a=>m(a.target.value),children:[e.jsx("option",{value:"",children:t("Chọn tài liệu liên quan","Choose a related document")}),r.value.choices.map(a=>e.jsx("option",{value:a.document_id,children:a.title},a.document_id))]}),e.jsx("button",{className:y,disabled:!o||l||u.busy,onClick:()=>{u.run(async()=>{await n("link",{...f,target_id:o}),c()})},children:t("Liên kết","Link")})]}),e.jsx("h4",{className:"font-medium",children:t("Lịch sử cập nhật","Revision history")}),e.jsx("ul",{className:"space-y-1",children:r.value.history.map(a=>e.jsx("li",{className:j,children:e.jsxs("button",{type:"button",className:"rounded px-2 py-1 hover:bg-control",disabled:u.busy,onClick:()=>{u.run(async()=>v((await n("read",{document_id:s.document_id,version:a.version})).document))},children:["v",a.version," · ",new Date(a.updated_at).toLocaleString()," · ",a.action]})},a.version))}),x&&e.jsxs("div",{className:w,children:[e.jsxs("p",{className:"font-medium",children:[x.title," · v",x.version]}),e.jsx("pre",{className:"max-h-60 overflow-y-auto whitespace-pre-wrap break-words",children:x.body})]})]}),u.error&&e.jsx("p",{role:"alert",className:"text-danger",children:u.error})]})}const A=2*1024*1024,H=s=>s.length<=260&&/\.(md|base|canvas)$/i.test(s)&&s.split("/").every(n=>!!n&&!n.startsWith(".")&&!n.endsWith(".")&&!n.endsWith(" ")&&!/[\\:<>|?*"]/.test(n)&&Array.from(n).every(i=>i.charCodeAt(0)>=32&&i.charCodeAt(0)!==127)&&!/^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/i.test(n)),O=()=>new Error(t("Tệp kho tri thức không hợp lệ.","Invalid vault file.")),M=()=>new Error(t("Mỗi lần nhập tối đa 64 tệp và 2 MiB. Hãy chọn ít tệp hơn.","Import up to 64 files and 2 MiB at a time. Choose fewer files."));function q(s){if(!Array.isArray(s)||!s.length||s.length>64)throw M();const n=new Set;let i=0;const l=new TextEncoder,c=s.map(r=>{if(!r||typeof r.path!="string"||!H(r.path)||typeof r.content!="string"||!r.content||r.content.length>15e4||n.has(r.path.toLowerCase()))throw O();if(i+=l.encode(r.content).length,i>A)throw M();return n.add(r.path.toLowerCase()),{path:r.path,content:r.content}});if(l.encode(JSON.stringify({files:c,dry_run:!1})).length>2e6)throw M();return c}async function fe(s,n){const i=Array.from(s);if(!n&&i.length===1&&/\.json$/i.test(i[0].name)){if(i[0].size>A*2)throw M();const c=JSON.parse(await i[0].text());if(c?.format!=="limix-knowledge-v1")throw O();return q(c.files)}const l=i.map(c=>({file:c,path:n?c.webkitRelativePath.split("/").slice(1).join("/"):c.name})).filter(({path:c})=>/\.(md|base|canvas)$/i.test(c)&&!c.split("/").some(r=>r.startsWith(".")));if(!l.length||l.length>64||l.reduce((c,r)=>c+r.file.size,0)>A)throw M();return q(await Promise.all(l.map(async({file:c,path:r})=>({path:r,content:await c.text()}))))}async function ve(s){const n=[],i=new Set;let l=0,c=0;for(;;){const{files:r,next_offset:o}=await s("export",{offset:c,limit:25});for(const m of r){if(!H(m.path)||i.has(m.path.toLowerCase())||typeof m.content!="string")throw O();if(l+=new TextEncoder().encode(m.content).length,l>48*1024*1024)throw new Error(t("Bản xuất vượt giới hạn 48 MiB của trình duyệt.","This export exceeds the browser’s 48 MiB limit."));i.add(m.path.toLowerCase()),n.push(m)}if(o==null)break;if(!Number.isSafeInteger(o)||o<=c||o>1e5)throw O();c=o}return n}async function ye(s,n,i){try{throw await s.getDirectoryHandle(n),new Error(t("Thư mục xuất đã tồn tại.","The export directory already exists."))}catch(c){if(!(c instanceof DOMException&&c.name==="NotFoundError"))throw c}const l=await s.getDirectoryHandle(n,{create:!0});for(const c of i){if(!H(c.path))throw O();let r=l;const o=c.path.split("/");for(const b of o.slice(0,-1))r=await r.getDirectoryHandle(b,{create:!0});const g=await(await r.getFileHandle(o.at(-1),{create:!0})).createWritable();try{await g.write(c.content),await g.close()}catch(b){throw await g.abort().catch(()=>{}),b}}}function je({call:s,canWrite:n}){const i=h.useRef(null),l=h.useRef(null),[c,r]=h.useState(),[o,m]=h.useState(""),g=_(),b=window.showDirectoryPicker,x=(u,f)=>{u.files?.length&&(r(void 0),m(""),g.run(async()=>{try{const a=await fe(u.files,f),d=await s("import",{files:a,dry_run:!0});r({files:a,...d})}finally{u.value=""}}))},v=u=>{g.run(async()=>{m("");let f;try{u&&b&&(f=await b.call(window,{mode:"readwrite"}))}catch(p){if(p instanceof DOMException&&p.name==="AbortError")return;throw p}const a=await ve(s);if(!a.length){m(t("Kho chưa có tài liệu để xuất.","There are no documents to export."));return}const d="Limix-Vault-"+crypto.randomUUID().slice(0,8);if(f)m(t("Đang ghi vào thư mục ","Writing to folder ")+d),await ye(f,d,a),m(t("Đã xuất ","Exported ")+a.length+t(" tệp vào "," files to ")+d);else{try{q(a)}catch{throw new Error(t("Kho lớn hơn một gói JSON. Hãy xuất thư mục bằng Chrome hoặc Edge trên máy tính.","This vault exceeds one JSON package. Use directory export in desktop Chrome or Edge."))}const p=new Blob([JSON.stringify({format:"limix-knowledge-v1",files:a})],{type:"application/json"}),T=URL.createObjectURL(p),S=document.createElement("a");S.href=T,S.download=d+".json",S.click(),setTimeout(()=>URL.revokeObjectURL(T),1e3),m(t("Đã tạo gói tải về gồm ","Created a download containing ")+a.length+t(" tệp."," files."))}})};return e.jsxs("section",{className:"space-y-3",children:[n&&e.jsxs("div",{className:w,children:[e.jsx("h4",{className:"font-medium",children:t("Nhập tài liệu Obsidian","Import Obsidian documents")}),e.jsx("p",{className:j,children:t("Chọn Markdown, Canvas, Bases hoặc gói JSON đã xuất. Bạn sẽ xem kết quả kiểm tra trước khi ghi.","Choose Markdown, Canvas, Bases or an exported JSON package. Review the preview before importing.")}),e.jsx("input",{type:"file",hidden:!0,multiple:!0,ref:u=>{i.current=u,u?.setAttribute("webkitdirectory","")},onChange:u=>x(u.currentTarget,!0)}),e.jsx("input",{type:"file",hidden:!0,multiple:!0,accept:".md,.canvas,.base,.json",ref:l,onChange:u=>x(u.currentTarget,!1)}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs("button",{className:y,disabled:g.busy,onClick:()=>i.current?.click(),children:[e.jsx(J,{size:15}),t("Chọn thư mục Vault","Choose vault folder")]}),e.jsx("button",{className:y,disabled:g.busy,onClick:()=>l.current?.click(),children:t("Chọn tệp","Choose files")})]}),c&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("p",{className:"text-sm",children:[t("Sẽ nhập","To import")," · ",c.imported," ",t("Trùng lặp","Duplicates")," · ",c.duplicates]}),e.jsxs("details",{children:[e.jsx("summary",{className:"text-sm",children:t("Xem danh sách tệp","Review file list")}),e.jsx("ul",{className:j,children:c.files.map(u=>e.jsx("li",{children:u.path},u.path))})]}),e.jsx("button",{className:D,disabled:g.busy||!c.imported,onClick:()=>{g.run(async()=>{const u=await s("import",{files:c.files,dry_run:!1});m(t("Đã nhập ","Imported ")+u.imported+t(" tài liệu."," documents.")),r(void 0)})},children:t("Xác nhận nhập","Confirm import")})]})]}),e.jsxs("div",{className:w,children:[e.jsx("h4",{className:"font-medium",children:t("Xuất Vault","Export vault")}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[b&&e.jsxs("button",{className:y,disabled:g.busy,onClick:()=>v(!0),children:[e.jsx(J,{size:15}),t("Xuất thư mục Obsidian","Export Obsidian folder")]}),e.jsxs("button",{className:y,disabled:g.busy,onClick:()=>v(!1),children:[e.jsx(ee,{size:15}),t("Tải gói JSON","Download JSON package")]})]})]}),n&&e.jsxs("div",{className:w,children:[e.jsx("p",{className:j,children:t("Sau khi chỉnh sửa tệp trong thư mục kho bằng ứng dụng khác, cập nhật chỉ mục để tìm kiếm phiên bản mới.","After editing vault files in another app, update the search index to pick up changes.")}),e.jsx("button",{className:y,disabled:g.busy,onClick:()=>{g.run(async()=>{await s("index"),m(t("Đã cập nhật chỉ mục.","Search index updated."))})},children:t("Cập nhật chỉ mục","Update search index")})]}),o&&e.jsx("p",{role:"status",className:"text-sm",children:o}),g.error&&e.jsx("p",{role:"alert",className:"text-danger",children:g.error})]})}function Ne({call:s}){const[n,i]=h.useState(""),[l,c]=h.useState(""),[r,o]=h.useState(),[m,g]=h.useState(""),b=_(),x=u=>{b.run(async()=>{let f;try{f=JSON.parse(l)}catch{throw new Error(t("Các hàng dữ liệu phải là một mảng JSON hợp lệ.","Enter the rows as a valid JSON array."))}const a={template:n,rows:f,dry_run:u};if(u)o((await s("render_template",a)).files);else{const d=await s("render_template",a);o(void 0),g(t("Đã nhập ","Imported ")+d.imported+t(" tài liệu từ mẫu."," documents from this template."))}})},v=()=>{o(void 0),g("")};return e.jsxs("details",{className:w,children:[e.jsx("summary",{className:"cursor-pointer font-medium",children:t("Tạo tài liệu từ mẫu Knap","Create documents from a Knap template")}),e.jsxs("label",{className:"block text-sm",children:[t("Mẫu Markdown","Markdown template"),e.jsx("textarea",{rows:3,className:C+" font-mono",maxLength:8192,placeholder:"# {{ title }}",value:n,disabled:b.busy,onChange:u=>{i(u.target.value),v()}})]}),e.jsxs("label",{className:"block text-sm",children:[t("Các hàng dữ liệu (JSON)","Data rows (JSON)"),e.jsx("textarea",{className:C+" font-mono",rows:3,maxLength:15e4,placeholder:'[{"filename":"report.md","variables":{"title":"Report"}}]',value:l,disabled:b.busy,onChange:u=>{c(u.target.value),v()}})]}),e.jsx("button",{className:y,disabled:!n.trim()||!l.trim()||b.busy,onClick:()=>x(!0),children:t("Xem trước","Preview template")}),r&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("ul",{className:"max-h-60 space-y-2 overflow-y-auto",children:r.map(u=>e.jsxs("li",{children:[e.jsx("p",{className:j,children:u.path}),e.jsx("pre",{className:"whitespace-pre-wrap break-words text-sm",children:u.content})]},u.path))}),e.jsx("button",{className:D,disabled:b.busy||!r.length,onClick:()=>x(!1),children:t("Ghi các tài liệu đã xem","Save reviewed documents")})]}),b.error&&e.jsx("p",{role:"alert",className:"text-sm text-danger",children:b.error}),m&&e.jsx("p",{role:"status",className:"text-sm",children:m})]})}function we({call:s,settings:n}){const[i,l]=h.useState(0),[c,r]=h.useState(""),[o,m]=h.useState(!1),[g,b]=h.useState(""),[x,v]=h.useState(0),[u,f]=h.useState(""),a=_(),d=L(h.useCallback(p=>s("list_sources",{limit:25,offset:25*x},p),[s,i,x]));return g?e.jsx(W,{id:g,settings:n,call:s,close:()=>{b(""),l(p=>p+1)}}):e.jsxs("section",{className:"space-y-3",children:[n.collection&&n.canWrite&&e.jsxs("form",{className:w,onSubmit:p=>{p.preventDefault(),f(""),a.run(async()=>{const T=await s("ingest",{url:c.trim(),archive:n.archive&&o});f(T.archived?t("Đã lưu nguồn và bản HTML ngoại tuyến.","Saved the source and its offline HTML."):t("Đã lưu nguồn.","Source saved.")),r(""),v(0),l(S=>S+1)})},children:[e.jsxs("label",{className:"block text-sm",children:[t("URL nguồn công khai","Public source URL"),e.jsx("input",{required:!0,type:"url",maxLength:2048,className:C,value:c,onChange:p=>r(p.target.value)})]}),n.archive&&e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:o,onChange:p=>m(p.target.checked)}),t("Lưu thêm bản HTML ngoại tuyến","Keep an offline HTML copy")]}),e.jsx("button",{className:D,disabled:a.busy||!c.trim(),children:a.busy?t("Đang thu thập…","Collecting…"):t("Thu thập nguồn","Collect source")})]}),!n.collection&&e.jsx("p",{className:j,children:t("Bật Thu thập website trong Cài đặt để thêm nguồn từ URL.","Enable website collection in Settings to add a source by URL.")}),a.error&&e.jsx("p",{role:"alert",className:"text-danger",children:a.error}),u&&e.jsx("p",{role:"status",className:"text-sm",children:u}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h4",{className:"font-medium",children:t("Nguồn đã lưu","Saved sources")}),e.jsxs("button",{type:"button",className:y,onClick:()=>l(p=>p+1),children:[e.jsx(de,{size:14}),t("Làm mới","Refresh")]})]}),d?.error&&e.jsx("p",{role:"alert",className:"text-danger",children:d.error}),d?.value?.documents.length===0&&e.jsx("p",{className:j,children:t("Chưa có nguồn ở trang này.","No sources on this page.")}),e.jsx("ul",{className:"divide-y divide-hairline",children:d?.value?.documents.map(p=>e.jsx("li",{children:e.jsxs("button",{className:"w-full rounded-lg p-2 text-left hover:bg-control",onClick:()=>b(p.document_id),children:[e.jsx("span",{className:"block break-words text-sm font-medium",children:p.title}),e.jsx("span",{className:j+" block break-all",children:p.source_url}),e.jsxs("span",{className:j,children:[F(p.verification_status)," · v",p.version]})]})},p.document_id))}),(x>0||d?.value?.documents.length===25)&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{className:y,disabled:!x,onClick:()=>v(p=>p-1),children:t("Trang trước","Previous page")}),e.jsx("button",{className:y,disabled:d?.value?.documents.length!==25,onClick:()=>v(p=>p+1),children:t("Trang sau","Next page")})]}),n.collection&&e.jsx(ke,{call:s,canWrite:n.canWrite,active:a.busy,revision:i,onChange:()=>l(p=>p+1)})]})}function U(s){return{new:t("Mới","New"),done:t("Hoàn tất","Completed"),running:t("Đang chạy","Running"),cancelled:t("Đã hủy","Cancelled"),failed:t("Lỗi","Failed"),skipped:t("Bỏ qua","Skipped")}[s]??s}function ke({call:s,canWrite:n,active:i,revision:l,onChange:c}){const[r,o]=h.useState(0),m=_(),g=_();h.useEffect(()=>{if(!i&&!m.busy)return;const x=setInterval(()=>{document.hidden||o(v=>v+1)},3e3);return()=>clearInterval(x)},[i,m.busy]);const b=L(h.useCallback(x=>s("jobs",{},x),[s,l,r]));return e.jsxs("div",{className:w,children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("h4",{className:"font-medium",children:t("Quy trình thu thập","Collection jobs")}),e.jsx("button",{className:y,onClick:()=>o(x=>x+1),children:t("Cập nhật trạng thái","Refresh jobs")})]}),b?.value?.jobs.length===0&&e.jsx("p",{className:j,children:t("Chưa có lần thu thập nào.","No collection jobs yet.")}),b?.value?.jobs.map(x=>e.jsxs("details",{className:"rounded border border-hairline px-2 py-1.5 text-sm",children:[e.jsxs("summary",{className:"cursor-pointer break-all",children:[U(x.status)," · ",x.source_url]}),e.jsx("p",{className:j,children:new Date(x.updated_at).toLocaleString()}),e.jsx("ol",{className:j,children:x.steps.map(v=>e.jsxs("li",{children:[v.stage," · ",U(v.status)," · ",v.attempts]},v.stage))}),n&&x.status==="running"&&e.jsx("button",{className:y,disabled:g.busy,onClick:()=>{g.run(async()=>{await s("cancel",{job_id:x.job_id}),c()})},children:t("Hủy quy trình","Cancel job")}),n&&["failed","cancelled"].includes(x.status)&&e.jsx("button",{className:y,disabled:m.busy,onClick:()=>{m.run(async()=>{await s("ingest",{url:x.source_url,archive:x.archive}),c()})},children:t("Tiếp tục thu thập","Resume collection")})]},x.job_id)),(m.error||g.error||b?.error)&&e.jsx("p",{role:"alert",className:"text-danger",children:m.error||g.error||b?.error})]})}function Ce({call:s}){const n=L(h.useCallback(r=>s("graph",{limit:100},r),[s]));if(n?.error)return e.jsx("p",{role:"alert",children:n.error});if(!n?.value)return e.jsx("p",{role:"status",children:t("Đang đọc liên kết…","Loading links…")});const{nodes:i,edges:l}=n.value,c=new Map(i.map(r=>[r.id,r.title]));return e.jsxs("section",{className:w,children:[e.jsx("h4",{className:"font-medium",children:t("Mạng lưới tri thức","Knowledge graph")}),e.jsxs("p",{className:j,children:[i.length," ",t("tài liệu","documents")," · ",l.length," ",t("liên kết","links")]}),e.jsx("ul",{className:"space-y-2",children:l.map(r=>e.jsxs("li",{className:"flex flex-wrap items-center gap-2 text-sm",children:[e.jsx("span",{children:c.get(r.from)}),e.jsx(te,{size:15,"aria-label":t("Liên kết đến","Links to")}),e.jsx("span",{children:c.get(r.to)})]},r.from+"/"+r.to))}),!l.length&&e.jsx("p",{className:j,children:t("Mở một tài liệu để liên kết tới tài liệu khác trong kho.","Open a document to link it to another document in the vault.")})]})}function Se({call:s,settings:n,openMemory:i}){const[l,c]=h.useState(""),[r,o]=h.useState(""),[m,g]=h.useState(),[b,x]=h.useState(),[v,u]=h.useState(""),f=_();return e.jsxs("section",{className:"space-y-3",children:[e.jsxs("form",{className:w,onSubmit:a=>{a.preventDefault(),f.run(async()=>{const{results:d}=await s("memory_recall",{query:l,limit:12});g(d)})},children:[e.jsxs("label",{className:"block text-sm",children:[t("Tìm trong bộ nhớ","Search memory"),e.jsx("input",{required:!0,type:"search",maxLength:400,className:C,value:l,onChange:a=>c(a.target.value)})]}),e.jsx("button",{className:y,disabled:f.busy||!l.trim(),children:t("Tìm ký ức","Recall")}),m?.length===0&&e.jsx("p",{className:j,children:t("Không tìm thấy ký ức phù hợp.","No matching memories.")}),m?.map((a,d)=>e.jsxs("div",{children:[e.jsx("p",{className:j,children:a.path}),e.jsx("p",{className:"whitespace-pre-wrap break-words text-sm",children:a.snippet})]},a.path+d))]}),n.canWriteMemory&&e.jsxs("form",{className:w,onSubmit:a=>{a.preventDefault(),f.run(async()=>{const d=await s("memory_store",{text:r});o(""),g(void 0),x(void 0),u(d.duplicate?t("Ký ức này đã có.","This memory already exists."):t("Đã ghi vào bộ nhớ của bot.","Saved to the bot’s memory."))})},children:[e.jsxs("label",{className:"block text-sm",children:[t("Thông tin cần ghi nhớ","Fact to remember"),e.jsx("textarea",{required:!0,rows:3,maxLength:1e3,className:C,value:r,onChange:a=>{o(a.target.value),u("")}})]}),e.jsx("button",{className:D,disabled:f.busy||!r.trim(),children:t("Lưu ký ức","Save memory")}),v&&e.jsx("p",{role:"status",className:"text-sm",children:v})]}),e.jsxs("div",{className:w,children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{className:y,disabled:f.busy,onClick:()=>{f.run(async()=>x(await s("memory_consolidate")))},children:t("Rà soát ký ức","Review memories")}),e.jsx("button",{className:y,onClick:i,children:t("Quản lý sổ nhớ của bot","Manage bot memory")})]}),b&&e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-sm",children:[t("Trùng lặp","Duplicates")," · ",b.duplicates," ",t("Hết hạn","Expired")," · ",b.expired," ",t("Có thể mâu thuẫn","Potential conflicts")," · ",b.possible_conflicts.length]}),b.possible_conflicts.map((a,d)=>e.jsxs("p",{className:j,children:[a.first,e.jsx("br",{}),a.second]},d))]})]}),f.error&&e.jsx("p",{role:"alert",className:"text-danger",children:f.error})]})}function Ke(){const{state:s,dispatch:n}=se(),i=s.bots.filter(o=>!o.hidden&&!o.movedTo),[l,c]=h.useState(""),r=i.find(o=>o.id===l);return e.jsxs("section",{"aria-label":t("Kho Tri Thức","Knowledge Vault"),className:"space-y-4 text-ink",children:[e.jsxs("div",{className:"flex flex-wrap items-end justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"flex items-center gap-2 text-xl font-semibold",children:[e.jsx(V,{size:21}),t("Kho Tri Thức","Knowledge Vault")]}),e.jsx("p",{className:"mt-1 text-sm text-ink-secondary",children:t("Chọn bot để quản lý tài liệu, nguồn và bộ nhớ của bot.","Choose a bot to manage its documents, sources and memory.")})]}),e.jsxs("select",{className:C+" sm:w-56","aria-label":t("Chọn bot","Choose a bot"),value:r?.id??"",onChange:o=>c(o.target.value),children:[e.jsx("option",{value:"",children:t("Chọn bot…","Choose a bot…")}),i.map(o=>e.jsx("option",{value:o.id,children:o.name},o.id))]})]}),!i.length&&e.jsx("p",{className:j,children:t("Chưa có bot trong danh sách của bạn.","You have no bots in this workspace.")}),r&&e.jsx(Te,{botId:r.id,openMemory:()=>{n({type:"togglePlugins",open:!1}),ne(n,"memory",{botId:r.id})}},r.id)]})}function Te({botId:s,openMemory:n}){const i=me(s),[l,c]=h.useState(0),r=L(h.useCallback(a=>B(P(s)+"settings",{signal:a}),[s,l])),o=r?.value,m=_(),[g,b]=h.useState("documents"),x=(a,d)=>{m.run(async()=>{await B(P(s)+"settings",{method:"PUT",body:JSON.stringify({[a]:d})}),a==="enabled"&&b("documents"),c(p=>p+1)})};if(r?.error)return e.jsxs("div",{className:w,children:[e.jsx("p",{role:"alert",children:r.error}),e.jsx("button",{className:y,onClick:()=>c(a=>a+1),children:t("Thử lại","Try again")})]});if(!o)return e.jsx("p",{role:"status",className:j,children:t("Đang tải quyền truy cập…","Loading access settings…")});const v=[{id:"documents",label:t("Tài liệu","Documents"),icon:V},{id:"sources",label:t("Nguồn dữ liệu","Sources"),icon:ae},...o.memory?[{id:"memory",label:t("Bộ nhớ AI","AI memory"),icon:ie}]:[],{id:"graph",label:t("Liên kết","Links"),icon:re},{id:"transfer",label:t("Nhập và xuất","Import and export"),icon:ce},{id:"settings",label:t("Cài đặt","Settings"),icon:he}],u=v.some(a=>a.id===g)?g:"documents",f=(a,d,p)=>e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:d}),e.jsx("p",{className:j,children:p})]}),e.jsx(oe,{"aria-label":d,checked:o[a],disabled:!o.canManage||m.busy,onClick:()=>x(a,!o[a])})]},a);return e.jsxs(e.Fragment,{children:[m.error&&e.jsx("p",{role:"alert",className:"text-sm text-danger",children:m.error}),(!o.enabled||u==="settings")&&e.jsxs("div",{className:w,children:[f("enabled",t("Bật Kho Tri Thức cho bot","Enable Knowledge Vault for this bot"),t("Lưu trữ và truy xuất tài liệu trong không gian làm việc này.","Store and retrieve documents in this workspace.")),!o.canManage&&e.jsx("p",{className:j,children:t("Quản trị viên của không gian làm việc có thể thay đổi cài đặt này.","A workspace administrator can change these settings.")})]}),o.enabled&&e.jsxs(e.Fragment,{children:[e.jsx("nav",{"aria-label":t("Chức năng Kho Tri Thức","Knowledge Vault sections"),className:"flex flex-wrap gap-1 border-b border-hairline pb-2",children:v.map(({id:a,label:d,icon:p})=>e.jsxs("button",{type:"button","aria-pressed":u===a,onClick:()=>b(a),className:"inline-flex items-center gap-1.5 rounded-lg px-2.5 py-2 text-sm "+(u===a?"bg-raised font-medium text-ink":"text-ink-secondary hover:bg-control"),children:[e.jsx(p,{size:15}),d]},a))}),u==="documents"&&e.jsx(xe,{call:i,settings:o}),u==="sources"&&e.jsx(we,{call:i,settings:o}),u==="memory"&&e.jsx(Se,{call:i,settings:o,openMemory:n}),u==="graph"&&e.jsx(Ce,{call:i}),u==="transfer"&&e.jsxs(e.Fragment,{children:[e.jsx(je,{call:i,canWrite:o.canWrite}),o.collection&&o.canWrite&&e.jsx(Ne,{call:i})]}),u==="settings"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:w,children:[f("collection",t("Thu thập website","Collect websites"),t("Cho phép nhập nội dung từ một URL công khai.","Allow importing content from a public URL.")),f("archive",t("Lưu bản HTML","Keep HTML archives"),t("Lưu thêm bản xem ngoại tuyến khi thu thập website.","Keep an offline copy when collecting a website.")),f("memory",t("Truy cập bộ nhớ AI","Access AI memory"),t("Dùng bộ nhớ hiện có của bot qua Kho Tri Thức.","Use the bot’s existing memory through Knowledge Vault.")),f("shared",t("Tài liệu dùng chung","Shared documents"),t("Cho phép bot sử dụng tài liệu dùng chung theo quyền được cấp.","Let the bot use shared workspace documents according to its permissions.")),f("semantic",t("Tìm kiếm ngữ nghĩa","Semantic search"),t("Cho phép gửi trích đoạn tới nhà cung cấp embedding đã cấu hình khi tìm kiếm.","Allow search to send excerpts to the configured embedding provider."))]}),e.jsx(_e,{call:i})]})]})]})}function _e({call:s}){const n=L(h.useCallback(l=>s("get_stats",{},l),[s]));if(n?.error)return e.jsx("p",{role:"alert",className:"text-danger",children:n.error});if(!n?.value)return e.jsx("p",{role:"status",className:j,children:t("Đang tính dung lượng…","Loading storage usage…")});const i=n.value;return e.jsx("dl",{className:"grid grid-cols-2 gap-3 sm:grid-cols-4",children:[[t("Tài liệu","Documents"),i.documents],[t("Đã duyệt","Verified"),i.verified],[t("Nguồn","Sources"),i.sources],[t("Dung lượng","Storage"),(i.bytes/1048576).toFixed(2)+" / "+(i.quota_bytes/1048576).toFixed(1)+" MiB"],...i.embedding_requests===void 0?[]:[[t("Lượt gọi embedding","Embedding requests"),i.embedding_requests]],...i.embedding_tokens==null?[]:[[t("Token embedding","Embedding tokens"),i.embedding_tokens]]].map(([l,c])=>e.jsxs("div",{className:"rounded-xl border border-hairline p-3",children:[e.jsx("dt",{className:j,children:l}),e.jsx("dd",{className:"font-medium",children:c})]},l))})}export{Ke as KnowledgePanel};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as m,j as h}from"./styles-DO3EUxm2.js";import{x as M}from"./App-
|
|
1
|
+
import{r as m,j as h}from"./styles-DO3EUxm2.js";import{x as M}from"./App-BgdjoCaG.js";const H="limix.settings.size",R=640,W=460,y=()=>typeof window<"u"&&window.innerWidth>=768;function b(n,o,l,p,c){const u=Math.max(1,window.innerWidth-p),s=Math.max(1,window.innerHeight-c);n.style.width=`${Math.round(Math.min(Math.max(o,R),u))}px`,n.style.height=`${Math.round(Math.min(Math.max(l,W),s))}px`}function v(n,o){n.style.width="",n.style.height="";try{window.localStorage.removeItem(o)}catch{}}const S=[{sx:1,sy:0,cls:"right-0 top-4 bottom-4 w-1.5",cursor:"cursor-ew-resize"},{sx:-1,sy:0,cls:"left-0 top-4 bottom-4 w-1.5",cursor:"cursor-ew-resize"},{sx:0,sy:1,cls:"bottom-0 left-4 right-4 h-1.5",cursor:"cursor-ns-resize"},{sx:0,sy:-1,cls:"top-0 left-4 right-4 h-1.5",cursor:"cursor-ns-resize"},{sx:1,sy:1,cls:"bottom-0 right-0 h-4 w-4",cursor:"cursor-nwse-resize"},{sx:-1,sy:1,cls:"bottom-0 left-0 h-4 w-4",cursor:"cursor-nesw-resize"}];function C({storageKey:n=H,widthInset:o=32,heightInset:l=96,showGrip:p=!1}={}){const c=m.useRef(null),u=m.useRef(null),s=m.useRef(null),z=M("Kéo để đổi kích thước (bấm đúp để đặt lại)","Drag to resize (double-click to reset)"),E=t=>{s.current={w:t.offsetWidth,h:t.offsetHeight};try{window.localStorage.setItem(n,JSON.stringify(s.current))}catch{}};m.useEffect(()=>{const t=c.current?.parentElement;if(!t)return;t.style.maxWidth="100%",t.style.maxHeight="100%",s.current=null;try{const e=JSON.parse(window.localStorage.getItem(n)??"null");e&&typeof e.w=="number"&&Number.isFinite(e.w)&&typeof e.h=="number"&&Number.isFinite(e.h)&&(s.current={w:e.w,h:e.h})}catch{}const r=()=>{const e=s.current;y()&&e?b(t,e.w,e.h,o,l):(t.style.width="",t.style.height="")};return r(),window.addEventListener("resize",r),()=>{u.current?.abort(),window.removeEventListener("resize",r)}},[n,o,l]);const k=t=>r=>{const e=c.current?.parentElement;if(!e||!y()||r.button!==0)return;r.preventDefault(),u.current?.abort();const i=new AbortController;u.current=i;const f=r.clientX,w=r.clientY,L=e.offsetWidth,N=e.offsetHeight,j=a=>{a.pointerId===r.pointerId&&b(e,L+t.sx*(a.clientX-f)*2,N+t.sy*(a.clientY-w)*2,o,l)},g=()=>{i.abort(),u.current=null,y()&&E(e)},D=a=>{a.pointerId===r.pointerId&&g()},d={signal:i.signal};window.addEventListener("pointermove",j,d),window.addEventListener("pointerup",D,d),window.addEventListener("pointercancel",D,d),window.addEventListener("blur",g,d)},x=()=>{const t=c.current?.parentElement;s.current=null,t&&v(t,n)};return h.jsx("span",{ref:c,className:"contents",children:S.map(t=>p&&t.sx===1&&t.sy===1?h.jsx("button",{type:"button",title:z,"aria-label":M("Đổi kích thước cửa sổ bằng phím mũi tên. Enter để đặt lại.","Resize with arrow keys. Press Enter to reset."),className:"absolute bottom-1 right-1 z-20 hidden size-5 cursor-nwse-resize touch-none items-center justify-center rounded text-ink-secondary hover:text-ink focus-visible:outline-2 focus-visible:outline-accent md:flex",onPointerDown:k(t),onDoubleClick:x,onKeyDown:r=>{const e=c.current?.parentElement;if(!e)return;if(r.key==="Enter"||r.key===" "){r.preventDefault(),x();return}const i=32,f=r.key==="ArrowRight"?i:r.key==="ArrowLeft"?-i:0,w=r.key==="ArrowDown"?i:r.key==="ArrowUp"?-i:0;!f&&!w||(r.preventDefault(),b(e,e.offsetWidth+f,e.offsetHeight+w,o,l),E(e))},children:h.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none","aria-hidden":"true",children:h.jsx("path",{d:"M3 10 10 3m-3 7 3-3",stroke:"currentColor",strokeLinecap:"round"})})},"grip"):h.jsx("span",{"aria-hidden":"true",title:z,className:`absolute z-20 hidden touch-none md:block ${t.cls} ${t.cursor}`,onPointerDown:k(t),onDoubleClick:x},`${t.sx}${t.sy}`))})}export{C as L};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as n,t as s,j as e,a as o}from"./styles-DO3EUxm2.js";import{c as H,t as M}from"./desktop-connection-Dfaq6k5a.js";import{u as P,d as B,L as D}from"./PlacesRail-tZyNm-l3.js";import{S as F,R as K}from"./MenuMotion-B0aZnuh_.js";import{P as O,U as q}from"./App-
|
|
1
|
+
import{r as n,t as s,j as e,a as o}from"./styles-DO3EUxm2.js";import{c as H,t as M}from"./desktop-connection-Dfaq6k5a.js";import{u as P,d as B,L as D}from"./PlacesRail-tZyNm-l3.js";import{S as F,R as K}from"./MenuMotion-B0aZnuh_.js";import{P as O,U as q}from"./App-BgdjoCaG.js";import"./desktop-viewer-CF-OpSo0.js";import"./monitor-zecPzfR5.js";import"./index-BQM4L4RU.js";function Z({target:x,threadId:f,name:R,poster:b,expanded:r,onExpandedChange:h,onHandBack:E,handingBack:g,onUnreachable:v}){const j=n.useRef(null),a=n.useRef(null),[i,c]=n.useState("connecting"),[k,w]=n.useState(0),[l,y]=n.useState(""),N=n.useRef(!1),{dragProps:L,noDragStyle:u}=P(),T=B().capabilities.windowChrome==="mac-inset",C=n.useRef(v);C.current=v,n.useEffect(()=>{const t=new AbortController;let p,S;const V=()=>{c("disconnected"),N.current?k===0&&(S=setTimeout(()=>w(1),1e3)):C.current()};return c("connecting"),H(j.current,x,{threadId:f,signal:t.signal,events:{connected:()=>{N.current=!0,c("connected")},disconnected:V}}).then(m=>{if(t.signal.aborted)return m.disconnect();p=m,a.current=m},()=>{t.signal.aborted||V()}),()=>{t.abort(),clearTimeout(S),p?.disconnect(),a.current===p&&(a.current=null)}},[x,f,k]),n.useEffect(()=>{i==="connected"&&a.current?.focus({preventScroll:!0})},[r,i]);const z=s("computer.viewerTitle",{name:R}),A=e.jsxs("span",{className:"pointer-events-none flex items-center gap-1.5 rounded-full bg-black/70 px-2.5 py-1 text-[11px] font-medium text-white shadow-sm",children:[e.jsx("span",{className:"size-1.5 rounded-full bg-success","aria-hidden":"true"}),s("computer.inControl")]}),d="flex items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-[12px] focus-visible:outline-2 focus-visible:outline-focus disabled:opacity-50";return e.jsxs("div",{"data-live-desktop":!0,"data-state":i,"data-expanded":r?"true":void 0,className:o(r?"fixed inset-0 z-[65] flex flex-col bg-app":"relative h-full w-full"),onKeyDown:t=>{r&&t.key==="Escape"&&!(t.target instanceof HTMLCanvasElement)&&h(!1)},children:[r&&e.jsxs("header",{...L,className:o("flex shrink-0 flex-wrap items-center gap-2 border-b border-hairline/40 bg-panel px-3 py-2",T&&"pl-[86px]"),children:[e.jsx("span",{className:"min-w-0 truncate text-[13px] font-medium text-ink",children:z}),A,e.jsxs("form",{style:u,className:"ml-auto flex min-w-0 items-center gap-1",onSubmit:t=>{t.preventDefault(),!(!a.current||i!=="connected"||!l)&&(M(a.current,l),y(""))},children:[e.jsx("input",{value:l,onChange:t=>y(t.target.value),maxLength:4096,autoComplete:"off",autoCapitalize:"off",spellCheck:!1,placeholder:s("desktopViewer.text"),"aria-label":s("desktopViewer.text"),className:"w-44 min-w-0 rounded-lg border border-hairline bg-inset px-2.5 py-1.5 text-[12px] text-ink outline-none focus:border-focus max-sm:w-28"}),e.jsx("button",{type:"submit",disabled:i!=="connected"||!l,title:s("desktopViewer.send"),"aria-label":s("desktopViewer.send"),className:o(d,"bg-control text-ink hover:bg-raised-hover"),children:e.jsx(F,{size:14,"aria-hidden":"true"})})]}),e.jsxs("button",{type:"button",style:u,onClick:()=>h(!1),className:o(d,"bg-control text-ink hover:bg-raised-hover"),children:[e.jsx(O,{size:14,"aria-hidden":"true"}),e.jsx("span",{className:"max-sm:hidden",children:s("desktopViewer.exitFullscreen")})]}),e.jsxs("button",{type:"button",style:u,onClick:E,disabled:g,className:o(d,"bg-accent font-medium text-accent-ink hover:brightness-110"),children:[g?e.jsx(D,{size:14,className:"animate-spin","aria-hidden":"true"}):e.jsx(q,{size:14,"aria-hidden":"true"}),s("computer.handBack")]})]}),e.jsxs("div",{className:o("relative overflow-hidden bg-inset",r?"min-h-0 flex-1":"h-full w-full"),children:[b&&i!=="connected"&&e.jsx("img",{src:b,alt:"","aria-hidden":"true",className:"absolute inset-0 h-full w-full object-contain opacity-50"}),e.jsx("div",{ref:j,role:"application","aria-label":z,className:"absolute inset-0"}),i==="connecting"&&e.jsxs("div",{role:"status",className:"pointer-events-none absolute inset-0 flex items-center justify-center gap-2 text-[12px] text-ink-secondary",children:[e.jsx(D,{size:16,className:"animate-spin","aria-hidden":"true"}),s("desktopViewer.connecting")]}),i==="disconnected"&&e.jsxs("div",{role:"alert",className:"absolute inset-x-0 bottom-0 flex flex-col items-center gap-2 bg-card/95 p-3 text-center text-[12px] text-ink-secondary",children:[e.jsx("span",{children:s("desktopViewer.disconnected")}),e.jsxs("button",{type:"button",onClick:()=>w(t=>t+1),className:"flex items-center gap-1.5 rounded-md bg-control px-3 py-1.5 text-ink hover:bg-raised-hover",children:[e.jsx(K,{size:13,"aria-hidden":"true"}),s("desktopViewer.reconnect")]})]})]})]})}export{Z as LiveDesktop};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as l,o as ae,s as ce,f as O,g as W,h as ve,r as i,p as he,j as c,X as we,a as Q,u as xe}from"./styles-DO3EUxm2.js";import{u as be,W as ke,X as ee,Y as ie,j as q,w as ye,U as te,Z as ge}from"./App-FkCoivKo.js";import{u as Ne,L as T}from"./PlacesRail-tZyNm-l3.js";import{M as le}from"./monitor-zecPzfR5.js";import{R as je}from"./MenuMotion-B0aZnuh_.js";import"./index-CaQlk_HV.js";function Ce(s,e){const u=(n,o)=>n.left<o.right&&n.right>o.left&&n.top<o.bottom&&n.bottom>o.top;return e.some(n=>n.visible&&n.rect.width>0&&n.rect.height>0&&(n.explicit||n.zIndex!==null&&n.zIndex>=10)&&s.some(o=>u(n.rect,o)))}async function Se(s,e,u,n){e&&e!==u&&(await s.setInteractive(null),await s.release(e));const o=await s.take(u);if(!o.held)throw new Error(l("vm.workspace.holdNotAcquired"));if(o.owned!==!0)return{status:"held-elsewhere",botId:u,snapshot:o};try{await s.setInteractive(n)}catch(d){throw await s.setInteractive(null).catch(()=>{}),await s.release(u).catch(()=>{}),d}return{status:"controlled",botId:u,snapshot:o}}async function $(s,e){return e?(await s.setInteractive(null).catch(()=>{}),s.release(e)):null}function ue(s){return s.filter(e=>e.computer==="vm"&&e.hidden!==!0).map(e=>e.id)}function Ee(s,e){const u=ue(s),n=u.includes(e)?e:u[0]??null;return[n,u.find(o=>o!==n)??null]}function Re(s,e,u){const n=[...s],o=e===0?1:0;return u&&n[o]===u&&(n[o]=n[e]),n[e]=u,n}function Le(s,e){const u=ue(e),n=new Set(u),o=[null,null];for(const d of[0,1]){const m=s[d];m&&n.delete(m)&&(o[d]=m)}for(const d of[0,1]){if(o[d])continue;const m=[...n][0];m&&(o[d]=m,n.delete(m))}return o}const ze=ae({mode:W(["shared","per-bot","pool"]).optional(),max_instances:ve().int().nonnegative().optional(),container:W(["running","stopped","missing"]).optional(),network:W(["loopback","unsafe","unknown"]).optional(),security:W(["hardened","unsafe","unknown"]).optional(),persistence:W(["durable","unsafe","unknown"]).optional(),desktopReady:O().optional(),ready:O().optional(),viewer_url:ce().min(1).optional()});function de(s){const e=ze.safeParse(s);return e.success?e.data:null}function X(s){const e=de(s),u=e?.mode??"unknown",n=e?.container??"unknown",o=e?.network??"unknown",d=e?.security??"unknown",m=e?.persistence??"unknown",w=e?.max_instances??0,h=e?.desktopReady===!0,x=!!(e?.ready===!0&&n==="running"&&o==="loopback"&&d==="hardened"&&m==="durable"&&h);return{mode:u,maxInstances:w,container:n,network:o,security:d,persistence:m,desktopReady:h,ready:x}}function Ve(s){const e=de(s);return!e||!X(s).ready?null:e.viewer_url??null}const D=["local-vm-workspace:left","local-vm-workspace:right"],pe=ae({held:O(),helpReason:ce().nullable(),help:xe().optional().transform(ge),owned:O().optional(),acquired:O().optional(),released:O().optional()});async function ne(s,e,u){const n=await q(`/api/bots/${s}/computer/control`,{method:"POST",body:JSON.stringify({action:e,controlLeaseId:u})}),o=pe.safeParse(n);if(!o.success)throw new Error("invalid-control-snapshot");return o.data}async function Oe(s){const e=pe.safeParse(await q(`/api/bots/${s}/computer/control`));if(!e.success)throw new Error("invalid-control-snapshot");return e.data}function re(s,e){fetch(`/api/bots/${s}/computer/control`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({action:"release",controlLeaseId:e}),keepalive:!0}).then(async u=>{u.ok}).catch(()=>{})}async function se(s,e){return!0}function H(s,e,u){s({type:"computerControl",botId:e,held:u.held,helpReason:u.helpReason,help:u.help??null})}function oe(s){const e=s.current?.getBoundingClientRect();return!e||e.width<1||e.height<1?null:{x:Math.round(e.left),y:Math.round(e.top),width:Math.round(e.width),height:Math.round(e.height)}}const Be=['[aria-modal="true"]','[role="dialog"]','[role="menu"]',"[popover]","[data-native-view-overlay]",".fixed",".absolute"].join(",");function Ie(){const s=[...document.querySelectorAll("[data-native-view-host]")],e=s.map(n=>n.getBoundingClientRect()).filter(n=>n.width>0&&n.height>0);if(e.length===0)return!1;const u=[...document.querySelectorAll(Be)].filter(n=>!s.some(o=>n===o||n.contains(o)||o.contains(n))).map(n=>{const o=window.getComputedStyle(n),d=n.matches('[aria-modal="true"], [role="dialog"], [role="menu"], [popover], [data-native-view-overlay]'),m=Number.parseInt(o.zIndex,10);return{rect:n.getBoundingClientRect(),explicit:d,visible:o.display!=="none"&&o.visibility!=="hidden"&&Number(o.opacity)!==0,zIndex:Number.isFinite(m)?m:null}});return Ce(e,u)}function We(s){const[e,u]=i.useState(!1);return i.useEffect(()=>{let n=0;const o=()=>u(Ie()),d=()=>{n||(n=requestAnimationFrame(()=>{n=0,o()}))};o();const m=new MutationObserver(d);m.observe(document.body,{subtree:!0,childList:!0,attributes:!0,attributeFilter:["class","style","aria-hidden","aria-modal","role","open","popover"]});const w=new ResizeObserver(d);w.observe(document.body);for(const x of document.querySelectorAll("[data-native-view-host]"))w.observe(x);const h=["toggle","animationstart","animationend","transitionstart","transitionend"];for(const x of h)document.addEventListener(x,d,!0);return window.addEventListener("resize",d),window.addEventListener("scroll",d,!0),()=>{n&&cancelAnimationFrame(n),m.disconnect(),w.disconnect();for(const x of h)document.removeEventListener(x,d,!0);window.removeEventListener("resize",d),window.removeEventListener("scroll",d,!0)}},[]),s||e}function Ae(s,e){return s?s.container==="missing"?l("vm.workspace.status.missing"):s.container==="stopped"?l("vm.workspace.status.stopped"):s.ready?e==="error"?l("vm.workspace.status.viewerUnavailable"):e!=="ready"?l("vm.workspace.status.connecting"):l("vm.workspace.status.live"):l("vm.workspace.status.unavailable"):l("vm.workspace.status.checking")}function _e({index:s,bot:e,bots:u,otherBotId:n,obscured:o,active:d,heldElsewhere:m,controlPending:w,onSelect:h,onTake:x,onRelease:B,onOpenComputer:A}){const v=D[s],p=e?.id??null,I=e?.name??l("vm.workspace.localVm"),b=i.useRef(null),k=i.useRef(Promise.resolve()),z=i.useRef(o),[_,V]=i.useState(0),[C,N]=i.useState(null),[j,y]=i.useState({contextId:v,open:!1,status:"closed",interactive:!1}),[E,g]=i.useState(null),R=i.useCallback(async t=>{if(p)try{const a=await q(`/api/bots/${p}/local-computer`,{signal:t});t?.aborted||N(X(a))}catch{}},[p]),F=i.useRef(R);i.useEffect(()=>{F.current=R},[R]),i.useEffect(()=>{z.current=o},[o]),i.useEffect(()=>window.ogb?.desktopWorkspace?.onState(a=>{a.contextId===v&&(y(a),(a.status==="error"||a.status==="closed")&&F.current())}),[v]),i.useEffect(()=>{const t=window.ogb?.desktopWorkspace;let a=!0;const f=new AbortController;N(null),g(null),y({contextId:v,open:!1,status:"closed",interactive:!1});const M=async()=>{if(t&&await t.close(v).catch(()=>{}),!(!a||!p)){if(!t){g(l("vm.workspace.desktopRequired"));return}try{const S=await q(`/api/bots/${p}/local-computer`,{signal:f.signal});if(!a)return;const J=X(S);N(J);const Y=Ve(S);if(!J.ready||!Y||(await new Promise(me=>{let G=!1;const K=()=>{G||(G=!0,me())},fe=setTimeout(K,100);requestAnimationFrame(()=>{clearTimeout(fe),K()})}),!a))return;const U=oe(b);if(!U)throw new Error("layout-unavailable");const Z=await t.open({contextId:v,url:Y,title:l("vm.workspace.windowTitle",{name:I}),bounds:U});if(!a){await t.close(v).catch(()=>{});return}y(Z),await t.layout([{contextId:v,bounds:U,visible:!z.current&&Z.open}])}catch(S){if(!a||f.signal.aborted)return;g(S instanceof Error&&S.message==="layout-unavailable"?l("vm.workspace.layoutUnavailable"):l("vm.workspace.connectFailed"))}}};return k.current=k.current.catch(()=>{}).then(M),()=>{a=!1,f.abort(),t&&(k.current=k.current.catch(()=>{}).then(()=>t.close(v).then(()=>{}).catch(()=>{})))}},[p,I,v,_]),i.useEffect(()=>{if(!p)return;const t=new AbortController,a=window.setInterval(()=>{R(t.signal)},3e4);return()=>{t.abort(),window.clearInterval(a)}},[p,R]);const L=i.useCallback(()=>{const t=window.ogb?.desktopWorkspace,a=oe(b);!t||!a||!j.open||t.layout([{contextId:v,bounds:a,visible:!o}]).catch(()=>g(l("vm.workspace.positionFailed")))},[v,j.open,o]);i.useEffect(()=>{const t=b.current;if(!t)return;const a=new ResizeObserver(L);a.observe(t),window.addEventListener("resize",L);const f=requestAnimationFrame(L);return()=>{cancelAnimationFrame(f),a.disconnect(),window.removeEventListener("resize",L)}},[L]);const P=Ae(C,j.status),r=!!(e&&C?.ready&&j.status==="ready"&&j.open);return c.jsxs("section",{className:Q("flex min-h-0 min-w-0 flex-col overflow-hidden rounded-xl border bg-panel",d?"border-accent/80 shadow-[0_0_0_1px_rgb(var(--accent)/0.35)]":"border-hairline/50"),children:[c.jsxs("div",{className:"flex min-h-[68px] items-center gap-3 border-b border-hairline/40 px-3 py-2.5",children:[c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsx("label",{className:"sr-only",htmlFor:`local-vm-slot-${s}`,children:l("vm.workspace.paneLabel",{number:s+1})}),c.jsxs(ye,{size:"sm",className:"w-full",id:`local-vm-slot-${s}`,value:e?.id??"",onChange:t=>h(t.target.value||null),disabled:w,children:[c.jsx("option",{value:"",children:l("vm.workspace.chooseBot")}),u.map(t=>c.jsx("option",{value:t.id,disabled:t.id===n,children:t.name},t.id))]}),c.jsxs("div",{className:"mt-1 flex items-center gap-1.5 text-[11px] text-ink-secondary",children:[c.jsx("span",{className:Q("h-1.5 w-1.5 rounded-full",d?"bg-accent":j.status==="ready"?"bg-success":j.status==="error"?"bg-danger":"bg-ink-secondary/50")}),d?l("vm.workspace.youHaveControl"):m?l("vm.workspace.controlElsewhere"):P]})]}),e&&d?c.jsxs("button",{type:"button",onClick:B,disabled:w,className:"flex shrink-0 items-center gap-1.5 rounded-lg bg-accent px-2.5 py-2 text-[12px] font-medium text-white hover:brightness-110 disabled:opacity-50",children:[w?c.jsx(T,{size:13,className:"animate-spin"}):c.jsx(te,{size:13}),l("vm.workspace.handBack")]}):e?c.jsxs("button",{type:"button",onClick:()=>x(e.id),disabled:!r||w||m,className:"flex shrink-0 items-center gap-1.5 rounded-lg bg-raised px-2.5 py-2 text-[12px] text-ink hover:bg-raised-hover disabled:opacity-45",title:l("vm.workspace.takeControlTitle"),children:[w?c.jsx(T,{size:13,className:"animate-spin"}):c.jsx(te,{size:13}),m?l("vm.workspace.heldElsewhere"):l("vm.workspace.takeControl")]}):null]}),c.jsx("div",{ref:b,"data-native-view-host":!0,className:"relative min-h-0 flex-1 bg-[#070707]",children:c.jsx("div",{className:"absolute inset-0 flex items-center justify-center p-6 text-center",children:e?!C&&!E?c.jsxs("div",{className:"flex items-center gap-2 text-[12px] text-ink-secondary",children:[c.jsx(T,{size:15,className:"animate-spin"})," ",l("vm.workspace.checking",{name:e.name})]}):C?.ready&&j.status!=="error"&&!E?c.jsxs("div",{className:"flex items-center gap-2 text-[12px] text-ink-secondary",children:[c.jsx(T,{size:15,className:"animate-spin"})," ",l("vm.workspace.connecting")]}):c.jsxs("div",{className:"flex max-w-[300px] flex-col items-center gap-3 text-ink-secondary",children:[c.jsx(ie,{size:21,className:"text-warning"}),c.jsx("div",{className:"text-[12px] leading-relaxed",children:E??(C?.container==="missing"?l("vm.workspace.notCreated",{name:e.name}):C?.container==="stopped"?l("vm.workspace.stopped",{name:e.name}):l("vm.workspace.notReady",{name:e.name}))}),c.jsxs("div",{className:"flex gap-2",children:[c.jsxs("button",{type:"button",onClick:()=>V(t=>t+1),className:"flex items-center gap-1.5 rounded-lg bg-raised px-3 py-2 text-[12px] text-ink hover:bg-raised-hover",children:[c.jsx(je,{size:13})," ",l("vm.workspace.retryStatus")]}),c.jsx("button",{type:"button",onClick:()=>A(e.id),className:"rounded-lg bg-raised px-3 py-2 text-[12px] text-ink hover:bg-raised-hover",children:l("vm.workspace.openComputer")})]})]}):c.jsxs("div",{className:"flex max-w-[260px] flex-col items-center gap-2 text-ink-secondary",children:[c.jsx(le,{size:22}),c.jsx("span",{className:"text-[12px]",children:l("vm.workspace.chooseAnother")})]})})})]})}function $e({primaryBotId:s,overlayOpen:e,onClose:u,onOpenComputer:n}){const{state:o,dispatch:d}=be(),{dragProps:m}=Ne(),w=i.useMemo(()=>o.bots.filter(r=>r.computer==="vm"&&!r.hidden),[o.bots]),[h,x]=i.useState(()=>Ee(o.bots,s)),B=i.useRef(h),[A,v]=i.useState(null),p=i.useRef(null),I=i.useRef(null),b=I.current??ke();I.current=b;const k=i.useRef(!1),z=i.useRef(!0),[_,V]=i.useState(!1),[C,N]=i.useState(null),j=We(e);i.useEffect(()=>{B.current=h},[h]);const y=i.useMemo(()=>({async take(r){const t=await ee({action:"take",syncNativeBrowser:!0,requestControl:a=>ne(r,a,b),setNativeBrowserControl:a=>se()});return H(d,r,t),t.held&&t.owned===!0?p.current=r:p.current===r&&(p.current=null),t},async release(r){const t=await ee({action:"release",syncNativeBrowser:!0,requestControl:a=>ne(r,a,b),setNativeBrowserControl:a=>se()});return H(d,r,t),p.current===r&&(p.current=null),t},async setInteractive(r){const t=window.ogb?.desktopWorkspace;if(!t)throw new Error(l("vm.workspace.bridgeUnavailable"));return t.setInteractive(r)}}),[b,d]);i.useEffect(()=>{x(r=>{const t=Le(r,o.bots);return t[0]===r[0]&&t[1]===r[1]?r:t})},[o.bots]),i.useEffect(()=>{let r=!0;return(async()=>{for(const a of h)if(a)try{const f=await Oe(a);r&&H(d,a,f)}catch{}})(),()=>{r=!1}},[d,h]),i.useEffect(()=>{const r=p.current;!r||h.includes(r)||$(y,r).then(()=>{v(null)}).catch(()=>{N(l("vm.workspace.handoffFailed"))})},[y,h]),i.useEffect(()=>(z.current=!0,()=>{z.current=!1;const r=p.current,t=window.ogb?.desktopWorkspace;if(!t){r&&re(r,b);return}t.setInteractive(null).catch(()=>{}).then(()=>(r&&re(r,b),t.close())).catch(()=>{})}),[b]);const E=i.useCallback(r=>{const t=B.current.indexOf(r);return t<0?null:D[t]},[]),g=i.useCallback(async()=>{const r=p.current;if(!r)return!0;if(k.current)return!1;k.current=!0,V(!0),N(null);try{return await $(y,r),v(null),!0}catch{return N(l("vm.workspace.handBackFailed",{app:he()})),!1}finally{k.current=!1,V(!1)}},[y]),R=i.useCallback(async r=>{if(k.current||p.current===r)return;const t=window.ogb?.desktopWorkspace,a=E(r);if(!(!t||!a)){k.current=!0,V(!0),N(null);try{const f={...y,async setInteractive(S){if(S&&E(r)!==S)throw new Error(l("vm.workspace.paneChanged"));return y.setInteractive(S)}},M=await Se(f,p.current,r,a);if(v(null),M.status==="held-elsewhere"){N(l("vm.workspace.alreadyControlled"));return}if(!z.current){await $(y,r).catch(()=>{});return}v(r)}catch{v(p.current),N(l("vm.workspace.switchFailed"))}finally{k.current=!1,V(!1)}}},[E,y]),F=i.useCallback(async(r,t)=>{if(k.current)return;const a=B.current[r];a!==t&&(a&&p.current===a&&!await g()||x(f=>Re(f,r,t)))},[g]),L=i.useCallback(async()=>{p.current&&!await g()||u()},[g,u]),P=i.useCallback(async r=>{p.current&&!await g()||n(r)},[g,n]);return c.jsxs("main",{className:"flex h-full min-w-0 flex-1 flex-col bg-app",children:[c.jsxs("header",{...m,className:"flex min-h-[60px] items-center gap-3 border-b border-hairline/40 px-5 py-3",children:[c.jsx("div",{className:"flex h-9 w-9 shrink-0 items-center justify-center rounded-lg bg-accent/15 text-accent",children:c.jsx(le,{size:18})}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsx("h1",{className:"truncate text-[14px] font-semibold text-ink",children:l("vm.workspace.viewTitle")}),c.jsx("p",{className:"truncate text-[12px] text-ink-secondary",children:l("vm.workspace.viewSubtitle")})]}),c.jsx("button",{type:"button",onClick:()=>{L()},disabled:_,className:"rounded-md p-1.5 text-ink-secondary hover:bg-raised hover:text-ink disabled:opacity-50","aria-label":l("vm.workspace.closeView"),children:c.jsx(we,{size:18})})]}),C&&c.jsxs("div",{className:"mx-3 mt-3 flex items-center gap-2 rounded-lg border border-danger/30 bg-danger/10 px-3 py-2 text-[12px] text-danger",children:[c.jsx(ie,{size:14,className:"shrink-0"})," ",C]}),c.jsx("div",{className:"grid min-h-0 flex-1 grid-cols-2 gap-3 p-3",children:[0,1].map(r=>{const t=h[r],a=w.find(f=>f.id===t)??null;return c.jsx(_e,{index:r,bot:a,bots:w,otherBotId:h[r===0?1:0],obscured:j,active:!!(a&&A===a.id),heldElsewhere:!!(a&&o.computerControl[a.id]?.held&&A!==a.id),controlPending:_,onSelect:f=>{F(r,f)},onTake:f=>{R(f)},onRelease:()=>{g()},onOpenComputer:f=>{P(f)}},D[r])})})]})}export{$e as LocalVmWorkspace};
|
|
1
|
+
import{t as l,o as ae,s as ce,f as O,g as W,h as ve,r as i,p as he,j as c,X as we,a as Q,u as xe}from"./styles-DO3EUxm2.js";import{u as be,W as ke,X as ee,Y as ie,j as q,w as ye,U as te,Z as ge}from"./App-BgdjoCaG.js";import{u as Ne,L as T}from"./PlacesRail-tZyNm-l3.js";import{M as le}from"./monitor-zecPzfR5.js";import{R as je}from"./MenuMotion-B0aZnuh_.js";import"./index-BQM4L4RU.js";function Ce(s,e){const u=(n,o)=>n.left<o.right&&n.right>o.left&&n.top<o.bottom&&n.bottom>o.top;return e.some(n=>n.visible&&n.rect.width>0&&n.rect.height>0&&(n.explicit||n.zIndex!==null&&n.zIndex>=10)&&s.some(o=>u(n.rect,o)))}async function Se(s,e,u,n){e&&e!==u&&(await s.setInteractive(null),await s.release(e));const o=await s.take(u);if(!o.held)throw new Error(l("vm.workspace.holdNotAcquired"));if(o.owned!==!0)return{status:"held-elsewhere",botId:u,snapshot:o};try{await s.setInteractive(n)}catch(d){throw await s.setInteractive(null).catch(()=>{}),await s.release(u).catch(()=>{}),d}return{status:"controlled",botId:u,snapshot:o}}async function $(s,e){return e?(await s.setInteractive(null).catch(()=>{}),s.release(e)):null}function ue(s){return s.filter(e=>e.computer==="vm"&&e.hidden!==!0).map(e=>e.id)}function Ee(s,e){const u=ue(s),n=u.includes(e)?e:u[0]??null;return[n,u.find(o=>o!==n)??null]}function Re(s,e,u){const n=[...s],o=e===0?1:0;return u&&n[o]===u&&(n[o]=n[e]),n[e]=u,n}function Le(s,e){const u=ue(e),n=new Set(u),o=[null,null];for(const d of[0,1]){const m=s[d];m&&n.delete(m)&&(o[d]=m)}for(const d of[0,1]){if(o[d])continue;const m=[...n][0];m&&(o[d]=m,n.delete(m))}return o}const ze=ae({mode:W(["shared","per-bot","pool"]).optional(),max_instances:ve().int().nonnegative().optional(),container:W(["running","stopped","missing"]).optional(),network:W(["loopback","unsafe","unknown"]).optional(),security:W(["hardened","unsafe","unknown"]).optional(),persistence:W(["durable","unsafe","unknown"]).optional(),desktopReady:O().optional(),ready:O().optional(),viewer_url:ce().min(1).optional()});function de(s){const e=ze.safeParse(s);return e.success?e.data:null}function X(s){const e=de(s),u=e?.mode??"unknown",n=e?.container??"unknown",o=e?.network??"unknown",d=e?.security??"unknown",m=e?.persistence??"unknown",w=e?.max_instances??0,h=e?.desktopReady===!0,x=!!(e?.ready===!0&&n==="running"&&o==="loopback"&&d==="hardened"&&m==="durable"&&h);return{mode:u,maxInstances:w,container:n,network:o,security:d,persistence:m,desktopReady:h,ready:x}}function Ve(s){const e=de(s);return!e||!X(s).ready?null:e.viewer_url??null}const D=["local-vm-workspace:left","local-vm-workspace:right"],pe=ae({held:O(),helpReason:ce().nullable(),help:xe().optional().transform(ge),owned:O().optional(),acquired:O().optional(),released:O().optional()});async function ne(s,e,u){const n=await q(`/api/bots/${s}/computer/control`,{method:"POST",body:JSON.stringify({action:e,controlLeaseId:u})}),o=pe.safeParse(n);if(!o.success)throw new Error("invalid-control-snapshot");return o.data}async function Oe(s){const e=pe.safeParse(await q(`/api/bots/${s}/computer/control`));if(!e.success)throw new Error("invalid-control-snapshot");return e.data}function re(s,e){fetch(`/api/bots/${s}/computer/control`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({action:"release",controlLeaseId:e}),keepalive:!0}).then(async u=>{u.ok}).catch(()=>{})}async function se(s,e){return!0}function H(s,e,u){s({type:"computerControl",botId:e,held:u.held,helpReason:u.helpReason,help:u.help??null})}function oe(s){const e=s.current?.getBoundingClientRect();return!e||e.width<1||e.height<1?null:{x:Math.round(e.left),y:Math.round(e.top),width:Math.round(e.width),height:Math.round(e.height)}}const Be=['[aria-modal="true"]','[role="dialog"]','[role="menu"]',"[popover]","[data-native-view-overlay]",".fixed",".absolute"].join(",");function Ie(){const s=[...document.querySelectorAll("[data-native-view-host]")],e=s.map(n=>n.getBoundingClientRect()).filter(n=>n.width>0&&n.height>0);if(e.length===0)return!1;const u=[...document.querySelectorAll(Be)].filter(n=>!s.some(o=>n===o||n.contains(o)||o.contains(n))).map(n=>{const o=window.getComputedStyle(n),d=n.matches('[aria-modal="true"], [role="dialog"], [role="menu"], [popover], [data-native-view-overlay]'),m=Number.parseInt(o.zIndex,10);return{rect:n.getBoundingClientRect(),explicit:d,visible:o.display!=="none"&&o.visibility!=="hidden"&&Number(o.opacity)!==0,zIndex:Number.isFinite(m)?m:null}});return Ce(e,u)}function We(s){const[e,u]=i.useState(!1);return i.useEffect(()=>{let n=0;const o=()=>u(Ie()),d=()=>{n||(n=requestAnimationFrame(()=>{n=0,o()}))};o();const m=new MutationObserver(d);m.observe(document.body,{subtree:!0,childList:!0,attributes:!0,attributeFilter:["class","style","aria-hidden","aria-modal","role","open","popover"]});const w=new ResizeObserver(d);w.observe(document.body);for(const x of document.querySelectorAll("[data-native-view-host]"))w.observe(x);const h=["toggle","animationstart","animationend","transitionstart","transitionend"];for(const x of h)document.addEventListener(x,d,!0);return window.addEventListener("resize",d),window.addEventListener("scroll",d,!0),()=>{n&&cancelAnimationFrame(n),m.disconnect(),w.disconnect();for(const x of h)document.removeEventListener(x,d,!0);window.removeEventListener("resize",d),window.removeEventListener("scroll",d,!0)}},[]),s||e}function Ae(s,e){return s?s.container==="missing"?l("vm.workspace.status.missing"):s.container==="stopped"?l("vm.workspace.status.stopped"):s.ready?e==="error"?l("vm.workspace.status.viewerUnavailable"):e!=="ready"?l("vm.workspace.status.connecting"):l("vm.workspace.status.live"):l("vm.workspace.status.unavailable"):l("vm.workspace.status.checking")}function _e({index:s,bot:e,bots:u,otherBotId:n,obscured:o,active:d,heldElsewhere:m,controlPending:w,onSelect:h,onTake:x,onRelease:B,onOpenComputer:A}){const v=D[s],p=e?.id??null,I=e?.name??l("vm.workspace.localVm"),b=i.useRef(null),k=i.useRef(Promise.resolve()),z=i.useRef(o),[_,V]=i.useState(0),[C,N]=i.useState(null),[j,y]=i.useState({contextId:v,open:!1,status:"closed",interactive:!1}),[E,g]=i.useState(null),R=i.useCallback(async t=>{if(p)try{const a=await q(`/api/bots/${p}/local-computer`,{signal:t});t?.aborted||N(X(a))}catch{}},[p]),F=i.useRef(R);i.useEffect(()=>{F.current=R},[R]),i.useEffect(()=>{z.current=o},[o]),i.useEffect(()=>window.ogb?.desktopWorkspace?.onState(a=>{a.contextId===v&&(y(a),(a.status==="error"||a.status==="closed")&&F.current())}),[v]),i.useEffect(()=>{const t=window.ogb?.desktopWorkspace;let a=!0;const f=new AbortController;N(null),g(null),y({contextId:v,open:!1,status:"closed",interactive:!1});const M=async()=>{if(t&&await t.close(v).catch(()=>{}),!(!a||!p)){if(!t){g(l("vm.workspace.desktopRequired"));return}try{const S=await q(`/api/bots/${p}/local-computer`,{signal:f.signal});if(!a)return;const J=X(S);N(J);const Y=Ve(S);if(!J.ready||!Y||(await new Promise(me=>{let G=!1;const K=()=>{G||(G=!0,me())},fe=setTimeout(K,100);requestAnimationFrame(()=>{clearTimeout(fe),K()})}),!a))return;const U=oe(b);if(!U)throw new Error("layout-unavailable");const Z=await t.open({contextId:v,url:Y,title:l("vm.workspace.windowTitle",{name:I}),bounds:U});if(!a){await t.close(v).catch(()=>{});return}y(Z),await t.layout([{contextId:v,bounds:U,visible:!z.current&&Z.open}])}catch(S){if(!a||f.signal.aborted)return;g(S instanceof Error&&S.message==="layout-unavailable"?l("vm.workspace.layoutUnavailable"):l("vm.workspace.connectFailed"))}}};return k.current=k.current.catch(()=>{}).then(M),()=>{a=!1,f.abort(),t&&(k.current=k.current.catch(()=>{}).then(()=>t.close(v).then(()=>{}).catch(()=>{})))}},[p,I,v,_]),i.useEffect(()=>{if(!p)return;const t=new AbortController,a=window.setInterval(()=>{R(t.signal)},3e4);return()=>{t.abort(),window.clearInterval(a)}},[p,R]);const L=i.useCallback(()=>{const t=window.ogb?.desktopWorkspace,a=oe(b);!t||!a||!j.open||t.layout([{contextId:v,bounds:a,visible:!o}]).catch(()=>g(l("vm.workspace.positionFailed")))},[v,j.open,o]);i.useEffect(()=>{const t=b.current;if(!t)return;const a=new ResizeObserver(L);a.observe(t),window.addEventListener("resize",L);const f=requestAnimationFrame(L);return()=>{cancelAnimationFrame(f),a.disconnect(),window.removeEventListener("resize",L)}},[L]);const P=Ae(C,j.status),r=!!(e&&C?.ready&&j.status==="ready"&&j.open);return c.jsxs("section",{className:Q("flex min-h-0 min-w-0 flex-col overflow-hidden rounded-xl border bg-panel",d?"border-accent/80 shadow-[0_0_0_1px_rgb(var(--accent)/0.35)]":"border-hairline/50"),children:[c.jsxs("div",{className:"flex min-h-[68px] items-center gap-3 border-b border-hairline/40 px-3 py-2.5",children:[c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsx("label",{className:"sr-only",htmlFor:`local-vm-slot-${s}`,children:l("vm.workspace.paneLabel",{number:s+1})}),c.jsxs(ye,{size:"sm",className:"w-full",id:`local-vm-slot-${s}`,value:e?.id??"",onChange:t=>h(t.target.value||null),disabled:w,children:[c.jsx("option",{value:"",children:l("vm.workspace.chooseBot")}),u.map(t=>c.jsx("option",{value:t.id,disabled:t.id===n,children:t.name},t.id))]}),c.jsxs("div",{className:"mt-1 flex items-center gap-1.5 text-[11px] text-ink-secondary",children:[c.jsx("span",{className:Q("h-1.5 w-1.5 rounded-full",d?"bg-accent":j.status==="ready"?"bg-success":j.status==="error"?"bg-danger":"bg-ink-secondary/50")}),d?l("vm.workspace.youHaveControl"):m?l("vm.workspace.controlElsewhere"):P]})]}),e&&d?c.jsxs("button",{type:"button",onClick:B,disabled:w,className:"flex shrink-0 items-center gap-1.5 rounded-lg bg-accent px-2.5 py-2 text-[12px] font-medium text-white hover:brightness-110 disabled:opacity-50",children:[w?c.jsx(T,{size:13,className:"animate-spin"}):c.jsx(te,{size:13}),l("vm.workspace.handBack")]}):e?c.jsxs("button",{type:"button",onClick:()=>x(e.id),disabled:!r||w||m,className:"flex shrink-0 items-center gap-1.5 rounded-lg bg-raised px-2.5 py-2 text-[12px] text-ink hover:bg-raised-hover disabled:opacity-45",title:l("vm.workspace.takeControlTitle"),children:[w?c.jsx(T,{size:13,className:"animate-spin"}):c.jsx(te,{size:13}),m?l("vm.workspace.heldElsewhere"):l("vm.workspace.takeControl")]}):null]}),c.jsx("div",{ref:b,"data-native-view-host":!0,className:"relative min-h-0 flex-1 bg-[#070707]",children:c.jsx("div",{className:"absolute inset-0 flex items-center justify-center p-6 text-center",children:e?!C&&!E?c.jsxs("div",{className:"flex items-center gap-2 text-[12px] text-ink-secondary",children:[c.jsx(T,{size:15,className:"animate-spin"})," ",l("vm.workspace.checking",{name:e.name})]}):C?.ready&&j.status!=="error"&&!E?c.jsxs("div",{className:"flex items-center gap-2 text-[12px] text-ink-secondary",children:[c.jsx(T,{size:15,className:"animate-spin"})," ",l("vm.workspace.connecting")]}):c.jsxs("div",{className:"flex max-w-[300px] flex-col items-center gap-3 text-ink-secondary",children:[c.jsx(ie,{size:21,className:"text-warning"}),c.jsx("div",{className:"text-[12px] leading-relaxed",children:E??(C?.container==="missing"?l("vm.workspace.notCreated",{name:e.name}):C?.container==="stopped"?l("vm.workspace.stopped",{name:e.name}):l("vm.workspace.notReady",{name:e.name}))}),c.jsxs("div",{className:"flex gap-2",children:[c.jsxs("button",{type:"button",onClick:()=>V(t=>t+1),className:"flex items-center gap-1.5 rounded-lg bg-raised px-3 py-2 text-[12px] text-ink hover:bg-raised-hover",children:[c.jsx(je,{size:13})," ",l("vm.workspace.retryStatus")]}),c.jsx("button",{type:"button",onClick:()=>A(e.id),className:"rounded-lg bg-raised px-3 py-2 text-[12px] text-ink hover:bg-raised-hover",children:l("vm.workspace.openComputer")})]})]}):c.jsxs("div",{className:"flex max-w-[260px] flex-col items-center gap-2 text-ink-secondary",children:[c.jsx(le,{size:22}),c.jsx("span",{className:"text-[12px]",children:l("vm.workspace.chooseAnother")})]})})})]})}function $e({primaryBotId:s,overlayOpen:e,onClose:u,onOpenComputer:n}){const{state:o,dispatch:d}=be(),{dragProps:m}=Ne(),w=i.useMemo(()=>o.bots.filter(r=>r.computer==="vm"&&!r.hidden),[o.bots]),[h,x]=i.useState(()=>Ee(o.bots,s)),B=i.useRef(h),[A,v]=i.useState(null),p=i.useRef(null),I=i.useRef(null),b=I.current??ke();I.current=b;const k=i.useRef(!1),z=i.useRef(!0),[_,V]=i.useState(!1),[C,N]=i.useState(null),j=We(e);i.useEffect(()=>{B.current=h},[h]);const y=i.useMemo(()=>({async take(r){const t=await ee({action:"take",syncNativeBrowser:!0,requestControl:a=>ne(r,a,b),setNativeBrowserControl:a=>se()});return H(d,r,t),t.held&&t.owned===!0?p.current=r:p.current===r&&(p.current=null),t},async release(r){const t=await ee({action:"release",syncNativeBrowser:!0,requestControl:a=>ne(r,a,b),setNativeBrowserControl:a=>se()});return H(d,r,t),p.current===r&&(p.current=null),t},async setInteractive(r){const t=window.ogb?.desktopWorkspace;if(!t)throw new Error(l("vm.workspace.bridgeUnavailable"));return t.setInteractive(r)}}),[b,d]);i.useEffect(()=>{x(r=>{const t=Le(r,o.bots);return t[0]===r[0]&&t[1]===r[1]?r:t})},[o.bots]),i.useEffect(()=>{let r=!0;return(async()=>{for(const a of h)if(a)try{const f=await Oe(a);r&&H(d,a,f)}catch{}})(),()=>{r=!1}},[d,h]),i.useEffect(()=>{const r=p.current;!r||h.includes(r)||$(y,r).then(()=>{v(null)}).catch(()=>{N(l("vm.workspace.handoffFailed"))})},[y,h]),i.useEffect(()=>(z.current=!0,()=>{z.current=!1;const r=p.current,t=window.ogb?.desktopWorkspace;if(!t){r&&re(r,b);return}t.setInteractive(null).catch(()=>{}).then(()=>(r&&re(r,b),t.close())).catch(()=>{})}),[b]);const E=i.useCallback(r=>{const t=B.current.indexOf(r);return t<0?null:D[t]},[]),g=i.useCallback(async()=>{const r=p.current;if(!r)return!0;if(k.current)return!1;k.current=!0,V(!0),N(null);try{return await $(y,r),v(null),!0}catch{return N(l("vm.workspace.handBackFailed",{app:he()})),!1}finally{k.current=!1,V(!1)}},[y]),R=i.useCallback(async r=>{if(k.current||p.current===r)return;const t=window.ogb?.desktopWorkspace,a=E(r);if(!(!t||!a)){k.current=!0,V(!0),N(null);try{const f={...y,async setInteractive(S){if(S&&E(r)!==S)throw new Error(l("vm.workspace.paneChanged"));return y.setInteractive(S)}},M=await Se(f,p.current,r,a);if(v(null),M.status==="held-elsewhere"){N(l("vm.workspace.alreadyControlled"));return}if(!z.current){await $(y,r).catch(()=>{});return}v(r)}catch{v(p.current),N(l("vm.workspace.switchFailed"))}finally{k.current=!1,V(!1)}}},[E,y]),F=i.useCallback(async(r,t)=>{if(k.current)return;const a=B.current[r];a!==t&&(a&&p.current===a&&!await g()||x(f=>Re(f,r,t)))},[g]),L=i.useCallback(async()=>{p.current&&!await g()||u()},[g,u]),P=i.useCallback(async r=>{p.current&&!await g()||n(r)},[g,n]);return c.jsxs("main",{className:"flex h-full min-w-0 flex-1 flex-col bg-app",children:[c.jsxs("header",{...m,className:"flex min-h-[60px] items-center gap-3 border-b border-hairline/40 px-5 py-3",children:[c.jsx("div",{className:"flex h-9 w-9 shrink-0 items-center justify-center rounded-lg bg-accent/15 text-accent",children:c.jsx(le,{size:18})}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsx("h1",{className:"truncate text-[14px] font-semibold text-ink",children:l("vm.workspace.viewTitle")}),c.jsx("p",{className:"truncate text-[12px] text-ink-secondary",children:l("vm.workspace.viewSubtitle")})]}),c.jsx("button",{type:"button",onClick:()=>{L()},disabled:_,className:"rounded-md p-1.5 text-ink-secondary hover:bg-raised hover:text-ink disabled:opacity-50","aria-label":l("vm.workspace.closeView"),children:c.jsx(we,{size:18})})]}),C&&c.jsxs("div",{className:"mx-3 mt-3 flex items-center gap-2 rounded-lg border border-danger/30 bg-danger/10 px-3 py-2 text-[12px] text-danger",children:[c.jsx(ie,{size:14,className:"shrink-0"})," ",C]}),c.jsx("div",{className:"grid min-h-0 flex-1 grid-cols-2 gap-3 p-3",children:[0,1].map(r=>{const t=h[r],a=w.find(f=>f.id===t)??null;return c.jsx(_e,{index:r,bot:a,bots:w,otherBotId:h[r===0?1:0],obscured:j,active:!!(a&&A===a.id),heldElsewhere:!!(a&&o.computerControl[a.id]?.held&&A!==a.id),controlPending:_,onSelect:f=>{F(r,f)},onTake:f=>{R(f)},onRelease:()=>{g()},onOpenComputer:f=>{P(f)}},D[r])})})]})}export{$e as LocalVmWorkspace};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as v,t as a,r as u,j as t}from"./styles-DO3EUxm2.js";import{d as k,L}from"./PlacesRail-tZyNm-l3.js";import{bl as C,bm as j,Y as N,bn as M,bo as S}from"./App-
|
|
1
|
+
import{c as v,t as a,r as u,j as t}from"./styles-DO3EUxm2.js";import{d as k,L}from"./PlacesRail-tZyNm-l3.js";import{bl as C,bm as j,Y as N,bn as M,bo as S}from"./App-BgdjoCaG.js";const E=[["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"}]],T=v("shield",E);async function I(e,r,s,i=6e4){const o=Date.now()+i;let c=e;for(;!c.ready&&c.container==="running"&&Date.now()<o;)s.throwIfAborted(),await new Promise((p,d)=>{const m=()=>{window.clearTimeout(l),d(s.reason)},l=window.setTimeout(()=>{s.removeEventListener("abort",m),p()},2e3);s.addEventListener("abort",m,{once:!0})}),c=await r();return s.throwIfAborted(),c}function g(e){if(!e)return e??null;const s={"Create the Local VM":"computer.problem.createVm","The Local VM is stopped; start it to continue":"computer.problem.vmStopped","The Local VM started, but Cua Driver is not ready yet":"computer.problem.cuaNotReady","The existing Local VM uses an older desktop or Cua Driver; recreate it":"computer.problem.oldImage","The existing container was not created by Limix Bot; recreate it":"computer.problem.unmanaged","The existing Local VM exposes its viewer publicly; recreate it":"computer.problem.publicViewer","The existing Local VM is missing safety limits; recreate it":"computer.problem.missingLimits","The existing Local VM is missing its durable folder; recreate it":"computer.problem.missingDurableFolder","Replace the private desktop to apply the working folder access change":"computer.problem.workingFolderChanged","Per-bot Local VMs require Docker or Podman because Apple container requires a fixed host port":"computer.problem.perBotRuntime","Install a supported container runtime first":"computer.problem.noRuntime"}[e];if(s)return a(s);const i=/^Start (\S+) first$/.exec(e);if(i)return a("computer.problem.startRuntime",{runtime:i[1]});const o=/^The Local VM desktop failed to start: (.+)$/.exec(e);return o?a("computer.problem.desktopFailed",{detail:o[1]}):e}class V extends Error{constructor(r,s,i){super(r),this.key=r,this.problem=s,this.fallbackKey=i}key;problem;fallbackKey}function K(e){if(e instanceof V)return a(e.key,e.fallbackKey?{problem:g(e.problem)??a(e.fallbackKey)}:void 0);const r=e instanceof Error?e.message:e;return typeof r=="string"&&/^\s*(?:HTTP\s*)?\d{3}\s*$/iu.test(r)?a("computer.err.screenUnavailable"):g(r)}let f=!1;const b=new Set,R=e=>(b.add(e),()=>{b.delete(e)}),w=()=>f;function P(){f=!0;for(const e of b)e()}async function D(e=r=>window.ogb?.permOpenSettings?.(r)){await e("accessibility"),!f&&await e("screen")}function B(){const{capabilities:e}=k(),r=u.useSyncExternalStore(R,w,w),s=e.localComputer.available?null:e.localComputer.message,i=C(j(s)),[o,c]=u.useState(!1),[p,d]=u.useState(!1),[m,l]=u.useState(null),h=async()=>{c(!0),l(null);try{await window.ogb?.localControl?.retry()}catch(n){l(n instanceof Error?n.message:String(n))}finally{c(!1)}},y=async()=>{l(null),d(!0);try{await D()}catch(n){d(!1),l(n instanceof Error?n.message:String(n))}};return u.useEffect(()=>{if(!p||r)return;let n=!1;const x=()=>{n||document.visibilityState==="visible"&&(n=!0,d(!1),h())};return window.addEventListener("focus",x),document.addEventListener("visibilitychange",x),()=>{window.removeEventListener("focus",x),document.removeEventListener("visibilitychange",x)}},[p,r]),e.host.platform!=="darwin"||e.localComputer.reasonCode==="remote-server"||e.localComputer.available||r?null:t.jsx("section",{className:"mt-4 rounded-xl border border-warning/25 bg-warning/10 p-4",children:t.jsxs("div",{className:"flex items-start gap-3",children:[t.jsx(T,{size:16,className:"mt-0.5 shrink-0 text-warning"}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("div",{className:"text-[14px] font-medium text-ink",children:a("computer.mac.allowTitle")}),t.jsx("p",{className:"mt-1 text-[13px] leading-relaxed text-ink-secondary",children:i??a("computer.mac.permission.generic")}),s&&t.jsxs("details",{className:"mt-2 text-[12px] text-ink-secondary",children:[t.jsx("summary",{className:"cursor-pointer",children:a("computer.mac.permission.driverDetail")}),t.jsx("p",{className:"mt-1 break-words",children:s})]}),m&&t.jsxs("div",{className:"mt-2 flex gap-1.5 text-[12px] text-danger",children:[t.jsx(N,{size:13,className:"mt-0.5 shrink-0"}),t.jsx("span",{children:m})]}),t.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[i&&s&&t.jsx(M,{reason:s}),!i&&t.jsx("button",{type:"button",onClick:()=>{y()},disabled:o,className:"inline-flex items-center gap-1.5 rounded-lg bg-accent px-3 py-1.5 text-[13px] font-medium text-white hover:brightness-110 disabled:opacity-50",children:a("computer.mac.openSystemSettings")}),t.jsxs("button",{type:"button",onClick:()=>{h()},disabled:o,className:"inline-flex items-center gap-1.5 rounded-lg border border-hairline/50 px-3 py-1.5 text-[13px] font-medium text-ink hover:bg-raised disabled:opacity-50",children:[o&&t.jsx(L,{size:13,className:"animate-spin"}),a("commandAllowlist.retry")]}),!o&&t.jsx(S,{onClick:P})]})]})]})})}export{V as L,B as M,g as l,K as p,I as w};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as i,j as e,t}from"./styles-DO3EUxm2.js";import{F as v,H as k,J as N,K as j,M as y,N as C,R as E,O as S}from"./App-
|
|
1
|
+
import{r as i,j as e,t}from"./styles-DO3EUxm2.js";import{F as v,H as k,J as N,K as j,M as y,N as C,R as E,O as S}from"./App-BgdjoCaG.js";import{L as z}from"./PlacesRail-tZyNm-l3.js";import"./index-BQM4L4RU.js";import"./monitor-zecPzfR5.js";import"./MenuMotion-B0aZnuh_.js";const A=2*1024*1024;function D({path:r,name:n,message:d}){const[x,u]=i.useState(0),[p,h]=i.useState(null),[c,m]=i.useState(null),[l,w]=i.useState(!1),a=v(r,n,d);i.useEffect(()=>{const o=new AbortController;return m(null),h(null),(async()=>{let f=!1;try{const s=await k(r,d,o.signal);f=!0;const g=await N(s,o.signal,A,"windows-1252");o.signal.aborted||h(g)}catch(s){if(o.signal.aborted)return;!f&&s instanceof Error&&!(s instanceof TypeError)?m({reason:s.message}):m(s instanceof Error&&s.message==="size"?"size":"load")}})(),()=>o.abort()},[r,d.threadId,d.messageId,x]);const b=e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mt-3 flex flex-wrap justify-center gap-2",children:[e.jsxs("button",{type:"button",className:"inline-flex max-w-full min-w-0 items-center gap-1.5 rounded-lg border border-hairline px-3 py-2 hover:bg-raised",disabled:a.state==="saving",onClick:()=>{a.save()},children:[e.jsx(j,{size:14,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 break-all",children:t("attach.saveAria",{name:n})})]}),e.jsx("button",{type:"button",className:"rounded-lg border border-hairline px-3 py-2 hover:bg-raised",onClick:()=>u(x+1),children:t("chat.retry")})]}),a.state==="failed"&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:a.reason})]});return c?e.jsxs("div",{className:"p-8 text-center text-sm",children:[e.jsx("p",{role:"alert",className:"text-ink-secondary",children:typeof c=="object"?t("markdown.refused",{reason:c.reason}):t(c==="size"?"markdown.tooLarge":"markdown.loadFailed")}),b]}):p===null?e.jsxs("div",{className:"p-12 text-center text-sm text-ink-secondary",children:[e.jsxs("span",{role:"status",className:"inline-flex items-center gap-2",children:[e.jsx(z,{size:16,className:"animate-spin"}),t("markdown.loading")]}),b]}):e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center justify-end gap-1",children:[e.jsx("button",{type:"button",className:"table-action","aria-pressed":l,"aria-label":t(l?"markdown.rendered":"html.source"),title:t(l?"markdown.rendered":"html.source"),onClick:()=>w(!l),children:l?e.jsx(y,{size:14}):e.jsx(C,{size:14})}),e.jsx("button",{type:"button",className:"table-action","aria-label":t("html.reload"),title:t("html.reload"),onClick:()=>u(x+1),children:e.jsx(E,{size:14})}),e.jsx("button",{type:"button",className:"table-action","aria-label":t("attach.saveAria",{name:n}),title:t("attach.saveAria",{name:n}),disabled:a.state==="saving",onClick:()=>{a.save()},children:e.jsx(j,{size:14})})]}),a.state==="failed"&&e.jsx("p",{role:"alert",className:"text-end text-[12px] text-danger",children:a.reason}),e.jsx(F,{source:p,showSource:l})]})}function F({source:r,showSource:n}){return n?e.jsx("pre",{className:"h-[72dvh] overflow-auto rounded-lg border border-hairline/40 bg-inset p-3 text-[12px] leading-5 whitespace-pre-wrap break-words text-ink",children:r}):e.jsx("div",{"data-markdown-file":!0,className:"h-[72dvh] overflow-auto rounded-lg border border-hairline/40 bg-panel px-5 py-4 text-[14px] leading-6 text-ink",children:e.jsx(S,{text:r})})}export{A as MARKDOWN_PREVIEW_MAX_BYTES,F as MarkdownFileView,D as default};
|