@spencerboucher/switchyard 0.24.0 → 0.25.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 (142) hide show
  1. package/README.md +1 -1
  2. package/dist/bridge/enroll.js +12 -3
  3. package/dist/catalog/worker.js +5913 -0
  4. package/dist/policies/worker.js +935 -950
  5. package/dist/switchyard.mjs +2413 -2484
  6. package/package.json +1 -1
  7. package/web-dist/assets/AutomationView-I80YGJ3M.js +2 -0
  8. package/web-dist/assets/{AutomationView-BiSxKpgA.js.map → AutomationView-I80YGJ3M.js.map} +1 -1
  9. package/web-dist/assets/{Checkbox-CneW7ZHn.js → Checkbox-BdFQsqCG.js} +2 -2
  10. package/web-dist/assets/{Checkbox-CneW7ZHn.js.map → Checkbox-BdFQsqCG.js.map} +1 -1
  11. package/web-dist/assets/{DangerZone-tpxj5S8V.js → DangerZone-C6qU1pp7.js} +2 -2
  12. package/web-dist/assets/{DangerZone-tpxj5S8V.js.map → DangerZone-C6qU1pp7.js.map} +1 -1
  13. package/web-dist/assets/{Field-0rAadZ7B.js → Field-DGV7eljt.js} +2 -2
  14. package/web-dist/assets/{Field-0rAadZ7B.js.map → Field-DGV7eljt.js.map} +1 -1
  15. package/web-dist/assets/{NavigationEditor-DE3vVnHw.js → NavigationEditor-COtm2NQY.js} +2 -2
  16. package/web-dist/assets/{NavigationEditor-DE3vVnHw.js.map → NavigationEditor-COtm2NQY.js.map} +1 -1
  17. package/web-dist/assets/{Overlay-kkZVSidv.js → Overlay-hRkfpjK4.js} +2 -2
  18. package/web-dist/assets/{Overlay-kkZVSidv.js.map → Overlay-hRkfpjK4.js.map} +1 -1
  19. package/web-dist/assets/{Priority-VTOBYjs9.js → Priority-DL3f-tRD.js} +2 -2
  20. package/web-dist/assets/{Priority-VTOBYjs9.js.map → Priority-DL3f-tRD.js.map} +1 -1
  21. package/web-dist/assets/{RadioCards-Oy23yrpF.js → RadioCards-9YvqB3va.js} +2 -2
  22. package/web-dist/assets/{RadioCards-Oy23yrpF.js.map → RadioCards-9YvqB3va.js.map} +1 -1
  23. package/web-dist/assets/{ScopeRepository-BU9I7Gs_.js → ScopeRepository-BPiPUjHi.js} +3 -3
  24. package/web-dist/assets/{ScopeRepository-BU9I7Gs_.js.map → ScopeRepository-BPiPUjHi.js.map} +1 -1
  25. package/web-dist/assets/{ScopeSelect-7ZYRzci5.js → ScopeSelect-DmWCXeIf.js} +2 -2
  26. package/web-dist/assets/{ScopeSelect-7ZYRzci5.js.map → ScopeSelect-DmWCXeIf.js.map} +1 -1
  27. package/web-dist/assets/{SegmentedControl-CCObjCnv.js → SegmentedControl-CefWecy1.js} +2 -2
  28. package/web-dist/assets/{SegmentedControl-CCObjCnv.js.map → SegmentedControl-CefWecy1.js.map} +1 -1
  29. package/web-dist/assets/{Select-CRC4mF4U.js → Select-CdANXO3X.js} +2 -2
  30. package/web-dist/assets/{Select-CRC4mF4U.js.map → Select-CdANXO3X.js.map} +1 -1
  31. package/web-dist/assets/StructuredValue-BjKzgQDM.js +5 -0
  32. package/web-dist/assets/StructuredValue-BjKzgQDM.js.map +1 -0
  33. package/web-dist/assets/{Switch-llihKH_2.js → Switch-DrrWalaQ.js} +2 -2
  34. package/web-dist/assets/{Switch-llihKH_2.js.map → Switch-DrrWalaQ.js.map} +1 -1
  35. package/web-dist/assets/{Tabs-CIolUgNo.js → Tabs-Cvyw8P4s.js} +4 -4
  36. package/web-dist/assets/{Tabs-CIolUgNo.js.map → Tabs-Cvyw8P4s.js.map} +1 -1
  37. package/web-dist/assets/TextLink-DMi_ZI43.js +2 -0
  38. package/web-dist/assets/{TextLink-BJlPjvKn.js.map → TextLink-DMi_ZI43.js.map} +1 -1
  39. package/web-dist/assets/{UINodeRenderer-DwZNt-8y.js → UINodeRenderer-CDPAUIOO.js} +2 -2
  40. package/web-dist/assets/{UINodeRenderer-DwZNt-8y.js.map → UINodeRenderer-CDPAUIOO.js.map} +1 -1
  41. package/web-dist/assets/{UnfilteredNote-B77oGOcW.js → UnfilteredNote-CgsOTad1.js} +2 -2
  42. package/web-dist/assets/{UnfilteredNote-B77oGOcW.js.map → UnfilteredNote-CgsOTad1.js.map} +1 -1
  43. package/web-dist/assets/{api-C7CMr6g-.js → api-Dlk6L3Cu.js} +2 -2
  44. package/web-dist/assets/{api-C7CMr6g-.js.map → api-Dlk6L3Cu.js.map} +1 -1
  45. package/web-dist/assets/{arrow-down-Bqx9CSB1.js → arrow-down-Cc6k_L7W.js} +2 -2
  46. package/web-dist/assets/{arrow-down-Bqx9CSB1.js.map → arrow-down-Cc6k_L7W.js.map} +1 -1
  47. package/web-dist/assets/{arrow-up-D0b2fv0Q.js → arrow-up-CW1a5Bhp.js} +2 -2
  48. package/web-dist/assets/{arrow-up-D0b2fv0Q.js.map → arrow-up-CW1a5Bhp.js.map} +1 -1
  49. package/web-dist/assets/attention-AZ2a-mzO.js +2 -0
  50. package/web-dist/assets/{attention-DMhF0I-p.js.map → attention-AZ2a-mzO.js.map} +1 -1
  51. package/web-dist/assets/{auth-vd8OFoQx.js → auth-Dzip9fVv.js} +2 -2
  52. package/web-dist/assets/{auth-vd8OFoQx.js.map → auth-Dzip9fVv.js.map} +1 -1
  53. package/web-dist/assets/{automations-Dz_JHvUj.js → automations-BYFgPSs2.js} +2 -2
  54. package/web-dist/assets/{automations-Dz_JHvUj.js.map → automations-BYFgPSs2.js.map} +1 -1
  55. package/web-dist/assets/board-D2LALQcR.js +6 -0
  56. package/web-dist/assets/board-D2LALQcR.js.map +1 -0
  57. package/web-dist/assets/{calendar-clock-C5cMYlld.js → calendar-clock-CkYP2-Qf.js} +2 -2
  58. package/web-dist/assets/{calendar-clock-C5cMYlld.js.map → calendar-clock-CkYP2-Qf.js.map} +1 -1
  59. package/web-dist/assets/chevron-right-Q-RTE0ar.js +2 -0
  60. package/web-dist/assets/{chevron-right-5ip-ZfOW.js.map → chevron-right-Q-RTE0ar.js.map} +1 -1
  61. package/web-dist/assets/code-BuAtgr-5.js +24 -0
  62. package/web-dist/assets/code-BuAtgr-5.js.map +1 -0
  63. package/web-dist/assets/{core.esm-C_QgTrGe.js → core.esm-yL4bmFrt.js} +2 -2
  64. package/web-dist/assets/{core.esm-C_QgTrGe.js.map → core.esm-yL4bmFrt.js.map} +1 -1
  65. package/web-dist/assets/{describe-Bd1JbydU.js → describe-B1R7Rpb3.js} +3 -3
  66. package/web-dist/assets/{describe-Bd1JbydU.js.map → describe-B1R7Rpb3.js.map} +1 -1
  67. package/web-dist/assets/{enroll-B_ZjVnEj.js → enroll-BJIkw0lm.js} +2 -2
  68. package/web-dist/assets/{enroll-B_ZjVnEj.js.map → enroll-BJIkw0lm.js.map} +1 -1
  69. package/web-dist/assets/{external-link-DeLk0jmb.js → external-link-BHZxy4tb.js} +2 -2
  70. package/web-dist/assets/{external-link-DeLk0jmb.js.map → external-link-BHZxy4tb.js.map} +1 -1
  71. package/web-dist/assets/{git-branch-DuApoZes.js → git-branch-C5Xwi6aW.js} +2 -2
  72. package/web-dist/assets/{git-branch-DuApoZes.js.map → git-branch-C5Xwi6aW.js.map} +1 -1
  73. package/web-dist/assets/{grip-vertical-DfKSP8jp.js → grip-vertical-kzr2x5pf.js} +2 -2
  74. package/web-dist/assets/{grip-vertical-DfKSP8jp.js.map → grip-vertical-kzr2x5pf.js.map} +1 -1
  75. package/web-dist/assets/{hand-ryhCgGbh.js → hand-DStB4fR7.js} +2 -2
  76. package/web-dist/assets/{hand-ryhCgGbh.js.map → hand-DStB4fR7.js.map} +1 -1
  77. package/web-dist/assets/index-D3WBnjbc.js +17 -0
  78. package/web-dist/assets/{index-BXoBPAUR.js.map → index-D3WBnjbc.js.map} +1 -1
  79. package/web-dist/assets/{link-2-pHvZvxCs.js → link-2-Cny9mRKW.js} +2 -2
  80. package/web-dist/assets/{link-2-pHvZvxCs.js.map → link-2-Cny9mRKW.js.map} +1 -1
  81. package/web-dist/assets/{logic-3so3T0af.js → logic-BOdOYgZ4.js} +3 -3
  82. package/web-dist/assets/{logic-3so3T0af.js.map → logic-BOdOYgZ4.js.map} +1 -1
  83. package/web-dist/assets/{logic-uhnfzaYJ.js → logic-CHh1lc3G.js} +2 -2
  84. package/web-dist/assets/{logic-uhnfzaYJ.js.map → logic-CHh1lc3G.js.map} +1 -1
  85. package/web-dist/assets/{more-C41VHBVG.js → more-BrHzsSfh.js} +2 -2
  86. package/web-dist/assets/{more-C41VHBVG.js.map → more-BrHzsSfh.js.map} +1 -1
  87. package/web-dist/assets/{pencil-BoQa6LEV.js → pencil-BmHgPcCk.js} +2 -2
  88. package/web-dist/assets/{pencil-BoQa6LEV.js.map → pencil-BmHgPcCk.js.map} +1 -1
  89. package/web-dist/assets/{play-DjTVY8Ej.js → play-Dul6ZDzY.js} +2 -2
  90. package/web-dist/assets/{play-DjTVY8Ej.js.map → play-Dul6ZDzY.js.map} +1 -1
  91. package/web-dist/assets/{plus-BQPgQYui.js → plus-DzBRN9tc.js} +2 -2
  92. package/web-dist/assets/{plus-BQPgQYui.js.map → plus-DzBRN9tc.js.map} +1 -1
  93. package/web-dist/assets/{policyLogic-cyMrhCM6.js → policyLogic-DVorBdH6.js} +2 -2
  94. package/web-dist/assets/{policyLogic-cyMrhCM6.js.map → policyLogic-DVorBdH6.js.map} +1 -1
  95. package/web-dist/assets/{prefs-CkiUftvR.js → prefs-CUMuH2EM.js} +2 -2
  96. package/web-dist/assets/{prefs-CkiUftvR.js.map → prefs-CUMuH2EM.js.map} +1 -1
  97. package/web-dist/assets/preload-helper-vwPq19u5.js +9 -0
  98. package/web-dist/assets/preload-helper-vwPq19u5.js.map +1 -0
  99. package/web-dist/assets/queue-hRZWM_pM.js +2 -0
  100. package/web-dist/assets/{queue-CSCmR2Xf.js.map → queue-hRZWM_pM.js.map} +1 -1
  101. package/web-dist/assets/{rotate-ccw-C07CP9JG.js → rotate-ccw-ByDiAA6o.js} +2 -2
  102. package/web-dist/assets/{rotate-ccw-C07CP9JG.js.map → rotate-ccw-ByDiAA6o.js.map} +1 -1
  103. package/web-dist/assets/{search-bqDM8qB0.js → search-DarT116I.js} +2 -2
  104. package/web-dist/assets/{search-bqDM8qB0.js.map → search-DarT116I.js.map} +1 -1
  105. package/web-dist/assets/settings-DHfdrqxv.js +6 -0
  106. package/web-dist/assets/settings-DHfdrqxv.js.map +1 -0
  107. package/web-dist/assets/{states-goHGz_CJ.js → states-hcvSpyb1.js} +5 -5
  108. package/web-dist/assets/states-hcvSpyb1.js.map +1 -0
  109. package/web-dist/assets/{terminal-BFJK8pLS.js → terminal-BmpsRI95.js} +2 -2
  110. package/web-dist/assets/{terminal-BFJK8pLS.js.map → terminal-BmpsRI95.js.map} +1 -1
  111. package/web-dist/assets/{terminal-login-DwI8gUw-.js → terminal-login-COaZPzQx.js} +2 -2
  112. package/web-dist/assets/{terminal-login-DwI8gUw-.js.map → terminal-login-COaZPzQx.js.map} +1 -1
  113. package/web-dist/assets/{useBreakpoint-C7ONetzK.js → useBreakpoint-CXotoLeq.js} +2 -2
  114. package/web-dist/assets/{useBreakpoint-C7ONetzK.js.map → useBreakpoint-CXotoLeq.js.map} +1 -1
  115. package/web-dist/assets/{useNow-BFhACgmu.js → useNow-BweXkeWc.js} +2 -2
  116. package/web-dist/assets/{useNow-BFhACgmu.js.map → useNow-BweXkeWc.js.map} +1 -1
  117. package/web-dist/assets/{useResource-Br3v4Sui.js → useResource-DAMkbbuf.js} +2 -2
  118. package/web-dist/assets/{useResource-Br3v4Sui.js.map → useResource-DAMkbbuf.js.map} +1 -1
  119. package/web-dist/assets/{useSwipeTabs-_JvGirwa.js → useSwipeTabs-3qLCxSS7.js} +2 -2
  120. package/web-dist/assets/{useSwipeTabs-_JvGirwa.js.map → useSwipeTabs-3qLCxSS7.js.map} +1 -1
  121. package/web-dist/assets/workboard-BEcRsjyQ.js +3 -0
  122. package/web-dist/assets/{workboard-IozvaLbf.js.map → workboard-BEcRsjyQ.js.map} +1 -1
  123. package/web-dist/index.html +7 -7
  124. package/web-dist/sw.js +1 -1
  125. package/web-dist/assets/AutomationView-BiSxKpgA.js +0 -2
  126. package/web-dist/assets/StructuredValue-DdwqFsZd.js +0 -5
  127. package/web-dist/assets/StructuredValue-DdwqFsZd.js.map +0 -1
  128. package/web-dist/assets/TextLink-BJlPjvKn.js +0 -2
  129. package/web-dist/assets/attention-DMhF0I-p.js +0 -2
  130. package/web-dist/assets/board-CMfIsKrb.js +0 -6
  131. package/web-dist/assets/board-CMfIsKrb.js.map +0 -1
  132. package/web-dist/assets/chevron-right-5ip-ZfOW.js +0 -2
  133. package/web-dist/assets/code-BpPDYwth.js +0 -24
  134. package/web-dist/assets/code-BpPDYwth.js.map +0 -1
  135. package/web-dist/assets/index-BXoBPAUR.js +0 -17
  136. package/web-dist/assets/preload-helper-B_HW6k8N.js +0 -9
  137. package/web-dist/assets/preload-helper-B_HW6k8N.js.map +0 -1
  138. package/web-dist/assets/queue-CSCmR2Xf.js +0 -2
  139. package/web-dist/assets/settings-iTwK6CzQ.js +0 -6
  140. package/web-dist/assets/settings-iTwK6CzQ.js.map +0 -1
  141. package/web-dist/assets/states-goHGz_CJ.js.map +0 -1
  142. package/web-dist/assets/workboard-IozvaLbf.js +0 -3
