@flamingo-stack/openframe-frontend-core 0.0.598-2039.5713.1 → 0.0.598

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 (225) hide show
  1. package/dist/chat-protocol/index.cjs +1 -8
  2. package/dist/chat-protocol/index.cjs.map +1 -1
  3. package/dist/chat-protocol/index.d.ts +0 -1
  4. package/dist/chat-protocol/index.d.ts.map +1 -1
  5. package/dist/chat-protocol/index.js +2 -7
  6. package/dist/chat-protocol/index.js.map +1 -1
  7. package/dist/chat-protocol/nats-decoder.d.ts.map +1 -1
  8. package/dist/{chunk-TSCIVH7T.js → chunk-2JNCZDJR.js} +2 -2
  9. package/dist/{chunk-6NSGAH5H.cjs → chunk-2SYX2Z7R.cjs} +34 -34
  10. package/dist/{chunk-6NSGAH5H.cjs.map → chunk-2SYX2Z7R.cjs.map} +1 -1
  11. package/dist/{chunk-6ZHH37RS.cjs → chunk-3WSS7C2V.cjs} +15 -15
  12. package/dist/{chunk-6ZHH37RS.cjs.map → chunk-3WSS7C2V.cjs.map} +1 -1
  13. package/dist/{chunk-5L4ERWSW.js → chunk-75YW6ET4.js} +4 -4
  14. package/dist/{chunk-VKCETV3C.js → chunk-BK6CCQG6.js} +12 -12
  15. package/dist/{chunk-HM25MFZX.cjs → chunk-BPVHDDNY.cjs} +8 -8
  16. package/dist/{chunk-HM25MFZX.cjs.map → chunk-BPVHDDNY.cjs.map} +1 -1
  17. package/dist/{chunk-VIBREYUK.cjs → chunk-BZEWPW5A.cjs} +3 -3
  18. package/dist/{chunk-VIBREYUK.cjs.map → chunk-BZEWPW5A.cjs.map} +1 -1
  19. package/dist/{chunk-KYWU6F3O.cjs → chunk-DAPOBLAK.cjs} +39 -39
  20. package/dist/{chunk-KYWU6F3O.cjs.map → chunk-DAPOBLAK.cjs.map} +1 -1
  21. package/dist/{chunk-DHCA5BZP.cjs → chunk-DI3SVVY5.cjs} +85 -85
  22. package/dist/{chunk-DHCA5BZP.cjs.map → chunk-DI3SVVY5.cjs.map} +1 -1
  23. package/dist/{chunk-BLUL2TE3.js → chunk-EVMHJB6X.js} +4 -4
  24. package/dist/{chunk-S6WBBSII.js → chunk-EZM5DNII.js} +3 -3
  25. package/dist/{chunk-BVQEU5JB.js → chunk-GGQZBSFN.js} +2 -2
  26. package/dist/{chunk-KTX5B2FW.js → chunk-GHYFVT52.js} +439 -414
  27. package/dist/chunk-GHYFVT52.js.map +1 -0
  28. package/dist/{chunk-CCWI3622.cjs → chunk-H64ZHSYR.cjs} +4 -4
  29. package/dist/{chunk-CCWI3622.cjs.map → chunk-H64ZHSYR.cjs.map} +1 -1
  30. package/dist/{chunk-4T42D6YG.js → chunk-HLPAVYK7.js} +4 -4
  31. package/dist/{chunk-HFHBA3VV.cjs → chunk-HWAYIK4U.cjs} +22 -22
  32. package/dist/{chunk-HFHBA3VV.cjs.map → chunk-HWAYIK4U.cjs.map} +1 -1
  33. package/dist/{chunk-CF4QJPTN.cjs → chunk-JVZVVZOZ.cjs} +9 -9
  34. package/dist/{chunk-CF4QJPTN.cjs.map → chunk-JVZVVZOZ.cjs.map} +1 -1
  35. package/dist/{chunk-XV7RFACE.js → chunk-KHOZ52NR.js} +6 -6
  36. package/dist/{chunk-IW746HJ7.js → chunk-LRQCKSZC.js} +2 -2
  37. package/dist/{chunk-JJUV7Z4L.cjs → chunk-M4YQUHOR.cjs} +15 -15
  38. package/dist/{chunk-JJUV7Z4L.cjs.map → chunk-M4YQUHOR.cjs.map} +1 -1
  39. package/dist/{chunk-FKBM6U43.js → chunk-MYBXCWEI.js} +2 -2
  40. package/dist/{chunk-QTPHBCPI.js → chunk-NIAMPMKV.js} +4 -4
  41. package/dist/{chunk-UXOOVP77.cjs → chunk-O4VZOA2Q.cjs} +3 -3
  42. package/dist/{chunk-UXOOVP77.cjs.map → chunk-O4VZOA2Q.cjs.map} +1 -1
  43. package/dist/{chunk-ABNBTPI2.cjs → chunk-P24VPJTT.cjs} +15 -15
  44. package/dist/{chunk-ABNBTPI2.cjs.map → chunk-P24VPJTT.cjs.map} +1 -1
  45. package/dist/{chunk-4XPPQDEM.js → chunk-PTK3CINU.js} +5 -5
  46. package/dist/{chunk-7FUIRGMU.js → chunk-PX4IPM7Q.js} +3 -3
  47. package/dist/{chunk-NLT5R43J.cjs → chunk-QD64Q4I2.cjs} +9 -9
  48. package/dist/{chunk-NLT5R43J.cjs.map → chunk-QD64Q4I2.cjs.map} +1 -1
  49. package/dist/{chunk-TEVP4KNG.cjs → chunk-QIKBISZM.cjs} +522 -497
  50. package/dist/chunk-QIKBISZM.cjs.map +1 -0
  51. package/dist/{chunk-FGNUI4CC.js → chunk-R4UV366K.js} +6 -6
  52. package/dist/{chunk-UPKZU6QU.cjs → chunk-RDTOMWDN.cjs} +1 -1
  53. package/dist/chunk-RDTOMWDN.cjs.map +1 -0
  54. package/dist/{chunk-YB6FI2G3.js → chunk-RYXIRVDC.js} +1 -1
  55. package/dist/chunk-RYXIRVDC.js.map +1 -0
  56. package/dist/{chunk-QPAPUIF3.cjs → chunk-SAEJGTCI.cjs} +35 -35
  57. package/dist/{chunk-QPAPUIF3.cjs.map → chunk-SAEJGTCI.cjs.map} +1 -1
  58. package/dist/{chunk-66HTVTZZ.js → chunk-SE3PVN64.js} +2 -2
  59. package/dist/{chunk-3IXDZI3R.cjs → chunk-STYNZ4QM.cjs} +3 -3
  60. package/dist/{chunk-3IXDZI3R.cjs.map → chunk-STYNZ4QM.cjs.map} +1 -1
  61. package/dist/{chunk-CQRYXSHL.js → chunk-TZPVRWPU.js} +5 -5
  62. package/dist/{chunk-RU3IKVY2.js → chunk-UAAXUFK6.js} +3 -3
  63. package/dist/{chunk-F5NEZLTG.cjs → chunk-UE7OFLLS.cjs} +14 -14
  64. package/dist/{chunk-F5NEZLTG.cjs.map → chunk-UE7OFLLS.cjs.map} +1 -1
  65. package/dist/{chunk-VUR24QYH.cjs → chunk-UG7JNQZY.cjs} +37 -37
  66. package/dist/{chunk-VUR24QYH.cjs.map → chunk-UG7JNQZY.cjs.map} +1 -1
  67. package/dist/{chunk-UQSOFWXP.cjs → chunk-V2QK5W3O.cjs} +3 -3
  68. package/dist/{chunk-UQSOFWXP.cjs.map → chunk-V2QK5W3O.cjs.map} +1 -1
  69. package/dist/{chunk-ZABAXD4U.js → chunk-VIRTMRS4.js} +7 -7
  70. package/dist/{chunk-D565OOXC.cjs → chunk-VLJTJAHJ.cjs} +25 -25
  71. package/dist/{chunk-D565OOXC.cjs.map → chunk-VLJTJAHJ.cjs.map} +1 -1
  72. package/dist/{chunk-K5QV7ZAY.js → chunk-VNSRNVPD.js} +437 -756
  73. package/dist/chunk-VNSRNVPD.js.map +1 -0
  74. package/dist/{chunk-UQEOAPAI.cjs → chunk-WCBRZCU4.cjs} +9 -9
  75. package/dist/{chunk-UQEOAPAI.cjs.map → chunk-WCBRZCU4.cjs.map} +1 -1
  76. package/dist/{chunk-3XFDRL32.js → chunk-WDWCQD75.js} +9 -9
  77. package/dist/{chunk-QT35C6CW.js → chunk-WPN545FW.js} +12 -12
  78. package/dist/{chunk-F2KBCLUG.js → chunk-WZJOILPU.js} +2 -2
  79. package/dist/{chunk-KAADFO74.js → chunk-XNPAVMPB.js} +5 -5
  80. package/dist/{chunk-5PPYXXUO.cjs → chunk-YBPFIXV4.cjs} +522 -841
  81. package/dist/chunk-YBPFIXV4.cjs.map +1 -0
  82. package/dist/{chunk-EHAYNUOL.cjs → chunk-YH6IQTPI.cjs} +3 -3
  83. package/dist/{chunk-EHAYNUOL.cjs.map → chunk-YH6IQTPI.cjs.map} +1 -1
  84. package/dist/{chunk-AVAENPVE.cjs → chunk-YWBAIFI2.cjs} +105 -105
  85. package/dist/{chunk-AVAENPVE.cjs.map → chunk-YWBAIFI2.cjs.map} +1 -1
  86. package/dist/components/case-studies/index.cjs +14 -14
  87. package/dist/components/case-studies/index.js +8 -8
  88. package/dist/components/chat/embeddable-chat.d.ts +19 -10
  89. package/dist/components/chat/embeddable-chat.d.ts.map +1 -1
  90. package/dist/components/chat/hooks/index.d.ts +0 -1
  91. package/dist/components/chat/hooks/index.d.ts.map +1 -1
  92. package/dist/components/chat/hooks/use-chat-dialog-manager.d.ts +2 -2
  93. package/dist/components/chat/hooks/use-chat-dialog-manager.d.ts.map +1 -1
  94. package/dist/components/chat/hooks/use-chat-history-hydration.d.ts +3 -13
  95. package/dist/components/chat/hooks/use-chat-history-hydration.d.ts.map +1 -1
  96. package/dist/components/chat/hooks/use-nats-chat-adapter.d.ts +16 -2
  97. package/dist/components/chat/hooks/use-nats-chat-adapter.d.ts.map +1 -1
  98. package/dist/components/chat/hooks/use-sse-chat-adapter.d.ts.map +1 -1
  99. package/dist/components/chat/hooks/use-unified-chat.d.ts.map +1 -1
  100. package/dist/components/chat/index.cjs +5 -9
  101. package/dist/components/chat/index.cjs.map +1 -1
  102. package/dist/components/chat/index.js +4 -8
  103. package/dist/components/chat/types/unified-chat-state.types.d.ts +6 -67
  104. package/dist/components/chat/types/unified-chat-state.types.d.ts.map +1 -1
  105. package/dist/components/chat/utils/index.d.ts +0 -1
  106. package/dist/components/chat/utils/index.d.ts.map +1 -1
  107. package/dist/components/contact/index.cjs +9 -9
  108. package/dist/components/contact/index.js +8 -8
  109. package/dist/components/docs/index.cjs +12 -12
  110. package/dist/components/docs/index.js +11 -11
  111. package/dist/components/embeds/index.cjs +9 -9
  112. package/dist/components/embeds/index.js +8 -8
  113. package/dist/components/faq/index.cjs +10 -10
  114. package/dist/components/faq/index.js +9 -9
  115. package/dist/components/features/index.cjs +8 -8
  116. package/dist/components/features/index.js +7 -7
  117. package/dist/components/help-center-pages/index.cjs +31 -31
  118. package/dist/components/help-center-pages/index.js +22 -22
  119. package/dist/components/index.cjs +66 -70
  120. package/dist/components/index.cjs.map +1 -1
  121. package/dist/components/index.js +22 -26
  122. package/dist/components/index.js.map +1 -1
  123. package/dist/components/meeting-scheduler/index.cjs +49 -49
  124. package/dist/components/meeting-scheduler/index.js +9 -9
  125. package/dist/components/navigation/index.cjs +11 -11
  126. package/dist/components/navigation/index.js +10 -10
  127. package/dist/components/onboarding-guides/index.cjs +12 -12
  128. package/dist/components/onboarding-guides/index.js +11 -11
  129. package/dist/components/related-content/index.cjs +7 -7
  130. package/dist/components/related-content/index.js +6 -6
  131. package/dist/components/tickets/index.cjs +13 -13
  132. package/dist/components/tickets/index.js +12 -12
  133. package/dist/components/ui/data-table/data-table-body.d.ts.map +1 -1
  134. package/dist/components/ui/data-table/data-table-skeleton.d.ts +31 -0
  135. package/dist/components/ui/data-table/data-table-skeleton.d.ts.map +1 -1
  136. package/dist/components/ui/index.cjs +8 -12
  137. package/dist/components/ui/index.cjs.map +1 -1
  138. package/dist/components/ui/index.js +7 -11
  139. package/dist/components/ui/table/table-empty-state.d.ts +1 -1
  140. package/dist/components/ui/table/table-empty-state.d.ts.map +1 -1
  141. package/dist/components/ui/table/table-skeleton.d.ts +1 -14
  142. package/dist/components/ui/table/table-skeleton.d.ts.map +1 -1
  143. package/dist/components/ui/table/table.d.ts +1 -1
  144. package/dist/components/ui/table/table.d.ts.map +1 -1
  145. package/dist/components/ui/table/types.d.ts +33 -6
  146. package/dist/components/ui/table/types.d.ts.map +1 -1
  147. package/dist/contexts/chat-runtime-context.d.ts +0 -12
  148. package/dist/contexts/chat-runtime-context.d.ts.map +1 -1
  149. package/dist/contexts/index.cjs +2 -2
  150. package/dist/contexts/index.js +1 -1
  151. package/dist/hooks/index.cjs +5 -5
  152. package/dist/hooks/index.js +4 -4
  153. package/dist/index.cjs +12 -16
  154. package/dist/index.cjs.map +1 -1
  155. package/dist/index.js +11 -15
  156. package/dist/index.js.map +1 -1
  157. package/package.json +1 -1
  158. package/src/chat-protocol/index.ts +0 -1
  159. package/src/chat-protocol/nats-decoder.ts +5 -1
  160. package/src/components/chat/.embeddable-chat.md +2 -4
  161. package/src/components/chat/embeddable-chat.tsx +84 -131
  162. package/src/components/chat/hooks/.use-chat-dialog-manager.md +1 -3
  163. package/src/components/chat/hooks/.use-nats-chat-adapter.md +1 -3
  164. package/src/components/chat/hooks/.use-sse-chat-adapter.md +1 -8
  165. package/src/components/chat/hooks/.use-unified-chat.md +2 -2
  166. package/src/components/chat/hooks/index.ts +0 -2
  167. package/src/components/chat/hooks/use-chat-dialog-manager.ts +65 -38
  168. package/src/components/chat/hooks/use-chat-history-hydration.ts +24 -67
  169. package/src/components/chat/hooks/use-nats-chat-adapter.ts +150 -65
  170. package/src/components/chat/hooks/use-sse-chat-adapter.ts +59 -233
  171. package/src/components/chat/hooks/use-unified-chat.ts +0 -5
  172. package/src/components/chat/types/.unified-chat-state.types.md +1 -13
  173. package/src/components/chat/types/unified-chat-state.types.ts +6 -74
  174. package/src/components/chat/utils/index.ts +0 -7
  175. package/src/components/ui/data-table/data-table-body.tsx +8 -49
  176. package/src/components/ui/data-table/data-table-skeleton.tsx +100 -0
  177. package/src/components/ui/table/table-empty-state.tsx +5 -1
  178. package/src/components/ui/table/table-skeleton.tsx +14 -40
  179. package/src/components/ui/table/table.tsx +34 -15
  180. package/src/components/ui/table/types.ts +33 -6
  181. package/src/contexts/.chat-runtime-context.md +1 -3
  182. package/src/contexts/chat-runtime-context.tsx +0 -12
  183. package/dist/chat-protocol/wire-narrow.d.ts +0 -17
  184. package/dist/chat-protocol/wire-narrow.d.ts.map +0 -1
  185. package/dist/chunk-5PPYXXUO.cjs.map +0 -1
  186. package/dist/chunk-K5QV7ZAY.js.map +0 -1
  187. package/dist/chunk-KTX5B2FW.js.map +0 -1
  188. package/dist/chunk-TEVP4KNG.cjs.map +0 -1
  189. package/dist/chunk-UPKZU6QU.cjs.map +0 -1
  190. package/dist/chunk-YB6FI2G3.js.map +0 -1
  191. package/dist/components/chat/hooks/use-managed-dialog-list.d.ts +0 -68
  192. package/dist/components/chat/hooks/use-managed-dialog-list.d.ts.map +0 -1
  193. package/dist/components/chat/utils/chat-conversations-api.d.ts +0 -29
  194. package/dist/components/chat/utils/chat-conversations-api.d.ts.map +0 -1
  195. package/src/chat-protocol/wire-narrow.ts +0 -22
  196. package/src/components/chat/hooks/.use-managed-dialog-list.md +0 -31
  197. package/src/components/chat/hooks/__tests__/managed-dialog-list.test.ts +0 -280
  198. package/src/components/chat/hooks/__tests__/nats-adapter-managed-dialogs.test.ts +0 -172
  199. package/src/components/chat/hooks/__tests__/sse-managed-dialogs.test.ts +0 -310
  200. package/src/components/chat/hooks/use-managed-dialog-list.ts +0 -371
  201. package/src/components/chat/utils/.chat-conversations-api.md +0 -16
  202. package/src/components/chat/utils/__tests__/chat-conversations-api-golden.test.ts +0 -105
  203. package/src/components/chat/utils/chat-conversations-api.ts +0 -83
  204. /package/dist/{chunk-TSCIVH7T.js.map → chunk-2JNCZDJR.js.map} +0 -0
  205. /package/dist/{chunk-5L4ERWSW.js.map → chunk-75YW6ET4.js.map} +0 -0
  206. /package/dist/{chunk-VKCETV3C.js.map → chunk-BK6CCQG6.js.map} +0 -0
  207. /package/dist/{chunk-BLUL2TE3.js.map → chunk-EVMHJB6X.js.map} +0 -0
  208. /package/dist/{chunk-S6WBBSII.js.map → chunk-EZM5DNII.js.map} +0 -0
  209. /package/dist/{chunk-BVQEU5JB.js.map → chunk-GGQZBSFN.js.map} +0 -0
  210. /package/dist/{chunk-4T42D6YG.js.map → chunk-HLPAVYK7.js.map} +0 -0
  211. /package/dist/{chunk-XV7RFACE.js.map → chunk-KHOZ52NR.js.map} +0 -0
  212. /package/dist/{chunk-IW746HJ7.js.map → chunk-LRQCKSZC.js.map} +0 -0
  213. /package/dist/{chunk-FKBM6U43.js.map → chunk-MYBXCWEI.js.map} +0 -0
  214. /package/dist/{chunk-QTPHBCPI.js.map → chunk-NIAMPMKV.js.map} +0 -0
  215. /package/dist/{chunk-4XPPQDEM.js.map → chunk-PTK3CINU.js.map} +0 -0
  216. /package/dist/{chunk-7FUIRGMU.js.map → chunk-PX4IPM7Q.js.map} +0 -0
  217. /package/dist/{chunk-FGNUI4CC.js.map → chunk-R4UV366K.js.map} +0 -0
  218. /package/dist/{chunk-66HTVTZZ.js.map → chunk-SE3PVN64.js.map} +0 -0
  219. /package/dist/{chunk-CQRYXSHL.js.map → chunk-TZPVRWPU.js.map} +0 -0
  220. /package/dist/{chunk-RU3IKVY2.js.map → chunk-UAAXUFK6.js.map} +0 -0
  221. /package/dist/{chunk-ZABAXD4U.js.map → chunk-VIRTMRS4.js.map} +0 -0
  222. /package/dist/{chunk-3XFDRL32.js.map → chunk-WDWCQD75.js.map} +0 -0
  223. /package/dist/{chunk-QT35C6CW.js.map → chunk-WPN545FW.js.map} +0 -0
  224. /package/dist/{chunk-F2KBCLUG.js.map → chunk-WZJOILPU.js.map} +0 -0
  225. /package/dist/{chunk-KAADFO74.js.map → chunk-XNPAVMPB.js.map} +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/home/runner/work/openframe-oss-lib/openframe-oss-lib/openframe-frontend-core/dist/chunk-UPKZU6QU.cjs","../src/contexts/chat-runtime-context.tsx"],"names":[],"mappings":"AAAA,qFAAY;AACZ;AACA;ACiCA,8BAA0C;AAgPnC,IAAM,mBAAA,EAAqB,kCAAA,IAAsC,CAAA;AAQjE,SAAS,cAAA,CAAA,EAAqC;AACnD,EAAA,OAAO,+BAAA,kBAA6B,CAAA;AACtC;AAUO,SAAS,sBAAA,CAAA,EAAsC;AACpD,EAAA,MAAM,EAAA,EAAI,+BAAA,kBAA6B,CAAA;AACvC,EAAA,GAAA,CAAI,CAAC,CAAA,EAAG;AACN,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,IAMF,CAAA;AAAA,EACF;AACA,EAAA,OAAO,CAAA;AACT;ADnSA;AACA;AACE;AACA;AACA;AACF,kJAAC","file":"/home/runner/work/openframe-oss-lib/openframe-oss-lib/openframe-frontend-core/dist/chunk-UPKZU6QU.cjs","sourcesContent":[null,"'use client';\n\n/**\n * Chat runtime context — single seam for embedding the chat panel in a\n * different host (e.g. user1.openframe.ai reverse-proxying API calls\n * under /api/mingo-guide/* to hub.openframe.ai/api/*).\n *\n * Three concerns, one context:\n * 1. API endpoints: chatStreamUrl / approvalToolUrl / commandsUrl /\n * buildListUrl + attachment endpoints + chat-identity. The chat\n * reads them from runtime; hub vs embedded app supply different\n * strings via different providers.\n * 2. Navigation mode + callbacks: 'host' or 'embed' mode. Host wires\n * its own router/docNav via the optional `navigate` callback\n * (plain function, NOT a hook); embed forces new-tab via\n * `defaultContentOrigin` + lib's `resolveExternalNavigation`.\n * 3. Identity context: only `source` (required for localStorage\n * namespacing). The display identity (greeting first-name etc.)\n * comes from the server via `useChatIdentity()` — never injected\n * client-side, so it always matches the server-resolved auth.\n *\n * Sibling of EndpointsRuntimeContext (announcement bar, contact form,\n * access codes). Each runtime stays an independent React context so\n * embedders can opt into either feature without forcing the other.\n *\n * IMPORTANT for embedders: memoize the value passed to\n * `<ChatRuntimeContext.Provider value={...}>` (e.g. via React.useMemo).\n * Every change to its reference identity invalidates downstream\n * `useMemo` consumers (the chat input's slash-commands binding,\n * useNavLink's embed-resolution memo, useDocChat's streamFn factory).\n * The hub's `<HubRuntimeProvider>` already memoizes correctly with\n * stable deps. Embedded apps that build the value inline on each render\n * will pay an avoidable re-render cost across the entire chat tree.\n */\n\nimport { createContext, useContext } from 'react';\n\nimport type { ComposeContentUrl } from '../utils/content-href';\n\n/**\n * Runtime config consumed by the chat panel.\n */\nexport interface ChatRuntime {\n endpoints: {\n /** POST streaming chat. Hub: '/api/docs/chat'. */\n chatStreamUrl: string;\n /** POST agent approve/reject. Hub: '/api/chat/agent/confirm-tool'. */\n approvalToolUrl: string;\n /** Customer-ticket agent endpoints (Help Center). OPTIONAL — when unset,\n * the ticket hooks fall back to the bare hub paths\n * (`/api/chat/agent/{find-ticket,ticket-action,list-engagements}`).\n * Embedders behind a reverse proxy set these to their proxied paths\n * (e.g. `/content/api/chat/agent/...`) so tickets route through the SAME\n * endpoint config + proxy as every other endpoint. */\n findTicketUrl?: string;\n ticketActionUrl?: string;\n listEngagementsUrl?: string;\n /** Ticket live-stream + read-receipt endpoints (Help Center\n * realtime). OPTIONAL — unset → bare hub paths under the DEDICATED\n * ticket surface (`/api/tickets/{stream,read}` — deliberately NOT\n * the chat agent's `/api/chat/agent/*` prefix). Reverse-proxy\n * embedders set their proxied paths. Consumed by\n * `TicketLiveProvider`. The unread summary has NO endpoint — it\n * arrives as `ticket-summary` frames on the stream and in\n * `ticket-read` responses. */\n ticketStreamUrl?: string;\n ticketReadUrl?: string;\n /** GET slash-command catalog. Hub: '/api/docs/commands'. */\n commandsUrl: string;\n /** GET server-side conversation history (`?conversationId=<id>`) — the\n * chat panel's mount-time hydration read against the server transcript\n * store (localStorage keeps only the server-issued conversation id).\n * OPTIONAL — defaults to `<chatStreamUrl>/history`, which is correct for\n * same-origin hosts AND for reverse-proxy embedders (the proxied chat\n * prefix covers it). Set explicitly only when the history route lives\n * elsewhere. */\n chatHistoryUrl?: string;\n /**\n * Conversation-list surface for the SSE/Guide chat — the server-side\n * transcript store exposed as a dialog list:\n * GET `<url>?status=active|archived&cursor=&limit=&search=` → `{ dialogs, nextCursor }`\n * PATCH `<url>/<id>` with `{ title }` (rename) or `{ archived }` (archive / restore)\n * Hub: '/api/docs/chat/conversations'. OPTIONAL and NEVER derived: unset =\n * the Guide adapter has no dialog list and the panel keeps its single-thread\n * UI. Set it to enable the \"Current Chats\" rail / archive / rename in Guide\n * mode (the same UX openframe gets in Mingo mode). Selecting a row hydrates\n * through `chatHistoryUrl`.\n */\n chatConversationsUrl?: string;\n /** GET RAG-search endpoint behind `<DocSearchBar>` (the in-source search\n * bar mounted by `<DocViewer>` / `<DocsHubPage>` when `showAIChat` is on).\n * Hub: '/api/docs/search'. OPTIONAL — falls back to the hub path so\n * same-origin Next.js hosts don't need to set it. Cross-origin embedders\n * set their proxied path so the search bar routes through the same\n * reverse proxy as everything else. Same pattern as `findTicketUrl`. */\n docsSearchUrl?: string;\n /** POST internal-link resolver. The in-source markdown renderer (lib or\n * custom) calls `<DocViewer>`'s `handlers.onResolveLink(href, currentPath)`\n * for relative hrefs like `./getting-started/intro.md` — that callback\n * posts to this URL with `{ link, currentPath, source }` and expects a\n * `ResolveLinkResult` back. Hub: '/api/docs/resolve-link'. OPTIONAL — same\n * fall-back chain as `docsSearchUrl`: prop override → runtime → default. */\n docsResolveLinkUrl?: string;\n /** GET per-platform empty-state config (admin-edited in\n * `/admin/chat-config`): `{ greeting, enabledRagTableIds, suggestedQueries }`.\n * Hub: '/api/docs/empty-state'. OPTIONAL — the in-app (host-mode) chat\n * injects these values as SSR props instead, so it leaves this unset.\n * Cross-origin EMBEDDERS (no server hop) set it to their proxied path\n * (e.g. '/content/api/docs/empty-state') so `<EmbeddableChat>` can fetch\n * the greeting / quick-action chips / RAG-source filter at runtime. When\n * unset, the chat falls back to the explicit `emptyStateGreeting` /\n * `suggestedQueries` / `enabledRagTableIds` props (or in-code defaults). */\n emptyStateUrl?: string;\n /** Build the per-agent display-config URL for an OpenFrame AI agent\n * (Fae/Mingo). OPTIONAL. The returned endpoint MUST be byte-compatible\n * with the empty-state wire shape ({ greeting, suggestedQueries,\n * enabledRagTableIds }). When set AND `EmbeddableChat` receives an\n * `activeAgentSlug` in embed mode, the chat fetches THIS url instead of\n * `emptyStateUrl` to render the selected agent's greeting + suggested\n * prompts (the \"agent mode\" URL override). Hub: `(slug) =>\n * '/api/ai-agents/' + encodeURIComponent(slug)`. */\n aiAgentConfigUrl?: (slug: string) => string;\n /** Build entity-card list URL for a content type + ids. Hub delegates\n * to the rag-table-config registry; embedded app provides its own\n * per-type URL builder against the reverse proxy. Returns null when\n * the type has no list endpoint (caller skips rendering). */\n buildListUrl: (type: string, ids: string[]) => string | null;\n /** Chat-attachment endpoints — added for the v2 attachment feature.\n *\n * Three concerns:\n * - `attachmentUploadUrl` — POSTed by the chat-attachment hook\n * to mint a Supabase signed-upload-URL + HMAC view token.\n * - `attachmentViewUrlPrefix` — embedded in markdown URLs the\n * chat hosts in user message bubbles (`![]()` / `[Attached]`).\n * Stored in chat history; chosen at SEND time. In host mode the\n * relative `/api/storage/view/chat-attachments/` is sufficient\n * (same-origin); embedders supply an absolute hub URL so the\n * browser can fetch cross-origin.\n * - `identityUrl` — GET endpoint the `useChatIdentity` hook\n * hits to learn the `{authTier, source, attachmentsEnabled}`\n * capability bag for the current session. Used beyond chat\n * (tickets / contact form / any embedded surface that needs\n * to identify the proxied customer), so the name has no\n * \"chat\" prefix even though the consuming hook still does. */\n attachmentUploadUrl: string;\n attachmentViewUrlPrefix: string;\n identityUrl: string;\n /** Optional URL prefix for the image proxy (`<prefix>?url=<external>`).\n * When unset, lib's `getProxiedImageUrl` returns the original URL\n * unchanged. Hub default: '/api/image-proxy'. Embedders that don't\n * host an image-proxy route leave this undefined → images load\n * directly cross-origin (CORS-permitting). */\n imageProxyUrlPrefix?: string;\n /** Optional list of hostnames that should bypass the image proxy\n * (rendered direct). Hub uses ['openmsp.ai']; embedders typically\n * leave it unset. Matches the `skipDomains` parameter of\n * `getProxiedImageUrl`. */\n imageProxySkipDomains?: string[];\n /** Optional base URL for the branded og-placeholder image route — the\n * DEFAULT cover-image fallback for entity cards with no image. The lib\n * appends `?title=…` (+ `w`/`h` for square slots) itself, so this is\n * the base, NOT a full URL: relative (`/api/og-placeholder`) for same-\n * origin hosts, or the proxied path (`/content/api/og-placeholder`) for\n * cross-origin embedders. May carry baked-in query params (preserved when\n * the lib layers `title`/dimensions on top) — but per-platform brand\n * colors are NO LONGER baked here; the `/api/og-placeholder` route\n * resolves them server-side from the platform. Most hosts leave this unset\n * and let the lib derive the base from `imageProxyUrlPrefix`.\n *\n * OPTIONAL — when unset the lib derives the base from the sibling\n * `imageProxyUrlPrefix` (same API base, route name swapped), then falls\n * back to the relative `/api/og-placeholder`. So an embedder that already\n * proxies images needs NO og-placeholder wiring. See\n * `resolveOgPlaceholderBase` / `buildOgPlaceholderUrl` in `../utils`. */\n ogPlaceholderUrl?: string;\n /** Base URL prefix for the captions route (`/api/captions` — the native\n * `<track>` VTT endpoint every video surface uses since captions stopped\n * being burned into video pixels). Plain path base, no query params.\n * Embedders point it at their proxied route (e.g. `/content/api/captions`);\n * unset ⇒ the same-origin relative `/api/captions` (the hub). Consumed via\n * `getEntityCaptionUrls` / `rebaseCaptionsUrl` in\n * `components/features/captions-url.ts`. */\n captionsUrlPrefix?: string;\n /** Supabase storage origin (e.g. `https://xyz.supabase.co`) — used\n * by `useVideoWarmup` to scope the `<link rel=\"preload\" as=\"video\">`\n * hint to MP4s the deployment actually hosts. Hub wires it via\n * `getSupabaseStorageOrigin()`; embedders without a Supabase\n * storage origin leave it unset (preload is then skipped; Mux/\n * YouTube preconnect still fires). */\n supabaseStorageOrigin?: string;\n };\n navigation: {\n /** ONE knob, two behaviors:\n * - 'host' = use the host page's existing click-routing untouched.\n * The chat panel calls `navigate?.()` for in-app routing.\n * - 'embed' = guest inside another app: short-circuit at the top\n * of click handlers to force new-tab + absolutize via\n * resolveExternalNavigation. */\n mode: 'host' | 'embed';\n /** Embed-only fallback origin for relative URLs whose target platform\n * can't be inferred. Used by resolveExternalNavigation when\n * `targetPlatform` is null — without this, a relative `/foo` href would\n * window.open against the embedder's origin, which is WRONG.\n * Set to your content host (e.g. 'https://hub.openframe.ai').\n * Required by the embedded app whenever mode='embed'. */\n defaultContentOrigin?: string;\n /** Override for opening external URLs. MUST BE SYNCHRONOUS —\n * Safari/Firefox block popups opened outside a direct user gesture.\n * Default: window.open(href, '_blank', 'noopener,noreferrer'). */\n openExternal?: (href: string) => void;\n /** Optional in-app navigation callback (host-mode only).\n * Returns `true` if the host handled the click in-app\n * (router.push + docNav.navigate); returns `false`, `undefined`,\n * or `void` → lib falls back to window.location.assign(href).\n * Hub wires this via HubRuntimeProvider's HubNavigationWiring;\n * embedders not in Next.js leave it undefined. */\n navigate?: (input: { href: string; path?: string | null; targetPlatform?: string | null }) => boolean | void;\n /** Optional new-tab decision callback. Returns true → lib opens in\n * new tab; false → same tab via `navigate`. Hub wires the existing\n * `decideNewTab` logic from use-nav-link.tsx (re-imports the pure\n * helper from lib). Embedders may omit; lib defaults to:\n * same-origin/same-platform → same tab, else new tab. */\n decideNewTab?: (args: { href: string; targetPlatform?: string | null }) => boolean;\n };\n /** Optional content-URL composer. Returns the platform-aware href +\n * target-platform tuple for a content entity. Hub wires this to its\n * `buildContentURL(type, slug, extractPrimaryPlatform(platforms))`\n * pipeline so the lib catalog/detail views can derive cross-\n * platform hrefs without knowing the hub's platform topology\n * (openmsp.ai / openframe.app / flamingo.run / tmcg).\n *\n * THE single content-href authority for every embeddable surface — page\n * views (onboarding catalog/detail, releases) AND chat cards / chips /\n * search results all resolve content links through this one seam, so a\n * given type lands in the SAME place regardless of where it's rendered.\n * Embedders wire `makeComposeContentUrl({ hostedTypes, contentOrigin })`;\n * omit it and lib views fall back to a same-origin relative path\n * (`buildDefaultHref`).\n *\n * Takes a single `ComposeContentUrlInput`: `type` + `identifier` (page\n * views pass the slug; chat rows pass the id + `externalUrl`, whose path\n * yields the slug for in-app routing) + optional `platforms` /\n * `externalUrl` / `targetPlatform`. */\n composeContentUrl?: ComposeContentUrl;\n /** Per-`documentType` doc-viewer targets — the UNIFIED, DYNAMIC replacement for\n * the single `chipBasePlatform` prop. Maps a doc-table documentType\n * (`'markdown'`, `'data_room_doc'`, …) → `{ platform, basePath }` for the PUBLIC\n * doc viewer that hosts it. Doc chips with no `externalUrl` resolve PER ROW to\n * `getBaseUrl(platform)/<basePath>/<path>`, so a chat mixing several doc sources\n * sends EACH to its own home (markdown→flamingo/knowledge-base,\n * data_room_doc→company-hub/data-room) instead of one static fallback. The hub\n * may keep using `chipBasePlatform` (one doc source per platform); embedders that\n * surface multiple doc sources wire this. Threaded into `resolveSourceRowCTA`. */\n docPlatformTargets?: Record<string, { platform: string; basePath: string }>;\n /** Chat source / platform identifier — OPTIONAL. The hub sets it from\n * `currentPlatform()`; EMBEDDERS leave it unset and stay platform-agnostic.\n *\n * It is NOT required for chat to work. The wire resolves source server-side\n * (`/docs/chat|search|commands` reject any client `source`); the\n * same-tab-vs-new-tab link decision falls back to an origin comparison when\n * it's absent (`decideNewTab` → `isCrossOriginUrl`); and the localStorage\n * history namespace falls back to a stable constant. Set it only where the\n * client legitimately needs to know its platform a priori — i.e. the hub,\n * where several platforms share related origins so \"same platform\" can't be\n * inferred from a URL alone. */\n source?: string;\n // NOTE: No `user` field. The chat's display identity (greeting\n // first-name, etc.) comes from the SERVER-resolved auth via\n // `useChatIdentity()` — the same identity the server uses to\n // authorize requests. Letting embedders pass a client-side `user`\n // would let it desync from the actual auth tier, causing greetings\n // like \"Hey Bob\" while the server treats the session as\n // alice@example.com. Single source of truth: the server.\n}\n\nexport const ChatRuntimeContext = createContext<ChatRuntime | null>(null);\n\n/**\n * Returns the active runtime, or null when no provider is mounted.\n * NULL is a first-class value — it signals \"no chat runtime configured.\"\n * Optional consumers fall back to no-op behavior; strict consumers\n * use `useRequiredChatRuntime` (below).\n */\nexport function useChatRuntime(): ChatRuntime | null {\n return useContext(ChatRuntimeContext);\n}\n\n/**\n * Strict variant used INSIDE the chat panel. Throws if no provider.\n * The hub guarantees one exists by mounting `<HubRuntimeProvider>` at\n * root; the embedded app mounts its own `<ChatRuntimeContext.Provider>`\n * at the tree root. In Jest / Storybook tests that render chat\n * internals directly, wrap with `<HubRuntimeProvider>` (hub defaults)\n * or supply `<ChatRuntimeContext.Provider value={mockedRuntime}>`.\n */\nexport function useRequiredChatRuntime(): ChatRuntime {\n const v = useContext(ChatRuntimeContext);\n if (!v) {\n throw new Error(\n '[chat-runtime] hook called outside a <ChatRuntimeContext.Provider>. ' +\n 'The hub mounts <HubRuntimeProvider> at root — this only fires when ' +\n 'chat internals are rendered above the provider tree. ' +\n 'Fix: ensure the rendering subtree descends from the runtime provider. ' +\n 'In tests/Storybook: wrap with <HubRuntimeProvider> or supply ' +\n 'a <ChatRuntimeContext.Provider value={mockedRuntime}>.',\n );\n }\n return v;\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/contexts/chat-runtime-context.tsx"],"sourcesContent":["'use client';\n\n/**\n * Chat runtime context — single seam for embedding the chat panel in a\n * different host (e.g. user1.openframe.ai reverse-proxying API calls\n * under /api/mingo-guide/* to hub.openframe.ai/api/*).\n *\n * Three concerns, one context:\n * 1. API endpoints: chatStreamUrl / approvalToolUrl / commandsUrl /\n * buildListUrl + attachment endpoints + chat-identity. The chat\n * reads them from runtime; hub vs embedded app supply different\n * strings via different providers.\n * 2. Navigation mode + callbacks: 'host' or 'embed' mode. Host wires\n * its own router/docNav via the optional `navigate` callback\n * (plain function, NOT a hook); embed forces new-tab via\n * `defaultContentOrigin` + lib's `resolveExternalNavigation`.\n * 3. Identity context: only `source` (required for localStorage\n * namespacing). The display identity (greeting first-name etc.)\n * comes from the server via `useChatIdentity()` — never injected\n * client-side, so it always matches the server-resolved auth.\n *\n * Sibling of EndpointsRuntimeContext (announcement bar, contact form,\n * access codes). Each runtime stays an independent React context so\n * embedders can opt into either feature without forcing the other.\n *\n * IMPORTANT for embedders: memoize the value passed to\n * `<ChatRuntimeContext.Provider value={...}>` (e.g. via React.useMemo).\n * Every change to its reference identity invalidates downstream\n * `useMemo` consumers (the chat input's slash-commands binding,\n * useNavLink's embed-resolution memo, useDocChat's streamFn factory).\n * The hub's `<HubRuntimeProvider>` already memoizes correctly with\n * stable deps. Embedded apps that build the value inline on each render\n * will pay an avoidable re-render cost across the entire chat tree.\n */\n\nimport { createContext, useContext } from 'react';\n\nimport type { ComposeContentUrl } from '../utils/content-href';\n\n/**\n * Runtime config consumed by the chat panel.\n */\nexport interface ChatRuntime {\n endpoints: {\n /** POST streaming chat. Hub: '/api/docs/chat'. */\n chatStreamUrl: string;\n /** POST agent approve/reject. Hub: '/api/chat/agent/confirm-tool'. */\n approvalToolUrl: string;\n /** Customer-ticket agent endpoints (Help Center). OPTIONAL — when unset,\n * the ticket hooks fall back to the bare hub paths\n * (`/api/chat/agent/{find-ticket,ticket-action,list-engagements}`).\n * Embedders behind a reverse proxy set these to their proxied paths\n * (e.g. `/content/api/chat/agent/...`) so tickets route through the SAME\n * endpoint config + proxy as every other endpoint. */\n findTicketUrl?: string;\n ticketActionUrl?: string;\n listEngagementsUrl?: string;\n /** Ticket live-stream + read-receipt endpoints (Help Center\n * realtime). OPTIONAL — unset → bare hub paths under the DEDICATED\n * ticket surface (`/api/tickets/{stream,read}` — deliberately NOT\n * the chat agent's `/api/chat/agent/*` prefix). Reverse-proxy\n * embedders set their proxied paths. Consumed by\n * `TicketLiveProvider`. The unread summary has NO endpoint — it\n * arrives as `ticket-summary` frames on the stream and in\n * `ticket-read` responses. */\n ticketStreamUrl?: string;\n ticketReadUrl?: string;\n /** GET slash-command catalog. Hub: '/api/docs/commands'. */\n commandsUrl: string;\n /** GET server-side conversation history (`?conversationId=<id>`) — the\n * chat panel's mount-time hydration read against the server transcript\n * store (localStorage keeps only the server-issued conversation id).\n * OPTIONAL — defaults to `<chatStreamUrl>/history`, which is correct for\n * same-origin hosts AND for reverse-proxy embedders (the proxied chat\n * prefix covers it). Set explicitly only when the history route lives\n * elsewhere. */\n chatHistoryUrl?: string;\n /**\n * Conversation-list surface for the SSE/Guide chat — the server-side\n * transcript store exposed as a dialog list:\n * GET `<url>?status=active|archived&cursor=&limit=&search=` → `{ dialogs, nextCursor }`\n * PATCH `<url>/<id>` with `{ title }` (rename) or `{ archived }` (archive / restore)\n * Hub: '/api/docs/chat/conversations'. OPTIONAL and NEVER derived: unset =\n * the Guide adapter has no dialog list and the panel keeps its single-thread\n * UI. Set it to enable the \"Current Chats\" rail / archive / rename in Guide\n * mode (the same UX openframe gets in Mingo mode). Selecting a row hydrates\n * through `chatHistoryUrl`.\n */\n chatConversationsUrl?: string;\n /** GET RAG-search endpoint behind `<DocSearchBar>` (the in-source search\n * bar mounted by `<DocViewer>` / `<DocsHubPage>` when `showAIChat` is on).\n * Hub: '/api/docs/search'. OPTIONAL — falls back to the hub path so\n * same-origin Next.js hosts don't need to set it. Cross-origin embedders\n * set their proxied path so the search bar routes through the same\n * reverse proxy as everything else. Same pattern as `findTicketUrl`. */\n docsSearchUrl?: string;\n /** POST internal-link resolver. The in-source markdown renderer (lib or\n * custom) calls `<DocViewer>`'s `handlers.onResolveLink(href, currentPath)`\n * for relative hrefs like `./getting-started/intro.md` — that callback\n * posts to this URL with `{ link, currentPath, source }` and expects a\n * `ResolveLinkResult` back. Hub: '/api/docs/resolve-link'. OPTIONAL — same\n * fall-back chain as `docsSearchUrl`: prop override → runtime → default. */\n docsResolveLinkUrl?: string;\n /** GET per-platform empty-state config (admin-edited in\n * `/admin/chat-config`): `{ greeting, enabledRagTableIds, suggestedQueries }`.\n * Hub: '/api/docs/empty-state'. OPTIONAL — the in-app (host-mode) chat\n * injects these values as SSR props instead, so it leaves this unset.\n * Cross-origin EMBEDDERS (no server hop) set it to their proxied path\n * (e.g. '/content/api/docs/empty-state') so `<EmbeddableChat>` can fetch\n * the greeting / quick-action chips / RAG-source filter at runtime. When\n * unset, the chat falls back to the explicit `emptyStateGreeting` /\n * `suggestedQueries` / `enabledRagTableIds` props (or in-code defaults). */\n emptyStateUrl?: string;\n /** Build the per-agent display-config URL for an OpenFrame AI agent\n * (Fae/Mingo). OPTIONAL. The returned endpoint MUST be byte-compatible\n * with the empty-state wire shape ({ greeting, suggestedQueries,\n * enabledRagTableIds }). When set AND `EmbeddableChat` receives an\n * `activeAgentSlug` in embed mode, the chat fetches THIS url instead of\n * `emptyStateUrl` to render the selected agent's greeting + suggested\n * prompts (the \"agent mode\" URL override). Hub: `(slug) =>\n * '/api/ai-agents/' + encodeURIComponent(slug)`. */\n aiAgentConfigUrl?: (slug: string) => string;\n /** Build entity-card list URL for a content type + ids. Hub delegates\n * to the rag-table-config registry; embedded app provides its own\n * per-type URL builder against the reverse proxy. Returns null when\n * the type has no list endpoint (caller skips rendering). */\n buildListUrl: (type: string, ids: string[]) => string | null;\n /** Chat-attachment endpoints — added for the v2 attachment feature.\n *\n * Three concerns:\n * - `attachmentUploadUrl` — POSTed by the chat-attachment hook\n * to mint a Supabase signed-upload-URL + HMAC view token.\n * - `attachmentViewUrlPrefix` — embedded in markdown URLs the\n * chat hosts in user message bubbles (`![]()` / `[Attached]`).\n * Stored in chat history; chosen at SEND time. In host mode the\n * relative `/api/storage/view/chat-attachments/` is sufficient\n * (same-origin); embedders supply an absolute hub URL so the\n * browser can fetch cross-origin.\n * - `identityUrl` — GET endpoint the `useChatIdentity` hook\n * hits to learn the `{authTier, source, attachmentsEnabled}`\n * capability bag for the current session. Used beyond chat\n * (tickets / contact form / any embedded surface that needs\n * to identify the proxied customer), so the name has no\n * \"chat\" prefix even though the consuming hook still does. */\n attachmentUploadUrl: string;\n attachmentViewUrlPrefix: string;\n identityUrl: string;\n /** Optional URL prefix for the image proxy (`<prefix>?url=<external>`).\n * When unset, lib's `getProxiedImageUrl` returns the original URL\n * unchanged. Hub default: '/api/image-proxy'. Embedders that don't\n * host an image-proxy route leave this undefined → images load\n * directly cross-origin (CORS-permitting). */\n imageProxyUrlPrefix?: string;\n /** Optional list of hostnames that should bypass the image proxy\n * (rendered direct). Hub uses ['openmsp.ai']; embedders typically\n * leave it unset. Matches the `skipDomains` parameter of\n * `getProxiedImageUrl`. */\n imageProxySkipDomains?: string[];\n /** Optional base URL for the branded og-placeholder image route — the\n * DEFAULT cover-image fallback for entity cards with no image. The lib\n * appends `?title=…` (+ `w`/`h` for square slots) itself, so this is\n * the base, NOT a full URL: relative (`/api/og-placeholder`) for same-\n * origin hosts, or the proxied path (`/content/api/og-placeholder`) for\n * cross-origin embedders. May carry baked-in query params (preserved when\n * the lib layers `title`/dimensions on top) — but per-platform brand\n * colors are NO LONGER baked here; the `/api/og-placeholder` route\n * resolves them server-side from the platform. Most hosts leave this unset\n * and let the lib derive the base from `imageProxyUrlPrefix`.\n *\n * OPTIONAL — when unset the lib derives the base from the sibling\n * `imageProxyUrlPrefix` (same API base, route name swapped), then falls\n * back to the relative `/api/og-placeholder`. So an embedder that already\n * proxies images needs NO og-placeholder wiring. See\n * `resolveOgPlaceholderBase` / `buildOgPlaceholderUrl` in `../utils`. */\n ogPlaceholderUrl?: string;\n /** Base URL prefix for the captions route (`/api/captions` — the native\n * `<track>` VTT endpoint every video surface uses since captions stopped\n * being burned into video pixels). Plain path base, no query params.\n * Embedders point it at their proxied route (e.g. `/content/api/captions`);\n * unset ⇒ the same-origin relative `/api/captions` (the hub). Consumed via\n * `getEntityCaptionUrls` / `rebaseCaptionsUrl` in\n * `components/features/captions-url.ts`. */\n captionsUrlPrefix?: string;\n /** Supabase storage origin (e.g. `https://xyz.supabase.co`) — used\n * by `useVideoWarmup` to scope the `<link rel=\"preload\" as=\"video\">`\n * hint to MP4s the deployment actually hosts. Hub wires it via\n * `getSupabaseStorageOrigin()`; embedders without a Supabase\n * storage origin leave it unset (preload is then skipped; Mux/\n * YouTube preconnect still fires). */\n supabaseStorageOrigin?: string;\n };\n navigation: {\n /** ONE knob, two behaviors:\n * - 'host' = use the host page's existing click-routing untouched.\n * The chat panel calls `navigate?.()` for in-app routing.\n * - 'embed' = guest inside another app: short-circuit at the top\n * of click handlers to force new-tab + absolutize via\n * resolveExternalNavigation. */\n mode: 'host' | 'embed';\n /** Embed-only fallback origin for relative URLs whose target platform\n * can't be inferred. Used by resolveExternalNavigation when\n * `targetPlatform` is null — without this, a relative `/foo` href would\n * window.open against the embedder's origin, which is WRONG.\n * Set to your content host (e.g. 'https://hub.openframe.ai').\n * Required by the embedded app whenever mode='embed'. */\n defaultContentOrigin?: string;\n /** Override for opening external URLs. MUST BE SYNCHRONOUS —\n * Safari/Firefox block popups opened outside a direct user gesture.\n * Default: window.open(href, '_blank', 'noopener,noreferrer'). */\n openExternal?: (href: string) => void;\n /** Optional in-app navigation callback (host-mode only).\n * Returns `true` if the host handled the click in-app\n * (router.push + docNav.navigate); returns `false`, `undefined`,\n * or `void` → lib falls back to window.location.assign(href).\n * Hub wires this via HubRuntimeProvider's HubNavigationWiring;\n * embedders not in Next.js leave it undefined. */\n navigate?: (input: { href: string; path?: string | null; targetPlatform?: string | null }) => boolean | void;\n /** Optional new-tab decision callback. Returns true → lib opens in\n * new tab; false → same tab via `navigate`. Hub wires the existing\n * `decideNewTab` logic from use-nav-link.tsx (re-imports the pure\n * helper from lib). Embedders may omit; lib defaults to:\n * same-origin/same-platform → same tab, else new tab. */\n decideNewTab?: (args: { href: string; targetPlatform?: string | null }) => boolean;\n };\n /** Optional content-URL composer. Returns the platform-aware href +\n * target-platform tuple for a content entity. Hub wires this to its\n * `buildContentURL(type, slug, extractPrimaryPlatform(platforms))`\n * pipeline so the lib catalog/detail views can derive cross-\n * platform hrefs without knowing the hub's platform topology\n * (openmsp.ai / openframe.app / flamingo.run / tmcg).\n *\n * THE single content-href authority for every embeddable surface — page\n * views (onboarding catalog/detail, releases) AND chat cards / chips /\n * search results all resolve content links through this one seam, so a\n * given type lands in the SAME place regardless of where it's rendered.\n * Embedders wire `makeComposeContentUrl({ hostedTypes, contentOrigin })`;\n * omit it and lib views fall back to a same-origin relative path\n * (`buildDefaultHref`).\n *\n * Takes a single `ComposeContentUrlInput`: `type` + `identifier` (page\n * views pass the slug; chat rows pass the id + `externalUrl`, whose path\n * yields the slug for in-app routing) + optional `platforms` /\n * `externalUrl` / `targetPlatform`. */\n composeContentUrl?: ComposeContentUrl;\n /** Per-`documentType` doc-viewer targets — the UNIFIED, DYNAMIC replacement for\n * the single `chipBasePlatform` prop. Maps a doc-table documentType\n * (`'markdown'`, `'data_room_doc'`, …) → `{ platform, basePath }` for the PUBLIC\n * doc viewer that hosts it. Doc chips with no `externalUrl` resolve PER ROW to\n * `getBaseUrl(platform)/<basePath>/<path>`, so a chat mixing several doc sources\n * sends EACH to its own home (markdown→flamingo/knowledge-base,\n * data_room_doc→company-hub/data-room) instead of one static fallback. The hub\n * may keep using `chipBasePlatform` (one doc source per platform); embedders that\n * surface multiple doc sources wire this. Threaded into `resolveSourceRowCTA`. */\n docPlatformTargets?: Record<string, { platform: string; basePath: string }>;\n /** Chat source / platform identifier — OPTIONAL. The hub sets it from\n * `currentPlatform()`; EMBEDDERS leave it unset and stay platform-agnostic.\n *\n * It is NOT required for chat to work. The wire resolves source server-side\n * (`/docs/chat|search|commands` reject any client `source`); the\n * same-tab-vs-new-tab link decision falls back to an origin comparison when\n * it's absent (`decideNewTab` → `isCrossOriginUrl`); and the localStorage\n * history namespace falls back to a stable constant. Set it only where the\n * client legitimately needs to know its platform a priori — i.e. the hub,\n * where several platforms share related origins so \"same platform\" can't be\n * inferred from a URL alone. */\n source?: string;\n // NOTE: No `user` field. The chat's display identity (greeting\n // first-name, etc.) comes from the SERVER-resolved auth via\n // `useChatIdentity()` — the same identity the server uses to\n // authorize requests. Letting embedders pass a client-side `user`\n // would let it desync from the actual auth tier, causing greetings\n // like \"Hey Bob\" while the server treats the session as\n // alice@example.com. Single source of truth: the server.\n}\n\nexport const ChatRuntimeContext = createContext<ChatRuntime | null>(null);\n\n/**\n * Returns the active runtime, or null when no provider is mounted.\n * NULL is a first-class value — it signals \"no chat runtime configured.\"\n * Optional consumers fall back to no-op behavior; strict consumers\n * use `useRequiredChatRuntime` (below).\n */\nexport function useChatRuntime(): ChatRuntime | null {\n return useContext(ChatRuntimeContext);\n}\n\n/**\n * Strict variant used INSIDE the chat panel. Throws if no provider.\n * The hub guarantees one exists by mounting `<HubRuntimeProvider>` at\n * root; the embedded app mounts its own `<ChatRuntimeContext.Provider>`\n * at the tree root. In Jest / Storybook tests that render chat\n * internals directly, wrap with `<HubRuntimeProvider>` (hub defaults)\n * or supply `<ChatRuntimeContext.Provider value={mockedRuntime}>`.\n */\nexport function useRequiredChatRuntime(): ChatRuntime {\n const v = useContext(ChatRuntimeContext);\n if (!v) {\n throw new Error(\n '[chat-runtime] hook called outside a <ChatRuntimeContext.Provider>. ' +\n 'The hub mounts <HubRuntimeProvider> at root — this only fires when ' +\n 'chat internals are rendered above the provider tree. ' +\n 'Fix: ensure the rendering subtree descends from the runtime provider. ' +\n 'In tests/Storybook: wrap with <HubRuntimeProvider> or supply ' +\n 'a <ChatRuntimeContext.Provider value={mockedRuntime}>.',\n );\n }\n return v;\n}\n"],"mappings":";;;AAmCA,SAAS,eAAe,kBAAkB;AAgPnC,IAAM,qBAAqB,cAAkC,IAAI;AAQjE,SAAS,iBAAqC;AACnD,SAAO,WAAW,kBAAkB;AACtC;AAUO,SAAS,yBAAsC;AACpD,QAAM,IAAI,WAAW,kBAAkB;AACvC,MAAI,CAAC,GAAG;AACN,UAAM,IAAI;AAAA,MACR;AAAA,IAMF;AAAA,EACF;AACA,SAAO;AACT;","names":[]}
@@ -1,68 +0,0 @@
1
- import type { DialogItem } from '../types/component.types';
2
- import type { FetchDialogsParams, FetchDialogsResult } from '../types/unified-chat-state.types';
3
- export interface UseManagedDialogListArgs {
4
- /** Gates the AUTOMATIC first-page load only (every other operation is
5
- * caller-driven). The adapters pass their own `active` gate so an idle
6
- * transport does no network; the Chat Archive passes `false` because it
7
- * loads on OPEN, which `openArchive` drives explicitly. */
8
- autoLoad: boolean;
9
- /** Pages the active dialog list. Absent = the hook is inert. */
10
- fetchDialogs?: (params: FetchDialogsParams) => Promise<FetchDialogsResult>;
11
- /** Backend rename — absent = `renameDialog` is a no-op. */
12
- renameDialog?: (id: string, title: string) => Promise<void>;
13
- /** Backend archive — absent = `archiveDialog` is a no-op. */
14
- archiveDialog?: (id: string) => Promise<void>;
15
- /** Backend delete — absent = `deleteDialog` is a no-op. */
16
- deleteDialog?: (id: string) => Promise<void>;
17
- /** Page size sent as `limit`. */
18
- pageSize: number;
19
- /** Delay before a FIRST-PAGE load raises `isDialogsLoading` (the full-view
20
- * skeleton), so a cached/fast fetch never flashes one. `0` (default) raises
21
- * it immediately. Pagination always shows its indicator at once — the list
22
- * stays visible. Use `isDialogsPending` for "a fetch is in flight". */
23
- skeletonDelayMs?: number;
24
- /** Server-side search term. `undefined` = no search support (the NATS
25
- * adapter never sets it, so its wire params stay `{cursor, limit}`); any
26
- * string change — including back to `''` — reloads page 1 with `search`. */
27
- search?: string;
28
- /** Fires AFTER a row was removed locally by a successful archive/delete.
29
- * Read through a latest-ref so its identity never enters the mutation
30
- * callbacks' deps. */
31
- onDialogRemoved?: (id: string, reason: 'archived' | 'deleted') => void;
32
- /** Console prefix for failure logs (`[useNatsChatAdapter]`, `[useSseChatAdapter]`). */
33
- logTag: string;
34
- }
35
- export interface UseManagedDialogListResult {
36
- dialogs: DialogItem[];
37
- dialogsNextCursor: string | null;
38
- /** Skeleton flag — true while a page request is in flight, subject to
39
- * `skeletonDelayMs` on a first-page load. */
40
- isDialogsLoading: boolean;
41
- /** A fetch is in flight, set SYNCHRONOUSLY and independent of
42
- * `skeletonDelayMs` — so an empty state stays suppressed during the delay
43
- * instead of flashing "no results" before the skeleton appears. */
44
- isDialogsPending: boolean;
45
- /** True when the FIRST page failed — a pagination failure keeps the loaded rows. */
46
- dialogsError: boolean;
47
- hasMoreDialogs: boolean;
48
- /** Load a page: `undefined` cursor = (re)load the first page. */
49
- loadDialogsPage: (cursor?: string) => Promise<void>;
50
- /** Retry / refresh the first page. */
51
- reloadDialogs: () => void;
52
- loadMoreDialogs: () => Promise<void>;
53
- renameDialog: (id: string, title: string) => Promise<void>;
54
- archiveDialog: (id: string) => Promise<void>;
55
- deleteDialog: (id: string) => Promise<void>;
56
- /** Prepend a row (dedupes by id) — a freshly created conversation. */
57
- upsertDialogTop: (item: DialogItem) => void;
58
- /** Drop a row locally, WITHOUT calling a backend callback — for a mutation
59
- * the caller performed itself (e.g. restoring an archived dialog removes it
60
- * from the archived list). No-op for an unknown id. */
61
- removeDialog: (id: string) => void;
62
- /** Move an existing row to the head of the list with a fresh `timestamp` —
63
- * what a new turn does server-side (`last_message_at desc`). No-op for an
64
- * id the list doesn't hold. */
65
- bumpDialogToTop: (id: string) => void;
66
- }
67
- export declare function useManagedDialogList({ autoLoad, fetchDialogs, renameDialog: renameDialogCallback, archiveDialog: archiveDialogCallback, deleteDialog: deleteDialogCallback, pageSize, skeletonDelayMs, search, onDialogRemoved, logTag, }: UseManagedDialogListArgs): UseManagedDialogListResult;
68
- //# sourceMappingURL=use-managed-dialog-list.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-managed-dialog-list.d.ts","sourceRoot":"","sources":["../../../../src/components/chat/hooks/use-managed-dialog-list.ts"],"names":[],"mappings":"AA0BA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,KAAK,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AAEhG,MAAM,WAAW,wBAAwB;IACvC;;;gEAG4D;IAC5D,QAAQ,EAAE,OAAO,CAAC;IAClB,gEAAgE;IAChE,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,kBAAkB,KAAK,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAC3E,2DAA2D;IAC3D,YAAY,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5D,6DAA6D;IAC7D,aAAa,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9C,2DAA2D;IAC3D,YAAY,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7C,iCAAiC;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB;;;4EAGwE;IACxE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;iFAE6E;IAC7E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;2BAEuB;IACvB,eAAe,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,GAAG,SAAS,KAAK,IAAI,CAAC;IACvE,uFAAuF;IACvF,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,0BAA0B;IACzC,OAAO,EAAE,UAAU,EAAE,CAAC;IACtB,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC;kDAC8C;IAC9C,gBAAgB,EAAE,OAAO,CAAC;IAC1B;;wEAEoE;IACpE,gBAAgB,EAAE,OAAO,CAAC;IAC1B,oFAAoF;IACpF,YAAY,EAAE,OAAO,CAAC;IACtB,cAAc,EAAE,OAAO,CAAC;IACxB,iEAAiE;IACjE,eAAe,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACpD,sCAAsC;IACtC,aAAa,EAAE,MAAM,IAAI,CAAC;IAC1B,eAAe,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACrC,YAAY,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3D,aAAa,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7C,YAAY,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5C,sEAAsE;IACtE,eAAe,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;IAC5C;;4DAEwD;IACxD,YAAY,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC;;oCAEgC;IAChC,eAAe,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;CACvC;AAED,wBAAgB,oBAAoB,CAAC,EACnC,QAAQ,EACR,YAAY,EACZ,YAAY,EAAE,oBAAoB,EAClC,aAAa,EAAE,qBAAqB,EACpC,YAAY,EAAE,oBAAoB,EAClC,QAAQ,EACR,eAAmB,EACnB,MAAM,EACN,eAAe,EACf,MAAM,GACP,EAAE,wBAAwB,GAAG,0BAA0B,CAwQvD"}
@@ -1,29 +0,0 @@
1
- /**
2
- * Conversation-list wire client for the SSE/Guide chat — the ONE place the
3
- * `ChatRuntime.endpoints.chatConversationsUrl` contract is spelled out:
4
- *
5
- * GET `<base>?status=active|archived&limit=&cursor=&search=`
6
- * → route-base envelope `{ data: { dialogs, nextCursor } }`
7
- * PATCH `<base>/<id>` body `{ title }` (rename)
8
- * PATCH `<base>/<id>` body `{ archived: true }` (archive)
9
- * PATCH `<base>/<id>` body `{ archived: false }` (restore)
10
- *
11
- * Goes through `embedAuthedFetch` with its DEFAULT credentials mode — the
12
- * hub identifies anonymous visitors with an httpOnly cookie, and
13
- * `same-origin` is exactly what carries it. Never override `credentials`.
14
- *
15
- * Wire rows are mapped to `DialogItem`; the ISO `timestamp` becomes a
16
- * `Date` so the list's Today/Yesterday/Older grouping is deterministic.
17
- */
18
- import type { FetchDialogsParams, FetchDialogsResult } from '../types/unified-chat-state.types';
19
- export type ChatConversationStatus = 'active' | 'archived';
20
- export interface ChatConversationsApi {
21
- fetchDialogs(params: FetchDialogsParams & {
22
- status: ChatConversationStatus;
23
- }): Promise<FetchDialogsResult>;
24
- renameDialog(id: string, title: string): Promise<void>;
25
- archiveDialog(id: string): Promise<void>;
26
- unarchiveDialog(id: string): Promise<void>;
27
- }
28
- export declare function createChatConversationsApi(baseUrl: string): ChatConversationsApi;
29
- //# sourceMappingURL=chat-conversations-api.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"chat-conversations-api.d.ts","sourceRoot":"","sources":["../../../../src/components/chat/utils/chat-conversations-api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAMH,OAAO,KAAK,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AAEhG,MAAM,MAAM,sBAAsB,GAAG,QAAQ,GAAG,UAAU,CAAC;AAE3D,MAAM,WAAW,oBAAoB;IACnC,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG;QAAE,MAAM,EAAE,sBAAsB,CAAA;KAAE,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAC3G,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvD,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACzC,eAAe,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5C;AAqBD,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,MAAM,GAAG,oBAAoB,CA8BhF"}
@@ -1,22 +0,0 @@
1
- /**
2
- * Narrowing primitives for untrusted hub JSON — ONE owner, shared by every
3
- * client that talks to a hub route (`use-chat-history-hydration`, the
4
- * conversation-list client, the NATS decoder).
5
- *
6
- * `unwrapEnvelope` encodes the response contract in one place. The hub's
7
- * route-base `successResponse` is `NextResponse.json(data)` — a RAW body, which
8
- * is the shape these clients normally see. The `{ data }` branch is defensive,
9
- * for an embedder or gateway that proxies our routes inside an envelope of its
10
- * own; it is not the hub's shape. (A payload whose own top-level key is `data`
11
- * would be unwrapped by mistake — none of ours has one.)
12
- */
13
-
14
- /** `typeof null === 'object'`, so the null check is the whole point. */
15
- export function isRecord(value: unknown): value is Record<string, unknown> {
16
- return typeof value === 'object' && value !== null;
17
- }
18
-
19
- /** route-base `{ data }` envelope, with a raw-body fallback. */
20
- export function unwrapEnvelope(payload: unknown): unknown {
21
- return isRecord(payload) && 'data' in payload ? payload.data : payload;
22
- }
@@ -1,31 +0,0 @@
1
- <!-- source-hash: 1f02c7279bc34fe9463df2e1bfb625b6 -->
2
- The ONE dialog-list state machine shared by both transport adapters — NATS/Mingo managed-dialog mode and the SSE/Guide adapter when `ChatRuntime.endpoints.chatConversationsUrl` is set. Extracted from `useNatsChatAdapter` so Guide mode reuses the exact list/paging/mutation semantics openframe-frontend already relies on.
3
-
4
- ## Key Components
5
-
6
- ### `useManagedDialogList(args)`
7
- Owns the loaded `DialogItem[]` page, the server cursor, first-page loading/error state (with the retry re-arm), cursor pagination, an optional server-side `search` term (a change re-runs page 1) and the optimistic rename / archive / delete mutations. Does NOT own the active dialog id, message history or the transport — the adapters layer those on top via `onDialogRemoved`.
8
-
9
- ### `UseManagedDialogListArgs`
10
- - `autoLoad` — gates the AUTOMATIC first-page load only. The adapters pass their own `active` gate; the Chat Archive passes `false` and drives page 1 from `openArchive`
11
- - `fetchDialogs` / `renameDialog` / `archiveDialog` / `deleteDialog` — host callbacks; presence IS the capability (absent = inert / no-op)
12
- - `pageSize` — sent as `limit`
13
- - `search` — `undefined` = no search support (NATS keeps `{cursor, limit}` wire params); any string change reloads page 1 with `search`
14
- - `onDialogRemoved(id, 'archived' | 'deleted')` — fires AFTER the local removal, read through a latest-ref
15
- - `logTag` — console prefix for failure logs
16
-
17
- ### `UseManagedDialogListResult`
18
- `dialogs`, `dialogsNextCursor`, `isDialogsLoading` (subject to `skeletonDelayMs`), `isDialogsPending` (synchronous in-flight flag), `dialogsError`, `hasMoreDialogs`, `loadDialogsPage`, `reloadDialogs`, `loadMoreDialogs`, `renameDialog`, `archiveDialog`, `deleteDialog`, plus `upsertDialogTop(item)` (prepend + dedupe), `removeDialog(id)` (local-only drop, for a mutation the caller performed itself) and `bumpDialogToTop(id)` (re-head with a fresh timestamp, matching the server's `last_message_at desc`).
19
-
20
- ## Behavioural contracts
21
-
22
- - `isDialogsLoading` reads true from the FIRST render whenever a first page is coming (and again synchronously on every search change, including clearing one), so a consumer branching on "the list is empty" never sees a settled-and-empty frame before the request starts.
23
- - A monotonic request id means only the LATEST page-1 load may touch the list, cursor or flags — search-as-you-type, the end-of-turn refresh and an unarchive all overlap, and without it the last-resolving response wins.
24
- - Appends dedupe by id: a row whose `last_message_at` moved between page fetches can come back on a later page.
25
- - Only the FIRST page failing sets `dialogsError`; a pagination failure keeps the loaded rows.
26
- - Rename, archive and delete failures are logged AND re-thrown (rename after rolling its optimistic title back), so a confirmation modal can stay open for a retry instead of closing over a write the server rejected. This is a deliberate contract change from the pre-extraction NATS adapter, which swallowed them — see `UnifiedChatState`.
27
- - Rename is optimistic; the rollback title is read synchronously from a live ref at call time (capturing it inside a `setState` updater was unreliable — the updater may run after an immediately-rejecting callback reaches the catch).
28
-
29
- ## Source
30
-
31
- [`use-managed-dialog-list.ts`](https://github.com/flamingo-stack/openframe-oss-lib/blob/main/use-managed-dialog-list.ts)
@@ -1,280 +0,0 @@
1
- /**
2
- * Unit tests for the shared `useManagedDialogList` hook — the parts the NATS
3
- * characterization test cannot reach: `upsertDialogTop` dedupe,
4
- * `bumpDialogToTop` ordering, append dedupe, out-of-order page-1 responses,
5
- * the `onDialogRemoved` reasons, and the inert no-`fetchDialogs` shape.
6
- */
7
-
8
- import { renderHook, act, waitFor } from '@testing-library/react';
9
- import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
10
- import { useManagedDialogList } from '../use-managed-dialog-list';
11
-
12
- const page = (ids: string[], nextCursor: string | null = null) => ({
13
- dialogs: ids.map(id => ({ id, title: `Chat ${id}` })),
14
- nextCursor,
15
- });
16
-
17
- describe('useManagedDialogList', () => {
18
- beforeEach(() => {
19
- vi.spyOn(console, 'error').mockImplementation(() => {});
20
- });
21
- afterEach(() => {
22
- vi.restoreAllMocks();
23
- });
24
-
25
- it('reports loading from the FIRST render when a load is coming', async () => {
26
- let resolve: ((v: ReturnType<typeof page>) => void) | undefined;
27
- const fetchDialogs = vi.fn(
28
- () =>
29
- new Promise<ReturnType<typeof page>>(r => {
30
- resolve = r;
31
- }),
32
- );
33
- const { result } = renderHook(() =>
34
- useManagedDialogList({ autoLoad: true, pageSize: 20, logTag: '[t]', fetchDialogs }),
35
- );
36
- // Before the effect has even run: a consumer branching on "empty list" must
37
- // not see a settled-and-empty state.
38
- expect(result.current.isDialogsLoading).toBe(true);
39
- expect(result.current.dialogs).toEqual([]);
40
- await act(async () => {
41
- resolve?.(page(['a']));
42
- await Promise.resolve();
43
- });
44
- expect(result.current.isDialogsLoading).toBe(false);
45
- expect(result.current.dialogs.map(d => d.id)).toEqual(['a']);
46
- });
47
-
48
- it('re-enters loading synchronously on a search change, including clearing it', async () => {
49
- const resolvers: Array<(v: ReturnType<typeof page>) => void> = [];
50
- const fetchDialogs = vi.fn(
51
- () =>
52
- new Promise<ReturnType<typeof page>>(r => {
53
- resolvers.push(r);
54
- }),
55
- );
56
- const { result, rerender } = renderHook(
57
- ({ search }) => useManagedDialogList({ autoLoad: true, pageSize: 20, logTag: '[t]', fetchDialogs, search }),
58
- { initialProps: { search: '' } },
59
- );
60
- await act(async () => {
61
- resolvers[0](page(['a']));
62
- await Promise.resolve();
63
- });
64
- expect(result.current.isDialogsLoading).toBe(false);
65
-
66
- rerender({ search: 'zzz' });
67
- expect(result.current.isDialogsLoading).toBe(true);
68
- await act(async () => {
69
- resolvers[1](page([]));
70
- await Promise.resolve();
71
- });
72
- expect(result.current.isDialogsLoading).toBe(false);
73
- expect(result.current.dialogs).toEqual([]);
74
-
75
- // Clearing the term must ALSO read as loading again, not as "settled empty".
76
- rerender({ search: '' });
77
- expect(result.current.isDialogsLoading).toBe(true);
78
- });
79
-
80
- it('a REJECTED first page still settles — the list must not stick on a skeleton', async () => {
81
- const fetchDialogs = vi.fn(() => Promise.reject(new Error('down')));
82
- const { result } = renderHook(() =>
83
- useManagedDialogList({ autoLoad: true, pageSize: 20, logTag: '[t]', fetchDialogs }),
84
- );
85
- expect(result.current.isDialogsLoading).toBe(true);
86
- await waitFor(() => expect(result.current.dialogsError).toBe(true));
87
- expect(result.current.isDialogsLoading).toBe(false);
88
- });
89
-
90
- it('a superseded response never settles the NEWER search term', async () => {
91
- const resolvers: Array<(v: ReturnType<typeof page>) => void> = [];
92
- const fetchDialogs = vi.fn(
93
- () =>
94
- new Promise<ReturnType<typeof page>>(r => {
95
- resolvers.push(r);
96
- }),
97
- );
98
- const { result, rerender } = renderHook(
99
- ({ search }) => useManagedDialogList({ autoLoad: true, pageSize: 20, logTag: '[t]', fetchDialogs, search }),
100
- { initialProps: { search: 'a' } },
101
- );
102
- await waitFor(() => expect(resolvers.length).toBe(1));
103
- rerender({ search: 'ab' });
104
- await waitFor(() => expect(resolvers.length).toBe(2));
105
- await act(async () => {
106
- resolvers[0](page([]));
107
- await Promise.resolve();
108
- });
109
- expect(result.current.isDialogsLoading).toBe(true);
110
- await act(async () => {
111
- resolvers[1](page([]));
112
- await Promise.resolve();
113
- });
114
- expect(result.current.isDialogsLoading).toBe(false);
115
- });
116
-
117
- it('re-arms when autoLoad turns on after mount (panel opened in the other mode)', async () => {
118
- let resolve: ((v: ReturnType<typeof page>) => void) | undefined;
119
- const fetchDialogs = vi.fn(
120
- () =>
121
- new Promise<ReturnType<typeof page>>(r => {
122
- resolve = r;
123
- }),
124
- );
125
- const { result, rerender } = renderHook(
126
- ({ autoLoad }) => useManagedDialogList({ autoLoad, pageSize: 20, logTag: '[t]', fetchDialogs }),
127
- { initialProps: { autoLoad: false } },
128
- );
129
- expect(result.current.isDialogsLoading).toBe(false);
130
- expect(fetchDialogs).not.toHaveBeenCalled();
131
-
132
- rerender({ autoLoad: true });
133
- // Must NOT read as settled-and-empty for a frame before the effect fires.
134
- expect(result.current.isDialogsLoading).toBe(true);
135
- await waitFor(() => expect(fetchDialogs).toHaveBeenCalledTimes(1));
136
- await act(async () => {
137
- resolve?.(page(['a']));
138
- await Promise.resolve();
139
- });
140
- expect(result.current.isDialogsLoading).toBe(false);
141
- expect(result.current.dialogs.map(d => d.id)).toEqual(['a']);
142
- });
143
-
144
- it('an archive-style consumer (autoLoad false) is settled from the start', () => {
145
- const { result } = renderHook(() =>
146
- useManagedDialogList({
147
- autoLoad: false,
148
- pageSize: 20,
149
- logTag: '[t]',
150
- fetchDialogs: () => Promise.resolve(page([])),
151
- }),
152
- );
153
- expect(result.current.isDialogsLoading).toBe(false);
154
- });
155
-
156
- it('is inert without fetchDialogs', () => {
157
- const { result } = renderHook(() => useManagedDialogList({ autoLoad: true, pageSize: 20, logTag: '[t]' }));
158
- expect(result.current.dialogs).toEqual([]);
159
- expect(result.current.hasMoreDialogs).toBe(false);
160
- expect(result.current.isDialogsLoading).toBe(false);
161
- });
162
-
163
- it('upsertDialogTop prepends + dedupes; bumpDialogToTop re-heads the row', async () => {
164
- const fetchDialogs = vi.fn(() => Promise.resolve(page(['a', 'b'])));
165
- const { result } = renderHook(() =>
166
- useManagedDialogList({ autoLoad: true, pageSize: 20, logTag: '[t]', fetchDialogs }),
167
- );
168
- await waitFor(() => expect(result.current.dialogs.length).toBe(2));
169
- act(() => result.current.upsertDialogTop({ id: 'b', title: 'B again' }));
170
- expect(result.current.dialogs.map(d => [d.id, d.title])).toEqual([
171
- ['b', 'B again'],
172
- ['a', 'Chat a'],
173
- ]);
174
- act(() => result.current.bumpDialogToTop('a'));
175
- expect(result.current.dialogs.map(d => d.id)).toEqual(['a', 'b']);
176
- expect(result.current.dialogs[0].timestamp).toBeInstanceOf(Date);
177
- // Unknown id is a no-op, not an insert.
178
- act(() => result.current.bumpDialogToTop('nope'));
179
- expect(result.current.dialogs.map(d => d.id)).toEqual(['a', 'b']);
180
- });
181
-
182
- it('drops a superseded page-1 response and dedupes appended pages', async () => {
183
- const resolvers: Array<(v: ReturnType<typeof page>) => void> = [];
184
- const fetchDialogs = vi.fn(() => new Promise<ReturnType<typeof page>>(resolve => resolvers.push(resolve)));
185
- const { result, rerender } = renderHook(
186
- ({ search }) => useManagedDialogList({ autoLoad: true, pageSize: 20, logTag: '[t]', fetchDialogs, search }),
187
- { initialProps: { search: 'a' } },
188
- );
189
- await waitFor(() => expect(resolvers.length).toBe(1));
190
- rerender({ search: 'ab' });
191
- await waitFor(() => expect(resolvers.length).toBe(2));
192
-
193
- // The NEWER request resolves first, then the stale one lands.
194
- await act(async () => {
195
- resolvers[1](page(['new'], 'cursor-new'));
196
- await Promise.resolve();
197
- });
198
- await act(async () => {
199
- resolvers[0](page(['stale'], 'cursor-stale'));
200
- await Promise.resolve();
201
- });
202
- expect(result.current.dialogs.map(d => d.id)).toEqual(['new']);
203
- expect(result.current.hasMoreDialogs).toBe(true);
204
-
205
- // Appended pages drop ids already rendered (a row can move between pages).
206
- await act(async () => {
207
- const p = result.current.loadMoreDialogs();
208
- resolvers[2](page(['new', 'later'], null));
209
- await p;
210
- });
211
- expect(result.current.dialogs.map(d => d.id)).toEqual(['new', 'later']);
212
- });
213
-
214
- it('re-throws a failed archive/delete so a confirmation modal can stay open', async () => {
215
- const { result } = renderHook(() =>
216
- useManagedDialogList({
217
- autoLoad: true,
218
- pageSize: 20,
219
- logTag: '[t]',
220
- fetchDialogs: () => Promise.resolve(page(['a'])),
221
- archiveDialog: () => Promise.reject(new Error('429')),
222
- deleteDialog: () => Promise.reject(new Error('boom')),
223
- }),
224
- );
225
- await waitFor(() => expect(result.current.dialogs.length).toBe(1));
226
- await act(async () => {
227
- await expect(result.current.archiveDialog('a')).rejects.toThrow('429');
228
- await expect(result.current.deleteDialog('a')).rejects.toThrow('boom');
229
- });
230
- // The row survives a failed write.
231
- expect(result.current.dialogs.map(d => d.id)).toEqual(['a']);
232
- });
233
-
234
- it('reports removal reasons AFTER the local removal', async () => {
235
- const seen: Array<[string, string, number]> = [];
236
- let latest: string[] = [];
237
- const { result } = renderHook(() =>
238
- useManagedDialogList({
239
- autoLoad: true,
240
- pageSize: 20,
241
- logTag: '[t]',
242
- fetchDialogs: () => Promise.resolve(page(['a', 'b'])),
243
- archiveDialog: () => Promise.resolve(),
244
- deleteDialog: () => Promise.resolve(),
245
- onDialogRemoved: (id, reason) => seen.push([id, reason, latest.length]),
246
- }),
247
- );
248
- await waitFor(() => expect(result.current.dialogs.length).toBe(2));
249
- latest = result.current.dialogs.map(d => d.id);
250
- await act(async () => {
251
- await result.current.archiveDialog('a');
252
- });
253
- await act(async () => {
254
- await result.current.deleteDialog('b');
255
- });
256
- expect(seen.map(([id, reason]) => [id, reason])).toEqual([
257
- ['a', 'archived'],
258
- ['b', 'deleted'],
259
- ]);
260
- expect(result.current.dialogs).toEqual([]);
261
- });
262
-
263
- it('mutations without their callback are no-ops', async () => {
264
- const { result } = renderHook(() =>
265
- useManagedDialogList({
266
- autoLoad: true,
267
- pageSize: 20,
268
- logTag: '[t]',
269
- fetchDialogs: () => Promise.resolve(page(['a'])),
270
- }),
271
- );
272
- await waitFor(() => expect(result.current.dialogs.length).toBe(1));
273
- await act(async () => {
274
- await result.current.renameDialog('a', 'x');
275
- await result.current.archiveDialog('a');
276
- await result.current.deleteDialog('a');
277
- });
278
- expect(result.current.dialogs.map(d => [d.id, d.title])).toEqual([['a', 'Chat a']]);
279
- });
280
- });