@deepseekcode/cli 1.0.15 → 1.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +3751 -1068
- package/package.json +1 -1
- package/web/dist/assets/{AgentFlowView-DrQSkIct.js → AgentFlowView-D-nPVDb9.js} +1 -1
- package/web/dist/assets/{AgentsView-YGu_UDf3.js → AgentsView-DHNgV13S.js} +1 -1
- package/web/dist/assets/{AskQuestionModal-CZ_rBLKX.js → AskQuestionModal-BKkh6JlF.js} +1 -1
- package/web/dist/assets/{AuditView-DrrR2wek.js → AuditView-ZCIV7Q0I.js} +1 -1
- package/web/dist/assets/AutomationView-By6rBhla.js +1 -0
- package/web/dist/assets/ChannelConfigView-_cIgiA-O.js +8 -0
- package/web/dist/assets/ConnectorsView-BQQ_k_7I.js +1 -0
- package/web/dist/assets/{FileTreeView-B0FyGNat.js → FileTreeView-DKUEkVqn.js} +1 -1
- package/web/dist/assets/HookApprovalModal-DC_q-If8.js +1 -0
- package/web/dist/assets/HookApprovalPreview-C8fU_Umi.js +3 -0
- package/web/dist/assets/HookConfigView-DbkxVuAs.js +3 -0
- package/web/dist/assets/{InboxView-GnuBfoZI.js → InboxView-B3ddpq78.js} +1 -1
- package/web/dist/assets/ModelsView-B2N4jMxM.js +1 -0
- package/web/dist/assets/SessionGrid-CnK6naC_.js +23 -0
- package/web/dist/assets/{SettingsPanel-CSrVortM.js → SettingsPanel-czOfv9mx.js} +3 -3
- package/web/dist/assets/SkillsView-BwJowYXS.js +1 -0
- package/web/dist/assets/TemplatesTab-BB-6z4z4.js +1 -0
- package/web/dist/assets/TerminalView-D9e8fyOS.js +3 -0
- package/web/dist/assets/ToolsView-CQ3hybgP.js +1 -0
- package/web/dist/assets/{icons-CjRO1znb.js → icons-B5yCkBjC.js} +122 -102
- package/web/dist/assets/index-DVZ3Ws5S.css +1 -0
- package/web/dist/assets/index-YAnKQ1Q6.js +20 -0
- package/web/dist/assets/{markdown-hmVtvQNZ.js → markdown-D0iUI0Yw.js} +1 -1
- package/web/dist/assets/panels-DOT_5rsR.js +1 -0
- package/web/dist/assets/{react-vendor-Dp4P972X.js → react-vendor-Bxu3r3ox.js} +1 -1
- package/web/dist/assets/{state-C_jK7HTi.js → state-C80Yzgl0.js} +1 -1
- package/web/dist/index.html +6 -6
- package/web/dist/assets/AutomationView-UOaPNG7X.js +0 -1
- package/web/dist/assets/ChannelConfigView-BGoNP_fJ.js +0 -8
- package/web/dist/assets/HookApprovalModal-Cnm43UOW.js +0 -1
- package/web/dist/assets/HookConfigView-D5AmWakw.js +0 -3
- package/web/dist/assets/ModelsView-D55ftBT-.js +0 -1
- package/web/dist/assets/SessionGrid-CU4xbLh6.js +0 -21
- package/web/dist/assets/SkillsView-CEdocw75.js +0 -1
- package/web/dist/assets/TerminalView-sY_xPkMQ.js +0 -3
- package/web/dist/assets/Toast-Bmm1ZZzF.js +0 -1
- package/web/dist/assets/ToolsView-CaPjukUV.js +0 -1
- package/web/dist/assets/index-Czlzypr3.css +0 -1
- package/web/dist/assets/index-DcT4VX3U.js +0 -20
- package/web/dist/assets/panels-C0Mxu2Md.js +0 -1
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e}from"./markdown-
|
|
1
|
+
import{j as e}from"./markdown-D0iUI0Yw.js";import{r as b,ae as m,af as p,L as f,s as h,t as j,a as v}from"./icons-B5yCkBjC.js";import{c as k,d as u}from"./index-YAnKQ1Q6.js";import"./react-vendor-Bxu3r3ox.js";import"./state-C80Yzgl0.js";const y=["Orchestrator","Explorer","Architect","Coder","Tester","Reviewer","Debug","Documenter","Evaluator"],w=t=>t==="running"||t==="scheduled"?e.jsx(f,{size:10,className:"animate-spin text-accent-blue"}):t==="completed"?e.jsx(h,{size:10,className:"text-accent-green"}):t==="failed"?e.jsx(j,{size:10,className:"text-accent-red"}):e.jsx(p,{size:10,className:"text-dark-muted"}),z=t=>t==="running"||t==="scheduled"?"Running":t==="completed"?"Complete":t==="failed"?"Failed":"Idle",l=t=>t.toLowerCase();function A({agent:t}){const n=t.status==="running"||t.status==="scheduled";return e.jsxs("div",{className:`flex items-center gap-2 px-3 py-2 rounded border transition-colors ${n?"bg-accent-blue/10 border-accent-blue/40":t.status==="completed"?"bg-accent-green/10 border-accent-green/30":t.status==="failed"?"bg-accent-red/10 border-accent-red/30":"border-dark-border"}`,children:[w(t.status),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[11px] font-semibold truncate",children:t.name}),e.jsx("span",{className:"text-[9px] text-dark-muted shrink-0",children:z(t.status)})]}),t.currentTask&&e.jsx("div",{className:"text-[9px] text-dark-muted truncate mt-0.5",children:t.currentTask})]})]})}function F(){const[t,n]=b.useState(!1),r=k(s=>s.activeSessionId),d=u(s=>r?s.getAgentsForSession(r):[]),c=u(s=>r?s.getEventsForSession(r).filter(a=>a.source==="agent"||a.source==="plan").slice(0,50):[]),o=new Map(d.map(s=>[l(s.name),s])),x=y.map(s=>o.get(l(s))||o.get(l(s.replace("Orchestrator","orchestrator")))).filter(Boolean),g=d.filter(s=>!x.some(a=>a.id===s.id)),i=[...x,...g],N=i.filter(s=>s.status==="running"||s.status==="scheduled").length;return e.jsxs("div",{className:"h-full flex flex-col bg-dark-bg",children:[e.jsxs("div",{className:"shrink-0 px-3 py-2.5 border-b border-dark-border flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(m,{size:14,className:"text-accent-purple"}),e.jsx("span",{className:"text-xs font-semibold text-dark-text",children:"Agent Flow"})]}),e.jsxs("div",{className:"flex items-center gap-2 text-[9px] text-dark-muted",children:[e.jsxs("span",{className:"flex items-center gap-0.5",children:[e.jsx(p,{size:8})," Idle"]}),e.jsxs("span",{className:"flex items-center gap-0.5",children:[e.jsx(f,{size:8,className:"animate-spin text-accent-blue"})," Running"]}),e.jsxs("span",{className:"flex items-center gap-0.5",children:[e.jsx(h,{size:8,className:"text-accent-green"})," Done"]}),e.jsxs("span",{className:"flex items-center gap-0.5",children:[e.jsx(j,{size:8,className:"text-accent-red"})," Failed"]})]})]}),e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsx("div",{className:"flex-1 overflow-y-auto overflow-x-hidden custom-scrollbar",children:e.jsx("div",{className:"px-3 py-3 space-y-2",children:i.length===0?e.jsx("div",{className:"min-h-[180px] flex items-center justify-center text-center text-dark-muted text-xs",children:e.jsxs("div",{children:[e.jsx(m,{size:28,className:"mx-auto mb-2 opacity-50"}),e.jsx("div",{children:"Waiting for agent activity"})]})}):i.map(s=>e.jsx(A,{agent:s},s.id))})}),e.jsxs("div",{className:"shrink-0 border-t border-dark-border transition-all duration-300",style:{height:t?180:32},children:[e.jsxs("button",{onClick:()=>n(!t),className:"w-full flex items-center justify-between px-3 py-1.5 hover:bg-dark-hover/30 transition-colors",children:[e.jsxs("span",{className:"text-[10px] font-semibold text-dark-text flex items-center gap-1.5",children:["Event Log",e.jsx("span",{className:"px-1 py-0.5 rounded text-[8px] bg-dark-surface text-dark-muted",children:c.length}),N>0&&e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-accent-blue animate-pulse"})]}),e.jsx(v,{size:12,className:"text-dark-muted transition-transform duration-300",style:{transform:t?"rotate(180deg)":"rotate(0deg)"}})]}),t&&e.jsx("div",{className:"overflow-y-auto custom-scrollbar px-2",style:{height:146},children:c.length===0?e.jsx("div",{className:"py-4 text-[10px] text-dark-muted text-center",children:"No flow events yet."}):e.jsx("div",{className:"space-y-1 pb-2",children:c.map(s=>e.jsxs("div",{className:"px-2 py-1.5 rounded border border-dark-border bg-dark-surface",children:[e.jsxs("div",{className:"flex items-center gap-1 text-[9px]",children:[e.jsx("span",{className:"font-medium text-dark-text truncate",children:s.title||s.type}),e.jsx("span",{className:"text-dark-muted/70 ml-auto",children:new Date(s.timestamp).toLocaleTimeString()})]}),s.message&&e.jsx("p",{className:"text-[8px] text-dark-muted/80 mt-0.5 truncate",children:s.message}),e.jsx("div",{className:"text-[8px] text-dark-muted/60 mt-0.5",children:s.source})]},s.id))})})]})]})]})}export{F as AgentFlowView,F as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e}from"./markdown-
|
|
1
|
+
import{j as e}from"./markdown-D0iUI0Yw.js";import{r as l,am as i,L as o,s as u,m as p,an as h}from"./icons-B5yCkBjC.js";import{c as f,a as j,d as n}from"./index-YAnKQ1Q6.js";import"./react-vendor-Bxu3r3ox.js";import"./state-C80Yzgl0.js";const N={idle:"bg-dark-hover text-dark-muted",scheduled:"bg-accent-blue/15 text-accent-blue",running:"bg-accent-blue/15 text-accent-blue",completed:"bg-accent-green/15 text-accent-green",failed:"bg-accent-red/15 text-accent-red"},b=({status:t})=>t==="running"?e.jsx(o,{size:14,className:"text-accent-blue animate-spin"}):t==="completed"?e.jsx(u,{size:14,className:"text-accent-green"}):t==="failed"?e.jsx(p,{size:14,className:"text-accent-red"}):e.jsx(h,{size:14,className:"text-dark-muted"}),g=t=>t==="workflow"?"Goal":t==="agent"?"Plan/Act":t;function A(){const t=f(s=>s.activeSessionId),[x,m]=l.useState([]);l.useEffect(()=>{j.agents.list().then(s=>{s.success&&Array.isArray(s.data)&&m(s.data.map(r=>({id:r.id,name:r.name,status:r.state==="busy"?"running":"idle",currentTask:"",phase:"",tokens:0,error:"",source:"agent"})))})},[]);const d=n(s=>t?s.getAgentsForSession(t):[]),c=n(s=>t?s.getEventsForSession(t).slice(0,8):[]),a=d.length>0?d:x;return e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("h2",{className:"text-lg font-semibold flex items-center gap-2",children:[e.jsx(i,{size:20}),"Agent Workspace",e.jsxs("span",{className:"text-sm font-normal text-dark-muted",children:["(",a.length,")"]})]}),e.jsx("div",{className:"text-xs text-dark-muted",children:t?`Session ${t}`:"No active session"})]}),e.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-[minmax(0,1fr)_320px] gap-4 min-h-0 flex-1",children:[e.jsx("div",{className:"overflow-y-auto custom-scrollbar border border-dark-border rounded bg-dark-surface",children:a.length>0?e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"sticky top-0 bg-dark-bg text-dark-muted border-b border-dark-border",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left font-medium px-3 py-2",children:"Agent"}),e.jsx("th",{className:"text-left font-medium px-3 py-2",children:"Status"}),e.jsx("th",{className:"text-left font-medium px-3 py-2",children:"Task"}),e.jsx("th",{className:"text-left font-medium px-3 py-2",children:"Source"}),e.jsx("th",{className:"text-right font-medium px-3 py-2",children:"Tokens"}),e.jsx("th",{className:"text-left font-medium px-3 py-2",children:"Error"})]})}),e.jsx("tbody",{children:a.map(s=>e.jsxs("tr",{className:"border-b border-dark-border/70 last:border-b-0",children:[e.jsxs("td",{className:"px-3 py-2",children:[e.jsx("div",{className:"font-medium",children:s.name}),e.jsx("div",{className:"text-xs text-dark-muted font-mono",children:s.id})]}),e.jsx("td",{className:"px-3 py-2",children:e.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-1 rounded text-xs ${N[s.status]}`,children:[e.jsx(b,{status:s.status}),s.status]})}),e.jsxs("td",{className:"px-3 py-2 max-w-[320px]",children:[e.jsx("div",{className:"truncate",children:s.currentTask||"-"}),s.phase&&e.jsx("div",{className:"text-xs text-dark-muted",children:s.phase})]}),e.jsx("td",{className:"px-3 py-2 text-dark-muted",children:g(s.source)}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:s.tokens??0}),e.jsx("td",{className:"px-3 py-2 text-accent-red text-xs max-w-[220px] truncate",children:s.error||"-"})]},s.id))})]}):e.jsx("div",{className:"h-full min-h-[240px] flex items-center justify-center text-center text-dark-muted",children:e.jsxs("div",{children:[e.jsx(i,{size:40,className:"mx-auto mb-3 opacity-50"}),e.jsx("p",{children:"No agent activity yet"}),e.jsx("p",{className:"text-xs mt-1",children:"Plan, Act, and Goal agents will appear here for the active session."})]})})}),e.jsxs("div",{className:"border border-dark-border rounded bg-dark-surface overflow-hidden flex flex-col min-h-[240px]",children:[e.jsx("div",{className:"px-3 py-2 border-b border-dark-border text-xs font-semibold",children:"Recent Events"}),e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto custom-scrollbar",children:c.length===0?e.jsx("div",{className:"text-xs text-dark-muted p-3",children:"No events recorded."}):e.jsx("div",{className:"divide-y divide-dark-border/70",children:c.map(s=>e.jsxs("div",{className:"px-3 py-2 text-xs",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium truncate",children:s.title||s.type}),e.jsx("span",{className:"ml-auto text-dark-muted",children:new Date(s.timestamp).toLocaleTimeString()})]}),s.message&&e.jsx("div",{className:"mt-1 text-dark-muted line-clamp-2",children:s.message}),e.jsx("div",{className:"mt-1 text-[10px] text-dark-muted",children:s.source})]},s.id))})})]})]})]})}export{A as AgentsView,A as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as t}from"./markdown-
|
|
1
|
+
import{j as t}from"./markdown-D0iUI0Yw.js";import{r,ai as _,aS as A,X as Q}from"./icons-B5yCkBjC.js";import{w as T,M as D}from"./index-YAnKQ1Q6.js";import"./react-vendor-Bxu3r3ox.js";import"./state-C80Yzgl0.js";const v="其他(我来说明)";function H({isOpen:f,onClose:w}){const[s,C]=r.useState(null),[$,N]=r.useState(-1),[m,E]=r.useState(new Set),[k,b]=r.useState(""),[h,x]=r.useState(!1),[l,p]=r.useState(!1),I=r.useRef(null);r.useEffect(()=>{if(f){const e=window.__pendingQuestion;e&&(C(e),N(e.multiSelect?-1:0),E(new Set),b(""),x(!1),p(!1))}},[f]),r.useEffect(()=>{const e=()=>{p(!0),setTimeout(()=>{w(),C(null),p(!1)},300)};return window.addEventListener("ask-question-dismiss",e),()=>window.removeEventListener("ask-question-dismiss",e)},[w]);const o=(s==null?void 0:s.options)||[],y=o.some(e=>e.label===v),c=r.useMemo(()=>{const e=y?[...o]:[...o,{label:v,description:"输入自定义答案"}];return s!=null&&s.multiSelect&&e.push({label:`确认选择 (${m.size} 项)`,description:"Ctrl+Enter 确认提交"}),e},[o,y,s==null?void 0:s.multiSelect,m.size]),j=r.useMemo(()=>y?o.findIndex(e=>e.label===v):o.length,[o,y]),d=r.useCallback((e,a)=>{l||!s||(p(!0),T.send({type:"question_answer",data:JSON.stringify({questionId:s.questionId,answer:e,selectedOptions:a})}))},[l,s]),L=r.useCallback(e=>{if(l||!s)return;if(s.multiSelect&&e===c.length-1){const n=[...m].map(i=>{var g;return((g=c[i])==null?void 0:g.label)||""});d(n.join(", "),n);return}if(e===j){N(e),x(!0),setTimeout(()=>{var n;return(n=I.current)==null?void 0:n.focus()},100);return}if(s.multiSelect){E(n=>{const i=new Set(n);return i.has(e)?i.delete(e):i.add(e),i});return}const a=c[e];a&&d(a.label,[a.label])},[l,s,c,m,j,d]),M=r.useCallback(()=>{l||d(k||"(用户未输入)")},[l,k,d]),z=r.useCallback(()=>{if(!l){if(h){x(!1),b("");return}d("(cancelled)")}},[l,h,d]),R=r.useCallback(()=>{l||z()},[l,z]);return!f||!s?null:t.jsx(D,{isOpen:f,onClose:R,title:s.header||"请回答",size:"md",children:t.jsxs("div",{className:"flex flex-col gap-4",children:[t.jsx("div",{className:"text-sm text-gray-700 dark:text-gray-300 leading-relaxed",children:s.question}),t.jsx("div",{className:"flex flex-col gap-2 max-h-64 overflow-y-auto",children:c.map((e,a)=>{const n=$===a,i=m.has(a),g=a===j,S=s.multiSelect&&a===c.length-1;return t.jsxs("div",{children:[t.jsxs("button",{type:"button",className:`w-full text-left px-3 py-2 rounded-md text-sm transition-colors ${S?"bg-blue-50 dark:bg-blue-900/20 border border-blue-300 dark:border-blue-700 hover:bg-blue-100 dark:hover:bg-blue-900/30":n?"bg-blue-50 dark:bg-blue-900/20 border border-blue-300 dark:border-blue-700":"bg-gray-50 dark:bg-gray-800 border border-gray-200 dark:border-gray-700 hover:bg-gray-100 dark:hover:bg-gray-750"}`,onClick:()=>L(a),disabled:l,children:[t.jsxs("div",{className:"flex items-center gap-2",children:[s.multiSelect&&!S&&t.jsx("span",{className:`w-4 h-4 rounded border flex items-center justify-center text-[10px] ${i?"bg-blue-600 border-blue-600 text-white":"border-gray-400 dark:border-gray-500"}`,children:i&&t.jsx(_,{size:10})}),S?t.jsx("span",{className:"font-medium text-blue-700 dark:text-blue-300",children:e.label}):t.jsxs(t.Fragment,{children:[t.jsxs("span",{className:`font-medium ${n?"text-blue-700 dark:text-blue-300":"text-gray-800 dark:text-gray-200"}`,children:[a+1,". ",e.label]}),g&&t.jsx("span",{className:"text-xs text-gray-400",children:"(自定义)"})]})]}),e.description&&t.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400 mt-0.5 ml-6",children:e.description})]}),g&&n&&h&&t.jsxs("div",{className:"mt-2 ml-4",children:[t.jsx("textarea",{ref:I,className:"w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 focus:outline-none focus:ring-2 focus:ring-blue-500 resize-none",rows:3,value:k,onChange:u=>b(u.target.value),onKeyDown:u=>{u.key==="Enter"&&!u.shiftKey&&(u.preventDefault(),M()),u.key==="Escape"&&(x(!1),b(""))},placeholder:"输入您的回答...",disabled:l,autoFocus:!0}),t.jsxs("div",{className:"flex gap-2 mt-1",children:[t.jsxs("button",{type:"button",className:"inline-flex items-center gap-1 px-3 py-1 text-xs font-medium text-white bg-blue-600 rounded-md hover:bg-blue-700 disabled:opacity-50",onClick:M,disabled:l,children:[t.jsx(A,{size:12}),"提交"]}),t.jsxs("button",{type:"button",className:"inline-flex items-center gap-1 px-3 py-1 text-xs font-medium text-gray-600 dark:text-gray-400 bg-gray-100 dark:bg-gray-700 rounded-md hover:bg-gray-200 dark:hover:bg-gray-600",onClick:()=>{x(!1),b("")},children:[t.jsx(Q,{size:12}),"取消"]})]})]})]},`opt-${a}`)})}),t.jsx("div",{className:"text-xs text-gray-400 dark:text-gray-500",children:l?t.jsx("span",{children:"提交中..."}):h?t.jsx("span",{children:"Enter 提交,Shift+Enter 换行,Esc 取消"}):s.multiSelect?t.jsx("span",{children:"点击切换选择,点击「确认选择」提交"}):t.jsx("span",{children:"点击选项确认选择,Esc 取消"})})]})})}export{H as AskQuestionModal};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as t}from"./markdown-
|
|
1
|
+
import{j as t}from"./markdown-D0iUI0Yw.js";import{r as c,S as j,R as v,m as N,C as y,b as w,aX as S,aY as C,aW as M}from"./icons-B5yCkBjC.js";import{E as z}from"./index-YAnKQ1Q6.js";import"./react-vendor-Bxu3r3ox.js";import"./state-C80Yzgl0.js";const u=20;function E(s){return s==="allow"?{cls:"bg-accent-green/20 text-accent-green",Icon:S,label:"允许"}:s==="deny"?{cls:"bg-accent-red/20 text-accent-red",Icon:C,label:"拒绝"}:{cls:"bg-accent-yellow/20 text-accent-yellow",Icon:M,label:"待定"}}function $(){const{audit:s,auditTotal:h,fetchAudit:i,loading:p,error:b}=z(),[n,g]=c.useState(""),[l,k]=c.useState("all"),[r,d]=c.useState(0),x=Math.max(1,Math.ceil(h/u));c.useEffect(()=>{i({tool:n||void 0,decision:l==="all"?void 0:l,page:r,pageSize:u})},[i,n,l,r]);const f=c.useMemo(()=>{var a;const e={};for(const o of s){const m=e[a=o.tool]??(e[a]={allow:0,deny:0,ask:0});m[o.decision]+=1}return e},[s]);return t.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden p-4",children:[t.jsxs("div",{className:"flex items-center justify-between mb-4",children:[t.jsxs("h2",{className:"text-lg font-semibold flex items-center gap-2",children:[t.jsx(j,{size:20,className:"text-accent-blue"}),"审计历史",t.jsxs("span",{className:"text-xs text-dark-muted font-normal",children:["(",h," 条)"]})]}),t.jsx("button",{onClick:()=>void i({tool:n||void 0,decision:l==="all"?void 0:l,page:r,pageSize:u}),className:"p-2 rounded-lg hover:bg-dark-hover text-dark-muted",title:"刷新",children:t.jsx(v,{size:16})})]}),t.jsxs("div",{className:"flex gap-2 mb-3 flex-wrap items-center",children:[t.jsx("input",{value:n,onChange:e=>{g(e.target.value),d(0)},placeholder:"按工具过滤(如 write_file)",className:"w-52 px-3 py-1.5 rounded-lg bg-dark-bg border border-dark-border text-sm focus:outline-none focus:border-accent-blue"}),t.jsx("div",{className:"flex rounded-lg bg-dark-hover p-0.5 text-sm",children:["all","allow","deny","ask"].map(e=>t.jsx("button",{onClick:()=>{k(e),d(0)},className:`px-3 py-1 rounded-md transition-colors ${l===e?"bg-accent-blue/20 text-accent-blue":"text-dark-muted hover:text-dark-text"}`,children:e==="all"?"全部":e==="allow"?"允许":e==="deny"?"拒绝":"待定"},e))})]}),t.jsx("div",{className:"flex flex-wrap gap-1 mb-3",children:Object.entries(f).slice(0,12).map(([e,a])=>t.jsxs("button",{onClick:()=>{g(e),d(0)},className:`px-2 py-0.5 rounded text-xs ${n===e?"bg-accent-blue/20 text-accent-blue":"bg-dark-hover text-dark-muted hover:text-dark-text"}`,children:[e," · ",t.jsx("span",{className:"text-accent-green",children:a.allow}),"/",t.jsx("span",{className:"text-accent-red",children:a.deny}),"/",t.jsx("span",{className:"text-accent-yellow",children:a.ask})]},e))}),b&&t.jsxs("div",{className:"mb-3 p-3 rounded-lg bg-accent-red/10 text-accent-red text-sm flex items-center gap-2",children:[t.jsx(N,{size:16})," ",b]}),t.jsxs("div",{className:"flex-1 overflow-y-auto border border-dark-border rounded-lg bg-dark-surface",children:[p&&s.length===0&&t.jsx("p",{className:"text-dark-muted text-center py-8",children:"加载中..."}),!p&&s.length===0&&t.jsx("p",{className:"text-dark-muted text-center py-8",children:"暂无审计记录"}),s.map(e=>{const{cls:a,Icon:o,label:m}=E(e.decision);return t.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-dark-border last:border-b-0 hover:bg-dark-hover/50",children:[t.jsxs("span",{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs shrink-0 ${a}`,children:[t.jsx(o,{size:12})," ",m]}),t.jsx("code",{className:"text-xs text-accent-blue shrink-0",children:e.tool}),e.argsMasked&&Object.keys(e.argsMasked).length>0&&t.jsx("span",{className:"text-[11px] text-dark-muted truncate flex-1",children:JSON.stringify(e.argsMasked).slice(0,120)}),t.jsxs("span",{className:"text-[11px] text-dark-muted shrink-0 hidden md:inline",children:[e.approvedBy||"auto"," · ",e.risk||""," · ",e.durationMs!=null?`${e.durationMs}ms`:""]}),t.jsx("span",{className:"text-[11px] text-dark-muted shrink-0",children:new Date(e.ts).toLocaleString()})]},e.id)})]}),t.jsxs("div",{className:"flex items-center justify-end gap-2 mt-3",children:[t.jsx("button",{onClick:()=>d(e=>Math.max(0,e-1)),disabled:r===0,className:"p-1.5 rounded-lg bg-dark-hover text-dark-muted disabled:opacity-30 hover:text-dark-text",children:t.jsx(y,{size:14})}),t.jsxs("span",{className:"text-xs text-dark-muted",children:["第 ",r+1," / ",x," 页"]}),t.jsx("button",{onClick:()=>d(e=>Math.min(x-1,e+1)),disabled:r>=x-1,className:"p-1.5 rounded-lg bg-dark-hover text-dark-muted disabled:opacity-30 hover:text-dark-text",children:t.jsx(w,{size:14})})]})]})}export{$ as AuditView};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as e}from"./markdown-D0iUI0Yw.js";import{r as a,h as k,R as $,P as I,m as T,aR as D,ao as L,a4 as O,aw as J,X as U}from"./icons-B5yCkBjC.js";import{E as B}from"./index-YAnKQ1Q6.js";import"./react-vendor-Bxu3r3ox.js";import"./state-C80Yzgl0.js";function H(){const{automations:r,runsByAutomation:c,fetchAutomations:n,createAutomation:v,deleteAutomation:N,toggleAutomation:y,runAutomation:w,fetchRuns:C,error:l}=B(),[S,i]=a.useState(!1),[x,A]=a.useState(null),[m,u]=a.useState(""),[p,b]=a.useState(""),[o,h]=a.useState("0 9 * * *"),[g,f]=a.useState("");a.useEffect(()=>{n()},[n]);const z=async t=>{const s=g.trim();if(!s)return;const[d,...R]=s.split(/\s+/),j=R.join(" ");d&&j&&(await fetch(`/api/automations/${encodeURIComponent(t)}/permissions`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({tool:d,target:j})})).ok&&(f(""),await n())},E=async(t,s)=>{(await fetch(`/api/automations/${encodeURIComponent(t)}/permissions`,{method:"DELETE",headers:{"content-type":"application/json"},body:JSON.stringify({entry:s})})).ok&&await n()},P=async t=>{const s=x===t?null:t;A(s),s&&await C(t)};return e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("h2",{className:"text-lg font-semibold flex items-center gap-2",children:[e.jsx(k,{size:20,className:"text-accent-blue"}),"定时自动化",e.jsxs("span",{className:"text-xs text-dark-muted font-normal",children:["(",r.length,")"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>void n(),className:"p-2 rounded-lg hover:bg-dark-hover text-dark-muted",title:"刷新",children:e.jsx($,{size:16})}),e.jsxs("button",{onClick:()=>i(t=>!t),className:"flex items-center gap-1 px-3 py-1.5 rounded-lg bg-accent-blue/20 text-accent-blue hover:bg-accent-blue/30 text-sm font-medium",children:[e.jsx(I,{size:16})," 新建"]})]})]}),l&&e.jsxs("div",{className:"mb-3 p-3 rounded-lg bg-accent-red/10 text-accent-red text-sm flex items-center gap-2",children:[e.jsx(T,{size:16})," ",l]}),S&&e.jsxs("div",{className:"mb-4 rounded-lg border border-dark-border bg-dark-surface p-4 space-y-3",children:[e.jsx("input",{value:m,onChange:t=>u(t.target.value),placeholder:"名称(如:每早 9 点汇总 Git 状态)",className:"w-full px-3 py-2 rounded-lg bg-dark-bg border border-dark-border text-sm focus:outline-none focus:border-accent-blue"}),e.jsx("textarea",{value:p,onChange:t=>b(t.target.value),placeholder:"指令(agent 每次触发时执行的内容)",rows:3,className:"w-full px-3 py-2 rounded-lg bg-dark-bg border border-dark-border text-sm focus:outline-none focus:border-accent-blue resize-none"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{value:o,onChange:t=>h(t.target.value),placeholder:"cron(5 段,如 0 9 * * *)",className:"flex-1 px-3 py-2 rounded-lg bg-dark-bg border border-dark-border text-sm focus:outline-none focus:border-accent-blue"}),e.jsx("button",{onClick:async()=>{await v({name:m,instructions:p,schedule:{kind:"cron",cron:o}})&&(u(""),b(""),i(!1))},className:"px-4 py-2 rounded-lg bg-accent-blue text-white text-sm font-medium hover:bg-accent-blue/80",children:"创建"})]}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:[["0 9 * * *","每天 9:00"],["0 9 * * 1-5","工作日 9:00"],["*/30 * * * *","每 30 分钟"]].map(([t,s])=>e.jsxs("button",{onClick:()=>h(t),className:`px-2 py-1 rounded text-xs ${o===t?"bg-accent-blue/20 text-accent-blue":"bg-dark-hover text-dark-muted hover:text-dark-text"}`,children:[s," (",t,")"]},t))})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto space-y-2",children:[r.length===0&&e.jsx("p",{className:"text-dark-muted text-center py-8",children:"还没有定时自动化。新建一个,让 agent 无人值守干活。"}),r.map(t=>e.jsxs("div",{className:"rounded-lg border border-dark-border bg-dark-surface",children:[e.jsxs("div",{className:"flex items-center justify-between p-3",children:[e.jsxs("button",{onClick:()=>void P(t.id),className:"flex items-center gap-2 min-w-0 text-left",children:[e.jsx(k,{size:16,className:"text-accent-blue shrink-0"}),e.jsx("span",{className:"font-medium text-sm truncate",children:t.name}),e.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded shrink-0 ${t.status==="enabled"?"bg-accent-green/20 text-accent-green":"bg-dark-hover text-dark-muted"}`,children:t.status})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsxs("span",{className:"text-xs text-dark-muted hidden lg:inline mr-1",children:[t.schedule.kind==="cron"?t.schedule.cron:t.schedule.fireAt,t.nextRunAt?` · ${new Date(t.nextRunAt).toLocaleString()}`:""]}),e.jsx("button",{onClick:()=>void y(t.id,t.status!=="enabled"),className:"p-1.5 rounded-lg hover:bg-dark-hover text-dark-muted",title:t.status==="enabled"?"停用":"启用",children:e.jsx(D,{size:15})}),e.jsx("button",{onClick:()=>void w(t.id),className:"p-1.5 rounded-lg hover:bg-dark-hover text-accent-green",title:"手动触发",children:e.jsx(L,{size:15})}),e.jsx("button",{onClick:()=>void N(t.id),className:"p-1.5 rounded-lg hover:bg-dark-hover text-accent-red",title:"删除",children:e.jsx(O,{size:15})})]})]}),x===t.id&&e.jsxs("div",{className:"px-3 pb-3 space-y-3 border-t border-dark-border pt-3",children:[e.jsx("p",{className:"text-xs text-dark-muted whitespace-pre-wrap",children:t.instructions}),e.jsxs("div",{children:[e.jsxs("h4",{className:"text-xs font-semibold text-dark-muted mb-1 flex items-center gap-1",children:[e.jsx(J,{size:12})," 运行历史"]}),(c[t.id]||[]).length===0&&e.jsx("p",{className:"text-xs text-dark-muted",children:"暂无运行记录"}),(c[t.id]||[]).slice(0,10).map(s=>e.jsxs("div",{className:"flex items-center gap-2 text-xs py-1",children:[e.jsx("span",{className:`px-1.5 py-0.5 rounded ${s.status==="ok"?"bg-accent-green/20 text-accent-green":s.status==="error"?"bg-accent-red/20 text-accent-red":"bg-accent-yellow/20 text-accent-yellow"}`,children:s.status}),e.jsx("span",{className:"text-dark-muted",children:new Date(s.startedAt).toLocaleString()}),e.jsxs("span",{className:"text-dark-muted truncate flex-1",children:["#",s.id.slice(0,8)," · ",s.trigger]})]},s.id))]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs font-semibold text-dark-muted mb-1",children:"作用域放行(tool target)"}),t.permissions.length===0&&e.jsx("p",{className:"text-xs text-dark-muted",children:"无。写操作将停放进 Inbox 等待批准。"}),e.jsx("div",{className:"flex flex-wrap gap-1 mb-1",children:t.permissions.map(s=>e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded bg-accent-blue/10 text-accent-blue text-xs",children:[s,e.jsx("button",{onClick:()=>void E(t.id,s),className:"hover:text-accent-red",children:e.jsx(U,{size:12})})]},s))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{value:g,onChange:s=>f(s.target.value),placeholder:"如:write_file docs/report.md",className:"flex-1 px-2 py-1.5 rounded-lg bg-dark-bg border border-dark-border text-xs focus:outline-none focus:border-accent-blue"}),e.jsx("button",{onClick:()=>void z(t.id),className:"px-3 py-1.5 rounded-lg bg-dark-hover text-dark-muted hover:text-dark-text text-xs",children:"添加"})]})]})]})]},t.id))]})]})}export{H as AutomationView};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import{j as i}from"./markdown-D0iUI0Yw.js";import{r as v,aT as Pe,aa as Re,a9 as Le,J as Xe,P as ee,aU as ue,a4 as _e,$ as et,R as tt}from"./icons-B5yCkBjC.js";import{z as fe,M as nt,a as be,t as te}from"./index-YAnKQ1Q6.js";import"./react-vendor-Bxu3r3ox.js";import"./state-C80Yzgl0.js";const we=new Set(["mattermost","msteams","googlechat","irc","imessage","sms","nextcloud-talk","nostr","synology-chat","tlon","twitch","zalo","zalouser","clickclack","raft","qa-channel"]),ye={wechat:"微信",feishu:"飞书",dingtalk:"钉钉",telegram:"Telegram",discord:"Discord",slack:"Slack",signal:"Signal",whatsapp:"WhatsApp",line:"LINE",qqbot:"QQ Bot",matrix:"Matrix",mattermost:"Mattermost",msteams:"Teams",googlechat:"Google Chat",irc:"IRC",imessage:"iMessage",sms:"SMS","nextcloud-talk":"Nextcloud Talk",nostr:"Nostr","synology-chat":"Synology Chat",tlon:"Tlon",twitch:"Twitch",zalo:"Zalo",zalouser:"ZaloUser",clickclack:"ClickClack",raft:"Raft","qa-channel":"QA"},Ne={wechat:"💬",feishu:"📘",dingtalk:"🔔",telegram:"✈️",discord:"🎮",slack:"💼",signal:"🔒",whatsapp:"📱",line:"🟢",qqbot:"🐧",matrix:"🧩",mattermost:"🏢",msteams:"📋",googlechat:"📧",irc:"💻",imessage:"✉️",sms:"📨"},Ce=[{label:"即时通讯",types:["wechat","feishu","dingtalk"]},{label:"国际主流",types:["telegram","discord","slack","signal","whatsapp"]},{label:"东亚",types:["line","qqbot"]},{label:"协作平台",types:["matrix","mattermost","msteams","googlechat"]},{label:"经典协议",types:["irc","imessage","sms"]},{label:"其他",types:["nextcloud-talk","nostr","synology-chat","tlon","twitch","zalo","zalouser"]},{label:"内置",types:["clickclack","raft","qa-channel"]}];function rt(){const{channels:t,selectedType:e,selectType:o}=fe(),r=v.useMemo(()=>{const n=new Map;for(const s of t){const a=n.get(s.type)??{count:0,connected:0};n.set(s.type,{count:a.count+1,connected:a.connected+(s.connected?1:0)})}return n},[t]);return i.jsxs("div",{className:"flex flex-col h-full min-h-0 border-r border-dark-border bg-dark-surface",children:[i.jsxs("div",{className:"shrink-0 px-4 py-3 border-b border-dark-border",children:[i.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-dark-muted",children:"频道列表"}),i.jsx("p",{className:"text-[11px] text-dark-muted mt-0.5",children:t.length>0?`${t.length} 个已配置`:"点击下方频道开始配置"})]}),i.jsxs("div",{className:"flex-1 overflow-y-auto custom-scrollbar",children:[Ce.map(n=>{const s=n.types.filter(a=>r.has(a));return s.length===0?null:i.jsxs("div",{children:[i.jsx("div",{className:"sticky top-0 bg-dark-surface/95 backdrop-blur px-4 py-1.5 text-[10px] font-semibold uppercase tracking-wider text-dark-muted/60",children:n.label}),s.map(a=>{const l=r.get(a);return i.jsx(ke,{label:ye[a]??a,icon:Ne[a]??"📡",isSelected:e===a,experimental:we.has(a),info:l,onClick:()=>o(a)},a)})]},n.label)}),(()=>{const n=Ce.flatMap(s=>s.types).filter(s=>!r.has(s));return n.length===0?null:i.jsxs("div",{children:[i.jsx("div",{className:"sticky top-0 bg-dark-surface/95 backdrop-blur px-4 py-1.5 text-[10px] font-semibold uppercase tracking-wider text-dark-muted/60",children:"未配置"}),n.map(s=>i.jsx(ke,{label:ye[s]??s,icon:Ne[s]??"📡",isSelected:e===s,experimental:we.has(s),onClick:()=>o(s)},s))]})})()]})]})}function ke({label:t,icon:e,isSelected:o,experimental:r,info:n,onClick:s}){return i.jsxs("button",{onClick:s,className:`w-full flex items-center gap-2.5 px-4 py-2.5 text-left transition-colors hover:bg-dark-hover ${o?"bg-accent-blue/10 border-l-2 border-accent-blue":"border-l-2 border-transparent"}`,children:[i.jsx("span",{className:"text-lg shrink-0 w-7 h-7 flex items-center justify-center rounded-md bg-dark-bg",children:e}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-1.5",children:[i.jsx("span",{className:"text-sm font-medium text-dark-text truncate",children:t}),r&&i.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[9px] text-yellow-500 bg-yellow-500/10 px-1 py-0.5 rounded shrink-0",title:"实验性实现,功能不完整",children:[i.jsx(Pe,{className:"w-2.5 h-2.5"})," 实验"]}),n&&i.jsx("span",{className:"text-[10px] text-dark-muted bg-dark-hover px-1.5 py-0.5 rounded shrink-0",children:n.count})]}),i.jsx("div",{className:"flex items-center gap-1 mt-0.5",children:n?n.connected>0?i.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-green-400",children:[i.jsx(Re,{className:"w-3 h-3"}),n.connected===n.count?"已连接":`${n.connected}/${n.count} 已连接`]}):i.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-dark-muted",children:[i.jsx(Le,{className:"w-3 h-3"}),"未连接"]}):i.jsx("span",{className:"text-[11px] text-dark-muted",children:"未配置"})})]})]})}const je=new Set(["mattermost","msteams","googlechat","irc","imessage","sms","nextcloud-talk","nostr","synology-chat","tlon","twitch","zalo","zalouser","clickclack","raft","qa-channel"]),Ee={wechat:"微信",feishu:"飞书",dingtalk:"钉钉",telegram:"Telegram",discord:"Discord",slack:"Slack",signal:"Signal",whatsapp:"WhatsApp",line:"LINE",qqbot:"QQ Bot",matrix:"Matrix",mattermost:"Mattermost",msteams:"Microsoft Teams",googlechat:"Google Chat",irc:"IRC",imessage:"iMessage",sms:"SMS","nextcloud-talk":"Nextcloud Talk",nostr:"Nostr","synology-chat":"Synology Chat",tlon:"Tlon",twitch:"Twitch",zalo:"Zalo",zalouser:"ZaloUser",clickclack:"ClickClack",raft:"Raft","qa-channel":"QA Channel"},ve={wechat:"💬",feishu:"📘",dingtalk:"🔔",telegram:"✈️",discord:"🎮",slack:"💼",signal:"🔒",whatsapp:"📱",line:"🟢",qqbot:"🐧",matrix:"🧩",mattermost:"🏢",msteams:"📋",googlechat:"📧",irc:"💻",imessage:"✉️",sms:"📨"},L={name:"",type:"wechat",appId:"",appSecret:"",token:"",encodingAESKey:"",enabled:!0};function st(){const{channels:t,selectedType:e,create:o,update:r,remove:n,toggle:s,error:a,clearError:l,openQr:c,load:u}=fe(),d=v.useMemo(()=>e?t.filter(N=>N.type===e):[],[t,e]),[y,g]=v.useState(""),[h,x]=v.useState(L),[C,j]=v.useState(!1),p=y==="__new__",m=v.useMemo(()=>p?null:d.find(N=>N.id===y)??null,[d,y,p]);v.useEffect(()=>{g(""),x(L),j(!1),l()},[e]),v.useEffect(()=>{e==="wechat"&&d.length===0&&c(null)},[e,d.length,c]),v.useEffect(()=>{m?x({name:m.name,type:m.type,appId:m.appId||"",appSecret:"",token:"",encodingAESKey:m.encodingAESKey||"",enabled:m.enabled}):p&&x(N=>({...N,type:e}))},[y]);const b=(N,A)=>{l(),x(z=>({...z,[N]:A}))},f=N=>{g(N),l()},w=()=>{g("__new__"),x({...L,type:e}),l()},k=()=>{g(""),x(L),l()},E=async()=>{if(!h.name.trim())return;j(!0);const N=m?await r(m.id,h):await o(h);j(!1),N&&(g(""),x(L))},S=async N=>{if(!confirm("确认删除该频道?"))return;await n(N)&&y===N&&(g(""),x(L))},B=(N,A)=>{s(N,A)};return e?i.jsxs("div",{className:"flex-1 flex flex-col min-h-0 overflow-hidden",children:[i.jsx("div",{className:"shrink-0 px-6 py-4 border-b border-dark-border",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("span",{className:"text-2xl",children:ve[e]??"📡"}),i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("h2",{className:"font-semibold text-base text-dark-text",children:Ee[e]??e}),je.has(e)&&i.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[10px] text-yellow-500 bg-yellow-500/10 px-1.5 py-0.5 rounded",title:"实验性实现,功能不完整",children:[i.jsx(Pe,{className:"w-3 h-3"})," 实验性"]})]}),i.jsx("p",{className:"text-xs text-dark-muted mt-0.5",children:d.length>0?`${d.length} 个配置实例`:"尚未配置"}),je.has(e)&&i.jsx("p",{className:"text-[10px] text-yellow-600/70 mt-1",children:"此频道为基础适配器封装,支持基础消息收发,部分高级功能可能不完整"})]})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("button",{onClick:()=>u(),className:"text-xs px-3 py-1.5 rounded-lg border border-dark-border text-dark-muted hover:text-dark-text hover:bg-dark-hover transition-colors",children:"刷新"}),i.jsxs("button",{onClick:w,className:"flex items-center gap-1.5 text-xs px-3 py-1.5 rounded-lg bg-accent-blue hover:bg-accent-blue/90 text-white transition-colors",children:[i.jsx(ee,{className:"w-3.5 h-3.5"})," 新建实例"]})]})]})}),a&&i.jsxs("div",{className:"shrink-0 mx-6 mt-3 bg-red-500/10 border border-red-500/40 text-red-400 px-3 py-2 rounded-lg text-sm flex justify-between items-center",children:[i.jsx("span",{children:a}),i.jsx("button",{onClick:l,className:"text-red-400 hover:text-red-300",children:i.jsx("span",{className:"w-4 h-4 inline-flex items-center justify-center",children:"×"})})]}),i.jsxs("div",{className:"flex-1 overflow-y-auto custom-scrollbar p-6",children:[d.length>1&&!p&&i.jsxs("div",{className:"mb-4",children:[i.jsx("label",{className:"block text-xs text-dark-muted mb-1.5",children:"选择实例"}),i.jsxs("div",{className:"flex flex-wrap gap-2",children:[d.map(N=>i.jsxs("button",{onClick:()=>f(N.id),className:`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs border transition-colors ${y===N.id?"bg-accent-blue/10 border-accent-blue/40 text-accent-blue":"border-dark-border text-dark-muted hover:text-dark-text hover:bg-dark-hover"}`,children:[i.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${N.connected?"bg-green-500":"bg-gray-500"}`}),N.name]},N.id)),i.jsxs("button",{onClick:w,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs border border-dashed border-dark-border text-dark-muted hover:text-dark-text hover:bg-dark-hover transition-colors",children:[i.jsx(ee,{className:"w-3 h-3"})," 新建"]})]})]}),d.length===0&&y===""&&i.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[i.jsx("div",{className:"text-4xl mb-3",children:ve[e]??"📡"}),i.jsxs("p",{className:"text-dark-text font-medium",children:["还没有配置 ",Ee[e]??e]}),i.jsx("p",{className:"text-sm text-dark-muted mt-1 mb-4",children:e==="wechat"?"点击下方按钮,用微信扫码即可自动完成绑定":"点击上方「新建实例」开始配置"}),e==="wechat"&&i.jsxs("button",{onClick:()=>c(null),className:"flex items-center gap-1.5 text-sm px-4 py-2 rounded-lg bg-green-600/15 hover:bg-green-600/25 text-green-400 border border-green-600/40 transition-colors mb-3",children:[i.jsx(ue,{className:"w-4 h-4"})," 扫码绑定"]}),i.jsxs("button",{onClick:w,className:"flex items-center gap-1.5 text-sm px-4 py-2 rounded-lg bg-accent-blue hover:bg-accent-blue/90 text-white transition-colors",children:[i.jsx(ee,{className:"w-4 h-4"})," 新建实例"]})]}),d.length===1&&y===""&&d[0]&&i.jsx(Se,{channel:d[0],onEdit:()=>f(d[0].id),onDelete:()=>S(d[0].id),onToggle:N=>B(d[0].id,N),onQr:()=>c(d[0])}),d.length>1&&y===""&&i.jsx("div",{className:"space-y-3",children:d.map(N=>i.jsx(Se,{channel:N,onEdit:()=>f(N.id),onDelete:()=>S(N.id),onToggle:A=>B(N.id,A),onQr:()=>c(N)},N.id))}),y!==""&&(p||m)&&i.jsx(ot,{form:h,upd:b,saving:C,editing:!!m,channel:m??void 0,onSave:E,onCancel:k,onDelete:m?()=>S(m.id):void 0,onQr:m?()=>c(m):void 0})]})]}):i.jsx("div",{className:"flex-1 flex items-center justify-center",children:i.jsxs("div",{className:"text-center",children:[i.jsx(Xe,{className:"w-12 h-12 mx-auto mb-3 text-dark-muted/40"}),i.jsx("p",{className:"text-dark-muted text-sm",children:"请从左侧选择一个频道类型"})]})})}function Se({channel:t,onEdit:e,onDelete:o,onToggle:r,onQr:n}){return i.jsxs("div",{className:"border border-dark-border rounded-lg bg-dark-surface overflow-hidden",children:[i.jsx("div",{className:"p-5",children:i.jsxs("div",{className:"flex items-start justify-between",children:[i.jsxs("div",{children:[i.jsx("h3",{className:"font-medium text-dark-text",children:t.name}),i.jsxs("div",{className:"flex items-center gap-3 mt-2",children:[i.jsx("span",{className:`flex items-center gap-1 text-xs ${t.connected?"text-green-400":"text-dark-muted"}`,children:t.connected?i.jsxs(i.Fragment,{children:[i.jsx(Re,{className:"w-3 h-3"})," 已连接"]}):i.jsxs(i.Fragment,{children:[i.jsx(Le,{className:"w-3 h-3"})," 未连接"]})}),i.jsxs("span",{className:"text-xs text-dark-muted",children:["AppID: ",t.appId||"—"]})]})]}),i.jsx("button",{onClick:()=>r(!t.enabled),className:`w-9 h-5 rounded-full relative transition-colors shrink-0 ${t.enabled?"bg-green-600":"bg-gray-600"}`,children:i.jsx("span",{className:`absolute top-0.5 w-4 h-4 bg-white rounded-full transition-all ${t.enabled?"left-[18px]":"left-0.5"}`})})]})}),i.jsxs("div",{className:"flex items-center gap-1 px-5 py-2.5 bg-dark-bg/50 border-t border-dark-border",children:[t.type==="wechat"&&i.jsxs("button",{onClick:n,className:"flex items-center gap-1.5 text-xs px-3 py-1.5 rounded-md text-green-400 hover:bg-green-500/10 transition-colors",children:[i.jsx(ue,{className:"w-3.5 h-3.5"})," 扫码登录"]}),i.jsxs("button",{onClick:e,className:"flex items-center gap-1.5 text-xs px-3 py-1.5 rounded-md text-accent-blue hover:bg-accent-blue/10 transition-colors",children:[i.jsx("span",{className:"w-3.5 h-3.5 inline-flex items-center justify-center",children:"✎"})," 编辑"]}),i.jsxs("button",{onClick:o,className:"flex items-center gap-1.5 text-xs px-3 py-1.5 rounded-md text-red-400 hover:bg-red-500/10 transition-colors ml-auto",children:[i.jsx(_e,{className:"w-3.5 h-3.5"})," 删除"]})]})]})}function ot({form:t,upd:e,saving:o,editing:r,channel:n,onSave:s,onCancel:a,onDelete:l,onQr:c}){return i.jsxs("div",{className:"border border-dark-border rounded-lg bg-dark-surface overflow-hidden",children:[i.jsx("div",{className:"px-5 py-4 border-b border-dark-border",children:i.jsx("h3",{className:"font-medium text-dark-text",children:r?"编辑配置":"新建配置"})}),i.jsxs("div",{className:"p-5 space-y-4",children:[i.jsx(Te,{label:"频道名称",required:!0,children:i.jsx("input",{value:t.name,onChange:u=>e("name",u.target.value),placeholder:"例如:研发群机器人",className:$})}),i.jsxs(Te,{label:"接入凭证",children:[i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-[10px] text-dark-muted mb-1",children:"AppID / 企业ID"}),i.jsx("input",{value:t.appId,onChange:u=>e("appId",u.target.value),placeholder:"AppID",className:$})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-[10px] text-dark-muted mb-1",children:"AppSecret"}),i.jsx("input",{type:"password",value:t.appSecret,onChange:u=>e("appSecret",u.target.value),placeholder:r?"留空不修改":"应用密钥",className:$})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-[10px] text-dark-muted mb-1",children:"Token"}),i.jsx("input",{value:t.token,onChange:u=>e("token",u.target.value),placeholder:r?"留空不修改":"回调校验 Token",className:$})]}),t.type==="wechat"&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-[10px] text-dark-muted mb-1",children:"EncodingAESKey"}),i.jsx("input",{value:t.encodingAESKey,onChange:u=>e("encodingAESKey",u.target.value),placeholder:"选填",className:$})]})]}),t.type==="wechat"&&i.jsx("p",{className:"text-xs text-dark-muted mt-2",children:"微信 iLink 机器人通过扫码授权,凭证可留空,保存后扫码登录即可。"})]}),i.jsxs("div",{className:"flex items-center justify-between rounded-lg border border-dark-border px-3 py-2.5",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-dark-text",children:"启用频道"}),i.jsx("p",{className:"text-xs text-dark-muted",children:"关闭后停止收发消息"})]}),i.jsx("button",{onClick:()=>e("enabled",!t.enabled),className:`w-9 h-5 rounded-full relative transition-colors shrink-0 ${t.enabled?"bg-green-600":"bg-gray-600"}`,children:i.jsx("span",{className:`absolute top-0.5 w-4 h-4 bg-white rounded-full transition-all ${t.enabled?"left-[18px]":"left-0.5"}`})})]}),r&&(n==null?void 0:n.type)==="wechat"&&c&&i.jsxs("button",{onClick:c,className:"w-full flex items-center justify-center gap-2 text-sm bg-green-600/15 hover:bg-green-600/25 text-green-400 border border-green-600/40 px-3 py-2.5 rounded-lg transition-colors",children:[i.jsx(ue,{className:"w-4 h-4"})," 扫码登录 / 重新授权"]})]}),i.jsxs("div",{className:"flex items-center justify-between px-5 py-3 bg-dark-bg/50 border-t border-dark-border",children:[i.jsx("div",{children:r&&l&&i.jsxs("button",{onClick:l,className:"flex items-center gap-1.5 text-xs px-3 py-1.5 rounded-md text-red-400 hover:bg-red-500/10 transition-colors",children:[i.jsx(_e,{className:"w-3.5 h-3.5"})," 删除"]})}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("button",{onClick:a,className:"px-4 py-2 text-sm text-dark-muted hover:text-dark-text transition-colors",children:"取消"}),i.jsxs("button",{onClick:s,disabled:o||!t.name.trim(),className:"flex items-center gap-1.5 px-4 py-2 text-sm bg-accent-blue hover:bg-accent-blue/90 text-white rounded-lg disabled:opacity-50 transition-colors",children:[i.jsx(et,{className:"w-3.5 h-3.5"}),o?"保存中...":"保存"]})]})]})]})}function Te({label:t,required:e,children:o}){return i.jsxs("div",{children:[i.jsxs("label",{className:"block text-xs text-dark-muted mb-1.5",children:[t,e&&i.jsx("span",{className:"text-red-400 ml-0.5",children:"*"})]}),o]})}const $="w-full bg-dark-bg border border-dark-border rounded-lg px-3 py-2 text-sm text-dark-text placeholder-dark-muted/60 focus:outline-none focus:border-accent-blue transition-colors";var q={},it=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then},De={},T={};let he;const at=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];T.getSymbolSize=function(e){if(!e)throw new Error('"version" cannot be null or undefined');if(e<1||e>40)throw new Error('"version" should be in range from 1 to 40');return e*4+17};T.getSymbolTotalCodewords=function(e){return at[e]};T.getBCHDigit=function(t){let e=0;for(;t!==0;)e++,t>>>=1;return e};T.setToSJISFunction=function(e){if(typeof e!="function")throw new Error('"toSJISFunc" is not a valid function.');he=e};T.isKanjiModeEnabled=function(){return typeof he<"u"};T.toSJIS=function(e){return he(e)};var G={};(function(t){t.L={bit:1},t.M={bit:0},t.Q={bit:3},t.H={bit:2};function e(o){if(typeof o!="string")throw new Error("Param is not a string");switch(o.toLowerCase()){case"l":case"low":return t.L;case"m":case"medium":return t.M;case"q":case"quartile":return t.Q;case"h":case"high":return t.H;default:throw new Error("Unknown EC Level: "+o)}}t.isValid=function(r){return r&&typeof r.bit<"u"&&r.bit>=0&&r.bit<4},t.from=function(r,n){if(t.isValid(r))return r;try{return e(r)}catch{return n}}})(G);function Ue(){this.buffer=[],this.length=0}Ue.prototype={get:function(t){const e=Math.floor(t/8);return(this.buffer[e]>>>7-t%8&1)===1},put:function(t,e){for(let o=0;o<e;o++)this.putBit((t>>>e-o-1&1)===1)},getLengthInBits:function(){return this.length},putBit:function(t){const e=Math.floor(this.length/8);this.buffer.length<=e&&this.buffer.push(0),t&&(this.buffer[e]|=128>>>this.length%8),this.length++}};var lt=Ue;function O(t){if(!t||t<1)throw new Error("BitMatrix size must be defined and greater than 0");this.size=t,this.data=new Uint8Array(t*t),this.reservedBit=new Uint8Array(t*t)}O.prototype.set=function(t,e,o,r){const n=t*this.size+e;this.data[n]=o,r&&(this.reservedBit[n]=!0)};O.prototype.get=function(t,e){return this.data[t*this.size+e]};O.prototype.xor=function(t,e,o){this.data[t*this.size+e]^=o};O.prototype.isReserved=function(t,e){return this.reservedBit[t*this.size+e]};var ct=O,Fe={};(function(t){const e=T.getSymbolSize;t.getRowColCoords=function(r){if(r===1)return[];const n=Math.floor(r/7)+2,s=e(r),a=s===145?26:Math.ceil((s-13)/(2*n-2))*2,l=[s-7];for(let c=1;c<n-1;c++)l[c]=l[c-1]-a;return l.push(6),l.reverse()},t.getPositions=function(r){const n=[],s=t.getRowColCoords(r),a=s.length;for(let l=0;l<a;l++)for(let c=0;c<a;c++)l===0&&c===0||l===0&&c===a-1||l===a-1&&c===0||n.push([s[l],s[c]]);return n}})(Fe);var ze={};const dt=T.getSymbolSize,Ae=7;ze.getPositions=function(e){const o=dt(e);return[[0,0],[o-Ae,0],[0,o-Ae]]};var $e={};(function(t){t.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};const e={N1:3,N2:3,N3:40,N4:10};t.isValid=function(n){return n!=null&&n!==""&&!isNaN(n)&&n>=0&&n<=7},t.from=function(n){return t.isValid(n)?parseInt(n,10):void 0},t.getPenaltyN1=function(n){const s=n.size;let a=0,l=0,c=0,u=null,d=null;for(let y=0;y<s;y++){l=c=0,u=d=null;for(let g=0;g<s;g++){let h=n.get(y,g);h===u?l++:(l>=5&&(a+=e.N1+(l-5)),u=h,l=1),h=n.get(g,y),h===d?c++:(c>=5&&(a+=e.N1+(c-5)),d=h,c=1)}l>=5&&(a+=e.N1+(l-5)),c>=5&&(a+=e.N1+(c-5))}return a},t.getPenaltyN2=function(n){const s=n.size;let a=0;for(let l=0;l<s-1;l++)for(let c=0;c<s-1;c++){const u=n.get(l,c)+n.get(l,c+1)+n.get(l+1,c)+n.get(l+1,c+1);(u===4||u===0)&&a++}return a*e.N2},t.getPenaltyN3=function(n){const s=n.size;let a=0,l=0,c=0;for(let u=0;u<s;u++){l=c=0;for(let d=0;d<s;d++)l=l<<1&2047|n.get(u,d),d>=10&&(l===1488||l===93)&&a++,c=c<<1&2047|n.get(d,u),d>=10&&(c===1488||c===93)&&a++}return a*e.N3},t.getPenaltyN4=function(n){let s=0;const a=n.data.length;for(let c=0;c<a;c++)s+=n.data[c];return Math.abs(Math.ceil(s*100/a/5)-10)*e.N4};function o(r,n,s){switch(r){case t.Patterns.PATTERN000:return(n+s)%2===0;case t.Patterns.PATTERN001:return n%2===0;case t.Patterns.PATTERN010:return s%3===0;case t.Patterns.PATTERN011:return(n+s)%3===0;case t.Patterns.PATTERN100:return(Math.floor(n/2)+Math.floor(s/3))%2===0;case t.Patterns.PATTERN101:return n*s%2+n*s%3===0;case t.Patterns.PATTERN110:return(n*s%2+n*s%3)%2===0;case t.Patterns.PATTERN111:return(n*s%3+(n+s)%2)%2===0;default:throw new Error("bad maskPattern:"+r)}}t.applyMask=function(n,s){const a=s.size;for(let l=0;l<a;l++)for(let c=0;c<a;c++)s.isReserved(c,l)||s.xor(c,l,o(n,c,l))},t.getBestMask=function(n,s){const a=Object.keys(t.Patterns).length;let l=0,c=1/0;for(let u=0;u<a;u++){s(u),t.applyMask(u,n);const d=t.getPenaltyN1(n)+t.getPenaltyN2(n)+t.getPenaltyN3(n)+t.getPenaltyN4(n);t.applyMask(u,n),d<c&&(c=d,l=u)}return l}})($e);var W={};const P=G,V=[1,1,1,1,1,1,1,1,1,1,2,2,1,2,2,4,1,2,4,4,2,4,4,4,2,4,6,5,2,4,6,6,2,5,8,8,4,5,8,8,4,5,8,11,4,8,10,11,4,9,12,16,4,9,16,16,6,10,12,18,6,10,17,16,6,11,16,19,6,13,18,21,7,14,21,25,8,16,20,25,8,17,23,25,9,17,23,34,9,18,25,30,10,20,27,32,12,21,29,35,12,23,34,37,12,25,34,40,13,26,35,42,14,28,38,45,15,29,40,48,16,31,43,51,17,33,45,54,18,35,48,57,19,37,51,60,19,38,53,63,20,40,56,66,21,43,59,70,22,45,62,74,24,47,65,77,25,49,68,81],Q=[7,10,13,17,10,16,22,28,15,26,36,44,20,36,52,64,26,48,72,88,36,64,96,112,40,72,108,130,48,88,132,156,60,110,160,192,72,130,192,224,80,150,224,264,96,176,260,308,104,198,288,352,120,216,320,384,132,240,360,432,144,280,408,480,168,308,448,532,180,338,504,588,196,364,546,650,224,416,600,700,224,442,644,750,252,476,690,816,270,504,750,900,300,560,810,960,312,588,870,1050,336,644,952,1110,360,700,1020,1200,390,728,1050,1260,420,784,1140,1350,450,812,1200,1440,480,868,1290,1530,510,924,1350,1620,540,980,1440,1710,570,1036,1530,1800,570,1064,1590,1890,600,1120,1680,1980,630,1204,1770,2100,660,1260,1860,2220,720,1316,1950,2310,750,1372,2040,2430];W.getBlocksCount=function(e,o){switch(o){case P.L:return V[(e-1)*4+0];case P.M:return V[(e-1)*4+1];case P.Q:return V[(e-1)*4+2];case P.H:return V[(e-1)*4+3];default:return}};W.getTotalCodewordsCount=function(e,o){switch(o){case P.L:return Q[(e-1)*4+0];case P.M:return Q[(e-1)*4+1];case P.Q:return Q[(e-1)*4+2];case P.H:return Q[(e-1)*4+3];default:return}};var Ke={},Z={};const K=new Uint8Array(512),J=new Uint8Array(256);(function(){let e=1;for(let o=0;o<255;o++)K[o]=e,J[e]=o,e<<=1,e&256&&(e^=285);for(let o=255;o<512;o++)K[o]=K[o-255]})();Z.log=function(e){if(e<1)throw new Error("log("+e+")");return J[e]};Z.exp=function(e){return K[e]};Z.mul=function(e,o){return e===0||o===0?0:K[J[e]+J[o]]};(function(t){const e=Z;t.mul=function(r,n){const s=new Uint8Array(r.length+n.length-1);for(let a=0;a<r.length;a++)for(let l=0;l<n.length;l++)s[a+l]^=e.mul(r[a],n[l]);return s},t.mod=function(r,n){let s=new Uint8Array(r);for(;s.length-n.length>=0;){const a=s[0];for(let c=0;c<n.length;c++)s[c]^=e.mul(n[c],a);let l=0;for(;l<s.length&&s[l]===0;)l++;s=s.slice(l)}return s},t.generateECPolynomial=function(r){let n=new Uint8Array([1]);for(let s=0;s<r;s++)n=t.mul(n,new Uint8Array([1,e.exp(s)]));return n}})(Ke);const He=Ke;function ge(t){this.genPoly=void 0,this.degree=t,this.degree&&this.initialize(this.degree)}ge.prototype.initialize=function(e){this.degree=e,this.genPoly=He.generateECPolynomial(this.degree)};ge.prototype.encode=function(e){if(!this.genPoly)throw new Error("Encoder not initialized");const o=new Uint8Array(e.length+this.degree);o.set(e);const r=He.mod(o,this.genPoly),n=this.degree-r.length;if(n>0){const s=new Uint8Array(this.degree);return s.set(r,n),s}return r};var ut=ge,qe={},R={},me={};me.isValid=function(e){return!isNaN(e)&&e>=1&&e<=40};var I={};const Oe="[0-9]+",ft="[A-Z $%*+\\-./:]+";let H="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";H=H.replace(/u/g,"\\u");const ht="(?:(?![A-Z0-9 $%*+\\-./:]|"+H+`)(?:.|[\r
|
|
2
|
+
]))+`;I.KANJI=new RegExp(H,"g");I.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g");I.BYTE=new RegExp(ht,"g");I.NUMERIC=new RegExp(Oe,"g");I.ALPHANUMERIC=new RegExp(ft,"g");const gt=new RegExp("^"+H+"$"),mt=new RegExp("^"+Oe+"$"),xt=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");I.testKanji=function(e){return gt.test(e)};I.testNumeric=function(e){return mt.test(e)};I.testAlphanumeric=function(e){return xt.test(e)};(function(t){const e=me,o=I;t.NUMERIC={id:"Numeric",bit:1,ccBits:[10,12,14]},t.ALPHANUMERIC={id:"Alphanumeric",bit:2,ccBits:[9,11,13]},t.BYTE={id:"Byte",bit:4,ccBits:[8,16,16]},t.KANJI={id:"Kanji",bit:8,ccBits:[8,10,12]},t.MIXED={bit:-1},t.getCharCountIndicator=function(s,a){if(!s.ccBits)throw new Error("Invalid mode: "+s);if(!e.isValid(a))throw new Error("Invalid version: "+a);return a>=1&&a<10?s.ccBits[0]:a<27?s.ccBits[1]:s.ccBits[2]},t.getBestModeForData=function(s){return o.testNumeric(s)?t.NUMERIC:o.testAlphanumeric(s)?t.ALPHANUMERIC:o.testKanji(s)?t.KANJI:t.BYTE},t.toString=function(s){if(s&&s.id)return s.id;throw new Error("Invalid mode")},t.isValid=function(s){return s&&s.bit&&s.ccBits};function r(n){if(typeof n!="string")throw new Error("Param is not a string");switch(n.toLowerCase()){case"numeric":return t.NUMERIC;case"alphanumeric":return t.ALPHANUMERIC;case"kanji":return t.KANJI;case"byte":return t.BYTE;default:throw new Error("Unknown mode: "+n)}}t.from=function(s,a){if(t.isValid(s))return s;try{return r(s)}catch{return a}}})(R);(function(t){const e=T,o=W,r=G,n=R,s=me,a=7973,l=e.getBCHDigit(a);function c(g,h,x){for(let C=1;C<=40;C++)if(h<=t.getCapacity(C,x,g))return C}function u(g,h){return n.getCharCountIndicator(g,h)+4}function d(g,h){let x=0;return g.forEach(function(C){const j=u(C.mode,h);x+=j+C.getBitsLength()}),x}function y(g,h){for(let x=1;x<=40;x++)if(d(g,x)<=t.getCapacity(x,h,n.MIXED))return x}t.from=function(h,x){return s.isValid(h)?parseInt(h,10):x},t.getCapacity=function(h,x,C){if(!s.isValid(h))throw new Error("Invalid QR Code version");typeof C>"u"&&(C=n.BYTE);const j=e.getSymbolTotalCodewords(h),p=o.getTotalCodewordsCount(h,x),m=(j-p)*8;if(C===n.MIXED)return m;const b=m-u(C,h);switch(C){case n.NUMERIC:return Math.floor(b/10*3);case n.ALPHANUMERIC:return Math.floor(b/11*2);case n.KANJI:return Math.floor(b/13);case n.BYTE:default:return Math.floor(b/8)}},t.getBestVersionForData=function(h,x){let C;const j=r.from(x,r.M);if(Array.isArray(h)){if(h.length>1)return y(h,j);if(h.length===0)return 1;C=h[0]}else C=h;return c(C.mode,C.getLength(),j)},t.getEncodedBits=function(h){if(!s.isValid(h)||h<7)throw new Error("Invalid QR Code version");let x=h<<12;for(;e.getBCHDigit(x)-l>=0;)x^=a<<e.getBCHDigit(x)-l;return h<<12|x}})(qe);var Ve={};const ae=T,Qe=1335,pt=21522,Be=ae.getBCHDigit(Qe);Ve.getEncodedBits=function(e,o){const r=e.bit<<3|o;let n=r<<10;for(;ae.getBCHDigit(n)-Be>=0;)n^=Qe<<ae.getBCHDigit(n)-Be;return(r<<10|n)^pt};var Je={};const bt=R;function _(t){this.mode=bt.NUMERIC,this.data=t.toString()}_.getBitsLength=function(e){return 10*Math.floor(e/3)+(e%3?e%3*3+1:0)};_.prototype.getLength=function(){return this.data.length};_.prototype.getBitsLength=function(){return _.getBitsLength(this.data.length)};_.prototype.write=function(e){let o,r,n;for(o=0;o+3<=this.data.length;o+=3)r=this.data.substr(o,3),n=parseInt(r,10),e.put(n,10);const s=this.data.length-o;s>0&&(r=this.data.substr(o),n=parseInt(r,10),e.put(n,s*3+1))};var wt=_;const yt=R,ne=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"," ","$","%","*","+","-",".","/",":"];function D(t){this.mode=yt.ALPHANUMERIC,this.data=t}D.getBitsLength=function(e){return 11*Math.floor(e/2)+6*(e%2)};D.prototype.getLength=function(){return this.data.length};D.prototype.getBitsLength=function(){return D.getBitsLength(this.data.length)};D.prototype.write=function(e){let o;for(o=0;o+2<=this.data.length;o+=2){let r=ne.indexOf(this.data[o])*45;r+=ne.indexOf(this.data[o+1]),e.put(r,11)}this.data.length%2&&e.put(ne.indexOf(this.data[o]),6)};var Nt=D;const Ct=R;function U(t){this.mode=Ct.BYTE,typeof t=="string"?this.data=new TextEncoder().encode(t):this.data=new Uint8Array(t)}U.getBitsLength=function(e){return e*8};U.prototype.getLength=function(){return this.data.length};U.prototype.getBitsLength=function(){return U.getBitsLength(this.data.length)};U.prototype.write=function(t){for(let e=0,o=this.data.length;e<o;e++)t.put(this.data[e],8)};var kt=U;const jt=R,Et=T;function F(t){this.mode=jt.KANJI,this.data=t}F.getBitsLength=function(e){return e*13};F.prototype.getLength=function(){return this.data.length};F.prototype.getBitsLength=function(){return F.getBitsLength(this.data.length)};F.prototype.write=function(t){let e;for(e=0;e<this.data.length;e++){let o=Et.toSJIS(this.data[e]);if(o>=33088&&o<=40956)o-=33088;else if(o>=57408&&o<=60351)o-=49472;else throw new Error("Invalid SJIS character: "+this.data[e]+`
|
|
3
|
+
Make sure your charset is UTF-8`);o=(o>>>8&255)*192+(o&255),t.put(o,13)}};var vt=F,Ye={exports:{}};(function(t){var e={single_source_shortest_paths:function(o,r,n){var s={},a={};a[r]=0;var l=e.PriorityQueue.make();l.push(r,0);for(var c,u,d,y,g,h,x,C,j;!l.empty();){c=l.pop(),u=c.value,y=c.cost,g=o[u]||{};for(d in g)g.hasOwnProperty(d)&&(h=g[d],x=y+h,C=a[d],j=typeof a[d]>"u",(j||C>x)&&(a[d]=x,l.push(d,x),s[d]=u))}if(typeof n<"u"&&typeof a[n]>"u"){var p=["Could not find a path from ",r," to ",n,"."].join("");throw new Error(p)}return s},extract_shortest_path_from_predecessor_list:function(o,r){for(var n=[],s=r;s;)n.push(s),o[s],s=o[s];return n.reverse(),n},find_path:function(o,r,n){var s=e.single_source_shortest_paths(o,r,n);return e.extract_shortest_path_from_predecessor_list(s,n)},PriorityQueue:{make:function(o){var r=e.PriorityQueue,n={},s;o=o||{};for(s in r)r.hasOwnProperty(s)&&(n[s]=r[s]);return n.queue=[],n.sorter=o.sorter||r.default_sorter,n},default_sorter:function(o,r){return o.cost-r.cost},push:function(o,r){var n={value:o,cost:r};this.queue.push(n),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return this.queue.length===0}}};t.exports=e})(Ye);var St=Ye.exports;(function(t){const e=R,o=wt,r=Nt,n=kt,s=vt,a=I,l=T,c=St;function u(p){return unescape(encodeURIComponent(p)).length}function d(p,m,b){const f=[];let w;for(;(w=p.exec(b))!==null;)f.push({data:w[0],index:w.index,mode:m,length:w[0].length});return f}function y(p){const m=d(a.NUMERIC,e.NUMERIC,p),b=d(a.ALPHANUMERIC,e.ALPHANUMERIC,p);let f,w;return l.isKanjiModeEnabled()?(f=d(a.BYTE,e.BYTE,p),w=d(a.KANJI,e.KANJI,p)):(f=d(a.BYTE_KANJI,e.BYTE,p),w=[]),m.concat(b,f,w).sort(function(E,S){return E.index-S.index}).map(function(E){return{data:E.data,mode:E.mode,length:E.length}})}function g(p,m){switch(m){case e.NUMERIC:return o.getBitsLength(p);case e.ALPHANUMERIC:return r.getBitsLength(p);case e.KANJI:return s.getBitsLength(p);case e.BYTE:return n.getBitsLength(p)}}function h(p){return p.reduce(function(m,b){const f=m.length-1>=0?m[m.length-1]:null;return f&&f.mode===b.mode?(m[m.length-1].data+=b.data,m):(m.push(b),m)},[])}function x(p){const m=[];for(let b=0;b<p.length;b++){const f=p[b];switch(f.mode){case e.NUMERIC:m.push([f,{data:f.data,mode:e.ALPHANUMERIC,length:f.length},{data:f.data,mode:e.BYTE,length:f.length}]);break;case e.ALPHANUMERIC:m.push([f,{data:f.data,mode:e.BYTE,length:f.length}]);break;case e.KANJI:m.push([f,{data:f.data,mode:e.BYTE,length:u(f.data)}]);break;case e.BYTE:m.push([{data:f.data,mode:e.BYTE,length:u(f.data)}])}}return m}function C(p,m){const b={},f={start:{}};let w=["start"];for(let k=0;k<p.length;k++){const E=p[k],S=[];for(let B=0;B<E.length;B++){const N=E[B],A=""+k+B;S.push(A),b[A]={node:N,lastCount:0},f[A]={};for(let z=0;z<w.length;z++){const M=w[z];b[M]&&b[M].node.mode===N.mode?(f[M][A]=g(b[M].lastCount+N.length,N.mode)-g(b[M].lastCount,N.mode),b[M].lastCount+=N.length):(b[M]&&(b[M].lastCount=N.length),f[M][A]=g(N.length,N.mode)+4+e.getCharCountIndicator(N.mode,m))}}w=S}for(let k=0;k<w.length;k++)f[w[k]].end=0;return{map:f,table:b}}function j(p,m){let b;const f=e.getBestModeForData(p);if(b=e.from(m,f),b!==e.BYTE&&b.bit<f.bit)throw new Error('"'+p+'" cannot be encoded with mode '+e.toString(b)+`.
|
|
4
|
+
Suggested mode is: `+e.toString(f));switch(b===e.KANJI&&!l.isKanjiModeEnabled()&&(b=e.BYTE),b){case e.NUMERIC:return new o(p);case e.ALPHANUMERIC:return new r(p);case e.KANJI:return new s(p);case e.BYTE:return new n(p)}}t.fromArray=function(m){return m.reduce(function(b,f){return typeof f=="string"?b.push(j(f,null)):f.data&&b.push(j(f.data,f.mode)),b},[])},t.fromString=function(m,b){const f=y(m,l.isKanjiModeEnabled()),w=x(f),k=C(w,b),E=c.find_path(k.map,"start","end"),S=[];for(let B=1;B<E.length-1;B++)S.push(k.table[E[B]].node);return t.fromArray(h(S))},t.rawSplit=function(m){return t.fromArray(y(m,l.isKanjiModeEnabled()))}})(Je);const X=T,re=G,Tt=lt,At=ct,Bt=Fe,It=ze,le=$e,ce=W,Mt=ut,Y=qe,Pt=Ve,Rt=R,se=Je;function Lt(t,e){const o=t.size,r=It.getPositions(e);for(let n=0;n<r.length;n++){const s=r[n][0],a=r[n][1];for(let l=-1;l<=7;l++)if(!(s+l<=-1||o<=s+l))for(let c=-1;c<=7;c++)a+c<=-1||o<=a+c||(l>=0&&l<=6&&(c===0||c===6)||c>=0&&c<=6&&(l===0||l===6)||l>=2&&l<=4&&c>=2&&c<=4?t.set(s+l,a+c,!0,!0):t.set(s+l,a+c,!1,!0))}}function _t(t){const e=t.size;for(let o=8;o<e-8;o++){const r=o%2===0;t.set(o,6,r,!0),t.set(6,o,r,!0)}}function Dt(t,e){const o=Bt.getPositions(e);for(let r=0;r<o.length;r++){const n=o[r][0],s=o[r][1];for(let a=-2;a<=2;a++)for(let l=-2;l<=2;l++)a===-2||a===2||l===-2||l===2||a===0&&l===0?t.set(n+a,s+l,!0,!0):t.set(n+a,s+l,!1,!0)}}function Ut(t,e){const o=t.size,r=Y.getEncodedBits(e);let n,s,a;for(let l=0;l<18;l++)n=Math.floor(l/3),s=l%3+o-8-3,a=(r>>l&1)===1,t.set(n,s,a,!0),t.set(s,n,a,!0)}function oe(t,e,o){const r=t.size,n=Pt.getEncodedBits(e,o);let s,a;for(s=0;s<15;s++)a=(n>>s&1)===1,s<6?t.set(s,8,a,!0):s<8?t.set(s+1,8,a,!0):t.set(r-15+s,8,a,!0),s<8?t.set(8,r-s-1,a,!0):s<9?t.set(8,15-s-1+1,a,!0):t.set(8,15-s-1,a,!0);t.set(r-8,8,1,!0)}function Ft(t,e){const o=t.size;let r=-1,n=o-1,s=7,a=0;for(let l=o-1;l>0;l-=2)for(l===6&&l--;;){for(let c=0;c<2;c++)if(!t.isReserved(n,l-c)){let u=!1;a<e.length&&(u=(e[a]>>>s&1)===1),t.set(n,l-c,u),s--,s===-1&&(a++,s=7)}if(n+=r,n<0||o<=n){n-=r,r=-r;break}}}function zt(t,e,o){const r=new Tt;o.forEach(function(c){r.put(c.mode.bit,4),r.put(c.getLength(),Rt.getCharCountIndicator(c.mode,t)),c.write(r)});const n=X.getSymbolTotalCodewords(t),s=ce.getTotalCodewordsCount(t,e),a=(n-s)*8;for(r.getLengthInBits()+4<=a&&r.put(0,4);r.getLengthInBits()%8!==0;)r.putBit(0);const l=(a-r.getLengthInBits())/8;for(let c=0;c<l;c++)r.put(c%2?17:236,8);return $t(r,t,e)}function $t(t,e,o){const r=X.getSymbolTotalCodewords(e),n=ce.getTotalCodewordsCount(e,o),s=r-n,a=ce.getBlocksCount(e,o),l=r%a,c=a-l,u=Math.floor(r/a),d=Math.floor(s/a),y=d+1,g=u-d,h=new Mt(g);let x=0;const C=new Array(a),j=new Array(a);let p=0;const m=new Uint8Array(t.buffer);for(let E=0;E<a;E++){const S=E<c?d:y;C[E]=m.slice(x,x+S),j[E]=h.encode(C[E]),x+=S,p=Math.max(p,S)}const b=new Uint8Array(r);let f=0,w,k;for(w=0;w<p;w++)for(k=0;k<a;k++)w<C[k].length&&(b[f++]=C[k][w]);for(w=0;w<g;w++)for(k=0;k<a;k++)b[f++]=j[k][w];return b}function Kt(t,e,o,r){let n;if(Array.isArray(t))n=se.fromArray(t);else if(typeof t=="string"){let u=e;if(!u){const d=se.rawSplit(t);u=Y.getBestVersionForData(d,o)}n=se.fromString(t,u||40)}else throw new Error("Invalid data");const s=Y.getBestVersionForData(n,o);if(!s)throw new Error("The amount of data is too big to be stored in a QR Code");if(!e)e=s;else if(e<s)throw new Error(`
|
|
5
|
+
The chosen QR Code version cannot contain this amount of data.
|
|
6
|
+
Minimum version required to store current data is: `+s+`.
|
|
7
|
+
`);const a=zt(e,o,n),l=X.getSymbolSize(e),c=new At(l);return Lt(c,e),_t(c),Dt(c,e),oe(c,o,0),e>=7&&Ut(c,e),Ft(c,a),isNaN(r)&&(r=le.getBestMask(c,oe.bind(null,c,o))),le.applyMask(r,c),oe(c,o,r),{modules:c,version:e,errorCorrectionLevel:o,maskPattern:r,segments:n}}De.create=function(e,o){if(typeof e>"u"||e==="")throw new Error("No input text");let r=re.M,n,s;return typeof o<"u"&&(r=re.from(o.errorCorrectionLevel,re.M),n=Y.from(o.version),s=le.from(o.maskPattern),o.toSJISFunc&&X.setToSJISFunction(o.toSJISFunc)),Kt(e,n,r,s)};var Ge={},xe={};(function(t){function e(o){if(typeof o=="number"&&(o=o.toString()),typeof o!="string")throw new Error("Color should be defined as hex string");let r=o.slice().replace("#","").split("");if(r.length<3||r.length===5||r.length>8)throw new Error("Invalid hex color: "+o);(r.length===3||r.length===4)&&(r=Array.prototype.concat.apply([],r.map(function(s){return[s,s]}))),r.length===6&&r.push("F","F");const n=parseInt(r.join(""),16);return{r:n>>24&255,g:n>>16&255,b:n>>8&255,a:n&255,hex:"#"+r.slice(0,6).join("")}}t.getOptions=function(r){r||(r={}),r.color||(r.color={});const n=typeof r.margin>"u"||r.margin===null||r.margin<0?4:r.margin,s=r.width&&r.width>=21?r.width:void 0,a=r.scale||4;return{width:s,scale:s?4:a,margin:n,color:{dark:e(r.color.dark||"#000000ff"),light:e(r.color.light||"#ffffffff")},type:r.type,rendererOpts:r.rendererOpts||{}}},t.getScale=function(r,n){return n.width&&n.width>=r+n.margin*2?n.width/(r+n.margin*2):n.scale},t.getImageWidth=function(r,n){const s=t.getScale(r,n);return Math.floor((r+n.margin*2)*s)},t.qrToImageData=function(r,n,s){const a=n.modules.size,l=n.modules.data,c=t.getScale(a,s),u=Math.floor((a+s.margin*2)*c),d=s.margin*c,y=[s.color.light,s.color.dark];for(let g=0;g<u;g++)for(let h=0;h<u;h++){let x=(g*u+h)*4,C=s.color.light;if(g>=d&&h>=d&&g<u-d&&h<u-d){const j=Math.floor((g-d)/c),p=Math.floor((h-d)/c);C=y[l[j*a+p]?1:0]}r[x++]=C.r,r[x++]=C.g,r[x++]=C.b,r[x]=C.a}}})(xe);(function(t){const e=xe;function o(n,s,a){n.clearRect(0,0,s.width,s.height),s.style||(s.style={}),s.height=a,s.width=a,s.style.height=a+"px",s.style.width=a+"px"}function r(){try{return document.createElement("canvas")}catch{throw new Error("You need to specify a canvas element")}}t.render=function(s,a,l){let c=l,u=a;typeof c>"u"&&(!a||!a.getContext)&&(c=a,a=void 0),a||(u=r()),c=e.getOptions(c);const d=e.getImageWidth(s.modules.size,c),y=u.getContext("2d"),g=y.createImageData(d,d);return e.qrToImageData(g.data,s,c),o(y,u,d),y.putImageData(g,0,0),u},t.renderToDataURL=function(s,a,l){let c=l;typeof c>"u"&&(!a||!a.getContext)&&(c=a,a=void 0),c||(c={});const u=t.render(s,a,c),d=c.type||"image/png",y=c.rendererOpts||{};return u.toDataURL(d,y.quality)}})(Ge);var We={};const Ht=xe;function Ie(t,e){const o=t.a/255,r=e+'="'+t.hex+'"';return o<1?r+" "+e+'-opacity="'+o.toFixed(2).slice(1)+'"':r}function ie(t,e,o){let r=t+e;return typeof o<"u"&&(r+=" "+o),r}function qt(t,e,o){let r="",n=0,s=!1,a=0;for(let l=0;l<t.length;l++){const c=Math.floor(l%e),u=Math.floor(l/e);!c&&!s&&(s=!0),t[l]?(a++,l>0&&c>0&&t[l-1]||(r+=s?ie("M",c+o,.5+u+o):ie("m",n,0),n=0,s=!1),c+1<e&&t[l+1]||(r+=ie("h",a),a=0)):n++}return r}We.render=function(e,o,r){const n=Ht.getOptions(o),s=e.modules.size,a=e.modules.data,l=s+n.margin*2,c=n.color.light.a?"<path "+Ie(n.color.light,"fill")+' d="M0 0h'+l+"v"+l+'H0z"/>':"",u="<path "+Ie(n.color.dark,"stroke")+' d="'+qt(a,s,n.margin)+'"/>',d='viewBox="0 0 '+l+" "+l+'"',g='<svg xmlns="http://www.w3.org/2000/svg" '+(n.width?'width="'+n.width+'" height="'+n.width+'" ':"")+d+' shape-rendering="crispEdges">'+c+u+`</svg>
|
|
8
|
+
`;return typeof r=="function"&&r(null,g),g};const Ot=it,de=De,Ze=Ge,Vt=We;function pe(t,e,o,r,n){const s=[].slice.call(arguments,1),a=s.length,l=typeof s[a-1]=="function";if(!l&&!Ot())throw new Error("Callback required as last argument");if(l){if(a<2)throw new Error("Too few arguments provided");a===2?(n=o,o=e,e=r=void 0):a===3&&(e.getContext&&typeof n>"u"?(n=r,r=void 0):(n=r,r=o,o=e,e=void 0))}else{if(a<1)throw new Error("Too few arguments provided");return a===1?(o=e,e=r=void 0):a===2&&!e.getContext&&(r=o,o=e,e=void 0),new Promise(function(c,u){try{const d=de.create(o,r);c(t(d,e,r))}catch(d){u(d)}})}try{const c=de.create(o,r);n(null,t(c,e,r))}catch(c){n(c)}}q.create=de.create;q.toCanvas=pe.bind(null,Ze.render);q.toDataURL=pe.bind(null,Ze.renderToDataURL);q.toString=pe.bind(null,function(t,e,o){return Vt.render(t,o)});const Qt=2e3,Me=5;function Jt({channel:t,onClose:e}){const[o,r]=v.useState("loading"),[n,s]=v.useState(null),[a,l]=v.useState(null),[c,u]=v.useState(""),d=v.useRef(null),y=v.useRef(0),g=v.useRef(null),h=v.useRef(!1),x=()=>{g.current&&(clearTimeout(g.current),g.current=null),h.current=!0},C=async f=>{if(d.current)try{await q.toCanvas(d.current,f,{width:240,margin:2,color:{dark:"#000000ff",light:"#ffffffff"}})}catch(w){console.warn("[WechatQr] Canvas QR generation failed, falling back to URL:",w)}},j=async()=>{if(!(h.current||!a))try{const f=await be.channels.weixin.bindStatus(a),w=(f==null?void 0:f.data)??f,k=(w==null?void 0:w.status)??"";if(y.current=0,k==="confirmed"){r("confirmed"),te.success(t?`微信「${t.name}」重新授权成功,频道已连接`:"微信绑定成功,频道已自动创建并连接"),setTimeout(e,2400);return}if(k==="scaned")r("scanned");else if(k==="expired"){r("expired");return}h.current||(g.current=setTimeout(j,Qt))}catch(f){if(y.current++,console.warn("[WechatQr] poll error ("+y.current+"/"+Me+")",f),y.current>=Me)r("error"),u("轮询状态失败次数过多,请刷新二维码重试"),te.error("微信绑定状态轮询失败,请刷新二维码重试");else if(!h.current){const w=Math.min(1e3*Math.pow(2,y.current),1e4);g.current=setTimeout(j,w)}}},p=()=>{x(),h.current=!1,y.current=0,g.current=setTimeout(j,1e3)},m=async()=>{r("loading"),s(null),l(null),u(""),y.current=0;try{const f=await be.channels.weixin.bind(),w=(f==null?void 0:f.data)??f,k=(w==null?void 0:w.qrcode_img_content)??"",E=(w==null?void 0:w.qrcode)??"";if(!k||!E){r("error"),u(`二维码数据缺失: ${JSON.stringify(w)}`);return}s(k),l(E),await C(k),r("waiting")}catch(f){r("error");const w=String((f==null?void 0:f.message)??f);u(w),te.error(`获取微信二维码失败:${w}`)}},b=()=>{m()};return v.useEffect(()=>(m(),x),[]),v.useEffect(()=>(a&&p(),x),[a]),i.jsx(nt,{isOpen:!0,onClose:e,title:`扫码绑定 · ${(t==null?void 0:t.name)??"微信"}`,size:"sm",children:i.jsxs("div",{className:"flex flex-col items-center gap-4 py-2",children:[i.jsxs("div",{className:"relative w-60 h-60 rounded-lg bg-white flex items-center justify-center overflow-hidden",children:[o==="loading"&&i.jsx("span",{className:"text-gray-400 text-sm",children:"二维码生成中..."}),o!=="error"&&o!=="expired"&&i.jsx("canvas",{ref:d,width:240,height:240,className:`w-full h-full object-contain ${o==="waiting"?"":"opacity-30"}`}),o==="scanned"&&i.jsxs("div",{className:"absolute inset-0 bg-black/70 flex flex-col items-center justify-center text-white gap-1",children:[i.jsx("span",{className:"text-2xl",children:"✓"}),i.jsx("span",{className:"text-sm",children:"已扫描,请在手机上确认"})]}),o==="confirmed"&&i.jsxs("div",{className:"absolute inset-0 bg-green-600/90 flex flex-col items-center justify-center text-white gap-2 px-4 text-center",children:[i.jsx("span",{className:"text-2xl",children:"🎉"}),i.jsx("span",{className:"text-sm font-medium",children:"绑定成功"}),i.jsx("span",{className:"text-xs opacity-90",children:t?`「${t.name}」已连接,可开始使用`:"微信频道已创建并连接,可开始使用"}),i.jsx("button",{onClick:e,className:"mt-1 text-xs bg-white/20 hover:bg-white/30 px-3 py-1.5 rounded-md transition-colors",children:"开始使用"})]}),o==="expired"&&i.jsxs("div",{className:"absolute inset-0 bg-black/80 flex flex-col items-center justify-center text-white gap-2",children:[i.jsx("span",{className:"text-sm",children:"二维码已失效"}),i.jsx("button",{onClick:b,className:"text-xs bg-green-600 hover:bg-green-500 px-3 py-1 rounded",children:"点击刷新"})]}),o==="error"&&i.jsxs("div",{className:"absolute inset-0 bg-black/80 flex flex-col items-center justify-center text-red-300 gap-2 px-4 text-center",children:[i.jsx("span",{className:"text-xs",children:c||"未知错误"}),i.jsx("button",{onClick:b,className:"text-xs bg-blue-600 hover:bg-blue-500 px-3 py-1 rounded text-white",children:"重试"})]})]}),i.jsxs("p",{className:"text-sm text-dark-muted text-center",children:[o==="waiting"&&"请使用微信扫描二维码授权机器人",o==="scanned"&&"已扫描,请在手机上确认...",o==="confirmed"&&"机器人已授权并启动,即将自动关闭",o==="loading"&&"正在连接 iLink 服务...",(o==="expired"||o==="error")&&(o==="expired"?"二维码已失效":"")]}),n&&o==="waiting"&&i.jsxs("button",{onClick:()=>window.open(n,"_blank","width=480,height=600,noopener"),className:"w-full flex items-center justify-center gap-2 text-sm bg-green-600/15 hover:bg-green-600/25 text-green-400 border border-green-600/40 px-3 py-2.5 rounded-lg transition-colors",children:[i.jsx("span",{children:"🔔"})," 在新标签页打开(备用)"]})]})})}function en(){const{load:t,loading:e,qrOpen:o,qrChannel:r,closeQr:n}=fe();return v.useEffect(()=>{t()},[]),i.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-dark-bg text-dark-text",children:[i.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-dark-border shrink-0",children:[i.jsxs("div",{children:[i.jsx("h2",{className:"font-semibold text-base",children:"频道管理"}),i.jsx("p",{className:"text-xs text-dark-muted mt-0.5",children:"接入微信、飞书、钉钉,用户可通过频道发送任务并实时接收进度与结果"})]}),i.jsx("div",{className:"flex items-center gap-2",children:i.jsx("button",{onClick:()=>t(),title:"刷新",className:"p-2 rounded-lg text-dark-muted hover:text-dark-text hover:bg-dark-hover transition-colors",children:i.jsx(tt,{className:`w-4 h-4 ${e?"animate-spin":""}`})})})]}),i.jsxs("div",{className:"flex-1 flex min-h-0 overflow-hidden",children:[i.jsx("div",{className:"w-[260px] shrink-0",children:i.jsx(rt,{})}),i.jsx("div",{className:"flex-1 min-w-0",children:i.jsx(st,{})})]}),o&&i.jsx(Jt,{channel:r,onClose:n})]})}export{en as ChannelConfigView};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as s}from"./markdown-D0iUI0Yw.js";import{r as d,L as w,m as _,J as A,P as ae,R as ne,T as le,x as F,aL as K,aQ as q,aj as oe,aG as V,aC as de,a4 as ce,D,s as ie}from"./icons-B5yCkBjC.js";import{e as me,a as f}from"./index-YAnKQ1Q6.js";import"./react-vendor-Bxu3r3ox.js";import"./state-C80Yzgl0.js";const xe={"code-intelligence":"🧠 代码智能",filesystem:"📂 文件系统",databases:"🗄️ 数据库","browser-automation":"🌐 浏览器自动化","knowledge-memory":"🧠 知识/记忆","search-web":"🔎 搜索/网页","cloud-platforms":"☁️ 云平台",communication:"💬 通讯","developer-tools":"🛠️ 开发者工具",security:"🔒 安全","test-demo":"🧪 测试/Demo",other:"📦 其他"};function fe(){const{t:r}=me(),[x,u]=d.useState([]),[H,C]=d.useState(!0),[S,E]=d.useState(null),[j,p]=d.useState({}),[z,m]=d.useState(null),[v,O]=d.useState(""),[b,$]=d.useState(null),[k,G]=d.useState("all"),[Q,g]=d.useState(null),[U,L]=d.useState({}),[Y,N]=d.useState(!1),[l,i]=d.useState({name:"",command:"",args:"",env:"",transport:"stdio",url:"",headers:""}),M=()=>i({name:"",command:"",args:"",env:"",transport:"stdio",url:"",headers:""}),T=e=>Object.fromEntries(e.split(",").map(t=>t.trim()).filter(Boolean).map(t=>{const n=t.indexOf("=");return n>0?[t.slice(0,n).trim(),t.slice(n+1).trim()]:[t,""]})),I=async()=>{const e=l.transport!=="stdio";if(!l.name.trim()||!e&&!l.command.trim()||e&&!l.url.trim()){m(r("connectors.customFormRequired"));return}p(t=>({...t,__add:!0})),m(null);try{const t=await f.connectors.addCustom({name:l.name.trim(),command:e?void 0:l.command.trim(),args:e?void 0:l.args.split(/\s+/).filter(Boolean),env:T(l.env),url:e?l.url.trim():void 0,transport:e?l.transport:void 0,headers:e?T(l.headers):void 0});t.success&&t.data?(u(n=>[...n,t.data]),N(!1),M()):m(t.error||"添加失败")}catch(t){m(t instanceof Error?t.message:String(t))}finally{p(t=>({...t,__add:!1}))}},J=async e=>{p(t=>({...t,[e.id]:!0}));try{const t=await f.connectors.removeCustom(e.id);t.success?u(n=>n.filter(a=>a.id!==e.id)):m(t.error||"删除失败")}finally{p(t=>({...t,[e.id]:!1}))}},y=async()=>{var t;C(!0),E(null);const e=await f.connectors.list();e.success&&Array.isArray((t=e.data)==null?void 0:t.connectors)?u(e.data.connectors):E(e.error||"加载连接器失败"),C(!1)};d.useEffect(()=>{y()},[]);const B=(e,t,n,a)=>{m(n||null),u(o=>o.map(c=>c.id===e?{...c,enabled:!!a,status:"error"}:c))},P=async(e,t,n)=>{m(null),p(a=>({...a,[e.id]:!0})),u(a=>a.map(o=>o.id===e.id?{...o,enabled:t,status:t?"connecting":"installed"}:o));try{const a=await f.connectors.toggle(e.id,t,n);a.success&&a.data?u(o=>o.map(c=>c.id===e.id?a.data:c)):B(e.id,void 0,a.error||`切换 ${e.name} 失败`,!t)}catch(a){B(e.id,void 0,a instanceof Error?a.message:String(a),!t)}finally{p(a=>({...a,[e.id]:!1}))}},W=e=>{var t,n;if(!e.enabled&&((t=e.requiresEnv)!=null&&t.length)&&((n=e.missingEnv)!=null&&n.length)){g(e.id);return}g(null),P(e,!e.enabled)},Z=(e,t)=>{g(null),L(n=>({...n,[e.id]:{}})),P(e,!0,t)},X=e=>{const t="inline-flex items-center gap-1 px-2 py-0.5 rounded text-xs font-medium";if(!e.installed)return s.jsxs("span",{className:`${t} bg-dark-hover text-dark-muted`,children:[s.jsx(D,{size:12}),r("connectors.notInstalled")]});switch(e.status){case"ready":return s.jsxs("span",{className:`${t} bg-accent-green/15 text-accent-green`,children:[s.jsx(ie,{size:12}),r("connectors.ready")]});case"connecting":return s.jsxs("span",{className:`${t} bg-accent-blue/15 text-accent-blue`,children:[s.jsx(w,{size:12,className:"animate-spin"}),r("connectors.connecting")]});case"error":return s.jsxs("span",{className:`${t} bg-accent-red/15 text-accent-red`,children:[s.jsx(_,{size:12}),r("connectors.error")]});case"disabled":return s.jsx("span",{className:`${t} bg-dark-hover text-dark-muted`,children:r("connectors.disabled")});default:return s.jsx("span",{className:`${t} bg-dark-hover text-dark-muted`,children:r("connectors.installed")})}},h=x.filter(e=>k==="all"||e.kind===k),R=h.filter(e=>{if(v){const t=v.toLowerCase();if(![e.name,e.id,e.description,e.category??"",e.kind,...e.languages??[]].join(" ").toLowerCase().includes(t))return!1}return!(b&&e.category!==b)}).sort((e,t)=>e.enabled!==t.enabled?e.enabled?-1:1:e.name.localeCompare(t.name)),ee=[...new Set(h.map(e=>e.category).filter(Boolean))];if(H)return s.jsx("div",{className:"flex-1 flex items-center justify-center",children:s.jsxs("div",{className:"text-center",children:[s.jsx(w,{size:32,className:"animate-spin mx-auto mb-2 text-accent-blue"}),s.jsx("p",{className:"text-dark-muted",children:r("common.loading")})]})});if(S)return s.jsx("div",{className:"flex-1 flex items-center justify-center",children:s.jsxs("div",{className:"text-center",children:[s.jsx(_,{size:32,className:"mx-auto mb-2 text-accent-red"}),s.jsx("p",{className:"text-accent-red mb-4",children:S}),s.jsx("button",{onClick:()=>void y(),className:"px-4 py-2 bg-accent-blue text-white rounded-lg",children:r("common.retry")})]})});const se=e=>{const t=U[e.id]??{},n=(a,o)=>L(c=>({...c,[e.id]:{...c[e.id]??{},[a]:o}}));return s.jsxs("div",{className:"mt-3 pt-3 border-t border-dark-border",children:[s.jsxs("div",{className:"text-xs text-dark-muted mb-2 flex items-center gap-1",children:[s.jsx(V,{size:12}),r("connectors.needCredentials")]}),s.jsx("div",{className:"space-y-2",children:(e.requiresEnv??[]).map(a=>s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] text-dark-muted mb-1",children:a.label}),s.jsx("input",{type:a.secret?"password":"text",value:t[a.key]??"",onChange:o=>n(a.key,o.target.value),placeholder:a.key,className:"w-full px-3 py-1.5 bg-dark-bg border border-dark-border rounded-lg text-sm text-dark-text placeholder-dark-muted focus:border-accent-blue focus:outline-none"})]},a.key))}),s.jsxs("div",{className:"flex gap-2 mt-2",children:[s.jsx("button",{onClick:()=>void Z(e,t),className:"px-3 py-1.5 bg-accent-blue text-white rounded-lg text-sm",children:r("connectors.connect")}),s.jsx("button",{onClick:()=>g(null),className:"px-3 py-1.5 bg-dark-surface border border-dark-border rounded-lg text-sm",children:r("common.cancel")})]})]})},te=e=>{var a,o,c;const t=!!j[e.id],n=Q===e.id;return s.jsxs("div",{className:`bg-dark-surface border border-dark-border rounded-lg p-4 transition-opacity ${e.enabled?"":"opacity-80"}`,children:[s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{className:"flex items-start gap-3 flex-1 min-w-0",children:[s.jsx("span",{className:`mt-0.5 shrink-0 px-2 py-1 rounded-md text-[11px] font-semibold uppercase ${e.kind==="lsp"?"bg-accent-purple/15 text-accent-purple":"bg-accent-green/15 text-accent-green"}`,children:e.kind==="lsp"?"LSP":"MCP"}),s.jsxs("div",{className:"min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[s.jsx("span",{className:"font-medium text-sm truncate",children:e.name}),e.custom?s.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-accent-purple/15 text-accent-purple",children:r("connectors.custom")}):null,e.official?s.jsxs("span",{title:"Official",className:"text-[10px] px-1.5 py-0.5 rounded bg-accent-yellow/15 text-accent-yellow",children:["🎖️ ",r("connectors.official")]}):null,e.scope==="cloud"?s.jsxs("span",{title:"Cloud",className:"inline-flex items-center gap-0.5 text-[10px] px-1.5 py-0.5 rounded bg-accent-blue/15 text-accent-blue",children:[s.jsx(K,{size:9}),r("connectors.cloud")]}):s.jsxs("span",{title:"Local",className:"inline-flex items-center gap-0.5 text-[10px] px-1.5 py-0.5 rounded bg-dark-hover text-dark-muted",children:[s.jsx(q,{size:9}),r("connectors.local")]}),e.language?s.jsx("span",{className:"text-[10px]",children:e.language}):null,X(e)]}),s.jsx("p",{className:"text-xs text-dark-muted mt-1 line-clamp-2",children:e.description}),s.jsxs("div",{className:"flex items-center gap-3 mt-2 text-[11px] text-dark-muted flex-wrap",children:[s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx(q,{size:11}),s.jsx("code",{className:"text-[10px]",children:e.installHint})]}),e.transport&&e.transport!=="stdio"?s.jsxs("span",{className:"inline-flex items-center gap-1 text-accent-blue",children:[s.jsx(K,{size:11}),e.transport==="sse"?"SSE":"Streamable HTTP"]}):null,(a=e.languages)!=null&&a.length?s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx(oe,{size:11}),e.languages.join(", ")]}):null,e.kind==="mcp"&&e.toolCount!==void 0?s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx(A,{size:11}),r("connectors.toolCount",{count:e.toolCount})]}):null,(o=e.requiresEnv)!=null&&o.length?s.jsxs("span",{className:"inline-flex items-center gap-1 text-accent-yellow",children:[s.jsx(V,{size:11}),(c=e.missingEnv)!=null&&c.length?`${e.missingEnv.join(", ")} ${r("connectors.missing")}`:r("connectors.envConfigured")]}):null,e.docsUrl?s.jsxs("a",{href:e.docsUrl,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 hover:text-accent-blue",onClick:re=>re.stopPropagation(),children:[s.jsx(de,{size:11}),r("connectors.docs")]}):null]}),e.error?s.jsx("p",{className:"text-[11px] text-accent-red mt-1",children:e.error}):null]})]}),s.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.custom?s.jsx("button",{onClick:()=>void J(e),disabled:t,title:r("connectors.removeCustom"),className:"p-1.5 rounded-lg text-dark-muted hover:text-accent-red hover:bg-accent-red/10 transition-colors disabled:opacity-40",children:s.jsx(ce,{size:14})}):null,!e.installed&&e.enabled?s.jsxs("span",{className:"text-[11px] text-accent-blue flex items-center gap-1",children:[s.jsx(D,{size:11,className:"animate-pulse"}),r("connectors.installing")]}):null,s.jsx("button",{role:"switch","aria-checked":e.enabled,disabled:t,onClick:()=>W(e),className:`relative w-12 h-6 rounded-full transition-colors disabled:opacity-50 ${e.enabled?"bg-accent-green":"bg-dark-border"}`,children:s.jsx("span",{className:`absolute top-1 w-4 h-4 bg-white rounded-full transition-transform ${e.enabled?"left-7":"left-1"}`})})]})]}),n?se(e):null]},e.id)};return s.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden p-4",children:[s.jsxs("div",{className:"flex items-center justify-between mb-3",children:[s.jsxs("h2",{className:"text-lg font-semibold flex items-center gap-2",children:[s.jsx(A,{size:20}),r("nav.connectors"),s.jsxs("span",{className:"text-sm font-normal text-dark-muted",children:["· ",x.filter(e=>e.enabled).length,"/",x.length]})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("button",{onClick:()=>N(e=>!e),className:"flex items-center gap-2 px-3 py-1.5 bg-accent-blue text-white rounded hover:bg-accent-blue/90 transition-colors",children:[s.jsx(ae,{size:14}),r("connectors.addCustom")]}),s.jsxs("button",{onClick:()=>void y(),className:"flex items-center gap-2 px-3 py-1.5 bg-dark-surface border border-dark-border rounded hover:bg-dark-hover transition-colors",children:[s.jsx(ne,{size:14}),r("common.refresh")]})]})]}),Y?s.jsxs("div",{className:"mb-4 p-4 bg-dark-surface border border-dark-border rounded-lg",children:[s.jsxs("div",{className:"flex items-center justify-between mb-3",children:[s.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium",children:[s.jsx(le,{size:15,className:"text-accent-purple"}),r("connectors.customTitle")]}),s.jsx("div",{className:"flex gap-1",children:[["stdio","🖥️ "+r("connectors.customLocal")],["http","🌐 HTTP"],["sse","📡 SSE"]].map(([e,t])=>s.jsx("button",{onClick:()=>i(n=>({...n,transport:e})),className:`px-3 py-1.5 rounded-lg text-xs transition-colors ${l.transport===e?"bg-accent-blue text-white":"bg-dark-bg border border-dark-border hover:bg-dark-hover"}`,children:t},e))})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] text-dark-muted mb-1",children:r("connectors.customName")}),s.jsx("input",{value:l.name,onChange:e=>i(t=>({...t,name:e.target.value})),placeholder:"my-server",className:"w-full px-3 py-1.5 bg-dark-bg border border-dark-border rounded-lg text-sm text-dark-text placeholder-dark-muted focus:border-accent-blue focus:outline-none"})]}),l.transport==="stdio"?s.jsxs(s.Fragment,{children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] text-dark-muted mb-1",children:r("connectors.customCommand")}),s.jsx("input",{value:l.command,onChange:e=>i(t=>({...t,command:e.target.value})),placeholder:"npx -y @some/mcp-server",className:"w-full px-3 py-1.5 bg-dark-bg border border-dark-border rounded-lg text-sm text-dark-text placeholder-dark-muted focus:border-accent-blue focus:outline-none"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] text-dark-muted mb-1",children:r("connectors.customArgs")}),s.jsx("input",{value:l.args,onChange:e=>i(t=>({...t,args:e.target.value})),placeholder:"--arg value",className:"w-full px-3 py-1.5 bg-dark-bg border border-dark-border rounded-lg text-sm text-dark-text placeholder-dark-muted focus:border-accent-blue focus:outline-none"})]})]}):s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] text-dark-muted mb-1",children:r("connectors.customUrl")}),s.jsx("input",{value:l.url,onChange:e=>i(t=>({...t,url:e.target.value})),placeholder:"https://mcp.example.com/mcp",className:"w-full px-3 py-1.5 bg-dark-bg border border-dark-border rounded-lg text-sm text-dark-text placeholder-dark-muted focus:border-accent-blue focus:outline-none"})]}),l.transport==="stdio"?s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] text-dark-muted mb-1",children:r("connectors.customEnv")}),s.jsx("input",{value:l.env,onChange:e=>i(t=>({...t,env:e.target.value})),placeholder:"KEY=value, KEY2=value2",className:"w-full px-3 py-1.5 bg-dark-bg border border-dark-border rounded-lg text-sm text-dark-text placeholder-dark-muted focus:border-accent-blue focus:outline-none"})]}):s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] text-dark-muted mb-1",children:r("connectors.customHeaders")}),s.jsx("input",{value:l.headers,onChange:e=>i(t=>({...t,headers:e.target.value})),placeholder:"Authorization=Bearer xxx",className:"w-full px-3 py-1.5 bg-dark-bg border border-dark-border rounded-lg text-sm text-dark-text placeholder-dark-muted focus:border-accent-blue focus:outline-none"})]})]}),s.jsxs("div",{className:"flex gap-2 mt-3",children:[s.jsx("button",{onClick:()=>void I(),disabled:!!j.__add,className:"px-3 py-1.5 bg-accent-blue text-white rounded-lg text-sm disabled:opacity-50",children:j.__add?s.jsx(w,{size:14,className:"animate-spin"}):r("connectors.add")}),s.jsx("button",{onClick:()=>N(!1),className:"px-3 py-1.5 bg-dark-surface border border-dark-border rounded-lg text-sm",children:r("common.cancel")})]})]}):null,s.jsx("div",{className:"flex gap-1 mb-3",children:[["all",`${r("connectors.all")} (${x.length})`],["lsp",`LSP (${x.filter(e=>e.kind==="lsp").length})`],["mcp",`MCP (${x.filter(e=>e.kind==="mcp").length})`]].map(([e,t])=>s.jsx("button",{onClick:()=>G(e),className:`px-3 py-1.5 rounded-lg text-sm transition-colors ${k===e?"bg-accent-blue text-white":"bg-dark-surface border border-dark-border hover:bg-dark-hover"}`,children:t},e))}),s.jsx("div",{className:"flex gap-3 mb-3",children:s.jsxs("div",{className:"flex-1 relative",children:[s.jsx(F,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-dark-muted"}),s.jsx("input",{type:"text",value:v,onChange:e=>O(e.target.value),placeholder:r("connectors.searchPlaceholder"),className:"w-full pl-10 pr-4 py-2 bg-dark-surface border border-dark-border rounded-lg text-dark-text placeholder-dark-muted focus:border-accent-blue focus:outline-none"})]})}),s.jsxs("div",{className:"flex gap-1 mb-4 flex-wrap",children:[s.jsxs("button",{onClick:()=>$(null),className:`px-3 py-1.5 rounded-lg text-sm transition-colors ${b?"bg-dark-surface border border-dark-border hover:bg-dark-hover":"bg-accent-blue text-white"}`,children:[r("connectors.all")," ",s.jsxs("span",{className:"opacity-70 text-xs",children:["(",h.length,")"]})]}),ee.map(e=>{const t=h.filter(n=>n.category===e).length;return s.jsxs("button",{onClick:()=>$(b===e?null:e),className:`px-3 py-1.5 rounded-lg text-sm transition-colors ${b===e?"bg-accent-blue text-white":"bg-dark-surface border border-dark-border hover:bg-dark-hover"}`,children:[xe[e]??e," ",s.jsxs("span",{className:"opacity-70 text-xs",children:["(",t,")"]})]},e)})]}),z?s.jsx("div",{className:"mb-4 px-3 py-2 bg-accent-red/10 border border-accent-red/30 rounded-lg text-accent-red text-sm",children:z}):null,s.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto custom-scrollbar",children:R.length===0?s.jsxs("div",{className:"text-center text-dark-muted text-sm py-10",children:[s.jsx(F,{size:24,className:"mx-auto mb-2 opacity-50"}),r("connectors.noResults")]}):s.jsx("div",{className:"space-y-2",children:R.map(te)})})]})}export{fe as ConnectorsView};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{j as l}from"./markdown-
|
|
1
|
+
import{j as l}from"./markdown-D0iUI0Yw.js";import{r as c,W as J,V as Se,ak as Ce,R as Me,at as Ne,x as ke,au as ce,$ as Pe,D as le,X as Ee,a as Re,b as Le,av as $e}from"./icons-B5yCkBjC.js";import{a as Q,t as $}from"./index-YAnKQ1Q6.js";import"./react-vendor-Bxu3r3ox.js";import"./state-C80Yzgl0.js";function ue(e,t){(t==null||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function ze(e){if(Array.isArray(e))return e}function Ae(e,t,r){return(t=qe(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function De(e,t){var r=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(r!=null){var n,o,u,h,g=[],b=!0,x=!1;try{if(u=(r=r.call(e)).next,t!==0)for(;!(b=(n=u.call(r)).done)&&(g.push(n.value),g.length!==t);b=!0);}catch(M){x=!0,o=M}finally{try{if(!b&&r.return!=null&&(h=r.return(),Object(h)!==h))return}finally{if(x)throw o}}return g}}function Fe(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
2
2
|
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function de(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(o){return Object.getOwnPropertyDescriptor(e,o).enumerable})),r.push.apply(r,n)}return r}function fe(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};t%2?de(Object(r),!0).forEach(function(n){Ae(e,n,r[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):de(Object(r)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(r,n))})}return e}function Te(e,t){if(e==null)return{};var r,n,o=Ie(e,t);if(Object.getOwnPropertySymbols){var u=Object.getOwnPropertySymbols(e);for(n=0;n<u.length;n++)r=u[n],t.indexOf(r)===-1&&{}.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}function Ie(e,t){if(e==null)return{};var r={};for(var n in e)if({}.hasOwnProperty.call(e,n)){if(t.indexOf(n)!==-1)continue;r[n]=e[n]}return r}function Ve(e,t){return ze(e)||De(e,t)||We(e,t)||Fe()}function Ue(e,t){if(typeof e!="object"||!e)return e;var r=e[Symbol.toPrimitive];if(r!==void 0){var n=r.call(e,t);if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function qe(e){var t=Ue(e,"string");return typeof t=="symbol"?t:t+""}function We(e,t){if(e){if(typeof e=="string")return ue(e,t);var r={}.toString.call(e).slice(8,-1);return r==="Object"&&e.constructor&&(r=e.constructor.name),r==="Map"||r==="Set"?Array.from(e):r==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?ue(e,t):void 0}}function He(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function pe(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(o){return Object.getOwnPropertyDescriptor(e,o).enumerable})),r.push.apply(r,n)}return r}function he(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};t%2?pe(Object(r),!0).forEach(function(n){He(e,n,r[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):pe(Object(r)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(r,n))})}return e}function Be(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return function(n){return t.reduceRight(function(o,u){return u(o)},n)}}function X(e){return function t(){for(var r=this,n=arguments.length,o=new Array(n),u=0;u<n;u++)o[u]=arguments[u];return o.length>=e.length?e.apply(this,o):function(){for(var h=arguments.length,g=new Array(h),b=0;b<h;b++)g[b]=arguments[b];return t.apply(r,[].concat(o,g))}}}function ne(e){return{}.toString.call(e).includes("Object")}function Ke(e){return!Object.keys(e).length}function _(e){return typeof e=="function"}function Qe(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Ge(e,t){return ne(t)||A("changeType"),Object.keys(t).some(function(r){return!Qe(e,r)})&&A("changeField"),t}function Je(e){_(e)||A("selectorType")}function Xe(e){_(e)||ne(e)||A("handlerType"),ne(e)&&Object.values(e).some(function(t){return!_(t)})&&A("handlersType")}function Ye(e){e||A("initialIsRequired"),ne(e)||A("initialType"),Ke(e)&&A("initialContent")}function _e(e,t){throw new Error(e[t]||e.default)}var Ze={initialIsRequired:"initial state is required",initialType:"initial state should be an object",initialContent:"initial state shouldn't be an empty object",handlerType:"handler should be an object or a function",handlersType:"all handlers should be a functions",selectorType:"selector should be a function",changeType:"provided value of changes should be an object",changeField:'it seams you want to change a field in the state which is not specified in the "initial" state',default:"an unknown error accured in `state-local` package"},A=X(_e)(Ze),te={changes:Ge,selector:Je,handler:Xe,initial:Ye};function et(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};te.initial(e),te.handler(t);var r={current:e},n=X(nt)(r,t),o=X(rt)(r),u=X(te.changes)(e),h=X(tt)(r);function g(){var x=arguments.length>0&&arguments[0]!==void 0?arguments[0]:function(M){return M};return te.selector(x),x(r.current)}function b(x){Be(n,o,u,h)(x)}return[g,b]}function tt(e,t){return _(t)?t(e.current):t}function rt(e,t){return e.current=he(he({},e.current),t),t}function nt(e,t,r){return _(t)?t(e.current):Object.keys(r).forEach(function(n){var o;return(o=t[n])===null||o===void 0?void 0:o.call(t,e.current[n])}),r}var at={create:et},it={paths:{vs:"https://cdn.jsdelivr.net/npm/monaco-editor@0.55.1/min/vs"}};function ot(e){return function t(){for(var r=this,n=arguments.length,o=new Array(n),u=0;u<n;u++)o[u]=arguments[u];return o.length>=e.length?e.apply(this,o):function(){for(var h=arguments.length,g=new Array(h),b=0;b<h;b++)g[b]=arguments[b];return t.apply(r,[].concat(o,g))}}}function st(e){return{}.toString.call(e).includes("Object")}function ct(e){return e||me("configIsRequired"),st(e)||me("configType"),e.urls?(lt(),{paths:{vs:e.urls.monacoBase}}):e}function lt(){console.warn(ge.deprecation)}function ut(e,t){throw new Error(e[t]||e.default)}var ge={configIsRequired:"the configuration object is required",configType:"the configuration object should be an object",default:"an unknown error accured in `@monaco-editor/loader` package",deprecation:`Deprecation warning!
|
|
3
3
|
You are using deprecated way of configuration.
|
|
4
4
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as t}from"./markdown-D0iUI0Yw.js";import{r as l,h as Z,aB as z,aC as ee,m as te}from"./icons-B5yCkBjC.js";import{e as se,l as ae,w as v,j as ne,R as le,v as re,x as oe,k as W,c as ie,m as de,u as ce,M as xe,A as N,y as ue}from"./index-YAnKQ1Q6.js";import{b as pe,t as me,v as he,s as fe,T as ve,P as F}from"./HookApprovalPreview-C8fU_Umi.js";import"./react-vendor-Bxu3r3ox.js";import"./state-C80Yzgl0.js";const b=15;function we({isOpen:u,onCloseModal:w}){const{t:s}=se("hook"),i=ae(),p=i.pendingApprovals,H=i.autoMode,M=i.setAutoMode,[I,T]=l.useState(0),[n,_]=l.useState(!1),[m,S]=l.useState(b),r=l.useRef(null),d=l.useRef(!1);l.useEffect(()=>{if(p.length!==0){if(H){p.forEach(a=>{v.send({type:"hook_allow",data:JSON.stringify({approvalId:a.approvalId})})}),i.clearApprovals();return}T(a=>Math.min(a,p.length-1))}},[p.length,H]);const e=p[I]??null,y=p.length>0&&e!==null,$=p.length,L=y?$-I-1:0;l.useEffect(()=>{if(!(!y||n||!u||!e))return S(b),r.current=setInterval(()=>{S(a=>a<=1?(r.current&&clearInterval(r.current),0):a-1)},1e3),()=>{r.current&&clearInterval(r.current)}},[y,n,u,e==null?void 0:e.approvalId]);const c=e?ne(e.toolName,e.askPayload):{level:"MEDIUM",reasonKey:"risk_default"},f=le[c.level],U=re[c.level==="CRITICAL"?"critical":c.level==="HIGH"?"high":c.level==="LOW"?"low":"medium"],A=e?pe(e.toolName,e.askPayload):null,D=e?oe(e.toolName,e.askPayload):null,C=e?{verb:he(e.toolName),target:me(e.toolName,e.askPayload)}:null,G=e?W(e.askPayload)!==null:!1,h=e?fe(e.toolName,e.askPayload):null,B=m/b*100,E=m<=5,Q=ue(b-m),O=l.useCallback((a,o)=>{const K=ie.getState().activeSessionId;K&&de.getState().updateHookApprovalStatus(K,a,o)},[]),x=l.useCallback(a=>{e&&(a&&O(e.approvalId,a),_(!0),setTimeout(()=>{i.removeApproval(e.approvalId),T(0),_(!1),d.current=!1,S(b)},200))},[e==null?void 0:e.approvalId,i,O]),k=l.useCallback(()=>{!e||n||d.current||(d.current=!0,r.current&&clearInterval(r.current),v.send({type:"hook_allow",data:JSON.stringify({approvalId:e.approvalId})}),x("approved"))},[e,x,n]),g=l.useCallback(()=>{!e||n||d.current||(d.current=!0,r.current&&clearInterval(r.current),v.send({type:"hook_deny",data:JSON.stringify({approvalId:e.approvalId})}),x("denied"))},[e,x,n]),P=l.useCallback(()=>{if(!e||n||d.current)return;d.current=!0,r.current&&clearInterval(r.current);const a=W(e.askPayload);a?(i.addToSessionAllowList(e.toolName,a),v.send({type:"hook_allow",data:JSON.stringify({approvalId:e.approvalId,sessionAllow:!0})})):(i.addToSessionAllowList(e.toolName),v.send({type:"hook_allow",data:JSON.stringify({approvalId:e.approvalId})})),x("approved")},[e,x,i,n]),R=l.useCallback(()=>{!e||n||d.current||(d.current=!0,r.current&&clearInterval(r.current),M(!0),ce.getState().setAuto(!0),v.send({type:"hook_allow",data:JSON.stringify({approvalId:e.approvalId})}),x("approved"))},[e,x,n,M]),j=((e==null?void 0:e.timeoutMs)??15e3)>0,J=(e==null?void 0:e.timeoutAction)==="deny"?g:k;if(l.useEffect(()=>{m===0&&u&&!n&&e&&j&&J()},[m,u,n,e,J,j]),l.useEffect(()=>{if(!u)return;const a=o=>{o.key==="Escape"?(o.preventDefault(),o.stopPropagation(),g()):o.key==="Enter"?(o.preventDefault(),k()):o.key==="1"?k():o.key==="2"?g():o.key==="3"?P():o.key==="4"&&R()};return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[u,k,g,P,R]),!y||!e)return null;const V=s("optionAllowHint"),q=s("optionDenyHint"),X=G?s("optionAllowPathHint"):s("optionAllowAlwaysHint",{tool:e.toolName}),Y=s("optionAutoModeHint");return t.jsx(xe,{isOpen:u,onClose:()=>w==null?void 0:w(),title:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(z,{className:"w-4 h-4 text-yellow-400"}),t.jsx("span",{children:s("hookApproval")}),t.jsxs("span",{className:"text-xs text-dark-muted",children:["(",I+1,"/",$,")"]})]}),size:"lg",children:t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:`flex items-center gap-2 px-3 py-2 rounded-lg ${f.bg} border ${f.border}`,children:[t.jsxs("span",{className:`px-1.5 py-0.5 rounded text-xs font-bold border ${f.badge}`,children:[f.icon," ",c.level]}),t.jsx("span",{className:"text-xs text-dark-muted truncate",children:s(c.reasonKey)}),t.jsxs("div",{className:"flex items-center gap-1.5 ml-auto shrink-0",children:[t.jsx(Z,{size:12,className:E?"text-accent-red":"text-dark-muted"}),t.jsx("span",{className:`text-xs font-mono ${E?"text-accent-red animate-pulse":"text-dark-muted"}`,children:j?`${m}s`:"∞"}),t.jsx("div",{className:"w-12 h-1.5 bg-dark-border rounded-full overflow-hidden",children:t.jsx("div",{className:`h-full rounded-full transition-all duration-700 ${E?"bg-accent-red":m<=8?"bg-accent-yellow":"bg-accent-green"}`,style:{width:`${B}%`}})})]})]}),t.jsxs("div",{className:"flex items-start justify-between gap-3",children:[t.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[t.jsx("span",{className:"flex-none w-7 h-7 rounded-lg bg-accent-blue/10 text-accent-blue inline-flex items-center justify-center",children:t.jsx(z,{size:15})}),C&&t.jsx(ve,{pre:s(C.verb),obj:C.target})]}),h&&(h.external&&h.path?t.jsxs("span",{className:"flex items-center gap-1 text-[11px] px-1.5 py-0.5 rounded bg-amber-500/10 text-amber-400 border border-amber-500/30 shrink-0",title:h.path,children:[t.jsx(ee,{size:10}),s("scopeExternal"),": ",h.path.length>48?`${h.path.slice(0,47)}…`:h.path]}):t.jsx("span",{className:"text-[11px] text-dark-muted/60 shrink-0",children:s("scopeLocal")}))]}),t.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[t.jsx("span",{className:"text-dark-muted shrink-0",children:s("tool")}),t.jsx("code",{className:"text-accent-blue font-mono text-xs bg-dark-surface px-1.5 py-0.5 rounded truncate",children:e.toolName}),t.jsx("span",{className:"text-dark-muted/50",children:Q}),t.jsx("span",{className:"text-dark-muted/50",children:U.label}),e.timeoutAction&&t.jsxs("span",{className:`text-xs ${e.timeoutAction==="deny"?"text-accent-red":"text-accent-green"}`,children:["timeout: ",j?`${e.timeoutAction==="allow"?"auto-allow":"auto-deny"}${e.timeoutMs?` (${(e.timeoutMs/1e3).toFixed(0)}s)`:""}`:s("timeoutWaitUser")]})]}),A?t.jsx(F,{text:A.text,mono:A.mono}):D?t.jsx(F,{text:D}):null,(c.level==="CRITICAL"||c.level==="HIGH")&&t.jsxs("div",{className:`flex items-center gap-1.5 text-xs px-2 py-1.5 rounded ${f.bg} ${f.text}`,children:[t.jsx(te,{size:13}),t.jsx("span",{children:c.level==="CRITICAL"?s("highRiskWarning"):s("mediumRiskConfirm")})]}),t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsxs("button",{onClick:k,disabled:n,className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-accent-blue text-white text-sm font-medium hover:opacity-90 shadow-sm transition-all disabled:opacity-50",children:[t.jsx("span",{className:"text-[10px] font-mono bg-white/20 rounded px-1",children:"1"}),t.jsx("span",{children:N.allow.label}),t.jsx("span",{className:"text-[11px] text-white/70 hidden sm:inline",children:V})]}),t.jsxs("button",{onClick:P,disabled:n,className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg border border-dark-border bg-dark-bg text-dark-text hover:bg-dark-hover text-sm transition-colors disabled:opacity-50",children:[t.jsx("span",{className:"text-[10px] font-mono text-dark-muted bg-dark-surface rounded px-1",children:"3"}),t.jsx("span",{children:N.allow_session.label}),t.jsx("span",{className:"text-[11px] text-dark-muted/60 hidden sm:inline",children:X})]}),t.jsxs("button",{onClick:R,disabled:n,className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg border border-dark-border bg-dark-bg text-dark-text hover:bg-dark-hover text-sm transition-colors disabled:opacity-50",children:[t.jsx("span",{className:"text-[10px] font-mono text-dark-muted bg-dark-surface rounded px-1",children:"4"}),t.jsx("span",{children:N.auto.label}),t.jsx("span",{className:"text-[11px] text-dark-muted/60 hidden sm:inline",children:Y})]}),t.jsx("span",{className:"flex-1"}),t.jsxs("button",{onClick:g,disabled:n,className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-dark-muted hover:bg-red-500/10 hover:text-red-400 text-sm transition-colors disabled:opacity-50",children:[t.jsx("span",{className:"text-[10px] font-mono text-dark-muted/60 rounded px-1",children:"2"}),t.jsx("span",{children:N.deny.label}),t.jsx("span",{className:"text-[11px] text-dark-muted/60 hidden sm:inline",children:q})]})]}),t.jsxs("div",{className:"flex items-center justify-between text-xs text-dark-muted/60",children:[t.jsx("span",{children:s("shortcutHint")}),t.jsx("span",{children:L>0?s("morePending",{n:L}):s("lastItem")})]})]})})}export{we as HookApprovalModal};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{k as w,e as R}from"./index-YAnKQ1Q6.js";import{j as a}from"./markdown-D0iUI0Yw.js";import{r as v}from"./icons-B5yCkBjC.js";function b(s){const n=s??"";let e=n,t=null,i=null;try{const r=JSON.parse(n);if(r&&typeof r=="object")if("payload"in r){i=typeof r.toolName=="string"?r.toolName:null;const o=r.payload;typeof o=="string"?e=o:o&&typeof o=="object"?(t=o,e=JSON.stringify(o,null,2)):e=""}else Array.isArray(r)||(t=r)}catch{e=n}if(!t&&e.length>0&&/^[\s]*[{[]/.test(e))try{const r=JSON.parse(e);r&&typeof r=="object"&&!Array.isArray(r)&&(t=r)}catch{}return{toolName:i,payloadText:e,args:t}}const p=/\b(bash|shell|exec|cmd|powershell|terminal)\b/i,h=/write_file|write|save|create|upload|deploy|publish/i,x=/edit_file|edit|patch|apply|update|replace/i,y=/read_file|read|view|cat|open|list|dir\b/i,N=/file_delete|delete|remove|unlink|\brm\b|\bdel\b/i,k=/\b(glob|find|locate)\b/i,A=/\b(grep|rg|search_contents)\b/i,S=/web_search|search_web|browse/i,E=/web_fetch|fetch|http|curl|wget|download|request|api/i,T=/git|commit|merge|rebase|push|checkout/i,j=/install|uninstall|npm|pnpm|yarn|pip|cargo|gem|apt|brew|choco/i,d=/send_message|send_file|message|notify|post/i;function C(s){const n=s.toLowerCase();return p.test(n)?"verbRunCommand":S.test(n)?"verbSearchWeb":h.test(n)?"verbWriteFile":x.test(n)?"verbEditFile":N.test(n)?"verbDeleteFile":y.test(n)?"verbReadFile":A.test(n)?"verbSearchContents":k.test(n)?"verbFindFiles":E.test(n)?"verbFetchUrl":T.test(n)?"verbGit":j.test(n)?"verbInstall":d.test(n)?"verbSendMessage":"verbRunTool"}function c(s,n){const e=(s??"").replace(/\s+/g," ").trim();return e.length>n?`${e.slice(0,n-1)}…`:e}function L(s){if(!s)return null;for(const n of["file_path","filePath","path","file","target"]){const e=s[n];if(typeof e=="string"&&e.length>0)return e}return null}function D(s,n){const{payloadText:e,args:t}=b(n),i=s.toLowerCase();if(p.test(i))return"";const r=L(t);if(r)return r;const o=e.match(/(?:file_path|path|file)["\s:=]+([^\s",}]+)/i);if(o!=null&&o[1])return o[1];if(E.test(i)&&typeof(t==null?void 0:t.url)=="string"&&t.url)return c(t.url,48);if(d.test(i)){const l=typeof(t==null?void 0:t.text)=="string"?t.text:typeof(t==null?void 0:t.message)=="string"?t.message:e;return c(l,48)}return c(e,48)}function W(s,n){const{payloadText:e,args:t}=b(n),i=s.toLowerCase();if(p.test(i)){const r=typeof(t==null?void 0:t.command)=="string"?t.command:e;return r?{text:r,mono:!0}:null}if(h.test(i)||x.test(i)){const r=typeof(t==null?void 0:t.content)=="string"?t.content:typeof(t==null?void 0:t.data)=="string"?t.data:"";if(r)return{text:r,mono:!0};if(t){const o=m(t);if(o)return{text:o,mono:!0}}return e?{text:e,mono:!0}:null}if(d.test(i)){const r=typeof(t==null?void 0:t.text)=="string"?t.text:typeof(t==null?void 0:t.message)=="string"?t.message:e;return r?{text:r,mono:!1}:null}if(y.test(i))return null;if(t){const r=m(t);if(r)return{text:r,mono:!0}}return e?{text:e,mono:!0}:null}function m(s){return s?Object.entries(s).filter(([,n])=>n!=null).map(([n,e])=>{let t=typeof e=="string"?e:JSON.stringify(e);return t.length>96&&(t=`${t.slice(0,95)}…`),`${n}=${t.replace(/\n/g," ")}`}).join(" "):""}function $(s,n){const e=w(n);return e?{path:e,external:!0}:{key:"scopeLocal",external:!1}}function O({pre:s,obj:n}){return a.jsxs("span",{className:"min-w-0 text-sm text-dark-muted",children:[a.jsx("span",{children:s}),n&&a.jsx("b",{className:"font-semibold text-dark-text",children:n})]})}const u=5,f=420;function J({text:s,mono:n=!0}){const{t:e}=R("hook"),[t,i]=v.useState(!1),r=s.split(`
|
|
2
|
+
`),o=r.length>u||s.length>f;let l=s;!t&&o&&(l=r.slice(0,u).join(`
|
|
3
|
+
`),l.length>f&&(l=`${l.slice(0,f).trimEnd()}…`));const g=t?e("showLess"):r.length>u?e("showAllLines",{n:r.length}):e("showAll");return a.jsxs("div",{className:`rounded-lg border border-dark-border bg-dark-surface p-2.5 text-xs leading-relaxed break-all whitespace-pre-wrap ${n?"font-mono":""} text-dark-text`,children:[l,o&&a.jsx("button",{type:"button",onClick:()=>i(_=>!_),className:"mt-1 block text-[11px] text-accent-blue hover:underline",children:g})]})}export{J as P,O as T,W as b,$ as s,D as t,C as v};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-YAnKQ1Q6.js","assets/markdown-D0iUI0Yw.js","assets/icons-B5yCkBjC.js","assets/react-vendor-Bxu3r3ox.js","assets/state-C80Yzgl0.js","assets/index-DVZ3Ws5S.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{a as j,_ as L}from"./index-YAnKQ1Q6.js";import{j as e}from"./markdown-D0iUI0Yw.js";import{r as N,ap as z,aq as F,ar as M,a4 as U,X as I,ao as $,C as Y,b as G,as as J,ac as B,ad as W,R as q,ak as V,D as X,P as K}from"./icons-B5yCkBjC.js";import{c as Q}from"./state-C80Yzgl0.js";import"./react-vendor-Bxu3r3ox.js";const P=Q((l,o)=>({rules:[],stats:null,events:[],agents:[],loading:!1,error:null,fieldErrors:null,formOpen:!1,editingRule:null,dryRunResult:null,loadRules:async()=>{const s=await j.hooks.list();s.success&&Array.isArray(s.data)?l({rules:s.data}):s.success&&s.data&&!Array.isArray(s.data)?l({error:"服务端返回的规则数据格式异常"}):l({error:s.error||"Failed to load rules"})},loadStats:async()=>{const s=await j.hooks.stats();s.success&&s.data&&l({stats:s.data})},loadEvents:async()=>{const s=await j.hooks.events();s.success&&Array.isArray(s.data)?l({events:s.data}):s.success&&s.data&&!Array.isArray(s.data)&&l({error:"服务端返回的事件数据格式异常"})},loadAgents:async()=>{const s=await j.hooks.agents();s.success&&Array.isArray(s.data)?l({agents:s.data}):s.success&&s.data&&!Array.isArray(s.data)&&l({error:"服务端返回的Agent数据格式异常"})},loadAll:async()=>{l({loading:!0,error:null});try{await Promise.all([o().loadRules(),o().loadStats(),o().loadEvents(),o().loadAgents()])}catch(s){l({error:String(s)})}finally{l({loading:!1})}},createRule:async s=>{l({fieldErrors:null});const r=await j.hooks.create(s);if(r.success)return await o().loadRules(),await o().loadStats(),l({formOpen:!1,editingRule:null}),!0;if(r.error){l({error:r.error});try{const m=JSON.parse(r.error);m.fieldErrors&&l({fieldErrors:m.fieldErrors})}catch{}}return!1},updateRule:async(s,r)=>{l({fieldErrors:null});const m=await j.hooks.update(s,r);return m.success?(await o().loadRules(),l({formOpen:!1,editingRule:null}),!0):(l({error:m.error||"Update failed"}),!1)},deleteRule:async s=>{const r=await j.hooks.delete(s);return r.success?(await o().loadRules(),await o().loadStats(),!0):(l({error:r.error||"Delete failed"}),!1)},batchDelete:async s=>{const r=await j.hooks.batchDelete(s);return r.success?(await o().loadRules(),await o().loadStats(),!0):(l({error:r.error||"Batch delete failed"}),!1)},toggleRule:async(s,r)=>(await j.hooks.toggle(s,r)).success?(l(v=>({rules:v.rules.map(d=>d.name===s?{...d,enabled:r}:d)})),!0):(await o().loadRules(),!1),batchToggle:async(s,r)=>(await j.hooks.batchToggle(s,r)).success?(l(v=>({rules:v.rules.map(d=>s.includes(d.name)?{...d,enabled:r}:d)})),!0):(await o().loadRules(),!1),dryRun:async s=>{const r=await j.hooks.dryRun(s);return r.success&&r.data?(l({dryRunResult:r.data}),r.data):(l({error:r.error||"Dry-run failed"}),null)},openForm:s=>l({formOpen:!0,editingRule:s||null,dryRunResult:null,fieldErrors:null}),closeForm:()=>l({formOpen:!1,editingRule:null,dryRunResult:null,fieldErrors:null}),setDryRunResult:s=>l({dryRunResult:s}),clearError:()=>l({error:null}),clearFieldErrors:()=>l({fieldErrors:null})})),Z={SYSTEM:"bg-accent-red/15 text-accent-red",SECURITY:"bg-accent-orange/15 text-accent-orange",PROJECT:"bg-accent-blue/15 text-accent-blue",USER:"bg-accent-green/15 text-accent-green",PLUGIN:"bg-accent-purple/15 text-accent-purple"},ee={SHELL:"bg-accent-yellow/15 text-accent-yellow",HTTP:"bg-accent-cyan/15 text-accent-cyan",PROMPT:"bg-accent-purple/15 text-accent-purple",AGENT:"bg-accent-blue/15 text-accent-blue"};function te({rules:l,onEdit:o}){const{toggleRule:s,deleteRule:r,batchDelete:m,batchToggle:v}=P(),[d,h]=N.useState(new Set),[T,k]=N.useState(!1),y=Array.isArray(l)?l:[];if(y.length===0)return e.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 py-16 text-dark-muted",children:[e.jsx("div",{className:"text-4xl opacity-60",children:"🪝"}),e.jsx("p",{className:"text-sm",children:"暂无 Hook 规则"}),e.jsx("p",{className:"text-xs text-dark-muted/70",children:'点击右上角"新增规则"创建第一个 Hook'})]});const S=t=>{const i=new Set(d);i.has(t)?i.delete(t):i.add(t),h(i),k(i.size===y.length)},f=()=>{T?(h(new Set),k(!1)):(h(new Set(y.map(t=>t.name))),k(!0))},x=()=>{d.size!==0&&confirm(`确认删除 ${d.size} 条规则?`)&&(m(Array.from(d)),h(new Set),k(!1))},p=t=>{d.size!==0&&(v(Array.from(d),t),h(new Set),k(!1))};return e.jsxs("div",{className:"flex flex-1 flex-col min-h-0",children:[d.size>0&&e.jsxs("div",{className:"mb-2 flex items-center gap-2 rounded-lg border border-accent-blue/30 bg-accent-blue/5 px-3 py-1.5 text-sm",children:[e.jsxs("span",{className:"text-dark-muted",children:["已选 ",d.size," 项"]}),e.jsx("button",{onClick:()=>p(!0),className:"rounded bg-accent-green/15 px-2 py-0.5 text-accent-green transition-colors hover:bg-accent-green/25",children:"全部启用"}),e.jsx("button",{onClick:()=>p(!1),className:"rounded bg-dark-hover px-2 py-0.5 text-dark-text transition-colors hover:bg-dark-border",children:"全部禁用"}),e.jsx("button",{onClick:x,className:"rounded bg-accent-red/15 px-2 py-0.5 text-accent-red transition-colors hover:bg-accent-red/25",children:"删除"})]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-auto custom-scrollbar rounded-xl border border-dark-border",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"sticky top-0 bg-dark-hover text-dark-muted",children:e.jsxs("tr",{children:[e.jsx("th",{className:"w-8 p-2.5",children:e.jsx("button",{onClick:f,children:T?e.jsx(z,{size:14}):e.jsx(F,{size:14})})}),e.jsx("th",{className:"p-2.5 text-left font-medium",children:"名称"}),e.jsx("th",{className:"p-2.5 text-left font-medium",children:"事件"}),e.jsx("th",{className:"p-2.5 text-left font-medium",children:"类型"}),e.jsx("th",{className:"p-2.5 text-left font-medium",children:"优先级"}),e.jsx("th",{className:"p-2.5 text-left font-medium",children:"状态"}),e.jsx("th",{className:"p-2.5 text-right font-medium",children:"操作"})]})}),e.jsx("tbody",{className:"divide-y divide-dark-border",children:y.map(t=>e.jsxs("tr",{className:"transition-colors hover:bg-dark-hover/50",children:[e.jsx("td",{className:"p-2.5",children:e.jsx("button",{onClick:()=>S(t.name),children:d.has(t.name)?e.jsx(z,{size:14,className:"text-accent-blue"}):e.jsx(F,{size:14,className:"text-dark-muted"})})}),e.jsxs("td",{className:"p-2.5",children:[e.jsx("div",{className:"font-medium text-dark-text",children:t.name}),t.description&&e.jsx("div",{className:"mt-0.5 max-w-[220px] truncate text-xs text-dark-muted",children:t.description})]}),e.jsx("td",{className:"p-2.5",children:e.jsxs("div",{className:"flex flex-wrap gap-1",children:[Array.isArray(t.events)&&t.events.slice(0,3).map(i=>e.jsx("span",{className:"rounded bg-dark-hover px-1.5 py-0.5 text-xs text-dark-text",children:i},i)),Array.isArray(t.events)&&t.events.length>3&&e.jsxs("span",{className:"px-1 py-0.5 text-xs text-dark-muted",children:["+",t.events.length-3]})]})}),e.jsx("td",{className:"p-2.5",children:e.jsx("span",{className:`rounded px-1.5 py-0.5 text-xs font-medium ${ee[t.implementationType]||"bg-dark-hover text-dark-muted"}`,children:t.implementationType})}),e.jsx("td",{className:"p-2.5",children:e.jsx("span",{className:`rounded px-1.5 py-0.5 text-xs font-medium ${Z[t.priority]||"bg-dark-hover text-dark-muted"}`,children:t.priority})}),e.jsx("td",{className:"p-2.5",children:e.jsx("button",{onClick:()=>s(t.name,!t.enabled),className:`relative h-5 w-9 rounded-full transition-colors ${t.enabled?"bg-accent-green":"bg-dark-border"}`,title:t.enabled?"点击禁用":"点击启用",children:e.jsx("span",{className:`absolute top-0.5 block h-3.5 w-3.5 rounded-full bg-white transition-all ${t.enabled?"left-[18px]":"left-[2px]"}`})})}),e.jsx("td",{className:"p-2.5",children:e.jsxs("div",{className:"flex items-center justify-end gap-1",children:[e.jsx("button",{onClick:()=>o(t),className:"rounded p-1 text-dark-muted transition-colors hover:bg-dark-hover hover:text-accent-blue",title:"编辑",children:e.jsx(M,{size:14})}),e.jsx("button",{onClick:()=>{confirm(`删除规则 "${t.name}"?`)&&r(t.name)},className:"rounded p-1 text-dark-muted transition-colors hover:bg-dark-hover hover:text-accent-red",title:"删除",children:e.jsx(U,{size:14})})]})})]},t.name))})]})})]})}const ae={name:"",description:"",events:[],implementationType:"SHELL",command:"",url:"",promptTemplate:"",agentName:"",priority:"USER",tools:[],matcherToolNamePattern:"",matcherFromState:"",matcherToState:"",timeoutMs:3e4,enabled:!0,failOpen:!0,scope:"project"},se=[{value:"SHELL",label:"Shell 脚本",desc:"执行外部脚本,stdin 接收 JSON,stdout 返回决策"},{value:"HTTP",label:"HTTP 端点",desc:"POST JSON 到外部端点"},{value:"PROMPT",label:"LLM Prompt",desc:"发送单轮 Prompt 给 LLM 做风险评估"},{value:"AGENT",label:"AI Agent",desc:"启动只读子代理做深度调查"}],re=[{value:"SYSTEM",label:"SYSTEM (100)"},{value:"SECURITY",label:"SECURITY (80)"},{value:"PROJECT",label:"PROJECT (60)"},{value:"USER",label:"USER (40)"},{value:"PLUGIN",label:"PLUGIN (20)"}],b=l=>`w-full rounded-lg border bg-dark-bg px-3 py-2 text-sm text-dark-text placeholder-dark-muted/60 transition-colors focus:outline-none focus:ring-2 ${l?"border-accent-red focus:border-accent-red focus:ring-accent-red/20":"border-dark-border focus:border-accent-blue focus:ring-accent-blue/20"}`,g="mb-1 block text-xs font-medium text-dark-muted";function le({events:l,agents:o}){const{editingRule:s,fieldErrors:r,dryRunResult:m,createRule:v,updateRule:d,closeForm:h,dryRun:T,setDryRunResult:k,clearFieldErrors:y}=P(),S=Array.isArray(l)?l:[],f=Array.isArray(o)?o:[],[x,p]=N.useState(0),[t,i]=N.useState(ae),[w,C]=N.useState("");N.useEffect(()=>{var a,n,c;s&&i({name:s.name,description:s.description||"",events:s.events,implementationType:s.implementationType,command:s.command||"",url:s.url||"",promptTemplate:s.promptTemplate||"",agentName:s.agentName||"",priority:s.priority,tools:s.tools||[],matcherToolNamePattern:((a=s.matchers)==null?void 0:a.toolNamePattern)||"",matcherFromState:((n=s.matchers)==null?void 0:n.fromState)||"",matcherToState:((c=s.matchers)==null?void 0:c.toState)||"",timeoutMs:s.timeoutMs,enabled:s.enabled,failOpen:s.failOpen,scope:s.scope||"project"})},[s]);const u=(a,n)=>{i(c=>({...c,[a]:n})),y()},O=a=>{i(n=>({...n,events:n.events.includes(a)?n.events.filter(c=>c!==a):[...n.events,a]}))},A=a=>{const n=a.every(c=>t.events.includes(c));i(n?c=>({...c,events:c.events.filter(R=>!a.includes(R))}):c=>({...c,events:[...new Set([...c.events,...a])]}))},E=async()=>{const a={};t.matcherToolNamePattern&&(a.toolNamePattern=t.matcherToolNamePattern),t.matcherFromState&&(a.fromState=t.matcherFromState),t.matcherToState&&(a.toState=t.matcherToState);const c={...{...t,tools:t.tools.length>0?t.tools:[]}};c.matchers=a,delete c.matcherToolNamePattern,delete c.matcherFromState,delete c.matcherToState,s?await d(s.name,c):await v(c)},_=async()=>{k(null);const a={};t.matcherToolNamePattern&&(a.toolNamePattern=t.matcherToolNamePattern),await T({hook:{name:t.name||"dry-run",description:t.description,events:t.events,implementationType:t.implementationType,command:t.command,url:t.url,promptTemplate:t.promptTemplate,agentName:t.agentName,priority:t.priority,tools:t.tools,matchers:a,timeoutMs:t.timeoutMs,enabled:!0,failOpen:t.failOpen,scope:t.scope},eventType:t.events[0]||"PRE_TOOL_USE",toolName:"",toolInput:""})},D=w?S.map(a=>({...a,events:Array.isArray(a.events)?a.events.filter(n=>n.name.toLowerCase().includes(w.toLowerCase())||n.summary.includes(w)):[]})).filter(a=>a.events.length>0):S,H=[{title:"基本信息",desc:"名称、描述、事件"},{title:"实现配置",desc:"执行方式与参数"},{title:"高级选项",desc:"优先级、过滤、测试"}];return e.jsxs("div",{className:"fixed inset-0 z-50 flex justify-end",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:h}),e.jsxs("div",{className:"relative flex h-full w-[560px] flex-col border-l border-dark-border bg-dark-bg shadow-2xl animate-slide-in-right",children:[e.jsxs("div",{className:"flex flex-shrink-0 items-center justify-between border-b border-dark-border px-4 py-3.5",children:[e.jsx("h3",{className:"text-base font-semibold text-dark-text",children:s?`编辑: ${s.name}`:"添加 Hook 规则"}),e.jsx("button",{onClick:h,className:"rounded-lg p-1 text-dark-muted transition-colors hover:bg-dark-hover hover:text-dark-text",children:e.jsx(I,{size:18})})]}),e.jsx("div",{className:"flex flex-shrink-0 border-b border-dark-border",children:H.map((a,n)=>{const c=n===x,R=n<x;return e.jsxs("button",{onClick:()=>p(n),className:`relative flex-1 border-b-2 px-2 py-2.5 text-center text-xs transition-colors ${c?"border-accent-blue bg-accent-blue/5 text-accent-blue":R?"border-transparent text-dark-text":"border-transparent text-dark-muted hover:text-dark-text"}`,children:[e.jsx("span",{className:`mr-1 inline-flex h-4 w-4 items-center justify-center rounded-full text-[10px] ${c?"bg-accent-blue text-white":R?"bg-accent-green text-white":"bg-dark-hover text-dark-muted"}`,children:R?"✓":n+1}),e.jsx("span",{className:"font-medium",children:a.title})]},a.title)})}),e.jsxs("div",{className:"flex-1 min-h-0 space-y-4 overflow-auto custom-scrollbar p-4",children:[r&&Object.keys(r).length>0&&e.jsx("div",{className:"rounded-lg border border-accent-red/40 bg-accent-red/10 p-2.5 text-xs text-accent-red",children:Object.entries(r).map(([a,n])=>e.jsxs("div",{children:[e.jsxs("strong",{children:[a,":"]})," ",n]},a))}),x===0&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:g,children:"名称 *"}),e.jsx("input",{value:t.name,onChange:a=>u("name",a.target.value),placeholder:"my-custom-hook",className:b(r==null?void 0:r.name)})]}),e.jsxs("div",{children:[e.jsx("label",{className:g,children:"描述"}),e.jsx("textarea",{value:t.description,onChange:a=>u("description",a.target.value),placeholder:"这个 Hook 的作用...",rows:2,className:b()})]}),e.jsxs("div",{children:[e.jsx("label",{className:g,children:"Scope"}),e.jsxs("select",{value:t.scope,onChange:a=>u("scope",a.target.value),className:b(),children:[e.jsx("option",{value:"project",children:"project (.agent/hooks.json)"}),e.jsx("option",{value:"user",children:"user (~/.agent/hooks.json)"}),e.jsx("option",{value:"local",children:"local (.agent/hooks.local.json)"})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[e.jsx("label",{className:"text-xs font-medium text-dark-muted",children:"事件 *"}),e.jsxs("span",{className:"text-xs text-accent-blue",children:[t.events.length," 已选"]})]}),e.jsx("input",{value:w,onChange:a=>C(a.target.value),placeholder:"搜索事件...",className:b()+" mb-2"}),e.jsx("div",{className:"max-h-[280px] space-y-2 overflow-auto custom-scrollbar rounded-lg border border-dark-border bg-dark-surface p-2",children:D.map(a=>e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>A(a.events.map(n=>n.name)),className:"mb-1 text-xs font-medium text-dark-muted transition-colors hover:text-dark-text",children:[a.category," — 全选/取消"]}),a.events.map(n=>{const c=t.events.includes(n.name);return e.jsxs("label",{className:"flex cursor-pointer items-center gap-2 rounded px-1 py-1 transition-colors hover:bg-dark-hover",children:[e.jsx("input",{type:"checkbox",checked:c,onChange:()=>O(n.name),className:"h-3.5 w-3.5 accent-accent-blue"}),e.jsx("span",{className:"text-xs text-dark-text",children:n.name}),e.jsxs("span",{className:"truncate text-xs text-dark-muted",children:["— ",n.summary]})]},n.name)})]},a.category))})]})]}),x===1&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:g,children:"实现类型 *"}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:se.map(a=>{const n=t.implementationType===a.value;return e.jsxs("button",{onClick:()=>u("implementationType",a.value),className:`rounded-lg border p-3 text-left transition-colors ${n?"border-accent-blue bg-accent-blue/10 ring-1 ring-accent-blue/30":"border-dark-border bg-dark-surface hover:bg-dark-hover"}`,children:[e.jsx("div",{className:`text-sm font-medium ${n?"text-accent-blue":"text-dark-text"}`,children:a.label}),e.jsx("div",{className:"mt-1 text-xs text-dark-muted",children:a.desc})]},a.value)})})]}),t.implementationType==="SHELL"&&e.jsxs("div",{children:[e.jsx("label",{className:g,children:"命令 *"}),e.jsx("input",{value:t.command,onChange:a=>u("command",a.target.value),placeholder:"python3 .agent/hooks/audit.py",className:`font-mono ${b(r==null?void 0:r.command)}`})]}),t.implementationType==="HTTP"&&e.jsxs("div",{children:[e.jsx("label",{className:g,children:"URL *"}),e.jsx("input",{value:t.url,onChange:a=>u("url",a.target.value),placeholder:"https://example.com/hooks/audit",className:b(r==null?void 0:r.url)})]}),t.implementationType==="PROMPT"&&e.jsxs("div",{children:[e.jsx("label",{className:g,children:"Prompt 模板 *"}),e.jsx("textarea",{value:t.promptTemplate,onChange:a=>u("promptTemplate",a.target.value),placeholder:"你是一个安全审计专家,请分析以下工具调用...",rows:5,className:`font-mono ${b(r==null?void 0:r.promptTemplate)}`})]}),t.implementationType==="AGENT"&&e.jsxs("div",{children:[e.jsx("label",{className:g,children:"Agent *"}),e.jsxs("select",{value:t.agentName,onChange:a=>u("agentName",a.target.value),className:b(r==null?void 0:r.agentName),children:[e.jsx("option",{value:"",children:"选择 Agent..."}),f.map(a=>e.jsxs("option",{value:a.id,children:[a.name," (",a.description,")"]},a.id))]}),e.jsx("p",{className:"mt-1 text-xs text-dark-muted",children:"Agent 将以只读模式运行(Read/Grep/Glob),不会修改文件"})]})]}),x===2&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:g,children:"优先级"}),e.jsx("select",{value:t.priority,onChange:a=>u("priority",a.target.value),className:b(),children:re.map(a=>e.jsx("option",{value:a.value,children:a.label},a.value))})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:g,children:"超时 (ms)"}),e.jsx("input",{type:"number",value:t.timeoutMs,onChange:a=>u("timeoutMs",parseInt(a.target.value)||3e4),min:100,max:3e5,step:1e3,className:b()})]}),e.jsxs("div",{className:"flex flex-col gap-2.5",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm text-dark-text",children:[e.jsx("input",{type:"checkbox",checked:t.enabled,onChange:a=>u("enabled",a.target.checked),className:"h-3.5 w-3.5 accent-accent-blue"}),"启用"]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm text-dark-text",children:[e.jsx("input",{type:"checkbox",checked:t.failOpen,onChange:a=>u("failOpen",a.target.checked),className:"h-3.5 w-3.5 accent-accent-blue"}),"Fail-open(超时放行)"]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:g,children:"工具过滤(正则,可选)"}),e.jsx("input",{value:t.matcherToolNamePattern,onChange:a=>u("matcherToolNamePattern",a.target.value),placeholder:"Bash.*|FileWrite.*",className:`font-mono ${b()}`})]}),t.events.some(a=>a.includes("STATE"))&&e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:g,children:"From State"}),e.jsx("input",{value:t.matcherFromState,onChange:a=>u("matcherFromState",a.target.value),className:b()})]}),e.jsxs("div",{children:[e.jsx("label",{className:g,children:"To State"}),e.jsx("input",{value:t.matcherToState,onChange:a=>u("matcherToState",a.target.value),className:b()})]})]}),m&&e.jsxs("div",{className:"rounded-lg border border-dark-border bg-dark-surface p-3",children:[e.jsx("div",{className:"mb-2 text-xs font-medium text-dark-text",children:"Dry-run 结果"}),e.jsxs("div",{className:"space-y-1 text-xs",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-dark-muted",children:"决策: "}),e.jsx("span",{className:m.decision==="ALLOW"?"text-accent-green":m.decision==="DENY"?"text-accent-red":"text-accent-yellow",children:m.decision})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-dark-muted",children:"原因: "}),e.jsx("span",{className:"text-dark-text",children:m.reason})]}),m.contextOutput&&e.jsxs("div",{children:[e.jsx("span",{className:"text-dark-muted",children:"输出: "}),e.jsx("span",{className:"text-dark-text",children:m.contextOutput})]})]})]}),e.jsxs("button",{onClick:_,className:"inline-flex items-center gap-1.5 rounded-lg border border-dark-border bg-dark-surface px-3 py-1.5 text-xs text-dark-text transition-colors hover:bg-dark-hover",children:[e.jsx($,{size:12})," 试运行 (Dry Run)"]})]})]}),e.jsxs("div",{className:"flex flex-shrink-0 items-center justify-between border-t border-dark-border px-4 py-3",children:[e.jsx("div",{className:"flex gap-2",children:x>0&&e.jsxs("button",{onClick:()=>p(x-1),className:"inline-flex items-center gap-1 rounded-lg border border-dark-border bg-dark-surface px-3 py-1.5 text-sm text-dark-text transition-colors hover:bg-dark-hover",children:[e.jsx(Y,{size:14})," 上一步"]})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:h,className:"rounded-lg border border-dark-border bg-dark-surface px-4 py-1.5 text-sm text-dark-text transition-colors hover:bg-dark-hover",children:"取消"}),x<2?e.jsxs("button",{onClick:()=>p(x+1),className:"inline-flex items-center gap-1 rounded-lg bg-accent-blue px-4 py-1.5 text-sm text-white transition-colors hover:bg-accent-blue/90",children:["下一步 ",e.jsx(G,{size:14})]}):e.jsx("button",{onClick:E,className:"rounded-lg bg-accent-blue px-4 py-1.5 text-sm text-white transition-colors hover:bg-accent-blue/90",children:s?"保存修改":"创建规则"})]})]})]})]})}function ne({stats:l}){if(!l)return null;const o=[{label:"总规则数",value:l.totalHooks,icon:J,iconWrap:"bg-accent-blue/15 text-accent-blue"},{label:"已启用",value:l.enabledCount,icon:B,iconWrap:"bg-accent-green/15 text-accent-green"},{label:"已禁用",value:l.disabledCount,icon:W,iconWrap:"bg-dark-hover text-dark-muted"}];return e.jsx("div",{className:"grid grid-cols-3 gap-3",children:o.map(s=>{const r=s.icon;return e.jsxs("div",{className:"flex items-center gap-3 rounded-xl border border-dark-border bg-dark-surface px-4 py-3",children:[e.jsx("span",{className:`flex h-9 w-9 shrink-0 items-center justify-center rounded-lg ${s.iconWrap}`,children:e.jsx(r,{size:18})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-xl font-bold text-dark-text",children:s.value}),e.jsx("div",{className:"text-xs text-dark-muted",children:s.label})]})]},s.label)})})}function xe(){const{rules:l,stats:o,events:s,agents:r,loading:m,error:v,formOpen:d,loadAll:h,openForm:T,clearError:k}=P();N.useEffect(()=>{h()},[]);const y=N.useCallback(async()=>{const{api:f}=await L(async()=>{const{api:p}=await import("./index-YAnKQ1Q6.js").then(t=>t.F);return{api:p}},__vite__mapDeps([0,1,2,3,4,5])),x=await f.hooks.export();if(x.success&&x.data){const p=new Blob([JSON.stringify(x.data,null,2)],{type:"application/json"}),t=URL.createObjectURL(p),i=document.createElement("a");i.href=t,i.download="hooks-export.json",i.click(),URL.revokeObjectURL(t)}},[]),S=N.useCallback(()=>{const f=document.createElement("input");f.type="file",f.accept=".json",f.onchange=async x=>{var i;const p=(i=x.target.files)==null?void 0:i[0];if(!p)return;const t=await p.text();try{const w=JSON.parse(t),{api:C}=await L(async()=>{const{api:A}=await import("./index-YAnKQ1Q6.js").then(E=>E.F);return{api:A}},__vite__mapDeps([0,1,2,3,4,5])),u=confirm(`合并到现有配置吗?
|
|
3
|
+
"确定"=合并 / "取消"=替换`)?"merge":"replace";(await C.hooks.import({...w,mergeMode:u})).success&&h()}catch(w){console.error("Import failed:",w)}},f.click()},[h]);return e.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-dark-bg text-dark-text",children:[e.jsxs("div",{className:"flex shrink-0 flex-wrap items-center justify-between gap-3 border-b border-dark-border px-6 py-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-semibold text-dark-text",children:"Hook 配置"}),e.jsx("p",{className:"mt-0.5 text-xs text-dark-muted",children:"在工具执行、任务流转等生命周期事件上挂载拦截器,实现审批与自定义逻辑"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:h,title:"刷新",className:"rounded-lg p-2 text-dark-muted transition-colors hover:bg-dark-hover hover:text-dark-text",children:e.jsx(q,{size:16,className:m?"animate-spin":""})}),e.jsxs("button",{onClick:S,className:"inline-flex items-center gap-1.5 rounded-lg border border-dark-border bg-dark-surface px-3 py-2 text-sm text-dark-text transition-colors hover:bg-dark-hover",children:[e.jsx(V,{size:14}),"导入"]}),e.jsxs("button",{onClick:y,className:"inline-flex items-center gap-1.5 rounded-lg border border-dark-border bg-dark-surface px-3 py-2 text-sm text-dark-text transition-colors hover:bg-dark-hover",children:[e.jsx(X,{size:14}),"导出"]}),e.jsxs("button",{onClick:()=>T(),className:"inline-flex items-center gap-1.5 rounded-lg bg-accent-blue px-3 py-2 text-sm text-white transition-colors hover:bg-accent-blue/90",children:[e.jsx(K,{size:14}),"新增规则"]})]})]}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-auto custom-scrollbar px-6 py-4",children:[v&&e.jsxs("div",{className:"mb-3 flex items-center justify-between rounded-lg border border-accent-red/40 bg-accent-red/10 px-4 py-2 text-sm text-accent-red",children:[e.jsx("span",{children:v}),e.jsx("button",{onClick:k,className:"text-accent-red/70 transition-colors hover:text-accent-red",children:e.jsx(I,{size:16})})]}),e.jsx(ne,{stats:o}),e.jsxs("section",{className:"mt-4 min-w-0 rounded-xl border border-dark-border bg-dark-surface p-4",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-semibold text-dark-text",children:"规则列表"}),e.jsxs("span",{className:"text-xs text-dark-muted",children:[l.length," 条"]})]}),m&&l.length===0?e.jsx("div",{className:"flex h-[520px] items-center justify-center text-dark-muted",children:"加载中..."}):e.jsx("div",{className:"min-h-[520px]",children:e.jsx(te,{rules:l,onEdit:f=>T(f)})})]})]}),d&&e.jsx(le,{events:s,agents:r})]})}export{xe as HookConfigView};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as t}from"./markdown-
|
|
1
|
+
import{j as t}from"./markdown-D0iUI0Yw.js";import{r as c,B as m,R as f,m as j,ai as k,X as v,aV as N,aW as y,h as w}from"./icons-B5yCkBjC.js";import{E as C}from"./index-YAnKQ1Q6.js";import"./react-vendor-Bxu3r3ox.js";import"./state-C80Yzgl0.js";function R(){const{items:i,pendingCount:x,fetchInbox:l,resolveInbox:d,loading:p,error:u}=C(),[r,g]=c.useState("pending");c.useEffect(()=>{l()},[l]);const o=c.useMemo(()=>i.filter(e=>r==="all"||e.state===r),[i,r]),h=e=>e.kind==="approval"?{label:"需要批准",icon:y,color:"text-accent-yellow"}:e.kind==="question"?{label:"需要回答",icon:w,color:"text-accent-blue"}:{label:"通知",icon:m,color:"text-dark-muted"},b=e=>{var n;if(e.kind!=="approval")return null;const a=((n=e.data)==null?void 0:n.payload)||{};for(const s of["target","recipient","channel","url"])if(typeof a[s]=="string"&&a[s])return a[s];for(const s of["path","filePath"])if(typeof a[s]=="string"&&a[s])return a[s];return null};return t.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden p-4",children:[t.jsxs("div",{className:"flex items-center justify-between mb-4",children:[t.jsxs("h2",{className:"text-lg font-semibold flex items-center gap-2",children:[t.jsx(m,{size:20,className:"text-accent-blue"}),"Inbox",x>0&&t.jsxs("span",{className:"ml-1 px-2 py-0.5 rounded-full bg-accent-yellow/20 text-accent-yellow text-xs",children:[x," 待处理"]})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("div",{className:"flex rounded-lg bg-dark-hover p-0.5 text-sm",children:["pending","resolved","all"].map(e=>t.jsx("button",{onClick:()=>g(e),className:`px-3 py-1 rounded-md transition-colors ${r===e?"bg-accent-blue/20 text-accent-blue":"text-dark-muted hover:text-dark-text"}`,children:e==="pending"?"待处理":e==="resolved"?"已解决":"全部"},e))}),t.jsx("button",{onClick:()=>void l(),className:"p-2 rounded-lg hover:bg-dark-hover text-dark-muted",title:"刷新",children:t.jsx(f,{size:16})})]})]}),u&&t.jsxs("div",{className:"mb-3 p-3 rounded-lg bg-accent-red/10 text-accent-red text-sm flex items-center gap-2",children:[t.jsx(j,{size:16})," ",u]}),t.jsxs("div",{className:"flex-1 overflow-y-auto space-y-2",children:[p&&o.length===0&&t.jsx("p",{className:"text-dark-muted text-center py-8",children:"加载中..."}),!p&&o.length===0&&t.jsxs("p",{className:"text-dark-muted text-center py-8",children:["没有",r==="pending"?"待处理":"","事项"]}),o.map(e=>{const a=h(e),n=a.icon;return t.jsxs("div",{className:"rounded-lg border border-dark-border bg-dark-surface p-3",children:[t.jsxs("div",{className:"flex items-start justify-between gap-2",children:[t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[t.jsx(n,{size:16,className:`${a.color} shrink-0`}),t.jsx("span",{className:"font-medium text-sm truncate",children:e.title}),t.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-dark-hover text-dark-muted shrink-0",children:e.kind})]}),t.jsx("span",{className:`text-xs shrink-0 ${e.state==="pending"?"text-accent-yellow":"text-accent-green"}`,children:e.state==="pending"?"pending":e.resolution||"resolved"})]}),e.body&&t.jsx("p",{className:"mt-1 text-xs text-dark-muted break-all",children:e.body}),e.data&&typeof e.data.toolName=="string"&&e.data.toolName&&t.jsxs("div",{className:"mt-2 p-2 rounded bg-dark-bg border border-dark-border",children:[t.jsxs("code",{className:"text-xs text-accent-blue",children:["工具: ",String(e.data.toolName)]}),typeof e.data.payload=="object"&&e.data.payload!==null&&t.jsx("pre",{className:"mt-1 text-[11px] text-dark-muted whitespace-pre-wrap max-h-24 overflow-y-auto",children:JSON.stringify(e.data.payload,null,2).slice(0,800)})]}),e.state==="pending"&&t.jsxs("div",{className:"mt-2 flex gap-2",children:[t.jsxs("button",{onClick:()=>void d(e.id,"allow"),className:"flex items-center gap-1 px-3 py-1.5 rounded-lg bg-accent-green/20 text-accent-green hover:bg-accent-green/30 text-xs font-medium",children:[t.jsx(k,{size:14})," 批准"]}),t.jsxs("button",{onClick:()=>void d(e.id,"deny"),className:"flex items-center gap-1 px-3 py-1.5 rounded-lg bg-accent-red/20 text-accent-red hover:bg-accent-red/30 text-xs font-medium",children:[t.jsx(v,{size:14})," 拒绝"]}),e.kind==="approval"&&(()=>{const s=b(e);return t.jsxs("button",{onClick:()=>void d(e.id,"always"),className:"flex items-center gap-1 px-3 py-1.5 rounded-lg bg-dark-hover text-dark-muted hover:text-dark-text text-xs font-medium",title:s?`此目标后续自动放行:${s}`:"此工具本次会话后续自动放行",children:[t.jsx(N,{size:14})," 总是允许",s?` ${s}`:""]})})()]})]},e.id)})]})]})}export{R as InboxView};
|