@undefineds.co/xpod 0.4.25 → 0.4.27

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 (155) hide show
  1. package/dist/api/ApiServer.d.ts +1 -0
  2. package/dist/api/ApiServer.js +38 -0
  3. package/dist/api/ai-config/AiConfigStore.js +18 -6
  4. package/dist/api/ai-gateway/connect/index.d.ts +1 -0
  5. package/dist/api/ai-gateway/connect/index.js +39 -18
  6. package/dist/api/ai-gateway/models/ProviderModelsAdapter.js +5 -2
  7. package/dist/api/container/common.js +8 -2
  8. package/dist/api/container/index.js +2 -2
  9. package/dist/api/container/local.js +6 -3
  10. package/dist/api/handlers/AiGatewayHandler.d.ts +1 -0
  11. package/dist/api/handlers/AiGatewayHandler.js +53 -3
  12. package/dist/api/handlers/AiGatewayManagementHandler.js +9 -0
  13. package/dist/api/handlers/TaskHandler.js +15 -10
  14. package/dist/api/network/NetworkEnvironmentConfigurationStore.js +1 -1
  15. package/dist/api/runs/ManagedRunWorker.d.ts +0 -1
  16. package/dist/api/runs/ManagedRunWorker.js +2 -14
  17. package/dist/api/runs/PiAgentRuntimeDriver.d.ts +0 -8
  18. package/dist/api/runs/PiAgentRuntimeDriver.js +65 -21
  19. package/dist/api/runs/RunStateCenter.js +1 -0
  20. package/dist/api/runs/store.d.ts +1 -0
  21. package/dist/api/runs/store.js +13 -0
  22. package/dist/api/tasks/TaskMaterializer.js +13 -6
  23. package/dist/api/tasks/TaskResumeDiagnostics.d.ts +28 -0
  24. package/dist/api/tasks/TaskResumeDiagnostics.js +148 -0
  25. package/dist/api/tasks/TaskService.js +40 -23
  26. package/dist/storage/conditions/StorageETagHandler.d.ts +1 -1
  27. package/dist/storage/conditions/StorageETagHandler.js +13 -4
  28. package/dist/util/task-model-diagnostics.d.ts +67 -0
  29. package/dist/util/task-model-diagnostics.js +118 -0
  30. package/node_modules/@undefineds.co/ai-connections/dist/AiApiKeyPool.d.ts +1 -0
  31. package/node_modules/@undefineds.co/ai-connections/dist/AiApiKeyPool.js +2 -1
  32. package/node_modules/@undefineds.co/ai-connections/dist/AiConnectDialog.d.ts +1 -0
  33. package/node_modules/@undefineds.co/ai-connections/dist/AiCredentialPoolSection.d.ts +1 -0
  34. package/node_modules/@undefineds.co/ai-connections/dist/AiCredentialPoolSection.js +10 -10
  35. package/node_modules/@undefineds.co/ai-connections/dist/AiGatewayKeyRow.d.ts +3 -1
  36. package/node_modules/@undefineds.co/ai-connections/dist/AiGatewayKeyRow.js +2 -2
  37. package/node_modules/@undefineds.co/ai-connections/dist/AiGatewayKeysSection.js +77 -23
  38. package/node_modules/@undefineds.co/ai-connections/dist/AiProviderCard.d.ts +1 -0
  39. package/node_modules/@undefineds.co/ai-connections/dist/AiSortableCredentialList.js +59 -59
  40. package/node_modules/@undefineds.co/ai-connections/dist/collection-runtime.js +2 -0
  41. package/node_modules/@undefineds.co/ai-connections/dist/collections.js +14 -6
  42. package/node_modules/@undefineds.co/ai-connections/dist/contract/ai-connections-client.d.ts +2 -1
  43. package/node_modules/@undefineds.co/ai-connections/dist/contract/ai-connections-client.js +1 -0
  44. package/node_modules/@undefineds.co/ai-connections/dist/contract/client/gateway-model-roles.d.ts +11 -0
  45. package/node_modules/@undefineds.co/ai-connections/dist/contract/client/gateway-model-roles.js +11 -0
  46. package/node_modules/@undefineds.co/ai-connections/dist/contract/client/normalize.d.ts +2 -1
  47. package/node_modules/@undefineds.co/ai-connections/dist/contract/client/normalize.js +12 -5
  48. package/node_modules/@undefineds.co/ai-connections/dist/contract/client/request.js +10 -2
  49. package/node_modules/@undefineds.co/ai-connections/dist/contract/client/types.d.ts +10 -0
  50. package/node_modules/@undefineds.co/ai-connections/package.json +1 -1
  51. package/node_modules/@undefineds.co/extension-sdk/dist/web.d.ts +1 -0
  52. package/node_modules/@undefineds.co/extension-sdk/package.json +1 -1
  53. package/node_modules/@undefineds.co/pod-collections/dist/index.cjs +60 -13
  54. package/node_modules/@undefineds.co/pod-collections/dist/mapping.d.ts +16 -1
  55. package/node_modules/@undefineds.co/pod-collections/dist/mapping.js +51 -0
  56. package/node_modules/@undefineds.co/pod-collections/dist/mutations.js +14 -18
  57. package/node_modules/@undefineds.co/pod-collections/package.json +1 -1
  58. package/node_modules/@undefineds.co/shared-ui/dist/list.d.ts +8 -1
  59. package/node_modules/@undefineds.co/shared-ui/dist/list.js +4 -1
  60. package/node_modules/@undefineds.co/shared-ui/dist/pod-sign-in/IdpChrome.d.ts +1 -1
  61. package/node_modules/@undefineds.co/shared-ui/dist/pod-sign-in/IdpChrome.js +2 -2
  62. package/node_modules/@undefineds.co/shared-ui/dist/pod-sign-in/IdpViews.js +2 -2
  63. package/node_modules/@undefineds.co/shared-ui/dist/pod-sign-in/PodSignInFrame.d.ts +3 -3
  64. package/node_modules/@undefineds.co/shared-ui/dist/pod-sign-in/PodSignInFrame.js +5 -5
  65. package/node_modules/@undefineds.co/shared-ui/dist/pod-sign-in/parts.d.ts +5 -5
  66. package/node_modules/@undefineds.co/shared-ui/dist/pod-sign-in/parts.js +5 -5
  67. package/node_modules/@undefineds.co/shared-ui/dist/section-header.js +1 -1
  68. package/node_modules/@undefineds.co/shared-ui/dist/theme.css +5 -32
  69. package/node_modules/@undefineds.co/shared-ui/package.json +1 -1
  70. package/node_modules/@undefineds.co/solid-sdk/package.json +1 -1
  71. package/package.json +2 -2
  72. package/static/app/assets/main.css +1 -1
  73. package/static/app/assets/main.js +1 -1
  74. package/static/dashboard/assets/AccountAuthBoundary-Dv52SZc6.js +1 -0
  75. package/static/dashboard/assets/DesktopOidcCallback-DaT_Rumf.js +1 -0
  76. package/static/dashboard/assets/DevicePages-HjclpIVm.js +2 -0
  77. package/static/dashboard/assets/ModelsPage-Be2TPd-x.js +11 -0
  78. package/static/dashboard/assets/{PaneListHeader-Dn5O0mwy.js → PaneListHeader-DtvnRmFq.js} +1 -1
  79. package/static/dashboard/assets/{PodDeletionAuthorizationPanel-D3NOG6ZM.js → PodDeletionAuthorizationPanel-BJk_8rJq.js} +3 -3
  80. package/static/dashboard/assets/PodPage-C4gzEspV.js +1 -0
  81. package/static/dashboard/assets/{SystemSettingsPage-BNQP_Yuc.js → SystemSettingsPage-HaNrP1H1.js} +1 -1
  82. package/static/dashboard/assets/TasksPage-BdO5K2L7.js +1 -0
  83. package/static/dashboard/assets/{WebDesktopEntry-vnb4CZWp.js → WebDesktopEntry-Cj9_ZfJU.js} +1 -1
  84. package/static/dashboard/assets/XpodAiConnectionsPodStore-B7gmXBmC.js +3 -0
  85. package/static/dashboard/assets/XpodShellApp-D_KY4nCW.js +4 -0
  86. package/static/dashboard/assets/{account-session-DCUmCop1.js → account-session-DlcKNG7k.js} +1 -1
  87. package/static/dashboard/assets/{button-By5Bgvmb.js → button-wslF55uZ.js} +1 -1
  88. package/static/dashboard/assets/collection-runtime-uxxgEu13.js +1 -0
  89. package/static/dashboard/assets/{createLucideIcon-bunMzPms.js → createLucideIcon-BJQl82Qk.js} +1 -1
  90. package/static/dashboard/assets/dashboard-CbJ-JkrI.css +1 -0
  91. package/static/dashboard/assets/{dashboard-mlsg3yaw.js → dashboard-Or0gnkou.js} +2 -2
  92. package/static/dashboard/assets/index-BqFeOML9.js +1 -0
  93. package/static/dashboard/assets/{index-DvMG5pHk.js → index-DgKn1twH.js} +2 -2
  94. package/static/dashboard/assets/{label-Bj03L9xs.js → label-CS6Sx6Zb.js} +1 -1
  95. package/static/dashboard/assets/list-UyhlCFKk.js +1 -0
  96. package/static/dashboard/assets/{nav-item-style-BNqWQY6p.js → nav-item-style-CW1Nnorq.js} +1 -1
  97. package/static/dashboard/assets/{pod-collections-host-KnnGFZHL.js → pod-collections-host-DjK2xf-b.js} +6 -6
  98. package/static/dashboard/assets/{safe-continuation-D9AhcWiB.js → safe-continuation-ClWAhcma.js} +1 -1
  99. package/static/dashboard/assets/{section-header-CLCzbOp_.js → section-header-CEIEcco-.js} +1 -1
  100. package/static/dashboard/assets/{setting-row-DTCec8A2.js → setting-row-CaYv3dfF.js} +1 -1
  101. package/static/dashboard/assets/xpod-remembered-login-BUF9fin1.js +310 -0
  102. package/static/dashboard/dashboard.html +2 -2
  103. package/static/settings/assets/{AccountAuthBoundary-C0og_gIA.js → AccountAuthBoundary-Chqd38oU.js} +1 -1
  104. package/static/settings/assets/{DesktopOidcCallback-C5q4oFZ0.js → DesktopOidcCallback-VUrOSM_q.js} +1 -1
  105. package/static/settings/assets/DevicePages-C6qwvWwu.js +2 -0
  106. package/static/settings/assets/ModelsPage-Ry_dObRQ.js +11 -0
  107. package/static/settings/assets/{PaneListHeader-DqVlMe2D.js → PaneListHeader-B5RkRqr4.js} +1 -1
  108. package/static/settings/assets/{PodDeletionAuthorizationPanel-DgVvarVY.js → PodDeletionAuthorizationPanel-DPM-5Izt.js} +3 -3
  109. package/static/settings/assets/PodPage-CxND6wwc.js +1 -0
  110. package/static/settings/assets/{SystemSettingsPage-Crzm_DrI.js → SystemSettingsPage-C8EdMkW7.js} +1 -1
  111. package/static/settings/assets/TasksPage-DuqptEm8.js +1 -0
  112. package/static/settings/assets/{WebDesktopEntry-BGC5eRF2.js → WebDesktopEntry-BRcyktkv.js} +1 -1
  113. package/static/settings/assets/XpodAiConnectionsPodStore-CyA_BJVC.js +3 -0
  114. package/static/settings/assets/XpodShellApp-CsivHJl0.js +4 -0
  115. package/static/settings/assets/XpodThemeProvider-CbJ-JkrI.css +1 -0
  116. package/static/settings/assets/{XpodThemeProvider-CB6LepTA.js → XpodThemeProvider-DK3pIdRG.js} +2 -2
  117. package/static/settings/assets/{account-session-BcLjCj0x.js → account-session-DJOZ03xr.js} +1 -1
  118. package/static/settings/assets/auth-callback-GIBYEz_7.js +1 -0
  119. package/static/settings/assets/{button-BObT8pTE.js → button-D3yW-2o1.js} +1 -1
  120. package/static/settings/assets/collection-runtime-DfGo25mh.js +1 -0
  121. package/static/settings/assets/{createLucideIcon-BVsUxXpZ.js → createLucideIcon-CacwLsmB.js} +1 -1
  122. package/static/settings/assets/{index-ktjMkj7-.js → index-r5KRYsKC.js} +1 -1
  123. package/static/settings/assets/{label-BrqO8_m_.js → label-MJjUmvzG.js} +1 -1
  124. package/static/settings/assets/list-Ce-5k1MX.js +1 -0
  125. package/static/settings/assets/{nav-item-style-Di2CxkDU.js → nav-item-style-ZUbL8KOZ.js} +1 -1
  126. package/static/settings/assets/{pod-collections-host-KnnGFZHL.js → pod-collections-host-DjK2xf-b.js} +6 -6
  127. package/static/settings/assets/{safe-continuation-Dx6ceJpY.js → safe-continuation-vlBZFSlU.js} +1 -1
  128. package/static/settings/assets/{section-header-Dtl7yjVr.js → section-header-DGJdEvQw.js} +1 -1
  129. package/static/settings/assets/{setting-row-BL6Hhe8N.js → setting-row-C7tuFiho.js} +1 -1
  130. package/static/settings/assets/{settings-DaRBxoZk.js → settings-CyQPih1O.js} +1 -1
  131. package/static/settings/assets/xpod-remembered-login-D-TzzT5K.js +567 -0
  132. package/static/settings/auth-callback.html +3 -3
  133. package/static/settings/settings.html +3 -3
  134. package/static/dashboard/assets/AccountAuthBoundary-BvoDydRz.js +0 -1
  135. package/static/dashboard/assets/DesktopOidcCallback-BwIj874x.js +0 -1
  136. package/static/dashboard/assets/DevicePages-jOjMcvsr.js +0 -2
  137. package/static/dashboard/assets/ModelsPage-CMTdfqBR.js +0 -11
  138. package/static/dashboard/assets/PodPage-BueBdJ9_.js +0 -1
  139. package/static/dashboard/assets/TasksPage-CxtLJiSF.js +0 -1
  140. package/static/dashboard/assets/XpodAiConnectionsPodStore-wx3Ttupm.js +0 -18
  141. package/static/dashboard/assets/XpodShellApp-5FWY8-d5.js +0 -4
  142. package/static/dashboard/assets/collection-runtime-BnomuB0E.js +0 -1
  143. package/static/dashboard/assets/dashboard-C64R553B.css +0 -1
  144. package/static/dashboard/assets/xpod-remembered-login-Dr69A0Rv.js +0 -295
  145. package/static/settings/assets/DevicePages-fyHjjucT.js +0 -2
  146. package/static/settings/assets/ModelsPage-EyOByLyE.js +0 -11
  147. package/static/settings/assets/PodPage-DY4Oi9wg.js +0 -1
  148. package/static/settings/assets/TasksPage-CfXJbnlt.js +0 -1
  149. package/static/settings/assets/XpodAiConnectionsPodStore-CXcmgKmQ.js +0 -3
  150. package/static/settings/assets/XpodShellApp-D1PS3Iut.js +0 -4
  151. package/static/settings/assets/XpodThemeProvider-C64R553B.css +0 -1
  152. package/static/settings/assets/auth-callback-DSPQ28ar.js +0 -1
  153. package/static/settings/assets/collection-runtime-DzNbdZGe.js +0 -1
  154. package/static/settings/assets/index-browser-3WfrNbcG.js +0 -273
  155. package/static/settings/assets/xpod-remembered-login-Q66DH12t.js +0 -295
