@spencerboucher/switchyard 0.12.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/README.md +2 -2
  2. package/dist/policies/worker.js +1350 -1276
  3. package/dist/switchyard.mjs +2338 -1651
  4. package/package.json +1 -1
  5. package/web-dist/assets/{AutomationView-BRVq9y-T.js → AutomationView-Cg7yk8nb.js} +2 -2
  6. package/web-dist/assets/{AutomationView-BRVq9y-T.js.map → AutomationView-Cg7yk8nb.js.map} +1 -1
  7. package/web-dist/assets/{Card-BqrWFEYY.js → Card-sHm0eI2Q.js} +2 -2
  8. package/web-dist/assets/{Card-BqrWFEYY.js.map → Card-sHm0eI2Q.js.map} +1 -1
  9. package/web-dist/assets/{Checkbox-DExv3fUO.js → Checkbox-CEvKyfJz.js} +2 -2
  10. package/web-dist/assets/{Checkbox-DExv3fUO.js.map → Checkbox-CEvKyfJz.js.map} +1 -1
  11. package/web-dist/assets/{Copy-BuBbxEQI.js → Copy-BHOLVthK.js} +2 -2
  12. package/web-dist/assets/{Copy-BuBbxEQI.js.map → Copy-BHOLVthK.js.map} +1 -1
  13. package/web-dist/assets/{InteractionCard-0PH6pIkH.js → InteractionCard-B-yhxwKs.js} +3 -3
  14. package/web-dist/assets/{InteractionCard-0PH6pIkH.js.map → InteractionCard-B-yhxwKs.js.map} +1 -1
  15. package/web-dist/assets/{Menu-BJ3Gyh5V.js → Menu-Cyt18mF2.js} +2 -2
  16. package/web-dist/assets/{Menu-BJ3Gyh5V.js.map → Menu-Cyt18mF2.js.map} +1 -1
  17. package/web-dist/assets/Overlay-BPNYBq3V.js +2 -0
  18. package/web-dist/assets/{Overlay-BgqVqKc6.js.map → Overlay-BPNYBq3V.js.map} +1 -1
  19. package/web-dist/assets/{Priority-B2tdgI2D.js → Priority-xSUsxoXm.js} +2 -2
  20. package/web-dist/assets/{Priority-B2tdgI2D.js.map → Priority-xSUsxoXm.js.map} +1 -1
  21. package/web-dist/assets/{SegmentedControl-DzwdZG6q.js → SegmentedControl-DaBwumC0.js} +2 -2
  22. package/web-dist/assets/{SegmentedControl-DzwdZG6q.js.map → SegmentedControl-DaBwumC0.js.map} +1 -1
  23. package/web-dist/assets/{Select-DZ-qJ_AO.js → Select-C5xlhWYb.js} +2 -2
  24. package/web-dist/assets/{Select-DZ-qJ_AO.js.map → Select-C5xlhWYb.js.map} +1 -1
  25. package/web-dist/assets/{Switch-DKiwAXXz.js → Switch-dVcf-7Je.js} +2 -2
  26. package/web-dist/assets/{Switch-DKiwAXXz.js.map → Switch-dVcf-7Je.js.map} +1 -1
  27. package/web-dist/assets/{Tabs-HOeWNnHD.js → Tabs-93APobOB.js} +2 -2
  28. package/web-dist/assets/{Tabs-HOeWNnHD.js.map → Tabs-93APobOB.js.map} +1 -1
  29. package/web-dist/assets/{TextArea-DK1uv3xX.js → TextArea-D8WB5GD8.js} +2 -2
  30. package/web-dist/assets/{TextArea-DK1uv3xX.js.map → TextArea-D8WB5GD8.js.map} +1 -1
  31. package/web-dist/assets/{TextLink-BoFPQuaH.js → TextLink-CrfA8AeH.js} +2 -2
  32. package/web-dist/assets/{TextLink-BoFPQuaH.js.map → TextLink-CrfA8AeH.js.map} +1 -1
  33. package/web-dist/assets/{attention-D1G0KCOr.js → attention-C8rfu6Uw.js} +2 -2
  34. package/web-dist/assets/{attention-D1G0KCOr.js.map → attention-C8rfu6Uw.js.map} +1 -1
  35. package/web-dist/assets/automations-DQxUzi5Q.js +2 -0
  36. package/web-dist/assets/{automations-DUUAfMK8.js.map → automations-DQxUzi5Q.js.map} +1 -1
  37. package/web-dist/assets/board-aS6ooJpx.js +10 -0
  38. package/web-dist/assets/{board-tIuyEKO0.js.map → board-aS6ooJpx.js.map} +1 -1
  39. package/web-dist/assets/code-Zr5DqwWI.js +25 -0
  40. package/web-dist/assets/code-Zr5DqwWI.js.map +1 -0
  41. package/web-dist/assets/{describe-BW5uUuvy.js → describe-w4KmQFfU.js} +2 -2
  42. package/web-dist/assets/{describe-BW5uUuvy.js.map → describe-w4KmQFfU.js.map} +1 -1
  43. package/web-dist/assets/enroll-DPKdD0en.js +2 -0
  44. package/web-dist/assets/{enroll-CL0BGGhd.js.map → enroll-DPKdD0en.js.map} +1 -1
  45. package/web-dist/assets/index-DFNY2EUd.css +2 -0
  46. package/web-dist/assets/index-DPScWz2I.js +11 -0
  47. package/web-dist/assets/index-DPScWz2I.js.map +1 -0
  48. package/web-dist/assets/{more-DNN_mtX8.js → more-CiyGP5GD.js} +2 -2
  49. package/web-dist/assets/{more-DNN_mtX8.js.map → more-CiyGP5GD.js.map} +1 -1
  50. package/web-dist/assets/{policyLogic-BKSj6mhC.js → policyLogic-7OOzM_xa.js} +2 -2
  51. package/web-dist/assets/{policyLogic-BKSj6mhC.js.map → policyLogic-7OOzM_xa.js.map} +1 -1
  52. package/web-dist/assets/{preload-helper-BudhqmWi.js → preload-helper-B2m1UyXR.js} +5 -5
  53. package/web-dist/assets/preload-helper-B2m1UyXR.js.map +1 -0
  54. package/web-dist/assets/queue-BcbJqzTY.js +2 -0
  55. package/web-dist/assets/{queue-k4o-I9uY.js.map → queue-BcbJqzTY.js.map} +1 -1
  56. package/web-dist/assets/{repo-CSQAnBaF.js → repo-BA_bnCvu.js} +2 -2
  57. package/web-dist/assets/{repo-CSQAnBaF.js.map → repo-BA_bnCvu.js.map} +1 -1
  58. package/web-dist/assets/settings-D03MF_Kx.js +7 -0
  59. package/web-dist/assets/{settings-CrYZRJ7E.js.map → settings-D03MF_Kx.js.map} +1 -1
  60. package/web-dist/assets/{shared-DIA598ns.js → shared-Bxc2JM1K.js} +2 -2
  61. package/web-dist/assets/{shared-DIA598ns.js.map → shared-Bxc2JM1K.js.map} +1 -1
  62. package/web-dist/assets/states-DynH8-o6.js +58 -0
  63. package/web-dist/assets/states-DynH8-o6.js.map +1 -0
  64. package/web-dist/assets/terminal-login-C0n8cXqn.js +2 -0
  65. package/web-dist/assets/{terminal-login-M5orrPPe.js.map → terminal-login-C0n8cXqn.js.map} +1 -1
  66. package/web-dist/assets/{useBreakpoint-CA0Mbmvv.js → useBreakpoint-CYDIV-KM.js} +2 -2
  67. package/web-dist/assets/{useBreakpoint-CA0Mbmvv.js.map → useBreakpoint-CYDIV-KM.js.map} +1 -1
  68. package/web-dist/assets/useNow-0tMsLHnB.js +2 -0
  69. package/web-dist/assets/{useNow-Dx0MCCez.js.map → useNow-0tMsLHnB.js.map} +1 -1
  70. package/web-dist/assets/{useResource-BTjwa4tV.js → useResource-DHtFcID5.js} +2 -2
  71. package/web-dist/assets/{useResource-BTjwa4tV.js.map → useResource-DHtFcID5.js.map} +1 -1
  72. package/web-dist/index.html +8 -8
  73. package/web-dist/sw.js +1 -1
  74. package/web-dist/assets/Overlay-BgqVqKc6.js +0 -2
  75. package/web-dist/assets/automations-DUUAfMK8.js +0 -2
  76. package/web-dist/assets/board-tIuyEKO0.js +0 -10
  77. package/web-dist/assets/code-O-DyPB50.js +0 -25
  78. package/web-dist/assets/code-O-DyPB50.js.map +0 -1
  79. package/web-dist/assets/enroll-CL0BGGhd.js +0 -2
  80. package/web-dist/assets/index-D-JHf__5.css +0 -2
  81. package/web-dist/assets/index-K0QOY1Li.js +0 -11
  82. package/web-dist/assets/index-K0QOY1Li.js.map +0 -1
  83. package/web-dist/assets/preload-helper-BudhqmWi.js.map +0 -1
  84. package/web-dist/assets/queue-k4o-I9uY.js +0 -2
  85. package/web-dist/assets/settings-CrYZRJ7E.js +0 -7
  86. package/web-dist/assets/states-C8oEFqek.js +0 -58
  87. package/web-dist/assets/states-C8oEFqek.js.map +0 -1
  88. package/web-dist/assets/terminal-login-M5orrPPe.js +0 -2
  89. package/web-dist/assets/useNow-Dx0MCCez.js +0 -2
