pikiloom 0.4.42 → 0.4.43
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/dashboard/dist/assets/{AgentTab-B9z4W2mh.js → AgentTab-B8V2eV_D.js} +1 -1
- package/dashboard/dist/assets/{ConnectionModal-2bL7sFKk.js → ConnectionModal-BOVwXLJB.js} +1 -1
- package/dashboard/dist/assets/{DirBrowser-CA4k8E_A.js → DirBrowser-DbeAWYiL.js} +1 -1
- package/dashboard/dist/assets/{ExtensionsTab-CRjTmFRl.js → ExtensionsTab-BMS3PW9N.js} +1 -1
- package/dashboard/dist/assets/{IMAccessTab-DDb7rsHe.js → IMAccessTab-B1sRgJk3.js} +1 -1
- package/dashboard/dist/assets/{Modal-DDiBG4kb.js → Modal-DCwGz46r.js} +1 -1
- package/dashboard/dist/assets/{Modals-CsUQjpxn.js → Modals-Bh_0en5P.js} +1 -1
- package/dashboard/dist/assets/{Select-CG_7h_Tz.js → Select-DC6zguGC.js} +1 -1
- package/dashboard/dist/assets/{SessionPanel-B5964GUj.js → SessionPanel-DNlLd-PL.js} +1 -1
- package/dashboard/dist/assets/{SystemTab-D7r1PsC9.js → SystemTab-uFqZinIZ.js} +1 -1
- package/dashboard/dist/assets/{index-BbplxgnQ.js → index-CL5H13Cl.js} +2 -2
- package/dashboard/dist/assets/index-DooLxbPX.js +23 -0
- package/dashboard/dist/assets/{shared-Bv8WvQSo.js → shared-Byy2BNLq.js} +1 -1
- package/dashboard/dist/index.html +1 -1
- package/dist/agent/accounts.js +2 -2
- package/dist/agent/drivers/claude.js +84 -38
- package/dist/agent/drivers/codex.js +30 -2
- package/dist/agent/kernel-bridge.js +18 -2
- package/dist/dashboard/routes/accounts.js +7 -0
- package/dist/dashboard/routes/agents.js +1 -1
- package/package.json +1 -1
- package/packages/kernel/dist/drivers/claude.d.ts +3 -1
- package/packages/kernel/dist/drivers/claude.js +126 -9
- package/packages/kernel/dist/drivers/codex.js +15 -3
- package/dashboard/dist/assets/index-CULTTvtY.js +0 -23
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as a,j as e}from"./react-vendor-C7Sl8SE7.js";import{u as C,d as _,L,I as P,m as D,a as F,t as Q}from"./index-BbplxgnQ.js";import{M as O,a as H}from"./Modal-DDiBG4kb.js";import{D as se}from"./DirBrowser-CA4k8E_A.js";import"./router-DHISdpPk.js";const Y="https://ilinkai.weixin.qq.com";function V(i){return i instanceof Error&&(i.name==="AbortError"||/aborted/i.test(i.message))}function $(i,h){return i instanceof Error&&/timed out/i.test(i.message)?h("modal.requestTimeout"):h("modal.networkError")}function de({open:i,onClose:h}){const p=C(d=>d.state),o=C(d=>d.toast),r=C(d=>d.reloadUntil),s=C(d=>d.locale),t=a.useMemo(()=>_(s),[s]),[w,G]=a.useState(""),[j,v]=a.useState(""),[B,S]=a.useState(!1),[y,c]=a.useState(!1),[u,n]=a.useState(null),[m,N]=a.useState(!1),T=a.useRef(null),E=a.useRef(p);E.current=p,a.useEffect(()=>{i?(G(E.current?.config.telegramBotToken||""),v(E.current?.config.telegramAllowedChatIds||""),S(!1),n(null),N(!E.current?.config.telegramBotToken)):(T.current?.abort(),T.current=null,c(!1))},[i]),a.useEffect(()=>()=>{T.current?.abort(),T.current=null},[]);const k=async()=>{if(!w.trim()){o(t("modal.inputToken"),!1);return}T.current?.abort();const d=new AbortController;T.current=d,c(!0),n(null);let b=!1;try{const f=await F.validateTelegramConfig(w.trim(),j.trim(),{signal:d.signal,timeoutMs:12e3});if(!f.ok){n({ok:!1,text:"✗ "+(f.error||t("modal.validationFailed"))});return}const l=f.normalizedAllowedChatIds??j.trim();n({ok:!0,text:"✓ @"+(f.bot?.username||"bot")+(f.bot?.displayName?" ("+f.bot.displayName+")":"")});const U=new Set((p?.setupState?.channels||[]).filter(A=>(A.ready||A.configured)&&A.channel!=="telegram").map(A=>A.channel));if(U.add("telegram"),await F.saveConfig({telegramBotToken:w.trim(),telegramAllowedChatIds:l,channels:[...U]}),!await r(A=>{const z=A.setupState?.channels?.find(g=>g.channel==="telegram");return A.config.telegramBotToken===w.trim()&&(A.config.telegramAllowedChatIds||"")===l&&!!z?.ready},{attempts:10,intervalMs:350})){n({ok:!1,text:"✗ "+t("modal.refreshStateFailed")}),o(t("modal.refreshStateFailed"),!1);return}o(t("modal.tgSaved")),b=!0}catch(f){if(V(f))return;const l=$(f,t);n({ok:!1,text:"✗ "+l}),o(l,!1)}finally{T.current===d&&(T.current=null),c(!1),b&&h()}},x=()=>{T.current?.abort(),T.current=null,h()};return e.jsxs(O,{open:i,onClose:x,children:[e.jsx(H,{title:t("modal.configureTelegram"),onClose:x}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-lg border border-edge bg-panel-alt",children:[e.jsxs("button",{type:"button",className:"flex w-full items-center justify-between px-3 py-2 text-xs font-medium text-fg-3 hover:text-fg-2 transition-colors",onClick:()=>N(!m),children:[e.jsx("span",{children:t("modal.tgGuideTitle")}),e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:`transition-transform ${m?"rotate-180":""}`,children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),m&&e.jsxs("div",{className:"space-y-1 border-t border-edge px-3 pb-3 pt-2 text-xs leading-relaxed text-fg-4",children:[e.jsx("p",{children:t("modal.tgGuideStep1")}),e.jsx("p",{children:t("modal.tgGuideStep2")}),e.jsx("p",{children:t("modal.tgGuideStep3")}),e.jsx("p",{children:t("modal.tgGuideStep4")}),e.jsx("p",{className:"mt-2 text-[11px] text-fg-5",children:t("modal.tgGuideIdTip")})]})]}),e.jsxs("div",{children:[e.jsx(L,{children:t("modal.botToken")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(P,{type:B?"text":"password",className:"flex-1 font-mono text-xs",placeholder:t("modal.pasteToken"),value:w,onChange:d=>G(d.target.value)}),e.jsx(D,{variant:"ghost",size:"sm",className:"!w-[34px] !p-0",onClick:()=>S(!B),children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[e.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),e.jsx("circle",{cx:"12",cy:"12",r:"3"})]})})]})]}),u&&e.jsx("div",{className:"text-xs",style:{color:u.ok?"var(--th-ok)":"var(--th-err)"},children:u.text}),e.jsxs("div",{children:[e.jsxs(L,{children:[t("modal.allowedIds")," ",e.jsxs("span",{className:"text-fg-5",children:["(",t("modal.optional"),")"]})]}),e.jsx(P,{className:"font-mono text-xs",placeholder:t("modal.commaSep"),value:j,onChange:d=>v(d.target.value)})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 mt-6",children:[e.jsx(D,{variant:"ghost",onClick:x,children:t("modal.cancel")}),e.jsx(D,{variant:"primary",disabled:y,onClick:k,children:t(y?"modal.validating":"modal.validateSave")})]})]})}const ee=JSON.stringify({scopes:{tenant:["im:message","im:message:send_as_bot","im:message.p2p_msg:readonly","im:message.group_at_msg:readonly","im:resource"],user:[]}},null,2);function ce({open:i,onClose:h}){const p=C(k=>k.state),o=C(k=>k.toast),r=C(k=>k.reloadUntil),s=C(k=>k.locale),t=a.useMemo(()=>_(s),[s]),[w,G]=a.useState(""),[j,v]=a.useState(""),[B,S]=a.useState(!1),[y,c]=a.useState(null),[u,n]=a.useState(!1),m=a.useRef(null),N=a.useRef(p);N.current=p,a.useEffect(()=>{i?(G(N.current?.config.feishuAppId||""),v(N.current?.config.feishuAppSecret||""),c(null),n(!N.current?.config.feishuAppId)):(m.current?.abort(),m.current=null,S(!1))},[i]),a.useEffect(()=>()=>{m.current?.abort(),m.current=null},[]);const T=async()=>{if(!w.trim()){o(t("modal.inputAppId"),!1);return}m.current?.abort();const k=new AbortController;m.current=k,S(!0),c(null);let x=!1;try{const d=await F.validateFeishuConfig(w.trim(),j.trim(),{signal:k.signal,timeoutMs:2e4});if(!d.ok){c({ok:!1,text:"✗ "+(d.error||t("modal.validationFailed"))});return}c({ok:!0,text:"✓ "+(d.app?.displayName||d.app?.appId||w.trim())});const b=new Set((p?.setupState?.channels||[]).filter(l=>(l.ready||l.configured)&&l.channel!=="feishu").map(l=>l.channel));if(b.add("feishu"),await F.saveConfig({feishuAppId:w.trim(),feishuAppSecret:j.trim(),channels:[...b]}),!await r(l=>{const U=l.setupState?.channels?.find(W=>W.channel==="feishu");return l.config.feishuAppId===w.trim()&&l.config.feishuAppSecret===j.trim()&&!!U?.ready},{attempts:10,intervalMs:350})){c({ok:!1,text:"✗ "+t("modal.refreshStateFailed")}),o(t("modal.refreshStateFailed"),!1);return}o(t("modal.feishuSaved")),x=!0}catch(d){if(V(d))return;const b=$(d,t);c({ok:!1,text:"✗ "+b}),o(b,!1)}finally{m.current===k&&(m.current=null),S(!1),x&&h()}},E=()=>{m.current?.abort(),m.current=null,h()};return e.jsxs(O,{open:i,onClose:E,children:[e.jsx(H,{title:t("modal.configureFeishu"),onClose:E}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-lg border border-edge bg-panel-alt",children:[e.jsxs("button",{type:"button",className:"flex w-full items-center justify-between px-3 py-2 text-xs font-medium text-fg-3 hover:text-fg-2 transition-colors",onClick:()=>n(!u),children:[e.jsx("span",{children:t("modal.feishuGuideTitle")}),e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:`transition-transform ${u?"rotate-180":""}`,children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),u&&e.jsxs("div",{className:"space-y-1 border-t border-edge px-3 pb-3 pt-2 text-xs leading-relaxed text-fg-4",children:[e.jsx("p",{children:t("modal.feishuGuideStep1")}),e.jsx("p",{children:t("modal.feishuGuideStep2")}),e.jsx("p",{children:t("modal.feishuGuideStep3")}),e.jsx("p",{children:t("modal.feishuGuideStep4")}),e.jsxs("div",{className:"ml-3 mt-1",children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[11px] text-fg-5",children:t("modal.feishuGuidePerms")}),e.jsx(D,{variant:"outline",size:"sm",onClick:()=>{navigator.clipboard.writeText(ee),o(t("modal.feishuJsonCopied"))},children:t("modal.feishuCopyJson")})]}),e.jsx("pre",{className:"overflow-x-auto rounded-md border border-edge bg-inset p-2 font-mono text-[11px] leading-snug text-fg-3",children:ee}),e.jsx("p",{className:"mt-1 text-[11px] text-fg-5",children:t("modal.feishuJsonNote")})]}),e.jsx("p",{children:t("modal.feishuGuideStep5")}),e.jsx("p",{children:t("modal.feishuGuideStep6")}),e.jsx("p",{children:t("modal.feishuGuideStep7")}),e.jsx("p",{className:"mt-2 text-[11px] text-fg-5",children:t("modal.feishuGuideCardKitTip")})]})]}),e.jsxs("div",{children:[e.jsx(L,{children:t("modal.appId")}),e.jsx(P,{className:"font-mono text-xs",placeholder:t("modal.feishuPlaceholder"),value:w,onChange:k=>G(k.target.value)})]}),e.jsxs("div",{children:[e.jsx(L,{children:t("modal.appSecret")}),e.jsx(P,{type:"password",className:"font-mono text-xs",placeholder:t("modal.appSecret"),value:j,onChange:k=>v(k.target.value)})]}),y&&e.jsx("div",{className:"text-xs",style:{color:y.ok?"var(--th-ok)":"var(--th-err)"},children:y.text})]}),e.jsxs("div",{className:"flex justify-end gap-2 mt-6",children:[e.jsx(D,{variant:"ghost",onClick:E,children:t("modal.cancel")}),e.jsx(D,{variant:"primary",disabled:B,onClick:T,children:t(B?"modal.validating":"modal.validateSave")})]})]})}function ue({open:i,onClose:h}){const p=C(x=>x.state),o=C(x=>x.toast),r=C(x=>x.reloadUntil),s=C(x=>x.locale),t=a.useMemo(()=>_(s),[s]),[w,G]=a.useState(Y),[j,v]=a.useState(!1),[B,S]=a.useState(""),[y,c]=a.useState(""),[u,n]=a.useState(null),m=a.useRef(null),N=a.useRef(p);N.current=p,a.useEffect(()=>{i?(G(N.current?.config.weixinBaseUrl||Y),v(!1),S(""),c(""),n(null)):(m.current?.abort(),m.current=null,v(!1))},[i]),a.useEffect(()=>()=>{m.current?.abort(),m.current=null},[]);const T=()=>{m.current?.abort(),m.current=null,h()},E=a.useCallback(async(x,d,b)=>{for(;!x.signal.aborted;){const f=await F.waitWeixinLogin(d,b,{signal:x.signal,timeoutMs:45e3});if(!f.ok&&!f.connected)return n({ok:!1,text:"✗ "+(f.error||f.message||t("modal.validationFailed"))}),!1;if(f.qrcodeUrl&&S(f.qrcodeUrl),f.status==="scaned"?n({ok:!0,text:t("modal.weixinScanned")}):f.status==="expired"?n({ok:!0,text:t("modal.weixinQrRefreshed")}):f.connected||n({ok:!0,text:t("modal.weixinWaitingScan")}),!f.connected)continue;n({ok:!0,text:t("modal.weixinLoginSuccess")});const l=f.baseUrl||b,U=f.botToken||"",W=f.accountId||"",A=await F.validateWeixinConfig(l,U,W,{signal:x.signal,timeoutMs:12e3});if(!A.ok)return n({ok:!1,text:"✗ "+(A.error||t("modal.validationFailed"))}),!1;const z=A.normalizedBaseUrl||l,g=new Set((N.current?.setupState?.channels||[]).filter(R=>(R.ready||R.configured)&&R.channel!=="weixin").map(R=>R.channel));return g.add("weixin"),await F.saveConfig({weixinBaseUrl:z,weixinBotToken:U,weixinAccountId:W,channels:[...g]}),await r(R=>{const I=R.setupState?.channels?.find(M=>M.channel==="weixin");return R.config.weixinBaseUrl===z&&R.config.weixinBotToken===U&&R.config.weixinAccountId===W&&!!I?.ready},{attempts:12,intervalMs:350})?(o(t("modal.weixinSaved")),!0):(n({ok:!1,text:"✗ "+t("modal.refreshStateFailed")}),o(t("modal.refreshStateFailed"),!1),!1)}return!1},[r,t,o]),k=async()=>{if(!w.trim()){o(t("modal.inputWeixinBaseUrl"),!1);return}m.current?.abort();const x=new AbortController;m.current=x,v(!0),S(""),c(""),n(null);let d=!1;try{const b=await F.startWeixinLogin(w.trim(),{signal:x.signal,timeoutMs:12e3});if(!b.ok||!b.qrcodeUrl){n({ok:!1,text:"✗ "+(b.error||b.message||t("modal.validationFailed"))});return}S(b.qrcodeUrl),c(b.sessionKey),n({ok:!0,text:t("modal.weixinWaitingScan")}),d=await E(x,b.sessionKey,w.trim())}catch(b){if(V(b))return;const f=$(b,t);n({ok:!1,text:"✗ "+f}),o(f,!1)}finally{m.current===x&&(m.current=null),v(!1),d&&h()}};return e.jsxs(O,{open:i,onClose:T,children:[e.jsx(H,{title:t("modal.configureWeixin"),onClose:T}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"text-xs leading-relaxed text-fg-4",children:t("modal.weixinScanHint")}),e.jsxs("div",{children:[e.jsx(L,{children:t("modal.weixinBaseUrl")}),e.jsx(P,{className:"font-mono text-xs",value:w,onChange:x=>G(x.target.value),placeholder:Y}),e.jsx("div",{className:"mt-1 text-[11px] text-fg-5",children:t("modal.weixinDefaultBaseUrlHint")})]}),B&&e.jsxs("div",{className:"rounded-xl border border-edge bg-panel-alt p-4",children:[e.jsx("img",{src:B,alt:t("modal.weixinQrAlt"),className:"mx-auto h-56 w-56 rounded-lg bg-white p-3 object-contain"}),y&&e.jsx("div",{className:"mt-2 truncate text-center font-mono text-[10px] text-fg-5",children:y})]}),u&&e.jsx("div",{className:"text-xs",style:{color:u.ok?"var(--th-ok)":"var(--th-err)"},children:u.text})]}),e.jsxs("div",{className:"mt-6 flex justify-end gap-2",children:[e.jsx(D,{variant:"ghost",onClick:T,children:t("modal.cancel")}),e.jsx(D,{variant:"primary",disabled:j,onClick:k,children:t(j?B?"modal.validating":"modal.weixinGeneratingQr":B?"modal.weixinRetry":"modal.weixinGenerateQr")})]})]})}function X({open:i,onClose:h,channel:p,titleKey:o,fields:r,validate:s,savedToastKey:t,guideTitleKey:w,guideStepKeys:G,guideOpenWhenEmpty:j=!0,validateTimeoutMs:v=12e3}){const B=C(g=>g.state),S=C(g=>g.toast),y=C(g=>g.reloadUntil),c=C(g=>g.locale),u=a.useMemo(()=>_(c),[c]),[n,m]=a.useState({}),[N,T]=a.useState({}),[E,k]=a.useState(!1),[x,d]=a.useState(null),[b,f]=a.useState(!1),l=a.useRef(null),U=a.useRef(B);U.current=B;const W=!!(G&&G.length);a.useEffect(()=>{if(i){const g=U.current?.config||{},K={};let R=!1;for(const I of r){const M=String(g[I.key]??"").trim();K[I.key]=M,!M&&I.required!==!1&&(R=!0)}m(K),T({}),d(null),f(W&&j&&R)}else l.current?.abort(),l.current=null,k(!1)},[i,r,W,j]),a.useEffect(()=>()=>{l.current?.abort(),l.current=null},[]);const A=()=>{l.current?.abort(),l.current=null,h()},z=async()=>{const g={};for(const I of r){const M=String(n[I.key]||"").trim();if(g[I.key]=M,I.required!==!1&&!M){S(u(I.labelKey)+": "+u("modal.fieldRequired"),!1);return}}l.current?.abort();const K=new AbortController;l.current=K,k(!0),d(null);let R=!1;try{const I=await s(g,{signal:K.signal,timeoutMs:v});if(!I.ok){d({ok:!1,text:"✗ "+(I.error||u("modal.validationFailed"))});return}d({ok:!0,text:"✓ "+(I.identity||u("modal.credentialsVerified"))});const M=new Set((B?.setupState?.channels||[]).filter(q=>(q.ready||q.configured)&&q.channel!==p).map(q=>q.channel));if(M.add(p),await F.saveConfig({...g,channels:[...M]}),!await y(q=>{const te=q.config||{};for(const J of r)if(String(te[J.key]||"").trim()!==g[J.key])return!1;return!!q.setupState?.channels?.find(J=>J.channel===p)?.ready},{attempts:10,intervalMs:350})){d({ok:!1,text:"✗ "+u("modal.refreshStateFailed")}),S(u("modal.refreshStateFailed"),!1);return}S(u(t)),R=!0}catch(I){if(V(I))return;const M=$(I,u);d({ok:!1,text:"✗ "+M}),S(M,!1)}finally{l.current===K&&(l.current=null),k(!1),R&&h()}};return e.jsxs(O,{open:i,onClose:A,children:[e.jsx(H,{title:u(o),onClose:A}),e.jsxs("div",{className:"space-y-4",children:[W&&w&&e.jsxs("div",{className:"rounded-lg border border-edge bg-panel-alt",children:[e.jsxs("button",{type:"button",className:"flex w-full items-center justify-between px-3 py-2 text-xs font-medium text-fg-3 hover:text-fg-2 transition-colors",onClick:()=>f(!b),children:[e.jsx("span",{children:u(w)}),e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:`transition-transform ${b?"rotate-180":""}`,children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),b&&e.jsx("div",{className:"space-y-1 border-t border-edge px-3 pb-3 pt-2 text-xs leading-relaxed text-fg-4",children:G.map(g=>e.jsx("p",{children:u(g)},g))})]}),r.map(g=>{const K=g.key,R=!!N[K],I=g.password&&!R?"password":"text";return e.jsxs("div",{children:[e.jsxs(L,{children:[u(g.labelKey),g.required===!1&&e.jsxs(e.Fragment,{children:[" ",e.jsxs("span",{className:"text-fg-5",children:["(",u("modal.optional"),")"]})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(P,{type:I,className:"flex-1 font-mono text-xs",placeholder:g.placeholder?u(g.placeholder):"",value:n[K]||"",onChange:M=>m(Z=>({...Z,[K]:M.target.value}))}),g.password&&e.jsx(D,{variant:"ghost",size:"sm",className:"!w-[34px] !p-0",onClick:()=>T(M=>({...M,[K]:!M[K]})),children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[e.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),e.jsx("circle",{cx:"12",cy:"12",r:"3"})]})})]})]},K)}),x&&e.jsx("div",{className:"text-xs",style:{color:x.ok?"var(--th-ok)":"var(--th-err)"},children:x.text})]}),e.jsxs("div",{className:"flex justify-end gap-2 mt-6",children:[e.jsx(D,{variant:"ghost",onClick:A,children:u("modal.cancel")}),e.jsx(D,{variant:"primary",disabled:E,onClick:z,children:u(E?"modal.validating":"modal.validateSave")})]})]})}function me({open:i,onClose:h}){return e.jsx(X,{open:i,onClose:h,channel:"slack",titleKey:"modal.configureSlack",savedToastKey:"modal.slackSaved",guideTitleKey:"modal.slackGuideTitle",guideStepKeys:["modal.slackGuideStep1","modal.slackGuideStep2","modal.slackGuideStep3","modal.slackGuideStep4","modal.slackGuideStep5"],fields:[{key:"slackBotToken",labelKey:"modal.slackBotToken",password:!0,placeholder:"modal.slackBotTokenPlaceholder"},{key:"slackAppToken",labelKey:"modal.slackAppToken",password:!0,placeholder:"modal.slackAppTokenPlaceholder"}],validate:async(p,o)=>{const r=await F.validateSlackConfig(p.slackBotToken,p.slackAppToken,o),s=r.bot?.username?"@"+r.bot.username+(r.bot.team?" ("+r.bot.team+")":""):null;return{ok:r.ok,error:r.error,identity:s}}})}function xe({open:i,onClose:h}){return e.jsx(X,{open:i,onClose:h,channel:"discord",titleKey:"modal.configureDiscord",savedToastKey:"modal.discordSaved",guideTitleKey:"modal.discordGuideTitle",guideStepKeys:["modal.discordGuideStep1","modal.discordGuideStep2","modal.discordGuideStep3","modal.discordGuideStep4","modal.discordGuideStep5"],fields:[{key:"discordBotToken",labelKey:"modal.discordBotToken",password:!0,placeholder:"modal.discordBotTokenPlaceholder"}],validate:async(p,o)=>{const r=await F.validateDiscordConfig(p.discordBotToken,o),s=r.bot?.username?"@"+r.bot.username:null;return{ok:r.ok,error:r.error,identity:s}}})}function fe({open:i,onClose:h}){return e.jsx(X,{open:i,onClose:h,channel:"dingtalk",titleKey:"modal.configureDingtalk",savedToastKey:"modal.dingtalkSaved",guideTitleKey:"modal.dingtalkGuideTitle",guideStepKeys:["modal.dingtalkGuideStep1","modal.dingtalkGuideStep2","modal.dingtalkGuideStep3","modal.dingtalkGuideStep4","modal.dingtalkGuideStep5"],fields:[{key:"dingtalkClientId",labelKey:"modal.dingtalkClientId",placeholder:"modal.dingtalkClientIdPlaceholder"},{key:"dingtalkClientSecret",labelKey:"modal.dingtalkClientSecret",password:!0,placeholder:"modal.dingtalkClientSecretPlaceholder"}],validate:async(p,o)=>{const r=await F.validateDingtalkConfig(p.dingtalkClientId,p.dingtalkClientSecret,o),s=r.app?.clientId?r.app.clientId.length>12?r.app.clientId.slice(0,6)+"..."+r.app.clientId.slice(-4):r.app.clientId:null;return{ok:r.ok,error:r.error,identity:s}}})}function he({open:i,onClose:h}){return e.jsx(X,{open:i,onClose:h,channel:"wecom",titleKey:"modal.configureWeCom",savedToastKey:"modal.wecomSaved",guideTitleKey:"modal.wecomGuideTitle",guideStepKeys:["modal.wecomGuideStep1","modal.wecomGuideStep2","modal.wecomGuideStep3","modal.wecomGuideStep4","modal.wecomGuideNote"],fields:[{key:"wecomBotId",labelKey:"modal.wecomBotId",placeholder:"modal.wecomBotIdPlaceholder"},{key:"wecomBotSecret",labelKey:"modal.wecomBotSecret",password:!0,placeholder:"modal.wecomBotSecretPlaceholder"}],validate:async(p,o)=>{const r=await F.validateWecomConfig(p.wecomBotId,p.wecomBotSecret,o),s=r.bot?.botId?r.bot.botId:null;return{ok:r.ok,error:r.error,identity:s}}})}function pe({open:i,onClose:h}){const p=C(n=>n.state),o=C(n=>n.toast),r=C(n=>n.reload),s=C(n=>n.locale),t=a.useMemo(()=>_(s),[s]),w=p?.bot?.workdir||p?.runtimeWorkdir||"",[G,j]=a.useState(""),[v,B]=a.useState(!1),[S,y]=a.useState(0);a.useEffect(()=>{i&&(j(w),y(n=>n+1))},[i,w]);const c=a.useCallback(n=>{j(n)},[]),u=async()=>{const n=G.trim();if(!n){o(t("modal.selectDirFirst"),!1);return}B(!0);try{const m=await F.switchWorkdir(n);m.ok?(await r(),o(t("modal.switchedTo")+m.workdir),h()):o(m.error||t("modal.switchFailed"),!1)}catch{o(t("modal.switchFailed"),!1)}finally{B(!1)}};return e.jsx(O,{open:i,onClose:v?void 0:h,panelStyle:{width:"min(500px, calc(100vw - 2rem))",maxWidth:"min(500px, calc(100vw - 2rem))"},children:v?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 gap-4 animate-in",children:[e.jsxs("svg",{width:"32",height:"32",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",className:"animate-spin text-fg-3",style:{animationDuration:"1.2s"},children:[e.jsx("polyline",{points:"23 4 23 10 17 10"}),e.jsx("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]}),e.jsx("span",{className:"text-sm font-medium text-fg-3",children:t("modal.switching")}),e.jsx("span",{className:"text-xs text-fg-5 max-w-[280px] truncate",children:G})]}):e.jsxs(e.Fragment,{children:[e.jsx(H,{title:t("modal.switchWorkdir"),onClose:h}),e.jsx(se,{initialPath:w,onSelect:c,t},S),e.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[e.jsx(D,{variant:"ghost",onClick:h,children:t("modal.cancel")}),e.jsx(D,{variant:"primary",onClick:u,children:t("modal.selectDir")})]})]})})}function ge({open:i,onClose:h,onSaved:p}){const o=C(l=>l.toast),r=C(l=>l.locale),s=a.useMemo(()=>_(r),[r]),[t,w]=a.useState(null),[G,j]=a.useState(!1),[v,B]=a.useState(!1),[S,y]=a.useState(null);a.useEffect(()=>{i&&(j(!1),y(null),F.getBrowser().then(l=>{w(l),B(!!l.browser.enabled)}).catch(()=>w(null)))},[i]);const c=t?.browser,u=!!c?.enabled,n=!!c&&u!==v,m=c?.remoteCdpUrl||"",N=!!m&&v,T=c?.profileDir||"",E=s(N?"ext.browserRemote":"ext.profileDir"),k=N?m:T,x=!!c?.chromeInstalled&&!!c?.profileCreated,d=t?c?.enabled?N?s("ext.browserRemote"):x?s("ext.browserReady"):c?.chromeInstalled?s("ext.chromeInstalled"):s("ext.needsSetup"):s("ext.disabled"):s("status.loading"),b=t&&c?.enabled?N||x?"ok":c?.chromeInstalled?"warn":"err":"muted",f=async()=>{j(!0),y(null);let l=null;try{await F.saveConfig({browserEnabled:v}),l=await F.getBrowser(),w(l),p?.()}catch{y({ok:!1,text:"✗ "+s("ext.browserModeSaveFailed")}),o(s("ext.browserModeSaveFailed"),!1),j(!1);return}if(!v){y({ok:!0,text:"✓ "+s("ext.browserDisabledSaved")}),o(s("ext.browserDisabledSaved")),j(!1);return}if(l?.browser.remoteCdpUrl){y({ok:!0,text:"✓ "+s("ext.browserRemoteStep")}),o(s("ext.browserRemoteStep")),j(!1);return}try{const U=await F.setupBrowser();if(!U.ok){y({ok:!1,text:"✗ "+(U.error||s("ext.browserLaunchFailed"))}),o(U.error||s("ext.browserLaunchFailed"),!1);return}w(W=>W?{...W,browser:U.browser}:{browser:U.browser}),y({ok:!0,text:"✓ "+s("ext.browserEnabledLaunched")}),o(s("ext.browserEnabledLaunched")),p?.()}catch{y({ok:!1,text:"✗ "+s("ext.browserLaunchFailed")}),o(s("ext.browserLaunchFailed"),!1)}finally{j(!1)}};return e.jsxs(O,{open:i,onClose:h,children:[e.jsx(H,{title:s("ext.setupBrowser"),description:s("ext.setupBrowserDesc"),onClose:h}),e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"rounded-lg border border-edge bg-panel-alt p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(Q,{variant:b,children:d}),c&&e.jsxs(e.Fragment,{children:[e.jsx(Q,{variant:u?"accent":"muted",children:s(u?"ext.enabled":"ext.disabled")}),n&&e.jsx(Q,{variant:"warn",children:s("ext.pendingModeChange")}),c.running&&e.jsxs(Q,{variant:"accent",children:[s("ext.browserOpen"),c.pid?` · PID ${c.pid}`:""]})]})]}),e.jsxs("div",{className:"mt-3",children:[e.jsx(L,{children:E}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(P,{className:"font-mono text-xs flex-1",value:k||"—",readOnly:!0,onClick:l=>l.target.select()}),e.jsx(D,{variant:"outline",size:"sm",disabled:!k,onClick:()=>{k&&(navigator.clipboard.writeText(k),o(s("ext.step2Copied")))},children:s("ext.copyPath")})]})]}),e.jsx("div",{className:"mt-3 text-xs text-fg-5",children:s(v?"ext.profileModeDesc":"ext.browserDescDisabled")}),c?.detail&&e.jsx("div",{className:"mt-2 text-xs text-fg-5",children:c.detail}),S&&e.jsx("div",{className:"mt-3 text-xs",style:{color:S.ok?"var(--th-ok)":"var(--th-err)"},children:S.text})]}),e.jsx("div",{className:"rounded-lg border border-edge bg-panel-alt p-4",children:e.jsxs("label",{className:"flex cursor-pointer items-start gap-3",children:[e.jsx("input",{type:"checkbox",checked:v,onChange:l=>B(l.target.checked),className:"mt-0.5 h-4 w-4 rounded border border-edge bg-inset"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-fg-2 mb-1",children:s("ext.browserEnableToggle")}),e.jsx("div",{className:"text-xs text-fg-4",children:s("ext.browserEnableToggleDesc")})]})]})}),e.jsxs("div",{className:"rounded-lg border border-edge bg-panel-alt p-4",children:[e.jsx("div",{className:"text-sm font-medium text-fg-2 mb-1",children:s(v?N?"ext.browserRemoteStep":"ext.step2Title":"ext.browserDisabledStepTitle")}),e.jsx("div",{className:"text-xs text-fg-4",children:s(v?N?"ext.browserRemoteStepDesc":"ext.step2Desc":"ext.browserDisabledHint")})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 mt-6",children:[e.jsx(D,{variant:"ghost",onClick:h,children:s("modal.cancel")}),e.jsx(D,{variant:"primary",disabled:G,onClick:f,children:s(G?"ext.launching":v?N?"ext.saveBrowserRemote":"ext.enableAndLaunchBrowser":"ext.saveBrowserDisabled")})]})]})}export{ge as BrowserSetupModal,fe as DingtalkModal,xe as DiscordModal,ce as FeishuModal,me as SlackModal,de as TelegramModal,he as WeComModal,ue as WeixinModal,pe as WorkdirModal};
|
|
1
|
+
import{r as a,j as e}from"./react-vendor-C7Sl8SE7.js";import{u as C,d as _,L,I as P,m as D,a as F,t as Q}from"./index-CL5H13Cl.js";import{M as O,a as H}from"./Modal-DCwGz46r.js";import{D as se}from"./DirBrowser-DbeAWYiL.js";import"./router-DHISdpPk.js";const Y="https://ilinkai.weixin.qq.com";function V(i){return i instanceof Error&&(i.name==="AbortError"||/aborted/i.test(i.message))}function $(i,h){return i instanceof Error&&/timed out/i.test(i.message)?h("modal.requestTimeout"):h("modal.networkError")}function de({open:i,onClose:h}){const p=C(d=>d.state),o=C(d=>d.toast),r=C(d=>d.reloadUntil),s=C(d=>d.locale),t=a.useMemo(()=>_(s),[s]),[w,G]=a.useState(""),[j,v]=a.useState(""),[B,S]=a.useState(!1),[y,c]=a.useState(!1),[u,n]=a.useState(null),[m,N]=a.useState(!1),T=a.useRef(null),E=a.useRef(p);E.current=p,a.useEffect(()=>{i?(G(E.current?.config.telegramBotToken||""),v(E.current?.config.telegramAllowedChatIds||""),S(!1),n(null),N(!E.current?.config.telegramBotToken)):(T.current?.abort(),T.current=null,c(!1))},[i]),a.useEffect(()=>()=>{T.current?.abort(),T.current=null},[]);const k=async()=>{if(!w.trim()){o(t("modal.inputToken"),!1);return}T.current?.abort();const d=new AbortController;T.current=d,c(!0),n(null);let b=!1;try{const f=await F.validateTelegramConfig(w.trim(),j.trim(),{signal:d.signal,timeoutMs:12e3});if(!f.ok){n({ok:!1,text:"✗ "+(f.error||t("modal.validationFailed"))});return}const l=f.normalizedAllowedChatIds??j.trim();n({ok:!0,text:"✓ @"+(f.bot?.username||"bot")+(f.bot?.displayName?" ("+f.bot.displayName+")":"")});const U=new Set((p?.setupState?.channels||[]).filter(A=>(A.ready||A.configured)&&A.channel!=="telegram").map(A=>A.channel));if(U.add("telegram"),await F.saveConfig({telegramBotToken:w.trim(),telegramAllowedChatIds:l,channels:[...U]}),!await r(A=>{const z=A.setupState?.channels?.find(g=>g.channel==="telegram");return A.config.telegramBotToken===w.trim()&&(A.config.telegramAllowedChatIds||"")===l&&!!z?.ready},{attempts:10,intervalMs:350})){n({ok:!1,text:"✗ "+t("modal.refreshStateFailed")}),o(t("modal.refreshStateFailed"),!1);return}o(t("modal.tgSaved")),b=!0}catch(f){if(V(f))return;const l=$(f,t);n({ok:!1,text:"✗ "+l}),o(l,!1)}finally{T.current===d&&(T.current=null),c(!1),b&&h()}},x=()=>{T.current?.abort(),T.current=null,h()};return e.jsxs(O,{open:i,onClose:x,children:[e.jsx(H,{title:t("modal.configureTelegram"),onClose:x}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-lg border border-edge bg-panel-alt",children:[e.jsxs("button",{type:"button",className:"flex w-full items-center justify-between px-3 py-2 text-xs font-medium text-fg-3 hover:text-fg-2 transition-colors",onClick:()=>N(!m),children:[e.jsx("span",{children:t("modal.tgGuideTitle")}),e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:`transition-transform ${m?"rotate-180":""}`,children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),m&&e.jsxs("div",{className:"space-y-1 border-t border-edge px-3 pb-3 pt-2 text-xs leading-relaxed text-fg-4",children:[e.jsx("p",{children:t("modal.tgGuideStep1")}),e.jsx("p",{children:t("modal.tgGuideStep2")}),e.jsx("p",{children:t("modal.tgGuideStep3")}),e.jsx("p",{children:t("modal.tgGuideStep4")}),e.jsx("p",{className:"mt-2 text-[11px] text-fg-5",children:t("modal.tgGuideIdTip")})]})]}),e.jsxs("div",{children:[e.jsx(L,{children:t("modal.botToken")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(P,{type:B?"text":"password",className:"flex-1 font-mono text-xs",placeholder:t("modal.pasteToken"),value:w,onChange:d=>G(d.target.value)}),e.jsx(D,{variant:"ghost",size:"sm",className:"!w-[34px] !p-0",onClick:()=>S(!B),children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[e.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),e.jsx("circle",{cx:"12",cy:"12",r:"3"})]})})]})]}),u&&e.jsx("div",{className:"text-xs",style:{color:u.ok?"var(--th-ok)":"var(--th-err)"},children:u.text}),e.jsxs("div",{children:[e.jsxs(L,{children:[t("modal.allowedIds")," ",e.jsxs("span",{className:"text-fg-5",children:["(",t("modal.optional"),")"]})]}),e.jsx(P,{className:"font-mono text-xs",placeholder:t("modal.commaSep"),value:j,onChange:d=>v(d.target.value)})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 mt-6",children:[e.jsx(D,{variant:"ghost",onClick:x,children:t("modal.cancel")}),e.jsx(D,{variant:"primary",disabled:y,onClick:k,children:t(y?"modal.validating":"modal.validateSave")})]})]})}const ee=JSON.stringify({scopes:{tenant:["im:message","im:message:send_as_bot","im:message.p2p_msg:readonly","im:message.group_at_msg:readonly","im:resource"],user:[]}},null,2);function ce({open:i,onClose:h}){const p=C(k=>k.state),o=C(k=>k.toast),r=C(k=>k.reloadUntil),s=C(k=>k.locale),t=a.useMemo(()=>_(s),[s]),[w,G]=a.useState(""),[j,v]=a.useState(""),[B,S]=a.useState(!1),[y,c]=a.useState(null),[u,n]=a.useState(!1),m=a.useRef(null),N=a.useRef(p);N.current=p,a.useEffect(()=>{i?(G(N.current?.config.feishuAppId||""),v(N.current?.config.feishuAppSecret||""),c(null),n(!N.current?.config.feishuAppId)):(m.current?.abort(),m.current=null,S(!1))},[i]),a.useEffect(()=>()=>{m.current?.abort(),m.current=null},[]);const T=async()=>{if(!w.trim()){o(t("modal.inputAppId"),!1);return}m.current?.abort();const k=new AbortController;m.current=k,S(!0),c(null);let x=!1;try{const d=await F.validateFeishuConfig(w.trim(),j.trim(),{signal:k.signal,timeoutMs:2e4});if(!d.ok){c({ok:!1,text:"✗ "+(d.error||t("modal.validationFailed"))});return}c({ok:!0,text:"✓ "+(d.app?.displayName||d.app?.appId||w.trim())});const b=new Set((p?.setupState?.channels||[]).filter(l=>(l.ready||l.configured)&&l.channel!=="feishu").map(l=>l.channel));if(b.add("feishu"),await F.saveConfig({feishuAppId:w.trim(),feishuAppSecret:j.trim(),channels:[...b]}),!await r(l=>{const U=l.setupState?.channels?.find(W=>W.channel==="feishu");return l.config.feishuAppId===w.trim()&&l.config.feishuAppSecret===j.trim()&&!!U?.ready},{attempts:10,intervalMs:350})){c({ok:!1,text:"✗ "+t("modal.refreshStateFailed")}),o(t("modal.refreshStateFailed"),!1);return}o(t("modal.feishuSaved")),x=!0}catch(d){if(V(d))return;const b=$(d,t);c({ok:!1,text:"✗ "+b}),o(b,!1)}finally{m.current===k&&(m.current=null),S(!1),x&&h()}},E=()=>{m.current?.abort(),m.current=null,h()};return e.jsxs(O,{open:i,onClose:E,children:[e.jsx(H,{title:t("modal.configureFeishu"),onClose:E}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-lg border border-edge bg-panel-alt",children:[e.jsxs("button",{type:"button",className:"flex w-full items-center justify-between px-3 py-2 text-xs font-medium text-fg-3 hover:text-fg-2 transition-colors",onClick:()=>n(!u),children:[e.jsx("span",{children:t("modal.feishuGuideTitle")}),e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:`transition-transform ${u?"rotate-180":""}`,children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),u&&e.jsxs("div",{className:"space-y-1 border-t border-edge px-3 pb-3 pt-2 text-xs leading-relaxed text-fg-4",children:[e.jsx("p",{children:t("modal.feishuGuideStep1")}),e.jsx("p",{children:t("modal.feishuGuideStep2")}),e.jsx("p",{children:t("modal.feishuGuideStep3")}),e.jsx("p",{children:t("modal.feishuGuideStep4")}),e.jsxs("div",{className:"ml-3 mt-1",children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[11px] text-fg-5",children:t("modal.feishuGuidePerms")}),e.jsx(D,{variant:"outline",size:"sm",onClick:()=>{navigator.clipboard.writeText(ee),o(t("modal.feishuJsonCopied"))},children:t("modal.feishuCopyJson")})]}),e.jsx("pre",{className:"overflow-x-auto rounded-md border border-edge bg-inset p-2 font-mono text-[11px] leading-snug text-fg-3",children:ee}),e.jsx("p",{className:"mt-1 text-[11px] text-fg-5",children:t("modal.feishuJsonNote")})]}),e.jsx("p",{children:t("modal.feishuGuideStep5")}),e.jsx("p",{children:t("modal.feishuGuideStep6")}),e.jsx("p",{children:t("modal.feishuGuideStep7")}),e.jsx("p",{className:"mt-2 text-[11px] text-fg-5",children:t("modal.feishuGuideCardKitTip")})]})]}),e.jsxs("div",{children:[e.jsx(L,{children:t("modal.appId")}),e.jsx(P,{className:"font-mono text-xs",placeholder:t("modal.feishuPlaceholder"),value:w,onChange:k=>G(k.target.value)})]}),e.jsxs("div",{children:[e.jsx(L,{children:t("modal.appSecret")}),e.jsx(P,{type:"password",className:"font-mono text-xs",placeholder:t("modal.appSecret"),value:j,onChange:k=>v(k.target.value)})]}),y&&e.jsx("div",{className:"text-xs",style:{color:y.ok?"var(--th-ok)":"var(--th-err)"},children:y.text})]}),e.jsxs("div",{className:"flex justify-end gap-2 mt-6",children:[e.jsx(D,{variant:"ghost",onClick:E,children:t("modal.cancel")}),e.jsx(D,{variant:"primary",disabled:B,onClick:T,children:t(B?"modal.validating":"modal.validateSave")})]})]})}function ue({open:i,onClose:h}){const p=C(x=>x.state),o=C(x=>x.toast),r=C(x=>x.reloadUntil),s=C(x=>x.locale),t=a.useMemo(()=>_(s),[s]),[w,G]=a.useState(Y),[j,v]=a.useState(!1),[B,S]=a.useState(""),[y,c]=a.useState(""),[u,n]=a.useState(null),m=a.useRef(null),N=a.useRef(p);N.current=p,a.useEffect(()=>{i?(G(N.current?.config.weixinBaseUrl||Y),v(!1),S(""),c(""),n(null)):(m.current?.abort(),m.current=null,v(!1))},[i]),a.useEffect(()=>()=>{m.current?.abort(),m.current=null},[]);const T=()=>{m.current?.abort(),m.current=null,h()},E=a.useCallback(async(x,d,b)=>{for(;!x.signal.aborted;){const f=await F.waitWeixinLogin(d,b,{signal:x.signal,timeoutMs:45e3});if(!f.ok&&!f.connected)return n({ok:!1,text:"✗ "+(f.error||f.message||t("modal.validationFailed"))}),!1;if(f.qrcodeUrl&&S(f.qrcodeUrl),f.status==="scaned"?n({ok:!0,text:t("modal.weixinScanned")}):f.status==="expired"?n({ok:!0,text:t("modal.weixinQrRefreshed")}):f.connected||n({ok:!0,text:t("modal.weixinWaitingScan")}),!f.connected)continue;n({ok:!0,text:t("modal.weixinLoginSuccess")});const l=f.baseUrl||b,U=f.botToken||"",W=f.accountId||"",A=await F.validateWeixinConfig(l,U,W,{signal:x.signal,timeoutMs:12e3});if(!A.ok)return n({ok:!1,text:"✗ "+(A.error||t("modal.validationFailed"))}),!1;const z=A.normalizedBaseUrl||l,g=new Set((N.current?.setupState?.channels||[]).filter(R=>(R.ready||R.configured)&&R.channel!=="weixin").map(R=>R.channel));return g.add("weixin"),await F.saveConfig({weixinBaseUrl:z,weixinBotToken:U,weixinAccountId:W,channels:[...g]}),await r(R=>{const I=R.setupState?.channels?.find(M=>M.channel==="weixin");return R.config.weixinBaseUrl===z&&R.config.weixinBotToken===U&&R.config.weixinAccountId===W&&!!I?.ready},{attempts:12,intervalMs:350})?(o(t("modal.weixinSaved")),!0):(n({ok:!1,text:"✗ "+t("modal.refreshStateFailed")}),o(t("modal.refreshStateFailed"),!1),!1)}return!1},[r,t,o]),k=async()=>{if(!w.trim()){o(t("modal.inputWeixinBaseUrl"),!1);return}m.current?.abort();const x=new AbortController;m.current=x,v(!0),S(""),c(""),n(null);let d=!1;try{const b=await F.startWeixinLogin(w.trim(),{signal:x.signal,timeoutMs:12e3});if(!b.ok||!b.qrcodeUrl){n({ok:!1,text:"✗ "+(b.error||b.message||t("modal.validationFailed"))});return}S(b.qrcodeUrl),c(b.sessionKey),n({ok:!0,text:t("modal.weixinWaitingScan")}),d=await E(x,b.sessionKey,w.trim())}catch(b){if(V(b))return;const f=$(b,t);n({ok:!1,text:"✗ "+f}),o(f,!1)}finally{m.current===x&&(m.current=null),v(!1),d&&h()}};return e.jsxs(O,{open:i,onClose:T,children:[e.jsx(H,{title:t("modal.configureWeixin"),onClose:T}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"text-xs leading-relaxed text-fg-4",children:t("modal.weixinScanHint")}),e.jsxs("div",{children:[e.jsx(L,{children:t("modal.weixinBaseUrl")}),e.jsx(P,{className:"font-mono text-xs",value:w,onChange:x=>G(x.target.value),placeholder:Y}),e.jsx("div",{className:"mt-1 text-[11px] text-fg-5",children:t("modal.weixinDefaultBaseUrlHint")})]}),B&&e.jsxs("div",{className:"rounded-xl border border-edge bg-panel-alt p-4",children:[e.jsx("img",{src:B,alt:t("modal.weixinQrAlt"),className:"mx-auto h-56 w-56 rounded-lg bg-white p-3 object-contain"}),y&&e.jsx("div",{className:"mt-2 truncate text-center font-mono text-[10px] text-fg-5",children:y})]}),u&&e.jsx("div",{className:"text-xs",style:{color:u.ok?"var(--th-ok)":"var(--th-err)"},children:u.text})]}),e.jsxs("div",{className:"mt-6 flex justify-end gap-2",children:[e.jsx(D,{variant:"ghost",onClick:T,children:t("modal.cancel")}),e.jsx(D,{variant:"primary",disabled:j,onClick:k,children:t(j?B?"modal.validating":"modal.weixinGeneratingQr":B?"modal.weixinRetry":"modal.weixinGenerateQr")})]})]})}function X({open:i,onClose:h,channel:p,titleKey:o,fields:r,validate:s,savedToastKey:t,guideTitleKey:w,guideStepKeys:G,guideOpenWhenEmpty:j=!0,validateTimeoutMs:v=12e3}){const B=C(g=>g.state),S=C(g=>g.toast),y=C(g=>g.reloadUntil),c=C(g=>g.locale),u=a.useMemo(()=>_(c),[c]),[n,m]=a.useState({}),[N,T]=a.useState({}),[E,k]=a.useState(!1),[x,d]=a.useState(null),[b,f]=a.useState(!1),l=a.useRef(null),U=a.useRef(B);U.current=B;const W=!!(G&&G.length);a.useEffect(()=>{if(i){const g=U.current?.config||{},K={};let R=!1;for(const I of r){const M=String(g[I.key]??"").trim();K[I.key]=M,!M&&I.required!==!1&&(R=!0)}m(K),T({}),d(null),f(W&&j&&R)}else l.current?.abort(),l.current=null,k(!1)},[i,r,W,j]),a.useEffect(()=>()=>{l.current?.abort(),l.current=null},[]);const A=()=>{l.current?.abort(),l.current=null,h()},z=async()=>{const g={};for(const I of r){const M=String(n[I.key]||"").trim();if(g[I.key]=M,I.required!==!1&&!M){S(u(I.labelKey)+": "+u("modal.fieldRequired"),!1);return}}l.current?.abort();const K=new AbortController;l.current=K,k(!0),d(null);let R=!1;try{const I=await s(g,{signal:K.signal,timeoutMs:v});if(!I.ok){d({ok:!1,text:"✗ "+(I.error||u("modal.validationFailed"))});return}d({ok:!0,text:"✓ "+(I.identity||u("modal.credentialsVerified"))});const M=new Set((B?.setupState?.channels||[]).filter(q=>(q.ready||q.configured)&&q.channel!==p).map(q=>q.channel));if(M.add(p),await F.saveConfig({...g,channels:[...M]}),!await y(q=>{const te=q.config||{};for(const J of r)if(String(te[J.key]||"").trim()!==g[J.key])return!1;return!!q.setupState?.channels?.find(J=>J.channel===p)?.ready},{attempts:10,intervalMs:350})){d({ok:!1,text:"✗ "+u("modal.refreshStateFailed")}),S(u("modal.refreshStateFailed"),!1);return}S(u(t)),R=!0}catch(I){if(V(I))return;const M=$(I,u);d({ok:!1,text:"✗ "+M}),S(M,!1)}finally{l.current===K&&(l.current=null),k(!1),R&&h()}};return e.jsxs(O,{open:i,onClose:A,children:[e.jsx(H,{title:u(o),onClose:A}),e.jsxs("div",{className:"space-y-4",children:[W&&w&&e.jsxs("div",{className:"rounded-lg border border-edge bg-panel-alt",children:[e.jsxs("button",{type:"button",className:"flex w-full items-center justify-between px-3 py-2 text-xs font-medium text-fg-3 hover:text-fg-2 transition-colors",onClick:()=>f(!b),children:[e.jsx("span",{children:u(w)}),e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:`transition-transform ${b?"rotate-180":""}`,children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),b&&e.jsx("div",{className:"space-y-1 border-t border-edge px-3 pb-3 pt-2 text-xs leading-relaxed text-fg-4",children:G.map(g=>e.jsx("p",{children:u(g)},g))})]}),r.map(g=>{const K=g.key,R=!!N[K],I=g.password&&!R?"password":"text";return e.jsxs("div",{children:[e.jsxs(L,{children:[u(g.labelKey),g.required===!1&&e.jsxs(e.Fragment,{children:[" ",e.jsxs("span",{className:"text-fg-5",children:["(",u("modal.optional"),")"]})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(P,{type:I,className:"flex-1 font-mono text-xs",placeholder:g.placeholder?u(g.placeholder):"",value:n[K]||"",onChange:M=>m(Z=>({...Z,[K]:M.target.value}))}),g.password&&e.jsx(D,{variant:"ghost",size:"sm",className:"!w-[34px] !p-0",onClick:()=>T(M=>({...M,[K]:!M[K]})),children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[e.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),e.jsx("circle",{cx:"12",cy:"12",r:"3"})]})})]})]},K)}),x&&e.jsx("div",{className:"text-xs",style:{color:x.ok?"var(--th-ok)":"var(--th-err)"},children:x.text})]}),e.jsxs("div",{className:"flex justify-end gap-2 mt-6",children:[e.jsx(D,{variant:"ghost",onClick:A,children:u("modal.cancel")}),e.jsx(D,{variant:"primary",disabled:E,onClick:z,children:u(E?"modal.validating":"modal.validateSave")})]})]})}function me({open:i,onClose:h}){return e.jsx(X,{open:i,onClose:h,channel:"slack",titleKey:"modal.configureSlack",savedToastKey:"modal.slackSaved",guideTitleKey:"modal.slackGuideTitle",guideStepKeys:["modal.slackGuideStep1","modal.slackGuideStep2","modal.slackGuideStep3","modal.slackGuideStep4","modal.slackGuideStep5"],fields:[{key:"slackBotToken",labelKey:"modal.slackBotToken",password:!0,placeholder:"modal.slackBotTokenPlaceholder"},{key:"slackAppToken",labelKey:"modal.slackAppToken",password:!0,placeholder:"modal.slackAppTokenPlaceholder"}],validate:async(p,o)=>{const r=await F.validateSlackConfig(p.slackBotToken,p.slackAppToken,o),s=r.bot?.username?"@"+r.bot.username+(r.bot.team?" ("+r.bot.team+")":""):null;return{ok:r.ok,error:r.error,identity:s}}})}function xe({open:i,onClose:h}){return e.jsx(X,{open:i,onClose:h,channel:"discord",titleKey:"modal.configureDiscord",savedToastKey:"modal.discordSaved",guideTitleKey:"modal.discordGuideTitle",guideStepKeys:["modal.discordGuideStep1","modal.discordGuideStep2","modal.discordGuideStep3","modal.discordGuideStep4","modal.discordGuideStep5"],fields:[{key:"discordBotToken",labelKey:"modal.discordBotToken",password:!0,placeholder:"modal.discordBotTokenPlaceholder"}],validate:async(p,o)=>{const r=await F.validateDiscordConfig(p.discordBotToken,o),s=r.bot?.username?"@"+r.bot.username:null;return{ok:r.ok,error:r.error,identity:s}}})}function fe({open:i,onClose:h}){return e.jsx(X,{open:i,onClose:h,channel:"dingtalk",titleKey:"modal.configureDingtalk",savedToastKey:"modal.dingtalkSaved",guideTitleKey:"modal.dingtalkGuideTitle",guideStepKeys:["modal.dingtalkGuideStep1","modal.dingtalkGuideStep2","modal.dingtalkGuideStep3","modal.dingtalkGuideStep4","modal.dingtalkGuideStep5"],fields:[{key:"dingtalkClientId",labelKey:"modal.dingtalkClientId",placeholder:"modal.dingtalkClientIdPlaceholder"},{key:"dingtalkClientSecret",labelKey:"modal.dingtalkClientSecret",password:!0,placeholder:"modal.dingtalkClientSecretPlaceholder"}],validate:async(p,o)=>{const r=await F.validateDingtalkConfig(p.dingtalkClientId,p.dingtalkClientSecret,o),s=r.app?.clientId?r.app.clientId.length>12?r.app.clientId.slice(0,6)+"..."+r.app.clientId.slice(-4):r.app.clientId:null;return{ok:r.ok,error:r.error,identity:s}}})}function he({open:i,onClose:h}){return e.jsx(X,{open:i,onClose:h,channel:"wecom",titleKey:"modal.configureWeCom",savedToastKey:"modal.wecomSaved",guideTitleKey:"modal.wecomGuideTitle",guideStepKeys:["modal.wecomGuideStep1","modal.wecomGuideStep2","modal.wecomGuideStep3","modal.wecomGuideStep4","modal.wecomGuideNote"],fields:[{key:"wecomBotId",labelKey:"modal.wecomBotId",placeholder:"modal.wecomBotIdPlaceholder"},{key:"wecomBotSecret",labelKey:"modal.wecomBotSecret",password:!0,placeholder:"modal.wecomBotSecretPlaceholder"}],validate:async(p,o)=>{const r=await F.validateWecomConfig(p.wecomBotId,p.wecomBotSecret,o),s=r.bot?.botId?r.bot.botId:null;return{ok:r.ok,error:r.error,identity:s}}})}function pe({open:i,onClose:h}){const p=C(n=>n.state),o=C(n=>n.toast),r=C(n=>n.reload),s=C(n=>n.locale),t=a.useMemo(()=>_(s),[s]),w=p?.bot?.workdir||p?.runtimeWorkdir||"",[G,j]=a.useState(""),[v,B]=a.useState(!1),[S,y]=a.useState(0);a.useEffect(()=>{i&&(j(w),y(n=>n+1))},[i,w]);const c=a.useCallback(n=>{j(n)},[]),u=async()=>{const n=G.trim();if(!n){o(t("modal.selectDirFirst"),!1);return}B(!0);try{const m=await F.switchWorkdir(n);m.ok?(await r(),o(t("modal.switchedTo")+m.workdir),h()):o(m.error||t("modal.switchFailed"),!1)}catch{o(t("modal.switchFailed"),!1)}finally{B(!1)}};return e.jsx(O,{open:i,onClose:v?void 0:h,panelStyle:{width:"min(500px, calc(100vw - 2rem))",maxWidth:"min(500px, calc(100vw - 2rem))"},children:v?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 gap-4 animate-in",children:[e.jsxs("svg",{width:"32",height:"32",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",className:"animate-spin text-fg-3",style:{animationDuration:"1.2s"},children:[e.jsx("polyline",{points:"23 4 23 10 17 10"}),e.jsx("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]}),e.jsx("span",{className:"text-sm font-medium text-fg-3",children:t("modal.switching")}),e.jsx("span",{className:"text-xs text-fg-5 max-w-[280px] truncate",children:G})]}):e.jsxs(e.Fragment,{children:[e.jsx(H,{title:t("modal.switchWorkdir"),onClose:h}),e.jsx(se,{initialPath:w,onSelect:c,t},S),e.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[e.jsx(D,{variant:"ghost",onClick:h,children:t("modal.cancel")}),e.jsx(D,{variant:"primary",onClick:u,children:t("modal.selectDir")})]})]})})}function ge({open:i,onClose:h,onSaved:p}){const o=C(l=>l.toast),r=C(l=>l.locale),s=a.useMemo(()=>_(r),[r]),[t,w]=a.useState(null),[G,j]=a.useState(!1),[v,B]=a.useState(!1),[S,y]=a.useState(null);a.useEffect(()=>{i&&(j(!1),y(null),F.getBrowser().then(l=>{w(l),B(!!l.browser.enabled)}).catch(()=>w(null)))},[i]);const c=t?.browser,u=!!c?.enabled,n=!!c&&u!==v,m=c?.remoteCdpUrl||"",N=!!m&&v,T=c?.profileDir||"",E=s(N?"ext.browserRemote":"ext.profileDir"),k=N?m:T,x=!!c?.chromeInstalled&&!!c?.profileCreated,d=t?c?.enabled?N?s("ext.browserRemote"):x?s("ext.browserReady"):c?.chromeInstalled?s("ext.chromeInstalled"):s("ext.needsSetup"):s("ext.disabled"):s("status.loading"),b=t&&c?.enabled?N||x?"ok":c?.chromeInstalled?"warn":"err":"muted",f=async()=>{j(!0),y(null);let l=null;try{await F.saveConfig({browserEnabled:v}),l=await F.getBrowser(),w(l),p?.()}catch{y({ok:!1,text:"✗ "+s("ext.browserModeSaveFailed")}),o(s("ext.browserModeSaveFailed"),!1),j(!1);return}if(!v){y({ok:!0,text:"✓ "+s("ext.browserDisabledSaved")}),o(s("ext.browserDisabledSaved")),j(!1);return}if(l?.browser.remoteCdpUrl){y({ok:!0,text:"✓ "+s("ext.browserRemoteStep")}),o(s("ext.browserRemoteStep")),j(!1);return}try{const U=await F.setupBrowser();if(!U.ok){y({ok:!1,text:"✗ "+(U.error||s("ext.browserLaunchFailed"))}),o(U.error||s("ext.browserLaunchFailed"),!1);return}w(W=>W?{...W,browser:U.browser}:{browser:U.browser}),y({ok:!0,text:"✓ "+s("ext.browserEnabledLaunched")}),o(s("ext.browserEnabledLaunched")),p?.()}catch{y({ok:!1,text:"✗ "+s("ext.browserLaunchFailed")}),o(s("ext.browserLaunchFailed"),!1)}finally{j(!1)}};return e.jsxs(O,{open:i,onClose:h,children:[e.jsx(H,{title:s("ext.setupBrowser"),description:s("ext.setupBrowserDesc"),onClose:h}),e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"rounded-lg border border-edge bg-panel-alt p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(Q,{variant:b,children:d}),c&&e.jsxs(e.Fragment,{children:[e.jsx(Q,{variant:u?"accent":"muted",children:s(u?"ext.enabled":"ext.disabled")}),n&&e.jsx(Q,{variant:"warn",children:s("ext.pendingModeChange")}),c.running&&e.jsxs(Q,{variant:"accent",children:[s("ext.browserOpen"),c.pid?` · PID ${c.pid}`:""]})]})]}),e.jsxs("div",{className:"mt-3",children:[e.jsx(L,{children:E}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(P,{className:"font-mono text-xs flex-1",value:k||"—",readOnly:!0,onClick:l=>l.target.select()}),e.jsx(D,{variant:"outline",size:"sm",disabled:!k,onClick:()=>{k&&(navigator.clipboard.writeText(k),o(s("ext.step2Copied")))},children:s("ext.copyPath")})]})]}),e.jsx("div",{className:"mt-3 text-xs text-fg-5",children:s(v?"ext.profileModeDesc":"ext.browserDescDisabled")}),c?.detail&&e.jsx("div",{className:"mt-2 text-xs text-fg-5",children:c.detail}),S&&e.jsx("div",{className:"mt-3 text-xs",style:{color:S.ok?"var(--th-ok)":"var(--th-err)"},children:S.text})]}),e.jsx("div",{className:"rounded-lg border border-edge bg-panel-alt p-4",children:e.jsxs("label",{className:"flex cursor-pointer items-start gap-3",children:[e.jsx("input",{type:"checkbox",checked:v,onChange:l=>B(l.target.checked),className:"mt-0.5 h-4 w-4 rounded border border-edge bg-inset"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-fg-2 mb-1",children:s("ext.browserEnableToggle")}),e.jsx("div",{className:"text-xs text-fg-4",children:s("ext.browserEnableToggleDesc")})]})]})}),e.jsxs("div",{className:"rounded-lg border border-edge bg-panel-alt p-4",children:[e.jsx("div",{className:"text-sm font-medium text-fg-2 mb-1",children:s(v?N?"ext.browserRemoteStep":"ext.step2Title":"ext.browserDisabledStepTitle")}),e.jsx("div",{className:"text-xs text-fg-4",children:s(v?N?"ext.browserRemoteStepDesc":"ext.step2Desc":"ext.browserDisabledHint")})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 mt-6",children:[e.jsx(D,{variant:"ghost",onClick:h,children:s("modal.cancel")}),e.jsx(D,{variant:"primary",disabled:G,onClick:f,children:s(G?"ext.launching":v?N?"ext.saveBrowserRemote":"ext.enableAndLaunchBrowser":"ext.saveBrowserDisabled")})]})]})}export{ge as BrowserSetupModal,fe as DingtalkModal,xe as DiscordModal,ce as FeishuModal,me as SlackModal,de as TelegramModal,he as WeComModal,ue as WeixinModal,pe as WorkdirModal};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as a,j as e,a as H}from"./react-vendor-C7Sl8SE7.js";import{c}from"./index-
|
|
1
|
+
import{r as a,j as e,a as H}from"./react-vendor-C7Sl8SE7.js";import{c}from"./index-CL5H13Cl.js";function y(u,h){return!!(u&&h instanceof Node&&u.contains(h))}function M({value:u,options:h,onChange:j,className:g,placeholder:l="—",disabled:x=!1,readOnly:f=!1}){const p=h.find(t=>t.value===u),w=f||h.length<=1,[i,m]=a.useState(!1),[o,d]=a.useState(null),n=a.useRef(null),_=a.useRef(null);if(a.useEffect(()=>{if(!i)return;const t=s=>{y(n.current,s.target)||y(_.current,s.target)||m(!1)},r=s=>{s.key==="Escape"&&(s.stopPropagation(),m(!1))};return document.addEventListener("mousedown",t),document.addEventListener("keydown",r,!0),()=>{document.removeEventListener("mousedown",t),document.removeEventListener("keydown",r,!0)}},[i]),a.useLayoutEffect(()=>{if(!i)return;const t=()=>{const r=n.current;if(!r)return;const s=r.getBoundingClientRect(),k=window.innerHeight-s.bottom-12,E=s.top-12,N=k<220&&E>k,L=Math.max(140,Math.min(260,N?E:k));d({left:s.left,top:N?Math.max(12,s.top-L-8):s.bottom+8,width:s.width,maxHeight:L})};return t(),window.addEventListener("resize",t),window.addEventListener("scroll",t,!0),()=>{window.removeEventListener("resize",t),window.removeEventListener("scroll",t,!0)}},[i]),w)return e.jsx("div",{className:c("flex h-9 w-full items-center rounded-md border border-edge bg-panel-alt px-3 text-[13px] text-fg-5 shadow-none",x&&"cursor-not-allowed",g),children:e.jsx("span",{className:c("truncate",!p&&"text-fg-6"),children:p?.label||l})});const b=t=>{x||(j(t),m(!1))},v=i&&o?H.createPortal(e.jsx("div",{ref:_,role:"listbox",className:"fixed z-[220] overflow-hidden rounded-xl border border-edge-h bg-[var(--th-dropdown)] p-1.5 shadow-[0_24px_64px_rgba(2,6,23,0.22)] backdrop-blur-xl",style:{left:o.left,top:o.top,width:o.width},children:e.jsx("div",{className:"overflow-y-auto",style:{maxHeight:o.maxHeight},children:h.map(t=>{const r=t.value===u;return e.jsxs("button",{type:"button",role:"option","aria-selected":r,onClick:()=>b(t.value),className:c("flex w-full items-start gap-2 rounded-lg px-3 py-2 text-left text-[13px] transition-colors duration-200",r?"bg-panel text-fg shadow-[inset_0_1px_0_rgba(255,255,255,0.03)]":"text-fg-3 hover:bg-panel-alt hover:text-fg-2"),children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-baseline gap-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate",children:t.label}),t.meta&&e.jsx("span",{className:"shrink-0 font-mono text-[10px] text-fg-5",children:t.meta})]}),t.description&&e.jsx("div",{className:"mt-0.5 truncate font-mono text-[10px] leading-relaxed text-fg-5",children:t.description})]}),r&&e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"mt-0.5 shrink-0 text-fg-4",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})})]},t.value)})})}),document.body):null;return e.jsxs("div",{ref:n,className:c("relative",g),children:[e.jsxs("button",{type:"button",disabled:x,"aria-haspopup":"listbox","aria-expanded":i,onClick:()=>m(t=>!t),className:c("flex h-9 w-full items-center rounded-md border border-control-border bg-control px-3 pr-8 text-left text-[13px] text-fg shadow-sm","transition-[border-color,box-shadow,background] duration-200 outline-none","hover:border-control-border-h hover:bg-control-h","focus-visible:border-control-border-h focus-visible:shadow-[0_0_0_4px_var(--th-glow-a)]","disabled:cursor-not-allowed disabled:bg-panel-alt disabled:border-edge disabled:text-fg-5","disabled:shadow-none disabled:hover:border-edge disabled:hover:bg-panel-alt",i&&"border-control-border-h bg-control-h shadow-[0_0_0_4px_var(--th-glow-a)]"),children:[e.jsx("span",{className:c("min-w-0 flex-1 truncate",!p&&"text-fg-5"),children:p?.label||l}),e.jsx("span",{className:c("pointer-events-none absolute inset-y-0 right-3 flex items-center text-fg-4 transition-transform duration-200",i&&"rotate-180"),children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})})]}),v]})}function P({value:u,options:h,onChange:j,renderIcon:g}){const[l,x]=a.useState(!1),[f,p]=a.useState(null),w=a.useRef(null),i=a.useRef(null);a.useEffect(()=>{if(!l)return;const o=n=>{y(w.current,n.target)||y(i.current,n.target)||x(!1)},d=n=>{n.key==="Escape"&&(n.stopPropagation(),x(!1))};return document.addEventListener("mousedown",o),document.addEventListener("keydown",d,!0),()=>{document.removeEventListener("mousedown",o),document.removeEventListener("keydown",d,!0)}},[l]),a.useLayoutEffect(()=>{if(!l)return;const o=()=>{const d=w.current;if(!d)return;const n=d.getBoundingClientRect(),b=window.innerHeight-n.bottom-12,v=n.top-12,t=b<220&&v>b,r=Math.max(140,Math.min(260,t?v:b));p({left:n.left,top:t?Math.max(12,n.top-r-8):n.bottom+8,width:Math.max(n.width,160),maxHeight:r})};return o(),window.addEventListener("resize",o),window.addEventListener("scroll",o,!0),()=>{window.removeEventListener("resize",o),window.removeEventListener("scroll",o,!0)}},[l]);const m=l&&f?H.createPortal(e.jsx("div",{ref:i,role:"listbox",className:"fixed z-[220] overflow-hidden rounded-xl border border-edge-h bg-[var(--th-dropdown)] p-1.5 shadow-[0_24px_64px_rgba(2,6,23,0.22)] backdrop-blur-xl",style:{left:f.left,top:f.top,width:f.width},children:e.jsx("div",{className:"overflow-y-auto",style:{maxHeight:f.maxHeight},children:h.map(o=>{const d=o.value===u;return e.jsxs("button",{type:"button",role:"option","aria-selected":d,onClick:()=>{j(o.value),x(!1)},className:c("flex w-full items-center gap-2.5 rounded-lg px-2.5 py-2 text-left text-[13px] transition-colors duration-200",d?"bg-panel text-fg shadow-[inset_0_1px_0_rgba(255,255,255,0.03)]":"text-fg-3 hover:bg-panel-alt hover:text-fg-2"),children:[g(o.value),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:o.label}),d&&e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"shrink-0 text-fg-4",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})})]},o.value)})})}),document.body):null;return e.jsxs("div",{ref:w,className:"relative shrink-0",children:[e.jsxs("button",{type:"button","aria-haspopup":"listbox","aria-expanded":l,onClick:()=>x(o=>!o),className:c("inline-flex items-center gap-1.5 rounded-lg border border-edge bg-inset px-2 py-1.5","transition-[border-color,box-shadow,background] duration-200 outline-none","hover:border-edge-h hover:bg-panel","focus-visible:border-edge-h focus-visible:shadow-[0_0_0_4px_var(--th-glow-a)]",l&&"border-edge-h bg-panel shadow-[0_0_0_4px_var(--th-glow-a)]"),children:[g(u),e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:c("text-fg-5 transition-transform duration-200",l&&"rotate-180"),children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),m]})}export{P as I,M as S};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as t,j as n}from"./react-vendor-C7Sl8SE7.js";import{c as Ut,I as Ft,S as Ce,m as Pe,a as j,u as Ze,d as Ht,g as Bt,l as Dt,e as Qt,j as _t,f as $t,s as Kt,Y as zt}from"./index-BbplxgnQ.js";import{s as Wt,l as Yt,n as pt,m as Xt,a as Gt,o as Vt,d as Jt,b as Zt,p as er,c as et,e as tt,T as tr,R as rr,U as ht,f as nr,g as xt,h as sr,L as lr,I as ar}from"./index-CULTTvtY.js";import{M as St,a as bt}from"./Modal-DDiBG4kb.js";import"./router-DHISdpPk.js";import"./Select-CG_7h_Tz.js";import"./DirBrowser-CA4k8E_A.js";import"./markdown-DxQYQFeH.js";import"./ExtensionsTab-CRjTmFRl.js";function or({snapshot:a}){const[r,f]=t.useState(a.currentIndex??0),[O,v]=t.useState(""),[k,g]=t.useState(!1),[C,S]=t.useState(null);t.useEffect(()=>{f(a.currentIndex??0),v(""),S(null)},[a.promptId,a.currentIndex]);const L=a.questions||[],y=L[r]||null,K=L.length,P=!!(y?.options&&y.options.length),M=P?!!y?.allowFreeform:!0,ae=u=>{u&&(f(c=>c+1),v(""))},Ie=async u=>{if(!k){g(!0),S(null);try{const c=await j.interactionSelectOption(a.promptId,u);if(!c.ok){S(c.error||"Failed to submit selection.");return}ae(c.advanced)}catch(c){S(c?.message||"Network error.")}finally{g(!1)}}},oe=async()=>{if(k)return;const u=O.trim();if(!u&&!y?.allowEmpty){S("Please enter a response.");return}g(!0),S(null);try{const c=await j.interactionSubmitText(a.promptId,u);if(!c.ok){S(c.error||"Failed to submit answer.");return}ae(c.advanced)}catch(c){S(c?.message||"Network error.")}finally{g(!1)}},p=async()=>{if(!k){g(!0),S(null);try{const u=await j.interactionSkip(a.promptId);if(!u.ok){S(u.error||"Failed to skip.");return}ae(u.advanced)}catch(u){S(u?.message||"Network error.")}finally{g(!1)}}},ue=async()=>{if(!k){g(!0);try{await j.interactionCancel(a.promptId)}catch{}}},ve=t.useMemo(()=>{const u=[];return a.hint&&u.push(a.hint),K>1&&u.push(`Question ${r+1} of ${K}`),u.join(" · ")||void 0},[a.hint,r,K]);return n.jsxs(St,{open:!0,onClose:ue,wide:P&&(y?.options?.length||0)>3,children:[n.jsx(bt,{title:a.title||"Pikiloom needs your input",description:ve,onClose:ue}),y?n.jsxs("div",{className:"space-y-4",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-xs font-medium uppercase tracking-wide text-fg-5",children:y.header||"Question"}),n.jsx("div",{className:"mt-1 whitespace-pre-wrap text-sm leading-relaxed text-fg",children:y.prompt})]}),P&&n.jsx("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2",children:(y.options||[]).map(u=>n.jsxs("button",{type:"button",disabled:k,onClick:()=>Ie(u.value||u.label),className:Ut("group rounded-lg border border-edge bg-panel-alt px-3 py-2 text-left text-sm transition","hover:border-control-border-h hover:bg-control-h hover:shadow-sm","focus:outline-none focus:ring-2 focus:ring-[var(--th-glow-a)]","disabled:cursor-not-allowed disabled:opacity-50"),children:[n.jsx("div",{className:"font-medium text-fg group-hover:text-fg",children:u.label}),u.description&&n.jsx("div",{className:"mt-0.5 text-xs leading-snug text-fg-4",children:u.description})]},u.value||u.label))}),M&&n.jsx("div",{children:n.jsx(Ft,{value:O,onChange:u=>v(u.target.value),onKeyDown:u=>{u.key==="Enter"&&!u.shiftKey&&!k&&(u.preventDefault(),oe())},placeholder:P?"Or type a custom answer…":"Type your answer…",disabled:k,autoFocus:!P})}),C&&n.jsx("div",{className:"rounded-md border border-red-300/40 bg-red-500/10 px-3 py-2 text-xs text-red-600",children:C}),n.jsxs("div",{className:"flex items-center justify-between gap-3",children:[n.jsx("div",{className:"text-xs text-fg-5",children:k?n.jsxs("span",{className:"inline-flex items-center gap-2",children:[n.jsx(Ce,{})," Submitting…"]}):n.jsxs("span",{children:["Press ",n.jsx("kbd",{className:"rounded border border-edge bg-panel-alt px-1.5 py-0.5 text-[10px] uppercase",children:"Enter"})," to send"]})}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(Pe,{variant:"ghost",size:"sm",onClick:p,disabled:k,children:"Skip"}),M&&n.jsx(Pe,{variant:"primary",size:"sm",onClick:oe,disabled:k||!O.trim()&&!y.allowEmpty,children:"Submit"})]})]})]}):n.jsxs("div",{className:"py-6 text-center text-sm text-fg-5",children:[n.jsx(Ce,{className:"mr-2 inline-block"})," Waiting for the agent…"]})]})}function ur(a){return a.isNull?a.localStreamPending||a.holdsActiveState?"reject-null":"apply":(typeof a.updatedAt=="number"?a.updatedAt:0)<a.lastAppliedUpdatedAt?"reject-stale":"apply"}function cr(a,r){return typeof r!="number"?a:r>a?r:a}function ir(a,r){return!a||!a.length?[]:r.size?a.filter(f=>!r.has(f)):a.slice()}function dr(a,r,f,O){if(!a.size)return a;const v=new Set(r);let k=!1;const g=new Map;for(const[C,S]of a){if(f-S>O||!v.has(C)){k=!0;continue}g.set(C,S)}return k?g:a}const rt=12,kt=160,fr=96,mr=[],gr=[],pr=[],hr=20,xr=6e4,le=new Map;function kr(a,r){return`${a}:${r}`}function Sr(a,r){for(le.delete(a),le.set(a,r);le.size>hr;)le.delete(le.keys().next().value)}const Ar=t.memo(function({session:r,workdir:f,active:O=!0,onSessionChange:v,initialPendingPrompt:k,initialPendingImageUrls:g,onPendingPromptConsumed:C}){const S=Ze(e=>e.locale),L=Ze(e=>e.agentStatus?.agents?.find(s=>s.agent===r.agent)??null),y=L?.selectedEffort??null,K=L?.selectedModel??null,P=Ze(e=>e.modelLayer),M=r.profileId?P?.profiles.find(e=>e.id===r.profileId)??null:null,ae=M?P?.providers.find(e=>e.id===M.providerId)??null:null,Ie=r.profileId===void 0?L?.byokProviderName??null:ae?.name??null,oe=r.profileId===void 0?L?.byokProfileName??null:M&&M.name.trim().toLowerCase()!==M.modelId.trim().toLowerCase()?M.name:null,p=t.useMemo(()=>Ht(S),[S]),ue=Bt(r.agent||""),ve=Dt(r),u=!!k||!!(g&&g.length),[c,qe]=t.useState(null),[Ue,ce]=t.useState(!u),[ie,nt]=t.useState(!1),[i,U]=t.useState(null),[de,fe]=t.useState(!1),[z,Fe]=t.useState(null),[It,st]=t.useState(0),[vt,He]=t.useState(null),[W,ye]=t.useState([]),[yt,Te]=t.useState([]),[me,Be]=t.useState([]),[h,Y]=t.useState(k||null),[E,X]=t.useState(g||[]),[Tt,G]=t.useState(null),F=t.useRef(null);F.current=Tt;const lt=t.useRef(h);lt.current=h;const[at,q]=t.useState([]),Re=t.useRef([]);Re.current=at;const ge=t.useRef(null),[Rt,ot]=t.useState(null),[je,pe]=t.useState(null),[he,De]=t.useState(""),[H,Qe]=t.useState(!1),jt=!!L?.capabilities?.fork,_e=t.useRef(null),A=t.useRef(g||[]),B=t.useRef(i),$e=t.useRef(de);B.current=i,$e.current=de;const Ke=t.useRef(W);Ke.current=W;const ut=t.useRef(z);ut.current=z;const D=t.useRef(null),we=t.useRef(null),V=t.useRef(!0),J=t.useRef(!1),Ne=t.useRef(null),ze=t.useRef(!1),Q=t.useRef(u),xe=t.useRef(!1),Z=t.useRef(!1),We=t.useRef(!1),Ye=t.useRef(!1),_=t.useRef(null),Ae=t.useRef(0),ke=t.useRef(new Map),ct=t.useRef({model:null,effort:null}),wt=t.useCallback(e=>{ct.current=e},[]);t.useEffect(()=>{We.current||!u||(We.current=!0,k&&!h&&Y(k),g&&g.length&&!E.length&&(X(g),A.current=g),ce(!1),st(e=>e+1),C?.())},[u,C]);const w=t.useCallback(()=>{Y(null),X(e=>{for(const s of e)URL.revokeObjectURL(s);return[]}),A.current=[],G(null)},[]),ee=t.useCallback(()=>{q(e=>{if(!e.length)return e;for(const s of e)for(const l of s.imageUrls)URL.revokeObjectURL(l);return[]}),ge.current=null},[]),it=t.useCallback((e,s)=>{const l=Wt({streaming:$e.current,liveStreamPhase:B.current?.phase??null,streamPhase:ut.current,queuedTaskCount:Ke.current.length,pendingQueuedCount:Re.current.length}),o=s||[];if(l){const d=`local-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`;ge.current=d,q(x=>[...x,{localId:d,taskId:null,prompt:e||"",imageUrls:o}]);return}B.current?.phase==="done"&&U(null);for(const d of A.current)URL.revokeObjectURL(d);ge.current=null,Y(e||null),X(o),A.current=o,G(null)},[]),Nt=t.useCallback(e=>{const s=ge.current;if(s){ge.current=null,q(l=>{const o=l.findIndex(x=>x.localId===s);if(o<0)return l;const d=l.slice();return d[o]={...d[o],taskId:e},d});return}G(e)},[]),At=t.useCallback(async()=>{if(!je)return;const e=he.trim();if(e){Qe(!0);try{const s=await j.forkSession(f,r.agent||"",r.sessionId,je.atTurn,e,{});if(!s.ok||!s.sessionKey){Qe(!1);return}const[l,o]=s.sessionKey.split(":");pe(null),De(""),v?.({agent:l,sessionId:o,workdir:f})}finally{Qe(!1)}}},[je,he,f,r.agent,r.sessionId,v]);_e.current=At;const Oe=t.useCallback(async(e,s={})=>{try{const l=await Yt({workdir:f,agent:r.agent||"",sessionId:r.sessionId,rich:!0,turnOffset:e.turnOffset,turnLimit:e.turnLimit,lastNTurns:e.lastNTurns},{force:s.force});return l.ok?pt(l):null}catch{return null}},[f,r.agent,r.sessionId]),N=t.useCallback(async({keepOlder:e,force:s=!1,scrollToBottom:l=!1})=>{const o=r.sessionId;if(Ne.current===o)return!1;Ne.current=o;try{const d=await Oe({turnOffset:0,turnLimit:rt},{force:s});if(!d||r.sessionId!==o)return!1;if(l&&(J.current=!0),qe(x=>!x||!e?d:Xt(x,d)),ce(!1),xe.current&&(xe.current=!1,w()),Z.current){const x=Z.current;Z.current=!1;const re=x!==!0?x.taskId:null;B.current&&(x===!0||B.current.taskId===re)&&U(null)}return!0}finally{Ne.current===o&&(Ne.current=null)}},[Oe,w,r.sessionId]),Le=t.useCallback(async()=>{if(!c?.hasOlder||ze.current)return;const e=D.current;e&&(we.current={scrollHeight:e.scrollHeight,scrollTop:e.scrollTop}),ze.current=!0,nt(!0);try{const s=await Oe({turnOffset:Math.max(0,c.totalTurns-c.startTurn),turnLimit:rt});s?qe(l=>l?Gt(l,s):s):we.current=null}finally{ze.current=!1,nt(!1)}},[Oe,c]),Me=t.useRef(null),te=t.useCallback((e,s="ws")=>{if(ur({updatedAt:e?.updatedAt,isNull:!e,lastAppliedUpdatedAt:Ae.current,localStreamPending:Q.current,holdsActiveState:$e.current||Ke.current.length>0})!=="apply")return;if(e&&(Ae.current=cr(Ae.current,e.updatedAt)),e?.sessionId&&e.sessionId!==r.sessionId&&(Ye.current=!0,Se.current=`${r.agent}:${e.sessionId}`,v?.({agent:r.agent||"",sessionId:e.sessionId,workdir:f})),!e){const m=Me.current;fe(!1),m==="streaming"?(xe.current=!0,Z.current=!0,N({keepOlder:!0,force:!0,scrollToBottom:V.current})):U(null),Q.current&&m!=="streaming"?N({keepOlder:!0,force:!0}):(m==="done"&&(w(),ee()),m!==null&&(Q.current=!1)),He(null),Fe(null),ye([]),Te([]),Be([]),Me.current=null;return}Fe(e.phase),He(e.taskId||null);const o=[];e.taskId&&o.push(e.taskId),Array.isArray(e.queuedTaskIds)&&o.push(...e.queuedTaskIds),ke.current=dr(ke.current,o,Date.now(),xr);const d=ke.current,x=ir(e.queuedTaskIds,d),re=(Array.isArray(e.queuedTasks)?e.queuedTasks:[]).filter(m=>!d.has(m.taskId));if(ye(x.length?x:mr),Te(re.length?re:gr),Be(Array.isArray(e.interactions)&&e.interactions.length?e.interactions:pr),Vt({pendingTaskId:F.current,streamTaskId:e.taskId||null,queuedTaskIds:e.queuedTaskIds})){const m=F.current,R=lt.current||"",I=A.current;q(b=>b.some(se=>se.taskId===m)?b:[...b,{localId:`demote-${m}`,taskId:m,prompt:R,imageUrls:I}]),Y(null),X([]),A.current=[],G(null),F.current=null}if(e.phase==="streaming"){if(U({taskId:e.taskId||null,phase:"streaming",text:e.text||"",thinking:e.thinking||"",activity:e.activity,plan:e.plan??null,model:e.model??null,effort:e.effort??null,previewMeta:e.previewMeta??null,subAgents:e.previewMeta?.subAgents??null,generatingImages:e.previewMeta?.generatingImages??0,artifacts:e.artifacts??null,startedAt:typeof e.startedAt=="number"?e.startedAt:null,error:null,question:e.question??null,questionBlocks:e.questionBlocks??null}),fe(!0),e.taskId&&e.taskId!==F.current){const m=Re.current,R=m.findIndex(I=>I.taskId===e.taskId);if(R>=0){const I=m[R];for(const b of A.current)URL.revokeObjectURL(b);Y(I.prompt||null),X(I.imageUrls),A.current=I.imageUrls,G(e.taskId),q(b=>b.filter((se,$)=>$!==R))}}V.current&&(J.current=!0)}else if(e.phase==="queued")U(null),fe(!1);else if(e.phase==="done"){const m=Jt(B.current?.taskId??null,e.taskId||null),R=x.length>0;if(m){fe(!1),U($=>$?{...$,phase:"done",error:e.error??null}:e.error?{taskId:e.taskId||null,phase:"done",text:"",thinking:"",activity:"",plan:null,model:e.model??null,effort:e.effort??null,previewMeta:e.previewMeta??null,subAgents:e.previewMeta?.subAgents??null,generatingImages:e.previewMeta?.generatingImages??0,artifacts:e.artifacts??null,error:e.error,question:e.question??null,questionBlocks:e.questionBlocks??null}:$);const I=B.current,b=!!I&&Zt(I),se=!!e.incomplete&&b&&!R;if(Me.current!=="done"){R||(xe.current=!0),Z.current=se?!1:{taskId:e.taskId||null},N({keepOlder:!0,force:!0,scrollToBottom:V.current});const $=r.agent||"",Ct=r.sessionId,Pt=Se.current;_.current&&clearTimeout(_.current),_.current=setTimeout(()=>{_.current=null,j.getSessionStreamState($,Ct).then(qt=>{Se.current===Pt&&Xe.current(qt.state,"seed")}).catch(()=>{})},900)}}R||(Q.current=!1)}const ne=new Set;if(e.taskId&&ne.add(e.taskId),Array.isArray(e.queuedTaskIds))for(const m of e.queuedTaskIds)ne.add(m);q(m=>{let R=!1;const I=[];for(const b of m)if(!b.taskId||ne.has(b.taskId))I.push(b);else{for(const se of b.imageUrls)URL.revokeObjectURL(se);R=!0}return R?I:m}),Me.current=e.phase},[w,ee,N,r.sessionId,r.agent,v,f]),Xe=t.useRef(te);Xe.current=te;const dt=t.useCallback(()=>{Q.current=!0,st(e=>e+1)},[]);t.useEffect(()=>()=>{_.current&&(clearTimeout(_.current),_.current=null)},[]);const Ot=t.useCallback(async e=>{try{ke.current.set(e,Date.now()),await j.recallSessionMessage(e),F.current===e&&w(),q(s=>{let l=!1;const o=[];for(const d of s)if(d.taskId===e){for(const x of d.imageUrls)URL.revokeObjectURL(x);l=!0}else o.push(d);return l?o:s}),ye(s=>s.filter(l=>l!==e)),Te(s=>s.filter(l=>l.taskId!==e)),He(s=>s===e?null:s)}catch{}},[w]),Lt=t.useCallback(async e=>{const s=Re.current.find(l=>l.taskId===e)||null;if(s&&s.imageUrls.length>0){for(const l of A.current)URL.revokeObjectURL(l);Y(s.prompt||null),X(s.imageUrls),A.current=s.imageUrls,G(e),F.current=e,q(l=>l.filter(o=>o.taskId!==e))}try{await j.steerSession(e)}catch{}},[]),Mt=t.useCallback(async()=>{try{await j.stopSession(r.agent||"",r.sessionId)}catch{}},[r.agent,r.sessionId]),Ee=kr(r.agent||"",r.sessionId);t.useEffect(()=>{if(Ye.current){Ye.current=!1;let d=!1;return N({keepOlder:!0,force:!0}).finally(()=>{d||ce(!1)}),()=>{d=!0}}let e=!1;const s=er({workdir:f,agent:r.agent||"",sessionId:r.sessionId,rich:!0,turnOffset:0,turnLimit:rt},{allowStale:!0}),l=u&&!We.current,o=s?.ok?pt(s):le.get(Ee)||null;return ce(l?!1:!o),qe(o),U(null),fe(!1),Fe(null),ye([]),Te([]),Be([]),Ae.current=0,ke.current=new Map,l||(w(),ee(),Q.current=!1,xe.current=!1,Z.current=!1),V.current=!0,J.current=!0,l||N({keepOlder:!1,force:!0}).finally(()=>{e||ce(!1)}),()=>{e=!0}},[N,r.agent,r.sessionId,f,Ee,w,ee]),t.useEffect(()=>{c&&c.turns.length>0&&Sr(Ee,c)},[Ee,c]),t.useEffect(()=>{O&&N({keepOlder:!0,force:!0})},[O,N]);const Se=t.useRef(`${r.agent}:${r.sessionId}`);Se.current=`${r.agent}:${r.sessionId}`,Qt("stream-update",t.useCallback(e=>{e.key===Se.current&&te(e.snapshot??null)},[te])),t.useEffect(()=>{let e=!0;return j.getSessionStreamState(r.agent||"",r.sessionId).then(s=>{e&&Xe.current(s.state,"seed")}).catch(()=>{}),()=>{e=!1}},[r.agent,r.sessionId,It]),_t(t.useCallback(()=>{j.getSessionStreamState(r.agent||"",r.sessionId).then(e=>{te(e.state,"seed")}).catch(()=>{}),N({keepOlder:!0,force:!0})},[te,r.agent,r.sessionId,N])),t.useEffect(()=>{!Q.current&&ve!=="running"&&!de&&!i&&!z&&W.length===0&&(w(),ee())},[ve,de,i,z,W.length,w,ee]),t.useLayoutEffect(()=>{const e=we.current,s=D.current;!e||!s||(we.current=null,s.scrollTop=e.scrollTop+(s.scrollHeight-e.scrollHeight))},[c?.turns.length]),t.useLayoutEffect(()=>{if(!J.current)return;const e=D.current;e&&(J.current=!1,e.scrollTop=e.scrollHeight,requestAnimationFrame(()=>{V.current&&(e.scrollTop=e.scrollHeight)}))},[c,i]),t.useLayoutEffect(()=>{if(!h)return;const e=D.current;e&&(e.scrollTop=e.scrollHeight)},[h]),t.useEffect(()=>{if(!c?.hasOlder||Ue||ie)return;const e=D.current;e&&e.scrollHeight<=e.clientHeight+kt&&Le()},[c?.hasOlder,c?.turns.length,Le,Ue,ie]);const Et=t.useCallback(()=>{const e=D.current;if(!e)return;const s=e.scrollHeight-e.scrollTop-e.clientHeight;V.current=s<=fr,e.scrollTop<=kt&&Le()},[Le]),be=i?.model||r.model||K||null,Ge=$t(r.agent||"",i?.effort||r.thinkingEffort||y||null,r.workflowEnabled??L?.workflowEnabled)||null,ft=oe&&(!be||be===K)?oe:be?Kt(be):null,Ve=zt(r,{streaming:de,hasLiveStream:!!i,streamPhase:z,queuedTaskCount:W.length}),T=c?.turns||[],Je=t.useMemo(()=>{if(!E.length||!T.length)return!1;const e=T[T.length-1];return!e.user||!et(e.user.text,h)?!1:e.user.blocks.filter(l=>l.type==="image").length<E.length},[T,h,E.length]),mt=t.useMemo(()=>E.length?E.map(e=>({type:"image",content:e})):!h||!i?.questionBlocks?.length?[]:et(h,i.question)?i.questionBlocks:[],[E,h,i]),gt=t.useMemo(()=>{let e=T;if(Je){const ne=e[e.length-1];e=[...e.slice(0,-1),{...ne,user:null}]}if(!i||!e.length)return e;const s=e[e.length-1];if(!s.assistant)return e;const l=h??(i.question||null),o=(i.text||"").trim(),d=s.assistant.text?.trim()||"";if(!(l!=null?tt(s.user?.text,l):!!d&&!!o&&(o.startsWith(d)||d.startsWith(o))))return e;const re=s.user&&l&&!et(s.user.text,l)?{...s.user,text:l}:s.user;return[...e.slice(0,-1),{...s,user:re,assistant:null}]},[T,i,h,Je]);return n.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[n.jsx("div",{ref:D,onScroll:Et,className:"flex-1 overflow-y-auto overscroll-contain",children:Ue&&!h&&!E.length&&!i?n.jsx("div",{className:"flex items-center justify-center py-20",children:n.jsx(Ce,{className:"h-5 w-5 text-fg-4"})}):gt.length===0&&!h&&!E.length&&!i&&!Ve?n.jsx("div",{className:"py-20 text-center text-[13px] text-fg-5",children:p("hub.noMessages")}):n.jsxs("div",{className:"max-w-[900px] mx-auto px-6 py-6 space-y-0",children:[(c?.hasOlder||ie)&&n.jsxs("div",{className:"mb-4 flex items-center justify-center gap-2 text-[11px] text-fg-5",children:[ie?n.jsx(Ce,{className:"h-3 w-3 text-fg-5"}):n.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-fg-5/35"}),n.jsx("span",{children:p(ie?"hub.loadingOlderTurns":"hub.loadOlderTurnsHint")})]}),r.migratedFrom?.kind==="fork"&&r.migratedFrom.sessionId&&n.jsxs("button",{type:"button",onClick:()=>v?.({agent:r.migratedFrom.agent||r.agent||"",sessionId:r.migratedFrom.sessionId,workdir:f}),className:"mb-4 inline-flex items-center gap-1.5 rounded-md border border-edge bg-panel-alt px-2.5 py-1 text-[11px] text-fg-5 transition hover:border-edge-h hover:text-fg-2",title:`#${r.migratedFrom.sessionId.slice(0,8)}`,children:[n.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[n.jsx("circle",{cx:"6",cy:"6",r:"2"}),n.jsx("circle",{cx:"18",cy:"6",r:"2"}),n.jsx("circle",{cx:"12",cy:"20",r:"2"}),n.jsx("path",{d:"M6 8v3a3 3 0 0 0 3 3h6a3 3 0 0 0 3-3V8"}),n.jsx("path",{d:"M12 14v4"})]}),n.jsx("span",{children:p("hub.forkBadge")}),n.jsxs("span",{className:"font-mono",children:["#",r.migratedFrom.sessionId.slice(0,8)]}),typeof r.migratedFrom.forkedAtTurn=="number"&&n.jsxs("span",{className:"text-fg-5/70",children:["· ",p("hub.forkBadgeAt").replace("{turn}",String(r.migratedFrom.forkedAtTurn+1))]})]}),gt.map((e,s)=>{const l=(c?.startTurn||0)+s;return n.jsx(tr,{turn:e,turnIndex:l,agent:r.agent||"",meta:ue,model:ft,effort:Ge,providerName:Ie,t:p,workdir:f,onResend:o=>{J.current=!0,it(o);const d=ct.current;j.sendSessionMessage(f,r.agent||"",r.sessionId,o,{model:d.model||be||void 0,effort:d.effort||Ge||void 0}).then(x=>{x.ok&&dt()}).catch(()=>{w()})},onEdit:o=>ot(o),onFork:jt?o=>{De(""),pe({atTurn:o})}:void 0},`${c?.startTurn||0}:${s}`)}),Ve&&n.jsx("div",{className:"mb-5 animate-in",children:n.jsx(rr,{detail:Ve,t:p})}),(h||mt.length>0)&&(Je||!(h&&T.length>0&&tt(T[T.length-1]?.user?.text,h)))&&n.jsxs("div",{className:"session-turn",children:[n.jsx(ht,{text:h||"",blocks:mt,t:p}),!i&&n.jsx("div",{className:"mt-3 mb-5 animate-in",children:n.jsx(nr,{className:"text-fg-5"})})]}),i&&xt(i)&&!h&&i.question&&!(T.length>0&&tt(T[T.length-1]?.user?.text,i.question))&&n.jsx("div",{className:"session-turn",children:n.jsx(ht,{text:i.question,blocks:i.questionBlocks||void 0,t:p})}),i&&xt(i)&&n.jsxs("div",{className:"mb-6",children:[n.jsx(sr,{agent:r.agent||"",meta:ue,model:ft,effort:Ge,providerName:Ie,previewMeta:i.previewMeta,hideContextUsage:!0}),n.jsx(lr,{stream:i,t:p,workdir:f})]}),n.jsx("div",{className:"h-4"})]})}),n.jsx(ar,{session:r,workdir:f,onStreamQueued:dt,onSendStart:it,onSendTaskAssigned:Nt,onSessionChange:v,t:p,streamPhase:z,streamTaskId:vt,queuedTaskIds:W,queuedTasks:yt,pendingQueuedSends:at,onRecall:Ot,onSteer:Lt,onStopAll:Mt,editDraft:Rt,onEditDraftConsumed:()=>ot(null),onSelectionChange:wt}),je&&n.jsxs(St,{open:!0,onClose:()=>{H||pe(null)},children:[n.jsx(bt,{title:p("hub.forkPromptTitle"),description:p("hub.forkPromptHint"),onClose:()=>{H||pe(null)}}),n.jsx("textarea",{autoFocus:!0,value:he,disabled:H,onChange:e=>De(e.target.value),onKeyDown:e=>{e.key==="Enter"&&(e.metaKey||e.ctrlKey)&&he.trim()&&!H&&(e.preventDefault(),_e.current?.())},placeholder:p("hub.forkPromptPlaceholder"),className:"w-full min-h-[120px] resize-y rounded-md border border-edge bg-panel-alt px-3 py-2 text-[13px] leading-relaxed text-fg outline-none focus:border-edge-h"}),n.jsxs("div",{className:"mt-4 flex items-center justify-end gap-2",children:[n.jsx(Pe,{variant:"ghost",disabled:H,onClick:()=>pe(null),children:p("modal.cancel")}),n.jsx(Pe,{variant:"primary",disabled:H||!he.trim(),onClick:()=>{_e.current?.()},children:p(H?"hub.forkSubmitting":"hub.forkSubmit")})]})]}),O&&me.length>0&&n.jsx(or,{snapshot:me[me.length-1]},me[me.length-1].promptId)]})});export{Ar as SessionPanel};
|
|
1
|
+
import{r as t,j as n}from"./react-vendor-C7Sl8SE7.js";import{c as Ut,I as Ft,S as Ce,m as Pe,a as j,u as Ze,d as Ht,g as Bt,l as Dt,e as Qt,j as _t,f as $t,s as Kt,Y as zt}from"./index-CL5H13Cl.js";import{s as Wt,l as Yt,n as pt,m as Xt,a as Gt,o as Vt,d as Jt,b as Zt,p as er,c as et,e as tt,T as tr,R as rr,U as ht,f as nr,g as xt,h as sr,L as lr,I as ar}from"./index-DooLxbPX.js";import{M as St,a as bt}from"./Modal-DCwGz46r.js";import"./router-DHISdpPk.js";import"./Select-DC6zguGC.js";import"./DirBrowser-DbeAWYiL.js";import"./markdown-DxQYQFeH.js";import"./ExtensionsTab-BMS3PW9N.js";function or({snapshot:a}){const[r,f]=t.useState(a.currentIndex??0),[O,v]=t.useState(""),[k,g]=t.useState(!1),[C,S]=t.useState(null);t.useEffect(()=>{f(a.currentIndex??0),v(""),S(null)},[a.promptId,a.currentIndex]);const L=a.questions||[],y=L[r]||null,K=L.length,P=!!(y?.options&&y.options.length),M=P?!!y?.allowFreeform:!0,ae=u=>{u&&(f(c=>c+1),v(""))},Ie=async u=>{if(!k){g(!0),S(null);try{const c=await j.interactionSelectOption(a.promptId,u);if(!c.ok){S(c.error||"Failed to submit selection.");return}ae(c.advanced)}catch(c){S(c?.message||"Network error.")}finally{g(!1)}}},oe=async()=>{if(k)return;const u=O.trim();if(!u&&!y?.allowEmpty){S("Please enter a response.");return}g(!0),S(null);try{const c=await j.interactionSubmitText(a.promptId,u);if(!c.ok){S(c.error||"Failed to submit answer.");return}ae(c.advanced)}catch(c){S(c?.message||"Network error.")}finally{g(!1)}},p=async()=>{if(!k){g(!0),S(null);try{const u=await j.interactionSkip(a.promptId);if(!u.ok){S(u.error||"Failed to skip.");return}ae(u.advanced)}catch(u){S(u?.message||"Network error.")}finally{g(!1)}}},ue=async()=>{if(!k){g(!0);try{await j.interactionCancel(a.promptId)}catch{}}},ve=t.useMemo(()=>{const u=[];return a.hint&&u.push(a.hint),K>1&&u.push(`Question ${r+1} of ${K}`),u.join(" · ")||void 0},[a.hint,r,K]);return n.jsxs(St,{open:!0,onClose:ue,wide:P&&(y?.options?.length||0)>3,children:[n.jsx(bt,{title:a.title||"Pikiloom needs your input",description:ve,onClose:ue}),y?n.jsxs("div",{className:"space-y-4",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-xs font-medium uppercase tracking-wide text-fg-5",children:y.header||"Question"}),n.jsx("div",{className:"mt-1 whitespace-pre-wrap text-sm leading-relaxed text-fg",children:y.prompt})]}),P&&n.jsx("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2",children:(y.options||[]).map(u=>n.jsxs("button",{type:"button",disabled:k,onClick:()=>Ie(u.value||u.label),className:Ut("group rounded-lg border border-edge bg-panel-alt px-3 py-2 text-left text-sm transition","hover:border-control-border-h hover:bg-control-h hover:shadow-sm","focus:outline-none focus:ring-2 focus:ring-[var(--th-glow-a)]","disabled:cursor-not-allowed disabled:opacity-50"),children:[n.jsx("div",{className:"font-medium text-fg group-hover:text-fg",children:u.label}),u.description&&n.jsx("div",{className:"mt-0.5 text-xs leading-snug text-fg-4",children:u.description})]},u.value||u.label))}),M&&n.jsx("div",{children:n.jsx(Ft,{value:O,onChange:u=>v(u.target.value),onKeyDown:u=>{u.key==="Enter"&&!u.shiftKey&&!k&&(u.preventDefault(),oe())},placeholder:P?"Or type a custom answer…":"Type your answer…",disabled:k,autoFocus:!P})}),C&&n.jsx("div",{className:"rounded-md border border-red-300/40 bg-red-500/10 px-3 py-2 text-xs text-red-600",children:C}),n.jsxs("div",{className:"flex items-center justify-between gap-3",children:[n.jsx("div",{className:"text-xs text-fg-5",children:k?n.jsxs("span",{className:"inline-flex items-center gap-2",children:[n.jsx(Ce,{})," Submitting…"]}):n.jsxs("span",{children:["Press ",n.jsx("kbd",{className:"rounded border border-edge bg-panel-alt px-1.5 py-0.5 text-[10px] uppercase",children:"Enter"})," to send"]})}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(Pe,{variant:"ghost",size:"sm",onClick:p,disabled:k,children:"Skip"}),M&&n.jsx(Pe,{variant:"primary",size:"sm",onClick:oe,disabled:k||!O.trim()&&!y.allowEmpty,children:"Submit"})]})]})]}):n.jsxs("div",{className:"py-6 text-center text-sm text-fg-5",children:[n.jsx(Ce,{className:"mr-2 inline-block"})," Waiting for the agent…"]})]})}function ur(a){return a.isNull?a.localStreamPending||a.holdsActiveState?"reject-null":"apply":(typeof a.updatedAt=="number"?a.updatedAt:0)<a.lastAppliedUpdatedAt?"reject-stale":"apply"}function cr(a,r){return typeof r!="number"?a:r>a?r:a}function ir(a,r){return!a||!a.length?[]:r.size?a.filter(f=>!r.has(f)):a.slice()}function dr(a,r,f,O){if(!a.size)return a;const v=new Set(r);let k=!1;const g=new Map;for(const[C,S]of a){if(f-S>O||!v.has(C)){k=!0;continue}g.set(C,S)}return k?g:a}const rt=12,kt=160,fr=96,mr=[],gr=[],pr=[],hr=20,xr=6e4,le=new Map;function kr(a,r){return`${a}:${r}`}function Sr(a,r){for(le.delete(a),le.set(a,r);le.size>hr;)le.delete(le.keys().next().value)}const Ar=t.memo(function({session:r,workdir:f,active:O=!0,onSessionChange:v,initialPendingPrompt:k,initialPendingImageUrls:g,onPendingPromptConsumed:C}){const S=Ze(e=>e.locale),L=Ze(e=>e.agentStatus?.agents?.find(s=>s.agent===r.agent)??null),y=L?.selectedEffort??null,K=L?.selectedModel??null,P=Ze(e=>e.modelLayer),M=r.profileId?P?.profiles.find(e=>e.id===r.profileId)??null:null,ae=M?P?.providers.find(e=>e.id===M.providerId)??null:null,Ie=r.profileId===void 0?L?.byokProviderName??null:ae?.name??null,oe=r.profileId===void 0?L?.byokProfileName??null:M&&M.name.trim().toLowerCase()!==M.modelId.trim().toLowerCase()?M.name:null,p=t.useMemo(()=>Ht(S),[S]),ue=Bt(r.agent||""),ve=Dt(r),u=!!k||!!(g&&g.length),[c,qe]=t.useState(null),[Ue,ce]=t.useState(!u),[ie,nt]=t.useState(!1),[i,U]=t.useState(null),[de,fe]=t.useState(!1),[z,Fe]=t.useState(null),[It,st]=t.useState(0),[vt,He]=t.useState(null),[W,ye]=t.useState([]),[yt,Te]=t.useState([]),[me,Be]=t.useState([]),[h,Y]=t.useState(k||null),[E,X]=t.useState(g||[]),[Tt,G]=t.useState(null),F=t.useRef(null);F.current=Tt;const lt=t.useRef(h);lt.current=h;const[at,q]=t.useState([]),Re=t.useRef([]);Re.current=at;const ge=t.useRef(null),[Rt,ot]=t.useState(null),[je,pe]=t.useState(null),[he,De]=t.useState(""),[H,Qe]=t.useState(!1),jt=!!L?.capabilities?.fork,_e=t.useRef(null),A=t.useRef(g||[]),B=t.useRef(i),$e=t.useRef(de);B.current=i,$e.current=de;const Ke=t.useRef(W);Ke.current=W;const ut=t.useRef(z);ut.current=z;const D=t.useRef(null),we=t.useRef(null),V=t.useRef(!0),J=t.useRef(!1),Ne=t.useRef(null),ze=t.useRef(!1),Q=t.useRef(u),xe=t.useRef(!1),Z=t.useRef(!1),We=t.useRef(!1),Ye=t.useRef(!1),_=t.useRef(null),Ae=t.useRef(0),ke=t.useRef(new Map),ct=t.useRef({model:null,effort:null}),wt=t.useCallback(e=>{ct.current=e},[]);t.useEffect(()=>{We.current||!u||(We.current=!0,k&&!h&&Y(k),g&&g.length&&!E.length&&(X(g),A.current=g),ce(!1),st(e=>e+1),C?.())},[u,C]);const w=t.useCallback(()=>{Y(null),X(e=>{for(const s of e)URL.revokeObjectURL(s);return[]}),A.current=[],G(null)},[]),ee=t.useCallback(()=>{q(e=>{if(!e.length)return e;for(const s of e)for(const l of s.imageUrls)URL.revokeObjectURL(l);return[]}),ge.current=null},[]),it=t.useCallback((e,s)=>{const l=Wt({streaming:$e.current,liveStreamPhase:B.current?.phase??null,streamPhase:ut.current,queuedTaskCount:Ke.current.length,pendingQueuedCount:Re.current.length}),o=s||[];if(l){const d=`local-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`;ge.current=d,q(x=>[...x,{localId:d,taskId:null,prompt:e||"",imageUrls:o}]);return}B.current?.phase==="done"&&U(null);for(const d of A.current)URL.revokeObjectURL(d);ge.current=null,Y(e||null),X(o),A.current=o,G(null)},[]),Nt=t.useCallback(e=>{const s=ge.current;if(s){ge.current=null,q(l=>{const o=l.findIndex(x=>x.localId===s);if(o<0)return l;const d=l.slice();return d[o]={...d[o],taskId:e},d});return}G(e)},[]),At=t.useCallback(async()=>{if(!je)return;const e=he.trim();if(e){Qe(!0);try{const s=await j.forkSession(f,r.agent||"",r.sessionId,je.atTurn,e,{});if(!s.ok||!s.sessionKey){Qe(!1);return}const[l,o]=s.sessionKey.split(":");pe(null),De(""),v?.({agent:l,sessionId:o,workdir:f})}finally{Qe(!1)}}},[je,he,f,r.agent,r.sessionId,v]);_e.current=At;const Oe=t.useCallback(async(e,s={})=>{try{const l=await Yt({workdir:f,agent:r.agent||"",sessionId:r.sessionId,rich:!0,turnOffset:e.turnOffset,turnLimit:e.turnLimit,lastNTurns:e.lastNTurns},{force:s.force});return l.ok?pt(l):null}catch{return null}},[f,r.agent,r.sessionId]),N=t.useCallback(async({keepOlder:e,force:s=!1,scrollToBottom:l=!1})=>{const o=r.sessionId;if(Ne.current===o)return!1;Ne.current=o;try{const d=await Oe({turnOffset:0,turnLimit:rt},{force:s});if(!d||r.sessionId!==o)return!1;if(l&&(J.current=!0),qe(x=>!x||!e?d:Xt(x,d)),ce(!1),xe.current&&(xe.current=!1,w()),Z.current){const x=Z.current;Z.current=!1;const re=x!==!0?x.taskId:null;B.current&&(x===!0||B.current.taskId===re)&&U(null)}return!0}finally{Ne.current===o&&(Ne.current=null)}},[Oe,w,r.sessionId]),Le=t.useCallback(async()=>{if(!c?.hasOlder||ze.current)return;const e=D.current;e&&(we.current={scrollHeight:e.scrollHeight,scrollTop:e.scrollTop}),ze.current=!0,nt(!0);try{const s=await Oe({turnOffset:Math.max(0,c.totalTurns-c.startTurn),turnLimit:rt});s?qe(l=>l?Gt(l,s):s):we.current=null}finally{ze.current=!1,nt(!1)}},[Oe,c]),Me=t.useRef(null),te=t.useCallback((e,s="ws")=>{if(ur({updatedAt:e?.updatedAt,isNull:!e,lastAppliedUpdatedAt:Ae.current,localStreamPending:Q.current,holdsActiveState:$e.current||Ke.current.length>0})!=="apply")return;if(e&&(Ae.current=cr(Ae.current,e.updatedAt)),e?.sessionId&&e.sessionId!==r.sessionId&&(Ye.current=!0,Se.current=`${r.agent}:${e.sessionId}`,v?.({agent:r.agent||"",sessionId:e.sessionId,workdir:f})),!e){const m=Me.current;fe(!1),m==="streaming"?(xe.current=!0,Z.current=!0,N({keepOlder:!0,force:!0,scrollToBottom:V.current})):U(null),Q.current&&m!=="streaming"?N({keepOlder:!0,force:!0}):(m==="done"&&(w(),ee()),m!==null&&(Q.current=!1)),He(null),Fe(null),ye([]),Te([]),Be([]),Me.current=null;return}Fe(e.phase),He(e.taskId||null);const o=[];e.taskId&&o.push(e.taskId),Array.isArray(e.queuedTaskIds)&&o.push(...e.queuedTaskIds),ke.current=dr(ke.current,o,Date.now(),xr);const d=ke.current,x=ir(e.queuedTaskIds,d),re=(Array.isArray(e.queuedTasks)?e.queuedTasks:[]).filter(m=>!d.has(m.taskId));if(ye(x.length?x:mr),Te(re.length?re:gr),Be(Array.isArray(e.interactions)&&e.interactions.length?e.interactions:pr),Vt({pendingTaskId:F.current,streamTaskId:e.taskId||null,queuedTaskIds:e.queuedTaskIds})){const m=F.current,R=lt.current||"",I=A.current;q(b=>b.some(se=>se.taskId===m)?b:[...b,{localId:`demote-${m}`,taskId:m,prompt:R,imageUrls:I}]),Y(null),X([]),A.current=[],G(null),F.current=null}if(e.phase==="streaming"){if(U({taskId:e.taskId||null,phase:"streaming",text:e.text||"",thinking:e.thinking||"",activity:e.activity,plan:e.plan??null,model:e.model??null,effort:e.effort??null,previewMeta:e.previewMeta??null,subAgents:e.previewMeta?.subAgents??null,generatingImages:e.previewMeta?.generatingImages??0,artifacts:e.artifacts??null,startedAt:typeof e.startedAt=="number"?e.startedAt:null,error:null,question:e.question??null,questionBlocks:e.questionBlocks??null}),fe(!0),e.taskId&&e.taskId!==F.current){const m=Re.current,R=m.findIndex(I=>I.taskId===e.taskId);if(R>=0){const I=m[R];for(const b of A.current)URL.revokeObjectURL(b);Y(I.prompt||null),X(I.imageUrls),A.current=I.imageUrls,G(e.taskId),q(b=>b.filter((se,$)=>$!==R))}}V.current&&(J.current=!0)}else if(e.phase==="queued")U(null),fe(!1);else if(e.phase==="done"){const m=Jt(B.current?.taskId??null,e.taskId||null),R=x.length>0;if(m){fe(!1),U($=>$?{...$,phase:"done",error:e.error??null}:e.error?{taskId:e.taskId||null,phase:"done",text:"",thinking:"",activity:"",plan:null,model:e.model??null,effort:e.effort??null,previewMeta:e.previewMeta??null,subAgents:e.previewMeta?.subAgents??null,generatingImages:e.previewMeta?.generatingImages??0,artifacts:e.artifacts??null,error:e.error,question:e.question??null,questionBlocks:e.questionBlocks??null}:$);const I=B.current,b=!!I&&Zt(I),se=!!e.incomplete&&b&&!R;if(Me.current!=="done"){R||(xe.current=!0),Z.current=se?!1:{taskId:e.taskId||null},N({keepOlder:!0,force:!0,scrollToBottom:V.current});const $=r.agent||"",Ct=r.sessionId,Pt=Se.current;_.current&&clearTimeout(_.current),_.current=setTimeout(()=>{_.current=null,j.getSessionStreamState($,Ct).then(qt=>{Se.current===Pt&&Xe.current(qt.state,"seed")}).catch(()=>{})},900)}}R||(Q.current=!1)}const ne=new Set;if(e.taskId&&ne.add(e.taskId),Array.isArray(e.queuedTaskIds))for(const m of e.queuedTaskIds)ne.add(m);q(m=>{let R=!1;const I=[];for(const b of m)if(!b.taskId||ne.has(b.taskId))I.push(b);else{for(const se of b.imageUrls)URL.revokeObjectURL(se);R=!0}return R?I:m}),Me.current=e.phase},[w,ee,N,r.sessionId,r.agent,v,f]),Xe=t.useRef(te);Xe.current=te;const dt=t.useCallback(()=>{Q.current=!0,st(e=>e+1)},[]);t.useEffect(()=>()=>{_.current&&(clearTimeout(_.current),_.current=null)},[]);const Ot=t.useCallback(async e=>{try{ke.current.set(e,Date.now()),await j.recallSessionMessage(e),F.current===e&&w(),q(s=>{let l=!1;const o=[];for(const d of s)if(d.taskId===e){for(const x of d.imageUrls)URL.revokeObjectURL(x);l=!0}else o.push(d);return l?o:s}),ye(s=>s.filter(l=>l!==e)),Te(s=>s.filter(l=>l.taskId!==e)),He(s=>s===e?null:s)}catch{}},[w]),Lt=t.useCallback(async e=>{const s=Re.current.find(l=>l.taskId===e)||null;if(s&&s.imageUrls.length>0){for(const l of A.current)URL.revokeObjectURL(l);Y(s.prompt||null),X(s.imageUrls),A.current=s.imageUrls,G(e),F.current=e,q(l=>l.filter(o=>o.taskId!==e))}try{await j.steerSession(e)}catch{}},[]),Mt=t.useCallback(async()=>{try{await j.stopSession(r.agent||"",r.sessionId)}catch{}},[r.agent,r.sessionId]),Ee=kr(r.agent||"",r.sessionId);t.useEffect(()=>{if(Ye.current){Ye.current=!1;let d=!1;return N({keepOlder:!0,force:!0}).finally(()=>{d||ce(!1)}),()=>{d=!0}}let e=!1;const s=er({workdir:f,agent:r.agent||"",sessionId:r.sessionId,rich:!0,turnOffset:0,turnLimit:rt},{allowStale:!0}),l=u&&!We.current,o=s?.ok?pt(s):le.get(Ee)||null;return ce(l?!1:!o),qe(o),U(null),fe(!1),Fe(null),ye([]),Te([]),Be([]),Ae.current=0,ke.current=new Map,l||(w(),ee(),Q.current=!1,xe.current=!1,Z.current=!1),V.current=!0,J.current=!0,l||N({keepOlder:!1,force:!0}).finally(()=>{e||ce(!1)}),()=>{e=!0}},[N,r.agent,r.sessionId,f,Ee,w,ee]),t.useEffect(()=>{c&&c.turns.length>0&&Sr(Ee,c)},[Ee,c]),t.useEffect(()=>{O&&N({keepOlder:!0,force:!0})},[O,N]);const Se=t.useRef(`${r.agent}:${r.sessionId}`);Se.current=`${r.agent}:${r.sessionId}`,Qt("stream-update",t.useCallback(e=>{e.key===Se.current&&te(e.snapshot??null)},[te])),t.useEffect(()=>{let e=!0;return j.getSessionStreamState(r.agent||"",r.sessionId).then(s=>{e&&Xe.current(s.state,"seed")}).catch(()=>{}),()=>{e=!1}},[r.agent,r.sessionId,It]),_t(t.useCallback(()=>{j.getSessionStreamState(r.agent||"",r.sessionId).then(e=>{te(e.state,"seed")}).catch(()=>{}),N({keepOlder:!0,force:!0})},[te,r.agent,r.sessionId,N])),t.useEffect(()=>{!Q.current&&ve!=="running"&&!de&&!i&&!z&&W.length===0&&(w(),ee())},[ve,de,i,z,W.length,w,ee]),t.useLayoutEffect(()=>{const e=we.current,s=D.current;!e||!s||(we.current=null,s.scrollTop=e.scrollTop+(s.scrollHeight-e.scrollHeight))},[c?.turns.length]),t.useLayoutEffect(()=>{if(!J.current)return;const e=D.current;e&&(J.current=!1,e.scrollTop=e.scrollHeight,requestAnimationFrame(()=>{V.current&&(e.scrollTop=e.scrollHeight)}))},[c,i]),t.useLayoutEffect(()=>{if(!h)return;const e=D.current;e&&(e.scrollTop=e.scrollHeight)},[h]),t.useEffect(()=>{if(!c?.hasOlder||Ue||ie)return;const e=D.current;e&&e.scrollHeight<=e.clientHeight+kt&&Le()},[c?.hasOlder,c?.turns.length,Le,Ue,ie]);const Et=t.useCallback(()=>{const e=D.current;if(!e)return;const s=e.scrollHeight-e.scrollTop-e.clientHeight;V.current=s<=fr,e.scrollTop<=kt&&Le()},[Le]),be=i?.model||r.model||K||null,Ge=$t(r.agent||"",i?.effort||r.thinkingEffort||y||null,r.workflowEnabled??L?.workflowEnabled)||null,ft=oe&&(!be||be===K)?oe:be?Kt(be):null,Ve=zt(r,{streaming:de,hasLiveStream:!!i,streamPhase:z,queuedTaskCount:W.length}),T=c?.turns||[],Je=t.useMemo(()=>{if(!E.length||!T.length)return!1;const e=T[T.length-1];return!e.user||!et(e.user.text,h)?!1:e.user.blocks.filter(l=>l.type==="image").length<E.length},[T,h,E.length]),mt=t.useMemo(()=>E.length?E.map(e=>({type:"image",content:e})):!h||!i?.questionBlocks?.length?[]:et(h,i.question)?i.questionBlocks:[],[E,h,i]),gt=t.useMemo(()=>{let e=T;if(Je){const ne=e[e.length-1];e=[...e.slice(0,-1),{...ne,user:null}]}if(!i||!e.length)return e;const s=e[e.length-1];if(!s.assistant)return e;const l=h??(i.question||null),o=(i.text||"").trim(),d=s.assistant.text?.trim()||"";if(!(l!=null?tt(s.user?.text,l):!!d&&!!o&&(o.startsWith(d)||d.startsWith(o))))return e;const re=s.user&&l&&!et(s.user.text,l)?{...s.user,text:l}:s.user;return[...e.slice(0,-1),{...s,user:re,assistant:null}]},[T,i,h,Je]);return n.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[n.jsx("div",{ref:D,onScroll:Et,className:"flex-1 overflow-y-auto overscroll-contain",children:Ue&&!h&&!E.length&&!i?n.jsx("div",{className:"flex items-center justify-center py-20",children:n.jsx(Ce,{className:"h-5 w-5 text-fg-4"})}):gt.length===0&&!h&&!E.length&&!i&&!Ve?n.jsx("div",{className:"py-20 text-center text-[13px] text-fg-5",children:p("hub.noMessages")}):n.jsxs("div",{className:"max-w-[900px] mx-auto px-6 py-6 space-y-0",children:[(c?.hasOlder||ie)&&n.jsxs("div",{className:"mb-4 flex items-center justify-center gap-2 text-[11px] text-fg-5",children:[ie?n.jsx(Ce,{className:"h-3 w-3 text-fg-5"}):n.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-fg-5/35"}),n.jsx("span",{children:p(ie?"hub.loadingOlderTurns":"hub.loadOlderTurnsHint")})]}),r.migratedFrom?.kind==="fork"&&r.migratedFrom.sessionId&&n.jsxs("button",{type:"button",onClick:()=>v?.({agent:r.migratedFrom.agent||r.agent||"",sessionId:r.migratedFrom.sessionId,workdir:f}),className:"mb-4 inline-flex items-center gap-1.5 rounded-md border border-edge bg-panel-alt px-2.5 py-1 text-[11px] text-fg-5 transition hover:border-edge-h hover:text-fg-2",title:`#${r.migratedFrom.sessionId.slice(0,8)}`,children:[n.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[n.jsx("circle",{cx:"6",cy:"6",r:"2"}),n.jsx("circle",{cx:"18",cy:"6",r:"2"}),n.jsx("circle",{cx:"12",cy:"20",r:"2"}),n.jsx("path",{d:"M6 8v3a3 3 0 0 0 3 3h6a3 3 0 0 0 3-3V8"}),n.jsx("path",{d:"M12 14v4"})]}),n.jsx("span",{children:p("hub.forkBadge")}),n.jsxs("span",{className:"font-mono",children:["#",r.migratedFrom.sessionId.slice(0,8)]}),typeof r.migratedFrom.forkedAtTurn=="number"&&n.jsxs("span",{className:"text-fg-5/70",children:["· ",p("hub.forkBadgeAt").replace("{turn}",String(r.migratedFrom.forkedAtTurn+1))]})]}),gt.map((e,s)=>{const l=(c?.startTurn||0)+s;return n.jsx(tr,{turn:e,turnIndex:l,agent:r.agent||"",meta:ue,model:ft,effort:Ge,providerName:Ie,t:p,workdir:f,onResend:o=>{J.current=!0,it(o);const d=ct.current;j.sendSessionMessage(f,r.agent||"",r.sessionId,o,{model:d.model||be||void 0,effort:d.effort||Ge||void 0}).then(x=>{x.ok&&dt()}).catch(()=>{w()})},onEdit:o=>ot(o),onFork:jt?o=>{De(""),pe({atTurn:o})}:void 0},`${c?.startTurn||0}:${s}`)}),Ve&&n.jsx("div",{className:"mb-5 animate-in",children:n.jsx(rr,{detail:Ve,t:p})}),(h||mt.length>0)&&(Je||!(h&&T.length>0&&tt(T[T.length-1]?.user?.text,h)))&&n.jsxs("div",{className:"session-turn",children:[n.jsx(ht,{text:h||"",blocks:mt,t:p}),!i&&n.jsx("div",{className:"mt-3 mb-5 animate-in",children:n.jsx(nr,{className:"text-fg-5"})})]}),i&&xt(i)&&!h&&i.question&&!(T.length>0&&tt(T[T.length-1]?.user?.text,i.question))&&n.jsx("div",{className:"session-turn",children:n.jsx(ht,{text:i.question,blocks:i.questionBlocks||void 0,t:p})}),i&&xt(i)&&n.jsxs("div",{className:"mb-6",children:[n.jsx(sr,{agent:r.agent||"",meta:ue,model:ft,effort:Ge,providerName:Ie,previewMeta:i.previewMeta,hideContextUsage:!0}),n.jsx(lr,{stream:i,t:p,workdir:f})]}),n.jsx("div",{className:"h-4"})]})}),n.jsx(ar,{session:r,workdir:f,onStreamQueued:dt,onSendStart:it,onSendTaskAssigned:Nt,onSessionChange:v,t:p,streamPhase:z,streamTaskId:vt,queuedTaskIds:W,queuedTasks:yt,pendingQueuedSends:at,onRecall:Ot,onSteer:Lt,onStopAll:Mt,editDraft:Rt,onEditDraftConsumed:()=>ot(null),onSelectionChange:wt}),je&&n.jsxs(St,{open:!0,onClose:()=>{H||pe(null)},children:[n.jsx(bt,{title:p("hub.forkPromptTitle"),description:p("hub.forkPromptHint"),onClose:()=>{H||pe(null)}}),n.jsx("textarea",{autoFocus:!0,value:he,disabled:H,onChange:e=>De(e.target.value),onKeyDown:e=>{e.key==="Enter"&&(e.metaKey||e.ctrlKey)&&he.trim()&&!H&&(e.preventDefault(),_e.current?.())},placeholder:p("hub.forkPromptPlaceholder"),className:"w-full min-h-[120px] resize-y rounded-md border border-edge bg-panel-alt px-3 py-2 text-[13px] leading-relaxed text-fg outline-none focus:border-edge-h"}),n.jsxs("div",{className:"mt-4 flex items-center justify-end gap-2",children:[n.jsx(Pe,{variant:"ghost",disabled:H,onClick:()=>pe(null),children:p("modal.cancel")}),n.jsx(Pe,{variant:"primary",disabled:H||!he.trim(),onClick:()=>{_e.current?.()},children:p(H?"hub.forkSubmitting":"hub.forkSubmit")})]})]}),O&&me.length>0&&n.jsx(or,{snapshot:me[me.length-1]},me[me.length-1].promptId)]})});export{Ar as SessionPanel};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e,r as f}from"./react-vendor-C7Sl8SE7.js";import{M as v,c as A,N as F,u as x,d as G,a as $,m as w,R as L,F as g,G as O}from"./index-
|
|
1
|
+
import{j as e,r as f}from"./react-vendor-C7Sl8SE7.js";import{M as v,c as A,N as F,u as x,d as G,a as $,m as w,R as L,F as g,G as O}from"./index-CL5H13Cl.js";import{ClientConnectionPanel as z,ServerConfigPanel as E}from"./ConnectionModal-BOVwXLJB.js";import{S as k}from"./shared-Byy2BNLq.js";import"./router-DHISdpPk.js";import"./Modal-DCwGz46r.js";function j(s){return Number.isFinite(s??NaN)?Math.max(0,Math.min(100,Number(s))):null}function S(s){return Number.isFinite(s??NaN)?Number(s).toFixed(2):null}function W(s){return s?[s.hostName||"—",s.platform,s.arch].filter(Boolean).join(" · "):""}function q(s,r){if(!s)return[];const o=s.totalMem||0,i=s.memoryUsed||o-(s.freeMem||0),t=j(s.memoryPercent||(o>0?i/o*100:0)),a=j(s.cpuUsage?.usedPercent),d=s.loadAverage||null,c=S(d?.one),p=S(d?.five),u=S(d?.fifteen),h=j(d?d.one/Math.max(s.cpuCount||1,1)*100:null),y=[{key:"cpu",label:r("sessions.cpu"),value:a!=null?`${a.toFixed(0)}%`:`${s.cpuCount} cores`,detail:[`${s.cpuCount} cores`,s.cpuModel||""].filter(Boolean),tone:a!=null&&a>=85?"warn":"ok",progressPercent:a},...c&&p&&u?[{key:"cpu-load",label:r("system.cpuLoad"),value:`1m ${c}`,detail:[`5m ${p}`,`15m ${u}`],tone:h!=null&&h>=85?"warn":"muted",progressPercent:h}]:[],{key:"memory",label:r("sessions.memory"),value:`${F(i)} / ${F(o)}`,detail:t!=null?`${t.toFixed(0)}%`:void 0,tone:t!=null&&t>=85?"warn":"ok",progressPercent:t}];if(s.disk){const m=j(parseFloat(String(s.disk.percent).replace("%","")));y.push({key:"disk",label:r("sessions.disk"),value:`${s.disk.used} / ${s.disk.total}`,detail:s.disk.percent,tone:m!=null&&m>=85?"warn":"muted",progressPercent:m})}else if(s.battery){const m=j(parseFloat(String(s.battery.percent).replace("%","")));y.push({key:"battery",label:r("sessions.battery"),value:s.battery.percent,detail:s.battery.state,tone:m!=null&&m<=20?"warn":"muted",progressPercent:m})}return y}function B(s){return s?Array.isArray(s)?s.join(" · "):s:""}function I({items:s,loading:r,className:o}){return r?e.jsx("div",{className:A("space-y-1",o),children:Array.from({length:4},(i,t)=>e.jsxs("div",{className:"grid grid-cols-[80px_auto_1fr] items-baseline gap-x-4 py-1",children:[e.jsx(v,{className:"h-3 w-12"}),e.jsx(v,{className:"h-3 w-24"}),e.jsx(v,{className:"h-3 w-28"})]},t))}):e.jsx("div",{className:A("flex flex-wrap items-baseline gap-x-5 gap-y-1.5",o),children:s.map(i=>{const t=B(i.detail);return e.jsxs("div",{className:"inline-flex items-baseline gap-1.5 whitespace-nowrap",title:t||void 0,children:[e.jsx("span",{className:"text-[10px] font-medium uppercase tracking-[0.12em] text-fg-5",children:i.label}),e.jsx("span",{className:"font-mono text-[12px] tabular-nums text-fg-2",children:i.value}),t&&e.jsxs("span",{className:"text-[11px] text-fg-5",children:["· ",t]})]},i.key)})})}const K=[{key:"screenRecording",labelKey:"perm.screenRecording",reasonZh:"用于截图与界面分析",reasonEn:"For screenshots and UI inspection",guidePathKey:"perm.pathScreenRecording",icon:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"4",y:"5.5",width:"11.5",height:"10",rx:"2.4"}),e.jsx("path",{d:"m17.5 8.4 2.7-1.5v7.2l-2.7-1.5"}),e.jsx("circle",{cx:"9.75",cy:"10.5",r:"1.1",fill:"currentColor",stroke:"none"})]})},{key:"fullDiskAccess",labelKey:"perm.fullDiskAccess",reasonZh:"访问桌面、下载等受保护目录",reasonEn:"Access to Desktop, Downloads and other protected folders",guidePathKey:"perm.pathFullDiskAccess",icon:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"6.2",y:"10.1",width:"11.6",height:"8.6",rx:"2.6"}),e.jsx("path",{d:"M9 10V7.8a3 3 0 1 1 6 0V10"}),e.jsx("circle",{cx:"12",cy:"13.5",r:"0.9",fill:"currentColor",stroke:"none"}),e.jsx("path",{d:"M12 14.6v1.8"})]})}];function T(s){return s==="zh-CN"?{introWithHost:"请在 macOS 中为 {hostApp} 开启以下权限。",intro:"请在 macOS 中开启以下权限。",status:"状态",summary:"系统位置",loading:"检查中",needsGrant:"需要授权",granted:"已授权",authorize:"授权",openSettings:"前往设置",refreshState:"刷新状态",checking:"检查中...",hostGranted:"{hostApp} 已可直接使用此权限。",hostGrantedFallback:"当前宿主应用已可直接使用此权限。",needsGrantDetail:"尚未授权,可通过右侧按钮发起系统授权。",needsSettingsDetail:"需要在系统设置中手动开启此权限。"}:{introWithHost:"Grant the following permissions to {hostApp} in macOS.",intro:"Grant the following permissions in macOS.",status:"Status",summary:"System path",loading:"Checking",needsGrant:"Needs access",granted:"Granted",authorize:"Authorize",openSettings:"Open settings",refreshState:"Refresh status",checking:"Checking...",hostGranted:"{hostApp} can use this permission now.",hostGrantedFallback:"The current host app can use this permission now.",needsGrantDetail:"Access has not been granted yet. Use the button on the right to trigger the macOS prompt.",needsSettingsDetail:"This permission needs to be enabled manually in System Settings."}}function H(){const s=x(n=>n.state),r=x(n=>n.locale),o=x(n=>n.reload),i=x(n=>n.toast),t=f.useMemo(()=>G(r),[r]),a=T(r),d=s?.permissions||{},c=s?.hostApp||null,p=!s,[u,h]=f.useState(null),y=f.useMemo(()=>K.map(n=>({...n,permission:d[n.key]})),[d]),m=f.useCallback(async n=>{if(!u){h(n);try{const l=await $.requestPermission(n);if(!l.ok){i(l.error||t("perm.requestFailed"),!1);return}l.action==="already_granted"?i(t("perm.alreadyGranted")):l.action==="prompted"?i(t("perm.promptOpened")):i(t("perm.settingsOpened")),await o()}catch(l){i(l instanceof Error?l.message:t("perm.requestFailed"),!1)}finally{h(l=>l===n?null:l)}}},[o,u,t,i]),M=f.useCallback(async()=>{await o()},[o]);return e.jsxs("div",{className:"animate-in space-y-3",children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx("div",{className:"text-[13px] leading-relaxed text-fg-4",children:c?a.introWithHost.replace("{hostApp}",c):a.intro})}),e.jsx(w,{variant:"outline",size:"sm",onClick:()=>{M()},children:a.refreshState})]}),e.jsx(L,{children:y.map(n=>{const l=n.permission,b=!!l?.granted,P=!!l&&l.checkable,C=p?a.loading:b?a.granted:a.needsGrant,D=p?"idle":b?"ok":"warn",N=p?a.loading:b?c?a.hostGranted.replace("{hostApp}",c):a.hostGrantedFallback:P?a.needsGrantDetail:a.needsSettingsDetail,R=p?a.checking:P?a.authorize:a.openSettings;return e.jsxs(g,{children:[e.jsx(g.Lead,{icon:n.icon,title:t(n.labelKey),subtitle:r==="zh-CN"?n.reasonZh:n.reasonEn}),e.jsx(g.Status,{children:e.jsx(O,{state:D,label:C})}),e.jsx(g.Field,{children:t(n.guidePathKey)}),e.jsx(g.Action,{children:!b&&e.jsx(w,{variant:"primary",size:"sm",disabled:p||!!u,onClick:()=>{m(n.key)},children:u===n.key?a.checking:R})}),N&&N!==C&&e.jsx(g.Description,{children:N})]},n.key)})})]})}function X({onOpenWorkdir:s}){const r=x(c=>c.state),o=x(c=>c.host),i=x(c=>c.locale),t=f.useMemo(()=>G(i),[i]),a=r?.bot?.workdir||r?.runtimeWorkdir||r?.config.workdir||"",d=W(o);return e.jsxs("div",{className:"animate-in space-y-3",children:[e.jsx(k,{className:"!p-3.5",children:e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"flex items-baseline gap-2",children:e.jsx("span",{className:"text-[13px] font-semibold tracking-tight text-fg",children:t("config.workdir")})}),e.jsx("div",{className:"mt-0.5 break-all font-mono text-[12px] leading-relaxed text-fg-2",children:a||t("sidebar.notSet")})]}),e.jsx(w,{variant:"outline",size:"sm",onClick:s,children:t("sidebar.switchDir")})]})}),e.jsxs(k,{className:"space-y-2 !p-3.5",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline justify-between gap-x-3 gap-y-0.5",children:[e.jsxs("div",{className:"flex items-baseline gap-2 min-w-0",children:[e.jsx("span",{className:"text-[13px] font-semibold tracking-tight text-fg",children:t("app.systemInfo")}),e.jsx("span",{className:"truncate text-[11px] text-fg-5",children:d||t("status.loading")})]}),e.jsxs("div",{className:"text-[11px] text-fg-5",children:[r?.version?`Pikiloom v${r.version}`:"Pikiloom",r?.nodeVersion?` · Node ${r.nodeVersion}`:""]})]}),e.jsx(I,{items:q(o,t),loading:!o})]}),e.jsx(k,{className:"!p-3.5",children:e.jsx(z,{})}),e.jsx(k,{className:"!p-3.5",children:e.jsx(E,{})}),e.jsxs(k,{className:"space-y-2 !p-3.5",children:[e.jsx("div",{className:"text-[13px] font-semibold tracking-tight text-fg",children:t("tab.permissions")}),e.jsx(H,{})]})]})}export{X as SystemTab};
|