@@ -1 +0,0 @@
1
- import{r as c,j as t}from"./dashboard-mlsg3yaw.js";import{v as U,w as Q,F as J,t as ie,x as re,y as se,A as oe}from"./xpod-remembered-login-Dr69A0Rv.js";import{f as le,g as de}from"./XpodAiConnectionsPodStore-wx3Ttupm.js";import{g as I,u as X,l as ce}from"./XpodShellApp-5FWY8-d5.js";import{D as ue,j as ge,k as fe,l as me,m as be,n as he,o as pe}from"./PodDeletionAuthorizationPanel-D3NOG6ZM.js";import{B as C}from"./button-By5Bgvmb.js";import{S as G,B as xe}from"./section-header-CLCzbOp_.js";import{S as ve}from"./setting-row-DTCec8A2.js";import"./createLucideIcon-bunMzPms.js";import"./account-session-DCUmCop1.js";import"@comunica/query-sparql-solid";import"./safe-continuation-D9AhcWiB.js";import"./nav-item-style-BNqWQY6p.js";function O(e){return e.map(n=>{const s=U(n)??U(n.toLowerCase().replaceAll("-","_"));return s?Q(s)??n:n})}function W(e,n){const s={chatModel:"chat",ocrModel:"vision",readerModel:"document_understanding",embeddingModel:"embedding",indexerModel:"indexing",rerankerModel:"reranking"}[n];return e.filter(i=>O(i.capabilities).includes(s))}function we(e,n){const s=W(e,"embeddingModel");return n?.restricted?s.filter(i=>n.allowed.some(o=>o.provider===i.owner&&o.model===i.id)):s}const N="flex min-h-14 flex-wrap items-center justify-between gap-3 border-b border-border py-3",ye={queued:"排队中",running:"进行中",succeeded:"已完成",failed:"失败"};function Ee(e){const[n,s]=c.useState(!1),[i,o]=c.useState("platform"),[d,g]=c.useState(""),[v,u]=c.useState(),[w,h]=c.useState(!1),[b,E]=c.useState("all"),p=async(r,a="已保存")=>{h(!0),u(void 0);try{await r(),u(a)}catch{u("操作未完成,请重试。")}finally{h(!1)}},f=e.busy||w,j=r=>r.map(a=>t.jsx(ve,{label:a.label,description:a.description,control:({id:l,"aria-describedby":y})=>t.jsx(ie,{id:l,"aria-describedby":y,checked:a.checked,disabled:f,onChange:A=>{p(()=>e.onToggle(a.id,A.target.checked))}})},a.id));return t.jsx(ue,{open:n,onOpenChange:r=>{f||s(r)},children:t.jsxs("div",{className:"mx-auto max-w-4xl space-y-6 p-6",children:[(v||e.error)&&t.jsx("p",{role:"status",className:"text-sm leading-normal",children:e.error?"Pod 设置暂时无法保存,请重试。":v}),e.section==="models"&&t.jsxs("section",{"aria-label":"默认模型",children:[t.jsx("p",{className:"text-sm leading-normal text-muted-foreground",children:"应用没有指定模型时用这里的默认值,随时可以改。"}),Array.from(new Set(e.models.map(r=>r.group))).map(r=>t.jsxs("section",{className:"mt-5",children:[t.jsx("h2",{className:"text-xs leading-normal text-muted-foreground",children:r}),e.models.filter(a=>a.group===r).map(a=>t.jsxs("div",{className:N,children:[t.jsx("label",{htmlFor:`pod-model-${a.id}`,className:"min-w-28 text-sm leading-normal",children:a.label}),a.id==="embeddingModel"?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"flex-1 text-sm leading-normal",children:e.embeddingLabel}),t.jsx(C,{variant:"outline",size:"sm",onClick:()=>e.onSection("search"),children:"去更换 ›"})]}):a.models?t.jsxs(t.Fragment,{children:[t.jsxs(I,{id:`pod-model-${a.id}`,className:"min-w-[10ch] flex-1",value:a.value??"",disabled:f,onChange:l=>{p(()=>e.onModel(a.id,l.target.value))},children:[t.jsx("option",{value:"",children:a.defaultLabel}),a.value&&!a.models.some(l=>l.ref===a.value)&&t.jsx("option",{value:a.value,children:"当前模型(暂不可用)"}),a.models.map(l=>t.jsx("option",{value:l.ref,children:l.label},l.ref))]}),a.testable?t.jsx(C,{variant:"outline",size:"sm",disabled:f||!a.value,onClick:()=>{p(()=>e.onTest(a.id,a.value),"测试通过")},children:"测试"}):t.jsx(T,{}),a.models.length===0&&e.freeQuotaUrl&&t.jsx("a",{href:e.freeQuotaUrl,className:"text-sm leading-normal text-primary",children:"领免费额度 ›"})]}):t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"flex-1 text-sm leading-normal text-muted-foreground",children:a.defaultLabel}),t.jsx(T,{})]})]},a.id))]},r))]}),e.section==="search"&&t.jsxs(t.Fragment,{children:[t.jsxs("section",{"aria-label":"检索",children:[j(e.search),t.jsxs("div",{className:N,children:[t.jsxs("span",{className:"text-sm leading-normal",children:["语义检索用的 Embedding",t.jsx("br",{}),t.jsx("span",{className:"text-xs leading-normal text-muted-foreground",children:e.embeddingLabel})]}),t.jsx(ge,{asChild:!0,children:t.jsx(C,{variant:"outline",size:"sm",disabled:f||!e.canChangeEmbedding,onClick:()=>{g(""),o("platform")},children:"更换"})})]})]}),t.jsxs("section",{"aria-label":"索引",children:[t.jsx(G,{level:2,title:"索引",titleClassName:"font-semibold",description:t.jsxs(t.Fragment,{children:["待处理 ",e.pending??0," · 配置版本 ",e.version??"默认"]}),actions:t.jsxs(t.Fragment,{children:[t.jsxs(I,{"aria-label":"重建哪部分",className:"min-w-[10ch] w-auto",value:b,onChange:r=>E(r.target.value),children:[t.jsx("option",{value:"all",children:"重建全部"}),t.jsx("option",{value:"fts",children:"只重建全文"}),t.jsx("option",{value:"vector",children:"只重建向量"})]}),t.jsx(C,{variant:"outline",size:"sm",disabled:f||!e.rebuildTargets.includes(b),onClick:()=>{p(()=>e.onRebuild(b),"重建已排队")},children:"重建"})]})}),e.jobs.length?e.jobs.map(r=>t.jsxs("div",{className:N,children:[t.jsx("span",{className:"text-sm leading-normal",children:r.label}),t.jsxs("span",{className:"text-sm leading-normal",children:[ye[r.status],r.progress===void 0?"":` · ${r.progress}%`]})]},r.id)):t.jsx("p",{className:"py-4 text-sm leading-normal text-muted-foreground",children:"还没有重建记录"}),j(e.maintenance),t.jsx("p",{className:"mt-3 text-xs leading-normal text-muted-foreground",children:"重建只重算索引,不改动 Pod 里的原始资料。"})]}),e.error?.includes("service_access_missing")&&t.jsx(C,{variant:"outline",size:"sm",disabled:f||e.backgroundAccess.busy,onClick:()=>{p(e.onGrant,"已允许 Xpod 访问")},children:"允许 Xpod 访问"})]}),e.section==="apps"&&t.jsxs("section",{"aria-label":"授权应用",children:[t.jsx("p",{className:"text-sm leading-normal text-muted-foreground",children:"哪些应用和服务能读写这个 Pod。"}),t.jsxs("div",{className:N,children:[t.jsxs("details",{className:"flex-1",children:[t.jsxs("summary",{className:"cursor-pointer text-sm leading-normal font-medium",children:["Xpod 后台访问 · ",e.backgroundAccess.loading?"读取中":e.backgroundAccess.granted?"已授权":"未授权"]}),t.jsx("p",{className:"py-3 text-xs leading-normal text-muted-foreground",children:"用于索引维护和后台任务。流量与访问记录:待接入。"})]}),e.backgroundAccess.granted?t.jsxs("details",{children:[t.jsx("summary",{"aria-label":"Xpod 后台访问的更多操作",className:"cursor-pointer p-2",children:"⋯"}),t.jsx("span",{className:"block py-2 text-xs leading-normal text-muted-foreground",children:"修改权限 · 待接入"}),t.jsx(C,{variant:"outline",size:"sm",disabled:f||e.backgroundAccess.busy,onClick:()=>{p(e.onRevoke,"已撤销授权")},children:"撤销"})]}):t.jsx(C,{variant:"outline",size:"sm",disabled:f||e.backgroundAccess.busy||e.backgroundAccess.loading,onClick:()=>{p(e.onGrant,"已允许 Xpod 访问")},children:"允许"})]}),e.backgroundAccess.error&&t.jsx("p",{role:"alert",className:"text-sm leading-normal",children:"授权操作暂时不可用,请重试。"}),t.jsx("p",{className:"mt-4 text-xs leading-normal text-muted-foreground",children:"其他授权应用 · 待接入"})]}),e.section==="data"&&t.jsxs(t.Fragment,{children:[t.jsxs("section",{"aria-label":"用量",children:[t.jsx(G,{level:2,title:"用量",titleClassName:"font-semibold"}),t.jsx("div",{className:"mt-3 grid grid-cols-2 gap-3",children:e.usage.map(r=>t.jsxs("div",{className:"rounded-xl border border-border p-4",children:[t.jsx("span",{className:"block text-xs leading-normal text-muted-foreground",children:r.label}),t.jsx("span",{className:"mt-2 block text-sm leading-normal",children:r.value})]},r.label))})]}),t.jsx("section",{"aria-label":"数据管理",children:["导入","导出","迁移"].map(r=>t.jsxs("div",{className:N,children:[t.jsx("span",{className:"text-sm leading-normal",children:r}),t.jsx(T,{}),r==="迁移"&&e.accountUrl&&t.jsx("a",{className:"text-sm leading-normal text-primary",href:e.accountUrl,children:"管理账号 ↗"})]},r))})]}),t.jsxs(fe,{closeLabel:"关闭",closeDisabled:f,className:"max-h-[90dvh] w-[calc(100%-2rem)] overflow-y-auto",onEscapeKeyDown:r=>{f&&r.preventDefault()},onInteractOutside:r=>{f&&r.preventDefault()},children:[t.jsx(me,{children:t.jsx(be,{children:"更换语义检索模型"})}),t.jsx(J,{label:"来源",children:r=>t.jsxs(I,{...r,value:i,disabled:f,onChange:a=>{o(a.target.value),g("")},children:[t.jsx("option",{value:"platform",children:"Xpod 提供"}),t.jsx("option",{value:"own",children:"用我自己的 Key"})]})}),t.jsx(J,{label:"模型",children:r=>t.jsxs(I,{...r,value:d,disabled:f,onChange:a=>g(a.target.value),children:[t.jsx("option",{value:"",children:"请选择"}),e.embeddingModels.filter(a=>a.source===i).map(a=>t.jsx("option",{value:a.ref,children:a.label},a.ref))]})}),!e.embeddingModels.some(r=>r.source===i)&&t.jsx("p",{className:"text-xs leading-normal text-muted-foreground",children:i==="platform"?"Xpod 提供的模型目录 · 待接入":"暂无可用向量模型,请先在 AI 连接中添加。"}),t.jsx(he,{children:"更换后会重建全部语义索引,重建期间只能全文检索。"}),t.jsxs(pe,{className:"gap-2",children:[t.jsx(C,{variant:"outline",disabled:f,onClick:()=>s(!1),children:"取消"}),t.jsx(C,{disabled:f||!e.canChangeEmbedding||!e.embeddingModels.some(r=>r.ref===d&&r.source===i),onClick:()=>{p(async()=>{await e.onEmbedding(d),s(!1)},"更换已保存,重建已排队")},children:"更换并重建索引"})]})]})]})})}function T(){return t.jsx(xe,{variant:"pending",className:"font-normal",children:"待接入"})}async function V(e){return Y(e(P("/api/ai/config"),{method:"GET",credentials:"include",headers:{accept:"application/json"}}))}async function je(e,n){return Y(e(P("/api/ai/config"),{method:"PATCH",credentials:"include",headers:{accept:"application/json","content-type":"application/json"},body:JSON.stringify(n)}))}async function Ce(e,n){const s=await e(P("/api/ai/config/rebuild"),{method:"POST",credentials:"include",headers:{accept:"application/json","content-type":"application/json"},body:JSON.stringify({target:n})}),i=await s.json().catch(()=>{});if(!s.ok||!i?.job)throw new Error(i?.error??"Index rebuild request failed");return i.job}async function Fe(e,n){const s=n.capabilities.some(o=>o.toLowerCase()==="embedding"),i=await e(P(s?"/v1/embeddings":"/v1/chat/completions"),{method:"POST",credentials:"include",headers:{accept:"application/json","content-type":"application/json"},body:JSON.stringify(s?{model:n.id,input:"xpod readiness probe"}:{model:n.id,messages:[{role:"user",content:"Reply OK."}],max_tokens:1,stream:!1})});if(!i.ok){const o=await i.json().catch(()=>{}),d=typeof o?.error=="string"?o.error:o?.error?.message;throw new Error(d??"Model readiness probe failed")}await i.arrayBuffer()}function P(e){if(typeof window>"u")throw new Error("AI Config API requires the current browser origin");return new URL(e,window.location.origin).toString()}async function Y(e){const n=await e,s=await n.json().catch(()=>{});if(!n.ok||!s?.config||!s.capabilities)throw new Error(s?.error??"AI Config request failed");return s}const Z=c.createContext(void 0),Ae=2e3;function ke({children:e}){const n=X(),[s,i]=c.useState(),[o,d]=c.useState(),[g,v]=c.useState([]),[u,w]=c.useState(),[h,b]=c.useState(!0),[E,p]=c.useState(!1),[f,j]=c.useState(!1),[r,a]=c.useState(),[l,y]=c.useState(0),A=!!(n.webId&&n.currentPod);c.useEffect(()=>{if(!n.webId||!n.currentPod)return;let x=!1;return queueMicrotask(()=>{if(x||!n.webId||!n.currentPod)return;b(!0),a(void 0);const m=le({webId:n.webId,podUrl:n.currentPod.podUrl,authenticatedFetch:n.fetch}),ae=de({database:n.currentPod.database,authenticatedFetch:n.fetch,podUrl:n.currentPod.podUrl,webId:n.currentPod.webId}).listModels?.()?.catch(()=>[])??Promise.resolve([]);Promise.all([V(n.fetch),m.listModels().catch(()=>[]),ae]).then(([k,ne,te])=>{x||(i(k.config),d(k.capabilities),w(k.lifecycle),v(Be(De(te,ne))))}).catch(k=>{x||a(k instanceof Error?k.message:String(k))}).finally(()=>{x||b(!1)})}),()=>{x=!0}},[l,n.currentPod,n.fetch,n.webId]);const B=c.useCallback(()=>{y(x=>x+1)},[]),S=u?.pending??0;c.useEffect(()=>{if(S<=0||!n.webId||!n.currentPod)return;let x=!1;const m=setInterval(()=>{V(n.fetch).then(D=>{x||w(D.lifecycle)}).catch(()=>{})},Ae);return()=>{x=!0,clearInterval(m)}},[S,n.currentPod,n.fetch,n.webId]);const F=c.useCallback(async x=>{p(!0),a(void 0);try{const m=await je(n.fetch,x);i(m.config),d(m.capabilities),w(m.lifecycle)}catch(m){throw a(m instanceof Error?m.message:String(m)),m}finally{p(!1)}},[n.fetch]),M=c.useCallback(async x=>{j(!0),a(void 0);try{const m=await Ce(n.fetch,x);w(D=>({configurationVersion:D?.configurationVersion,pending:(D?.pending??0)+1,recent:[m,...D?.recent??[]].slice(0,20)}))}catch(m){throw a(m instanceof Error?m.message:String(m)),m}finally{j(!1)}},[n.fetch]),z=c.useCallback(async(x,m)=>{await F(x),await M(m)},[M,F]),K=A?h:!1,ee=c.useMemo(()=>({config:s,capabilities:o,lifecycle:u,models:g,loading:K,saving:E,rebuilding:f,error:r,reload:B,save:F,rebuild:M,saveAndRebuild:z}),[o,s,K,r,u,g,M,f,B,F,z,E]);return t.jsx(Z.Provider,{value:ee,children:e})}function De(e,n){const s=new Map,i=o=>`${o.provider}\0${L(o.id)}`;for(const o of[...e,...n]){const d=i(o),g=s.get(d);if(!g){s.set(d,{...o,id:L(o.id)});continue}const v=[...new Set([...g.capabilities??[],...o.capabilities??[]])];s.set(d,{...g,...o,id:L(o.id),resourceId:g.resourceId??o.resourceId,displayName:g.displayName??o.displayName,availability:g.availability==="available"?g.availability:o.availability,modelType:g.modelType??o.modelType,...v.length>0?{capabilities:v}:{},...g.inputModalities??o.inputModalities?{inputModalities:g.inputModalities??o.inputModalities}:{}})}return[...s.values()]}function L(e){const n=e.lastIndexOf("#");return n>=0?e.slice(n+1):e}function Be(e){return e.map(n=>{const s=[...n.capabilities??[]],i=n.modelType?re(n.modelType):void 0,o=i?oe[i]:void 0;return o&&!s.some(d=>U(d)===o)&&s.push(Q(o)),{id:n.id,displayName:n.displayName,owner:n.provider,ref:se(n.provider,n.id),capabilities:s}})}function Se(){const e=c.useContext(Z);if(!e)throw new Error("useAiConfig must be used within AiConfigProvider");return e}function H(e,n=!1){if(n)return!0;const s=Me(e)?.phase;return s==="queued"||s==="running"}function Ne(e){const n=e?.rebuildTargets??[];if(n.includes("vector"))return"vector";if(n.includes("all"))return"all"}function Me(e){if(!e)return;const n=e.recent[0];if(!n)return e.pending>0?{phase:"queued",pending:e.pending}:void 0;if(!(n.status==="queued"&&e.pending<=0))return{phase:n.status,pending:e.pending,target:n.target,...n.progress!==void 0?{progress:n.progress}:{},...n.error?{error:n.error}:{}}}function _(e,n){const s=n??(typeof window>"u"?void 0:window.location.origin);if(!s)throw new Error("task credential request needs a current browser origin");return new URL(e,s).toString()}async function $(e){const n=await e.text().catch(()=>"");if(n)try{const s=JSON.parse(n);return s&&typeof s=="object"&&!Array.isArray(s)?s:void 0}catch{return}}function q(e,n){const s=e?.error;return typeof s=="string"&&s?s:n}async function Ie(e){const n=await e.fetch(_("/api/ai/task-credentials",e.origin),{method:"GET",credentials:"include",headers:{accept:"application/json"}}),s=await $(n);if(!n.ok)throw new Error(q(s,"Task credential request failed"));const i=s?.data;return Array.isArray(i)?i:[]}async function Pe(e){const n=await e.fetch(_("/api/ai/task-credentials",e.origin),{method:"POST",credentials:"include",headers:{accept:"application/json","content-type":"application/json"},body:JSON.stringify({apiKey:e.apiKey,...e.name?{name:e.name}:{}})}),s=await $(n);if(!n.ok)throw new Error(q(s,"Task credential grant failed"));const i=s?.credential;if(!i||typeof i!="object")throw new Error("Task credential grant returned no grant");return i}async function Te(e){const n=await e.fetch(_(`/api/ai/task-credentials/${encodeURIComponent(e.credentialRef)}`,e.origin),{method:"DELETE",credentials:"include",headers:{accept:"application/json"}});if(!n.ok)throw new Error(q(await $(n),"Task credential revocation failed"))}function Le(e,n){return e.filter(s=>s.status==="active"&&(!n||s.issuer===n)).sort((s,i)=>i.version-s.version)[0]}function Re(e,n){return e?`${e}\0${n??""}`:void 0}function R(e){return e instanceof Error?e.message:String(e)}const Ue=()=>({loaded:!1,working:!1});function Oe(){const e=X(),{fetch:n,issuer:s,requestPodApiKey:i,webId:o}=e,d=Re(o,s),[g,v]=c.useState(()=>({scope:d,generation:0}));g.scope!==d&&v({scope:d,generation:g.generation+1});const{generation:u}=g,w=c.useRef(u);c.useLayoutEffect(()=>{w.current=u},[u]);const h=g.scope===d?g.entry:void 0,b=c.useCallback((r,a)=>{v(l=>l.generation===r?{...l,entry:a(l.entry??Ue())}:l)},[]),E=c.useCallback(r=>Ie({fetch:n}).then(a=>{b(r,l=>({...l,credential:Le(a,s),loaded:!0,error:void 0}))}).catch(a=>{b(r,l=>({...l,loaded:!0,error:R(a)}))}),[s,n,b]);c.useEffect(()=>{d!==void 0&&E(u)},[u,E,d]);const p=c.useCallback(async()=>{d!==void 0&&await E(u)},[u,E,d]),f=c.useCallback(async()=>{if(d===void 0)return;const r=u;b(r,a=>({...a,working:!0,error:void 0}));try{const a=await i?.();if(!a)throw new Error("当前会话无法准备凭据");if(w.current!==r)throw new Error("会话已改变,本次授权已取消");const l=await Pe({fetch:n,apiKey:a,name:"Xpod 后台任务"});b(r,y=>({...y,credential:l,loaded:!0,working:!1,error:void 0}))}catch(a){throw b(r,l=>({...l,loaded:!0,working:!1,error:R(a)})),a}},[u,i,n,d,b]),j=c.useCallback(async()=>{if(d===void 0||!h?.credential)return;const r=u,a=h.credential.credentialRef;b(r,l=>({...l,working:!0,error:void 0}));try{await Te({fetch:n,credentialRef:a}),b(r,l=>({...l,credential:void 0,loaded:!0,working:!1,error:void 0}))}catch(l){throw b(r,y=>({...y,loaded:!0,working:!1,error:R(l)})),l}},[h,u,n,d,b]);return{...h?.credential?{credential:h.credential}:{},loading:d!==void 0&&h?.loaded!==!0,working:h?.working===!0,...h?.error?{error:h.error}:{},grant:f,revoke:j,reload:p}}function ea(e){return t.jsx(ke,{children:t.jsx(Xe,{...e})})}function Xe({section:e,onSection:n,accountUrl:s}){const i=Se(),o=X(),d=Oe(),[g,v]=c.useState();if(c.useEffect(()=>{let a=!1;if(!(e!=="data"||!o.webId||!o.currentPod))return ce({webId:o.webId,podUrl:o.currentPod.podUrl,authenticatedFetch:o.fetch}).then(l=>{a||v({webId:o.webId,podUrl:o.currentPod.podUrl,value:l.storage})}).catch(()=>{a||v({webId:o.webId,podUrl:o.currentPod.podUrl,value:{status:"error"}})}),()=>{a=!0}},[e,o.webId,o.currentPod,o.fetch]),(e==="models"||e==="search")&&!i.config)return t.jsxs("div",{className:"p-6 text-sm",children:[i.loading?"正在读取 Pod 设置…":"暂时无法读取 Pod 设置。",!i.loading&&(i.error?.includes("service_access_missing")?t.jsx("button",{className:"ml-3 text-primary",disabled:d.working||d.loading,onClick:()=>{d.grant().then(i.reload).catch(()=>{})},children:"允许 Xpod 访问"}):t.jsx("button",{className:"ml-3 text-primary",onClick:i.reload,children:"重试"}))]});const u=i.config,w=a=>({ref:a.ref,label:`${a.displayName??a.id} · ${a.owner}`,capabilities:a.capabilities,source:"own"}),h=(a,l,y,A)=>{const B=W(i.models,a),S=B.find(F=>F.ref===u?.models[a]);return{id:a,label:l,group:y,defaultLabel:A,value:u?.models[a],models:B.map(w),testable:!!(S&&O(S.capabilities).some(F=>["chat","embedding"].includes(F)))}},b=[h("chatModel","智能","对话","Xpod 提供"),{id:"fast",label:"快速",group:"对话",defaultLabel:"Xpod 提供"},h("ocrModel","视觉辅助","对话","不使用"),h("readerModel","文档理解","文档理解","PaddleOCR · 百度(Xpod 提供)"),{id:"embeddingModel",label:"语义检索",group:"向量",defaultLabel:""},...["语音合成","语音识别"].map(a=>({id:a,label:a,group:"语音",defaultLabel:"不使用"})),...["图像生成","视频生成"].map(a=>({id:a,label:a,group:"图像与视频",defaultLabel:"不使用"})),{id:"decision",label:"决策",group:"决策",defaultLabel:"不使用"}],E=i.models.find(a=>a.ref===u?.models.embeddingModel),p=Ne(i.capabilities),f=async(a,l)=>{a==="ftsEnabled"||a==="vectorEnabled"||a==="progressiveIndexingEnabled"?await i.save({searchIndexing:{[a]:l}}):(a==="automaticIndexing"||a==="refreshAfterSourceUpdate"||a==="removeAfterSourceDeletion")&&await i.save({lifecycle:{[a]:l}})},j=g?.webId===o.webId&&g?.podUrl===o.currentPod?.podUrl?g?.value:void 0,r=j?.status==="available"?j.usage:void 0;return t.jsx(Ee,{section:e,onSection:n,accountUrl:s,busy:i.saving||i.rebuilding,error:i.error,models:b,embeddingLabel:E?w(E).label:u?.models.embeddingModel?"当前模型暂不可用":"Xpod 提供",embeddingValue:u?.models.embeddingModel,embeddingModels:we(i.models,i.capabilities?.embeddingModels).map(w),canChangeEmbedding:!!p&&!H(i.lifecycle,i.rebuilding),search:[{id:"ftsEnabled",label:"全文检索",checked:u?.searchIndexing.ftsEnabled??!1},{id:"vectorEnabled",label:"语义检索",checked:u?.searchIndexing.vectorEnabled??!1,description:"资料片段会发给向量模型的服务商。"},{id:"progressiveIndexingEnabled",label:"渐进式索引",checked:u?.searchIndexing.progressiveIndexingEnabled??!1}],maintenance:[{id:"automaticIndexing",label:"自动索引新资料",checked:u?.lifecycle.automaticIndexing??!1},{id:"refreshAfterSourceUpdate",label:"资料更新后刷新索引",checked:u?.lifecycle.refreshAfterSourceUpdate??!1},{id:"removeAfterSourceDeletion",label:"资料删除后清理索引",checked:u?.lifecycle.removeAfterSourceDeletion??!1}],pending:i.lifecycle?.pending,version:i.lifecycle?.configurationVersion,jobs:(i.lifecycle?.recent??[]).map(a=>({id:a.id,label:{all:"全部索引",fts:"全文索引",vector:"语义索引"}[a.target],status:a.status,progress:a.progress})),rebuildTargets:i.capabilities?.rebuildTargets??[],onRebuild:i.rebuild,backgroundAccess:{granted:!!d.credential,loading:d.loading,busy:d.working,error:d.error},onGrant:d.grant,onRevoke:d.revoke,usage:[{label:"存储",value:r?`${(r.storageBytes/1024/1024).toFixed(1)} MiB`:"—"},{label:"流量",value:r?`${((r.ingressBytes+r.egressBytes)/1024/1024).toFixed(1)} MiB`:"—"},{label:"AI 用量",value:r?`${r.tokensUsed.toLocaleString()} tokens`:"—"},{label:"计算时长",value:r?`${r.computeSeconds.toLocaleString()} 秒`:"—"}],onModel:async(a,l)=>{(a==="chatModel"||a==="ocrModel"||a==="readerModel")&&await i.save({models:{[a]:l||null}})},onTest:async(a,l)=>{const y=i.models.find(A=>A.ref===l);if(!y)throw new Error("Model unavailable");await Fe(o.fetch,{...y,capabilities:O(y.capabilities)})},onToggle:f,onEmbedding:async a=>{if(!p||H(i.lifecycle,i.rebuilding))throw new Error("Rebuild unavailable");a===u?.models.embeddingModel?await i.rebuild(p):await i.saveAndRebuild({models:{embeddingModel:a}},p)}})}export{ea as default};
@@ -1 +0,0 @@
1
- import{r as i,j as e,u as ve,a as Ee}from"./dashboard-mlsg3yaw.js";import{I as Z,S as Fe,g as be,u as ke,h as Ce,i as Ae,A as Be,j as we,k as De}from"./XpodShellApp-5FWY8-d5.js";import{i as ye,I as P}from"./PodDeletionAuthorizationPanel-D3NOG6ZM.js";import{T as Ne,u as te,W as Se}from"./nav-item-style-BNqWQY6p.js";import{c as ee,B as E,i as L}from"./button-By5Bgvmb.js";import{t as Te}from"./xpod-remembered-login-Dr69A0Rv.js";import"./account-session-DCUmCop1.js";import"./safe-continuation-D9AhcWiB.js";import"./createLucideIcon-bunMzPms.js";const ae=i.forwardRef(({className:s,...u},c)=>e.jsx("textarea",{ref:c,className:ee(ye,"min-h-20 resize-y",s),...u}));ae.displayName="Textarea";const ze={sm:"min-h-9 px-2.5 text-xs [@media(pointer:coarse)]:min-h-11",md:"min-h-9 px-3 text-sm [@media(pointer:coarse)]:min-h-11"},Le="bg-card font-semibold text-primary shadow-sm",Ie="text-foreground hover:text-primary";function se({value:s,onValueChange:u,options:c,ariaLabel:d,name:o,size:p="md",className:n,onKeyDown:x,...m}){const h=i.useId(),b=o??h,A=i.useRef([]),k=c.findIndex(r=>r.value===s),F=c.map((r,j)=>r.disabled?-1:j).filter(r=>r>=0),f=k>=0&&!c[k]?.disabled?k:F[0],_=r=>{const j=c[r];!j||j.disabled||(A.current[r]?.focus(),j.value!==s&&u(j.value))},N=(r,j)=>{if(F.length===0)return;const C=F.indexOf(r),y=C<0?j>0?0:F.length-1:(C+j+F.length)%F.length;_(F[y])},W=r=>{if(x?.(r),r.defaultPrevented)return;const j=A.current.findIndex(y=>y===document.activeElement),C=j>=0?j:f;switch(r.key){case"ArrowRight":case"ArrowDown":r.preventDefault(),N(C,1);break;case"ArrowLeft":case"ArrowUp":r.preventDefault(),N(C,-1);break;case"Home":r.preventDefault(),N(-1,1);break;case"End":r.preventDefault(),N(-1,-1);break}};return e.jsx("div",{role:"radiogroup","aria-label":d,className:ee("inline-flex items-center gap-0.5 rounded-lg bg-muted p-0.5",n),onKeyDown:W,...m,children:c.map((r,j)=>{const C=r.value===s,y=r["aria-label"];return e.jsxs("label",{className:ee("relative inline-flex min-w-0 grow cursor-pointer select-none items-center justify-center gap-1.5 rounded-md transition-colors",ze[p],C?Le:Ie,r.disabled&&"cursor-not-allowed opacity-50"),children:[e.jsx("input",{ref:$=>{A.current[j]=$},type:"radio",className:"absolute inset-0 m-0 h-full w-full cursor-pointer appearance-none opacity-0 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring disabled:cursor-not-allowed",name:b,value:r.value,checked:C,disabled:r.disabled,tabIndex:j===f?0:-1,"aria-label":y,onChange:()=>_(j)}),r.icon?e.jsx("span",{"aria-hidden":"true",className:"inline-flex shrink-0 items-center",children:r.icon}):null,r.label?e.jsx("span",{className:"min-w-0 break-words text-center",children:r.label}):null]},r.value)})})}const q=s=>["completed","failed","cancelled"].includes(s.status),B=(s,u)=>s.assignedTo===u;function $e(s,u,c,d){const o=s.filter(n=>c==="all"||(c==="mine"?B(n,u):!!n.assignedTo&&!B(n,u))),p=o.filter(n=>!q(n));return{waiting:p.filter(n=>n.waiting),mine:p.filter(n=>!n.waiting&&B(n,u)).sort((n,x)=>(n.dueAt??1/0)-(x.dueAt??1/0)||n.createdAt-x.createdAt),ai:p.filter(n=>!n.waiting&&!!n.assignedTo&&!B(n,u)),unassigned:p.filter(n=>!n.waiting&&!n.assignedTo),recent:o.filter(n=>q(n)&&n.completedAt!==void 0&&n.completedAt>=d-7*86400),ended:o.filter(q)}}function Me(s,u,c){const d=new Date(c.getFullYear(),c.getMonth(),c.getDate()),o=new Date(d);o.setDate(o.getDate()+1);const p=new Date(d);p.setDate(p.getDate()+2);const n=new Date(d);n.setDate(n.getDate()+(7-(d.getDay()+6)%7));const x={overdue:[],today:[],tomorrow:[],week:[],later:[]};for(const m of s.filter(h=>!q(h))){const h=B(m,u)?m.dueAt:m.schedule?.kind==="cron"||m.schedule?.kind==="once"?m.schedule.nextRunAt:void 0;if(h===void 0)continue;const b=h*1e3,A=b<+d?"overdue":b<+o?"today":b<+p?"tomorrow":b<+n?"week":"later";x[A].push(m)}for(const m of Object.values(x))m.sort((h,b)=>(h.dueAt??h.schedule?.nextRunAt??0)-(b.dueAt??b.schedule?.nextRunAt??0));return x}const ce={createAi:!1,resumeStep:!1,handoff:!1,approve:!1},U={open:"待办",active:"按计划运行",blocked:"已暂停",completed:"已完成",failed:"失败",cancelled:"已取消",running:"进行中",queued:"等待执行",waiting_input:"在等你",waiting_runner:"等待执行环境"},I={cron:"定时",interval:"周期",event:"事件",once:"定时"},V=s=>s===void 0?"未设置":new Date(s*1e3).toLocaleString("zh-CN",{month:"numeric",day:"numeric",hour:"2-digit",minute:"2-digit"}),Re=s=>{const u=/^(\d+) (\d+) \* \* \*$/.exec(s??"");return u?`每天 ${u[2].padStart(2,"0")}:${u[1].padStart(2,"0")}`:"自定义计划"},oe=s=>s&&/^https?:\/\//.test(s)?s:void 0;function Pe({client:s,webId:u,workspace:c,onOpenConnections:d,selectedTaskId:o,selectedRunId:p,renderApproval:n,headerActions:x}){const[m,h]=i.useState([]),[b,A]=i.useState(ce),[k,F]=i.useState(),[f,_]=i.useState("all"),[N,W]=i.useState("list"),[r,j]=i.useState(""),[C,y]=i.useState(""),[$,he]=i.useState(!1),[M,me]=i.useState(!1),[ne,R]=i.useState(!1),[ue,H]=i.useState([]),[v,T]=i.useState(),[O,K]=i.useState(),[pe,X]=i.useState([]),[Y,S]=i.useState(""),[w,ie]=i.useState(!1),[xe,le]=i.useState(!0),G=async()=>{const t=await s.list();h(t.tasks),A(t.capabilities)};i.useEffect(()=>{let t=!0;return le(!0),h([]),A(ce),F(void 0),K(void 0),S(""),s.list().then(a=>{t&&(h(a.tasks),A(a.capabilities))}).catch(a=>{t&&S(String(a.message??a))}).finally(()=>{t&&le(!1)}),()=>{t=!1}},[s,u]),i.useEffect(()=>{let t=!0;return H([]),T(void 0),X([]),k&&s.runs(k).then(a=>{t&&(H(a.runs),O&&T(a.runs.find(Q=>Q.id===O.id)??O))}).catch(a=>{t&&S(String(a.message??a))}),()=>{t=!1}},[s,k,O]),i.useEffect(()=>{let t=!0;return X([]),v&&s.steps(v.id).then(a=>{t&&X(a.steps)}).catch(a=>{t&&S(String(a.message??a))}),()=>{t=!1}},[s,v?.id]),i.useEffect(()=>{if(!o)return;const t=m.find(a=>a.id===o||a.iri===o);t&&(F(t.id),R(!1))},[o,m]),i.useEffect(()=>{let t=!0;return p&&s.selection(p).then(a=>{t&&(F(a.taskId),K(a.run),R(!1))}).catch(a=>{t&&S(String(a.message??a))}),()=>{t=!1}},[s,p]);const D=async t=>{if(!w){ie(!0),S("");try{await t(),await G()}catch(a){S(a instanceof Error?a.message:String(a))}finally{ie(!1)}}},l=m.find(t=>t.id===k),re=m.filter(t=>`${t.title??""} ${t.instruction}`.toLowerCase().includes(r.toLowerCase())),g=$e(re,u,f,Date.now()/1e3),fe=Me(re.filter(t=>f==="all"||(f==="mine"?B(t,u):!!t.assignedTo&&!B(t,u))),u,new Date),J=t=>{F(t.id),K(void 0),R(!1)},z=t=>t.map(a=>e.jsxs("div",{className:`task-row ${k===a.id?"selected":""}`,children:[B(a,u)?e.jsx(Te,{"aria-label":`完成 ${a.title??a.instruction}`,checked:a.status==="completed",disabled:w,onChange:Q=>{D(()=>s.update(a.id,{completed:Q.target.checked}))}}):e.jsx("span",{"aria-label":I[a.schedule?.kind??""]??"任务",children:a.schedule?.kind==="event"?"ϟ":a.schedule?.kind==="interval"?"↻":"▦"}),e.jsxs(qe,{onClick:()=>J(a),"aria-current":k===a.id?"true":void 0,children:[e.jsx("strong",{children:a.title??a.instruction}),e.jsx("small",{children:a.waiting?"在等你":a.dueAt?V(a.dueAt):U[a.status]??a.status})]})]},a.id)),je=t=>{t.preventDefault(),C.trim()&&D(async()=>{const a=await s.create({prompt:C.trim(),kind:"todo",workspace:c});y(""),J(a.task)})},ge=e.jsxs("form",{onSubmit:je,className:"task-quick-add",children:[e.jsx("span",{"aria-hidden":!0,children:"+"}),e.jsx(P,{"aria-label":"添加待办",placeholder:"添加待办,回车",value:C,onChange:t=>y(t.target.value),disabled:w})]});return e.jsx(Ne,{className:"tasks-panel",pageType:"collection",hasObjectCollection:!0,listHeader:e.jsxs("div",{className:"tasks-list-header",children:[e.jsx(Fe,{"aria-label":"搜索任务",value:r,onChange:t=>j(t.target.value)}),e.jsx(E,{size:"sm",variant:"outline",className:"h-auto min-h-9 whitespace-normal py-1",type:"button","aria-label":"新建任务",onClick:()=>{R(!0),F(void 0)},children:"+"})]}),list:e.jsxs("div",{className:"tasks-list",children:[e.jsx(_e,{selection:k??(ne?"create":void 0)}),e.jsxs("div",{className:"tasks-toolbar",children:[e.jsx(se,{className:"flex-1",size:"sm",ariaLabel:"交给谁",value:f,onValueChange:_,options:[{value:"all",label:"全部"},{value:"mine",label:"我的"},{value:"ai",label:"AI 的"}]}),e.jsx(se,{size:"sm",ariaLabel:"视图",value:N,onValueChange:W,options:[{value:"list",icon:e.jsx(Ve,{}),"aria-label":"清单"},{value:"agenda",icon:e.jsx(We,{}),"aria-label":"日程"}]})]}),e.jsx("div",{className:"tasks-scroll",children:xe?e.jsx("p",{role:"status",children:"正在读取任务…"}):e.jsxs(e.Fragment,{children:[g.waiting.length>0&&e.jsxs("section",{children:[e.jsxs("h3",{children:["在等你 ",e.jsx("small",{children:g.waiting.length})]}),z(g.waiting)]}),N==="list"?e.jsxs(e.Fragment,{children:[f!=="ai"&&e.jsxs("section",{children:[e.jsxs("h3",{children:["我的待办 ",e.jsx("small",{children:g.mine.length})]}),ge,z($?g.mine:g.mine.slice(0,5)),g.mine.length>5&&e.jsx(E,{size:"sm",variant:"ghost",className:"task-more h-auto min-h-9 whitespace-normal py-1",type:"button",onClick:()=>he(!$),children:$?"收起":`还有 ${g.mine.length-5} 条`})]}),f!=="mine"&&e.jsxs("details",{children:[e.jsxs("summary",{className:L,children:["AI 按计划在做 ",e.jsx("small",{children:g.ai.length})]}),z(g.ai)]}),g.unassigned.length>0&&e.jsxs("details",{children:[e.jsxs("summary",{className:L,children:["未分配 ",e.jsx("small",{children:g.unassigned.length})]}),z(g.unassigned)]}),e.jsxs("details",{children:[e.jsxs("summary",{className:L,children:["已结束 · ",M?"全部":"最近 7 天"," ",e.jsx("small",{children:(M?g.ended:g.recent).length})]}),z(M?g.ended:g.recent),e.jsx(E,{size:"sm",variant:"ghost",className:"task-more h-auto min-h-9 whitespace-normal py-1",type:"button",onClick:()=>me(!M),children:M?"只看最近 7 天":"查看全部已完成"})]})]}):Object.entries(fe).map(([t,a])=>e.jsxs("section",{children:[e.jsx("h3",{children:{overdue:"已逾期",today:"今天",tomorrow:"明天",week:"本周",later:"以后"}[t]}),a.length?z(a):e.jsx("p",{className:"task-muted",children:"没有安排"})]},t))]})}),e.jsx("footer",{children:e.jsx(E,{size:"sm",variant:"outline",className:"h-auto min-h-9 whitespace-normal py-1",type:"button",disabled:w,onClick:()=>{D(G)},children:"刷新"})})]}),mainHeader:e.jsxs("div",{className:"tasks-main-header",children:[e.jsx(He,{}),e.jsx("span",{children:"任务与待办"}),x]}),main:e.jsxs("div",{className:"tasks-detail",children:[Y&&e.jsx(Z,{className:"task-notice",tone:"destructive",role:"alert",action:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(E,{size:"sm",variant:"outline",className:"h-auto min-h-9 whitespace-normal py-1",type:"button",onClick:()=>{D(G)},children:"重试"}),d&&e.jsx(E,{size:"sm",variant:"outline",className:"h-auto min-h-9 whitespace-normal py-1",type:"button",onClick:d,children:"检查连接与授权"})]}),children:e.jsx("p",{children:/[\u4e00-\u9fff]/.test(Y)?Y:"暂时无法加载任务,请检查连接后重试"})}),ne?e.jsx(Ue,{supported:b.createAi,busy:w,onCancel:()=>R(!1),onSubmit:t=>{D(async()=>{const a=await s.create({...t,workspace:c});J(a.task)})}},"create"):l?e.jsxs(e.Fragment,{children:[e.jsxs("header",{children:[e.jsxs("div",{children:[e.jsx("span",{className:"task-eyebrow",children:B(l,u)?"我的待办":I[l.schedule?.kind??""]??"任务"}),e.jsx("h2",{children:l.title??l.instruction})]}),e.jsx("span",{className:"task-badge",children:U[l.status]??l.status})]}),e.jsxs("section",{children:[e.jsx("h3",{children:"要做什么"}),e.jsx("p",{className:"task-instruction",children:l.instruction})]}),B(l,u)?e.jsx(Oe,{task:l,busy:w,onSave:t=>{D(()=>s.update(l.id,t))}},`${l.id}:${l.updatedAt}`):e.jsxs(e.Fragment,{children:[e.jsxs("section",{children:[e.jsx("h3",{children:"什么时候"}),e.jsxs("p",{children:[I[l.schedule?.kind??""]??"未设置"," · ",(l.schedule?.cron?Re(l.schedule.cron):void 0)??(l.schedule?.intervalSeconds?`每 ${l.schedule.intervalSeconds} 秒`:l.schedule?.eventName??"待接入")]}),e.jsxs("p",{children:["下次运行:",V(l.schedule?.nextRunAt)]})]}),e.jsxs("section",{children:[e.jsx("h3",{children:"能动哪些资料"}),e.jsx("p",{className:"task-muted",children:"资料授权明细待接入"})]}),e.jsxs("div",{className:"task-actions",children:[e.jsx(E,{size:"sm",variant:"outline",className:"h-auto min-h-9 whitespace-normal py-1",type:"button",disabled:w||!["active","blocked"].includes(l.status)||!l.schedule,onClick:()=>{D(async()=>{const t=await s.run(l.id);T(t.run),H((await s.runs(l.id)).runs)})},children:"立即运行一次"}),e.jsx(E,{size:"sm",variant:"outline",className:"h-auto min-h-9 whitespace-normal py-1",type:"button",disabled:w||q(l)||!l.schedule||l.schedule.kind==="once",onClick:()=>{D(()=>s.pause(l.id,!l.schedule?.paused))},children:l.schedule?.paused?"恢复后续运行":"暂停后续运行"})]})]}),e.jsxs("section",{children:[e.jsx("h3",{children:"怎么来的"}),oe(l.source)?e.jsx("a",{className:L,href:oe(l.source),target:"_blank",rel:"noreferrer",children:"查看来源对话"}):e.jsx("p",{className:"task-muted",children:"未记录来源"})]}),e.jsxs("section",{children:[e.jsx("h3",{children:"最近运行"}),ue.length?ue.map(t=>e.jsxs("button",{type:"button",className:`task-run-row ${L}`,onClick:()=>T(t),children:[e.jsx("span",{children:V(t.createdAt)}),e.jsx("span",{children:U[t.status]??t.status})]},t.id)):e.jsx("p",{className:"task-muted",children:"暂无运行记录"})]}),v&&e.jsxs("section",{className:"task-run-detail","aria-label":"运行详情",children:[e.jsxs("header",{children:[e.jsxs("h3",{children:["这次运行 · ",U[v.status]??v.status]}),e.jsx(E,{size:"sm",variant:"outline",className:"h-auto min-h-9 whitespace-normal py-1",type:"button",onClick:()=>T(void 0),children:"关闭"})]}),v.status==="waiting_input"&&(n?n(v):e.jsx("p",{children:"这次运行在等你确认。继续同一次运行的确认入口待接入。"})),v.error&&e.jsx(Z,{className:"task-notice",tone:"destructive",role:"alert",children:/[\u4e00-\u9fff]/.test(v.error)?v.error:"本次执行未完成,请检查连接与授权后重试"}),e.jsx("ol",{children:pe.map(t=>e.jsxs("li",{children:[e.jsx("span",{children:V(t.createdAt)})," ",t.message??t.type]},t.id))}),v.status==="failed"&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"task-muted",children:"以上是已记录的执行步骤;未记录的副作用无法确认。"}),d&&e.jsx(E,{size:"sm",variant:"outline",className:"h-auto min-h-9 whitespace-normal py-1",type:"button",onClick:d,children:"检查并修复连接"}),e.jsx("p",{className:"task-muted",children:"从失败这一步继续 · 待接入"})]}),["queued","running","waiting_input","waiting_runner"].includes(v.status)&&e.jsx(E,{size:"sm",variant:"outline",className:"h-auto min-h-9 whitespace-normal py-1",type:"button",disabled:w||!!v.cancelRequestedAt,onClick:()=>{D(async()=>{const t=await s.stop(v.id);T(t.run),H((await s.runs(l.id)).runs)})},children:v.cancelRequestedAt?"已请求停止":"停止这次运行"})]})]}):e.jsxs("div",{className:"tasks-empty",children:[e.jsx("span",{className:"task-eyebrow",children:"任务与待办"}),e.jsx("h2",{children:"把想做的事,安排好"}),e.jsx("p",{children:"记下自己的待办,或让 AI 按计划完成任务。"}),e.jsx("p",{className:"task-muted",children:"从左边选择一项,查看详情和运行记录。"})]})]})})}function qe({onClick:s,children:u,...c}){const{openMain:d}=te();return e.jsx("button",{className:L,type:"button",...c,onClick:()=>{s(),d()},children:u})}function _e({selection:s}){const{openMain:u}=te();return i.useEffect(()=>{s&&u()},[s,u]),null}function He(){const{mode:s,openList:u}=te();return!i.useContext(Se)&&s==="stack"?e.jsx(E,{size:"sm",variant:"outline",className:"h-auto min-h-9 whitespace-normal py-1",type:"button",onClick:u,"aria-label":"返回任务清单",children:"‹"}):null}function Oe({task:s,busy:u,onSave:c}){const[d,o]=i.useState(s.notes??""),[p,n]=i.useState(s.priority??"normal"),[x,m]=i.useState(s.dueAt?new Date(s.dueAt*1e3-new Date(s.dueAt*1e3).getTimezoneOffset()*6e4).toISOString().slice(0,16):"");return e.jsxs("form",{className:"task-form",onSubmit:h=>{h.preventDefault(),c({notes:d,priority:p,dueAt:x?new Date(x).getTime()/1e3:null})},children:[e.jsxs("label",{children:["截止日期",e.jsx(P,{type:"datetime-local",value:x,onChange:h=>m(h.target.value)})]}),e.jsxs("label",{children:["重要程度",e.jsxs(be,{value:p,onChange:h=>n(h.target.value),children:[e.jsx("option",{value:"normal",children:"普通"}),e.jsx("option",{value:"high",children:"重要"}),e.jsx("option",{value:"urgent",children:"紧急"})]})]}),e.jsxs("label",{children:["备注",e.jsx(ae,{value:d,onChange:h=>o(h.target.value)})]}),e.jsxs("div",{className:"task-actions",children:[e.jsx(E,{size:"sm",variant:"outline",className:"h-auto min-h-9 whitespace-normal py-1",type:"submit",disabled:u,children:"保存待办"}),e.jsx(E,{size:"sm",variant:"outline",className:"h-auto min-h-9 whitespace-normal py-1",type:"button",disabled:u,onClick:()=>c({completed:s.status!=="completed"}),children:s.status==="completed"?"重新打开":"标记完成"})]}),e.jsx("p",{className:"task-muted",children:"交给 AI 去做 · 待接入"})]})}function Ue({supported:s,busy:u,onSubmit:c,onCancel:d}){const[o,p]=i.useState(""),[n,x]=i.useState("cron"),[m,h]=i.useState("09:00"),[b,A]=i.useState(60),[k,F]=i.useState("");return e.jsxs("form",{className:"task-form",onSubmit:f=>{f.preventDefault(),c({prompt:o,kind:n,...n==="cron"?{cron:`${Number(m.split(":")[1])} ${Number(m.split(":")[0])} * * *`}:n==="interval"?{intervalSeconds:b*60}:{eventName:k}})},children:[e.jsxs("header",{children:[e.jsx("h2",{children:"新建任务"}),e.jsx(E,{size:"sm",variant:"outline",className:"h-auto min-h-9 whitespace-normal py-1",type:"button",onClick:d,children:"取消"})]}),e.jsxs("label",{children:["要做什么",e.jsx(ae,{required:!0,value:o,placeholder:"例如,每天整理我关注的信息",onChange:f=>p(f.target.value)})]}),e.jsxs("fieldset",{children:[e.jsx("legend",{children:"什么时候"}),e.jsx(se,{className:"grow",size:"sm",ariaLabel:"什么时候",value:n,onValueChange:x,options:[{value:"cron",label:I.cron},{value:"interval",label:I.interval},{value:"event",label:I.event}]})]}),n==="cron"?e.jsxs("label",{children:["每天几点",e.jsx(P,{type:"time",required:!0,value:m,onChange:f=>h(f.target.value)}),e.jsx("small",{children:"按执行环境的时区安排。"})]}):n==="interval"?e.jsxs("label",{children:["每隔多少分钟",e.jsx(P,{type:"number",min:"1",required:!0,value:b,onChange:f=>A(Number(f.target.value))})]}):e.jsxs("label",{children:["事件名称",e.jsx(P,{required:!0,value:k,onChange:f=>F(f.target.value)})]}),!s&&e.jsx(Z,{tone:"info",role:"status",children:"代理执行身份待接入。你可以先在清单中添加自己的待办。"}),e.jsx(E,{size:"sm",variant:"outline",className:"h-auto min-h-9 whitespace-normal py-1",type:"submit",disabled:u||!s||!o.trim(),children:"创建任务"})]})}const de={width:15,height:15,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};function Ve(){return e.jsx("svg",{...de,children:e.jsx("path",{d:"M8 6h13M8 12h13M8 18h13M3 6h.01M3 12h.01M3 18h.01"})})}function We(){return e.jsx("svg",{...de,children:e.jsx("path",{d:"M4 5h16v15H4zM4 10h16M8 3v4M16 3v4"})})}function Ke(s,u,c){if(!u.thread)return;const d=s.filter(o=>o.approvalId&&o.run===u.id&&o.thread===u.thread);return d.find(o=>o.approvalId===c)??d[0]}function as(){const s=ke(),u=ve(),[c]=Ee(),d=Ce(),o=i.useMemo(()=>{const n=Ae({fetch:s.fetch,baseUrl:window.location.origin});return{...n,stop:async x=>{const m=await n.stop(x);return window.dispatchEvent(new Event("xpod:pod-changed")),m}}},[s.fetch]),p=c.get("approval");return e.jsx(Pe,{client:o,webId:s.webId,workspace:s.currentPod.podUrl,selectedTaskId:c.get("task")??void 0,selectedRunId:c.get("run")??void 0,onOpenConnections:()=>u("/ai-connections"),headerActions:e.jsx(De,{}),renderApproval:n=>{const x=Ke(d.snapshot.attention,n,p),m=d.snapshot.attention.some(h=>h.id===n.id&&h.resumeApproval);return e.jsxs(e.Fragment,{children:[x?e.jsx(Be,{item:x}):!m&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"这次运行在等你确认,暂未收到对应的申请。"}),e.jsx(we,{run:n.id})]})}},`${s.webId}:${s.currentPod?.podUrl}`)}export{as as default};