@runweave/server-darwin-arm64 0.1.2 → 0.1.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 (88) hide show
  1. package/manifest.json +161 -156
  2. package/native.tar.gz +0 -0
  3. package/package.json +1 -1
  4. package/payload/app-server/build-info.json +4 -4
  5. package/payload/app-server/index.cjs +290 -89
  6. package/payload/app-server/index.cjs.map +1 -1
  7. package/payload/backend/build-info.json +4 -4
  8. package/payload/backend/dev-resources/control.cjs +197 -20
  9. package/payload/backend/evolution-sqlite-worker.cjs +58 -1
  10. package/payload/backend/index.cjs +3108 -2061
  11. package/payload/backend/scheduled-tasks-sqlite-worker.cjs +11 -7
  12. package/payload/frontend/dist/assets/{_baseUniq-B6OtH5JH.js → _baseUniq-2DZJ97aQ.js} +1 -1
  13. package/payload/frontend/dist/assets/{access-CpH3nCnI.js → access-Jw5gZrYY.js} +1 -1
  14. package/payload/frontend/dist/assets/{advanced-U5MqNTD5.js → advanced-DRe-Doxo.js} +1 -1
  15. package/payload/frontend/dist/assets/{appearance-Cb8XjaOT.js → appearance-D1wpkdXT.js} +1 -1
  16. package/payload/frontend/dist/assets/{arc-CEnFQNMK.js → arc-keTQ5uhA.js} +1 -1
  17. package/payload/frontend/dist/assets/{architectureDiagram-Q4EWVU46-T438RyEG.js → architectureDiagram-Q4EWVU46-BXbCJ77m.js} +1 -1
  18. package/payload/frontend/dist/assets/{blockDiagram-DXYQGD6D-B6Mqb9og.js → blockDiagram-DXYQGD6D-De0Ki8tO.js} +1 -1
  19. package/payload/frontend/dist/assets/{c4Diagram-AHTNJAMY-CO3eA3hw.js → c4Diagram-AHTNJAMY-EfazoSVi.js} +1 -1
  20. package/payload/frontend/dist/assets/channel-CExZE0tD.js +1 -0
  21. package/payload/frontend/dist/assets/{chunk-4BX2VUAB-1vjsV_mH.js → chunk-4BX2VUAB-BXCGPL07.js} +1 -1
  22. package/payload/frontend/dist/assets/{chunk-4TB4RGXK-CtMNFDLV.js → chunk-4TB4RGXK-ByjQ1_yc.js} +1 -1
  23. package/payload/frontend/dist/assets/{chunk-55IACEB6-DVWWqMjZ.js → chunk-55IACEB6-D-KjMbGJ.js} +1 -1
  24. package/payload/frontend/dist/assets/{chunk-EDXVE4YY-BBf3C6eJ.js → chunk-EDXVE4YY-tAgLMZ4w.js} +1 -1
  25. package/payload/frontend/dist/assets/{chunk-FMBD7UC4-BUQfXSvf.js → chunk-FMBD7UC4-D3J3ERtV.js} +1 -1
  26. package/payload/frontend/dist/assets/{chunk-OYMX7WX6-DM1nFyON.js → chunk-OYMX7WX6-DZHtmvkW.js} +1 -1
  27. package/payload/frontend/dist/assets/{chunk-QZHKN3VN-Bz3CUNpU.js → chunk-QZHKN3VN-D6IIGd1d.js} +1 -1
  28. package/payload/frontend/dist/assets/{chunk-YZCP3GAM-Bb6CnKMv.js → chunk-YZCP3GAM-KD19-lMa.js} +1 -1
  29. package/payload/frontend/dist/assets/classDiagram-6PBFFD2Q-DNOAkizi.js +1 -0
  30. package/payload/frontend/dist/assets/classDiagram-v2-HSJHXN6E-DNOAkizi.js +1 -0
  31. package/payload/frontend/dist/assets/clone-CzOxlTa8.js +1 -0
  32. package/payload/frontend/dist/assets/connection-Cm6G1HOW.js +12 -0
  33. package/payload/frontend/dist/assets/{connections-1OP6Izpn.js → connections-B8tSRWt9.js} +1 -1
  34. package/payload/frontend/dist/assets/{cose-bilkent-S5V4N54A-DvX1W1oQ.js → cose-bilkent-S5V4N54A-AYXbL8jP.js} +1 -1
  35. package/payload/frontend/dist/assets/{dagre-KV5264BT-BYV7l80W.js → dagre-KV5264BT-DCunJ-sG.js} +1 -1
  36. package/payload/frontend/dist/assets/{desktop-DKYPd_Z3.js → desktop-DnY652OH.js} +1 -1
  37. package/payload/frontend/dist/assets/{diagram-5BDNPKRD-BU_VxMcA.js → diagram-5BDNPKRD-Ch2b63ll.js} +1 -1
  38. package/payload/frontend/dist/assets/{diagram-G4DWMVQ6-6jnkLcPr.js → diagram-G4DWMVQ6-BAuc_Uar.js} +1 -1
  39. package/payload/frontend/dist/assets/{diagram-MMDJMWI5-DAjbbS4T.js → diagram-MMDJMWI5-DH8qMuDA.js} +1 -1
  40. package/payload/frontend/dist/assets/{diagram-TYMM5635-p2T86-Pr.js → diagram-TYMM5635-BflD7Kjb.js} +1 -1
  41. package/payload/frontend/dist/assets/{erDiagram-SMLLAGMA-DcZPoxkO.js → erDiagram-SMLLAGMA-BGzvzTP9.js} +1 -1
  42. package/payload/frontend/dist/assets/{flowDiagram-DWJPFMVM-CDB-5IUB.js → flowDiagram-DWJPFMVM-BR4mXArp.js} +1 -1
  43. package/payload/frontend/dist/assets/{ganttDiagram-T4ZO3ILL-imCnxO5S.js → ganttDiagram-T4ZO3ILL-uXtJoz5O.js} +1 -1
  44. package/payload/frontend/dist/assets/{gitGraphDiagram-UUTBAWPF-DW7bWVfm.js → gitGraphDiagram-UUTBAWPF-BeLB68OO.js} +1 -1
  45. package/payload/frontend/dist/assets/{graph-rPoUAwm2.js → graph-DakNuFNs.js} +1 -1
  46. package/payload/frontend/dist/assets/{image-pt4OUNUX.js → image-BICNaNq8.js} +1 -1
  47. package/payload/frontend/dist/assets/{index-CpU0rt1e.js → index-Cf9Vl4GJ.js} +92 -89
  48. package/payload/frontend/dist/assets/{infoDiagram-42DDH7IO-C6DYDEhQ.js → infoDiagram-42DDH7IO-CAGn0b04.js} +1 -1
  49. package/payload/frontend/dist/assets/{ishikawaDiagram-UXIWVN3A-o3dlbDPW.js → ishikawaDiagram-UXIWVN3A-fbaDUCpd.js} +1 -1
  50. package/payload/frontend/dist/assets/{journeyDiagram-VCZTEJTY-ukG3M2cI.js → journeyDiagram-VCZTEJTY-ZOmjleqG.js} +1 -1
  51. package/payload/frontend/dist/assets/{kanban-definition-6JOO6SKY-CzFLztFd.js → kanban-definition-6JOO6SKY-BmODq4tv.js} +1 -1
  52. package/payload/frontend/dist/assets/{layout-C8SEMYSj.js → layout-CLfuo3Vs.js} +1 -1
  53. package/payload/frontend/dist/assets/{linear-DY8vPita.js → linear-csTsZ7Al.js} +1 -1
  54. package/payload/frontend/dist/assets/main-DtzgJZEf.css +33 -0
  55. package/payload/frontend/dist/assets/{main-B_ifx48h.js → main-DwDuhfcr.js} +154 -151
  56. package/payload/frontend/dist/assets/{min-9StlgeN8.js → min-B4B7Rr4j.js} +1 -1
  57. package/payload/frontend/dist/assets/{mindmap-definition-QFDTVHPH-CyJisFtS.js → mindmap-definition-QFDTVHPH-CiV2UasH.js} +1 -1
  58. package/payload/frontend/dist/assets/{monitoring-Bjm0etKL.js → monitoring-1_Fnxura.js} +1 -1
  59. package/payload/frontend/dist/assets/{notifications-DhRLCgMU.js → notifications-VJaMbzoX.js} +1 -1
  60. package/payload/frontend/dist/assets/{pieDiagram-DEJITSTG-DHSht7rk.js → pieDiagram-DEJITSTG-DwazVxKI.js} +1 -1
  61. package/payload/frontend/dist/assets/{quadrantDiagram-34T5L4WZ-92xIujrE.js → quadrantDiagram-34T5L4WZ-CAn9HHbO.js} +1 -1
  62. package/payload/frontend/dist/assets/{record-content-Cy_dPSdi.js → record-content-Bewq09_f.js} +1 -1
  63. package/payload/frontend/dist/assets/{requirementDiagram-MS252O5E-CXuOqrNd.js → requirementDiagram-MS252O5E-CFot9peV.js} +1 -1
  64. package/payload/frontend/dist/assets/{sankeyDiagram-XADWPNL6-DR-mjY0Y.js → sankeyDiagram-XADWPNL6-CdRX6WuA.js} +1 -1
  65. package/payload/frontend/dist/assets/{sequenceDiagram-FGHM5R23-DmmUpAoP.js → sequenceDiagram-FGHM5R23-vRc1a5W1.js} +1 -1
  66. package/payload/frontend/dist/assets/{stateDiagram-FHFEXIEX-CKoqQ0-j.js → stateDiagram-FHFEXIEX-Bxcr7s70.js} +1 -1
  67. package/payload/frontend/dist/assets/stateDiagram-v2-QKLJ7IA2-YGvbZNwL.js +1 -0
  68. package/payload/frontend/dist/assets/{status-B__OyRqS.js → status-9tZZeoV7.js} +1 -1
  69. package/payload/frontend/dist/assets/suiji-DX2ioZ0I.js +1 -0
  70. package/payload/frontend/dist/assets/{svg-BpvEgtI3.js → svg-qpyWsADE.js} +1 -1
  71. package/payload/frontend/dist/assets/{tabs-BjCNEXFA.js → tabs-CwPtRQY0.js} +1 -1
  72. package/payload/frontend/dist/assets/{timeline-definition-GMOUNBTQ-CHT2sQNz.js → timeline-definition-GMOUNBTQ-2mD2ePS6.js} +1 -1
  73. package/payload/frontend/dist/assets/{vennDiagram-DHZGUBPP-Bvnh5q4I.js → vennDiagram-DHZGUBPP-w4DbLykx.js} +1 -1
  74. package/payload/frontend/dist/assets/{wardley-RL74JXVD-DeQXKB6h.js → wardley-RL74JXVD-C3H8SQaZ.js} +1 -1
  75. package/payload/frontend/dist/assets/{wardleyDiagram-NUSXRM2D-jWo5oC0L.js → wardleyDiagram-NUSXRM2D-DEI0kC2c.js} +1 -1
  76. package/payload/frontend/dist/assets/{xychartDiagram-5P7HB3ND-Btji0cq9.js → xychartDiagram-5P7HB3ND-DDVlpQ28.js} +1 -1
  77. package/payload/frontend/dist/build-info.json +4 -4
  78. package/payload/frontend/dist/companion.html +1 -1
  79. package/payload/frontend/dist/index.html +3 -3
  80. package/payload/server/index.cjs +205 -19
  81. package/payload/frontend/dist/assets/channel-D7VgadXd.js +0 -1
  82. package/payload/frontend/dist/assets/classDiagram-6PBFFD2Q-DHRHkXVC.js +0 -1
  83. package/payload/frontend/dist/assets/classDiagram-v2-HSJHXN6E-DHRHkXVC.js +0 -1
  84. package/payload/frontend/dist/assets/clone-BzLTnNJj.js +0 -1
  85. package/payload/frontend/dist/assets/connection-ChK196PA.js +0 -12
  86. package/payload/frontend/dist/assets/main-C-ZLrzMh.css +0 -33
  87. package/payload/frontend/dist/assets/stateDiagram-v2-QKLJ7IA2-BfZc0BCX.js +0 -1
  88. package/payload/frontend/dist/assets/suiji-nz2Jwmpc.js +0 -1
