@flamingo-stack/openframe-frontend-core 0.0.598 → 0.0.599-2039.5716.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.
- package/dist/chat-protocol/index.cjs +8 -1
- package/dist/chat-protocol/index.cjs.map +1 -1
- package/dist/chat-protocol/index.d.ts +1 -0
- package/dist/chat-protocol/index.d.ts.map +1 -1
- package/dist/chat-protocol/index.js +7 -2
- package/dist/chat-protocol/index.js.map +1 -1
- package/dist/chat-protocol/nats-decoder.d.ts.map +1 -1
- package/dist/chat-protocol/wire-narrow.d.ts +17 -0
- package/dist/chat-protocol/wire-narrow.d.ts.map +1 -0
- package/dist/{chunk-VLJTJAHJ.cjs → chunk-2B4HSYAX.cjs} +25 -25
- package/dist/{chunk-VLJTJAHJ.cjs.map → chunk-2B4HSYAX.cjs.map} +1 -1
- package/dist/{chunk-UE7OFLLS.cjs → chunk-2GCBN73M.cjs} +14 -14
- package/dist/{chunk-UE7OFLLS.cjs.map → chunk-2GCBN73M.cjs.map} +1 -1
- package/dist/{chunk-STYNZ4QM.cjs → chunk-3IXDZI3R.cjs} +3 -3
- package/dist/{chunk-STYNZ4QM.cjs.map → chunk-3IXDZI3R.cjs.map} +1 -1
- package/dist/{chunk-DAPOBLAK.cjs → chunk-3RWSKUIN.cjs} +39 -39
- package/dist/{chunk-DAPOBLAK.cjs.map → chunk-3RWSKUIN.cjs.map} +1 -1
- package/dist/{chunk-VNSRNVPD.js → chunk-4HJYXP5O.js} +722 -406
- package/dist/chunk-4HJYXP5O.js.map +1 -0
- package/dist/{chunk-HWAYIK4U.cjs → chunk-4MOY5TQR.cjs} +22 -22
- package/dist/{chunk-HWAYIK4U.cjs.map → chunk-4MOY5TQR.cjs.map} +1 -1
- package/dist/{chunk-VIRTMRS4.js → chunk-4PBUEYAE.js} +7 -7
- package/dist/{chunk-TZPVRWPU.js → chunk-4TG5BWPE.js} +5 -5
- package/dist/{chunk-PTK3CINU.js → chunk-6JF65LRQ.js} +5 -5
- package/dist/{chunk-YWBAIFI2.cjs → chunk-6XISE63Q.cjs} +105 -105
- package/dist/{chunk-YWBAIFI2.cjs.map → chunk-6XISE63Q.cjs.map} +1 -1
- package/dist/{chunk-QD64Q4I2.cjs → chunk-A4HMGZ4L.cjs} +9 -9
- package/dist/{chunk-QD64Q4I2.cjs.map → chunk-A4HMGZ4L.cjs.map} +1 -1
- package/dist/{chunk-BK6CCQG6.js → chunk-AUCJ6I3R.js} +12 -12
- package/dist/{chunk-3WSS7C2V.cjs → chunk-BBBZ5QUB.cjs} +15 -15
- package/dist/{chunk-3WSS7C2V.cjs.map → chunk-BBBZ5QUB.cjs.map} +1 -1
- package/dist/{chunk-EVMHJB6X.js → chunk-BLUL2TE3.js} +4 -4
- package/dist/{chunk-GGQZBSFN.js → chunk-BVQEU5JB.js} +2 -2
- package/dist/{chunk-V2QK5W3O.cjs → chunk-BW644MGF.cjs} +3 -3
- package/dist/{chunk-V2QK5W3O.cjs.map → chunk-BW644MGF.cjs.map} +1 -1
- package/dist/{chunk-H64ZHSYR.cjs → chunk-CCWI3622.cjs} +4 -4
- package/dist/{chunk-H64ZHSYR.cjs.map → chunk-CCWI3622.cjs.map} +1 -1
- package/dist/{chunk-DI3SVVY5.cjs → chunk-COERKO4N.cjs} +85 -85
- package/dist/{chunk-DI3SVVY5.cjs.map → chunk-COERKO4N.cjs.map} +1 -1
- package/dist/{chunk-SE3PVN64.js → chunk-DZ44C6KB.js} +2 -2
- package/dist/{chunk-2SYX2Z7R.cjs → chunk-E27TMQRE.cjs} +34 -34
- package/dist/{chunk-2SYX2Z7R.cjs.map → chunk-E27TMQRE.cjs.map} +1 -1
- package/dist/{chunk-YH6IQTPI.cjs → chunk-EHAYNUOL.cjs} +3 -3
- package/dist/{chunk-YH6IQTPI.cjs.map → chunk-EHAYNUOL.cjs.map} +1 -1
- package/dist/{chunk-WZJOILPU.js → chunk-F2KBCLUG.js} +2 -2
- package/dist/{chunk-MYBXCWEI.js → chunk-FKBM6U43.js} +2 -2
- package/dist/{chunk-75YW6ET4.js → chunk-FNK4RZ25.js} +4 -4
- package/dist/{chunk-UG7JNQZY.cjs → chunk-GB5FPCUN.cjs} +37 -37
- package/dist/{chunk-UG7JNQZY.cjs.map → chunk-GB5FPCUN.cjs.map} +1 -1
- package/dist/{chunk-P24VPJTT.cjs → chunk-HJUXXWTM.cjs} +15 -15
- package/dist/{chunk-P24VPJTT.cjs.map → chunk-HJUXXWTM.cjs.map} +1 -1
- package/dist/{chunk-WPN545FW.js → chunk-ILJTXIEI.js} +12 -12
- package/dist/{chunk-YBPFIXV4.cjs → chunk-ITZDJYWI.cjs} +796 -480
- package/dist/chunk-ITZDJYWI.cjs.map +1 -0
- package/dist/{chunk-LRQCKSZC.js → chunk-IW746HJ7.js} +2 -2
- package/dist/{chunk-PX4IPM7Q.js → chunk-J62LLUDC.js} +3 -3
- package/dist/{chunk-M4YQUHOR.cjs → chunk-JJUV7Z4L.cjs} +15 -15
- package/dist/{chunk-M4YQUHOR.cjs.map → chunk-JJUV7Z4L.cjs.map} +1 -1
- package/dist/{chunk-GHYFVT52.js → chunk-JZF6EUMO.js} +5 -5
- package/dist/{chunk-JVZVVZOZ.cjs → chunk-KYGTR6EG.cjs} +9 -9
- package/dist/{chunk-JVZVVZOZ.cjs.map → chunk-KYGTR6EG.cjs.map} +1 -1
- package/dist/{chunk-QIKBISZM.cjs → chunk-L66UPFCQ.cjs} +242 -242
- package/dist/{chunk-QIKBISZM.cjs.map → chunk-L66UPFCQ.cjs.map} +1 -1
- package/dist/{chunk-NIAMPMKV.js → chunk-LJ4UG2SW.js} +4 -4
- package/dist/{chunk-WDWCQD75.js → chunk-MWQSHXYK.js} +9 -9
- package/dist/{chunk-BPVHDDNY.cjs → chunk-NLFST5II.cjs} +8 -8
- package/dist/{chunk-BPVHDDNY.cjs.map → chunk-NLFST5II.cjs.map} +1 -1
- package/dist/{chunk-SAEJGTCI.cjs → chunk-QPAPUIF3.cjs} +35 -35
- package/dist/{chunk-SAEJGTCI.cjs.map → chunk-QPAPUIF3.cjs.map} +1 -1
- package/dist/{chunk-HLPAVYK7.js → chunk-RSTEDWAT.js} +4 -4
- package/dist/{chunk-UAAXUFK6.js → chunk-RU3IKVY2.js} +3 -3
- package/dist/{chunk-EZM5DNII.js → chunk-S6WBBSII.js} +3 -3
- package/dist/{chunk-2JNCZDJR.js → chunk-TSCIVH7T.js} +2 -2
- package/dist/{chunk-RDTOMWDN.cjs → chunk-UPKZU6QU.cjs} +1 -1
- package/dist/chunk-UPKZU6QU.cjs.map +1 -0
- package/dist/{chunk-WCBRZCU4.cjs → chunk-UQEOAPAI.cjs} +9 -9
- package/dist/{chunk-WCBRZCU4.cjs.map → chunk-UQEOAPAI.cjs.map} +1 -1
- package/dist/{chunk-O4VZOA2Q.cjs → chunk-UXOOVP77.cjs} +3 -3
- package/dist/{chunk-O4VZOA2Q.cjs.map → chunk-UXOOVP77.cjs.map} +1 -1
- package/dist/{chunk-R4UV366K.js → chunk-UYLZAW6Y.js} +6 -6
- package/dist/{chunk-BZEWPW5A.cjs → chunk-VIBREYUK.cjs} +3 -3
- package/dist/{chunk-BZEWPW5A.cjs.map → chunk-VIBREYUK.cjs.map} +1 -1
- package/dist/{chunk-KHOZ52NR.js → chunk-XSMBLU44.js} +6 -6
- package/dist/{chunk-RYXIRVDC.js → chunk-YB6FI2G3.js} +1 -1
- package/dist/chunk-YB6FI2G3.js.map +1 -0
- package/dist/{chunk-XNPAVMPB.js → chunk-YG7DCXRD.js} +5 -5
- package/dist/components/case-studies/index.cjs +14 -14
- package/dist/components/case-studies/index.js +8 -8
- package/dist/components/chat/embeddable-chat.d.ts +10 -19
- package/dist/components/chat/embeddable-chat.d.ts.map +1 -1
- package/dist/components/chat/hooks/index.d.ts +1 -0
- package/dist/components/chat/hooks/index.d.ts.map +1 -1
- package/dist/components/chat/hooks/use-chat-history-hydration.d.ts +13 -3
- package/dist/components/chat/hooks/use-chat-history-hydration.d.ts.map +1 -1
- package/dist/components/chat/hooks/use-managed-dialog-list.d.ts +53 -0
- package/dist/components/chat/hooks/use-managed-dialog-list.d.ts.map +1 -0
- package/dist/components/chat/hooks/use-nats-chat-adapter.d.ts +2 -16
- package/dist/components/chat/hooks/use-nats-chat-adapter.d.ts.map +1 -1
- package/dist/components/chat/hooks/use-sse-chat-adapter.d.ts.map +1 -1
- package/dist/components/chat/hooks/use-unified-chat.d.ts.map +1 -1
- package/dist/components/chat/index.cjs +9 -5
- package/dist/components/chat/index.cjs.map +1 -1
- package/dist/components/chat/index.js +8 -4
- package/dist/components/chat/types/unified-chat-state.types.d.ts +72 -6
- package/dist/components/chat/types/unified-chat-state.types.d.ts.map +1 -1
- package/dist/components/chat/utils/chat-conversations-api.d.ts +29 -0
- package/dist/components/chat/utils/chat-conversations-api.d.ts.map +1 -0
- package/dist/components/chat/utils/index.d.ts +1 -0
- package/dist/components/chat/utils/index.d.ts.map +1 -1
- package/dist/components/contact/index.cjs +9 -9
- package/dist/components/contact/index.js +8 -8
- package/dist/components/docs/index.cjs +12 -12
- package/dist/components/docs/index.js +11 -11
- package/dist/components/embeds/index.cjs +9 -9
- package/dist/components/embeds/index.js +8 -8
- package/dist/components/faq/index.cjs +10 -10
- package/dist/components/faq/index.js +9 -9
- package/dist/components/features/index.cjs +8 -8
- package/dist/components/features/index.js +7 -7
- package/dist/components/help-center-pages/index.cjs +31 -31
- package/dist/components/help-center-pages/index.js +22 -22
- package/dist/components/index.cjs +70 -66
- package/dist/components/index.cjs.map +1 -1
- package/dist/components/index.js +26 -22
- package/dist/components/index.js.map +1 -1
- package/dist/components/meeting-scheduler/index.cjs +49 -49
- package/dist/components/meeting-scheduler/index.js +9 -9
- package/dist/components/navigation/index.cjs +11 -11
- package/dist/components/navigation/index.js +10 -10
- package/dist/components/onboarding-guides/index.cjs +12 -12
- package/dist/components/onboarding-guides/index.js +11 -11
- package/dist/components/related-content/index.cjs +7 -7
- package/dist/components/related-content/index.js +6 -6
- package/dist/components/tickets/index.cjs +13 -13
- package/dist/components/tickets/index.js +12 -12
- package/dist/components/ui/index.cjs +12 -8
- package/dist/components/ui/index.cjs.map +1 -1
- package/dist/components/ui/index.js +11 -7
- package/dist/contexts/chat-runtime-context.d.ts +12 -0
- package/dist/contexts/chat-runtime-context.d.ts.map +1 -1
- package/dist/contexts/index.cjs +2 -2
- package/dist/contexts/index.js +1 -1
- package/dist/hooks/index.cjs +5 -5
- package/dist/hooks/index.js +4 -4
- package/dist/index.cjs +16 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +15 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/chat-protocol/index.ts +1 -0
- package/src/chat-protocol/nats-decoder.ts +1 -5
- package/src/chat-protocol/wire-narrow.ts +22 -0
- package/src/components/chat/.embeddable-chat.md +4 -2
- package/src/components/chat/embeddable-chat.tsx +136 -84
- package/src/components/chat/hooks/.index.md +1 -1
- package/src/components/chat/hooks/.use-managed-dialog-list.md +31 -0
- package/src/components/chat/hooks/.use-nats-chat-adapter.md +3 -1
- package/src/components/chat/hooks/.use-sse-chat-adapter.md +8 -1
- package/src/components/chat/hooks/.use-unified-chat.md +2 -2
- package/src/components/chat/hooks/__tests__/managed-dialog-list.test.ts +280 -0
- package/src/components/chat/hooks/__tests__/nats-adapter-managed-dialogs.test.ts +173 -0
- package/src/components/chat/hooks/__tests__/sse-managed-dialogs.test.ts +310 -0
- package/src/components/chat/hooks/index.ts +2 -0
- package/src/components/chat/hooks/use-chat-history-hydration.ts +67 -24
- package/src/components/chat/hooks/use-managed-dialog-list.ts +339 -0
- package/src/components/chat/hooks/use-nats-chat-adapter.ts +65 -150
- package/src/components/chat/hooks/use-sse-chat-adapter.ts +233 -59
- package/src/components/chat/hooks/use-unified-chat.ts +5 -0
- package/src/components/chat/types/.unified-chat-state.types.md +13 -1
- package/src/components/chat/types/unified-chat-state.types.ts +79 -6
- package/src/components/chat/utils/.chat-conversations-api.md +16 -0
- package/src/components/chat/utils/.index.md +1 -1
- package/src/components/chat/utils/__tests__/chat-conversations-api-golden.test.ts +105 -0
- package/src/components/chat/utils/chat-conversations-api.ts +83 -0
- package/src/components/chat/utils/index.ts +7 -0
- package/src/contexts/.chat-runtime-context.md +3 -1
- package/src/contexts/chat-runtime-context.tsx +12 -0
- package/dist/chunk-RDTOMWDN.cjs.map +0 -1
- package/dist/chunk-RYXIRVDC.js.map +0 -1
- package/dist/chunk-VNSRNVPD.js.map +0 -1
- package/dist/chunk-YBPFIXV4.cjs.map +0 -1
- /package/dist/{chunk-VIRTMRS4.js.map → chunk-4PBUEYAE.js.map} +0 -0
- /package/dist/{chunk-TZPVRWPU.js.map → chunk-4TG5BWPE.js.map} +0 -0
- /package/dist/{chunk-PTK3CINU.js.map → chunk-6JF65LRQ.js.map} +0 -0
- /package/dist/{chunk-BK6CCQG6.js.map → chunk-AUCJ6I3R.js.map} +0 -0
- /package/dist/{chunk-EVMHJB6X.js.map → chunk-BLUL2TE3.js.map} +0 -0
- /package/dist/{chunk-GGQZBSFN.js.map → chunk-BVQEU5JB.js.map} +0 -0
- /package/dist/{chunk-SE3PVN64.js.map → chunk-DZ44C6KB.js.map} +0 -0
- /package/dist/{chunk-WZJOILPU.js.map → chunk-F2KBCLUG.js.map} +0 -0
- /package/dist/{chunk-MYBXCWEI.js.map → chunk-FKBM6U43.js.map} +0 -0
- /package/dist/{chunk-75YW6ET4.js.map → chunk-FNK4RZ25.js.map} +0 -0
- /package/dist/{chunk-WPN545FW.js.map → chunk-ILJTXIEI.js.map} +0 -0
- /package/dist/{chunk-LRQCKSZC.js.map → chunk-IW746HJ7.js.map} +0 -0
- /package/dist/{chunk-PX4IPM7Q.js.map → chunk-J62LLUDC.js.map} +0 -0
- /package/dist/{chunk-GHYFVT52.js.map → chunk-JZF6EUMO.js.map} +0 -0
- /package/dist/{chunk-NIAMPMKV.js.map → chunk-LJ4UG2SW.js.map} +0 -0
- /package/dist/{chunk-WDWCQD75.js.map → chunk-MWQSHXYK.js.map} +0 -0
- /package/dist/{chunk-HLPAVYK7.js.map → chunk-RSTEDWAT.js.map} +0 -0
- /package/dist/{chunk-UAAXUFK6.js.map → chunk-RU3IKVY2.js.map} +0 -0
- /package/dist/{chunk-EZM5DNII.js.map → chunk-S6WBBSII.js.map} +0 -0
- /package/dist/{chunk-2JNCZDJR.js.map → chunk-TSCIVH7T.js.map} +0 -0
- /package/dist/{chunk-R4UV366K.js.map → chunk-UYLZAW6Y.js.map} +0 -0
- /package/dist/{chunk-KHOZ52NR.js.map → chunk-XSMBLU44.js.map} +0 -0
- /package/dist/{chunk-XNPAVMPB.js.map → chunk-YG7DCXRD.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
|
|
86
|
-
// Plain module-scope constants so the adapter's return identity stays
|
|
87
|
-
//
|
|
88
|
-
//
|
|
89
|
-
|
|
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
|
-
/*
|
|
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
|
-
/*
|
|
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
|
-
|
|
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):
|
|
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
|
-
|
|
444
|
-
|
|
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
|
-
[
|
|
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
|
|
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
|
-
...(
|
|
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
|
-
[
|
|
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,34 @@ 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
|
-
|
|
572
|
-
conversationStorage.clear();
|
|
718
|
+
commitConversationId(null);
|
|
573
719
|
hydrationSendCountRef.current = 0;
|
|
574
720
|
hydratedKeyRef.current = null;
|
|
575
|
-
}, [mutate,
|
|
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
|
+
const dialogCapabilities = useMemo<ChatDialogCapabilities | undefined>(
|
|
733
|
+
() =>
|
|
734
|
+
conversationsApi
|
|
735
|
+
? {
|
|
736
|
+
canRename: true,
|
|
737
|
+
canArchive: true,
|
|
738
|
+
fetchArchivedDialogs,
|
|
739
|
+
unarchiveDialog,
|
|
740
|
+
searchQuery: dialogSearch,
|
|
741
|
+
onSearchChange: setDialogSearch,
|
|
742
|
+
}
|
|
743
|
+
: undefined,
|
|
744
|
+
[conversationsApi, fetchArchivedDialogs, unarchiveDialog, dialogSearch],
|
|
745
|
+
);
|
|
576
746
|
|
|
577
747
|
// ─── Public message mapping (sendIdx fan-out lookup) ──────────────────────
|
|
578
748
|
// Index sources/scrollAnchor by USER-SEND count (`sendIdx`), not by
|
|
@@ -721,26 +891,30 @@ export function useSseChatAdapter(
|
|
|
721
891
|
/** Cross-call usage breakdown (Haiku rewriter/classifier/summarizer
|
|
722
892
|
* token counts). null until the trailing usage frame lands. */
|
|
723
893
|
currentUsageBreakdown: latestMeta?.breakdown ?? null,
|
|
724
|
-
// ─── Dialog management
|
|
725
|
-
//
|
|
726
|
-
// (`
|
|
727
|
-
//
|
|
728
|
-
//
|
|
729
|
-
//
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
894
|
+
// ─── Dialog management ───────────────────────────────────────────────
|
|
895
|
+
// With `chatConversationsUrl` the server transcript store IS the dialog
|
|
896
|
+
// list (shared `useManagedDialogList`); selecting a row re-hydrates through
|
|
897
|
+
// the history route. WITHOUT it the same hook is inert by construction —
|
|
898
|
+
// no `fetchDialogs`, so an empty list, false flags and memoized no-op
|
|
899
|
+
// mutations — which is why only the four genuinely mode-dependent fields
|
|
900
|
+
// are branched here.
|
|
901
|
+
dialogs,
|
|
902
|
+
isDialogsLoading,
|
|
903
|
+
dialogsError,
|
|
904
|
+
reloadDialogs,
|
|
905
|
+
hasMoreDialogs,
|
|
906
|
+
loadMoreDialogs,
|
|
907
|
+
renameDialog,
|
|
908
|
+
archiveDialog,
|
|
909
|
+
// New chat = `clearMessages` (the server mints on the next send); there is
|
|
910
|
+
// no create call. Delete is not offered — archive replaces it.
|
|
733
911
|
startNewDialog: noopStartNewDialog,
|
|
734
912
|
deleteDialog: noopDeleteDialog,
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
reloadDialogs: noopReloadDialogs,
|
|
741
|
-
isMessagesLoading: false,
|
|
742
|
-
hasMoreDialogs: false,
|
|
743
|
-
loadMoreDialogs: noopAsync,
|
|
913
|
+
activeDialogId: conversationsApi ? conversationId : null,
|
|
914
|
+
selectDialog: conversationsApi ? selectDialog : noopSelectDialog,
|
|
915
|
+
isMessagesLoading: conversationsApi ? isHydratingHistory : false,
|
|
916
|
+
dialogsManaged: !!conversationsApi,
|
|
917
|
+
dialogCapabilities,
|
|
744
918
|
hasMoreMessages: false,
|
|
745
919
|
loadMoreMessages: noopAsync,
|
|
746
920
|
approveRequest: noopApproveRequest,
|
|
@@ -220,6 +220,11 @@ export function useUnifiedChat(options: UseUnifiedChatOptions): UnifiedChatState
|
|
|
220
220
|
setDialogScope,
|
|
221
221
|
hasMoreMessages: activeState.hasMoreMessages,
|
|
222
222
|
loadMoreMessages,
|
|
223
|
+
// Adapter-owned dialog list flag + capabilities (SSE with a
|
|
224
|
+
// conversations endpoint, NATS managed mode). Forwarded verbatim —
|
|
225
|
+
// `EmbeddableChat` gates the history UI on them.
|
|
226
|
+
dialogsManaged: activeState.dialogsManaged,
|
|
227
|
+
dialogCapabilities: activeState.dialogCapabilities,
|
|
223
228
|
// Approvals
|
|
224
229
|
approveRequest,
|
|
225
230
|
rejectRequest,
|
|
@@ -1,6 +1,18 @@
|
|
|
1
|
-
<!-- source-hash:
|
|
1
|
+
<!-- source-hash: ccc4ed7293c6218bca77c53f754ea8c0 -->
|
|
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` additions: **`dialogsManaged?: boolean`** — true when the active adapter owns a server-side dialog list (NATS managed mode, or the SSE/Guide adapter with `ChatRuntime.endpoints.chatConversationsUrl`); `EmbeddableChat` gates its history UI on this rather than on the mode, so Guide mode gets the same "Current Chats" rail as Mingo. **`dialogCapabilities?: ChatDialogCapabilities`** — read in preference to the legacy per-mode derivations, so the ⋯ menu never advertises an unwired action.
|
|
15
|
+
|
|
4
16
|
## Key Components
|
|
5
17
|
|
|
6
18
|
| Export | Kind | Description |
|
|
@@ -24,6 +24,48 @@ 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
|
+
|
|
27
69
|
// ─── Per-dialog token usage (Mingo backend telemetry) ────────────────────────
|
|
28
70
|
|
|
29
71
|
/**
|
|
@@ -357,17 +399,28 @@ export interface UnifiedChatState {
|
|
|
357
399
|
* adapter doesn't support creation, resolves to `null`. */
|
|
358
400
|
startNewDialog: () => Promise<string | null>;
|
|
359
401
|
|
|
360
|
-
/** Delete a dialog from history. No-op when the adapter doesn't
|
|
361
|
-
* expose `deleteDialog
|
|
362
|
-
*
|
|
402
|
+
/** Delete a dialog from history. No-op (resolves) when the adapter doesn't
|
|
403
|
+
* expose `deleteDialog`.
|
|
404
|
+
*
|
|
405
|
+
* REJECTS when the backend call fails — the row is kept and the error is
|
|
406
|
+
* re-thrown so a confirmation modal can stay open for a retry instead of
|
|
407
|
+
* closing over a write that never landed. Callers must `await`/`.catch()`;
|
|
408
|
+
* a bare `void state.deleteDialog(id)` produces an unhandled rejection. */
|
|
363
409
|
deleteDialog: (id: string) => Promise<void>;
|
|
364
410
|
|
|
365
411
|
/** Rename a dialog. Optimistically updates the title in the local list.
|
|
366
|
-
* No-op when the adapter doesn't expose a rename callback.
|
|
412
|
+
* No-op (resolves) when the adapter doesn't expose a rename callback.
|
|
413
|
+
*
|
|
414
|
+
* ALWAYS RESOLVES — unlike `deleteDialog` / `archiveDialog`. A failure rolls
|
|
415
|
+
* the optimistic title back and is logged, never re-thrown, because
|
|
416
|
+
* `useChatDialogManager` fires rename as `void renameDialog(...)` and closes
|
|
417
|
+
* its modal immediately; rejecting here would only produce an unhandled
|
|
418
|
+
* rejection. The rollback is the user-visible signal. */
|
|
367
419
|
renameDialog: (id: string, title: string) => Promise<void>;
|
|
368
420
|
|
|
369
|
-
/** Archive a dialog (removes it from the active list). No-op when
|
|
370
|
-
* adapter doesn't expose an archive callback.
|
|
421
|
+
/** Archive a dialog (removes it from the active list). No-op (resolves) when
|
|
422
|
+
* the adapter doesn't expose an archive callback.
|
|
423
|
+
* REJECTS on failure, keeping the row — see `deleteDialog`. */
|
|
371
424
|
archiveDialog: (id: string) => Promise<void>;
|
|
372
425
|
|
|
373
426
|
/** True while the dialog list is being fetched for the first time. */
|
|
@@ -405,6 +458,26 @@ export interface UnifiedChatState {
|
|
|
405
458
|
/** Fetch the next page of historical messages for the active dialog. */
|
|
406
459
|
loadMoreMessages: () => Promise<void>;
|
|
407
460
|
|
|
461
|
+
/**
|
|
462
|
+
* True when the active adapter OWNS a server-side dialog list (NATS
|
|
463
|
+
* managed-dialog mode, or the SSE/Guide adapter with
|
|
464
|
+
* `ChatRuntime.endpoints.chatConversationsUrl` set). `EmbeddableChat` gates
|
|
465
|
+
* the history list / archive / rename affordances on this flag — transport-
|
|
466
|
+
* agnostic, so Guide mode gets the same "Current Chats" UI as Mingo mode.
|
|
467
|
+
* Undefined/false = the single-thread panel (bare transports, host-injected
|
|
468
|
+
* `mingoState`, which drives the UI through the Mingo mode check instead).
|
|
469
|
+
*/
|
|
470
|
+
dialogsManaged?: boolean;
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* Dialog-management capabilities the active adapter can honour. Only
|
|
474
|
+
* meaningful when `dialogsManaged` is true; `EmbeddableChat` reads it in
|
|
475
|
+
* preference to the legacy per-mode derivations so the row ⋯ menu, the
|
|
476
|
+
* archive page and the header search never advertise an action the
|
|
477
|
+
* transport hasn't wired.
|
|
478
|
+
*/
|
|
479
|
+
dialogCapabilities?: ChatDialogCapabilities;
|
|
480
|
+
|
|
408
481
|
// ─── Approval mutations (Mingo agent tool-call workflow) ──────────────────
|
|
409
482
|
|
|
410
483
|
/** 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)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<!-- source-hash:
|
|
1
|
+
<!-- source-hash: 9d22c40887dffb49c99bc7d0d13ffb7c -->
|
|
2
2
|
Barrel export module that consolidates and re-exports all message processing, chat navigation, UI styling, and content utility functions for chat interfaces.
|
|
3
3
|
|
|
4
4
|
## Key Components
|