orc-ai 0.1.59 → 0.1.60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -7
- package/dist/index.js +911 -866
- package/dist/skills/orc-platform/references/packages.md +14 -2
- package/dist/skills/orc-platform/references/scratchpads.md +18 -0
- package/dist/skills/orc-platform/references/work.md +4 -2
- package/dist/web/assets/{Agents-BwzrreDL.js → Agents-DBN_IKhQ.js} +1 -1
- package/dist/web/assets/Attention-Col9bpvb.js +2 -0
- package/dist/web/assets/{Audit-MunmWePJ.js → Audit-DDhPMP5V.js} +1 -1
- package/dist/web/assets/{ChatUiRenderer-B8mQriTi.js → ChatUiRenderer-Bflvv2nP.js} +1 -1
- package/dist/web/assets/{ConfirmDialog-C2YawyrD.js → ConfirmDialog-DOSTWblx.js} +1 -1
- package/dist/web/assets/{Dashboard-BxIs9Tic.js → Dashboard-CXREcWFQ.js} +1 -1
- package/dist/web/assets/{DocumentWorkspace-CGBAaBzX.js → DocumentWorkspace-DVnU3uMP.js} +1 -1
- package/dist/web/assets/{FileEditor-BTbqUvIu.js → FileEditor-YLZReqhf.js} +1 -1
- package/dist/web/assets/{FormDialog-B4dHT0EU.js → FormDialog-CelnA8hT.js} +1 -1
- package/dist/web/assets/IntegrationCallback-elv3Aqfs.js +1 -0
- package/dist/web/assets/{JobWebhooks-CGwMk_nF.js → JobWebhooks-BvKIhaAK.js} +1 -1
- package/dist/web/assets/Jobs-TFiqlEzO.js +1 -0
- package/dist/web/assets/Knowledge-Dz9v7lfr.js +1 -0
- package/dist/web/assets/Markdown-CtVGTUZH.js +2 -0
- package/dist/web/assets/MarkdownEditor-CSloDLyL.js +2 -0
- package/dist/web/assets/{MarkdownRenderer-CSqZzC8Y.js → MarkdownRenderer-B6SKIKVL.js} +4 -4
- package/dist/web/assets/NativeFolderField-DwXF9tJW.js +1 -0
- package/dist/web/assets/{PackageCatalog-CNQ_Rha1.js → PackageCatalog-DSwcvJsN.js} +2 -2
- package/dist/web/assets/{PackageRunDialog-DUIQUood.js → PackageRunDialog-HoczGux2.js} +1 -1
- package/dist/web/assets/{Pager-CleJ2qHm.js → Pager-D-y150yZ.js} +1 -1
- package/dist/web/assets/Projects-D5da4x_q.js +3 -0
- package/dist/web/assets/{ResponsiveFilters-BIAzZYPs.js → ResponsiveFilters-CQ42T3S8.js} +1 -1
- package/dist/web/assets/{ResumeActions-Dbv5ctO7.js → ResumeActions-DYiHEYFy.js} +1 -1
- package/dist/web/assets/Rules-CYG1JoBH.js +18 -0
- package/dist/web/assets/{ScratchpadDiagramEditor-CY0VDkOm.js → ScratchpadDiagramEditor-Dcfngku2.js} +1 -1
- package/dist/web/assets/Scratchpads-uSMao0H4.js +10 -0
- package/dist/web/assets/Sessions-BWh81qh3.js +3 -0
- package/dist/web/assets/Settings-w_H15X7M.js +14 -0
- package/dist/web/assets/Skills-CmcTt8ye.js +8 -0
- package/dist/web/assets/{SourceEditor-Bm3YcLGC.js → SourceEditor-DNHVu9ux.js} +3 -3
- package/dist/web/assets/{TagInput-XEuKQyEW.js → TagInput-BmRYPN4B.js} +1 -1
- package/dist/web/assets/TaskDetailSheet-DfK_DtzG.js +1 -0
- package/dist/web/assets/{Tasks-C_0Et1rr.js → Tasks-CbOw64sI.js} +7 -7
- package/dist/web/assets/Terminals-DP3MyIBo.js +3 -0
- package/dist/web/assets/{ViewHeader-BajY1vkx.js → ViewHeader-BtTaSrXy.js} +1 -1
- package/dist/web/assets/{Webhooks-DgMaSyjO.js → Webhooks-CP-m_Dos.js} +1 -1
- package/dist/web/assets/{badge-CczwlQze.js → badge-CpU0J4qt.js} +1 -1
- package/dist/web/assets/check-N8fVGVDO.js +1 -0
- package/dist/web/assets/chevron-down-wgh-M0zj.js +1 -0
- package/dist/web/assets/circle-alert-OZ-kwnCD.js +1 -0
- package/dist/web/assets/{circle-check-B_-siEWc.js → circle-check-DQM5o2QS.js} +1 -1
- package/dist/web/assets/client-BnTXPI20.js +1 -0
- package/dist/web/assets/{dialog-C7wt3DcD.js → dialog-D86vkhdt.js} +1 -1
- package/dist/web/assets/{download-B0FkIRZc.js → download-6d5_Jyox.js} +1 -1
- package/dist/web/assets/{highlighted-body-JLMTFACH-CT50vDjv.js → highlighted-body-JLMTFACH-C0zXH1C-.js} +1 -1
- package/dist/web/assets/{index-C0yeM676.js → index-D5qFuDmc.js} +84 -30
- package/dist/web/assets/index-z4BVJQry.css +1 -0
- package/dist/web/assets/{link-2-CE3Sblf0.js → link-2-Ced5Jr2w.js} +1 -1
- package/dist/web/assets/{list-CSWWmpsk.js → list-OJI1AaZs.js} +1 -1
- package/dist/web/assets/{maximize-2-CN8Tztng.js → maximize-2-Daih3Vv7.js} +1 -1
- package/dist/web/assets/mermaid-WFAXDIZX-BTh2e4d1.js +1 -0
- package/dist/web/assets/{save-DWlDLKMf.js → save-CnCcteVb.js} +1 -1
- package/dist/web/assets/{scratchpad-kinds-BhSSEfi9.js → scratchpad-kinds-vQJshqz1.js} +1 -1
- package/dist/web/assets/{scratchpad-routes-BBSS02R-.js → scratchpad-routes-D8SCEha7.js} +1 -1
- package/dist/web/assets/{upload-Dj3lbGL_.js → upload-BLDr7Cwk.js} +1 -1
- package/dist/web/assets/useIntegrations-CkfXwYNs.js +1 -0
- package/dist/web/assets/{useJobs-lhzWAkUN.js → useJobs-BNj4dd9l.js} +1 -1
- package/dist/web/assets/{useMemories-76m7jnqk.js → useMemories-BpfvcV2g.js} +1 -1
- package/dist/web/assets/{useSessions-gfliXBHJ.js → useSessions-n-bp8ic5.js} +1 -1
- package/dist/web/assets/{x-vKt_RFSV.js → x-CIaAKXRo.js} +1 -1
- package/dist/web/index.html +11 -12
- package/package.json +1 -1
- package/dist/web/assets/Attention-By2dScSb.js +0 -2
- package/dist/web/assets/IntegrationCallback-DXHVQyoB.js +0 -1
- package/dist/web/assets/Jobs-B4eLen3k.js +0 -1
- package/dist/web/assets/Knowledge-CG71SuxG.js +0 -1
- package/dist/web/assets/Markdown-DRYI2VLT.js +0 -2
- package/dist/web/assets/MarkdownEditor-D8aBF3I9.js +0 -2
- package/dist/web/assets/Projects-BVhb3Dtm.js +0 -3
- package/dist/web/assets/Rules-CvQ24J5a.js +0 -18
- package/dist/web/assets/Scratchpads-D4htYgy_.js +0 -10
- package/dist/web/assets/Sessions-CG1mCfIY.js +0 -3
- package/dist/web/assets/Settings-BNCj7UWA.js +0 -14
- package/dist/web/assets/Skills-Ck_KrsPB.js +0 -8
- package/dist/web/assets/TaskDetailSheet-BzYkmkFK.js +0 -1
- package/dist/web/assets/Terminals-BbhfCTPR.js +0 -3
- package/dist/web/assets/check-DZNzZAdD.js +0 -1
- package/dist/web/assets/chevron-down-DjliQtS1.js +0 -1
- package/dist/web/assets/client-ByMuVs3d.js +0 -1
- package/dist/web/assets/index-Ci_YnsZ9.css +0 -1
- package/dist/web/assets/mermaid-WFAXDIZX-BLiIUJmd.js +0 -1
- package/dist/web/assets/schemas-BQZhekae.js +0 -55
- package/dist/web/assets/useIntegrations-Dmrd-_Pu.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e}from"./rolldown-runtime-DSDNlrLa.js";import{n as t,t as n}from"./jsx-runtime-CVMpzJz9.js";import{n as r}from"./QueryClientProvider-DlPztvhd.js";import{n as i,t as a}from"./useMutation-HX90wI4L.js";import{t as o}from"./chunk-OB3PAWPO-1IihCzFx.js";import{t as s}from"./button-C91mbQEU.js";import{t as c}from"./label-BdnRgBbz.js";import{i as l,n as u}from"./client-ByMuVs3d.js";import{Ft as d}from"./index-C0yeM676.js";import{l as f}from"./useJobs-lhzWAkUN.js";import{t as p}from"./ErrorState-DprXzfow.js";var m=e(t(),1);function h(e){return i({queryKey:[`webhooks`,e],queryFn:()=>u.webhooks.list(e),select:e=>e.webhooks})}function g(e){return i({queryKey:[`webhook-deliveries`,e],queryFn:()=>u.webhooks.deliveries(e),select:e=>e.deliveries,enabled:!!e,refetchInterval:3e3})}function _(){let e=r();return a({mutationFn:e=>u.webhooks.create(e),onSuccess:()=>e.invalidateQueries({queryKey:[`webhooks`]})})}function v(){let e=r();return a({mutationFn:({id:e,...t})=>u.webhooks.update(e,t),onSuccess:()=>e.invalidateQueries({queryKey:[`webhooks`]})})}function y(){let e=r();return a({mutationFn:e=>u.webhooks.delete(e),onSuccess:()=>e.invalidateQueries({queryKey:[`webhooks`]})})}function b(){return a({mutationFn:e=>u.webhooks.rotate(e)})}function x(e){return[...new Set(e.split(`,`).map(e=>e.trim()).filter(Boolean))]}function S(e,t,n){return new URL(`/webhooks/${encodeURIComponent(e)}`,new URL(t,n)).href}function C(e){return[`localhost`,`127.0.0.1`,`[::1]`].includes(new URL(e).hostname)}var w=n();function T({id:e,testId:t,value:n,onChange:r,placeholder:i}){let[a,o]=(0,m.useState)(n.join(`, `));return(0,w.jsx)(d,{id:e,"data-testid":t,value:a,placeholder:i,onChange:e=>{o(e.target.value),r(e.target.value)}})}function E({projectId:e,onCreated:t}){let n=_(),[r,i]=(0,m.useState)(``),[a,o]=(0,m.useState)(`github`),[l,u]=(0,m.useState)(null),f=(0,m.useId)();return l?(0,w.jsxs)(`div`,{"data-testid":`webhook-created`,className:`space-y-3`,children:[(0,w.jsx)(A,{hook:l,secret:l.secret}),(0,w.jsx)(s,{type:`button`,variant:`outline`,"data-testid":`webhook-setup-done`,onClick:()=>{t?.(l),u(null),i(``)},children:`I've copied the setup details`})]}):(0,w.jsxs)(`div`,{className:`space-y-3`,"data-testid":`webhook-create-form`,children:[(0,w.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,w.jsx)(c,{htmlFor:`${f}-name`,children:`Webhook name`}),(0,w.jsx)(d,{id:`${f}-name`,"data-testid":`webhook-name`,value:r,onChange:e=>i(e.target.value),maxLength:100,placeholder:`GitHub repository events`})]}),(0,w.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,w.jsx)(c,{htmlFor:`${f}-provider`,children:`Provider`}),(0,w.jsxs)(`select`,{id:`${f}-provider`,"data-testid":`webhook-provider`,className:`w-full min-h-8 rounded-md border border-control-border bg-background px-3 text-sm`,value:a,onChange:e=>o(e.target.value),children:[(0,w.jsx)(`option`,{value:`github`,children:`GitHub`}),(0,w.jsx)(`option`,{value:`generic`,children:`Other service (HMAC)`})]})]}),(0,w.jsx)(`p`,{className:`text-xs text-outline`,children:`Create the event source here. Connect jobs and choose their event filters in Jobs. No job is required to create a webhook.`}),n.error&&(0,w.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:n.error.message}),(0,w.jsx)(s,{type:`button`,"data-testid":`webhook-create`,disabled:!r.trim()||n.isPending,onClick:()=>n.mutate({name:r.trim(),provider:a,project_id:e??null},{onSuccess:u}),children:n.isPending?`Creating...`:`Create webhook`})]})}function D({value:e,onChange:t,projectId:n}){let{data:r,error:i,isLoading:a,refetch:o}=h(n),l=r?.filter(e=>e.project_id===null||e.project_id===n),[u,d]=(0,m.useState)(!1);function f(n){e.some(e=>e.webhook_id===n)||t([...e,{webhook_id:n,events:[],actions:[]}])}function g(n,r,i){t(e.map(e=>e.webhook_id===n?{...e,[r]:x(i)}:e))}return(0,w.jsxs)(`section`,{className:`space-y-3 border-y border-border py-4`,"data-testid":`job-webhook-picker`,children:[(0,w.jsx)(`h3`,{className:`text-sm font-medium`,children:`Which webhook should trigger this job?`}),i?(0,w.jsx)(p,{message:i.message,onRetry:()=>o()}):(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(c,{htmlFor:`job-webhook-source`,children:`Configured webhooks`}),(0,w.jsxs)(`select`,{id:`job-webhook-source`,"data-testid":`job-webhook-select`,className:`w-full min-h-8 rounded-md border border-control-border bg-background px-3 text-sm`,value:``,disabled:a,onChange:e=>{e.target.value&&f(e.target.value)},children:[(0,w.jsx)(`option`,{value:``,children:a?`Loading webhooks...`:`Select an existing webhook`}),(l??[]).filter(t=>!e.some(e=>e.webhook_id===t.id)).map(e=>(0,w.jsxs)(`option`,{value:e.id,children:[e.name,e.enabled?``:` (disabled)`]},e.id))]}),!a&&!l?.length&&(0,w.jsx)(`p`,{className:`text-xs text-outline`,children:`No webhooks configured for this project yet. Create one below or on the Webhooks page.`})]}),e.map(n=>(0,w.jsxs)(`div`,{className:`space-y-2 border-t border-border pt-3`,"data-testid":`job-webhook-binding`,"data-webhook-id":n.webhook_id,children:[(0,w.jsxs)(`div`,{className:`flex justify-between gap-2`,children:[(0,w.jsx)(`span`,{className:`text-sm font-medium`,children:l?.find(e=>e.id===n.webhook_id)?.name??n.webhook_id}),(0,w.jsx)(s,{type:`button`,variant:`ghost`,size:`sm`,"data-testid":`job-webhook-remove`,onClick:()=>t(e.filter(e=>e.webhook_id!==n.webhook_id)),children:`Disconnect`})]}),(0,w.jsx)(c,{htmlFor:`events-${n.webhook_id}`,children:`Events for this job`}),(0,w.jsx)(T,{id:`events-${n.webhook_id}`,testId:`webhook-events`,value:n.events,onChange:e=>g(n.webhook_id,`events`,e),placeholder:`pull_request, push (blank accepts all)`}),(0,w.jsx)(c,{htmlFor:`actions-${n.webhook_id}`,children:`Actions for this job (optional)`}),(0,w.jsx)(T,{id:`actions-${n.webhook_id}`,testId:`webhook-actions`,value:n.actions,onChange:e=>g(n.webhook_id,`actions`,e),placeholder:`opened, synchronize (blank accepts all)`})]},n.webhook_id)),(0,w.jsx)(s,{type:`button`,size:`sm`,variant:`outline`,"data-testid":`webhook-add`,onClick:()=>d(!u),children:u?`Close new webhook`:`Create a webhook`}),u&&(0,w.jsx)(E,{projectId:n,onCreated:e=>{f(e.id),d(!1)}})]})}function O({job:e}){let t=f(),[n,r]=(0,m.useState)(e.webhooks??[]);return(0,w.jsxs)(`section`,{className:`space-y-3`,"data-testid":`job-webhooks`,children:[!e.enabled&&(0,w.jsx)(`p`,{className:`text-sm text-outline`,children:`Job disabled. Configure connections now and enable it from Jobs when ready.`}),(0,w.jsx)(D,{value:n,onChange:r,projectId:e.project_id??void 0}),t.error&&(0,w.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:t.error.message}),(0,w.jsx)(s,{type:`button`,size:`sm`,"data-testid":`job-webhooks-save`,disabled:t.isPending,onClick:()=>t.mutate({id:e.id,webhooks:n,trigger_type:`webhook`}),children:`Save connections`}),t.isSuccess&&(0,w.jsx)(`p`,{role:`status`,className:`text-xs text-outline`,children:`Connections saved.`}),(0,w.jsx)(o,{className:`inline-block text-sm underline`,to:`/webhooks?project=${encodeURIComponent(e.project_id??`all`)}`,children:`Manage configured webhooks and deliveries`})]})}function k({label:e,value:t,secret:n=!1}){let[r,i]=(0,m.useState)(!1),[a,o]=(0,m.useState)(!1);return(0,w.jsxs)(`div`,{className:`space-y-1`,children:[(0,w.jsx)(`p`,{className:`text-xs text-outline`,children:e}),(0,w.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,w.jsx)(`code`,{className:`min-w-0 flex-1 break-all text-xs`,"data-testid":n?`webhook-secret`:`webhook-url`,children:t}),(0,w.jsx)(s,{type:`button`,size:`sm`,variant:`outline`,"aria-label":`Copy ${e}`,onClick:async()=>{try{await navigator.clipboard.writeText(t),i(!0),o(!1)}catch{o(!0)}},children:r?`Copied`:`Copy`})]}),a&&(0,w.jsx)(`p`,{role:`alert`,className:`text-xs text-error`,children:`Select and copy the value above; clipboard access is unavailable.`})]})}function A({hook:e,secret:t,showInstructions:n=!0,instructionsId:r}){let i=S(e.token,l(),window.location.origin);return(0,w.jsxs)(`div`,{className:`space-y-3`,"data-testid":`webhook-setup`,children:[(0,w.jsx)(k,{label:`Payload URL`,value:i}),C(i)&&(0,w.jsx)(`p`,{className:`text-sm text-warning`,children:`This address is local. For external providers, use your publicly reachable ORC address with the same /webhooks/ path.`}),n&&(0,w.jsxs)(`div`,{id:r,"data-testid":`webhook-setup-instructions`,className:`space-y-3`,children:[t?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(k,{label:`Signing secret`,value:t,secret:!0}),(0,w.jsx)(`p`,{className:`text-xs text-outline`,children:`Copy the signing secret before leaving. It is shown once.`})]}):(0,w.jsx)(`p`,{className:`text-xs text-outline`,children:`The signing secret is hidden. Generate a replacement only if you need to reconnect the sender.`}),e.provider===`github`?(0,w.jsxs)(`ol`,{className:`list-decimal space-y-1 pl-5 text-sm text-outline`,children:[(0,w.jsx)(`li`,{children:`In your repository, open GitHub Settings - Webhooks - Add webhook.`}),(0,w.jsx)(`li`,{children:`Paste the Payload URL, select application/json, and enter the signing secret.`}),(0,w.jsx)(`li`,{children:`Select the events needed by your connected jobs. Each job has its own filters.`}),(0,w.jsx)(`li`,{children:`Send a test event, then open Recent deliveries for this webhook.`})]}):(0,w.jsx)(`p`,{className:`text-sm text-outline`,children:`Send JSON, signed with HMAC-SHA256 of the raw body. Set X-Orc-Signature-256 to sha256=<hex signature>, X-Orc-Event to the event name and X-Orc-Delivery to a unique delivery ID.`})]})]})}function j({hook:e}){let t=v(),n=b(),[r,i]=(0,m.useState)(!1),[a,c]=(0,m.useState)(!1),[l,u]=(0,m.useState)(!1),[d,f]=(0,m.useState)(),p=(0,m.useId)();return(0,w.jsxs)(`article`,{className:`space-y-3 border-b border-border pb-5`,"data-testid":`webhook-endpoint`,"data-webhook-id":e.id,children:[(0,w.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,w.jsx)(`h3`,{className:`text-sm font-medium`,children:e.name}),(0,w.jsxs)(`span`,{className:`text-xs text-outline`,children:[e.provider,` - `,e.enabled?`Enabled`:`Disabled`]}),(0,w.jsx)(s,{type:`button`,variant:`outline`,size:`sm`,disabled:t.isPending,onClick:()=>t.mutate({id:e.id,enabled:!e.enabled}),children:e.enabled?`Disable`:`Enable`})]}),(0,w.jsxs)(`div`,{className:`space-y-1`,"data-testid":`webhook-connected-jobs`,children:[(0,w.jsxs)(`p`,{className:`text-xs text-outline`,children:[`Connected jobs (`,e.subscriptions.length,`)`]}),e.subscriptions.length?e.subscriptions.map(e=>(0,w.jsxs)(`div`,{className:`text-sm`,children:[(0,w.jsx)(o,{className:`underline`,"data-testid":`webhook-job-link`,to:`/jobs/${e.job_id}?project=all`,children:e.name}),(0,w.jsxs)(`span`,{className:`text-xs text-outline`,children:[` `,`- `,e.enabled?`Enabled`:`Disabled`,`; events:`,` `,e.events.join(`, `)||`all`,`; actions:`,` `,e.actions.join(`, `)||`all`]})]},e.job_id)):null]}),(0,w.jsx)(A,{hook:e,secret:d,showInstructions:a,instructionsId:p}),(0,w.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,w.jsx)(s,{type:`button`,variant:`outline`,size:`sm`,"data-testid":`webhook-deliveries-toggle`,onClick:()=>i(!r),children:r?`Hide deliveries`:`Recent deliveries`}),(0,w.jsx)(s,{type:`button`,variant:`ghost`,size:`sm`,"data-testid":`webhook-setup-toggle`,"aria-expanded":a,"aria-controls":a?p:void 0,disabled:n.isPending,onClick:()=>{a&&f(void 0),c(!a),u(!1)},children:a?d?`I've copied the setup details`:`Hide setup`:`Setup instructions`})]}),a&&(0,w.jsx)(s,{type:`button`,variant:`ghost`,size:`sm`,disabled:n.isPending,onClick:()=>u(!l),children:`New signing secret`}),a&&l&&(0,w.jsxs)(`div`,{className:`space-y-2 text-sm`,children:[(0,w.jsx)(`p`,{children:`The sender's existing secret will stop working. Update it after generating the replacement.`}),(0,w.jsx)(s,{type:`button`,variant:`outline`,size:`sm`,disabled:n.isPending,onClick:()=>n.mutate(e.id,{onSuccess:e=>{f(e.secret),c(!0),u(!1)}}),children:`Generate replacement secret`})]}),(t.error||n.error)&&(0,w.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:(t.error??n.error)?.message}),r&&(0,w.jsx)(M,{id:e.id})]})}function M({id:e}){let{data:t,isLoading:n,error:r,refetch:i}=g(e);return(0,w.jsxs)(`section`,{className:`space-y-2`,"data-testid":`webhook-deliveries`,children:[(0,w.jsx)(`h4`,{className:`text-sm font-medium`,children:`Recent deliveries`}),r?(0,w.jsx)(p,{message:r.message,onRetry:()=>i()}):n?(0,w.jsx)(`p`,{role:`status`,children:`Loading deliveries...`}):t?.length?t.map(e=>(0,w.jsxs)(`div`,{className:`space-y-1 border-t border-border py-2 text-xs`,"data-testid":`webhook-delivery`,children:[(0,w.jsxs)(`div`,{className:`flex flex-wrap justify-between gap-2`,children:[(0,w.jsxs)(`span`,{children:[e.event,e.action?` / ${e.action}`:``]}),(0,w.jsx)(`span`,{children:e.status})]}),(0,w.jsxs)(`p`,{className:`text-outline`,children:[e.repository,` `,new Date(e.created_at).toLocaleString()]}),e.status===`ignored`&&(0,w.jsx)(`p`,{className:`text-outline`,children:`No enabled connected job matched this event.`}),e.error&&(0,w.jsx)(`p`,{className:`text-error`,children:e.error}),e.runs.map(e=>(0,w.jsxs)(`div`,{className:`flex flex-wrap gap-3`,children:[(0,w.jsxs)(o,{className:`underline`,to:`/jobs/${e.job_id}?project=all`,children:[`Job run: `,e.status]}),e.task_id&&(0,w.jsx)(o,{className:`underline`,to:`/tasks/${e.task_id}?project=all`,children:`Created task`}),e.session_id&&(0,w.jsx)(o,{className:`underline`,to:`/audit/${e.session_id}?project=all`,children:`Agent session`})]},e.job_run_id))]},e.id)):(0,w.jsx)(`p`,{className:`text-sm text-outline`,children:`No events received yet. Register the endpoint with your provider, then send an event.`})]})}export{y as a,D as i,E as n,h as o,j as r,O as t};
|
|
1
|
+
import{a as e}from"./rolldown-runtime-DSDNlrLa.js";import{n as t,t as n}from"./jsx-runtime-CVMpzJz9.js";import{n as r}from"./QueryClientProvider-DlPztvhd.js";import{n as i,t as a}from"./useMutation-HX90wI4L.js";import{t as o}from"./chunk-OB3PAWPO-1IihCzFx.js";import{t as s}from"./button-C91mbQEU.js";import{t as c}from"./label-BdnRgBbz.js";import{i as l,n as u}from"./client-BnTXPI20.js";import{Ft as d}from"./index-D5qFuDmc.js";import{l as f}from"./useJobs-BNj4dd9l.js";import{t as p}from"./ErrorState-DprXzfow.js";var m=e(t(),1);function h(e){return i({queryKey:[`webhooks`,e],queryFn:()=>u.webhooks.list(e),select:e=>e.webhooks})}function g(e){return i({queryKey:[`webhook-deliveries`,e],queryFn:()=>u.webhooks.deliveries(e),select:e=>e.deliveries,enabled:!!e,refetchInterval:3e3})}function _(){let e=r();return a({mutationFn:e=>u.webhooks.create(e),onSuccess:()=>e.invalidateQueries({queryKey:[`webhooks`]})})}function v(){let e=r();return a({mutationFn:({id:e,...t})=>u.webhooks.update(e,t),onSuccess:()=>e.invalidateQueries({queryKey:[`webhooks`]})})}function y(){let e=r();return a({mutationFn:e=>u.webhooks.delete(e),onSuccess:()=>e.invalidateQueries({queryKey:[`webhooks`]})})}function b(){return a({mutationFn:e=>u.webhooks.rotate(e)})}function x(e){return[...new Set(e.split(`,`).map(e=>e.trim()).filter(Boolean))]}function S(e,t,n){return new URL(`/webhooks/${encodeURIComponent(e)}`,new URL(t,n)).href}function C(e){return[`localhost`,`127.0.0.1`,`[::1]`].includes(new URL(e).hostname)}var w=n();function T({id:e,testId:t,value:n,onChange:r,placeholder:i}){let[a,o]=(0,m.useState)(n.join(`, `));return(0,w.jsx)(d,{id:e,"data-testid":t,value:a,placeholder:i,onChange:e=>{o(e.target.value),r(e.target.value)}})}function E({projectId:e,onCreated:t}){let n=_(),[r,i]=(0,m.useState)(``),[a,o]=(0,m.useState)(`github`),[l,u]=(0,m.useState)(null),f=(0,m.useId)();return l?(0,w.jsxs)(`div`,{"data-testid":`webhook-created`,className:`space-y-3`,children:[(0,w.jsx)(A,{hook:l,secret:l.secret}),(0,w.jsx)(s,{type:`button`,variant:`outline`,"data-testid":`webhook-setup-done`,onClick:()=>{t?.(l),u(null),i(``)},children:`I've copied the setup details`})]}):(0,w.jsxs)(`div`,{className:`space-y-3`,"data-testid":`webhook-create-form`,children:[(0,w.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,w.jsx)(c,{htmlFor:`${f}-name`,children:`Webhook name`}),(0,w.jsx)(d,{id:`${f}-name`,"data-testid":`webhook-name`,value:r,onChange:e=>i(e.target.value),maxLength:100,placeholder:`GitHub repository events`})]}),(0,w.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,w.jsx)(c,{htmlFor:`${f}-provider`,children:`Provider`}),(0,w.jsxs)(`select`,{id:`${f}-provider`,"data-testid":`webhook-provider`,className:`w-full min-h-8 rounded-md border border-control-border bg-background px-3 text-sm`,value:a,onChange:e=>o(e.target.value),children:[(0,w.jsx)(`option`,{value:`github`,children:`GitHub`}),(0,w.jsx)(`option`,{value:`generic`,children:`Other service (HMAC)`})]})]}),(0,w.jsx)(`p`,{className:`text-xs text-outline`,children:`Create the event source here. Connect jobs and choose their event filters in Jobs. No job is required to create a webhook.`}),n.error&&(0,w.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:n.error.message}),(0,w.jsx)(s,{type:`button`,"data-testid":`webhook-create`,disabled:!r.trim()||n.isPending,onClick:()=>n.mutate({name:r.trim(),provider:a,project_id:e??null},{onSuccess:u}),children:n.isPending?`Creating...`:`Create webhook`})]})}function D({value:e,onChange:t,projectId:n}){let{data:r,error:i,isLoading:a,refetch:o}=h(n),l=r?.filter(e=>e.project_id===null||e.project_id===n),[u,d]=(0,m.useState)(!1);function f(n){e.some(e=>e.webhook_id===n)||t([...e,{webhook_id:n,events:[],actions:[]}])}function g(n,r,i){t(e.map(e=>e.webhook_id===n?{...e,[r]:x(i)}:e))}return(0,w.jsxs)(`section`,{className:`space-y-3 border-y border-border py-4`,"data-testid":`job-webhook-picker`,children:[(0,w.jsx)(`h3`,{className:`text-sm font-medium`,children:`Which webhook should trigger this job?`}),i?(0,w.jsx)(p,{message:i.message,onRetry:()=>o()}):(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(c,{htmlFor:`job-webhook-source`,children:`Configured webhooks`}),(0,w.jsxs)(`select`,{id:`job-webhook-source`,"data-testid":`job-webhook-select`,className:`w-full min-h-8 rounded-md border border-control-border bg-background px-3 text-sm`,value:``,disabled:a,onChange:e=>{e.target.value&&f(e.target.value)},children:[(0,w.jsx)(`option`,{value:``,children:a?`Loading webhooks...`:`Select an existing webhook`}),(l??[]).filter(t=>!e.some(e=>e.webhook_id===t.id)).map(e=>(0,w.jsxs)(`option`,{value:e.id,children:[e.name,e.enabled?``:` (disabled)`]},e.id))]}),!a&&!l?.length&&(0,w.jsx)(`p`,{className:`text-xs text-outline`,children:`No webhooks configured for this project yet. Create one below or on the Webhooks page.`})]}),e.map(n=>(0,w.jsxs)(`div`,{className:`space-y-2 border-t border-border pt-3`,"data-testid":`job-webhook-binding`,"data-webhook-id":n.webhook_id,children:[(0,w.jsxs)(`div`,{className:`flex justify-between gap-2`,children:[(0,w.jsx)(`span`,{className:`text-sm font-medium`,children:l?.find(e=>e.id===n.webhook_id)?.name??n.webhook_id}),(0,w.jsx)(s,{type:`button`,variant:`ghost`,size:`sm`,"data-testid":`job-webhook-remove`,onClick:()=>t(e.filter(e=>e.webhook_id!==n.webhook_id)),children:`Disconnect`})]}),(0,w.jsx)(c,{htmlFor:`events-${n.webhook_id}`,children:`Events for this job`}),(0,w.jsx)(T,{id:`events-${n.webhook_id}`,testId:`webhook-events`,value:n.events,onChange:e=>g(n.webhook_id,`events`,e),placeholder:`pull_request, push (blank accepts all)`}),(0,w.jsx)(c,{htmlFor:`actions-${n.webhook_id}`,children:`Actions for this job (optional)`}),(0,w.jsx)(T,{id:`actions-${n.webhook_id}`,testId:`webhook-actions`,value:n.actions,onChange:e=>g(n.webhook_id,`actions`,e),placeholder:`opened, synchronize (blank accepts all)`})]},n.webhook_id)),(0,w.jsx)(s,{type:`button`,size:`sm`,variant:`outline`,"data-testid":`webhook-add`,onClick:()=>d(!u),children:u?`Close new webhook`:`Create a webhook`}),u&&(0,w.jsx)(E,{projectId:n,onCreated:e=>{f(e.id),d(!1)}})]})}function O({job:e}){let t=f(),[n,r]=(0,m.useState)(e.webhooks??[]);return(0,w.jsxs)(`section`,{className:`space-y-3`,"data-testid":`job-webhooks`,children:[!e.enabled&&(0,w.jsx)(`p`,{className:`text-sm text-outline`,children:`Job disabled. Configure connections now and enable it from Jobs when ready.`}),(0,w.jsx)(D,{value:n,onChange:r,projectId:e.project_id??void 0}),t.error&&(0,w.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:t.error.message}),(0,w.jsx)(s,{type:`button`,size:`sm`,"data-testid":`job-webhooks-save`,disabled:t.isPending,onClick:()=>t.mutate({id:e.id,webhooks:n,trigger_type:`webhook`}),children:`Save connections`}),t.isSuccess&&(0,w.jsx)(`p`,{role:`status`,className:`text-xs text-outline`,children:`Connections saved.`}),(0,w.jsx)(o,{className:`inline-block text-sm underline`,to:`/webhooks?project=${encodeURIComponent(e.project_id??`all`)}`,children:`Manage configured webhooks and deliveries`})]})}function k({label:e,value:t,secret:n=!1}){let[r,i]=(0,m.useState)(!1),[a,o]=(0,m.useState)(!1);return(0,w.jsxs)(`div`,{className:`space-y-1`,children:[(0,w.jsx)(`p`,{className:`text-xs text-outline`,children:e}),(0,w.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,w.jsx)(`code`,{className:`min-w-0 flex-1 break-all text-xs`,"data-testid":n?`webhook-secret`:`webhook-url`,children:t}),(0,w.jsx)(s,{type:`button`,size:`sm`,variant:`outline`,"aria-label":`Copy ${e}`,onClick:async()=>{try{await navigator.clipboard.writeText(t),i(!0),o(!1)}catch{o(!0)}},children:r?`Copied`:`Copy`})]}),a&&(0,w.jsx)(`p`,{role:`alert`,className:`text-xs text-error`,children:`Select and copy the value above; clipboard access is unavailable.`})]})}function A({hook:e,secret:t,showInstructions:n=!0,instructionsId:r}){let i=S(e.token,l(),window.location.origin);return(0,w.jsxs)(`div`,{className:`space-y-3`,"data-testid":`webhook-setup`,children:[(0,w.jsx)(k,{label:`Payload URL`,value:i}),C(i)&&(0,w.jsx)(`p`,{className:`text-sm text-warning`,children:`This address is local. For external providers, use your publicly reachable ORC address with the same /webhooks/ path.`}),n&&(0,w.jsxs)(`div`,{id:r,"data-testid":`webhook-setup-instructions`,className:`space-y-3`,children:[t?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(k,{label:`Signing secret`,value:t,secret:!0}),(0,w.jsx)(`p`,{className:`text-xs text-outline`,children:`Copy the signing secret before leaving. It is shown once.`})]}):(0,w.jsx)(`p`,{className:`text-xs text-outline`,children:`The signing secret is hidden. Generate a replacement only if you need to reconnect the sender.`}),e.provider===`github`?(0,w.jsxs)(`ol`,{className:`list-decimal space-y-1 pl-5 text-sm text-outline`,children:[(0,w.jsx)(`li`,{children:`In your repository, open GitHub Settings - Webhooks - Add webhook.`}),(0,w.jsx)(`li`,{children:`Paste the Payload URL, select application/json, and enter the signing secret.`}),(0,w.jsx)(`li`,{children:`Select the events needed by your connected jobs. Each job has its own filters.`}),(0,w.jsx)(`li`,{children:`Send a test event, then open Recent deliveries for this webhook.`})]}):(0,w.jsx)(`p`,{className:`text-sm text-outline`,children:`Send JSON, signed with HMAC-SHA256 of the raw body. Set X-Orc-Signature-256 to sha256=<hex signature>, X-Orc-Event to the event name and X-Orc-Delivery to a unique delivery ID.`})]})]})}function j({hook:e}){let t=v(),n=b(),[r,i]=(0,m.useState)(!1),[a,c]=(0,m.useState)(!1),[l,u]=(0,m.useState)(!1),[d,f]=(0,m.useState)(),p=(0,m.useId)();return(0,w.jsxs)(`article`,{className:`space-y-3 border-b border-border pb-5`,"data-testid":`webhook-endpoint`,"data-webhook-id":e.id,children:[(0,w.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,w.jsx)(`h3`,{className:`text-sm font-medium`,children:e.name}),(0,w.jsxs)(`span`,{className:`text-xs text-outline`,children:[e.provider,` - `,e.enabled?`Enabled`:`Disabled`]}),(0,w.jsx)(s,{type:`button`,variant:`outline`,size:`sm`,disabled:t.isPending,onClick:()=>t.mutate({id:e.id,enabled:!e.enabled}),children:e.enabled?`Disable`:`Enable`})]}),(0,w.jsxs)(`div`,{className:`space-y-1`,"data-testid":`webhook-connected-jobs`,children:[(0,w.jsxs)(`p`,{className:`text-xs text-outline`,children:[`Connected jobs (`,e.subscriptions.length,`)`]}),e.subscriptions.length?e.subscriptions.map(e=>(0,w.jsxs)(`div`,{className:`text-sm`,children:[(0,w.jsx)(o,{className:`underline`,"data-testid":`webhook-job-link`,to:`/jobs/${e.job_id}?project=all`,children:e.name}),(0,w.jsxs)(`span`,{className:`text-xs text-outline`,children:[` `,`- `,e.enabled?`Enabled`:`Disabled`,`; events:`,` `,e.events.join(`, `)||`all`,`; actions:`,` `,e.actions.join(`, `)||`all`]})]},e.job_id)):null]}),(0,w.jsx)(A,{hook:e,secret:d,showInstructions:a,instructionsId:p}),(0,w.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,w.jsx)(s,{type:`button`,variant:`outline`,size:`sm`,"data-testid":`webhook-deliveries-toggle`,onClick:()=>i(!r),children:r?`Hide deliveries`:`Recent deliveries`}),(0,w.jsx)(s,{type:`button`,variant:`ghost`,size:`sm`,"data-testid":`webhook-setup-toggle`,"aria-expanded":a,"aria-controls":a?p:void 0,disabled:n.isPending,onClick:()=>{a&&f(void 0),c(!a),u(!1)},children:a?d?`I've copied the setup details`:`Hide setup`:`Setup instructions`})]}),a&&(0,w.jsx)(s,{type:`button`,variant:`ghost`,size:`sm`,disabled:n.isPending,onClick:()=>u(!l),children:`New signing secret`}),a&&l&&(0,w.jsxs)(`div`,{className:`space-y-2 text-sm`,children:[(0,w.jsx)(`p`,{children:`The sender's existing secret will stop working. Update it after generating the replacement.`}),(0,w.jsx)(s,{type:`button`,variant:`outline`,size:`sm`,disabled:n.isPending,onClick:()=>n.mutate(e.id,{onSuccess:e=>{f(e.secret),c(!0),u(!1)}}),children:`Generate replacement secret`})]}),(t.error||n.error)&&(0,w.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:(t.error??n.error)?.message}),r&&(0,w.jsx)(M,{id:e.id})]})}function M({id:e}){let{data:t,isLoading:n,error:r,refetch:i}=g(e);return(0,w.jsxs)(`section`,{className:`space-y-2`,"data-testid":`webhook-deliveries`,children:[(0,w.jsx)(`h4`,{className:`text-sm font-medium`,children:`Recent deliveries`}),r?(0,w.jsx)(p,{message:r.message,onRetry:()=>i()}):n?(0,w.jsx)(`p`,{role:`status`,children:`Loading deliveries...`}):t?.length?t.map(e=>(0,w.jsxs)(`div`,{className:`space-y-1 border-t border-border py-2 text-xs`,"data-testid":`webhook-delivery`,children:[(0,w.jsxs)(`div`,{className:`flex flex-wrap justify-between gap-2`,children:[(0,w.jsxs)(`span`,{children:[e.event,e.action?` / ${e.action}`:``]}),(0,w.jsx)(`span`,{children:e.status})]}),(0,w.jsxs)(`p`,{className:`text-outline`,children:[e.repository,` `,new Date(e.created_at).toLocaleString()]}),e.status===`ignored`&&(0,w.jsx)(`p`,{className:`text-outline`,children:`No enabled connected job matched this event.`}),e.error&&(0,w.jsx)(`p`,{className:`text-error`,children:e.error}),e.runs.map(e=>(0,w.jsxs)(`div`,{className:`flex flex-wrap gap-3`,children:[(0,w.jsxs)(o,{className:`underline`,to:`/jobs/${e.job_id}?project=all`,children:[`Job run: `,e.status]}),e.task_id&&(0,w.jsx)(o,{className:`underline`,to:`/tasks/${e.task_id}?project=all`,children:`Created task`}),e.session_id&&(0,w.jsx)(o,{className:`underline`,to:`/audit/${e.session_id}?project=all`,children:`Agent session`})]},e.job_run_id))]},e.id)):(0,w.jsx)(`p`,{className:`text-sm text-outline`,children:`No events received yet. Register the endpoint with your provider, then send an event.`})]})}export{y as a,D as i,E as n,h as o,j as r,O as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e}from"./rolldown-runtime-DSDNlrLa.js";import{n as t,t as n}from"./jsx-runtime-CVMpzJz9.js";import{t as r}from"./chunk-OB3PAWPO-1IihCzFx.js";import{t as i}from"./button-C91mbQEU.js";import{t as a}from"./label-BdnRgBbz.js";import{t as o}from"./scroll-area-Cmb_s_kX.js";import{a as s,i as c,n as l,o as u,r as d,t as f}from"./FormDialog-CelnA8hT.js";import{h as p}from"./client-BnTXPI20.js";import{t as m}from"./chevron-down-wgh-M0zj.js";import{t as h}from"./ResponsiveFilters-CQ42T3S8.js";import{t as g}from"./textarea-BRdsUa6B.js";import{a as _,i as v,o as y}from"./dialog-D86vkhdt.js";import{Ct as b,Ft as x,G as S,Hn as C,J as w,K as T,P as E,Pn as D,Rn as O,St as k,Tt as A,U as j,Vn as M,W as N,X as P,Y as F,er as I,ft as L,st as R,vt as z,wt as B,xt as V}from"./index-D5qFuDmc.js";import{t as H}from"./ConfirmDialog-DOSTWblx.js";import{a as U,c as W,i as ee,l as G,n as K,o as te,r as ne,s as re,t as ie}from"./useJobs-BNj4dd9l.js";import{t as ae}from"./StatusBadge-BUGpPpcH.js";import{t as q}from"./ErrorState-DprXzfow.js";import{t as oe}from"./ViewHeader-BtTaSrXy.js";import{t as se}from"./useDetailRoute-DOhAbdV7.js";import{t as J}from"./view-params-DD7i9s5g.js";import{t as ce}from"./EmptyState-YM4VSLR9.js";import{a as le,i as Y,n as ue,o as de,r as X,t as fe}from"./table-Q26Vm3R3.js";import{t as pe}from"./useProjectScope-DtEj9j-P.js";import{n as me,t as he}from"./useListSelection-DLQYrJX-.js";import{i as ge,t as _e}from"./JobWebhooks-BvKIhaAK.js";var ve={name:`play`,size:24,node:[[`path`,{d:`M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z`,key:`10ikf1`}]]};ve.node;var ye=p(ve),be={name:`power`,size:24,node:[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]};be.node;var xe=p(be),Z=e(t(),1),Q=n();function Se(e){return e.type===`command`?!!e.command.trim():e.type===`agent`?!!(e.prompt.trim()&&e.backend.trim()):!!e.title.trim()}function Ce({value:e,onChange:t}){let n=(0,Z.useId)(),{data:r}=L();return(0,Q.jsxs)(`section`,{className:`space-y-3 border-y border-border py-4`,"data-testid":`job-action-fields`,children:[(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{htmlFor:`${n}-type`,children:`What should this job do?`}),(0,Q.jsxs)(`select`,{id:`${n}-type`,"data-testid":`job-action-type`,className:`w-full min-h-8 rounded-md border border-control-border bg-background px-3 text-sm`,value:e.type,onChange:e=>{e.target.value===`command`&&t({type:`command`,command:``}),e.target.value===`agent`&&t({type:`agent`,backend:`codex-cli`,prompt:``,auto_approve:!1}),e.target.value===`task`&&t({type:`task`,title:``,body:``,start_automatically:!1})},children:[(0,Q.jsx)(`option`,{value:`command`,children:`Run command`}),(0,Q.jsx)(`option`,{value:`agent`,children:`Run agent`}),(0,Q.jsx)(`option`,{value:`task`,children:`Create task`})]})]}),e.type===`command`&&(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{htmlFor:`${n}-command`,children:`Command`}),(0,Q.jsx)(g,{id:`${n}-command`,"aria-label":`Command`,"data-testid":`job-command-input`,value:e.command,onChange:n=>t({...e,command:n.target.value}),rows:3,placeholder:`bun run build`,required:!0})]}),e.type===`agent`&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{htmlFor:`${n}-backend`,children:`Agent backend`}),(0,Q.jsx)(x,{id:`${n}-backend`,"data-testid":`job-agent-backend`,value:e.backend,list:`${n}-backends`,onChange:n=>t({...e,backend:n.target.value}),required:!0}),(0,Q.jsx)(`datalist`,{id:`${n}-backends`,children:r?.backends.map(e=>(0,Q.jsx)(`option`,{value:e.name,children:e.available?`Available`:`Unavailable`},e.name))})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{htmlFor:`${n}-model`,children:`Model (optional)`}),(0,Q.jsx)(x,{id:`${n}-model`,"data-testid":`job-agent-model`,value:e.model??``,onChange:n=>t({...e,model:n.target.value||void 0})})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{htmlFor:`${n}-prompt`,children:`Instructions`}),(0,Q.jsx)(g,{id:`${n}-prompt`,"data-testid":`job-agent-prompt`,value:e.prompt,onChange:n=>t({...e,prompt:n.target.value}),required:!0,rows:4})]}),(0,Q.jsxs)(`label`,{className:`flex min-h-11 items-center gap-2 text-sm`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:e.auto_approve,onChange:n=>t({...e,auto_approve:n.target.checked})}),`Allow agent tools automatically`]}),(0,Q.jsx)(`p`,{className:`text-xs text-outline`,children:`Starts a tracked agent session. When automatic tool approval is off, permission requests are denied.`})]}),e.type===`task`&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{htmlFor:`${n}-title`,children:`Task title`}),(0,Q.jsx)(x,{id:`${n}-title`,"data-testid":`job-task-title`,value:e.title,onChange:n=>t({...e,title:n.target.value}),required:!0,maxLength:200})]}),(0,Q.jsx)(E,{label:`Task instructions`,id:`${n}-body`,"data-testid":`job-task-body`,value:e.body,onChange:n=>t({...e,body:n}),rows:4}),(0,Q.jsxs)(`label`,{className:`flex min-h-11 items-center gap-2 text-sm`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,"data-testid":`job-task-autostart`,checked:e.start_automatically,onChange:n=>t({...e,start_automatically:n.target.checked})}),`Start the task flow automatically`]}),e.start_automatically&&(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{htmlFor:`${n}-flow`,children:`Flow (blank uses the configured default)`}),(0,Q.jsx)(x,{id:`${n}-flow`,"data-testid":`job-task-flow`,value:e.flow_name??``,onChange:n=>t({...e,flow_name:n.target.value||void 0})})]}),(0,Q.jsx)(`p`,{className:`text-xs text-outline`,children:`Creates a task in this job's project. Automatic start is off by default; the task waits for a manual flow start.`})]})]})}function we({jobId:e,open:t,onClose:n,onEdit:r,projectScope:a=`all`}){let{data:o,isLoading:s,error:c,refetch:l}=ne(e),u=o&&(a===`all`||(a===`unassigned`?o.project_id===null:o.project_id===a)),d=u?o:void 0;(0,Z.useEffect)(()=>{t&&o&&!u&&n()},[t,o,u,n]);let{data:f,isLoading:p,error:m,refetch:h}=U(d?.id??null),g=W(),_=G(),[v,y]=(0,Z.useState)(null);return(0,Q.jsx)(N,{open:t,onOpenChange:e=>!e&&n(),children:(0,Q.jsxs)(T,{"data-testid":`job-detail-sheet`,children:[(0,Q.jsxs)(F,{children:[(0,Q.jsx)(P,{children:d?.name??`Job details`}),d?.description&&(0,Q.jsx)(`p`,{className:`font-body text-xs text-outline mt-1`,children:d.description})]}),(0,Q.jsx)(S,{children:c?(0,Q.jsx)(q,{message:c.message,onRetry:()=>l()}):s?(0,Q.jsx)(`div`,{className:`space-y-3`,children:[...[,,,,,,]].map((e,t)=>(0,Q.jsx)(j,{className:`h-8 w-full bg-surface-highest`},t))}):d?(0,Q.jsxs)(`div`,{className:`space-y-6`,children:[(0,Q.jsxs)(`div`,{className:`space-y-4`,children:[(0,Q.jsx)(R,{label:`Action`,children:(0,Q.jsx)(`pre`,{className:`font-mono text-xs bg-background p-2 rounded-lg border border-surface-highest overflow-x-auto whitespace-pre-wrap break-all`,children:d.action?.type===`agent`?`Run agent (${d.action.backend}): ${d.action.prompt}`:d.action?.type===`task`?`Create task: ${d.action.title}`:d.command})}),(0,Q.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-4`,children:[(0,Q.jsx)(R,{label:`Trigger Type`,children:(0,Q.jsx)(`span`,{className:`font-label text-xs px-2 py-0.5 bg-surface-highest text-on-surface-variant border border-surface-highest/50 inline-flex`,children:d.trigger_type})}),(0,Q.jsx)(R,{label:`Enabled`,children:(0,Q.jsx)(`span`,{className:`font-label text-xs font-bold ${d.enabled?`text-secondary`:`text-outline`}`,children:d.enabled?`● ON`:`○ OFF`})})]}),d.cron_expr&&(0,Q.jsx)(R,{label:`Cron Expression`,children:(0,Q.jsx)(`code`,{className:`font-mono text-xs`,children:d.cron_expr})}),(0,Q.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-4`,children:[(0,Q.jsxs)(R,{label:`Timeout`,children:[d.timeout_secs,`s`]}),(0,Q.jsx)(R,{label:`Max Retries`,children:d.max_retries}),(0,Q.jsx)(R,{label:`Overlap`,children:d.overlap})]}),(0,Q.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-4`,children:[(0,Q.jsx)(R,{label:`Notify On`,children:d.notify_on}),(0,Q.jsx)(R,{label:`Run Count`,children:d.run_count})]}),d.next_run_at&&(0,Q.jsx)(R,{label:`Next Run`,children:new Date(d.next_run_at).toLocaleString()})]}),!d.command.startsWith(`__`)&&(0,Q.jsx)(_e,{job:d},d.id),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`font-label text-xs font-medium text-outline mb-3`,children:`Recent runs`}),m?(0,Q.jsx)(q,{message:m.message,onRetry:()=>h()}):p?(0,Q.jsx)(`div`,{className:`space-y-2`,children:[...[,,,]].map((e,t)=>(0,Q.jsx)(j,{className:`h-8 w-full bg-surface-highest`},t))}):f?.length?(0,Q.jsx)(`div`,{className:`space-y-1`,children:f.map(t=>(0,Q.jsx)(Te,{run:t,jobId:e,expanded:v===t.id,onToggle:()=>y(v===t.id?null:t.id)},t.id))}):(0,Q.jsx)(`div`,{className:`font-label text-xs text-outline py-4 text-center`,children:`No runs yet`})]})]}):(0,Q.jsx)(`p`,{className:`text-sm text-outline`,children:`Job not found`})}),(0,Q.jsxs)(w,{className:`flex-wrap`,children:[(_.error||g.error)&&(0,Q.jsx)(`p`,{role:`alert`,className:`w-full text-sm text-error`,children:(_.error??g.error)?.message}),d&&r&&(0,Q.jsxs)(i,{"data-testid":`job-detail-edit`,size:`sm`,variant:`outline`,onClick:()=>r(d),children:[(0,Q.jsx)(C,{size:16}),`Edit job`]}),d&&(0,Q.jsxs)(i,{size:`sm`,variant:`ghost`,disabled:_.isPending,onClick:()=>_.mutate({id:d.id,enabled:!d.enabled}),className:`font-label text-xs font-medium`,children:[(0,Q.jsx)(xe,{size:12,className:`mr-1.5`}),d.enabled?`Disable`:`Enable`]}),d&&(0,Q.jsxs)(i,{variant:`ghost`,size:`sm`,disabled:g.isPending,onClick:()=>g.mutate(d.id),className:`font-label text-xs font-medium bg-transparent text-on-surface border border-control-border hover:bg-surface`,children:[(0,Q.jsx)(ye,{size:12,className:`mr-1.5`}),g.isPending?`Triggering...`:`Trigger run`]})]})]})})}function Te({run:e,jobId:t,expanded:n,onToggle:i}){return(0,Q.jsxs)(`div`,{className:`min-w-0 border-y border-border overflow-hidden bg-background`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:i,"aria-expanded":n,className:`w-full flex items-center gap-3 px-3 py-2 hover:bg-surface transition-colors text-left`,children:[n?(0,Q.jsx)(m,{size:12,className:`text-outline shrink-0`}):(0,Q.jsx)(I,{size:12,className:`text-outline shrink-0`}),(0,Q.jsx)(ae,{status:e.status,type:`job`}),(0,Q.jsxs)(`span`,{className:`font-label text-xs text-outline flex-1`,children:[e.started_at?new Date(e.started_at).toLocaleString():`—`,e.ended_at&&(0,Q.jsxs)(`span`,{className:`ml-2`,children:[`\\u2192 `,new Date(e.ended_at).toLocaleString()]})]}),e.exit_code!==null&&(0,Q.jsxs)(`span`,{className:`font-mono text-xs ${e.exit_code===0?`text-secondary`:`text-error`}`,children:[`exit `,e.exit_code]})]}),(e.task_id||e.session_id)&&(0,Q.jsxs)(`div`,{className:`flex gap-3 px-3 py-2 text-xs`,children:[e.task_id&&(0,Q.jsx)(r,{className:`underline`,"data-testid":`job-run-task-link`,to:`/tasks/${e.task_id}?project=all`,children:`Created task`}),e.session_id&&(0,Q.jsx)(r,{className:`underline`,"data-testid":`job-run-session-link`,to:`/audit/${e.session_id}?project=all`,children:`Agent session`})]}),e.error_msg&&(0,Q.jsx)(`div`,{className:`px-3 pb-2`,children:(0,Q.jsx)(`span`,{className:`font-body text-xs text-error`,children:e.error_msg})}),n&&(0,Q.jsx)(Ee,{jobId:t,runId:e.id})]})}function Ee({jobId:e,runId:t}){let{data:n,isLoading:r,error:i,refetch:a}=ee(e,t);return i?(0,Q.jsx)(q,{message:i.message,onRetry:()=>a()}):r?(0,Q.jsx)(`div`,{className:`px-3 pb-3`,children:(0,Q.jsx)(j,{className:`h-24 w-full bg-surface-highest`})}):n?.length?(0,Q.jsx)(`div`,{className:`mx-3 mb-3 rounded-lg overflow-hidden border border-surface-highest`,children:(0,Q.jsx)(o,{className:`h-[240px]`,children:(0,Q.jsx)(`pre`,{className:`font-mono text-xs leading-relaxed bg-background p-3`,children:n.map(e=>(0,Q.jsx)(`div`,{className:e.stream===`stderr`?`text-error`:`text-on-surface`,children:e.line},e.id))})})}):(0,Q.jsx)(`div`,{className:`px-3 pb-3 font-label text-xs text-outline`,children:`No log output`})}var $=[`one-shot`,`cron`,`watch`,`webhook`,`manual`,`bridge-msg`],De=[`skip`,`queue`,`kill`],Oe=[`never`,`failure`,`always`];function ke({projectId:e}){let t=A(`xl`),[n,r]=J(`jobQuery`,``),[a,o]=J(`jobStatus`,`all`,[`all`,`enabled`,`disabled`]),[s,c]=J(`jobTrigger`,`all`,[`all`,...$]),l=pe(e),u=l===`all`||l===`unassigned`?void 0:l,{data:d,isLoading:f,error:p,refetch:m}=te({project_id:l===`all`?void 0:l,limit:100}),g=(l===`unassigned`?d?.filter(e=>e.project_id===null):d)?.filter(e=>(!n||`${e.name} ${e.description??``} ${e.command??``}`.toLowerCase().includes(n.toLowerCase()))&&(a===`all`||e.enabled===(a===`enabled`))&&(s===`all`||e.trigger_type===s)),_=JSON.stringify([l,n,a,s]),v=W(),y=K(),b=G(),S=re(),w=S.data?.scope===_?S.data:void 0,T=he((g??[]).map(e=>e.id),_);async function E(e){let t=await S.mutateAsync({ids:T.selectedIds,enabled:e,scope:_});T.select(t.failed.map(e=>e.id))}let{selectedId:k,openDetail:N,closeDetail:P}=se(`/jobs`,`jobId`),[F,I]=(0,Z.useState)(!1),[L,R]=(0,Z.useState)(null),[z,B]=(0,Z.useState)(null);if(p)return(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(oe,{title:`Jobs`}),(0,Q.jsx)(q,{message:p.message,onRetry:()=>m()})]});let V=(g??[]).filter(e=>e.enabled).length;return(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(oe,{title:`Jobs`,compact:!0,meta:`${V}/${(g??[]).length} enabled`,action:(0,Q.jsxs)(i,{"data-testid":`new-job-button`,size:`sm`,onClick:()=>I(!0),className:`font-label text-xs font-medium bg-primary text-primary-foreground hover:bg-primary/90`,children:[(0,Q.jsx)(M,{size:12,className:`mr-1`}),` New job`]})}),(0,Q.jsxs)(`div`,{className:`mb-4 flex flex-wrap items-center gap-2`,children:[(0,Q.jsxs)(`div`,{className:`relative min-w-0 flex-1 lg:max-w-md`,children:[(0,Q.jsx)(O,{size:14,className:`absolute left-3 top-1/2 -translate-y-1/2 text-outline`}),(0,Q.jsx)(x,{type:`search`,"aria-label":`Search jobs`,"data-testid":`job-search`,placeholder:`Search jobs…`,value:n,onChange:e=>r(e.target.value,{replace:!0}),className:`h-11 pl-9 text-base lg:h-9 lg:text-sm`})]}),(0,Q.jsxs)(h,{activeCount:Number(a!==`all`)+Number(s!==`all`),children:[(0,Q.jsxs)(`select`,{"aria-label":`Job status`,"data-testid":`job-status-filter`,value:a,onChange:e=>o(e.target.value),className:`form-control form-control-single max-w-full`,children:[(0,Q.jsx)(`option`,{value:`all`,children:`All statuses`}),(0,Q.jsx)(`option`,{value:`enabled`,children:`Enabled`}),(0,Q.jsx)(`option`,{value:`disabled`,children:`Disabled`})]}),(0,Q.jsxs)(`select`,{"aria-label":`Job trigger`,"data-testid":`job-trigger-filter`,value:s,onChange:e=>c(e.target.value),className:`form-control form-control-single max-w-full`,children:[(0,Q.jsx)(`option`,{value:`all`,children:`All triggers`}),$.map(e=>(0,Q.jsx)(`option`,{value:e,children:e},e))]})]})]}),(v.error||y.error||b.error)&&(0,Q.jsx)(`p`,{role:`alert`,className:`mb-4 text-sm text-error`,children:(v.error??y.error??b.error)?.message}),!!g?.length&&(0,Q.jsxs)(me,{resourceLabel:`jobs`,count:T.selectedIds.length,allSelected:T.allSelected,someSelected:T.someSelected,onSelectAll:T.selectAll,onClear:T.clear,disabled:S.isPending,children:[(0,Q.jsx)(i,{type:`button`,variant:`outline`,size:`sm`,"data-testid":`jobs-bulk-enable`,disabled:S.isPending||b.isPending,onClick:()=>void E(!0),children:`Enable selected`}),(0,Q.jsx)(i,{type:`button`,variant:`outline`,size:`sm`,"data-testid":`jobs-bulk-disable`,disabled:S.isPending||b.isPending,onClick:()=>void E(!1),children:`Disable selected`})]}),S.isPending&&(0,Q.jsx)(`p`,{role:`status`,className:`mb-3 text-sm text-outline`,children:`Updating selected jobs…`}),!S.isPending&&w&&(0,Q.jsxs)(`div`,{className:`mb-3 space-y-1 text-sm`,"data-testid":`jobs-bulk-result`,role:`status`,children:[(0,Q.jsxs)(`p`,{children:[w.succeeded.length,` jobs `,w.enabled?`enabled`:`disabled`,`.`]}),w.failed.map(e=>(0,Q.jsxs)(`p`,{className:`text-error`,children:[g?.find(t=>t.id===e.id)?.name??e.id,`: `,e.error,`. Still selected for retry.`]},e.id))]}),f?(0,Q.jsx)(`div`,{role:`status`,"aria-label":`Loading jobs`,className:`space-y-2`,children:[...[,,,]].map((e,t)=>(0,Q.jsx)(j,{className:`h-12 w-full bg-surface-highest`},t))}):(g??[]).length===0?(0,Q.jsx)(ce,{message:n||a!==`all`||s!==`all`?`No jobs match`:`No jobs configured`}):t?(0,Q.jsx)(`div`,{className:`min-w-0 overflow-hidden`,children:(0,Q.jsxs)(fe,{children:[(0,Q.jsx)(le,{children:(0,Q.jsxs)(de,{className:`border-b border-border hover:bg-transparent`,children:[(0,Q.jsx)(Y,{className:`w-11`,children:(0,Q.jsx)(`span`,{className:`sr-only`,children:`Select jobs`})}),(0,Q.jsx)(Y,{className:`font-label text-xs font-medium text-outline`,children:`Name`}),(0,Q.jsx)(Y,{className:`font-label text-xs font-medium text-outline w-24`,children:`Trigger`}),(0,Q.jsx)(Y,{className:`font-label text-xs font-medium text-outline w-48`,children:`Action`}),(0,Q.jsx)(Y,{className:`font-label text-xs font-medium text-outline w-16`,children:`Enabled`}),(0,Q.jsx)(Y,{className:`font-label text-xs font-medium text-outline w-36`,children:`Last Run`}),(0,Q.jsx)(Y,{className:`font-label text-xs font-medium text-outline w-16`,children:`Runs`}),(0,Q.jsx)(Y,{className:`font-label text-xs font-medium text-outline w-36`,children:`Next Run`}),(0,Q.jsx)(Y,{className:`w-28`})]})}),(0,Q.jsx)(ue,{children:(g??[]).map(e=>(0,Q.jsxs)(de,{"data-testid":`job-row`,"data-job-id":e.id,"data-job-name":e.name,className:`border-b border-border/65 hover:bg-surface-high cursor-pointer`,onClick:()=>N(e.id),children:[(0,Q.jsx)(X,{children:(0,Q.jsx)(`input`,{type:`checkbox`,className:`size-4 accent-primary`,"aria-label":`Select ${e.name}`,"data-testid":`job-select`,checked:T.selectedIds.includes(e.id),disabled:S.isPending,onClick:e=>e.stopPropagation(),onChange:()=>T.toggle(e.id)})}),(0,Q.jsxs)(X,{children:[(0,Q.jsx)(`button`,{type:`button`,className:`font-body text-sm font-medium text-on-surface text-left hover:text-primary`,"data-testid":`job-open-detail`,onClick:t=>{t.stopPropagation(),N(e.id)},children:e.name}),e.description&&(0,Q.jsx)(`div`,{className:`font-body text-sm text-outline mt-0.5 truncate max-w-[200px]`,children:e.description})]}),(0,Q.jsx)(X,{children:(0,Q.jsx)(`span`,{className:`font-label text-xs text-on-surface-variant inline-flex`,children:e.trigger_type})}),(0,Q.jsx)(X,{children:(0,Q.jsx)(`code`,{className:`font-mono text-xs text-outline truncate block max-w-[180px]`,children:e.action?.type===`agent`?`Agent: ${e.action.backend}`:e.action?.type===`task`?`Task: ${e.action.title}`:e.command})}),(0,Q.jsx)(X,{children:(0,Q.jsx)(i,{type:`button`,"data-testid":`job-toggle-enabled`,variant:`outline`,size:`sm`,"aria-label":`${e.enabled?`Disable`:`Enable`} ${e.name}`,"aria-pressed":e.enabled,disabled:b.isPending||S.isPending,onClick:t=>{t.stopPropagation(),b.mutate({id:e.id,enabled:!e.enabled})},children:e.enabled?`Disable`:`Enable`})}),(0,Q.jsx)(X,{className:`font-label text-xs text-outline`,children:e.last_run_at?new Date(e.last_run_at).toLocaleString():`—`}),(0,Q.jsx)(X,{className:`font-label text-xs text-outline`,children:e.run_count}),(0,Q.jsx)(X,{className:`font-label text-xs text-outline`,children:e.next_run_at?new Date(e.next_run_at).toLocaleString():`—`}),(0,Q.jsx)(X,{children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,onClick:e=>e.stopPropagation(),children:[(0,Q.jsxs)(i,{variant:`ghost`,"data-testid":`job-trigger`,size:`sm`,disabled:v.isPending,onClick:()=>v.mutate(e.id),className:`font-label text-sm min-h-8 px-3 bg-transparent text-on-surface border border-border hover:bg-surface-high`,children:[(0,Q.jsx)(ye,{size:10,className:`mr-1`}),` Run`]}),(0,Q.jsx)(i,{type:`button`,"data-testid":`job-edit`,variant:`ghost`,size:`icon`,"aria-label":`Edit ${e.name}`,onClick:()=>R(e),className:`inline-flex min-h-8 min-w-8 items-center justify-center rounded-md text-outline hover:text-primary hover:bg-surface-highest`,children:(0,Q.jsx)(C,{size:16})}),(0,Q.jsx)(i,{type:`button`,"data-testid":`job-delete`,variant:`ghost`,size:`icon`,"aria-label":`Delete ${e.name}`,onClick:()=>B(e),className:`inline-flex min-h-8 min-w-8 items-center justify-center rounded-md text-outline hover:text-error hover:bg-error/10`,children:(0,Q.jsx)(D,{size:12})})]})})]},e.id))})]})}):(0,Q.jsx)(`div`,{className:`divide-y divide-border`,children:(g??[]).map(e=>(0,Q.jsxs)(`article`,{"data-testid":`job-row`,"data-job-id":e.id,"data-job-name":e.name,className:`py-3 space-y-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,className:`size-4 accent-primary shrink-0 mt-1`,"aria-label":`Select ${e.name}`,"data-testid":`job-select`,checked:T.selectedIds.includes(e.id),disabled:S.isPending,onChange:()=>T.toggle(e.id)}),(0,Q.jsx)(`button`,{type:`button`,className:`min-w-0 flex-1 text-left font-medium text-sm text-on-surface wrap-break-word hover:text-primary`,"data-testid":`job-open-detail`,onClick:()=>N(e.id),children:e.name}),(0,Q.jsx)(i,{type:`button`,"data-testid":`job-toggle-enabled`,variant:`outline`,size:`sm`,"aria-label":`${e.enabled?`Disable`:`Enable`} ${e.name}`,"aria-pressed":e.enabled,disabled:b.isPending||S.isPending,onClick:()=>b.mutate({id:e.id,enabled:!e.enabled}),children:e.enabled?`Disable`:`Enable`})]}),e.description&&(0,Q.jsx)(`p`,{className:`text-sm text-outline wrap-break-word`,children:e.description}),(0,Q.jsx)(`code`,{className:`block whitespace-pre-wrap break-all text-xs text-on-surface-variant`,children:e.action?.type===`agent`?`Agent: ${e.action.backend}`:e.action?.type===`task`?`Task: ${e.action.title}`:e.command}),(0,Q.jsxs)(`p`,{className:`text-xs text-outline`,children:[e.trigger_type,` · `,e.run_count,` runs`,e.next_run_at?` · Next: ${new Date(e.next_run_at).toLocaleString()}`:``]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Q.jsxs)(i,{"data-testid":`job-edit`,variant:`ghost`,size:`sm`,onClick:()=>R(e),children:[(0,Q.jsx)(C,{}),`Edit`]}),(0,Q.jsxs)(i,{"data-testid":`job-trigger`,variant:`ghost`,size:`sm`,disabled:v.isPending,onClick:()=>v.mutate(e.id),children:[(0,Q.jsx)(ye,{}),`Run`]}),(0,Q.jsx)(i,{"data-testid":`job-delete`,"aria-label":`Delete ${e.name}`,variant:`ghost`,size:`icon`,onClick:()=>B(e),children:(0,Q.jsx)(D,{})})]})]},e.id))}),(0,Q.jsx)(we,{projectScope:l,jobId:k,open:!!k,onClose:P,onEdit:e=>{P(),R(e)}}),F&&(0,Q.jsx)(Ae,{defaultProjectId:u,open:F,onClose:()=>I(!1)}),L&&(0,Q.jsx)(je,{job:L,open:!!L,onClose:()=>R(null)}),z&&(0,Q.jsx)(H,{open:!!z,title:`Delete Job`,description:`Delete job "${z.name}"? This cannot be undone.`,confirmLabel:`Delete`,variant:`destructive`,isPending:y.isPending,onConfirm:()=>{y.mutate(z.id,{onSuccess:()=>B(null)})},onCancel:()=>B(null)})]})}function Ae({defaultProjectId:e,open:t,onClose:n}){let{data:r}=z(),o=B([{id:`details`,label:`Details`},{id:`execution`,label:`Execution`},{id:`automation`,label:`Automation`}],t),[p,m]=(0,Z.useState)(``),[h,g]=(0,Z.useState)(``),[S,C]=(0,Z.useState)({type:`command`,command:``}),[w,T]=(0,Z.useState)([]),[E,D]=(0,Z.useState)(`manual`),[O,A]=(0,Z.useState)(``),[j,M]=(0,Z.useState)(`300`),[N,P]=(0,Z.useState)(`0`),[F,I]=(0,Z.useState)(`skip`),[L,R]=(0,Z.useState)(`failure`),[H,U]=(0,Z.useState)(``),[W,ee]=(0,Z.useState)(e??``),G=ie(),[K,te]=(0,Z.useState)(!1),ne=(e,t=n)=>{if(e.preventDefault(),E===`webhook`&&!w.length){o.invalid(`automation`,`Select at least one webhook for this trigger.`);return}if(!p.trim()||!Se(S))return;let r={name:p.trim(),description:h.trim(),action:S,webhooks:E===`webhook`?w:[],trigger_type:E,enabled:K,cron_expr:E===`cron`&&O.trim()||void 0,timeout_secs:Number.parseInt(j,10)||void 0,max_retries:Number.parseInt(N,10),overlap:F,notify_on:L,project_id:W||void 0,working_dir:H.trim()||void 0};G.mutate(r,{onSuccess:t})};return(0,Q.jsx)(f,{open:t,onClose:n,busy:G.isPending,dirty:JSON.stringify([p,h,S,w,E,O,j,N,F,L,H,W,K])!==JSON.stringify([``,``,{type:`command`,command:``},[],`manual`,``,`300`,`0`,`skip`,`failure`,``,e??``,!1]),children:(e,t)=>(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(_,{children:(0,Q.jsx)(y,{className:`font-headline text-sm font-medium text-on-surface`,children:`New job`})}),(0,Q.jsx)(`form`,{noValidate:!0,ref:o.form,onSubmit:e=>o.submit(e,()=>ne(e,t)),className:`min-h-0`,children:(0,Q.jsxs)(b,{steps:o,children:[(0,Q.jsxs)(`div`,{className:`work-form-body space-y-4`,children:[(0,Q.jsxs)(k,{steps:o,id:`details`,children:[(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{className:`font-label text-xs font-medium text-outline`,children:`Name *`}),(0,Q.jsx)(x,{required:!0,"aria-label":`Name`,"data-testid":`job-name-input`,value:p,onChange:e=>m(e.target.value),placeholder:`Job name...`,className:`bg-background border-control-border text-on-surface font-body text-sm`,autoFocus:!0})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{className:`font-label text-xs font-medium text-outline`,children:`Description`}),(0,Q.jsx)(x,{"aria-label":`Description`,value:h,onChange:e=>g(e.target.value),placeholder:`Optional description...`,className:`bg-background border-control-border text-on-surface font-body text-sm`})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{className:`font-label text-xs font-medium text-outline`,children:`Project`}),(0,Q.jsxs)(l,{value:W||`__none__`,onValueChange:e=>{ee(e===`__none__`?``:e),T([])},children:[(0,Q.jsx)(s,{"aria-label":`Project`,"data-testid":`job-project-select`,className:`bg-background border-control-border text-on-surface font-body text-sm min-h-8`,children:(0,Q.jsx)(u,{})}),(0,Q.jsxs)(d,{className:`bg-surface border-border`,children:[(0,Q.jsx)(c,{value:`__none__`,className:`font-body text-sm`,children:`None`}),r?.map(e=>(0,Q.jsx)(c,{value:e.id,className:`font-body text-sm`,children:e.name},e.id))]})]})]})]}),(0,Q.jsxs)(k,{steps:o,id:`execution`,children:[(0,Q.jsx)(Ce,{value:S,onChange:C}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{className:`font-label text-xs font-medium text-outline`,children:`Working Dir`}),(0,Q.jsx)(x,{"aria-label":`Working directory`,value:H,onChange:e=>U(e.target.value),placeholder:`/path/to/dir`,className:`bg-background border-control-border text-on-surface font-body text-sm`})]}),(0,Q.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-3 md:col-span-2`,children:[(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{className:`font-label text-xs font-medium text-outline`,children:`Timeout (s)`}),(0,Q.jsx)(x,{"aria-label":`Timeout in seconds`,type:`number`,min:1,required:!0,value:j,onChange:e=>M(e.target.value),className:`bg-background border-control-border text-on-surface font-body text-sm`})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{className:`font-label text-xs font-medium text-outline`,children:`Retries`}),(0,Q.jsx)(x,{"aria-label":`Maximum retries`,type:`number`,min:0,required:!0,value:N,onChange:e=>P(e.target.value),className:`bg-background border-control-border text-on-surface font-body text-sm`})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{className:`font-label text-xs font-medium text-outline`,children:`Overlap`}),(0,Q.jsxs)(l,{value:F,onValueChange:e=>I(e),children:[(0,Q.jsx)(s,{"aria-label":`Overlap`,className:`bg-background border-control-border text-on-surface font-body text-sm min-h-8`,children:(0,Q.jsx)(u,{})}),(0,Q.jsx)(d,{className:`bg-surface border-border`,children:De.map(e=>(0,Q.jsx)(c,{value:e,className:`font-body text-sm`,children:e},e))})]})]})]})]}),(0,Q.jsxs)(k,{steps:o,id:`automation`,children:[(0,Q.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2 md:col-span-2`,children:[(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{className:`font-label text-xs font-medium text-outline`,children:`Trigger`}),(0,Q.jsxs)(l,{value:E,onValueChange:e=>D(e),children:[(0,Q.jsx)(s,{"aria-label":`Trigger type`,"data-testid":`job-trigger-type`,className:`bg-background border-control-border text-on-surface font-body text-sm min-h-8`,children:(0,Q.jsx)(u,{})}),(0,Q.jsx)(d,{className:`bg-surface border-border`,children:$.map(e=>(0,Q.jsx)(c,{value:e,"data-testid":`job-trigger-${e}`,className:`font-body text-sm`,children:e},e))})]})]}),E===`webhook`&&(0,Q.jsx)(`div`,{className:`sm:col-span-2`,children:(0,Q.jsx)(ge,{value:w,onChange:T,projectId:W||void 0})}),E===`cron`&&(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{className:`font-label text-xs font-medium text-outline`,children:`Cron expression`}),(0,Q.jsx)(x,{required:!0,"aria-label":`Cron expression`,value:O,onChange:e=>A(e.target.value),placeholder:`*/5 * * * *`,className:`bg-background border-control-border text-on-surface font-mono text-xs`})]})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{className:`font-label text-xs font-medium text-outline`,children:`Notify On`}),(0,Q.jsxs)(l,{value:L,onValueChange:e=>R(e),children:[(0,Q.jsx)(s,{"aria-label":`Notify on`,className:`bg-background border-control-border text-on-surface font-body text-sm min-h-8`,children:(0,Q.jsx)(u,{})}),(0,Q.jsx)(d,{className:`bg-surface border-border`,children:Oe.map(e=>(0,Q.jsx)(c,{value:e,className:`font-body text-sm`,children:e},e))})]})]}),(0,Q.jsxs)(`label`,{className:`flex min-h-11 items-center gap-3 text-sm md:col-span-2`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,"data-testid":`job-create-enabled`,checked:K,onChange:e=>te(e.target.checked),className:`size-4 accent-primary`}),`Enable this job immediately`]}),(0,Q.jsx)(`p`,{className:`text-xs text-outline md:col-span-2`,children:`Created disabled unless you enable it above.`})]}),(0,Q.jsx)(`div`,{className:`md:col-span-2`,children:G.error&&(0,Q.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:G.error.message})}),o.error&&(0,Q.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:o.error})]}),(0,Q.jsxs)(v,{className:`work-form-footer`,children:[(0,Q.jsx)(i,{type:`button`,variant:`ghost`,size:`sm`,"data-testid":`form-cancel`,onClick:e,className:`font-label text-xs text-outline`,children:`Cancel`}),(0,Q.jsx)(V,{steps:o,busy:G.isPending,children:(0,Q.jsx)(i,{"data-testid":`job-submit`,type:`submit`,size:`sm`,disabled:G.isPending,className:`font-label text-xs bg-primary text-primary-foreground hover:bg-primary/90`,children:G.isPending?`Creating...`:E===`webhook`?`Create job`:`Create`})})]})]})})]})})}function je({job:e,open:t,onClose:n}){let r=B([{id:`details`,label:`Details`},{id:`execution`,label:`Execution`},{id:`automation`,label:`Automation`}],t),[o,p]=(0,Z.useState)(e.name),[m,h]=(0,Z.useState)(e.description??``),[g,S]=(0,Z.useState)(e.action??{type:`command`,command:e.command}),[C,w]=(0,Z.useState)(e.webhooks??[]),[T,E]=(0,Z.useState)(e.trigger_type),[D,O]=(0,Z.useState)(e.cron_expr??``),[A,j]=(0,Z.useState)(String(e.timeout_secs)),[M,N]=(0,Z.useState)(String(e.max_retries)),[P,F]=(0,Z.useState)(e.overlap),[I,L]=(0,Z.useState)(e.notify_on),[R,z]=(0,Z.useState)(e.enabled),H=G(),U=(t,i=n)=>{if(t.preventDefault(),T===`webhook`&&!C.length){r.invalid(`automation`,`Select at least one webhook for this trigger.`);return}if(!o.trim()||!Se(g))return;let a={id:e.id,name:o.trim(),description:m.trim(),action:g,webhooks:T===`webhook`?C:[],trigger_type:T,cron_expr:T===`cron`&&D.trim()||void 0,timeout_secs:Number.parseInt(A,10)||void 0,max_retries:Number.parseInt(M,10),overlap:P,notify_on:I,enabled:R};H.mutate(a,{onSuccess:i})};return(0,Q.jsx)(f,{open:t,onClose:n,busy:H.isPending,dirty:JSON.stringify([o,m,g,C,T,D,A,M,P,I,R])!==JSON.stringify([e.name,e.description??``,e.action??{type:`command`,command:e.command},e.webhooks??[],e.trigger_type,e.cron_expr??``,String(e.timeout_secs),String(e.max_retries),e.overlap,e.notify_on,e.enabled]),children:(t,n)=>(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(_,{children:(0,Q.jsx)(y,{className:`font-headline text-sm font-medium text-on-surface`,children:`Edit job`})}),(0,Q.jsx)(`form`,{noValidate:!0,ref:r.form,id:`edit-job-form`,onSubmit:e=>r.submit(e,()=>U(e,n)),className:`min-h-0`,children:(0,Q.jsxs)(b,{steps:r,children:[(0,Q.jsxs)(`div`,{className:`work-form-body space-y-4`,children:[(0,Q.jsxs)(k,{steps:r,id:`details`,children:[(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{className:`font-label text-xs font-medium text-outline`,children:`Name *`}),(0,Q.jsx)(x,{required:!0,"aria-label":`Name`,value:o,onChange:e=>p(e.target.value),className:`bg-background border-control-border text-on-surface font-body text-sm`})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{className:`font-label text-xs font-medium text-outline`,children:`Description`}),(0,Q.jsx)(x,{"aria-label":`Description`,value:m,onChange:e=>h(e.target.value),className:`bg-background border-control-border text-on-surface font-body text-sm`})]})]}),(0,Q.jsxs)(k,{steps:r,id:`execution`,children:[(0,Q.jsx)(Ce,{value:g,onChange:S}),(0,Q.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-3 md:col-span-2`,children:[(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{className:`font-label text-xs font-medium text-outline`,children:`Timeout (s)`}),(0,Q.jsx)(x,{"aria-label":`Timeout in seconds`,type:`number`,min:1,required:!0,value:A,onChange:e=>j(e.target.value),className:`bg-background border-control-border text-on-surface font-body text-sm`})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{className:`font-label text-xs font-medium text-outline`,children:`Retries`}),(0,Q.jsx)(x,{"aria-label":`Maximum retries`,type:`number`,min:0,required:!0,value:M,onChange:e=>N(e.target.value),className:`bg-background border-control-border text-on-surface font-body text-sm`})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{className:`font-label text-xs font-medium text-outline`,children:`Overlap`}),(0,Q.jsxs)(l,{value:P,onValueChange:e=>F(e),children:[(0,Q.jsx)(s,{"aria-label":`Overlap`,className:`bg-background border-control-border text-on-surface font-body text-sm min-h-8`,children:(0,Q.jsx)(u,{})}),(0,Q.jsx)(d,{className:`bg-surface border-border`,children:De.map(e=>(0,Q.jsx)(c,{value:e,className:`font-body text-sm`,children:e},e))})]})]})]})]}),(0,Q.jsxs)(k,{steps:r,id:`automation`,children:[(0,Q.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2 md:col-span-2`,children:[(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{className:`font-label text-xs font-medium text-outline`,children:`Trigger`}),(0,Q.jsxs)(l,{value:T,onValueChange:e=>E(e),children:[(0,Q.jsx)(s,{"aria-label":`Trigger type`,"data-testid":`job-trigger-type`,className:`bg-background border-control-border text-on-surface font-body text-sm min-h-8`,children:(0,Q.jsx)(u,{})}),(0,Q.jsx)(d,{className:`bg-surface border-border`,children:$.map(e=>(0,Q.jsx)(c,{value:e,"data-testid":`job-trigger-${e}`,className:`font-body text-sm`,children:e},e))})]})]}),T===`webhook`&&(0,Q.jsx)(`div`,{className:`sm:col-span-2`,children:(0,Q.jsx)(ge,{value:C,onChange:w,projectId:e.project_id??void 0})}),T===`cron`&&(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{className:`font-label text-xs font-medium text-outline`,children:`Cron expression`}),(0,Q.jsx)(x,{required:!0,"aria-label":`Cron expression`,value:D,onChange:e=>O(e.target.value),placeholder:`*/5 * * * *`,className:`bg-background border-control-border text-on-surface font-mono text-xs`})]})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{className:`font-label text-xs font-medium text-outline`,children:`Notify On`}),(0,Q.jsxs)(l,{value:I,onValueChange:e=>L(e),children:[(0,Q.jsx)(s,{"aria-label":`Notify on`,className:`bg-background border-control-border text-on-surface font-body text-sm min-h-8`,children:(0,Q.jsx)(u,{})}),(0,Q.jsx)(d,{className:`bg-surface border-border`,children:Oe.map(e=>(0,Q.jsx)(c,{value:e,className:`font-body text-sm`,children:e},e))})]})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{className:`font-label text-xs font-medium text-outline`,children:`Enabled`}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>z(!R),className:`w-full min-h-11 rounded-md flex items-center justify-center border font-label text-xs font-medium transition-colors ${R?`bg-surface-highest text-on-surface border-border`:`bg-background text-outline border-border`}`,children:R?`● Enabled`:`○ Disabled`})]})]}),(0,Q.jsx)(`div`,{className:`md:col-span-2`,children:H.error&&(0,Q.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:H.error.message})}),r.error&&(0,Q.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:r.error})]}),(0,Q.jsxs)(v,{className:`work-form-footer`,children:[(0,Q.jsx)(i,{type:`button`,variant:`ghost`,size:`sm`,"data-testid":`form-cancel`,onClick:t,className:`font-label text-xs text-outline`,children:`Cancel`}),(0,Q.jsx)(V,{steps:r,busy:H.isPending,children:(0,Q.jsx)(i,{"data-testid":`job-edit-submit`,form:`edit-job-form`,type:`submit`,size:`sm`,disabled:H.isPending,className:`font-label text-xs bg-primary text-primary-foreground hover:bg-primary/90`,children:H.isPending?`Saving...`:`Save`})})]})]})})]})})}export{ke as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e}from"./rolldown-runtime-DSDNlrLa.js";import{n as t,t as n}from"./jsx-runtime-CVMpzJz9.js";import{n as r}from"./QueryClientProvider-DlPztvhd.js";import{n as i,t as a}from"./useMutation-HX90wI4L.js";import{f as o,m as s,p as c,t as l,u}from"./chunk-OB3PAWPO-1IihCzFx.js";import{l as d,t as f,u as p}from"./button-C91mbQEU.js";import{a as m,c as h,i as g,l as _,n as v,o as y,s as b,t as x}from"./x-CIaAKXRo.js";import{t as S}from"./label-BdnRgBbz.js";import{a as C,i as w,n as T,o as E,r as D,t as O}from"./FormDialog-CelnA8hT.js";import{h as k,n as A}from"./client-BnTXPI20.js";import{t as j}from"./chevron-down-wgh-M0zj.js";import{t as M}from"./download-6d5_Jyox.js";import{t as N}from"./MarkdownEditor-CSloDLyL.js";import{t as ee}from"./ResponsiveFilters-CQ42T3S8.js";import{t as P}from"./upload-BLDr7Cwk.js";import{t as te}from"./Markdown-CtVGTUZH.js";import{t as F}from"./textarea-BRdsUa6B.js";import{a as I,i as L,n as R,o as z,t as B}from"./dialog-D86vkhdt.js";import{An as ne,Bn as V,C as re,Cn as ie,Ct as ae,Dn as H,En as U,F as oe,Ft as W,G as se,Gn as ce,Hn as le,In as ue,K as de,Mt as fe,Nn as pe,Nt as me,On as he,P as ge,Pn as _e,Pt as ve,Qn as ye,Rn as be,S as xe,Sn as Se,St as Ce,Tt as we,U as Te,Vn as Ee,W as De,X as Oe,Xn as ke,Y as Ae,Zn as je,ar as Me,cr as Ne,dr as Pe,er as Fe,fr as Ie,ft as Le,jn as Re,kn as G,lr as ze,lt as Be,rr as Ve,sr as He,st as Ue,ur as We,vt as Ge,wn as Ke,wt as qe,xn as K,xt as Je,yn as Ye}from"./index-D5qFuDmc.js";import{n as Xe}from"./wiki-links-A52THGx_.js";import{t as Ze}from"./ConfirmDialog-DOSTWblx.js";import{t as Qe}from"./save-file-3ZpJah8W.js";import{t as $e}from"./ErrorState-DprXzfow.js";import{t as et}from"./ViewHeader-BtTaSrXy.js";import{t as tt}from"./view-params-DD7i9s5g.js";import{t as nt}from"./EmptyState-YM4VSLR9.js";import{a as rt,i as it,n as at,o as ot,r as st,t as ct}from"./table-Q26Vm3R3.js";import{t as lt}from"./useProjectScope-DtEj9j-P.js";import{a as ut,c as dt,i as ft,n as pt,o as mt,r as ht,s as gt,t as _t}from"./useMemories-BpfvcV2g.js";import{n as vt,t as yt}from"./DocumentWorkspace-DVnU3uMP.js";import{_ as bt,a as xt,c as St,d as Ct,f as wt,g as Tt,i as Et,l as Dt,m as Ot,n as kt,o as At,p as jt,r as q,s as Mt,t as Nt,u as Pt,v as Ft}from"./badge-CpU0J4qt.js";import{t as It}from"./TagInput-BmRYPN4B.js";import{n as Lt,t as Rt}from"./NativeFolderField-DwXF9tJW.js";var zt={name:`file-down`,size:24,node:[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M12 18v-6`,key:`17g6i2`}],[`path`,{d:`m9 15 3 3 3-3`,key:`1npd3o`}]]};zt.node;var Bt=k(zt),Vt={name:`file-plus`,size:24,node:[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M9 15h6`,key:`cctwl0`}],[`path`,{d:`M12 18v-6`,key:`17g6i2`}]]};Vt.node;var Ht=k(Vt),Ut={name:`file-up`,size:24,node:[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M12 12v6`,key:`3ahymv`}],[`path`,{d:`m15 15-3-3-3 3`,key:`15xj92`}]]};Ut.node;var Wt=k(Ut),Gt={name:`folder-sync`,size:24,node:[[`path`,{d:`M9 20H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v.5`,key:`1dkoa9`}],[`path`,{d:`M12 10v4h4`,key:`1czhmt`}],[`path`,{d:`m12 14 1.535-1.605a5 5 0 0 1 8 1.5`,key:`lvuxfi`}],[`path`,{d:`M22 22v-4h-4`,key:`1ewp4q`}],[`path`,{d:`m22 18-1.535 1.605a5 5 0 0 1-8-1.5`,key:`14ync0`}]]};Gt.node;var Kt=k(Gt),qt={name:`panel-right`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}]]};qt.node;var Jt=k(qt),J=e(t(),1),Y=[`mcp`,`api`,`cli`,`ui`],Yt=[`fetch`,`cited`,`search_hit`],Xt=G().trim().min(1).max(120),Zt=K(Ye(Y)).max(Y.length).transform(e=>Y.filter(t=>e.includes(t)));H({name:Xt,description:G().trim().max(2e3).default(``),project_id:G().min(1).nullable(),editable_by:Zt.default([...Y]),parser:G().min(1).max(40).nullable().default(null)}).strict(),H({name:Xt.optional(),description:G().trim().max(2e3).optional(),editable_by:Zt.optional(),parser:G().min(1).max(40).nullable().optional()}).strict();var Qt=[`default`,`project`,`global`,`all`],$t=G().trim().min(1).max(500).refine(e=>!e.startsWith(`/`)&&!e.includes(`\\`)&&!e.includes(`:`)&&!e.includes(`\0`)&&e.split(`/`).every(e=>e&&e!==`.`&&e!==`..`),`Use a relative path with / separators and no . or .. segments`),en=K(G().trim().min(1).max(60)).max(30),tn=2097152;H({title:G().trim().min(1).max(300),path:$t.optional(),description:G().trim().max(2e3).optional(),labels:en.default([]),content:G().max(tn),note:G().trim().max(1e3).optional(),derived_from:K(G().min(1)).max(50).default([])}).strict(),H({expected_revision:U().int().min(1),title:G().trim().min(1).max(300).optional(),path:$t.optional(),description:G().trim().max(2e3).optional(),labels:en.optional(),content:G().max(tn).optional(),note:G().trim().max(1e3).optional(),derived_from:K(G().min(1)).max(50).optional()}).strict();var nn=H({kind:Ye([`heading`,`paragraph`,`list_item`,`table`,`code`]),text:G(),level:U().int().min(1).max(6).optional(),rows:K(K(G())).optional(),heading_path:K(G()),locator:H({page:U().int().min(1).optional(),sheet:G().optional(),bbox:K(U()).length(4).optional()}).optional()});H({schema_version:Ke(1),parser:H({id:G(),version:G(),options:he(G(),Re())}),source_sha256:G().regex(/^[0-9a-f]{64}$/),status:Ye([`ok`,`partial`,`failed`]),language:G().optional(),blocks:K(nn),markdown:G(),warnings:K(G()),timings_ms:he(G(),U()).optional(),peak_rss_mb:U().optional()});var rn=[`auto`,`lexical`,`semantic`,`hybrid`];H({query:G().trim().min(1).max(2e3),scope:Ye(Qt).default(`default`),kb_ids:K(G().min(1)).max(50).optional(),labels:K(G().min(1)).max(20).optional(),media_types:K(G().min(1)).max(20).optional(),mode:Ye(rn).default(`auto`),limit:U().int().min(1).max(50).default(10)}).strict().omit({limit:!0,mode:!0}).extend({mode:Ye(rn).default(`auto`),token_budget:U().int().min(500).max(32e3).default(6e3),max_per_document:U().int().min(1).max(10).default(3)}).strict();var an=H({old:G().min(1).max(tn),new:G().max(tn),replace_all:Se().optional()}).strict(),on=H({start_line:U().int().min(1),end_line:U().int().min(0),new:G().max(tn)}).strict();H({expected_revision:U().int().min(1),edits:K(ne([an,on])).min(1).max(50),note:G().trim().min(1).max(1e3)}).strict();var sn=[`open`,`resolved`,`dismissed`];H({document_id:G().min(1).nullable().optional(),body:G().trim().min(1).max(1e4)}).strict(),H({status:Ye([`resolved`,`dismissed`]),reply:G().trim().min(1).max(4e3)}).strict();var cn=ie(`type`,[H({type:Ke(`cron`),cron:G().trim().min(1).max(120)}).strict(),H({type:Ke(`manual`)}).strict()]);H({instructions:G().trim().min(1).max(2e4).optional(),backend:G().min(1).max(64).regex(/^[a-z][a-z0-9_-]*$/).optional(),schedule:cn.optional(),enabled:Se().optional(),timeout_secs:U().int().min(60).max(7200).optional()}).strict();var ln=`0 3 * * *`,X=n();function un({title:e,testId:t,toggleTestId:n,summary:r,actions:i,expanded:a=!1,onExpandedChange:o,heading:s=`h3`,compact:c=!1,children:l}){let u=(0,J.useId)(),f=l!==void 0&&o!==void 0;return(0,X.jsxs)(`section`,{"data-testid":t,"data-expanded":f?a:void 0,"aria-labelledby":`${u}-heading`,className:`min-w-0 text-sm`,children:[(0,X.jsxs)(`div`,{className:d(`grid min-h-12 min-w-0 grid-cols-[minmax(0,1fr)_auto] items-center gap-x-3 gap-y-0.5 py-1.5`,!c&&`sm:grid-cols-[9rem_minmax(0,1fr)_auto]`),children:[(0,X.jsx)(s,{id:`${u}-heading`,className:`min-w-0 font-medium`,children:f?(0,X.jsxs)(`button`,{type:`button`,"data-testid":n,"aria-expanded":a,"aria-controls":u,className:`-ml-1 flex min-h-9 items-center gap-1.5 rounded px-1 text-left hover:bg-surface-high`,onClick:()=>o(!a),children:[(0,X.jsx)(Fe,{size:14,"aria-hidden":!0,className:d(`shrink-0 text-outline transition-transform`,a&&`rotate-90`)}),e]}):(0,X.jsx)(`span`,{className:`flex min-h-9 items-center pl-5`,children:e})}),(0,X.jsx)(`div`,{className:d(`col-span-2 row-start-2 flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 pl-5`,!c&&`sm:col-span-1 sm:col-start-2 sm:row-start-1 sm:pl-0`),children:r}),(0,X.jsx)(`div`,{className:d(`col-start-2 row-start-1 flex items-center justify-end gap-1`,!c&&`sm:col-start-3`),children:i})]}),f&&a&&(0,X.jsx)(`div`,{id:u,className:`min-w-0 pb-4 pl-5 pt-1`,children:l})]})}function Z({tone:e}){return(0,X.jsx)(`span`,{"aria-hidden":!0,className:d(`size-1.5 shrink-0 rounded-full`,e===`ok`&&`bg-secondary`,e===`warning`&&`bg-warning`,e===`error`&&`bg-error`,e===`off`&&`bg-muted-foreground`,e===`progress`&&`bg-progress`)})}var dn=[`Sunday`,`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`],fn=/^\d+$/,pn=e=>e.padStart(2,`0`),mn=e=>/^\*\/(\d+)$/.exec(e)?.[1],hn=(e,t)=>e===`1`?`Every ${t}`:`Every ${e} ${t}s`;function gn(e){let[t=``,n=``,r,i,a=``,...o]=e.trim().split(/\s+/);if(o.length||r!==`*`||i!==`*`)return e;if(n===`*`&&a===`*`){if(t===`*`)return`Every minute`;let n=mn(t);return n?hn(n,`minute`):fn.test(t)?Number(t)?`Every hour at :${pn(t)}`:`Every hour`:e}if(!fn.test(t))return e;let s=mn(n);if(s&&a===`*`)return`${hn(s,`hour`)}${Number(t)?` at :${pn(t)}`:``}`;if(!fn.test(n))return e;let c=`${pn(n)}:${pn(t)}`;return a===`*`?`Daily at ${c}`:a===`1-5`?`Weekdays at ${c}`:a===`0,6`||a===`6,0`?`Weekends at ${c}`:/^[0-7]$/.test(a)?`${dn[Number(a)%7]}s at ${c}`:e}var _n=[{name:`minute`,min:0,max:59,names:[]},{name:`hour`,min:0,max:23,names:[]},{name:`day of month`,min:1,max:31,names:[]},{name:`month`,min:1,max:12,names:[`JAN`,`FEB`,`MAR`,`APR`,`MAY`,`JUN`,`JUL`,`AUG`,`SEP`,`OCT`,`NOV`,`DEC`]},{name:`weekday`,min:0,max:7,names:[`SUN`,`MON`,`TUE`,`WED`,`THU`,`FRI`,`SAT`]}];function vn(e,t){let n=e=>{let n=t.names.indexOf(e.toUpperCase()),r=n>=0?n+ +(t.min===1):fn.test(e)?Number(e):NaN;return r>=t.min&&r<=t.max?r:NaN};return e.split(`,`).every(e=>{let t=/^(\*|[a-z0-9]+(?:-[a-z0-9]+)?)(?:\/(\d+))?$/i.exec(e);if(!t?.[1]||t[2]!==void 0&&Number(t[2])<1)return!1;if(t[1]===`*`)return!0;let[r=``,i]=t[1].split(`-`);return i===void 0?!Number.isNaN(n(r)):n(r)<=n(i)})}function yn(e){let t=e.trim().split(/\s+/).filter(Boolean);if(!t.length)return`Enter a cron expression.`;if(t.length!==5)return`A cron expression has 5 fields (minute hour day month weekday); this one has ${t.length}.`;for(let[e,n]of _n.entries()){let r=t[e]??``;if(!vn(r,n))return`The ${n.name} field "${r}" is not valid. Use a number from ${n.min} to ${n.max}, *, a range (1-5), a list (1,3) or a step (*/2).`}return null}function bn(e){let t=Math.max(0,Math.round((e-Date.now())/1e3));if(t<60)return`in under a minute`;if(t<3600)return`in ${Math.round(t/60)}m`;if(t<86400)return`in ${Math.round(t/3600)}h`;let n=new Date(e);return`${dn[n.getDay()]?.slice(0,3)} ${pn(String(n.getHours()))}:${pn(String(n.getMinutes()))}`}function xn(e){let t=Math.max(0,Math.round((Date.now()-e)/1e3));return t<60?`just now`:t<3600?`${Math.round(t/60)}m ago`:t<86400?`${Math.round(t/3600)}h ago`:`${Math.round(t/86400)}d ago`}function Sn(e){let t=e.last_run?.status;return t===`running`?`progress`:e.schedule.type===`cron`&&!e.enabled?`off`:t===`failed`?`error`:t===`completed`?`ok`:`off`}function Cn({kb:e}){let t=xt(e.id),[n,r]=(0,J.useState)(null),[i,a]=(0,J.useState)(!1),o=t.data;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(un,{title:`Digest`,testId:`kb-digest`,toggleTestId:`kb-digest-expand`,expanded:i,onExpandedChange:a,summary:t.error?(0,X.jsx)(`span`,{role:`alert`,className:`text-error`,children:t.error.message}):t.isLoading?(0,X.jsx)(`span`,{className:`text-outline`,children:`Loading…`}):o?(0,X.jsx)(wn,{digest:o}):(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-outline`,"data-testid":`kb-digest-off`,children:[(0,X.jsx)(Z,{tone:`off`}),`Off, documents change only when someone edits them`]}),actions:o?(0,X.jsx)(Tn,{kb:e,digest:o,onStarted:()=>a(!0)}):t.data===null?(0,X.jsx)(f,{size:`sm`,variant:`outline`,"data-testid":`kb-digest-add`,onClick:()=>r(`edit`),children:`Set up`}):null,children:o?(0,X.jsx)(En,{kb:e,digest:o,onEdit:()=>r(`edit`)}):(0,X.jsx)(`p`,{className:`max-w-prose text-outline`,children:`A digest is an agent that reads new memories, sessions and open comments, then keeps the documents in this knowledge base current. It can run on a schedule or only when you start it.`})}),n===`edit`&&(0,X.jsx)(Xn,{kb:e,digest:o??null,onClose:()=>r(null),onRemove:()=>r(`remove`)}),n===`remove`&&(0,X.jsx)(Zn,{kb:e,onClose:()=>r(null)})]})}function wn({digest:e}){let t=e.last_run,n=e.schedule.type===`manual`||e.enabled;return(0,X.jsxs)(`span`,{"data-testid":`kb-digest-summary`,className:`inline-flex min-w-0 flex-wrap items-center gap-x-1.5`,children:[(0,X.jsx)(Z,{tone:Sn(e)}),(0,X.jsx)(`span`,{"data-testid":`kb-digest-enabled`,children:n?`On`:`Paused`}),(0,X.jsxs)(`span`,{children:[`·`,` `,e.schedule.type===`manual`?`runs when you start it`:(0,X.jsx)(`span`,{title:e.schedule.cron,children:gn(e.schedule.cron)})]}),e.next_run_at!==null&&(0,X.jsxs)(`span`,{className:`text-outline`,"data-testid":`kb-digest-next-run`,children:[`·`,` `,(0,X.jsxs)(`span`,{title:new Date(e.next_run_at).toLocaleString(),children:[`next run `,bn(e.next_run_at)]})]}),(0,X.jsxs)(`span`,{className:`text-outline`,"data-testid":`kb-digest-last-run`,"data-status":t?.status??`never`,children:[`·`,` `,t?t.status===`running`?`running now`:(0,X.jsxs)(`span`,{title:new Date(t.at).toLocaleString(),children:[`last run`,` `,(0,X.jsx)(`span`,{className:t.status===`failed`?`text-error`:void 0,children:t.status===`completed`?`succeeded`:t.status}),` `,xn(t.at)]}):`not run yet`]})]})}function Tn({kb:e,digest:t,onStarted:n}){let r=q(),i=Q(),a=t.last_run?.status===`running`;async function o(){await i.run(()=>A.kb.runDigest(e.id))&&(n(),await r())}return(0,X.jsxs)(X.Fragment,{children:[i.error&&(0,X.jsx)(`span`,{role:`alert`,className:`text-error`,"data-testid":`kb-digest-error`,children:i.error}),(0,X.jsx)(f,{size:`sm`,variant:`outline`,"data-testid":`kb-digest-run`,onClick:o,disabled:i.pending||a,children:a?`Running…`:`Run now`})]})}function En({kb:e,digest:t,onEdit:n}){let r=q(),i=Q(),a=At(e.id,t);async function o(){await i.run(()=>A.kb.setDigest(e.id,{enabled:!t.enabled}))&&await r()}return(0,X.jsxs)(`div`,{className:`min-w-0 space-y-3`,children:[(0,X.jsxs)(`p`,{className:`max-w-prose text-outline`,children:[`The `,(0,X.jsx)(`span`,{className:`font-mono text-on-surface`,children:t.backend}),` agent reads new memories, sessions and open comments, then updates documents here.`,` `,(0,X.jsx)(`span`,{"data-testid":`kb-digest-open-comments`,children:t.open_comments}),` open`,` `,t.open_comments===1?`comment waits`:`comments wait`,` for the next run.`]}),(0,X.jsxs)(`div`,{className:`-ml-2 flex flex-wrap items-center gap-1`,children:[(0,X.jsx)(f,{size:`sm`,variant:`ghost`,"data-testid":`kb-digest-edit`,onClick:n,children:`Edit instructions and schedule`}),t.schedule.type===`cron`&&(0,X.jsx)(f,{size:`sm`,variant:`ghost`,"data-testid":`kb-digest-toggle`,onClick:o,disabled:i.pending,children:t.enabled?`Pause schedule`:`Resume schedule`}),(0,X.jsx)(f,{size:`sm`,variant:`ghost`,asChild:!0,children:(0,X.jsx)(l,{to:`/jobs/${encodeURIComponent(t.job_id)}`,"data-testid":`kb-digest-job`,children:`Job history`})})]}),i.error&&(0,X.jsx)(`p`,{role:`alert`,className:`text-error`,"data-testid":`kb-digest-error`,children:i.error}),(0,X.jsx)(On,{runs:a.data??[]})]})}var Dn={failed:`error`,success:`ok`,running:`progress`};function On({runs:e}){return e.length?(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(`h4`,{className:`text-xs font-medium text-outline`,children:`Recent runs`}),(0,X.jsx)(`ol`,{"data-testid":`kb-digest-runs`,className:`divide-y divide-outline-variant`,children:e.map(e=>(0,X.jsxs)(`li`,{"data-testid":`kb-digest-run-row`,"data-status":e.status,className:`min-w-0 wrap-break-word py-1.5`,children:[(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(Z,{tone:Dn[e.status]??`off`}),e.status]}),(0,X.jsxs)(`span`,{className:`text-outline`,children:[` · `,e.started_at?(0,X.jsx)(`span`,{title:new Date(e.started_at).toLocaleString(),children:xn(e.started_at)}):`not started`,e.trigger_by?` · ${e.trigger_by}`:``]}),e.session_id&&(0,X.jsx)(l,{to:`/audit/${encodeURIComponent(e.session_id)}`,className:`ml-2 text-primary hover:underline`,children:`Session`}),(e.error||e.summary)&&(0,X.jsx)(`span`,{className:`block truncate text-xs text-outline`,title:e.error??e.summary??``,children:e.error??e.summary})]},e.run_id))})]}):(0,X.jsx)(`p`,{className:`text-outline`,children:`No runs yet.`})}var kn=`__global__`,An=`__auto__`;function jn(e){return e instanceof Error?e.message:`Request failed`}function Q(){let[e,t]=(0,J.useState)(!1),[n,r]=(0,J.useState)(null);async function i(e){t(!0),r(null);try{return await e()}catch(e){r(jn(e));return}finally{t(!1)}}return{pending:e,error:n,run:i,setError:r}}function $({label:e,children:t,hint:n}){return(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(S,{className:`text-sm text-muted-foreground`,children:e}),t,n&&(0,X.jsx)(`p`,{className:`text-xs text-outline`,children:n})]})}function Mn({error:e}){return e?(0,X.jsx)(`p`,{role:`alert`,"data-testid":`kb-dialog-error`,className:`text-sm text-error`,children:e}):null}function Nn({open:e,onClose:t,title:n,wide:r,size:i,children:a}){return(0,X.jsx)(B,{open:e,onOpenChange:e=>!e&&t(),children:(0,X.jsxs)(R,{className:`bg-surface border-outline-variant ${i===`xl`?`w-[calc(100%-1rem)] max-w-4xl`:r?`max-w-3xl`:`max-w-md`}`,children:[(0,X.jsx)(I,{children:(0,X.jsx)(z,{className:`text-base text-on-surface`,children:n})}),a]})})}function Pn({value:e,onChange:t}){let n=wt();return(0,X.jsxs)(T,{value:e??An,onValueChange:e=>t(e===An?null:e),children:[(0,X.jsx)(C,{"aria-label":`Parser`,"data-testid":`kb-parser-select`,children:(0,X.jsx)(E,{})}),(0,X.jsxs)(D,{children:[(0,X.jsx)(w,{value:An,children:`Workspace default`}),(n.data?.parsers??[]).map(e=>(0,X.jsxs)(w,{value:e.id,disabled:!e.installed,children:[e.label,e.installed?``:` (not installed)`]},e.id))]})]})}var Fn={ui:`Web UI`,cli:`CLI`,api:`REST API`,mcp:`Agents (MCP)`};function In({value:e,onChange:t}){return(0,X.jsxs)(`fieldset`,{className:`space-y-2 rounded-md border border-outline-variant p-3`,children:[(0,X.jsx)(`legend`,{className:`px-1 text-sm text-muted-foreground`,children:`Who can change documents`}),(0,X.jsx)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-2`,children:Y.map(n=>(0,X.jsxs)(`label`,{className:`flex items-center gap-2 text-sm`,children:[(0,X.jsx)(`input`,{type:`checkbox`,"data-testid":`kb-editable-${n}`,checked:e.includes(n),onChange:r=>t(Y.filter(t=>t===n?r.target.checked:e.includes(t)))}),Fn[n]]},n))}),(0,X.jsx)(`p`,{className:`text-xs text-outline`,children:`Every source can read and search. Knowledge base settings change only from the UI, CLI or API.`})]})}function Ln({open:e,projectId:t,onClose:n,onCreated:r}){let i=Ge(),a=q(),o=Q(),[s,c]=(0,J.useState)(``),[l,u]=(0,J.useState)(``),[d,p]=(0,J.useState)(t??kn),[m,h]=(0,J.useState)([...Y]),[g,_]=(0,J.useState)(null);async function v(e){e.preventDefault();let t=await o.run(()=>A.kb.create({name:s.trim(),description:l.trim(),project_id:d===kn?null:d,editable_by:m,parser:g}));t&&(await a(),r(t))}return(0,X.jsx)(Nn,{open:e,onClose:n,title:`New knowledge base`,children:(0,X.jsxs)(`form`,{onSubmit:v,className:`space-y-4`,children:[(0,X.jsx)($,{label:`Name`,children:(0,X.jsx)(W,{"aria-label":`Name`,"data-testid":`kb-name-input`,value:s,onChange:e=>c(e.target.value),placeholder:`e.g. Runbooks`,autoFocus:!0})}),(0,X.jsx)($,{label:`Description`,children:(0,X.jsx)(F,{"aria-label":`Description`,value:l,onChange:e=>u(e.target.value),rows:2})}),(0,X.jsx)($,{label:`Belongs to`,hint:`Project knowledge bases are visible in that project; global ones in every project.`,children:(0,X.jsxs)(T,{value:d,onValueChange:p,children:[(0,X.jsx)(C,{"aria-label":`Belongs to`,"data-testid":`kb-owner-select`,children:(0,X.jsx)(E,{})}),(0,X.jsxs)(D,{children:[(0,X.jsx)(w,{value:kn,children:`Global (all projects)`}),(i.data??[]).map(e=>(0,X.jsx)(w,{value:e.id,children:e.name},e.id))]})]})}),(0,X.jsx)(In,{value:m,onChange:h}),(0,X.jsx)($,{label:`Parser for uploads`,children:(0,X.jsx)(Pn,{value:g,onChange:_})}),(0,X.jsx)(Mn,{error:o.error}),(0,X.jsxs)(L,{children:[(0,X.jsx)(f,{type:`button`,variant:`ghost`,onClick:n,children:`Cancel`}),(0,X.jsx)(f,{type:`submit`,"data-testid":`kb-create-submit`,disabled:!s.trim()||o.pending,children:o.pending?`Creating…`:`Create`})]})]})})}function Rn({kb:e,onClose:t,onDeleted:n}){let r=Ge(),i=q(),a=Q(),[o,s]=(0,J.useState)(e.name),[c,l]=(0,J.useState)(e.description),[u,d]=(0,J.useState)(e.editable_by),[p,m]=(0,J.useState)(e.parser),[h,g]=(0,J.useState)(!1);async function _(n){n.preventDefault(),await a.run(()=>A.kb.update(e.id,{name:o.trim(),description:c.trim(),editable_by:u,parser:p}))&&(await i(),t())}return(0,X.jsxs)(Nn,{open:!0,onClose:t,title:`Knowledge base settings`,children:[(0,X.jsxs)(`form`,{onSubmit:_,className:`space-y-4`,children:[(0,X.jsx)($,{label:`Name`,children:(0,X.jsx)(W,{"aria-label":`Name`,"data-testid":`kb-name-input`,value:o,onChange:e=>s(e.target.value)})}),(0,X.jsx)($,{label:`Description`,children:(0,X.jsx)(F,{"aria-label":`Description`,value:c,onChange:e=>l(e.target.value),rows:2})}),(0,X.jsxs)(`div`,{className:`space-y-1 text-sm`,children:[(0,X.jsx)(`div`,{className:`font-medium`,children:`Belongs to`}),(0,X.jsxs)(`p`,{className:`text-outline`,"data-testid":`kb-settings-owner`,children:[e.project_id===null?`Global, visible in every project`:`${r.data?.find(t=>t.id===e.project_id)?.name??`A project`}, visible in that project`,`. Set when the knowledge base is created.`]})]}),(0,X.jsx)(In,{value:u,onChange:d}),(0,X.jsx)($,{label:`Parser for uploads`,hint:`Applies to new uploads and reparses.`,children:(0,X.jsx)(Pn,{value:p,onChange:m})}),(0,X.jsx)(Mn,{error:a.error}),(0,X.jsxs)(L,{className:`gap-2 sm:justify-between`,children:[(0,X.jsxs)(f,{type:`button`,variant:`ghost`,className:`text-error`,"data-testid":`kb-delete`,onClick:()=>g(!0),children:[(0,X.jsx)(_e,{size:14}),`Delete`]}),(0,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.jsx)(f,{type:`button`,variant:`ghost`,onClick:t,children:`Cancel`}),(0,X.jsx)(f,{type:`submit`,"data-testid":`kb-settings-save`,disabled:!o.trim()||a.pending,children:`Save`})]})]})]}),(0,X.jsx)(Ze,{open:h,title:`Delete knowledge base`,description:`Delete "${e.name}" with its ${e.document_count} documents, revisions and uploaded files? Registered folders on disk are not touched.`,isPending:a.pending,onCancel:()=>g(!1),onConfirm:async()=>{let t=await a.run(()=>A.kb.remove(e.id));g(!1),t!==void 0&&(await i(),n())}})]})}function zn(e){return`${e.trim().toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)||`untitled`}.md`}function Bn(e){return e.match(/^#\s+(.+?)\s*#*\s*$/m)?.[1]?.trim()??``}var Vn=/\.(md|markdown|txt)$/i;function Hn({kb:e,initialFile:t,onClose:n,onCreated:r,onUploadMany:i}){let a=q(),o=Q(),s=Pt(e.id),[c,l]=(0,J.useState)(``),[u,d]=(0,J.useState)(``),[m,h]=(0,J.useState)(``),[g,_]=(0,J.useState)([]),[v,y]=(0,J.useState)(null),[b,S]=(0,J.useState)(!1),C=(0,J.useRef)(null),w=v?``:Bn(u),T=c.trim()||w,E=v?v.name:zn(T),D=v!==null||u.trim()!==``;async function O(e){let t=e.name.replace(/\.[^.]+$/,``);if(!Vn.test(e.name)){y(e),l(t),h(``);return}S(!0);let n=await o.run(()=>e.text());S(!1),n!==void 0&&(y(null),d(n),l(Bn(n)||t),h(/\.txt$/i.test(e.name)?zn(t):e.name))}function k(e){let t=[...e??[]];t.length>1?i(t):t[0]&&O(t[0])}(0,J.useEffect)(()=>{t&&O(t)},[]);async function j(t){t.preventDefault();let n=await o.run(()=>v?A.kb.upload(e.id,{file:v,title:T,path:m.trim()||void 0,labels:g}):A.kb.createDocument(e.id,{title:T,path:m.trim()||E,labels:g,content:D?u:`# ${T}\n\n`}));n&&(await a(),r(n,D))}return(0,X.jsx)(Nn,{open:!0,onClose:n,title:`New document in ${e.name}`,size:`xl`,children:(0,X.jsxs)(`form`,{onSubmit:j,className:`space-y-4`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-sm text-outline`,children:[(0,X.jsx)(`span`,{children:`Write or paste below, or start from a file.`}),(0,X.jsxs)(f,{type:`button`,size:`sm`,variant:`outline`,"data-testid":`kb-doc-choose-file`,disabled:b||o.pending,onClick:()=>C.current?.click(),children:[(0,X.jsx)(P,{size:16}),b?`Reading…`:`Upload file`]}),(0,X.jsx)(`input`,{ref:C,type:`file`,multiple:!0,hidden:!0,"data-testid":`kb-doc-file-input`,onChange:e=>{k(e.target.files),e.target.value=``}})]}),(0,X.jsx)($,{label:`Title`,hint:w&&!c.trim()?`Taken from the first heading.`:void 0,children:(0,X.jsx)(W,{"aria-label":`Title`,"data-testid":`kb-doc-title-input`,value:c,onChange:e=>l(e.target.value),placeholder:w||`e.g. Deploy runbook`,autoFocus:!0})}),v?(0,X.jsx)($,{label:`File`,hint:`Converted to searchable text after it is added. The original file is kept.`,children:(0,X.jsxs)(`div`,{"data-testid":`kb-doc-file`,className:`flex items-center gap-3 rounded-md border border-surface-highest bg-surface p-3`,children:[(0,X.jsx)(je,{size:20,className:`shrink-0 text-outline`,"aria-hidden":!0}),(0,X.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm`,title:v.name,children:v.name}),(0,X.jsx)(`span`,{className:`shrink-0 text-xs text-outline`,children:p(v.size)}),(0,X.jsx)(f,{type:`button`,size:`icon`,variant:`ghost`,"aria-label":`Remove ${v.name}`,"data-testid":`kb-doc-file-remove`,onClick:()=>{y(null),l(``)},children:(0,X.jsx)(x,{size:16})})]})}):(0,X.jsx)($,{label:`Content`,hint:`Markdown. Leave empty to start writing in the editor.`,children:(0,X.jsx)(N,{path:m.trim()||E,value:u,onChange:d,testId:`kb-doc-content-input`,label:`Content`,placeholder:`Write or paste Markdown`,initialMode:`edit`,height:`45vh`})}),(0,X.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,X.jsx)($,{label:`Labels`,hint:`Enter, comma or space adds a label.`,children:(0,X.jsx)(It,{"aria-label":`Labels`,"data-testid":`kb-doc-labels-input`,value:g,onChange:_,suggestions:s.data?.labels.map(e=>e.label)})}),(0,X.jsx)($,{label:`Path`,hint:`Optional. Folders come from the path, e.g. guides/setup.md.`,children:(0,X.jsx)(W,{"aria-label":`Path`,"data-testid":`kb-doc-path-input`,value:m,onChange:e=>h(e.target.value),placeholder:E,className:`font-mono text-sm`})})]}),(0,X.jsx)(Mn,{error:o.error}),(0,X.jsxs)(L,{children:[(0,X.jsx)(f,{type:`button`,variant:`ghost`,onClick:n,children:`Cancel`}),(0,X.jsx)(f,{type:`submit`,"data-testid":`kb-doc-create-submit`,disabled:!T||o.pending,children:`Create`})]})]})})}function Un({doc:e,linkedFrom:t,onClose:n,onSaved:r}){let i=q(),a=Q(),[o,s]=(0,J.useState)(e.title),[c,l]=(0,J.useState)(e.path),u=Pt(e.kb_id),[d,p]=(0,J.useState)(e.labels),[m,h]=(0,J.useState)(e.description),g=o.trim()!==e.title||c.trim()!==e.path;async function _(t){t.preventDefault(),await a.run(()=>A.kb.updateDocument(e.id,{expected_revision:e.revision,title:o.trim(),path:c.trim(),labels:d,description:m.trim()}))&&(await i(),r())}return(0,X.jsx)(Nn,{open:!0,onClose:n,title:`Document properties`,children:(0,X.jsxs)(`form`,{onSubmit:_,className:`space-y-4`,children:[(0,X.jsx)($,{label:`Title`,children:(0,X.jsx)(W,{"aria-label":`Title`,"data-testid":`kb-doc-title-input`,value:o,onChange:e=>s(e.target.value)})}),(0,X.jsx)($,{label:`Path`,children:(0,X.jsx)(W,{"aria-label":`Path`,"data-testid":`kb-doc-path-input`,value:c,onChange:e=>l(e.target.value),className:`font-mono text-sm`})}),(0,X.jsx)($,{label:`Labels`,hint:`Enter, comma or space adds a label.`,children:(0,X.jsx)(It,{"aria-label":`Labels`,"data-testid":`kb-doc-labels-input`,value:d,onChange:p,suggestions:u.data?.labels.map(e=>e.label)})}),(0,X.jsx)($,{label:`Description`,children:(0,X.jsx)(F,{"aria-label":`Description`,value:m,onChange:e=>h(e.target.value),rows:2})}),g&&t>0&&(0,X.jsxs)(`p`,{role:`status`,className:`text-sm text-warning`,"data-testid":`kb-rename-warning`,children:[t===1?`1 document links`:`${t} documents link`,` to this document. Links that use the old title or path will show as missing.`]}),(0,X.jsx)(Mn,{error:a.error}),(0,X.jsxs)(L,{children:[(0,X.jsx)(f,{type:`button`,variant:`ghost`,onClick:n,children:`Cancel`}),(0,X.jsx)(f,{type:`submit`,"data-testid":`kb-doc-properties-save`,disabled:!o.trim()||a.pending,children:`Save`})]})]})})}var Wn={daily:`Every day`,weekly:`Once a week`,custom:`Custom cron`,manual:`Manual only`};function Gn(e){let t=e.type===`cron`?e.cron:ln,n={plan:`custom`,time:`03:00`,day:`1`,cron:t},r=/^(\d{1,2}) (\d{1,2}) \* \* (\*|[0-6])$/.exec(t.trim().split(/\s+/).join(` `)),[i,a]=[Number(r?.[1]),Number(r?.[2])],o=r&&i<=59&&a<=23?`${String(a).padStart(2,`0`)}:${String(i).padStart(2,`0`)}`:null;return e.type===`manual`?{...n,plan:`manual`,time:o??n.time}:!r?.[3]||!o?n:r[3]===`*`?{...n,plan:`daily`,time:o}:{...n,plan:`weekly`,time:o,day:r[3]}}function Kn({plan:e,time:t,day:n,cron:r}){if(e===`manual`)return null;if(e===`custom`)return r.trim();let[i,a]=t.split(`:`).map(Number);return`${a} ${i} * * ${e===`weekly`?n:`*`}`}function qn(e){return e.plan===`manual`?null:e.plan===`custom`?yn(e.cron):/^\d{2}:\d{2}$/.test(e.time)?null:`Pick a time.`}function Jn(e){let t=gn(e);return t===e?`Runs on this cron schedule`:dn.some(e=>t.startsWith(e))?`Runs ${t}`:`Runs ${t.charAt(0).toLowerCase()}${t.slice(1)}`}function Yn({value:e,onChange:t}){let n=Kn(e),r=qn(e),i=n=>t({...e,...n});return(0,X.jsxs)(`fieldset`,{className:`space-y-3 rounded-md border border-outline-variant p-3`,children:[(0,X.jsx)(`legend`,{className:`px-1 text-sm text-muted-foreground`,children:`When it runs`}),(0,X.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[(0,X.jsx)($,{label:`Schedule`,children:(0,X.jsxs)(T,{value:e.plan,onValueChange:e=>i({plan:e,...e===`custom`&&n?{cron:n}:{}}),children:[(0,X.jsx)(C,{"aria-label":`Schedule`,"data-testid":`kb-digest-schedule`,children:(0,X.jsx)(E,{})}),(0,X.jsx)(D,{children:Object.keys(Wn).map(e=>(0,X.jsx)(w,{value:e,children:Wn[e]},e))})]})}),e.plan===`weekly`&&(0,X.jsx)($,{label:`Day`,children:(0,X.jsxs)(T,{value:e.day,onValueChange:e=>i({day:e}),children:[(0,X.jsx)(C,{"aria-label":`Day`,"data-testid":`kb-digest-day`,children:(0,X.jsx)(E,{})}),(0,X.jsx)(D,{children:dn.map((e,t)=>(0,X.jsx)(w,{value:String(t),children:e},e))})]})}),(e.plan===`daily`||e.plan===`weekly`)&&(0,X.jsx)($,{label:`Time`,children:(0,X.jsx)(W,{type:`time`,"aria-label":`Time`,"data-testid":`kb-digest-time`,value:e.time,onChange:e=>i({time:e.target.value})})}),e.plan===`custom`&&(0,X.jsx)(`div`,{className:`sm:col-span-2`,children:(0,X.jsx)($,{label:`Cron expression`,hint:`minute hour day month weekday, e.g. 0 */6 * * *`,children:(0,X.jsx)(W,{"aria-label":`Cron expression`,"aria-invalid":r!==null,"data-testid":`kb-digest-cron`,value:e.cron,onChange:e=>i({cron:e.target.value}),className:`font-mono`,autoComplete:`off`})})})]}),(0,X.jsx)(`p`,{"aria-live":`polite`,"data-testid":`kb-digest-schedule-preview`,"data-valid":r===null,className:`text-sm ${r?`text-error`:`text-outline`}`,children:r||(n?(0,X.jsxs)(X.Fragment,{children:[Jn(n),` `,(0,X.jsxs)(`span`,{className:`font-mono text-xs`,children:[`(`,n,`)`]}),`, in the ORC server's time zone.`]}):`Runs only when you start it.`)})]})}function Xn({kb:e,digest:t,onClose:n,onRemove:r}){let i=q(),a=Q(),o=Le(),s=Mt(!t),[c,l]=(0,J.useState)(t?.instructions??null),[u,d]=(0,J.useState)(t?.backend??`__default__`),[p,m]=(0,J.useState)(()=>Gn(t?.schedule??{type:`cron`,cron:`0 3 * * *`}));(0,J.useEffect)(()=>{c===null&&s.data&&l(s.data.instructions)},[c,s.data]);let h=qn(p);async function g(t){if(t.preventDefault(),h)return a.setError(h);let r=u===`__default__`?o.data?.default_backend:u,s=Kn(p);await a.run(()=>A.kb.setDigest(e.id,{instructions:c?.trim()??``,...r?{backend:r}:{},schedule:s?{type:`cron`,cron:s}:{type:`manual`}}))&&(await i(),n())}let _=c!==null;return(0,X.jsx)(Nn,{open:!0,onClose:n,title:t?`Digest settings`:`Set up a digest`,wide:!0,children:(0,X.jsxs)(`form`,{onSubmit:g,className:`min-w-0 space-y-4`,children:[!e.editable_by.includes(`mcp`)&&(0,X.jsx)(`p`,{className:`text-sm text-warning`,"data-testid":`kb-digest-mcp-hint`,children:`The digest writes through MCP. Allow Agents (MCP) in this knowledge base's settings first.`}),(0,X.jsx)(Yn,{value:p,onChange:m}),(0,X.jsx)(Be,{value:u,onChange:d,testId:`kb-digest-backend`}),(0,X.jsx)($,{label:`Instructions`,children:_?(0,X.jsx)(N,{path:`digest.md`,value:c,onChange:l,testId:`kb-digest-instructions`,label:`Instructions`,initialMode:`edit`,height:320}):s.error?(0,X.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:jn(s.error)}):(0,X.jsx)(`p`,{role:`status`,className:`text-sm text-outline`,children:`Loading template…`})}),(0,X.jsx)(Mn,{error:a.error}),(0,X.jsxs)(L,{className:`gap-2 sm:justify-between`,children:[t&&r?(0,X.jsxs)(f,{type:`button`,variant:`ghost`,className:`text-error`,"data-testid":`kb-digest-remove`,onClick:r,children:[(0,X.jsx)(_e,{size:14}),`Remove digest`]}):(0,X.jsx)(`span`,{}),(0,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.jsx)(f,{type:`button`,variant:`ghost`,onClick:n,children:`Cancel`}),(0,X.jsx)(f,{type:`submit`,"data-testid":`kb-digest-save`,disabled:!_||!c?.trim()||h!==null||a.pending,children:a.pending?`Saving…`:`Save`})]})]})]})})}function Zn({kb:e,onClose:t}){let n=r(),i=Q();async function a(){await i.run(()=>A.kb.removeDigest(e.id,e.name))!==void 0&&(n.setQueryData([kt,e.id],{digest:null}),await n.invalidateQueries({queryKey:[`kb`]}),t())}return(0,X.jsx)(Nn,{open:!0,onClose:t,title:`Remove digest?`,children:(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsx)(`p`,{className:`text-sm text-outline`,children:`Documents and comments stay. The digest's instructions, schedule, job and run history are removed.`}),(0,X.jsx)(Mn,{error:i.error}),(0,X.jsxs)(L,{children:[(0,X.jsx)(f,{type:`button`,variant:`ghost`,onClick:t,children:`Cancel`}),(0,X.jsx)(f,{type:`button`,variant:`destructive`,"data-testid":`kb-digest-remove-confirm`,onClick:a,disabled:i.pending,autoFocus:!0,children:i.pending?`Removing…`:`Remove digest`})]})]})})}var Qn={open:`bg-warning`,resolved:`bg-secondary`,dismissed:`bg-muted-foreground`};function $n({status:e}){return(0,X.jsx)(`span`,{"aria-hidden":!0,className:d(`size-1.5 shrink-0 rounded-full`,Qn[e])})}function er({kbId:e,documentId:t,onOpenDocument:n,heading:r=`h3`,compact:i=!1}){let[a,o]=(0,J.useState)(!1),[s,c]=(0,J.useState)(null),l=Et(e,{...t?{document_id:t}:{},...s?{status:s}:{}}),u=l.data?.counts,f=u?u.open+u.resolved+u.dismissed:0;function p(e){c(a&&s===e?null:e),o(!0)}return(0,X.jsx)(un,{title:`Comments`,testId:`kb-comments`,toggleTestId:`kb-comments-toggle`,heading:r,compact:i,expanded:a,onExpandedChange:o,summary:(0,X.jsxs)(X.Fragment,{children:[u&&f===0&&(0,X.jsx)(`span`,{className:`text-outline`,"data-testid":`kb-comments-none`,children:`None yet`}),u&&sn.filter(e=>u[e]>0).map(e=>(0,X.jsxs)(`button`,{type:`button`,"data-testid":`kb-comments-count-${e}`,"aria-pressed":a&&s===e,"aria-label":`${u[e]} ${e} ${u[e]===1?`comment`:`comments`}`,className:d(`inline-flex min-h-8 items-center gap-1.5 rounded px-1.5`,a&&s===e?`bg-surface-highest text-on-surface`:`text-outline hover:bg-surface-high`),onClick:()=>p(e),children:[(0,X.jsx)($n,{status:e}),(0,X.jsx)(`span`,{className:`tabular-nums text-on-surface`,children:u[e]}),e]},e)),l.error&&(0,X.jsx)(`span`,{role:`alert`,className:`text-error`,"data-testid":`kb-comments-error`,children:l.error.message})]}),children:(0,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsx)(tr,{kbId:e,documentId:t}),s&&l.data?.comments.length===0&&(0,X.jsxs)(`p`,{className:`text-outline`,"data-testid":`kb-comments-empty`,children:[`No `,s,` comments.`]}),(0,X.jsx)(`ul`,{className:`divide-y divide-outline-variant`,children:l.data?.comments.map(e=>(0,X.jsx)(nr,{comment:e,showDocument:!t,onOpenDocument:n},e.id))})]})})}function tr({kbId:e,documentId:t}){let n=q(),r=Q(),[i,a]=(0,J.useState)(``);async function o(o){o.preventDefault(),await r.run(()=>A.kb.addComment(e,{body:i.trim(),...t?{document_id:t}:{}}))&&(a(``),await n())}return(0,X.jsxs)(`form`,{onSubmit:o,className:`space-y-2`,children:[(0,X.jsx)(F,{"aria-label":t?`Comment on this document`:`Comment on this knowledge base`,placeholder:t?`Ask for a change to this document`:`Ask for a change`,"data-testid":`kb-comment-input`,value:i,onChange:e=>a(e.target.value),rows:2,maxLength:1e4}),i.trim()&&(0,X.jsx)(f,{type:`submit`,size:`sm`,variant:`outline`,"data-testid":`kb-comment-add`,disabled:r.pending,children:`Add comment`}),r.error&&(0,X.jsx)(`p`,{role:`alert`,className:`text-error`,"data-testid":`kb-comment-add-error`,children:r.error})]})}function nr({comment:e,showDocument:t,onOpenDocument:n}){let r=q(),i=Q(),[a,o]=(0,J.useState)(null),[s,c]=(0,J.useState)(``);async function l(t){if(t.preventDefault(),!a)return;let n=a;await i.run(()=>A.kb.closeComment(e.id,{status:n,reply:s.trim()}))&&(o(null),c(``),await r())}async function u(){await i.run(()=>A.kb.reopenComment(e.id))&&await r()}return(0,X.jsxs)(`li`,{"data-testid":`kb-comment`,"data-status":e.status,className:`min-w-0 space-y-1 py-2`,children:[(0,X.jsxs)(`p`,{className:`flex min-w-0 flex-wrap items-center gap-x-2 text-xs text-outline`,children:[(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-on-surface`,children:[(0,X.jsx)($n,{status:e.status}),(0,X.jsx)(`span`,{"data-testid":`kb-comment-status`,children:e.status})]}),(0,X.jsxs)(`span`,{className:`min-w-0 wrap-break-word`,children:[e.source===e.author?e.author:`${e.author} via ${e.source}`,` ·`,` `,new Date(e.created_at).toLocaleString(),t&&e.document_id&&(0,X.jsxs)(X.Fragment,{children:[` · on `,n?(0,X.jsx)(`button`,{type:`button`,className:`text-primary hover:underline`,onClick:()=>e.document_id&&n(e.document_id),children:e.document_title??`a deleted document`}):e.document_title??`a deleted document`]})]})]}),(0,X.jsx)(`p`,{className:`whitespace-pre-wrap wrap-break-word`,children:e.body}),e.reply&&(0,X.jsxs)(`p`,{className:`wrap-break-word text-xs`,"data-testid":`kb-comment-reply-text`,children:[(0,X.jsxs)(`span`,{className:`text-outline`,children:[e.status===`dismissed`?`Dismissed`:`Resolved`,e.resolved_by?` by ${e.resolved_by}`:``,`:`]}),` `,e.reply]}),a?(0,X.jsxs)(`form`,{onSubmit:l,className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(W,{"aria-label":a===`resolved`?`Resolution reply`:`Reason for dismissing`,placeholder:a===`resolved`?`What changed`:`Why not`,"data-testid":`kb-comment-reply`,value:s,onChange:e=>c(e.target.value),maxLength:4e3,autoFocus:!0,className:`min-w-0 flex-1 basis-48`}),(0,X.jsx)(f,{type:`submit`,size:`sm`,"data-testid":`kb-comment-close-submit`,disabled:!s.trim()||i.pending,children:a===`resolved`?`Resolve`:`Dismiss`}),(0,X.jsx)(f,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>{o(null),c(``),i.setError(null)},children:`Cancel`})]}):e.status===`open`?(0,X.jsxs)(`div`,{className:`-ml-2 flex flex-wrap`,children:[(0,X.jsx)(f,{size:`sm`,variant:`ghost`,"data-testid":`kb-comment-resolve`,onClick:()=>o(`resolved`),children:`Resolve`}),(0,X.jsx)(f,{size:`sm`,variant:`ghost`,"data-testid":`kb-comment-dismiss`,onClick:()=>o(`dismissed`),children:`Dismiss`})]}):(0,X.jsx)(f,{size:`sm`,variant:`ghost`,className:`-ml-2`,"data-testid":`kb-comment-reopen`,onClick:u,disabled:i.pending,children:`Reopen`}),i.error&&(0,X.jsx)(`p`,{role:`alert`,className:`text-xs text-error`,"data-testid":`kb-comment-error`,children:i.error})]})}var rr=e=>`kb:${e}`,ir={pending:`Processing`,partial:`Partially parsed`,failed:`Failed`,lexical_ready:`Keyword search ready`,semantic_pending:`Embedding`,semantic_ready:`Semantic search ready`};function ar(e){let t=[...e.currentTarget.querySelectorAll(`[role="menuitem"]:not(:disabled)`)],n=t.indexOf(document.activeElement),r=e.key===`ArrowDown`?(n+1)%t.length:e.key===`ArrowUp`?(n-1+t.length)%t.length:e.key===`Home`?0:e.key===`End`?t.length-1:null;r!==null&&t.length&&(e.preventDefault(),t[r]?.focus())}function or({usage:e,testId:t}){return(0,X.jsxs)(`div`,{"data-testid":t,className:`space-y-2`,children:[(0,X.jsxs)(`div`,{className:`text-sm`,children:[(0,X.jsx)(`span`,{"data-testid":`${t}-reads`,className:`font-medium`,children:e.reads}),` `,`reads · `,e.exposures,` search appearances · `,e.distinct_sessions,` sessions`]}),(0,X.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,X.jsx)(`thead`,{children:(0,X.jsxs)(`tr`,{className:`text-outline`,children:[(0,X.jsx)(`th`,{className:`py-1 text-left font-normal`,children:`Source`}),Yt.map(e=>(0,X.jsx)(`th`,{className:`py-1 text-right font-normal`,children:e===`search_hit`?`listed`:e},e))]})}),(0,X.jsx)(`tbody`,{children:Y.map(n=>(0,X.jsxs)(`tr`,{"data-testid":`${t}-${n}`,className:`border-t border-outline-variant/50`,children:[(0,X.jsx)(`td`,{className:`py-1 uppercase`,children:n}),Yt.map(t=>(0,X.jsx)(`td`,{className:`py-1 text-right tabular-nums`,children:e.totals[n][t]},t))]},n))})]}),(0,X.jsxs)(`div`,{className:`text-xs text-outline`,children:[`Last 7 days `,e.window.days_7,` · last 30 days `,e.window.days_30]})]})}function sr({kb:e,doc:t,onHome:n,onOpen:r,onDeleted:i,onReplaceFile:a,detailsOpen:o,onDetailsOpenChange:c}){let l=q(),[u]=s(),m=u.get(`editorMode`),h=Et(t.kb_id,{document_id:t.id}).data?.counts.open??0,[g,_]=(0,J.useState)(!1),[v,y]=(0,J.useState)(!1),[b,x]=(0,J.useState)(!1),S=we(`lg`),[C,w]=(0,J.useState)(null),T=(0,J.useRef)(null),[E,D]=(0,J.useState)(null),[O,k]=(0,J.useState)(!1),j=(0,J.useRef)(null),N=(0,J.useRef)(t.revision),ee=new Map(t.links.filter(e=>e.document_id).map(e=>[Xe(e.target),e.document_id])),P={slugs:[...ee.keys()],select:e=>{let t=ee.get(e);t&&r(t)}};async function te(e){k(!0),D(null);try{return await e(),await l(),!0}catch(e){return D(e instanceof Error?e.message:`Request failed`),!1}finally{k(!1)}}async function F(){await te(async()=>Qe(await A.kb.original(t.id),t.original_name??t.path.split(`/`).pop()??`document`))}function I(){let e=(t.path.split(`/`).pop()??`document`).replace(/\.(md|markdown)$/i,``);Qe(new Blob([t.content],{type:`text/markdown;charset=utf-8`}),`${e}.md`)}let L=t.origin===`upload`,R=L||t.origin===`external`&&!t.editable,z=C?.backlinks.filter(e=>!t.backlinks.some(t=>t.document_id===e.document_id))??[],B=(e,t,n,r,i=!1)=>(0,X.jsxs)(`button`,{type:`button`,role:`menuitem`,"data-testid":e,disabled:O,className:d(`flex min-h-9 w-full items-center gap-2 rounded px-2 text-left text-sm outline-hidden hover:bg-surface-highest focus-visible:bg-surface-highest disabled:opacity-50`,i&&`text-error`),onClick:()=>{x(!1),r()},children:[t,n]});return(0,X.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col overflow-y-auto lg:flex-row lg:overflow-hidden`,children:[(0,X.jsx)(`article`,{"data-testid":`kb-document`,className:`min-w-0 lg:min-h-0 lg:flex-1 lg:overflow-y-auto`,children:(0,X.jsxs)(`div`,{className:`w-full min-w-0 px-4 pb-16 pt-4 sm:px-8 sm:pt-6`,children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1`,children:[(0,X.jsxs)(`nav`,{"aria-label":`Breadcrumb`,className:`flex min-w-0 flex-1 basis-48 items-center gap-1 text-sm text-outline`,children:[(0,X.jsx)(`button`,{type:`button`,"data-testid":`kb-breadcrumb-kb`,className:`min-w-0 max-w-[60%] truncate hover:text-on-surface hover:underline`,onClick:n,children:e.name}),(0,X.jsx)(Fe,{size:14,className:`shrink-0`,"aria-hidden":!0}),(0,X.jsx)(`span`,{className:`min-w-0 truncate font-mono text-xs`,"data-testid":`kb-document-path`,title:t.path,children:t.path})]}),(0,X.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[(0,X.jsxs)(f,{size:`sm`,variant:o?`secondary`:`ghost`,"aria-pressed":o,"data-testid":`kb-details-toggle`,onClick:()=>c(!o),children:[(0,X.jsx)(Jt,{size:14}),`Details`,h>0&&(0,X.jsxs)(`span`,{"data-testid":`kb-details-open-comments`,title:`${h} open ${h===1?`comment`:`comments`}`,className:`inline-flex items-center gap-1 text-xs tabular-nums text-outline`,children:[(0,X.jsx)(Z,{tone:`warning`}),h]})]}),(0,X.jsxs)(ze,{open:b,onOpenChange:x,children:[(0,X.jsx)(Ie,{asChild:!0,children:(0,X.jsx)(f,{size:`icon`,variant:`ghost`,"aria-label":`Document actions`,"aria-haspopup":`menu`,"data-testid":`kb-doc-menu`,children:(0,X.jsx)(ye,{size:16})})}),(0,X.jsx)(Pe,{children:(0,X.jsxs)(We,{align:`end`,sideOffset:4,collisionPadding:8,role:`menu`,"aria-label":`Document actions`,className:`z-50 w-52 rounded-md border border-outline-variant bg-surface-high p-1 shadow-lg`,onOpenAutoFocus:e=>{e.preventDefault(),e.currentTarget.querySelector(`[role="menuitem"]:not(:disabled)`)?.focus()},onKeyDown:ar,children:[B(`kb-doc-properties`,(0,X.jsx)(le,{size:14}),`Title and labels`,()=>{T.current={title:t.title,backlinks:t.backlinks},_(!0)}),!R&&B(`kb-doc-download-markdown`,(0,X.jsx)(Bt,{size:14}),`Download Markdown`,I),R&&B(`kb-doc-download`,(0,X.jsx)(M,{size:14}),`Download original`,()=>void F()),L&&B(`kb-doc-reparse`,(0,X.jsx)(V,{size:14}),`Parse again`,()=>void te(()=>A.kb.reparse(t.id))),L&&B(`kb-doc-replace`,(0,X.jsx)(Wt,{size:14}),`Replace file`,()=>j.current?.click()),t.origin!==`external`&&B(`kb-doc-delete`,(0,X.jsx)(_e,{size:14}),`Delete document`,()=>y(!0),!0)]})})]})]})]}),(0,X.jsxs)(`header`,{className:`mb-2 mt-4 space-y-2`,children:[(0,X.jsx)(`h1`,{"data-testid":`kb-document-title`,className:`wrap-break-word text-3xl font-medium`,children:t.title}),t.description&&(0,X.jsx)(`p`,{className:`text-outline`,children:t.description}),(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1.5 text-xs text-outline`,children:[t.labels.length>0&&(0,X.jsx)(`span`,{className:`flex flex-wrap gap-1`,children:t.labels.map(e=>(0,X.jsx)(Nt,{variant:`secondary`,"data-testid":`kb-document-label`,children:e},e))}),t.parse_state!==`ok`&&(0,X.jsxs)(`span`,{className:d(`inline-flex items-center gap-1.5`,t.parse_state===`failed`&&`text-error`),children:[(0,X.jsx)(Z,{tone:t.parse_state===`failed`?`error`:t.parse_state===`partial`?`warning`:`progress`}),(0,X.jsx)(`span`,{"data-testid":`kb-parse-state`,children:ir[t.parse_state]})]}),t.folder_sync&&(0,X.jsx)(`span`,{"data-testid":`kb-folder-sync`,title:t.folder_sync===`following`?`Copied from a synced folder; scans pick up changes to the file`:`Edited in ORC; scans no longer change this copy`,children:t.folder_sync===`following`?`Follows folder file`:`Edited, no longer synced`}),t.stale&&(0,X.jsx)(`span`,{className:`text-warning`,"data-testid":`kb-document-stale`,children:`Stale: a source changed`}),(0,X.jsxs)(`span`,{children:[`Updated `,new Date(t.updated_at).toLocaleDateString(),` by `,t.updated_by]})]})]}),t.warnings.length>0&&(0,X.jsx)(`ul`,{"data-testid":`kb-document-warnings`,className:`mb-2 space-y-1 text-sm text-warning`,children:t.warnings.map(e=>(0,X.jsxs)(`li`,{className:`flex gap-2`,children:[(0,X.jsx)(pe,{size:14,className:`mt-0.5 shrink-0`}),e]},e))}),L&&(0,X.jsxs)(`p`,{className:`mb-2 text-sm text-outline`,children:[`Text parsed from `,t.original_name??`the upload`,` (`,p(t.size_bytes),t.parser?`, ${t.parser.id} ${t.parser.version}`:``,`). Replace the file to change it.`]}),t.folder_sync===`following`&&(m===`edit`||m===`split`)&&(0,X.jsx)(`p`,{role:`status`,"data-testid":`kb-folder-sync-warning`,className:`mb-2 text-sm text-warning`,children:`This copy follows a file in a synced folder. Saving here stops it following that file; later changes to the file will not reach it.`}),E&&(0,X.jsx)(`p`,{role:`alert`,"data-testid":`kb-document-error`,className:`mb-2 text-sm text-error`,children:E}),C&&z.length>0&&(0,X.jsxs)(`div`,{role:`status`,"data-testid":`kb-rename-broken-links`,className:`mb-2 flex flex-wrap items-center gap-x-2 text-sm text-warning`,children:[(0,X.jsx)(pe,{size:14,className:`shrink-0`,"aria-hidden":!0}),(0,X.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[z.length===1?`1 document`:`${z.length} documents`,` linked to “`,C.title,`” by its old title or path; those links now show as missing:`,` `,z.map((e,t)=>(0,X.jsxs)(`span`,{children:[t>0&&`, `,(0,X.jsx)(`button`,{type:`button`,className:`underline underline-offset-2 hover:text-on-surface`,onClick:()=>r(e.document_id),children:e.title})]},e.document_id))]}),(0,X.jsx)(f,{size:`sm`,variant:`ghost`,onClick:()=>w(null),children:`Dismiss`})]}),(0,X.jsx)(yt,{documentId:rr(t.id),path:t.editable?t.path:`${t.path}.md`,content:t.content,wikiLinks:P,testId:`kb-document-content`,layout:`page`,pageTitle:t.title,hideFrontmatter:!0,onSave:t.editable?async(e,n)=>{try{let r=await A.kb.updateDocument(t.id,{expected_revision:n===t.content?t.revision:N.current,content:e});return N.current=r.revision,e}finally{await l()}}:void 0},rr(t.id))]})}),o&&S&&(0,X.jsx)(lr,{doc:t,onOpen:r}),!S&&(0,X.jsx)(De,{open:o,onOpenChange:c,children:(0,X.jsxs)(de,{defaultWidth:360,resizeKey:`kb-properties`,"aria-describedby":void 0,children:[(0,X.jsx)(Ae,{className:`py-3`,children:(0,X.jsx)(Oe,{children:`Details`})}),(0,X.jsx)(se,{className:`p-0 sm:p-0`,children:(0,X.jsx)(lr,{doc:t,onOpen:(e,t)=>{c(!1),r(e,t)}})})]})}),(0,X.jsx)(`input`,{ref:j,type:`file`,hidden:!0,"data-testid":`kb-doc-replace-input`,onChange:e=>{let t=e.target.files?.[0];t&&a(t),e.target.value=``}}),g&&(0,X.jsx)(Un,{doc:t,linkedFrom:t.backlinks.length,onClose:()=>_(!1),onSaved:()=>{_(!1),w(T.current)}}),(0,X.jsx)(Ze,{open:v,title:`Delete document`,description:`Delete "${t.title}" and its revision history${L?` and uploaded file`:``}?`,isPending:O,onCancel:()=>y(!1),onConfirm:async()=>{y(!1),await te(()=>A.kb.removeDocument(t.id))&&i()}})]})}function cr({title:e,children:t}){return(0,X.jsxs)(`section`,{className:`space-y-1.5`,children:[(0,X.jsx)(`h2`,{className:`text-sm font-medium text-outline`,children:e}),t]})}function lr({doc:e,onOpen:t}){let n=Dt(e.id),r=jt(e.id),i=`block min-h-8 w-full wrap-break-word text-left text-primary hover:underline`;return(0,X.jsxs)(`aside`,{"data-testid":`kb-document-details`,"aria-label":`Document details`,className:`w-full shrink-0 space-y-6 p-4 text-sm lg:min-h-0 lg:w-80 lg:overflow-y-auto lg:border-l lg:border-outline-variant`,children:[e.outline.length>0&&(0,X.jsx)(cr,{title:`On this page`,children:(0,X.jsx)(`nav`,{"aria-label":`Outline`,className:`space-y-0.5`,children:e.outline.map(n=>(0,X.jsx)(`button`,{type:`button`,className:`block min-h-7 w-full truncate text-left text-outline hover:text-on-surface`,style:{paddingLeft:`${(n.level-1)*.75}rem`},onClick:()=>t(e.id,n.text),children:n.text},`${n.block}-${n.text}`))})}),e.links.length>0&&(0,X.jsx)(cr,{title:`Links to (${e.links.length})`,children:e.links.map(e=>e.document_id?(0,X.jsx)(`button`,{type:`button`,"data-testid":`kb-outgoing-link`,className:i,onClick:()=>t(e.document_id),children:e.title??e.target},e.target):(0,X.jsxs)(`p`,{className:`py-1 text-outline`,"data-testid":`kb-unresolved-link`,children:[e.target,` `,(0,X.jsx)(`span`,{className:`text-xs`,children:`(no such document)`})]},e.target))}),e.backlinks.length>0&&(0,X.jsx)(cr,{title:`Linked from (${e.backlinks.length})`,children:e.backlinks.map(e=>(0,X.jsx)(`button`,{type:`button`,"data-testid":`kb-backlink`,className:i,onClick:()=>t(e.document_id),children:e.title},e.document_id))}),(0,X.jsx)(`div`,{className:`border-y border-outline-variant`,children:(0,X.jsx)(er,{kbId:e.kb_id,documentId:e.id,heading:`h2`,compact:!0})}),(0,X.jsxs)(`details`,{"data-testid":`kb-doc-history`,className:`group`,children:[(0,X.jsxs)(`summary`,{className:`flex min-h-9 cursor-pointer list-none items-center gap-1.5 font-medium [&::-webkit-details-marker]:hidden`,children:[(0,X.jsx)(Fe,{size:14,"aria-hidden":!0,className:`text-outline transition-transform group-open:rotate-90`}),`Usage and history`]}),(0,X.jsxs)(`div`,{className:`mt-3 space-y-5 pl-5`,children:[n.data?(0,X.jsx)(or,{usage:n.data,testId:`kb-doc-usage`}):(0,X.jsx)(`p`,{className:`text-outline`,children:n.error?`Usage unavailable`:`Loading…`}),(0,X.jsx)(`ol`,{className:`space-y-2`,"data-testid":`kb-revisions`,children:r.data?.map(e=>(0,X.jsxs)(`li`,{"data-testid":`kb-revision`,children:[(0,X.jsxs)(`div`,{children:[`Revision `,e.revision,` · `,e.actor,(0,X.jsxs)(`span`,{className:`text-outline`,children:[` via `,e.source]})]}),(0,X.jsxs)(`div`,{className:`text-xs text-outline`,children:[new Date(e.created_at).toLocaleString(),e.note?` · ${e.note}`:``]})]},e.revision))}),(0,X.jsxs)(`dl`,{className:`grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-1 text-xs text-outline`,children:[(0,X.jsx)(`dt`,{children:`Search`}),(0,X.jsx)(`dd`,{"data-testid":`kb-index-state`,children:ir[e.index_state]??e.index_state}),(0,X.jsx)(`dt`,{children:`Origin`}),(0,X.jsx)(`dd`,{children:e.origin}),(0,X.jsx)(`dt`,{children:`Type`}),(0,X.jsx)(`dd`,{children:e.media_type}),(0,X.jsx)(`dt`,{children:`Size`}),(0,X.jsx)(`dd`,{children:p(e.size_bytes)}),(0,X.jsx)(`dt`,{children:`Updated`}),(0,X.jsxs)(`dd`,{children:[new Date(e.updated_at).toLocaleString(),` by `,e.updated_by]}),(0,X.jsx)(`dt`,{children:`ID`}),(0,X.jsx)(`dd`,{className:`break-all font-mono`,children:e.id})]})]})]})]})}function ur(e){return`${e.added} added · ${e.updated} updated · ${e.missing} missing${e.errors.length?` · ${e.errors.length} errors: ${e.errors.slice(0,3).join(`; `)}`:``}`}var dr=(e,t,n)=>`${e} ${e===1?t:n}`;function fr(){return/win/i.test(navigator.platform)?`Choose a folder or type its full path, e.g. C:\\notes`:/mac/i.test(navigator.platform)?`Choose a folder or type its full path, e.g. /Users/you/notes`:`Choose a folder or type its full path, e.g. /home/you/notes`}function pr(e){let t=e.document_count-e.edited_count,n=t?`${dr(t,`synced copy is`,`synced copies are`)} removed from this knowledge base`:`No synced copies are removed`,r=e.edited_count?`; ${dr(e.edited_count,`edited copy is`,`edited copies are`)} kept as documents`:``;return`Stop syncing ${e.root_path}? ${n}${r}. Files on disk are not touched.`}function mr(e){return e.replace(/[\\/]+$/,``).split(/[\\/]/).pop()||e}function hr({kb:e}){let t=Tt(e.id),n=q(),r=Q(),[i,a]=(0,J.useState)(!1),[o,s]=(0,J.useState)(``),[c,l]=(0,J.useState)(`**/*.md`),[u,d]=(0,J.useState)(null),[p,m]=(0,J.useState)(null),[h,g]=(0,J.useState)(!1),[_,v]=(0,J.useState)(!1),y=t.data??[],b=y.filter(e=>e.last_error).length,x=y.reduce((e,t)=>e+t.document_count,0);function S(){a(!0),g(!0)}function C(){g(!1),s(``),r.setError(null),y.length===0&&a(!1)}async function w(){v(!0),r.setError(null);try{let{path:e}=await A.terminals.pickFolder(o.trim()||void 0);e&&s(e)}catch(e){r.setError(e instanceof Error?e.message:String(e))}finally{v(!1)}}async function T(t){t.preventDefault();let i=await r.run(()=>A.kb.addSource(e.id,{root_path:o.trim(),pattern:c.trim()||`**/*.md`}));i&&(s(``),g(!1),d(ur(i.scan)),await n())}return(0,X.jsxs)(un,{title:`Synced folders`,testId:`kb-folders`,toggleTestId:`kb-sources`,expanded:i,onExpandedChange:e=>{a(e),g(e&&y.length===0)},summary:t.isLoading?(0,X.jsx)(`span`,{className:`text-outline`,children:`Loading…`}):y.length===0?(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-outline`,"data-testid":`kb-folders-none`,children:[(0,X.jsx)(Z,{tone:`off`}),`None`]}):(0,X.jsxs)(`span`,{className:`inline-flex min-w-0 max-w-full items-center gap-1.5`,"data-testid":`kb-folders-summary`,children:[(0,X.jsx)(Z,{tone:b?`error`:`ok`}),y.length===1?(0,X.jsx)(`span`,{className:`min-w-0 truncate`,title:y[0]?.root_path,children:mr(y[0]?.root_path??``)}):`${y.length} folders`,(0,X.jsxs)(`span`,{className:`shrink-0 text-outline`,children:[`· `,x,` `,x===1?`document`:`documents`,b?` · ${b} failing`:``]})]}),actions:y.length===0&&!i?(0,X.jsx)(f,{size:`sm`,variant:`outline`,"data-testid":`kb-folders-add`,onClick:S,children:`Add folder`}):null,children:[(0,X.jsxs)(`div`,{className:`min-w-0 space-y-3`,children:[(0,X.jsx)(`p`,{className:`max-w-prose text-outline`,children:`Matching files are copied in and kept in sync: ORC rescans every minute while the daemon runs, or when you choose Scan now. A copy you edit here stops following its file. ORC never writes to the folder.`}),y.length>0&&(0,X.jsx)(`ul`,{className:`divide-y divide-outline-variant`,"data-testid":`kb-sources-list`,children:y.map(e=>(0,X.jsxs)(`li`,{"data-testid":`kb-source-row`,className:`flex min-w-0 flex-wrap items-center gap-2 py-2`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1 basis-56`,children:[(0,X.jsx)(`div`,{className:`font-medium`,children:mr(e.root_path)}),(0,X.jsx)(`div`,{className:`break-all font-mono text-xs text-outline`,children:e.root_path}),(0,X.jsxs)(`div`,{className:`text-xs text-outline`,children:[e.pattern,` · `,dr(e.document_count,`document`,`documents`),e.edited_count?` (${e.edited_count} edited)`:``,` ·`,` `,e.last_scan_at?(0,X.jsxs)(`span`,{title:new Date(e.last_scan_at).toLocaleString(),children:[`scanned `,xn(e.last_scan_at)]}):`not scanned yet`]}),e.last_error&&(0,X.jsx)(`div`,{className:`text-xs text-error`,children:e.last_error})]}),(0,X.jsxs)(f,{variant:`ghost`,size:`sm`,"data-testid":`kb-source-scan`,disabled:r.pending,onClick:async()=>{let t=await r.run(()=>A.kb.scanSource(e.id));t&&d(ur(t)),await n()},children:[(0,X.jsx)(Kt,{size:14}),`Scan now`]}),(0,X.jsx)(f,{variant:`ghost`,size:`sm`,title:`Stop syncing ${e.root_path}`,"data-testid":`kb-source-remove`,onClick:()=>m(e),children:`Stop syncing`})]},e.id))}),u&&(0,X.jsx)(`p`,{role:`status`,"data-testid":`kb-source-result`,className:`text-outline`,children:u}),h?(0,X.jsxs)(`form`,{onSubmit:T,className:`min-w-0 space-y-3`,"data-testid":`kb-source-form`,children:[(0,X.jsxs)(`div`,{className:`grid min-w-0 gap-3 sm:grid-cols-[minmax(0,1fr)_12rem]`,children:[(0,X.jsx)($,{label:`Folder path`,hint:fr(),children:(0,X.jsxs)(`div`,{className:`flex min-w-0 gap-2`,children:[(0,X.jsx)(W,{"aria-label":`Folder path`,"data-testid":`kb-source-path-input`,value:o,onChange:e=>s(e.target.value),className:`min-w-0 font-mono text-sm`,autoFocus:!0}),(0,X.jsxs)(f,{type:`button`,variant:`outline`,"data-testid":`kb-source-choose-folder`,onClick:w,disabled:_,className:`shrink-0`,children:[(0,X.jsx)(ke,{size:14}),_?`Choosing…`:`Choose folder`]})]})}),(0,X.jsx)($,{label:`File pattern`,hint:`e.g. *.md, **/*.md`,children:(0,X.jsx)(W,{"aria-label":`File pattern`,"data-testid":`kb-source-pattern-input`,value:c,onChange:e=>l(e.target.value),className:`font-mono text-sm`})})]}),(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,X.jsx)(f,{type:`submit`,size:`sm`,variant:`outline`,"data-testid":`kb-source-add`,disabled:!o.trim()||r.pending,children:`Add folder`}),(0,X.jsx)(f,{type:`button`,size:`sm`,variant:`ghost`,"data-testid":`kb-source-cancel`,onClick:C,children:`Cancel`})]})]}):y.length>0&&(0,X.jsxs)(f,{size:`sm`,variant:`ghost`,className:`-ml-2`,"data-testid":`kb-folders-add-another`,onClick:()=>g(!0),children:[(0,X.jsx)(Ee,{size:14}),`Add another folder`]}),(0,X.jsx)(Mn,{error:r.error})]}),(0,X.jsx)(Ze,{open:p!==null,title:`Stop syncing folder`,description:p?pr(p):``,confirmLabel:`Stop syncing`,variant:`warning`,isPending:r.pending,onCancel:()=>m(null),onConfirm:async()=>{let e=p;m(null),e&&await r.run(()=>A.kb.removeSource(e.id)),await n()}})]})}var gr=8;function _r(e,t,n){return n===`title`?e.title.localeCompare(t.title):n===`updated`?e.updated_at-t.updated_at:e.reads-t.reads}function vr(e,t){if(e.key===t)return e.desc?`descending`:`ascending`}function yr(e){let t=new Date(e);return t.toDateString()===new Date().toDateString()?t.toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`}):t.toLocaleDateString([],{month:`short`,day:`numeric`,year:`numeric`})}function br({kb:e,owner:t,listing:n,label:r,onLabel:i,onOpen:a,onNewDocument:o,onSettings:s}){let c=e.editable_by.includes(`mcp`);return(0,X.jsxs)(`div`,{"data-testid":`kb-overview`,className:`w-full min-w-0 space-y-6 p-4 sm:p-6`,children:[(0,X.jsxs)(`header`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 space-y-1`,children:[(0,X.jsx)(`h2`,{className:`wrap-break-word text-base font-medium`,"data-testid":`kb-overview-name`,children:e.name}),e.description&&(0,X.jsx)(`p`,{className:`max-w-prose text-outline`,children:e.description}),(0,X.jsxs)(`p`,{className:`text-xs text-outline`,"data-testid":`kb-overview-meta`,children:[t,` · `,e.document_count,` `,e.document_count===1?`document`:`documents`,` ·`,` `,c?`agents can edit`:`agents read only`]})]}),(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsxs)(f,{size:`sm`,"data-testid":`kb-new-document`,onClick:o,children:[(0,X.jsx)(Ht,{size:16}),`New document`]}),(0,X.jsxs)(f,{size:`sm`,variant:`ghost`,"data-testid":`kb-settings`,onClick:s,children:[(0,X.jsx)(ue,{size:16}),`Settings`]})]})]}),(0,X.jsx)(wr,{kbId:e.id,onOpen:a}),(0,X.jsx)(Cr,{listing:n,total:e.document_count,label:r,onLabel:i,onOpen:a,onNewDocument:o}),(0,X.jsxs)(`section`,{"aria-labelledby":`kb-setup-heading`,className:`space-y-1`,children:[(0,X.jsx)(`h3`,{id:`kb-setup-heading`,className:`text-sm font-medium text-outline`,children:`Setup`}),(0,X.jsxs)(`div`,{className:`divide-y divide-outline-variant border-y border-outline-variant`,children:[(0,X.jsx)(Cn,{kb:e}),(0,X.jsx)(hr,{kb:e}),(0,X.jsx)(xr,{kb:e,onSettings:s}),(0,X.jsx)(Sr,{kb:e,onSettings:s}),(0,X.jsx)(er,{kbId:e.id,onOpenDocument:a})]})]})]})}function xr({kb:e,onSettings:t}){let n=e.editable_by.includes(`mcp`);return(0,X.jsx)(un,{title:`Who can edit`,testId:`kb-access`,summary:(0,X.jsxs)(`span`,{className:`inline-flex min-w-0 flex-wrap items-center gap-x-1.5`,children:[(0,X.jsx)(Z,{tone:n?`ok`:`off`}),n?`Agents can edit`:`Agents read only`,(0,X.jsxs)(`span`,{className:`text-outline`,children:[`·`,` `,e.editable_by.length?e.editable_by.map(e=>Fn[e]).join(`, `):`nobody, read only everywhere`]})]}),actions:(0,X.jsx)(f,{size:`sm`,variant:`ghost`,"data-testid":`kb-access-change`,onClick:t,children:`Change`})})}function Sr({kb:e,onSettings:t}){let n=wt(),r=e.parser?n.data?.parsers.find(t=>t.id===e.parser)?.label??e.parser:`Workspace default parser`;return(0,X.jsx)(un,{title:`Uploads`,testId:`kb-uploads-setup`,summary:(0,X.jsxs)(`span`,{className:`text-outline`,"data-testid":`kb-uploads-parser`,children:[r,(0,X.jsx)(oe,{label:`Document uploads`,children:`PDF, Word, PowerPoint, Excel, HTML, Markdown and text are converted to searchable Markdown by the selected parser.`})]}),actions:(0,X.jsx)(f,{size:`sm`,variant:`ghost`,"data-testid":`kb-parser-change`,onClick:t,children:`Change`})})}function Cr({listing:e,total:t,label:n,onLabel:r,onOpen:i,onNewDocument:a}){let[o,s]=(0,J.useState)(``),[c,l]=(0,J.useState)(!1),[u,p]=(0,J.useState)({key:`updated`,desc:!0}),m=o.trim().toLowerCase(),h=(e?.documents??[]).filter(e=>(!n||e.labels.includes(n))&&(!m||e.title.toLowerCase().includes(m)||e.path.toLowerCase().includes(m)||e.labels.some(e=>e.toLowerCase().includes(m)))).sort((e,t)=>_r(e,t,u.key)*(u.desc?-1:1));function g(e){p(t=>t.key===e?{key:e,desc:!t.desc}:{key:e,desc:e!==`title`})}function _(e,t){let n=u.desc?Ne:Me;return(0,X.jsxs)(`button`,{type:`button`,"data-testid":`kb-sort-${e}`,className:`inline-flex min-h-8 items-center gap-1 hover:text-on-surface`,onClick:()=>g(e),children:[t,u.key===e&&(0,X.jsx)(n,{size:12,"aria-hidden":!0})]})}let v=[...e?.labels??[]].sort((e,t)=>t.count-e.count),y=c?v:v.filter((e,t)=>t<gr||e.label===n),b=v.length-y.length;return(0,X.jsxs)(`section`,{"aria-labelledby":`kb-documents-heading`,"data-testid":`kb-documents`,className:`space-y-3`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,X.jsxs)(`h3`,{id:`kb-documents-heading`,className:`mr-auto text-sm font-medium text-outline`,children:[`Documents`,n?` labelled ${n}`:``]}),t>0&&(0,X.jsx)(W,{"aria-label":`Filter documents`,"data-testid":`kb-documents-filter`,placeholder:`Filter by title, path or label`,value:o,onChange:e=>s(e.target.value),className:`h-9 w-full sm:w-64`})]}),y.length>0&&(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,"data-testid":`kb-labels`,children:[(0,X.jsx)(`span`,{className:`mr-1 text-xs text-outline`,children:`Label`}),y.map(e=>(0,X.jsxs)(`button`,{type:`button`,"data-testid":`kb-label-filter`,"aria-pressed":n===e.label,className:d(`min-h-8 rounded-full border px-2.5 text-xs`,n===e.label?`border-primary bg-primary/10 text-primary`:`border-outline-variant text-outline hover:text-on-surface`),onClick:()=>r(n===e.label?null:e.label),children:[e.label,` `,(0,X.jsx)(`span`,{className:`tabular-nums`,children:e.count})]},e.label)),(b>0||c)&&v.length>gr&&(0,X.jsx)(`button`,{type:`button`,"data-testid":`kb-labels-more`,className:`min-h-8 px-2 text-xs text-primary hover:underline`,onClick:()=>l(!c),children:c?`Fewer labels`:`${b} more`})]}),t===0?(0,X.jsxs)(`div`,{className:`flex flex-col items-center justify-center gap-2 rounded-md border border-dashed border-outline-variant px-6 py-10 text-center text-sm text-outline`,children:[(0,X.jsx)(P,{size:22,className:`text-primary`,"aria-hidden":!0}),(0,X.jsx)(`span`,{children:`This knowledge base is empty. Drop PDF, Word, PowerPoint, Excel, HTML, Markdown or text files here, or`}),(0,X.jsx)(f,{size:`sm`,variant:`outline`,onClick:a,"data-testid":`kb-overview-new-document`,children:`add a document`})]}):(0,X.jsxs)(X.Fragment,{children:[h.length===0&&e&&(0,X.jsxs)(`p`,{className:`py-4 text-sm text-outline`,"data-testid":`kb-documents-empty`,children:[`No documents match.`,` `,(0,X.jsx)(`button`,{type:`button`,"data-testid":`kb-documents-clear`,className:`text-primary hover:underline`,onClick:()=>{s(``),r(null)},children:`Clear filters`})]}),h.length>0&&(0,X.jsxs)(`table`,{className:`w-full table-fixed text-sm`,children:[(0,X.jsx)(`thead`,{children:(0,X.jsxs)(`tr`,{className:`border-b border-outline-variant text-left text-xs text-outline`,children:[(0,X.jsx)(`th`,{className:`py-1 pr-3 font-normal`,"aria-sort":vr(u,`title`),children:_(`title`,`Title`)}),(0,X.jsx)(`th`,{className:`hidden w-[30%] py-2 pr-3 font-normal md:table-cell`,children:`Labels`}),(0,X.jsx)(`th`,{className:`w-24 py-1 pr-3 font-normal sm:w-28`,"aria-sort":vr(u,`updated`),children:_(`updated`,`Updated`)}),(0,X.jsx)(`th`,{className:`hidden w-16 py-1 text-right font-normal sm:table-cell`,"aria-sort":vr(u,`reads`),children:_(`reads`,`Reads`)})]})}),(0,X.jsx)(`tbody`,{children:h.map(e=>(0,X.jsxs)(`tr`,{className:`cursor-pointer border-b border-outline-variant/60 align-top hover:bg-surface-high`,onClick:()=>i(e.id),children:[(0,X.jsxs)(`td`,{className:`min-w-0 py-2 pr-3`,children:[(0,X.jsxs)(`button`,{type:`button`,"data-testid":`kb-document-row`,"data-document-title":e.title,className:`flex w-full min-w-0 items-center gap-1.5 text-left font-medium hover:text-primary`,onClick:t=>{t.stopPropagation(),i(e.id)},children:[(0,X.jsx)(`span`,{className:`min-w-0 truncate`,children:e.title}),e.origin===`external`&&(0,X.jsx)(Kt,{size:13,className:`shrink-0 text-outline`,"aria-label":`From a synced folder`})]}),(0,X.jsx)(`span`,{className:`block truncate font-mono text-xs text-outline`,children:e.path}),(e.parse_state===`pending`||e.parse_state===`failed`)&&(0,X.jsx)(`span`,{className:d(`text-xs`,e.parse_state===`failed`?`text-error`:`text-outline`),children:e.parse_state===`failed`?`Parsing failed`:`Parsing…`})]}),(0,X.jsx)(`td`,{className:`hidden py-2 pr-3 text-xs text-outline md:table-cell`,children:(0,X.jsx)(`span`,{className:`line-clamp-2`,children:e.labels.join(`, `)})}),(0,X.jsx)(`td`,{className:`py-2 pr-3 text-xs text-outline tabular-nums`,children:yr(e.updated_at)}),(0,X.jsx)(`td`,{className:`hidden py-2 text-right text-xs text-outline tabular-nums sm:table-cell`,children:e.reads||``})]},e.id))})]}),(0,X.jsx)(`p`,{className:`text-xs text-outline`,children:`Drop files anywhere on this page to upload.`})]})]})}function wr({kbId:e,onOpen:t}){let n=Ct(e).data;return!n||!(n.stale.length||n.failed.length||n.unresolved_links.length)?null:(0,X.jsxs)(`section`,{"data-testid":`kb-maintenance`,className:`space-y-1 text-sm`,children:[(0,X.jsx)(`h3`,{className:`text-sm font-medium text-outline`,children:`Needs attention`}),(0,X.jsxs)(`ul`,{className:`space-y-1`,children:[n.failed.map(e=>(0,X.jsx)(`li`,{children:(0,X.jsxs)(`button`,{type:`button`,className:`text-left text-error hover:underline`,onClick:()=>t(e.id),children:[`Parsing failed: `,e.title]})},e.id)),n.stale.map(e=>(0,X.jsx)(`li`,{children:(0,X.jsxs)(`button`,{type:`button`,className:`text-left text-warning hover:underline`,onClick:()=>t(e.id),children:[`Stale summary: `,e.title]})},e.id)),n.unresolved_links.map(e=>(0,X.jsx)(`li`,{children:(0,X.jsxs)(`button`,{type:`button`,className:`text-left text-outline hover:underline`,onClick:()=>t(e.document_id),children:[`[[`,e.target,`]] in `,e.title,` has no target`]})},`${e.document_id}-${e.target}`))]})]})}function Tr(){let e=q(),[t,n]=(0,J.useState)([]),r=(0,J.useRef)(1),i=(e,t)=>n(n=>n.map(n=>n.id===e?{...n,...t}:n));async function a(t){i(t.id,{status:`uploading`,progress:0,error:void 0});try{let n=await A.kb.upload(t.kbId,{file:t.file,...t.replace},e=>i(t.id,{progress:e}));i(t.id,{status:`done`,progress:1,document:n}),await e()}catch(e){i(t.id,{status:`failed`,error:e instanceof Error?e.message:`Upload failed`})}}function o(e,t,i={}){let o=t.map(t=>({id:r.current++,kbId:e,file:t,...i.replace?{replace:i.replace}:{},progress:0,status:`uploading`}));n(e=>[...e,...o]);for(let e of o)a(e)}return{uploads:t,add:o,retry:e=>{let n=t.find(t=>t.id===e);n&&a(n)},clearFinished:()=>n(e=>e.filter(e=>e.status===`uploading`))}}var Er={new:``,installed:`Already in ORC`,duplicate:`Near copy already in ORC`,conflict:`Name taken in ORC (different content), select to replace`,invalid:`Invalid`},Dr={new:``,identical:`Already in the folder`,near:`Near copy in the folder, select to overwrite`,conflict:`Different memory with this name in the folder, select to overwrite`,duplicate:`Already in the folder under another name`},Or=`__folder__`;function kr({mode:e,initialProjectId:t,projects:n,onClose:o}){let[s,c]=(0,J.useState)(t??``),[l,u]=(0,J.useState)(null),[d,p]=(0,J.useState)(``),[m,h]=(0,J.useState)(``),[g,_]=(0,J.useState)({}),v=r(),y=i({queryKey:[`memory-transfer`,`sources`,s],queryFn:()=>A.memories.nativeSources(s),enabled:!!s}),b=y.data?.sources??[],x=l??b.find(e=>e.project_match)?.dir??``,S=x===Or?m:x,C=i({queryKey:[`memory-transfer`,e,s,S],queryFn:async()=>{if(e===`import`){let e=await A.memories.previewImport(s,S);return{dir:e.dir,rows:e.memories.map(e=>({...e,selectable:e.status===`new`||e.can_replace}))}}let t=await A.memories.previewExport(s,S);return{dir:t.dir,index:t.index,rows:t.memories.map(e=>({...e,selectable:e.status===`new`||e.can_overwrite,...e.status===`duplicate`?{error:e.reason}:{}}))}},enabled:!!(s&&S)}),w=a({mutationFn:async t=>{if(e===`import`){let e=await A.memories.importNative(s,S,t.map(e=>({name:e.name,...e.status===`new`?{}:{replace:!0}})));return{done:[...e.imported.map(e=>`Imported ${e}`),...e.replaced.map(e=>`Replaced ${e}`)],skipped:e.skipped}}let n=await A.memories.exportNative(s,S,t.map(e=>e.name),t.filter(e=>e.status!==`new`).map(e=>e.name));return{done:n.exported.map(e=>`${e.replaced?`Replaced`:`Wrote`} ${e.file}`),skipped:n.skipped}},onSuccess:async t=>{_({}),await v.invalidateQueries({queryKey:[`memory-transfer`]}),e===`import`&&await v.invalidateQueries({queryKey:[`memories`]}),t.skipped.length||o()}}),T=w.isPending,E=s&&S?C.data?.rows??[]:[],D=E.filter(e=>e.selectable&&g[e.name]),O=E.filter(e=>e.status===`new`),k=e===`import`?Er:Dr,j=e===`import`?`Import`:`Export`,M=`memory-${e}`,N=y.error||C.error||w.error;return(0,X.jsx)(B,{open:!0,onOpenChange:e=>!e&&!T&&o(),children:(0,X.jsxs)(R,{closeDisabled:T,"data-testid":`${M}-dialog`,className:`flex min-w-0 w-[min(800px,calc(100vw-2rem))] max-w-none max-h-[calc(var(--app-height,100dvh)-2rem)] flex-col gap-0 overflow-hidden p-0`,children:[(0,X.jsxs)(I,{className:`shrink-0 flex-row items-center gap-1 border-b px-4 py-3 pr-12 sm:px-6`,children:[(0,X.jsx)(z,{children:e===`import`?`Import native memories`:`Export memories`}),(0,X.jsx)(oe,{label:`memory ${e}`,children:e===`import`?`Reads Claude Code memory files (~/.claude/projects/<project>/memory/*.md), Codex notes (~/.codex/memories/extensions/ad_hoc/notes) or any folder of memory files into this project. Near copies are flagged so a small edit does not create a duplicate.`:`Writes this project's memories as memory files: Claude Code folders also get a MEMORY.md index, and Codex merges its notes into its memory. Existing files are only replaced when you select them, and a backup is kept.`})]}),(0,X.jsxs)(`div`,{className:`min-h-0 min-w-0 flex-1 space-y-4 overflow-y-auto overscroll-contain px-4 py-4 sm:px-6`,"data-testid":`${M}-body`,children:[(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(`label`,{htmlFor:`${M}-project`,className:`text-sm font-medium`,children:e===`import`?`Into project`:`From project`}),(0,X.jsxs)(`select`,{id:`${M}-project`,"data-testid":`${M}-project`,className:`block h-11 w-full rounded-md border border-input bg-background px-3 text-sm sm:h-8`,value:s,disabled:T,onChange:e=>{c(e.target.value),u(null),_({}),w.reset()},children:[(0,X.jsx)(`option`,{value:``,children:`Choose a project`}),n.map(e=>(0,X.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(`label`,{htmlFor:`${M}-source`,className:`text-sm font-medium`,children:e===`import`?`Source`:`Destination`}),(0,X.jsxs)(`select`,{id:`${M}-source`,"data-testid":`${M}-source`,className:`block h-11 w-full rounded-md border border-input bg-background px-3 text-sm sm:h-8`,value:x,disabled:T||!s||y.isLoading,onChange:e=>{u(e.target.value),_({}),w.reset()},children:[(0,X.jsx)(`option`,{value:``,children:`Choose a folder`}),b.map(e=>(0,X.jsxs)(`option`,{value:e.dir,children:[e.label,` · `,e.count,` `,e.count===1?`memory`:`memories`,e.project_match?` · this project`:``]},e.dir)),(0,X.jsx)(`option`,{value:Or,children:`Custom folder`})]}),x===Or&&(0,X.jsxs)(`form`,{className:`flex flex-col gap-2 sm:flex-row sm:items-end`,onSubmit:e=>{e.preventDefault(),_({}),h(d.trim())},children:[(0,X.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,X.jsx)(Lt,{id:`${M}-folder`,label:`Folder`,value:d,disabled:T,onChange:p})}),(0,X.jsx)(f,{type:`submit`,variant:`outline`,"data-testid":`${M}-folder-apply`,disabled:T||!d.trim(),children:e===`import`?`Scan`:`Compare`})]})]}),C.isLoading&&s&&S&&(0,X.jsx)(`p`,{role:`status`,children:`Reading the folder…`}),C.data&&s&&S&&(0,X.jsxs)(`section`,{"data-testid":`${M}-plan`,className:`space-y-1`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,X.jsxs)(`p`,{className:`min-w-0 flex-1 text-xs text-outline wrap-break-word`,children:[C.data.dir,C.data.index?` · MEMORY.md index is updated`:``]}),(0,X.jsxs)(f,{size:`sm`,variant:`outline`,"data-testid":`${M}-select-new`,disabled:T||!O.length,onClick:()=>_({...g,...Object.fromEntries(O.map(e=>[e.name,!0]))}),children:[`Select all new (`,O.length,`)`]})]}),!E.length&&(0,X.jsx)(`p`,{role:`status`,children:e===`import`?`No memory files in this folder.`:`This project has no memories.`}),(0,X.jsx)(`div`,{className:`divide-y divide-border`,children:E.map(e=>(0,X.jsxs)(`label`,{className:`flex min-h-11 min-w-0 items-start gap-3 py-2 text-sm`,"data-testid":`${M}-item`,"data-memory-name":e.name,"data-status":e.status,children:[(0,X.jsx)(`input`,{type:`checkbox`,"aria-label":`${j} ${e.name}`,className:`mt-1 shrink-0`,"data-testid":`${M}-select`,checked:e.selectable&&!!g[e.name],disabled:T||!e.selectable,onChange:t=>_({...g,[e.name]:t.target.checked})}),(0,X.jsxs)(`span`,{className:`min-w-0 wrap-break-word`,children:[(0,X.jsx)(`span`,{className:`font-medium`,children:e.name}),k[e.status]&&(0,X.jsx)(`span`,{className:`ml-2 text-xs text-outline`,children:k[e.status]}),(0,X.jsx)(`span`,{className:`mt-0.5 line-clamp-2 text-xs leading-4 text-outline`,children:e.description}),(0,X.jsx)(Rt,{match:e.match}),e.error&&(0,X.jsx)(`span`,{className:`block text-xs text-destructive`,children:e.error})]})]},e.name))})]}),w.data?.skipped.map(e=>(0,X.jsxs)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:[`Skipped `,e.name,`: `,e.reason]},e.name)),N&&(0,X.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:N.message})]}),(0,X.jsxs)(L,{className:`shrink-0 border-t px-4 py-3 sm:px-6`,children:[(0,X.jsx)(f,{variant:`ghost`,disabled:T,onClick:o,children:`Close`}),(0,X.jsx)(f,{"data-testid":`${M}-submit`,disabled:T||!D.length,onClick:()=>w.mutate(D),children:T?`${j===`Import`?`Importing`:`Exporting`}…`:`${j} selected${D.length?` (${D.length})`:``}`})]})]})})}var Ar=`all`,jr=200,Mr=[{value:`reads`,label:`Most read`},{value:`recent`,label:`Recent`},{value:`priority`,label:`Priority`}];function Nr(e){return new Date(e*1e3).toLocaleString()}function Pr({projectId:e}){let t=o(),n=u(),{memoryProject:r,memoryName:i}=c(),[a,s]=tt(`project`,e),[l,d]=tt(`memoryQuery`,``),[p,m]=tt(`memorySort`,`reads`,Mr.map(e=>e.value)),[h,g]=(0,J.useState)(l);(0,J.useEffect)(()=>g(l),[l]);let _=(0,J.useRef)(d);_.current=d,(0,J.useEffect)(()=>{if(h===l)return;let e=window.setTimeout(()=>_.current(h,{replace:!0}),250);return()=>window.clearTimeout(e)},[h,l]);let v=we(`lg`),[y,b]=(0,J.useState)(null),[x,S]=(0,J.useState)(null),{data:O}=Ge({status:`active`}),k=pt(),[A,N]=(0,J.useState)(!1),[te,F]=(0,J.useState)(null),I=a===`unassigned`,L=a===Ar,R=ht({project_id:L?void 0:a,q:l||void 0,sort:p,limit:jr},{enabled:!I}),z=R.data?.memories??[],B=e=>O?.find(t=>t.id===e)?.name??e,ne=L||I?null:a,V=z.find(e=>e.project_id===r&&e.name===i),ie=e=>t(`${re(e.project_id,e.name)}${n.search}`),ae=()=>t(`${xe}${n.search}`),H=L||!I&&r===a;return(0,J.useEffect)(()=>{r&&i&&!H&&t(`${xe}${n.search}`,{replace:!0})},[r,i,H,t,n.search]),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(et,{title:`Memories`,help:`Short project facts such as ports, conventions and decisions that agents can read in later sessions. Longer procedures belong in a skill.`,meta:R.data?`${R.data.total} ${R.data.total===1?`memory`:`memories`}`:void 0,action:(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,X.jsxs)(fe,{open:A,onOpenChange:N,children:[(0,X.jsx)(ve,{asChild:!0,children:(0,X.jsxs)(f,{"data-testid":`memory-transfer-menu`,"aria-label":`Import or export memories`,size:`sm`,variant:`ghost`,children:[(0,X.jsx)(M,{size:14}),(0,X.jsx)(`span`,{className:`hidden sm:inline`,children:`Import / export`}),(0,X.jsx)(j,{size:12,className:`hidden sm:block`})]})}),(0,X.jsxs)(me,{"aria-label":`Import or export memories`,align:`end`,className:`w-64 space-y-1 p-1`,children:[(0,X.jsxs)(f,{"data-testid":`memory-import-button`,size:`sm`,variant:`ghost`,className:`w-full justify-start`,onClick:()=>{N(!1),F(`import`)},children:[(0,X.jsx)(M,{size:12,className:`mr-1`}),` Import native memories`]}),(0,X.jsxs)(f,{"data-testid":`memory-export-button`,size:`sm`,variant:`ghost`,className:`w-full justify-start`,onClick:()=>{N(!1),F(`export`)},children:[(0,X.jsx)(P,{size:12,className:`mr-1`}),` Export to native memory`]})]})]}),(0,X.jsxs)(f,{"data-testid":`new-memory-button`,size:`sm`,onClick:()=>b(`new`),className:`font-label text-sm`,children:[(0,X.jsx)(Ee,{size:12,className:`mr-1`}),` New memory`]})]})}),(0,X.jsxs)(`div`,{className:`mb-4 flex flex-wrap items-center gap-2`,children:[(0,X.jsxs)(ee,{activeCount:Number(p!==`reads`)+Number(a!==Ar),children:[(0,X.jsxs)(T,{value:a,onValueChange:e=>s(e),children:[(0,X.jsx)(C,{"aria-label":`Project`,"data-testid":`memory-project-filter`,className:`h-9 w-48 bg-background text-on-surface font-body text-sm`,children:(0,X.jsx)(E,{})}),(0,X.jsxs)(D,{className:`bg-surface border-outline-variant`,children:[(0,X.jsx)(w,{value:Ar,className:`font-body text-sm`,children:`All projects`}),I&&(0,X.jsx)(w,{value:`unassigned`,className:`font-body text-sm`,children:`Unassigned`}),O?.map(e=>(0,X.jsx)(w,{value:e.id,"data-testid":`memory-project-option-${e.id}`,className:`font-body text-sm`,children:e.name},e.id))]})]}),(0,X.jsx)(`div`,{className:`flex shrink-0 flex-wrap gap-1.5`,children:Mr.map(e=>(0,X.jsx)(`button`,{type:`button`,onClick:()=>m(e.value),"data-testid":`memory-sort-${e.value}`,"aria-pressed":p===e.value,className:`font-label text-sm px-3 py-1.5 border transition-colors ${p===e.value?`bg-surface-highest text-on-surface border-transparent`:`bg-transparent border-transparent text-muted-foreground hover:bg-surface-low hover:text-on-surface`}`,children:e.label},e.value))})]}),(0,X.jsxs)(`div`,{className:`relative order-first min-w-0 flex-1 lg:max-w-md`,children:[(0,X.jsx)(be,{size:12,className:`absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground`}),(0,X.jsx)(W,{"aria-label":`Search memories`,"data-testid":`memory-search-input`,value:h,onChange:e=>g(e.target.value),onKeyDown:e=>e.key===`Enter`&&d(e.currentTarget.value),placeholder:`Search memories...`,className:`pl-8 bg-background text-on-surface font-body text-sm placeholder:text-muted-foreground`})]})]}),I?(0,X.jsx)(nt,{message:`Memories belong to a project. Choose a project to see its memories.`}):R.error?(0,X.jsx)($e,{message:R.error.message,onRetry:()=>void R.refetch()}):R.isLoading?(0,X.jsx)(`div`,{className:`space-y-2`,children:[...[,,,,,]].map((e,t)=>(0,X.jsx)(Te,{className:`h-10 w-full bg-surface-highest`},t))}):z.length===0?(0,X.jsx)(nt,{message:l?`No memories match your search`:`No memories yet`}):v?(0,X.jsx)(`div`,{className:`overflow-hidden`,children:(0,X.jsxs)(ct,{children:[(0,X.jsx)(rt,{children:(0,X.jsxs)(ot,{className:`border-b border-outline-variant hover:bg-transparent`,children:[(0,X.jsx)(it,{className:`font-label text-sm text-muted-foreground`,children:`Name`}),(0,X.jsx)(it,{className:`font-label text-sm text-muted-foreground`,children:`Description`}),L&&(0,X.jsx)(it,{className:`font-label text-sm text-muted-foreground`,children:`Project`}),(0,X.jsx)(it,{className:`font-label text-sm text-muted-foreground w-20`,children:`Priority`}),(0,X.jsx)(it,{className:`font-label text-sm text-muted-foreground w-16`,children:`Reads`}),(0,X.jsx)(it,{className:`font-label text-sm text-muted-foreground w-44`,children:`Updated`})]})}),(0,X.jsx)(at,{children:z.map(e=>(0,X.jsxs)(ot,{"data-testid":`memory-row`,"data-memory-name":e.name,"data-memory-project":e.project_id,className:`border-b border-outline-variant/50 hover:bg-surface-low cursor-pointer`,onClick:()=>ie(e),children:[(0,X.jsx)(st,{className:`font-body text-sm font-medium text-on-surface`,children:(0,X.jsx)(`button`,{type:`button`,className:`min-h-11 text-left hover:text-primary`,onClick:t=>{t.stopPropagation(),ie(e)},children:e.name})}),(0,X.jsx)(st,{className:`font-body text-sm text-muted-foreground max-w-md truncate`,children:e.description}),L&&(0,X.jsx)(st,{className:`font-body text-sm text-muted-foreground`,children:B(e.project_id)}),(0,X.jsx)(st,{children:(0,X.jsx)(Ir,{priority:e.priority})}),(0,X.jsx)(st,{"data-testid":`memory-read-count`,className:`font-label text-sm text-muted-foreground`,title:Fr(e),children:e.read_count}),(0,X.jsx)(st,{className:`font-label text-sm text-muted-foreground`,children:Nr(e.updated_at)})]},e.key))})]})}):(0,X.jsx)(`div`,{className:`divide-y divide-outline-variant`,children:z.map(e=>(0,X.jsxs)(`button`,{type:`button`,"data-testid":`memory-row`,"data-memory-name":e.name,"data-memory-project":e.project_id,onClick:()=>ie(e),className:`flex w-full min-w-0 items-start justify-between gap-3 px-2 py-3 text-left hover:bg-surface`,children:[(0,X.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`span`,{className:`block wrap-break-word text-sm font-medium`,children:e.name}),(0,X.jsx)(`span`,{className:`mt-1 line-clamp-2 wrap-break-word text-sm text-muted-foreground`,children:e.description}),(0,X.jsxs)(`span`,{className:`mt-1 flex flex-wrap items-center gap-x-2 text-xs text-muted-foreground`,children:[L&&(0,X.jsx)(`span`,{children:B(e.project_id)}),(0,X.jsxs)(`span`,{"data-testid":`memory-read-count`,title:Fr(e),children:[e.read_count,` reads`]})]})]}),(0,X.jsx)(Ir,{priority:e.priority})]},e.key))}),r&&i&&H&&(0,X.jsx)(Lr,{projectId:r,name:i,projectName:B(r),listItem:V,onClose:ae,onEdit:b,onDelete:S},`${r}/${i}`),y&&(0,X.jsx)(Hr,{memory:y===`new`?null:y,defaultProjectId:L||I?``:a,onClose:()=>b(null),onCreated:e=>ie(e)}),te&&(0,X.jsx)(kr,{mode:te,initialProjectId:ne,projects:O??[],onClose:()=>F(null)}),x&&(0,X.jsx)(Ze,{open:!0,title:`Delete memory`,description:`Delete "${x.name}"? It can be restored from its history.`,confirmLabel:`Delete`,variant:`destructive`,isPending:k.isPending,onConfirm:()=>k.mutate({projectId:x.project_id,name:x.name},{onSuccess:()=>{S(null),ae()}}),onCancel:()=>S(null)}),k.error&&(0,X.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive mt-2`,children:k.error.message})]})}function Fr(e){let{mcp:t,cli:n,api:r,ui:i}=e.reads_by_source;return`mcp ${t} · cli ${n} · api ${r} · ui ${i}${e.last_read_at?` · last read ${Nr(e.last_read_at)}`:``}`}function Ir({priority:e}){return e===null?(0,X.jsx)(`span`,{"data-testid":`memory-priority`,className:`font-label text-xs text-outline`,children:`Unscored`}):(0,X.jsxs)(`span`,{"data-testid":`memory-priority`,className:`font-label text-xs text-primary`,children:[`P`,e]})}function Lr({projectId:e,name:t,projectName:n,listItem:r,onClose:i,onEdit:a,onDelete:o}){let{data:s,isLoading:c,error:l,refetch:u}=ft(e,t);return(0,X.jsx)(De,{open:!0,onOpenChange:e=>!e&&i(),children:(0,X.jsxs)(de,{"data-testid":`memory-detail`,defaultWidth:860,resizeKey:`memories`,children:[(0,X.jsxs)(Ae,{children:[(0,X.jsx)(Oe,{children:t}),s&&(0,X.jsx)(`p`,{"data-testid":`memory-detail-description`,className:`font-body text-sm text-muted-foreground mt-1`,children:s.description})]}),(0,X.jsx)(se,{children:l?(0,X.jsx)($e,{message:l.message,onRetry:()=>void u()}):c||!s?(0,X.jsx)(`div`,{className:`space-y-3`,children:[...[,,,,]].map((e,t)=>(0,X.jsx)(Te,{className:`h-8 w-full bg-surface-highest`},t))}):(0,X.jsxs)(`div`,{className:`space-y-6`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,X.jsxs)(f,{"data-testid":`memory-edit`,size:`sm`,variant:`outline`,onClick:()=>a(s),children:[(0,X.jsx)(le,{size:12,className:`mr-1`}),` Edit`]}),(0,X.jsxs)(f,{"data-testid":`memory-delete`,size:`sm`,variant:`outline`,onClick:()=>o(s),children:[(0,X.jsx)(_e,{size:12,className:`mr-1`}),` Delete`]})]}),(0,X.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-4`,children:[(0,X.jsx)(Ue,{label:`Project`,children:n}),(0,X.jsx)(Ue,{label:`Priority`,children:(0,X.jsx)(Ir,{priority:s.priority})}),(0,X.jsx)(Ue,{label:`Reads`,children:r?(0,X.jsx)(`span`,{title:Fr(r),children:r.read_count}):`—`}),(0,X.jsx)(Ue,{label:`Author`,children:(0,X.jsx)(`span`,{"data-testid":`memory-detail-author`,children:s.author})}),(0,X.jsx)(Ue,{label:`Session`,children:(0,X.jsx)(`code`,{className:`font-mono text-xs break-all`,children:s.session_id??`—`})}),(0,X.jsx)(Ue,{label:`Updated`,children:Nr(s.updated_at)})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`font-label text-sm text-muted-foreground mb-2`,children:`Content`}),(0,X.jsx)(`div`,{"data-testid":`memory-detail-content`,className:`wrap-break-word font-body text-sm text-on-surface`,children:(0,X.jsx)(te,{readable:!0,children:s.content})})]}),(0,X.jsx)(zr,{projectId:e,name:t,onDeleted:i})]})})]})})}function Rr({label:e,snapshot:t}){return(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`p`,{className:`text-xs text-outline mt-2`,children:e}),t?(0,X.jsxs)(`div`,{className:`text-xs space-y-1`,children:[(0,X.jsxs)(`p`,{children:[(0,X.jsx)(`span`,{className:`text-outline`,children:`Priority:`}),` `,t.priority===null?`unscored`:t.priority]}),(0,X.jsxs)(`p`,{children:[(0,X.jsx)(`span`,{className:`text-outline`,children:`Description:`}),` `,t.description]}),(0,X.jsx)(`pre`,{className:`whitespace-pre-wrap break-all`,children:t.content})]}):(0,X.jsx)(`p`,{className:`text-xs italic text-muted-foreground`,children:`(none)`})]})}function zr({projectId:e,name:t,onDeleted:n}){let r=ut(e,t),i=gt(),[a,o]=(0,J.useState)(``),s=r.data?.changes??[],c=s[0];return(0,X.jsxs)(`section`,{"data-testid":`memory-history-panel`,className:`space-y-3`,children:[(0,X.jsx)(`h3`,{className:`text-sm font-medium`,children:`History`}),r.error&&(0,X.jsx)(`p`,{role:`alert`,children:r.error.message}),i.error&&(0,X.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:i.error.message}),s.length>1&&(0,X.jsx)(W,{"data-testid":`memory-revert-reason`,"aria-label":`Reason for reverting`,value:a,onChange:e=>o(e.target.value),placeholder:`Reason for reverting...`}),s.map(r=>(0,X.jsxs)(`details`,{"data-testid":`memory-history-change`,className:`border-b border-outline-variant p-3`,children:[(0,X.jsxs)(`summary`,{className:`text-xs cursor-pointer`,children:[r.action.replace(`memory.`,``),` · `,Nr(r.created_at),` ·`,` `,r.author,r.session_id?` · ${r.session_id}`:``,r.reason?` · ${r.reason}`:``]}),(0,X.jsx)(Rr,{label:`Before`,snapshot:r.previous}),(0,X.jsx)(Rr,{label:`After`,snapshot:r.current}),c&&r.previous&&(0,X.jsx)(f,{"data-testid":`memory-revert-change`,size:`sm`,variant:`outline`,className:`mt-2`,disabled:!a.trim()||i.isPending,onClick:()=>i.mutate({name:t,project_id:e,change_id:r.id,expected_change_id:c.id,reason:a.trim()},{onSuccess:({memory:e})=>{o(``),e||n()}}),children:`Restore state before this change`})]},r.id))]})}function Br(e){return[...e].length}function Vr({value:e,max:t,testId:n}){let r=Br(e);return(0,X.jsx)(`span`,{"data-testid":n,className:`text-xs ${t!==void 0&&r>t?`text-destructive`:`text-muted-foreground`}`,children:t===void 0?r:`${r}/${t}`})}function Hr({memory:e,defaultProjectId:t,onClose:n,onCreated:r}){let{data:i}=Ge({status:`active`}),[a,o]=(0,J.useState)(e?.project_id??t),[s,c]=(0,J.useState)(e?.name??``),[l,u]=(0,J.useState)(e?.description??``),[d,p]=(0,J.useState)(e?.content??``),[m,h]=(0,J.useState)(e?.priority===null||e?.priority===void 0?``:String(e.priority)),[g,_]=(0,J.useState)(``),v=_t(),y=dt(),b=(0,J.useRef)(JSON.stringify([a,s,l,d,m,g])),x=mt().data?.content_max,k=e?y:v,A=qe([{id:`details`,label:`Details`},{id:`content`,label:`Content`}]),j=m.trim()===``?null:Number(m),M=j===null||Number.isInteger(j)&&j>=0&&j<=100,N=!!a&&!!s.trim()&&!!l.trim()&&Br(l)<=300&&!!d.trim()&&(x===void 0||Br(d)<=x)&&M;function ee(t){if(k.isPending)return;if(!N){!a||!s.trim()||!l.trim()||Br(l)>300||!M?A.invalid(`details`,a?M?`Enter a name and description within the displayed limits.`:`Priority must be a whole number from 0 to 100.`:`Choose a project.`):A.invalid(`content`,`Enter memory content within the displayed limit.`);return}if(!e){v.mutate({project_id:a,name:s.trim(),description:l.trim(),content:d.trim(),priority:j},{onSuccess:e=>{t(),r(e)}});return}let n={...l.trim()!==e.description&&{description:l.trim()},...d.trim()!==e.content&&{content:d.trim()},...j!==e.priority&&{priority:j}};Object.keys(n).length===0?t():y.mutate({name:e.name,project_id:e.project_id,...n,...g.trim()&&{reason:g.trim()}},{onSuccess:t})}return(0,X.jsx)(O,{open:!0,onClose:n,busy:k.isPending,dirty:JSON.stringify([a,s,l,d,m,g])!==b.current,testId:`memory-form-dialog`,className:A.step===`content`?`h-[min(85dvh,calc(var(--app-height,100dvh)-2rem))]`:void 0,children:(t,n)=>(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(I,{children:(0,X.jsx)(z,{className:`font-headline text-base text-on-surface`,children:e?`Edit ${e.name}`:`New memory`})}),(0,X.jsx)(`form`,{noValidate:!0,ref:A.form,onSubmit:e=>A.submit(e,()=>ee(n)),className:A.step===`content`?`min-h-0 flex-1`:`min-h-0`,children:(0,X.jsxs)(ae,{steps:A,children:[(0,X.jsxs)(`div`,{className:A.step===`content`?`work-form-body flex min-h-0 flex-1 flex-col gap-4`:`work-form-body space-y-4`,children:[(0,X.jsxs)(Ce,{steps:A,id:`details`,children:[!e&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(S,{className:`font-label text-sm text-muted-foreground`,children:`Project *`}),(0,X.jsxs)(T,{value:a,onValueChange:o,children:[(0,X.jsx)(C,{"aria-label":`Memory project`,"data-testid":`memory-project-select`,className:`bg-background text-on-surface font-body text-sm h-9`,children:(0,X.jsx)(E,{placeholder:`Choose a project`})}),(0,X.jsx)(D,{className:`bg-surface border-outline-variant`,children:i?.map(e=>(0,X.jsx)(w,{value:e.id,className:`font-body text-sm`,children:e.name},e.id))})]})]}),(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(S,{className:`font-label text-sm text-muted-foreground`,children:`Name *`}),(0,X.jsx)(W,{"aria-label":`Name`,"data-testid":`memory-name-input`,value:s,onChange:e=>c(e.target.value),placeholder:`api-port`,maxLength:64,required:!0,className:`bg-background text-on-surface font-body text-sm`,autoFocus:!0}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Lowercase words joined by hyphens, unique in the project.`})]})]}),(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsx)(S,{className:`font-label text-sm text-muted-foreground`,children:`Description *`}),(0,X.jsx)(Vr,{value:l,max:300,testId:`memory-description-count`})]}),(0,X.jsx)(F,{"aria-label":`Description`,"data-testid":`memory-description-input`,value:l,onChange:e=>u(e.target.value),placeholder:`One line agents see in lists and context`,className:`bg-background text-on-surface font-body text-sm resize-none`,rows:2,required:!0})]}),(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(S,{className:`font-label text-sm text-muted-foreground`,children:[`Priority (0-`,100,`, empty = unscored)`]}),(0,X.jsx)(W,{"aria-label":`Priority`,"data-testid":`memory-priority-input`,type:`number`,min:0,max:100,step:1,value:m,onChange:e=>h(e.target.value),className:`w-32 bg-background text-on-surface font-body text-sm`}),!M&&(0,X.jsxs)(`p`,{className:`text-xs text-destructive`,children:[`Priority must be a whole number from 0 to `,100,`.`]})]}),e&&(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(S,{className:`font-label text-sm text-muted-foreground`,children:`Reason`}),(0,X.jsx)(W,{"aria-label":`Reason`,"data-testid":`memory-reason-input`,value:g,onChange:e=>_(e.target.value),placeholder:`Why this changed (optional)`,className:`bg-background text-on-surface font-body text-sm`})]})]}),(0,X.jsx)(Ce,{steps:A,id:`content`,className:`flex min-h-0 flex-1 flex-col`,children:(0,X.jsx)(ge,{label:`Content`,"aria-label":`Content`,"data-testid":`memory-content-input`,value:d,onChange:p,placeholder:`The fact itself. Longer guidance belongs in a skill.`,accessory:(0,X.jsx)(Vr,{value:d,max:x,testId:`memory-content-count`}),fill:!0,disabled:k.isPending,required:!0})}),A.error&&(0,X.jsx)(`p`,{role:`alert`,"data-testid":`memory-step-error`,className:`text-sm text-destructive`,children:A.error}),k.error&&(0,X.jsx)(`p`,{role:`alert`,"data-testid":`memory-form-error`,className:`text-sm text-destructive md:col-span-2`,children:k.error.message})]}),(0,X.jsxs)(L,{className:`work-form-footer`,children:[(0,X.jsx)(f,{type:`button`,variant:`ghost`,size:`sm`,onClick:t,disabled:k.isPending,className:`font-label text-sm text-muted-foreground`,children:`Cancel`}),(0,X.jsx)(Je,{steps:A,busy:k.isPending,children:(0,X.jsx)(f,{"data-testid":`memory-submit`,type:`submit`,size:`sm`,disabled:k.isPending,className:`font-label text-sm`,children:k.isPending?`Saving...`:e?`Save`:`Create`})})]})]})})]})})}function Ur({projectId:e}){let t=lt(e),{pathname:n}=u();return n.startsWith(`/knowledge/memories`)?(0,X.jsx)(`div`,{"data-testid":`knowledge-base-view`,children:(0,X.jsx)(Pr,{projectId:e,embedded:!0})}):(0,X.jsx)(`div`,{"data-testid":`knowledge-base-view`,className:`flex min-h-0 min-w-0 flex-1`,children:(0,X.jsx)(Kr,{projectId:t===`all`||t===`unassigned`?void 0:t,globalOnly:t===`unassigned`},t)})}function Wr(e){return e.replace(/```[\w-]*/g,` `).replace(/<\/?[a-z][^>]*>/gi,` `).replace(/!?\[([^\]]*)\]\([^)]*\)/g,`$1`).replace(/(^|\s)#{1,6}\s+/g,`$1`).replace(/(^|\n)\s*(?:>\s*)+/g,`$1`).replace(/(^|\n)\s*(?:[-*+]|\d+[.)])\s+/g,`$1`).replace(/\|?\s*:?-{3,}:?\s*(?:\|\s*:?-{3,}:?\s*)*\|?/g,` `).replace(/(^|\s)(?:\*{3,}|_{3,})(?=\s|$)/g,`$1`).replace(/`/g,``).replace(/(^|[\s(«])[*_~]+(?=\S)/g,`$1`).replace(/(\S)[*_~]+(?=$|[\s).,;:!?»])/g,`$1`).replace(/\s*\|[\s|]*/g,` · `).replace(/\s+/g,` `).replace(/^ · | · $/g,``).trim()}function Gr({text:e}){let t=Wr(e).split(/«([^»]*)»/g);return(0,X.jsx)(X.Fragment,{children:t.map((e,t)=>t%2?(0,X.jsx)(`mark`,{className:`rounded-xs bg-primary/20 px-0.5 text-on-surface`,children:e},t):(0,X.jsx)(J.Fragment,{children:e},t))})}function Kr({projectId:e,globalOnly:t=!1}){let[n,r]=s(),i=n.get(`kb`),a=n.get(`document`),o=n.get(`label`)??``,c=n.get(`q`)??``,l=n.get(`searchAll`)===`1`,[u,p]=(0,J.useState)(c);(0,J.useEffect)(()=>p(c),[c]);let[S,C]=(0,J.useState)(null),[w,T]=(0,J.useState)(!1),E=we(`lg`),[D,O]=(0,J.useState)(()=>typeof window<`u`&&window.innerWidth>=1600),[k,A]=(0,J.useState)(!1),[j,M]=(0,J.useState)(null),[N,ee]=(0,J.useState)();function P(){C(null),ee(void 0)}let te=Ge(),F=Ft(e,t),I=F.data?.find(e=>e.id===i)??null,L=Pt(I?.id??null),R=St(F.data===void 0?null:a),z=F.data!==void 0&&(I!==null||F.data.length===0),B=Ot(c&&z?{query:c,...I&&!l?{kb_ids:[I.id]}:{},scope:e?`default`:t?`global`:`all`,limit:20}:null,e),ne=Tr();function V(e,t=!1){r(()=>{let t=new URLSearchParams(window.location.search);for(let[n,r]of Object.entries(e))r?t.set(n,r):t.delete(n);return t},{replace:t})}let re=()=>!a||vt(rr(a));function ie(e){T(!1),(e!==i||a||c)&&re()&&(e!==i&&ne.clearFinished(),V({kb:e,document:null,label:null,q:null}))}function ae(e,t){T(!1),(e===a||re())&&(V({document:e,q:null}),M(t??null))}function H(e,t){V({document:e}),M(t??null)}function U(){T(!1);let e=u.trim();if(!e)return V({q:null});re()&&V({q:e,document:null})}(0,J.useEffect)(()=>{E&&T(!1)},[E]),(0,J.useEffect)(()=>{F.data&&(a&&R.data&&!F.data.some(e=>e.id===R.data.kb_id)?V({kb:F.data[0]?.id??null,document:null,label:null,q:null},!0):i&&!F.data.some(e=>e.id===i)&&(!a||R.error)?V({kb:null,document:null},!0):!i&&F.data[0]&&V({kb:F.data[0].id},!0))}),(0,J.useEffect)(()=>{R.data&&R.data.kb_id!==i&&F.data?.some(e=>e.id===R.data.kb_id)&&V({kb:R.data.kb_id,label:null},!0)}),(0,J.useEffect)(()=>{if(!j||!R.data)return;let e=[...document.querySelector(`[data-testid="kb-document"]`)?.querySelectorAll(`h1,h2,h3,h4,h5,h6`)??[]].find(e=>e.textContent?.trim()===j);e&&(e.scrollIntoView({block:`start`}),M(null))});function se(e){e.preventDefault(),A(!1);let t=[...e.dataTransfer.files];I&&t.length!==0&&(t.length>1?ne.add(I.id,t):(ee(t[0]),C(`new-document`)))}let le=e=>e===null?`Global`:te.data?.find(t=>t.id===e)?.name??`Project`;if(F.error)return(0,X.jsx)($e,{message:F.error.message,onRetry:()=>F.refetch()});let ue=a?R.data&&I&&R.data.kb_id===I.id?(0,X.jsx)(sr,{kb:I,doc:R.data,detailsOpen:D,onDetailsOpenChange:O,onHome:()=>ie(I.id),onOpen:ae,onDeleted:()=>V({document:null}),onReplaceFile:e=>R.data&&ne.add(R.data.kb_id,[e],{replace:{document_id:R.data.id,expected_revision:R.data.revision}})},R.data.id):R.error?(0,X.jsxs)(Xr,{children:[(0,X.jsx)(`p`,{role:`alert`,"data-testid":`kb-document-error`,className:`text-sm text-error`,children:R.error.message}),(0,X.jsx)(f,{variant:`outline`,onClick:()=>V({document:null}),children:`Back`})]}):(0,X.jsx)(Xr,{children:(0,X.jsx)(`p`,{role:`status`,className:`text-sm text-outline`,children:`Loading document…`})}):c?(0,X.jsx)(Yr,{children:(0,X.jsx)(Zr,{query:c,search:B,onOpen:H,onClear:()=>V({q:null})})}):I?(0,X.jsx)(Yr,{children:(0,X.jsx)(br,{kb:I,owner:le(I.project_id),listing:L.data,label:o,onLabel:e=>V({label:e}),onOpen:ae,onNewDocument:()=>C(`new-document`),onSettings:()=>C(`settings`)})}):F.data?.length===0?(0,X.jsxs)(Xr,{testId:`empty-state`,children:[(0,X.jsx)(`p`,{className:`text-sm text-outline`,children:`No knowledge bases configured`}),(0,X.jsxs)(f,{"data-testid":`kb-empty-create`,onClick:()=>C(`create`),children:[(0,X.jsx)(Ee,{size:16}),`New knowledge base`]})]}):null,de=(0,X.jsxs)(`nav`,{id:`kb-sidebar-panel`,"aria-label":`Knowledge bases`,"data-testid":`kb-sidebar`,className:`flex h-full min-h-0 flex-col border-outline-variant bg-background lg:w-72 lg:shrink-0 lg:border-r`,children:[(0,X.jsxs)(`form`,{className:`flex shrink-0 items-center gap-1.5 border-b border-outline-variant p-3`,onSubmit:e=>{e.preventDefault(),U()},children:[(0,X.jsx)(W,{"aria-label":`Search knowledge`,"data-testid":`kb-search-input`,value:u,onChange:e=>p(e.target.value),placeholder:I&&!l?`Search ${I.name}`:`Search everything`,className:`h-9 min-w-0 flex-1`}),(0,X.jsx)(f,{type:`submit`,size:`icon`,variant:`ghost`,"data-testid":`kb-search-submit`,"aria-label":`Search`,children:(0,X.jsx)(be,{size:16})}),w&&(0,X.jsx)(f,{type:`button`,size:`icon`,variant:`ghost`,"data-testid":`kb-browser-close`,"aria-label":`Close knowledge browser`,onClick:()=>T(!1),children:(0,X.jsx)(x,{size:16})})]}),I&&(0,X.jsxs)(`label`,{className:`flex shrink-0 items-center gap-2 border-b border-outline-variant px-3 py-2 text-xs text-outline`,children:[(0,X.jsx)(`input`,{type:`checkbox`,"data-testid":`kb-search-all`,checked:l,onChange:e=>V({searchAll:e.target.checked?`1`:null})}),`Search all knowledge bases`]}),(0,X.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between px-2 pb-1`,children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1`,children:[(0,X.jsx)(`h2`,{className:`text-sm font-medium text-outline`,children:`Knowledge bases`}),(0,X.jsx)(oe,{label:`Knowledge bases`,children:`Upload documents, write Markdown or sync a folder. Agents search this knowledge with citations, and document details show what they read.`})]}),(0,X.jsx)(f,{size:`icon`,variant:`ghost`,"aria-label":`New knowledge base`,"data-testid":`kb-create`,onClick:()=>C(`create`),children:(0,X.jsx)(Ee,{size:16})})]}),F.isLoading&&(0,X.jsx)(Te,{className:`mx-2 h-9`}),(0,X.jsx)(qr,{bases:F.data??[],projectName:le,kbId:i,documentId:a,documents:L.data?.documents??[],onSelectKb:ie,onOpenDocument:ae})]}),(0,X.jsx)(Jr,{})]});return(0,X.jsx)(v,{open:w&&!E,onOpenChange:T,children:(0,X.jsxs)(`div`,{"data-testid":`knowledge-bases`,className:`relative flex min-h-0 min-w-0 flex-1`,children:[(0,X.jsx)(`h1`,{"data-testid":`view-title`,className:`sr-only`,children:`Knowledge bases`}),E&&de,!E&&(0,X.jsxs)(b,{children:[(0,X.jsx)(y,{className:`fixed inset-0 z-50 bg-black/70`}),(0,X.jsxs)(g,{"data-testid":`kb-mobile-browser`,className:`viewport-sheet fixed inset-x-0 z-50 bg-background`,children:[(0,X.jsx)(h,{className:`sr-only`,children:`Browse knowledge`}),(0,X.jsx)(m,{className:`sr-only`,children:`Search knowledge bases and choose a document`}),de]})]}),(0,X.jsxs)(`div`,{"data-testid":`kb-dropzone`,className:d(`relative flex min-h-0 min-w-0 flex-1 flex-col`,k&&`outline-2 -outline-offset-4 outline-dashed outline-primary`),onDragOver:e=>{I&&(e.preventDefault(),A(!0))},onDragLeave:()=>A(!1),onDrop:se,children:[(0,X.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b border-outline-variant px-3 py-2 lg:hidden`,children:[(0,X.jsx)(_,{asChild:!0,children:(0,X.jsxs)(f,{"data-testid":`kb-browser-open`,variant:`ghost`,size:`sm`,"aria-expanded":w,"aria-controls":`kb-sidebar-panel`,onClick:()=>T(!0),children:[(0,X.jsx)(ce,{size:16}),`Browse`]})}),I&&(0,X.jsx)(`span`,{className:`min-w-0 truncate text-sm text-outline`,children:I.name})]}),a&&c&&(0,X.jsx)(`div`,{className:`flex shrink-0 items-center border-b border-outline-variant px-3 py-1`,children:(0,X.jsxs)(f,{variant:`ghost`,size:`sm`,"data-testid":`kb-search-back`,className:`min-w-0`,onClick:()=>re()&&V({document:null}),children:[(0,X.jsx)(He,{size:14}),(0,X.jsxs)(`span`,{className:`truncate`,children:[`Back to results for “`,c,`”`]})]})}),(0,X.jsx)(`div`,{className:`flex min-h-0 min-w-0 flex-1`,children:ue}),(0,X.jsx)(Qr,{uploads:ne,onOpen:ae})]}),S===`create`&&(0,X.jsx)(Ln,{open:!0,projectId:e,onClose:()=>C(null),onCreated:e=>{C(null),T(!1),V({kb:e.id,document:null,label:null,q:null})}}),S===`settings`&&I&&(0,X.jsx)(Rn,{kb:I,onClose:()=>C(null),onDeleted:()=>{C(null),V({kb:null,document:null,label:null})}}),S===`new-document`&&I&&(0,X.jsx)(Hn,{kb:I,initialFile:N,onClose:P,onUploadMany:e=>{P(),ne.add(I.id,e)},onCreated:(e,t)=>{P(),V({document:e.id,editorMode:t?null:`edit`})}})]})})}function qr({bases:e,projectName:t,kbId:n,documentId:r,documents:i,onSelectKb:a,onOpenDocument:o}){let[s,c]=(0,J.useState)(null);(0,J.useEffect)(()=>{r&&c(null)},[r]);let l=new Map;for(let n of e){let e=t(n.project_id);l.set(e,[...l.get(e)??[],n])}let u=[...l.entries()].sort(([e],[t])=>e===`Global`?-1:t===`Global`?1:e.localeCompare(t));return(0,X.jsx)(`div`,{"data-testid":`kb-list`,className:`space-y-3`,children:u.map(([e,t])=>(0,X.jsxs)(`section`,{"aria-label":e,children:[u.length>1&&(0,X.jsx)(`h3`,{className:`truncate px-2 pb-0.5 pt-1 text-xs text-outline`,children:e}),(0,X.jsx)(`ul`,{className:`space-y-0.5`,children:t.map(e=>{let t=e.id===n,l=t&&s!==e.id&&i.length>0;return(0,X.jsxs)(`li`,{children:[(0,X.jsxs)(`button`,{type:`button`,"data-testid":`kb-row`,"data-kb-name":e.name,"aria-current":t&&!r?`page`:void 0,"aria-expanded":l,className:d(`flex min-h-9 w-full items-center gap-2 rounded-md px-2 text-left text-sm hover:bg-surface-high`,t&&`font-medium`,t&&!r&&`bg-surface-high`),onClick:()=>{t&&c(t=>t===e.id?null:e.id),a(e.id)},children:[(0,X.jsx)(Fe,{size:14,"aria-hidden":!0,className:d(`-mr-1 shrink-0 text-outline transition-transform motion-reduce:transition-none`,l&&`rotate-90`,e.document_count===0&&`invisible`)}),(0,X.jsx)(Ve,{size:15,className:`shrink-0 text-outline`,"aria-hidden":!0}),(0,X.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.name}),(0,X.jsx)(`span`,{className:`text-xs font-normal tabular-nums text-outline`,children:e.document_count})]}),l&&(0,X.jsx)(`ul`,{className:`ml-4 mt-0.5 space-y-0.5 border-l border-outline-variant pl-2`,children:i.map(e=>(0,X.jsx)(`li`,{children:(0,X.jsxs)(`button`,{type:`button`,"data-testid":`kb-nav-document`,"data-document-title":e.title,"aria-current":e.id===r?`page`:void 0,className:d(`flex min-h-8 w-full items-center gap-2 rounded-md px-2 text-left text-sm hover:bg-surface-high`,e.id===r?`bg-surface-high text-on-surface`:`text-outline`),onClick:()=>o(e.id),children:[(0,X.jsx)(je,{size:14,className:`shrink-0`,"aria-hidden":!0}),(0,X.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.title})]})},e.id))})]},e.id)})})]},e))})}function Jr(){let e=bt(),t=e.data,n=t?t.embedding.provider===`none`?{text:`Keyword search only`,title:`Configure embeddings in Settings to also search by meaning`}:t.embedding.ready?{text:`Hybrid search`,title:t.embedding.model??void 0}:{text:`Embeddings not ready`,title:t.embedding.detail??``}:null,r=t?t.jobs.queued+t.jobs.running:0;return(0,X.jsx)(`p`,{role:`status`,"data-testid":`kb-status`,className:`shrink-0 border-t border-outline-variant px-4 py-2 text-xs text-outline`,children:t?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{title:n?.title,children:n?.text}),r?` · ${r} processing`:``]}):e.error?`Knowledge status unavailable`:`Loading…`})}function Yr({children:e}){return(0,X.jsx)(`div`,{className:`min-h-0 min-w-0 flex-1 overflow-y-auto`,children:e})}function Xr({children:e,testId:t}){return(0,X.jsx)(`div`,{"data-testid":t,className:`mx-auto flex max-w-lg flex-1 flex-col items-start justify-center gap-4 p-6`,children:e})}function Zr({query:e,search:t,onOpen:n,onClear:r}){let i=t.data;return(0,X.jsxs)(`section`,{"data-testid":`kb-search-results`,"aria-label":`Search results`,className:`w-full min-w-0 space-y-4 p-4 sm:p-8`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsxs)(`h2`,{className:`mr-auto text-lg font-medium`,children:[`Results for “`,e,`”`]}),i&&i.hits.length>0&&(0,X.jsxs)(`span`,{className:`text-xs text-outline`,"data-testid":`kb-search-count`,children:[i.hits.length,` `,i.hits.length===1?`result`:`results`]}),(0,X.jsxs)(f,{variant:`ghost`,size:`sm`,onClick:r,"data-testid":`kb-search-clear`,children:[(0,X.jsx)(x,{size:14}),`Clear`]})]}),i?.degraded&&(0,X.jsx)(`p`,{role:`status`,className:`text-sm text-warning`,children:i.degraded}),t.isLoading&&(0,X.jsx)(`p`,{className:`text-sm text-outline`,children:`Searching…`}),t.error&&(0,X.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:t.error.message}),i?.hits.length===0&&(0,X.jsx)(`p`,{className:`text-sm text-outline`,"data-testid":`kb-search-empty`,children:`Nothing matched. Try other words or search all knowledge bases.`}),i?.hits.map(e=>(0,X.jsxs)(`article`,{"data-testid":`kb-search-result`,className:`space-y-2 border-b border-outline-variant pb-4`,children:[(0,X.jsxs)(`button`,{type:`button`,className:`block text-left`,onClick:()=>n(e.document_id,ti(e.passages[0]?.heading_path)),children:[(0,X.jsx)(`span`,{className:`block font-medium text-primary hover:underline`,children:e.title}),(0,X.jsxs)(`span`,{className:`block break-all text-xs text-outline`,children:[e.kb_name,` · `,e.path]})]}),e.labels.length>0&&(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.labels.map(e=>(0,X.jsx)(Nt,{variant:`secondary`,children:e},e))}),e.passages.map(t=>(0,X.jsxs)(`div`,{"data-testid":`kb-search-passage`,className:`cursor-pointer space-y-1 rounded-md p-2 hover:bg-surface-high`,onClick:()=>n(e.document_id,ti(t.heading_path)),children:[(t.heading_path.length>0||t.locator?.page||t.locator?.sheet)&&(0,X.jsx)(`div`,{className:`text-xs text-outline`,children:[...t.heading_path.map(Wr),...t.locator?.page?[`page ${t.locator.page}`]:[],...t.locator?.sheet?[`sheet ${t.locator.sheet}`]:[]].join(` › `)}),(0,X.jsx)(`p`,{className:`text-sm leading-relaxed`,children:(0,X.jsx)(Gr,{text:t.snippet})})]},t.chunk_id))]},e.document_id))]})}function Qr({uploads:e,onOpen:t}){if(!e.uploads.length)return null;let n=e.uploads.some(e=>e.status!==`uploading`);return(0,X.jsxs)(`section`,{"data-testid":`kb-upload-queue`,"aria-label":`Uploads`,className:`absolute bottom-4 right-4 z-10 flex max-h-72 w-80 max-w-[calc(100%-2rem)] flex-col rounded-lg border border-outline-variant bg-surface text-sm shadow-lg`,children:[(0,X.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between px-3 py-1.5`,children:[(0,X.jsx)(`span`,{className:`font-medium`,children:`Uploads`}),n&&(0,X.jsx)(f,{size:`sm`,variant:`ghost`,onClick:e.clearFinished,"data-testid":`kb-upload-clear`,children:`Dismiss`})]}),(0,X.jsx)(`div`,{className:`min-h-0 space-y-1 overflow-y-auto px-3 pb-2`,children:e.uploads.map(n=>(0,X.jsx)(ei,{upload:n,onOpen:t,onRetry:()=>e.retry(n.id)},n.id))})]})}var $r={pending:`Parsing…`,ok:`Open`,partial:`Open · partly parsed`,failed:`Parse failed`};function ei({upload:e,onOpen:t,onRetry:n}){let r=Pt(e.status===`done`?e.kbId:null).data?.documents.find(t=>t.id===e.document?.id)??e.document;return(0,X.jsxs)(`div`,{"data-testid":`kb-upload-item`,"data-status":e.status,"data-parse-state":r?.parse_state,className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.file.name}),e.status===`uploading`&&(0,X.jsx)(`span`,{className:`h-1.5 w-24 overflow-hidden rounded-full bg-surface-high`,role:`progressbar`,"aria-label":`Upload progress`,"aria-valuenow":Math.round(e.progress*100),children:(0,X.jsx)(`span`,{className:`block h-full bg-primary`,style:{width:`${Math.round(e.progress*100)}%`}})}),e.status===`done`&&r&&(0,X.jsx)(`button`,{type:`button`,className:d(`hover:underline`,r.parse_state===`failed`?`text-error`:`text-primary`),onClick:()=>t(r.id),children:$r[r.parse_state]}),e.status===`failed`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{role:`alert`,className:`text-error`,children:e.error}),(0,X.jsx)(f,{size:`sm`,variant:`ghost`,onClick:n,"data-testid":`kb-upload-retry`,children:`Retry`})]})]})}function ti(e){return e?.[e.length-1]}export{Ur as default};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/MarkdownRenderer-B6SKIKVL.js","assets/rolldown-runtime-DSDNlrLa.js","assets/jsx-runtime-CVMpzJz9.js","assets/react-dom-DTbwZiiP.js","assets/button-C91mbQEU.js","assets/floating-ui.react-dom-BDMgcqWu.js","assets/bundle-mjs-CdK3cBzO.js","assets/client-BnTXPI20.js","assets/preload-helper-BLdHbfdN.js","assets/dialog-D86vkhdt.js","assets/x-CIaAKXRo.js","assets/dist-bytwC6rk.js","assets/es2015-w69PgVrA.js","assets/document-display-BQ5dM8QT.js","assets/index-D5qFuDmc.js","assets/QueryClientProvider-DlPztvhd.js","assets/useMutation-HX90wI4L.js","assets/chunk-OB3PAWPO-1IihCzFx.js","assets/tabs-DpKnjRll.js","assets/dist-BKxzy3T8.js","assets/dist-Ct6061MC.js","assets/label-BdnRgBbz.js","assets/FormDialog-CelnA8hT.js","assets/dist-D8Wfxh48.js","assets/check-N8fVGVDO.js","assets/chevron-down-wgh-M0zj.js","assets/maximize-2-Daih3Vv7.js","assets/MarkdownEditor-CSloDLyL.js","assets/file-kind-BYU1kv95.js","assets/textarea-BRdsUa6B.js","assets/bulk-actions-C8S1Gt4W.js","assets/index-z4BVJQry.css","assets/mermaid.core-CE0shN4j.js","assets/chunk-Y2CYZVJY-DsF7k-Jl.js","assets/src-DpAUOMD9.js","assets/chunk-DU6HZSFF-BaVVqpDB.js","assets/chunk-75Z2AOVW-DGmxZV98.js","assets/dist-BwUkq7ma.js","assets/chunk-P2QGCYS3-DpMkYw3X.js","assets/chunk-PWAF6VOD-CP1kSMru.js","assets/chunk-GMAD6QVW-D7d5cxQ3.js","assets/chunk-4HAMMTFA-DY6eE90t.js","assets/rough.esm-Dy-Kn_BL.js","assets/chunk-GVQU2GXP-GfOuiNH1.js","assets/chunk-L3NEJ4N5-BD8q2mez.js","assets/chunk-OSK3NFVY-DN8XtEwT.js","assets/line-BmNPsHiE.js","assets/path-fybaL0A-.js","assets/array-BifhSqXX.js","assets/graphlib-DS17s2tU.js","assets/wiki-links-A52THGx_.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{a as e}from"./rolldown-runtime-DSDNlrLa.js";import{n as t,t as n}from"./jsx-runtime-CVMpzJz9.js";import{t as r}from"./preload-helper-BLdHbfdN.js";var i=e(t(),1),a=n(),o=(0,i.lazy)(()=>r(()=>import(`./MarkdownRenderer-B6SKIKVL.js`).then(e=>({default:e.MarkdownRenderer})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50]))),s=(0,i.memo)(function(e){let{fallback:t,...n}=e;return(0,a.jsx)(i.Suspense,{fallback:t??(0,a.jsx)(`div`,{role:`status`,className:`text-sm text-outline`,children:`Loading document…`}),children:(0,a.jsx)(o,{...n})})});export{s as t};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/SourceEditor-DNHVu9ux.js","assets/rolldown-runtime-DSDNlrLa.js","assets/jsx-runtime-CVMpzJz9.js","assets/client-BnTXPI20.js","assets/Markdown-CtVGTUZH.js","assets/preload-helper-BLdHbfdN.js","assets/file-kind-BYU1kv95.js","assets/index-D5qFuDmc.js","assets/QueryClientProvider-DlPztvhd.js","assets/useMutation-HX90wI4L.js","assets/react-dom-DTbwZiiP.js","assets/chunk-OB3PAWPO-1IihCzFx.js","assets/button-C91mbQEU.js","assets/floating-ui.react-dom-BDMgcqWu.js","assets/bundle-mjs-CdK3cBzO.js","assets/dist-bytwC6rk.js","assets/es2015-w69PgVrA.js","assets/x-CIaAKXRo.js","assets/tabs-DpKnjRll.js","assets/dist-BKxzy3T8.js","assets/dist-Ct6061MC.js","assets/label-BdnRgBbz.js","assets/FormDialog-CelnA8hT.js","assets/dist-D8Wfxh48.js","assets/check-N8fVGVDO.js","assets/chevron-down-wgh-M0zj.js","assets/dialog-D86vkhdt.js","assets/document-display-BQ5dM8QT.js","assets/maximize-2-Daih3Vv7.js","assets/textarea-BRdsUa6B.js","assets/bulk-actions-C8S1Gt4W.js","assets/index-z4BVJQry.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{a as e}from"./rolldown-runtime-DSDNlrLa.js";import{n as t,t as n}from"./jsx-runtime-CVMpzJz9.js";import{t as r}from"./button-C91mbQEU.js";import{h as i}from"./client-BnTXPI20.js";import{t as a}from"./maximize-2-Daih3Vv7.js";import{t as o}from"./preload-helper-BLdHbfdN.js";import{t as s}from"./Markdown-CtVGTUZH.js";import{r as c}from"./document-display-BQ5dM8QT.js";import{t as l}from"./file-kind-BYU1kv95.js";var u={name:`minimize-2`,size:24,node:[[`path`,{d:`m14 10 7-7`,key:`oa77jy`}],[`path`,{d:`M20 10h-6V4`,key:`mjg0md`}],[`path`,{d:`m3 21 7-7`,key:`tjx5ai`}],[`path`,{d:`M4 14h6v6`,key:`rmj7iw`}]]};u.node;var d=i(u),f=e(t(),1),p=n(),m=(0,f.lazy)(()=>o(()=>import(`./SourceEditor-DNHVu9ux.js`).then(e=>({default:e.SourceEditor})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31])));function h(e){return(0,p.jsx)(f.Suspense,{fallback:(0,p.jsx)(`div`,{style:{height:e.height??320},className:`p-3 text-xs text-outline`,children:`Loading editor...`}),children:(0,p.jsx)(m,{...e})})}function g(e,t){if(!t)return e;let n=e.match(/^\s*#[ \t]+(.+?)[ \t#]*(?:\r?\n|$)/),r=e=>e.trim().replace(/\s+/g,` `).toLowerCase();return n?.[1]&&r(n[1])===r(t)?e.slice(n[0].length):e}function _({path:e,value:t,onChange:n,onSave:i,readOnly:o=!1,testId:u,wikiLinks:m,initialMode:_,mode:v,onModeChange:y,header:b,height:x,id:S,label:C,placeholder:w,expanded:T,onExpandedChange:E,layout:D=`frame`,actions:O,notice:k,pageTitle:A,hideFrontmatter:j=!1,compact:M=!1}){let N=l(e),[P,F]=(0,f.useState)(_??(o&&N?`read`:`edit`)),I=v??P;function L(e){F(e),y?.(e)}let[R,z]=(0,f.useState)(!1),B=T??R,V=(0,f.useRef)(null);(0,f.useEffect)(()=>{if(!B||!V.current)return;let e=[],t=V.current;for(;t.parentElement;){let n=t.parentElement;for(let r of Array.from(n.children))r!==t&&r instanceof HTMLElement&&(e.push({element:r,inert:r.inert}),r.inert=!0);if(n.hasAttribute(`data-document-container`)||n===document.body)break;t=n}return()=>{for(let t of e)t.element.inert=t.inert}},[B]);function H(e){z(e),E?.(e)}(0,f.useEffect)(()=>{if(!B)return;function e(e){if(e.key!==`Escape`||e.defaultPrevented)return;let t=document.querySelector(`[role="dialog"], [role="alertdialog"]`);(!t||V.current?.contains(t))&&(z(!1),E?.(!1))}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[B,E]);let U=c(t),W=g(U.body,A),G=D===`page`&&N&&!B;return(0,p.jsxs)(`section`,{ref:V,"data-testid":`markdown-editor`,"data-expanded":B,"data-document-expanded":B,className:`flex min-w-0 flex-col ${G?``:`min-h-0 rounded-md border border-surface-highest bg-surface`} ${B?`fixed inset-2 z-60 sm:inset-6`:``}`,style:B||G?void 0:{height:x??`min(65dvh, 760px)`,minHeight:x?void 0:280},"aria-label":`Document ${e}`,onKeyDown:e=>{e.defaultPrevented||(e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`s`&&(e.preventDefault(),i?.())},children:[b&&(0,p.jsx)(`div`,{className:`shrink-0 border-b border-surface-highest p-3`,children:b}),(0,p.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center ${M?`gap-1`:`gap-2`} border-b border-surface-highest ${G?`sticky top-0 z-10 bg-background py-2`:M?`px-2 py-1`:`p-2`}`,children:[N&&(0,p.jsx)(`fieldset`,{className:`flex gap-1`,"aria-label":`Document mode`,children:[`read`,`edit`,`split`].map(e=>(0,p.jsx)(r,{type:`button`,size:`sm`,variant:!M&&I===e?`default`:`ghost`,className:`${e===`split`&&D===`page`?`hidden md:inline-flex`:``} ${M&&I===e?`bg-surface-highest text-on-surface`:``}`,"data-testid":`markdown-mode-${e}`,"aria-pressed":I===e,onClick:()=>L(e),children:e===`read`?`Read`:e===`edit`?o?`Source`:`Edit`:`Split`},e))}),(0,p.jsx)(`span`,{className:`min-w-0 flex-1 truncate px-1 text-xs text-outline`,title:e,children:D===`page`||M?``:e}),O,B&&i&&!b&&!O&&(0,p.jsx)(r,{type:`button`,"data-testid":`markdown-save`,disabled:o,onClick:i,children:`Save`}),(0,p.jsx)(r,{type:`button`,size:`icon`,variant:`ghost`,"data-testid":`markdown-expand`,"aria-label":B?`Exit fullscreen`:`Expand editor`,"aria-pressed":B,onClick:()=>H(!B),children:B?(0,p.jsx)(d,{size:16}):(0,p.jsx)(a,{size:16})})]}),k&&(0,p.jsx)(`div`,{className:`shrink-0 space-y-1 border-b border-surface-highest ${G?`py-2`:`p-3`}`,children:k}),(0,p.jsxs)(`div`,{className:`grid min-h-0 min-w-0 flex-1 ${G?`items-start gap-6 pt-4`:`overflow-hidden`} ${I===`split`&&N?`grid-rows-2 md:grid-cols-2 md:grid-rows-1`:`grid-cols-1`}`,children:[(0,p.jsx)(`div`,{className:`min-h-0 min-w-0 ${G?`[&_.cm-editor]:min-h-[50dvh]`:`overflow-hidden`} ${I===`read`&&N?`hidden`:``}`,children:(0,p.jsx)(h,{path:e,value:t,onChange:n,onSave:i,readOnly:o,height:G?`auto`:`100%`,testId:u,hidePreview:!0,defaultWrap:!0,id:S,label:C,placeholder:w})}),N&&I!==`edit`&&(0,p.jsx)(`article`,{"data-testid":`markdown-preview`,"aria-label":`Rendered Markdown`,className:`min-h-0 min-w-0 ${G?`pb-6`:`overflow-auto p-4 sm:p-8`} ${I===`split`&&!G?`border-t border-surface-highest md:border-l md:border-t-0`:``}`,children:(0,p.jsxs)(`div`,{className:`wrap-break-word ${G?`[&_:is(p,ul,ol,blockquote,h1,h2,h3,h4,h5,h6)]:max-w-[72ch]`:`mx-auto max-w-[76ch]`}`,children:[U.metadata!==null&&!j&&(0,p.jsxs)(`details`,{className:`mb-5 rounded border border-surface-highest p-3 text-sm text-outline`,children:[(0,p.jsx)(`summary`,{className:`cursor-pointer`,children:`Document metadata`}),(0,p.jsx)(`pre`,{className:`mt-3 whitespace-pre-wrap wrap-break-word font-mono text-xs`,children:U.metadata})]}),t.trim()?(0,p.jsx)(s,{readable:!0,wikiLinks:m,children:W}):(0,p.jsx)(`p`,{className:`text-sm text-outline`,children:`This document is empty.`})]})})]})]})}export{h as n,d as r,_ as t};
|