@flamingo-stack/openframe-frontend-core 0.0.598 → 0.0.599-2039.5717.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 (206) hide show
  1. package/dist/chat-protocol/index.cjs +8 -1
  2. package/dist/chat-protocol/index.cjs.map +1 -1
  3. package/dist/chat-protocol/index.d.ts +1 -0
  4. package/dist/chat-protocol/index.d.ts.map +1 -1
  5. package/dist/chat-protocol/index.js +7 -2
  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/chat-protocol/wire-narrow.d.ts +17 -0
  9. package/dist/chat-protocol/wire-narrow.d.ts.map +1 -0
  10. package/dist/{chunk-BK6CCQG6.js → chunk-2R6F56U5.js} +12 -12
  11. package/dist/{chunk-STYNZ4QM.cjs → chunk-3IXDZI3R.cjs} +3 -3
  12. package/dist/{chunk-STYNZ4QM.cjs.map → chunk-3IXDZI3R.cjs.map} +1 -1
  13. package/dist/{chunk-QIKBISZM.cjs → chunk-4ZAQSPCQ.cjs} +242 -242
  14. package/dist/{chunk-QIKBISZM.cjs.map → chunk-4ZAQSPCQ.cjs.map} +1 -1
  15. package/dist/{chunk-JVZVVZOZ.cjs → chunk-5DORSDXA.cjs} +9 -9
  16. package/dist/{chunk-JVZVVZOZ.cjs.map → chunk-5DORSDXA.cjs.map} +1 -1
  17. package/dist/{chunk-YWBAIFI2.cjs → chunk-6D4DUONA.cjs} +105 -105
  18. package/dist/{chunk-YWBAIFI2.cjs.map → chunk-6D4DUONA.cjs.map} +1 -1
  19. package/dist/{chunk-KHOZ52NR.js → chunk-7654NDQB.js} +6 -6
  20. package/dist/{chunk-DI3SVVY5.cjs → chunk-AC5SWE3S.cjs} +85 -85
  21. package/dist/{chunk-DI3SVVY5.cjs.map → chunk-AC5SWE3S.cjs.map} +1 -1
  22. package/dist/{chunk-R4UV366K.js → chunk-AJU3NYAA.js} +6 -6
  23. package/dist/{chunk-GHYFVT52.js → chunk-B23ID4DM.js} +5 -5
  24. package/dist/{chunk-SE3PVN64.js → chunk-B6HSRLC5.js} +2 -2
  25. package/dist/{chunk-EVMHJB6X.js → chunk-BLUL2TE3.js} +4 -4
  26. package/dist/{chunk-GGQZBSFN.js → chunk-BVQEU5JB.js} +2 -2
  27. package/dist/{chunk-75YW6ET4.js → chunk-C4APMQWW.js} +4 -4
  28. package/dist/{chunk-H64ZHSYR.cjs → chunk-CCWI3622.cjs} +4 -4
  29. package/dist/{chunk-H64ZHSYR.cjs.map → chunk-CCWI3622.cjs.map} +1 -1
  30. package/dist/{chunk-WPN545FW.js → chunk-CVYVYSP2.js} +12 -12
  31. package/dist/{chunk-YH6IQTPI.cjs → chunk-EHAYNUOL.cjs} +3 -3
  32. package/dist/{chunk-YH6IQTPI.cjs.map → chunk-EHAYNUOL.cjs.map} +1 -1
  33. package/dist/{chunk-VIRTMRS4.js → chunk-EZOI5UR3.js} +7 -7
  34. package/dist/{chunk-WZJOILPU.js → chunk-F2KBCLUG.js} +2 -2
  35. package/dist/{chunk-MYBXCWEI.js → chunk-FKBM6U43.js} +2 -2
  36. package/dist/{chunk-2SYX2Z7R.cjs → chunk-GIG3WQTF.cjs} +34 -34
  37. package/dist/{chunk-2SYX2Z7R.cjs.map → chunk-GIG3WQTF.cjs.map} +1 -1
  38. package/dist/{chunk-LRQCKSZC.js → chunk-IW746HJ7.js} +2 -2
  39. package/dist/{chunk-YBPFIXV4.cjs → chunk-IYEKAU4X.cjs} +801 -482
  40. package/dist/chunk-IYEKAU4X.cjs.map +1 -0
  41. package/dist/{chunk-VLJTJAHJ.cjs → chunk-J3ODLFCA.cjs} +25 -25
  42. package/dist/{chunk-VLJTJAHJ.cjs.map → chunk-J3ODLFCA.cjs.map} +1 -1
  43. package/dist/{chunk-UE7OFLLS.cjs → chunk-J4RRF2EP.cjs} +14 -14
  44. package/dist/{chunk-UE7OFLLS.cjs.map → chunk-J4RRF2EP.cjs.map} +1 -1
  45. package/dist/{chunk-M4YQUHOR.cjs → chunk-JJUV7Z4L.cjs} +15 -15
  46. package/dist/{chunk-M4YQUHOR.cjs.map → chunk-JJUV7Z4L.cjs.map} +1 -1
  47. package/dist/{chunk-UG7JNQZY.cjs → chunk-JKFWKPHW.cjs} +37 -37
  48. package/dist/{chunk-UG7JNQZY.cjs.map → chunk-JKFWKPHW.cjs.map} +1 -1
  49. package/dist/{chunk-3WSS7C2V.cjs → chunk-KAHI4QWA.cjs} +15 -15
  50. package/dist/{chunk-3WSS7C2V.cjs.map → chunk-KAHI4QWA.cjs.map} +1 -1
  51. package/dist/{chunk-VNSRNVPD.js → chunk-KJ5EQ6P6.js} +728 -409
  52. package/dist/chunk-KJ5EQ6P6.js.map +1 -0
  53. package/dist/{chunk-V2QK5W3O.cjs → chunk-L64FTMML.cjs} +3 -3
  54. package/dist/{chunk-V2QK5W3O.cjs.map → chunk-L64FTMML.cjs.map} +1 -1
  55. package/dist/{chunk-P24VPJTT.cjs → chunk-LT6GIGMZ.cjs} +15 -15
  56. package/dist/{chunk-P24VPJTT.cjs.map → chunk-LT6GIGMZ.cjs.map} +1 -1
  57. package/dist/{chunk-WDWCQD75.js → chunk-LVVDTK5X.js} +9 -9
  58. package/dist/{chunk-HWAYIK4U.cjs → chunk-MSPYY2F4.cjs} +22 -22
  59. package/dist/{chunk-HWAYIK4U.cjs.map → chunk-MSPYY2F4.cjs.map} +1 -1
  60. package/dist/{chunk-QD64Q4I2.cjs → chunk-N7LOLURS.cjs} +9 -9
  61. package/dist/{chunk-QD64Q4I2.cjs.map → chunk-N7LOLURS.cjs.map} +1 -1
  62. package/dist/{chunk-TZPVRWPU.js → chunk-O33JVUR5.js} +5 -5
  63. package/dist/{chunk-HLPAVYK7.js → chunk-ODPN724R.js} +4 -4
  64. package/dist/{chunk-NIAMPMKV.js → chunk-OQNKAF4F.js} +4 -4
  65. package/dist/{chunk-SAEJGTCI.cjs → chunk-QPAPUIF3.cjs} +35 -35
  66. package/dist/{chunk-SAEJGTCI.cjs.map → chunk-QPAPUIF3.cjs.map} +1 -1
  67. package/dist/{chunk-BPVHDDNY.cjs → chunk-R2VBMBPJ.cjs} +8 -8
  68. package/dist/{chunk-BPVHDDNY.cjs.map → chunk-R2VBMBPJ.cjs.map} +1 -1
  69. package/dist/{chunk-UAAXUFK6.js → chunk-RU3IKVY2.js} +3 -3
  70. package/dist/{chunk-EZM5DNII.js → chunk-S6WBBSII.js} +3 -3
  71. package/dist/{chunk-2JNCZDJR.js → chunk-TSCIVH7T.js} +2 -2
  72. package/dist/{chunk-PX4IPM7Q.js → chunk-TYY6HOTI.js} +3 -3
  73. package/dist/{chunk-RDTOMWDN.cjs → chunk-UPKZU6QU.cjs} +1 -1
  74. package/dist/chunk-UPKZU6QU.cjs.map +1 -0
  75. package/dist/{chunk-WCBRZCU4.cjs → chunk-UQEOAPAI.cjs} +9 -9
  76. package/dist/{chunk-WCBRZCU4.cjs.map → chunk-UQEOAPAI.cjs.map} +1 -1
  77. package/dist/{chunk-O4VZOA2Q.cjs → chunk-UXOOVP77.cjs} +3 -3
  78. package/dist/{chunk-O4VZOA2Q.cjs.map → chunk-UXOOVP77.cjs.map} +1 -1
  79. package/dist/{chunk-PTK3CINU.js → chunk-VELZVF3F.js} +5 -5
  80. package/dist/{chunk-BZEWPW5A.cjs → chunk-VIBREYUK.cjs} +3 -3
  81. package/dist/{chunk-BZEWPW5A.cjs.map → chunk-VIBREYUK.cjs.map} +1 -1
  82. package/dist/{chunk-RYXIRVDC.js → chunk-YB6FI2G3.js} +1 -1
  83. package/dist/chunk-YB6FI2G3.js.map +1 -0
  84. package/dist/{chunk-DAPOBLAK.cjs → chunk-YEO6W4CT.cjs} +39 -39
  85. package/dist/{chunk-DAPOBLAK.cjs.map → chunk-YEO6W4CT.cjs.map} +1 -1
  86. package/dist/{chunk-XNPAVMPB.js → chunk-YUELNVD5.js} +5 -5
  87. package/dist/components/case-studies/index.cjs +14 -14
  88. package/dist/components/case-studies/index.js +8 -8
  89. package/dist/components/chat/embeddable-chat.d.ts +10 -19
  90. package/dist/components/chat/embeddable-chat.d.ts.map +1 -1
  91. package/dist/components/chat/hooks/index.d.ts +1 -0
  92. package/dist/components/chat/hooks/index.d.ts.map +1 -1
  93. package/dist/components/chat/hooks/use-chat-history-hydration.d.ts +13 -3
  94. package/dist/components/chat/hooks/use-chat-history-hydration.d.ts.map +1 -1
  95. package/dist/components/chat/hooks/use-managed-dialog-list.d.ts +53 -0
  96. package/dist/components/chat/hooks/use-managed-dialog-list.d.ts.map +1 -0
  97. package/dist/components/chat/hooks/use-nats-chat-adapter.d.ts +2 -16
  98. package/dist/components/chat/hooks/use-nats-chat-adapter.d.ts.map +1 -1
  99. package/dist/components/chat/hooks/use-sse-chat-adapter.d.ts.map +1 -1
  100. package/dist/components/chat/hooks/use-unified-chat.d.ts +12 -1
  101. package/dist/components/chat/hooks/use-unified-chat.d.ts.map +1 -1
  102. package/dist/components/chat/index.cjs +11 -5
  103. package/dist/components/chat/index.cjs.map +1 -1
  104. package/dist/components/chat/index.js +10 -4
  105. package/dist/components/chat/types/unified-chat-state.types.d.ts +86 -6
  106. package/dist/components/chat/types/unified-chat-state.types.d.ts.map +1 -1
  107. package/dist/components/chat/utils/chat-conversations-api.d.ts +29 -0
  108. package/dist/components/chat/utils/chat-conversations-api.d.ts.map +1 -0
  109. package/dist/components/chat/utils/index.d.ts +1 -0
  110. package/dist/components/chat/utils/index.d.ts.map +1 -1
  111. package/dist/components/contact/index.cjs +9 -9
  112. package/dist/components/contact/index.js +8 -8
  113. package/dist/components/docs/index.cjs +12 -12
  114. package/dist/components/docs/index.js +11 -11
  115. package/dist/components/embeds/index.cjs +9 -9
  116. package/dist/components/embeds/index.js +8 -8
  117. package/dist/components/faq/index.cjs +10 -10
  118. package/dist/components/faq/index.js +9 -9
  119. package/dist/components/features/index.cjs +8 -8
  120. package/dist/components/features/index.js +7 -7
  121. package/dist/components/help-center-pages/index.cjs +31 -31
  122. package/dist/components/help-center-pages/index.js +22 -22
  123. package/dist/components/index.cjs +72 -66
  124. package/dist/components/index.cjs.map +1 -1
  125. package/dist/components/index.js +28 -22
  126. package/dist/components/index.js.map +1 -1
  127. package/dist/components/meeting-scheduler/index.cjs +49 -49
  128. package/dist/components/meeting-scheduler/index.js +9 -9
  129. package/dist/components/navigation/index.cjs +11 -11
  130. package/dist/components/navigation/index.js +10 -10
  131. package/dist/components/onboarding-guides/index.cjs +12 -12
  132. package/dist/components/onboarding-guides/index.js +11 -11
  133. package/dist/components/related-content/index.cjs +7 -7
  134. package/dist/components/related-content/index.js +6 -6
  135. package/dist/components/tickets/index.cjs +13 -13
  136. package/dist/components/tickets/index.js +12 -12
  137. package/dist/components/ui/index.cjs +14 -8
  138. package/dist/components/ui/index.cjs.map +1 -1
  139. package/dist/components/ui/index.js +13 -7
  140. package/dist/contexts/chat-runtime-context.d.ts +12 -0
  141. package/dist/contexts/chat-runtime-context.d.ts.map +1 -1
  142. package/dist/contexts/index.cjs +2 -2
  143. package/dist/contexts/index.js +1 -1
  144. package/dist/hooks/index.cjs +5 -5
  145. package/dist/hooks/index.js +4 -4
  146. package/dist/index.cjs +18 -12
  147. package/dist/index.cjs.map +1 -1
  148. package/dist/index.js +17 -11
  149. package/dist/index.js.map +1 -1
  150. package/package.json +1 -1
  151. package/src/chat-protocol/index.ts +1 -0
  152. package/src/chat-protocol/nats-decoder.ts +1 -5
  153. package/src/chat-protocol/wire-narrow.ts +22 -0
  154. package/src/components/chat/.embeddable-chat.md +4 -2
  155. package/src/components/chat/embeddable-chat.tsx +131 -87
  156. package/src/components/chat/hooks/.index.md +1 -1
  157. package/src/components/chat/hooks/.use-managed-dialog-list.md +31 -0
  158. package/src/components/chat/hooks/.use-nats-chat-adapter.md +3 -1
  159. package/src/components/chat/hooks/.use-sse-chat-adapter.md +8 -1
  160. package/src/components/chat/hooks/.use-unified-chat.md +2 -2
  161. package/src/components/chat/hooks/__tests__/managed-dialog-list.test.ts +280 -0
  162. package/src/components/chat/hooks/__tests__/nats-adapter-managed-dialogs.test.ts +193 -0
  163. package/src/components/chat/hooks/__tests__/sse-managed-dialogs.test.ts +310 -0
  164. package/src/components/chat/hooks/__tests__/unified-chat-dialog-capabilities.test.ts +129 -0
  165. package/src/components/chat/hooks/index.ts +2 -0
  166. package/src/components/chat/hooks/use-chat-history-hydration.ts +67 -24
  167. package/src/components/chat/hooks/use-managed-dialog-list.ts +339 -0
  168. package/src/components/chat/hooks/use-nats-chat-adapter.ts +64 -150
  169. package/src/components/chat/hooks/use-sse-chat-adapter.ts +238 -59
  170. package/src/components/chat/hooks/use-unified-chat.ts +26 -2
  171. package/src/components/chat/types/.unified-chat-state.types.md +13 -1
  172. package/src/components/chat/types/unified-chat-state.types.ts +93 -6
  173. package/src/components/chat/utils/.chat-conversations-api.md +16 -0
  174. package/src/components/chat/utils/.index.md +1 -1
  175. package/src/components/chat/utils/__tests__/chat-conversations-api-golden.test.ts +105 -0
  176. package/src/components/chat/utils/chat-conversations-api.ts +83 -0
  177. package/src/components/chat/utils/index.ts +7 -0
  178. package/src/contexts/.chat-runtime-context.md +3 -1
  179. package/src/contexts/chat-runtime-context.tsx +12 -0
  180. package/dist/chunk-RDTOMWDN.cjs.map +0 -1
  181. package/dist/chunk-RYXIRVDC.js.map +0 -1
  182. package/dist/chunk-VNSRNVPD.js.map +0 -1
  183. package/dist/chunk-YBPFIXV4.cjs.map +0 -1
  184. /package/dist/{chunk-BK6CCQG6.js.map → chunk-2R6F56U5.js.map} +0 -0
  185. /package/dist/{chunk-KHOZ52NR.js.map → chunk-7654NDQB.js.map} +0 -0
  186. /package/dist/{chunk-R4UV366K.js.map → chunk-AJU3NYAA.js.map} +0 -0
  187. /package/dist/{chunk-GHYFVT52.js.map → chunk-B23ID4DM.js.map} +0 -0
  188. /package/dist/{chunk-SE3PVN64.js.map → chunk-B6HSRLC5.js.map} +0 -0
  189. /package/dist/{chunk-EVMHJB6X.js.map → chunk-BLUL2TE3.js.map} +0 -0
  190. /package/dist/{chunk-GGQZBSFN.js.map → chunk-BVQEU5JB.js.map} +0 -0
  191. /package/dist/{chunk-75YW6ET4.js.map → chunk-C4APMQWW.js.map} +0 -0
  192. /package/dist/{chunk-WPN545FW.js.map → chunk-CVYVYSP2.js.map} +0 -0
  193. /package/dist/{chunk-VIRTMRS4.js.map → chunk-EZOI5UR3.js.map} +0 -0
  194. /package/dist/{chunk-WZJOILPU.js.map → chunk-F2KBCLUG.js.map} +0 -0
  195. /package/dist/{chunk-MYBXCWEI.js.map → chunk-FKBM6U43.js.map} +0 -0
  196. /package/dist/{chunk-LRQCKSZC.js.map → chunk-IW746HJ7.js.map} +0 -0
  197. /package/dist/{chunk-WDWCQD75.js.map → chunk-LVVDTK5X.js.map} +0 -0
  198. /package/dist/{chunk-TZPVRWPU.js.map → chunk-O33JVUR5.js.map} +0 -0
  199. /package/dist/{chunk-HLPAVYK7.js.map → chunk-ODPN724R.js.map} +0 -0
  200. /package/dist/{chunk-NIAMPMKV.js.map → chunk-OQNKAF4F.js.map} +0 -0
  201. /package/dist/{chunk-UAAXUFK6.js.map → chunk-RU3IKVY2.js.map} +0 -0
  202. /package/dist/{chunk-EZM5DNII.js.map → chunk-S6WBBSII.js.map} +0 -0
  203. /package/dist/{chunk-2JNCZDJR.js.map → chunk-TSCIVH7T.js.map} +0 -0
  204. /package/dist/{chunk-PX4IPM7Q.js.map → chunk-TYY6HOTI.js.map} +0 -0
  205. /package/dist/{chunk-PTK3CINU.js.map → chunk-VELZVF3F.js.map} +0 -0
  206. /package/dist/{chunk-XNPAVMPB.js.map → chunk-YUELNVD5.js.map} +0 -0
