@useorgx/openclaw-plugin 0.7.0 → 0.7.2

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 (122) hide show
  1. package/README.md +42 -11
  2. package/dashboard/dist/assets/6mILZQ2a.js +1 -0
  3. package/dashboard/dist/assets/6mILZQ2a.js.br +0 -0
  4. package/dashboard/dist/assets/6mILZQ2a.js.gz +0 -0
  5. package/dashboard/dist/assets/{DG6y9wJI.js → 8dksYiq4.js} +1 -1
  6. package/dashboard/dist/assets/8dksYiq4.js.br +0 -0
  7. package/dashboard/dist/assets/8dksYiq4.js.gz +0 -0
  8. package/dashboard/dist/assets/{PAUiij_z.js → B5zYRHc3.js} +1 -1
  9. package/dashboard/dist/assets/B5zYRHc3.js.br +0 -0
  10. package/dashboard/dist/assets/B5zYRHc3.js.gz +0 -0
  11. package/dashboard/dist/assets/{CFGKRAzG.js → B6wPWJ35.js} +1 -1
  12. package/dashboard/dist/assets/B6wPWJ35.js.br +0 -0
  13. package/dashboard/dist/assets/B6wPWJ35.js.gz +0 -0
  14. package/dashboard/dist/assets/BWEwjt1W.js +1 -0
  15. package/dashboard/dist/assets/BWEwjt1W.js.br +0 -0
  16. package/dashboard/dist/assets/BWEwjt1W.js.gz +0 -0
  17. package/dashboard/dist/assets/BzRbDCAD.css +1 -0
  18. package/dashboard/dist/assets/BzRbDCAD.css.br +0 -0
  19. package/dashboard/dist/assets/BzRbDCAD.css.gz +0 -0
  20. package/dashboard/dist/assets/{DNxKz-GV.js → C8uM3AX8.js} +1 -1
  21. package/dashboard/dist/assets/C8uM3AX8.js.br +0 -0
  22. package/dashboard/dist/assets/C8uM3AX8.js.gz +0 -0
  23. package/dashboard/dist/assets/C9jy61eu.js +212 -0
  24. package/dashboard/dist/assets/C9jy61eu.js.br +0 -0
  25. package/dashboard/dist/assets/C9jy61eu.js.gz +0 -0
  26. package/dashboard/dist/assets/{CE38zU4U.js → CC63EwFD.js} +1 -1
  27. package/dashboard/dist/assets/CC63EwFD.js.br +0 -0
  28. package/dashboard/dist/assets/CC63EwFD.js.gz +0 -0
  29. package/dashboard/dist/assets/{nByHNHoW.js → CZaT3ob_.js} +1 -1
  30. package/dashboard/dist/assets/CZaT3ob_.js.br +0 -0
  31. package/dashboard/dist/assets/CZaT3ob_.js.gz +0 -0
  32. package/dashboard/dist/assets/{tS9mbYZi.js → CgaottFX.js} +1 -1
  33. package/dashboard/dist/assets/CgaottFX.js.br +0 -0
  34. package/dashboard/dist/assets/CgaottFX.js.gz +0 -0
  35. package/dashboard/dist/assets/CzCxAZlW.js +1 -0
  36. package/dashboard/dist/assets/CzCxAZlW.js.br +0 -0
  37. package/dashboard/dist/assets/CzCxAZlW.js.gz +0 -0
  38. package/dashboard/dist/assets/D3iMTYEj.js +1 -0
  39. package/dashboard/dist/assets/D3iMTYEj.js.br +0 -0
  40. package/dashboard/dist/assets/D3iMTYEj.js.gz +0 -0
  41. package/dashboard/dist/assets/{DjcdE6jC.js → D8JNX8kq.js} +1 -1
  42. package/dashboard/dist/assets/D8JNX8kq.js.br +0 -0
  43. package/dashboard/dist/assets/D8JNX8kq.js.gz +0 -0
  44. package/dashboard/dist/assets/DnA8dpj6.js +1 -0
  45. package/dashboard/dist/assets/DnA8dpj6.js.br +0 -0
  46. package/dashboard/dist/assets/DnA8dpj6.js.gz +0 -0
  47. package/dashboard/dist/assets/{DbNoijHm.js → IUexzymk.js} +1 -1
  48. package/dashboard/dist/assets/IUexzymk.js.br +0 -0
  49. package/dashboard/dist/assets/IUexzymk.js.gz +0 -0
  50. package/dashboard/dist/assets/{CZZTvkQZ.js → rttbDbEx.js} +1 -1
  51. package/dashboard/dist/assets/rttbDbEx.js.br +0 -0
  52. package/dashboard/dist/assets/rttbDbEx.js.gz +0 -0
  53. package/dashboard/dist/index.html +2 -2
  54. package/dashboard/dist/index.html.br +0 -0
  55. package/dashboard/dist/index.html.gz +0 -0
  56. package/dist/contracts/practice-exercise-schema.d.ts +216 -0
  57. package/dist/contracts/practice-exercise-schema.js +314 -0
  58. package/dist/contracts/shared-types.d.ts +2 -2
  59. package/dist/contracts/shared-types.js +22 -0
  60. package/dist/contracts/types.d.ts +20 -0
  61. package/dist/fs-utils.js +1 -13
  62. package/dist/http/helpers/auto-continue-engine.js +638 -24
  63. package/dist/http/helpers/autopilot-runtime.js +22 -7
  64. package/dist/http/helpers/autopilot-slice-utils.js +0 -2
  65. package/dist/http/helpers/kickoff-context.js +30 -0
  66. package/dist/http/helpers/slice-run-projections.js +19 -2
  67. package/dist/http/index.js +151 -93
  68. package/dist/http/routes/agent-suite.js +87 -0
  69. package/dist/http/routes/entities.js +1 -63
  70. package/dist/http/routes/live-snapshot.d.ts +1 -0
  71. package/dist/http/routes/live-snapshot.js +15 -4
  72. package/dist/http/routes/live-terminal.js +1 -108
  73. package/dist/http/routes/live-triage.js +1 -57
  74. package/dist/http/routes/mission-control-actions.js +0 -88
  75. package/dist/http/routes/mission-control-read.js +73 -8
  76. package/dist/mcp-http-handler.d.ts +3 -0
  77. package/dist/mcp-http-handler.js +2 -2
  78. package/dist/paths.js +14 -2
  79. package/dist/reporting/rollups.d.ts +0 -12
  80. package/dist/reporting/rollups.js +0 -35
  81. package/package.json +7 -3
  82. package/dashboard/dist/assets/BXWDRGm-.js +0 -1
  83. package/dashboard/dist/assets/BXWDRGm-.js.br +0 -0
  84. package/dashboard/dist/assets/BXWDRGm-.js.gz +0 -0
  85. package/dashboard/dist/assets/CE38zU4U.js.br +0 -0
  86. package/dashboard/dist/assets/CE38zU4U.js.gz +0 -0
  87. package/dashboard/dist/assets/CFGKRAzG.js.br +0 -0
  88. package/dashboard/dist/assets/CFGKRAzG.js.gz +0 -0
  89. package/dashboard/dist/assets/CGGR2GZh.js +0 -1
  90. package/dashboard/dist/assets/CGGR2GZh.js.br +0 -0
  91. package/dashboard/dist/assets/CGGR2GZh.js.gz +0 -0
  92. package/dashboard/dist/assets/CPFiTmlw.js +0 -8
  93. package/dashboard/dist/assets/CPFiTmlw.js.br +0 -0
  94. package/dashboard/dist/assets/CPFiTmlw.js.gz +0 -0
  95. package/dashboard/dist/assets/CZZTvkQZ.js.br +0 -0
  96. package/dashboard/dist/assets/CZZTvkQZ.js.gz +0 -0
  97. package/dashboard/dist/assets/D-bf6hEI.js +0 -213
  98. package/dashboard/dist/assets/D-bf6hEI.js.br +0 -0
  99. package/dashboard/dist/assets/D-bf6hEI.js.gz +0 -0
  100. package/dashboard/dist/assets/DG6y9wJI.js.br +0 -0
  101. package/dashboard/dist/assets/DG6y9wJI.js.gz +0 -0
  102. package/dashboard/dist/assets/DNxKz-GV.js.br +0 -0
  103. package/dashboard/dist/assets/DNxKz-GV.js.gz +0 -0
  104. package/dashboard/dist/assets/DW_rKUic.js +0 -11
  105. package/dashboard/dist/assets/DW_rKUic.js.br +0 -0
  106. package/dashboard/dist/assets/DW_rKUic.js.gz +0 -0
  107. package/dashboard/dist/assets/DbNoijHm.js.br +0 -0
  108. package/dashboard/dist/assets/DbNoijHm.js.gz +0 -0
  109. package/dashboard/dist/assets/DjcdE6jC.js.br +0 -0
  110. package/dashboard/dist/assets/DjcdE6jC.js.gz +0 -0
  111. package/dashboard/dist/assets/FZYuCDnt.js +0 -1
  112. package/dashboard/dist/assets/FZYuCDnt.js.br +0 -0
  113. package/dashboard/dist/assets/FZYuCDnt.js.gz +0 -0
  114. package/dashboard/dist/assets/PAUiij_z.js.br +0 -0
  115. package/dashboard/dist/assets/PAUiij_z.js.gz +0 -0
  116. package/dashboard/dist/assets/h5biQs2I.css +0 -1
  117. package/dashboard/dist/assets/h5biQs2I.css.br +0 -0
  118. package/dashboard/dist/assets/h5biQs2I.css.gz +0 -0
  119. package/dashboard/dist/assets/nByHNHoW.js.br +0 -0
  120. package/dashboard/dist/assets/nByHNHoW.js.gz +0 -0
  121. package/dashboard/dist/assets/tS9mbYZi.js.br +0 -0
  122. package/dashboard/dist/assets/tS9mbYZi.js.gz +0 -0
@@ -157,41 +157,6 @@ export function computeTaskCompletionReadiness(input) {
157
157
  warnings,
158
158
  };
159
159
  }
160
- /**
161
- * Derive an honest lifecycle state for an entity based on its raw status
162
- * and child statuses. This is the authoritative backend derivation —
163
- * the dashboard mirrors this logic in status-taxonomy.ts.
164
- */
165
- export function deriveLifecycleState(rawStatus, childStatuses) {
166
- const s = classifyTaskState(rawStatus);
167
- if (s === 'done')
168
- return 'Completed';
169
- if (s === 'blocked')
170
- return 'Blocked';
171
- if (!childStatuses || childStatuses.length === 0) {
172
- if (s === 'active')
173
- return 'In Progress';
174
- return 'Queued';
175
- }
176
- const counts = summarizeTaskStatuses(childStatuses);
177
- if (counts.total > 0 && counts.done >= counts.total)
178
- return 'Completed';
179
- if (counts.blocked > 0 && counts.active === 0 && counts.done < counts.total)
180
- return 'Blocked';
181
- if (counts.active > 0 || counts.done > 0)
182
- return 'In Progress';
183
- return 'Queued';
184
- }
185
- /**
186
- * Compute cascaded progress: parent progress derived from child task states.
187
- * Returns a percentage (0–100) representing weighted completion.
188
- */
189
- export function cascadeProgressFromChildren(childStatuses) {
190
- if (!Array.isArray(childStatuses) || childStatuses.length === 0)
191
- return 0;
192
- const counts = summarizeTaskStatuses(childStatuses);
193
- return toPercent(counts.done, counts.total);
194
- }
195
160
  export function detectEvalPassRateDrift(input) {
196
161
  const thresholdDropPct = typeof input.thresholdDropPct === "number" && Number.isFinite(input.thresholdDropPct) && input.thresholdDropPct >= 0
197
162
  ? input.thresholdDropPct
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@useorgx/openclaw-plugin",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "description": "OrgX plugin for OpenClaw — agent orchestration, quality gates, model routing, and live dashboard",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -21,8 +21,9 @@
21
21
  }
22
22
  },
23
23
  "openclaw": {
24
- "plugin": true,
25
- "entry": "./dist/index.js"
24
+ "extensions": [
25
+ "./dist/index.js"
26
+ ]
26
27
  },
27
28
  "files": [
28
29
  "dist/",
@@ -83,6 +84,9 @@
83
84
  ],
84
85
  "author": "OrgX Team <team@useorgx.com>",
85
86
  "license": "MIT",
