@eworkbase/plugin-ai-rules 0.8.3 → 0.8.4

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.
Files changed (2) hide show
  1. package/dist/ui/main.js +1 -1
  2. package/package.json +2 -2
package/dist/ui/main.js CHANGED
@@ -305,7 +305,7 @@ targets: ["*"]
305
305
  description: 描述适用场景
306
306
  ---
307
307
 
308
- `}function oD(e,t){if(e.kind===`mcp`)return`server.json`;if(e.kind!==`skills`)return`rules/.rulesync/${e.kind}/${e.id}.md`;let n=t?t.split(`/`).slice(4).join(`/`):`SKILL.md`;return`rules/.rulesync/skills/${e.id}/${n}`}function sD(e){try{let t=JSON.parse(e??`{}`);return t&&typeof t==`object`&&!Array.isArray(t)?t:null}catch{return null}}const cD=new Map([[`local`,`仅本地`],[`pending`,`待同步`],[`synced`,`已同步`],[`unknown`,`状态未知`]]),lD=new Map([[`rules`,`Rules`],[`skills`,`Skills`],[`mcp`,`MCP`],[`commands`,`Commands`],[`subagents`,`Subagents`]]),uD=(0,A.memo)(function({host:e,isActive:t,workspaceId:n}){let{catalog:r,kind:i,selected:a,draft:o,mode:s,error:c,isBusy:l,isRefreshing:u,isReading:d,query:f,isSourceView:p,isEditing:m,refresh:h,handleOpen:g,handleKind:_,handleCreate:v,handleEdit:y,handleCancel:b,handleId:x,handleFile:S,handleSearch:C,handleSourceView:w,handleContent:T,handleMarkdownContent:E,handleMcpField:D,handleImport:O,handleSave:k,handleToggleRepository:A,handleDelete:j,handlePublish:M,handleWorkflows:N,resource:P,file:F,server:I,visibleItems:L,isMarkdown:R,fileName:ee}=iD({host:e,isActive:t,workspaceId:n}),z=L[0],B=a?.id??z?.id,te=r?.publicationWarning,ne=P?.repository?F?.path:F?.path.slice(6);return(0,V.jsxs)(`section`,{className:`configuration-manager`,"data-editing":m,"aria-label":`资源配置`,children:[c&&!m&&(0,V.jsx)(ws,{isDismissible:!!r,title:`规则资源操作未完成`,error:c,scope:`当前资源操作;已读取的资源内容保留。`,recovery:`按原因处理后重试;资源仍被引用时可检查工作流关联。`,children:(0,V.jsx)(Go,{variant:`subtle`,onClick:N,children:`查看工作流关联`})}),m&&P&&c&&(0,V.jsx)(ws,{isDismissible:!0,title:`资源保存未完成`,error:c,scope:`当前资源的保存;编辑内容已保留。`,recovery:`处理冲突或配置问题后重试保存。`}),m?(0,V.jsx)(`p`,{className:`configuration-editing-notice`,role:`status`,children:`正在编辑,保存或取消后可切换资源类型与条目。`}):null,(0,V.jsxs)(`header`,{className:`configuration-navigation`,children:[(0,V.jsx)(`nav`,{className:`configuration-tabs`,"aria-label":`资源类型`,children:[...lD].map(([e,t])=>(0,V.jsxs)(`button`,{type:`button`,value:e,"aria-pressed":i===e,disabled:m||l,onClick:_,children:[t,(0,V.jsx)(`span`,{"aria-hidden":`true`,children:r?.resources.filter(t=>t.kind===e).length??0})]},e))}),r?.pendingPublication&&(0,V.jsxs)(Go,{size:`compact-sm`,variant:`light`,disabled:m||l,onClick:M,children:[`发布规则变更 · `,r.pendingPublication.files.length]}),(0,V.jsx)(Go,{variant:`subtle`,color:`gray`,size:`compact-sm`,loading:u,disabled:m||l,onClick:h,children:`刷新列表`})]}),te&&(0,V.jsx)(ws,{title:`规则同步状态暂不可用`,error:te,scope:`资源的同步状态。`,recovery:`重新读取后可继续检查哪些规则需要发布。`,children:(0,V.jsx)(Go,{size:`compact-sm`,variant:`default`,disabled:m||l||u,onClick:h,children:`重试读取`})}),(0,V.jsxs)(`div`,{className:`configuration-resource-grid`,children:[(0,V.jsxs)(`aside`,{className:`configuration-list`,"aria-label":`资源目录`,children:[(0,V.jsxs)(`div`,{className:`configuration-list-heading`,children:[(0,V.jsx)(`h2`,{children:`资源目录`}),(0,V.jsx)(Go,{size:`compact-sm`,variant:`default`,disabled:m||l||d,onClick:v,children:`新增`})]}),(0,V.jsx)(`input`,{autoCapitalize:`none`,className:`configuration-search`,type:`search`,"aria-label":`搜索资源`,placeholder:`搜索资源名称…`,value:f,onChange:C,disabled:m}),(0,V.jsxs)(`div`,{className:`configuration-items`,children:[!r&&(0,V.jsx)(`p`,{className:`configuration-notice`,role:`status`,children:c?`资源尚未读取`:`正在读取资源…`}),r&&!L.length&&(0,V.jsx)(`p`,{className:`configuration-notice`,children:f?`没有匹配的资源,试试其他名称。`:`还没有资源,从新增开始。`}),L.map(e=>(0,V.jsxs)(`div`,{className:`configuration-item`,children:[(0,V.jsxs)(`button`,{type:`button`,className:`configuration-row`,"data-id":e.id,"aria-current":B===e.id?`true`:void 0,disabled:m||l,onClick:g,children:[(0,V.jsx)(`strong`,{children:e.title??e.id}),(0,V.jsx)(`span`,{children:e.repository?`来源仓库 · `+e.repository.label:e.id+` · `+e.paths.length+` 个文件`}),(0,V.jsx)(`span`,{className:`resource-publication`,"data-status":e.publicationStatus??`unknown`,children:e.repository?e.repository.enabled?`已启用`:`已停用`:cD.get(e.publicationStatus??`unknown`)})]}),!m&&!e.repository?(0,V.jsx)(Go,{className:`configuration-delete`,variant:`subtle`,color:`red`,size:`compact-sm`,"data-id":e.id,disabled:l||d,onClick:j,title:`删除资源`,"aria-label":`删除资源:`+(e.title??e.id),children:(0,V.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:(0,V.jsx)(`path`,{d:`M3 6h18M9 6V4h6v2M5 6l1 14h12l1-14M10 10v6M14 10v6`})})}):null]},e.id))]}),i===`skills`&&(0,V.jsx)(`div`,{className:`configuration-list-footer`,children:(0,V.jsx)(Go,{variant:`subtle`,size:`compact-sm`,disabled:m||l||d,onClick:O,children:`导入 Skill 目录`})})]}),(0,V.jsxs)(`section`,{className:`configuration-detail`,"aria-label":`资源详情`,"aria-busy":d||!r&&u,tabIndex:0,children:[d&&(0,V.jsxs)(`p`,{className:`configuration-reading`,role:`status`,children:[(0,V.jsx)(fi,{size:`xs`}),`正在读取内容…`]}),!P&&!d&&z&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`header`,{className:`configuration-detail-header`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h2`,{children:z.title??z.id}),(0,V.jsxs)(`p`,{children:[lD.get(i),` `,(0,V.jsx)(`code`,{children:z.id})]})]}),(0,V.jsx)(Go,{"data-id":z.id,onClick:g,children:`查看正文`})]}),(0,V.jsx)(`div`,{className:`configuration-detail-body`,children:(0,V.jsxs)(`dl`,{className:`configuration-facts`,children:[z.repository?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`dt`,{children:`来源仓库`}),(0,V.jsx)(`dd`,{children:z.repository.label})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`dt`,{children:`应用范围`}),(0,V.jsxs)(`dd`,{children:[`仅在修改此仓库时应用 · `,z.repository.enabled?`已启用`:`已停用`]})]})]}):(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`dt`,{children:`同步状态`}),(0,V.jsx)(`dd`,{children:cD.get(z.publicationStatus??`unknown`)})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`dt`,{children:`关联文件`}),(0,V.jsxs)(`dd`,{children:[z.paths.length,` 个`]})]}),z.description&&(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`dt`,{children:`说明`}),(0,V.jsx)(`dd`,{children:z.description})]}),z.paths[0]&&(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`dt`,{children:`文件路径`}),(0,V.jsx)(`dd`,{children:(0,V.jsx)(`code`,{children:z.paths[0]})})]})]})})]}),r&&!P&&!d&&!z&&(0,V.jsxs)(`div`,{className:`configuration-empty`,children:[(0,V.jsx)(`h2`,{children:`暂无可查看的资源`}),(0,V.jsx)(`p`,{children:f?`试试其他名称,或清空搜索。`:`可在目录中新增资源。`})]}),P&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`header`,{className:m?`configuration-detail-header is-editing`:`configuration-detail-header`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h2`,{children:s===bs.Create?`新增 ${lD.get(i)}`:P.title??P.id}),P.repository?(0,V.jsxs)(`p`,{children:[`来源 · `,P.repository.label,` / AGENTS.md`,(0,V.jsx)(`br`,{}),`仅在修改此仓库时应用`]}):null,(0,V.jsxs)(`p`,{children:[lD.get(P.kind),(0,V.jsx)(`code`,{children:P.id}),(0,V.jsx)(`span`,{className:`configuration-mode`,children:m?`编辑中`:`只读查看`})]})]}),m?(0,V.jsxs)(`div`,{className:`configuration-actions`,children:[(0,V.jsx)(Go,{variant:`default`,disabled:l,onClick:b,children:`取消编辑`}),(0,V.jsx)(Go,{loading:l,disabled:!o?.id.trim(),onClick:k,children:`保存并同步`})]}):P.repository?(0,V.jsx)(ms,{label:`启用仓库规则`,checked:P.repository.enabled,disabled:l||d,onChange:A}):(0,V.jsx)(Go,{disabled:l||d,onClick:y,children:`编辑`}),m&&(0,V.jsx)(`div`,{className:`configuration-header-feedback`,children:(0,V.jsx)(`p`,{children:`保存后,团队成员可以同步这份资源。`})})]}),(0,V.jsxs)(`div`,{className:`configuration-detail-body`,children:[m&&(0,V.jsxs)(`section`,{className:`configuration-section`,children:[(0,V.jsx)(`h3`,{children:`基本信息`}),(0,V.jsxs)(`label`,{className:`configuration-field`,children:[`ID`,(0,V.jsx)(`input`,{autoCapitalize:`none`,disabled:l,value:P.id,onChange:x,readOnly:s!==bs.Create,placeholder:`例如 team-review`}),(0,V.jsx)(`span`,{className:`configuration-hint`,children:s===bs.Create?`使用字母、数字、短横线或下划线。`:`已有资源的 ID 保持不变,工作流通过它关联资源。`})]})]}),m&&i===`mcp`&&(0,V.jsxs)(`section`,{className:`configuration-section`,children:[(0,V.jsx)(`h3`,{children:`连接设置`}),(0,V.jsxs)(`div`,{className:`configuration-fields`,children:[(0,V.jsxs)(`label`,{className:`configuration-field`,children:[`启动命令`,(0,V.jsx)(`input`,{autoCapitalize:`none`,name:`command`,value:typeof I?.command==`string`?I.command:``,disabled:l||!I,onChange:D,placeholder:`本机已安装的程序`})]}),(0,V.jsxs)(`label`,{className:`configuration-field`,children:[`服务地址`,(0,V.jsx)(`input`,{autoCapitalize:`none`,name:`url`,value:typeof I?.url==`string`?I.url:``,disabled:l||!I,onChange:D,placeholder:`https://…`})]})]})]}),(0,V.jsxs)(`section`,{className:`configuration-section`,children:[(0,V.jsxs)(`div`,{className:`configuration-document-bar`,children:[P.files.length>1?(0,V.jsxs)(`label`,{className:`configuration-file-picker`,children:[`文件`,(0,V.jsx)(`select`,{disabled:l,value:F?.path??``,onChange:S,children:P.files.map(({path:e})=>(0,V.jsx)(`option`,{value:e,children:e.split(`/`).slice(4).join(`/`)||e},e))})]}):(0,V.jsx)(`span`,{children:ee||(i===`mcp`?`MCP 配置`:`资源内容`)}),!m&&R&&(0,V.jsx)(Go,{variant:`subtle`,color:`gray`,size:`compact-sm`,onClick:w,children:p?`返回预览`:`查看源码`})]}),m&&R?(0,V.jsx)(Ls,{label:`正文与元数据`,sourcePath:ne,value:F?.content??``,onChange:E,isDisabled:l},P.id+`:`+(F?.path??``)):m?(0,V.jsxs)(`label`,{className:`configuration-field`,children:[i===`mcp`?`MCP JSON`:`正文与元数据`,(0,V.jsx)(`textarea`,{autoCapitalize:`none`,className:`configuration-code-editor`,disabled:l,rows:18,value:F?.content??``,onChange:T,spellCheck:!1}),(0,V.jsx)(`span`,{className:`configuration-hint`,children:i===`mcp`?`可粘贴完整服务配置,额外字段会保留。`:`直接编辑源文件,保留 Markdown 与文件头元数据。`})]}):R&&!p?(0,V.jsx)(kE,{content:F?.content??``,sourcePath:ne}):(0,V.jsx)(`pre`,{className:`configuration-content`,tabIndex:0,children:F?.content||`(内容为空)`})]})]}),!m&&(0,V.jsx)(`footer`,{className:`configuration-footer`,children:(0,V.jsx)(`p`,{children:`保存后,团队成员可以同步这份资源。`})})]})]},JSON.stringify([i,a?.id,m&&!a]))]})]})});var dD=class extends Error{code;constructor(e,t){super(t),this.name=`PenpalError`,this.code=e}},fD=e=>({name:e.name,message:e.message,stack:e.stack,penpalCode:e instanceof dD?e.code:void 0}),pD=({name:e,message:t,stack:n,penpalCode:r})=>{let i=r?new dD(r,t):Error(t);return i.name=e,i.stack=n,i},mD=class{value;transferables;constructor(e,t){this.value=e,this.transferables=t?.transferables}},hD=`penpal`,gD=e=>typeof e==`object`&&!!e,_D=e=>typeof e==`function`,vD=e=>gD(e)&&e.namespace===hD,yD=e=>e.type===`SYN`,bD=e=>e.type===`ACK1`,xD=e=>e.type===`ACK2`,SD=e=>e.type===`CALL`,CD=e=>e.type===`REPLY`,wD=e=>e.type===`DESTROY`,TD=(e,t=[])=>{let n=[];for(let r of Object.keys(e)){let i=e[r];_D(i)?n.push([...t,r]):gD(i)&&n.push(...TD(i,[...t,r]))}return n},ED=(e,t)=>{let n=e.reduce((e,t)=>gD(e)?e[t]:void 0,t);return _D(n)?n:void 0},DD=e=>e.join(`.`),OD=(e,t,n)=>({namespace:hD,channel:e,type:`REPLY`,callId:t,isError:!0,...n instanceof Error?{value:fD(n),isSerializedErrorInstance:!0}:{value:n}}),kD=(e,t,n,r)=>{let i=!1,a=async a=>{if(i||!SD(a))return;r?.(`Received ${DD(a.methodPath)}() call`,a);let{methodPath:o,args:s,id:c}=a,l,u;try{let e=ED(o,t);if(!e)throw new dD(`METHOD_NOT_FOUND`,`Method \`${DD(o)}\` is not found.`);let r=await e(...s);r instanceof mD&&(u=r.transferables,r=await r.value),l={namespace:hD,channel:n,type:`REPLY`,callId:c,value:r}}catch(e){l=OD(n,c,e)}if(!i)try{r?.(`Sending ${DD(o)}() reply`,l),e.sendMessage(l,u)}catch(t){throw t.name===`DataCloneError`&&(l=OD(n,c,t),r?.(`Sending ${DD(o)}() reply`,l),e.sendMessage(l)),t}};return e.addMessageHandler(a),()=>{i=!0,e.removeMessageHandler(a)}},AD=crypto.randomUUID?.bind(crypto)??(()=>[,,,,].fill(0).map(()=>Math.floor(Math.random()*(2**53-1)).toString(16)).join(`-`)),jD=class{transferables;timeout;constructor(e){this.transferables=e?.transferables,this.timeout=e?.timeout}},MD=new Set([`apply`,`call`,`bind`]),ND=(e,t,n=[])=>new Proxy(n.length?()=>{}:Object.create(null),{get(r,i){if(i!==`then`)return n.length&&MD.has(i)?Reflect.get(r,i):ND(e,t,[...n,i])},apply(t,r,i){return e(n,i)}}),PD=e=>new dD(`CONNECTION_DESTROYED`,`Method call ${DD(e)}() failed due to destroyed connection`),FD=(e,t,n)=>{let r=!1,i=new Map,a=e=>{if(!CD(e))return;let{callId:t,value:r,isError:a,isSerializedErrorInstance:o}=e,s=i.get(t);s&&(i.delete(t),n?.(`Received ${DD(s.methodPath)}() call`,e),a?s.reject(o?pD(r):r):s.resolve(r))};return e.addMessageHandler(a),{remoteProxy:ND((a,o)=>{if(r)throw PD(a);let s=AD(),c=o[o.length-1],l=c instanceof jD,{timeout:u,transferables:d}=l?c:{},f=l?o.slice(0,-1):o;return new Promise((r,o)=>{let c=u===void 0?void 0:window.setTimeout(()=>{i.delete(s),o(new dD(`METHOD_CALL_TIMEOUT`,`Method call ${DD(a)}() timed out after ${u}ms`))},u);i.set(s,{methodPath:a,resolve:r,reject:o,timeoutId:c});try{let r={namespace:hD,channel:t,type:`CALL`,id:s,methodPath:a,args:f};n?.(`Sending ${DD(a)}() call`,r),e.sendMessage(r,d)}catch(e){o(new dD(`TRANSMISSION_FAILED`,e.message))}})},n),destroy:()=>{r=!0,e.removeMessageHandler(a);for(let{methodPath:e,reject:t,timeoutId:n}of i.values())clearTimeout(n),t(PD(e));i.clear()}}},ID=()=>{let e,t;return{promise:new Promise((n,r)=>{e=n,t=r}),resolve:e,reject:t}},LD=`deprecated-penpal`,RD=e=>gD(e)&&`penpal`in e,zD=e=>e.split(`.`),BD=e=>e.join(`.`),VD=e=>{try{return JSON.stringify(e)}catch{return String(e)}},HD=e=>new dD(`TRANSMISSION_FAILED`,`Unexpected message to translate: ${VD(e)}`),UD=e=>{if(e.penpal===`syn`)return{namespace:hD,channel:void 0,type:`SYN`,participantId:LD};if(e.penpal===`ack`)return{namespace:hD,channel:void 0,type:`ACK2`};if(e.penpal===`call`)return{namespace:hD,channel:void 0,type:`CALL`,id:e.id,methodPath:zD(e.methodName),args:e.args};if(e.penpal===`reply`)return e.resolution===`fulfilled`?{namespace:hD,channel:void 0,type:`REPLY`,callId:e.id,value:e.returnValue}:{namespace:hD,channel:void 0,type:`REPLY`,callId:e.id,isError:!0,...e.returnValueIsError?{value:e.returnValue,isSerializedErrorInstance:!0}:{value:e.returnValue}};throw HD(e)},WD=e=>{if(bD(e))return{penpal:`synAck`,methodNames:e.methodPaths.map(BD)};if(SD(e))return{penpal:`call`,id:e.id,methodName:BD(e.methodPath),args:e.args};if(CD(e))return e.isError?{penpal:`reply`,id:e.callId,resolution:`rejected`,...e.isSerializedErrorInstance?{returnValue:e.value,returnValueIsError:!0}:{returnValue:e.value}}:{penpal:`reply`,id:e.callId,resolution:`fulfilled`,returnValue:e.value};throw HD(e)},GD=({messenger:e,methods:t,timeout:n,channel:r,log:i})=>{let a=AD(),o,s=[],c=!1,l=TD(t),{promise:u,resolve:d,reject:f}=ID(),p=n===void 0?void 0:setTimeout(()=>{f(new dD(`CONNECTION_TIMEOUT`,`Connection timed out after ${n}ms`))},n),m=()=>{for(let e of s)e()},h=()=>{if(c)return;s.push(kD(e,t,r,i));let{remoteProxy:n,destroy:a}=FD(e,r,i);s.push(a),clearTimeout(p),c=!0,d({remoteProxy:n,destroy:m})},g=()=>{let t={namespace:hD,type:`SYN`,channel:r,participantId:a};i?.(`Sending handshake SYN`,t);try{e.sendMessage(t)}catch(e){f(new dD(`TRANSMISSION_FAILED`,e.message))}},_=t=>{if(i?.(`Received handshake SYN`,t),t.participantId===o&&o!==LD||(o=t.participantId,g(),!(a>o||o===LD)))return;let n={namespace:hD,channel:r,type:`ACK1`,methodPaths:l};i?.(`Sending handshake ACK1`,n);try{e.sendMessage(n)}catch(e){f(new dD(`TRANSMISSION_FAILED`,e.message));return}},v=t=>{i?.(`Received handshake ACK1`,t);let n={namespace:hD,channel:r,type:`ACK2`};i?.(`Sending handshake ACK2`,n);try{e.sendMessage(n)}catch(e){f(new dD(`TRANSMISSION_FAILED`,e.message));return}h()},y=e=>{i?.(`Received handshake ACK2`,e),h()},b=e=>{yD(e)&&_(e),bD(e)&&v(e),xD(e)&&y(e)};return e.addMessageHandler(b),s.push(()=>e.removeMessageHandler(b)),g(),u},KD=e=>{let t=!1,n;return(...r)=>(t||(t=!0,n=e(...r)),n)},qD=new WeakSet,JD=({messenger:e,methods:t={},timeout:n,channel:r,log:i})=>{if(!e)throw new dD(`INVALID_ARGUMENT`,`messenger must be defined`);if(qD.has(e))throw new dD(`INVALID_ARGUMENT`,`A messenger can only be used for a single connection`);qD.add(e);let a=[e.destroy],o=KD(t=>{if(t){let t={namespace:hD,channel:r,type:`DESTROY`};try{e.sendMessage(t)}catch{}}for(let e of a)e();i?.(`Connection destroyed`)}),s=e=>vD(e)&&e.channel===r;return{promise:(async()=>{try{e.initialize({log:i,validateReceivedMessage:s}),e.addMessageHandler(e=>{wD(e)&&o(!1)});let{remoteProxy:c,destroy:l}=await GD({messenger:e,methods:t,timeout:n,channel:r,log:i});return a.push(l),c}catch(e){throw o(!0),e}})(),destroy:()=>{o(!0)}}},YD=class{#e;#t;#n;#r;#i;#a=new Set;#o;#s=!1;constructor({remoteWindow:e,allowedOrigins:t}){if(!e)throw new dD(`INVALID_ARGUMENT`,`remoteWindow must be defined`);this.#e=e,this.#t=t?.length?t:[window.origin]}initialize=({log:e,validateReceivedMessage:t})=>{this.#n=e,this.#r=t,window.addEventListener(`message`,this.#d)};sendMessage=(e,t)=>{if(yD(e)){let n=this.#l(e);this.#e.postMessage(e,{targetOrigin:n,transfer:t});return}if(bD(e)||this.#s){let n=this.#s?WD(e):e,r=this.#l(e);this.#e.postMessage(n,{targetOrigin:r,transfer:t});return}if(xD(e)){let{port1:n,port2:r}=new MessageChannel;this.#o=n,n.addEventListener(`message`,this.#f),n.start();let i=[r,...t||[]],a=this.#l(e);this.#e.postMessage(e,{targetOrigin:a,transfer:i});return}if(this.#o){this.#o.postMessage(e,{transfer:t});return}throw new dD(`TRANSMISSION_FAILED`,`Cannot send message because the MessagePort is not connected`)};addMessageHandler=e=>{this.#a.add(e)};removeMessageHandler=e=>{this.#a.delete(e)};destroy=()=>{window.removeEventListener(`message`,this.#d),this.#u(),this.#a.clear()};#c=e=>this.#t.some(t=>t instanceof RegExp?t.test(e):t===e||t===`*`);#l=e=>{if(yD(e))return`*`;if(!this.#i)throw new dD(`TRANSMISSION_FAILED`,`Cannot send message because the remote origin is not established`);return this.#i===`null`&&this.#t.includes(`*`)?`*`:this.#i};#u=()=>{this.#o?.removeEventListener(`message`,this.#f),this.#o?.close(),this.#o=void 0};#d=({source:e,origin:t,ports:n,data:r})=>{if(e===this.#e){if(RD(r)){this.#n?.(`Please upgrade the child window to the latest version of Penpal.`),this.#s=!0;try{r=UD(r)}catch(e){this.#n?.(`Failed to translate deprecated message: ${e.message}`);return}}if(this.#r?.(r)){if(!this.#c(t)){this.#n?.(`Received a message from origin \`${t}\` which did not match allowed origins \`[${this.#t.join(`, `)}]\``);return}if(yD(r)&&(this.#u(),this.#i=t),xD(r)&&!this.#s){if(this.#o=n[0],!this.#o){this.#n?.(`Ignoring ACK2 because it did not include a MessagePort`);return}this.#o.addEventListener(`message`,this.#f),this.#o.start()}for(let e of this.#a)e(r)}}};#f=({data:e})=>{if(this.#r?.(e))for(let t of this.#a)t(e)}};function XD(e,t){let n=e?.onInit,r=t?.connectToHost,i=t?.targetWindow;if(typeof n!=`function`)throw TypeError(`defineWorkbasePluginUi requires an onInit callback.`);if(!i||typeof r!=`function`)throw TypeError(`Plugin UI transport is unavailable.`);let a={fatalReportPromise:null,isInitialized:!1,contentHeight:null,recoverableHostErrors:new WeakSet},o=new Set,s=new Set,c=0,l=!1,u=!1,d={filesChanged:async()=>{if(u=!0,!(l||c||!a.isInitialized)){l=!0;try{for(;u;)u=!1,await Promise.all([...s].map(e=>e()))}finally{l=!1}}},executionChanged:async e=>{a.isInitialized&&[...o].forEach(t=>t(e))},initialize:async e=>{oO(e),a.isInitialized=!0,c++;try{await n(e)}finally{c--}u&&await d.filesChanged(),await nO(i),await aO(p,{targetWindow:i,state:a})}},f=r(d),p=f.promise,m=ZD(p,a);return eO({connection:f,state:a,targetWindow:i}),$D(m,{targetWindow:i,subscribe:async e=>{let t=t=>e(t);o.add(t);try{await m(`command.subscribe`,{enabled:!0})}catch(e){throw o.delete(t),e}return async()=>{o.delete(t)&&!o.size&&await m(`command.subscribe`,{enabled:!1})}},onFilesChanged:e=>(s.add(e),()=>{s.delete(e)})})}function ZD(e,t){return async(n,r)=>{if(!t.isInitialized)throw Error(`Plugin UI is not initialized.`);let i=await(await e).call(n,r);if(uO(i)&&i.ok===!0)return i.result;let a=QD(i);throw t.recoverableHostErrors.add(a),a}}function QD(e){let t=uO(e)&&uO(e.error)?e.error:null,n=typeof t?.message==`string`?t.message:`Host action failed.`,r=typeof t?.code==`string`?t.code:`host_error`;return Object.assign(Error(n),{code:r})}function $D(e,{targetWindow:t,subscribe:n,onFilesChanged:r}){let i=Object.freeze({subscribe:n,reply:t=>e(`command.reply`,{executionId:t}),clear:t=>e(`command.clear`,t===void 0?{}:{executionId:t}),start:(n,r,i={})=>e(`command.start`,{commandId:n,input:r,executionId:i.executionId??t.crypto.randomUUID()}),query:t=>e(`command.query`,{executionId:t??null}),cancel:t=>e(`command.cancel`,{executionId:t}),execute:(n,r,i={})=>e(`command.execute`,{commandId:n,executionId:i.executionId??t.crypto.randomUUID(),input:r})}),a=Object.freeze({resolve:(t,n)=>e(`status.resolve`,{input:n,statusId:t})}),o=Object.freeze({onFilesChanged:r,setModified:t=>e(`view.modified`,t),call:(t,n)=>e(`view.call`,{input:n,method:t})});return Object.freeze({dismiss:()=>e(`interaction.dismiss`,{}),respond:t=>e(`interaction.respond`,{value:t}),closeOutput:t=>e(`output.close`,{id:t}),commands:i,desktop:Object.freeze({open:t=>e(`desktop.open`,t)}),navigate:(t,{replace:n=!1}={})=>e(`navigate`,{replace:n,to:t}),openOutput:t=>e(`output.open`,t),selectFiles:(t={})=>e(`file.select`,t),showPrompt:t=>e(`dialog.prompt`,t),showToast:t=>e(`toast.show`,t),status:a,updateOutput:t=>e(`output.update`,t),view:o})}function eO({connection:e,state:t,targetWindow:n}){let r=null,i=n=>{(n.error||n.message!==`ResizeObserver loop completed with undelivered notifications.`&&n.message!==`ResizeObserver loop limit exceeded`)&&rO(e.promise,t,n.error??n.message)},a=n=>{n.reason instanceof Error&&t.recoverableHostErrors.has(n.reason)||rO(e.promise,t,n.reason)},o=new n.ResizeObserver(()=>{r===null&&(r=n.requestAnimationFrame(()=>{r=null,t.isInitialized&&aO(e.promise,{targetWindow:n,state:t})}))}),s=()=>{n.removeEventListener(`error`,i,!0),n.removeEventListener(`unhandledrejection`,a),n.removeEventListener(`beforeunload`,s),o.disconnect(),r!==null&&n.cancelAnimationFrame(r),e.destroy(),t.fatalReportPromise=null,t.isInitialized=!1};tO(e.promise),o.observe(n.document.body??n.document.documentElement),n.addEventListener(`error`,i,!0),n.addEventListener(`unhandledrejection`,a),n.addEventListener(`beforeunload`,s,{once:!0})}async function tO(e){try{await e}catch{}}async function nO(e){await new Promise(t=>{e.requestAnimationFrame(()=>{e.requestAnimationFrame(()=>t())})})}async function rO(e,t,n){t.fatalReportPromise||=iO(e,dO(n).slice(0,1e3)),await t.fatalReportPromise}async function iO(e,t){try{await(await e).reportFatal(t)}catch{}}async function aO(e,{targetWindow:t,state:n}){let r=t.document.body??t.document.documentElement,i=Math.max(r.offsetHeight,r.scrollHeight);if(Number.isFinite(i))try{let t=await e,r=Math.min(Math.max(Math.ceil(i),1),1e4);if(!n.isInitialized||n.contentHeight===r)return;n.contentHeight=r,await t.reportContentHeight(r)}catch{}}function oO(e){if(!sO(e))throw TypeError(`Plugin UI initialization payload is invalid.`)}function sO(e){return!uO(e)||e.configurationRevision!==void 0&&typeof e.configurationRevision!=`string`||e.activationGeneration!==void 0&&(!Number.isSafeInteger(e.activationGeneration)||Number(e.activationGeneration)<0)?!1:cO(e.project)&&cO(e.workspace)&&lO(e.view)}function cO(e){return uO(e)&&typeof e.id==`string`&&e.id.length>0}function lO(e){return cO(e)&&uO(e)&&typeof e.pluginId==`string`&&e.pluginId.length>0&&typeof e.title==`string`&&e.title.length>0}function uO(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function dO(e){return e instanceof Error?e.message:typeof e==`string`&&e.trim().length>0?e:`Plugin UI failed.`}function fO(e){let t=window;return XD(e,{connectToHost:e=>pO(t,e),targetWindow:t})}function pO(e,t){let n=JD({channel:`workbase-plugin-ui-v1`,messenger:new YD({allowedOrigins:mO(e),remoteWindow:e.parent}),methods:t});return{destroy:n.destroy,promise:n.promise}}function mO(e){let t=new URL(e.location.href).searchParams.get(`__workbaseHostOrigin`);return t&&t!==`null`?[t]:[`*`]}function hO(){let[e,t]=(0,A.useState)(``),[n,r]=(0,A.useState)(0),[i,a]=(0,A.useState)(``),[o,s]=(0,A.useState)(!0),[c,l]=(0,A.useState)(!1),u=(0,A.useCallback)(()=>s(!0),[]),d=(0,A.useCallback)(()=>s(!1),[]),f=(0,A.useCallback)(()=>l(!0),[]),p=(0,A.useRef)(null),m=(0,A.useRef)(null),h=(0,A.useRef)(0),g=(0,A.useRef)(null),_=(0,A.useRef)(!1),v=(0,A.useRef)(null),[y,b]=(0,A.useState)(!1),[x,S]=(0,A.useState)(null),[C,w]=(0,A.useState)(null),[T,E]=(0,A.useState)(null),[D,O]=(0,A.useState)(null),[k,j]=(0,A.useState)(null),M=(0,A.useCallback)((e,t=!1)=>{let n=g.current;g.current=e,S(e),w(r=>!t&&r&&n&&!LE(n,r)?r:IE(e))},[]),N=(0,A.useCallback)(async()=>{if(_.current)return;if(v.current)return v.current;let e=ME(p.current),t=h.current;return b(!0),v.current=(async()=>{try{let n=NE(await e.status.resolve(`sync`,{}));if(t!==h.current)return;M(n),O(null)}catch(e){t===h.current&&O(VE(e))}finally{t===h.current&&(v.current=null,b(!1))}})(),v.current},[M]),P=(0,A.useCallback)(e=>{r(e.activationGeneration??0);let n=JSON.stringify([e.project.id,e.workspace.id]);m.current!==n&&(m.current=n,h.current+=1,g.current=null,v.current=null,_.current=!1,t(n),a(e.workspace.id),l(!1),S(null),w(null),E(null),O(null),j(null),N())},[N]);(0,A.useEffect)(()=>{p.current=fO({onInit:P});let e=p.current.view.onFilesChanged?.(N);return()=>{e?.(),h.current+=1,p.current=null}},[P,N]);let F=(0,A.useCallback)(async({commandId:e,overwriteFiles:t})=>{if(_.current)return;_.current=!0;let n=++h.current;v.current=null,b(!1);let r=ME(p.current);E(e),O(null);try{let i=await r.commands.execute(e,t?{overwriteFiles:t}:{}),a=PE(i.value);if(n!==h.current)return;M(a.status),j({logId:i.logId,result:a.result})}catch(e){if(n!==h.current)return;O(VE(e));try{let e=NE(await r.status.resolve(`sync`,{}));n===h.current&&M(e)}catch(t){n===h.current&&O(`${VE(e)}\n同步状态读取失败:${VE(t)}`)}}finally{n===h.current&&(_.current=!1,E(null))}},[M]),I=(0,A.useCallback)(async({commandId:e,message:t,title:n,overwriteFiles:r,submitLabel:i=`继续`})=>{let a=ME(p.current),o=h.current;try{await a.showPrompt({message:t,submitLabel:i,title:n,type:`confirm`})===!0&&o===h.current&&await F({commandId:e,overwriteFiles:r})}catch(e){o===h.current&&O(VE(e))}},[F]),L=(0,A.useCallback)(async()=>{if(!C||_.current)return;_.current=!0;let e=++h.current;v.current=null,b(!1);let t=ME(p.current);E(`configuration.save`),O(null);try{let n=await t.commands.execute(`configuration.save`,C),r=NE(n.value);if(e!==h.current)return;M(r,!0),l(!1),ys(t,{level:n.publication.status===`pending`?`warn`:`success`,description:xs(n.publication),title:`同步配置已保存`})}catch(t){e===h.current&&O(VE(t))}finally{e===h.current&&(_.current=!1,E(null))}},[M,C]),R=(0,A.useCallback)(()=>{x&&w(IE(x)),l(!1)},[x]),ee=(0,A.useCallback)((e,t)=>{w(n=>n&&{...n,targets:RE({values:n.targets,value:e,isSelected:t})})},[]),z=(0,A.useCallback)((e,t)=>{w(n=>n&&{...n,features:RE({values:n.features,value:e,isSelected:t})})},[]),B=(0,A.useCallback)(e=>{let t=e.currentTarget.checked;w(e=>e&&{...e,autoSync:t})},[]),te=(0,A.useCallback)(()=>I({commandId:`sync`,message:`将规则更新到当前 Workspace 中已选择客户端的 AI 上下文文件。`,title:`同步 AI 上下文`}),[I]),ne=(0,A.useCallback)(async()=>{!_.current&&x?.conflicts.length&&await I({commandId:`sync`,overwriteFiles:x.conflicts,title:`强制覆盖并同步`,submitLabel:`强制覆盖并同步`,message:`将丢弃以下客户端文件中的本地修改,按所选同步目标重新生成客户端配置,并恢复当前会话的规则与 MCP 连接。\n\n${x.conflicts.map(({path:e})=>e).join(`
308
+ `}function oD(e,t){if(e.kind===`mcp`)return`server.json`;if(e.kind!==`skills`)return`rules/.rulesync/${e.kind}/${e.id}.md`;let n=t?t.split(`/`).slice(4).join(`/`):`SKILL.md`;return`rules/.rulesync/skills/${e.id}/${n}`}function sD(e){try{let t=JSON.parse(e??`{}`);return t&&typeof t==`object`&&!Array.isArray(t)?t:null}catch{return null}}const cD=new Map([[`local`,`仅本地`],[`pending`,`待同步`],[`synced`,`已同步`],[`unknown`,`状态未知`]]),lD=new Map([[`rules`,`Rules`],[`skills`,`Skills`],[`mcp`,`MCP`],[`commands`,`Commands`],[`subagents`,`Subagents`]]),uD=(0,A.memo)(function({host:e,isActive:t,workspaceId:n}){let{catalog:r,kind:i,selected:a,draft:o,mode:s,error:c,isBusy:l,isRefreshing:u,isReading:d,query:f,isSourceView:p,isEditing:m,refresh:h,handleOpen:g,handleKind:_,handleCreate:v,handleEdit:y,handleCancel:b,handleId:x,handleFile:S,handleSearch:C,handleSourceView:w,handleContent:T,handleMarkdownContent:E,handleMcpField:D,handleImport:O,handleSave:k,handleToggleRepository:A,handleDelete:j,handlePublish:M,handleWorkflows:N,resource:P,file:F,server:I,visibleItems:L,isMarkdown:R,fileName:ee}=iD({host:e,isActive:t,workspaceId:n}),z=L[0],B=a?.id??z?.id,te=r?.publicationWarning,ne=P?.repository?F?.path:F?.path.slice(6);return(0,V.jsxs)(`section`,{className:`configuration-manager`,"data-editing":m,"aria-label":`资源配置`,children:[c&&!m&&(0,V.jsx)(ws,{isDismissible:!!r,title:`规则资源操作未完成`,error:c,scope:`当前资源操作;已读取的资源内容保留。`,recovery:`按原因处理后重试;资源仍被引用时可检查工作流关联。`,children:(0,V.jsx)(Go,{variant:`subtle`,onClick:N,children:`查看工作流关联`})}),m&&P&&c&&(0,V.jsx)(ws,{isDismissible:!0,title:`资源保存未完成`,error:c,scope:`当前资源的保存;编辑内容已保留。`,recovery:`处理冲突或配置问题后重试保存。`}),m?(0,V.jsx)(`p`,{className:`configuration-editing-notice`,role:`status`,children:`正在编辑,保存或取消后可切换资源类型与条目。`}):null,(0,V.jsxs)(`header`,{className:`configuration-navigation`,children:[(0,V.jsx)(`nav`,{className:`configuration-tabs`,"aria-label":`资源类型`,children:[...lD].map(([e,t])=>(0,V.jsxs)(`button`,{type:`button`,value:e,"aria-pressed":i===e,disabled:m||l,onClick:_,children:[t,(0,V.jsx)(`span`,{"aria-hidden":`true`,children:r?.resources.filter(t=>t.kind===e).length??0})]},e))}),r?.pendingPublication&&(0,V.jsxs)(Go,{size:`compact-sm`,variant:`light`,disabled:m||l,onClick:M,children:[`发布规则变更 · `,r.pendingPublication.files.length]}),(0,V.jsx)(Go,{variant:`subtle`,color:`gray`,size:`compact-sm`,loading:u,disabled:m||l,onClick:h,children:`刷新列表`})]}),te&&(0,V.jsx)(ws,{title:`规则同步状态暂不可用`,error:te,scope:`资源的同步状态。`,recovery:`重新读取后可继续检查哪些规则需要发布。`,children:(0,V.jsx)(Go,{size:`compact-sm`,variant:`default`,disabled:m||l||u,onClick:h,children:`重试读取`})}),(0,V.jsxs)(`div`,{className:`configuration-resource-grid`,children:[(0,V.jsxs)(`aside`,{className:`configuration-list`,"aria-label":`资源目录`,children:[(0,V.jsxs)(`div`,{className:`configuration-list-heading`,children:[(0,V.jsx)(`h2`,{children:`资源目录`}),(0,V.jsx)(Go,{size:`compact-sm`,variant:`default`,disabled:m||l||d,onClick:v,children:`新增`})]}),(0,V.jsx)(`input`,{autoCapitalize:`none`,className:`configuration-search`,type:`search`,"aria-label":`搜索资源`,placeholder:`搜索资源名称…`,value:f,onChange:C,disabled:m}),(0,V.jsxs)(`div`,{className:`configuration-items`,children:[!r&&(0,V.jsx)(`p`,{className:`configuration-notice`,role:`status`,children:c?`资源尚未读取`:`正在读取资源…`}),r&&!L.length&&(0,V.jsx)(`p`,{className:`configuration-notice`,children:f?`没有匹配的资源,试试其他名称。`:`还没有资源,从新增开始。`}),L.map(e=>(0,V.jsxs)(`div`,{className:`configuration-item`,children:[(0,V.jsxs)(`button`,{type:`button`,className:`configuration-row`,"data-id":e.id,"aria-current":B===e.id?`true`:void 0,disabled:m||l,onClick:g,children:[(0,V.jsx)(`strong`,{children:e.title??e.id}),(0,V.jsx)(`span`,{children:e.repository?`来源仓库 · `+e.repository.label:e.id+` · `+e.paths.length+` 个文件`}),(0,V.jsx)(`span`,{className:`resource-publication`,"data-status":e.publicationStatus??`unknown`,children:e.repository?e.repository.enabled?`已启用`:`已停用`:cD.get(e.publicationStatus??`unknown`)})]}),!m&&!e.repository?(0,V.jsx)(Go,{className:`configuration-delete`,variant:`subtle`,color:`red`,size:`compact-sm`,"data-id":e.id,disabled:l||d,onClick:j,title:`删除资源`,"aria-label":`删除资源:`+(e.title??e.id),children:(0,V.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:(0,V.jsx)(`path`,{d:`M3 6h18M9 6V4h6v2M5 6l1 14h12l1-14M10 10v6M14 10v6`})})}):null]},e.id))]}),i===`skills`&&(0,V.jsx)(`div`,{className:`configuration-list-footer`,children:(0,V.jsx)(Go,{variant:`subtle`,size:`compact-sm`,disabled:m||l||d,onClick:O,children:`导入 Skill 目录`})})]}),(0,V.jsxs)(`section`,{className:`configuration-detail`,"aria-label":`资源详情`,"aria-busy":d||!r&&u,tabIndex:0,children:[d&&(0,V.jsxs)(`p`,{className:`configuration-reading`,role:`status`,children:[(0,V.jsx)(fi,{size:`xs`}),`正在读取内容…`]}),!P&&!d&&z&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`header`,{className:`configuration-detail-header`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h2`,{children:z.title??z.id}),(0,V.jsxs)(`p`,{children:[lD.get(i),` `,(0,V.jsx)(`code`,{children:z.id})]})]}),(0,V.jsx)(Go,{"data-id":z.id,onClick:g,children:`查看正文`})]}),(0,V.jsx)(`div`,{className:`configuration-detail-body`,children:(0,V.jsxs)(`dl`,{className:`configuration-facts`,children:[z.repository?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`dt`,{children:`来源仓库`}),(0,V.jsx)(`dd`,{children:z.repository.label})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`dt`,{children:`应用范围`}),(0,V.jsxs)(`dd`,{children:[`仅在修改此仓库时应用 · `,z.repository.enabled?`已启用`:`已停用`]})]})]}):(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`dt`,{children:`同步状态`}),(0,V.jsx)(`dd`,{children:cD.get(z.publicationStatus??`unknown`)})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`dt`,{children:`关联文件`}),(0,V.jsxs)(`dd`,{children:[z.paths.length,` 个`]})]}),z.description&&(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`dt`,{children:`说明`}),(0,V.jsx)(`dd`,{children:z.description})]}),z.paths[0]&&(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`dt`,{children:`文件路径`}),(0,V.jsx)(`dd`,{children:(0,V.jsx)(`code`,{children:z.paths[0]})})]})]})})]}),r&&!P&&!d&&!z&&(0,V.jsxs)(`div`,{className:`configuration-empty`,children:[(0,V.jsx)(`h2`,{children:`暂无可查看的资源`}),(0,V.jsx)(`p`,{children:f?`试试其他名称,或清空搜索。`:`可在目录中新增资源。`})]}),P&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`header`,{className:m?`configuration-detail-header is-editing`:`configuration-detail-header`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h2`,{children:s===bs.Create?`新增 ${lD.get(i)}`:P.title??P.id}),P.repository?(0,V.jsxs)(`p`,{children:[`来源 · `,P.repository.label,` / AGENTS.md`,(0,V.jsx)(`br`,{}),`仅在修改此仓库时应用`]}):null,(0,V.jsxs)(`p`,{children:[lD.get(P.kind),(0,V.jsx)(`code`,{children:P.id}),(0,V.jsx)(`span`,{className:`configuration-mode`,children:m?`编辑中`:`只读查看`})]})]}),m?(0,V.jsxs)(`div`,{className:`configuration-actions`,children:[(0,V.jsx)(Go,{variant:`default`,disabled:l,onClick:b,children:`取消编辑`}),(0,V.jsx)(Go,{loading:l,disabled:!o?.id.trim(),onClick:k,children:`保存并同步`})]}):P.repository?(0,V.jsx)(ms,{label:`启用仓库规则`,checked:P.repository.enabled,disabled:l||d,onChange:A}):(0,V.jsx)(Go,{disabled:l||d,onClick:y,children:`编辑`}),m&&(0,V.jsx)(`div`,{className:`configuration-header-feedback`,children:(0,V.jsx)(`p`,{children:`保存后,团队成员可以同步这份资源。`})})]}),(0,V.jsxs)(`div`,{className:`configuration-detail-body`,children:[m&&(0,V.jsxs)(`section`,{className:`configuration-section`,children:[(0,V.jsx)(`h3`,{children:`基本信息`}),(0,V.jsxs)(`label`,{className:`configuration-field`,children:[`ID`,(0,V.jsx)(`input`,{autoCapitalize:`none`,disabled:l,value:P.id,onChange:x,readOnly:s!==bs.Create,placeholder:`例如 team-review`}),(0,V.jsx)(`span`,{className:`configuration-hint`,children:s===bs.Create?`使用字母、数字、短横线或下划线。`:`已有资源的 ID 保持不变,工作流通过它关联资源。`})]})]}),m&&i===`mcp`&&(0,V.jsxs)(`section`,{className:`configuration-section`,children:[(0,V.jsx)(`h3`,{children:`连接设置`}),(0,V.jsxs)(`div`,{className:`configuration-fields`,children:[(0,V.jsxs)(`label`,{className:`configuration-field`,children:[`启动命令`,(0,V.jsx)(`input`,{autoCapitalize:`none`,name:`command`,value:typeof I?.command==`string`?I.command:``,disabled:l||!I,onChange:D,placeholder:`本机已安装的程序`})]}),(0,V.jsxs)(`label`,{className:`configuration-field`,children:[`服务地址`,(0,V.jsx)(`input`,{autoCapitalize:`none`,name:`url`,value:typeof I?.url==`string`?I.url:``,disabled:l||!I,onChange:D,placeholder:`https://…`})]})]})]}),(0,V.jsxs)(`section`,{className:`configuration-section`,children:[(0,V.jsxs)(`div`,{className:`configuration-document-bar`,children:[P.files.length>1?(0,V.jsxs)(`label`,{className:`configuration-file-picker`,children:[`文件`,(0,V.jsx)(`select`,{disabled:l,value:F?.path??``,onChange:S,children:P.files.map(({path:e})=>(0,V.jsx)(`option`,{value:e,children:e.split(`/`).slice(4).join(`/`)||e},e))})]}):(0,V.jsx)(`span`,{children:ee||(i===`mcp`?`MCP 配置`:`资源内容`)}),!m&&R&&(0,V.jsx)(Go,{variant:`subtle`,color:`gray`,size:`compact-sm`,onClick:w,children:p?`返回预览`:`查看源码`})]}),m&&R?(0,V.jsx)(Ls,{label:`正文与元数据`,sourcePath:ne,value:F?.content??``,onChange:E,isDisabled:l},P.id+`:`+(F?.path??``)):m?(0,V.jsxs)(`label`,{className:`configuration-field`,children:[i===`mcp`?`MCP JSON`:`正文与元数据`,(0,V.jsx)(`textarea`,{autoCapitalize:`none`,className:`configuration-code-editor`,disabled:l,rows:18,value:F?.content??``,onChange:T,spellCheck:!1}),(0,V.jsx)(`span`,{className:`configuration-hint`,children:i===`mcp`?`可粘贴完整服务配置,额外字段会保留。`:`直接编辑源文件,保留 Markdown 与文件头元数据。`})]}):R&&!p?(0,V.jsx)(kE,{content:F?.content??``,sourcePath:ne}):(0,V.jsx)(`pre`,{className:`configuration-content`,tabIndex:0,children:F?.content||`(内容为空)`})]})]}),!m&&(0,V.jsx)(`footer`,{className:`configuration-footer`,children:(0,V.jsx)(`p`,{children:`保存后,团队成员可以同步这份资源。`})})]})]},JSON.stringify([i,a?.id,m&&!a]))]})]})});var dD=class extends Error{code;constructor(e,t){super(t),this.name=`PenpalError`,this.code=e}},fD=e=>({name:e.name,message:e.message,stack:e.stack,penpalCode:e instanceof dD?e.code:void 0}),pD=({name:e,message:t,stack:n,penpalCode:r})=>{let i=r?new dD(r,t):Error(t);return i.name=e,i.stack=n,i},mD=class{value;transferables;constructor(e,t){this.value=e,this.transferables=t?.transferables}},hD=`penpal`,gD=e=>typeof e==`object`&&!!e,_D=e=>typeof e==`function`,vD=e=>gD(e)&&e.namespace===hD,yD=e=>e.type===`SYN`,bD=e=>e.type===`ACK1`,xD=e=>e.type===`ACK2`,SD=e=>e.type===`CALL`,CD=e=>e.type===`REPLY`,wD=e=>e.type===`DESTROY`,TD=(e,t=[])=>{let n=[];for(let r of Object.keys(e)){let i=e[r];_D(i)?n.push([...t,r]):gD(i)&&n.push(...TD(i,[...t,r]))}return n},ED=(e,t)=>{let n=e.reduce((e,t)=>gD(e)?e[t]:void 0,t);return _D(n)?n:void 0},DD=e=>e.join(`.`),OD=(e,t,n)=>({namespace:hD,channel:e,type:`REPLY`,callId:t,isError:!0,...n instanceof Error?{value:fD(n),isSerializedErrorInstance:!0}:{value:n}}),kD=(e,t,n,r)=>{let i=!1,a=async a=>{if(i||!SD(a))return;r?.(`Received ${DD(a.methodPath)}() call`,a);let{methodPath:o,args:s,id:c}=a,l,u;try{let e=ED(o,t);if(!e)throw new dD(`METHOD_NOT_FOUND`,`Method \`${DD(o)}\` is not found.`);let r=await e(...s);r instanceof mD&&(u=r.transferables,r=await r.value),l={namespace:hD,channel:n,type:`REPLY`,callId:c,value:r}}catch(e){l=OD(n,c,e)}if(!i)try{r?.(`Sending ${DD(o)}() reply`,l),e.sendMessage(l,u)}catch(t){throw t.name===`DataCloneError`&&(l=OD(n,c,t),r?.(`Sending ${DD(o)}() reply`,l),e.sendMessage(l)),t}};return e.addMessageHandler(a),()=>{i=!0,e.removeMessageHandler(a)}},AD=crypto.randomUUID?.bind(crypto)??(()=>[,,,,].fill(0).map(()=>Math.floor(Math.random()*(2**53-1)).toString(16)).join(`-`)),jD=class{transferables;timeout;constructor(e){this.transferables=e?.transferables,this.timeout=e?.timeout}},MD=new Set([`apply`,`call`,`bind`]),ND=(e,t,n=[])=>new Proxy(n.length?()=>{}:Object.create(null),{get(r,i){if(i!==`then`)return n.length&&MD.has(i)?Reflect.get(r,i):ND(e,t,[...n,i])},apply(t,r,i){return e(n,i)}}),PD=e=>new dD(`CONNECTION_DESTROYED`,`Method call ${DD(e)}() failed due to destroyed connection`),FD=(e,t,n)=>{let r=!1,i=new Map,a=e=>{if(!CD(e))return;let{callId:t,value:r,isError:a,isSerializedErrorInstance:o}=e,s=i.get(t);s&&(i.delete(t),n?.(`Received ${DD(s.methodPath)}() call`,e),a?s.reject(o?pD(r):r):s.resolve(r))};return e.addMessageHandler(a),{remoteProxy:ND((a,o)=>{if(r)throw PD(a);let s=AD(),c=o[o.length-1],l=c instanceof jD,{timeout:u,transferables:d}=l?c:{},f=l?o.slice(0,-1):o;return new Promise((r,o)=>{let c=u===void 0?void 0:window.setTimeout(()=>{i.delete(s),o(new dD(`METHOD_CALL_TIMEOUT`,`Method call ${DD(a)}() timed out after ${u}ms`))},u);i.set(s,{methodPath:a,resolve:r,reject:o,timeoutId:c});try{let r={namespace:hD,channel:t,type:`CALL`,id:s,methodPath:a,args:f};n?.(`Sending ${DD(a)}() call`,r),e.sendMessage(r,d)}catch(e){o(new dD(`TRANSMISSION_FAILED`,e.message))}})},n),destroy:()=>{r=!0,e.removeMessageHandler(a);for(let{methodPath:e,reject:t,timeoutId:n}of i.values())clearTimeout(n),t(PD(e));i.clear()}}},ID=()=>{let e,t;return{promise:new Promise((n,r)=>{e=n,t=r}),resolve:e,reject:t}},LD=`deprecated-penpal`,RD=e=>gD(e)&&`penpal`in e,zD=e=>e.split(`.`),BD=e=>e.join(`.`),VD=e=>{try{return JSON.stringify(e)}catch{return String(e)}},HD=e=>new dD(`TRANSMISSION_FAILED`,`Unexpected message to translate: ${VD(e)}`),UD=e=>{if(e.penpal===`syn`)return{namespace:hD,channel:void 0,type:`SYN`,participantId:LD};if(e.penpal===`ack`)return{namespace:hD,channel:void 0,type:`ACK2`};if(e.penpal===`call`)return{namespace:hD,channel:void 0,type:`CALL`,id:e.id,methodPath:zD(e.methodName),args:e.args};if(e.penpal===`reply`)return e.resolution===`fulfilled`?{namespace:hD,channel:void 0,type:`REPLY`,callId:e.id,value:e.returnValue}:{namespace:hD,channel:void 0,type:`REPLY`,callId:e.id,isError:!0,...e.returnValueIsError?{value:e.returnValue,isSerializedErrorInstance:!0}:{value:e.returnValue}};throw HD(e)},WD=e=>{if(bD(e))return{penpal:`synAck`,methodNames:e.methodPaths.map(BD)};if(SD(e))return{penpal:`call`,id:e.id,methodName:BD(e.methodPath),args:e.args};if(CD(e))return e.isError?{penpal:`reply`,id:e.callId,resolution:`rejected`,...e.isSerializedErrorInstance?{returnValue:e.value,returnValueIsError:!0}:{returnValue:e.value}}:{penpal:`reply`,id:e.callId,resolution:`fulfilled`,returnValue:e.value};throw HD(e)},GD=({messenger:e,methods:t,timeout:n,channel:r,log:i})=>{let a=AD(),o,s=[],c=!1,l=TD(t),{promise:u,resolve:d,reject:f}=ID(),p=n===void 0?void 0:setTimeout(()=>{f(new dD(`CONNECTION_TIMEOUT`,`Connection timed out after ${n}ms`))},n),m=()=>{for(let e of s)e()},h=()=>{if(c)return;s.push(kD(e,t,r,i));let{remoteProxy:n,destroy:a}=FD(e,r,i);s.push(a),clearTimeout(p),c=!0,d({remoteProxy:n,destroy:m})},g=()=>{let t={namespace:hD,type:`SYN`,channel:r,participantId:a};i?.(`Sending handshake SYN`,t);try{e.sendMessage(t)}catch(e){f(new dD(`TRANSMISSION_FAILED`,e.message))}},_=t=>{if(i?.(`Received handshake SYN`,t),t.participantId===o&&o!==LD||(o=t.participantId,g(),!(a>o||o===LD)))return;let n={namespace:hD,channel:r,type:`ACK1`,methodPaths:l};i?.(`Sending handshake ACK1`,n);try{e.sendMessage(n)}catch(e){f(new dD(`TRANSMISSION_FAILED`,e.message));return}},v=t=>{i?.(`Received handshake ACK1`,t);let n={namespace:hD,channel:r,type:`ACK2`};i?.(`Sending handshake ACK2`,n);try{e.sendMessage(n)}catch(e){f(new dD(`TRANSMISSION_FAILED`,e.message));return}h()},y=e=>{i?.(`Received handshake ACK2`,e),h()},b=e=>{yD(e)&&_(e),bD(e)&&v(e),xD(e)&&y(e)};return e.addMessageHandler(b),s.push(()=>e.removeMessageHandler(b)),g(),u},KD=e=>{let t=!1,n;return(...r)=>(t||(t=!0,n=e(...r)),n)},qD=new WeakSet,JD=({messenger:e,methods:t={},timeout:n,channel:r,log:i})=>{if(!e)throw new dD(`INVALID_ARGUMENT`,`messenger must be defined`);if(qD.has(e))throw new dD(`INVALID_ARGUMENT`,`A messenger can only be used for a single connection`);qD.add(e);let a=[e.destroy],o=KD(t=>{if(t){let t={namespace:hD,channel:r,type:`DESTROY`};try{e.sendMessage(t)}catch{}}for(let e of a)e();i?.(`Connection destroyed`)}),s=e=>vD(e)&&e.channel===r;return{promise:(async()=>{try{e.initialize({log:i,validateReceivedMessage:s}),e.addMessageHandler(e=>{wD(e)&&o(!1)});let{remoteProxy:c,destroy:l}=await GD({messenger:e,methods:t,timeout:n,channel:r,log:i});return a.push(l),c}catch(e){throw o(!0),e}})(),destroy:()=>{o(!0)}}},YD=class{#e;#t;#n;#r;#i;#a=new Set;#o;#s=!1;constructor({remoteWindow:e,allowedOrigins:t}){if(!e)throw new dD(`INVALID_ARGUMENT`,`remoteWindow must be defined`);this.#e=e,this.#t=t?.length?t:[window.origin]}initialize=({log:e,validateReceivedMessage:t})=>{this.#n=e,this.#r=t,window.addEventListener(`message`,this.#d)};sendMessage=(e,t)=>{if(yD(e)){let n=this.#l(e);this.#e.postMessage(e,{targetOrigin:n,transfer:t});return}if(bD(e)||this.#s){let n=this.#s?WD(e):e,r=this.#l(e);this.#e.postMessage(n,{targetOrigin:r,transfer:t});return}if(xD(e)){let{port1:n,port2:r}=new MessageChannel;this.#o=n,n.addEventListener(`message`,this.#f),n.start();let i=[r,...t||[]],a=this.#l(e);this.#e.postMessage(e,{targetOrigin:a,transfer:i});return}if(this.#o){this.#o.postMessage(e,{transfer:t});return}throw new dD(`TRANSMISSION_FAILED`,`Cannot send message because the MessagePort is not connected`)};addMessageHandler=e=>{this.#a.add(e)};removeMessageHandler=e=>{this.#a.delete(e)};destroy=()=>{window.removeEventListener(`message`,this.#d),this.#u(),this.#a.clear()};#c=e=>this.#t.some(t=>t instanceof RegExp?t.test(e):t===e||t===`*`);#l=e=>{if(yD(e))return`*`;if(!this.#i)throw new dD(`TRANSMISSION_FAILED`,`Cannot send message because the remote origin is not established`);return this.#i===`null`&&this.#t.includes(`*`)?`*`:this.#i};#u=()=>{this.#o?.removeEventListener(`message`,this.#f),this.#o?.close(),this.#o=void 0};#d=({source:e,origin:t,ports:n,data:r})=>{if(e===this.#e){if(RD(r)){this.#n?.(`Please upgrade the child window to the latest version of Penpal.`),this.#s=!0;try{r=UD(r)}catch(e){this.#n?.(`Failed to translate deprecated message: ${e.message}`);return}}if(this.#r?.(r)){if(!this.#c(t)){this.#n?.(`Received a message from origin \`${t}\` which did not match allowed origins \`[${this.#t.join(`, `)}]\``);return}if(yD(r)&&(this.#u(),this.#i=t),xD(r)&&!this.#s){if(this.#o=n[0],!this.#o){this.#n?.(`Ignoring ACK2 because it did not include a MessagePort`);return}this.#o.addEventListener(`message`,this.#f),this.#o.start()}for(let e of this.#a)e(r)}}};#f=({data:e})=>{if(this.#r?.(e))for(let t of this.#a)t(e)}};function XD(e,t){let n=e?.onInit,r=t?.connectToHost,i=t?.targetWindow;if(typeof n!=`function`)throw TypeError(`defineWorkbasePluginUi requires an onInit callback.`);if(!i||typeof r!=`function`)throw TypeError(`Plugin UI transport is unavailable.`);let a={fatalReportPromise:null,isInitialized:!1,supportsRepositoryPush:!1,contentHeight:null,recoverableHostErrors:new WeakSet},o=new Set,s=new Set,c=0,l=!1,u=!1,d={filesChanged:async()=>{if(u=!0,!(l||c||!a.isInitialized)){l=!0;try{for(;u;)u=!1,await Promise.all([...s].map(e=>e()))}finally{l=!1}}},executionChanged:async e=>{a.isInitialized&&[...o].forEach(t=>t(e))},initialize:async e=>{oO(e),a.isInitialized=!0,a.supportsRepositoryPush=e.supportsRepositoryPush===!0,c++;try{await n(e)}finally{c--}u&&await d.filesChanged(),await nO(i),await aO(p,{targetWindow:i,state:a})}},f=r(d),p=f.promise,m=ZD(p,a);return eO({connection:f,state:a,targetWindow:i}),$D(m,{targetWindow:i,subscribe:async e=>{let t=t=>e(t);o.add(t);try{await m(`command.subscribe`,{enabled:!0})}catch(e){throw o.delete(t),e}return async()=>{o.delete(t)&&!o.size&&await m(`command.subscribe`,{enabled:!1})}},onFilesChanged:e=>(s.add(e),()=>{s.delete(e)})})}function ZD(e,t){return async(n,r)=>{if(!t.isInitialized)throw Error(`Plugin UI is not initialized.`);if(n===`repository.push`&&!t.supportsRepositoryPush){let e=Error(`当前 Workbase 版本无法在插件内推送,请在工作区同步仓库。`);throw t.recoverableHostErrors.add(e),e}let i=await(await e).call(n,r);if(uO(i)&&i.ok===!0)return i.result;let a=QD(i);throw t.recoverableHostErrors.add(a),a}}function QD(e){let t=uO(e)&&uO(e.error)?e.error:null,n=typeof t?.message==`string`?t.message:`Host action failed.`,r=typeof t?.code==`string`?t.code:`host_error`;return Object.assign(Error(n),{code:r})}function $D(e,{targetWindow:t,subscribe:n,onFilesChanged:r}){let i=Object.freeze({subscribe:n,reply:t=>e(`command.reply`,{executionId:t}),clear:t=>e(`command.clear`,t===void 0?{}:{executionId:t}),start:(n,r,i={})=>e(`command.start`,{commandId:n,input:r,executionId:i.executionId??t.crypto.randomUUID()}),query:t=>e(`command.query`,{executionId:t??null}),cancel:t=>e(`command.cancel`,{executionId:t}),execute:(n,r,i={})=>e(`command.execute`,{commandId:n,executionId:i.executionId??t.crypto.randomUUID(),input:r})}),a=Object.freeze({resolve:(t,n)=>e(`status.resolve`,{input:n,statusId:t})}),o=Object.freeze({onFilesChanged:r,setModified:t=>e(`view.modified`,t),call:(t,n)=>e(`view.call`,{input:n,method:t})});return Object.freeze({dismiss:()=>e(`interaction.dismiss`,{}),respond:t=>e(`interaction.respond`,{value:t}),closeOutput:t=>e(`output.close`,{id:t}),commands:i,desktop:Object.freeze({open:t=>e(`desktop.open`,t)}),repositories:Object.freeze({push:t=>e(`repository.push`,t)}),navigate:(t,{replace:n=!1}={})=>e(`navigate`,{replace:n,to:t}),openOutput:t=>e(`output.open`,t),selectFiles:(t={})=>e(`file.select`,t),showPrompt:t=>e(`dialog.prompt`,t),showToast:t=>e(`toast.show`,t),status:a,updateOutput:t=>e(`output.update`,t),view:o})}function eO({connection:e,state:t,targetWindow:n}){let r=null,i=n=>{(n.error||n.message!==`ResizeObserver loop completed with undelivered notifications.`&&n.message!==`ResizeObserver loop limit exceeded`)&&rO(e.promise,t,n.error??n.message)},a=n=>{n.reason instanceof Error&&t.recoverableHostErrors.has(n.reason)||rO(e.promise,t,n.reason)},o=new n.ResizeObserver(()=>{r===null&&(r=n.requestAnimationFrame(()=>{r=null,t.isInitialized&&aO(e.promise,{targetWindow:n,state:t})}))}),s=()=>{n.removeEventListener(`error`,i,!0),n.removeEventListener(`unhandledrejection`,a),n.removeEventListener(`beforeunload`,s),o.disconnect(),r!==null&&n.cancelAnimationFrame(r),e.destroy(),t.fatalReportPromise=null,t.isInitialized=!1};tO(e.promise),o.observe(n.document.body??n.document.documentElement),n.addEventListener(`error`,i,!0),n.addEventListener(`unhandledrejection`,a),n.addEventListener(`beforeunload`,s,{once:!0})}async function tO(e){try{await e}catch{}}async function nO(e){await new Promise(t=>{e.requestAnimationFrame(()=>{e.requestAnimationFrame(()=>t())})})}async function rO(e,t,n){t.fatalReportPromise||=iO(e,dO(n).slice(0,1e3)),await t.fatalReportPromise}async function iO(e,t){try{await(await e).reportFatal(t)}catch{}}async function aO(e,{targetWindow:t,state:n}){let r=t.document.body??t.document.documentElement,i=Math.max(r.offsetHeight,r.scrollHeight);if(Number.isFinite(i))try{let t=await e,r=Math.min(Math.max(Math.ceil(i),1),1e4);if(!n.isInitialized||n.contentHeight===r)return;n.contentHeight=r,await t.reportContentHeight(r)}catch{}}function oO(e){if(!sO(e))throw TypeError(`Plugin UI initialization payload is invalid.`)}function sO(e){return!uO(e)||e.configurationRevision!==void 0&&typeof e.configurationRevision!=`string`||e.activationGeneration!==void 0&&(!Number.isSafeInteger(e.activationGeneration)||Number(e.activationGeneration)<0)?!1:cO(e.project)&&cO(e.workspace)&&lO(e.view)}function cO(e){return uO(e)&&typeof e.id==`string`&&e.id.length>0}function lO(e){return cO(e)&&uO(e)&&typeof e.pluginId==`string`&&e.pluginId.length>0&&typeof e.title==`string`&&e.title.length>0}function uO(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function dO(e){return e instanceof Error?e.message:typeof e==`string`&&e.trim().length>0?e:`Plugin UI failed.`}function fO(e){let t=window;return XD(e,{connectToHost:e=>pO(t,e),targetWindow:t})}function pO(e,t){let n=JD({channel:`workbase-plugin-ui-v1`,messenger:new YD({allowedOrigins:mO(e),remoteWindow:e.parent}),methods:t});return{destroy:n.destroy,promise:n.promise}}function mO(e){let t=new URL(e.location.href).searchParams.get(`__workbaseHostOrigin`);return t&&t!==`null`?[t]:[`*`]}function hO(){let[e,t]=(0,A.useState)(``),[n,r]=(0,A.useState)(0),[i,a]=(0,A.useState)(``),[o,s]=(0,A.useState)(!0),[c,l]=(0,A.useState)(!1),u=(0,A.useCallback)(()=>s(!0),[]),d=(0,A.useCallback)(()=>s(!1),[]),f=(0,A.useCallback)(()=>l(!0),[]),p=(0,A.useRef)(null),m=(0,A.useRef)(null),h=(0,A.useRef)(0),g=(0,A.useRef)(null),_=(0,A.useRef)(!1),v=(0,A.useRef)(null),[y,b]=(0,A.useState)(!1),[x,S]=(0,A.useState)(null),[C,w]=(0,A.useState)(null),[T,E]=(0,A.useState)(null),[D,O]=(0,A.useState)(null),[k,j]=(0,A.useState)(null),M=(0,A.useCallback)((e,t=!1)=>{let n=g.current;g.current=e,S(e),w(r=>!t&&r&&n&&!LE(n,r)?r:IE(e))},[]),N=(0,A.useCallback)(async()=>{if(_.current)return;if(v.current)return v.current;let e=ME(p.current),t=h.current;return b(!0),v.current=(async()=>{try{let n=NE(await e.status.resolve(`sync`,{}));if(t!==h.current)return;M(n),O(null)}catch(e){t===h.current&&O(VE(e))}finally{t===h.current&&(v.current=null,b(!1))}})(),v.current},[M]),P=(0,A.useCallback)(e=>{r(e.activationGeneration??0);let n=JSON.stringify([e.project.id,e.workspace.id]);m.current!==n&&(m.current=n,h.current+=1,g.current=null,v.current=null,_.current=!1,t(n),a(e.workspace.id),l(!1),S(null),w(null),E(null),O(null),j(null),N())},[N]);(0,A.useEffect)(()=>{p.current=fO({onInit:P});let e=p.current.view.onFilesChanged?.(N);return()=>{e?.(),h.current+=1,p.current=null}},[P,N]);let F=(0,A.useCallback)(async({commandId:e,overwriteFiles:t})=>{if(_.current)return;_.current=!0;let n=++h.current;v.current=null,b(!1);let r=ME(p.current);E(e),O(null);try{let i=await r.commands.execute(e,t?{overwriteFiles:t}:{}),a=PE(i.value);if(n!==h.current)return;M(a.status),j({logId:i.logId,result:a.result})}catch(e){if(n!==h.current)return;O(VE(e));try{let e=NE(await r.status.resolve(`sync`,{}));n===h.current&&M(e)}catch(t){n===h.current&&O(`${VE(e)}\n同步状态读取失败:${VE(t)}`)}}finally{n===h.current&&(_.current=!1,E(null))}},[M]),I=(0,A.useCallback)(async({commandId:e,message:t,title:n,overwriteFiles:r,submitLabel:i=`继续`})=>{let a=ME(p.current),o=h.current;try{await a.showPrompt({message:t,submitLabel:i,title:n,type:`confirm`})===!0&&o===h.current&&await F({commandId:e,overwriteFiles:r})}catch(e){o===h.current&&O(VE(e))}},[F]),L=(0,A.useCallback)(async()=>{if(!C||_.current)return;_.current=!0;let e=++h.current;v.current=null,b(!1);let t=ME(p.current);E(`configuration.save`),O(null);try{let n=await t.commands.execute(`configuration.save`,C),r=NE(n.value);if(e!==h.current)return;M(r,!0),l(!1),ys(t,{level:n.publication.status===`pending`?`warn`:`success`,description:xs(n.publication),title:`同步配置已保存`})}catch(t){e===h.current&&O(VE(t))}finally{e===h.current&&(_.current=!1,E(null))}},[M,C]),R=(0,A.useCallback)(()=>{x&&w(IE(x)),l(!1)},[x]),ee=(0,A.useCallback)((e,t)=>{w(n=>n&&{...n,targets:RE({values:n.targets,value:e,isSelected:t})})},[]),z=(0,A.useCallback)((e,t)=>{w(n=>n&&{...n,features:RE({values:n.features,value:e,isSelected:t})})},[]),B=(0,A.useCallback)(e=>{let t=e.currentTarget.checked;w(e=>e&&{...e,autoSync:t})},[]),te=(0,A.useCallback)(()=>I({commandId:`sync`,message:`将规则更新到当前 Workspace 中已选择客户端的 AI 上下文文件。`,title:`同步 AI 上下文`}),[I]),ne=(0,A.useCallback)(async()=>{!_.current&&x?.conflicts.length&&await I({commandId:`sync`,overwriteFiles:x.conflicts,title:`强制覆盖并同步`,submitLabel:`强制覆盖并同步`,message:`将丢弃以下客户端文件中的本地修改,按所选同步目标重新生成客户端配置,并恢复当前会话的规则与 MCP 连接。\n\n${x.conflicts.map(({path:e})=>e).join(`
309
309
  `)}`})},[I,x]),re=(0,A.useCallback)(()=>I({commandId:`initialize`,message:`将在项目根目录的 rules 文件夹中创建 Rulesync 配置,并立即生成当前 Workspace 的 AI 上下文。`,title:`初始化并同步`}),[I]),ie=(0,A.useCallback)(()=>I({commandId:`sources.update`,message:`将更新远端规则版本、锁文件和当前 Workspace 的客户端配置。`,title:`更新远端并同步`}),[I]),ae=(0,A.useCallback)(()=>F({commandId:`preview`}),[F]),oe=(0,A.useCallback)(()=>F({commandId:`doctor`}),[F]),se=(0,A.useCallback)(()=>F({commandId:`check`}),[F]),ce=(0,A.useCallback)(async()=>{k?.logId&&await ME(p.current).navigate(`/logs/${k.logId}`)},[k]),le=(0,A.useCallback)(()=>j(null),[]),ue=T!==null,de=!!(C&&C.targets.length>0&&C.features.length>0),fe=(0,A.useMemo)(()=>x!==null&&C!==null&&!LE(x,C),[C,x]),pe=(0,A.useMemo)(()=>k?FE(k.result):null,[k]),me=x?.configured&&!x.conflicts.length?`teal`:`orange`;return{resourceKey:e,markdownContextKey:JSON.stringify([e,n]),workspaceId:i,isResourceMode:o,isEditingSync:c,handleResourceMode:u,handleSyncMode:d,handleEditSync:f,pluginUiRef:p,contextKeyRef:m,isRefreshing:y,status:x,draft:C,busyCommand:T,error:D,operationDialog:k,refreshStatus:N,handleSave:L,handleCancelSync:R,handleTargetToggle:ee,handleFeatureToggle:z,handleAutoSyncChange:B,handleSync:te,handleForceSync:ne,handleInitialize:re,handleUpdateSources:ie,handlePreview:ae,handleDoctor:oe,handleCheck:se,handleOpenLog:ce,handleCloseResult:le,isBusy:ue,isConfigurationValid:de,isDirty:fe,operationPresentation:pe,statusColor:me}}const gO=[{label:`Codex CLI`,value:`codexcli`},{label:`Claude Code`,value:`claudecode`}],_O=[{label:`规则`,value:`rules`},{label:`MCP`,value:`mcp`},{label:`命令`,value:`commands`},{label:`子代理`,value:`subagents`},{label:`技能`,value:`skills`}],vO=(0,A.memo)(function(){let{resourceKey:e,markdownContextKey:t,workspaceId:n,isResourceMode:r,isEditingSync:i,handleResourceMode:a,handleSyncMode:o,handleEditSync:s,pluginUiRef:c,contextKeyRef:l,isRefreshing:u,status:d,draft:f,busyCommand:p,error:m,operationDialog:h,refreshStatus:g,handleSave:_,handleCancelSync:v,handleTargetToggle:y,handleFeatureToggle:b,handleAutoSyncChange:x,handleSync:S,handleForceSync:C,handleInitialize:w,handleUpdateSources:T,handlePreview:E,handleDoctor:D,handleCheck:O,handleOpenLog:k,handleCloseResult:A,isBusy:j,isConfigurationValid:M,isDirty:N,operationPresentation:P,statusColor:F}=hO(),I=d?.configured?`可同步`:`待初始化`,L=d?.conflicts.map(({path:e})=>e)??[],R=L.length>0,ee=j?`正在处理`:R?`需处理本地修改`:I,z=p===`preview`?`预览中…`:`预览变更`,B=p===`sync`?`同步中…`:`同步当前变动`,te=p===`initialize`?`初始化中…`:`初始化并同步`,ne=d?.lastOperation?.success?`成功`:`失败`,re=d?`规则操作未完成`:`无法读取同步配置`;return(0,V.jsx)(qs,{host:c.current,contextKey:t,children:(0,V.jsxs)(`main`,{className:`plugin-surface app-shell rules-shell`,children:[(0,V.jsxs)(`header`,{"data-tone":`teal`,className:`plugin-toolbar`,children:[(0,V.jsxs)(`h1`,{children:[(0,V.jsx)(cc,{className:`plugin-title-icon`,"aria-hidden":`true`}),`规则`]}),(0,V.jsxs)(`nav`,{className:`configuration-page-tabs`,"aria-label":`规则模式`,children:[(0,V.jsx)(`button`,{type:`button`,"aria-pressed":r,onClick:a,children:`资源配置`}),(0,V.jsx)(`button`,{type:`button`,"aria-pressed":!r,onClick:o,children:`客户端同步`})]}),(0,V.jsx)(Go,{"aria-label":`刷新状态`,title:`刷新状态`,className:`plugin-toolbar-actions rules-refresh`,leftSection:(0,V.jsx)(dc,{"aria-hidden":`true`,size:15}),hidden:r,variant:`subtle`,loading:u,disabled:j||!l.current,onClick:g,children:`刷新状态`})]}),m||R?(0,V.jsxs)(ws,{isDismissible:!(!d||R),title:R?`客户端规则存在本地修改`:re,error:m??`${L.length} 个客户端文件有本地修改,普通同步已暂停。`,scope:`当前规则操作;已读取的配置和未保存的选择均保留。`,recovery:R?`处理文件冲突后可刷新同步状态。强制覆盖会丢弃所列文件中的本地修改。`:`按原因检查相关文件或配置,处理后重试刚才的操作。`,technicalDetails:[`工作区:${d?.workspaceRoot??`尚未读取`}\n配置:${d?.configPath??`尚未读取`}`,m,L.join(`
310
310
  `)].filter(Boolean).join(`
311
311
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eworkbase/plugin-ai-rules",
3
- "version": "0.8.3",
3
+ "version": "0.8.4",
4
4
  "type": "module",
5
5
  "workbase": {
6
6
  "id": "ai-rules",
@@ -41,7 +41,7 @@
41
41
  "typescript": "^5.8.3",
42
42
  "yaml": "^2.8.1",
43
43
  "lucide-react": "^1.21.0",
44
- "@eworkbase/sdk": "0.8.3"
44
+ "@eworkbase/sdk": "0.8.4"
45
45
  },
46
46
  "publishConfig": {
47
47
  "access": "public"