agent-relay-server 0.124.0 → 0.125.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/docs/openapi.json +1 -1
  2. package/package.json +2 -2
  3. package/public/assets/{MessageBubble-SQK8-Mzp.js → MessageBubble-BYeYFteG.js} +2 -2
  4. package/public/assets/{MessageBubble-SQK8-Mzp.js.map → MessageBubble-BYeYFteG.js.map} +1 -1
  5. package/public/assets/{PlanGraphPanel-CS-aow4S.js → PlanGraphPanel-iAXvkZKW.js} +2 -2
  6. package/public/assets/{PlanGraphPanel-CS-aow4S.js.map → PlanGraphPanel-iAXvkZKW.js.map} +1 -1
  7. package/public/assets/{activity-W31XvhC2.js → activity-Du9SRJt5.js} +2 -2
  8. package/public/assets/{activity-W31XvhC2.js.map → activity-Du9SRJt5.js.map} +1 -1
  9. package/public/assets/agent-profiles-DXDQnrlH.js +2 -0
  10. package/public/assets/{agent-profiles-DXysA9To.js.map → agent-profiles-DXDQnrlH.js.map} +1 -1
  11. package/public/assets/{agent-type-icon-BxUopALO.js → agent-type-icon-B3i0rndK.js} +2 -2
  12. package/public/assets/{agent-type-icon-BxUopALO.js.map → agent-type-icon-B3i0rndK.js.map} +1 -1
  13. package/public/assets/{agents-B5GRNRnN.js → agents-CWOdKrxP.js} +2 -2
  14. package/public/assets/{agents-B5GRNRnN.js.map → agents-CWOdKrxP.js.map} +1 -1
  15. package/public/assets/{analytics-DqAuUAwX.js → analytics-YcY59Hv9.js} +2 -2
  16. package/public/assets/{analytics-DqAuUAwX.js.map → analytics-YcY59Hv9.js.map} +1 -1
  17. package/public/assets/{automation-DYlgHYcb.js → automation-CItTse7F.js} +2 -2
  18. package/public/assets/{automation-DYlgHYcb.js.map → automation-CItTse7F.js.map} +1 -1
  19. package/public/assets/{branch-state-badge-Mf0Ow77K.js → branch-state-badge-QjTktTYj.js} +2 -2
  20. package/public/assets/{branch-state-badge-Mf0Ow77K.js.map → branch-state-badge-QjTktTYj.js.map} +1 -1
  21. package/public/assets/{channels-DVRkVeky.js → channels-BSFTsbhT.js} +2 -2
  22. package/public/assets/{channels-DVRkVeky.js.map → channels-BSFTsbhT.js.map} +1 -1
  23. package/public/assets/chat-CRzFSFWe.js +2 -0
  24. package/public/assets/chat-CRzFSFWe.js.map +1 -0
  25. package/public/assets/{connectors-Cqubkw9C.js → connectors-C7d5dlYz.js} +2 -2
  26. package/public/assets/{connectors-Cqubkw9C.js.map → connectors-C7d5dlYz.js.map} +1 -1
  27. package/public/assets/{display-GFbGUG0O.js → display-aTnwsqQh.js} +3 -3
  28. package/public/assets/{display-GFbGUG0O.js.map → display-aTnwsqQh.js.map} +1 -1
  29. package/public/assets/{formatted-body-BYQ-SPtj.js → formatted-body-BuLfVMeD.js} +3 -3
  30. package/public/assets/{formatted-body-BYQ-SPtj.js.map → formatted-body-BuLfVMeD.js.map} +1 -1
  31. package/public/assets/{formatted-body-impl-L1EMnNW6.js → formatted-body-impl-DO-8giS6.js} +2 -2
  32. package/public/assets/{formatted-body-impl-L1EMnNW6.js.map → formatted-body-impl-DO-8giS6.js.map} +1 -1
  33. package/public/assets/index-C9X_0QBt.css +2 -0
  34. package/public/assets/index-De1tR7J4.js +26 -0
  35. package/public/assets/index-De1tR7J4.js.map +1 -0
  36. package/public/assets/{insights-DwZxq1Dn.js → insights-Ci3VuA5Y.js} +2 -2
  37. package/public/assets/{insights-DwZxq1Dn.js.map → insights-Ci3VuA5Y.js.map} +1 -1
  38. package/public/assets/{integrations-9G5TJnnU.js → integrations-BboxWQQD.js} +2 -2
  39. package/public/assets/{integrations-9G5TJnnU.js.map → integrations-BboxWQQD.js.map} +1 -1
  40. package/public/assets/{maintenance-COcmUDnf.js → maintenance-CO1miJIJ.js} +2 -2
  41. package/public/assets/{maintenance-COcmUDnf.js.map → maintenance-CO1miJIJ.js.map} +1 -1
  42. package/public/assets/{managed-agents-D9-dgMeX.js → managed-agents-r4oYK3Fm.js} +2 -2
  43. package/public/assets/{managed-agents-D9-dgMeX.js.map → managed-agents-r4oYK3Fm.js.map} +1 -1
  44. package/public/assets/{markdown-preview-impl-DH372bL-.js → markdown-preview-impl-5CCM9iyL.js} +2 -2
  45. package/public/assets/{markdown-preview-impl-DH372bL-.js.map → markdown-preview-impl-5CCM9iyL.js.map} +1 -1
  46. package/public/assets/{memory-B9hRK8sk.js → memory-BJJS07W-.js} +2 -2
  47. package/public/assets/{memory-B9hRK8sk.js.map → memory-BJJS07W-.js.map} +1 -1
  48. package/public/assets/{messages-BHkHlXzF.js → messages-RT_dfEsL.js} +2 -2
  49. package/public/assets/{messages-BHkHlXzF.js.map → messages-RT_dfEsL.js.map} +1 -1
  50. package/public/assets/{orchestrators-CXy3SDSn.js → orchestrators-8hyl8hW1.js} +2 -2
  51. package/public/assets/{orchestrators-CXy3SDSn.js.map → orchestrators-8hyl8hW1.js.map} +1 -1
  52. package/public/assets/{overview-D2yRyCQq.js → overview-CUJ9QmW_.js} +2 -2
  53. package/public/assets/{overview-D2yRyCQq.js.map → overview-CUJ9QmW_.js.map} +1 -1
  54. package/public/assets/{pairs-5tXdHylI.js → pairs-CzkzMGZq.js} +2 -2
  55. package/public/assets/{pairs-5tXdHylI.js.map → pairs-CzkzMGZq.js.map} +1 -1
  56. package/public/assets/{projects-CquHTMo1.js → projects-CAuLWBU5.js} +2 -2
  57. package/public/assets/{projects-CquHTMo1.js.map → projects-CAuLWBU5.js.map} +1 -1
  58. package/public/assets/{prompt-settings-Bn5mmi9w.js → prompt-settings-BnB90R7F.js} +2 -2
  59. package/public/assets/{prompt-settings-Bn5mmi9w.js.map → prompt-settings-BnB90R7F.js.map} +1 -1
  60. package/public/assets/{registry-C3sB7qv5.js → registry-B8TInqru.js} +2 -2
  61. package/public/assets/{registry-C3sB7qv5.js.map → registry-B8TInqru.js.map} +1 -1
  62. package/public/assets/{security-CmD-YE-_.js → security-DG_VVZUW.js} +2 -2
  63. package/public/assets/{security-CmD-YE-_.js.map → security-DG_VVZUW.js.map} +1 -1
  64. package/public/assets/{select-C0UlhK2k.js → select-BJ8G38_V.js} +2 -2
  65. package/public/assets/{select-C0UlhK2k.js.map → select-BJ8G38_V.js.map} +1 -1
  66. package/public/assets/{settings-DrqMG5nG.js → settings-CK_T9z5w.js} +4 -4
  67. package/public/assets/{settings-DrqMG5nG.js.map → settings-CK_T9z5w.js.map} +1 -1
  68. package/public/assets/{store-zFLzd0Jd.js → store-Dl9Z8YUS.js} +4 -4
  69. package/public/assets/{store-zFLzd0Jd.js.map → store-Dl9Z8YUS.js.map} +1 -1
  70. package/public/assets/{tasks-ChQjtXHu.js → tasks-Briui9Mp.js} +2 -2
  71. package/public/assets/{tasks-ChQjtXHu.js.map → tasks-Briui9Mp.js.map} +1 -1
  72. package/public/assets/{teams-itjNlDLp.js → teams-Ck4EVV3R.js} +2 -2
  73. package/public/assets/{teams-itjNlDLp.js.map → teams-Ck4EVV3R.js.map} +1 -1
  74. package/public/assets/{terminal-viewer-impl-B9M6s2vB.js → terminal-viewer-impl-66ZjVN1v.js} +2 -2
  75. package/public/assets/{terminal-viewer-impl-B9M6s2vB.js.map → terminal-viewer-impl-66ZjVN1v.js.map} +1 -1
  76. package/public/assets/{types-CRptbSYh.js → types-BqeSkWrv.js} +2 -2
  77. package/public/assets/{types-CRptbSYh.js.map → types-BqeSkWrv.js.map} +1 -1
  78. package/public/assets/{user-avatar-kYPfLgXp.js → user-avatar-BOy9o2xK.js} +2 -2
  79. package/public/assets/{user-avatar-kYPfLgXp.js.map → user-avatar-BOy9o2xK.js.map} +1 -1
  80. package/public/assets/{work-queue-Kw0uMkEF.js → work-queue-CnghFRG2.js} +2 -2
  81. package/public/assets/{work-queue-Kw0uMkEF.js.map → work-queue-CnghFRG2.js.map} +1 -1
  82. package/public/assets/{workspaces-CR6f7G0R.js → workspaces-BzmQnzSm.js} +2 -2
  83. package/public/assets/{workspaces-CR6f7G0R.js.map → workspaces-BzmQnzSm.js.map} +1 -1
  84. package/public/index.html +7 -7
  85. package/runner/plugins/claude/.claude-plugin/plugin.json +1 -1
  86. package/runner/plugins/claude/hooks/relay-status.sh +11 -1
  87. package/runner/plugins/claude/hooks/stop.sh +6 -1
  88. package/runner/plugins/claude/hooks/user-prompt-submit.sh +6 -1
  89. package/runner/src/adapter.ts +5 -1
  90. package/runner/src/adapters/claude-transcript.ts +52 -58
  91. package/runner/src/adapters/codex-agent-message-capture.ts +8 -36
  92. package/runner/src/adapters/codex.ts +30 -12
  93. package/runner/src/control-server.ts +9 -4
  94. package/runner/src/response-capture-report.ts +4 -1
  95. package/runner/src/runner-core.ts +75 -33
  96. package/src/agent-lifecycle-events.ts +8 -0
  97. package/src/bus.ts +0 -24
  98. package/src/db/agents.ts +15 -1
  99. package/src/db/messages.ts +114 -43
  100. package/src/maintenance/jobs.ts +8 -2
  101. package/src/mcp/tools-workspace.ts +4 -0
  102. package/src/routes/agents.ts +0 -4
  103. package/src/services/send-message.ts +7 -18
  104. package/src/services/shutdown-agent.ts +6 -0
  105. package/src/services/task-entity.ts +4 -0
  106. package/src/services/transient-agent-reaper.ts +40 -1
  107. package/src/services/work-finality.ts +25 -0
  108. package/public/assets/agent-profiles-DXysA9To.js +0 -2
  109. package/public/assets/chat-Clz6qOtn.js +0 -2
  110. package/public/assets/chat-Clz6qOtn.js.map +0 -1
  111. package/public/assets/index-0uIGXT14.js +0 -25
  112. package/public/assets/index-0uIGXT14.js.map +0 -1
  113. package/public/assets/index-DOJ7KidA.css +0 -2