@@ -0,0 +1,12 @@
1
+ var _e=Object.defineProperty;var Ge=(a,t,s)=>t in a?_e(a,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):a[t]=s;var B=(a,t,s)=>Ge(a,typeof t!="symbol"?t+"":t,s);import{r as x,j as e,u as A}from"./index-D9-cSGu-.js";import{s as Be,B as u,I as K,t as ee,v as Qe,w as Ze,x as Xe,y as Ye,E as et,P as tt,N as st,G as it,J as at,K as rt,h as nt,r as ot,O as lt,X as ct,Q as ke}from"./main-DwDuhfcr.js";import{S as Fe,r as pe,R as Ce,a as Me}from"./record-content-Bewq09_f.js";/**
2
+ * @license lucide-react v0.484.0 - ISC
3
+ *
4
+ * This source code is licensed under the ISC license.
5
+ * See the LICENSE file in the root directory of this source tree.
6
+ */const dt=[["path",{d:"M12 12h.01",key:"1mp3jc"}],["path",{d:"M16 6V4a2 2 0 0 0-2-2h-4a2 2 0 0 0-2 2v2",key:"1ksdt3"}],["path",{d:"M22 13a18.15 18.15 0 0 1-20 0",key:"12hx5q"}],["rect",{width:"20",height:"14",x:"2",y:"6",rx:"2",key:"i6l2r4"}]],ut=Be("briefcase-business",dt);/**
7
+ * @license lucide-react v0.484.0 - ISC
8
+ *
9
+ * This source code is licensed under the ISC license.
10
+ * See the LICENSE file in the root directory of this source tree.
11
+ */const ht=[["path",{d:"m3 17 2 2 4-4",key:"1jhpwq"}],["path",{d:"m3 7 2 2 4-4",key:"1obspn"}],["path",{d:"M13 6h8",key:"15sg57"}],["path",{d:"M13 12h8",key:"h98zly"}],["path",{d:"M13 18h8",key:"oe0vm4"}]],pt=Be("list-checks",ht);function ft({report:a,onOpen:t}){const s=a.days.filter(i=>i.coverage!=="complete");return e.jsxs("button",{type:"button",onClick:t,className:"rounded-2xl border border-emerald-600/40 bg-emerald-50/40 p-4 text-left dark:bg-emerald-950/20",children:[e.jsxs("p",{className:"mb-2 text-xs font-medium text-emerald-700 dark:text-emerald-400",children:["周报 · ",a.from," — ",a.to]}),e.jsx("h3",{className:"mb-2 font-semibold",children:a.title}),e.jsx("p",{className:"line-clamp-2 whitespace-pre-wrap text-sm leading-7",children:a.body.replace(/[#*]/g,"")}),e.jsxs("p",{className:"mt-3 text-xs text-muted-foreground",children:[s.length?`${s.length} 天来源尚未齐全 · `:"","查看完整周报 →"]})]})}function xt({original:a,model:t,writable:s,onClose:i,onLogs:r}){const[n,d]=x.useState(a),[l,c]=x.useState(),[f,p]=x.useState(!1),[m,o]=x.useState(!1),[v,k]=x.useState(""),E="work:report:"+a.id;x.useEffect(()=>{let j=!0;return Promise.all([t.client.request("/api/suiji/v1/work-reports/"+a.id),t.store.get(E)]).then(([w,C])=>{j&&t.client.active&&(d(w.report),c(C))},w=>{j&&k(String(w))}),()=>{j=!1}},[a.id,t,E]);const g=async j=>{t.client.active&&c(j),await t.persistReportDraft(E,j)},b=async()=>{try{l||await g({title:n.title,body:n.body,version:n.version}),p(!0)}catch(j){k(String(j))}},S=async()=>{if(!l||m||!s)return;o(!0),k("");let j=l;try{if(!j.pending){if(!j.title.trim()||[...j.title.trim()].length>80||!j.body.trim()||[...j.body].length>2e4)throw new Error("标题1–80字,正文1–20000字");j={...j,pending:{path:"/api/suiji/v1/work-reports/"+n.id,method:"PATCH",key:crypto.randomUUID(),data:{title:j.title.trim(),body:j.body,expectedVersion:j.version}}},await g(j)}const w=j.pending,C=await t.client.request(w.path,w.method,w.data,w.key),R=w.data;if(C.report.id!==n.id||C.report.body!==R.body||C.report.title!==R.title||C.report.version!==R.expectedVersion+1)throw new Error("保存回执不匹配,请手动确认原请求");await t.clearReportDraft(E),t.client.active&&(d(C.report),c(void 0),p(!1),await t.load())}catch(w){w instanceof ee&&!w.uncertain&&await g({...j,pending:void 0}),t.client.active&&k(String(w))}finally{t.client.active&&o(!1)}};return e.jsxs("section",{className:"flex min-h-0 flex-1 flex-col","aria-label":"周报详情",children:[e.jsxs("header",{className:"flex items-center justify-between border-b p-4",children:[e.jsx(u,{variant:"ghost",disabled:m,onClick:i,children:"返回工作"}),e.jsx("span",{children:"周报"}),e.jsx(u,{variant:"ghost",disabled:m||!s,onClick:()=>void(f?S():b()),children:f?l!=null&&l.pending?"手动确认原请求":"保存":"编辑周报"})]}),e.jsxs("div",{className:"flex-1 space-y-4 overflow-y-auto p-5",children:[v&&e.jsx("p",{role:"alert",className:"text-sm text-destructive",children:v}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[n.from," — ",n.to," · 七个自然日"]}),n.needsReview?e.jsx("p",{className:"text-sm text-amber-600",children:"来源含历史浏览内容,此周报待人工复核。"}):null,e.jsxs("p",{className:"text-xs text-muted-foreground",children:["根据 ",n.sourceFacts.length," 条工作事实整理",n.manuallyEdited?" · 已人工编辑":""]}),n.days.some(j=>j.coverage!=="complete")&&e.jsxs("p",{className:"rounded-xl bg-amber-50 p-3 text-sm text-amber-900",children:["来源未齐:",n.days.filter(j=>j.coverage!=="complete").map(j=>j.date).join("、"),"。未上报不代表没有工作。"]}),f&&l?e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"block text-sm",children:["周报标题",e.jsx(K,{"aria-label":"周报标题",value:l.title,disabled:m||!!l.pending,onChange:j=>void g({...l,title:j.target.value}).catch(w=>k(String(w)))})]}),e.jsxs("label",{className:"block text-sm",children:["周报正文",e.jsx("textarea",{"aria-label":"周报正文",className:"min-h-80 w-full rounded-xl border bg-background p-3",value:l.body,disabled:m||!!l.pending,onChange:j=>void g({...l,body:j.target.value}).catch(w=>k(String(w)))})]}),l.pending?e.jsx("p",{children:"保存结果待确认,返回或重启不会自动发送。"}):e.jsx(u,{variant:"outline",onClick:()=>{t.client.request("/api/suiji/v1/work-reports/"+n.id).then(async j=>{d(j.report),await g({...l,version:j.report.version}),k("已更新版本,保留草稿,请核对后保存。")},j=>k(String(j)))},children:"读取最新版本并保留草稿"})]}):e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"text-xl font-semibold",children:n.title}),e.jsx("div",{className:"whitespace-pre-wrap break-words leading-8",children:n.body})]})]}),e.jsx("footer",{className:"border-t p-4",children:e.jsx(u,{variant:"outline",disabled:m,onClick:r,children:"查看原始日志"})})]})}const Ne={progress:"有进展",discussed:"讨论",documented:"已记录",attempted:"尝试","agent-reported":"Agent 反馈",verified:"已验证"},Ue=()=>new Intl.DateTimeFormat("en-CA",{timeZone:"Asia/Shanghai",year:"numeric",month:"2-digit",day:"2-digit"}).format(new Date),ne="/api/suiji/v1/work-facts",H=a=>a instanceof Error?a.message:"操作失败";class mt{constructor(t,s,i=!1){B(this,"state",{items:[],reports:[],view:"all",days:[],cursor:null,from:"",to:"",loading:!1,busy:!1,error:""});B(this,"listeners",new Set);B(this,"generation",0);B(this,"alive",!0);B(this,"writable",!1);B(this,"read");B(this,"writes",Promise.resolve());B(this,"subscribe",t=>(this.listeners.add(t),()=>{this.listeners.delete(t)}));B(this,"snapshot",()=>this.state);this.client=t,this.store=s,this.reportsSupported=i}set(t){this.alive&&this.client.active&&(this.state={...this.state,...t},this.listeners.forEach(s=>s()))}persist(t,s){const i=structuredClone(s),r=this.writes.catch(()=>{}).then(()=>this.store.set(t,i));return this.writes=r,r}dispose(){var t;this.alive=!1,++this.generation,(t=this.read)==null||t.abort()}async settled(){await this.writes.catch(()=>{})}async initialize(){this.alive=!0;try{const[t,s,i]=await Promise.all([this.store.get("work:dates"),this.store.get("work:reclassify:active"),this.store.get("work:reclassify:undo")]),r=s?await this.store.get("work:reclassify:"+s):void 0;this.set({...t??{},batch:r,undo:i}),await this.load()}catch(t){this.set({error:H(t)})}}async load(t=!1,s=!0){var f;if(t&&(!this.state.cursor||this.state.loading))return;(f=this.read)==null||f.abort(),this.read=new AbortController;const i=++this.generation,{from:r,to:n,cursor:d,view:l}=this.state;this.set({loading:!0,error:"",...t?{}:{items:[],reports:[],days:[],cursor:null}});const c=new URLSearchParams({...this.reportsSupported?{view:l}:{},...r?{from:r}:{},...n?{to:n}:{},...t&&d?{cursor:d}:{}});try{const p=await this.client.request(ne+"?"+c,"GET",void 0,void 0,this.read.signal);if(!this.alive||i!==this.generation)return;const m=t?Object.values(Object.fromEntries([...this.state.days,...p.days].map(o=>[o.date,o]))):p.days;this.set({items:t?[...this.state.items,...p.items]:p.items,reports:t?[...this.state.reports,...p.reports??[]]:p.reports??[],days:m,cursor:p.nextCursor})}catch(p){if(!this.alive||i!==this.generation)return;if(p instanceof ee&&p.detail.error.code==="WORK_FEED_CHANGED"&&s){await this.load(!1,!1);return}this.set({error:H(p)})}finally{i===this.generation&&this.set({loading:!1})}}persistReportDraft(t,s){return this.persist(t,s)}async clearReportDraft(t){await this.writes,await this.store.remove(t)}async show(t,s=this.state.from,i=this.state.to){this.set({view:t}),await this.dates(s,i)}async dates(t,s){if(t&&s&&t>s){this.set({error:"开始日期不能晚于结束日期"});return}await this.persist("work:dates",{from:t,to:s}),this.set({from:t,to:s}),await this.load()}async detail(t){try{const s=await this.client.request(ne+"/"+t);this.set({detail:s.fact})}catch(s){this.set({error:H(s)})}}closeDetail(){this.set({detail:void 0})}async edit(t){try{await this.writes;const s=(t==null?void 0:t.id)??"new",i=s==="new"?"work:new":"work:edit:"+s,r=await this.store.get(i)??{id:s,fields:t?{workDate:t.workDate,title:t.title,statement:t.statement,status:t.status,project:t.project}:{workDate:Ue(),title:"",statement:"",status:"progress",project:null},...t?{base:t}:{}};await this.persist(i,r),this.set({draft:r,error:""})}catch(s){this.set({error:H(s)})}}update(t){const s=this.state.draft;if(!this.writable||!s||s.pending||this.state.busy)return;const i={...s,fields:{...s.fields,...t}};this.set({draft:i}),this.persist(i.id==="new"?"work:new":"work:edit:"+i.id,i).catch(r=>this.set({error:H(r)}))}closeEditor(){this.state.busy||this.set({draft:void 0})}async discardEditor(){const t=this.state.draft;if(!(!t||t.pending||this.state.busy))try{await this.writes,await this.store.remove(t.id==="new"?"work:new":"work:edit:"+t.id),this.set({draft:void 0})}catch(s){this.set({error:H(s)})}}async refreshVersion(){const t=this.state.draft;if(!(!(t!=null&&t.base)||t.pending||this.state.busy))try{const{fact:s}=await this.client.request(ne+"/"+t.id),i={...t,base:s};await this.persist("work:edit:"+t.id,i),this.set({draft:i,detail:s,error:"已读取当前版本,下方保留你的草稿;请核对最新事实后再保存。"})}catch(s){this.set({error:H(s)})}}async save(){var i,r;let t=this.state.draft;if(!this.writable||!t||this.state.busy)return;this.set({busy:!0,error:""});const s=t.id==="new"?"work:new":"work:edit:"+t.id;try{if(await this.writes,!t.pending){const l=t.fields;if(!l.title.trim()||!l.statement.trim()||[...l.title.trim()].length>80||[...l.statement].length>4e3||[...((i=l.project)==null?void 0:i.trim())??""].length>80||!/^\d{4}-\d\d-\d\d$/.test(l.workDate))throw new Error("请填写有效工作日期、1–80字标题及1–4000字正文;项目最多80字");const c={...l,title:l.title.trim(),project:((r=l.project)==null?void 0:r.trim())||null},f=t.base?{expectedVersion:t.base.version,...Object.fromEntries(Object.entries(c).filter(([p,m])=>m!==t.base[p]))}:c;if(t.base&&Object.keys(f).length===1){this.set({draft:void 0});return}t={...t,pending:{key:crypto.randomUUID(),method:t.base?"PATCH":"POST",path:ne+(t.base?"/"+t.id:""),data:f}},await this.persist(s,t),this.set({draft:t})}const n=t.pending,{fact:d}=await this.client.request(n.path,n.method,n.data,n.key);if(!(d!=null&&d.id)||t.base&&d.id!==t.id||Object.entries(n.data).some(([l,c])=>l!=="expectedVersion"&&d[l]!==c))throw new Error("保存回执不匹配,请手动确认原请求");await this.store.remove(s),this.set({draft:void 0,detail:d}),await this.dates(d.workDate,d.workDate)}catch(n){n instanceof ee&&!n.uncertain&&t.pending&&(t={...t,pending:void 0},await this.persist(s,t),this.set({draft:t})),this.set({error:H(n)})}finally{this.set({busy:!1})}}async beginBatch(t,s=!1){if(!(this.state.batch||this.state.busy))try{const i={id:crypto.randomUUID(),rows:t,project:"",...s?{undo:s}:{}};await this.persist("work:reclassify:"+i.id,i),await this.persist("work:reclassify:active",i.id),this.set({batch:i,error:""})}catch(i){this.set({error:H(i)})}}updateBatch(t,s){const i=this.state.batch;if(!i||i.pending||this.state.busy)return;const r={...i,rows:t,project:s};this.set({batch:r}),this.persist("work:reclassify:"+i.id,r).catch(n=>this.set({error:H(n)}))}async refreshBatch(){const t=this.state.batch;if(!(!this.writable||!t||t.undo||t.pending||this.state.busy))try{const s=await Promise.all(t.rows.map(async r=>(await this.client.request(ne+"/"+r.id)).fact)),i={...t,rows:s};await this.persist("work:reclassify:"+t.id,i),this.set({batch:i,error:"已读取所选事实的最新版本,请核对后再确认归类。"})}catch(s){this.set({error:H(s)})}}async cancelBatch(){const t=this.state.batch;if(!(!t||t.pending||this.state.busy))try{await this.writes,await this.store.remove("work:reclassify:"+t.id),await this.store.remove("work:reclassify:active"),this.set({batch:void 0})}catch(s){this.set({error:H(s)})}}async undo(){this.state.undo&&!this.state.batch&&await this.beginBatch([],!0)}async commitBatch(){let t=this.state.batch;if(!this.writable||!t||this.state.busy)return;this.set({busy:!0,error:""});const s="work:reclassify:"+t.id;try{if(await this.writes,!t.pending){if(!t.undo&&(t.rows.length<1||t.rows.length>100))throw new Error("请选择1–100条已加载记录");const c=t.undo?this.state.undo:{items:t.rows.map(f=>({id:f.id,expectedVersion:f.version})),project:t.project.trim()||null};if(!c)throw new Error("没有可撤销的项目调整");t={...t,pending:{path:ne+(t.undo?"/reclassify/undo":"/reclassify"),method:"POST",data:c,key:crypto.randomUUID()}},await this.persist(s,t),this.set({batch:t})}const i=t.pending,{facts:r}=await this.client.request(i.path,i.method,i.data,i.key),n=i.data;if(!Array.isArray(r)||r.length!==n.items.length||n.items.some(c=>!r.some(f=>f.id===c.id&&f.version===c.expectedVersion+1&&f.project===("project"in c?c.project:n.project))))throw new Error("归类回执不匹配,请手动确认原请求");const d=t.undo?void 0:{items:r.map(c=>({id:c.id,expectedVersion:c.version,project:t.rows.find(f=>f.id===c.id).project}))};d?await this.persist("work:reclassify:undo",d):await this.store.remove("work:reclassify:undo"),await this.store.remove(s),await this.store.remove("work:reclassify:active");const l=r.find(c=>{var f;return c.id===((f=this.state.detail)==null?void 0:f.id)})??this.state.detail;this.set({batch:void 0,undo:d,detail:l}),await this.load()}catch(i){i instanceof ee&&!i.uncertain&&t.pending&&(t={...t,pending:void 0},await this.persist(s,t),this.set({batch:t})),this.set({error:H(i)})}finally{this.set({busy:!1})}}}function gt({model:a,writable:t}){const{draft:s,busy:i,error:r,detail:n}=a.state;if(!s)return null;const d=!t||i||!!s.pending,l=(c,f)=>a.update({[c]:f});return e.jsxs("section",{className:"flex min-h-0 flex-1 flex-col","aria-label":"工作事实编辑",children:[e.jsxs("header",{className:"flex items-center justify-between border-b p-4",children:[e.jsx(u,{variant:"ghost",disabled:i,onClick:()=>a.closeEditor(),children:"返回"}),e.jsx("h2",{children:s.base?"编辑事实":"补记事实"}),e.jsx(u,{disabled:i||!t,onClick:()=>void a.save(),children:i?"保存中…":s.pending?"手动确认原请求":"保存"})]}),e.jsxs("div",{className:"flex flex-1 flex-col gap-5 overflow-y-auto p-5",children:[r?e.jsx("p",{role:"alert",className:"text-sm text-destructive",children:r}):null,s.pending?e.jsx("p",{role:"status",className:"text-sm",children:"保存结果待确认。原请求已保存在本机,返回或重启不会自动发送。"}):null,e.jsxs("label",{className:"space-y-2 text-sm",children:["工作日期",e.jsx(K,{type:"date","aria-label":"工作日期",disabled:d,value:s.fields.workDate,onChange:c=>l("workDate",c.target.value)})]}),e.jsxs("label",{className:"space-y-2 text-sm",children:["标题",e.jsx(K,{"aria-label":"事实标题",disabled:d,value:s.fields.title,onChange:c=>l("title",c.target.value)})]}),e.jsxs("label",{className:"space-y-2 text-sm",children:["事实正文",e.jsx("textarea",{"aria-label":"事实正文",disabled:d,className:"min-h-48 w-full rounded-xl border bg-background p-3",value:s.fields.statement,onChange:c=>l("statement",c.target.value)})]}),e.jsxs("label",{className:"space-y-2 text-sm",children:["实际状态",e.jsx("select",{"aria-label":"事实状态",disabled:d,className:"w-full rounded-xl border bg-background p-3",value:s.fields.status,onChange:c=>a.update({status:c.target.value}),children:Object.entries(Ne).map(([c,f])=>e.jsx("option",{value:c,children:f},c))})]}),e.jsxs("label",{className:"space-y-2 text-sm",children:["项目(可选)",e.jsx(K,{"aria-label":"事实项目",placeholder:"未归类",disabled:d,value:s.fields.project??"",onChange:c=>a.update({project:c.target.value||null})})]}),s.base&&!s.pending?e.jsxs(e.Fragment,{children:[e.jsx(u,{variant:"outline",disabled:i,onClick:()=>void a.refreshVersion(),children:"读取最新版本并保留草稿"}),(n==null?void 0:n.id)===s.id?e.jsxs("div",{className:"whitespace-pre-wrap rounded-xl bg-secondary p-3 text-sm",children:[e.jsxs("p",{children:["服务当前 v",n.version," · ",n.workDate," ·"," ",n.project??"未归类"]}),e.jsx("strong",{children:n.title}),e.jsx("p",{children:n.statement})]}):null]}):null,e.jsx(u,{variant:"ghost",disabled:d,onClick:()=>void a.discardEditor(),children:"丢弃未保存草稿"})]})]})}function vt({model:a,writable:t}){const{batch:s,items:i,busy:r,error:n,undo:d}=a.state;if(!s)return null;const l=!t||r||!!s.pending,c=new Set(s.rows.map(p=>p.id)),f=[...s.rows,...i.filter(p=>!c.has(p.id))];return e.jsxs("section",{className:"flex min-h-0 flex-1 flex-col","aria-label":"重新归类",children:[e.jsxs("header",{className:"flex items-center justify-between border-b p-4",children:[e.jsx("h2",{children:s.undo?"撤销本次归类":"重新归类"}),e.jsx(u,{variant:"ghost",disabled:l,onClick:()=>void a.cancelBatch(),children:"取消"})]}),e.jsxs("div",{className:"flex flex-1 flex-col gap-4 overflow-y-auto p-5",children:[n?e.jsx("p",{role:"alert",className:"text-sm text-destructive",children:n}):null,s.pending?e.jsx("p",{children:"操作结果待确认,原请求已保存在本机;不会自动重发。"}):null,s.undo?e.jsxs("p",{children:["按原成功回执的版本还原 ",(d==null?void 0:d.items.length)??0," ","条记录的项目;任何一条版本变化将整批停止。"]}):e.jsxs(e.Fragment,{children:[e.jsx(u,{variant:"ghost",disabled:l,onClick:()=>void a.refreshBatch(),children:"读取所选事实最新版本"}),e.jsxs("p",{className:"text-sm",children:["已选 ",s.rows.length," 条。仅修改项目,正文、日期和状态保持。"]}),e.jsx(u,{variant:"outline",disabled:l||i.length>100,onClick:()=>a.updateBatch([...new Map([...s.rows,...i].map(p=>[p.id,p])).values()],s.project),children:"全选已加载记录"}),a.state.cursor?e.jsx("p",{className:"text-sm text-muted-foreground",children:"还有未加载记录;返回列表加载后再选择。"}):null,e.jsxs("label",{className:"text-sm",children:["目标项目(留空为未归类)",e.jsx(K,{"aria-label":"目标项目",list:"work-projects",disabled:l,value:s.project,onChange:p=>a.updateBatch(s.rows,p.target.value)})]}),e.jsx("datalist",{id:"work-projects",children:[...new Set(i.map(p=>p.project).filter(p=>!!p))].map(p=>e.jsx("option",{value:p},p))}),e.jsx("div",{className:"flex flex-col gap-3",children:f.map(p=>e.jsxs("label",{className:"flex items-start gap-3 rounded-xl border p-3 text-sm",children:[e.jsx("input",{type:"checkbox","aria-label":`选择 ${p.title}`,disabled:l||!c.has(p.id)&&s.rows.length>=100,checked:c.has(p.id),onChange:m=>a.updateBatch(m.target.checked?[...s.rows,p]:s.rows.filter(o=>o.id!==p.id),s.project)}),e.jsxs("span",{children:[e.jsx("strong",{children:p.title}),e.jsx("br",{}),p.workDate," · ",p.project??"未归类",e.jsx("br",{}),e.jsx("small",{children:p.id})]})]},p.id))})]})]}),e.jsx("div",{className:"shrink-0 border-t bg-background p-4",children:e.jsx(u,{className:"h-auto min-h-10 w-full whitespace-normal break-words",disabled:!t||r||!s.undo&&!s.rows.length,onClick:()=>void a.commitBatch(),children:r?"保存中…":s.pending?"手动确认原请求":s.undo?"确认撤销项目调整":`确认 ${s.rows.length} 条 → ${s.project.trim()||"未归类"}`})})]})}function bt({model:a,active:t,writable:s,onReview:i}){const r=x.useSyncExternalStore(a.subscribe,a.snapshot),[n,d]=x.useState(!1),[l,c]=x.useState(""),[f,p]=x.useState(""),[m,o]=x.useState(!1);x.useEffect(()=>{a.writable=s},[a,s]),x.useEffect(()=>{t&&a.load()},[t,a]);const{detail:v,draft:k,batch:E}=r,[g,b]=x.useState();if(g)return e.jsx(xt,{original:g,model:a,writable:s,onClose:()=>b(void 0),onLogs:()=>{b(void 0),a.show("logs",g.from,g.to)}});const S=w=>{const C=Math.round((Date.parse(Ue()+"T00:00:00Z")-Date.parse(w+"T00:00:00Z"))/864e5);return`${C===0?"今天 · ":C===1?"昨天 · ":C===2?"前天 · ":""}${w}`},j=()=>{if(r.view==="reports")return"这个日期范围尚无周报";const w=r.from&&r.to?Math.floor((Date.parse(r.to)-Date.parse(r.from))/864e5)+1:0;return w>0&&r.days.length===w&&r.days.every(C=>C.coverage==="complete"&&C.count===0)?"已导入范围内没有记录":r.days.some(C=>C.coverage==="partial")?"记录尚未完整导入":"这个日期范围尚未导入工作记录"};return e.jsxs("div",{className:"relative flex min-h-0 flex-1 flex-col",children:[e.jsxs("div",{className:k||E||v?"hidden":"flex min-h-0 flex-1 flex-col",children:[e.jsxs("header",{className:"flex shrink-0 items-center justify-between px-5 py-3",children:[e.jsx("h1",{className:"text-lg font-semibold",children:"工作"}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx(u,{variant:"ghost",size:"sm",onClick:()=>{c(r.from),p(r.to),d(w=>!w)},children:"日期"}),e.jsx(u,{variant:"ghost",size:"sm","aria-label":"工作更多",onClick:()=>o(w=>!w),children:"更多"})]})]}),a.reportsSupported&&e.jsx("div",{className:"flex gap-2 px-5 pb-3","aria-label":"工作类型",children:[["all","全部"],["logs","日志"],["reports","总结"]].map(([w,C])=>e.jsx(u,{size:"sm",variant:r.view===w?"secondary":"ghost",onClick:()=>void a.show(w),children:C},w))}),m?e.jsxs("div",{className:"flex flex-wrap gap-2 border-y px-5 py-2",children:[e.jsx(u,{variant:"ghost",size:"sm",disabled:r.loading,onClick:()=>{o(!1),a.load()},children:"刷新工作"}),e.jsx(u,{variant:"ghost",size:"sm",onClick:()=>{o(!1),i()},children:"AI 回顾"}),e.jsx(u,{variant:"ghost",size:"sm",disabled:!s,onClick:()=>{o(!1),a.beginBatch([])},children:"重新归类"}),r.undo?e.jsx(u,{variant:"ghost",size:"sm",disabled:!s,onClick:()=>{o(!1),a.undo()},children:"撤销上次归类"}):null]}):null,n?e.jsxs("form",{className:"flex flex-col gap-3 border-y p-5",onSubmit:w=>{w.preventDefault(),(!l||!f||l<=f)&&(d(!1),a.dates(l,f))},children:[e.jsxs("label",{className:"text-sm",children:["开始日期",e.jsx(K,{type:"date","aria-label":"开始日期",value:l,onChange:w=>c(w.target.value)})]}),e.jsxs("label",{className:"text-sm",children:["结束日期",e.jsx(K,{type:"date","aria-label":"结束日期",value:f,onChange:w=>p(w.target.value)})]}),l&&f&&l>f?e.jsx("p",{role:"alert",className:"text-sm text-destructive",children:"开始日期不能晚于结束日期"}):null,e.jsxs("div",{className:"flex gap-2",children:[e.jsx(u,{type:"submit",disabled:!!(l&&f&&l>f),children:"应用日期"}),e.jsx(u,{type:"button",variant:"outline",onClick:()=>{d(!1),a.dates("","")},children:"清空日期"}),e.jsx(u,{type:"button",variant:"ghost",onClick:()=>d(!1),children:"取消"})]})]}):null,r.from||r.to?e.jsxs("p",{className:"px-5 pb-2 text-sm text-muted-foreground",children:[r.from||"最早"," 至 ",r.to||"最近"]}):null,e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto px-5 pb-24","aria-label":"工作事实列表",children:[r.error?e.jsx("p",{role:"alert",className:"py-3 text-sm text-destructive",children:r.error}):null,[...new Set([...r.items.map(w=>w.workDate),...r.reports.map(w=>w.to)])].sort().reverse().map(w=>{var C;return e.jsxs("section",{className:"pb-5",children:[e.jsxs("h2",{className:"mb-3 text-sm font-medium text-muted-foreground",children:[S(w)," ",e.jsxs("span",{children:["· ",((C=r.days.find(R=>R.date===w))==null?void 0:C.count)??"…"," 条"]})]}),e.jsxs("div",{className:"flex flex-col gap-3",children:[r.reports.filter(R=>R.to===w).map(R=>e.jsx(ft,{report:R,onOpen:()=>b(R)},R.id)),r.items.filter(R=>R.workDate===w).map(R=>e.jsxs("button",{type:"button",onClick:()=>void a.detail(R.id),className:"rounded-2xl border bg-card p-4 text-left",children:[e.jsxs("p",{className:"mb-2 text-xs text-muted-foreground",children:[R.project??"未归类"," · ",Ne[R.status]]}),e.jsx("h3",{className:"mb-2 font-semibold",children:R.title}),e.jsx("p",{className:"whitespace-pre-wrap break-words text-sm leading-7",children:R.statement})]},R.id))]})]},w)}),!r.loading&&!r.items.length&&!r.reports.length?e.jsx("p",{className:"py-16 text-center text-muted-foreground",children:j()}):null,r.loading?e.jsx("p",{role:"status",className:"py-8 text-center",children:"正在读取工作事实…"}):null,r.cursor?e.jsx(u,{variant:"outline",className:"w-full",disabled:r.loading,onClick:()=>void a.load(!0),children:"加载更多工作记录"}):null]}),e.jsx(u,{"aria-label":"补记工作事实",className:"absolute bottom-5 right-5 size-12 rounded-full text-2xl shadow-lg",disabled:!s,onClick:()=>void a.edit(),children:"+"})]}),v&&!k&&!E?e.jsxs("section",{className:"flex min-h-0 flex-1 flex-col","aria-label":"工作事实详情",children:[e.jsxs("header",{className:"flex items-center justify-between border-b p-4",children:[e.jsx(u,{variant:"ghost",onClick:()=>a.closeDetail(),children:"返回工作"}),e.jsx(u,{variant:"ghost",disabled:!s,onClick:()=>void a.edit(v),children:"编辑事实"})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-5",children:[e.jsxs("p",{className:"mb-3 text-sm text-muted-foreground",children:[v.workDate," · ",v.project??"未归类"," ·"," ",Ne[v.status]]}),e.jsx("h2",{className:"mb-4 text-xl font-semibold",children:v.title}),e.jsx("p",{className:"mb-6 whitespace-pre-wrap break-words leading-8",children:v.statement}),e.jsx(u,{variant:"outline",disabled:!s,onClick:()=>void a.beginBatch([v]),children:"重新归类这条"})]})]}):null,k?e.jsx(gt,{model:a,writable:s}):E?e.jsx(vt,{model:a,writable:s}):null]})}const ue={bodyScalars:2e4,attachmentBytes:5*1024*1024,imagesPerRecord:1,markdownPerRecord:1,defaultPageSize:20,maxPageSize:100,tagsPerRecord:2,tagScalars:20};function Le(a){if(a.length>ue.tagsPerRecord)throw new Error("最多 2 个标签");const t=a.map(s=>s.trim());if(t.some(s=>!s||[...s].length>ue.tagScalars||/[\u0000-\u001f\u007f\uD800-\uDFFF]/u.test(s)))throw new Error("标签须为 1–20 个字符,不能包含控制字符或无效 Unicode");if(new Set(t).size!==t.length)throw new Error("标签不能重复");return t}function jt(a,t){var s,i;return(((s=a==null?void 0:a.latest)==null?void 0:s.sequence)??0)>(((i=t==null?void 0:t.latest)==null?void 0:i.sequence)??0)?a:t??a}function wt(a){return`使用随记 Skill 处理这条记录。先读取最新原文、全部跟进和相关附件,按我本次要求执行。完整结果、图片和文档在当前终端交付;随记只追加简短最终摘要,默认不上传图片、文档或附件,不记录过程或失败。后续问答、补图不自动回写。未经我确认,不标记完成。
12
+ `+JSON.stringify({format:"suiji-handoff-v1",...a},null,2)}class $e{constructor(t,s,i,r,n=!1){B(this,"listeners",new Set);B(this,"queue",Promise.resolve());B(this,"writes",0);B(this,"active",!0);B(this,"state");B(this,"correctionAbort");B(this,"correctionKey");B(this,"subscribe",t=>(this.listeners.add(t),()=>{this.listeners.delete(t)}));B(this,"snapshot",()=>this.state);this.client=s,this.store=i,this.followupRecordId=r,this.historySupported=n,this.state={draft:t,busy:!1,localSaving:!1,message:t.frozen?"保存结果待确认,请手动重试;输入暂时锁定":"",localError:!1,conflict:!1}}get storeKey(){return this.followupRecordId?"followup:"+this.followupRecordId:"draft:"+this.state.draft.id}dispose(){var t;this.active=!1,(t=this.correctionAbort)==null||t.abort(),this.listeners.clear()}settled(){return this.queue}initialize(){return this.loadFeedbackState(),this.persist()}async discard(){if(!(this.state.busy||this.state.draft.frozen)){this.patch({busy:!0});try{await this.queue,this.check(),await this.store.remove(this.storeKey),this.patch({discarded:!0})}catch(t){this.patch({message:t instanceof Error?t.message:"放弃草稿失败"})}finally{this.patch({busy:!1})}}}check(){if(!this.active||!this.client.active)throw new DOMException("编辑会话已结束","AbortError")}patch(t){this.state={...this.state,...t},this.listeners.forEach(s=>s())}persist(t=this.state.draft){const s=structuredClone(t);++this.writes,this.patch({localSaving:!0});const i=this.queue.then(()=>this.store.set(this.storeKey,s));return this.queue=i.catch(()=>{}),i.then(()=>this.patch({localError:!1})).catch(r=>{throw this.patch({message:r instanceof Error?r.message:"本机草稿未保存",localError:!0}),r}).finally(()=>{--this.writes,this.patch({localSaving:this.writes>0})})}edit(t){if(this.state.busy||this.state.draft.frozen)return;const s={...this.state.draft,...t};this.patch({draft:s,...t.body!==void 0&&t.body!==this.state.draft.body?{correction:void 0,correctionSource:void 0}:{}}),this.persist(s).catch(()=>{})}async loadLexicon(){try{const t=await this.store.get("lexicon-intent");this.check(),this.patch({lexiconPending:!!t});const s=await this.client.request("/api/suiji/v1/correction-lexicon");this.check(),this.patch({lexicon:s})}catch(t){this.active&&this.patch({correctionMessage:t instanceof Error?t.message:"词库读取失败"})}}async correct(){const t=this.state.draft.body;if(this.state.busy||this.state.draft.frozen||!t.trim()||this.state.correctionBusy)return;if(this.correctionKey&&this.state.correctionSource!==t){this.patch({correctionMessage:"原请求结果待确认;请先取消,再对新正文发起纠错"});return}const s=new AbortController;this.correctionAbort=s;const i=this.correctionKey??crypto.randomUUID();this.correctionKey=i,this.patch({correctionBusy:!0,correction:void 0,correctionSource:t,correctionMessage:"正在纠正文字…"});try{let r=await this.client.request("/api/suiji/v1/corrections","POST",{text:t,...this.historySupported&&!this.followupRecordId?{feedbackCapable:!0,...this.state.draft.id!=="new"?{recordId:this.state.draft.id}:{}}:{}},i,s.signal);for(this.check(),this.patch({correction:r});r.status==="running"&&!s.signal.aborted;)await new Promise(n=>setTimeout(n,1e3)),this.check(),r=await this.client.request("/api/suiji/v1/corrections/"+r.id,"GET",void 0,void 0,s.signal),this.patch({correction:r});if(this.check(),s.signal.aborted)return;this.correctionKey=void 0,this.patch({correction:r,correctionMessage:r.status==="completed"?"":r.error??"纠错未完成"})}catch(r){this.active&&!s.signal.aborted&&this.patch({correctionMessage:"纠错结果待确认;再次点击会沿用同一请求。"+(r instanceof Error?r.message:"")})}finally{this.correctionAbort===s&&(this.correctionAbort=void 0,this.patch({correctionBusy:!1}))}}async cancelCorrection(){var s,i;const t=(s=this.state.correction)==null?void 0:s.id;(i=this.correctionAbort)==null||i.abort(),t&&await this.client.request("/api/suiji/v1/corrections/"+t,"DELETE").catch(()=>{}),this.correctionKey=void 0,this.patch({correction:void 0,correctionSource:void 0,correctionBusy:!1,correctionMessage:""})}applyCorrection(){const{correction:t,correctionSource:s,draft:i}=this.state;if(!t||t.status!=="completed"||!t.correctedText||s!==i.body||i.frozen||this.state.busy||!this.active||!this.client.active){this.patch({correctionMessage:"正文或编辑会话已变化,请重新纠错"});return}const r={...i,body:t.correctedText,correctionTrace:t.historyId&&this.state.correctionSource?{correctionId:t.id,inputText:this.state.correctionSource,correctedText:t.correctedText,applied:!0}:void 0};this.patch({draft:r,correction:void 0,correctionSource:void 0}),this.persist(r).catch(()=>{}),this.patch({correctionMessage:"已应用到本机草稿;点击保存才会更新记录"})}async putLexicon(t){this.check();const s=this.state.lexicon;if(!s)throw new Error("请先读取词库");const r=await this.store.get("lexicon-intent")??{key:crypto.randomUUID(),data:{expectedVersion:s.version,entries:t}};await this.store.set("lexicon-intent",r),this.patch({lexiconPending:!0});try{const n=await this.client.request("/api/suiji/v1/correction-lexicon","PUT",r.data,r.key);this.check(),await this.store.remove("lexicon-intent"),this.patch({lexicon:n,lexiconPending:!1,correctionMessage:"已记住;可在词库中撤销"})}catch(n){throw n instanceof ee&&!n.uncertain&&(await this.store.remove("lexicon-intent"),this.patch({lexiconPending:!1})),this.patch({correctionMessage:n instanceof Error?n.message:"词库结果待确认,请手动重试"}),n}}async addFile(t){try{if(this.check(),t.size>ue.attachmentBytes)throw new Error("每个附件最多 5 MiB");const s=["image/jpeg","image/png"].includes(t.type);if(!s&&!/\.md$/i.test(t.name))throw new Error("仅支持 JPEG、PNG 和 Markdown");s||new TextDecoder("utf-8",{fatal:!0}).decode(await t.arrayBuffer()),this.check();const i=this.state.draft,r=s?"image":"markdown";if(i.existing.some(n=>n.kind===r)||i.files.some(n=>(n.file.type.startsWith("image/")?"image":"markdown")===r))throw new Error("每条最多一张图片和一个 Markdown,请先移除原附件");s||(t=new File([t],t.name,{type:"text/markdown",lastModified:t.lastModified})),this.edit({files:[...i.files,{id:crypto.randomUUID(),file:t,key:crypto.randomUUID()}]})}catch(s){this.patch({message:s instanceof Error?s.message:"附件读取失败"})}}async save(){var t,s;if(!(this.state.busy||this.state.saved||this.state.savedFollowup)){this.patch({busy:!0,message:""});try{this.check();let i=this.state.draft;if(!this.followupRecordId&&!i.pending&&i.tags!==void 0&&(i={...i,tags:Le(i.tags)},this.patch({draft:i})),[...i.body].length>ue.bodyScalars)throw new Error("正文最多 20,000 个字符");if(!i.body.trim()&&!i.existing.length&&!i.files.length)throw new Error("请输入正文或添加附件");if(await this.persist(i),this.check(),!i.pending){i={...i,frozen:!0},this.patch({draft:i}),await this.persist(i);for(const[d,l]of i.files.entries()){if(l.uploaded)continue;this.check();const c=new FormData;c.append("file",l.file,l.file.name);const f=await this.client.request("/api/suiji/v1/uploads","POST",c,l.key);this.check(),i={...i,files:i.files.map((p,m)=>m===d?{...p,uploaded:f.attachment}:p)},this.patch({draft:i}),await this.persist(i)}i={...i,pending:{path:this.followupRecordId?`/api/suiji/v1/records/${this.followupRecordId}/followups`:"/api/suiji/v1/records"+(i.id==="new"?"":"/"+i.id),method:this.followupRecordId||i.id==="new"?"POST":"PATCH",key:crypto.randomUUID(),data:{...this.followupRecordId?{}:{kind:i.kind,...i.id==="new"?{}:{expectedVersion:i.version}},body:i.body,...this.followupRecordId||i.tags===void 0?{}:{tags:i.tags},attachmentIds:[...i.existing.map(d=>d.id),...i.files.map(d=>d.uploaded.id)]}}},this.patch({draft:i}),await this.persist(i)}this.check();const r=i.pending,n=await this.client.request(r.path,r.method,r.data,r.key);if(this.check(),this.followupRecordId&&(!("followup"in n)||n.followup.recordId!==this.followupRecordId||n.followup.body!==i.body||JSON.stringify(n.followup.attachments.map(d=>d.id))!==JSON.stringify(i.files.map(d=>d.uploaded.id))||((t=n.followupSummary.latest)==null?void 0:t.sequence)!==n.followup.sequence))throw new Error("跟进响应与保存内容不一致,请手动重试确认");if("record"in n&&(n.record.body!==i.body||i.id!=="new"&&n.record.id!==i.id))throw new Error("记录响应与保存正文不一致,请手动重试确认");"record"in n&&((s=i.correctionTrace)!=null&&s.applied)&&(i.version===void 0||n.record.version>i.version)&&await this.enqueueFeedback({correctionId:i.correctionTrace.correctionId,key:crypto.randomUUID(),recordId:n.record.id,recordVersion:n.record.version,saveKey:r.key}).catch(()=>{}),await this.store.remove(this.storeKey),"record"in n&&this.retryFeedback(),"followup"in n?this.patch({savedFollowup:n}):this.patch({saved:n.record})}catch(i){if(!this.active)return;if(i instanceof ee&&!i.uncertain){const r=i.detail.error.code==="VERSION_CONFLICT",n={...this.state.draft,frozen:!1,pending:void 0};this.patch({draft:n,conflict:r,message:i.message}),await this.persist(n).catch(()=>{})}else this.patch({message:(this.state.draft.frozen?"保存结果待确认,手动重试会沿用同一次请求。":"")+(i instanceof Error?i.message:"保存失败")})}finally{this.patch({busy:!1})}}}async loadPreferences(){if(this.historySupported)try{const t=await this.client.request("/api/suiji/v1/correction-preferences");this.check(),this.patch({preferences:t})}catch(t){this.patch({correctionMessage:t instanceof Error?t.message:"读取历史设置失败"})}}async setHistoryEnabled(t){const s=this.state.preferences;if(s)try{const i=await this.client.request("/api/suiji/v1/correction-preferences","PUT",{expectedVersion:s.version,historyEnabled:t},crypto.randomUUID());this.check(),this.patch({preferences:i})}catch(i){this.patch({correctionMessage:i instanceof Error?i.message:"设置失败"})}}async loadHistory(t){if(this.historySupported)try{const s=await this.client.request("/api/suiji/v1/correction-history"+(t?"?cursor="+encodeURIComponent(t):""));this.check(),this.patch({history:t&&this.state.history?{items:[...this.state.history.items,...s.items],nextCursor:s.nextCursor}:s})}catch(s){this.patch({correctionMessage:s instanceof Error?s.message:"历史读取失败"})}}async deleteHistory(t){try{await this.client.request("/api/suiji/v1/correction-history"+(t?"/"+t:""),"DELETE",void 0,crypto.randomUUID()),this.check(),await this.loadHistory(),await this.loadPreferences()}catch(s){this.patch({correctionMessage:s instanceof Error?s.message:"删除失败"})}}async loadFeedbackState(){const t=await this.store.get("feedback-intents").catch(()=>{});this.active&&this.patch({feedbackPending:!!(t!=null&&t.length)})}async enqueueFeedback(t){const s=await this.store.get("feedback-intents")??[];await this.store.set("feedback-intents",[...s,t]),this.patch({feedbackPending:!0})}async retryFeedback(){const t=await this.store.get("feedback-intents").catch(()=>{});if(!(t!=null&&t.length))return;const s=[];for(const i of t)try{await this.client.request("/api/suiji/v1/corrections/"+i.correctionId+"/feedback","POST",{recordId:i.recordId,recordVersion:i.recordVersion,saveKey:i.saveKey},i.key)}catch(r){(!(r instanceof ee)||r.uncertain)&&s.push(i)}s.length?await this.store.set("feedback-intents",s):await this.store.remove("feedback-intents"),this.patch({feedbackPending:!!s.length})}async loadLatest(){if(!(this.state.busy||this.state.draft.id==="new"))try{const{record:t}=await this.client.request("/api/suiji/v1/records/"+this.state.draft.id);this.check(),this.patch({latest:t})}catch(t){this.patch({message:t instanceof Error?t.message:"读取最新版本失败"})}}acceptLatestVersion(){const t=this.state.latest;if(!t||this.state.busy||this.state.draft.frozen)return;const s={...this.state.draft,version:t.version,existing:t.attachments,files:[]};if(this.state.draft.files.length){this.patch({message:"本机还有新增附件,请先保存其文件并移除,再采用最新附件版本"});return}this.patch({draft:s,latest:void 0,conflict:!1,message:"已采用最新版本号与附件,本机正文、类型和标签选择保留;请比较后手动保存"}),this.persist(s).catch(()=>{})}}function yt({client:a,store:t,writable:s,alive:i,models:r,setEditor:n,setItems:d,setDetail:l,setMessage:c}){const f=A(m=>{if(!i.current||!a.active)return;const o=v=>({...v.version>m.version?v:m,followupSummary:jt(v.followupSummary,m.followupSummary)});d(v=>v.map(k=>k.id===m.id?o(k):k)),l(v=>(v==null?void 0:v.record.id)===m.id?{...v,record:o(v.record)}:v)}),p=A(async m=>{if(!(!s||m.deletedAt))try{const o="followup:"+m.id;let v=r.current.get(o);if(!v){const k=await t.get(o)??{id:m.id,kind:"note",body:"",existing:[],files:[]};if(!i.current)return;v=new $e(k,a,t,m.id),r.current.set(o,v),await v.initialize()}i.current&&n(v)}catch(o){i.current&&c(o instanceof Error?o.message:"跟进草稿读取失败")}});return{acceptRecord:f,editFollowup:p}}function kt({client:a,store:t,writable:s,statusBusy:i,alive:r,setStatusBusy:n,setMessage:d,setPending:l,acceptRecord:c,setDetail:f,load:p}){return A(async(m,o)=>{var v;if(!(!s||i)){n(!0),d("");try{const k=await t.get("status:"+m.id);if(!k&&((v=await t.get("draft:"+m.id))!=null&&v.frozen))throw new Error("正文保存结果待确认,请先在编辑器确认");const E=k??{path:`/api/suiji/v1/records/${m.id}${"tags"in o?"":"trashed"in o?"/trash":"/task-status"}`,method:"tags"in o?"PATCH":"POST",key:crypto.randomUUID(),data:{expectedVersion:m.version,...o}};if(await t.set("status:"+m.id,E),!r.current)return;l(b=>new Set([...b,m.id]));const g=await a.request(E.path,E.method,E.data,E.key);if(!r.current)return;await t.remove("status:"+m.id),l(b=>{const S=new Set(b);return S.delete(m.id),S}),c(g.record),f(b=>(b==null?void 0:b.record.id)!==m.id?b:E.path.endsWith("/trash")||E.path.endsWith("/task-status")&&g.record.taskStatus==="done"?void 0:b),await p()}catch(k){if(!r.current)return;if(k instanceof ee&&!k.uncertain)try{await t.remove("status:"+m.id),l(E=>{const g=new Set(E);return g.delete(m.id),g})}catch{d("本机状态确认写入失败,请手动重试");return}if(k instanceof ee&&k.detail.error.code==="VERSION_CONFLICT"){try{const E=await a.request(`/api/suiji/v1/records/${m.id}`);c(E.record),d("记录已在其他地方更新,已显示最新内容,请重新选择标签或操作")}catch{d("记录已有新版本,读取失败,请返回列表重新打开后再操作")}return}d(k instanceof Error?k.message:"操作结果待确认")}finally{r.current&&n(!1)}}})}const Ae=["bg-emerald-100 text-emerald-900 dark:bg-emerald-950 dark:text-emerald-200","bg-blue-100 text-blue-900 dark:bg-blue-950 dark:text-blue-200","bg-purple-100 text-purple-900 dark:bg-purple-950 dark:text-purple-200","bg-pink-100 text-pink-900 dark:bg-pink-950 dark:text-pink-200","bg-orange-100 text-orange-900 dark:bg-orange-950 dark:text-orange-200","bg-teal-100 text-teal-900 dark:bg-teal-950 dark:text-teal-200"];function Se(a){let t=0;for(const s of a)t=(t*31+s.codePointAt(0))%Ae.length;return Ae[t]}function he({tags:a=[],onSelect:t}){return a.length?e.jsx("div",{className:"relative flex flex-wrap gap-2",children:a.map(s=>t?e.jsx("button",{type:"button",className:`rounded-full px-2.5 py-1 text-xs break-all ${Se(s)}`,"aria-label":`筛选标签:${s}`,onClick:()=>t(s),children:s},s):e.jsx("span",{className:`rounded-full px-2.5 py-1 text-xs break-all ${Se(s)}`,children:s},s))}):null}function Ve({selected:a=[],available:t,onChange:s}){const[i,r]=x.useState(!1),[n,d]=x.useState(""),[l,c]=x.useState(""),f=t.slice(0,6),p=o=>{try{s(Le([...a,o])),d(""),c(""),r(!1)}catch(v){c(v.message)}},m=o=>{s(a.filter(v=>v!==o)),c("")};return e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[a.filter(o=>!f.includes(o)).map(o=>e.jsxs("button",{type:"button","aria-label":`移除标签:${o}`,className:`rounded-full px-2.5 py-1 text-sm break-all ${Se(o)}`,onClick:()=>m(o),children:[o," ×"]},o)),e.jsx(u,{type:"button",variant:"ghost",size:"sm",disabled:a.length>=2,"aria-expanded":i,onClick:()=>r(!i),children:"+标签"}),a.length>=2?e.jsx("span",{className:"text-xs text-muted-foreground",children:"最多 2 个标签"}):null]}),f.length?e.jsxs("div",{role:"group","aria-label":"最近使用的标签",className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"最近使用"}),f.map(o=>{const v=a.includes(o);return e.jsxs(u,{type:"button",variant:v?"default":"outline",size:"sm","aria-pressed":v,disabled:!v&&a.length>=2,onClick:()=>v?m(o):p(o),children:[o,v?" ✓":""]},o)})]}):null,i&&a.length<2?e.jsxs("div",{className:"flex flex-col gap-2 rounded-xl border p-3",children:[e.jsx(K,{"aria-label":"标签名称",placeholder:"搜索或创建标签",value:n,onChange:o=>d(o.target.value),onKeyDown:o=>{o.key==="Enter"&&!o.nativeEvent.isComposing&&(o.preventDefault(),p(n))}}),e.jsx("div",{className:"flex max-h-40 flex-wrap gap-2 overflow-y-auto",children:t.filter(o=>!a.includes(o)&&o.includes(n.trim())).map(o=>e.jsx(u,{type:"button",variant:"outline",size:"sm",onClick:()=>p(o),children:o},o))}),n.trim()&&!t.includes(n.trim())?e.jsxs(u,{type:"button",variant:"outline",size:"sm",onClick:()=>p(n),children:["创建「",n.trim(),"」"]}):null]}):null,l?e.jsx("p",{role:"alert",className:"text-sm text-destructive",children:l}):null]})}function Nt({available:a,selected:t,onSelect:s}){const[i,r]=x.useState(!1),[n,d]=x.useState(""),l=a.slice(0,5);if(t&&!l.includes(t)&&l.push(t),!l.length)return null;const c=f=>{s(f===t?"":f),r(!1),d("")};return e.jsxs("div",{className:"mb-4 flex flex-col gap-2","aria-label":"标签筛选",children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[l.map(f=>e.jsxs(u,{type:"button",size:"sm",variant:t===f?"default":"outline","aria-pressed":t===f,onClick:()=>c(f),children:[f,t===f?" ×":""]},f)),e.jsx(u,{type:"button",variant:"ghost",size:"sm","aria-expanded":i,onClick:()=>r(!i),children:"更多标签"})]}),i?e.jsxs("div",{className:"flex flex-col gap-2 rounded-xl border p-3",children:[e.jsx(K,{"aria-label":"搜索标签",placeholder:"搜索已有标签",value:n,onChange:f=>d(f.target.value)}),e.jsx("div",{className:"flex max-h-48 flex-wrap gap-2 overflow-y-auto",children:a.filter(f=>f.includes(n.trim())).map(f=>e.jsx(u,{type:"button",size:"sm",variant:t===f?"default":"outline",onClick:()=>c(f),children:f},f))})]}):null]})}function St(a,t){const s=[...new Set(t.map(r=>r.canonical))].filter(Boolean).sort((r,n)=>n.length-r.length),i=[];for(let r=0;r<a.length;){const n=s.find(d=>a.startsWith(d,r));if(n)i.push({text:n,term:t.find(d=>d.canonical===n)}),r+=n.length;else{const d=i.at(-1);d&&!d.term?d.text+=a.charAt(r):i.push({text:a.charAt(r)}),r++}}return i}function Ct({model:a,selectedText:t,available:s}){var C,R,L,F,W,N;const i=x.useSyncExternalStore(a.subscribe,a.snapshot),[r,n]=x.useState(!1),[d,l]=x.useState(!1),[c,f]=x.useState(!1),[p,m]=x.useState(),[o,v]=x.useState(),[k,E]=x.useState("");x.useEffect(()=>{a.loadLexicon(),a.loadPreferences()},[a]);const g=((C=i.lexicon)==null?void 0:C.entries)??[],b=async()=>{if(!p||!i.lexicon)return;const y=p.canonical.trim(),q=p.variant.trim();if(!y)return;const M=structuredClone(g),U=structuredClone(g),$=U.find(I=>I.canonical===y);if($?q&&!$.variants.includes(q)&&$.variants.push(q):U.push({canonical:y,variants:q?[q]:[]}),JSON.stringify(U)===JSON.stringify(g)){E("这个写法已在词库中"),m(void 0);return}try{await a.putLexicon(U),v(M),m(void 0)}catch{}},S=async y=>{try{await a.putLexicon(g.filter(q=>q.canonical!==y))}catch{}},j=i.correction,w=(j==null?void 0:j.status)==="completed"&&j.correctedText;return e.jsxs("section",{className:"space-y-3 rounded-xl border p-4 text-sm","aria-label":"文字纠错",children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(u,{type:"button",variant:"outline",disabled:!s||!i.draft.body.trim()||i.correctionBusy||i.draft.frozen,onClick:()=>void a.correct(),children:i.correctionBusy?"正在纠正…":"纠正文字"}),e.jsx(u,{type:"button",variant:"ghost",onClick:()=>l(!d),children:"纠错词库"}),a.historySupported?e.jsx(u,{type:"button",variant:"ghost",onClick:()=>{f(!c),c||a.loadHistory()},children:"历史辅助"}):null,t?e.jsx(u,{type:"button",variant:"ghost",onClick:()=>m({canonical:t,variant:""}),children:"记住选词"}):null]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"点击后,本次文字和专有词库会经 Codex CLI 发送给模型提供方。"}),s?null:e.jsx("p",{className:"text-xs text-muted-foreground",children:"此服务尚未启用文字纠错;词库仍可管理。"}),i.correctionMessage||k?e.jsx("p",{role:"status",children:k||i.correctionMessage}):null,i.feedbackPending?e.jsx(u,{type:"button",variant:"outline",onClick:()=>void a.retryFeedback(),children:"手动重试历史反馈"}):null,c&&a.historySupported?e.jsxs("div",{className:"space-y-2 rounded-lg border p-3",children:[e.jsx("strong",{children:"历史辅助"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"开启后,随记服务端会保存纠错前文本、候选和应用后实际保存的正文; 下次纠错会将少量相关修改示例连同本次文字发送给模型提供方。不会自动修改正式词库。"}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:((R=i.preferences)==null?void 0:R.historyEnabled)??!1,disabled:!i.preferences,onChange:y=>void a.setHistoryEnabled(y.target.checked)}),"启用历史辅助"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"关闭后不再新增或使用历史。清空只删除纠错派生记录,不删除随记正文或词库。"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(u,{type:"button",variant:"outline",onClick:()=>void a.loadHistory(),children:"刷新历史"}),e.jsx(u,{type:"button",variant:"outline",disabled:!((L=i.history)!=null&&L.items.length),onClick:()=>void a.deleteHistory(),children:"清空纠错历史"})]}),(F=i.history)==null?void 0:F.items.map(y=>e.jsxs("div",{className:"space-y-1 rounded border p-2",children:[e.jsxs("p",{className:"whitespace-pre-wrap break-words",children:["候选:",y.correctedText]}),e.jsxs("p",{className:"whitespace-pre-wrap break-words",children:["保存:",y.finalText]}),e.jsx(u,{type:"button",variant:"ghost",onClick:()=>void a.deleteHistory(y.id),children:"删除"})]},y.id)),(W=i.history)!=null&&W.nextCursor?e.jsx(u,{type:"button",variant:"outline",onClick:()=>{var y;return void a.loadHistory((y=i.history)==null?void 0:y.nextCursor)},children:"加载更多"}):null]}):null,i.lexiconPending?e.jsx(u,{type:"button",variant:"outline",onClick:()=>void a.putLexicon(g).then(()=>{v(g),m(void 0),E("")}).catch(()=>{}),children:"手动重试确认词库写入"}):null,w?e.jsxs("div",{className:"space-y-3 rounded-lg border p-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("strong",{children:"纠错预览"}),e.jsx(u,{type:"button",variant:"ghost",onClick:()=>n(!r),children:r?"收起原文":"查看原文"})]}),r?e.jsx("p",{className:"whitespace-pre-wrap break-words",children:i.correctionSource}):null,e.jsx("p",{className:"whitespace-pre-wrap break-words",children:St(j.correctedText,j.suggestedTerms??[]).map((y,q)=>y.term?e.jsx("button",{type:"button",className:"decoration-dotted underline underline-offset-4",onClick:()=>m(y.term),children:y.text},q):e.jsx("span",{children:y.text},q))}),(N=j.uncertainTerms)!=null&&N.length?e.jsxs("p",{children:["仍不确定:",j.uncertainTerms.join("、"),"。请核对原文。"]}):null,e.jsxs("div",{className:"flex gap-2",children:[e.jsx(u,{type:"button",onClick:()=>a.applyCorrection(),disabled:i.draft.body!==i.correctionSource||i.draft.frozen,children:"应用到草稿"}),e.jsx(u,{type:"button",variant:"outline",onClick:()=>void a.cancelCorrection(),children:"取消"})]})]}):null,p?e.jsxs("div",{className:"space-y-2 rounded-lg border p-3",children:[e.jsx("strong",{children:"记住这个写法"}),e.jsxs("label",{className:"block",children:["正确写法",e.jsx("input",{className:"w-full rounded border bg-background p-2",value:p.canonical,onChange:y=>m({...p,canonical:y.target.value})})]}),e.jsxs("label",{className:"block",children:["误识别写法(可留空)",e.jsx("input",{className:"w-full rounded border bg-background p-2",value:p.variant,onChange:y=>m({...p,variant:y.target.value})})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(u,{type:"button",disabled:i.lexiconPending||!i.lexicon,onClick:()=>void b(),children:"加入词库"}),e.jsx(u,{type:"button",variant:"ghost",onClick:()=>m(void 0),children:"取消"})]})]}):null,o?e.jsx(u,{type:"button",variant:"ghost",onClick:()=>{a.putLexicon(o).then(()=>v(void 0)).catch(()=>{})},children:"撤销本次添加"}):null,d?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("strong",{children:"纠错词库"}),e.jsx(u,{type:"button",variant:"ghost",onClick:()=>void a.loadLexicon(),children:"刷新"})]}),g.map(y=>e.jsxs("div",{className:"flex items-center justify-between gap-2 rounded border p-2",children:[e.jsxs("span",{children:[y.canonical,y.variants.length?` ← ${y.variants.join("、")}`:""]}),e.jsx(u,{type:"button",variant:"ghost",onClick:()=>void S(y.canonical),children:"移除"})]},y.canonical)),e.jsx(u,{type:"button",variant:"outline",onClick:()=>m({canonical:"",variant:""}),children:"新增词条"})]}):null]})}function Et({model:a,onClose:t,onSaved:s,onFollowupSaved:i,onDiscard:r,availableTags:n,correctionAvailable:d}){const l=x.useSyncExternalStore(a.subscribe,a.snapshot),{draft:c,busy:f}=l,p=A(s),[m,o]=x.useState(""),v=A(g=>{const b=Array.from(g.clipboardData.files).find(S=>S.type.startsWith("image/"));b&&(g.preventDefault(),g.stopPropagation(),!f&&!c.frozen&&a.addFile(b))}),k=A(g=>i==null?void 0:i(g));x.useEffect(()=>{l.savedFollowup&&k(l.savedFollowup)},[l.savedFollowup,k]);const E=A(r);return x.useEffect(()=>{l.saved&&p(l.saved)},[l.saved,p]),x.useEffect(()=>{l.discarded&&E()},[l.discarded,E]),e.jsxs(Fe,{title:a.followupRecordId?"追加跟进":c.id==="new"?"记下一点什么":"编辑记录",onBack:t,busy:f,onPaste:v,description:c.frozen?"保存结果待确认,请手动重试":"草稿自动保留,点保存后上传。",children:[e.jsxs("fieldset",{disabled:f||c.frozen,className:"flex flex-col gap-4",children:[a.followupRecordId?null:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{children:"类型"}),e.jsx("div",{role:"group","aria-label":"记录类型",className:"inline-flex gap-1 rounded-xl bg-secondary p-1",children:[["note","想法"],["task","待办"]].map(([g,b])=>e.jsx(u,{type:"button",size:"sm",variant:c.kind===g?"default":"ghost","aria-pressed":c.kind===g,disabled:!!c.material&&g==="task",onClick:()=>a.edit({kind:g}),children:b},g))})]}),!a.followupRecordId&&c.id!=="new"?e.jsx("p",{className:"text-sm text-muted-foreground",children:c.material?`旧素材归属日期:${c.material.materialDate}。服务切换后保存到浏览;原冻结请求保持不变,请在新版随记中查看。`:"切换为待办时设为未完成;切换为想法时清除待办状态。"}):null,e.jsxs("label",{className:"flex flex-col gap-2",children:[a.followupRecordId?"跟进内容":"原文",e.jsx("textarea",{"aria-label":a.followupRecordId?"跟进内容":"原文",value:c.body,onChange:g=>a.edit({body:g.target.value}),onSelect:g=>{const b=g.currentTarget;o(b.value.slice(b.selectionStart,b.selectionEnd).trim().slice(0,80))},placeholder:"此刻的想法、一个链接,或者以后想做的事……",className:"min-h-56 resize-y rounded-xl border bg-background p-4 leading-relaxed outline-none focus:ring-2 focus:ring-ring"})]}),d!==void 0?e.jsx(Ct,{model:a,selectedText:m,available:d}):null,a.followupRecordId?null:e.jsx(Ve,{selected:c.tags,available:n,onChange:g=>a.edit({tags:g})}),e.jsxs("span",{className:"text-right text-xs text-muted-foreground",children:[[...c.body].length.toLocaleString()," / 20,000"]}),e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:["添加图片或 Markdown",e.jsx("span",{className:"text-xs text-muted-foreground",children:"可在编辑区按 ⌘V / Ctrl+V 粘贴图片。"}),e.jsx("input",{"aria-label":"添加附件",type:"file",accept:"image/jpeg,image/png,.md",onChange:g=>{var S;const b=(S=g.target.files)==null?void 0:S[0];g.target.value="",b&&a.addFile(b)}})]}),[...c.existing.map(g=>({id:g.id,name:g.fileName,existing:!0})),...c.files.map(g=>({id:g.id,name:g.file.name,existing:!1}))].map(g=>e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border p-3",children:[e.jsx("span",{className:"truncate",children:g.name}),e.jsx(u,{type:"button",size:"sm",variant:"ghost",onClick:()=>a.edit(g.existing?{existing:c.existing.filter(b=>b.id!==g.id)}:{files:c.files.filter(b=>b.id!==g.id)}),children:"移除"})]},g.id))]}),l.message?e.jsx("p",{role:"alert",className:"whitespace-pre-wrap text-sm text-destructive",children:l.message}):null,l.conflict?e.jsx(u,{variant:"outline",onClick:()=>void a.loadLatest(),children:"查看最新原文"}):null,l.latest?e.jsxs("section",{className:"flex flex-col gap-3 rounded-xl border p-4",children:[e.jsx("p",{children:"云端标签"}),e.jsx(he,{tags:l.latest.tags}),e.jsxs("p",{children:["本机标签",c.tags===void 0?":未修改,保存时保留云端标签":""]}),e.jsx(he,{tags:c.tags}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["服务端版本 ",l.latest.version,",类型:",l.latest.kind==="note"?"想法":"待办","。请与上方本机草稿比较"]}),e.jsx("p",{className:"whitespace-pre-wrap break-words",children:l.latest.body}),e.jsx(u,{variant:"outline",onClick:()=>a.acceptLatestVersion(),children:"保留本机正文、类型和标签选择,采用最新版本继续编辑"})]}):null,e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("span",{role:"status",className:"text-xs text-muted-foreground",children:l.localError?"本机草稿未保存":l.localSaving?"正在保存本机草稿…":"本机草稿已保存"}),e.jsx(u,{disabled:f,onClick:()=>void a.save(),children:f?"正在保存…":c.frozen?"手动重试确认":"保存"})]}),e.jsx(u,{variant:"ghost",disabled:f||c.frozen,onClick:()=>{window.confirm("放弃这份本机草稿?已保存的记录不会改变。")&&a.discard()},children:"放弃本机草稿"})]})}function Rt({record:a,client:t,writable:s,onAdd:i,onRecord:r,onOpenLink:n}){var g;const[d,l]=x.useState([]),[c,f]=x.useState(null),[p,m]=x.useState(!1),[o,v]=x.useState(""),k=x.useRef(0),E=A(async(b=!1)=>{const S=++k.current;m(!0),v("");try{const j=`/api/suiji/v1/records/${a.id}`,[w,C]=await Promise.all([t.request(j+"/followups"+(b&&c?"?cursor="+encodeURIComponent(c):"")),b?void 0:t.request(j)]);if(!t.active||S!==k.current)return;l(R=>b?[...R,...w.items.filter(L=>!R.some(F=>F.id===L.id))]:w.items),f(w.nextCursor),C&&r(C.record)}catch(j){S===k.current&&v(j instanceof Error?j.message:"跟进读取失败")}finally{S===k.current&&m(!1)}});return x.useEffect(()=>{const b=k;return E(),()=>{++b.current}},[E,a.id,t]),e.jsxs("section",{className:"flex flex-col gap-4 border-t pt-4","aria-label":"跟进",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("h3",{children:["跟进 ",((g=a.followupSummary)==null?void 0:g.count)??d.length," 条"]}),e.jsx(u,{variant:"ghost",disabled:p,onClick:()=>void E(),children:"刷新跟进"}),a.deletedAt?null:e.jsx(u,{disabled:!s,onClick:i,children:"追加跟进"})]}),o?e.jsx("p",{role:"alert",className:"text-destructive",children:o}):null,d.map(b=>e.jsxs("article",{className:"flex flex-col gap-2 rounded-xl border p-4",children:[e.jsxs("p",{className:"text-xs text-muted-foreground",children:[b.source.actor==="app"?"你":`Agent${b.source.agentName?" · "+b.source.agentName:""}`," ","· ",pe(b.createdAt)]}),b.source.sessionId?e.jsxs("p",{className:"break-all text-xs text-muted-foreground",children:["会话:",b.source.sessionId]}):null,e.jsx(Ce,{body:b.body,onOpenLink:n}),b.attachments.map(S=>e.jsx(Me,{attachment:S,client:t},S.id))]},b.id)),p?e.jsx("p",{role:"status",children:"正在读取跟进…"}):null,c?e.jsx(u,{variant:"outline",disabled:p,onClick:()=>void E(!0),children:"加载更早跟进"}):null]})}const Ee=a=>a.kind==="note"?"想法":{open:"未完成",done:"已完成",archived:"不再做"}[a.taskStatus??"open"];function It({record:a,onOpenLink:t,client:s,onTag:i,availableTags:r,onTagsChange:n,message:d,onClose:l,onEdit:c,onStatus:f,onTrash:p,onReview:m,onRecreate:o,info:v,onFollowup:k,onRecord:E,writable:g,pending:b,busy:S,citedVersion:j}){var M,U;const[w,C]=x.useState(!1),[R,L]=x.useState(!1),[F,W]=x.useState(!1),[N,y]=x.useState("");x.useEffect(()=>{y("")},[a.id,a.body]),x.useEffect(()=>{if(!N)return;const $=window.setTimeout(()=>y(""),2500);return()=>window.clearTimeout($)},[N]);const q=A(async()=>{W(!0),y("");try{await navigator.clipboard.writeText(a.body),y(a.attachments.length?"正文已复制,附件未包含":"正文已复制")}catch{y("复制失败,请重试或选择正文手动复制")}finally{W(!1)}});return e.jsxs(Fe,{title:Ee(a),description:pe(a.createdAt),onBack:l,actions:e.jsxs(e.Fragment,{children:[e.jsx(u,{variant:"ghost",size:"icon","aria-label":"复制",title:a.body?"复制":"暂无正文可复制",disabled:!a.body||F,onClick:()=>void q(),children:e.jsx(Qe,{className:"size-4"})}),e.jsx(u,{variant:"ghost",disabled:!g||b||S||!!a.deletedAt,onClick:c,children:"编辑"})]}),feedback:N?e.jsx("div",{className:"pointer-events-none absolute inset-x-4 bottom-5 z-10 flex justify-center",children:e.jsx("p",{role:"status",className:"rounded-full border bg-popover px-4 py-2.5 text-center text-sm text-popover-foreground shadow-lg",children:N})}):null,children:[j!==void 0&&j!==a.version?e.jsxs("p",{role:"status",className:"text-sm text-muted-foreground",children:["此记录已更新;回答引用的是版本 ",j,",下方是当前原文。"]}):null,e.jsx(Ce,{body:a.body,onOpenLink:t}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(he,{tags:a.tags,onSelect:i}),a.deletedAt?null:e.jsx(u,{variant:"ghost",size:"sm",disabled:!g||b||S,"aria-expanded":R,onClick:()=>L(!R),children:R?"收起标签":(((M=a.tags)==null?void 0:M.length)??0)>=2?"管理标签":"添加标签"})]}),R&&!a.deletedAt?e.jsxs("fieldset",{disabled:!g||b||S,"aria-label":"快速编辑标签",className:"min-w-0 space-y-2 rounded-xl border p-3 disabled:opacity-60",children:[e.jsx(Ve,{selected:a.tags,available:r,onChange:n}),e.jsx("p",{role:"status",className:"text-xs text-muted-foreground",children:S?"正在保存标签…":b?"保存结果待确认,请手动确认":"选择或移除后自动保存,最多 2 个标签"})]}):null,d?e.jsx("p",{role:"alert",className:"text-sm text-destructive",children:d}):null,e.jsx("div",{className:"flex flex-wrap gap-2",children:a.attachments.map($=>e.jsx(Me,{attachment:$,client:s},$.id))}),(U=v.features)!=null&&U.followups?e.jsxs(e.Fragment,{children:[a.deletedAt?null:e.jsx(u,{variant:"outline",onClick:()=>{navigator.clipboard.writeText(wt({endpoint:s.endpoint,serverId:v.serverId,ownerId:v.ownerId,recordId:a.id})).then(()=>y("交接指令已复制"),()=>y("复制失败,请重试"))},children:"交给 Agent"}),e.jsx(Rt,{record:a,client:s,writable:g,onAdd:k,onRecord:E,onOpenLink:t})]}):null,a.deletedAt?e.jsx("p",{role:"status",children:"已在回收站,恢复后可继续编辑。"}):null,b?e.jsx(u,{disabled:!g||S,onClick:()=>f("done"),children:"操作结果待确认 · 手动确认"}):null,e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(u,{variant:"outline",disabled:!!a.deletedAt,onClick:m,children:"聊聊这条"}),!a.deletedAt&&a.kind==="task"&&(a.taskStatus==="open"||b)?e.jsxs(e.Fragment,{children:[e.jsx(u,{disabled:!g||S,onClick:()=>f("done"),children:b?"手动确认操作":"标记完成"}),b?null:e.jsx(u,{variant:"outline",disabled:!g||S,onClick:()=>f("archived"),children:"不再做"})]}):!a.deletedAt&&a.taskStatus==="done"?e.jsx(u,{disabled:!g||S||b,onClick:()=>f("open"),children:"撤销完成"}):!a.deletedAt&&a.kind==="task"?e.jsx(u,{disabled:!g,onClick:o,children:"再次想做"}):null,a.deletedAt?e.jsx(u,{disabled:!g||b||S,onClick:()=>p(!1),children:"恢复记录"}):w?e.jsxs("div",{className:"flex flex-wrap items-center gap-2",role:"alert",children:[e.jsx("span",{children:"移入回收站后可恢复,正文和附件会保留。"}),e.jsx(u,{variant:"destructive",disabled:!g||b||S,onClick:()=>{C(!1),p(!0)},children:"确认移入回收站"}),e.jsx(u,{variant:"ghost",onClick:()=>C(!1),children:"取消"})]}):e.jsx(u,{variant:"destructive",disabled:!g||b||S,onClick:()=>C(!0),children:"移入回收站"})]})]})}function Tt({record:a,pending:t,onOpen:s,onOpenLink:i,onTag:r}){var n;return e.jsxs("article",{className:"relative flex flex-col gap-3 rounded-2xl border bg-card p-4 text-left shadow-sm transition-colors hover:bg-accent",children:[e.jsx("button",{type:"button","aria-label":`查看记录:${a.body||"附件记录"}`,onClick:s,className:"absolute inset-0 rounded-2xl focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"}),e.jsxs("span",{className:"pointer-events-none relative flex items-center justify-between gap-3 text-xs text-muted-foreground",children:[e.jsxs("span",{children:[Ee(a),t?" · 状态待确认":""]}),e.jsx("time",{children:pe(a.createdAt)})]}),e.jsx(Ce,{onOpenLink:i,body:a.body||"附件记录",className:"pointer-events-none relative line-clamp-5"}),a.attachments.length?e.jsx("span",{className:"pointer-events-none relative text-xs text-muted-foreground",children:a.attachments.map(d=>d.fileName).join(" · ")}):null,(n=a.followupSummary)!=null&&n.latest?e.jsxs("p",{className:"pointer-events-none relative truncate text-sm text-muted-foreground",children:["跟进 ",a.followupSummary.count," 条 · ",a.followupSummary.latest.excerpt]}):null,e.jsx(he,{tags:a.tags,onSelect:r})]})}function qt({client:a,info:t,scope:s,onScope:i,onOpen:r,onSave:n,writable:d,onLockedChange:l}){var W;const[c,f]=x.useState(""),[p,m]=x.useState([]),[o,v]=x.useState(),[k,E]=x.useState(!1),[g,b]=x.useState(""),S=x.useRef(void 0),j=x.useRef(!0);x.useEffect(()=>{l==null||l(!!(S.current||k||(o==null?void 0:o.status)==="running"))},[k,o,g,l]),x.useEffect(()=>(j.current=!0,()=>{j.current=!1}),[]);const w=A(async()=>{if(!(k||(o==null?void 0:o.status)==="running")){E(!0),b(""),S.current??(S.current={key:crypto.randomUUID(),input:{question:c,scope:s,history:p.flatMap(N=>{var y;return[{role:"user",text:N.question},{role:"assistant",text:((y=N.job.answer)==null?void 0:y.text)??""}]}).slice(-6)}});try{const N=await a.request("/api/suiji/v1/reviews","POST",S.current.input,S.current.key);j.current&&v(N)}catch(N){j.current&&b((N instanceof Error?N.message:"回顾请求失败")+"。问题保留,点击手动确认可重查同一次请求。")}finally{j.current&&E(!1)}}}),C=A(N=>{v(N),N.status!=="running"&&(N.status==="completed"?(m(y=>{var q;return[...y,{question:((q=S.current)==null?void 0:q.input.question)??c,job:N}]}),f(""),b("")):b(N.error??(N.status==="cancelled"?"已取消,原问题保留":"回顾未完成")),S.current=void 0)});x.useEffect(()=>{if(!o)return;if(o.status!=="running"){S.current&&C(o);return}let N=!0,y;const q=async()=>{try{const M=await a.request("/api/suiji/v1/reviews/"+o.id);if(!N)return;M.status!=="running"?C(M):y=setTimeout(()=>void q(),1500)}catch(M){N&&b((M instanceof Error?M.message:"无法读取进度")+"。可手动查询此回顾的进度。")}};return y=setTimeout(()=>void q(),800),()=>{N=!1,clearTimeout(y)}},[a,o,C]);const R=A(async()=>{if(o)try{C(await a.request("/api/suiji/v1/reviews/"+o.id)),b("")}catch(N){b(N instanceof Error?N.message:"查询失败")}}),L=A(async()=>{if(o)try{C(await a.request("/api/suiji/v1/reviews/"+o.id,"DELETE"))}catch(N){b(N instanceof Error?N.message:"取消失败,请手动重试")}}),F=k||(o==null?void 0:o.status)==="running";return(W=t.ai)!=null&&W.enabled?e.jsxs("section",{className:"flex flex-col gap-7",children:[e.jsxs("header",{className:"flex flex-col gap-2",children:[e.jsx("h2",{className:"text-xl font-semibold",children:"从记录里,接着想"}),e.jsx("p",{className:"text-sm leading-6 text-muted-foreground",children:"主动发问后才检索。回答引用实际原文,保存结论由你决定。"})]}),p.map(N=>e.jsxs("article",{className:"flex flex-col gap-4",children:[e.jsx("p",{className:"ml-8 rounded-2xl bg-secondary p-4 whitespace-pre-wrap",children:N.question}),e.jsxs("div",{className:"flex flex-col gap-4 rounded-2xl border bg-card p-5",children:[e.jsx("p",{className:"whitespace-pre-wrap break-words leading-7",children:N.job.answer.text}),N.job.answer.citations.map((y,q)=>e.jsxs("button",{className:"flex flex-col gap-1 rounded-xl border p-3 text-left hover:bg-accent",onClick:()=>r(y.recordId,y.version),children:[e.jsxs("span",{className:"text-xs text-muted-foreground",children:["[",q+1,"] ",pe(y.createdAt)," ·"," ",Ee(y)," · 版本 ",y.version,y.attachment?` · ${y.attachment.fileName}`:""]}),e.jsx("span",{className:"whitespace-pre-wrap break-words text-sm",children:y.quote||"已读取图片附件"})]},q)),e.jsxs("p",{className:"text-xs leading-5 text-muted-foreground",children:["本次查看 ",N.job.answer.coverage.listedRecords," 条摘要、",N.job.answer.coverage.readRecords," 条原文、",N.job.answer.coverage.attachmentReads," ","段附件。关键词检索,未启用向量索引,未读取外链。"]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(u,{variant:"outline",size:"sm",disabled:!d,onClick:()=>n(N.job.answer.text,"note"),children:"另存笔记"}),e.jsx(u,{variant:"outline",size:"sm",disabled:!d,onClick:()=>n(N.job.answer.text,"task"),children:"新建待办"})]})]})]},N.job.id)),e.jsxs("form",{className:"flex flex-col gap-3 rounded-2xl border bg-card p-5",onSubmit:N=>{N.preventDefault(),w()},children:[e.jsxs("label",{className:"flex items-center gap-3 text-sm",children:["回顾范围",e.jsxs("select",{"aria-label":"回顾范围",disabled:F||!!S.current,value:s.kind,onChange:N=>i({kind:N.target.value}),className:"rounded-lg border bg-background p-2",children:[e.jsx("option",{value:"all",children:"全部历史"}),e.jsx("option",{value:"open",children:"当前待办"}),s.kind==="record"?e.jsx("option",{value:"record",children:"这条记录"}):null]})]}),e.jsx("label",{className:"sr-only",htmlFor:"suiji-question",children:"向随记提问"}),e.jsx("textarea",{id:"suiji-question",value:c,disabled:F||!!S.current,onChange:N=>f(N.target.value),maxLength:4e3,placeholder:"以前有哪些想做、后来放下的事?",className:"min-h-28 resize-y rounded-xl border bg-background p-3 leading-6"}),F?e.jsx("p",{role:"status",className:"text-sm text-muted-foreground",children:"正在检索与回顾,可以继续浏览记录…"}):null,g?e.jsx("p",{role:"alert",className:"text-sm text-destructive",children:g}):null,e.jsxs("div",{className:"flex flex-wrap justify-end gap-2",children:[g&&!k?e.jsx(u,{type:"button",variant:"ghost",onClick:()=>{S.current=void 0,v(void 0),b("")},children:"结束此次等待,重新提问"}):null,(o==null?void 0:o.status)==="running"?e.jsxs(e.Fragment,{children:[e.jsx(u,{type:"button",variant:"outline",onClick:()=>void R(),children:"查询进度"}),e.jsx(u,{type:"button",variant:"outline",onClick:()=>void L(),children:"取消回顾"})]}):e.jsx(u,{type:"submit",disabled:k||!c.trim(),children:S.current?"手动确认请求":"发送"})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"对话仅保留在当前页面会话,刷新后不会自动重新执行。服务上的回顾结果保留 30 分钟。"})]}):e.jsxs("section",{className:"flex flex-col gap-3 py-16 text-center",children:[e.jsx("h2",{className:"text-xl",children:"AI 回顾尚未启用"}),e.jsx("p",{className:"text-muted-foreground",children:"当前服务没有可用的回顾模型。记录和待办仍可正常使用。"})]})}function zt({active:a,disabled:t,loading:s,cursor:i,load:r}){const n=x.useRef(null),d=x.useRef(null),l=x.useRef(null),[c,f]=x.useState(!1);return x.useEffect(()=>{const p=n.current,m=d.current;if(!a||t||s||!i||c||!p||!m)return;const o=new IntersectionObserver(([v])=>{v!=null&&v.isIntersecting&&(o.disconnect(),r(!0))},{root:p,rootMargin:"0px 0px 200px 0px"});return o.observe(m),()=>o.disconnect()},[a,t,s,i,c,n,d,r]),{failed:c,scrollContainer:n,trigger:d,begin:(p,m,o)=>p&&(!m||o||l.current===m)?!1:(l.current=p?m:null,f(!1),!0),fail:p=>{p&&(l.current=null,f(!0))}}}function Dt({cursor:a,failed:t,loading:s,trigger:i,onRetry:r}){return e.jsx("div",{ref:i,className:"flex min-h-px justify-center gap-3",children:a&&t?e.jsx(u,{variant:"outline",disabled:s,onClick:r,children:"重试加载"}):null})}function Pt({connection:a,active:t=!0,headerActions:s,onOpenLink:i}){var ze,De,Pe;const{client:r,info:n,store:d}=a,[l]=x.useState(()=>{var h;return new mt(r,d,((h=n.features)==null?void 0:h.workReports)===!0)}),[c,f]=x.useState(!1),[p,m]=x.useState(),[o,v]=x.useState("records"),[k,E]=x.useState(""),[g,b]=x.useState("open"),[S,j]=x.useState(""),[w,C]=x.useState(""),[R,L]=x.useState([]),[F,W]=x.useState(!1),N=Ze(S,{wait:250}),y=x.useRef(0),[q,M]=x.useState([]),[U,$]=x.useState(null),[I,oe]=x.useState(!1),[fe,G]=x.useState(""),[P,Q]=x.useState(),[V,re]=x.useState(),[Oe,Re]=x.useState({kind:"all"}),[xe,me]=x.useState(new Set),[Ie,He]=x.useState(!1),[te,Ke]=x.useState(!1),O=x.useRef(!0),Z=x.useRef(0),ge=x.useRef(!1),ce=x.useRef(void 0),ie=x.useRef(new Map),ve=A(async()=>{if(!(ge.current||!navigator.locks)){ge.current=!0;try{await navigator.locks.request("suiji-editor:"+d.scope,{ifAvailable:!0},async h=>{!h||!O.current||(Ke(!0),await new Promise(T=>{ce.current=T}))})}finally{ge.current=!1}}});x.useEffect(()=>{var T;O.current=!0,ve(),(T=n.features)!=null&&T.workRecords&&l.initialize();const h=ie.current;return()=>{O.current=!1,h.forEach(z=>z.dispose()),l.dispose(),Promise.all([...h.values()].map(z=>z.settled()).concat(l.settled())).finally(()=>{var z;(z=ce.current)==null||z.call(ce),d.close()})}},[ve,d,l,n]);const X=A(async(h=!1)=>{var ae;if(o==="ai"||o==="work"||!le.begin(h,U,I))return;const T=++Z.current;oe(!0),G(""),h||(M([]),$(null));const z=new URLSearchParams;o==="tasks"?(z.set("kind","task"),z.set("taskStatus",g)):k&&z.set("kind",k),o==="trash"&&z.set("trash","true"),N&&z.set("q",N),w&&z.set("tag",w),h&&U&&z.set("cursor",U);try{const[D,_]=await Promise.all([r.request("/api/suiji/v1/records?"+z),h?void 0:r.request("/api/suiji/v1/tags")]);if(!O.current||T!==Z.current)return;_&&L(_.items);const se=await Promise.all(D.items.map(async Y=>await d.get("status:"+Y.id)?Y.id:void 0));if(!O.current||T!==Z.current)return;const J=(ae=n.features)!=null&&ae.browse?D.items.filter(Y=>!Y.material):D.items;M(Y=>h?[...Y,...J.filter(ye=>!Y.some(Je=>Je.id===ye.id))]:J),$(D.nextCursor),me(Y=>new Set([...h?Y:[],...se.filter(ye=>!!ye)]))}catch(D){O.current&&T===Z.current&&(le.fail(h),G(D instanceof Error?D.message:"读取失败"))}finally{O.current&&T===Z.current&&oe(!1)}});x.useEffect(()=>{t&&X()},[X,o,k,g,N,w,t]);const le=zt({active:t,disabled:o==="ai"||o==="work"||!!(P||V),loading:I,cursor:U,load:X}),be=A(h=>{++Z.current,++y.current,M([]),$(null),Q(void 0),o==="ai"&&v("records"),h===w?X():C(h)}),Te=A(async(h,T)=>{const z=Z.current,ae=++y.current;try{const{record:D}=await r.request("/api/suiji/v1/records/"+h),_=await d.get("status:"+h);if(!O.current||z!==Z.current||ae!==y.current)return;me(se=>{const J=new Set(se);return _?J.add(h):J.delete(h),J}),M(se=>se.map(J=>J.id===D.id&&J.version<=D.version?D:J)),Q({record:D,citedVersion:T})}catch(D){O.current&&G(D instanceof Error?D.message:"读取失败")}}),de=A(async(h,T="task",z="")=>{var ae;if(!(!te||h!=null&&h.deletedAt))try{if(h&&await d.get("status:"+h.id))throw new Error("记录操作待确认,请先手动确认");const D=(h==null?void 0:h.id)??"new";let _=ie.current.get(D);if(_&&z&&G("已恢复原有草稿;新结论未覆盖它。请先处理当前草稿,再另存结论。"),!_){const se=await d.get("draft:"+D);if(!O.current)return;const J=se??{id:D,kind:(h==null?void 0:h.kind)??T,material:h==null?void 0:h.material,body:(h==null?void 0:h.body)??z,tags:(h==null?void 0:h.tags)??[],version:h==null?void 0:h.version,existing:(h==null?void 0:h.attachments)??[],files:[]};_=new $e(J,r,d,void 0,((ae=n.features)==null?void 0:ae.correctionHistory)===!0),ie.current.set(D,_),se&&z&&G("已恢复原有草稿;新结论未覆盖它。请先处理当前草稿,再另存结论。"),await _.initialize()}O.current&&re(_)}catch(D){O.current&&G(D instanceof Error?D.message:"草稿读取失败")}}),{acceptRecord:je,editFollowup:We}=yt({client:r,store:d,writable:te,alive:O,models:ie,setEditor:re,setItems:M,setDetail:Q,setMessage:G}),we=kt({client:r,store:d,writable:te,statusBusy:Ie,alive:O,setStatusBusy:He,setMessage:G,setPending:me,acceptRecord:je,setDetail:Q,load:X}),qe=q.filter(h=>!!h.deletedAt==(o==="trash")&&(!w||(h.tags??[]).includes(w))&&(o==="tasks"?h.kind==="task"&&h.taskStatus===g:!k||h.kind===k)&&(o!=="records"||h.taskStatus!=="done"&&h.taskStatus!=="archived"||xe.has(h.id)));return e.jsxs("main",{className:"relative flex h-full min-h-0 flex-col bg-background text-foreground",children:[s&&o!=="ai"&&o!=="work"&&!P&&!V?Xe.createPortal(e.jsx(u,{variant:"ghost",size:"icon","aria-label":I?"刷新中":"刷新",title:"刷新",disabled:I,onClick:()=>void X(),children:e.jsx(Ye,{className:`size-4 ${I?"animate-spin":""}`})}),s):null,e.jsxs("div",{className:P||V?"hidden":"flex min-h-0 flex-1 flex-col",children:[(ze=n.features)!=null&&ze.workRecords?e.jsx("div",{className:o==="work"?"flex min-h-0 flex-1 flex-col":"hidden",children:e.jsx(bt,{model:l,active:o==="work",writable:te,onReview:()=>{m({tab:"work"}),v("ai")}})}):null,e.jsxs("div",{ref:le.scrollContainer,className:o==="work"?"hidden":"min-h-0 flex-1 overflow-y-auto px-5 pt-4",children:[te?null:e.jsxs("div",{className:"flex items-center justify-between gap-4 rounded-xl border p-4 text-sm",children:[e.jsx("p",{children:"另一随记页面正在编辑,当前可浏览。关闭那一页后可接管编辑。"}),e.jsx(u,{variant:"outline",size:"sm",onClick:()=>void ve(),children:"接管编辑"})]}),fe?e.jsx("p",{role:"alert",className:"text-sm text-destructive",children:fe}):null,e.jsxs("div",{hidden:o!=="ai",className:"pb-6",children:[p?e.jsxs(u,{variant:"ghost",onClick:()=>{v(p.tab),Q(p.detail),m(void 0)},children:["返回",p.detail?"原记录":"工作"]}):null,e.jsx(qt,{client:r,info:n,scope:Oe,onScope:Re,onOpen:(h,T)=>void Te(h,T),onSave:(h,T)=>void de(void 0,T,h),writable:te,onLockedChange:f})]}),o!=="ai"&&o!=="work"?e.jsxs(e.Fragment,{children:[e.jsxs("section",{className:"mb-4 flex flex-wrap items-center justify-between gap-3",children:[o==="tasks"?e.jsxs("label",{className:"flex items-center gap-3 text-sm",children:["状态",e.jsxs("select",{"aria-label":"待办状态",value:g,onChange:h=>b(h.target.value),className:"rounded-xl border bg-card p-2",children:[e.jsx("option",{value:"open",children:"未完成"}),e.jsx("option",{value:"done",children:"已完成"}),e.jsx("option",{value:"archived",children:"不再做"})]})]}):e.jsx("div",{className:"flex items-center gap-3 text-sm",children:e.jsx("div",{role:"group","aria-label":"类型筛选",className:"inline-flex gap-1 rounded-xl bg-secondary p-1",children:[["","全部"],["note","想法"],["task","待办"]].map(([h,T])=>e.jsx(u,{type:"button",size:"sm",variant:k===h?"default":"ghost","aria-pressed":k===h,onClick:()=>E(h),children:T},h))})}),e.jsx(u,{variant:"ghost",size:"icon","aria-label":"搜索记录","aria-pressed":F,onClick:()=>{F&&j(""),W(h=>!h)},children:e.jsx(et,{className:"size-4"})}),F?e.jsx(K,{autoFocus:!0,"aria-label":"搜索原文",placeholder:"搜索正文关键词",value:S,onChange:h=>j(h.target.value),className:"w-full"}):null]}),e.jsx(Nt,{available:R,selected:w,onSelect:be}),e.jsxs("section",{className:"flex flex-col gap-4 pb-20",children:[qe.map(h=>e.jsx(Tt,{record:h,pending:xe.has(h.id),onOpen:()=>void Te(h.id),onOpenLink:i,onTag:be},h.id)),I?e.jsx("p",{role:"status",className:"py-8 text-center text-muted-foreground",children:"正在读取记录…"}):qe.length===0?e.jsxs("div",{className:"flex flex-col gap-3 py-16 text-center",children:[e.jsx("h2",{className:"text-xl",children:S||w?"没有找到匹配的原文":o==="trash"?"回收站为空":"留一点想法在这里"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:S||w?"试试其他标签或更短的关键词。":o==="trash"?"删除的记录会保留在这里,可随时恢复。":"点右下角加号,记下一句想到的事。"})]}):null,e.jsx(Dt,{cursor:U,failed:le.failed,loading:I,trigger:le.trigger,onRetry:()=>void X(!0)})]})]}):null]}),o!=="trash"&&o!=="ai"&&o!=="work"?e.jsx(u,{"aria-label":"新增记录",className:"absolute bottom-20 right-5 size-12 rounded-full shadow-lg",disabled:!te,onClick:()=>void de(),children:e.jsx(tt,{})}):null,e.jsx("nav",{"aria-label":"随记导航",className:"grid shrink-0 grid-cols-4 border-t bg-background px-2 py-2",children:[["records","记录",st],["tasks","待办",pt],["trash","回收站",it],(De=n.features)!=null&&De.workRecords?["work","工作",ut]:["ai","AI",at]].map(([h,T,z])=>e.jsxs("button",{type:"button","aria-current":o===h?"page":void 0,className:`flex flex-col items-center gap-1 rounded-lg py-2 text-xs ${o===h?"bg-secondary text-primary":"text-muted-foreground hover:bg-accent"}`,onClick:()=>{++Z.current,v(h)},children:[e.jsx(z,{className:"size-5"}),T]},h))})]}),P&&!V?e.jsx(It,{onOpenLink:i,...P,client:r,info:n,onFollowup:()=>void We(P.record),onRecord:je,onTag:be,availableTags:R,onTagsChange:h=>void we(P.record,{tags:h}),message:fe,onClose:()=>Q(void 0),onEdit:()=>void de(P.record),onStatus:h=>void we(P.record,{targetStatus:h}),onTrash:h=>void we(P.record,{trashed:h}),onReview:()=>{m({tab:o,detail:P}),c||Re({kind:"record",recordId:P.record.id}),Q(void 0),v("ai")},onRecreate:()=>void de(void 0,"task",P.record.body),writable:te,pending:xe.has(P.record.id),busy:Ie},P.record.id):null,V?e.jsx(Et,{model:V,correctionAvailable:(Pe=n.features)==null?void 0:Pe.correction,availableTags:R,onClose:()=>{V.cancelCorrection(),re(void 0)},onDiscard:()=>{ie.current.delete(V.followupRecordId?"followup:"+V.followupRecordId:V.state.draft.id),V.dispose(),re(void 0)},onFollowupSaved:h=>{const T=h.followup.recordId;ie.current.delete("followup:"+T),V.dispose(),re(void 0),(P==null?void 0:P.record.id)===T&&je({...P.record,followupSummary:h.followupSummary}),X()},onSaved:h=>{var T;(T=n.features)!=null&&T.browse&&h.material?(Q(void 0),G("此素材已保存到浏览,请在新版随记 App 中查看。")):P&&Q({record:h}),ie.current.delete(V.followupRecordId?"followup:"+V.followupRecordId:V.state.draft.id),V.dispose(),re(void 0),X()}}):null]})}function Ut({active:a=!0,accountOnly:t=!1,onClose:s,onOpenLink:i}){const{accounts:r,endpoint:n,setEndpoint:d,username:l,setUsername:c,password:f,setPassword:p,busy:m,message:o,connection:v,needsLogin:k,setNeedsLogin:E,ensure:g,initialize:b,connect:S,switchEnvironment:j,logout:w,editAccount:C,isCurrent:R}=rt(),[L,F]=x.useState(t),[W,N]=x.useState(null),y=x.useRef(!0);x.useEffect(()=>(y.current=!0,g(),()=>{y.current=!1}),[g]),x.useEffect(()=>{v&&F(t)},[v,t]);const q=A(I=>{const oe=v==null?void 0:v.client;i==null||i(I,()=>y.current&&!!oe&&R(oe))}),M=A(async I=>{$&&!window.confirm("放弃当前环境未保存的账户修改?")||await j(I)}),U=r==null?void 0:r.profiles[r.active],$=t&&!!U&&!v&&(n!==U.endpoint||l!==U.username||f!==(U.password??""));return nt($,t&&m&&$),e.jsxs("section",{className:"suiji-theme flex h-full min-h-0 flex-col bg-background text-foreground","aria-label":"随记内容",children:[e.jsxs("header",{className:"flex h-14 shrink-0 items-center gap-2 border-b px-4",children:[L&&v&&!t?e.jsx(u,{variant:"ghost",size:"icon","aria-label":"返回随记",onClick:()=>F(!1),children:e.jsx(ot,{className:"size-4"})}):null,e.jsx("h1",{className:"font-semibold",children:L?"账户设置":"随记"}),(r==null?void 0:r.active)==="development"?e.jsx("span",{className:"rounded bg-secondary px-2 py-0.5 text-xs",children:"开发"}):null,e.jsxs("div",{className:"ml-auto flex items-center gap-1",children:[L?null:e.jsx("div",{ref:N,className:"flex"}),v&&!L?e.jsx(u,{variant:"ghost",size:"icon","aria-label":"随记设置",onClick:()=>F(!0),children:e.jsx(lt,{className:"size-4"})}):null,s?e.jsx(u,{variant:"ghost",size:"icon","aria-label":"关闭随记",onClick:s,children:e.jsx(ct,{className:"size-4"})}):null]})]}),v&&!t?e.jsx("div",{hidden:L,className:"min-h-0 flex-1",children:e.jsx(Pt,{connection:v,active:a,headerActions:W,onOpenLink:i?q:void 0},v.store.scope)}):null,t||L||!v?e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto p-5",children:[r?e.jsxs(e.Fragment,{children:[e.jsx("fieldset",{disabled:m,className:"mb-6 flex gap-2","aria-label":"账户环境",children:["production","development"].map(I=>e.jsx(u,{className:"flex-1",variant:r.active===I?"default":"outline","aria-pressed":r.active===I,onClick:()=>void M(I),children:ke(I)},I))}),e.jsx("p",{className:"mb-5 text-sm text-muted-foreground",children:v?"切换环境会保留各自的账户和草稿。":"首次登录后,下次打开会自动连接。"}),v?e.jsxs("div",{className:"flex flex-col gap-4 text-sm",children:[e.jsxs("p",{children:["已登录",ke(r.active),"环境 · ",l]}),e.jsx("p",{className:"break-all text-muted-foreground",children:n}),e.jsx(u,{variant:"outline",disabled:m,onClick:C,children:"修改账户配置"}),e.jsxs(u,{variant:"destructive",disabled:m,onClick:()=>void w(),children:["退出",ke(r.active),"账户"]})]}):k?e.jsxs("form",{className:"flex flex-col gap-5",onSubmit:I=>{I.preventDefault(),S(r,!0)},children:[e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:["服务地址",e.jsx(K,{"aria-label":"随记服务地址",type:"url",value:n,required:!0,disabled:m,onChange:I=>d(I.target.value),placeholder:"https://你的随记服务"})]}),e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:["账号",e.jsx(K,{"aria-label":"随记账号",autoComplete:"username",value:l,required:!0,disabled:m,onChange:I=>c(I.target.value)})]}),e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:["密码",e.jsx(K,{"aria-label":"随记密码",type:"password",autoComplete:"current-password",value:f,required:!0,disabled:m,onChange:I=>p(I.target.value)})]}),e.jsx(u,{type:"submit",disabled:m,children:m?"正在连接…":"登录随记"})]}):e.jsxs("div",{className:"flex flex-col gap-4 text-sm",children:[e.jsx("p",{children:m?"正在恢复已保存的账户…":"暂时无法连接,账户和草稿已保留。"}),e.jsx(u,{variant:"outline",disabled:m,onClick:()=>E(!0),children:"修改账户配置"})]})]}):null,m?e.jsx("p",{role:"status",className:"mt-4 text-sm",children:"正在连接…"}):null,o?e.jsxs("div",{className:"mt-4 flex flex-col gap-3",children:[e.jsx("p",{role:"alert",className:"text-sm text-destructive",children:o}),e.jsx(u,{variant:"outline",disabled:m,onClick:()=>void b(),children:"重试连接"})]}):null]}):null]})}export{Ut as default};
@@ -1 +1 @@
1
- import{j as n}from"./index-D9-cSGu-.js";import{e as m,o as u,T as h,p as l}from"./main-B_ifx48h.js";import{S as x}from"./tabs-BjCNEXFA.js";function R(t){var i,r;const e=m(),s=u(),o=new URLSearchParams(e.search),c=o.get("section")??"saved";return(i=window.electronAPI)!=null&&i.isElectron?n.jsxs(n.Fragment,{children:[n.jsx(x,{items:[["saved","连接"],["hosts","SSH 主机与通道"]],active:c}),c==="hosts"?n.jsx(h,{embedded:!0}):n.jsx(l,{embedded:!0,onManageTunnels:()=>{const a=new URLSearchParams(e.search);a.set("section","hosts"),s(`${e.pathname}?${a}`,{state:e.state})},connections:t.connections,activeId:o.get("target")??((r=t.activeConnection)==null?void 0:r.id)??null,onAdd:t.onAdd,onRemove:t.onRemove,onEdit:t.onEdit,onReconnect:t.onReconnect,onSelect:a=>{const d=new URLSearchParams(e.search);d.set("target",a),s(`${e.pathname}?${d}`,{state:e.state})}})]}):n.jsx("p",{className:"text-sm text-muted-foreground",children:"连接与 SSH 通道由桌面应用管理。"})}export{R as default};
1
+ import{j as n}from"./index-D9-cSGu-.js";import{e as m,o as u,T as h,p as l}from"./main-DwDuhfcr.js";import{S as x}from"./tabs-CwPtRQY0.js";function R(t){var i,r;const e=m(),s=u(),o=new URLSearchParams(e.search),c=o.get("section")??"saved";return(i=window.electronAPI)!=null&&i.isElectron?n.jsxs(n.Fragment,{children:[n.jsx(x,{items:[["saved","连接"],["hosts","SSH 主机与通道"]],active:c}),c==="hosts"?n.jsx(h,{embedded:!0}):n.jsx(l,{embedded:!0,onManageTunnels:()=>{const a=new URLSearchParams(e.search);a.set("section","hosts"),s(`${e.pathname}?${a}`,{state:e.state})},connections:t.connections,activeId:o.get("target")??((r=t.activeConnection)==null?void 0:r.id)??null,onAdd:t.onAdd,onRemove:t.onRemove,onEdit:t.onEdit,onReconnect:t.onReconnect,onSelect:a=>{const d=new URLSearchParams(e.search);d.set("target",a),s(`${e.pathname}?${d}`,{state:e.state})}})]}):n.jsx("p",{className:"text-sm text-muted-foreground",children:"连接与 SSH 通道由桌面应用管理。"})}export{R as default};