toolroll 0.9.1 → 0.9.3
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/CHANGELOG.md +37 -0
- package/dist/agent-fence.d.ts +11 -2
- package/dist/agent-fence.js +29 -3
- package/dist/browser/workspace.css +1 -1
- package/dist/browser/workspace.js +3 -3
- package/dist/builder.js +21 -2
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +3 -0
- package/dist/desktop-update.d.ts +1 -1
- package/dist/flow-engine.d.ts +7 -0
- package/dist/flow-engine.js +47 -15
- package/dist/flow-insights.d.ts +9 -0
- package/dist/flow-insights.js +16 -0
- package/dist/flow-replies.js +1 -1
- package/dist/flow-starters.d.ts +6 -1
- package/dist/flow-starters.js +46 -3
- package/dist/flow-triggers.d.ts +20 -1
- package/dist/flow-triggers.js +105 -6
- package/dist/flows-cli.d.ts +228 -0
- package/dist/flows-cli.js +403 -0
- package/dist/flows-ui.js +1 -1
- package/dist/flows.d.ts +25 -4
- package/dist/flows.js +75 -2
- package/dist/guides.js +23 -0
- package/dist/keys.js +4 -1
- package/dist/mate-contract.js +1 -1
- package/dist/mate-tools.js +4 -3
- package/dist/operate.d.ts +1 -1
- package/dist/operate.js +39 -4
- package/dist/plane-review.d.ts +39 -0
- package/dist/plane-review.js +233 -0
- package/dist/store.d.ts +2 -0
- package/dist/store.js +5 -0
- package/dist/surface.js +4 -0
- package/package.json +1 -1
|
@@ -59,11 +59,11 @@ ${t}`}function Kb({firstRun:e,onDraft:t}){let a=t===void 0?[]:e.suggestions;retu
|
|
|
59
59
|
`)}),placeholder:"One level per line, lowest first","aria-label":`Note ${i+1}: levels, lowest first`})]},i)),e.notes.length<3&&(0,m.jsxs)(oe,{size:"sm",variant:"outline",className:"self-start",onClick:()=>o({...e,notes:[...e.notes,{id:"",kind:"yes-no",question:"",levels:null}]}),children:[(0,m.jsx)(ta,{className:"size-4"}),"Add a note"]})]})]})]})}var aC="Fill-ins: {{card.title}}, {{card.description}}, {{card.email}}, {{stage.<zone id>}}.";function JX({request:e,view:t,csrf:a,apply:o,set:n}){let r=Object.entries(e.headers),s=(i,l,c)=>n({...e,headers:Object.fromEntries(r.map((f,u)=>u===i?[l,c]:f).filter(([f])=>f!==""))});return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(he,{label:"Address",hint:`The host is written out; fill-ins can go after it. ${aC}`,children:(0,m.jsxs)("div",{className:"flex gap-1.5",children:[(0,m.jsx)("select",{className:ue(gt,"w-24 shrink-0"),value:e.method,onChange:i=>n({...e,method:i.target.value}),"aria-label":"Method",children:["GET","POST","PUT","PATCH","DELETE"].map(i=>(0,m.jsx)("option",{value:i,children:i},i))}),(0,m.jsx)(Se,{value:e.url,maxLength:2e3,onChange:i=>n({...e,url:i.target.value}),className:"font-mono text-[12.5px]",placeholder:"https://api.example.com/items","aria-label":"Address"})]})}),(0,m.jsxs)("div",{className:"grid gap-1.5",children:[(0,m.jsx)("span",{className:"text-[13px] font-medium",children:"Headers"}),r.map(([i,l],c)=>(0,m.jsxs)("div",{className:"flex gap-1.5","data-request-header":c,children:[(0,m.jsx)(Se,{value:i,maxLength:64,onChange:f=>s(c,f.target.value,l),className:"w-32 shrink-0 font-mono text-[12px]",placeholder:"Authorization","aria-label":`Header ${c+1} name`}),(0,m.jsx)(Se,{value:l,maxLength:500,onChange:f=>s(c,i,f.target.value),className:"font-mono text-[12px]",placeholder:"Bearer {{secret.API_TOKEN}}","aria-label":`Header ${c+1} value`}),(0,m.jsx)(oe,{variant:"ghost",size:"icon",onClick:()=>n({...e,headers:Object.fromEntries(r.filter((f,u)=>u!==c))}),"aria-label":`Remove header ${i||c+1}`,children:(0,m.jsx)(jt,{className:"size-4"})})]},c)),r.length<10&&(0,m.jsxs)(oe,{size:"sm",variant:"outline",className:"self-start",onClick:()=>n({...e,headers:{...e.headers,[`X-Header-${r.length+1}`]:""}}),children:[(0,m.jsx)(ta,{className:"size-4"}),"Add a header"]})]}),e.method!=="GET"&&e.method!=="DELETE"&&(0,m.jsx)(he,{label:"What it sends",hint:"JSON is sent as JSON, with fill-ins inside its strings; anything else as plain text.",children:(0,m.jsx)(na,{rows:5,value:e.body??"",maxLength:8e3,onChange:i=>n({...e,body:i.target.value}),className:"font-mono text-[12px]","aria-label":"What it sends"})}),(0,m.jsx)(ZO,{view:t,csrf:a,apply:o,words:(0,m.jsxs)(m.Fragment,{children:["Kept on this computer, never shown again. Use one in a header as ","{{secret.NAME}}","."]})})]})}function ZO({view:e,csrf:t,apply:a,words:o,chosen:n,choose:r}){let[s,i]=(0,fe.useState)({name:"",value:""}),[l,c]=(0,fe.useState)(!1),f=n??[];return(0,m.jsxs)("details",{className:"rounded-md border px-3 py-2","data-request-secrets":!0,open:f.length>0?!0:void 0,children:[(0,m.jsxs)("summary",{className:"cursor-pointer text-[13px] font-medium",children:["Secrets",r!==void 0?f.length>0?` (${f.length} used)`:"":e.requestSecrets.length>0?` (${e.requestSecrets.length})`:""]}),(0,m.jsxs)("div",{className:"mt-2 grid gap-2",children:[(0,m.jsx)("p",{className:"text-[12px] text-muted-foreground",children:o}),e.requestSecrets.length>0&&(r===void 0?(0,m.jsx)("p",{className:"flex flex-wrap gap-1.5",children:e.requestSecrets.map(u=>(0,m.jsx)(Bt,{tone:"neutral",className:"font-mono",children:u},u))}):(0,m.jsx)("div",{className:"flex flex-wrap gap-x-3 gap-y-1.5",children:e.requestSecrets.map(u=>(0,m.jsxs)("label",{className:"inline-flex items-center gap-1.5 font-mono text-[12px]",children:[(0,m.jsx)("input",{type:"checkbox",className:"size-4 accent-[var(--so-accent)]",checked:f.includes(u),onChange:d=>r(d.target.checked?[...f,u]:f.filter(p=>p!==u))}),u]},u))})),f.filter(u=>!e.requestSecrets.includes(u)).map(u=>(0,m.jsxs)("p",{className:"text-[12px] text-warning",children:[u," isn't saved yet: save it below."]},u)),(0,m.jsxs)("div",{className:"flex gap-1.5",children:[(0,m.jsx)(Se,{value:s.name,onChange:u=>i({...s,name:u.target.value.toUpperCase().replace(/[^A-Z0-9_]/g,"_")}),className:"w-32 shrink-0 font-mono text-[12px]",placeholder:"API_TOKEN","aria-label":"Secret name"}),(0,m.jsx)(Se,{type:"password",autoComplete:"off",value:s.value,onChange:u=>i({...s,value:u.target.value}),placeholder:"Its value (empty removes it)","aria-label":"Secret value"})]}),(0,m.jsx)(oe,{size:"sm",variant:"outline",className:"self-start",disabled:l||s.name==="",onClick:async()=>{c(!0);let u=await Xa(`${e.flow.href}/secrets`,s,t);c(!1),a(u),u.ok&&(r!==void 0&&s.value.trim()!==""&&!f.includes(s.name)&&r([...f,s.name]),i({name:"",value:""}))},children:"Save secret"})]})]})}function KO({routes:e,others:t,set:a,hint:o}){return(0,m.jsxs)("div",{className:"grid gap-1.5","data-code-routes":!0,children:[(0,m.jsx)("span",{className:"text-[13px] font-medium",children:"Answers (optional)"}),(0,m.jsx)("p",{className:"text-[12px] text-muted-foreground",children:o}),e.map((n,r)=>(0,m.jsxs)("div",{className:"flex gap-1.5",children:[(0,m.jsx)(Se,{value:n.answer,maxLength:40,onChange:s=>a(e.map((i,l)=>l===r?{...i,answer:s.target.value}:i)),className:"w-32 shrink-0",placeholder:"Urgent","aria-label":`Answer ${r+1}`}),(0,m.jsx)("select",{className:gt,value:n.to,onChange:s=>a(e.map((i,l)=>l===r?{...i,to:s.target.value}:i)),"aria-label":`Where ${n.answer||`answer ${r+1}`} leads`,children:t.map(s=>(0,m.jsx)("option",{value:s.id,children:s.title},s.id))}),(0,m.jsx)(oe,{variant:"ghost",size:"icon",onClick:()=>a(e.filter((s,i)=>i!==r)),"aria-label":`Remove ${n.answer||`answer ${r+1}`}`,children:(0,m.jsx)(jt,{className:"size-4"})})]},r)),e.length<12&&t.length>0&&(0,m.jsxs)(oe,{size:"sm",variant:"outline",className:"self-start",onClick:()=>a([...e,{answer:"",to:t[0].id}]),children:[(0,m.jsx)(ta,{className:"size-4"}),"Add an answer"]})]})}function eY({question:e,csrf:t,apply:a}){let[o,n]=(0,fe.useState)(""),[r,s]=(0,fe.useState)(!1),i=async c=>{s(!0);let f=await Xa(`/teammates/questions/${e.id}/answer`,c,t);s(!1),a(f),f.ok&&n("")},l=e.call??null;return(0,m.jsxs)("div",{className:"flex flex-col gap-2 rounded-lg border border-attention/50 p-3","data-teammate-question":e.id,children:[(0,m.jsx)("p",{className:"text-[12px] text-muted-foreground",children:l===null?`${e.from} asks${e.mine?" you":` ${e.askedOf}`}`:`${e.from} needs ${e.mine?"your":`${e.askedOf}'s`} approval`}),(0,m.jsx)("p",{className:"break-words text-[13px] font-medium",children:e.question}),l!==null&&(0,m.jsxs)("p",{className:"text-[12.5px] text-muted-foreground","data-teammate-call-why":!0,children:[l.why!==""&&(0,m.jsxs)(m.Fragment,{children:[l.why," "]}),"(",l.rule,")"]}),e.mine&&(0,m.jsxs)(m.Fragment,{children:[e.options.length>0&&(0,m.jsx)("div",{className:"flex flex-wrap gap-2",children:e.options.map((c,f)=>(0,m.jsx)(oe,{size:"sm",variant:l!==null&&f===0?"default":"outline",disabled:r,onClick:()=>{i({choice:c.id})},children:c.label},c.id))}),(0,m.jsx)(na,{value:o,onChange:c=>n(c.target.value),rows:2,maxLength:2e3,placeholder:l===null?"Or answer in your words":`Or tell ${e.from.split(" · ")[0]} what to do instead`,"aria-label":"Your answer"}),(0,m.jsx)(oe,{size:"sm",className:"self-start",disabled:r||o.trim()==="",onClick:()=>{i({text:o})},children:"Answer"})]})]})}function tY({stage:e,others:t,view:a,update:o}){let n=a.teammates??[];return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(he,{label:"Teammate",hint:n.length===0?void 0:"It follows its soul file's rules, and asks the flow's owner when they say to.",children:n.length===0?(0,m.jsxs)("p",{className:"text-[13px] text-muted-foreground",children:["No teammates in this project yet. ",(0,m.jsx)("a",{className:"font-medium text-primary underline-offset-4 hover:underline",href:"/teammates",children:"Add one"}),"."]}):(0,m.jsx)("select",{className:gt,"aria-label":"Teammate",value:e.teammate??"",onChange:r=>o({teammate:r.target.value}),children:n.map(r=>(0,m.jsxs)("option",{value:r.handle,children:[r.label,r.working?"":" (paused)"]},r.handle))})}),(0,m.jsx)(he,{label:"What to do here",children:(0,m.jsx)(na,{rows:4,value:e.instructions??"",maxLength:4e3,onChange:r=>o({instructions:r.target.value}),"aria-label":"What to do here",placeholder:"Read the customer's reply and decide what happens next."})}),(0,m.jsx)(KO,{routes:e.routes??[],others:t,set:r=>o({routes:r}),hint:"It picks one, and writes what the next zones send. With none, it moves the card on to “Then”."}),(0,m.jsxs)("label",{className:"flex items-start gap-2 text-[13px]",children:[(0,m.jsx)("input",{type:"checkbox",className:"mt-0.5 size-4",checked:e.reply===!0,onChange:r=>o({reply:r.target.checked?!0:void 0}),"data-teammate-reply":!0}),(0,m.jsxs)("span",{children:["Answer whoever asked",(0,m.jsx)("span",{className:"block text-[12px] text-muted-foreground",children:"What it writes goes back to the person who added the card, in their chat app."})]})]})]})}function aY({stage:e,others:t,view:a,csrf:o,apply:n,update:r}){let s=e.routes??[],i=a.scripts.find(c=>c.name===e.script),l=c=>r({routes:c});return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(he,{label:"Script",hint:a.scripts.length===0?"This project has no scripts yet: make one with Scripts in the toolbar, or ask your lead in chat.":i!==void 0?`${QO[i.language]}${i.file===null?"":`, runs ${i.file}`}. It gets the card as JSON on stdin; what it prints is this step's result.`:void 0,children:(0,m.jsxs)("select",{className:gt,"aria-label":"Script",value:e.script??"",onChange:c=>r({script:c.target.value||null}),children:[(0,m.jsx)("option",{value:"",children:"Choose a script"}),a.scripts.map(c=>(0,m.jsxs)("option",{value:c.name,children:[c.name," — ",c.about]},c.name)),e.script!==null&&!a.scripts.some(c=>c.name===e.script)&&(0,m.jsxs)("option",{value:e.script,children:[e.script," (missing)"]})]})}),(0,m.jsx)(he,{label:"Runs in",hint:(e.runIn??"copy")==="folder"?"Fast. The project's folder is at $FLOW_PROJECT.":"The project's setup runs first. Use this to test or check code.",children:(0,m.jsxs)("select",{className:gt,"aria-label":"Runs in",value:e.runIn??"copy",onChange:c=>r({runIn:c.target.value}),children:[(0,m.jsx)("option",{value:"folder",children:"An empty folder"}),(0,m.jsx)("option",{value:"copy",children:"A copy of the project, at the card's work"})]})}),(0,m.jsx)(KO,{routes:s,others:t,set:l,hint:(0,m.jsxs)(m.Fragment,{children:["If its last line is “goto: ",(0,m.jsx)("em",{children:"answer"}),"”, the card goes where that answer leads."]})}),(0,m.jsx)(ZO,{view:a,csrf:o,apply:n,chosen:e.secrets??[],choose:c=>r({secrets:c}),words:"Kept on this computer, never shown again. The script gets each one it's given as a variable of the same name."})]})}var QO={shell:"Shell",python:"Python",node:"Node"},oY={python:`import json, sys
|
|
60
60
|
card = json.load(sys.stdin)["card"]
|
|
61
61
|
print(f"Looked at {card['title']}")`,node:'import { readFileSync } from "node:fs";\nconst { card } = JSON.parse(readFileSync(0, "utf8"));\nconsole.log(`Looked at ${card.title}`);',shell:`npm ci
|
|
62
|
-
npm test`};function nY({email:e,view:t,set:a}){return(0,m.jsxs)(m.Fragment,{children:[!t.emailReady&&(0,m.jsxs)("p",{className:"rounded-md border border-border px-3 py-2 text-[12.5px]","data-email-needs-setup":!0,children:["Email isn't set up yet. ",(0,m.jsx)("a",{className:"font-medium text-primary underline-offset-4 hover:underline",href:"/settings#email",children:"Add your mail server in Settings"})]}),(0,m.jsx)(he,{label:"To",children:(0,m.jsx)(Se,{value:e.to,maxLength:500,onChange:o=>a({...e,to:o.target.value}),"aria-label":"To"})}),(0,m.jsx)(he,{label:"Subject",children:(0,m.jsx)(Se,{value:e.subject,maxLength:200,onChange:o=>a({...e,subject:o.target.value}),"aria-label":"Subject"})}),(0,m.jsx)(he,{label:"Email",hint:aC,children:(0,m.jsx)(na,{rows:6,value:e.body,maxLength:8e3,onChange:o=>a({...e,body:o.target.value}),"aria-label":"Email"})})]})}function rY({tool:e,view:t,set:a}){let o=t.tools.find(n=>n.name===e.server);return(0,m.jsxs)(m.Fragment,{children:[t.tools.length===0?(0,m.jsxs)("p",{className:"rounded-md border border-border px-3 py-2 text-[12.5px]","data-tool-needs-setup":!0,children:["This project has no tools yet. ",(0,m.jsx)("a",{className:"font-medium text-primary underline-offset-4 hover:underline",href:"/settings/tools",children:"Add one on the Tools page"})]}):(0,m.jsx)(he,{label:"Tool",...o!==void 0&&!o.ready?{hint:"It needs its secrets set on the Tools page first."}:o!==void 0?{hint:o.about}:{},children:(0,m.jsxs)("select",{className:gt,value:e.server,onChange:n=>a({...e,server:n.target.value,name:t.tools.find(r=>r.name===n.target.value)?.functions[0]??""}),"aria-label":"Tool",children:[o===void 0&&(0,m.jsx)("option",{value:e.server,children:e.server===""?"Choose a tool":`${e.server} (missing)`}),t.tools.map(n=>(0,m.jsx)("option",{value:n.name,children:n.name},n.name))]})}),(0,m.jsx)(he,{label:"What it does",hint:o!==void 0&&o.functions.length===0?"Test the tool on the Tools page to list what it can do.":void 0,children:o!==void 0&&o.functions.length>0?(0,m.jsxs)("select",{className:gt,value:e.name,onChange:n=>a({...e,name:n.target.value}),"aria-label":"What it does",children:[!o.functions.includes(e.name)&&(0,m.jsx)("option",{value:e.name,children:e.name||"Choose"}),o.functions.map(n=>(0,m.jsx)("option",{value:n,children:n},n))]}):(0,m.jsx)(Se,{value:e.name,maxLength:100,onChange:n=>a({...e,name:n.target.value}),className:"font-mono","aria-label":"What it does"})}),(0,m.jsx)(he,{label:"Arguments",hint:`JSON, with fill-ins inside its strings. ${aC}`,children:(0,m.jsx)(na,{rows:5,value:e.args,maxLength:4e3,onChange:n=>a({...e,args:n.target.value}),className:"font-mono text-[12px]","aria-label":"Arguments"})})]})}function sY({stage:e,stages:t,view:a,csrf:o,apply:n,update:r,remove:s,makeStart:i,onClose:l}){let c=t.filter(d=>d.id!==e.id),f=gt,u=a.kinds.find(d=>d.kind===e.kind);return(0,m.jsxs)("div",{className:"flex flex-col gap-3","data-flow-zone-panel":e.id,children:[(0,m.jsxs)("div",{className:"flex items-center gap-2",children:[(0,m.jsx)("h2",{className:"flex-1 text-[15px] font-semibold",children:"Edit zone"}),(0,m.jsx)(oe,{variant:"ghost",size:"icon",onClick:l,"aria-label":"Close",children:(0,m.jsx)(jt,{className:"size-4"})})]}),(0,m.jsx)(he,{label:"Name",children:(0,m.jsx)(Se,{value:e.title,maxLength:60,onChange:d=>r({title:d.target.value}),"aria-label":"Zone name"})}),(0,m.jsx)(he,{label:"What happens here",...u===void 0?{}:{hint:u.about},children:(0,m.jsx)("select",{className:f,"aria-label":"What happens here",value:e.kind,onChange:d=>r({kind:d.target.value,...d.target.value==="done"?{next:null,onFail:null}:{},...d.target.value==="update"?{close:e.close??!0,message:e.message??"Done: {{card.title}}"}:{},...d.target.value==="check"?{script:e.script??a.scripts[0]?.name??null,runIn:e.runIn??"folder"}:{},...d.target.value==="request"?{request:e.request??{method:"POST",url:"https://",headers:{},body:'{"title": "{{card.title}}", "details": "{{card.description}}"}'}}:{},...d.target.value==="email"?{email:e.email??{to:"{{card.email}}",subject:"Re: {{card.title}}",body:t.find(p=>p.kind==="draft")?`{{stage.${t.find(p=>p.kind==="draft").id}}}`:""}}:{},...d.target.value==="tool"?{tool:e.tool??{server:a.tools[0]?.name??"",name:a.tools[0]?.functions[0]??"",args:'{"text": "{{card.title}}"}'}}:{},...d.target.value==="draft"?{instructions:e.instructions??"Write a short, friendly reply to the person who sent this card, in plain words."}:{},...d.target.value==="approval"?{toOwner:e.toOwner??!0}:{},...d.target.value==="wait"?{wait:e.wait??{for:"reply",minutes:4320}}:{},...d.target.value==="teammate"?{teammate:e.teammate??a.teammates?.[0]?.handle,instructions:e.instructions??"Read the card and decide what happens next."}:d.target.value!=="approval"?{teammate:void 0}:{},...d.target.value==="wait"||d.target.value==="done"?{limit:void 0}:d.target.value!=="inbox"&&d.target.value!=="approval"&&e.limit!==void 0?{limit:{...e.limit,to:null}}:{},...d.target.value==="sort"?{next:null,sort:e.sort??{question:"What kind of card is this?",answers:c.slice(0,2).map(p=>({answer:p.title.slice(0,40),means:p.title,to:p.id})),sureAt:.8,notes:[]}}:{}}),children:a.kinds.map(d=>(0,m.jsx)("option",{value:d.kind,children:d.label},d.kind))})}),e.kind==="draft"&&(0,m.jsx)(he,{label:"What Claude should write",hint:"Claude reads the card and what earlier zones said. Put a “Person decides” zone next to read and edit it first.",children:(0,m.jsx)(na,{rows:5,value:e.instructions??"",maxLength:4e3,onChange:d=>r({instructions:d.target.value}),"aria-label":"What Claude should write"})}),(e.kind==="task"||e.kind==="report")&&(0,m.jsx)(he,{label:"What the agent should do",hint:"Fill-ins: {{card.title}}, {{card.description}}, {{note}} (the latest send-back note), {{stage.<zone id>}} (an earlier zone's report).",children:(0,m.jsx)(na,{rows:7,value:e.instructions??"",onChange:d=>r({instructions:d.target.value}),"aria-label":"What the agent should do"})}),e.kind==="task"&&(0,m.jsx)(he,{label:"Plan first?",children:(0,m.jsxs)("select",{className:f,"aria-label":"Plan first?",value:e.planning??"auto",onChange:d=>r({planning:d.target.value}),children:[(0,m.jsx)("option",{value:"auto",children:"Let Toolroll decide"}),(0,m.jsx)("option",{value:"required",children:"Always plan first"}),(0,m.jsx)("option",{value:"skip",children:"Build directly"})]})}),e.kind==="approval"&&(0,m.jsx)(he,{label:"Who decides",children:(0,m.jsxs)("select",{className:f,"aria-label":"Who decides",value:e.teammate!==void 0?`__mate__:${e.teammate}`:e.toOwner===!0?"__owner__":e.approver??"",onChange:d=>r(d.target.value.startsWith("__mate__:")?{teammate:d.target.value.slice(9),toOwner:!0,approver:null}:d.target.value==="__owner__"?{teammate:void 0,toOwner:!0,approver:null}:{teammate:void 0,toOwner:!1,approver:d.target.value===""?null:d.target.value}),children:[(a.teammates??[]).map(d=>(0,m.jsxs)("option",{value:`__mate__:${d.handle}`,children:[d.name," (AI teammate), handing hard ones to the flow's owner",d.working?"":" (paused)"]},d.handle)),(0,m.jsxs)("option",{value:"__owner__",children:["The flow's owner (",a.flow.owner,"), in their chat app"]}),(0,m.jsx)("option",{value:"",children:"Anyone who can approve"}),a.approvers.map(d=>(0,m.jsx)("option",{value:d,children:d},d))]})}),e.kind==="notify"&&(0,m.jsx)(he,{label:"Message",children:(0,m.jsx)(Se,{value:e.message??"",maxLength:1e3,onChange:d=>r({message:d.target.value}),"aria-label":"Message"})}),e.kind==="update"&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(he,{label:"Comment on the issue",hint:"Fill-ins: {{card.title}}, {{note}}, {{stage.<zone id>}}.",children:(0,m.jsx)(na,{rows:3,value:e.message??"",maxLength:1e3,onChange:d=>r({message:d.target.value}),"aria-label":"Comment on the issue"})}),(0,m.jsxs)("label",{className:"flex items-center gap-2 text-[13px]",children:[(0,m.jsx)("input",{type:"checkbox",className:"size-4 accent-[var(--so-accent)]",checked:e.close!==!1,onChange:d=>r({close:d.target.checked})}),"Close the issue too (Linear: move it to done)"]})]}),e.kind==="pull-request"&&(0,m.jsx)(he,{label:"When checks pass",hint:"Merging needs a “Person decides” zone before this one, and a person's approval of the card since it was built.",children:(0,m.jsxs)("select",{className:f,"aria-label":"When checks pass",value:e.merge??"",onChange:d=>r({merge:d.target.value===""?void 0:d.target.value}),children:[(0,m.jsx)("option",{value:"",children:"Move on; a person merges"}),(0,m.jsx)("option",{value:"squash",children:"Merge (squash)"}),(0,m.jsx)("option",{value:"merge",children:"Merge (merge commit)"}),(0,m.jsx)("option",{value:"rebase",children:"Merge (rebase)"})]})}),e.kind==="check"&&(0,m.jsx)(aY,{stage:e,others:c,view:a,csrf:o,apply:n,update:r}),e.kind==="teammate"&&(0,m.jsx)(tY,{stage:e,others:c,view:a,update:r}),e.kind==="request"&&e.request!==void 0&&(0,m.jsx)(JX,{request:e.request,view:a,csrf:o,apply:n,set:d=>r({request:d})}),e.kind==="email"&&e.email!==void 0&&(0,m.jsx)(nY,{email:e.email,view:a,set:d=>r({email:d})}),e.kind==="tool"&&e.tool!==void 0&&(0,m.jsx)(rY,{tool:e.tool,view:a,set:d=>r({tool:d})}),e.kind==="sort"&&e.sort!==null&&(0,m.jsx)(QX,{sort:e.sort,others:c,ready:a.sortReady,set:d=>r({sort:d})}),e.kind==="wait"&&e.wait!==void 0&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(he,{label:"Wait for",hint:e.wait.for==="reply"?"Only a reply from someone it emailed counts. Needs the inbox in Settings → Email.":void 0,children:(0,m.jsxs)("select",{className:f,"aria-label":"Wait for",value:e.wait.for,onChange:d=>r({wait:d.target.value==="hours"?{for:"hours",minutes:0,from:e.wait.from??"22:00",to:e.wait.to??"06:00"}:{for:d.target.value,minutes:e.wait.minutes>0?e.wait.minutes:1440}}),children:[(0,m.jsx)("option",{value:"reply",children:"A reply to the card's email"}),(0,m.jsx)("option",{value:"time",children:"A set time"}),(0,m.jsx)("option",{value:"hours",children:"Set hours, like overnight"})]})}),e.wait.for==="hours"?(0,m.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[(0,m.jsx)(he,{label:"From",children:(0,m.jsx)(Se,{type:"time",value:e.wait.from??"22:00",onChange:d=>r({wait:{...e.wait,from:d.target.value}}),"aria-label":"From"})}),(0,m.jsx)(he,{label:"Until",children:(0,m.jsx)(Se,{type:"time",value:e.wait.to??"06:00",onChange:d=>r({wait:{...e.wait,to:d.target.value}}),"aria-label":"Until"})})]}):(0,m.jsx)(he,{label:e.wait.for==="reply"?"For up to":"How long",children:(0,m.jsx)(JO,{minutes:e.wait.minutes,label:e.wait.for==="reply"?"For up to":"How long",set:d=>r({wait:{...e.wait,minutes:d}})})})]}),e.kind!=="done"&&e.kind!=="sort"&&(0,m.jsx)(he,{label:e.kind==="wait"&&e.wait?.for==="reply"?"When they reply":"Then",children:(0,m.jsxs)("select",{className:f,"aria-label":e.kind==="wait"&&e.wait?.for==="reply"?"When they reply":"Then",value:e.next??"",onChange:d=>r({next:d.target.value||null}),children:[(0,m.jsx)("option",{value:"",children:"Wait here"}),c.map(d=>(0,m.jsx)("option",{value:d.id,children:d.title},d.id))]})}),e.kind==="wait"&&e.wait?.for==="reply"&&(0,m.jsx)(he,{label:"If no reply",children:(0,m.jsxs)("select",{className:f,"aria-label":"If no reply",value:e.onFail??"",onChange:d=>r({onFail:d.target.value||null}),children:[(0,m.jsx)("option",{value:"",children:"Stay here for a person"}),c.map(d=>(0,m.jsx)("option",{value:d.id,children:d.title},d.id))]})}),(e.kind==="approval"||e.kind==="task"||e.kind==="report"||e.kind==="check"||e.kind==="pull-request"||e.kind==="update"||e.kind==="sort"||e.kind==="request"||e.kind==="email"||e.kind==="tool"||e.kind==="teammate")&&(0,m.jsx)(he,{label:e.kind==="approval"?"If sent back":e.kind==="sort"?"If it isn't sure":e.kind==="teammate"?"If it can't handle it":e.kind==="pull-request"?"If checks fail":"If it fails",children:(0,m.jsxs)("select",{className:f,"aria-label":e.kind==="approval"?"If sent back":e.kind==="sort"?"If it isn't sure":e.kind==="teammate"?"If it can't handle it":e.kind==="pull-request"?"If checks fail":"If it fails",value:e.onFail??"",onChange:d=>r({onFail:d.target.value||null}),children:[(0,m.jsx)("option",{value:"",children:e.kind==="approval"?"Can't be sent back":e.kind==="sort"?"Wait here for a person":"Wait here"}),c.map(d=>(0,m.jsx)("option",{value:d.id,children:d.title},d.id))]})}),e.kind!=="wait"&&e.kind!=="done"&&(0,m.jsx)(iY,{stage:e,others:c,update:r}),(0,m.jsxs)("div",{className:"grid gap-1.5",children:[(0,m.jsx)("span",{className:"text-[13px] font-medium",children:"Color"}),(0,m.jsx)("div",{className:"flex gap-2",children:a.colors.map(d=>(0,m.jsx)("button",{type:"button","aria-label":d,"aria-pressed":e.zone.color===d,className:ue("size-7 rounded-full border-2",e.zone.color===d?"border-foreground":"border-transparent"),style:{background:qf[d]},onClick:()=>r({zone:{...e.zone,color:d}})},d))})]}),(0,m.jsxs)("div",{className:"flex flex-wrap gap-2 pt-1",children:[a.start!==e.id&&(0,m.jsx)(oe,{variant:"outline",size:"sm",onClick:i,children:"New cards start here"}),(0,m.jsx)(oe,{variant:"ghost",size:"sm",className:"text-destructive",onClick:s,disabled:t.length<=1,children:"Delete zone"})]})]})}function JO({minutes:e,label:t,set:a}){let o=e%1440===0?1440:e%60===0?60:1;return(0,m.jsxs)("div",{className:"flex gap-2",children:[(0,m.jsx)(Se,{type:"number",min:1,max:Math.floor(43200/o),value:e/o,className:"w-24","aria-label":`${t} (number)`,onChange:n=>{let r=Math.round(Number(n.target.value));Number.isFinite(r)&&r>=1&&a(Math.min(43200,r*o))}}),(0,m.jsxs)("select",{className:gt,"aria-label":`${t} (unit)`,value:o,onChange:n=>a(Math.min(43200,Math.max(1,e/o*Number(n.target.value)))),children:[(0,m.jsx)("option",{value:1,children:"minutes"}),(0,m.jsx)("option",{value:60,children:"hours"}),(0,m.jsx)("option",{value:1440,children:"days"})]})]})}function iY({stage:e,others:t,update:a}){let o=e.kind==="inbox"||e.kind==="approval";return(0,m.jsxs)("div",{className:"grid gap-2","data-time-limit":!0,children:[(0,m.jsxs)("label",{className:"flex items-center gap-2 text-[13px] font-medium",children:[(0,m.jsx)("input",{type:"checkbox",className:"size-4 accent-[var(--so-accent)]",checked:e.limit!==void 0,onChange:n=>a({limit:n.target.checked?{minutes:1440,to:null}:void 0})}),"Time limit"]}),e.limit!==void 0&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(he,{label:"Remind after",hint:e.kind==="approval"?"Whoever decides hears about it once.":"The card's owner (or the flow's) hears about it once.",children:(0,m.jsx)(JO,{minutes:e.limit.minutes,label:"Remind after",set:n=>a({limit:{...e.limit,minutes:n}})})}),o&&(0,m.jsx)(he,{label:"Then",children:(0,m.jsxs)("select",{className:gt,"aria-label":"After the time limit",value:e.limit.to??"",onChange:n=>a({limit:{...e.limit,to:n.target.value||null}}),children:[(0,m.jsx)("option",{value:"",children:"Keep it here"}),t.map(n=>(0,m.jsxs)("option",{value:n.id,children:["Move it to ",n.title]},n.id))]})})]})]})}function eB({view:e,csrf:t,apply:a,onClose:o}){let[n,r]=(0,fe.useState)(""),[s,i]=(0,fe.useState)(""),[l,c]=(0,fe.useState)(!1),f=e.stages.find(u=>u.id===e.start);return(0,m.jsxs)("form",{className:"flex flex-col gap-2",onSubmit:async u=>{u.preventDefault(),c(!0);let d=await Xa(`${e.flow.href}/cards`,{title:n,description:s},t);c(!1),a(d),d.ok&&(r(""),i(""))},children:[(0,m.jsxs)("div",{className:"flex items-center gap-2",children:[(0,m.jsx)("h2",{className:"flex-1 text-[15px] font-semibold",children:"New card"}),o!==void 0&&(0,m.jsx)(oe,{type:"button",variant:"ghost",size:"icon",onClick:o,"aria-label":"Close",children:(0,m.jsx)(jt,{className:"size-4"})})]}),(0,m.jsxs)("p",{className:"text-[12px] text-muted-foreground",children:["It starts in ",f?.title??"the first zone","."]}),(0,m.jsx)(Se,{value:n,onChange:u=>r(u.target.value),placeholder:"What needs doing?",maxLength:200,required:!0,"aria-label":"Title"}),(0,m.jsx)(na,{value:s,onChange:u=>i(u.target.value),placeholder:"Details (optional)",rows:4,"aria-label":"Details"}),(0,m.jsxs)(oe,{type:"submit",size:"sm",className:"self-start",disabled:l||n.trim()==="",children:[(0,m.jsx)(ta,{className:"size-4"}),"Add card"]})]})}var tB=e=>{if(e===null)return"";let t=Math.round((Date.now()-Date.parse(e))/6e4);return t<1?"Just now":t<60?`${t} min ago`:t<1440?`${Math.round(t/60)} h ago`:new Date(e).toLocaleDateString(void 0,{month:"short",day:"numeric"})};function qO({label:e,value:t}){return(0,m.jsxs)("div",{className:"grid gap-1",children:[(0,m.jsx)("span",{className:"text-[12px] font-medium",children:e}),(0,m.jsxs)("div",{className:"flex gap-2",children:[(0,m.jsx)(Se,{readOnly:!0,value:t,className:"h-8 font-mono text-[12px]",onFocus:o=>o.target.select(),"aria-label":e}),(0,m.jsx)(oe,{type:"button",size:"sm",variant:"outline",onClick:()=>{navigator.clipboard?.writeText(t).then(()=>lo.success(`${e} copied.`),()=>lo.error("Select it and copy it by hand."))},"aria-label":`Copy ${e.toLowerCase()}`,children:(0,m.jsx)(Id,{className:"size-3.5"})})]})]})}function lY({kind:e,reveal:t,onDone:a}){return(0,m.jsxs)("div",{className:"flex flex-col gap-2 rounded-lg border border-primary/40 bg-primary/5 p-3","data-trigger-reveal":!0,children:[(0,m.jsx)("p",{className:"text-[13px] font-semibold",children:"Copy these now. They aren't shown again."}),t.address===null?(0,m.jsxs)("p",{className:"text-[12px]",children:["Save your public webhook address below first, then choose New address. ",(0,m.jsx)("span",{className:"break-all font-mono",children:t.path})]}):(0,m.jsx)(qO,{label:"Address",value:t.address}),t.secret!==null&&(0,m.jsx)(qO,{label:"Secret",value:t.secret}),(0,m.jsx)("p",{className:"text-[12px] text-muted-foreground",children:e==="github"?"In GitHub: Settings → Webhooks → Add webhook. Paste the address and the secret, choose application/json, and pick the events this trigger watches (Issues, Pull requests or Workflow runs).":e==="linear"?"In Linear: Settings → API → Webhooks → New webhook. Paste the address and choose Issues. Then paste Linear's signing secret on this trigger.":e==="form"?"Share this link. Anyone who has it can add a card without signing in; the work it starts still waits for your approval.":"Post JSON to the address. A title field becomes the card's title; description, its details."}),(0,m.jsx)(oe,{type:"button",size:"sm",variant:"outline",className:"self-start",onClick:a,children:"Done"})]})}var uY={button:["label","questions"],schedule:["schedule","title","description","script","secrets"],github:["repo","watch","label","branch","from","delivery"],linear:["team","state","label","delivery"],flow:["flow","when"],webhook:["title","titleField","bodyField"],email:["folder","sender","subject"]};function cY({view:e,csrf:t,open:a,onResult:o}){let n=e.triggerSetup,[r,s]=(0,fe.useState)("button"),[i,l]=(0,fe.useState)({}),[c,f]=(0,fe.useState)(!1),[u,d]=(0,fe.useState)(!1),g={schedule:{schedule:`daily 09:00 ${Intl.DateTimeFormat().resolvedOptions().timeZone}`},github:{repo:n.githubRepo??"",watch:"issues",from:"team",delivery:"poll",branch:"main"},linear:{delivery:"poll"},flow:{flow:String(n.otherFlows[0]?.id??"")},webhook:{title:"Webhook"},email:{folder:"INBOX"}},v=h=>i[h]??g[r]?.[h]??"",b=h=>w=>l(C=>({...C,[h]:w.target.value})),x=n.otherFlows.find(h=>String(h.id)===v("flow")),y=async h=>{h.preventDefault();let w={kind:r,zone:v("zone")||null};for(let S of uY[r]??[])w[S]=S==="questions"?v(S).split(`
|
|
62
|
+
npm test`};function nY({email:e,view:t,set:a}){return(0,m.jsxs)(m.Fragment,{children:[!t.emailReady&&(0,m.jsxs)("p",{className:"rounded-md border border-border px-3 py-2 text-[12.5px]","data-email-needs-setup":!0,children:["Email isn't set up yet. ",(0,m.jsx)("a",{className:"font-medium text-primary underline-offset-4 hover:underline",href:"/settings#email",children:"Add your mail server in Settings"})]}),(0,m.jsx)(he,{label:"To",children:(0,m.jsx)(Se,{value:e.to,maxLength:500,onChange:o=>a({...e,to:o.target.value}),"aria-label":"To"})}),(0,m.jsx)(he,{label:"Subject",children:(0,m.jsx)(Se,{value:e.subject,maxLength:200,onChange:o=>a({...e,subject:o.target.value}),"aria-label":"Subject"})}),(0,m.jsx)(he,{label:"Email",hint:aC,children:(0,m.jsx)(na,{rows:6,value:e.body,maxLength:8e3,onChange:o=>a({...e,body:o.target.value}),"aria-label":"Email"})})]})}function rY({tool:e,view:t,set:a}){let o=t.tools.find(n=>n.name===e.server);return(0,m.jsxs)(m.Fragment,{children:[t.tools.length===0?(0,m.jsxs)("p",{className:"rounded-md border border-border px-3 py-2 text-[12.5px]","data-tool-needs-setup":!0,children:["This project has no tools yet. ",(0,m.jsx)("a",{className:"font-medium text-primary underline-offset-4 hover:underline",href:"/settings/tools",children:"Add one on the Tools page"})]}):(0,m.jsx)(he,{label:"Tool",...o!==void 0&&!o.ready?{hint:"It needs its secrets set on the Tools page first."}:o!==void 0?{hint:o.about}:{},children:(0,m.jsxs)("select",{className:gt,value:e.server,onChange:n=>a({...e,server:n.target.value,name:t.tools.find(r=>r.name===n.target.value)?.functions[0]??""}),"aria-label":"Tool",children:[o===void 0&&(0,m.jsx)("option",{value:e.server,children:e.server===""?"Choose a tool":`${e.server} (missing)`}),t.tools.map(n=>(0,m.jsx)("option",{value:n.name,children:n.name},n.name))]})}),(0,m.jsx)(he,{label:"What it does",hint:o!==void 0&&o.functions.length===0?"Test the tool on the Tools page to list what it can do.":void 0,children:o!==void 0&&o.functions.length>0?(0,m.jsxs)("select",{className:gt,value:e.name,onChange:n=>a({...e,name:n.target.value}),"aria-label":"What it does",children:[!o.functions.includes(e.name)&&(0,m.jsx)("option",{value:e.name,children:e.name||"Choose"}),o.functions.map(n=>(0,m.jsx)("option",{value:n,children:n},n))]}):(0,m.jsx)(Se,{value:e.name,maxLength:100,onChange:n=>a({...e,name:n.target.value}),className:"font-mono","aria-label":"What it does"})}),(0,m.jsx)(he,{label:"Arguments",hint:`JSON, with fill-ins inside its strings. ${aC}`,children:(0,m.jsx)(na,{rows:5,value:e.args,maxLength:4e3,onChange:n=>a({...e,args:n.target.value}),className:"font-mono text-[12px]","aria-label":"Arguments"})})]})}function sY({stage:e,stages:t,view:a,csrf:o,apply:n,update:r,remove:s,makeStart:i,onClose:l}){let c=t.filter(d=>d.id!==e.id),f=gt,u=a.kinds.find(d=>d.kind===e.kind);return(0,m.jsxs)("div",{className:"flex flex-col gap-3","data-flow-zone-panel":e.id,children:[(0,m.jsxs)("div",{className:"flex items-center gap-2",children:[(0,m.jsx)("h2",{className:"flex-1 text-[15px] font-semibold",children:"Edit zone"}),(0,m.jsx)(oe,{variant:"ghost",size:"icon",onClick:l,"aria-label":"Close",children:(0,m.jsx)(jt,{className:"size-4"})})]}),(0,m.jsx)(he,{label:"Name",children:(0,m.jsx)(Se,{value:e.title,maxLength:60,onChange:d=>r({title:d.target.value}),"aria-label":"Zone name"})}),(0,m.jsx)(he,{label:"What happens here",...u===void 0?{}:{hint:u.about},children:(0,m.jsx)("select",{className:f,"aria-label":"What happens here",value:e.kind,onChange:d=>r({kind:d.target.value,...d.target.value==="done"?{next:null,onFail:null}:{},...d.target.value==="update"?{close:e.close??!0,message:e.message??"Done: {{card.title}}"}:{},...d.target.value==="check"?{script:e.script??a.scripts[0]?.name??null,runIn:e.runIn??"folder"}:{},...d.target.value==="request"?{request:e.request??{method:"POST",url:"https://",headers:{},body:'{"title": "{{card.title}}", "details": "{{card.description}}"}'}}:{},...d.target.value==="email"?{email:e.email??{to:"{{card.email}}",subject:"Re: {{card.title}}",body:t.find(p=>p.kind==="draft")?`{{stage.${t.find(p=>p.kind==="draft").id}}}`:""}}:{},...d.target.value==="tool"?{tool:e.tool??{server:a.tools[0]?.name??"",name:a.tools[0]?.functions[0]??"",args:'{"text": "{{card.title}}"}'}}:{},...d.target.value==="draft"?{instructions:e.instructions??"Write a short, friendly reply to the person who sent this card, in plain words."}:{},...d.target.value==="approval"?{toOwner:e.toOwner??!0}:{},...d.target.value==="wait"?{wait:e.wait??{for:"reply",minutes:4320}}:{},...d.target.value==="teammate"?{teammate:e.teammate??a.teammates?.[0]?.handle,instructions:e.instructions??"Read the card and decide what happens next."}:d.target.value!=="approval"?{teammate:void 0}:{},...d.target.value==="wait"||d.target.value==="done"?{limit:void 0}:d.target.value!=="inbox"&&d.target.value!=="approval"&&e.limit!==void 0?{limit:{...e.limit,to:null}}:{},...d.target.value==="sort"?{next:null,sort:e.sort??{question:"What kind of card is this?",answers:c.slice(0,2).map(p=>({answer:p.title.slice(0,40),means:p.title,to:p.id})),sureAt:.8,notes:[]}}:{}}),children:a.kinds.map(d=>(0,m.jsx)("option",{value:d.kind,children:d.label},d.kind))})}),e.kind==="draft"&&(0,m.jsx)(he,{label:"What Claude should write",hint:"Claude reads the card and what earlier zones said. Put a “Person decides” zone next to read and edit it first.",children:(0,m.jsx)(na,{rows:5,value:e.instructions??"",maxLength:4e3,onChange:d=>r({instructions:d.target.value}),"aria-label":"What Claude should write"})}),(e.kind==="task"||e.kind==="report")&&(0,m.jsx)(he,{label:"What the agent should do",hint:"Fill-ins: {{card.title}}, {{card.description}}, {{note}} (the latest send-back note), {{stage.<zone id>}} (an earlier zone's report).",children:(0,m.jsx)(na,{rows:7,value:e.instructions??"",onChange:d=>r({instructions:d.target.value}),"aria-label":"What the agent should do"})}),e.kind==="task"&&(0,m.jsx)(he,{label:"Plan first?",children:(0,m.jsxs)("select",{className:f,"aria-label":"Plan first?",value:e.planning??"auto",onChange:d=>r({planning:d.target.value}),children:[(0,m.jsx)("option",{value:"auto",children:"Let Toolroll decide"}),(0,m.jsx)("option",{value:"required",children:"Always plan first"}),(0,m.jsx)("option",{value:"skip",children:"Build directly"})]})}),e.kind==="approval"&&(0,m.jsx)(he,{label:"Who decides",children:(0,m.jsxs)("select",{className:f,"aria-label":"Who decides",value:e.teammate!==void 0?`__mate__:${e.teammate}`:e.toOwner===!0?"__owner__":e.approver??"",onChange:d=>r(d.target.value.startsWith("__mate__:")?{teammate:d.target.value.slice(9),toOwner:!0,approver:null}:d.target.value==="__owner__"?{teammate:void 0,toOwner:!0,approver:null}:{teammate:void 0,toOwner:!1,approver:d.target.value===""?null:d.target.value}),children:[(a.teammates??[]).map(d=>(0,m.jsxs)("option",{value:`__mate__:${d.handle}`,children:[d.name," (AI teammate), handing hard ones to the flow's owner",d.working?"":" (paused)"]},d.handle)),(0,m.jsxs)("option",{value:"__owner__",children:["The flow's owner (",a.flow.owner,"), in their chat app"]}),(0,m.jsx)("option",{value:"",children:"Anyone who can approve"}),a.approvers.map(d=>(0,m.jsx)("option",{value:d,children:d},d))]})}),e.kind==="notify"&&(0,m.jsx)(he,{label:"Message",children:(0,m.jsx)(Se,{value:e.message??"",maxLength:1e3,onChange:d=>r({message:d.target.value}),"aria-label":"Message"})}),e.kind==="update"&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(he,{label:"Comment on the issue",hint:"Fill-ins: {{card.title}}, {{note}}, {{stage.<zone id>}}.",children:(0,m.jsx)(na,{rows:3,value:e.message??"",maxLength:1e3,onChange:d=>r({message:d.target.value}),"aria-label":"Comment on the issue"})}),(0,m.jsxs)("label",{className:"flex items-center gap-2 text-[13px]",children:[(0,m.jsx)("input",{type:"checkbox",className:"size-4 accent-[var(--so-accent)]",checked:e.close!==!1,onChange:d=>r({close:d.target.checked})}),"Close the issue too (Linear: move it to done)"]})]}),e.kind==="pull-request"&&(0,m.jsx)(he,{label:"When checks pass",hint:"Merging needs a “Person decides” zone before this one, and a person's approval of the card since it was built.",children:(0,m.jsxs)("select",{className:f,"aria-label":"When checks pass",value:e.merge??"",onChange:d=>r({merge:d.target.value===""?void 0:d.target.value}),children:[(0,m.jsx)("option",{value:"",children:"Move on; a person merges"}),(0,m.jsx)("option",{value:"squash",children:"Merge (squash)"}),(0,m.jsx)("option",{value:"merge",children:"Merge (merge commit)"}),(0,m.jsx)("option",{value:"rebase",children:"Merge (rebase)"})]})}),e.kind==="check"&&(0,m.jsx)(aY,{stage:e,others:c,view:a,csrf:o,apply:n,update:r}),e.kind==="teammate"&&(0,m.jsx)(tY,{stage:e,others:c,view:a,update:r}),e.kind==="request"&&e.request!==void 0&&(0,m.jsx)(JX,{request:e.request,view:a,csrf:o,apply:n,set:d=>r({request:d})}),e.kind==="email"&&e.email!==void 0&&(0,m.jsx)(nY,{email:e.email,view:a,set:d=>r({email:d})}),e.kind==="tool"&&e.tool!==void 0&&(0,m.jsx)(rY,{tool:e.tool,view:a,set:d=>r({tool:d})}),e.kind==="sort"&&e.sort!==null&&(0,m.jsx)(QX,{sort:e.sort,others:c,ready:a.sortReady,set:d=>r({sort:d})}),e.kind==="wait"&&e.wait!==void 0&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(he,{label:"Wait for",hint:e.wait.for==="reply"?"Only a reply from someone it emailed counts. Needs the inbox in Settings → Email.":void 0,children:(0,m.jsxs)("select",{className:f,"aria-label":"Wait for",value:e.wait.for,onChange:d=>r({wait:d.target.value==="hours"?{for:"hours",minutes:0,from:e.wait.from??"22:00",to:e.wait.to??"06:00"}:{for:d.target.value,minutes:e.wait.minutes>0?e.wait.minutes:1440}}),children:[(0,m.jsx)("option",{value:"reply",children:"A reply to the card's email"}),(0,m.jsx)("option",{value:"time",children:"A set time"}),(0,m.jsx)("option",{value:"hours",children:"Set hours, like overnight"})]})}),e.wait.for==="hours"?(0,m.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[(0,m.jsx)(he,{label:"From",children:(0,m.jsx)(Se,{type:"time",value:e.wait.from??"22:00",onChange:d=>r({wait:{...e.wait,from:d.target.value}}),"aria-label":"From"})}),(0,m.jsx)(he,{label:"Until",children:(0,m.jsx)(Se,{type:"time",value:e.wait.to??"06:00",onChange:d=>r({wait:{...e.wait,to:d.target.value}}),"aria-label":"Until"})})]}):(0,m.jsx)(he,{label:e.wait.for==="reply"?"For up to":"How long",children:(0,m.jsx)(JO,{minutes:e.wait.minutes,label:e.wait.for==="reply"?"For up to":"How long",set:d=>r({wait:{...e.wait,minutes:d}})})})]}),e.kind!=="done"&&e.kind!=="sort"&&(0,m.jsx)(he,{label:e.kind==="wait"&&e.wait?.for==="reply"?"When they reply":"Then",children:(0,m.jsxs)("select",{className:f,"aria-label":e.kind==="wait"&&e.wait?.for==="reply"?"When they reply":"Then",value:e.next??"",onChange:d=>r({next:d.target.value||null}),children:[(0,m.jsx)("option",{value:"",children:"Wait here"}),c.map(d=>(0,m.jsx)("option",{value:d.id,children:d.title},d.id))]})}),e.kind==="wait"&&e.wait?.for==="reply"&&(0,m.jsx)(he,{label:"If no reply",children:(0,m.jsxs)("select",{className:f,"aria-label":"If no reply",value:e.onFail??"",onChange:d=>r({onFail:d.target.value||null}),children:[(0,m.jsx)("option",{value:"",children:"Stay here for a person"}),c.map(d=>(0,m.jsx)("option",{value:d.id,children:d.title},d.id))]})}),(e.kind==="approval"||e.kind==="task"||e.kind==="report"||e.kind==="check"||e.kind==="pull-request"||e.kind==="update"||e.kind==="sort"||e.kind==="request"||e.kind==="email"||e.kind==="tool"||e.kind==="teammate")&&(0,m.jsx)(he,{label:e.kind==="approval"?"If sent back":e.kind==="sort"?"If it isn't sure":e.kind==="teammate"?"If it can't handle it":e.kind==="pull-request"?"If checks fail":"If it fails",children:(0,m.jsxs)("select",{className:f,"aria-label":e.kind==="approval"?"If sent back":e.kind==="sort"?"If it isn't sure":e.kind==="teammate"?"If it can't handle it":e.kind==="pull-request"?"If checks fail":"If it fails",value:e.onFail??"",onChange:d=>r({onFail:d.target.value||null}),children:[(0,m.jsx)("option",{value:"",children:e.kind==="approval"?"Can't be sent back":e.kind==="sort"?"Wait here for a person":"Wait here"}),c.map(d=>(0,m.jsx)("option",{value:d.id,children:d.title},d.id))]})}),e.kind!=="wait"&&e.kind!=="done"&&(0,m.jsx)(iY,{stage:e,others:c,update:r}),(0,m.jsxs)("div",{className:"grid gap-1.5",children:[(0,m.jsx)("span",{className:"text-[13px] font-medium",children:"Color"}),(0,m.jsx)("div",{className:"flex gap-2",children:a.colors.map(d=>(0,m.jsx)("button",{type:"button","aria-label":d,"aria-pressed":e.zone.color===d,className:ue("size-7 rounded-full border-2",e.zone.color===d?"border-foreground":"border-transparent"),style:{background:qf[d]},onClick:()=>r({zone:{...e.zone,color:d}})},d))})]}),(0,m.jsxs)("div",{className:"flex flex-wrap gap-2 pt-1",children:[a.start!==e.id&&(0,m.jsx)(oe,{variant:"outline",size:"sm",onClick:i,children:"New cards start here"}),(0,m.jsx)(oe,{variant:"ghost",size:"sm",className:"text-destructive",onClick:s,disabled:t.length<=1,children:"Delete zone"})]})]})}function JO({minutes:e,label:t,set:a}){let o=e%1440===0?1440:e%60===0?60:1;return(0,m.jsxs)("div",{className:"flex gap-2",children:[(0,m.jsx)(Se,{type:"number",min:1,max:Math.floor(43200/o),value:e/o,className:"w-24","aria-label":`${t} (number)`,onChange:n=>{let r=Math.round(Number(n.target.value));Number.isFinite(r)&&r>=1&&a(Math.min(43200,r*o))}}),(0,m.jsxs)("select",{className:gt,"aria-label":`${t} (unit)`,value:o,onChange:n=>a(Math.min(43200,Math.max(1,e/o*Number(n.target.value)))),children:[(0,m.jsx)("option",{value:1,children:"minutes"}),(0,m.jsx)("option",{value:60,children:"hours"}),(0,m.jsx)("option",{value:1440,children:"days"})]})]})}function iY({stage:e,others:t,update:a}){let o=e.kind==="inbox"||e.kind==="approval";return(0,m.jsxs)("div",{className:"grid gap-2","data-time-limit":!0,children:[(0,m.jsxs)("label",{className:"flex items-center gap-2 text-[13px] font-medium",children:[(0,m.jsx)("input",{type:"checkbox",className:"size-4 accent-[var(--so-accent)]",checked:e.limit!==void 0,onChange:n=>a({limit:n.target.checked?{minutes:1440,to:null}:void 0})}),"Time limit"]}),e.limit!==void 0&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(he,{label:"Remind after",hint:e.kind==="approval"?"Whoever decides hears about it once.":"The card's owner (or the flow's) hears about it once.",children:(0,m.jsx)(JO,{minutes:e.limit.minutes,label:"Remind after",set:n=>a({limit:{...e.limit,minutes:n}})})}),o&&(0,m.jsx)(he,{label:"Then",children:(0,m.jsxs)("select",{className:gt,"aria-label":"After the time limit",value:e.limit.to??"",onChange:n=>a({limit:{...e.limit,to:n.target.value||null}}),children:[(0,m.jsx)("option",{value:"",children:"Keep it here"}),t.map(n=>(0,m.jsxs)("option",{value:n.id,children:["Move it to ",n.title]},n.id))]})})]})]})}function eB({view:e,csrf:t,apply:a,onClose:o}){let[n,r]=(0,fe.useState)(""),[s,i]=(0,fe.useState)(""),[l,c]=(0,fe.useState)(!1),f=e.stages.find(u=>u.id===e.start);return(0,m.jsxs)("form",{className:"flex flex-col gap-2",onSubmit:async u=>{u.preventDefault(),c(!0);let d=await Xa(`${e.flow.href}/cards`,{title:n,description:s},t);c(!1),a(d),d.ok&&(r(""),i(""))},children:[(0,m.jsxs)("div",{className:"flex items-center gap-2",children:[(0,m.jsx)("h2",{className:"flex-1 text-[15px] font-semibold",children:"New card"}),o!==void 0&&(0,m.jsx)(oe,{type:"button",variant:"ghost",size:"icon",onClick:o,"aria-label":"Close",children:(0,m.jsx)(jt,{className:"size-4"})})]}),(0,m.jsxs)("p",{className:"text-[12px] text-muted-foreground",children:["It starts in ",f?.title??"the first zone","."]}),(0,m.jsx)(Se,{value:n,onChange:u=>r(u.target.value),placeholder:"What needs doing?",maxLength:200,required:!0,"aria-label":"Title"}),(0,m.jsx)(na,{value:s,onChange:u=>i(u.target.value),placeholder:"Details (optional)",rows:4,"aria-label":"Details"}),(0,m.jsxs)(oe,{type:"submit",size:"sm",className:"self-start",disabled:l||n.trim()==="",children:[(0,m.jsx)(ta,{className:"size-4"}),"Add card"]})]})}var tB=e=>{if(e===null)return"";let t=Math.round((Date.now()-Date.parse(e))/6e4);return t<1?"Just now":t<60?`${t} min ago`:t<1440?`${Math.round(t/60)} h ago`:new Date(e).toLocaleDateString(void 0,{month:"short",day:"numeric"})};function qO({label:e,value:t}){return(0,m.jsxs)("div",{className:"grid gap-1",children:[(0,m.jsx)("span",{className:"text-[12px] font-medium",children:e}),(0,m.jsxs)("div",{className:"flex gap-2",children:[(0,m.jsx)(Se,{readOnly:!0,value:t,className:"h-8 font-mono text-[12px]",onFocus:o=>o.target.select(),"aria-label":e}),(0,m.jsx)(oe,{type:"button",size:"sm",variant:"outline",onClick:()=>{navigator.clipboard?.writeText(t).then(()=>lo.success(`${e} copied.`),()=>lo.error("Select it and copy it by hand."))},"aria-label":`Copy ${e.toLowerCase()}`,children:(0,m.jsx)(Id,{className:"size-3.5"})})]})]})}function lY({kind:e,reveal:t,onDone:a}){return(0,m.jsxs)("div",{className:"flex flex-col gap-2 rounded-lg border border-primary/40 bg-primary/5 p-3","data-trigger-reveal":!0,children:[(0,m.jsx)("p",{className:"text-[13px] font-semibold",children:"Copy these now. They aren't shown again."}),t.address===null?(0,m.jsxs)("p",{className:"text-[12px]",children:["Save your public webhook address below first, then choose New address. ",(0,m.jsx)("span",{className:"break-all font-mono",children:t.path})]}):(0,m.jsx)(qO,{label:"Address",value:t.address}),t.secret!==null&&(0,m.jsx)(qO,{label:"Secret",value:t.secret}),(0,m.jsx)("p",{className:"text-[12px] text-muted-foreground",children:e==="github"?"In GitHub: Settings → Webhooks → Add webhook. Paste the address and the secret, choose application/json, and pick the events this trigger watches (Issues, Pull requests or Workflow runs).":e==="linear"?"In Linear: Settings → API → Webhooks → New webhook. Paste the address and choose Issues. Then paste Linear's signing secret on this trigger.":e==="form"?"Share this link. Anyone who has it can add a card without signing in; the work it starts still waits for your approval.":"Post JSON to the address. A title field becomes the card's title; description, its details."}),(0,m.jsx)(oe,{type:"button",size:"sm",variant:"outline",className:"self-start",onClick:a,children:"Done"})]})}var uY={button:["label","questions"],schedule:["schedule","title","description","script","secrets"],github:["repo","watch","label","branch","from","delivery"],linear:["team","state","label","delivery"],flow:["flow","when"],webhook:["title","titleField","bodyField"],email:["folder","sender","subject"],"plane-review":["at","timeZone"]};function cY({view:e,csrf:t,open:a,onResult:o}){let n=e.triggerSetup,[r,s]=(0,fe.useState)("button"),[i,l]=(0,fe.useState)({}),[c,f]=(0,fe.useState)(!1),[u,d]=(0,fe.useState)(!1),p=Intl.DateTimeFormat().resolvedOptions().timeZone,g={schedule:{schedule:`daily 09:00 ${p}`},github:{repo:n.githubRepo??"",watch:"issues",from:"team",delivery:"poll",branch:"main"},linear:{delivery:"poll"},flow:{flow:String(n.otherFlows[0]?.id??"")},webhook:{title:"Webhook"},email:{folder:"INBOX"},"plane-review":{at:"07:30",timeZone:p}},v=h=>i[h]??g[r]?.[h]??"",b=h=>w=>l(C=>({...C,[h]:w.target.value})),x=n.otherFlows.find(h=>String(h.id)===v("flow")),y=async h=>{h.preventDefault();let w={kind:r,zone:v("zone")||null};for(let S of uY[r]??[])w[S]=S==="questions"?v(S).split(`
|
|
63
63
|
`):S==="flow"?Number(v(S)):v(S)||null;d(!0);let C=await Xa(`${e.flow.href}/triggers`,{trigger:JSON.stringify(w)},t);d(!1),o(C,r),C.ok&&l({})};return(0,m.jsxs)("details",{className:"rounded-lg border px-3 py-2",open:a,children:[(0,m.jsx)("summary",{className:"cursor-pointer text-[13px] font-semibold",children:"Add a trigger"}),(0,m.jsxs)("form",{className:"flex flex-col gap-3 pt-3",onSubmit:h=>{y(h)},"data-add-trigger":!0,children:[(0,m.jsx)(he,{label:"What starts cards",children:(0,m.jsx)("select",{className:gt,value:r,onChange:h=>{s(h.target.value),l({})},children:n.kinds.map(h=>(0,m.jsx)("option",{value:h.kind,children:h.label},h.kind))})}),r==="button"&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(he,{label:"Button name",children:(0,m.jsx)(Se,{value:v("label"),onChange:b("label"),placeholder:"Report a bug",maxLength:40,required:!0})}),(0,m.jsx)(he,{label:"Questions it asks",hint:"One per line. The first answer becomes the card's title.",children:(0,m.jsx)(na,{rows:3,value:v("questions"),onChange:b("questions"),placeholder:`What happened?
|
|
64
64
|
Steps to reproduce
|
|
65
|
-
How bad is it?`})})]}),r==="schedule"&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(he,{label:"When",hint:"For example: daily 09:00 Europe/London, monday 09:00, every 4 hours.",children:(0,m.jsx)(Se,{value:v("schedule"),onChange:b("schedule"),required:!0})}),(0,m.jsx)(he,{label:"Makes",children:(0,m.jsxs)("select",{className:gt,value:v("script")===""&&!c?"card":"script","aria-label":"Makes",onChange:h=>{f(h.target.value==="script"),l(w=>({...w,script:h.target.value==="script"?e.scripts[0]?.name??"":""}))},children:[(0,m.jsx)("option",{value:"card",children:"One card each time"}),(0,m.jsx)("option",{value:"script",children:"A card for each item a script prints"})]})}),v("script")!==""||c?e.scripts.length===0?(0,m.jsx)("p",{className:"text-[13px] text-muted-foreground",children:"This project has no scripts yet: make one with Scripts in the toolbar."}):(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(he,{label:"Script",hint:'It prints one item per line (a title, or JSON like {"title": "…", "key": 42}). The same item never makes two cards.',children:(0,m.jsx)("select",{className:gt,value:v("script"),onChange:b("script"),"aria-label":"Script",children:e.scripts.map(h=>(0,m.jsxs)("option",{value:h.name,children:[h.name," — ",h.about]},h.name))})}),(0,m.jsx)(he,{label:"Secrets it gets (optional)",hint:"Names of saved secrets, like CRM_KEY. Save them on a script zone's Secrets.",children:(0,m.jsx)(Se,{value:v("secrets"),onChange:b("secrets"),className:"font-mono",placeholder:"CRM_KEY",maxLength:400})})]}):(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(he,{label:"Card title",hint:"Each card's date is added to it.",children:(0,m.jsx)(Se,{value:v("title"),onChange:b("title"),placeholder:"Dependency check",maxLength:200,required:!0})}),(0,m.jsx)(he,{label:"Details (optional)",children:(0,m.jsx)(na,{rows:3,value:v("description"),onChange:b("description")})})]})]}),r==="github"&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(he,{label:"Repository",children:(0,m.jsx)(Se,{value:v("repo"),onChange:b("repo"),placeholder:"owner/name",required:!0})}),(0,m.jsx)(he,{label:"Watch",children:(0,m.jsxs)("select",{className:gt,value:v("watch"),onChange:b("watch"),children:[(0,m.jsx)("option",{value:"issues",children:"New issues"}),(0,m.jsx)("option",{value:"pulls",children:"New pull requests"}),(0,m.jsx)("option",{value:"checks",children:"Failed checks"})]})}),v("watch")!=="checks"&&(0,m.jsx)(he,{label:"Label (optional)",hint:v("watch")==="issues"?"With a label, an issue joins the moment it gets the label.":"Only pull requests with this label.",children:(0,m.jsx)(Se,{value:v("label"),onChange:b("label"),placeholder:"bug",maxLength:50})}),v("watch")==="checks"&&(0,m.jsx)(he,{label:"Branch",children:(0,m.jsx)(Se,{value:v("branch"),onChange:b("branch"),maxLength:100})}),v("watch")!=="checks"&&(0,m.jsx)(he,{label:"From",hint:v("from")==="anyone"?"Anyone who can open one there can write what the agent reads. The work still waits for your approval.":void 0,children:(0,m.jsxs)("select",{className:gt,value:v("from"),onChange:b("from"),children:[(0,m.jsx)("option",{value:"team",children:"People with write access"}),(0,m.jsx)("option",{value:"anyone",children:"Anyone"})]})})]}),r==="linear"&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(he,{label:"Team key",hint:"Like ENG. Name a team, a label, or both.",children:(0,m.jsx)(Se,{value:v("team"),onChange:b("team"),placeholder:"ENG",maxLength:12})}),(0,m.jsx)(he,{label:"When it moves to (optional)",children:(0,m.jsx)(Se,{value:v("state"),onChange:b("state"),placeholder:"Todo",maxLength:40})}),(0,m.jsx)(he,{label:"Label (optional)",children:(0,m.jsx)(Se,{value:v("label"),onChange:b("label"),placeholder:"bug",maxLength:50})})]}),(r==="github"||r==="linear")&&(0,m.jsx)(he,{label:"How it arrives",hint:v("delivery")==="webhook"?n.hooksBase===null?"Needs your public webhook address: set it under Settings below.":"You'll get an address to paste into "+(r==="github"?"GitHub.":"Linear."):r==="linear"&&!n.linearKey?"Save your Linear key under Settings below first.":void 0,children:(0,m.jsxs)("select",{className:gt,value:v("delivery"),onChange:b("delivery"),children:[(0,m.jsx)("option",{value:"poll",children:"Checked every 2 minutes"}),(0,m.jsx)("option",{value:"webhook",children:"Sent to a webhook address"})]})}),r==="flow"&&(n.otherFlows.length===0?(0,m.jsx)("p",{className:"text-[13px] text-muted-foreground",children:"There are no other flows to follow yet."}):(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(he,{label:"Flow",children:(0,m.jsx)("select",{className:gt,value:v("flow"),onChange:h=>l(w=>({...w,flow:h.target.value,when:""})),children:n.otherFlows.map(h=>(0,m.jsx)("option",{value:h.id,children:h.name},h.id))})}),(0,m.jsx)(he,{label:"When a card reaches",children:(0,m.jsxs)("select",{className:gt,value:v("when"),onChange:b("when"),children:[(0,m.jsx)("option",{value:"",children:"The end"}),x?.zones.map(h=>(0,m.jsx)("option",{value:h.id,children:h.title},h.id))]})})]})),r==="chat"&&(0,m.jsxs)("div",{className:"flex flex-col gap-2 rounded-md bg-muted px-2.5 py-2 text-[12.5px]","data-chat-connect":!0,children:[(0,m.jsx)("p",{children:"Connect a Slack, Discord or Teams channel, or a Telegram group, from the channel itself. Where Toolroll is, send:"}),(0,m.jsx)("p",{children:(0,m.jsxs)("code",{className:"rounded bg-background px-1.5 py-0.5 font-semibold",children:["flow ",e.flow.id]})}),(0,m.jsxs)("p",{className:"text-muted-foreground",children:["Each new message there becomes a card here, and replies in its thread join the card's discussion. “flow off” stops it. In Teams, mention Toolroll in each message. In Telegram, send /flow ",e.flow.id,", and turn the bot's privacy mode off in BotFather so it sees every message."]})]}),r==="email"&&(0,m.jsxs)(m.Fragment,{children:[n.mailbox===null?(0,m.jsxs)("p",{className:"rounded-md bg-muted px-2.5 py-2 text-[12.5px]","data-mailbox-missing":!0,children:["Reading mail isn't set up yet. Add your mail server's IMAP address, or sign in with Google, in ",(0,m.jsx)("a",{className:"underline",href:"/settings#email",children:"Settings → Email"}),"."]}):(0,m.jsxs)("p",{className:"text-[12.5px] text-muted-foreground",children:["New mail in ",n.mailbox," becomes cards, from now on. The mailbox is only read: nothing is marked or moved."]}),(0,m.jsx)(he,{label:"Folder",children:(0,m.jsx)(Se,{value:v("folder"),onChange:b("folder"),placeholder:"INBOX",maxLength:100})}),(0,m.jsx)(he,{label:"Only from (optional)",hint:"Addresses or domains, like priya@example.com, example.com.",children:(0,m.jsx)(Se,{value:v("sender"),onChange:b("sender"),maxLength:300})}),(0,m.jsx)(he,{label:"Subject has (optional)",children:(0,m.jsx)(Se,{value:v("subject"),onChange:b("subject"),placeholder:"Order",maxLength:100})})]}),r==="webhook"&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(he,{label:"Title field",hint:"Where to find the card's title in the posted JSON, like title or data.issue.title.",children:(0,m.jsx)(Se,{value:v("titleField"),onChange:b("titleField"),placeholder:"title",maxLength:80})}),(0,m.jsx)(he,{label:"Details field",children:(0,m.jsx)(Se,{value:v("bodyField"),onChange:b("bodyField"),placeholder:"description",maxLength:80})}),(0,m.jsx)(he,{label:"Title when there is none",children:(0,m.jsx)(Se,{value:v("title"),onChange:b("title"),maxLength:120})})]}),r!=="chat"&&(0,m.jsx)(he,{label:"Cards start in",children:(0,m.jsxs)("select",{className:gt,value:v("zone"),onChange:b("zone"),children:[(0,m.jsx)("option",{value:"",children:e.stages.find(h=>h.id===e.start)?.title??"The first zone"}),e.stages.filter(h=>h.id!==e.start).map(h=>(0,m.jsx)("option",{value:h.id,children:h.title},h.id))]})}),r!=="chat"&&(0,m.jsxs)(oe,{type:"submit",size:"sm",className:"self-start",disabled:u||r==="flow"&&n.otherFlows.length===0,children:[(0,m.jsx)(ta,{className:"size-4"}),"Add trigger"]})]})]})}function dY({view:e,csrf:t,apply:a}){let o=e.triggerSetup,[n,r]=(0,fe.useState)(""),[s,i]=(0,fe.useState)(""),[l,c]=(0,fe.useState)(o.hooksBase??""),[f,u]=(0,fe.useState)(!1),d=async(p,g)=>{u(!0);let v=await Xa(p,g,t);u(!1),a(v),v.ok&&(r(""),i(""))};return(0,m.jsxs)("details",{className:"rounded-lg border px-3 py-2",children:[(0,m.jsx)("summary",{className:"cursor-pointer text-[13px] font-semibold",children:"Settings"}),(0,m.jsxs)("div",{className:"flex flex-col gap-4 pt-3",children:[o.linearKey?(0,m.jsxs)("div",{className:"grid gap-1.5",children:[(0,m.jsx)("span",{className:"text-[13px] font-medium",children:"Linear key"}),(0,m.jsx)("p",{className:"text-[12px] text-muted-foreground",children:"Saved on this computer."}),(0,m.jsx)(oe,{type:"button",size:"sm",variant:"ghost",className:"self-start text-destructive",disabled:f,onClick:()=>{d(`${e.flow.href}/linear-key`,{remove:"yes"})},children:"Remove key"})]}):(0,m.jsxs)("form",{className:"flex flex-col gap-2",onSubmit:p=>{p.preventDefault(),d(`${e.flow.href}/linear-key`,{key:n,password:s})},children:[(0,m.jsx)(he,{label:"Linear key",hint:"From Linear → Settings → Security & access → Personal API keys. Kept on this computer only.",children:(0,m.jsx)(Se,{type:"password",autoComplete:"off",value:n,onChange:p=>r(p.target.value),placeholder:"lin_api_…"})}),(0,m.jsx)(aB,{view:e,password:s,setPassword:i}),(0,m.jsx)(oe,{type:"submit",size:"sm",className:"self-start",disabled:f||n.trim()===""||!oB(e,s),children:"Save key"})]}),(0,m.jsxs)("form",{className:"flex flex-col gap-2",onSubmit:p=>{p.preventDefault(),d(`${e.flow.href}/hooks-address`,{address:l})},children:[(0,m.jsx)(he,{label:"Public webhook address",hint:"The https site your reverse proxy (Caddy, for example) serves. Have it pass only paths starting /hooks/ to this console.",children:(0,m.jsx)(Se,{value:l,onChange:p=>c(p.target.value),placeholder:"https://hooks.example.com"})}),(0,m.jsx)(oe,{type:"submit",size:"sm",variant:"outline",className:"self-start",disabled:f,children:"Save address"})]})]})]})}function aB({view:e,password:t,setPassword:a}){return e.stepUp===void 0?(0,m.jsx)(he,{label:"Your Toolroll password",children:(0,m.jsx)(Se,{type:"password",autoComplete:"current-password",value:t,onChange:o=>a(o.target.value)})}):e.stepUp.fresh?(0,m.jsxs)("p",{className:"text-[13px] text-success","data-sso-step-up":"confirmed",children:["✓ Confirmed with ",e.stepUp.label]}):(0,m.jsxs)("a",{className:"text-[13px] underline","data-sso-step-up":"confirm",href:e.stepUp.confirmHref,children:["Confirm with ",e.stepUp.label]})}var oB=(e,t)=>e.stepUp===void 0?t!=="":e.stepUp.fresh;function fY({trigger:e,view:t,csrf:a,apply:o}){let[n,r]=(0,fe.useState)(""),[s,i]=(0,fe.useState)(""),[l,c]=(0,fe.useState)(!1);return(0,m.jsxs)("form",{className:"mt-2 flex flex-col gap-2 rounded-md border border-attention/50 p-2",onSubmit:async f=>{f.preventDefault(),c(!0);let u=await Xa(`${t.flow.href}/triggers/${e.id}/secret`,{secret:n,password:s},a);c(!1),o(u),u.ok&&(r(""),i(""))},children:[(0,m.jsx)(he,{label:"Linear's signing secret",hint:"Linear shows it when you create the webhook.",children:(0,m.jsx)(Se,{type:"password",autoComplete:"off",value:n,onChange:f=>r(f.target.value)})}),(0,m.jsx)(aB,{view:t,password:s,setPassword:i}),(0,m.jsx)(oe,{type:"submit",size:"sm",className:"self-start",disabled:l||n.trim()===""||!oB(t,s),children:"Save secret"})]})}function pY({view:e,csrf:t,apply:a,focus:o,onPress:n,onClose:r}){let[s,i]=(0,fe.useState)(null),[l,c]=(0,fe.useState)(!1),f=`${e.flow.href}/triggers`,u=async(p,g)=>{c(!0);let v=await Xa(p,{},t);c(!1),a(v),v.reveal!==void 0&&i({kind:g,reveal:v.reveal})},d=e.triggers.filter(p=>p.state!=="removed");return(0,fe.useEffect)(()=>{o!==null&&document.querySelector(`[data-trigger-row="${o}"]`)?.scrollIntoView({block:"nearest"})},[o]),(0,m.jsxs)("div",{className:"flex flex-col gap-4","data-flow-triggers":!0,children:[(0,m.jsxs)("div",{className:"flex items-center gap-2",children:[(0,m.jsx)("h2",{className:"flex-1 text-[15px] font-semibold",children:"Triggers"}),(0,m.jsx)(oe,{variant:"ghost",size:"icon",onClick:r,"aria-label":"Close",children:(0,m.jsx)(jt,{className:"size-4"})})]}),(0,m.jsx)("p",{className:"text-[13px] text-muted-foreground",children:"Triggers add cards to this flow on their own. The work they start still waits for your usual approvals."}),s!==null&&(0,m.jsx)(lY,{kind:s.kind,reveal:s.reveal,onDone:()=>i(null)}),d.length>0&&(0,m.jsx)("ul",{className:"flex flex-col gap-3",children:d.map(p=>(0,m.jsxs)("li",{className:ue("rounded-lg border p-3",o===p.id&&"ring-2 ring-primary/50"),"data-trigger-row":p.id,children:[(0,m.jsxs)("div",{className:"flex items-start gap-2",children:[(0,m.jsx)("span",{className:"mt-0.5 inline-flex size-6 shrink-0 items-center justify-center rounded-md bg-muted text-muted-foreground",children:VO[p.kind]??(0,m.jsx)(Cs,{className:"size-3.5","aria-hidden":"true"})}),(0,m.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,m.jsx)("p",{className:"text-[13px] font-medium leading-snug",children:p.words}),(0,m.jsxs)("p",{className:"text-[12px] text-muted-foreground",children:["Starts in ",p.zone,p.state==="paused"?" · Paused":"",p.shared?" · Shared as a form":""]}),p.status!==null&&(0,m.jsxs)("p",{className:ue("text-[12px]",p.failing?"text-warning":"text-muted-foreground"),children:[tB(p.statusAt),": ",p.status]})]})]}),p.hook?.needsSecret===!0&&!p.hook.ready&&(0,m.jsx)(fY,{trigger:p,view:e,csrf:t,apply:a}),(0,m.jsxs)("div",{className:"mt-2 flex flex-wrap gap-1.5",children:[p.button!==null&&p.state==="active"&&(0,m.jsx)(oe,{size:"sm",onClick:()=>n(p.id),children:"Start"}),p.button!==null&&(0,m.jsx)(oe,{size:"sm",variant:"outline",disabled:l,onClick:()=>{u(`${f}/${p.id}/share`,"form")},children:p.shared?"New form link":"Share as a form"}),p.shared&&(0,m.jsx)(oe,{size:"sm",variant:"ghost",disabled:l,onClick:()=>{u(`${f}/${p.id}/unshare`,"form")},children:"Stop sharing"}),p.checkable&&p.state==="active"&&(0,m.jsx)(oe,{size:"sm",variant:"outline",disabled:l,onClick:()=>{u(`${f}/${p.id}/check`,p.kind)},children:p.kind==="schedule"?"Run now":"Check now"}),p.hook!==null&&(0,m.jsx)(oe,{size:"sm",variant:"outline",disabled:l,onClick:()=>{u(`${f}/${p.id}/renew`,p.kind)},children:"New address"}),(0,m.jsx)(oe,{size:"sm",variant:"ghost",disabled:l,onClick:()=>{u(`${f}/${p.id}/${p.state==="paused"?"resume":"pause"}`,p.kind)},children:p.state==="paused"?"Turn on":"Pause"}),(0,m.jsx)(oe,{size:"sm",variant:"ghost",className:"text-destructive",disabled:l,onClick:()=>{u(`${f}/${p.id}/remove`,p.kind)},children:"Remove"})]})]},p.id))}),(0,m.jsx)(cY,{view:e,csrf:t,open:d.length===0,onResult:(p,g)=>{a(p),p.reveal!==void 0&&i({kind:g,reveal:p.reveal})}}),(0,m.jsx)(dY,{view:e,csrf:t,apply:a})]})}function nB({trigger:e,view:t,csrf:a,apply:o,onClose:n}){let r=e.button?.questions??[],[s,i]=(0,fe.useState)(r.map(()=>"")),[l,c]=(0,fe.useState)(!1),f=u=>d=>i(p=>p.map((g,v)=>v===u?d.target.value:g));return(0,m.jsxs)("form",{className:"flex flex-col gap-3","data-flow-press":e.id,onSubmit:async u=>{u.preventDefault(),c(!0);let d=await Xa(`${t.flow.href}/triggers/${e.id}/press`,{answers:JSON.stringify(s)},a);c(!1),o(d),d.ok&&n()},children:[(0,m.jsxs)("div",{className:"flex items-center gap-2",children:[(0,m.jsx)("h2",{className:"flex-1 text-[15px] font-semibold",children:e.button?.label}),(0,m.jsx)(oe,{type:"button",variant:"ghost",size:"icon",onClick:n,"aria-label":"Close",children:(0,m.jsx)(jt,{className:"size-4"})})]}),(0,m.jsxs)("p",{className:"text-[12px] text-muted-foreground",children:["The card starts in ",e.zone,"."]}),r.map((u,d)=>(0,m.jsx)(he,{label:u,children:d===0?(0,m.jsx)(Se,{value:s[d]??"",onChange:f(d),maxLength:200,required:!0,autoFocus:!0}):(0,m.jsx)(na,{rows:3,value:s[d]??"",onChange:f(d)})},d)),(0,m.jsxs)(oe,{type:"submit",size:"sm",className:"self-start",disabled:l||(s[0]??"").trim()==="",children:[(0,m.jsx)(ta,{className:"size-4"}),"Add card"]})]})}function mY({view:e,csrf:t,apply:a,onClose:o}){let n={name:"",about:"",body:"",timeoutMinutes:"15",language:"python",file:""},[r,s]=(0,fe.useState)(e.scripts.length===0?n:null),[i,l]=(0,fe.useState)(!1),c=async()=>{if(r===null)return;l(!0);let p=await Xa(`${e.flow.href}/scripts`,r,t);l(!1),a(p),p.ok&&(s(null),d(!1))},f=p=>g=>s(v=>v===null?v:{...v,[p]:g.target.value}),[u,d]=(0,fe.useState)(!1);return(0,m.jsxs)("div",{className:"flex flex-col gap-4","data-flow-scripts":!0,children:[(0,m.jsxs)("div",{className:"flex items-center gap-2",children:[(0,m.jsx)("h2",{className:"flex-1 text-[15px] font-semibold",children:"Scripts"}),(0,m.jsx)(oe,{variant:"ghost",size:"icon",onClick:o,"aria-label":"Close",children:(0,m.jsx)(jt,{className:"size-4"})})]}),(0,m.jsxs)("p",{className:"text-[13px] text-muted-foreground",children:["Reusable steps with no AI, in shell, Python or Node. A “Run a script” zone runs one with the card, and a schedule can run one to make cards. Any flow in ",e.flow.project," can use them."]}),e.scripts.length>0&&(0,m.jsx)("ul",{className:"flex flex-col gap-2",children:e.scripts.map(p=>(0,m.jsxs)("li",{className:"rounded-lg border p-3","data-script":p.name,children:[(0,m.jsxs)("div",{className:"flex items-start gap-2",children:[(0,m.jsx)("span",{className:"mt-0.5 inline-flex size-6 shrink-0 items-center justify-center rounded-md bg-muted text-muted-foreground",children:(0,m.jsx)(vs,{className:"size-3.5","aria-hidden":"true"})}),(0,m.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,m.jsx)("p",{className:"font-mono text-[13px] font-semibold",children:p.name}),(0,m.jsx)("p",{className:"text-[12.5px]",children:p.about}),(0,m.jsxs)("p",{className:"text-[12px] text-muted-foreground",children:[QO[p.language],p.file===null?"":` · runs ${p.file}`," · version ",p.version," · ",p.savedBy," · up to ",p.timeoutMinutes," min",p.usedHere.length>0?` · runs in ${p.usedHere.join(", ")}`:" · not used in this flow"]})]})]}),p.file===null&&(0,m.jsxs)("details",{className:"mt-2",children:[(0,m.jsx)("summary",{className:"cursor-pointer text-[12px] text-muted-foreground",children:"Show the script"}),(0,m.jsx)("pre",{className:"mt-2 max-h-56 overflow-auto rounded-md bg-muted p-2 font-mono text-[12px]",children:p.body})]}),e.canEdit&&(0,m.jsxs)("div",{className:"mt-2 flex gap-1.5",children:[(0,m.jsx)(oe,{size:"sm",variant:"outline",onClick:()=>{d(p.file!==null),s({name:p.name,about:p.about,body:p.body,timeoutMinutes:String(p.timeoutMinutes),language:p.language,file:p.file??""})},children:"Edit"}),(0,m.jsx)(oe,{size:"sm",variant:"ghost",className:"text-destructive",disabled:i,onClick:async()=>{l(!0),a(await Xa(`${e.flow.href}/scripts`,{remove:"yes",name:p.name},t)),l(!1)},children:"Remove"})]})]},p.name))}),e.canEdit&&(r===null?(0,m.jsxs)(oe,{size:"sm",variant:"outline",className:"self-start",onClick:()=>{d(!1),s(n)},children:[(0,m.jsx)(ta,{className:"size-4"}),"New script"]}):(0,m.jsxs)("form",{className:"flex flex-col gap-3 rounded-lg border p-3",onSubmit:p=>{p.preventDefault(),c()},"data-script-form":!0,children:[(0,m.jsx)(he,{label:"Name",hint:"Lowercase and dashes, like run-tests. Saving under an existing name makes a new version.",children:(0,m.jsx)(Se,{value:r.name,onChange:f("name"),maxLength:40,className:"font-mono",required:!0})}),(0,m.jsx)(he,{label:"What it checks or does",children:(0,m.jsx)(Se,{value:r.about,onChange:f("about"),maxLength:160,placeholder:"Looks the company up in our CRM",required:!0})}),(0,m.jsxs)("div",{className:"flex gap-2",children:[(0,m.jsx)(he,{label:"Language",children:(0,m.jsxs)("select",{className:gt,value:r.language,onChange:f("language"),"aria-label":"Language",children:[(0,m.jsx)("option",{value:"python",children:"Python"}),(0,m.jsx)("option",{value:"node",children:"Node"}),(0,m.jsx)("option",{value:"shell",children:"Shell"})]})}),(0,m.jsx)(he,{label:"Runs",children:(0,m.jsxs)("select",{className:gt,value:r.file===""&&!u?"here":"file",onChange:p=>{d(p.target.value==="file"),s(g=>g===null?g:{...g,file:p.target.value==="file"?g.file:""})},"aria-label":"Runs",children:[(0,m.jsx)("option",{value:"here",children:"What's written here"}),(0,m.jsx)("option",{value:"file",children:"A file in the project"})]})})]}),u||r.file!==""?(0,m.jsx)(he,{label:"File",hint:"A path from the top of the project. It gets the card as JSON on stdin (and in $FLOW_INPUT); what it prints is the step's result.",children:(0,m.jsx)(Se,{value:r.file,onChange:f("file"),maxLength:200,className:"font-mono",placeholder:"scripts/enrich.py",required:!0})}):(0,m.jsx)(he,{label:"Script",hint:"It gets the card as JSON on stdin (and in $FLOW_INPUT). What it prints is the step's result; a last line “goto: <answer>” picks the next zone. Exit 0 passes.",children:(0,m.jsx)(na,{value:r.body,onChange:f("body"),rows:8,className:"font-mono text-[12.5px]",placeholder:oY[r.language]??"",required:!0})}),(0,m.jsx)(he,{label:"Stop it after (minutes)",children:(0,m.jsx)(Se,{type:"number",min:1,max:60,value:r.timeoutMinutes,onChange:f("timeoutMinutes"),className:"w-28"})}),(0,m.jsxs)("div",{className:"flex gap-2",children:[(0,m.jsx)(oe,{type:"submit",size:"sm",disabled:i,children:"Save script"}),(0,m.jsx)(oe,{type:"button",size:"sm",variant:"ghost",onClick:()=>s(null),children:"Cancel"})]})]}))]})}var hY=e=>e===null?"—":e<1?"under a minute":e<90?`${Math.round(e)} min`:e<2880?`${Math.round(e/60)} h`:`${Math.round(e/1440)} days`;function gY({view:e,onClose:t}){let[a,o]=(0,fe.useState)(30),[n,r]=(0,fe.useState)(null),[s,i]=(0,fe.useState)(null),[l,c]=(0,fe.useState)(null);(0,fe.useEffect)(()=>{let u=!0;return r(null),i(null),fetch(`${e.flow.href}/insights?days=${a}`,{credentials:"same-origin",headers:{accept:"application/json"}}).then(async d=>{if(u){if(!d.ok)throw new Error("load");r(await d.json())}}).catch(()=>{u&&i("The insights couldn't load. Try again.")}),()=>{u=!1}},[a,e.flow.href,e.flow.revision]);let f=async(u,d)=>{let p=`${u}:${d}`;if(l?.key===p){c(null);return}try{let v=await(await fetch(`${e.flow.href}/runs/${u}/${d}`,{credentials:"same-origin",headers:{accept:"application/json"}})).json();c({key:p,text:v.log===void 0||v.log===""?"This run left no output.":v.log})}catch{c({key:p,text:"The log couldn't load."})}};return(0,m.jsxs)("div",{className:"flex flex-col gap-4","data-flow-insights":!0,children:[(0,m.jsxs)("div",{className:"flex items-center gap-2",children:[(0,m.jsx)("h2",{className:"flex-1 text-[15px] font-semibold",children:"Insights"}),(0,m.jsxs)("select",{className:"h-8 rounded-md border bg-transparent px-2 text-[12px]",value:a,onChange:u=>o(Number(u.target.value)),"aria-label":"Period",children:[(0,m.jsx)("option",{value:7,children:"Last 7 days"}),(0,m.jsx)("option",{value:30,children:"Last 30 days"}),(0,m.jsx)("option",{value:90,children:"Last 90 days"})]}),(0,m.jsx)(oe,{variant:"ghost",size:"icon",onClick:t,"aria-label":"Close",children:(0,m.jsx)(jt,{className:"size-4"})})]}),s!==null&&(0,m.jsx)("p",{className:"text-[13px] text-destructive",children:s}),n===null&&s===null&&(0,m.jsx)("p",{className:"text-[13px] text-muted-foreground",children:"Loading…"}),n!==null&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsxs)("p",{className:"text-[13px]",children:[n.cards.started," card",n.cards.started===1?"":"s"," started, ",n.cards.finished," finished, ",n.cards.active," in progress."]}),(0,m.jsxs)("section",{className:"flex flex-col gap-2",children:[(0,m.jsx)("h3",{className:"text-[13px] font-semibold",children:"Where it breaks"}),n.breaks.length===0?(0,m.jsx)("p",{className:"text-[12.5px] text-muted-foreground",children:"Nothing failed or was sent back in this period."}):(0,m.jsx)("ul",{className:"flex flex-col gap-2",children:n.breaks.map(u=>{let d=n.zones.find(p=>p.zone===u.zone);return(0,m.jsxs)("li",{className:"rounded-lg border border-border p-2.5 text-[13px]",children:[(0,m.jsxs)("p",{children:[(0,m.jsx)("span",{className:"font-semibold",children:u.title}),": ",u.problems," of ",u.of," card",u.of===1?"":"s"," failed or were sent back"]}),d?.lastProblem&&(0,m.jsxs)("p",{className:"mt-0.5 text-[12px] text-muted-foreground",children:["Latest: ",d.lastProblem.cardTitle,d.lastProblem.note===null?"":` — ${d.lastProblem.note.split(`
|
|
66
|
-
`)[0]}`]})]},u.zone)})})]}),(0,m.jsxs)("section",{className:"flex flex-col gap-1.5",children:[(0,m.jsx)("h3",{className:"text-[13px] font-semibold",children:"Zones"}),(0,m.jsxs)("table",{className:"w-full text-left text-[12px]",children:[(0,m.jsx)("thead",{className:"text-muted-foreground",children:(0,m.jsxs)("tr",{children:[(0,m.jsx)("th",{className:"py-1 font-medium",children:"Zone"}),(0,m.jsx)("th",{className:"font-medium",children:"In"}),(0,m.jsx)("th",{className:"font-medium",children:"On"}),(0,m.jsx)("th",{className:"font-medium",children:"Failed"}),(0,m.jsx)("th",{className:"font-medium",children:"Back"}),(0,m.jsx)("th",{className:"font-medium",children:"Typical stay"})]})}),(0,m.jsx)("tbody",{children:n.zones.map(u=>(0,m.jsxs)("tr",{className:"border-t",children:[(0,m.jsxs)("td",{className:"py-1.5 pr-2 font-medium",children:[u.title,u.here>0?(0,m.jsxs)("span",{className:"text-muted-foreground",children:[" · ",u.here," here"]}):null]}),(0,m.jsx)("td",{children:u.entered}),(0,m.jsx)("td",{children:u.movedOn}),(0,m.jsx)("td",{className:u.failed>0?"font-semibold text-destructive":"",children:u.failed}),(0,m.jsx)("td",{className:u.sentBack>0?"font-semibold text-foreground":"",children:u.sentBack}),(0,m.jsx)("td",{children:hY(u.typicalMinutes)})]},u.zone))})]})]}),n.scripts.length>0&&(0,m.jsxs)("section",{className:"flex flex-col gap-1.5",children:[(0,m.jsx)("h3",{className:"text-[13px] font-semibold",children:"Scripts"}),(0,m.jsx)("ul",{className:"flex flex-col gap-1 text-[12.5px]",children:n.scripts.map(u=>(0,m.jsxs)("li",{children:[(0,m.jsx)("span",{className:"font-mono font-semibold",children:u.script}),": ",u.passed," of ",u.runs," passed",u.typicalSeconds===null?"":`, usually ${u.typicalSeconds<90?`${u.typicalSeconds} s`:`${Math.round(u.typicalSeconds/60)} min`}`]},u.script))})]}),n.sorts.length>0&&(0,m.jsxs)("section",{className:"flex flex-col gap-2","data-insights-sorts":!0,children:[(0,m.jsx)("h3",{className:"text-[13px] font-semibold",children:"Sorting"}),n.sorts.map(u=>(0,m.jsxs)("div",{className:"rounded-lg border p-2.5 text-[12.5px]","data-insights-sort":u.zone,children:[(0,m.jsxs)("p",{children:[(0,m.jsx)("span",{className:"font-semibold",children:u.title}),": ",u.sorted," sorted · ",u.alone," on its own · ",u.notSure," for a person",u.corrected>0&&(0,m.jsxs)(m.Fragment,{children:[" · ",(0,m.jsxs)("span",{className:"font-semibold text-attention",children:[u.corrected," moved elsewhere by people"]})]})]}),u.bands.some(d=>d.of>0)&&(0,m.jsxs)("p",{className:"mt-1 text-muted-foreground",children:["Right when ",u.bands.filter(d=>d.of>0).map(d=>`${d.from}–${d.to}% sure: ${d.right} of ${d.of}`).join(" · ")]}),u.suggestion!==null&&(0,m.jsx)("p",{className:"mt-1",children:u.suggestion}),u.costUsd>0&&(0,m.jsxs)("p",{className:"mt-1 text-muted-foreground",children:["Cost: ",u.costUsd<.01?"under 1¢":`$${u.costUsd.toFixed(2)}`]})]},u.zone))]}),(0,m.jsxs)("section",{className:"flex flex-col gap-1.5",children:[(0,m.jsx)("h3",{className:"text-[13px] font-semibold",children:"Recent runs"}),n.runs.length===0?(0,m.jsx)("p",{className:"text-[12.5px] text-muted-foreground",children:"No scripts, sorts or updates have run in this period."}):(0,m.jsx)("ul",{className:"flex flex-col gap-1.5",children:n.runs.map(u=>{let d=`${u.card}:${u.entry}`;return(0,m.jsxs)("li",{className:"rounded-md border px-2.5 py-2 text-[12.5px]","data-run":d,children:[(0,m.jsxs)("button",{type:"button",className:"flex w-full items-start gap-2 text-left",onClick:()=>{f(u.card,u.entry)},"aria-expanded":l?.key===d,children:[(0,m.jsx)("span",{className:ue("mt-1 size-2 shrink-0 rounded-full",u.state==="passed"?"bg-success":u.state==="failed"?"bg-destructive":"bg-info"),"aria-hidden":"true"}),(0,m.jsxs)("span",{className:"min-w-0 flex-1",children:[(0,m.jsx)("span",{className:"font-medium",children:u.script??u.zoneTitle})," · ",u.cardTitle,(0,m.jsxs)("span",{className:"block text-[12px] text-muted-foreground",children:[u.kind==="sort"&&u.state==="passed"&&u.result!==null?u.result.split(". ")[0].replace(/\.$/,""):u.state==="passed"?"Passed":u.state==="failed"?"Failed":u.state==="waiting"?"Trying again":"Running",u.durationMs===null?"":u.kind==="sort"?` · ${u.durationMs<1e3?`${u.durationMs} ms`:`${(u.durationMs/1e3).toFixed(1)} s`}`:` in ${Math.max(1,Math.round(u.durationMs/1e3))} s`," · ",$O(u.at)]})]})]}),l?.key===d&&(0,m.jsx)("pre",{className:"mt-2 max-h-72 overflow-auto whitespace-pre-wrap rounded-md bg-muted p-2 font-mono text-[11.5px]","data-run-log":!0,children:l.text})]},d)})})]})]})]})}function xY({view:e,csrf:t}){let[a,o]=(0,fe.useState)(e),[n,r]=(0,fe.useState)(!1),[s,i]=(0,fe.useState)(null),[l,c]=(0,fe.useState)(e.selectedCard!==null?{card:e.selectedCard}:e.startTrigger!==null&&e.triggers.some(F=>F.id===e.startTrigger&&F.button!==null)?{press:e.startTrigger}:null),[f,u]=(0,fe.useState)(!1),[d,p]=(0,fe.useState)(!1),[g,v]=(0,fe.useState)(()=>{try{return window.localStorage.getItem("so-flows-mine")==="1"}catch{return!1}});(0,fe.useEffect)(()=>{try{window.localStorage.setItem("so-flows-mine",g?"1":"0")}catch{}},[g]);let b=Hf(),x=s?.stages??a.stages,y=s?.start??a.start,h=s!==null&&JSON.stringify({name:s.name,start:s.start,stages:s.stages,owner:s.owner})!==JSON.stringify({name:a.flow.name,start:a.start,stages:a.stages,owner:a.flow.owner}),w=(0,fe.useCallback)(F=>{(F.ok?lo.success:lo.error)(F.said),F.view!==void 0&&o(F.view)},[]),C=GO(a,o,{card:l!==null&&"card"in l?l.card:null,editing:n}),S=(0,fe.useMemo)(()=>{let F={};for(let V of C)if(!V.editing)for(let re of V.cards)(F[re]??=[]).push(V.name);return F},[C]),L=(0,fe.useCallback)(async(F,V)=>{let re=a.cards.find(K=>K.id===F);re===void 0||re.stage===V||w(await Xa(`${a.flow.href}/cards/${F}/move`,{stage:V},t))},[a,t,w]),I=(0,fe.useMemo)(()=>x.map(F=>({id:F.id,type:"zone",position:{x:F.zone.x,y:F.zone.y},width:F.zone.w,height:F.zone.h,style:{width:F.zone.w,height:F.zone.h},draggable:n,selectable:n,data:{stage:F,kindLabel:a.kinds.find(V=>V.kind===F.kind)?.label??F.kind,owner:s?.owner??a.flow.owner,teammate:F.teammate===void 0?null:a.teammates?.find(V=>V.handle===F.teammate)?.name??F.teammate,cards:a.cards.filter(V=>V.stage===F.id&&V.state==="active"&&(!g||V.mine)),hidden:g?a.cards.filter(V=>V.stage===F.id&&V.state==="active"&&!V.mine).length:0,lookers:S,editing:n,canMove:a.canEdit,start:F.id===y,selectedCard:l!==null&&"card"in l?l.card:null,onCard:V=>{p(!1),c({card:V})},onDrop:(V,re)=>{L(V,re)},onResize:(V,re)=>i(K=>K===null?K:{...K,stages:K.stages.map(Le=>Le.id===V?{...Le,zone:{...Le.zone,x:Math.round(re.x),y:Math.round(re.y),w:Math.round(re.width),h:Math.round(re.height)}}:Le)})}})),[x,a,n,l,y,L,g,S]),R=(0,fe.useMemo)(()=>a.triggers.filter(F=>F.state!=="removed"),[a.triggers]),P=(0,fe.useMemo)(()=>{let F=new Map;for(let V of R){let re=x.some(K=>K.id===V.zoneId)?V.zoneId:y;F.set(re,[...F.get(re)??[],V])}return[...F].flatMap(([V,re])=>{let K=x.find(De=>De.id===V);if(K===void 0)return[];let Le=YO+re.length*XO;return[{id:`trigger-${V}`,type:"trigger",position:{x:K.zone.x-272,y:K.zone.y+Math.max(0,(K.zone.h-Le)/2)},width:236,height:Le,style:{width:236,height:Le},draggable:!1,selectable:!1,data:{triggers:re,onOpen:De=>c({triggers:De}),onPress:De=>c({press:De})}}]})},[R,x,y]),O=R.map(F=>`${F.id}:${F.zoneId}`).join(","),B=(0,fe.useRef)(O);(0,fe.useEffect)(()=>{if(B.current===O)return;B.current=O;let F=requestAnimationFrame(()=>{b.fitView({padding:.12,minZoom:.55,maxZoom:1,duration:250})});return()=>cancelAnimationFrame(F)},[O,b]);let z=(0,fe.useMemo)(()=>[...I,...P],[I,P]),[N,M]=(0,fe.useState)(z);(0,fe.useEffect)(()=>{M(F=>z.map(V=>{let re=F.find(K=>K.id===V.id);return re===void 0?V:{...re,...V,...re.measured===void 0?{}:{measured:re.measured},selected:n&&re.selected===!0}}))},[z,n]);let T=(0,fe.useMemo)(()=>{let F=K=>({x:K.zone.x+K.zone.w/2,y:K.zone.y+K.zone.h/2}),V=(K,Le,De)=>{let xt=F(K),ot=F(Le),Ht=ot.x-xt.x,$e=ot.y-xt.y,Je=Math.abs(Ht)>=Math.abs($e);if(De){let Aa=Le.zone.x>=K.zone.x+K.zone.w||K.zone.x>=Le.zone.x+Le.zone.w,Lt=Le.zone.y>=K.zone.y+K.zone.h||K.zone.y>=Le.zone.y+Le.zone.h;return Aa&&Lt?Ht>=0?{source:"s-Right",target:"t-Left"}:{source:"s-Left",target:"t-Right"}:Je?{source:"s-Bottom",target:"t-Bottom"}:{source:"s-Left",target:"t-Left"}}return Je?Ht>=0?{source:"s-Right",target:"t-Left"}:{source:"s-Left",target:"t-Right"}:$e>=0?{source:"s-Bottom",target:"t-Top"}:{source:"s-Top",target:"t-Bottom"}},re=P.map(K=>({id:`${K.id}->zone`,source:K.id,sourceHandle:"out",target:K.id.slice(8),targetHandle:"t-Left",type:"smoothstep",animated:K.data.triggers.some(Le=>Le.state==="active"),deletable:!1,markerEnd:{type:Ko.ArrowClosed},style:{strokeWidth:1.5}}));return GX([...re,...x.flatMap(K=>{let Le=K.next===null?void 0:x.find($e=>$e.id===K.next),De=K.onFail===null?void 0:x.find($e=>$e.id===K.onFail),xt=K.limit?.to==null?void 0:x.find($e=>$e.id===K.limit.to),ot=K.kind==="sort"&&K.sort!==null?K.sort.answers:K.kind==="check"||K.kind==="teammate"?K.routes??[]:[],Ht=ot.length>0?[...new Set(ot.map($e=>$e.to))].flatMap($e=>{let Je=x.find(Lt=>Lt.id===$e);if(Je===void 0)return[];let Aa=Je.zone.x>K.zone.x+K.zone.w?{source:"s-Right",target:"t-Left"}:V(K,Je,!1);return[{id:`${K.id}->answer-${$e}`,source:K.id,target:$e,sourceHandle:Aa.source,targetHandle:Aa.target,type:"smoothstep",label:ot.filter(Lt=>Lt.to===$e).map(Lt=>Lt.answer).join(", "),labelStyle:{fontSize:11,fontWeight:600,fill:"var(--color-foreground)"},labelBgStyle:{fill:"var(--color-card)"},markerEnd:{type:Ko.ArrowClosed},style:{strokeWidth:2},deletable:!1}]}):[];return[...Ht,...Le===void 0?[]:[{id:`${K.id}->next`,source:K.id,target:Le.id,sourceHandle:V(K,Le,!1).source,targetHandle:V(K,Le,!1).target,type:"smoothstep",markerEnd:{type:Ko.ArrowClosed},style:{strokeWidth:2},deletable:n,...K.kind==="wait"&&K.wait?.for==="reply"?{label:"replied",labelStyle:{fontSize:11,fontWeight:600,fill:"var(--color-foreground)"},labelBgStyle:{fill:"var(--color-card)"}}:{}}],...De===void 0||!n&&Ht.some($e=>$e.target===De.id)?[]:[{id:`${K.id}->fail`,source:K.id,target:De.id,sourceHandle:V(K,De,!0).source,targetHandle:V(K,De,!0).target,type:"smoothstep",pathOptions:{offset:28,borderRadius:10},label:K.kind==="approval"?"sent back":K.kind==="sort"?"not sure":K.kind==="wait"?"no reply":"fails",labelStyle:{fontSize:11,fill:(K.kind==="wait","var(--color-muted-foreground)")},labelBgStyle:{fill:"var(--color-card)"},markerEnd:{type:Ko.ArrowClosed,color:(K.kind==="wait","var(--color-muted-foreground)")},style:{strokeWidth:1.5,strokeDasharray:"6 4",stroke:(K.kind==="wait","var(--color-muted-foreground)")},deletable:n}],...xt===void 0||K.limit===void 0?[]:[{id:`${K.id}->limit`,source:K.id,target:xt.id,sourceHandle:V(K,xt,!0).source,targetHandle:V(K,xt,!0).target,type:"smoothstep",pathOptions:{offset:36,borderRadius:10},label:`after ${YX(K.limit.minutes)}`,labelStyle:{fontSize:11,fill:"var(--color-muted-foreground)"},labelBgStyle:{fill:"var(--color-card)"},markerEnd:{type:Ko.ArrowClosed,color:"var(--color-muted-foreground)"},style:{strokeWidth:1.5,strokeDasharray:"2 4",stroke:"var(--color-muted-foreground)"},deletable:n}]]})],x)},[x,n,P,y]),A=(F,V)=>i(re=>re===null?re:{...re,stages:re.stages.map(K=>K.id===F?{...K,...V}:K)}),H=F=>{if(M(V=>Kw(F,V)),!!n)for(let V of F)V.type==="select"&&V.selected&&!V.id.startsWith("trigger-")&&c({zone:V.id})},U=(F,V)=>{!n||V.type!=="zone"||i(re=>re===null?re:{...re,stages:re.stages.map(K=>K.id===V.id?{...K,zone:{...K.zone,x:Math.round(V.position.x),y:Math.round(V.position.y)}}:K)})},_=F=>{if(!n||F.source===F.target)return;let V=x.find(re=>re.id===F.source);if(V?.kind==="sort"&&V.sort!==null&&F.sourceHandle!=="fail"){let re=x.find(K=>K.id===F.target);re!==void 0&&V.sort.answers.length<12&&A(V.id,{sort:{...V.sort,answers:[...V.sort.answers,{answer:re.title.slice(0,40),means:re.title,to:re.id}]}}),c({zone:V.id});return}A(F.source,F.sourceHandle==="fail"?{onFail:F.target}:{next:F.target})},W=()=>{i({name:a.flow.name,start:a.start,stages:a.stages,owner:a.flow.owner}),r(!0),c(null)},$=()=>{i(null),r(!1),c(null)},ie=async()=>{if(s===null)return;u(!0);let F=await Xa(`${a.flow.href}/save`,{name:s.name,owner:s.owner,revision:String(a.flow.revision),definition:JSON.stringify({version:1,start:s.start,stages:s.stages})},t);u(!1),w(F),F.ok&&(i(null),r(!1),c(null))},te=()=>{if(s===null)return;let F=new Set(s.stages.map(K=>K.id)),V=b.screenToFlowPosition({x:window.innerWidth/2,y:window.innerHeight/2}),re={id:XX("New zone",F),title:"New zone",kind:"inbox",zone:{x:Math.round(V.x-140),y:Math.round(V.y-120),w:280,h:300,color:"slate"},instructions:null,planning:null,approver:null,message:null,close:null,script:null,sort:null,next:null,onFail:null};i({...s,stages:[...s.stages,re]}),c({zone:re.id})},ae=l!==null&&"card"in l?a.cards.find(F=>F.id===l.card)??null:null,D=l!==null&&"press"in l?a.triggers.find(F=>F.id===l.press&&F.button!==null)??null:null,J=l!==null&&"triggers"in l&&!n,q=l!==null&&"scripts"in l,j=l!==null&&"insights"in l&&!n,le=l!==null&&"zone"in l?x.find(F=>F.id===l.zone)??null:null,ce=a.cards.filter(F=>F.canDecide).length;return(0,m.jsxs)("div",{className:"flex h-[calc(100dvh-7.5rem)] min-h-[560px] flex-col overflow-hidden rounded-xl border bg-card","data-flow":a.flow.id,children:[(0,m.jsxs)("div",{className:"flex flex-wrap items-center gap-2 border-b px-4 py-2.5",children:[n&&s!==null?(0,m.jsx)(Se,{value:s.name,onChange:F=>i({...s,name:F.target.value}),maxLength:80,className:"h-8 max-w-64 font-semibold","aria-label":"Flow name"}):(0,m.jsx)("h1",{className:"text-[15px] font-semibold",children:a.flow.name}),(0,m.jsx)("span",{className:"text-[12px] text-muted-foreground",children:a.flow.project}),(0,m.jsx)(jO,{others:C,cards:a.cards}),n&&s!==null&&(0,m.jsxs)("label",{className:"inline-flex items-center gap-1.5 text-[12px] text-muted-foreground",children:["Owner",(0,m.jsx)("select",{className:"h-8 rounded-md border bg-transparent px-2 text-[12px] text-foreground",value:s.owner,onChange:F=>i({...s,owner:F.target.value}),"aria-label":"Flow owner",children:[...new Set([s.owner,...a.approvers])].map(F=>(0,m.jsx)("option",{value:F,children:F===a.me?`${F} (you)`:F},F))})]}),ce>0&&!n&&(0,m.jsxs)(Bt,{tone:"attention",children:[ce," waiting for you"]}),!n&&(0,m.jsx)("div",{className:"ml-1 inline-flex rounded-md border p-0.5",role:"group","aria-label":"Which cards",children:[["All cards",!1],["Mine",!0]].map(([F,V])=>(0,m.jsx)("button",{type:"button","aria-pressed":g===V,onClick:()=>v(V),className:ue("rounded px-2 py-1 text-[12px] font-medium",g===V?"bg-muted text-foreground":"text-muted-foreground hover:text-foreground"),children:F},F))}),(0,m.jsx)("span",{className:"flex-1"}),n?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsxs)(oe,{size:"sm",variant:"ghost",onClick:()=>c({scripts:!0}),children:[(0,m.jsx)(vs,{className:"size-4"}),"Scripts"]}),(0,m.jsxs)(oe,{size:"sm",variant:"outline",onClick:te,children:[(0,m.jsx)(ta,{className:"size-4"}),"Add zone"]}),(0,m.jsx)(oe,{size:"sm",variant:"ghost",onClick:$,children:"Discard"}),(0,m.jsx)(oe,{size:"sm",onClick:()=>{ie()},disabled:!h||f,children:f?"Saving…":"Save flow"})]}):(0,m.jsxs)(m.Fragment,{children:[(0,m.jsxs)(oe,{size:"sm",variant:"ghost",onClick:()=>{p(!1),c({insights:!0})},"data-open-insights":!0,children:[(0,m.jsx)(Fn,{className:"size-4"}),"Insights"]}),(0,m.jsxs)(oe,{size:"sm",variant:"ghost",onClick:()=>{p(!1),c({scripts:!0})},"data-open-scripts":!0,children:[(0,m.jsx)(vs,{className:"size-4"}),"Scripts"]}),a.canEdit&&(0,m.jsxs)(oe,{size:"sm",variant:"ghost",onClick:()=>{p(!1),c({triggers:null})},"data-open-triggers":!0,children:[(0,m.jsx)(Cs,{className:"size-4"}),"Triggers",R.length>0?` · ${R.length}`:""]}),a.canEdit&&(0,m.jsx)(oe,{size:"sm",variant:"ghost",asChild:!0,children:(0,m.jsxs)("a",{href:a.chatHref,children:[(0,m.jsx)(qn,{className:"size-4"}),"Change in chat"]})}),a.canEdit&&(0,m.jsxs)(oe,{size:"sm",variant:"outline",onClick:W,children:[(0,m.jsx)(qd,{className:"size-4"}),"Edit flow"]}),a.canEdit&&(0,m.jsxs)(oe,{size:"sm",onClick:()=>{c(null),p(!0)},children:[(0,m.jsx)(ta,{className:"size-4"}),"New card"]})]})]}),(0,m.jsxs)("div",{className:"relative flex min-h-0 flex-1",children:[(0,m.jsxs)("div",{className:"relative min-w-0 flex-1","data-flow-canvas":!0,children:[(0,m.jsxs)(_O,{nodes:N,edges:T,nodeTypes:qX,edgeTypes:VX,onNodesChange:H,onNodeDragStop:U,onConnect:_,onEdgesDelete:F=>{for(let V of F)A(V.source,V.id.endsWith("->fail")?{onFail:null}:V.id.endsWith("->limit")?{limit:{...s?.stages.find(re=>re.id===V.source)?.limit??{minutes:1440},to:null}}:{next:null})},onPaneClick:()=>{n&&c(null)},onNodeClick:()=>{},nodesDraggable:n,nodesConnectable:n,elementsSelectable:n,fitView:!0,fitViewOptions:{padding:.12,minZoom:.55,maxZoom:1},minZoom:.3,maxZoom:1.5,proOptions:{hideAttribution:!0},deleteKeyCode:n?["Backspace","Delete"]:null,children:[(0,m.jsx)(OO,{variant:Qn.Dots,gap:20,size:1}),(0,m.jsx)(zO,{showInteractive:!1})]}),n&&(0,m.jsx)("p",{className:"pointer-events-none absolute bottom-3 left-14 max-w-md rounded-lg bg-foreground/85 px-3 py-1.5 text-[12px] text-background",children:"Drag zones to arrange them. Drag from a zone's right dot to say where work goes next, from its bottom dot for where it goes if sent back."})]}),le!==null&&n||ae!==null||d&&!n||J||D!==null||q||j?(0,m.jsx)("aside",{className:"absolute inset-y-0 right-0 z-10 w-[360px] max-w-full overflow-y-auto border-l bg-card p-4 shadow-xl","data-flow-drawer":!0,children:le!==null&&n?(0,m.jsx)(sY,{stage:le,stages:x,view:a,csrf:t,apply:w,update:F=>A(le.id,F),remove:()=>{i(F=>F===null?F:{...F,start:F.start===le.id?F.stages.find(V=>V.id!==le.id).id:F.start,stages:F.stages.filter(V=>V.id!==le.id).map(V=>({...V,next:V.next===le.id?null:V.next,onFail:V.onFail===le.id?null:V.onFail}))}),c(null)},makeStart:()=>i(F=>F===null?F:{...F,start:le.id}),onClose:()=>c(null)}):q?(0,m.jsx)(mY,{view:a,csrf:t,apply:w,onClose:()=>c(null)}):j?(0,m.jsx)(gY,{view:a,onClose:()=>c(null)}):D!==null?(0,m.jsx)(nB,{trigger:D,view:a,csrf:t,apply:w,onClose:()=>c(null)},D.id):J?(0,m.jsx)(pY,{view:a,csrf:t,apply:w,focus:l!==null&&"triggers"in l?l.triggers:null,onPress:F=>c({press:F}),onClose:()=>c(null)}):ae!==null?(0,m.jsx)(WO,{card:ae,view:a,csrf:t,apply:w,onClose:()=>c(null)}):(0,m.jsx)(eB,{view:a,csrf:t,apply:F=>{w(F),F.ok&&p(!1)},onClose:()=>p(!1)})}):null]})]})}function vY({view:e,csrf:t}){let[a,o]=(0,fe.useState)(e),[n,r]=(0,fe.useState)(e.selectedCard),[s,i]=(0,fe.useState)(e.startTrigger),l=p=>{(p.ok?lo.success:lo.error)(p.said),p.view!==void 0&&o(p.view)},c=GO(a,o,{card:n,editing:!1}),f=n===null?null:a.cards.find(p=>p.id===n)??null,u=s===null?null:a.triggers.find(p=>p.id===s&&p.button!==null&&p.state==="active")??null,d=a.triggers.filter(p=>p.state!=="removed");return u!==null?(0,m.jsx)("div",{className:"p-4",children:(0,m.jsx)(nB,{trigger:u,view:a,csrf:t,apply:l,onClose:()=>i(null)})}):f!==null?(0,m.jsx)("div",{className:"p-4",children:(0,m.jsx)(WO,{card:f,view:a,csrf:t,apply:l,onClose:()=>r(null)})}):(0,m.jsxs)("div",{className:"flex flex-col gap-3 p-4","data-flow":a.flow.id,children:[(0,m.jsxs)("div",{children:[(0,m.jsx)("h1",{className:"text-[17px] font-semibold",children:a.flow.name}),(0,m.jsxs)("p",{className:"text-[12px] text-muted-foreground",children:[a.flow.project,a.canEdit?(0,m.jsxs)(m.Fragment,{children:[" · ",(0,m.jsx)("a",{className:"underline",href:a.chatHref,children:"change it in chat"}),", or edit it on a larger screen"]}):null]}),c.length>0&&(0,m.jsx)("div",{className:"mt-1.5",children:(0,m.jsx)(jO,{others:c,cards:a.cards})})]}),a.canEdit&&d.some(p=>p.button!==null&&p.state==="active")&&(0,m.jsx)("div",{className:"flex flex-wrap gap-2",children:d.filter(p=>p.button!==null&&p.state==="active").map(p=>(0,m.jsxs)(oe,{size:"sm",onClick:()=>i(p.id),children:[(0,m.jsx)(Nu,{className:"size-4"}),p.button.label]},p.id))}),a.canEdit&&(0,m.jsxs)("details",{className:"rounded-lg border p-3",children:[(0,m.jsx)("summary",{className:"cursor-pointer text-[14px] font-semibold",children:"New card"}),(0,m.jsx)("div",{className:"pt-3",children:(0,m.jsx)(eB,{view:a,csrf:t,apply:l})})]}),jX(a.stages,a.start).map(p=>{let g=a.cards.filter(v=>v.stage===p.id&&v.state==="active");return(0,m.jsxs)("section",{className:"rounded-lg border bg-muted/40",children:[(0,m.jsxs)("header",{className:"flex items-center gap-2 px-3 py-2",children:[(0,m.jsx)("span",{className:"inline-flex size-6 items-center justify-center rounded-md text-white",style:{background:qf[p.zone.color]??"#64748b"},children:UO[p.kind]}),(0,m.jsx)("span",{className:"flex-1 text-[14px] font-semibold",children:p.title}),g.length>0&&(0,m.jsx)("span",{className:"text-[12px] text-muted-foreground",children:g.length})]}),g.length>0&&(0,m.jsx)("ul",{className:"flex flex-col gap-2 px-3 pb-3",children:g.map(v=>(0,m.jsx)("li",{children:(0,m.jsxs)("button",{type:"button",onClick:()=>r(v.id),className:ue("min-h-11 w-full rounded-lg border bg-card px-3 py-2 text-left",v.canDecide&&"border-attention/60"),children:[(0,m.jsxs)("div",{className:"flex items-start gap-2",children:[(0,m.jsx)("div",{className:"min-w-0 flex-1 text-[14px] font-medium",children:v.title}),v.owner!==null&&(0,m.jsx)(Vs,{name:v.owner})]}),v.sorted!==null&&(0,m.jsx)("div",{className:"mt-1 flex",children:(0,m.jsx)(tC,{sorted:v.sorted})}),v.waiting!==null&&(0,m.jsx)("div",{className:ue("text-[12px]",v.canDecide?"font-semibold text-attention":"text-muted-foreground"),children:v.canDecide?"Needs your decision":v.waiting}),v.comments.length>0&&(0,m.jsxs)("div",{className:"mt-0.5 inline-flex items-center gap-1 text-[12px] text-muted-foreground",children:[(0,m.jsx)(qn,{className:"size-3","aria-hidden":"true"}),v.comments.length]})]})},v.id))})]},p.id)}),d.length>0&&(0,m.jsxs)("section",{className:"rounded-lg border p-3","data-flow-triggers":!0,children:[(0,m.jsx)("h2",{className:"text-[14px] font-semibold",children:"Triggers"}),(0,m.jsx)("ul",{className:"mt-2 flex flex-col gap-2",children:d.map(p=>(0,m.jsxs)("li",{className:"text-[13px]",children:[(0,m.jsx)("span",{className:"font-medium",children:p.name})," · ",p.detail,(0,m.jsx)("div",{className:ue("text-[12px]",p.failing?"text-warning":"text-muted-foreground"),children:p.state==="paused"?"Paused":p.status===null?`Starts in ${p.zone}`:`${tB(p.statusAt)}: ${p.status}`})]},p.id))})]})]})}function rB({view:e,csrf:t}){let a=(0,fe.useRef)(typeof window<"u"&&window.matchMedia("(max-width: 767px)").matches),[o,n]=(0,fe.useState)(a.current);return(0,fe.useEffect)(()=>{let r=window.matchMedia("(max-width: 767px)"),s=()=>n(r.matches);return r.addEventListener("change",s),()=>r.removeEventListener("change",s)},[]),o?(0,m.jsx)(vY,{view:e,csrf:t}):(0,m.jsx)(Jw,{children:(0,m.jsx)(xY,{view:e,csrf:t})})}var Gs=X(pe(),1);function sB({view:e,csrf:t}){return(0,Gs.jsx)("div",{"data-view":e.kind,className:"w-full",children:e.kind==="tasks"?(0,Gs.jsx)(TA,{view:e}):e.kind==="settings"?(0,Gs.jsx)(LA,{view:e,csrf:t}):e.kind==="task"?(0,Gs.jsx)(NA,{view:e}):e.kind==="projects"?(0,Gs.jsx)(fA,{view:e,csrf:t}):e.kind==="result"?(0,Gs.jsx)(mA,{view:e,csrf:t}):e.kind==="flow"?(0,Gs.jsx)(rB,{view:e,csrf:t}):null})}function iB(e){return e.security?`Toolroll ${e.version} is available, with security fixes`:`Toolroll ${e.version} is available`}var E=X(pe(),1);function Jo({name:e}){return(0,E.jsx)("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",width:"20",height:"20",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:{menu:(0,E.jsx)("path",{d:"M4 6h16M4 12h16M4 18h16"}),chat:(0,E.jsx)("path",{d:"M5 4h14a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H9l-6 3V6a2 2 0 0 1 2-2Z"}),tasks:(0,E.jsx)(E.Fragment,{children:(0,E.jsx)("path",{d:"m3 6 2 2 4-4m-6 9 2 2 4-4m-6 9 2 2 4-4M13 6h8M13 13h8M13 20h8"})}),flows:(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)("rect",{width:"8",height:"8",x:"3",y:"3",rx:"2"}),(0,E.jsx)("path",{d:"M7 11v4a2 2 0 0 0 2 2h4"}),(0,E.jsx)("rect",{width:"8",height:"8",x:"13",y:"13",rx:"2"})]}),projects:(0,E.jsx)("path",{d:"M3 7V5a2 2 0 0 1 2-2h5l3 4h6a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7Z"}),knowledge:(0,E.jsx)("path",{d:"M12 5c-3-2-7-2-10-1v15c3-1 7-1 10 1 3-2 7-2 10-1V4c-3-1-7-1-10 1Zm0 0v15"}),settings:(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)("path",{d:"M4 6h16M4 12h16M4 18h16"}),(0,E.jsx)("path",{d:"M8 3v6M16 9v6M10 15v6"})]}),arrow:(0,E.jsx)("path",{d:"m10 6-6 6 6 6M4 12h16"}),close:(0,E.jsx)("path",{d:"m6 6 12 12M6 18 18 6"}),send:(0,E.jsx)("path",{d:"m12 19 0-14m-6 6 6-6 6 6"}),tools:(0,E.jsx)(E.Fragment,{children:(0,E.jsx)("path",{d:"M4 4h6v6H4zM14 4h6v6h-6zM4 14h6v6H4zM14 14h6v6h-6z"})}),plus:(0,E.jsx)("path",{d:"M12 5v14M5 12h14"})}[e]})}function oC(){try{return window.sessionStorage}catch{return{getItem:()=>null,removeItem:()=>{},setItem:()=>{throw new Error("Storage unavailable")}}}}function nC(e){let t=e.conversation;return t?{user:e.user,session:t.sessionId,task:t.taskId??(t.project?`project:${t.project}`:null)}:null}function lB(){return!document.hidden&&navigator.onLine!==!1}var yY=new Set(["/work","/board","/queue","/workbench","/code"]);function bY(e){let[t,a]=(0,Te.useState)(e),o=nC(e),[n,r]=(0,Te.useState)(()=>{let B=e.conversation&&o?gR(oC(),o,e.conversation.requestId,e.conversation.maxChars):Km(""),z=e.conversation?new URLSearchParams(window.location.search).get("draft"):null;return z&&B.text===""&&B.pending===null?{...B,text:z.slice(0,e.conversation.maxChars)}:B});(0,Te.useEffect)(()=>{let B=new URL(window.location.href);B.searchParams.has("draft")&&(B.searchParams.delete("draft"),window.history.replaceState(window.history.state,"",B.pathname+B.search+B.hash))},[]);let[s,i]=(0,Te.useState)(""),[l,c]=(0,Te.useState)(!0),[f,u]=(0,Te.useState)(!1),[d,p]=(0,Te.useState)(!1),[g,v]=(0,Te.useState)(()=>navigator.onLine===!1),b=(0,Te.useRef)({workspace:t,draft:n,stale:d,sending:f,notice:s});b.current={workspace:t,draft:n,stale:d,sending:f,notice:s};let x=(0,Te.useRef)(!1),y=(0,Te.useRef)(!1),h=(0,Te.useRef)(void 0),w=(0,Te.useRef)(null),C=(0,Te.useRef)(5e3),S=(0,Te.useRef)(!0),L=(0,Te.useRef)(!1),I=(0,Te.useCallback)(B=>{b.current.draft=B,r(B);let z=nC(e);z&&c(xR(oC(),z,B))},[e]),R=(0,Te.useCallback)(async(B=!0)=>{if(!S.current||b.current.stale||!(e.conversation||e.refreshSeconds)||!lB())return;if(x.current){B&&(y.current=!0);return}y.current=!1,clearTimeout(h.current),B&&(C.current=5e3),x.current=!0;let z=b.current.draft.pending?.request??null,N=!1;try{let M=await kR(b.current.workspace,z,fetch,{etag:w.current,force:B});if(!S.current)return;if(w.current=z?null:M.etag,M.kind==="unchanged"){N=!0,!b.current.draft.pending&&b.current.notice&&i("");return}let T=M.workspace;if(!SR(e,T)){b.current.stale=!0,p(!0),i("This conversation changed or ended. Reconnect to continue with your draft.");return}let A=wR(b.current.draft,z,T.receipt);A!==b.current.draft&&I(A),b.current.workspace=T,a(T),i(A.pending?"Delivery is not confirmed. Check again before sending another message.":"")}catch(M){if(!S.current)return;M instanceof yr&&(b.current.stale=!0,p(!0)),i(M instanceof Error?M.message:"Updates are unavailable. Your work is still saved.")}finally{if(x.current=!1,S.current&&!b.current.stale&&lB())if(y.current)y.current=!1,R(!0);else{let M=b.current.draft.pending!==null||b.current.workspace.conversation?.pendingTurnId!=null||L.current;C.current=e.conversation?LR(C.current,N,M):e.refreshSeconds*1e3,h.current=window.setTimeout(()=>{R(!1)},C.current)}}},[e,I]);(0,Te.useEffect)(()=>{if(S.current=!0,!e.conversation&&!e.refreshSeconds)return;e.conversation?R():h.current=window.setTimeout(()=>{R(!1)},e.refreshSeconds*1e3);let B=()=>{document.hidden?clearTimeout(h.current):R(!0)},z=()=>{v(!1),R()},N=()=>{v(!0),clearTimeout(h.current)};return document.addEventListener("visibilitychange",B),window.addEventListener("online",z),window.addEventListener("offline",N),()=>{S.current=!1,clearTimeout(h.current),document.removeEventListener("visibilitychange",B),window.removeEventListener("online",z),window.removeEventListener("offline",N)}},[R,e.conversation,e.refreshSeconds]);let P=async B=>{B.preventDefault();let z=b.current;if(L.current||z.stale||navigator.onLine===!1||z.draft.pending||z.workspace.conversation?.pendingTurnId!==null||!z.draft.text.trim())return;let N=bR(z.draft);if(N.pending){L.current=!0,u(!0),I(N),i("");try{let M=await IR(z.workspace,N.pending);if(!S.current)return;M.refused?(I(CR(b.current.draft,N.pending.request)),i(M.message??"Message not sent. Your draft is saved.")):(i("Checking delivery…"),R())}catch(M){if(!S.current)return;M instanceof yr&&(b.current.stale=!0,p(!0)),i(M instanceof yr?M.message:"Delivery is not confirmed. Check again before sending another message."),R()}finally{L.current=!1,S.current&&u(!1)}}},O=()=>{let B=nC(e);B&&vR(oC(),B,b.current.draft.text),window.location.reload()};return(0,Te.useEffect)(()=>{let B=N=>{let M=N.target;if(!(M instanceof HTMLFormElement)||M.dataset.workspaceComposer!==void 0||M.getAttribute("action")!=="/chat")return;let T=b.current;if(!T.workspace.conversation)return;if(T.stale||L.current||T.draft.pending||navigator.onLine===!1||T.workspace.conversation.pendingTurnId!==null){N.preventDefault(),i("Wait for the current message before sending another.");return}if(M.getAttribute("aria-busy")==="true"){N.preventDefault();return}let A=(H,U)=>{if(M.querySelector(`[name="${H}"]`))return;let _=document.createElement("input");_.type="hidden",_.name=H,_.value=U,M.append(_)};A("request",T.workspace.conversation.requestId),A("request-session",String(T.workspace.conversation.sessionId)),T.workspace.conversation.taskId&&A("task",T.workspace.conversation.taskId),T.workspace.conversation.resultRunId!==null&&A("result",String(T.workspace.conversation.resultRunId)),!N.defaultPrevented&&(L.current=!0,M.setAttribute("aria-busy","true"))},z=()=>{L.current=!1,document.querySelectorAll('form[action="/chat"][aria-busy="true"]:not([data-workspace-composer])').forEach(N=>N.removeAttribute("aria-busy")),R()};return document.addEventListener("submit",B),window.addEventListener("pageshow",z),()=>{document.removeEventListener("submit",B),window.removeEventListener("pageshow",z)}},[R]),{workspace:t,draft:n,notice:s,storageAvailable:l,sending:f,stale:d,offline:g,send:P,check:R,reconnect:O,edit:B=>I(yR(b.current.draft,B))}}function hB(e){return e==="problem"?"danger":e==="attention"?"attention":e==="done"||e==="ready"?"success":e==="live"?"info":"neutral"}function uB({workspace:e,items:t}){return(0,E.jsx)("ul",{className:"so-work-list",children:t.map(a=>(0,E.jsxs)("li",{"data-workspace-task":a.id,"data-work-status":a.state,children:[(0,E.jsxs)("a",{className:"so-work-row",href:a.resultHref??a.href,"aria-current":e.focus?.id===a.id?"page":void 0,children:[(0,E.jsxs)("div",{className:"so-work-heading",children:[(0,E.jsx)("span",{className:"so-work-title",children:a.title}),(0,E.jsx)(Lu,{tone:hB(a.tone),children:a.label})]}),a.project&&(0,E.jsx)("span",{className:"so-work-project",children:e.projects.find(o=>o.path===a.project)?.name??a.project.split(/[\\/]/).filter(Boolean).pop()})]}),a.action&&a.action.href!==(a.resultHref??a.href)&&(0,E.jsx)("a",{className:"so-work-action",href:a.action.href,children:a.action.label})]},a.id))})}function cB({workspace:e}){let t=n=>n.tone==="done"||n.state==="cancelled",a=e.crew.filter(n=>!t(n)),o=e.crew.filter(t);return(0,E.jsxs)("section",{className:"so-crew","aria-labelledby":"crew-title","data-workspace-crew":!0,children:[(0,E.jsxs)("div",{className:"so-section-heading",children:[(0,E.jsx)("h2",{id:"crew-title",children:"Crew"}),(0,E.jsx)("a",{href:"/work",children:"All tasks"})]}),e.crew.length===0?(0,E.jsxs)("div",{className:"so-crew-empty",children:[(0,E.jsx)("p",{children:"No tasks yet."}),(0,E.jsx)("p",{children:"Work you start with the lead appears here."})]}):(0,E.jsxs)(E.Fragment,{children:[a.length>0?(0,E.jsx)(uB,{workspace:e,items:a}):(0,E.jsx)("p",{className:"so-crew-quiet",children:"Nothing is running or waiting on you."}),o.length>0&&(0,E.jsx)(dn,{summary:`Finished (${o.length}${e.crewTruncated?"+":""})`,className:"so-crew-finished",children:(0,E.jsx)(uB,{workspace:e,items:o.slice(0,8)})})]}),e.crewTruncated&&(0,E.jsx)("a",{className:"so-all-work",href:"/work",children:"View more tasks"})]})}function gB({workspace:e}){let t=(0,Te.useId)(),a=e.projects.find(o=>new URL(e.path,window.location.origin).searchParams.get("project")===o.path||new URL(e.path,window.location.origin).searchParams.get("repo")===o.path||e.crew.find(n=>n.id===e.focus?.id)?.project===o.path);return(0,E.jsxs)("div",{className:"so-navigation-content",children:[(0,E.jsxs)("a",{href:"/chat",className:"so-wordmark",children:[(0,E.jsxs)("span",{className:"so-brand-mark","aria-hidden":"true",children:[(0,E.jsx)("i",{}),(0,E.jsx)("i",{}),(0,E.jsx)("i",{})]}),"Toolroll"]}),(0,E.jsxs)("a",{href:"/tasks/new",className:"so-new-task",children:[(0,E.jsx)(Jo,{name:"plus"}),"New task"]}),e.projects.length>0&&(0,E.jsxs)("div",{className:"so-project-switch",children:[(0,E.jsx)(Si,{htmlFor:t,children:"Project"}),(0,E.jsxs)("select",{id:t,value:a?.href??"/work",onChange:o=>{window.location.assign(o.target.value)},children:[(0,E.jsx)("option",{value:"/work",children:"All projects"}),e.projects.map(o=>(0,E.jsx)("option",{value:o.href,children:o.name},o.path))]})]}),(0,E.jsx)("nav",{"aria-label":"Workspace",className:"so-primary-navigation",children:e.navigation.filter(o=>o.href!=="/menu").map(o=>{let n=o.label.toLowerCase();return(0,E.jsxs)("a",{href:o.href,"aria-current":o.active?"page":void 0,children:[(0,E.jsx)(Jo,{name:["chat","tasks","flows","projects","knowledge","settings"].includes(n)?n:"tools"}),(0,E.jsx)("span",{children:o.label}),o.count!==void 0&&o.count>0&&(0,E.jsx)("span",{className:"so-nav-count","aria-label":`${o.count} ${o.count===1?"needs":"need"} you`,children:o.count})]},o.href)})}),a&&(0,E.jsxs)("div",{className:"so-project-links",children:[(0,E.jsx)("a",{className:"so-project-knowledge",href:`/chat?project=${encodeURIComponent(a.path)}`,children:"Project chat"}),(0,E.jsx)("a",{className:"so-project-knowledge",href:a.knowledgeHref,children:"Project knowledge"})]}),(e.chats?.length??0)>0&&(0,E.jsxs)("nav",{"aria-label":"Recent chats",className:"so-recent-chats",children:[(0,E.jsx)("p",{className:"so-recent-chats-label",children:"Recent chats"}),e.chats.map(o=>(0,E.jsxs)("a",{href:o.href,"aria-current":o.active?"page":void 0,title:o.title,children:[(0,E.jsx)("span",{className:"so-recent-chat-kind","aria-hidden":"true",children:o.kind==="task"?"Task":"Project"}),(0,E.jsx)("span",{className:"so-recent-chat-title",children:o.title})]},o.href))]}),(0,E.jsxs)("div",{className:"so-navigation-bottom",children:[(0,E.jsxs)("a",{href:"/menu","aria-current":e.navigation.find(o=>o.href==="/menu")?.active?"page":void 0,children:[(0,E.jsx)(Jo,{name:"tools"}),"Workspace tools"]}),(0,E.jsxs)("div",{className:"so-account",children:[(0,E.jsx)("span",{title:e.user,children:e.user}),(0,E.jsxs)("form",{method:"post",action:"/logout",children:[(0,E.jsx)("input",{type:"hidden",name:"csrf",value:e.csrf}),(0,E.jsx)(Be,{variant:"ghost",size:"sm",type:"submit",children:"Sign out"})]})]})]})]})}function wY(e,t=""){let a=[...e.navigation.map(n=>({label:n.label,detail:"Page",href:n.href})),...e.projects.map(n=>({label:n.name,detail:"Project",href:n.href})),...e.crew.map(n=>({label:n.title,detail:n.label,href:n.resultHref??n.href}))],o=new Set;return a.filter(n=>{let r=`${n.label}
|
|
65
|
+
How bad is it?`})})]}),r==="schedule"&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(he,{label:"When",hint:"For example: daily 09:00 Europe/London, monday 09:00, every 4 hours.",children:(0,m.jsx)(Se,{value:v("schedule"),onChange:b("schedule"),required:!0})}),(0,m.jsx)(he,{label:"Makes",children:(0,m.jsxs)("select",{className:gt,value:v("script")===""&&!c?"card":"script","aria-label":"Makes",onChange:h=>{f(h.target.value==="script"),l(w=>({...w,script:h.target.value==="script"?e.scripts[0]?.name??"":""}))},children:[(0,m.jsx)("option",{value:"card",children:"One card each time"}),(0,m.jsx)("option",{value:"script",children:"A card for each item a script prints"})]})}),v("script")!==""||c?e.scripts.length===0?(0,m.jsx)("p",{className:"text-[13px] text-muted-foreground",children:"This project has no scripts yet: make one with Scripts in the toolbar."}):(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(he,{label:"Script",hint:'It prints one item per line (a title, or JSON like {"title": "…", "key": 42}). The same item never makes two cards.',children:(0,m.jsx)("select",{className:gt,value:v("script"),onChange:b("script"),"aria-label":"Script",children:e.scripts.map(h=>(0,m.jsxs)("option",{value:h.name,children:[h.name," — ",h.about]},h.name))})}),(0,m.jsx)(he,{label:"Secrets it gets (optional)",hint:"Names of saved secrets, like CRM_KEY. Save them on a script zone's Secrets.",children:(0,m.jsx)(Se,{value:v("secrets"),onChange:b("secrets"),className:"font-mono",placeholder:"CRM_KEY",maxLength:400})})]}):(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(he,{label:"Card title",hint:"Each card's date is added to it.",children:(0,m.jsx)(Se,{value:v("title"),onChange:b("title"),placeholder:"Dependency check",maxLength:200,required:!0})}),(0,m.jsx)(he,{label:"Details (optional)",children:(0,m.jsx)(na,{rows:3,value:v("description"),onChange:b("description")})})]})]}),r==="github"&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(he,{label:"Repository",children:(0,m.jsx)(Se,{value:v("repo"),onChange:b("repo"),placeholder:"owner/name",required:!0})}),(0,m.jsx)(he,{label:"Watch",children:(0,m.jsxs)("select",{className:gt,value:v("watch"),onChange:b("watch"),children:[(0,m.jsx)("option",{value:"issues",children:"New issues"}),(0,m.jsx)("option",{value:"pulls",children:"New pull requests"}),(0,m.jsx)("option",{value:"checks",children:"Failed checks"})]})}),v("watch")!=="checks"&&(0,m.jsx)(he,{label:"Label (optional)",hint:v("watch")==="issues"?"With a label, an issue joins the moment it gets the label.":"Only pull requests with this label.",children:(0,m.jsx)(Se,{value:v("label"),onChange:b("label"),placeholder:"bug",maxLength:50})}),v("watch")==="checks"&&(0,m.jsx)(he,{label:"Branch",children:(0,m.jsx)(Se,{value:v("branch"),onChange:b("branch"),maxLength:100})}),v("watch")!=="checks"&&(0,m.jsx)(he,{label:"From",hint:v("from")==="anyone"?"Anyone who can open one there can write what the agent reads. The work still waits for your approval.":void 0,children:(0,m.jsxs)("select",{className:gt,value:v("from"),onChange:b("from"),children:[(0,m.jsx)("option",{value:"team",children:"People with write access"}),(0,m.jsx)("option",{value:"anyone",children:"Anyone"})]})})]}),r==="linear"&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(he,{label:"Team key",hint:"Like ENG. Name a team, a label, or both.",children:(0,m.jsx)(Se,{value:v("team"),onChange:b("team"),placeholder:"ENG",maxLength:12})}),(0,m.jsx)(he,{label:"When it moves to (optional)",children:(0,m.jsx)(Se,{value:v("state"),onChange:b("state"),placeholder:"Todo",maxLength:40})}),(0,m.jsx)(he,{label:"Label (optional)",children:(0,m.jsx)(Se,{value:v("label"),onChange:b("label"),placeholder:"bug",maxLength:50})})]}),(r==="github"||r==="linear")&&(0,m.jsx)(he,{label:"How it arrives",hint:v("delivery")==="webhook"?n.hooksBase===null?"Needs your public webhook address: set it under Settings below.":"You'll get an address to paste into "+(r==="github"?"GitHub.":"Linear."):r==="linear"&&!n.linearKey?"Save your Linear key under Settings below first.":void 0,children:(0,m.jsxs)("select",{className:gt,value:v("delivery"),onChange:b("delivery"),children:[(0,m.jsx)("option",{value:"poll",children:"Checked every 2 minutes"}),(0,m.jsx)("option",{value:"webhook",children:"Sent to a webhook address"})]})}),r==="flow"&&(n.otherFlows.length===0?(0,m.jsx)("p",{className:"text-[13px] text-muted-foreground",children:"There are no other flows to follow yet."}):(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(he,{label:"Flow",children:(0,m.jsx)("select",{className:gt,value:v("flow"),onChange:h=>l(w=>({...w,flow:h.target.value,when:""})),children:n.otherFlows.map(h=>(0,m.jsx)("option",{value:h.id,children:h.name},h.id))})}),(0,m.jsx)(he,{label:"When a card reaches",children:(0,m.jsxs)("select",{className:gt,value:v("when"),onChange:b("when"),children:[(0,m.jsx)("option",{value:"",children:"The end"}),x?.zones.map(h=>(0,m.jsx)("option",{value:h.id,children:h.title},h.id))]})})]})),r==="chat"&&(0,m.jsxs)("div",{className:"flex flex-col gap-2 rounded-md bg-muted px-2.5 py-2 text-[12.5px]","data-chat-connect":!0,children:[(0,m.jsx)("p",{children:"Connect a Slack, Discord or Teams channel, or a Telegram group, from the channel itself. Where Toolroll is, send:"}),(0,m.jsx)("p",{children:(0,m.jsxs)("code",{className:"rounded bg-background px-1.5 py-0.5 font-semibold",children:["flow ",e.flow.id]})}),(0,m.jsxs)("p",{className:"text-muted-foreground",children:["Each new message there becomes a card here, and replies in its thread join the card's discussion. “flow off” stops it. In Teams, mention Toolroll in each message. In Telegram, send /flow ",e.flow.id,", and turn the bot's privacy mode off in BotFather so it sees every message."]})]}),r==="email"&&(0,m.jsxs)(m.Fragment,{children:[n.mailbox===null?(0,m.jsxs)("p",{className:"rounded-md bg-muted px-2.5 py-2 text-[12.5px]","data-mailbox-missing":!0,children:["Reading mail isn't set up yet. Add your mail server's IMAP address, or sign in with Google, in ",(0,m.jsx)("a",{className:"underline",href:"/settings#email",children:"Settings → Email"}),"."]}):(0,m.jsxs)("p",{className:"text-[12.5px] text-muted-foreground",children:["New mail in ",n.mailbox," becomes cards, from now on. The mailbox is only read: nothing is marked or moved."]}),(0,m.jsx)(he,{label:"Folder",children:(0,m.jsx)(Se,{value:v("folder"),onChange:b("folder"),placeholder:"INBOX",maxLength:100})}),(0,m.jsx)(he,{label:"Only from (optional)",hint:"Addresses or domains, like priya@example.com, example.com.",children:(0,m.jsx)(Se,{value:v("sender"),onChange:b("sender"),maxLength:300})}),(0,m.jsx)(he,{label:"Subject has (optional)",children:(0,m.jsx)(Se,{value:v("subject"),onChange:b("subject"),placeholder:"Order",maxLength:100})})]}),r==="plane-review"&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)("p",{className:"text-[12.5px] text-muted-foreground",children:"Every morning, reads the last 24 hours and makes one card per problem worth fixing. A problem that comes back joins its card. A clean day adds nothing."}),(0,m.jsx)(he,{label:"Time",hint:`Every day, in ${v("timeZone")||"your time zone"}.`,children:(0,m.jsx)(Se,{type:"time",value:v("at"),onChange:b("at"),required:!0})})]}),r==="webhook"&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(he,{label:"Title field",hint:"Where to find the card's title in the posted JSON, like title or data.issue.title.",children:(0,m.jsx)(Se,{value:v("titleField"),onChange:b("titleField"),placeholder:"title",maxLength:80})}),(0,m.jsx)(he,{label:"Details field",children:(0,m.jsx)(Se,{value:v("bodyField"),onChange:b("bodyField"),placeholder:"description",maxLength:80})}),(0,m.jsx)(he,{label:"Title when there is none",children:(0,m.jsx)(Se,{value:v("title"),onChange:b("title"),maxLength:120})})]}),r!=="chat"&&(0,m.jsx)(he,{label:"Cards start in",children:(0,m.jsxs)("select",{className:gt,value:v("zone"),onChange:b("zone"),children:[(0,m.jsx)("option",{value:"",children:e.stages.find(h=>h.id===e.start)?.title??"The first zone"}),e.stages.filter(h=>h.id!==e.start).map(h=>(0,m.jsx)("option",{value:h.id,children:h.title},h.id))]})}),r!=="chat"&&(0,m.jsxs)(oe,{type:"submit",size:"sm",className:"self-start",disabled:u||r==="flow"&&n.otherFlows.length===0,children:[(0,m.jsx)(ta,{className:"size-4"}),"Add trigger"]})]})]})}function dY({view:e,csrf:t,apply:a}){let o=e.triggerSetup,[n,r]=(0,fe.useState)(""),[s,i]=(0,fe.useState)(""),[l,c]=(0,fe.useState)(o.hooksBase??""),[f,u]=(0,fe.useState)(!1),d=async(p,g)=>{u(!0);let v=await Xa(p,g,t);u(!1),a(v),v.ok&&(r(""),i(""))};return(0,m.jsxs)("details",{className:"rounded-lg border px-3 py-2",children:[(0,m.jsx)("summary",{className:"cursor-pointer text-[13px] font-semibold",children:"Settings"}),(0,m.jsxs)("div",{className:"flex flex-col gap-4 pt-3",children:[o.linearKey?(0,m.jsxs)("div",{className:"grid gap-1.5",children:[(0,m.jsx)("span",{className:"text-[13px] font-medium",children:"Linear key"}),(0,m.jsx)("p",{className:"text-[12px] text-muted-foreground",children:"Saved on this computer."}),(0,m.jsx)(oe,{type:"button",size:"sm",variant:"ghost",className:"self-start text-destructive",disabled:f,onClick:()=>{d(`${e.flow.href}/linear-key`,{remove:"yes"})},children:"Remove key"})]}):(0,m.jsxs)("form",{className:"flex flex-col gap-2",onSubmit:p=>{p.preventDefault(),d(`${e.flow.href}/linear-key`,{key:n,password:s})},children:[(0,m.jsx)(he,{label:"Linear key",hint:"From Linear → Settings → Security & access → Personal API keys. Kept on this computer only.",children:(0,m.jsx)(Se,{type:"password",autoComplete:"off",value:n,onChange:p=>r(p.target.value),placeholder:"lin_api_…"})}),(0,m.jsx)(aB,{view:e,password:s,setPassword:i}),(0,m.jsx)(oe,{type:"submit",size:"sm",className:"self-start",disabled:f||n.trim()===""||!oB(e,s),children:"Save key"})]}),(0,m.jsxs)("form",{className:"flex flex-col gap-2",onSubmit:p=>{p.preventDefault(),d(`${e.flow.href}/hooks-address`,{address:l})},children:[(0,m.jsx)(he,{label:"Public webhook address",hint:"The https site your reverse proxy (Caddy, for example) serves. Have it pass only paths starting /hooks/ to this console.",children:(0,m.jsx)(Se,{value:l,onChange:p=>c(p.target.value),placeholder:"https://hooks.example.com"})}),(0,m.jsx)(oe,{type:"submit",size:"sm",variant:"outline",className:"self-start",disabled:f,children:"Save address"})]})]})]})}function aB({view:e,password:t,setPassword:a}){return e.stepUp===void 0?(0,m.jsx)(he,{label:"Your Toolroll password",children:(0,m.jsx)(Se,{type:"password",autoComplete:"current-password",value:t,onChange:o=>a(o.target.value)})}):e.stepUp.fresh?(0,m.jsxs)("p",{className:"text-[13px] text-success","data-sso-step-up":"confirmed",children:["✓ Confirmed with ",e.stepUp.label]}):(0,m.jsxs)("a",{className:"text-[13px] underline","data-sso-step-up":"confirm",href:e.stepUp.confirmHref,children:["Confirm with ",e.stepUp.label]})}var oB=(e,t)=>e.stepUp===void 0?t!=="":e.stepUp.fresh;function fY({trigger:e,view:t,csrf:a,apply:o}){let[n,r]=(0,fe.useState)(""),[s,i]=(0,fe.useState)(""),[l,c]=(0,fe.useState)(!1);return(0,m.jsxs)("form",{className:"mt-2 flex flex-col gap-2 rounded-md border border-attention/50 p-2",onSubmit:async f=>{f.preventDefault(),c(!0);let u=await Xa(`${t.flow.href}/triggers/${e.id}/secret`,{secret:n,password:s},a);c(!1),o(u),u.ok&&(r(""),i(""))},children:[(0,m.jsx)(he,{label:"Linear's signing secret",hint:"Linear shows it when you create the webhook.",children:(0,m.jsx)(Se,{type:"password",autoComplete:"off",value:n,onChange:f=>r(f.target.value)})}),(0,m.jsx)(aB,{view:t,password:s,setPassword:i}),(0,m.jsx)(oe,{type:"submit",size:"sm",className:"self-start",disabled:l||n.trim()===""||!oB(t,s),children:"Save secret"})]})}function pY({view:e,csrf:t,apply:a,focus:o,onPress:n,onClose:r}){let[s,i]=(0,fe.useState)(null),[l,c]=(0,fe.useState)(!1),f=`${e.flow.href}/triggers`,u=async(p,g)=>{c(!0);let v=await Xa(p,{},t);c(!1),a(v),v.reveal!==void 0&&i({kind:g,reveal:v.reveal})},d=e.triggers.filter(p=>p.state!=="removed");return(0,fe.useEffect)(()=>{o!==null&&document.querySelector(`[data-trigger-row="${o}"]`)?.scrollIntoView({block:"nearest"})},[o]),(0,m.jsxs)("div",{className:"flex flex-col gap-4","data-flow-triggers":!0,children:[(0,m.jsxs)("div",{className:"flex items-center gap-2",children:[(0,m.jsx)("h2",{className:"flex-1 text-[15px] font-semibold",children:"Triggers"}),(0,m.jsx)(oe,{variant:"ghost",size:"icon",onClick:r,"aria-label":"Close",children:(0,m.jsx)(jt,{className:"size-4"})})]}),(0,m.jsx)("p",{className:"text-[13px] text-muted-foreground",children:"Triggers add cards to this flow on their own. The work they start still waits for your usual approvals."}),s!==null&&(0,m.jsx)(lY,{kind:s.kind,reveal:s.reveal,onDone:()=>i(null)}),d.length>0&&(0,m.jsx)("ul",{className:"flex flex-col gap-3",children:d.map(p=>(0,m.jsxs)("li",{className:ue("rounded-lg border p-3",o===p.id&&"ring-2 ring-primary/50"),"data-trigger-row":p.id,children:[(0,m.jsxs)("div",{className:"flex items-start gap-2",children:[(0,m.jsx)("span",{className:"mt-0.5 inline-flex size-6 shrink-0 items-center justify-center rounded-md bg-muted text-muted-foreground",children:VO[p.kind]??(0,m.jsx)(Cs,{className:"size-3.5","aria-hidden":"true"})}),(0,m.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,m.jsx)("p",{className:"text-[13px] font-medium leading-snug",children:p.words}),(0,m.jsxs)("p",{className:"text-[12px] text-muted-foreground",children:["Starts in ",p.zone,p.state==="paused"?" · Paused":"",p.shared?" · Shared as a form":""]}),p.status!==null&&(0,m.jsxs)("p",{className:ue("text-[12px]",p.failing?"text-warning":"text-muted-foreground"),children:[tB(p.statusAt),": ",p.status]})]})]}),p.hook?.needsSecret===!0&&!p.hook.ready&&(0,m.jsx)(fY,{trigger:p,view:e,csrf:t,apply:a}),(0,m.jsxs)("div",{className:"mt-2 flex flex-wrap gap-1.5",children:[p.button!==null&&p.state==="active"&&(0,m.jsx)(oe,{size:"sm",onClick:()=>n(p.id),children:"Start"}),p.button!==null&&(0,m.jsx)(oe,{size:"sm",variant:"outline",disabled:l,onClick:()=>{u(`${f}/${p.id}/share`,"form")},children:p.shared?"New form link":"Share as a form"}),p.shared&&(0,m.jsx)(oe,{size:"sm",variant:"ghost",disabled:l,onClick:()=>{u(`${f}/${p.id}/unshare`,"form")},children:"Stop sharing"}),p.checkable&&p.state==="active"&&(0,m.jsx)(oe,{size:"sm",variant:"outline",disabled:l,onClick:()=>{u(`${f}/${p.id}/check`,p.kind)},children:p.kind==="schedule"?"Run now":"Check now"}),p.hook!==null&&(0,m.jsx)(oe,{size:"sm",variant:"outline",disabled:l,onClick:()=>{u(`${f}/${p.id}/renew`,p.kind)},children:"New address"}),(0,m.jsx)(oe,{size:"sm",variant:"ghost",disabled:l,onClick:()=>{u(`${f}/${p.id}/${p.state==="paused"?"resume":"pause"}`,p.kind)},children:p.state==="paused"?"Turn on":"Pause"}),(0,m.jsx)(oe,{size:"sm",variant:"ghost",className:"text-destructive",disabled:l,onClick:()=>{u(`${f}/${p.id}/remove`,p.kind)},children:"Remove"})]})]},p.id))}),(0,m.jsx)(cY,{view:e,csrf:t,open:d.length===0,onResult:(p,g)=>{a(p),p.reveal!==void 0&&i({kind:g,reveal:p.reveal})}}),(0,m.jsx)(dY,{view:e,csrf:t,apply:a})]})}function nB({trigger:e,view:t,csrf:a,apply:o,onClose:n}){let r=e.button?.questions??[],[s,i]=(0,fe.useState)(r.map(()=>"")),[l,c]=(0,fe.useState)(!1),f=u=>d=>i(p=>p.map((g,v)=>v===u?d.target.value:g));return(0,m.jsxs)("form",{className:"flex flex-col gap-3","data-flow-press":e.id,onSubmit:async u=>{u.preventDefault(),c(!0);let d=await Xa(`${t.flow.href}/triggers/${e.id}/press`,{answers:JSON.stringify(s)},a);c(!1),o(d),d.ok&&n()},children:[(0,m.jsxs)("div",{className:"flex items-center gap-2",children:[(0,m.jsx)("h2",{className:"flex-1 text-[15px] font-semibold",children:e.button?.label}),(0,m.jsx)(oe,{type:"button",variant:"ghost",size:"icon",onClick:n,"aria-label":"Close",children:(0,m.jsx)(jt,{className:"size-4"})})]}),(0,m.jsxs)("p",{className:"text-[12px] text-muted-foreground",children:["The card starts in ",e.zone,"."]}),r.map((u,d)=>(0,m.jsx)(he,{label:u,children:d===0?(0,m.jsx)(Se,{value:s[d]??"",onChange:f(d),maxLength:200,required:!0,autoFocus:!0}):(0,m.jsx)(na,{rows:3,value:s[d]??"",onChange:f(d)})},d)),(0,m.jsxs)(oe,{type:"submit",size:"sm",className:"self-start",disabled:l||(s[0]??"").trim()==="",children:[(0,m.jsx)(ta,{className:"size-4"}),"Add card"]})]})}function mY({view:e,csrf:t,apply:a,onClose:o}){let n={name:"",about:"",body:"",timeoutMinutes:"15",language:"python",file:""},[r,s]=(0,fe.useState)(e.scripts.length===0?n:null),[i,l]=(0,fe.useState)(!1),c=async()=>{if(r===null)return;l(!0);let p=await Xa(`${e.flow.href}/scripts`,r,t);l(!1),a(p),p.ok&&(s(null),d(!1))},f=p=>g=>s(v=>v===null?v:{...v,[p]:g.target.value}),[u,d]=(0,fe.useState)(!1);return(0,m.jsxs)("div",{className:"flex flex-col gap-4","data-flow-scripts":!0,children:[(0,m.jsxs)("div",{className:"flex items-center gap-2",children:[(0,m.jsx)("h2",{className:"flex-1 text-[15px] font-semibold",children:"Scripts"}),(0,m.jsx)(oe,{variant:"ghost",size:"icon",onClick:o,"aria-label":"Close",children:(0,m.jsx)(jt,{className:"size-4"})})]}),(0,m.jsxs)("p",{className:"text-[13px] text-muted-foreground",children:["Reusable steps with no AI, in shell, Python or Node. A “Run a script” zone runs one with the card, and a schedule can run one to make cards. Any flow in ",e.flow.project," can use them."]}),e.scripts.length>0&&(0,m.jsx)("ul",{className:"flex flex-col gap-2",children:e.scripts.map(p=>(0,m.jsxs)("li",{className:"rounded-lg border p-3","data-script":p.name,children:[(0,m.jsxs)("div",{className:"flex items-start gap-2",children:[(0,m.jsx)("span",{className:"mt-0.5 inline-flex size-6 shrink-0 items-center justify-center rounded-md bg-muted text-muted-foreground",children:(0,m.jsx)(vs,{className:"size-3.5","aria-hidden":"true"})}),(0,m.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,m.jsx)("p",{className:"font-mono text-[13px] font-semibold",children:p.name}),(0,m.jsx)("p",{className:"text-[12.5px]",children:p.about}),(0,m.jsxs)("p",{className:"text-[12px] text-muted-foreground",children:[QO[p.language],p.file===null?"":` · runs ${p.file}`," · version ",p.version," · ",p.savedBy," · up to ",p.timeoutMinutes," min",p.usedHere.length>0?` · runs in ${p.usedHere.join(", ")}`:" · not used in this flow"]})]})]}),p.file===null&&(0,m.jsxs)("details",{className:"mt-2",children:[(0,m.jsx)("summary",{className:"cursor-pointer text-[12px] text-muted-foreground",children:"Show the script"}),(0,m.jsx)("pre",{className:"mt-2 max-h-56 overflow-auto rounded-md bg-muted p-2 font-mono text-[12px]",children:p.body})]}),e.canEdit&&(0,m.jsxs)("div",{className:"mt-2 flex gap-1.5",children:[(0,m.jsx)(oe,{size:"sm",variant:"outline",onClick:()=>{d(p.file!==null),s({name:p.name,about:p.about,body:p.body,timeoutMinutes:String(p.timeoutMinutes),language:p.language,file:p.file??""})},children:"Edit"}),(0,m.jsx)(oe,{size:"sm",variant:"ghost",className:"text-destructive",disabled:i,onClick:async()=>{l(!0),a(await Xa(`${e.flow.href}/scripts`,{remove:"yes",name:p.name},t)),l(!1)},children:"Remove"})]})]},p.name))}),e.canEdit&&(r===null?(0,m.jsxs)(oe,{size:"sm",variant:"outline",className:"self-start",onClick:()=>{d(!1),s(n)},children:[(0,m.jsx)(ta,{className:"size-4"}),"New script"]}):(0,m.jsxs)("form",{className:"flex flex-col gap-3 rounded-lg border p-3",onSubmit:p=>{p.preventDefault(),c()},"data-script-form":!0,children:[(0,m.jsx)(he,{label:"Name",hint:"Lowercase and dashes, like run-tests. Saving under an existing name makes a new version.",children:(0,m.jsx)(Se,{value:r.name,onChange:f("name"),maxLength:40,className:"font-mono",required:!0})}),(0,m.jsx)(he,{label:"What it checks or does",children:(0,m.jsx)(Se,{value:r.about,onChange:f("about"),maxLength:160,placeholder:"Looks the company up in our CRM",required:!0})}),(0,m.jsxs)("div",{className:"flex gap-2",children:[(0,m.jsx)(he,{label:"Language",children:(0,m.jsxs)("select",{className:gt,value:r.language,onChange:f("language"),"aria-label":"Language",children:[(0,m.jsx)("option",{value:"python",children:"Python"}),(0,m.jsx)("option",{value:"node",children:"Node"}),(0,m.jsx)("option",{value:"shell",children:"Shell"})]})}),(0,m.jsx)(he,{label:"Runs",children:(0,m.jsxs)("select",{className:gt,value:r.file===""&&!u?"here":"file",onChange:p=>{d(p.target.value==="file"),s(g=>g===null?g:{...g,file:p.target.value==="file"?g.file:""})},"aria-label":"Runs",children:[(0,m.jsx)("option",{value:"here",children:"What's written here"}),(0,m.jsx)("option",{value:"file",children:"A file in the project"})]})})]}),u||r.file!==""?(0,m.jsx)(he,{label:"File",hint:"A path from the top of the project. It gets the card as JSON on stdin (and in $FLOW_INPUT); what it prints is the step's result.",children:(0,m.jsx)(Se,{value:r.file,onChange:f("file"),maxLength:200,className:"font-mono",placeholder:"scripts/enrich.py",required:!0})}):(0,m.jsx)(he,{label:"Script",hint:"It gets the card as JSON on stdin (and in $FLOW_INPUT). What it prints is the step's result; a last line “goto: <answer>” picks the next zone. Exit 0 passes.",children:(0,m.jsx)(na,{value:r.body,onChange:f("body"),rows:8,className:"font-mono text-[12.5px]",placeholder:oY[r.language]??"",required:!0})}),(0,m.jsx)(he,{label:"Stop it after (minutes)",children:(0,m.jsx)(Se,{type:"number",min:1,max:60,value:r.timeoutMinutes,onChange:f("timeoutMinutes"),className:"w-28"})}),(0,m.jsxs)("div",{className:"flex gap-2",children:[(0,m.jsx)(oe,{type:"submit",size:"sm",disabled:i,children:"Save script"}),(0,m.jsx)(oe,{type:"button",size:"sm",variant:"ghost",onClick:()=>s(null),children:"Cancel"})]})]}))]})}var hY=e=>e===null?"—":e<1?"under a minute":e<90?`${Math.round(e)} min`:e<2880?`${Math.round(e/60)} h`:`${Math.round(e/1440)} days`;function gY({view:e,onClose:t}){let[a,o]=(0,fe.useState)(30),[n,r]=(0,fe.useState)(null),[s,i]=(0,fe.useState)(null),[l,c]=(0,fe.useState)(null);(0,fe.useEffect)(()=>{let u=!0;return r(null),i(null),fetch(`${e.flow.href}/insights?days=${a}`,{credentials:"same-origin",headers:{accept:"application/json"}}).then(async d=>{if(u){if(!d.ok)throw new Error("load");r(await d.json())}}).catch(()=>{u&&i("The insights couldn't load. Try again.")}),()=>{u=!1}},[a,e.flow.href,e.flow.revision]);let f=async(u,d)=>{let p=`${u}:${d}`;if(l?.key===p){c(null);return}try{let v=await(await fetch(`${e.flow.href}/runs/${u}/${d}`,{credentials:"same-origin",headers:{accept:"application/json"}})).json();c({key:p,text:v.log===void 0||v.log===""?"This run left no output.":v.log})}catch{c({key:p,text:"The log couldn't load."})}};return(0,m.jsxs)("div",{className:"flex flex-col gap-4","data-flow-insights":!0,children:[(0,m.jsxs)("div",{className:"flex items-center gap-2",children:[(0,m.jsx)("h2",{className:"flex-1 text-[15px] font-semibold",children:"Insights"}),(0,m.jsxs)("select",{className:"h-8 rounded-md border bg-transparent px-2 text-[12px]",value:a,onChange:u=>o(Number(u.target.value)),"aria-label":"Period",children:[(0,m.jsx)("option",{value:7,children:"Last 7 days"}),(0,m.jsx)("option",{value:30,children:"Last 30 days"}),(0,m.jsx)("option",{value:90,children:"Last 90 days"})]}),(0,m.jsx)(oe,{variant:"ghost",size:"icon",onClick:t,"aria-label":"Close",children:(0,m.jsx)(jt,{className:"size-4"})})]}),s!==null&&(0,m.jsx)("p",{className:"text-[13px] text-destructive",children:s}),n===null&&s===null&&(0,m.jsx)("p",{className:"text-[13px] text-muted-foreground",children:"Loading…"}),n!==null&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsxs)("p",{className:"text-[13px]",children:[n.cards.started," card",n.cards.started===1?"":"s"," started, ",n.cards.finished," finished, ",n.cards.active," in progress."]}),(0,m.jsxs)("section",{className:"flex flex-col gap-2",children:[(0,m.jsx)("h3",{className:"text-[13px] font-semibold",children:"Where it breaks"}),n.breaks.length===0?(0,m.jsx)("p",{className:"text-[12.5px] text-muted-foreground",children:"Nothing failed or was sent back in this period."}):(0,m.jsx)("ul",{className:"flex flex-col gap-2",children:n.breaks.map(u=>{let d=n.zones.find(p=>p.zone===u.zone);return(0,m.jsxs)("li",{className:"rounded-lg border border-border p-2.5 text-[13px]",children:[(0,m.jsxs)("p",{children:[(0,m.jsx)("span",{className:"font-semibold",children:u.title}),": ",u.problems," of ",u.of," card",u.of===1?"":"s"," failed or were sent back"]}),d?.lastProblem&&(0,m.jsxs)("p",{className:"mt-0.5 text-[12px] text-muted-foreground",children:["Latest: ",d.lastProblem.cardTitle,d.lastProblem.note===null?"":` — ${d.lastProblem.note.split(`
|
|
66
|
+
`)[0]}`]})]},u.zone)})})]}),(0,m.jsxs)("section",{className:"flex flex-col gap-1.5",children:[(0,m.jsx)("h3",{className:"text-[13px] font-semibold",children:"Zones"}),(0,m.jsxs)("table",{className:"w-full text-left text-[12px]",children:[(0,m.jsx)("thead",{className:"text-muted-foreground",children:(0,m.jsxs)("tr",{children:[(0,m.jsx)("th",{className:"py-1 font-medium",children:"Zone"}),(0,m.jsx)("th",{className:"font-medium",children:"In"}),(0,m.jsx)("th",{className:"font-medium",children:"On"}),(0,m.jsx)("th",{className:"font-medium",children:"Failed"}),(0,m.jsx)("th",{className:"font-medium",children:"Back"}),(0,m.jsx)("th",{className:"font-medium",children:"Typical stay"})]})}),(0,m.jsx)("tbody",{children:n.zones.map(u=>(0,m.jsxs)("tr",{className:"border-t",children:[(0,m.jsxs)("td",{className:"py-1.5 pr-2 font-medium",children:[u.title,u.here>0?(0,m.jsxs)("span",{className:"text-muted-foreground",children:[" · ",u.here," here"]}):null]}),(0,m.jsx)("td",{children:u.entered}),(0,m.jsx)("td",{children:u.movedOn}),(0,m.jsx)("td",{className:u.failed>0?"font-semibold text-destructive":"",children:u.failed}),(0,m.jsx)("td",{className:u.sentBack>0?"font-semibold text-foreground":"",children:u.sentBack}),(0,m.jsx)("td",{children:hY(u.typicalMinutes)})]},u.zone))})]})]}),n.scripts.length>0&&(0,m.jsxs)("section",{className:"flex flex-col gap-1.5",children:[(0,m.jsx)("h3",{className:"text-[13px] font-semibold",children:"Scripts"}),(0,m.jsx)("ul",{className:"flex flex-col gap-1 text-[12.5px]",children:n.scripts.map(u=>(0,m.jsxs)("li",{children:[(0,m.jsx)("span",{className:"font-mono font-semibold",children:u.script}),": ",u.passed," of ",u.runs," passed",u.typicalSeconds===null?"":`, usually ${u.typicalSeconds<90?`${u.typicalSeconds} s`:`${Math.round(u.typicalSeconds/60)} min`}`]},u.script))})]}),n.sorts.length>0&&(0,m.jsxs)("section",{className:"flex flex-col gap-2","data-insights-sorts":!0,children:[(0,m.jsx)("h3",{className:"text-[13px] font-semibold",children:"Sorting"}),n.sorts.map(u=>(0,m.jsxs)("div",{className:"rounded-lg border p-2.5 text-[12.5px]","data-insights-sort":u.zone,children:[(0,m.jsxs)("p",{children:[(0,m.jsx)("span",{className:"font-semibold",children:u.title}),": ",u.sorted," sorted · ",u.alone," on its own · ",u.notSure," for a person",u.corrected>0&&(0,m.jsxs)(m.Fragment,{children:[" · ",(0,m.jsxs)("span",{className:"font-semibold text-attention",children:[u.corrected," moved elsewhere by people"]})]})]}),u.bands.some(d=>d.of>0)&&(0,m.jsxs)("p",{className:"mt-1 text-muted-foreground",children:["Right when ",u.bands.filter(d=>d.of>0).map(d=>`${d.from}–${d.to}% sure: ${d.right} of ${d.of}`).join(" · ")]}),u.suggestion!==null&&(0,m.jsx)("p",{className:"mt-1",children:u.suggestion}),u.costUsd>0&&(0,m.jsxs)("p",{className:"mt-1 text-muted-foreground",children:["Cost: ",u.costUsd<.01?"under 1¢":`$${u.costUsd.toFixed(2)}`]})]},u.zone))]}),(n.recurring??[]).length>0&&(0,m.jsxs)("section",{className:"flex flex-col gap-1.5","data-insights-recurring":!0,children:[(0,m.jsx)("h3",{className:"text-[13px] font-semibold",children:"What keeps coming back"}),(0,m.jsx)("ul",{className:"flex flex-col gap-1 text-[12.5px]",children:n.recurring.map(u=>(0,m.jsxs)("li",{className:"flex items-baseline gap-2",children:[(0,m.jsx)("span",{className:"min-w-0 flex-1 truncate",children:u.card===null?u.title:(0,m.jsx)("a",{className:"underline-offset-2 hover:underline",href:`${e.flow.href}?card=${u.card}`,children:u.title})}),(0,m.jsxs)("span",{className:ue("shrink-0 tabular-nums",u.days>1?"font-semibold text-foreground":"text-muted-foreground"),children:[u.days," day",u.days===1?"":"s"]})]},u.problem))})]}),(0,m.jsxs)("section",{className:"flex flex-col gap-1.5",children:[(0,m.jsx)("h3",{className:"text-[13px] font-semibold",children:"Recent runs"}),n.runs.length===0?(0,m.jsx)("p",{className:"text-[12.5px] text-muted-foreground",children:"No scripts, sorts or updates have run in this period."}):(0,m.jsx)("ul",{className:"flex flex-col gap-1.5",children:n.runs.map(u=>{let d=`${u.card}:${u.entry}`;return(0,m.jsxs)("li",{className:"rounded-md border px-2.5 py-2 text-[12.5px]","data-run":d,children:[(0,m.jsxs)("button",{type:"button",className:"flex w-full items-start gap-2 text-left",onClick:()=>{f(u.card,u.entry)},"aria-expanded":l?.key===d,children:[(0,m.jsx)("span",{className:ue("mt-1 size-2 shrink-0 rounded-full",u.state==="passed"?"bg-success":u.state==="failed"?"bg-destructive":"bg-info"),"aria-hidden":"true"}),(0,m.jsxs)("span",{className:"min-w-0 flex-1",children:[(0,m.jsx)("span",{className:"font-medium",children:u.script??u.zoneTitle})," · ",u.cardTitle,(0,m.jsxs)("span",{className:"block text-[12px] text-muted-foreground",children:[u.kind==="sort"&&u.state==="passed"&&u.result!==null?u.result.split(". ")[0].replace(/\.$/,""):u.state==="passed"?"Passed":u.state==="failed"?"Failed":u.state==="waiting"?"Trying again":"Running",u.durationMs===null?"":u.kind==="sort"?` · ${u.durationMs<1e3?`${u.durationMs} ms`:`${(u.durationMs/1e3).toFixed(1)} s`}`:` in ${Math.max(1,Math.round(u.durationMs/1e3))} s`," · ",$O(u.at)]})]})]}),l?.key===d&&(0,m.jsx)("pre",{className:"mt-2 max-h-72 overflow-auto whitespace-pre-wrap rounded-md bg-muted p-2 font-mono text-[11.5px]","data-run-log":!0,children:l.text})]},d)})})]})]})]})}function xY({view:e,csrf:t}){let[a,o]=(0,fe.useState)(e),[n,r]=(0,fe.useState)(!1),[s,i]=(0,fe.useState)(null),[l,c]=(0,fe.useState)(e.selectedCard!==null?{card:e.selectedCard}:e.startTrigger!==null&&e.triggers.some(F=>F.id===e.startTrigger&&F.button!==null)?{press:e.startTrigger}:null),[f,u]=(0,fe.useState)(!1),[d,p]=(0,fe.useState)(!1),[g,v]=(0,fe.useState)(()=>{try{return window.localStorage.getItem("so-flows-mine")==="1"}catch{return!1}});(0,fe.useEffect)(()=>{try{window.localStorage.setItem("so-flows-mine",g?"1":"0")}catch{}},[g]);let b=Hf(),x=s?.stages??a.stages,y=s?.start??a.start,h=s!==null&&JSON.stringify({name:s.name,start:s.start,stages:s.stages,owner:s.owner})!==JSON.stringify({name:a.flow.name,start:a.start,stages:a.stages,owner:a.flow.owner}),w=(0,fe.useCallback)(F=>{(F.ok?lo.success:lo.error)(F.said),F.view!==void 0&&o(F.view)},[]),C=GO(a,o,{card:l!==null&&"card"in l?l.card:null,editing:n}),S=(0,fe.useMemo)(()=>{let F={};for(let V of C)if(!V.editing)for(let re of V.cards)(F[re]??=[]).push(V.name);return F},[C]),L=(0,fe.useCallback)(async(F,V)=>{let re=a.cards.find(K=>K.id===F);re===void 0||re.stage===V||w(await Xa(`${a.flow.href}/cards/${F}/move`,{stage:V},t))},[a,t,w]),I=(0,fe.useMemo)(()=>x.map(F=>({id:F.id,type:"zone",position:{x:F.zone.x,y:F.zone.y},width:F.zone.w,height:F.zone.h,style:{width:F.zone.w,height:F.zone.h},draggable:n,selectable:n,data:{stage:F,kindLabel:a.kinds.find(V=>V.kind===F.kind)?.label??F.kind,owner:s?.owner??a.flow.owner,teammate:F.teammate===void 0?null:a.teammates?.find(V=>V.handle===F.teammate)?.name??F.teammate,cards:a.cards.filter(V=>V.stage===F.id&&V.state==="active"&&(!g||V.mine)),hidden:g?a.cards.filter(V=>V.stage===F.id&&V.state==="active"&&!V.mine).length:0,lookers:S,editing:n,canMove:a.canEdit,start:F.id===y,selectedCard:l!==null&&"card"in l?l.card:null,onCard:V=>{p(!1),c({card:V})},onDrop:(V,re)=>{L(V,re)},onResize:(V,re)=>i(K=>K===null?K:{...K,stages:K.stages.map(Le=>Le.id===V?{...Le,zone:{...Le.zone,x:Math.round(re.x),y:Math.round(re.y),w:Math.round(re.width),h:Math.round(re.height)}}:Le)})}})),[x,a,n,l,y,L,g,S]),R=(0,fe.useMemo)(()=>a.triggers.filter(F=>F.state!=="removed"),[a.triggers]),P=(0,fe.useMemo)(()=>{let F=new Map;for(let V of R){let re=x.some(K=>K.id===V.zoneId)?V.zoneId:y;F.set(re,[...F.get(re)??[],V])}return[...F].flatMap(([V,re])=>{let K=x.find(De=>De.id===V);if(K===void 0)return[];let Le=YO+re.length*XO;return[{id:`trigger-${V}`,type:"trigger",position:{x:K.zone.x-272,y:K.zone.y+Math.max(0,(K.zone.h-Le)/2)},width:236,height:Le,style:{width:236,height:Le},draggable:!1,selectable:!1,data:{triggers:re,onOpen:De=>c({triggers:De}),onPress:De=>c({press:De})}}]})},[R,x,y]),O=R.map(F=>`${F.id}:${F.zoneId}`).join(","),B=(0,fe.useRef)(O);(0,fe.useEffect)(()=>{if(B.current===O)return;B.current=O;let F=requestAnimationFrame(()=>{b.fitView({padding:.12,minZoom:.55,maxZoom:1,duration:250})});return()=>cancelAnimationFrame(F)},[O,b]);let z=(0,fe.useMemo)(()=>[...I,...P],[I,P]),[N,M]=(0,fe.useState)(z);(0,fe.useEffect)(()=>{M(F=>z.map(V=>{let re=F.find(K=>K.id===V.id);return re===void 0?V:{...re,...V,...re.measured===void 0?{}:{measured:re.measured},selected:n&&re.selected===!0}}))},[z,n]);let T=(0,fe.useMemo)(()=>{let F=K=>({x:K.zone.x+K.zone.w/2,y:K.zone.y+K.zone.h/2}),V=(K,Le,De)=>{let xt=F(K),ot=F(Le),Ht=ot.x-xt.x,$e=ot.y-xt.y,Je=Math.abs(Ht)>=Math.abs($e);if(De){let Aa=Le.zone.x>=K.zone.x+K.zone.w||K.zone.x>=Le.zone.x+Le.zone.w,Lt=Le.zone.y>=K.zone.y+K.zone.h||K.zone.y>=Le.zone.y+Le.zone.h;return Aa&&Lt?Ht>=0?{source:"s-Right",target:"t-Left"}:{source:"s-Left",target:"t-Right"}:Je?{source:"s-Bottom",target:"t-Bottom"}:{source:"s-Left",target:"t-Left"}}return Je?Ht>=0?{source:"s-Right",target:"t-Left"}:{source:"s-Left",target:"t-Right"}:$e>=0?{source:"s-Bottom",target:"t-Top"}:{source:"s-Top",target:"t-Bottom"}},re=P.map(K=>({id:`${K.id}->zone`,source:K.id,sourceHandle:"out",target:K.id.slice(8),targetHandle:"t-Left",type:"smoothstep",animated:K.data.triggers.some(Le=>Le.state==="active"),deletable:!1,markerEnd:{type:Ko.ArrowClosed},style:{strokeWidth:1.5}}));return GX([...re,...x.flatMap(K=>{let Le=K.next===null?void 0:x.find($e=>$e.id===K.next),De=K.onFail===null?void 0:x.find($e=>$e.id===K.onFail),xt=K.limit?.to==null?void 0:x.find($e=>$e.id===K.limit.to),ot=K.kind==="sort"&&K.sort!==null?K.sort.answers:K.kind==="check"||K.kind==="teammate"?K.routes??[]:[],Ht=ot.length>0?[...new Set(ot.map($e=>$e.to))].flatMap($e=>{let Je=x.find(Lt=>Lt.id===$e);if(Je===void 0)return[];let Aa=Je.zone.x>K.zone.x+K.zone.w?{source:"s-Right",target:"t-Left"}:V(K,Je,!1);return[{id:`${K.id}->answer-${$e}`,source:K.id,target:$e,sourceHandle:Aa.source,targetHandle:Aa.target,type:"smoothstep",label:ot.filter(Lt=>Lt.to===$e).map(Lt=>Lt.answer).join(", "),labelStyle:{fontSize:11,fontWeight:600,fill:"var(--color-foreground)"},labelBgStyle:{fill:"var(--color-card)"},markerEnd:{type:Ko.ArrowClosed},style:{strokeWidth:2},deletable:!1}]}):[];return[...Ht,...Le===void 0?[]:[{id:`${K.id}->next`,source:K.id,target:Le.id,sourceHandle:V(K,Le,!1).source,targetHandle:V(K,Le,!1).target,type:"smoothstep",markerEnd:{type:Ko.ArrowClosed},style:{strokeWidth:2},deletable:n,...K.kind==="wait"&&K.wait?.for==="reply"?{label:"replied",labelStyle:{fontSize:11,fontWeight:600,fill:"var(--color-foreground)"},labelBgStyle:{fill:"var(--color-card)"}}:{}}],...De===void 0||!n&&Ht.some($e=>$e.target===De.id)?[]:[{id:`${K.id}->fail`,source:K.id,target:De.id,sourceHandle:V(K,De,!0).source,targetHandle:V(K,De,!0).target,type:"smoothstep",pathOptions:{offset:28,borderRadius:10},label:K.kind==="approval"?"sent back":K.kind==="sort"?"not sure":K.kind==="wait"?"no reply":"fails",labelStyle:{fontSize:11,fill:(K.kind==="wait","var(--color-muted-foreground)")},labelBgStyle:{fill:"var(--color-card)"},markerEnd:{type:Ko.ArrowClosed,color:(K.kind==="wait","var(--color-muted-foreground)")},style:{strokeWidth:1.5,strokeDasharray:"6 4",stroke:(K.kind==="wait","var(--color-muted-foreground)")},deletable:n}],...xt===void 0||K.limit===void 0?[]:[{id:`${K.id}->limit`,source:K.id,target:xt.id,sourceHandle:V(K,xt,!0).source,targetHandle:V(K,xt,!0).target,type:"smoothstep",pathOptions:{offset:36,borderRadius:10},label:`after ${YX(K.limit.minutes)}`,labelStyle:{fontSize:11,fill:"var(--color-muted-foreground)"},labelBgStyle:{fill:"var(--color-card)"},markerEnd:{type:Ko.ArrowClosed,color:"var(--color-muted-foreground)"},style:{strokeWidth:1.5,strokeDasharray:"2 4",stroke:"var(--color-muted-foreground)"},deletable:n}]]})],x)},[x,n,P,y]),A=(F,V)=>i(re=>re===null?re:{...re,stages:re.stages.map(K=>K.id===F?{...K,...V}:K)}),H=F=>{if(M(V=>Kw(F,V)),!!n)for(let V of F)V.type==="select"&&V.selected&&!V.id.startsWith("trigger-")&&c({zone:V.id})},U=(F,V)=>{!n||V.type!=="zone"||i(re=>re===null?re:{...re,stages:re.stages.map(K=>K.id===V.id?{...K,zone:{...K.zone,x:Math.round(V.position.x),y:Math.round(V.position.y)}}:K)})},_=F=>{if(!n||F.source===F.target)return;let V=x.find(re=>re.id===F.source);if(V?.kind==="sort"&&V.sort!==null&&F.sourceHandle!=="fail"){let re=x.find(K=>K.id===F.target);re!==void 0&&V.sort.answers.length<12&&A(V.id,{sort:{...V.sort,answers:[...V.sort.answers,{answer:re.title.slice(0,40),means:re.title,to:re.id}]}}),c({zone:V.id});return}A(F.source,F.sourceHandle==="fail"?{onFail:F.target}:{next:F.target})},W=()=>{i({name:a.flow.name,start:a.start,stages:a.stages,owner:a.flow.owner}),r(!0),c(null)},$=()=>{i(null),r(!1),c(null)},ie=async()=>{if(s===null)return;u(!0);let F=await Xa(`${a.flow.href}/save`,{name:s.name,owner:s.owner,revision:String(a.flow.revision),definition:JSON.stringify({version:1,start:s.start,stages:s.stages})},t);u(!1),w(F),F.ok&&(i(null),r(!1),c(null))},te=()=>{if(s===null)return;let F=new Set(s.stages.map(K=>K.id)),V=b.screenToFlowPosition({x:window.innerWidth/2,y:window.innerHeight/2}),re={id:XX("New zone",F),title:"New zone",kind:"inbox",zone:{x:Math.round(V.x-140),y:Math.round(V.y-120),w:280,h:300,color:"slate"},instructions:null,planning:null,approver:null,message:null,close:null,script:null,sort:null,next:null,onFail:null};i({...s,stages:[...s.stages,re]}),c({zone:re.id})},ae=l!==null&&"card"in l?a.cards.find(F=>F.id===l.card)??null:null,D=l!==null&&"press"in l?a.triggers.find(F=>F.id===l.press&&F.button!==null)??null:null,J=l!==null&&"triggers"in l&&!n,q=l!==null&&"scripts"in l,j=l!==null&&"insights"in l&&!n,le=l!==null&&"zone"in l?x.find(F=>F.id===l.zone)??null:null,ce=a.cards.filter(F=>F.canDecide).length;return(0,m.jsxs)("div",{className:"flex h-[calc(100dvh-7.5rem)] min-h-[560px] flex-col overflow-hidden rounded-xl border bg-card","data-flow":a.flow.id,children:[(0,m.jsxs)("div",{className:"flex flex-wrap items-center gap-2 border-b px-4 py-2.5",children:[n&&s!==null?(0,m.jsx)(Se,{value:s.name,onChange:F=>i({...s,name:F.target.value}),maxLength:80,className:"h-8 max-w-64 font-semibold","aria-label":"Flow name"}):(0,m.jsx)("h1",{className:"text-[15px] font-semibold",children:a.flow.name}),(0,m.jsx)("span",{className:"text-[12px] text-muted-foreground",children:a.flow.project}),(0,m.jsx)(jO,{others:C,cards:a.cards}),n&&s!==null&&(0,m.jsxs)("label",{className:"inline-flex items-center gap-1.5 text-[12px] text-muted-foreground",children:["Owner",(0,m.jsx)("select",{className:"h-8 rounded-md border bg-transparent px-2 text-[12px] text-foreground",value:s.owner,onChange:F=>i({...s,owner:F.target.value}),"aria-label":"Flow owner",children:[...new Set([s.owner,...a.approvers])].map(F=>(0,m.jsx)("option",{value:F,children:F===a.me?`${F} (you)`:F},F))})]}),ce>0&&!n&&(0,m.jsxs)(Bt,{tone:"attention",children:[ce," waiting for you"]}),!n&&(0,m.jsx)("div",{className:"ml-1 inline-flex rounded-md border p-0.5",role:"group","aria-label":"Which cards",children:[["All cards",!1],["Mine",!0]].map(([F,V])=>(0,m.jsx)("button",{type:"button","aria-pressed":g===V,onClick:()=>v(V),className:ue("rounded px-2 py-1 text-[12px] font-medium",g===V?"bg-muted text-foreground":"text-muted-foreground hover:text-foreground"),children:F},F))}),(0,m.jsx)("span",{className:"flex-1"}),n?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsxs)(oe,{size:"sm",variant:"ghost",onClick:()=>c({scripts:!0}),children:[(0,m.jsx)(vs,{className:"size-4"}),"Scripts"]}),(0,m.jsxs)(oe,{size:"sm",variant:"outline",onClick:te,children:[(0,m.jsx)(ta,{className:"size-4"}),"Add zone"]}),(0,m.jsx)(oe,{size:"sm",variant:"ghost",onClick:$,children:"Discard"}),(0,m.jsx)(oe,{size:"sm",onClick:()=>{ie()},disabled:!h||f,children:f?"Saving…":"Save flow"})]}):(0,m.jsxs)(m.Fragment,{children:[(0,m.jsxs)(oe,{size:"sm",variant:"ghost",onClick:()=>{p(!1),c({insights:!0})},"data-open-insights":!0,children:[(0,m.jsx)(Fn,{className:"size-4"}),"Insights"]}),(0,m.jsxs)(oe,{size:"sm",variant:"ghost",onClick:()=>{p(!1),c({scripts:!0})},"data-open-scripts":!0,children:[(0,m.jsx)(vs,{className:"size-4"}),"Scripts"]}),a.canEdit&&(0,m.jsxs)(oe,{size:"sm",variant:"ghost",onClick:()=>{p(!1),c({triggers:null})},"data-open-triggers":!0,children:[(0,m.jsx)(Cs,{className:"size-4"}),"Triggers",R.length>0?` · ${R.length}`:""]}),a.canEdit&&(0,m.jsx)(oe,{size:"sm",variant:"ghost",asChild:!0,children:(0,m.jsxs)("a",{href:a.chatHref,children:[(0,m.jsx)(qn,{className:"size-4"}),"Change in chat"]})}),a.canEdit&&(0,m.jsxs)(oe,{size:"sm",variant:"outline",onClick:W,children:[(0,m.jsx)(qd,{className:"size-4"}),"Edit flow"]}),a.canEdit&&(0,m.jsxs)(oe,{size:"sm",onClick:()=>{c(null),p(!0)},children:[(0,m.jsx)(ta,{className:"size-4"}),"New card"]})]})]}),(0,m.jsxs)("div",{className:"relative flex min-h-0 flex-1",children:[(0,m.jsxs)("div",{className:"relative min-w-0 flex-1","data-flow-canvas":!0,children:[(0,m.jsxs)(_O,{nodes:N,edges:T,nodeTypes:qX,edgeTypes:VX,onNodesChange:H,onNodeDragStop:U,onConnect:_,onEdgesDelete:F=>{for(let V of F)A(V.source,V.id.endsWith("->fail")?{onFail:null}:V.id.endsWith("->limit")?{limit:{...s?.stages.find(re=>re.id===V.source)?.limit??{minutes:1440},to:null}}:{next:null})},onPaneClick:()=>{n&&c(null)},onNodeClick:()=>{},nodesDraggable:n,nodesConnectable:n,elementsSelectable:n,fitView:!0,fitViewOptions:{padding:.12,minZoom:.55,maxZoom:1},minZoom:.3,maxZoom:1.5,proOptions:{hideAttribution:!0},deleteKeyCode:n?["Backspace","Delete"]:null,children:[(0,m.jsx)(OO,{variant:Qn.Dots,gap:20,size:1}),(0,m.jsx)(zO,{showInteractive:!1})]}),n&&(0,m.jsx)("p",{className:"pointer-events-none absolute bottom-3 left-14 max-w-md rounded-lg bg-foreground/85 px-3 py-1.5 text-[12px] text-background",children:"Drag zones to arrange them. Drag from a zone's right dot to say where work goes next, from its bottom dot for where it goes if sent back."})]}),le!==null&&n||ae!==null||d&&!n||J||D!==null||q||j?(0,m.jsx)("aside",{className:"absolute inset-y-0 right-0 z-10 w-[360px] max-w-full overflow-y-auto border-l bg-card p-4 shadow-xl","data-flow-drawer":!0,children:le!==null&&n?(0,m.jsx)(sY,{stage:le,stages:x,view:a,csrf:t,apply:w,update:F=>A(le.id,F),remove:()=>{i(F=>F===null?F:{...F,start:F.start===le.id?F.stages.find(V=>V.id!==le.id).id:F.start,stages:F.stages.filter(V=>V.id!==le.id).map(V=>({...V,next:V.next===le.id?null:V.next,onFail:V.onFail===le.id?null:V.onFail}))}),c(null)},makeStart:()=>i(F=>F===null?F:{...F,start:le.id}),onClose:()=>c(null)}):q?(0,m.jsx)(mY,{view:a,csrf:t,apply:w,onClose:()=>c(null)}):j?(0,m.jsx)(gY,{view:a,onClose:()=>c(null)}):D!==null?(0,m.jsx)(nB,{trigger:D,view:a,csrf:t,apply:w,onClose:()=>c(null)},D.id):J?(0,m.jsx)(pY,{view:a,csrf:t,apply:w,focus:l!==null&&"triggers"in l?l.triggers:null,onPress:F=>c({press:F}),onClose:()=>c(null)}):ae!==null?(0,m.jsx)(WO,{card:ae,view:a,csrf:t,apply:w,onClose:()=>c(null)}):(0,m.jsx)(eB,{view:a,csrf:t,apply:F=>{w(F),F.ok&&p(!1)},onClose:()=>p(!1)})}):null]})]})}function vY({view:e,csrf:t}){let[a,o]=(0,fe.useState)(e),[n,r]=(0,fe.useState)(e.selectedCard),[s,i]=(0,fe.useState)(e.startTrigger),l=p=>{(p.ok?lo.success:lo.error)(p.said),p.view!==void 0&&o(p.view)},c=GO(a,o,{card:n,editing:!1}),f=n===null?null:a.cards.find(p=>p.id===n)??null,u=s===null?null:a.triggers.find(p=>p.id===s&&p.button!==null&&p.state==="active")??null,d=a.triggers.filter(p=>p.state!=="removed");return u!==null?(0,m.jsx)("div",{className:"p-4",children:(0,m.jsx)(nB,{trigger:u,view:a,csrf:t,apply:l,onClose:()=>i(null)})}):f!==null?(0,m.jsx)("div",{className:"p-4",children:(0,m.jsx)(WO,{card:f,view:a,csrf:t,apply:l,onClose:()=>r(null)})}):(0,m.jsxs)("div",{className:"flex flex-col gap-3 p-4","data-flow":a.flow.id,children:[(0,m.jsxs)("div",{children:[(0,m.jsx)("h1",{className:"text-[17px] font-semibold",children:a.flow.name}),(0,m.jsxs)("p",{className:"text-[12px] text-muted-foreground",children:[a.flow.project,a.canEdit?(0,m.jsxs)(m.Fragment,{children:[" · ",(0,m.jsx)("a",{className:"underline",href:a.chatHref,children:"change it in chat"}),", or edit it on a larger screen"]}):null]}),c.length>0&&(0,m.jsx)("div",{className:"mt-1.5",children:(0,m.jsx)(jO,{others:c,cards:a.cards})})]}),a.canEdit&&d.some(p=>p.button!==null&&p.state==="active")&&(0,m.jsx)("div",{className:"flex flex-wrap gap-2",children:d.filter(p=>p.button!==null&&p.state==="active").map(p=>(0,m.jsxs)(oe,{size:"sm",onClick:()=>i(p.id),children:[(0,m.jsx)(Nu,{className:"size-4"}),p.button.label]},p.id))}),a.canEdit&&(0,m.jsxs)("details",{className:"rounded-lg border p-3",children:[(0,m.jsx)("summary",{className:"cursor-pointer text-[14px] font-semibold",children:"New card"}),(0,m.jsx)("div",{className:"pt-3",children:(0,m.jsx)(eB,{view:a,csrf:t,apply:l})})]}),jX(a.stages,a.start).map(p=>{let g=a.cards.filter(v=>v.stage===p.id&&v.state==="active");return(0,m.jsxs)("section",{className:"rounded-lg border bg-muted/40",children:[(0,m.jsxs)("header",{className:"flex items-center gap-2 px-3 py-2",children:[(0,m.jsx)("span",{className:"inline-flex size-6 items-center justify-center rounded-md text-white",style:{background:qf[p.zone.color]??"#64748b"},children:UO[p.kind]}),(0,m.jsx)("span",{className:"flex-1 text-[14px] font-semibold",children:p.title}),g.length>0&&(0,m.jsx)("span",{className:"text-[12px] text-muted-foreground",children:g.length})]}),g.length>0&&(0,m.jsx)("ul",{className:"flex flex-col gap-2 px-3 pb-3",children:g.map(v=>(0,m.jsx)("li",{children:(0,m.jsxs)("button",{type:"button",onClick:()=>r(v.id),className:ue("min-h-11 w-full rounded-lg border bg-card px-3 py-2 text-left",v.canDecide&&"border-attention/60"),children:[(0,m.jsxs)("div",{className:"flex items-start gap-2",children:[(0,m.jsx)("div",{className:"min-w-0 flex-1 text-[14px] font-medium",children:v.title}),v.owner!==null&&(0,m.jsx)(Vs,{name:v.owner})]}),v.sorted!==null&&(0,m.jsx)("div",{className:"mt-1 flex",children:(0,m.jsx)(tC,{sorted:v.sorted})}),v.waiting!==null&&(0,m.jsx)("div",{className:ue("text-[12px]",v.canDecide?"font-semibold text-attention":"text-muted-foreground"),children:v.canDecide?"Needs your decision":v.waiting}),v.comments.length>0&&(0,m.jsxs)("div",{className:"mt-0.5 inline-flex items-center gap-1 text-[12px] text-muted-foreground",children:[(0,m.jsx)(qn,{className:"size-3","aria-hidden":"true"}),v.comments.length]})]})},v.id))})]},p.id)}),d.length>0&&(0,m.jsxs)("section",{className:"rounded-lg border p-3","data-flow-triggers":!0,children:[(0,m.jsx)("h2",{className:"text-[14px] font-semibold",children:"Triggers"}),(0,m.jsx)("ul",{className:"mt-2 flex flex-col gap-2",children:d.map(p=>(0,m.jsxs)("li",{className:"text-[13px]",children:[(0,m.jsx)("span",{className:"font-medium",children:p.name})," · ",p.detail,(0,m.jsx)("div",{className:ue("text-[12px]",p.failing?"text-warning":"text-muted-foreground"),children:p.state==="paused"?"Paused":p.status===null?`Starts in ${p.zone}`:`${tB(p.statusAt)}: ${p.status}`})]},p.id))})]})]})}function rB({view:e,csrf:t}){let a=(0,fe.useRef)(typeof window<"u"&&window.matchMedia("(max-width: 767px)").matches),[o,n]=(0,fe.useState)(a.current);return(0,fe.useEffect)(()=>{let r=window.matchMedia("(max-width: 767px)"),s=()=>n(r.matches);return r.addEventListener("change",s),()=>r.removeEventListener("change",s)},[]),o?(0,m.jsx)(vY,{view:e,csrf:t}):(0,m.jsx)(Jw,{children:(0,m.jsx)(xY,{view:e,csrf:t})})}var Gs=X(pe(),1);function sB({view:e,csrf:t}){return(0,Gs.jsx)("div",{"data-view":e.kind,className:"w-full",children:e.kind==="tasks"?(0,Gs.jsx)(TA,{view:e}):e.kind==="settings"?(0,Gs.jsx)(LA,{view:e,csrf:t}):e.kind==="task"?(0,Gs.jsx)(NA,{view:e}):e.kind==="projects"?(0,Gs.jsx)(fA,{view:e,csrf:t}):e.kind==="result"?(0,Gs.jsx)(mA,{view:e,csrf:t}):e.kind==="flow"?(0,Gs.jsx)(rB,{view:e,csrf:t}):null})}function iB(e){return e.security?`Toolroll ${e.version} is available, with security fixes`:`Toolroll ${e.version} is available`}var E=X(pe(),1);function Jo({name:e}){return(0,E.jsx)("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",width:"20",height:"20",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:{menu:(0,E.jsx)("path",{d:"M4 6h16M4 12h16M4 18h16"}),chat:(0,E.jsx)("path",{d:"M5 4h14a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H9l-6 3V6a2 2 0 0 1 2-2Z"}),tasks:(0,E.jsx)(E.Fragment,{children:(0,E.jsx)("path",{d:"m3 6 2 2 4-4m-6 9 2 2 4-4m-6 9 2 2 4-4M13 6h8M13 13h8M13 20h8"})}),flows:(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)("rect",{width:"8",height:"8",x:"3",y:"3",rx:"2"}),(0,E.jsx)("path",{d:"M7 11v4a2 2 0 0 0 2 2h4"}),(0,E.jsx)("rect",{width:"8",height:"8",x:"13",y:"13",rx:"2"})]}),projects:(0,E.jsx)("path",{d:"M3 7V5a2 2 0 0 1 2-2h5l3 4h6a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7Z"}),knowledge:(0,E.jsx)("path",{d:"M12 5c-3-2-7-2-10-1v15c3-1 7-1 10 1 3-2 7-2 10-1V4c-3-1-7-1-10 1Zm0 0v15"}),settings:(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)("path",{d:"M4 6h16M4 12h16M4 18h16"}),(0,E.jsx)("path",{d:"M8 3v6M16 9v6M10 15v6"})]}),arrow:(0,E.jsx)("path",{d:"m10 6-6 6 6 6M4 12h16"}),close:(0,E.jsx)("path",{d:"m6 6 12 12M6 18 18 6"}),send:(0,E.jsx)("path",{d:"m12 19 0-14m-6 6 6-6 6 6"}),tools:(0,E.jsx)(E.Fragment,{children:(0,E.jsx)("path",{d:"M4 4h6v6H4zM14 4h6v6h-6zM4 14h6v6H4zM14 14h6v6h-6z"})}),plus:(0,E.jsx)("path",{d:"M12 5v14M5 12h14"})}[e]})}function oC(){try{return window.sessionStorage}catch{return{getItem:()=>null,removeItem:()=>{},setItem:()=>{throw new Error("Storage unavailable")}}}}function nC(e){let t=e.conversation;return t?{user:e.user,session:t.sessionId,task:t.taskId??(t.project?`project:${t.project}`:null)}:null}function lB(){return!document.hidden&&navigator.onLine!==!1}var yY=new Set(["/work","/board","/queue","/workbench","/code"]);function bY(e){let[t,a]=(0,Te.useState)(e),o=nC(e),[n,r]=(0,Te.useState)(()=>{let B=e.conversation&&o?gR(oC(),o,e.conversation.requestId,e.conversation.maxChars):Km(""),z=e.conversation?new URLSearchParams(window.location.search).get("draft"):null;return z&&B.text===""&&B.pending===null?{...B,text:z.slice(0,e.conversation.maxChars)}:B});(0,Te.useEffect)(()=>{let B=new URL(window.location.href);B.searchParams.has("draft")&&(B.searchParams.delete("draft"),window.history.replaceState(window.history.state,"",B.pathname+B.search+B.hash))},[]);let[s,i]=(0,Te.useState)(""),[l,c]=(0,Te.useState)(!0),[f,u]=(0,Te.useState)(!1),[d,p]=(0,Te.useState)(!1),[g,v]=(0,Te.useState)(()=>navigator.onLine===!1),b=(0,Te.useRef)({workspace:t,draft:n,stale:d,sending:f,notice:s});b.current={workspace:t,draft:n,stale:d,sending:f,notice:s};let x=(0,Te.useRef)(!1),y=(0,Te.useRef)(!1),h=(0,Te.useRef)(void 0),w=(0,Te.useRef)(null),C=(0,Te.useRef)(5e3),S=(0,Te.useRef)(!0),L=(0,Te.useRef)(!1),I=(0,Te.useCallback)(B=>{b.current.draft=B,r(B);let z=nC(e);z&&c(xR(oC(),z,B))},[e]),R=(0,Te.useCallback)(async(B=!0)=>{if(!S.current||b.current.stale||!(e.conversation||e.refreshSeconds)||!lB())return;if(x.current){B&&(y.current=!0);return}y.current=!1,clearTimeout(h.current),B&&(C.current=5e3),x.current=!0;let z=b.current.draft.pending?.request??null,N=!1;try{let M=await kR(b.current.workspace,z,fetch,{etag:w.current,force:B});if(!S.current)return;if(w.current=z?null:M.etag,M.kind==="unchanged"){N=!0,!b.current.draft.pending&&b.current.notice&&i("");return}let T=M.workspace;if(!SR(e,T)){b.current.stale=!0,p(!0),i("This conversation changed or ended. Reconnect to continue with your draft.");return}let A=wR(b.current.draft,z,T.receipt);A!==b.current.draft&&I(A),b.current.workspace=T,a(T),i(A.pending?"Delivery is not confirmed. Check again before sending another message.":"")}catch(M){if(!S.current)return;M instanceof yr&&(b.current.stale=!0,p(!0)),i(M instanceof Error?M.message:"Updates are unavailable. Your work is still saved.")}finally{if(x.current=!1,S.current&&!b.current.stale&&lB())if(y.current)y.current=!1,R(!0);else{let M=b.current.draft.pending!==null||b.current.workspace.conversation?.pendingTurnId!=null||L.current;C.current=e.conversation?LR(C.current,N,M):e.refreshSeconds*1e3,h.current=window.setTimeout(()=>{R(!1)},C.current)}}},[e,I]);(0,Te.useEffect)(()=>{if(S.current=!0,!e.conversation&&!e.refreshSeconds)return;e.conversation?R():h.current=window.setTimeout(()=>{R(!1)},e.refreshSeconds*1e3);let B=()=>{document.hidden?clearTimeout(h.current):R(!0)},z=()=>{v(!1),R()},N=()=>{v(!0),clearTimeout(h.current)};return document.addEventListener("visibilitychange",B),window.addEventListener("online",z),window.addEventListener("offline",N),()=>{S.current=!1,clearTimeout(h.current),document.removeEventListener("visibilitychange",B),window.removeEventListener("online",z),window.removeEventListener("offline",N)}},[R,e.conversation,e.refreshSeconds]);let P=async B=>{B.preventDefault();let z=b.current;if(L.current||z.stale||navigator.onLine===!1||z.draft.pending||z.workspace.conversation?.pendingTurnId!==null||!z.draft.text.trim())return;let N=bR(z.draft);if(N.pending){L.current=!0,u(!0),I(N),i("");try{let M=await IR(z.workspace,N.pending);if(!S.current)return;M.refused?(I(CR(b.current.draft,N.pending.request)),i(M.message??"Message not sent. Your draft is saved.")):(i("Checking delivery…"),R())}catch(M){if(!S.current)return;M instanceof yr&&(b.current.stale=!0,p(!0)),i(M instanceof yr?M.message:"Delivery is not confirmed. Check again before sending another message."),R()}finally{L.current=!1,S.current&&u(!1)}}},O=()=>{let B=nC(e);B&&vR(oC(),B,b.current.draft.text),window.location.reload()};return(0,Te.useEffect)(()=>{let B=N=>{let M=N.target;if(!(M instanceof HTMLFormElement)||M.dataset.workspaceComposer!==void 0||M.getAttribute("action")!=="/chat")return;let T=b.current;if(!T.workspace.conversation)return;if(T.stale||L.current||T.draft.pending||navigator.onLine===!1||T.workspace.conversation.pendingTurnId!==null){N.preventDefault(),i("Wait for the current message before sending another.");return}if(M.getAttribute("aria-busy")==="true"){N.preventDefault();return}let A=(H,U)=>{if(M.querySelector(`[name="${H}"]`))return;let _=document.createElement("input");_.type="hidden",_.name=H,_.value=U,M.append(_)};A("request",T.workspace.conversation.requestId),A("request-session",String(T.workspace.conversation.sessionId)),T.workspace.conversation.taskId&&A("task",T.workspace.conversation.taskId),T.workspace.conversation.resultRunId!==null&&A("result",String(T.workspace.conversation.resultRunId)),!N.defaultPrevented&&(L.current=!0,M.setAttribute("aria-busy","true"))},z=()=>{L.current=!1,document.querySelectorAll('form[action="/chat"][aria-busy="true"]:not([data-workspace-composer])').forEach(N=>N.removeAttribute("aria-busy")),R()};return document.addEventListener("submit",B),window.addEventListener("pageshow",z),()=>{document.removeEventListener("submit",B),window.removeEventListener("pageshow",z)}},[R]),{workspace:t,draft:n,notice:s,storageAvailable:l,sending:f,stale:d,offline:g,send:P,check:R,reconnect:O,edit:B=>I(yR(b.current.draft,B))}}function hB(e){return e==="problem"?"danger":e==="attention"?"attention":e==="done"||e==="ready"?"success":e==="live"?"info":"neutral"}function uB({workspace:e,items:t}){return(0,E.jsx)("ul",{className:"so-work-list",children:t.map(a=>(0,E.jsxs)("li",{"data-workspace-task":a.id,"data-work-status":a.state,children:[(0,E.jsxs)("a",{className:"so-work-row",href:a.resultHref??a.href,"aria-current":e.focus?.id===a.id?"page":void 0,children:[(0,E.jsxs)("div",{className:"so-work-heading",children:[(0,E.jsx)("span",{className:"so-work-title",children:a.title}),(0,E.jsx)(Lu,{tone:hB(a.tone),children:a.label})]}),a.project&&(0,E.jsx)("span",{className:"so-work-project",children:e.projects.find(o=>o.path===a.project)?.name??a.project.split(/[\\/]/).filter(Boolean).pop()})]}),a.action&&a.action.href!==(a.resultHref??a.href)&&(0,E.jsx)("a",{className:"so-work-action",href:a.action.href,children:a.action.label})]},a.id))})}function cB({workspace:e}){let t=n=>n.tone==="done"||n.state==="cancelled",a=e.crew.filter(n=>!t(n)),o=e.crew.filter(t);return(0,E.jsxs)("section",{className:"so-crew","aria-labelledby":"crew-title","data-workspace-crew":!0,children:[(0,E.jsxs)("div",{className:"so-section-heading",children:[(0,E.jsx)("h2",{id:"crew-title",children:"Crew"}),(0,E.jsx)("a",{href:"/work",children:"All tasks"})]}),e.crew.length===0?(0,E.jsxs)("div",{className:"so-crew-empty",children:[(0,E.jsx)("p",{children:"No tasks yet."}),(0,E.jsx)("p",{children:"Work you start with the lead appears here."})]}):(0,E.jsxs)(E.Fragment,{children:[a.length>0?(0,E.jsx)(uB,{workspace:e,items:a}):(0,E.jsx)("p",{className:"so-crew-quiet",children:"Nothing is running or waiting on you."}),o.length>0&&(0,E.jsx)(dn,{summary:`Finished (${o.length}${e.crewTruncated?"+":""})`,className:"so-crew-finished",children:(0,E.jsx)(uB,{workspace:e,items:o.slice(0,8)})})]}),e.crewTruncated&&(0,E.jsx)("a",{className:"so-all-work",href:"/work",children:"View more tasks"})]})}function gB({workspace:e}){let t=(0,Te.useId)(),a=e.projects.find(o=>new URL(e.path,window.location.origin).searchParams.get("project")===o.path||new URL(e.path,window.location.origin).searchParams.get("repo")===o.path||e.crew.find(n=>n.id===e.focus?.id)?.project===o.path);return(0,E.jsxs)("div",{className:"so-navigation-content",children:[(0,E.jsxs)("a",{href:"/chat",className:"so-wordmark",children:[(0,E.jsxs)("span",{className:"so-brand-mark","aria-hidden":"true",children:[(0,E.jsx)("i",{}),(0,E.jsx)("i",{}),(0,E.jsx)("i",{})]}),"Toolroll"]}),(0,E.jsxs)("a",{href:"/tasks/new",className:"so-new-task",children:[(0,E.jsx)(Jo,{name:"plus"}),"New task"]}),e.projects.length>0&&(0,E.jsxs)("div",{className:"so-project-switch",children:[(0,E.jsx)(Si,{htmlFor:t,children:"Project"}),(0,E.jsxs)("select",{id:t,value:a?.href??"/work",onChange:o=>{window.location.assign(o.target.value)},children:[(0,E.jsx)("option",{value:"/work",children:"All projects"}),e.projects.map(o=>(0,E.jsx)("option",{value:o.href,children:o.name},o.path))]})]}),(0,E.jsx)("nav",{"aria-label":"Workspace",className:"so-primary-navigation",children:e.navigation.filter(o=>o.href!=="/menu").map(o=>{let n=o.label.toLowerCase();return(0,E.jsxs)("a",{href:o.href,"aria-current":o.active?"page":void 0,children:[(0,E.jsx)(Jo,{name:["chat","tasks","flows","projects","knowledge","settings"].includes(n)?n:"tools"}),(0,E.jsx)("span",{children:o.label}),o.count!==void 0&&o.count>0&&(0,E.jsx)("span",{className:"so-nav-count","aria-label":`${o.count} ${o.count===1?"needs":"need"} you`,children:o.count})]},o.href)})}),a&&(0,E.jsxs)("div",{className:"so-project-links",children:[(0,E.jsx)("a",{className:"so-project-knowledge",href:`/chat?project=${encodeURIComponent(a.path)}`,children:"Project chat"}),(0,E.jsx)("a",{className:"so-project-knowledge",href:a.knowledgeHref,children:"Project knowledge"})]}),(e.chats?.length??0)>0&&(0,E.jsxs)("nav",{"aria-label":"Recent chats",className:"so-recent-chats",children:[(0,E.jsx)("p",{className:"so-recent-chats-label",children:"Recent chats"}),e.chats.map(o=>(0,E.jsxs)("a",{href:o.href,"aria-current":o.active?"page":void 0,title:o.title,children:[(0,E.jsx)("span",{className:"so-recent-chat-kind","aria-hidden":"true",children:o.kind==="task"?"Task":"Project"}),(0,E.jsx)("span",{className:"so-recent-chat-title",children:o.title})]},o.href))]}),(0,E.jsxs)("div",{className:"so-navigation-bottom",children:[(0,E.jsxs)("a",{href:"/menu","aria-current":e.navigation.find(o=>o.href==="/menu")?.active?"page":void 0,children:[(0,E.jsx)(Jo,{name:"tools"}),"Workspace tools"]}),(0,E.jsxs)("div",{className:"so-account",children:[(0,E.jsx)("span",{title:e.user,children:e.user}),(0,E.jsxs)("form",{method:"post",action:"/logout",children:[(0,E.jsx)("input",{type:"hidden",name:"csrf",value:e.csrf}),(0,E.jsx)(Be,{variant:"ghost",size:"sm",type:"submit",children:"Sign out"})]})]})]})]})}function wY(e,t=""){let a=[...e.navigation.map(n=>({label:n.label,detail:"Page",href:n.href})),...e.projects.map(n=>({label:n.name,detail:"Project",href:n.href})),...e.crew.map(n=>({label:n.title,detail:n.label,href:n.resultHref??n.href}))],o=new Set;return a.filter(n=>{let r=`${n.label}
|
|
67
67
|
${n.href}`;return o.has(r)?!1:(o.add(r),`${n.label} ${n.detail}`.toLowerCase().includes(t.trim().toLowerCase()))})}function CY({workspace:e}){let[t,a]=(0,Te.useState)(!1),[o,n]=(0,Te.useState)(""),r=(0,Te.useId)(),s=(0,Te.useRef)(null),i=(0,Te.useRef)(null),l=f=>{a(f),n("")};if((0,Te.useEffect)(()=>{if(e.sensitive)return;let f=u=>{!(u.metaKey||u.ctrlKey)||u.altKey||u.key.toLowerCase()!=="k"||u.target instanceof Element&&u.target.closest('input, textarea, select, [contenteditable="true"], [role="textbox"]')||(u.preventDefault(),a(d=>!d),n(""))};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[e.sensitive]),e.sensitive)return null;let c=wY(e,o);return(0,E.jsxs)(F0,{open:t,onOpenChange:l,children:[(0,E.jsx)(H0,{asChild:!0,children:(0,E.jsxs)(Be,{variant:"ghost",size:"sm",className:"so-command-trigger",children:["Search",(0,E.jsx)("span",{className:"so-command-hint","aria-hidden":"true",children:"⌘ / Ctrl K"})]})}),(0,E.jsxs)(U0,{className:"so-command-dialog","data-workspace-command":!0,onOpenAutoFocus:f=>{f.preventDefault(),s.current?.focus()},children:[(0,E.jsxs)("div",{className:"so-command-heading",children:[(0,E.jsx)(V0,{children:"Go to"}),(0,E.jsx)(q0,{asChild:!0,children:(0,E.jsx)(Be,{variant:"ghost",size:"icon","aria-label":"Close search",children:(0,E.jsx)(Jo,{name:"close"})})})]}),(0,E.jsx)(G0,{className:"so-sr-only",children:"Search pages, projects, and tasks. Use Tab or the arrow keys to choose a link."}),(0,E.jsx)(Si,{htmlFor:r,className:"so-sr-only",children:"Search workspace"}),(0,E.jsx)(Ci,{ref:s,id:r,type:"search",placeholder:"Search workspace…",value:o,onChange:f=>n(f.target.value),onKeyDown:f=>{f.key==="ArrowDown"&&(f.preventDefault(),i.current?.querySelector("a")?.focus())}}),(0,E.jsx)("ul",{ref:i,className:"so-command-results",onKeyDown:f=>{if(f.key!=="ArrowDown"&&f.key!=="ArrowUp")return;let u=Array.from(i.current?.querySelectorAll("a")??[]),d=u.indexOf(document.activeElement);d<0||(f.preventDefault(),u[(d+(f.key==="ArrowDown"?1:-1)+u.length)%u.length]?.focus())},children:c.map(f=>(0,E.jsx)("li",{children:(0,E.jsxs)("a",{href:f.href,children:[(0,E.jsx)("span",{children:f.label}),(0,E.jsx)("small",{children:f.detail})]})},f.href))}),c.length===0&&(0,E.jsx)("p",{className:"so-command-empty",role:"status",children:"No matches."})]})]})}function SY({workspace:e}){return(0,E.jsxs)(F0,{children:[(0,E.jsx)(H0,{asChild:!0,children:(0,E.jsx)(Be,{variant:"ghost",size:"icon",className:"so-mobile-menu","aria-label":"Open navigation",children:(0,E.jsx)(Jo,{name:"menu"})})}),(0,E.jsxs)(U0,{className:"so-navigation-dialog",children:[(0,E.jsx)(V0,{className:"so-sr-only",children:"Workspace navigation"}),(0,E.jsx)(G0,{className:"so-sr-only",children:"Choose a project or a workspace page."}),(0,E.jsx)(q0,{asChild:!0,children:(0,E.jsx)(Be,{variant:"ghost",size:"icon",className:"so-navigation-close","aria-label":"Close navigation",children:(0,E.jsx)(Jo,{name:"close"})})}),(0,E.jsx)(gB,{workspace:e})]})]})}var LY=[["support-desk","Support desk"],["bug-triage","Bug triage"],["sales-follow-up","Sales follow-up"],["ops-requests","Ops requests"]],dB={task:{title:"Ask about this task",hint:"Questions, changes and next steps. Actions come back as cards you confirm.",placeholder:"Ask about this task…",suggestions:["Where does this task stand?","Move this forward","Request changes: "]},result:{title:"Ask about this result",hint:"Ask what changed or why, or request a revision. Actions come back as cards you confirm.",placeholder:"Ask about this result…",suggestions:["Summarize what changed","What does the check log say?","Request changes: "]},tasks:{title:"Ask about this project",hint:"Plan work, file tasks and check progress. Actions come back as cards you confirm.",placeholder:"Ask about this project…",suggestions:["What needs my attention here?","What should we build next?","File a task: "]}};function kY(e,t,a){let[o,n]=(0,Te.useState)(null),r=(0,Te.useRef)(a);return r.current=a,(0,Te.useEffect)(()=>{if(e===null||!t||typeof EventSource>"u"){n(null);return}let s=new URLSearchParams;e.taskId?s.set("task",e.taskId):e.project&&s.set("project",e.project);let i=s.toString(),l=new EventSource(`/chat/stream${i===""?"":`?${i}`}`);return l.addEventListener("turn",c=>{let f;try{f=JSON.parse(c.data)}catch{return}if(typeof f!="object"||f===null||!Array.isArray(f.steps))return;let u=f,d=u.steps.filter(p=>typeof p=="object"&&p!==null&&Array.isArray(p.tools)&&typeof p.text=="string").map(p=>({tools:p.tools.filter(g=>typeof g=="string"),text:p.text}));n({steps:d,done:u.done===!0}),u.done===!0&&(l.close(),r.current())}),l.onerror=()=>{l.close()},()=>l.close()},[e?.sessionId,e?.taskId,e?.project,t]),t?o:null}function IY({live:e}){let t=e?.steps??[],a=t.flatMap(r=>r.tools).filter((r,s,i)=>s===0||i[s-1]!==r),o=[...t].reverse().find(r=>r.text.trim()!=="")?.text??"",n=t.length>0&&t.at(-1).text.trim()!=="";return(0,E.jsxs)($0,{from:"assistant",className:"so-live-reply","data-live-reply":!0,children:[(0,E.jsx)("div",{className:"so-message-label",children:"Lead"}),(0,E.jsxs)(W0,{children:[a.length>0&&(0,E.jsx)("ul",{className:"so-live-steps","aria-label":"What the lead is doing",children:a.map((r,s)=>(0,E.jsx)("li",{"data-done":n||s<a.length-1?"true":"false",children:r},s))}),o!==""&&(0,E.jsxs)("p",{className:"so-live-text",children:[o,(0,E.jsx)("span",{className:"so-live-caret","aria-hidden":"true"})]}),(0,E.jsxs)("div",{className:"so-working",role:"status",children:[(0,E.jsx)("span",{className:"so-live-dot"}),n?"Writing…":a.length>0?`${a.at(-1)}…`:"Thinking…"]})]})]})}function fB({controller:e,docked:t=null}){let{workspace:a,draft:o,notice:n,storageAvailable:r,sending:s,stale:i,offline:l}=e,c=a.conversation,f=t===null?null:dB[t]??dB.task,u=(0,Te.useRef)(null),d=c.pendingTurnId!==null,p=Wb[t??(c.taskId?"task":c.project?"tasks":"lead")]??Wb.lead,g=/^\/(\w*)$/.exec(o.text)?.[1]?.toLowerCase(),[v,b]=(0,Te.useState)(0),[x,y]=(0,Te.useState)(!1),h=g===void 0||x?[]:p.filter(R=>R.command.startsWith(g)),w=(0,Te.useId)(),C=R=>{e.edit(R.text),b(0),requestAnimationFrame(()=>{let P=u.current;P&&(P.focus(),P.setSelectionRange(P.value.length,P.value.length))})},S=kY(c,d||o.pending!==null&&!s,()=>{e.check()}),L=s||i||l||d||o.pending!==null||!o.text.trim();(0,Te.useLayoutEffect)(()=>{let R=u.current;if(R){let P=matchMedia("(max-width: 760px)").matches;R.style.height=P?"0px":"auto",R.style.height=`${Math.min(180,Math.max(P?44:48,R.scrollHeight))}px`}},[o.text]);let I=l?"Offline. Your draft stays in this tab.":s?"Sending…":n;return(0,E.jsxs)("div",{className:"so-lead-chat","data-workspace-chat":!0,children:[(0,E.jsxs)(iR,{className:"so-conversation",children:[(0,E.jsxs)(lR,{className:"so-conversation-content",children:[!f&&a.firstRun&&(0,E.jsx)(Kb,{firstRun:a.firstRun,onDraft:R=>{e.edit(cA(o.text,R)),u.current?.focus()}}),!f&&a.catchUpHtml&&(0,E.jsx)(ga,{html:a.catchUpHtml,className:"so-catch-up"}),c.messages.length===0&&(!f&&a.firstRun?null:f?(0,E.jsxs)("div",{className:"so-docked-empty",children:[(0,E.jsx)("p",{className:"so-docked-empty-title",children:f.title}),(0,E.jsx)("p",{className:"so-docked-empty-hint",children:f.hint}),(0,E.jsx)("div",{className:"so-suggestions",children:f.suggestions.map(R=>(0,E.jsx)("button",{type:"button",className:"so-suggestion",onClick:()=>{e.edit(R),u.current?.focus()},children:R.trim().replace(/:$/,"…")},R))})]}):(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(cR,{title:"What would you like to work on?",description:"Plan the work with your lead. Your crew’s tasks and results stay beside the conversation."}),(0,E.jsxs)("nav",{className:"so-kit-links","aria-label":"Starter kits","data-kit-links":!0,children:[(0,E.jsx)("span",{children:"Or start from a kit:"}),LY.map(([R,P])=>(0,E.jsx)("a",{className:"so-suggestion",href:`/kits/${R}`,children:P},R))]})]})),(0,E.jsx)("div",{id:"chat-thread","data-chat-region":"thread",children:c.messages.map(R=>(0,E.jsxs)($0,{from:R.role==="operator"?"user":"assistant","data-message-id":R.id,children:[(0,E.jsx)("div",{className:"so-message-label",children:R.role==="operator"?"You":"Lead"}),(0,E.jsxs)(W0,{children:[(0,E.jsx)(ga,{html:R.html}),R.activity&&(0,E.jsx)(dn,{summary:"Activity",children:(0,E.jsx)("p",{className:"so-activity-copy",children:R.activity})}),R.cards!==void 0&&R.cards.length>0?(0,E.jsx)(lA,{cards:R.cards,csrf:a.csrf,onChanged:()=>{e.check()}}):R.cardsHtml&&(0,E.jsx)(ga,{html:R.cardsHtml,className:"so-message-cards"})]})]},R.id))}),(d||S!==null)&&(0,E.jsx)(IY,{live:S})]}),(0,E.jsx)(uR,{})]}),(0,E.jsxs)("div",{className:"so-composer-area",children:[I&&(0,E.jsxs)("div",{className:"so-connection",role:i?"alert":"status",children:[(0,E.jsx)("span",{children:I}),i?(0,E.jsx)(Be,{variant:"secondary",size:"sm",onClick:e.reconnect,children:"Reconnect"}):!s&&!l&&(0,E.jsx)(Be,{variant:"ghost",size:"sm",onClick:()=>{e.check()},children:"Check again"})]}),(0,E.jsxs)("form",{onSubmit:e.send,action:"/chat",method:"post","data-workspace-composer":!0,"aria-busy":s,children:[(0,E.jsx)(Si,{htmlFor:"lead-message",className:"so-sr-only",children:"Message your lead"}),h.length>0&&(0,E.jsx)("ul",{id:w,role:"listbox","aria-label":"Commands",className:"so-slash-menu",children:h.map((R,P)=>(0,E.jsxs)("li",{role:"option","aria-selected":P===Math.min(v,h.length-1),onMouseDown:O=>{O.preventDefault(),C(R)},children:[(0,E.jsxs)("span",{className:"so-slash-name",children:["/",R.command]}),(0,E.jsx)("span",{className:"so-slash-hint",children:R.hint})]},R.command))}),(0,E.jsx)(ps,{ref:u,id:"lead-message",name:"message",rows:2,maxLength:c.maxChars,placeholder:f?.placeholder??"Message your lead…",value:o.text,role:h.length>0?"combobox":void 0,"aria-expanded":h.length>0?!0:void 0,"aria-controls":h.length>0?w:void 0,onChange:R=>{y(!1),e.edit(R.target.value)},onKeyDown:R=>{if(h.length>0){let P=Math.min(v,h.length-1);if(R.key==="ArrowDown"||R.key==="ArrowUp"){R.preventDefault(),b((P+(R.key==="ArrowDown"?1:h.length-1))%h.length);return}if(R.key==="Enter"&&!R.shiftKey||R.key==="Tab"){R.preventDefault(),C(h[P]);return}if(R.key==="Escape"){R.preventDefault(),y(!0);return}}R.key==="Enter"&&!R.shiftKey&&!R.nativeEvent.isComposing&&(R.preventDefault(),L||R.currentTarget.form?.requestSubmit())},"aria-describedby":"composer-hint"}),(0,E.jsxs)("div",{className:"so-composer-actions",children:[(0,E.jsx)("span",{id:"composer-hint",children:r?o.text.length>c.maxChars-200?`${o.text.length} / ${c.maxChars}`:"/ for commands · Shift + Enter for a new line":"Draft stays on this page only."}),(0,E.jsxs)(Be,{type:"submit",disabled:L,"aria-label":"Send message",children:[(0,E.jsx)(Jo,{name:"send"}),(0,E.jsx)("span",{children:"Send"})]})]})]}),!f&&a.controlsHtml&&(0,E.jsx)(dn,{summary:"Conversation settings",className:"so-conversation-settings",children:(0,E.jsx)(ga,{html:a.controlsHtml,immutable:!0})})]})]})}function RY(){(0,Te.useEffect)(()=>{let e=()=>{(window.scrollX!==0||window.scrollY!==0)&&window.scrollTo(0,0)},t=()=>{let o=decodeURIComponent(window.location.hash.slice(1));o!==""&&o!=="workspace-main"&&document.getElementById(o)?.scrollIntoView({block:"start"}),e()},a=requestAnimationFrame(t);return window.addEventListener("scroll",e,{passive:!0}),window.addEventListener("hashchange",t),()=>{cancelAnimationFrame(a),window.removeEventListener("scroll",e),window.removeEventListener("hashchange",t)}},[])}function NY({initial:e}){let t=bY(e),[a,o]=(0,Te.useState)(e.team),n=a?.tasks?{...t.workspace,...ER(a.tasks,a.selected?.id)}:t.workspace,[r,s]=(0,Te.useState)(n.result||n.focus?"work":"chat"),i=n.focus!==null||n.result!==null,l=n.crew.find(w=>w.id===n.focus?.id),c=n.navigation.some(w=>w.label==="Chat"&&w.active),f=n.navigation.find(w=>w.active)?.label??n.title.charAt(0).toUpperCase()+n.title.slice(1),u=!n.team&&n.conversation!==null&&n.view!=null,[d,p]=(0,Te.useState)("chat"),g=!n.team&&(!n.conversation||u),v=new URL(n.path,window.location.origin).pathname,b=g&&!u&&!i&&(yY.has(v)||v.startsWith("/code/")||n.view?.kind==="flow"),[x,y]=(0,Te.useState)(null),h=n.update!==void 0&&n.update.version!==x?n.update:null;return(0,Te.useEffect)(ob,[]),RY(),(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(ME,{}),(0,E.jsxs)("div",{className:`so-workspace${b?" so-workspace--single":""}${u?" so-workspace--docked":""}`,"data-workspace-shell":!0,"data-workspace-phone-view":r,"data-workspace-has-result":n.result!==null,children:[(0,E.jsx)("a",{href:"#workspace-main",className:"so-skip-link",children:"Skip to content"}),(0,E.jsx)("aside",{className:"so-sidebar",children:(0,E.jsx)(gB,{workspace:n})}),(0,E.jsxs)("div",{className:`so-main-column${c?" so-main-column--chat":""}`,children:[(0,E.jsxs)("header",{className:"so-workspace-header",children:[(0,E.jsx)(SY,{workspace:n}),g?(0,E.jsx)("p",{className:"so-header-title",children:f}):(0,E.jsx)("h1",{children:c?"Lead":f}),n.focus&&c&&(0,E.jsx)("span",{className:"so-focus-label",title:n.focus.title,children:n.focus.title}),(0,E.jsx)(CY,{workspace:n}),c&&(0,E.jsx)(Be,{variant:"secondary",size:"sm",className:"so-phone-work-button",onClick:()=>s("work"),children:i?"Open work":"Crew"}),u&&(0,E.jsxs)(Be,{variant:"secondary",size:"sm",className:"so-phone-work-button",onClick:()=>{p("chat"),s("work")},children:[(0,E.jsx)(Jo,{name:"chat"}),"Ask"]})]}),(n.notices.length>0||(n.signIn?.length??0)>0||h!==null)&&(0,E.jsxs)("div",{className:"so-workspace-notices",children:[n.signIn?.map(w=>(0,E.jsxs)(jo,{className:"so-sign-in","data-sign-in":w.provider,children:[(0,E.jsx)("p",{className:"so-sign-in-title",children:w.title}),(0,E.jsxs)("p",{className:"so-sign-in-detail",children:["Run ",(0,E.jsx)("code",{children:w.command})," on this computer, then resume.",w.detail===""?"":` ${w.detail}`]}),(0,E.jsxs)("form",{method:"post",action:w.resumeHref,children:[(0,E.jsx)("input",{type:"hidden",name:"csrf",value:n.csrf}),(0,E.jsx)(Be,{size:"sm",type:"submit",children:w.resumeLabel})]})]},w.provider)),n.notices.map((w,C)=>(0,E.jsx)(jo,{children:w},C)),h!==null&&(0,E.jsxs)(jo,{className:"so-update","data-update":h.version,children:[(0,E.jsxs)("p",{children:[(0,E.jsx)("span",{children:iB(h)})," · ",(0,E.jsx)("a",{href:h.href,children:"What's new"})]}),(0,E.jsxs)("form",{method:"post",action:h.dismissHref,onSubmit:w=>{w.preventDefault(),y(h.version),fetch(h.dismissHref,{method:"POST",body:new URLSearchParams({csrf:n.csrf,version:h.version,quiet:"1"})}).catch(()=>{})},children:[(0,E.jsx)("input",{type:"hidden",name:"csrf",value:n.csrf}),(0,E.jsx)("input",{type:"hidden",name:"version",value:h.version}),(0,E.jsx)(Be,{variant:"ghost",size:"icon",type:"submit","aria-label":`Dismiss the notice about ${h.version}`,children:(0,E.jsx)(Jo,{name:"close"})})]})]})]}),(0,E.jsx)("main",{id:"workspace-main",className:"so-main-content",tabIndex:-1,children:n.team?(0,E.jsx)(NR,{initial:n.team,user:n.user,csrf:n.csrf,onSnapshot:o}):n.conversation&&!u?(0,E.jsx)(fB,{controller:t}):(0,E.jsxs)("div",{className:"so-page-content","data-workspace-page":!0,children:[c&&n.firstRun&&(0,E.jsx)(Kb,{firstRun:n.firstRun}),n.view?(0,E.jsx)(sB,{view:n.view,csrf:n.csrf}):(0,E.jsx)(ga,{html:e.pageHtml??"",immutable:!0})]})})]}),u&&(0,E.jsxs)("aside",{className:"so-supporting-panel so-ask-panel","data-workspace-detail":!0,"aria-label":"Ask",children:[(0,E.jsxs)("div",{className:"so-ask-header",children:[(0,E.jsxs)(Be,{variant:"ghost",size:"sm",className:"so-phone-back",onClick:()=>s("chat"),children:[(0,E.jsx)(Jo,{name:"arrow"}),"Back"]}),(0,E.jsxs)("div",{role:"tablist","aria-label":"Panel",className:"so-ask-tabs",children:[(0,E.jsx)("button",{type:"button",role:"tab","aria-selected":d==="chat",onClick:()=>p("chat"),children:"Chat"}),(0,E.jsx)("button",{type:"button",role:"tab","aria-selected":d==="crew",onClick:()=>p("crew"),children:"Crew"})]})]}),(0,E.jsx)("div",{className:"so-ask-body",hidden:d!=="chat",children:(0,E.jsx)(fB,{controller:t,docked:n.view?.kind??"task"})}),d==="crew"&&(0,E.jsx)(cB,{workspace:n})]}),!b&&!u&&(0,E.jsxs)("aside",{className:`so-supporting-panel${i?" so-supporting-panel--detail":""}`,"data-workspace-detail":!0,children:[(0,E.jsxs)("div",{className:"so-work-panel-header",children:[(0,E.jsxs)(Be,{variant:"ghost",size:"sm",className:"so-phone-back",onClick:()=>s("chat"),children:[(0,E.jsx)(Jo,{name:"arrow"}),c?"Back to chat":"Back"]}),i&&(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)("h2",{children:n.result?"Result":"Task"}),n.result&&l&&(0,E.jsxs)(Lu,{tone:hB(l.tone),className:"so-current-task-state","data-workspace-current-task-state":!0,children:["Task: ",l.label]}),(0,E.jsx)("a",{href:a?.selected?"/chat?conversation="+encodeURIComponent(a.selected.id):"/chat",className:"so-close-work","aria-label":"Close work and return to the main chat",children:(0,E.jsx)(Jo,{name:"close"})})]})]}),i?(0,E.jsxs)("div",{className:"so-work-detail-content",children:[n.focus&&(n.result?(0,E.jsx)(dn,{summary:"Task details",className:"so-result-task-details",children:(0,E.jsx)(ga,{html:n.focus.html,className:"so-task-context"},n.focus.id)}):(0,E.jsx)(ga,{html:n.focus.html,className:"so-task-context"},n.focus.id)),n.result&&(0,E.jsx)(dR,{"data-workspace-result":n.result.runId,children:(0,E.jsx)(fR,{children:(0,E.jsx)(ga,{html:n.result.html,immutable:!0},n.result.runId)})})]}):(0,E.jsx)(cB,{workspace:n})]})]})]})}var xB=e=>{let t=e.viewTransition;for(let a of[t?.finished,t?.ready,t?.updateCallbackDone])a?.catch(()=>{})};window.addEventListener("pageswap",xB);window.addEventListener("pagereveal",xB);var rC=document.getElementById("standing-orders-workspace"),pB=document.getElementById("standing-orders-workspace-data");if(rC&&pB)try{let e=JSON.parse(pB.textContent??"null");if(!eb(e))throw new Error("Workspace data is incomplete");(0,mB.createRoot)(rC).render((0,E.jsx)(NY,{initial:e}))}catch{rC.setAttribute("data-workspace-unavailable","true")}export{CY as CommandMenu,ga as GuardedHtml,NY as WorkspaceApp,AR as regionIsEditing,bY as useWorkspace,wY as workspaceCommands};
|
|
68
68
|
/*! Bundled license information:
|
|
69
69
|
|