@@ -1,2 +1,2 @@
1
- import{D as e}from"./states-goHGz_CJ.js";var t={name:`link-2`,size:24,node:[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7h2`,key:`8i5ue5`}],[`path`,{d:`M15 7h2a5 5 0 1 1 0 10h-2`,key:`1b9ql8`}],[`line`,{x1:`8`,x2:`16`,y1:`12`,y2:`12`,key:`1jonct`}]]};t.node;var n=e(t);export{n as t};
2
- //# sourceMappingURL=link-2-pHvZvxCs.js.map
1
+ import{D as e}from"./states-hcvSpyb1.js";var t={name:`link-2`,size:24,node:[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7h2`,key:`8i5ue5`}],[`path`,{d:`M15 7h2a5 5 0 1 1 0 10h-2`,key:`1b9ql8`}],[`line`,{x1:`8`,x2:`16`,y1:`12`,y2:`12`,key:`1jonct`}]]};t.node;var n=e(t);export{n as t};
2
+ //# sourceMappingURL=link-2-Cny9mRKW.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"link-2-pHvZvxCs.js","names":["createLucideIcon","__iconData","Link2"],"sources":["../../../../node_modules/.pnpm/lucide-react@1.61.0_@types+react@19.3.0_react@19.3.1/node_modules/lucide-react/dist/esm/icons/link-2.mjs"],"sourcesContent":["/**\n * @license lucide-react v1.61.0 - ISC\n *\n * This source code is licensed under the ISC license.\n * See the LICENSE file in the root directory of this source tree.\n */\n\nimport createLucideIcon from '../createLucideIcon.mjs';\n\nconst __iconData = {\n name: \"link-2\",\n size: 24,\n node: [\n [\"path\", { d: \"M9 17H7A5 5 0 0 1 7 7h2\", key: \"8i5ue5\" }],\n [\"path\", { d: \"M15 7h2a5 5 0 1 1 0 10h-2\", key: \"1b9ql8\" }],\n [\"line\", { x1: \"8\", x2: \"16\", y1: \"12\", y2: \"12\", key: \"1jonct\" }]\n ]\n};\n__iconData.node;\nconst Link2 = createLucideIcon(__iconData);\n\nexport { __iconData, Link2 as default };\n//# sourceMappingURL=link-2.mjs.map\n"],"ignoreList":[0],"mappings":"A,yCASA,IAAMC,EAAa,CACjB,KAAM,SACN,KAAM,GACN,KAAM,CACJ,CAAC,OAAQ,CAAE,EAAG,0BAA2B,IAAK,QAAS,CAAC,EACxD,CAAC,OAAQ,CAAE,EAAG,4BAA6B,IAAK,QAAS,CAAC,EAC1D,CAAC,OAAQ,CAAE,GAAI,IAAK,GAAI,KAAM,GAAI,KAAM,GAAI,KAAM,IAAK,QAAS,CAAC,CACnE,CACF,EACAA,EAAW,KACX,IAAMC,EAAQF,EAAiBC,CAAU,E"}
1
+ {"version":3,"file":"link-2-Cny9mRKW.js","names":["createLucideIcon","__iconData","Link2"],"sources":["../../../../node_modules/.pnpm/lucide-react@1.61.0_@types+react@19.3.0_react@19.3.1/node_modules/lucide-react/dist/esm/icons/link-2.mjs"],"sourcesContent":["/**\n * @license lucide-react v1.61.0 - ISC\n *\n * This source code is licensed under the ISC license.\n * See the LICENSE file in the root directory of this source tree.\n */\n\nimport createLucideIcon from '../createLucideIcon.mjs';\n\nconst __iconData = {\n name: \"link-2\",\n size: 24,\n node: [\n [\"path\", { d: \"M9 17H7A5 5 0 0 1 7 7h2\", key: \"8i5ue5\" }],\n [\"path\", { d: \"M15 7h2a5 5 0 1 1 0 10h-2\", key: \"1b9ql8\" }],\n [\"line\", { x1: \"8\", x2: \"16\", y1: \"12\", y2: \"12\", key: \"1jonct\" }]\n ]\n};\n__iconData.node;\nconst Link2 = createLucideIcon(__iconData);\n\nexport { __iconData, Link2 as default };\n//# sourceMappingURL=link-2.mjs.map\n"],"ignoreList":[0],"mappings":"A,yCASA,IAAMC,EAAa,CACjB,KAAM,SACN,KAAM,GACN,KAAM,CACJ,CAAC,OAAQ,CAAE,EAAG,0BAA2B,IAAK,QAAS,CAAC,EACxD,CAAC,OAAQ,CAAE,EAAG,4BAA6B,IAAK,QAAS,CAAC,EAC1D,CAAC,OAAQ,CAAE,GAAI,IAAK,GAAI,KAAM,GAAI,KAAM,GAAI,KAAM,IAAK,QAAS,CAAC,CACnE,CACF,EACAA,EAAW,KACX,IAAMC,EAAQF,EAAiBC,CAAU,E"}
@@ -1,4 +1,4 @@
1
- import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{G as t,St as n,Zt as r,_ as i,d as a,en as o,g as s,hn as c,m as l,n as u,nn as d,rn as f,v as p,vn as m}from"./states-goHGz_CJ.js";import{_ as h,g,i as _,m as v,n as y,p as b,t as x,u as S,v as C}from"./Overlay-kkZVSidv.js";import{$ as w,It as T,W as E,cn as D,dn as O,ln as k,mt as A,p as j,pn as M,pt as N,u as P,un as F,ut as I}from"./preload-helper-B_HW6k8N.js";import{t as L}from"./arrow-up-D0b2fv0Q.js";import{t as R}from"./UINodeRenderer-DwZNt-8y.js";import{t as z}from"./useBreakpoint-C7ONetzK.js";import{$ as ee,G as B,K as V,W as H}from"./index-BXoBPAUR.js";import{t as te}from"./TextLink-BJlPjvKn.js";import{i as U,r as ne}from"./Tabs-CIolUgNo.js";import{t as W}from"./haptics-O69vKVoK.js";import{t as re}from"./Field-0rAadZ7B.js";import{t as G}from"./api-C7CMr6g-.js";var K=e(m(),1),ie=`This dialog can't be answered from Switchyard.`,ae=`An extension is showing its own interface in this session's terminal. Open the terminal (switchyard tui) to answer it.`,oe=`This dialog can only be answered in the terminal where Pi is running.`,se=[{id:`abort`,label:`Stop the run`,tone:`danger`},{id:`message`,label:`Send a message to Pi`,tone:`primary`}];function ce(e){if(e.t===`actions`)return e;if(e.t===`section`)for(let t of e.children){let e=ce(t);if(e)return e}return null}function le(e){if(e.t===`text`)return e.text.trim()||null;if(e.t===`section`)for(let t of e.children){let e=le(t);if(e)return e}return null}function ue(e){return e.state===`unsupported`||e.source.kind===`unsupported_custom`}function de(e){let t=(ce(e.presentation)?.actions??[]).filter(e=>e.id===`abort`||e.id===`message`).map(e=>({id:e.id,label:e.label,tone:e.tone==="default"?`secondary`:e.tone??(e.id===`abort`?`danger`:`primary`)})),n=le(e.presentation);return{answerable:e.state===`unsupported`&&e.resolution===null,actions:t.length>0?t:se,copy:n===ae?oe:n??`This dialog can't be answered from Switchyard.`}}function fe(e){return e===`running`||e===`waiting_input`?`followUp`:`prompt`}var q=l();function J(e){switch(e.t){case`form`:case`confirm`:case`actions`:return!0;case`list`:return e.items.some(J);case`section`:return e.children.some(J);case`tabs`:return e.tabs.some(e=>e.children.some(J));default:return!1}}function Y(e){return e===`host`?`the host`:e===`pi`?`Pi`:`a device`}function pe({interaction:e,readOnlyReason:n,className:r,onAnswered:i,id:c,sticky:l,flush:m,mode:h=`card`,keys:g=!0,planAnchorId:_}){let v=t(e=>e.upsertInteraction),[y,b]=(0,K.useState)(!1),[x,S]=(0,K.useState)(null),[C,w]=(0,K.useState)(null),[T,E]=(0,K.useState)(null),[D,O]=(0,K.useState)(null),k=D&&D.id===e.id&&D.revision>e.revision?D:e,A=k.state===`pending`,j=ue(k),M=t(e=>e.sessions[k.sessionId]?.runtime),[N,P]=(0,K.useState)(!1),[F,I]=(0,K.useState)(``),L=async e=>{b(!0),S(null),E(e);try{let t=await o(`/api/interactions/${encodeURIComponent(k.id)}/answer`,{revision:k.revision,response:e});return t?.interaction&&(v(t.interaction),O(t.interaction),i?.(t.interaction)),!0}catch(e){if(f(e,`already_answered`)){let t=e.details?.interaction;t&&(v(t),O(t)),w(t?.resolution?.summary??`answered on another device`)}else S(e);return!1}finally{b(!1)}},B=async()=>{let e=F.trim();if(e){b(!0),S(null);try{await o(`/api/sessions/${encodeURIComponent(k.sessionId)}/prompt`,{text:e,mode:fe(M)})}catch(e){S(e),b(!1);return}b(!1),await L({kind:`action`,actionId:`message`})&&(P(!1),I(``))}},V=z();if(A&&!C&&!j&&ye(k.presentation))return(0,q.jsx)(Ce,{id:c,interaction:k,node:k.presentation,onRespond:e=>void L(e),busy:y,disabled:!!n,disabledReason:n??null,part:h===`reader`?`reader`:h===`dock`?`answers`:`all`,planAnchorId:_,mobile:V===`mobile`,sticky:l??!0,flush:m??!1,className:r});let H=h===`dock`;return(0,q.jsxs)(`article`,{id:c,"aria-label":`Question: ${k.title}`,className:p(H?`flex min-w-0 flex-col gap-2`:`flex min-w-0 flex-col gap-3 border-l-2 py-1 pl-3`,!H&&(A?`border-warning`:`border-border`),r),children:[H?(0,q.jsx)(`h3`,{className:`text-sm font-semibold break-words`,children:k.title}):(0,q.jsxs)(`header`,{className:`flex min-w-0 flex-wrap items-start gap-2`,children:[(0,q.jsx)(`h3`,{className:`min-w-0 flex-1 text-sm font-semibold break-words`,children:k.title}),(0,q.jsx)(ee,{kind:`interaction`,value:k.state,size:`sm`})]}),C&&(0,q.jsxs)(`p`,{role:`status`,className:`rounded-md bg-surface-2 px-3 py-2 text-sm`,children:[`Already answered: `,C]}),j?(0,q.jsx)(me,{interaction:k,readOnlyReason:n??null,busy:y,answered:C!==null,composing:N,message:F,setMessage:I,onAction:e=>{e===`message`?P(!0):L({kind:`action`,actionId:e})},onSend:()=>void B(),onCancelMessage:()=>P(!1)}):A&&!C?(0,q.jsxs)(q.Fragment,{children:[n&&(0,q.jsx)(`p`,{className:`text-sm text-muted`,children:n}),(0,q.jsx)(R,{node:k.presentation,onRespond:e=>void L(e),busy:y,disabled:!!n,dock:H?{title:k.title,keys:g&&k.kind===`question`}:void 0}),!n&&!J(k.presentation)&&(0,q.jsx)(`div`,{children:(0,q.jsx)(a,{busy:y,onClick:()=>void L({kind:`cancel`}),children:`Dismiss`})}),y&&(0,q.jsx)(`p`,{role:`status`,className:`text-sm text-muted`,children:`Sending answer… waiting for the host to confirm.`})]}):C?null:k.resolution?(0,q.jsxs)(`p`,{className:`text-sm text-muted`,children:[k.state===`resolved`?`Answered`:`Closed`,` by`,` `,Y(k.resolution.by),` `,s(k.resolution.at),`:`,` `,(0,q.jsx)(`span`,{className:`text-text`,children:k.resolution.summary})]}):(0,q.jsx)(`p`,{className:`text-sm text-muted`,children:k.state===`expired`?`This question expired before it was answered (Pi closed the dialog).`:`This question was canceled.`}),x!==null&&(0,q.jsx)(u,{compact:!0,title:`Answer not delivered`,error:d(x),onRetry:T?()=>void L(T):void 0})]})}function me({interaction:e,readOnlyReason:t,busy:n,answered:r,composing:i,message:o,setMessage:c,onAction:l,onSend:u,onCancelMessage:d}){let f=de(e);return(0,q.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,q.jsx)(`p`,{className:`text-sm text-muted`,children:f.copy}),e.resolution?(0,q.jsxs)(`p`,{className:`text-sm text-muted`,children:[`Chosen by `,Y(e.resolution.by),` `,s(e.resolution.at),`: `,(0,q.jsx)(`span`,{className:`text-text`,children:e.resolution.summary})]}):!f.answerable||r?null:t?(0,q.jsx)(`p`,{className:`text-sm text-muted`,children:t}):i?(0,q.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,q.jsx)(H,{"aria-label":`Message for Pi`,value:o,onChange:e=>c(e.target.value),rows:3,autoFocus:!0,placeholder:`Tell Pi what to do instead`}),(0,q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,q.jsx)(a,{variant:`primary`,busy:n,disabled:!o.trim(),onClick:u,children:`Send message`}),(0,q.jsx)(a,{disabled:n,onClick:d,children:`Cancel`})]})]}):(0,q.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:f.actions.map(e=>(0,q.jsx)(a,{variant:e.tone,busy:n&&e.id===`abort`,disabled:n,onClick:()=>l(e.id),children:e.label},e.id))})]})}function he(e){if(e.t!==`section`||e.children.length<2)return null;let t=e.children[e.children.length-1];if(t?.t!==`actions`)return null;let n=e.children.slice(0,-1);return n.some(J)?null:{body:{...e,children:n},actions:t}}function ge(e,t){let n=window.matchMedia?.(`(prefers-reduced-motion: reduce)`).matches;e?.scrollIntoView({behavior:n?`auto`:`smooth`,block:t})}function _e(e){let[t,n]=(0,K.useState)(!0);return(0,K.useEffect)(()=>{let t=e.current;if(!t||typeof IntersectionObserver>`u`)return;let r=new IntersectionObserver(([e])=>n(!!e?.isIntersecting));return r.observe(t),()=>r.disconnect()},[e]),t}function ve(e){if(e.t===`markdown`)return e.text;if(e.t===`section`)for(let t of e.children){let e=ve(t);if(e!==null)return e}return null}function ye(e){if(!he(e))return!1;let t=ve(e);return t!==null&&(t.length>=400||t.split(`
1
+ import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{G as t,Qt as n,St as r,_ as i,d as a,g as o,gn as s,in as c,m as l,n as u,rn as d,tn as f,v as p,yn as m}from"./states-hcvSpyb1.js";import{_ as h,g,i as _,m as v,n as y,p as b,t as x,u as S,v as C}from"./Overlay-hRkfpjK4.js";import{$ as w,It as T,W as E,cn as D,dn as O,ln as k,mt as A,on as j,p as M,pt as N,sn as P,u as F,ut as I}from"./preload-helper-vwPq19u5.js";import{t as L}from"./arrow-up-CW1a5Bhp.js";import{t as R}from"./UINodeRenderer-CDPAUIOO.js";import{t as z}from"./useBreakpoint-CXotoLeq.js";import{$ as ee,G as B,K as V,W as H}from"./index-D3WBnjbc.js";import{t as te}from"./TextLink-DMi_ZI43.js";import{i as U,r as ne}from"./Tabs-Cvyw8P4s.js";import{t as W}from"./haptics-O69vKVoK.js";import{t as re}from"./Field-DGV7eljt.js";import{t as G}from"./api-Dlk6L3Cu.js";var K=e(m(),1),ie=`This dialog can't be answered from Switchyard.`,ae=`An extension is showing its own interface in this session's terminal. Open the terminal (switchyard tui) to answer it.`,oe=`This dialog can only be answered in the terminal where Pi is running.`,se=[{id:`abort`,label:`Stop the run`,tone:`danger`},{id:`message`,label:`Send a message to Pi`,tone:`primary`}];function ce(e){if(e.t===`actions`)return e;if(e.t===`section`)for(let t of e.children){let e=ce(t);if(e)return e}return null}function le(e){if(e.t===`text`)return e.text.trim()||null;if(e.t===`section`)for(let t of e.children){let e=le(t);if(e)return e}return null}function ue(e){return e.state===`unsupported`||e.source.kind===`unsupported_custom`}function de(e){let t=(ce(e.presentation)?.actions??[]).filter(e=>e.id===`abort`||e.id===`message`).map(e=>({id:e.id,label:e.label,tone:e.tone==="default"?`secondary`:e.tone??(e.id===`abort`?`danger`:`primary`)})),n=le(e.presentation);return{answerable:e.state===`unsupported`&&e.resolution===null,actions:t.length>0?t:se,copy:n===ae?oe:n??`This dialog can't be answered from Switchyard.`}}function fe(e){return e===`running`||e===`waiting_input`?`followUp`:`prompt`}var q=l();function J(e){switch(e.t){case`form`:case`confirm`:case`actions`:return!0;case`list`:return e.items.some(J);case`section`:return e.children.some(J);case`tabs`:return e.tabs.some(e=>e.children.some(J));default:return!1}}function Y(e){return e===`host`?`the host`:e===`pi`?`Pi`:`a device`}function pe({interaction:e,readOnlyReason:n,className:r,onAnswered:i,id:s,sticky:l,flush:m,mode:h=`card`,keys:g=!0,planAnchorId:_}){let v=t(e=>e.upsertInteraction),[y,b]=(0,K.useState)(!1),[x,S]=(0,K.useState)(null),[C,w]=(0,K.useState)(null),[T,E]=(0,K.useState)(null),[D,O]=(0,K.useState)(null),k=D&&D.id===e.id&&D.revision>e.revision?D:e,A=k.state===`pending`,j=ue(k),M=t(e=>e.sessions[k.sessionId]?.runtime),[N,P]=(0,K.useState)(!1),[F,I]=(0,K.useState)(``),L=async e=>{b(!0),S(null),E(e);try{let t=await f(`/api/interactions/${encodeURIComponent(k.id)}/answer`,{revision:k.revision,response:e});return t?.interaction&&(v(t.interaction),O(t.interaction),i?.(t.interaction)),!0}catch(e){if(c(e,`already_answered`)){let t=e.details?.interaction;t&&(v(t),O(t)),w(t?.resolution?.summary??`answered on another device`)}else S(e);return!1}finally{b(!1)}},B=async()=>{let e=F.trim();if(e){b(!0),S(null);try{await f(`/api/sessions/${encodeURIComponent(k.sessionId)}/prompt`,{text:e,mode:fe(M)})}catch(e){S(e),b(!1);return}b(!1),await L({kind:`action`,actionId:`message`})&&(P(!1),I(``))}},V=z();if(A&&!C&&!j&&ye(k.presentation))return(0,q.jsx)(Ce,{id:s,interaction:k,node:k.presentation,onRespond:e=>void L(e),busy:y,disabled:!!n,disabledReason:n??null,part:h===`reader`?`reader`:h===`dock`?`answers`:`all`,planAnchorId:_,mobile:V===`mobile`,sticky:l??!0,flush:m??!1,className:r});let H=h===`dock`;return(0,q.jsxs)(`article`,{id:s,"aria-label":`Question: ${k.title}`,className:p(H?`flex min-w-0 flex-col gap-2`:`flex min-w-0 flex-col gap-3 border-l-2 py-1 pl-3`,!H&&(A?`border-warning`:`border-border`),r),children:[H?(0,q.jsx)(`h3`,{className:`text-sm font-semibold break-words`,children:k.title}):(0,q.jsxs)(`header`,{className:`flex min-w-0 flex-wrap items-start gap-2`,children:[(0,q.jsx)(`h3`,{className:`min-w-0 flex-1 text-sm font-semibold break-words`,children:k.title}),(0,q.jsx)(ee,{kind:`interaction`,value:k.state,size:`sm`})]}),C&&(0,q.jsxs)(`p`,{role:`status`,className:`rounded-md bg-surface-2 px-3 py-2 text-sm`,children:[`Already answered: `,C]}),j?(0,q.jsx)(me,{interaction:k,readOnlyReason:n??null,busy:y,answered:C!==null,composing:N,message:F,setMessage:I,onAction:e=>{e===`message`?P(!0):L({kind:`action`,actionId:e})},onSend:()=>void B(),onCancelMessage:()=>P(!1)}):A&&!C?(0,q.jsxs)(q.Fragment,{children:[n&&(0,q.jsx)(`p`,{className:`text-sm text-muted`,children:n}),(0,q.jsx)(R,{node:k.presentation,onRespond:e=>void L(e),busy:y,disabled:!!n,dock:H?{title:k.title,keys:g&&k.kind===`question`}:void 0}),!n&&!J(k.presentation)&&(0,q.jsx)(`div`,{children:(0,q.jsx)(a,{busy:y,onClick:()=>void L({kind:`cancel`}),children:`Dismiss`})}),y&&(0,q.jsx)(`p`,{role:`status`,className:`text-sm text-muted`,children:`Sending answer… waiting for the host to confirm.`})]}):C?null:k.resolution?(0,q.jsxs)(`p`,{className:`text-sm text-muted`,children:[k.state===`resolved`?`Answered`:`Closed`,` by`,` `,Y(k.resolution.by),` `,o(k.resolution.at),`:`,` `,(0,q.jsx)(`span`,{className:`text-text`,children:k.resolution.summary})]}):(0,q.jsx)(`p`,{className:`text-sm text-muted`,children:k.state===`expired`?`This question expired before it was answered (Pi closed the dialog).`:`This question was canceled.`}),x!==null&&(0,q.jsx)(u,{compact:!0,title:`Answer not delivered`,error:d(x),onRetry:T?()=>void L(T):void 0})]})}function me({interaction:e,readOnlyReason:t,busy:n,answered:r,composing:i,message:s,setMessage:c,onAction:l,onSend:u,onCancelMessage:d}){let f=de(e);return(0,q.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,q.jsx)(`p`,{className:`text-sm text-muted`,children:f.copy}),e.resolution?(0,q.jsxs)(`p`,{className:`text-sm text-muted`,children:[`Chosen by `,Y(e.resolution.by),` `,o(e.resolution.at),`: `,(0,q.jsx)(`span`,{className:`text-text`,children:e.resolution.summary})]}):!f.answerable||r?null:t?(0,q.jsx)(`p`,{className:`text-sm text-muted`,children:t}):i?(0,q.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,q.jsx)(H,{"aria-label":`Message for Pi`,value:s,onChange:e=>c(e.target.value),rows:3,autoFocus:!0,placeholder:`Tell Pi what to do instead`}),(0,q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,q.jsx)(a,{variant:`primary`,busy:n,disabled:!s.trim(),onClick:u,children:`Send message`}),(0,q.jsx)(a,{disabled:n,onClick:d,children:`Cancel`})]})]}):(0,q.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:f.actions.map(e=>(0,q.jsx)(a,{variant:e.tone,busy:n&&e.id===`abort`,disabled:n,onClick:()=>l(e.id),children:e.label},e.id))})]})}function he(e){if(e.t!==`section`||e.children.length<2)return null;let t=e.children[e.children.length-1];if(t?.t!==`actions`)return null;let n=e.children.slice(0,-1);return n.some(J)?null:{body:{...e,children:n},actions:t}}function ge(e,t){let n=window.matchMedia?.(`(prefers-reduced-motion: reduce)`).matches;e?.scrollIntoView({behavior:n?`auto`:`smooth`,block:t})}function _e(e){let[t,n]=(0,K.useState)(!0);return(0,K.useEffect)(()=>{let t=e.current;if(!t||typeof IntersectionObserver>`u`)return;let r=new IntersectionObserver(([e])=>n(!!e?.isIntersecting));return r.observe(t),()=>r.disconnect()},[e]),t}function ve(e){if(e.t===`markdown`)return e.text;if(e.t===`section`)for(let t of e.children){let e=ve(t);if(e!==null)return e}return null}function ye(e){if(!he(e))return!1;let t=ve(e);return t!==null&&(t.length>=400||t.split(`
2
2
  `).length>=12)}function be(e){let t=/^\s*#{1,6}\s+(.+?)\s*(?:\n+|$)/.exec(e);return t?.[1]?{title:t[1],rest:e.slice(t[0].length)}:{title:null,rest:e}}function xe(e){let t=[],n=!1;for(let r of e.split(`
3
- `)){/^\s*```/.test(r)&&(n=!n);let e=n?null:/^##\s+(.+?)\s*$/.exec(r);e?.[1]&&t.push({text:e[1],id:U(e[1])})}return t}function Se(e,t){let[n,r]=(0,K.useState)(null),[i,a]=(0,K.useState)(null),o=e.join(`|`);(0,K.useEffect)(()=>{if(typeof IntersectionObserver>`u`||!e.length)return;let n=e.map(e=>t.current?.querySelector(`#${CSS.escape(e)}`)).filter(e=>!!e),i=new IntersectionObserver(e=>{for(let t of e)t.isIntersecting&&r(t.target.id)},{rootMargin:`-56px 0px -70% 0px`});for(let e of n)i.observe(e);let o=()=>a(null);return window.addEventListener(`wheel`,o,{passive:!0}),window.addEventListener(`touchmove`,o,{passive:!0}),window.addEventListener(`keydown`,o),()=>{i.disconnect(),window.removeEventListener(`wheel`,o),window.removeEventListener(`touchmove`,o),window.removeEventListener(`keydown`,o)}},[o,t]);let s=i??n;return(0,K.useEffect)(()=>{let e=t.current;if(e){for(let t of e.querySelectorAll(`h2[data-active]`))delete t.dataset.active;if(s){let t=e.querySelector(`#${CSS.escape(s)}`);t&&(t.dataset.active=`true`)}}},[s,o,t]),[s,a]}function Ce({id:e,interaction:t,node:n,onRespond:r,busy:i,disabled:o,disabledReason:s,part:c,planAnchorId:l,mobile:u,sticky:d,flush:f,className:m}){let h=(0,K.useRef)(null),g=(0,K.useRef)(null),v=(0,K.useRef)(null),y=_e(v),[b,x]=(0,K.useState)(!1),C=he(n),{title:w,rest:T}=be((C?.body.t===`section`?C.body.children.find(e=>e.t===`markdown`):void 0)?.text??``),E=xe(T),[D,O]=Se(E.map(e=>e.id),h);if(C?.body.t!==`section`)return null;let k=C.actions.actions,A=C.body.children.find(e=>e.t===`section`),j=t.title,M=w??j,N=e=>{x(!1),r({kind:`action`,actionId:e})},P=(e,t)=>e===0||t===`primary`?`primary`:t===`danger`?`danger`:`secondary`,F=!o&&!y,I=`h-auto! min-h-9 min-w-0 py-1.5 text-left leading-tight whitespace-normal!`,z=e=>ge(e,`start`),B=()=>c===`answers`?l?document.getElementById(l):null:g.current,V=c!==`answers`||l!==void 0,H=u?(0,q.jsxs)(q.Fragment,{children:[V&&(0,q.jsx)(S,{label:`Plan start`,icon:(0,q.jsx)(L,{className:`size-4`}),variant:`secondary`,onClick:()=>z(B())}),k.length>2?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(a,{variant:`primary`,disabled:i,className:p(I,`flex-1`),onClick:()=>N(k[0].id),children:k[0].label}),(0,q.jsxs)(a,{variant:`secondary`,onClick:()=>x(!0),children:[`More (`,k.length-1,`)`]})]}):k.map((e,t)=>(0,q.jsx)(a,{variant:P(t,e.tone),disabled:i,className:p(I,`flex-1`),onClick:()=>N(e.id),children:e.label},e.id))]}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`span`,{className:`max-w-[16rem] min-w-0 shrink truncate text-sm font-medium`,title:j,children:j}),(0,q.jsx)(`div`,{className:`grid min-w-0 flex-1 grid-cols-[repeat(auto-fit,minmax(11rem,1fr))] gap-2`,children:k.map((e,t)=>(0,q.jsx)(a,{variant:P(t,e.tone),disabled:i,className:p(I,`w-full md:text-center`),onClick:()=>N(e.id),children:e.label},e.id))}),V&&(0,q.jsx)(S,{label:`Plan start`,icon:(0,q.jsx)(L,{className:`size-4`}),variant:`secondary`,size:`sm`,onClick:()=>z(B())})]}),U=(0,q.jsx)(_,{open:b,onClose:()=>x(!1),title:j,children:(0,q.jsx)(`div`,{className:`flex flex-col gap-2`,children:k.map((e,t)=>(0,q.jsx)(a,{block:!0,variant:P(t,e.tone),disabled:i,className:I,onClick:()=>N(e.id),children:e.label},e.id))})});if(c===`answers`)return(0,q.jsxs)(`article`,{"aria-label":`Question: ${j}`,"data-testid":`plan-answers`,className:p(`flex min-w-0 flex-col gap-2`,m),children:[u&&(0,q.jsx)(`p`,{className:`text-sm font-medium`,children:j}),s?(0,q.jsx)(`p`,{className:`text-sm text-muted`,children:s}):(0,q.jsx)(`div`,{"data-testid":`answer-bar`,className:`flex min-w-0 items-center gap-2 md:gap-3`,children:H}),U]});let W=c===`reader`;return(0,q.jsxs)(`article`,{id:e,"data-testid":`document-interaction`,"aria-label":`Question: ${j}`,className:p(`w-full min-w-0 self-stretch border-t border-border`,m),children:[(0,q.jsxs)(`header`,{className:p(`z-10 flex min-w-0 items-center gap-2 border-b border-border bg-bg px-4 py-2 md:px-6`,d&&(f?`md:sticky md:top-0`:`max-md:static md:sticky md:-top-3`)),children:[(0,q.jsx)(`h3`,{className:`min-w-0 flex-1 truncate text-[15px] leading-snug font-semibold md:text-sm`,children:M}),u&&!W&&(0,q.jsx)(ee,{kind:`interaction`,value:t.state,size:`sm`,className:`[&>span]:sr-only`}),!W&&!o&&!y&&(0,q.jsx)(te,{size:`xs`,className:`shrink-0`,onClick:()=>ge(v.current,`center`),children:`Jump to options ↓`})]}),A&&(0,q.jsx)(`aside`,{className:`mx-4 mt-3 rounded-md bg-warning-soft px-3 py-2 text-sm md:mx-6`,children:(0,q.jsx)(R,{node:A})}),(0,q.jsxs)(`div`,{className:`px-4 py-4 md:grid md:grid-cols-[13rem_minmax(0,1fr)] 2xl:grid-cols-[15rem_minmax(0,1fr)] md:gap-8 md:px-6`,children:[E.length>0&&(0,q.jsx)(`nav`,{"aria-label":`Plan sections`,className:`hidden md:block`,children:(0,q.jsxs)(`ol`,{className:`sticky top-16 flex flex-col gap-0.5 border-l border-border text-sm`,children:[(0,q.jsx)(`li`,{children:(0,q.jsx)(`button`,{type:`button`,className:`-ml-px block w-full truncate border-l-2 border-transparent py-1 pl-3 text-left text-muted hover:text-text`,onClick:()=>z(g.current),children:`Start`})}),E.map(e=>(0,q.jsx)(`li`,{children:(0,q.jsx)(`button`,{type:`button`,"aria-current":D===e.id,className:`-ml-px block w-full truncate border-l-2 border-transparent py-1 pl-3 text-left text-muted hover:text-text aria-[current=true]:border-accent aria-[current=true]:text-text`,onClick:()=>{O(e.id),z(h.current?.querySelector(`#${CSS.escape(e.id)}`)??null)},children:e.text})},e.id))]})}),(0,q.jsx)(`div`,{ref:g,className:`min-w-0 scroll-mt-14`,children:(0,q.jsx)(`div`,{ref:h,className:`sy-prose-compact max-w-[80ch] min-w-0 2xl:max-w-[100ch] min-[1800px]:text-base [&_h2]:scroll-mt-14`,children:(0,q.jsx)(ne,{text:T,headingIds:!0,className:`text-inherit`})})})]}),!W&&(0,q.jsxs)(`section`,{ref:v,"data-testid":`plan-options`,"aria-label":j,className:`border-t border-border px-4 py-3 md:px-6`,children:[(0,q.jsx)(`p`,{className:`mb-2 text-sm font-medium`,children:j}),!o&&(0,q.jsx)(`div`,{className:`flex min-w-0 flex-col gap-2 md:flex-row md:flex-wrap`,children:k.map((e,t)=>(0,q.jsx)(a,{variant:P(t,e.tone),size:`md`,disabled:i,className:p(I,`md:text-center`),onClick:()=>N(e.id),children:e.label},e.id))}),(0,q.jsx)(te,{size:`xs`,className:`mt-2`,icon:(0,q.jsx)(L,{"aria-hidden":!0,className:`size-3.5`}),onClick:()=>z(g.current),children:`Back to the plan start`})]}),!W&&F&&(0,q.jsx)(`div`,{"data-testid":`answer-bar`,className:p(`z-10 flex min-w-0 items-center gap-2 border-t border-border bg-bg px-4 py-2 md:gap-3 md:px-6`,d&&!f?`sticky -bottom-3`:`sticky bottom-0`),children:H}),!W&&U]})}var we={red:`bg-[#e5484d] text-white`,orange:`bg-[#f76b15] text-white`,blue:`bg-[#0090ff] text-white`,gray:`bg-[#6e7681] text-white`,green:`bg-[#30a46c] text-white`},Te=`transform 260ms cubic-bezier(0.2, 0.9, 0.25, 1)`,Ee=`input, textarea, select, [contenteditable], [data-no-swipe]`,X=null;function De({leading:e=[],trailing:t=[],disabled:n,children:r,className:i,contentClassName:a}){let o=(0,K.useRef)(null),s=(0,K.useRef)(null),c=(0,K.useRef)(!1),[l,u]=(0,K.useState)(0),[d,f]=(0,K.useState)(!1),m=(0,K.useRef)(0),_=(0,K.useRef)({leading:e,trailing:t});_.current={leading:e,trailing:t};let y=!n&&(e.length>0||t.length>0),x=()=>o.current?.offsetWidth||320,S=(e,t)=>{let n=o.current;n&&(n.style.transition=t?Te:`none`,n.style.transform=e===0?``:`translateX(${e}px)`),m.current=e,u(e)},w=(0,K.useRef)(()=>{});w.current=()=>{S(0,!0),f(!1),X===T&&(X=null)};let[T]=(0,K.useState)(()=>()=>w.current()),E=async(e,t)=>{if(W(),e.removes){let n=x();f(!0),S(t===`leading`?n:-n,!0);try{await e.onAction()}catch{w.current();return}let r=o.current?.parentElement;r&&!window.matchMedia?.(`(prefers-reduced-motion: reduce)`).matches&&r.animate?.([{height:`${r.offsetHeight}px`},{height:`0px`}],{duration:220,easing:`cubic-bezier(0.2, 0.8, 0.2, 1)`,fill:`forwards`})}else w.current(),await e.onAction()},D=l!==0;(0,K.useEffect)(()=>{if(!D)return;let e=e=>{o.current?.parentElement?.contains(e.target)||s.current||w.current()};return document.addEventListener(`pointerdown`,e,!0),()=>document.removeEventListener(`pointerdown`,e,!0)},[D]),(0,K.useEffect)(()=>()=>{X===T&&(X=null)},[T]);let O=e=>{y&&e.isPrimary&&(e.pointerType===`touch`||e.pointerType===`pen`)&&(e.target.closest(Ee)||(c.current=!1,s.current={id:e.pointerId,x:e.clientX,y:e.clientY,axis:null,start:m.current,raw:m.current,full:!1,samples:[]}))},k=e=>{let t=s.current;if(!t||e.pointerId!==t.id)return;let n=e.clientX-t.x;if(t.axis===null){if(t.axis=v(n,e.clientY-t.y),t.axis===null)return;if(t.axis===`y`){s.current=null;return}c.current=!0,e.currentTarget.setPointerCapture?.(e.pointerId),X&&X!==T&&X()}let{leading:r,trailing:i}=_.current,a=x(),o=t.start+n;o>0&&r.length===0&&(o=g(o,a)*.15),o<0&&i.length===0&&(o=g(o,a)*.15),t.raw=o,t.samples.push({t:e.timeStamp,v:o}),t.samples=t.samples.slice(-12);let l=(o>0?r.length:i.length)*76,u=l>0&&Math.abs(o)>=b(a,l);u!==t.full&&(t.full=u,f(u),W()),S(o,!1)},A=e=>{let t=s.current;if(s.current=null,t?.axis!==`x`)return;let{leading:n,trailing:r}=_.current;if(e.type===`pointercancel`)return w.current();let i=h(t.raw,C(t.samples),{width:x(),reveal:{leading:n.length*76,trailing:r.length*76},fullSwipe:{leading:!0,trailing:!0}});if(i.kind===`close`)return w.current();let a=i.side===`leading`?n:r,o=a[0];if(!o)return w.current();if(i.kind===`commit`)return void E(o,i.side);f(!1),S((i.side===`leading`?1:-1)*a.length*76,!0),X=T},j=l>0?`leading`:`trailing`,M=l>0?e:t,N=j===`trailing`?[...M].reverse():M;return(0,q.jsxs)(`div`,{className:p(`relative overflow-hidden`,i),"data-swipe-row":!0,children:[l!==0&&M.length>0&&(0,q.jsx)(`div`,{"aria-hidden":!0,className:p(`absolute inset-y-0 flex`,j===`leading`?`left-0`:`right-0`),style:{width:Math.abs(l)},children:N.map(e=>{let t=e===M[0];return(0,q.jsxs)(`button`,{type:`button`,tabIndex:-1,"data-swipe-action":e.id,onClick:()=>void E(e,j),style:{flexGrow:d?+!!t:1,flexBasis:0},className:p(`flex min-w-0 flex-col items-center justify-center gap-1 overflow-hidden text-xs font-semibold whitespace-nowrap transition-[flex-grow] duration-200`,we[e.tone],d&&t&&(j===`leading`?`items-start pl-6`:`items-end pr-6`)),children:[e.icon,e.label]},e.id)})}),(0,q.jsx)(`div`,{ref:o,className:p(`relative touch-pan-y bg-surface`,a),onPointerDown:O,onPointerMove:k,onPointerUp:A,onPointerCancel:A,onClickCapture:e=>{c.current?(c.current=!1,e.preventDefault(),e.stopPropagation()):m.current!==0&&(e.preventDefault(),e.stopPropagation(),w.current())},children:r})]})}function Oe(e){let n=t(e=>e.issues);return(0,K.useMemo)(()=>{let t=Object.values(n),r=e?F(t)(e):null;return{linked:r,candidates:e&&!r?t.filter(n=>k(n,e,t)===null).sort(D):[],canUnlink:!!r&&O(r)===null}},[n,e])}function ke({open:e,onClose:t,workspace:n,candidates:r}){let[i,o]=(0,K.useState)(null),[s,c]=(0,K.useState)(null),l=()=>{c(null),t()},f=async e=>{if(!i){o(e.id),c(null);try{await P(e.id,n.id),V.success(`Linked to #${e.number}`),l()}catch(e){c(e)}finally{o(null)}}};return(0,q.jsx)(y,{open:e,onClose:l,title:`Link to issue`,description:`Link ${n.branch} to an issue that has no branch yet. Its sessions then stay in the issue's scope.`,footer:(0,q.jsx)(a,{onClick:l,children:`Cancel`}),children:(0,q.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[s!==null&&(0,q.jsx)(u,{compact:!0,title:`Could not link`,error:d(s)}),r.length===0&&(0,q.jsx)(`p`,{className:`text-sm text-muted`,children:`No issue without a branch in this project.`}),(0,q.jsx)(`ul`,{className:`flex min-w-0 flex-col gap-1`,children:r.map(e=>(0,q.jsx)(`li`,{className:`min-w-0`,children:(0,q.jsxs)(`button`,{type:`button`,disabled:!!i,"aria-busy":i===e.id,onClick:()=>void f(e),className:`tap flex w-full min-w-0 flex-col rounded-md px-2 py-1.5 text-left hover:bg-surface-2 disabled:opacity-55`,children:[(0,q.jsxs)(`span`,{className:`truncate text-sm`,children:[`#`,e.number,` `,e.title]}),(0,q.jsxs)(`span`,{className:`truncate text-xs text-muted`,children:[e.repository,e.board?.priority?` · ${e.board.priority.name}`:``]})]})},e.id))})]})})}var Ae=[];function je(e,n,r){let i=r&&!!e&&!n,[a,o]=(0,K.useState)(null);return(0,K.useEffect)(()=>{if(!i||!e)return;let n=new AbortController;return o({id:e,lookup:{state:`loading`}}),G.get(e,n.signal).then(e=>{t.getState().upsertSessionIfMissing(e),o(null)},t=>{n.signal.aborted||o({id:e,lookup:f(t,`not_found`)?{state:`missing`}:{state:`error`,error:d(t)}})}),()=>n.abort()},[i,e]),i?a?.id===e?a.lookup:{state:`loading`}:{state:`idle`}}function Me(e){let n=t(t=>e?t.hosts[e.hostId]:void 0),r=t(t=>e?.projectId?t.projects[e.projectId]:void 0),i=t(t=>e?.workspaceId?t.workspaces[e.workspaceId]:void 0),a=t(e=>e.runs),o=t(e=>e.tasks),s=t(t=>e?t.adapters[e.hostId]??Ae:Ae);return(0,K.useMemo)(()=>{if(!e)return null;let t=T(a,e),c=e.taskId??t?.taskId??null;return{session:e,host:n,hostName:n?.name??`Unknown host`,link:I(n,e),project:r,workspace:i,run:t,task:c?o[c]:void 0,control:E(t),adapters:s}},[e,n,r,i,a,o,s])}function Z(e,t={}){let[n,r]=(0,K.useState)(!1),[i,a]=(0,K.useState)(null),o=(0,K.useRef)(e);o.current=e;let s=(0,K.useRef)(t);s.current=t;let c=(0,K.useRef)(!0);return(0,K.useEffect)(()=>(c.current=!0,()=>{c.current=!1}),[]),{run:(0,K.useCallback)(async(...e)=>{r(!0),a(null);try{let t=await o.current(...e),{success:n}=s.current,r=typeof n==`function`?n(t):n;return r&&V.success(r),!0}catch(e){return c.current&&a(e),s.current.errorToast&&V.error(d(e)),!1}finally{c.current&&r(!1)}},[]),busy:n,error:i,reset:(0,K.useCallback)(()=>a(null),[])}}function Ne(e,t=1e3){let[n,r]=(0,K.useState)(()=>Date.now());return(0,K.useEffect)(()=>{if(!e)return;r(Date.now());let n=setInterval(()=>r(Date.now()),t);return()=>clearInterval(n)},[e,t]),n}function Pe(){let e=(0,K.useRef)(null),[t,n]=(0,K.useState)(0);return(0,K.useLayoutEffect)(()=>{let t=e.current;if(!t)return;n(t.clientWidth);let r=new ResizeObserver(([e])=>{e&&n(e.contentRect.width)});return r.observe(t),()=>r.disconnect()},[]),[e,t]}function Q({label:e,value:t}){return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`dt`,{className:`text-muted`,children:e}),(0,q.jsx)(`dd`,{className:`min-w-0 font-mono text-xs break-all`,children:t})]})}function Fe({session:e,hostLabel:t,open:n,onClose:r}){let a=w(e),o=e.stats;return(0,q.jsx)(y,{open:n,onClose:r,title:`Session info`,children:(0,q.jsxs)(`dl`,{className:`grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-2 text-sm`,children:[(0,q.jsx)(Q,{label:`Switchyard session`,value:e.id}),(0,q.jsx)(Q,{label:`Pi session id`,value:e.nativeHandle?.sessionId??`Not started`}),(0,q.jsx)(Q,{label:`Session file`,value:e.nativeHandle?.sessionFile??`None yet`}),(0,q.jsx)(Q,{label:`Host`,value:t}),(0,q.jsx)(Q,{label:`Working directory`,value:e.cwd}),(0,q.jsx)(Q,{label:`Origin`,value:e.provenance}),(0,q.jsx)(Q,{label:`Profile`,value:e.profileSnapshot.name}),(0,q.jsx)(Q,{label:`Created`,value:i(e.createdAt)}),o?.tokens!=null&&(0,q.jsx)(Q,{label:`Tokens`,value:o.tokens.toLocaleString(`en-US`)}),o?.costUsd!=null&&(0,q.jsx)(Q,{label:`Cost`,value:`$${o.costUsd.toFixed(2)}`}),a&&(0,q.jsx)(Q,{label:`Context`,value:`${a.label} (${a.detail})`})]})})}function Ie(e){let{session:i,run:s,control:l}=e,f=c(),[p,m]=(0,K.useState)(null),[h,g]=(0,K.useState)(i.title),_=Oe(i.provenance===`subagent`?null:e.workspace),v=t(e=>e.attention),b=(0,K.useMemo)(()=>Object.values(v).filter(e=>e.sessionId===i.id&&!e.resolvedAt&&n(e.reason)),[v,i.id]),S=t(e=>{if(i.provenance===`subagent`||i.archivedAt)return!1;let t=Object.values(e.sessions).filter(e=>e.archivedAt===null&&e.provenance!==`subagent`&&(i.workspaceId?e.workspaceId===i.workspaceId:e.workspaceId===null&&e.hostId===i.hostId&&e.cwd===i.cwd));return M(t)?.id===i.id}),C=Z(()=>G.takeover(i.id),{success:`You have control. Automatic continuations are paused.`,errorToast:!0}),w=Z(()=>G.returnToAutomation(i.id),{success:`Returned to automation.`,errorToast:!0}),T=Z(()=>G.stop(i.id),{success:`Session stopped.`}),E=Z(()=>G.resume(i.id),{success:`Session resumed.`,errorToast:!0}),D=Z(e=>G.rename(i.id,e),{success:`Session renamed.`}),O=Z(()=>G.cacheAlert(i.id,!i.cacheAlert),{errorToast:!0}),k=Z(()=>G.archive(i.id),{success:`Session archived.`}),P=Z(()=>G.unarchive(i.id),{success:`Session unarchived.`,errorToast:!0}),F=e.link===`connected`,I=()=>{m(null),T.reset(),D.reset(),k.reset()},L=N(i)?`Stop the session before archiving it`:null,R=(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(x,{open:p===`stop`,onClose:I,title:`Stop this session?`,description:`Stops the current execution and clears queued messages.`,confirmLabel:`Stop session`,busy:T.busy,error:T.error,errorTitle:`Could not stop`,onConfirm:()=>void T.run().then(e=>e&&m(null)),children:(0,q.jsx)(`p`,{className:`text-sm text-muted`,children:s?`The task keeps its run, marked interrupted and blocked (Stopped by user). Automation settings are unchanged.`:`Pi stays available; you can send a new message afterwards.`})}),(0,q.jsx)(y,{open:p===`rename`,onClose:I,title:`Rename session`,footer:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(a,{onClick:I,children:`Cancel`}),(0,q.jsx)(a,{variant:`primary`,type:`submit`,form:`sy-rename-form`,busy:D.busy,disabled:!h.trim(),children:`Save`})]}),children:(0,q.jsxs)(`form`,{id:`sy-rename-form`,onSubmit:e=>{e.preventDefault(),h.trim()&&D.run(h.trim()).then(e=>e&&m(null))},className:`flex flex-col gap-2`,children:[(0,q.jsx)(re,{id:`sy-rename-input`,label:`Title`,children:(0,q.jsx)(B,{id:`sy-rename-input`,value:h,maxLength:200,onChange:e=>g(e.target.value)})}),D.error!==null&&(0,q.jsx)(u,{compact:!0,title:`Could not rename`,error:d(D.error)})]})}),(0,q.jsx)(x,{open:p===`archive`,onClose:I,title:`Archive this session?`,description:`It leaves the navigator. The Pi session file stays on the host.`,danger:!1,confirmLabel:`Archive`,busy:k.busy,error:k.error,errorTitle:`Could not archive`,onConfirm:()=>void k.run().then(e=>{e&&(m(null),f(`/code`))}),children:i.runtime===`idle`&&(0,q.jsx)(`p`,{className:`text-sm text-muted`,children:`The idle Pi process is stopped first.`})}),e.workspace&&(0,q.jsx)(ke,{open:p===`link`,onClose:I,workspace:e.workspace,candidates:_.candidates}),(0,q.jsx)(Fe,{session:i,hostLabel:`${e.hostName} (${e.link})`,open:p===`info`,onClose:I})]});return{canTakeover:l===`automation`,canReturn:l===`human`,canStop:N(i)&&F,canResume:!A(i)&&!!i.nativeHandle&&!i.readOnly&&F,archiveBlocked:L,takeover:()=>void C.run(),returnToAutomation:()=>void w.run(),requestStop:()=>m(`stop`),resume:()=>void E.run(),openRename:()=>{g(i.title),m(`rename`)},requestArchive:()=>{L?V.info(L):m(`archive`)},openInfo:()=>m(`info`),toggleCacheAlert:()=>void O.run(),unarchive:()=>void P.run(),dismissAttention:b.length>0?()=>{Promise.all(b.map(Le)).then(()=>V.success(`Cleared. A question Pi is still waiting on stays.`)).catch(e=>V.error(d(e)))}:null,setPinned:(e,t)=>{let n=`/api/scopes/${encodeURIComponent(e)}/sessions/${encodeURIComponent(i.id)}`;(t?o(n):r(n)).catch(e=>V.error(d(e)))},isPrimary:S,setPrimary:e=>{G.setPrimary(i.id,e).catch(e=>V.error(d(e)))},newInBranch:i.projectId&&i.workspaceId?()=>{G.createSession({projectId:i.projectId,workspace:{existingId:i.workspaceId},prompt:``}).then(e=>{t.getState().upsertSessionIfMissing(e),f(`/code/${encodeURIComponent(e.id)}`)}).catch(e=>V.error(d(e)))}:null,issueLink:e.workspace&&i.provenance!==`subagent`?{..._,open:()=>m(`link`),unlink:()=>{let e=_.linked;e&&j(e.id).then(()=>V.success(`Unlinked from #${e.number}`)).catch(e=>V.error(d(e)))}}:null,busy:{takeover:C.busy,ret:w.busy,stop:T.busy,resume:E.busy,unarchive:P.busy},dialogs:R}}async function Le(e){let n=await o(`/api/attention/${encodeURIComponent(e.id)}/dismiss`),r=n&&typeof n==`object`&&`id`in n?n:{...e,resolvedAt:new Date().toISOString()};return t.setState(t=>t.attention[e.id]?{attention:{...t.attention,[e.id]:r}}:{}),r}var $=[`needs_input`,`failed`,`ready_for_review`,`unsupported_interaction`,`host_unreachable`,`cache_expiring`];function Re(e){let t=Object.fromEntries($.map(e=>[e,[]]));for(let n of e)t[n.reason]?.push(n);return t}var ze={dismiss:`Marks it as seen and moves it to Dismissed; it stays open, and a question keeps flagging its session.`,clear:`Resolves it now: the session loses this flag and the item moves to History.`,clearNeedsInput:`Removes this session's Needs input flag and moves it to History; a question Pi is still waiting on stays.`};function Be(e){return e===`dismissed`||e===`history`?e:`open`}function Ve(e,t){return t===`history`?[]:e.filter(e=>t===`open`?!e.acknowledgedAt:!!e.acknowledgedAt)}function He(e,t,n){return[e?.name,t?.title,n&&n.title!==t?.title?n.title:null].filter(Boolean).join(` · `)||`Switchyard`}export{Y as _,Be as a,ue as b,Ie as c,Z as d,Ne as f,pe as g,De as h,Re as i,Fe as l,je as m,$ as n,Ve as o,Me as p,He as r,Le as s,ze as t,Pe as u,ye as v,ie as y};
4
- //# sourceMappingURL=logic-3so3T0af.js.map
3
+ `)){/^\s*```/.test(r)&&(n=!n);let e=n?null:/^##\s+(.+?)\s*$/.exec(r);e?.[1]&&t.push({text:e[1],id:U(e[1])})}return t}function Se(e,t){let[n,r]=(0,K.useState)(null),[i,a]=(0,K.useState)(null),o=e.join(`|`);(0,K.useEffect)(()=>{if(typeof IntersectionObserver>`u`||!e.length)return;let n=e.map(e=>t.current?.querySelector(`#${CSS.escape(e)}`)).filter(e=>!!e),i=new IntersectionObserver(e=>{for(let t of e)t.isIntersecting&&r(t.target.id)},{rootMargin:`-56px 0px -70% 0px`});for(let e of n)i.observe(e);let o=()=>a(null);return window.addEventListener(`wheel`,o,{passive:!0}),window.addEventListener(`touchmove`,o,{passive:!0}),window.addEventListener(`keydown`,o),()=>{i.disconnect(),window.removeEventListener(`wheel`,o),window.removeEventListener(`touchmove`,o),window.removeEventListener(`keydown`,o)}},[o,t]);let s=i??n;return(0,K.useEffect)(()=>{let e=t.current;if(e){for(let t of e.querySelectorAll(`h2[data-active]`))delete t.dataset.active;if(s){let t=e.querySelector(`#${CSS.escape(s)}`);t&&(t.dataset.active=`true`)}}},[s,o,t]),[s,a]}function Ce({id:e,interaction:t,node:n,onRespond:r,busy:i,disabled:o,disabledReason:s,part:c,planAnchorId:l,mobile:u,sticky:d,flush:f,className:m}){let h=(0,K.useRef)(null),g=(0,K.useRef)(null),v=(0,K.useRef)(null),y=_e(v),[b,x]=(0,K.useState)(!1),C=he(n),{title:w,rest:T}=be((C?.body.t===`section`?C.body.children.find(e=>e.t===`markdown`):void 0)?.text??``),E=xe(T),[D,O]=Se(E.map(e=>e.id),h);if(C?.body.t!==`section`)return null;let k=C.actions.actions,A=C.body.children.find(e=>e.t===`section`),j=t.title,M=w??j,N=e=>{x(!1),r({kind:`action`,actionId:e})},P=(e,t)=>e===0||t===`primary`?`primary`:t===`danger`?`danger`:`secondary`,F=!o&&!y,I=`h-auto! min-h-9 min-w-0 py-1.5 text-left leading-tight whitespace-normal!`,z=e=>ge(e,`start`),B=()=>c===`answers`?l?document.getElementById(l):null:g.current,V=c!==`answers`||l!==void 0,H=u?(0,q.jsxs)(q.Fragment,{children:[V&&(0,q.jsx)(S,{label:`Plan start`,icon:(0,q.jsx)(L,{className:`size-4`}),variant:`secondary`,onClick:()=>z(B())}),k.length>2?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(a,{variant:`primary`,disabled:i,className:p(I,`flex-1`),onClick:()=>N(k[0].id),children:k[0].label}),(0,q.jsxs)(a,{variant:`secondary`,onClick:()=>x(!0),children:[`More (`,k.length-1,`)`]})]}):k.map((e,t)=>(0,q.jsx)(a,{variant:P(t,e.tone),disabled:i,className:p(I,`flex-1`),onClick:()=>N(e.id),children:e.label},e.id))]}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`span`,{className:`max-w-[16rem] min-w-0 shrink truncate text-sm font-medium`,title:j,children:j}),(0,q.jsx)(`div`,{className:`grid min-w-0 flex-1 grid-cols-[repeat(auto-fit,minmax(11rem,1fr))] gap-2`,children:k.map((e,t)=>(0,q.jsx)(a,{variant:P(t,e.tone),disabled:i,className:p(I,`w-full md:text-center`),onClick:()=>N(e.id),children:e.label},e.id))}),V&&(0,q.jsx)(S,{label:`Plan start`,icon:(0,q.jsx)(L,{className:`size-4`}),variant:`secondary`,size:`sm`,onClick:()=>z(B())})]}),U=(0,q.jsx)(_,{open:b,onClose:()=>x(!1),title:j,children:(0,q.jsx)(`div`,{className:`flex flex-col gap-2`,children:k.map((e,t)=>(0,q.jsx)(a,{block:!0,variant:P(t,e.tone),disabled:i,className:I,onClick:()=>N(e.id),children:e.label},e.id))})});if(c===`answers`)return(0,q.jsxs)(`article`,{"aria-label":`Question: ${j}`,"data-testid":`plan-answers`,className:p(`flex min-w-0 flex-col gap-2`,m),children:[u&&(0,q.jsx)(`p`,{className:`text-sm font-medium`,children:j}),s?(0,q.jsx)(`p`,{className:`text-sm text-muted`,children:s}):(0,q.jsx)(`div`,{"data-testid":`answer-bar`,className:`flex min-w-0 items-center gap-2 md:gap-3`,children:H}),U]});let W=c===`reader`;return(0,q.jsxs)(`article`,{id:e,"data-testid":`document-interaction`,"aria-label":`Question: ${j}`,className:p(`w-full min-w-0 self-stretch border-t border-border`,m),children:[(0,q.jsxs)(`header`,{className:p(`z-10 flex min-w-0 items-center gap-2 border-b border-border bg-bg px-4 py-2 md:px-6`,d&&(f?`md:sticky md:top-0`:`max-md:static md:sticky md:-top-3`)),children:[(0,q.jsx)(`h3`,{className:`min-w-0 flex-1 truncate text-[15px] leading-snug font-semibold md:text-sm`,children:M}),u&&!W&&(0,q.jsx)(ee,{kind:`interaction`,value:t.state,size:`sm`,className:`[&>span]:sr-only`}),!W&&!o&&!y&&(0,q.jsx)(te,{size:`xs`,className:`shrink-0`,onClick:()=>ge(v.current,`center`),children:`Jump to options ↓`})]}),A&&(0,q.jsx)(`aside`,{className:`mx-4 mt-3 rounded-md bg-warning-soft px-3 py-2 text-sm md:mx-6`,children:(0,q.jsx)(R,{node:A})}),(0,q.jsxs)(`div`,{className:`px-4 py-4 md:grid md:grid-cols-[13rem_minmax(0,1fr)] 2xl:grid-cols-[15rem_minmax(0,1fr)] md:gap-8 md:px-6`,children:[E.length>0&&(0,q.jsx)(`nav`,{"aria-label":`Plan sections`,className:`hidden md:block`,children:(0,q.jsxs)(`ol`,{className:`sticky top-16 flex flex-col gap-0.5 border-l border-border text-sm`,children:[(0,q.jsx)(`li`,{children:(0,q.jsx)(`button`,{type:`button`,className:`-ml-px block w-full truncate border-l-2 border-transparent py-1 pl-3 text-left text-muted hover:text-text`,onClick:()=>z(g.current),children:`Start`})}),E.map(e=>(0,q.jsx)(`li`,{children:(0,q.jsx)(`button`,{type:`button`,"aria-current":D===e.id,className:`-ml-px block w-full truncate border-l-2 border-transparent py-1 pl-3 text-left text-muted hover:text-text aria-[current=true]:border-accent aria-[current=true]:text-text`,onClick:()=>{O(e.id),z(h.current?.querySelector(`#${CSS.escape(e.id)}`)??null)},children:e.text})},e.id))]})}),(0,q.jsx)(`div`,{ref:g,className:`min-w-0 scroll-mt-14`,children:(0,q.jsx)(`div`,{ref:h,className:`sy-prose-compact max-w-[80ch] min-w-0 2xl:max-w-[100ch] min-[1800px]:text-base [&_h2]:scroll-mt-14`,children:(0,q.jsx)(ne,{text:T,headingIds:!0,className:`text-inherit`})})})]}),!W&&(0,q.jsxs)(`section`,{ref:v,"data-testid":`plan-options`,"aria-label":j,className:`border-t border-border px-4 py-3 md:px-6`,children:[(0,q.jsx)(`p`,{className:`mb-2 text-sm font-medium`,children:j}),!o&&(0,q.jsx)(`div`,{className:`flex min-w-0 flex-col gap-2 md:flex-row md:flex-wrap`,children:k.map((e,t)=>(0,q.jsx)(a,{variant:P(t,e.tone),size:`md`,disabled:i,className:p(I,`md:text-center`),onClick:()=>N(e.id),children:e.label},e.id))}),(0,q.jsx)(te,{size:`xs`,className:`mt-2`,icon:(0,q.jsx)(L,{"aria-hidden":!0,className:`size-3.5`}),onClick:()=>z(g.current),children:`Back to the plan start`})]}),!W&&F&&(0,q.jsx)(`div`,{"data-testid":`answer-bar`,className:p(`z-10 flex min-w-0 items-center gap-2 border-t border-border bg-bg px-4 py-2 md:gap-3 md:px-6`,d&&!f?`sticky -bottom-3`:`sticky bottom-0`),children:H}),!W&&U]})}var we={red:`bg-[#e5484d] text-white`,orange:`bg-[#f76b15] text-white`,blue:`bg-[#0090ff] text-white`,gray:`bg-[#6e7681] text-white`,green:`bg-[#30a46c] text-white`},Te=`transform 260ms cubic-bezier(0.2, 0.9, 0.25, 1)`,Ee=`input, textarea, select, [contenteditable], [data-no-swipe]`,X=null;function De({leading:e=[],trailing:t=[],disabled:n,children:r,className:i,contentClassName:a}){let o=(0,K.useRef)(null),s=(0,K.useRef)(null),c=(0,K.useRef)(!1),[l,u]=(0,K.useState)(0),[d,f]=(0,K.useState)(!1),m=(0,K.useRef)(0),_=(0,K.useRef)({leading:e,trailing:t});_.current={leading:e,trailing:t};let y=!n&&(e.length>0||t.length>0),x=()=>o.current?.offsetWidth||320,S=(e,t)=>{let n=o.current;n&&(n.style.transition=t?Te:`none`,n.style.transform=e===0?``:`translateX(${e}px)`),m.current=e,u(e)},w=(0,K.useRef)(()=>{});w.current=()=>{S(0,!0),f(!1),X===T&&(X=null)};let[T]=(0,K.useState)(()=>()=>w.current()),E=async(e,t)=>{if(W(),e.removes){let n=x();f(!0),S(t===`leading`?n:-n,!0);try{await e.onAction()}catch{w.current();return}let r=o.current?.parentElement;r&&!window.matchMedia?.(`(prefers-reduced-motion: reduce)`).matches&&r.animate?.([{height:`${r.offsetHeight}px`},{height:`0px`}],{duration:220,easing:`cubic-bezier(0.2, 0.8, 0.2, 1)`,fill:`forwards`})}else w.current(),await e.onAction()},D=l!==0;(0,K.useEffect)(()=>{if(!D)return;let e=e=>{o.current?.parentElement?.contains(e.target)||s.current||w.current()};return document.addEventListener(`pointerdown`,e,!0),()=>document.removeEventListener(`pointerdown`,e,!0)},[D]),(0,K.useEffect)(()=>()=>{X===T&&(X=null)},[T]);let O=e=>{y&&e.isPrimary&&(e.pointerType===`touch`||e.pointerType===`pen`)&&(e.target.closest(Ee)||(c.current=!1,s.current={id:e.pointerId,x:e.clientX,y:e.clientY,axis:null,start:m.current,raw:m.current,full:!1,samples:[]}))},k=e=>{let t=s.current;if(!t||e.pointerId!==t.id)return;let n=e.clientX-t.x;if(t.axis===null){if(t.axis=v(n,e.clientY-t.y),t.axis===null)return;if(t.axis===`y`){s.current=null;return}c.current=!0,e.currentTarget.setPointerCapture?.(e.pointerId),X&&X!==T&&X()}let{leading:r,trailing:i}=_.current,a=x(),o=t.start+n;o>0&&r.length===0&&(o=g(o,a)*.15),o<0&&i.length===0&&(o=g(o,a)*.15),t.raw=o,t.samples.push({t:e.timeStamp,v:o}),t.samples=t.samples.slice(-12);let l=(o>0?r.length:i.length)*76,u=l>0&&Math.abs(o)>=b(a,l);u!==t.full&&(t.full=u,f(u),W()),S(o,!1)},A=e=>{let t=s.current;if(s.current=null,t?.axis!==`x`)return;let{leading:n,trailing:r}=_.current;if(e.type===`pointercancel`)return w.current();let i=h(t.raw,C(t.samples),{width:x(),reveal:{leading:n.length*76,trailing:r.length*76},fullSwipe:{leading:!0,trailing:!0}});if(i.kind===`close`)return w.current();let a=i.side===`leading`?n:r,o=a[0];if(!o)return w.current();if(i.kind===`commit`)return void E(o,i.side);f(!1),S((i.side===`leading`?1:-1)*a.length*76,!0),X=T},j=l>0?`leading`:`trailing`,M=l>0?e:t,N=j===`trailing`?[...M].reverse():M;return(0,q.jsxs)(`div`,{className:p(`relative overflow-hidden`,i),"data-swipe-row":!0,children:[l!==0&&M.length>0&&(0,q.jsx)(`div`,{"aria-hidden":!0,className:p(`absolute inset-y-0 flex`,j===`leading`?`left-0`:`right-0`),style:{width:Math.abs(l)},children:N.map(e=>{let t=e===M[0];return(0,q.jsxs)(`button`,{type:`button`,tabIndex:-1,"data-swipe-action":e.id,onClick:()=>void E(e,j),style:{flexGrow:d?+!!t:1,flexBasis:0},className:p(`flex min-w-0 flex-col items-center justify-center gap-1 overflow-hidden text-xs font-semibold whitespace-nowrap transition-[flex-grow] duration-200`,we[e.tone],d&&t&&(j===`leading`?`items-start pl-6`:`items-end pr-6`)),children:[e.icon,e.label]},e.id)})}),(0,q.jsx)(`div`,{ref:o,className:p(`relative touch-pan-y bg-surface`,a),onPointerDown:O,onPointerMove:k,onPointerUp:A,onPointerCancel:A,onClickCapture:e=>{c.current?(c.current=!1,e.preventDefault(),e.stopPropagation()):m.current!==0&&(e.preventDefault(),e.stopPropagation(),w.current())},children:r})]})}function Oe(e){let n=t(e=>e.issues);return(0,K.useMemo)(()=>{let t=Object.values(n),r=e?D(t)(e):null;return{linked:r,candidates:e&&!r?t.filter(n=>P(n,e,t)===null).sort(j):[],canUnlink:!!r&&k(r)===null}},[n,e])}function ke({open:e,onClose:t,workspace:n,candidates:r}){let[i,o]=(0,K.useState)(null),[s,c]=(0,K.useState)(null),l=()=>{c(null),t()},f=async e=>{if(!i){o(e.id),c(null);try{await F(e.id,n.id),V.success(`Linked to #${e.number}`),l()}catch(e){c(e)}finally{o(null)}}};return(0,q.jsx)(y,{open:e,onClose:l,title:`Link to issue`,description:`Link ${n.branch} to an issue that has no branch yet. Its sessions then stay in the issue's scope.`,footer:(0,q.jsx)(a,{onClick:l,children:`Cancel`}),children:(0,q.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[s!==null&&(0,q.jsx)(u,{compact:!0,title:`Could not link`,error:d(s)}),r.length===0&&(0,q.jsx)(`p`,{className:`text-sm text-muted`,children:`No issue without a branch in this project.`}),(0,q.jsx)(`ul`,{className:`flex min-w-0 flex-col gap-1`,children:r.map(e=>(0,q.jsx)(`li`,{className:`min-w-0`,children:(0,q.jsxs)(`button`,{type:`button`,disabled:!!i,"aria-busy":i===e.id,onClick:()=>void f(e),className:`tap flex w-full min-w-0 flex-col rounded-md px-2 py-1.5 text-left hover:bg-surface-2 disabled:opacity-55`,children:[(0,q.jsxs)(`span`,{className:`truncate text-sm`,children:[`#`,e.number,` `,e.title]}),(0,q.jsxs)(`span`,{className:`truncate text-xs text-muted`,children:[e.repository,e.board?.priority?` · ${e.board.priority.name}`:``]})]})},e.id))})]})})}var Ae=[];function je(e,n,r){let i=r&&!!e&&!n,[a,o]=(0,K.useState)(null);return(0,K.useEffect)(()=>{if(!i||!e)return;let n=new AbortController;return o({id:e,lookup:{state:`loading`}}),G.get(e,n.signal).then(e=>{t.getState().upsertSessionIfMissing(e),o(null)},t=>{n.signal.aborted||o({id:e,lookup:c(t,`not_found`)?{state:`missing`}:{state:`error`,error:d(t)}})}),()=>n.abort()},[i,e]),i?a?.id===e?a.lookup:{state:`loading`}:{state:`idle`}}function Me(e){let n=t(t=>e?t.hosts[e.hostId]:void 0),r=t(t=>e?.projectId?t.projects[e.projectId]:void 0),i=t(t=>e?.workspaceId?t.workspaces[e.workspaceId]:void 0),a=t(e=>e.runs),o=t(e=>e.tasks),s=t(t=>e?t.adapters[e.hostId]??Ae:Ae);return(0,K.useMemo)(()=>{if(!e)return null;let t=T(a,e),c=e.taskId??t?.taskId??null;return{session:e,host:n,hostName:n?.name??`Unknown host`,link:I(n,e),project:r,workspace:i,run:t,task:c?o[c]:void 0,control:E(t),adapters:s}},[e,n,r,i,a,o,s])}function Z(e,t={}){let[n,r]=(0,K.useState)(!1),[i,a]=(0,K.useState)(null),o=(0,K.useRef)(e);o.current=e;let s=(0,K.useRef)(t);s.current=t;let c=(0,K.useRef)(!0);return(0,K.useEffect)(()=>(c.current=!0,()=>{c.current=!1}),[]),{run:(0,K.useCallback)(async(...e)=>{r(!0),a(null);try{let t=await o.current(...e),{success:n}=s.current,r=typeof n==`function`?n(t):n;return r&&V.success(r),!0}catch(e){return c.current&&a(e),s.current.errorToast&&V.error(d(e)),!1}finally{c.current&&r(!1)}},[]),busy:n,error:i,reset:(0,K.useCallback)(()=>a(null),[])}}function Ne(e,t=1e3){let[n,r]=(0,K.useState)(()=>Date.now());return(0,K.useEffect)(()=>{if(!e)return;r(Date.now());let n=setInterval(()=>r(Date.now()),t);return()=>clearInterval(n)},[e,t]),n}function Pe(){let e=(0,K.useRef)(null),[t,n]=(0,K.useState)(0);return(0,K.useLayoutEffect)(()=>{let t=e.current;if(!t)return;n(t.clientWidth);let r=new ResizeObserver(([e])=>{e&&n(e.contentRect.width)});return r.observe(t),()=>r.disconnect()},[]),[e,t]}function Q({label:e,value:t}){return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`dt`,{className:`text-muted`,children:e}),(0,q.jsx)(`dd`,{className:`min-w-0 font-mono text-xs break-all`,children:t})]})}function Fe({session:e,hostLabel:t,open:n,onClose:r}){let a=w(e),o=e.stats;return(0,q.jsx)(y,{open:n,onClose:r,title:`Session info`,children:(0,q.jsxs)(`dl`,{className:`grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-2 text-sm`,children:[(0,q.jsx)(Q,{label:`Switchyard session`,value:e.id}),(0,q.jsx)(Q,{label:`Pi session id`,value:e.nativeHandle?.sessionId??`Not started`}),(0,q.jsx)(Q,{label:`Session file`,value:e.nativeHandle?.sessionFile??`None yet`}),(0,q.jsx)(Q,{label:`Host`,value:t}),(0,q.jsx)(Q,{label:`Working directory`,value:e.cwd}),(0,q.jsx)(Q,{label:`Origin`,value:e.provenance}),(0,q.jsx)(Q,{label:`Profile`,value:e.profileSnapshot.name}),(0,q.jsx)(Q,{label:`Created`,value:i(e.createdAt)}),o?.tokens!=null&&(0,q.jsx)(Q,{label:`Tokens`,value:o.tokens.toLocaleString(`en-US`)}),o?.costUsd!=null&&(0,q.jsx)(Q,{label:`Cost`,value:`$${o.costUsd.toFixed(2)}`}),a&&(0,q.jsx)(Q,{label:`Context`,value:`${a.label} (${a.detail})`})]})})}function Ie(e){let{session:i,run:o,control:c}=e,l=s(),[p,m]=(0,K.useState)(null),[h,g]=(0,K.useState)(i.title),_=Oe(i.provenance===`subagent`?null:e.workspace),v=t(e=>e.attention),b=(0,K.useMemo)(()=>Object.values(v).filter(e=>e.sessionId===i.id&&!e.resolvedAt&&r(e.reason)),[v,i.id]),S=t(e=>{if(i.provenance===`subagent`||i.archivedAt)return!1;let t=Object.values(e.sessions).filter(e=>e.archivedAt===null&&e.provenance!==`subagent`&&(i.workspaceId?e.workspaceId===i.workspaceId:e.workspaceId===null&&e.hostId===i.hostId&&e.cwd===i.cwd));return O(t)?.id===i.id}),C=Z(()=>G.takeover(i.id),{success:`You have control. Automatic continuations are paused.`,errorToast:!0}),w=Z(()=>G.returnToAutomation(i.id),{success:`Returned to automation.`,errorToast:!0}),T=Z(()=>G.stop(i.id),{success:`Session stopped.`}),E=Z(()=>G.resume(i.id),{success:`Session resumed.`,errorToast:!0}),D=Z(e=>G.rename(i.id,e),{success:`Session renamed.`}),k=Z(()=>G.cacheAlert(i.id,!i.cacheAlert),{errorToast:!0}),j=Z(()=>G.archive(i.id),{success:`Session archived.`}),P=Z(()=>G.unarchive(i.id),{success:`Session unarchived.`,errorToast:!0}),F=e.link===`connected`,I=()=>{m(null),T.reset(),D.reset(),j.reset()},L=N(i)?`Stop the session before archiving it`:null,R=(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(x,{open:p===`stop`,onClose:I,title:`Stop this session?`,description:`Stops the current execution and clears queued messages.`,confirmLabel:`Stop session`,busy:T.busy,error:T.error,errorTitle:`Could not stop`,onConfirm:()=>void T.run().then(e=>e&&m(null)),children:(0,q.jsx)(`p`,{className:`text-sm text-muted`,children:o?`The task keeps its run, marked interrupted and blocked (Stopped by user). Automation settings are unchanged.`:`Pi stays available; you can send a new message afterwards.`})}),(0,q.jsx)(y,{open:p===`rename`,onClose:I,title:`Rename session`,footer:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(a,{onClick:I,children:`Cancel`}),(0,q.jsx)(a,{variant:`primary`,type:`submit`,form:`sy-rename-form`,busy:D.busy,disabled:!h.trim(),children:`Save`})]}),children:(0,q.jsxs)(`form`,{id:`sy-rename-form`,onSubmit:e=>{e.preventDefault(),h.trim()&&D.run(h.trim()).then(e=>e&&m(null))},className:`flex flex-col gap-2`,children:[(0,q.jsx)(re,{id:`sy-rename-input`,label:`Title`,children:(0,q.jsx)(B,{id:`sy-rename-input`,value:h,maxLength:200,onChange:e=>g(e.target.value)})}),D.error!==null&&(0,q.jsx)(u,{compact:!0,title:`Could not rename`,error:d(D.error)})]})}),(0,q.jsx)(x,{open:p===`archive`,onClose:I,title:`Archive this session?`,description:`It leaves the navigator. The Pi session file stays on the host.`,danger:!1,confirmLabel:`Archive`,busy:j.busy,error:j.error,errorTitle:`Could not archive`,onConfirm:()=>void j.run().then(e=>{e&&(m(null),l(`/code`))}),children:i.runtime===`idle`&&(0,q.jsx)(`p`,{className:`text-sm text-muted`,children:`The idle Pi process is stopped first.`})}),e.workspace&&(0,q.jsx)(ke,{open:p===`link`,onClose:I,workspace:e.workspace,candidates:_.candidates}),(0,q.jsx)(Fe,{session:i,hostLabel:`${e.hostName} (${e.link})`,open:p===`info`,onClose:I})]});return{canTakeover:c===`automation`,canReturn:c===`human`,canStop:N(i)&&F,canResume:!A(i)&&!!i.nativeHandle&&!i.readOnly&&F,archiveBlocked:L,takeover:()=>void C.run(),returnToAutomation:()=>void w.run(),requestStop:()=>m(`stop`),resume:()=>void E.run(),openRename:()=>{g(i.title),m(`rename`)},requestArchive:()=>{L?V.info(L):m(`archive`)},openInfo:()=>m(`info`),toggleCacheAlert:()=>void k.run(),unarchive:()=>void P.run(),dismissAttention:b.length>0?()=>{Promise.all(b.map(Le)).then(()=>V.success(`Cleared. A question Pi is still waiting on stays.`)).catch(e=>V.error(d(e)))}:null,setPinned:(e,t)=>{let r=`/api/scopes/${encodeURIComponent(e)}/sessions/${encodeURIComponent(i.id)}`;(t?f(r):n(r)).catch(e=>V.error(d(e)))},isPrimary:S,setPrimary:e=>{G.setPrimary(i.id,e).catch(e=>V.error(d(e)))},newInBranch:i.projectId&&i.workspaceId?()=>{G.createSession({projectId:i.projectId,workspace:{existingId:i.workspaceId},prompt:``}).then(e=>{t.getState().upsertSessionIfMissing(e),l(`/code/${encodeURIComponent(e.id)}`)}).catch(e=>V.error(d(e)))}:null,issueLink:e.workspace&&i.provenance!==`subagent`?{..._,open:()=>m(`link`),unlink:()=>{let e=_.linked;e&&M(e.id).then(()=>V.success(`Unlinked from #${e.number}`)).catch(e=>V.error(d(e)))}}:null,busy:{takeover:C.busy,ret:w.busy,stop:T.busy,resume:E.busy,unarchive:P.busy},dialogs:R}}async function Le(e){let n=await f(`/api/attention/${encodeURIComponent(e.id)}/dismiss`),r=n&&typeof n==`object`&&`id`in n?n:{...e,resolvedAt:new Date().toISOString()};return t.setState(t=>t.attention[e.id]?{attention:{...t.attention,[e.id]:r}}:{}),r}var $=[`needs_input`,`failed`,`ready_for_review`,`unsupported_interaction`,`host_unreachable`,`cache_expiring`];function Re(e){let t=Object.fromEntries($.map(e=>[e,[]]));for(let n of e)t[n.reason]?.push(n);return t}var ze={dismiss:`Marks it as seen and moves it to Dismissed; it stays open, and a question keeps flagging its session.`,clear:`Resolves it now: the session loses this flag and the item moves to History.`,clearNeedsInput:`Removes this session's Needs input flag and moves it to History; a question Pi is still waiting on stays.`};function Be(e){return e===`dismissed`||e===`history`?e:`open`}function Ve(e,t){return t===`history`?[]:e.filter(e=>t===`open`?!e.acknowledgedAt:!!e.acknowledgedAt)}function He(e,t,n){return[e?.name,t?.title,n&&n.title!==t?.title?n.title:null].filter(Boolean).join(` · `)||`Switchyard`}export{Y as _,Be as a,ue as b,Ie as c,Z as d,Ne as f,pe as g,De as h,Re as i,Fe as l,je as m,$ as n,Ve as o,Me as p,He as r,Le as s,ze as t,Pe as u,ye as v,ie as y};
4
+ //# sourceMappingURL=logic-BOdOYgZ4.js.map