@agent-dock/cli 0.3.23 → 0.3.25

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.
@@ -1 +0,0 @@
1
- import{c as J,j as s}from"./index-CWUiS-aC.js";import{r as c}from"./syntax-highlighter-d-DuIo_w.js";class L extends Error{constructor(n,l){super(l),this.code=n,this.name="ApiError"}}async function i(a,n){var t,v;const l=await fetch(a,{...n,headers:{...n!=null&&n.body?{"content-type":"application/json"}:{},...(n==null?void 0:n.headers)??{}}}),x=await l.json();if(!l.ok)throw new L(((t=x.error)==null?void 0:t.code)??"REQUEST_FAILED",((v=x.error)==null?void 0:v.message)??`请求失败:HTTP ${l.status}`);return x}const d={sources:()=>i("/api/sources"),createSource:a=>i("/api/sources",{method:"POST",body:JSON.stringify(a)}),setEnabled:(a,n)=>i(`/api/sources/${encodeURIComponent(a)}/${n?"enable":"disable"}`,{method:"POST"}),cases:(a={})=>{const n=new URLSearchParams;return a.sourceId&&n.set("sourceId",a.sourceId),a.status&&n.set("status",a.status),i(`/api/source-router/cases${n.size?`?${n}`:""}`)},caseDetail:a=>i(`/api/source-router/cases/${encodeURIComponent(a)}`),closeCase:(a,n)=>i(`/api/source-router/cases/${encodeURIComponent(a)}/close`,{method:"POST",body:JSON.stringify({reason:n})}),routerStatus:()=>i("/api/router/status"),openRouter:()=>i("/api/router/open",{method:"POST"}),setPaused:a=>i("/api/router/pause",{method:"POST",body:JSON.stringify({paused:a})})},b=a=>a?new Date(a).toLocaleString("zh-CN",{hour12:!1}):"—",S=a=>s.jsx("span",{className:"sr-badge","data-status":a,children:a});function N({title:a,actions:n,children:l}){return s.jsxs("section",{className:"sr-panel",children:[s.jsxs("header",{className:"sr-panel-header",children:[s.jsx("h2",{children:a}),s.jsx("div",{children:n})]}),s.jsx("div",{className:"sr-panel-body",children:l})]})}function M(){const[a,n]=c.useState([]),[l,x]=c.useState([]),[t,v]=c.useState(null),[r,y]=c.useState(null),[g,E]=c.useState(""),[C,D]=c.useState(""),[f,F]=c.useState(""),[k,A]=c.useState(""),[w,P]=c.useState(""),[h,T]=c.useState(!1),[$,O]=c.useState(""),[I,j]=c.useState(""),u=c.useCallback(async()=>{try{const[e,o,m]=await Promise.all([d.sources(),d.cases({sourceId:C||void 0,status:f||void 0}),d.routerStatus()]);if(n(e),x(o),v(m),j(""),g)try{y(await d.caseDetail(g))}catch{y(null),E("")}}catch(e){j(e instanceof Error?e.message:String(e))}},[g,C,f]);c.useEffect(()=>{u()},[u]),c.useEffect(()=>{const e=setInterval(()=>void u(),1e4);return()=>clearInterval(e)},[u]);const p=async(e,o)=>{T(!0),j(""),O("");try{await e(),O(o),await u()}catch(m){j(m instanceof Error?m.message:String(m))}finally{T(!1)}},U=()=>p(async()=>d.createSource({name:k.trim()||"新的消息源",kind:"webhook",config:{correlation:{mode:"object"},allowedRepos:[],actions:["comment"]},...w?{secrets:{signingSecret:w}}:{}}),"消息源已创建").then(()=>{A(""),P("")}),R=c.useMemo(()=>(t==null?void 0:t.inbox.filter(e=>e.status==="pending"))??[],[t]);return s.jsxs("div",{className:"sr-app",children:[s.jsxs("aside",{className:"sr-sidebar",children:[s.jsxs("div",{className:"sr-brand",children:[s.jsx("span",{className:"sr-dot"}),"AgentDock"]}),s.jsx("h1",{children:"消息源与 Router"}),s.jsx("p",{className:"sr-muted",children:"外部事件进入 Case,Router 判断并委派 Worker;所有内容按不可信数据处理。"}),s.jsxs("nav",{children:[s.jsx("a",{href:"/",children:"返回主控制台"}),s.jsx("a",{href:"/sources-router.html",className:"active",children:"消息源控制台"})]}),s.jsxs("div",{className:"sr-summary",children:[s.jsxs("div",{children:[s.jsx("span",{children:"消息源"}),s.jsx("strong",{children:a.length})]}),s.jsxs("div",{children:[s.jsx("span",{children:"Case"}),s.jsx("strong",{children:l.length})]}),s.jsxs("div",{children:[s.jsx("span",{children:"Inbox"}),s.jsx("strong",{children:R.length})]})]}),s.jsxs("div",{className:"sr-router-card",children:[s.jsx("span",{className:"sr-label",children:"Router Session"}),s.jsx("code",{children:(t==null?void 0:t.sessionId)??"懒创建"}),s.jsx("small",{children:t!=null&&t.paused?"已暂停":"运行中"}),s.jsx("button",{disabled:h,onClick:()=>void p(()=>d.openRouter(),"Router Session 已就绪"),children:"打开 / 复用 Router"}),s.jsx("button",{disabled:h,onClick:()=>t&&void p(()=>d.setPaused(!t.paused),t.paused?"已恢复 Router 派发":"已开启全部暂停"),children:t!=null&&t.paused?"恢复全部":"全部暂停"})]})]}),s.jsxs("main",{className:"sr-main",children:[($||I)&&s.jsx("div",{className:`sr-notice ${I?"error":""}`,children:I||$}),s.jsxs("div",{className:"sr-grid",children:[s.jsxs(N,{title:"消息源",actions:s.jsx("button",{disabled:h,onClick:()=>void u(),children:"刷新"}),children:[s.jsxs("div",{className:"sr-form",children:[s.jsx("input",{"aria-label":"消息源名称",placeholder:"消息源名称",value:k,onChange:e=>A(e.target.value)}),s.jsx("input",{"aria-label":"签名密钥",type:"password",placeholder:"签名密钥(可选)",value:w,onChange:e=>P(e.target.value)}),s.jsx("button",{disabled:h,onClick:()=>void U(),children:"创建"})]}),s.jsxs("div",{className:"sr-list",children:[a.map(e=>s.jsxs("article",{className:"sr-row",children:[s.jsxs("div",{children:[s.jsx("strong",{children:e.name}),s.jsx("code",{children:e.id}),s.jsxs("span",{children:[e.kind," · 最近事件 ",b(e.lastEventAt)]})]}),s.jsxs("div",{className:"sr-row-actions",children:[S(e.enabled?e.status:"disabled"),s.jsx("button",{disabled:h,onClick:()=>void p(()=>d.setEnabled(e.id,!e.enabled),e.enabled?"消息源已禁用":"消息源已启用"),children:e.enabled?"禁用":"启用"})]})]},e.id)),!a.length&&s.jsx("p",{className:"sr-empty",children:"暂无消息源。"})]})]}),s.jsx(N,{title:"Router Inbox",children:s.jsxs("div",{className:"sr-list",children:[R.map(e=>s.jsxs("article",{className:"sr-row",children:[s.jsxs("div",{children:[s.jsx("strong",{children:e.kind}),s.jsx("code",{children:e.caseId??"-"}),s.jsx("span",{children:b(e.createdAt)})]}),S(e.status)]},e.id)),!R.length&&s.jsx("p",{className:"sr-empty",children:"Inbox 为空。"})]})}),s.jsx(N,{title:"Cases",actions:s.jsxs(s.Fragment,{children:[s.jsxs("select",{"aria-label":"按消息源筛选",value:C,onChange:e=>D(e.target.value),children:[s.jsx("option",{value:"",children:"全部消息源"}),a.map(e=>s.jsx("option",{value:e.id,children:e.name},e.id))]}),s.jsxs("select",{"aria-label":"按状态筛选",value:f,onChange:e=>F(e.target.value),children:[s.jsx("option",{value:"",children:"全部状态"}),s.jsx("option",{value:"open",children:"open"}),s.jsx("option",{value:"waiting",children:"waiting"}),s.jsx("option",{value:"closed",children:"closed"})]})]}),children:s.jsxs("div",{className:"sr-list",children:[l.map(e=>s.jsxs("button",{className:`sr-case ${g===e.id?"selected":""}`,onClick:()=>void d.caseDetail(e.id).then(o=>{y(o),E(e.id)}).catch(o=>j(String(o))),children:[s.jsxs("span",{children:[s.jsx("strong",{children:e.title}),s.jsx("code",{children:e.id})]}),S(e.status),s.jsx("small",{children:b(e.updatedAt)})]},e.id)),!l.length&&s.jsx("p",{className:"sr-empty",children:"暂无 Case。"})]})}),s.jsx(N,{title:"Case 详情",actions:r&&r.status!=="closed"?s.jsx("button",{disabled:h,onClick:()=>r&&void p(()=>d.closeCase(r.id,"控制台手动关闭"),"Case 已关闭"),children:"关闭 Case"}):null,children:r?s.jsxs("div",{className:"sr-detail",children:[s.jsxs("div",{className:"sr-detail-head",children:[s.jsx("strong",{children:r.title}),S(r.status),s.jsx("code",{children:r.correlationKey})]}),s.jsxs("p",{className:"sr-muted",children:["来源对象:",s.jsx("code",{children:String(r.objectValue.id??"-")})," · 主会话:",s.jsx("code",{children:r.primarySessionId??"-"})]}),s.jsx("h3",{children:"时间线"}),s.jsx("ol",{className:"sr-timeline",children:r.events.map(e=>s.jsxs("li",{children:[s.jsx("time",{children:b(e.createdAt)}),s.jsx("span",{children:e.kind}),s.jsx("p",{children:e.summary})]},e.id))}),s.jsx("h3",{children:"关联会话与动作"}),s.jsxs("div",{className:"sr-chips",children:[r.sessions.map(e=>s.jsxs("span",{children:["委派 · ",e.sessionId]},e.sessionId)),r.watches.map(e=>s.jsxs("span",{children:["Watch · ",e.status]},e.id)),r.actions.map(e=>s.jsxs("span",{children:["Action · ",e.status]},e.id)),!r.sessions.length&&!r.watches.length&&!r.actions.length&&s.jsx("span",{children:"暂无关联对象"})]})]}):s.jsx("p",{className:"sr-empty",children:"选择一个 Case 查看时间线、关联 Session、Watch 和 Action。"})})]})]})]})}J.createRoot(document.getElementById("root")).render(s.jsx(c.StrictMode,{children:s.jsx(M,{})}));