@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
@@ -51,7 +51,7 @@
51
51
  * Ask + Display buttons WORK out of the box.
52
52
  */
53
53
 
54
- import { useCallback, useMemo, useRef } from 'react';
54
+ import { useCallback, useMemo, useRef, useState } from 'react';
55
55
  import { buildConfirmToolBody, readServerErrorMessage } from '../../../chat-protocol/confirm-tool';
56
56
  import { createSseFrameDecoder } from '../../../chat-protocol/decode';
57
57
  import type { ChatStreamEvent } from '../../../chat-protocol/events';
@@ -62,53 +62,46 @@ import { createChatDialogStore } from '../stream/chat-dialog-store';
62
62
  import type { ChatDialogStore } from '../stream/chat-dialog-store';
63
63
  import type { ChatStreamReducerOptions } from '../stream/chat-stream-reducer';
64
64
  import { useChatStreamReducer } from '../stream/use-chat-stream-reducer';
65
- import type { DialogItem } from '../types/component.types';
66
65
  import type { Message, MessageSegment } from '../types/message.types';
67
66
  import type {
67
+ ChatDialogCapabilities,
68
+ FetchDialogsParams,
68
69
  UnifiedChatState,
69
70
  UnifiedChatMessage,
70
71
  UnifiedSendMessageOptions,
71
72
  } from '../types/unified-chat-state.types';
72
73
  import { createChatConversationStorage, pruneStaleChatConversationStorage } from '../utils/chat-conversation-storage';
74
+ import { createChatConversationsApi } from '../utils/chat-conversations-api';
73
75
  import { buildDiscussPrompt } from '../utils/discuss-ref-prompt';
74
76
  import type { ScrollAnchor } from '../utils/scroll-anchor';
75
77
  import { sanitizeTitleForChat } from '../utils/slash-dispatch-utils';
76
78
  import type { WireCommandOverride } from '../utils/slash-dispatch-utils';
77
79
  import { defaultTableIdForDocumentType } from '../utils/source-icons';
78
80
  import { useChatHistoryHydration } from './use-chat-history-hydration';
81
+ import { useManagedDialogList } from './use-managed-dialog-list';
79
82
  import { useSlashCommandRegistry, type SlashCommandSummary } from './use-slash-commands';
80
83
 
81
84
  // Canonical home of the per-turn meta row moved to the stream module in
82
85
  // Phase 3; re-exported here to keep the legacy import path stable.
83
86
  export type { ChatTurnMeta } from '../stream/chat-stream-reducer';
84
87
 
85
- // ─── Stable no-op references for the Guide-mode dialog-management stubs ──
86
- // Plain module-scope constants so the adapter's return identity stays
87
- // stable across renders — consumers that memo on these fields don't get
88
- // spurious re-runs.
89
- const SSE_EMPTY_DIALOGS: DialogItem[] = [];
88
+ // ─── Stable no-op references for the capabilities Guide mode never has ──
89
+ // Plain module-scope constants so the adapter's return identity stays stable
90
+ // across renders — consumers that memo on these fields don't get spurious
91
+ // re-runs. The dialog LIST itself is no longer stubbed here: without a
92
+ // conversations endpoint the shared `useManagedDialogList` is inert by
93
+ // construction (empty list, false flags, memoized no-op mutations).
90
94
  const noopSelectDialog = (_id: string | null): void => {
91
- /* Guide mode has no managed dialog list yet */
95
+ /* No conversations endpoint configured — nothing to select */
92
96
  };
97
+ /** "New chat" is `clearMessages` (the server mints an id on the next send);
98
+ * there is no create call to make. */
93
99
  const noopStartNewDialog = (): Promise<string | null> => Promise.resolve(null);
94
100
  const noopDeleteDialog = async (_id: string): Promise<void> => {
95
- /* no-op until Guide server-side history is exposed as dialogs */
96
- };
97
- const noopRenameDialog = async (_id: string, _title: string): Promise<void> => {
98
- /* no-op until Guide server-side history is exposed as dialogs */
99
- };
100
- const noopArchiveDialog = async (_id: string): Promise<void> => {
101
- /* no-op until Guide server-side history is exposed as dialogs */
101
+ /* Deletion is not offered — archive replaces it. */
102
102
  };
103
103
  const noopAsync = async (): Promise<void> => {
104
- /* no-op pagination stub */
105
- };
106
- /** `reloadDialogs` is `() => void` in the unified contract, unlike the async
107
- * pagination stubs above — it is wired straight to an error-state `onRetry`,
108
- * which ignores a returned promise. Keeping it sync means no caller is handed
109
- * a promise it will silently drop. */
110
- const noopReloadDialogs = (): void => {
111
- /* no-op until Guide server-side history is exposed as dialogs */
104
+ /* no-op pagination stub (message history, which Guide does not page) */
112
105
  };