87
+ "publishConfig": {
88
+ "access": "public"
89
+ },
86
90
  "repository": {
87
91
  "type": "git",
88
92
  "url": "https://github.com/useorgx/openclaw-plugin.git"
@@ -1 +0,0 @@
1
- import{u as Ft,r as h,a as Bt,b as Ee,j as e}from"./cNrhgGc1.js";import{i as Lt,q as Te,b as Be,N as et,B as Rt,u as Mt,P as Et,w as he,C as tt,K as st,x as se,A as ot,E as Ne,h as Ke,y as nt,z as Tt,U as Pt}from"./D-bf6hEI.js";import{S as G}from"./nByHNHoW.js";import{A as Pe,m as ce,R as At,b as _t,a as zt}from"./CxQ08qFN.js";function Kt({initiativeId:t=null,authToken:r=null,embedMode:o=!1,enabled:s=!0}){var R,A,oe;const g=Ft(),y=Lt(),j=h.useMemo(()=>Te.autoContinueStatus({initiativeId:t??"__global__",authToken:r,embedMode:o}),[t,r,o]),w=Bt({queryKey:j,enabled:s&&(!!t||t===null),queryFn:async()=>{if(y)return{ok:!0,initiativeId:t,run:null,defaults:{tokenBudget:null,tickMs:0}};const x=new URLSearchParams;t&&x.set("initiative_id",t);const m=await fetch(`/orgx/api/mission-control/auto-continue/status?${x.toString()}`,{headers:Be({authToken:r,embedMode:o})}),u=await m.json().catch(()=>null);if(!m.ok){const c=typeof(u==null?void 0:u.error)=="string"&&u.error||typeof(u==null?void 0:u.message)=="string"&&u.message||`Failed to load auto-continue status (${m.status})`;return{ok:!1,initiativeId:t,run:null,defaults:{tokenBudget:null,tickMs:0},error:c}}return u},refetchInterval:x=>{var M,f;const m=x.state.data;if((m==null?void 0:m.ok)===!1)return!1;const u=((M=m==null?void 0:m.error)==null?void 0:M.toLowerCase())??"";if(u.includes("404")||u.includes("400")||u.includes("not found")||u.includes("bad request"))return!1;const v=((f=m==null?void 0:m.run)==null?void 0:f.status)??null;return v==="running"||v==="stopping"?2500:12e3}}),$=async()=>{await g.invalidateQueries({queryKey:j}),await g.invalidateQueries({queryKey:Te.missionControlGraph({initiativeId:t,authToken:r,embedMode:o})}),await g.invalidateQueries({queryKey:Te.liveData({authToken:r,embedMode:o})})},T=Ee({mutationFn:async x=>{if(y){const v=w.data??null;return{ok:!0,initiativeId:t,run:(v==null?void 0:v.run)??null,defaults:(v==null?void 0:v.defaults)??{tokenBudget:null,tickMs:0}}}const m={};t&&(m.initiativeId=t),m.ignoreSpawnGuardRateLimit=!0,x&&typeof x=="object"&&(typeof x.tokenBudgetTokens=="number"&&(m.tokenBudgetTokens=x.tokenBudgetTokens),typeof x.agentId=="string"&&x.agentId.trim().length>0&&(m.agentId=x.agentId.trim()),typeof x.maxParallelSlices=="number"&&Number.isFinite(x.maxParallelSlices)&&(m.maxParallelSlices=x.maxParallelSlices),x.parallelMode==="iwmt"&&(m.parallelMode=x.parallelMode));const u=await fetch("/orgx/api/mission-control/auto-continue/start",{method:"POST",headers:Be({authToken:r,embedMode:o,contentTypeJson:!0}),body:JSON.stringify(m)}),c=await u.json().catch(()=>null);if(!u.ok){const v=et(c);if(v)throw v;const M=typeof(c==null?void 0:c.error)=="string"&&c.error||typeof(c==null?void 0:c.message)=="string"&&c.message||`Failed to start auto-continue (${u.status})`;throw new Error(M)}if(c&&typeof c=="object"&&"run"in c){const v=w.data??null;return{ok:!0,initiativeId:t,run:c.run??null,defaults:(v==null?void 0:v.defaults)??{tokenBudget:null,tickMs:0}}}return c},onSuccess:()=>{$()}}),te=Ee({mutationFn:async()=>{if(y){const c=w.data??null;return{ok:!0,initiativeId:t,run:null,defaults:(c==null?void 0:c.defaults)??{tokenBudget:null,tickMs:0}}}const x={};t&&(x.initiativeId=t);const m=await fetch("/orgx/api/mission-control/auto-continue/stop",{method:"POST",headers:Be({authToken:r,embedMode:o,contentTypeJson:!0}),body:JSON.stringify(x)}),u=await m.json().catch(()=>null);if(!m.ok){const c=typeof(u==null?void 0:u.error)=="string"&&u.error||typeof(u==null?void 0:u.message)=="string"&&u.message||`Failed to stop auto-continue (${m.status})`;throw new Error(c)}if(u&&typeof u=="object"&&"run"in u){const c=w.data??null;return{ok:!0,initiativeId:t,run:u.run??null,defaults:(c==null?void 0:c.defaults)??{tokenBudget:null,tickMs:0}}}return u},onSuccess:()=>{$()}}),Z=Ee({mutationFn:async x=>{var v;if(y)return{ok:!0,dispatched:((v=x.workstreamIds)==null?void 0:v.length)??1};const m={initiativeId:x.initiativeId};x.workstreamIds&&x.workstreamIds.length>0&&(m.workstreamIds=x.workstreamIds),x.agentId&&(m.agentId=x.agentId),x.scope&&(m.scope=x.scope),m.ignoreSpawnGuardRateLimit=!0;const u=await fetch("/orgx/api/mission-control/next-up/launch",{method:"POST",headers:Be({authToken:r,embedMode:o,contentTypeJson:!0}),body:JSON.stringify(m)}),c=await u.json().catch(()=>null);if(!u.ok){const M=et(c);if(M)throw M;const f=typeof(c==null?void 0:c.error)=="string"&&c.error||typeof(c==null?void 0:c.message)=="string"&&c.message||`Failed to launch (${u.status})`;throw new Error(f)}return c??{ok:!0,dispatched:0}},onSuccess:()=>{$()}}),N=((R=w.data)==null?void 0:R.run)??null,P=(N==null?void 0:N.status)==="running"||(N==null?void 0:N.status)==="stopping";return{status:w.data??null,run:N,isRunning:P,isLoading:w.isLoading,error:((A=w.data)==null?void 0:A.error)??((oe=w.error)==null?void 0:oe.message)??null,start:T.mutateAsync,stop:te.mutateAsync,launchSingle:Z.mutateAsync,isStarting:T.isPending,isStopping:te.isPending,isLaunching:Z.isPending,refetch:w.refetch}}async function it(t,r){var y;const s=await(await fetch(t,r)).json().catch(()=>null),g=((y=s==null?void 0:s.data)==null?void 0:y.url)??(s==null?void 0:s.url)??null;if(typeof g=="string"&&g.trim())return g.trim();throw new Error((s==null?void 0:s.error)??"Billing link unavailable")}async function Qt(t){var g;const r=((g=t==null?void 0:t.actions)==null?void 0:g.checkout)??"/orgx/api/billing/checkout",o=((t==null?void 0:t.requiredPlan)??"starter").trim().toLowerCase()||"starter",s=await it(r,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({planId:o})});window.open(s,"_blank","noopener,noreferrer")}async function Ut(t){var s;const r=((s=t==null?void 0:t.actions)==null?void 0:s.portal)??"/orgx/api/billing/portal",o=await it(r,{method:"POST"});window.open(o,"_blank","noopener,noreferrer")}function Wt(t){return t==="success"?"border-emerald-400/30 bg-[#0A1210]/95 text-emerald-100":t==="warning"?"border-amber-300/30 bg-[#12100A]/95 text-amber-100":t==="error"?"border-red-400/32 bg-[#120A0A]/95 text-red-100":t==="info"?"border-cyan-300/28 bg-[#0A1012]/95 text-cyan-100":"border-strong bg-[#0B0F16]/95 text-primary"}function Dt({open:t,tone:r="neutral",title:o,message:s=null,className:g,primaryAction:y=null,secondaryAction:j=null,onDismiss:w=null,autoDismissMs:$=null}){return h.useEffect(()=>{if(!t||!w||!$)return;const T=window.setTimeout(()=>w(),$);return()=>window.clearTimeout(T)},[$,w,t,o,s]),e.jsx(Pe,{initial:!1,children:t?e.jsx(ce.div,{initial:{opacity:0,y:-8,scale:.985},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-8,scale:.985},transition:{duration:.2,ease:[.22,1,.36,1]},className:`pointer-events-none ${g??""}`,children:e.jsxs("div",{className:`pointer-events-none min-w-[220px] max-w-[420px] rounded-xl border px-3 py-2 shadow-[0_16px_36px_rgba(0,0,0,0.42)] backdrop-blur ${Wt(r)}`,children:[e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-caption font-semibold",children:o}),s?e.jsx("p",{className:"mt-0.5 text-caption opacity-85",children:s}):null]}),w?e.jsx("button",{type:"button",onClick:w,className:"pointer-events-auto inline-flex h-6 w-6 items-center justify-center rounded-md text-current/70 transition-colors hover:bg-white/[0.08] hover:text-current","aria-label":"Dismiss toast",title:"Dismiss",children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"m6 6 12 12"})]})}):null]}),y||j?e.jsxs("div",{className:"mt-2 flex items-center gap-1.5",children:[j?e.jsx("button",{type:"button",onClick:j.onClick,className:"pointer-events-auto h-7 rounded-md border border-strong bg-white/[0.06] px-2.5 text-micro font-semibold text-current transition-colors hover:bg-white/[0.12]",children:j.label}):null,y?e.jsx("button",{type:"button",onClick:y.onClick,className:"pointer-events-auto h-7 rounded-md border border-white/25 bg-white/[0.14] px-2.5 text-micro font-semibold text-current transition-colors hover:bg-white/[0.2]",children:y.label}):null]}):null]})}):null})}function Ae({className:t=""}){return e.jsx("svg",{viewBox:"0 0 20 20",fill:"none","aria-hidden":!0,className:t,children:e.jsx("path",{d:"M7 5.4v9.2c0 .7.75 1.15 1.38.83l7.6-4.6a.95.95 0 0 0 0-1.62l-7.6-4.64A.95.95 0 0 0 7 5.4Z",fill:"currentColor"})})}function Vt({className:t=""}){return e.jsx("svg",{viewBox:"0 0 20 20",fill:"none","aria-hidden":!0,className:t,children:e.jsx("path",{d:"M6.1 13.25C4.25 13.25 2.8 11.8 2.8 10s1.45-3.25 3.3-3.25c3.15 0 4.35 6.5 8.05 6.5 1.85 0 3.3-1.45 3.3-3.25s-1.45-3.25-3.3-3.25c-3.7 0-4.9 6.5-8.05 6.5Z",stroke:"currentColor",strokeWidth:"2.1",strokeLinecap:"round",strokeLinejoin:"round"})})}function Ht({className:t=""}){return e.jsxs("svg",{viewBox:"0 0 20 20",fill:"none","aria-hidden":!0,className:t,children:[e.jsx("path",{d:"M6.2 9.4V6.7c0-.7.5-1.2 1.1-1.2s1.1.5 1.1 1.2v2.2",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"}),e.jsx("path",{d:"M8.4 8.9V5.8c0-.7.5-1.3 1.1-1.3s1.1.6 1.1 1.3v3",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"}),e.jsx("path",{d:"M10.6 8.9V6.2c0-.7.5-1.3 1.1-1.3s1.1.6 1.1 1.3v3.2",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"}),e.jsx("path",{d:"M12.8 9.6V7.2c0-.7.5-1.2 1.1-1.2s1.1.5 1.1 1.2v4.2c0 2.7-1.9 4.6-4.6 4.6H9.2c-2.1 0-3.7-1-4.6-2.8l-.9-1.7c-.3-.6 0-1.4.6-1.7.6-.3 1.3 0 1.6.6l.7 1.4",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"})]})}function Jt({className:t=""}){return e.jsxs("svg",{viewBox:"0 0 20 20",fill:"none","aria-hidden":!0,className:t,children:[e.jsx("path",{d:"M6.4 9.2V7.4c0-.7.5-1.2 1.1-1.2s1.1.5 1.1 1.2v1.3",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"}),e.jsx("path",{d:"M8.6 8.9V7c0-.7.5-1.2 1.1-1.2s1.1.5 1.1 1.2v2",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"}),e.jsx("path",{d:"M10.8 9.2V7.3c0-.7.5-1.2 1.1-1.2s1.1.5 1.1 1.2v2.6",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"}),e.jsx("path",{d:"M13 9.8V8.2c0-.7.5-1.2 1.1-1.2s1.1.5 1.1 1.2v3.6c0 2.4-1.7 4-4.1 4H9.7c-2 0-3.4-.9-4.2-2.5l-.8-1.4c-.3-.6 0-1.3.5-1.6.6-.3 1.2-.1 1.6.5l.6 1",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"})]})}const Gt=[{value:"initiative",label:"Initiative"},{value:"workstream",label:"Workstream"},{value:"milestone",label:"Milestone"}];function Zt({value:t,onChange:r}){return e.jsx("div",{className:"flex gap-1 p-1 rounded-lg bg-white/5 border border-white/[0.08]",children:Gt.map(o=>e.jsx("button",{type:"button",onClick:()=>r(o.value),className:he("px-3 py-1 text-[11px] font-medium rounded-md transition-all duration-150",t===o.value?"bg-white/10 text-white shadow-[inset_0_0_8px_rgba(191,255,0,0.08)]":"text-white/50 hover:text-white/70"),children:o.label},o.value))})}function at(t){return t==="running"?"from-teal-300/0 via-teal-300/60 to-teal-300/0":t==="blocked"?"from-amber-300/0 via-amber-300/55 to-amber-300/0":t==="idle"?"from-white/0 via-white/35 to-white/0":"from-[#BFFF00]/0 via-[#BFFF00]/70 to-[#BFFF00]/0"}function _e(t){return t==="running"?"Current":t==="blocked"?"Blocked on":"Next"}function ze(t){const r=typeof t.sliceTaskCount=="number"&&Number.isFinite(t.sliceTaskCount)?Math.max(0,Math.floor(t.sliceTaskCount)):null,o=t.sliceScope==="task"?"task":t.sliceScope==="milestone"?"milestone slice":"workstream slice",s=r&&r>0?`${r} ${r===1?"task":"tasks"}`:null;return t.queueState==="running"?s?`Executing ${s} in ${o}.`:"Execution in progress. Task detail will appear as the scheduler advances.":t.queueState==="blocked"?t.blockReason?"Blocked while waiting for dependency resolution.":"Blocked. Waiting for dependency or review.":t.queueState==="queued"?s?`Queued with ${s} in ${o}.`:"Queued at workstream scope. Task detail will populate after dispatch.":t.queueState==="completed"?"Completed. No queued tasks remain.":"Idle. Ready to dispatch when started."}function lt(t){const r=typeof t.initiativePriority=="string"?t.initiativePriority.trim().toLowerCase():"",o=typeof t.initiativePriorityNum=="number"&&Number.isFinite(t.initiativePriorityNum)?Math.max(1,Math.min(100,Math.round(t.initiativePriorityNum))):null,s=r==="urgent"||r==="high"||r==="medium"||r==="low"?r:o!==null?o<=12?"urgent":o<=30?"high":o<=60?"medium":"low":null;if(!s)return null;const g=s==="urgent"?"P1":s==="high"?"P2":s==="medium"?"P3":"P4",y=s==="urgent"?"Urgent":s==="high"?"High":s==="medium"?"Medium":"Low",j=s==="urgent"?"border-red-300/35 bg-red-500/[0.14] text-red-100":s==="high"?"border-amber-300/35 bg-amber-500/[0.14] text-amber-100":s==="medium"?"border-[#BFFF00]/35 bg-[#BFFF00]/14 text-[#E1FFB2]":"border-white/[0.2] bg-white/[0.08] text-white/70";return{shortLabel:`${g} ${y}`,longLabel:`Initiative priority ${y} (${g})`,toneClass:j}}function Xt(t){const r=t.trim().toLowerCase();if(r.includes("timed out")||r.includes("timeout")||r.includes("request cancelled")||r.includes("signal is aborted"))return"Next Up is still syncing. Keep this panel open and it will repopulate automatically.";if(r.includes("unauthorized")||r.includes("forbidden")||r.includes("api key")||r.includes("auth"))return"Next Up is unavailable until OrgX authentication is reconnected in Settings.";if(r.includes("unknown api endpoint")||r.includes("route is unavailable"))return"This runtime is missing queue routes. Restart and update the plugin build.";const o=t.split("|").map(s=>s.trim()).filter(Boolean).map(s=>s.replace(/^[^:]+:\s*/,"").trim()).filter(Boolean).slice(0,2).join(" ");return Ke(o||t)||"Next Up is temporarily unavailable."}function Ot(t){const r=t.trim().toLowerCase();return r.includes("timed out")||r.includes("timeout")||r.includes("request cancelled")||r.includes("signal is aborted")?"Signal is delayed right now. Queue data will appear as soon as sync catches up.":r.includes("fallback")?"Showing fallback queue data while full signal refreshes.":r.includes("unknown api endpoint")||r.includes("route is unavailable")?"Some queue controls are unavailable in this plugin build. Update and restart to restore full controls.":Ke(t.trim())}function Le(t,r,o){const s=typeof t=="string"?t.trim():"";if(s&&!nt(s))return se(s);const g=typeof r=="string"?r.trim():"";return g?nt(g)?`${o} ${Tt(g)}`:se(g):o}function ct(t){const r=typeof t.runnerAgentName=="string"?t.runnerAgentName.trim():"";if(!r)return"Unassigned";const o=r.toLowerCase();return o==="undefined"||o==="null"||o==="main"&&(t.runnerAgentId==="unassigned"||t.runnerSource==="fallback")?"Unassigned":r}function ut(t){return t.runnerSource==="inferred"?"inferred":null}function dt(t,r){const o=t.runnerSource==="assigned"?"assigned":t.runnerSource==="inferred"?"inferred":"fallback";return r==="Unassigned"?`Runner ${o}`:`${r} · ${o}`}function re(t,r){return!t||t.trim().length===0?r:Ke(t.trim())||r}function rt(t){return!t||typeof t!="object"||Array.isArray(t)?null:t}function mt(t,r){const o=se(t.workstreamTitle),s=rt(r),g=s&&typeof s.dispatchMode=="string"?s.dispatchMode:null,y=rt(s==null?void 0:s.run);return(y&&typeof y.stopReason=="string"?y.stopReason:y&&typeof y.stop_reason=="string"?y.stop_reason:null)==="budget_exhausted"?`Dispatch acknowledged for ${o}, but autopilot stopped: budget exhausted.`:g==="pending"?`Dispatching ${o}; waiting for slice start…`:g==="fallback"?`Dispatched ${o} using fallback runner.`:`Dispatched ${o}.`}function pt({className:t=""}){return e.jsxs("svg",{viewBox:"0 0 20 20",fill:"none","aria-hidden":!0,className:t,children:[e.jsx("circle",{cx:"4.5",cy:"10",r:"1.4",fill:"currentColor"}),e.jsx("circle",{cx:"10",cy:"10",r:"1.4",fill:"currentColor"}),e.jsx("circle",{cx:"15.5",cy:"10",r:"1.4",fill:"currentColor"})]})}function Yt({compact:t}){const r=t?3:6;return e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs("div",{className:"flex items-center gap-2 px-1 pt-1 text-micro uppercase tracking-[0.12em] text-muted",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-[#BFFF00]/70 status-breathe"}),e.jsx("span",{children:"Calibrating queue"})]}),Array.from({length:r}).map((o,s)=>e.jsxs("div",{className:"nextup-skeleton-card rounded-2xl border border-white/[0.08] bg-white/[0.02] px-3 py-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2.5",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-start gap-2.5",children:[e.jsx(G,{className:"h-8 w-8 rounded-full"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx(G,{className:"h-3 w-40 rounded-md"}),e.jsx(G,{className:"mt-2 h-4 w-56 rounded-md"})]})]}),e.jsx(G,{className:"h-5 w-16 rounded-full"})]}),e.jsxs("div",{className:"mt-3 rounded-lg border border-white/[0.07] bg-black/[0.18] px-2.5 py-2",children:[e.jsx(G,{className:"h-3 w-14 rounded"}),e.jsx(G,{className:"mt-2 h-3 w-full rounded"}),e.jsx(G,{className:"mt-2 h-3 w-3/5 rounded"})]}),e.jsxs("div",{className:"mt-2.5 flex flex-wrap gap-1.5",children:[e.jsx(G,{className:"h-8 w-24 rounded-full"}),e.jsx(G,{className:"h-8 w-20 rounded-full"}),e.jsx(G,{className:"h-8 w-24 rounded-full"})]})]},`nextup-skeleton-${s}`))]})}function en({initiativeId:t=null,projectId:r=null,authToken:o=null,embedMode:s=!1,title:g="Next Up",showHeader:y=!0,compact:j=!1,className:w,disableEnterAnimation:$=!1,allowCompactToggle:T=!1,onToggleCompact:te,onOpenInitiative:Z,onOpenSettings:N,onUpgradeGate:P,onOpenSliceDetail:R,selectionEnabled:A=!0,panelStyle:oe="card",showQueueSettings:x=!0,queueModel:m,queueActions:u,snapshotVersion:c=null}){var Ye;const[v,M]=h.useState(j);h.useEffect(()=>M(j),[j]);const f=T&&!te?v:j,fe=n=>{te?te(n):M(n)},[K,C]=h.useState(null),[S,be]=h.useState("workstream"),[Q,U]=h.useState(null),ge="bottom",[I,ne]=h.useState(null),[X,ie]=h.useState(null),[W,D]=h.useState(null),[b,ue]=h.useState(new Set),[Se,de]=h.useState(null),[ye,we]=h.useState(!1),[xt,Ce]=h.useState(!1),Qe=h.useRef(null),ht=Rt({initiativeId:t,projectId:r,authToken:o,embedMode:s,enabled:!m,snapshotVersion:c,zoomLevel:S}),ft=m??ht,{items:me,degraded:ae,isLoading:O,isFetching:Ue,error:Ie,refetch:bt,playWorkstream:We,startWorkstreamAutoContinue:De,initiativeGroups:nn,milestoneGroups:rn}=ft,$e=Kt({initiativeId:t,authToken:o,embedMode:s,enabled:!!t}),gt=Mt({authToken:o,embedMode:s}),Y=u??gt,V=n=>`${n.initiativeId}:${n.workstreamId}`,ke=h.useMemo(()=>me.filter(n=>n.queueState==="running").length,[me]),H=h.useMemo(()=>{const n=me.filter(i=>i.queueState!=="running");return n.length>0?n:me},[me]),Ve=h.useMemo(()=>H.length===0?"empty":H.some(n=>n.queueState!=="running"&&n.queueState!=="blocked")?"queued":H.some(n=>n.queueState==="blocked")?"blocked":H.some(n=>n.queueState==="running")?"running":"queued",[H]),F=h.useMemo(()=>f?H.slice(0,5):H,[f,H]),yt=h.useMemo(()=>F.filter(n=>b.has(V(n))),[b,F]),[pe,J]=h.useState([]),ee=h.useRef([]),He=h.useMemo(()=>{const n=new Map;for(const i of F)n.set(V(i),i);return n},[F]),B=h.useMemo(()=>F.map(V),[F]),wt=h.useMemo(()=>B.join("|"),[B]);h.useEffect(()=>{J(n=>{if(f)return[];const i=[],a=new Set(B);for(const l of n)a.has(l)&&i.push(l);for(const l of B)i.includes(l)||i.push(l);return i})},[f,wt]),h.useEffect(()=>{ee.current=pe},[pe]),h.useEffect(()=>{Se&&(B.includes(Se)||de(null))},[Se,B]),h.useEffect(()=>{ue(n=>{if(n.size===0)return n;const i=new Set(F.map(V)),a=new Set;for(const l of n)i.has(l)&&a.add(l);return a.size===n.size?n:a})},[F]),h.useEffect(()=>{if(!W)return;F.some(i=>V(i)===W)||D(null)},[W,F]),h.useEffect(()=>{if(!Q)return;const n=window.setTimeout(()=>U(null),4e3);return()=>window.clearTimeout(n)},[Q]),h.useEffect(()=>{if(ae.length===0){Ce(!1);return}Ce(!1)},[ae]),h.useEffect(()=>{A&&!f&&b.size>0&&we(!1)},[f,b.size,A]),h.useEffect(()=>{if(!ye)return;const n=a=>{var p;const l=a.target;l&&((p=Qe.current)!=null&&p.contains(l)||we(!1))},i=a=>{a.key==="Escape"&&we(!1)};return document.addEventListener("mousedown",n),document.addEventListener("touchstart",n),document.addEventListener("keydown",i),()=>{document.removeEventListener("mousedown",n),document.removeEventListener("touchstart",n),document.removeEventListener("keydown",i)}},[ye]);const Je=async n=>{const i=V(n),a=se(n.workstreamTitle),l=ee.current.slice();Ge(new Set([i]));try{await Y.remove({initiativeId:n.initiativeId,workstreamId:n.workstreamId}),ue(p=>{if(!p.has(i))return p;const d=new Set(p);return d.delete(i),d}),de(p=>p===i?null:p),C(`Removed ${a} from queue.`)}catch(p){f||J(l);const d=p instanceof Error?p.message:"";C(re(d,"Failed to remove from queue"))}},kt=(n,i,a)=>{const l=f?B:pe.length>0?pe:B;ue(p=>{const d=new Set(p),k=Se;if(a&&k&&l.includes(k)){const E=l.indexOf(n),_=l.indexOf(k);if(E>=0&&_>=0){const[z,Fe]=E<_?[E,_]:[_,E];for(const je of l.slice(z,Fe+1))i?d.add(je):d.delete(je)}else i?d.add(n):d.delete(n)}else i?d.add(n):d.delete(n);return d}),de(n)},vt=()=>{ue(new Set(B)),de(B.length>0?B[B.length-1]:null)},jt=()=>{ue(new Set),de(null)},xe=(n,i)=>{n.size!==0&&J(a=>{const l=a.length>0?a:B,p=[],d=[];for(const k of l)n.has(k)?p.push(k):d.push(k);return p.length===0?a:i==="top"?[...p,...d]:[...d,...p]})},Ge=n=>{n.size!==0&&J(i=>i.filter(a=>!n.has(a)))},Re=async n=>{if(b.size===0){C("Select one or more queue items first.");return}const i=F.map(p=>({key:V(p),item:p})).filter(p=>b.has(p.key));if(i.length===0){C("Selected queue items are no longer visible.");return}const a=new Set(i.map(({key:p})=>p)),l=ee.current.slice();n==="move_top"?xe(a,"top"):n==="move_bottom"?xe(a,"bottom"):n==="remove"&&Ge(a),ie(`bulk:${n}`),C(null);try{const p=i.map(({item:z})=>({initiativeId:z.initiativeId,workstreamId:z.workstreamId})),d=await Y.bulk({action:n,items:p}),k=typeof(d==null?void 0:d.updated)=="number"?d.updated??0:0,L=typeof(d==null?void 0:d.failed)=="number"?d.failed??0:0,E=Array.isArray(d==null?void 0:d.errors)?d.errors.filter(z=>typeof z=="string").map(z=>z.trim()).filter(Boolean):[],_=n==="remove"?"removed":n==="move_top"?"moved to top":"moved to bottom";k===0&&L>0&&E.length>0?C(re(E[0],`${L} queue action${L===1?"":"s"} failed.`)):C(L>0?`${k} item${k===1?"":"s"} ${_}; ${L} failed.`:`${k} item${k===1?"":"s"} ${_}.`),ue(new Set),de(null)}catch(p){f||J(l);const d=p instanceof Error?p.message:"";C(re(d,"Bulk queue action failed"))}finally{ie(null)}},Nt=async()=>{const n=ee.current.map(i=>He.get(i)).filter(Boolean).map(i=>({initiativeId:i.initiativeId,workstreamId:i.workstreamId}));n.length!==0&&await Y.reorder({order:n})},ve=async(n,i,a,l)=>{var p,d;C(null),ne(null),P==null||P(null),(p=l==null?void 0:l.optimistic)==null||p.call(l),ie(n);try{const k=await i();C(typeof a=="function"?a(k):a)}catch(k){if((d=l==null?void 0:l.rollback)==null||d.call(l),k instanceof Pt)ne(k),P==null||P(k);else{const L=k instanceof Error?k.message:"";C(re(L,"Action failed"))}}finally{ie(null)}},St=async()=>{if(t){U("Dispatching...");try{const n=me.filter(l=>l.queueState!=="running"&&l.queueState!=="completed").map(l=>l.workstreamId),i=await $e.launchSingle({initiativeId:t,workstreamIds:n.length>0?n:void 0}),a=(i==null?void 0:i.dispatched)??n.length;U(`${a} workstream${a===1?"":"s"} dispatched`)}catch(n){const i=n instanceof Error?n.message:"";U(re(i,"Launch failed"))}}},Ct=async()=>{if(t){U("Enabling autopilot...");try{await $e.start({}),U("Autopilot enabled")}catch(n){const i=n instanceof Error?n.message:"";U(re(i,"Autopilot failed"))}}},qe=I?"upgrade":Ie?"error":K?"notice":null,Ze=Ie?Xt(Ie):null,Me=ae.length>0?Ot(ae[0]):null,It=qe!==null,$t=ae.length>0&&!xt&&W===null&&!ye,le=yt.length,Xe=A&&!f&&le>0,qt=ke>0?`No queued workstreams yet. ${ke} running item${ke===1?"":"s"} still in-flight.`:ae.length>0?"Queue signal is delayed right now.":"No queued workstreams right now.",Oe=e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:vt,className:"control-pill h-8 px-2.5 text-caption font-semibold",children:"Select all"}),e.jsx("button",{type:"button",onClick:jt,disabled:b.size===0,className:"control-pill h-8 px-2.5 text-caption font-semibold disabled:opacity-45",children:"Clear"}),e.jsx("button",{type:"button",disabled:le===0||X==="bulk:move_top",onClick:()=>void Re("move_top"),className:"control-pill h-8 px-2.5 text-caption font-semibold disabled:opacity-45",children:"Move top"}),e.jsx("button",{type:"button",disabled:le===0||X==="bulk:move_bottom",onClick:()=>void Re("move_bottom"),className:"control-pill h-8 px-2.5 text-caption font-semibold disabled:opacity-45",children:"Move bottom"}),e.jsx("button",{type:"button",disabled:le===0||X==="bulk:remove",onClick:()=>void Re("remove"),className:"control-pill h-8 px-2.5 text-caption font-semibold disabled:opacity-45",children:"Remove"})]});return e.jsxs(Et,{surface:oe==="card",className:`flex h-full min-h-0 flex-col overflow-hidden ${$?"":"card-enter"} ${oe==="flat"?"!rounded-none !border-none !bg-transparent !shadow-none":""} ${w??""}`,children:[y?e.jsxs("div",{className:"flex items-center justify-between gap-2 border-b border-subtle px-4 py-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("h2",{className:"truncate text-heading font-semibold text-white",children:g}),e.jsx("span",{className:"chip inline-flex min-w-[52px] justify-center text-micro tabular-nums",children:O?e.jsx("span",{"aria-hidden":!0,className:"h-2.5 w-5 rounded bg-white/15 animate-pulse"}):H.length}),e.jsx("span",{className:he("chip inline-flex min-w-[148px] justify-center text-micro tabular-nums transition-opacity",!O&&ke>0?"text-secondary opacity-100":"pointer-events-none opacity-0"),children:`${ke} active elsewhere`}),e.jsx("span",{className:he("inline-flex min-w-[92px] justify-end text-micro text-muted transition-opacity",Ue&&!O?"opacity-100":"opacity-0"),"aria-live":"polite",children:"refreshing…"})]}),e.jsx("div",{className:"flex items-center gap-1.5",children:T?e.jsx("button",{type:"button",onClick:()=>fe(!f),className:"control-pill h-8 flex-shrink-0 whitespace-nowrap px-3 text-caption font-semibold",title:f?"Switch to expanded cards":"Switch to compact list","aria-label":f?"Expand Next Up queue":"Compact Next Up queue",children:f?"Expand":"Compact"}):null})]}):null,e.jsxs("div",{className:"flex items-center justify-between gap-2 border-b border-subtle px-3 py-2",children:[e.jsx(Zt,{value:S,onChange:be}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("button",{type:"button",disabled:$e.isLaunching||!t,onClick:()=>void St(),className:"border border-[#BFFF00]/30 text-[#BFFF00] hover:bg-[#BFFF00]/10 px-3 py-1.5 rounded-lg text-[11px] font-medium flex items-center gap-1.5 disabled:opacity-40 transition-colors",title:"Launch queued workstreams",children:[e.jsx(Ae,{className:"h-3 w-3"}),e.jsx("span",{children:"Launch"})]}),e.jsxs("button",{type:"button",disabled:$e.isStarting||!t,onClick:()=>void Ct(),className:"border border-[#14B8A6]/30 text-[#14B8A6] hover:bg-[#14B8A6]/10 px-3 py-1.5 rounded-lg text-[11px] font-medium flex items-center gap-1.5 disabled:opacity-40 transition-colors",title:"Enable autopilot for this initiative",children:[e.jsx(Vt,{className:"h-3 w-3"}),e.jsx("span",{children:"Autopilot"})]})]})]}),Q&&e.jsx("div",{className:"px-3 pt-1.5",children:e.jsx(ce.div,{initial:{opacity:0,y:-4},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},transition:{duration:.18},className:"rounded-lg border border-[#BFFF00]/20 bg-[#BFFF00]/[0.06] px-2.5 py-1.5 text-[11px] text-[#E1FFB2]",children:Q})}),It&&e.jsx("div",{className:"px-3 pt-2",children:e.jsx(Pe,{initial:!1,mode:"wait",children:qe==="upgrade"&&I?e.jsx(ce.div,{initial:{opacity:0,y:-4,scale:.99},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-4,scale:.99},transition:{duration:.18,ease:[.22,1,.36,1]},className:"rounded-xl border border-amber-200/25 bg-amber-200/10 px-3 py-2 text-caption text-amber-100",children:e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"rounded-full border border-amber-200/25 bg-amber-200/10 px-2 py-0.5 text-micro font-semibold uppercase tracking-[0.08em] text-amber-100/90",children:"Upgrade required"}),e.jsxs("span",{className:"truncate text-micro text-secondary",children:[tt(I.currentPlan)," →"," ",tt(I.requiredPlan)]})]}),e.jsx("div",{className:"mt-1 line-clamp-2 text-caption leading-snug text-amber-50/90",title:I.message,children:I.message}),K?e.jsx("div",{className:"mt-1 text-micro text-rose-50/85",children:K}):null]}),e.jsxs("div",{className:"flex flex-shrink-0 flex-col items-end gap-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>void Qt({actions:I.actions,requiredPlan:I.requiredPlan}).catch(n=>C(re(n instanceof Error?n.message:"","Checkout failed"))),className:"h-7 rounded-full border border-amber-200/25 bg-amber-200/15 px-3 text-micro font-semibold text-amber-50 transition-colors hover:bg-amber-200/20",children:"Upgrade"}),e.jsx("button",{type:"button",onClick:()=>void Ut({actions:I.actions}).catch(n=>C(re(n instanceof Error?n.message:"","Portal failed"))),className:"h-7 rounded-full border border-strong bg-white/[0.04] px-3 text-micro font-semibold text-primary transition-colors hover:bg-white/[0.08]",children:"Billing"}),N&&e.jsx("button",{type:"button",onClick:N,className:"h-7 rounded-full border border-strong bg-white/[0.04] px-2.5 text-micro font-semibold text-primary transition-colors hover:bg-white/[0.08]",children:"Settings"})]}),(Ye=I.actions)!=null&&Ye.pricing?e.jsx("a",{href:I.actions.pricing,target:"_blank",rel:"noopener noreferrer",className:"text-micro text-secondary underline decoration-white/20 hover:text-primary",children:"View pricing"}):null]})]})},"upgrade"):qe==="error"&&Ze?e.jsx(ce.div,{initial:{opacity:0,y:-4},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},transition:{duration:.18},className:"rounded-xl border border-red-400/25 bg-red-500/[0.08] px-3 py-2 text-caption text-red-100",children:Ze},"error"):qe==="notice"&&K?e.jsx(ce.div,{initial:{opacity:0,y:-4},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},transition:{duration:.18},className:"rounded-xl border border-white/[0.1] bg-white/[0.03] px-3 py-2 text-caption text-primary",children:K},"notice"):null})}),e.jsxs("div",{className:`flex-1 space-y-2.5 overflow-y-auto overscroll-y-contain px-3 pb-3 ${y?"pt-1":"pt-2.5"}`,children:[!O&&H.length>0?e.jsxs("div",{className:"flex flex-col gap-2.5 px-0.5 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-micro uppercase tracking-[0.08em] text-muted",children:Ve==="blocked"?"Needs attention":Ve==="running"?"Running now":"Queue"}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-1.5",children:[le>0?e.jsxs("span",{className:"chip text-micro",children:[le," selected"]}):null,e.jsx("span",{className:he("inline-flex min-w-[92px] text-micro text-muted transition-opacity",Ue&&!O?"opacity-100":"opacity-0"),"aria-live":"polite",children:"refreshing…"}),A&&!f&&le===0?e.jsx("span",{className:"text-micro text-muted",children:"Shift+select to pick ranges."}):null]})]}),e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-1.5 sm:justify-end",children:[T?e.jsx("button",{type:"button",onClick:()=>fe(!f),className:"control-pill h-8 px-2.5 text-caption font-semibold",title:f?"Switch to expanded cards":"Switch to compact list","aria-label":f?"Expand Next Up queue":"Compact Next Up queue",children:f?"Expand":"Compact"}):null,Xe?e.jsx("div",{className:"flex flex-wrap justify-end gap-1.5",children:Oe}):null,!Xe&&x?e.jsxs("div",{ref:Qe,className:"relative",children:[e.jsxs("button",{type:"button",onClick:()=>we(n=>!n),className:"control-pill h-8 px-2.5 text-caption font-semibold","aria-haspopup":"menu","aria-expanded":ye,title:"Queue settings",children:[e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"opacity-85","aria-hidden":!0,children:[e.jsx("path",{d:"M4 6h16"}),e.jsx("path",{d:"M7 12h10"}),e.jsx("path",{d:"M10 18h4"})]}),e.jsx("span",{children:"Queue"})]}),ye?e.jsx("div",{className:"surface-tier-2 absolute right-0 top-[calc(100%+8px)] z-[280] w-[320px] max-w-[86vw] rounded-xl p-3 shadow-[0_18px_42px_rgba(0,0,0,0.46)] backdrop-blur-xl",children:e.jsxs("div",{className:"space-y-2.5",children:[A&&!f?e.jsxs("div",{children:[e.jsx("p",{className:"section-kicker",children:"Bulk actions"}),e.jsx("div",{className:"mt-1.5 flex flex-wrap items-center gap-1.5",children:Oe})]}):null,N?e.jsx("button",{type:"button",onClick:()=>{we(!1),N()},className:"control-pill h-7 px-2.5 text-micro font-semibold",children:"Open settings"}):null]})}):null]}):null]})]}):null,O?e.jsx(Yt,{compact:f}):null,!O&&F.length===0&&!Ie&&e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.02] px-3 py-4 text-center",children:[e.jsx("p",{className:"text-body text-secondary",children:qt}),Me?e.jsx("p",{className:"mt-1 text-micro text-muted",children:Me}):null,ae.length>0?e.jsx("div",{className:"mt-2.5 flex items-center justify-center gap-1.5",children:e.jsx("button",{type:"button",onClick:()=>{Ce(!1),bt()},className:"control-pill h-7 px-2.5 text-micro font-semibold",children:"Retry now"})}):null]}),!O&&f?e.jsx(Pe,{initial:!1,children:F.map((n,i)=>{const a=V(n),l=X===a,p=n.queueState==="running",d=n.nextTaskDueAt?st(n.nextTaskDueAt):null,k=Le(n.initiativeTitle,n.initiativeId,"Initiative"),L=Le(n.workstreamTitle,n.workstreamId,"Workstream"),E=lt(n),_=n.nextTaskTitle?se(n.nextTaskTitle):null,z=n.blockReason?se(n.blockReason):null,Fe=ct(n),je=ut(n);return e.jsxs(ce.article,{layout:!0,initial:{opacity:0,y:6,scale:.99},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-4,scale:.99},transition:{duration:.22,delay:Math.min(i,7)*.018,ease:[.22,1,.36,1]},className:"group relative overflow-visible rounded-2xl border border-white/[0.08] bg-white/[0.02] px-2.5 py-2 cursor-pointer transition-colors hover:border-white/[0.14]",onClick:()=>R==null?void 0:R(n),role:"button",tabIndex:0,onKeyDown:q=>{(q.key==="Enter"||q.key===" ")&&(q.preventDefault(),R==null||R(n))},children:[e.jsx("div",{className:`pointer-events-none absolute inset-x-2.5 top-0 h-px bg-gradient-to-r ${at(n.queueState)}`,"aria-hidden":!0}),e.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[e.jsx(ot,{name:Fe,hint:dt(n,Fe),size:"xs"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[e.jsx(Ne,{type:"initiative",size:11,className:"flex-shrink-0 opacity-85"}),e.jsx("button",{type:"button",onClick:()=>Z==null?void 0:Z(n.initiativeId,n.initiativeTitle),className:"block min-w-0 flex-1 truncate text-left text-micro uppercase tracking-[0.08em] text-muted transition-colors hover:text-white/72",title:k,children:k}),E?e.jsx("span",{className:he("inline-flex flex-shrink-0 items-center rounded-full border px-2 py-0.5 text-[9px] font-semibold uppercase tracking-[0.08em]",E.toneClass),title:E.longLabel,children:E.shortLabel}):null]}),e.jsxs("p",{className:"mt-0.5 flex min-w-0 items-center gap-1.5 text-caption font-semibold leading-snug text-white",title:L,children:[e.jsx(Ne,{type:"workstream",size:12,className:"flex-shrink-0 opacity-95"}),e.jsx("span",{className:"line-clamp-2",children:L})]}),_?e.jsxs("p",{className:"mt-0.5 line-clamp-2 text-micro leading-snug text-secondary",title:`${_e(n.queueState)}: ${_}${d?` · ${d}`:""}`,children:[_e(n.queueState),": ",_,d?` · ${d}`:""]}):e.jsx("p",{className:"mt-0.5 line-clamp-2 text-micro leading-snug text-secondary",title:ze(n),children:ze(n)}),je?e.jsxs("p",{className:"mt-0.5 text-micro text-muted",children:["Runner ",je]}):null]})]}),z&&e.jsxs("div",{className:"mt-1.5 rounded-lg border border-red-400/24 bg-red-500/[0.08] px-2.5 py-1 text-micro text-red-100/85",children:["Blocked: ",z]}),e.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5",onClick:q=>q.stopPropagation(),children:[e.jsx("button",{type:"button",disabled:l||p,onClick:()=>void ve(a,()=>We({initiativeId:n.initiativeId,workstreamId:n.workstreamId,agentId:n.runnerAgentId}),q=>mt(n,q)),className:"control-pill flex h-7 items-center justify-center px-2.5 text-micro font-semibold disabled:opacity-40",title:p?"Already running":"Start now",children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Ae,{className:"h-3 w-3 opacity-85"}),e.jsx("span",{children:p?"Running":"Start"})]})}),e.jsxs("div",{className:"relative ml-auto",children:[e.jsx("button",{type:"button",disabled:l,onClick:()=>D(q=>q===a?null:a),className:"control-pill flex h-7 items-center justify-center px-2.5 text-micro font-semibold disabled:opacity-40",title:"Queue actions",children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(pt,{className:"h-3 w-3 opacity-85"}),e.jsx("span",{children:"More"})]})}),W===a&&e.jsxs("div",{className:"absolute right-0 top-[calc(100%+6px)] z-[320] min-w-[178px] rounded-xl border border-white/[0.1] bg-[#080d14]/95 p-1.5 shadow-[0_16px_36px_rgba(0,0,0,0.42)] backdrop-blur",children:[e.jsx("button",{type:"button",onClick:()=>{D(null);const q=ee.current.slice();ve(`${a}:top`,()=>Y.move({initiativeId:n.initiativeId,workstreamId:n.workstreamId,placement:"top"}),`Moved ${L} to top of queue.`,{optimistic:()=>xe(new Set([a]),"top"),rollback:()=>J(q)})},className:"flex h-8 w-full items-center rounded-md px-2.5 text-left text-caption text-primary transition-colors hover:bg-white/[0.08]",children:"Move to top"}),e.jsx("button",{type:"button",onClick:()=>{D(null);const q=ee.current.slice();ve(`${a}:bottom`,()=>Y.move({initiativeId:n.initiativeId,workstreamId:n.workstreamId,placement:"bottom"}),`Moved ${L} to bottom of queue.`,{optimistic:()=>xe(new Set([a]),"bottom"),rollback:()=>J(q)})},className:"flex h-8 w-full items-center rounded-md px-2.5 text-left text-caption text-primary transition-colors hover:bg-white/[0.08]",children:"Move to bottom"}),e.jsx("button",{type:"button",onClick:()=>{D(null);const q=ee.current.slice();ve(`${a}:auto`,async()=>(await Y.move({initiativeId:n.initiativeId,workstreamId:n.workstreamId,placement:"top"}),De({initiativeId:n.initiativeId,workstreamId:n.workstreamId,agentId:n.runnerAgentId,scope:"initiative"})),`Start+Auto enabled for ${k}.`,{optimistic:()=>xe(new Set([a]),"top"),rollback:()=>J(q)})},className:"flex h-8 w-full items-center rounded-md px-2.5 text-left text-caption text-primary transition-colors hover:bg-white/[0.08]",children:"Start with auto"}),e.jsx("button",{type:"button",disabled:Y.isRemoving,onClick:()=>{D(null),Je(n)},className:"mt-1 flex h-8 w-full items-center rounded-md px-2.5 text-left text-caption text-red-100 transition-colors hover:bg-red-500/[0.12] disabled:opacity-45",children:"Remove from queue"})]})]})]})]},a)})}):O?null:e.jsx(At,{axis:"y",values:pe,onReorder:n=>{ee.current=n,J(n)},className:"space-y-2.5",children:pe.map(n=>He.get(n)).filter(Boolean).map((n,i)=>e.jsx(tn,{item:n,index:i,actionKey:X,setNotice:C,setUpgradeGate:ne,onUpgradeGate:P,onOpenInitiative:Z,onOpenSliceDetail:R,selected:b.has(V(n)),selectionEnabled:A,onToggleSelection:kt,menuKey:W,setMenuKey:D,playWorkstream:We,startWorkstreamAutoContinue:De,triagePlacement:ge,onPauseWorkstream:(a,l)=>Y.stopTriage({initiativeId:a.initiativeId,workstreamId:a.workstreamId,placement:l,resetToTodo:!1}),onMoveWorkstream:(a,l)=>Y.move({initiativeId:a.initiativeId,workstreamId:a.workstreamId,placement:l}),onApplyLocalPlacement:xe,onRestoreOrder:a=>J(a),captureOrder:()=>ee.current.slice(),onCommitReorder:()=>void Nt().catch(()=>null),onDismiss:Je,runAction:ve},V(n)))})]}),e.jsx("div",{className:"pointer-events-none absolute bottom-3 right-3 z-[250]",children:e.jsx(Dt,{open:$t,tone:"warning",title:"Limited signal",message:Me,autoDismissMs:6e3,onDismiss:()=>Ce(!0)})})]})}function tn({item:t,index:r,actionKey:o,setNotice:s,setUpgradeGate:g,onUpgradeGate:y,onOpenInitiative:j,onOpenSliceDetail:w,selected:$,selectionEnabled:T,onToggleSelection:te,menuKey:Z,setMenuKey:N,playWorkstream:P,startWorkstreamAutoContinue:R,triagePlacement:A,onPauseWorkstream:oe,onMoveWorkstream:x,onApplyLocalPlacement:m,onRestoreOrder:u,captureOrder:c,onCommitReorder:v,onDismiss:M,runAction:f}){const fe=_t(),[K,C]=h.useState(!1),S=`${t.initiativeId}:${t.workstreamId}`,be=o===S,Q=t.queueState==="running",U=t.nextTaskDueAt?st(t.nextTaskDueAt):null,ge=Le(t.initiativeTitle,t.initiativeId,"Initiative"),I=Le(t.workstreamTitle,t.workstreamId,"Workstream"),ne=lt(t),X=t.nextTaskTitle?se(t.nextTaskTitle):null,ie=t.blockReason?se(t.blockReason):null,W=ct(t),D=ut(t);return e.jsx(zt,{value:S,id:S,dragListener:!1,dragControls:fe,onDragStart:()=>C(!0),onDragEnd:()=>{C(!1),v()},whileDrag:{scale:1.02,boxShadow:"0 20px 48px rgba(0,0,0,0.5), 0 0 0 1px rgba(191,255,0,0.15)",zIndex:50,cursor:"grabbing"},className:"relative",children:e.jsxs(ce.article,{layout:!0,initial:{opacity:0,y:12,scale:.97},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-8,scale:.98},transition:{duration:.4,ease:[.25,.1,.25,1],delay:Math.min(r,7)*.05,opacity:{duration:.32,ease:[.25,.1,.25,1]}},className:"group relative overflow-visible rounded-2xl border border-white/[0.08] bg-white/[0.02] px-3 py-3 cursor-pointer transition-colors hover:border-white/[0.14]",onClick:()=>w==null?void 0:w(t),role:"button",tabIndex:0,onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),w==null||w(t))},children:[e.jsx("div",{className:`pointer-events-none absolute inset-x-3 top-0 h-px bg-gradient-to-r ${at(t.queueState)}`,"aria-hidden":!0}),e.jsx("div",{className:"flex items-start justify-between gap-2.5",children:e.jsxs("div",{className:"min-w-0 flex flex-1 items-start gap-2.5",children:[e.jsxs("div",{className:"relative h-8 w-8 flex-shrink-0",children:[e.jsx("div",{className:`absolute inset-0 transition-[opacity,transform] duration-200 ease-out ${T?$?"opacity-0 scale-90":"opacity-100 scale-100 group-hover:opacity-0 group-hover:scale-90 group-focus-within:opacity-0 group-focus-within:scale-90":"opacity-100 scale-100"}`,children:e.jsx(ot,{name:W,hint:dt(t,W),size:"sm"})}),T?e.jsx("button",{type:"button",role:"checkbox","aria-checked":$,"aria-label":"Select queue row",title:$?"Selected (Shift+click for range)":"Select (Shift+click for range)",onClick:b=>{b.stopPropagation(),te(S,!$,b.shiftKey)},onMouseDown:b=>b.stopPropagation(),onKeyDown:b=>b.stopPropagation(),className:`absolute inset-0 flex items-center justify-center rounded-full border transition-[opacity,transform,background-color,border-color,color] duration-200 ease-out ${$?"opacity-100 scale-100 border-[#BFFF00]/40 bg-[#BFFF00]/18 text-[#E1FFB2]":"opacity-0 scale-90 border-white/[0.24] bg-black/55 text-white/78 group-hover:opacity-100 group-hover:scale-100 group-focus-within:opacity-100 group-focus-within:scale-100 hover:bg-black/62"}`,children:e.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center rounded-full border border-current/45 bg-black/30",children:$?e.jsx("svg",{viewBox:"0 0 16 16",className:"h-2.5 w-2.5",fill:"none","aria-hidden":!0,children:e.jsx("path",{d:"M3.2 8.3 6.2 11l6.6-6.1",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}):null})}):null]}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[e.jsx(Ne,{type:"initiative",size:11,className:"flex-shrink-0 opacity-85"}),e.jsx("button",{type:"button",onClick:()=>j==null?void 0:j(t.initiativeId,t.initiativeTitle),className:"block min-w-0 flex-1 truncate text-left text-micro uppercase tracking-[0.08em] text-muted transition-colors hover:text-white/72",title:ge,children:ge}),ne?e.jsx("span",{className:he("inline-flex flex-shrink-0 items-center rounded-full border px-2 py-0.5 text-[9px] font-semibold uppercase tracking-[0.08em]",ne.toneClass),title:ne.longLabel,children:ne.shortLabel}):null]}),e.jsxs("div",{className:"mt-0.5 flex min-w-0 items-start gap-1.5",children:[e.jsx(Ne,{type:"workstream",size:12,className:"mt-[3px] flex-shrink-0 opacity-95"}),e.jsx("p",{className:"min-w-0 line-clamp-2 text-body font-semibold leading-snug text-white",title:I,children:I})]}),e.jsxs("div",{className:"mt-1.5 flex items-center gap-2 text-micro text-secondary",children:[e.jsx("span",{className:"rounded-full border border-strong bg-white/[0.03] px-2 py-0.5 text-micro uppercase tracking-[0.08em] text-secondary",children:"Runner"}),e.jsxs("span",{className:"truncate text-white/68",children:[W,D?` · ${D}`:""]})]})]})]})}),e.jsx("div",{className:"mt-2 rounded-lg border border-white/[0.07] bg-black/[0.18] px-2.5 py-2 text-caption text-white/68",children:X?e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1 text-micro uppercase tracking-[0.08em] text-white/44",children:[e.jsx(Ne,{type:"task",size:10,className:"flex-shrink-0 opacity-80"}),e.jsx("span",{children:_e(t.queueState)}),U?e.jsxs("span",{className:"truncate text-micro normal-case tracking-normal text-muted",children:["· ",U]}):null]}),e.jsx("p",{className:"line-clamp-2 break-words text-caption leading-snug text-white/84",title:X,children:X})]}):e.jsx("span",{className:"text-secondary",children:ze(t)})}),ie&&e.jsxs("div",{className:"mt-1.5 rounded-lg border border-red-400/24 bg-red-500/[0.08] px-2.5 py-1 text-micro text-red-100/85",children:["Blocked: ",ie]}),e.jsxs("div",{className:"mt-2 flex items-center gap-1.5",onClick:b=>b.stopPropagation(),children:[e.jsx("button",{type:"button",disabled:be||Q,onClick:()=>void f(S,()=>P({initiativeId:t.initiativeId,workstreamId:t.workstreamId,agentId:t.runnerAgentId}),b=>mt(t,b)),className:"control-pill flex h-7 items-center justify-center px-2.5 text-micro font-semibold disabled:opacity-40",title:Q?"Already running":"Start this workstream now",children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Ae,{className:"h-3 w-3 opacity-85"}),e.jsx("span",{children:Q?"Running":"Start"})]})}),e.jsxs("button",{type:"button",onPointerDown:b=>fe.start(b),"aria-label":"Drag to reorder",title:K?"Reordering":"Drag to reorder",className:`control-pill flex h-7 items-center justify-center gap-1 px-2 text-micro font-semibold transition-colors ${K?"border-[#BFFF00]/35 bg-[#BFFF00]/14 text-[#E1FFB2] cursor-grabbing":"cursor-grab hover:bg-white/[0.08] hover:text-bright"}`,children:[K?e.jsx(Jt,{className:"h-3.5 w-3.5 opacity-90"}):e.jsx(Ht,{className:"h-3.5 w-3.5 opacity-90"}),e.jsx("span",{children:K?"Reordering":"Drag"})]}),e.jsxs("div",{className:"relative ml-auto",children:[e.jsx("button",{type:"button",disabled:be,onClick:()=>N(b=>b===S?null:S),className:"control-pill flex h-7 items-center justify-center px-2.5 text-micro font-semibold disabled:opacity-40",title:"Queue actions",children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(pt,{className:"h-3 w-3 opacity-85"}),e.jsx("span",{children:"More"})]})}),Z===S&&e.jsxs("div",{className:"absolute right-0 top-[calc(100%+6px)] z-[320] min-w-[198px] rounded-xl border border-white/[0.1] bg-[#080d14]/95 p-1.5 shadow-[0_16px_36px_rgba(0,0,0,0.42)] backdrop-blur",children:[e.jsx("button",{type:"button",onClick:()=>{N(null);const b=c();f(`${S}:top`,()=>x(t,"top"),`Moved ${I} to top of queue.`,{optimistic:()=>m(new Set([S]),"top"),rollback:()=>u(b)})},className:"flex h-8 w-full items-center rounded-md px-2.5 text-left text-caption text-primary transition-colors hover:bg-white/[0.08]",children:"Move to top"}),e.jsx("button",{type:"button",onClick:()=>{N(null);const b=c();f(`${S}:bottom`,()=>x(t,"bottom"),`Moved ${I} to bottom of queue.`,{optimistic:()=>m(new Set([S]),"bottom"),rollback:()=>u(b)})},className:"flex h-8 w-full items-center rounded-md px-2.5 text-left text-caption text-primary transition-colors hover:bg-white/[0.08]",children:"Move to bottom"}),e.jsx("button",{type:"button",onClick:()=>{N(null);const b=c();f(`${S}:auto`,async()=>(await x(t,"top"),R({initiativeId:t.initiativeId,workstreamId:t.workstreamId,agentId:t.runnerAgentId,scope:"initiative"})),`Start+Auto enabled for ${ge}.`,{optimistic:()=>m(new Set([S]),"top"),rollback:()=>u(b)})},className:"flex h-8 w-full items-center rounded-md px-2.5 text-left text-caption text-primary transition-colors hover:bg-white/[0.08]",children:"Start with auto"}),Q?e.jsx("button",{type:"button",onClick:()=>{N(null),f(`${S}:pause`,()=>oe(t,A),`Paused ${I}.`)},className:"mt-1 flex h-8 w-full items-center rounded-md px-2.5 text-left text-caption text-primary transition-colors hover:bg-white/[0.08]",children:"Pause run"}):null,e.jsx("button",{type:"button",disabled:be||Q,onClick:()=>{N(null),M(t)},className:"mt-1 flex h-8 w-full items-center rounded-md px-2.5 text-left text-caption text-red-100 transition-colors hover:bg-red-500/[0.12] disabled:opacity-45",children:"Remove from queue"})]})]})]})]})})}const cn=Object.freeze(Object.defineProperty({__proto__:null,NextUpPanel:en},Symbol.toStringTag,{value:"Module"}));export{Dt as I,en as N,cn as a,Qt as o,Kt as u};
@@ -1 +0,0 @@
1
- import{r as x,j as e,u as we,a as se,b as ue}from"./cNrhgGc1.js";import{O as Se,w as F,i as re,b as Q,Q as Re,R as Ne,S as Pe,r as Fe,T as ie,V as Ee}from"./D-bf6hEI.js";import{A as ve,m as te}from"./CxQ08qFN.js";import"./C-KIc3Wc.js";import"./BJgZIVUQ.js";function Ce(t){switch(t){case"config":return"plugin configuration";case"environment":return"environment variable";case"persisted":return"saved credentials";case"openclaw-config-file":return"OpenClaw config";case"legacy-dev":return"legacy key";default:return""}}function _e(t,n){return t==="connected"&&n?"connected":t==="awaiting_browser_auth"||t==="pairing"||t==="starting"?"connecting":t==="error"?"error":"idle"}function Ie({phase:t}){const n=t==="connected"||t==="connecting"?"bg-[#BFFF00]":t==="error"?"bg-red-400":"bg-white/30",l=t==="connecting";return e.jsxs("span",{className:"relative flex h-2.5 w-2.5 shrink-0",children:[l&&e.jsx("span",{className:F("absolute inline-flex h-full w-full animate-ping rounded-full opacity-40",n)}),e.jsx("span",{className:F("relative inline-flex h-2.5 w-2.5 rounded-full",n)})]})}function $e({phase:t}){const n=t==="connected"?"Connected":t==="connecting"?"Connecting...":t==="error"?"Connection issue":"Not connected",l=t==="connected"?"text-[#BFFF00]":t==="error"?"text-red-400":"text-primary";return e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(Ie,{phase:t}),e.jsx("span",{className:F("text-body font-semibold",l),children:n})]})}function De({state:t,isStarting:n,isSubmittingManual:l,workspaceOptions:p,selectedWorkspaceId:s,onSelectWorkspace:v,onRefresh:f,onStartPairing:d,onSubmitManualKey:m,onBackToPairing:k,onUseManualKey:N,onDisconnect:g}){const y="https://www.useorgx.com/settings#security",u=_e(t.status,t.connectionVerified),E=t.status==="manual_key",h=t.status==="awaiting_browser_auth"||t.status==="pairing"||t.status==="starting",A=!!t.lastError,j=Ce(t.keySource),b=x.useMemo(()=>u==="connected"?"Live sync is active. Initiatives, tasks, and activity flow in real time.":u==="connecting"?"Approve the pairing in your browser to finish connecting.":u==="error"?"Trouble reaching OrgX. Try reconnecting or use a manual API key.":t.hasApiKey?"An API key is present but the connection has not been verified yet.":"Connect to OrgX to sync initiatives, tasks, activity, and decisions.",[u,t.hasApiKey]),O=u==="connected"?"border-[#BFFF00]/15":u==="error"?"border-rose-400/20":"border-white/[0.07]";return e.jsxs("div",{className:"flex min-h-0 flex-col gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-heading font-semibold text-white",children:"OrgX connection"}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:b})]}),A&&e.jsx("div",{className:"rounded-xl border border-rose-300/20 bg-rose-400/10 px-4 py-3 text-body text-rose-100",children:t.lastError}),E?e.jsx(Se,{isSubmitting:l,onSubmit:m,onBack:k}):e.jsxs("div",{className:F("rounded-2xl border bg-white/[0.02] p-5",O),children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx($e,{phase:u}),e.jsx("button",{type:"button",onClick:()=>{f()},className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-secondary transition-colors hover:bg-white/[0.06] hover:text-white",children:"Refresh"})]}),u==="connected"&&e.jsxs("div",{className:"mt-4 grid gap-3 text-body text-secondary",children:[e.jsxs("div",{className:"max-w-sm",children:[e.jsx("label",{htmlFor:"settings-workspace-scope",className:"mb-1.5 block text-caption uppercase tracking-[0.08em] text-muted",children:"Workspace scope"}),e.jsxs("div",{className:"relative",children:[e.jsxs("select",{id:"settings-workspace-scope",value:s??"__all__",onChange:R=>{const a=R.target.value;v(a==="__all__"?null:a)},className:"h-9 w-full appearance-none rounded-full border border-strong bg-white/[0.03] pl-3 pr-9 text-body font-semibold text-primary focus:outline-none focus-visible:ring-2 focus-visible:ring-lime/40",title:"Select workspace scope",children:[e.jsx("option",{value:"__all__",children:"All workspaces"}),p.map(R=>e.jsx("option",{value:R.id,children:R.title},R.id))]}),e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"pointer-events-none absolute right-3 top-1/2 -translate-y-1/2 text-secondary",children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]})]}),t.workspaceName&&e.jsxs("p",{className:"text-caption text-muted",children:["Connected account: ",e.jsx("span",{className:"text-secondary",children:t.workspaceName})]}),j&&e.jsxs("div",{className:"flex items-baseline gap-1.5",children:[e.jsx("span",{className:"text-muted",children:"Authenticated via"}),e.jsx("span",{className:"text-primary",children:j})]})]}),u==="idle"&&t.hasApiKey&&!t.connectionVerified&&e.jsxs("p",{className:"mt-3 text-caption text-amber-200/70",children:["Key detected",j?` from ${j}`:""," but not yet verified. Refresh or reconnect to activate live sync."]}),h&&t.connectUrl&&e.jsxs("div",{className:"mt-4 rounded-xl border border-[#BFFF00]/20 bg-[#BFFF00]/[0.06] px-4 py-3",children:[e.jsx("p",{className:"text-caption uppercase tracking-[0.1em] text-[#D8FFA1]",children:"Pairing pending"}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:"A browser tab should have opened. Approve the connection to finish."}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsx("a",{href:t.connectUrl,target:"_blank",rel:"noopener noreferrer",className:"rounded-full border border-[#BFFF00]/30 bg-[#BFFF00]/15 px-3 py-1.5 text-caption font-semibold text-[#D8FFA1] transition-colors hover:bg-[#BFFF00]/25",children:"Open approval page"}),t.expiresAt&&e.jsxs("span",{className:"text-caption text-muted",children:["Expires ",new Date(t.expiresAt).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})]})]})]}),e.jsx("div",{className:F("flex flex-wrap items-center gap-2",u==="connected"?"mt-5":"mt-4"),children:u==="connected"?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>{d()},disabled:n,className:"rounded-full border border-strong bg-white/[0.03] px-4 py-2 text-body font-semibold text-primary transition-colors hover:bg-white/[0.06] disabled:cursor-not-allowed disabled:opacity-50",children:"Reconnect"}),e.jsx("button",{type:"button",onClick:()=>{g()},className:"rounded-full border border-rose-300/20 bg-transparent px-4 py-2 text-body font-semibold text-rose-200/70 transition-colors hover:bg-rose-400/10",children:"Disconnect"}),e.jsx("a",{href:y,target:"_blank",rel:"noreferrer",className:"rounded-full border border-strong bg-white/[0.03] px-4 py-2 text-body font-semibold text-primary transition-colors hover:bg-white/[0.06]",children:"Manage API keys"})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>{d()},disabled:n,"data-modal-autofocus":"true",className:"inline-flex items-center gap-2 rounded-full bg-[#BFFF00] px-4 py-2 text-body font-semibold text-black transition-colors hover:bg-[#d3ff42] disabled:cursor-not-allowed disabled:opacity-50",children:n?"Connecting...":"Connect in browser"}),e.jsx("button",{type:"button",onClick:N,className:"rounded-full border border-strong bg-white/[0.03] px-4 py-2 text-body font-semibold text-primary transition-colors hover:bg-white/[0.06]",children:"Use API key"}),t.hasApiKey&&e.jsx("button",{type:"button",onClick:()=>{g()},className:"rounded-full border border-rose-300/20 bg-transparent px-4 py-2 text-body font-semibold text-rose-200/70 transition-colors hover:bg-rose-400/10",children:"Disconnect"})]})})]}),u!=="connected"&&e.jsxs("p",{className:"text-caption leading-relaxed text-muted",children:["Prefer user-scoped keys (",e.jsx("code",{className:"rounded bg-black/40 px-1",children:"oxk_..."}),"). They don't require a separate userId header."]})]})}const Be=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;function ke(t){if(typeof t!="string")return null;const n=t.trim();return Be.test(n)?n:null}const ee={decisionV2Enabled:!0,decisionDedupeEnabled:!0,decisionEvidenceRequiredForBlocking:!1,decisionAutoResolveGuardedEnabled:!0,customRunInstructions:""};function Ue(t){return{decisionV2Enabled:typeof(t==null?void 0:t.decision_v2_enabled)=="boolean"?t.decision_v2_enabled:ee.decisionV2Enabled,decisionDedupeEnabled:typeof(t==null?void 0:t.decision_dedupe_enabled)=="boolean"?t.decision_dedupe_enabled:ee.decisionDedupeEnabled,decisionEvidenceRequiredForBlocking:typeof(t==null?void 0:t.decision_evidence_required_for_blocking)=="boolean"?t.decision_evidence_required_for_blocking:ee.decisionEvidenceRequiredForBlocking,decisionAutoResolveGuardedEnabled:typeof(t==null?void 0:t.decision_auto_resolve_guarded_enabled)=="boolean"?t.decision_auto_resolve_guarded_enabled:ee.decisionAutoResolveGuardedEnabled,customRunInstructions:typeof(t==null?void 0:t.custom_run_instructions)=="string"?t.custom_run_instructions:ee.customRunInstructions}}function Le(t){return{id:t.id,name:typeof t.name=="string"&&t.name.trim().length>0?t.name:t.id,type:typeof t.type=="string"?t.type:"custom",status:typeof t.status=="string"?t.status:"active",model:typeof t.model=="string"?t.model:null,runtimeSettings:Ue(t.runtime_settings)}}function ge(t){if(!t||t.ok!==!0||!t.data||t.data.ok!==!0)return{projectId:null,agents:[]};const n=t.data,l=Array.isArray(n.agents)?n.agents:n.agent?[n.agent]:[];return{projectId:ke(typeof n.workspace_id=="string"?n.workspace_id:typeof n.command_center_id=="string"?n.command_center_id:typeof n.project_id=="string"?n.project_id:null),agents:l.map(Le)}}function Ae({authToken:t=null,embedMode:n=!1,enabled:l=!0}={}){var g,y,u,E;const p=we(),s=re(),v=x.useMemo(()=>["agent-suite",{authToken:t,embedMode:n}],[t,n]),f=x.useMemo(()=>["agent-suite-runtime-settings",{authToken:t,embedMode:n}],[t,n]),d=se({queryKey:v,enabled:l,queryFn:async()=>{if(s)return{ok:!1,error:"Agent suite controls are unavailable in demo mode."};const h=await fetch("/orgx/api/agent-suite/status",{headers:Q({authToken:t,embedMode:n})}),A=await h.json().catch(()=>null);return h.ok?A:{ok:!1,error:(A==null?void 0:A.error)??`Failed to load agent suite (${h.status})`}},staleTime:1e4}),m=se({queryKey:f,enabled:l,queryFn:async()=>{if(s)return{projectId:null,agents:[]};const h=await fetch("/orgx/api/agent-suite/runtime-settings",{headers:Q({authToken:t,embedMode:n})}),A=await h.json().catch(()=>null);if(!h.ok){const j=A==null?void 0:A.error,b=typeof j=="string"?j.trim():"",O=b.includes("<!DOCTYPE")||b.includes("<html"),R=h.status===404?"Agent runtime settings endpoint is not available in this plugin build.":b.length>0&&!O?b:`Failed to load agent runtime settings (${h.status})`;throw new Error(R)}return ge(A??null)},staleTime:1e4}),k=ue({mutationFn:async({dryRun:h,forceSkillPack:A}={})=>{if(s)return{ok:!1,error:"Agent suite install is unavailable in demo mode."};const j=await fetch("/orgx/api/agent-suite/install",{method:"POST",headers:Q({authToken:t,embedMode:n,contentTypeJson:!0}),body:JSON.stringify({dryRun:!!h,forceSkillPack:!!A})}),b=await j.json().catch(()=>null);if(!j.ok)throw new Error((b==null?void 0:b.error)??`Failed to install agent suite (${j.status})`);return b},onSuccess:async()=>{await p.invalidateQueries({queryKey:v})}}),N=ue({mutationFn:async h=>{if(s)return{projectId:null,agents:[]};const A=ke(h.projectId??null),j=await fetch("/orgx/api/agent-suite/runtime-settings",{method:"PATCH",headers:Q({authToken:t,embedMode:n,contentTypeJson:!0}),body:JSON.stringify({...A?{workspace_id:A}:{},agent_id:h.agentId,runtime_settings:{decision_v2_enabled:h.runtimeSettings.decisionV2Enabled,decision_dedupe_enabled:h.runtimeSettings.decisionDedupeEnabled,decision_evidence_required_for_blocking:h.runtimeSettings.decisionEvidenceRequiredForBlocking,decision_auto_resolve_guarded_enabled:h.runtimeSettings.decisionAutoResolveGuardedEnabled,custom_run_instructions:h.runtimeSettings.customRunInstructions}})}),b=await j.json().catch(()=>null);if(!j.ok)throw new Error((b==null?void 0:b.error)??`Failed to save agent runtime settings (${j.status})`);return ge(b??null)},onSuccess:async()=>{await p.invalidateQueries({queryKey:f})}});return{status:d.data??null,isLoading:d.isLoading,isRefetching:d.isRefetching,error:(d.data&&"error"in d.data?d.data.error:null)??((g=d.error)==null?void 0:g.message)??null,installError:((y=k.error)==null?void 0:y.message)??null,runtimeSettings:m.data??{projectId:null,agents:[]},runtimeSettingsError:((u=m.error)==null?void 0:u.message)??null,isRuntimeSettingsLoading:m.isLoading,isRuntimeSettingsRefetching:m.isRefetching,refetchRuntimeSettings:m.refetch,saveRuntimeSettings:N.mutate,saveRuntimeSettingsAsync:N.mutateAsync,saveRuntimeSettingsError:((E=N.error)==null?void 0:E.message)??null,isSavingRuntimeSettings:N.isPending,refetchStatus:d.refetch,install:k.mutate,installAsync:k.mutateAsync,resetInstall:k.reset,installResult:k.data??null,isInstalling:k.isPending}}function H(t,n){return t===1?`${t} ${n}`:`${t} ${n}s`}function q({tone:t,children:n}){const l=x.useMemo(()=>t==="good"?"border-lime/25 bg-lime/[0.10] text-lime":t==="warn"?"border-amber-300/25 bg-amber-400/10 text-amber-100/90":"border-white/[0.10] bg-white/[0.02] text-primary",[t]);return e.jsx("span",{className:F("inline-flex items-center rounded-full border px-2.5 py-1 text-caption font-semibold",l),children:n})}const ae={conservative:"Conservative",balanced:"Balanced",autonomous:"Autonomous"},Oe={conservative:"All approvals. Freeze and pin policy updates until manually reviewed.",balanced:"Smart defaults. Keep policy live but pinned to current checksum.",autonomous:"Max automation. Keep policy live and unpinned for newest updates."};function Te(t){return t?t.frozen&&t.pinnedChecksum?"conservative":!t.frozen&&t.pinnedChecksum?"balanced":!t.frozen&&!t.pinnedChecksum?"autonomous":null:null}function Ke(t){return t==="conservative"?{frozen:!0,pinToCurrent:!0,reason:"Applied Conservative preset from Agent Settings UI"}:t==="balanced"?{frozen:!1,pinToCurrent:!0,reason:"Applied Balanced preset from Agent Settings UI"}:{frozen:!1,clearPin:!0,reason:"Applied Autonomous preset from Agent Settings UI"}}function Me({plan:t,agentId:n,sampleTaskId:l}){var N;const p=t.workspaceFiles.filter(g=>g.action!=="noop"),s=p.filter(g=>g.action==="conflict").length,v=p.filter(g=>g.action==="create").length,f=p.filter(g=>g.action==="update").length,d=[];s>0&&d.push(`${H(s,"managed file")} needs review before apply.`),t.skillPackUpdateAvailable&&d.push("Remote skill update is available; behavior could drift after refresh."),(N=t.skillPackPolicy)!=null&&N.frozen&&d.push("Skill pack is frozen; preview reflects pinned behavior only.");const m=[`Load draft simulation for ${n}.`,`Run sample task "${l}" through current suite guardrails.`,"Assemble managed/local overlay and compute write plan.",s>0?"Stop before apply because conflicts require operator review.":"Proceed to apply path if operator confirms."],k=[`${H(t.openclawConfigAddedAgents.length,"agent")} added to OpenClaw config.`,`${H(p.length,"workspace file")} changed (${v} create, ${f} update).`,`Progress stream expected at start and completion for sample "${l}".`];return{outcome:d.length>0?"warning":"ready",executionTrace:m,riskFlags:d,expectedOutputs:k,confidence:d.length>0?"Medium confidence: preview is deterministic but includes review-dependent flags.":"High confidence: preview is deterministic with no active risk flags."}}function qe({authToken:t=null,embedMode:n=!1,enabled:l=!0,devMode:p=!1}){var D,X,Z,pe,xe;const[s,v]=x.useState(!1),[f,d]=x.useState(""),[m,k]=x.useState("triage-sample"),[N,g]=x.useState(null),[y,u]=x.useState(null),[E,h]=x.useState(!1),[A,j]=x.useState(null),[b,O]=x.useState(null),[R,a]=x.useState(null),[S,P]=x.useState(null),w=Ae({authToken:t,embedMode:n,enabled:l}),o=(D=w.status)!=null&&D.ok?w.status.data:null,U=((X=o==null?void 0:o.agents)==null?void 0:X.length)??0,I=((Z=o==null?void 0:o.openclawConfigAddedAgents)==null?void 0:Z.length)??0,C=x.useMemo(()=>{var r;return((r=o==null?void 0:o.workspaceFiles)==null?void 0:r.filter(B=>B.action!=="noop"))??[]},[o]),T=C.length,G=x.useMemo(()=>C.filter(r=>r.action==="create").length,[C]),L=x.useMemo(()=>C.filter(r=>r.action==="update").length,[C]),$=x.useMemo(()=>C.filter(r=>r.action==="conflict").length,[C]),z=x.useMemo(()=>{if(w.isLoading)return"Loading agent suite status...";if(w.error)return`Unable to read suite status: ${w.error}`;if(!o)return"Suite status unavailable.";if($>0)return`${H($,"file")} to review.`;if(I===0&&T===0)return"Suite is installed and up to date.";const r=[];return I>0&&r.push(`will add ${H(I,"agent")}`),T>0&&r.push(`will update ${H(T,"file")}`),`Preview: ${r.join(", ")}.`},[T,$,I,o,w.error,w.isLoading]),K=(pe=w.installResult)!=null&&pe.ok?w.installResult:null,Y=!!(K!=null&&K.dryRun),W=Te((o==null?void 0:o.skillPackPolicy)??null),i=async()=>{var B;if(!o||w.isInstalling||E)return;const r=f||(((B=o.agents[0])==null?void 0:B.id)??"unassigned-agent");v(!0),h(!0),u(null);try{const M=await w.installAsync({dryRun:!0});if(!M.ok)throw new Error(M.error??"Dry-run failed.");g(Me({plan:M.data,agentId:r,sampleTaskId:m})),j(new Date().toISOString())}catch(M){u(M instanceof Error?M.message:"Dry-run failed.")}finally{h(!1)}},c=async r=>{await fetch("/orgx/api/skill-pack/policy",{method:"POST",headers:Q({authToken:t,embedMode:n,contentTypeJson:!0}),body:JSON.stringify(r)}).then(async B=>{if(!B.ok){const M=await B.json().catch(()=>null);throw new Error((M==null?void 0:M.error)??`Failed to update policy (${B.status})`)}}),await w.refetchStatus()},_=async r=>{if(!(!(o!=null&&o.skillPackPolicy)||b)){P(null),a(null),O(r);try{await c(Ke(r)),a(`${ae[r]} preset applied.`)}catch(B){P(B instanceof Error?B.message:"Failed to apply preset.")}finally{O(null)}}};return e.jsxs("div",{className:"rounded-2xl border border-white/[0.07] bg-white/[0.02] p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-heading font-semibold text-white",children:"OrgX agent suite"}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:"Installs domain agents into your workspace (workspaces + guardrails + managed/local overlay)."})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{w.resetInstall(),w.refetchStatus()},disabled:w.isRefetching,className:"rounded-full border border-strong bg-white/[0.03] px-4 py-2 text-body font-semibold text-primary transition-colors hover:bg-white/[0.06] disabled:cursor-not-allowed disabled:opacity-50",children:w.isRefetching?"Refreshing...":"Refresh"}),e.jsx("button",{type:"button",onClick:()=>{i()},disabled:w.isInstalling||E,className:"inline-flex min-h-[44px] items-center rounded-full border border-lime/30 bg-lime/[0.14] px-4 py-2 text-body font-semibold text-lime transition-colors hover:bg-lime/[0.2] disabled:cursor-not-allowed disabled:opacity-50",title:"Runs a sample dry-run against the current draft settings",children:E?"Testing config...":"Test This Config"}),e.jsx("button",{type:"button",onClick:()=>{w.install({dryRun:!1,forceSkillPack:!0})},disabled:w.isInstalling,className:"rounded-full border border-strong bg-white/[0.03] px-4 py-2 text-body font-semibold text-primary transition-colors hover:bg-white/[0.06] disabled:cursor-not-allowed disabled:opacity-50",title:"Forces a check for the latest OrgX skill pack and applies it (managed/local overlay preserves local edits)",children:"Refresh skills"}),e.jsx("button",{type:"button",onClick:()=>{w.install({dryRun:!1})},disabled:w.isInstalling,className:"inline-flex items-center gap-2 rounded-full bg-[#BFFF00] px-4 py-2 text-body font-semibold text-black transition-colors hover:bg-[#d3ff42] disabled:cursor-not-allowed disabled:opacity-50",title:"Install missing agents and scaffold managed workspace files",children:w.isInstalling?"Installing...":"Install / Update"})]})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsx(q,{tone:w.error?"warn":"neutral",children:z}),o&&e.jsxs(e.Fragment,{children:[e.jsx(q,{tone:I===0?"good":"neutral",children:I===0?"agents configured":`${I} agents to install`}),e.jsxs(q,{tone:"neutral",children:[H(U,"agent")," total"]}),e.jsx(q,{tone:T===0?"good":"neutral",children:T===0?"no file changes":`${T} file changes`}),$>0&&e.jsx(q,{tone:"neutral",children:H($,"file to review")}),o.skillPackUpdateAvailable&&e.jsx(q,{tone:"warn",children:"skill update available"}),((xe=o.skillPackPolicy)==null?void 0:xe.frozen)&&e.jsx(q,{tone:"neutral",children:"skills frozen"})]})]}),w.installError&&e.jsx("div",{className:"mt-3 rounded-xl border border-rose-300/20 bg-rose-400/10 px-4 py-3 text-body text-rose-100",children:w.installError}),K&&e.jsxs("div",{className:"mt-3 rounded-xl border border-lime/20 bg-lime/[0.06] px-4 py-3",children:[e.jsx("p",{className:"text-caption uppercase tracking-[0.1em] text-[#D8FFA1]",children:Y?"Dry run":"Applied"}),e.jsxs("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:[p&&K.operationId&&e.jsxs(e.Fragment,{children:["Operation ",e.jsx("code",{className:"rounded bg-black/40 px-1",children:K.operationId})," "]}),Y?"Computed the plan without writing any files.":"Installed config and refreshed managed files."]})]}),o&&e.jsxs("div",{className:"mt-4",children:[e.jsxs("div",{className:"rounded-xl border border-white/[0.07] bg-black/20 p-3",children:[e.jsx("p",{className:"text-body font-semibold text-primary",children:"Dry-run sample"}),e.jsx("p",{className:"mt-1 text-caption leading-relaxed text-secondary",children:"Validate expected behavior with draft settings before applying changes."}),e.jsxs("div",{className:"mt-3 grid gap-3 md:grid-cols-2",children:[e.jsxs("label",{className:"grid gap-1.5 text-caption text-secondary",children:["Agent",e.jsxs("select",{value:f,onChange:r=>d(r.target.value),className:"min-h-[44px] rounded-lg border border-white/[0.1] bg-white/[0.03] px-3 text-body text-primary outline-none transition-colors focus:border-lime/35",children:[e.jsx("option",{value:"",children:"Auto-select first pending agent"}),o.agents.map(r=>e.jsxs("option",{value:r.id,children:[r.name," (",r.id,")"]},r.id))]})]}),e.jsxs("label",{className:"grid gap-1.5 text-caption text-secondary",children:["Sample task",e.jsxs("select",{value:m,onChange:r=>k(r.target.value),className:"min-h-[44px] rounded-lg border border-white/[0.1] bg-white/[0.03] px-3 text-body text-primary outline-none transition-colors focus:border-lime/35",children:[e.jsx("option",{value:"triage-sample",children:"Triage sample"}),e.jsx("option",{value:"incident-template",children:"Incident template"}),e.jsx("option",{value:"handoff-summary",children:"Handoff summary"})]})]})]}),y&&e.jsx("p",{className:"mt-3 rounded-lg border border-rose-300/20 bg-rose-400/10 px-3 py-2 text-caption text-rose-100",children:y}),N&&e.jsxs("div",{role:"region","aria-live":"polite",className:"mt-3 rounded-lg border border-teal/30 bg-teal/[0.08] px-3 py-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("p",{className:"text-caption font-semibold uppercase tracking-[0.08em] text-teal",children:"Draft simulation"}),e.jsx(q,{tone:N.outcome==="ready"?"good":"warn",children:N.outcome==="ready"?"Ready to apply":"Review recommended"})]}),A&&e.jsx("p",{className:"mt-1 text-caption text-secondary",children:new Date(A).toLocaleString()}),e.jsxs("div",{className:"mt-3 grid gap-3 lg:grid-cols-3",children:[e.jsxs("div",{className:"rounded-lg border border-white/[0.08] bg-black/20 p-2.5",children:[e.jsx("p",{className:"text-caption font-semibold text-primary",children:"Execution trace"}),e.jsx("ol",{className:"mt-1.5 grid gap-1 text-caption text-secondary",children:N.executionTrace.map((r,B)=>e.jsxs("li",{children:[B+1,". ",r]},r))})]}),e.jsxs("div",{className:"rounded-lg border border-white/[0.08] bg-black/20 p-2.5",children:[e.jsx("p",{className:"text-caption font-semibold text-primary",children:"Risk flags"}),e.jsx("div",{className:"mt-1.5 grid gap-1 text-caption text-secondary",children:N.riskFlags.length>0?N.riskFlags.map(r=>e.jsx("p",{children:r},r)):e.jsx("p",{children:"No risk flags detected."})})]}),e.jsxs("div",{className:"rounded-lg border border-white/[0.08] bg-black/20 p-2.5",children:[e.jsx("p",{className:"text-caption font-semibold text-primary",children:"Expected outputs"}),e.jsxs("div",{className:"mt-1.5 grid gap-1 text-caption text-secondary",children:[N.expectedOutputs.map(r=>e.jsx("p",{children:r},r)),e.jsx("p",{className:"text-primary",children:N.confidence})]})]})]})]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-body font-semibold text-primary",children:"Suite details"}),e.jsx("button",{type:"button",onClick:()=>v(r=>!r),className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.06]",children:s?"Hide":"Show"})]}),s&&e.jsxs("div",{className:"mt-3 grid gap-3",children:[e.jsx("div",{className:"rounded-xl border border-white/[0.07] bg-black/20 p-3",children:e.jsxs("div",{className:"grid gap-1 text-body text-secondary",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{children:"Workspace config"}),p?e.jsx("code",{className:"rounded bg-black/40 px-1.5 py-0.5 text-caption text-primary",children:o.openclawConfigPath}):e.jsx("span",{className:"text-caption text-primary",children:"Connected"})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{children:"Agent workspaces"}),e.jsxs("code",{className:"rounded bg-black/40 px-1.5 py-0.5 text-caption text-primary",children:[o.suiteWorkspaceRoot,"/","{agent-id}"]})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{children:"Pack"}),e.jsxs("code",{className:"rounded bg-black/40 px-1.5 py-0.5 text-caption text-primary",children:[o.packId,"@",o.packVersion]})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{children:"Skill pack"}),e.jsx("code",{className:"rounded bg-black/40 px-1.5 py-0.5 text-caption text-primary",children:o.skillPack?`${o.skillPack.name}@${o.skillPack.version} (${o.skillPack.source})`:"builtin"})]}),o.skillPackRemote&&e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{children:"Skill pack remote"}),e.jsxs("code",{className:"rounded bg-black/40 px-1.5 py-0.5 text-caption text-primary",children:[o.skillPackRemote.name,"@",o.skillPackRemote.version]})]}),o.skillPackPolicy&&e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{children:"Skill pack policy"}),e.jsxs("code",{className:"rounded bg-black/40 px-1.5 py-0.5 text-caption text-primary",children:[o.skillPackPolicy.frozen?"frozen":"live",o.skillPackPolicy.pinnedChecksum?`, pinned:${o.skillPackPolicy.pinnedChecksum.slice(0,8)}…`:""]})]}),o.skillPackPolicy&&e.jsxs("div",{className:"mt-2 rounded-xl border border-white/[0.08] bg-white/[0.02] p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("p",{className:"text-caption font-semibold uppercase tracking-[0.08em] text-secondary",children:"Execution presets"}),e.jsx(q,{tone:W?"good":"neutral",children:W?`Active: ${ae[W]}`:"Active: custom"})]}),e.jsx("p",{className:"mt-1 text-caption text-secondary",children:"Choose how much human approval vs automation your default behavior policy should use."}),e.jsx("div",{className:"mt-2 grid gap-2 sm:grid-cols-3",children:["conservative","balanced","autonomous"].map(r=>{const B=W===r,M=b===r;return e.jsxs("button",{type:"button",onClick:()=>{_(r)},disabled:!!b,className:F("min-h-[44px] rounded-lg border px-3 py-2 text-left transition-colors disabled:cursor-not-allowed disabled:opacity-50",B?"border-lime/35 bg-lime/[0.12] text-lime":"border-white/[0.12] bg-white/[0.03] text-primary hover:bg-white/[0.06]"),children:[e.jsx("p",{className:"text-body font-semibold",children:M?"Applying…":ae[r]}),e.jsx("p",{className:"mt-1 text-caption text-secondary",children:Oe[r]})]},r)})}),R&&e.jsx("p",{className:"mt-2 rounded-lg border border-lime/20 bg-lime/[0.07] px-2.5 py-2 text-caption text-[#D8FFA1]",children:R}),S&&e.jsx("p",{className:"mt-2 rounded-lg border border-rose-300/20 bg-rose-400/10 px-2.5 py-2 text-caption text-rose-100",children:S})]}),o.skillPackPolicy&&e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{var r;c({frozen:!((r=o.skillPackPolicy)!=null&&r.frozen)})},className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.06]",children:o.skillPackPolicy.frozen?"Unfreeze skills":"Freeze skills"}),e.jsx("button",{type:"button",onClick:()=>{var r;(r=o.skillPackPolicy)!=null&&r.pinnedChecksum?c({clearPin:!0}):c({pinToCurrent:!0})},className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.06]",children:o.skillPackPolicy.pinnedChecksum?"Unpin":"Pin current"}),e.jsx("p",{className:"text-caption text-muted",children:"Freeze prevents background checks; pin prevents applying a new checksum."})]})]})}),e.jsxs("div",{className:"rounded-xl border border-white/[0.07] bg-black/20 p-3",children:[e.jsxs("p",{className:"text-body font-semibold text-primary",children:["Agents (",U,")"]}),e.jsx("div",{className:"mt-2 grid gap-2",children:o.agents.map(r=>e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 rounded-xl border border-subtle 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-semibold text-bright",children:r.name}),e.jsxs("p",{className:"mt-0.5 truncate text-caption text-secondary",children:[e.jsx("code",{className:"rounded bg-black/40 px-1",children:r.id}),e.jsx("span",{className:"px-1",children:"·"}),e.jsx("span",{children:r.domain})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(q,{tone:r.configuredInOpenclaw?"good":"neutral",children:r.configuredInOpenclaw?"configured":"to install"}),e.jsx(q,{tone:r.workspaceExists?"good":"neutral",children:r.workspaceExists?"workspace ok":"workspace missing"})]})]},r.id))})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.07] bg-black/20 p-3",children:[e.jsx("p",{className:"text-body font-semibold text-primary",children:"Planned file writes"}),e.jsxs("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:["Managed files are written to ",e.jsx("code",{className:"rounded bg-black/40 px-1",children:".orgx/managed"}),". Local overrides are read from ",e.jsx("code",{className:"rounded bg-black/40 px-1",children:".orgx/local"})," and appended into the composite files in the agent workspace root."]}),e.jsxs("div",{className:"mt-2 grid gap-1 text-caption text-secondary",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{children:"Writes"}),e.jsx("span",{className:"text-primary",children:H(o.workspaceFiles.length,"file")})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{children:"Creates/updates"}),e.jsx("span",{className:"text-primary",children:T})]}),(G>0||L>0)&&e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{children:"Breakdown"}),e.jsxs("span",{className:"text-primary",children:[G>0?`${G} create`:"0 create",","," ",L>0?`${L} update`:"0 update"]})]})]}),I>0&&e.jsxs("div",{className:"mt-3 rounded-lg border border-white/[0.08] bg-white/[0.02] px-3 py-2",children:[e.jsx("p",{className:"text-caption font-semibold text-primary",children:"Agents to install"}),e.jsx("div",{className:"mt-1 flex flex-wrap gap-2",children:o.openclawConfigAddedAgents.map(r=>e.jsx("code",{className:"rounded-full border border-strong bg-black/40 px-2 py-0.5 text-caption text-primary",children:r},r))})]}),C.length>0&&e.jsxs("div",{className:"mt-3 rounded-lg border border-white/[0.08] bg-white/[0.02] px-3 py-2",children:[e.jsx("p",{className:"text-caption font-semibold text-primary",children:"Files that will change"}),e.jsxs("div",{className:"mt-2 grid gap-1.5",children:[C.slice(0,24).map(r=>e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 text-caption",children:[e.jsxs("code",{className:"rounded bg-black/40 px-1.5 py-0.5 text-primary",children:[r.agentId,"/",r.file]}),e.jsx("span",{className:"text-secondary",children:r.action})]},`${r.agentId}:${r.file}`)),C.length>24&&e.jsxs("p",{className:"text-caption text-muted",children:["Showing 24 of ",C.length,". Install/Update to apply all."]})]})]})]})]})]})]})}function he(t){return{ok:!0,updatedAt:null,providers:{openai:{configured:!!(t!=null&&t.openai),source:"none",masked:null},anthropic:{configured:!!(t!=null&&t.anthropic),source:"none",masked:null},openrouter:{configured:!!(t!=null&&t.openrouter),source:"none",masked:null}}}}function ze(){return{ok:!0,agentId:"demo",providers:{openai:{ok:!1,error:"Demo mode does not run provider probes."},anthropic:{ok:!1,error:"Demo mode does not run provider probes."},openrouter:{ok:!1,error:"Demo mode does not run provider probes."}}}}function Ve({authToken:t=null,embedMode:n=!1,enabled:l=!0}={}){var k,N;const p=we(),s=x.useMemo(()=>["byok-settings",{authToken:t,embedMode:n}],[t,n]),v=x.useMemo(()=>["byok-health",{authToken:t,embedMode:n}],[t,n]),f=se({queryKey:s,enabled:l,queryFn:async()=>{if(re())return he();const g=await fetch("/orgx/api/settings/byok",{headers:Q({authToken:t,embedMode:n})}),y=await g.json().catch(()=>null);return g.ok?y:{ok:!1,updatedAt:null,providers:{openai:{configured:!1,source:"none",masked:null},anthropic:{configured:!1,source:"none",masked:null},openrouter:{configured:!1,source:"none",masked:null}},error:(y==null?void 0:y.error)??`Failed to load settings (${g.status})`}},staleTime:15e3}),d=se({queryKey:v,enabled:!1,queryFn:async()=>{if(re())return ze();const g=await fetch("/orgx/api/settings/byok/health",{headers:Q({authToken:t,embedMode:n})}),y=await g.json().catch(()=>null);return g.ok?y:{ok:!1,agentId:"main",providers:{openai:{ok:!1,error:(y==null?void 0:y.error)??`Probe failed (${g.status})`},anthropic:{ok:!1,error:(y==null?void 0:y.error)??`Probe failed (${g.status})`},openrouter:{ok:!1,error:(y==null?void 0:y.error)??`Probe failed (${g.status})`}},error:(y==null?void 0:y.error)??`Probe failed (${g.status})`}}}),m=ue({mutationFn:async g=>{if(re())return he({openai:typeof g.openaiApiKey=="string"&&g.openaiApiKey.trim().length>0,anthropic:typeof g.anthropicApiKey=="string"&&g.anthropicApiKey.trim().length>0,openrouter:typeof g.openrouterApiKey=="string"&&g.openrouterApiKey.trim().length>0});const y=await fetch("/orgx/api/settings/byok",{method:"POST",headers:Q({authToken:t,embedMode:n,contentTypeJson:!0}),body:JSON.stringify(g??{})}),u=await y.json().catch(()=>null);if(!y.ok)throw new Error((u==null?void 0:u.error)??`Failed to save settings (${y.status})`);return u},onSuccess:async()=>{await p.invalidateQueries({queryKey:s})}});return{status:f.data??null,isLoading:f.isLoading,error:((k=f.data)==null?void 0:k.error)??((N=f.error)==null?void 0:N.message)??null,refetchStatus:f.refetch,update:m.mutateAsync,isSaving:m.isPending,health:d.data??null,probe:d.refetch,isProbing:d.isFetching}}const me=[{id:"openai",label:"OpenAI",hint:"Used for GPT models.",envVar:"OPENAI_API_KEY"},{id:"anthropic",label:"Anthropic",hint:"Used for Claude models.",envVar:"ANTHROPIC_API_KEY"},{id:"openrouter",label:"OpenRouter",hint:"Used for multi-vendor routing.",envVar:"OPENROUTER_API_KEY"}];function be(t){return t==="openai"?"openaiApiKey":t==="anthropic"?"anthropicApiKey":"openrouterApiKey"}function He(t){var n;return((n=me.find(l=>l.id===t))==null?void 0:n.label)??t}function Qe({authToken:t=null,embedMode:n=!1,enabled:l=!0}){const p=Ve({authToken:t,embedMode:n,enabled:l}),s=p.status,v=p.health,[f,d]=x.useState({openai:"",anthropic:"",openrouter:""}),[m,k]=x.useState({openai:!1,anthropic:!1,openrouter:!1}),[N,g]=x.useState({openai:!1,anthropic:!1,openrouter:!1}),[y,u]=x.useState(null),[E,h]=x.useState(null);x.useEffect(()=>{l&&(d({openai:"",anthropic:"",openrouter:""}),k({openai:!1,anthropic:!1,openrouter:!1}),g({openai:!1,anthropic:!1,openrouter:!1}),u(null),h(null))},[l]);const A=x.useMemo(()=>s!=null&&s.ok?Number(s.providers.openai.configured)+Number(s.providers.anthropic.configured)+Number(s.providers.openrouter.configured):0,[s]),j=x.useMemo(()=>{var w;const a=me.map(o=>{var C;const U=(C=s==null?void 0:s.providers)==null?void 0:C[o.id],I=m[o.id]&&f[o.id].trim().length>0;return{id:o.id,label:o.label,configured:I||!!(U!=null&&U.configured),source:I?"pending stored key":(U==null?void 0:U.source)??"none",pending:I?"save":"none"}}),S=a.filter(o=>o.configured),P=S.length===0?"Run preview: launch blocked until at least one provider key is configured.":S.length===1?`Run preview: launches with ${(w=S[0])==null?void 0:w.label} as the only provider.`:`Run preview: launches with ${S.length} providers available for routing.`;return{providers:a,activeProviders:S,summary:P}},[m,s,f]),b=async a=>{if(!l)return;h(null);const S=f[a].trim();if(!m[a])return;if(!S){h(`Enter a ${He(a)} API key or use "Clear" to remove the saved key.`);return}const P=be(a);try{u(a),await p.update({[P]:S}),k(w=>({...w,[a]:!1})),d(w=>({...w,[a]:""})),g(w=>({...w,[a]:!1}))}finally{u(null)}},O=async a=>{h(null);const S=be(a);try{u(a),await p.update({[S]:null}),k(P=>({...P,[a]:!1})),d(P=>({...P,[a]:""})),g(P=>({...P,[a]:!1}))}finally{u(null)}},R=async()=>{h(null),await p.probe()};return e.jsxs("div",{className:"flex min-h-0 flex-col",children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("h3",{className:"text-heading font-semibold text-white",children:"Provider keys"}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:"Bring your own provider keys. Keys are stored locally and used for agent launches."}),A===0?e.jsxs("div",{className:"mt-3 inline-flex items-center gap-2 rounded-full border border-amber-200/20 bg-amber-200/10 px-3 py-1 text-caption text-amber-100/85",children:[e.jsx("span",{className:"inline-flex h-1.5 w-1.5 rounded-full bg-amber-200/80"}),"No keys detected yet. You can also use env vars."]}):e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsxs("span",{className:"chip",children:[A," / 3 configured"]}),(s==null?void 0:s.updatedAt)&&e.jsxs("span",{className:"text-caption text-muted",children:["Updated ",new Date(s.updatedAt).toLocaleString()]})]})]}),(E||p.error)&&e.jsx("div",{className:"mb-4 rounded-xl border border-rose-300/20 bg-rose-400/10 p-4 text-body text-rose-100",children:E??p.error}),e.jsxs("div",{className:"mb-4 rounded-2xl border border-subtle bg-white/[0.02] p-4",children:[e.jsx("p",{className:"text-body font-semibold text-primary",children:"Where keys come from"}),e.jsxs("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:["If you set an env var (e.g."," ",e.jsx("code",{className:"rounded bg-black/40 px-1",children:"OPENAI_API_KEY"}),"), it will be used unless a saved key overrides it."]})]}),e.jsxs("div",{className:"mb-4 rounded-2xl border border-lime/20 bg-lime/[0.05] p-4",children:[e.jsx("p",{className:"text-body font-semibold text-[#D8FFA1]",children:"Agent run preview"}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:j.summary}),e.jsx("div",{className:"mt-3 grid gap-2 sm:grid-cols-3",children:j.providers.map(a=>e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-black/20 px-3 py-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-caption font-semibold text-primary",children:a.label}),e.jsx("span",{className:F("rounded-full border px-2 py-0.5 text-micro uppercase tracking-[0.12em]",a.configured?"border-lime/30 bg-lime/[0.14] text-[#D8FFA1]":"border-white/[0.14] bg-white/[0.04] text-secondary"),children:a.configured?"Available":"Missing"})]}),e.jsxs("p",{className:"mt-1 text-caption text-muted",children:["Source: ",a.source,a.pending==="save"?" (not saved yet)":""]})]},a.id))})]}),e.jsx("div",{className:"grid grid-cols-1 gap-4",children:me.map(a=>{var L,$;const S=(L=s==null?void 0:s.providers)==null?void 0:L[a.id],P=($=v==null?void 0:v.providers)==null?void 0:$[a.id],w=(S==null?void 0:S.masked)??null,o=(S==null?void 0:S.source)??"none",U=o==="stored",I=y===a.id,C=m[a.id]&&f[a.id].trim().length>0&&!p.isSaving&&!I,T=U&&!p.isSaving&&!I,G=U?"Update":"Save";return e.jsxs("div",{className:"rounded-2xl border border-white/[0.07] bg-white/[0.02] p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("p",{className:"text-body font-semibold text-white",children:a.label}),e.jsx("span",{className:F("rounded-full border px-2 py-0.5 text-micro uppercase tracking-[0.12em]",S!=null&&S.configured?"border-emerald-300/25 bg-emerald-400/10 text-emerald-100":"border-strong bg-white/[0.03] text-secondary"),children:S!=null&&S.configured?"Configured":"Missing"})]}),e.jsxs("p",{className:"mt-1 text-body text-secondary",children:[a.hint," ",e.jsxs("span",{className:"text-muted",children:["Env: ",e.jsx("code",{className:"rounded bg-black/40 px-1",children:a.envVar})]})]}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[o!=="none"&&e.jsxs("span",{className:"chip",children:["source: ",o]}),w&&e.jsxs("span",{className:"chip",children:["key: ",w]}),P&&e.jsx("span",{className:F("chip",P.ok?"text-emerald-100":"text-rose-100"),children:P.ok?`ready (${P.modelCount??0} models)`:"not ready"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>g(z=>({...z,[a.id]:!z[a.id]})),className:"rounded-lg border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.08]",title:N[a.id]?"Hide key":"Show key",children:N[a.id]?"Hide":"Show"}),e.jsx("button",{type:"button",onClick:()=>void R(),className:"rounded-lg border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.08]",title:"Probe configured models",children:"Probe"})]})]}),e.jsxs("form",{className:"mt-3",onSubmit:z=>{z.preventDefault(),b(a.id)},children:[e.jsx("input",{type:"text",name:`provider-user-${a.id}`,autoComplete:"username",value:`${a.id}-key`,readOnly:!0,tabIndex:-1,"aria-hidden":"true",className:"sr-only"}),e.jsxs("label",{className:"block",htmlFor:`provider-key-${a.id}`,children:[e.jsx("span",{className:"mb-1.5 block text-caption font-medium uppercase tracking-[0.14em] text-muted",children:"API key (stored locally)"}),e.jsx("input",{id:`provider-key-${a.id}`,name:`provider-key-${a.id}`,value:f[a.id],onChange:z=>{d(K=>({...K,[a.id]:z.target.value})),k(K=>({...K,[a.id]:!0})),E&&h(null)},type:N[a.id]?"text":"password",autoComplete:"new-password",spellCheck:!1,placeholder:`Paste ${a.label} key`,className:"w-full rounded-xl border border-white/[0.08] bg-black/30 px-3 py-2.5 font-mono text-body text-primary placeholder:text-faint focus:border-[#BFFF00]/40 focus:outline-none"})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"submit",disabled:!C,className:"rounded-full bg-[#BFFF00] px-4 py-2 text-body font-semibold text-black transition-colors hover:bg-[#d3ff42] disabled:cursor-not-allowed disabled:opacity-40",children:I?"Saving...":G}),e.jsx("button",{type:"button",onClick:()=>void O(a.id),disabled:!T,className:"rounded-full border border-strong bg-white/[0.03] px-4 py-2 text-body font-semibold text-primary transition-colors hover:bg-white/[0.06] disabled:cursor-not-allowed disabled:opacity-35",children:"Clear stored"}),e.jsx("span",{className:"text-caption text-muted",children:m[a.id]?"Unsaved changes":" "})]})]})]},a.id)})})]})}const fe={engineering:"Engineering",product:"Product",design:"Design",marketing:"Marketing",sales:"Sales",operations:"Operations",orchestration:"Orchestration"},J={decisionV2Enabled:!0,decisionDedupeEnabled:!0,decisionEvidenceRequiredForBlocking:!1,decisionAutoResolveGuardedEnabled:!0,customRunInstructions:""},Ge=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;function oe(t){return typeof t!="string"?!1:Ge.test(t.trim())}function ye(t){const n=`${t.name??""} ${t.id??""}`.toLowerCase();return n.includes("orchestrat")?"orchestration":n.includes("engineer")||n.includes("dev delivery")?"engineering":n.includes("product")?"product":n.includes("design")?"design":n.includes("market")?"marketing":n.includes("sales")?"sales":n.includes("operations")||n.includes("ops ")?"operations":null}function We(t,n){return t.decisionV2Enabled===n.decisionV2Enabled&&t.decisionDedupeEnabled===n.decisionDedupeEnabled&&t.decisionEvidenceRequiredForBlocking===n.decisionEvidenceRequiredForBlocking&&t.decisionAutoResolveGuardedEnabled===n.decisionAutoResolveGuardedEnabled&&t.customRunInstructions.trim()===n.customRunInstructions.trim()}function Xe({status:t}){return e.jsx("span",{className:F("rounded-full border px-2 py-0.5 text-micro uppercase tracking-[0.08em]",t==="healthy"?"border-teal/25 bg-teal/[0.10] text-teal":t==="conflict"?"border-rose-300/30 bg-rose-500/[0.12] text-rose-100":"border-white/[0.14] bg-white/[0.04] text-secondary"),children:t==="healthy"?"Healthy":t==="conflict"?"Conflict":"Needs apply"})}function ne({label:t,description:n,enabled:l,onToggle:p}){return e.jsxs("div",{className:"flex min-h-[54px] items-start justify-between gap-3 rounded-xl border border-white/[0.08] bg-black/20 px-3 py-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-body font-semibold text-primary",children:t}),e.jsx("p",{className:"mt-1 text-caption leading-relaxed text-secondary",children:n})]}),e.jsx("button",{type:"button",role:"switch","aria-checked":l,onClick:()=>p(!l),className:F("relative inline-flex h-6 w-11 flex-shrink-0 rounded-full border transition-colors",l?"border-lime/35 bg-lime/[0.20]":"border-white/[0.12] bg-white/[0.06]"),children:e.jsx("span",{"aria-hidden":"true",className:F("absolute top-0.5 h-5 w-5 rounded-full transition-all",l?"left-[20px] bg-lime":"left-0.5 bg-white/70")})})]})}function Je({authToken:t=null,embedMode:n=!1,enabled:l=!0,initialDomain:p=null}){var Y,W;const s=Ae({authToken:t,embedMode:n,enabled:l}),v=(Y=s.status)!=null&&Y.ok?s.status.data.agents:[],f=s.runtimeSettings.agents,d=x.useMemo(()=>{const i=new Map;for(const c of s.runtimeSettings.agents)i.set(c.id,c.runtimeSettings);return i},[s.runtimeSettings.agents]),m=x.useMemo(()=>{const i=new Map;for(const c of f){const _=ye({name:c.name,id:c.id});!_||i.has(_)||i.set(_,{id:c.id,model:c.model,runtimeSettings:c.runtimeSettings})}return v.length>0?v.map(c=>{var _,D,X,Z;return{id:((_=i.get(c.domain))==null?void 0:_.id)??c.id,name:c.name,domain:c.domain,model:((D=i.get(c.domain))==null?void 0:D.model)??null,configStatus:((X=c.configHealth)==null?void 0:X.status)??null,runtimeSettings:((Z=i.get(c.domain))==null?void 0:Z.runtimeSettings)??d.get(c.id)??J}}):f.map(c=>({id:c.id,name:c.name,domain:ye({name:c.name,id:c.id}),model:c.model,configStatus:null,runtimeSettings:c.runtimeSettings}))},[f,v,d]),k=x.useMemo(()=>{const i={};for(const c of m)i[c.id]=c.runtimeSettings;return i},[m]),[N,g]=x.useState(null),[y,u]=x.useState({}),[E,h]=x.useState(null),[A,j]=x.useState(null);x.useEffect(()=>{if(m.length===0){g(null);return}(!N||!m.some(i=>i.id===N))&&g(m[0].id),u(i=>{let c=!1;const _={...i};for(const D of m)_[D.id]||(_[D.id]=k[D.id]??J,c=!0);return c?_:i})},[N,m,k]),x.useEffect(()=>{if(!p||m.length===0)return;const i=m.find(c=>c.domain===p);i&&i.id!==N&&g(i.id)},[N,m,p]);const b=x.useMemo(()=>m.find(i=>i.id===N)??null,[N,m]),O=i=>y[i]??k[i]??J,R=b?O(b.id):null,a=x.useMemo(()=>m.filter(i=>!We(O(i.id),k[i.id])).map(i=>i.id),[m,y,k]),S=x.useMemo(()=>new Set(a),[a]),P=i=>{b&&u(c=>{const _=c[b.id]??k[b.id]??J;return{...c,[b.id]:{..._,...i}}})},w=()=>{b&&u(i=>({...i,[b.id]:k[b.id]??J}))},o=()=>{if(!R||m.length===0)return;const i={...R,customRunInstructions:R.customRunInstructions.trim().slice(0,4e3)};u(c=>{const _={...c};for(const D of m)_[D.id]={...i};return _}),h("Applied active agent settings to all agents."),j(null)},U=()=>{const i={};for(const c of m)i[c.id]=k[c.id]??J;u(i),h(null),j(null)},I=async()=>{var i;if(!(a.length===0||s.isSavingRuntimeSettings)){h(null),j(null);try{for(const c of a){if(!oe(c)){const D=((i=m.find(X=>X.id===c))==null?void 0:i.name)??c;throw new Error(`Cannot save "${D}" because it is not linked to a valid OrgX agent UUID yet. Re-sync Agent Suite and try again.`)}const _=O(c);await s.saveRuntimeSettingsAsync({projectId:s.runtimeSettings.projectId,agentId:c,runtimeSettings:{..._,customRunInstructions:_.customRunInstructions.trim().slice(0,4e3)}})}h(`Saved runtime settings for ${a.length} ${a.length===1?"agent":"agents"}.`),j(null)}catch(c){j(c instanceof Error?c.message:"Failed to save agent settings.")}}},C=((W=s.runtimeSettingsError)==null?void 0:W.trim())??null,T=!!C,G=!!(C&&(C.toLowerCase().includes("endpoint is not available")||C.includes("(404)"))),L=T;if(s.isLoading)return e.jsx("section",{className:"rounded-xl border border-subtle bg-white/[0.02] p-4",children:e.jsx("p",{className:"text-body text-secondary",children:"Loading agent settings..."})});if(s.error&&!s.status)return e.jsxs("section",{className:"rounded-xl border border-rose-300/25 bg-rose-400/10 p-4",children:[e.jsx("h3",{className:"text-body font-semibold text-rose-100",children:"Unable to load agent settings"}),e.jsx("p",{className:"mt-1 text-caption leading-relaxed text-rose-100/85",children:s.error})]});if(m.length===0||!b||!R)return e.jsxs("section",{className:"rounded-xl border border-subtle bg-white/[0.02] p-4",children:[e.jsx("h3",{className:"text-body font-semibold text-primary",children:"No agents configured"}),e.jsx("p",{className:"mt-1 text-caption leading-relaxed text-secondary",children:"Install the agent suite first, then runtime settings will appear here."})]});const $=a.length,z=S.has(b.id),K=b.domain?fe[b.domain]:"Agent";return e.jsxs("section",{className:"space-y-4",children:[e.jsx("header",{className:"rounded-xl border border-subtle bg-white/[0.02] p-4",children:e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-heading font-semibold text-white",children:"Agent runtime settings"}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:L?G?"Viewing agent suite roster. Runtime configuration requires a plugin rebuild.":"Viewing agent suite roster. Runtime configuration is temporarily unavailable.":"Configure decision guardrails and persistent run instructions per agent."})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("span",{className:"rounded-full border border-white/[0.10] bg-white/[0.03] px-3 py-1 text-caption text-primary",children:[m.length," agents"]}),!L&&e.jsxs("span",{className:F("rounded-full border px-3 py-1 text-caption",$>0?"border-lime/25 bg-lime/[0.12] text-lime":"border-white/[0.10] bg-white/[0.03] text-secondary"),children:[$," unsaved"]})]})]})}),L&&e.jsx("div",{className:"rounded-xl border border-amber-300/20 bg-[#12100A]/95 px-4 py-3",children:G?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-caption font-medium text-amber-100",children:"Runtime settings endpoint is not available in the running plugin build."}),e.jsx("p",{className:"mt-1 text-caption text-amber-100/70",children:"Rebuild the plugin server to enable per-agent configuration. Agent roster is shown below."})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-caption font-medium text-amber-100",children:"Runtime settings could not be loaded from the OrgX API."}),e.jsx("p",{className:"mt-1 text-caption text-amber-100/70",children:C})]})}),e.jsxs("div",{className:"grid gap-4 lg:grid-cols-[280px_minmax(0,1fr)]",children:[e.jsx("aside",{className:"rounded-xl border border-subtle bg-white/[0.02] p-2",children:e.jsx("div",{className:"max-h-[520px] space-y-1 overflow-y-auto pr-1",children:m.map(i=>{const c=i.id===b.id,_=S.has(i.id),D=oe(i.id);return e.jsxs("button",{type:"button",onClick:()=>g(i.id),className:F("w-full rounded-lg border px-3 py-2 text-left transition-colors",c?"border-lime/25 bg-lime/[0.12]":"border-white/[0.08] bg-black/20 hover:bg-white/[0.04]"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"truncate text-body font-semibold text-primary",children:i.name}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[D?null:e.jsx("span",{className:"rounded-full border border-amber-300/25 bg-amber-400/[0.16] px-1.5 py-0.5 text-micro uppercase tracking-[0.08em] text-amber-100",children:"Not linked"}),i.configStatus?e.jsx(Xe,{status:i.configStatus}):null]})]}),e.jsxs("div",{className:"mt-1 flex items-center justify-between gap-2",children:[e.jsx("p",{className:"truncate text-caption text-secondary",children:i.domain?fe[i.domain]:i.model??"Agent"}),_?e.jsx("span",{className:"rounded-full border border-lime/25 bg-lime/[0.10] px-1.5 py-0.5 text-micro uppercase tracking-[0.08em] text-lime",children:"Draft"}):null]})]},i.id)})})}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("article",{className:"rounded-xl border border-subtle bg-white/[0.02] p-4",children:e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-caption uppercase tracking-[0.08em] text-secondary",children:K}),e.jsx("h4",{className:"mt-1 text-heading font-semibold text-white",children:b.name}),oe(b.id)?null:e.jsx("p",{className:"mt-1 text-caption text-amber-100/85",children:"This agent is not linked to a runtime UUID yet. Apply Agent Suite sync before saving."})]}),!L&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",onClick:o,className:"min-h-[44px] rounded-full border border-white/[0.14] bg-white/[0.03] px-3 py-2 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.06]",children:"Apply to all"}),e.jsx("button",{type:"button",onClick:w,disabled:!z,className:"min-h-[44px] rounded-full border border-white/[0.14] bg-white/[0.03] px-3 py-2 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.06] disabled:cursor-not-allowed disabled:opacity-50",children:"Reset active"})]})]})}),e.jsxs("div",{className:L?"pointer-events-none opacity-40":"",children:[e.jsxs("article",{className:"rounded-xl border border-subtle bg-white/[0.02] p-4",children:[e.jsx("h4",{className:"text-body font-semibold text-primary",children:"Decision pipeline"}),e.jsx("p",{className:"mt-1 text-caption leading-relaxed text-secondary",children:"These controls are injected into dispatch and decision flows for this agent."}),e.jsxs("div",{className:"mt-3 space-y-2",children:[e.jsx(ne,{label:"Decision envelope v2",description:"Emit richer context fields for diagnosis and replay.",enabled:R.decisionV2Enabled,onToggle:i=>P({decisionV2Enabled:i})}),e.jsx(ne,{label:"Decision dedupe",description:"Collapse repeated blockers into the same pending decision.",enabled:R.decisionDedupeEnabled,onToggle:i=>P({decisionDedupeEnabled:i})}),e.jsx(ne,{label:"Require evidence for blocking decisions",description:"Attach evidence before a blocking decision can be emitted.",enabled:R.decisionEvidenceRequiredForBlocking,onToggle:i=>P({decisionEvidenceRequiredForBlocking:i})}),e.jsx(ne,{label:"Guarded auto-resolve",description:"Attempt deterministic remediation before escalating to humans.",enabled:R.decisionAutoResolveGuardedEnabled,onToggle:i=>P({decisionAutoResolveGuardedEnabled:i})})]})]}),e.jsxs("article",{className:"mt-3 rounded-xl border border-subtle bg-white/[0.02] p-4",children:[e.jsx("h4",{className:"text-body font-semibold text-primary",children:"Persistent run instructions"}),e.jsx("p",{className:"mt-1 text-caption leading-relaxed text-secondary",children:"Injected into every run for this agent as runtime guidance."}),e.jsx("textarea",{value:R.customRunInstructions,onChange:i=>P({customRunInstructions:i.target.value.slice(0,4e3)}),rows:7,placeholder:"Add concise constraints, workflow defaults, and handoff requirements.",className:"mt-3 w-full rounded-xl border border-white/[0.12] bg-black/25 px-3 py-2 text-body text-primary outline-none transition-colors placeholder:text-muted focus:border-lime/35"}),e.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-caption text-secondary",children:"Keep instructions explicit and operational, not aspirational."}),e.jsxs("p",{className:"text-micro uppercase tracking-[0.08em] text-secondary",children:[R.customRunInstructions.trim().length,"/4000"]})]})]})]})]})]}),e.jsx("div",{className:F("sticky bottom-0 z-10 rounded-xl border border-subtle bg-[#08090d]/90 p-3 backdrop-blur",L&&"hidden"),children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("div",{className:"min-h-[20px]",children:A?e.jsx("p",{className:"text-caption text-rose-100",children:A}):E?e.jsx("p",{className:"text-caption text-lime",children:E}):e.jsx("p",{className:"text-caption text-secondary",children:$>0?`${$} ${$===1?"agent has":"agents have"} unsaved changes.`:"All agent runtime settings are saved."})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:U,disabled:$===0||s.isSavingRuntimeSettings,className:"min-h-[44px] rounded-lg border border-white/[0.14] px-3 py-2 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.06] disabled:cursor-not-allowed disabled:opacity-50",children:"Discard all"}),e.jsx("button",{type:"button",onClick:()=>{I()},disabled:$===0||s.isSavingRuntimeSettings,className:"min-h-[44px] rounded-lg border border-lime/30 bg-lime/[0.14] px-3 py-2 text-caption font-semibold text-lime transition-colors hover:bg-lime/[0.2] disabled:cursor-not-allowed disabled:opacity-50",children:s.isSavingRuntimeSettings?"Saving...":"Save changes"})]})]})})]})}function Ye({authToken:t=null,embedMode:n=!1,enabled:l=!0}={}){var v;const p=x.useMemo(()=>["usage-control-plane",{authToken:t,embedMode:n}],[t,n]),s=se({queryKey:p,enabled:l,queryFn:async()=>{const f=await fetch("/orgx/api/usage/control-plane/summary",{headers:Q({authToken:t,embedMode:n})}),d=await f.json().catch(()=>null);if(!f.ok){const m=(d&&typeof d=="object"&&"error"in d&&typeof d.error=="string"?d.error:null)??(d&&typeof d=="object"&&"message"in d&&typeof d.message=="string"?d.message:null)??`Failed to load usage summary (${f.status})`;throw new Error(m)}if(!d||typeof d!="object"||!("generatedAt"in d))throw new Error("Usage summary response is missing required fields.");return d},refetchInterval:6e4});return{summary:s.data??null,isLoading:s.isLoading,isFetching:s.isFetching,error:((v=s.error)==null?void 0:v.message)??null,refetch:s.refetch}}function V(t){return new Intl.NumberFormat("en-US").format(Math.max(0,Math.round(t)))}function le(t){return`$${(Math.max(0,t)/100).toFixed(2)}`}function ce(t){return typeof t!="number"||!Number.isFinite(t)?"—":`${Math.max(0,Math.round(t))}%`}function Ze(t){return t==="over_limit"?"border-rose-300/30 bg-rose-400/12 text-rose-100":t==="at_risk"?"border-amber-300/30 bg-amber-400/12 text-amber-100":t==="watch"?"border-teal-300/25 bg-teal-400/10 text-teal-100":"border-lime/30 bg-lime/[0.14] text-[#D8FFA1]"}function je(t,n=4){return!Array.isArray(t)||t.length===0?[]:[...t].sort((l,p)=>p.tokens-l.tokens).slice(0,n)}function et(t){const n=Date.parse(t.generatedAt);if(!Number.isFinite(n))return"Updated just now";const l=Math.max(0,Math.round((Date.now()-n)/6e4));return l<1?"Updated just now":l<60?`Updated ${l}m ago`:`Updated ${Math.round(l/60)}h ago`}function tt({authToken:t=null,embedMode:n=!1,enabled:l=!0}){const p=Ye({authToken:t,embedMode:n,enabled:l}),s=p.summary;return e.jsxs("div",{className:"rounded-2xl border border-white/[0.07] bg-white/[0.02] p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-heading font-semibold text-white",children:"Usage control plane"}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:"Actual vs predicted token, runtime, and cost usage for this billing period."})]}),e.jsx("button",{type:"button",onClick:()=>void p.refetch(),disabled:p.isFetching,className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.07] disabled:cursor-not-allowed disabled:opacity-50",children:p.isFetching?"Refreshing…":"Refresh"})]}),p.error?e.jsx("div",{className:"mt-3 rounded-xl border border-rose-300/25 bg-rose-400/10 px-3 py-2.5 text-body text-rose-100",children:p.error}):null,!s&&p.isLoading?e.jsx("div",{className:"mt-3 grid gap-2 sm:grid-cols-2 lg:grid-cols-4",children:Array.from({length:4}).map((v,f)=>e.jsx("div",{className:"h-[92px] animate-pulse rounded-xl border border-white/[0.08] bg-white/[0.03]"},`usage-loading-${f}`))}):null,s?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:F("rounded-full border px-2.5 py-1 text-caption font-semibold",Ze(s.risk)),children:s.risk.replace("_"," ")}),e.jsx("span",{className:"chip",children:s.plan.name}),s.source?e.jsxs("span",{className:"chip",children:["source: ",s.source]}):null,e.jsx("span",{className:"text-caption text-muted",children:et(s)})]}),e.jsxs("div",{className:"mt-3 grid gap-2 sm:grid-cols-2 lg:grid-cols-4",children:[e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-black/20 px-3 py-2.5",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Agent runs"}),e.jsxs("p",{className:"mt-1 text-heading font-semibold text-white",children:[V(s.actual.agentRuns),e.jsxs("span",{className:"ml-1 text-caption text-secondary",children:["/ ",s.plan.agentRunsLimit>0?V(s.plan.agentRunsLimit):"∞"]})]}),e.jsxs("p",{className:"mt-1 text-caption text-muted",children:["Forecast ",V(s.predicted.agentRuns)]})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-black/20 px-3 py-2.5",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Agent minutes"}),e.jsxs("p",{className:"mt-1 text-heading font-semibold text-white",children:[V(s.actual.agentMinutes),e.jsxs("span",{className:"ml-1 text-caption text-secondary",children:["/ ",s.plan.agentMinutesLimit>0?V(s.plan.agentMinutesLimit):"∞"]})]}),e.jsxs("p",{className:"mt-1 text-caption text-muted",children:["Forecast ",V(s.predicted.agentMinutes)]})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-black/20 px-3 py-2.5",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Tokens"}),e.jsx("p",{className:"mt-1 text-heading font-semibold text-white",children:V(s.actual.tokens)}),e.jsxs("p",{className:"mt-1 text-caption text-muted",children:["Forecast ",V(s.predicted.tokens)]})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-black/20 px-3 py-2.5",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.12em] text-muted",children:"Spend"}),e.jsxs("p",{className:"mt-1 text-heading font-semibold text-white",children:[le(s.actual.costCents),e.jsxs("span",{className:"ml-1 text-caption text-secondary",children:["/ ",s.plan.includedBudgetCents>0?le(s.plan.includedBudgetCents):"—"]})]}),e.jsxs("p",{className:"mt-1 text-caption text-muted",children:["Forecast ",le(s.predicted.costCents)]})]})]}),e.jsxs("div",{className:"mt-3 grid gap-2 sm:grid-cols-3",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-muted",children:"Run utilization"}),e.jsx("p",{className:"mt-1 text-caption font-semibold text-primary",children:ce(s.utilization.runsPct)})]}),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-muted",children:"Minute utilization"}),e.jsx("p",{className:"mt-1 text-caption font-semibold text-primary",children:ce(s.utilization.minutesPct)})]}),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-muted",children:"Budget utilization"}),e.jsx("p",{className:"mt-1 text-caption font-semibold text-primary",children:ce(s.utilization.budgetPct)})]})]}),je(s.breakdown.sourceClient,4).length>0?e.jsxs("div",{className:"mt-3 rounded-xl border border-white/[0.08] bg-black/20 p-3",children:[e.jsx("p",{className:"text-caption font-semibold text-primary",children:"Runtime client mix"}),e.jsx("div",{className:"mt-2 space-y-2",children:je(s.breakdown.sourceClient,4).map(v=>{const f=s.actual.tokens>0?Math.max(0,Math.min(100,Math.round(v.tokens/s.actual.tokens*100))):0;return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-caption text-secondary",children:v.label}),e.jsxs("span",{className:"text-caption text-primary",children:[V(v.tokens)," tokens · ",V(v.runs)," runs"]})]}),e.jsx("div",{className:"h-1.5 rounded-full bg-white/[0.08]",children:e.jsx("div",{className:"h-1.5 rounded-full bg-lime/80 transition-all",style:{width:`${Math.max(6,f)}%`}})})]},`usage-source-${v.key}`)})})]}):null,Array.isArray(s.warnings)&&s.warnings.length>0?e.jsxs("div",{className:"mt-3 rounded-xl border border-amber-300/25 bg-amber-400/10 px-3 py-2.5",children:[e.jsx("p",{className:"text-caption font-semibold text-amber-100",children:"Usage warnings"}),e.jsx("ul",{className:"mt-1 space-y-1",children:s.warnings.slice(0,3).map((v,f)=>e.jsxs("li",{className:"text-caption text-amber-100/90",children:["• ",v]},`usage-warning-${f}`))})]}):null]}):null]})}function st({connectionPhase:t,workspaceName:n}){const{displayName:l,avatarSeed:p,updateName:s,regenerateAvatar:v}=Re(),[f,d]=x.useState(!1),[m,k]=x.useState(""),N=x.useRef(null),g=x.useCallback(()=>{k(l),d(!0),requestAnimationFrame(()=>{var j;return(j=N.current)==null?void 0:j.focus()})},[l]),y=x.useCallback(()=>{s(m),d(!1)},[m,s]),u=x.useCallback(()=>{d(!1)},[]),E=x.useCallback(j=>{j.key==="Enter"?y():j.key==="Escape"&&u()},[y,u]),h=t==="connected",A=h?`Connected${n?` to ${n}`:""}`:t==="connecting"?"Connecting...":t==="error"?"Connection error":"Not connected";return e.jsx("div",{className:"rounded-2xl border border-white/[0.07] bg-white/[0.02] p-5",children:e.jsxs("div",{className:"flex items-center gap-5",children:[e.jsx(ve,{mode:"wait",children:e.jsx(te.div,{initial:{opacity:0,scale:.9},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.9},transition:{duration:.3,ease:Ne.easingEntrance},children:e.jsx(Pe,{seed:p,size:80})},p)}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Your identity"}),f?e.jsxs("div",{className:"mt-1.5 flex items-center gap-2",children:[e.jsx("input",{ref:N,type:"text",value:m,onChange:j=>k(j.target.value),onKeyDown:E,maxLength:64,placeholder:"Enter your name",className:"h-8 flex-1 rounded-lg border border-white/[0.12] bg-white/[0.04] px-2.5 text-heading font-semibold text-white placeholder:text-muted focus:border-lime/30 focus:outline-none"}),e.jsx("button",{type:"button",onClick:y,className:"rounded-lg bg-lime/[0.12] px-3 py-1.5 text-caption font-medium text-lime transition hover:bg-lime/[0.2]",children:"Save"}),e.jsx("button",{type:"button",onClick:u,className:"rounded-lg px-3 py-1.5 text-caption text-secondary transition hover:bg-white/[0.04]",children:"Cancel"})]}):e.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[e.jsx("h4",{className:"text-heading font-semibold text-white",children:l||"Anonymous"}),e.jsx("button",{type:"button",onClick:g,className:"rounded-md px-2 py-0.5 text-caption text-secondary transition hover:bg-white/[0.06] hover:text-white",children:l?"Edit":"Add name"})]}),e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("span",{className:"relative flex h-2 w-2",children:e.jsx("span",{className:F("relative inline-flex h-2 w-2 rounded-full",h?"bg-lime":t==="error"?"bg-red-400":"bg-white/30")})}),e.jsx("span",{className:"text-caption text-secondary",children:A})]}),e.jsx("button",{type:"button",onClick:v,className:"mt-3 rounded-lg border border-white/[0.08] bg-white/[0.02] px-3 py-1.5 text-caption text-secondary transition hover:bg-white/[0.06] hover:text-white",children:"Regenerate avatar"})]})]})})}function de({label:t,description:n,enabled:l,onToggle:p}){return e.jsxs("div",{className:"flex items-start justify-between gap-6 py-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-body font-medium text-white",children:t}),e.jsx("p",{className:"mt-0.5 text-caption leading-relaxed text-secondary",children:n})]}),e.jsx("button",{type:"button",role:"switch","aria-checked":l,onClick:()=>p(!l),className:F("relative inline-flex h-[22px] w-[38px] flex-shrink-0 rounded-full border transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-lime/50",l?"border-lime/30 bg-lime/[0.15]":"border-white/[0.12] bg-white/[0.04] hover:bg-white/[0.08]"),children:e.jsx("span",{"aria-hidden":"true",className:F("absolute top-[1px] h-[18px] w-[18px] rounded-full shadow-sm transition-all",l?"left-[17px] bg-lime shadow-[0_0_8px_rgba(191,255,0,0.4)]":"left-[1px] bg-secondary")})})]})}function lt({open:t,onClose:n,activeTab:l,onChangeTab:p,demoMode:s,onToggleDemoMode:v,devMode:f=!1,onToggleDevMode:d,showSyntheticEntities:m,onToggleShowSyntheticEntities:k,workspaceOptions:N,selectedWorkspaceId:g,onSelectWorkspace:y,onboarding:u,authToken:E=null,embedMode:h=!1,agentBehaviorInitialDomain:A=null}){return e.jsx(Fe,{open:t,onClose:n,maxWidth:"max-w-4xl",closeOnBackdropClick:!1,closeOnEscapeWhenTyping:!1,children:e.jsxs("div",{className:"flex h-full min-h-0 w-full min-w-0 flex-1 flex-col",children:[e.jsxs("div",{className:"w-full pt-6 px-5 sm:px-8",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-title font-medium text-white",children:"Settings"}),e.jsx("p",{className:"mt-1.5 text-body text-secondary",children:"Profile, OrgX connection, agent behavior, and provider keys."})]}),e.jsx("button",{type:"button",onClick:n,"aria-label":"Close settings",className:"inline-flex h-8 w-8 items-center justify-center rounded-full text-secondary transition-colors hover:bg-white/[0.06] hover:text-white focus:outline-none focus-visible:bg-white/[0.06]",children:e.jsxs("svg",{width:"15",height:"15",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.jsx("div",{className:"mt-6 flex items-center gap-6 border-b border-white/[0.06]",role:"tablist","aria-label":"Settings tabs",children:[{id:"orgx",label:"OrgX"},{id:"agents",label:"Agents"},{id:"providers",label:"Provider keys"}].map(j=>{const b=l===j.id;return e.jsxs("button",{type:"button",role:"tab","aria-selected":b,onClick:()=>p(j.id),className:F("relative pb-3 text-caption font-medium transition-colors focus:outline-none",b?"text-white":"text-secondary hover:text-primary"),children:[j.label,b&&e.jsx(te.span,{layoutId:"settings-tab-indicator",className:"absolute bottom-0 left-0 right-0 h-px bg-white shadow-[0_0_8px_rgba(255,255,255,0.4)]","aria-hidden":"true",transition:{duration:.22,ease:Ne.easingStandard}})]},j.id)})})]}),e.jsx("div",{className:"min-h-0 w-full flex-1 overflow-y-auto px-5 py-6 sm:px-8",children:e.jsx(ve,{mode:"wait",children:l==="orgx"?e.jsxs(te.div,{...ie,className:"grid gap-12",children:[e.jsx(st,{connectionPhase:u.state.status==="connected"?"connected":u.state.status==="error"?"error":u.state.status==="starting"||u.state.status==="awaiting_browser_auth"||u.state.status==="pairing"?"connecting":"idle",workspaceName:u.state.workspaceName}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-heading font-semibold text-white",children:"Developer tools"}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:"Toggle debug features and synthetic data."}),e.jsxs("div",{className:"mt-4 grid gap-1 border-t border-white/[0.04] pt-2",children:[e.jsx(de,{label:"Developer mode",description:"Show technical details, config paths, and raw data in session inspectors.",enabled:f,onToggle:j=>d==null?void 0:d(j)}),e.jsx("div",{className:F("border-t border-white/[0.04]",f?"":"pointer-events-none opacity-40"),children:e.jsx(de,{label:"Demo mode",description:"Load local demo data for walkthroughs.",enabled:s,onToggle:v})}),e.jsx("div",{className:F("border-t border-white/[0.04]",f?"":"pointer-events-none opacity-40"),children:e.jsx(de,{label:"Show synthetic entities",description:"Include QA/test initiative IDs in the agent column.",enabled:m,onToggle:k})})]})]}),e.jsx(De,{state:u.state,isStarting:u.isStarting,isSubmittingManual:u.isSubmittingManual,workspaceOptions:N,selectedWorkspaceId:g,onSelectWorkspace:y,onRefresh:u.refreshStatus,onStartPairing:u.startPairing,onSubmitManualKey:u.submitManualKey,onBackToPairing:u.backToPairing,onUseManualKey:u.setManualMode,onDisconnect:u.disconnect}),e.jsx(qe,{authToken:E,embedMode:h,enabled:t&&!s,devMode:f}),e.jsx(tt,{authToken:E,embedMode:h,enabled:t&&!s})]},"orgx"):l==="agents"?e.jsx(te.div,{...ie,children:e.jsx(Je,{authToken:E,embedMode:h,enabled:t&&!s,initialDomain:A})},"agents"):e.jsx(te.div,{...ie,children:e.jsx(Qe,{authToken:E,embedMode:h,enabled:t&&!s})},"providers")})}),e.jsx("div",{className:"w-full border-t border-subtle px-5 py-2.5 sm:px-6",children:e.jsx(Ee,{compact:!0})})]})})}export{lt as SettingsModal};
@@ -1,8 +0,0 @@
1
- import{r as x,a as J,j as e}from"./cNrhgGc1.js";import{k as K,q as Y,r as Z,_ as q,d as c,R as O,b as X}from"./D-bf6hEI.js";import{S as C}from"./nByHNHoW.js";import{m as b,A as H}from"./CxQ08qFN.js";import"./C-KIc3Wc.js";import"./BJgZIVUQ.js";const M=15,L={draft:c.textMuted,in_review:c.amber,approved:c.lime,changes_requested:c.red,superseded:c.textMuted,archived:c.textMuted},Q={draft:"Draft",in_review:"In Review",approved:"Approved",changes_requested:"Changes Requested",superseded:"Superseded",archived:"Archived"},G={type:"spring",stiffness:O.easingSpring.stiffness,damping:O.easingSpring.damping};function ee(a,n,l){var o;if(n){const r=n.toLowerCase();if(r.includes("typescript")||r.includes(".ts")||r.includes("javascript")||r.includes(".js"))return"typescript";if(r.includes("json")||r.includes("schema"))return"json";if(r.includes("yaml")||r.includes("yml"))return"yaml";if(r.includes("markdown")||r.includes(".md"))return"markdown"}if(l){const r=(o=l.split(".").pop())==null?void 0:o.toLowerCase();if(r==="ts"||r==="tsx"||r==="js"||r==="jsx")return"typescript";if(r==="json")return"json";if(r==="yaml"||r==="yml")return"yaml";if(r==="md"||r==="mdx")return"markdown"}const s=a.trimStart();return s.startsWith("{")||s.startsWith("[")?"json":s.startsWith("---")?"yaml":s.startsWith("#")&&/^#{1,6}\s/.test(s)?"markdown":/\b(import|export|const|function|interface|type)\b/.test(s.slice(0,500))?"typescript":/^[\w-]+:\s/m.test(s.slice(0,500))?"yaml":"plain"}const te=new Set(["const","let","var","function","return","if","else","for","while","import","export","from","class","interface","type","extends","implements","new","this","super","async","await","try","catch","finally","throw","default","switch","case","break","continue","do","of","in","typeof","instanceof","void","null","undefined","true","false","as","is"]);function ne(a){const n=[],l=/("(?:[^"\\]|\\.)*")\s*(:)?|(-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)|(\btrue\b|\bfalse\b)|(\bnull\b)|([{}[\],])|(\s+)|([^\s"{}[\],:]+)/g;let s;for(;(s=l.exec(a))!==null;)s[1]?(n.push({type:s[2]?"key":"string",value:s[1]}),s[2]&&n.push({type:"punctuation",value:":"})):s[3]?n.push({type:"number",value:s[3]}):s[4]?n.push({type:"boolean",value:s[4]}):s[5]?n.push({type:"null",value:s[5]}):s[6]?n.push({type:"punctuation",value:s[6]}):n.push({type:"plain",value:s[0]});return n}function se(a){const n=[],l=a.split(`
2
- `);for(let s=0;s<l.length;s++){s>0&&n.push({type:"plain",value:`
3
- `});const o=l[s];if(o.trimStart().startsWith("#")){n.push({type:"comment",value:o});continue}const r=o.match(/^(\s*)([\w.-]+)(\s*:\s*)(.*)/);if(r){r[1]&&n.push({type:"plain",value:r[1]}),n.push({type:"key",value:r[2]}),n.push({type:"punctuation",value:r[3]});const i=r[4];/^(true|false|yes|no|on|off)$/i.test(i.trim())?n.push({type:"boolean",value:i}):/^-?\d+(\.\d+)?$/.test(i.trim())?n.push({type:"number",value:i}):/^['"]/.test(i.trim())?n.push({type:"string",value:i}):i.trim()==="null"||i.trim()==="~"?n.push({type:"null",value:i}):n.push({type:"string",value:i})}else n.push({type:"plain",value:o})}return n}function ae(a){const n=[],l=/(\/\/[^\n]*|\/\*[\s\S]*?\*\/)|(`(?:[^`\\]|\\.)*`|"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*')|(-?\b\d+(?:\.\d+)?(?:[eE][+-]?\d+)?\b)|(\b[a-zA-Z_$][\w$]*\b)|([{}()[\];,.:?!<>=+\-*/&|^~%@#]+)|(\s+)/g;let s;for(;(s=l.exec(a))!==null;)s[1]?n.push({type:"comment",value:s[1]}):s[2]?n.push({type:"string",value:s[2]}):s[3]?n.push({type:"number",value:s[3]}):s[4]?te.has(s[4])?n.push({type:"keyword",value:s[4]}):s[4]==="true"||s[4]==="false"?n.push({type:"boolean",value:s[4]}):n.push({type:"plain",value:s[4]}):s[5]?n.push({type:"punctuation",value:s[5]}):n.push({type:"plain",value:s[0]});return n}function re(a){const n=[],l=a.split(`
4
- `);for(let s=0;s<l.length;s++){s>0&&n.push({type:"plain",value:`
5
- `});const o=l[s];if(/^#{1,6}\s/.test(o))n.push({type:"heading",value:o});else if(/^```/.test(o.trimStart()))n.push({type:"code",value:o});else{const r=/(\*\*[^*]+\*\*)|(\*[^*]+\*)|(`[^`]+`)|(https?:\/\/[^\s)]+)|(\[[^\]]*\]\([^)]*\))|([^*`[\]]+)/g;let i;for(;(i=r.exec(o))!==null;)i[1]?n.push({type:"bold",value:i[1]}):i[2]?n.push({type:"italic",value:i[2]}):i[3]?n.push({type:"code",value:i[3]}):i[4]?n.push({type:"link",value:i[4]}):i[5]?n.push({type:"link",value:i[5]}):n.push({type:"plain",value:i[0]})}}return n}function ie(a,n){switch(n){case"json":return ne(a);case"yaml":return se(a);case"typescript":return ae(a);case"markdown":return re(a);default:return[{type:"plain",value:a}]}}function oe(a,n){const l=n||c.lime;switch(a){case"keyword":return l;case"key":return l;case"string":return c.teal;case"number":return c.amber;case"boolean":return c.amber;case"null":return c.red;case"comment":return"rgba(255,255,255,0.40)";case"punctuation":return"rgba(255,255,255,0.60)";case"heading":return c.iris;case"bold":return c.text;case"italic":return"rgba(255,255,255,0.75)";case"code":return c.cyan;case"link":return c.cyan;case"plain":default:return"rgba(255,255,255,0.85)"}}function le(a){if(a==="keyword"||a==="heading"||a==="bold"||a==="key")return 600}function ce(a){if(a==="italic"||a==="comment")return"italic"}function de({code:a,language:n,agentColor:l,maxLines:s,expanded:o}){const r=a.split(`
6
- `),i=!o&&s!=null&&r.length>s,h=i?r.slice(0,s).join(`
7
- `):a,N=x.useMemo(()=>ie(h,n),[h,n]);return e.jsxs("div",{className:"relative",children:[e.jsx("pre",{className:"font-mono text-[13px] leading-relaxed overflow-x-auto p-4 m-0 whitespace-pre-wrap break-words",children:e.jsx("code",{children:N.map((f,w)=>e.jsx("span",{style:{color:oe(f.type,l),fontWeight:le(f.type),fontStyle:ce(f.type)},children:f.value},w))})}),i&&e.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-16 bg-gradient-to-t from-[#08090D] to-transparent"})]})}function V({text:a}){const[n,l]=x.useState(!1),s=x.useCallback(async()=>{try{await navigator.clipboard.writeText(a),l(!0)}catch{}},[a]);return x.useEffect(()=>{if(!n)return;const o=window.setTimeout(()=>l(!1),2e3);return()=>window.clearTimeout(o)},[n]),e.jsxs("button",{type:"button",onClick:s,className:"relative flex items-center gap-1.5 rounded-lg border border-white/[0.08] bg-white/[0.04] px-2.5 py-1.5 text-micro font-medium text-secondary transition-colors hover:bg-white/[0.08] hover:text-white",title:"Copy content",children:[e.jsx("div",{className:"relative h-3.5 w-3.5",children:e.jsx(H,{mode:"wait",initial:!1,children:n?e.jsx(b.svg,{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:c.lime,strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",initial:{opacity:0,scale:.5},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.5},transition:{duration:.3,ease:[.16,1,.3,1]},className:"absolute inset-0",children:e.jsx(b.path,{d:"M20 6 9 17l-5-5",initial:{pathLength:0},animate:{pathLength:1},transition:{duration:.3,ease:[.16,1,.3,1]}})},"check"):e.jsxs(b.svg,{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",initial:{opacity:0,scale:.5},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.5},transition:{duration:.15},className:"absolute inset-0",children:[e.jsx("rect",{width:"14",height:"14",x:"8",y:"8",rx:"2"}),e.jsx("path",{d:"M16 8V6a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v8a2 2 0 0 0 2 2h2"})]},"copy")})}),e.jsx(H,{mode:"wait",initial:!1,children:n?e.jsx(b.span,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},transition:{duration:.15},style:{color:c.lime},children:"Copied"},"label-copied"):e.jsx(b.span,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},transition:{duration:.15},children:"Copy"},"label-copy")})]})}function ue(){return e.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:c.cyan,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"}),e.jsx("path",{d:"M14 2v4a2 2 0 0 0 2 2h4"}),e.jsx("path",{d:"M10 9H8"}),e.jsx("path",{d:"M16 13H8"}),e.jsx("path",{d:"M16 17H8"})]})}function pe({metadata:a,agentColor:n,createdAt:l}){const s=typeof a.agent_name=="string"&&a.agent_name||typeof a.agent=="string"&&a.agent||typeof a.produced_by=="string"&&a.produced_by||null,o=typeof a.task_id=="string"&&a.task_id||typeof a.run_ref=="string"&&a.run_ref||typeof a.queue_ref=="string"&&a.queue_ref||null;return!s&&!o?null:e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-micro text-faint",children:[s&&e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"inline-block h-2 w-2 rounded-full",style:{backgroundColor:n||c.textMuted}}),e.jsx("span",{className:"font-medium",style:{color:n||c.textMuted},children:s})]}),o&&e.jsx("span",{className:"truncate max-w-[200px] opacity-70",title:o,children:o.length>20?`${o.slice(0,8)}...`:o}),e.jsx("span",{className:"opacity-60",children:new Date(l).toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"})})]})}function be(){var E,T,$,D,I,R;const{state:a,close:n,setContentMeta:l}=K(),s=null,o=!1,[r,i]=x.useState(!1);x.useEffect(()=>{i(!1)},[a.artifactId]);const{data:h,isLoading:N,isFetching:f,error:w,refetch:P}=J({queryKey:Y.artifactDetail({artifactId:a.artifactId??"",authToken:s,embedMode:o}),enabled:!!a.artifactId,queryFn:async()=>{const u=X({authToken:s,embedMode:o}),p=await fetch(`/orgx/api/artifacts/${encodeURIComponent(a.artifactId)}`,{headers:u});if(!p.ok){const m=await p.json().catch(()=>null),k=(typeof(m==null?void 0:m.error)=="string"?m.error:null)??(m!=null&&m.error&&typeof m.error=="object"&&typeof m.error.message=="string"?m.error.message:null)??(typeof(m==null?void 0:m.message)=="string"?m.message:null),U=p.status===401?"Authentication required to view this artifact.":`Failed to fetch artifact (${p.status}).`;throw new Error(k!=null&&k.trim().length?k.trim():U)}return p.json()}}),t=h==null?void 0:h.artifact,d=x.useMemo(()=>{if(a.contentBlob)return a.contentBlob;if(!(t!=null&&t.metadata))return null;const u=[t.metadata.content,t.metadata.body,t.metadata.code,t.metadata.source,t.metadata.text,t.metadata.preview_markdown];for(const p of u)if(typeof p=="string"&&p.trim().length>0)return p;if(t.metadata.output&&typeof t.metadata.output=="object")try{return JSON.stringify(t.metadata.output,null,2)}catch{}return null},[t==null?void 0:t.metadata,a.contentBlob]),y=x.useMemo(()=>a.detectedLanguage?a.detectedLanguage:d?ee(d,t==null?void 0:t.artifact_type,t==null?void 0:t.name):"plain",[d,t==null?void 0:t.artifact_type,t==null?void 0:t.name,a.detectedLanguage]),v=x.useMemo(()=>{if(a.agentColor)return a.agentColor;const u=t==null?void 0:t.metadata;if(!u)return null;const p=typeof u.agent_name=="string"&&u.agent_name||typeof u.agent=="string"&&u.agent||typeof u.produced_by=="string"&&u.produced_by||null;return p&&{Pace:"#7C7CFF",Eli:"#BFFF00",Dana:"#FF00D4",Mark:"#F5B700",System:"#14B8A6",Sage:"#0AD4C4",Orion:"#14B8A6",Xandy:"#FF6B88",Nova:"#A78BFA"}[p]||null},[t==null?void 0:t.metadata,a.agentColor]);x.useEffect(()=>{(d||y!=="plain"||v)&&l({contentBlob:d,detectedLanguage:y,agentColor:v})},[d,y,v,l]);const z=(h==null?void 0:h.localFallback)===!0||((E=t==null?void 0:t.metadata)==null?void 0:E.local_fallback)===!0,S=(typeof(h==null?void 0:h.warning)=="string"&&h.warning.trim().length>0?h.warning:(T=t==null?void 0:t.metadata)==null?void 0:T.local_warning)??null,_=(($=t==null?void 0:t.metadata)==null?void 0:$.preview_markdown)??null,g=x.useMemo(()=>{if(!(t!=null&&t.metadata))return null;const u=[t.metadata.local_source_path,t.metadata.url,t.metadata.path,t.metadata.file_path,t.metadata.filepath,t.metadata.artifact_path,t.metadata.output_path];for(const p of u)if(typeof p=="string"&&p.trim().length>0)return p.trim();return null},[t==null?void 0:t.metadata]),B=x.useMemo(()=>g?/^https?:\/\//i.test(g)?g:`/orgx/api/live/filesystem/open?path=${encodeURIComponent(g)}`:null,[g]),F=((D=t==null?void 0:t.metadata)==null?void 0:D.external_url)??(t==null?void 0:t.artifact_url),j=d?d.split(`
8
- `).length:0,W=j>M,A=x.useMemo(()=>({json:"JSON",yaml:"YAML",markdown:"Markdown",typescript:"TypeScript",plain:"Plain Text"})[y]||y,[y]);return e.jsxs(Z,{open:!!a.artifactId,onClose:n,maxWidth:"max-w-3xl",children:[N&&e.jsxs("div",{className:"p-6 space-y-4",children:[e.jsx(C,{className:"h-6 w-2/3"}),e.jsx(C,{className:"h-4 w-1/3"}),e.jsx(C,{className:"h-32 w-full"})]}),w&&e.jsxs("div",{className:"space-y-4 p-6",children:[e.jsxs("div",{className:"rounded-xl border border-red-300/22 bg-red-500/[0.08] p-4",children:[e.jsx("p",{className:"text-body font-semibold text-red-200",children:"Failed to load artifact"}),e.jsx("p",{className:"mt-1 text-caption leading-relaxed text-red-100/80",children:w.message})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",onClick:n,className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-primary transition-colors hover:bg-white/[0.08]",children:"Back to activity"}),e.jsx("button",{type:"button",onClick:()=>void P(),disabled:f,className:"rounded-full border border-red-300/22 bg-red-500/[0.08] px-3 py-1.5 text-caption font-semibold text-red-100 transition-colors hover:bg-red-500/[0.14] disabled:opacity-45",children:f?"Retrying...":"Retry"})]})]}),t&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-subtle px-5 py-4 sm:px-6",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx(ue,{}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"truncate text-sm font-medium text-white",children:t.name}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[e.jsx(q,{tone:"muted",className:"text-micro uppercase tracking-[0.06em]",children:((I=t.catalog)==null?void 0:I.label)??t.artifact_type}),e.jsx(q,{tone:"neutral",className:"text-micro font-semibold uppercase tracking-[0.06em]",style:{color:L[t.status]??c.textMuted,backgroundColor:`${L[t.status]??c.textMuted}20`,borderColor:`${L[t.status]??c.textMuted}44`},children:Q[t.status]??t.status}),d&&e.jsxs("span",{className:"text-micro text-faint",children:[A," · ",j," line",j!==1?"s":""]}),((R=t.catalog)==null?void 0:R.domain)&&e.jsxs("span",{className:"text-micro text-faint",children:[t.catalog.domain," / ",t.catalog.stage]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[d&&e.jsx(V,{text:d}),F&&e.jsx("a",{href:F,target:"_blank",rel:"noopener noreferrer",className:"rounded-lg p-2 text-secondary transition-colors hover:bg-white/[0.08] hover:text-white",title:"Open source",children:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M15 3h6v6"}),e.jsx("path",{d:"M10 14 21 3"}),e.jsx("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"})]})}),e.jsx("button",{onClick:n,className:"p-2 rounded-lg hover:bg-white/[0.06] text-secondary hover:text-white transition-colors",children:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"m6 6 12 12"})]})})]})]}),e.jsxs("div",{className:"max-h-[65vh] overflow-y-auto px-5 py-4 sm:px-6 space-y-4",children:[z&&e.jsxs("div",{className:"rounded-xl border border-amber-300/25 bg-amber-500/[0.09] p-4",children:[e.jsx("p",{className:"text-caption font-semibold uppercase tracking-[0.08em] text-amber-100/90",children:"Local fallback artifact"}),e.jsx("p",{className:"mt-1 text-body text-amber-50/90",children:"This artifact is buffered locally because OrgX registration is currently unavailable."}),S&&e.jsxs("p",{className:"mt-1.5 text-caption text-amber-100/70",children:["Upstream error: ",S]}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[B&&e.jsx("a",{href:B,target:"_blank",rel:"noopener noreferrer",className:"rounded-full border border-amber-200/25 bg-black/25 px-3 py-1 text-caption font-semibold text-amber-100 transition-colors hover:bg-black/35",children:"Open local artifact"}),g&&e.jsx("button",{type:"button",onClick:()=>void navigator.clipboard.writeText(g),className:"rounded-full border border-amber-200/25 bg-black/20 px-3 py-1 text-caption font-semibold text-amber-100 transition-colors hover:bg-black/35",children:"Copy path"})]})]}),t.metadata&&e.jsx(pe,{metadata:t.metadata,agentColor:v,createdAt:t.created_at}),t.description&&e.jsx("div",{children:e.jsx("p",{className:"text-body leading-relaxed text-primary",children:t.description})}),d&&e.jsxs("div",{className:"rounded-xl border border-white/[0.06] bg-[#08090D] overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-white/[0.06] px-4 py-2",children:[e.jsx("span",{className:"text-micro font-medium text-faint uppercase tracking-wider",children:A}),e.jsx(V,{text:d})]}),e.jsx(b.div,{initial:!1,animate:{height:r||!W?"auto":`${M*22+32}px`},transition:G,className:"overflow-hidden",children:e.jsx(de,{code:d,language:y,agentColor:v,maxLines:M,expanded:r})}),W&&e.jsxs("button",{type:"button",onClick:()=>i(u=>!u),className:"flex w-full items-center justify-center gap-1.5 border-t border-white/[0.06] px-4 py-2.5 text-micro font-semibold transition-colors hover:bg-white/[0.04]",style:{color:v||c.cyan},children:[e.jsx(b.svg,{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",animate:{rotate:r?180:0},transition:{duration:.22},children:e.jsx("path",{d:"m6 9 6 6 6-6"})}),r?"Collapse":`View Full (${j} lines)`]})]}),!d&&_&&e.jsx("div",{className:"rounded-xl border border-white/[0.06] bg-white/[0.02] p-4",children:e.jsx("pre",{className:"font-mono text-[13px] leading-relaxed text-primary whitespace-pre-wrap break-words",children:_})}),!t.description&&!d&&!_&&e.jsxs("div",{className:"py-12 text-center text-muted",children:[e.jsxs("svg",{className:"mx-auto mb-3 opacity-50",width:"32",height:"32",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"}),e.jsx("path",{d:"M14 2v4a2 2 0 0 0 2 2h4"})]}),e.jsx("p",{className:"text-sm",children:"No preview available"})]}),e.jsxs("div",{className:"flex flex-wrap gap-x-6 gap-y-1.5 text-micro text-faint",children:[e.jsxs("span",{children:["Entity: ",t.entity_type,"/",t.entity_id.slice(0,8)]}),e.jsxs("span",{children:["Version: ",t.version]}),e.jsxs("span",{children:["Updated:"," ",new Date(t.updated_at).toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric"})]})]})]})]})]})}export{be as ArtifactViewerModal};