@useorgx/openclaw-plugin 0.7.26 → 0.7.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/dashboard/dist/assets/BGqqzQfq.js +1 -0
  2. package/dashboard/dist/assets/BGqqzQfq.js.br +0 -0
  3. package/dashboard/dist/assets/BGqqzQfq.js.gz +0 -0
  4. package/dashboard/dist/assets/BIW2kmQr.js +1 -0
  5. package/dashboard/dist/assets/BIW2kmQr.js.br +0 -0
  6. package/dashboard/dist/assets/BIW2kmQr.js.gz +0 -0
  7. package/dashboard/dist/assets/{BZCkOZ20.js → BLCzNocO.js} +1 -1
  8. package/dashboard/dist/assets/BLCzNocO.js.br +0 -0
  9. package/dashboard/dist/assets/BLCzNocO.js.gz +0 -0
  10. package/dashboard/dist/assets/BYsvgOkA.js +1 -0
  11. package/dashboard/dist/assets/BYsvgOkA.js.br +0 -0
  12. package/dashboard/dist/assets/BYsvgOkA.js.gz +0 -0
  13. package/dashboard/dist/assets/BafISmbX.js +1 -0
  14. package/dashboard/dist/assets/BafISmbX.js.br +0 -0
  15. package/dashboard/dist/assets/BafISmbX.js.gz +0 -0
  16. package/dashboard/dist/assets/CDsk---g.js +1 -0
  17. package/dashboard/dist/assets/CDsk---g.js.br +0 -0
  18. package/dashboard/dist/assets/CDsk---g.js.gz +0 -0
  19. package/dashboard/dist/assets/{BvFcH_Iy.js → CJ0ozAqs.js} +1 -1
  20. package/dashboard/dist/assets/CJ0ozAqs.js.br +0 -0
  21. package/dashboard/dist/assets/CJ0ozAqs.js.gz +0 -0
  22. package/dashboard/dist/assets/{MrW1ixGx.js → CKUnb6Tt.js} +1 -1
  23. package/dashboard/dist/assets/CKUnb6Tt.js.br +0 -0
  24. package/dashboard/dist/assets/CKUnb6Tt.js.gz +0 -0
  25. package/dashboard/dist/assets/{B_LdOJUa.js → CPfdWIdE.js} +1 -1
  26. package/dashboard/dist/assets/CPfdWIdE.js.br +0 -0
  27. package/dashboard/dist/assets/CPfdWIdE.js.gz +0 -0
  28. package/dashboard/dist/assets/{B6VftyY6.js → CQceXoUm.js} +1 -1
  29. package/dashboard/dist/assets/CQceXoUm.js.br +0 -0
  30. package/dashboard/dist/assets/CQceXoUm.js.gz +0 -0
  31. package/dashboard/dist/assets/{BANQdlC4.js → CgCm4tUc.js} +1 -1
  32. package/dashboard/dist/assets/CgCm4tUc.js.br +0 -0
  33. package/dashboard/dist/assets/CgCm4tUc.js.gz +0 -0
  34. package/dashboard/dist/assets/{DJYl7gyA.js → Cgp0m1Ld.js} +1 -1
  35. package/dashboard/dist/assets/Cgp0m1Ld.js.br +0 -0
  36. package/dashboard/dist/assets/Cgp0m1Ld.js.gz +0 -0
  37. package/dashboard/dist/assets/{DZtNMX0t.js → CjGl4MOt.js} +1 -1
  38. package/dashboard/dist/assets/CjGl4MOt.js.br +0 -0
  39. package/dashboard/dist/assets/CjGl4MOt.js.gz +0 -0
  40. package/dashboard/dist/assets/DNCNDTzi.js +212 -0
  41. package/dashboard/dist/assets/DNCNDTzi.js.br +0 -0
  42. package/dashboard/dist/assets/DNCNDTzi.js.gz +0 -0
  43. package/dashboard/dist/assets/dgbgHLWm.js +1 -0
  44. package/dashboard/dist/assets/dgbgHLWm.js.br +0 -0
  45. package/dashboard/dist/assets/dgbgHLWm.js.gz +0 -0
  46. package/dashboard/dist/assets/h2T7lbDc.js +1 -0
  47. package/dashboard/dist/assets/h2T7lbDc.js.br +0 -0
  48. package/dashboard/dist/assets/h2T7lbDc.js.gz +0 -0
  49. package/dashboard/dist/assets/oWHKFgkC.js +1 -0
  50. package/dashboard/dist/assets/oWHKFgkC.js.br +0 -0
  51. package/dashboard/dist/assets/oWHKFgkC.js.gz +0 -0
  52. package/dashboard/dist/assets/{CqRNb2EL.js → qD5absr0.js} +1 -1
  53. package/dashboard/dist/assets/qD5absr0.js.br +0 -0
  54. package/dashboard/dist/assets/qD5absr0.js.gz +0 -0
  55. package/dashboard/dist/assets/wzn4QuPG.css +1 -0
  56. package/dashboard/dist/assets/wzn4QuPG.css.br +0 -0
  57. package/dashboard/dist/assets/wzn4QuPG.css.gz +0 -0
  58. package/dashboard/dist/index.html +2 -2
  59. package/dashboard/dist/index.html.br +0 -0
  60. package/dashboard/dist/index.html.gz +0 -0
  61. package/dist/openclaw.plugin.json +1 -1
  62. package/openclaw.plugin.json +1 -1
  63. package/package.json +1 -1
  64. package/dashboard/dist/assets/B6VftyY6.js.br +0 -0
  65. package/dashboard/dist/assets/B6VftyY6.js.gz +0 -0
  66. package/dashboard/dist/assets/BANQdlC4.js.br +0 -0
  67. package/dashboard/dist/assets/BANQdlC4.js.gz +0 -0
  68. package/dashboard/dist/assets/BPL4CL3c.js +0 -1
  69. package/dashboard/dist/assets/BPL4CL3c.js.br +0 -0
  70. package/dashboard/dist/assets/BPL4CL3c.js.gz +0 -0
  71. package/dashboard/dist/assets/BZCkOZ20.js.br +0 -0
  72. package/dashboard/dist/assets/BZCkOZ20.js.gz +0 -0
  73. package/dashboard/dist/assets/B_LdOJUa.js.br +0 -0
  74. package/dashboard/dist/assets/B_LdOJUa.js.gz +0 -0
  75. package/dashboard/dist/assets/Bfp-wdwb.css +0 -1
  76. package/dashboard/dist/assets/Bfp-wdwb.css.br +0 -0
  77. package/dashboard/dist/assets/Bfp-wdwb.css.gz +0 -0
  78. package/dashboard/dist/assets/BvFcH_Iy.js.br +0 -0
  79. package/dashboard/dist/assets/BvFcH_Iy.js.gz +0 -0
  80. package/dashboard/dist/assets/By0MIBj_.js +0 -1
  81. package/dashboard/dist/assets/By0MIBj_.js.br +0 -0
  82. package/dashboard/dist/assets/By0MIBj_.js.gz +0 -0
  83. package/dashboard/dist/assets/C0i7ABUU.js +0 -212
  84. package/dashboard/dist/assets/C0i7ABUU.js.br +0 -0
  85. package/dashboard/dist/assets/C0i7ABUU.js.gz +0 -0
  86. package/dashboard/dist/assets/CFB0MM7j.js +0 -1
  87. package/dashboard/dist/assets/CFB0MM7j.js.br +0 -0
  88. package/dashboard/dist/assets/CFB0MM7j.js.gz +0 -0
  89. package/dashboard/dist/assets/CQSRb1yu.js +0 -1
  90. package/dashboard/dist/assets/CQSRb1yu.js.br +0 -0
  91. package/dashboard/dist/assets/CQSRb1yu.js.gz +0 -0
  92. package/dashboard/dist/assets/CUoQoSm-.js +0 -1
  93. package/dashboard/dist/assets/CUoQoSm-.js.br +0 -0
  94. package/dashboard/dist/assets/CUoQoSm-.js.gz +0 -0
  95. package/dashboard/dist/assets/Ckd1R1iE.js +0 -1
  96. package/dashboard/dist/assets/Ckd1R1iE.js.br +0 -0
  97. package/dashboard/dist/assets/Ckd1R1iE.js.gz +0 -0
  98. package/dashboard/dist/assets/CqRNb2EL.js.br +0 -0
  99. package/dashboard/dist/assets/CqRNb2EL.js.gz +0 -0
  100. package/dashboard/dist/assets/DClUc9rw.js +0 -1
  101. package/dashboard/dist/assets/DClUc9rw.js.br +0 -0
  102. package/dashboard/dist/assets/DClUc9rw.js.gz +0 -0
  103. package/dashboard/dist/assets/DF2PMTwT.js +0 -1
  104. package/dashboard/dist/assets/DF2PMTwT.js.br +0 -0
  105. package/dashboard/dist/assets/DF2PMTwT.js.gz +0 -0
  106. package/dashboard/dist/assets/DJYl7gyA.js.br +0 -0
  107. package/dashboard/dist/assets/DJYl7gyA.js.gz +0 -0
  108. package/dashboard/dist/assets/DZtNMX0t.js.br +0 -0
  109. package/dashboard/dist/assets/DZtNMX0t.js.gz +0 -0
  110. package/dashboard/dist/assets/DlEa8PI0.js +0 -1
  111. package/dashboard/dist/assets/DlEa8PI0.js.br +0 -0
  112. package/dashboard/dist/assets/DlEa8PI0.js.gz +0 -0
  113. package/dashboard/dist/assets/M4QxcXjh.js +0 -1
  114. package/dashboard/dist/assets/M4QxcXjh.js.br +0 -0
  115. package/dashboard/dist/assets/M4QxcXjh.js.gz +0 -0
  116. package/dashboard/dist/assets/MrW1ixGx.js.br +0 -0
  117. package/dashboard/dist/assets/MrW1ixGx.js.gz +0 -0