113
106
  const noopApproveRequest = async (_id: string): Promise<void> => {
114
107
  /* Guide mode has no tool-call approval workflow */
@@ -316,8 +309,6 @@ export function useSseChatAdapter(
316
309
  createReducerOptions,
317
310
  });
318
311
 
319
- const abortControllerRef = useRef<AbortController | null>(null);
320
-
321
312
  // ─── Conversation identity — server-minted id, restored once on mount ─────
322
313
  // Null = no conversation yet: the FIRST send goes out without an id, the
323
314
  // server mints one, and the metadata-frame capture (in the send loop below)
@@ -332,6 +323,20 @@ export function useSseChatAdapter(
332
323
  pruneStaleChatConversationStorage(source);
333
324
  conversationIdRef.current = conversationStorage.load()?.conversationId ?? null;
334
325
  }
326
+ // Render-visible mirror of the ref. The ref stays the SYNCHRONOUS send-time
327
+ // source (a capture mid-stream must be visible to the very next send); the
328
+ // state is what re-arms history hydration and drives `activeDialogId` when
329
+ // the user switches conversations. ONE writer for both + storage.
330
+ const [conversationId, setConversationId] = useState<string | null>(() => conversationIdRef.current);
331
+ const commitConversationId = useCallback(
332
+ (id: string | null) => {
333
+ conversationIdRef.current = id;
334
+ setConversationId(id);
335
+ if (id) conversationStorage.save({ conversationId: id });
336
+ else conversationStorage.clear();
337
+ },
338
+ [conversationStorage],
339
+ );
335
340
 
336
341
  // ─── Slash-command registry (displayRef lookup) ───────────────────────────
337
342
  // Reads from the SAME react-query cache entry as `<EmbeddableChat>`'s
@@ -401,18 +406,119 @@ export function useSseChatAdapter(
401
406
  },
402
407
  [mutate],
403
408
  );
409
+ // Live message count for the orphan guard below (a ref, so the callback's
410
+ // identity never changes — see the note on `onOrphanedConversation`).
411
+ const messagesLenRef = useRef(0);
412
+ messagesLenRef.current = state.messages.length;
413
+ const onOrphanedConversation = useCallback(
414
+ (id: string) => {
415
+ if (conversationIdRef.current === id && messagesLenRef.current === 0) commitConversationId(null);
416
+ },
417
+ [commitConversationId],
418
+ );
419
+
404
420
  const { isHydratingHistory, hydratedKeyRef } = useChatHistoryHydration({
405
421
  active,
406
422
  source,
407
423
  historyUrl,
408
- conversationIdRef,
424
+ conversationId,
409
425
  sendCountRef: hydrationSendCountRef,
410
426
  hydrateMessages,
411
427
  // Meta invalidation is a reducer concern here: `seedSseMaps` (inside
412
428
  // `hydrateMessages` above) already invalidates the snapshot.
413
429
  bumpMetaTick: noopBumpMetaTick,
430
+ // Drop a stored id the server no longer recognizes (deleted, or claimed by
431
+ // an account while this browser is signed out) — keeping it would stream
432
+ // answers the server refuses to persist. Guarded on "no live turn yet" so
433
+ // a just-minted id is never dropped.
434
+ //
435
+ // IDENTITY-STABLE by construction: this is a dependency of the hydration
436
+ // effect, so a callback that changed with the message count would CANCEL
437
+ // an in-flight hydration the moment the user typed — silently discarding
438
+ // the thread they just opened. The live count is read through a ref.
439
+ onOrphanedConversation,
414
440
  });
415
441
 
