@templatical/editor 0.25.2 → 0.26.1

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 (179) hide show
  1. package/dist/{AiChatSidebar-JLsbPnsH.js → AiChatSidebar-B_fwa6zc.js} +8 -8
  2. package/dist/{AiFeatureMenu-BvA-lViN.js → AiFeatureMenu-BBBKsYD4.js} +4 -4
  3. package/dist/{BlockIssueBadge-Cf0-GC3o.js → BlockIssueBadge-Buk3_6QF.js} +2 -2
  4. package/dist/{BlockPreviewCanvas-CnJIM5TO.js → BlockPreviewCanvas-zyyq2de0.js} +1 -1
  5. package/dist/{CloudEditor-Caq7z4-7.js → CloudEditor-DM3RRCVn.js} +19 -19
  6. package/dist/{CollaboratorBar-BFz4LgA0.js → CollaboratorBar-Coj8Ebwf.js} +2 -2
  7. package/dist/{ColorPicker-B5xXWWX5.js → ColorPicker-ClETsjA3.js} +1 -1
  8. package/dist/{CommentsSidebar-CGihWwn9.js → CommentsSidebar-CdRCCSDD.js} +10 -10
  9. package/dist/{CountdownToolbar-DpNCZAUI.js → CountdownToolbar-CBE9wRaV.js} +2 -2
  10. package/dist/{DesignReferenceSidebar-CiIHHiil.js → DesignReferenceSidebar-hDXOvGoV.js} +6 -6
  11. package/dist/{IssuesPanel-CUkmAC_S.js → IssuesPanel-Do7RLXsP.js} +5 -5
  12. package/dist/{MergeTagModeToggle-C6nS3qri.js → MergeTagModeToggle-D0t5NHBZ.js} +3 -3
  13. package/dist/{MergeTagSuggestion-98fAcuM-.js → MergeTagSuggestion-BJ43ihWR.js} +9 -9
  14. package/dist/{NumberWithSuffix-DB-1GNvx.js → NumberWithSuffix-D37ZWiZh.js} +1 -1
  15. package/dist/{ParagraphEditor-NgW-T9YV.js → ParagraphEditor-B-CYrQMY.js} +19 -19
  16. package/dist/{RichTextEditorContent-CN7OVR6u.js → RichTextEditorContent-fbYJXAio.js} +3 -3
  17. package/dist/{SaveBlockDialog-lgcmhAsO.js → SaveBlockDialog-CoVPZfUv.js} +6 -6
  18. package/dist/{SavedBlocksBrowserModal-3u247V2z.js → SavedBlocksBrowserModal-DX13xw0O.js} +7 -7
  19. package/dist/{SavedBlocksPanels-Dh6dABJt.js → SavedBlocksPanels-B7pBiZcc.js} +1 -1
  20. package/dist/{SavedBlocksPickBar-Bo82D3Qy.js → SavedBlocksPickBar-ZfqXByph.js} +2 -2
  21. package/dist/{SnapshotHistory-Dsb1i40w.js → SnapshotHistory-BxABntv5.js} +11 -11
  22. package/dist/{TemplateScoringPanel-Bzd_YSag.js → TemplateScoringPanel-BZUsb3FD.js} +10 -10
  23. package/dist/{TestEmailModal-DvqDTOcO.js → TestEmailModal-Db4qheuy.js} +7 -7
  24. package/dist/{TestEmailPanel-BXoVnAqu.js → TestEmailPanel-B-SXSnRg.js} +1 -1
  25. package/dist/{TitleEditor-DWSi998C.js → TitleEditor-DmoaKooA.js} +8 -8
  26. package/dist/{TplModal-DKn0h2qe.js → TplModal-Bym-Kf_i.js} +1 -1
  27. package/dist/{blockTypeIcons-DKlza6aR.js → blockTypeIcons-BnCXsB2I.js} +2 -2
  28. package/dist/bundle-stats.json +6 -6
  29. package/dist/cdn/chunks/{AiChatSidebar-BY1Iy-e8.js → AiChatSidebar-CFvS4-EZ.js} +35 -35
  30. package/dist/cdn/chunks/{AiChatSidebar-BY1Iy-e8.js.map → AiChatSidebar-CFvS4-EZ.js.map} +1 -1
  31. package/dist/cdn/chunks/{AiFeatureMenu-BS4Rek6j.js → AiFeatureMenu-a0gBZiJ9.js} +11 -11
  32. package/dist/cdn/chunks/{AiFeatureMenu-BS4Rek6j.js.map → AiFeatureMenu-a0gBZiJ9.js.map} +1 -1
  33. package/dist/cdn/chunks/{BlockIssueBadge-BcIQUe_Q.js → BlockIssueBadge-BEEY9o2o.js} +5 -5
  34. package/dist/cdn/chunks/{BlockIssueBadge-BcIQUe_Q.js.map → BlockIssueBadge-BEEY9o2o.js.map} +1 -1
  35. package/dist/cdn/chunks/{BlockPreviewCanvas-oND1iXLL.js → BlockPreviewCanvas-C27XK2q0.js} +22 -22
  36. package/dist/cdn/chunks/{BlockPreviewCanvas-oND1iXLL.js.map → BlockPreviewCanvas-C27XK2q0.js.map} +1 -1
  37. package/dist/cdn/chunks/{CloudEditor-BaqiFbf0.js → CloudEditor-Ddnatfuw.js} +65 -65
  38. package/dist/cdn/chunks/{CloudEditor-BaqiFbf0.js.map → CloudEditor-Ddnatfuw.js.map} +1 -1
  39. package/dist/cdn/chunks/{CollaboratorBar-DF02nTwF.js → CollaboratorBar-C5Xf6Mz9.js} +12 -12
  40. package/dist/cdn/chunks/{CollaboratorBar-DF02nTwF.js.map → CollaboratorBar-C5Xf6Mz9.js.map} +1 -1
  41. package/dist/cdn/chunks/{ColorPicker-BXH44v2H.js → ColorPicker-W_UyiVGc.js} +131 -131
  42. package/dist/cdn/chunks/{ColorPicker-BXH44v2H.js.map → ColorPicker-W_UyiVGc.js.map} +1 -1
  43. package/dist/cdn/chunks/{CommentsSidebar-B9bWvvbl.js → CommentsSidebar-BLRZRSSC.js} +112 -112
  44. package/dist/cdn/chunks/{CommentsSidebar-B9bWvvbl.js.map → CommentsSidebar-BLRZRSSC.js.map} +1 -1
  45. package/dist/cdn/chunks/{CountdownBlock-BTpRd0Hn.js → CountdownBlock-vLTkTI9e.js} +11 -11
  46. package/dist/cdn/chunks/{CountdownBlock-BTpRd0Hn.js.map → CountdownBlock-vLTkTI9e.js.map} +1 -1
  47. package/dist/cdn/chunks/{CountdownToolbar-CW10rbWt.js → CountdownToolbar-DPjcgcVR.js} +41 -41
  48. package/dist/cdn/chunks/{CountdownToolbar-CW10rbWt.js.map → CountdownToolbar-DPjcgcVR.js.map} +1 -1
  49. package/dist/cdn/chunks/{DesignReferenceSidebar-BXjH47QC.js → DesignReferenceSidebar-CZiP00JN.js} +28 -28
  50. package/dist/cdn/chunks/{DesignReferenceSidebar-BXjH47QC.js.map → DesignReferenceSidebar-CZiP00JN.js.map} +1 -1
  51. package/dist/cdn/chunks/{IssuesPanel-DStHCHfr.js → IssuesPanel-DKTS4QVb.js} +32 -32
  52. package/dist/cdn/chunks/{IssuesPanel-DStHCHfr.js.map → IssuesPanel-DKTS4QVb.js.map} +1 -1
  53. package/dist/cdn/chunks/{LoadingTrack-DQowK3MV.js → LoadingTrack-C52ZGL5q.js} +2 -2
  54. package/dist/cdn/chunks/{LoadingTrack-DQowK3MV.js.map → LoadingTrack-C52ZGL5q.js.map} +1 -1
  55. package/dist/cdn/chunks/{MergeTagModeToggle-BCmQg4Qe.js → MergeTagModeToggle-ClGdRNpZ.js} +20 -20
  56. package/dist/cdn/chunks/{MergeTagModeToggle-BCmQg4Qe.js.map → MergeTagModeToggle-ClGdRNpZ.js.map} +1 -1
  57. package/dist/cdn/chunks/{MergeTagSuggestion-BgExdloL.js → MergeTagSuggestion-Dn8dExNa.js} +18 -18
  58. package/dist/cdn/chunks/{MergeTagSuggestion-BgExdloL.js.map → MergeTagSuggestion-Dn8dExNa.js.map} +1 -1
  59. package/dist/cdn/chunks/{NumberWithSuffix-BANVbpT0.js → NumberWithSuffix-BXrRdfq1.js} +22 -22
  60. package/dist/cdn/chunks/{NumberWithSuffix-BANVbpT0.js.map → NumberWithSuffix-BXrRdfq1.js.map} +1 -1
  61. package/dist/cdn/chunks/{ParagraphEditor-DqilB4_f.js → ParagraphEditor-BNc146Pp.js} +43 -43
  62. package/dist/cdn/chunks/{ParagraphEditor-DqilB4_f.js.map → ParagraphEditor-BNc146Pp.js.map} +1 -1
  63. package/dist/cdn/chunks/{RichTextEditorContent-BeJx4LVH.js → RichTextEditorContent-DtL49Jpo.js} +20 -20
  64. package/dist/cdn/chunks/{RichTextEditorContent-BeJx4LVH.js.map → RichTextEditorContent-DtL49Jpo.js.map} +1 -1
  65. package/dist/cdn/chunks/{SaveBlockDialog-Dm31xRZy.js → SaveBlockDialog-ogieDQp7.js} +43 -43
  66. package/dist/cdn/chunks/{SaveBlockDialog-Dm31xRZy.js.map → SaveBlockDialog-ogieDQp7.js.map} +1 -1
  67. package/dist/cdn/chunks/{SavedBlocksBrowserModal-Tp37b4y7.js → SavedBlocksBrowserModal-DSpZcT_T.js} +62 -62
  68. package/dist/cdn/chunks/{SavedBlocksBrowserModal-Tp37b4y7.js.map → SavedBlocksBrowserModal-DSpZcT_T.js.map} +1 -1
  69. package/dist/cdn/chunks/{SavedBlocksPanels-ElerTTa_.js → SavedBlocksPanels-WYrSyf-l.js} +3 -3
  70. package/dist/cdn/chunks/{SavedBlocksPanels-ElerTTa_.js.map → SavedBlocksPanels-WYrSyf-l.js.map} +1 -1
  71. package/dist/cdn/chunks/{SavedBlocksPickBar-QHJ-Mjx0.js → SavedBlocksPickBar-DGbLBG5P.js} +12 -12
  72. package/dist/cdn/chunks/{SavedBlocksPickBar-QHJ-Mjx0.js.map → SavedBlocksPickBar-DGbLBG5P.js.map} +1 -1
  73. package/dist/cdn/chunks/{SnapshotHistory-jogWGLB-.js → SnapshotHistory-VyL4tJwn.js} +26 -26
  74. package/dist/cdn/chunks/{SnapshotHistory-jogWGLB-.js.map → SnapshotHistory-VyL4tJwn.js.map} +1 -1
  75. package/dist/cdn/chunks/{TemplateScoringPanel-B2XIOTl-.js → TemplateScoringPanel-NucRtAP0.js} +34 -34
  76. package/dist/cdn/chunks/{TemplateScoringPanel-B2XIOTl-.js.map → TemplateScoringPanel-NucRtAP0.js.map} +1 -1
  77. package/dist/cdn/chunks/{TestEmailModal-BcPjQygV.js → TestEmailModal-DRte11oT.js} +31 -31
  78. package/dist/cdn/chunks/{TestEmailModal-BcPjQygV.js.map → TestEmailModal-DRte11oT.js.map} +1 -1
  79. package/dist/cdn/chunks/{TestEmailPanel-1zxRa00s.js → TestEmailPanel-CpK5t4E3.js} +3 -3
  80. package/dist/cdn/chunks/{TestEmailPanel-1zxRa00s.js.map → TestEmailPanel-CpK5t4E3.js.map} +1 -1
  81. package/dist/cdn/chunks/{TitleEditor-DTrmublj.js → TitleEditor-EkDchueW.js} +35 -35
  82. package/dist/cdn/chunks/{TitleEditor-DTrmublj.js.map → TitleEditor-EkDchueW.js.map} +1 -1
  83. package/dist/cdn/chunks/{TplModal-By50gtwa.js → TplModal-BGLstO3F.js} +17 -17
  84. package/dist/cdn/chunks/{TplModal-By50gtwa.js.map → TplModal-BGLstO3F.js.map} +1 -1
  85. package/dist/cdn/chunks/{blockTypeIcons-BhFhHuFt.js → blockTypeIcons-FXlMM3PL.js} +2 -2
  86. package/dist/cdn/chunks/{blockTypeIcons-BhFhHuFt.js.map → blockTypeIcons-FXlMM3PL.js.map} +1 -1
  87. package/dist/cdn/chunks/{cloud-B0f7Ub8f.js → cloud-CNpvDuv7.js} +3 -3
  88. package/dist/cdn/chunks/{cloud-B0f7Ub8f.js.map → cloud-CNpvDuv7.js.map} +1 -1
  89. package/dist/cdn/chunks/{dist-H51neg3K.js → dist-B2HKGHnc.js} +3 -3
  90. package/dist/cdn/chunks/{dist-H51neg3K.js.map → dist-B2HKGHnc.js.map} +1 -1
  91. package/dist/cdn/chunks/{dist-B4VIlp1g.js → dist-C6z8AjBC.js} +2 -2
  92. package/dist/cdn/chunks/{dist-B4VIlp1g.js.map → dist-C6z8AjBC.js.map} +1 -1
  93. package/dist/cdn/chunks/{draggable-Z4XXmbPC.js → draggable-DCs9qL-b.js} +2 -2
  94. package/dist/cdn/chunks/{draggable-Z4XXmbPC.js.map → draggable-DCs9qL-b.js.map} +1 -1
  95. package/dist/cdn/chunks/{extensions-Dq0D79tq.js → extensions-CZAB08kD.js} +22 -22
  96. package/dist/cdn/chunks/{extensions-Dq0D79tq.js.map → extensions-CZAB08kD.js.map} +1 -1
  97. package/dist/cdn/chunks/{icons-C_kRN0_C.js → icons-CvYN6zrM.js} +8 -8
  98. package/dist/cdn/chunks/{icons-C_kRN0_C.js.map → icons-CvYN6zrM.js.map} +1 -1
  99. package/dist/cdn/chunks/{keys-DsoX52o_.js → keys-Cmc2Yl3D.js} +2 -2
  100. package/dist/cdn/chunks/{keys-DsoX52o_.js.map → keys-Cmc2Yl3D.js.map} +1 -1
  101. package/dist/cdn/chunks/{liquid.browser-DrGys_ek.js → liquid.browser-UlAOKBjI.js} +99 -91
  102. package/dist/cdn/chunks/liquid.browser-UlAOKBjI.js.map +1 -0
  103. package/dist/cdn/chunks/{src-CRvTVX4F.js → src-BRRRFqXr.js} +201 -201
  104. package/dist/cdn/chunks/{src-CRvTVX4F.js.map → src-BRRRFqXr.js.map} +1 -1
  105. package/dist/cdn/chunks/{src-Aea1Vl1H.js → src-COnW7gMq.js} +123 -123
  106. package/dist/cdn/chunks/src-COnW7gMq.js.map +1 -0
  107. package/dist/cdn/chunks/{src-CZjSXPYq.js → src-DsvVSm7Z.js} +221 -166
  108. package/dist/cdn/chunks/src-DsvVSm7Z.js.map +1 -0
  109. package/dist/cdn/chunks/{src-_GNJgPcS.js → src-DzH5U9Vm.js} +79 -79
  110. package/dist/cdn/chunks/{src-_GNJgPcS.js.map → src-DzH5U9Vm.js.map} +1 -1
  111. package/dist/cdn/chunks/{styles-znpPfrFd.js → styles-DEU_sn3k.js} +935 -917
  112. package/dist/cdn/chunks/styles-DEU_sn3k.js.map +1 -0
  113. package/dist/cdn/chunks/{tiptap-C5vzWlHv.js → tiptap-C44S1Cmh.js} +3480 -2806
  114. package/dist/cdn/chunks/tiptap-C44S1Cmh.js.map +1 -0
  115. package/dist/cdn/chunks/{useAliveFlag-4IDYQRNu.js → useAliveFlag-Dxwgo6P4.js} +2 -2
  116. package/dist/cdn/chunks/{useAliveFlag-4IDYQRNu.js.map → useAliveFlag-Dxwgo6P4.js.map} +1 -1
  117. package/dist/cdn/chunks/{useCloudI18n-D4JpHTPk.js → useCloudI18n-8wkJtuJD.js} +3 -3
  118. package/dist/cdn/chunks/{useCloudI18n-D4JpHTPk.js.map → useCloudI18n-8wkJtuJD.js.map} +1 -1
  119. package/dist/cdn/chunks/{useEditorCore-BMXBmdd8.js → useEditorCore-fyFmWS3D.js} +297 -297
  120. package/dist/cdn/chunks/useEditorCore-fyFmWS3D.js.map +1 -0
  121. package/dist/cdn/chunks/{useI18n-BvcEYzrI.js → useI18n-UMs0F71x.js} +3 -3
  122. package/dist/cdn/chunks/{useI18n-BvcEYzrI.js.map → useI18n-UMs0F71x.js.map} +1 -1
  123. package/dist/cdn/chunks/{useMergeTag-BSdxMUzg.js → useMergeTag-DjQoCGEz.js} +4 -4
  124. package/dist/cdn/chunks/{useMergeTag-BSdxMUzg.js.map → useMergeTag-DjQoCGEz.js.map} +1 -1
  125. package/dist/cdn/chunks/{usePopoverPosition-ig-71caO.js → usePopoverPosition-cf8Y-ynK.js} +3 -3
  126. package/dist/cdn/chunks/{usePopoverPosition-ig-71caO.js.map → usePopoverPosition-cf8Y-ynK.js.map} +1 -1
  127. package/dist/cdn/editor.js +47 -47
  128. package/dist/cdn/editor.js.map +1 -1
  129. package/dist/{check-COV27dGb.js → check-On4TSac-.js} +1 -1
  130. package/dist/{chevron-down-vsU88vcr.js → chevron-down-69EiBGoB.js} +1 -1
  131. package/dist/{chevron-up-RrZ0Rjn9.js → chevron-up-Dh3MG1Dw.js} +1 -1
  132. package/dist/{circle-alert-B6GlHmmi.js → circle-alert-cilwzafX.js} +1 -1
  133. package/dist/{clock-egOt8zjQ.js → clock-Dt0APH92.js} +1 -1
  134. package/dist/{cloud-D-2StbvU.js → cloud-4SuOLNTK.js} +1 -1
  135. package/dist/{createLucideIcon-D6cqT5Pm.js → createLucideIcon-C8WzBYCv.js} +2 -2
  136. package/dist/dist-6YJAWMuf.js +5 -0
  137. package/dist/dist-8vlm9kfO.js +5 -0
  138. package/dist/{dist-DHwnYYx0.js → dist-BImfm-46.js} +2 -2
  139. package/dist/{dist-CQ0fVBQ3.js → dist-BvYvG5SQ.js} +110 -57
  140. package/dist/{dist-DzzTB4eE.js → dist-C08jiemd.js} +7 -7
  141. package/dist/{dist-CqV4XslQ.js → dist-C27SeFL5.js} +15 -15
  142. package/dist/{dist-MwT7T6Xp.js → dist-CYx-E82k.js} +2 -2
  143. package/dist/{dist-CHxPjcxA.js → dist-ChYLhoJ4.js} +2143 -1583
  144. package/dist/{dist-UkG5ZJ1P.js → dist-Cl8J0IES.js} +258 -172
  145. package/dist/{dist-D4GoAr2g.js → dist-DMJRSouD.js} +464 -436
  146. package/dist/{dist-GUZZpDK3.js → dist-DfpeSdmE.js} +2 -2
  147. package/dist/{dist-Du95Y9M3.js → dist-M7m1lYRe.js} +47 -47
  148. package/dist/{dist-vpuiQ7_Q.js → dist-g6cbzhZW.js} +2 -2
  149. package/dist/{extensions-y6KjLr9t.js → extensions-Dz5jj0wf.js} +16 -16
  150. package/dist/{image-up-CycES-MQ.js → image-up-Ceggh_R3.js} +1 -1
  151. package/dist/{info-BUdvm046.js → info-DO5odBcZ.js} +1 -1
  152. package/dist/{liquid.browser-Di5zMIEx.js → liquid.browser-B-rGrnrQ.js} +98 -90
  153. package/dist/{list-checks-BAeuuATD.js → list-checks-BSkPKbuI.js} +1 -1
  154. package/dist/{loader-circle-L5yuAx_j.js → loader-circle-bO7o7_HD.js} +1 -1
  155. package/dist/{message-circle-DRdaapVc.js → message-circle-BEkAk65X.js} +1 -1
  156. package/dist/{pencil-BfErVPf_.js → pencil-t6m0EtKL.js} +1 -1
  157. package/dist/{refresh-cw-D0PYatER.js → refresh-cw-CkOYVzK5.js} +1 -1
  158. package/dist/{scan-line-Byi3fJcr.js → scan-line-DwSVj25O.js} +1 -1
  159. package/dist/{send-DuyNexMY.js → send-CWsWN8PQ.js} +1 -1
  160. package/dist/{shield-check-BkkN_1qw.js → shield-check-qje8Kufw.js} +1 -1
  161. package/dist/{sparkles-DAw2sBXk.js → sparkles-DumaWRW-.js} +1 -1
  162. package/dist/{styles-BzwheHH_.js → styles-DbP2S8Z1.js} +446 -428
  163. package/dist/templatical-editor.js +9 -9
  164. package/dist/{text-align-start-Ba3xJKn6.js → text-align-start-Ir8Ah4mT.js} +1 -1
  165. package/dist/{trash-2-CapEBXBI.js → trash-2-CklAFCmO.js} +1 -1
  166. package/dist/{triangle-alert-52pdw8jI.js → triangle-alert-BBi4n93g.js} +1 -1
  167. package/dist/{upload-oAgigC31.js → upload-sVqqppuv.js} +1 -1
  168. package/dist/{useEditorCore-BhjEMSeE.js → useEditorCore-CbcmGpwp.js} +889 -889
  169. package/dist/{useMergeTag-DTSOQnyr.js → useMergeTag-B9xG9EJ7.js} +1 -1
  170. package/dist/{x-DvBgbDuf.js → x-Mby7KlhS.js} +1 -1
  171. package/package.json +23 -23
  172. package/dist/cdn/chunks/liquid.browser-DrGys_ek.js.map +0 -1
  173. package/dist/cdn/chunks/src-Aea1Vl1H.js.map +0 -1
  174. package/dist/cdn/chunks/src-CZjSXPYq.js.map +0 -1
  175. package/dist/cdn/chunks/styles-znpPfrFd.js.map +0 -1
  176. package/dist/cdn/chunks/tiptap-C5vzWlHv.js.map +0 -1
  177. package/dist/cdn/chunks/useEditorCore-BMXBmdd8.js.map +0 -1
  178. package/dist/dist-B56SufAv.js +0 -5
  179. package/dist/dist-BQZkRg05.js +0 -5
