agent-tower 0.5.2 → 0.5.3-beta.0
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 +14 -0
- package/dist/cli.js.map +1 -1
- package/dist/executors/__tests__/base.executor.test.js +12 -0
- package/dist/executors/__tests__/base.executor.test.js.map +1 -1
- package/dist/executors/execution-env.d.ts +1 -1
- package/dist/executors/execution-env.d.ts.map +1 -1
- package/dist/executors/execution-env.js +4 -0
- package/dist/executors/execution-env.js.map +1 -1
- package/dist/routes/conversations.d.ts +3 -0
- package/dist/routes/conversations.d.ts.map +1 -0
- package/dist/routes/conversations.js +102 -0
- package/dist/routes/conversations.js.map +1 -0
- package/dist/routes/index.d.ts.map +1 -1
- package/dist/routes/index.js +3 -0
- package/dist/routes/index.js.map +1 -1
- package/dist/routes/sessions.d.ts.map +1 -1
- package/dist/routes/sessions.js +37 -21
- package/dist/routes/sessions.js.map +1 -1
- package/dist/services/__tests__/conversation.service.test.d.ts +2 -0
- package/dist/services/__tests__/conversation.service.test.d.ts.map +1 -0
- package/dist/services/__tests__/conversation.service.test.js +102 -0
- package/dist/services/__tests__/conversation.service.test.js.map +1 -0
- package/dist/services/commit-message.service.d.ts.map +1 -1
- package/dist/services/commit-message.service.js +4 -0
- package/dist/services/commit-message.service.js.map +1 -1
- package/dist/services/conversation.service.d.ts +26 -0
- package/dist/services/conversation.service.d.ts.map +1 -0
- package/dist/services/conversation.service.js +224 -0
- package/dist/services/conversation.service.js.map +1 -0
- package/dist/services/session-manager.d.ts +69 -13
- package/dist/services/session-manager.d.ts.map +1 -1
- package/dist/services/session-manager.js +107 -42
- package/dist/services/session-manager.js.map +1 -1
- package/dist/services/task.service.d.ts +2 -2
- package/dist/services/terminal-manager.d.ts.map +1 -1
- package/dist/services/terminal-manager.js +2 -0
- package/dist/services/terminal-manager.js.map +1 -1
- package/dist/services/workspace.service.d.ts +9 -7
- package/dist/services/workspace.service.d.ts.map +1 -1
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +6 -0
- package/dist/types/index.js.map +1 -1
- package/dist/web/assets/AgentDemoPage-CUgqAjq9.js +1 -0
- package/dist/web/assets/ConversationPage-Cyiw8Hra.js +3 -0
- package/dist/web/assets/CreateTaskInput-BILlpv9b.js +2 -0
- package/dist/web/assets/{DemoPage-Xc4QRNUj.js → DemoPage-SywVXjL0.js} +1 -1
- package/dist/web/assets/{GeneralSettingsPage-DWKl6BHA.js → GeneralSettingsPage-CTymytF6.js} +1 -1
- package/dist/web/assets/Icons-DmLVnVdg.js +1 -0
- package/dist/web/assets/{McpSettingsPage-BHEMUq7Z.js → McpSettingsPage-DyolUN8C.js} +1 -1
- package/dist/web/assets/{MemberAvatar-b_WKLu8w.js → MemberAvatar-u6jTOiDY.js} +1 -1
- package/dist/web/assets/NotificationSettingsPage-BBop2Bu4.js +1 -0
- package/dist/web/assets/ProfileSettingsPage-Bw-eI0cF.js +3 -0
- package/dist/web/assets/ProjectKanbanPage-BFf2FZVz.js +89 -0
- package/dist/web/assets/ProjectSettingsPage-BJ4sOhMl.js +2 -0
- package/dist/web/assets/{ProviderSettingsPage-DQ_IDUUZ.js → ProviderSettingsPage-BlLaN0i2.js} +19 -19
- package/dist/web/assets/{SettingsMasterDetail-Cx9Ylq9N.js → SettingsMasterDetail-CdimTj5n.js} +1 -1
- package/dist/web/assets/TeamSettingsPage-CqQTc5AI.js +1 -0
- package/dist/web/assets/{arc-D31VhUJX.js → arc-Ddp5hhH6.js} +1 -1
- package/dist/web/assets/{architectureDiagram-3BPJPVTR-Ak9jpJ8q.js → architectureDiagram-3BPJPVTR-CpK7WDLU.js} +1 -1
- package/dist/web/assets/{arrow-left-DcUokonk.js → arrow-left-B6KMicbE.js} +1 -1
- package/dist/web/assets/{blockDiagram-GPEHLZMM-DEDpa_4t.js → blockDiagram-GPEHLZMM-6_0hov2h.js} +1 -1
- package/dist/web/assets/{c4Diagram-AAUBKEIU-BgS3ci_x.js → c4Diagram-AAUBKEIU-Br6Tzu3R.js} +1 -1
- package/dist/web/assets/channel-Bg_GO2e9.js +1 -0
- package/dist/web/assets/check-D9lM__p8.js +1 -0
- package/dist/web/assets/{chevron-down-DuDzRplH.js → chevron-down-Cur5jANy.js} +1 -1
- package/dist/web/assets/{chevron-right-BezhysME.js → chevron-right-R3KVa8oQ.js} +1 -1
- package/dist/web/assets/{chevron-up-DtQ85g91.js → chevron-up-DcLdFanO.js} +1 -1
- package/dist/web/assets/{chunk-2J33WTMH-BnpAjP2E.js → chunk-2J33WTMH-D8zyttB-.js} +1 -1
- package/dist/web/assets/{chunk-4BX2VUAB-DNUdFpBR.js → chunk-4BX2VUAB-Cqi9xJ8M.js} +1 -1
- package/dist/web/assets/{chunk-55IACEB6-CTj6ihx_.js → chunk-55IACEB6-Dxjaitf1.js} +1 -1
- package/dist/web/assets/{chunk-727SXJPM-yKiHVB7X.js → chunk-727SXJPM-CAn8Y9XB.js} +1 -1
- package/dist/web/assets/{chunk-AQP2D5EJ-njbMVjqc.js → chunk-AQP2D5EJ-B4sECH9U.js} +1 -1
- package/dist/web/assets/{chunk-FMBD7UC4-h0jEUL75.js → chunk-FMBD7UC4-Ckd3e1dg.js} +1 -1
- package/dist/web/assets/{chunk-ND2GUHAM-DjMFJZNr.js → chunk-ND2GUHAM-h5WBT7BK.js} +1 -1
- package/dist/web/assets/{chunk-QZHKN3VN-odAhWIp4.js → chunk-QZHKN3VN-Cdzk46MK.js} +1 -1
- package/dist/web/assets/{circle-alert-IhLKVEi9.js → circle-alert-OKyZ9U2p.js} +1 -1
- package/dist/web/assets/classDiagram-4FO5ZUOK-BeJctdRx.js +1 -0
- package/dist/web/assets/classDiagram-v2-Q7XG4LA2-BeJctdRx.js +1 -0
- package/dist/web/assets/{code-block-OCS4YCEC-4ofbxqu2.js → code-block-OCS4YCEC-VMJOsrkF.js} +1 -1
- package/dist/web/assets/{confirm-dialog-Amksh2QM.js → confirm-dialog-BAnxa2C9.js} +1 -1
- package/dist/web/assets/{cose-bilkent-S5V4N54A-Ds62_zKQ.js → cose-bilkent-S5V4N54A-CbFey2pd.js} +1 -1
- package/dist/web/assets/{dagre-BM42HDAG-De9CyhMh.js → dagre-BM42HDAG-Bd2eIyf3.js} +1 -1
- package/dist/web/assets/{diagram-2AECGRRQ-Db7DRtzA.js → diagram-2AECGRRQ-CXONvVnW.js} +1 -1
- package/dist/web/assets/{diagram-5GNKFQAL-DXeGI1-M.js → diagram-5GNKFQAL-B2E90mVs.js} +1 -1
- package/dist/web/assets/{diagram-KO2AKTUF-Llle6qEC.js → diagram-KO2AKTUF-ByaC99pb.js} +1 -1
- package/dist/web/assets/{diagram-LMA3HP47-BcK1LGRh.js → diagram-LMA3HP47-DwVBF2fn.js} +1 -1
- package/dist/web/assets/{diagram-OG6HWLK6-0_sJ3YRD.js → diagram-OG6HWLK6-FWRddceo.js} +1 -1
- package/dist/web/assets/{erDiagram-TEJ5UH35-BjT0k23c.js → erDiagram-TEJ5UH35-ye6i3SGj.js} +1 -1
- package/dist/web/assets/{flowDiagram-I6XJVG4X-kaKS6P_m.js → flowDiagram-I6XJVG4X-B6l7qTcg.js} +1 -1
- package/dist/web/assets/folder-B0m3OL2U.js +1 -0
- package/dist/web/assets/folder-picker-D5XrSfLA.js +1 -0
- package/dist/web/assets/{ganttDiagram-6RSMTGT7-CW8IoCY6.js → ganttDiagram-6RSMTGT7-BCCqDrep.js} +1 -1
- package/dist/web/assets/{gitGraphDiagram-PVQCEYII-C5-QVJMh.js → gitGraphDiagram-PVQCEYII-Ca4ANaSw.js} +1 -1
- package/dist/web/assets/index-C4twOgZR.css +1 -0
- package/dist/web/assets/{index-Du7RXa9t.js → index-C9hQg1KT.js} +4 -4
- package/dist/web/assets/{index-Bd5HU-dB.js → index-DbO4YyUv.js} +6 -6
- package/dist/web/assets/{infoDiagram-5YYISTIA-CG7QnPme.js → infoDiagram-5YYISTIA-D1V1Tezr.js} +1 -1
- package/dist/web/assets/{input-BxcpVmsb.js → input-Dqnd4oTj.js} +1 -1
- package/dist/web/assets/{ishikawaDiagram-YF4QCWOH-DitLiYai.js → ishikawaDiagram-YF4QCWOH-DnGiJn9p.js} +1 -1
- package/dist/web/assets/{journeyDiagram-JHISSGLW-EKXFhiai.js → journeyDiagram-JHISSGLW-QFxbLfhN.js} +1 -1
- package/dist/web/assets/{kanban-definition-UN3LZRKU-Ckbr1P9R.js → kanban-definition-UN3LZRKU-BA2nBc7B.js} +1 -1
- package/dist/web/assets/{layers-Dqjek9Kd.js → layers-CfFYGUtI.js} +1 -1
- package/dist/web/assets/{linear-HA2k3O-l.js → linear-DpASQZmA.js} +1 -1
- package/dist/web/assets/{loader-circle-B4v8mirO.js → loader-circle-B5Lfi46Y.js} +1 -1
- package/dist/web/assets/log-adapter-CjgRCCYG.js +1 -0
- package/dist/web/assets/{mermaid-NOHMQCX5-C2N-Y-YP.js → mermaid-NOHMQCX5-7FmPQynq.js} +60 -60
- package/dist/web/assets/{message-square-B-2bz9LU.js → message-square-CEefL0sf.js} +1 -1
- package/dist/web/assets/{mindmap-definition-RKZ34NQL-ByCTUtXz.js → mindmap-definition-RKZ34NQL-C7QuD-ms.js} +1 -1
- package/dist/web/assets/modal-CAB_bs-c.js +1 -0
- package/dist/web/assets/{pencil-DzjmtIoi.js → pencil-B__GQn9r.js} +1 -1
- package/dist/web/assets/{pieDiagram-4H26LBE5-DeQnXQoJ.js → pieDiagram-4H26LBE5-Bf5diCKb.js} +1 -1
- package/dist/web/assets/{quadrantDiagram-W4KKPZXB--ocdxSbH.js → quadrantDiagram-W4KKPZXB-BMbcPnH3.js} +1 -1
- package/dist/web/assets/{requirementDiagram-4Y6WPE33-CJq21gDX.js → requirementDiagram-4Y6WPE33-CUPvJXMk.js} +1 -1
- package/dist/web/assets/{rotate-ccw-BhUVdZv6.js → rotate-ccw-5d-eMwsw.js} +1 -1
- package/dist/web/assets/{sankeyDiagram-5OEKKPKP-U373GNMv.js → sankeyDiagram-5OEKKPKP-C77g6vmK.js} +1 -1
- package/dist/web/assets/{select-CCf5nwYs.js → select-BJfNuuIV.js} +1 -1
- package/dist/web/assets/{sequenceDiagram-3UESZ5HK-BuH8el8s.js → sequenceDiagram-3UESZ5HK-xGOV8CdQ.js} +1 -1
- package/dist/web/assets/{stateDiagram-AJRCARHV-CqZ_L1ch.js → stateDiagram-AJRCARHV-Bc0piegy.js} +1 -1
- package/dist/web/assets/stateDiagram-v2-BHNVJYJU-CiRT9t6d.js +1 -0
- package/dist/web/assets/{switch-DsjSr4nv.js → switch-bLlDOWNp.js} +1 -1
- package/dist/web/assets/{terminal-JXRig8oL.js → terminal-Bh2qSv0U.js} +1 -1
- package/dist/web/assets/{textarea-BzeEPT1A.js → textarea-BcVRpxhF.js} +1 -1
- package/dist/web/assets/{timeline-definition-PNZ67QCA-BIrIbCOG.js → timeline-definition-PNZ67QCA-CcACRt_V.js} +1 -1
- package/dist/web/assets/trash-2-8Pu6lwnW.js +1 -0
- package/dist/web/assets/{upload-BwkqnAVE.js → upload-DNwyW_bv.js} +1 -1
- package/dist/web/assets/{use-profiles-DcyUHq0p.js → use-profiles-BIqkQu69.js} +1 -1
- package/dist/web/assets/{use-providers-BWgjPVX8.js → use-providers-BOyY0DcV.js} +1 -1
- package/dist/web/assets/{vennDiagram-CIIHVFJN-Dmk1mluX.js → vennDiagram-CIIHVFJN-BC9RHBQ5.js} +1 -1
- package/dist/web/assets/{wardley-L42UT6IY-CEY4M7Op.js → wardley-L42UT6IY-BgPj73Dc.js} +1 -1
- package/dist/web/assets/{wardleyDiagram-YWT4CUSO-CiK-Q213.js → wardleyDiagram-YWT4CUSO-PbfDUndy.js} +1 -1
- package/dist/web/assets/{xychartDiagram-2RQKCTM6-C5rj3Hpu.js → xychartDiagram-2RQKCTM6-D87KYJUM.js} +1 -1
- package/dist/web/index.html +2 -2
- package/node_modules/@agent-tower/shared/dist/types.d.ts +41 -1
- package/node_modules/@agent-tower/shared/dist/types.d.ts.map +1 -1
- package/node_modules/@agent-tower/shared/dist/types.js +8 -0
- package/node_modules/@agent-tower/shared/dist/types.js.map +1 -1
- package/node_modules/@prisma/client/.prisma/client/edge.js +21 -6
- package/node_modules/@prisma/client/.prisma/client/index-browser.js +14 -0
- package/node_modules/@prisma/client/.prisma/client/index.d.ts +1789 -211
- package/node_modules/@prisma/client/.prisma/client/index.js +21 -6
- package/node_modules/@prisma/client/.prisma/client/package.json +1 -1
- package/node_modules/@prisma/client/.prisma/client/schema.prisma +34 -14
- package/node_modules/@prisma/client/.prisma/client/wasm.js +14 -0
- package/package.json +1 -1
- package/prisma/migrations/20260618000000_add_conversations/migration.sql +79 -0
- package/prisma/schema.prisma +22 -2
- package/dist/web/assets/AgentDemoPage-DAdN5g19.js +0 -1
- package/dist/web/assets/NotificationSettingsPage-C2KeYegv.js +0 -1
- package/dist/web/assets/ProfileSettingsPage-CVOCVwVK.js +0 -3
- package/dist/web/assets/ProjectKanbanPage-J_5GxZQ7.js +0 -90
- package/dist/web/assets/ProjectSettingsPage-CP3V8oAJ.js +0 -2
- package/dist/web/assets/TeamSettingsPage-BHE2x82g.js +0 -1
- package/dist/web/assets/channel-BLjA9Brq.js +0 -1
- package/dist/web/assets/check-DyTLNLlk.js +0 -1
- package/dist/web/assets/classDiagram-4FO5ZUOK-DHqakOiv.js +0 -1
- package/dist/web/assets/classDiagram-v2-Q7XG4LA2-DHqakOiv.js +0 -1
- package/dist/web/assets/folder-picker-CbAfVBHD.js +0 -1
- package/dist/web/assets/index-LbQD7FZK.css +0 -1
- package/dist/web/assets/log-adapter-CtvxzS4j.js +0 -1
- package/dist/web/assets/modal-C6m1dmin.js +0 -1
- package/dist/web/assets/stateDiagram-v2-BHNVJYJU-DkD_6IX-.js +0 -1
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{u as G,r as o,m as ce,j as e,X as ee,S as L,M as de,d as J,n as Q,g as K,B as A,N as ue,t as W}from"./index-DbO4YyUv.js";import{F as $,a as me,u as xe,b as pe,c as he,d as fe,e as ge}from"./folder-picker-D5XrSfLA.js";import{F as H}from"./folder-B0m3OL2U.js";import{P as te,T as je}from"./trash-2-8Pu6lwnW.js";import{T as ve,M as X}from"./modal-CAB_bs-c.js";import{S as be}from"./SettingsMasterDetail-CdimTj5n.js";import{R as Ne}from"./rotate-ccw-5d-eMwsw.js";import"./chevron-right-R3KVa8oQ.js";import"./loader-circle-B5Lfi46Y.js";import"./circle-alert-OKyZ9U2p.js";import"./check-D9lM__p8.js";import"./arrow-left-B6KMicbE.js";function ye({value:t,onChange:j,repoPath:v,placeholder:P}){const{t:l}=G(),[i,c]=o.useState(""),[x,p]=o.useState([]),[b,n]=o.useState(!1),[d,N]=o.useState(-1),u=o.useRef(null),g=o.useRef(null),k=o.useRef(void 0),I=o.useCallback(async s=>{if(!v||!s){p([]),n(!1);return}try{const a=await ce.get("/filesystem/complete",{params:{basePath:v,prefix:s}});p(a.results),n(a.results.length>0),N(-1)}catch{p([]),n(!1)}},[v]);o.useEffect(()=>{if(clearTimeout(k.current),!i){p([]),n(!1);return}return k.current=setTimeout(()=>I(i),200),()=>clearTimeout(k.current)},[i,I]),o.useEffect(()=>{const s=a=>{g.current&&!g.current.contains(a.target)&&u.current&&!u.current.contains(a.target)&&n(!1)};return document.addEventListener("mousedown",s),()=>document.removeEventListener("mousedown",s)},[]);const w=s=>{const a=s.trim();!a||t.includes(a)||(j([...t,a]),c(""),n(!1),u.current?.focus())},z=s=>{j(t.filter((a,S)=>S!==s))},D=s=>{s.type==="directory"?(c(s.path),u.current?.focus()):w(s.path)},C=(s,a)=>{a.stopPropagation(),w(s.path.replace(/\/$/,""))},F=s=>{s.nativeEvent.isComposing||s.nativeEvent.keyCode===229||(b&&x.length>0?s.key==="ArrowDown"?(s.preventDefault(),N(a=>Math.min(a+1,x.length-1))):s.key==="ArrowUp"?(s.preventDefault(),N(a=>Math.max(a-1,-1))):s.key==="Enter"?(s.preventDefault(),d>=0?D(x[d]):w(i)):s.key==="Escape"&&n(!1):s.key==="Enter"&&(s.preventDefault(),w(i)))};return e.jsxs("div",{children:[t.length>0&&e.jsx("div",{className:"border border-neutral-200 rounded-lg mb-2 divide-y divide-neutral-100",children:t.map((s,a)=>e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 group",children:[s.includes(".")&&!s.endsWith("/")?e.jsx($,{size:14,className:"text-neutral-400 shrink-0"}):e.jsx(H,{size:14,className:"text-amber-500 shrink-0"}),e.jsx("span",{className:"text-sm font-mono text-neutral-700 truncate flex-1",children:s}),e.jsx("button",{onClick:()=>z(a),className:"p-0.5 text-neutral-300 hover:text-red-500 opacity-0 group-hover:opacity-100 transition-opacity shrink-0",children:e.jsx(ee,{size:14})})]},s))}),e.jsxs("div",{className:"relative",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{ref:u,type:"text",value:i,onChange:s=>c(s.target.value),onKeyDown:F,onFocus:()=>{i&&x.length>0&&n(!0)},placeholder:P??l("输入文件路径..."),className:"flex-1 px-3 py-2 border border-neutral-200 rounded-lg text-sm font-mono focus:outline-none focus:ring-1 focus:ring-neutral-300"}),e.jsxs("button",{onClick:()=>w(i),disabled:!i.trim(),className:"flex items-center gap-1 px-3 py-2 text-sm bg-neutral-900 text-white rounded-lg hover:bg-neutral-800 disabled:opacity-30 disabled:cursor-not-allowed transition-colors",children:[e.jsx(te,{size:14}),e.jsx("span",{children:l("添加")})]})]}),b&&e.jsx("div",{ref:g,className:"absolute z-50 left-0 right-0 mt-1 bg-white border border-neutral-200 rounded-lg shadow-lg max-h-[200px] overflow-y-auto",children:x.map((s,a)=>e.jsxs("button",{onClick:()=>D(s),className:`w-full flex items-center gap-2 px-3 py-1.5 text-sm text-left hover:bg-neutral-50 transition-colors ${a===d?"bg-neutral-100":""}`,children:[s.type==="directory"?e.jsx(H,{size:14,className:"text-amber-500 shrink-0"}):e.jsx($,{size:14,className:"text-neutral-400 shrink-0"}),e.jsx("span",{className:"font-mono text-neutral-700 truncate flex-1",children:s.path}),s.type==="directory"&&e.jsx("span",{onClick:S=>C(s,S),className:"p-0.5 text-neutral-300 hover:text-emerald-600 shrink-0",title:l("添加此目录"),children:e.jsx(me,{size:14})})]},s.path))})]})]})}function Pe({value:t,onChange:j}){const{t:v}=G(),[P,l]=o.useState(""),[i,c]=o.useState(""),x=()=>{const n=P.trim(),d=i.trim();!n||!d||(j([...t,{name:n,command:d}]),l(""),c(""))},p=n=>{j(t.filter((d,N)=>N!==n))},b=n=>{n.key==="Enter"&&!n.nativeEvent.isComposing&&n.nativeEvent.keyCode!==229&&(n.preventDefault(),x())};return e.jsxs("div",{children:[t.length>0&&e.jsx("div",{className:"border border-neutral-200 rounded-lg mb-2 divide-y divide-neutral-100",children:t.map((n,d)=>e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 group",children:[e.jsx("span",{className:"text-sm font-medium text-neutral-700 w-28 shrink-0 truncate",children:n.name}),e.jsx("span",{className:"text-sm font-mono text-neutral-500 flex-1 truncate",children:n.command}),e.jsx("button",{onClick:()=>p(d),className:"p-0.5 text-neutral-300 hover:text-red-500 opacity-0 group-hover:opacity-100 transition-opacity shrink-0",children:e.jsx(ee,{size:14})})]},d))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:P,onChange:n=>l(n.target.value),onKeyDown:b,placeholder:v("名称"),className:"w-28 shrink-0 px-3 py-2 border border-neutral-200 rounded-lg text-sm focus:outline-none focus:ring-1 focus:ring-neutral-300"}),e.jsx("input",{type:"text",value:i,onChange:n=>c(n.target.value),onKeyDown:b,placeholder:v("命令"),className:"flex-1 px-3 py-2 border border-neutral-200 rounded-lg text-sm font-mono focus:outline-none focus:ring-1 focus:ring-neutral-300"}),e.jsxs("button",{onClick:x,disabled:!P.trim()||!i.trim(),className:"flex items-center gap-1 px-3 py-2 text-sm bg-neutral-900 text-white rounded-lg hover:bg-neutral-800 disabled:opacity-30 disabled:cursor-not-allowed transition-colors shrink-0",children:[e.jsx(te,{size:14}),e.jsx("span",{children:v("添加")})]})]})]})}function V(t){return t?t.split(",").map(j=>j.trim()).filter(Boolean):[]}function Y(t){if(!t)return[];try{return JSON.parse(t)}catch{return[]}}function Z(t){return typeof t.color!="string"||t.color.trim()===""?"bg-muted-foreground":t.color.startsWith("bg-")?t.color:t.color.startsWith("text-")?t.color.replace("text-","bg-"):"bg-muted-foreground"}function Me(){const{t}=G(),{data:j,isLoading:v}=xe({limit:100,includeArchived:!0}),P=pe(),l=he(),i=fe(),[c,x]=o.useState(""),[p,b]=o.useState(null),[n,d]=o.useState({copyFiles:[],setupScript:"",quickCommands:[]}),[N,u]=o.useState(!1),[g,k]=o.useState(null),[I,w]=o.useState(!1),[z,D]=o.useState(!1),[C,F]=o.useState(!1),[s,a]=o.useState(!1),[S,q]=o.useState(""),[se,U]=o.useState(!1),R=j?.data??[],h=o.useMemo(()=>R.filter(r=>!r.archivedAt),[R]),E=o.useMemo(()=>R.filter(r=>r.archivedAt),[R]),f=h.find(r=>r.id===c),M=o.useMemo(()=>R.find(r=>r.id===g)??null,[g,R]);if(o.useEffect(()=>{!c&&h.length>0&&x(h[0].id)},[h,c]),o.useEffect(()=>{if(p){h.some(r=>r.id===p)&&(x(p),b(null));return}c&&!h.some(r=>r.id===c)&&(x(h[0]?.id??""),u(!1))},[h,p,c]),o.useEffect(()=>{f&&!N&&d({copyFiles:V(f.copyFiles),setupScript:f.setupScript??"",quickCommands:Y(f.quickCommands)})},[f,N]),v)return e.jsx(L,{className:"max-w-5xl",children:e.jsx(de,{})});if(R.length===0)return e.jsxs(L,{className:"max-w-5xl",children:[e.jsx(J,{title:t("项目配置")}),e.jsx(Q,{message:t("暂无项目,请先创建项目")})]});const re=()=>{c&&P.mutate({id:c,copyFiles:n.copyFiles.length>0?n.copyFiles.join(", "):null,setupScript:n.setupScript.trim()||null,quickCommands:n.quickCommands.length>0?JSON.stringify(n.quickCommands):null},{onSuccess:()=>u(!1)})},ne=r=>{b(null),x(r),u(!1),U(!0)},oe=()=>{f&&(k(f.id),F(!1),a(!1),w(!0))},O=()=>{l.isPending||(w(!1),k(null),F(!1),a(!1))},ae=async()=>{if(g)try{await l.mutateAsync({id:g,deleteRepo:C}),W.success(t(C?"项目已删除,并清理了本地文件":"项目已删除")),u(!1),O()}catch{}},ie=r=>{const m=E.find(y=>y.id===r);k(r),q(m?.repoDeletedAt?m.repoPath:""),D(!0)},T=()=>{i.isPending||(D(!1),k(null),q(""))},le=async()=>{if(!(!g||M?.repoDeletedAt&&!S.trim()))try{const m=await i.mutateAsync({id:g,repoPath:S.trim()||void 0});W.success(t("项目已恢复"));for(const y of m.warnings)W.warning(y);u(!1),b(m.project.id),x(m.project.id),T()}catch{}},_=M?.name??t("this project"),B=!!M?.repoDeletedAt;return e.jsxs(e.Fragment,{children:[e.jsxs(L,{className:"max-w-5xl",children:[e.jsx(J,{title:t("项目配置")}),h.length===0&&E.length===0?e.jsx(Q,{message:t("暂无项目,请先创建项目")}):e.jsx(be,{items:h,selectedId:c,onSelectItem:ne,getItemId:r=>r.id,mobileShowDetail:se,onMobileBack:()=>U(!1),renderListItem:(r,m)=>e.jsxs(e.Fragment,{children:[e.jsx("span",{className:K("h-2 w-2 rounded-full shrink-0",m?"bg-primary-foreground/60":Z(r))}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[13px] font-medium",children:r.name}),e.jsx("div",{className:K("truncate text-[11px] font-mono",m?"text-primary-foreground/70":"text-muted-foreground"),children:r.repoPath.split("/").pop()})]})]}),renderListFooter:E.length>0?()=>e.jsxs("div",{className:"pt-3 mt-2 border-t border-border",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 mb-1",children:[e.jsx("span",{className:"text-[11px] font-medium text-muted-foreground",children:t("已删除")}),e.jsx("span",{className:"rounded-full bg-muted px-1.5 py-0.5 text-[10px] font-medium text-muted-foreground",children:E.length})]}),E.map(r=>e.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-lg px-3 py-2 text-muted-foreground",children:[e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx("div",{className:"truncate text-[12px]",children:r.name})}),e.jsx("button",{onClick:()=>ie(r.id),disabled:i.isPending,className:"shrink-0 text-[11px] hover:text-foreground transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60","aria-label":t("恢复项目"),children:e.jsx(Ne,{size:12})})]},r.id))]}):void 0,renderDetail:r=>r?e.jsxs("div",{className:"p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:K("h-2.5 w-2.5 rounded-full shrink-0",Z(r))}),e.jsx("h3",{className:"text-base font-semibold text-foreground",children:r.name})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground font-mono mb-5",children:r.repoPath}),e.jsxs("div",{className:"divide-y divide-border/60",children:[e.jsxs("div",{className:"py-5 first:pt-0",children:[e.jsxs("div",{className:"mb-3",children:[e.jsx("h3",{className:"text-[13px] font-medium text-foreground",children:t("自动复制文件")}),e.jsx("p",{className:"text-[11px] text-muted-foreground mt-0.5",children:t("创建 worktree 时自动从主仓库复制的文件或目录,适用于 .env、node_modules 等不在 git 管理中的文件。支持 glob。")})]}),e.jsx(ye,{value:n.copyFiles,onChange:m=>{d(y=>({...y,copyFiles:m})),u(!0)},repoPath:r.repoPath})]}),e.jsxs("div",{className:"py-5",children:[e.jsxs("div",{className:"mb-3",children:[e.jsx("h3",{className:"text-[13px] font-medium text-foreground",children:t("Setup 脚本")}),e.jsx("p",{className:"text-[11px] text-muted-foreground mt-0.5",children:t("创建 worktree 后自动执行的命令,每行一条。在 worktree 目录下执行,单条超时 5 分钟。")})]}),e.jsx("textarea",{value:n.setupScript,onChange:m=>{d(y=>({...y,setupScript:m.target.value})),u(!0)},placeholder:`pnpm install
|
|
2
|
+
pnpm run setup`,rows:4,className:"w-full rounded-lg border border-input bg-muted/50 px-3 py-2 text-sm font-mono transition-colors focus:border-ring focus:bg-background focus:outline-none resize-none"})]}),e.jsxs("div",{className:"py-5",children:[e.jsxs("div",{className:"mb-3",children:[e.jsx("h3",{className:"text-[13px] font-medium text-foreground",children:t("常用命令")}),e.jsx("p",{className:"text-[11px] text-muted-foreground mt-0.5",children:t("在终端中可快速执行的命令,不会自动运行。")})]}),e.jsx(Pe,{value:n.quickCommands,onChange:m=>{d(y=>({...y,quickCommands:m})),u(!0)}})]})]}),e.jsx("div",{className:"mt-2 rounded-lg border border-destructive/30 bg-destructive/10 p-4",children:e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(ve,{size:15,className:"text-destructive mt-0.5 shrink-0","aria-hidden":"true"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[13px] font-medium text-foreground",children:t("删除项目")}),e.jsx("p",{className:"text-[11px] text-muted-foreground mt-0.5",children:t("项目将从默认列表隐藏,历史记录保留。可选同时删除本地文件。")})]})]}),e.jsxs(A,{size:"sm",variant:"destructive",className:"shrink-0",onClick:oe,disabled:l.isPending||i.isPending,children:[e.jsx(je,{size:13}),t("删除项目")]})]})}),N&&e.jsx(ue,{saving:P.isPending,onSave:re,onCancel:()=>{f&&d({copyFiles:V(f.copyFiles),setupScript:f.setupScript??"",quickCommands:Y(f.quickCommands)}),u(!1)},className:"-mx-5"})]}):e.jsx("div",{className:"py-16 text-center text-sm text-muted-foreground",children:h.length>0?t("选择一个项目查看配置"):t("当前没有可配置的项目")})})]}),e.jsx(X,{isOpen:I,onClose:O,title:t("Delete Project"),action:e.jsxs(e.Fragment,{children:[e.jsx(A,{variant:"outline",onClick:O,disabled:l.isPending,children:t("Cancel")}),e.jsx(A,{variant:"destructive",onClick:ae,disabled:l.isPending||C&&!s,children:l.isPending?t("Deleting..."):t("Delete Project")})]}),children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground leading-relaxed",children:t("项目「{title}」将从默认项目列表隐藏,但历史任务、workspace 和会话记录仍会保留。",{title:_})}),e.jsxs("label",{className:"flex items-start gap-3 rounded-lg border border-border bg-muted px-3 py-3",children:[e.jsx("input",{type:"checkbox",checked:C,onChange:r=>{F(r.target.checked),r.target.checked||a(!1)},className:"mt-0.5 h-4 w-4 rounded border-border accent-primary"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:t("同时删除本地项目文件")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:t("勾选后会删除 repoPath 指向的本地仓库目录,并禁用代码/Git 相关能力。")})]})]}),C&&e.jsxs("div",{className:"rounded-lg border border-destructive/30 bg-destructive/10 px-3 py-3",children:[e.jsx("p",{className:"text-sm font-medium text-destructive",children:t("勾选后会连项目文件一起删除,请谨慎选择。")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:t("恢复该项目时需要重新绑定一个有效的 Git 仓库路径。")}),e.jsxs("label",{className:"mt-3 flex items-start gap-2 text-xs text-foreground",children:[e.jsx("input",{type:"checkbox",checked:s,onChange:r=>a(r.target.checked),className:"mt-0.5 h-4 w-4 rounded border-border accent-primary"}),e.jsx("span",{children:t("我已确认这会删除本地项目文件")})]})]}),l.isError&&e.jsx("p",{className:"text-xs text-destructive",children:l.error instanceof Error?l.error.message:t("Failed to delete project")})]})}),e.jsx(X,{isOpen:z,onClose:T,title:t("Restore Project"),action:e.jsxs(e.Fragment,{children:[e.jsx(A,{variant:"outline",onClick:T,disabled:i.isPending,children:t("Cancel")}),e.jsx(A,{onClick:le,disabled:i.isPending||B&&!S.trim(),children:i.isPending?t("Restoring..."):t("Restore Project")})]}),children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground leading-relaxed",children:B?t("项目「{title}」的本地仓库文件已删除。恢复前需要重新绑定一个有效的 Git 仓库路径。",{title:_}):t("恢复后,项目会重新出现在默认项目列表中。")}),B&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-foreground mb-1.5",children:t("Repository Path")}),e.jsx(ge,{value:S,onChange:q}),e.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:t("Agent Tower 会尽量校验仓库 identity;如果 remote URL 或目录名不同,会给出警告但允许继续。")})]}),i.isError&&e.jsx("p",{className:"text-xs text-destructive",children:i.error instanceof Error?i.error.message:t("Failed to restore project")})]})})]})}export{Me as ProjectSettingsPage};
|
package/dist/web/assets/{ProviderSettingsPage-DQ_IDUUZ.js → ProviderSettingsPage-BlLaN0i2.js}
RENAMED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import{h as Ne,i as Ce,q as Ee,m as ke,u as _,r as v,j as n,g as S,S as te,
|
|
2
|
-
`,
|
|
3
|
-
`))}return
|
|
1
|
+
import{h as Ne,i as Ce,q as Ee,m as ke,u as _,r as v,j as n,g as S,S as te,M as Pe,d as Oe,B as N,n as Ie,Y as _e,t as P,f as K,U as ne}from"./index-DbO4YyUv.js";import{u as Se,a as Te,b as Ae,c as De,d as Le,e as Re,f as Fe}from"./use-providers-BOyY0DcV.js";import{C as Me}from"./confirm-dialog-BAnxa2C9.js";import{I as M}from"./input-Dqnd4oTj.js";import{M as q,T as Ue}from"./modal-CAB_bs-c.js";import{S as le}from"./select-BJfNuuIV.js";import{C as ze,S as Be}from"./switch-bLlDOWNp.js";import{T as ae}from"./textarea-BcVRpxhF.js";import{A as w}from"./log-adapter-CjgRCCYG.js";import{C as oe}from"./chevron-down-Cur5jANy.js";import{S as Ge}from"./SettingsMasterDetail-CdimTj5n.js";import{U as Ke,C as Xe}from"./upload-DNwyW_bv.js";import{P as Z,T as ce}from"./trash-2-8Pu6lwnW.js";import{P as Ve}from"./pencil-B__GQn9r.js";import{R as Ze}from"./rotate-ccw-5d-eMwsw.js";import"./check-D9lM__p8.js";import"./arrow-left-B6KMicbE.js";const $e=[["path",{d:"M12 15V3",key:"m9g1x1"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["path",{d:"m7 10 5 5 5-5",key:"brsn70"}]],Ye=Ne("download",$e);function qe(e,t){let l=e.slice(0,t).split(/\r\n|\n|\r/g);return[l.length,l.pop().length+1]}function He(e,t,l){let a=e.split(/\r\n|\n|\r/g),s="",i=(Math.log10(t+1)|0)+1;for(let r=t-1;r<=t+1;r++){let o=a[r-1];o&&(s+=r.toString().padEnd(i," "),s+=": ",s+=o,s+=`
|
|
2
|
+
`,r===t&&(s+=" ".repeat(i+l+2),s+=`^
|
|
3
|
+
`))}return s}class p extends Error{line;column;codeblock;constructor(t,l){const[a,s]=qe(l.toml,l.ptr),i=He(l.toml,a,s);super(`Invalid TOML document: ${t}
|
|
4
4
|
|
|
5
|
-
${i}`,l),this.line=a,this.column=
|
|
5
|
+
${i}`,l),this.line=a,this.column=s,this.codeblock=i}}function Je(e,t){let l=0;for(;e[t-++l]==="\\";);return--l&&l%2}function $(e,t=0,l=e.length){let a=e.indexOf(`
|
|
6
6
|
`,t);return e[a-1]==="\r"&&a--,a<=l?a:-1}function U(e,t){for(let l=t;l<e.length;l++){let a=e[l];if(a===`
|
|
7
7
|
`)return l;if(a==="\r"&&e[l+1]===`
|
|
8
|
-
`)return l+1;if(a<" "&&a!==" "||a==="")throw new p("control characters are not allowed in comments",{toml:e,ptr:t})}return e.length}function
|
|
9
|
-
`||
|
|
10
|
-
`);)t++;return a||
|
|
11
|
-
`||
|
|
12
|
-
`))return i}}throw new p("cannot find end of structure",{toml:e,ptr:t})}function de(e,t){let l=e[t],a=l===e[t+1]&&e[t+1]===e[t+2]?e.slice(t,t+3):l;t+=a.length-1;do t=e.indexOf(a,++t);while(t>-1&&l!=="'"&&
|
|
13
|
-
`,f:"\f",r:"\r",e:"\x1B",'"':'"',"\\":"\\"};function ue(e,t=0,l=e.length){let a=e[t]==="'",
|
|
14
|
-
`&&t++);let i=0,
|
|
8
|
+
`)return l+1;if(a<" "&&a!==" "||a==="")throw new p("control characters are not allowed in comments",{toml:e,ptr:t})}return e.length}function I(e,t,l,a){let s;for(;(s=e[t])===" "||s===" "||!l&&(s===`
|
|
9
|
+
`||s==="\r"&&e[t+1]===`
|
|
10
|
+
`);)t++;return a||s!=="#"?t:I(e,U(e,t),l)}function We(e,t,l,a,s=!1){if(!a)return t=$(e,t),t<0?e.length:t;for(let i=t;i<e.length;i++){let r=e[i];if(r==="#")i=$(e,i);else{if(r===l)return i+1;if(r===a||s&&(r===`
|
|
11
|
+
`||r==="\r"&&e[i+1]===`
|
|
12
|
+
`))return i}}throw new p("cannot find end of structure",{toml:e,ptr:t})}function de(e,t){let l=e[t],a=l===e[t+1]&&e[t+1]===e[t+2]?e.slice(t,t+3):l;t+=a.length-1;do t=e.indexOf(a,++t);while(t>-1&&l!=="'"&&Je(e,t));return t>-1&&(t+=a.length,a.length>1&&(e[t]===l&&t++,e[t]===l&&t++)),t}let Qe=/^(\d{4}-\d{2}-\d{2})?[T ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|[-+]\d{2}:\d{2})?$/i;class A extends Date{#t=!1;#n=!1;#e=null;constructor(t){let l=!0,a=!0,s="Z";if(typeof t=="string"){let i=t.match(Qe);i?(i[1]||(l=!1,t=`0000-01-01T${t}`),a=!!i[2],a&&t[10]===" "&&(t=t.replace(" ","T")),i[2]&&+i[2]>23?t="":(s=i[3]||null,t=t.toUpperCase(),!s&&a&&(t+="Z"))):t=""}super(t),isNaN(this.getTime())||(this.#t=l,this.#n=a,this.#e=s)}isDateTime(){return this.#t&&this.#n}isLocal(){return!this.#t||!this.#n||!this.#e}isDate(){return this.#t&&!this.#n}isTime(){return this.#n&&!this.#t}isValid(){return this.#t||this.#n}toISOString(){let t=super.toISOString();if(this.isDate())return t.slice(0,10);if(this.isTime())return t.slice(11,23);if(this.#e===null)return t.slice(0,-1);if(this.#e==="Z")return t;let l=+this.#e.slice(1,3)*60+ +this.#e.slice(4,6);return l=this.#e[0]==="-"?l:-l,new Date(this.getTime()-l*6e4).toISOString().slice(0,-1)+this.#e}static wrapAsOffsetDateTime(t,l="Z"){let a=new A(t);return a.#e=l,a}static wrapAsLocalDateTime(t){let l=new A(t);return l.#e=null,l}static wrapAsLocalDate(t){let l=new A(t);return l.#n=!1,l.#e=null,l}static wrapAsLocalTime(t){let l=new A(t);return l.#t=!1,l.#e=null,l}}let et=/^((0x[0-9a-fA-F](_?[0-9a-fA-F])*)|(([+-]|0[ob])?\d(_?\d)*))$/,tt=/^[+-]?\d(_?\d)*(\.\d(_?\d)*)?([eE][+-]?\d(_?\d)*)?$/,nt=/^[+-]?0[0-9_]/,rt=/^[0-9a-f]{2,8}$/i,re={b:"\b",t:" ",n:`
|
|
13
|
+
`,f:"\f",r:"\r",e:"\x1B",'"':'"',"\\":"\\"};function ue(e,t=0,l=e.length){let a=e[t]==="'",s=e[t++]===e[t]&&e[t]===e[t+1];s&&(l-=2,e[t+=2]==="\r"&&t++,e[t]===`
|
|
14
|
+
`&&t++);let i=0,r,o="",d=t;for(;t<l-1;){let c=e[t++];if(c===`
|
|
15
15
|
`||c==="\r"&&e[t]===`
|
|
16
|
-
`){if(!
|
|
17
|
-
`||c===" "||c===" "||c==="\r")){if(t=
|
|
18
|
-
`&&e[t]!=="\r")throw new p("invalid escape: only line-ending whitespace may be escaped",{toml:e,ptr:i});t=
|
|
19
|
-
`&&e[
|
|
20
|
-
`&&
|
|
21
|
-
`&&i!=="\r"){let
|
|
22
|
-
`&&e[o]!=="\r")throw new p("each key-value declaration must be followed by an end-of-line",{toml:e,ptr:o});o=
|
|
16
|
+
`){if(!s)throw new p("newlines are not allowed in strings",{toml:e,ptr:t-1})}else if(c<" "&&c!==" "||c==="")throw new p("control characters are not allowed in strings",{toml:e,ptr:t-1});if(r){if(r=!1,c==="x"||c==="u"||c==="U"){let f=e.slice(t,t+=c==="x"?2:c==="u"?4:8);if(!rt.test(f))throw new p("invalid unicode escape",{toml:e,ptr:i});try{o+=String.fromCodePoint(parseInt(f,16))}catch{throw new p("invalid unicode escape",{toml:e,ptr:i})}}else if(s&&(c===`
|
|
17
|
+
`||c===" "||c===" "||c==="\r")){if(t=I(e,t-1,!0),e[t]!==`
|
|
18
|
+
`&&e[t]!=="\r")throw new p("invalid escape: only line-ending whitespace may be escaped",{toml:e,ptr:i});t=I(e,t)}else if(c in re)o+=re[c];else throw new p("unrecognized escape sequence",{toml:e,ptr:i});d=t}else!a&&c==="\\"&&(i=t-1,r=!0,o+=e.slice(d,i))}return o+e.slice(d,l-1)}function st(e,t,l,a){if(e==="true")return!0;if(e==="false")return!1;if(e==="-inf")return-1/0;if(e==="inf"||e==="+inf")return 1/0;if(e==="nan"||e==="+nan"||e==="-nan")return NaN;if(e==="-0")return a?0n:0;let s=et.test(e);if(s||tt.test(e)){if(nt.test(e))throw new p("leading zeroes are not allowed",{toml:t,ptr:l});e=e.replace(/_/g,"");let r=+e;if(isNaN(r))throw new p("invalid number",{toml:t,ptr:l});if(s){if((s=!Number.isSafeInteger(r))&&!a)throw new p("integer value cannot be represented losslessly",{toml:t,ptr:l});(s||a===!0)&&(r=BigInt(e))}return r}const i=new A(e);if(!i.isValid())throw new p("invalid value",{toml:t,ptr:l});return i}function it(e,t,l){let a=e.slice(t,l),s=a.indexOf("#");return s>-1&&(U(e,s),a=a.slice(0,s)),[a.trimEnd(),s]}function H(e,t,l,a,s){if(a===0)throw new p("document contains excessively nested structures. aborting.",{toml:e,ptr:t});let i=e[t];if(i==="["||i==="{"){let[d,c]=i==="["?ot(e,t,a,s):at(e,t,a,s);if(l){if(c=I(e,c),e[c]===",")c++;else if(e[c]!==l)throw new p("expected comma or end of structure",{toml:e,ptr:c})}return[d,c]}let r;if(i==='"'||i==="'"){r=de(e,t);let d=ue(e,t,r);if(l){if(r=I(e,r),e[r]&&e[r]!==","&&e[r]!==l&&e[r]!==`
|
|
19
|
+
`&&e[r]!=="\r")throw new p("unexpected character encountered",{toml:e,ptr:r});r+=+(e[r]===",")}return[d,r]}r=We(e,t,",",l);let o=it(e,t,r-+(e[r-1]===","));if(!o[0])throw new p("incomplete key-value declaration: no value specified",{toml:e,ptr:t});return l&&o[1]>-1&&(r=I(e,t+o[1]),r+=+(e[r]===",")),[st(o[0],e,t,s),r]}let lt=/^[a-zA-Z0-9-_]+[ \t]*$/;function Y(e,t,l="="){let a=t-1,s=[],i=e.indexOf(l,t);if(i<0)throw new p("incomplete key-value: cannot find end of key",{toml:e,ptr:t});do{let r=e[t=++a];if(r!==" "&&r!==" ")if(r==='"'||r==="'"){if(r===e[t+1]&&r===e[t+2])throw new p("multiline strings are not allowed in keys",{toml:e,ptr:t});let o=de(e,t);if(o<0)throw new p("unfinished string encountered",{toml:e,ptr:t});a=e.indexOf(".",o);let d=e.slice(o,a<0||a>i?i:a),c=$(d);if(c>-1)throw new p("newlines are not allowed in keys",{toml:e,ptr:t+a+c});if(d.trimStart())throw new p("found extra tokens after the string part",{toml:e,ptr:o});if(i<o&&(i=e.indexOf(l,o),i<0))throw new p("incomplete key-value: cannot find end of key",{toml:e,ptr:t});s.push(ue(e,t,o))}else{a=e.indexOf(".",t);let o=e.slice(t,a<0||a>i?i:a);if(!lt.test(o))throw new p("only letter, numbers, dashes and underscores are allowed in keys",{toml:e,ptr:t});s.push(o.trimEnd())}}while(a+1&&a<i);return[s,I(e,i+1,!0,!0)]}function at(e,t,l,a){let s={},i=new Set,r;for(t++;(r=e[t++])!=="}"&&r;){if(r===",")throw new p("expected value, found comma",{toml:e,ptr:t-1});if(r==="#")t=U(e,t);else if(r!==" "&&r!==" "&&r!==`
|
|
20
|
+
`&&r!=="\r"){let o,d=s,c=!1,[f,j]=Y(e,t-1);for(let x=0;x<f.length;x++){if(x&&(d=c?d[o]:d[o]={}),o=f[x],(c=Object.hasOwn(d,o))&&(typeof d[o]!="object"||i.has(d[o])))throw new p("trying to redefine an already defined value",{toml:e,ptr:t});!c&&o==="__proto__"&&Object.defineProperty(d,o,{enumerable:!0,configurable:!0,writable:!0})}if(c)throw new p("trying to redefine an already defined value",{toml:e,ptr:t});let[h,m]=H(e,j,"}",l-1,a);i.add(h),d[o]=h,t=m}}if(!r)throw new p("unfinished table encountered",{toml:e,ptr:t});return[s,t]}function ot(e,t,l,a){let s=[],i;for(t++;(i=e[t++])!=="]"&&i;){if(i===",")throw new p("expected value, found comma",{toml:e,ptr:t-1});if(i==="#")t=U(e,t);else if(i!==" "&&i!==" "&&i!==`
|
|
21
|
+
`&&i!=="\r"){let r=H(e,t-1,"]",l-1,a);s.push(r[0]),t=r[1]}}if(!i)throw new p("unfinished array encountered",{toml:e,ptr:t});return[s,t]}function se(e,t,l,a){let s=t,i=l,r,o=!1,d;for(let c=0;c<e.length;c++){if(c){if(s=o?s[r]:s[r]={},i=(d=i[r]).c,a===0&&(d.t===1||d.t===2))return null;if(d.t===2){let f=s.length-1;s=s[f],i=i[f].c}}if(r=e[c],(o=Object.hasOwn(s,r))&&i[r]?.t===0&&i[r]?.d)return null;o||(r==="__proto__"&&(Object.defineProperty(s,r,{enumerable:!0,configurable:!0,writable:!0}),Object.defineProperty(i,r,{enumerable:!0,configurable:!0,writable:!0})),i[r]={t:c<e.length-1&&a===2?3:a,d:!1,i:0,c:{}})}if(d=i[r],d.t!==a&&!(a===1&&d.t===3)||(a===2&&(d.d||(d.d=!0,s[r]=[]),s[r].push(s={}),d.c[d.i++]=d={t:1,d:!1,i:0,c:{}}),d.d))return null;if(d.d=!0,a===1)s=o?s[r]:s[r]={};else if(a===0&&o)return null;return[r,s,d.c]}function ct(e,{maxDepth:t=1e3,integersAsBigInt:l}={}){let a={},s={},i=a,r=s;for(let o=I(e,0);o<e.length;){if(e[o]==="["){let d=e[++o]==="[",c=Y(e,o+=+d,"]");if(d){if(e[c[1]-1]!=="]")throw new p("expected end of table declaration",{toml:e,ptr:c[1]-1});c[1]++}let f=se(c[0],a,s,d?2:1);if(!f)throw new p("trying to redefine an already defined table or value",{toml:e,ptr:o});r=f[2],i=f[1],o=c[1]}else{let d=Y(e,o),c=se(d[0],i,r,0);if(!c)throw new p("trying to redefine an already defined table or value",{toml:e,ptr:o});let f=H(e,d[1],void 0,t,l);c[1][c[0]]=f[0],o=f[1]}if(o=I(e,o,!0),e[o]&&e[o]!==`
|
|
22
|
+
`&&e[o]!=="\r")throw new p("each key-value declaration must be followed by an end-of-line",{toml:e,ptr:o});o=I(e,o)}return a}function dt(){return Ce({queryKey:Ee.system.cursorAgentModels,queryFn:()=>ke.get("/system/cursor-agent-models"),staleTime:1e3*60*10})}function ut({value:e,onChange:t}){const{t:l}=_(),{data:a,isLoading:s,isError:i}=dt(),r=a?.models??[],[o,d]=v.useState(!1),[c,f]=v.useState(""),j=v.useMemo(()=>{const h=c.trim().toLowerCase();return h?r.filter(m=>m.id.toLowerCase().includes(h)||m.label.toLowerCase().includes(h)):r},[r,c]);return n.jsxs("div",{className:"flex flex-col gap-2 flex-1 min-w-0",children:[n.jsx("input",{type:"text",value:e,onChange:h=>{const m=h.target.value;t(m===""?void 0:m)},placeholder:l("留空为 auto;或直接输入模型 ID(与 cursor-agent --model 一致)"),className:"w-full px-3 py-1.5 text-sm border border-neutral-200 rounded focus:outline-none focus:ring-1 focus:ring-neutral-900 font-mono"}),n.jsxs("button",{type:"button",onClick:()=>d(h=>!h),disabled:s,className:"flex items-center gap-1 text-xs text-neutral-600 hover:text-neutral-900 disabled:opacity-50 w-fit",children:[n.jsx(oe,{size:14,className:S("transition-transform",o&&"rotate-180")}),s?l("正在加载 cursor-agent 模型列表…"):o?l("收起列表"):l("从本机 cursor-agent 选择({count} 个)",{count:r.length})]}),o&&!s&&n.jsxs("div",{className:"rounded-lg border border-neutral-200 bg-white shadow-sm overflow-hidden",children:[n.jsx("input",{type:"text",value:c,onChange:h=>f(h.target.value),placeholder:l("筛选模型…"),className:"w-full px-3 py-2 text-sm border-b border-neutral-100 focus:outline-none focus:ring-1 focus:ring-inset focus:ring-neutral-300"}),n.jsxs("div",{className:"max-h-[min(50vh,22rem)] overflow-y-auto py-1",children:[n.jsx("button",{type:"button",onClick:()=>{t(void 0),d(!1),f("")},className:S("w-full px-3 py-2 text-left text-sm hover:bg-neutral-50",e?"text-neutral-700":"bg-neutral-50 font-medium"),children:l("默认 (auto)")}),j.map(h=>n.jsxs("button",{type:"button",onClick:()=>{t(h.id),d(!1),f("")},className:S("w-full px-3 py-2 text-left text-sm hover:bg-neutral-50 border-t border-neutral-100",e===h.id?"bg-blue-50/80":""),children:[n.jsx("div",{className:"font-mono text-xs text-neutral-900 break-all",children:h.id}),n.jsx("div",{className:"text-xs text-neutral-500 mt-0.5 break-words",children:h.label})]},h.id)),j.length===0&&n.jsx("div",{className:"px-3 py-4 text-xs text-neutral-400 text-center",children:l("无匹配项")})]})]}),(i||a?.error)&&n.jsxs("p",{className:"text-xs text-amber-700",children:[l("无法从本机加载模型列表({error})。仍可手动输入;或在安装 cursor-agent 的机器上运行",{error:a?.error??l("请求失败")}),n.jsx("code",{className:"mx-0.5 bg-neutral-100 px-1 rounded text-[11px]",children:"cursor-agent --list-models"}),l("查看 ID。")]})]})}const z={CLAUDE_CODE:"Claude Code",GEMINI_CLI:"Gemini CLI",CURSOR_AGENT:"Cursor Agent",CODEX:"Codex"},F={key:"appendPrompt",label:"追加 Prompt",type:"textarea",rows:3,placeholder:"追加到每次 prompt 末尾的文本"},J={[w.CLAUDE_CODE]:[{key:"dangerouslySkipPermissions",label:"跳过权限确认",type:"switch"},{key:"model",label:"模型",type:"input",placeholder:"claude-sonnet-4-20250514"},{key:"effort",label:"推理强度",type:"select",options:[{value:"",label:"默认"},{value:"low",label:"Low"},{value:"medium",label:"Medium"},{value:"high",label:"High"},{value:"xhigh",label:"XHigh"},{value:"max",label:"Max"}]},F],[w.GEMINI_CLI]:[{key:"yolo",label:"跳过权限确认",type:"switch"},{key:"model",label:"模型",type:"input",placeholder:"gemini-2.5-pro"},F],[w.CURSOR_AGENT]:[{key:"force",label:"强制执行",type:"switch"},{key:"model",label:"模型",type:"cursor_model"},F],[w.CODEX]:[{key:"dangerouslyBypassApprovalsAndSandbox",label:"跳过所有确认和沙盒",type:"switch"},{key:"model",label:"模型",type:"input",placeholder:"o3"},{key:"profile",label:"Profile",type:"input",placeholder:"~/.codex/config.toml 中的 profile 名称"},F]};function ie(){return{}}function W(e,t){return{...t}}const mt=JSON.stringify({env:{ANTHROPIC_API_KEY:"",ANTHROPIC_BASE_URL:""}},null,2),xt=`# Codex config.toml 配置片段 — 通过 -c 参数注入,不会修改 ~/.codex/config.toml
|
|
23
23
|
# 参考: https://developers.openai.com/codex/config-sample
|
|
24
24
|
|
|
25
25
|
# ─── 模型与推理 ─────────────────────────────────────────────
|
|
@@ -51,4 +51,4 @@ ${i}`,l),this.line=a,this.column=r,this.codeblock=i}}function Ye(e,t){let l=0;fo
|
|
|
51
51
|
# name = "Ollama"
|
|
52
52
|
# base_url = "http://localhost:11434/v1"
|
|
53
53
|
# wire_api = "responses"
|
|
54
|
-
`;function X(e){return e===w.CLAUDE_CODE?mt:e===w.CODEX?xt:""}function ft(e){return e===w.CLAUDE_CODE||e===w.CODEX}const pt=Object.values(Y).flat().reduce((e,t)=>(e[t.key]||(e[t.key]=t.label),e),{}),ht=Object.values(Y).flat().reduce((e,t)=>(t.options&&(e[t.key]=Object.fromEntries(t.options.map(l=>[l.value,l.label]))),e),{});function gt(e,t){return typeof t=="boolean"?t?ne("是"):ne("否"):typeof t=="string"&&t?ht[e]?.[t]??t:String(t)}function T(e,t){return e instanceof Error?e.message:t}function bt(e){return`agent-tower-provider-backup-${e.replace(/[:.]/g,"-")}.json`}function vt(e,t){const l=new Blob([JSON.stringify(t,null,2)],{type:"application/json"}),a=URL.createObjectURL(l),r=document.createElement("a");r.href=a,r.download=e,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(a)}function yt(e){switch(e){case"CREATE":return{label:"新增",className:"bg-success/10 text-success"};case"OVERWRITE":return{label:"覆盖",className:"bg-warning/10 text-warning"};case"SKIP":return{label:"跳过",className:"bg-muted text-muted-foreground"}}}function jt({type:e}){const t=e==="LOGIN_DETECTED"||e==="INSTALLATION_FOUND";return n.jsx("span",{className:S("inline-block h-2 w-2 rounded-full shrink-0",t?"bg-success":"bg-border"),title:t?"Available":"Unavailable",children:n.jsx("span",{className:"sr-only",children:t?"Available":"Unavailable"})})}function wt({type:e}){const{t}=_();return e==="LOGIN_DETECTED"||e==="INSTALLATION_FOUND"?n.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-success/10 px-2 py-0.5 text-[11px] font-medium text-success",children:[n.jsx(ze,{size:11,"aria-hidden":"true"}),t("可用")]}):n.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-muted px-2 py-0.5 text-[11px] font-medium text-muted-foreground",children:[n.jsx(Xe,{size:11,"aria-hidden":"true"}),t("不可用")]})}function V({title:e,defaultOpen:t=!1,children:l}){const[a,r]=v.useState(t);return n.jsxs("div",{className:"rounded-lg border border-border",children:[n.jsxs("button",{type:"button",onClick:()=>r(i=>!i),"aria-expanded":a,className:"w-full flex items-center justify-between rounded-lg px-4 py-2.5 text-sm font-medium text-foreground transition-colors hover:bg-muted/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60 focus-visible:ring-inset",children:[e,n.jsx(ce,{size:14,"aria-hidden":"true",className:S("text-muted-foreground transition-transform motion-reduce:transition-none",a&&"rotate-180")})]}),a&&n.jsx("div",{className:"px-4 pb-4 space-y-3",children:l})]})}function Nt({agentType:e,config:t,onChange:l}){const{t:a}=_(),r=Y[e]??[];if(r.length===0)return n.jsx("p",{className:"text-xs text-muted-foreground",children:a("该类型暂无运行配置")});const i=(s,o)=>{l({...t,[s]:o})};return n.jsx("div",{className:"space-y-3",children:r.map(s=>s.type==="textarea"?n.jsxs("div",{children:[n.jsx("label",{className:"mb-1 block text-sm text-foreground",children:a(s.label)}),n.jsx(oe,{value:t[s.key]??"",onChange:o=>i(s.key,o.target.value||void 0),placeholder:s.placeholder?a(s.placeholder):void 0,rows:s.rows??3,className:"py-1.5"})]},s.key):s.type==="cursor_model"?n.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-start",children:[n.jsx("label",{className:"w-32 shrink-0 text-sm text-foreground sm:pt-2",children:a(s.label)}),n.jsx(ut,{value:t[s.key]??"",onChange:o=>i(s.key,o)})]},s.key):n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("label",{className:"w-32 shrink-0 text-sm text-foreground",children:a(s.label)}),s.type==="switch"&&n.jsx(Be,{checked:!!t[s.key],onCheckedChange:o=>i(s.key,o),"aria-label":a(s.label)}),s.type==="input"&&n.jsx(M,{value:t[s.key]??"",onChange:o=>i(s.key,o.target.value||void 0),placeholder:s.placeholder?a(s.placeholder):void 0,className:"flex-1 py-1.5"}),s.type==="select"&&s.options&&n.jsx(ae,{value:t[s.key]??"",onChange:o=>i(s.key,o||void 0),options:s.options,placeholder:a("选择...")})]},s.key))})}function Ct({isOpen:e,onClose:t,initialData:l,onSave:a}){const{t:r}=_(),[i,s]=v.useState(l??{name:"",agentType:w.CLAUDE_CODE,config:ie(),settings:"",env:[],isDefault:!1}),[o,d]=v.useState("");v.useEffect(()=>{if(!l&&!i.settings){const m=X(i.agentType);m&&s(x=>({...x,settings:m}))}},[]);const c=m=>{s(x=>({...x,agentType:m,config:ie(),settings:X(m)}))},f=()=>{d("");const m=W(i.agentType,i.config),x={};for(const[I,k]of Object.entries(m))k!==void 0&&k!==""&&(x[I]=k);const y=i.settings.trim();if(y){if(i.agentType===w.CODEX)try{ct(y)}catch(I){d(r("TOML 语法错误: {message}",{message:I instanceof Error?I.message:String(I)}));return}else if(i.agentType===w.CLAUDE_CODE)try{JSON.parse(y)}catch{d(r("JSON 语法错误"));return}}const b={};for(const{key:I,value:k}of i.env){const D=I.trim();D&&(b[D]=k)}const E=!!l,B={name:i.name,agentType:i.agentType,config:x,settings:E?y||"":y||void 0,env:E||Object.keys(b).length>0?b:void 0,isDefault:i.isDefault};a(B)};if(!e)return null;const j=ft(i.agentType),h=i.agentType===w.CODEX;return n.jsx(H,{isOpen:e,onClose:t,title:r(l?"编辑 Provider":"新建 Provider"),className:"max-w-2xl",children:n.jsxs("div",{className:"space-y-4",children:[n.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2",children:[n.jsxs("div",{children:[n.jsx("label",{htmlFor:"provider-name",className:"mb-1 block text-xs font-medium text-foreground",children:r("名称")}),n.jsx(M,{id:"provider-name",value:i.name,onChange:m=>s(x=>({...x,name:m.target.value})),placeholder:r("例如: Claude Code (官方)")})]}),!l&&n.jsxs("div",{children:[n.jsx("label",{className:"mb-1 block text-xs font-medium text-foreground",children:r("Agent 类型")}),n.jsx(ae,{value:i.agentType,onChange:m=>c(m),options:Object.values(w).map(m=>({value:m,label:z[m]??m})),placeholder:r("选择 Agent 类型")})]})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("input",{type:"checkbox",id:"isDefault",checked:i.isDefault,onChange:m=>s(x=>({...x,isDefault:m.target.checked})),className:"h-4 w-4 rounded border-border accent-primary"}),n.jsx("label",{htmlFor:"isDefault",className:"text-sm text-foreground",children:r("设为该类型的默认 Provider")})]}),n.jsx(V,{title:r("运行配置"),defaultOpen:!0,children:n.jsx(Nt,{agentType:i.agentType,config:i.config,onChange:m=>s(x=>({...x,config:m}))})}),n.jsxs(V,{title:r("环境变量"),defaultOpen:i.env.length>0,children:[n.jsxs("p",{className:"text-xs text-muted-foreground mb-2",children:[r("注入到 Agent 进程的环境变量。Codex 的")," ",n.jsx("code",{className:"rounded bg-muted px-1",children:"env_key"})," ",r("指定的是变量名,实际值需在此处设置。")]}),n.jsxs("div",{className:"space-y-2",children:[i.env.map((m,x)=>n.jsxs("div",{className:"flex gap-2 items-center",children:[n.jsx(M,{value:m.key,onChange:y=>{const b=[...i.env];b[x]={...b[x],key:y.target.value},s(E=>({...E,env:b}))},placeholder:r("变量名,如 AZURE_OPENAI_API_KEY"),className:"flex-1 py-1.5 font-mono"}),n.jsx(M,{value:m.value,onChange:y=>{const b=[...i.env];b[x]={...b[x],value:y.target.value},s(E=>({...E,env:b}))},placeholder:r("值"),className:"flex-1 py-1.5 font-mono"}),n.jsx("button",{type:"button",onClick:()=>{const y=i.env.filter((b,E)=>E!==x);s(b=>({...b,env:y}))},"aria-label":r("删除"),className:"rounded-md p-1.5 text-muted-foreground transition-colors hover:text-destructive focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60",children:n.jsx(le,{size:14})})]},x)),n.jsxs(N,{variant:"outline",size:"sm",onClick:()=>s(m=>({...m,env:[...m.env,{key:"",value:""}]})),children:[n.jsx(Z,{size:12,className:"mr-1"}),r("添加变量")]})]})]}),j&&n.jsxs(V,{title:r(h?"CLI 原生配置 (config.toml)":"CLI 原生配置 (settings.json)"),children:[n.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:h?n.jsxs(n.Fragment,{children:[r("直接填写 Codex")," ",n.jsx("code",{className:"rounded bg-muted px-1",children:"config.toml"})," ",r("格式的配置片段,通过")," ",n.jsx("code",{className:"rounded bg-muted px-1",children:"-c"})," ",r("参数注入。不会修改你的")," ",n.jsx("code",{className:"rounded bg-muted px-1",children:"~/.codex/config.toml"})," ",r("文件。")]}):n.jsxs(n.Fragment,{children:[r("对应 Claude Code 的")," ",n.jsx("code",{className:"rounded bg-muted px-1",children:"~/.claude/settings.json"}),",",r("通过")," ",n.jsx("code",{className:"rounded bg-muted px-1",children:"--settings"})," ",r("参数注入。在")," ",n.jsx("code",{className:"rounded bg-muted px-1",children:"env"})," ",r("中设置 ANTHROPIC_API_KEY、ANTHROPIC_BASE_URL 等。")]})}),n.jsx(oe,{value:i.settings,onChange:m=>{s(x=>({...x,settings:m.target.value})),d("")},rows:10,className:"font-mono",placeholder:X(i.agentType),"aria-invalid":!!o}),o&&n.jsx("p",{role:"alert",className:"mt-1 text-xs text-destructive",children:o})]}),n.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[n.jsx(N,{variant:"outline",onClick:t,children:r("取消")}),n.jsx(N,{onClick:f,disabled:!i.name.trim(),children:r("保存")})]})]})})}function Et({isOpen:e,onClose:t,onConfirm:l,acknowledged:a,onAcknowledgedChange:r,isLoading:i}){const{t:s}=_();return n.jsx(H,{isOpen:e,onClose:t,title:s("导出 Provider 备份"),className:"max-w-xl",action:n.jsxs(n.Fragment,{children:[n.jsx(N,{variant:"outline",onClick:t,disabled:i,children:s("取消")}),n.jsx(N,{onClick:l,disabled:!a||i,children:s(i?"导出中...":"导出备份")})]}),children:n.jsxs("div",{className:"space-y-4",children:[n.jsxs("div",{className:"flex items-start gap-2.5 rounded-lg border border-warning/30 bg-warning/10 px-4 py-3 text-sm text-foreground",children:[n.jsx(Ue,{size:15,className:"mt-0.5 shrink-0 text-warning","aria-hidden":"true"}),n.jsx("span",{children:s("导出的备份文件将包含完整的 Provider 配置,包括环境变量、CLI settings 等敏感信息。任何拿到文件的人都可能直接使用这些 Provider。")})]}),n.jsxs("div",{className:"space-y-2 text-sm text-muted-foreground",children:[n.jsx("p",{children:s("这个功能用于备份和迁移,不用于分享配置。")}),n.jsx("p",{children:s("导出内容只包含用户层配置:自定义 Provider,以及对内置 Provider 的覆盖。")})]}),n.jsxs("label",{className:"flex items-start gap-3 rounded-lg border border-border px-4 py-3 text-sm text-foreground",children:[n.jsx("input",{type:"checkbox",checked:a,onChange:o=>r(o.target.checked),className:"mt-0.5 h-4 w-4 rounded border-border accent-primary"}),n.jsx("span",{children:s("我已知晓该备份文件包含敏感信息,只会保存在安全位置。")})]})]})})}function kt({isOpen:e,onClose:t,preview:l,backup:a,onConfirm:r,isLoading:i}){const{t:s}=_();if(!l||!a)return null;const o=l.summary.create+l.summary.overwrite,d=[...l.items].sort((c,f)=>{const j={CREATE:0,OVERWRITE:1,SKIP:2};return j[c.action]-j[f.action]});return n.jsx(H,{isOpen:e,onClose:t,title:s("导入 Provider 备份"),className:"max-w-3xl",action:n.jsxs(n.Fragment,{children:[n.jsx(N,{variant:"outline",onClick:t,disabled:i,children:s("取消")}),n.jsx(N,{onClick:r,disabled:o===0||i,children:i?s("导入中..."):s("确认导入 {count} 项",{count:o})})]}),children:n.jsxs("div",{className:"space-y-4",children:[n.jsxs("div",{className:"rounded-lg border border-border bg-muted/40 px-4 py-3 text-sm text-muted-foreground",children:[n.jsx("div",{children:s("导出时间:{value}",{value:new Date(a.exportedAt).toLocaleString()})}),n.jsx("div",{children:s("模式:完整备份(含敏感信息)")}),n.jsx("div",{children:s("文件内 Provider 数量:{count}",{count:a.providers.length})})]}),n.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[n.jsxs("div",{className:"rounded-lg border border-success/25 bg-success/10 px-4 py-3",children:[n.jsx("div",{className:"text-xs font-medium text-success",children:s("新增")}),n.jsx("div",{className:"text-lg font-semibold text-foreground",children:l.summary.create})]}),n.jsxs("div",{className:"rounded-lg border border-warning/25 bg-warning/10 px-4 py-3",children:[n.jsx("div",{className:"text-xs font-medium text-warning",children:s("覆盖")}),n.jsx("div",{className:"text-lg font-semibold text-foreground",children:l.summary.overwrite})]}),n.jsxs("div",{className:"rounded-lg border border-border bg-muted/40 px-4 py-3",children:[n.jsx("div",{className:"text-xs font-medium text-muted-foreground",children:s("跳过")}),n.jsx("div",{className:"text-lg font-semibold text-foreground",children:l.summary.skip})]})]}),n.jsx("div",{className:"max-h-[420px] overflow-y-auto space-y-3 pr-1",children:d.map(c=>{const f=yt(c.action);return n.jsxs("div",{className:"rounded-lg border border-border px-4 py-3",children:[n.jsx("div",{className:"flex items-center justify-between gap-3",children:n.jsxs("div",{className:"min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("h4",{className:"truncate text-sm font-medium text-foreground",children:c.incoming.name}),n.jsx("span",{className:`inline-flex rounded-full px-2 py-0.5 text-[11px] font-medium ${f.className}`,children:s(f.label)})]}),n.jsxs("div",{className:"mt-1 text-xs text-muted-foreground",children:[z[c.incoming.agentType]??c.incoming.agentType," · ",n.jsx("code",{className:"rounded bg-muted px-1 py-0.5",children:c.incoming.id})]})]})}),c.action==="OVERWRITE"&&c.existing&&n.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:s("将覆盖当前已有的 Provider:{name}",{name:c.existing.name})}),c.action==="SKIP"&&n.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:s("当前同 ID Provider 配置一致,本次不会重复写入。")}),c.action==="CREATE"&&n.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:s("当前不存在同 ID Provider,将直接新增。")})]},c.incoming.id)})})]})})}function Pt({item:e,onEdit:t,onDelete:l}){const{t:a}=_(),r=e.provider,i=e.availability,s=W(r.agentType,r.config),o=Object.entries(s).filter(([c])=>c!=="cmd"),d=Object.keys(r.env||{});return n.jsxs("div",{className:"space-y-6",children:[n.jsxs("div",{className:"flex items-start justify-between gap-4",children:[n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center gap-2.5",children:[n.jsx("h3",{className:"text-base font-semibold text-foreground",children:r.name}),n.jsx(wt,{type:i.type})]}),n.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2 text-xs text-muted-foreground",children:[n.jsx("span",{children:z[r.agentType]??r.agentType}),r.isDefault&&n.jsx("span",{className:"rounded-full bg-primary/[0.06] px-2 py-0.5 text-[11px] font-medium text-primary",children:a("默认")}),r.builtIn&&n.jsx("span",{className:"rounded-full bg-muted px-2 py-0.5 text-[11px] font-medium text-muted-foreground",children:a("内置")})]})]}),n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsxs(N,{size:"sm",variant:"outline",onClick:t,children:[n.jsx(Ve,{size:13}),a("编辑")]}),n.jsxs(N,{size:"sm",variant:r.builtIn?"outline":"destructive",onClick:l,disabled:r.deletable===!1,children:[r.builtIn?n.jsx(Ze,{size:13}):n.jsx(le,{size:13}),r.builtIn?a("恢复默认"):a("删除")]})]})]}),o.length>0&&n.jsxs("div",{children:[n.jsx(K,{className:"mb-3",children:a("运行配置")}),n.jsx("div",{className:"grid gap-px overflow-hidden rounded-lg border border-border bg-border/60",children:o.map(([c,f])=>n.jsxs("div",{className:"flex items-center gap-4 bg-background px-4 py-2.5",children:[n.jsx("span",{className:"w-32 shrink-0 text-[13px] text-muted-foreground",children:a(pt[c]??c)}),n.jsx("span",{className:"font-mono text-[13px] text-foreground",children:gt(c,f)})]},c))})]}),d.length>0&&n.jsxs("div",{children:[n.jsx(K,{className:"mb-3",children:a("环境变量")}),n.jsx("div",{className:"grid gap-px overflow-hidden rounded-lg border border-border bg-border/60",children:d.map(c=>n.jsxs("div",{className:"flex items-center gap-4 bg-background px-4 py-2.5",children:[n.jsx("span",{className:"font-mono text-[13px] text-foreground",children:c}),n.jsx("span",{className:"text-[13px] text-muted-foreground","aria-label":"hidden",children:"•••••"})]},c))})]}),r.settings?.trim()&&n.jsxs("div",{children:[n.jsx(K,{className:"mb-3",children:a("CLI 配置")}),n.jsx("div",{className:"rounded-lg border border-border bg-muted/40 p-4",children:n.jsx("pre",{className:"max-h-[200px] overflow-y-auto whitespace-pre-wrap break-all font-mono text-xs text-muted-foreground",children:r.settings})})]}),o.length===0&&d.length===0&&!r.settings?.trim()&&n.jsx("div",{className:"py-8 text-center text-sm text-muted-foreground",children:a('该 Provider 未配置额外参数。点击"编辑"添加运行配置、环境变量或 CLI 配置。')})]})}function Xt(){const{t:e}=_(),{data:t,isLoading:l}=Se(),a=Te(),r=Ae(),i=De(),s=Le(),o=Re(),d=Fe(),c=v.useRef(null),[f,j]=v.useState(null),[h,m]=v.useState(null),[x,y]=v.useState(null),[b,E]=v.useState(!1),[B,I]=v.useState(!1),[k,D]=v.useState(null),[me,G]=v.useState(!1),L=t??[];v.useEffect(()=>{!f&&L.length>0&&j(L[0].provider.id)},[L,f]);const xe=u=>{a.mutate(u,{onSuccess:()=>m(null),onError:g=>P.error(T(g,e("创建 Provider 失败")))})},fe=(u,g)=>{r.mutate({id:u,data:g},{onSuccess:()=>m(null),onError:C=>P.error(T(C,e("更新 Provider 失败")))})},pe=u=>{if(!(u.deletable??!u.builtIn)){P.error(e("系统内置 Provider 不可删除"));return}y({id:u.id,name:u.name,builtIn:u.builtIn})},he=()=>{x&&i.mutate(x.id,{onSuccess:()=>{P.success(x.builtIn?e("已恢复默认 Provider 配置"):e("Provider 已删除")),f===x.id&&j(null),y(null),G(!1)},onError:u=>P.error(T(u,e("删除 Provider 失败")))})},Q=()=>{E(!1),I(!1)},ee=()=>D(null),ge=()=>{s.mutate(void 0,{onSuccess:u=>{vt(bt(u.exportedAt),u),P.success(e("Provider 备份已导出")),Q()},onError:u=>P.error(T(u,e("导出 Provider 备份失败")))})},be=()=>{c.current&&(c.current.value="",c.current.click())},ve=async u=>{const g=u.target.files?.[0];if(u.target.value="",!g)return;let C;try{C=JSON.parse(await g.text())}catch{P.error(e("备份文件不是有效的 JSON"));return}o.mutate(C,{onSuccess:R=>D({backup:C,preview:R}),onError:R=>P.error(T(R,e("导入预览失败")))})},ye=()=>{k&&d.mutate(k.backup,{onSuccess:u=>{const g=u.summary.create+u.summary.overwrite;P.success(g===0?e("导入完成,当前配置无需变更"):e("导入完成:新增 {create},覆盖 {overwrite},跳过 {skip}",{create:u.summary.create,overwrite:u.summary.overwrite,skip:u.summary.skip})),ee()},onError:u=>P.error(T(u,e("导入 Provider 备份失败")))})},je=u=>{const g=u.provider,C=g.env?Object.entries(g.env).map(([R,we])=>({key:R,value:we})):[];m({id:g.id,data:{name:g.name,agentType:g.agentType,config:W(g.agentType,g.config),settings:g.settings??"",env:C,isDefault:g.isDefault}})};return l?n.jsx(te,{className:"max-w-5xl",children:n.jsx(Pe,{})}):n.jsxs(te,{className:"max-w-5xl",children:[n.jsx("input",{ref:c,type:"file",accept:".json,application/json",className:"hidden",onChange:ve}),n.jsx(Ie,{title:e("Agent 配置"),actions:n.jsxs(n.Fragment,{children:[n.jsxs(N,{variant:"outline",size:"sm",onClick:be,disabled:o.isPending||d.isPending,children:[n.jsx(Ke,{size:13}),e("导入")]}),n.jsxs(N,{variant:"outline",size:"sm",onClick:()=>E(!0),disabled:s.isPending,children:[n.jsx(qe,{size:13}),e("导出")]}),n.jsxs(N,{size:"sm",onClick:()=>m({}),children:[n.jsx(Z,{size:13,className:"mr-1"}),e("新建")]})]})}),L.length===0?n.jsx(Oe,{icon:_e,message:e("暂无 Agent 配置"),action:n.jsxs(N,{size:"sm",onClick:()=>m({}),children:[n.jsx(Z,{size:13,className:"mr-1"}),e("新建配置")]})}):n.jsx(Ge,{items:L,selectedId:f,onSelectItem:u=>{j(u),G(!0)},getItemId:u=>u.provider.id,mobileShowDetail:me,onMobileBack:()=>G(!1),renderListItem:(u,g)=>{const C=u.provider;return n.jsxs(n.Fragment,{children:[n.jsx(jt,{type:u.availability.type}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsx("div",{className:"truncate text-[13px] font-medium",children:C.name}),n.jsx("div",{className:S("truncate text-[11px]",g?"text-primary-foreground/60":"text-muted-foreground"),children:z[C.agentType]??C.agentType})]}),C.isDefault&&n.jsx("span",{className:S("shrink-0 rounded px-1.5 py-0.5 text-[10px] font-medium",g?"bg-white/20 text-primary-foreground":"bg-primary/[0.06] text-primary"),children:e("默认")})]})},renderDetail:u=>u?n.jsx("div",{className:"p-5",children:n.jsx(Pt,{item:u,onEdit:()=>je(u),onDelete:()=>pe(u.provider)})}):n.jsx("div",{className:"py-16 text-center text-sm text-muted-foreground",children:e("选择一个 Provider 查看详情")})}),h&&n.jsx(Ct,{isOpen:!0,onClose:()=>m(null),initialData:h.data,onSave:u=>{h.id?fe(h.id,u):xe(u)}}),n.jsx(Me,{isOpen:x!==null,onClose:()=>{i.isPending||y(null)},onConfirm:he,title:x?.builtIn?e("恢复默认 Provider"):e("删除 Provider"),description:x?.builtIn?e('确定删除 "{name}" 的自定义覆盖,并恢复系统默认配置?',{name:x?.name}):e('确定删除 "{name}"?此操作不可撤销。',{name:x?.name}),confirmText:x?.builtIn?e("恢复默认"):e("删除"),cancelText:e("取消"),variant:"danger",isLoading:i.isPending}),n.jsx(Et,{isOpen:b,onClose:Q,onConfirm:ge,acknowledged:B,onAcknowledgedChange:I,isLoading:s.isPending}),n.jsx(kt,{isOpen:!!k,onClose:ee,preview:k?.preview??null,backup:k?.backup??null,onConfirm:ye,isLoading:d.isPending})]})}export{Xt as ProviderSettingsPage};
|
|
54
|
+
`;function X(e){return e===w.CLAUDE_CODE?mt:e===w.CODEX?xt:""}function ft(e){return e===w.CLAUDE_CODE||e===w.CODEX}const pt=Object.values(J).flat().reduce((e,t)=>(e[t.key]||(e[t.key]=t.label),e),{}),ht=Object.values(J).flat().reduce((e,t)=>(t.options&&(e[t.key]=Object.fromEntries(t.options.map(l=>[l.value,l.label]))),e),{});function gt(e,t){return typeof t=="boolean"?t?ne("是"):ne("否"):typeof t=="string"&&t?ht[e]?.[t]??t:String(t)}function T(e,t){return e instanceof Error?e.message:t}function bt(e){return`agent-tower-provider-backup-${e.replace(/[:.]/g,"-")}.json`}function vt(e,t){const l=new Blob([JSON.stringify(t,null,2)],{type:"application/json"}),a=URL.createObjectURL(l),s=document.createElement("a");s.href=a,s.download=e,document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(a)}function yt(e){switch(e){case"CREATE":return{label:"新增",className:"bg-success/10 text-success"};case"OVERWRITE":return{label:"覆盖",className:"bg-warning/10 text-warning"};case"SKIP":return{label:"跳过",className:"bg-muted text-muted-foreground"}}}function jt({type:e}){const t=e==="LOGIN_DETECTED"||e==="INSTALLATION_FOUND";return n.jsx("span",{className:S("inline-block h-2 w-2 rounded-full shrink-0",t?"bg-success":"bg-border"),title:t?"Available":"Unavailable",children:n.jsx("span",{className:"sr-only",children:t?"Available":"Unavailable"})})}function wt({type:e}){const{t}=_();return e==="LOGIN_DETECTED"||e==="INSTALLATION_FOUND"?n.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-success/10 px-2 py-0.5 text-[11px] font-medium text-success",children:[n.jsx(ze,{size:11,"aria-hidden":"true"}),t("可用")]}):n.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-muted px-2 py-0.5 text-[11px] font-medium text-muted-foreground",children:[n.jsx(Xe,{size:11,"aria-hidden":"true"}),t("不可用")]})}function V({title:e,defaultOpen:t=!1,children:l}){const[a,s]=v.useState(t);return n.jsxs("div",{className:"rounded-lg border border-border",children:[n.jsxs("button",{type:"button",onClick:()=>s(i=>!i),"aria-expanded":a,className:"w-full flex items-center justify-between rounded-lg px-4 py-2.5 text-sm font-medium text-foreground transition-colors hover:bg-muted/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60 focus-visible:ring-inset",children:[e,n.jsx(oe,{size:14,"aria-hidden":"true",className:S("text-muted-foreground transition-transform motion-reduce:transition-none",a&&"rotate-180")})]}),a&&n.jsx("div",{className:"px-4 pb-4 space-y-3",children:l})]})}function Nt({agentType:e,config:t,onChange:l}){const{t:a}=_(),s=J[e]??[];if(s.length===0)return n.jsx("p",{className:"text-xs text-muted-foreground",children:a("该类型暂无运行配置")});const i=(r,o)=>{l({...t,[r]:o})};return n.jsx("div",{className:"space-y-3",children:s.map(r=>r.type==="textarea"?n.jsxs("div",{children:[n.jsx("label",{className:"mb-1 block text-sm text-foreground",children:a(r.label)}),n.jsx(ae,{value:t[r.key]??"",onChange:o=>i(r.key,o.target.value||void 0),placeholder:r.placeholder?a(r.placeholder):void 0,rows:r.rows??3,className:"py-1.5"})]},r.key):r.type==="cursor_model"?n.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-start",children:[n.jsx("label",{className:"w-32 shrink-0 text-sm text-foreground sm:pt-2",children:a(r.label)}),n.jsx(ut,{value:t[r.key]??"",onChange:o=>i(r.key,o)})]},r.key):n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("label",{className:"w-32 shrink-0 text-sm text-foreground",children:a(r.label)}),r.type==="switch"&&n.jsx(Be,{checked:!!t[r.key],onCheckedChange:o=>i(r.key,o),"aria-label":a(r.label)}),r.type==="input"&&n.jsx(M,{value:t[r.key]??"",onChange:o=>i(r.key,o.target.value||void 0),placeholder:r.placeholder?a(r.placeholder):void 0,className:"flex-1 py-1.5"}),r.type==="select"&&r.options&&n.jsx(le,{value:t[r.key]??"",onChange:o=>i(r.key,o||void 0),options:r.options,placeholder:a("选择...")})]},r.key))})}function Ct({isOpen:e,onClose:t,initialData:l,onSave:a}){const{t:s}=_(),[i,r]=v.useState(l??{name:"",agentType:w.CLAUDE_CODE,config:ie(),settings:"",env:[],isDefault:!1}),[o,d]=v.useState("");v.useEffect(()=>{if(!l&&!i.settings){const m=X(i.agentType);m&&r(x=>({...x,settings:m}))}},[]);const c=m=>{r(x=>({...x,agentType:m,config:ie(),settings:X(m)}))},f=()=>{d("");const m=W(i.agentType,i.config),x={};for(const[O,k]of Object.entries(m))k!==void 0&&k!==""&&(x[O]=k);const y=i.settings.trim();if(y){if(i.agentType===w.CODEX)try{ct(y)}catch(O){d(s("TOML 语法错误: {message}",{message:O instanceof Error?O.message:String(O)}));return}else if(i.agentType===w.CLAUDE_CODE)try{JSON.parse(y)}catch{d(s("JSON 语法错误"));return}}const b={};for(const{key:O,value:k}of i.env){const D=O.trim();D&&(b[D]=k)}const E=!!l,B={name:i.name,agentType:i.agentType,config:x,settings:E?y||"":y||void 0,env:E||Object.keys(b).length>0?b:void 0,isDefault:i.isDefault};a(B)};if(!e)return null;const j=ft(i.agentType),h=i.agentType===w.CODEX;return n.jsx(q,{isOpen:e,onClose:t,title:s(l?"编辑 Provider":"新建 Provider"),className:"max-w-2xl",children:n.jsxs("div",{className:"space-y-4",children:[n.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2",children:[n.jsxs("div",{children:[n.jsx("label",{htmlFor:"provider-name",className:"mb-1 block text-xs font-medium text-foreground",children:s("名称")}),n.jsx(M,{id:"provider-name",value:i.name,onChange:m=>r(x=>({...x,name:m.target.value})),placeholder:s("例如: Claude Code (官方)")})]}),!l&&n.jsxs("div",{children:[n.jsx("label",{className:"mb-1 block text-xs font-medium text-foreground",children:s("Agent 类型")}),n.jsx(le,{value:i.agentType,onChange:m=>c(m),options:Object.values(w).map(m=>({value:m,label:z[m]??m})),placeholder:s("选择 Agent 类型")})]})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("input",{type:"checkbox",id:"isDefault",checked:i.isDefault,onChange:m=>r(x=>({...x,isDefault:m.target.checked})),className:"h-4 w-4 rounded border-border accent-primary"}),n.jsx("label",{htmlFor:"isDefault",className:"text-sm text-foreground",children:s("设为该类型的默认 Provider")})]}),n.jsx(V,{title:s("运行配置"),defaultOpen:!0,children:n.jsx(Nt,{agentType:i.agentType,config:i.config,onChange:m=>r(x=>({...x,config:m}))})}),n.jsxs(V,{title:s("环境变量"),defaultOpen:i.env.length>0,children:[n.jsxs("p",{className:"text-xs text-muted-foreground mb-2",children:[s("注入到 Agent 进程的环境变量。Codex 的")," ",n.jsx("code",{className:"rounded bg-muted px-1",children:"env_key"})," ",s("指定的是变量名,实际值需在此处设置。")]}),n.jsxs("div",{className:"space-y-2",children:[i.env.map((m,x)=>n.jsxs("div",{className:"flex gap-2 items-center",children:[n.jsx(M,{value:m.key,onChange:y=>{const b=[...i.env];b[x]={...b[x],key:y.target.value},r(E=>({...E,env:b}))},placeholder:s("变量名,如 AZURE_OPENAI_API_KEY"),className:"flex-1 py-1.5 font-mono"}),n.jsx(M,{value:m.value,onChange:y=>{const b=[...i.env];b[x]={...b[x],value:y.target.value},r(E=>({...E,env:b}))},placeholder:s("值"),className:"flex-1 py-1.5 font-mono"}),n.jsx("button",{type:"button",onClick:()=>{const y=i.env.filter((b,E)=>E!==x);r(b=>({...b,env:y}))},"aria-label":s("删除"),className:"rounded-md p-1.5 text-muted-foreground transition-colors hover:text-destructive focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60",children:n.jsx(ce,{size:14})})]},x)),n.jsxs(N,{variant:"outline",size:"sm",onClick:()=>r(m=>({...m,env:[...m.env,{key:"",value:""}]})),children:[n.jsx(Z,{size:12,className:"mr-1"}),s("添加变量")]})]})]}),j&&n.jsxs(V,{title:s(h?"CLI 原生配置 (config.toml)":"CLI 原生配置 (settings.json)"),children:[n.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:h?n.jsxs(n.Fragment,{children:[s("直接填写 Codex")," ",n.jsx("code",{className:"rounded bg-muted px-1",children:"config.toml"})," ",s("格式的配置片段,通过")," ",n.jsx("code",{className:"rounded bg-muted px-1",children:"-c"})," ",s("参数注入。不会修改你的")," ",n.jsx("code",{className:"rounded bg-muted px-1",children:"~/.codex/config.toml"})," ",s("文件。")]}):n.jsxs(n.Fragment,{children:[s("对应 Claude Code 的")," ",n.jsx("code",{className:"rounded bg-muted px-1",children:"~/.claude/settings.json"}),",",s("通过")," ",n.jsx("code",{className:"rounded bg-muted px-1",children:"--settings"})," ",s("参数注入。在")," ",n.jsx("code",{className:"rounded bg-muted px-1",children:"env"})," ",s("中设置 ANTHROPIC_API_KEY、ANTHROPIC_BASE_URL 等。")]})}),n.jsx(ae,{value:i.settings,onChange:m=>{r(x=>({...x,settings:m.target.value})),d("")},rows:10,className:"font-mono",placeholder:X(i.agentType),"aria-invalid":!!o}),o&&n.jsx("p",{role:"alert",className:"mt-1 text-xs text-destructive",children:o})]}),n.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[n.jsx(N,{variant:"outline",onClick:t,children:s("取消")}),n.jsx(N,{onClick:f,disabled:!i.name.trim(),children:s("保存")})]})]})})}function Et({isOpen:e,onClose:t,onConfirm:l,acknowledged:a,onAcknowledgedChange:s,isLoading:i}){const{t:r}=_();return n.jsx(q,{isOpen:e,onClose:t,title:r("导出 Provider 备份"),className:"max-w-xl",action:n.jsxs(n.Fragment,{children:[n.jsx(N,{variant:"outline",onClick:t,disabled:i,children:r("取消")}),n.jsx(N,{onClick:l,disabled:!a||i,children:r(i?"导出中...":"导出备份")})]}),children:n.jsxs("div",{className:"space-y-4",children:[n.jsxs("div",{className:"flex items-start gap-2.5 rounded-lg border border-warning/30 bg-warning/10 px-4 py-3 text-sm text-foreground",children:[n.jsx(Ue,{size:15,className:"mt-0.5 shrink-0 text-warning","aria-hidden":"true"}),n.jsx("span",{children:r("导出的备份文件将包含完整的 Provider 配置,包括环境变量、CLI settings 等敏感信息。任何拿到文件的人都可能直接使用这些 Provider。")})]}),n.jsxs("div",{className:"space-y-2 text-sm text-muted-foreground",children:[n.jsx("p",{children:r("这个功能用于备份和迁移,不用于分享配置。")}),n.jsx("p",{children:r("导出内容只包含用户层配置:自定义 Provider,以及对内置 Provider 的覆盖。")})]}),n.jsxs("label",{className:"flex items-start gap-3 rounded-lg border border-border px-4 py-3 text-sm text-foreground",children:[n.jsx("input",{type:"checkbox",checked:a,onChange:o=>s(o.target.checked),className:"mt-0.5 h-4 w-4 rounded border-border accent-primary"}),n.jsx("span",{children:r("我已知晓该备份文件包含敏感信息,只会保存在安全位置。")})]})]})})}function kt({isOpen:e,onClose:t,preview:l,backup:a,onConfirm:s,isLoading:i}){const{t:r}=_();if(!l||!a)return null;const o=l.summary.create+l.summary.overwrite,d=[...l.items].sort((c,f)=>{const j={CREATE:0,OVERWRITE:1,SKIP:2};return j[c.action]-j[f.action]});return n.jsx(q,{isOpen:e,onClose:t,title:r("导入 Provider 备份"),className:"max-w-3xl",action:n.jsxs(n.Fragment,{children:[n.jsx(N,{variant:"outline",onClick:t,disabled:i,children:r("取消")}),n.jsx(N,{onClick:s,disabled:o===0||i,children:i?r("导入中..."):r("确认导入 {count} 项",{count:o})})]}),children:n.jsxs("div",{className:"space-y-4",children:[n.jsxs("div",{className:"rounded-lg border border-border bg-muted/40 px-4 py-3 text-sm text-muted-foreground",children:[n.jsx("div",{children:r("导出时间:{value}",{value:new Date(a.exportedAt).toLocaleString()})}),n.jsx("div",{children:r("模式:完整备份(含敏感信息)")}),n.jsx("div",{children:r("文件内 Provider 数量:{count}",{count:a.providers.length})})]}),n.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[n.jsxs("div",{className:"rounded-lg border border-success/25 bg-success/10 px-4 py-3",children:[n.jsx("div",{className:"text-xs font-medium text-success",children:r("新增")}),n.jsx("div",{className:"text-lg font-semibold text-foreground",children:l.summary.create})]}),n.jsxs("div",{className:"rounded-lg border border-warning/25 bg-warning/10 px-4 py-3",children:[n.jsx("div",{className:"text-xs font-medium text-warning",children:r("覆盖")}),n.jsx("div",{className:"text-lg font-semibold text-foreground",children:l.summary.overwrite})]}),n.jsxs("div",{className:"rounded-lg border border-border bg-muted/40 px-4 py-3",children:[n.jsx("div",{className:"text-xs font-medium text-muted-foreground",children:r("跳过")}),n.jsx("div",{className:"text-lg font-semibold text-foreground",children:l.summary.skip})]})]}),n.jsx("div",{className:"max-h-[420px] overflow-y-auto space-y-3 pr-1",children:d.map(c=>{const f=yt(c.action);return n.jsxs("div",{className:"rounded-lg border border-border px-4 py-3",children:[n.jsx("div",{className:"flex items-center justify-between gap-3",children:n.jsxs("div",{className:"min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("h4",{className:"truncate text-sm font-medium text-foreground",children:c.incoming.name}),n.jsx("span",{className:`inline-flex rounded-full px-2 py-0.5 text-[11px] font-medium ${f.className}`,children:r(f.label)})]}),n.jsxs("div",{className:"mt-1 text-xs text-muted-foreground",children:[z[c.incoming.agentType]??c.incoming.agentType," · ",n.jsx("code",{className:"rounded bg-muted px-1 py-0.5",children:c.incoming.id})]})]})}),c.action==="OVERWRITE"&&c.existing&&n.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:r("将覆盖当前已有的 Provider:{name}",{name:c.existing.name})}),c.action==="SKIP"&&n.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:r("当前同 ID Provider 配置一致,本次不会重复写入。")}),c.action==="CREATE"&&n.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:r("当前不存在同 ID Provider,将直接新增。")})]},c.incoming.id)})})]})})}function Pt({item:e,onEdit:t,onDelete:l}){const{t:a}=_(),s=e.provider,i=e.availability,r=W(s.agentType,s.config),o=Object.entries(r).filter(([c])=>c!=="cmd"),d=Object.keys(s.env||{});return n.jsxs("div",{className:"space-y-6",children:[n.jsxs("div",{className:"flex items-start justify-between gap-4",children:[n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center gap-2.5",children:[n.jsx("h3",{className:"text-base font-semibold text-foreground",children:s.name}),n.jsx(wt,{type:i.type})]}),n.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2 text-xs text-muted-foreground",children:[n.jsx("span",{children:z[s.agentType]??s.agentType}),s.isDefault&&n.jsx("span",{className:"rounded-full bg-primary/[0.06] px-2 py-0.5 text-[11px] font-medium text-primary",children:a("默认")}),s.builtIn&&n.jsx("span",{className:"rounded-full bg-muted px-2 py-0.5 text-[11px] font-medium text-muted-foreground",children:a("内置")})]})]}),n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsxs(N,{size:"sm",variant:"outline",onClick:t,children:[n.jsx(Ve,{size:13}),a("编辑")]}),n.jsxs(N,{size:"sm",variant:s.builtIn?"outline":"destructive",onClick:l,disabled:s.deletable===!1,children:[s.builtIn?n.jsx(Ze,{size:13}):n.jsx(ce,{size:13}),s.builtIn?a("恢复默认"):a("删除")]})]})]}),o.length>0&&n.jsxs("div",{children:[n.jsx(K,{className:"mb-3",children:a("运行配置")}),n.jsx("div",{className:"grid gap-px overflow-hidden rounded-lg border border-border bg-border/60",children:o.map(([c,f])=>n.jsxs("div",{className:"flex items-center gap-4 bg-background px-4 py-2.5",children:[n.jsx("span",{className:"w-32 shrink-0 text-[13px] text-muted-foreground",children:a(pt[c]??c)}),n.jsx("span",{className:"font-mono text-[13px] text-foreground",children:gt(c,f)})]},c))})]}),d.length>0&&n.jsxs("div",{children:[n.jsx(K,{className:"mb-3",children:a("环境变量")}),n.jsx("div",{className:"grid gap-px overflow-hidden rounded-lg border border-border bg-border/60",children:d.map(c=>n.jsxs("div",{className:"flex items-center gap-4 bg-background px-4 py-2.5",children:[n.jsx("span",{className:"font-mono text-[13px] text-foreground",children:c}),n.jsx("span",{className:"text-[13px] text-muted-foreground","aria-label":"hidden",children:"•••••"})]},c))})]}),s.settings?.trim()&&n.jsxs("div",{children:[n.jsx(K,{className:"mb-3",children:a("CLI 配置")}),n.jsx("div",{className:"rounded-lg border border-border bg-muted/40 p-4",children:n.jsx("pre",{className:"max-h-[200px] overflow-y-auto whitespace-pre-wrap break-all font-mono text-xs text-muted-foreground",children:s.settings})})]}),o.length===0&&d.length===0&&!s.settings?.trim()&&n.jsx("div",{className:"py-8 text-center text-sm text-muted-foreground",children:a('该 Provider 未配置额外参数。点击"编辑"添加运行配置、环境变量或 CLI 配置。')})]})}function Vt(){const{t:e}=_(),{data:t,isLoading:l}=Se(),a=Te(),s=Ae(),i=De(),r=Le(),o=Re(),d=Fe(),c=v.useRef(null),[f,j]=v.useState(null),[h,m]=v.useState(null),[x,y]=v.useState(null),[b,E]=v.useState(!1),[B,O]=v.useState(!1),[k,D]=v.useState(null),[me,G]=v.useState(!1),L=t??[];v.useEffect(()=>{!f&&L.length>0&&j(L[0].provider.id)},[L,f]);const xe=u=>{a.mutate(u,{onSuccess:()=>m(null),onError:g=>P.error(T(g,e("创建 Provider 失败")))})},fe=(u,g)=>{s.mutate({id:u,data:g},{onSuccess:()=>m(null),onError:C=>P.error(T(C,e("更新 Provider 失败")))})},pe=u=>{if(!(u.deletable??!u.builtIn)){P.error(e("系统内置 Provider 不可删除"));return}y({id:u.id,name:u.name,builtIn:u.builtIn})},he=()=>{x&&i.mutate(x.id,{onSuccess:()=>{P.success(x.builtIn?e("已恢复默认 Provider 配置"):e("Provider 已删除")),f===x.id&&j(null),y(null),G(!1)},onError:u=>P.error(T(u,e("删除 Provider 失败")))})},Q=()=>{E(!1),O(!1)},ee=()=>D(null),ge=()=>{r.mutate(void 0,{onSuccess:u=>{vt(bt(u.exportedAt),u),P.success(e("Provider 备份已导出")),Q()},onError:u=>P.error(T(u,e("导出 Provider 备份失败")))})},be=()=>{c.current&&(c.current.value="",c.current.click())},ve=async u=>{const g=u.target.files?.[0];if(u.target.value="",!g)return;let C;try{C=JSON.parse(await g.text())}catch{P.error(e("备份文件不是有效的 JSON"));return}o.mutate(C,{onSuccess:R=>D({backup:C,preview:R}),onError:R=>P.error(T(R,e("导入预览失败")))})},ye=()=>{k&&d.mutate(k.backup,{onSuccess:u=>{const g=u.summary.create+u.summary.overwrite;P.success(g===0?e("导入完成,当前配置无需变更"):e("导入完成:新增 {create},覆盖 {overwrite},跳过 {skip}",{create:u.summary.create,overwrite:u.summary.overwrite,skip:u.summary.skip})),ee()},onError:u=>P.error(T(u,e("导入 Provider 备份失败")))})},je=u=>{const g=u.provider,C=g.env?Object.entries(g.env).map(([R,we])=>({key:R,value:we})):[];m({id:g.id,data:{name:g.name,agentType:g.agentType,config:W(g.agentType,g.config),settings:g.settings??"",env:C,isDefault:g.isDefault}})};return l?n.jsx(te,{className:"max-w-5xl",children:n.jsx(Pe,{})}):n.jsxs(te,{className:"max-w-5xl",children:[n.jsx("input",{ref:c,type:"file",accept:".json,application/json",className:"hidden",onChange:ve}),n.jsx(Oe,{title:e("Agent 配置"),actions:n.jsxs(n.Fragment,{children:[n.jsxs(N,{variant:"outline",size:"sm",onClick:be,disabled:o.isPending||d.isPending,children:[n.jsx(Ke,{size:13}),e("导入")]}),n.jsxs(N,{variant:"outline",size:"sm",onClick:()=>E(!0),disabled:r.isPending,children:[n.jsx(Ye,{size:13}),e("导出")]}),n.jsxs(N,{size:"sm",onClick:()=>m({}),children:[n.jsx(Z,{size:13,className:"mr-1"}),e("新建")]})]})}),L.length===0?n.jsx(Ie,{icon:_e,message:e("暂无 Agent 配置"),action:n.jsxs(N,{size:"sm",onClick:()=>m({}),children:[n.jsx(Z,{size:13,className:"mr-1"}),e("新建配置")]})}):n.jsx(Ge,{items:L,selectedId:f,onSelectItem:u=>{j(u),G(!0)},getItemId:u=>u.provider.id,mobileShowDetail:me,onMobileBack:()=>G(!1),renderListItem:(u,g)=>{const C=u.provider;return n.jsxs(n.Fragment,{children:[n.jsx(jt,{type:u.availability.type}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsx("div",{className:"truncate text-[13px] font-medium",children:C.name}),n.jsx("div",{className:S("truncate text-[11px]",g?"text-primary-foreground/60":"text-muted-foreground"),children:z[C.agentType]??C.agentType})]}),C.isDefault&&n.jsx("span",{className:S("shrink-0 rounded px-1.5 py-0.5 text-[10px] font-medium",g?"bg-white/20 text-primary-foreground":"bg-primary/[0.06] text-primary"),children:e("默认")})]})},renderDetail:u=>u?n.jsx("div",{className:"p-5",children:n.jsx(Pt,{item:u,onEdit:()=>je(u),onDelete:()=>pe(u.provider)})}):n.jsx("div",{className:"py-16 text-center text-sm text-muted-foreground",children:e("选择一个 Provider 查看详情")})}),h&&n.jsx(Ct,{isOpen:!0,onClose:()=>m(null),initialData:h.data,onSave:u=>{h.id?fe(h.id,u):xe(u)}}),n.jsx(Me,{isOpen:x!==null,onClose:()=>{i.isPending||y(null)},onConfirm:he,title:x?.builtIn?e("恢复默认 Provider"):e("删除 Provider"),description:x?.builtIn?e('确定删除 "{name}" 的自定义覆盖,并恢复系统默认配置?',{name:x?.name}):e('确定删除 "{name}"?此操作不可撤销。',{name:x?.name}),confirmText:x?.builtIn?e("恢复默认"):e("删除"),cancelText:e("取消"),variant:"danger",isLoading:i.isPending}),n.jsx(Et,{isOpen:b,onClose:Q,onConfirm:ge,acknowledged:B,onAcknowledgedChange:O,isLoading:r.isPending}),n.jsx(kt,{isOpen:!!k,onClose:ee,preview:k?.preview??null,backup:k?.backup??null,onConfirm:ye,isLoading:d.isPending})]})}export{Vt as ProviderSettingsPage};
|
package/dist/web/assets/{SettingsMasterDetail-Cx9Ylq9N.js → SettingsMasterDetail-CdimTj5n.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{u as v,j as r,g as o}from"./index-
|
|
1
|
+
import{u as v,j as r,g as o}from"./index-DbO4YyUv.js";import{A as h}from"./arrow-left-B6KMicbE.js";function N({items:n,selectedId:t,onSelectItem:c,getItemId:l,renderListItem:d,renderDetail:u,renderListFooter:g,mobileShowDetail:a,onMobileBack:x,listClassName:f,detailClassName:p}){const{t:m}=v(),b=n.find(e=>l(e)===t)??null;return r.jsxs("div",{className:"grid gap-5 lg:grid-cols-[240px_minmax(0,1fr)] lg:h-[calc(100vh-16rem)] lg:max-h-[640px]",children:[r.jsxs("div",{className:o("space-y-1 lg:overflow-y-auto lg:pr-1 scrollbar-app-thin",a&&"hidden lg:block",f),children:[n.map(e=>{const s=l(e),i=s===t;return r.jsx("button",{onClick:()=>c(s),"aria-current":i?"true":void 0,className:o("flex w-full items-center gap-3 rounded-lg px-3 py-2.5 text-left transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60",i?"bg-primary text-primary-foreground":"text-foreground hover:bg-muted/50"),children:d(e,i)},s)}),g?.()]}),r.jsxs("div",{className:o("rounded-xl border border-border bg-card lg:overflow-y-auto scrollbar-app-thin",!a&&"hidden lg:block",p),children:[r.jsxs("button",{onClick:x,className:"mb-4 flex items-center gap-1.5 px-5 pt-3 text-xs text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60 lg:hidden",children:[r.jsx(h,{size:14}),m("返回列表")]}),u(b)]})]})}export{N as S};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{u as Oe,s as gt,v as bt,w as ft,x as ht,y as vt,z as jt,A as yt,C as Pt,r as l,j as e,S as Ee,D as Nt,d as kt,g as B,B as p,n as Ae,t as c}from"./index-DbO4YyUv.js";import{C as Me}from"./confirm-dialog-BAnxa2C9.js";import{M as Tt}from"./modal-CAB_bs-c.js";import{S as O}from"./select-BJfNuuIV.js";import{M as U}from"./MemberAvatar-u6jTOiDY.js";import{u as wt}from"./use-providers-BOyY0DcV.js";import{A as _e}from"./arrow-left-B6KMicbE.js";import{T as ue,P as R}from"./trash-2-8Pu6lwnW.js";import{C as Ct}from"./chevron-up-DcLdFanO.js";import{C as It}from"./chevron-down-Cur5jANy.js";import"./check-D9lM__p8.js";const o="/avatars/presets",St=[{id:"developer",label:"Developer",src:`${o}/avatar-preset-01-developer.png`},{id:"architect",label:"Architect",src:`${o}/avatar-preset-02-architect.png`},{id:"tester",label:"Tester",src:`${o}/avatar-preset-03-tester.png`},{id:"devops",label:"DevOps",src:`${o}/avatar-preset-04-devops.png`},{id:"data-scientist",label:"Data scientist",src:`${o}/avatar-preset-05-data-scientist.png`},{id:"frontend",label:"Frontend",src:`${o}/avatar-preset-06-frontend.png`},{id:"backend",label:"Backend",src:`${o}/avatar-preset-07-backend.png`},{id:"security",label:"Security",src:`${o}/avatar-preset-08-security.png`},{id:"project-manager",label:"Project manager",src:`${o}/avatar-preset-09-project-manager.png`},{id:"product-manager",label:"Product manager",src:`${o}/avatar-preset-10-product-manager.png`},{id:"scrum-master",label:"Scrum master",src:`${o}/avatar-preset-11-scrum-master.png`},{id:"tech-lead",label:"Tech lead",src:`${o}/avatar-preset-12-tech-lead.png`},{id:"coordinator",label:"Coordinator",src:`${o}/avatar-preset-13-coordinator.png`},{id:"mentor",label:"Mentor",src:`${o}/avatar-preset-14-mentor.png`},{id:"reviewer",label:"Reviewer",src:`${o}/avatar-preset-15-reviewer.png`},{id:"ui-designer",label:"UI designer",src:`${o}/avatar-preset-16-ui-designer.png`},{id:"ux-researcher",label:"UX researcher",src:`${o}/avatar-preset-17-ux-researcher.png`},{id:"documenter",label:"Documenter",src:`${o}/avatar-preset-18-documenter.png`},{id:"translator",label:"Translator",src:`${o}/avatar-preset-19-translator.png`},{id:"analyst",label:"Analyst",src:`${o}/avatar-preset-20-analyst.png`},{id:"consultant",label:"Consultant",src:`${o}/avatar-preset-21-consultant.png`},{id:"creative-director",label:"Creative director",src:`${o}/avatar-preset-22-creative-director.png`},{id:"support",label:"Support",src:`${o}/avatar-preset-23-support.png`},{id:"assistant",label:"Assistant",src:`${o}/avatar-preset-24-assistant.png`},{id:"robot",label:"Robot",src:`${o}/avatar-preset-25-robot.png`}],Re="/api",Et=2*1024*1024,At=[],Mt=[],_t=[],De=[{key:"readRoom",label:"读房间"},{key:"postRoomMessage",label:"发房间消息"},{key:"mentionMembers",label:"提及成员"},{key:"stopMemberWork",label:"停止成员工作"},{key:"markReadyForReview",label:"标记可审查"},{key:"readFiles",label:"读文件"},{key:"writeFiles",label:"写文件"},{key:"runCommands",label:"运行命令"},{key:"readDiff",label:"读 diff"},{key:"mergeWorkspace",label:"合并工作区"}],ze={readRoom:!1,postRoomMessage:!1,mentionMembers:!1,stopMemberWork:!1,markReadyForReview:!1,readFiles:!1,writeFiles:!1,runCommands:!1,readDiff:!1,mergeWorkspace:!1},Fe=[{value:"none",label:"无"},{value:"shared",label:"共享"},{value:"dedicated",label:"独占"}],Ft=[{value:"MENTION_ONLY",label:"仅提及"},{value:"USER_MESSAGES",label:"所有用户消息"}],$t=[{value:"new_per_request",label:"每次新会话"},{value:"resume_last",label:"复用上次会话"}],Ot=[{value:"own_only",label:"仅自己队列"},{value:"team_pending",label:"全队列待处理"}];function Y(){return{name:"",aliasesText:"",providerId:"",rolePrompt:"",capabilities:{...ze},workspacePolicy:"none",triggerPolicy:"MENTION_ONLY",sessionPolicy:"new_per_request",queueManagementPolicy:"own_only",avatar:""}}function xe(r){return{name:r.name,aliasesText:r.aliases.join(", "),providerId:r.providerId,rolePrompt:r.rolePrompt,capabilities:{...ze,...r.capabilities},workspacePolicy:r.workspacePolicy,triggerPolicy:r.triggerPolicy,sessionPolicy:r.sessionPolicy,queueManagementPolicy:r.queueManagementPolicy,avatar:r.avatar??""}}function q(){return{name:"",memberPresetIds:[]}}function pe(r){return{name:r.name,memberPresetIds:r.members?.map(i=>i.memberPresetId)??[]}}function Rt(r,i,d,m){if(d.filter(M=>M===m).length<=1)return r;const W=d.slice(0,i+1).filter(M=>M===m).length;return`${r} #${W}`}function Dt(r){return Array.from(new Set(r.split(/[\n,]/).map(i=>i.trim()).filter(Boolean)))}function zt(r){return r.trim()||null}function $e(r){return De.reduce((i,d)=>i+(r[d.key]?1:0),0)}function A(r,i){return r instanceof Error?r.message:i}function Lt(r){return["image/png","image/jpeg","image/webp"].includes(r.type)}async function Bt(r){const i=new FormData;i.append("file",r);const d=await fetch(`${Re}/attachments/upload`,{method:"POST",body:i});if(!d.ok){const m=await d.json().catch(()=>({}));throw new Error(m.error||m.message||`Upload failed (${d.status})`)}return d.json()}function G({title:r,error:i,isFetching:d,onRetry:m}){const{t:T}=Oe();return e.jsx("div",{role:"alert",className:"rounded-lg border border-destructive/30 bg-destructive/10 px-4 py-3 text-sm text-destructive",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium",children:r}),e.jsx("div",{className:"mt-1 text-xs text-destructive/90",children:A(i,T("请稍后重试。"))})]}),e.jsx(p,{type:"button",size:"sm",variant:"outline",onClick:m,disabled:d,children:T(d?"加载中...":"重试")})]})})}function Zt(){const{t:r}=Oe(),{data:i,error:d,isError:m,isFetching:T,isLoading:W,refetch:M}=wt(),{data:Le,error:ge,isError:w,isFetching:be,isLoading:V,refetch:fe}=gt(),{data:Be,error:Ue,isError:D,isFetching:Ye,isLoading:H,refetch:qe}=bt(),Q=ft(),X=ht(),he=vt(),J=jt(),K=yt(),ve=Pt(),[Z,je]=l.useState("presets"),[C,ee]=l.useState("edit"),[f,te]=l.useState(null),[a,v]=l.useState(Y()),[ye,_]=l.useState(!1),[j,re]=l.useState(null),[Ge,se]=l.useState(!1),[Pe,Ne]=l.useState(!1),ke=l.useRef(null),[I,ae]=l.useState("edit"),[h,ne]=l.useState(null),[y,g]=l.useState(q()),[Te,P]=l.useState(!1),[N,oe]=l.useState(null),[we,F]=l.useState(!1),u=Le??At,b=Be??Mt,z=i??_t,$=l.useMemo(()=>new Map(u.map(t=>[t.id,t])),[u]),le=l.useMemo(()=>new Map(b.map(t=>[t.id,t])),[b]),We=l.useMemo(()=>{const t=z.map(({provider:s,availability:n})=>({value:s.id,label:s.name+(n.type==="NOT_FOUND"?r(" (不可用)"):""),disabled:n.type==="NOT_FOUND"}));return a.providerId&&!t.some(s=>s.value===a.providerId)&&t.unshift({value:a.providerId,label:`${a.providerId}${r(" (不可用)")}`,disabled:!0}),t},[a.providerId,z,r]),ie=f?$.get(f)??null:null,de=h?le.get(h)??null:null,Ve=l.useMemo(()=>new Map(z.map(({provider:t,availability:s})=>[t.id,t.name+(s.type==="NOT_FOUND"?r(" (不可用)"):"")])),[z,r]);if(l.useEffect(()=>{if(!(V||w||ye)){if(C==="create"){v(Y());return}if(f){const t=$.get(f);t&&v(xe(t));return}if(u.length>0){const t=u[0];te(t.id),ee("edit"),v(xe(t));return}ee("create"),te(null),v(Y())}},[$,ye,C,u,w,V,f]),l.useEffect(()=>{if(!(H||D||Te)){if(I==="create"){g(q());return}if(h){const t=le.get(h);t&&g(pe(t));return}if(b.length>0){const t=b[0];ne(t.id),ae("edit"),g(pe(t));return}ae("create"),ne(null),g(q())}},[h,le,Te,I,b,D,H]),W||V||H)return e.jsx(Ee,{className:"max-w-6xl",children:e.jsx(Nt,{cards:6})});const x=(t,s)=>{v(n=>({...n,[t]:s})),_(!0)},He=(t,s)=>{v(n=>({...n,capabilities:{...n.capabilities,[t]:s}})),_(!0)},Qe=t=>{x("avatar",t),se(!1)},Xe=()=>{x("avatar","")},Je=async t=>{const s=t.target.files?.[0];if(t.target.value="",!!s){if(!Lt(s)){c.error(r("仅支持 PNG、JPG、WebP 头像。"));return}if(s.size>Et){c.error(r("头像图片不能超过 2MB。"));return}Ne(!0);try{const n=await Bt(s);x("avatar",`${Re}${n.url}`),c.success(r("头像已上传"))}catch(n){c.error(A(n,r("头像上传失败")))}finally{Ne(!1)}}},S=(t,s)=>{ee(t),te(s?.id??null),v(s?xe(s):Y()),_(!1)},Ke=(t,s)=>{g(n=>({...n,[t]:s})),P(!0)},E=(t,s)=>{ae(t),ne(s?.id??null),g(s?pe(s):q()),P(!1)},Ze=async()=>{const t={name:a.name.trim(),aliases:Dt(a.aliasesText),providerId:a.providerId.trim(),rolePrompt:a.rolePrompt.trim(),capabilities:{...a.capabilities},workspacePolicy:a.workspacePolicy,triggerPolicy:a.triggerPolicy,sessionPolicy:a.sessionPolicy,queueManagementPolicy:a.queueManagementPolicy,avatar:zt(a.avatar)};try{if(C==="create"||!f){const s=await Q.mutateAsync(t);S("edit",s),c.success(r("已创建"))}else{const s=await X.mutateAsync({id:f,data:t});S("edit",s),c.success(r("已保存"))}}catch(s){c.error(A(s,r("保存失败")))}},et=async()=>{if(j)try{await he.mutateAsync(j.id),c.success(r("Deleted"));const t=u.filter(s=>s.id!==j.id);f===j.id&&(t.length>0?S("edit",t[0]):S("create",null)),re(null)}catch(t){c.error(A(t,r("删除失败")))}},tt=async()=>{const t={name:y.name.trim(),memberPresetIds:y.memberPresetIds};try{if(I==="create"||!h){const s=await J.mutateAsync(t);E("edit",s),c.success(r("已创建"))}else{const s=await K.mutateAsync({id:h,data:t});E("edit",s),c.success(r("已保存"))}}catch(s){c.error(A(s,r("保存失败")))}},rt=async()=>{if(N)try{await ve.mutateAsync(N.id),c.success(r("Deleted"));const t=b.filter(s=>s.id!==N.id);h===N.id&&(t.length>0?E("edit",t[0]):E("create",null)),oe(null)}catch(t){c.error(A(t,r("删除失败")))}},st=$e(a.capabilities),at=!!a.name.trim()&&!!a.providerId.trim()&&!!a.rolePrompt.trim()&&!m&&!w&&!Q.isPending&&!X.isPending,nt=!!y.name.trim()&&!D&&!w&&!J.isPending&&!K.isPending,ce=y.memberPresetIds.map(t=>$.get(t)).filter(t=>!!t),ot=t=>{_(!1),S("edit",t)},lt=()=>{_(!1),S("create",null)},it=t=>{P(!1),E("edit",t)},dt=()=>{P(!1),E("create",null)},ct=t=>{g(s=>({...s,memberPresetIds:[...s.memberPresetIds,t]})),P(!0)},mt=t=>{g(s=>({...s,memberPresetIds:s.memberPresetIds.filter((n,k)=>k!==t)})),P(!0)},Ce=(t,s)=>{g(n=>{const k=t+s;if(k<0||k>=n.memberPresetIds.length)return n;const me=[...n.memberPresetIds],[pt]=me.splice(t,1);return me.splice(k,0,pt),{...n,memberPresetIds:me}}),P(!0)},ut=t=>{ot(t),F(!0)},Ie=()=>{lt(),F(!0)},xt=t=>{it(t),F(!0)},Se=()=>{dt(),F(!0)},L=()=>F(!1);return e.jsxs(Ee,{className:"max-w-6xl",children:[e.jsx(kt,{title:r("团队协作设置"),actions:e.jsxs("div",{className:"inline-flex rounded-lg border border-border bg-muted/80 p-0.5",children:[e.jsx("button",{type:"button",onClick:()=>{je("presets"),L()},className:B("rounded-md px-3 py-1.5 text-[12px] font-medium transition-all",Z==="presets"?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:r("成员预设")}),e.jsx("button",{type:"button",onClick:()=>{je("templates"),L()},className:B("rounded-md px-3 py-1.5 text-[12px] font-medium transition-all",Z==="templates"?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:r("团队模板")})]})}),m&&e.jsx(G,{title:r("Provider 列表加载失败"),error:d,isFetching:T,onRetry:()=>{M()}}),Z==="presets"?we?e.jsxs("div",{className:"rounded-xl border border-border bg-white",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-border/60 px-5 py-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:L,className:"flex items-center gap-1.5 text-xs text-muted-foreground hover:text-foreground transition-colors",children:[e.jsx(_e,{size:14}),r("返回")]}),e.jsx("span",{className:"text-neutral-200",children:"|"}),e.jsx("h3",{className:"text-[13px] font-semibold text-foreground",children:C==="create"?r("创建新预设"):ie?.name??r("编辑预设")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[C==="edit"&&ie&&e.jsx("button",{onClick:()=>re(ie),className:"flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10 transition-colors",title:r("删除"),children:e.jsx(ue,{size:14})}),e.jsx(p,{size:"sm",onClick:Ze,disabled:!at,children:Q.isPending||X.isPending?r("保存中..."):r(C==="create"?"创建":"保存")})]})]}),e.jsxs("div",{className:"p-5 space-y-5",children:[e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsxs("div",{className:"shrink-0",children:[e.jsx(U,{name:a.name||r("Agent"),avatar:a.avatar,className:"h-14 w-14 text-sm"}),e.jsxs("div",{className:"flex justify-center gap-1 mt-2",children:[e.jsx("button",{type:"button",onClick:()=>se(!0),className:"text-[10px] text-muted-foreground hover:text-foreground transition-colors",children:r("选择")}),e.jsx("span",{className:"text-[10px] text-muted-foreground/60",children:"·"}),e.jsx("button",{type:"button",onClick:()=>ke.current?.click(),disabled:Pe,className:"text-[10px] text-muted-foreground hover:text-foreground transition-colors",children:r(Pe?"...":"上传")}),a.avatar.trim()&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-[10px] text-muted-foreground/60",children:"·"}),e.jsx("button",{type:"button",onClick:Xe,className:"text-[10px] text-muted-foreground hover:text-destructive transition-colors",children:r("清除")})]})]}),e.jsx("input",{ref:ke,type:"file",accept:"image/png,image/jpeg,image/webp",className:"hidden",onChange:Je})]}),e.jsxs("div",{className:"flex-1 min-w-0 grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-[12px] font-medium text-muted-foreground mb-1",children:r("名称")}),e.jsx("input",{value:a.name,onChange:t=>x("name",t.target.value),className:"w-full rounded-lg border border-border bg-background px-3 py-2 text-sm transition-colors focus:border-ring focus:outline-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[12px] font-medium text-muted-foreground mb-1",children:r("别名")}),e.jsx("input",{value:a.aliasesText,onChange:t=>x("aliasesText",t.target.value),placeholder:r("alice, a, reviewer"),className:"w-full rounded-lg border border-border bg-background px-3 py-2 text-sm transition-colors focus:border-ring focus:outline-none"})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[12px] font-medium text-muted-foreground mb-1",children:r("Provider")}),e.jsx(O,{value:a.providerId,onChange:t=>x("providerId",t),options:We,disabled:m}),m&&e.jsx("p",{className:"mt-1 text-[11px] text-destructive",children:r("Provider 列表加载失败。")})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[12px] font-medium text-muted-foreground mb-1",children:r("角色提示词")}),e.jsx("textarea",{value:a.rolePrompt,onChange:t=>x("rolePrompt",t.target.value),rows:4,className:"w-full rounded-lg border border-border bg-muted/50 px-3 py-2 text-sm font-mono transition-colors focus:border-ring focus:bg-background focus:outline-none resize-y"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-end justify-between gap-3 mb-2",children:[e.jsx("label",{className:"text-[12px] font-medium text-muted-foreground",children:r("可用能力")}),e.jsxs("span",{className:"text-[11px] text-muted-foreground",children:[st,"/10"]})]}),e.jsx("div",{className:"grid gap-1 sm:grid-cols-2 xl:grid-cols-3",children:De.map(t=>e.jsxs("label",{className:"flex items-center gap-2 rounded px-2.5 py-1.5 text-[12px] text-foreground hover:bg-muted transition-colors cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:a.capabilities[t.key],onChange:s=>He(t.key,s.target.checked),className:"h-3.5 w-3.5 rounded border-border"}),e.jsx("span",{children:r(t.label)})]},t.key))})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-[12px] font-medium text-muted-foreground mb-1",children:r("工作区")}),e.jsx(O,{value:a.workspacePolicy,onChange:t=>x("workspacePolicy",t),options:Fe.map(t=>({value:t.value,label:r(t.label)}))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[12px] font-medium text-muted-foreground mb-1",children:r("触发")}),e.jsx(O,{value:a.triggerPolicy,onChange:t=>x("triggerPolicy",t),options:Ft.map(t=>({value:t.value,label:r(t.label)}))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[12px] font-medium text-muted-foreground mb-1",children:r("会话")}),e.jsx(O,{value:a.sessionPolicy,onChange:t=>x("sessionPolicy",t),options:$t.map(t=>({value:t.value,label:r(t.label)}))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[12px] font-medium text-muted-foreground mb-1",children:r("队列")}),e.jsx(O,{value:a.queueManagementPolicy,onChange:t=>x("queueManagementPolicy",t),options:Ot.map(t=>({value:t.value,label:r(t.label)}))})]})]})]})]}):e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 mb-4",children:[e.jsx("span",{className:"text-[12px] text-muted-foreground",children:r("{count} 个成员预设",{count:u.length})}),e.jsxs(p,{size:"sm",variant:"outline",onClick:Ie,children:[e.jsx(R,{size:13})," ",r("新增预设")]})]}),w?e.jsx(G,{title:r("加载失败"),error:ge,isFetching:be,onRetry:()=>{fe()}}):u.length===0?e.jsx(Ae,{message:r("暂无成员预设"),action:e.jsxs(p,{size:"sm",onClick:Ie,children:[e.jsx(R,{size:13,className:"mr-1"})," ",r("新增预设")]})}):e.jsx("div",{className:"grid gap-3 grid-cols-1 sm:grid-cols-2 lg:grid-cols-3",children:u.map(t=>{const s=$e(t.capabilities);return e.jsxs("button",{type:"button",onClick:()=>ut(t),className:"flex items-start gap-3 rounded-xl border border-border bg-background p-4 text-left transition-all hover:border-border hover:shadow-sm",children:[e.jsx(U,{name:t.name,avatar:t.avatar,className:"h-10 w-10 text-xs shrink-0"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[13px] font-semibold text-foreground",children:t.name}),t.aliases.length>0&&e.jsx("div",{className:"truncate text-[11px] text-muted-foreground mt-0.5",children:t.aliases.join(", ")}),e.jsx("div",{className:"truncate text-[11px] text-muted-foreground mt-1",children:Ve.get(t.providerId)??t.providerId}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mt-2",children:[e.jsx("span",{className:"rounded bg-muted px-1.5 py-0.5 text-[10px] font-medium text-muted-foreground",children:r(Fe.find(n=>n.value===t.workspacePolicy)?.label??t.workspacePolicy)}),e.jsxs("span",{className:"rounded bg-muted px-1.5 py-0.5 text-[10px] font-medium text-muted-foreground",children:[s,"/10 ",r("能力")]})]})]})]},t.id)})})]}):we?e.jsxs("div",{className:"rounded-xl border border-border bg-white",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-border/60 px-5 py-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:L,className:"flex items-center gap-1.5 text-xs text-muted-foreground hover:text-foreground transition-colors",children:[e.jsx(_e,{size:14}),r("返回")]}),e.jsx("span",{className:"text-neutral-200",children:"|"}),e.jsx("h3",{className:"text-[13px] font-semibold text-foreground",children:I==="create"?r("创建新模板"):de?.name??r("编辑模板")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[I==="edit"&&de&&e.jsx("button",{onClick:()=>oe(de),className:"flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10 transition-colors",title:r("删除"),children:e.jsx(ue,{size:14})}),e.jsx(p,{size:"sm",onClick:tt,disabled:!nt,children:J.isPending||K.isPending?r("保存中..."):r(I==="create"?"创建":"保存")})]})]}),e.jsxs("div",{className:"p-5 space-y-5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-[12px] font-medium text-muted-foreground mb-1",children:r("模板名称")}),e.jsx("input",{value:y.name,onChange:t=>Ke("name",t.target.value),className:"w-full rounded-lg border border-border bg-background px-3 py-2 text-sm transition-colors focus:border-ring focus:outline-none"})]}),e.jsxs("div",{className:"grid gap-4 xl:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-[12px] font-medium text-muted-foreground mb-2",children:r("可用预设")}),e.jsx("div",{className:"max-h-[400px] space-y-1 overflow-y-auto scrollbar-app-thin",children:w?e.jsx(G,{title:r("加载失败"),error:ge,isFetching:be,onRetry:()=>{fe()}}):u.length===0?e.jsx("div",{className:"rounded-lg border border-dashed border-border p-3 text-center text-[12px] text-muted-foreground",children:r("先创建成员预设")}):u.map(t=>{const s=y.memberPresetIds.filter(n=>n===t.id).length;return e.jsxs("button",{type:"button",onClick:()=>ct(t.id),className:B("flex w-full items-center gap-2.5 rounded-lg border px-3 py-2 text-left transition-all",s>0?"border-neutral-900 bg-muted":"border-border bg-background hover:border-border"),children:[e.jsx(U,{name:t.name,avatar:t.avatar,className:"h-7 w-7 text-[10px] shrink-0"}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx("div",{className:"truncate text-[12px] font-medium text-foreground",children:t.name})}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[s>0&&e.jsxs("span",{className:"rounded-full bg-neutral-900 px-1.5 py-0.5 text-[10px] font-medium text-white",children:["x",s]}),e.jsx(R,{size:13,className:"text-muted-foreground"})]})]},t.id)})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[12px] font-medium text-muted-foreground mb-2",children:r("已选成员")}),e.jsx("div",{className:"max-h-[400px] space-y-1 overflow-y-auto scrollbar-app-thin",children:ce.length===0?e.jsx("div",{className:"rounded-lg border border-dashed border-border p-3 text-center text-[12px] text-muted-foreground",children:r("尚未选择")}):ce.map((t,s)=>e.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-lg border border-border bg-background px-3 py-2",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(U,{name:t.name,avatar:t.avatar,className:"h-7 w-7 text-[10px] shrink-0"}),e.jsx("span",{className:"truncate text-[12px] font-medium text-foreground",children:Rt(t.name,s,y.memberPresetIds,t.id)})]}),e.jsxs("div",{className:"flex items-center gap-0.5 shrink-0",children:[e.jsx(p,{type:"button",variant:"ghost",size:"icon-sm",onClick:()=>Ce(s,-1),disabled:s===0,children:e.jsx(Ct,{size:13})}),e.jsx(p,{type:"button",variant:"ghost",size:"icon-sm",onClick:()=>Ce(s,1),disabled:s===ce.length-1,children:e.jsx(It,{size:13})}),e.jsx(p,{type:"button",variant:"ghost",size:"icon-sm",onClick:()=>mt(s),children:e.jsx(ue,{size:13})})]})]},`${t.id}-${s}`))})]})]})]})]}):e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 mb-4",children:[e.jsx("span",{className:"text-[12px] text-muted-foreground",children:r("{count} 个团队模板",{count:b.length})}),e.jsxs(p,{size:"sm",variant:"outline",onClick:Se,children:[e.jsx(R,{size:13})," ",r("新增模板")]})]}),D?e.jsx(G,{title:r("加载失败"),error:Ue,isFetching:Ye,onRetry:()=>{qe()}}):b.length===0?e.jsx(Ae,{message:r("暂无团队模板"),action:e.jsxs(p,{size:"sm",onClick:Se,children:[e.jsx(R,{size:13,className:"mr-1"})," ",r("新增模板")]})}):e.jsx("div",{className:"grid gap-3 grid-cols-1 sm:grid-cols-2 lg:grid-cols-3",children:b.map(t=>{const s=t.members?.length??0,n=(t.members??[]).slice(0,3).map(k=>$.get(k.memberPresetId)?.name).filter(Boolean);return e.jsxs("button",{type:"button",onClick:()=>xt(t),className:"flex flex-col rounded-xl border border-border bg-background p-4 text-left transition-all hover:border-border hover:shadow-sm",children:[e.jsx("div",{className:"truncate text-[13px] font-semibold text-foreground",children:t.name}),e.jsx("div",{className:"text-[11px] text-muted-foreground mt-1",children:r("{count} 个成员",{count:s})}),n.length>0&&e.jsxs("div",{className:"truncate text-[11px] text-muted-foreground mt-1.5",children:[n.join(", "),s>3?` +${s-3}`:""]})]},t.id)})})]}),e.jsx(Me,{isOpen:!!j,onClose:()=>re(null),onConfirm:et,title:r("删除"),description:j?r('确定删除 "{name}"?此操作不可撤销。',{name:j.name}):"",variant:"danger",confirmText:r("删除"),cancelText:r("取消"),isLoading:he.isPending}),e.jsx(Tt,{isOpen:Ge,onClose:()=>se(!1),title:r("选择预设头像"),className:"max-w-2xl",children:e.jsx("div",{className:"grid grid-cols-4 gap-2 sm:grid-cols-5",children:St.map(t=>{const s=a.avatar===t.src;return e.jsxs("button",{type:"button",onClick:()=>Qe(t.src),className:B("group rounded-xl border bg-background p-2 text-center transition-all hover:border-neutral-400 hover:bg-muted focus:outline-none focus:ring-2 focus:ring-neutral-900/15",s?"border-neutral-900 ring-2 ring-neutral-900/10":"border-border"),"aria-pressed":s,"aria-label":r("选择 {name} 头像",{name:t.label}),children:[e.jsx("img",{src:t.src,alt:t.label,loading:"lazy",className:"mx-auto h-14 w-14 rounded-full object-cover sm:h-16 sm:w-16"}),e.jsx("span",{className:"mt-1 block truncate text-[10px] font-medium text-muted-foreground",children:t.label})]},t.id)})})}),e.jsx(Me,{isOpen:!!N,onClose:()=>oe(null),onConfirm:rt,title:r("删除"),description:N?r('确定删除 "{name}"?此操作不可撤销。',{name:N.name}):"",variant:"danger",confirmText:r("删除"),cancelText:r("取消"),isLoading:ve.isPending})]})}export{Zt as TeamSettingsPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a0 as ln,a1 as an,a2 as H,a3 as q,a4 as B,a5 as un,a6 as y,a7 as tn,a8 as L,a9 as _,aa as rn,ab as o,ac as on,ad as sn,ae as fn}from"./index-
|
|
1
|
+
import{a0 as ln,a1 as an,a2 as H,a3 as q,a4 as B,a5 as un,a6 as y,a7 as tn,a8 as L,a9 as _,aa as rn,ab as o,ac as on,ad as sn,ae as fn}from"./index-C9hQg1KT.js";function cn(l){return l.innerRadius}function yn(l){return l.outerRadius}function gn(l){return l.startAngle}function dn(l){return l.endAngle}function mn(l){return l&&l.padAngle}function pn(l,h,I,D,v,A,C,a){var O=I-l,i=D-h,n=C-v,d=a-A,u=d*O-n*i;if(!(u*u<y))return u=(n*(h-A)-d*(l-v))/u,[l+u*O,h+u*i]}function W(l,h,I,D,v,A,C){var a=l-I,O=h-D,i=(C?A:-A)/L(a*a+O*O),n=i*O,d=-i*a,u=l+n,s=h+d,f=I+n,c=D+d,F=(u+f)/2,t=(s+c)/2,m=f-u,g=c-s,R=m*m+g*g,T=v-A,P=u*c-f*s,S=(g<0?-1:1)*L(on(0,T*T*R-P*P)),j=(P*g-m*S)/R,z=(-P*m-g*S)/R,w=(P*g+m*S)/R,p=(-P*m+g*S)/R,x=j-F,e=z-t,r=w-F,G=p-t;return x*x+e*e>r*r+G*G&&(j=w,z=p),{cx:j,cy:z,x01:-n,y01:-d,x11:j*(v/T-1),y11:z*(v/T-1)}}function hn(){var l=cn,h=yn,I=B(0),D=null,v=gn,A=dn,C=mn,a=null,O=ln(i);function i(){var n,d,u=+l.apply(this,arguments),s=+h.apply(this,arguments),f=v.apply(this,arguments)-un,c=A.apply(this,arguments)-un,F=rn(c-f),t=c>f;if(a||(a=n=O()),s<u&&(d=s,s=u,u=d),!(s>y))a.moveTo(0,0);else if(F>tn-y)a.moveTo(s*H(f),s*q(f)),a.arc(0,0,s,f,c,!t),u>y&&(a.moveTo(u*H(c),u*q(c)),a.arc(0,0,u,c,f,t));else{var m=f,g=c,R=f,T=c,P=F,S=F,j=C.apply(this,arguments)/2,z=j>y&&(D?+D.apply(this,arguments):L(u*u+s*s)),w=_(rn(s-u)/2,+I.apply(this,arguments)),p=w,x=w,e,r;if(z>y){var G=sn(z/u*q(j)),M=sn(z/s*q(j));(P-=G*2)>y?(G*=t?1:-1,R+=G,T-=G):(P=0,R=T=(f+c)/2),(S-=M*2)>y?(M*=t?1:-1,m+=M,g-=M):(S=0,m=g=(f+c)/2)}var J=s*H(m),K=s*q(m),N=u*H(T),Q=u*q(T);if(w>y){var U=s*H(g),V=s*q(g),X=u*H(R),Y=u*q(R),E;if(F<an)if(E=pn(J,K,X,Y,U,V,N,Q)){var Z=J-E[0],$=K-E[1],b=U-E[0],k=V-E[1],nn=1/q(fn((Z*b+$*k)/(L(Z*Z+$*$)*L(b*b+k*k)))/2),en=L(E[0]*E[0]+E[1]*E[1]);p=_(w,(u-en)/(nn-1)),x=_(w,(s-en)/(nn+1))}else p=x=0}S>y?x>y?(e=W(X,Y,J,K,s,x,t),r=W(U,V,N,Q,s,x,t),a.moveTo(e.cx+e.x01,e.cy+e.y01),x<w?a.arc(e.cx,e.cy,x,o(e.y01,e.x01),o(r.y01,r.x01),!t):(a.arc(e.cx,e.cy,x,o(e.y01,e.x01),o(e.y11,e.x11),!t),a.arc(0,0,s,o(e.cy+e.y11,e.cx+e.x11),o(r.cy+r.y11,r.cx+r.x11),!t),a.arc(r.cx,r.cy,x,o(r.y11,r.x11),o(r.y01,r.x01),!t))):(a.moveTo(J,K),a.arc(0,0,s,m,g,!t)):a.moveTo(J,K),!(u>y)||!(P>y)?a.lineTo(N,Q):p>y?(e=W(N,Q,U,V,u,-p,t),r=W(J,K,X,Y,u,-p,t),a.lineTo(e.cx+e.x01,e.cy+e.y01),p<w?a.arc(e.cx,e.cy,p,o(e.y01,e.x01),o(r.y01,r.x01),!t):(a.arc(e.cx,e.cy,p,o(e.y01,e.x01),o(e.y11,e.x11),!t),a.arc(0,0,u,o(e.cy+e.y11,e.cx+e.x11),o(r.cy+r.y11,r.cx+r.x11),t),a.arc(r.cx,r.cy,p,o(r.y11,r.x11),o(r.y01,r.x01),!t))):a.arc(0,0,u,T,R,t)}if(a.closePath(),n)return a=null,n+""||null}return i.centroid=function(){var n=(+l.apply(this,arguments)+ +h.apply(this,arguments))/2,d=(+v.apply(this,arguments)+ +A.apply(this,arguments))/2-an/2;return[H(d)*n,q(d)*n]},i.innerRadius=function(n){return arguments.length?(l=typeof n=="function"?n:B(+n),i):l},i.outerRadius=function(n){return arguments.length?(h=typeof n=="function"?n:B(+n),i):h},i.cornerRadius=function(n){return arguments.length?(I=typeof n=="function"?n:B(+n),i):I},i.padRadius=function(n){return arguments.length?(D=n==null?null:typeof n=="function"?n:B(+n),i):D},i.startAngle=function(n){return arguments.length?(v=typeof n=="function"?n:B(+n),i):v},i.endAngle=function(n){return arguments.length?(A=typeof n=="function"?n:B(+n),i):A},i.padAngle=function(n){return arguments.length?(C=typeof n=="function"?n:B(+n),i):C},i.context=function(n){return arguments.length?(a=n??null,i):a},i}export{hn as d};
|