442
+ const abortControllerRef = useRef<AbortController | null>(null);
443
+
444
+ /** Switch the panel to another conversation (or to the draft state with
445
+ * `null`): abort any in-flight stream, flush + reset the reducer, re-arm
446
+ * the hydration guard, and commit the new id. `useChatHistoryHydration`
447
+ * then re-fetches for a non-null id through its `conversationId` dep. */
448
+ const switchConversation = useCallback(
449
+ (id: string | null) => {
450
+ abortControllerRef.current?.abort();
451
+ flushDeltas();
452
+ mutate(r => r.reset());
453
+ hydrationSendCountRef.current = 0;
454
+ hydratedKeyRef.current = null;
455
+ commitConversationId(id);
456
+ },
457
+ [flushDeltas, mutate, hydratedKeyRef, commitConversationId],
458
+ );
459
+
460
+ // ─── Managed dialog list (only with `chatConversationsUrl`) ───────────────
461
+ // The SAME list state machine the NATS adapter runs; the host contract is
462
+ // the hub's conversations route, spelled out once in
463
+ // `chat-conversations-api.ts`. Without the endpoint the hook is inert and
464
+ // the return shape below keeps the single-thread stubs — zero behaviour
465
+ // change for hosts that never set it.
466
+ const conversationsUrl = runtime.endpoints.chatConversationsUrl;
467
+ const conversationsApi = useMemo(
468
+ () => (conversationsUrl ? createChatConversationsApi(conversationsUrl) : null),
469
+ [conversationsUrl],
470
+ );
471
+ const [dialogSearch, setDialogSearch] = useState('');
472
+ const fetchActiveDialogs = useMemo(
473
+ () =>
474
+ conversationsApi
475
+ ? (params: FetchDialogsParams) => conversationsApi.fetchDialogs({ ...params, status: 'active' })
476
+ : undefined,
477
+ [conversationsApi],
478
+ );
479
+ const fetchArchivedDialogs = useMemo(
480
+ () =>
481
+ conversationsApi
482
+ ? (params: FetchDialogsParams) => conversationsApi.fetchDialogs({ ...params, status: 'archived' })
483
+ : undefined,
484
+ [conversationsApi],
485
+ );
486
+ const {
487
+ dialogs,
488
+ isDialogsLoading,
489
+ dialogsError,
490
+ hasMoreDialogs,
491
+ reloadDialogs,
492
+ loadMoreDialogs,
493
+ renameDialog,
494
+ archiveDialog,
495
+ upsertDialogTop,
496
+ bumpDialogToTop,
497
+ } = useManagedDialogList({
498
+ autoLoad: active,
499
+ fetchDialogs: fetchActiveDialogs,
500
+ renameDialog: conversationsApi?.renameDialog,
501
+ archiveDialog: conversationsApi?.archiveDialog,
502
+ pageSize: 20,
503
+ search: conversationsApi ? dialogSearch : undefined,
504
+ logTag: '[useSseChatAdapter]',
505
+ // Archiving the OPEN conversation drops back to the draft state (the
506
+ // manager also clears the thread; both paths are idempotent).
507
+ onDialogRemoved: id => {
508
+ if (conversationIdRef.current === id) switchConversation(null);
509
+ },
510
+ });
511
+ const unarchiveDialog = useMemo(
512
+ () =>
513
+ conversationsApi
514
+ ? async (id: string) => {
515
+ await conversationsApi.unarchiveDialog(id);
516
+ reloadDialogs();
517
+ }
518
+ : undefined,
519
+ [conversationsApi, reloadDialogs],
520
+ );
521
+
416
522
  // ─── Send / stream loop ────────────────────────────────────────────────────
417
523
 
418
524
  /**
@@ -435,15 +541,19 @@ export function useSseChatAdapter(
435
541
  * same conversation. The reducer ignores the field (identity is a
436
542
  * transport/persistence concern, not render state). */
