pikiloom 0.4.12 → 0.4.14
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-DdA7lBTM.js → AgentTab-Ce9nOgKB.js} +1 -1
- package/dashboard/dist/assets/{DirBrowser-ChaxfTLA.js → DirBrowser-B5hxg2zn.js} +1 -1
- package/dashboard/dist/assets/{ExtensionsTab-DS1QHNtt.js → ExtensionsTab-C2FAUsui.js} +1 -1
- package/dashboard/dist/assets/{IMAccessTab-wj6_hdBo.js → IMAccessTab-CS-2-ENn.js} +1 -1
- package/dashboard/dist/assets/{Modal-Bhdq3fQH.js → Modal-BF2CycPZ.js} +1 -1
- package/dashboard/dist/assets/Modals-BHYtxTUE.js +1 -0
- package/dashboard/dist/assets/{Select-DRA-XB6z.js → Select--CwQ1vbY.js} +1 -1
- package/dashboard/dist/assets/{SessionPanel-Cdje64_Q.js → SessionPanel-D0h4d0Nw.js} +1 -1
- package/dashboard/dist/assets/{SystemTab-B7Y5IjIC.js → SystemTab-B_hq7KIo.js} +1 -1
- package/dashboard/dist/assets/{index-DDITAW7a.js → index-Dws-2k-J.js} +3 -3
- package/dashboard/dist/assets/{index-BLei0B_k.js → index-jCpvbF9B.js} +3 -3
- package/dashboard/dist/assets/{shared-vqgXV5IK.js → shared-D1ruCzXL.js} +1 -1
- package/dashboard/dist/index.html +1 -1
- package/dist/agent/mcp/bridge.js +53 -2
- package/dist/dashboard/routes/extensions.js +6 -0
- package/dist/model/injector.js +167 -28
- package/dist/model/responses-bridge.js +366 -0
- package/package.json +1 -1
- package/dashboard/dist/assets/Modals-DhEz9IH-.js +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as a,j as e}from"./react-vendor-C7Sl8SE7.js";import{u as C,d as O,L,I as P,i as K,a as F,m as $}from"./index-DDITAW7a.js";import{M as Q,a as V}from"./Modal-Bhdq3fQH.js";import{D as te}from"./DirBrowser-ChaxfTLA.js";import"./router-DHISdpPk.js";const Y="https://ilinkai.weixin.qq.com";function _(o){return o instanceof Error&&(o.name==="AbortError"||/aborted/i.test(o.message))}function X(o,h){return o instanceof Error&&/timed out/i.test(o.message)?h("modal.requestTimeout"):h("modal.networkError")}function ie({open:o,onClose:h}){const p=C(d=>d.state),i=C(d=>d.toast),r=C(d=>d.reloadUntil),s=C(d=>d.locale),t=a.useMemo(()=>O(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),D=a.useRef(p);D.current=p,a.useEffect(()=>{o?(G(D.current?.config.telegramBotToken||""),v(D.current?.config.telegramAllowedChatIds||""),S(!1),n(null),N(!D.current?.config.telegramBotToken)):(T.current?.abort(),T.current=null,c(!1))},[o]),a.useEffect(()=>()=>{T.current?.abort(),T.current=null},[]);const k=async()=>{if(!w.trim()){i(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")}),i(t("modal.refreshStateFailed"),!1);return}i(t("modal.tgSaved")),b=!0}catch(f){if(_(f))return;const l=X(f,t);n({ok:!1,text:"✗ "+l}),i(l,!1)}finally{T.current===d&&(T.current=null),c(!1),b&&h()}},x=()=>{T.current?.abort(),T.current=null,h()};return e.jsxs(Q,{open:o,onClose:x,children:[e.jsx(V,{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(K,{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(K,{variant:"ghost",onClick:x,children:t("modal.cancel")}),e.jsx(K,{variant:"primary",disabled:y,onClick:k,children:t(y?"modal.validating":"modal.validateSave")})]})]})}function de({open:o,onClose:h}){const p=C(k=>k.state),i=C(k=>k.toast),r=C(k=>k.reloadUntil),s=C(k=>k.locale),t=a.useMemo(()=>O(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(()=>{o?(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))},[o]),a.useEffect(()=>()=>{m.current?.abort(),m.current=null},[]);const T=async()=>{if(!w.trim()){i(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")}),i(t("modal.refreshStateFailed"),!1);return}i(t("modal.feishuSaved")),x=!0}catch(d){if(_(d))return;const b=X(d,t);c({ok:!1,text:"✗ "+b}),i(b,!1)}finally{m.current===k&&(m.current=null),S(!1),x&&h()}},D=()=>{m.current?.abort(),m.current=null,h()};return e.jsxs(Q,{open:o,onClose:D,children:[e.jsx(V,{title:t("modal.configureFeishu"),onClose:D}),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.jsx("p",{className:"ml-3 font-mono text-[11px] text-fg-5",children:t("modal.feishuGuidePerms")}),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(K,{variant:"ghost",onClick:D,children:t("modal.cancel")}),e.jsx(K,{variant:"primary",disabled:B,onClick:T,children:t(B?"modal.validating":"modal.validateSave")})]})]})}function ce({open:o,onClose:h}){const p=C(x=>x.state),i=C(x=>x.toast),r=C(x=>x.reloadUntil),s=C(x=>x.locale),t=a.useMemo(()=>O(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(()=>{o?(G(N.current?.config.weixinBaseUrl||Y),v(!1),S(""),c(""),n(null)):(m.current?.abort(),m.current=null,v(!1))},[o]),a.useEffect(()=>()=>{m.current?.abort(),m.current=null},[]);const T=()=>{m.current?.abort(),m.current=null,h()},D=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})?(i(t("modal.weixinSaved")),!0):(n({ok:!1,text:"✗ "+t("modal.refreshStateFailed")}),i(t("modal.refreshStateFailed"),!1),!1)}return!1},[r,t,i]),k=async()=>{if(!w.trim()){i(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 D(x,b.sessionKey,w.trim())}catch(b){if(_(b))return;const f=X(b,t);n({ok:!1,text:"✗ "+f}),i(f,!1)}finally{m.current===x&&(m.current=null),v(!1),d&&h()}};return e.jsxs(Q,{open:o,onClose:T,children:[e.jsx(V,{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(K,{variant:"ghost",onClick:T,children:t("modal.cancel")}),e.jsx(K,{variant:"primary",disabled:j,onClick:k,children:t(j?B?"modal.validating":"modal.weixinGeneratingQr":B?"modal.weixinRetry":"modal.weixinGenerateQr")})]})]})}function J({open:o,onClose:h,channel:p,titleKey:i,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(()=>O(c),[c]),[n,m]=a.useState({}),[N,T]=a.useState({}),[D,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(o){const g=U.current?.config||{},E={};let R=!1;for(const I of r){const M=String(g[I.key]??"").trim();E[I.key]=M,!M&&I.required!==!1&&(R=!0)}m(E),T({}),d(null),f(W&&j&&R)}else l.current?.abort(),l.current=null,k(!1)},[o,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 E=new AbortController;l.current=E,k(!0),d(null);let R=!1;try{const I=await s(g,{signal:E.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 ee=q.config||{};for(const H of r)if(String(ee[H.key]||"").trim()!==g[H.key])return!1;return!!q.setupState?.channels?.find(H=>H.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(_(I))return;const M=X(I,u);d({ok:!1,text:"✗ "+M}),S(M,!1)}finally{l.current===E&&(l.current=null),k(!1),R&&h()}};return e.jsxs(Q,{open:o,onClose:A,children:[e.jsx(V,{title:u(i),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 E=g.key,R=!!N[E],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[E]||"",onChange:M=>m(Z=>({...Z,[E]:M.target.value}))}),g.password&&e.jsx(K,{variant:"ghost",size:"sm",className:"!w-[34px] !p-0",onClick:()=>T(M=>({...M,[E]:!M[E]})),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"})]})})]})]},E)}),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(K,{variant:"ghost",onClick:A,children:u("modal.cancel")}),e.jsx(K,{variant:"primary",disabled:D,onClick:z,children:u(D?"modal.validating":"modal.validateSave")})]})]})}function ue({open:o,onClose:h}){return e.jsx(J,{open:o,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,i)=>{const r=await F.validateSlackConfig(p.slackBotToken,p.slackAppToken,i),s=r.bot?.username?"@"+r.bot.username+(r.bot.team?" ("+r.bot.team+")":""):null;return{ok:r.ok,error:r.error,identity:s}}})}function me({open:o,onClose:h}){return e.jsx(J,{open:o,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,i)=>{const r=await F.validateDiscordConfig(p.discordBotToken,i),s=r.bot?.username?"@"+r.bot.username:null;return{ok:r.ok,error:r.error,identity:s}}})}function xe({open:o,onClose:h}){return e.jsx(J,{open:o,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,i)=>{const r=await F.validateDingtalkConfig(p.dingtalkClientId,p.dingtalkClientSecret,i),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 fe({open:o,onClose:h}){return e.jsx(J,{open:o,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,i)=>{const r=await F.validateWecomConfig(p.wecomBotId,p.wecomBotSecret,i),s=r.bot?.botId?r.bot.botId:null;return{ok:r.ok,error:r.error,identity:s}}})}function he({open:o,onClose:h}){const p=C(n=>n.state),i=C(n=>n.toast),r=C(n=>n.reload),s=C(n=>n.locale),t=a.useMemo(()=>O(s),[s]),w=p?.bot?.workdir||p?.runtimeWorkdir||"",[G,j]=a.useState(""),[v,B]=a.useState(!1),[S,y]=a.useState(0);a.useEffect(()=>{o&&(j(w),y(n=>n+1))},[o,w]);const c=a.useCallback(n=>{j(n)},[]),u=async()=>{const n=G.trim();if(!n){i(t("modal.selectDirFirst"),!1);return}B(!0);try{const m=await F.switchWorkdir(n);m.ok?(await r(),i(t("modal.switchedTo")+m.workdir),h()):i(m.error||t("modal.switchFailed"),!1)}catch{i(t("modal.switchFailed"),!1)}finally{B(!1)}};return e.jsx(Q,{open:o,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(V,{title:t("modal.switchWorkdir"),onClose:h}),e.jsx(te,{initialPath:w,onSelect:c,t},S),e.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[e.jsx(K,{variant:"ghost",onClick:h,children:t("modal.cancel")}),e.jsx(K,{variant:"primary",onClick:u,children:t("modal.selectDir")})]})]})})}function pe({open:o,onClose:h,onSaved:p}){const i=C(l=>l.toast),r=C(l=>l.locale),s=a.useMemo(()=>O(r),[r]),[t,w]=a.useState(null),[G,j]=a.useState(!1),[v,B]=a.useState(!1),[S,y]=a.useState(null);a.useEffect(()=>{o&&(j(!1),y(null),F.getBrowser().then(l=>{w(l),B(!!l.browser.enabled)}).catch(()=>w(null)))},[o]);const c=t?.browser,u=!!c?.enabled,n=!!c&&u!==v,m=c?.remoteCdpUrl||"",N=!!m&&v,T=c?.profileDir||"",D=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")}),i(s("ext.browserModeSaveFailed"),!1),j(!1);return}if(!v){y({ok:!0,text:"✓ "+s("ext.browserDisabledSaved")}),i(s("ext.browserDisabledSaved")),j(!1);return}if(l?.browser.remoteCdpUrl){y({ok:!0,text:"✓ "+s("ext.browserRemoteStep")}),i(s("ext.browserRemoteStep")),j(!1);return}try{const U=await F.setupBrowser();if(!U.ok){y({ok:!1,text:"✗ "+(U.error||s("ext.browserLaunchFailed"))}),i(U.error||s("ext.browserLaunchFailed"),!1);return}w(W=>W?{...W,browser:U.browser}:{browser:U.browser}),y({ok:!0,text:"✓ "+s("ext.browserEnabledLaunched")}),i(s("ext.browserEnabledLaunched")),p?.()}catch{y({ok:!1,text:"✗ "+s("ext.browserLaunchFailed")}),i(s("ext.browserLaunchFailed"),!1)}finally{j(!1)}};return e.jsxs(Q,{open:o,onClose:h,children:[e.jsx(V,{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($,{variant:b,children:d}),c&&e.jsxs(e.Fragment,{children:[e.jsx($,{variant:u?"accent":"muted",children:s(u?"ext.enabled":"ext.disabled")}),n&&e.jsx($,{variant:"warn",children:s("ext.pendingModeChange")}),c.running&&e.jsxs($,{variant:"accent",children:[s("ext.browserOpen"),c.pid?` · PID ${c.pid}`:""]})]})]}),e.jsxs("div",{className:"mt-3",children:[e.jsx(L,{children:D}),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(K,{variant:"outline",size:"sm",disabled:!k,onClick:()=>{k&&(navigator.clipboard.writeText(k),i(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(K,{variant:"ghost",onClick:h,children:s("modal.cancel")}),e.jsx(K,{variant:"primary",disabled:G,onClick:f,children:s(G?"ext.launching":v?N?"ext.saveBrowserRemote":"ext.enableAndLaunchBrowser":"ext.saveBrowserDisabled")})]})]})}export{pe as BrowserSetupModal,xe as DingtalkModal,me as DiscordModal,de as FeishuModal,ue as SlackModal,ie as TelegramModal,fe as WeComModal,ce as WeixinModal,he as WorkdirModal};
|