@@ -1 +1 @@
1
- {"version":3,"file":"cloud-B0f7Ub8f.js","names":[],"sources":["../../../../core/src/cloud/auth.ts","../../../../core/src/cloud/url-builder.ts","../../../../core/src/cloud/api.ts","../../../../core/src/cloud/websocket-client.ts","../../../../core/src/cloud/mcp-operation-handler.ts","../../../../core/src/cloud/editor.ts","../../../../core/src/cloud/ai-chat.ts","../../../../core/src/cloud/ai-config.ts","../../../../core/src/cloud/template-scoring.ts","../../../../core/src/cloud/design-reference.ts","../../../../core/src/cloud/comments.ts","../../../../core/src/cloud/comment-listener.ts","../../../../core/src/cloud/collaboration.ts","../../../../core/src/cloud/collaboration-broadcast.ts","../../../../core/src/cloud/web-socket.ts","../../../../core/src/cloud/saved-blocks-provider.ts","../../../../core/src/cloud/snapshots.ts","../../../../core/src/cloud/test-email.ts","../../../../core/src/cloud/test-email-provider.ts","../../../../core/src/cloud/export.ts","../../../../core/src/cloud/plan-config.ts","../../../../core/src/cloud/health-check.ts","../../../../core/src/cloud/mcp-listener.ts"],"sourcesContent":["import type {\n AuthConfig,\n AuthRequestOptions,\n SdkAuthConfig,\n TestEmailConfig,\n TokenData,\n UserConfig,\n} from \"@templatical/types\";\nimport { SdkError } from \"@templatical/types\";\n\nexport type {\n AuthConfig,\n AuthRequestOptions,\n SdkAuthConfig,\n TestEmailConfig,\n UserConfig,\n};\n\nexport class AuthManager {\n private static readonly DEFAULT_BASE_URL = \"https://templatical.com\";\n\n private accessToken: string | null = null;\n private expiresAt: Date | null = null;\n private _projectId: string | null = null;\n private _tenantId: string | null = null;\n private _tenantSlug: string | null = null;\n private _testEmailConfig: TestEmailConfig | null = null;\n private _userConfig: UserConfig | null = null;\n private readonly url: string;\n private readonly baseUrl: string;\n private readonly requestOptions: AuthRequestOptions;\n private readonly onError?: (error: Error) => void;\n private refreshPromise: Promise<string> | null = null;\n\n private static readonly REFRESH_THRESHOLD_MS = 60 * 1000;\n\n constructor(config: AuthConfig) {\n this.url = config.url;\n this.baseUrl = (config.baseUrl ?? AuthManager.DEFAULT_BASE_URL).replace(\n /\\/$/,\n \"\",\n );\n this.requestOptions = config.requestOptions ?? {};\n this.onError = config.onError;\n }\n\n resolveUrl(path: string): string {\n if (path.startsWith(\"http://\") || path.startsWith(\"https://\")) {\n return path;\n }\n\n const normalizedPath = path.startsWith(\"/\") ? path : `/${path}`;\n return `${this.baseUrl}${normalizedPath}`;\n }\n\n get projectId(): string {\n if (!this._projectId) {\n throw new Error(\"Project ID not available. Call initialize() first.\");\n }\n return this._projectId;\n }\n\n get tenantId(): string {\n if (!this._tenantId) {\n throw new Error(\"Tenant ID not available. Call initialize() first.\");\n }\n return this._tenantId;\n }\n\n get tenantSlug(): string {\n if (!this._tenantSlug) {\n throw new Error(\"Tenant slug not available. Call initialize() first.\");\n }\n return this._tenantSlug;\n }\n\n get testEmailConfig(): TestEmailConfig | null {\n return this._testEmailConfig;\n }\n\n get userConfig(): UserConfig | null {\n return this._userConfig;\n }\n\n get accessTokenValue(): string | null {\n return this.accessToken;\n }\n\n async initialize(): Promise<void> {\n await this.ensureToken();\n }\n\n private async ensureToken(): Promise<string> {\n if (this.accessToken && !this.isTokenExpiringSoon()) {\n return this.accessToken;\n }\n return this.refreshToken();\n }\n\n private isTokenExpiringSoon(): boolean {\n if (!this.expiresAt) {\n return true;\n }\n const timeUntilExpiry = this.expiresAt.getTime() - Date.now();\n return timeUntilExpiry < AuthManager.REFRESH_THRESHOLD_MS;\n }\n\n async refreshToken(): Promise<string> {\n if (this.refreshPromise) {\n return this.refreshPromise;\n }\n\n this.refreshPromise = this.performRefresh();\n\n try {\n const token = await this.refreshPromise;\n return token;\n } finally {\n this.refreshPromise = null;\n }\n }\n\n private async performRefresh(): Promise<string> {\n try {\n const method = this.requestOptions.method ?? \"POST\";\n const headers: Record<string, string> = {\n Accept: \"application/json\",\n ...this.requestOptions.headers,\n };\n\n const fetchOptions: RequestInit = {\n method,\n headers,\n credentials: this.requestOptions.credentials ?? \"include\",\n };\n\n if (method === \"POST\" && this.requestOptions.body) {\n headers[\"Content-Type\"] = \"application/json\";\n fetchOptions.body = JSON.stringify(this.requestOptions.body);\n }\n\n const response = await fetch(this.url, fetchOptions);\n\n if (!response.ok) {\n throw new SdkError(\n `Token refresh failed: ${response.status}`,\n response.status,\n );\n }\n\n const data: TokenData = await response.json();\n\n if (!data.token || !data.expires_at || !data.project_id || !data.tenant) {\n throw new Error(\n \"Invalid token response: missing token, expires_at, project_id, or tenant\",\n );\n }\n\n this.accessToken = data.token;\n this.expiresAt = new Date(data.expires_at * 1000);\n this._projectId = data.project_id;\n this._tenantSlug = data.tenant;\n\n if (data.test_email?.allowed_emails && data.test_email?.signature) {\n this._testEmailConfig = {\n allowedEmails: data.test_email.allowed_emails,\n signature: data.test_email.signature,\n };\n } else {\n this._testEmailConfig = null;\n }\n\n if (data.user?.id && data.user?.name && data.user?.signature) {\n this._userConfig = {\n id: data.user.id,\n name: data.user.name,\n signature: data.user.signature,\n };\n } else {\n this._userConfig = null;\n }\n\n return this.accessToken;\n } catch (error) {\n const wrappedError =\n error instanceof Error\n ? error\n : new Error(\"Token refresh failed\", { cause: error });\n this.onError?.(wrappedError);\n throw wrappedError;\n }\n }\n\n async authenticatedFetch(\n url: string,\n options: RequestInit = {},\n ): Promise<Response> {\n const token = await this.ensureToken();\n const resolvedUrl = this.resolveUrl(url);\n\n const makeRequest = async (authToken: string): Promise<Response> => {\n return fetch(resolvedUrl, {\n ...options,\n headers: {\n ...options.headers,\n Authorization: `Bearer ${authToken}`,\n },\n });\n };\n\n let response = await makeRequest(token);\n\n if (response.status === 401) {\n const newToken = await this.refreshToken();\n response = await makeRequest(newToken);\n }\n\n return response;\n }\n}\n\nexport function createSdkAuthManager(\n config: SdkAuthConfig,\n onError?: (error: Error) => void,\n): AuthManager {\n if (config.mode === \"direct\") {\n const baseUrl = (config.baseUrl ?? \"https://templatical.com\").replace(\n /\\/$/,\n \"\",\n );\n\n return new AuthManager({\n url: `${baseUrl}/api/v1/auth/token`,\n baseUrl: config.baseUrl,\n requestOptions: {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: {\n client_id: config.clientId,\n client_secret: config.clientSecret,\n tenant: config.tenant,\n client_type: \"sdk\",\n },\n },\n onError,\n });\n }\n\n return new AuthManager({\n url: config.url,\n baseUrl: config.baseUrl,\n requestOptions: config.requestOptions,\n onError,\n });\n}\n","export function buildUrl(\n template: string,\n params: Record<string, string>,\n): string {\n return template.replace(/\\{(\\w+)\\}/g, (_, key: string) =>\n encodeURIComponent(params[key] ?? \"\"),\n );\n}\n\nconst BASE = \"/api/v1/projects/{project}/tenants/{tenant}\";\nconst TEMPLATE = `${BASE}/templates/{template}`;\nconst AI = `${TEMPLATE}/ai`;\nconst MEDIA = `${BASE}/media`;\nconst FOLDERS = `${MEDIA}/folders`;\nconst MODULES = `${BASE}/saved-modules`;\n\nexport const API_ROUTES = {\n health: \"/api/v1/health\",\n \"projects.config\": `${BASE}/config`,\n \"broadcasting.auth\": `${BASE}/broadcasting/auth`,\n \"templates.store\": `${BASE}/templates`,\n \"templates.show\": `${TEMPLATE}`,\n \"templates.update\": `${TEMPLATE}`,\n \"templates.destroy\": `${TEMPLATE}`,\n \"templates.export\": `${TEMPLATE}/export`,\n \"templates.importFromBeefree\": `${BASE}/templates/import/from-beefree`,\n \"templates.sendTestEmail\": `${TEMPLATE}/send-test-email`,\n \"snapshots.index\": `${TEMPLATE}/snapshots`,\n \"snapshots.store\": `${TEMPLATE}/snapshots`,\n \"snapshots.show\": `${TEMPLATE}/snapshots/{snapshot}`,\n \"snapshots.restore\": `${TEMPLATE}/snapshots/{snapshot}/restore`,\n \"comments.index\": `${TEMPLATE}/comments`,\n \"comments.store\": `${TEMPLATE}/comments`,\n \"comments.update\": `${TEMPLATE}/comments/{comment}`,\n \"comments.destroy\": `${TEMPLATE}/comments/{comment}`,\n \"comments.resolve\": `${TEMPLATE}/comments/{comment}/resolve`,\n \"ai.generate\": `${AI}/generate`,\n \"ai.conversationMessages\": `${AI}/conversation-messages`,\n \"ai.suggestions\": `${AI}/suggestions`,\n \"ai.rewriteText\": `${AI}/rewrite-text`,\n \"ai.score\": `${AI}/score`,\n \"ai.fixFinding\": `${AI}/fix-finding`,\n \"ai.generateFromDesign\": `${AI}/generate-from-design`,\n \"media.upload\": `${MEDIA}/upload`,\n \"media.browse\": `${MEDIA}/browse`,\n \"media.delete\": `${MEDIA}/delete`,\n \"media.move\": `${MEDIA}/move`,\n \"media.update\": `${MEDIA}/{media}`,\n \"media.replace\": `${MEDIA}/{media}/replace`,\n \"media.checkUsage\": `${MEDIA}/check-usage`,\n \"media.frequentlyUsed\": `${MEDIA}/frequently-used`,\n \"media.importFromUrl\": `${MEDIA}/import-from-url`,\n \"folders.index\": `${FOLDERS}`,\n \"folders.store\": `${FOLDERS}`,\n \"folders.update\": `${FOLDERS}/{mediaFolder}`,\n \"folders.destroy\": `${FOLDERS}/{mediaFolder}`,\n \"savedModules.index\": `${MODULES}`,\n \"savedModules.store\": `${MODULES}`,\n \"savedModules.update\": `${MODULES}/{savedModule}`,\n \"savedModules.destroy\": `${MODULES}/{savedModule}`,\n} as const;\n","import type {\n ApiError,\n ApiResponse,\n Comment,\n CustomFont,\n PlanConfig,\n SavedBlock,\n Template,\n TemplateContent,\n TemplateSnapshot,\n} from \"@templatical/types\";\nimport { SdkError } from \"@templatical/types\";\nimport type { Block } from \"@templatical/types\";\nimport type { AuthManager } from \"./auth\";\nimport { API_ROUTES, buildUrl } from \"./url-builder\";\n\nexport class ApiClient {\n constructor(private readonly authManager: AuthManager) {}\n\n private get projectId(): string {\n return this.authManager.projectId;\n }\n\n private get tenantSlug(): string {\n return this.authManager.tenantSlug;\n }\n\n private get baseParams(): Record<string, string> {\n return { project: this.projectId, tenant: this.tenantSlug };\n }\n\n private async request<T>(\n path: string,\n options: RequestInit = {},\n ): Promise<T> {\n const response = await this.authManager.authenticatedFetch(path, {\n ...options,\n headers: {\n \"Content-Type\": \"application/json\",\n Accept: \"application/json\",\n ...options.headers,\n },\n });\n\n if (!response.ok) {\n const error: ApiError = await response.json().catch(() => ({\n message: `HTTP error ${response.status}`,\n }));\n\n const errorMessage = this.extractFirstValidationError(error);\n throw new SdkError(errorMessage, response.status);\n }\n\n if (response.status === 204) {\n return undefined as T;\n }\n\n const json: ApiResponse<T> = await response.json();\n return json.data;\n }\n\n private extractFirstValidationError(error: ApiError): string {\n if (error.errors) {\n const firstField = Object.keys(error.errors)[0];\n if (firstField && error.errors[firstField]?.length > 0) {\n return error.errors[firstField][0];\n }\n }\n return error.message;\n }\n\n async createTemplate(content: TemplateContent): Promise<Template> {\n return this.request<Template>(\n buildUrl(API_ROUTES[\"templates.store\"], this.baseParams),\n {\n method: \"POST\",\n body: JSON.stringify({ content }),\n },\n );\n }\n\n async getTemplate(id: string): Promise<Template> {\n return this.request<Template>(\n buildUrl(API_ROUTES[\"templates.show\"], {\n ...this.baseParams,\n template: id,\n }),\n );\n }\n\n async updateTemplate(\n id: string,\n content: TemplateContent,\n ): Promise<Template> {\n return this.request<Template>(\n buildUrl(API_ROUTES[\"templates.update\"], {\n ...this.baseParams,\n template: id,\n }),\n {\n method: \"PUT\",\n body: JSON.stringify({ content }),\n },\n );\n }\n\n async createSnapshot(\n templateId: string,\n content: TemplateContent,\n ): Promise<TemplateSnapshot> {\n return this.request<TemplateSnapshot>(\n buildUrl(API_ROUTES[\"snapshots.store\"], {\n ...this.baseParams,\n template: templateId,\n }),\n {\n method: \"POST\",\n body: JSON.stringify({ content }),\n },\n );\n }\n\n async deleteTemplate(id: string): Promise<void> {\n return this.request<void>(\n buildUrl(API_ROUTES[\"templates.destroy\"], {\n ...this.baseParams,\n template: id,\n }),\n {\n method: \"DELETE\",\n },\n );\n }\n\n async getSnapshots(templateId: string): Promise<TemplateSnapshot[]> {\n return this.request<TemplateSnapshot[]>(\n buildUrl(API_ROUTES[\"snapshots.index\"], {\n ...this.baseParams,\n template: templateId,\n }),\n );\n }\n\n async restoreSnapshot(\n templateId: string,\n snapshotId: string,\n ): Promise<Template> {\n return this.request<Template>(\n buildUrl(API_ROUTES[\"snapshots.restore\"], {\n ...this.baseParams,\n template: templateId,\n snapshot: snapshotId,\n }),\n {\n method: \"POST\",\n },\n );\n }\n\n async exportTemplate(\n templateId: string,\n fontsPayload?: {\n customFonts: CustomFont[];\n defaultFallback: string;\n },\n ): Promise<{ html: string; mjml: string }> {\n const body = fontsPayload\n ? JSON.stringify({\n custom_fonts: fontsPayload.customFonts,\n default_fallback: fontsPayload.defaultFallback,\n })\n : undefined;\n\n return this.request<{ html: string; mjml: string }>(\n buildUrl(API_ROUTES[\"templates.export\"], {\n ...this.baseParams,\n template: templateId,\n }),\n {\n method: \"POST\",\n body,\n },\n );\n }\n\n async sendTestEmail(\n templateId: string,\n payload: {\n recipient: string;\n html: string;\n allowed_emails: string[];\n signature: string;\n },\n ): Promise<void> {\n await this.request<void>(\n buildUrl(API_ROUTES[\"templates.sendTestEmail\"], {\n ...this.baseParams,\n template: templateId,\n }),\n {\n method: \"POST\",\n body: JSON.stringify(payload),\n },\n );\n }\n\n private commentsUrl(templateId: string, commentId?: string): string {\n if (commentId) {\n return buildUrl(API_ROUTES[\"comments.update\"], {\n ...this.baseParams,\n template: templateId,\n comment: commentId,\n });\n }\n return buildUrl(API_ROUTES[\"comments.index\"], {\n ...this.baseParams,\n template: templateId,\n });\n }\n\n async getComments(templateId: string): Promise<Comment[]> {\n return this.request<Comment[]>(this.commentsUrl(templateId));\n }\n\n async createComment(\n templateId: string,\n data: {\n body: string;\n block_id?: string;\n parent_id?: string;\n user_id: string;\n user_name: string;\n user_signature: string;\n },\n headers?: Record<string, string>,\n ): Promise<Comment> {\n return this.request<Comment>(this.commentsUrl(templateId), {\n method: \"POST\",\n body: JSON.stringify(data),\n headers,\n });\n }\n\n async updateComment(\n templateId: string,\n commentId: string,\n data: {\n body: string;\n user_id: string;\n user_name: string;\n user_signature: string;\n },\n headers?: Record<string, string>,\n ): Promise<Comment> {\n return this.request<Comment>(this.commentsUrl(templateId, commentId), {\n method: \"PUT\",\n body: JSON.stringify(data),\n headers,\n });\n }\n\n async deleteComment(\n templateId: string,\n commentId: string,\n data: {\n user_id: string;\n user_name: string;\n user_signature: string;\n },\n headers?: Record<string, string>,\n ): Promise<void> {\n return this.request<void>(this.commentsUrl(templateId, commentId), {\n method: \"DELETE\",\n body: JSON.stringify(data),\n headers,\n });\n }\n\n async resolveComment(\n templateId: string,\n commentId: string,\n data: {\n user_id: string;\n user_name: string;\n user_signature: string;\n },\n headers?: Record<string, string>,\n ): Promise<Comment> {\n return this.request<Comment>(\n buildUrl(API_ROUTES[\"comments.resolve\"], {\n ...this.baseParams,\n template: templateId,\n comment: commentId,\n }),\n {\n method: \"POST\",\n body: JSON.stringify(data),\n headers,\n },\n );\n }\n\n async fetchConfig(): Promise<PlanConfig> {\n return this.request<PlanConfig>(\n buildUrl(API_ROUTES[\"projects.config\"], this.baseParams),\n );\n }\n\n async listModules(search?: string, category?: string): Promise<SavedBlock[]> {\n const url = buildUrl(API_ROUTES[\"savedModules.index\"], this.baseParams);\n const params = new URLSearchParams();\n if (search) params.set(\"search\", search);\n if (category) params.set(\"category\", category);\n const query = params.size > 0 ? `?${params}` : \"\";\n return this.request<SavedBlock[]>(`${url}${query}`);\n }\n\n async createModule(data: {\n name: string;\n content: Block[];\n category?: string;\n }): Promise<SavedBlock> {\n return this.request<SavedBlock>(\n buildUrl(API_ROUTES[\"savedModules.store\"], this.baseParams),\n {\n method: \"POST\",\n body: JSON.stringify(data),\n },\n );\n }\n\n async updateModule(\n id: string,\n data: Partial<{ name: string; content: Block[]; category: string }>,\n ): Promise<SavedBlock> {\n return this.request<SavedBlock>(\n buildUrl(API_ROUTES[\"savedModules.update\"], {\n ...this.baseParams,\n savedModule: id,\n }),\n {\n method: \"PUT\",\n body: JSON.stringify(data),\n },\n );\n }\n\n async deleteModule(id: string): Promise<void> {\n return this.request<void>(\n buildUrl(API_ROUTES[\"savedModules.destroy\"], {\n ...this.baseParams,\n savedModule: id,\n }),\n {\n method: \"DELETE\",\n },\n );\n }\n}\n","import type { WebSocketServerConfig } from \"@templatical/types\";\nimport type { AuthManager } from \"./auth\";\nimport { API_ROUTES, buildUrl } from \"./url-builder\";\nimport type Pusher from \"pusher-js\";\nimport type { Channel, PresenceChannel } from \"pusher-js\";\n\ntype PusherType = Pusher;\n\nexport interface WebSocketConfig {\n host: string;\n port: number;\n appKey: string;\n}\n\nexport function resolveWebSocketConfig(\n serverConfig: WebSocketServerConfig,\n): WebSocketConfig {\n return {\n host: serverConfig.host,\n port: serverConfig.port,\n appKey: serverConfig.app_key,\n };\n}\n\nexport interface PresenceMember {\n id: string;\n name: string;\n type: \"user\" | \"mcp\";\n}\n\nexport interface WebSocketClientOptions {\n authManager: AuthManager;\n config: WebSocketConfig;\n onError?: (error: Error) => void;\n}\n\nexport class WebSocketClient {\n private pusher: PusherType | null = null;\n private readonly authManager: AuthManager;\n private readonly config: WebSocketConfig;\n private readonly onError?: (error: Error) => void;\n\n constructor(options: WebSocketClientOptions) {\n this.authManager = options.authManager;\n this.config = options.config;\n this.onError = options.onError;\n }\n\n async connect(): Promise<void> {\n if (this.pusher) {\n return;\n }\n\n let Pusher: typeof import(\"pusher-js\").default;\n try {\n ({ default: Pusher } = await import(\"pusher-js\"));\n } catch {\n throw new Error(\n \"Cloud features require the optional peer dependency 'pusher-js'. Install it with: npm install pusher-js\",\n );\n }\n\n const { host, port, appKey } = this.config;\n const authEndpoint = this.authManager.resolveUrl(\n buildUrl(API_ROUTES[\"broadcasting.auth\"], {\n project: this.authManager.projectId,\n tenant: this.authManager.tenantSlug,\n }),\n );\n\n this.pusher = new Pusher(appKey, {\n wsHost: host,\n wsPort: port,\n wssPort: port,\n forceTLS: true,\n disableStats: true,\n enabledTransports: [\"ws\", \"wss\"],\n cluster: \"\",\n channelAuthorization: {\n transport: \"ajax\",\n endpoint: authEndpoint,\n headers: {\n Authorization: `Bearer ${this.authManager.accessTokenValue}`,\n Accept: \"application/json\",\n },\n params: {\n user_id: this.authManager.userConfig?.id ?? \"\",\n user_name: this.authManager.userConfig?.name ?? \"\",\n user_signature: this.authManager.userConfig?.signature ?? \"\",\n },\n },\n });\n\n this.pusher.connection.bind(\"error\", (error: unknown) => {\n this.onError?.(\n error instanceof Error\n ? error\n : new Error(\"WebSocket connection error\"),\n );\n });\n }\n\n subscribePresence(channelName: string): PresenceChannel {\n if (!this.pusher) {\n throw new Error(\"WebSocketClient not connected. Call connect() first.\");\n }\n\n return this.pusher.subscribe(channelName) as PresenceChannel;\n }\n\n unsubscribe(channelName: string): void {\n this.pusher?.unsubscribe(channelName);\n }\n\n getChannel(channelName: string): Channel | undefined {\n return this.pusher?.channel(channelName);\n }\n\n disconnect(): void {\n if (this.pusher) {\n this.pusher.disconnect();\n this.pusher = null;\n }\n }\n\n getSocketId(): string | null {\n return this.pusher?.connection.socket_id ?? null;\n }\n\n get isConnected(): boolean {\n return this.pusher?.connection.state === \"connected\";\n }\n}\n","import type { McpOperationPayload } from \"@templatical/types\";\nimport type {\n Block,\n TemplateContent,\n TemplateSettings,\n} from \"@templatical/types\";\nimport type { UseEditorReturn } from \"./editor\";\n\nexport function handleOperation(\n editor: UseEditorReturn,\n payload: McpOperationPayload,\n): void {\n const { operation, data } = payload;\n\n switch (operation) {\n case \"add_block\":\n editor.addBlock(\n data.block as Block,\n data.section_id as string | undefined,\n data.column_index as number | undefined,\n data.index as number | undefined,\n );\n break;\n\n case \"update_block\":\n editor.updateBlock(\n data.block_id as string,\n data.updates as Partial<Block>,\n );\n break;\n\n case \"delete_block\":\n editor.removeBlock(data.block_id as string);\n break;\n\n case \"move_block\":\n editor.moveBlock(\n data.block_id as string,\n data.index as number,\n data.section_id as string | undefined,\n data.column_index as number | undefined,\n );\n break;\n\n case \"update_settings\":\n editor.updateSettings(data.updates as Partial<TemplateSettings>);\n break;\n\n case \"set_content\":\n editor.setContent(data.content as TemplateContent);\n break;\n\n case \"update_block_style\":\n editor.updateBlock(\n data.block_id as string,\n {\n styles: data.styles,\n } as Partial<Block>,\n );\n break;\n }\n}\n","import type {\n EditorState,\n Template,\n TemplateDefaults,\n UiTheme,\n ViewportSize,\n} from \"@templatical/types\";\nimport { SdkError } from \"@templatical/types\";\nimport { ApiClient } from \"./api\";\nimport type { AuthManager } from \"./auth\";\nimport type {\n Block,\n ColumnLayout,\n TemplateContent,\n TemplateSettings,\n} from \"@templatical/types\";\nimport { createDefaultTemplateContent } from \"@templatical/types\";\nimport { computed, reactive, readonly, type DeepReadonly, type Ref } from \"vue\";\n\nfunction getColumnCount(layout: ColumnLayout): number {\n if (layout === \"1\") return 1;\n if (layout === \"3\") return 3;\n return 2;\n}\n\nexport interface UseEditorOptions {\n authManager: AuthManager;\n defaultFontFamily?: string;\n templateDefaults?: TemplateDefaults;\n onError?: (error: Error) => void;\n lockedBlocks?: Ref<Map<string, unknown>>;\n}\n\nexport interface UseEditorReturn {\n state: DeepReadonly<EditorState>;\n content: Ref<TemplateContent>;\n selectedBlock: Ref<Block | null>;\n setContent: (content: TemplateContent, markDirty?: boolean) => void;\n selectBlock: (blockId: string | null) => void;\n setViewport: (viewport: ViewportSize) => void;\n setDarkMode: (darkMode: boolean) => void;\n setPreviewMode: (previewMode: boolean) => void;\n setUiTheme: (theme: UiTheme) => void;\n updateBlock: (blockId: string, updates: Partial<Block>) => void;\n updateSettings: (updates: Partial<TemplateSettings>) => void;\n addBlock: (\n block: Block,\n targetSectionId?: string,\n columnIndex?: number,\n index?: number,\n ) => void;\n removeBlock: (blockId: string) => void;\n moveBlock: (\n blockId: string,\n newIndex: number,\n targetSectionId?: string,\n columnIndex?: number,\n ) => void;\n savedBlockIds: Ref<Set<string>>;\n isBlockLocked: (blockId: string) => boolean;\n findBlockLocation: (blockId: string) => {\n targetSectionId?: string;\n columnIndex?: number;\n index: number;\n } | null;\n create: (content?: TemplateContent) => Promise<Template>;\n load: (templateId: string) => Promise<Template>;\n save: () => Promise<Template>;\n createSnapshot: () => Promise<void>;\n hasTemplate: () => boolean;\n markDirty: () => void;\n}\n\nexport function useEditor(options: UseEditorOptions): UseEditorReturn {\n const api = new ApiClient(options.authManager);\n\n const state = reactive<EditorState>({\n template: null,\n content: createDefaultTemplateContent(\n options.defaultFontFamily,\n options.templateDefaults,\n ),\n selectedBlockId: null,\n viewport: \"desktop\",\n darkMode: false,\n previewMode: false,\n isDirty: false,\n isSaving: false,\n isLoading: false,\n uiTheme: \"auto\",\n });\n\n const content = computed({\n get: () => state.content,\n set: (value: TemplateContent) => {\n state.content = value;\n state.isDirty = true;\n },\n });\n\n const selectedBlock = computed(() => {\n if (!state.selectedBlockId) return null;\n return findBlockById(state.content.blocks, state.selectedBlockId);\n });\n\n const savedBlockIds = computed<Set<string>>(() => {\n const ids = new Set<string>();\n const blocks = state.template?.content?.blocks;\n if (!blocks) {\n return ids;\n }\n for (const block of blocks) {\n ids.add(block.id);\n if (block.type === \"section\") {\n for (const column of block.children) {\n for (const child of column) {\n ids.add(child.id);\n }\n }\n }\n }\n return ids;\n });\n\n function findBlockById(blocks: Block[], id: string): Block | null {\n for (const block of blocks) {\n if (block.id === id) return block;\n if (block.type === \"section\") {\n for (const column of block.children) {\n const found = findBlockById(column, id);\n if (found) return found;\n }\n }\n }\n return null;\n }\n\n function findBlockParent(\n blocks: Block[],\n id: string,\n parent: {\n blocks: Block[];\n sectionId?: string;\n columnIndex?: number;\n } = { blocks },\n ): { blocks: Block[]; sectionId?: string; columnIndex?: number } | null {\n for (let i = 0; i < blocks.length; i++) {\n const block = blocks[i];\n if (block.id === id) return parent;\n if (block.type === \"section\") {\n for (let colIdx = 0; colIdx < block.children.length; colIdx++) {\n const result = findBlockParent(block.children[colIdx], id, {\n blocks: block.children[colIdx],\n sectionId: block.id,\n columnIndex: colIdx,\n });\n if (result) return result;\n }\n }\n }\n return null;\n }\n\n function isBlockLocked(blockId: string): boolean {\n return options.lockedBlocks?.value.has(blockId) ?? false;\n }\n\n function setContent(newContent: TemplateContent, markDirty = true): void {\n state.content = newContent;\n if (markDirty) {\n state.isDirty = true;\n }\n }\n\n function selectBlock(blockId: string | null): void {\n if (blockId && isBlockLocked(blockId)) {\n return;\n }\n state.selectedBlockId = blockId;\n }\n\n function setViewport(viewport: ViewportSize): void {\n state.viewport = viewport;\n }\n\n function setDarkMode(darkMode: boolean): void {\n state.darkMode = darkMode;\n }\n\n function setUiTheme(theme: UiTheme): void {\n state.uiTheme = theme;\n }\n\n function setPreviewMode(previewMode: boolean): void {\n state.previewMode = previewMode;\n if (previewMode) {\n state.selectedBlockId = null;\n }\n }\n\n function updateBlock(blockId: string, updates: Partial<Block>): void {\n if (isBlockLocked(blockId)) {\n return;\n }\n const block = findBlockById(state.content.blocks, blockId);\n if (block) {\n Object.assign(block, updates);\n state.isDirty = true;\n }\n }\n\n function updateSettings(updates: Partial<TemplateSettings>): void {\n state.content.settings = { ...state.content.settings, ...updates };\n state.isDirty = true;\n }\n\n function addBlock(\n block: Block,\n targetSectionId?: string,\n columnIndex = 0,\n index?: number,\n ): void {\n if (targetSectionId) {\n const section = findBlockById(state.content.blocks, targetSectionId);\n if (section && section.type === \"section\") {\n section.children[columnIndex] = section.children[columnIndex] || [];\n const targetArray = section.children[columnIndex];\n if (index !== undefined && index < targetArray.length) {\n targetArray.splice(index, 0, block);\n } else {\n targetArray.push(block);\n }\n }\n } else {\n if (index !== undefined && index < state.content.blocks.length) {\n state.content.blocks.splice(index, 0, block);\n } else {\n state.content.blocks.push(block);\n }\n }\n state.isDirty = true;\n }\n\n function removeBlock(blockId: string): void {\n if (isBlockLocked(blockId)) {\n return;\n }\n const parent = findBlockParent(state.content.blocks, blockId);\n if (parent) {\n const index = parent.blocks.findIndex((b) => b.id === blockId);\n if (index !== -1) {\n parent.blocks.splice(index, 1);\n if (state.selectedBlockId === blockId) {\n state.selectedBlockId = null;\n }\n state.isDirty = true;\n }\n }\n }\n\n function moveBlock(\n blockId: string,\n newIndex: number,\n targetSectionId?: string,\n columnIndex = 0,\n ): void {\n const parent = findBlockParent(state.content.blocks, blockId);\n if (!parent) return;\n\n const oldIndex = parent.blocks.findIndex((b) => b.id === blockId);\n if (oldIndex === -1) return;\n\n // Resolve target before mutating the source — otherwise an invalid\n // targetSectionId (stale/deleted id, non-section block, or out-of-range\n // columnIndex) leaves the block spliced-out and unrecoverable. Reachable\n // via untrusted remote move_block payloads (MCP/collaboration), which take\n // no history snapshot, so a dropped block can't even be undone.\n let targetArray: Block[];\n if (targetSectionId) {\n const section = findBlockById(state.content.blocks, targetSectionId);\n if (!section || section.type !== \"section\") return;\n if (columnIndex < 0 || columnIndex >= getColumnCount(section.columns)) {\n return;\n }\n section.children[columnIndex] = section.children[columnIndex] || [];\n targetArray = section.children[columnIndex];\n } else {\n targetArray = state.content.blocks;\n }\n\n const [block] = parent.blocks.splice(oldIndex, 1);\n targetArray.splice(newIndex, 0, block);\n\n state.isDirty = true;\n }\n\n async function create(content?: TemplateContent): Promise<Template> {\n state.isLoading = true;\n try {\n if (content) {\n state.content = content;\n }\n const template = await api.createTemplate(state.content);\n state.template = template;\n state.isDirty = false;\n return template;\n } catch (error) {\n options.onError?.(error as Error);\n throw error;\n } finally {\n state.isLoading = false;\n }\n }\n\n async function load(templateId: string): Promise<Template> {\n state.isLoading = true;\n try {\n const template = await api.getTemplate(templateId);\n state.template = template;\n state.content = template.content;\n state.isDirty = false;\n return template;\n } catch (error) {\n options.onError?.(error as Error);\n throw error;\n } finally {\n state.isLoading = false;\n }\n }\n\n async function save(): Promise<Template> {\n if (!state.template?.id) {\n throw new SdkError(\n \"No template loaded. Call create() or load() before saving.\",\n );\n }\n\n state.isSaving = true;\n try {\n const template = await api.updateTemplate(\n state.template.id,\n state.content,\n );\n state.template = template;\n state.isDirty = false;\n return template;\n } catch (error) {\n options.onError?.(error as Error);\n throw error;\n } finally {\n state.isSaving = false;\n }\n }\n\n async function createSnapshot(): Promise<void> {\n if (!state.template?.id) {\n return;\n }\n\n try {\n await api.createSnapshot(state.template.id, state.content);\n } catch (error) {\n options.onError?.(error as Error);\n throw error;\n }\n }\n\n function hasTemplate(): boolean {\n return state.template?.id !== undefined;\n }\n\n function markDirty(): void {\n state.isDirty = true;\n }\n\n function findBlockLocation(blockId: string): {\n targetSectionId?: string;\n columnIndex?: number;\n index: number;\n } | null {\n const parent = findBlockParent(state.content.blocks, blockId);\n if (!parent) return null;\n const index = parent.blocks.findIndex((b) => b.id === blockId);\n if (index === -1) return null;\n return {\n targetSectionId: parent.sectionId,\n columnIndex: parent.columnIndex,\n index,\n };\n }\n\n return {\n state: readonly(state),\n content,\n selectedBlock,\n savedBlockIds,\n isBlockLocked,\n findBlockLocation,\n setContent,\n selectBlock,\n setViewport,\n setDarkMode,\n setUiTheme,\n setPreviewMode,\n updateBlock,\n updateSettings,\n addBlock,\n removeBlock,\n moveBlock,\n create,\n load,\n save,\n createSnapshot,\n hasTemplate,\n markDirty,\n };\n}\n","import type { AiChatMessage } from \"@templatical/types\";\nimport type { AuthManager } from \"./auth\";\nimport { API_ROUTES, buildUrl } from \"./url-builder\";\nimport type { MergeTag, TemplateContent } from \"@templatical/types\";\nimport { ref } from \"vue\";\n\nexport interface UseAiChatOptions {\n authManager: AuthManager;\n getTemplateId: () => string | null;\n onApply?: (content: TemplateContent) => void;\n onError?: (error: Error) => void;\n}\n\nexport interface UseAiChatReturn {\n messages: ReturnType<typeof ref<AiChatMessage[]>>;\n isGenerating: ReturnType<typeof ref<boolean>>;\n isLoadingHistory: ReturnType<typeof ref<boolean>>;\n isLastChangeReverted: ReturnType<typeof ref<boolean>>;\n lastApplyMessageId: ReturnType<typeof ref<string | null>>;\n error: ReturnType<typeof ref<string | null>>;\n failedPrompt: ReturnType<typeof ref<string | null>>;\n suggestions: ReturnType<typeof ref<string[]>>;\n isLoadingSuggestions: ReturnType<typeof ref<boolean>>;\n sendPrompt: (\n prompt: string,\n currentContent: TemplateContent,\n mergeTags: MergeTag[],\n ) => Promise<TemplateContent | null>;\n toggleLastRevert: () => void;\n loadConversation: () => Promise<void>;\n loadSuggestions: (\n currentContent: TemplateContent,\n mergeTags: MergeTag[],\n ) => Promise<void>;\n clearChat: () => void;\n}\n\nlet messageIdCounter = 0;\n\nfunction generateMessageId(): string {\n return `msg_${Date.now()}_${++messageIdCounter}`;\n}\n\nexport function useAiChat(options: UseAiChatOptions): UseAiChatReturn {\n const { authManager, getTemplateId, onApply, onError } = options;\n\n const messages = ref<AiChatMessage[]>([]);\n const isGenerating = ref(false);\n const isLoadingHistory = ref(false);\n const error = ref<string | null>(null);\n const failedPrompt = ref<string | null>(null);\n const conversationId = ref<string | null>(null);\n const lastApplyMessageId = ref<string | null>(null);\n const lastPreviousContent = ref<TemplateContent | null>(null);\n const lastAppliedContent = ref<TemplateContent | null>(null);\n const isLastChangeReverted = ref(false);\n const suggestions = ref<string[]>([]);\n const isLoadingSuggestions = ref(false);\n\n function updateMessage(msgId: string, updates: Partial<AiChatMessage>): void {\n const idx = messages.value.findIndex((m) => m.id === msgId);\n if (idx === -1) {\n return;\n }\n\n const updated = { ...messages.value[idx], ...updates };\n messages.value = [\n ...messages.value.slice(0, idx),\n updated,\n ...messages.value.slice(idx + 1),\n ];\n }\n\n async function loadConversation(): Promise<void> {\n const templateId = getTemplateId();\n if (!templateId) {\n return;\n }\n\n isLoadingHistory.value = true;\n\n try {\n const url = buildUrl(API_ROUTES[\"ai.conversationMessages\"], {\n project: authManager.projectId,\n tenant: authManager.tenantSlug,\n template: templateId,\n });\n\n const response = await authManager.authenticatedFetch(url, {\n method: \"GET\",\n headers: {\n Accept: \"application/json\",\n },\n });\n\n if (!response.ok) {\n return;\n }\n\n const data = await response.json();\n\n if (data.conversation_id) {\n conversationId.value = data.conversation_id;\n }\n\n if (Array.isArray(data.data) && data.data.length > 0) {\n messages.value = data.data.map(\n (msg: {\n id: string;\n role: \"user\" | \"assistant\";\n content: string;\n created_at: string;\n }) => ({\n id: msg.id,\n role: msg.role,\n content: msg.content,\n timestamp: new Date(msg.created_at).getTime(),\n }),\n );\n }\n } catch {\n // Silently fail - chat will start fresh\n } finally {\n isLoadingHistory.value = false;\n }\n }\n\n async function loadSuggestions(\n currentContent: TemplateContent,\n mergeTags: MergeTag[],\n ): Promise<void> {\n const templateId = getTemplateId();\n if (!templateId) {\n return;\n }\n\n isLoadingSuggestions.value = true;\n\n try {\n const url = buildUrl(API_ROUTES[\"ai.suggestions\"], {\n project: authManager.projectId,\n tenant: authManager.tenantSlug,\n template: templateId,\n });\n\n const response = await authManager.authenticatedFetch(url, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Accept: \"text/event-stream\",\n },\n body: JSON.stringify({\n current_content: currentContent,\n merge_tags: mergeTags.map((p) => ({\n label: p.label,\n value: p.value,\n })),\n }),\n });\n\n if (!response.ok) {\n return;\n }\n\n const reader = response.body?.getReader();\n if (!reader) {\n return;\n }\n\n const decoder = new TextDecoder();\n let buffer = \"\";\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n\n buffer += decoder.decode(value, { stream: true });\n\n const lines = buffer.split(\"\\n\");\n buffer = lines.pop() ?? \"\";\n\n for (const line of lines) {\n if (!line.startsWith(\"data: \")) {\n continue;\n }\n\n let event;\n try {\n event = JSON.parse(line.slice(6));\n } catch {\n continue;\n }\n\n if (event.type === \"done\" && Array.isArray(event.suggestions)) {\n suggestions.value = event.suggestions.slice(0, 3);\n }\n }\n }\n } catch {\n // Silently fail - suggestions are non-critical\n } finally {\n isLoadingSuggestions.value = false;\n }\n }\n\n async function sendPrompt(\n prompt: string,\n currentContent: TemplateContent,\n mergeTags: MergeTag[],\n ): Promise<TemplateContent | null> {\n const templateId = getTemplateId();\n if (!templateId) {\n throw new Error(\"Template must be saved before using AI generation\");\n }\n\n isGenerating.value = true;\n error.value = null;\n failedPrompt.value = null;\n suggestions.value = [];\n\n const userMsgId = generateMessageId();\n messages.value = [\n ...messages.value,\n {\n id: userMsgId,\n role: \"user\",\n content: prompt,\n timestamp: Date.now(),\n },\n ];\n\n const assistantMsgId = generateMessageId();\n messages.value = [\n ...messages.value,\n {\n id: assistantMsgId,\n role: \"assistant\",\n content: \"\",\n timestamp: Date.now(),\n },\n ];\n\n try {\n const url = buildUrl(API_ROUTES[\"ai.generate\"], {\n project: authManager.projectId,\n tenant: authManager.tenantSlug,\n template: templateId,\n });\n\n const response = await authManager.authenticatedFetch(url, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Accept: \"text/event-stream\",\n },\n body: JSON.stringify({\n prompt,\n current_content: currentContent,\n merge_tags: mergeTags.map((p) => ({\n label: p.label,\n value: p.value,\n })),\n conversation_id: conversationId.value,\n }),\n });\n\n if (!response.ok) {\n const errorData = await response.json().catch(() => null);\n if (response.status === 403) {\n throw new Error(\"ai_generation_not_available\");\n }\n throw new Error(errorData?.message || \"Failed to generate template\");\n }\n\n const reader = response.body?.getReader();\n if (!reader) {\n throw new Error(\"Failed to read stream\");\n }\n\n const decoder = new TextDecoder();\n let buffer = \"\";\n let result: TemplateContent | null = null;\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n\n buffer += decoder.decode(value, { stream: true });\n\n const lines = buffer.split(\"\\n\");\n buffer = lines.pop() ?? \"\";\n\n for (const line of lines) {\n if (!line.startsWith(\"data: \")) {\n continue;\n }\n\n const jsonStr = line.slice(6);\n\n let event;\n try {\n event = JSON.parse(jsonStr);\n } catch {\n continue;\n }\n\n if (event.type === \"text\") {\n updateMessage(assistantMsgId, {\n content:\n (messages.value.find((m) => m.id === assistantMsgId)\n ?.content ?? \"\") + event.text,\n });\n } else if (event.type === \"error\") {\n throw new Error(event.message || \"Failed to generate template\");\n } else if (event.type === \"done\") {\n if (event.conversation_id) {\n conversationId.value = event.conversation_id;\n }\n\n updateMessage(assistantMsgId, {\n content: event.text,\n });\n\n result = event.content ?? null;\n\n if (result) {\n lastPreviousContent.value = currentContent;\n lastAppliedContent.value = result;\n lastApplyMessageId.value = assistantMsgId;\n isLastChangeReverted.value = false;\n onApply?.(result);\n } else {\n error.value = \"ai_apply_failed\";\n }\n }\n }\n }\n } finally {\n // Release the underlying network resource even on early exit.\n // Without this, throwing out of the loop (e.g. on an `error` SSE\n // event) leaves the socket and read buffer attached until GC.\n reader.cancel().catch(() => {});\n }\n\n return result;\n } catch (err) {\n const wrappedError =\n err instanceof Error\n ? err\n : new Error(\"Failed to generate template\", { cause: err });\n error.value = wrappedError.message;\n failedPrompt.value = prompt;\n onError?.(wrappedError);\n\n messages.value = messages.value.filter(\n (m) => m.id !== userMsgId && m.id !== assistantMsgId,\n );\n\n return null;\n } finally {\n isGenerating.value = false;\n }\n }\n\n function toggleLastRevert(): void {\n if (isLastChangeReverted.value) {\n if (lastAppliedContent.value) {\n onApply?.(lastAppliedContent.value);\n }\n isLastChangeReverted.value = false;\n } else {\n if (lastPreviousContent.value) {\n onApply?.(lastPreviousContent.value);\n }\n isLastChangeReverted.value = true;\n }\n }\n\n function clearChat(): void {\n messages.value = [];\n conversationId.value = null;\n error.value = null;\n lastApplyMessageId.value = null;\n lastPreviousContent.value = null;\n lastAppliedContent.value = null;\n isLastChangeReverted.value = false;\n }\n\n return {\n messages,\n isGenerating,\n isLoadingHistory,\n isLastChangeReverted,\n lastApplyMessageId,\n error,\n failedPrompt,\n suggestions,\n isLoadingSuggestions,\n sendPrompt,\n toggleLastRevert,\n loadConversation,\n loadSuggestions,\n clearChat,\n };\n}\n","import type { AiConfig } from \"@templatical/types\";\nimport { computed, type ComputedRef } from \"vue\";\n\nexport interface UseAiConfigReturn {\n isFeatureEnabled: (feature: keyof AiConfig) => boolean;\n hasAnyMenuFeature: ComputedRef<boolean>;\n}\n\nexport function useAiConfig(config?: AiConfig | false): UseAiConfigReturn {\n function isFeatureEnabled(feature: keyof AiConfig): boolean {\n if (config === false) {\n return false;\n }\n\n return config?.[feature] !== false;\n }\n\n const hasAnyMenuFeature = computed(\n () =>\n isFeatureEnabled(\"chat\") ||\n isFeatureEnabled(\"scoring\") ||\n isFeatureEnabled(\"designToTemplate\"),\n );\n\n return {\n isFeatureEnabled,\n hasAnyMenuFeature,\n };\n}\n","import type {\n ScoringCategory,\n ScoringFinding,\n ScoringResult,\n} from \"@templatical/types\";\nimport type { AuthManager } from \"./auth\";\nimport { API_ROUTES, buildUrl } from \"./url-builder\";\nimport type { MergeTag, TemplateContent } from \"@templatical/types\";\nimport { ref } from \"vue\";\n\nexport interface UseTemplateScoringOptions {\n authManager: AuthManager;\n getTemplateId: () => string | null;\n}\n\nexport interface UseTemplateScoringReturn {\n isScoring: ReturnType<typeof ref<boolean>>;\n scoringResult: ReturnType<typeof ref<ScoringResult | null>>;\n error: ReturnType<typeof ref<string | null>>;\n fixingFindingId: ReturnType<typeof ref<string | null>>;\n fixStreamingText: ReturnType<typeof ref<string>>;\n fixError: ReturnType<typeof ref<string | null>>;\n score: (\n content: TemplateContent,\n mergeTags: MergeTag[],\n ) => Promise<ScoringResult | null>;\n fixFinding: (\n blockContent: string,\n finding: ScoringFinding,\n mergeTags: MergeTag[],\n ) => Promise<string | null>;\n removeFinding: (category: ScoringCategory, findingId: string) => void;\n reset: () => void;\n}\n\nexport function useTemplateScoring(\n options: UseTemplateScoringOptions,\n): UseTemplateScoringReturn {\n const { authManager, getTemplateId } = options;\n\n const isScoring = ref(false);\n const scoringResult = ref<ScoringResult | null>(null);\n const error = ref<string | null>(null);\n const fixingFindingId = ref<string | null>(null);\n const fixStreamingText = ref(\"\");\n const fixError = ref<string | null>(null);\n\n async function score(\n content: TemplateContent,\n mergeTags: MergeTag[],\n ): Promise<ScoringResult | null> {\n const templateId = getTemplateId();\n if (!templateId) {\n return null;\n }\n\n isScoring.value = true;\n error.value = null;\n scoringResult.value = null;\n\n try {\n const url = buildUrl(API_ROUTES[\"ai.score\"], {\n project: authManager.projectId,\n tenant: authManager.tenantSlug,\n template: templateId,\n });\n\n const response = await authManager.authenticatedFetch(url, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Accept: \"text/event-stream\",\n },\n body: JSON.stringify({\n current_content: content,\n merge_tags: mergeTags.map((p) => ({\n label: p.label,\n value: p.value,\n })),\n }),\n });\n\n if (!response.ok) {\n if (response.status === 403) {\n throw new Error(\"ai_generation_not_available\");\n }\n const errorData = await response.json().catch(() => null);\n throw new Error(errorData?.message || \"Failed to score template\");\n }\n\n const reader = response.body?.getReader();\n if (!reader) {\n throw new Error(\"Failed to read stream\");\n }\n\n const decoder = new TextDecoder();\n let buffer = \"\";\n let result: ScoringResult | null = null;\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n\n buffer += decoder.decode(value, { stream: true });\n\n const lines = buffer.split(\"\\n\");\n buffer = lines.pop() ?? \"\";\n\n for (const line of lines) {\n if (!line.startsWith(\"data: \")) {\n continue;\n }\n\n let event;\n try {\n event = JSON.parse(line.slice(6));\n } catch {\n continue;\n }\n\n if (event.type === \"error\") {\n throw new Error(event.message || \"Failed to score template\");\n }\n\n if (event.type === \"done\") {\n result = event.result ?? null;\n }\n }\n }\n\n if (result) {\n for (const [category, categoryData] of Object.entries(\n result.categories,\n )) {\n for (const finding of categoryData.findings) {\n finding.category = category as ScoringCategory;\n }\n }\n }\n\n scoringResult.value = result;\n return result;\n } catch (err) {\n error.value =\n err instanceof Error ? err.message : \"Failed to score template\";\n return null;\n } finally {\n isScoring.value = false;\n }\n }\n\n async function fixFinding(\n blockContent: string,\n finding: ScoringFinding,\n mergeTags: MergeTag[],\n ): Promise<string | null> {\n const templateId = getTemplateId();\n if (!templateId) {\n return null;\n }\n\n fixingFindingId.value = finding.id;\n fixStreamingText.value = \"\";\n fixError.value = null;\n\n try {\n const url = buildUrl(API_ROUTES[\"ai.fixFinding\"], {\n project: authManager.projectId,\n tenant: authManager.tenantSlug,\n template: templateId,\n });\n\n const response = await authManager.authenticatedFetch(url, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Accept: \"text/event-stream\",\n },\n body: JSON.stringify({\n content: blockContent,\n finding: {\n id: finding.id,\n message: finding.message,\n suggestion: finding.suggestion,\n category: finding.category,\n },\n merge_tags: mergeTags.map((p) => ({\n label: p.label,\n value: p.value,\n })),\n }),\n });\n\n if (!response.ok) {\n if (response.status === 403) {\n throw new Error(\"ai_generation_not_available\");\n }\n const errorData = await response.json().catch(() => null);\n throw new Error(errorData?.message || \"Failed to fix finding\");\n }\n\n const reader = response.body?.getReader();\n if (!reader) {\n throw new Error(\"Failed to read stream\");\n }\n\n const decoder = new TextDecoder();\n let buffer = \"\";\n let result: string | null = null;\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n\n buffer += decoder.decode(value, { stream: true });\n\n const lines = buffer.split(\"\\n\");\n buffer = lines.pop() ?? \"\";\n\n for (const line of lines) {\n if (!line.startsWith(\"data: \")) {\n continue;\n }\n\n let event;\n try {\n event = JSON.parse(line.slice(6));\n } catch {\n continue;\n }\n\n if (event.type === \"text\") {\n fixStreamingText.value += event.text;\n } else if (event.type === \"error\") {\n throw new Error(event.message || \"Failed to fix finding\");\n } else if (event.type === \"done\") {\n result = event.content ?? null;\n }\n }\n }\n\n return result;\n } catch (err) {\n fixError.value =\n err instanceof Error ? err.message : \"Failed to fix finding\";\n return null;\n } finally {\n fixingFindingId.value = null;\n }\n }\n\n function removeFinding(category: ScoringCategory, findingId: string): void {\n if (!scoringResult.value) {\n return;\n }\n\n const cat = scoringResult.value.categories[category];\n if (!cat) {\n return;\n }\n\n cat.findings = cat.findings.filter((f) => f.id !== findingId);\n }\n\n function reset(): void {\n isScoring.value = false;\n scoringResult.value = null;\n error.value = null;\n fixingFindingId.value = null;\n fixStreamingText.value = \"\";\n fixError.value = null;\n }\n\n return {\n isScoring,\n scoringResult,\n error,\n fixingFindingId,\n fixStreamingText,\n fixError,\n score,\n fixFinding,\n removeFinding,\n reset,\n };\n}\n","import type { AuthManager } from \"./auth\";\nimport { API_ROUTES, buildUrl } from \"./url-builder\";\nimport type { TemplateContent } from \"@templatical/types\";\nimport { ref } from \"vue\";\n\nexport interface UseDesignReferenceOptions {\n authManager: AuthManager;\n getTemplateId: () => string | null;\n onApply?: (content: TemplateContent) => void;\n onError?: (error: Error) => void;\n}\n\nexport interface UseDesignReferenceReturn {\n isGenerating: ReturnType<typeof ref<boolean>>;\n error: ReturnType<typeof ref<string | null>>;\n generate: (input: DesignReferenceInput) => Promise<TemplateContent | null>;\n reset: () => void;\n}\n\nexport interface DesignReferenceInput {\n prompt?: string;\n imageUpload?: File;\n pdfUpload?: File;\n}\n\nexport function useDesignReference(\n options: UseDesignReferenceOptions,\n): UseDesignReferenceReturn {\n const { authManager, getTemplateId, onApply, onError } = options;\n\n const isGenerating = ref(false);\n const error = ref<string | null>(null);\n\n async function generate(\n input: DesignReferenceInput,\n ): Promise<TemplateContent | null> {\n const templateId = getTemplateId();\n if (!templateId) {\n throw new Error(\"Template must be saved before using design reference\");\n }\n\n isGenerating.value = true;\n error.value = null;\n\n try {\n const formData = new FormData();\n\n if (input.prompt) {\n formData.append(\"prompt\", input.prompt);\n }\n\n if (input.imageUpload) {\n formData.append(\"image_upload\", input.imageUpload);\n }\n\n if (input.pdfUpload) {\n formData.append(\"pdf_upload\", input.pdfUpload);\n }\n\n const url = buildUrl(API_ROUTES[\"ai.generateFromDesign\"], {\n project: authManager.projectId,\n tenant: authManager.tenantSlug,\n template: templateId,\n });\n\n const response = await authManager.authenticatedFetch(url, {\n method: \"POST\",\n headers: {\n Accept: \"text/event-stream\",\n },\n body: formData,\n });\n\n if (!response.ok) {\n const errorData = await response.json().catch(() => null);\n if (response.status === 403) {\n throw new Error(\"ai_generation_not_available\");\n }\n throw new Error(\n errorData?.message || \"Failed to generate template from design\",\n );\n }\n\n const reader = response.body?.getReader();\n if (!reader) {\n throw new Error(\"Failed to read stream\");\n }\n\n const decoder = new TextDecoder();\n let buffer = \"\";\n let result: TemplateContent | null = null;\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n\n buffer += decoder.decode(value, { stream: true });\n\n const lines = buffer.split(\"\\n\");\n buffer = lines.pop() ?? \"\";\n\n for (const line of lines) {\n if (!line.startsWith(\"data: \")) {\n continue;\n }\n\n const jsonStr = line.slice(6);\n\n let event;\n try {\n event = JSON.parse(jsonStr);\n } catch {\n continue;\n }\n\n if (event.type === \"error\") {\n throw new Error(\n event.message || \"Failed to generate template from design\",\n );\n }\n\n if (event.type === \"done\") {\n result = event.content ?? null;\n\n if (result) {\n onApply?.(result);\n }\n }\n }\n }\n\n return result;\n } catch (err) {\n const wrappedError =\n err instanceof Error\n ? err\n : new Error(\"Failed to generate template from design\", {\n cause: err,\n });\n error.value = wrappedError.message;\n onError?.(wrappedError);\n\n return null;\n } finally {\n isGenerating.value = false;\n }\n }\n\n function reset(): void {\n isGenerating.value = false;\n error.value = null;\n }\n\n return {\n isGenerating,\n error,\n generate,\n reset,\n };\n}\n","import type {\n Comment,\n CommentEvent,\n CommentThread,\n UserConfig,\n} from \"@templatical/types\";\nimport { ApiClient } from \"./api\";\nimport type { AuthManager } from \"./auth\";\nimport { computed, ref, type ComputedRef, type Ref } from \"vue\";\n\nexport interface UseCommentsOptions {\n authManager: AuthManager;\n getTemplateId: () => string | null;\n getSocketId?: () => string | null;\n onComment?: (event: CommentEvent) => void;\n onError?: (error: Error) => void;\n isAuthReady?: Ref<boolean>;\n hasCommentingFeature?: () => boolean;\n}\n\nexport interface UseCommentsReturn {\n comments: Ref<CommentThread[]>;\n isLoading: Ref<boolean>;\n isSubmitting: Ref<boolean>;\n isEnabled: ComputedRef<boolean>;\n commentCountByBlock: ComputedRef<Map<string, number>>;\n totalCount: ComputedRef<number>;\n unresolvedCount: ComputedRef<number>;\n loadComments: () => Promise<void>;\n addComment: (\n body: string,\n blockId?: string,\n parentId?: string,\n ) => Promise<Comment | null>;\n editComment: (commentId: string, body: string) => Promise<Comment | null>;\n removeComment: (commentId: string) => Promise<boolean>;\n toggleResolve: (commentId: string) => Promise<Comment | null>;\n applyRemoteCreate: (comment: Comment) => void;\n applyRemoteUpdate: (comment: Comment) => void;\n applyRemoteDelete: (commentId: string, parentId: string | null) => void;\n}\n\nexport function useComments(options: UseCommentsOptions): UseCommentsReturn {\n const {\n authManager,\n getTemplateId,\n getSocketId,\n onComment,\n onError,\n hasCommentingFeature,\n } = options;\n\n const api = new ApiClient(authManager);\n const comments = ref<CommentThread[]>([]);\n const isLoading = ref(false);\n const isSubmitting = ref(false);\n\n const isEnabled = computed<boolean>(() => {\n const featureAvailable = hasCommentingFeature?.() ?? false;\n return featureAvailable && authManager.userConfig !== null;\n });\n\n const totalCount = computed<number>(() => {\n let count = 0;\n for (const thread of comments.value) {\n count += 1 + (thread.replies?.length ?? 0);\n }\n return count;\n });\n\n const unresolvedCount = computed<number>(() => {\n return comments.value.filter((c) => !c.resolved_at).length;\n });\n\n const commentCountByBlock = computed<Map<string, number>>(() => {\n const map = new Map<string, number>();\n for (const thread of comments.value) {\n if (thread.block_id) {\n map.set(\n thread.block_id,\n (map.get(thread.block_id) ?? 0) + 1 + (thread.replies?.length ?? 0),\n );\n }\n }\n return map;\n });\n\n function getUserPayload(): {\n user_id: string;\n user_name: string;\n user_signature: string;\n } {\n const user: UserConfig | null = authManager.userConfig;\n if (!user) {\n throw new Error(\"User config not available\");\n }\n return {\n user_id: user.id,\n user_name: user.name,\n user_signature: user.signature,\n };\n }\n\n function socketHeaders(): Record<string, string> | undefined {\n const socketId = getSocketId?.();\n if (!socketId) {\n return undefined;\n }\n return { \"X-Socket-ID\": socketId };\n }\n\n function emitEvent(type: CommentEvent[\"type\"], comment: Comment): void {\n onComment?.({ type, comment });\n }\n\n function findComment(commentId: string): Comment | null {\n for (const thread of comments.value) {\n if (thread.id === commentId) {\n return thread;\n }\n for (const reply of thread.replies ?? []) {\n if (reply.id === commentId) {\n return reply;\n }\n }\n }\n return null;\n }\n\n async function loadComments(): Promise<void> {\n const templateId = getTemplateId();\n if (!templateId) {\n return;\n }\n\n isLoading.value = true;\n\n try {\n comments.value = await api.getComments(templateId);\n } catch (err) {\n const wrappedError =\n err instanceof Error\n ? err\n : new Error(\"Failed to load comments\", { cause: err });\n onError?.(wrappedError);\n } finally {\n isLoading.value = false;\n }\n }\n\n async function addComment(\n body: string,\n blockId?: string,\n parentId?: string,\n ): Promise<Comment | null> {\n const templateId = getTemplateId();\n if (!templateId) {\n return null;\n }\n\n isSubmitting.value = true;\n\n try {\n const comment = await api.createComment(\n templateId,\n {\n body,\n block_id: blockId,\n parent_id: parentId,\n ...getUserPayload(),\n },\n socketHeaders(),\n );\n\n if (parentId) {\n const parent = findComment(parentId);\n if (parent) {\n parent.replies = [...(parent.replies ?? []), comment];\n }\n } else {\n comments.value = [...comments.value, comment];\n }\n\n emitEvent(\"created\", comment);\n return comment;\n } catch (err) {\n const wrappedError =\n err instanceof Error\n ? err\n : new Error(\"Failed to create comment\", { cause: err });\n onError?.(wrappedError);\n return null;\n } finally {\n isSubmitting.value = false;\n }\n }\n\n async function editComment(\n commentId: string,\n body: string,\n ): Promise<Comment | null> {\n const templateId = getTemplateId();\n if (!templateId) {\n return null;\n }\n\n isSubmitting.value = true;\n\n try {\n const updated = await api.updateComment(\n templateId,\n commentId,\n {\n body,\n ...getUserPayload(),\n },\n socketHeaders(),\n );\n\n updateCommentInState(commentId, updated);\n emitEvent(\"updated\", updated);\n return updated;\n } catch (err) {\n const wrappedError =\n err instanceof Error\n ? err\n : new Error(\"Failed to update comment\", { cause: err });\n onError?.(wrappedError);\n return null;\n } finally {\n isSubmitting.value = false;\n }\n }\n\n async function removeComment(commentId: string): Promise<boolean> {\n const templateId = getTemplateId();\n if (!templateId) {\n return false;\n }\n\n const comment = findComment(commentId);\n if (!comment) {\n return false;\n }\n\n const commentSnapshot = {\n ...comment,\n replies: [...(comment.replies ?? [])],\n };\n\n isSubmitting.value = true;\n\n try {\n await api.deleteComment(\n templateId,\n commentId,\n getUserPayload(),\n socketHeaders(),\n );\n\n if (comment.parent_id) {\n const parent = findComment(comment.parent_id);\n if (parent) {\n parent.replies = (parent.replies ?? []).filter(\n (r) => r.id !== commentId,\n );\n }\n } else {\n comments.value = comments.value.filter((c) => c.id !== commentId);\n }\n\n emitEvent(\"deleted\", commentSnapshot);\n return true;\n } catch (err) {\n const wrappedError =\n err instanceof Error\n ? err\n : new Error(\"Failed to delete comment\", { cause: err });\n onError?.(wrappedError);\n return false;\n } finally {\n isSubmitting.value = false;\n }\n }\n\n async function toggleResolve(commentId: string): Promise<Comment | null> {\n const templateId = getTemplateId();\n if (!templateId) {\n return null;\n }\n\n isSubmitting.value = true;\n\n try {\n const updated = await api.resolveComment(\n templateId,\n commentId,\n getUserPayload(),\n socketHeaders(),\n );\n\n updateCommentInState(commentId, updated);\n\n const eventType = updated.resolved_at ? \"resolved\" : \"unresolved\";\n emitEvent(eventType, updated);\n return updated;\n } catch (err) {\n const wrappedError =\n err instanceof Error\n ? err\n : new Error(\"Failed to toggle comment resolution\", { cause: err });\n onError?.(wrappedError);\n return null;\n } finally {\n isSubmitting.value = false;\n }\n }\n\n function applyRemoteCreate(comment: Comment): void {\n if (comment.parent_id) {\n const parent = findComment(comment.parent_id);\n if (parent) {\n parent.replies = [...(parent.replies ?? []), comment];\n }\n } else {\n comments.value = [...comments.value, comment];\n }\n emitEvent(\"created\", comment);\n }\n\n function applyRemoteUpdate(comment: Comment): void {\n updateCommentInState(comment.id, comment);\n emitEvent(\"updated\", comment);\n }\n\n function applyRemoteDelete(commentId: string, parentId: string | null): void {\n const comment = findComment(commentId);\n const snapshot = comment\n ? { ...comment, replies: [...(comment.replies ?? [])] }\n : null;\n\n if (parentId) {\n const parent = findComment(parentId);\n if (parent) {\n parent.replies = (parent.replies ?? []).filter(\n (r) => r.id !== commentId,\n );\n }\n } else {\n comments.value = comments.value.filter((c) => c.id !== commentId);\n }\n\n if (snapshot) {\n emitEvent(\"deleted\", snapshot);\n }\n }\n\n function updateCommentInState(commentId: string, updated: Comment): void {\n for (let i = 0; i < comments.value.length; i++) {\n if (comments.value[i].id === commentId) {\n comments.value = [\n ...comments.value.slice(0, i),\n { ...updated, replies: comments.value[i].replies },\n ...comments.value.slice(i + 1),\n ];\n return;\n }\n\n const replies = comments.value[i].replies ?? [];\n for (let j = 0; j < replies.length; j++) {\n if (replies[j].id === commentId) {\n const newReplies = [\n ...replies.slice(0, j),\n updated,\n ...replies.slice(j + 1),\n ];\n comments.value = [\n ...comments.value.slice(0, i),\n { ...comments.value[i], replies: newReplies },\n ...comments.value.slice(i + 1),\n ];\n return;\n }\n }\n }\n }\n\n return {\n comments,\n isLoading,\n isSubmitting,\n isEnabled,\n commentCountByBlock,\n totalCount,\n unresolvedCount,\n loadComments,\n addComment,\n editComment,\n removeComment,\n toggleResolve,\n applyRemoteCreate,\n applyRemoteUpdate,\n applyRemoteDelete,\n };\n}\n","import type { UseCommentsReturn } from \"./comments\";\nimport type { Comment } from \"@templatical/types\";\nimport type { PresenceChannel } from \"pusher-js\";\nimport { onScopeDispose, watch, type Ref } from \"vue\";\n\nexport interface CommentBroadcastPayload {\n action:\n | \"comment_created\"\n | \"comment_updated\"\n | \"comment_deleted\"\n | \"comment_resolved\"\n | \"comment_unresolved\";\n comment: Comment;\n}\n\nexport interface UseCommentListenerOptions {\n comments: UseCommentsReturn;\n channel: Ref<PresenceChannel | null>;\n}\n\nexport function useCommentListener(options: UseCommentListenerOptions): void {\n const { comments, channel } = options;\n\n watch(channel, (newChannel, oldChannel) => {\n if (oldChannel) {\n oldChannel.unbind(\"comment-broadcast\");\n }\n\n if (newChannel) {\n newChannel.bind(\n \"comment-broadcast\",\n (payload: CommentBroadcastPayload) => {\n handleCommentBroadcast(comments, payload);\n },\n );\n }\n });\n\n // The watch only unbinds on channel *transitions*. On scope dispose the\n // currently-bound handler stays attached, processing broadcasts on a\n // dead component. Explicitly tear it down.\n onScopeDispose(() => {\n channel.value?.unbind(\"comment-broadcast\");\n });\n}\n\nfunction handleCommentBroadcast(\n comments: UseCommentsReturn,\n payload: CommentBroadcastPayload,\n): void {\n switch (payload.action) {\n case \"comment_created\":\n comments.applyRemoteCreate(payload.comment);\n break;\n case \"comment_updated\":\n comments.applyRemoteUpdate(payload.comment);\n break;\n case \"comment_deleted\":\n comments.applyRemoteDelete(payload.comment.id, payload.comment.parent_id);\n break;\n case \"comment_resolved\":\n case \"comment_unresolved\":\n comments.applyRemoteUpdate(payload.comment);\n break;\n }\n}\n","import type { UseEditorReturn } from \"./editor\";\nimport type { AuthManager } from \"./auth\";\nimport type { Collaborator, McpOperationPayload } from \"@templatical/types\";\nimport { handleOperation } from \"./mcp-operation-handler\";\nimport type { PresenceMember } from \"./websocket-client\";\nimport type { PresenceChannel } from \"pusher-js\";\nimport { computed, onScopeDispose, ref, watch, type Ref } from \"vue\";\n\nconst COLLAB_EVENTS = [\n \"pusher:member_added\",\n \"pusher:member_removed\",\n \"client-block_locked\",\n \"client-block_unlocked\",\n \"client-operation\",\n \"mcp-operation\",\n] as const;\n\nfunction unbindCollabEvents(channel: PresenceChannel): void {\n for (const event of COLLAB_EVENTS) {\n channel.unbind(event);\n }\n}\n\nconst COLLABORATOR_COLORS = [\n \"#3b82f6\",\n \"#ef4444\",\n \"#10b981\",\n \"#f59e0b\",\n \"#8b5cf6\",\n \"#ec4899\",\n \"#06b6d4\",\n \"#f97316\",\n \"#6366f1\",\n \"#14b8a6\",\n];\n\nexport interface UseCollaborationOptions {\n authManager: AuthManager;\n editor: UseEditorReturn;\n channel: Ref<PresenceChannel | null>;\n onError?: (error: Error) => void;\n onCollaboratorJoined?: (collaborator: Collaborator) => void;\n onCollaboratorLeft?: (collaborator: Collaborator) => void;\n onBlockLocked?: (event: {\n blockId: string;\n collaborator: Collaborator;\n }) => void;\n onBlockUnlocked?: (event: {\n blockId: string;\n collaborator: Collaborator;\n }) => void;\n}\n\nexport interface UseCollaborationReturn {\n collaborators: Ref<Collaborator[]>;\n lockedBlocks: Ref<Map<string, Collaborator>>;\n}\n\nexport function useCollaboration(\n options: UseCollaborationOptions,\n): UseCollaborationReturn & {\n _broadcastOperation: (payload: McpOperationPayload) => void;\n _isProcessingRemoteOperation: () => boolean;\n} {\n const { authManager, editor, channel } = options;\n\n const collaborators = ref<Collaborator[]>([]);\n const lockedBlocks = ref<Map<string, Collaborator>>(new Map());\n\n let colorIndex = 0;\n let isProcessingRemoteOperation = false;\n\n const myUserId = computed(() => authManager.userConfig?.id ?? \"\");\n\n function assignColor(): string {\n const color = COLLABORATOR_COLORS[colorIndex % COLLABORATOR_COLORS.length];\n colorIndex++;\n return color;\n }\n\n function addCollaborator(member: PresenceMember): Collaborator | undefined {\n if (member.id === myUserId.value) {\n return undefined;\n }\n\n if (collaborators.value.some((c) => c.id === member.id)) {\n return undefined;\n }\n\n const collaborator: Collaborator = {\n id: member.id,\n name: member.name,\n color: assignColor(),\n selectedBlockId: null,\n };\n\n collaborators.value = [...collaborators.value, collaborator];\n\n return collaborator;\n }\n\n function removeCollaborator(memberId: string): void {\n const newLockedBlocks = new Map(lockedBlocks.value);\n for (const [blockId, collaborator] of newLockedBlocks) {\n if (collaborator.id === memberId) {\n newLockedBlocks.delete(blockId);\n }\n }\n lockedBlocks.value = newLockedBlocks;\n\n collaborators.value = collaborators.value.filter((c) => c.id !== memberId);\n }\n\n function handleBlockLocked(data: { blockId: string; userId: string }): void {\n const collaborator = collaborators.value.find((c) => c.id === data.userId);\n if (!collaborator) {\n return;\n }\n\n collaborators.value = collaborators.value.map((c) =>\n c.id === data.userId ? { ...c, selectedBlockId: data.blockId } : c,\n );\n\n const newLockedBlocks = new Map(lockedBlocks.value);\n for (const [blockId, holder] of newLockedBlocks) {\n if (holder.id === data.userId) {\n newLockedBlocks.delete(blockId);\n }\n }\n\n newLockedBlocks.set(data.blockId, {\n ...collaborator,\n selectedBlockId: data.blockId,\n });\n lockedBlocks.value = newLockedBlocks;\n\n if (editor.state.selectedBlockId === data.blockId) {\n editor.selectBlock(null);\n }\n }\n\n function handleBlockUnlocked(data: { blockId: string }): void {\n const newLockedBlocks = new Map(lockedBlocks.value);\n const holder = newLockedBlocks.get(data.blockId);\n newLockedBlocks.delete(data.blockId);\n lockedBlocks.value = newLockedBlocks;\n\n if (holder) {\n collaborators.value = collaborators.value.map((c) =>\n c.id === holder.id ? { ...c, selectedBlockId: null } : c,\n );\n }\n }\n\n function handleRemoteOperation(payload: McpOperationPayload): void {\n isProcessingRemoteOperation = true;\n try {\n handleOperation(editor, payload);\n } finally {\n isProcessingRemoteOperation = false;\n }\n }\n\n function broadcastOperation(payload: McpOperationPayload): void {\n if (!channel.value || isProcessingRemoteOperation) {\n return;\n }\n\n channel.value.trigger(\"client-operation\", payload);\n }\n\n function broadcastBlockLocked(blockId: string): void {\n if (!channel.value) {\n return;\n }\n\n channel.value.trigger(\"client-block_locked\", {\n blockId,\n userId: myUserId.value,\n });\n }\n\n function broadcastBlockUnlocked(blockId: string): void {\n if (!channel.value) {\n return;\n }\n\n channel.value.trigger(\"client-block_unlocked\", { blockId });\n }\n\n watch(\n () => editor.state.selectedBlockId,\n (newBlockId, oldBlockId) => {\n if (isProcessingRemoteOperation) {\n return;\n }\n\n if (oldBlockId) {\n broadcastBlockUnlocked(oldBlockId);\n }\n\n if (newBlockId) {\n broadcastBlockLocked(newBlockId);\n }\n },\n );\n\n watch(channel, (newChannel, oldChannel) => {\n if (oldChannel) {\n unbindCollabEvents(oldChannel);\n }\n\n if (!newChannel) {\n collaborators.value = [];\n lockedBlocks.value = new Map();\n colorIndex = 0;\n return;\n }\n\n const members = (\n newChannel as PresenceChannel & {\n members: {\n each: (\n callback: (member: { id: string; info: PresenceMember }) => void,\n ) => void;\n };\n }\n ).members;\n if (members) {\n members.each((member: { id: string; info: PresenceMember }) => {\n addCollaborator(member.info);\n });\n }\n\n newChannel.bind(\n \"pusher:member_added\",\n (member: { id: string; info: PresenceMember }) => {\n const collaborator = addCollaborator(member.info);\n if (collaborator) {\n options.onCollaboratorJoined?.(collaborator);\n }\n },\n );\n\n newChannel.bind(\n \"pusher:member_removed\",\n (member: { id: string; info: PresenceMember }) => {\n const collaborator = collaborators.value.find(\n (c) => c.id === member.id,\n );\n removeCollaborator(member.id);\n if (collaborator) {\n options.onCollaboratorLeft?.(collaborator);\n }\n },\n );\n\n newChannel.bind(\n \"client-block_locked\",\n (data: { blockId: string; userId: string }) => {\n handleBlockLocked(data);\n const collaborator = collaborators.value.find(\n (c) => c.id === data.userId,\n );\n if (collaborator) {\n options.onBlockLocked?.({\n blockId: data.blockId,\n collaborator,\n });\n }\n },\n );\n\n newChannel.bind(\"client-block_unlocked\", (data: { blockId: string }) => {\n const holder = lockedBlocks.value.get(data.blockId);\n handleBlockUnlocked(data);\n if (holder) {\n options.onBlockUnlocked?.({\n blockId: data.blockId,\n collaborator: holder,\n });\n }\n });\n\n newChannel.bind(\"client-operation\", (payload: McpOperationPayload) => {\n handleRemoteOperation(payload);\n });\n\n newChannel.bind(\"mcp-operation\", (payload: McpOperationPayload) => {\n handleRemoteOperation(payload);\n });\n });\n\n // The watch above only unbinds when the channel ref *changes*. On scope\n // dispose (component unmount) the watch is auto-stopped but the currently\n // bound listeners stay attached forever — handlers fire on a dead component\n // and accumulate on remount. Tear them down explicitly.\n onScopeDispose(() => {\n if (channel.value) {\n unbindCollabEvents(channel.value);\n }\n });\n\n return {\n collaborators,\n lockedBlocks,\n _broadcastOperation: broadcastOperation,\n _isProcessingRemoteOperation: () => isProcessingRemoteOperation,\n };\n}\n","import type { McpOperationPayload } from \"@templatical/types\";\nimport type { UseEditorReturn } from \"../editor\";\n\ninterface BroadcastTarget {\n _broadcastOperation: (payload: McpOperationPayload) => void;\n}\n\n/**\n * Wraps editor mutation methods to broadcast operations to collaboration\n * peers after each mutation executes. Mutates the editor object in place.\n *\n * Must be applied **before** the history interceptor so the call chain is:\n * history.record() → broadcast + original mutation.\n */\nexport function useCollaborationBroadcast(\n editor: UseEditorReturn,\n collaboration: BroadcastTarget,\n): void {\n const originalAddBlock = editor.addBlock;\n const originalUpdateBlock = editor.updateBlock;\n const originalRemoveBlock = editor.removeBlock;\n const originalMoveBlock = editor.moveBlock;\n const originalUpdateSettings = editor.updateSettings;\n const originalSetContent = editor.setContent;\n\n editor.addBlock = (block, targetSectionId?, columnIndex?, index?) => {\n originalAddBlock(block, targetSectionId, columnIndex, index);\n collaboration._broadcastOperation({\n operation: \"add_block\",\n data: {\n block,\n section_id: targetSectionId,\n column_index: columnIndex,\n index,\n },\n timestamp: Date.now(),\n });\n };\n\n editor.updateBlock = (blockId, updates) => {\n originalUpdateBlock(blockId, updates);\n collaboration._broadcastOperation({\n operation: \"update_block\",\n data: { block_id: blockId, updates },\n timestamp: Date.now(),\n });\n };\n\n editor.removeBlock = (blockId) => {\n originalRemoveBlock(blockId);\n collaboration._broadcastOperation({\n operation: \"delete_block\",\n data: { block_id: blockId },\n timestamp: Date.now(),\n });\n };\n\n editor.moveBlock = (blockId, newIndex, targetSectionId?, columnIndex?) => {\n originalMoveBlock(blockId, newIndex, targetSectionId, columnIndex);\n collaboration._broadcastOperation({\n operation: \"move_block\",\n data: {\n block_id: blockId,\n index: newIndex,\n section_id: targetSectionId,\n column_index: columnIndex,\n },\n timestamp: Date.now(),\n });\n };\n\n editor.updateSettings = (updates) => {\n originalUpdateSettings(updates);\n collaboration._broadcastOperation({\n operation: \"update_settings\",\n data: { updates },\n timestamp: Date.now(),\n });\n };\n\n editor.setContent = (content, markDirty?) => {\n originalSetContent(content, markDirty);\n collaboration._broadcastOperation({\n operation: \"set_content\",\n data: { content },\n timestamp: Date.now(),\n });\n };\n}\n","import type { AuthManager } from \"./auth\";\nimport type { WebSocketConfig } from \"./websocket-client\";\nimport { WebSocketClient } from \"./websocket-client\";\nimport type { PresenceChannel } from \"pusher-js\";\nimport { ref, type Ref } from \"vue\";\n\nexport interface UseWebSocketOptions {\n authManager: AuthManager;\n onError?: (error: Error) => void;\n}\n\nexport interface UseWebSocketReturn {\n channel: Ref<PresenceChannel | null>;\n isConnected: Ref<boolean>;\n connect: (templateId: string, config: WebSocketConfig) => Promise<void>;\n disconnect: () => void;\n getSocketId: () => string | null;\n}\n\nexport function useWebSocket(options: UseWebSocketOptions): UseWebSocketReturn {\n const { authManager, onError } = options;\n\n const channel = ref<PresenceChannel | null>(\n null,\n ) as Ref<PresenceChannel | null>;\n const isConnected = ref(false);\n\n let wsClient: WebSocketClient | null = null;\n let channelName: string | null = null;\n\n async function connect(\n templateId: string,\n config: WebSocketConfig,\n ): Promise<void> {\n if (wsClient) {\n return;\n }\n\n wsClient = new WebSocketClient({\n authManager,\n config,\n onError,\n });\n\n await wsClient.connect();\n\n channelName = `presence-template.${templateId}`;\n const presenceChannel = wsClient.subscribePresence(channelName);\n\n presenceChannel.bind(\"pusher:subscription_succeeded\", () => {\n isConnected.value = true;\n channel.value = presenceChannel;\n });\n\n presenceChannel.bind(\"pusher:subscription_error\", (error: unknown) => {\n isConnected.value = false;\n channel.value = null;\n onError?.(\n error instanceof Error\n ? error\n : new Error(\"Failed to subscribe to template channel\"),\n );\n });\n }\n\n function disconnect(): void {\n if (channelName && wsClient) {\n wsClient.unsubscribe(channelName);\n }\n\n wsClient?.disconnect();\n wsClient = null;\n channelName = null;\n channel.value = null;\n isConnected.value = false;\n }\n\n function getSocketId(): string | null {\n return wsClient?.getSocketId() ?? null;\n }\n\n return {\n channel,\n isConnected,\n connect,\n disconnect,\n getSocketId,\n };\n}\n","import type {\n SavedBlock,\n SavedBlockInput,\n SavedBlockPatch,\n SavedBlocksListParams,\n SavedBlocksProvider,\n} from \"@templatical/types\";\nimport { ApiClient } from \"./api\";\nimport type { AuthManager } from \"./auth\";\n\n/**\n * Cloud-backed {@link SavedBlocksProvider} — the Templatical Cloud adapter for\n * the same contract consumers implement themselves.\n *\n * Auth (JWT via {@link AuthManager}) and project/tenant scoping live entirely\n * on this side of the seam: the shared `useSavedBlocks` composable and the\n * editor UI never see them. Plan gating is applied by the caller before this\n * provider is constructed.\n *\n * Wraps the existing `ApiClient` saved-module endpoints, so the REST contract\n * is unchanged from before saved blocks became an open-source feature.\n *\n * Rows pass straight through, unmapped: the Cloud endpoints speak the same\n * `SavedBlock` shape the contract defines, so this adapter only supplies auth\n * and scoping. That means the payload's field names track the contract — the\n * backend serialises `category`, `canUpdate`, `canDelete`, `createdAt` and\n * `updatedAt`. Until it does, those fields simply arrive absent, which degrades\n * to \"no timestamp label, every action allowed\" rather than breaking.\n */\nexport function createCloudSavedBlocksProvider(\n authManager: AuthManager,\n): SavedBlocksProvider {\n const api = new ApiClient(authManager);\n\n return {\n list(params?: SavedBlocksListParams): Promise<SavedBlock[]> {\n return api.listModules(params?.search, params?.category);\n },\n // All three enabled: Cloud gates saved blocks by plan entitlement above\n // this seam, and row-level permissions arrive as `canUpdate`/`canDelete`\n // on the entries themselves.\n create(input: SavedBlockInput): Promise<SavedBlock> {\n return api.createModule(input);\n },\n update(id: string, patch: SavedBlockPatch): Promise<SavedBlock> {\n return api.updateModule(id, patch);\n },\n delete(id: string): Promise<void> {\n return api.deleteModule(id);\n },\n };\n}\n","import type { Template, TemplateSnapshot } from \"@templatical/types\";\nimport { ApiClient } from \"./api\";\nimport type { AuthManager } from \"./auth\";\nimport { ref, type Ref } from \"vue\";\n\nexport interface UseSnapshotHistoryOptions {\n authManager: AuthManager;\n templateId: string;\n onRestore?: (template: Template) => void;\n onError?: (error: Error) => void;\n}\n\nexport interface UseSnapshotHistoryReturn {\n snapshots: Ref<TemplateSnapshot[]>;\n isLoading: Ref<boolean>;\n isRestoring: Ref<boolean>;\n loadSnapshots: () => Promise<void>;\n restoreSnapshot: (snapshotId: string) => Promise<Template>;\n}\n\nexport function useSnapshotHistory(\n options: UseSnapshotHistoryOptions,\n): UseSnapshotHistoryReturn {\n const api = new ApiClient(options.authManager);\n\n const snapshots = ref<TemplateSnapshot[]>([]);\n const isLoading = ref(false);\n const isRestoring = ref(false);\n\n async function loadSnapshots(): Promise<void> {\n isLoading.value = true;\n try {\n snapshots.value = await api.getSnapshots(options.templateId);\n } catch (error) {\n options.onError?.(error as Error);\n throw error;\n } finally {\n isLoading.value = false;\n }\n }\n\n async function restoreSnapshot(snapshotId: string): Promise<Template> {\n isRestoring.value = true;\n try {\n const template = await api.restoreSnapshot(\n options.templateId,\n snapshotId,\n );\n options.onRestore?.(template);\n return template;\n } catch (error) {\n options.onError?.(error as Error);\n throw error;\n } finally {\n isRestoring.value = false;\n }\n }\n\n return {\n snapshots,\n isLoading,\n isRestoring,\n loadSnapshots,\n restoreSnapshot,\n };\n}\n","import type { TestEmailConfig } from \"@templatical/types\";\nimport type { AuthManager } from \"./auth\";\nimport type { ComputedRef, Ref } from \"vue\";\nimport { computed, ref, watch } from \"vue\";\n\n/**\n * Cloud's test-email *configuration* — whether the project has the feature, who\n * may be sent to, and the signature that lets the backend verify that list.\n *\n * Sending itself lives in `createCloudTestEmailProvider`, which plugs into the\n * shared `useTestEmailFeature` seam in `@templatical/editor` alongside a\n * consumer's own sender. Keeping the send body in exactly one place is the point:\n * both editors then drive identical UI, state and error handling, so the sending\n * spinner, the inline error and the success confirmation can't drift apart.\n */\nexport interface UseTestEmailOptions {\n authManager: AuthManager;\n /** Gates reading the config off the auth manager until the JWT has resolved. */\n isAuthReady?: Ref<boolean>;\n}\n\nexport interface UseTestEmailReturn {\n /** Whether the project's token carries a test-email config at all. */\n isEnabled: ComputedRef<boolean>;\n /**\n * Addresses the project permits. Empty until auth resolves — read it\n * reactively, never snapshot it, or it stays empty for the session.\n */\n allowedEmails: ComputedRef<string[]>;\n /** The signature accompanying {@link allowedEmails}, or `null` when disabled. */\n getSignature: () => string | null;\n}\n\nexport function useTestEmail(options: UseTestEmailOptions): UseTestEmailReturn {\n const { authManager, isAuthReady } = options;\n\n const testEmailConfig = ref<TestEmailConfig | null>(null);\n\n if (isAuthReady) {\n watch(\n isAuthReady,\n (ready) => {\n if (ready) {\n testEmailConfig.value = authManager.testEmailConfig;\n }\n },\n { immediate: true },\n );\n }\n\n const isEnabled = computed<boolean>(() => testEmailConfig.value !== null);\n\n const allowedEmails = computed<string[]>(\n () => testEmailConfig.value?.allowedEmails ?? [],\n );\n\n function getSignature(): string | null {\n return testEmailConfig.value?.signature ?? null;\n }\n\n return { isEnabled, allowedEmails, getSignature };\n}\n","import type {\n ExportResult,\n Template,\n TestEmailProvider,\n} from \"@templatical/types\";\nimport type { AuthManager } from \"./auth\";\nimport { ApiClient } from \"./api\";\nimport type { ComputedRef } from \"vue\";\n\nexport interface CreateCloudTestEmailProviderOptions {\n authManager: AuthManager;\n getTemplateId: () => string | null;\n save: () => Promise<Template>;\n exportHtml: (templateId: string) => Promise<ExportResult>;\n /**\n * The project's allowed recipients, from the signed JWT.\n *\n * Taken as a `ComputedRef` rather than an array because it only becomes\n * populated once auth resolves — see the getter note on the returned provider.\n */\n allowedEmails: ComputedRef<string[]>;\n /** The signature that lets the backend verify {@link allowedEmails}. */\n getSignature: () => string | null;\n onBeforeTestEmail?: (html: string) => string | Promise<string>;\n}\n\n/**\n * Templatical Cloud's test-email sender, shaped as a {@link TestEmailProvider}\n * so it plugs into the same editor seam a consumer's own sender would.\n *\n * Two things about it are deliberately unlike a BYO provider:\n *\n * - **It ignores `payload.content` and `payload.allowedRecipients`.** Cloud saves\n * the template, has its backend render the HTML, and derives the allowlist plus\n * its signature from the auth manager. Trusting the echoed payload would swap a\n * server-signed list for an unsigned browser value. The contract is \"send a test\n * of the current template\" — how an adapter obtains the bytes is its business,\n * so this is honest rather than a smell. Don't \"fix\" it.\n * - **It never sets `includeMjml`.** Cloud renders server-side, so the editor\n * should not spend a render pass producing MJML nobody reads.\n */\nexport function createCloudTestEmailProvider(\n options: CreateCloudTestEmailProviderOptions,\n): TestEmailProvider {\n const api = new ApiClient(options.authManager);\n\n return {\n /**\n * A getter, not a snapshot: the allowlist arrives with the JWT, so it starts\n * empty and fills once auth is ready. The editor reads this property inside a\n * computed, which is what makes the trigger appear at that point — reading it\n * once at construction would pin it to `[]` and, because an empty allowlist\n * means \"nobody may be sent to\", hide the button forever.\n */\n get allowedRecipients(): string[] {\n return options.allowedEmails.value;\n },\n\n async send({ recipient }): Promise<void> {\n const signature = options.getSignature();\n if (signature === null) {\n throw new Error(\"Test email is not enabled for this project\");\n }\n\n const templateId = options.getTemplateId();\n if (templateId === null) {\n throw new Error(\"Template must be saved before sending a test email\");\n }\n\n // Save first: the backend renders from the stored template, so sending\n // without this would mail a stale version of what's on screen.\n await options.save();\n\n let { html } = await options.exportHtml(templateId);\n if (options.onBeforeTestEmail) {\n html = await options.onBeforeTestEmail(html);\n }\n\n await api.sendTestEmail(templateId, {\n recipient,\n html,\n allowed_emails: options.allowedEmails.value,\n signature,\n });\n },\n };\n}\n","import type { CustomFont, ExportResult, FontsConfig } from \"@templatical/types\";\nimport { ApiClient } from \"./api\";\nimport type { AuthManager } from \"./auth\";\n\nexport interface UseExportOptions {\n authManager: AuthManager;\n getFontsConfig?: () => FontsConfig | undefined;\n canUseCustomFonts?: () => boolean;\n}\n\nexport interface UseExportReturn {\n exportHtml: (templateId: string) => Promise<ExportResult>;\n getMjmlSource: (templateId: string) => Promise<string>;\n}\n\nexport function useExport(options: UseExportOptions): UseExportReturn {\n const { authManager, getFontsConfig, canUseCustomFonts } = options;\n const api = new ApiClient(authManager);\n\n function getExportFontsPayload(): {\n customFonts: CustomFont[];\n defaultFallback: string;\n } {\n const fontsConfig = getFontsConfig?.();\n const customFontsAllowed = canUseCustomFonts?.() ?? true;\n\n return {\n customFonts:\n customFontsAllowed && fontsConfig?.customFonts\n ? fontsConfig.customFonts\n : [],\n defaultFallback: fontsConfig?.defaultFallback ?? \"Arial, sans-serif\",\n };\n }\n\n async function exportHtml(templateId: string): Promise<ExportResult> {\n const fontsPayload = getExportFontsPayload();\n const result = await api.exportTemplate(templateId, fontsPayload);\n\n return {\n html: result.html,\n mjml: result.mjml,\n };\n }\n\n async function getMjmlSource(templateId: string): Promise<string> {\n const fontsPayload = getExportFontsPayload();\n const result = await api.exportTemplate(templateId, fontsPayload);\n return result.mjml;\n }\n\n return {\n exportHtml,\n getMjmlSource,\n };\n}\n","import type { PlanConfig, PlanFeatures } from \"@templatical/types\";\nimport { ApiClient } from \"./api\";\nimport type { AuthManager } from \"./auth\";\nimport { computed, ref, type ComputedRef, type Ref } from \"vue\";\n\nexport interface UsePlanConfigOptions {\n authManager: AuthManager;\n onError?: (error: Error) => void;\n}\n\nexport interface UsePlanConfigReturn {\n config: Ref<PlanConfig | null>;\n isLoading: Ref<boolean>;\n hasFeature: (feature: keyof PlanFeatures) => boolean;\n features: ComputedRef<PlanFeatures | null>;\n fetchConfig: () => Promise<void>;\n}\n\nexport function usePlanConfig(\n options: UsePlanConfigOptions,\n): UsePlanConfigReturn {\n const { authManager, onError } = options;\n\n const config = ref<PlanConfig | null>(null);\n const isLoading = ref(false);\n\n const apiClient = new ApiClient(authManager);\n\n const features = computed(() => config.value?.features ?? null);\n\n function hasFeature(feature: keyof PlanFeatures): boolean {\n return config.value?.features[feature] ?? false;\n }\n\n async function fetchConfig(): Promise<void> {\n if (isLoading.value) {\n return;\n }\n\n isLoading.value = true;\n\n try {\n config.value = await apiClient.fetchConfig();\n } catch (error) {\n onError?.(\n error instanceof Error\n ? error\n : new Error(\"Failed to fetch config\", { cause: error }),\n );\n } finally {\n isLoading.value = false;\n }\n }\n\n return {\n config,\n isLoading,\n hasFeature,\n features,\n fetchConfig,\n };\n}\n","import type { HealthCheckResult } from \"@templatical/types\";\nimport type { AuthManager } from \"./auth\";\nimport { API_ROUTES } from \"./url-builder\";\n\ninterface HealthCheckOptions {\n authManager?: AuthManager;\n baseUrl?: string;\n}\n\nconst WS_HANDSHAKE_TIMEOUT = 5000;\n\nfunction resolveHealthUrl(options: HealthCheckOptions): string {\n if (options.authManager) {\n return options.authManager.resolveUrl(API_ROUTES.health);\n }\n\n const base = (options.baseUrl ?? \"https://templatical.com\").replace(\n /\\/$/,\n \"\",\n );\n return `${base}${API_ROUTES.health}`;\n}\n\nasync function checkApiAndAuth(\n url: string,\n authManager?: AuthManager,\n): Promise<{\n api: { ok: boolean; latency: number };\n auth: { ok: boolean; error?: string };\n wsConfig?: { host: string; port: number; app_key: string };\n}> {\n const start = performance.now();\n\n try {\n const response = authManager\n ? await authManager.authenticatedFetch(API_ROUTES.health, {\n method: \"GET\",\n headers: { Accept: \"application/json\" },\n })\n : await fetch(url, {\n method: \"GET\",\n headers: { Accept: \"application/json\" },\n });\n\n const latency = Math.round(performance.now() - start);\n\n if (response.status === 401) {\n return {\n api: { ok: true, latency },\n auth: { ok: false, error: \"HTTP 401\" },\n };\n }\n\n if (!response.ok) {\n return {\n api: { ok: false, latency },\n auth: {\n ok: !authManager,\n error: authManager ? `HTTP ${response.status}` : undefined,\n },\n };\n }\n\n const data = await response.json();\n\n return {\n api: { ok: data.status === \"ok\", latency },\n auth: { ok: true },\n wsConfig: data.websocket,\n };\n } catch (error) {\n const latency = Math.round(performance.now() - start);\n\n return {\n api: { ok: false, latency },\n auth: {\n ok: !authManager,\n error: authManager\n ? error instanceof Error\n ? error.message\n : \"Authentication check failed\"\n : undefined,\n },\n };\n }\n}\n\nasync function checkWebSocket(wsConfig?: {\n host: string;\n port: number;\n app_key: string;\n}): Promise<{ ok: boolean; error?: string }> {\n if (!wsConfig?.host || !wsConfig?.app_key) {\n return { ok: false, error: \"WebSocket configuration not available\" };\n }\n\n if (typeof WebSocket === \"undefined\") {\n return {\n ok: false,\n error: \"WebSocket not supported in this environment\",\n };\n }\n\n const protocol = wsConfig.port === 443 ? \"wss\" : \"ws\";\n const url = `${protocol}://${wsConfig.host}:${wsConfig.port}/app/${wsConfig.app_key}?protocol=7&client=js&version=8.4.0-rc2&flash=false`;\n\n return new Promise((resolve) => {\n let ws: WebSocket | null = null;\n\n const timeout = setTimeout(() => {\n ws?.close();\n resolve({ ok: false, error: \"WebSocket connection timed out\" });\n }, WS_HANDSHAKE_TIMEOUT);\n\n try {\n ws = new WebSocket(url);\n } catch (error) {\n // Some browsers throw synchronously from `new WebSocket(...)`\n // (e.g. SecurityError on mixed content, InvalidAccessError on\n // malformed URL). Without this catch the queued timeout would\n // later access `ws` in TDZ and the outer promise would hang.\n clearTimeout(timeout);\n resolve({\n ok: false,\n error:\n error instanceof Error\n ? error.message\n : \"WebSocket connection failed\",\n });\n return;\n }\n\n ws.onopen = () => {\n clearTimeout(timeout);\n ws?.close();\n resolve({ ok: true });\n };\n\n ws.onerror = () => {\n clearTimeout(timeout);\n resolve({ ok: false, error: \"WebSocket connection failed\" });\n };\n });\n}\n\nexport async function performHealthCheck(\n options: HealthCheckOptions = {},\n): Promise<HealthCheckResult> {\n const healthUrl = resolveHealthUrl(options);\n\n const result = await checkApiAndAuth(healthUrl, options.authManager);\n const wsResult = await checkWebSocket(result.wsConfig);\n\n return {\n api: result.api,\n websocket: wsResult,\n auth: result.auth,\n overall: result.api.ok && result.auth.ok,\n };\n}\n","import type { UseEditorReturn } from \"./editor\";\nimport type { McpOperationPayload } from \"@templatical/types\";\nimport { handleOperation } from \"./mcp-operation-handler\";\nimport type { PresenceChannel } from \"pusher-js\";\nimport { watch, type Ref } from \"vue\";\n\nexport interface UseMcpListenerOptions {\n editor: UseEditorReturn;\n channel: Ref<PresenceChannel | null>;\n onOperation?: (payload: McpOperationPayload) => void;\n}\n\nexport function useMcpListener(options: UseMcpListenerOptions): void {\n const { editor, channel, onOperation } = options;\n\n watch(channel, (newChannel, oldChannel) => {\n if (oldChannel) {\n oldChannel.unbind(\"mcp-operation\");\n }\n\n if (newChannel) {\n newChannel.bind(\"mcp-operation\", (payload: McpOperationPayload) => {\n handleOperation(editor, payload);\n onOperation?.(payload);\n });\n }\n });\n}\n"],"mappings":";;;;AAkBA,IAAa,IAAb,MAAa,EAAY;CACvB,OAAwB,mBAAmB;CAE3C,cAAqC;CACrC,YAAiC;CACjC,aAAoC;CACpC,YAAmC;CACnC,cAAqC;CACrC,mBAAmD;CACnD,cAAyC;CACzC;CACA;CACA;CACA;CACA,iBAAiD;CAEjD,OAAwB,uBAAuB;CAE/C,YAAY,GAAoB;EAO9B,AANA,KAAK,MAAM,EAAO,KAClB,KAAK,WAAW,EAAO,WAAW,EAAY,iBAAA,CAAkB,QAC9D,OACA,EACF,GACA,KAAK,iBAAiB,EAAO,kBAAkB,CAAC,GAChD,KAAK,UAAU,EAAO;CACxB;CAEA,WAAW,GAAsB;EAC/B,IAAI,EAAK,WAAW,SAAS,KAAK,EAAK,WAAW,UAAU,GAC1D,OAAO;EAGT,IAAM,IAAiB,EAAK,WAAW,GAAG,IAAI,IAAO,IAAI;EACzD,OAAO,GAAG,KAAK,UAAU;CAC3B;CAEA,IAAI,YAAoB;EACtB,IAAI,CAAC,KAAK,YACR,MAAU,MAAM,oDAAoD;EAEtE,OAAO,KAAK;CACd;CAEA,IAAI,WAAmB;EACrB,IAAI,CAAC,KAAK,WACR,MAAU,MAAM,mDAAmD;EAErE,OAAO,KAAK;CACd;CAEA,IAAI,aAAqB;EACvB,IAAI,CAAC,KAAK,aACR,MAAU,MAAM,qDAAqD;EAEvE,OAAO,KAAK;CACd;CAEA,IAAI,kBAA0C;EAC5C,OAAO,KAAK;CACd;CAEA,IAAI,aAAgC;EAClC,OAAO,KAAK;CACd;CAEA,IAAI,mBAAkC;EACpC,OAAO,KAAK;CACd;CAEA,MAAM,aAA4B;EAChC,MAAM,KAAK,YAAY;CACzB;CAEA,MAAc,cAA+B;EAI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AM,IAAU,GAAY,MAAe;EAKzC,AAJI,KACF,EAAW,OAAO,eAAe,GAG/B,KACF,EAAW,KAAK,kBAAkB,MAAiC;GAEjE,AADA,EAAgB,GAAQ,CAAO,GAC/B,IAAc,CAAO;EACvB,CAAC;CAEL,CAAC;AACH"}
1
+ {"version":3,"file":"cloud-CNpvDuv7.js","names":[],"sources":["../../../../core/src/cloud/auth.ts","../../../../core/src/cloud/url-builder.ts","../../../../core/src/cloud/api.ts","../../../../core/src/cloud/websocket-client.ts","../../../../core/src/cloud/mcp-operation-handler.ts","../../../../core/src/cloud/editor.ts","../../../../core/src/cloud/ai-chat.ts","../../../../core/src/cloud/ai-config.ts","../../../../core/src/cloud/template-scoring.ts","../../../../core/src/cloud/design-reference.ts","../../../../core/src/cloud/comments.ts","../../../../core/src/cloud/comment-listener.ts","../../../../core/src/cloud/collaboration.ts","../../../../core/src/cloud/collaboration-broadcast.ts","../../../../core/src/cloud/web-socket.ts","../../../../core/src/cloud/saved-blocks-provider.ts","../../../../core/src/cloud/snapshots.ts","../../../../core/src/cloud/test-email.ts","../../../../core/src/cloud/test-email-provider.ts","../../../../core/src/cloud/export.ts","../../../../core/src/cloud/plan-config.ts","../../../../core/src/cloud/health-check.ts","../../../../core/src/cloud/mcp-listener.ts"],"sourcesContent":["import type {\n AuthConfig,\n AuthRequestOptions,\n SdkAuthConfig,\n TestEmailConfig,\n TokenData,\n UserConfig,\n} from \"@templatical/types\";\nimport { SdkError } from \"@templatical/types\";\n\nexport type {\n AuthConfig,\n AuthRequestOptions,\n SdkAuthConfig,\n TestEmailConfig,\n UserConfig,\n};\n\nexport class AuthManager {\n private static readonly DEFAULT_BASE_URL = \"https://templatical.com\";\n\n private accessToken: string | null = null;\n private expiresAt: Date | null = null;\n private _projectId: string | null = null;\n private _tenantId: string | null = null;\n private _tenantSlug: string | null = null;\n private _testEmailConfig: TestEmailConfig | null = null;\n private _userConfig: UserConfig | null = null;\n private readonly url: string;\n private readonly baseUrl: string;\n private readonly requestOptions: AuthRequestOptions;\n private readonly onError?: (error: Error) => void;\n private refreshPromise: Promise<string> | null = null;\n\n private static readonly REFRESH_THRESHOLD_MS = 60 * 1000;\n\n constructor(config: AuthConfig) {\n this.url = config.url;\n this.baseUrl = (config.baseUrl ?? AuthManager.DEFAULT_BASE_URL).replace(\n /\\/$/,\n \"\",\n );\n this.requestOptions = config.requestOptions ?? {};\n this.onError = config.onError;\n }\n\n resolveUrl(path: string): string {\n if (path.startsWith(\"http://\") || path.startsWith(\"https://\")) {\n return path;\n }\n\n const normalizedPath = path.startsWith(\"/\") ? path : `/${path}`;\n return `${this.baseUrl}${normalizedPath}`;\n }\n\n get projectId(): string {\n if (!this._projectId) {\n throw new Error(\"Project ID not available. Call initialize() first.\");\n }\n return this._projectId;\n }\n\n get tenantId(): string {\n if (!this._tenantId) {\n throw new Error(\"Tenant ID not available. Call initialize() first.\");\n }\n return this._tenantId;\n }\n\n get tenantSlug(): string {\n if (!this._tenantSlug) {\n throw new Error(\"Tenant slug not available. Call initialize() first.\");\n }\n return this._tenantSlug;\n }\n\n get testEmailConfig(): TestEmailConfig | null {\n return this._testEmailConfig;\n }\n\n get userConfig(): UserConfig | null {\n return this._userConfig;\n }\n\n get accessTokenValue(): string | null {\n return this.accessToken;\n }\n\n async initialize(): Promise<void> {\n await this.ensureToken();\n }\n\n private async ensureToken(): Promise<string> {\n if (this.accessToken && !this.isTokenExpiringSoon()) {\n return this.accessToken;\n }\n return this.refreshToken();\n }\n\n private isTokenExpiringSoon(): boolean {\n if (!this.expiresAt) {\n return true;\n }\n const timeUntilExpiry = this.expiresAt.getTime() - Date.now();\n return timeUntilExpiry < AuthManager.REFRESH_THRESHOLD_MS;\n }\n\n async refreshToken(): Promise<string> {\n if (this.refreshPromise) {\n return this.refreshPromise;\n }\n\n this.refreshPromise = this.performRefresh();\n\n try {\n const token = await this.refreshPromise;\n return token;\n } finally {\n this.refreshPromise = null;\n }\n }\n\n private async performRefresh(): Promise<string> {\n try {\n const method = this.requestOptions.method ?? \"POST\";\n const headers: Record<string, string> = {\n Accept: \"application/json\",\n ...this.requestOptions.headers,\n };\n\n const fetchOptions: RequestInit = {\n method,\n headers,\n credentials: this.requestOptions.credentials ?? \"include\",\n };\n\n if (method === \"POST\" && this.requestOptions.body) {\n headers[\"Content-Type\"] = \"application/json\";\n fetchOptions.body = JSON.stringify(this.requestOptions.body);\n }\n\n const response = await fetch(this.url, fetchOptions);\n\n if (!response.ok) {\n throw new SdkError(\n `Token refresh failed: ${response.status}`,\n response.status,\n );\n }\n\n const data: TokenData = await response.json();\n\n if (!data.token || !data.expires_at || !data.project_id || !data.tenant) {\n throw new Error(\n \"Invalid token response: missing token, expires_at, project_id, or tenant\",\n );\n }\n\n this.accessToken = data.token;\n this.expiresAt = new Date(data.expires_at * 1000);\n this._projectId = data.project_id;\n this._tenantSlug = data.tenant;\n\n if (data.test_email?.allowed_emails && data.test_email?.signature) {\n this._testEmailConfig = {\n allowedEmails: data.test_email.allowed_emails,\n signature: data.test_email.signature,\n };\n } else {\n this._testEmailConfig = null;\n }\n\n if (data.user?.id && data.user?.name && data.user?.signature) {\n this._userConfig = {\n id: data.user.id,\n name: data.user.name,\n signature: data.user.signature,\n };\n } else {\n this._userConfig = null;\n }\n\n return this.accessToken;\n } catch (error) {\n const wrappedError =\n error instanceof Error\n ? error\n : new Error(\"Token refresh failed\", { cause: error });\n this.onError?.(wrappedError);\n throw wrappedError;\n }\n }\n\n async authenticatedFetch(\n url: string,\n options: RequestInit = {},\n ): Promise<Response> {\n const token = await this.ensureToken();\n const resolvedUrl = this.resolveUrl(url);\n\n const makeRequest = async (authToken: string): Promise<Response> => {\n return fetch(resolvedUrl, {\n ...options,\n headers: {\n ...options.headers,\n Authorization: `Bearer ${authToken}`,\n },\n });\n };\n\n let response = await makeRequest(token);\n\n if (response.status === 401) {\n const newToken = await this.refreshToken();\n response = await makeRequest(newToken);\n }\n\n return response;\n }\n}\n\nexport function createSdkAuthManager(\n config: SdkAuthConfig,\n onError?: (error: Error) => void,\n): AuthManager {\n if (config.mode === \"direct\") {\n const baseUrl = (config.baseUrl ?? \"https://templatical.com\").replace(\n /\\/$/,\n \"\",\n );\n\n return new AuthManager({\n url: `${baseUrl}/api/v1/auth/token`,\n baseUrl: config.baseUrl,\n requestOptions: {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: {\n client_id: config.clientId,\n client_secret: config.clientSecret,\n tenant: config.tenant,\n client_type: \"sdk\",\n },\n },\n onError,\n });\n }\n\n return new AuthManager({\n url: config.url,\n baseUrl: config.baseUrl,\n requestOptions: config.requestOptions,\n onError,\n });\n}\n","export function buildUrl(\n template: string,\n params: Record<string, string>,\n): string {\n return template.replace(/\\{(\\w+)\\}/g, (_, key: string) =>\n encodeURIComponent(params[key] ?? \"\"),\n );\n}\n\nconst BASE = \"/api/v1/projects/{project}/tenants/{tenant}\";\nconst TEMPLATE = `${BASE}/templates/{template}`;\nconst AI = `${TEMPLATE}/ai`;\nconst MEDIA = `${BASE}/media`;\nconst FOLDERS = `${MEDIA}/folders`;\nconst MODULES = `${BASE}/saved-modules`;\n\nexport const API_ROUTES = {\n health: \"/api/v1/health\",\n \"projects.config\": `${BASE}/config`,\n \"broadcasting.auth\": `${BASE}/broadcasting/auth`,\n \"templates.store\": `${BASE}/templates`,\n \"templates.show\": `${TEMPLATE}`,\n \"templates.update\": `${TEMPLATE}`,\n \"templates.destroy\": `${TEMPLATE}`,\n \"templates.export\": `${TEMPLATE}/export`,\n \"templates.importFromBeefree\": `${BASE}/templates/import/from-beefree`,\n \"templates.sendTestEmail\": `${TEMPLATE}/send-test-email`,\n \"snapshots.index\": `${TEMPLATE}/snapshots`,\n \"snapshots.store\": `${TEMPLATE}/snapshots`,\n \"snapshots.show\": `${TEMPLATE}/snapshots/{snapshot}`,\n \"snapshots.restore\": `${TEMPLATE}/snapshots/{snapshot}/restore`,\n \"comments.index\": `${TEMPLATE}/comments`,\n \"comments.store\": `${TEMPLATE}/comments`,\n \"comments.update\": `${TEMPLATE}/comments/{comment}`,\n \"comments.destroy\": `${TEMPLATE}/comments/{comment}`,\n \"comments.resolve\": `${TEMPLATE}/comments/{comment}/resolve`,\n \"ai.generate\": `${AI}/generate`,\n \"ai.conversationMessages\": `${AI}/conversation-messages`,\n \"ai.suggestions\": `${AI}/suggestions`,\n \"ai.rewriteText\": `${AI}/rewrite-text`,\n \"ai.score\": `${AI}/score`,\n \"ai.fixFinding\": `${AI}/fix-finding`,\n \"ai.generateFromDesign\": `${AI}/generate-from-design`,\n \"media.upload\": `${MEDIA}/upload`,\n \"media.browse\": `${MEDIA}/browse`,\n \"media.delete\": `${MEDIA}/delete`,\n \"media.move\": `${MEDIA}/move`,\n \"media.update\": `${MEDIA}/{media}`,\n \"media.replace\": `${MEDIA}/{media}/replace`,\n \"media.checkUsage\": `${MEDIA}/check-usage`,\n \"media.frequentlyUsed\": `${MEDIA}/frequently-used`,\n \"media.importFromUrl\": `${MEDIA}/import-from-url`,\n \"folders.index\": `${FOLDERS}`,\n \"folders.store\": `${FOLDERS}`,\n \"folders.update\": `${FOLDERS}/{mediaFolder}`,\n \"folders.destroy\": `${FOLDERS}/{mediaFolder}`,\n \"savedModules.index\": `${MODULES}`,\n \"savedModules.store\": `${MODULES}`,\n \"savedModules.update\": `${MODULES}/{savedModule}`,\n \"savedModules.destroy\": `${MODULES}/{savedModule}`,\n} as const;\n","import type {\n ApiError,\n ApiResponse,\n Comment,\n CustomFont,\n PlanConfig,\n SavedBlock,\n Template,\n TemplateContent,\n TemplateSnapshot,\n} from \"@templatical/types\";\nimport { SdkError } from \"@templatical/types\";\nimport type { Block } from \"@templatical/types\";\nimport type { AuthManager } from \"./auth\";\nimport { API_ROUTES, buildUrl } from \"./url-builder\";\n\nexport class ApiClient {\n constructor(private readonly authManager: AuthManager) {}\n\n private get projectId(): string {\n return this.authManager.projectId;\n }\n\n private get tenantSlug(): string {\n return this.authManager.tenantSlug;\n }\n\n private get baseParams(): Record<string, string> {\n return { project: this.projectId, tenant: this.tenantSlug };\n }\n\n private async request<T>(\n path: string,\n options: RequestInit = {},\n ): Promise<T> {\n const response = await this.authManager.authenticatedFetch(path, {\n ...options,\n headers: {\n \"Content-Type\": \"application/json\",\n Accept: \"application/json\",\n ...options.headers,\n },\n });\n\n if (!response.ok) {\n const error: ApiError = await response.json().catch(() => ({\n message: `HTTP error ${response.status}`,\n }));\n\n const errorMessage = this.extractFirstValidationError(error);\n throw new SdkError(errorMessage, response.status);\n }\n\n if (response.status === 204) {\n return undefined as T;\n }\n\n const json: ApiResponse<T> = await response.json();\n return json.data;\n }\n\n private extractFirstValidationError(error: ApiError): string {\n if (error.errors) {\n const firstField = Object.keys(error.errors)[0];\n if (firstField && error.errors[firstField]?.length > 0) {\n return error.errors[firstField][0];\n }\n }\n return error.message;\n }\n\n async createTemplate(content: TemplateContent): Promise<Template> {\n return this.request<Template>(\n buildUrl(API_ROUTES[\"templates.store\"], this.baseParams),\n {\n method: \"POST\",\n body: JSON.stringify({ content }),\n },\n );\n }\n\n async getTemplate(id: string): Promise<Template> {\n return this.request<Template>(\n buildUrl(API_ROUTES[\"templates.show\"], {\n ...this.baseParams,\n template: id,\n }),\n );\n }\n\n async updateTemplate(\n id: string,\n content: TemplateContent,\n ): Promise<Template> {\n return this.request<Template>(\n buildUrl(API_ROUTES[\"templates.update\"], {\n ...this.baseParams,\n template: id,\n }),\n {\n method: \"PUT\",\n body: JSON.stringify({ content }),\n },\n );\n }\n\n async createSnapshot(\n templateId: string,\n content: TemplateContent,\n ): Promise<TemplateSnapshot> {\n return this.request<TemplateSnapshot>(\n buildUrl(API_ROUTES[\"snapshots.store\"], {\n ...this.baseParams,\n template: templateId,\n }),\n {\n method: \"POST\",\n body: JSON.stringify({ content }),\n },\n );\n }\n\n async deleteTemplate(id: string): Promise<void> {\n return this.request<void>(\n buildUrl(API_ROUTES[\"templates.destroy\"], {\n ...this.baseParams,\n template: id,\n }),\n {\n method: \"DELETE\",\n },\n );\n }\n\n async getSnapshots(templateId: string): Promise<TemplateSnapshot[]> {\n return this.request<TemplateSnapshot[]>(\n buildUrl(API_ROUTES[\"snapshots.index\"], {\n ...this.baseParams,\n template: templateId,\n }),\n );\n }\n\n async restoreSnapshot(\n templateId: string,\n snapshotId: string,\n ): Promise<Template> {\n return this.request<Template>(\n buildUrl(API_ROUTES[\"snapshots.restore\"], {\n ...this.baseParams,\n template: templateId,\n snapshot: snapshotId,\n }),\n {\n method: \"POST\",\n },\n );\n }\n\n async exportTemplate(\n templateId: string,\n fontsPayload?: {\n customFonts: CustomFont[];\n defaultFallback: string;\n },\n ): Promise<{ html: string; mjml: string }> {\n const body = fontsPayload\n ? JSON.stringify({\n custom_fonts: fontsPayload.customFonts,\n default_fallback: fontsPayload.defaultFallback,\n })\n : undefined;\n\n return this.request<{ html: string; mjml: string }>(\n buildUrl(API_ROUTES[\"templates.export\"], {\n ...this.baseParams,\n template: templateId,\n }),\n {\n method: \"POST\",\n body,\n },\n );\n }\n\n async sendTestEmail(\n templateId: string,\n payload: {\n recipient: string;\n html: string;\n allowed_emails: string[];\n signature: string;\n },\n ): Promise<void> {\n await this.request<void>(\n buildUrl(API_ROUTES[\"templates.sendTestEmail\"], {\n ...this.baseParams,\n template: templateId,\n }),\n {\n method: \"POST\",\n body: JSON.stringify(payload),\n },\n );\n }\n\n private commentsUrl(templateId: string, commentId?: string): string {\n if (commentId) {\n return buildUrl(API_ROUTES[\"comments.update\"], {\n ...this.baseParams,\n template: templateId,\n comment: commentId,\n });\n }\n return buildUrl(API_ROUTES[\"comments.index\"], {\n ...this.baseParams,\n template: templateId,\n });\n }\n\n async getComments(templateId: string): Promise<Comment[]> {\n return this.request<Comment[]>(this.commentsUrl(templateId));\n }\n\n async createComment(\n templateId: string,\n data: {\n body: string;\n block_id?: string;\n parent_id?: string;\n user_id: string;\n user_name: string;\n user_signature: string;\n },\n headers?: Record<string, string>,\n ): Promise<Comment> {\n return this.request<Comment>(this.commentsUrl(templateId), {\n method: \"POST\",\n body: JSON.stringify(data),\n headers,\n });\n }\n\n async updateComment(\n templateId: string,\n commentId: string,\n data: {\n body: string;\n user_id: string;\n user_name: string;\n user_signature: string;\n },\n headers?: Record<string, string>,\n ): Promise<Comment> {\n return this.request<Comment>(this.commentsUrl(templateId, commentId), {\n method: \"PUT\",\n body: JSON.stringify(data),\n headers,\n });\n }\n\n async deleteComment(\n templateId: string,\n commentId: string,\n data: {\n user_id: string;\n user_name: string;\n user_signature: string;\n },\n headers?: Record<string, string>,\n ): Promise<void> {\n return this.request<void>(this.commentsUrl(templateId, commentId), {\n method: \"DELETE\",\n body: JSON.stringify(data),\n headers,\n });\n }\n\n async resolveComment(\n templateId: string,\n commentId: string,\n data: {\n user_id: string;\n user_name: string;\n user_signature: string;\n },\n headers?: Record<string, string>,\n ): Promise<Comment> {\n return this.request<Comment>(\n buildUrl(API_ROUTES[\"comments.resolve\"], {\n ...this.baseParams,\n template: templateId,\n comment: commentId,\n }),\n {\n method: \"POST\",\n body: JSON.stringify(data),\n headers,\n },\n );\n }\n\n async fetchConfig(): Promise<PlanConfig> {\n return this.request<PlanConfig>(\n buildUrl(API_ROUTES[\"projects.config\"], this.baseParams),\n );\n }\n\n async listModules(search?: string, category?: string): Promise<SavedBlock[]> {\n const url = buildUrl(API_ROUTES[\"savedModules.index\"], this.baseParams);\n const params = new URLSearchParams();\n if (search) params.set(\"search\", search);\n if (category) params.set(\"category\", category);\n const query = params.size > 0 ? `?${params}` : \"\";\n return this.request<SavedBlock[]>(`${url}${query}`);\n }\n\n async createModule(data: {\n name: string;\n content: Block[];\n category?: string;\n }): Promise<SavedBlock> {\n return this.request<SavedBlock>(\n buildUrl(API_ROUTES[\"savedModules.store\"], this.baseParams),\n {\n method: \"POST\",\n body: JSON.stringify(data),\n },\n );\n }\n\n async updateModule(\n id: string,\n data: Partial<{ name: string; content: Block[]; category: string }>,\n ): Promise<SavedBlock> {\n return this.request<SavedBlock>(\n buildUrl(API_ROUTES[\"savedModules.update\"], {\n ...this.baseParams,\n savedModule: id,\n }),\n {\n method: \"PUT\",\n body: JSON.stringify(data),\n },\n );\n }\n\n async deleteModule(id: string): Promise<void> {\n return this.request<void>(\n buildUrl(API_ROUTES[\"savedModules.destroy\"], {\n ...this.baseParams,\n savedModule: id,\n }),\n {\n method: \"DELETE\",\n },\n );\n }\n}\n","import type { WebSocketServerConfig } from \"@templatical/types\";\nimport type { AuthManager } from \"./auth\";\nimport { API_ROUTES, buildUrl } from \"./url-builder\";\nimport type Pusher from \"pusher-js\";\nimport type { Channel, PresenceChannel } from \"pusher-js\";\n\ntype PusherType = Pusher;\n\nexport interface WebSocketConfig {\n host: string;\n port: number;\n appKey: string;\n}\n\nexport function resolveWebSocketConfig(\n serverConfig: WebSocketServerConfig,\n): WebSocketConfig {\n return {\n host: serverConfig.host,\n port: serverConfig.port,\n appKey: serverConfig.app_key,\n };\n}\n\nexport interface PresenceMember {\n id: string;\n name: string;\n type: \"user\" | \"mcp\";\n}\n\nexport interface WebSocketClientOptions {\n authManager: AuthManager;\n config: WebSocketConfig;\n onError?: (error: Error) => void;\n}\n\nexport class WebSocketClient {\n private pusher: PusherType | null = null;\n private readonly authManager: AuthManager;\n private readonly config: WebSocketConfig;\n private readonly onError?: (error: Error) => void;\n\n constructor(options: WebSocketClientOptions) {\n this.authManager = options.authManager;\n this.config = options.config;\n this.onError = options.onError;\n }\n\n async connect(): Promise<void> {\n if (this.pusher) {\n return;\n }\n\n let Pusher: typeof import(\"pusher-js\").default;\n try {\n ({ default: Pusher } = await import(\"pusher-js\"));\n } catch {\n throw new Error(\n \"Cloud features require the optional peer dependency 'pusher-js'. Install it with: npm install pusher-js\",\n );\n }\n\n const { host, port, appKey } = this.config;\n const authEndpoint = this.authManager.resolveUrl(\n buildUrl(API_ROUTES[\"broadcasting.auth\"], {\n project: this.authManager.projectId,\n tenant: this.authManager.tenantSlug,\n }),\n );\n\n this.pusher = new Pusher(appKey, {\n wsHost: host,\n wsPort: port,\n wssPort: port,\n forceTLS: true,\n disableStats: true,\n enabledTransports: [\"ws\", \"wss\"],\n cluster: \"\",\n channelAuthorization: {\n transport: \"ajax\",\n endpoint: authEndpoint,\n headers: {\n Authorization: `Bearer ${this.authManager.accessTokenValue}`,\n Accept: \"application/json\",\n },\n params: {\n user_id: this.authManager.userConfig?.id ?? \"\",\n user_name: this.authManager.userConfig?.name ?? \"\",\n user_signature: this.authManager.userConfig?.signature ?? \"\",\n },\n },\n });\n\n this.pusher.connection.bind(\"error\", (error: unknown) => {\n this.onError?.(\n error instanceof Error\n ? error\n : new Error(\"WebSocket connection error\"),\n );\n });\n }\n\n subscribePresence(channelName: string): PresenceChannel {\n if (!this.pusher) {\n throw new Error(\"WebSocketClient not connected. Call connect() first.\");\n }\n\n return this.pusher.subscribe(channelName) as PresenceChannel;\n }\n\n unsubscribe(channelName: string): void {\n this.pusher?.unsubscribe(channelName);\n }\n\n getChannel(channelName: string): Channel | undefined {\n return this.pusher?.channel(channelName);\n }\n\n disconnect(): void {\n if (this.pusher) {\n this.pusher.disconnect();\n this.pusher = null;\n }\n }\n\n getSocketId(): string | null {\n return this.pusher?.connection.socket_id ?? null;\n }\n\n get isConnected(): boolean {\n return this.pusher?.connection.state === \"connected\";\n }\n}\n","import type { McpOperationPayload } from \"@templatical/types\";\nimport type {\n Block,\n TemplateContent,\n TemplateSettings,\n} from \"@templatical/types\";\nimport type { UseEditorReturn } from \"./editor\";\n\nexport function handleOperation(\n editor: UseEditorReturn,\n payload: McpOperationPayload,\n): void {\n const { operation, data } = payload;\n\n switch (operation) {\n case \"add_block\":\n editor.addBlock(\n data.block as Block,\n data.section_id as string | undefined,\n data.column_index as number | undefined,\n data.index as number | undefined,\n );\n break;\n\n case \"update_block\":\n editor.updateBlock(\n data.block_id as string,\n data.updates as Partial<Block>,\n );\n break;\n\n case \"delete_block\":\n editor.removeBlock(data.block_id as string);\n break;\n\n case \"move_block\":\n editor.moveBlock(\n data.block_id as string,\n data.index as number,\n data.section_id as string | undefined,\n data.column_index as number | undefined,\n );\n break;\n\n case \"update_settings\":\n editor.updateSettings(data.updates as Partial<TemplateSettings>);\n break;\n\n case \"set_content\":\n editor.setContent(data.content as TemplateContent);\n break;\n\n case \"update_block_style\":\n editor.updateBlock(\n data.block_id as string,\n {\n styles: data.styles,\n } as Partial<Block>,\n );\n break;\n }\n}\n","import type {\n EditorState,\n Template,\n TemplateDefaults,\n UiTheme,\n ViewportSize,\n} from \"@templatical/types\";\nimport { SdkError } from \"@templatical/types\";\nimport { ApiClient } from \"./api\";\nimport type { AuthManager } from \"./auth\";\nimport type {\n Block,\n ColumnLayout,\n TemplateContent,\n TemplateSettings,\n} from \"@templatical/types\";\nimport { createDefaultTemplateContent } from \"@templatical/types\";\nimport { computed, reactive, readonly, type DeepReadonly, type Ref } from \"vue\";\n\nfunction getColumnCount(layout: ColumnLayout): number {\n if (layout === \"1\") return 1;\n if (layout === \"3\") return 3;\n return 2;\n}\n\nexport interface UseEditorOptions {\n authManager: AuthManager;\n defaultFontFamily?: string;\n templateDefaults?: TemplateDefaults;\n onError?: (error: Error) => void;\n lockedBlocks?: Ref<Map<string, unknown>>;\n}\n\nexport interface UseEditorReturn {\n state: DeepReadonly<EditorState>;\n content: Ref<TemplateContent>;\n selectedBlock: Ref<Block | null>;\n setContent: (content: TemplateContent, markDirty?: boolean) => void;\n selectBlock: (blockId: string | null) => void;\n setViewport: (viewport: ViewportSize) => void;\n setDarkMode: (darkMode: boolean) => void;\n setPreviewMode: (previewMode: boolean) => void;\n setUiTheme: (theme: UiTheme) => void;\n updateBlock: (blockId: string, updates: Partial<Block>) => void;\n updateSettings: (updates: Partial<TemplateSettings>) => void;\n addBlock: (\n block: Block,\n targetSectionId?: string,\n columnIndex?: number,\n index?: number,\n ) => void;\n removeBlock: (blockId: string) => void;\n moveBlock: (\n blockId: string,\n newIndex: number,\n targetSectionId?: string,\n columnIndex?: number,\n ) => void;\n savedBlockIds: Ref<Set<string>>;\n isBlockLocked: (blockId: string) => boolean;\n findBlockLocation: (blockId: string) => {\n targetSectionId?: string;\n columnIndex?: number;\n index: number;\n } | null;\n create: (content?: TemplateContent) => Promise<Template>;\n load: (templateId: string) => Promise<Template>;\n save: () => Promise<Template>;\n createSnapshot: () => Promise<void>;\n hasTemplate: () => boolean;\n markDirty: () => void;\n}\n\nexport function useEditor(options: UseEditorOptions): UseEditorReturn {\n const api = new ApiClient(options.authManager);\n\n const state = reactive<EditorState>({\n template: null,\n content: createDefaultTemplateContent(\n options.defaultFontFamily,\n options.templateDefaults,\n ),\n selectedBlockId: null,\n viewport: \"desktop\",\n darkMode: false,\n previewMode: false,\n isDirty: false,\n isSaving: false,\n isLoading: false,\n uiTheme: \"auto\",\n });\n\n const content = computed({\n get: () => state.content,\n set: (value: TemplateContent) => {\n state.content = value;\n state.isDirty = true;\n },\n });\n\n const selectedBlock = computed(() => {\n if (!state.selectedBlockId) return null;\n return findBlockById(state.content.blocks, state.selectedBlockId);\n });\n\n const savedBlockIds = computed<Set<string>>(() => {\n const ids = new Set<string>();\n const blocks = state.template?.content?.blocks;\n if (!blocks) {\n return ids;\n }\n for (const block of blocks) {\n ids.add(block.id);\n if (block.type === \"section\") {\n for (const column of block.children) {\n for (const child of column) {\n ids.add(child.id);\n }\n }\n }\n }\n return ids;\n });\n\n function findBlockById(blocks: Block[], id: string): Block | null {\n for (const block of blocks) {\n if (block.id === id) return block;\n if (block.type === \"section\") {\n for (const column of block.children) {\n const found = findBlockById(column, id);\n if (found) return found;\n }\n }\n }\n return null;\n }\n\n function findBlockParent(\n blocks: Block[],\n id: string,\n parent: {\n blocks: Block[];\n sectionId?: string;\n columnIndex?: number;\n } = { blocks },\n ): { blocks: Block[]; sectionId?: string; columnIndex?: number } | null {\n for (let i = 0; i < blocks.length; i++) {\n const block = blocks[i];\n if (block.id === id) return parent;\n if (block.type === \"section\") {\n for (let colIdx = 0; colIdx < block.children.length; colIdx++) {\n const result = findBlockParent(block.children[colIdx], id, {\n blocks: block.children[colIdx],\n sectionId: block.id,\n columnIndex: colIdx,\n });\n if (result) return result;\n }\n }\n }\n return null;\n }\n\n function isBlockLocked(blockId: string): boolean {\n return options.lockedBlocks?.value.has(blockId) ?? false;\n }\n\n function setContent(newContent: TemplateContent, markDirty = true): void {\n state.content = newContent;\n if (markDirty) {\n state.isDirty = true;\n }\n }\n\n function selectBlock(blockId: string | null): void {\n if (blockId && isBlockLocked(blockId)) {\n return;\n }\n state.selectedBlockId = blockId;\n }\n\n function setViewport(viewport: ViewportSize): void {\n state.viewport = viewport;\n }\n\n function setDarkMode(darkMode: boolean): void {\n state.darkMode = darkMode;\n }\n\n function setUiTheme(theme: UiTheme): void {\n state.uiTheme = theme;\n }\n\n function setPreviewMode(previewMode: boolean): void {\n state.previewMode = previewMode;\n if (previewMode) {\n state.selectedBlockId = null;\n }\n }\n\n function updateBlock(blockId: string, updates: Partial<Block>): void {\n if (isBlockLocked(blockId)) {\n return;\n }\n const block = findBlockById(state.content.blocks, blockId);\n if (block) {\n Object.assign(block, updates);\n state.isDirty = true;\n }\n }\n\n function updateSettings(updates: Partial<TemplateSettings>): void {\n state.content.settings = { ...state.content.settings, ...updates };\n state.isDirty = true;\n }\n\n function addBlock(\n block: Block,\n targetSectionId?: string,\n columnIndex = 0,\n index?: number,\n ): void {\n if (targetSectionId) {\n const section = findBlockById(state.content.blocks, targetSectionId);\n if (section && section.type === \"section\") {\n section.children[columnIndex] = section.children[columnIndex] || [];\n const targetArray = section.children[columnIndex];\n if (index !== undefined && index < targetArray.length) {\n targetArray.splice(index, 0, block);\n } else {\n targetArray.push(block);\n }\n }\n } else {\n if (index !== undefined && index < state.content.blocks.length) {\n state.content.blocks.splice(index, 0, block);\n } else {\n state.content.blocks.push(block);\n }\n }\n state.isDirty = true;\n }\n\n function removeBlock(blockId: string): void {\n if (isBlockLocked(blockId)) {\n return;\n }\n const parent = findBlockParent(state.content.blocks, blockId);\n if (parent) {\n const index = parent.blocks.findIndex((b) => b.id === blockId);\n if (index !== -1) {\n parent.blocks.splice(index, 1);\n if (state.selectedBlockId === blockId) {\n state.selectedBlockId = null;\n }\n state.isDirty = true;\n }\n }\n }\n\n function moveBlock(\n blockId: string,\n newIndex: number,\n targetSectionId?: string,\n columnIndex = 0,\n ): void {\n const parent = findBlockParent(state.content.blocks, blockId);\n if (!parent) return;\n\n const oldIndex = parent.blocks.findIndex((b) => b.id === blockId);\n if (oldIndex === -1) return;\n\n // Resolve target before mutating the source — otherwise an invalid\n // targetSectionId (stale/deleted id, non-section block, or out-of-range\n // columnIndex) leaves the block spliced-out and unrecoverable. Reachable\n // via untrusted remote move_block payloads (MCP/collaboration), which take\n // no history snapshot, so a dropped block can't even be undone.\n let targetArray: Block[];\n if (targetSectionId) {\n const section = findBlockById(state.content.blocks, targetSectionId);\n if (!section || section.type !== \"section\") return;\n if (columnIndex < 0 || columnIndex >= getColumnCount(section.columns)) {\n return;\n }\n section.children[columnIndex] = section.children[columnIndex] || [];\n targetArray = section.children[columnIndex];\n } else {\n targetArray = state.content.blocks;\n }\n\n const [block] = parent.blocks.splice(oldIndex, 1);\n targetArray.splice(newIndex, 0, block);\n\n state.isDirty = true;\n }\n\n async function create(content?: TemplateContent): Promise<Template> {\n state.isLoading = true;\n try {\n if (content) {\n state.content = content;\n }\n const template = await api.createTemplate(state.content);\n state.template = template;\n state.isDirty = false;\n return template;\n } catch (error) {\n options.onError?.(error as Error);\n throw error;\n } finally {\n state.isLoading = false;\n }\n }\n\n async function load(templateId: string): Promise<Template> {\n state.isLoading = true;\n try {\n const template = await api.getTemplate(templateId);\n state.template = template;\n state.content = template.content;\n state.isDirty = false;\n return template;\n } catch (error) {\n options.onError?.(error as Error);\n throw error;\n } finally {\n state.isLoading = false;\n }\n }\n\n async function save(): Promise<Template> {\n if (!state.template?.id) {\n throw new SdkError(\n \"No template loaded. Call create() or load() before saving.\",\n );\n }\n\n state.isSaving = true;\n try {\n const template = await api.updateTemplate(\n state.template.id,\n state.content,\n );\n state.template = template;\n state.isDirty = false;\n return template;\n } catch (error) {\n options.onError?.(error as Error);\n throw error;\n } finally {\n state.isSaving = false;\n }\n }\n\n async function createSnapshot(): Promise<void> {\n if (!state.template?.id) {\n return;\n }\n\n try {\n await api.createSnapshot(state.template.id, state.content);\n } catch (error) {\n options.onError?.(error as Error);\n throw error;\n }\n }\n\n function hasTemplate(): boolean {\n return state.template?.id !== undefined;\n }\n\n function markDirty(): void {\n state.isDirty = true;\n }\n\n function findBlockLocation(blockId: string): {\n targetSectionId?: string;\n columnIndex?: number;\n index: number;\n } | null {\n const parent = findBlockParent(state.content.blocks, blockId);\n if (!parent) return null;\n const index = parent.blocks.findIndex((b) => b.id === blockId);\n if (index === -1) return null;\n return {\n targetSectionId: parent.sectionId,\n columnIndex: parent.columnIndex,\n index,\n };\n }\n\n return {\n state: readonly(state),\n content,\n selectedBlock,\n savedBlockIds,\n isBlockLocked,\n findBlockLocation,\n setContent,\n selectBlock,\n setViewport,\n setDarkMode,\n setUiTheme,\n setPreviewMode,\n updateBlock,\n updateSettings,\n addBlock,\n removeBlock,\n moveBlock,\n create,\n load,\n save,\n createSnapshot,\n hasTemplate,\n markDirty,\n };\n}\n","import type { AiChatMessage } from \"@templatical/types\";\nimport type { AuthManager } from \"./auth\";\nimport { API_ROUTES, buildUrl } from \"./url-builder\";\nimport type { MergeTag, TemplateContent } from \"@templatical/types\";\nimport { ref } from \"vue\";\n\nexport interface UseAiChatOptions {\n authManager: AuthManager;\n getTemplateId: () => string | null;\n onApply?: (content: TemplateContent) => void;\n onError?: (error: Error) => void;\n}\n\nexport interface UseAiChatReturn {\n messages: ReturnType<typeof ref<AiChatMessage[]>>;\n isGenerating: ReturnType<typeof ref<boolean>>;\n isLoadingHistory: ReturnType<typeof ref<boolean>>;\n isLastChangeReverted: ReturnType<typeof ref<boolean>>;\n lastApplyMessageId: ReturnType<typeof ref<string | null>>;\n error: ReturnType<typeof ref<string | null>>;\n failedPrompt: ReturnType<typeof ref<string | null>>;\n suggestions: ReturnType<typeof ref<string[]>>;\n isLoadingSuggestions: ReturnType<typeof ref<boolean>>;\n sendPrompt: (\n prompt: string,\n currentContent: TemplateContent,\n mergeTags: MergeTag[],\n ) => Promise<TemplateContent | null>;\n toggleLastRevert: () => void;\n loadConversation: () => Promise<void>;\n loadSuggestions: (\n currentContent: TemplateContent,\n mergeTags: MergeTag[],\n ) => Promise<void>;\n clearChat: () => void;\n}\n\nlet messageIdCounter = 0;\n\nfunction generateMessageId(): string {\n return `msg_${Date.now()}_${++messageIdCounter}`;\n}\n\nexport function useAiChat(options: UseAiChatOptions): UseAiChatReturn {\n const { authManager, getTemplateId, onApply, onError } = options;\n\n const messages = ref<AiChatMessage[]>([]);\n const isGenerating = ref(false);\n const isLoadingHistory = ref(false);\n const error = ref<string | null>(null);\n const failedPrompt = ref<string | null>(null);\n const conversationId = ref<string | null>(null);\n const lastApplyMessageId = ref<string | null>(null);\n const lastPreviousContent = ref<TemplateContent | null>(null);\n const lastAppliedContent = ref<TemplateContent | null>(null);\n const isLastChangeReverted = ref(false);\n const suggestions = ref<string[]>([]);\n const isLoadingSuggestions = ref(false);\n\n function updateMessage(msgId: string, updates: Partial<AiChatMessage>): void {\n const idx = messages.value.findIndex((m) => m.id === msgId);\n if (idx === -1) {\n return;\n }\n\n const updated = { ...messages.value[idx], ...updates };\n messages.value = [\n ...messages.value.slice(0, idx),\n updated,\n ...messages.value.slice(idx + 1),\n ];\n }\n\n async function loadConversation(): Promise<void> {\n const templateId = getTemplateId();\n if (!templateId) {\n return;\n }\n\n isLoadingHistory.value = true;\n\n try {\n const url = buildUrl(API_ROUTES[\"ai.conversationMessages\"], {\n project: authManager.projectId,\n tenant: authManager.tenantSlug,\n template: templateId,\n });\n\n const response = await authManager.authenticatedFetch(url, {\n method: \"GET\",\n headers: {\n Accept: \"application/json\",\n },\n });\n\n if (!response.ok) {\n return;\n }\n\n const data = await response.json();\n\n if (data.conversation_id) {\n conversationId.value = data.conversation_id;\n }\n\n if (Array.isArray(data.data) && data.data.length > 0) {\n messages.value = data.data.map(\n (msg: {\n id: string;\n role: \"user\" | \"assistant\";\n content: string;\n created_at: string;\n }) => ({\n id: msg.id,\n role: msg.role,\n content: msg.content,\n timestamp: new Date(msg.created_at).getTime(),\n }),\n );\n }\n } catch {\n // Silently fail - chat will start fresh\n } finally {\n isLoadingHistory.value = false;\n }\n }\n\n async function loadSuggestions(\n currentContent: TemplateContent,\n mergeTags: MergeTag[],\n ): Promise<void> {\n const templateId = getTemplateId();\n if (!templateId) {\n return;\n }\n\n isLoadingSuggestions.value = true;\n\n try {\n const url = buildUrl(API_ROUTES[\"ai.suggestions\"], {\n project: authManager.projectId,\n tenant: authManager.tenantSlug,\n template: templateId,\n });\n\n const response = await authManager.authenticatedFetch(url, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Accept: \"text/event-stream\",\n },\n body: JSON.stringify({\n current_content: currentContent,\n merge_tags: mergeTags.map((p) => ({\n label: p.label,\n value: p.value,\n })),\n }),\n });\n\n if (!response.ok) {\n return;\n }\n\n const reader = response.body?.getReader();\n if (!reader) {\n return;\n }\n\n const decoder = new TextDecoder();\n let buffer = \"\";\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n\n buffer += decoder.decode(value, { stream: true });\n\n const lines = buffer.split(\"\\n\");\n buffer = lines.pop() ?? \"\";\n\n for (const line of lines) {\n if (!line.startsWith(\"data: \")) {\n continue;\n }\n\n let event;\n try {\n event = JSON.parse(line.slice(6));\n } catch {\n continue;\n }\n\n if (event.type === \"done\" && Array.isArray(event.suggestions)) {\n suggestions.value = event.suggestions.slice(0, 3);\n }\n }\n }\n } catch {\n // Silently fail - suggestions are non-critical\n } finally {\n isLoadingSuggestions.value = false;\n }\n }\n\n async function sendPrompt(\n prompt: string,\n currentContent: TemplateContent,\n mergeTags: MergeTag[],\n ): Promise<TemplateContent | null> {\n const templateId = getTemplateId();\n if (!templateId) {\n throw new Error(\"Template must be saved before using AI generation\");\n }\n\n isGenerating.value = true;\n error.value = null;\n failedPrompt.value = null;\n suggestions.value = [];\n\n const userMsgId = generateMessageId();\n messages.value = [\n ...messages.value,\n {\n id: userMsgId,\n role: \"user\",\n content: prompt,\n timestamp: Date.now(),\n },\n ];\n\n const assistantMsgId = generateMessageId();\n messages.value = [\n ...messages.value,\n {\n id: assistantMsgId,\n role: \"assistant\",\n content: \"\",\n timestamp: Date.now(),\n },\n ];\n\n try {\n const url = buildUrl(API_ROUTES[\"ai.generate\"], {\n project: authManager.projectId,\n tenant: authManager.tenantSlug,\n template: templateId,\n });\n\n const response = await authManager.authenticatedFetch(url, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Accept: \"text/event-stream\",\n },\n body: JSON.stringify({\n prompt,\n current_content: currentContent,\n merge_tags: mergeTags.map((p) => ({\n label: p.label,\n value: p.value,\n })),\n conversation_id: conversationId.value,\n }),\n });\n\n if (!response.ok) {\n const errorData = await response.json().catch(() => null);\n if (response.status === 403) {\n throw new Error(\"ai_generation_not_available\");\n }\n throw new Error(errorData?.message || \"Failed to generate template\");\n }\n\n const reader = response.body?.getReader();\n if (!reader) {\n throw new Error(\"Failed to read stream\");\n }\n\n const decoder = new TextDecoder();\n let buffer = \"\";\n let result: TemplateContent | null = null;\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n\n buffer += decoder.decode(value, { stream: true });\n\n const lines = buffer.split(\"\\n\");\n buffer = lines.pop() ?? \"\";\n\n for (const line of lines) {\n if (!line.startsWith(\"data: \")) {\n continue;\n }\n\n const jsonStr = line.slice(6);\n\n let event;\n try {\n event = JSON.parse(jsonStr);\n } catch {\n continue;\n }\n\n if (event.type === \"text\") {\n updateMessage(assistantMsgId, {\n content:\n (messages.value.find((m) => m.id === assistantMsgId)\n ?.content ?? \"\") + event.text,\n });\n } else if (event.type === \"error\") {\n throw new Error(event.message || \"Failed to generate template\");\n } else if (event.type === \"done\") {\n if (event.conversation_id) {\n conversationId.value = event.conversation_id;\n }\n\n updateMessage(assistantMsgId, {\n content: event.text,\n });\n\n result = event.content ?? null;\n\n if (result) {\n lastPreviousContent.value = currentContent;\n lastAppliedContent.value = result;\n lastApplyMessageId.value = assistantMsgId;\n isLastChangeReverted.value = false;\n onApply?.(result);\n } else {\n error.value = \"ai_apply_failed\";\n }\n }\n }\n }\n } finally {\n // Release the underlying network resource even on early exit.\n // Without this, throwing out of the loop (e.g. on an `error` SSE\n // event) leaves the socket and read buffer attached until GC.\n reader.cancel().catch(() => {});\n }\n\n return result;\n } catch (err) {\n const wrappedError =\n err instanceof Error\n ? err\n : new Error(\"Failed to generate template\", { cause: err });\n error.value = wrappedError.message;\n failedPrompt.value = prompt;\n onError?.(wrappedError);\n\n messages.value = messages.value.filter(\n (m) => m.id !== userMsgId && m.id !== assistantMsgId,\n );\n\n return null;\n } finally {\n isGenerating.value = false;\n }\n }\n\n function toggleLastRevert(): void {\n if (isLastChangeReverted.value) {\n if (lastAppliedContent.value) {\n onApply?.(lastAppliedContent.value);\n }\n isLastChangeReverted.value = false;\n } else {\n if (lastPreviousContent.value) {\n onApply?.(lastPreviousContent.value);\n }\n isLastChangeReverted.value = true;\n }\n }\n\n function clearChat(): void {\n messages.value = [];\n conversationId.value = null;\n error.value = null;\n lastApplyMessageId.value = null;\n lastPreviousContent.value = null;\n lastAppliedContent.value = null;\n isLastChangeReverted.value = false;\n }\n\n return {\n messages,\n isGenerating,\n isLoadingHistory,\n isLastChangeReverted,\n lastApplyMessageId,\n error,\n failedPrompt,\n suggestions,\n isLoadingSuggestions,\n sendPrompt,\n toggleLastRevert,\n loadConversation,\n loadSuggestions,\n clearChat,\n };\n}\n","import type { AiConfig } from \"@templatical/types\";\nimport { computed, type ComputedRef } from \"vue\";\n\nexport interface UseAiConfigReturn {\n isFeatureEnabled: (feature: keyof AiConfig) => boolean;\n hasAnyMenuFeature: ComputedRef<boolean>;\n}\n\nexport function useAiConfig(config?: AiConfig | false): UseAiConfigReturn {\n function isFeatureEnabled(feature: keyof AiConfig): boolean {\n if (config === false) {\n return false;\n }\n\n return config?.[feature] !== false;\n }\n\n const hasAnyMenuFeature = computed(\n () =>\n isFeatureEnabled(\"chat\") ||\n isFeatureEnabled(\"scoring\") ||\n isFeatureEnabled(\"designToTemplate\"),\n );\n\n return {\n isFeatureEnabled,\n hasAnyMenuFeature,\n };\n}\n","import type {\n ScoringCategory,\n ScoringFinding,\n ScoringResult,\n} from \"@templatical/types\";\nimport type { AuthManager } from \"./auth\";\nimport { API_ROUTES, buildUrl } from \"./url-builder\";\nimport type { MergeTag, TemplateContent } from \"@templatical/types\";\nimport { ref } from \"vue\";\n\nexport interface UseTemplateScoringOptions {\n authManager: AuthManager;\n getTemplateId: () => string | null;\n}\n\nexport interface UseTemplateScoringReturn {\n isScoring: ReturnType<typeof ref<boolean>>;\n scoringResult: ReturnType<typeof ref<ScoringResult | null>>;\n error: ReturnType<typeof ref<string | null>>;\n fixingFindingId: ReturnType<typeof ref<string | null>>;\n fixStreamingText: ReturnType<typeof ref<string>>;\n fixError: ReturnType<typeof ref<string | null>>;\n score: (\n content: TemplateContent,\n mergeTags: MergeTag[],\n ) => Promise<ScoringResult | null>;\n fixFinding: (\n blockContent: string,\n finding: ScoringFinding,\n mergeTags: MergeTag[],\n ) => Promise<string | null>;\n removeFinding: (category: ScoringCategory, findingId: string) => void;\n reset: () => void;\n}\n\nexport function useTemplateScoring(\n options: UseTemplateScoringOptions,\n): UseTemplateScoringReturn {\n const { authManager, getTemplateId } = options;\n\n const isScoring = ref(false);\n const scoringResult = ref<ScoringResult | null>(null);\n const error = ref<string | null>(null);\n const fixingFindingId = ref<string | null>(null);\n const fixStreamingText = ref(\"\");\n const fixError = ref<string | null>(null);\n\n async function score(\n content: TemplateContent,\n mergeTags: MergeTag[],\n ): Promise<ScoringResult | null> {\n const templateId = getTemplateId();\n if (!templateId) {\n return null;\n }\n\n isScoring.value = true;\n error.value = null;\n scoringResult.value = null;\n\n try {\n const url = buildUrl(API_ROUTES[\"ai.score\"], {\n project: authManager.projectId,\n tenant: authManager.tenantSlug,\n template: templateId,\n });\n\n const response = await authManager.authenticatedFetch(url, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Accept: \"text/event-stream\",\n },\n body: JSON.stringify({\n current_content: content,\n merge_tags: mergeTags.map((p) => ({\n label: p.label,\n value: p.value,\n })),\n }),\n });\n\n if (!response.ok) {\n if (response.status === 403) {\n throw new Error(\"ai_generation_not_available\");\n }\n const errorData = await response.json().catch(() => null);\n throw new Error(errorData?.message || \"Failed to score template\");\n }\n\n const reader = response.body?.getReader();\n if (!reader) {\n throw new Error(\"Failed to read stream\");\n }\n\n const decoder = new TextDecoder();\n let buffer = \"\";\n let result: ScoringResult | null = null;\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n\n buffer += decoder.decode(value, { stream: true });\n\n const lines = buffer.split(\"\\n\");\n buffer = lines.pop() ?? \"\";\n\n for (const line of lines) {\n if (!line.startsWith(\"data: \")) {\n continue;\n }\n\n let event;\n try {\n event = JSON.parse(line.slice(6));\n } catch {\n continue;\n }\n\n if (event.type === \"error\") {\n throw new Error(event.message || \"Failed to score template\");\n }\n\n if (event.type === \"done\") {\n result = event.result ?? null;\n }\n }\n }\n\n if (result) {\n for (const [category, categoryData] of Object.entries(\n result.categories,\n )) {\n for (const finding of categoryData.findings) {\n finding.category = category as ScoringCategory;\n }\n }\n }\n\n scoringResult.value = result;\n return result;\n } catch (err) {\n error.value =\n err instanceof Error ? err.message : \"Failed to score template\";\n return null;\n } finally {\n isScoring.value = false;\n }\n }\n\n async function fixFinding(\n blockContent: string,\n finding: ScoringFinding,\n mergeTags: MergeTag[],\n ): Promise<string | null> {\n const templateId = getTemplateId();\n if (!templateId) {\n return null;\n }\n\n fixingFindingId.value = finding.id;\n fixStreamingText.value = \"\";\n fixError.value = null;\n\n try {\n const url = buildUrl(API_ROUTES[\"ai.fixFinding\"], {\n project: authManager.projectId,\n tenant: authManager.tenantSlug,\n template: templateId,\n });\n\n const response = await authManager.authenticatedFetch(url, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Accept: \"text/event-stream\",\n },\n body: JSON.stringify({\n content: blockContent,\n finding: {\n id: finding.id,\n message: finding.message,\n suggestion: finding.suggestion,\n category: finding.category,\n },\n merge_tags: mergeTags.map((p) => ({\n label: p.label,\n value: p.value,\n })),\n }),\n });\n\n if (!response.ok) {\n if (response.status === 403) {\n throw new Error(\"ai_generation_not_available\");\n }\n const errorData = await response.json().catch(() => null);\n throw new Error(errorData?.message || \"Failed to fix finding\");\n }\n\n const reader = response.body?.getReader();\n if (!reader) {\n throw new Error(\"Failed to read stream\");\n }\n\n const decoder = new TextDecoder();\n let buffer = \"\";\n let result: string | null = null;\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n\n buffer += decoder.decode(value, { stream: true });\n\n const lines = buffer.split(\"\\n\");\n buffer = lines.pop() ?? \"\";\n\n for (const line of lines) {\n if (!line.startsWith(\"data: \")) {\n continue;\n }\n\n let event;\n try {\n event = JSON.parse(line.slice(6));\n } catch {\n continue;\n }\n\n if (event.type === \"text\") {\n fixStreamingText.value += event.text;\n } else if (event.type === \"error\") {\n throw new Error(event.message || \"Failed to fix finding\");\n } else if (event.type === \"done\") {\n result = event.content ?? null;\n }\n }\n }\n\n return result;\n } catch (err) {\n fixError.value =\n err instanceof Error ? err.message : \"Failed to fix finding\";\n return null;\n } finally {\n fixingFindingId.value = null;\n }\n }\n\n function removeFinding(category: ScoringCategory, findingId: string): void {\n if (!scoringResult.value) {\n return;\n }\n\n const cat = scoringResult.value.categories[category];\n if (!cat) {\n return;\n }\n\n cat.findings = cat.findings.filter((f) => f.id !== findingId);\n }\n\n function reset(): void {\n isScoring.value = false;\n scoringResult.value = null;\n error.value = null;\n fixingFindingId.value = null;\n fixStreamingText.value = \"\";\n fixError.value = null;\n }\n\n return {\n isScoring,\n scoringResult,\n error,\n fixingFindingId,\n fixStreamingText,\n fixError,\n score,\n fixFinding,\n removeFinding,\n reset,\n };\n}\n","import type { AuthManager } from \"./auth\";\nimport { API_ROUTES, buildUrl } from \"./url-builder\";\nimport type { TemplateContent } from \"@templatical/types\";\nimport { ref } from \"vue\";\n\nexport interface UseDesignReferenceOptions {\n authManager: AuthManager;\n getTemplateId: () => string | null;\n onApply?: (content: TemplateContent) => void;\n onError?: (error: Error) => void;\n}\n\nexport interface UseDesignReferenceReturn {\n isGenerating: ReturnType<typeof ref<boolean>>;\n error: ReturnType<typeof ref<string | null>>;\n generate: (input: DesignReferenceInput) => Promise<TemplateContent | null>;\n reset: () => void;\n}\n\nexport interface DesignReferenceInput {\n prompt?: string;\n imageUpload?: File;\n pdfUpload?: File;\n}\n\nexport function useDesignReference(\n options: UseDesignReferenceOptions,\n): UseDesignReferenceReturn {\n const { authManager, getTemplateId, onApply, onError } = options;\n\n const isGenerating = ref(false);\n const error = ref<string | null>(null);\n\n async function generate(\n input: DesignReferenceInput,\n ): Promise<TemplateContent | null> {\n const templateId = getTemplateId();\n if (!templateId) {\n throw new Error(\"Template must be saved before using design reference\");\n }\n\n isGenerating.value = true;\n error.value = null;\n\n try {\n const formData = new FormData();\n\n if (input.prompt) {\n formData.append(\"prompt\", input.prompt);\n }\n\n if (input.imageUpload) {\n formData.append(\"image_upload\", input.imageUpload);\n }\n\n if (input.pdfUpload) {\n formData.append(\"pdf_upload\", input.pdfUpload);\n }\n\n const url = buildUrl(API_ROUTES[\"ai.generateFromDesign\"], {\n project: authManager.projectId,\n tenant: authManager.tenantSlug,\n template: templateId,\n });\n\n const response = await authManager.authenticatedFetch(url, {\n method: \"POST\",\n headers: {\n Accept: \"text/event-stream\",\n },\n body: formData,\n });\n\n if (!response.ok) {\n const errorData = await response.json().catch(() => null);\n if (response.status === 403) {\n throw new Error(\"ai_generation_not_available\");\n }\n throw new Error(\n errorData?.message || \"Failed to generate template from design\",\n );\n }\n\n const reader = response.body?.getReader();\n if (!reader) {\n throw new Error(\"Failed to read stream\");\n }\n\n const decoder = new TextDecoder();\n let buffer = \"\";\n let result: TemplateContent | null = null;\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n\n buffer += decoder.decode(value, { stream: true });\n\n const lines = buffer.split(\"\\n\");\n buffer = lines.pop() ?? \"\";\n\n for (const line of lines) {\n if (!line.startsWith(\"data: \")) {\n continue;\n }\n\n const jsonStr = line.slice(6);\n\n let event;\n try {\n event = JSON.parse(jsonStr);\n } catch {\n continue;\n }\n\n if (event.type === \"error\") {\n throw new Error(\n event.message || \"Failed to generate template from design\",\n );\n }\n\n if (event.type === \"done\") {\n result = event.content ?? null;\n\n if (result) {\n onApply?.(result);\n }\n }\n }\n }\n\n return result;\n } catch (err) {\n const wrappedError =\n err instanceof Error\n ? err\n : new Error(\"Failed to generate template from design\", {\n cause: err,\n });\n error.value = wrappedError.message;\n onError?.(wrappedError);\n\n return null;\n } finally {\n isGenerating.value = false;\n }\n }\n\n function reset(): void {\n isGenerating.value = false;\n error.value = null;\n }\n\n return {\n isGenerating,\n error,\n generate,\n reset,\n };\n}\n","import type {\n Comment,\n CommentEvent,\n CommentThread,\n UserConfig,\n} from \"@templatical/types\";\nimport { ApiClient } from \"./api\";\nimport type { AuthManager } from \"./auth\";\nimport { computed, ref, type ComputedRef, type Ref } from \"vue\";\n\nexport interface UseCommentsOptions {\n authManager: AuthManager;\n getTemplateId: () => string | null;\n getSocketId?: () => string | null;\n onComment?: (event: CommentEvent) => void;\n onError?: (error: Error) => void;\n isAuthReady?: Ref<boolean>;\n hasCommentingFeature?: () => boolean;\n}\n\nexport interface UseCommentsReturn {\n comments: Ref<CommentThread[]>;\n isLoading: Ref<boolean>;\n isSubmitting: Ref<boolean>;\n isEnabled: ComputedRef<boolean>;\n commentCountByBlock: ComputedRef<Map<string, number>>;\n totalCount: ComputedRef<number>;\n unresolvedCount: ComputedRef<number>;\n loadComments: () => Promise<void>;\n addComment: (\n body: string,\n blockId?: string,\n parentId?: string,\n ) => Promise<Comment | null>;\n editComment: (commentId: string, body: string) => Promise<Comment | null>;\n removeComment: (commentId: string) => Promise<boolean>;\n toggleResolve: (commentId: string) => Promise<Comment | null>;\n applyRemoteCreate: (comment: Comment) => void;\n applyRemoteUpdate: (comment: Comment) => void;\n applyRemoteDelete: (commentId: string, parentId: string | null) => void;\n}\n\nexport function useComments(options: UseCommentsOptions): UseCommentsReturn {\n const {\n authManager,\n getTemplateId,\n getSocketId,\n onComment,\n onError,\n hasCommentingFeature,\n } = options;\n\n const api = new ApiClient(authManager);\n const comments = ref<CommentThread[]>([]);\n const isLoading = ref(false);\n const isSubmitting = ref(false);\n\n const isEnabled = computed<boolean>(() => {\n const featureAvailable = hasCommentingFeature?.() ?? false;\n return featureAvailable && authManager.userConfig !== null;\n });\n\n const totalCount = computed<number>(() => {\n let count = 0;\n for (const thread of comments.value) {\n count += 1 + (thread.replies?.length ?? 0);\n }\n return count;\n });\n\n const unresolvedCount = computed<number>(() => {\n return comments.value.filter((c) => !c.resolved_at).length;\n });\n\n const commentCountByBlock = computed<Map<string, number>>(() => {\n const map = new Map<string, number>();\n for (const thread of comments.value) {\n if (thread.block_id) {\n map.set(\n thread.block_id,\n (map.get(thread.block_id) ?? 0) + 1 + (thread.replies?.length ?? 0),\n );\n }\n }\n return map;\n });\n\n function getUserPayload(): {\n user_id: string;\n user_name: string;\n user_signature: string;\n } {\n const user: UserConfig | null = authManager.userConfig;\n if (!user) {\n throw new Error(\"User config not available\");\n }\n return {\n user_id: user.id,\n user_name: user.name,\n user_signature: user.signature,\n };\n }\n\n function socketHeaders(): Record<string, string> | undefined {\n const socketId = getSocketId?.();\n if (!socketId) {\n return undefined;\n }\n return { \"X-Socket-ID\": socketId };\n }\n\n function emitEvent(type: CommentEvent[\"type\"], comment: Comment): void {\n onComment?.({ type, comment });\n }\n\n function findComment(commentId: string): Comment | null {\n for (const thread of comments.value) {\n if (thread.id === commentId) {\n return thread;\n }\n for (const reply of thread.replies ?? []) {\n if (reply.id === commentId) {\n return reply;\n }\n }\n }\n return null;\n }\n\n async function loadComments(): Promise<void> {\n const templateId = getTemplateId();\n if (!templateId) {\n return;\n }\n\n isLoading.value = true;\n\n try {\n comments.value = await api.getComments(templateId);\n } catch (err) {\n const wrappedError =\n err instanceof Error\n ? err\n : new Error(\"Failed to load comments\", { cause: err });\n onError?.(wrappedError);\n } finally {\n isLoading.value = false;\n }\n }\n\n async function addComment(\n body: string,\n blockId?: string,\n parentId?: string,\n ): Promise<Comment | null> {\n const templateId = getTemplateId();\n if (!templateId) {\n return null;\n }\n\n isSubmitting.value = true;\n\n try {\n const comment = await api.createComment(\n templateId,\n {\n body,\n block_id: blockId,\n parent_id: parentId,\n ...getUserPayload(),\n },\n socketHeaders(),\n );\n\n if (parentId) {\n const parent = findComment(parentId);\n if (parent) {\n parent.replies = [...(parent.replies ?? []), comment];\n }\n } else {\n comments.value = [...comments.value, comment];\n }\n\n emitEvent(\"created\", comment);\n return comment;\n } catch (err) {\n const wrappedError =\n err instanceof Error\n ? err\n : new Error(\"Failed to create comment\", { cause: err });\n onError?.(wrappedError);\n return null;\n } finally {\n isSubmitting.value = false;\n }\n }\n\n async function editComment(\n commentId: string,\n body: string,\n ): Promise<Comment | null> {\n const templateId = getTemplateId();\n if (!templateId) {\n return null;\n }\n\n isSubmitting.value = true;\n\n try {\n const updated = await api.updateComment(\n templateId,\n commentId,\n {\n body,\n ...getUserPayload(),\n },\n socketHeaders(),\n );\n\n updateCommentInState(commentId, updated);\n emitEvent(\"updated\", updated);\n return updated;\n } catch (err) {\n const wrappedError =\n err instanceof Error\n ? err\n : new Error(\"Failed to update comment\", { cause: err });\n onError?.(wrappedError);\n return null;\n } finally {\n isSubmitting.value = false;\n }\n }\n\n async function removeComment(commentId: string): Promise<boolean> {\n const templateId = getTemplateId();\n if (!templateId) {\n return false;\n }\n\n const comment = findComment(commentId);\n if (!comment) {\n return false;\n }\n\n const commentSnapshot = {\n ...comment,\n replies: [...(comment.replies ?? [])],\n };\n\n isSubmitting.value = true;\n\n try {\n await api.deleteComment(\n templateId,\n commentId,\n getUserPayload(),\n socketHeaders(),\n );\n\n if (comment.parent_id) {\n const parent = findComment(comment.parent_id);\n if (parent) {\n parent.replies = (parent.replies ?? []).filter(\n (r) => r.id !== commentId,\n );\n }\n } else {\n comments.value = comments.value.filter((c) => c.id !== commentId);\n }\n\n emitEvent(\"deleted\", commentSnapshot);\n return true;\n } catch (err) {\n const wrappedError =\n err instanceof Error\n ? err\n : new Error(\"Failed to delete comment\", { cause: err });\n onError?.(wrappedError);\n return false;\n } finally {\n isSubmitting.value = false;\n }\n }\n\n async function toggleResolve(commentId: string): Promise<Comment | null> {\n const templateId = getTemplateId();\n if (!templateId) {\n return null;\n }\n\n isSubmitting.value = true;\n\n try {\n const updated = await api.resolveComment(\n templateId,\n commentId,\n getUserPayload(),\n socketHeaders(),\n );\n\n updateCommentInState(commentId, updated);\n\n const eventType = updated.resolved_at ? \"resolved\" : \"unresolved\";\n emitEvent(eventType, updated);\n return updated;\n } catch (err) {\n const wrappedError =\n err instanceof Error\n ? err\n : new Error(\"Failed to toggle comment resolution\", { cause: err });\n onError?.(wrappedError);\n return null;\n } finally {\n isSubmitting.value = false;\n }\n }\n\n function applyRemoteCreate(comment: Comment): void {\n if (comment.parent_id) {\n const parent = findComment(comment.parent_id);\n if (parent) {\n parent.replies = [...(parent.replies ?? []), comment];\n }\n } else {\n comments.value = [...comments.value, comment];\n }\n emitEvent(\"created\", comment);\n }\n\n function applyRemoteUpdate(comment: Comment): void {\n updateCommentInState(comment.id, comment);\n emitEvent(\"updated\", comment);\n }\n\n function applyRemoteDelete(commentId: string, parentId: string | null): void {\n const comment = findComment(commentId);\n const snapshot = comment\n ? { ...comment, replies: [...(comment.replies ?? [])] }\n : null;\n\n if (parentId) {\n const parent = findComment(parentId);\n if (parent) {\n parent.replies = (parent.replies ?? []).filter(\n (r) => r.id !== commentId,\n );\n }\n } else {\n comments.value = comments.value.filter((c) => c.id !== commentId);\n }\n\n if (snapshot) {\n emitEvent(\"deleted\", snapshot);\n }\n }\n\n function updateCommentInState(commentId: string, updated: Comment): void {\n for (let i = 0; i < comments.value.length; i++) {\n if (comments.value[i].id === commentId) {\n comments.value = [\n ...comments.value.slice(0, i),\n { ...updated, replies: comments.value[i].replies },\n ...comments.value.slice(i + 1),\n ];\n return;\n }\n\n const replies = comments.value[i].replies ?? [];\n for (let j = 0; j < replies.length; j++) {\n if (replies[j].id === commentId) {\n const newReplies = [\n ...replies.slice(0, j),\n updated,\n ...replies.slice(j + 1),\n ];\n comments.value = [\n ...comments.value.slice(0, i),\n { ...comments.value[i], replies: newReplies },\n ...comments.value.slice(i + 1),\n ];\n return;\n }\n }\n }\n }\n\n return {\n comments,\n isLoading,\n isSubmitting,\n isEnabled,\n commentCountByBlock,\n totalCount,\n unresolvedCount,\n loadComments,\n addComment,\n editComment,\n removeComment,\n toggleResolve,\n applyRemoteCreate,\n applyRemoteUpdate,\n applyRemoteDelete,\n };\n}\n","import type { UseCommentsReturn } from \"./comments\";\nimport type { Comment } from \"@templatical/types\";\nimport type { PresenceChannel } from \"pusher-js\";\nimport { onScopeDispose, watch, type Ref } from \"vue\";\n\nexport interface CommentBroadcastPayload {\n action:\n | \"comment_created\"\n | \"comment_updated\"\n | \"comment_deleted\"\n | \"comment_resolved\"\n | \"comment_unresolved\";\n comment: Comment;\n}\n\nexport interface UseCommentListenerOptions {\n comments: UseCommentsReturn;\n channel: Ref<PresenceChannel | null>;\n}\n\nexport function useCommentListener(options: UseCommentListenerOptions): void {\n const { comments, channel } = options;\n\n watch(channel, (newChannel, oldChannel) => {\n if (oldChannel) {\n oldChannel.unbind(\"comment-broadcast\");\n }\n\n if (newChannel) {\n newChannel.bind(\n \"comment-broadcast\",\n (payload: CommentBroadcastPayload) => {\n handleCommentBroadcast(comments, payload);\n },\n );\n }\n });\n\n // The watch only unbinds on channel *transitions*. On scope dispose the\n // currently-bound handler stays attached, processing broadcasts on a\n // dead component. Explicitly tear it down.\n onScopeDispose(() => {\n channel.value?.unbind(\"comment-broadcast\");\n });\n}\n\nfunction handleCommentBroadcast(\n comments: UseCommentsReturn,\n payload: CommentBroadcastPayload,\n): void {\n switch (payload.action) {\n case \"comment_created\":\n comments.applyRemoteCreate(payload.comment);\n break;\n case \"comment_updated\":\n comments.applyRemoteUpdate(payload.comment);\n break;\n case \"comment_deleted\":\n comments.applyRemoteDelete(payload.comment.id, payload.comment.parent_id);\n break;\n case \"comment_resolved\":\n case \"comment_unresolved\":\n comments.applyRemoteUpdate(payload.comment);\n break;\n }\n}\n","import type { UseEditorReturn } from \"./editor\";\nimport type { AuthManager } from \"./auth\";\nimport type { Collaborator, McpOperationPayload } from \"@templatical/types\";\nimport { handleOperation } from \"./mcp-operation-handler\";\nimport type { PresenceMember } from \"./websocket-client\";\nimport type { PresenceChannel } from \"pusher-js\";\nimport { computed, onScopeDispose, ref, watch, type Ref } from \"vue\";\n\nconst COLLAB_EVENTS = [\n \"pusher:member_added\",\n \"pusher:member_removed\",\n \"client-block_locked\",\n \"client-block_unlocked\",\n \"client-operation\",\n \"mcp-operation\",\n] as const;\n\nfunction unbindCollabEvents(channel: PresenceChannel): void {\n for (const event of COLLAB_EVENTS) {\n channel.unbind(event);\n }\n}\n\nconst COLLABORATOR_COLORS = [\n \"#3b82f6\",\n \"#ef4444\",\n \"#10b981\",\n \"#f59e0b\",\n \"#8b5cf6\",\n \"#ec4899\",\n \"#06b6d4\",\n \"#f97316\",\n \"#6366f1\",\n \"#14b8a6\",\n];\n\nexport interface UseCollaborationOptions {\n authManager: AuthManager;\n editor: UseEditorReturn;\n channel: Ref<PresenceChannel | null>;\n onError?: (error: Error) => void;\n onCollaboratorJoined?: (collaborator: Collaborator) => void;\n onCollaboratorLeft?: (collaborator: Collaborator) => void;\n onBlockLocked?: (event: {\n blockId: string;\n collaborator: Collaborator;\n }) => void;\n onBlockUnlocked?: (event: {\n blockId: string;\n collaborator: Collaborator;\n }) => void;\n}\n\nexport interface UseCollaborationReturn {\n collaborators: Ref<Collaborator[]>;\n lockedBlocks: Ref<Map<string, Collaborator>>;\n}\n\nexport function useCollaboration(\n options: UseCollaborationOptions,\n): UseCollaborationReturn & {\n _broadcastOperation: (payload: McpOperationPayload) => void;\n _isProcessingRemoteOperation: () => boolean;\n} {\n const { authManager, editor, channel } = options;\n\n const collaborators = ref<Collaborator[]>([]);\n const lockedBlocks = ref<Map<string, Collaborator>>(new Map());\n\n let colorIndex = 0;\n let isProcessingRemoteOperation = false;\n\n const myUserId = computed(() => authManager.userConfig?.id ?? \"\");\n\n function assignColor(): string {\n const color = COLLABORATOR_COLORS[colorIndex % COLLABORATOR_COLORS.length];\n colorIndex++;\n return color;\n }\n\n function addCollaborator(member: PresenceMember): Collaborator | undefined {\n if (member.id === myUserId.value) {\n return undefined;\n }\n\n if (collaborators.value.some((c) => c.id === member.id)) {\n return undefined;\n }\n\n const collaborator: Collaborator = {\n id: member.id,\n name: member.name,\n color: assignColor(),\n selectedBlockId: null,\n };\n\n collaborators.value = [...collaborators.value, collaborator];\n\n return collaborator;\n }\n\n function removeCollaborator(memberId: string): void {\n const newLockedBlocks = new Map(lockedBlocks.value);\n for (const [blockId, collaborator] of newLockedBlocks) {\n if (collaborator.id === memberId) {\n newLockedBlocks.delete(blockId);\n }\n }\n lockedBlocks.value = newLockedBlocks;\n\n collaborators.value = collaborators.value.filter((c) => c.id !== memberId);\n }\n\n function handleBlockLocked(data: { blockId: string; userId: string }): void {\n const collaborator = collaborators.value.find((c) => c.id === data.userId);\n if (!collaborator) {\n return;\n }\n\n collaborators.value = collaborators.value.map((c) =>\n c.id === data.userId ? { ...c, selectedBlockId: data.blockId } : c,\n );\n\n const newLockedBlocks = new Map(lockedBlocks.value);\n for (const [blockId, holder] of newLockedBlocks) {\n if (holder.id === data.userId) {\n newLockedBlocks.delete(blockId);\n }\n }\n\n newLockedBlocks.set(data.blockId, {\n ...collaborator,\n selectedBlockId: data.blockId,\n });\n lockedBlocks.value = newLockedBlocks;\n\n if (editor.state.selectedBlockId === data.blockId) {\n editor.selectBlock(null);\n }\n }\n\n function handleBlockUnlocked(data: { blockId: string }): void {\n const newLockedBlocks = new Map(lockedBlocks.value);\n const holder = newLockedBlocks.get(data.blockId);\n newLockedBlocks.delete(data.blockId);\n lockedBlocks.value = newLockedBlocks;\n\n if (holder) {\n collaborators.value = collaborators.value.map((c) =>\n c.id === holder.id ? { ...c, selectedBlockId: null } : c,\n );\n }\n }\n\n function handleRemoteOperation(payload: McpOperationPayload): void {\n isProcessingRemoteOperation = true;\n try {\n handleOperation(editor, payload);\n } finally {\n isProcessingRemoteOperation = false;\n }\n }\n\n function broadcastOperation(payload: McpOperationPayload): void {\n if (!channel.value || isProcessingRemoteOperation) {\n return;\n }\n\n channel.value.trigger(\"client-operation\", payload);\n }\n\n function broadcastBlockLocked(blockId: string): void {\n if (!channel.value) {\n return;\n }\n\n channel.value.trigger(\"client-block_locked\", {\n blockId,\n userId: myUserId.value,\n });\n }\n\n function broadcastBlockUnlocked(blockId: string): void {\n if (!channel.value) {\n return;\n }\n\n channel.value.trigger(\"client-block_unlocked\", { blockId });\n }\n\n watch(\n () => editor.state.selectedBlockId,\n (newBlockId, oldBlockId) => {\n if (isProcessingRemoteOperation) {\n return;\n }\n\n if (oldBlockId) {\n broadcastBlockUnlocked(oldBlockId);\n }\n\n if (newBlockId) {\n broadcastBlockLocked(newBlockId);\n }\n },\n );\n\n watch(channel, (newChannel, oldChannel) => {\n if (oldChannel) {\n unbindCollabEvents(oldChannel);\n }\n\n if (!newChannel) {\n collaborators.value = [];\n lockedBlocks.value = new Map();\n colorIndex = 0;\n return;\n }\n\n const members = (\n newChannel as PresenceChannel & {\n members: {\n each: (\n callback: (member: { id: string; info: PresenceMember }) => void,\n ) => void;\n };\n }\n ).members;\n if (members) {\n members.each((member: { id: string; info: PresenceMember }) => {\n addCollaborator(member.info);\n });\n }\n\n newChannel.bind(\n \"pusher:member_added\",\n (member: { id: string; info: PresenceMember }) => {\n const collaborator = addCollaborator(member.info);\n if (collaborator) {\n options.onCollaboratorJoined?.(collaborator);\n }\n },\n );\n\n newChannel.bind(\n \"pusher:member_removed\",\n (member: { id: string; info: PresenceMember }) => {\n const collaborator = collaborators.value.find(\n (c) => c.id === member.id,\n );\n removeCollaborator(member.id);\n if (collaborator) {\n options.onCollaboratorLeft?.(collaborator);\n }\n },\n );\n\n newChannel.bind(\n \"client-block_locked\",\n (data: { blockId: string; userId: string }) => {\n handleBlockLocked(data);\n const collaborator = collaborators.value.find(\n (c) => c.id === data.userId,\n );\n if (collaborator) {\n options.onBlockLocked?.({\n blockId: data.blockId,\n collaborator,\n });\n }\n },\n );\n\n newChannel.bind(\"client-block_unlocked\", (data: { blockId: string }) => {\n const holder = lockedBlocks.value.get(data.blockId);\n handleBlockUnlocked(data);\n if (holder) {\n options.onBlockUnlocked?.({\n blockId: data.blockId,\n collaborator: holder,\n });\n }\n });\n\n newChannel.bind(\"client-operation\", (payload: McpOperationPayload) => {\n handleRemoteOperation(payload);\n });\n\n newChannel.bind(\"mcp-operation\", (payload: McpOperationPayload) => {\n handleRemoteOperation(payload);\n });\n });\n\n // The watch above only unbinds when the channel ref *changes*. On scope\n // dispose (component unmount) the watch is auto-stopped but the currently\n // bound listeners stay attached forever — handlers fire on a dead component\n // and accumulate on remount. Tear them down explicitly.\n onScopeDispose(() => {\n if (channel.value) {\n unbindCollabEvents(channel.value);\n }\n });\n\n return {\n collaborators,\n lockedBlocks,\n _broadcastOperation: broadcastOperation,\n _isProcessingRemoteOperation: () => isProcessingRemoteOperation,\n };\n}\n","import type { McpOperationPayload } from \"@templatical/types\";\nimport type { UseEditorReturn } from \"../editor\";\n\ninterface BroadcastTarget {\n _broadcastOperation: (payload: McpOperationPayload) => void;\n}\n\n/**\n * Wraps editor mutation methods to broadcast operations to collaboration\n * peers after each mutation executes. Mutates the editor object in place.\n *\n * Must be applied **before** the history interceptor so the call chain is:\n * history.record() → broadcast + original mutation.\n */\nexport function useCollaborationBroadcast(\n editor: UseEditorReturn,\n collaboration: BroadcastTarget,\n): void {\n const originalAddBlock = editor.addBlock;\n const originalUpdateBlock = editor.updateBlock;\n const originalRemoveBlock = editor.removeBlock;\n const originalMoveBlock = editor.moveBlock;\n const originalUpdateSettings = editor.updateSettings;\n const originalSetContent = editor.setContent;\n\n editor.addBlock = (block, targetSectionId?, columnIndex?, index?) => {\n originalAddBlock(block, targetSectionId, columnIndex, index);\n collaboration._broadcastOperation({\n operation: \"add_block\",\n data: {\n block,\n section_id: targetSectionId,\n column_index: columnIndex,\n index,\n },\n timestamp: Date.now(),\n });\n };\n\n editor.updateBlock = (blockId, updates) => {\n originalUpdateBlock(blockId, updates);\n collaboration._broadcastOperation({\n operation: \"update_block\",\n data: { block_id: blockId, updates },\n timestamp: Date.now(),\n });\n };\n\n editor.removeBlock = (blockId) => {\n originalRemoveBlock(blockId);\n collaboration._broadcastOperation({\n operation: \"delete_block\",\n data: { block_id: blockId },\n timestamp: Date.now(),\n });\n };\n\n editor.moveBlock = (blockId, newIndex, targetSectionId?, columnIndex?) => {\n originalMoveBlock(blockId, newIndex, targetSectionId, columnIndex);\n collaboration._broadcastOperation({\n operation: \"move_block\",\n data: {\n block_id: blockId,\n index: newIndex,\n section_id: targetSectionId,\n column_index: columnIndex,\n },\n timestamp: Date.now(),\n });\n };\n\n editor.updateSettings = (updates) => {\n originalUpdateSettings(updates);\n collaboration._broadcastOperation({\n operation: \"update_settings\",\n data: { updates },\n timestamp: Date.now(),\n });\n };\n\n editor.setContent = (content, markDirty?) => {\n originalSetContent(content, markDirty);\n collaboration._broadcastOperation({\n operation: \"set_content\",\n data: { content },\n timestamp: Date.now(),\n });\n };\n}\n","import type { AuthManager } from \"./auth\";\nimport type { WebSocketConfig } from \"./websocket-client\";\nimport { WebSocketClient } from \"./websocket-client\";\nimport type { PresenceChannel } from \"pusher-js\";\nimport { ref, type Ref } from \"vue\";\n\nexport interface UseWebSocketOptions {\n authManager: AuthManager;\n onError?: (error: Error) => void;\n}\n\nexport interface UseWebSocketReturn {\n channel: Ref<PresenceChannel | null>;\n isConnected: Ref<boolean>;\n connect: (templateId: string, config: WebSocketConfig) => Promise<void>;\n disconnect: () => void;\n getSocketId: () => string | null;\n}\n\nexport function useWebSocket(options: UseWebSocketOptions): UseWebSocketReturn {\n const { authManager, onError } = options;\n\n const channel = ref<PresenceChannel | null>(\n null,\n ) as Ref<PresenceChannel | null>;\n const isConnected = ref(false);\n\n let wsClient: WebSocketClient | null = null;\n let channelName: string | null = null;\n\n async function connect(\n templateId: string,\n config: WebSocketConfig,\n ): Promise<void> {\n if (wsClient) {\n return;\n }\n\n wsClient = new WebSocketClient({\n authManager,\n config,\n onError,\n });\n\n await wsClient.connect();\n\n channelName = `presence-template.${templateId}`;\n const presenceChannel = wsClient.subscribePresence(channelName);\n\n presenceChannel.bind(\"pusher:subscription_succeeded\", () => {\n isConnected.value = true;\n channel.value = presenceChannel;\n });\n\n presenceChannel.bind(\"pusher:subscription_error\", (error: unknown) => {\n isConnected.value = false;\n channel.value = null;\n onError?.(\n error instanceof Error\n ? error\n : new Error(\"Failed to subscribe to template channel\"),\n );\n });\n }\n\n function disconnect(): void {\n if (channelName && wsClient) {\n wsClient.unsubscribe(channelName);\n }\n\n wsClient?.disconnect();\n wsClient = null;\n channelName = null;\n channel.value = null;\n isConnected.value = false;\n }\n\n function getSocketId(): string | null {\n return wsClient?.getSocketId() ?? null;\n }\n\n return {\n channel,\n isConnected,\n connect,\n disconnect,\n getSocketId,\n };\n}\n","import type {\n SavedBlock,\n SavedBlockInput,\n SavedBlockPatch,\n SavedBlocksListParams,\n SavedBlocksProvider,\n} from \"@templatical/types\";\nimport { ApiClient } from \"./api\";\nimport type { AuthManager } from \"./auth\";\n\n/**\n * Cloud-backed {@link SavedBlocksProvider} — the Templatical Cloud adapter for\n * the same contract consumers implement themselves.\n *\n * Auth (JWT via {@link AuthManager}) and project/tenant scoping live entirely\n * on this side of the seam: the shared `useSavedBlocks` composable and the\n * editor UI never see them. Plan gating is applied by the caller before this\n * provider is constructed.\n *\n * Wraps the existing `ApiClient` saved-module endpoints, so the REST contract\n * is unchanged from before saved blocks became an open-source feature.\n *\n * Rows pass straight through, unmapped: the Cloud endpoints speak the same\n * `SavedBlock` shape the contract defines, so this adapter only supplies auth\n * and scoping. That means the payload's field names track the contract — the\n * backend serialises `category`, `canUpdate`, `canDelete`, `createdAt` and\n * `updatedAt`. Until it does, those fields simply arrive absent, which degrades\n * to \"no timestamp label, every action allowed\" rather than breaking.\n */\nexport function createCloudSavedBlocksProvider(\n authManager: AuthManager,\n): SavedBlocksProvider {\n const api = new ApiClient(authManager);\n\n return {\n list(params?: SavedBlocksListParams): Promise<SavedBlock[]> {\n return api.listModules(params?.search, params?.category);\n },\n // All three enabled: Cloud gates saved blocks by plan entitlement above\n // this seam, and row-level permissions arrive as `canUpdate`/`canDelete`\n // on the entries themselves.\n create(input: SavedBlockInput): Promise<SavedBlock> {\n return api.createModule(input);\n },\n update(id: string, patch: SavedBlockPatch): Promise<SavedBlock> {\n return api.updateModule(id, patch);\n },\n delete(id: string): Promise<void> {\n return api.deleteModule(id);\n },\n };\n}\n","import type { Template, TemplateSnapshot } from \"@templatical/types\";\nimport { ApiClient } from \"./api\";\nimport type { AuthManager } from \"./auth\";\nimport { ref, type Ref } from \"vue\";\n\nexport interface UseSnapshotHistoryOptions {\n authManager: AuthManager;\n templateId: string;\n onRestore?: (template: Template) => void;\n onError?: (error: Error) => void;\n}\n\nexport interface UseSnapshotHistoryReturn {\n snapshots: Ref<TemplateSnapshot[]>;\n isLoading: Ref<boolean>;\n isRestoring: Ref<boolean>;\n loadSnapshots: () => Promise<void>;\n restoreSnapshot: (snapshotId: string) => Promise<Template>;\n}\n\nexport function useSnapshotHistory(\n options: UseSnapshotHistoryOptions,\n): UseSnapshotHistoryReturn {\n const api = new ApiClient(options.authManager);\n\n const snapshots = ref<TemplateSnapshot[]>([]);\n const isLoading = ref(false);\n const isRestoring = ref(false);\n\n async function loadSnapshots(): Promise<void> {\n isLoading.value = true;\n try {\n snapshots.value = await api.getSnapshots(options.templateId);\n } catch (error) {\n options.onError?.(error as Error);\n throw error;\n } finally {\n isLoading.value = false;\n }\n }\n\n async function restoreSnapshot(snapshotId: string): Promise<Template> {\n isRestoring.value = true;\n try {\n const template = await api.restoreSnapshot(\n options.templateId,\n snapshotId,\n );\n options.onRestore?.(template);\n return template;\n } catch (error) {\n options.onError?.(error as Error);\n throw error;\n } finally {\n isRestoring.value = false;\n }\n }\n\n return {\n snapshots,\n isLoading,\n isRestoring,\n loadSnapshots,\n restoreSnapshot,\n };\n}\n","import type { TestEmailConfig } from \"@templatical/types\";\nimport type { AuthManager } from \"./auth\";\nimport type { ComputedRef, Ref } from \"vue\";\nimport { computed, ref, watch } from \"vue\";\n\n/**\n * Cloud's test-email *configuration* — whether the project has the feature, who\n * may be sent to, and the signature that lets the backend verify that list.\n *\n * Sending itself lives in `createCloudTestEmailProvider`, which plugs into the\n * shared `useTestEmailFeature` seam in `@templatical/editor` alongside a\n * consumer's own sender. Keeping the send body in exactly one place is the point:\n * both editors then drive identical UI, state and error handling, so the sending\n * spinner, the inline error and the success confirmation can't drift apart.\n */\nexport interface UseTestEmailOptions {\n authManager: AuthManager;\n /** Gates reading the config off the auth manager until the JWT has resolved. */\n isAuthReady?: Ref<boolean>;\n}\n\nexport interface UseTestEmailReturn {\n /** Whether the project's token carries a test-email config at all. */\n isEnabled: ComputedRef<boolean>;\n /**\n * Addresses the project permits. Empty until auth resolves — read it\n * reactively, never snapshot it, or it stays empty for the session.\n */\n allowedEmails: ComputedRef<string[]>;\n /** The signature accompanying {@link allowedEmails}, or `null` when disabled. */\n getSignature: () => string | null;\n}\n\nexport function useTestEmail(options: UseTestEmailOptions): UseTestEmailReturn {\n const { authManager, isAuthReady } = options;\n\n const testEmailConfig = ref<TestEmailConfig | null>(null);\n\n if (isAuthReady) {\n watch(\n isAuthReady,\n (ready) => {\n if (ready) {\n testEmailConfig.value = authManager.testEmailConfig;\n }\n },\n { immediate: true },\n );\n }\n\n const isEnabled = computed<boolean>(() => testEmailConfig.value !== null);\n\n const allowedEmails = computed<string[]>(\n () => testEmailConfig.value?.allowedEmails ?? [],\n );\n\n function getSignature(): string | null {\n return testEmailConfig.value?.signature ?? null;\n }\n\n return { isEnabled, allowedEmails, getSignature };\n}\n","import type {\n ExportResult,\n Template,\n TestEmailProvider,\n} from \"@templatical/types\";\nimport type { AuthManager } from \"./auth\";\nimport { ApiClient } from \"./api\";\nimport type { ComputedRef } from \"vue\";\n\nexport interface CreateCloudTestEmailProviderOptions {\n authManager: AuthManager;\n getTemplateId: () => string | null;\n save: () => Promise<Template>;\n exportHtml: (templateId: string) => Promise<ExportResult>;\n /**\n * The project's allowed recipients, from the signed JWT.\n *\n * Taken as a `ComputedRef` rather than an array because it only becomes\n * populated once auth resolves — see the getter note on the returned provider.\n */\n allowedEmails: ComputedRef<string[]>;\n /** The signature that lets the backend verify {@link allowedEmails}. */\n getSignature: () => string | null;\n onBeforeTestEmail?: (html: string) => string | Promise<string>;\n}\n\n/**\n * Templatical Cloud's test-email sender, shaped as a {@link TestEmailProvider}\n * so it plugs into the same editor seam a consumer's own sender would.\n *\n * Two things about it are deliberately unlike a BYO provider:\n *\n * - **It ignores `payload.content` and `payload.allowedRecipients`.** Cloud saves\n * the template, has its backend render the HTML, and derives the allowlist plus\n * its signature from the auth manager. Trusting the echoed payload would swap a\n * server-signed list for an unsigned browser value. The contract is \"send a test\n * of the current template\" — how an adapter obtains the bytes is its business,\n * so this is honest rather than a smell. Don't \"fix\" it.\n * - **It never sets `includeMjml`.** Cloud renders server-side, so the editor\n * should not spend a render pass producing MJML nobody reads.\n */\nexport function createCloudTestEmailProvider(\n options: CreateCloudTestEmailProviderOptions,\n): TestEmailProvider {\n const api = new ApiClient(options.authManager);\n\n return {\n /**\n * A getter, not a snapshot: the allowlist arrives with the JWT, so it starts\n * empty and fills once auth is ready. The editor reads this property inside a\n * computed, which is what makes the trigger appear at that point — reading it\n * once at construction would pin it to `[]` and, because an empty allowlist\n * means \"nobody may be sent to\", hide the button forever.\n */\n get allowedRecipients(): string[] {\n return options.allowedEmails.value;\n },\n\n async send({ recipient }): Promise<void> {\n const signature = options.getSignature();\n if (signature === null) {\n throw new Error(\"Test email is not enabled for this project\");\n }\n\n const templateId = options.getTemplateId();\n if (templateId === null) {\n throw new Error(\"Template must be saved before sending a test email\");\n }\n\n // Save first: the backend renders from the stored template, so sending\n // without this would mail a stale version of what's on screen.\n await options.save();\n\n let { html } = await options.exportHtml(templateId);\n if (options.onBeforeTestEmail) {\n html = await options.onBeforeTestEmail(html);\n }\n\n await api.sendTestEmail(templateId, {\n recipient,\n html,\n allowed_emails: options.allowedEmails.value,\n signature,\n });\n },\n };\n}\n","import type { CustomFont, ExportResult, FontsConfig } from \"@templatical/types\";\nimport { ApiClient } from \"./api\";\nimport type { AuthManager } from \"./auth\";\n\nexport interface UseExportOptions {\n authManager: AuthManager;\n getFontsConfig?: () => FontsConfig | undefined;\n canUseCustomFonts?: () => boolean;\n}\n\nexport interface UseExportReturn {\n exportHtml: (templateId: string) => Promise<ExportResult>;\n getMjmlSource: (templateId: string) => Promise<string>;\n}\n\nexport function useExport(options: UseExportOptions): UseExportReturn {\n const { authManager, getFontsConfig, canUseCustomFonts } = options;\n const api = new ApiClient(authManager);\n\n function getExportFontsPayload(): {\n customFonts: CustomFont[];\n defaultFallback: string;\n } {\n const fontsConfig = getFontsConfig?.();\n const customFontsAllowed = canUseCustomFonts?.() ?? true;\n\n return {\n customFonts:\n customFontsAllowed && fontsConfig?.customFonts\n ? fontsConfig.customFonts\n : [],\n defaultFallback: fontsConfig?.defaultFallback ?? \"Arial, sans-serif\",\n };\n }\n\n async function exportHtml(templateId: string): Promise<ExportResult> {\n const fontsPayload = getExportFontsPayload();\n const result = await api.exportTemplate(templateId, fontsPayload);\n\n return {\n html: result.html,\n mjml: result.mjml,\n };\n }\n\n async function getMjmlSource(templateId: string): Promise<string> {\n const fontsPayload = getExportFontsPayload();\n const result = await api.exportTemplate(templateId, fontsPayload);\n return result.mjml;\n }\n\n return {\n exportHtml,\n getMjmlSource,\n };\n}\n","import type { PlanConfig, PlanFeatures } from \"@templatical/types\";\nimport { ApiClient } from \"./api\";\nimport type { AuthManager } from \"./auth\";\nimport { computed, ref, type ComputedRef, type Ref } from \"vue\";\n\nexport interface UsePlanConfigOptions {\n authManager: AuthManager;\n onError?: (error: Error) => void;\n}\n\nexport interface UsePlanConfigReturn {\n config: Ref<PlanConfig | null>;\n isLoading: Ref<boolean>;\n hasFeature: (feature: keyof PlanFeatures) => boolean;\n features: ComputedRef<PlanFeatures | null>;\n fetchConfig: () => Promise<void>;\n}\n\nexport function usePlanConfig(\n options: UsePlanConfigOptions,\n): UsePlanConfigReturn {\n const { authManager, onError } = options;\n\n const config = ref<PlanConfig | null>(null);\n const isLoading = ref(false);\n\n const apiClient = new ApiClient(authManager);\n\n const features = computed(() => config.value?.features ?? null);\n\n function hasFeature(feature: keyof PlanFeatures): boolean {\n return config.value?.features[feature] ?? false;\n }\n\n async function fetchConfig(): Promise<void> {\n if (isLoading.value) {\n return;\n }\n\n isLoading.value = true;\n\n try {\n config.value = await apiClient.fetchConfig();\n } catch (error) {\n onError?.(\n error instanceof Error\n ? error\n : new Error(\"Failed to fetch config\", { cause: error }),\n );\n } finally {\n isLoading.value = false;\n }\n }\n\n return {\n config,\n isLoading,\n hasFeature,\n features,\n fetchConfig,\n };\n}\n","import type { HealthCheckResult } from \"@templatical/types\";\nimport type { AuthManager } from \"./auth\";\nimport { API_ROUTES } from \"./url-builder\";\n\ninterface HealthCheckOptions {\n authManager?: AuthManager;\n baseUrl?: string;\n}\n\nconst WS_HANDSHAKE_TIMEOUT = 5000;\n\nfunction resolveHealthUrl(options: HealthCheckOptions): string {\n if (options.authManager) {\n return options.authManager.resolveUrl(API_ROUTES.health);\n }\n\n const base = (options.baseUrl ?? \"https://templatical.com\").replace(\n /\\/$/,\n \"\",\n );\n return `${base}${API_ROUTES.health}`;\n}\n\nasync function checkApiAndAuth(\n url: string,\n authManager?: AuthManager,\n): Promise<{\n api: { ok: boolean; latency: number };\n auth: { ok: boolean; error?: string };\n wsConfig?: { host: string; port: number; app_key: string };\n}> {\n const start = performance.now();\n\n try {\n const response = authManager\n ? await authManager.authenticatedFetch(API_ROUTES.health, {\n method: \"GET\",\n headers: { Accept: \"application/json\" },\n })\n : await fetch(url, {\n method: \"GET\",\n headers: { Accept: \"application/json\" },\n });\n\n const latency = Math.round(performance.now() - start);\n\n if (response.status === 401) {\n return {\n api: { ok: true, latency },\n auth: { ok: false, error: \"HTTP 401\" },\n };\n }\n\n if (!response.ok) {\n return {\n api: { ok: false, latency },\n auth: {\n ok: !authManager,\n error: authManager ? `HTTP ${response.status}` : undefined,\n },\n };\n }\n\n const data = await response.json();\n\n return {\n api: { ok: data.status === \"ok\", latency },\n auth: { ok: true },\n wsConfig: data.websocket,\n };\n } catch (error) {\n const latency = Math.round(performance.now() - start);\n\n return {\n api: { ok: false, latency },\n auth: {\n ok: !authManager,\n error: authManager\n ? error instanceof Error\n ? error.message\n : \"Authentication check failed\"\n : undefined,\n },\n };\n }\n}\n\nasync function checkWebSocket(wsConfig?: {\n host: string;\n port: number;\n app_key: string;\n}): Promise<{ ok: boolean; error?: string }> {\n if (!wsConfig?.host || !wsConfig?.app_key) {\n return { ok: false, error: \"WebSocket configuration not available\" };\n }\n\n if (typeof WebSocket === \"undefined\") {\n return {\n ok: false,\n error: \"WebSocket not supported in this environment\",\n };\n }\n\n const protocol = wsConfig.port === 443 ? \"wss\" : \"ws\";\n const url = `${protocol}://${wsConfig.host}:${wsConfig.port}/app/${wsConfig.app_key}?protocol=7&client=js&version=8.4.0-rc2&flash=false`;\n\n return new Promise((resolve) => {\n let ws: WebSocket | null = null;\n\n const timeout = setTimeout(() => {\n ws?.close();\n resolve({ ok: false, error: \"WebSocket connection timed out\" });\n }, WS_HANDSHAKE_TIMEOUT);\n\n try {\n ws = new WebSocket(url);\n } catch (error) {\n // Some browsers throw synchronously from `new WebSocket(...)`\n // (e.g. SecurityError on mixed content, InvalidAccessError on\n // malformed URL). Without this catch the queued timeout would\n // later access `ws` in TDZ and the outer promise would hang.\n clearTimeout(timeout);\n resolve({\n ok: false,\n error:\n error instanceof Error\n ? error.message\n : \"WebSocket connection failed\",\n });\n return;\n }\n\n ws.onopen = () => {\n clearTimeout(timeout);\n ws?.close();\n resolve({ ok: true });\n };\n\n ws.onerror = () => {\n clearTimeout(timeout);\n resolve({ ok: false, error: \"WebSocket connection failed\" });\n };\n });\n}\n\nexport async function performHealthCheck(\n options: HealthCheckOptions = {},\n): Promise<HealthCheckResult> {\n const healthUrl = resolveHealthUrl(options);\n\n const result = await checkApiAndAuth(healthUrl, options.authManager);\n const wsResult = await checkWebSocket(result.wsConfig);\n\n return {\n api: result.api,\n websocket: wsResult,\n auth: result.auth,\n overall: result.api.ok && result.auth.ok,\n };\n}\n","import type { UseEditorReturn } from \"./editor\";\nimport type { McpOperationPayload } from \"@templatical/types\";\nimport { handleOperation } from \"./mcp-operation-handler\";\nimport type { PresenceChannel } from \"pusher-js\";\nimport { watch, type Ref } from \"vue\";\n\nexport interface UseMcpListenerOptions {\n editor: UseEditorReturn;\n channel: Ref<PresenceChannel | null>;\n onOperation?: (payload: McpOperationPayload) => void;\n}\n\nexport function useMcpListener(options: UseMcpListenerOptions): void {\n const { editor, channel, onOperation } = options;\n\n watch(channel, (newChannel, oldChannel) => {\n if (oldChannel) {\n oldChannel.unbind(\"mcp-operation\");\n }\n\n if (newChannel) {\n newChannel.bind(\"mcp-operation\", (payload: McpOperationPayload) => {\n handleOperation(editor, payload);\n onOperation?.(payload);\n });\n }\n });\n}\n"],"mappings":";;;;AAkBA,IAAa,IAAb,MAAa,EAAY;CACvB,OAAwB,mBAAmB;CAE3C,cAAqC;CACrC,YAAiC;CACjC,aAAoC;CACpC,YAAmC;CACnC,cAAqC;CACrC,mBAAmD;CACnD,cAAyC;CACzC;CACA;CACA;CACA;CACA,iBAAiD;CAEjD,OAAwB,uBAAuB;CAE/C,YAAY,GAAoB;EAO9B,AANA,KAAK,MAAM,EAAO,KAClB,KA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