437
543
  const captureConversationId = useCallback(
438
- (event: ChatStreamEvent): void => {
439
- if (event.type !== 'metadata') return;
544
+ (event: ChatStreamEvent): boolean => {
545
+ if (event.type !== 'metadata') return false;
440
546
  const id = event.conversationId;
441
- if (typeof id !== 'string' || !id) return;
442
- if (conversationIdRef.current === id) return;
443
- conversationIdRef.current = id;
444
- conversationStorage.save({ conversationId: id });
547
+ if (typeof id !== 'string' || !id) return false;
548
+ if (conversationIdRef.current === id) return false;
549
+ // Mark the new id as ALREADY hydrated before it becomes render state:
550
+ // the turn being streamed IS its history, and a mount-style fetch here
551
+ // would prepend that same turn once the server has persisted it.
552
+ hydratedKeyRef.current = `${source}:${id}`;
553
+ commitConversationId(id);
554
+ return true;
445
555
  },
446
- [conversationStorage],
556
+ [commitConversationId, hydratedKeyRef, source],
447
557
  );
448
558
 
449
559
  const sendMessage = useCallback(
@@ -460,19 +570,19 @@ export function useSseChatAdapter(
460
570
  // The server is the single source of conversation history: it re-reads
461
571
  // `chat_messages` by conversation id on every turn. The wire therefore
462
572
  // carries ONLY the new user message — never the prior conversation.
463
- const conversationId = conversationIdRef.current;
573
+ const echoedConversationId = conversationIdRef.current;
464
574
  const targetPath = approvalAction ? endpointsRef.current.approvalToolUrl : endpointsRef.current.chatStreamUrl;
465
575
  const requestBody = approvalAction
466
576
  ? // Shared with every other transport that resolves a hub proposal —
467
577
  // the body shape is the hub's, not this adapter's. `conversationId`
468
578
  // is always present here: an approval can only happen inside an
469
579
  // established conversation (the proposal turn captured the id).
470
- buildConfirmToolBody({ ...approvalAction, conversationId })
580
+ buildConfirmToolBody({ ...approvalAction, conversationId: echoedConversationId })
471
581
  : {
472
582
  messages: [{ role: 'user', content: text }],
473
583
  ...(commandOverride ? { commandOverride } : {}),
474
584
  ...(attachments && attachments.length > 0 ? { pendingAttachments: attachments } : {}),
475
- ...(conversationId ? { conversationId } : {}),
585
+ ...(echoedConversationId ? { conversationId: echoedConversationId } : {}),
476
586
  };
477
587
 
478
588
  // Optimistic user bubble + assistant placeholder + phase 'thinking'
@@ -481,6 +591,7 @@ export function useSseChatAdapter(
481
591
 
482
592
  const ctrl = new AbortController();
483
593
  abortControllerRef.current = ctrl;
594
+ let mintedThisTurn = false;
484
595
 
485
596
  try {
486
597
  // `embedAuthedFetch` carries the bearer-act-as headers (+ Supabase
@@ -513,7 +624,19 @@ export function useSseChatAdapter(
513
624
  if (done) break;
514
625
  if (ctrl.signal.aborted) break;
515
626
  for (const event of frameDecoder.push(value)) {
516
- captureConversationId(event);
627
+ if (captureConversationId(event)) {
628
+ mintedThisTurn = true;
629
+ // Optimistic row so the list shows the new conversation at
630
+ // once; the end-of-turn reload swaps in the server's title.
631
+ // NEUTRAL placeholder — the SERVER owns titles (it strips slash
632
+ // commands + attachment markdown and cuts at a word boundary),
633
+ // so guessing here would flash a signed attachment URL or a
634
+ // `/command` token, and a naive slice can split an emoji.
635
+ const mintedId = conversationIdRef.current;
636
+ if (conversationsApi && !hidden && mintedId) {
637
+ upsertDialogTop({ id: mintedId, title: 'New chat', timestamp: new Date() });
638
+ }
639
+ }
517
640
  applyEvent(event);
518
641
  }
519
642
  }
@@ -550,9 +673,33 @@ export function useSseChatAdapter(
550
673
  // path streams no text — and returns the phase to idle).
551
674
  flushDeltas();
552
675
  mutate(r => r.endSseTurn());
676
+ // Keep the managed list in step with the transcript: a first turn
677
+ // re-reads the list (server-derived title replaces the placeholder,
678
+ // the row is persisted by the time the stream ends); a later turn
679
+ // just bumps the row to the top.
680
+ if (conversationsApi && !ctrl.signal.aborted) {
681
+ if (mintedThisTurn) {
682
+ reloadDialogs();
683
+ } else if (conversationIdRef.current) {
684
+ // Re-insert at the TOP rather than patching in place: the server
685
+ // has moved this row to the head of `last_message_at desc`, so an
686
+ // in-place bump would leave the rail's order and its
687
+ // Today/Yesterday grouping disagreeing with the server.
688
+ bumpDialogToTop(conversationIdRef.current);
689
+ }
690
+ }
553
691
  }
554
692
  },
555
- [mutate, applyEvent, flushDeltas, captureConversationId],
693
+ [
694
+ mutate,
695
+ applyEvent,
696
+ flushDeltas,
697
+ captureConversationId,
698
+ conversationsApi,
699
+ upsertDialogTop,
700
+ reloadDialogs,
701
+ bumpDialogToTop,
702
+ ],
556
703
  );
557
704
  sendMessageRef.current = sendMessage;
558
705
 
@@ -568,11 +715,40 @@ export function useSseChatAdapter(
568
715
  // server-side; the NEXT send goes out id-less and the server mints a
569
716
  // fresh conversation (echoed back and re-captured then). Resetting the
570
717
  // hydration guard means a re-captured id can hydrate again if needed.
571
- conversationIdRef.current = null;
572
- conversationStorage.clear();
718
+ commitConversationId(null);
573
719
  hydrationSendCountRef.current = 0;
574
720
  hydratedKeyRef.current = null;
575
- }, [mutate, conversationStorage, hydratedKeyRef]);
721
+ }, [mutate, commitConversationId, hydratedKeyRef]);
722
+
723
+ /** Open a conversation from the managed list. Idempotent on the active id. */
724
+ const selectDialog = useCallback(
725
+ (id: string | null) => {
726
+ if (id === conversationIdRef.current) return;
727
+ switchConversation(id);
728
+ },
729
+ [switchConversation],
730
+ );
731
+
732
+ // Present ONLY with a conversations endpoint — its absence is what keeps a
733
+ // Guide panel single-thread, and it is the single signal `EmbeddableChat`
734
+ // gates the whole history surface on.
735
+ const dialogCapabilities = useMemo<ChatDialogCapabilities | undefined>(
736
+ () =>
737
+ conversationsApi
738
+ ? {
739
+ canRename: true,
740
+ canArchive: true,
741
+ fetchArchivedDialogs,
742
+ unarchiveDialog,
743
+ searchQuery: dialogSearch,
744
+ onSearchChange: setDialogSearch,
745
+ // A public panel's first-time visitor must reach the composer
746
+ // without tapping through an empty list.
747
+ emptyListSkipsToCompose: true,
748
+ }
749
+ : undefined,
750
+ [conversationsApi, fetchArchivedDialogs, unarchiveDialog, dialogSearch],
751
+ );
576
752
 