@@ -1 +1 @@
1
- import{j as r}from"./Dj2k1r16.js";import{C as s}from"./C0i7ABUU.js";function i({className:e=""}){return r.jsx("div",{className:s("shimmer-skeleton",e),"aria-hidden":"true"})}export{i as S};
1
+ import{j as r}from"./Dj2k1r16.js";import{C as s}from"./DNCNDTzi.js";function i({className:e=""}){return r.jsx("div",{className:s("shimmer-skeleton",e),"aria-hidden":"true"})}export{i as S};
@@ -0,0 +1 @@
1
+ import{r as o,j as e}from"./Dj2k1r16.js";import{f as l,z as p,E as h,a3 as u}from"./DNCNDTzi.js";import{DecisionQueue as b}from"./CDsk---g.js";import"./DMKyYAtD.js";import"./eeHXe_OQ.js";import"./cX2e-TLi.js";import"./BjK42gtU.js";import"./BV0BcV1u.js";import"./qD5absr0.js";function k({open:n,onClose:a,decisions:t,onApproveDecision:i,onRejectDecision:d,onApproveAll:m,onBulkDecisionAction:x}){const r=o.useMemo(()=>t.length>0?Math.max(0,...t.map(c=>c.waitingMinutes)):0,[t]),s=o.useMemo(()=>t.length>=20||r>=15?l.red:t.length>0?l.amber:l.textMuted,[t.length,r]);return e.jsx(p,{open:n,onClose:a,maxWidth:"max-w-3xl",children:e.jsxs("div",{className:"flex h-full w-full flex-col",children:[e.jsx("div",{className:"border-b border-subtle px-5 pt-5 pb-4",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h3",{className:"inline-flex items-center gap-2 text-heading font-semibold text-white",children:[e.jsx(h,{type:"decision",size:14}),e.jsx("span",{className:"truncate",children:"Decisions"}),e.jsx("span",{className:"rounded-full border px-2 py-0.5 text-caption font-semibold",style:{borderColor:`${s}30`,backgroundColor:`${s}14`,color:s},children:t.length})]}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:"Bulk review and resolve pending decisions."}),t.length>0&&e.jsxs("p",{className:"mt-2 text-caption text-secondary",children:["Oldest: ",e.jsxs("span",{className:"font-semibold text-white",children:[u(r)," ago"]})]})]}),e.jsx("button",{type:"button",onClick:a,className:"rounded-md border border-strong bg-white/[0.03] px-2.5 py-1.5 text-caption text-primary transition-colors hover:bg-white/[0.08]","aria-label":"Close decisions modal",children:"Close"})]})}),e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden p-4",children:e.jsx(b,{decisions:t,onApproveDecision:i,onRejectDecision:d,onApproveAll:m,onBulkDecisionAction:x})})]})})}export{k as BulkDecisionsModal};
@@ -0,0 +1 @@
1
+ import{r as p,j as e}from"./Dj2k1r16.js";import{A as v,m as w}from"./eeHXe_OQ.js";function k(s){switch(s){case"decision_required":return"Decision required";case"blocked_intervention":return"Blocked — needs intervention";case"review_required":return"Review required";case"failure_diagnostic":return"Failure diagnostic";default:return s}}function A(s){switch(s){case"critical":return"#FF6B6B";case"high":return"#F5B700";case"medium":return"#0AD4C4";default:return"#8B8FA3"}}function C(s){const t=s.intervention,n=new Set;if(!t)return n.add("Intervention brief"),Array.from(n);const r=Array.isArray(t.evidence)&&t.evidence.length>0||s.proofBundle.artifactRefs.length>0||s.proofBundle.logRefs.length>0||s.proofBundle.prRefs.length>0||s.proofBundle.fileChanges.length>0,a=Array.isArray(t.scopeHierarchy)&&t.scopeHierarchy.length>0,i=!!t.requiredAction||!!t.recommendedAction;return s.kind==="decision_required"||s.kind==="review_required"?(!t.decisionPrompt&&!t.decisionSummary&&n.add("Decision prompt"),(!Array.isArray(t.decisionOptions)||t.decisionOptions.length===0)&&n.add("Decision options"),i||n.add("Recommended action"),r||n.add("Supporting evidence"),a||n.add("Affected scope"),Array.from(n)):(!t.blockerReason&&!s.summary&&n.add("Blocker reason"),i||n.add("Required action"),!t.waitingOn&&!t.currentRunState&&n.add("What is blocked"),r||n.add("Supporting evidence"),a||n.add("Affected scope"),Array.from(n))}function B({missing:s}){return s.length===0?null:e.jsxs("div",{className:"rounded-xl border border-amber-300/20 bg-amber-300/[0.08] px-3.5 py-3",children:[e.jsx("p",{className:"text-micro font-semibold uppercase tracking-wider text-amber-100",children:"Signal incomplete"}),e.jsx("p",{className:"mt-1 text-caption text-amber-50/90",children:"This intervention is missing context the operator needs to act cleanly."}),e.jsx("ul",{className:"mt-2 space-y-0.5",children:s.map(t=>e.jsxs("li",{className:"text-caption text-amber-100/85",children:["- ",t]},t))}),e.jsx("p",{className:"mt-2 text-micro text-amber-100/60",children:"Raw diagnostics remain available under Technical details."})]})}function E(s,t){const n=new Set(C(s));return t&&((t.context??"").trim().length>0&&(n.delete("Decision prompt"),n.delete("Decision context")),Array.isArray(t.options)&&t.options.length>0&&n.delete("Decision options"),(t.recommendedAction??"").trim().length>0&&n.delete("Recommended action"),Array.isArray(t.evidenceRefs)&&t.evidenceRefs.length>0&&n.delete("Supporting evidence")),Array.from(n)}function b({children:s}){return e.jsx("h4",{className:"text-micro font-semibold uppercase tracking-wider text-muted mb-1.5",children:s})}function R({item:s}){const t=s.proofBundle;return t.artifactRefs.length>0||t.fileChanges.length>0||t.prRefs.length>0||t.logRefs.length>0||t.decisionRefs.length>0?e.jsxs("div",{children:[e.jsx(b,{children:"Proof"}),e.jsxs("div",{className:"space-y-1",children:[t.prRefs.map((r,a)=>e.jsx(h,{icon:"pr",label:r},`pr-${a}`)),t.fileChanges.map((r,a)=>e.jsx(h,{icon:"file",label:r},`file-${a}`)),t.artifactRefs.map((r,a)=>e.jsx(h,{icon:"artifact",label:r},`art-${a}`)),t.logRefs.map((r,a)=>e.jsx(h,{icon:"log",label:r},`log-${a}`)),t.decisionRefs.map((r,a)=>e.jsx(h,{icon:"decision",label:r},`dec-${a}`))]})]}):null}function h({icon:s,label:t}){const n=s==="pr"?"⎇":s==="file"?"◇":s==="log"?"▸":s==="decision"?"◈":"▪";return e.jsxs("div",{className:"flex items-center gap-2 rounded bg-white/[0.03] px-2 py-1 text-caption text-secondary",children:[e.jsx("span",{className:"text-muted flex-shrink-0 w-4 text-center",children:n}),e.jsx("span",{className:"truncate",children:t})]})}function D({item:s}){const{impact:t}=s;return t.initiativeCount===0&&t.workstreamCount===0&&t.downstreamBlockedCount===0?null:e.jsxs("div",{children:[e.jsx(b,{children:"Impact if ignored"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[t.initiativeCount>0&&e.jsx(j,{label:`${t.initiativeCount} initiative${t.initiativeCount>1?"s":""}`}),t.workstreamCount>0&&e.jsx(j,{label:`${t.workstreamCount} workstream${t.workstreamCount>1?"s":""}`}),t.downstreamBlockedCount>0&&e.jsx(j,{label:`${t.downstreamBlockedCount} blocked downstream`,tone:"red"})]})]})}function S({item:s}){const t=s.intervention;return!t||!(!!t.blockerReason||!!t.decisionPrompt||!!t.decisionSummary||!!t.waitingOn||!!t.requiredAction||!!t.recommendedAction||!!t.requiredActor||!!t.errorCode||!!t.errorCategory||!!t.currentRunState||!!t.impactIfDelayed||typeof t.retryable=="boolean"||Array.isArray(t.suggestedActions)&&t.suggestedActions.length>0||Array.isArray(t.nextActions)&&t.nextActions.length>0||Array.isArray(t.scopeHierarchy)&&t.scopeHierarchy.length>0||Array.isArray(t.decisionOptions)&&t.decisionOptions.length>0||Array.isArray(t.evidence)&&t.evidence.length>0||Array.isArray(t.artifacts)&&t.artifacts.length>0||Array.isArray(t.updatesApplied)&&t.updatesApplied.length>0||typeof t.taskUpdateCount=="number"||typeof t.milestoneUpdateCount=="number")?null:e.jsxs("div",{children:[e.jsx(b,{children:"Intervention brief"}),e.jsxs("div",{className:"space-y-2 rounded-lg border border-white/[0.08] bg-white/[0.02] px-3 py-2.5",children:[Array.isArray(t.scopeHierarchy)&&t.scopeHierarchy.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-micro uppercase tracking-wider text-muted",children:"Scope"}),e.jsx("p",{className:"text-caption text-primary",children:t.scopeHierarchy.join(" › ")})]}),t.decisionPrompt&&e.jsxs("div",{children:[e.jsx("p",{className:"text-micro uppercase tracking-wider text-muted",children:"Decision prompt"}),e.jsx("p",{className:"text-caption text-primary",children:t.decisionPrompt}),t.decisionSummary&&e.jsx("p",{className:"mt-1 text-caption text-secondary",children:t.decisionSummary})]}),t.blockerReason&&e.jsxs("div",{children:[e.jsx("p",{className:"text-micro uppercase tracking-wider text-muted",children:"Blocker"}),e.jsx("p",{className:"text-caption text-primary",children:t.blockerReason})]}),t.requiredAction&&e.jsxs("div",{children:[e.jsx("p",{className:"text-micro uppercase tracking-wider text-muted",children:"Required action"}),e.jsx("p",{className:"text-caption text-[#7AEDE5]",children:t.requiredAction})]}),t.recommendedAction&&t.recommendedAction!==t.requiredAction&&e.jsxs("div",{children:[e.jsx("p",{className:"text-micro uppercase tracking-wider text-muted",children:"Recommended"}),e.jsx("p",{className:"text-caption text-[#7AEDE5]",children:t.recommendedAction})]}),t.waitingOn&&e.jsxs("div",{children:[e.jsx("p",{className:"text-micro uppercase tracking-wider text-muted",children:"Waiting on"}),e.jsx("p",{className:"text-caption text-secondary",children:t.waitingOn})]}),(t.currentRunState||t.impactIfDelayed)&&e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2",children:[t.currentRunState&&e.jsxs("div",{children:[e.jsx("p",{className:"text-micro uppercase tracking-wider text-muted",children:"Run state"}),e.jsx("p",{className:"text-caption text-secondary",children:t.currentRunState})]}),t.impactIfDelayed&&e.jsxs("div",{children:[e.jsx("p",{className:"text-micro uppercase tracking-wider text-muted",children:"Impact if delayed"}),e.jsx("p",{className:"text-caption text-secondary",children:t.impactIfDelayed})]})]}),(t.errorCode||t.errorCategory||typeof t.retryable=="boolean")&&e.jsxs("div",{className:"flex flex-wrap gap-2",children:[t.errorCode&&e.jsxs("span",{className:"rounded bg-white/[0.06] px-1.5 py-0.5 text-micro text-secondary",children:["Error: ",t.errorCode]}),t.errorCategory&&e.jsxs("span",{className:"rounded bg-white/[0.06] px-1.5 py-0.5 text-micro text-secondary",children:["Category: ",t.errorCategory]}),typeof t.retryable=="boolean"&&e.jsx("span",{className:"rounded bg-white/[0.06] px-1.5 py-0.5 text-micro text-secondary",children:t.retryable?"Retryable":"Non-retryable"})]}),Array.isArray(t.decisionOptions)&&t.decisionOptions.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-micro uppercase tracking-wider text-muted",children:"Options"}),e.jsx("div",{className:"mt-1.5 space-y-1.5",children:t.decisionOptions.slice(0,6).map((r,a)=>e.jsxs("div",{className:"rounded-lg border border-white/[0.06] bg-black/[0.18] px-2.5 py-2",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx("p",{className:"text-caption font-medium text-primary",children:r.label}),r.recommended?e.jsx("span",{className:"rounded-full bg-[#0AD4C4]/12 px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wider text-[#7AEDE5]",children:"Recommended"}):null]}),r.description?e.jsx("p",{className:"mt-1 text-caption text-secondary",children:r.description}):null,r.consequences?e.jsx("p",{className:"mt-1 text-micro text-muted",children:r.consequences}):null]},`${r.id??r.label}-${a}`))})]}),((t.taskUpdateCount??0)>0||(t.milestoneUpdateCount??0)>0)&&e.jsxs("div",{className:"flex flex-wrap gap-2",children:[(t.taskUpdateCount??0)>0&&e.jsxs("span",{className:"rounded bg-[#0AD4C4]/12 px-1.5 py-0.5 text-micro text-[#7AEDE5]",children:[t.taskUpdateCount," task update",t.taskUpdateCount===1?"":"s"]}),(t.milestoneUpdateCount??0)>0&&e.jsxs("span",{className:"rounded bg-[#0AD4C4]/12 px-1.5 py-0.5 text-micro text-[#7AEDE5]",children:[t.milestoneUpdateCount," milestone update",t.milestoneUpdateCount===1?"":"s"]})]}),Array.isArray(t.updatesApplied)&&t.updatesApplied.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-micro uppercase tracking-wider text-muted",children:"Updates applied"}),e.jsx("ul",{className:"mt-1 space-y-0.5",children:t.updatesApplied.slice(0,4).map(r=>e.jsxs("li",{className:"text-caption text-secondary",children:["- ",r]},r))})]}),Array.isArray(t.artifacts)&&t.artifacts.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-micro uppercase tracking-wider text-muted",children:"Artifacts"}),e.jsx("ul",{className:"mt-1 space-y-0.5",children:t.artifacts.slice(0,4).map(r=>e.jsxs("li",{className:"text-caption text-secondary",children:["- ",r]},r))})]}),Array.isArray(t.evidence)&&t.evidence.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-micro uppercase tracking-wider text-muted",children:"Evidence"}),e.jsx("div",{className:"mt-1.5 space-y-1.5",children:t.evidence.slice(0,4).map((r,a)=>e.jsxs("div",{className:"rounded-lg border border-white/[0.06] bg-black/[0.18] px-2.5 py-2",children:[e.jsx("p",{className:"text-caption font-medium text-primary",children:r.title}),r.summary?e.jsx("p",{className:"mt-1 text-caption text-secondary",children:r.summary}):null,(r.url||r.pointer)&&e.jsxs("p",{className:"mt-1 text-micro text-muted",children:[r.url?e.jsx("a",{href:r.url,target:"_blank",rel:"noopener noreferrer",className:"text-[#7AEDE5] transition-colors hover:text-white",children:"Open source"}):r.pointer,r.url&&r.pointer?` · ${r.pointer}`:null]})]},`${r.title}-${a}`))})]}),Array.isArray(t.suggestedActions)&&t.suggestedActions.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-micro uppercase tracking-wider text-muted",children:"Suggested actions"}),e.jsx("ul",{className:"mt-1 space-y-0.5",children:t.suggestedActions.slice(0,4).map(r=>e.jsxs("li",{className:"text-caption text-secondary",children:["- ",r]},r))})]}),Array.isArray(t.nextActions)&&t.nextActions.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-micro uppercase tracking-wider text-muted",children:"Next up"}),e.jsx("ul",{className:"mt-1 space-y-0.5",children:t.nextActions.slice(0,4).map(r=>e.jsxs("li",{className:"text-caption text-secondary",children:["- ",r]},r))})]})]})]})}function I({decision:s,onReviewDecision:t}){const n=(s.context??"").trim(),r=Array.isArray(s.options)?s.options.slice(0,4):[],a=Array.isArray(s.evidenceRefs)?s.evidenceRefs.slice(0,3):[];return e.jsxs("div",{className:"rounded-xl border border-[#14B8A6]/18 bg-[#14B8A6]/[0.06] px-3.5 py-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-micro font-semibold uppercase tracking-wider text-[#7AEDE5]",children:"Linked decision"}),e.jsx("p",{className:"mt-1 text-body font-medium text-primary",children:s.title}),s.recommendedAction?e.jsxs("p",{className:"mt-1 text-caption text-[#7AEDE5]",children:["Recommended: ",s.recommendedAction]}):null]}),t?e.jsx("button",{type:"button",onClick:()=>t(s.id),className:"rounded-lg border border-[#14B8A6]/25 bg-[#14B8A6]/10 px-3 py-1.5 text-caption font-semibold text-[#7AEDE5] transition-colors hover:bg-[#14B8A6]/18",children:"Open full decision"}):null]}),n?e.jsx("p",{className:"mt-3 text-caption leading-relaxed text-secondary",children:n}):null,r.length>0?e.jsxs("div",{className:"mt-3",children:[e.jsx("p",{className:"text-micro uppercase tracking-wider text-muted",children:"Options"}),e.jsx("div",{className:"mt-1.5 space-y-1.5",children:r.map(i=>e.jsxs("div",{className:"rounded-lg border border-white/[0.06] bg-black/[0.16] px-2.5 py-2",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx("p",{className:"text-caption font-medium text-primary",children:i.label}),i.impliedStatus==="approved"?e.jsx("span",{className:"rounded-full bg-[#14B8A6]/12 px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wider text-[#7AEDE5]",children:"Suggested"}):null]}),i.description?e.jsx("p",{className:"mt-1 text-caption text-secondary",children:i.description}):null,i.consequences?e.jsx("p",{className:"mt-1 text-micro text-muted",children:i.consequences}):null]},i.id))})]}):null,a.length>0?e.jsxs("div",{className:"mt-3",children:[e.jsx("p",{className:"text-micro uppercase tracking-wider text-muted",children:"Evidence"}),e.jsx("div",{className:"mt-1.5 space-y-1.5",children:a.map((i,m)=>e.jsxs("div",{className:"rounded-lg border border-white/[0.06] bg-black/[0.16] px-2.5 py-2",children:[e.jsx("p",{className:"text-caption font-medium text-primary",children:i.title}),i.summary?e.jsx("p",{className:"mt-1 text-caption text-secondary",children:i.summary}):null,i.sourceUrl?e.jsx("a",{href:i.sourceUrl,target:"_blank",rel:"noopener noreferrer",className:"mt-1 inline-flex text-micro text-[#7AEDE5] transition-colors hover:text-white",children:"Open source"}):null]},`${i.title}-${m}`))})]}):null]})}function j({label:s,tone:t="amber"}){const n=t==="red"?"bg-[#FF6B6B]/14":"bg-[#F5B700]/14",r=t==="red"?"text-[#FFA8A8]":"text-[#FFE7A8]";return e.jsx("span",{className:`rounded-full px-2 py-0.5 text-micro font-medium ${n} ${r}`,children:s})}function F({triageAction:s,onPerform:t,isActing:n}){const[r,a]=p.useState(!1),[i,m]=p.useState(""),y=s.action==="approve"||s.action==="autofix",f=s.action==="dismiss",u=y?"bg-[#0AD4C4]/20 text-[#7AEDE5] hover:bg-[#0AD4C4]/30":f?"bg-[#FF6B6B]/14 text-[#FFA8A8] hover:bg-[#FF6B6B]/20":"bg-white/[0.08] text-secondary hover:bg-white/[0.12]";return s.available?s.requiresNote&&r?e.jsxs("div",{className:"flex flex-col gap-1.5 w-full",children:[e.jsx("textarea",{value:i,onChange:d=>m(d.target.value),placeholder:"Add a note...",className:"w-full rounded-lg border border-subtle bg-white/[0.04] px-2.5 py-1.5 text-caption text-primary placeholder:text-muted resize-none",rows:2}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>t(s.action,i,s.optionId??void 0),disabled:n,className:`rounded-lg px-3 py-1 text-caption font-medium transition-colors disabled:opacity-40 ${u}`,children:"Confirm"}),e.jsx("button",{type:"button",onClick:()=>a(!1),className:"text-caption text-muted hover:text-secondary",children:"Cancel"})]})]}):e.jsxs("button",{type:"button",onClick:()=>{s.requiresNote?a(!0):t(s.action,void 0,s.optionId??void 0)},disabled:n,className:`rounded-lg px-3 py-1.5 text-caption font-medium transition-colors disabled:opacity-40 ${u}`,title:s.consequences,children:[e.jsx("span",{children:s.label}),e.jsxs("span",{className:"ml-1 text-micro opacity-60",children:["— ",s.consequences]})]}):e.jsx("button",{type:"button",disabled:!0,className:"rounded-lg px-3 py-1.5 text-caption font-medium opacity-30 bg-white/[0.06] text-muted cursor-not-allowed",title:"Not available",children:s.label})}function $({item:s}){const[t,n]=p.useState(!1),r=[["ID",s.id],["Kind",s.kind],["Dedupe key",s.dedupeKey],["Source system",s.sourceSystem],["Conflict source",s.conflictSource],["Agent ID",s.agentId],["Source decision",s.sourceDecisionId],["Source activity",s.sourceActivityId],["First seen",s.firstSeenAt],["Last seen",s.lastSeenAt],["Created",s.createdAt]].filter(([,a])=>a!=null);return e.jsxs("div",{className:"border-t border-subtle pt-2",children:[e.jsxs("button",{type:"button",onClick:()=>n(a=>!a),className:"flex w-full items-center justify-between text-micro font-semibold uppercase tracking-wider text-muted hover:text-secondary transition-colors",children:[e.jsx("span",{children:"Technical details"}),e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:`transition-transform ${t?"rotate-180":""}`,children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]}),t&&e.jsx("div",{className:"mt-2 space-y-0.5",children:r.map(([a,i])=>e.jsxs("div",{className:"flex gap-2 text-micro",children:[e.jsx("span",{className:"text-muted w-28 flex-shrink-0",children:a}),e.jsx("span",{className:"text-secondary truncate",children:i})]},a))})]})}function U({item:s,actions:t,onClose:n,onNavigate:r,currentIndex:a,totalCount:i,decisions:m,onReviewDecision:y}){const f=p.useRef(null),u=p.useCallback(o=>{if(!s)return;const c=s.actionContract.find(l=>l.action===o&&typeof l.optionId=="string"&&l.optionId.trim().length>0);return typeof(c==null?void 0:c.optionId)=="string"?c.optionId:void 0},[s]);p.useEffect(()=>{if(!s)return;const o=c=>{var g;const l=(g=c.target)==null?void 0:g.tagName;if(!(l==="INPUT"||l==="TEXTAREA"))switch(c.key){case"j":case"ArrowRight":c.preventDefault(),r==null||r(1);break;case"k":case"ArrowLeft":c.preventDefault(),r==null||r(-1);break;case"a":c.preventDefault(),d("approve");break;case"d":c.preventDefault(),d("dismiss");break;case"r":c.preventDefault(),d("retry");break;case"s":c.preventDefault(),d("snooze");break;case"Escape":c.preventDefault(),n();break}};return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[s,r,n]);const d=p.useCallback(async(o,c,l)=>{if(s)try{await t.performAction(s.id,o,{note:c,optionId:l??u(o)}),r==null||r(1)}catch{}},[s,t,r,u]);if(!s)return null;const x=s.sourceDecisionId&&Array.isArray(m)?m.find(o=>o.id===s.sourceDecisionId)??null:null,N=E(s,x);return e.jsx(v,{mode:"wait",children:e.jsxs(w.div,{ref:f,initial:{opacity:0,x:44,scale:.985},animate:{opacity:1,x:0,scale:1},exit:{opacity:0,x:-44,scale:.985},transition:{duration:.28},className:"flex h-full min-h-0 flex-col overflow-y-auto px-5 pb-5 pt-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[r&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>r(-1),className:"rounded p-1 text-muted hover:text-secondary hover:bg-white/[0.06] transition-colors",title:"Previous (k)",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"m15 18-6-6 6-6"})})}),e.jsx("button",{type:"button",onClick:()=>r(1),className:"rounded p-1 text-muted hover:text-secondary hover:bg-white/[0.06] transition-colors",title:"Next (j)",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"m9 18 6-6-6-6"})})})]}),a!=null&&i!=null&&e.jsxs("span",{className:"text-micro text-muted tabular-nums",children:[a+1," of ",i]})]}),e.jsx("button",{type:"button",onClick:n,className:"rounded p-1 text-muted hover:text-secondary hover:bg-white/[0.06] transition-colors",title:"Close (Esc)",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M18 6 6 18M6 6l12 12"})})})]}),(s.initiativeTitle||s.workstreamTitle)&&e.jsx("p",{className:"text-micro text-muted mb-1",children:[s.initiativeTitle,s.workstreamTitle,s.taskTitle].filter(Boolean).join(" › ")}),e.jsxs("div",{className:"mb-4 space-y-2",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx("h3",{className:"text-heading font-semibold text-primary",children:s.title}),e.jsx("span",{className:"flex-shrink-0 rounded-full px-2 py-0.5 text-[10px] font-semibold uppercase tracking-wider",style:{backgroundColor:`${A(s.severity)}20`,color:A(s.severity)},children:k(s.kind)})]}),e.jsxs("div",{className:"flex items-center gap-2 text-caption text-secondary",children:[s.agentId&&e.jsx("span",{className:"rounded bg-white/[0.06] px-1.5 py-0.5 text-micro font-medium text-secondary",children:s.agentId}),s.occurrenceCount>1&&e.jsxs("span",{className:"text-micro text-muted",children:["x",s.occurrenceCount," occurrences"]})]}),e.jsx("p",{className:"text-body text-secondary leading-relaxed",children:s.summary}),(x==null?void 0:x.recommendedAction)&&e.jsxs("p",{className:"text-caption text-[#7AEDE5]",children:["Recommended: ",x.recommendedAction]})]}),e.jsx("div",{className:"h-px bg-gradient-to-r from-transparent via-white/[0.06] to-transparent mb-4"}),e.jsxs("div",{className:"space-y-4 mb-4",children:[e.jsx(B,{missing:N}),x?e.jsx(I,{decision:x,onReviewDecision:y}):null,e.jsx(S,{item:s}),e.jsx(R,{item:s})]}),e.jsx("div",{className:"mb-4",children:e.jsx(D,{item:s})}),e.jsxs("div",{className:"mb-4",children:[e.jsx("div",{className:"space-y-1.5",children:s.actionContract.map(o=>e.jsx(F,{triageAction:o,onPerform:d,isActing:t.isActing},o.action))}),s.recommendedAction&&e.jsxs("p",{className:"mt-2 text-micro text-[#7AEDE5]",children:["Recommended: ",s.recommendedAction]})]}),e.jsx($,{item:s}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-x-3 gap-y-1 text-micro text-muted opacity-60",children:[e.jsx("span",{children:"j/k nav"}),e.jsx("span",{children:"a approve"}),e.jsx("span",{children:"d dismiss"}),e.jsx("span",{children:"r retry"}),e.jsx("span",{children:"s snooze"}),e.jsx("span",{children:"esc close"})]})]},s.id)})}export{U as TriageDetailModal};
@@ -0,0 +1 @@
1
+ import{r as d,j as e}from"./Dj2k1r16.js";import{E as ce,f as D,z as Be,a4 as he,w as Le,a5 as Ge,a6 as Ke,M as Je,h as Ue,C as le,P as Xe}from"./DNCNDTzi.js";import{E as Ve}from"./qD5absr0.js";import{A as Re,m as ee,u as Ze}from"./eeHXe_OQ.js";import"./DMKyYAtD.js";import"./cX2e-TLi.js";import"./BjK42gtU.js";import"./BV0BcV1u.js";const Qe={pr:"⎋",file:"◇",artifact:"▪",log:"▸",decision:"◈"};function Ye(n){return n>=.8?"#BFFF00":n>=.5?"#F5B700":"#FF6B88"}function He(n){const t=n.match(/https?:\/\/\S+/);return t?t[0]:null}function et({evidenceType:n,title:t,summary:p,sourceUrl:m,confidence:b,payload:A,icon:y,label:w,onOpenTerminal:C}){const[c,P]=d.useState(!1),B=t??w??null,M=n??(y?y.toUpperCase():null),$=y?Qe[y]:null,T=y==="pr"&&w?He(w):null;return e.jsxs("div",{className:"rounded-xl border border-white/[0.06] bg-white/[0.02] px-3 py-2.5",children:[e.jsxs("div",{className:"flex items-start gap-2.5 cursor-pointer",onClick:()=>P(N=>!N),children:[(M||$)&&e.jsxs("span",{className:"mt-0.5 flex-shrink-0 rounded bg-white/[0.06] px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wider text-secondary",children:[$?e.jsx("span",{className:"mr-1",children:$}):null,M]}),e.jsxs("div",{className:"min-w-0 flex-1",children:[B&&e.jsx("p",{className:"text-body font-medium text-primary",children:m?e.jsx("a",{href:m,target:"_blank",rel:"noopener noreferrer",className:"text-[#D8FFA1] hover:underline",onClick:N=>N.stopPropagation(),children:B}):T?e.jsx("a",{href:T,target:"_blank",rel:"noopener noreferrer",className:"text-[#D8FFA1] hover:underline",onClick:N=>N.stopPropagation(),children:B}):B}),p&&e.jsx("p",{className:`mt-0.5 text-caption text-secondary ${c?"":"line-clamp-2"}`,children:p})]}),e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:`mt-1 flex-shrink-0 text-muted transition-transform ${c?"rotate-180":""}`,children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]}),b!=null&&e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("div",{className:"h-1 flex-1 overflow-hidden rounded-full bg-white/[0.06]",children:e.jsx("div",{className:"h-full rounded-full transition-all",style:{width:`${Math.round(b*100)}%`,backgroundColor:Ye(b)}})}),e.jsxs("span",{className:"text-micro text-muted tabular-nums",children:[Math.round(b*100),"%"]})]}),e.jsx(Re,{children:c&&e.jsx(ee.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.2},className:"overflow-hidden",children:e.jsxs("div",{className:"mt-2 space-y-2",children:[y==="log"&&C&&e.jsxs("button",{type:"button",onClick:N=>{N.stopPropagation(),C()},className:"inline-flex items-center gap-1.5 rounded-lg border border-white/[0.12] bg-white/[0.04] px-3 py-1.5 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.08]",children:[e.jsx("span",{className:"font-mono text-micro",children:">_"}),"Open in terminal"]}),A&&Object.keys(A).length>0&&e.jsx("pre",{className:"max-h-40 overflow-auto rounded-lg bg-black/40 p-2.5 text-micro text-secondary font-mono",children:JSON.stringify(A,null,2)})]})})})]})}function tt({segments:n}){return n.length===0?null:e.jsx("nav",{className:"flex items-center gap-1.5 min-w-0 text-caption text-secondary",children:n.map((t,p)=>e.jsxs("span",{className:"flex items-center gap-1.5 min-w-0",children:[p>0&&e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"flex-shrink-0 text-faint",children:e.jsx("path",{d:"m9 18 6-6-6-6"})}),t.icon&&e.jsx(ce,{type:t.icon,size:11,className:"flex-shrink-0 opacity-80"}),t.onClick?e.jsx("button",{type:"button",onClick:t.onClick,className:"truncate transition-colors hover:text-primary",children:t.label}):e.jsx("span",{className:"truncate",children:t.label})]},p))})}const Ne={label:"Retry this workstream",description:"Re-run with the same configuration. Recommended if this was a transient issue.",impliedStatus:"approved"},H={label:"Skip and continue",description:"Mark as accepted and move to the next workstream.",impliedStatus:"approved"},st=[{test:/Worker exited without structured output.*?code=(\S+?),\s*signal=(\S+?)\)/i,headline:"Agent work stopped unexpectedly",explain:(n,t)=>{const p=t[1]==="null"?"none":t[1],m=t[2]==="null"?"none":t[2];return`The agent process exited before producing results. Exit code: ${p}. Signal: ${m}. This usually means the worker was terminated externally or ran out of resources.`},severity:"critical",options:[Ne,{label:"Retry with more resources",description:"Increase token budget before re-running.",impliedStatus:"approved"},H],extractDetails:(n,t)=>({exitCode:t[1]==="null"?void 0:t[1],signal:t[2]==="null"?void 0:t[2]})},{test:/MCP handshake failed(?:\s+for\s+(\S+))?/i,headline:"Agent couldn't connect to tools",explain:(n,t)=>`The agent failed to connect to its tool server${t[1]?` (${t[1]})`:""}. This typically means the MCP server is unreachable or took too long to respond.`,severity:"critical",options:[Ne,{label:"Check MCP server",description:"Investigate the tool server connection before retrying.",impliedStatus:"approved"},H],extractDetails:(n,t)=>({server:t[1]||void 0})},{test:/(?:Slice|Autopilot slice) timed out after (\d+)/i,headline:"Agent ran out of time",explain:(n,t)=>{const p=Math.round(parseInt(t[1],10)/6e4);return`The agent exceeded its ${p>0?`${p}-minute`:`${t[1]}ms`} time limit. Consider breaking the work into smaller steps or increasing the time budget.`},severity:"warning",options:[{label:"Retry with more time",description:"Increase the timeout before re-running.",impliedStatus:"approved"},{label:"Break into smaller tasks",description:"Split the workstream into smaller pieces that fit the time budget.",impliedStatus:"approved"},H],extractDetails:(n,t)=>({elapsedMs:t[1]})},{test:/(?:Slice|Autopilot slice) stalled/i,headline:"Agent stopped making progress",explain:()=>"The agent stopped producing output. It may be stuck in a loop, waiting on an unresponsive resource, or unable to proceed with the current approach.",severity:"warning",options:[Ne,{label:"Review logs",description:"Check the session logs to understand why the agent stalled.",impliedStatus:"approved"},H]},{test:/blocked.*?(?:needs|requires?) intervention/i,headline:"Agent needs your help to continue",explain:()=>"The agent reached a point where it cannot proceed without human guidance. This may be a question about requirements, a permission needed, or an ambiguity.",severity:"warning",options:[{label:"Review blocker",description:"Look at what the agent needs and provide guidance.",impliedStatus:"approved"},{label:"Provide guidance",description:"Add a note with instructions for the agent.",impliedStatus:"approved"},H]},{test:/completed.*?(?:without|no) (?:verifiable )?(?:outcomes?|artifacts?)/i,headline:"Agent finished but produced no outputs",explain:()=>"The agent reported completion but produced no artifacts or status updates. The work may have been done informally, or the agent could not find actionable work.",severity:"info",options:[{label:"Accept as-is",description:"The work was done informally or no output was needed.",impliedStatus:"approved"},{label:"Retry with stronger output requirements",description:"Re-run and require the agent to produce structured artifacts.",impliedStatus:"approved"},H]},{test:/Spawn guard denied/i,headline:"Agent dispatch was blocked by safety check",explain:()=>"The system's safety checks prevented this agent from starting. This is typically due to capacity limits or quality gate requirements.",severity:"warning",options:[{label:"Approve exception",description:"Override the safety check and allow dispatch.",impliedStatus:"approved"},{label:"Investigate quality gate",description:"Review what safety check failed before proceeding.",impliedStatus:"approved"},H]},{test:/code=(\d+)/i,headline:"Agent encountered an error",explain:(n,t)=>`The agent process exited with error code ${t[1]}. Reviewing the session logs will show what operation failed.`,severity:"critical",options:[Ne,{label:"Review error logs",description:"Check session logs to understand the error before retrying.",impliedStatus:"approved"},H],extractDetails:(n,t)=>({exitCode:t[1]})}];function nt(n){var p;const t=n.context||n.title||"";for(const m of st){const b=t.match(m.test);if(b)return{headline:m.headline,explanation:m.explain(t,b),structuredDetails:((p=m.extractDetails)==null?void 0:p.call(m,t,b))??{},suggestedOptions:m.options,severity:m.severity}}return n.decisionType==="autopilot_failure"?{headline:"Agent work needs attention",explanation:t||"An issue occurred during autopilot execution that requires review.",structuredDetails:{},suggestedOptions:[Ne,H],severity:"warning"}:{headline:n.title||"Decision needed",explanation:t||"Review the details and choose an action.",structuredDetails:{},suggestedOptions:[],severity:"info"}}function rt(n){return n.map((t,p)=>({id:`suggested-${p}`,label:t.label,description:t.description,impliedStatus:t.impliedStatus,actionType:null,requiresNote:!1}))}function it(n,t){var w;if(!t||!n.workstreamId||!t.nodes.find(C=>C.id===n.workstreamId&&C.entityType==="workstream"))return null;const m=new Set(t.edges.filter(C=>C.source===n.workstreamId).map(C=>C.target)),b=[];for(const C of m){const c=t.nodes.find(P=>P.id===C);c&&b.push({id:c.id,title:c.title,taskCount:((w=c.children)==null?void 0:w.length)??0,status:c.status})}if(b.length===0)return null;const A=b.reduce((C,c)=>C+c.taskCount,0),y=b.some(C=>t.edges.some(c=>c.source===C.id));return{blockedWorkstreams:b,totalBlockedTasks:A,criticalPath:y}}function at(n){const t=n.blockedWorkstreams.length,p=n.blockedWorkstreams.map(m=>m.title);return t===1?`Resolving this unblocks 1 downstream workstream: ${p[0]}.`:t<=3?`Resolving this unblocks ${t} downstream workstreams: ${p.join(", ")}.`:`Resolving this unblocks ${t} downstream workstreams including ${p[0]} and ${p[1]}.`}const Pe=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent);function ot(n){try{return JSON.stringify(n,null,2)}catch{return null}}function fe(n){return!n||typeof n!="object"||Array.isArray(n)?null:n}function lt(n){if(!n)return[];const t=fe(n.result),p=[n,t].filter(y=>!!y),m=[],b=new Set,A=(y,w)=>{if(Array.isArray(w))for(const C of w){const c=fe(C);if(!c)continue;const P=typeof c.task_id=="string"&&c.task_id.trim()||typeof c.taskId=="string"&&c.taskId.trim()||typeof c.milestone_id=="string"&&c.milestone_id.trim()||typeof c.milestoneId=="string"&&c.milestoneId.trim()||null,B=typeof c.task_title=="string"&&c.task_title.trim()||typeof c.taskTitle=="string"&&c.taskTitle.trim()||typeof c.milestone_title=="string"&&c.milestone_title.trim()||typeof c.milestoneTitle=="string"&&c.milestoneTitle.trim()||typeof c.title=="string"&&c.title.trim()||P||y,M=typeof c.status=="string"&&c.status.trim()||typeof c.state=="string"&&c.state.trim()||null,$=typeof c.reason=="string"&&c.reason.trim()||typeof c.summary=="string"&&c.summary.trim()||typeof c.note=="string"&&c.note.trim()||null,T=`${y}|${B.toLowerCase()}|${(M??"").toLowerCase()}|${($??"").toLowerCase()}`;b.has(T)||(b.add(T),m.push({scope:y,label:B,status:M,note:$}))}};for(const y of p)A("Task",y.task_updates??y.taskUpdates),A("Milestone",y.milestone_updates??y.milestoneUpdates);return m.slice(0,8)}function ct(n){const t=new Set;return n.context.trim().length===0&&t.add("Decision context"),n.options.length===0&&t.add("Decision options"),n.recommendedAction||t.add("Recommended action"),n.evidenceCount===0&&t.add("Supporting evidence"),n.updateCount===0&&t.add("Expected downstream updates"),Array.from(t)}function dt({missing:n}){return n.length===0?null:e.jsxs("div",{className:"mb-4 rounded-xl border border-amber-300/20 bg-amber-300/[0.08] px-4 py-3",children:[e.jsx("p",{className:"text-micro font-semibold uppercase tracking-wider text-amber-100",children:"Decision brief needs more context"}),e.jsx("p",{className:"mt-1 text-caption text-amber-50/90",children:"Review is still possible, but this payload is missing some of the operator context needed for a confident judgment."}),e.jsx("ul",{className:"mt-2 space-y-0.5",children:n.map(t=>e.jsxs("li",{className:"text-caption text-amber-100/85",children:["- ",t]},t))}),e.jsx("p",{className:"mt-2 text-micro text-amber-100/60",children:"Use the linked evidence and technical details below if you need to diagnose the payload itself."})]})}function ut(n){const t=new Set(["Decision context","Decision options","Supporting evidence"]);return n.filter(p=>t.has(p))}function Fe(n){if(typeof n!="string")return null;const t=n.trim().toLowerCase();return t==="rejected"?"declined":t==="approved"||t==="declined"||t==="cancelled"?t:null}function Me(n,t){return!n||n.trim().length===0?t:Ue(n.trim())||t}function pt(n){switch(n){case"spawn_guard_blocked":return"Spawn Guard";case"autopilot_failure":return"Autopilot Failure";case"budget_exceeded":return"Budget Exceeded";case"scope_change":return"Scope Change";case"conflict_resolution":return"Conflict Resolution";case"approval_required":return"Approval Required";case"review_required":return"Review Required";case"permission_request":return"Permission Request";default:return n.replace(/[_-]/g," ").replace(/\b\w/g,t=>t.toUpperCase())}}function mt(n){const t=n.toLowerCase();return t==="critical"||t==="p0"?D.red:t==="high"||t==="p1"?D.amber:t==="medium"||t==="p2"?D.iris:"rgba(255,255,255,0.5)"}function xt({open:n,decision:t,onClose:p,onApprove:m,onReject:b,initiativeTitle:A,workstreamTitle:y,onNavigate:w,currentIndex:C,totalCount:c,onFocusRunId:P,graph:B}){const[M,$]=d.useState("idle"),[T,N]=d.useState(null),[te,K]=d.useState(null),[S,de]=d.useState(""),[J,X]=d.useState(!1),[V,_]=d.useState(!1),se=d.useRef(null),re=d.useRef(),F=d.useRef(p);F.current=p,d.useEffect(()=>{if(n){$("idle"),N(null);const s=(t==null?void 0:t.selectedOptionId)??(t!=null&&t.options&&t.options.length===1?t.options[0].id:null);K(s),de(""),X(!1),_(!1)}return()=>{re.current&&clearTimeout(re.current)}},[n,t==null?void 0:t.id]);const k=t==null?void 0:t.metadata,ie=d.useMemo(()=>{if(!k)return[];const s=k,a=s.decision_options??s.options??s.actions??null;if(!Array.isArray(a))return[];const x=[],U=new Set;for(let R=0;R<a.length;R+=1){const i=a[R];if(typeof i=="string"){const u=i.trim();if(!u)continue;const g=`option-${R+1}`;if(U.has(g))continue;U.add(g),x.push({id:g,label:u,description:null,consequences:null,impliedStatus:null,actionType:null,requiresNote:!1});continue}if(!i||typeof i!="object")continue;const r=i,o=typeof r.id=="string"&&r.id.trim()||typeof r.option_id=="string"&&r.option_id.trim()||typeof r.action_id=="string"&&r.action_id.trim()||`option-${R+1}`;if(U.has(o))continue;const l=typeof r.label=="string"&&r.label.trim()||typeof r.title=="string"&&r.title.trim()||typeof r.name=="string"&&r.name.trim()||typeof r.action=="string"&&r.action.trim()||null;l&&(U.add(o),x.push({id:o,label:l,description:typeof r.description=="string"?r.description:null,consequences:typeof r.consequences=="string"&&r.consequences||typeof r.impact=="string"&&r.impact||null,impliedStatus:Fe(r.implied_status)??Fe(r.status),actionType:typeof r.action_type=="string"&&r.action_type||typeof r.type=="string"&&r.type||null,requiresNote:r.requires_note===!0||r.requiresNote===!0||r.note_required===!0}))}return x.slice(0,12)},[k]),h=d.useMemo(()=>t?nt(t):null,[t==null?void 0:t.context,t==null?void 0:t.title,t==null?void 0:t.decisionType]),E=d.useMemo(()=>t?it(t,B??null):null,[t==null?void 0:t.workstreamId,t==null?void 0:t.initiativeId,B]),z=((t==null?void 0:t.waitingMinutes)??0)>1440,j=d.useMemo(()=>t!=null&&t.options&&t.options.length>0?t.options:ie.length>0?ie:h&&h.suggestedOptions.length>0?rt(h.suggestedOptions):[],[t==null?void 0:t.options,ie,h]),f=d.useMemo(()=>j.find(s=>s.id===te)??null,[j,te]),ke=(f==null?void 0:f.requiresNote)===!0,ge=d.useMemo(()=>{const s=((t==null?void 0:t.context)??"").trim();if(s)return s;if(!k)return"";const a=k,x=(typeof a.summary=="string"?a.summary:null)??(typeof a.description=="string"?a.description:null)??"";return String(x??"").trim()},[t==null?void 0:t.context,k]),I=d.useMemo(()=>{var o,l,u;const s=k&&typeof k=="object"?k:void 0,a=lt(s),x=fe(s==null?void 0:s.outcomes),U=typeof(s==null?void 0:s.status_updates_applied)=="number"&&Number.isFinite(s.status_updates_applied)?s.status_updates_applied:typeof((o=fe(s==null?void 0:s.result))==null?void 0:o.status_updates_applied)=="number"&&Number.isFinite((l=fe(s==null?void 0:s.result))==null?void 0:l.status_updates_applied)?(u=fe(s==null?void 0:s.result))==null?void 0:u.status_updates_applied:null,R=Array.isArray(s==null?void 0:s.artifacts)?s.artifacts.length:typeof(x==null?void 0:x.artifacts)=="number"?x.artifacts:null,i=(s==null?void 0:s.status_updates_buffered)??(s==null?void 0:s.statusUpdatesBuffered),r=i===!0||typeof i=="number"&&i>0||typeof i=="string"&&["true","1","yes"].includes(i.trim().toLowerCase());return{rows:a,statusUpdatesApplied:U,artifactCount:typeof R=="number"?R:null,buffered:r,hasPr:typeof(x==null?void 0:x.pr_url)=="string"||typeof(x==null?void 0:x.commit_sha)=="string"}},[k]),ue=d.useMemo(()=>{const s=(t==null?void 0:t.waitingMinutes)??0;return s>=15?D.red:s>=5?D.amber:D.teal},[t==null?void 0:t.waitingMinutes]),Ie=d.useCallback(async()=>{if(!t)return;const s=ot({decision:t,metadata:k});if(s)try{await navigator.clipboard.writeText(s),X(!0),setTimeout(()=>X(!1),2e3)}catch{}},[t,k]),pe=d.useCallback(()=>{const s=S.trim(),a=f==null?void 0:f.id;if(!(!s&&!a))return{note:s.length>0?s:void 0,optionId:a??void 0}},[S,f]),W=d.useCallback(async()=>{if(!t||!m)return;if(j.length>0&&!f){N("Select an option before approving this decision.");return}if(f!=null&&f.requiresNote&&S.trim().length===0){N("A note is required for the selected option."),requestAnimationFrame(()=>{var a;return(a=se.current)==null?void 0:a.focus()});return}let s=!1;if($(a=>a==="approving"||a==="rejecting"?a:(s=!0,"approving")),!!s){N(null);try{const a=await m(t.id,pe());a.failed>0?($("error"),N(Me(a.firstError,"Approval failed. Please try again."))):($("success"),re.current=setTimeout(()=>F.current(),800))}catch(a){$("error");const x=a instanceof Error?a.message:"";N(Me(x,"Approval failed."))}}},[pe,t,S,m,j.length,f]),be=d.useCallback(async()=>{if(!t||!b)return;if(j.length>0&&!f){N("Select an option before rejecting this decision.");return}if(f!=null&&f.requiresNote&&S.trim().length===0){N("A note is required for the selected option."),requestAnimationFrame(()=>{var a;return(a=se.current)==null?void 0:a.focus()});return}let s=!1;if($(a=>a==="approving"||a==="rejecting"?a:(s=!0,"rejecting")),!!s){N(null);try{const a=await b(t.id,pe());a.failed>0?($("error"),N(Me(a.firstError,"Rejection failed. Please try again."))):($("rejected"),re.current=setTimeout(()=>F.current(),800))}catch(a){$("error");const x=a instanceof Error?a.message:"";N(Me(x,"Rejection failed."))}}},[pe,t,S,b,j.length,f]);if(d.useEffect(()=>{if(!n)return;const s=a=>{var U,R;if((a.metaKey||a.ctrlKey)&&a.key==="Enter"){a.preventDefault(),W();return}const x=(U=a.target)==null?void 0:U.tagName;if(!(x==="INPUT"||x==="TEXTAREA"))switch(a.key){case"j":a.preventDefault(),w==null||w(1);break;case"k":a.preventDefault(),w==null||w(-1);break;case"a":a.preventDefault(),W();break;case"r":a.preventDefault(),be();break;case"n":a.preventDefault(),(R=se.current)==null||R.focus();break}};return document.addEventListener("keydown",s),()=>document.removeEventListener("keydown",s)},[n,W,be,w]),!n||!t)return null;const q=M==="approving"||M==="rejecting",ye=M==="success"||M==="rejected",L=(t.status??"pending").toLowerCase(),ne=!L.includes("approved")&&!L.includes("resolved")&&!L.includes("rejected")&&!L.includes("declined")&&!L.includes("cancelled"),Z=t.evidenceRefs??[],Te=Z.length>0,we=t.recommendedAction??null,Ce=t.decisionType??null,me=t.priority??null,je=t.occurrenceCount??null,O=t.sourceRunId??null,ve=ct({context:ge,recommendedAction:we,options:j,evidenceCount:Z.length,updateCount:I.rows.length+(I.statusUpdatesApplied??0)}),xe=ut(ve),Q=j.length>0&&!f,Se=(f==null?void 0:f.requiresNote)===!0&&S.trim().length===0,ae=xe.length>=2||xe.includes("Decision context")&&xe.includes("Decision options"),G=q||Q||Se||ae,oe=[];A&&oe.push({label:A,icon:"initiative"}),y&&oe.push({label:y,icon:"workstream"});const Ae=[["ID",t.id],["Type",t.decisionType],["Dedupe key",t.dedupeKey],["Source system",t.sourceSystem],["Conflict source",t.conflictSource],["Agent ID",t.agentId],["Source run",t.sourceRunId],["Source session",t.sourceSessionId],["Source stream",t.sourceStreamId]].filter(([,s])=>s!=null);if(ye){const s=M==="success",a=s?D.lime:D.red;return e.jsx(Be,{open:n,onClose:p,maxWidth:"max-w-xl",fitContent:!0,children:e.jsxs("div",{className:"flex flex-col items-center justify-center px-8 py-12",children:[e.jsx("div",{className:"mb-4 flex h-16 w-16 items-center justify-center rounded-full",style:{backgroundColor:`${a}18`,border:`1.5px solid ${a}40`},children:s?e.jsx("svg",{width:"28",height:"28",viewBox:"0 0 24 24",fill:"none",stroke:a,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):e.jsxs("svg",{width:"28",height:"28",viewBox:"0 0 24 24",fill:"none",stroke:a,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 6L6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})}),e.jsx("p",{className:"text-heading font-semibold text-white",children:s?"Approved":"Rejected"}),e.jsx("p",{className:"mt-1 text-body text-secondary",children:t.title})]})})}return e.jsx(Be,{open:n,onClose:p,maxWidth:"max-w-xl",children:e.jsxs("div",{className:"flex h-full min-h-0 w-full flex-col",style:z?{boxShadow:`inset 0 0 0 1px ${D.amber}30`,borderRadius:"inherit"}:void 0,children:[e.jsx("div",{className:"h-[2px] w-full flex-shrink-0",style:{background:`linear-gradient(90deg, ${ue}60, ${ue}20, transparent)`}}),w&&e.jsxs("div",{className:"flex items-center justify-between px-6 pt-3 pb-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>w(-1),className:"rounded p-1 text-muted hover:text-secondary hover:bg-white/[0.06] transition-colors",title:"Previous (k)",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"m15 18-6-6 6-6"})})}),e.jsx("button",{type:"button",onClick:()=>w(1),className:"rounded p-1 text-muted hover:text-secondary hover:bg-white/[0.06] transition-colors",title:"Next (j)",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"m9 18 6-6-6-6"})})}),C!=null&&c!=null&&e.jsxs("span",{className:"text-micro text-muted tabular-nums",children:[C+1," of ",c,e.jsx("span",{className:"ml-1 hidden sm:inline",children:"· Longest waiting first"})]})]}),e.jsx("button",{type:"button",onClick:p,"aria-label":"Close",className:"rounded p-1 text-muted hover:text-secondary hover:bg-white/[0.06] transition-colors",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M18 6 6 18M6 6l12 12"})})})]}),oe.length>0&&e.jsx("div",{className:"px-6 pt-2",children:e.jsx(tt,{segments:oe})}),e.jsxs("div",{className:"flex items-start justify-between gap-3 px-6 pt-4 pb-4",children:[e.jsx("div",{className:"min-w-0 flex-1",children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-lg",style:{backgroundColor:`${ue}14`,border:`1px solid ${ue}30`},children:e.jsx(ce,{type:"decision",size:14})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{className:"text-title font-medium leading-tight text-white mb-2",children:t.title||"Decision Required"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-body text-secondary",children:[e.jsx("span",{children:t.agentName||"OrgX Autopilot"}),e.jsx("span",{className:"text-white/[0.15]",children:"|"}),e.jsx("span",{className:z?"font-semibold text-red-300":"",children:he(t.waitingMinutes).text}),Ce&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-white/[0.15]",children:"|"}),e.jsx("span",{className:"text-primary",children:pt(Ce)})]}),me&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-white/[0.15]",children:"|"}),e.jsx("span",{className:"font-medium",style:{color:mt(me)},children:me})]})]}),je!=null&&je>1&&e.jsxs("p",{className:"mt-2 text-caption text-muted",children:["Seen ",je," times",t.firstSeenAt&&e.jsxs(e.Fragment,{children:[" · first ",Le(t.firstSeenAt)]}),t.lastSeenAt&&e.jsxs(e.Fragment,{children:[" · last ",Le(t.lastSeenAt)]})]})]})]})}),!w&&e.jsx("button",{type:"button",onClick:p,"aria-label":"Close",className:"mt-0.5 flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-lg text-muted transition-colors hover:bg-white/[0.06] hover:text-white",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 6L6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto px-6 pb-4",children:[(t.initiativeId||t.workstreamId)&&e.jsx("div",{className:"mb-4",children:e.jsx(Ge,{nodes:Ke({initiativeId:t.initiativeId,initiativeTitle:A,workstreamId:t.workstreamId,workstreamTitle:y,agentName:t.agentName,agentId:t.agentId}),activeId:t.workstreamId,compact:!0})}),e.jsx(dt,{missing:ve}),we&&e.jsxs("div",{className:"mb-4 rounded-xl border border-cyan-300/[0.28] bg-cyan-500/[0.12] px-4 py-3",children:[e.jsx("p",{className:"text-micro font-semibold uppercase tracking-wider text-cyan-200 mb-1",children:"Recommended"}),e.jsx("p",{className:"text-body text-cyan-100",children:we})]}),e.jsxs("div",{className:"mb-4",children:[e.jsx("p",{className:"mb-2 px-1 text-micro font-semibold uppercase tracking-wider text-muted",children:"Supporting evidence"}),Te?e.jsx("div",{className:"space-y-1.5",children:Z.map((s,a)=>e.jsx(et,{evidenceType:s.evidenceType,title:s.title,summary:s.summary,sourceUrl:s.sourceUrl,confidence:s.confidence,payload:s.payload},a))}):e.jsx("div",{className:"rounded-xl border border-white/[0.06] bg-white/[0.02] px-4 py-3",children:e.jsx("p",{className:"text-body text-muted",children:"No supporting evidence was emitted for this decision. Review the source run or add a note before escalating."})})]}),z&&e.jsx("div",{className:"mb-4 rounded-xl border border-amber-400/[0.3] bg-amber-500/[0.08] px-4 py-3",children:e.jsxs("p",{className:"text-body text-amber-200",children:["This decision has been waiting"," ",e.jsx("span",{className:"font-semibold text-amber-100",children:he(t.waitingMinutes).text}),". Downstream work is paused."]})}),e.jsxs("div",{className:"rounded-xl border border-white/[0.06] bg-white/[0.02] px-4 py-3",children:[e.jsx("p",{className:"mb-2 text-micro font-semibold uppercase tracking-wider text-muted",children:"Decision context"}),h&&h.headline!==t.title?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-body text-primary leading-relaxed",children:h.explanation}),Object.keys(h.structuredDetails).length>0&&e.jsx("div",{className:"mt-3 flex flex-wrap gap-x-4 gap-y-1 text-caption text-secondary",children:Object.entries(h.structuredDetails).filter(([,s])=>s!=null).map(([s,a])=>e.jsxs("span",{children:[s.replace(/([A-Z])/g," $1").replace(/^./,x=>x.toUpperCase()),": ",a]},s))})]}):ge?e.jsx(Je,{text:ge,mode:"block"}):e.jsx("p",{className:"text-body text-muted",children:"No decision context was emitted. The operator only has the title, age, and surrounding timeline to work from."})]}),e.jsxs("div",{className:"mt-4 rounded-xl border border-[#14B8A6]/20 bg-[#14B8A6]/[0.06] px-4 py-3",children:[e.jsx("p",{className:"text-micro font-semibold uppercase tracking-wider text-[#7ce0d3] mb-1",children:I.buffered?"Updates being applied":"Expected updates"}),(I.statusUpdatesApplied??0)>0&&e.jsxs("p",{className:"text-caption text-primary",children:[I.statusUpdatesApplied," status update",I.statusUpdatesApplied===1?"":"s",I.buffered?" queued for sync":" planned","."]}),(I.artifactCount??0)>0&&e.jsxs("p",{className:"text-caption text-primary",children:[I.artifactCount," artifact",I.artifactCount===1?"":"s"," expected from this decision path."]}),I.rows.length>0?e.jsx("ul",{className:"mt-2 space-y-1 pl-4",children:I.rows.map((s,a)=>e.jsxs("li",{className:"text-caption text-secondary",children:[e.jsxs("span",{className:"text-primary",children:[s.scope,": ",s.label]}),s.status?` → ${s.status}`:"",s.note?` · ${s.note}`:""]},`${s.scope}-${s.label}-${a}`))}):e.jsx("p",{className:"text-caption text-secondary",children:"No downstream task or milestone updates were emitted for this decision. Approval may resume work, but the exact updates are unspecified in the current payload."})]}),e.jsxs("div",{className:"mt-8",children:[e.jsx("p",{className:"mb-3 px-1 text-[11px] font-semibold uppercase tracking-[0.08em] text-muted",children:"Options"}),j.length>0?e.jsx("div",{className:"space-y-1 relative",children:j.map(s=>{const a=te===s.id;return e.jsxs("button",{type:"button",onClick:()=>{K(a?null:s.id),s.requiresNote&&requestAnimationFrame(()=>{var x;return(x=se.current)==null?void 0:x.focus()})},disabled:q,className:"group relative flex w-full items-start gap-4 px-4 py-4 text-left focus:outline-none",children:[a&&e.jsx(ee.div,{layoutId:"decision-option-bg",className:"absolute inset-0 rounded-xl",style:{backgroundColor:`${D.lime}12`},transition:{type:"spring",stiffness:400,damping:25}}),!a&&e.jsx("div",{className:"absolute inset-0 rounded-xl opacity-0 transition-opacity group-hover:bg-white/[0.03]"}),e.jsx("div",{className:"relative mt-0.5 flex h-5 w-5 flex-shrink-0 items-center justify-center rounded-full border-[1.5px] transition-colors",style:{borderColor:a?D.lime:"rgba(255,255,255,0.2)"},children:e.jsx(Re,{children:a&&e.jsx(ee.div,{initial:{scale:0},animate:{scale:1},exit:{scale:0},transition:{type:"spring",stiffness:500,damping:30},className:"h-2.5 w-2.5 rounded-full",style:{backgroundColor:D.lime}})})}),e.jsxs("div",{className:"relative min-w-0 flex-1",children:[e.jsx("span",{className:`block text-[15px] ${a?"font-medium text-white":"text-primary"}`,children:s.label}),s.description&&e.jsx("p",{className:"mt-1 text-[13px] leading-relaxed text-secondary",children:s.description}),s.consequences&&e.jsx("p",{className:"mt-1 text-[12px] leading-relaxed text-muted",children:s.consequences}),s.requiresNote&&e.jsx("p",{className:"mt-1.5 text-[11px] font-medium uppercase tracking-wider text-amber-400",children:"Note required"})]})]},s.id)})}):e.jsx("div",{className:"rounded-xl border border-white/[0.06] bg-white/[0.02] px-4 py-3",children:e.jsx("p",{className:"text-body text-muted",children:"No explicit options were emitted for this decision. Approval and rejection stay blocked until an option set or stronger recommendation is available."})})]}),ne&&ke&&e.jsxs("div",{className:"mt-4",children:[e.jsx("textarea",{ref:se,value:S,onChange:s=>de(s.target.value),disabled:q,placeholder:"Required: add context for this decision...",rows:3,className:"w-full resize-none rounded-xl border border-white/[0.08] bg-white/[0.03] px-4 py-3 text-body text-primary placeholder-white/30 outline-none transition-colors focus:border-white/[0.16] focus:bg-white/[0.04]"}),S.trim().length===0&&e.jsx("p",{className:"mt-2 text-caption text-amber-300",children:"This option requires a note before submission."})]}),E&&e.jsxs("div",{className:"mt-6 rounded-xl border border-white/[0.06] bg-white/[0.02] px-4 py-3",children:[e.jsx("p",{className:"text-micro font-semibold uppercase tracking-wider text-muted mb-2",children:"Impact"}),e.jsx("p",{className:"text-body text-primary leading-relaxed",children:at(E)}),E.blockedWorkstreams.length>0&&e.jsx("ul",{className:"mt-2 space-y-1 text-caption text-secondary",children:E.blockedWorkstreams.map(s=>e.jsxs("li",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"inline-block h-1 w-1 rounded-full bg-amber-400 flex-shrink-0"}),s.title,s.status==="blocked"&&e.jsx("span",{className:"text-amber-400 text-micro",children:"(blocked)"})]},s.id))})]}),O&&P&&e.jsx("div",{className:"mt-4",children:e.jsxs("button",{type:"button",onClick:()=>P(O),className:"inline-flex items-center gap-1.5 text-caption text-[#D8FFA1] transition-colors hover:text-white",children:[e.jsx(ce,{type:"session",size:12}),"View source run"]})}),e.jsx("div",{className:"mt-4 border-t border-white/[0.06] pt-4",children:e.jsx(Ve,{entityType:"decision",entityId:t.id})}),Ae.length>0&&e.jsxs("div",{className:"mt-4 border-t border-white/[0.06] pt-2",children:[e.jsxs("button",{type:"button",onClick:()=>_(s=>!s),className:"flex w-full items-center justify-between text-micro font-semibold uppercase tracking-wider text-muted hover:text-secondary transition-colors",children:[e.jsx("span",{children:"Technical details"}),e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:`transition-transform ${V?"rotate-180":""}`,children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]}),V&&e.jsx("div",{className:"mt-2 space-y-0.5",children:Ae.map(([s,a])=>e.jsxs("div",{className:"flex gap-2 text-micro",children:[e.jsx("span",{className:"text-muted w-28 flex-shrink-0",children:s}),e.jsx("span",{className:"text-secondary truncate",children:a})]},s))})]}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-x-3 gap-y-1 text-micro text-muted opacity-60",children:[w&&e.jsx("span",{children:"j/k nav"}),e.jsx("span",{children:"a approve"}),e.jsx("span",{children:"r reject"}),e.jsx("span",{children:"n note"}),e.jsxs("span",{children:[Pe?"⌘":"Ctrl","+Enter approve"]}),e.jsx("span",{children:"esc close"})]})]}),T&&e.jsxs("div",{className:"flex items-center gap-2 border-t border-white/[0.06] px-6 py-3",children:[e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:D.red,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",x2:"12",y1:"8",y2:"12"}),e.jsx("line",{x1:"12",x2:"12.01",y1:"16",y2:"16"})]}),e.jsx("p",{className:"text-caption text-red-300",children:T})]}),ne&&ae?e.jsx("div",{className:"border-t border-white/[0.06] px-6 py-3",children:e.jsx("p",{className:"text-caption text-amber-200",children:"This payload still needs more context before approval or rejection is safe. Review the evidence and open the source run if you need to escalate."})}):null,ne&&e.jsx("div",{className:"relative mt-auto border-t border-white/[0.04] bg-black/60 px-6 py-5 backdrop-blur-xl",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[b&&e.jsx(ee.button,{whileTap:{scale:.97},type:"button",onClick:be,disabled:G,className:"rounded-lg px-4 py-2 text-[14px] font-medium text-secondary transition-colors hover:text-red-400 disabled:opacity-40 focus:outline-none",children:M==="rejecting"?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"inline-block h-3 w-3 animate-spin rounded-full border-[1.5px] border-current border-t-transparent"}),"Rejecting"]}):"Reject"}),e.jsx("button",{type:"button",onClick:Ie,className:"rounded-lg px-2 py-2 text-[13px] text-muted transition-colors hover:text-secondary focus:outline-none",title:"Copy decision as JSON",children:J?"Copied":"Copy JSON"})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("span",{className:"hidden text-[13px] text-muted sm:block",children:[Pe?"⌘":"Ctrl","+Enter"]}),e.jsx(ee.button,{whileTap:!m||G?void 0:{scale:.97},type:"button",onClick:W,disabled:!m||G,"data-modal-autofocus":"true",className:"rounded-lg px-6 py-2.5 text-[14px] font-semibold transition-all focus:outline-none",style:{backgroundColor:!m||G?"rgba(255,255,255,0.06)":D.lime,color:!m||G?"rgba(255,255,255,0.4)":"#000"},children:M==="approving"?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"inline-block h-3 w-3 animate-spin rounded-full border-[1.5px] border-black/40 border-t-black"}),"Approving"]}):ae?"Needs more context":"Approve"})]})]})})]})})}const De=40;function Ee(n,t){return!n||n.trim().length===0?t:Ue(n.trim())||t}function We(n,t,p){const m=n==="approve"?`Approval failed for ${t} decision${t===1?"":"s"}.`:`Rejection failed for ${t} decision${t===1?"":"s"}.`;return Ee(p,m)}function qe(n){return n>=1440?"overdue":n>=60?"urgent":"normal"}function ht(n){return n.length>=32?n.slice(0,8):n}function Oe({group:n}){const t=qe(n.worstWaitingMinutes),p=n.clusters.length;return e.jsxs(ee.div,{initial:{opacity:0,x:-6},animate:{opacity:1,x:0},transition:{duration:.22,ease:[.22,1,.36,1]},className:"flex items-center gap-2 px-1 pb-1 pt-2.5 first:pt-0",children:[e.jsx("span",{className:"text-caption font-semibold text-white/70 truncate",children:n.label}),e.jsxs("span",{className:"text-micro text-muted whitespace-nowrap",children:["(",p," decision",p===1?"":"s",")"]}),t==="overdue"&&e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-red-500/[0.12] px-1.5 py-0.5 text-micro font-medium text-red-400",children:[e.jsx("span",{"aria-hidden":!0,className:"h-1.5 w-1.5 rounded-full bg-red-400"}),"overdue"]}),t==="urgent"&&e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-amber-400/[0.12] px-1.5 py-0.5 text-micro font-medium text-amber-400",children:[e.jsx("span",{"aria-hidden":!0,className:"h-1.5 w-1.5 rounded-full bg-amber-400"}),"urgent"]})]})}function ft(n){const t=(n.dedupeKey??"").trim();return t.length>0?t:n.id}function $e(n){return n.duplicateCount<=1?n.representative.title:`${n.representative.title}`}function gt(n){return n.replace(/[_-]/g," ").replace(/\b\w/g,t=>t.toUpperCase())}const St=d.memo(function({decisions:t,focusDecisionId:p=null,onFocusDecisionHandled:m,onApproveDecision:b,onRejectDecision:A,onApproveAll:y,onBulkDecisionAction:w,mutationState:C,showHeader:c=!0,panelStyle:P="card",className:B,initiativeNames:M}){var R;const $=Ze(),[T,N]=d.useState(!1),[te,K]=d.useState(new Set),[S,de]=d.useState(!1),[J,X]=d.useState(new Set),[V,_]=d.useState(null),[se,re]=d.useState(De),[F,k]=d.useState(null),ie=d.useRef(null),h=d.useMemo(()=>{const i=new Set;return[...t].filter(r=>i.has(r.id)?!1:(i.add(r.id),!0)).sort((r,o)=>{if(r.waitingMinutes!==o.waitingMinutes)return o.waitingMinutes-r.waitingMinutes;const l=Date.parse(r.requestedAt??r.updatedAt??""),u=Date.parse(o.requestedAt??o.updatedAt??""),g=Number.isFinite(l)?l:0;return(Number.isFinite(u)?u:0)-g})},[t]),E=d.useMemo(()=>{const i=new Map,r=[];for(const o of h){const l=ft(o),u=i.get(l);u?u.push(o):(i.set(l,[o]),r.push(l))}return r.map(o=>{const l=i.get(o)??[];return{key:o,representative:l[0],decisions:l,duplicateCount:l.length}})},[h]);d.useEffect(()=>{X(i=>{const r=new Set(E.map(l=>l.key)),o=new Set;for(const l of i)r.has(l)&&o.add(l);return o})},[E]);const z=J.size,j=d.useMemo(()=>E.slice(0,se),[E,se]),f=d.useMemo(()=>{const i=new Map,r=[];for(const l of j){const u=l.representative.initiativeId??"_unscoped";let g=i.get(u);g||(g=[],i.set(u,g),r.push(u)),g.push(l)}const o=r.map(l=>{const u=i.get(l),g=Math.max(0,...u.map(_e=>_e.representative.waitingMinutes)),v=l==="_unscoped"?"General":(M==null?void 0:M[l])??ht(l);return{initiativeId:l,label:v,clusters:u,worstWaitingMinutes:g}});return o.sort((l,u)=>u.worstWaitingMinutes-l.worstWaitingMinutes),o},[M,j]),ke=d.useMemo(()=>{if(j.length===0)return!1;for(const i of j)if(!J.has(i.key))return!1;return!0},[J,j]),ge=d.useMemo(()=>F?h.find(i=>i.id===F)??null:null,[F,h]),I=d.useMemo(()=>F?h.findIndex(i=>i.id===F):-1,[F,h]),ue=d.useCallback(i=>{const r=I+i;r>=0&&r<h.length&&k(h[r].id)},[I,h]),Ie=async(i,r)=>{_(null),K(l=>{const u=new Set(l);return u.add(i),u});const o=await b(i,r);return o.failed>0?_(We("approve",o.failed,o.firstError)):o.updated>0&&_("Decision approved. Changes synced."),K(l=>{const u=new Set(l);return u.delete(i),u}),o},pe=A?async(i,r)=>{_(null),K(l=>{const u=new Set(l);return u.add(i),u});const o=await A(i,r);return o.failed>0?_(We("reject",o.failed,o.firstError)):o.updated>0&&_("Decision rejected. Changes synced."),K(l=>{const u=new Set(l);return u.delete(i),u}),o}:void 0;d.useEffect(()=>{re(i=>E.length===0?0:Math.min(Math.max(De,i),E.length))},[E.length]),d.useEffect(()=>{const i=(p??"").trim();if(!i){ie.current=null;return}ie.current===i||!h.some(o=>o.id===i)||(ie.current=i,k(i),m==null||m(i))},[p,m,h]);const W=i=>{X(r=>{const o=new Set(r);return o.has(i)?o.delete(i):o.add(i),o})},be=()=>{X(i=>{if(j.length===0)return i;const r=new Set(i),o=ke;for(const l of j)o?r.delete(l.key):r.add(l.key);return r})},q=d.useMemo(()=>j.filter(i=>J.has(i.key)),[J,j]),ye=d.useMemo(()=>q.flatMap(i=>i.decisions.map(r=>r.id)),[q]),L=ye.length,ne=d.useMemo(()=>new Set(q.map(i=>i.representative.initiativeId??"_unscoped")).size,[q]),Z=d.useMemo(()=>q.filter(i=>!!i.representative.recommendedAction).length,[q]),Te=d.useMemo(()=>q.length===0?"No decisions selected":q.length===1?`Reviewing ${q[0].representative.title}`:`${q.length} decision groups selected`,[q]),we=d.useMemo(()=>{const i=[];return L>0&&i.push(`${L} decision${L===1?"":"s"}`),ne>0&&i.push(`${ne} initiative${ne===1?"":"s"}`),Z>0&&i.push(`${Z} recommended path${Z===1?"":"s"}`),i},[L,ne,Z]),Ce=async(i,r)=>{if(i.length===0)return{updated:0,failed:0};if(r==="approve"&&i.length===h.length)return y();let o=0,l=0,u;for(const g of i)try{const v=r==="approve"?await b(g):A?await A(g):{updated:0,failed:1};o+=v.updated,l+=v.failed,!u&&v.firstError&&(u=v.firstError)}catch{l+=1}return{updated:o,failed:l,firstError:u}},me=async i=>{if(T)return;const r=ye;if(r.length===0){_("No decisions selected for this action.");return}_(null),N(!0),K(new Set(r));try{const o=w?await w(r,i):await Ce(r,i),l=i==="approve"?"Approved":"Rejected";if(o.failed>0){const u=`${l} ${o.updated}; ${o.failed} failed.`,g=Ee(o.firstError,u);_(g===u?u:`${u} ${g}`)}else o.updated>0?_(`${l} ${o.updated} decision${o.updated===1?"":"s"}.`):_("No decisions were updated.");X(new Set),de(!1)}catch(o){const l=o instanceof Error?o.message:"";_(Ee(l,"Bulk decision action failed."))}finally{N(!1),K(new Set)}};d.useEffect(()=>{if(!V)return;const i=window.setTimeout(()=>_(null),5200);return()=>window.clearTimeout(i)},[V]);const je=V!==null&&!V.toLowerCase().includes("fail"),O=T||te.size>0,ve=Math.max(te.size,T?z:0),xe=O?`Applying ${ve} decision action${ve===1?"":"s"}…`:V??null,Q=O?"processing":V?je?"success":"warning":"idle",Se=!$&&j.length<=32,ae=ye.length>0&&!T,G=h.length,oe=((R=h[0])==null?void 0:R.waitingMinutes)??0,Ae=xe!==null||Q!=="idle",s=P==="card"?Xe:"div",a=h.length>0?S?e.jsxs("div",{className:"flex flex-shrink-0 items-center gap-2",children:[e.jsx("button",{type:"button",onClick:be,disabled:O,className:"control-pill h-8 px-3 text-caption font-semibold disabled:opacity-45",children:ke?"Clear all":"Select all"}),e.jsx("button",{type:"button",onClick:()=>{de(!1),X(new Set)},className:"control-pill h-8 px-3 text-caption font-semibold",children:"Cancel"})]}):e.jsx("button",{type:"button",onClick:()=>de(!0),className:"control-pill h-8 px-3 text-caption font-semibold",children:"Select"}):null,x=Ae?e.jsxs(ee.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},transition:{duration:.22,ease:[.22,1,.36,1]},"aria-live":"polite",className:le("flex min-h-[32px] items-center gap-2 rounded-lg border px-2.5 py-1.5 text-caption transition-colors overflow-hidden",Q==="processing"?"border-amber-300/25 bg-amber-400/[0.08] text-amber-100":Q==="success"?"border-lime/30 bg-lime/10 text-lime":Q==="warning"?"border-red-400/25 bg-red-500/[0.08] text-red-100":"border-strong bg-white/[0.02] text-secondary"),children:[Q==="processing"?e.jsx("span",{"aria-hidden":!0,className:"h-3.5 w-3.5 rounded-full border-2 border-amber-200/45 border-t-transparent animate-spin"}):Q==="success"?e.jsx(ce,{type:"decision",size:12,className:"opacity-90"}):Q==="warning"?e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"opacity-90",children:[e.jsx("path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z"}),e.jsx("line",{x1:"12",x2:"12",y1:"9",y2:"13"}),e.jsx("line",{x1:"12",x2:"12.01",y1:"17",y2:"17"})]}):e.jsx("span",{"aria-hidden":!0,className:"h-1.5 w-1.5 rounded-full bg-white/35"}),e.jsx("span",{className:"min-w-0 truncate",children:xe})]}):null,U=S&&z>0?e.jsx("div",{className:le(c?"mt-3 px-3 pb-3":"border-t border-subtle bg-black/40 px-2 pt-2 pb-2 backdrop-blur-xl"),children:e.jsx("div",{className:"rounded-xl border border-white/[0.08] bg-black/70 px-3 py-3 backdrop-blur-xl",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"min-w-0 space-y-1",children:[e.jsx("p",{className:"text-caption font-semibold text-white",children:Te}),e.jsx("p",{className:"text-micro leading-relaxed text-secondary",children:"Review the selected decision basket before applying a shared outcome."})]}),e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[e.jsxs("span",{className:"chip text-micro",children:[z," selected card",z===1?"":"s"]}),we.map(i=>e.jsx("span",{className:"chip text-micro",children:i},i))]}),e.jsxs("p",{className:"text-micro leading-relaxed text-white/45",children:[Z>0?"Recommended paths are present in this selection. Confirm the grouped consequence before approving. ":"","Bulk actions apply only to the selected decision groups in this rail."]}),e.jsxs("div",{className:"grid grid-cols-1 gap-2",children:[A?e.jsxs("button",{type:"button",onClick:()=>void me("reject"),disabled:!ae||O,className:"control-pill h-9 w-full justify-center px-3 text-caption font-semibold disabled:opacity-45",children:["Reject ",L||z," selected"]}):null,e.jsx("button",{type:"button",onClick:()=>void me("approve"),disabled:!ae||O,className:"control-pill h-9 w-full justify-center px-3 text-caption font-semibold disabled:opacity-45","data-tone":ae?"lime":void 0,children:T?"Applying…":`Approve ${L||z} selected`})]})]})})}):null;return e.jsxs(s,{className:le("flex h-full min-h-0 flex-col",P==="card"&&"card-enter",B),children:[e.jsx(xt,{open:F!==null,decision:ge,onClose:()=>k(null),onApprove:Ie,onReject:pe,onNavigate:ue,currentIndex:I>=0?I:void 0,totalCount:h.length}),c?e.jsxs("div",{className:"space-y-2.5 border-b border-subtle px-4 py-3.5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h2",{className:"inline-flex items-center gap-2 text-heading font-semibold text-white",children:[e.jsx(ce,{type:"decision",size:14}),"Decisions"]}),e.jsx("p",{className:"mt-0.5 text-caption text-secondary",children:G>0?`${G} decision${G===1?"":"s"} need${G===1?"s":""} your input`:"All clear — no decisions pending"}),oe>0?e.jsxs("p",{className:"mt-1 text-micro text-white/35",children:["Longest waiting: ",he(oe).text]}):null]}),a]}),x]}):null,e.jsxs("div",{className:le("min-h-0 flex-1 space-y-2 overflow-y-auto",c?"p-3":"p-0",S&&"pb-20"),children:[!c&&(a||x)?e.jsxs("div",{className:"space-y-2 border-b border-subtle px-2 pb-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-white/40",children:"Decision controls"}),e.jsx("p",{className:"mt-1 text-caption text-secondary",children:"Review or batch-resolve the visible decision groups."})]}),a]}),x]}):null,h.length===0&&e.jsx(ee.div,{initial:{opacity:0,scale:.97},animate:{opacity:1,scale:1},transition:{duration:.28,ease:[.22,1,.36,1]},className:"flex flex-col items-center gap-2.5 rounded-xl border border-subtle bg-white/[0.02] p-4 text-center",children:O?e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":!0,className:"h-5 w-5 rounded-full border-2 border-amber-200/45 border-t-transparent animate-spin"}),e.jsx("p",{className:"text-body text-secondary",children:"Finalizing decision updates…"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-faint",children:[e.jsx("path",{d:"M22 11.08V12a10 10 0 1 1-5.93-9.14"}),e.jsx("polyline",{points:"22 4 12 14.01 9 11.01"})]}),e.jsx("p",{className:"text-body text-secondary",children:"No pending decisions. All clear."})]})}),Se?e.jsx(Re,{mode:"popLayout",children:f.map(i=>e.jsxs("div",{children:[f.length>1?e.jsx(Oe,{group:i}):null,i.clusters.map((r,o)=>{const l=r.representative,u=r.decisions.some(Y=>te.has(Y.id)),g=J.has(r.key),v=qe(l.waitingMinutes),_e={duration:.24,ease:[.22,1,.36,1],...T?{delay:o*.04}:{}},ze=e.jsxs("div",{className:"flex items-start gap-2.5",children:[S?e.jsx("input",{type:"checkbox",checked:g,onChange:()=>W(r.key),disabled:u||O,onClick:Y=>Y.stopPropagation(),className:"mt-0.5 h-4 w-4 rounded border-white/20 bg-black/40 text-lime focus:ring-lime/40","aria-label":`Select ${l.title}`}):null,e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-1.5",children:[v!=="normal"?e.jsx("span",{"aria-label":v==="overdue"?"Overdue":"Urgent",className:le("mt-[5px] h-2 w-2 flex-shrink-0 rounded-full",v==="overdue"?"bg-red-400":"bg-amber-400")}):null,e.jsxs("p",{className:"flex min-w-0 items-start gap-1.5 text-body font-medium text-white",title:$e(r),children:[e.jsx(ce,{type:"decision",size:12,className:"mt-[3px] flex-shrink-0 opacity-90"}),e.jsx("span",{className:"line-clamp-2",children:$e(r)})]})]}),l.context?e.jsx("p",{className:"mt-1 line-clamp-2 text-caption text-secondary",title:l.context,children:l.context}):null,e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-1.5 text-micro text-secondary",children:[e.jsxs("span",{className:le("truncate",v==="overdue"?"text-red-400":v==="urgent"?"text-amber-400":"text-muted"),title:`${l.agentName??"OrgX Autopilot"} · ${he(l.waitingMinutes).text}`,children:[l.agentName??"OrgX Autopilot"," · ",he(l.waitingMinutes).text]}),r.duplicateCount>1?e.jsxs("span",{className:"chip text-micro",children:[r.duplicateCount," similar requests"]}):null,l.recommendedAction?e.jsx("span",{className:"chip text-micro border-[#14B8A6]/28 bg-[#14B8A6]/10 text-[#7AEDE5]",children:"Recommended path"}):null,l.decisionType?e.jsx("span",{className:"chip text-micro",children:gt(l.decisionType)}):null]}),S?null:e.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2 border-t border-white/[0.07] pt-2",children:[e.jsx("p",{className:"text-micro text-white/40",children:r.duplicateCount>1?"Open the cluster to inspect the lead decision and related duplicates.":"Open the full decision context before taking action."}),e.jsx("button",{type:"button",onClick:Y=>{Y.stopPropagation(),k(l.id)},className:"control-pill h-7 px-2.5 text-micro font-semibold","aria-label":`Review ${l.title}`,children:"Review"})]})]})]});return Se?e.jsx(ee.article,{role:"button",tabIndex:0,onClick:()=>{if(S){W(r.key);return}k(l.id)},onKeyDown:Y=>{if(!(Y.key!=="Enter"&&Y.key!==" ")){if(Y.preventDefault(),S){W(r.key);return}k(l.id)}},initial:T?{opacity:0,x:300}:{opacity:0,y:8,scale:.98},animate:{opacity:1,y:0,x:0,scale:1},exit:{opacity:0,scale:.96,y:-6},transition:_e,layout:!0,className:"mt-1.5 rounded-xl border bg-white/[0.03] px-3 py-2.5 transition-[border-color,box-shadow] cv-auto",style:{borderColor:g?`${D.lime}50`:"rgba(255, 255, 255, 0.1)",boxShadow:g?"0 0 0 1px rgba(191, 255, 0, 0.14)":"none"},children:ze},r.key):null})]},i.initiativeId))}):f.map(i=>e.jsxs("div",{children:[f.length>1?e.jsx(Oe,{group:i}):null,i.clusters.map(r=>{const o=r.representative,l=r.decisions.some(v=>te.has(v.id)),u=J.has(r.key),g=qe(o.waitingMinutes);return e.jsx("article",{role:"button",tabIndex:0,onClick:()=>{if(S){W(r.key);return}k(o.id)},onKeyDown:v=>{if(!(v.key!=="Enter"&&v.key!==" ")){if(v.preventDefault(),S){W(r.key);return}k(o.id)}},className:"mt-1.5 rounded-xl border bg-white/[0.03] px-3 py-2.5 transition-[border-color,box-shadow] cv-auto",style:{borderColor:u?`${D.lime}50`:"rgba(255, 255, 255, 0.1)",boxShadow:u?"0 0 0 1px rgba(191, 255, 0, 0.14)":"none"},children:e.jsxs("div",{className:"flex items-start gap-2.5",children:[S?e.jsx("input",{type:"checkbox",checked:u,onChange:()=>W(r.key),disabled:l||O,onClick:v=>v.stopPropagation(),className:"mt-0.5 h-4 w-4 rounded border-white/20 bg-black/40 text-lime focus:ring-lime/40","aria-label":`Select ${o.title}`}):null,e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-1.5",children:[g!=="normal"?e.jsx("span",{"aria-label":g==="overdue"?"Overdue":"Urgent",className:le("mt-[5px] h-2 w-2 flex-shrink-0 rounded-full",g==="overdue"?"bg-red-400":"bg-amber-400")}):null,e.jsxs("p",{className:"flex min-w-0 items-start gap-1.5 text-body font-medium text-white",title:$e(r),children:[e.jsx(ce,{type:"decision",size:12,className:"mt-[3px] flex-shrink-0 opacity-90"}),e.jsx("span",{className:"line-clamp-2",children:$e(r)})]})]}),o.context?e.jsx("p",{className:"mt-1 line-clamp-2 text-caption text-secondary",title:o.context,children:o.context}):null,e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-1.5 text-micro text-secondary",children:[e.jsxs("span",{children:[o.agentName??"OrgX Autopilot"," · ",he(o.waitingMinutes).text]}),r.duplicateCount>1?e.jsxs("span",{className:"chip text-micro",children:[r.duplicateCount," similar requests"]}):null,o.recommendedAction?e.jsx("span",{className:"chip text-micro border-[#14B8A6]/28 bg-[#14B8A6]/10 text-[#7AEDE5]",children:"Recommended path"}):null]}),S?null:e.jsx("div",{className:"mt-2 flex items-center justify-end border-t border-white/[0.07] pt-2",children:e.jsx("button",{type:"button",onClick:v=>{v.stopPropagation(),k(o.id)},className:"control-pill h-7 px-2.5 text-micro font-semibold","aria-label":`Review ${o.title}`,children:"Review"})})]})]})},r.key)})]},i.initiativeId)),j.length<E.length&&e.jsxs("button",{onClick:()=>re(i=>Math.min(E.length,i+De)),className:"w-full rounded-xl border border-white/[0.08] bg-white/[0.02] px-3 py-2 text-caption text-secondary transition-colors hover:bg-white/[0.05]",children:["Load more (",E.length-j.length," remaining)"]})]}),U]})});export{St as DecisionQueue};
@@ -1 +1 @@
1
- import{r as c}from"./Dj2k1r16.js";import{c as m}from"./DMKyYAtD.js";import{b as g,h as n}from"./C0i7ABUU.js";function h({authToken:s=null,embedMode:o=!1,enabled:i=!0}={}){var a;const u=c.useMemo(()=>["usage-control-plane",{authToken:s,embedMode:o}],[s,o]),e=m({queryKey:u,enabled:i,queryFn:async()=>{const t=await fetch("/orgx/api/usage/control-plane/summary",{headers:g({authToken:s,embedMode:o})}),r=await t.json().catch(()=>null);if(!t.ok){const l=(r&&typeof r=="object"&&"error"in r&&typeof r.error=="string"?r.error:null)??(r&&typeof r=="object"&&"message"in r&&typeof r.message=="string"?r.message:null)??`Failed to load usage summary (${t.status})`;throw new Error(n(l))}if(!r||typeof r!="object"||!("generatedAt"in r))throw new Error(n("Usage summary response is missing required fields."));return r},refetchInterval:6e4});return{summary:e.data??null,isLoading:e.isLoading,isFetching:e.isFetching,error:((a=e.error)==null?void 0:a.message)??null,refetch:e.refetch}}export{h as u};
1
+ import{r as c}from"./Dj2k1r16.js";import{c as m}from"./DMKyYAtD.js";import{b as g,h as n}from"./DNCNDTzi.js";function h({authToken:s=null,embedMode:o=!1,enabled:i=!0}={}){var a;const u=c.useMemo(()=>["usage-control-plane",{authToken:s,embedMode:o}],[s,o]),e=m({queryKey:u,enabled:i,queryFn:async()=>{const t=await fetch("/orgx/api/usage/control-plane/summary",{headers:g({authToken:s,embedMode:o})}),r=await t.json().catch(()=>null);if(!t.ok){const l=(r&&typeof r=="object"&&"error"in r&&typeof r.error=="string"?r.error:null)??(r&&typeof r=="object"&&"message"in r&&typeof r.message=="string"?r.message:null)??`Failed to load usage summary (${t.status})`;throw new Error(n(l))}if(!r||typeof r!="object"||!("generatedAt"in r))throw new Error(n("Usage summary response is missing required fields."));return r},refetchInterval:6e4});return{summary:e.data??null,isLoading:e.isLoading,isFetching:e.isFetching,error:((a=e.error)==null?void 0:a.message)??null,refetch:e.refetch}}export{h as u};
@@ -1 +1 @@
1
- import{r as l,j as e}from"./Dj2k1r16.js";import{f as r,z as u,E as f,w as j}from"./C0i7ABUU.js";import"./DMKyYAtD.js";import"./eeHXe_OQ.js";import"./cX2e-TLi.js";import"./BjK42gtU.js";import"./BV0BcV1u.js";function c(a){if(!a)return"unknown";try{return j(a)}catch{return"unknown"}}function E({open:a,onClose:o,outbox:t,onOpenSettings:p,onRefresh:m}){const[x,d]=l.useState(!1),h=l.useMemo(()=>Object.entries(t.pendingByQueue??{}).filter(([,s])=>typeof s=="number"&&s>0).sort((s,y)=>y[1]-s[1]),[t.pendingByQueue]),i=l.useMemo(()=>t.replayStatus==="error"?r.red:t.pendingTotal>0?r.amber:r.textMuted,[t.pendingTotal,t.replayStatus]),b=async()=>{try{await navigator.clipboard.writeText(JSON.stringify(t,null,2)),d(!0),setTimeout(()=>d(!1),1200)}catch{}};return e.jsx(u,{open:a,onClose:o,maxWidth:"max-w-3xl",fitContent:!0,children:e.jsxs("div",{className:"flex w-full flex-col",children:[e.jsxs("div",{className:"border-b border-subtle px-5 pt-5 pb-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h3",{className:"inline-flex items-center gap-2 text-heading font-semibold text-white",children:[e.jsx(f,{type:"outbox",size:14}),e.jsx("span",{className:"truncate",children:"Outbox"}),e.jsx("span",{className:"rounded-full border px-2 py-0.5 text-caption font-semibold",style:{borderColor:`${i}30`,backgroundColor:`${i}14`,color:i},children:t.pendingTotal})]}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:"Buffered updates queued for replay to OrgX when connectivity is healthy."})]}),e.jsx("button",{type:"button",onClick:o,className:"rounded-md border border-strong bg-white/[0.03] px-2.5 py-1.5 text-caption text-primary transition-colors hover:bg-white/[0.08]","aria-label":"Close outbox modal",children:"Close"})]}),e.jsxs("div",{className:"mt-3 grid grid-cols-1 gap-2 sm:grid-cols-2",children:[e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.02] px-3 py-2",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-secondary",children:"Replay status"}),e.jsx("p",{className:"mt-1 text-body font-semibold",style:{color:i},children:t.replayStatus}),t.lastReplayError&&t.replayStatus==="error"&&e.jsx("p",{className:"mt-1 line-clamp-2 text-caption text-red-200/75",children:t.lastReplayError})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.02] px-3 py-2",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-secondary",children:"Window"}),e.jsxs("p",{className:"mt-1 text-caption text-primary",children:["Oldest: ",e.jsx("span",{className:"font-semibold text-white",children:c(t.oldestEventAt)})]}),e.jsxs("p",{className:"mt-0.5 text-caption text-primary",children:["Newest: ",e.jsx("span",{className:"font-semibold text-white",children:c(t.newestEventAt)})]})]})]})]}),e.jsx("div",{className:"px-5 py-4",children:t.pendingTotal===0?e.jsx("div",{className:"rounded-xl border border-subtle bg-white/[0.02] p-4 text-body text-secondary",children:"Outbox is empty."}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-caption font-semibold uppercase tracking-[0.12em] text-secondary",children:"Queues"}),e.jsx("button",{type:"button",onClick:b,className:"rounded-md border border-strong bg-white/[0.03] px-2.5 py-1.5 text-caption text-secondary transition-colors hover:bg-white/[0.08]",children:x?"Copied":"Copy JSON"})]}),e.jsx("div",{className:"space-y-1.5",children:h.map(([n,s])=>e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-xl border border-white/[0.08] bg-white/[0.02] px-3 py-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-body font-medium text-white",children:n}),e.jsxs("p",{className:"mt-0.5 text-micro text-secondary",children:[s," event",s===1?"":"s"]})]}),e.jsx("span",{className:"rounded-full border px-2 py-0.5 text-caption font-semibold",style:{borderColor:`${r.amber}30`,backgroundColor:`${r.amber}14`,color:r.amber},children:s})]},n))}),e.jsx("div",{className:"rounded-xl border border-subtle bg-white/[0.02] px-3 py-2 text-caption text-secondary",children:"Replay is handled automatically by the OrgX sync service. If events stay queued, check Settings for API key and last replay errors."})]})}),e.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-subtle px-5 py-3",children:[e.jsx("button",{type:"button",onClick:m,className:"rounded-md border border-strong bg-white/[0.03] px-3 py-1.5 text-caption text-primary transition-colors hover:bg-white/[0.08]",children:"Refresh"}),e.jsx("button",{type:"button",onClick:p,className:"rounded-md border border-lime/25 bg-lime/10 px-3 py-1.5 text-caption font-semibold text-lime transition-colors hover:bg-lime/20",children:"Open settings"})]})]})})}export{E as BulkOutboxModal};
1
+ import{r as l,j as e}from"./Dj2k1r16.js";import{f as r,z as u,E as f,w as j}from"./DNCNDTzi.js";import"./DMKyYAtD.js";import"./eeHXe_OQ.js";import"./cX2e-TLi.js";import"./BjK42gtU.js";import"./BV0BcV1u.js";function c(a){if(!a)return"unknown";try{return j(a)}catch{return"unknown"}}function E({open:a,onClose:o,outbox:t,onOpenSettings:p,onRefresh:m}){const[x,d]=l.useState(!1),h=l.useMemo(()=>Object.entries(t.pendingByQueue??{}).filter(([,s])=>typeof s=="number"&&s>0).sort((s,y)=>y[1]-s[1]),[t.pendingByQueue]),i=l.useMemo(()=>t.replayStatus==="error"?r.red:t.pendingTotal>0?r.amber:r.textMuted,[t.pendingTotal,t.replayStatus]),b=async()=>{try{await navigator.clipboard.writeText(JSON.stringify(t,null,2)),d(!0),setTimeout(()=>d(!1),1200)}catch{}};return e.jsx(u,{open:a,onClose:o,maxWidth:"max-w-3xl",fitContent:!0,children:e.jsxs("div",{className:"flex w-full flex-col",children:[e.jsxs("div",{className:"border-b border-subtle px-5 pt-5 pb-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h3",{className:"inline-flex items-center gap-2 text-heading font-semibold text-white",children:[e.jsx(f,{type:"outbox",size:14}),e.jsx("span",{className:"truncate",children:"Outbox"}),e.jsx("span",{className:"rounded-full border px-2 py-0.5 text-caption font-semibold",style:{borderColor:`${i}30`,backgroundColor:`${i}14`,color:i},children:t.pendingTotal})]}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:"Buffered updates queued for replay to OrgX when connectivity is healthy."})]}),e.jsx("button",{type:"button",onClick:o,className:"rounded-md border border-strong bg-white/[0.03] px-2.5 py-1.5 text-caption text-primary transition-colors hover:bg-white/[0.08]","aria-label":"Close outbox modal",children:"Close"})]}),e.jsxs("div",{className:"mt-3 grid grid-cols-1 gap-2 sm:grid-cols-2",children:[e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.02] px-3 py-2",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-secondary",children:"Replay status"}),e.jsx("p",{className:"mt-1 text-body font-semibold",style:{color:i},children:t.replayStatus}),t.lastReplayError&&t.replayStatus==="error"&&e.jsx("p",{className:"mt-1 line-clamp-2 text-caption text-red-200/75",children:t.lastReplayError})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.02] px-3 py-2",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-secondary",children:"Window"}),e.jsxs("p",{className:"mt-1 text-caption text-primary",children:["Oldest: ",e.jsx("span",{className:"font-semibold text-white",children:c(t.oldestEventAt)})]}),e.jsxs("p",{className:"mt-0.5 text-caption text-primary",children:["Newest: ",e.jsx("span",{className:"font-semibold text-white",children:c(t.newestEventAt)})]})]})]})]}),e.jsx("div",{className:"px-5 py-4",children:t.pendingTotal===0?e.jsx("div",{className:"rounded-xl border border-subtle bg-white/[0.02] p-4 text-body text-secondary",children:"Outbox is empty."}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-caption font-semibold uppercase tracking-[0.12em] text-secondary",children:"Queues"}),e.jsx("button",{type:"button",onClick:b,className:"rounded-md border border-strong bg-white/[0.03] px-2.5 py-1.5 text-caption text-secondary transition-colors hover:bg-white/[0.08]",children:x?"Copied":"Copy JSON"})]}),e.jsx("div",{className:"space-y-1.5",children:h.map(([n,s])=>e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-xl border border-white/[0.08] bg-white/[0.02] px-3 py-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-body font-medium text-white",children:n}),e.jsxs("p",{className:"mt-0.5 text-micro text-secondary",children:[s," event",s===1?"":"s"]})]}),e.jsx("span",{className:"rounded-full border px-2 py-0.5 text-caption font-semibold",style:{borderColor:`${r.amber}30`,backgroundColor:`${r.amber}14`,color:r.amber},children:s})]},n))}),e.jsx("div",{className:"rounded-xl border border-subtle bg-white/[0.02] px-3 py-2 text-caption text-secondary",children:"Replay is handled automatically by the OrgX sync service. If events stay queued, check Settings for API key and last replay errors."})]})}),e.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-subtle px-5 py-3",children:[e.jsx("button",{type:"button",onClick:m,className:"rounded-md border border-strong bg-white/[0.03] px-3 py-1.5 text-caption text-primary transition-colors hover:bg-white/[0.08]",children:"Refresh"}),e.jsx("button",{type:"button",onClick:p,className:"rounded-md border border-lime/25 bg-lime/10 px-3 py-1.5 text-caption font-semibold text-lime transition-colors hover:bg-lime/20",children:"Open settings"})]})]})})}export{E as BulkOutboxModal};
@@ -1 +1 @@
1
- import{r as s,j as t}from"./Dj2k1r16.js";import{z as ke}from"./C0i7ABUU.js";import"./DMKyYAtD.js";import"./eeHXe_OQ.js";import"./cX2e-TLi.js";import"./BjK42gtU.js";import"./BV0BcV1u.js";const I={PREVIEW:"orgx_orchestrator_preview",APPLY:"orgx_orchestrator_apply",STATUS:"orgx_orchestrator_status"};function l(p){if(typeof p!="string")return null;const n=p.trim();return n.length?n:null}function Ce(p){if(!p.trim())return{};const n=JSON.parse(p);return!n||typeof n!="object"||Array.isArray(n)?{}:n}function Q(p){const n=l(p.transcript)??l(p.text)??l(p.delta??null);if(n)return n;const h=p.item&&typeof p.item=="object"?p.item:null,v=Array.isArray(h==null?void 0:h.content)?h==null?void 0:h.content:[];for(const y of v){if(!y||typeof y!="object")continue;const f=l(y.transcript)??l(y.text);if(f)return f}return null}function Se(p){const n=p.response&&typeof p.response=="object"?p.response:null,h=Array.isArray(n==null?void 0:n.output)?n==null?void 0:n.output:[],v=[];for(const y of h){if(!y||typeof y!="object")continue;const f=y;if(f.type!=="function_call")continue;const C=l(f.name),S=l(f.call_id)??l(f.id),A=typeof f.arguments=="string"?f.arguments:"{}";!C||!S||v.push({callId:S,name:C,arguments:A})}return v}function Ae(p){const n=Number.isFinite(p)?p*100:0;return`${Math.max(0,Math.min(100,Math.round(n)))}%`}const fe=[{type:"function",name:I.PREVIEW,description:"Preview orchestrator actions from a natural language command. Use this before apply.",parameters:{type:"object",additionalProperties:!1,properties:{input:{type:"string",description:"Natural language command from the operator."},workspace_id:{type:"string",description:"Optional OrgX workspace/command_center id."}},required:["input"]}},{type:"function",name:I.APPLY,description:"Apply selected action ids from a previewed command after user confirmation.",parameters:{type:"object",additionalProperties:!1,properties:{command_id:{type:"string",description:"Command id from preview response."},confirmed_action_ids:{type:"array",items:{type:"string"},description:"Optional subset of action ids to apply. Omit to apply all."},workspace_id:{type:"string",description:"Optional OrgX workspace/command_center id."}},required:["command_id"]}},{type:"function",name:I.STATUS,description:"Get latest status for a previously created command.",parameters:{type:"object",additionalProperties:!1,properties:{command_id:{type:"string",description:"Command id from preview/apply response."}},required:["command_id"]}}];function Me({open:p,selectedWorkspaceId:n,onClose:h}){var le,de,pe;const[v,y]=s.useState(!1),[f,C]=s.useState(!1),[S,A]=s.useState(!1),[xe,he]=s.useState("gpt-realtime-1.5"),[$,Z]=s.useState(""),[W,M]=s.useState(""),[o,P]=s.useState(null),[T,B]=s.useState([]),[ee,te]=s.useState(!1),[re,oe]=s.useState(!1),[se,b]=s.useState(null),[ne,X]=s.useState([]),G=s.useRef(null),D=s.useRef(null),O=s.useRef(null),H=s.useRef(null),E=s.useRef(""),J=s.useRef(new Set),R=s.useCallback(e=>{X(r=>[e,...r].slice(0,10))},[]),N=s.useCallback(()=>{A(!1),C(!1),J.current=new Set;const e=D.current;if(e)try{e.close()}catch{}D.current=null;const r=G.current;if(r)try{r.close()}catch{}G.current=null;const a=O.current;if(a)for(const m of a.getTracks())try{m.stop()}catch{}O.current=null;const d=H.current;if(d){try{const m=d.srcObject;m==null||m.getTracks().forEach(i=>i.stop())}catch{}try{d.pause()}catch{}d.srcObject=null}H.current=null},[]);s.useEffect(()=>{p||(N(),b(null),M(""),X([]),E.current="")},[N,p]),s.useEffect(()=>()=>N(),[N]);const g=s.useCallback(e=>{const r=D.current;!r||r.readyState!=="open"||r.send(JSON.stringify(e))},[]),ae=s.useCallback(async e=>{const r=await fetch(e),a=await r.json().catch(()=>({}));if(!r.ok)throw new Error(a&&typeof a=="object"&&"error"in a&&a.error||`Request failed: ${r.status}`);return a},[]),j=s.useCallback(async(e,r)=>{const a=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)}),d=await a.json().catch(()=>({}));if(!a.ok)throw new Error(d&&typeof d=="object"&&"error"in d&&d.error||`Request failed: ${a.status}`);return d},[]),L=s.useCallback(async e=>{if(!J.current.has(e.callId)){J.current.add(e.callId);try{const r=Ce(e.arguments);let a={ok:!1,error:"Unsupported tool call."};if(e.name===I.PREVIEW){const d=l(r.input);if(!d)throw new Error("Preview tool call requires input.");const m=await j("/orgx/api/orchestrator/commands/preview",{input:d,workspace_id:l(r.workspace_id)??n??void 0});if(!m.command)throw new Error(m.error??"Preview command failed.");P(m.command),B(m.command.proposedActions.map(i=>i.actionId)),a={ok:!0,command:m.command}}else if(e.name===I.APPLY){const d=l(r.command_id);if(!d)throw new Error("Apply tool call requires command_id.");const m=Array.isArray(r.confirmed_action_ids)?r.confirmed_action_ids.filter(F=>typeof F=="string"):void 0,i=await j("/orgx/api/orchestrator/commands/apply",{command_id:d,confirmed_action_ids:m,workspace_id:l(r.workspace_id)??n??void 0});if(!i.command)throw new Error(i.error??"Apply command failed.");P(i.command),a={ok:!0,command:i.command}}else if(e.name===I.STATUS){const d=l(r.command_id);if(!d)throw new Error("Status tool call requires command_id.");const m=await ae(`/orgx/api/orchestrator/commands/${encodeURIComponent(d)}`);if(!m.command)throw new Error(m.error??"Command status unavailable.");P(m.command),a={ok:!0,command:m.command}}g({type:"conversation.item.create",item:{type:"function_call_output",call_id:e.callId,output:JSON.stringify(a)}}),g({type:"response.create"}),R(`Tool executed: ${e.name}`)}catch(r){const a=r instanceof Error?r.message:"Tool execution failed.";b(a),g({type:"conversation.item.create",item:{type:"function_call_output",call_id:e.callId,output:JSON.stringify({ok:!1,error:a})}}),g({type:"response.create"}),R(`Tool failed: ${e.name}`)}}},[ae,R,j,n,g]),ye=s.useCallback(async()=>{var e,r,a,d,m;if(!((e=navigator.mediaDevices)!=null&&e.getUserMedia)){b("Microphone capture is unavailable in this browser/runtime.");return}b(null),y(!0),X([]);try{const i=await j("/orgx/api/realtime/session",{workspace_id:n??void 0,model:"gpt-realtime-1.5",voice:"alloy",tool_choice:"auto",tools:fe,instructions:"You are the OrgX realtime orchestrator copilot. Use tools for state-changing operations. Before applying actions, state the plan concisely."});if(!(i!=null&&i.session))throw new Error((i==null?void 0:i.error)??"Failed to create realtime session.");const F=l((r=i==null?void 0:i.session)==null?void 0:r.model)??l((a=i==null?void 0:i.defaults)==null?void 0:a.model)??"gpt-realtime-1.5";he(F);const me=l((m=(d=i==null?void 0:i.session)==null?void 0:d.client_secret)==null?void 0:m.value);if(!me)throw new Error("Realtime session is missing client_secret.");const U=await navigator.mediaDevices.getUserMedia({audio:!0});O.current=U;for(const _ of U.getAudioTracks())_.enabled=!1;const k=new RTCPeerConnection;G.current=k,U.getTracks().forEach(_=>k.addTrack(_,U));const q=document.createElement("audio");q.autoplay=!0,H.current=q,k.ontrack=_=>{const[u]=_.streams;u&&(q.srcObject=u,q.play().catch(()=>{}))};const V=k.createDataChannel("oai-events");D.current=V,V.onmessage=_=>{try{const u=JSON.parse(String(_.data)),x=l(u.type)??"";if(x==="error"){const c=u.error&&typeof u.error=="object"?u.error:null,w=l(c==null?void 0:c.message)??l(u.message)??"Realtime session error.";b(w),R(`Error: ${w}`);return}if(x==="conversation.item.input_audio_transcription.completed"){const c=Q(u);c&&Z(c)}if(x==="response.output_text.delta"||x==="response.text.delta"||x==="response.output_audio_transcript.delta"||x==="response.audio_transcript.delta"){const c=l(u.delta)??Q(u);c&&(E.current=`${E.current}${c}`,M(E.current))}if(x==="response.output_text.done"||x==="response.text.done"||x==="response.output_audio_transcript.done"||x==="response.audio_transcript.done"){const c=Q(u);c&&(E.current=c,M(c))}if(x==="response.function_call_arguments.done"){const c=l(u.call_id),w=l(u.name);if(c&&w){const z=typeof u.arguments=="string"?u.arguments:"{}";L({callId:c,name:w,arguments:z})}}if(x==="response.output_item.done"){const c=u.item&&typeof u.item=="object"?u.item:null;if((c==null?void 0:c.type)==="function_call"){const w=l(c.call_id)??l(c.id),z=l(c.name);if(w&&z){const Ne=typeof c.arguments=="string"?c.arguments:"{}";L({callId:w,name:z,arguments:Ne})}}}if(x==="response.done"){const c=Se(u);for(const w of c)L(w)}}catch{}},V.onopen=()=>{C(!0),g({type:"session.update",session:{tools:fe,tool_choice:"auto"}}),R("Realtime connected")},V.onclose=()=>{C(!1),A(!1)};const ue=await k.createOffer();await k.setLocalDescription(ue);const Y=await fetch(`https://api.openai.com/v1/realtime?model=${encodeURIComponent(F)}`,{method:"POST",headers:{Authorization:`Bearer ${me}`,"Content-Type":"application/sdp"},body:ue.sdp??""});if(!Y.ok){const _=await Y.text().catch(()=>Y.statusText);throw new Error(`Realtime SDP negotiation failed: ${_}`)}const ve=await Y.text();await k.setRemoteDescription({type:"answer",sdp:ve})}catch(i){N(),b(i instanceof Error?i.message:"Failed to connect realtime session.")}finally{y(!1)}},[N,L,R,j,n]),ie=s.useCallback(()=>{if(!f)return;const e=O.current;if(e){for(const r of e.getAudioTracks())r.enabled=!0;E.current="",M(""),A(!0),g({type:"input_audio_buffer.clear"})}},[f,g]),K=s.useCallback(()=>{const e=O.current;if(e)for(const r of e.getAudioTracks())r.enabled=!1;A(!1),g({type:"input_audio_buffer.commit"}),g({type:"response.create"})},[g]),ge=s.useCallback(async()=>{const e=$.trim();if(e){te(!0),b(null);try{const r=await j("/orgx/api/orchestrator/commands/preview",{input:e,workspace_id:n??void 0});if(!r.command)throw new Error(r.error??"Failed to preview command.");P(r.command),B(r.command.proposedActions.map(a=>a.actionId))}catch(r){b(r instanceof Error?r.message:"Failed to preview command.")}finally{te(!1)}}},[$,j,n]),be=s.useCallback(async()=>{if(o!=null&&o.id){oe(!0),b(null);try{const e=await j("/orgx/api/orchestrator/commands/apply",{command_id:o.id,confirmed_action_ids:T,workspace_id:n??void 0});if(!e.command)throw new Error(e.error??"Failed to apply command.");P(e.command)}catch(e){b(e instanceof Error?e.message:"Failed to apply command.")}finally{oe(!1)}}},[o==null?void 0:o.id,j,T,n]),ce=T.length,we=(((le=o==null?void 0:o.proposedActions)==null?void 0:le.length)??0)>0,je=!!(o!=null&&o.id)&&ce>0&&!re,_e=s.useMemo(()=>{const e=(o==null?void 0:o.status)??"draft";return e==="completed"?"text-lime":e==="completed_with_errors"||e==="failed"?"text-amber-300":e==="applying"?"text-teal":"text-secondary"},[o==null?void 0:o.status]);return t.jsxs(ke,{open:p,onClose:h,maxWidth:"max-w-5xl",fitContent:!0,closeOnEscapeWhenTyping:!1,children:[t.jsx("div",{className:"border-b border-strong px-4 py-3",children:t.jsxs("div",{className:"flex items-start justify-between gap-3",children:[t.jsxs("div",{children:[t.jsx("p",{className:"text-caption uppercase tracking-[0.14em] text-secondary",children:"Realtime Orchestrator"}),t.jsx("h2",{className:"text-heading font-semibold text-white",children:"GPT Realtime 1.5"}),t.jsx("p",{className:"text-micro text-secondary",children:"Voice + tool-calls for initiative launch, decision resolution, and Next Up control."})]}),t.jsx("button",{type:"button",onClick:h,className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption text-secondary transition-colors hover:bg-white/[0.08] hover:text-white",children:"Close"})]})}),t.jsxs("div",{className:"grid gap-4 px-4 pb-4 pt-3 lg:grid-cols-[1.12fr_1fr]",children:[t.jsxs("section",{className:"space-y-3",children:[t.jsxs("div",{className:"rounded-xl border border-strong bg-white/[0.02] p-3",children:[t.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[t.jsx("span",{className:"text-caption uppercase tracking-[0.12em] text-secondary",children:"Session"}),t.jsx("span",{className:"text-micro text-secondary",children:xe})]}),t.jsx("div",{className:"flex flex-wrap items-center gap-2",children:f?t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",onMouseDown:ie,onMouseUp:K,onMouseLeave:()=>{S&&K()},onTouchStart:e=>{e.preventDefault(),ie()},onTouchEnd:e=>{e.preventDefault(),K()},className:`rounded-full border px-3 py-1.5 text-caption font-semibold transition-colors ${S?"border-teal/45 bg-teal/[0.16] text-teal":"border-white/[0.2] bg-white/[0.04] text-primary hover:bg-white/[0.1]"}`,children:S?"Listening… release to send":"Hold to talk"}),t.jsx("button",{type:"button",onClick:N,className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption text-secondary transition-colors hover:bg-white/[0.08] hover:text-primary",children:"Disconnect"})]}):t.jsx("button",{type:"button",disabled:v,onClick:()=>void ye(),className:"rounded-full border border-lime/35 bg-lime/[0.12] px-3 py-1.5 text-caption font-semibold text-lime transition-colors hover:bg-lime/[0.2] disabled:cursor-not-allowed disabled:opacity-60",children:v?"Connecting…":"Connect Realtime"})}),ne.length>0?t.jsx("div",{className:"mt-3 rounded-lg border border-strong bg-black/20 p-2",children:ne.map((e,r)=>t.jsx("p",{className:"text-micro text-secondary",children:e},`${e}-${r}`))}):null]}),t.jsxs("div",{className:"rounded-xl border border-strong bg-white/[0.02] p-3",children:[t.jsx("label",{className:"mb-2 block text-caption uppercase tracking-[0.12em] text-secondary",children:"Command Input"}),t.jsx("textarea",{value:$,onChange:e=>Z(e.target.value),rows:4,"data-modal-autofocus":"true",placeholder:"Example: create initiative called AI Readiness Audit for this workspace",className:"w-full rounded-lg border border-strong bg-[#040912] px-3 py-2 text-body text-primary placeholder:text-secondary focus:border-lime/35 focus:outline-none"}),W?t.jsxs("p",{className:"mt-2 text-caption text-secondary",children:["Assistant: ",t.jsx("span",{className:"text-primary",children:W})]}):null,t.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[t.jsx("button",{type:"button",disabled:ee||$.trim().length===0,onClick:()=>void ge(),className:"rounded-full border border-teal/35 bg-teal/[0.12] px-3 py-1.5 text-caption font-semibold text-teal transition-colors hover:bg-teal/[0.2] disabled:cursor-not-allowed disabled:opacity-60",children:ee?"Previewing…":"Preview Actions"}),t.jsx("button",{type:"button",disabled:!je,onClick:()=>void be(),className:"rounded-full border border-lime/35 bg-lime/[0.12] px-3 py-1.5 text-caption font-semibold text-lime transition-colors hover:bg-lime/[0.2] disabled:cursor-not-allowed disabled:opacity-60",children:re?"Applying…":`Apply (${ce})`})]})]})]}),t.jsxs("section",{className:"space-y-3",children:[t.jsxs("div",{className:"rounded-xl border border-strong bg-white/[0.02] p-3",children:[t.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[t.jsx("span",{className:"text-caption uppercase tracking-[0.12em] text-secondary",children:"Command Status"}),t.jsx("span",{className:`text-caption font-semibold ${_e}`,children:(o==null?void 0:o.status)??"idle"})]}),t.jsx("p",{className:"text-body text-primary",children:(o==null?void 0:o.humanSummary)??"Preview a command or use voice to trigger tool calls."}),(de=o==null?void 0:o.riskFlags)!=null&&de.length?t.jsxs("p",{className:"mt-2 text-caption text-amber-200",children:["Risk flags: ",o.riskFlags.join(", ")]}):null]}),t.jsxs("div",{className:"max-h-[360px] space-y-2 overflow-y-auto rounded-xl border border-strong bg-white/[0.02] p-3",children:[t.jsx("p",{className:"text-caption uppercase tracking-[0.12em] text-secondary",children:"Proposed Actions"}),we?o.proposedActions.map(e=>{const r=T.includes(e.actionId);return t.jsx("label",{className:"block rounded-lg border border-strong bg-[#040912] p-2 text-body",children:t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsx("input",{type:"checkbox",checked:r,onChange:a=>{const d=a.target.checked?[...T,e.actionId]:T.filter(m=>m!==e.actionId);B(d)},className:"mt-1"}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"font-semibold text-primary",children:e.type}),t.jsx("p",{className:"text-caption text-secondary",children:e.reason}),t.jsxs("p",{className:"text-micro text-secondary",children:["confidence ",Ae(e.confidence)," • impact ",e.blockingImpact]})]})]})},e.actionId)}):t.jsx("p",{className:"text-body text-secondary",children:"No actions inferred yet."})]}),(((pe=o==null?void 0:o.results)==null?void 0:pe.length)??0)>0?t.jsxs("div",{className:"max-h-[220px] space-y-2 overflow-y-auto rounded-xl border border-strong bg-white/[0.02] p-3",children:[t.jsx("p",{className:"text-caption uppercase tracking-[0.12em] text-secondary",children:"Apply Results"}),o.results.map(e=>t.jsxs("div",{className:`rounded-lg border p-2 text-body ${e.ok?"border-lime/30 bg-lime/[0.08] text-lime":"border-amber-400/35 bg-amber-500/[0.12] text-amber-100"}`,children:[t.jsx("p",{className:"font-semibold",children:e.type}),t.jsx("p",{className:"text-caption",children:e.message}),e.error?t.jsxs("p",{className:"text-micro text-amber-200",children:["error: ",e.error]}):null]},`${e.actionId}-${e.type}`))]}):null]})]}),se?t.jsx("div",{className:"border-t border-amber-500/30 bg-amber-500/[0.12] px-4 py-2 text-caption text-amber-100",children:se}):null]})}export{Me as RealtimeOrchestratorModal};
1
+ import{r as s,j as t}from"./Dj2k1r16.js";import{z as ke}from"./DNCNDTzi.js";import"./DMKyYAtD.js";import"./eeHXe_OQ.js";import"./cX2e-TLi.js";import"./BjK42gtU.js";import"./BV0BcV1u.js";const I={PREVIEW:"orgx_orchestrator_preview",APPLY:"orgx_orchestrator_apply",STATUS:"orgx_orchestrator_status"};function l(p){if(typeof p!="string")return null;const n=p.trim();return n.length?n:null}function Ce(p){if(!p.trim())return{};const n=JSON.parse(p);return!n||typeof n!="object"||Array.isArray(n)?{}:n}function Q(p){const n=l(p.transcript)??l(p.text)??l(p.delta??null);if(n)return n;const h=p.item&&typeof p.item=="object"?p.item:null,v=Array.isArray(h==null?void 0:h.content)?h==null?void 0:h.content:[];for(const y of v){if(!y||typeof y!="object")continue;const f=l(y.transcript)??l(y.text);if(f)return f}return null}function Se(p){const n=p.response&&typeof p.response=="object"?p.response:null,h=Array.isArray(n==null?void 0:n.output)?n==null?void 0:n.output:[],v=[];for(const y of h){if(!y||typeof y!="object")continue;const f=y;if(f.type!=="function_call")continue;const C=l(f.name),S=l(f.call_id)??l(f.id),A=typeof f.arguments=="string"?f.arguments:"{}";!C||!S||v.push({callId:S,name:C,arguments:A})}return v}function Ae(p){const n=Number.isFinite(p)?p*100:0;return`${Math.max(0,Math.min(100,Math.round(n)))}%`}const fe=[{type:"function",name:I.PREVIEW,description:"Preview orchestrator actions from a natural language command. Use this before apply.",parameters:{type:"object",additionalProperties:!1,properties:{input:{type:"string",description:"Natural language command from the operator."},workspace_id:{type:"string",description:"Optional OrgX workspace/command_center id."}},required:["input"]}},{type:"function",name:I.APPLY,description:"Apply selected action ids from a previewed command after user confirmation.",parameters:{type:"object",additionalProperties:!1,properties:{command_id:{type:"string",description:"Command id from preview response."},confirmed_action_ids:{type:"array",items:{type:"string"},description:"Optional subset of action ids to apply. Omit to apply all."},workspace_id:{type:"string",description:"Optional OrgX workspace/command_center id."}},required:["command_id"]}},{type:"function",name:I.STATUS,description:"Get latest status for a previously created command.",parameters:{type:"object",additionalProperties:!1,properties:{command_id:{type:"string",description:"Command id from preview/apply response."}},required:["command_id"]}}];function Me({open:p,selectedWorkspaceId:n,onClose:h}){var le,de,pe;const[v,y]=s.useState(!1),[f,C]=s.useState(!1),[S,A]=s.useState(!1),[xe,he]=s.useState("gpt-realtime-1.5"),[$,Z]=s.useState(""),[W,M]=s.useState(""),[o,P]=s.useState(null),[T,B]=s.useState([]),[ee,te]=s.useState(!1),[re,oe]=s.useState(!1),[se,b]=s.useState(null),[ne,X]=s.useState([]),G=s.useRef(null),D=s.useRef(null),O=s.useRef(null),H=s.useRef(null),E=s.useRef(""),J=s.useRef(new Set),R=s.useCallback(e=>{X(r=>[e,...r].slice(0,10))},[]),N=s.useCallback(()=>{A(!1),C(!1),J.current=new Set;const e=D.current;if(e)try{e.close()}catch{}D.current=null;const r=G.current;if(r)try{r.close()}catch{}G.current=null;const a=O.current;if(a)for(const m of a.getTracks())try{m.stop()}catch{}O.current=null;const d=H.current;if(d){try{const m=d.srcObject;m==null||m.getTracks().forEach(i=>i.stop())}catch{}try{d.pause()}catch{}d.srcObject=null}H.current=null},[]);s.useEffect(()=>{p||(N(),b(null),M(""),X([]),E.current="")},[N,p]),s.useEffect(()=>()=>N(),[N]);const g=s.useCallback(e=>{const r=D.current;!r||r.readyState!=="open"||r.send(JSON.stringify(e))},[]),ae=s.useCallback(async e=>{const r=await fetch(e),a=await r.json().catch(()=>({}));if(!r.ok)throw new Error(a&&typeof a=="object"&&"error"in a&&a.error||`Request failed: ${r.status}`);return a},[]),j=s.useCallback(async(e,r)=>{const a=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)}),d=await a.json().catch(()=>({}));if(!a.ok)throw new Error(d&&typeof d=="object"&&"error"in d&&d.error||`Request failed: ${a.status}`);return d},[]),L=s.useCallback(async e=>{if(!J.current.has(e.callId)){J.current.add(e.callId);try{const r=Ce(e.arguments);let a={ok:!1,error:"Unsupported tool call."};if(e.name===I.PREVIEW){const d=l(r.input);if(!d)throw new Error("Preview tool call requires input.");const m=await j("/orgx/api/orchestrator/commands/preview",{input:d,workspace_id:l(r.workspace_id)??n??void 0});if(!m.command)throw new Error(m.error??"Preview command failed.");P(m.command),B(m.command.proposedActions.map(i=>i.actionId)),a={ok:!0,command:m.command}}else if(e.name===I.APPLY){const d=l(r.command_id);if(!d)throw new Error("Apply tool call requires command_id.");const m=Array.isArray(r.confirmed_action_ids)?r.confirmed_action_ids.filter(F=>typeof F=="string"):void 0,i=await j("/orgx/api/orchestrator/commands/apply",{command_id:d,confirmed_action_ids:m,workspace_id:l(r.workspace_id)??n??void 0});if(!i.command)throw new Error(i.error??"Apply command failed.");P(i.command),a={ok:!0,command:i.command}}else if(e.name===I.STATUS){const d=l(r.command_id);if(!d)throw new Error("Status tool call requires command_id.");const m=await ae(`/orgx/api/orchestrator/commands/${encodeURIComponent(d)}`);if(!m.command)throw new Error(m.error??"Command status unavailable.");P(m.command),a={ok:!0,command:m.command}}g({type:"conversation.item.create",item:{type:"function_call_output",call_id:e.callId,output:JSON.stringify(a)}}),g({type:"response.create"}),R(`Tool executed: ${e.name}`)}catch(r){const a=r instanceof Error?r.message:"Tool execution failed.";b(a),g({type:"conversation.item.create",item:{type:"function_call_output",call_id:e.callId,output:JSON.stringify({ok:!1,error:a})}}),g({type:"response.create"}),R(`Tool failed: ${e.name}`)}}},[ae,R,j,n,g]),ye=s.useCallback(async()=>{var e,r,a,d,m;if(!((e=navigator.mediaDevices)!=null&&e.getUserMedia)){b("Microphone capture is unavailable in this browser/runtime.");return}b(null),y(!0),X([]);try{const i=await j("/orgx/api/realtime/session",{workspace_id:n??void 0,model:"gpt-realtime-1.5",voice:"alloy",tool_choice:"auto",tools:fe,instructions:"You are the OrgX realtime orchestrator copilot. Use tools for state-changing operations. Before applying actions, state the plan concisely."});if(!(i!=null&&i.session))throw new Error((i==null?void 0:i.error)??"Failed to create realtime session.");const F=l((r=i==null?void 0:i.session)==null?void 0:r.model)??l((a=i==null?void 0:i.defaults)==null?void 0:a.model)??"gpt-realtime-1.5";he(F);const me=l((m=(d=i==null?void 0:i.session)==null?void 0:d.client_secret)==null?void 0:m.value);if(!me)throw new Error("Realtime session is missing client_secret.");const U=await navigator.mediaDevices.getUserMedia({audio:!0});O.current=U;for(const _ of U.getAudioTracks())_.enabled=!1;const k=new RTCPeerConnection;G.current=k,U.getTracks().forEach(_=>k.addTrack(_,U));const q=document.createElement("audio");q.autoplay=!0,H.current=q,k.ontrack=_=>{const[u]=_.streams;u&&(q.srcObject=u,q.play().catch(()=>{}))};const V=k.createDataChannel("oai-events");D.current=V,V.onmessage=_=>{try{const u=JSON.parse(String(_.data)),x=l(u.type)??"";if(x==="error"){const c=u.error&&typeof u.error=="object"?u.error:null,w=l(c==null?void 0:c.message)??l(u.message)??"Realtime session error.";b(w),R(`Error: ${w}`);return}if(x==="conversation.item.input_audio_transcription.completed"){const c=Q(u);c&&Z(c)}if(x==="response.output_text.delta"||x==="response.text.delta"||x==="response.output_audio_transcript.delta"||x==="response.audio_transcript.delta"){const c=l(u.delta)??Q(u);c&&(E.current=`${E.current}${c}`,M(E.current))}if(x==="response.output_text.done"||x==="response.text.done"||x==="response.output_audio_transcript.done"||x==="response.audio_transcript.done"){const c=Q(u);c&&(E.current=c,M(c))}if(x==="response.function_call_arguments.done"){const c=l(u.call_id),w=l(u.name);if(c&&w){const z=typeof u.arguments=="string"?u.arguments:"{}";L({callId:c,name:w,arguments:z})}}if(x==="response.output_item.done"){const c=u.item&&typeof u.item=="object"?u.item:null;if((c==null?void 0:c.type)==="function_call"){const w=l(c.call_id)??l(c.id),z=l(c.name);if(w&&z){const Ne=typeof c.arguments=="string"?c.arguments:"{}";L({callId:w,name:z,arguments:Ne})}}}if(x==="response.done"){const c=Se(u);for(const w of c)L(w)}}catch{}},V.onopen=()=>{C(!0),g({type:"session.update",session:{tools:fe,tool_choice:"auto"}}),R("Realtime connected")},V.onclose=()=>{C(!1),A(!1)};const ue=await k.createOffer();await k.setLocalDescription(ue);const Y=await fetch(`https://api.openai.com/v1/realtime?model=${encodeURIComponent(F)}`,{method:"POST",headers:{Authorization:`Bearer ${me}`,"Content-Type":"application/sdp"},body:ue.sdp??""});if(!Y.ok){const _=await Y.text().catch(()=>Y.statusText);throw new Error(`Realtime SDP negotiation failed: ${_}`)}const ve=await Y.text();await k.setRemoteDescription({type:"answer",sdp:ve})}catch(i){N(),b(i instanceof Error?i.message:"Failed to connect realtime session.")}finally{y(!1)}},[N,L,R,j,n]),ie=s.useCallback(()=>{if(!f)return;const e=O.current;if(e){for(const r of e.getAudioTracks())r.enabled=!0;E.current="",M(""),A(!0),g({type:"input_audio_buffer.clear"})}},[f,g]),K=s.useCallback(()=>{const e=O.current;if(e)for(const r of e.getAudioTracks())r.enabled=!1;A(!1),g({type:"input_audio_buffer.commit"}),g({type:"response.create"})},[g]),ge=s.useCallback(async()=>{const e=$.trim();if(e){te(!0),b(null);try{const r=await j("/orgx/api/orchestrator/commands/preview",{input:e,workspace_id:n??void 0});if(!r.command)throw new Error(r.error??"Failed to preview command.");P(r.command),B(r.command.proposedActions.map(a=>a.actionId))}catch(r){b(r instanceof Error?r.message:"Failed to preview command.")}finally{te(!1)}}},[$,j,n]),be=s.useCallback(async()=>{if(o!=null&&o.id){oe(!0),b(null);try{const e=await j("/orgx/api/orchestrator/commands/apply",{command_id:o.id,confirmed_action_ids:T,workspace_id:n??void 0});if(!e.command)throw new Error(e.error??"Failed to apply command.");P(e.command)}catch(e){b(e instanceof Error?e.message:"Failed to apply command.")}finally{oe(!1)}}},[o==null?void 0:o.id,j,T,n]),ce=T.length,we=(((le=o==null?void 0:o.proposedActions)==null?void 0:le.length)??0)>0,je=!!(o!=null&&o.id)&&ce>0&&!re,_e=s.useMemo(()=>{const e=(o==null?void 0:o.status)??"draft";return e==="completed"?"text-lime":e==="completed_with_errors"||e==="failed"?"text-amber-300":e==="applying"?"text-teal":"text-secondary"},[o==null?void 0:o.status]);return t.jsxs(ke,{open:p,onClose:h,maxWidth:"max-w-5xl",fitContent:!0,closeOnEscapeWhenTyping:!1,children:[t.jsx("div",{className:"border-b border-strong px-4 py-3",children:t.jsxs("div",{className:"flex items-start justify-between gap-3",children:[t.jsxs("div",{children:[t.jsx("p",{className:"text-caption uppercase tracking-[0.14em] text-secondary",children:"Realtime Orchestrator"}),t.jsx("h2",{className:"text-heading font-semibold text-white",children:"GPT Realtime 1.5"}),t.jsx("p",{className:"text-micro text-secondary",children:"Voice + tool-calls for initiative launch, decision resolution, and Next Up control."})]}),t.jsx("button",{type:"button",onClick:h,className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption text-secondary transition-colors hover:bg-white/[0.08] hover:text-white",children:"Close"})]})}),t.jsxs("div",{className:"grid gap-4 px-4 pb-4 pt-3 lg:grid-cols-[1.12fr_1fr]",children:[t.jsxs("section",{className:"space-y-3",children:[t.jsxs("div",{className:"rounded-xl border border-strong bg-white/[0.02] p-3",children:[t.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[t.jsx("span",{className:"text-caption uppercase tracking-[0.12em] text-secondary",children:"Session"}),t.jsx("span",{className:"text-micro text-secondary",children:xe})]}),t.jsx("div",{className:"flex flex-wrap items-center gap-2",children:f?t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",onMouseDown:ie,onMouseUp:K,onMouseLeave:()=>{S&&K()},onTouchStart:e=>{e.preventDefault(),ie()},onTouchEnd:e=>{e.preventDefault(),K()},className:`rounded-full border px-3 py-1.5 text-caption font-semibold transition-colors ${S?"border-teal/45 bg-teal/[0.16] text-teal":"border-white/[0.2] bg-white/[0.04] text-primary hover:bg-white/[0.1]"}`,children:S?"Listening… release to send":"Hold to talk"}),t.jsx("button",{type:"button",onClick:N,className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption text-secondary transition-colors hover:bg-white/[0.08] hover:text-primary",children:"Disconnect"})]}):t.jsx("button",{type:"button",disabled:v,onClick:()=>void ye(),className:"rounded-full border border-lime/35 bg-lime/[0.12] px-3 py-1.5 text-caption font-semibold text-lime transition-colors hover:bg-lime/[0.2] disabled:cursor-not-allowed disabled:opacity-60",children:v?"Connecting…":"Connect Realtime"})}),ne.length>0?t.jsx("div",{className:"mt-3 rounded-lg border border-strong bg-black/20 p-2",children:ne.map((e,r)=>t.jsx("p",{className:"text-micro text-secondary",children:e},`${e}-${r}`))}):null]}),t.jsxs("div",{className:"rounded-xl border border-strong bg-white/[0.02] p-3",children:[t.jsx("label",{className:"mb-2 block text-caption uppercase tracking-[0.12em] text-secondary",children:"Command Input"}),t.jsx("textarea",{value:$,onChange:e=>Z(e.target.value),rows:4,"data-modal-autofocus":"true",placeholder:"Example: create initiative called AI Readiness Audit for this workspace",className:"w-full rounded-lg border border-strong bg-[#040912] px-3 py-2 text-body text-primary placeholder:text-secondary focus:border-lime/35 focus:outline-none"}),W?t.jsxs("p",{className:"mt-2 text-caption text-secondary",children:["Assistant: ",t.jsx("span",{className:"text-primary",children:W})]}):null,t.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[t.jsx("button",{type:"button",disabled:ee||$.trim().length===0,onClick:()=>void ge(),className:"rounded-full border border-teal/35 bg-teal/[0.12] px-3 py-1.5 text-caption font-semibold text-teal transition-colors hover:bg-teal/[0.2] disabled:cursor-not-allowed disabled:opacity-60",children:ee?"Previewing…":"Preview Actions"}),t.jsx("button",{type:"button",disabled:!je,onClick:()=>void be(),className:"rounded-full border border-lime/35 bg-lime/[0.12] px-3 py-1.5 text-caption font-semibold text-lime transition-colors hover:bg-lime/[0.2] disabled:cursor-not-allowed disabled:opacity-60",children:re?"Applying…":`Apply (${ce})`})]})]})]}),t.jsxs("section",{className:"space-y-3",children:[t.jsxs("div",{className:"rounded-xl border border-strong bg-white/[0.02] p-3",children:[t.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[t.jsx("span",{className:"text-caption uppercase tracking-[0.12em] text-secondary",children:"Command Status"}),t.jsx("span",{className:`text-caption font-semibold ${_e}`,children:(o==null?void 0:o.status)??"idle"})]}),t.jsx("p",{className:"text-body text-primary",children:(o==null?void 0:o.humanSummary)??"Preview a command or use voice to trigger tool calls."}),(de=o==null?void 0:o.riskFlags)!=null&&de.length?t.jsxs("p",{className:"mt-2 text-caption text-amber-200",children:["Risk flags: ",o.riskFlags.join(", ")]}):null]}),t.jsxs("div",{className:"max-h-[360px] space-y-2 overflow-y-auto rounded-xl border border-strong bg-white/[0.02] p-3",children:[t.jsx("p",{className:"text-caption uppercase tracking-[0.12em] text-secondary",children:"Proposed Actions"}),we?o.proposedActions.map(e=>{const r=T.includes(e.actionId);return t.jsx("label",{className:"block rounded-lg border border-strong bg-[#040912] p-2 text-body",children:t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsx("input",{type:"checkbox",checked:r,onChange:a=>{const d=a.target.checked?[...T,e.actionId]:T.filter(m=>m!==e.actionId);B(d)},className:"mt-1"}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"font-semibold text-primary",children:e.type}),t.jsx("p",{className:"text-caption text-secondary",children:e.reason}),t.jsxs("p",{className:"text-micro text-secondary",children:["confidence ",Ae(e.confidence)," • impact ",e.blockingImpact]})]})]})},e.actionId)}):t.jsx("p",{className:"text-body text-secondary",children:"No actions inferred yet."})]}),(((pe=o==null?void 0:o.results)==null?void 0:pe.length)??0)>0?t.jsxs("div",{className:"max-h-[220px] space-y-2 overflow-y-auto rounded-xl border border-strong bg-white/[0.02] p-3",children:[t.jsx("p",{className:"text-caption uppercase tracking-[0.12em] text-secondary",children:"Apply Results"}),o.results.map(e=>t.jsxs("div",{className:`rounded-lg border p-2 text-body ${e.ok?"border-lime/30 bg-lime/[0.08] text-lime":"border-amber-400/35 bg-amber-500/[0.12] text-amber-100"}`,children:[t.jsx("p",{className:"font-semibold",children:e.type}),t.jsx("p",{className:"text-caption",children:e.message}),e.error?t.jsxs("p",{className:"text-micro text-amber-200",children:["error: ",e.error]}):null]},`${e.actionId}-${e.type}`))]}):null]})]}),se?t.jsx("div",{className:"border-t border-amber-500/30 bg-amber-500/[0.12] px-4 py-2 text-caption text-amber-100",children:se}):null]})}export{Me as RealtimeOrchestratorModal};