@@ -1,2 +0,0 @@
1
- import{_ as e,a as t,f as n,m as r,t as i}from"./jsx-runtime-D13aM9HY.js";import{At as a,Mt as o,Nt as s,Ot as c,a as l,c as u,d,h as f,v as p}from"./states-C8oEFqek.js";import{t as m}from"./terminal-BOV_MXPZ.js";import{r as h}from"./TextArea-DK1uv3xX.js";import{t as g}from"./TextLink-BoFPQuaH.js";var _=e(r(),1),v=i();function y(){let[e]=t(),r=n(),i=e.get(`code`)?.trim()??``,[y,b]=(0,_.useState)(``),[x,S]=(0,_.useState)(null),[C,w]=(0,_.useState)(null),[T,E]=(0,_.useState)(null),[D,O]=(0,_.useState)(!1),[k,A]=(0,_.useState)(null);(0,_.useEffect)(()=>{if(!i)return;let e=new AbortController;return S(null),w(null),E(null),c(`/api/auth/terminal/requests/${encodeURIComponent(i)}`,void 0,e.signal).then(t=>!e.signal.aborted&&S(t)).catch(t=>{e.signal.aborted||(s(t)&&t.code===`not_found`?w(o(t)):E(t))}),()=>e.abort()},[i]);let j=async e=>{O(!0),A(null);try{S(await a(`/api/auth/terminal/requests/${encodeURIComponent(i)}/${e}`))}catch(e){A(e)}finally{O(!1)}},M;return M=i?C?(0,v.jsxs)(`div`,{role:`alert`,className:`rounded-md border border-border bg-danger-soft px-3 py-2 text-sm`,children:[(0,v.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium`,children:[(0,v.jsx)(p,{"aria-hidden":!0,className:`size-4 shrink-0`}),`Sign-in request not found`]}),(0,v.jsx)(`div`,{className:`text-muted`,children:C})]}):T?(0,v.jsx)(l,{error:T}):x?x.status===`approved`?(0,v.jsxs)(`div`,{role:`status`,className:`flex flex-col gap-3 text-sm`,children:[(0,v.jsx)(`p`,{className:`font-medium`,children:`Terminal signed in. You can close this tab and return to your terminal.`}),(0,v.jsx)(g,{to:`/`,children:`Back to Switchyard`})]}):x.status===`denied`?(0,v.jsx)(`p`,{role:`status`,className:`text-sm font-medium`,children:`Sign-in denied. The terminal was not signed in.`}):(0,v.jsxs)(`div`,{className:`flex flex-col gap-4 text-sm`,children:[(0,v.jsx)(`p`,{className:`text-base font-medium`,children:`Sign in a terminal?`}),(0,v.jsxs)(`dl`,{className:`grid grid-cols-[auto_1fr] gap-x-4 gap-y-2`,children:[(0,v.jsx)(`dt`,{className:`text-muted`,children:`Terminal`}),(0,v.jsx)(`dd`,{className:`break-words`,children:x.name}),(0,v.jsx)(`dt`,{className:`text-muted`,children:`Code`}),(0,v.jsx)(`dd`,{"data-testid":`terminal-login-code`,className:`font-mono text-lg tracking-widest`,children:x.userCode}),(0,v.jsx)(`dt`,{className:`text-muted`,children:`From`}),(0,v.jsx)(`dd`,{children:x.requestedFrom}),(0,v.jsx)(`dt`,{className:`text-muted`,children:`Requested`}),(0,v.jsx)(`dd`,{children:f(x.createdAt)})]}),(0,v.jsx)(`p`,{className:`text-muted`,children:`Approve only if you just ran switchyard login and your terminal shows this code.`}),(0,v.jsx)(l,{error:k}),(0,v.jsxs)(`div`,{className:`flex gap-2`,children:[(0,v.jsx)(d,{variant:`primary`,"data-testid":`terminal-login-approve`,busy:D,onClick:()=>void j(`approve`),children:`Approve`}),(0,v.jsx)(d,{"data-testid":`terminal-login-deny`,disabled:D,onClick:()=>void j(`deny`),children:`Deny`})]})]}):(0,v.jsx)(u,{label:`Loading the sign-in request…`}):(0,v.jsxs)(`form`,{className:`flex flex-col gap-3`,onSubmit:e=>{e.preventDefault(),y.trim()&&r(`?code=${encodeURIComponent(y.trim())}`)},children:[(0,v.jsx)(`label`,{htmlFor:`tl-code`,className:`text-sm font-medium`,children:`Code from your terminal`}),(0,v.jsx)(h,{id:`tl-code`,value:y,autoComplete:`off`,onChange:e=>b(e.target.value)}),(0,v.jsx)(d,{type:`submit`,variant:`primary`,disabled:!y.trim(),children:`Continue`})]}),(0,v.jsx)(`div`,{className:`flex min-h-dvh items-start justify-center px-4 safe-pt-10 safe-pb-10 sm:items-center`,children:(0,v.jsxs)(`div`,{className:`w-full max-w-sm rounded-xl border border-border bg-surface p-5 shadow-sm`,children:[(0,v.jsxs)(`div`,{className:`mb-4 flex items-center gap-3`,children:[(0,v.jsx)(`img`,{src:`/icon.svg`,alt:``,className:`size-10 rounded-lg`}),(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Switchyard`}),(0,v.jsxs)(`p`,{className:`flex items-center gap-1 text-sm text-muted`,children:[(0,v.jsx)(m,{"aria-hidden":!0,className:`size-3.5`}),` Terminal sign-in`]})]})]}),M]})})}export{y as default};
2
- //# sourceMappingURL=terminal-login-M5orrPPe.js.map
@@ -1,2 +0,0 @@
1
- import{_ as e,m as t,n,t as r}from"./jsx-runtime-D13aM9HY.js";import{T as i,_ as a,h as o,i as s,n as c,w as l}from"./Overlay-BgqVqKc6.js";import{At as u,B as d,Dt as f,F as p,Mt as m,Nt as h,Ot as g,Y as _,_ as v,d as y,dt as b,i as ee,j as te,kt as ne,n as x,o as S,u as C}from"./states-C8oEFqek.js";import{c as w,s as T}from"./useBreakpoint-CA0Mbmvv.js";import{n as re,t as E}from"./Checkbox-DExv3fUO.js";import{r as ie}from"./TextArea-DK1uv3xX.js";import{c as ae}from"./index-K0QOY1Li.js";import{t as oe}from"./TextLink-BoFPQuaH.js";import{r as se}from"./useResource-BTjwa4tV.js";import{t as D}from"./Select-DZ-qJ_AO.js";var O={name:`funnel`,size:24,node:[[`path`,{d:`M10 20a1 1 0 0 0 .553.895l2 1A1 1 0 0 0 14 21v-7a2 2 0 0 1 .517-1.341L21.74 4.67A1 1 0 0 0 21 3H3a1 1 0 0 0-.742 1.67l7.225 7.989A2 2 0 0 1 10 14z`,key:`sc7q7i`}]],aliases:[`filter`]};O.node;var ce=n(O),k=e(t(),1),A=e=>`/api/tasks/${encodeURIComponent(e)}`;function j(e){if(!e||typeof e!=`object`)return null;let t=e;return t.task&&typeof t.task==`object`?t.task:typeof t.id==`string`&&typeof t.state==`string`?t:null}function M(e){let t=j(e);return t?(d.setState(e=>{let n=e.tasks[t.id];return n&&n.updatedAt>t.updatedAt?{}:{tasks:{...e.tasks,[t.id]:t}}}),t):null}async function N(e){let t=M(await u(`/api/tasks`,e));if(!t)throw Error(`The coordinator returned an unexpected response`);return t}async function P(e,t){return M(await ne(A(e),t))}async function F(e){await f(A(e)),d.setState(t=>{if(!t.tasks[e])return{};let{[e]:n,...r}=t.tasks;return{tasks:r}})}async function I(e,t){return M(await u(`${A(e)}/move`,t))}async function L(e,t,n,r){return M(await u(`${A(e)}/${t}${r??``}`,n))}async function R(e,t){return M(await u(`${A(e)}/request-changes`,{feedback:t}))}function z(e,t){return g(`${A(e)}/eligibility`,void 0,t)}async function B(e,t){let n=await g(`${A(e)}/runs`,void 0,t);return Array.isArray(n)?n:n.runs??[]}async function V(e){await u(`/api/dispatch/pause`,{paused:e}),d.setState({dispatchPaused:e})}function H(e){return!h(e)||e.status!==409&&e.code!==`invalid_transition`?!1:e.details?.needsConfirm===!0||/confirm/i.test(e.message)}function U(e){if(!h(e))return!1;let t=e.details;return Array.isArray(t?.choices)||t?.needsChoice===!0||t?.onRunning===!0||/pause automation or stop execution/i.test(e.message)}var W=[`backlog`,`ready`,`in_progress`,`review`,`done`],G={backlog:`Backlog`,ready:`Ready`,in_progress:`In progress`,review:`Review`,done:`Done`,canceled:`Canceled`},K={search:``,priorities:[],hostId:null,attentionOnly:!1,blockedOnly:!1,showCanceled:!1,showCompleted:!0,sort:`priority`};function le(e){let t=e&&typeof e==`object`?e:{};return{search:typeof t.search==`string`?t.search:``,priorities:Array.isArray(t.priorities)?t.priorities.filter(e=>[0,1,2,3].includes(e)):[],hostId:typeof t.hostId==`string`?t.hostId:null,attentionOnly:t.attentionOnly===!0,blockedOnly:t.blockedOnly===!0,showCanceled:t.showCanceled===!0,showCompleted:t.showCompleted!==!1,sort:t.sort===`updated`||t.sort===`created`?t.sort:`priority`}}function q(e,t){let n=[];e.search.trim()&&n.push({key:`search`,label:`Search: ${e.search.trim()}`,clear:e=>({...e,search:``})});for(let t of e.priorities)n.push({key:`priority-${t}`,label:`Priority: ${b[t]}`,clear:e=>({...e,priorities:e.priorities.filter(e=>e!==t)})});return e.hostId&&n.push({key:`host`,label:`Host: ${t(e.hostId)}`,clear:e=>({...e,hostId:null})}),e.attentionOnly&&n.push({key:`attention`,label:`Needs attention`,clear:e=>({...e,attentionOnly:!1})}),e.blockedOnly&&n.push({key:`blocked`,label:`Blocked`,clear:e=>({...e,blockedOnly:!1})}),e.showCanceled&&n.push({key:`canceled`,label:`Including canceled`,clear:e=>({...e,showCanceled:!1})}),n}function ue(e,t){return(e.currentRunId?t[e.currentRunId]:void 0)?.hostId??e.policy.hostId??null}function de(e,t,n){if(e.hiddenFromBoard||n.projectId&&e.projectId!==n.projectId||e.state===`canceled`&&!t.showCanceled)return!1;let r=t.search.trim().toLowerCase();return!(r&&!`${e.title}\n${e.objective}`.toLowerCase().includes(r)||t.priorities.length>0&&!t.priorities.includes(e.priority)||t.hostId&&ue(e,n.runs)!==t.hostId||t.attentionOnly&&!n.attentionTaskIds.has(e.id)||t.blockedOnly&&!e.blocked)}function fe(e,t){let n=[...e];return t===`updated`?n.sort((e,t)=>t.lastActivityAt.localeCompare(e.lastActivityAt)):t===`created`?n.sort((e,t)=>t.createdAt.localeCompare(e.createdAt)):n.sort((e,t)=>e.priority-t.priority||e.position-t.position||e.createdAt.localeCompare(t.createdAt)),n}function pe(e,t,n){let r={backlog:[],ready:[],in_progress:[],review:[],done:[],canceled:[]};for(let i of Object.values(e))de(i,t,n)&&r[i.state].push(i);for(let e of Object.keys(r))r[e]=fe(r[e],t.sort);return r}function me(e,t){let n={done:0,total:0,canceled:0},r=t[e];for(let i of Object.values(t))i.parentTaskId===e&&i.id!==e&&(r&&i.projectId!==r.projectId||(n.total++,i.state===`done`&&n.done++,i.state===`canceled`&&n.canceled++));return n}function J(e,t){let n=[],r=new Set([e.id]),i=e.parentTaskId;for(;i&&!r.has(i);){r.add(i);let a=t[i];if(!a||a.projectId!==e.projectId)break;n.push(a),i=a.parentTaskId}return n.reverse()}function he(e,t){let n=new Map;for(let r of e)n.set(r.id,{task:r,children:[],depth:0,ancestors:J(r,t)});let r=new Map;for(let t of e){let e=t.parentTaskId?n.get(t.parentTaskId)?.task:void 0;e&&e.projectId===t.projectId&&e.state===t.state&&r.set(t.id,e.id)}let i=new Set;for(let t of e){let e=new Set,n=t.id;for(;n&&!i.has(n);){if(e.has(n)){r.delete(n);break}e.add(n),n=r.get(n)}for(let t of e)i.add(t)}let a=[];for(let e of n.values()){let t=r.get(e.task.id);t?n.get(t).children.push(e):a.push(e)}let o=[...a];for(;o.length;){let e=o.pop();for(let t of e.children)t.depth=e.depth+1,o.push(t)}return a}function ge(e){let t=[],n=[...e].reverse();for(;n.length;){let e=n.pop();t.push(e);for(let t=e.children.length-1;t>=0;t--)n.push(e.children[t])}return t}function _e(e,t,n){return Object.values(t).filter(r=>r.projectId===e&&r.id!==n&&(!n||!J(r,t).some(e=>e.id===n))).sort((e,t)=>e.title.localeCompare(t.title))}function ve(e){return e.showCanceled?[...W,`canceled`]:W}var Y={backlog:[`ready`,`canceled`],ready:[`backlog`,`in_progress`,`canceled`],in_progress:[`review`,`ready`,`backlog`,`canceled`,`done`],review:[`in_progress`,`done`,`ready`,`canceled`],done:[`ready`,`backlog`],canceled:[`backlog`]};function ye(e){return!!e&&[`queued`,`dispatching`,`uncertain`,`running`,`waiting_input`,`checking`].includes(e.state)}function be(e,t){let n=[];e.state!==`review`&&n.push(`The task has not been through review.`),e.acceptanceCriteria.length>0&&n.push(`${e.acceptanceCriteria.length} acceptance ${e.acceptanceCriteria.length===1?`criterion has`:`criteria have`} not been confirmed.`);let r=(e.policy.completion.checks?.length??0)>0,i=t?.checks.filter(e=>e.exitCode!==0)??[];return i.length>0?n.push(`Checks failing: ${i.map(e=>e.command).join(`, `)}.`):r&&(!t||t.checks.length===0)&&n.push(`Required checks have not run.`),e.policy.completion.requireHumanReview&&e.state===`review`&&n.push(`Human review is required: moving to Done accepts the work.`),n}var xe=[`backlog`,`ready`,`in_progress`,`review`,`done`,`canceled`];function Se(e){switch(e.kind){case`invalid`:return e.reason;case`choose_running`:return`Asks whether to pause automation or stop execution.`;case`confirm_done`:return`Asks you to confirm acceptance.`;case`run_now`:return`Starts now if the task is eligible.`;default:return null}}function Ce(e,t,n){if(e.state===t)return{kind:`noop`};let r=e.state;if(!Y[r].includes(t))return{kind:`invalid`,reason:we(r,t)};if(r===`ready`&&t===`in_progress`)return{kind:`run_now`};if(r===`review`&&t===`in_progress`)return{kind:`new_attempt`};if(r===`in_progress`&&(t===`ready`||t===`backlog`))return{kind:`choose_running`};if(t===`done`){let t=be(e,n);if(t.length>0)return{kind:`confirm_done`,reasons:t}}return{kind:`move`}}function we(e,t){let n=G[e],r=G[t];return t===`in_progress`?e===`backlog`?`A Backlog task cannot start directly. Move it to Ready first; the dispatcher starts it when it is eligible.`:`${n} tasks cannot be moved to In progress. Only the dispatcher starts work (Run now from Ready).`:t===`review`?`Only a finished run moves a task to Review. Run the task, or use Done to accept it.`:e===`canceled`?`A canceled task can only be restored to Backlog.`:e===`done`&&t===`canceled`?`A Done task cannot be canceled. Reopen it first.`:e===`backlog`&&t===`done`?`A Backlog task cannot be marked Done. Make it ready and review its work first.`:e===`ready`&&t===`done`?`A task that has not run cannot be marked Done. Run it, or cancel it.`:`Moving from ${n} to ${r} is not allowed.`}function Te(e){return Y[e.state]}function Ee(e,t,n){let r=e.filter(e=>e.id!==n);if(r.length===0)return 1;if(t===null)return r[r.length-1].position+1;let i=r.findIndex(e=>e.id===t);if(i<0)return r[r.length-1].position+1;let a=r[i].position;return((i>0?r[i-1].position:a-2)+a)/2}var X={dependency:`Waiting on dependencies`,host_offline:`Host offline`,project_limit:`Project run limit reached`,workspace_occupied:`Workspace occupied`,scheduled_time:`Scheduled for later`,invalid_configuration:`Invalid configuration`,dispatch_paused:`Dispatch paused`,project_automation_disabled:`Auto-start is off for this project`,not_ready:`Not ready`,already_dispatched:`Already dispatched`,retry_backoff:`Retrying after a failure`};function De(e){return e.eligible?`Will start automatically on ${e.hostName}`:`Will wait: ${e.message||X[e.wait]}`}function Oe(e,t){let{project:n}=e;if(!n)return{eligible:!1,wait:`invalid_configuration`,message:`Choose a project`};if(t.dispatchPaused)return{eligible:!1,wait:`dispatch_paused`,message:`Dispatch is paused; resume it to start new work`};if(!n.automationEnabled)return{eligible:!1,wait:`project_automation_disabled`,message:`Auto-start is off for ${n.name}`};let r=e.dependencies.map(e=>t.tasks[e]).filter(e=>!!e&&e.state!==`done`);if(r.length>0)return{eligible:!1,wait:`dependency`,message:`Waiting on ${r.map(e=>e.title).join(`, `)}`};if(e.notBefore&&Date.parse(e.notBefore)>Date.now())return{eligible:!1,wait:`scheduled_time`,message:`Scheduled for ${new Date(e.notBefore).toLocaleString()}`};let i=e.hostId??n.defaultHostId,a=i?t.hosts[i]:void 0;return!a||a.revokedAt?{eligible:!1,wait:`invalid_configuration`,message:`No host is configured for this project`}:a.piCompatible?a.connectivity===`connected`?(t.runningByProject[n.id]??0)>=n.maxConcurrentRuns?{eligible:!1,wait:`project_limit`,message:`${n.name} already runs ${n.maxConcurrentRuns} of ${n.maxConcurrentRuns} allowed tasks`}:{eligible:!0,hostId:a.id,hostName:a.name}:{eligible:!1,wait:`host_offline`,message:`${a.name} is offline`}:{eligible:!1,wait:`invalid_configuration`,message:`Pi on ${a.name} is not compatible`}}function ke(e){let t=new Map;for(let n of Object.values(e)){if(n.resolvedAt||!n.taskId)continue;let e=t.get(n.taskId)??[];e.push(n),t.set(n.taskId,e)}return t}function Ae(e,t){let n=e.dependencies.length;if(n===0)return null;let r=e.dependencies.filter(e=>t[e]?.state!==`done`).length,i=`${n} ${n===1?`dependency`:`dependencies`}`;return r>0?`${i} (${r} open)`:`${i} (all done)`}var Z=r();function je({board:e,className:t,labelVisible:n}){let r=p(),i=(0,k.useId)();return(0,Z.jsxs)(`div`,{className:v(n?`flex min-w-0 flex-col gap-1`:`flex min-w-0 items-center gap-2`,t),children:[(0,Z.jsx)(`label`,{htmlFor:i,className:n?`text-sm font-medium`:`sr-only`,children:`Project`}),(0,Z.jsxs)(D,{id:i,className:n?`w-full`:`max-w-56`,value:e.projectId??``,onChange:t=>e.setProjectId(t.target.value||null),children:[(0,Z.jsx)(`option`,{value:``,children:`All projects`}),r.map(e=>(0,Z.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]})}function Q({board:e,className:t,autoFocus:n}){let r=(0,k.useId)();return(0,Z.jsxs)(`div`,{className:v(`relative min-w-0`,t),children:[(0,Z.jsx)(`label`,{htmlFor:r,className:`sr-only`,children:`Search tasks`}),(0,Z.jsx)(re,{"aria-hidden":!0,className:`pointer-events-none absolute top-1/2 left-2.5 size-4 -translate-y-1/2 text-subtle`}),(0,Z.jsx)(ie,{id:r,type:`search`,placeholder:`Search tasks`,autoFocus:n,className:`pl-8`,value:e.filters.search,onChange:t=>e.setFilters({...e.filters,search:t.target.value})})]})}function Me({board:e}){let t=(0,k.useId)();return(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-sm`,children:[(0,Z.jsx)(`label`,{htmlFor:t,className:`text-muted`,children:`Sort`}),(0,Z.jsxs)(D,{id:t,width:`auto`,value:e.filters.sort,onChange:t=>e.setFilters({...e.filters,sort:t.target.value}),children:[(0,Z.jsx)(`option`,{value:`priority`,children:`Priority`}),(0,Z.jsx)(`option`,{value:`updated`,children:`Recently updated`}),(0,Z.jsx)(`option`,{value:`created`,children:`Newest`})]})]})}function Ne({board:e}){return(0,Z.jsx)(E,{label:`Show completed`,checked:e.filters.showCompleted,onChange:t=>e.setFilters({...e.filters,showCompleted:t})})}function Pe(){let e=d(e=>e.dispatchPaused),[t,n]=(0,k.useState)(!1);return{paused:e,busy:t,toggle:async()=>{n(!0);try{await V(!e),T.success(e?`Dispatch resumed. Ready tasks start when eligible.`:`Dispatch paused. Running work continues; nothing new starts.`)}catch(t){T.error(`Could not ${e?`resume`:`pause`} dispatch: ${m(t)}`)}finally{n(!1)}}}}function $(){let{paused:e,busy:t,toggle:n}=Pe(),r=e?i:l;return(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2 text-sm`,children:[(0,Z.jsxs)(`span`,{role:`status`,className:v(`inline-flex items-center gap-1.5 font-medium`,e?`text-warning`:`text-success`),children:[(0,Z.jsx)(r,{"aria-hidden":!0,className:`size-4`}),(0,Z.jsx)(`span`,{className:`text-text`,children:e?`Dispatch paused`:`Dispatch on`})]}),(0,Z.jsx)(y,{size:`sm`,busy:t,onClick:()=>void n(),children:e?`Resume dispatch`:`Pause dispatch`})]})}function Fe({queueCount:e}){let t=d(e=>e.dispatchPaused),[n,r]=(0,k.useState)(!1),o=t?i:l;return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`button`,{type:`button`,"aria-haspopup":`dialog`,onClick:()=>r(!0),className:v(`tap inline-flex items-center gap-1 rounded-full border px-2.5 text-xs leading-6 font-medium`,t?a.warning:a.neutral),children:[(0,Z.jsx)(o,{"aria-hidden":!0,className:v(`size-3.5`,t?`text-warning`:`text-success`)}),(0,Z.jsx)(`span`,{className:`text-text`,children:t?`Dispatch paused`:`Dispatch on`}),(0,Z.jsxs)(`span`,{children:[`· `,e,` queued`]})]}),(0,Z.jsx)(s,{open:n,onClose:()=>r(!1),title:`Dispatch`,description:`Pausing stops new work from starting. Runs already in progress keep going.`,children:(0,Z.jsx)($,{})})]})}function Ie({value:e,onChange:t,withSort:n}){let r=te(),i=(0,k.useId)(),a=(n,r)=>t({...e,priorities:r?[...e.priorities,n]:e.priorities.filter(e=>e!==n)});return(0,Z.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Z.jsxs)(`fieldset`,{className:`flex flex-col gap-1`,children:[(0,Z.jsx)(`legend`,{className:`mb-1 text-sm font-medium`,children:`Priority`}),(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-x-4`,children:b.map((t,n)=>(0,Z.jsx)(E,{label:t,checked:e.priorities.includes(n),onChange:e=>a(n,e)},t))})]}),(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,Z.jsx)(`label`,{htmlFor:`${i}-host`,className:`text-sm font-medium`,children:`Host`}),(0,Z.jsxs)(D,{id:`${i}-host`,value:e.hostId??``,onChange:n=>t({...e,hostId:n.target.value||null}),children:[(0,Z.jsx)(`option`,{value:``,children:`Any host`}),r.map(e=>(0,Z.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,Z.jsxs)(`fieldset`,{className:`flex flex-col gap-1`,children:[(0,Z.jsx)(`legend`,{className:`mb-1 text-sm font-medium`,children:`Show`}),(0,Z.jsx)(E,{label:`Only tasks that need attention`,checked:e.attentionOnly,onChange:n=>t({...e,attentionOnly:n})}),(0,Z.jsx)(E,{label:`Only blocked tasks`,checked:e.blockedOnly,onChange:n=>t({...e,blockedOnly:n})}),(0,Z.jsx)(E,{label:`Canceled tasks`,checked:e.showCanceled,onChange:n=>t({...e,showCanceled:n})}),(0,Z.jsx)(E,{label:`Completed tasks`,checked:e.showCompleted,onChange:n=>t({...e,showCompleted:n})})]}),n&&(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,Z.jsx)(`label`,{htmlFor:`${i}-sort`,className:`text-sm font-medium`,children:`Sort`}),(0,Z.jsxs)(D,{id:`${i}-sort`,value:e.sort,onChange:n=>t({...e,sort:n.target.value}),children:[(0,Z.jsx)(`option`,{value:`priority`,children:`Priority`}),(0,Z.jsx)(`option`,{value:`updated`,children:`Recently updated`}),(0,Z.jsx)(`option`,{value:`created`,children:`Newest`})]})]})]})}function Le({board:e,mobile:t,extra:n,extraCount:r=0}){let[i,a]=(0,k.useState)(!1),[l,u]=(0,k.useState)(e.filters),f=d(e=>e.hosts),p=q(e.filters,e=>f[e]?.name??`host`).filter(e=>e.key!==`search`).length+r,m=t?s:c;return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(y,{size:t?`sm`:`md`,icon:(0,Z.jsx)(ce,{className:`size-4`}),onClick:()=>{u(e.filters),a(!0)},"aria-label":p?`Filters, ${p} active`:`Filters`,children:[`Filters`,p>0&&(0,Z.jsx)(o,{tone:`accent`,children:p})]}),(0,Z.jsx)(m,{open:i,onClose:()=>a(!1),title:`Filter tasks`,footer:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(y,{variant:`ghost`,onClick:()=>u({...K,search:l.search}),children:`Reset`}),(0,Z.jsx)(y,{variant:`primary`,onClick:()=>{e.setFilters(l),a(!1)},children:`Show results`})]}),children:(0,Z.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[n&&(0,Z.jsx)(`div`,{className:`flex flex-col gap-4 border-b border-border pb-4`,children:n}),(0,Z.jsx)(Ie,{value:l,onChange:u,withSort:t})]})})]})}function Re({board:e,includeSearch:t}){let n=d(e=>e.hosts),r=q(e.filters,e=>n[e]?.name??`Unknown host`).filter(e=>t||e.key!==`search`);return r.length===0?null:(0,Z.jsxs)(`ul`,{"data-testid":`filter-chips`,"aria-label":`Active filters`,className:`flex min-w-0 flex-wrap gap-1.5`,children:[r.map(t=>(0,Z.jsx)(`li`,{className:`min-w-0`,children:(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>e.setFilters(t.clear(e.filters)),"aria-label":`Remove filter ${t.label}`,className:`tap inline-flex max-w-full items-center gap-1 rounded-full border border-border bg-surface-2 px-2.5 py-0.5 text-xs font-medium`,children:[(0,Z.jsx)(`span`,{className:`truncate`,children:t.label}),(0,Z.jsx)(w,{"aria-hidden":!0,className:`size-3.5 shrink-0`})]})},t.key)),r.length>1&&(0,Z.jsx)(`li`,{children:(0,Z.jsx)(oe,{size:`xs`,onClick:()=>e.setFilters({...K,sort:e.filters.sort}),children:`Clear all`})})]})}function ze({board:e}){let t=d(e=>e.tasks),n=d(e=>e.runs),r=d(e=>e.hosts),i=d(e=>e.interactions),{offline:a,pending:o}=(0,k.useMemo)(()=>{let a=new Set,o=new Set;for(let i of Object.values(t)){if(e.projectId&&i.projectId!==e.projectId)continue;i.sessionId&&o.add(i.sessionId);let t=i.currentRunId?n[i.currentRunId]:void 0;if(i.state===`in_progress`&&t?.hostId){let e=r[t.hostId];e&&e.connectivity!==`connected`&&a.add(e.id)}}let s=_(i,o);return{offline:[...a].map(e=>r[e]),pending:s}},[t,n,r,i,e.projectId]),s=e.now.error,c=[];for(let e of a)c.push((0,Z.jsx)(ee,{compact:!0,hostName:e.name,connectivity:e.connectivity===`reconnecting`?`reconnecting`:`unreachable`,lastSeenAt:e.lastSeenAt,detail:`Its In progress tasks keep their last known state; nothing is restarted elsewhere.`},`host-${e.id}`));return o.length>0&&c.push((0,Z.jsx)(S,{count:o.length,to:ae.interaction(o[0].sessionId,o[0].id),label:o.length===1?`A task needs input`:`${o.length} questions need input`},`pending`)),s!=null&&(h(s)&&s.status===404?c.push((0,Z.jsx)(C,{capability:`Queue details`,reason:`This coordinator does not report why Ready tasks are waiting.`},`now`)):c.push((0,Z.jsx)(x,{compact:!0,title:`Could not load the dispatch queue`,error:m(s),onRetry:e.now.reload},`now`))),c.length===0?null:(0,Z.jsx)(`div`,{className:`flex flex-col gap-2 px-4 pt-2`,children:c})}function Be(e=!0){let t=se(e?`now`:null,e=>g(`/api/now`,void 0,e),{refreshMs:15e3}),n=d(e=>e.tasks),r=d(e=>e.runs),i=d(e=>e.dispatchPaused),a=(0,k.useRef)(!0),{reload:o}=t;return(0,k.useEffect)(()=>{if(a.current){a.current=!1;return}if(!e)return;let t=setTimeout(o,500);return()=>clearTimeout(t)},[n,r,i,e,o]),t}export{ve as A,P as B,Te as C,Ce as D,_e as E,I as F,H as I,U as L,F as M,z as N,Ee as O,B as P,R,Se as S,ke as T,me as _,$ as a,De as b,je as c,xe as d,K as f,pe as g,he as h,Fe as i,N as j,Oe as k,Q as l,X as m,ze as n,Le as o,G as p,Ne as r,Re as s,Be as t,Me as u,ge as v,le as w,ye as x,Ae as y,L as z};
2
- //# sourceMappingURL=useNow-Dx0MCCez.js.map