577
753
  // ─── Public message mapping (sendIdx fan-out lookup) ──────────────────────
578
754
  // Index sources/scrollAnchor by USER-SEND count (`sendIdx`), not by
@@ -721,26 +897,29 @@ export function useSseChatAdapter(
721
897
  /** Cross-call usage breakdown (Haiku rewriter/classifier/summarizer
722
898
  * token counts). null until the trailing usage frame lands. */
723
899
  currentUsageBreakdown: latestMeta?.breakdown ?? null,
724
- // ─── Dialog management — stubs for v1 ────────────────────────────────
725
- // Guide mode keeps ONE server-side conversation per stored id
726
- // (`chat_conversations`, hydrated on mount). Surfacing multiple threads
727
- // as a structured dialog list is a follow-up; for now the shape is
728
- // satisfied with empty defaults so the unified contract type-checks and
729
- // EmbeddableChat hides sidebar affordances when `dialogs.length === 0`.
730
- dialogs: SSE_EMPTY_DIALOGS,
731
- activeDialogId: null,
732
- selectDialog: noopSelectDialog,
900
+ // ─── Dialog management ───────────────────────────────────────────────
901
+ // With `chatConversationsUrl` the server transcript store IS the dialog
902
+ // list (shared `useManagedDialogList`); selecting a row re-hydrates through
903
+ // the history route. WITHOUT it the same hook is inert by construction —
904
+ // no `fetchDialogs`, so an empty list, false flags and memoized no-op
905
+ // mutations — which is why only the four genuinely mode-dependent fields
906
+ // are branched here.
907
+ dialogs,
908
+ isDialogsLoading,
909
+ dialogsError,
910
+ reloadDialogs,
911
+ hasMoreDialogs,
912
+ loadMoreDialogs,
913
+ renameDialog,
914
+ archiveDialog,
915
+ // New chat = `clearMessages` (the server mints on the next send); there is
916
+ // no create call. Delete is not offered — archive replaces it.
733
917
  startNewDialog: noopStartNewDialog,
734
918
  deleteDialog: noopDeleteDialog,
735
- renameDialog: noopRenameDialog,
736
- archiveDialog: noopArchiveDialog,
737
- isDialogsLoading: false,
738
- // SSE/guide has no server-side dialog list — never errors, nothing to retry.
739
- dialogsError: false,
740
- reloadDialogs: noopReloadDialogs,
741
- isMessagesLoading: false,
742
- hasMoreDialogs: false,
743
- loadMoreDialogs: noopAsync,
919
+ activeDialogId: conversationsApi ? conversationId : null,
920
+ selectDialog: conversationsApi ? selectDialog : noopSelectDialog,
921
+ isMessagesLoading: conversationsApi ? isHydratingHistory : false,
922
+ dialogCapabilities,
744
923
  hasMoreMessages: false,
745
924
  loadMoreMessages: noopAsync,
746
925
  approveRequest: noopApproveRequest,
@@ -19,7 +19,8 @@
19
19
  */
20
20
 
21
21
  import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
22
- import type { UnifiedChatState } from '../types/unified-chat-state.types';
22
+ import { EMPTY_DIALOG_CAPABILITIES } from '../types/unified-chat-state.types';
23
+ import type { ChatDialogCapabilities, UnifiedChatState } from '../types/unified-chat-state.types';
23
24
  import { useNatsChatAdapter, type UseNatsChatAdapterConfig } from './use-nats-chat-adapter';
24
25
  import { useSseChatAdapter, type UseSseChatAdapterOptions } from './use-sse-chat-adapter';
25
26
 
@@ -70,6 +71,18 @@ export interface UseUnifiedChatOptions {
70
71
  * hook's local React state. Guide mode is unaffected.
71
72
  */
72
73
  mingoStateOverride?: UnifiedChatState;
74
+
75
+ /**
76
+ * Conversation-list capabilities for a `mingoStateOverride`. A host that
77
+ * builds the whole state in its own store has no adapter to report them, so
78
+ * it declares them alongside the state it injects.
79
+ *
80
+ * Supplying the override AT ALL declares that its panel owns a conversation
81
+ * list — an override with no capabilities still resolves to an empty object,
82
+ * never `undefined`, so such a host keeps its list surface exactly as before.
83
+ * Ignored unless the override is the active state.
84
+ */
85
+ injectedDialogCapabilities?: ChatDialogCapabilities;
73
86
  }
74
87
 
75
88
  // =============================================================================
@@ -96,7 +109,7 @@ function createDisabledNatsConfig(): UseNatsChatAdapterConfig {
96
109
  // =============================================================================
97
110
 
98
111
  export function useUnifiedChat(options: UseUnifiedChatOptions): UnifiedChatState {
99
- const { modes, activeMode, mingoStateOverride } = options;
112
+ const { modes, activeMode, mingoStateOverride, injectedDialogCapabilities } = options;
100
113
 
101
114
  // The mingo config object identity matters — `useNatsChatAdapter`
102
115
  // wires its `dialogId`/url/publish into deps. Stabilise the disabled
@@ -121,6 +134,14 @@ export function useUnifiedChat(options: UseUnifiedChatOptions): UnifiedChatState
121
134
  // still runs (rules of hooks) but is idle (no `modes.mingo` → not active),
122
135
  // and we hand the host's store-backed state straight through as active.
123
136
  const activeState = activeMode === 'guide' ? sseState : (mingoStateOverride ?? natsState);
137
+ // The ONE place the injected state's capabilities are defaulted, because this
138
+ // is the ONE place that decides which state won. `EmbeddableChat` therefore
139
+ // reads a single resolved `dialogCapabilities` and never re-derives it from
140
+ // the mode.
141
+ const activeStateIsInjected = activeState === mingoStateOverride;
142
+ const dialogCapabilities = activeStateIsInjected
143
+ ? (activeState.dialogCapabilities ?? injectedDialogCapabilities ?? EMPTY_DIALOG_CAPABILITIES)
144
+ : activeState.dialogCapabilities;
124
145
 
125
146
  // Live ref to the active state. The injected `mingoState` (and the SSE/NATS
126
147
  // adapters) hand back a NEW state object on EVERY streaming chunk
@@ -220,6 +241,8 @@ export function useUnifiedChat(options: UseUnifiedChatOptions): UnifiedChatState
220
241
  setDialogScope,
221
242
  hasMoreMessages: activeState.hasMoreMessages,
222
243
  loadMoreMessages,
244
+ // THE conversation-list signal — resolved once, above.
245
+ dialogCapabilities,
223
246
  // Approvals
224
247
  approveRequest,
225
248
  rejectRequest,
@@ -229,6 +252,7 @@ export function useUnifiedChat(options: UseUnifiedChatOptions): UnifiedChatState
229
252
  }),
230
253
  [
231
254
  activeState,
255
+ dialogCapabilities,
232
256
  sendMessage,
233
257
  stopMessage,
234
258
  clearMessages,
@@ -1,6 +1,18 @@
1
- <!-- source-hash: c1ee0588313988b2559f2016a0a5d7cf -->
1
+ <!-- source-hash: dfcacb5bf08b66f3f617f36bfc6414c6 -->
2
2
  Unified contract type definitions for the `useChat` hook's transport-agnostic return shape, shared by both the SSE (Guide mode) and NATS (Mingo mode) transport adapters.
3
3
 
4
+ ### Dialog-list host contract (shared by both adapters)
5
+
6
+ | Export | Kind | Description |
7
+ |---|---|---|
8
+ | `FetchDialogsParams` | interface | `{ cursor?, limit?, search? }` — page-fetch params passed to a host `fetchDialogs`. `search` is present ONLY when the adapter runs a server-side list search |
9
+ | `FetchDialogsResult` | interface | `{ dialogs: DialogItem[], nextCursor: string \| null }` — `null` terminates infinite scroll |
10
+ | `ChatDialogCapabilities` | interface | What a transport (or an injecting host) can honour: `canRename`, `canArchive`, `fetchArchivedDialogs`, `unarchiveDialog`, `searchQuery`, `onSearchChange`, `onCopyLink`. ONE shape for both the adapter-owned (`UnifiedChatState.dialogCapabilities`) and host-injected (`EmbeddableChatProps.mingoDialogCapabilities`) paths |
11
+
12
+ `renameDialog` / `archiveDialog` / `deleteDialog` REJECT on a failed backend write (rename after rolling its optimistic title back) so a confirmation modal can stay open — callers must await or catch.
13
+
14
+ `UnifiedChatState` addition: **`dialogCapabilities?: ChatDialogCapabilities`** — THE conversation-list signal, present iff the state owns a list. `EmbeddableChat` gates its whole history surface on its presence rather than on the mode, so Guide mode gets the same "Current Chats" rail as Mingo. Deliberately ONE field: a `dialogsManaged` boolean beside the object would be a second signal derived from the same predicate, free to disagree with it and easy for a producer to forget. Inside the object each field gates one affordance by presence, so the ⋯ menu never advertises an unwired action; `emptyListSkipsToCompose` is the list owner's policy for a settled-empty list (a public panel skips it, a workspace panel keeps it). `EMPTY_DIALOG_CAPABILITIES` is the frozen "owns a list, no affordances" singleton — frozen because it is read inside memo dependency lists.
15
+
4
16
  ## Key Components
5
17
 
6
18
  | Export | Kind | Description |
@@ -24,6 +24,67 @@ import type { DialogItem } from './component.types';
24
24
  import type { ChatContextItem } from './context-item.types';
25
25
  import type { MessageSegment, ScrollAnchor } from './message.types';
26
26
 
27
+ // ─── Dialog-list host contract (shared by the NATS + SSE adapters) ───────────
28
+
29
+ /** Page-fetch parameters passed to a host `fetchDialogs` callback. The
30
+ * adapter owns the cursor — the host only resolves it against the backend.
31
+ * `search` is present ONLY when the adapter runs a server-side list search
32
+ * (never spread as an `undefined` key). */
33
+ export interface FetchDialogsParams {
34
+ cursor?: string;
35
+ limit?: number;
36
+ search?: string;
37
+ }
38
+
39
+ /** Successful `fetchDialogs` response. `nextCursor: null` means "no more
40
+ * pages" — used to terminate the infinite-scroll observer in the list. */
41
+ export interface FetchDialogsResult {
42
+ dialogs: DialogItem[];
43
+ nextCursor: string | null;
44
+ }
45
+
46
+ /**
47
+ * Dialog-management capabilities a transport exposes to `EmbeddableChat`.
48
+ * Structurally identical to the host-injected `mingoDialogCapabilities`
49
+ * prop — one shape, whether the list is host-owned (openframe `mingoState`)
50
+ * or adapter-owned (`UnifiedChatState.dialogCapabilities`).
51
+ */
52
+ export interface ChatDialogCapabilities {
53
+ /** Show "Rename chat" in the row ⋯ menu and the conversation header. */
54
+ canRename?: boolean;
55
+ /** Show "Archive chat" in the row ⋯ menu and the conversation header. */
56
+ canArchive?: boolean;
57
+ /** Pages archived dialogs — presence gates the archive page + header button. */
58
+ fetchArchivedDialogs?: (params: FetchDialogsParams) => Promise<FetchDialogsResult>;
59
+ /** Restores an archived dialog — presence gates the restore button. */
60
+ unarchiveDialog?: (id: string) => Promise<void>;
61
+ /** Current list-search term (host/adapter owned; the list never filters). */
62
+ searchQuery?: string;
63
+ /** Presence wires the header magnifier + the rail's search field. */
64
+ onSearchChange?: (query: string) => void;
65
+ /** "Copy chat link" — the owner of the URL shape + clipboard write. */
66
+ onCopyLink?: (dialog: DialogItem) => void;
67
+ /**
68
+ * When the list has settled EMPTY and is unsearched, land on the composer
69
+ * instead of an empty "Current Chats" screen.
70
+ *
71
+ * A policy, not a transport detail: a public marketing panel must not make a
72
+ * first-time visitor tap through an empty list to ask a question, while a
73
+ * signed-in workspace panel wants the list (with its "Start New Chat"
74
+ * affordance) as the landing surface. Omit to keep the list.
75
+ */
76
+ emptyListSkipsToCompose?: boolean;
77
+ }
78
+
79
+ /**
80
+ * "This panel owns a conversation list, and no optional affordance on it."
81
+ *
82
+ * A frozen module singleton so it is referentially stable across renders —
83
+ * it is read inside memo dependency lists, where a fresh `{}` would
84
+ * invalidate them on every pass.
85
+ */
86
+ export const EMPTY_DIALOG_CAPABILITIES: ChatDialogCapabilities = Object.freeze({});
87
+
27
88
  // ─── Per-dialog token usage (Mingo backend telemetry) ────────────────────────
28
89
 
29
90
  /**
@@ -357,17 +418,28 @@ export interface UnifiedChatState {
357
418
  * adapter doesn't support creation, resolves to `null`. */
358
419
  startNewDialog: () => Promise<string | null>;
359
420
 
360
- /** Delete a dialog from history. No-op when the adapter doesn't
361
- * expose `deleteDialog` (Guide localStorage always supports it;
362
- * Mingo gates on the host-provided callback). */
421
+ /** Delete a dialog from history. No-op (resolves) when the adapter doesn't
422
+ * expose `deleteDialog`.
423
+ *
424
+ * REJECTS when the backend call fails — the row is kept and the error is
425
+ * re-thrown so a confirmation modal can stay open for a retry instead of
426
+ * closing over a write that never landed. Callers must `await`/`.catch()`;
427
+ * a bare `void state.deleteDialog(id)` produces an unhandled rejection. */
363
428
  deleteDialog: (id: string) => Promise<void>;
364
429
 
365
430
  /** Rename a dialog. Optimistically updates the title in the local list.
366
- * No-op when the adapter doesn't expose a rename callback. */
431
+ * No-op (resolves) when the adapter doesn't expose a rename callback.
432
+ *
433
+ * ALWAYS RESOLVES — unlike `deleteDialog` / `archiveDialog`. A failure rolls
434
+ * the optimistic title back and is logged, never re-thrown, because
435
+ * `useChatDialogManager` fires rename as `void renameDialog(...)` and closes
436
+ * its modal immediately; rejecting here would only produce an unhandled
437
+ * rejection. The rollback is the user-visible signal. */
367
438
  renameDialog: (id: string, title: string) => Promise<void>;
368
439
 
369
- /** Archive a dialog (removes it from the active list). No-op when the
370
- * adapter doesn't expose an archive callback. */
440
+ /** Archive a dialog (removes it from the active list). No-op (resolves) when
441
+ * the adapter doesn't expose an archive callback.
442
+ * REJECTS on failure, keeping the row — see `deleteDialog`. */
371
443
  archiveDialog: (id: string) => Promise<void>;
372
444
 
373
445
  /** True while the dialog list is being fetched for the first time. */
@@ -405,6 +477,21 @@ export interface UnifiedChatState {
405
477
  /** Fetch the next page of historical messages for the active dialog. */
406
478
  loadMoreMessages: () => Promise<void>;
407
479
 
480
+ /**
481
+ * THE conversation-list signal. Present iff this state owns a conversation
482
+ * list; absent = a single-thread panel. `EmbeddableChat` gates the whole
483
+ * history surface — rail, stacked list, archive page, rename/archive menus,
484
+ * header search — on its presence alone, so the panel never asks WHICH
485
+ * transport it is talking to. Each field inside it then gates one
486
+ * affordance, on the same rule the rest of this file uses: the presence of
487
+ * a callback IS the capability.
488
+ *
489
+ * Deliberately ONE field, not a `dialogsManaged` boolean beside an object:
490
+ * two signals derived from the same predicate can disagree, and every
491
+ * producer would have to remember to set both.
492
+ */
493
+ dialogCapabilities?: ChatDialogCapabilities;
494
+
408
495
  // ─── Approval mutations (Mingo agent tool-call workflow) ──────────────────
409
496
 
410
497
  /** Approve an in-flight tool-call request. Errors surface via the
@@ -0,0 +1,16 @@
1
+ <!-- source-hash: a771c833d70e73ea6c8571343495d470 -->
2
+ Wire client for the SSE/Guide conversation list — the ONE place the `ChatRuntime.endpoints.chatConversationsUrl` contract is spelled out.
3
+
4
+ ## Key Components
5
+
6
+ ### `createChatConversationsApi(baseUrl)` → `ChatConversationsApi`
7
+ - `fetchDialogs({ status, cursor, limit, search })` — `GET <base>?status=active|archived&limit=&cursor=&search=` (empty params omitted); unwraps the route-base `{ data }` envelope; maps rows to `DialogItem` (ISO `timestamp` → `Date`, empty title → `'Untitled chat'`)
8
+ - `renameDialog(id, title)` — `PATCH <base>/<id>` body `{ title }`
9
+ - `archiveDialog(id)` — `PATCH <base>/<id>` body `{ archived: true }`
10
+ - `unarchiveDialog(id)` — `PATCH <base>/<id>` body `{ archived: false }`
11
+
12
+ All calls go through `embedAuthedFetch` with its DEFAULT credentials mode: the hub identifies anonymous visitors with an httpOnly cookie and `same-origin` is what carries it — never override `credentials`. Failures throw the server's own error copy (`readServerErrorMessage`) or a status fallback.
13
+
14
+ ## Source
15
+
16
+ [`chat-conversations-api.ts`](https://github.com/flamingo-stack/openframe-oss-lib/blob/main/chat-conversations-api.ts)