@@ -170,7 +170,7 @@ import {
170
170
  safeHref,
171
171
  sortBitesByCreatedAtDesc,
172
172
  useCoverImageFallback
173
- } from "./chunk-UAAXUFK6.js";
173
+ } from "./chunk-RU3IKVY2.js";
174
174
  import {
175
175
  next_image_default
176
176
  } from "./chunk-MDKCTSDS.js";
@@ -183,14 +183,14 @@ import {
183
183
  getPlatformDisplayName,
184
184
  useAuthedAssetSrc,
185
185
  useAuthedImageSrc
186
- } from "./chunk-MYBXCWEI.js";
186
+ } from "./chunk-FKBM6U43.js";
187
187
  import {
188
188
  OpenFrameLogo
189
189
  } from "./chunk-OTX6XNSA.js";
190
190
  import {
191
191
  useChatRuntime,
192
192
  useRequiredChatRuntime
193
- } from "./chunk-RYXIRVDC.js";
193
+ } from "./chunk-YB6FI2G3.js";
194
194
  import {
195
195
  COLLISION_PADDING_PX,
196
196
  CollisionBoundaryContext,
@@ -16030,6 +16030,9 @@ var NETWORK_CONFIG = {
16030
16030
  RETRY_BACKOFF_MULTIPLIER: 2
16031
16031
  };
16032
16032
 
16033
+ // src/components/chat/types/unified-chat-state.types.ts
16034
+ var EMPTY_DIALOG_CAPABILITIES = Object.freeze({});
16035
+
16033
16036
  // src/components/chat/hooks/use-chunk-catchup.ts
16034
16037
  import { useCallback as useCallback13, useEffect as useEffect22, useRef as useRef19 } from "react";
16035
16038
  function makeSeqKey(messageType, chunkType, sequenceId) {
@@ -17764,7 +17767,7 @@ function useChat({
17764
17767
  }
17765
17768
 
17766
17769
  // src/components/chat/hooks/use-sse-chat-adapter.ts
17767
- import { useCallback as useCallback20, useMemo as useMemo25, useRef as useRef28 } from "react";
17770
+ import { useCallback as useCallback21, useMemo as useMemo26, useRef as useRef29, useState as useState41 } from "react";
17768
17771
 
17769
17772
  // src/chat-protocol/confirm-tool.ts
17770
17773
  function buildConfirmToolBody(request) {
@@ -20251,6 +20254,62 @@ function pruneStaleChatConversationStorage(source) {
20251
20254
  }
20252
20255
  }
20253
20256
 
20257
+ // src/chat-protocol/wire-narrow.ts
20258
+ function isRecord(value) {
20259
+ return typeof value === "object" && value !== null;
20260
+ }
20261
+ function unwrapEnvelope(payload) {
20262
+ return isRecord(payload) && "data" in payload ? payload.data : payload;
20263
+ }
20264
+
20265
+ // src/components/chat/utils/chat-conversations-api.ts
20266
+ function toDialogItem(row) {
20267
+ if (!isRecord(row)) return null;
20268
+ const id = typeof row.id === "string" ? row.id : "";
20269
+ if (!id) return null;
20270
+ const title = typeof row.title === "string" && row.title.length > 0 ? row.title : "Untitled chat";
20271
+ const ts = typeof row.timestamp === "string" ? new Date(row.timestamp) : void 0;
20272
+ return {
20273
+ id,
20274
+ title,
20275
+ ...ts && !Number.isNaN(ts.getTime()) ? { timestamp: ts } : {},
20276
+ ...typeof row.lastMessage === "string" ? { lastMessage: row.lastMessage } : {}
20277
+ };
20278
+ }
20279
+ async function failWith(response, fallback) {
20280
+ const message = await readServerErrorMessage(response);
20281
+ throw new Error(message ?? `${fallback}: ${response.status}`);
20282
+ }
20283
+ function createChatConversationsApi(baseUrl) {
20284
+ const base = baseUrl.replace(/\/+$/, "");
20285
+ const patch = async (id, body, what) => {
20286
+ const response = await embedAuthedFetch(`${base}/${encodeURIComponent(id)}`, {
20287
+ method: "PATCH",
20288
+ body: JSON.stringify(body)
20289
+ });
20290
+ if (!response.ok) await failWith(response, `${what} failed`);
20291
+ };
20292
+ return {
20293
+ async fetchDialogs({ status, cursor, limit, search }) {
20294
+ const qs = new URLSearchParams();
20295
+ qs.set("status", status);
20296
+ if (limit !== void 0) qs.set("limit", String(limit));
20297
+ if (cursor) qs.set("cursor", cursor);
20298
+ if (search) qs.set("search", search);
20299
+ const response = await embedAuthedFetch(`${base}?${qs.toString()}`, { method: "GET" });
20300
+ if (!response.ok) await failWith(response, "Conversation list failed");
20301
+ const body = unwrapEnvelope(await response.json());
20302
+ const rawDialogs = isRecord(body) && Array.isArray(body.dialogs) ? body.dialogs : [];
20303
+ const dialogs = rawDialogs.map(toDialogItem).filter((d) => d !== null);
20304
+ const nextCursor = isRecord(body) && typeof body.nextCursor === "string" ? body.nextCursor : null;
20305
+ return { dialogs, nextCursor };
20306
+ },
20307
+ renameDialog: (id, title) => patch(id, { title }, "Rename"),
20308
+ archiveDialog: (id) => patch(id, { archived: true }, "Archive"),
20309
+ unarchiveDialog: (id) => patch(id, { archived: false }, "Restore")
20310
+ };
20311
+ }
20312
+
20254
20313
  // src/components/chat/utils/slash-dispatch-utils.ts
20255
20314
  var WIRE_TABLE_ID_REGEX = /^[a-z][a-z0-9-]*$/;
20256
20315
  var WIRE_ID_REGEX = /^[A-Za-z0-9._:/-]+$/;
@@ -20333,41 +20392,48 @@ function buildAutoContinuationDirective(toolName, opts = {}) {
20333
20392
  }
20334
20393
 
20335
20394
  // src/components/chat/hooks/use-chat-history-hydration.ts
20336
- function isRecord(value) {
20337
- return typeof value === "object" && value !== null;
20338
- }
20339
20395
  function useChatHistoryHydration({
20340
20396
  active,
20341
20397
  source,
20342
20398
  historyUrl,
20343
- conversationIdRef,
20399
+ conversationId,
20344
20400
  sendCountRef,
20345
20401
  hydrateMessages,
20346
- bumpMetaTick
20402
+ bumpMetaTick,
20403
+ onOrphanedConversation
20347
20404
  }) {
20348
20405
  const [isHydratingHistory, setIsHydratingHistory] = useState39(false);
20349
20406
  const hydratedKeyRef = useRef27(null);
20407
+ const runIdRef = useRef27(0);
20350
20408
  useEffect33(() => {
20351
- if (!active) return void 0;
20352
- const conversationId = conversationIdRef.current;
20353
- if (!conversationId) return void 0;
20409
+ if (!active || !conversationId) return () => setIsHydratingHistory(false);
20354
20410
  const key = `${source}:${conversationId}`;
20355
- if (hydratedKeyRef.current === key) return void 0;
20411
+ if (hydratedKeyRef.current === key) return () => setIsHydratingHistory(false);
20356
20412
  hydratedKeyRef.current = key;
20357
20413
  let cancelled = false;
20414
+ let completed = false;
20415
+ const runId = ++runIdRef.current;
20416
+ const isCurrentRun = () => runIdRef.current === runId;
20358
20417
  setIsHydratingHistory(true);
20359
20418
  void (async () => {
20360
20419
  try {
20361
20420
  const res = await embedAuthedFetch(`${historyUrl}?conversationId=${encodeURIComponent(conversationId)}`, {
20362
20421
  method: "GET"
20363
20422
  });
20364
- if (!res.ok) return;
20423
+ if (!res.ok) {
20424
+ if (isCurrentRun() && hydratedKeyRef.current === key) hydratedKeyRef.current = null;
20425
+ return;
20426
+ }
20365
20427
  const payload = await res.json().catch(() => null);
20366
- const envelope = isRecord(payload) ? payload.data : void 0;
20367
- const body = envelope ?? payload;
20428
+ const body = unwrapEnvelope(payload);
20368
20429
  const rawRows = isRecord(body) ? body.messages : void 0;
20369
20430
  const rows = Array.isArray(rawRows) ? rawRows.filter(isRecord) : [];
20370
- if (cancelled || rows.length === 0) return;
20431
+ if (cancelled) return;
20432
+ if (rows.length === 0) {
20433
+ const found = isRecord(body) ? body.found : void 0;
20434
+ if (found === false) onOrphanedConversation?.(conversationId);
20435
+ return;
20436
+ }
20371
20437
  const hydrated = [];
20372
20438
  const sourcesSeed = /* @__PURE__ */ new Map();
20373
20439
  let userTurns = 0;
@@ -20395,32 +20461,218 @@ function useChatHistoryHydration({
20395
20461
  hydrateMessages(hydrated, Array.from(sourcesSeed.entries()));
20396
20462
  bumpMetaTick();
20397
20463
  } catch {
20464
+ if (isCurrentRun() && hydratedKeyRef.current === key) hydratedKeyRef.current = null;
20398
20465
  } finally {
20399
- if (!cancelled) setIsHydratingHistory(false);
20466
+ completed = true;
20467
+ if (isCurrentRun()) setIsHydratingHistory(false);
20400
20468
  }
20401
20469
  })();
20402
20470
  return () => {
20403
20471
  cancelled = true;
20472
+ if (!completed && isCurrentRun() && hydratedKeyRef.current === key) hydratedKeyRef.current = null;
20473
+ if (isCurrentRun()) setIsHydratingHistory(false);
20404
20474
  };
20405
- }, [active, source, historyUrl, hydrateMessages, bumpMetaTick, conversationIdRef, sendCountRef]);
20475
+ }, [active, source, historyUrl, conversationId, hydrateMessages, bumpMetaTick, onOrphanedConversation, sendCountRef]);
20406
20476
  return { isHydratingHistory, hydratedKeyRef };
20407
20477
  }
20408
20478
 
20479
+ // src/components/chat/hooks/use-managed-dialog-list.ts
20480
+ import { useCallback as useCallback20, useEffect as useEffect34, useMemo as useMemo25, useRef as useRef28, useState as useState40 } from "react";
20481
+ function useManagedDialogList({
20482
+ autoLoad,
20483
+ fetchDialogs,
20484
+ renameDialog: renameDialogCallback,
20485
+ archiveDialog: archiveDialogCallback,
20486
+ deleteDialog: deleteDialogCallback,
20487
+ pageSize,
20488
+ search,
20489
+ onDialogRemoved,
20490
+ logTag
20491
+ }) {
20492
+ const [dialogs, setDialogs] = useState40([]);
20493
+ const [dialogsNextCursor, setDialogsNextCursor] = useState40(null);
20494
+ const [isDialogsLoading, setIsDialogsLoading] = useState40(false);
20495
+ const [settledSearch, setSettledSearch] = useState40(
20496
+ autoLoad && fetchDialogs ? void 0 : null
20497
+ );
20498
+ const [autoLoadWas, setAutoLoadWas] = useState40(autoLoad);
20499
+ if (autoLoad !== autoLoadWas) {
20500
+ setAutoLoadWas(autoLoad);
20501
+ if (autoLoad && fetchDialogs) setSettledSearch(void 0);
20502
+ }
20503
+ const pendingRef = useRef28(false);
20504
+ const [dialogsError, setDialogsError] = useState40(false);
20505
+ const dialogsRef = useRef28(dialogs);
20506
+ useEffect34(() => {
20507
+ dialogsRef.current = dialogs;
20508
+ });
20509
+ const onDialogRemovedRef = useRef28(onDialogRemoved);
20510
+ useEffect34(() => {
20511
+ onDialogRemovedRef.current = onDialogRemoved;
20512
+ });
20513
+ const initialDialogsLoadedRef = useRef28(false);
20514
+ const requestIdRef = useRef28(0);
20515
+ const loadDialogsPage = useCallback20(
20516
+ async (cursor) => {
20517
+ if (!fetchDialogs) return;
20518
+ const requestId = ++requestIdRef.current;
20519
+ const isCurrent = () => requestIdRef.current === requestId;
20520
+ pendingRef.current = true;
20521
+ setIsDialogsLoading(true);
20522
+ if (cursor === void 0) setDialogsError(false);
20523
+ try {
20524
+ const result = await fetchDialogs({
20525
+ cursor,
20526
+ limit: pageSize,
20527
+ // Only hosts that run a search ever see the key.
20528
+ ...search !== void 0 ? { search } : {}
20529
+ });
20530
+ if (!isCurrent()) return;
20531
+ setDialogsNextCursor(result.nextCursor);
20532
+ if (cursor === void 0) {
20533
+ setDialogs(result.dialogs);
20534
+ } else {
20535
+ setDialogs((prev) => {
20536
+ const seen = new Set(prev.map((d) => d.id));
20537
+ return [...prev, ...result.dialogs.filter((d) => !seen.has(d.id))];
20538
+ });
20539
+ }
20540
+ } catch (err) {
20541
+ if (!isCurrent()) return;
20542
+ console.error(`${logTag} fetchDialogs failed:`, err);
20543
+ if (cursor === void 0) {
20544
+ setDialogsError(true);
20545
+ initialDialogsLoadedRef.current = false;
20546
+ }
20547
+ } finally {
20548
+ if (isCurrent()) {
20549
+ pendingRef.current = false;
20550
+ if (cursor === void 0) setSettledSearch(search ?? null);
20551
+ setIsDialogsLoading(false);
20552
+ }
20553
+ }
20554
+ },
20555
+ [fetchDialogs, pageSize, search, logTag]
20556
+ );
20557
+ const reloadDialogs = useCallback20(() => {
20558
+ void loadDialogsPage();
20559
+ }, [loadDialogsPage]);
20560
+ const loadedSearchRef = useRef28(void 0);
20561
+ useEffect34(() => {
20562
+ if (!fetchDialogs) return;
20563
+ if (!autoLoad) return;
20564
+ if (initialDialogsLoadedRef.current && loadedSearchRef.current === search) return;
20565
+ initialDialogsLoadedRef.current = true;
20566
+ loadedSearchRef.current = search;
20567
+ void loadDialogsPage();
20568
+ }, [autoLoad, fetchDialogs, search, loadDialogsPage]);
20569
+ const removeLocal = useCallback20((id) => {
20570
+ setDialogs((prev) => prev.filter((d) => d.id !== id));
20571
+ }, []);
20572
+ const deleteDialog = useCallback20(
20573
+ async (id) => {
20574
+ if (!deleteDialogCallback) return;
20575
+ try {
20576
+ await deleteDialogCallback(id);
20577
+ removeLocal(id);
20578
+ onDialogRemovedRef.current?.(id, "deleted");
20579
+ } catch (err) {
20580
+ console.error(`${logTag} deleteDialog failed:`, err);
20581
+ throw err;
20582
+ }
20583
+ },
20584
+ [deleteDialogCallback, removeLocal, logTag]
20585
+ );
20586
+ const renameDialog = useCallback20(
20587
+ async (id, title) => {
20588
+ if (!renameDialogCallback) return;
20589
+ const previous = dialogsRef.current.find((d) => d.id === id)?.title;
20590
+ setDialogs((prev) => prev.map((d) => d.id === id ? { ...d, title } : d));
20591
+ try {
20592
+ await renameDialogCallback(id, title);
20593
+ } catch (err) {
20594
+ console.error(`${logTag} renameDialog failed:`, err);
20595
+ if (previous !== void 0) {
20596
+ setDialogs((prev) => prev.map((d) => d.id === id ? { ...d, title: previous } : d));
20597
+ }
20598
+ }
20599
+ },
20600
+ [renameDialogCallback, logTag]
20601
+ );
20602
+ const archiveDialog = useCallback20(
20603
+ async (id) => {
20604
+ if (!archiveDialogCallback) return;
20605
+ try {
20606
+ await archiveDialogCallback(id);
20607
+ removeLocal(id);
20608
+ onDialogRemovedRef.current?.(id, "archived");
20609
+ } catch (err) {
20610
+ console.error(`${logTag} archiveDialog failed:`, err);
20611
+ throw err;
20612
+ }
20613
+ },
20614
+ [archiveDialogCallback, removeLocal, logTag]
20615
+ );
20616
+ const loadMoreDialogs = useCallback20(async () => {
20617
+ if (!dialogsNextCursor) return;
20618
+ if (pendingRef.current) return;
20619
+ await loadDialogsPage(dialogsNextCursor);
20620
+ }, [dialogsNextCursor, loadDialogsPage]);
20621
+ const upsertDialogTop = useCallback20((item) => {
20622
+ setDialogs((prev) => [item, ...prev.filter((d) => d.id !== item.id)]);
20623
+ }, []);
20624
+ const bumpDialogToTop = useCallback20((id) => {
20625
+ setDialogs((prev) => {
20626
+ const row = prev.find((d) => d.id === id);
20627
+ if (!row) return prev;
20628
+ return [{ ...row, timestamp: /* @__PURE__ */ new Date() }, ...prev.filter((d) => d.id !== id)];
20629
+ });
20630
+ }, []);
20631
+ const hasMoreDialogs = dialogsNextCursor != null;
20632
+ const awaitingFirstPage = !!fetchDialogs && settledSearch !== (search ?? null);
20633
+ const dialogsLoading = isDialogsLoading || awaitingFirstPage;
20634
+ return useMemo25(
20635
+ () => ({
20636
+ dialogs,
20637
+ dialogsNextCursor,
20638
+ isDialogsLoading: dialogsLoading,
20639
+ dialogsError,
20640
+ hasMoreDialogs,
20641
+ loadDialogsPage,
20642
+ reloadDialogs,
20643
+ loadMoreDialogs,
20644
+ renameDialog,
20645
+ archiveDialog,
20646
+ deleteDialog,
20647
+ upsertDialogTop,
20648
+ bumpDialogToTop
20649
+ }),
20650
+ [
20651
+ dialogs,
20652
+ dialogsNextCursor,
20653
+ dialogsLoading,
20654
+ dialogsError,
20655
+ hasMoreDialogs,
20656
+ loadDialogsPage,
20657
+ reloadDialogs,
20658
+ loadMoreDialogs,
20659
+ renameDialog,
20660
+ archiveDialog,
20661
+ deleteDialog,
20662
+ upsertDialogTop,
20663
+ bumpDialogToTop
20664
+ ]
20665
+ );
20666
+ }
20667
+
20409
20668
  // src/components/chat/hooks/use-sse-chat-adapter.ts
20410
- var SSE_EMPTY_DIALOGS = [];
20411
20669
  var noopSelectDialog = (_id) => {
20412
20670
  };
20413
20671
  var noopStartNewDialog = () => Promise.resolve(null);
20414
20672
  var noopDeleteDialog = async (_id) => {
20415
20673
  };
20416
- var noopRenameDialog = async (_id, _title) => {
20417
- };
20418
- var noopArchiveDialog = async (_id) => {
20419
- };
20420
20674
  var noopAsync = async () => {
20421
20675
  };
20422
- var noopReloadDialogs = () => {
20423
- };
20424
20676
  var noopApproveRequest = async (_id) => {
20425
20677
  };
20426
20678
  var noopRejectRequest = async (_id, _reason) => {
@@ -20446,10 +20698,10 @@ function useSseChatAdapter(options, runtimeOptions = {}) {
20446
20698
  const runtime = useRequiredChatRuntime();
20447
20699
  const source = runtime.source || DEFAULT_CHAT_SOURCE;
20448
20700
  const tableIdForDocumentType = options?.tableIdForDocumentType ?? defaultTableIdForDocumentType;
20449
- const sendMessageRef = useRef28(
20701
+ const sendMessageRef = useRef29(
20450
20702
  () => Promise.resolve(true)
20451
20703
  );
20452
- const cardResolve = useCallback20(
20704
+ const cardResolve = useCallback21(
20453
20705
  (action) => (reqId) => {
20454
20706
  if (!reqId) return void 0;
20455
20707
  return sendMessageRef.current("", {
@@ -20459,36 +20711,45 @@ function useSseChatAdapter(options, runtimeOptions = {}) {
20459
20711
  },
20460
20712
  []
20461
20713
  );
20462
- const cardApprove = useMemo25(() => cardResolve("approve"), [cardResolve]);
20463
- const cardReject = useMemo25(() => cardResolve("reject"), [cardResolve]);
20464
- const createReducerOptions = useCallback20(
20714
+ const cardApprove = useMemo26(() => cardResolve("approve"), [cardResolve]);
20715
+ const cardReject = useMemo26(() => cardResolve("reject"), [cardResolve]);
20716
+ const createReducerOptions = useCallback21(
20465
20717
  () => ({
20466
20718
  transport: "sse",
20467
20719
  callbacks: { onApprove: cardApprove, onReject: cardReject }
20468
20720
  }),
20469
20721
  [cardApprove, cardReject]
20470
20722
  );
20471
- const storeRef = useRef28(null);
20723
+ const storeRef = useRef29(null);
20472
20724
  if (storeRef.current === null) storeRef.current = createChatDialogStore();
20473
20725
  const { state, applyEvent, flushDeltas, mutate } = useChatStreamReducer({
20474
20726
  store: storeRef.current,
20475
20727
  dialogId: source,
20476
20728
  createReducerOptions
20477
20729
  });
20478
- const abortControllerRef = useRef28(null);
20479
- const conversationStorage = useMemo25(() => createChatConversationStorage(source), [source]);
20480
- const conversationIdRef = useRef28(null);
20481
- const restoredConversationRef = useRef28(false);
20730
+ const conversationStorage = useMemo26(() => createChatConversationStorage(source), [source]);
20731
+ const conversationIdRef = useRef29(null);
20732
+ const restoredConversationRef = useRef29(false);
20482
20733
  if (!restoredConversationRef.current) {
20483
20734
  restoredConversationRef.current = true;
20484
20735
  pruneStaleChatConversationStorage(source);
20485
20736
  conversationIdRef.current = conversationStorage.load()?.conversationId ?? null;
20486
20737
  }
20738
+ const [conversationId, setConversationId] = useState41(() => conversationIdRef.current);
20739
+ const commitConversationId = useCallback21(
20740
+ (id) => {
20741
+ conversationIdRef.current = id;
20742
+ setConversationId(id);
20743
+ if (id) conversationStorage.save({ conversationId: id });
20744
+ else conversationStorage.clear();
20745
+ },
20746
+ [conversationStorage]
20747
+ );
20487
20748
  const commandsUrl = runtime.endpoints.commandsUrl;
20488
20749
  const { commands: slashCommands } = useSlashCommandRegistry(commandsUrl, {
20489
20750
  enabled: active
20490
20751
  });
20491
- const cmdIdByTableId = useMemo25(() => {
20752
+ const cmdIdByTableId = useMemo26(() => {
20492
20753
  const buckets = /* @__PURE__ */ new Map();
20493
20754
  for (const cmd of slashCommands) {
20494
20755
  if (!cmd.primarySourceId) continue;
@@ -20509,8 +20770,8 @@ function useSseChatAdapter(options, runtimeOptions = {}) {
20509
20770
  return map;
20510
20771
  }, [slashCommands]);
20511
20772
  const historyUrl = runtime.endpoints.chatHistoryUrl ?? `${runtime.endpoints.chatStreamUrl.replace(/\/+$/, "")}/history`;
20512
- const hydrationSendCountRef = useRef28(0);
20513
- const hydrateMessages = useCallback20(
20773
+ const hydrationSendCountRef = useRef29(0);
20774
+ const hydrateMessages = useCallback21(
20514
20775
  (history, sourcesSeed) => {
20515
20776
  mutate((r) => {
20516
20777
  const mapped = history.map(historyMessageToReducerMessage);
@@ -20531,52 +20792,130 @@ function useSseChatAdapter(options, runtimeOptions = {}) {
20531
20792
  },
20532
20793
  [mutate]
20533
20794
  );
20795
+ const messagesLenRef = useRef29(0);
20796
+ messagesLenRef.current = state.messages.length;
20797
+ const onOrphanedConversation = useCallback21(
20798
+ (id) => {
20799
+ if (conversationIdRef.current === id && messagesLenRef.current === 0) commitConversationId(null);
20800
+ },
20801
+ [commitConversationId]
20802
+ );
20534
20803
  const { isHydratingHistory, hydratedKeyRef } = useChatHistoryHydration({
20535
20804
  active,
20536
20805
  source,
20537
20806
  historyUrl,
20538
- conversationIdRef,
20807
+ conversationId,
20539
20808
  sendCountRef: hydrationSendCountRef,
20540
20809
  hydrateMessages,
20541
20810
  // Meta invalidation is a reducer concern here: `seedSseMaps` (inside
20542
20811
  // `hydrateMessages` above) already invalidates the snapshot.
20543
- bumpMetaTick: noopBumpMetaTick
20812
+ bumpMetaTick: noopBumpMetaTick,
20813
+ // Drop a stored id the server no longer recognizes (deleted, or claimed by
20814
+ // an account while this browser is signed out) — keeping it would stream
20815
+ // answers the server refuses to persist. Guarded on "no live turn yet" so
20816
+ // a just-minted id is never dropped.
20817
+ //
20818
+ // IDENTITY-STABLE by construction: this is a dependency of the hydration
20819
+ // effect, so a callback that changed with the message count would CANCEL
20820
+ // an in-flight hydration the moment the user typed — silently discarding
20821
+ // the thread they just opened. The live count is read through a ref.
20822
+ onOrphanedConversation
20544
20823
  });
20545
- const endpointsRef = useRef28(runtime.endpoints);
20824
+ const abortControllerRef = useRef29(null);
20825
+ const switchConversation = useCallback21(
20826
+ (id) => {
20827
+ abortControllerRef.current?.abort();
20828
+ flushDeltas();
20829
+ mutate((r) => r.reset());
20830
+ hydrationSendCountRef.current = 0;
20831
+ hydratedKeyRef.current = null;
20832
+ commitConversationId(id);
20833
+ },
20834
+ [flushDeltas, mutate, hydratedKeyRef, commitConversationId]
20835
+ );
20836
+ const conversationsUrl = runtime.endpoints.chatConversationsUrl;
20837
+ const conversationsApi = useMemo26(
20838
+ () => conversationsUrl ? createChatConversationsApi(conversationsUrl) : null,
20839
+ [conversationsUrl]
20840
+ );
20841
+ const [dialogSearch, setDialogSearch] = useState41("");
20842
+ const fetchActiveDialogs = useMemo26(
20843
+ () => conversationsApi ? (params) => conversationsApi.fetchDialogs({ ...params, status: "active" }) : void 0,
20844
+ [conversationsApi]
20845
+ );
20846
+ const fetchArchivedDialogs = useMemo26(
20847
+ () => conversationsApi ? (params) => conversationsApi.fetchDialogs({ ...params, status: "archived" }) : void 0,
20848
+ [conversationsApi]
20849
+ );
20850
+ const {
20851
+ dialogs,
20852
+ isDialogsLoading,
20853
+ dialogsError,
20854
+ hasMoreDialogs,
20855
+ reloadDialogs,
20856
+ loadMoreDialogs,
20857
+ renameDialog,
20858
+ archiveDialog,
20859
+ upsertDialogTop,
20860
+ bumpDialogToTop
20861
+ } = useManagedDialogList({
20862
+ autoLoad: active,
20863
+ fetchDialogs: fetchActiveDialogs,
20864
+ renameDialog: conversationsApi?.renameDialog,
20865
+ archiveDialog: conversationsApi?.archiveDialog,
20866
+ pageSize: 20,
20867
+ search: conversationsApi ? dialogSearch : void 0,
20868
+ logTag: "[useSseChatAdapter]",
20869
+ // Archiving the OPEN conversation drops back to the draft state (the
20870
+ // manager also clears the thread; both paths are idempotent).
20871
+ onDialogRemoved: (id) => {
20872
+ if (conversationIdRef.current === id) switchConversation(null);
20873
+ }
20874
+ });
20875
+ const unarchiveDialog = useMemo26(
20876
+ () => conversationsApi ? async (id) => {
20877
+ await conversationsApi.unarchiveDialog(id);
20878
+ reloadDialogs();
20879
+ } : void 0,
20880
+ [conversationsApi, reloadDialogs]
20881
+ );
20882
+ const endpointsRef = useRef29(runtime.endpoints);
20546
20883
  endpointsRef.current = runtime.endpoints;
20547
- const captureConversationId = useCallback20(
20884
+ const captureConversationId = useCallback21(
20548
20885
  (event) => {
20549
- if (event.type !== "metadata") return;
20886
+ if (event.type !== "metadata") return false;
20550
20887
  const id = event.conversationId;
20551
- if (typeof id !== "string" || !id) return;
20552
- if (conversationIdRef.current === id) return;
20553
- conversationIdRef.current = id;
20554
- conversationStorage.save({ conversationId: id });
20888
+ if (typeof id !== "string" || !id) return false;
20889
+ if (conversationIdRef.current === id) return false;
20890
+ hydratedKeyRef.current = `${source}:${id}`;
20891
+ commitConversationId(id);
20892
+ return true;
20555
20893
  },
20556
- [conversationStorage]
20894
+ [commitConversationId, hydratedKeyRef, source]
20557
20895
  );
20558
- const sendMessage = useCallback20(
20896
+ const sendMessage = useCallback21(
20559
20897
  // Resolves `true` on a clean turn, `false` when the request failed
20560
20898
  // (surfaced to batch approve-all loops via the card callbacks).
20561
20899
  async (text, sendOptions) => {
20562
20900
  const { hidden, attachments, commandOverride, approvalAction } = sendOptions ?? {};
20563
- const conversationId = conversationIdRef.current;
20901
+ const echoedConversationId = conversationIdRef.current;
20564
20902
  const targetPath = approvalAction ? endpointsRef.current.approvalToolUrl : endpointsRef.current.chatStreamUrl;
20565
20903
  const requestBody = approvalAction ? (
20566
20904
  // Shared with every other transport that resolves a hub proposal —
20567
20905
  // the body shape is the hub's, not this adapter's. `conversationId`
20568
20906
  // is always present here: an approval can only happen inside an
20569
20907
  // established conversation (the proposal turn captured the id).
20570
- buildConfirmToolBody({ ...approvalAction, conversationId })
20908
+ buildConfirmToolBody({ ...approvalAction, conversationId: echoedConversationId })
20571
20909
  ) : {
20572
20910
  messages: [{ role: "user", content: text }],
20573
20911
  ...commandOverride ? { commandOverride } : {},
20574
20912
  ...attachments && attachments.length > 0 ? { pendingAttachments: attachments } : {},
20575
- ...conversationId ? { conversationId } : {}
20913
+ ...echoedConversationId ? { conversationId: echoedConversationId } : {}
20576
20914
  };
20577
20915
  mutate((r) => r.beginSseSend({ text, hidden, userName: "You", assistantName: "Mingo AI" }));
20578
20916
  const ctrl = new AbortController();
20579
20917
  abortControllerRef.current = ctrl;
20918
+ let mintedThisTurn = false;
20580
20919
  try {
20581
20920
  const response = await embedAuthedFetch(targetPath, {
20582
20921
  method: "POST",
@@ -20597,7 +20936,13 @@ function useSseChatAdapter(options, runtimeOptions = {}) {
20597
20936
  if (done) break;
20598
20937
  if (ctrl.signal.aborted) break;
20599
20938
  for (const event of frameDecoder.push(value)) {
20600
- captureConversationId(event);
20939
+ if (captureConversationId(event)) {
20940
+ mintedThisTurn = true;
20941
+ const mintedId = conversationIdRef.current;
20942
+ if (conversationsApi && !hidden && mintedId) {
20943
+ upsertDialogTop({ id: mintedId, title: "New chat", timestamp: /* @__PURE__ */ new Date() });
20944
+ }
20945
+ }
20601
20946
  applyEvent(event);
20602
20947
  }
20603
20948
  }
@@ -20624,24 +20969,60 @@ function useSseChatAdapter(options, runtimeOptions = {}) {
20624
20969
  }
20625
20970
  flushDeltas();
20626
20971
  mutate((r) => r.endSseTurn());
20972
+ if (conversationsApi && !ctrl.signal.aborted) {
20973
+ if (mintedThisTurn) {
20974
+ reloadDialogs();
20975
+ } else if (conversationIdRef.current) {
20976
+ bumpDialogToTop(conversationIdRef.current);
20977
+ }
20978
+ }
20627
20979
  }
20628
20980
  },
20629
- [mutate, applyEvent, flushDeltas, captureConversationId]
20981
+ [
20982
+ mutate,
20983
+ applyEvent,
20984
+ flushDeltas,
20985
+ captureConversationId,
20986
+ conversationsApi,
20987
+ upsertDialogTop,
20988
+ reloadDialogs,
20989
+ bumpDialogToTop
20990
+ ]
20630
20991
  );
20631
20992
  sendMessageRef.current = sendMessage;
20632
- const stopMessage = useCallback20(() => {
20993
+ const stopMessage = useCallback21(() => {
20633
20994
  abortControllerRef.current?.abort();
20634
20995
  flushDeltas();
20635
20996
  mutate((r) => r.setPhase("idle"));
20636
20997
  }, [mutate, flushDeltas]);
20637
- const clearMessages = useCallback20(() => {
20998
+ const clearMessages = useCallback21(() => {
20638
20999
  mutate((r) => r.reset());
20639
- conversationIdRef.current = null;
20640
- conversationStorage.clear();
21000
+ commitConversationId(null);
20641
21001
  hydrationSendCountRef.current = 0;
20642
21002
  hydratedKeyRef.current = null;
20643
- }, [mutate, conversationStorage, hydratedKeyRef]);
20644
- const docMessages = useMemo25(() => {
21003
+ }, [mutate, commitConversationId, hydratedKeyRef]);
21004
+ const selectDialog = useCallback21(
21005
+ (id) => {
21006
+ if (id === conversationIdRef.current) return;
21007
+ switchConversation(id);
21008
+ },
21009
+ [switchConversation]
21010
+ );
21011
+ const dialogCapabilities = useMemo26(
21012
+ () => conversationsApi ? {
21013
+ canRename: true,
21014
+ canArchive: true,
21015
+ fetchArchivedDialogs,
21016
+ unarchiveDialog,
21017
+ searchQuery: dialogSearch,
21018
+ onSearchChange: setDialogSearch,
21019
+ // A public panel's first-time visitor must reach the composer
21020
+ // without tapping through an empty list.
21021
+ emptyListSkipsToCompose: true
21022
+ } : void 0,
21023
+ [conversationsApi, fetchArchivedDialogs, unarchiveDialog, dialogSearch]
21024
+ );
21025
+ const docMessages = useMemo26(() => {
20645
21026
  const { meta, sources: sourcesMap } = state.turnMeta;
20646
21027
  let sendIdx = -1;
20647
21028
  return state.messages.map((m) => {
@@ -20668,7 +21049,7 @@ function useSseChatAdapter(options, runtimeOptions = {}) {
20668
21049
  };
20669
21050
  });
20670
21051
  }, [state.messages, state.turnMeta]);
20671
- const displayRef = useCallback20(
21052
+ const displayRef = useCallback21(
20672
21053
  (reference) => {
20673
21054
  const tableId = tableIdForDocumentType(reference.type);
20674
21055
  if (!tableId) {
@@ -20690,7 +21071,7 @@ function useSseChatAdapter(options, runtimeOptions = {}) {
20690
21071
  },
20691
21072
  [sendMessage, source, cmdIdByTableId, tableIdForDocumentType]
20692
21073
  );
20693
- const discussRef = useCallback20(
21074
+ const discussRef = useCallback21(
20694
21075
  (reference) => {
20695
21076
  const tableId = tableIdForDocumentType(reference.type);
20696
21077
  if (!tableId) {
@@ -20709,7 +21090,7 @@ function useSseChatAdapter(options, runtimeOptions = {}) {
20709
21090
  },
20710
21091
  [sendMessage, tableIdForDocumentType]
20711
21092
  );
20712
- const latestMeta = useMemo25(() => {
21093
+ const latestMeta = useMemo26(() => {
20713
21094
  const { meta, sendCount } = state.turnMeta;
20714
21095
  return meta.get(sendCount - 1) ?? meta.get(sendCount - 2) ?? null;
20715
21096
  }, [state]);
@@ -20740,26 +21121,29 @@ function useSseChatAdapter(options, runtimeOptions = {}) {
20740
21121
  /** Cross-call usage breakdown (Haiku rewriter/classifier/summarizer
20741
21122
  * token counts). null until the trailing usage frame lands. */
20742
21123
  currentUsageBreakdown: latestMeta?.breakdown ?? null,
20743
- // ─── Dialog management — stubs for v1 ────────────────────────────────
20744
- // Guide mode keeps ONE server-side conversation per stored id
20745
- // (`chat_conversations`, hydrated on mount). Surfacing multiple threads
20746
- // as a structured dialog list is a follow-up; for now the shape is
20747
- // satisfied with empty defaults so the unified contract type-checks and
20748
- // EmbeddableChat hides sidebar affordances when `dialogs.length === 0`.
20749
- dialogs: SSE_EMPTY_DIALOGS,
20750
- activeDialogId: null,
20751
- selectDialog: noopSelectDialog,
21124
+ // ─── Dialog management ───────────────────────────────────────────────
21125
+ // With `chatConversationsUrl` the server transcript store IS the dialog
21126
+ // list (shared `useManagedDialogList`); selecting a row re-hydrates through
21127
+ // the history route. WITHOUT it the same hook is inert by construction —
21128
+ // no `fetchDialogs`, so an empty list, false flags and memoized no-op
21129
+ // mutations — which is why only the four genuinely mode-dependent fields
21130
+ // are branched here.
21131
+ dialogs,
21132
+ isDialogsLoading,
21133
+ dialogsError,
21134
+ reloadDialogs,
21135
+ hasMoreDialogs,
21136
+ loadMoreDialogs,
21137
+ renameDialog,
21138
+ archiveDialog,
21139
+ // New chat = `clearMessages` (the server mints on the next send); there is
21140
+ // no create call. Delete is not offered — archive replaces it.
20752
21141
  startNewDialog: noopStartNewDialog,
20753
21142
  deleteDialog: noopDeleteDialog,
20754
- renameDialog: noopRenameDialog,
20755
- archiveDialog: noopArchiveDialog,
20756
- isDialogsLoading: false,
20757
- // SSE/guide has no server-side dialog list — never errors, nothing to retry.
20758
- dialogsError: false,
20759
- reloadDialogs: noopReloadDialogs,
20760
- isMessagesLoading: false,
20761
- hasMoreDialogs: false,
20762
- loadMoreDialogs: noopAsync,
21143
+ activeDialogId: conversationsApi ? conversationId : null,
21144
+ selectDialog: conversationsApi ? selectDialog : noopSelectDialog,
21145
+ isMessagesLoading: conversationsApi ? isHydratingHistory : false,
21146
+ dialogCapabilities,
20763
21147
  hasMoreMessages: false,
20764
21148
  loadMoreMessages: noopAsync,
20765
21149
  approveRequest: noopApproveRequest,
@@ -20770,12 +21154,9 @@ function useSseChatAdapter(options, runtimeOptions = {}) {
20770
21154
  }
20771
21155
 
20772
21156
  // src/components/chat/hooks/use-nats-chat-adapter.ts
20773
- import { useCallback as useCallback21, useEffect as useEffect34, useMemo as useMemo26, useRef as useRef29, useState as useState40 } from "react";
21157
+ import { useCallback as useCallback22, useEffect as useEffect35, useMemo as useMemo27, useRef as useRef30, useState as useState42 } from "react";
20774
21158
 
20775
21159
  // src/chat-protocol/nats-decoder.ts
20776
- function isRecord2(value) {
20777
- return typeof value === "object" && value !== null;
20778
- }
20779
21160
  function str(value) {
20780
21161
  return typeof value === "string" ? value : void 0;
20781
21162
  }
@@ -20788,7 +21169,7 @@ function numOr(value, fallback = 0) {
20788
21169
  }
20789
21170
  function normalizeToolCalls(raw) {
20790
21171
  if (!Array.isArray(raw)) return [];
20791
- return raw.filter(isRecord2).map((item) => ({
21172
+ return raw.filter(isRecord).map((item) => ({
20792
21173
  toolExecutionRequestId: String(item.toolExecutionRequestId ?? ""),
20793
21174
  toolName: String(item.toolName ?? ""),
20794
21175
  toolTitle: typeof item.toolTitle === "string" ? item.toolTitle : void 0,
@@ -20796,12 +21177,12 @@ function normalizeToolCalls(raw) {
20796
21177
  toolType: typeof item.toolType === "string" ? item.toolType : void 0,
20797
21178
  requiresApproval: item.requiresApproval === true,
20798
21179
  approvalType: typeof item.approvalType === "string" ? item.approvalType : null,
20799
- toolCallArguments: isRecord2(item.toolCallArguments) ? item.toolCallArguments : null
21180
+ toolCallArguments: isRecord(item.toolCallArguments) ? item.toolCallArguments : null
20800
21181
  }));
20801
21182
  }
20802
21183
  function normalizeAskOptions(raw) {
20803
21184
  if (!Array.isArray(raw)) return [];
20804
- return raw.filter(isRecord2).map((item) => ({
21185
+ return raw.filter(isRecord).map((item) => ({
20805
21186
  label: typeof item.label === "string" ? item.label.trim() : "",
20806
21187
  description: typeof item.description === "string" ? item.description : void 0
20807
21188
  })).filter((option) => option.label.length > 0);
@@ -20870,7 +21251,7 @@ function decodeNatsChunk(chunk) {
20870
21251
  // the EXECUTING segment held. Dropping it here therefore blanks the
20871
21252
  // card for the whole lifetime of the run.
20872
21253
  toolExplanation: typeof data.toolExplanation === "string" ? data.toolExplanation : void 0,
20873
- parameters: isRecord2(data.parameters) ? data.parameters : void 0,
21254
+ parameters: isRecord(data.parameters) ? data.parameters : void 0,
20874
21255
  toolExecutionRequestId: typeof data.toolExecutionRequestId === "string" ? data.toolExecutionRequestId : void 0
20875
21256
  },
20876
21257
  ...seq
@@ -20883,7 +21264,7 @@ function decodeNatsChunk(chunk) {
20883
21264
  integratedToolType: strOr(data.integratedToolType),
20884
21265
  toolFunction: strOr(data.toolFunction),
20885
21266
  toolTitle: typeof data.title === "string" ? data.title : void 0,
20886
- parameters: isRecord2(data.parameters) ? data.parameters : void 0,
21267
+ parameters: isRecord(data.parameters) ? data.parameters : void 0,
20887
21268
  result: str(data.result),
20888
21269
  success: typeof data.success === "boolean" ? data.success : void 0,
20889
21270
  toolExecutionRequestId: typeof data.toolExecutionRequestId === "string" ? data.toolExecutionRequestId : void 0
@@ -21748,6 +22129,8 @@ function useNatsChatAdapter(config, options = {}) {
21748
22129
  deleteDialog: deleteDialogCallback,
21749
22130
  renameDialog: renameDialogCallback,
21750
22131
  archiveDialog: archiveDialogCallback,
22132
+ fetchArchivedDialogs,
22133
+ unarchiveDialog,
21751
22134
  approveRequest: approveRequestCallback,
21752
22135
  rejectRequest: rejectRequestCallback,
21753
22136
  stopGeneration: stopGenerationCallback,
@@ -21759,26 +22142,26 @@ function useNatsChatAdapter(config, options = {}) {
21759
22142
  modelLabel = null
21760
22143
  } = config;
21761
22144
  const isManagedMode = fetchDialogs !== void 0;
21762
- const [internalDialogId, setInternalDialogId] = useState40(null);
22145
+ const [internalDialogId, setInternalDialogId] = useState42(null);
21763
22146
  const dialogId = isManagedMode ? internalDialogId : controlledDialogId !== void 0 ? controlledDialogId : null;
21764
- const currentDialogIdRef = useRef29(dialogId);
21765
- useEffect34(() => {
22147
+ const currentDialogIdRef = useRef30(dialogId);
22148
+ useEffect35(() => {
21766
22149
  currentDialogIdRef.current = dialogId;
21767
22150
  });
21768
- const handleApproveRef = useRef29(async () => {
22151
+ const handleApproveRef = useRef30(async () => {
21769
22152
  });
21770
- const handleRejectRef = useRef29(async () => {
22153
+ const handleRejectRef = useRef30(async () => {
21771
22154
  });
21772
- const accumApprove = useCallback21((requestId) => {
22155
+ const accumApprove = useCallback22((requestId) => {
21773
22156
  if (!requestId) return void 0;
21774
22157
  return handleApproveRef.current(requestId);
21775
22158
  }, []);
21776
- const accumReject = useCallback21((requestId) => {
22159
+ const accumReject = useCallback22((requestId) => {
21777
22160
  if (!requestId) return void 0;
21778
22161
  return handleRejectRef.current(requestId);
21779
22162
  }, []);
21780
- const [dialogStore] = useState40(() => createChatDialogStore());
21781
- const [globalApprovalStatuses] = useState40(() => ({}));
22163
+ const [dialogStore] = useState42(() => createChatDialogStore());
22164
+ const [globalApprovalStatuses] = useState42(() => ({}));
21782
22165
  const dialogKey = dialogId ?? DRAFT_DIALOG_KEY;
21783
22166
  const { state, applyEvent, mutate } = useChatStreamReducer({
21784
22167
  store: dialogStore,
@@ -21791,10 +22174,10 @@ function useNatsChatAdapter(config, options = {}) {
21791
22174
  callbacks: { onApprove: accumApprove, onReject: accumReject }
21792
22175
  })
21793
22176
  });
21794
- useEffect34(() => {
22177
+ useEffect35(() => {
21795
22178
  Object.assign(globalApprovalStatuses, state.approvalStatuses);
21796
22179
  }, [globalApprovalStatuses, state.approvalStatuses]);
21797
- useEffect34(() => {
22180
+ useEffect35(() => {
21798
22181
  handleApproveRef.current = async (requestId) => {
21799
22182
  if (!approveRequestCallback) return;
21800
22183
  const key = dialogKey;
@@ -21826,22 +22209,44 @@ function useNatsChatAdapter(config, options = {}) {
21826
22209
  }
21827
22210
  };
21828
22211
  });
21829
- const processChunk = useCallback21(
22212
+ const processChunk = useCallback22(
21830
22213
  (chunk) => {
21831
22214
  const event = decodeNatsChunk(chunk);
21832
22215
  if (event) applyEvent(event);
21833
22216
  },
21834
22217
  [applyEvent]
21835
22218
  );
21836
- const [dialogs, setDialogs] = useState40([]);
21837
- const [dialogsNextCursor, setDialogsNextCursor] = useState40(null);
21838
- const [isDialogsLoading, setIsDialogsLoading] = useState40(false);
21839
- const [dialogsError, setDialogsError] = useState40(false);
21840
- const [isCreatingDialog, setIsCreatingDialog] = useState40(false);
21841
- const [messagesNextCursor, setMessagesNextCursor] = useState40(null);
21842
- const [isMessagesLoading, setIsMessagesLoading] = useState40(false);
21843
- const [connectedForDialog, setConnectedForDialog] = useState40(null);
21844
- const hasConnectedOnceRef = useRef29(false);
22219
+ const [isCreatingDialog, setIsCreatingDialog] = useState42(false);
22220
+ const {
22221
+ dialogs,
22222
+ isDialogsLoading,
22223
+ dialogsError,
22224
+ hasMoreDialogs,
22225
+ reloadDialogs,
22226
+ loadMoreDialogs,
22227
+ renameDialog,
22228
+ archiveDialog,
22229
+ deleteDialog,
22230
+ upsertDialogTop
22231
+ } = useManagedDialogList({
22232
+ autoLoad: active,
22233
+ fetchDialogs,
22234
+ renameDialog: renameDialogCallback,
22235
+ archiveDialog: archiveDialogCallback,
22236
+ deleteDialog: deleteDialogCallback,
22237
+ pageSize: dialogsPageSize,
22238
+ logTag: "[useNatsChatAdapter]",
22239
+ onDialogRemoved: (id, reason) => {
22240
+ if (reason === "deleted") dialogStore.remove(id);
22241
+ if (isManagedMode && internalDialogId === id) {
22242
+ setInternalDialogId(null);
22243
+ }
22244
+ }
22245
+ });
22246
+ const [messagesNextCursor, setMessagesNextCursor] = useState42(null);
22247
+ const [isMessagesLoading, setIsMessagesLoading] = useState42(false);
22248
+ const [connectedForDialog, setConnectedForDialog] = useState42(null);
22249
+ const hasConnectedOnceRef = useRef30(false);
21845
22250
  const {
21846
22251
  processChunk: catchupProcessChunk,
21847
22252
  catchUpChunks,
@@ -21854,8 +22259,8 @@ function useNatsChatAdapter(config, options = {}) {
21854
22259
  onChunkReceived: (chunk) => processChunk(chunk),
21855
22260
  fetchChunks
21856
22261
  });
21857
- const historyLoadSeqRef = useRef29(0);
21858
- const loadDialogHistory = useCallback21(
22262
+ const historyLoadSeqRef = useRef30(0);
22263
+ const loadDialogHistory = useCallback22(
21859
22264
  async (id, cursor) => {
21860
22265
  if (!fetchDialogMessages) return;
21861
22266
  historyLoadSeqRef.current += 1;
@@ -21913,8 +22318,8 @@ function useNatsChatAdapter(config, options = {}) {
21913
22318
  isBufferingActive
21914
22319
  ]
21915
22320
  );
21916
- const prevDialogIdRef = useRef29(void 0);
21917
- useEffect34(() => {
22321
+ const prevDialogIdRef = useRef30(void 0);
22322
+ useEffect35(() => {
21918
22323
  if (prevDialogIdRef.current === dialogId) return;
21919
22324
  prevDialogIdRef.current = dialogId;
21920
22325
  historyLoadSeqRef.current += 1;
@@ -21927,7 +22332,7 @@ function useNatsChatAdapter(config, options = {}) {
21927
22332
  if (!active || !dialogId) return;
21928
22333
  void loadDialogHistory(dialogId);
21929
22334
  }, [active, dialogId, dialogKey, dialogStore, globalApprovalStatuses, loadDialogHistory]);
21930
- useEffect34(() => {
22335
+ useEffect35(() => {
21931
22336
  if (!active || !dialogId) return;
21932
22337
  const store = dialogStore;
21933
22338
  store.mutate(dialogId, DEFAULT_DIALOG_SIDE, (r) => r.adjustAgentBusySuppression(1));
@@ -21987,46 +22392,7 @@ function useNatsChatAdapter(config, options = {}) {
21987
22392
  }
21988
22393
  });
21989
22394
  const connectionState = !active || !dialogId ? "connected" : connectedForDialog === dialogId ? "connected" : "connecting";
21990
- const initialDialogsLoadedRef = useRef29(false);
21991
- const loadDialogsPage = useCallback21(
21992
- async (cursor) => {
21993
- if (!fetchDialogs) return;
21994
- setIsDialogsLoading(true);
21995
- if (cursor === void 0) setDialogsError(false);
21996
- try {
21997
- const result = await fetchDialogs({
21998
- cursor,
21999
- limit: dialogsPageSize
22000
- });
22001
- setDialogsNextCursor(result.nextCursor);
22002
- if (cursor === void 0) {
22003
- setDialogs(result.dialogs);
22004
- } else {
22005
- setDialogs((prev) => [...prev, ...result.dialogs]);
22006
- }
22007
- } catch (err) {
22008
- console.error("[useNatsChatAdapter] fetchDialogs failed:", err);
22009
- if (cursor === void 0) {
22010
- setDialogsError(true);
22011
- initialDialogsLoadedRef.current = false;
22012
- }
22013
- } finally {
22014
- setIsDialogsLoading(false);
22015
- }
22016
- },
22017
- [fetchDialogs, dialogsPageSize]
22018
- );
22019
- const reloadDialogs = useCallback21(() => {
22020
- void loadDialogsPage();
22021
- }, [loadDialogsPage]);
22022
- useEffect34(() => {
22023
- if (!fetchDialogs) return;
22024
- if (!active) return;
22025
- if (initialDialogsLoadedRef.current) return;
22026
- initialDialogsLoadedRef.current = true;
22027
- void loadDialogsPage();
22028
- }, [active, fetchDialogs, loadDialogsPage]);
22029
- const sendMessage = useCallback21(
22395
+ const sendMessage = useCallback22(
22030
22396
  async (text, sendOptions) => {
22031
22397
  const hidden = sendOptions?.hidden ?? false;
22032
22398
  mutate((r) => r.pushOptimisticSend(text, hidden));
@@ -22034,7 +22400,7 @@ function useNatsChatAdapter(config, options = {}) {
22034
22400
  },
22035
22401
  [mutate, publishUserMessage, dialogId]
22036
22402
  );
22037
- const stopMessage = useCallback21(() => {
22403
+ const stopMessage = useCallback22(() => {
22038
22404
  mutate((r) => r.setPhase("idle"));
22039
22405
  if (stopGenerationCallback && dialogId) {
22040
22406
  void stopGenerationCallback(dialogId).catch((err) => {
@@ -22042,10 +22408,10 @@ function useNatsChatAdapter(config, options = {}) {
22042
22408
  });
22043
22409
  }
22044
22410
  }, [mutate, stopGenerationCallback, dialogId]);
22045
- const clearMessages = useCallback21(() => {
22411
+ const clearMessages = useCallback22(() => {
22046
22412
  mutate((r) => r.clearThread());
22047
22413
  }, [mutate]);
22048
- const selectDialog = useCallback21(
22414
+ const selectDialog = useCallback22(
22049
22415
  (id) => {
22050
22416
  if (!isManagedMode) {
22051
22417
  return;
@@ -22054,20 +22420,17 @@ function useNatsChatAdapter(config, options = {}) {
22054
22420
  },
22055
22421
  [isManagedMode]
22056
22422
  );
22057
- const startNewDialog = useCallback21(async () => {
22423
+ const startNewDialog = useCallback22(async () => {
22058
22424
  if (!createDialogCallback) return null;
22059
22425
  if (isCreatingDialog) return null;
22060
22426
  try {
22061
22427
  setIsCreatingDialog(true);
22062
22428
  const result = await createDialogCallback();
22063
- setDialogs((prev) => [
22064
- {
22065
- id: result.dialogId,
22066
- title: "New Chat",
22067
- timestamp: /* @__PURE__ */ new Date()
22068
- },
22069
- ...prev.filter((d) => d.id !== result.dialogId)
22070
- ]);
22429
+ upsertDialogTop({
22430
+ id: result.dialogId,
22431
+ title: "New Chat",
22432
+ timestamp: /* @__PURE__ */ new Date()
22433
+ });
22071
22434
  if (isManagedMode) {
22072
22435
  setInternalDialogId(result.dialogId);
22073
22436
  }
@@ -22078,76 +22441,18 @@ function useNatsChatAdapter(config, options = {}) {
22078
22441
  } finally {
22079
22442
  setIsCreatingDialog(false);
22080
22443
  }
22081
- }, [createDialogCallback, isCreatingDialog, isManagedMode]);
22082
- const deleteDialog = useCallback21(
22083
- async (id) => {
22084
- if (!deleteDialogCallback) return;
22085
- try {
22086
- await deleteDialogCallback(id);
22087
- setDialogs((prev) => prev.filter((d) => d.id !== id));
22088
- dialogStore.remove(id);
22089
- if (isManagedMode && internalDialogId === id) {
22090
- setInternalDialogId(null);
22091
- }
22092
- } catch (err) {
22093
- console.error("[useNatsChatAdapter] deleteDialog failed:", err);
22094
- }
22095
- },
22096
- [deleteDialogCallback, dialogStore, internalDialogId, isManagedMode]
22097
- );
22098
- const renameDialog = useCallback21(
22099
- async (id, title) => {
22100
- if (!renameDialogCallback) return;
22101
- let previous;
22102
- setDialogs(
22103
- (prev) => prev.map((d) => {
22104
- if (d.id !== id) return d;
22105
- previous = d.title;
22106
- return { ...d, title };
22107
- })
22108
- );
22109
- try {
22110
- await renameDialogCallback(id, title);
22111
- } catch (err) {
22112
- console.error("[useNatsChatAdapter] renameDialog failed:", err);
22113
- const rollbackTitle = previous;
22114
- if (rollbackTitle !== void 0) {
22115
- setDialogs((prev) => prev.map((d) => d.id === id ? { ...d, title: rollbackTitle } : d));
22116
- }
22117
- }
22118
- },
22119
- [renameDialogCallback]
22120
- );
22121
- const archiveDialog = useCallback21(
22122
- async (id) => {
22123
- if (!archiveDialogCallback) return;
22124
- try {
22125
- await archiveDialogCallback(id);
22126
- setDialogs((prev) => prev.filter((d) => d.id !== id));
22127
- if (isManagedMode && internalDialogId === id) {
22128
- setInternalDialogId(null);
22129
- }
22130
- } catch (err) {
22131
- console.error("[useNatsChatAdapter] archiveDialog failed:", err);
22132
- }
22133
- },
22134
- [archiveDialogCallback, internalDialogId, isManagedMode]
22135
- );
22136
- const loadMoreDialogs = useCallback21(async () => {
22137
- if (!dialogsNextCursor) return;
22138
- await loadDialogsPage(dialogsNextCursor);
22139
- }, [dialogsNextCursor, loadDialogsPage]);
22140
- const loadMoreMessages = useCallback21(async () => {
22444
+ }, [createDialogCallback, isCreatingDialog, isManagedMode, upsertDialogTop]);
22445
+ const loadMoreMessages = useCallback22(async () => {
22141
22446
  if (!dialogId || !messagesNextCursor) return;
22142
22447
  await loadDialogHistory(dialogId, messagesNextCursor);
22143
22448
  }, [dialogId, messagesNextCursor, loadDialogHistory]);
22144
- const approveRequest = useCallback21(async (requestId) => {
22449
+ const approveRequest = useCallback22(async (requestId) => {
22145
22450
  await handleApproveRef.current(requestId);
22146
22451
  }, []);
22147
- const rejectRequest = useCallback21(async (requestId, reason) => {
22452
+ const rejectRequest = useCallback22(async (requestId, reason) => {
22148
22453
  await handleRejectRef.current(requestId, reason);
22149
22454
  }, []);
22150
- const discussRef = useCallback21(
22455
+ const discussRef = useCallback22(
22151
22456
  (reference) => {
22152
22457
  const prompt = buildDiscussPrompt(reference, { includeReference: true });
22153
22458
  void sendMessage(prompt).catch((err) => {
@@ -22158,9 +22463,17 @@ function useNatsChatAdapter(config, options = {}) {
22158
22463
  );
22159
22464
  const { messages, streamingPhase, dialogTokenUsage = null, liveModel = null } = state;
22160
22465
  const isLoading = streamingPhase !== "idle";
22161
- const hasMoreDialogs = dialogsNextCursor != null;
22162
22466
  const hasMoreMessages = messagesNextCursor != null;
22163
- return useMemo26(
22467
+ const dialogCapabilities = useMemo27(
22468
+ () => ({
22469
+ canRename: isManagedMode && !!renameDialogCallback,
22470
+ canArchive: isManagedMode && !!archiveDialogCallback,
22471
+ fetchArchivedDialogs: isManagedMode ? fetchArchivedDialogs : void 0,
22472
+ unarchiveDialog: isManagedMode ? unarchiveDialog : void 0
22473
+ }),
22474
+ [isManagedMode, renameDialogCallback, archiveDialogCallback, fetchArchivedDialogs, unarchiveDialog]
22475
+ );
22476
+ return useMemo27(
22164
22477
  () => ({
22165
22478
  messages,
22166
22479
  isLoading,
@@ -22197,6 +22510,7 @@ function useNatsChatAdapter(config, options = {}) {
22197
22510
  loadMoreDialogs,
22198
22511
  hasMoreMessages,
22199
22512
  loadMoreMessages,
22513
+ dialogCapabilities,
22200
22514
  // Approval mutations
22201
22515
  approveRequest,
22202
22516
  rejectRequest,
@@ -22229,6 +22543,7 @@ function useNatsChatAdapter(config, options = {}) {
22229
22543
  loadMoreDialogs,
22230
22544
  hasMoreMessages,
22231
22545
  loadMoreMessages,
22546
+ dialogCapabilities,
22232
22547
  approveRequest,
22233
22548
  rejectRequest,
22234
22549
  dialogTokenUsage,
@@ -22241,7 +22556,7 @@ function useNatsChatAdapter(config, options = {}) {
22241
22556
  }
22242
22557
 
22243
22558
  // src/components/chat/hooks/use-unified-chat.ts
22244
- import { useCallback as useCallback22, useEffect as useEffect35, useMemo as useMemo27, useRef as useRef30, useState as useState41 } from "react";
22559
+ import { useCallback as useCallback23, useEffect as useEffect36, useMemo as useMemo28, useRef as useRef31, useState as useState43 } from "react";
22245
22560
  var EMPTY_SSE_OPTIONS = {};
22246
22561
  function createDisabledNatsConfig() {
22247
22562
  return {
@@ -22255,8 +22570,8 @@ function createDisabledNatsConfig() {
22255
22570
  };
22256
22571
  }
22257
22572
  function useUnifiedChat(options) {
22258
- const { modes, activeMode, mingoStateOverride } = options;
22259
- const [disabledNatsConfig] = useState41(createDisabledNatsConfig);
22573
+ const { modes, activeMode, mingoStateOverride, injectedDialogCapabilities } = options;
22574
+ const [disabledNatsConfig] = useState43(createDisabledNatsConfig);
22260
22575
  const sseActive = activeMode === "guide" && modes.guide !== void 0;
22261
22576
  const natsActive = activeMode === "mingo" && modes.mingo !== void 0;
22262
22577
  const sseState = useSseChatAdapter(modes.guide ?? EMPTY_SSE_OPTIONS, {
@@ -22264,40 +22579,42 @@ function useUnifiedChat(options) {
22264
22579
  });
22265
22580
  const natsState = useNatsChatAdapter(modes.mingo ?? disabledNatsConfig, { active: natsActive });
22266
22581
  const activeState = activeMode === "guide" ? sseState : mingoStateOverride ?? natsState;
22267
- const activeStateRef = useRef30(activeState);
22268
- useEffect35(() => {
22582
+ const activeStateIsInjected = activeState === mingoStateOverride;
22583
+ const dialogCapabilities = activeStateIsInjected ? activeState.dialogCapabilities ?? injectedDialogCapabilities ?? EMPTY_DIALOG_CAPABILITIES : activeState.dialogCapabilities;
22584
+ const activeStateRef = useRef31(activeState);
22585
+ useEffect36(() => {
22269
22586
  activeStateRef.current = activeState;
22270
22587
  });
22271
- const stopMessage = useCallback22(() => activeStateRef.current.stopMessage(), []);
22272
- const clearMessages = useCallback22(() => activeStateRef.current.clearMessages(), []);
22273
- const sendMessage = useCallback22(
22588
+ const stopMessage = useCallback23(() => activeStateRef.current.stopMessage(), []);
22589
+ const clearMessages = useCallback23(() => activeStateRef.current.clearMessages(), []);
22590
+ const sendMessage = useCallback23(
22274
22591
  (text, opts) => activeStateRef.current.sendMessage(text, opts),
22275
22592
  []
22276
22593
  );
22277
- const discussRef = useCallback22(
22594
+ const discussRef = useCallback23(
22278
22595
  (ref) => activeStateRef.current.discussRef(ref),
22279
22596
  []
22280
22597
  );
22281
- const displayRefForward = useCallback22(
22598
+ const displayRefForward = useCallback23(
22282
22599
  (ref) => activeStateRef.current.displayRef?.(ref),
22283
22600
  []
22284
22601
  );
22285
22602
  const displayRef = activeState.displayRef ? displayRefForward : void 0;
22286
- const selectDialog = useCallback22((id) => activeStateRef.current.selectDialog(id), []);
22287
- const startNewDialog = useCallback22(() => activeStateRef.current.startNewDialog(), []);
22288
- const deleteDialog = useCallback22((id) => activeStateRef.current.deleteDialog(id), []);
22289
- const renameDialog = useCallback22((id, title) => activeStateRef.current.renameDialog(id, title), []);
22290
- const archiveDialog = useCallback22((id) => activeStateRef.current.archiveDialog(id), []);
22291
- const loadMoreDialogs = useCallback22(() => activeStateRef.current.loadMoreDialogs(), []);
22292
- const setDialogScope = useCallback22((scope) => activeStateRef.current.setDialogScope?.(scope), []);
22293
- const reloadDialogs = useCallback22(() => activeStateRef.current.reloadDialogs(), []);
22294
- const loadMoreMessages = useCallback22(() => activeStateRef.current.loadMoreMessages(), []);
22295
- const approveRequest = useCallback22((requestId) => activeStateRef.current.approveRequest(requestId), []);
22296
- const rejectRequest = useCallback22(
22603
+ const selectDialog = useCallback23((id) => activeStateRef.current.selectDialog(id), []);
22604
+ const startNewDialog = useCallback23(() => activeStateRef.current.startNewDialog(), []);
22605
+ const deleteDialog = useCallback23((id) => activeStateRef.current.deleteDialog(id), []);
22606
+ const renameDialog = useCallback23((id, title) => activeStateRef.current.renameDialog(id, title), []);
22607
+ const archiveDialog = useCallback23((id) => activeStateRef.current.archiveDialog(id), []);
22608
+ const loadMoreDialogs = useCallback23(() => activeStateRef.current.loadMoreDialogs(), []);
22609
+ const setDialogScope = useCallback23((scope) => activeStateRef.current.setDialogScope?.(scope), []);
22610
+ const reloadDialogs = useCallback23(() => activeStateRef.current.reloadDialogs(), []);
22611
+ const loadMoreMessages = useCallback23(() => activeStateRef.current.loadMoreMessages(), []);
22612
+ const approveRequest = useCallback23((requestId) => activeStateRef.current.approveRequest(requestId), []);
22613
+ const rejectRequest = useCallback23(
22297
22614
  (requestId, reason) => activeStateRef.current.rejectRequest(requestId, reason),
22298
22615
  []
22299
22616
  );
22300
- return useMemo27(
22617
+ return useMemo28(
22301
22618
  () => ({
22302
22619
  messages: activeState.messages,
22303
22620
  isLoading: activeState.isLoading,
@@ -22334,6 +22651,8 @@ function useUnifiedChat(options) {
22334
22651
  setDialogScope,
22335
22652
  hasMoreMessages: activeState.hasMoreMessages,
22336
22653
  loadMoreMessages,
22654
+ // THE conversation-list signal — resolved once, above.
22655
+ dialogCapabilities,
22337
22656
  // Approvals
22338
22657
  approveRequest,
22339
22658
  rejectRequest,
@@ -22343,6 +22662,7 @@ function useUnifiedChat(options) {
22343
22662
  }),
22344
22663
  [
22345
22664
  activeState,
22665
+ dialogCapabilities,
22346
22666
  sendMessage,
22347
22667
  stopMessage,
22348
22668
  clearMessages,
@@ -22653,7 +22973,7 @@ import { VisuallyHidden } from "@radix-ui/react-visually-hidden";
22653
22973
  import { usePreventScroll } from "@react-aria/overlays";
22654
22974
  import { isIOS } from "@react-aria/utils";
22655
22975
  import { MessageSquare as MessageSquare3 } from "lucide-react";
22656
- import React10, { useCallback as useCallback26, useEffect as useEffect37, useImperativeHandle as useImperativeHandle4, useMemo as useMemo29, useRef as useRef34, useState as useState45 } from "react";
22976
+ import React10, { useCallback as useCallback27, useEffect as useEffect38, useImperativeHandle as useImperativeHandle4, useMemo as useMemo30, useRef as useRef35, useState as useState47 } from "react";
22657
22977
 
22658
22978
  // src/components/ui/drawer.tsx
22659
22979
  import * as DialogPrimitive from "@radix-ui/react-dialog";
@@ -22661,10 +22981,10 @@ import { cva as cva2 } from "class-variance-authority";
22661
22981
  import { X } from "lucide-react";
22662
22982
  import {
22663
22983
  forwardRef as forwardRef26,
22664
- useCallback as useCallback23,
22665
- useEffect as useEffect36,
22666
- useRef as useRef31,
22667
- useState as useState42
22984
+ useCallback as useCallback24,
22985
+ useEffect as useEffect37,
22986
+ useRef as useRef32,
22987
+ useState as useState44
22668
22988
  } from "react";
22669
22989
  import { jsx as jsx95, jsxs as jsxs73 } from "react/jsx-runtime";
22670
22990
  var OVERLAY_BACKDROP_CLASS = "bg-ods-overlay";
@@ -22758,7 +23078,7 @@ function viewportSize(isHorizontal) {
22758
23078
  return isHorizontal ? window.innerWidth : window.innerHeight;
22759
23079
  }
22760
23080
  function useResizableSize({ enabled, isHorizontal, minSize, maxSize, defaultSize, storageKey }) {
22761
- const clampToViewport = useCallback23(
23081
+ const clampToViewport = useCallback24(
22762
23082
  (value) => {
22763
23083
  const vp = viewportSize(isHorizontal);
22764
23084
  const effectiveMax = vp > 0 ? Math.min(maxSize, vp - 80) : maxSize;
@@ -22766,7 +23086,7 @@ function useResizableSize({ enabled, isHorizontal, minSize, maxSize, defaultSize
22766
23086
  },
22767
23087
  [isHorizontal, minSize, maxSize]
22768
23088
  );
22769
- const readInitial = useCallback23(() => {
23089
+ const readInitial = useCallback24(() => {
22770
23090
  if (!enabled) return defaultSize;
22771
23091
  if (typeof window === "undefined") return defaultSize;
22772
23092
  if (!storageKey) return clampToViewport(defaultSize);
@@ -22780,16 +23100,16 @@ function useResizableSize({ enabled, isHorizontal, minSize, maxSize, defaultSize
22780
23100
  return clampToViewport(defaultSize);
22781
23101
  }
22782
23102
  }, [enabled, storageKey, defaultSize, clampToViewport]);
22783
- const [size2, setSizeRaw] = useState42(readInitial);
22784
- const setSize = useCallback23((next) => setSizeRaw(clampToViewport(next)), [clampToViewport]);
22785
- useEffect36(() => {
23103
+ const [size2, setSizeRaw] = useState44(readInitial);
23104
+ const setSize = useCallback24((next) => setSizeRaw(clampToViewport(next)), [clampToViewport]);
23105
+ useEffect37(() => {
22786
23106
  if (!enabled || !storageKey || typeof window === "undefined") return;
22787
23107
  try {
22788
23108
  window.localStorage.setItem(storageKey, String(Math.round(size2)));
22789
23109
  } catch {
22790
23110
  }
22791
23111
  }, [enabled, size2, storageKey]);
22792
- useEffect36(() => {
23112
+ useEffect37(() => {
22793
23113
  if (!enabled || typeof window === "undefined") return void 0;
22794
23114
  const onResize = () => setSizeRaw((prev) => clampToViewport(prev));
22795
23115
  window.addEventListener("resize", onResize);
@@ -22799,7 +23119,7 @@ function useResizableSize({ enabled, isHorizontal, minSize, maxSize, defaultSize
22799
23119
  }
22800
23120
  function DrawerResizeHandle({ side, size: size2, minSize, maxSize, onSize, ariaLabel }) {
22801
23121
  const isHorizontal = HORIZONTAL_SIDES.has(side);
22802
- const startRef = useRef31(null);
23122
+ const startRef = useRef32(null);
22803
23123
  const direction = side === "right" || side === "bottom" ? -1 : 1;
22804
23124
  const handlePointerDown = (e) => {
22805
23125
  if (e.button !== 0 && e.pointerType === "mouse") return;
@@ -22904,8 +23224,8 @@ var DrawerContent = forwardRef26(
22904
23224
  const isHorizontal = HORIZONTAL_SIDES.has(resolvedSide);
22905
23225
  const initialSize = defaultSize ?? (isHorizontal ? 560 : 480);
22906
23226
  const headerHeight = useHeaderHeight();
22907
- const [isMobile, setIsMobile] = useState42(false);
22908
- useEffect36(() => {
23227
+ const [isMobile, setIsMobile] = useState44(false);
23228
+ useEffect37(() => {
22909
23229
  if (typeof window === "undefined") return void 0;
22910
23230
  const mq = window.matchMedia(`(max-width: ${mobileBreakpoint - 1}px)`);
22911
23231
  const update = () => setIsMobile(mq.matches);
@@ -22995,7 +23315,7 @@ var DrawerFooter = ({ className, ...props }) => /* @__PURE__ */ jsx95("div", { c
22995
23315
  DrawerFooter.displayName = "DrawerFooter";
22996
23316
 
22997
23317
  // src/components/ui/hover-dropdown.tsx
22998
- import { useState as useState43, useRef as useRef32, useCallback as useCallback24 } from "react";
23318
+ import { useState as useState45, useRef as useRef33, useCallback as useCallback25 } from "react";
22999
23319
  import { Fragment as Fragment33, jsx as jsx96, jsxs as jsxs74 } from "react/jsx-runtime";
23000
23320
  function DefaultAnchor({ href, className, children }) {
23001
23321
  return /* @__PURE__ */ jsx96("a", { href, className, children });
@@ -23008,10 +23328,10 @@ function HoverDropdown({
23008
23328
  className,
23009
23329
  renderAnchor
23010
23330
  }) {
23011
- const [open, setOpen] = useState43(false);
23012
- const timeoutRef = useRef32(void 0);
23013
- const containerRef = useRef32(null);
23014
- const panelRef = useRef32(null);
23331
+ const [open, setOpen] = useState45(false);
23332
+ const timeoutRef = useRef33(void 0);
23333
+ const containerRef = useRef33(null);
23334
+ const panelRef = useRef33(null);
23015
23335
  useIsomorphicLayoutEffect(() => {
23016
23336
  const el = panelRef.current;
23017
23337
  const container = containerRef.current;
@@ -23039,14 +23359,14 @@ function HoverDropdown({
23039
23359
  }
23040
23360
  }
23041
23361
  });
23042
- const show = useCallback24(() => {
23362
+ const show = useCallback25(() => {
23043
23363
  clearTimeout(timeoutRef.current);
23044
23364
  setOpen(true);
23045
23365
  }, []);
23046
- const hide = useCallback24(() => {
23366
+ const hide = useCallback25(() => {
23047
23367
  timeoutRef.current = setTimeout(() => setOpen(false), hideDelay);
23048
23368
  }, [hideDelay]);
23049
- const toggle = useCallback24((e) => {
23369
+ const toggle = useCallback25((e) => {
23050
23370
  e.stopPropagation();
23051
23371
  clearTimeout(timeoutRef.current);
23052
23372
  setOpen((prev) => !prev);
@@ -23112,7 +23432,7 @@ function HoverDropdown({
23112
23432
  }
23113
23433
 
23114
23434
  // src/components/chat/hooks/use-chat-dialog-manager.ts
23115
- import { useCallback as useCallback25, useMemo as useMemo28, useRef as useRef33, useState as useState44 } from "react";
23435
+ import { useCallback as useCallback26, useMemo as useMemo29, useRef as useRef34, useState as useState46 } from "react";
23116
23436
  function useChatDialogManager({
23117
23437
  dialogs,
23118
23438
  activeDialogId,
@@ -23123,17 +23443,17 @@ function useChatDialogManager({
23123
23443
  fetchArchivedDialogs,
23124
23444
  unarchiveDialog
23125
23445
  }) {
23126
- const [renameTarget, setRenameTarget] = useState44(null);
23127
- const [archiveTarget, setArchiveTarget] = useState44(null);
23128
- const handleConfirmRename = useCallback25(
23446
+ const [renameTarget, setRenameTarget] = useState46(null);
23447
+ const [archiveTarget, setArchiveTarget] = useState46(null);
23448
+ const handleConfirmRename = useCallback26(
23129
23449
  (name) => {
23130
23450
  if (renameTarget) void renameDialog(renameTarget.id, name);
23131
23451
  setRenameTarget(null);
23132
23452
  },
23133
23453
  [renameTarget, renameDialog]
23134
23454
  );
23135
- const [openingDialogId, setOpeningDialogId] = useState44(null);
23136
- const handleConfirmArchive = useCallback25(async () => {
23455
+ const [openingDialogId, setOpeningDialogId] = useState46(null);
23456
+ const handleConfirmArchive = useCallback26(async () => {
23137
23457
  if (archiveTarget) {
23138
23458
  try {
23139
23459
  await archiveDialog(archiveTarget.id);
@@ -23148,13 +23468,13 @@ function useChatDialogManager({
23148
23468
  }
23149
23469
  setArchiveTarget(null);
23150
23470
  }, [archiveTarget, archiveDialog, activeDialogId, clearMessages]);
23151
- const [archiveOpen, setArchiveOpen] = useState44(false);
23152
- const [archivedDialogs, setArchivedDialogs] = useState44([]);
23153
- const [archivedCursor, setArchivedCursor] = useState44(null);
23154
- const [archivedLoading, setArchivedLoading] = useState44(false);
23155
- const [archivedPending, setArchivedPending] = useState44(false);
23156
- const archivedRequestIdRef = useRef33(0);
23157
- const loadArchivedPage = useCallback25(
23471
+ const [archiveOpen, setArchiveOpen] = useState46(false);
23472
+ const [archivedDialogs, setArchivedDialogs] = useState46([]);
23473
+ const [archivedCursor, setArchivedCursor] = useState46(null);
23474
+ const [archivedLoading, setArchivedLoading] = useState46(false);
23475
+ const [archivedPending, setArchivedPending] = useState46(false);
23476
+ const archivedRequestIdRef = useRef34(0);
23477
+ const loadArchivedPage = useCallback26(
23158
23478
  async (cursor) => {
23159
23479
  if (!fetchArchivedDialogs) return;
23160
23480
  const requestId = ++archivedRequestIdRef.current;
@@ -23187,13 +23507,13 @@ function useChatDialogManager({
23187
23507
  },
23188
23508
  [fetchArchivedDialogs]
23189
23509
  );
23190
- const openArchive = useCallback25(() => {
23510
+ const openArchive = useCallback26(() => {
23191
23511
  setArchiveOpen(true);
23192
23512
  void loadArchivedPage();
23193
23513
  }, [loadArchivedPage]);
23194
- const closeArchive = useCallback25(() => setArchiveOpen(false), []);
23195
- const [viewingArchivedId, setViewingArchivedId] = useState44(null);
23196
- const handleSelectDialog = useCallback25(
23514
+ const closeArchive = useCallback26(() => setArchiveOpen(false), []);
23515
+ const [viewingArchivedId, setViewingArchivedId] = useState46(null);
23516
+ const handleSelectDialog = useCallback26(
23197
23517
  (id) => {
23198
23518
  setViewingArchivedId(null);
23199
23519
  setOpeningDialogId(id);
@@ -23202,7 +23522,7 @@ function useChatDialogManager({
23202
23522
  [selectDialog]
23203
23523
  );
23204
23524
  const isOpeningDialog = openingDialogId != null && openingDialogId === activeDialogId;
23205
- const handleArchivedSelect = useCallback25(
23525
+ const handleArchivedSelect = useCallback26(
23206
23526
  (id) => {
23207
23527
  setArchiveOpen(false);
23208
23528
  setOpeningDialogId(null);
@@ -23211,8 +23531,8 @@ function useChatDialogManager({
23211
23531
  },
23212
23532
  [selectDialog]
23213
23533
  );
23214
- const [restoreTarget, setRestoreTarget] = useState44(null);
23215
- const handleConfirmRestore = useCallback25(async () => {
23534
+ const [restoreTarget, setRestoreTarget] = useState46(null);
23535
+ const handleConfirmRestore = useCallback26(async () => {
23216
23536
  if (restoreTarget) {
23217
23537
  try {
23218
23538
  await unarchiveDialog?.(restoreTarget.id);
@@ -23226,7 +23546,7 @@ function useChatDialogManager({
23226
23546
  setRestoreTarget(null);
23227
23547
  }, [restoreTarget, unarchiveDialog]);
23228
23548
  const isViewingArchived = viewingArchivedId != null && viewingArchivedId === activeDialogId;
23229
- const handleBack = useCallback25(() => {
23549
+ const handleBack = useCallback26(() => {
23230
23550
  const wasArchived = isViewingArchived;
23231
23551
  setViewingArchivedId(null);
23232
23552
  setOpeningDialogId(null);
@@ -23234,14 +23554,14 @@ function useChatDialogManager({
23234
23554
  clearMessages();
23235
23555
  if (wasArchived) setArchiveOpen(true);
23236
23556
  }, [isViewingArchived, selectDialog, clearMessages]);
23237
- const resetToNewChat = useCallback25(() => {
23557
+ const resetToNewChat = useCallback26(() => {
23238
23558
  setViewingArchivedId(null);
23239
23559
  setOpeningDialogId(null);
23240
23560
  selectDialog(null);
23241
23561
  clearMessages();
23242
23562
  setArchiveOpen(false);
23243
23563
  }, [selectDialog, clearMessages]);
23244
- const activeDialog = useMemo28(
23564
+ const activeDialog = useMemo29(
23245
23565
  () => dialogs.find((d) => d.id === activeDialogId) ?? archivedDialogs.find((d) => d.id === activeDialogId),
23246
23566
  [dialogs, archivedDialogs, activeDialogId]
23247
23567
  );
@@ -23282,12 +23602,18 @@ function useChatDialogManager({
23282
23602
 
23283
23603
  // src/components/chat/embeddable-chat.tsx
23284
23604
  import { Fragment as Fragment34, jsx as jsx97, jsxs as jsxs75 } from "react/jsx-runtime";
23605
+ var HISTORY_RAIL_WIDTH = 320;
23606
+ var CHAT_BLOCK_MIN_WIDTH = 400;
23607
+ var SPLIT_MIN_WIDTH = HISTORY_RAIL_WIDTH + CHAT_BLOCK_MIN_WIDTH;
23285
23608
  var DRAWER_DEFAULT_WIDTH_RATIO = 0.5;
23286
- var DRAWER_WIDTH_KEY = "mingo-chat-width-v3";
23609
+ var DRAWER_WIDTH_KEY = "mingo-chat-width-v4";
23287
23610
  var DRAWER_DEFAULT_WIDTH_PX = 750;
23288
- function drawerDefaultWidth() {
23611
+ var SPLIT_DEFAULT_WIDTH_ALLOWANCE = 16;
23612
+ function drawerDefaultWidth(withHistoryRail) {
23289
23613
  if (typeof window === "undefined") return DRAWER_DEFAULT_WIDTH_PX;
23290
- return Math.round(window.innerWidth * DRAWER_DEFAULT_WIDTH_RATIO);
23614
+ const ratioWidth = Math.round(window.innerWidth * DRAWER_DEFAULT_WIDTH_RATIO);
23615
+ if (!withHistoryRail) return ratioWidth;
23616
+ return Math.max(ratioWidth, SPLIT_MIN_WIDTH + SPLIT_DEFAULT_WIDTH_ALLOWANCE);
23291
23617
  }
23292
23618
  var formatRelativePath = (p) => p.replace(/^\/+/, "").replace(/\/+$/, "");
23293
23619
  var mentionTokenOf = (key, markerByType) => {
@@ -23297,18 +23623,15 @@ var mentionTokenOf = (key, markerByType) => {
23297
23623
  return `${markerByType.get(type) ?? type.toLowerCase()}:${id}`;
23298
23624
  };
23299
23625
  var FALLBACK_TOP_RETRIEVED = 3;
23300
- var HISTORY_RAIL_WIDTH = 320;
23301
- var CHAT_BLOCK_MIN_WIDTH = 400;
23302
- var SPLIT_MIN_WIDTH = HISTORY_RAIL_WIDTH + CHAT_BLOCK_MIN_WIDTH;
23303
23626
  var RAIL_COLLAPSED_STORAGE_KEY = "mingo-chat-history-collapsed";
23304
23627
  var NO_CONTEXT_ITEMS = [];
23305
23628
  var RAIL_ANIM_MS = 320;
23306
23629
  function useRailPresence(open) {
23307
- const [mounted, setMounted] = useState45(open);
23308
- const [active, setActive] = useState45(false);
23630
+ const [mounted, setMounted] = useState47(open);
23631
+ const [active, setActive] = useState47(false);
23309
23632
  if (open && !mounted) setMounted(true);
23310
23633
  if (!open && active) setActive(false);
23311
- useEffect37(() => {
23634
+ useEffect38(() => {
23312
23635
  if (open) {
23313
23636
  let raf2 = 0;
23314
23637
  const raf1 = requestAnimationFrame(() => {
@@ -23524,7 +23847,7 @@ function SourceChips({
23524
23847
  onClose,
23525
23848
  onDiscuss
23526
23849
  }) {
23527
- const [expanded, setExpanded] = useState45(false);
23850
+ const [expanded, setExpanded] = useState47(false);
23528
23851
  if (cited.length === 0) {
23529
23852
  const fallback = uncited.slice(0, FALLBACK_TOP_RETRIEVED);
23530
23853
  if (fallback.length === 0) return null;
@@ -23631,7 +23954,7 @@ function EmbeddableChatInner({
23631
23954
  const commandsUrl = runtime.endpoints.commandsUrl;
23632
23955
  const { attachmentsEnabled, user: identityUser } = useChatIdentity();
23633
23956
  const viewUrlPrefix = runtime.endpoints.attachmentViewUrlPrefix;
23634
- useEffect37(() => {
23957
+ useEffect38(() => {
23635
23958
  if (process.env.NODE_ENV !== "production") {
23636
23959
  const hasOpen = open !== void 0;
23637
23960
  const hasHandler = onOpenChange !== void 0;
@@ -23647,13 +23970,13 @@ function EmbeddableChatInner({
23647
23970
  defaultProp: defaultOpen ?? false,
23648
23971
  onChange: onOpenChange
23649
23972
  });
23650
- const [autoFocusInput] = useState45(() => {
23973
+ const [autoFocusInput] = useState47(() => {
23651
23974
  if (typeof window === "undefined") return false;
23652
23975
  return !window.matchMedia("(pointer: coarse)").matches;
23653
23976
  });
23654
23977
  usePreventScroll({ isDisabled: !isOpen || shellLess });
23655
- const navigatingAwayRef = useRef34(false);
23656
- useEffect37(() => {
23978
+ const navigatingAwayRef = useRef35(false);
23979
+ useEffect38(() => {
23657
23980
  if (!isOpen) return void 0;
23658
23981
  if (shellLess) return void 0;
23659
23982
  if (typeof window === "undefined") return void 0;
@@ -23679,9 +24002,9 @@ function EmbeddableChatInner({
23679
24002
  window.scrollTo(0, scrollY);
23680
24003
  };
23681
24004
  }, [isOpen, shellLess]);
23682
- const chatInputRef = useRef34(null);
23683
- const [quickActionPreview, setQuickActionPreview] = useState45(null);
23684
- const slashCommandsProp = useMemo29(
24005
+ const chatInputRef = useRef35(null);
24006
+ const [quickActionPreview, setQuickActionPreview] = useState47(null);
24007
+ const slashCommandsProp = useMemo30(
23685
24008
  () => ({
23686
24009
  fetchCommands: (prefix, signal) => fetchSlashCommands(prefix, signal, commandsUrl),
23687
24010
  resolveSourceIcon: (sourceId) => {
@@ -23696,38 +24019,16 @@ function EmbeddableChatInner({
23696
24019
  [commandsUrl]
23697
24020
  );
23698
24021
  const headerUserName = identityUser?.name?.trim() || [identityUser?.firstName, identityUser?.lastName].filter(Boolean).join(" ").trim() || userDisplayName?.trim() || void 0;
23699
- const effectiveModes = useMemo29(() => {
24022
+ const effectiveModes = useMemo30(() => {
23700
24023
  if (modes) return modes;
23701
24024
  const guideOptions = tableIdForDocumentType ? { tableIdForDocumentType } : {};
23702
24025
  return { guide: guideOptions };
23703
24026
  }, [modes, tableIdForDocumentType]);
23704
- const mingoCaps = useMemo29(() => {
23705
- if (mingoState) {
23706
- return {
23707
- canRename: mingoDialogCapabilities?.canRename ?? false,
23708
- canArchive: mingoDialogCapabilities?.canArchive ?? false,
23709
- fetchArchivedDialogs: mingoDialogCapabilities?.fetchArchivedDialogs,
23710
- unarchiveDialog: mingoDialogCapabilities?.unarchiveDialog,
23711
- searchQuery: mingoDialogCapabilities?.searchQuery,
23712
- onSearchChange: mingoDialogCapabilities?.onSearchChange,
23713
- onCopyLink: mingoDialogCapabilities?.onCopyLink
23714
- };
23715
- }
23716
- return {
23717
- canRename: !!effectiveModes.mingo?.renameDialog,
23718
- canArchive: !!effectiveModes.mingo?.archiveDialog,
23719
- fetchArchivedDialogs: effectiveModes.mingo?.fetchArchivedDialogs,
23720
- unarchiveDialog: effectiveModes.mingo?.unarchiveDialog,
23721
- searchQuery: void 0,
23722
- onSearchChange: void 0,
23723
- onCopyLink: void 0
23724
- };
23725
- }, [mingoState, mingoDialogCapabilities, effectiveModes]);
23726
24027
  const hasMingoMode = !!effectiveModes.mingo || !!mingoState;
23727
24028
  const initialActiveMode = controlledActiveMode ?? defaultActiveMode ?? (effectiveModes.guide ? "guide" : "mingo");
23728
- const [uncontrolledActiveMode, setUncontrolledActiveMode] = useState45(initialActiveMode);
24029
+ const [uncontrolledActiveMode, setUncontrolledActiveMode] = useState47(initialActiveMode);
23729
24030
  const activeMode = controlledActiveMode ?? uncontrolledActiveMode;
23730
- const handleActiveModeChange = useCallback26(
24031
+ const handleActiveModeChange = useCallback27(
23731
24032
  (next) => {
23732
24033
  if (controlledActiveMode === void 0) {
23733
24034
  setUncontrolledActiveMode(next);
@@ -23739,7 +24040,7 @@ function EmbeddableChatInner({
23739
24040
  const { commands: commandsList, loaded: commandsLoaded } = useSlashCommandRegistry(commandsUrl, {
23740
24041
  enabled: activeMode === "guide"
23741
24042
  });
23742
- const commandsById = useMemo29(() => {
24043
+ const commandsById = useMemo30(() => {
23743
24044
  const map = /* @__PURE__ */ new Map();
23744
24045
  for (const cmd of commandsList) map.set(cmd.id, cmd);
23745
24046
  return map;
@@ -23753,7 +24054,7 @@ function EmbeddableChatInner({
23753
24054
  const effectiveGreeting = emptyStateConfig.greeting ?? emptyStateGreeting;
23754
24055
  const effectiveEnabledRagTableIds = emptyStateUrl ? emptyStateConfig.enabledRagTableIds : enabledRagTableIds;
23755
24056
  const effectiveSuggestedQueries = emptyStateUrl ? emptyStateConfig.suggestedQueries : suggestedQueries;
23756
- const effectiveQuickActions = useMemo29(
24057
+ const effectiveQuickActions = useMemo30(
23757
24058
  () => emptyStateUrl ? emptyStateConfig.quickActions : [],
23758
24059
  [emptyStateUrl, emptyStateConfig.quickActions]
23759
24060
  );
@@ -23790,10 +24091,25 @@ function EmbeddableChatInner({
23790
24091
  dialogScope,
23791
24092
  setDialogScope,
23792
24093
  hasMoreMessages,
23793
- loadMoreMessages
23794
- } = useUnifiedChat({ modes: effectiveModes, activeMode, mingoStateOverride: mingoState });
23795
- const guidePromptSentRef = useRef34(false);
23796
- useEffect37(() => {
24094
+ loadMoreMessages,
24095
+ dialogCapabilities
24096
+ } = useUnifiedChat({
24097
+ modes: effectiveModes,
24098
+ activeMode,
24099
+ mingoStateOverride: mingoState,
24100
+ injectedDialogCapabilities: mingoDialogCapabilities
24101
+ });
24102
+ const historyListMode = dialogCapabilities !== void 0;
24103
+ const mingoCaps = useMemo30(
24104
+ () => ({
24105
+ ...dialogCapabilities,
24106
+ canRename: dialogCapabilities?.canRename ?? false,
24107
+ canArchive: dialogCapabilities?.canArchive ?? false
24108
+ }),
24109
+ [dialogCapabilities]
24110
+ );
24111
+ const guidePromptSentRef = useRef35(false);
24112
+ useEffect38(() => {
23797
24113
  if (!guidePendingPrompt) {
23798
24114
  guidePromptSentRef.current = false;
23799
24115
  return;
@@ -23816,35 +24132,35 @@ function EmbeddableChatInner({
23816
24132
  const { panelRef: galleryPanelRef, modal: galleryModal } = useChatAttachmentImageGallery();
23817
24133
  const contextMaxItems = contextPicker?.maxItems ?? 10;
23818
24134
  const contextPickerForMode = activeMode === "mingo" ? contextPicker : void 0;
23819
- const [contextItems, setContextItems] = useState45(NO_CONTEXT_ITEMS);
23820
- const [contextPickerOpen, setContextPickerOpen] = useState45(false);
23821
- const [mentionQuery, setMentionQuery] = useState45(null);
23822
- const mentionActiveRef = useRef34(false);
23823
- useEffect37(() => {
24135
+ const [contextItems, setContextItems] = useState47(NO_CONTEXT_ITEMS);
24136
+ const [contextPickerOpen, setContextPickerOpen] = useState47(false);
24137
+ const [mentionQuery, setMentionQuery] = useState47(null);
24138
+ const mentionActiveRef = useRef35(false);
24139
+ useEffect38(() => {
23824
24140
  mentionActiveRef.current = mentionQuery !== null;
23825
24141
  }, [mentionQuery]);
23826
- const mentionKeysRef = useRef34(/* @__PURE__ */ new Set());
23827
- const [contextClearedFor, setContextClearedFor] = useState45({ activeDialogId, activeMode });
24142
+ const mentionKeysRef = useRef35(/* @__PURE__ */ new Set());
24143
+ const [contextClearedFor, setContextClearedFor] = useState47({ activeDialogId, activeMode });
23828
24144
  if (contextClearedFor.activeDialogId !== activeDialogId || contextClearedFor.activeMode !== activeMode) {
23829
24145
  setContextClearedFor({ activeDialogId, activeMode });
23830
24146
  setContextItems(NO_CONTEXT_ITEMS);
23831
24147
  setMentionQuery(null);
23832
24148
  }
23833
- useEffect37(() => {
24149
+ useEffect38(() => {
23834
24150
  mentionKeysRef.current.clear();
23835
24151
  }, [activeDialogId, activeMode]);
23836
- const mentionMarkerByType = useMemo29(() => {
24152
+ const mentionMarkerByType = useMemo30(() => {
23837
24153
  const m = /* @__PURE__ */ new Map();
23838
24154
  for (const t of contextPicker?.entityTypes ?? []) if (t.marker) m.set(t.type, t.marker);
23839
24155
  return m;
23840
24156
  }, [contextPicker?.entityTypes]);
23841
24157
  const contextEntityTypes = contextPicker?.entityTypes;
23842
- const resolveContextIcon = useMemo29(() => {
24158
+ const resolveContextIcon = useMemo30(() => {
23843
24159
  const byType = /* @__PURE__ */ new Map();
23844
24160
  for (const t of contextEntityTypes ?? []) byType.set(t.type, t.icon);
23845
24161
  return (item) => byType.get(item.type);
23846
24162
  }, [contextEntityTypes]);
23847
- const toggleContextItem = useCallback26(
24163
+ const toggleContextItem = useCallback27(
23848
24164
  (item) => {
23849
24165
  const key = `${item.type}:${item.id}`;
23850
24166
  if (mentionActiveRef.current) {
@@ -23867,7 +24183,7 @@ function EmbeddableChatInner({
23867
24183
  },
23868
24184
  [contextMaxItems, contextItems, mentionMarkerByType, resolveContextIcon]
23869
24185
  );
23870
- const removeContextItem = useCallback26(
24186
+ const removeContextItem = useCallback27(
23871
24187
  (item) => {
23872
24188
  const key = `${item.type}:${item.id}`;
23873
24189
  setContextItems((prev) => prev.filter((p) => `${p.type}:${p.id}` !== key));
@@ -23880,7 +24196,7 @@ function EmbeddableChatInner({
23880
24196
  },
23881
24197
  [mentionMarkerByType]
23882
24198
  );
23883
- const handleContextValueChange = useCallback26(
24199
+ const handleContextValueChange = useCallback27(
23884
24200
  (value) => {
23885
24201
  for (const key of Array.from(mentionKeysRef.current)) {
23886
24202
  if (!value.includes(`@${mentionTokenOf(key, mentionMarkerByType)}`)) {
@@ -23891,32 +24207,32 @@ function EmbeddableChatInner({
23891
24207
  },
23892
24208
  [mentionMarkerByType]
23893
24209
  );
23894
- const openContextPicker = useCallback26(() => {
24210
+ const openContextPicker = useCallback27(() => {
23895
24211
  setMentionQuery(null);
23896
24212
  setContextPickerOpen(true);
23897
24213
  }, []);
23898
- const closeContextPicker = useCallback26(() => {
24214
+ const closeContextPicker = useCallback27(() => {
23899
24215
  if (mentionActiveRef.current) {
23900
24216
  chatInputRef.current?.removeMentionTrigger();
23901
24217
  }
23902
24218
  setContextPickerOpen(false);
23903
24219
  setMentionQuery(null);
23904
24220
  }, []);
23905
- const handleMentionQueryChange = useCallback26((query) => {
24221
+ const handleMentionQueryChange = useCallback27((query) => {
23906
24222
  setMentionQuery(query);
23907
24223
  setContextPickerOpen(query !== null);
23908
24224
  }, []);
23909
24225
  const resolvedBaseRoute = baseRoute || (source === "flamingo" ? "/knowledge-base" : "/data-room");
23910
- const handleClose = useCallback26(() => setIsOpen(false), [setIsOpen]);
23911
- const handleNavigationClose = useCallback26(() => {
24226
+ const handleClose = useCallback27(() => setIsOpen(false), [setIsOpen]);
24227
+ const handleNavigationClose = useCallback27(() => {
23912
24228
  navigatingAwayRef.current = true;
23913
24229
  setIsOpen(false);
23914
24230
  }, [setIsOpen]);
23915
- const chatPanelHandle = useMemo29(
24231
+ const chatPanelHandle = useMemo30(
23916
24232
  () => ({ closeChat: handleNavigationClose }),
23917
24233
  [handleNavigationClose]
23918
24234
  );
23919
- const renderEntityCard = useCallback26(
24235
+ const renderEntityCard = useCallback27(
23920
24236
  (reference) => renderChatInlineEntityCard(reference, {
23921
24237
  onDiscuss: discussRef,
23922
24238
  onDisplay: displayRef,
@@ -23926,14 +24242,14 @@ function EmbeddableChatInner({
23926
24242
  }),
23927
24243
  [discussRef, displayRef, resolvedBaseRoute, chipBasePlatform, extras]
23928
24244
  );
23929
- const mingoAssistantIcon = useMemo29(
24245
+ const mingoAssistantIcon = useMemo30(
23930
24246
  () => effectiveAssistantIcon ? /* @__PURE__ */ jsx97(EntityIcon, { icon: effectiveAssistantIcon, size: 24 }) : /* @__PURE__ */ jsx97(MingoIcon, { className: "h-6 w-6", cornerColor: "var(--ods-flamingo-cyan-base)" }),
23931
24247
  [effectiveAssistantIcon]
23932
24248
  );
23933
- const [timestampCache] = useState45(() => /* @__PURE__ */ new Map());
24249
+ const [timestampCache] = useState47(() => /* @__PURE__ */ new Map());
23934
24250
  const guideUserName = activeMode === "guide" ? [identityUser?.firstName, identityUser?.lastName].filter(Boolean).join(" ").trim() || identityUser?.name?.trim() || void 0 : void 0;
23935
24251
  const guideUserAvatar = activeMode === "guide" ? identityUser?.avatarUrl?.trim() || void 0 : void 0;
23936
- const messages = useMemo29(() => {
24252
+ const messages = useMemo30(() => {
23937
24253
  const cache = timestampCache;
23938
24254
  const seenIds = /* @__PURE__ */ new Set();
23939
24255
  const mapped = rawMessages.map((m) => {
@@ -23978,7 +24294,7 @@ function EmbeddableChatInner({
23978
24294
  }
23979
24295
  return mapped;
23980
24296
  }, [rawMessages, guideUserName, guideUserAvatar, timestampCache]);
23981
- const handleSend = useCallback26(
24297
+ const handleSend = useCallback27(
23982
24298
  (text) => {
23983
24299
  let augmentedText = text;
23984
24300
  if (readyAttachments.length > 0) {
@@ -24000,7 +24316,7 @@ function EmbeddableChatInner({
24000
24316
  },
24001
24317
  [sendMessage, readyAttachments, viewUrlPrefix, clearAttachments, contextItems]
24002
24318
  );
24003
- const handleAskSelect = useCallback26(
24319
+ const handleAskSelect = useCallback27(
24004
24320
  (label) => {
24005
24321
  void sendMessage(label).catch((err) => {
24006
24322
  console.error("[EmbeddableChat] handleAskSelect send failed:", err);
@@ -24008,7 +24324,7 @@ function EmbeddableChatInner({
24008
24324
  },
24009
24325
  [sendMessage]
24010
24326
  );
24011
- const guideSuggestedActions = useMemo29(() => {
24327
+ const guideSuggestedActions = useMemo30(() => {
24012
24328
  if (effectiveQuickActions.length > 0) {
24013
24329
  return effectiveQuickActions.map((qa) => ({
24014
24330
  id: qa.id,
@@ -24067,9 +24383,9 @@ function EmbeddableChatInner({
24067
24383
  fetchArchivedDialogs: mingoCaps.fetchArchivedDialogs,
24068
24384
  unarchiveDialog: mingoCaps.unarchiveDialog
24069
24385
  });
24070
- const handleOpen = useCallback26(() => setIsOpen(true), [setIsOpen]);
24386
+ const handleOpen = useCallback27(() => setIsOpen(true), [setIsOpen]);
24071
24387
  useCloseOnNavigation(handleNavigationClose, null);
24072
- useEffect37(() => {
24388
+ useEffect38(() => {
24073
24389
  const handler = (e) => {
24074
24390
  const detail = e.detail;
24075
24391
  if (!detail || detail.source !== source) return;
@@ -24079,7 +24395,7 @@ function EmbeddableChatInner({
24079
24395
  window.addEventListener("ask-ai:open-with-ref", handler);
24080
24396
  return () => window.removeEventListener("ask-ai:open-with-ref", handler);
24081
24397
  }, [source, discussRef, setIsOpen]);
24082
- useEffect37(() => {
24398
+ useEffect38(() => {
24083
24399
  const handler = (e) => {
24084
24400
  const detail = e.detail;
24085
24401
  if (!detail || detail.source !== source) return;
@@ -24091,7 +24407,8 @@ function EmbeddableChatInner({
24091
24407
  const hasMessages = messages.length > 0;
24092
24408
  const dialogsInitialLoading = isDialogsLoading && dialogs.length === 0;
24093
24409
  const dialogsLoadError = dialogsError && dialogs.length === 0;
24094
- const hasConversation = hasMessages || isOpeningDialog || isViewingArchived || previewMode && isMessagesLoading;
24410
+ const isLoadingActiveDialogMessages = activeDialogId != null && isMessagesLoading;
24411
+ const hasConversation = hasMessages || isOpeningDialog || isViewingArchived || isLoadingActiveDialogMessages || previewMode && isMessagesLoading;
24095
24412
  const messagesInitialLoading = isMessagesLoading && !hasMessages;
24096
24413
  const contentViewKey = hasConversation ? "conversation" : activeMode;
24097
24414
  const isGuideEmpty = !hasConversation && activeMode === "guide";
@@ -24099,11 +24416,11 @@ function EmbeddableChatInner({
24099
24416
  if (!isQuickActionEmpty && quickActionPreview !== null) setQuickActionPreview(null);
24100
24417
  const guideCanReturnToMingo = isGuideEmpty && hasMingoMode;
24101
24418
  const sourceLabel = source === "flamingo" ? "Knowledge Base" : "Data Room";
24102
- const enabledSet = useMemo29(
24419
+ const enabledSet = useMemo30(
24103
24420
  () => effectiveEnabledRagTableIds ? new Set(effectiveEnabledRagTableIds) : null,
24104
24421
  [effectiveEnabledRagTableIds]
24105
24422
  );
24106
- const chipCommands = useMemo29(() => {
24423
+ const chipCommands = useMemo30(() => {
24107
24424
  const out = [];
24108
24425
  for (const cmd of commandsById.values()) {
24109
24426
  if (cmd.displayOrder === void 0) continue;
@@ -24119,7 +24436,7 @@ function EmbeddableChatInner({
24119
24436
  return out;
24120
24437
  }, [commandsById, enabledSet]);
24121
24438
  const lastAssistantMsg = [...rawMessages].reverse().find((m) => m.role === "assistant");
24122
- const lastSources = useMemo29(() => {
24439
+ const lastSources = useMemo30(() => {
24123
24440
  if (chatLoading) return void 0;
24124
24441
  const sources = lastAssistantMsg?.sources;
24125
24442
  if (!sources || sources.length === 0) return void 0;
@@ -24133,28 +24450,25 @@ function EmbeddableChatInner({
24133
24450
  const uncited = sources.filter((s) => !seenOrder.has(s.index));
24134
24451
  return { cited, uncited };
24135
24452
  }, [lastAssistantMsg, chatLoading]);
24136
- const [portalHost, setPortalHost] = useState45(null);
24137
- const [panelBoundary, setPanelBoundary] = useState45(null);
24138
- const [panelWidth, setPanelWidth] = useState45(0);
24139
- const panelMeasureRef = useRef34(null);
24140
- useEffect37(() => {
24141
- const el = panelMeasureRef.current;
24142
- if (!el || typeof ResizeObserver === "undefined") return void 0;
24453
+ const [portalHost, setPortalHost] = useState47(null);
24454
+ const [panelBoundary, setPanelBoundary] = useState47(null);
24455
+ const [panelWidth, setPanelWidth] = useState47(0);
24456
+ useEffect38(() => {
24457
+ if (!panelBoundary || typeof ResizeObserver === "undefined") return void 0;
24143
24458
  const ro = new ResizeObserver((entries) => {
24144
24459
  const w = entries[0]?.contentRect?.width;
24145
24460
  if (typeof w === "number") setPanelWidth(w);
24146
24461
  });
24147
- ro.observe(el);
24148
- setPanelWidth(el.clientWidth);
24462
+ ro.observe(panelBoundary);
24149
24463
  return () => ro.disconnect();
24150
- }, []);
24151
- const setPanelNode = useCallback26((node) => {
24152
- panelMeasureRef.current = node;
24464
+ }, [panelBoundary]);
24465
+ const setPanelNode = useCallback27((node) => {
24153
24466
  setPanelBoundary(node);
24467
+ if (node) setPanelWidth(node.clientWidth);
24154
24468
  }, []);
24155
- const [railCollapsed, setRailCollapsed] = useState45(false);
24469
+ const [railCollapsed, setRailCollapsed] = useState47(false);
24156
24470
  const railStorageHydrated = useIsHydrated();
24157
- const [railStorageRead, setRailStorageRead] = useState45(false);
24471
+ const [railStorageRead, setRailStorageRead] = useState47(false);
24158
24472
  if (railStorageHydrated && !railStorageRead) {
24159
24473
  setRailStorageRead(true);
24160
24474
  try {
@@ -24162,7 +24476,7 @@ function EmbeddableChatInner({
24162
24476
  } catch {
24163
24477
  }
24164
24478
  }
24165
- const toggleRailCollapsed = useCallback26(() => {
24479
+ const toggleRailCollapsed = useCallback27(() => {
24166
24480
  setRailCollapsed((prev) => {
24167
24481
  const next = !prev;
24168
24482
  try {
@@ -24172,19 +24486,21 @@ function EmbeddableChatInner({
24172
24486
  return next;
24173
24487
  });
24174
24488
  }, []);
24175
- const [railSearchOpen, setRailSearchOpen] = useState45(false);
24176
- const splitEligible = activeMode === "mingo";
24489
+ const [railSearchOpen, setRailSearchOpen] = useState47(false);
24490
+ const splitEligible = historyListMode;
24177
24491
  const canSplit = panelWidth >= SPLIT_MIN_WIDTH;
24178
24492
  const wideMingo = splitEligible && canSplit && !previewMode;
24179
24493
  const splitActive = wideMingo && !railCollapsed;
24180
24494
  const railPresence = useRailPresence(splitActive);
24181
24495
  const showWideHeader = wideMingo || railPresence.mounted;
24182
- const [composeOpen, setComposeOpen] = useState45(false);
24496
+ const [composeOpen, setComposeOpen] = useState47(false);
24183
24497
  if (hasConversation && composeOpen) setComposeOpen(false);
24184
- const isMingoMode = activeMode === "mingo";
24185
- const stackedListView = isMingoMode && !hasConversation && !archiveOpen && !wideMingo && !composeOpen;
24498
+ const isMingoMode = historyListMode;
24499
+ const emptyListSkipped = mingoCaps.emptyListSkipsToCompose === true && dialogs.length === 0 && !dialogsInitialLoading && !mingoCaps.searchQuery;
24500
+ const stackedListView = isMingoMode && !hasConversation && !archiveOpen && !wideMingo && !composeOpen && !emptyListSkipped;
24186
24501
  const headerShowBack = hasConversation || guideCanReturnToMingo;
24187
- const headerTitle = hasConversation ? activeDialog?.title || "New Chat" : isGuideEmpty ? headerAssistantName ?? "Mingo Guide" : "Current Chats";
24502
+ const freshConversationTitle = isGuideEmpty ? headerAssistantName ?? "Mingo Guide" : "New Chat";
24503
+ const headerTitle = hasConversation ? activeDialog?.title || freshConversationTitle : isGuideEmpty ? freshConversationTitle : "Current Chats";
24188
24504
  const headerBackAriaLabel = hasConversation ? isViewingArchived ? "Back to archive" : "Back" : "Back to Mingo";
24189
24505
  const headerOnBack = hasConversation ? handleBack : () => handleActiveModeChange("mingo");
24190
24506
  const headerOnRestore = isViewingArchived && unarchiveDialog && activeDialog ? () => setRestoreTarget(activeDialog) : void 0;
@@ -24196,7 +24512,7 @@ function EmbeddableChatInner({
24196
24512
  const headerPersonName = headerOwner?.name?.trim() || headerUserName;
24197
24513
  const headerPersonAvatarUrl = headerOwner ? headerOwner.avatarUrl?.trim() || void 0 : identityUser?.avatarUrl?.trim() || userAvatarUrl?.trim() || void 0;
24198
24514
  const headerAvatar = headerPersonName || headerPersonAvatarUrl ? { name: headerPersonName, avatarUrl: headerPersonAvatarUrl } : void 0;
24199
- const handleNewChat = useCallback26(() => {
24515
+ const handleNewChat = useCallback27(() => {
24200
24516
  resetToNewChat();
24201
24517
  }, [resetToNewChat]);
24202
24518
  useImperativeHandle4(
@@ -24214,10 +24530,10 @@ function EmbeddableChatInner({
24214
24530
  headerOnRename && { id: "rename", label: "Rename chat", onClick: headerOnRename },
24215
24531
  headerOnArchive && { id: "archive", label: "Archive chat", onClick: headerOnArchive }
24216
24532
  ].filter(Boolean);
24217
- const narrowMingoEmpty = isMingoMode && !hasConversation && !archiveOpen;
24533
+ const narrowMingoEmpty = isMingoMode && !hasConversation && !archiveOpen && !emptyListSkipped;
24218
24534
  const narrowHeaderProps = narrowMingoEmpty ? composeOpen ? {
24219
24535
  showBack: true,
24220
- title: "New Chat",
24536
+ title: freshConversationTitle,
24221
24537
  subtitle: headerUserName,
24222
24538
  avatar: headerAvatar,
24223
24539
  backAriaLabel: "Back to chats",
@@ -24334,7 +24650,7 @@ function EmbeddableChatInner({
24334
24650
  ),
24335
24651
  /* @__PURE__ */ jsxs75("div", { className: "flex min-w-0 flex-1 items-center gap-[var(--spacing-system-m)] px-[var(--spacing-system-mf)] py-[var(--spacing-system-sf)]", children: [
24336
24652
  /* @__PURE__ */ jsxs75("div", { className: "flex min-w-0 flex-col", children: [
24337
- /* @__PURE__ */ jsx97("p", { className: "truncate leading-tight text-ods-text-primary text-h3", children: headerShowBack ? headerTitle : "New Chat" }),
24653
+ /* @__PURE__ */ jsx97("p", { className: "truncate leading-tight text-ods-text-primary text-h3", children: headerShowBack || isGuideEmpty ? headerTitle : freshConversationTitle }),
24338
24654
  headerPersonName && /* @__PURE__ */ jsx97("p", { className: "truncate leading-tight text-ods-text-secondary text-h6", children: headerPersonName })
24339
24655
  ] }),
24340
24656
  headerAvatar ? (
@@ -24656,7 +24972,7 @@ function EmbeddableChatInner({
24656
24972
  resizable: true,
24657
24973
  minSize: 480,
24658
24974
  maxSize: 1600,
24659
- defaultSize: drawerDefaultWidth(),
24975
+ defaultSize: drawerDefaultWidth(historyListMode),
24660
24976
  storageKey: DRAWER_WIDTH_KEY,
24661
24977
  resizeAriaLabel: "Resize chat panel",
24662
24978
  overlayClassName: "mingo-chat-overlay",
@@ -24997,6 +25313,7 @@ export {
24997
25313
  isStructuredContent,
24998
25314
  normalizeContent2 as normalizeContent,
24999
25315
  NETWORK_CONFIG,
25316
+ EMPTY_DIALOG_CAPABILITIES,
25000
25317
  useChunkCatchup,
25001
25318
  useScriptedStream,
25002
25319
  RESYNC_AFTER_HIDDEN_MS,
@@ -25031,6 +25348,7 @@ export {
25031
25348
  createChatDialogStore,
25032
25349
  createDeltaBatcher,
25033
25350
  useChatStreamReducer,
25351
+ createChatConversationsApi,
25034
25352
  parseWireCommandOverride,
25035
25353
  sanitizeTitleForChat,
25036
25354
  formatSingularLookupInvocation,
@@ -25039,6 +25357,7 @@ export {
25039
25357
  buildDiscussPrompt,
25040
25358
  AUTO_CONTINUATION_DIRECTIVE_PREFIX,
25041
25359
  buildAutoContinuationDirective,
25360
+ useManagedDialogList,
25042
25361
  useSseChatAdapter,
25043
25362
  extractIncompleteMessageState,
25044
25363
  extractIncompleteTailState,
@@ -25063,4 +25382,4 @@ export {
25063
25382
  buildStreamFrames,
25064
25383
  EmbeddableChat
25065
25384
  };
25066
- //# sourceMappingURL=chunk-VNSRNVPD.js.map
25385
+ //# sourceMappingURL=chunk-KJ5EQ6P6.js.map