pi-web-ui 0.115.0 → 0.117.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/CHANGELOG.md +65 -2
- package/bin/device-hub-cli.mjs +26 -3
- package/bin/pi-web-ui.mjs +159 -71
- package/dist/server/agent-service-daemon.js +136 -8
- package/dist/server/agent-service.js +594 -159
- package/dist/server/canvas/canvas-workspace.js +18 -86
- package/dist/server/client-state.js +52 -8
- package/dist/server/compaction-markers.js +43 -24
- package/dist/server/dangling-tools.js +172 -16
- package/dist/server/device-center/bot-execution.js +77 -2
- package/dist/server/device-center/collab-service.js +61 -12
- package/dist/server/device-center/collab-tool.js +482 -21
- package/dist/server/device-center/connector.js +107 -37
- package/dist/server/device-center/delivery-authority.js +98 -0
- package/dist/server/device-center/delivery-subject.js +30 -0
- package/dist/server/device-center/device-integration.js +453 -183
- package/dist/server/device-center/execution-guides.js +17 -7
- package/dist/server/device-center/execution-instructions.js +2 -1
- package/dist/server/device-center/execution-settings.js +138 -25
- package/dist/server/device-center/executor.js +51 -6
- package/dist/server/device-center/file-sync.js +14 -13
- package/dist/server/device-center/group-context-message.js +3 -1
- package/dist/server/device-center/group-context.js +73 -3
- package/dist/server/device-center/hub-conversations.js +71 -6
- package/dist/server/device-center/hub-deliveries.js +120 -15
- package/dist/server/device-center/hub-integration.js +655 -334
- package/dist/server/device-center/hub-locks.js +320 -0
- package/dist/server/device-center/hub-page.js +16 -35
- package/dist/server/device-center/hub-setup.js +23 -1
- package/dist/server/device-center/hub-transaction-log.js +197 -0
- package/dist/server/device-center/hub-webhooks.js +165 -0
- package/dist/server/device-center/hub.js +1531 -305
- package/dist/server/device-center/integration-verification.js +113 -0
- package/dist/server/device-center/local-hub.js +8 -3
- package/dist/server/device-center/local-publication.js +423 -0
- package/dist/server/device-center/local-verification-job.js +97 -0
- package/dist/server/device-center/local-verification.js +274 -0
- package/dist/server/device-center/local.js +181 -13
- package/dist/server/device-center/main.js +4 -1
- package/dist/server/device-center/partition-log.js +330 -0
- package/dist/server/device-center/publication-journal.js +312 -0
- package/dist/server/device-center/publish-intent.js +379 -0
- package/dist/server/device-center/relay.js +134 -24
- package/dist/server/device-center/runtime.js +475 -42
- package/dist/server/device-center/store.js +366 -89
- package/dist/server/device-center/task-outcome.js +81 -0
- package/dist/server/device-center/task-recovery.js +603 -178
- package/dist/server/device-center/task-scheduler.js +48 -3
- package/dist/server/device-center/task-settlement.js +353 -0
- package/dist/server/device-center/task-workspace.js +443 -0
- package/dist/server/device-center/transfers.js +41 -15
- package/dist/server/device-center/verification-limits.js +10 -0
- package/dist/server/device-center/work-contract.js +995 -0
- package/dist/server/dispatch-domain-handlers.js +29 -3
- package/dist/server/dsh/dsh-agent-service.js +9 -2
- package/dist/server/engine-probe.js +112 -1
- package/dist/server/global-loader.js +119 -19
- package/dist/server/index.js +159 -17
- package/dist/server/managed.js +2 -0
- package/dist/server/model-admin.js +48 -6
- package/dist/server/model-enrich.js +10 -1
- package/dist/server/patch-node-pty.js +3 -2
- package/dist/server/patch-remote-catalog.js +3 -2
- package/dist/server/plugins.js +64 -7
- package/dist/server/preset-fields.js +17 -1
- package/dist/server/preset-share.js +1 -0
- package/dist/server/prompt-composer.js +39 -0
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/quick-ask-settings.js +28 -0
- package/dist/server/quick-ask.js +164 -0
- package/dist/server/reasoning-registry.js +207 -0
- package/dist/server/resolve-global-sdk.js +61 -11
- package/dist/server/scheduler-tasks.js +35 -8
- package/dist/server/session-list-scan.js +223 -0
- package/dist/server/session-open.js +93 -0
- package/dist/server/session-parser.js +4 -0
- package/dist/server/session-scan.js +90 -38
- package/dist/server/settings-service.js +9 -1
- package/dist/server/soft-cap.js +5 -0
- package/dist/server/startup-banner.js +35 -0
- package/dist/server/subagents.js +2 -1
- package/dist/server/tool-manager.js +17 -9
- package/dist/server/transcript-prepare.js +73 -0
- package/dist/server/unauthorized-page.js +319 -0
- package/dist/server/universal/drivers/claude-code.js +98 -34
- package/dist/server/universal/universal-session.js +4 -0
- package/dist/server/workspace-handle.js +428 -0
- package/docs/architecture-plugins.md +959 -0
- package/docs/device-center.md +34 -20
- package/package.json +4 -4
- package/plugin-sdk/README.md +16 -8
- package/plugin-sdk/client.d.ts +27 -0
- package/plugin-sdk/client.mjs +82 -0
- package/plugin-sdk/index.d.ts +10 -0
- package/plugin-sdk/index.mjs +4 -683
- package/plugin-sdk/package.json +15 -4
- package/plugin-sdk/testing.d.ts +10 -0
- package/plugin-sdk/testing.mjs +566 -0
- package/themes/flow-cristallo.css +168 -0
- package/themes/flow-ink.css +169 -0
- package/themes/flow-obsidian.css +169 -0
- package/themes/flow-zurich.css +169 -0
- package/web/dist/.build-assets.json +1 -1
- package/web/dist/assets/{BgTasksModal-BYzPgmoq.js → BgTasksModal-BjNRIUIc.js} +1 -1
- package/web/dist/assets/{BgTasksModal-ni0VTmAQ.js → BgTasksModal-C0zuU8FE.js} +1 -1
- package/web/dist/assets/{CanvasStudio-DNmDNBod.js → CanvasStudio-BWvdmJ0M.js} +3 -3
- package/web/dist/assets/{CanvasStudio-BCUeEf25.js → CanvasStudio-VQFjmTGq.js} +3 -3
- package/web/dist/assets/DeviceCenter-DI9_0aBB.js +3 -0
- package/web/dist/assets/DeviceCenter-DsNtXqzY.js +3 -0
- package/web/dist/assets/DeviceExecutionSettings-BLP1Su5G.js +1 -0
- package/web/dist/assets/DeviceGroups-2Pvk0Cds.js +1 -0
- package/web/dist/assets/DeviceGroups-CP7CcyPD.js +1 -0
- package/web/dist/assets/{Dropdown-CGXD0DfT.js → Dropdown-CQtstPGv.js} +1 -1
- package/web/dist/assets/FilePreview-BMB2tNyT.js +2 -0
- package/web/dist/assets/FilePreview-RGFQUbJo.js +2 -0
- package/web/dist/assets/{GlobalSearchModal-mevF-ySi.js → GlobalSearchModal-BM5wxiqU.js} +1 -1
- package/web/dist/assets/{GlobalSearchModal-qL99FN_F.js → GlobalSearchModal-DGv_WINq.js} +1 -1
- package/web/dist/assets/GroupConversation-B7SnuXj1.js +61 -0
- package/web/dist/assets/GroupConversation-Dda69q-2.js +61 -0
- package/web/dist/assets/{HintTip-LHwkS2jV.js → HintTip-ChTW8o1m.js} +1 -1
- package/web/dist/assets/ModelConfigModal-C-0Z4hUZ.js +2 -0
- package/web/dist/assets/ModelConfigModal-yqeadyab.js +2 -0
- package/web/dist/assets/{PiSetupModal-DE5-gEtI.js → PiSetupModal-BX5rUuoI.js} +1 -1
- package/web/dist/assets/{ProviderOAuthControls-6UMARucA.js → ProviderOAuthControls-DY4SCfXg.js} +1 -1
- package/web/dist/assets/SCMPanel-C4KbQvvK.js +2 -0
- package/web/dist/assets/SCMPanel-DPAyY2sW.js +2 -0
- package/web/dist/assets/SettingsModal-DxZp6D_g.js +32 -0
- package/web/dist/assets/SettingsModal-WhQzaOPt.js +32 -0
- package/web/dist/assets/{TerminalPanel-CTp_BZ4S.js → TerminalPanel-D4By_RVc.js} +2 -2
- package/web/dist/assets/{TerminalPanel-CkYxC-Gh.js → TerminalPanel-lZw8-i3j.js} +2 -2
- package/web/dist/assets/{TuiOverlayModal-1cRLP8IF.js → TuiOverlayModal-C3pAVuC8.js} +1 -1
- package/web/dist/assets/{TuiOverlayModal-2xlptqWX.js → TuiOverlayModal-D7_rEXcJ.js} +1 -1
- package/web/dist/assets/app-globals-KqOVtmp1.js +123 -0
- package/web/dist/assets/{canvas-client-Bye9nSFO.js → canvas-client-BY6ojmle.js} +1 -1
- package/web/dist/assets/{desktop-kjBoE3Nu.js → desktop-CV6KKp9R.js} +1 -1
- package/web/dist/assets/index-BawF7ZP5.js +397 -0
- package/web/dist/assets/index-BoGCoq5X.js +397 -0
- package/web/dist/assets/index-CVW9FoY2.css +1 -0
- package/web/dist/assets/{plugin-host-C8mNgghx.js → plugin-host-Dn8Dd6SC.js} +1 -1
- package/web/dist/assets/{remote-ssh-client-CeP3CLUW.js → remote-ssh-client-Dzi-eEyE.js} +1 -1
- package/web/dist/assets/{theme-BXGpyTMh.js → theme-D_bihpdN.js} +1 -1
- package/web/dist/index.html +11 -11
- package/web/dist/sw.js +1 -1
- package/dist/server/patch-turn-end-boundary.js +0 -77
- package/web/dist/assets/DeviceCenter-BcBhRgL6.js +0 -3
- package/web/dist/assets/DeviceCenter-CmL5FZmt.js +0 -3
- package/web/dist/assets/DeviceGroups-CLdpdnI7.js +0 -1
- package/web/dist/assets/DeviceGroups-CgBaDPrD.js +0 -1
- package/web/dist/assets/FilePreview-B8iqnBjy.js +0 -2
- package/web/dist/assets/FilePreview-BqviZKCN.js +0 -2
- package/web/dist/assets/GroupConversation-B88Yy-lt.js +0 -3
- package/web/dist/assets/GroupConversation-BwP5NVOE.js +0 -3
- package/web/dist/assets/ModelConfigModal-Do3Fe3jH.js +0 -2
- package/web/dist/assets/SCMPanel-Hi6QqC1Q.js +0 -2
- package/web/dist/assets/SCMPanel-ezY_ZtCu.js +0 -2
- package/web/dist/assets/SettingsModal-6HgeEsJ8.js +0 -20
- package/web/dist/assets/SettingsModal-CF-7MwqS.js +0 -20
- package/web/dist/assets/app-globals-DZNa9v8u.js +0 -325
- package/web/dist/assets/index-CsFs_HMb.css +0 -1
- package/web/dist/assets/index-DHeeHS_l.js +0 -85
- package/web/dist/assets/index-DTZch8uz.js +0 -85
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{A as t,B as n,Bt as r,Dn as i,Ft as a,H as o,K as s,Kt as c,Q as l,Qt as u,Rt as d,S as f,Sn as p,Tn as m,Vt as h,Xt as g,Z as _,at as v,bn as y,f as b,fn as x,i as S,in as C,j as w,kn as T,ln as E,p as D,pn as O,ut as k,v as A,vt as j,xt as M,yt as N,z as P}from"./app-globals-KqOVtmp1.js";import{i as F,t as I}from"./react-CR5VJ85Q.js";import{t as L}from"./uuid-BzDIGCwP.js";import{D as R,V as z,bt as B,ft as V,jt as H,mt as U,vt as ee,wt as te,xt as ne,yt as W}from"./index-BawF7ZP5.js";import{a as G,i as K,n as re,o as q}from"./group-view-state-CGCzYF8k.js";import{t as ie}from"./canvas-client-BY6ojmle.js";var J=e(F(),1);function ae(e,t){return!!e&&!!t&&e.artifactTaskId===t.artifactTaskId&&e.attemptId===t.attemptId&&e.artifactId===t.artifactId&&e.artifactDigest===t.artifactDigest&&e.contractId===t.contractId&&e.contractRevision===t.contractRevision&&e.contractDigest===t.contractDigest&&e.manifestDigest===t.manifestDigest&&e.baselineCommit===t.baselineCommit&&e.repositoryId===t.repositoryId&&e.inputTree===t.inputTree&&e.outputTree===t.outputTree}function oe(e,t){return!e||!t||e.id!==t.deliveryId||e.accountId!==t.accountId||e.roomId!==t.roomId||e.conversationId!==t.conversationId?!1:e.artifactRef?t.artifactDigest===e.artifactRef.artifactDigest&&ae(e.artifactRef,t.artifactRef):!t.artifactRef&&!t.artifactDigest&&!!e.commit&&e.commit===t.commit}function se(e){if(e.status===`closed`)return null;if(e.attention)return e.attention.kind;if(e.status===`queued`||e.status===`running`)return null;if(e.status===`failed`)return`failed`;if(e.status===`interrupted`)return`interrupted`;let t=e.latestDelivery??e.deliveries?.at(-1);if(!t)return null;let n=[...e.reviews??[],...e.latestReview?[e.latestReview]:[]].filter(e=>oe(t,e)).sort((e,t)=>e.createdAt-t.createdAt).at(-1);return n?n.verdict===`changes_requested`?`changes_requested`:null:`awaiting_review`}function ce(e,t){return{answer:[`等待回答`,`Waiting for an answer`],decision:[`等待决策`,`Waiting for a decision`],failed:[`执行失败,需处理`,`Execution failed — needs attention`],interrupted:[`执行中断,需处理`,`Execution interrupted — needs attention`],changes_requested:[`审查要求修改`,`Changes requested`],awaiting_review:[`已交付,待验收`,`Delivered — awaiting review`]}[e][+!t]}var Y=8e4,le=65e4,X=I();function ue(e){return!!e?.publishIntent&&(!!e.publishStop&&!e.publishStop.stopConfirmed||!e.publishReceipt&&!(e.publishStop?.closed&&e.publishStop.stopConfirmed))}async function Z(e,t,n,r=3e4){let a=await fetch(i(T(`/api/device-center/${e}`)),{method:n?`POST`:`GET`,credentials:`same-origin`,signal:AbortSignal.any([t,AbortSignal.timeout(r)]),...n?{headers:{"Content-Type":`application/json`},body:JSON.stringify(n)}:{}}),o=await a.json().catch(()=>({}));if(!a.ok)throw Error(o.error||String(a.status));return o}function Q({roomId:e,conversationId:t,delivery:n,review:r,onIntegrationChange:i,bots:a,disabled:o=!1,zh:s}){let[,c]=(0,J.useState)([]),[l,u]=(0,J.useState)(null),[d,f]=(0,J.useState)(!1),[p,m]=(0,J.useState)(n.botId||a[0]?.id||``),[h,g]=(0,J.useState)(n.branch||`main`),[_,v]=(0,J.useState)([]),[y,b]=(0,J.useState)(``),[x,S]=(0,J.useState)(null);(0,J.useEffect)(()=>S(null),[l?.id]);let[C,w]=(0,J.useState)(!1),[T,E]=(0,J.useState)(``),[D,O]=(0,J.useState)(!1),k=(0,J.useRef)(null),A=(0,J.useRef)(0),j=`rooms/${encodeURIComponent(e)}/conversations/${encodeURIComponent(t)}/integrations`;(0,J.useEffect)(()=>{i?.(l)},[l,i]),(0,J.useEffect)(()=>{A.current++,k.current?.abort(),u(null),f(!1),m(n.botId||a[0]?.id||``),g(n.branch||`main`),v([]),b(``),w(!1),E(``)},[e,t,n.id,n.artifactRef?.artifactDigest,n.commit]),(0,J.useEffect)(()=>{o&&(A.current++,k.current?.abort(),w(!1))},[o]),(0,J.useEffect)(()=>{if(!D)return;let e=++A.current;k.current?.abort();let t=new AbortController;k.current=t,E(``),f(!1);async function r(){try{let r=await Z(j,t.signal,void 0,15e3);if(t.signal.aborted||e!==A.current)return;f(r.canResumePublication===!0);let i=r.integrations||[];c(i);let a=i.filter(e=>e.deliveryId===n.id).sort((e,t)=>t.createdAt-e.createdAt)[0];u(a||null)}catch(n){!t.signal.aborted&&e===A.current&&E(n instanceof Error?n.message:String(n))}}return r(),()=>{A.current++,k.current?.abort(),w(!1)}},[D,e,t,n.id,n.commit,n.artifactRef?.artifactDigest]);let M=ue(l);(0,J.useEffect)(()=>{if(!D||o||C||!l||l.status!==`verifying`&&!M||l.deliveryId!==n.id)return;let e=l.id,t=A.current,r=new AbortController,i=5e3,a=M?Y:le,c=Date.now()+a,d=Math.ceil(a/i),p=0,m,h=()=>!r.signal.aborted&&t===A.current,g=()=>E(M?l.publishReceipt?s?`已记录发布效果,原进程停止仍未确认。请稍后回查。`:`Publication effect is recorded; original process stop remains unconfirmed. Reconcile later.`:s?`发布结果仍未知。稍后手动回查;不会自动重发写入。`:`Publication outcome remains unknown. Reconcile later; writes are never retried automatically.`:s?`验证仍在运行,稍后关闭并重新打开此面板以刷新状态。`:`Verification is still running. Close and reopen this panel later to refresh its status.`);async function _(){if(h()){if(Date.now()>=c||p>=d){g();return}p++;try{let t;if(M)t=(await Z(`${j}/${encodeURIComponent(e)}/reconcile`,r.signal,{},Math.min(Y,c-Date.now()))).integration;else{let i=await Z(j,r.signal,void 0,Math.min(15e3,c-Date.now()));if(!h())return;f(i.canResumePublication===!0),t=i.integrations.find(t=>t.id===e&&t.deliveryId===n.id)}if(!h())return;if(t?.id===e&&t.deliveryId===n.id&&(u(t),t.status!==`verifying`&&!ue(t))){E(t.error??``);return}}catch(e){if(!h())return;E(e instanceof Error?e.message:String(e))}if(Date.now()>=c||p>=d){g();return}m=setTimeout(()=>void _(),Math.min(i,c-Date.now()))}}return m=setTimeout(()=>void _(),i),()=>{r.abort(),clearTimeout(m)}},[D,o,C,l?.id,l?.status,M,n.id,j,s]);async function N(){if(o||C||!p||!ee)return;let e=++A.current;k.current?.abort();let t=new AbortController;k.current=t,w(!0),E(``);try{let r=await Z(j,t.signal,{deliveryId:n.id,targetBotId:p,targetBranch:h.trim()||`main`},Y);if(t.signal.aborted||e!==A.current)return;u(r.integration),c(e=>[r.integration,...e.filter(e=>e.id!==r.integration.id)])}catch(n){!t.signal.aborted&&e===A.current&&E(n instanceof Error?n.message:String(n))}finally{e===A.current&&w(!1)}}async function P(){if(o||C||!l||!G)return;let e=[...l.verificationPlan?.commands??x??_];if(!l.verificationPlan&&!x&&y.trim()&&!e.includes(y.trim())&&e.push(y.trim()),e.length===0){E(s?`请勾选或输入至少一条验证命令`:`Select or enter at least one validation command`);return}S(e);let t=++A.current;k.current?.abort();let n=new AbortController;k.current=n,w(!0),E(``);try{let r=await Z(`${j}/${encodeURIComponent(l.id)}/verify`,n.signal,{commands:e},le);if(n.signal.aborted||t!==A.current)return;u(r.integration),c(e=>e.map(e=>e.id===r.integration.id?r.integration:e))}catch(e){if(!n.signal.aborted&&t===A.current){E(e instanceof Error?e.message:String(e));try{let e=await Z(j,n.signal,void 0,15e3);if(!n.signal.aborted&&t===A.current){let t=e.integrations.find(e=>e.id===l.id);t&&u(t)}}catch(r){!n.signal.aborted&&t===A.current&&E(`${e instanceof Error?e.message:String(e)} · ${r instanceof Error?r.message:String(r)}`)}}}finally{t===A.current&&w(!1)}}async function F(){if(o||C||!l||!q)return;let e=++A.current;k.current?.abort();let t=new AbortController;k.current=t,w(!0),E(``);try{let n=await Z(`${j}/${encodeURIComponent(l.id)}/apply`,t.signal,{expectedTargetSha:l.expectedTargetSha},Y);if(t.signal.aborted||e!==A.current)return;u(n.integration),c(e=>e.map(e=>e.id===n.integration.id?n.integration:e))}catch(n){!t.signal.aborted&&e===A.current&&(E(n instanceof Error?n.message:String(n)),await I(l.id,t,e))}finally{e===A.current&&w(!1)}}async function I(e,t,r){try{let i=await Z(j,t.signal,void 0,15e3);if(t.signal.aborted||r!==A.current)return;f(i.canResumePublication===!0);let a=i.integrations.find(t=>t.id===e&&t.deliveryId===n.id);a&&(u(a),(a.publishReceipt||a.publishStop?.closed&&a.publishStop.stopConfirmed)&&E(a.error??``))}catch{}}async function L(e){if(o||C||!l?.publishIntent||e===`resume`&&!U)return;let t=l,n=t.publishIntent,r=++A.current;k.current?.abort();let i=new AbortController;k.current=i,w(!0),E(``);try{let a=await Z(`${j}/${encodeURIComponent(t.id)}/${e}`,i.signal,e===`resume`?{intentId:n.id,intentDigest:n.digest,candidateSha:n.candidateSha}:{},Y);if(i.signal.aborted||r!==A.current)return;u(a.integration),c(e=>e.map(e=>e.id===a.integration.id?a.integration:e))}catch(e){!i.signal.aborted&&r===A.current&&(E(e instanceof Error?e.message:String(e)),await I(t.id,i,r))}finally{r===A.current&&w(!1)}}async function R(){if(o||C||!l)return;let e=++A.current;k.current?.abort();let t=new AbortController;k.current=t,w(!0),E(``);try{let n=await Z(`${j}/${encodeURIComponent(l.id)}/cancel`,t.signal,{},Y);if(t.signal.aborted||e!==A.current)return;u(n.integration),c(e=>e.map(e=>e.id===n.integration.id?n.integration:e))}catch(n){!t.signal.aborted&&e===A.current&&(E(n instanceof Error?n.message:String(n)),await I(l.id,t,e))}finally{e===A.current&&w(!1)}}let z=!!l?.publishReceipt||l?.status===`applied`,B=!!l?.publishStop?.closed&&l.publishStop.stopConfirmed,V=!!l&&!l.publishIntent&&([`applying`,`cancelling`].includes(l.status)||l.status===`failed`&&/Apply failed; check target outcome|Publication outcome unknown/.test(l.error??``)),H=!z&&(!!l?.publishIntent&&!(B&&l.publishStop?.pastEffect===`not_applied`)||V),U=d&&!!l?.publishIntent&&l.publishObservation?.intentId===l.publishIntent.id&&l.publishObservation?.intentDigest===l.publishIntent.digest&&l.publishObservation?.candidateSha===l.publishIntent.candidateSha&&l.publishObservation?.retryable===!0&&[`prepared`,`cas_rejected`].includes(l.publishObservation.phase)&&!l.publishStop?.closed&&!l.publishReceipt&&l.status!==`cancelling`,ee=(!!n.artifactRef||te())&&!M&&!V;function te(){return r?.verdict===`accepted`&&oe(n,r)}let ne=l?.status===`conflict`,W=l?.status===`cancelled`&&(!l.publishIntent||B&&l.publishStop?.pastEffect===`not_applied`),G=!l?.verification&&!l?.publishIntent&&(l?.status===`prepared`||l?.status===`failed`&&!!l.verificationPlan),K=!!l?.verificationPlan||!!x,re=r?.verdict===`accepted`&&oe(n,r),q=l?.status===`verified`&&!l.publishIntent&&!!l.verification?.digest&&re&&(n.artifactRef?ae(n.artifactRef,l.artifactRef)&&r.integrationId===l.id&&r.verificationDigest===l.verification.digest&&Array.isArray(n.acceptanceCriteria)&&r.criteriaResults?.length===n.acceptanceCriteria.length&&n.acceptanceCriteria.every((e,t)=>r.criteriaResults.some(e=>e.criterionIndex===t&&e.verdict===`met`&&!!e.evidence.trim())):l.reviewId===r.id);return(0,X.jsxs)(`details`,{className:`gi-panel`,onToggle:e=>O(e.currentTarget.open),style:{marginTop:`1rem`,borderTop:`1px solid var(--border)`,paddingTop:`0.75rem`},children:[(0,X.jsxs)(`summary`,{style:{cursor:`pointer`,fontWeight:600,fontSize:`0.95rem`},children:[s?`验证与合并`:`Verify & merge`,` ·`,` `,z?s?`已合并`:`Merged`:H?s?`发布结果未知`:`Publication outcome unknown`:l?l.status:s?`待集成`:`Ready to integrate`]}),(0,X.jsxs)(`div`,{style:{marginTop:`0.5rem`},children:[(0,X.jsx)(`p`,{style:{margin:`0 0 0.5rem 0`,fontSize:`0.85rem`,color:`var(--text-faint)`},children:s?`先在独立工作区验证此交付${n.commit?` (${n.commit.slice(0,8)})`:``},验收通过并确认后才写入目标分支。`:`Verify this delivery${n.commit?` (${n.commit.slice(0,8)})`:``} in a separate workspace. The target branch changes only after acceptance and your confirmation.`}),T&&(0,X.jsx)(`p`,{role:`alert`,style:{color:`var(--red, #f43f5e)`,fontSize:`0.85rem`,margin:`0.25rem 0`},children:T}),l?.publishIntent&&(0,X.jsxs)(`div`,{className:`gi-publication`,style:{overflowWrap:`anywhere`,wordBreak:`break-word`,minWidth:0},children:[(0,X.jsx)(`p`,{role:`status`,children:z?s?`已记录发布效果(证据:${l.publishReceipt?.proof??`legacy`})。`:`Publication effect recorded (proof: ${l.publishReceipt?.proof??`legacy`}).`:H?s?`发布结果未知。回查只读取证据,不会自动重新写入分支。`:`Publication outcome unknown. Reconciliation observes evidence and never retries branch writes.`:s?`已确认在发布前取消。`:`Cancellation before publication is confirmed.`}),(0,X.jsxs)(`div`,{children:[s?`发布意图:`:`Intent: `,(0,X.jsx)(`code`,{children:l.publishIntent.id})]}),(0,X.jsxs)(`div`,{children:[s?`候选提交:`:`Candidate: `,(0,X.jsx)(`code`,{children:l.publishIntent.candidateSha})]}),(0,X.jsxs)(`p`,{children:[s?`当前目标观察:`:`Current target observation: `,l.publishObservation?(0,X.jsxs)(X.Fragment,{children:[l.publishObservation.target,` · `,l.publishObservation.phase,` `,(0,X.jsx)(`code`,{children:l.publishObservation.targetSha})]}):s?`未知(尚未观察)`:`Unknown (not yet observed)`]}),l.publishStop&&(0,X.jsx)(`p`,{children:l.publishStop.stopConfirmed?l.publishStop.pastEffect===`unknown`?s?`已封闭写入并确认进程停止;历史发布结果仍未知。`:`Writes are fenced and process stop is confirmed; historical publication outcome remains unknown.`:s?`已确认封闭并停止发布操作。`:`Publication operation is fenced and confirmed stopped.`:s?`已封闭未来写入;原发布进程停止尚未确认,仍保持隔离。`:`Future writes are fenced; the original publication process has not been confirmed stopped and remains isolated.`}),(0,X.jsx)(`button`,{type:`button`,className:`btn`,disabled:o||C,onClick:()=>void L(`reconcile`),children:s?`回查发布证据`:`Reconcile publication`}),U&&(0,X.jsx)(`button`,{type:`button`,className:`btn`,disabled:o||C,onClick:()=>void L(`resume`),children:s?`恢复同一发布意图`:`Resume same publication intent`})]}),z&&!l?.publishReceipt&&(0,X.jsx)(`p`,{role:`status`,children:s?`旧记录标记已应用;没有持久发布回执。`:`Legacy applied record; no durable publication receipt.`}),V&&(0,X.jsx)(`p`,{role:`status`,children:s?`旧发布记录缺少持久意图,历史结果未知。需本机核查;不会自动重试。`:`Legacy publication has no durable intent; its historical outcome is unknown. Local inspection is required; it will not retry automatically.`}),!l||W?(0,X.jsx)(`div`,{className:`gi-prepare-form`,style:{display:`flex`,flexDirection:`column`,gap:`0.5rem`},children:(0,X.jsxs)(`div`,{style:{display:`flex`,gap:`0.5rem`,flexWrap:`wrap`,alignItems:`center`},children:[(0,X.jsxs)(`label`,{style:{fontSize:`0.85rem`},children:[s?`目标工作区 (Bot):`:`Target Bot Workspace:`,(0,X.jsx)(`select`,{value:p,onChange:e=>m(e.target.value),disabled:o||C,style:{marginLeft:`0.25rem`},children:a.map(e=>(0,X.jsx)(`option`,{value:e.id,children:e.name||e.id},e.id))})]}),(0,X.jsxs)(`label`,{style:{fontSize:`0.85rem`},children:[s?`目标分支:`:`Target Branch:`,(0,X.jsx)(`input`,{type:`text`,value:h,onChange:e=>g(e.target.value),disabled:o||C,style:{marginLeft:`0.25rem`,width:`120px`}})]}),(0,X.jsx)(`button`,{type:`button`,className:`btn primary`,disabled:o||C||!p||!ee,onClick:()=>void N(),children:C?s?`准备中…`:`Preparing…`:s?`准备隔离集成`:`Prepare Isolated Integration`})]})}):(0,X.jsxs)(`div`,{className:`gi-active-task`,style:{display:`flex`,flexDirection:`column`,gap:`0.5rem`},children:[(0,X.jsxs)(`div`,{style:{display:`flex`,justifyContent:`space-between`,alignItems:`center`},children:[(0,X.jsxs)(`span`,{style:{fontSize:`0.85rem`,fontWeight:600},children:[s?`集成状态: `:`Status: `,(0,X.jsx)(`span`,{style:{color:z?`var(--green, #10b981)`:ne?`var(--red, #f43f5e)`:`var(--accent)`},children:H?s?`发布结果未知`:`Publication outcome unknown`:l.status})]}),(!z||M)&&!W&&!B&&(0,X.jsx)(`button`,{type:`button`,className:`btn danger`,disabled:o||C,onClick:()=>void R(),style:{fontSize:`0.75rem`,padding:`0.2rem 0.5rem`},children:z?s?`封闭写入并确认进程停止`:`Fence writes & confirm process stop`:s?`取消集成`:`Cancel`})]}),(0,X.jsxs)(`div`,{style:{fontSize:`0.8rem`,color:`var(--text-faint)`},children:[(0,X.jsxs)(`span`,{children:[s?`目标分支: `:`Target Branch: `,(0,X.jsx)(`code`,{children:l.targetBranch})]}),l.expectedTargetSha&&(0,X.jsxs)(`span`,{style:{marginLeft:`1rem`},children:[s?`基线 SHA: `:`Target SHA: `,(0,X.jsx)(`code`,{children:l.expectedTargetSha.slice(0,8)})]}),l.newCommitSha&&(0,X.jsxs)(`span`,{style:{marginLeft:`1rem`},children:[s?`新提交 SHA: `:`New Commit SHA: `,(0,X.jsx)(`code`,{children:l.newCommitSha.slice(0,8)})]})]}),ne&&l.conflicts&&(0,X.jsxs)(`div`,{style:{background:`rgba(244, 63, 94, 0.1)`,padding:`0.5rem`,borderRadius:`4px`},children:[(0,X.jsx)(`strong`,{style:{color:`var(--red, #f43f5e)`,fontSize:`0.85rem`},children:s?`检测到合并冲突!无法自动合并:`:`Merge conflicts detected:`}),(0,X.jsx)(`ul`,{style:{margin:`0.25rem 0`,paddingLeft:`1.2rem`,fontSize:`0.8rem`},children:l.conflicts.map((e,t)=>(0,X.jsx)(`li`,{children:(0,X.jsx)(`code`,{children:e})},t))}),l.diff&&(0,X.jsxs)(`details`,{style:{marginTop:`0.25rem`,fontSize:`0.8rem`},children:[(0,X.jsx)(`summary`,{children:s?`查看冲突 Diff`:`View Conflict Diff`}),(0,X.jsx)(`pre`,{style:{maxHeight:`150px`,overflow:`auto`,fontSize:`0.75rem`},children:l.diff})]})]}),l.diff&&!ne&&(0,X.jsxs)(`details`,{style:{fontSize:`0.85rem`,margin:`0.25rem 0`},children:[(0,X.jsx)(`summary`,{children:s?`集成 Diff 预览`:`Integration Diff Preview`}),(0,X.jsx)(`pre`,{style:{maxHeight:`200px`,overflow:`auto`,fontSize:`0.75rem`,background:`var(--code-bg, rgba(0,0,0,0.2))`,padding:`0.5rem`,borderRadius:`4px`},children:l.diff})]}),G&&(0,X.jsxs)(`div`,{style:{border:`1px solid var(--border)`,borderRadius:`4px`,padding:`0.5rem`,background:`var(--bg-elev2)`},children:[(0,X.jsx)(`div`,{style:{fontSize:`0.85rem`,fontWeight:600,marginBottom:`0.25rem`},children:s?`验证命令`:`Verification commands`}),(0,X.jsx)(`p`,{style:{fontSize:`0.75rem`,color:`var(--text-faint)`,margin:`0 0 0.25rem 0`},children:s?K?`命令已锁定。重试会运行相同命令;更换命令需要新建验证。`:`请由账户所有者选择或填写命令。点击验证即授权执行并锁定这些命令。`:K?`Commands are locked. A retry runs the same commands; start a new verification to change them.`:`As the account owner, select or enter commands. Clicking Verify authorizes execution and locks these commands.`}),K&&(0,X.jsx)(`pre`,{children:(l.verificationPlan?.commands??x??[]).join(`
|
|
2
|
+
`)}),!K&&n.checks.length>0&&(0,X.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`0.25rem`,margin:`0.25rem 0`},children:n.checks.map((e,t)=>(0,X.jsxs)(`label`,{style:{fontSize:`0.8rem`,display:`flex`,alignItems:`center`,gap:`0.25rem`},children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:_.includes(e.command),disabled:o||C||K,onChange:t=>{t.target.checked?v(t=>[...t,e.command]):v(t=>t.filter(t=>t!==e.command))}}),(0,X.jsx)(`code`,{children:e.command}),(0,X.jsxs)(`span`,{style:{color:`var(--text-faint)`,fontSize:`0.75rem`},children:[`(`,s?`Bot 自述结果:`:`Bot claimed:`,` `,e.status,`)`]})]},t))}),(0,X.jsxs)(`div`,{style:{display:`flex`,gap:`0.5rem`,marginTop:`0.25rem`},children:[(0,X.jsx)(`input`,{type:`text`,placeholder:s?`自定义验证命令,如 npm test`:`Custom command, e.g. npm test`,value:y,onChange:e=>b(e.target.value),disabled:o||C||K,style:{flex:1,fontSize:`0.8rem`}}),(0,X.jsx)(`button`,{type:`button`,className:`btn`,disabled:o||C||!K&&_.length===0&&!y.trim(),onClick:()=>void P(),style:{fontSize:`0.8rem`},children:C&&l.status===`verifying`?s?`验证中…`:`Verifying…`:s?`验证`:`Verify`})]}),l.validationCommands.length>0&&(0,X.jsxs)(`div`,{style:{marginTop:`0.5rem`},children:[(0,X.jsx)(`div`,{style:{fontSize:`0.8rem`,fontWeight:600},children:s?`验证结果:`:`Validation Results:`}),l.validationCommands.map((e,t)=>(0,X.jsxs)(`div`,{style:{fontSize:`0.75rem`,margin:`0.25rem 0`},children:[(0,X.jsx)(`code`,{children:e.command}),`:`,` `,(0,X.jsx)(`span`,{style:{color:e.status===`passed`?`var(--green, #10b981)`:`var(--red, #f43f5e)`,fontWeight:600},children:e.status}),e.exitCode!==void 0&&` (exit ${e.exitCode})`,e.output&&(0,X.jsx)(`pre`,{style:{maxHeight:`100px`,overflow:`auto`,margin:`0.1rem 0`,padding:`0.25rem`,background:`rgba(0,0,0,0.15)`},children:e.output})]},t))]})]}),l.verification&&(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`p`,{role:`status`,children:s?`验证已成功并锁定。重新验证请新建整合。`:`Verification succeeded and is locked. Start a new integration to verify again.`}),(0,X.jsxs)(`details`,{children:[(0,X.jsx)(`summary`,{children:s?`验证结果`:`Verification results`}),l.verification.results.map((e,t)=>(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`code`,{children:e.command}),` · `,e.status,` (exit `,e.exitCode,`)`,(0,X.jsx)(`pre`,{style:{maxHeight:`150px`,overflow:`auto`},children:e.outputPreview})]},t))]})]}),l.verification&&!q&&!z&&!l.publishIntent&&(0,X.jsx)(`p`,{children:s?`请完成与本次验证对应的独立验收,再确认合并。`:`Complete an independent review for this verification before confirming the merge.`}),!z&&ee&&(0,X.jsx)(`button`,{type:`button`,className:`btn`,disabled:o||C,onClick:()=>void N(),children:s?`新建整合与验证`:`Start a new integration & verification`}),q&&(0,X.jsxs)(`div`,{style:{marginTop:`0.5rem`,display:`flex`,alignItems:`center`,gap:`0.5rem`},children:[(0,X.jsx)(`button`,{type:`button`,className:`btn primary`,disabled:o||C,onClick:()=>void F(),style:{fontSize:`0.85rem`},children:C&&l.status===`applying`?s?`正在写入目标分支…`:`Writing to target branch…`:s?`确认合并写入 ${l.targetBranch}`:`Confirm & Merge into ${l.targetBranch}`}),(0,X.jsx)(`span`,{style:{fontSize:`0.75rem`,color:`var(--text-faint)`},children:s?`(点击即确认合并,绝不强制覆盖或自动推送)`:`(Explicit confirmation; never forces or pushes)`})]}),z&&(0,X.jsxs)(`div`,{style:{color:`var(--green, #10b981)`,fontSize:`0.85rem`,fontWeight:600,marginTop:`0.25rem`},children:[`✓`,` `,s?`已记录分支 ${l.targetBranch} 的历史发布结果;当前分支状态以上方观察为准。`:`Historical publication recorded for branch ${l.targetBranch}; see the current target observation above.`]})]})]})]})}async function de(e,t,n){let r=await fetch(i(T(`/api/device-center/${e}`)),{method:n?`POST`:`GET`,credentials:`same-origin`,signal:AbortSignal.any([t,AbortSignal.timeout(15e3)]),...n?{headers:{"Content-Type":`application/json`},body:JSON.stringify(n)}:{}}),a=await r.json().catch(()=>({}));if(!r.ok)throw Error(a.error||String(r.status));return a}function fe({roomId:e,conversations:t,bots:n,disabled:r,error:i,onRefresh:a}){let{locale:o}=y(),s=m(o),[c,l]=(0,J.useState)(!0),u=t.filter(e=>se(e)).length,d=c?t.filter(e=>se(e)):t;return(0,X.jsxs)(`details`,{className:`gd-panel`,children:[(0,X.jsxs)(`summary`,{children:[s?`需要我处理`:`Needs attention`,` · `,u,` · `,s?`全部对话`:`All conversations`,` `,t.length]}),(0,X.jsxs)(`div`,{className:`gd-content`,children:[i&&(0,X.jsx)(`p`,{role:`alert`,children:i}),(0,X.jsxs)(`label`,{children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:c,onChange:e=>l(e.target.checked)}),s?`仅显示需要处理的事项`:`Show only items needing attention`]}),!d.length&&(0,X.jsx)(`p`,{children:c?s?`当前没有需要处理的事项。`:`Nothing needs attention right now.`:s?`暂无 Bot 对话。`:`No Bot conversations yet.`}),d.map(t=>(0,X.jsx)(pe,{roomId:e,conversation:t,bot:n.find(e=>e.id===t.botId)?.name??t.botId,bots:n,disabled:r||!!i,onRefresh:a,zh:s},`${e}:${t.id}`))]})]})}function pe({roomId:e,conversation:t,bot:n,bots:r=[],disabled:i,onRefresh:a,zh:o}){let s=se(t),[c,l]=(0,J.useState)(!1),[u,d]=(0,J.useState)(``),[f,p]=(0,J.useState)(!1),[m,h]=(0,J.useState)(``),[g,_]=(0,J.useState)(null),[v,y]=(0,J.useState)(``),[b,x]=(0,J.useState)(!1),[S,C]=(0,J.useState)(!1),w=(0,J.useRef)(!1);(0,J.useEffect)(()=>{T.current?.abort(),T.current=null,w.current=!1,_(null),C(!1)},[t.latestDelivery?.id,t.reviewCount]);let T=(0,J.useRef)(null);(0,J.useEffect)(()=>()=>T.current?.abort(),[]),(0,J.useEffect)(()=>{i&&T.current?.abort()},[i]);let E=t.deliveries??(t.latestDelivery?[t.latestDelivery]:[]),D=t.reviews??(t.latestReview?[t.latestReview]:[]),O=E[E.length-1],k=`rooms/${encodeURIComponent(e)}/conversations/${encodeURIComponent(t.id)}`;async function A(){if(w.current||i||T.current&&!T.current.signal.aborted)return;let e=new AbortController;T.current=e,C(!0);try{let t=await de(k,e.signal);if(e.signal.aborted)return;w.current=!0,_(t),y(``)}catch(t){e.signal.aborted||y(t instanceof Error?t.message:String(t))}finally{e.signal.aborted||C(!1),T.current===e&&(T.current=null)}}return(0,J.useEffect)(()=>{b&&A()},[b,t.latestDelivery?.id,t.reviewCount,i]),(0,X.jsxs)(`section`,{className:`gd-conversation`,"aria-label":`${n} · ${t.name}`,children:[(0,X.jsxs)(`strong`,{children:[n,` · `,t.name||(o?`未命名对话`:`Untitled conversation`)]}),(0,X.jsxs)(`p`,{children:[o?`执行状态`:`Execution status`,`: `,t.status]}),t.closedReason&&(0,X.jsx)(`p`,{role:`status`,children:t.closedReason===`device_revoked`?o?`承载 Bot 的设备已解绑,此会话已停止。`:`The device hosting this Bot was revoked, so the conversation stopped.`:o?`此会话已停止。`:`This conversation was stopped.`}),t.stale&&(0,X.jsx)(`p`,{role:`status`,children:o?`Bot 配置已变更(revision/设备/成员),此会话无法继续;请新建对话。`:`This Bot's configuration changed (revision, device or membership); start a new conversation.`}),t.status!==`closed`&&!t.stale&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`button`,{type:`button`,className:`btn`,disabled:i||f,onClick:async()=>{if(!(i||f)){p(!0),h(``);try{await de(`rooms/${encodeURIComponent(e)}/conversations/${encodeURIComponent(t.id)}/stop`,AbortSignal.timeout(15e3),{}),a?.()}catch(e){h(e instanceof Error?e.message:String(e))}finally{p(!1)}}},children:o?`关闭会话`:`Close conversation`}),m&&(0,X.jsx)(`p`,{role:`alert`,children:m})]}),(t.status===`closed`||t.stale)&&!t.deliveryCount&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`button`,{type:`button`,className:`btn`,disabled:i||c,onClick:async()=>{if(!(i||c)){l(!0),d(``);try{await de(`rooms/${encodeURIComponent(e)}/conversations/${encodeURIComponent(t.id)}/delete`,AbortSignal.timeout(15e3),{}),a?.()}catch(e){d(e instanceof Error?e.message:String(e))}finally{l(!1)}}},children:o?`删除会话(释放容量)`:`Delete conversation (free capacity)`}),u&&(0,X.jsx)(`p`,{role:`alert`,children:u})]}),s&&(0,X.jsx)(`p`,{role:`status`,children:ce(s,o)}),t.attention&&(0,X.jsx)(me,{roomId:e,conversation:t,disabled:i,zh:o},t.attention.id),(s===`failed`||s===`interrupted`||s===`changes_requested`)&&(0,X.jsx)(`p`,{children:o?`在输入框输入 @,选择此 Bot 的原对话补充要求或继续处理。`:`Type @ in the composer and select this Bot's existing conversation to continue.`}),t.deliverySummaryTruncated&&!g&&(0,X.jsx)(`p`,{children:o?`当前为摘要,请展开完整交付后验收。`:`Summary only. Load the full delivery before reviewing.`}),O?(0,X.jsx)(he,{roomId:e,conversationId:t.id,bots:r,delivery:g?.deliveries.find(e=>e.id===O.id)??O,reviews:[...g?.reviews??[],...D],base:k,disabled:i||!!t.deliverySummaryTruncated&&!g,zh:o},O.id):(0,X.jsx)(`p`,{children:o?`未交付(执行结束不代表已交付)`:`Not delivered (execution ending does not imply delivery)`}),O&&(0,X.jsxs)(`details`,{className:`gd-history`,onToggle:e=>{x(e.currentTarget.open)},children:[(0,X.jsxs)(`summary`,{children:[o?`完整交付与历史`:`Full delivery & history`,` · `,t.deliveryCount??E.length]}),S&&(0,X.jsx)(`p`,{role:`status`,children:o?`加载中…`:`Loading…`}),v&&(0,X.jsxs)(`p`,{role:`alert`,children:[v,` `,(0,X.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>void A(),children:o?`重试`:`Retry`})]}),(t.deliveries??g?.deliveries??[]).filter(e=>e.id!==O?.id).map(e=>(0,X.jsx)(he,{delivery:e,reviews:t.reviews??g?.reviews??[],base:k,disabled:i,readOnly:!0,zh:o},e.id))]})]})}function me({roomId:e,conversation:t,disabled:n,zh:r}){let[i,a]=(0,J.useState)(``),[o,s]=(0,J.useState)(``),[c,l]=(0,J.useState)(!1),[u,d]=(0,J.useState)(!1),f=(0,J.useRef)(null),p=(0,J.useRef)(null);(0,J.useEffect)(()=>()=>f.current?.abort(),[]),(0,J.useEffect)(()=>{n&&f.current?.abort()},[n]);async function m(){if(n||c||u||!i.trim()||!t.attention)return;let r=new AbortController;f.current=r,p.current?.text!==i.trim()&&(p.current={text:i.trim(),key:L()}),l(!0);try{await de(`rooms/${encodeURIComponent(e)}/conversations/${encodeURIComponent(t.id)}/messages`,r.signal,{text:p.current.text,attentionId:t.attention.id,idempotencyKey:p.current.key}),r.signal.aborted||(d(!0),s(``))}catch(e){r.signal.aborted||s(e instanceof Error?e.message:String(e))}finally{f.current===r&&(f.current=null,l(!1))}}return(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`p`,{children:t.attention?.question}),u?(0,X.jsx)(`p`,{role:`status`,children:r?`已回复,原会话将继续。`:`Answer sent. The original conversation will continue.`}):(0,X.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),m()},children:[(0,X.jsxs)(`label`,{children:[r?`你的答复`:`Your answer`,(0,X.jsx)(`textarea`,{value:i,maxLength:8e3,disabled:n||c,onChange:e=>a(e.target.value)})]}),(0,X.jsx)(`button`,{type:`submit`,className:`btn`,disabled:n||c||!i.trim()||t.status===`closed`,children:r?`回复并继续`:`Answer & continue`}),o&&(0,X.jsx)(`p`,{role:`alert`,children:o})]})]})}function he({delivery:e,reviews:t,base:n,roomId:r,conversationId:i,bots:a=[],disabled:o,readOnly:s=!1,zh:c}){let[l,u]=(0,J.useState)(null),[d,f]=(0,J.useState)(null),[p,m]=(0,J.useState)([]);(0,J.useEffect)(()=>{m([])},[d?.id,d?.verification?.digest]);let[h,g]=(0,J.useState)(``),[_,v]=(0,J.useState)(!1),[y,b]=(0,J.useState)(``),x=(0,J.useRef)(null),S=(0,J.useRef)(null);(0,J.useEffect)(()=>()=>x.current?.abort(),[]),(0,J.useEffect)(()=>{o&&x.current?.abort()},[o]);let C=[...t,...l?[l]:[]].filter(t=>oe(e,t)),w=d?.deliveryId===e.id&&d.status===`verified`&&!!d.verification?.digest&&ae(e.artifactRef,d.artifactRef),T=Array.isArray(e.acceptanceCriteria)&&e.acceptanceCriteria.every((e,t)=>p[t]?.met&&p[t]?.evidence.trim()),E=!e.artifactRef||w&&T,D=C.sort((e,t)=>t.createdAt-e.createdAt)[0];async function O(t){if(s||o||x.current||!h.trim()||t===`accepted`&&!E)return;let r=e.artifactRef?{artifactDigest:e.artifactRef.artifactDigest,...t===`accepted`?{integrationId:d.id,verificationDigest:d.verification.digest,criteriaResults:e.acceptanceCriteria.map((e,t)=>({criterionIndex:t,verdict:`met`,evidence:p[t].evidence.trim()}))}:{}}:{commit:e.commit},i=JSON.stringify([e.id,r,t,h.trim()]);S.current?.fingerprint!==i&&(S.current={fingerprint:i,key:L()});let a=new AbortController;x.current=a,v(!0),b(``);try{let i=await de(`${n}/reviews`,a.signal,{deliveryId:e.id,...r,verdict:t,summary:h.trim(),idempotencyKey:S.current.key});if(a.signal.aborted)return;u(i.review),g(``),S.current=null}catch(e){a.signal.aborted||b(e instanceof Error?e.message:String(e))}finally{x.current===a&&(x.current=null,v(!1))}}return(0,X.jsxs)(`article`,{className:`gd-delivery`,children:[(0,X.jsx)(`p`,{className:`gd-status`,role:`status`,children:D?D.verdict===`accepted`?c?`验收通过`:`Accepted`:c?`需返工`:`Changes requested`:c?`已交付 · 待验收`:`Delivered · Awaiting review`}),(0,X.jsxs)(`dl`,{children:[(0,X.jsx)(`dt`,{children:c?`交付版本 ID`:`Delivery version ID`}),(0,X.jsx)(`dd`,{children:e.id}),(0,X.jsx)(`dt`,{children:c?`仓库`:`Repository`}),(0,X.jsx)(`dd`,{children:e.repository}),e.commit&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`dt`,{children:`Commit SHA`}),(0,X.jsx)(`dd`,{children:(0,X.jsx)(`code`,{children:e.commit})})]}),e.artifactRef&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`dt`,{children:c?`产物`:`Artifact`}),(0,X.jsx)(`dd`,{children:e.artifactRef.artifactId}),(0,X.jsx)(`dt`,{children:c?`源码任务`:`Source task`}),(0,X.jsx)(`dd`,{children:e.artifactRef.artifactTaskId}),(0,X.jsx)(`dt`,{children:c?`内容摘要`:`Content digest`}),(0,X.jsx)(`dd`,{children:(0,X.jsx)(`code`,{children:e.artifactRef.artifactDigest})}),(0,X.jsx)(`dt`,{children:c?`文件树版本`:`File tree version`}),(0,X.jsx)(`dd`,{children:(0,X.jsx)(`code`,{children:e.artifactRef.outputTree})})]}),(0,X.jsx)(`dt`,{children:c?`基线 SHA`:`Base SHA`}),(0,X.jsx)(`dd`,{children:(0,X.jsx)(`code`,{children:e.baseCommit})}),e.branch&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`dt`,{children:c?`分支`:`Branch`}),(0,X.jsx)(`dd`,{children:e.branch})]}),(0,X.jsx)(`dt`,{children:c?`交付摘要`:`Summary`}),(0,X.jsx)(`dd`,{children:e.summary}),(0,X.jsx)(`dt`,{children:c?`限制与未完成项`:`Limitations`}),(0,X.jsx)(`dd`,{children:e.limitations.length?e.limitations.join(`
|
|
3
|
+
`):c?`Bot 未报告限制`:`No limitations reported by Bot`})]}),(0,X.jsx)(`p`,{children:c?`检查来源:Bot 自报,未经宿主或 CI 验证。`:`Checks source: Bot self-report; not verified by host or CI.`}),e.checks.length?(0,X.jsx)(`ul`,{children:e.checks.map((e,t)=>(0,X.jsxs)(`li`,{children:[(0,X.jsx)(`code`,{children:e.command}),` · `,e.status,` · `,e.result,e.exitCode!==void 0&&` (exit ${e.exitCode})`]},t))}):(0,X.jsx)(`p`,{children:c?`Bot 未报告检查`:`No checks reported by Bot`}),D&&(0,X.jsxs)(`p`,{children:[c?`验收意见`:`Review`,` (`,D.reviewer.type===`human`?c?`人工`:`Human`:`Bot`,`) ·`,` `,D.summary]}),!s&&(0,X.jsxs)(`form`,{onSubmit:e=>e.preventDefault(),children:[(0,X.jsxs)(`label`,{children:[c?`人工验收意见(对应以上交付版本)`:`Human review (for the delivery version above)`,(0,X.jsx)(`textarea`,{value:h,onChange:e=>g(e.target.value),disabled:o||_,rows:2,required:!0})]}),e.artifactRef&&(0,X.jsxs)(`fieldset`,{disabled:o||_||!w,children:[(0,X.jsx)(`legend`,{children:c?`逐项验收`:`Acceptance criteria`}),(0,X.jsx)(`p`,{children:w?(c?`对应验证:`:`Reviewing verification: `)+d.id:c?`请先展开验证与合并,完成验证后填写验收证据。`:`Open Verify & merge and complete verification before entering acceptance evidence.`}),e.acceptanceCriteria?.map((e,t)=>(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`label`,{children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:p[t]?.met??!1,onChange:e=>m(n=>{let r=[...n];return r[t]={evidence:n[t]?.evidence??``,met:e.target.checked},r})}),e]}),(0,X.jsxs)(`label`,{children:[c?`验收证据`:`Evidence`,(0,X.jsx)(`textarea`,{value:p[t]?.evidence??``,maxLength:2e3,onChange:e=>m(n=>{let r=[...n];return r[t]={met:n[t]?.met??!1,evidence:e.target.value},r})})]})]},t))]}),(0,X.jsxs)(`div`,{className:`gd-actions`,children:[(0,X.jsx)(`button`,{type:`button`,className:`btn`,disabled:o||_||!h.trim()||!E,onClick:()=>void O(`accepted`),children:c?`验收通过`:`Accept delivery`}),(0,X.jsx)(`button`,{type:`button`,className:`btn`,disabled:o||_||!h.trim(),onClick:()=>void O(`changes_requested`),children:c?`需返工`:`Request changes`})]}),_&&(0,X.jsx)(`p`,{role:`status`,children:c?`提交中…`:`Submitting…`}),y&&(0,X.jsx)(`p`,{role:`alert`,children:y})]}),!s&&r&&i&&(0,X.jsx)(Q,{roomId:r,conversationId:i,delivery:e,review:D,onIntegrationChange:f,bots:a,disabled:o,zh:c},`${r}:${i}:${e.id}`)]})}function ge({roomId:e,disabled:t,refreshKey:n=0,connected:r=!1}){let{locale:a}=y(),o=m(a),[s,c]=(0,J.useState)([]),[l,u]=(0,J.useState)(``),[d,f]=(0,J.useState)(0),p=(0,J.useRef)(null);(0,J.useEffect)(()=>()=>{p.current?.abort(),p.current=null},[e,t]);let h=i(T(`/api/device-center/rooms/${encodeURIComponent(e)}/interactions`));(0,J.useEffect)(()=>{if(u(``),t){c([]);return}let n=new AbortController,i=!1;async function a(){if(!(i||document.visibilityState===`hidden`)){i=!0;try{let t=await fetch(h,{credentials:`same-origin`,signal:n.signal}),r=await t.json();if(!t.ok)throw Error(r.error||String(t.status));n.signal.aborted||(c(Array.isArray(r.interactions)?r.interactions.filter(t=>t&&typeof t.id==`string`&&t.roomId===e&&[`question`,`approval`].includes(t.kind)):[]),u(``))}catch(e){n.signal.aborted||u(String(e))}finally{i=!1}}}a();let o=r?void 0:setInterval(()=>void a(),2e3),s=()=>{document.visibilityState!==`hidden`&&a()};return document.addEventListener(`visibilitychange`,s),()=>{n.abort(),clearInterval(o),document.removeEventListener(`visibilitychange`,s)}},[h,t,d,n,r]),(0,J.useEffect)(()=>{c([])},[e]);async function g(e,t){p.current?.abort();let n=new AbortController;p.current=n;try{let r=await fetch(h,{method:`POST`,credentials:`same-origin`,signal:AbortSignal.any([n.signal,AbortSignal.timeout(15e3)]),headers:{"Content-Type":`application/json`},body:JSON.stringify({taskId:e.taskId,attemptId:e.attemptId,interactionId:e.id,...t})}),i=await r.json();if(!r.ok)throw Error(i.error||String(r.status));n.signal.aborted||f(e=>e+1)}finally{p.current===n&&(p.current=null)}}return!s.length&&!l?null:(0,X.jsxs)(`div`,{className:`gd-content dg-native-interactions-wrap`,children:[l&&(0,X.jsx)(`p`,{role:`alert`,children:l}),s.map(t=>(0,X.jsx)(_e,{item:t,zh:o,answer:e=>g(t,e)},`${e}:${t.id}`))]})}function _e({item:e,zh:t,answer:n}){let[r,i]=(0,J.useState)({}),[a,o]=(0,J.useState)(!1),[s,c]=(0,J.useState)(``);async function l(e){o(!0),c(``);try{await n(e)}catch(e){c(String(e)),o(!1)}}let u=(e.questions??[]).filter(e=>!e.dependsOn||r[e.dependsOn.questionId]&&(!e.dependsOn.value||[e.dependsOn.value].flat().some(t=>r[e.dependsOn.questionId].selected.includes(t)))),d=u.every(e=>r[e.id]?.selected.length||r[e.id]?.custom?.trim());return(0,X.jsxs)(`section`,{className:`gd-card`,children:[(0,X.jsxs)(`strong`,{children:[e.kind===`approval`?t?`工具审批 · 仅本次`:`Tool approval · once`:t?`模型提问`:`Model question`,` `,`· `,e.botId]}),e.deadline&&(0,X.jsxs)(`p`,{children:[t?`截止时间:`:`Deadline: `,new Date(e.deadline).toLocaleString()]}),e.kind===`approval`?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`p`,{children:e.toolName}),(0,X.jsx)(`pre`,{children:e.paramsPreview}),(0,X.jsx)(`p`,{children:e.reason}),(0,X.jsx)(`button`,{className:`btn`,disabled:a,onClick:()=>void l({decision:`approve`}),children:t?`批准本次`:`Approve once`}),(0,X.jsx)(`button`,{className:`btn`,disabled:a,onClick:()=>void l({decision:`deny`}),children:t?`拒绝`:`Deny`})]}):(0,X.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),d&&l({answers:u.map(e=>r[e.id]??{id:e.id,selected:[]})})},children:[u.map(t=>{let n=r[t.id]??{id:t.id,selected:[]},o=t.optionsMap&&t.dependsOn?t.optionsMap[r[t.dependsOn.questionId]?.selected[0]]??t.options:t.options;return(0,X.jsxs)(`fieldset`,{disabled:a,children:[(0,X.jsx)(`legend`,{children:t.question}),t.detail&&(0,X.jsx)(`p`,{children:t.detail}),o?.map(r=>(0,X.jsxs)(`label`,{children:[(0,X.jsx)(`input`,{type:t.multiSelect?`checkbox`:`radio`,name:`${e.id}:${t.id}`,checked:n.selected.includes(r.label),onChange:e=>i(i=>({...i,[t.id]:{...n,selected:t.multiSelect?e.target.checked?[...n.selected,r.label]:n.selected.filter(e=>e!==r.label):[r.label]}}))}),r.label,r.description&&` · ${r.description}`]},r.label)),(0,X.jsx)(`textarea`,{"aria-label":t.question,maxLength:4e3,value:n.custom??``,onChange:e=>i(r=>({...r,[t.id]:{...n,custom:e.target.value}}))})]},t.id)}),(0,X.jsx)(`button`,{type:`submit`,className:`btn`,disabled:a||!d,children:t?`提交回答`:`Submit answer`}),(0,X.jsx)(`button`,{type:`button`,className:`btn`,disabled:a,onClick:()=>void l({answers:[],cancelled:!0}),children:t?`取消问卷`:`Cancel question`})]}),s&&(0,X.jsx)(`p`,{role:`alert`,children:s})]})}function ve(e){if(!Number.isFinite(e)||e<=0)return`0 B`;let t=[`B`,`KiB`,`MiB`,`GiB`],n=0,r=e;for(;r>=1024&&n<t.length-1;)r/=1024,n++;return`${r.toFixed(n===0?0:1)} ${t[n]}`}async function ye(e,t,n){let r=await fetch(i(T(`/api/device-center/${e}`)),{method:n?`POST`:`GET`,credentials:`same-origin`,signal:t?AbortSignal.any([t,AbortSignal.timeout(15e3)]):AbortSignal.timeout(15e3),...n?{headers:{"Content-Type":`application/json`},body:JSON.stringify(n)}:{}}),a=await r.json().catch(()=>({}));if(!r.ok)throw Error(a.error||String(r.status));return a}function be({roomId:e,bots:t=[],disabled:n=!1}){let{locale:r}=y(),i=m(r),[a,o]=(0,J.useState)([]),[s,c]=(0,J.useState)({}),[l,u]=(0,J.useState)(!1),[d,f]=(0,J.useState)(``),[p,h]=(0,J.useState)(``),[g,_]=(0,J.useState)(!1),[v,b]=(0,J.useState)(``),[x,S]=(0,J.useState)(``),[C,w]=(0,J.useState)(``),[T,E]=(0,J.useState)(!0),[D,O]=(0,J.useState)(!1),k=(0,J.useRef)(0),A=(0,J.useRef)(e);A.current=e;let j=(0,J.useRef)(new Set),M=(0,J.useRef)(null);function N(){let e=new AbortController;return j.current.add(e),e}let P=(0,J.useRef)(new Map);(0,J.useEffect)(()=>{P.current=new Map(t.map(e=>[e.id,e.name||e.id])),b(e=>t.some(t=>t.id===e)?e:t[0]?.id??``),S(e=>t.some(t=>t.id===e)?e:t[1]?.id??``)},[t,e]);function F(e){return P.current.get(e)||e}(0,J.useEffect)(()=>(k.current++,M.current=null,O(!1),u(!1),o([]),h(``),f(``),c({}),_(!1),w(``),()=>{k.current++;for(let e of j.current)e.abort();j.current.clear()}),[e]),(0,J.useEffect)(()=>{if(!e)return;let t=k.current,n,r=null,i=!1;async function s(){if(!(i||t!==k.current)){if(document.visibilityState===`hidden`){n=setTimeout(s,4e3);return}r=new AbortController;try{let n=await ye(`rooms/${encodeURIComponent(e)}/transfers`,r.signal);!i&&t===k.current&&A.current===e&&Array.isArray(n?.transfers)&&o(n.transfers)}catch{}finally{if(!i&&t===k.current){let e=a.some(e=>[`queued`,`staging`,`cancelling`,`applying`].includes(e.status));n=setTimeout(s,e?1500:4e3)}}}}return s(),()=>{i=!0,clearTimeout(n),r?.abort()}},[e,a.length]);let I=(e,t)=>{c(n=>{let r=new Set(n[e]||[]);return r.has(t)?r.delete(t):r.add(t),{...n,[e]:r}})},L=async t=>{if(t.preventDefault(),!v||!x||!C.trim()||D)return;if(v===x){h(i?`源机器人与目标机器人不能相同`:`Source and target bots must be different`);return}let n=k.current,r=e,a=N();O(!0),h(``),f(i?`正在创建并启动文件传输...`:`Initiating chunked file transfer...`);try{let t=C.split(`
|
|
4
|
+
`).map(e=>e.trim()).filter(Boolean),s=JSON.stringify([e,v,x,t,T]);M.current?.fingerprint!==s&&(M.current={fingerprint:s,key:crypto.randomUUID()});let c=await ye(`rooms/${encodeURIComponent(e)}/transfers/start`,a.signal,{idempotencyKey:M.current.key,sourceBotId:v,targetBotId:x,paths:t,recursive:T});if(n!==k.current||r!==A.current)return;f(i?`传输任务已成功启动 (ID: ${c.transferId?.slice(0,8)??``}),正在后台分块传输中。`:`Transfer started (ID: ${c.transferId?.slice(0,8)??``}), streaming chunks in background.`),_(!1),w(``),M.current=null;let l=await ye(`rooms/${encodeURIComponent(e)}/transfers`,a.signal);n===k.current&&r===A.current&&Array.isArray(l?.transfers)&&o(l.transfers)}catch(e){n===k.current&&r===A.current&&h(e instanceof Error?e.message:String(e))}finally{j.current.delete(a),n===k.current&&r===A.current&&O(!1)}},R=async t=>{let n=t.preview||(t.files?{id:t.transferId,revision:t.revision||``,files:t.files}:void 0);if(!n||l)return;let r=k.current,a=e,c=N();u(!0),h(``),f(i?`正在导入文件变更...`:`Applying file changes...`);try{let l=Array.from(s[t.transferId]||[]),u=await ye(`rooms/${encodeURIComponent(e)}/transfers/${encodeURIComponent(t.transferId)}/apply`,c.signal,{revision:n.revision,overwritePaths:l});if(r!==k.current||a!==A.current)return;f(i?`导入成功:已应用 ${u.applied?.length??0} 个文件,未变 ${u.unchanged?.length??0} 个`:`Apply successful: applied ${u.applied?.length??0}, unchanged ${u.unchanged?.length??0}`),o(e=>e.map(e=>e.transferId===t.transferId?{...e,status:`applied`}:e))}catch(e){r===k.current&&a===A.current&&h(e instanceof Error?e.message:String(e))}finally{j.current.delete(c),r===k.current&&a===A.current&&u(!1)}},z=async t=>{let n=k.current,r=e,a=N();try{if(await ye(`rooms/${encodeURIComponent(e)}/transfers/${encodeURIComponent(t.transferId)}/abort`,a.signal,{}),n!==k.current||r!==A.current)return;o(e=>e.map(e=>e.transferId===t.transferId?{...e,status:`cancelled`}:e)),f(i?`传输已取消,暂存文件与配额已物理释放`:`Transfer aborted; staged quota freed`)}catch(e){n===k.current&&r===A.current&&h(e instanceof Error?e.message:String(e))}finally{j.current.delete(a)}},B=async t=>{let n=k.current,r=e,i=N();try{let e=await ye(`rooms/${encodeURIComponent(r)}/transfers/${encodeURIComponent(t.transferId)}/resume`,i.signal,{manifestHash:t.manifestHash,sourceBotRevision:t.sourceBotRevision,targetBotRevision:t.targetBotRevision});n===k.current&&r===A.current&&o(n=>n.map(n=>n.transferId===t.transferId?e:n))}catch(e){n===k.current&&r===A.current&&h(e instanceof Error?e.message:String(e))}finally{j.current.delete(i)}},V=a.filter(e=>[`queued`,`staging`,`cancelling`].includes(e.status)).length,H=a.filter(e=>e.status===`staged`||e.status===`ready`).length;return(0,X.jsxs)(`details`,{className:`dft-panel`,open:a.length>0,children:[(0,X.jsxs)(`summary`,{className:`dft-summary`,children:[(0,X.jsx)(`span`,{className:`dft-title-icon`,children:`📦`}),(0,X.jsx)(`span`,{children:i?`跨机大文件传输与断点续传`:`Cross-Device Chunked File Transfers`}),a.length>0&&(0,X.jsx)(`span`,{className:`dft-badge`,children:V>0?i?`${V} 个传输中`:`${V} streaming`:H>0?i?`${H} 个待导入`:`${H} staged`:`${a.length}`})]}),(0,X.jsxs)(`div`,{className:`dft-content`,children:[p&&(0,X.jsx)(`div`,{className:`dft-alert dft-alert-error`,role:`alert`,children:p}),d&&(0,X.jsx)(`div`,{className:`dft-alert dft-alert-info`,children:d}),(0,X.jsx)(`div`,{className:`dft-toolbar`,children:(0,X.jsx)(`button`,{type:`button`,className:`btn dft-btn-toggle`,onClick:()=>_(e=>!e),disabled:n||t.length<2,children:g?i?`收起传输表单`:`Close Transfer Form`:i?`+ 发起新文件/目录传输`:`+ New File/Directory Transfer`})}),g&&(0,X.jsxs)(`form`,{className:`dft-start-form`,onSubmit:L,children:[(0,X.jsxs)(`div`,{className:`dft-form-row`,children:[(0,X.jsxs)(`label`,{className:`dft-form-label`,children:[(0,X.jsx)(`span`,{children:i?`源机器人 (发送端)`:`Source Bot (Sender)`}),(0,X.jsx)(`select`,{className:`dft-select`,value:v,onChange:e=>b(e.target.value),disabled:n||D,children:t.map(e=>(0,X.jsxs)(`option`,{value:e.id,children:[e.name||e.id,` (`,e.id.slice(0,8),`)`]},e.id))})]}),(0,X.jsxs)(`label`,{className:`dft-form-label`,children:[(0,X.jsx)(`span`,{children:i?`目标机器人 (接收端)`:`Target Bot (Receiver)`}),(0,X.jsx)(`select`,{className:`dft-select`,value:x,onChange:e=>S(e.target.value),disabled:n||D,children:t.filter(e=>e.id!==v).map(e=>(0,X.jsxs)(`option`,{value:e.id,children:[e.name||e.id,` (`,e.id.slice(0,8),`)`]},e.id))})]})]}),(0,X.jsx)(`div`,{className:`dft-form-row`,children:(0,X.jsxs)(`label`,{className:`dft-form-label full-width`,children:[(0,X.jsx)(`span`,{children:i?`相对路径(文件或目录,每行一个)`:`Project-relative paths (one per line)`}),(0,X.jsx)(`textarea`,{className:`dft-textarea`,rows:2,placeholder:i?`如: src/ 或 large-asset.bin`:`e.g. src/ or data/model.weights`,value:C,onChange:e=>w(e.target.value),disabled:n||D})]})}),(0,X.jsxs)(`div`,{className:`dft-form-footer`,children:[(0,X.jsxs)(`label`,{className:`dft-checkbox-label`,children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:T,onChange:e=>E(e.target.checked),disabled:n||D}),(0,X.jsx)(`span`,{children:i?`递归包含子目录 (recursive)`:`Recursive directory traversal`})]}),(0,X.jsx)(`button`,{type:`submit`,className:`btn primary dft-btn-submit`,disabled:n||D||!C.trim()||v===x,children:D?i?`启动中...`:`Starting...`:i?`开始分块传输`:`Start Transfer`})]})]}),a.length===0?(0,X.jsxs)(`div`,{className:`dft-empty`,children:[(0,X.jsx)(`p`,{children:i?`当前群暂无文件传输记录。`:`No active file transfers in this room.`}),(0,X.jsx)(`span`,{className:`dft-hint`,children:i?`支持突破 8MiB 限制的大文件及 >128 文件的目录分块传输。发起后将在此实时展示进度与断点续传状态。`:`Supports >8MiB files and 128+ file directories. Live progress, chunk checksums and resume controls appear here.`})]}):(0,X.jsx)(`div`,{className:`dft-transfers-list`,children:a.map(e=>{let t=Math.min(100,Math.max(0,e.percent??0)),r=e.preview?.files||e.files||[],a=s[e.transferId]||new Set;return(0,X.jsxs)(`div`,{className:`dft-card dft-card-${e.status}`,children:[(0,X.jsxs)(`div`,{className:`dft-card-header`,children:[(0,X.jsxs)(`div`,{className:`dft-route`,children:[(0,X.jsx)(`span`,{className:`dft-bot-name`,children:F(e.sourceBotId)}),(0,X.jsx)(`span`,{className:`dft-arrow`,children:`➔`}),(0,X.jsx)(`span`,{className:`dft-bot-name`,children:F(e.targetBotId)}),(0,X.jsx)(`span`,{className:`dft-id-badge`,title:e.transferId,children:e.transferId.slice(0,8)})]}),(0,X.jsxs)(`span`,{className:`dft-status-tag dft-tag-${e.status}`,children:[e.status===`staging`&&(i?`分块传输中`:`Streaming`),(e.status===`staged`||e.status===`ready`)&&(i?`待确认导入`:`Ready`),e.status===`queued`&&(i?`排队中`:`Queued`),e.status===`interrupted`&&(i?`已中断`:`Interrupted`),e.status===`cancelling`&&(i?`取消中`:`Cancelling`),e.status===`applying`&&(i?`导入中`:`Applying`),e.status===`applied`&&(i?`已导入`:`Applied`),e.status===`cancelled`&&(i?`已取消`:`Cancelled`),e.status===`failed`&&(i?`失败`:`Failed`)]})]}),(0,X.jsxs)(`div`,{className:`dft-metrics`,children:[(0,X.jsxs)(`span`,{children:[i?`文件: `:`Files: `,(0,X.jsx)(`strong`,{children:e.totalFiles==null?`-`:e.totalFiles})]}),(0,X.jsxs)(`span`,{children:[i?`大小: `:`Size: `,(0,X.jsx)(`strong`,{children:e.totalBytes==null?`-`:ve(e.totalBytes)})]}),(0,X.jsxs)(`span`,{children:[i?`分块: `:`Chunks: `,(0,X.jsx)(`strong`,{children:e.totalChunks==null?`-`:`${e.receivedChunks?.length??0} / ${e.totalChunks}`})]})]}),(0,X.jsx)(`div`,{className:`dft-progress-bar-wrap`,children:(0,X.jsx)(`div`,{className:`dft-progress-bar`,style:{width:`${t}%`}})}),(0,X.jsxs)(`div`,{className:`dft-progress-label`,children:[(0,X.jsxs)(`span`,{children:[t,`%`]}),(0,X.jsx)(`span`,{className:`dft-hash-status`,children:e.status===`staged`||e.status===`ready`||e.status===`applied`?i?`✓ SHA256 完整校验通过`:`✓ SHA256 Verified`:e.status===`cancelled`?i?`传输已取消`:`Transfer cancelled`:e.status===`failed`?i?`传输失败`:`Transfer failed`:e.status===`interrupted`?i?`传输已中断`:`Transfer interrupted`:i?`32KiB 有界分块传输与断点校验中`:`32KiB Bounded Chunk Streaming`})]}),e.error&&(0,X.jsx)(`div`,{className:`dft-item-error`,title:e.error,children:e.error}),r.length>0&&(0,X.jsxs)(`div`,{className:`dft-preview-section`,children:[(0,X.jsx)(`div`,{className:`dft-preview-title`,children:i?`变更差异预览:`:`File Changes Preview:`}),(0,X.jsx)(`div`,{className:`dft-files-table`,children:r.map(t=>(0,X.jsxs)(`div`,{className:`dft-file-row dft-file-${t.status}`,children:[(0,X.jsxs)(`span`,{className:`dft-file-status-icon`,children:[t.status===`create`&&`➕`,t.status===`identical`&&`✓`,t.status===`conflict`&&`⚠️`]}),(0,X.jsx)(`span`,{className:`dft-file-path`,title:t.path,children:t.path}),(0,X.jsx)(`span`,{className:`dft-file-size`,children:ve(t.size)}),t.status===`conflict`&&(0,X.jsxs)(`label`,{className:`dft-overwrite-toggle`,children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:a.has(t.path),onChange:()=>I(e.transferId,t.path),disabled:n||e.status!==`staged`&&e.status!==`ready`}),(0,X.jsx)(`span`,{children:i?`显式覆盖`:`Overwrite`})]})]},t.path))})]}),(0,X.jsxs)(`div`,{className:`dft-card-actions`,children:[e.status===`interrupted`&&e.manifestHash&&(0,X.jsx)(`button`,{type:`button`,className:`btn`,disabled:n,onClick:()=>B(e),children:i?`按原版本续传`:`Resume saved version`}),!e.applyStarted&&[`queued`,`staging`,`ready`,`interrupted`,`failed`].includes(e.status)&&(0,X.jsx)(`button`,{type:`button`,className:`btn dft-btn-abort`,onClick:()=>z(e),disabled:n,children:i?`取消传输`:`Abort Transfer`}),(e.status===`staged`||e.status===`ready`)&&(0,X.jsx)(`button`,{type:`button`,className:`btn primary dft-btn-apply`,onClick:()=>R(e),disabled:n||l,children:l?i?`导入中...`:`Applying...`:i?`确认导入变更 (Apply)`:`Confirm Apply`})]})]},e.transferId)})})]})]})}async function xe(e,t){let n=await fetch(i(T(`/api/device-center/${e}`)),{method:`GET`,credentials:`same-origin`,signal:AbortSignal.any([t,AbortSignal.timeout(15e3)])}),r=await n.json().catch(()=>({}));if(!n.ok)throw Error(r.error||`HTTP ${n.status}`);return r}function Se({roomId:e,taskId:t,onClose:n}){let{locale:r}=y(),i=m(r),[a,o]=(0,J.useState)(null),[s,c]=(0,J.useState)([]),[l,u]=(0,J.useState)(null),[d,f]=(0,J.useState)(!0),[p,h]=(0,J.useState)(!1),[g,_]=(0,J.useState)(``),[v,b]=(0,J.useState)(``),[x,S]=(0,J.useState)(`journal`),[C,w]=(0,J.useState)(null),[T,E]=(0,J.useState)(``),[D,O]=(0,J.useState)(!1),[k,A]=(0,J.useState)(void 0),[j,M]=(0,J.useState)(!1),[N,P]=(0,J.useState)(!1),F=(0,J.useRef)(null),I=(0,J.useRef)(null),L=(0,J.useRef)(null),R=(0,J.useRef)(n);R.current=n,(0,J.useEffect)(()=>{let e=e=>{e.key===`Escape`&&R.current()};return window.addEventListener(`keydown`,e),L.current?.focus(),()=>{window.removeEventListener(`keydown`,e)}},[]),(0,J.useEffect)(()=>{F.current?.abort();let n=new AbortController;F.current=n,o(null),c([]),u(null),E(``),w(null),O(!1),A(void 0),P(!1),_(``),b(``),f(!0);async function r(){let[r,a]=await Promise.allSettled([xe(`rooms/${encodeURIComponent(e)}/tasks/${encodeURIComponent(t)}`,n.signal),xe(`rooms/${encodeURIComponent(e)}/tasks/${encodeURIComponent(t)}/journal?limit=25&direction=forward`,n.signal)]);if(!n.signal.aborted){if(r.status===`fulfilled`){let e=r.value;o(e),e.reportMeta&&w(e.reportMeta)}else _(r.reason?.message||`Failed to load task details`);a.status===`fulfilled`?(c(a.value.items),u(a.value)):b(a.reason?.message||(i?`加载事件流失败`:`Failed to load journal`)),f(!1)}}return r(),()=>{n.abort(),I.current!==null&&(clearTimeout(I.current),I.current=null)}},[e,t]);async function z(){if(!l?.nextCursor||p)return;let n=F.current??new AbortController;h(!0);try{let r=await xe(`rooms/${encodeURIComponent(e)}/tasks/${encodeURIComponent(t)}/journal?limit=25&direction=forward&cursor=${encodeURIComponent(l.nextCursor)}`,n.signal);if(n.signal.aborted)return;c(e=>[...e,...r.items]),u(r)}catch(e){n.signal.aborted||b(e?.message||(i?`分页加载日志失败`:`Failed to load more journal events`))}finally{n.signal.aborted||h(!1)}}async function B(n){let r=F.current??new AbortController;M(!0);try{let i=n===void 0?`?offset=0&limit=262144`:`?offset=${n}&limit=262144`,a=await xe(`rooms/${encodeURIComponent(e)}/tasks/${encodeURIComponent(t)}/report${i}`,r.signal);if(r.signal.aborted)return;w(a.meta);let o=a.text??``;E(e=>n===void 0||n===0?o:e+o),O(!!a.hasMore),A(a.nextOffset??void 0)}catch(e){r.signal.aborted||_(i?`加载报告分片失败: ${e.message}`:`Failed to load report slice: ${e.message}`)}finally{r.signal.aborted||M(!1)}}function V(){T&&navigator.clipboard.writeText(T).then(()=>{P(!0),I.current!==null&&clearTimeout(I.current),I.current=window.setTimeout(()=>{P(!1),I.current=null},2e3)}).catch(()=>{_(i?`复制报告失败,请手动选择复制`:`Failed to copy report to clipboard`)})}let H=s.filter(e=>e.toolName||e.type.startsWith(`tool_`)||e.parametersPreview&&Object.keys(e.parametersPreview).length>0),U=a?.task;function ee(e){let t=e||`queued`,n={queued:{zh:`排队中`,en:`Queued`,cls:`gtd-badge-queued`},running:{zh:`运行中`,en:`Running`,cls:`gtd-badge-running`},completed:{zh:`已完成`,en:`Completed`,cls:`gtd-badge-completed`},failed:{zh:`失败`,en:`Failed`,cls:`gtd-badge-failed`},interrupted:{zh:`已中断`,en:`Interrupted`,cls:`gtd-badge-interrupted`}}[t]||{zh:t,en:t,cls:`gtd-badge-queued`};return(0,X.jsx)(`span`,{className:`gtd-badge ${n.cls}`,children:i?n.zh:n.en})}return(0,X.jsx)(`div`,{className:`gtd-overlay`,role:`dialog`,"aria-modal":`true`,"aria-label":i?`任务详情`:`Task Details`,children:(0,X.jsxs)(`div`,{className:`gtd-panel`,ref:L,tabIndex:-1,children:[(0,X.jsxs)(`div`,{className:`gtd-header`,children:[(0,X.jsxs)(`div`,{className:`gtd-header-title`,children:[(0,X.jsx)(`h3`,{children:i?`群任务详情与操作审计`:`Group Task Details & Audit Log`}),U&&(0,X.jsxs)(`span`,{className:`gtd-task-id`,children:[`#`,U.id.slice(0,8)]}),U&&ee(U.status)]}),(0,X.jsx)(`button`,{type:`button`,className:`btn gtd-close-btn gtd-close`,onClick:n,children:`✕`})]}),g&&(0,X.jsx)(`div`,{className:`gtd-error-banner`,role:`alert`,children:g}),d?(0,X.jsx)(`div`,{className:`gtd-loading`,children:i?`加载任务详情中...`:`Loading task details...`}):(0,X.jsxs)(`div`,{className:`gtd-body`,children:[U&&(0,X.jsxs)(`div`,{className:`gtd-overview-card`,children:[(0,X.jsxs)(`div`,{className:`gtd-field`,children:[(0,X.jsx)(`span`,{className:`gtd-label`,children:i?`目标内容:`:`Objective:`}),(0,X.jsx)(`span`,{className:`gtd-value gtd-task-text`,children:U.text})]}),(0,X.jsxs)(`div`,{className:`gtd-meta-row`,children:[(0,X.jsxs)(`div`,{className:`gtd-field`,children:[(0,X.jsx)(`span`,{className:`gtd-label`,children:i?`执行 Bot:`:`Bot:`}),(0,X.jsx)(`span`,{className:`gtd-value`,children:U.botName||U.botId})]}),U.deviceName&&(0,X.jsxs)(`div`,{className:`gtd-field`,children:[(0,X.jsx)(`span`,{className:`gtd-label`,children:i?`运行设备:`:`Device:`}),(0,X.jsx)(`span`,{className:`gtd-value`,children:U.deviceName})]}),(0,X.jsxs)(`div`,{className:`gtd-field`,children:[(0,X.jsx)(`span`,{className:`gtd-label`,children:i?`创建时间:`:`Created:`}),(0,X.jsx)(`span`,{className:`gtd-value`,children:new Date(U.createdAt).toLocaleTimeString()})]})]}),U.queuedReason&&(0,X.jsxs)(`div`,{className:`gtd-callout gtd-callout-info`,children:[(0,X.jsx)(`strong`,{children:i?`排队原因:`:`Queued Reason:`}),` `,U.queuedReason]}),U.interruptedReason&&(0,X.jsxs)(`div`,{className:`gtd-callout gtd-callout-warning`,children:[(0,X.jsx)(`strong`,{children:i?`中断原因:`:`Interruption Reason:`}),` `,U.interruptedReason]})]}),a&&a.interactions.length>0&&(0,X.jsxs)(`div`,{className:`gtd-section`,children:[(0,X.jsx)(`h4`,{children:i?`关联人工审批与问卷`:`Associated Human Interactions`}),(0,X.jsx)(`div`,{className:`gtd-interaction-list`,children:a.interactions.map(e=>(0,X.jsxs)(`div`,{className:`gtd-interaction-item`,children:[(0,X.jsxs)(`div`,{className:`gtd-interaction-header`,children:[(0,X.jsx)(`span`,{className:`gtd-interaction-kind`,children:e.kind}),(0,X.jsx)(`span`,{className:e.resolved?`gtd-badge-completed`:`gtd-badge-queued`,children:e.resolved?i?`已裁决`:`Resolved`:i?`待处理`:`Pending`})]}),e.question&&(0,X.jsx)(`div`,{className:`gtd-interaction-q`,children:e.question}),e.decision&&(0,X.jsxs)(`div`,{className:`gtd-interaction-ans`,children:[i?`裁决结论: `:`Decision: `,` `,e.decision]})]},e.id))})]}),a&&a.deliveries.length>0&&(0,X.jsxs)(`div`,{className:`gtd-section`,children:[(0,X.jsx)(`h4`,{children:i?`关联代码交付`:`Associated Code Deliveries`}),(0,X.jsx)(`div`,{className:`gtd-delivery-list`,children:a.deliveries.map(e=>(0,X.jsxs)(`div`,{className:`gtd-delivery-item`,children:[(0,X.jsxs)(`div`,{className:`gtd-delivery-header`,children:[e.commit&&(0,X.jsx)(`span`,{className:`gtd-commit-sha`,children:e.commit.slice(0,8)}),e.branch&&(0,X.jsx)(`span`,{className:`gtd-branch-chip`,children:e.branch}),(0,X.jsx)(`span`,{className:e.reportedCheckCount===0?`gtd-badge-queued`:e.passed?`gtd-badge-completed`:`gtd-badge-failed`,children:e.reportedCheckCount===0?i?`未自报检查`:`No reported checks`:e.passed?i?`自报检查通过`:`Reported checks passed`:i?`自报检查未通过`:`Reported checks not passed`})]}),(0,X.jsx)(`div`,{className:`gtd-delivery-summary`,children:e.summary}),e.artifactRef&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`gtd-field`,children:[(0,X.jsx)(`span`,{className:`gtd-label`,children:i?`交付版本 ID:`:`Delivery version ID:`}),(0,X.jsx)(`span`,{className:`gtd-value`,children:e.id})]}),(0,X.jsxs)(`div`,{className:`gtd-field`,children:[(0,X.jsx)(`span`,{className:`gtd-label`,children:i?`产物:`:`Artifact:`}),(0,X.jsx)(`span`,{className:`gtd-value`,children:e.artifactRef.artifactId})]}),(0,X.jsxs)(`div`,{className:`gtd-field`,children:[(0,X.jsx)(`span`,{className:`gtd-label`,children:i?`源码任务:`:`Source task:`}),(0,X.jsx)(`span`,{className:`gtd-value`,children:e.artifactRef.artifactTaskId})]}),(0,X.jsxs)(`div`,{className:`gtd-field`,children:[(0,X.jsx)(`span`,{className:`gtd-label`,children:i?`内容摘要:`:`Content digest:`}),(0,X.jsx)(`span`,{className:`gtd-value`,children:e.artifactRef.artifactDigest})]}),(0,X.jsxs)(`div`,{className:`gtd-field`,children:[(0,X.jsx)(`span`,{className:`gtd-label`,children:i?`文件树版本:`:`File tree version:`}),(0,X.jsx)(`span`,{className:`gtd-value`,children:e.artifactRef.outputTree})]})]})]},e.id))})]}),(0,X.jsxs)(`div`,{className:`gtd-tabs`,children:[(0,X.jsxs)(`button`,{type:`button`,className:`gtd-tab ${x===`journal`?`active`:``}`,onClick:()=>S(`journal`),children:[i?`事件与审计流`:`Journal Events`,` (`,s.length,`)`]}),(0,X.jsxs)(`button`,{type:`button`,className:`gtd-tab ${x===`tools`?`active`:``}`,onClick:()=>S(`tools`),children:[i?`工具调用卡片`:`Tool Lifecycles`,` (`,H.length,`)`]}),(0,X.jsx)(`button`,{type:`button`,className:`gtd-tab ${x===`report`?`active`:``}`,onClick:()=>{S(`report`),T||(M(!0),B())},children:i?`任务完整报告`:`Full Report Log`})]}),x===`journal`&&(0,X.jsxs)(`div`,{className:`gtd-tab-content`,children:[l?.truncated&&(0,X.jsxs)(`div`,{className:`gtd-truncation-notice`,children:[`⚠️`,` `,i?`由于日志保留配额,最早的 ${l.droppedCount} 条事件已自动淘汰。系统明确标记并不伪装历史完整。`:`The earliest ${l.droppedCount} events were pruned due to journal retention quota. History is not disguised as complete.`]}),l?.cursorExpired&&(0,X.jsx)(`div`,{className:`gtd-callout gtd-callout-warning`,children:i?`游标所在的分段已淘汰,显示当前保留的最旧事件。`:`The requested cursor was pruned from disk; showing oldest retained segments.`}),l?.corrupted&&(0,X.jsx)(`div`,{className:`gtd-callout gtd-callout-warning`,children:i?`部分分段可能存在损坏行,已保留损坏证据。`:`Corrupted lines detected and flagged.`}),v&&(0,X.jsx)(`div`,{className:`gtd-callout gtd-callout-warning`,role:`alert`,children:v}),l?.journalUnavailable&&(0,X.jsx)(`div`,{className:`gtd-callout gtd-callout-warning`,children:i?`事件日志写入失败或被降级,审计流可能不完整。`:`Journal persistence failed or degraded; the audit trail may be incomplete.`}),s.length===0?(0,X.jsx)(`div`,{className:`gtd-empty`,children:i?`暂无事件记录`:`No journal events recorded.`}):(0,X.jsx)(`div`,{className:`gtd-journal-list`,children:s.map(e=>(0,X.jsxs)(`div`,{className:`gtd-journal-entry`,children:[(0,X.jsxs)(`div`,{className:`gtd-entry-meta`,children:[(0,X.jsxs)(`span`,{className:`gtd-entry-seq`,children:[`#`,e.sequence]}),(0,X.jsx)(`span`,{className:`gtd-entry-type`,children:e.type}),(0,X.jsx)(`span`,{className:`gtd-entry-time`,children:new Date(e.timestamp).toLocaleTimeString()})]}),e.summary&&(0,X.jsx)(`div`,{className:`gtd-entry-summary`,children:e.summary}),e.output&&(0,X.jsx)(`pre`,{className:`gtd-entry-output`,children:e.output}),e.reason&&(0,X.jsx)(`div`,{className:`gtd-entry-reason`,children:e.reason})]},e.id))}),l?.hasMore&&(0,X.jsx)(`div`,{className:`gtd-load-more-row`,children:(0,X.jsx)(`button`,{type:`button`,className:`btn gtd-load-more-btn`,disabled:p,onClick:z,children:p?i?`加载中...`:`Loading...`:i?`加载更多历史事件`:`Load more journal events`})})]}),x===`tools`&&(0,X.jsxs)(`div`,{className:`gtd-tab-content`,children:[v&&(0,X.jsx)(`div`,{className:`gtd-callout gtd-callout-warning`,role:`alert`,children:v}),H.length===0?(0,X.jsx)(`div`,{className:`gtd-empty`,children:i?`本任务暂无工具调用记录`:`No tool invocations recorded.`}):(0,X.jsx)(`div`,{className:`gtd-tool-cards`,children:H.map(e=>(0,X.jsxs)(`div`,{className:`gtd-tool-card`,children:[(0,X.jsxs)(`div`,{className:`gtd-tool-card-head`,children:[(0,X.jsx)(`strong`,{children:e.toolName||`tool`}),(0,X.jsx)(`span`,{className:`gtd-tool-phase`,children:e.type})]}),e.parametersPreview&&(0,X.jsxs)(`div`,{className:`gtd-tool-params`,children:[(0,X.jsx)(`span`,{className:`gtd-label`,children:i?`安全参数摘要:`:`Parameters:`}),(0,X.jsx)(`pre`,{children:JSON.stringify(e.parametersPreview,null,2)})]}),e.output&&(0,X.jsxs)(`div`,{className:`gtd-tool-output`,children:[(0,X.jsx)(`span`,{className:`gtd-label`,children:i?`增量安全输出:`:`Output Snippet:`}),(0,X.jsx)(`pre`,{children:e.output})]})]},e.id))})]}),x===`report`&&(0,X.jsxs)(`div`,{className:`gtd-tab-content`,children:[C&&(0,X.jsxs)(`div`,{className:`gtd-report-meta-box`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`span`,{className:`gtd-label`,children:i?`存储位置:`:`Storage:`}),` `,(0,X.jsxs)(`code`,{children:[C.storageLocation.role,`::`,C.storageLocation.reportRef]})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`span`,{className:`gtd-label`,children:i?`报告总大小:`:`Total Size:`}),` `,(0,X.jsxs)(`span`,{children:[C.totalBytes,` bytes`]})]}),C.sha256&&(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`span`,{className:`gtd-label`,children:i?`完整性 SHA256:`:`SHA256:`}),` `,(0,X.jsxs)(`code`,{children:[C.sha256.slice(0,16),`...`]})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`span`,{className:`gtd-label`,children:i?`当前已加载:`:`Loaded Size:`}),` `,(0,X.jsxs)(`span`,{children:[new TextEncoder().encode(T).length,` bytes`]})]}),C.quotaExceeded&&(0,X.jsxs)(`div`,{className:`gtd-callout gtd-callout-warning`,children:[`⚠️`,` `,i?`报告超过配额硬限制 (${C.quotaLimit} bytes),系统明确拒绝接收超额部分,绝不伪装完整。`:`Report exceeded quota limit (${C.quotaLimit} bytes) and was rejected without partial truncation disguise.`]}),C.uploadPending&&(0,X.jsxs)(`div`,{className:`gtd-callout gtd-callout-info`,children:[`⏳ `,i?`完整报告正在由执行设备分块同步中...`:`Full report chunk sync in progress...`]}),C.missing&&!C.uploadPending&&(0,X.jsxs)(`div`,{className:`gtd-callout gtd-callout-warning`,children:[`⚠️ `,i?`执行设备尚未上传完整报告原文。`:`Full report has not yet been uploaded by device.`]})]}),(0,X.jsxs)(`div`,{className:`gtd-report-actions`,children:[D&&(0,X.jsx)(`button`,{type:`button`,className:`btn`,disabled:j,onClick:()=>B(k),children:j?i?`加载中...`:`Loading...`:i?`加载更多报告内容`:`Load more report`}),(0,X.jsx)(`button`,{type:`button`,className:`btn`,disabled:j||!T,onClick:V,children:N?i?`已复制`:`Copied!`:i?`复制报告全文`:`Copy Report`})]}),j&&!T?(0,X.jsx)(`div`,{className:`gtd-loading`,children:i?`正在读取报告文件...`:`Loading report file...`}):(0,X.jsx)(`pre`,{className:`gtd-report-viewer gtd-report-text`,children:T})]})]})]})})}var Ce={zh:{planTitle:`群任务计划`,planDraft:`计划草稿编制中`,planReady:`计划已就绪(需确认后开始)`,planApproved:`计划已批准实施`,startPlan:`开始实施`,startingPlan:`正在启动…`,canvasTitle:`关联画布工作流`,canvasManualNote:`画布已就绪。引用不会自动运行,点击按钮显式启动。`,launchCanvas:`启动画布`,launchingCanvas:`正在启动画布…`,botPresetTitle:`Bot 运行快照`,lockedSnapshot:`在途任务快照已锁定(v{rev})`,toolsCount:`已授权 {count} 个工具`,isolatedNote:`独立隔离运行,未共享主会话私有配置`,applyPreset:`应用最新快照`,applyingPreset:`应用中…`,lockedCannotApply:`在途任务禁止热改预设`},en:{planTitle:`Group Task Plan`,planDraft:`Drafting plan`,planReady:`Plan Ready (Requires confirmation to start)`,planApproved:`Plan approved & executing`,startPlan:`Start Execution`,startingPlan:`Starting…`,canvasTitle:`Linked Canvas Workflow`,canvasManualNote:`Canvas attached. Workflow will not run automatically. Click to launch explicitly.`,launchCanvas:`Launch Canvas`,launchingCanvas:`Launching canvas…`,botPresetTitle:`Bot Preset Snapshot`,lockedSnapshot:`Active task snapshot locked (v{rev})`,toolsCount:`{count} authorized tools`,isolatedNote:`Isolated run, main session private config is not leaked`,applyPreset:`Apply Latest Snapshot`,applyingPreset:`Applying…`,lockedCannotApply:`Active tasks cannot hot-reload presets`}};function we({roomId:e,activeTaskId:t,taskSnapshotRevision:n,planState:r,canvasRef:i,botSnapshot:a,onStartPlanExecution:o,onLaunchCanvas:s,onApplyPresetSnapshot:c,uiSlotEntries:l,onUiAction:f,className:p}){let{locale:_}=y(),v=Ce[m(_)?`zh`:`en`],b=(0,J.useRef)(e);(0,J.useEffect)(()=>{b.current=e,A(null),S(!1),T(!1),O(!1)},[e]);let[x,S]=(0,J.useState)(!1),[C,T]=(0,J.useState)(!1),[E,O]=(0,J.useState)(!1),[k,A]=(0,J.useState)(null);return k||r||i||a||l&&l.length>0?(0,X.jsxs)(`div`,{className:`group-workspace-actions ${p??``}`.trim(),children:[k&&(0,X.jsxs)(`div`,{className:`group-workspace-error-banner`,role:`alert`,children:[(0,X.jsx)(D,{className:`error-icon`}),(0,X.jsx)(`span`,{children:k})]}),r&&(0,X.jsxs)(`div`,{className:`group-workspace-card plan-card`,children:[(0,X.jsxs)(`div`,{className:`card-header`,children:[(0,X.jsx)(w,{className:`card-icon`}),(0,X.jsx)(`span`,{className:`card-title`,children:v.planTitle}),(0,X.jsxs)(`span`,{className:`plan-badge status-${r.state}`,children:[r.state===`draft`&&v.planDraft,r.state===`ready`&&v.planReady,r.state===`approved`&&v.planApproved]})]}),r.steps&&r.steps.length>0&&(0,X.jsx)(`ul`,{className:`plan-steps-list`,children:r.steps.map(e=>(0,X.jsxs)(`li`,{className:`step-item status-${e.status??`pending`}`,children:[(0,X.jsx)(P,{className:`step-icon`}),(0,X.jsx)(`span`,{className:`step-title`,children:e.title})]},e.id))}),r.state===`ready`&&o&&(0,X.jsx)(`div`,{className:`card-actions`,children:(0,X.jsxs)(`button`,{type:`button`,className:`btn primary start-plan-btn`,onClick:async()=>{if(!t||!r||x||!o)return;let n=re(r);if(!n.ok){A(n.reason??`Plan is not ready for approval`);return}A(null),S(!0);try{await o(t)}catch(t){b.current===e&&A(t instanceof Error?t.message:String(t))}finally{b.current===e&&S(!1)}},disabled:x,children:[(0,X.jsx)(d,{className:`btn-icon`}),(0,X.jsx)(`span`,{children:x?v.startingPlan:v.startPlan})]})})]}),i&&(0,X.jsxs)(`div`,{className:`group-workspace-card canvas-card`,children:[(0,X.jsxs)(`div`,{className:`card-header`,children:[(0,X.jsx)(N,{className:`card-icon`}),(0,X.jsx)(`span`,{className:`card-title`,children:v.canvasTitle}),(0,X.jsx)(`span`,{className:`canvas-badge`,children:i.title||i.graphId})]}),(0,X.jsx)(`p`,{className:`card-note`,children:v.canvasManualNote}),s&&(0,X.jsx)(`div`,{className:`card-actions`,children:(0,X.jsxs)(`button`,{type:`button`,className:`btn launch-canvas-btn`,onClick:async()=>{if(i&&!C&&s&&!q(i)){A(null),T(!0);try{await s(i.graphId)}catch(t){b.current===e&&A(t instanceof Error?t.message:String(t))}finally{b.current===e&&T(!1)}}},disabled:C,children:[(0,X.jsx)(d,{className:`btn-icon`}),(0,X.jsx)(`span`,{children:C?v.launchingCanvas:v.launchCanvas})]})})]}),a&&(0,X.jsxs)(`div`,{className:`group-workspace-card bot-preset-card`,children:[(0,X.jsxs)(`div`,{className:`card-header`,children:[(0,X.jsx)(u,{className:`card-icon`}),(0,X.jsx)(`span`,{className:`card-title`,children:v.botPresetTitle}),(0,X.jsx)(`span`,{className:`bot-badge`,children:a.name})]}),(0,X.jsxs)(`div`,{className:`bot-snapshot-meta`,children:[(0,X.jsxs)(`span`,{className:`snapshot-rev`,children:[(0,X.jsx)(g,{className:`rev-icon`}),v.lockedSnapshot.replace(`{rev}`,String(a.revision))]}),(0,X.jsx)(`span`,{className:`snapshot-tools`,children:v.toolsCount.replace(`{count}`,String(a.toolWhitelist.length))})]}),(0,X.jsx)(`p`,{className:`card-note-faint`,children:v.isolatedNote}),c&&(0,X.jsx)(`div`,{className:`card-actions`,children:(0,X.jsxs)(`button`,{type:`button`,className:`btn secondary apply-preset-btn`,onClick:async()=>{if(a&&!E&&c){if(!K(n,a.revision)){A(v.lockedCannotApply);return}A(null),O(!0);try{let e=G(a,a.botId,a.revision+1);await c(a.botId,e)}catch(t){b.current===e&&A(t instanceof Error?t.message:String(t))}finally{b.current===e&&O(!1)}}},disabled:E||!K(n,a.revision),title:K(n,a.revision)?void 0:v.lockedCannotApply,children:[(0,X.jsx)(h,{className:`btn-icon`}),(0,X.jsx)(`span`,{children:E?v.applyingPreset:v.applyPreset})]})})]}),l&&l.length>0&&(0,X.jsxs)(`div`,{className:`group-workspace-card group-slots-card`,children:[(0,X.jsx)(`div`,{className:`card-header`,children:(0,X.jsx)(`span`,{className:`card-title`,children:m(_)?`扩展操作`:`Extensions`})}),(0,X.jsx)(`div`,{className:`card-actions group-slots-actions`,children:l.filter(e=>!e.hidden).map(e=>(0,X.jsx)(`button`,{type:`button`,className:`btn secondary group-slot-btn`,onClick:()=>f?.(e),title:e.label,children:e.label},e.id))})]})]}):null}function Te({roomId:e,binding:t,onSaved:n}){let r=m(y().locale),a=S(`cwd`),o=(0,J.useRef)(null),s=(0,J.useRef)(null),[c,l]=(0,J.useState)([]),[u,d]=(0,J.useState)(t?.graphId??``),[f,p]=(0,J.useState)(t?.cwd??a),[h,g]=(0,J.useState)(``),[_,v]=(0,J.useState)(!1),[b,x]=(0,J.useState)(!1),[C,w]=(0,J.useState)(``);(0,J.useEffect)(()=>{let e=new AbortController;s.current=e,x(!1),fetch(i(T(`/api/device-center/chat-status`)),{signal:e.signal}).then(async e=>{let t=await e.json();if(!e.ok||!t.deviceId)throw Error(t.error??`Local device identity unavailable`);g(t.deviceId)}).catch(t=>{e.signal.aborted||w(String(t.message))});let n=new ie({loadGraphOnConnect:!1});o.current=n;let r=n.subscribe(e=>{e.type===`canvas_list_result`&&l(e.graphs),e.type===`canvas_error`&&e.graphId===t?.graphId&&w(e.message),e.type===`canvas_node_event`&&e.graphId===t?.graphId&&w(`${e.nodeId}: ${e.event}`)}),a=n.subscribeConnection(v);return n.connect(),()=>{e.abort(),r(),a(),n.dispose(),o.current=null}},[t?.graphId,e]),(0,J.useEffect)(()=>{d(t?.graphId??``),p(t?.cwd??a)},[t?.graphId,t?.cwd,a]);let E=!!h&&(!t||t.deviceId===h);async function D(t=!1){let a=s.current;if(a&&!a.signal.aborted){x(!0),w(``);try{let o=c.find(e=>e.id===u);if(!t&&(!o||!f.trim()||!h))throw Error(`Select a local graph and workspace`);let s=await fetch(i(T(`/api/device-center/rooms/${encodeURIComponent(e)}/canvas`)),{method:`POST`,signal:a.signal,headers:{"Content-Type":`application/json`},body:JSON.stringify({binding:t?null:{deviceId:h,graphId:u,cwd:f.trim(),title:o.name}})}),l=await s.json();if(!s.ok)throw Error(l.error??`Canvas binding failed`);if(a.signal.aborted)return;n(),w(r?`群画布引用已保存;点击启动才会执行。`:`Group canvas reference saved. Run explicitly to execute.`)}catch(e){a.signal.aborted||w(e.message)}finally{a.signal.aborted||x(!1)}}}return(0,X.jsxs)(`details`,{className:`group-ecosystem-panel`,children:[(0,X.jsxs)(`summary`,{children:[r?`群画布`:`Group canvas`,t?` · ${t.title}`:``]}),(0,X.jsx)(`p`,{children:r?`引用保存在群组中。运行发生在绑定设备,使用下方工作目录;保存引用不会运行。`:`References are saved with the group. Runs use the bound device and workspace. Saving does not run the graph.`}),t&&(0,X.jsxs)(`p`,{children:[t.deviceId,` · `,t.graphId,` · `,t.cwd]}),!E&&t&&(0,X.jsx)(`p`,{role:`status`,children:r?`此画布属于另一台设备,请在该设备打开群组后运行。可选择本机画布重新绑定。`:`This canvas belongs to another device. Open the group there to run it, or bind a local canvas.`}),(0,X.jsxs)(`label`,{children:[r?`本机工程`:`Local graph`,(0,X.jsxs)(`select`,{value:u,onChange:e=>d(e.target.value),children:[(0,X.jsx)(`option`,{value:``,children:r?`选择画布`:`Select canvas`}),c.map(e=>(0,X.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,X.jsxs)(`label`,{children:[r?`本机工作目录`:`Local workspace`,(0,X.jsx)(`input`,{value:f,onChange:e=>p(e.target.value)})]}),(0,X.jsx)(`button`,{className:`btn`,disabled:b||!_||!h||!u||!f.trim(),onClick:()=>void D(),children:r?`保存群引用`:`Save group reference`}),t&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`button`,{className:`btn`,disabled:b,onClick:()=>void D(!0),children:r?`解除引用`:`Unbind`}),(0,X.jsx)(`button`,{className:`btn primary`,disabled:!_||!E||b,onClick:()=>{t&&E&&w(o.current?.send({type:`canvas_run_all`,graphId:t.graphId,cwd:t.cwd})?r?`已请求启动,等待画布运行状态。`:`Run requested; waiting for canvas status.`:r?`画布连接已断开。`:`Canvas disconnected.`)},children:r?`启动绑定画布`:`Run bound canvas`})]}),C&&(0,X.jsx)(`p`,{role:`status`,children:C})]})}async function Ee(e,t,n){let r=await fetch(i(T(`/api/device-center/${e}`)),{method:n?`POST`:`GET`,signal:t,headers:n?{"Content-Type":`application/json`}:void 0,body:n?JSON.stringify(n):void 0}),a=await r.json();if(!r.ok)throw Error(a.error??`HTTP ${r.status}`);return a}function De({bots:e,preferredBotId:t,onSaved:n}){let r=m(y().locale),[i,a]=(0,J.useState)(t??e[0]?.id??``),[o,s]=(0,J.useState)(null),[c,l]=(0,J.useState)(``),[u,d]=(0,J.useState)(``),[f,p]=(0,J.useState)(!1),[h,g]=(0,J.useState)(``),[_,v]=(0,J.useState)(0),b=(0,J.useRef)(null);(0,J.useEffect)(()=>{!i&&e.length&&a(t??e[0].id)},[i,e,t]);let x=e.find(e=>e.id===i),S=!!c&&!!x?.deviceId&&x.deviceId!==c;(0,J.useEffect)(()=>{let e=new AbortController;return b.current=e,p(!1),s(null),g(``),(async()=>{let t=await Ee(`chat-status`,e.signal);if(l(t.deviceId??``),!i||x?.deviceId&&t.deviceId!==x.deviceId)return;let n=await Ee(`local-bots/${encodeURIComponent(i)}`,e.signal);e.signal.aborted||s(n.bot)})().catch(t=>{e.signal.aborted||g(t.message)}),()=>e.abort()},[i,x?.deviceId,_]);async function C(){let e=b.current;if(o&&!S&&u.trim()&&e&&!e.signal.aborted){p(!0),g(``);try{let t=await Ee(`local-bots/${encodeURIComponent(o.id)}/preset`,e.signal,{revision:o.revision,preset:JSON.parse(u)});if(e.signal.aborted)return;s(t.bot),n(),g(`${r?`已保存新版本`:`Saved revision`} v${t.bot.revision}${t.synced?``:r?`;Hub同步待重试`:`; Hub sync pending`}`)}catch(t){e.signal.aborted||g(t.message)}finally{e.signal.aborted||p(!1)}}}return(0,X.jsxs)(`details`,{className:`group-ecosystem-panel`,children:[(0,X.jsx)(`summary`,{children:r?`Bot 配置与预设`:`Bot configuration and presets`}),(0,X.jsxs)(`label`,{children:[`Bot`,(0,X.jsxs)(`select`,{value:i,disabled:f,onChange:e=>a(e.target.value),children:[(0,X.jsx)(`option`,{value:``,children:r?`选择 Bot`:`Select Bot`}),e.map(e=>(0,X.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,X.jsx)(`p`,{children:r?`仅编辑本机 Bot。保存创建新 revision;忙碌的 Bot 会拒绝修改,在途任务不热改。`:`Edit local Bots only. Saving creates a new revision. Busy Bots reject edits; in-flight tasks retain their configuration.`}),S&&(0,X.jsx)(`p`,{role:`status`,children:r?`此 Bot 在远程设备。请在该设备的本机界面读取和保存配置。`:`This Bot belongs to a remote device. Read and save its configuration in that device's local UI.`}),o&&!S&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`p`,{children:[o.name,` · v`,o.revision,` · `,o.cwd]}),(0,X.jsxs)(`p`,{children:[r?`模型`:`Model`,`:`,` `,o.model?`${o.model.provider}/${o.model.modelId}`:r?`跟随设备默认`:`Device default`]}),(0,X.jsxs)(`p`,{children:[r?`已授权工具`:`Authorized tools`,`: `,o.tools.join(`, `)||(r?`无`:`None`)]}),(0,X.jsxs)(`label`,{children:[r?`可选预设 JSON(仅填写要修改的字段)`:`Optional preset JSON (include only fields to change)`,(0,X.jsx)(`textarea`,{rows:6,value:u,onChange:e=>d(e.target.value),placeholder:`{"systemPrompt":"…"}`})]}),(0,X.jsx)(`p`,{children:r?`允许字段:model、tools、skills、mcpServers、systemPrompt。省略字段保留当前值;工具、技能、MCP及模型须在本机目录中可用。`:`Allowed fields: model, tools, skills, mcpServers, systemPrompt. Omitted fields retain current values. Tools, skills, MCP and models must be available locally.`}),(0,X.jsx)(`button`,{className:`btn`,disabled:f,onClick:()=>v(e=>e+1),children:r?`重新读取配置`:`Reload configuration`}),(0,X.jsx)(`button`,{className:`btn primary`,disabled:f||!u.trim(),onClick:()=>void C(),children:r?`保存为新 revision(基于 v${o.revision})`:`Save new revision (based on v${o.revision})`})]}),h&&(0,X.jsx)(`p`,{role:`status`,children:h})]})}var Oe=[{id:`architecture`,titleZh:`架构设计`,titleEn:`Architecture`,aliases:[`架构设计`,`系统架构`,`architecture`,`system architecture`,`架构契约`,`技术方案`]},{id:`contracts`,titleZh:`接口契约`,titleEn:`Contracts`,aliases:[`接口契约`,`接口规范`,`contracts`,`api contracts`,`api规范`,`协议契约`,`数据契约`]},{id:`progress`,titleZh:`任务分工`,titleEn:`Task Progress`,aliases:[`任务分工`,`分工与进度`,`progress`,`tasks`,`task progress`,`流水线分工`,`任务流水线`]},{id:`blockers`,titleZh:`阻塞与决策`,titleEn:`Blockers & Decisions`,aliases:[`阻塞与决策`,`决策记录`,`blockers`,`decisions`,`风险与阻塞`,`关键技术决策`]}];function ke(e){if(!e||!e.trim())return{preamble:``,sections:[]};let t=e.split(/\r?\n/),n=[],r=``,i=``,a=[],o=[],s=!1;for(let e of t){let t=e.match(/^##\s+(.+)$/);if(t){let o=t[1].trim();s?(n.push({id:Ae(r),title:r,content:a.join(`
|
|
5
|
+
`).trim(),rawHeader:i}),a=[]):s=!0,r=o,i=e;continue}s?a.push(e):o.push(e)}return s&&r&&n.push({id:Ae(r),title:r,content:a.join(`
|
|
6
|
+
`).trim(),rawHeader:i}),{preamble:o.join(`
|
|
7
|
+
`).trim(),sections:n}}function Ae(e){let t=e.toLowerCase();for(let e of Oe)if(e.aliases.some(e=>t.includes(e.toLowerCase())))return e.id;return`custom-${encodeURIComponent(e.slice(0,32))}`}function je(e,t,n,r){let{preamble:i,sections:a}=ke(e),o=a.findIndex(e=>e.id===t);o>=0?a[o].content=r.trim():a.push({id:t,title:n,content:r.trim(),rawHeader:`## ${n}`});let s=[];i&&s.push(i);for(let e of a)e.rawHeader?s.push(e.rawHeader):s.push(`## ${e.title}`),e.content&&s.push(e.content);return s.join(`
|
|
8
|
+
|
|
9
|
+
`)}function Me({roomId:e,blackboard:r,disabled:a=!1,onSaved:s}){let{locale:c}=y(),u=m(c),[d,f]=(0,J.useState)(`all`),[p,g]=(0,J.useState)(!1),[_,b]=(0,J.useState)(r?.title??``),[S,C]=(0,J.useState)(r?.content??``),[w,O]=(0,J.useState)(``),[k,A]=(0,J.useState)(!1),[N,F]=(0,J.useState)(null),{copied:I,copy:L}=U({duration:1800}),R=(0,J.useMemo)(()=>ke(r?.content??``),[r?.content]),z=(0,J.useMemo)(()=>{let e=[{id:`all`,label:u?`全量共识`:`All Consensus`}];for(let t of Oe){let n=R.sections.find(e=>e.id===t.id);e.push({id:t.id,label:u?t.titleZh:t.titleEn,count:+!!n?.content})}for(let t of R.sections)Oe.some(e=>e.id===t.id)||e.push({id:t.id,label:t.title,count:+!!t.content,isCustom:!0});return e},[R.sections,u]);(0,J.useEffect)(()=>{p||(b(r?.title??``),C(r?.content??``))},[r,p]);let B=(0,J.useMemo)(()=>d===`all`?null:R.sections.find(e=>e.id===d)??null,[d,R.sections]),H=(0,J.useMemo)(()=>Oe.find(e=>e.id===d),[d]),ee=(0,J.useCallback)(()=>{if(F(null),d===`all`)b(r?.title??``),C(r?.content??``);else{let e=R.sections.find(e=>e.id===d);O(e?.content??``)}g(!0)},[d,r,R.sections]),te=(0,J.useCallback)(()=>{g(!1),F(null),d===`all`?(b(r?.title??``),C(r?.content??``)):O(``)},[d,r]),ne=(0,J.useCallback)(async()=>{A(!0),F(null);try{let t=r?.version??0;if(d!==`all`){let n=!1;try{(await fetch(i(T(`/api/device-center/rooms/${encodeURIComponent(e)}/blackboard/sections/${encodeURIComponent(d)}`)),{method:`PUT`,credentials:`same-origin`,headers:{"Content-Type":`application/json`},body:JSON.stringify({content:w,expectedVersion:t})})).ok&&(n=!0)}catch{}if(!n){let n=H?u?H.titleZh:H.titleEn:B?.title||d,a=je(r?.content??``,d,n,w),o=await fetch(i(T(`/api/device-center/rooms/${encodeURIComponent(e)}/blackboard`)),{method:`PUT`,credentials:`same-origin`,headers:{"Content-Type":`application/json`},body:JSON.stringify({title:r?.title||void 0,content:a,expectedVersion:t})}),s=await o.json().catch(()=>({}));if(!o.ok)throw o.status===409?Error(u?`黑板已被其他成员更新,版本发生冲突,请刷新后重试。`:`Blackboard has been updated by another member (version conflict). Refresh and retry.`):Error(s.error||String(o.status))}}else{if(!S.trim()){F(u?`黑板内容不能为空`:`Blackboard content cannot be empty`),A(!1);return}let n=await fetch(i(T(`/api/device-center/rooms/${encodeURIComponent(e)}/blackboard`)),{method:`PUT`,credentials:`same-origin`,headers:{"Content-Type":`application/json`},body:JSON.stringify({title:_.trim()||void 0,content:S,expectedVersion:t})}),r=await n.json().catch(()=>({}));if(!n.ok)throw n.status===409?Error(u?`黑板已被其他成员更新,版本发生冲突,请刷新后重试。`:`Blackboard has been updated by another member (version conflict). Refresh and retry.`):Error(r.error||String(n.status))}g(!1),s?.()}catch(e){F(e?.message||(u?`保存黑板失败`:`Failed to save blackboard`))}finally{A(!1)}},[d,r,S,w,_,e,u,H,B,s]),W=(0,J.useMemo)(()=>d===`all`?r?.content??``:B?.content??``,[d,r?.content,B?.content]),G=r?.updatedAt?new Date(r.updatedAt).toLocaleTimeString(c,{hour:`2-digit`,minute:`2-digit`,second:`2-digit`}):``;return(0,X.jsxs)(`div`,{className:`dg-blackboard-view`,children:[(0,X.jsxs)(`div`,{className:`dg-blackboard-header`,children:[(0,X.jsxs)(`div`,{className:`dg-blackboard-meta`,children:[(0,X.jsx)(`span`,{className:`dg-blackboard-badge`,title:u?`黑板协议版本`:`Protocol version`,children:r?.version?`v${r.version}`:u?`未初始化`:`Initial`}),r?.updatedBy&&(0,X.jsxs)(`span`,{className:`dg-blackboard-updater`,title:u?`最后更新者`:`Last updated by`,children:[(0,X.jsx)(E,{style:{marginRight:4}}),r.updatedBy.name,` (`,r.updatedBy.type===`bot`?`Bot`:u?`人工`:`Human`,`)`]}),G&&(0,X.jsxs)(`span`,{className:`dg-blackboard-time`,title:u?`更新时间`:`Updated at`,children:[(0,X.jsx)(P,{style:{marginRight:4}}),G]})]}),(0,X.jsxs)(`div`,{className:`dg-blackboard-actions`,children:[(0,X.jsxs)(`button`,{type:`button`,className:`btn secondary sm`,onClick:()=>L(W),disabled:!W.trim(),title:u?`复制当前查看的黑板内容`:`Copy current content to clipboard`,children:[I?(0,X.jsx)(t,{style:{color:`var(--green)`,marginRight:4}}):(0,X.jsx)(o,{style:{marginRight:4}}),I?u?`已复制`:`Copied`:u?`复制`:`Copy`]}),p?(0,X.jsxs)(`div`,{className:`dg-edit-btn-group`,children:[(0,X.jsxs)(`button`,{type:`button`,className:`btn secondary sm`,onClick:te,disabled:k,children:[(0,X.jsx)(x,{style:{marginRight:4}}),u?`取消`:`Cancel`]}),(0,X.jsxs)(`button`,{type:`button`,className:`btn primary sm`,onClick:ne,disabled:k||(d===`all`?!S.trim():!w.trim()),children:[k?(0,X.jsx)(h,{className:`spin`,style:{marginRight:4}}):(0,X.jsx)(t,{style:{marginRight:4}}),k?u?`保存中...`:`Saving...`:u?`提交保存`:`Save`]})]}):(0,X.jsxs)(`button`,{type:`button`,className:`btn secondary sm`,onClick:ee,disabled:a,title:u?`编辑黑板内容`:`Edit blackboard content`,children:[(0,X.jsx)(l,{style:{marginRight:4}}),d===`all`?u?`编辑共识`:`Edit All`:u?`编辑此分区`:`Edit Section`]})]})]}),(0,X.jsx)(`div`,{className:`dg-bb-tabs`,role:`tablist`,children:z.map(e=>{let t=d===e.id;return(0,X.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":t,className:`dg-bb-tab ${t?`active`:``}`,onClick:()=>{p&&te(),f(e.id)},children:[e.id===`all`&&(0,X.jsx)(j,{style:{marginRight:4}}),e.id===`architecture`&&(0,X.jsx)(j,{style:{marginRight:4}}),e.id===`contracts`&&(0,X.jsx)(n,{style:{marginRight:4}}),e.id===`progress`&&(0,X.jsx)(M,{style:{marginRight:4}}),e.id===`blockers`&&(0,X.jsx)(D,{style:{marginRight:4}}),(0,X.jsx)(`span`,{children:e.label}),e.count!==void 0&&e.count>0&&(0,X.jsx)(`span`,{className:`dg-bb-tab-dot`})]},e.id)})}),N&&(0,X.jsx)(`div`,{className:`dg-error-banner`,role:`alert`,children:N}),p?(0,X.jsx)(`div`,{className:`dg-blackboard-editor`,children:d===`all`?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`dg-editor-field`,children:[(0,X.jsx)(`label`,{className:`dg-field-label`,children:u?`共识主题 / 标题 (可选)`:`Title / Subject (Optional)`}),(0,X.jsx)(`input`,{type:`text`,className:`dg-input`,placeholder:u?`例如:系统统一重构规范 (RFC-089)`:`e.g. Unified System Redesign RFC`,value:_,onChange:e=>b(e.target.value),maxLength:200,disabled:k})]}),(0,X.jsxs)(`div`,{className:`dg-editor-field`,children:[(0,X.jsxs)(`div`,{className:`dg-field-header`,children:[(0,X.jsx)(`label`,{className:`dg-field-label`,children:u?`结构化 Markdown 全量内容`:`Structured Markdown Content`}),(0,X.jsxs)(`span`,{className:`dg-field-bytes`,children:[new TextEncoder().encode(S).length,` bytes`]})]}),(0,X.jsx)(`textarea`,{className:`dg-textarea`,rows:14,placeholder:u?`# 群组共享共识
|
|
10
|
+
|
|
11
|
+
## 架构设计
|
|
12
|
+
- 统一事件模型
|
|
13
|
+
- 接口规范定义
|
|
14
|
+
|
|
15
|
+
## 任务分工
|
|
16
|
+
- [ ] BotA: 调研接口
|
|
17
|
+
- [ ] BotB: 实现测试`:`# Shared Consensus
|
|
18
|
+
|
|
19
|
+
## Architecture
|
|
20
|
+
- Unified event model
|
|
21
|
+
|
|
22
|
+
## Pipeline
|
|
23
|
+
- [ ] BotA: Draft interfaces`,value:S,onChange:e=>C(e.target.value),disabled:k})]})]}):(0,X.jsxs)(`div`,{className:`dg-editor-field`,children:[(0,X.jsxs)(`div`,{className:`dg-field-header`,children:[(0,X.jsx)(`label`,{className:`dg-field-label`,children:u?`编辑分区:${H?H.titleZh:B?.title||d}`:`Edit Section: ${H?H.titleEn:B?.title||d}`}),(0,X.jsxs)(`span`,{className:`dg-field-bytes`,children:[new TextEncoder().encode(w).length,` bytes`]})]}),(0,X.jsx)(`textarea`,{className:`dg-textarea`,rows:12,placeholder:(e=>{switch(e){case`architecture`:return u?`架构设计与技术栈决策规范
|
|
24
|
+
|
|
25
|
+
例如:
|
|
26
|
+
- 系统分层与目录拓扑
|
|
27
|
+
- 事件模型与状态机规范
|
|
28
|
+
- 核心数据流驱动方式`:`Architecture & System Design
|
|
29
|
+
|
|
30
|
+
e.g.
|
|
31
|
+
- Topology & Layering
|
|
32
|
+
- Event & State Machine
|
|
33
|
+
- Core Data Flow`;case`contracts`:return u?`接口契约与数据模型定义
|
|
34
|
+
|
|
35
|
+
例如:
|
|
36
|
+
- REST / RPC 接口路由与方法
|
|
37
|
+
- 请求入参和响应出参 JSON Schema
|
|
38
|
+
- 错误码与异常契约`:`Interface Contracts & Schemas
|
|
39
|
+
|
|
40
|
+
e.g.
|
|
41
|
+
- Endpoints & Methods
|
|
42
|
+
- Request & Response Schemas
|
|
43
|
+
- Error Codes`;case`progress`:return u?`任务流水线分工与进度追踪
|
|
44
|
+
|
|
45
|
+
例如:
|
|
46
|
+
- [ ] @BotA: 数据层适配与测试
|
|
47
|
+
- [ ] @BotB: 业务层实现
|
|
48
|
+
- [ ] @BotC: 验证与交付物汇总`:`Task Pipeline & Assignments
|
|
49
|
+
|
|
50
|
+
e.g.
|
|
51
|
+
- [ ] @BotA: Data layer
|
|
52
|
+
- [ ] @BotB: Business logic
|
|
53
|
+
- [ ] @BotC: Verification`;case`blockers`:return u?`阻塞卡点与关键技术决策记录 (ADR)
|
|
54
|
+
|
|
55
|
+
例如:
|
|
56
|
+
- 决策:采用 SSE 替代长轮询
|
|
57
|
+
- 阻塞:依赖的设备驱动尚未注册`:`Blockers & Architecture Decision Records (ADR)
|
|
58
|
+
|
|
59
|
+
e.g.
|
|
60
|
+
- Decision: Use SSE instead of polling
|
|
61
|
+
- Blocker: Missing device driver`;default:return u?`在此输入该分区的 Markdown 格式内容...`:`Enter Markdown content for this section...`}})(d),value:w,onChange:e=>O(e.target.value),disabled:k})]})}):(0,X.jsx)(`div`,{className:`dg-blackboard-content`,children:d===`all`?(0,X.jsxs)(X.Fragment,{children:[r?.title&&(0,X.jsx)(`h3`,{className:`dg-blackboard-title`,children:r.title}),r?.content?(0,X.jsx)(`div`,{className:`dg-blackboard-markdown`,children:(0,X.jsx)(V,{text:r.content})}):(0,X.jsxs)(`div`,{className:`dg-blackboard-empty`,children:[(0,X.jsx)(v,{style:{fontSize:32,opacity:.4,marginBottom:8}}),(0,X.jsx)(`p`,{children:u?`当前群组黑板为空。点击右上角“编辑共识”为所有协作 Bot 确立技术架构契约与长期记忆。`:`Blackboard is empty. Click 'Edit All' to set shared contracts and long-term memory.`})]})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`dg-bb-section-header`,children:(0,X.jsx)(`h4`,{className:`dg-bb-section-title`,children:H?u?H.titleZh:H.titleEn:B?.title||d})}),B?.content?(0,X.jsx)(`div`,{className:`dg-blackboard-markdown`,children:(0,X.jsx)(V,{text:B.content})}):(0,X.jsxs)(`div`,{className:`dg-blackboard-empty`,children:[(0,X.jsx)(v,{style:{fontSize:32,opacity:.4,marginBottom:8}}),(0,X.jsx)(`p`,{children:u?`该分区当前尚无记录内容。点击右上角“编辑此分区”快速添加共识与规则。`:`No content in this section yet. Click 'Edit Section' to add consensus and specifications.`})]})]})})]})}var Ne=[{id:`message`,zh:`新群聊消息`,en:`New message`},{id:`task_completed`,zh:`Bot 任务成功完成`,en:`Task completed`},{id:`task_failed`,zh:`Bot 任务执行失败`,en:`Task failed`},{id:`delivery`,zh:`Bot 代码交付提交`,en:`Code delivery`}];function Pe({roomId:e,disabled:n=!1}){let{locale:a}=y(),s=m(a),[l,d]=(0,J.useState)([]),[p,g]=(0,J.useState)(!0),[v,x]=(0,J.useState)(``),[S,w]=(0,J.useState)(!1),[E,D]=(0,J.useState)(null),[O,j]=(0,J.useState)(``),[M,N]=(0,J.useState)(``),[P,F]=(0,J.useState)(!1),[I,L]=(0,J.useState)(``),[R,z]=(0,J.useState)(!1),[B,V]=(0,J.useState)(`hub`),[H,U]=(0,J.useState)(null),[ee,te]=(0,J.useState)(null),[ne,W]=(0,J.useState)(null),G=(0,J.useRef)(null),K=async()=>{G.current&&G.current.abort();let t=new AbortController;G.current=t;try{x(``);let[n,r,a]=await Promise.all([fetch(i(T(`/api/device-center/rooms/${encodeURIComponent(e)}/webhooks`)),{signal:t.signal}),fetch(i(T(`/api/device-center/rooms/${encodeURIComponent(e)}`)),{signal:t.signal}).catch(()=>null),fetch(i(T(`/api/device-center/status`)),{signal:t.signal}).catch(()=>null)]);if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.error||`HTTP ${n.status}`)}let o=await n.json();if(d(o.webhooks||[]),r&&r.ok){let e=(await r.json()).room?.hubRelayBaseUrl||``;N(e),L(e)}if(a&&a.ok){let e=await a.json();e.hubUrl&&j(e.hubUrl)}}catch(e){t.signal.aborted||x(e?.message||(s?`加载 Webhooks 失败`:`Failed to load webhooks`))}finally{t.signal.aborted||g(!1)}};(0,J.useEffect)(()=>(g(!0),K(),()=>{G.current&&G.current.abort()}),[e]);let re=M||O||window.location.origin,q=async()=>{z(!0),x(``);try{let t=await fetch(i(T(`/api/device-center/rooms/${encodeURIComponent(e)}/hub-relay`)),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({hubRelayBaseUrl:I.trim()||null})});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error||`Failed to update Hub relay base URL`)}N(I.trim()),F(!1)}catch(e){x(e?.message||`Failed to save Hub relay URL`)}finally{z(!1)}},ie=(e,t)=>{navigator.clipboard.writeText(e),U(t),setTimeout(()=>U(null),2e3)},ae=async t=>{try{let n=await fetch(i(T(`/api/device-center/rooms/${encodeURIComponent(e)}/webhooks/${encodeURIComponent(t.id)}`)),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({enabled:!t.enabled})});if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.error||`Update failed`)}await K()}catch(e){x(e?.message||`Failed to update webhook`)}},oe=async t=>{if(window.confirm(s?`确定要删除该 Webhook 吗?`:`Are you sure you want to delete this webhook?`))try{let n=await fetch(i(T(`/api/device-center/rooms/${encodeURIComponent(e)}/webhooks/${encodeURIComponent(t)}/delete`)),{method:`POST`});if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.error||`Delete failed`)}await K()}catch(e){x(e?.message||`Failed to delete webhook`)}},se=async t=>{if(window.confirm(s?`重新生成 Token 将使旧 Token 立即失效,依赖此 URL 的外部服务需要同步更新。确定重新生成?`:`Regenerating the token will invalidate the old one immediately. Continue?`))try{let n=await fetch(i(T(`/api/device-center/rooms/${encodeURIComponent(e)}/webhooks/${encodeURIComponent(t)}/regenerate-token`)),{method:`POST`});if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.error||`Regenerate failed`)}await K()}catch(e){x(e?.message||`Failed to regenerate token`)}},ce=async t=>{te(t.id),W(null);try{let n=await fetch(i(T(`/api/device-center/rooms/${encodeURIComponent(e)}/webhooks/${encodeURIComponent(t.id)}/test`)),{method:`POST`}),r=await n.json().catch(()=>({}));if(n.ok&&r.success){let e=t.relayViaHub===!1?``:s?` [Hub中转]`:` [via Hub]`;W({id:t.id,success:!0,message:s?`推送成功${e} (HTTP ${r.status??200})`:`Delivered successfully${e} (HTTP ${r.status??200})`})}else W({id:t.id,success:!1,message:r.error||(s?`推送测试失败`:`Test failed`)})}catch(e){W({id:t.id,success:!1,message:e?.message||`Network request failed`})}finally{te(null)}},Y=l.filter(e=>e.type===`incoming`),le=l.filter(e=>e.type===`outgoing`);return(0,X.jsxs)(`div`,{className:`group-webhooks-container`,children:[(0,X.jsxs)(`div`,{className:`group-webhooks-header`,children:[(0,X.jsx)(`div`,{className:`group-webhooks-desc`,children:(0,X.jsx)(`p`,{children:s?`群组 Webhook 支持双向通信与可选 Hub 中转:入站可使用公网 Hub 中转地址接收外部事件唤醒 Bot;出站通知可选由 Hub 服务端中转代发。`:`Two-way Webhooks with optional Hub relay: incoming uses Hub public relay endpoints, outgoing supports relaying via Hub.`})}),(0,X.jsxs)(`button`,{type:`button`,className:`btn primary group-webhooks-add-btn`,disabled:n,onClick:()=>{D(null),w(!0)},children:[(0,X.jsx)(r,{}),(0,X.jsx)(`span`,{children:s?`新建 Webhook`:`Add Webhook`})]})]}),v&&(0,X.jsxs)(`div`,{className:`group-webhooks-error-banner`,role:`alert`,children:[(0,X.jsx)(b,{}),(0,X.jsx)(`span`,{children:v})]}),(0,X.jsxs)(`div`,{className:`group-webhook-relay-bar`,children:[(0,X.jsxs)(`div`,{className:`group-webhook-relay-info`,children:[(0,X.jsx)(k,{className:`icon-hub`}),(0,X.jsxs)(`div`,{className:`group-webhook-relay-text`,children:[(0,X.jsx)(`strong`,{children:s?`Hub 中转基准地址:`:`Hub Relay Base URL:`}),(0,X.jsx)(`code`,{children:re}),M&&(0,X.jsx)(`span`,{className:`badge-custom`,children:s?`自定义`:`Custom`})]})]}),(0,X.jsxs)(`button`,{type:`button`,className:`btn secondary sm`,onClick:()=>F(!P),title:s?`配置自定义 Hub 中转基准域名`:`Configure Hub relay base URL`,children:[(0,X.jsx)(u,{}),(0,X.jsx)(`span`,{children:s?`设置中转域名`:`Relay URL`})]})]}),P&&(0,X.jsx)(`div`,{className:`group-webhook-relay-config-box`,children:(0,X.jsxs)(`div`,{className:`group-webhook-relay-config-fields`,children:[(0,X.jsx)(`label`,{children:s?`若 Hub 位于公网反向代理或具有独立域名,请输入对外公开的完整基准地址(如 https://hub.example.com):`:`Specify the public Hub URL (e.g. https://hub.example.com) if behind a reverse proxy:`}),(0,X.jsxs)(`div`,{className:`group-webhook-relay-input-row`,children:[(0,X.jsx)(`input`,{type:`url`,className:`input`,placeholder:`https://hub.example.com`,value:I,onChange:e=>L(e.target.value)}),(0,X.jsx)(`button`,{type:`button`,className:`btn primary sm`,disabled:R,onClick:q,children:R?s?`保存中…`:`Saving...`:s?`保存中转地址`:`Save`}),M&&(0,X.jsx)(`button`,{type:`button`,className:`btn secondary sm`,disabled:R,onClick:()=>{L(``),q()},children:s?`重置`:`Reset`})]})]})}),p?(0,X.jsx)(`div`,{className:`group-webhooks-loading`,children:s?`正在加载 Webhook 列表…`:`Loading webhooks...`}):l.length===0?(0,X.jsxs)(`div`,{className:`group-webhooks-empty`,children:[(0,X.jsx)(`div`,{className:`group-webhooks-empty-icon`,children:`🔗`}),(0,X.jsx)(`h4`,{children:s?`暂未配置群组 Webhook`:`No Webhooks Configured`}),(0,X.jsx)(`p`,{children:s?`点击上方「新建 Webhook」创建入站或出站自动化集成。`:`Click 'Add Webhook' above to create incoming or outgoing automations.`})]}):(0,X.jsxs)(`div`,{className:`group-webhooks-list`,children:[Y.length>0&&(0,X.jsxs)(`div`,{className:`group-webhooks-section`,children:[(0,X.jsxs)(`div`,{className:`group-webhooks-section-header`,children:[(0,X.jsxs)(`h4`,{className:`group-webhooks-section-title`,children:[(0,X.jsx)(A,{className:`icon-incoming`}),(0,X.jsx)(`span`,{children:s?`入站 Webhook (Incoming)`:`Incoming Webhooks`}),(0,X.jsx)(`span`,{className:`badge`,children:Y.length})]}),(0,X.jsxs)(`div`,{className:`group-webhook-mode-toggle`,title:s?`选择生成中转还是直连地址`:`Select address mode`,children:[(0,X.jsxs)(`button`,{type:`button`,className:`mode-btn ${B===`hub`?`active`:``}`,onClick:()=>V(`hub`),children:[`🌐 `,s?`Hub 中转地址`:`Hub Relay`]}),(0,X.jsxs)(`button`,{type:`button`,className:`mode-btn ${B===`direct`?`active`:``}`,onClick:()=>V(`direct`),children:[`💻 `,s?`本地直连地址`:`Direct`]})]})]}),(0,X.jsx)(`div`,{className:`group-webhooks-cards`,children:Y.map(r=>{let i=`${B===`hub`?re:window.location.origin}/api/rooms/${e}/webhooks/incoming/${r.id}?token=${r.token}`,a=`curl -X POST "${i}" -H "Content-Type: application/json" -d '{"text":"Hello from Webhook","senderName":"${r.name}"}'`;return(0,X.jsxs)(`div`,{className:`group-webhook-card ${r.enabled?`enabled`:`disabled`}`,children:[(0,X.jsxs)(`div`,{className:`group-webhook-card-header`,children:[(0,X.jsxs)(`div`,{className:`group-webhook-name-box`,children:[(0,X.jsx)(`strong`,{className:`group-webhook-name`,children:r.name}),(0,X.jsx)(`span`,{className:`group-webhook-badge ${r.enabled?`badge-active`:`badge-inactive`}`,children:r.enabled?s?`已启用`:`Active`:s?`已暂停`:`Disabled`}),(0,X.jsx)(`span`,{className:`group-webhook-badge badge-relay`,children:B===`hub`?s?`🌐 Hub中转`:`🌐 Hub Relay`:s?`💻 本机直连`:`💻 Direct`}),r.allowBotTrigger!==!1&&(0,X.jsx)(`span`,{className:`group-webhook-badge badge-info`,title:s?`收到外部消息时自动触发群主管或被 @ 的 Bot`:`Triggers Bot execution`,children:s?`可唤醒 Bot`:`Triggers Bot`})]}),(0,X.jsxs)(`div`,{className:`group-webhook-actions`,children:[(0,X.jsx)(`button`,{type:`button`,className:`btn-icon-subtle`,title:s?`编辑`:`Edit`,disabled:n,onClick:()=>{D(r),w(!0)},children:(0,X.jsx)(_,{})}),(0,X.jsx)(`button`,{type:`button`,className:`btn-icon-subtle danger`,title:s?`删除`:`Delete`,disabled:n,onClick:()=>oe(r.id),children:(0,X.jsx)(C,{})}),(0,X.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":r.enabled,className:`set-switch ${r.enabled?`on`:``}`,disabled:n,onClick:()=>ae(r),title:s?`启用/禁用切换`:`Toggle status`,children:(0,X.jsx)(`span`,{className:`set-switch-knob`})})]})]}),(0,X.jsxs)(`div`,{className:`group-webhook-field`,children:[(0,X.jsxs)(`label`,{children:[s?`Webhook 入站地址:`:`Webhook URL:`,(0,X.jsxs)(`span`,{className:`mode-indicator`,children:[`(`,B===`hub`?s?`外部经 Hub 中转打入`:`Forwarded via Hub`:s?`本地端口直通`:`Direct access`,`)`]})]}),(0,X.jsxs)(`div`,{className:`group-webhook-url-row`,children:[(0,X.jsx)(`code`,{className:`group-webhook-code`,children:i}),(0,X.jsxs)(`button`,{type:`button`,className:`btn secondary sm`,title:s?`复制 URL`:`Copy URL`,onClick:()=>ie(i,`url-${r.id}`),children:[H===`url-${r.id}`?(0,X.jsx)(t,{}):(0,X.jsx)(o,{}),(0,X.jsx)(`span`,{children:H===`url-${r.id}`?s?`已复制`:`Copied`:s?`复制`:`Copy`})]}),(0,X.jsx)(`button`,{type:`button`,className:`btn secondary sm`,title:s?`重新生成安全凭证 Token`:`Regenerate Token`,disabled:n,onClick:()=>se(r.id),children:(0,X.jsx)(h,{})})]})]}),(0,X.jsxs)(`div`,{className:`group-webhook-field`,children:[(0,X.jsx)(`label`,{children:s?`调用示例 (cURL):`:`cURL Example:`}),(0,X.jsxs)(`div`,{className:`group-webhook-curl-box`,children:[(0,X.jsx)(`code`,{children:a}),(0,X.jsx)(`button`,{type:`button`,className:`btn-icon-subtle`,title:s?`复制 cURL`:`Copy cURL`,onClick:()=>ie(a,`curl-${r.id}`),children:H===`curl-${r.id}`?(0,X.jsx)(t,{}):(0,X.jsx)(o,{})})]})]})]},r.id)})})]}),le.length>0&&(0,X.jsxs)(`div`,{className:`group-webhooks-section`,children:[(0,X.jsxs)(`h4`,{className:`group-webhooks-section-title`,children:[(0,X.jsx)(f,{className:`icon-outgoing`}),(0,X.jsx)(`span`,{children:s?`出站 Webhook (Outgoing)`:`Outgoing Webhooks`}),(0,X.jsx)(`span`,{className:`badge`,children:le.length})]}),(0,X.jsx)(`div`,{className:`group-webhooks-cards`,children:le.map(e=>{let r=ee===e.id,i=ne?.id===e.id?ne:null,a=e.relayViaHub!==!1;return(0,X.jsxs)(`div`,{className:`group-webhook-card ${e.enabled?`enabled`:`disabled`}`,children:[(0,X.jsxs)(`div`,{className:`group-webhook-card-header`,children:[(0,X.jsxs)(`div`,{className:`group-webhook-name-box`,children:[(0,X.jsx)(`strong`,{className:`group-webhook-name`,children:e.name}),(0,X.jsx)(`span`,{className:`group-webhook-badge ${e.enabled?`badge-active`:`badge-inactive`}`,children:e.enabled?s?`已启用`:`Active`:s?`已暂停`:`Disabled`}),(0,X.jsx)(`span`,{className:`group-webhook-badge ${a?`badge-relay`:`badge-direct`}`,title:a?s?`由 Hub 服务器统一代理出网外发`:`Relayed via Hub server`:s?`由本地设备节点直连外发`:`Direct connection from device`,children:a?s?`🌐 Hub中转代发`:`🌐 Hub Relay`:s?`💻 本地直连外发`:`💻 Direct Outbound`}),e.secret?(0,X.jsx)(`span`,{className:`group-webhook-badge badge-secret`,title:s?`已配置 HMAC-SHA256 签名校验密钥`:`HMAC secret configured`,children:s?`带签名`:`Signed`}):null]}),(0,X.jsxs)(`div`,{className:`group-webhook-actions`,children:[(0,X.jsxs)(`button`,{type:`button`,className:`btn secondary sm`,disabled:n||r,onClick:()=>ce(e),title:s?`向目标地址发送一条测试 Ping`:`Send test ping`,children:[(0,X.jsx)(c,{}),(0,X.jsx)(`span`,{children:r?s?`测试中…`:`Testing...`:s?`测试`:`Test`})]}),(0,X.jsx)(`button`,{type:`button`,className:`btn-icon-subtle`,title:s?`编辑`:`Edit`,disabled:n,onClick:()=>{D(e),w(!0)},children:(0,X.jsx)(_,{})}),(0,X.jsx)(`button`,{type:`button`,className:`btn-icon-subtle danger`,title:s?`删除`:`Delete`,disabled:n,onClick:()=>oe(e.id),children:(0,X.jsx)(C,{})}),(0,X.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":e.enabled,className:`set-switch ${e.enabled?`on`:``}`,disabled:n,onClick:()=>ae(e),title:s?`启用/禁用切换`:`Toggle status`,children:(0,X.jsx)(`span`,{className:`set-switch-knob`})})]})]}),(0,X.jsxs)(`div`,{className:`group-webhook-field`,children:[(0,X.jsx)(`label`,{children:s?`目标推送 URL:`:`Target URL:`}),(0,X.jsx)(`code`,{className:`group-webhook-code`,children:e.url})]}),(0,X.jsxs)(`div`,{className:`group-webhook-field`,children:[(0,X.jsx)(`label`,{children:s?`订阅事件:`:`Subscribed Events:`}),(0,X.jsx)(`div`,{className:`group-webhook-event-chips`,children:(e.events||[`message`,`task_completed`,`task_failed`,`delivery`]).map(e=>{let t=Ne.find(t=>t.id===e);return(0,X.jsx)(`span`,{className:`group-webhook-event-chip`,children:t?s?t.zh:t.en:e},e)})})]}),i&&(0,X.jsxs)(`div`,{className:`group-webhook-test-result ${i.success?`success`:`failed`}`,children:[i.success?(0,X.jsx)(t,{}):(0,X.jsx)(b,{}),(0,X.jsx)(`span`,{children:i.message})]})]},e.id)})})]})]}),S&&(0,X.jsx)(Fe,{roomId:e,webhook:E,onClose:()=>{w(!1),D(null)},onSaved:async()=>{w(!1),D(null),await K()}})]})}function Fe({roomId:e,webhook:t,onClose:n,onSaved:r}){let{locale:a}=y(),o=m(a),s=!!t,[c,l]=(0,J.useState)(t?.name||``),[u,d]=(0,J.useState)(t?.type||`incoming`),[f,p]=(0,J.useState)(!t||t.enabled),[h,g]=(0,J.useState)(!t||t.allowBotTrigger!==!1),[_,v]=(0,J.useState)(!t||t.relayViaHub!==!1),[x,S]=(0,J.useState)(t?.url||``),[C,w]=(0,J.useState)(t?.secret||``),[E,D]=(0,J.useState)(t?.events||[`message`,`task_completed`,`task_failed`,`delivery`]),[O,k]=(0,J.useState)(!1),[A,j]=(0,J.useState)(``),M=async n=>{if(n.preventDefault(),!c.trim()){j(o?`请输入 Webhook 名称`:`Name is required`);return}if(u===`outgoing`&&(!x.trim()||!/^https?:\/\/.+/i.test(x.trim()))){j(o?`请输入有效的 http:// 或 https:// 目标地址`:`Valid HTTP/HTTPS URL is required`);return}k(!0),j(``);try{let n={name:c.trim(),enabled:f};s||(n.type=u),u===`incoming`?n.allowBotTrigger=h:(n.url=x.trim(),n.secret=C.trim()||void 0,n.events=E,n.relayViaHub=_);let a=s?`/api/device-center/rooms/${encodeURIComponent(e)}/webhooks/${encodeURIComponent(t.id)}`:`/api/device-center/rooms/${encodeURIComponent(e)}/webhooks`,o=await fetch(i(T(a)),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(n)});if(!o.ok){let e=await o.json().catch(()=>({}));throw Error(e.error||`Save failed`)}r()}catch(e){j(e?.message||`Failed to save webhook`)}finally{k(!1)}},N=e=>{if(E.includes(e)){if(E.length===1)return;D(E.filter(t=>t!==e))}else D([...E,e])};return(0,X.jsx)(`div`,{className:`modal-backdrop`,onClick:n,children:(0,X.jsxs)(`div`,{className:`group-webhook-modal-dialog`,onClick:e=>e.stopPropagation(),role:`dialog`,"aria-modal":`true`,children:[(0,X.jsxs)(`div`,{className:`gwm-header`,children:[(0,X.jsxs)(`div`,{className:`gwm-title-box`,children:[(0,X.jsxs)(`h3`,{children:[(0,X.jsx)(`span`,{className:`gwm-title-icon`,children:`🔗`}),` `,s?o?`编辑 Webhook`:`Edit Webhook`:o?`新建 Webhook`:`New Webhook`]}),(0,X.jsx)(`p`,{className:`gwm-subtitle`,children:o?`配置入站自动化触发或出站事件广播通知`:`Configure incoming automations or outgoing event notifications`})]}),(0,X.jsx)(`button`,{type:`button`,className:`gwm-close-btn`,onClick:n,"aria-label":o?`关闭`:`Close`,title:o?`关闭`:`Close`,children:`✕`})]}),(0,X.jsxs)(`form`,{onSubmit:M,children:[(0,X.jsxs)(`div`,{className:`gwm-body`,children:[A&&(0,X.jsxs)(`div`,{className:`group-webhooks-error-banner`,role:`alert`,children:[(0,X.jsx)(b,{}),(0,X.jsx)(`span`,{children:A})]}),!s&&(0,X.jsxs)(`div`,{className:`gwm-form-group`,children:[(0,X.jsx)(`label`,{className:`gwm-label`,children:o?`集成类型`:`Integration Type`}),(0,X.jsxs)(`div`,{className:`gwm-type-cards`,children:[(0,X.jsxs)(`div`,{className:`gwm-type-card ${u===`incoming`?`selected`:``}`,onClick:()=>d(`incoming`),role:`button`,tabIndex:0,children:[(0,X.jsx)(`span`,{className:`gwm-type-check`,children:`✓`}),(0,X.jsxs)(`div`,{className:`gwm-type-card-head`,children:[(0,X.jsx)(`span`,{className:`gwm-type-icon incoming`,children:`📥`}),(0,X.jsx)(`span`,{className:`gwm-type-name`,children:o?`入站 Webhook`:`Incoming Webhook`})]}),(0,X.jsx)(`p`,{className:`gwm-type-desc`,children:o?`外部系统推送消息进群,可自动指派或唤醒群内 Bot 执行任务`:`External services push messages to this group & trigger Bots`})]}),(0,X.jsxs)(`div`,{className:`gwm-type-card ${u===`outgoing`?`selected`:``}`,onClick:()=>d(`outgoing`),role:`button`,tabIndex:0,children:[(0,X.jsx)(`span`,{className:`gwm-type-check`,children:`✓`}),(0,X.jsxs)(`div`,{className:`gwm-type-card-head`,children:[(0,X.jsx)(`span`,{className:`gwm-type-icon outgoing`,children:`📤`}),(0,X.jsx)(`span`,{className:`gwm-type-name`,children:o?`出站 Webhook`:`Outgoing Webhook`})]}),(0,X.jsx)(`p`,{className:`gwm-type-desc`,children:o?`将新消息、任务完成、失败或交付等事件实时推送至外部服务`:`Forward messages, task completions, and deliveries to external endpoints`})]})]})]}),(0,X.jsxs)(`div`,{className:`gwm-form-group`,children:[(0,X.jsx)(`label`,{htmlFor:`webhook-name`,className:`gwm-label`,children:o?`Webhook 名称`:`Webhook Name`}),(0,X.jsx)(`input`,{id:`webhook-name`,type:`text`,className:`gwm-input`,placeholder:o?`例如:GitHub Actions CI、监控告警、飞书群通知`:`e.g. GitHub Actions CI, Sentry Alerts`,value:c,maxLength:80,onChange:e=>l(e.target.value),autoFocus:!0})]}),u===`incoming`?(0,X.jsxs)(`div`,{className:`gwm-switch-row`,onClick:()=>g(!h),children:[(0,X.jsxs)(`div`,{className:`gwm-switch-text`,children:[(0,X.jsx)(`span`,{className:`gwm-switch-title`,children:o?`收到外部推送时唤醒 Bot 执行任务`:`Allow incoming messages to trigger Bots`}),(0,X.jsx)(`span`,{className:`gwm-switch-desc`,children:o?`检测到消息包含 @Bot 或群组设有群主管时,自动生成任务派发`:`Triggers coordinator or mentioned Bots automatically`})]}),(0,X.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":h,className:`set-switch ${h?`on`:``}`,onClick:e=>{e.stopPropagation(),g(!h)},children:(0,X.jsx)(`span`,{className:`set-switch-knob`})})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`gwm-form-group`,children:[(0,X.jsx)(`label`,{htmlFor:`webhook-url`,className:`gwm-label`,children:o?`目标推送 URL`:`Target Endpoint URL`}),(0,X.jsx)(`input`,{id:`webhook-url`,type:`url`,className:`gwm-input`,placeholder:`https://example.com/webhook/endpoint`,value:x,onChange:e=>S(e.target.value)}),(0,X.jsx)(`span`,{className:`gwm-field-hint`,children:o?`事件触发时,系统将以 HTTP POST 发送 JSON 格式载荷至此地址。`:`Delivered as HTTP POST with JSON content.`})]}),(0,X.jsxs)(`div`,{className:`gwm-switch-row`,onClick:()=>v(!_),children:[(0,X.jsxs)(`div`,{className:`gwm-switch-text`,children:[(0,X.jsx)(`span`,{className:`gwm-switch-title`,children:o?`通过 Hub 服务端中转代发 (Relay via Hub)`:`Relay via Hub Server`}),(0,X.jsx)(`span`,{className:`gwm-switch-desc`,children:o?`由 Hub 服务器统一作为代理外发通知(固定出口 IP);若目标是局域网私有地址请关闭`:`Dispatched centrally by Hub. Uncheck if target is internal LAN address.`})]}),(0,X.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":_,className:`set-switch ${_?`on`:``}`,onClick:e=>{e.stopPropagation(),v(!_)},children:(0,X.jsx)(`span`,{className:`set-switch-knob`})})]}),(0,X.jsxs)(`div`,{className:`gwm-form-group`,children:[(0,X.jsx)(`label`,{htmlFor:`webhook-secret`,className:`gwm-label`,children:o?`签名密钥 Secret(可选)`:`HMAC Secret (Optional)`}),(0,X.jsx)(`input`,{id:`webhook-secret`,type:`text`,className:`gwm-input`,placeholder:o?`可选密钥,用于生成 X-Pi-Signature 请求头防篡改校验`:`Optional secret used for X-Pi-Signature header`,value:C,maxLength:256,onChange:e=>w(e.target.value)})]}),(0,X.jsxs)(`div`,{className:`gwm-form-group`,children:[(0,X.jsx)(`label`,{className:`gwm-label`,children:o?`订阅事件`:`Subscribed Events`}),(0,X.jsx)(`div`,{className:`gwm-events-grid`,children:Ne.map(e=>(0,X.jsxs)(`div`,{className:`gwm-event-chip ${E.includes(e.id)?`active`:``}`,onClick:()=>N(e.id),children:[(0,X.jsx)(`span`,{className:`gwm-chip-box`,children:E.includes(e.id)?`✓`:``}),(0,X.jsx)(`span`,{children:o?e.zh:e.en})]},e.id))})]})]}),(0,X.jsxs)(`div`,{className:`gwm-switch-row`,onClick:()=>p(!f),children:[(0,X.jsxs)(`div`,{className:`gwm-switch-text`,children:[(0,X.jsx)(`span`,{className:`gwm-switch-title`,children:o?`立即启用该 Webhook`:`Enable this Webhook`}),(0,X.jsx)(`span`,{className:`gwm-switch-desc`,children:o?`创建完成后立即生效并接受/分发事件`:`Active immediately upon save`})]}),(0,X.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":f,className:`set-switch ${f?`on`:``}`,onClick:e=>{e.stopPropagation(),p(!f)},children:(0,X.jsx)(`span`,{className:`set-switch-knob`})})]})]}),(0,X.jsxs)(`div`,{className:`gwm-footer`,children:[(0,X.jsx)(`button`,{type:`button`,className:`btn secondary`,onClick:n,disabled:O,children:o?`取消`:`Cancel`}),(0,X.jsx)(`button`,{type:`submit`,className:`btn primary`,disabled:O,children:O?o?`保存中…`:`Saving...`:s?o?`保存修改`:`Save Changes`:o?`创建 Webhook`:`Create Webhook`})]})]})]})})}var Ie=()=>{},Le=(0,J.memo)(function({isOpen:e,activeTab:t,onClose:n,roomId:r,detail:i,devices:a,members:o,conversations:s,attentionCount:c,disabled:l,conversationError:u,onRefreshGroup:d,onRefreshConversations:f}){let{locale:p}=y(),h=m(p);if((0,J.useEffect)(()=>{if(!e)return;let t=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,n]),!e)return null;let g={blackboard:{icon:`📋`,title:h?`群组共享共识黑板`:`Group Shared Blackboard`,badge:i?.room.blackboard?.version},deliveries:{icon:`📦`,title:h?`交付与待办事项`:`Deliveries & Attention`,badge:c>0?c:s.length>0?s.length:void 0},transfers:{icon:`📁`,title:h?`跨机大文件传输与断点续传`:`Cross-Device File Transfers`},canvas:{icon:`🎨`,title:h?`群画布工作流`:`Group Canvas Workflow`},presets:{icon:`🤖`,title:h?`Bot 预设与规则配置`:`Bot Presets & Settings`},bots:{icon:`👥`,title:h?`群协作 Bot 成员清单`:`Collaborating Bots`,badge:o.length},webhooks:{icon:`🔗`,title:h?`群组 Webhook 集成`:`Group Webhooks`,badge:i?.room.webhooks?.filter(e=>e.enabled).length}}[t]||{icon:`📦`,title:h?`群协同`:`Collaboration`};return(0,X.jsxs)(`div`,{className:`group-drawer-overlay`,role:`dialog`,"aria-modal":`true`,"aria-label":g.title,children:[(0,X.jsx)(`div`,{className:`group-drawer-backdrop`,onClick:n,"aria-hidden":!0}),(0,X.jsxs)(`aside`,{className:`group-drawer-panel`,onClick:e=>e.stopPropagation(),children:[(0,X.jsxs)(`div`,{className:`group-drawer-header`,children:[(0,X.jsxs)(`div`,{className:`group-drawer-title-box`,children:[(0,X.jsx)(`span`,{className:`group-drawer-title-icon`,children:g.icon}),(0,X.jsx)(`h3`,{className:`group-drawer-title`,children:g.title}),g.badge!==void 0&&g.badge>0&&(0,X.jsx)(`span`,{className:`group-drawer-badge ${t===`deliveries`&&c>0?`attention`:``}`,children:g.badge})]}),(0,X.jsx)(`button`,{type:`button`,className:`btn group-drawer-close-btn`,onClick:n,title:h?`关闭抽屉 (Esc)`:`Close Drawer (Esc)`,"aria-label":h?`关闭`:`Close`,children:(0,X.jsx)(x,{})})]}),(0,X.jsxs)(`div`,{className:`group-drawer-body`,children:[t===`blackboard`&&(0,X.jsx)(`div`,{className:`group-drawer-pane`,children:(0,X.jsx)(Me,{roomId:r,blackboard:i?.room.blackboard,disabled:l,onSaved:d??Ie})}),t===`deliveries`&&(0,X.jsx)(`div`,{className:`group-drawer-pane`,children:(0,X.jsx)(fe,{roomId:r,conversations:s,bots:a,disabled:l,error:u,onRefresh:f})}),t===`transfers`&&(0,X.jsx)(`div`,{className:`group-drawer-pane`,children:(0,X.jsx)(be,{roomId:r,bots:a,disabled:l})}),t===`canvas`&&(0,X.jsx)(`div`,{className:`group-drawer-pane`,children:(0,X.jsx)(Te,{roomId:r,binding:i?.room.canvasBinding,onSaved:d??Ie})}),t===`presets`&&(0,X.jsx)(`div`,{className:`group-drawer-pane`,children:(0,X.jsx)(De,{bots:o,onSaved:d??Ie})}),t===`webhooks`&&(0,X.jsx)(`div`,{className:`group-drawer-pane`,children:(0,X.jsx)(Pe,{roomId:r,disabled:l})}),t===`bots`&&(0,X.jsxs)(`div`,{className:`group-drawer-pane group-members-overview`,children:[(0,X.jsxs)(`div`,{className:`grp-section-title`,children:[(0,X.jsx)(`span`,{children:h?`群协作 Bot 成员清单`:`Collaborating Bots`}),(0,X.jsxs)(`span`,{className:`grp-count`,children:[`(`,o.length,`)`]})]}),(0,X.jsx)(`div`,{className:`grp-bot-list`,children:o.map(e=>(0,X.jsxs)(`div`,{className:`grp-bot-card`,children:[(0,X.jsxs)(`div`,{className:`grp-bot-card-top`,children:[(0,X.jsxs)(`div`,{className:`grp-bot-title`,children:[(0,X.jsx)(`span`,{className:`grp-bot-indicator ${e.online===!1?`offline`:`online`}`}),(0,X.jsx)(`strong`,{children:e.name}),e.id===i?.room.primaryBotId&&(0,X.jsx)(`span`,{className:`grp-primary-badge`,children:h?`主协调`:`Primary`})]}),(0,X.jsx)(`span`,{className:`grp-bot-status-text`,children:e.online===!1?h?`离线`:`Offline`:h?`在线就绪`:`Online Ready`})]}),(0,X.jsxs)(`div`,{className:`grp-bot-info`,children:[e.deviceName&&(0,X.jsxs)(`div`,{className:`grp-bot-device`,children:[(0,X.jsxs)(`span`,{children:[`🖥 `,h?`设备: `:`Device: `]}),(0,X.jsx)(`code`,{children:e.deviceName})]}),(0,X.jsxs)(`div`,{className:`grp-bot-id`,children:[(0,X.jsx)(`span`,{children:`ID: `}),(0,X.jsx)(`code`,{title:e.id,children:e.id})]})]}),e.tools&&e.tools.length>0&&(0,X.jsxs)(`div`,{className:`grp-bot-tools`,children:[(0,X.jsx)(`span`,{className:`grp-tools-label`,children:h?`授权工具: `:`Tools: `}),(0,X.jsx)(`div`,{className:`grp-tools-chips`,children:e.tools.map(e=>(0,X.jsx)(`span`,{className:`grp-tool-chip`,children:e},e))})]})]},e.id))})]})]})]})]})}),Re=[{id:`summarize-finish`,labelZh:`直接汇总当前阶段产物并结束`,labelEn:`Summarize & Finish`,textZh:`直接汇总当前阶段产物并结束,保留关键交付物与验证结论。`,textEn:`Directly summarize current phase deliverables and finish, retaining key evidence and conclusions.`},{id:`check-types`,labelZh:`优先检查并补充类型声明`,labelEn:`Prioritize Types`,textZh:`优先检查并补充缺失的类型声明,确保 strict typecheck 零错误。`,textEn:`Prioritize checking and adding type declarations to ensure zero typecheck errors.`},{id:`self-test`,labelZh:`先进行自测并展示通过证据`,labelEn:`Self-test & Show Evidence`,textZh:`先进行自测并展示通过证据,包括具体的测试用例与终端运行输出。`,textEn:`Run self-tests first and present verification evidence including test cases and terminal output.`},{id:`concise-report`,labelZh:`精简输出与风险`,labelEn:`Concise Output & Risks`,textZh:`精简后续输出,跳过冗余细节,仅汇报核心变更、未决风险与阻碍项。`,textEn:`Keep subsequent output concise; report only core changes, unresolved risks, and blockers.`}];function ze({task:e,botName:n,deviceName:r,onClose:i,onSubmit:o}){let{locale:c}=y(),l=m(c),[u,d]=(0,J.useState)(``),[f,p]=(0,J.useState)(!1),[g,_]=(0,J.useState)(null),v=(0,J.useRef)(null);(0,J.useEffect)(()=>{v.current?.focus()},[]);let x=(0,J.useCallback)(e=>{let t=l?e.textZh:e.textEn;d(e=>e.trim()?`${e.trim()}\n${t}`:t),v.current?.focus()},[l]),S=(0,J.useCallback)(async()=>{let e=u.trim();if(!e){_(l?`请输入转向纠偏指令`:`Please enter steering instruction`);return}p(!0),_(null);try{await o(e),i()}catch(e){_(e?.message||(l?`注入转向指令失败`:`Failed to inject steering instruction`))}finally{p(!1)}},[u,o,i,l]),C=(0,J.useCallback)(e=>{(e.ctrlKey||e.metaKey)&&e.key===`Enter`&&(e.preventDefault(),S())},[S]),w=ee(e.text),T=n||e.botId,E=r||e.deviceId;return(0,X.jsx)(te,{open:!0,onClose:i,title:l?`任务飞行中实时转向 (In-flight Steering)`:`In-flight Task Steering`,icon:(0,X.jsx)(a,{className:`dg-steer-icon`}),className:`dg-steer-modal`,children:(0,X.jsxs)(`div`,{className:`dg-steer-body`,children:[(0,X.jsxs)(`div`,{className:`dg-steer-target-card`,children:[(0,X.jsxs)(`div`,{className:`dg-steer-target-header`,children:[(0,X.jsxs)(`div`,{className:`dg-steer-bot-badge`,children:[(0,X.jsx)(s,{style:{marginRight:4}}),(0,X.jsxs)(`strong`,{children:[`@`,T]})]}),E&&(0,X.jsx)(`span`,{className:`dg-steer-device-name`,title:l?`目标设备`:`Target Device`,children:E}),(0,X.jsxs)(`span`,{className:`dg-steer-task-id`,title:e.id,children:[`#`,e.id.slice(0,8)]})]}),(0,X.jsxs)(`div`,{className:`dg-steer-target-text`,title:w,children:[(0,X.jsx)(`span`,{className:`dg-steer-text-label`,children:l?`当前目标:`:`Current Goal: `}),w]}),e.progress?.phase&&(0,X.jsxs)(`div`,{className:`dg-steer-progress-tag`,children:[(0,X.jsx)(`span`,{className:`dg-steer-progress-dot`}),(0,X.jsxs)(`span`,{children:[l?`阶段`:`Phase`,`: `,(0,X.jsx)(`code`,{children:e.progress.phase}),e.progress.toolName&&` · Tool: ${e.progress.toolName}`]})]})]}),(0,X.jsxs)(`div`,{className:`dg-steer-presets-section`,children:[(0,X.jsxs)(`div`,{className:`dg-steer-presets-header`,children:[(0,X.jsx)(O,{className:`dg-steer-zap-icon`}),(0,X.jsx)(`span`,{children:l?`常用纠偏预设(点击快速填入)`:`Quick Steering Presets`})]}),(0,X.jsx)(`div`,{className:`dg-steer-preset-chips`,children:Re.map(e=>(0,X.jsx)(`button`,{type:`button`,className:`dg-steer-preset-chip`,onClick:()=>x(e),disabled:f,title:l?e.textZh:e.textEn,children:l?e.labelZh:e.labelEn},e.id))})]}),(0,X.jsxs)(`div`,{className:`dg-steer-input-section`,children:[(0,X.jsx)(`label`,{className:`dg-field-label`,children:l?`转向指令 (Ctrl+Enter 提交)`:`Steering Instruction (Ctrl+Enter to submit)`}),(0,X.jsx)(`textarea`,{ref:v,className:`dg-steer-textarea`,rows:4,placeholder:l?`例如:当前步骤已通过,请直接进行单元测试并汇报覆盖率;或者跳过重构,保持既有接口契约。`:`e.g. Current phase looks good, please jump to unit tests; or skip refactoring and adhere to contracts.`,value:u,onChange:e=>d(e.target.value),onKeyDown:C,disabled:f})]}),g&&(0,X.jsxs)(`div`,{className:`dg-error-banner`,role:`alert`,children:[(0,X.jsx)(b,{style:{marginRight:6,flexShrink:0}}),(0,X.jsx)(`span`,{children:g})]}),(0,X.jsxs)(`div`,{className:`dg-steer-actions`,children:[(0,X.jsx)(`button`,{type:`button`,className:`btn secondary`,onClick:i,disabled:f,children:l?`取消`:`Cancel`}),(0,X.jsxs)(`button`,{type:`button`,className:`btn primary`,onClick:S,disabled:f||!u.trim(),children:[f?(0,X.jsx)(h,{className:`spin`,style:{marginRight:6}}):(0,X.jsx)(t,{style:{marginRight:6}}),f?l?`注入中...`:`Injecting...`:l?`发送转向指令`:`Inject Steering`]})]})]})})}function Be(e,t,n=e=>new EventSource(e)){let r=!1,i=n(e),a=()=>!r&&t.alive();return i.onopen=()=>{a()&&(t.connected(!0),t.sync())},i.onerror=()=>{a()&&(t.connected(!1),t.sync())},i.addEventListener(`invalidate`,()=>{a()&&t.sync()}),i.addEventListener(`progress`,e=>{if(a())try{let n=JSON.parse(e.data);if(!n||[n.taskId,n.botId,n.attemptId].some(e=>typeof e!=`string`||!e||e.length>128)||!Number.isSafeInteger(n.sequence)||n.sequence<1||![`model`,`tool`,`waiting`].includes(n.phase)||n.text!==void 0&&(typeof n.text!=`string`||new TextEncoder().encode(n.text).byteLength>2048)||n.toolName!==void 0&&(typeof n.toolName!=`string`||!/^[A-Za-z0-9_.:-]{1,80}$/.test(n.toolName)))return;t.progress({taskId:n.taskId,botId:n.botId,attemptId:n.attemptId,sequence:n.sequence,phase:n.phase,...n.text===void 0?{}:{text:n.text},...n.toolName===void 0?{}:{toolName:n.toolName}})}catch{}}),()=>{r=!0,i.close()}}function Ve(e,t){return!!t&&e.status===`running`&&e.id===t.taskId&&e.botId===t.botId&&e.attemptId===t.attemptId}function He(e,t){return!e||e.attemptId!==t.attemptId||e.sequence<t.sequence}var $=null,Ue=new Set;function We(){for(let e of Ue)e()}function Ge(e){if(!e){$!==null&&($=null,We());return}let t=!!($&&$.roomId===e.roomId),n=t&&$?$.activeRightTab:e.attentionCount>0?`deliveries`:`files`;$&&t&&$.detail===e.detail&&$.devices===e.devices&&$.members===e.members&&$.conversations===e.conversations&&$.attentionCount===e.attentionCount&&$.disabled===e.disabled&&$.conversationError===e.conversationError&&$.activeRightTab===n||($={...$,...e,activeRightTab:n},We())}var Ke=class extends Error{status;code;constructor(e,t,n=``){super(t),this.status=e,this.code=n}};async function qe(e,t,n){let r=await fetch(i(T(`/api/device-center/${e}`)),{method:n?`POST`:`GET`,credentials:`same-origin`,signal:AbortSignal.any([t,AbortSignal.timeout(15e3)]),...n?{headers:{"Content-Type":`application/json`},body:JSON.stringify(n)}:{}}),a=await r.json().catch(()=>({}));if(!r.ok)throw new Ke(r.status,a.error||String(r.status),a.code??``);return a}var Je=new Map,Ye=()=>{};function Xe({roomId:e,active:t=!0,onBack:n,uiHeaderSlots:r,uiActionSlots:i}){return(0,X.jsx)(Ze,{roomId:e,active:t,onBack:n,uiHeaderSlots:r,uiActionSlots:i},e)}function Ze({roomId:e,active:t,onBack:n,uiHeaderSlots:r,uiActionSlots:a}){let{locale:o}=y(),s=m(o),[c,l]=(0,J.useState)(null),u=c?.bots??[],[d,f]=(0,J.useState)(``),[h,g]=(0,J.useState)(!1),[_,v]=(0,J.useState)(0),[b,x]=(0,J.useState)(0),[S,C]=(0,J.useState)(!1),[w,E]=(0,J.useState)([]),[D,O]=(0,J.useState)(``),[k,A]=(0,J.useState)(!1),[j,M]=(0,J.useState)(`deliveries`),N=(0,J.useCallback)(e=>{M(e),A(!0)},[]),P=(0,J.useCallback)(()=>{A(!1)},[]),[F,I]=(0,J.useState)(null),[V,U]=(0,J.useState)(null),ee=(0,J.useCallback)(()=>U(null),[]);function te(e){return e instanceof Ke&&(e.status===404||e.status===403||e.status===409&&e.code===`REPAIR_REQUIRED`)}function G(e){return e instanceof Ke&&e.status===409&&e.code===`REPAIR_REQUIRED`?s?`设备绑定已失效,请返回设备设置重新绑定。`:`Device binding expired. Return to device settings and bind again.`:e instanceof Error?e.message:String(e)}let K=(0,J.useRef)(0),re=(0,J.useRef)(null),q=(0,J.useRef)(null),ie=(0,J.useRef)(!1);(0,J.useEffect)(()=>{let n=++K.current,r=new Map,a=null,o=!1,c=!1,u=null,d=!1;async function p(){if(K.current!==n||!t||document.visibilityState===`hidden`)return;if(d){c=!0;return}c=!1,d=!0,u=new AbortController;let i=u.signal;try{let t=`rooms/${encodeURIComponent(e)}`,[a,o]=await Promise.allSettled([qe(t,i),qe(`${t}/conversations`,i)]);if(K.current!==n||i.aborted)return;if(o.status===`fulfilled`&&Array.isArray(o.value.conversations)?(E(o.value.conversations),O(``)):O(s?`无法更新对话列表,请稍后重试。`:`Could not refresh conversations. Try again shortly.`),a.status===`rejected`)throw a.reason;l({...a.value,tasks:a.value.tasks.map(e=>({...e,progress:Ve(e,r.get(e.id))?r.get(e.id):void 0}))});for(let e of r.keys())a.value.tasks.some(t=>Ve(t,r.get(e)))||r.delete(e);g(!1)}catch(e){if(K.current!==n||i.aborted)return;te(e)&&(l(null),g(!0)),f(G(e))}finally{d=!1,c&&K.current===n&&p()}}function m(){K.current===n&&t&&document.visibilityState!==`hidden`&&!a&&typeof EventSource<`u`&&(a=Be(i(T(`/api/device-center/rooms/${encodeURIComponent(e)}/events`)),{alive:()=>K.current===n&&document.visibilityState!==`hidden`,sync:()=>{x(e=>e+1),p()},connected:e=>{o=e,C(e)},progress:e=>{let t=r.get(e.taskId);!He(t,e)||r.size>=128&&!t||(r.set(e.taskId,e),l(t=>t&&{...t,tasks:t.tasks.map(t=>Ve(t,e)?{...t,progress:e}:t)}))}}))}p(),m();let h=window.setInterval(()=>{o||p()},2e3),_=()=>{document.visibilityState===`hidden`?(u?.abort(),c=!1,a?.(),a=null,o=!1,C(!1)):(p(),m())};return document.addEventListener(`visibilitychange`,_),()=>{++K.current,C(!1),a?.(),u?.abort(),re.current?.abort(),clearInterval(h),document.removeEventListener(`visibilitychange`,_)}},[e,t,_]);let{state:ae,labels:oe}=(0,J.useMemo)(()=>B(e,c,u,s),[e,c,u,s]),ce=p(),Y=(0,J.useMemo)(()=>H([],{locale:o,t:e=>ce(e)}),[o,ce]),le=(0,J.useMemo)(()=>r??(Y[`device.group.header`]??[]).filter(e=>!e.hidden),[r,Y]),ue=(0,J.useMemo)(()=>a??(Y[`device.group.actions`]??[]).filter(e=>!e.hidden),[a,Y]),Z=u.filter(e=>e.enabled!==!1&&c?.room.botIds.includes(e.id)),Q=(0,J.useMemo)(()=>w.filter(e=>!!se(e)).length,[w]),de=(0,J.useMemo)(()=>(c?.tasks??[]).filter(e=>e.status===`running`||e.status===`queued`),[c?.tasks]),pe=(0,J.useCallback)(async t=>{let n=t.conversationId||w.find(e=>e.botId===t.botId&&e.status!==`closed`)?.id;if(n)try{await qe(`rooms/${encodeURIComponent(e)}/conversations/${encodeURIComponent(n)}/stop`,new AbortController().signal,{}),v(e=>e+1)}catch(e){f(e?.message||(s?`中止任务失败`:`Failed to stop task`))}},[e,w,s]);(0,J.useEffect)(()=>{Ge({roomId:e,detail:c,devices:u,members:Z,conversations:w,attentionCount:Q,disabled:!t||h,conversationError:D})},[e,c,u,Z,w,Q,t,h,D]),(0,J.useEffect)(()=>()=>{Ge(null)},[]);async function me(n,r,i,a){if(!t||h||!c||ie.current)return!1;let o=i,u=w.find(e=>e.id===o);if(o&&(!u||u.status===`closed`||D||!Z.some(e=>e.id===u.botId)))return f(s?`所选对话不可用,请重新选择对话或新建任务。`:`Selected conversation is unavailable. Choose a conversation or New task.`),!1;if(u&&r.some(e=>e!==u.botId))return f(s?`继续对话只能发送给原 Bot,请移除其他目标。`:`Continue with the original Bot only. Remove other targets.`),!1;if(r.some(e=>!c.room.botIds.includes(e)))return!1;let d=a?.planOnly===!0,p=u?Z.filter(e=>e.id===u.botId):Z.filter(e=>r.includes(e.id)||!r.length&&e.id===c.room.primaryBotId);if(d&&p.some(e=>!e.tools?.includes(`plan_update`)))return f(s?`所选 Bot 未授权 plan_update,请先在 Bot 工具白名单中启用。`:`Selected Bot is not authorized to use plan_update. Enable it in the Bot tool allowlist first.`),!1;let m=n.includes(`->`);q.current=ne(q.current,JSON.stringify([e,o,d,m]),n,r,L);let _=new AbortController;re.current=_;let y=K.current;ie.current=!0;try{let t=`rooms/${encodeURIComponent(e)}`;return await qe(o?`${t}/conversations/${encodeURIComponent(o)}/messages`:`${t}/messages`,_.signal,o?{text:n,kind:`message`,idempotencyKey:q.current.key,...d?{planOnly:!0}:{},...m?{pipeline:!0}:{}}:{text:n,targetBotIds:r,idempotencyKey:q.current.key,...d?{planOnly:!0}:{},...m?{pipeline:!0}:{}}),_.signal.aborted||K.current!==y?!1:(q.current=null,f(``),v(e=>e+1),!0)}catch(e){if(!_.signal.aborted&&K.current===y){if(o)return f(s?`继续对话失败,请重试或重新选择目标。`:`Could not continue the conversation. Retry or choose a target.`),!1;te(e)&&(l(null),g(!0)),f(G(e))}return!1}finally{re.current===_&&(ie.current=!1,re.current=null)}}return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`dg-head`,children:[(0,X.jsxs)(`div`,{className:`dg-head-info`,children:[(0,X.jsxs)(`div`,{className:`dg-head-brand`,children:[(0,X.jsx)(`span`,{className:`dg-brand-icon`,children:`⚡`}),(0,X.jsx)(`strong`,{className:`dg-head-title`,children:c?.room.name??(s?`联合开发群`:`Group Chat`)})]}),Z.length>0&&(0,X.jsxs)(`button`,{type:`button`,className:`dg-head-pill`,onClick:()=>N(`bots`),title:s?`点击查看协作 Bot 成员详情`:`Click to view collaborating Bots`,children:[(0,X.jsx)(`span`,{className:`dg-head-pill-dot`}),(0,X.jsxs)(`span`,{children:[Z.length,` `,s?`位协作 Bot`:`Bots`]})]})]}),(0,X.jsxs)(`div`,{className:`dg-head-nav`,children:[(0,X.jsxs)(`button`,{type:`button`,className:`dg-nav-tab ${k&&j===`blackboard`?`active`:``}`,onClick:()=>N(`blackboard`),title:s?`打开群组共享共识黑板`:`Open Group Blackboard`,children:[(0,X.jsx)(`span`,{className:`dg-nav-icon`,children:`📋`}),(0,X.jsx)(`span`,{className:`dg-nav-text`,children:s?`群黑板`:`Blackboard`}),c?.room.blackboard?.version?(0,X.jsxs)(`span`,{className:`dg-nav-badge`,children:[`v`,c.room.blackboard.version]}):null]}),(0,X.jsxs)(`button`,{type:`button`,className:`dg-nav-tab ${k&&j===`deliveries`?`active`:``} ${Q>0?`has-attention`:``}`,onClick:()=>N(`deliveries`),title:s?`打开交付与待办审查抽屉`:`Open Deliveries & Reviews`,children:[(0,X.jsx)(`span`,{className:`dg-nav-icon`,children:`📦`}),(0,X.jsx)(`span`,{className:`dg-nav-text`,children:s?`交付与待办`:`Deliveries`}),Q>0?(0,X.jsx)(`span`,{className:`dg-nav-badge attention`,children:Q}):w.length>0?(0,X.jsx)(`span`,{className:`dg-nav-badge`,children:w.length}):null]}),(0,X.jsxs)(`button`,{type:`button`,className:`dg-nav-tab ${k&&j===`transfers`?`active`:``}`,onClick:()=>N(`transfers`),title:s?`打开跨机大文件传输抽屉`:`Open Cross-Device File Transfers`,children:[(0,X.jsx)(`span`,{className:`dg-nav-icon`,children:`📁`}),(0,X.jsx)(`span`,{className:`dg-nav-text`,children:s?`文件传输`:`Transfers`})]}),(0,X.jsxs)(`button`,{type:`button`,className:`dg-nav-tab ${k&&j===`canvas`?`active`:``}`,onClick:()=>N(`canvas`),title:s?`打开群画布工作流抽屉`:`Open Group Canvas`,children:[(0,X.jsx)(`span`,{className:`dg-nav-icon`,children:`🎨`}),(0,X.jsx)(`span`,{className:`dg-nav-text`,children:s?`群画布`:`Canvas`}),c?.room.canvasBinding&&(0,X.jsx)(`span`,{className:`dg-nav-dot active`})]}),(0,X.jsxs)(`button`,{type:`button`,className:`dg-nav-tab ${k&&j===`presets`?`active`:``}`,onClick:()=>N(`presets`),title:s?`打开 Bot 预设与规则配置抽屉`:`Open Bot Presets`,children:[(0,X.jsx)(`span`,{className:`dg-nav-icon`,children:`🤖`}),(0,X.jsx)(`span`,{className:`dg-nav-text`,children:s?`Bot 预设`:`Presets`})]}),(0,X.jsxs)(`button`,{type:`button`,className:`dg-nav-tab ${k&&j===`bots`?`active`:``}`,onClick:()=>N(`bots`),title:s?`查看成员运行状态与授权工具`:`View Bot Status`,children:[(0,X.jsx)(`span`,{className:`dg-nav-icon`,children:`👥`}),(0,X.jsx)(`span`,{className:`dg-nav-text`,children:s?`成员状态`:`Bots`})]}),(0,X.jsxs)(`button`,{type:`button`,className:`dg-nav-tab ${k&&j===`webhooks`?`active`:``}`,onClick:()=>N(`webhooks`),title:s?`配置入站与出站 Webhook`:`Configure Incoming and Outgoing Webhooks`,children:[(0,X.jsx)(`span`,{className:`dg-nav-icon`,children:`🔗`}),(0,X.jsx)(`span`,{className:`dg-nav-text`,children:s?`Webhook`:`Webhooks`}),c?.room.webhooks&&c.room.webhooks.filter(e=>e.enabled).length>0&&(0,X.jsx)(`span`,{className:`dg-nav-badge`,children:c.room.webhooks.filter(e=>e.enabled).length})]})]}),(0,X.jsxs)(`div`,{className:`dg-head-actions`,children:[le.map(e=>(0,X.jsx)(`button`,{type:`button`,className:`btn secondary`,title:e.label,children:e.label},e.id)),n&&(0,X.jsxs)(`button`,{type:`button`,className:`btn dg-back-btn`,onClick:n,title:s?`返回普通对话`:`Back to single chat`,children:[`← `,s?`返回对话`:`Back to chat`]})]})]}),d&&(0,X.jsxs)(`div`,{className:`dg-error-banner`,role:`alert`,children:[d,h?s?`此群聊已删除或你已不在群中,请返回。`:`This group is unavailable or you are no longer a member. Return to chat.`:null]}),(0,X.jsx)(`div`,{className:`dg-tools-shelf collapsed`,"aria-hidden":`true`,style:{display:`none`},children:(0,X.jsxs)(`div`,{className:`dg-tools-shelf-content`,children:[(0,X.jsx)(`div`,{className:`dg-tool-pane`,children:(0,X.jsx)(fe,{roomId:e,conversations:w,bots:u,disabled:!t||h,error:D})}),(0,X.jsx)(`div`,{className:`dg-tool-pane`,children:(0,X.jsx)(be,{roomId:e,bots:u,disabled:!t||h})}),(0,X.jsx)(`div`,{className:`dg-tool-pane`,children:(0,X.jsx)(Te,{roomId:e,binding:c?.room.canvasBinding,onSaved:()=>v(e=>e+1)})}),(0,X.jsx)(`div`,{className:`dg-tool-pane`,children:(0,X.jsx)(De,{bots:Z,onSaved:()=>v(e=>e+1)})})]})}),(Q>0||c?.tasks&&c.tasks.length>0)&&(0,X.jsxs)(`div`,{className:`dg-tasks-strip`,children:[Q>0&&(0,X.jsxs)(`button`,{type:`button`,className:`dg-task-chip dg-attention-chip ${k&&j===`deliveries`?`active`:``}`,onClick:()=>N(`deliveries`),title:s?`点击在协同抽屉中查看需要处理的交付与事项`:`View items needing attention in drawer`,children:[(0,X.jsx)(`span`,{className:`dg-attention-dot`}),(0,X.jsx)(`span`,{className:`dg-attention-text`,children:s?`${Q} 项待处理`:`${Q} need attention`})]}),(()=>{let e=c?.tasks??[],t=e.filter(e=>e.status===`running`||e.status===`waiting`||e.status===`queued`),n=e.slice(-4);if(t.length>0){let r=new Set(t.map(e=>e.id));for(let e of t)e.dependsOnTaskId&&r.add(e.dependsOnTaskId);let i=e.filter(e=>e.status===`completed`).slice(-2);for(let e of i)r.add(e.id);let a=e.filter(e=>r.has(e.id));n=a.length>0?a.slice(-6):e.slice(-6)}return n.map((e,t)=>{let{botPrefix:r,summary:i}=W(e.text),a=t>0?n[t-1]:void 0,o=t>0&&(e.dependsOnTaskId===a?.id||a?.status===`completed`&&(e.status===`running`||e.status===`waiting`)||e.dependsOnTaskId!==void 0);return(0,X.jsxs)(`div`,{className:`dg-pipeline-step-wrapper`,children:[o&&(0,X.jsx)(`span`,{className:`dg-pipeline-arrow`,title:s?`流水线流转依赖`:`Pipeline flow dependency`,"aria-hidden":`true`,children:`→`}),(0,X.jsxs)(`div`,{className:`dg-task-chip ${e.status===`running`?`is-running`:``} ${e.status===`waiting`?`is-waiting`:``}`,children:[(0,X.jsx)(`span`,{className:`dg-task-status-dot status-${e.status}`,title:e.status===`waiting`?s?`等待前序任务`:`Waiting for upstream`:e.status}),e.status===`waiting`&&(0,X.jsx)(`span`,{className:`dg-task-waiting-badge`,children:s?`⏳ 等待中`:`⏳ Waiting`}),r&&(0,X.jsx)(`strong`,{className:`dg-task-bot-prefix`,children:r}),(0,X.jsx)(`span`,{className:`dg-task-title`,title:e.text,children:i.length>24?i.slice(0,24)+`...`:i}),(0,X.jsx)(`button`,{type:`button`,className:`btn dg-task-detail-btn`,onClick:()=>U(e.id),children:s?`详情`:`Details`}),e.status===`running`&&(0,X.jsx)(`button`,{type:`button`,className:`btn dg-task-detail-btn`,title:s?`飞行中实时注入转向纠偏`:`Inject in-flight steering`,onClick:()=>I(e),children:s?`转向`:`Steer`}),(e.status===`running`||e.status===`queued`||e.status===`waiting`)&&(0,X.jsx)(`button`,{type:`button`,className:`btn dg-task-detail-btn dg-task-stop-action`,title:s?`中止此任务`:`Stop task`,onClick:()=>pe(e),children:s?`中止`:`Stop`})]})]},e.id)})})()]}),(0,X.jsx)(ge,{roomId:e,disabled:!t||h,refreshKey:b,connected:S}),(()=>{let t=c?.tasks.find(e=>e.id===V)??c?.tasks.find(e=>e.status===`running`)??c?.tasks.at(-1);return(0,X.jsx)(we,{roomId:e,activeTaskId:t?.id,taskSnapshotRevision:t?.botRevision,planState:t?.plan,uiSlotEntries:ue,onStartPlanExecution:t?.status===`completed`?async t=>{await qe(`rooms/${encodeURIComponent(e)}/tasks/${encodeURIComponent(t)}/approve-plan`,new AbortController().signal,{}),v(e=>e+1)}:void 0})})(),(0,X.jsx)(z,{state:ae,liveOutputs:Je,toolStatuses:Je,messageLabels:oe,readOnly:!0}),V&&(0,X.jsx)(Se,{roomId:e,taskId:V,onClose:ee}),F&&(0,X.jsx)(ze,{task:F,botName:Z.find(e=>e.id===F.botId)?.name,deviceName:u.find(e=>e.id===F.botId)?.deviceName||F.deviceId,onClose:()=>I(null),onSubmit:async t=>{await qe(`rooms/${encodeURIComponent(e)}/tasks/${encodeURIComponent(F.id)}/steer`,new AbortController().signal,{text:t.trim()}),v(e=>e+1)}}),(0,X.jsx)(Le,{isOpen:k,activeTab:j,onClose:P,onSelectTab:M,roomId:e,detail:c,devices:u,members:Z,conversations:w,attentionCount:Q,disabled:!t||h,conversationError:D,onRefreshGroup:()=>v(e=>e+1),onRefreshConversations:()=>v(e=>e+1)}),(0,X.jsx)(R,{groupDevices:Z,groupPrimaryBotName:Z.find(e=>e.id===c?.room.primaryBotId)?.name,groupConversations:w,groupConversationError:D,onGroupSend:me,streaming:de.length>0,onAbort:de.length>0?()=>pe(de[0]):void 0,messages:ae.messages,slashCommands:[],modelState:null,models:[],modelsLoading:!1,attachments:[],onRemoveAttachment:Ye,onAddImageFiles:Ye,onAddLocalFiles:Ye,onNotice:(e,t)=>f(t),onSent:Ye,onManageModels:Ye,providerKeys:{},quickPhrases:[],quickPhrasesEnabled:!1,groupReady:t&&!!c&&!h,sessionId:`device-group:${e}`,conversationId:`device-group:${e}`})]})}export{Xe as GroupConversation};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{pt as t}from"./app-globals-KqOVtmp1.js";import{i as n,r,t as i}from"./react-CR5VJ85Q.js";var a=e(n(),1),o=r();function s(e,t,n){let r=Math.max(8,e.left-8),i=e.bottom+8;return r+t.width>n.width-8&&(r=Math.max(8,e.right+8-t.width)),i+t.height>n.height-8&&(i=Math.max(8,e.top-8-t.height)),{left:r,top:i}}function c(){return typeof window<`u`&&window.matchMedia?.(`(hover: hover) and (pointer: fine)`)?.matches===!0}var l=i();function u(e){let t=(0,a.useRef)(null),n=(0,a.useRef)(null),[r,i]=(0,a.useState)(!1),[c,u]=(0,a.useState)({left:0,top:0});return(0,a.useEffect)(()=>{if(!r)return;let e=n.current,i=t.current;if(!e||!i)return;let a=e.getBoundingClientRect(),o=s(i.getBoundingClientRect(),a,{width:window.innerWidth,height:window.innerHeight});u(e=>e.left===o.left&&e.top===o.top?e:o)},[r,e]),(0,a.useEffect)(()=>{if(!r)return;let e=0,a=()=>{cancelAnimationFrame(e),e=requestAnimationFrame(()=>{let e=t.current,r=n.current;if(!e||!r)return;let a=e.getBoundingClientRect();if(a.bottom<0||a.top>window.innerHeight||a.right<0||a.left>window.innerWidth){i(!1);return}let o=s(a,r.getBoundingClientRect(),{width:window.innerWidth,height:window.innerHeight});u(e=>e.left===o.left&&e.top===o.top?e:o)})};return window.addEventListener(`scroll`,a,!0),window.addEventListener(`resize`,a),()=>{cancelAnimationFrame(e),window.removeEventListener(`scroll`,a,!0),window.removeEventListener(`resize`,a)}},[r]),{anchorRef:t,show:()=>{let e=t.current?.getBoundingClientRect();e&&(u({left:Math.max(8,e.left-8),top:e.bottom+8}),i(!0))},hide:()=>i(!1),onKeyDown:e=>{e.key===`Escape`&&e.target.blur()},tipPortal:r&&(0,o.createPortal)((0,l.jsx)(`span`,{ref:n,className:`set-tip-bubble open`,role:`tooltip`,style:{position:`fixed`,left:c.left,top:c.top},children:e}),document.body)}}function d({text:e}){let{anchorRef:n,show:r,hide:i,onKeyDown:a,tipPortal:o}=u(e);return(0,l.jsxs)(`span`,{ref:n,className:`set-tip`,tabIndex:0,"aria-label":e,onMouseEnter:r,onMouseLeave:i,onFocus:r,onBlur:i,onKeyDown:a,children:[(0,l.jsx)(t,{}),o]})}function f({tip:e,children:t,onMouseEnter:n,onMouseLeave:r,onFocus:i,onBlur:a,onKeyDown:o,...s}){let{anchorRef:c,show:d,hide:f,onKeyDown:p,tipPortal:m}=u(e);return(0,l.jsxs)(`button`,{ref:c,type:`button`,"aria-label":s[`aria-label`]??e,...s,onMouseEnter:e=>{d(),n?.(e)},onMouseLeave:e=>{f(),r?.(e)},onFocus:e=>{d(),i?.(e)},onBlur:e=>{f(),a?.(e)},onKeyDown:e=>{p(e),o?.(e)},children:[t,m]})}export{c as i,f as n,s as r,d as t};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{A as t,Bt as n,Gt as r,H as i,K as a,Qt as o,Sn as s,Vt as c,X as l,d as u,fn as d,in as f,pn as p,t as m}from"./app-globals-KqOVtmp1.js";import{i as ee,t as te}from"./react-CR5VJ85Q.js";import{Dt as ne,Et as re,Ot as ie,Tt as ae}from"./index-BoGCoq5X.js";import{t as oe}from"./ProviderOAuthControls-DY4SCfXg.js";var h=e(ee(),1);function se(e,t,n){if(JSON.stringify(e)===JSON.stringify(t))return n;let r=new Map(t.map(e=>[e.id,e])),i=new Map(n.map(e=>[e.id,e])),a=new Set(e.map(e=>e.id)),o=e.flatMap(e=>{let t=r.get(e.id);if(!t||JSON.stringify(t)!==JSON.stringify(e))return[e];let n=i.get(e.id);return n?[n]:[]});for(let e of n)!r.has(e.id)&&!a.has(e.id)&&o.push(e);return o}var g=te(),ce=[`openai-completions`,`openai-responses`,`anthropic-messages`,`google-generative-ai`],le=[{id:`openai`,name:`OpenAI`,api:`openai-responses`,baseUrl:`https://api.openai.com/v1`,authHeader:!0,tag:`官方`},{id:`anthropic`,name:`Anthropic`,api:`anthropic-messages`,baseUrl:`https://api.anthropic.com`,authHeader:!0,tag:`官方`},{id:`google`,name:`Google Gemini`,api:`google-generative-ai`,baseUrl:`https://generativelanguage.googleapis.com/v1beta`,authHeader:!0,tag:`官方`},{id:`dashscope`,name:`Alibaba Cloud Bailian (CN)`,api:`openai-completions`,baseUrl:`https://dashscope.aliyuncs.com/compatible-mode/v1`,authHeader:!0,tag:`官方`},{id:`dashscope-intl`,name:`Alibaba Cloud Bailian (Singapore)`,api:`openai-completions`,baseUrl:`https://dashscope-intl.aliyuncs.com/compatible-mode/v1`,authHeader:!0,tag:`官方`},{id:`minimax-cn`,name:`MiniMax (CN)`,api:`anthropic-messages`,baseUrl:`https://api.minimax.cn/anthropic`,authHeader:!0,tag:`官方`},{id:`minimax`,name:`MiniMax (International)`,api:`anthropic-messages`,baseUrl:`https://api.minimax.io/anthropic`,authHeader:!0,tag:`官方`},{id:`mistral`,name:`Mistral`,api:`openai-completions`,baseUrl:`https://api.mistral.ai/v1`,authHeader:!0,tag:`官方`},{id:`groq`,name:`Groq`,api:`openai-completions`,baseUrl:`https://api.groq.com/openai/v1`,authHeader:!0,tag:`官方`},{id:`xai`,name:`xAI`,api:`openai-completions`,baseUrl:`https://api.x.ai/v1`,authHeader:!0,tag:`官方`},{id:`magpie`,name:`Magpie`,api:`openai-completions`,baseUrl:`http://127.0.0.1:3425/v1`,authHeader:!0,apiKey:`magpie`},{id:`deepseek`,name:`DeepSeek`,api:`openai-completions`,baseUrl:`https://api.deepseek.com/v1`,authHeader:!0,tag:`官方`},{id:`openrouter`,name:`OpenRouter`,api:`openai-completions`,baseUrl:`https://openrouter.ai/api/v1`,authHeader:!0,tag:`聚合`},{id:`moonshot`,name:`Moonshot (Kimi)`,api:`openai-completions`,baseUrl:`https://api.moonshot.cn/v1`,authHeader:!0,tag:`官方`},{id:`zhipu`,name:`智谱 GLM`,api:`openai-completions`,baseUrl:`https://open.bigmodel.cn/api/paas/v4`,authHeader:!0,tag:`官方`},{id:`siliconflow`,name:`硅基流动`,api:`openai-completions`,baseUrl:`https://api.siliconflow.cn/v1`,authHeader:!0,tag:`云端`},{id:`ollama`,name:`Ollama`,api:`openai-completions`,baseUrl:`http://127.0.0.1:11434/v1`,authHeader:!0,tag:`本地`},{id:`vllm`,name:`vLLM / LM Studio`,api:`openai-completions`,baseUrl:`http://127.0.0.1:8000/v1`,authHeader:!0,tag:`本地`},{id:`antigravity`,name:`Antigravity (OpenAI)`,api:`openai-completions`,baseUrl:`http://127.0.0.1:8045/v1`,authHeader:!0,tag:`反代`},{id:`antigravity-anthropic`,name:`Antigravity (Anthropic)`,api:`anthropic-messages`,baseUrl:`http://127.0.0.1:8045`,authHeader:!0,tag:`反代`}],_=[{label:`8K`,value:`8192`},{label:`16K`,value:`16384`},{label:`32K`,value:`32768`},{label:`64K`,value:`65536`},{label:`128K`,value:`131072`},{label:`200K`,value:`200000`},{label:`1M`,value:`1000000`}],v=[{label:`2K`,value:`2048`},{label:`4K`,value:`4096`},{label:`8K`,value:`8192`},{label:`16K`,value:`16384`},{label:`32K`,value:`32768`},{label:`64K`,value:`65536`}];function ue(e,t){switch(e){case`官方`:return t(`presetTagOfficial`);case`聚合`:return t(`presetTagAggregator`);case`云端`:return t(`presetTagCloud`);case`本地`:return t(`presetTagLocal`);case`反代`:return t(`presetTagProxy`);default:return e}}var y=`pi_web_ui_thinking_custom_presets`;function de(){if(typeof localStorage>`u`)return[];try{let e=localStorage.getItem(y);return e?JSON.parse(e):[]}catch{return[]}}function fe(e){if(typeof localStorage<`u`)try{localStorage.setItem(y,JSON.stringify(e))}catch{}}function pe(e){if(!e.trim())return{valid:!0};try{let t=JSON.parse(e.trim());return!t||typeof t!=`object`||Array.isArray(t)?{valid:!1,error:`必须是 JSON 对象 (以 { 开头)`}:{valid:!0}}catch(e){return{valid:!1,error:e.message}}}var b=()=>({id:``,name:``,reasoning:!1,input:`text`,contextWindow:``,maxTokens:``}),x=()=>({providerId:``,name:``,api:`openai-completions`,baseUrl:``,apiKey:``,hasApiKey:!1,authHeader:!0,models:[b()]});function S(e){return{providerId:e.providerId,name:e.name??``,api:e.api??`openai-completions`,baseUrl:e.baseUrl??``,apiKey:``,hasApiKey:e.hasApiKey??!1,authHeader:e.authHeader??!1,models:(e.models.length?e.models:[b()]).map(e=>({id:e.id,name:e.name??``,reasoning:e.reasoning??!1,input:e.input?.includes(`image`)?`text-image`:`text`,contextWindow:e.contextWindow?String(e.contextWindow):``,maxTokens:e.maxTokens?String(e.maxTokens):``,...e.thinkingLevelMap?{thinkingLevelMap:e.thinkingLevelMap}:{},...e.compat?{compat:e.compat}:{},...e.customExtraBody?{customExtraBody:e.customExtraBody}:{}}))}}function me(e){let t={};for(let n of e.split(`
|
|
2
|
+
`)){let e=n.indexOf(`=`);if(e<=0)continue;let r=n.slice(0,e).trim(),i=n.slice(e+1).trim();r&&i&&(t[r]=i)}return t}function he({candidates:e,preselectedIds:t,onAdopt:n,onClose:i}){let a=s(),[o,c]=(0,h.useState)(``),[l,u]=(0,h.useState)(()=>{let n=new Set(e.map(e=>e.id)),r=(t??[]).map(e=>e.trim()).filter(e=>n.has(e));if(r.length>0)return new Set(r);let i=new Set;for(let t of e){let e=t.id.toLowerCase();!e.includes(`embed`)&&!e.includes(`audio`)&&!e.includes(`tts`)&&!e.includes(`whisper`)&&i.add(t.id)}if(i.size===0)for(let t of e)i.add(t.id);return i}),f=(0,h.useMemo)(()=>{let t=o.trim().toLowerCase();return t?e.filter(e=>e.id.toLowerCase().includes(t)||e.name&&e.name.toLowerCase().includes(t)):e},[e,o]),m=e=>{u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,g.jsx)(`div`,{className:`candidate-picker-backdrop`,onClick:i,children:(0,g.jsxs)(`div`,{className:`candidate-picker-modal`,onClick:e=>e.stopPropagation(),children:[(0,g.jsxs)(`div`,{className:`candidate-header`,children:[(0,g.jsxs)(`div`,{className:`candidate-title-group`,children:[(0,g.jsx)(`span`,{className:`candidate-title`,children:a(`candidatePickerTitle`)}),(0,g.jsx)(`span`,{className:`candidate-subtitle`,children:a(`candidatePickerSubtitle`,{n:e.length})})]}),(0,g.jsx)(`button`,{type:`button`,className:`iconbtn`,onClick:i,"aria-label":a(`close`),children:(0,g.jsx)(d,{})})]}),(0,g.jsxs)(`div`,{className:`candidate-filter-bar`,children:[(0,g.jsx)(r,{style:{color:`var(--text-faint)`,flexShrink:0}}),(0,g.jsx)(`input`,{type:`text`,className:`candidate-search-input`,placeholder:a(`searchCandidatePlaceholder`),value:o,onChange:e=>c(e.target.value),autoFocus:!0}),(0,g.jsxs)(`div`,{style:{display:`flex`,gap:6,flexShrink:0},children:[(0,g.jsx)(`button`,{type:`button`,className:`btn sm`,onClick:()=>{u(new Set(f.map(e=>e.id)))},children:a(`selectAll`)}),(0,g.jsx)(`button`,{type:`button`,className:`btn sm`,onClick:()=>{u(new Set)},children:a(`deselectAll`)})]})]}),(0,g.jsxs)(`div`,{className:`candidate-list-scroll`,children:[f.length===0&&(0,g.jsx)(`div`,{style:{padding:`32px 0`,textAlign:`center`,color:`var(--text-faint)`,fontSize:13},children:a(`noCandidateMatches`)}),f.map(e=>{let t=l.has(e.id);return(0,g.jsxs)(`div`,{className:`candidate-item-card ${t?`selected`:``}`,onClick:()=>m(e.id),children:[(0,g.jsxs)(`div`,{className:`candidate-item-left`,children:[(0,g.jsx)(`input`,{type:`checkbox`,className:`candidate-checkbox`,checked:t,onChange:()=>{},onClick:e=>e.stopPropagation()}),(0,g.jsxs)(`div`,{className:`candidate-id-info`,children:[(0,g.jsx)(`span`,{className:`candidate-id-name`,children:e.id}),e.name&&e.name!==e.id&&(0,g.jsx)(`span`,{style:{fontSize:11.5,color:`var(--text-dim)`},children:e.name})]})]}),(0,g.jsxs)(`div`,{className:`candidate-item-meta`,children:[e.contextWindow&&(0,g.jsx)(`span`,{className:`spec-badge ctx`,title:a(`contextWindowTooltip`),children:e.contextWindow>=1e6?`${Math.round(e.contextWindow/1e6)}M`:`${Math.round(e.contextWindow/1024)}K`}),e.reasoning&&(0,g.jsxs)(`span`,{className:`spec-badge reasoning`,title:a(`reasoningTooltip`),children:[(0,g.jsx)(p,{}),` `,a(`reasoning`)]}),e.input?.includes(`image`)&&(0,g.jsx)(`span`,{className:`spec-badge vision`,title:a(`visionTooltip`),children:a(`vision`)})]})]},e.id)})]}),(0,g.jsxs)(`div`,{className:`candidate-actions-footer`,children:[(0,g.jsx)(`span`,{className:`candidate-select-summary`,children:a(`selectedCandidatesCount`,{count:l.size,total:e.length})}),(0,g.jsxs)(`div`,{style:{display:`flex`,gap:8},children:[(0,g.jsx)(`button`,{type:`button`,className:`btn`,onClick:i,children:a(`cancel`)}),(0,g.jsx)(`button`,{type:`button`,className:`btn primary`,disabled:l.size===0,onClick:()=>{n(e.filter(e=>l.has(e.id)))},children:a(`adoptSelectedModels`,{count:l.size})})]})]})]})})}function C({providers:e,providerStatus:r,providerKeys:p,providerOAuthFlows:ee,providerOAuthResults:te,fetchModelsResult:y,testModelConnectionResult:C,enrichModelsResult:w,enrichModelsProgress:ge,cloneProviderResult:T,refreshBuiltinResult:E,refreshProviderResult:D,appendBuiltinResult:O,defaultModel:k,onClose:A}){let j=s(),[M,N]=(0,h.useState)(()=>e.length>0?{type:`custom`,id:e[0].providerId}:r.length>0?{type:`builtin`,id:r[0].id}:{type:`custom`,id:``}),[P,F]=(0,h.useState)(()=>e.length>0?S(e[0]):r.length>0?null:x()),_e=(0,h.useRef)(e);(0,h.useEffect)(()=>{let t=_e.current;_e.current=e,F(n=>{if(!n)return n;let r=e.find(e=>e.providerId===n.providerId),i=t.find(e=>e.providerId===n.providerId);return!r||r===i?n:{...n,hasApiKey:r.hasApiKey??!1,models:se(n.models,i?S(i).models:[],S(r).models)}})},[e]);let[ve,ye]=(0,h.useState)(null),[be,xe]=(0,h.useState)(!1),[Se,Ce]=(0,h.useState)(0),[I,L]=(0,h.useState)(null),we=(0,h.useRef)(0),[R,Te]=(0,h.useState)({}),[Ee,De]=(0,h.useState)({}),[z,B]=(0,h.useState)(null),Oe=(0,h.useRef)(p),V=(0,h.useRef)(null);(0,h.useEffect)(()=>{let e=z;e&&p[e]!==Oe.current[e]&&(B(null),Te(t=>({...t,[e]:``})),De(t=>({...t,[e]:``})),V.current&&clearTimeout(V.current)),Oe.current=p},[p,z]),(0,h.useEffect)(()=>()=>{V.current&&clearTimeout(V.current)},[]);let[H,ke]=(0,h.useState)(!1),[Ae,je]=(0,h.useState)(0),[U,W]=(0,h.useState)(null),Me=(0,h.useRef)(0),[G,Ne]=(0,h.useState)(!1),[K,q]=(0,h.useState)(!1),[Pe,Fe]=(0,h.useState)(0),[J,Y]=(0,h.useState)(null),[Ie,Le]=(0,h.useState)([]),[Re]=(0,h.useState)(``),ze=(0,h.useRef)(0),[X,Be]=(0,h.useState)(null),[Ve,He]=(0,h.useState)(de),[Ue,We]=(0,h.useState)(``),[Ge,Ke]=(0,h.useState)(null),qe=e=>{let t=Ue.trim();if(!t||!P)return;let n=P.models[e];if(!n)return;let r={id:`preset-${Date.now()}`,name:t,thinkingFormat:n.compat?.thinkingFormat||void 0,customExtraBody:n.customExtraBody?.trim()||void 0,map:n.thinkingLevelMap??{}},i=[...Ve,r];He(i),fe(i),We(``),Ke(null)},Je=(e,t)=>{t.stopPropagation();let n=Ve.filter(t=>t.id!==e);He(n),fe(n)},[Ye,Xe]=(0,h.useState)(!1),[Ze,Qe]=(0,h.useState)(0),[$e,et]=(0,h.useState)(null),tt=(0,h.useRef)(0),[nt,rt]=(0,h.useState)(null),[it,at]=(0,h.useState)(``),[Z,ot]=(0,h.useState)(``),[st,ct]=(0,h.useState)(``),[lt,ut]=(0,h.useState)(``),[dt,ft]=(0,h.useState)(!1),[pt,mt]=(0,h.useState)(0),[ht,Q]=(0,h.useState)(null),gt=(0,h.useRef)(0),[_t,vt]=(0,h.useState)(null),[yt,bt]=(0,h.useState)(``),[xt,St]=(0,h.useState)(null),[Ct,wt]=(0,h.useState)({}),Tt=(0,h.useRef)(0),Et=(0,h.useRef)(0),[Dt,Ot]=(0,h.useState)(null),kt=(0,h.useRef)(0),At=(0,h.useRef)(0),jt=e=>{if(Ct[e])return;let t=++Tt.current+Date.now();wt(t=>({...t,[e]:!0})),m({type:`refresh_provider_models`,providerId:e,reqId:t})};(0,h.useEffect)(()=>{D&&D.reqId!==Et.current&&(Et.current=D.reqId,wt({}))},[D]);let Mt=e=>{if(Dt)return;Ot(e.id);let t=++kt.current+Date.now();m({type:`clone_provider`,provider:e.id,reqId:t})||Ot(null)};(0,h.useEffect)(()=>{m({type:`list_models_config`}),m({type:`list_providers`}),m({type:`list_provider_keys`}),m({type:`list_provider_oauth_flows`})},[]),(0,h.useEffect)(()=>{C&&C.reqId!==we.current&&(we.current=C.reqId,xe(!1),L({ok:C.ok,latencyMs:C.latencyMs,error:C.error}))},[C]),(0,h.useEffect)(()=>{y&&y.reqId!==Me.current&&(Me.current=y.reqId,ke(!1),y.ok&&y.models?.length?(ye(y.models),W({ok:!0,text:j(`fetchModelsOk`,{n:y.models.length})})):W({ok:!1,text:y.error||j(`fetchModelsEmpty`)}))},[y,j]),(0,h.useEffect)(()=>{if(w&&w.reqId!==ze.current){if(ze.current=w.reqId,Ne(!1),q(!1),w.ok&&w.results?.length){let e=w.results,t=new Map(e.map(e=>[e.id.trim(),e]));F(e=>e&&{...e,models:e.models.map(e=>{let n=t.get(e.id.trim());return!n||n.status!==`matched`?e:{...e,name:e.name||n.name||``,contextWindow:e.contextWindow||(n.contextWindow?String(n.contextWindow):``),maxTokens:e.maxTokens||(n.maxTokens?String(n.maxTokens):``),input:e.input===`text`&&n.input?.includes(`image`)?`text-image`:e.input,reasoning:e.reasoning||(n.reasoning??!1),thinkingLevelMap:e.thinkingLevelMap||n.thinkingLevelMap,src:n.source}})});let n=e.filter(e=>e.status===`matched`).length,r=e.length-n;Y({ok:!0,text:j(`enrichModelsOk`,{n,m:r})});let i=e.filter(e=>e.status!==`matched`&&(e.suggestions?.length||e.note)).map(e=>({id:e.id,suggestions:e.suggestions??[],note:e.note}));Le(i)}else Y({ok:!1,text:w.error||j(`enrichModelsErr`,{msg:``})})}},[w,j]),(0,h.useEffect)(()=>{E&&E.reqId!==tt.current&&(tt.current=E.reqId,Xe(!1),E.ok?et({ok:!0,text:j(`refreshBuiltinOk`)}):et({ok:!1,text:E.error||j(`refreshBuiltinFail`)}))},[E,j]),(0,h.useEffect)(()=>{O&&O.reqId!==gt.current&&(gt.current=O.reqId,ft(!1),O.ok?(Q({ok:!0,text:j(`appendModelOk`)}),at(``),ot(``),ct(``),ut(``),rt(null),m({type:`list_models_config`})):Q({ok:!1,text:O.error||j(`appendModelFail`)}))},[O,j]),(0,h.useEffect)(()=>{if(T&&T.reqId!==At.current&&(At.current=T.reqId,Ot(null),T.ok)){let e=T.configs;if(e&&e.length>1){vt(e.map(e=>S(e))),bt(``);return}T.config&&St(S(T.config))}},[T]);let Nt=()=>{if(!P)return;let e=P.baseUrl.trim();if(!e){L({ok:!1,error:j(`fetchModelsNeedBaseUrl`)});return}xe(!0),L(null);let t=Se+1;Ce(t),m({type:`test_model_connection`,reqId:t,baseUrl:e,apiKey:P.apiKey.trim()||void 0,...P.apiKey.trim()?{}:P.hasApiKey?{providerId:P.providerId.trim()}:{},authHeader:P.authHeader,api:P.api})},Pt=()=>{if(!P)return;let e=P.baseUrl.trim();if(!e){W({ok:!1,text:j(`fetchModelsNeedBaseUrl`)});return}if(H)return;ke(!0),W(null);let t=Ae+1;je(t),m({type:`fetch_models`,reqId:t,baseUrl:e,apiKey:P.apiKey.trim()||void 0,...P.apiKey.trim()?{}:P.hasApiKey?{providerId:P.providerId.trim()}:{},authHeader:P.authHeader,api:P.api})},Ft=e=>{P&&(F(t=>{if(!t)return t;let n=t.models.filter(e=>e.id.trim()),r=new Set(n.map(e=>e.id.trim())),i=e.filter(e=>!r.has(e.id)).map(e=>({id:e.id,name:e.name??``,reasoning:e.reasoning??!1,input:e.input?.includes(`image`)?`text-image`:`text`,contextWindow:e.contextWindow?String(e.contextWindow):``,maxTokens:e.maxTokens?String(e.maxTokens):``,...e.thinkingLevelMap?{thinkingLevelMap:e.thinkingLevelMap}:{}}));return{...t,models:n.length===0?i:[...n,...i]}}),ye(null))},It=()=>{if(!P||G)return;let e=P.models.map(e=>e.id.trim()).filter(Boolean);if(e.length===0){Y({ok:!1,text:j(`enrichModelsNeedIds`)});return}Ne(!0),q(!1),Y(null),Le([]);let t=Pe+1;Fe(t),m({type:`enrich_models`,reqId:t,ids:e,hints:me(Re)})},Lt=()=>{G&&!K&&(q(!0),m({type:`abort_enrich_models`,reqId:Pe}))},Rt=e=>{F(t=>({providerId:t?.providerId.trim()||e.id,name:t?.name.trim()||e.name,api:e.api,baseUrl:e.baseUrl,apiKey:t?.apiKey||(t?.hasApiKey?``:e.apiKey)||``,hasApiKey:t?.hasApiKey??!1,authHeader:e.authHeader,models:t?.models.length?t.models:[b()]})),L(null),W(null)},zt=()=>{if(!P)return;let e=P.providerId.trim();if(!e)return;let t=P.models.filter(e=>e.id.trim()).map(e=>({id:e.id.trim(),name:e.name.trim()||void 0,reasoning:e.reasoning||void 0,input:e.input===`text-image`?[`text`,`image`]:void 0,contextWindow:e.contextWindow?Number(e.contextWindow):void 0,maxTokens:e.maxTokens?Number(e.maxTokens):void 0,...e.thinkingLevelMap?{thinkingLevelMap:e.thinkingLevelMap}:{},...e.compat?{compat:e.compat}:{},...e.customExtraBody?.trim()?{customExtraBody:e.customExtraBody.trim()}:{}})),n={providerId:e,name:P.name.trim()||void 0,api:P.api.trim()||void 0,baseUrl:P.baseUrl.trim()||void 0,...P.apiKey.trim()?{apiKey:P.apiKey.trim()}:{},authHeader:P.authHeader||void 0,models:t};m({type:`save_model_config`,providerId:e,config:n}),A()},$=(e,t)=>{P&&F({...P,models:P.models.map((n,r)=>r===e?{...n,...t}:n)})},Bt=()=>{P&&F({...P,models:[...P.models,b()]})},Vt=e=>{P&&F({...P,models:P.models.filter((t,n)=>n!==e)})},Ht=e=>{let t=(R[e.id]??``).trim();t&&!z&&(B(e.id),m({type:`add_provider_key`,provider:e.id,apiKey:t,name:(Ee[e.id]??``).trim()||void 0}),V.current&&clearTimeout(V.current),V.current=setTimeout(()=>{B(t=>t===e.id?null:t)},1e4))},Ut=(e,t)=>{m({type:`activate_provider_key`,provider:e,keyName:t}),m({type:`list_provider_keys`})},Wt=(e,t)=>{window.confirm(j(`removeKeyConfirm`))&&(m({type:`remove_provider_key`,provider:e,keyName:t}),m({type:`list_provider_keys`}))},Gt=e=>{window.confirm(j(`clearKeyConfirm`,{id:e}))&&m({type:`clear_provider_api_key`,provider:e})},Kt=t=>{if(window.confirm(j(`deleteProviderConfirm`,{id:t.providerId,n:t.models.length}))&&(m({type:`delete_model_config`,providerId:t.providerId}),M.type===`custom`&&M.id===t.providerId)){let n=e.filter(e=>e.providerId!==t.providerId);n.length>0?(N({type:`custom`,id:n[0].providerId}),F(S(n[0]))):(N({type:`custom`,id:``}),F(x()))}},qt=e=>{let t=it.trim();if(!t||dt)return;ft(!0),Q(null);let n=pt+1;mt(n),m({type:`append_builtin_model`,providerId:e,model:{id:t,...Z.trim()?{name:Z.trim()}:{},...st?{api:st}:{},...lt.trim()?{baseUrl:lt.trim()}:{}},reqId:n})};return(0,g.jsx)(`div`,{className:`modal-backdrop`,onClick:A,children:(0,g.jsxs)(`div`,{className:`modal model-studio-modal`,onClick:e=>e.stopPropagation(),children:[(0,g.jsxs)(`div`,{className:`studio-header`,children:[(0,g.jsxs)(`div`,{className:`studio-header-left`,children:[(0,g.jsx)(`div`,{className:`studio-header-icon-box`,children:(0,g.jsx)(a,{})}),(0,g.jsxs)(`div`,{className:`studio-header-title-wrap`,children:[(0,g.jsx)(`h2`,{className:`studio-header-title`,children:j(`modelManagementTitle`)}),(0,g.jsx)(`span`,{className:`studio-header-badge`,children:`Studio`})]})]}),(0,g.jsxs)(`div`,{className:`studio-header-actions`,children:[k!==void 0&&k&&(0,g.jsxs)(`div`,{style:{display:`inline-flex`,alignItems:`center`,gap:5,padding:`3px 8px`,borderRadius:6,background:`rgba(251, 191, 36, 0.08)`,border:`1px solid rgba(251, 191, 36, 0.3)`,fontSize:11.5,color:`var(--amber)`},title:j(`defaultModelLabel`,{model:k}),children:[(0,g.jsx)(`span`,{children:`★`}),(0,g.jsx)(`span`,{style:{maxWidth:120,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,fontFamily:`var(--mono)`},children:k.split(`/`).slice(1).join(`/`)}),(0,g.jsx)(`button`,{type:`button`,style:{background:`transparent`,border:`none`,color:`var(--amber)`,cursor:`pointer`,fontSize:10,padding:`0 2px`,opacity:.7},title:j(`clearDefaultModel`),onClick:()=>m({type:`clear_default_model`}),children:`✕`})]}),(0,g.jsxs)(`button`,{type:`button`,className:`studio-header-btn`,title:j(`refreshBuiltinHint`),disabled:Ye,onClick:()=>{if(Ye)return;Xe(!0),et(null);let e=Ze+1;Qe(e),m({type:`refresh_builtin_models`,reqId:e})},children:[(0,g.jsx)(l,{}),(0,g.jsx)(`span`,{children:j(Ye?`refreshBuiltinBusy`:`refreshBuiltinCatalog`)})]}),(0,g.jsx)(`button`,{type:`button`,className:`studio-header-iconbtn`,title:j(`reloadModelsHint`),onClick:()=>m({type:`reload_models_config`}),children:(0,g.jsx)(c,{})}),(0,g.jsx)(`button`,{type:`button`,className:`studio-header-iconbtn close-btn`,"aria-label":j(`close`),onClick:A,children:(0,g.jsx)(d,{})})]})]}),$e&&(0,g.jsx)(`div`,{style:{padding:`6px 20px`,background:`var(--bg-elev2)`,fontSize:12,borderBottom:`1px solid var(--border-soft)`},children:(0,g.jsx)(`span`,{className:`fetch-msg ${$e.ok?`ok`:`err`}`,children:$e.text})}),(0,g.jsxs)(`div`,{className:`model-studio-body`,children:[(0,g.jsxs)(`div`,{className:`model-studio-sidebar`,children:[(0,g.jsx)(`div`,{style:{padding:`12px 10px 6px`},children:(0,g.jsxs)(`button`,{type:`button`,className:`btn primary sm`,style:{width:`100%`,justifyContent:`center`},onClick:()=>{N({type:`custom`,id:``}),F(x()),L(null),W(null)},children:[(0,g.jsx)(n,{}),` `,j(`addCustomProvider`)]})}),(0,g.jsxs)(`div`,{className:`studio-sidebar-section`,children:[(0,g.jsx)(`span`,{className:`studio-sidebar-title`,children:j(`customProvidersCount`,{n:e.length})}),e.length===0&&(0,g.jsx)(`div`,{style:{fontSize:11.5,color:`var(--text-faint)`,padding:`6px 8px`},children:j(`noCustomProviders`)}),e.map(e=>{let t=M.type===`custom`&&M.id===e.providerId;return(0,g.jsxs)(`div`,{className:`studio-nav-item ${t?`active`:``}`,onClick:()=>{N({type:`custom`,id:e.providerId}),F(S(e)),L(null),W(null)},children:[(0,g.jsxs)(`span`,{className:`studio-nav-label`,children:[(0,g.jsx)(`span`,{className:`studio-nav-dot configured`}),(0,g.jsx)(`span`,{children:e.name||e.providerId})]}),(0,g.jsxs)(`span`,{style:{fontSize:10.5,color:`var(--text-faint)`,fontFamily:`var(--mono)`},children:[e.models.length,`m`]})]},e.providerId)})]}),(0,g.jsxs)(`div`,{className:`studio-sidebar-section`,children:[(0,g.jsx)(`span`,{className:`studio-sidebar-title`,children:j(`builtinProvidersCount`,{n:r.length})}),r.map(e=>{let t=M.type===`builtin`&&M.id===e.id,n=p[e.id]??[];return(0,g.jsxs)(`div`,{className:`studio-nav-item ${t?`active`:``}`,onClick:()=>{N({type:`builtin`,id:e.id}),F(null)},children:[(0,g.jsxs)(`span`,{className:`studio-nav-label`,children:[(0,g.jsx)(`span`,{className:`studio-nav-dot ${e.configured?`configured`:``}`}),(0,g.jsx)(`span`,{children:e.name})]}),n.length>0&&(0,g.jsxs)(`span`,{style:{fontSize:10.5,color:`var(--text-faint)`,fontFamily:`var(--mono)`},children:[n.length,`k`]})]},e.id)})]})]}),(0,g.jsxs)(`div`,{className:`model-studio-main`,children:[P&&(0,g.jsxs)(`div`,{className:`studio-card`,children:[(0,g.jsxs)(`div`,{className:`studio-card-head`,children:[(0,g.jsxs)(`div`,{className:`studio-card-title`,children:[(0,g.jsx)(`span`,{children:P.providerId?j(`editProviderTitle`,{id:P.providerId}):j(`newCustomProviderTitle`)}),P.providerId&&e.some(e=>e.providerId===P.providerId)&&(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(`button`,{type:`button`,className:`iconbtn sm`,title:j(`refreshModels`),disabled:Ct[P.providerId],onClick:()=>jt(P.providerId),children:(0,g.jsx)(c,{className:Ct[P.providerId]?`spin`:``})}),(0,g.jsx)(`button`,{type:`button`,className:`iconbtn danger sm`,title:j(`deleteProviderTooltip`),onClick:()=>{let t=e.find(e=>e.providerId===P.providerId);t&&Kt(t)},children:(0,g.jsx)(f,{})})]})]}),(0,g.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8},children:[(0,g.jsxs)(`div`,{className:`conn-test-box`,children:[(0,g.jsxs)(`button`,{type:`button`,className:`conn-test-btn`,disabled:be||!P.baseUrl.trim(),onClick:Nt,children:[(0,g.jsx)(u,{}),` `,j(be?`testingConnection`:`testConnection`)]}),I&&(0,g.jsxs)(`span`,{className:`ping-indicator ${I.ok?`ok`:`err`}`,children:[(0,g.jsx)(`span`,{className:`ping-dot`}),(0,g.jsx)(`span`,{children:I.ok?j(`connSuccess`,{latency:I.latencyMs??0}):j(`connFailed`)})]})]}),(0,g.jsx)(`button`,{type:`button`,className:`btn primary sm`,onClick:zt,children:j(`save`)})]})]}),(0,g.jsxs)(`div`,{className:`quick-chips-wrapper`,children:[(0,g.jsx)(`span`,{className:`quick-chips-label`,children:j(`quickPresetsLabel`)}),(0,g.jsx)(`div`,{className:`quick-chips-grid`,children:le.map(e=>(0,g.jsxs)(`button`,{type:`button`,className:`quick-chip`,onClick:()=>Rt(e),children:[(0,g.jsx)(`span`,{className:`quick-chip-name`,children:e.name}),e.tag&&(0,g.jsx)(`span`,{className:`quick-chip-tag`,children:ue(e.tag,j)})]},e.id))})]}),(0,g.jsxs)(`div`,{className:`form-grid`,children:[(0,g.jsxs)(`label`,{className:`field`,children:[(0,g.jsxs)(`span`,{className:`field-label`,children:[j(`providerId`),` `,(0,g.jsx)(`em`,{children:j(`providerIdHint`)})]}),(0,g.jsx)(`input`,{type:`text`,value:P.providerId,disabled:e.some(e=>e.providerId===P.providerId),onChange:e=>F({...P,providerId:e.target.value}),placeholder:j(`providerIdPlaceholder`)})]}),(0,g.jsxs)(`label`,{className:`field`,children:[(0,g.jsx)(`span`,{className:`field-label`,children:j(`displayName`)}),(0,g.jsx)(`input`,{type:`text`,value:P.name,onChange:e=>F({...P,name:e.target.value}),placeholder:j(`displayNamePh`)})]}),(0,g.jsxs)(`label`,{className:`field`,children:[(0,g.jsx)(`span`,{className:`field-label`,children:j(`apiType`)}),(0,g.jsx)(`select`,{value:P.api,onChange:e=>F({...P,api:e.target.value}),children:ce.map(e=>(0,g.jsx)(`option`,{value:e,children:e},e))})]}),(0,g.jsxs)(`label`,{className:`field`,children:[(0,g.jsxs)(`span`,{className:`field-label`,children:[`baseUrl `,(0,g.jsx)(`em`,{children:j(`baseUrlHint`)})]}),(0,g.jsx)(`input`,{type:`text`,value:P.baseUrl,onChange:e=>F({...P,baseUrl:e.target.value}),placeholder:`https://api.deepseek.com/v1`})]}),(0,g.jsxs)(`label`,{className:`field`,children:[(0,g.jsx)(`span`,{className:`field-label`,children:j(`apiKey`)}),(0,g.jsx)(`input`,{type:`password`,value:P.apiKey,onChange:e=>F({...P,apiKey:e.target.value}),placeholder:P.hasApiKey?j(`apiKeySavedHint`):j(`apiKeyHint`)})]}),(0,g.jsxs)(`label`,{className:`field check`,style:{alignSelf:`center`,paddingTop:16},children:[(0,g.jsx)(`input`,{type:`checkbox`,checked:P.authHeader,onChange:e=>F({...P,authHeader:e.target.checked})}),(0,g.jsx)(`span`,{children:j(`authHeader`)})]})]}),(0,g.jsxs)(`div`,{style:{marginTop:8},children:[(0,g.jsxs)(`div`,{className:`model-section-head`,children:[(0,g.jsx)(`span`,{className:`form-section-title`,style:{fontSize:13,fontWeight:600},children:j(`modelMatrixCount`,{n:P.models.filter(e=>e.id.trim()).length})}),(0,g.jsxs)(`div`,{className:`model-section-actions`,children:[U&&(0,g.jsx)(`span`,{className:`fetch-msg ${U.ok?`ok`:`err`}`,title:U.text,children:U.text}),J&&(0,g.jsx)(`span`,{className:`fetch-msg ${J.ok?`ok`:`err`}`,title:J.text,children:J.text}),(0,g.jsxs)(`button`,{type:`button`,className:`btn sm`,disabled:H||!P.baseUrl.trim(),title:j(`fetchModelsHint`),onClick:Pt,children:[(0,g.jsx)(l,{}),` `,j(H?`fetchingModels`:`autoFetchAndAdopt`)]}),(0,g.jsxs)(`button`,{type:`button`,className:`btn sm`,disabled:G,title:j(`enrichModelsHint`),onClick:It,children:[(0,g.jsx)(l,{}),` `,j(G?`enrichingModels`:`enrichModels`)]}),G&&(0,g.jsxs)(`button`,{type:`button`,className:`btn sm`,disabled:K,title:j(`enrichModelsAbort`),onClick:Lt,style:{color:`var(--red)`},children:[(0,g.jsx)(d,{}),` `,j(K?`enrichCancelling`:`enrichModelsCancel`)]})]})]}),(0,g.jsxs)(`div`,{className:`model-matrix-list`,children:[P.models.map((e,t)=>(0,g.jsxs)(`div`,{className:`model-matrix-card`,children:[(0,g.jsxs)(`div`,{className:`matrix-main-row`,children:[(0,g.jsxs)(`div`,{className:`matrix-input-group id-group`,children:[(0,g.jsxs)(`span`,{className:`matrix-input-prefix`,children:[(0,g.jsx)(a,{}),` ID`]}),(0,g.jsx)(`input`,{type:`text`,className:`matrix-input-field mono`,value:e.id,onChange:e=>$(t,{id:e.target.value}),placeholder:j(`modelIdPlaceholder`)})]}),(0,g.jsxs)(`div`,{className:`matrix-input-group name-group`,children:[(0,g.jsx)(`span`,{className:`matrix-input-prefix`,children:j(`modelAliasPrefix`)}),(0,g.jsx)(`input`,{type:`text`,className:`matrix-input-field`,value:e.name,onChange:e=>$(t,{name:e.target.value}),placeholder:j(`modelAliasPlaceholder`)})]}),(0,g.jsxs)(`div`,{className:`matrix-toggles`,children:[(0,g.jsx)(`button`,{type:`button`,className:`matrix-toggle-tag ${e.input===`text-image`?`active vision`:``}`,onClick:()=>$(t,{input:e.input===`text-image`?`text`:`text-image`}),title:j(`visionCheckboxTitle`),children:j(`visionCheckboxLabel`)}),(0,g.jsx)(`button`,{type:`button`,className:`matrix-toggle-tag ${e.reasoning?`active reasoning`:``}`,onClick:()=>$(t,{reasoning:!e.reasoning}),title:j(`reasoningCheckboxTitle`),children:j(`reasoningCheckboxLabel`)}),e.reasoning&&(0,g.jsxs)(`button`,{type:`button`,className:`matrix-toggle-tag ${X===t?`active thinking-config`:``}`,onClick:()=>Be(X===t?null:t),title:j(`thinkingConfigTitle`),children:[(0,g.jsx)(o,{}),` `,j(`thinkingConfigBtn`),` `,e.thinkingLevelMap?`(${j(`thinkingCustomized`)})`:``]}),k!==void 0&&e.id.trim()&&(()=>{let t=`${P.providerId}/${e.id.trim()}`,n=k===t||k===e.id.trim();return(0,g.jsxs)(`button`,{type:`button`,className:`matrix-star-btn ${n?`active`:``}`,title:j(n?`cancelDefaultTooltip`:`setDefaultTooltip`),onClick:()=>{m(n?{type:`clear_default_model`}:{type:`set_default_model`,modelId:t})},children:[(0,g.jsx)(`span`,{className:`matrix-star-icon`,children:n?`★`:`☆`}),(0,g.jsx)(`span`,{children:j(n?`defaultModelBadge`:`setDefaultModelBtn`)})]})})(),(0,g.jsx)(`button`,{type:`button`,className:`matrix-delete-btn`,title:j(`delete`),onClick:()=>Vt(t),children:(0,g.jsx)(f,{})})]})]}),(0,g.jsxs)(`div`,{className:`matrix-spec-bar`,children:[(0,g.jsxs)(`div`,{className:`spec-combobox`,children:[(0,g.jsx)(`span`,{className:`spec-combobox-label`,children:j(`contextWindowLabel`)}),(0,g.jsxs)(`select`,{className:`spec-combobox-select`,value:_.some(t=>t.value===e.contextWindow)?e.contextWindow:`custom`,onChange:e=>{e.target.value!==`custom`&&$(t,{contextWindow:e.target.value})},children:[_.map(e=>(0,g.jsxs)(`option`,{value:e.value,children:[e.label,` (`,Math.round(Number(e.value)/1024),`K)`]},e.value)),(0,g.jsx)(`option`,{value:`custom`,children:j(`customOption`)})]}),(!_.some(t=>t.value===e.contextWindow)||e.contextWindow===``)&&(0,g.jsx)(`input`,{type:`text`,className:`spec-combobox-custom-input`,value:e.contextWindow,onChange:e=>$(t,{contextWindow:e.target.value}),placeholder:j(`contextPlaceholder`)})]}),(0,g.jsxs)(`div`,{className:`spec-combobox`,children:[(0,g.jsx)(`span`,{className:`spec-combobox-label`,children:j(`maxOutputLabel`)}),(0,g.jsxs)(`select`,{className:`spec-combobox-select`,value:v.some(t=>t.value===e.maxTokens)?e.maxTokens:`custom`,onChange:e=>{e.target.value!==`custom`&&$(t,{maxTokens:e.target.value})},children:[v.map(e=>(0,g.jsxs)(`option`,{value:e.value,children:[e.label,` (`,Math.round(Number(e.value)/1024),`K)`]},e.value)),(0,g.jsx)(`option`,{value:`custom`,children:j(`customOption`)})]}),(!v.some(t=>t.value===e.maxTokens)||e.maxTokens===``)&&(0,g.jsx)(`input`,{type:`text`,className:`spec-combobox-custom-input`,value:e.maxTokens,onChange:e=>$(t,{maxTokens:e.target.value}),placeholder:j(`maxOutputPlaceholder`)})]}),(0,g.jsx)(`div`,{className:`matrix-spec-quick-pills`,children:[`32K`,`128K`,`200K`].map(n=>{let r=_.find(e=>e.label===n);return r?(0,g.jsx)(`button`,{type:`button`,className:`param-pill ${e.contextWindow===r.value?`active`:``}`,onClick:()=>$(t,{contextWindow:r.value}),title:j(`contextPresetTooltip`,{label:n}),children:n},n):null})})]}),e.reasoning&&X===t&&(0,g.jsxs)(`div`,{className:`matrix-thinking-config-drawer`,children:[(0,g.jsxs)(`div`,{className:`thinking-drawer-header`,children:[(0,g.jsxs)(`div`,{className:`thinking-drawer-title`,children:[(0,g.jsx)(o,{}),(0,g.jsx)(`span`,{children:j(`thinkingConfigBtn`)||`思考配置`})]}),(0,g.jsx)(`div`,{className:`thinking-drawer-actions`,children:(0,g.jsx)(`button`,{type:`button`,className:`btn xs text-btn`,style:{whiteSpace:`nowrap`},onClick:()=>$(t,{thinkingLevelMap:void 0,compat:void 0,customExtraBody:``}),title:j(`thinkingResetDefault`),children:j(`thinkingResetDefault`)})})]}),(0,g.jsxs)(`div`,{className:`thinking-presets-row`,children:[(0,g.jsx)(`span`,{className:`thinking-presets-label`,children:j(`thinkingQuickApply`)}),(0,g.jsxs)(`div`,{className:`thinking-preset-pills`,children:[ne.map(n=>(0,g.jsx)(`button`,{type:`button`,className:`param-pill`,onClick:()=>{let r={...e.compat??{}};n.thinkingFormat?r.thinkingFormat=n.thinkingFormat:(n.id===`fixed-deepseek`||n.id===`claude-budget`)&&delete r.thinkingFormat,$(t,{thinkingLevelMap:n.map,compat:Object.keys(r).length?r:void 0})},title:n.desc,children:n.name},n.id)),Ve.map(n=>(0,g.jsxs)(`span`,{className:`param-pill user-preset-pill`,children:[(0,g.jsxs)(`button`,{type:`button`,className:`user-preset-btn`,onClick:()=>{let r={...e.compat??{}};n.thinkingFormat?r.thinkingFormat=n.thinkingFormat:delete r.thinkingFormat,$(t,{thinkingLevelMap:n.map,compat:Object.keys(r).length?r:void 0,customExtraBody:n.customExtraBody??``})},title:`套用自定义预设:${n.name}`,children:[`🏷️ `,n.name]}),(0,g.jsx)(`button`,{type:`button`,className:`user-preset-del`,onClick:e=>Je(n.id,e),title:`删除此预设`,children:`×`})]},n.id))]})]}),(0,g.jsxs)(`div`,{className:`thinking-advanced-row`,children:[(0,g.jsxs)(`div`,{className:`thinking-advanced-head`,children:[(0,g.jsxs)(`div`,{className:`thinking-format-selector`,children:[(0,g.jsx)(`span`,{className:`spec-combobox-label`,children:j(`thinkingFormatLabel`)}),(0,g.jsx)(`select`,{className:`spec-combobox-select`,value:e.compat?.thinkingFormat??``,onChange:n=>{let r=n.target.value.trim(),i={...e.compat??{}};r?i.thinkingFormat=r:delete i.thinkingFormat,$(t,{compat:Object.keys(i).length?i:void 0})},children:re.map(e=>(0,g.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),Ge===t?(0,g.jsxs)(`div`,{className:`save-preset-inline`,children:[(0,g.jsx)(`input`,{type:`text`,className:`spec-combobox-custom-input`,style:{width:130,textAlign:`left`},placeholder:`预设名称 (如: 16K模版)`,value:Ue,onChange:e=>We(e.target.value),onKeyDown:e=>{e.key===`Enter`&&qe(t)}}),(0,g.jsx)(`button`,{type:`button`,className:`btn xs`,onClick:()=>qe(t),children:`保存`}),(0,g.jsx)(`button`,{type:`button`,className:`btn xs text-btn`,onClick:()=>Ke(null),children:`取消`})]}):(0,g.jsxs)(`button`,{type:`button`,className:`btn xs`,onClick:()=>{Ke(t),We(``)},title:`将当前模型的思考配置、协议与 JSON 存为一个命名的预设模板`,children:[(0,g.jsx)(n,{}),` 存为我的预设`]})]}),(0,g.jsxs)(`div`,{className:`thinking-raw-body-block`,children:[(0,g.jsxs)(`div`,{style:{display:`flex`,justifyContent:`space-between`,alignItems:`center`},children:[(0,g.jsx)(`span`,{className:`spec-combobox-label`,children:j(`thinkingRawBodyLabel`)}),e.customExtraBody&&(0,g.jsx)(`span`,{style:{fontSize:`10.5px`,color:pe(e.customExtraBody).valid?`var(--green, #22c55e)`:`var(--red, #ef4444)`},children:pe(e.customExtraBody).valid?`✓ JSON语法有效(保存后自动无损合入请求 body)`:`✕ ${pe(e.customExtraBody).error}`})]}),(0,g.jsx)(`textarea`,{className:`thinking-raw-body-textarea`,placeholder:`{"thinking": {"type": "enabled", "budget_tokens": 16000}}`,rows:2,value:e.customExtraBody??``,onChange:e=>$(t,{customExtraBody:e.target.value})})]})]}),(0,g.jsx)(`div`,{className:`thinking-levels-grid`,children:ie.map(n=>{let r=e.thinkingLevelMap,i=!(r&&r[n]===null),a=r&&r[n]!==null&&r[n]!==void 0?String(r[n]):``,o=ae[n],s=o==null?n:String(o);return(0,g.jsxs)(`div`,{className:`thinking-level-col ${i?`enabled`:`disabled`}`,children:[(0,g.jsx)(`div`,{className:`level-col-head`,children:(0,g.jsxs)(`label`,{className:`level-check-label`,children:[(0,g.jsx)(`input`,{type:`checkbox`,checked:i,onChange:r=>{let i={...e.thinkingLevelMap??{}};r.target.checked?delete i[n]:i[n]=null,$(t,{thinkingLevelMap:i})}}),(0,g.jsx)(`span`,{className:`level-name`,children:j(`thinking.${n}`)||n})]})}),i&&(0,g.jsx)(`input`,{type:`text`,className:`level-val-input`,value:a,placeholder:s,title:`自定义发送给模型/网关的字面量或 Token 数(留空为默认)`,onChange:r=>{let i={...e.thinkingLevelMap??{}},a=r.target.value.trim();a?i[n]=a:delete i[n],$(t,{thinkingLevelMap:i})}})]},n)})})]})]},t)),(0,g.jsxs)(`button`,{type:`button`,className:`btn sm`,style:{alignSelf:`flex-start`,marginTop:4},onClick:Bt,children:[(0,g.jsx)(n,{}),` `,j(`addModelRow`)]})]})]})]}),M.type===`builtin`&&(()=>{let e=r.find(e=>e.id===M.id);if(!e)return null;let a=p[e.id]??[];return(0,g.jsxs)(`div`,{className:`studio-card`,children:[(0,g.jsxs)(`div`,{className:`studio-card-head`,children:[(0,g.jsxs)(`div`,{className:`studio-card-title`,children:[(0,g.jsx)(`span`,{children:j(`builtinProviderTitle`,{name:e.name})}),e.configured&&(0,g.jsx)(`span`,{className:`auth-badge`,children:j(`configuredBadge`)}),e.source&&!e.configured&&(0,g.jsx)(`span`,{className:`auth-badge dim`,children:e.source})]}),(0,g.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:6},children:[(0,g.jsxs)(`button`,{type:`button`,className:`btn sm`,title:j(`cloneProvider`),disabled:Dt===e.id,onClick:()=>Mt(e),children:[(0,g.jsx)(i,{}),` `,j(`cloneProvider`)]}),(0,g.jsxs)(`button`,{type:`button`,className:`btn sm`,onClick:()=>{rt(nt===e.id?null:e.id),Q(null)},children:[(0,g.jsx)(n,{}),` `,j(`appendModel`)]}),e.supportsApiKey&&e.source===`stored`&&!e.usingOAuth&&(0,g.jsxs)(`button`,{type:`button`,className:`btn sm danger`,title:j(`clearKeyTitle`),onClick:()=>Gt(e.id),children:[(0,g.jsx)(f,{}),` `,j(`clearKey`)]})]})]}),e.supportsOAuth&&(0,g.jsx)(oe,{provider:e,flow:ee.find(t=>t.provider===e.id),result:te[e.id]}),e.supportsApiKey&&(0,g.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:10},children:[(0,g.jsx)(`span`,{style:{fontSize:12.5,fontWeight:600},children:j(`apiKeyManagement`)}),(0,g.jsxs)(`div`,{className:`provider-keys`,children:[a.length===0&&(0,g.jsx)(`div`,{className:`provider-key-empty`,children:j(`noKeyYet`)}),a.map(n=>(0,g.jsxs)(`div`,{className:`provider-key-item ${n.active?`active`:``}`,children:[(0,g.jsx)(`span`,{className:`provider-key-dot`,children:n.active?`●`:`○`}),(0,g.jsx)(`span`,{className:`provider-key-label`,children:n.name}),!n.active&&(0,g.jsx)(`button`,{type:`button`,className:`iconbtn`,title:j(`activateKey`),onClick:()=>Ut(e.id,n.name),children:(0,g.jsx)(t,{})}),(0,g.jsx)(`button`,{type:`button`,className:`iconbtn danger`,title:j(`removeKey`),onClick:()=>Wt(e.id,n.name),children:(0,g.jsx)(f,{})})]},n.name))]}),(0,g.jsxs)(`div`,{className:`provider-add-key`,style:{marginTop:6},children:[(0,g.jsx)(`input`,{type:`text`,className:`key-input key-input-name`,placeholder:j(`keyNamePh`),value:Ee[e.id]??``,onChange:t=>De(n=>({...n,[e.id]:t.target.value}))}),(0,g.jsx)(`input`,{type:`password`,className:`key-input key-input-value`,placeholder:j(`addKeyPlaceholder`),value:R[e.id]??``,onChange:t=>Te(n=>({...n,[e.id]:t.target.value}))}),(0,g.jsxs)(`button`,{type:`button`,className:`btn primary sm`,disabled:!(R[e.id]??``).trim()||z===e.id,onClick:()=>Ht(e),children:[(0,g.jsx)(n,{}),` `,z===e.id?j(`savingKey`):j(`addKey`)]})]})]}),nt===e.id&&(0,g.jsxs)(`div`,{style:{marginTop:12,padding:12,background:`var(--bg)`,borderRadius:8,border:`1px dashed var(--border-soft)`},children:[(0,g.jsx)(`span`,{style:{fontSize:12,fontWeight:600,display:`block`,marginBottom:8},children:j(`addBuiltinOverlay`)}),(0,g.jsxs)(`div`,{style:{display:`flex`,gap:8,flexWrap:`wrap`},children:[(0,g.jsx)(`input`,{type:`text`,className:`key-input`,placeholder:j(`overlayModelIdPlaceholder`),value:it,onChange:e=>at(e.target.value)}),(0,g.jsx)(`input`,{type:`text`,className:`key-input`,placeholder:j(`overlayModelNamePlaceholder`),value:Z,onChange:e=>ot(e.target.value)}),(0,g.jsxs)(`button`,{type:`button`,className:`btn primary sm`,disabled:!it.trim()||dt,onClick:()=>qt(e.id),children:[(0,g.jsx)(n,{}),` `,j(`submitOverlayBtn`)]})]}),ht&&(0,g.jsx)(`span`,{style:{fontSize:12,color:ht.ok?`var(--green)`:`var(--red)`,marginTop:6},children:ht.text})]})]})})()]})]}),ve&&(0,g.jsx)(he,{candidates:ve,preselectedIds:P?.models.map(e=>e.id.trim()).filter(Boolean)??[],onAdopt:Ft,onClose:()=>ye(null)})]})})}export{C as ModelConfigModal};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{A as t,Bt as n,Gt as r,H as i,K as a,Qt as o,Sn as s,Vt as c,X as l,d as u,fn as d,in as f,pn as p,t as m}from"./app-globals-KqOVtmp1.js";import{i as ee,t as te}from"./react-CR5VJ85Q.js";import{Dt as ne,Et as re,Ot as ie,Tt as ae}from"./index-BawF7ZP5.js";import{t as oe}from"./ProviderOAuthControls-DY4SCfXg.js";var h=e(ee(),1);function se(e,t,n){if(JSON.stringify(e)===JSON.stringify(t))return n;let r=new Map(t.map(e=>[e.id,e])),i=new Map(n.map(e=>[e.id,e])),a=new Set(e.map(e=>e.id)),o=e.flatMap(e=>{let t=r.get(e.id);if(!t||JSON.stringify(t)!==JSON.stringify(e))return[e];let n=i.get(e.id);return n?[n]:[]});for(let e of n)!r.has(e.id)&&!a.has(e.id)&&o.push(e);return o}var g=te(),ce=[`openai-completions`,`openai-responses`,`anthropic-messages`,`google-generative-ai`],le=[{id:`openai`,name:`OpenAI`,api:`openai-responses`,baseUrl:`https://api.openai.com/v1`,authHeader:!0,tag:`官方`},{id:`anthropic`,name:`Anthropic`,api:`anthropic-messages`,baseUrl:`https://api.anthropic.com`,authHeader:!0,tag:`官方`},{id:`google`,name:`Google Gemini`,api:`google-generative-ai`,baseUrl:`https://generativelanguage.googleapis.com/v1beta`,authHeader:!0,tag:`官方`},{id:`dashscope`,name:`Alibaba Cloud Bailian (CN)`,api:`openai-completions`,baseUrl:`https://dashscope.aliyuncs.com/compatible-mode/v1`,authHeader:!0,tag:`官方`},{id:`dashscope-intl`,name:`Alibaba Cloud Bailian (Singapore)`,api:`openai-completions`,baseUrl:`https://dashscope-intl.aliyuncs.com/compatible-mode/v1`,authHeader:!0,tag:`官方`},{id:`minimax-cn`,name:`MiniMax (CN)`,api:`anthropic-messages`,baseUrl:`https://api.minimax.cn/anthropic`,authHeader:!0,tag:`官方`},{id:`minimax`,name:`MiniMax (International)`,api:`anthropic-messages`,baseUrl:`https://api.minimax.io/anthropic`,authHeader:!0,tag:`官方`},{id:`mistral`,name:`Mistral`,api:`openai-completions`,baseUrl:`https://api.mistral.ai/v1`,authHeader:!0,tag:`官方`},{id:`groq`,name:`Groq`,api:`openai-completions`,baseUrl:`https://api.groq.com/openai/v1`,authHeader:!0,tag:`官方`},{id:`xai`,name:`xAI`,api:`openai-completions`,baseUrl:`https://api.x.ai/v1`,authHeader:!0,tag:`官方`},{id:`magpie`,name:`Magpie`,api:`openai-completions`,baseUrl:`http://127.0.0.1:3425/v1`,authHeader:!0,apiKey:`magpie`},{id:`deepseek`,name:`DeepSeek`,api:`openai-completions`,baseUrl:`https://api.deepseek.com/v1`,authHeader:!0,tag:`官方`},{id:`openrouter`,name:`OpenRouter`,api:`openai-completions`,baseUrl:`https://openrouter.ai/api/v1`,authHeader:!0,tag:`聚合`},{id:`moonshot`,name:`Moonshot (Kimi)`,api:`openai-completions`,baseUrl:`https://api.moonshot.cn/v1`,authHeader:!0,tag:`官方`},{id:`zhipu`,name:`智谱 GLM`,api:`openai-completions`,baseUrl:`https://open.bigmodel.cn/api/paas/v4`,authHeader:!0,tag:`官方`},{id:`siliconflow`,name:`硅基流动`,api:`openai-completions`,baseUrl:`https://api.siliconflow.cn/v1`,authHeader:!0,tag:`云端`},{id:`ollama`,name:`Ollama`,api:`openai-completions`,baseUrl:`http://127.0.0.1:11434/v1`,authHeader:!0,tag:`本地`},{id:`vllm`,name:`vLLM / LM Studio`,api:`openai-completions`,baseUrl:`http://127.0.0.1:8000/v1`,authHeader:!0,tag:`本地`},{id:`antigravity`,name:`Antigravity (OpenAI)`,api:`openai-completions`,baseUrl:`http://127.0.0.1:8045/v1`,authHeader:!0,tag:`反代`},{id:`antigravity-anthropic`,name:`Antigravity (Anthropic)`,api:`anthropic-messages`,baseUrl:`http://127.0.0.1:8045`,authHeader:!0,tag:`反代`}],_=[{label:`8K`,value:`8192`},{label:`16K`,value:`16384`},{label:`32K`,value:`32768`},{label:`64K`,value:`65536`},{label:`128K`,value:`131072`},{label:`200K`,value:`200000`},{label:`1M`,value:`1000000`}],v=[{label:`2K`,value:`2048`},{label:`4K`,value:`4096`},{label:`8K`,value:`8192`},{label:`16K`,value:`16384`},{label:`32K`,value:`32768`},{label:`64K`,value:`65536`}];function ue(e,t){switch(e){case`官方`:return t(`presetTagOfficial`);case`聚合`:return t(`presetTagAggregator`);case`云端`:return t(`presetTagCloud`);case`本地`:return t(`presetTagLocal`);case`反代`:return t(`presetTagProxy`);default:return e}}var y=`pi_web_ui_thinking_custom_presets`;function de(){if(typeof localStorage>`u`)return[];try{let e=localStorage.getItem(y);return e?JSON.parse(e):[]}catch{return[]}}function fe(e){if(typeof localStorage<`u`)try{localStorage.setItem(y,JSON.stringify(e))}catch{}}function pe(e){if(!e.trim())return{valid:!0};try{let t=JSON.parse(e.trim());return!t||typeof t!=`object`||Array.isArray(t)?{valid:!1,error:`必须是 JSON 对象 (以 { 开头)`}:{valid:!0}}catch(e){return{valid:!1,error:e.message}}}var b=()=>({id:``,name:``,reasoning:!1,input:`text`,contextWindow:``,maxTokens:``}),x=()=>({providerId:``,name:``,api:`openai-completions`,baseUrl:``,apiKey:``,hasApiKey:!1,authHeader:!0,models:[b()]});function S(e){return{providerId:e.providerId,name:e.name??``,api:e.api??`openai-completions`,baseUrl:e.baseUrl??``,apiKey:``,hasApiKey:e.hasApiKey??!1,authHeader:e.authHeader??!1,models:(e.models.length?e.models:[b()]).map(e=>({id:e.id,name:e.name??``,reasoning:e.reasoning??!1,input:e.input?.includes(`image`)?`text-image`:`text`,contextWindow:e.contextWindow?String(e.contextWindow):``,maxTokens:e.maxTokens?String(e.maxTokens):``,...e.thinkingLevelMap?{thinkingLevelMap:e.thinkingLevelMap}:{},...e.compat?{compat:e.compat}:{},...e.customExtraBody?{customExtraBody:e.customExtraBody}:{}}))}}function me(e){let t={};for(let n of e.split(`
|
|
2
|
+
`)){let e=n.indexOf(`=`);if(e<=0)continue;let r=n.slice(0,e).trim(),i=n.slice(e+1).trim();r&&i&&(t[r]=i)}return t}function he({candidates:e,preselectedIds:t,onAdopt:n,onClose:i}){let a=s(),[o,c]=(0,h.useState)(``),[l,u]=(0,h.useState)(()=>{let n=new Set(e.map(e=>e.id)),r=(t??[]).map(e=>e.trim()).filter(e=>n.has(e));if(r.length>0)return new Set(r);let i=new Set;for(let t of e){let e=t.id.toLowerCase();!e.includes(`embed`)&&!e.includes(`audio`)&&!e.includes(`tts`)&&!e.includes(`whisper`)&&i.add(t.id)}if(i.size===0)for(let t of e)i.add(t.id);return i}),f=(0,h.useMemo)(()=>{let t=o.trim().toLowerCase();return t?e.filter(e=>e.id.toLowerCase().includes(t)||e.name&&e.name.toLowerCase().includes(t)):e},[e,o]),m=e=>{u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,g.jsx)(`div`,{className:`candidate-picker-backdrop`,onClick:i,children:(0,g.jsxs)(`div`,{className:`candidate-picker-modal`,onClick:e=>e.stopPropagation(),children:[(0,g.jsxs)(`div`,{className:`candidate-header`,children:[(0,g.jsxs)(`div`,{className:`candidate-title-group`,children:[(0,g.jsx)(`span`,{className:`candidate-title`,children:a(`candidatePickerTitle`)}),(0,g.jsx)(`span`,{className:`candidate-subtitle`,children:a(`candidatePickerSubtitle`,{n:e.length})})]}),(0,g.jsx)(`button`,{type:`button`,className:`iconbtn`,onClick:i,"aria-label":a(`close`),children:(0,g.jsx)(d,{})})]}),(0,g.jsxs)(`div`,{className:`candidate-filter-bar`,children:[(0,g.jsx)(r,{style:{color:`var(--text-faint)`,flexShrink:0}}),(0,g.jsx)(`input`,{type:`text`,className:`candidate-search-input`,placeholder:a(`searchCandidatePlaceholder`),value:o,onChange:e=>c(e.target.value),autoFocus:!0}),(0,g.jsxs)(`div`,{style:{display:`flex`,gap:6,flexShrink:0},children:[(0,g.jsx)(`button`,{type:`button`,className:`btn sm`,onClick:()=>{u(new Set(f.map(e=>e.id)))},children:a(`selectAll`)}),(0,g.jsx)(`button`,{type:`button`,className:`btn sm`,onClick:()=>{u(new Set)},children:a(`deselectAll`)})]})]}),(0,g.jsxs)(`div`,{className:`candidate-list-scroll`,children:[f.length===0&&(0,g.jsx)(`div`,{style:{padding:`32px 0`,textAlign:`center`,color:`var(--text-faint)`,fontSize:13},children:a(`noCandidateMatches`)}),f.map(e=>{let t=l.has(e.id);return(0,g.jsxs)(`div`,{className:`candidate-item-card ${t?`selected`:``}`,onClick:()=>m(e.id),children:[(0,g.jsxs)(`div`,{className:`candidate-item-left`,children:[(0,g.jsx)(`input`,{type:`checkbox`,className:`candidate-checkbox`,checked:t,onChange:()=>{},onClick:e=>e.stopPropagation()}),(0,g.jsxs)(`div`,{className:`candidate-id-info`,children:[(0,g.jsx)(`span`,{className:`candidate-id-name`,children:e.id}),e.name&&e.name!==e.id&&(0,g.jsx)(`span`,{style:{fontSize:11.5,color:`var(--text-dim)`},children:e.name})]})]}),(0,g.jsxs)(`div`,{className:`candidate-item-meta`,children:[e.contextWindow&&(0,g.jsx)(`span`,{className:`spec-badge ctx`,title:a(`contextWindowTooltip`),children:e.contextWindow>=1e6?`${Math.round(e.contextWindow/1e6)}M`:`${Math.round(e.contextWindow/1024)}K`}),e.reasoning&&(0,g.jsxs)(`span`,{className:`spec-badge reasoning`,title:a(`reasoningTooltip`),children:[(0,g.jsx)(p,{}),` `,a(`reasoning`)]}),e.input?.includes(`image`)&&(0,g.jsx)(`span`,{className:`spec-badge vision`,title:a(`visionTooltip`),children:a(`vision`)})]})]},e.id)})]}),(0,g.jsxs)(`div`,{className:`candidate-actions-footer`,children:[(0,g.jsx)(`span`,{className:`candidate-select-summary`,children:a(`selectedCandidatesCount`,{count:l.size,total:e.length})}),(0,g.jsxs)(`div`,{style:{display:`flex`,gap:8},children:[(0,g.jsx)(`button`,{type:`button`,className:`btn`,onClick:i,children:a(`cancel`)}),(0,g.jsx)(`button`,{type:`button`,className:`btn primary`,disabled:l.size===0,onClick:()=>{n(e.filter(e=>l.has(e.id)))},children:a(`adoptSelectedModels`,{count:l.size})})]})]})]})})}function C({providers:e,providerStatus:r,providerKeys:p,providerOAuthFlows:ee,providerOAuthResults:te,fetchModelsResult:y,testModelConnectionResult:C,enrichModelsResult:w,enrichModelsProgress:ge,cloneProviderResult:T,refreshBuiltinResult:E,refreshProviderResult:D,appendBuiltinResult:O,defaultModel:k,onClose:A}){let j=s(),[M,N]=(0,h.useState)(()=>e.length>0?{type:`custom`,id:e[0].providerId}:r.length>0?{type:`builtin`,id:r[0].id}:{type:`custom`,id:``}),[P,F]=(0,h.useState)(()=>e.length>0?S(e[0]):r.length>0?null:x()),_e=(0,h.useRef)(e);(0,h.useEffect)(()=>{let t=_e.current;_e.current=e,F(n=>{if(!n)return n;let r=e.find(e=>e.providerId===n.providerId),i=t.find(e=>e.providerId===n.providerId);return!r||r===i?n:{...n,hasApiKey:r.hasApiKey??!1,models:se(n.models,i?S(i).models:[],S(r).models)}})},[e]);let[ve,ye]=(0,h.useState)(null),[be,xe]=(0,h.useState)(!1),[Se,Ce]=(0,h.useState)(0),[I,L]=(0,h.useState)(null),we=(0,h.useRef)(0),[R,Te]=(0,h.useState)({}),[Ee,De]=(0,h.useState)({}),[z,B]=(0,h.useState)(null),Oe=(0,h.useRef)(p),V=(0,h.useRef)(null);(0,h.useEffect)(()=>{let e=z;e&&p[e]!==Oe.current[e]&&(B(null),Te(t=>({...t,[e]:``})),De(t=>({...t,[e]:``})),V.current&&clearTimeout(V.current)),Oe.current=p},[p,z]),(0,h.useEffect)(()=>()=>{V.current&&clearTimeout(V.current)},[]);let[H,ke]=(0,h.useState)(!1),[Ae,je]=(0,h.useState)(0),[U,W]=(0,h.useState)(null),Me=(0,h.useRef)(0),[G,Ne]=(0,h.useState)(!1),[K,q]=(0,h.useState)(!1),[Pe,Fe]=(0,h.useState)(0),[J,Y]=(0,h.useState)(null),[Ie,Le]=(0,h.useState)([]),[Re]=(0,h.useState)(``),ze=(0,h.useRef)(0),[X,Be]=(0,h.useState)(null),[Ve,He]=(0,h.useState)(de),[Ue,We]=(0,h.useState)(``),[Ge,Ke]=(0,h.useState)(null),qe=e=>{let t=Ue.trim();if(!t||!P)return;let n=P.models[e];if(!n)return;let r={id:`preset-${Date.now()}`,name:t,thinkingFormat:n.compat?.thinkingFormat||void 0,customExtraBody:n.customExtraBody?.trim()||void 0,map:n.thinkingLevelMap??{}},i=[...Ve,r];He(i),fe(i),We(``),Ke(null)},Je=(e,t)=>{t.stopPropagation();let n=Ve.filter(t=>t.id!==e);He(n),fe(n)},[Ye,Xe]=(0,h.useState)(!1),[Ze,Qe]=(0,h.useState)(0),[$e,et]=(0,h.useState)(null),tt=(0,h.useRef)(0),[nt,rt]=(0,h.useState)(null),[it,at]=(0,h.useState)(``),[Z,ot]=(0,h.useState)(``),[st,ct]=(0,h.useState)(``),[lt,ut]=(0,h.useState)(``),[dt,ft]=(0,h.useState)(!1),[pt,mt]=(0,h.useState)(0),[ht,Q]=(0,h.useState)(null),gt=(0,h.useRef)(0),[_t,vt]=(0,h.useState)(null),[yt,bt]=(0,h.useState)(``),[xt,St]=(0,h.useState)(null),[Ct,wt]=(0,h.useState)({}),Tt=(0,h.useRef)(0),Et=(0,h.useRef)(0),[Dt,Ot]=(0,h.useState)(null),kt=(0,h.useRef)(0),At=(0,h.useRef)(0),jt=e=>{if(Ct[e])return;let t=++Tt.current+Date.now();wt(t=>({...t,[e]:!0})),m({type:`refresh_provider_models`,providerId:e,reqId:t})};(0,h.useEffect)(()=>{D&&D.reqId!==Et.current&&(Et.current=D.reqId,wt({}))},[D]);let Mt=e=>{if(Dt)return;Ot(e.id);let t=++kt.current+Date.now();m({type:`clone_provider`,provider:e.id,reqId:t})||Ot(null)};(0,h.useEffect)(()=>{m({type:`list_models_config`}),m({type:`list_providers`}),m({type:`list_provider_keys`}),m({type:`list_provider_oauth_flows`})},[]),(0,h.useEffect)(()=>{C&&C.reqId!==we.current&&(we.current=C.reqId,xe(!1),L({ok:C.ok,latencyMs:C.latencyMs,error:C.error}))},[C]),(0,h.useEffect)(()=>{y&&y.reqId!==Me.current&&(Me.current=y.reqId,ke(!1),y.ok&&y.models?.length?(ye(y.models),W({ok:!0,text:j(`fetchModelsOk`,{n:y.models.length})})):W({ok:!1,text:y.error||j(`fetchModelsEmpty`)}))},[y,j]),(0,h.useEffect)(()=>{if(w&&w.reqId!==ze.current){if(ze.current=w.reqId,Ne(!1),q(!1),w.ok&&w.results?.length){let e=w.results,t=new Map(e.map(e=>[e.id.trim(),e]));F(e=>e&&{...e,models:e.models.map(e=>{let n=t.get(e.id.trim());return!n||n.status!==`matched`?e:{...e,name:e.name||n.name||``,contextWindow:e.contextWindow||(n.contextWindow?String(n.contextWindow):``),maxTokens:e.maxTokens||(n.maxTokens?String(n.maxTokens):``),input:e.input===`text`&&n.input?.includes(`image`)?`text-image`:e.input,reasoning:e.reasoning||(n.reasoning??!1),thinkingLevelMap:e.thinkingLevelMap||n.thinkingLevelMap,src:n.source}})});let n=e.filter(e=>e.status===`matched`).length,r=e.length-n;Y({ok:!0,text:j(`enrichModelsOk`,{n,m:r})});let i=e.filter(e=>e.status!==`matched`&&(e.suggestions?.length||e.note)).map(e=>({id:e.id,suggestions:e.suggestions??[],note:e.note}));Le(i)}else Y({ok:!1,text:w.error||j(`enrichModelsErr`,{msg:``})})}},[w,j]),(0,h.useEffect)(()=>{E&&E.reqId!==tt.current&&(tt.current=E.reqId,Xe(!1),E.ok?et({ok:!0,text:j(`refreshBuiltinOk`)}):et({ok:!1,text:E.error||j(`refreshBuiltinFail`)}))},[E,j]),(0,h.useEffect)(()=>{O&&O.reqId!==gt.current&&(gt.current=O.reqId,ft(!1),O.ok?(Q({ok:!0,text:j(`appendModelOk`)}),at(``),ot(``),ct(``),ut(``),rt(null),m({type:`list_models_config`})):Q({ok:!1,text:O.error||j(`appendModelFail`)}))},[O,j]),(0,h.useEffect)(()=>{if(T&&T.reqId!==At.current&&(At.current=T.reqId,Ot(null),T.ok)){let e=T.configs;if(e&&e.length>1){vt(e.map(e=>S(e))),bt(``);return}T.config&&St(S(T.config))}},[T]);let Nt=()=>{if(!P)return;let e=P.baseUrl.trim();if(!e){L({ok:!1,error:j(`fetchModelsNeedBaseUrl`)});return}xe(!0),L(null);let t=Se+1;Ce(t),m({type:`test_model_connection`,reqId:t,baseUrl:e,apiKey:P.apiKey.trim()||void 0,...P.apiKey.trim()?{}:P.hasApiKey?{providerId:P.providerId.trim()}:{},authHeader:P.authHeader,api:P.api})},Pt=()=>{if(!P)return;let e=P.baseUrl.trim();if(!e){W({ok:!1,text:j(`fetchModelsNeedBaseUrl`)});return}if(H)return;ke(!0),W(null);let t=Ae+1;je(t),m({type:`fetch_models`,reqId:t,baseUrl:e,apiKey:P.apiKey.trim()||void 0,...P.apiKey.trim()?{}:P.hasApiKey?{providerId:P.providerId.trim()}:{},authHeader:P.authHeader,api:P.api})},Ft=e=>{P&&(F(t=>{if(!t)return t;let n=t.models.filter(e=>e.id.trim()),r=new Set(n.map(e=>e.id.trim())),i=e.filter(e=>!r.has(e.id)).map(e=>({id:e.id,name:e.name??``,reasoning:e.reasoning??!1,input:e.input?.includes(`image`)?`text-image`:`text`,contextWindow:e.contextWindow?String(e.contextWindow):``,maxTokens:e.maxTokens?String(e.maxTokens):``,...e.thinkingLevelMap?{thinkingLevelMap:e.thinkingLevelMap}:{}}));return{...t,models:n.length===0?i:[...n,...i]}}),ye(null))},It=()=>{if(!P||G)return;let e=P.models.map(e=>e.id.trim()).filter(Boolean);if(e.length===0){Y({ok:!1,text:j(`enrichModelsNeedIds`)});return}Ne(!0),q(!1),Y(null),Le([]);let t=Pe+1;Fe(t),m({type:`enrich_models`,reqId:t,ids:e,hints:me(Re)})},Lt=()=>{G&&!K&&(q(!0),m({type:`abort_enrich_models`,reqId:Pe}))},Rt=e=>{F(t=>({providerId:t?.providerId.trim()||e.id,name:t?.name.trim()||e.name,api:e.api,baseUrl:e.baseUrl,apiKey:t?.apiKey||(t?.hasApiKey?``:e.apiKey)||``,hasApiKey:t?.hasApiKey??!1,authHeader:e.authHeader,models:t?.models.length?t.models:[b()]})),L(null),W(null)},zt=()=>{if(!P)return;let e=P.providerId.trim();if(!e)return;let t=P.models.filter(e=>e.id.trim()).map(e=>({id:e.id.trim(),name:e.name.trim()||void 0,reasoning:e.reasoning||void 0,input:e.input===`text-image`?[`text`,`image`]:void 0,contextWindow:e.contextWindow?Number(e.contextWindow):void 0,maxTokens:e.maxTokens?Number(e.maxTokens):void 0,...e.thinkingLevelMap?{thinkingLevelMap:e.thinkingLevelMap}:{},...e.compat?{compat:e.compat}:{},...e.customExtraBody?.trim()?{customExtraBody:e.customExtraBody.trim()}:{}})),n={providerId:e,name:P.name.trim()||void 0,api:P.api.trim()||void 0,baseUrl:P.baseUrl.trim()||void 0,...P.apiKey.trim()?{apiKey:P.apiKey.trim()}:{},authHeader:P.authHeader||void 0,models:t};m({type:`save_model_config`,providerId:e,config:n}),A()},$=(e,t)=>{P&&F({...P,models:P.models.map((n,r)=>r===e?{...n,...t}:n)})},Bt=()=>{P&&F({...P,models:[...P.models,b()]})},Vt=e=>{P&&F({...P,models:P.models.filter((t,n)=>n!==e)})},Ht=e=>{let t=(R[e.id]??``).trim();t&&!z&&(B(e.id),m({type:`add_provider_key`,provider:e.id,apiKey:t,name:(Ee[e.id]??``).trim()||void 0}),V.current&&clearTimeout(V.current),V.current=setTimeout(()=>{B(t=>t===e.id?null:t)},1e4))},Ut=(e,t)=>{m({type:`activate_provider_key`,provider:e,keyName:t}),m({type:`list_provider_keys`})},Wt=(e,t)=>{window.confirm(j(`removeKeyConfirm`))&&(m({type:`remove_provider_key`,provider:e,keyName:t}),m({type:`list_provider_keys`}))},Gt=e=>{window.confirm(j(`clearKeyConfirm`,{id:e}))&&m({type:`clear_provider_api_key`,provider:e})},Kt=t=>{if(window.confirm(j(`deleteProviderConfirm`,{id:t.providerId,n:t.models.length}))&&(m({type:`delete_model_config`,providerId:t.providerId}),M.type===`custom`&&M.id===t.providerId)){let n=e.filter(e=>e.providerId!==t.providerId);n.length>0?(N({type:`custom`,id:n[0].providerId}),F(S(n[0]))):(N({type:`custom`,id:``}),F(x()))}},qt=e=>{let t=it.trim();if(!t||dt)return;ft(!0),Q(null);let n=pt+1;mt(n),m({type:`append_builtin_model`,providerId:e,model:{id:t,...Z.trim()?{name:Z.trim()}:{},...st?{api:st}:{},...lt.trim()?{baseUrl:lt.trim()}:{}},reqId:n})};return(0,g.jsx)(`div`,{className:`modal-backdrop`,onClick:A,children:(0,g.jsxs)(`div`,{className:`modal model-studio-modal`,onClick:e=>e.stopPropagation(),children:[(0,g.jsxs)(`div`,{className:`studio-header`,children:[(0,g.jsxs)(`div`,{className:`studio-header-left`,children:[(0,g.jsx)(`div`,{className:`studio-header-icon-box`,children:(0,g.jsx)(a,{})}),(0,g.jsxs)(`div`,{className:`studio-header-title-wrap`,children:[(0,g.jsx)(`h2`,{className:`studio-header-title`,children:j(`modelManagementTitle`)}),(0,g.jsx)(`span`,{className:`studio-header-badge`,children:`Studio`})]})]}),(0,g.jsxs)(`div`,{className:`studio-header-actions`,children:[k!==void 0&&k&&(0,g.jsxs)(`div`,{style:{display:`inline-flex`,alignItems:`center`,gap:5,padding:`3px 8px`,borderRadius:6,background:`rgba(251, 191, 36, 0.08)`,border:`1px solid rgba(251, 191, 36, 0.3)`,fontSize:11.5,color:`var(--amber)`},title:j(`defaultModelLabel`,{model:k}),children:[(0,g.jsx)(`span`,{children:`★`}),(0,g.jsx)(`span`,{style:{maxWidth:120,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,fontFamily:`var(--mono)`},children:k.split(`/`).slice(1).join(`/`)}),(0,g.jsx)(`button`,{type:`button`,style:{background:`transparent`,border:`none`,color:`var(--amber)`,cursor:`pointer`,fontSize:10,padding:`0 2px`,opacity:.7},title:j(`clearDefaultModel`),onClick:()=>m({type:`clear_default_model`}),children:`✕`})]}),(0,g.jsxs)(`button`,{type:`button`,className:`studio-header-btn`,title:j(`refreshBuiltinHint`),disabled:Ye,onClick:()=>{if(Ye)return;Xe(!0),et(null);let e=Ze+1;Qe(e),m({type:`refresh_builtin_models`,reqId:e})},children:[(0,g.jsx)(l,{}),(0,g.jsx)(`span`,{children:j(Ye?`refreshBuiltinBusy`:`refreshBuiltinCatalog`)})]}),(0,g.jsx)(`button`,{type:`button`,className:`studio-header-iconbtn`,title:j(`reloadModelsHint`),onClick:()=>m({type:`reload_models_config`}),children:(0,g.jsx)(c,{})}),(0,g.jsx)(`button`,{type:`button`,className:`studio-header-iconbtn close-btn`,"aria-label":j(`close`),onClick:A,children:(0,g.jsx)(d,{})})]})]}),$e&&(0,g.jsx)(`div`,{style:{padding:`6px 20px`,background:`var(--bg-elev2)`,fontSize:12,borderBottom:`1px solid var(--border-soft)`},children:(0,g.jsx)(`span`,{className:`fetch-msg ${$e.ok?`ok`:`err`}`,children:$e.text})}),(0,g.jsxs)(`div`,{className:`model-studio-body`,children:[(0,g.jsxs)(`div`,{className:`model-studio-sidebar`,children:[(0,g.jsx)(`div`,{style:{padding:`12px 10px 6px`},children:(0,g.jsxs)(`button`,{type:`button`,className:`btn primary sm`,style:{width:`100%`,justifyContent:`center`},onClick:()=>{N({type:`custom`,id:``}),F(x()),L(null),W(null)},children:[(0,g.jsx)(n,{}),` `,j(`addCustomProvider`)]})}),(0,g.jsxs)(`div`,{className:`studio-sidebar-section`,children:[(0,g.jsx)(`span`,{className:`studio-sidebar-title`,children:j(`customProvidersCount`,{n:e.length})}),e.length===0&&(0,g.jsx)(`div`,{style:{fontSize:11.5,color:`var(--text-faint)`,padding:`6px 8px`},children:j(`noCustomProviders`)}),e.map(e=>{let t=M.type===`custom`&&M.id===e.providerId;return(0,g.jsxs)(`div`,{className:`studio-nav-item ${t?`active`:``}`,onClick:()=>{N({type:`custom`,id:e.providerId}),F(S(e)),L(null),W(null)},children:[(0,g.jsxs)(`span`,{className:`studio-nav-label`,children:[(0,g.jsx)(`span`,{className:`studio-nav-dot configured`}),(0,g.jsx)(`span`,{children:e.name||e.providerId})]}),(0,g.jsxs)(`span`,{style:{fontSize:10.5,color:`var(--text-faint)`,fontFamily:`var(--mono)`},children:[e.models.length,`m`]})]},e.providerId)})]}),(0,g.jsxs)(`div`,{className:`studio-sidebar-section`,children:[(0,g.jsx)(`span`,{className:`studio-sidebar-title`,children:j(`builtinProvidersCount`,{n:r.length})}),r.map(e=>{let t=M.type===`builtin`&&M.id===e.id,n=p[e.id]??[];return(0,g.jsxs)(`div`,{className:`studio-nav-item ${t?`active`:``}`,onClick:()=>{N({type:`builtin`,id:e.id}),F(null)},children:[(0,g.jsxs)(`span`,{className:`studio-nav-label`,children:[(0,g.jsx)(`span`,{className:`studio-nav-dot ${e.configured?`configured`:``}`}),(0,g.jsx)(`span`,{children:e.name})]}),n.length>0&&(0,g.jsxs)(`span`,{style:{fontSize:10.5,color:`var(--text-faint)`,fontFamily:`var(--mono)`},children:[n.length,`k`]})]},e.id)})]})]}),(0,g.jsxs)(`div`,{className:`model-studio-main`,children:[P&&(0,g.jsxs)(`div`,{className:`studio-card`,children:[(0,g.jsxs)(`div`,{className:`studio-card-head`,children:[(0,g.jsxs)(`div`,{className:`studio-card-title`,children:[(0,g.jsx)(`span`,{children:P.providerId?j(`editProviderTitle`,{id:P.providerId}):j(`newCustomProviderTitle`)}),P.providerId&&e.some(e=>e.providerId===P.providerId)&&(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(`button`,{type:`button`,className:`iconbtn sm`,title:j(`refreshModels`),disabled:Ct[P.providerId],onClick:()=>jt(P.providerId),children:(0,g.jsx)(c,{className:Ct[P.providerId]?`spin`:``})}),(0,g.jsx)(`button`,{type:`button`,className:`iconbtn danger sm`,title:j(`deleteProviderTooltip`),onClick:()=>{let t=e.find(e=>e.providerId===P.providerId);t&&Kt(t)},children:(0,g.jsx)(f,{})})]})]}),(0,g.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8},children:[(0,g.jsxs)(`div`,{className:`conn-test-box`,children:[(0,g.jsxs)(`button`,{type:`button`,className:`conn-test-btn`,disabled:be||!P.baseUrl.trim(),onClick:Nt,children:[(0,g.jsx)(u,{}),` `,j(be?`testingConnection`:`testConnection`)]}),I&&(0,g.jsxs)(`span`,{className:`ping-indicator ${I.ok?`ok`:`err`}`,children:[(0,g.jsx)(`span`,{className:`ping-dot`}),(0,g.jsx)(`span`,{children:I.ok?j(`connSuccess`,{latency:I.latencyMs??0}):j(`connFailed`)})]})]}),(0,g.jsx)(`button`,{type:`button`,className:`btn primary sm`,onClick:zt,children:j(`save`)})]})]}),(0,g.jsxs)(`div`,{className:`quick-chips-wrapper`,children:[(0,g.jsx)(`span`,{className:`quick-chips-label`,children:j(`quickPresetsLabel`)}),(0,g.jsx)(`div`,{className:`quick-chips-grid`,children:le.map(e=>(0,g.jsxs)(`button`,{type:`button`,className:`quick-chip`,onClick:()=>Rt(e),children:[(0,g.jsx)(`span`,{className:`quick-chip-name`,children:e.name}),e.tag&&(0,g.jsx)(`span`,{className:`quick-chip-tag`,children:ue(e.tag,j)})]},e.id))})]}),(0,g.jsxs)(`div`,{className:`form-grid`,children:[(0,g.jsxs)(`label`,{className:`field`,children:[(0,g.jsxs)(`span`,{className:`field-label`,children:[j(`providerId`),` `,(0,g.jsx)(`em`,{children:j(`providerIdHint`)})]}),(0,g.jsx)(`input`,{type:`text`,value:P.providerId,disabled:e.some(e=>e.providerId===P.providerId),onChange:e=>F({...P,providerId:e.target.value}),placeholder:j(`providerIdPlaceholder`)})]}),(0,g.jsxs)(`label`,{className:`field`,children:[(0,g.jsx)(`span`,{className:`field-label`,children:j(`displayName`)}),(0,g.jsx)(`input`,{type:`text`,value:P.name,onChange:e=>F({...P,name:e.target.value}),placeholder:j(`displayNamePh`)})]}),(0,g.jsxs)(`label`,{className:`field`,children:[(0,g.jsx)(`span`,{className:`field-label`,children:j(`apiType`)}),(0,g.jsx)(`select`,{value:P.api,onChange:e=>F({...P,api:e.target.value}),children:ce.map(e=>(0,g.jsx)(`option`,{value:e,children:e},e))})]}),(0,g.jsxs)(`label`,{className:`field`,children:[(0,g.jsxs)(`span`,{className:`field-label`,children:[`baseUrl `,(0,g.jsx)(`em`,{children:j(`baseUrlHint`)})]}),(0,g.jsx)(`input`,{type:`text`,value:P.baseUrl,onChange:e=>F({...P,baseUrl:e.target.value}),placeholder:`https://api.deepseek.com/v1`})]}),(0,g.jsxs)(`label`,{className:`field`,children:[(0,g.jsx)(`span`,{className:`field-label`,children:j(`apiKey`)}),(0,g.jsx)(`input`,{type:`password`,value:P.apiKey,onChange:e=>F({...P,apiKey:e.target.value}),placeholder:P.hasApiKey?j(`apiKeySavedHint`):j(`apiKeyHint`)})]}),(0,g.jsxs)(`label`,{className:`field check`,style:{alignSelf:`center`,paddingTop:16},children:[(0,g.jsx)(`input`,{type:`checkbox`,checked:P.authHeader,onChange:e=>F({...P,authHeader:e.target.checked})}),(0,g.jsx)(`span`,{children:j(`authHeader`)})]})]}),(0,g.jsxs)(`div`,{style:{marginTop:8},children:[(0,g.jsxs)(`div`,{className:`model-section-head`,children:[(0,g.jsx)(`span`,{className:`form-section-title`,style:{fontSize:13,fontWeight:600},children:j(`modelMatrixCount`,{n:P.models.filter(e=>e.id.trim()).length})}),(0,g.jsxs)(`div`,{className:`model-section-actions`,children:[U&&(0,g.jsx)(`span`,{className:`fetch-msg ${U.ok?`ok`:`err`}`,title:U.text,children:U.text}),J&&(0,g.jsx)(`span`,{className:`fetch-msg ${J.ok?`ok`:`err`}`,title:J.text,children:J.text}),(0,g.jsxs)(`button`,{type:`button`,className:`btn sm`,disabled:H||!P.baseUrl.trim(),title:j(`fetchModelsHint`),onClick:Pt,children:[(0,g.jsx)(l,{}),` `,j(H?`fetchingModels`:`autoFetchAndAdopt`)]}),(0,g.jsxs)(`button`,{type:`button`,className:`btn sm`,disabled:G,title:j(`enrichModelsHint`),onClick:It,children:[(0,g.jsx)(l,{}),` `,j(G?`enrichingModels`:`enrichModels`)]}),G&&(0,g.jsxs)(`button`,{type:`button`,className:`btn sm`,disabled:K,title:j(`enrichModelsAbort`),onClick:Lt,style:{color:`var(--red)`},children:[(0,g.jsx)(d,{}),` `,j(K?`enrichCancelling`:`enrichModelsCancel`)]})]})]}),(0,g.jsxs)(`div`,{className:`model-matrix-list`,children:[P.models.map((e,t)=>(0,g.jsxs)(`div`,{className:`model-matrix-card`,children:[(0,g.jsxs)(`div`,{className:`matrix-main-row`,children:[(0,g.jsxs)(`div`,{className:`matrix-input-group id-group`,children:[(0,g.jsxs)(`span`,{className:`matrix-input-prefix`,children:[(0,g.jsx)(a,{}),` ID`]}),(0,g.jsx)(`input`,{type:`text`,className:`matrix-input-field mono`,value:e.id,onChange:e=>$(t,{id:e.target.value}),placeholder:j(`modelIdPlaceholder`)})]}),(0,g.jsxs)(`div`,{className:`matrix-input-group name-group`,children:[(0,g.jsx)(`span`,{className:`matrix-input-prefix`,children:j(`modelAliasPrefix`)}),(0,g.jsx)(`input`,{type:`text`,className:`matrix-input-field`,value:e.name,onChange:e=>$(t,{name:e.target.value}),placeholder:j(`modelAliasPlaceholder`)})]}),(0,g.jsxs)(`div`,{className:`matrix-toggles`,children:[(0,g.jsx)(`button`,{type:`button`,className:`matrix-toggle-tag ${e.input===`text-image`?`active vision`:``}`,onClick:()=>$(t,{input:e.input===`text-image`?`text`:`text-image`}),title:j(`visionCheckboxTitle`),children:j(`visionCheckboxLabel`)}),(0,g.jsx)(`button`,{type:`button`,className:`matrix-toggle-tag ${e.reasoning?`active reasoning`:``}`,onClick:()=>$(t,{reasoning:!e.reasoning}),title:j(`reasoningCheckboxTitle`),children:j(`reasoningCheckboxLabel`)}),e.reasoning&&(0,g.jsxs)(`button`,{type:`button`,className:`matrix-toggle-tag ${X===t?`active thinking-config`:``}`,onClick:()=>Be(X===t?null:t),title:j(`thinkingConfigTitle`),children:[(0,g.jsx)(o,{}),` `,j(`thinkingConfigBtn`),` `,e.thinkingLevelMap?`(${j(`thinkingCustomized`)})`:``]}),k!==void 0&&e.id.trim()&&(()=>{let t=`${P.providerId}/${e.id.trim()}`,n=k===t||k===e.id.trim();return(0,g.jsxs)(`button`,{type:`button`,className:`matrix-star-btn ${n?`active`:``}`,title:j(n?`cancelDefaultTooltip`:`setDefaultTooltip`),onClick:()=>{m(n?{type:`clear_default_model`}:{type:`set_default_model`,modelId:t})},children:[(0,g.jsx)(`span`,{className:`matrix-star-icon`,children:n?`★`:`☆`}),(0,g.jsx)(`span`,{children:j(n?`defaultModelBadge`:`setDefaultModelBtn`)})]})})(),(0,g.jsx)(`button`,{type:`button`,className:`matrix-delete-btn`,title:j(`delete`),onClick:()=>Vt(t),children:(0,g.jsx)(f,{})})]})]}),(0,g.jsxs)(`div`,{className:`matrix-spec-bar`,children:[(0,g.jsxs)(`div`,{className:`spec-combobox`,children:[(0,g.jsx)(`span`,{className:`spec-combobox-label`,children:j(`contextWindowLabel`)}),(0,g.jsxs)(`select`,{className:`spec-combobox-select`,value:_.some(t=>t.value===e.contextWindow)?e.contextWindow:`custom`,onChange:e=>{e.target.value!==`custom`&&$(t,{contextWindow:e.target.value})},children:[_.map(e=>(0,g.jsxs)(`option`,{value:e.value,children:[e.label,` (`,Math.round(Number(e.value)/1024),`K)`]},e.value)),(0,g.jsx)(`option`,{value:`custom`,children:j(`customOption`)})]}),(!_.some(t=>t.value===e.contextWindow)||e.contextWindow===``)&&(0,g.jsx)(`input`,{type:`text`,className:`spec-combobox-custom-input`,value:e.contextWindow,onChange:e=>$(t,{contextWindow:e.target.value}),placeholder:j(`contextPlaceholder`)})]}),(0,g.jsxs)(`div`,{className:`spec-combobox`,children:[(0,g.jsx)(`span`,{className:`spec-combobox-label`,children:j(`maxOutputLabel`)}),(0,g.jsxs)(`select`,{className:`spec-combobox-select`,value:v.some(t=>t.value===e.maxTokens)?e.maxTokens:`custom`,onChange:e=>{e.target.value!==`custom`&&$(t,{maxTokens:e.target.value})},children:[v.map(e=>(0,g.jsxs)(`option`,{value:e.value,children:[e.label,` (`,Math.round(Number(e.value)/1024),`K)`]},e.value)),(0,g.jsx)(`option`,{value:`custom`,children:j(`customOption`)})]}),(!v.some(t=>t.value===e.maxTokens)||e.maxTokens===``)&&(0,g.jsx)(`input`,{type:`text`,className:`spec-combobox-custom-input`,value:e.maxTokens,onChange:e=>$(t,{maxTokens:e.target.value}),placeholder:j(`maxOutputPlaceholder`)})]}),(0,g.jsx)(`div`,{className:`matrix-spec-quick-pills`,children:[`32K`,`128K`,`200K`].map(n=>{let r=_.find(e=>e.label===n);return r?(0,g.jsx)(`button`,{type:`button`,className:`param-pill ${e.contextWindow===r.value?`active`:``}`,onClick:()=>$(t,{contextWindow:r.value}),title:j(`contextPresetTooltip`,{label:n}),children:n},n):null})})]}),e.reasoning&&X===t&&(0,g.jsxs)(`div`,{className:`matrix-thinking-config-drawer`,children:[(0,g.jsxs)(`div`,{className:`thinking-drawer-header`,children:[(0,g.jsxs)(`div`,{className:`thinking-drawer-title`,children:[(0,g.jsx)(o,{}),(0,g.jsx)(`span`,{children:j(`thinkingConfigBtn`)||`思考配置`})]}),(0,g.jsx)(`div`,{className:`thinking-drawer-actions`,children:(0,g.jsx)(`button`,{type:`button`,className:`btn xs text-btn`,style:{whiteSpace:`nowrap`},onClick:()=>$(t,{thinkingLevelMap:void 0,compat:void 0,customExtraBody:``}),title:j(`thinkingResetDefault`),children:j(`thinkingResetDefault`)})})]}),(0,g.jsxs)(`div`,{className:`thinking-presets-row`,children:[(0,g.jsx)(`span`,{className:`thinking-presets-label`,children:j(`thinkingQuickApply`)}),(0,g.jsxs)(`div`,{className:`thinking-preset-pills`,children:[ne.map(n=>(0,g.jsx)(`button`,{type:`button`,className:`param-pill`,onClick:()=>{let r={...e.compat??{}};n.thinkingFormat?r.thinkingFormat=n.thinkingFormat:(n.id===`fixed-deepseek`||n.id===`claude-budget`)&&delete r.thinkingFormat,$(t,{thinkingLevelMap:n.map,compat:Object.keys(r).length?r:void 0})},title:n.desc,children:n.name},n.id)),Ve.map(n=>(0,g.jsxs)(`span`,{className:`param-pill user-preset-pill`,children:[(0,g.jsxs)(`button`,{type:`button`,className:`user-preset-btn`,onClick:()=>{let r={...e.compat??{}};n.thinkingFormat?r.thinkingFormat=n.thinkingFormat:delete r.thinkingFormat,$(t,{thinkingLevelMap:n.map,compat:Object.keys(r).length?r:void 0,customExtraBody:n.customExtraBody??``})},title:`套用自定义预设:${n.name}`,children:[`🏷️ `,n.name]}),(0,g.jsx)(`button`,{type:`button`,className:`user-preset-del`,onClick:e=>Je(n.id,e),title:`删除此预设`,children:`×`})]},n.id))]})]}),(0,g.jsxs)(`div`,{className:`thinking-advanced-row`,children:[(0,g.jsxs)(`div`,{className:`thinking-advanced-head`,children:[(0,g.jsxs)(`div`,{className:`thinking-format-selector`,children:[(0,g.jsx)(`span`,{className:`spec-combobox-label`,children:j(`thinkingFormatLabel`)}),(0,g.jsx)(`select`,{className:`spec-combobox-select`,value:e.compat?.thinkingFormat??``,onChange:n=>{let r=n.target.value.trim(),i={...e.compat??{}};r?i.thinkingFormat=r:delete i.thinkingFormat,$(t,{compat:Object.keys(i).length?i:void 0})},children:re.map(e=>(0,g.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),Ge===t?(0,g.jsxs)(`div`,{className:`save-preset-inline`,children:[(0,g.jsx)(`input`,{type:`text`,className:`spec-combobox-custom-input`,style:{width:130,textAlign:`left`},placeholder:`预设名称 (如: 16K模版)`,value:Ue,onChange:e=>We(e.target.value),onKeyDown:e=>{e.key===`Enter`&&qe(t)}}),(0,g.jsx)(`button`,{type:`button`,className:`btn xs`,onClick:()=>qe(t),children:`保存`}),(0,g.jsx)(`button`,{type:`button`,className:`btn xs text-btn`,onClick:()=>Ke(null),children:`取消`})]}):(0,g.jsxs)(`button`,{type:`button`,className:`btn xs`,onClick:()=>{Ke(t),We(``)},title:`将当前模型的思考配置、协议与 JSON 存为一个命名的预设模板`,children:[(0,g.jsx)(n,{}),` 存为我的预设`]})]}),(0,g.jsxs)(`div`,{className:`thinking-raw-body-block`,children:[(0,g.jsxs)(`div`,{style:{display:`flex`,justifyContent:`space-between`,alignItems:`center`},children:[(0,g.jsx)(`span`,{className:`spec-combobox-label`,children:j(`thinkingRawBodyLabel`)}),e.customExtraBody&&(0,g.jsx)(`span`,{style:{fontSize:`10.5px`,color:pe(e.customExtraBody).valid?`var(--green, #22c55e)`:`var(--red, #ef4444)`},children:pe(e.customExtraBody).valid?`✓ JSON语法有效(保存后自动无损合入请求 body)`:`✕ ${pe(e.customExtraBody).error}`})]}),(0,g.jsx)(`textarea`,{className:`thinking-raw-body-textarea`,placeholder:`{"thinking": {"type": "enabled", "budget_tokens": 16000}}`,rows:2,value:e.customExtraBody??``,onChange:e=>$(t,{customExtraBody:e.target.value})})]})]}),(0,g.jsx)(`div`,{className:`thinking-levels-grid`,children:ie.map(n=>{let r=e.thinkingLevelMap,i=!(r&&r[n]===null),a=r&&r[n]!==null&&r[n]!==void 0?String(r[n]):``,o=ae[n],s=o==null?n:String(o);return(0,g.jsxs)(`div`,{className:`thinking-level-col ${i?`enabled`:`disabled`}`,children:[(0,g.jsx)(`div`,{className:`level-col-head`,children:(0,g.jsxs)(`label`,{className:`level-check-label`,children:[(0,g.jsx)(`input`,{type:`checkbox`,checked:i,onChange:r=>{let i={...e.thinkingLevelMap??{}};r.target.checked?delete i[n]:i[n]=null,$(t,{thinkingLevelMap:i})}}),(0,g.jsx)(`span`,{className:`level-name`,children:j(`thinking.${n}`)||n})]})}),i&&(0,g.jsx)(`input`,{type:`text`,className:`level-val-input`,value:a,placeholder:s,title:`自定义发送给模型/网关的字面量或 Token 数(留空为默认)`,onChange:r=>{let i={...e.thinkingLevelMap??{}},a=r.target.value.trim();a?i[n]=a:delete i[n],$(t,{thinkingLevelMap:i})}})]},n)})})]})]},t)),(0,g.jsxs)(`button`,{type:`button`,className:`btn sm`,style:{alignSelf:`flex-start`,marginTop:4},onClick:Bt,children:[(0,g.jsx)(n,{}),` `,j(`addModelRow`)]})]})]})]}),M.type===`builtin`&&(()=>{let e=r.find(e=>e.id===M.id);if(!e)return null;let a=p[e.id]??[];return(0,g.jsxs)(`div`,{className:`studio-card`,children:[(0,g.jsxs)(`div`,{className:`studio-card-head`,children:[(0,g.jsxs)(`div`,{className:`studio-card-title`,children:[(0,g.jsx)(`span`,{children:j(`builtinProviderTitle`,{name:e.name})}),e.configured&&(0,g.jsx)(`span`,{className:`auth-badge`,children:j(`configuredBadge`)}),e.source&&!e.configured&&(0,g.jsx)(`span`,{className:`auth-badge dim`,children:e.source})]}),(0,g.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:6},children:[(0,g.jsxs)(`button`,{type:`button`,className:`btn sm`,title:j(`cloneProvider`),disabled:Dt===e.id,onClick:()=>Mt(e),children:[(0,g.jsx)(i,{}),` `,j(`cloneProvider`)]}),(0,g.jsxs)(`button`,{type:`button`,className:`btn sm`,onClick:()=>{rt(nt===e.id?null:e.id),Q(null)},children:[(0,g.jsx)(n,{}),` `,j(`appendModel`)]}),e.supportsApiKey&&e.source===`stored`&&!e.usingOAuth&&(0,g.jsxs)(`button`,{type:`button`,className:`btn sm danger`,title:j(`clearKeyTitle`),onClick:()=>Gt(e.id),children:[(0,g.jsx)(f,{}),` `,j(`clearKey`)]})]})]}),e.supportsOAuth&&(0,g.jsx)(oe,{provider:e,flow:ee.find(t=>t.provider===e.id),result:te[e.id]}),e.supportsApiKey&&(0,g.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:10},children:[(0,g.jsx)(`span`,{style:{fontSize:12.5,fontWeight:600},children:j(`apiKeyManagement`)}),(0,g.jsxs)(`div`,{className:`provider-keys`,children:[a.length===0&&(0,g.jsx)(`div`,{className:`provider-key-empty`,children:j(`noKeyYet`)}),a.map(n=>(0,g.jsxs)(`div`,{className:`provider-key-item ${n.active?`active`:``}`,children:[(0,g.jsx)(`span`,{className:`provider-key-dot`,children:n.active?`●`:`○`}),(0,g.jsx)(`span`,{className:`provider-key-label`,children:n.name}),!n.active&&(0,g.jsx)(`button`,{type:`button`,className:`iconbtn`,title:j(`activateKey`),onClick:()=>Ut(e.id,n.name),children:(0,g.jsx)(t,{})}),(0,g.jsx)(`button`,{type:`button`,className:`iconbtn danger`,title:j(`removeKey`),onClick:()=>Wt(e.id,n.name),children:(0,g.jsx)(f,{})})]},n.name))]}),(0,g.jsxs)(`div`,{className:`provider-add-key`,style:{marginTop:6},children:[(0,g.jsx)(`input`,{type:`text`,className:`key-input key-input-name`,placeholder:j(`keyNamePh`),value:Ee[e.id]??``,onChange:t=>De(n=>({...n,[e.id]:t.target.value}))}),(0,g.jsx)(`input`,{type:`password`,className:`key-input key-input-value`,placeholder:j(`addKeyPlaceholder`),value:R[e.id]??``,onChange:t=>Te(n=>({...n,[e.id]:t.target.value}))}),(0,g.jsxs)(`button`,{type:`button`,className:`btn primary sm`,disabled:!(R[e.id]??``).trim()||z===e.id,onClick:()=>Ht(e),children:[(0,g.jsx)(n,{}),` `,z===e.id?j(`savingKey`):j(`addKey`)]})]})]}),nt===e.id&&(0,g.jsxs)(`div`,{style:{marginTop:12,padding:12,background:`var(--bg)`,borderRadius:8,border:`1px dashed var(--border-soft)`},children:[(0,g.jsx)(`span`,{style:{fontSize:12,fontWeight:600,display:`block`,marginBottom:8},children:j(`addBuiltinOverlay`)}),(0,g.jsxs)(`div`,{style:{display:`flex`,gap:8,flexWrap:`wrap`},children:[(0,g.jsx)(`input`,{type:`text`,className:`key-input`,placeholder:j(`overlayModelIdPlaceholder`),value:it,onChange:e=>at(e.target.value)}),(0,g.jsx)(`input`,{type:`text`,className:`key-input`,placeholder:j(`overlayModelNamePlaceholder`),value:Z,onChange:e=>ot(e.target.value)}),(0,g.jsxs)(`button`,{type:`button`,className:`btn primary sm`,disabled:!it.trim()||dt,onClick:()=>qt(e.id),children:[(0,g.jsx)(n,{}),` `,j(`submitOverlayBtn`)]})]}),ht&&(0,g.jsx)(`span`,{style:{fontSize:12,color:ht.ok?`var(--green)`:`var(--red)`,marginTop:6},children:ht.text})]})]})})()]})]}),ve&&(0,g.jsx)(he,{candidates:ve,preselectedIds:P?.models.map(e=>e.id.trim()).filter(Boolean)??[],onAdopt:Ft,onClose:()=>ye(null)})]})})}export{C as ModelConfigModal};
|