@@ -1,6 +1,6 @@
1
- import{r as e}from"./chunk-CilyBKbf.js";import{$ as t,An as n,C as r,Cn as i,H as a,K as o,M as s,N as c,Pn as l,Pt as u,R as d,Tn as f,Wn as p,Xt as m,Yn as h,Yt as g,cr as _,en as v,g as y,gr as b,ir as x,k as S,l as C,m as w,mt as T,rr as E,tr as D,xn as O,yn as ee}from"./lucide-react-CoU_Xts2.js";import{_ as te,d as ne,h as k,t as A}from"./store-zFLzd0Jd.js";import{f as re,g as j,l as ie,m as ae}from"./types-CRptbSYh.js";import{t as oe}from"./themes-DjSwmAZN.js";import{a as M,i as N,n as P,r as F,t as I}from"./select-C0UlhK2k.js";import{t as L}from"./badge-XEru6wto.js";import{t as R}from"./button-C3CQSr4p.js";import{t as z}from"./input-CXMbJ848.js";import{W as se,yt as B}from"./index-0uIGXT14.js";import{i as V,n as ce,o as H,r as U,s as W,t as G}from"./card-C5XTIPvq.js";import{t as le}from"./user-avatar-kYPfLgXp.js";var K=e(b(),1);function q(e){return`${e.namespace}/${e.key}`}function ue(e){return`/settings/${encodeURIComponent(e.namespace)}/${encodeURIComponent(e.key)}`}function de(e){return e.trim().toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)||`settings`}function fe(e){let t=new Map;for(let n of e.filter(e=>e.readable)){let e=n.display?.group?.trim()||n.namespace;t.set(e,[...t.get(e)??[],n])}return[...t.entries()].map(([e,t])=>({group:e,slug:de(e),settings:t.sort(pe)})).sort((e,t)=>me(e.settings)-me(t.settings)||e.group.localeCompare(t.group))}function pe(e,t){return(e.display?.order??2**53-1)-(t.display?.order??2**53-1)||e.display?.label?.localeCompare(t.display?.label??``)||q(e).localeCompare(q(t))}function me(e){return Math.min(...e.map(e=>e.display?.order??2**53-1))}function he(e){return Array.isArray(e.type)?e.type.find(e=>e!==`null`):e.type}function ge(e,t,n){if(!t.length)return n;let[r,...i]=t;if(r===void 0)return n;if(typeof r==`number`){let t=Array.isArray(e)?[...e]:[];return t[r]=ge(t[r],i,n),t}let a=re(e)?{...e}:{},o=ge(a[r],i,n);return o===void 0?delete a[r]:a[r]=o,a}function _e(e){if(e.default!==void 0)return e.default;if(e.const!==void 0)return e.const;if(e.enum?.length)return e.enum[0];switch(he(e)){case`boolean`:return!1;case`integer`:case`number`:return 0;case`array`:return[];case`object`:return{};case`string`:return``;default:return}}function ve(e){return e.split(/\r?\n|,/).map(e=>e.trim()).filter(Boolean)}function ye(e){return Array.isArray(e)?e.map(e=>String(e)).join(`
2
- `):``}function be(e){return re(e)?Object.entries(e).map(([e,t])=>`${e}=${String(t??``)}`).join(`
3
- `):``}function xe(e){return Object.fromEntries(e.split(/\r?\n/).map(e=>e.trim()).filter(Boolean).map(e=>{let t=e.indexOf(`=`);return t>=0?[e.slice(0,t).trim(),e.slice(t+1)]:[e,``]}))}var J=E(),Se=`__unset__`;function Ce(e){return e===`server-runtime`?`Server runtime`:e===`bootstrap`?`Bootstrap`:`Browser`}function we(e){return e===`server-runtime`?`Stored by Relay and mutable while the server is running.`:e===`bootstrap`?`Read from startup configuration; restart or host config changes are required.`:`Stored only in this browser profile.`}function Te(e){return e===`browser`?(0,J.jsx)(t,{className:`size-3.5`}):(0,J.jsx)(S,{className:`size-3.5`})}function Ee(e){return e.details??[]}function De({group:e,settings:t,onSaved:n}){let r=[...new Set(t.map(e=>e.tier))];return(0,J.jsxs)(`section`,{className:`space-y-3`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,J.jsx)(`h2`,{className:`text-base font-semibold`,children:e}),(0,J.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:r.map(e=>(0,J.jsxs)(L,{variant:`outline`,className:`gap-1`,title:we(e),children:[Te(e),Ce(e)]},e))})]}),t.length===0?(0,J.jsx)(G,{size:`sm`,children:(0,J.jsx)(U,{className:`text-sm text-muted-foreground`,children:`No settings in this group.`})}):(0,J.jsx)(`div`,{className:`space-y-3`,children:t.map(e=>(0,J.jsx)(Oe,{setting:e,onSaved:n},q(e)))})]})}function Oe({setting:e,onSaved:t}){let[n,r]=(0,K.useState)(()=>e.value??e.defaults??_e(e.schema)),[i,a]=(0,K.useState)(!1),[o,c]=(0,K.useState)(``),[l,u]=(0,K.useState)([]),d=e.writable&&e.tier===`server-runtime`;function f(e,t){r(n=>ge(n,e,t)),u([]),c(``)}async function p(){if(d){a(!0),u([]),c(``);try{let i=await x(`PUT`,ue(e),{value:n,updatedBy:`dashboard`});r(i.value),t(i),c(`Saved`)}catch(e){let t=Ee(e);u(t.length?t:[e.message])}finally{a(!1)}}}return(0,J.jsxs)(G,{size:`sm`,children:[(0,J.jsxs)(H,{children:[(0,J.jsxs)(W,{className:`flex flex-wrap items-center gap-2 text-sm`,children:[e.display.label,(0,J.jsxs)(L,{variant:`outline`,className:`gap-1`,title:we(e.tier),children:[Te(e.tier),Ce(e.tier)]}),!e.writable&&(0,J.jsx)(L,{variant:`secondary`,children:`Read only`})]}),e.display.description&&(0,J.jsx)(V,{children:e.display.description}),(0,J.jsx)(ce,{children:(0,J.jsxs)(R,{size:`sm`,onClick:p,disabled:!d||i,children:[(0,J.jsx)(s,{className:`size-4`}),i?`Saving`:`Save`]})})]}),(0,J.jsxs)(U,{className:`space-y-3`,children:[(0,J.jsx)(ke,{schema:e.schema,value:n,path:[],label:e.display.label,required:!0,disabled:!d||i,onChange:f}),(0,J.jsxs)(`p`,{className:`flex flex-wrap items-center gap-x-2 text-[11px] text-muted-foreground`,children:[(0,J.jsxs)(`code`,{className:`rounded bg-muted px-1.5 py-0.5 font-mono`,children:[e.namespace,`/`,e.key]}),(0,J.jsxs)(`span`,{children:[`read `,(0,J.jsx)(`span`,{className:`text-foreground/70`,children:e.scope.read})]}),(0,J.jsx)(`span`,{"aria-hidden":!0,children:`·`}),(0,J.jsxs)(`span`,{children:[`write `,(0,J.jsx)(`span`,{className:`text-foreground/70`,children:e.scope.write})]})]}),l.length>0&&(0,J.jsxs)(`div`,{className:`rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive`,children:[(0,J.jsxs)(`div`,{className:`mb-1 flex items-center gap-2 font-medium`,children:[(0,J.jsx)(O,{className:`size-4`}),`Save failed`]}),(0,J.jsx)(`ul`,{className:`list-disc space-y-1 pl-5`,children:l.map(e=>(0,J.jsx)(`li`,{children:e},e))})]}),o&&(0,J.jsxs)(`p`,{className:`flex items-center gap-1 text-sm text-emerald-500`,children:[(0,J.jsx)(ee,{className:`size-4`}),o]})]})]})}function ke(e){let{schema:t,value:n,path:r,label:i,required:a,disabled:o,onChange:s}=e,c=he(t);if(t.enum?.length){let e=n==null||n===``?Se:String(n);return(0,J.jsx)(Y,{label:i,description:t.description,children:(0,J.jsxs)(I,{value:e,onValueChange:e=>s(r,e===`__unset__`?void 0:e),disabled:o,children:[(0,J.jsx)(N,{children:(0,J.jsx)(M,{})}),(0,J.jsxs)(P,{children:[!a&&(0,J.jsx)(F,{value:`__unset__`,children:`Not set`}),t.enum.map(e=>(0,J.jsx)(F,{value:String(e),children:String(e)},String(e)))]})]})})}if(c===`boolean`)return(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-md border bg-muted/20 p-3`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`text-sm font-medium`,children:i}),t.description&&(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:t.description})]}),(0,J.jsx)(B,{checked:!!n,onCheckedChange:e=>s(r,e),disabled:o})]});if(c===`integer`||c===`number`)return(0,J.jsx)(Y,{label:i,description:t.description,children:(0,J.jsx)(z,{type:`number`,min:typeof t.minimum==`number`?t.minimum:void 0,max:typeof t.maximum==`number`?t.maximum:void 0,step:c===`integer`?1:`any`,value:typeof n==`number`?n:``,disabled:o,onChange:e=>s(r,e.target.value===``&&!a?void 0:Number(e.target.value))})});if(c===`array`)return(0,J.jsx)(Y,{label:i,description:t.description??`One item per line.`,children:(0,J.jsx)(se,{rows:Math.min(8,Math.max(3,Array.isArray(n)?n.length+1:3)),value:ye(n),disabled:o,onChange:e=>s(r,ve(e.target.value))})});if(c===`object`){let e=t.properties??{},a=new Set(t.required??[]);return Object.keys(e).length===0&&t.additionalProperties?(0,J.jsx)(Y,{label:i,description:t.description??`KEY=value, one entry per line.`,children:(0,J.jsx)(se,{rows:5,value:be(n),disabled:o,onChange:e=>s(r,xe(e.target.value))})}):(0,J.jsxs)(`div`,{className:`space-y-3`,children:[r.length>0&&(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`text-sm font-medium`,children:i}),t.description&&(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:t.description})]}),(0,J.jsx)(`div`,{className:`grid gap-3 md:grid-cols-2`,children:Object.entries(e).map(([e,t])=>{let i=re(n)?n[e]:void 0;return(0,J.jsx)(ke,{schema:t,value:i===void 0&&a.has(e)?_e(t):i,path:[...r,e],label:t.title||Ae(e),required:a.has(e),disabled:o,onChange:s},e)})})]})}return(0,J.jsx)(Y,{label:i,description:t.description,children:(0,J.jsx)(z,{value:typeof n==`string`?n:n==null?``:String(n),disabled:o,onChange:e=>s(r,e.target.value===``&&!a?void 0:e.target.value)})})}function Y({label:e,description:t,children:n}){return(0,J.jsxs)(`label`,{className:`block space-y-1.5 text-sm`,children:[(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:e}),n,t&&(0,J.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:t})]})}function Ae(e){return e.replace(/([a-z0-9])([A-Z])/g,`$1 $2`).replace(/[-_]+/g,` `).replace(/^\w/,e=>e.toUpperCase())}function je(){let e=A(e=>e.theme),n=A(e=>e.showReasoning),r=A(e=>e.set);return(0,J.jsxs)(`section`,{className:`space-y-4`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`h2`,{className:`text-base font-semibold`,children:`Browser preferences`}),(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`These are stored in local dashboard state, not in Relay server config.`})]}),(0,J.jsxs)(G,{size:`sm`,children:[(0,J.jsxs)(H,{children:[(0,J.jsx)(W,{className:`text-sm`,children:`Dashboard display`}),(0,J.jsx)(V,{className:`text-xs`,children:`Browser tier · persisted in this browser profile.`}),(0,J.jsx)(ce,{children:(0,J.jsxs)(L,{variant:`outline`,className:`gap-1`,children:[(0,J.jsx)(t,{className:`size-3.5`}),`Browser`]})})]}),(0,J.jsxs)(U,{className:`grid gap-3 md:grid-cols-2`,children:[(0,J.jsx)(Y,{label:`Theme`,children:(0,J.jsxs)(I,{value:e,onValueChange:e=>r({theme:e}),children:[(0,J.jsx)(N,{children:(0,J.jsx)(M,{})}),(0,J.jsx)(P,{children:oe.map(e=>(0,J.jsx)(F,{value:e.id,children:e.label},e.id))})]})}),(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-md border bg-muted/20 p-3`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(l,{className:`size-4`}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`text-sm font-medium`,children:`Show reasoning details`}),(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Display captured reasoning/tool steps in chat. Server capture is controlled separately by provider reasoningCapture.`})]})]}),(0,J.jsx)(B,{checked:n,onCheckedChange:e=>r({showReasoning:e})})]})]})]}),(0,J.jsx)(Me,{})]})}function Me(){let e=A(e=>e.voiceTtsEnabled),t=A(e=>e.setVoiceTtsEnabled),n=A(e=>e.voiceTtsMode),r=A(e=>e.setVoiceTtsMode),i=A(e=>e.voiceTtsKokoroVoice),a=A(e=>e.setVoiceTtsKokoroVoice),o=A(e=>e.voiceTtsBrowserVoice),s=A(e=>e.setVoiceTtsBrowserVoice),c=A(e=>e.voiceInputMode),l=A(e=>e.setVoiceInputMode),[u,d]=(0,K.useState)(()=>te());(0,K.useEffect)(()=>{if(typeof window>`u`||!(`speechSynthesis`in window))return;let e=()=>d(te());return e(),window.speechSynthesis.addEventListener?.(`voiceschanged`,e),()=>window.speechSynthesis.removeEventListener?.(`voiceschanged`,e)},[]);let f=k.some(e=>e.id===i)?k:[...k,{id:i,label:i}];return(0,J.jsxs)(G,{size:`sm`,children:[(0,J.jsxs)(H,{children:[(0,J.jsxs)(W,{className:`flex items-center gap-2 text-sm`,children:[(0,J.jsx)(C,{className:`size-4`}),`Voice`]}),(0,J.jsx)(V,{className:`text-xs`,children:`Browser tier TTS and push-to-talk behavior.`}),(0,J.jsx)(ce,{children:(0,J.jsx)(B,{checked:e,onCheckedChange:t})})]}),(0,J.jsxs)(U,{className:`grid gap-3 md:grid-cols-2`,children:[(0,J.jsx)(Y,{label:`Speech engine`,children:(0,J.jsxs)(I,{value:n,onValueChange:e=>r(e),children:[(0,J.jsx)(N,{children:(0,J.jsx)(M,{})}),(0,J.jsxs)(P,{children:[(0,J.jsx)(F,{value:`kokoro`,children:`Kokoro (server, fallback to browser)`}),(0,J.jsx)(F,{value:`browser`,children:`Browser Web Speech API`})]})]})}),(0,J.jsx)(Y,{label:`Kokoro voice`,children:(0,J.jsxs)(I,{value:i,onValueChange:a,children:[(0,J.jsx)(N,{children:(0,J.jsx)(M,{})}),(0,J.jsx)(P,{children:f.map(e=>(0,J.jsx)(F,{value:e.id,children:e.label},e.id))})]})}),(0,J.jsx)(Y,{label:`Browser voice`,children:(0,J.jsxs)(I,{value:o||`__unset__`,onValueChange:e=>s(e===`__unset__`?``:e),children:[(0,J.jsx)(N,{children:(0,J.jsx)(M,{})}),(0,J.jsxs)(P,{children:[(0,J.jsx)(F,{value:Se,children:`System default`}),u.map(e=>(0,J.jsx)(F,{value:e.uri,children:e.label},e.uri))]})]})}),(0,J.jsx)(Y,{label:`Push-to-talk input`,children:(0,J.jsxs)(I,{value:c,onValueChange:e=>l(e),children:[(0,J.jsx)(N,{children:(0,J.jsx)(M,{})}),(0,J.jsxs)(P,{children:[(0,J.jsx)(F,{value:`compose`,children:`Fill message box`}),(0,J.jsx)(F,{value:`autosend`,children:`Send immediately`})]})]})})]})]})}function Ne({catalog:e,error:t,canWrite:n,onCatalog:i}){let s=e[0]?.provider??``,[c,l]=(0,K.useState)(s),[u,d]=(0,K.useState)(()=>Pe(s)),[f,p]=(0,K.useState)(``),[h,_]=(0,K.useState)([]),v=e.some(e=>e.provider===c)?c:s,b=e.find(e=>e.provider===v)??e[0],C=e.map(e=>e.provider);function w(e){d(t=>({...t,...e})),_([]),p(``)}function T(e){l(e),d(Pe(e)),_([]),p(``)}async function E(){i((await x(`GET`,`/providers`)).catalog)}async function D(){if(n){_([]),p(``);try{await x(`PUT`,`/providers/${encodeURIComponent(u.provider)}/models/${encodeURIComponent(u.alias)}`,{label:u.label,providerModel:u.providerModel,efforts:ve(u.efforts),defaultEffort:u.defaultEffort.trim()||void 0,limits:u.limits,capabilities:u.capabilities,contextThreshold:Fe(u),disabled:u.disabled,updatedBy:`dashboard`}),await E(),p(`${u.alias} saved`),d(Pe(u.provider))}catch(e){let t=Ee(e);_(t.length?t:[e.message])}}}async function O(e,t){if(n){_([]),p(``);try{await x(`PATCH`,`/providers/${encodeURIComponent(v)}/models/${encodeURIComponent(e.alias)}`,{disabled:t,updatedBy:`dashboard`}),await E(),p(`${e.alias} ${t?`disabled`:`enabled`}`)}catch(e){let t=Ee(e);_(t.length?t:[e.message])}}}async function te(e){if(n){_([]),p(``);try{await x(`DELETE`,`/providers/${encodeURIComponent(v)}/models/${encodeURIComponent(e.alias)}`),await E(),p(`${e.alias} removed`)}catch(e){let t=Ee(e);_(t.length?t:[e.message])}}}function ne(e){d({provider:v,alias:e.alias,label:e.label,providerModel:e.providerModel,efforts:e.efforts.join(`, `),defaultEffort:e.defaultEffort??``,selfCompactUtilization:e.contextThreshold?.selfCompactUtilization?.toString()??``,warnUtilization:e.contextThreshold?.warnUtilization?.toString()??``,hardBackstopUtilization:e.contextThreshold?.hardBackstopUtilization?.toString()??``,disabled:!!e.disabled,limits:e.limits,capabilities:e.capabilities}),_([]),p(``)}return t?(0,J.jsx)(G,{size:`sm`,children:(0,J.jsxs)(U,{className:`text-sm text-muted-foreground`,children:[(0,J.jsxs)(`div`,{className:`mb-1 flex items-center gap-2 font-medium text-foreground`,children:[(0,J.jsx)(r,{className:`size-4`}),`Model catalog`]}),t]})}):(0,J.jsxs)(`section`,{className:`space-y-4`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`h2`,{className:`text-base font-semibold`,children:`Model catalog`}),(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Add override models, disable unavailable models, or remove custom entries from the provider catalog.`})]}),!n&&(0,J.jsx)(L,{variant:`secondary`,children:`Read only: needs settings:write:provider`})]}),(0,J.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:C.map(e=>(0,J.jsx)(R,{variant:e===v?`default`:`outline`,size:`sm`,onClick:()=>T(e),children:e},e))}),(0,J.jsxs)(G,{size:`sm`,children:[(0,J.jsxs)(H,{children:[(0,J.jsx)(W,{className:`text-sm`,children:`Add or edit model`}),(0,J.jsx)(ce,{children:(0,J.jsxs)(L,{variant:`outline`,className:`gap-1`,children:[(0,J.jsx)(S,{className:`size-3.5`}),`Server runtime`]})})]}),(0,J.jsxs)(U,{className:`space-y-3`,children:[(0,J.jsxs)(`div`,{className:`grid gap-3 md:grid-cols-2`,children:[(0,J.jsx)(Y,{label:`Alias`,children:(0,J.jsx)(z,{value:u.alias,disabled:!n,placeholder:`nightly`,onChange:e=>w({alias:e.target.value.trim()})})}),(0,J.jsx)(Y,{label:`Label`,children:(0,J.jsx)(z,{value:u.label,disabled:!n,placeholder:`Nightly Codex`,onChange:e=>w({label:e.target.value})})}),(0,J.jsx)(Y,{label:`Provider model`,children:(0,J.jsx)(z,{value:u.providerModel,disabled:!n,placeholder:`codex-nightly`,onChange:e=>w({providerModel:e.target.value})})}),(0,J.jsx)(Y,{label:`Efforts`,children:(0,J.jsx)(z,{value:u.efforts,disabled:!n,placeholder:`low, medium, high`,onChange:e=>w({efforts:e.target.value})})}),(0,J.jsx)(Y,{label:`Default effort`,children:(0,J.jsx)(z,{value:u.defaultEffort,disabled:!n,placeholder:`medium`,onChange:e=>w({defaultEffort:e.target.value})})}),(0,J.jsx)(Y,{label:`Self compact utilization`,children:(0,J.jsx)(z,{value:u.selfCompactUtilization,disabled:!n,placeholder:`0.80`,inputMode:`decimal`,onChange:e=>w({selfCompactUtilization:e.target.value})})}),(0,J.jsx)(Y,{label:`Warn utilization`,children:(0,J.jsx)(z,{value:u.warnUtilization,disabled:!n,placeholder:`default: self - 0.10`,inputMode:`decimal`,onChange:e=>w({warnUtilization:e.target.value})})}),(0,J.jsx)(Y,{label:`Hard backstop utilization`,children:(0,J.jsx)(z,{value:u.hardBackstopUtilization,disabled:!n,placeholder:`0.90`,inputMode:`decimal`,onChange:e=>w({hardBackstopUtilization:e.target.value})})}),(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-md border bg-muted/20 p-3`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`text-sm font-medium`,children:`Disabled`}),(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Keep visible but unavailable for new launches.`})]}),(0,J.jsx)(B,{checked:u.disabled,disabled:!n,onCheckedChange:e=>w({disabled:e})})]})]}),(0,J.jsxs)(R,{onClick:D,disabled:!n||!u.alias||!u.label||!u.providerModel,children:[(0,J.jsx)(a,{className:`size-4`}),`Save model`]})]})]}),(0,J.jsxs)(`div`,{className:`space-y-2`,children:[b&&b.models.length===0&&(0,J.jsx)(G,{size:`sm`,children:(0,J.jsx)(U,{className:`text-sm text-muted-foreground`,children:`No models in this provider catalog yet.`})}),b?.models.map(e=>(0,J.jsx)(G,{size:`sm`,children:(0,J.jsxs)(U,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,J.jsxs)(`div`,{className:`min-w-0`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,J.jsx)(`span`,{className:`font-medium`,children:e.label}),(0,J.jsx)(`code`,{className:`rounded bg-muted px-1.5 py-0.5 font-mono text-xs`,children:e.alias}),e.disabled&&(0,J.jsx)(L,{variant:`secondary`,children:`Disabled`})]}),(0,J.jsxs)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:[e.providerModel,e.efforts.length>0?` · efforts ${e.efforts.join(`, `)}`:` · no effort levels`,e.defaultEffort?` · default ${e.defaultEffort}`:``,` · context ${Le(e)}`]})]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,J.jsxs)(R,{variant:`outline`,size:`sm`,onClick:()=>ne(e),children:[(0,J.jsx)(o,{className:`size-4`}),`Edit`]}),(0,J.jsxs)(R,{variant:`outline`,size:`sm`,disabled:!n,onClick:()=>void O(e,!e.disabled),children:[e.disabled?(0,J.jsx)(g,{className:`size-4`}):(0,J.jsx)(m,{className:`size-4`}),e.disabled?`Enable`:`Disable`]}),(0,J.jsxs)(R,{variant:`outline`,size:`sm`,disabled:!n,onClick:()=>void te(e),children:[(0,J.jsx)(y,{className:`size-4`}),`Remove`]})]})]})},e.alias))]}),h.length>0&&(0,J.jsx)(`div`,{className:`rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive`,children:(0,J.jsx)(`ul`,{className:`list-disc space-y-1 pl-5`,children:h.map(e=>(0,J.jsx)(`li`,{children:e},e))})}),f&&(0,J.jsxs)(`p`,{className:`flex items-center gap-1 text-sm text-emerald-500`,children:[(0,J.jsx)(ee,{className:`size-4`}),f]})]})}function Pe(e){return{provider:e,alias:``,label:``,providerModel:``,efforts:``,defaultEffort:``,selfCompactUtilization:``,warnUtilization:``,hardBackstopUtilization:``,disabled:!1}}function Fe(e){let t=Ie(e.selfCompactUtilization,`Self compact utilization`),n=Ie(e.warnUtilization,`Warn utilization`),r=Ie(e.hardBackstopUtilization,`Hard backstop utilization`);if(!(t===void 0&&n===void 0&&r===void 0)){if(t===void 0)throw Error(`Self compact utilization is required when setting context thresholds`);return{selfCompactUtilization:t,...n===void 0?{}:{warnUtilization:n},...r===void 0?{}:{hardBackstopUtilization:r}}}}function Ie(e,t){let n=e.trim();if(!n)return;let r=Number(n);if(!Number.isFinite(r))throw Error(`${t} must be a number`);return r}function Le(e){if(e.contextThreshold)return`self ${Re(e.contextThreshold.selfCompactUtilization)}, warn ${Re(e.contextThreshold.warnUtilization??Math.max(0,e.contextThreshold.selfCompactUtilization-.1))}`;let t=ne(e.limits?.contextWindowTokens?.value);return`derived self ${Re(t.selfCompactUtilization)}, warn ${Re(t.warnUtilization)}`}function Re(e){return`${Math.round(e*100)}%`}var ze=5,Be=15,Ve={claude:`Claude`,codex:`Codex`};function He(e){return Math.round(e/6e4)}function Ue(e){return`${He(e)} min`}function We({canWrite:e}){let[t,n]=(0,K.useState)(null),[r,i]=(0,K.useState)(``),[a,o]=(0,K.useState)(``),[s,c]=(0,K.useState)(null);(0,K.useEffect)(()=>{let e=!1;return(async()=>{try{let t=await x(`GET`,`/providers/quota-config`);e||n(t)}catch(t){e||i(t.message)}})(),()=>{e=!0}},[]);async function l(e,t){n(n=>({...n??{},[e]:t})),o(``),c(e);try{let r=await x(`PUT`,`/providers/${e}/quota-config`,t);n(t=>({...t??{},[e]:r}))}catch(t){o(`${Ve[e]??e}: ${t.message}`)}finally{c(null)}}let d=t?Object.keys(t).sort():[];return(0,J.jsxs)(`section`,{className:`space-y-4`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`h2`,{className:`text-base font-semibold`,children:`Quota`}),(0,J.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Per-provider quota collection and display. `,(0,J.jsx)(`strong`,{children:`Enabled`}),` governs collection (disabled stops polling — no API calls);`,(0,J.jsx)(`strong`,{children:` Show in widget`}),` governs display only.`]})]}),r&&(0,J.jsxs)(`div`,{className:`flex items-start gap-2 rounded-lg border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive`,children:[(0,J.jsx)(O,{className:`mt-0.5 size-4`}),(0,J.jsx)(`span`,{children:r})]}),a&&(0,J.jsxs)(`div`,{className:`flex items-start gap-2 rounded-lg border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive`,children:[(0,J.jsx)(O,{className:`mt-0.5 size-4`}),(0,J.jsx)(`span`,{children:a})]}),!t&&!r&&(0,J.jsx)(G,{size:`sm`,children:(0,J.jsxs)(U,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,J.jsx)(T,{className:`size-4 animate-spin`}),`Loading quota config…`]})}),d.map(r=>{let i=t[r],a=!e||s===r;return(0,J.jsxs)(G,{size:`sm`,children:[(0,J.jsxs)(H,{children:[(0,J.jsxs)(W,{className:`flex items-center gap-2 text-sm`,children:[(0,J.jsx)(u,{className:`size-4`}),Ve[r]??r,s===r&&(0,J.jsx)(T,{className:`size-3 animate-spin text-muted-foreground`})]}),(0,J.jsxs)(V,{className:`text-xs`,children:[i.enabled?`Polled every ${Ue(i.pollIntervalMs)}`:`Collection disabled`,i.enabled&&!i.showInWidget?` · hidden from widget`:``]})]}),(0,J.jsxs)(U,{className:`space-y-4`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-md border bg-muted/20 p-3`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`text-sm font-medium`,children:`Enabled`}),(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Collect quota for this provider. Off stops all polling (no API calls, no token spend).`})]}),(0,J.jsx)(B,{checked:i.enabled,disabled:a,onCheckedChange:e=>void l(r,{...i,enabled:e})})]}),(0,J.jsxs)(`div`,{className:`rounded-md border bg-muted/20 p-3 space-y-2`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,J.jsx)(`div`,{className:`text-sm font-medium`,children:`Polling interval`}),(0,J.jsx)(L,{variant:`outline`,className:`tabular-nums`,children:Ue(i.pollIntervalMs)})]}),(0,J.jsx)(`input`,{type:`range`,min:ze,max:Be,step:1,value:He(i.pollIntervalMs),disabled:a||!i.enabled,onChange:e=>{let t=Number(e.target.value)*6e4;n(e=>({...e??{},[r]:{...i,pollIntervalMs:t}}))},onPointerUp:e=>void l(r,{...i,pollIntervalMs:Number(e.target.value)*6e4}),onKeyUp:e=>void l(r,{...i,pollIntervalMs:Number(e.target.value)*6e4}),className:`w-full accent-primary disabled:opacity-50`}),(0,J.jsxs)(`div`,{className:`flex justify-between text-[10px] text-muted-foreground`,children:[(0,J.jsxs)(`span`,{children:[ze,` min`]}),(0,J.jsxs)(`span`,{children:[Be,` min`]})]})]}),(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-md border bg-muted/20 p-3`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`text-sm font-medium`,children:`Show in quota widget`}),(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Display only. Off hides this provider from the dashboard widget; collection continues if enabled.`})]}),(0,J.jsx)(B,{checked:i.showInWidget,disabled:a,onCheckedChange:e=>void l(r,{...i,showInWidget:e})})]}),(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-md border bg-muted/20 p-3`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`text-sm font-medium`,children:`Burn-rate sparkline`}),(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Show a mini utilization chart per window in the expanded widget.`})]}),(0,J.jsx)(B,{checked:i.sparklineEnabled??!0,disabled:a,onCheckedChange:e=>void l(r,{...i,sparklineEnabled:e})})]}),(0,J.jsxs)(`div`,{className:`rounded-md border bg-muted/20 p-3 space-y-2`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,J.jsx)(`div`,{className:`text-sm font-medium`,children:`Sparkline range`}),(0,J.jsxs)(L,{variant:`outline`,className:`tabular-nums`,children:[i.sparklineRangeHours??8,`h`]})]}),(0,J.jsx)(`input`,{type:`range`,min:1,max:8,step:1,value:i.sparklineRangeHours??8,disabled:a||!(i.sparklineEnabled??!0),onChange:e=>{let t=Number(e.target.value);n(e=>({...e??{},[r]:{...i,sparklineRangeHours:t}}))},onPointerUp:e=>void l(r,{...i,sparklineRangeHours:Number(e.target.value)}),onKeyUp:e=>void l(r,{...i,sparklineRangeHours:Number(e.target.value)}),className:`w-full accent-primary disabled:opacity-50`}),(0,J.jsxs)(`div`,{className:`flex justify-between text-[10px] text-muted-foreground`,children:[(0,J.jsx)(`span`,{children:`1h`}),(0,J.jsx)(`span`,{children:`8h`})]})]})]})]},r)})]})}function Ge({message:e}){return(0,J.jsxs)(`div`,{className:`flex items-start gap-2 rounded-lg border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive`,children:[(0,J.jsx)(O,{className:`mt-0.5 size-4 shrink-0`}),(0,J.jsx)(`span`,{children:e})]})}var Ke=ae(),X={cautionAt:.15,avoidLargeAt:.5,hardAvoidAt:1},qe=.99,Je=.5;function Z(e,t){return((e??t)*100).toFixed(0)}function Q(e){let t=e.trim();if(!t)return null;let n=Number(t);return!Number.isFinite(n)||n<0||n>100?null:n/100}function Ye(e,t){return e.trim()?Q(e):t}function Xe({policy:e,canWrite:t,onPolicy:n}){let r=e.quotaBands,i=e.providerQuota??{},[a,o]=(0,K.useState)(Z(r?.cautionAt,X.cautionAt)),[c,l]=(0,K.useState)(Z(r?.avoidLargeAt,X.avoidLargeAt)),[u,d]=(0,K.useState)(Z(r?.hardAvoidAt,X.hardAvoidAt)),[f,p]=(0,K.useState)(()=>{let e={};for(let t of Ke){let n=i[t]??{};e[t]={backstop:Z(n.hardBackstopUtilization,qe),floor:Z(n.burnPenaltyUtilizationFloor,Je)}}return e}),[m,h]=(0,K.useState)(!1),[g,_]=(0,K.useState)(``),[v,y]=(0,K.useState)(!1),[b,S]=(0,K.useState)(``);async function C(){let t=Q(a),r=Q(c),i=Q(u);if(t===null){S(`Caution threshold must be 0–100%.`);return}if(r===null){S(`Avoid-large threshold must be 0–100%.`);return}if(i===null){S(`Hard-avoid threshold must be 0–100%.`);return}if(t>=r){S(`Caution must be less than avoid-large.`);return}if(r>=i){S(`Avoid-large must be less than hard-avoid.`);return}let o={};for(let e of Ke){let t=f[e],n=Ye(t.backstop,qe),r=Q(t.floor);if(n===null){S(`${j(e)}: hard-backstop must be 0–100%.`);return}if(r===null){S(`${j(e)}: burn-penalty floor must be 0–100%.`);return}o[e]={hardBackstopUtilization:n,burnPenaltyUtilizationFloor:r}}S(``),h(!0),_(``),y(!1);try{n(await x(`PUT`,`/routing-policy`,{...e,quotaBands:{cautionAt:t,avoidLargeAt:r,hardAvoidAt:i},providerQuota:o})),y(!0),setTimeout(()=>y(!1),2e3)}catch(e){_(e.message)}finally{h(!1)}}function w(e,t){p(n=>({...n,[e]:{...n[e],...t}})),S(``),y(!1)}function E(){S(``),y(!1)}return(0,J.jsxs)(G,{size:`sm`,children:[(0,J.jsxs)(H,{children:[(0,J.jsx)(W,{className:`text-sm`,children:`Quota thresholds`}),(0,J.jsx)(V,{className:`text-xs`,children:`Band cutoffs govern when the orchestrator starts penalising or blocking high-quota providers. Values are utilization percentages (0–100).`})]}),(0,J.jsxs)(U,{className:`space-y-4`,children:[(g||b)&&(0,J.jsx)(Ge,{message:g||b}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`mb-2 text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:`Band cutoffs`}),(0,J.jsx)(Ze,{caution:Number(a),avoidLarge:Number(c),hardAvoid:Number(u)}),(0,J.jsxs)(`div`,{className:`mt-3 grid gap-3 sm:grid-cols-3`,children:[(0,J.jsx)($,{label:`Caution at`,hint:`Default: ${(X.cautionAt*100).toFixed(0)}%`,value:a,disabled:!t||m,onChange:e=>{o(e),E()}}),(0,J.jsx)($,{label:`Avoid-large at`,hint:`Default: ${(X.avoidLargeAt*100).toFixed(0)}%`,value:c,disabled:!t||m,onChange:e=>{l(e),E()}}),(0,J.jsx)($,{label:`Hard-avoid at`,hint:`Default: ${(X.hardAvoidAt*100).toFixed(0)}%`,value:u,disabled:!t||m,onChange:e=>{d(e),E()}})]})]}),Ke.map(e=>{let n=f[e];return(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`div`,{className:`mb-2 text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:[j(e),` overrides`]}),(0,J.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,J.jsx)($,{label:`Hard-backstop utilization`,hint:`0 = disable backstop (never block on this quota); blank uses the ${(qe*100).toFixed(0)}% default.`,value:n.backstop,disabled:!t||m,onChange:t=>w(e,{backstop:t})}),(0,J.jsx)($,{label:`Burn-penalty floor`,hint:`Penalties suppressed below this. Default: ${(Je*100).toFixed(0)}%`,value:n.floor,disabled:!t||m,onChange:t=>w(e,{floor:t})})]})]},e)}),t&&(0,J.jsxs)(R,{size:`sm`,onClick:()=>void C(),disabled:m,children:[m?(0,J.jsx)(T,{className:`size-4 animate-spin`}):(0,J.jsx)(s,{className:`size-4`}),v?`Saved`:`Save thresholds`]})]})]})}function Ze({caution:e,avoidLarge:t,hardAvoid:n}){let r=e=>Math.max(0,Math.min(100,Number.isFinite(e)?e:0)),i=r(e),a=Math.max(i,r(t)),o=Math.max(a,r(n)),s=e=>`${e.toFixed(0)}%`,c=[{key:`normal`,label:`normal`,color:`bg-emerald-500`,from:0,to:i,range:`0–${s(i)}`},{key:`caution`,label:`caution`,color:`bg-amber-500`,from:i,to:a,range:`${s(i)}–${s(a)}`},{key:`avoid-large`,label:`avoid large`,color:`bg-orange-500`,from:a,to:o,range:`${s(a)}–${s(o)}`},{key:`hard-avoid`,label:`hard avoid`,color:`bg-red-500`,from:o,to:100,range:`≥ ${s(o)}`}];return(0,J.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,J.jsx)(`div`,{className:`flex h-2.5 overflow-hidden rounded-full bg-muted`,role:`img`,"aria-label":`Quota penalty bands from 0 to 100 percent`,children:c.map(e=>(0,J.jsx)(`div`,{className:D(e.color,`transition-[width] duration-300`),style:{width:`${e.to-e.from}%`},title:`${e.label} · ${e.range}`},e.key))}),(0,J.jsx)(`div`,{className:`flex flex-wrap gap-x-3 gap-y-1 text-[10px] text-muted-foreground`,children:c.map(e=>(0,J.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(`span`,{className:D(`size-2 shrink-0 rounded-full`,e.color)}),e.label,` `,(0,J.jsx)(`span`,{className:`tabular-nums text-foreground/70`,children:e.range})]},e.key))})]})}function $({label:e,hint:t,value:n,disabled:r,onChange:i}){return(0,J.jsxs)(`label`,{className:`space-y-1`,children:[(0,J.jsx)(`span`,{className:`text-[10px] font-medium text-muted-foreground`,children:e}),(0,J.jsxs)(`div`,{className:`relative`,children:[(0,J.jsx)(z,{value:n,onChange:e=>i(e.target.value),disabled:r,className:`h-8 pr-6 text-xs tabular-nums`}),(0,J.jsx)(`span`,{className:`pointer-events-none absolute inset-y-0 right-2.5 flex items-center text-xs text-muted-foreground`,children:`%`})]}),(0,J.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:t})]})}function Qe(){let[e,t]=(0,K.useState)(null),[n,r]=(0,K.useState)(!1),[a,o]=(0,K.useState)(``),[s,c]=(0,K.useState)(!1),[l,u]=(0,K.useState)(!1);async function p(){if(!l){r(!0),o(``);try{let[e,n]=await Promise.all([x(`GET`,`/routing-policy`),x(`GET`,`/agent-profiles/coordinator`).catch(()=>null)]);t({policy:e,profile:n}),u(!0)}catch(e){o(e.message)}finally{r(!1)}}}async function m(){u(!1),r(!0),o(``);try{let[e,n]=await Promise.all([x(`GET`,`/routing-policy`),x(`GET`,`/agent-profiles/coordinator`).catch(()=>null)]);t({policy:e,profile:n}),u(!0)}catch(e){o(e.message)}finally{r(!1)}}function h(){let e=!s;c(e),e&&!l&&p()}return(0,J.jsx)(G,{size:`sm`,children:(0,J.jsxs)(U,{className:`space-y-3`,children:[(0,J.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 text-left`,onClick:h,children:[(0,J.jsx)(g,{className:`size-4 text-muted-foreground`}),(0,J.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,J.jsx)(`div`,{className:`text-sm font-semibold`,children:`What your coordinator knows`}),(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Active routing policy + coordinator profile instructions (read-only)`})]}),s?(0,J.jsx)(f,{className:`size-4 shrink-0 text-muted-foreground`}):(0,J.jsx)(i,{className:`size-4 shrink-0 text-muted-foreground`})]}),s&&(0,J.jsxs)(`div`,{className:`space-y-4 pt-1`,children:[(0,J.jsx)(`div`,{className:`flex justify-end`,children:(0,J.jsxs)(R,{variant:`outline`,size:`sm`,onClick:()=>void m(),disabled:n,children:[(0,J.jsx)(d,{className:D(`size-3.5`,n&&`animate-spin`)}),`Refresh`]})}),a&&(0,J.jsx)(Ge,{message:a}),n&&!e&&(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground py-2`,children:[(0,J.jsx)(T,{className:`size-3.5 animate-spin`}),`Loading…`]}),e&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)($e,{policy:e.policy}),e.profile?(0,J.jsx)(tt,{profile:e.profile}):(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:`Coordinator profile not found.`})]})]})]})})}function $e({policy:e}){let t=e.quotaBands,n=e.providerQuota??{};return(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsx)(`div`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wide`,children:`Active routing policy`}),e.rules.length===0?(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:`No rules — coordinators use their own heuristics.`}):(0,J.jsxs)(`div`,{className:`overflow-hidden rounded-md border border-border text-xs`,children:[(0,J.jsxs)(`div`,{className:`grid grid-cols-[1.5rem_minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)] gap-px bg-border text-[10px] font-medium text-muted-foreground uppercase tracking-wide`,children:[(0,J.jsx)(`div`,{className:`bg-muted/40 px-2 py-1.5`,children:`#`}),(0,J.jsx)(`div`,{className:`bg-muted/40 px-2 py-1.5`,children:`Match`}),(0,J.jsx)(`div`,{className:`bg-muted/40 px-2 py-1.5`,children:`Target`}),(0,J.jsx)(`div`,{className:`bg-muted/40 px-2 py-1.5`,children:`Status`})]}),e.rules.map((e,t)=>(0,J.jsxs)(`div`,{className:D(`grid grid-cols-[1.5rem_minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)] gap-px bg-border`,e.enabled===!1&&`opacity-50`),children:[(0,J.jsx)(`div`,{className:`bg-card px-2 py-1.5 text-muted-foreground tabular-nums`,children:t+1}),(0,J.jsxs)(`div`,{className:`bg-card px-2 py-1.5`,children:[e.label&&(0,J.jsx)(`div`,{className:`font-medium`,children:e.label}),e.match.taskType&&(0,J.jsxs)(`div`,{className:`font-mono`,children:[`task: `,e.match.taskType]}),e.match.capability&&(0,J.jsxs)(`div`,{className:`font-mono`,children:[`cap: `,e.match.capability]})]}),(0,J.jsxs)(`div`,{className:`bg-card px-2 py-1.5`,children:[(0,J.jsx)(`span`,{className:`font-medium`,children:e.target.provider}),e.target.model&&(0,J.jsxs)(`span`,{className:`text-muted-foreground`,children:[` / `,e.target.model]}),e.target.effort&&(0,J.jsxs)(`span`,{className:`text-muted-foreground`,children:[` (`,e.target.effort,`)`]})]}),(0,J.jsx)(`div`,{className:`bg-card px-2 py-1.5`,children:e.enabled===!1?(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:`disabled`}):(0,J.jsx)(`span`,{className:`text-emerald-500`,children:`active`})})]},t))]}),(t||Object.keys(n).length>0)&&(0,J.jsxs)(`div`,{className:`rounded-md border border-border bg-muted/10 px-3 py-2 text-xs space-y-1`,children:[t&&(0,J.jsxs)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-0.5`,children:[t.cautionAt!==void 0&&(0,J.jsxs)(`span`,{children:[`caution ≥ `,(t.cautionAt*100).toFixed(0),`%`]}),t.avoidLargeAt!==void 0&&(0,J.jsxs)(`span`,{children:[`avoid-large ≥ `,(t.avoidLargeAt*100).toFixed(0),`%`]}),t.hardAvoidAt!==void 0&&(0,J.jsxs)(`span`,{children:[`hard-avoid ≥ `,(t.hardAvoidAt*100).toFixed(0),`%`]})]}),Object.entries(n).map(([e,t])=>(0,J.jsxs)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-0.5 text-muted-foreground`,children:[(0,J.jsx)(`span`,{className:`font-medium text-foreground`,children:j(e)}),t?.hardBackstopUtilization!==void 0&&(0,J.jsxs)(`span`,{children:[`backstop: `,(t.hardBackstopUtilization*100).toFixed(0),`%`]}),t?.burnPenaltyUtilizationFloor!==void 0&&(0,J.jsxs)(`span`,{children:[`floor: `,(t.burnPenaltyUtilizationFloor*100).toFixed(0),`%`]})]},e))]})]})}function et({text:e,index:t}){return(0,J.jsxs)(`div`,{className:`relative max-h-72 overflow-y-auto rounded-md border border-border bg-muted/20`,children:[t!==void 0&&(0,J.jsxs)(`span`,{className:`sticky top-0 float-right m-1.5 rounded bg-muted px-1.5 py-0.5 text-[9px] font-medium tabular-nums text-muted-foreground`,children:[`#`,t]}),(0,J.jsx)(`pre`,{className:`whitespace-pre-wrap break-words px-3 py-2.5 font-sans text-[11px] leading-relaxed text-foreground/90`,children:e})]})}function tt({profile:e}){return(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsxs)(`div`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wide`,children:[`Coordinator profile instructions`,(0,J.jsx)(L,{variant:`secondary`,className:`ml-2 text-[10px]`,children:e.name}),e.builtIn&&(0,J.jsx)(L,{variant:`outline`,className:`ml-1 text-[10px]`,children:`built-in`})]}),e.description&&(0,J.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.description}),(0,J.jsxs)(`div`,{className:`flex flex-wrap gap-2 text-[10px]`,children:[(0,J.jsxs)(L,{variant:`outline`,children:[`base: `,e.base]}),(0,J.jsxs)(L,{variant:`outline`,children:[`repo: `,e.instructions.repoInstructions]}),(0,J.jsxs)(L,{variant:`outline`,children:[`global: `,e.instructions.globalInstructions]}),e.provider&&(0,J.jsxs)(L,{variant:`outline`,children:[`provider: `,e.provider]})]}),e.instructions.system&&(0,J.jsxs)(`div`,{className:`space-y-1`,children:[(0,J.jsx)(`div`,{className:`text-[10px] font-medium text-muted-foreground uppercase tracking-wide`,children:`System prompt`}),(0,J.jsx)(et,{text:e.instructions.system})]}),e.instructions.append.length>0&&(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsxs)(`div`,{className:`text-[10px] font-medium text-muted-foreground uppercase tracking-wide`,children:[`Appended instructions (`,e.instructions.append.length,`)`]}),e.instructions.append.map((e,t)=>(0,J.jsx)(et,{text:e,index:t+1},t))]}),e.instructions.append.length===0&&!e.instructions.system&&(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:`No instruction blocks defined.`})]})}var nt=ae();function rt(){return{label:``,matchTaskType:``,matchCapability:``,targetProvider:nt[0]??``,targetModel:``,targetEffort:``,enabled:!0}}function it(e){return{label:e.label??``,matchTaskType:e.match.taskType??``,matchCapability:e.match.capability??``,targetProvider:e.target.provider,targetModel:e.target.model??``,targetEffort:e.target.effort??``,enabled:e.enabled!==!1}}function at(e){return{...e.label.trim()?{label:e.label.trim()}:{},match:{...e.matchTaskType.trim()?{taskType:e.matchTaskType.trim()}:{},...e.matchCapability.trim()?{capability:e.matchCapability.trim()}:{}},target:{provider:e.targetProvider,...e.targetModel.trim()?{model:e.targetModel.trim()}:{},...e.targetEffort.trim()?{effort:e.targetEffort.trim()}:{}},enabled:e.enabled}}function ot(e){return!e.matchTaskType.trim()&&!e.matchCapability.trim()?`At least one match criterion (task type or capability) is required.`:null}function st({message:e}){return(0,J.jsxs)(`div`,{className:`flex items-start gap-2 rounded-lg border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive`,children:[(0,J.jsx)(O,{className:`mt-0.5 size-4 shrink-0`}),(0,J.jsx)(`span`,{children:e})]})}function ct({canWrite:e}){let[t,n]=(0,K.useState)(null),[r,i]=(0,K.useState)(!1),[a,o]=(0,K.useState)(``),[s,c]=(0,K.useState)(!1);!s&&!r&&!a&&(i(!0),(async()=>{try{n(await x(`GET`,`/routing-policy`)),c(!0)}catch(e){o(e.message)}finally{i(!1)}})());async function l(){i(!0),o(``);try{n(await x(`GET`,`/routing-policy`)),c(!0)}catch(e){o(e.message)}finally{i(!1)}}return(0,J.jsxs)(`div`,{className:`space-y-6`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`h2`,{className:`text-base font-semibold`,children:`Routing`}),(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Declarative rules mapping task types and capabilities to providers. Rules are advisory — coordinators apply them; explicit per-spawn arguments always take precedence.`})]}),(0,J.jsxs)(R,{variant:`outline`,size:`sm`,onClick:()=>void l(),disabled:r,children:[(0,J.jsx)(d,{className:D(`size-4`,r&&`animate-spin`)}),`Refresh`]})]}),a&&(0,J.jsx)(st,{message:a}),r&&!t&&(0,J.jsx)(G,{size:`sm`,children:(0,J.jsxs)(U,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,J.jsx)(T,{className:`size-4 animate-spin`}),`Loading routing policy…`]})}),t&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(lt,{policy:t,canWrite:e,onPolicy:n}),(0,J.jsx)(Xe,{policy:t,canWrite:e,onPolicy:n})]}),(0,J.jsx)(Qe,{})]})}function lt({policy:e,canWrite:t,onPolicy:n}){let[r,i]=(0,K.useState)(!1),[o,s]=(0,K.useState)(``),[l,u]=(0,K.useState)(!1),[d,f]=(0,K.useState)(rt),[p,m]=(0,K.useState)(``),[h,g]=(0,K.useState)(null),[_,v]=(0,K.useState)(rt),[y,b]=(0,K.useState)(``);async function S(e){i(!0),s(``);try{n(await x(`PUT`,`/routing-policy`,e))}catch(e){s(e.message)}finally{i(!1)}}function C(t,n){let r=[...e.rules],i=t+n;i<0||i>=r.length||([r[t],r[i]]=[r[i],r[t]],S({...e,rules:r}))}function w(t){let n=e.rules.map((e,n)=>n===t?{...e,enabled:e.enabled===!1}:e);S({...e,rules:n})}function E(t){S({...e,rules:e.rules.filter((e,n)=>n!==t)})}function D(){f(rt()),m(``),u(!0)}function O(){u(!1),m(``)}function ee(){let t=ot(d);if(t){m(t);return}u(!1),S({...e,rules:[...e.rules,at(d)]})}function te(t){g(t),v(it(e.rules[t])),b(``)}function ne(){g(null),b(``)}function k(){if(h===null)return;let t=ot(_);if(t){b(t);return}let n=e.rules.map((e,t)=>t===h?at(_):e);g(null),S({...e,rules:n})}return(0,J.jsxs)(G,{size:`sm`,children:[(0,J.jsxs)(H,{children:[(0,J.jsxs)(W,{className:`flex items-center gap-2 text-sm`,children:[(0,J.jsx)(c,{className:`size-4`}),`Rules`,(0,J.jsxs)(L,{variant:`outline`,className:`ml-auto text-[10px]`,children:[e.rules.length,` rule`,e.rules.length===1?``:`s`]}),r&&(0,J.jsx)(T,{className:`size-3 animate-spin text-muted-foreground`})]}),(0,J.jsx)(V,{className:`text-xs`,children:`Evaluated in order — first matching enabled rule wins. Rules are advisory; explicit spawn arguments override them.`})]}),(0,J.jsxs)(U,{className:`space-y-2`,children:[o&&(0,J.jsx)(st,{message:o}),e.rules.length===0&&!l&&(0,J.jsx)(`div`,{className:`rounded-md border border-dashed border-border py-6 text-center text-xs text-muted-foreground`,children:`No rules — coordinators fall back to their own heuristics.`}),e.rules.map((n,i)=>h===i?(0,J.jsx)(dt,{form:_,error:y,onChange:v,onSave:k,onCancel:ne},i):(0,J.jsx)(ut,{rule:n,idx:i,total:e.rules.length,canWrite:t,saving:r,onMoveUp:()=>C(i,-1),onMoveDown:()=>C(i,1),onToggle:()=>w(i),onEdit:()=>te(i),onRemove:()=>E(i)},i)),l&&(0,J.jsx)(dt,{form:d,error:p,onChange:f,onSave:ee,onCancel:O,isNew:!0}),t&&!l&&h===null&&(0,J.jsxs)(R,{variant:`outline`,size:`sm`,className:`w-full gap-1`,onClick:D,disabled:r,children:[(0,J.jsx)(a,{className:`size-4`}),`Add rule`]})]})]})}function ut({rule:e,idx:t,total:n,canWrite:r,saving:i,onMoveUp:a,onMoveDown:o,onToggle:s,onEdit:c,onRemove:l}){return(0,J.jsxs)(`div`,{className:D(`group flex items-start gap-3 rounded-md border bg-muted/20 p-3`,e.enabled===!1&&`opacity-60`),children:[(0,J.jsxs)(`div`,{className:`flex flex-col items-center gap-0.5 pt-0.5`,children:[(0,J.jsx)(`button`,{type:`button`,title:`Move up`,onClick:a,disabled:!r||i||t===0,className:`rounded p-0.5 text-muted-foreground hover:bg-accent hover:text-foreground disabled:pointer-events-none disabled:opacity-30`,children:(0,J.jsx)(p,{className:`size-3.5`})}),(0,J.jsx)(`button`,{type:`button`,title:`Move down`,onClick:o,disabled:!r||i||t===n-1,className:`rounded p-0.5 text-muted-foreground hover:bg-accent hover:text-foreground disabled:pointer-events-none disabled:opacity-30`,children:(0,J.jsx)(h,{className:`size-3.5`})})]}),(0,J.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-1`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsxs)(`span`,{className:`text-[10px] tabular-nums text-muted-foreground`,children:[`#`,t+1]}),e.label&&(0,J.jsx)(`span`,{className:`text-xs font-medium`,children:e.label}),(0,J.jsx)(L,{variant:`outline`,className:`text-[10px]`,children:e.target.provider}),e.target.model&&(0,J.jsx)(L,{variant:`outline`,className:`text-[10px] font-mono`,children:e.target.model}),e.target.effort&&(0,J.jsx)(L,{variant:`outline`,className:`text-[10px]`,children:e.target.effort})]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap gap-x-3 gap-y-0.5 text-[10px] text-muted-foreground`,children:[e.match.taskType&&(0,J.jsxs)(`span`,{children:[`task-type: `,(0,J.jsx)(`span`,{className:`font-mono text-foreground`,children:e.match.taskType})]}),e.match.capability&&(0,J.jsxs)(`span`,{children:[`capability: `,(0,J.jsx)(`span`,{className:`font-mono text-foreground`,children:e.match.capability})]})]})]}),(0,J.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 opacity-70 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100`,children:[(0,J.jsx)(B,{checked:e.enabled!==!1,disabled:!r||i,onCheckedChange:s,title:e.enabled===!1?`Enable rule`:`Disable rule`}),r&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`button`,{type:`button`,title:`Edit`,onClick:c,disabled:i,className:`rounded p-1 text-muted-foreground hover:bg-accent hover:text-foreground disabled:pointer-events-none`,children:(0,J.jsxs)(`svg`,{className:`size-3.5`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,children:[(0,J.jsx)(`path`,{d:`M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7`}),(0,J.jsx)(`path`,{d:`M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z`})]})}),(0,J.jsx)(`button`,{type:`button`,title:`Remove`,onClick:l,disabled:i,className:`rounded p-1 text-destructive hover:bg-destructive/10 disabled:pointer-events-none`,children:(0,J.jsx)(y,{className:`size-3.5`})})]})]})]})}function dt({form:e,error:t,onChange:n,onSave:r,onCancel:i,isNew:a}){function o(t){n({...e,...t})}return(0,J.jsxs)(`div`,{className:`rounded-md border border-primary/30 bg-primary/5 p-3 space-y-3`,children:[(0,J.jsx)(`div`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wide`,children:a?`New rule`:`Edit rule`}),(0,J.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,J.jsxs)(`label`,{className:`space-y-1`,children:[(0,J.jsx)(`span`,{className:`text-[10px] font-medium text-muted-foreground`,children:`Label (optional)`}),(0,J.jsx)(z,{value:e.label,onChange:e=>o({label:e.target.value}),placeholder:`e.g. Route GUI tasks to Claude`,className:`h-8 text-xs`})]}),(0,J.jsxs)(`label`,{className:`space-y-1`,children:[(0,J.jsx)(`span`,{className:`text-[10px] font-medium text-muted-foreground`,children:`Target provider`}),(0,J.jsxs)(I,{value:e.targetProvider,onValueChange:e=>o({targetProvider:e}),children:[(0,J.jsx)(N,{className:`h-8 text-xs`,children:(0,J.jsx)(M,{})}),(0,J.jsx)(P,{children:nt.map(e=>(0,J.jsx)(F,{value:e,className:`text-xs`,children:j(e)},e))})]})]})]}),(0,J.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,J.jsxs)(`label`,{className:`space-y-1`,children:[(0,J.jsx)(`span`,{className:`text-[10px] font-medium text-muted-foreground`,children:`Match task-type (prefix)`}),(0,J.jsx)(z,{value:e.matchTaskType,onChange:e=>o({matchTaskType:e.target.value}),placeholder:`e.g. gui, backend, mechanical`,className:`h-8 font-mono text-xs`}),(0,J.jsxs)(`span`,{className:`block text-[10px] leading-snug text-muted-foreground`,children:[`Prefix match — `,(0,J.jsx)(`span`,{className:`font-mono text-foreground`,children:`gui`}),` matches `,(0,J.jsx)(`span`,{className:`font-mono text-foreground`,children:`gui/ux`}),`, `,(0,J.jsx)(`span`,{className:`font-mono text-foreground`,children:`gui/layout`}),`.`]})]}),(0,J.jsxs)(`label`,{className:`space-y-1`,children:[(0,J.jsx)(`span`,{className:`text-[10px] font-medium text-muted-foreground`,children:`Match capability (exact)`}),(0,J.jsx)(z,{value:e.matchCapability,onChange:e=>o({matchCapability:e.target.value}),placeholder:`e.g. code, research, bounded`,className:`h-8 font-mono text-xs`}),(0,J.jsx)(`span`,{className:`block text-[10px] leading-snug text-muted-foreground`,children:`Exact match against the agent's capability tag. Both fields are AND-ed.`})]})]}),(0,J.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,J.jsxs)(`label`,{className:`space-y-1`,children:[(0,J.jsx)(`span`,{className:`text-[10px] font-medium text-muted-foreground`,children:`Model alias (optional)`}),(0,J.jsx)(z,{value:e.targetModel,onChange:e=>o({targetModel:e.target.value}),placeholder:`e.g. opus, gpt-5.4`,className:`h-8 font-mono text-xs`})]}),(0,J.jsxs)(`label`,{className:`space-y-1`,children:[(0,J.jsx)(`span`,{className:`text-[10px] font-medium text-muted-foreground`,children:`Effort (optional)`}),(0,J.jsx)(z,{value:e.targetEffort,onChange:e=>o({targetEffort:e.target.value}),placeholder:`e.g. high, low`,className:`h-8 text-xs`})]})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(B,{checked:e.enabled,onCheckedChange:e=>o({enabled:e})}),(0,J.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Enabled`})]}),t&&(0,J.jsx)(st,{message:t}),(0,J.jsxs)(`div`,{className:`flex gap-2`,children:[(0,J.jsxs)(R,{size:`sm`,onClick:r,children:[(0,J.jsx)(s,{className:`size-4`}),a?`Add`:`Save`]}),(0,J.jsx)(R,{size:`sm`,variant:`outline`,onClick:i,children:`Cancel`})]})]})}var ft=`browser`,pt=`models`,mt=`profile`,ht=`routing`,gt=[`branch.landed`,`landed-failure`,`agent.ready`,`agent.exited`,`agent.spawn_failed`,`agent.context_threshold`,`agent.quota_threshold`,`workspace.steward_task`,`workspace.conflict`,`workspace.review_request`];function _t(){if(typeof window>`u`)return``;let e=window.location.hash.replace(/^#/,``);return e.startsWith(`settings/`)?decodeURIComponent(e.slice(9)):``}function vt(e){if(typeof window>`u`)return;let t=new URL(window.location.href);t.hash=`settings/${encodeURIComponent(e)}`,window.history.pushState({},``,t)}function yt(){let[e,t]=(0,K.useState)([]),[n,r]=(0,K.useState)(null),[i,a]=(0,K.useState)([]),[o,s]=(0,K.useState)(()=>_t()),[c,l]=(0,K.useState)(!0),[u,f]=(0,K.useState)(``),[p,m]=(0,K.useState)(``);async function h(){l(!0),f(``),m(``);try{let[e,n,i]=await Promise.all([x(`GET`,`/settings`),x(`GET`,`/tokens/me`),x(`GET`,`/providers`).catch(e=>(m(e.message),{catalog:[]}))]);t(e.settings),r(n),a(i.catalog)}catch(e){f(e.message)}finally{l(!1)}}(0,K.useEffect)(()=>{h()},[]),(0,K.useEffect)(()=>{let e=()=>s(_t());return window.addEventListener(`hashchange`,e),window.addEventListener(`popstate`,e),()=>{window.removeEventListener(`hashchange`,e),window.removeEventListener(`popstate`,e)}},[]);let g=(0,K.useMemo)(()=>fe(e),[e]),_=(0,K.useMemo)(()=>[...g.map(e=>({slug:e.slug,label:e.group,description:`${e.settings.length} schema setting${e.settings.length===1?``:`s`}`,kind:`descriptors`,settings:e.settings})),{slug:ht,label:`Routing`,description:`Rules, quota thresholds, coordinator view`,kind:`routing`,settings:[]},{slug:mt,label:`Profile`,description:`Display name and avatar`,kind:`profile`,settings:[]},{slug:ft,label:`Browser`,description:`Local dashboard preferences`,kind:`browser`,settings:[]},{slug:pt,label:`Models`,description:`Provider model catalog`,kind:`models`,settings:[]}],[g]),y=_.find(e=>e.slug===o)??_[0];function b(e){s(e),vt(e)}function S(e){t(t=>t.map(t=>q(t)===q(e)?e:t))}return(0,J.jsxs)(`div`,{className:`space-y-4`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Settings`}),(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Schema-driven Relay settings, browser preferences, and model catalog controls.`})]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[n&&(0,J.jsxs)(L,{variant:`outline`,className:`gap-1`,children:[(0,J.jsx)(v,{className:`size-3`}),n.kind,`:`,n.actor]}),(0,J.jsxs)(R,{variant:`outline`,size:`sm`,onClick:()=>void h(),disabled:c,children:[(0,J.jsx)(d,{className:D(`size-4`,c&&`animate-spin`)}),`Refresh`]})]})]}),u&&(0,J.jsxs)(`div`,{className:`flex items-start gap-2 rounded-lg border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive`,children:[(0,J.jsx)(O,{className:`mt-0.5 size-4`}),(0,J.jsx)(`span`,{children:u})]}),(0,J.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-[230px_minmax(0,1fr)]`,children:[(0,J.jsx)(`nav`,{className:`space-y-1 lg:sticky lg:top-4 lg:self-start`,children:_.map(e=>(0,J.jsxs)(`button`,{type:`button`,className:D(`w-full rounded-md border px-3 py-2 text-left text-sm transition-colors`,y?.slug===e.slug?`border-primary/50 bg-primary/10 text-foreground`:`border-transparent hover:border-border hover:bg-accent`),onClick:()=>b(e.slug),children:[(0,J.jsx)(`span`,{className:`block font-medium`,children:e.label}),(0,J.jsx)(`span`,{className:`block truncate text-xs text-muted-foreground`,children:e.description})]},e.slug))}),(0,J.jsx)(`div`,{className:`min-w-0 space-y-4`,children:c&&!e.length?(0,J.jsx)(G,{size:`sm`,children:(0,J.jsx)(U,{className:`text-sm text-muted-foreground`,children:`Loading settings…`})}):y?.kind===`routing`?(0,J.jsx)(ct,{canWrite:ie(n?.scopes,`settings:write:routing`)}):y?.kind===`descriptors`?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(De,{group:y.label,settings:y.settings,onSaved:S}),y.label===`Providers`&&(0,J.jsx)(We,{canWrite:ie(n?.scopes,`settings:write:provider`)}),y.label===`Notifications`&&(0,J.jsx)(bt,{})]}):y?.kind===`profile`?(0,J.jsx)(xt,{}):y?.kind===`browser`?(0,J.jsx)(je,{}):(0,J.jsx)(Ne,{catalog:i,error:p,canWrite:ie(n?.scopes,`settings:write:provider`),onCatalog:a})})]})]})}function bt(){let[e,t]=(0,K.useState)(`branch.landed`),[n,r]=(0,K.useState)(`{
1
+ import{r as e}from"./chunk-CilyBKbf.js";import{$ as t,An as n,C as r,Cn as i,H as a,K as o,M as s,N as c,Pn as l,Pt as u,R as d,Tn as f,Wn as p,Xt as m,Yn as h,Yt as g,cr as _,en as v,g as y,gr as b,ir as x,k as S,l as C,m as w,mt as T,rr as E,tr as D,xn as O,yn as ee}from"./lucide-react-CoU_Xts2.js";import{_ as te,d as ne,h as k,t as A}from"./store-Dl9Z8YUS.js";import{_ as j,h as re,p as ie,u as ae}from"./types-BqeSkWrv.js";import{t as oe}from"./themes-DjSwmAZN.js";import{a as M,i as N,n as P,r as F,t as I}from"./select-BJ8G38_V.js";import{t as L}from"./badge-XEru6wto.js";import{t as R}from"./button-C3CQSr4p.js";import{t as z}from"./input-CXMbJ848.js";import{W as se,yt as B}from"./index-De1tR7J4.js";import{i as V,n as ce,o as H,r as U,s as W,t as G}from"./card-C5XTIPvq.js";import{t as le}from"./user-avatar-BOy9o2xK.js";var K=e(b(),1);function q(e){return`${e.namespace}/${e.key}`}function ue(e){return`/settings/${encodeURIComponent(e.namespace)}/${encodeURIComponent(e.key)}`}function de(e){return e.trim().toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)||`settings`}function fe(e){let t=new Map;for(let n of e.filter(e=>e.readable)){let e=n.display?.group?.trim()||n.namespace;t.set(e,[...t.get(e)??[],n])}return[...t.entries()].map(([e,t])=>({group:e,slug:de(e),settings:t.sort(pe)})).sort((e,t)=>me(e.settings)-me(t.settings)||e.group.localeCompare(t.group))}function pe(e,t){return(e.display?.order??2**53-1)-(t.display?.order??2**53-1)||e.display?.label?.localeCompare(t.display?.label??``)||q(e).localeCompare(q(t))}function me(e){return Math.min(...e.map(e=>e.display?.order??2**53-1))}function he(e){return Array.isArray(e.type)?e.type.find(e=>e!==`null`):e.type}function ge(e,t,n){if(!t.length)return n;let[r,...i]=t;if(r===void 0)return n;if(typeof r==`number`){let t=Array.isArray(e)?[...e]:[];return t[r]=ge(t[r],i,n),t}let a=ie(e)?{...e}:{},o=ge(a[r],i,n);return o===void 0?delete a[r]:a[r]=o,a}function _e(e){if(e.default!==void 0)return e.default;if(e.const!==void 0)return e.const;if(e.enum?.length)return e.enum[0];switch(he(e)){case`boolean`:return!1;case`integer`:case`number`:return 0;case`array`:return[];case`object`:return{};case`string`:return``;default:return}}function ve(e){return e.split(/\r?\n|,/).map(e=>e.trim()).filter(Boolean)}function ye(e){return Array.isArray(e)?e.map(e=>String(e)).join(`
2
+ `):``}function be(e){return ie(e)?Object.entries(e).map(([e,t])=>`${e}=${String(t??``)}`).join(`
3
+ `):``}function xe(e){return Object.fromEntries(e.split(/\r?\n/).map(e=>e.trim()).filter(Boolean).map(e=>{let t=e.indexOf(`=`);return t>=0?[e.slice(0,t).trim(),e.slice(t+1)]:[e,``]}))}var J=E(),Se=`__unset__`;function Ce(e){return e===`server-runtime`?`Server runtime`:e===`bootstrap`?`Bootstrap`:`Browser`}function we(e){return e===`server-runtime`?`Stored by Relay and mutable while the server is running.`:e===`bootstrap`?`Read from startup configuration; restart or host config changes are required.`:`Stored only in this browser profile.`}function Te(e){return e===`browser`?(0,J.jsx)(t,{className:`size-3.5`}):(0,J.jsx)(S,{className:`size-3.5`})}function Ee(e){return e.details??[]}function De({group:e,settings:t,onSaved:n}){let r=[...new Set(t.map(e=>e.tier))];return(0,J.jsxs)(`section`,{className:`space-y-3`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,J.jsx)(`h2`,{className:`text-base font-semibold`,children:e}),(0,J.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:r.map(e=>(0,J.jsxs)(L,{variant:`outline`,className:`gap-1`,title:we(e),children:[Te(e),Ce(e)]},e))})]}),t.length===0?(0,J.jsx)(G,{size:`sm`,children:(0,J.jsx)(U,{className:`text-sm text-muted-foreground`,children:`No settings in this group.`})}):(0,J.jsx)(`div`,{className:`space-y-3`,children:t.map(e=>(0,J.jsx)(Oe,{setting:e,onSaved:n},q(e)))})]})}function Oe({setting:e,onSaved:t}){let[n,r]=(0,K.useState)(()=>e.value??e.defaults??_e(e.schema)),[i,a]=(0,K.useState)(!1),[o,c]=(0,K.useState)(``),[l,u]=(0,K.useState)([]),d=e.writable&&e.tier===`server-runtime`;function f(e,t){r(n=>ge(n,e,t)),u([]),c(``)}async function p(){if(d){a(!0),u([]),c(``);try{let i=await x(`PUT`,ue(e),{value:n,updatedBy:`dashboard`});r(i.value),t(i),c(`Saved`)}catch(e){let t=Ee(e);u(t.length?t:[e.message])}finally{a(!1)}}}return(0,J.jsxs)(G,{size:`sm`,children:[(0,J.jsxs)(H,{children:[(0,J.jsxs)(W,{className:`flex flex-wrap items-center gap-2 text-sm`,children:[e.display.label,(0,J.jsxs)(L,{variant:`outline`,className:`gap-1`,title:we(e.tier),children:[Te(e.tier),Ce(e.tier)]}),!e.writable&&(0,J.jsx)(L,{variant:`secondary`,children:`Read only`})]}),e.display.description&&(0,J.jsx)(V,{children:e.display.description}),(0,J.jsx)(ce,{children:(0,J.jsxs)(R,{size:`sm`,onClick:p,disabled:!d||i,children:[(0,J.jsx)(s,{className:`size-4`}),i?`Saving`:`Save`]})})]}),(0,J.jsxs)(U,{className:`space-y-3`,children:[(0,J.jsx)(ke,{schema:e.schema,value:n,path:[],label:e.display.label,required:!0,disabled:!d||i,onChange:f}),(0,J.jsxs)(`p`,{className:`flex flex-wrap items-center gap-x-2 text-[11px] text-muted-foreground`,children:[(0,J.jsxs)(`code`,{className:`rounded bg-muted px-1.5 py-0.5 font-mono`,children:[e.namespace,`/`,e.key]}),(0,J.jsxs)(`span`,{children:[`read `,(0,J.jsx)(`span`,{className:`text-foreground/70`,children:e.scope.read})]}),(0,J.jsx)(`span`,{"aria-hidden":!0,children:`·`}),(0,J.jsxs)(`span`,{children:[`write `,(0,J.jsx)(`span`,{className:`text-foreground/70`,children:e.scope.write})]})]}),l.length>0&&(0,J.jsxs)(`div`,{className:`rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive`,children:[(0,J.jsxs)(`div`,{className:`mb-1 flex items-center gap-2 font-medium`,children:[(0,J.jsx)(O,{className:`size-4`}),`Save failed`]}),(0,J.jsx)(`ul`,{className:`list-disc space-y-1 pl-5`,children:l.map(e=>(0,J.jsx)(`li`,{children:e},e))})]}),o&&(0,J.jsxs)(`p`,{className:`flex items-center gap-1 text-sm text-emerald-500`,children:[(0,J.jsx)(ee,{className:`size-4`}),o]})]})]})}function ke(e){let{schema:t,value:n,path:r,label:i,required:a,disabled:o,onChange:s}=e,c=he(t);if(t.enum?.length){let e=n==null||n===``?Se:String(n);return(0,J.jsx)(Y,{label:i,description:t.description,children:(0,J.jsxs)(I,{value:e,onValueChange:e=>s(r,e===`__unset__`?void 0:e),disabled:o,children:[(0,J.jsx)(N,{children:(0,J.jsx)(M,{})}),(0,J.jsxs)(P,{children:[!a&&(0,J.jsx)(F,{value:`__unset__`,children:`Not set`}),t.enum.map(e=>(0,J.jsx)(F,{value:String(e),children:String(e)},String(e)))]})]})})}if(c===`boolean`)return(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-md border bg-muted/20 p-3`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`text-sm font-medium`,children:i}),t.description&&(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:t.description})]}),(0,J.jsx)(B,{checked:!!n,onCheckedChange:e=>s(r,e),disabled:o})]});if(c===`integer`||c===`number`)return(0,J.jsx)(Y,{label:i,description:t.description,children:(0,J.jsx)(z,{type:`number`,min:typeof t.minimum==`number`?t.minimum:void 0,max:typeof t.maximum==`number`?t.maximum:void 0,step:c===`integer`?1:`any`,value:typeof n==`number`?n:``,disabled:o,onChange:e=>s(r,e.target.value===``&&!a?void 0:Number(e.target.value))})});if(c===`array`)return(0,J.jsx)(Y,{label:i,description:t.description??`One item per line.`,children:(0,J.jsx)(se,{rows:Math.min(8,Math.max(3,Array.isArray(n)?n.length+1:3)),value:ye(n),disabled:o,onChange:e=>s(r,ve(e.target.value))})});if(c===`object`){let e=t.properties??{},a=new Set(t.required??[]);return Object.keys(e).length===0&&t.additionalProperties?(0,J.jsx)(Y,{label:i,description:t.description??`KEY=value, one entry per line.`,children:(0,J.jsx)(se,{rows:5,value:be(n),disabled:o,onChange:e=>s(r,xe(e.target.value))})}):(0,J.jsxs)(`div`,{className:`space-y-3`,children:[r.length>0&&(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`text-sm font-medium`,children:i}),t.description&&(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:t.description})]}),(0,J.jsx)(`div`,{className:`grid gap-3 md:grid-cols-2`,children:Object.entries(e).map(([e,t])=>{let i=ie(n)?n[e]:void 0;return(0,J.jsx)(ke,{schema:t,value:i===void 0&&a.has(e)?_e(t):i,path:[...r,e],label:t.title||Ae(e),required:a.has(e),disabled:o,onChange:s},e)})})]})}return(0,J.jsx)(Y,{label:i,description:t.description,children:(0,J.jsx)(z,{value:typeof n==`string`?n:n==null?``:String(n),disabled:o,onChange:e=>s(r,e.target.value===``&&!a?void 0:e.target.value)})})}function Y({label:e,description:t,children:n}){return(0,J.jsxs)(`label`,{className:`block space-y-1.5 text-sm`,children:[(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:e}),n,t&&(0,J.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:t})]})}function Ae(e){return e.replace(/([a-z0-9])([A-Z])/g,`$1 $2`).replace(/[-_]+/g,` `).replace(/^\w/,e=>e.toUpperCase())}function je(){let e=A(e=>e.theme),n=A(e=>e.showReasoning),r=A(e=>e.set);return(0,J.jsxs)(`section`,{className:`space-y-4`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`h2`,{className:`text-base font-semibold`,children:`Browser preferences`}),(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`These are stored in local dashboard state, not in Relay server config.`})]}),(0,J.jsxs)(G,{size:`sm`,children:[(0,J.jsxs)(H,{children:[(0,J.jsx)(W,{className:`text-sm`,children:`Dashboard display`}),(0,J.jsx)(V,{className:`text-xs`,children:`Browser tier · persisted in this browser profile.`}),(0,J.jsx)(ce,{children:(0,J.jsxs)(L,{variant:`outline`,className:`gap-1`,children:[(0,J.jsx)(t,{className:`size-3.5`}),`Browser`]})})]}),(0,J.jsxs)(U,{className:`grid gap-3 md:grid-cols-2`,children:[(0,J.jsx)(Y,{label:`Theme`,children:(0,J.jsxs)(I,{value:e,onValueChange:e=>r({theme:e}),children:[(0,J.jsx)(N,{children:(0,J.jsx)(M,{})}),(0,J.jsx)(P,{children:oe.map(e=>(0,J.jsx)(F,{value:e.id,children:e.label},e.id))})]})}),(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-md border bg-muted/20 p-3`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(l,{className:`size-4`}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`text-sm font-medium`,children:`Show reasoning details`}),(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Display captured reasoning/tool steps in chat. Server capture is controlled separately by provider reasoningCapture.`})]})]}),(0,J.jsx)(B,{checked:n,onCheckedChange:e=>r({showReasoning:e})})]})]})]}),(0,J.jsx)(Me,{})]})}function Me(){let e=A(e=>e.voiceTtsEnabled),t=A(e=>e.setVoiceTtsEnabled),n=A(e=>e.voiceTtsMode),r=A(e=>e.setVoiceTtsMode),i=A(e=>e.voiceTtsKokoroVoice),a=A(e=>e.setVoiceTtsKokoroVoice),o=A(e=>e.voiceTtsBrowserVoice),s=A(e=>e.setVoiceTtsBrowserVoice),c=A(e=>e.voiceInputMode),l=A(e=>e.setVoiceInputMode),[u,d]=(0,K.useState)(()=>te());(0,K.useEffect)(()=>{if(typeof window>`u`||!(`speechSynthesis`in window))return;let e=()=>d(te());return e(),window.speechSynthesis.addEventListener?.(`voiceschanged`,e),()=>window.speechSynthesis.removeEventListener?.(`voiceschanged`,e)},[]);let f=k.some(e=>e.id===i)?k:[...k,{id:i,label:i}];return(0,J.jsxs)(G,{size:`sm`,children:[(0,J.jsxs)(H,{children:[(0,J.jsxs)(W,{className:`flex items-center gap-2 text-sm`,children:[(0,J.jsx)(C,{className:`size-4`}),`Voice`]}),(0,J.jsx)(V,{className:`text-xs`,children:`Browser tier TTS and push-to-talk behavior.`}),(0,J.jsx)(ce,{children:(0,J.jsx)(B,{checked:e,onCheckedChange:t})})]}),(0,J.jsxs)(U,{className:`grid gap-3 md:grid-cols-2`,children:[(0,J.jsx)(Y,{label:`Speech engine`,children:(0,J.jsxs)(I,{value:n,onValueChange:e=>r(e),children:[(0,J.jsx)(N,{children:(0,J.jsx)(M,{})}),(0,J.jsxs)(P,{children:[(0,J.jsx)(F,{value:`kokoro`,children:`Kokoro (server, fallback to browser)`}),(0,J.jsx)(F,{value:`browser`,children:`Browser Web Speech API`})]})]})}),(0,J.jsx)(Y,{label:`Kokoro voice`,children:(0,J.jsxs)(I,{value:i,onValueChange:a,children:[(0,J.jsx)(N,{children:(0,J.jsx)(M,{})}),(0,J.jsx)(P,{children:f.map(e=>(0,J.jsx)(F,{value:e.id,children:e.label},e.id))})]})}),(0,J.jsx)(Y,{label:`Browser voice`,children:(0,J.jsxs)(I,{value:o||`__unset__`,onValueChange:e=>s(e===`__unset__`?``:e),children:[(0,J.jsx)(N,{children:(0,J.jsx)(M,{})}),(0,J.jsxs)(P,{children:[(0,J.jsx)(F,{value:Se,children:`System default`}),u.map(e=>(0,J.jsx)(F,{value:e.uri,children:e.label},e.uri))]})]})}),(0,J.jsx)(Y,{label:`Push-to-talk input`,children:(0,J.jsxs)(I,{value:c,onValueChange:e=>l(e),children:[(0,J.jsx)(N,{children:(0,J.jsx)(M,{})}),(0,J.jsxs)(P,{children:[(0,J.jsx)(F,{value:`compose`,children:`Fill message box`}),(0,J.jsx)(F,{value:`autosend`,children:`Send immediately`})]})]})})]})]})}function Ne({catalog:e,error:t,canWrite:n,onCatalog:i}){let s=e[0]?.provider??``,[c,l]=(0,K.useState)(s),[u,d]=(0,K.useState)(()=>Pe(s)),[f,p]=(0,K.useState)(``),[h,_]=(0,K.useState)([]),v=e.some(e=>e.provider===c)?c:s,b=e.find(e=>e.provider===v)??e[0],C=e.map(e=>e.provider);function w(e){d(t=>({...t,...e})),_([]),p(``)}function T(e){l(e),d(Pe(e)),_([]),p(``)}async function E(){i((await x(`GET`,`/providers`)).catalog)}async function D(){if(n){_([]),p(``);try{await x(`PUT`,`/providers/${encodeURIComponent(u.provider)}/models/${encodeURIComponent(u.alias)}`,{label:u.label,providerModel:u.providerModel,efforts:ve(u.efforts),defaultEffort:u.defaultEffort.trim()||void 0,limits:u.limits,capabilities:u.capabilities,contextThreshold:Fe(u),disabled:u.disabled,updatedBy:`dashboard`}),await E(),p(`${u.alias} saved`),d(Pe(u.provider))}catch(e){let t=Ee(e);_(t.length?t:[e.message])}}}async function O(e,t){if(n){_([]),p(``);try{await x(`PATCH`,`/providers/${encodeURIComponent(v)}/models/${encodeURIComponent(e.alias)}`,{disabled:t,updatedBy:`dashboard`}),await E(),p(`${e.alias} ${t?`disabled`:`enabled`}`)}catch(e){let t=Ee(e);_(t.length?t:[e.message])}}}async function te(e){if(n){_([]),p(``);try{await x(`DELETE`,`/providers/${encodeURIComponent(v)}/models/${encodeURIComponent(e.alias)}`),await E(),p(`${e.alias} removed`)}catch(e){let t=Ee(e);_(t.length?t:[e.message])}}}function ne(e){d({provider:v,alias:e.alias,label:e.label,providerModel:e.providerModel,efforts:e.efforts.join(`, `),defaultEffort:e.defaultEffort??``,selfCompactUtilization:e.contextThreshold?.selfCompactUtilization?.toString()??``,warnUtilization:e.contextThreshold?.warnUtilization?.toString()??``,hardBackstopUtilization:e.contextThreshold?.hardBackstopUtilization?.toString()??``,disabled:!!e.disabled,limits:e.limits,capabilities:e.capabilities}),_([]),p(``)}return t?(0,J.jsx)(G,{size:`sm`,children:(0,J.jsxs)(U,{className:`text-sm text-muted-foreground`,children:[(0,J.jsxs)(`div`,{className:`mb-1 flex items-center gap-2 font-medium text-foreground`,children:[(0,J.jsx)(r,{className:`size-4`}),`Model catalog`]}),t]})}):(0,J.jsxs)(`section`,{className:`space-y-4`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`h2`,{className:`text-base font-semibold`,children:`Model catalog`}),(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Add override models, disable unavailable models, or remove custom entries from the provider catalog.`})]}),!n&&(0,J.jsx)(L,{variant:`secondary`,children:`Read only: needs settings:write:provider`})]}),(0,J.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:C.map(e=>(0,J.jsx)(R,{variant:e===v?`default`:`outline`,size:`sm`,onClick:()=>T(e),children:e},e))}),(0,J.jsxs)(G,{size:`sm`,children:[(0,J.jsxs)(H,{children:[(0,J.jsx)(W,{className:`text-sm`,children:`Add or edit model`}),(0,J.jsx)(ce,{children:(0,J.jsxs)(L,{variant:`outline`,className:`gap-1`,children:[(0,J.jsx)(S,{className:`size-3.5`}),`Server runtime`]})})]}),(0,J.jsxs)(U,{className:`space-y-3`,children:[(0,J.jsxs)(`div`,{className:`grid gap-3 md:grid-cols-2`,children:[(0,J.jsx)(Y,{label:`Alias`,children:(0,J.jsx)(z,{value:u.alias,disabled:!n,placeholder:`nightly`,onChange:e=>w({alias:e.target.value.trim()})})}),(0,J.jsx)(Y,{label:`Label`,children:(0,J.jsx)(z,{value:u.label,disabled:!n,placeholder:`Nightly Codex`,onChange:e=>w({label:e.target.value})})}),(0,J.jsx)(Y,{label:`Provider model`,children:(0,J.jsx)(z,{value:u.providerModel,disabled:!n,placeholder:`codex-nightly`,onChange:e=>w({providerModel:e.target.value})})}),(0,J.jsx)(Y,{label:`Efforts`,children:(0,J.jsx)(z,{value:u.efforts,disabled:!n,placeholder:`low, medium, high`,onChange:e=>w({efforts:e.target.value})})}),(0,J.jsx)(Y,{label:`Default effort`,children:(0,J.jsx)(z,{value:u.defaultEffort,disabled:!n,placeholder:`medium`,onChange:e=>w({defaultEffort:e.target.value})})}),(0,J.jsx)(Y,{label:`Self compact utilization`,children:(0,J.jsx)(z,{value:u.selfCompactUtilization,disabled:!n,placeholder:`0.80`,inputMode:`decimal`,onChange:e=>w({selfCompactUtilization:e.target.value})})}),(0,J.jsx)(Y,{label:`Warn utilization`,children:(0,J.jsx)(z,{value:u.warnUtilization,disabled:!n,placeholder:`default: self - 0.10`,inputMode:`decimal`,onChange:e=>w({warnUtilization:e.target.value})})}),(0,J.jsx)(Y,{label:`Hard backstop utilization`,children:(0,J.jsx)(z,{value:u.hardBackstopUtilization,disabled:!n,placeholder:`0.90`,inputMode:`decimal`,onChange:e=>w({hardBackstopUtilization:e.target.value})})}),(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-md border bg-muted/20 p-3`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`text-sm font-medium`,children:`Disabled`}),(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Keep visible but unavailable for new launches.`})]}),(0,J.jsx)(B,{checked:u.disabled,disabled:!n,onCheckedChange:e=>w({disabled:e})})]})]}),(0,J.jsxs)(R,{onClick:D,disabled:!n||!u.alias||!u.label||!u.providerModel,children:[(0,J.jsx)(a,{className:`size-4`}),`Save model`]})]})]}),(0,J.jsxs)(`div`,{className:`space-y-2`,children:[b&&b.models.length===0&&(0,J.jsx)(G,{size:`sm`,children:(0,J.jsx)(U,{className:`text-sm text-muted-foreground`,children:`No models in this provider catalog yet.`})}),b?.models.map(e=>(0,J.jsx)(G,{size:`sm`,children:(0,J.jsxs)(U,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,J.jsxs)(`div`,{className:`min-w-0`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,J.jsx)(`span`,{className:`font-medium`,children:e.label}),(0,J.jsx)(`code`,{className:`rounded bg-muted px-1.5 py-0.5 font-mono text-xs`,children:e.alias}),e.disabled&&(0,J.jsx)(L,{variant:`secondary`,children:`Disabled`})]}),(0,J.jsxs)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:[e.providerModel,e.efforts.length>0?` · efforts ${e.efforts.join(`, `)}`:` · no effort levels`,e.defaultEffort?` · default ${e.defaultEffort}`:``,` · context ${Le(e)}`]})]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,J.jsxs)(R,{variant:`outline`,size:`sm`,onClick:()=>ne(e),children:[(0,J.jsx)(o,{className:`size-4`}),`Edit`]}),(0,J.jsxs)(R,{variant:`outline`,size:`sm`,disabled:!n,onClick:()=>void O(e,!e.disabled),children:[e.disabled?(0,J.jsx)(g,{className:`size-4`}):(0,J.jsx)(m,{className:`size-4`}),e.disabled?`Enable`:`Disable`]}),(0,J.jsxs)(R,{variant:`outline`,size:`sm`,disabled:!n,onClick:()=>void te(e),children:[(0,J.jsx)(y,{className:`size-4`}),`Remove`]})]})]})},e.alias))]}),h.length>0&&(0,J.jsx)(`div`,{className:`rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive`,children:(0,J.jsx)(`ul`,{className:`list-disc space-y-1 pl-5`,children:h.map(e=>(0,J.jsx)(`li`,{children:e},e))})}),f&&(0,J.jsxs)(`p`,{className:`flex items-center gap-1 text-sm text-emerald-500`,children:[(0,J.jsx)(ee,{className:`size-4`}),f]})]})}function Pe(e){return{provider:e,alias:``,label:``,providerModel:``,efforts:``,defaultEffort:``,selfCompactUtilization:``,warnUtilization:``,hardBackstopUtilization:``,disabled:!1}}function Fe(e){let t=Ie(e.selfCompactUtilization,`Self compact utilization`),n=Ie(e.warnUtilization,`Warn utilization`),r=Ie(e.hardBackstopUtilization,`Hard backstop utilization`);if(!(t===void 0&&n===void 0&&r===void 0)){if(t===void 0)throw Error(`Self compact utilization is required when setting context thresholds`);return{selfCompactUtilization:t,...n===void 0?{}:{warnUtilization:n},...r===void 0?{}:{hardBackstopUtilization:r}}}}function Ie(e,t){let n=e.trim();if(!n)return;let r=Number(n);if(!Number.isFinite(r))throw Error(`${t} must be a number`);return r}function Le(e){if(e.contextThreshold)return`self ${Re(e.contextThreshold.selfCompactUtilization)}, warn ${Re(e.contextThreshold.warnUtilization??Math.max(0,e.contextThreshold.selfCompactUtilization-.1))}`;let t=ne(e.limits?.contextWindowTokens?.value);return`derived self ${Re(t.selfCompactUtilization)}, warn ${Re(t.warnUtilization)}`}function Re(e){return`${Math.round(e*100)}%`}var ze=5,Be=15,Ve={claude:`Claude`,codex:`Codex`};function He(e){return Math.round(e/6e4)}function Ue(e){return`${He(e)} min`}function We({canWrite:e}){let[t,n]=(0,K.useState)(null),[r,i]=(0,K.useState)(``),[a,o]=(0,K.useState)(``),[s,c]=(0,K.useState)(null);(0,K.useEffect)(()=>{let e=!1;return(async()=>{try{let t=await x(`GET`,`/providers/quota-config`);e||n(t)}catch(t){e||i(t.message)}})(),()=>{e=!0}},[]);async function l(e,t){n(n=>({...n??{},[e]:t})),o(``),c(e);try{let r=await x(`PUT`,`/providers/${e}/quota-config`,t);n(t=>({...t??{},[e]:r}))}catch(t){o(`${Ve[e]??e}: ${t.message}`)}finally{c(null)}}let d=t?Object.keys(t).sort():[];return(0,J.jsxs)(`section`,{className:`space-y-4`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`h2`,{className:`text-base font-semibold`,children:`Quota`}),(0,J.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Per-provider quota collection and display. `,(0,J.jsx)(`strong`,{children:`Enabled`}),` governs collection (disabled stops polling — no API calls);`,(0,J.jsx)(`strong`,{children:` Show in widget`}),` governs display only.`]})]}),r&&(0,J.jsxs)(`div`,{className:`flex items-start gap-2 rounded-lg border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive`,children:[(0,J.jsx)(O,{className:`mt-0.5 size-4`}),(0,J.jsx)(`span`,{children:r})]}),a&&(0,J.jsxs)(`div`,{className:`flex items-start gap-2 rounded-lg border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive`,children:[(0,J.jsx)(O,{className:`mt-0.5 size-4`}),(0,J.jsx)(`span`,{children:a})]}),!t&&!r&&(0,J.jsx)(G,{size:`sm`,children:(0,J.jsxs)(U,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,J.jsx)(T,{className:`size-4 animate-spin`}),`Loading quota config…`]})}),d.map(r=>{let i=t[r],a=!e||s===r;return(0,J.jsxs)(G,{size:`sm`,children:[(0,J.jsxs)(H,{children:[(0,J.jsxs)(W,{className:`flex items-center gap-2 text-sm`,children:[(0,J.jsx)(u,{className:`size-4`}),Ve[r]??r,s===r&&(0,J.jsx)(T,{className:`size-3 animate-spin text-muted-foreground`})]}),(0,J.jsxs)(V,{className:`text-xs`,children:[i.enabled?`Polled every ${Ue(i.pollIntervalMs)}`:`Collection disabled`,i.enabled&&!i.showInWidget?` · hidden from widget`:``]})]}),(0,J.jsxs)(U,{className:`space-y-4`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-md border bg-muted/20 p-3`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`text-sm font-medium`,children:`Enabled`}),(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Collect quota for this provider. Off stops all polling (no API calls, no token spend).`})]}),(0,J.jsx)(B,{checked:i.enabled,disabled:a,onCheckedChange:e=>void l(r,{...i,enabled:e})})]}),(0,J.jsxs)(`div`,{className:`rounded-md border bg-muted/20 p-3 space-y-2`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,J.jsx)(`div`,{className:`text-sm font-medium`,children:`Polling interval`}),(0,J.jsx)(L,{variant:`outline`,className:`tabular-nums`,children:Ue(i.pollIntervalMs)})]}),(0,J.jsx)(`input`,{type:`range`,min:ze,max:Be,step:1,value:He(i.pollIntervalMs),disabled:a||!i.enabled,onChange:e=>{let t=Number(e.target.value)*6e4;n(e=>({...e??{},[r]:{...i,pollIntervalMs:t}}))},onPointerUp:e=>void l(r,{...i,pollIntervalMs:Number(e.target.value)*6e4}),onKeyUp:e=>void l(r,{...i,pollIntervalMs:Number(e.target.value)*6e4}),className:`w-full accent-primary disabled:opacity-50`}),(0,J.jsxs)(`div`,{className:`flex justify-between text-[10px] text-muted-foreground`,children:[(0,J.jsxs)(`span`,{children:[ze,` min`]}),(0,J.jsxs)(`span`,{children:[Be,` min`]})]})]}),(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-md border bg-muted/20 p-3`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`text-sm font-medium`,children:`Show in quota widget`}),(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Display only. Off hides this provider from the dashboard widget; collection continues if enabled.`})]}),(0,J.jsx)(B,{checked:i.showInWidget,disabled:a,onCheckedChange:e=>void l(r,{...i,showInWidget:e})})]}),(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-md border bg-muted/20 p-3`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`text-sm font-medium`,children:`Burn-rate sparkline`}),(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Show a mini utilization chart per window in the expanded widget.`})]}),(0,J.jsx)(B,{checked:i.sparklineEnabled??!0,disabled:a,onCheckedChange:e=>void l(r,{...i,sparklineEnabled:e})})]}),(0,J.jsxs)(`div`,{className:`rounded-md border bg-muted/20 p-3 space-y-2`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,J.jsx)(`div`,{className:`text-sm font-medium`,children:`Sparkline range`}),(0,J.jsxs)(L,{variant:`outline`,className:`tabular-nums`,children:[i.sparklineRangeHours??8,`h`]})]}),(0,J.jsx)(`input`,{type:`range`,min:1,max:8,step:1,value:i.sparklineRangeHours??8,disabled:a||!(i.sparklineEnabled??!0),onChange:e=>{let t=Number(e.target.value);n(e=>({...e??{},[r]:{...i,sparklineRangeHours:t}}))},onPointerUp:e=>void l(r,{...i,sparklineRangeHours:Number(e.target.value)}),onKeyUp:e=>void l(r,{...i,sparklineRangeHours:Number(e.target.value)}),className:`w-full accent-primary disabled:opacity-50`}),(0,J.jsxs)(`div`,{className:`flex justify-between text-[10px] text-muted-foreground`,children:[(0,J.jsx)(`span`,{children:`1h`}),(0,J.jsx)(`span`,{children:`8h`})]})]})]})]},r)})]})}function Ge({message:e}){return(0,J.jsxs)(`div`,{className:`flex items-start gap-2 rounded-lg border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive`,children:[(0,J.jsx)(O,{className:`mt-0.5 size-4 shrink-0`}),(0,J.jsx)(`span`,{children:e})]})}var Ke=re(),X={cautionAt:.15,avoidLargeAt:.5,hardAvoidAt:1},qe=.99,Je=.5;function Z(e,t){return((e??t)*100).toFixed(0)}function Q(e){let t=e.trim();if(!t)return null;let n=Number(t);return!Number.isFinite(n)||n<0||n>100?null:n/100}function Ye(e,t){return e.trim()?Q(e):t}function Xe({policy:e,canWrite:t,onPolicy:n}){let r=e.quotaBands,i=e.providerQuota??{},[a,o]=(0,K.useState)(Z(r?.cautionAt,X.cautionAt)),[c,l]=(0,K.useState)(Z(r?.avoidLargeAt,X.avoidLargeAt)),[u,d]=(0,K.useState)(Z(r?.hardAvoidAt,X.hardAvoidAt)),[f,p]=(0,K.useState)(()=>{let e={};for(let t of Ke){let n=i[t]??{};e[t]={backstop:Z(n.hardBackstopUtilization,qe),floor:Z(n.burnPenaltyUtilizationFloor,Je)}}return e}),[m,h]=(0,K.useState)(!1),[g,_]=(0,K.useState)(``),[v,y]=(0,K.useState)(!1),[b,S]=(0,K.useState)(``);async function C(){let t=Q(a),r=Q(c),i=Q(u);if(t===null){S(`Caution threshold must be 0–100%.`);return}if(r===null){S(`Avoid-large threshold must be 0–100%.`);return}if(i===null){S(`Hard-avoid threshold must be 0–100%.`);return}if(t>=r){S(`Caution must be less than avoid-large.`);return}if(r>=i){S(`Avoid-large must be less than hard-avoid.`);return}let o={};for(let e of Ke){let t=f[e],n=Ye(t.backstop,qe),r=Q(t.floor);if(n===null){S(`${j(e)}: hard-backstop must be 0–100%.`);return}if(r===null){S(`${j(e)}: burn-penalty floor must be 0–100%.`);return}o[e]={hardBackstopUtilization:n,burnPenaltyUtilizationFloor:r}}S(``),h(!0),_(``),y(!1);try{n(await x(`PUT`,`/routing-policy`,{...e,quotaBands:{cautionAt:t,avoidLargeAt:r,hardAvoidAt:i},providerQuota:o})),y(!0),setTimeout(()=>y(!1),2e3)}catch(e){_(e.message)}finally{h(!1)}}function w(e,t){p(n=>({...n,[e]:{...n[e],...t}})),S(``),y(!1)}function E(){S(``),y(!1)}return(0,J.jsxs)(G,{size:`sm`,children:[(0,J.jsxs)(H,{children:[(0,J.jsx)(W,{className:`text-sm`,children:`Quota thresholds`}),(0,J.jsx)(V,{className:`text-xs`,children:`Band cutoffs govern when the orchestrator starts penalising or blocking high-quota providers. Values are utilization percentages (0–100).`})]}),(0,J.jsxs)(U,{className:`space-y-4`,children:[(g||b)&&(0,J.jsx)(Ge,{message:g||b}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`mb-2 text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:`Band cutoffs`}),(0,J.jsx)(Ze,{caution:Number(a),avoidLarge:Number(c),hardAvoid:Number(u)}),(0,J.jsxs)(`div`,{className:`mt-3 grid gap-3 sm:grid-cols-3`,children:[(0,J.jsx)($,{label:`Caution at`,hint:`Default: ${(X.cautionAt*100).toFixed(0)}%`,value:a,disabled:!t||m,onChange:e=>{o(e),E()}}),(0,J.jsx)($,{label:`Avoid-large at`,hint:`Default: ${(X.avoidLargeAt*100).toFixed(0)}%`,value:c,disabled:!t||m,onChange:e=>{l(e),E()}}),(0,J.jsx)($,{label:`Hard-avoid at`,hint:`Default: ${(X.hardAvoidAt*100).toFixed(0)}%`,value:u,disabled:!t||m,onChange:e=>{d(e),E()}})]})]}),Ke.map(e=>{let n=f[e];return(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`div`,{className:`mb-2 text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:[j(e),` overrides`]}),(0,J.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,J.jsx)($,{label:`Hard-backstop utilization`,hint:`0 = disable backstop (never block on this quota); blank uses the ${(qe*100).toFixed(0)}% default.`,value:n.backstop,disabled:!t||m,onChange:t=>w(e,{backstop:t})}),(0,J.jsx)($,{label:`Burn-penalty floor`,hint:`Penalties suppressed below this. Default: ${(Je*100).toFixed(0)}%`,value:n.floor,disabled:!t||m,onChange:t=>w(e,{floor:t})})]})]},e)}),t&&(0,J.jsxs)(R,{size:`sm`,onClick:()=>void C(),disabled:m,children:[m?(0,J.jsx)(T,{className:`size-4 animate-spin`}):(0,J.jsx)(s,{className:`size-4`}),v?`Saved`:`Save thresholds`]})]})]})}function Ze({caution:e,avoidLarge:t,hardAvoid:n}){let r=e=>Math.max(0,Math.min(100,Number.isFinite(e)?e:0)),i=r(e),a=Math.max(i,r(t)),o=Math.max(a,r(n)),s=e=>`${e.toFixed(0)}%`,c=[{key:`normal`,label:`normal`,color:`bg-emerald-500`,from:0,to:i,range:`0–${s(i)}`},{key:`caution`,label:`caution`,color:`bg-amber-500`,from:i,to:a,range:`${s(i)}–${s(a)}`},{key:`avoid-large`,label:`avoid large`,color:`bg-orange-500`,from:a,to:o,range:`${s(a)}–${s(o)}`},{key:`hard-avoid`,label:`hard avoid`,color:`bg-red-500`,from:o,to:100,range:`≥ ${s(o)}`}];return(0,J.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,J.jsx)(`div`,{className:`flex h-2.5 overflow-hidden rounded-full bg-muted`,role:`img`,"aria-label":`Quota penalty bands from 0 to 100 percent`,children:c.map(e=>(0,J.jsx)(`div`,{className:D(e.color,`transition-[width] duration-300`),style:{width:`${e.to-e.from}%`},title:`${e.label} · ${e.range}`},e.key))}),(0,J.jsx)(`div`,{className:`flex flex-wrap gap-x-3 gap-y-1 text-[10px] text-muted-foreground`,children:c.map(e=>(0,J.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(`span`,{className:D(`size-2 shrink-0 rounded-full`,e.color)}),e.label,` `,(0,J.jsx)(`span`,{className:`tabular-nums text-foreground/70`,children:e.range})]},e.key))})]})}function $({label:e,hint:t,value:n,disabled:r,onChange:i}){return(0,J.jsxs)(`label`,{className:`space-y-1`,children:[(0,J.jsx)(`span`,{className:`text-[10px] font-medium text-muted-foreground`,children:e}),(0,J.jsxs)(`div`,{className:`relative`,children:[(0,J.jsx)(z,{value:n,onChange:e=>i(e.target.value),disabled:r,className:`h-8 pr-6 text-xs tabular-nums`}),(0,J.jsx)(`span`,{className:`pointer-events-none absolute inset-y-0 right-2.5 flex items-center text-xs text-muted-foreground`,children:`%`})]}),(0,J.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:t})]})}function Qe(){let[e,t]=(0,K.useState)(null),[n,r]=(0,K.useState)(!1),[a,o]=(0,K.useState)(``),[s,c]=(0,K.useState)(!1),[l,u]=(0,K.useState)(!1);async function p(){if(!l){r(!0),o(``);try{let[e,n]=await Promise.all([x(`GET`,`/routing-policy`),x(`GET`,`/agent-profiles/coordinator`).catch(()=>null)]);t({policy:e,profile:n}),u(!0)}catch(e){o(e.message)}finally{r(!1)}}}async function m(){u(!1),r(!0),o(``);try{let[e,n]=await Promise.all([x(`GET`,`/routing-policy`),x(`GET`,`/agent-profiles/coordinator`).catch(()=>null)]);t({policy:e,profile:n}),u(!0)}catch(e){o(e.message)}finally{r(!1)}}function h(){let e=!s;c(e),e&&!l&&p()}return(0,J.jsx)(G,{size:`sm`,children:(0,J.jsxs)(U,{className:`space-y-3`,children:[(0,J.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 text-left`,onClick:h,children:[(0,J.jsx)(g,{className:`size-4 text-muted-foreground`}),(0,J.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,J.jsx)(`div`,{className:`text-sm font-semibold`,children:`What your coordinator knows`}),(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Active routing policy + coordinator profile instructions (read-only)`})]}),s?(0,J.jsx)(f,{className:`size-4 shrink-0 text-muted-foreground`}):(0,J.jsx)(i,{className:`size-4 shrink-0 text-muted-foreground`})]}),s&&(0,J.jsxs)(`div`,{className:`space-y-4 pt-1`,children:[(0,J.jsx)(`div`,{className:`flex justify-end`,children:(0,J.jsxs)(R,{variant:`outline`,size:`sm`,onClick:()=>void m(),disabled:n,children:[(0,J.jsx)(d,{className:D(`size-3.5`,n&&`animate-spin`)}),`Refresh`]})}),a&&(0,J.jsx)(Ge,{message:a}),n&&!e&&(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground py-2`,children:[(0,J.jsx)(T,{className:`size-3.5 animate-spin`}),`Loading…`]}),e&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)($e,{policy:e.policy}),e.profile?(0,J.jsx)(tt,{profile:e.profile}):(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:`Coordinator profile not found.`})]})]})]})})}function $e({policy:e}){let t=e.quotaBands,n=e.providerQuota??{};return(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsx)(`div`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wide`,children:`Active routing policy`}),e.rules.length===0?(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:`No rules — coordinators use their own heuristics.`}):(0,J.jsxs)(`div`,{className:`overflow-hidden rounded-md border border-border text-xs`,children:[(0,J.jsxs)(`div`,{className:`grid grid-cols-[1.5rem_minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)] gap-px bg-border text-[10px] font-medium text-muted-foreground uppercase tracking-wide`,children:[(0,J.jsx)(`div`,{className:`bg-muted/40 px-2 py-1.5`,children:`#`}),(0,J.jsx)(`div`,{className:`bg-muted/40 px-2 py-1.5`,children:`Match`}),(0,J.jsx)(`div`,{className:`bg-muted/40 px-2 py-1.5`,children:`Target`}),(0,J.jsx)(`div`,{className:`bg-muted/40 px-2 py-1.5`,children:`Status`})]}),e.rules.map((e,t)=>(0,J.jsxs)(`div`,{className:D(`grid grid-cols-[1.5rem_minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)] gap-px bg-border`,e.enabled===!1&&`opacity-50`),children:[(0,J.jsx)(`div`,{className:`bg-card px-2 py-1.5 text-muted-foreground tabular-nums`,children:t+1}),(0,J.jsxs)(`div`,{className:`bg-card px-2 py-1.5`,children:[e.label&&(0,J.jsx)(`div`,{className:`font-medium`,children:e.label}),e.match.taskType&&(0,J.jsxs)(`div`,{className:`font-mono`,children:[`task: `,e.match.taskType]}),e.match.capability&&(0,J.jsxs)(`div`,{className:`font-mono`,children:[`cap: `,e.match.capability]})]}),(0,J.jsxs)(`div`,{className:`bg-card px-2 py-1.5`,children:[(0,J.jsx)(`span`,{className:`font-medium`,children:e.target.provider}),e.target.model&&(0,J.jsxs)(`span`,{className:`text-muted-foreground`,children:[` / `,e.target.model]}),e.target.effort&&(0,J.jsxs)(`span`,{className:`text-muted-foreground`,children:[` (`,e.target.effort,`)`]})]}),(0,J.jsx)(`div`,{className:`bg-card px-2 py-1.5`,children:e.enabled===!1?(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:`disabled`}):(0,J.jsx)(`span`,{className:`text-emerald-500`,children:`active`})})]},t))]}),(t||Object.keys(n).length>0)&&(0,J.jsxs)(`div`,{className:`rounded-md border border-border bg-muted/10 px-3 py-2 text-xs space-y-1`,children:[t&&(0,J.jsxs)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-0.5`,children:[t.cautionAt!==void 0&&(0,J.jsxs)(`span`,{children:[`caution ≥ `,(t.cautionAt*100).toFixed(0),`%`]}),t.avoidLargeAt!==void 0&&(0,J.jsxs)(`span`,{children:[`avoid-large ≥ `,(t.avoidLargeAt*100).toFixed(0),`%`]}),t.hardAvoidAt!==void 0&&(0,J.jsxs)(`span`,{children:[`hard-avoid ≥ `,(t.hardAvoidAt*100).toFixed(0),`%`]})]}),Object.entries(n).map(([e,t])=>(0,J.jsxs)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-0.5 text-muted-foreground`,children:[(0,J.jsx)(`span`,{className:`font-medium text-foreground`,children:j(e)}),t?.hardBackstopUtilization!==void 0&&(0,J.jsxs)(`span`,{children:[`backstop: `,(t.hardBackstopUtilization*100).toFixed(0),`%`]}),t?.burnPenaltyUtilizationFloor!==void 0&&(0,J.jsxs)(`span`,{children:[`floor: `,(t.burnPenaltyUtilizationFloor*100).toFixed(0),`%`]})]},e))]})]})}function et({text:e,index:t}){return(0,J.jsxs)(`div`,{className:`relative max-h-72 overflow-y-auto rounded-md border border-border bg-muted/20`,children:[t!==void 0&&(0,J.jsxs)(`span`,{className:`sticky top-0 float-right m-1.5 rounded bg-muted px-1.5 py-0.5 text-[9px] font-medium tabular-nums text-muted-foreground`,children:[`#`,t]}),(0,J.jsx)(`pre`,{className:`whitespace-pre-wrap break-words px-3 py-2.5 font-sans text-[11px] leading-relaxed text-foreground/90`,children:e})]})}function tt({profile:e}){return(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsxs)(`div`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wide`,children:[`Coordinator profile instructions`,(0,J.jsx)(L,{variant:`secondary`,className:`ml-2 text-[10px]`,children:e.name}),e.builtIn&&(0,J.jsx)(L,{variant:`outline`,className:`ml-1 text-[10px]`,children:`built-in`})]}),e.description&&(0,J.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.description}),(0,J.jsxs)(`div`,{className:`flex flex-wrap gap-2 text-[10px]`,children:[(0,J.jsxs)(L,{variant:`outline`,children:[`base: `,e.base]}),(0,J.jsxs)(L,{variant:`outline`,children:[`repo: `,e.instructions.repoInstructions]}),(0,J.jsxs)(L,{variant:`outline`,children:[`global: `,e.instructions.globalInstructions]}),e.provider&&(0,J.jsxs)(L,{variant:`outline`,children:[`provider: `,e.provider]})]}),e.instructions.system&&(0,J.jsxs)(`div`,{className:`space-y-1`,children:[(0,J.jsx)(`div`,{className:`text-[10px] font-medium text-muted-foreground uppercase tracking-wide`,children:`System prompt`}),(0,J.jsx)(et,{text:e.instructions.system})]}),e.instructions.append.length>0&&(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsxs)(`div`,{className:`text-[10px] font-medium text-muted-foreground uppercase tracking-wide`,children:[`Appended instructions (`,e.instructions.append.length,`)`]}),e.instructions.append.map((e,t)=>(0,J.jsx)(et,{text:e,index:t+1},t))]}),e.instructions.append.length===0&&!e.instructions.system&&(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:`No instruction blocks defined.`})]})}var nt=re();function rt(){return{label:``,matchTaskType:``,matchCapability:``,targetProvider:nt[0]??``,targetModel:``,targetEffort:``,enabled:!0}}function it(e){return{label:e.label??``,matchTaskType:e.match.taskType??``,matchCapability:e.match.capability??``,targetProvider:e.target.provider,targetModel:e.target.model??``,targetEffort:e.target.effort??``,enabled:e.enabled!==!1}}function at(e){return{...e.label.trim()?{label:e.label.trim()}:{},match:{...e.matchTaskType.trim()?{taskType:e.matchTaskType.trim()}:{},...e.matchCapability.trim()?{capability:e.matchCapability.trim()}:{}},target:{provider:e.targetProvider,...e.targetModel.trim()?{model:e.targetModel.trim()}:{},...e.targetEffort.trim()?{effort:e.targetEffort.trim()}:{}},enabled:e.enabled}}function ot(e){return!e.matchTaskType.trim()&&!e.matchCapability.trim()?`At least one match criterion (task type or capability) is required.`:null}function st({message:e}){return(0,J.jsxs)(`div`,{className:`flex items-start gap-2 rounded-lg border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive`,children:[(0,J.jsx)(O,{className:`mt-0.5 size-4 shrink-0`}),(0,J.jsx)(`span`,{children:e})]})}function ct({canWrite:e}){let[t,n]=(0,K.useState)(null),[r,i]=(0,K.useState)(!1),[a,o]=(0,K.useState)(``),[s,c]=(0,K.useState)(!1);!s&&!r&&!a&&(i(!0),(async()=>{try{n(await x(`GET`,`/routing-policy`)),c(!0)}catch(e){o(e.message)}finally{i(!1)}})());async function l(){i(!0),o(``);try{n(await x(`GET`,`/routing-policy`)),c(!0)}catch(e){o(e.message)}finally{i(!1)}}return(0,J.jsxs)(`div`,{className:`space-y-6`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`h2`,{className:`text-base font-semibold`,children:`Routing`}),(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Declarative rules mapping task types and capabilities to providers. Rules are advisory — coordinators apply them; explicit per-spawn arguments always take precedence.`})]}),(0,J.jsxs)(R,{variant:`outline`,size:`sm`,onClick:()=>void l(),disabled:r,children:[(0,J.jsx)(d,{className:D(`size-4`,r&&`animate-spin`)}),`Refresh`]})]}),a&&(0,J.jsx)(st,{message:a}),r&&!t&&(0,J.jsx)(G,{size:`sm`,children:(0,J.jsxs)(U,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,J.jsx)(T,{className:`size-4 animate-spin`}),`Loading routing policy…`]})}),t&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(lt,{policy:t,canWrite:e,onPolicy:n}),(0,J.jsx)(Xe,{policy:t,canWrite:e,onPolicy:n})]}),(0,J.jsx)(Qe,{})]})}function lt({policy:e,canWrite:t,onPolicy:n}){let[r,i]=(0,K.useState)(!1),[o,s]=(0,K.useState)(``),[l,u]=(0,K.useState)(!1),[d,f]=(0,K.useState)(rt),[p,m]=(0,K.useState)(``),[h,g]=(0,K.useState)(null),[_,v]=(0,K.useState)(rt),[y,b]=(0,K.useState)(``);async function S(e){i(!0),s(``);try{n(await x(`PUT`,`/routing-policy`,e))}catch(e){s(e.message)}finally{i(!1)}}function C(t,n){let r=[...e.rules],i=t+n;i<0||i>=r.length||([r[t],r[i]]=[r[i],r[t]],S({...e,rules:r}))}function w(t){let n=e.rules.map((e,n)=>n===t?{...e,enabled:e.enabled===!1}:e);S({...e,rules:n})}function E(t){S({...e,rules:e.rules.filter((e,n)=>n!==t)})}function D(){f(rt()),m(``),u(!0)}function O(){u(!1),m(``)}function ee(){let t=ot(d);if(t){m(t);return}u(!1),S({...e,rules:[...e.rules,at(d)]})}function te(t){g(t),v(it(e.rules[t])),b(``)}function ne(){g(null),b(``)}function k(){if(h===null)return;let t=ot(_);if(t){b(t);return}let n=e.rules.map((e,t)=>t===h?at(_):e);g(null),S({...e,rules:n})}return(0,J.jsxs)(G,{size:`sm`,children:[(0,J.jsxs)(H,{children:[(0,J.jsxs)(W,{className:`flex items-center gap-2 text-sm`,children:[(0,J.jsx)(c,{className:`size-4`}),`Rules`,(0,J.jsxs)(L,{variant:`outline`,className:`ml-auto text-[10px]`,children:[e.rules.length,` rule`,e.rules.length===1?``:`s`]}),r&&(0,J.jsx)(T,{className:`size-3 animate-spin text-muted-foreground`})]}),(0,J.jsx)(V,{className:`text-xs`,children:`Evaluated in order — first matching enabled rule wins. Rules are advisory; explicit spawn arguments override them.`})]}),(0,J.jsxs)(U,{className:`space-y-2`,children:[o&&(0,J.jsx)(st,{message:o}),e.rules.length===0&&!l&&(0,J.jsx)(`div`,{className:`rounded-md border border-dashed border-border py-6 text-center text-xs text-muted-foreground`,children:`No rules — coordinators fall back to their own heuristics.`}),e.rules.map((n,i)=>h===i?(0,J.jsx)(dt,{form:_,error:y,onChange:v,onSave:k,onCancel:ne},i):(0,J.jsx)(ut,{rule:n,idx:i,total:e.rules.length,canWrite:t,saving:r,onMoveUp:()=>C(i,-1),onMoveDown:()=>C(i,1),onToggle:()=>w(i),onEdit:()=>te(i),onRemove:()=>E(i)},i)),l&&(0,J.jsx)(dt,{form:d,error:p,onChange:f,onSave:ee,onCancel:O,isNew:!0}),t&&!l&&h===null&&(0,J.jsxs)(R,{variant:`outline`,size:`sm`,className:`w-full gap-1`,onClick:D,disabled:r,children:[(0,J.jsx)(a,{className:`size-4`}),`Add rule`]})]})]})}function ut({rule:e,idx:t,total:n,canWrite:r,saving:i,onMoveUp:a,onMoveDown:o,onToggle:s,onEdit:c,onRemove:l}){return(0,J.jsxs)(`div`,{className:D(`group flex items-start gap-3 rounded-md border bg-muted/20 p-3`,e.enabled===!1&&`opacity-60`),children:[(0,J.jsxs)(`div`,{className:`flex flex-col items-center gap-0.5 pt-0.5`,children:[(0,J.jsx)(`button`,{type:`button`,title:`Move up`,onClick:a,disabled:!r||i||t===0,className:`rounded p-0.5 text-muted-foreground hover:bg-accent hover:text-foreground disabled:pointer-events-none disabled:opacity-30`,children:(0,J.jsx)(p,{className:`size-3.5`})}),(0,J.jsx)(`button`,{type:`button`,title:`Move down`,onClick:o,disabled:!r||i||t===n-1,className:`rounded p-0.5 text-muted-foreground hover:bg-accent hover:text-foreground disabled:pointer-events-none disabled:opacity-30`,children:(0,J.jsx)(h,{className:`size-3.5`})})]}),(0,J.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-1`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsxs)(`span`,{className:`text-[10px] tabular-nums text-muted-foreground`,children:[`#`,t+1]}),e.label&&(0,J.jsx)(`span`,{className:`text-xs font-medium`,children:e.label}),(0,J.jsx)(L,{variant:`outline`,className:`text-[10px]`,children:e.target.provider}),e.target.model&&(0,J.jsx)(L,{variant:`outline`,className:`text-[10px] font-mono`,children:e.target.model}),e.target.effort&&(0,J.jsx)(L,{variant:`outline`,className:`text-[10px]`,children:e.target.effort})]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap gap-x-3 gap-y-0.5 text-[10px] text-muted-foreground`,children:[e.match.taskType&&(0,J.jsxs)(`span`,{children:[`task-type: `,(0,J.jsx)(`span`,{className:`font-mono text-foreground`,children:e.match.taskType})]}),e.match.capability&&(0,J.jsxs)(`span`,{children:[`capability: `,(0,J.jsx)(`span`,{className:`font-mono text-foreground`,children:e.match.capability})]})]})]}),(0,J.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 opacity-70 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100`,children:[(0,J.jsx)(B,{checked:e.enabled!==!1,disabled:!r||i,onCheckedChange:s,title:e.enabled===!1?`Enable rule`:`Disable rule`}),r&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`button`,{type:`button`,title:`Edit`,onClick:c,disabled:i,className:`rounded p-1 text-muted-foreground hover:bg-accent hover:text-foreground disabled:pointer-events-none`,children:(0,J.jsxs)(`svg`,{className:`size-3.5`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,children:[(0,J.jsx)(`path`,{d:`M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7`}),(0,J.jsx)(`path`,{d:`M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z`})]})}),(0,J.jsx)(`button`,{type:`button`,title:`Remove`,onClick:l,disabled:i,className:`rounded p-1 text-destructive hover:bg-destructive/10 disabled:pointer-events-none`,children:(0,J.jsx)(y,{className:`size-3.5`})})]})]})]})}function dt({form:e,error:t,onChange:n,onSave:r,onCancel:i,isNew:a}){function o(t){n({...e,...t})}return(0,J.jsxs)(`div`,{className:`rounded-md border border-primary/30 bg-primary/5 p-3 space-y-3`,children:[(0,J.jsx)(`div`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wide`,children:a?`New rule`:`Edit rule`}),(0,J.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,J.jsxs)(`label`,{className:`space-y-1`,children:[(0,J.jsx)(`span`,{className:`text-[10px] font-medium text-muted-foreground`,children:`Label (optional)`}),(0,J.jsx)(z,{value:e.label,onChange:e=>o({label:e.target.value}),placeholder:`e.g. Route GUI tasks to Claude`,className:`h-8 text-xs`})]}),(0,J.jsxs)(`label`,{className:`space-y-1`,children:[(0,J.jsx)(`span`,{className:`text-[10px] font-medium text-muted-foreground`,children:`Target provider`}),(0,J.jsxs)(I,{value:e.targetProvider,onValueChange:e=>o({targetProvider:e}),children:[(0,J.jsx)(N,{className:`h-8 text-xs`,children:(0,J.jsx)(M,{})}),(0,J.jsx)(P,{children:nt.map(e=>(0,J.jsx)(F,{value:e,className:`text-xs`,children:j(e)},e))})]})]})]}),(0,J.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,J.jsxs)(`label`,{className:`space-y-1`,children:[(0,J.jsx)(`span`,{className:`text-[10px] font-medium text-muted-foreground`,children:`Match task-type (prefix)`}),(0,J.jsx)(z,{value:e.matchTaskType,onChange:e=>o({matchTaskType:e.target.value}),placeholder:`e.g. gui, backend, mechanical`,className:`h-8 font-mono text-xs`}),(0,J.jsxs)(`span`,{className:`block text-[10px] leading-snug text-muted-foreground`,children:[`Prefix match — `,(0,J.jsx)(`span`,{className:`font-mono text-foreground`,children:`gui`}),` matches `,(0,J.jsx)(`span`,{className:`font-mono text-foreground`,children:`gui/ux`}),`, `,(0,J.jsx)(`span`,{className:`font-mono text-foreground`,children:`gui/layout`}),`.`]})]}),(0,J.jsxs)(`label`,{className:`space-y-1`,children:[(0,J.jsx)(`span`,{className:`text-[10px] font-medium text-muted-foreground`,children:`Match capability (exact)`}),(0,J.jsx)(z,{value:e.matchCapability,onChange:e=>o({matchCapability:e.target.value}),placeholder:`e.g. code, research, bounded`,className:`h-8 font-mono text-xs`}),(0,J.jsx)(`span`,{className:`block text-[10px] leading-snug text-muted-foreground`,children:`Exact match against the agent's capability tag. Both fields are AND-ed.`})]})]}),(0,J.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,J.jsxs)(`label`,{className:`space-y-1`,children:[(0,J.jsx)(`span`,{className:`text-[10px] font-medium text-muted-foreground`,children:`Model alias (optional)`}),(0,J.jsx)(z,{value:e.targetModel,onChange:e=>o({targetModel:e.target.value}),placeholder:`e.g. opus, gpt-5.4`,className:`h-8 font-mono text-xs`})]}),(0,J.jsxs)(`label`,{className:`space-y-1`,children:[(0,J.jsx)(`span`,{className:`text-[10px] font-medium text-muted-foreground`,children:`Effort (optional)`}),(0,J.jsx)(z,{value:e.targetEffort,onChange:e=>o({targetEffort:e.target.value}),placeholder:`e.g. high, low`,className:`h-8 text-xs`})]})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(B,{checked:e.enabled,onCheckedChange:e=>o({enabled:e})}),(0,J.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Enabled`})]}),t&&(0,J.jsx)(st,{message:t}),(0,J.jsxs)(`div`,{className:`flex gap-2`,children:[(0,J.jsxs)(R,{size:`sm`,onClick:r,children:[(0,J.jsx)(s,{className:`size-4`}),a?`Add`:`Save`]}),(0,J.jsx)(R,{size:`sm`,variant:`outline`,onClick:i,children:`Cancel`})]})]})}var ft=`browser`,pt=`models`,mt=`profile`,ht=`routing`,gt=[`branch.landed`,`landed-failure`,`agent.ready`,`agent.exited`,`agent.spawn_failed`,`agent.context_threshold`,`agent.quota_threshold`,`workspace.steward_task`,`workspace.conflict`,`workspace.review_request`];function _t(){if(typeof window>`u`)return``;let e=window.location.hash.replace(/^#/,``);return e.startsWith(`settings/`)?decodeURIComponent(e.slice(9)):``}function vt(e){if(typeof window>`u`)return;let t=new URL(window.location.href);t.hash=`settings/${encodeURIComponent(e)}`,window.history.pushState({},``,t)}function yt(){let[e,t]=(0,K.useState)([]),[n,r]=(0,K.useState)(null),[i,a]=(0,K.useState)([]),[o,s]=(0,K.useState)(()=>_t()),[c,l]=(0,K.useState)(!0),[u,f]=(0,K.useState)(``),[p,m]=(0,K.useState)(``);async function h(){l(!0),f(``),m(``);try{let[e,n,i]=await Promise.all([x(`GET`,`/settings`),x(`GET`,`/tokens/me`),x(`GET`,`/providers`).catch(e=>(m(e.message),{catalog:[]}))]);t(e.settings),r(n),a(i.catalog)}catch(e){f(e.message)}finally{l(!1)}}(0,K.useEffect)(()=>{h()},[]),(0,K.useEffect)(()=>{let e=()=>s(_t());return window.addEventListener(`hashchange`,e),window.addEventListener(`popstate`,e),()=>{window.removeEventListener(`hashchange`,e),window.removeEventListener(`popstate`,e)}},[]);let g=(0,K.useMemo)(()=>fe(e),[e]),_=(0,K.useMemo)(()=>[...g.map(e=>({slug:e.slug,label:e.group,description:`${e.settings.length} schema setting${e.settings.length===1?``:`s`}`,kind:`descriptors`,settings:e.settings})),{slug:ht,label:`Routing`,description:`Rules, quota thresholds, coordinator view`,kind:`routing`,settings:[]},{slug:mt,label:`Profile`,description:`Display name and avatar`,kind:`profile`,settings:[]},{slug:ft,label:`Browser`,description:`Local dashboard preferences`,kind:`browser`,settings:[]},{slug:pt,label:`Models`,description:`Provider model catalog`,kind:`models`,settings:[]}],[g]),y=_.find(e=>e.slug===o)??_[0];function b(e){s(e),vt(e)}function S(e){t(t=>t.map(t=>q(t)===q(e)?e:t))}return(0,J.jsxs)(`div`,{className:`space-y-4`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Settings`}),(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Schema-driven Relay settings, browser preferences, and model catalog controls.`})]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[n&&(0,J.jsxs)(L,{variant:`outline`,className:`gap-1`,children:[(0,J.jsx)(v,{className:`size-3`}),n.kind,`:`,n.actor]}),(0,J.jsxs)(R,{variant:`outline`,size:`sm`,onClick:()=>void h(),disabled:c,children:[(0,J.jsx)(d,{className:D(`size-4`,c&&`animate-spin`)}),`Refresh`]})]})]}),u&&(0,J.jsxs)(`div`,{className:`flex items-start gap-2 rounded-lg border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive`,children:[(0,J.jsx)(O,{className:`mt-0.5 size-4`}),(0,J.jsx)(`span`,{children:u})]}),(0,J.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-[230px_minmax(0,1fr)]`,children:[(0,J.jsx)(`nav`,{className:`space-y-1 lg:sticky lg:top-4 lg:self-start`,children:_.map(e=>(0,J.jsxs)(`button`,{type:`button`,className:D(`w-full rounded-md border px-3 py-2 text-left text-sm transition-colors`,y?.slug===e.slug?`border-primary/50 bg-primary/10 text-foreground`:`border-transparent hover:border-border hover:bg-accent`),onClick:()=>b(e.slug),children:[(0,J.jsx)(`span`,{className:`block font-medium`,children:e.label}),(0,J.jsx)(`span`,{className:`block truncate text-xs text-muted-foreground`,children:e.description})]},e.slug))}),(0,J.jsx)(`div`,{className:`min-w-0 space-y-4`,children:c&&!e.length?(0,J.jsx)(G,{size:`sm`,children:(0,J.jsx)(U,{className:`text-sm text-muted-foreground`,children:`Loading settings…`})}):y?.kind===`routing`?(0,J.jsx)(ct,{canWrite:ae(n?.scopes,`settings:write:routing`)}):y?.kind===`descriptors`?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(De,{group:y.label,settings:y.settings,onSaved:S}),y.label===`Providers`&&(0,J.jsx)(We,{canWrite:ae(n?.scopes,`settings:write:provider`)}),y.label===`Notifications`&&(0,J.jsx)(bt,{})]}):y?.kind===`profile`?(0,J.jsx)(xt,{}):y?.kind===`browser`?(0,J.jsx)(je,{}):(0,J.jsx)(Ne,{catalog:i,error:p,canWrite:ae(n?.scopes,`settings:write:provider`),onCatalog:a})})]})]})}function bt(){let[e,t]=(0,K.useState)(`branch.landed`),[n,r]=(0,K.useState)(`{
4
4
  "repoRoot": "/repo"
5
5
  }`),[i,a]=(0,K.useState)(null),[o,s]=(0,K.useState)(!1),[l,u]=(0,K.useState)(``);async function d(){s(!0),u(``);try{let t=JSON.parse(n);if(!t||typeof t!=`object`||Array.isArray(t))throw Error(`Scope must be a JSON object`);a((await x(`POST`,`/notifications/preview`,{type:e,scope:t})).preview)}catch(e){a(null),u(e.message)}finally{s(!1)}}return(0,J.jsx)(G,{size:`sm`,children:(0,J.jsxs)(U,{className:`space-y-3`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Who gets what`}),(0,J.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Dry-run notification routing without sending.`})]}),(0,J.jsxs)(R,{size:`sm`,onClick:()=>void d(),disabled:o,children:[(0,J.jsx)(c,{className:`size-4`}),`Preview`]})]}),(0,J.jsxs)(`div`,{className:`grid gap-3 md:grid-cols-[240px_minmax(0,1fr)]`,children:[(0,J.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,J.jsx)(`label`,{className:`text-xs font-medium text-muted-foreground`,children:`Type`}),(0,J.jsxs)(I,{value:e,onValueChange:t,children:[(0,J.jsx)(N,{className:`w-full`,children:(0,J.jsx)(M,{})}),(0,J.jsx)(P,{children:gt.map(e=>(0,J.jsx)(F,{value:e,children:e},e))})]})]}),(0,J.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,J.jsx)(`label`,{className:`text-xs font-medium text-muted-foreground`,children:`Scope`}),(0,J.jsx)(se,{value:n,onChange:e=>r(e.target.value),rows:4,className:`font-mono text-xs`})]})]}),l&&(0,J.jsxs)(`div`,{className:`flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/10 p-2 text-xs text-destructive`,children:[(0,J.jsx)(O,{className:`mt-0.5 size-3.5`}),(0,J.jsx)(`span`,{children:l})]}),i&&(0,J.jsx)(`div`,{className:`overflow-hidden rounded-md border border-border`,children:i.recipients.length===0?(0,J.jsx)(`div`,{className:`px-3 py-4 text-center text-xs text-muted-foreground`,children:`No recipients`}):i.recipients.map(e=>(0,J.jsxs)(`div`,{className:`grid gap-1 border-b border-border px-3 py-2 text-xs last:border-b-0 md:grid-cols-[minmax(0,180px)_minmax(0,160px)_minmax(0,1fr)]`,children:[(0,J.jsx)(`span`,{className:`truncate font-medium`,children:e.recipient}),(0,J.jsx)(`span`,{className:`truncate font-mono text-muted-foreground`,children:e.matchedRule}),(0,J.jsx)(`span`,{className:`truncate text-muted-foreground`,children:e.reason})]},`${e.recipient}-${e.matchedRule}`))})]})})}function xt(){let e=A(e=>e.fetchUsers),t=(0,K.useRef)(null),[r,i]=(0,K.useState)(null),[a,o]=(0,K.useState)(``),[c,l]=(0,K.useState)(!0),[u,d]=(0,K.useState)(!1),[f,p]=(0,K.useState)(``);async function m(){l(!0),p(``);try{let e=await x(`GET`,`/users/me`);i(e),o(e.displayName||e.handle)}catch(e){p(e.message)}finally{l(!1)}}(0,K.useEffect)(()=>{m()},[]);async function h(){d(!0),p(``);try{let t=await x(`PATCH`,`/users/me`,{displayName:a});i(t),o(t.displayName||t.handle),await e()}catch(e){p(e.message)}finally{d(!1)}}async function g(n){if(n){d(!0),p(``);try{let t=await _(`/users/me/avatar`,n);i(t.user),o(t.user.displayName||t.user.handle),await e()}catch(e){p(e.message)}finally{d(!1),t.current&&(t.current.value=``)}}}async function v(){d(!0),p(``);try{i(await x(`DELETE`,`/users/me/avatar`)),await e()}catch(e){p(e.message)}finally{d(!1)}}return(0,J.jsx)(G,{size:`sm`,children:(0,J.jsxs)(U,{className:`space-y-4`,children:[f&&(0,J.jsxs)(`div`,{className:`flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive`,children:[(0,J.jsx)(O,{className:`mt-0.5 size-4`}),(0,J.jsx)(`span`,{children:f})]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[(0,J.jsx)(le,{user:r??void 0,distinct:!0,className:`size-16 text-lg`}),(0,J.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-2`,children:[(0,J.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground`,htmlFor:`profile-display-name`,children:`Display name`}),(0,J.jsx)(`input`,{id:`profile-display-name`,className:`h-9 w-full rounded-md border border-input bg-background px-3 text-sm`,value:a,onChange:e=>o(e.target.value),disabled:c||u,maxLength:120})]})]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,J.jsxs)(R,{size:`sm`,onClick:()=>void h(),disabled:c||u||!a.trim(),children:[(0,J.jsx)(s,{className:`size-4`}),`Save`]}),(0,J.jsxs)(R,{size:`sm`,variant:`outline`,onClick:()=>t.current?.click(),disabled:c||u,children:[(0,J.jsx)(w,{className:`size-4`}),`Upload`]}),(0,J.jsxs)(R,{size:`sm`,variant:`outline`,onClick:()=>void v(),disabled:c||u||!r?.avatarArtifactId,children:[(0,J.jsx)(y,{className:`size-4`}),`Remove`]}),u&&(0,J.jsx)(n,{className:`size-4 animate-pulse text-muted-foreground`}),(0,J.jsx)(`input`,{ref:t,type:`file`,accept:`image/png,image/jpeg,image/gif,image/webp`,className:`hidden`,onChange:e=>void g(e.target.files?.[0])})]})]})})}export{yt as SettingsView};
6
- //# sourceMappingURL=settings-DrqMG5nG.js.map
6
+ //# sourceMappingURL=settings-CK_T9z5w.js.map