@flamingo-stack/openframe-frontend-core 0.0.597 → 0.0.598-2039.5702.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/{chunk-PT54TJWD.js → chunk-26MKONC3.js} +5 -5
- package/dist/{chunk-NK6COZ3P.cjs → chunk-2TWJF4AB.cjs} +22 -22
- package/dist/{chunk-NK6COZ3P.cjs.map → chunk-2TWJF4AB.cjs.map} +1 -1
- package/dist/{chunk-E74GL4E3.cjs → chunk-3GLZDKWZ.cjs} +8 -8
- package/dist/{chunk-E74GL4E3.cjs.map → chunk-3GLZDKWZ.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-DNQP4VPB.js → chunk-3XHNV6W7.js} +12 -12
- package/dist/{chunk-TVK7PQON.js → chunk-442V6CPU.js} +6 -6
- package/dist/{chunk-BZ4UEHNJ.js → chunk-5IMAIYID.js} +9 -9
- package/dist/{chunk-VQ6INRQ4.cjs → chunk-5VQKQIOG.cjs} +105 -105
- package/dist/{chunk-VQ6INRQ4.cjs.map → chunk-5VQKQIOG.cjs.map} +1 -1
- package/dist/{chunk-6QZNDPMV.cjs → chunk-7WTEFZP7.cjs} +9 -9
- package/dist/{chunk-6QZNDPMV.cjs.map → chunk-7WTEFZP7.cjs.map} +1 -1
- package/dist/{chunk-B4BZRBKC.js → chunk-7YMVB7GE.js} +4 -4
- package/dist/{chunk-BOILDHSY.js → chunk-AC2TI6UT.js} +12 -12
- package/dist/{chunk-YBPFIXV4.cjs → chunk-B6ZJV7L4.cjs} +746 -448
- package/dist/{chunk-YBPFIXV4.cjs.map → chunk-B6ZJV7L4.cjs.map} +1 -1
- package/dist/{chunk-RYZKWZBG.cjs → chunk-B72CD6YE.cjs} +15 -15
- package/dist/{chunk-RYZKWZBG.cjs.map → chunk-B72CD6YE.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-H64ZHSYR.cjs → chunk-CCWI3622.cjs} +4 -4
- package/dist/{chunk-H64ZHSYR.cjs.map → chunk-CCWI3622.cjs.map} +1 -1
- package/dist/{chunk-ELG2QNW5.js → chunk-D7X33EAT.js} +7 -7
- package/dist/{chunk-L3L2ATFK.cjs → chunk-E2K2LYSM.cjs} +85 -85
- package/dist/{chunk-L3L2ATFK.cjs.map → chunk-E2K2LYSM.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-FKOYQPMK.js → chunk-GQLYYZF4.js} +5 -5
- package/dist/{chunk-LRQCKSZC.js → chunk-IW746HJ7.js} +2 -2
- package/dist/{chunk-GKZUTZT3.cjs → chunk-JI2R4UW5.cjs} +15 -15
- package/dist/{chunk-GKZUTZT3.cjs.map → chunk-JI2R4UW5.cjs.map} +1 -1
- 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-2JOIC34G.cjs → chunk-KJMXCDYI.cjs} +37 -37
- package/dist/{chunk-2JOIC34G.cjs.map → chunk-KJMXCDYI.cjs.map} +1 -1
- package/dist/{chunk-IRXLB6GV.js → chunk-KV24I5MD.js} +5 -5
- package/dist/{chunk-Z4QFA4BF.cjs → chunk-M7U3MT2Q.cjs} +14 -14
- package/dist/{chunk-Z4QFA4BF.cjs.map → chunk-M7U3MT2Q.cjs.map} +1 -1
- package/dist/{chunk-R2YJKREE.js → chunk-NJCVIERS.js} +4 -4
- package/dist/{chunk-VXEHG53O.js → chunk-OIUXJUMH.js} +6 -6
- 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-CPJP7GKL.cjs → chunk-R6LFBCGC.cjs} +3 -3
- package/dist/{chunk-CPJP7GKL.cjs.map → chunk-R6LFBCGC.cjs.map} +1 -1
- package/dist/{chunk-FHWL7QFL.js → chunk-RTCKC6RH.js} +5 -5
- package/dist/{chunk-UAAXUFK6.js → chunk-RU3IKVY2.js} +3 -3
- package/dist/{chunk-EZM5DNII.js → chunk-S6WBBSII.js} +3 -3
- package/dist/{chunk-WWGSYT7R.js → chunk-SYFSVIGH.js} +2 -2
- package/dist/{chunk-R2MOCGZ7.cjs → chunk-SZRP4264.cjs} +34 -34
- package/dist/{chunk-R2MOCGZ7.cjs.map → chunk-SZRP4264.cjs.map} +1 -1
- package/dist/{chunk-2JNCZDJR.js → chunk-TSCIVH7T.js} +2 -2
- package/dist/{chunk-JJFYMYBJ.cjs → chunk-TYENRLNN.cjs} +39 -39
- package/dist/{chunk-JJFYMYBJ.cjs.map → chunk-TYENRLNN.cjs.map} +1 -1
- package/dist/{chunk-EGQ345IA.js → chunk-UHWDSVZI.js} +4 -4
- 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-BZEWPW5A.cjs → chunk-VIBREYUK.cjs} +3 -3
- package/dist/{chunk-BZEWPW5A.cjs.map → chunk-VIBREYUK.cjs.map} +1 -1
- package/dist/{chunk-E27AKT4A.cjs → chunk-WRZV3HGH.cjs} +9 -9
- package/dist/{chunk-E27AKT4A.cjs.map → chunk-WRZV3HGH.cjs.map} +1 -1
- package/dist/{chunk-PIQRGLTF.cjs → chunk-WU53IOY6.cjs} +25 -25
- package/dist/{chunk-PIQRGLTF.cjs.map → chunk-WU53IOY6.cjs.map} +1 -1
- package/dist/{chunk-VNSRNVPD.js → chunk-XAJZIDFH.js} +673 -375
- package/dist/chunk-XAJZIDFH.js.map +1 -0
- package/dist/{chunk-UIVLSMEZ.cjs → chunk-XRVFQQ7W.cjs} +242 -242
- package/dist/{chunk-UIVLSMEZ.cjs.map → chunk-XRVFQQ7W.cjs.map} +1 -1
- package/dist/{chunk-RYXIRVDC.js → chunk-YB6FI2G3.js} +1 -1
- package/dist/chunk-YB6FI2G3.js.map +1 -0
- package/dist/{chunk-V6KX4KO3.js → chunk-YPJB4LJD.js} +3 -3
- package/dist/components/case-studies/index.cjs +14 -14
- package/dist/components/case-studies/index.js +8 -8
- 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 +5 -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 +49 -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 +55 -0
- 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/components/chat/.embeddable-chat.md +2 -1
- package/src/components/chat/embeddable-chat.tsx +69 -37
- package/src/components/chat/hooks/.use-managed-dialog-list.md +28 -0
- package/src/components/chat/hooks/.use-nats-chat-adapter.md +2 -0
- package/src/components/chat/hooks/.use-sse-chat-adapter.md +7 -0
- package/src/components/chat/hooks/.use-unified-chat.md +1 -1
- package/src/components/chat/hooks/__tests__/managed-dialog-list.test.ts +92 -0
- package/src/components/chat/hooks/__tests__/nats-adapter-managed-dialogs.test.ts +167 -0
- package/src/components/chat/hooks/__tests__/sse-managed-dialogs.test.ts +256 -0
- package/src/components/chat/hooks/index.ts +2 -0
- package/src/components/chat/hooks/use-chat-history-hydration.ts +8 -7
- package/src/components/chat/hooks/use-managed-dialog-list.ts +263 -0
- package/src/components/chat/hooks/use-nats-chat-adapter.ts +65 -150
- package/src/components/chat/hooks/use-sse-chat-adapter.ts +213 -39
- package/src/components/chat/hooks/use-unified-chat.ts +5 -0
- package/src/components/chat/types/unified-chat-state.types.ts +62 -0
- package/src/components/chat/utils/.chat-conversations-api.md +16 -0
- package/src/components/chat/utils/__tests__/chat-conversations-api-golden.test.ts +90 -0
- package/src/components/chat/utils/chat-conversations-api.ts +92 -0
- package/src/components/chat/utils/index.ts +7 -0
- package/src/contexts/.chat-runtime-context.md +2 -0
- 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-PT54TJWD.js.map → chunk-26MKONC3.js.map} +0 -0
- /package/dist/{chunk-DNQP4VPB.js.map → chunk-3XHNV6W7.js.map} +0 -0
- /package/dist/{chunk-TVK7PQON.js.map → chunk-442V6CPU.js.map} +0 -0
- /package/dist/{chunk-BZ4UEHNJ.js.map → chunk-5IMAIYID.js.map} +0 -0
- /package/dist/{chunk-B4BZRBKC.js.map → chunk-7YMVB7GE.js.map} +0 -0
- /package/dist/{chunk-BOILDHSY.js.map → chunk-AC2TI6UT.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-ELG2QNW5.js.map → chunk-D7X33EAT.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-FKOYQPMK.js.map → chunk-GQLYYZF4.js.map} +0 -0
- /package/dist/{chunk-LRQCKSZC.js.map → chunk-IW746HJ7.js.map} +0 -0
- /package/dist/{chunk-IRXLB6GV.js.map → chunk-KV24I5MD.js.map} +0 -0
- /package/dist/{chunk-R2YJKREE.js.map → chunk-NJCVIERS.js.map} +0 -0
- /package/dist/{chunk-VXEHG53O.js.map → chunk-OIUXJUMH.js.map} +0 -0
- /package/dist/{chunk-FHWL7QFL.js.map → chunk-RTCKC6RH.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-WWGSYT7R.js.map → chunk-SYFSVIGH.js.map} +0 -0
- /package/dist/{chunk-2JNCZDJR.js.map → chunk-TSCIVH7T.js.map} +0 -0
- /package/dist/{chunk-EGQ345IA.js.map → chunk-UHWDSVZI.js.map} +0 -0
- /package/dist/{chunk-V6KX4KO3.js.map → chunk-YPJB4LJD.js.map} +0 -0
|
@@ -170,7 +170,7 @@ import {
|
|
|
170
170
|
safeHref,
|
|
171
171
|
sortBitesByCreatedAtDesc,
|
|
172
172
|
useCoverImageFallback
|
|
173
|
-
} from "./chunk-
|
|
173
|
+
} from "./chunk-RU3IKVY2.js";
|
|
174
174
|
import {
|
|
175
175
|
next_image_default
|
|
176
176
|
} from "./chunk-MDKCTSDS.js";
|
|
@@ -183,14 +183,14 @@ import {
|
|
|
183
183
|
getPlatformDisplayName,
|
|
184
184
|
useAuthedAssetSrc,
|
|
185
185
|
useAuthedImageSrc
|
|
186
|
-
} from "./chunk-
|
|
186
|
+
} from "./chunk-FKBM6U43.js";
|
|
187
187
|
import {
|
|
188
188
|
OpenFrameLogo
|
|
189
189
|
} from "./chunk-OTX6XNSA.js";
|
|
190
190
|
import {
|
|
191
191
|
useChatRuntime,
|
|
192
192
|
useRequiredChatRuntime
|
|
193
|
-
} from "./chunk-
|
|
193
|
+
} from "./chunk-YB6FI2G3.js";
|
|
194
194
|
import {
|
|
195
195
|
COLLISION_PADDING_PX,
|
|
196
196
|
CollisionBoundaryContext,
|
|
@@ -17764,7 +17764,7 @@ function useChat({
|
|
|
17764
17764
|
}
|
|
17765
17765
|
|
|
17766
17766
|
// src/components/chat/hooks/use-sse-chat-adapter.ts
|
|
17767
|
-
import { useCallback as
|
|
17767
|
+
import { useCallback as useCallback21, useMemo as useMemo26, useRef as useRef29, useState as useState41 } from "react";
|
|
17768
17768
|
|
|
17769
17769
|
// src/chat-protocol/confirm-tool.ts
|
|
17770
17770
|
function buildConfirmToolBody(request) {
|
|
@@ -20251,6 +20251,60 @@ function pruneStaleChatConversationStorage(source) {
|
|
|
20251
20251
|
}
|
|
20252
20252
|
}
|
|
20253
20253
|
|
|
20254
|
+
// src/components/chat/utils/chat-conversations-api.ts
|
|
20255
|
+
function isRecord(value) {
|
|
20256
|
+
return typeof value === "object" && value !== null;
|
|
20257
|
+
}
|
|
20258
|
+
function unwrapEnvelope(payload) {
|
|
20259
|
+
return isRecord(payload) && "data" in payload ? payload.data : payload;
|
|
20260
|
+
}
|
|
20261
|
+
function toDialogItem(row) {
|
|
20262
|
+
if (!isRecord(row)) return null;
|
|
20263
|
+
const id = typeof row.id === "string" ? row.id : "";
|
|
20264
|
+
if (!id) return null;
|
|
20265
|
+
const title = typeof row.title === "string" && row.title.length > 0 ? row.title : "Untitled chat";
|
|
20266
|
+
const ts = typeof row.timestamp === "string" ? new Date(row.timestamp) : void 0;
|
|
20267
|
+
return {
|
|
20268
|
+
id,
|
|
20269
|
+
title,
|
|
20270
|
+
...ts && !Number.isNaN(ts.getTime()) ? { timestamp: ts } : {},
|
|
20271
|
+
...typeof row.lastMessage === "string" ? { lastMessage: row.lastMessage } : {}
|
|
20272
|
+
};
|
|
20273
|
+
}
|
|
20274
|
+
async function failWith(response, fallback) {
|
|
20275
|
+
const message = await readServerErrorMessage(response);
|
|
20276
|
+
throw new Error(message ?? `${fallback}: ${response.status}`);
|
|
20277
|
+
}
|
|
20278
|
+
function createChatConversationsApi(baseUrl) {
|
|
20279
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
20280
|
+
const patch = async (id, body, what) => {
|
|
20281
|
+
const response = await embedAuthedFetch(`${base}/${encodeURIComponent(id)}`, {
|
|
20282
|
+
method: "PATCH",
|
|
20283
|
+
body: JSON.stringify(body)
|
|
20284
|
+
});
|
|
20285
|
+
if (!response.ok) await failWith(response, `${what} failed`);
|
|
20286
|
+
};
|
|
20287
|
+
return {
|
|
20288
|
+
async fetchDialogs({ status, cursor, limit, search }) {
|
|
20289
|
+
const qs = new URLSearchParams();
|
|
20290
|
+
qs.set("status", status);
|
|
20291
|
+
if (limit !== void 0) qs.set("limit", String(limit));
|
|
20292
|
+
if (cursor) qs.set("cursor", cursor);
|
|
20293
|
+
if (search) qs.set("search", search);
|
|
20294
|
+
const response = await embedAuthedFetch(`${base}?${qs.toString()}`, { method: "GET" });
|
|
20295
|
+
if (!response.ok) await failWith(response, "Conversation list failed");
|
|
20296
|
+
const body = unwrapEnvelope(await response.json());
|
|
20297
|
+
const rawDialogs = isRecord(body) && Array.isArray(body.dialogs) ? body.dialogs : [];
|
|
20298
|
+
const dialogs = rawDialogs.map(toDialogItem).filter((d) => d !== null);
|
|
20299
|
+
const nextCursor = isRecord(body) && typeof body.nextCursor === "string" ? body.nextCursor : null;
|
|
20300
|
+
return { dialogs, nextCursor };
|
|
20301
|
+
},
|
|
20302
|
+
renameDialog: (id, title) => patch(id, { title }, "Rename"),
|
|
20303
|
+
archiveDialog: (id) => patch(id, { archived: true }, "Archive"),
|
|
20304
|
+
unarchiveDialog: (id) => patch(id, { archived: false }, "Restore")
|
|
20305
|
+
};
|
|
20306
|
+
}
|
|
20307
|
+
|
|
20254
20308
|
// src/components/chat/utils/slash-dispatch-utils.ts
|
|
20255
20309
|
var WIRE_TABLE_ID_REGEX = /^[a-z][a-z0-9-]*$/;
|
|
20256
20310
|
var WIRE_ID_REGEX = /^[A-Za-z0-9._:/-]+$/;
|
|
@@ -20333,14 +20387,14 @@ function buildAutoContinuationDirective(toolName, opts = {}) {
|
|
|
20333
20387
|
}
|
|
20334
20388
|
|
|
20335
20389
|
// src/components/chat/hooks/use-chat-history-hydration.ts
|
|
20336
|
-
function
|
|
20390
|
+
function isRecord2(value) {
|
|
20337
20391
|
return typeof value === "object" && value !== null;
|
|
20338
20392
|
}
|
|
20339
20393
|
function useChatHistoryHydration({
|
|
20340
20394
|
active,
|
|
20341
20395
|
source,
|
|
20342
20396
|
historyUrl,
|
|
20343
|
-
|
|
20397
|
+
conversationId,
|
|
20344
20398
|
sendCountRef,
|
|
20345
20399
|
hydrateMessages,
|
|
20346
20400
|
bumpMetaTick
|
|
@@ -20349,7 +20403,6 @@ function useChatHistoryHydration({
|
|
|
20349
20403
|
const hydratedKeyRef = useRef27(null);
|
|
20350
20404
|
useEffect33(() => {
|
|
20351
20405
|
if (!active) return void 0;
|
|
20352
|
-
const conversationId = conversationIdRef.current;
|
|
20353
20406
|
if (!conversationId) return void 0;
|
|
20354
20407
|
const key = `${source}:${conversationId}`;
|
|
20355
20408
|
if (hydratedKeyRef.current === key) return void 0;
|
|
@@ -20363,10 +20416,10 @@ function useChatHistoryHydration({
|
|
|
20363
20416
|
});
|
|
20364
20417
|
if (!res.ok) return;
|
|
20365
20418
|
const payload = await res.json().catch(() => null);
|
|
20366
|
-
const envelope =
|
|
20419
|
+
const envelope = isRecord2(payload) ? payload.data : void 0;
|
|
20367
20420
|
const body = envelope ?? payload;
|
|
20368
|
-
const rawRows =
|
|
20369
|
-
const rows = Array.isArray(rawRows) ? rawRows.filter(
|
|
20421
|
+
const rawRows = isRecord2(body) ? body.messages : void 0;
|
|
20422
|
+
const rows = Array.isArray(rawRows) ? rawRows.filter(isRecord2) : [];
|
|
20370
20423
|
if (cancelled || rows.length === 0) return;
|
|
20371
20424
|
const hydrated = [];
|
|
20372
20425
|
const sourcesSeed = /* @__PURE__ */ new Map();
|
|
@@ -20402,10 +20455,168 @@ function useChatHistoryHydration({
|
|
|
20402
20455
|
return () => {
|
|
20403
20456
|
cancelled = true;
|
|
20404
20457
|
};
|
|
20405
|
-
}, [active, source, historyUrl, hydrateMessages, bumpMetaTick,
|
|
20458
|
+
}, [active, source, historyUrl, conversationId, hydrateMessages, bumpMetaTick, sendCountRef]);
|
|
20406
20459
|
return { isHydratingHistory, hydratedKeyRef };
|
|
20407
20460
|
}
|
|
20408
20461
|
|
|
20462
|
+
// src/components/chat/hooks/use-managed-dialog-list.ts
|
|
20463
|
+
import { useCallback as useCallback20, useEffect as useEffect34, useMemo as useMemo25, useRef as useRef28, useState as useState40 } from "react";
|
|
20464
|
+
function useManagedDialogList({
|
|
20465
|
+
active,
|
|
20466
|
+
fetchDialogs,
|
|
20467
|
+
renameDialog: renameDialogCallback,
|
|
20468
|
+
archiveDialog: archiveDialogCallback,
|
|
20469
|
+
deleteDialog: deleteDialogCallback,
|
|
20470
|
+
pageSize,
|
|
20471
|
+
search,
|
|
20472
|
+
onDialogRemoved,
|
|
20473
|
+
logTag
|
|
20474
|
+
}) {
|
|
20475
|
+
const [dialogs, setDialogs] = useState40([]);
|
|
20476
|
+
const [dialogsNextCursor, setDialogsNextCursor] = useState40(null);
|
|
20477
|
+
const [isDialogsLoading, setIsDialogsLoading] = useState40(false);
|
|
20478
|
+
const [dialogsError, setDialogsError] = useState40(false);
|
|
20479
|
+
const dialogsRef = useRef28(dialogs);
|
|
20480
|
+
useEffect34(() => {
|
|
20481
|
+
dialogsRef.current = dialogs;
|
|
20482
|
+
});
|
|
20483
|
+
const onDialogRemovedRef = useRef28(onDialogRemoved);
|
|
20484
|
+
useEffect34(() => {
|
|
20485
|
+
onDialogRemovedRef.current = onDialogRemoved;
|
|
20486
|
+
});
|
|
20487
|
+
const initialDialogsLoadedRef = useRef28(false);
|
|
20488
|
+
const loadDialogsPage = useCallback20(
|
|
20489
|
+
async (cursor) => {
|
|
20490
|
+
if (!fetchDialogs) return;
|
|
20491
|
+
setIsDialogsLoading(true);
|
|
20492
|
+
if (cursor === void 0) setDialogsError(false);
|
|
20493
|
+
try {
|
|
20494
|
+
const result = await fetchDialogs({
|
|
20495
|
+
cursor,
|
|
20496
|
+
limit: pageSize,
|
|
20497
|
+
// Only hosts that run a search ever see the key.
|
|
20498
|
+
...search !== void 0 ? { search } : {}
|
|
20499
|
+
});
|
|
20500
|
+
setDialogsNextCursor(result.nextCursor);
|
|
20501
|
+
if (cursor === void 0) {
|
|
20502
|
+
setDialogs(result.dialogs);
|
|
20503
|
+
} else {
|
|
20504
|
+
setDialogs((prev) => [...prev, ...result.dialogs]);
|
|
20505
|
+
}
|
|
20506
|
+
} catch (err) {
|
|
20507
|
+
console.error(`${logTag} fetchDialogs failed:`, err);
|
|
20508
|
+
if (cursor === void 0) {
|
|
20509
|
+
setDialogsError(true);
|
|
20510
|
+
initialDialogsLoadedRef.current = false;
|
|
20511
|
+
}
|
|
20512
|
+
} finally {
|
|
20513
|
+
setIsDialogsLoading(false);
|
|
20514
|
+
}
|
|
20515
|
+
},
|
|
20516
|
+
[fetchDialogs, pageSize, search, logTag]
|
|
20517
|
+
);
|
|
20518
|
+
const reloadDialogs = useCallback20(() => {
|
|
20519
|
+
void loadDialogsPage();
|
|
20520
|
+
}, [loadDialogsPage]);
|
|
20521
|
+
const loadedSearchRef = useRef28(void 0);
|
|
20522
|
+
useEffect34(() => {
|
|
20523
|
+
if (!fetchDialogs) return;
|
|
20524
|
+
if (!active) return;
|
|
20525
|
+
if (initialDialogsLoadedRef.current && loadedSearchRef.current === search) return;
|
|
20526
|
+
initialDialogsLoadedRef.current = true;
|
|
20527
|
+
loadedSearchRef.current = search;
|
|
20528
|
+
void loadDialogsPage();
|
|
20529
|
+
}, [active, fetchDialogs, search, loadDialogsPage]);
|
|
20530
|
+
const removeLocal = useCallback20((id) => {
|
|
20531
|
+
setDialogs((prev) => prev.filter((d) => d.id !== id));
|
|
20532
|
+
}, []);
|
|
20533
|
+
const deleteDialog = useCallback20(
|
|
20534
|
+
async (id) => {
|
|
20535
|
+
if (!deleteDialogCallback) return;
|
|
20536
|
+
try {
|
|
20537
|
+
await deleteDialogCallback(id);
|
|
20538
|
+
removeLocal(id);
|
|
20539
|
+
onDialogRemovedRef.current?.(id, "deleted");
|
|
20540
|
+
} catch (err) {
|
|
20541
|
+
console.error(`${logTag} deleteDialog failed:`, err);
|
|
20542
|
+
}
|
|
20543
|
+
},
|
|
20544
|
+
[deleteDialogCallback, removeLocal, logTag]
|
|
20545
|
+
);
|
|
20546
|
+
const renameDialog = useCallback20(
|
|
20547
|
+
async (id, title) => {
|
|
20548
|
+
if (!renameDialogCallback) return;
|
|
20549
|
+
const previous = dialogsRef.current.find((d) => d.id === id)?.title;
|
|
20550
|
+
setDialogs((prev) => prev.map((d) => d.id === id ? { ...d, title } : d));
|
|
20551
|
+
try {
|
|
20552
|
+
await renameDialogCallback(id, title);
|
|
20553
|
+
} catch (err) {
|
|
20554
|
+
console.error(`${logTag} renameDialog failed:`, err);
|
|
20555
|
+
if (previous !== void 0) {
|
|
20556
|
+
setDialogs((prev) => prev.map((d) => d.id === id ? { ...d, title: previous } : d));
|
|
20557
|
+
}
|
|
20558
|
+
}
|
|
20559
|
+
},
|
|
20560
|
+
[renameDialogCallback, logTag]
|
|
20561
|
+
);
|
|
20562
|
+
const archiveDialog = useCallback20(
|
|
20563
|
+
async (id) => {
|
|
20564
|
+
if (!archiveDialogCallback) return;
|
|
20565
|
+
try {
|
|
20566
|
+
await archiveDialogCallback(id);
|
|
20567
|
+
removeLocal(id);
|
|
20568
|
+
onDialogRemovedRef.current?.(id, "archived");
|
|
20569
|
+
} catch (err) {
|
|
20570
|
+
console.error(`${logTag} archiveDialog failed:`, err);
|
|
20571
|
+
}
|
|
20572
|
+
},
|
|
20573
|
+
[archiveDialogCallback, removeLocal, logTag]
|
|
20574
|
+
);
|
|
20575
|
+
const loadMoreDialogs = useCallback20(async () => {
|
|
20576
|
+
if (!dialogsNextCursor) return;
|
|
20577
|
+
await loadDialogsPage(dialogsNextCursor);
|
|
20578
|
+
}, [dialogsNextCursor, loadDialogsPage]);
|
|
20579
|
+
const upsertDialogTop = useCallback20((item) => {
|
|
20580
|
+
setDialogs((prev) => [item, ...prev.filter((d) => d.id !== item.id)]);
|
|
20581
|
+
}, []);
|
|
20582
|
+
const patchDialog = useCallback20((id, patch) => {
|
|
20583
|
+
setDialogs((prev) => prev.map((d) => d.id === id ? { ...d, ...patch } : d));
|
|
20584
|
+
}, []);
|
|
20585
|
+
const hasMoreDialogs = dialogsNextCursor != null;
|
|
20586
|
+
return useMemo25(
|
|
20587
|
+
() => ({
|
|
20588
|
+
dialogs,
|
|
20589
|
+
dialogsNextCursor,
|
|
20590
|
+
isDialogsLoading,
|
|
20591
|
+
dialogsError,
|
|
20592
|
+
hasMoreDialogs,
|
|
20593
|
+
loadDialogsPage,
|
|
20594
|
+
reloadDialogs,
|
|
20595
|
+
loadMoreDialogs,
|
|
20596
|
+
renameDialog,
|
|
20597
|
+
archiveDialog,
|
|
20598
|
+
deleteDialog,
|
|
20599
|
+
upsertDialogTop,
|
|
20600
|
+
patchDialog
|
|
20601
|
+
}),
|
|
20602
|
+
[
|
|
20603
|
+
dialogs,
|
|
20604
|
+
dialogsNextCursor,
|
|
20605
|
+
isDialogsLoading,
|
|
20606
|
+
dialogsError,
|
|
20607
|
+
hasMoreDialogs,
|
|
20608
|
+
loadDialogsPage,
|
|
20609
|
+
reloadDialogs,
|
|
20610
|
+
loadMoreDialogs,
|
|
20611
|
+
renameDialog,
|
|
20612
|
+
archiveDialog,
|
|
20613
|
+
deleteDialog,
|
|
20614
|
+
upsertDialogTop,
|
|
20615
|
+
patchDialog
|
|
20616
|
+
]
|
|
20617
|
+
);
|
|
20618
|
+
}
|
|
20619
|
+
|
|
20409
20620
|
// src/components/chat/hooks/use-sse-chat-adapter.ts
|
|
20410
20621
|
var SSE_EMPTY_DIALOGS = [];
|
|
20411
20622
|
var noopSelectDialog = (_id) => {
|
|
@@ -20446,10 +20657,10 @@ function useSseChatAdapter(options, runtimeOptions = {}) {
|
|
|
20446
20657
|
const runtime = useRequiredChatRuntime();
|
|
20447
20658
|
const source = runtime.source || DEFAULT_CHAT_SOURCE;
|
|
20448
20659
|
const tableIdForDocumentType = options?.tableIdForDocumentType ?? defaultTableIdForDocumentType;
|
|
20449
|
-
const sendMessageRef =
|
|
20660
|
+
const sendMessageRef = useRef29(
|
|
20450
20661
|
() => Promise.resolve(true)
|
|
20451
20662
|
);
|
|
20452
|
-
const cardResolve =
|
|
20663
|
+
const cardResolve = useCallback21(
|
|
20453
20664
|
(action) => (reqId) => {
|
|
20454
20665
|
if (!reqId) return void 0;
|
|
20455
20666
|
return sendMessageRef.current("", {
|
|
@@ -20459,36 +20670,45 @@ function useSseChatAdapter(options, runtimeOptions = {}) {
|
|
|
20459
20670
|
},
|
|
20460
20671
|
[]
|
|
20461
20672
|
);
|
|
20462
|
-
const cardApprove =
|
|
20463
|
-
const cardReject =
|
|
20464
|
-
const createReducerOptions =
|
|
20673
|
+
const cardApprove = useMemo26(() => cardResolve("approve"), [cardResolve]);
|
|
20674
|
+
const cardReject = useMemo26(() => cardResolve("reject"), [cardResolve]);
|
|
20675
|
+
const createReducerOptions = useCallback21(
|
|
20465
20676
|
() => ({
|
|
20466
20677
|
transport: "sse",
|
|
20467
20678
|
callbacks: { onApprove: cardApprove, onReject: cardReject }
|
|
20468
20679
|
}),
|
|
20469
20680
|
[cardApprove, cardReject]
|
|
20470
20681
|
);
|
|
20471
|
-
const storeRef =
|
|
20682
|
+
const storeRef = useRef29(null);
|
|
20472
20683
|
if (storeRef.current === null) storeRef.current = createChatDialogStore();
|
|
20473
20684
|
const { state, applyEvent, flushDeltas, mutate } = useChatStreamReducer({
|
|
20474
20685
|
store: storeRef.current,
|
|
20475
20686
|
dialogId: source,
|
|
20476
20687
|
createReducerOptions
|
|
20477
20688
|
});
|
|
20478
|
-
const
|
|
20479
|
-
const
|
|
20480
|
-
const
|
|
20481
|
-
const restoredConversationRef = useRef28(false);
|
|
20689
|
+
const conversationStorage = useMemo26(() => createChatConversationStorage(source), [source]);
|
|
20690
|
+
const conversationIdRef = useRef29(null);
|
|
20691
|
+
const restoredConversationRef = useRef29(false);
|
|
20482
20692
|
if (!restoredConversationRef.current) {
|
|
20483
20693
|
restoredConversationRef.current = true;
|
|
20484
20694
|
pruneStaleChatConversationStorage(source);
|
|
20485
20695
|
conversationIdRef.current = conversationStorage.load()?.conversationId ?? null;
|
|
20486
20696
|
}
|
|
20697
|
+
const [conversationId, setConversationId] = useState41(() => conversationIdRef.current);
|
|
20698
|
+
const commitConversationId = useCallback21(
|
|
20699
|
+
(id) => {
|
|
20700
|
+
conversationIdRef.current = id;
|
|
20701
|
+
setConversationId(id);
|
|
20702
|
+
if (id) conversationStorage.save({ conversationId: id });
|
|
20703
|
+
else conversationStorage.clear();
|
|
20704
|
+
},
|
|
20705
|
+
[conversationStorage]
|
|
20706
|
+
);
|
|
20487
20707
|
const commandsUrl = runtime.endpoints.commandsUrl;
|
|
20488
20708
|
const { commands: slashCommands } = useSlashCommandRegistry(commandsUrl, {
|
|
20489
20709
|
enabled: active
|
|
20490
20710
|
});
|
|
20491
|
-
const cmdIdByTableId =
|
|
20711
|
+
const cmdIdByTableId = useMemo26(() => {
|
|
20492
20712
|
const buckets = /* @__PURE__ */ new Map();
|
|
20493
20713
|
for (const cmd of slashCommands) {
|
|
20494
20714
|
if (!cmd.primarySourceId) continue;
|
|
@@ -20509,8 +20729,8 @@ function useSseChatAdapter(options, runtimeOptions = {}) {
|
|
|
20509
20729
|
return map;
|
|
20510
20730
|
}, [slashCommands]);
|
|
20511
20731
|
const historyUrl = runtime.endpoints.chatHistoryUrl ?? `${runtime.endpoints.chatStreamUrl.replace(/\/+$/, "")}/history`;
|
|
20512
|
-
const hydrationSendCountRef =
|
|
20513
|
-
const hydrateMessages =
|
|
20732
|
+
const hydrationSendCountRef = useRef29(0);
|
|
20733
|
+
const hydrateMessages = useCallback21(
|
|
20514
20734
|
(history, sourcesSeed) => {
|
|
20515
20735
|
mutate((r) => {
|
|
20516
20736
|
const mapped = history.map(historyMessageToReducerMessage);
|
|
@@ -20535,48 +20755,108 @@ function useSseChatAdapter(options, runtimeOptions = {}) {
|
|
|
20535
20755
|
active,
|
|
20536
20756
|
source,
|
|
20537
20757
|
historyUrl,
|
|
20538
|
-
|
|
20758
|
+
conversationId,
|
|
20539
20759
|
sendCountRef: hydrationSendCountRef,
|
|
20540
20760
|
hydrateMessages,
|
|
20541
20761
|
// Meta invalidation is a reducer concern here: `seedSseMaps` (inside
|
|
20542
20762
|
// `hydrateMessages` above) already invalidates the snapshot.
|
|
20543
20763
|
bumpMetaTick: noopBumpMetaTick
|
|
20544
20764
|
});
|
|
20545
|
-
const
|
|
20765
|
+
const abortControllerRef = useRef29(null);
|
|
20766
|
+
const switchConversation = useCallback21(
|
|
20767
|
+
(id) => {
|
|
20768
|
+
abortControllerRef.current?.abort();
|
|
20769
|
+
flushDeltas();
|
|
20770
|
+
mutate((r) => r.reset());
|
|
20771
|
+
hydrationSendCountRef.current = 0;
|
|
20772
|
+
hydratedKeyRef.current = null;
|
|
20773
|
+
commitConversationId(id);
|
|
20774
|
+
},
|
|
20775
|
+
[flushDeltas, mutate, hydratedKeyRef, commitConversationId]
|
|
20776
|
+
);
|
|
20777
|
+
const conversationsUrl = runtime.endpoints.chatConversationsUrl;
|
|
20778
|
+
const conversationsApi = useMemo26(
|
|
20779
|
+
() => conversationsUrl ? createChatConversationsApi(conversationsUrl) : null,
|
|
20780
|
+
[conversationsUrl]
|
|
20781
|
+
);
|
|
20782
|
+
const [dialogSearch, setDialogSearch] = useState41("");
|
|
20783
|
+
const fetchActiveDialogs = useMemo26(
|
|
20784
|
+
() => conversationsApi ? (params) => conversationsApi.fetchDialogs({ ...params, status: "active" }) : void 0,
|
|
20785
|
+
[conversationsApi]
|
|
20786
|
+
);
|
|
20787
|
+
const fetchArchivedDialogs = useMemo26(
|
|
20788
|
+
() => conversationsApi ? (params) => conversationsApi.fetchDialogs({ ...params, status: "archived" }) : void 0,
|
|
20789
|
+
[conversationsApi]
|
|
20790
|
+
);
|
|
20791
|
+
const {
|
|
20792
|
+
dialogs,
|
|
20793
|
+
isDialogsLoading,
|
|
20794
|
+
dialogsError,
|
|
20795
|
+
hasMoreDialogs,
|
|
20796
|
+
reloadDialogs,
|
|
20797
|
+
loadMoreDialogs,
|
|
20798
|
+
renameDialog,
|
|
20799
|
+
archiveDialog,
|
|
20800
|
+
upsertDialogTop,
|
|
20801
|
+
patchDialog
|
|
20802
|
+
} = useManagedDialogList({
|
|
20803
|
+
active,
|
|
20804
|
+
fetchDialogs: fetchActiveDialogs,
|
|
20805
|
+
renameDialog: conversationsApi?.renameDialog,
|
|
20806
|
+
archiveDialog: conversationsApi?.archiveDialog,
|
|
20807
|
+
pageSize: 20,
|
|
20808
|
+
search: conversationsApi ? dialogSearch : void 0,
|
|
20809
|
+
logTag: "[useSseChatAdapter]",
|
|
20810
|
+
// Archiving the OPEN conversation drops back to the draft state (the
|
|
20811
|
+
// manager also clears the thread; both paths are idempotent).
|
|
20812
|
+
onDialogRemoved: (id) => {
|
|
20813
|
+
if (conversationIdRef.current === id) switchConversation(null);
|
|
20814
|
+
}
|
|
20815
|
+
});
|
|
20816
|
+
const unarchiveDialog = useMemo26(
|
|
20817
|
+
() => conversationsApi ? async (id) => {
|
|
20818
|
+
await conversationsApi.unarchiveDialog(id);
|
|
20819
|
+
reloadDialogs();
|
|
20820
|
+
} : void 0,
|
|
20821
|
+
[conversationsApi, reloadDialogs]
|
|
20822
|
+
);
|
|
20823
|
+
const endpointsRef = useRef29(runtime.endpoints);
|
|
20546
20824
|
endpointsRef.current = runtime.endpoints;
|
|
20547
|
-
const captureConversationId =
|
|
20825
|
+
const captureConversationId = useCallback21(
|
|
20548
20826
|
(event) => {
|
|
20549
|
-
if (event.type !== "metadata") return;
|
|
20827
|
+
if (event.type !== "metadata") return false;
|
|
20550
20828
|
const id = event.conversationId;
|
|
20551
|
-
if (typeof id !== "string" || !id) return;
|
|
20552
|
-
if (conversationIdRef.current === id) return;
|
|
20553
|
-
|
|
20554
|
-
|
|
20829
|
+
if (typeof id !== "string" || !id) return false;
|
|
20830
|
+
if (conversationIdRef.current === id) return false;
|
|
20831
|
+
hydratedKeyRef.current = `${source}:${id}`;
|
|
20832
|
+
commitConversationId(id);
|
|
20833
|
+
return true;
|
|
20555
20834
|
},
|
|
20556
|
-
[
|
|
20835
|
+
[commitConversationId, hydratedKeyRef, source]
|
|
20557
20836
|
);
|
|
20558
|
-
const sendMessage =
|
|
20837
|
+
const sendMessage = useCallback21(
|
|
20559
20838
|
// Resolves `true` on a clean turn, `false` when the request failed
|
|
20560
20839
|
// (surfaced to batch approve-all loops via the card callbacks).
|
|
20561
20840
|
async (text, sendOptions) => {
|
|
20562
20841
|
const { hidden, attachments, commandOverride, approvalAction } = sendOptions ?? {};
|
|
20563
|
-
const
|
|
20842
|
+
const echoedConversationId = conversationIdRef.current;
|
|
20564
20843
|
const targetPath = approvalAction ? endpointsRef.current.approvalToolUrl : endpointsRef.current.chatStreamUrl;
|
|
20565
20844
|
const requestBody = approvalAction ? (
|
|
20566
20845
|
// Shared with every other transport that resolves a hub proposal —
|
|
20567
20846
|
// the body shape is the hub's, not this adapter's. `conversationId`
|
|
20568
20847
|
// is always present here: an approval can only happen inside an
|
|
20569
20848
|
// established conversation (the proposal turn captured the id).
|
|
20570
|
-
buildConfirmToolBody({ ...approvalAction, conversationId })
|
|
20849
|
+
buildConfirmToolBody({ ...approvalAction, conversationId: echoedConversationId })
|
|
20571
20850
|
) : {
|
|
20572
20851
|
messages: [{ role: "user", content: text }],
|
|
20573
20852
|
...commandOverride ? { commandOverride } : {},
|
|
20574
20853
|
...attachments && attachments.length > 0 ? { pendingAttachments: attachments } : {},
|
|
20575
|
-
...
|
|
20854
|
+
...echoedConversationId ? { conversationId: echoedConversationId } : {}
|
|
20576
20855
|
};
|
|
20577
20856
|
mutate((r) => r.beginSseSend({ text, hidden, userName: "You", assistantName: "Mingo AI" }));
|
|
20578
20857
|
const ctrl = new AbortController();
|
|
20579
20858
|
abortControllerRef.current = ctrl;
|
|
20859
|
+
let mintedThisTurn = false;
|
|
20580
20860
|
try {
|
|
20581
20861
|
const response = await embedAuthedFetch(targetPath, {
|
|
20582
20862
|
method: "POST",
|
|
@@ -20597,7 +20877,16 @@ function useSseChatAdapter(options, runtimeOptions = {}) {
|
|
|
20597
20877
|
if (done) break;
|
|
20598
20878
|
if (ctrl.signal.aborted) break;
|
|
20599
20879
|
for (const event of frameDecoder.push(value)) {
|
|
20600
|
-
captureConversationId(event)
|
|
20880
|
+
if (captureConversationId(event)) {
|
|
20881
|
+
mintedThisTurn = true;
|
|
20882
|
+
if (conversationsApi && !hidden) {
|
|
20883
|
+
upsertDialogTop({
|
|
20884
|
+
id: conversationIdRef.current ?? "",
|
|
20885
|
+
title: text.slice(0, 80),
|
|
20886
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
20887
|
+
});
|
|
20888
|
+
}
|
|
20889
|
+
}
|
|
20601
20890
|
applyEvent(event);
|
|
20602
20891
|
}
|
|
20603
20892
|
}
|
|
@@ -20624,24 +20913,54 @@ function useSseChatAdapter(options, runtimeOptions = {}) {
|
|
|
20624
20913
|
}
|
|
20625
20914
|
flushDeltas();
|
|
20626
20915
|
mutate((r) => r.endSseTurn());
|
|
20916
|
+
if (conversationsApi && !ctrl.signal.aborted) {
|
|
20917
|
+
if (mintedThisTurn) reloadDialogs();
|
|
20918
|
+
else if (conversationIdRef.current) patchDialog(conversationIdRef.current, { timestamp: /* @__PURE__ */ new Date() });
|
|
20919
|
+
}
|
|
20627
20920
|
}
|
|
20628
20921
|
},
|
|
20629
|
-
[
|
|
20922
|
+
[
|
|
20923
|
+
mutate,
|
|
20924
|
+
applyEvent,
|
|
20925
|
+
flushDeltas,
|
|
20926
|
+
captureConversationId,
|
|
20927
|
+
conversationsApi,
|
|
20928
|
+
upsertDialogTop,
|
|
20929
|
+
reloadDialogs,
|
|
20930
|
+
patchDialog
|
|
20931
|
+
]
|
|
20630
20932
|
);
|
|
20631
20933
|
sendMessageRef.current = sendMessage;
|
|
20632
|
-
const stopMessage =
|
|
20934
|
+
const stopMessage = useCallback21(() => {
|
|
20633
20935
|
abortControllerRef.current?.abort();
|
|
20634
20936
|
flushDeltas();
|
|
20635
20937
|
mutate((r) => r.setPhase("idle"));
|
|
20636
20938
|
}, [mutate, flushDeltas]);
|
|
20637
|
-
const clearMessages =
|
|
20939
|
+
const clearMessages = useCallback21(() => {
|
|
20638
20940
|
mutate((r) => r.reset());
|
|
20639
|
-
|
|
20640
|
-
conversationStorage.clear();
|
|
20941
|
+
commitConversationId(null);
|
|
20641
20942
|
hydrationSendCountRef.current = 0;
|
|
20642
20943
|
hydratedKeyRef.current = null;
|
|
20643
|
-
}, [mutate,
|
|
20644
|
-
const
|
|
20944
|
+
}, [mutate, commitConversationId, hydratedKeyRef]);
|
|
20945
|
+
const selectDialog = useCallback21(
|
|
20946
|
+
(id) => {
|
|
20947
|
+
if (id === conversationIdRef.current) return;
|
|
20948
|
+
switchConversation(id);
|
|
20949
|
+
},
|
|
20950
|
+
[switchConversation]
|
|
20951
|
+
);
|
|
20952
|
+
const dialogCapabilities = useMemo26(
|
|
20953
|
+
() => conversationsApi ? {
|
|
20954
|
+
canRename: true,
|
|
20955
|
+
canArchive: true,
|
|
20956
|
+
fetchArchivedDialogs,
|
|
20957
|
+
unarchiveDialog,
|
|
20958
|
+
searchQuery: dialogSearch,
|
|
20959
|
+
onSearchChange: setDialogSearch
|
|
20960
|
+
} : void 0,
|
|
20961
|
+
[conversationsApi, fetchArchivedDialogs, unarchiveDialog, dialogSearch]
|
|
20962
|
+
);
|
|
20963
|
+
const docMessages = useMemo26(() => {
|
|
20645
20964
|
const { meta, sources: sourcesMap } = state.turnMeta;
|
|
20646
20965
|
let sendIdx = -1;
|
|
20647
20966
|
return state.messages.map((m) => {
|
|
@@ -20668,7 +20987,7 @@ function useSseChatAdapter(options, runtimeOptions = {}) {
|
|
|
20668
20987
|
};
|
|
20669
20988
|
});
|
|
20670
20989
|
}, [state.messages, state.turnMeta]);
|
|
20671
|
-
const displayRef =
|
|
20990
|
+
const displayRef = useCallback21(
|
|
20672
20991
|
(reference) => {
|
|
20673
20992
|
const tableId = tableIdForDocumentType(reference.type);
|
|
20674
20993
|
if (!tableId) {
|
|
@@ -20690,7 +21009,7 @@ function useSseChatAdapter(options, runtimeOptions = {}) {
|
|
|
20690
21009
|
},
|
|
20691
21010
|
[sendMessage, source, cmdIdByTableId, tableIdForDocumentType]
|
|
20692
21011
|
);
|
|
20693
|
-
const discussRef =
|
|
21012
|
+
const discussRef = useCallback21(
|
|
20694
21013
|
(reference) => {
|
|
20695
21014
|
const tableId = tableIdForDocumentType(reference.type);
|
|
20696
21015
|
if (!tableId) {
|
|
@@ -20709,7 +21028,7 @@ function useSseChatAdapter(options, runtimeOptions = {}) {
|
|
|
20709
21028
|
},
|
|
20710
21029
|
[sendMessage, tableIdForDocumentType]
|
|
20711
21030
|
);
|
|
20712
|
-
const latestMeta =
|
|
21031
|
+
const latestMeta = useMemo26(() => {
|
|
20713
21032
|
const { meta, sendCount } = state.turnMeta;
|
|
20714
21033
|
return meta.get(sendCount - 1) ?? meta.get(sendCount - 2) ?? null;
|
|
20715
21034
|
}, [state]);
|
|
@@ -20740,26 +21059,46 @@ function useSseChatAdapter(options, runtimeOptions = {}) {
|
|
|
20740
21059
|
/** Cross-call usage breakdown (Haiku rewriter/classifier/summarizer
|
|
20741
21060
|
* token counts). null until the trailing usage frame lands. */
|
|
20742
21061
|
currentUsageBreakdown: latestMeta?.breakdown ?? null,
|
|
20743
|
-
// ─── Dialog management
|
|
20744
|
-
//
|
|
20745
|
-
// (`
|
|
20746
|
-
//
|
|
20747
|
-
//
|
|
20748
|
-
|
|
20749
|
-
|
|
20750
|
-
|
|
20751
|
-
|
|
20752
|
-
|
|
20753
|
-
|
|
20754
|
-
|
|
20755
|
-
|
|
20756
|
-
|
|
20757
|
-
|
|
20758
|
-
|
|
20759
|
-
|
|
20760
|
-
|
|
20761
|
-
|
|
20762
|
-
|
|
21062
|
+
// ─── Dialog management ───────────────────────────────────────────────
|
|
21063
|
+
// With `chatConversationsUrl` the server transcript store IS the dialog
|
|
21064
|
+
// list (shared `useManagedDialogList`); selecting a row re-hydrates
|
|
21065
|
+
// through the history route. Without it (hosts that never set the
|
|
21066
|
+
// endpoint) the single-thread stubs below are returned unchanged.
|
|
21067
|
+
...conversationsApi ? {
|
|
21068
|
+
dialogs,
|
|
21069
|
+
activeDialogId: conversationId,
|
|
21070
|
+
selectDialog,
|
|
21071
|
+
// New chat = `clearMessages` (the server mints on the next send);
|
|
21072
|
+
// there is no create call.
|
|
21073
|
+
startNewDialog: noopStartNewDialog,
|
|
21074
|
+
deleteDialog: noopDeleteDialog,
|
|
21075
|
+
renameDialog,
|
|
21076
|
+
archiveDialog,
|
|
21077
|
+
isDialogsLoading,
|
|
21078
|
+
dialogsError,
|
|
21079
|
+
reloadDialogs,
|
|
21080
|
+
isMessagesLoading: isHydratingHistory,
|
|
21081
|
+
hasMoreDialogs,
|
|
21082
|
+
loadMoreDialogs,
|
|
21083
|
+
dialogsManaged: true,
|
|
21084
|
+
dialogCapabilities
|
|
21085
|
+
} : {
|
|
21086
|
+
dialogs: SSE_EMPTY_DIALOGS,
|
|
21087
|
+
activeDialogId: null,
|
|
21088
|
+
selectDialog: noopSelectDialog,
|
|
21089
|
+
startNewDialog: noopStartNewDialog,
|
|
21090
|
+
deleteDialog: noopDeleteDialog,
|
|
21091
|
+
renameDialog: noopRenameDialog,
|
|
21092
|
+
archiveDialog: noopArchiveDialog,
|
|
21093
|
+
isDialogsLoading: false,
|
|
21094
|
+
// No server-side dialog list — never errors, nothing to retry.
|
|
21095
|
+
dialogsError: false,
|
|
21096
|
+
reloadDialogs: noopReloadDialogs,
|
|
21097
|
+
isMessagesLoading: false,
|
|
21098
|
+
hasMoreDialogs: false,
|
|
21099
|
+
loadMoreDialogs: noopAsync,
|
|
21100
|
+
dialogsManaged: false
|
|
21101
|
+
},
|
|
20763
21102
|
hasMoreMessages: false,
|
|
20764
21103
|
loadMoreMessages: noopAsync,
|
|
20765
21104
|
approveRequest: noopApproveRequest,
|
|
@@ -20770,10 +21109,10 @@ function useSseChatAdapter(options, runtimeOptions = {}) {
|
|
|
20770
21109
|
}
|
|
20771
21110
|
|
|
20772
21111
|
// src/components/chat/hooks/use-nats-chat-adapter.ts
|
|
20773
|
-
import { useCallback as
|
|
21112
|
+
import { useCallback as useCallback22, useEffect as useEffect35, useMemo as useMemo27, useRef as useRef30, useState as useState42 } from "react";
|
|
20774
21113
|
|
|
20775
21114
|
// src/chat-protocol/nats-decoder.ts
|
|
20776
|
-
function
|
|
21115
|
+
function isRecord3(value) {
|
|
20777
21116
|
return typeof value === "object" && value !== null;
|
|
20778
21117
|
}
|
|
20779
21118
|
function str(value) {
|
|
@@ -20788,7 +21127,7 @@ function numOr(value, fallback = 0) {
|
|
|
20788
21127
|
}
|
|
20789
21128
|
function normalizeToolCalls(raw) {
|
|
20790
21129
|
if (!Array.isArray(raw)) return [];
|
|
20791
|
-
return raw.filter(
|
|
21130
|
+
return raw.filter(isRecord3).map((item) => ({
|
|
20792
21131
|
toolExecutionRequestId: String(item.toolExecutionRequestId ?? ""),
|
|
20793
21132
|
toolName: String(item.toolName ?? ""),
|
|
20794
21133
|
toolTitle: typeof item.toolTitle === "string" ? item.toolTitle : void 0,
|
|
@@ -20796,12 +21135,12 @@ function normalizeToolCalls(raw) {
|
|
|
20796
21135
|
toolType: typeof item.toolType === "string" ? item.toolType : void 0,
|
|
20797
21136
|
requiresApproval: item.requiresApproval === true,
|
|
20798
21137
|
approvalType: typeof item.approvalType === "string" ? item.approvalType : null,
|
|
20799
|
-
toolCallArguments:
|
|
21138
|
+
toolCallArguments: isRecord3(item.toolCallArguments) ? item.toolCallArguments : null
|
|
20800
21139
|
}));
|
|
20801
21140
|
}
|
|
20802
21141
|
function normalizeAskOptions(raw) {
|
|
20803
21142
|
if (!Array.isArray(raw)) return [];
|
|
20804
|
-
return raw.filter(
|
|
21143
|
+
return raw.filter(isRecord3).map((item) => ({
|
|
20805
21144
|
label: typeof item.label === "string" ? item.label.trim() : "",
|
|
20806
21145
|
description: typeof item.description === "string" ? item.description : void 0
|
|
20807
21146
|
})).filter((option) => option.label.length > 0);
|
|
@@ -20870,7 +21209,7 @@ function decodeNatsChunk(chunk) {
|
|
|
20870
21209
|
// the EXECUTING segment held. Dropping it here therefore blanks the
|
|
20871
21210
|
// card for the whole lifetime of the run.
|
|
20872
21211
|
toolExplanation: typeof data.toolExplanation === "string" ? data.toolExplanation : void 0,
|
|
20873
|
-
parameters:
|
|
21212
|
+
parameters: isRecord3(data.parameters) ? data.parameters : void 0,
|
|
20874
21213
|
toolExecutionRequestId: typeof data.toolExecutionRequestId === "string" ? data.toolExecutionRequestId : void 0
|
|
20875
21214
|
},
|
|
20876
21215
|
...seq
|
|
@@ -20883,7 +21222,7 @@ function decodeNatsChunk(chunk) {
|
|
|
20883
21222
|
integratedToolType: strOr(data.integratedToolType),
|
|
20884
21223
|
toolFunction: strOr(data.toolFunction),
|
|
20885
21224
|
toolTitle: typeof data.title === "string" ? data.title : void 0,
|
|
20886
|
-
parameters:
|
|
21225
|
+
parameters: isRecord3(data.parameters) ? data.parameters : void 0,
|
|
20887
21226
|
result: str(data.result),
|
|
20888
21227
|
success: typeof data.success === "boolean" ? data.success : void 0,
|
|
20889
21228
|
toolExecutionRequestId: typeof data.toolExecutionRequestId === "string" ? data.toolExecutionRequestId : void 0
|
|
@@ -21748,6 +22087,8 @@ function useNatsChatAdapter(config, options = {}) {
|
|
|
21748
22087
|
deleteDialog: deleteDialogCallback,
|
|
21749
22088
|
renameDialog: renameDialogCallback,
|
|
21750
22089
|
archiveDialog: archiveDialogCallback,
|
|
22090
|
+
fetchArchivedDialogs,
|
|
22091
|
+
unarchiveDialog,
|
|
21751
22092
|
approveRequest: approveRequestCallback,
|
|
21752
22093
|
rejectRequest: rejectRequestCallback,
|
|
21753
22094
|
stopGeneration: stopGenerationCallback,
|
|
@@ -21759,26 +22100,26 @@ function useNatsChatAdapter(config, options = {}) {
|
|
|
21759
22100
|
modelLabel = null
|
|
21760
22101
|
} = config;
|
|
21761
22102
|
const isManagedMode = fetchDialogs !== void 0;
|
|
21762
|
-
const [internalDialogId, setInternalDialogId] =
|
|
22103
|
+
const [internalDialogId, setInternalDialogId] = useState42(null);
|
|
21763
22104
|
const dialogId = isManagedMode ? internalDialogId : controlledDialogId !== void 0 ? controlledDialogId : null;
|
|
21764
|
-
const currentDialogIdRef =
|
|
21765
|
-
|
|
22105
|
+
const currentDialogIdRef = useRef30(dialogId);
|
|
22106
|
+
useEffect35(() => {
|
|
21766
22107
|
currentDialogIdRef.current = dialogId;
|
|
21767
22108
|
});
|
|
21768
|
-
const handleApproveRef =
|
|
22109
|
+
const handleApproveRef = useRef30(async () => {
|
|
21769
22110
|
});
|
|
21770
|
-
const handleRejectRef =
|
|
22111
|
+
const handleRejectRef = useRef30(async () => {
|
|
21771
22112
|
});
|
|
21772
|
-
const accumApprove =
|
|
22113
|
+
const accumApprove = useCallback22((requestId) => {
|
|
21773
22114
|
if (!requestId) return void 0;
|
|
21774
22115
|
return handleApproveRef.current(requestId);
|
|
21775
22116
|
}, []);
|
|
21776
|
-
const accumReject =
|
|
22117
|
+
const accumReject = useCallback22((requestId) => {
|
|
21777
22118
|
if (!requestId) return void 0;
|
|
21778
22119
|
return handleRejectRef.current(requestId);
|
|
21779
22120
|
}, []);
|
|
21780
|
-
const [dialogStore] =
|
|
21781
|
-
const [globalApprovalStatuses] =
|
|
22121
|
+
const [dialogStore] = useState42(() => createChatDialogStore());
|
|
22122
|
+
const [globalApprovalStatuses] = useState42(() => ({}));
|
|
21782
22123
|
const dialogKey = dialogId ?? DRAFT_DIALOG_KEY;
|
|
21783
22124
|
const { state, applyEvent, mutate } = useChatStreamReducer({
|
|
21784
22125
|
store: dialogStore,
|
|
@@ -21791,10 +22132,10 @@ function useNatsChatAdapter(config, options = {}) {
|
|
|
21791
22132
|
callbacks: { onApprove: accumApprove, onReject: accumReject }
|
|
21792
22133
|
})
|
|
21793
22134
|
});
|
|
21794
|
-
|
|
22135
|
+
useEffect35(() => {
|
|
21795
22136
|
Object.assign(globalApprovalStatuses, state.approvalStatuses);
|
|
21796
22137
|
}, [globalApprovalStatuses, state.approvalStatuses]);
|
|
21797
|
-
|
|
22138
|
+
useEffect35(() => {
|
|
21798
22139
|
handleApproveRef.current = async (requestId) => {
|
|
21799
22140
|
if (!approveRequestCallback) return;
|
|
21800
22141
|
const key = dialogKey;
|
|
@@ -21826,22 +22167,44 @@ function useNatsChatAdapter(config, options = {}) {
|
|
|
21826
22167
|
}
|
|
21827
22168
|
};
|
|
21828
22169
|
});
|
|
21829
|
-
const processChunk =
|
|
22170
|
+
const processChunk = useCallback22(
|
|
21830
22171
|
(chunk) => {
|
|
21831
22172
|
const event = decodeNatsChunk(chunk);
|
|
21832
22173
|
if (event) applyEvent(event);
|
|
21833
22174
|
},
|
|
21834
22175
|
[applyEvent]
|
|
21835
22176
|
);
|
|
21836
|
-
const [
|
|
21837
|
-
const
|
|
21838
|
-
|
|
21839
|
-
|
|
21840
|
-
|
|
21841
|
-
|
|
21842
|
-
|
|
21843
|
-
|
|
21844
|
-
|
|
22177
|
+
const [isCreatingDialog, setIsCreatingDialog] = useState42(false);
|
|
22178
|
+
const {
|
|
22179
|
+
dialogs,
|
|
22180
|
+
isDialogsLoading,
|
|
22181
|
+
dialogsError,
|
|
22182
|
+
hasMoreDialogs,
|
|
22183
|
+
reloadDialogs,
|
|
22184
|
+
loadMoreDialogs,
|
|
22185
|
+
renameDialog,
|
|
22186
|
+
archiveDialog,
|
|
22187
|
+
deleteDialog,
|
|
22188
|
+
upsertDialogTop
|
|
22189
|
+
} = useManagedDialogList({
|
|
22190
|
+
active,
|
|
22191
|
+
fetchDialogs,
|
|
22192
|
+
renameDialog: renameDialogCallback,
|
|
22193
|
+
archiveDialog: archiveDialogCallback,
|
|
22194
|
+
deleteDialog: deleteDialogCallback,
|
|
22195
|
+
pageSize: dialogsPageSize,
|
|
22196
|
+
logTag: "[useNatsChatAdapter]",
|
|
22197
|
+
onDialogRemoved: (id, reason) => {
|
|
22198
|
+
if (reason === "deleted") dialogStore.remove(id);
|
|
22199
|
+
if (isManagedMode && internalDialogId === id) {
|
|
22200
|
+
setInternalDialogId(null);
|
|
22201
|
+
}
|
|
22202
|
+
}
|
|
22203
|
+
});
|
|
22204
|
+
const [messagesNextCursor, setMessagesNextCursor] = useState42(null);
|
|
22205
|
+
const [isMessagesLoading, setIsMessagesLoading] = useState42(false);
|
|
22206
|
+
const [connectedForDialog, setConnectedForDialog] = useState42(null);
|
|
22207
|
+
const hasConnectedOnceRef = useRef30(false);
|
|
21845
22208
|
const {
|
|
21846
22209
|
processChunk: catchupProcessChunk,
|
|
21847
22210
|
catchUpChunks,
|
|
@@ -21854,8 +22217,8 @@ function useNatsChatAdapter(config, options = {}) {
|
|
|
21854
22217
|
onChunkReceived: (chunk) => processChunk(chunk),
|
|
21855
22218
|
fetchChunks
|
|
21856
22219
|
});
|
|
21857
|
-
const historyLoadSeqRef =
|
|
21858
|
-
const loadDialogHistory =
|
|
22220
|
+
const historyLoadSeqRef = useRef30(0);
|
|
22221
|
+
const loadDialogHistory = useCallback22(
|
|
21859
22222
|
async (id, cursor) => {
|
|
21860
22223
|
if (!fetchDialogMessages) return;
|
|
21861
22224
|
historyLoadSeqRef.current += 1;
|
|
@@ -21913,8 +22276,8 @@ function useNatsChatAdapter(config, options = {}) {
|
|
|
21913
22276
|
isBufferingActive
|
|
21914
22277
|
]
|
|
21915
22278
|
);
|
|
21916
|
-
const prevDialogIdRef =
|
|
21917
|
-
|
|
22279
|
+
const prevDialogIdRef = useRef30(void 0);
|
|
22280
|
+
useEffect35(() => {
|
|
21918
22281
|
if (prevDialogIdRef.current === dialogId) return;
|
|
21919
22282
|
prevDialogIdRef.current = dialogId;
|
|
21920
22283
|
historyLoadSeqRef.current += 1;
|
|
@@ -21927,7 +22290,7 @@ function useNatsChatAdapter(config, options = {}) {
|
|
|
21927
22290
|
if (!active || !dialogId) return;
|
|
21928
22291
|
void loadDialogHistory(dialogId);
|
|
21929
22292
|
}, [active, dialogId, dialogKey, dialogStore, globalApprovalStatuses, loadDialogHistory]);
|
|
21930
|
-
|
|
22293
|
+
useEffect35(() => {
|
|
21931
22294
|
if (!active || !dialogId) return;
|
|
21932
22295
|
const store = dialogStore;
|
|
21933
22296
|
store.mutate(dialogId, DEFAULT_DIALOG_SIDE, (r) => r.adjustAgentBusySuppression(1));
|
|
@@ -21987,46 +22350,7 @@ function useNatsChatAdapter(config, options = {}) {
|
|
|
21987
22350
|
}
|
|
21988
22351
|
});
|
|
21989
22352
|
const connectionState = !active || !dialogId ? "connected" : connectedForDialog === dialogId ? "connected" : "connecting";
|
|
21990
|
-
const
|
|
21991
|
-
const loadDialogsPage = useCallback21(
|
|
21992
|
-
async (cursor) => {
|
|
21993
|
-
if (!fetchDialogs) return;
|
|
21994
|
-
setIsDialogsLoading(true);
|
|
21995
|
-
if (cursor === void 0) setDialogsError(false);
|
|
21996
|
-
try {
|
|
21997
|
-
const result = await fetchDialogs({
|
|
21998
|
-
cursor,
|
|
21999
|
-
limit: dialogsPageSize
|
|
22000
|
-
});
|
|
22001
|
-
setDialogsNextCursor(result.nextCursor);
|
|
22002
|
-
if (cursor === void 0) {
|
|
22003
|
-
setDialogs(result.dialogs);
|
|
22004
|
-
} else {
|
|
22005
|
-
setDialogs((prev) => [...prev, ...result.dialogs]);
|
|
22006
|
-
}
|
|
22007
|
-
} catch (err) {
|
|
22008
|
-
console.error("[useNatsChatAdapter] fetchDialogs failed:", err);
|
|
22009
|
-
if (cursor === void 0) {
|
|
22010
|
-
setDialogsError(true);
|
|
22011
|
-
initialDialogsLoadedRef.current = false;
|
|
22012
|
-
}
|
|
22013
|
-
} finally {
|
|
22014
|
-
setIsDialogsLoading(false);
|
|
22015
|
-
}
|
|
22016
|
-
},
|
|
22017
|
-
[fetchDialogs, dialogsPageSize]
|
|
22018
|
-
);
|
|
22019
|
-
const reloadDialogs = useCallback21(() => {
|
|
22020
|
-
void loadDialogsPage();
|
|
22021
|
-
}, [loadDialogsPage]);
|
|
22022
|
-
useEffect34(() => {
|
|
22023
|
-
if (!fetchDialogs) return;
|
|
22024
|
-
if (!active) return;
|
|
22025
|
-
if (initialDialogsLoadedRef.current) return;
|
|
22026
|
-
initialDialogsLoadedRef.current = true;
|
|
22027
|
-
void loadDialogsPage();
|
|
22028
|
-
}, [active, fetchDialogs, loadDialogsPage]);
|
|
22029
|
-
const sendMessage = useCallback21(
|
|
22353
|
+
const sendMessage = useCallback22(
|
|
22030
22354
|
async (text, sendOptions) => {
|
|
22031
22355
|
const hidden = sendOptions?.hidden ?? false;
|
|
22032
22356
|
mutate((r) => r.pushOptimisticSend(text, hidden));
|
|
@@ -22034,7 +22358,7 @@ function useNatsChatAdapter(config, options = {}) {
|
|
|
22034
22358
|
},
|
|
22035
22359
|
[mutate, publishUserMessage, dialogId]
|
|
22036
22360
|
);
|
|
22037
|
-
const stopMessage =
|
|
22361
|
+
const stopMessage = useCallback22(() => {
|
|
22038
22362
|
mutate((r) => r.setPhase("idle"));
|
|
22039
22363
|
if (stopGenerationCallback && dialogId) {
|
|
22040
22364
|
void stopGenerationCallback(dialogId).catch((err) => {
|
|
@@ -22042,10 +22366,10 @@ function useNatsChatAdapter(config, options = {}) {
|
|
|
22042
22366
|
});
|
|
22043
22367
|
}
|
|
22044
22368
|
}, [mutate, stopGenerationCallback, dialogId]);
|
|
22045
|
-
const clearMessages =
|
|
22369
|
+
const clearMessages = useCallback22(() => {
|
|
22046
22370
|
mutate((r) => r.clearThread());
|
|
22047
22371
|
}, [mutate]);
|
|
22048
|
-
const selectDialog =
|
|
22372
|
+
const selectDialog = useCallback22(
|
|
22049
22373
|
(id) => {
|
|
22050
22374
|
if (!isManagedMode) {
|
|
22051
22375
|
return;
|
|
@@ -22054,20 +22378,17 @@ function useNatsChatAdapter(config, options = {}) {
|
|
|
22054
22378
|
},
|
|
22055
22379
|
[isManagedMode]
|
|
22056
22380
|
);
|
|
22057
|
-
const startNewDialog =
|
|
22381
|
+
const startNewDialog = useCallback22(async () => {
|
|
22058
22382
|
if (!createDialogCallback) return null;
|
|
22059
22383
|
if (isCreatingDialog) return null;
|
|
22060
22384
|
try {
|
|
22061
22385
|
setIsCreatingDialog(true);
|
|
22062
22386
|
const result = await createDialogCallback();
|
|
22063
|
-
|
|
22064
|
-
|
|
22065
|
-
|
|
22066
|
-
|
|
22067
|
-
|
|
22068
|
-
},
|
|
22069
|
-
...prev.filter((d) => d.id !== result.dialogId)
|
|
22070
|
-
]);
|
|
22387
|
+
upsertDialogTop({
|
|
22388
|
+
id: result.dialogId,
|
|
22389
|
+
title: "New Chat",
|
|
22390
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
22391
|
+
});
|
|
22071
22392
|
if (isManagedMode) {
|
|
22072
22393
|
setInternalDialogId(result.dialogId);
|
|
22073
22394
|
}
|
|
@@ -22078,76 +22399,18 @@ function useNatsChatAdapter(config, options = {}) {
|
|
|
22078
22399
|
} finally {
|
|
22079
22400
|
setIsCreatingDialog(false);
|
|
22080
22401
|
}
|
|
22081
|
-
}, [createDialogCallback, isCreatingDialog, isManagedMode]);
|
|
22082
|
-
const
|
|
22083
|
-
async (id) => {
|
|
22084
|
-
if (!deleteDialogCallback) return;
|
|
22085
|
-
try {
|
|
22086
|
-
await deleteDialogCallback(id);
|
|
22087
|
-
setDialogs((prev) => prev.filter((d) => d.id !== id));
|
|
22088
|
-
dialogStore.remove(id);
|
|
22089
|
-
if (isManagedMode && internalDialogId === id) {
|
|
22090
|
-
setInternalDialogId(null);
|
|
22091
|
-
}
|
|
22092
|
-
} catch (err) {
|
|
22093
|
-
console.error("[useNatsChatAdapter] deleteDialog failed:", err);
|
|
22094
|
-
}
|
|
22095
|
-
},
|
|
22096
|
-
[deleteDialogCallback, dialogStore, internalDialogId, isManagedMode]
|
|
22097
|
-
);
|
|
22098
|
-
const renameDialog = useCallback21(
|
|
22099
|
-
async (id, title) => {
|
|
22100
|
-
if (!renameDialogCallback) return;
|
|
22101
|
-
let previous;
|
|
22102
|
-
setDialogs(
|
|
22103
|
-
(prev) => prev.map((d) => {
|
|
22104
|
-
if (d.id !== id) return d;
|
|
22105
|
-
previous = d.title;
|
|
22106
|
-
return { ...d, title };
|
|
22107
|
-
})
|
|
22108
|
-
);
|
|
22109
|
-
try {
|
|
22110
|
-
await renameDialogCallback(id, title);
|
|
22111
|
-
} catch (err) {
|
|
22112
|
-
console.error("[useNatsChatAdapter] renameDialog failed:", err);
|
|
22113
|
-
const rollbackTitle = previous;
|
|
22114
|
-
if (rollbackTitle !== void 0) {
|
|
22115
|
-
setDialogs((prev) => prev.map((d) => d.id === id ? { ...d, title: rollbackTitle } : d));
|
|
22116
|
-
}
|
|
22117
|
-
}
|
|
22118
|
-
},
|
|
22119
|
-
[renameDialogCallback]
|
|
22120
|
-
);
|
|
22121
|
-
const archiveDialog = useCallback21(
|
|
22122
|
-
async (id) => {
|
|
22123
|
-
if (!archiveDialogCallback) return;
|
|
22124
|
-
try {
|
|
22125
|
-
await archiveDialogCallback(id);
|
|
22126
|
-
setDialogs((prev) => prev.filter((d) => d.id !== id));
|
|
22127
|
-
if (isManagedMode && internalDialogId === id) {
|
|
22128
|
-
setInternalDialogId(null);
|
|
22129
|
-
}
|
|
22130
|
-
} catch (err) {
|
|
22131
|
-
console.error("[useNatsChatAdapter] archiveDialog failed:", err);
|
|
22132
|
-
}
|
|
22133
|
-
},
|
|
22134
|
-
[archiveDialogCallback, internalDialogId, isManagedMode]
|
|
22135
|
-
);
|
|
22136
|
-
const loadMoreDialogs = useCallback21(async () => {
|
|
22137
|
-
if (!dialogsNextCursor) return;
|
|
22138
|
-
await loadDialogsPage(dialogsNextCursor);
|
|
22139
|
-
}, [dialogsNextCursor, loadDialogsPage]);
|
|
22140
|
-
const loadMoreMessages = useCallback21(async () => {
|
|
22402
|
+
}, [createDialogCallback, isCreatingDialog, isManagedMode, upsertDialogTop]);
|
|
22403
|
+
const loadMoreMessages = useCallback22(async () => {
|
|
22141
22404
|
if (!dialogId || !messagesNextCursor) return;
|
|
22142
22405
|
await loadDialogHistory(dialogId, messagesNextCursor);
|
|
22143
22406
|
}, [dialogId, messagesNextCursor, loadDialogHistory]);
|
|
22144
|
-
const approveRequest =
|
|
22407
|
+
const approveRequest = useCallback22(async (requestId) => {
|
|
22145
22408
|
await handleApproveRef.current(requestId);
|
|
22146
22409
|
}, []);
|
|
22147
|
-
const rejectRequest =
|
|
22410
|
+
const rejectRequest = useCallback22(async (requestId, reason) => {
|
|
22148
22411
|
await handleRejectRef.current(requestId, reason);
|
|
22149
22412
|
}, []);
|
|
22150
|
-
const discussRef =
|
|
22413
|
+
const discussRef = useCallback22(
|
|
22151
22414
|
(reference) => {
|
|
22152
22415
|
const prompt = buildDiscussPrompt(reference, { includeReference: true });
|
|
22153
22416
|
void sendMessage(prompt).catch((err) => {
|
|
@@ -22158,9 +22421,17 @@ function useNatsChatAdapter(config, options = {}) {
|
|
|
22158
22421
|
);
|
|
22159
22422
|
const { messages, streamingPhase, dialogTokenUsage = null, liveModel = null } = state;
|
|
22160
22423
|
const isLoading = streamingPhase !== "idle";
|
|
22161
|
-
const hasMoreDialogs = dialogsNextCursor != null;
|
|
22162
22424
|
const hasMoreMessages = messagesNextCursor != null;
|
|
22163
|
-
|
|
22425
|
+
const dialogCapabilities = useMemo27(
|
|
22426
|
+
() => isManagedMode ? {
|
|
22427
|
+
canRename: !!renameDialogCallback,
|
|
22428
|
+
canArchive: !!archiveDialogCallback,
|
|
22429
|
+
fetchArchivedDialogs,
|
|
22430
|
+
unarchiveDialog
|
|
22431
|
+
} : void 0,
|
|
22432
|
+
[isManagedMode, renameDialogCallback, archiveDialogCallback, fetchArchivedDialogs, unarchiveDialog]
|
|
22433
|
+
);
|
|
22434
|
+
return useMemo27(
|
|
22164
22435
|
() => ({
|
|
22165
22436
|
messages,
|
|
22166
22437
|
isLoading,
|
|
@@ -22197,6 +22468,8 @@ function useNatsChatAdapter(config, options = {}) {
|
|
|
22197
22468
|
loadMoreDialogs,
|
|
22198
22469
|
hasMoreMessages,
|
|
22199
22470
|
loadMoreMessages,
|
|
22471
|
+
dialogsManaged: isManagedMode,
|
|
22472
|
+
dialogCapabilities,
|
|
22200
22473
|
// Approval mutations
|
|
22201
22474
|
approveRequest,
|
|
22202
22475
|
rejectRequest,
|
|
@@ -22229,6 +22502,8 @@ function useNatsChatAdapter(config, options = {}) {
|
|
|
22229
22502
|
loadMoreDialogs,
|
|
22230
22503
|
hasMoreMessages,
|
|
22231
22504
|
loadMoreMessages,
|
|
22505
|
+
isManagedMode,
|
|
22506
|
+
dialogCapabilities,
|
|
22232
22507
|
approveRequest,
|
|
22233
22508
|
rejectRequest,
|
|
22234
22509
|
dialogTokenUsage,
|
|
@@ -22241,7 +22516,7 @@ function useNatsChatAdapter(config, options = {}) {
|
|
|
22241
22516
|
}
|
|
22242
22517
|
|
|
22243
22518
|
// src/components/chat/hooks/use-unified-chat.ts
|
|
22244
|
-
import { useCallback as
|
|
22519
|
+
import { useCallback as useCallback23, useEffect as useEffect36, useMemo as useMemo28, useRef as useRef31, useState as useState43 } from "react";
|
|
22245
22520
|
var EMPTY_SSE_OPTIONS = {};
|
|
22246
22521
|
function createDisabledNatsConfig() {
|
|
22247
22522
|
return {
|
|
@@ -22256,7 +22531,7 @@ function createDisabledNatsConfig() {
|
|
|
22256
22531
|
}
|
|
22257
22532
|
function useUnifiedChat(options) {
|
|
22258
22533
|
const { modes, activeMode, mingoStateOverride } = options;
|
|
22259
|
-
const [disabledNatsConfig] =
|
|
22534
|
+
const [disabledNatsConfig] = useState43(createDisabledNatsConfig);
|
|
22260
22535
|
const sseActive = activeMode === "guide" && modes.guide !== void 0;
|
|
22261
22536
|
const natsActive = activeMode === "mingo" && modes.mingo !== void 0;
|
|
22262
22537
|
const sseState = useSseChatAdapter(modes.guide ?? EMPTY_SSE_OPTIONS, {
|
|
@@ -22264,40 +22539,40 @@ function useUnifiedChat(options) {
|
|
|
22264
22539
|
});
|
|
22265
22540
|
const natsState = useNatsChatAdapter(modes.mingo ?? disabledNatsConfig, { active: natsActive });
|
|
22266
22541
|
const activeState = activeMode === "guide" ? sseState : mingoStateOverride ?? natsState;
|
|
22267
|
-
const activeStateRef =
|
|
22268
|
-
|
|
22542
|
+
const activeStateRef = useRef31(activeState);
|
|
22543
|
+
useEffect36(() => {
|
|
22269
22544
|
activeStateRef.current = activeState;
|
|
22270
22545
|
});
|
|
22271
|
-
const stopMessage =
|
|
22272
|
-
const clearMessages =
|
|
22273
|
-
const sendMessage =
|
|
22546
|
+
const stopMessage = useCallback23(() => activeStateRef.current.stopMessage(), []);
|
|
22547
|
+
const clearMessages = useCallback23(() => activeStateRef.current.clearMessages(), []);
|
|
22548
|
+
const sendMessage = useCallback23(
|
|
22274
22549
|
(text, opts) => activeStateRef.current.sendMessage(text, opts),
|
|
22275
22550
|
[]
|
|
22276
22551
|
);
|
|
22277
|
-
const discussRef =
|
|
22552
|
+
const discussRef = useCallback23(
|
|
22278
22553
|
(ref) => activeStateRef.current.discussRef(ref),
|
|
22279
22554
|
[]
|
|
22280
22555
|
);
|
|
22281
|
-
const displayRefForward =
|
|
22556
|
+
const displayRefForward = useCallback23(
|
|
22282
22557
|
(ref) => activeStateRef.current.displayRef?.(ref),
|
|
22283
22558
|
[]
|
|
22284
22559
|
);
|
|
22285
22560
|
const displayRef = activeState.displayRef ? displayRefForward : void 0;
|
|
22286
|
-
const selectDialog =
|
|
22287
|
-
const startNewDialog =
|
|
22288
|
-
const deleteDialog =
|
|
22289
|
-
const renameDialog =
|
|
22290
|
-
const archiveDialog =
|
|
22291
|
-
const loadMoreDialogs =
|
|
22292
|
-
const setDialogScope =
|
|
22293
|
-
const reloadDialogs =
|
|
22294
|
-
const loadMoreMessages =
|
|
22295
|
-
const approveRequest =
|
|
22296
|
-
const rejectRequest =
|
|
22561
|
+
const selectDialog = useCallback23((id) => activeStateRef.current.selectDialog(id), []);
|
|
22562
|
+
const startNewDialog = useCallback23(() => activeStateRef.current.startNewDialog(), []);
|
|
22563
|
+
const deleteDialog = useCallback23((id) => activeStateRef.current.deleteDialog(id), []);
|
|
22564
|
+
const renameDialog = useCallback23((id, title) => activeStateRef.current.renameDialog(id, title), []);
|
|
22565
|
+
const archiveDialog = useCallback23((id) => activeStateRef.current.archiveDialog(id), []);
|
|
22566
|
+
const loadMoreDialogs = useCallback23(() => activeStateRef.current.loadMoreDialogs(), []);
|
|
22567
|
+
const setDialogScope = useCallback23((scope) => activeStateRef.current.setDialogScope?.(scope), []);
|
|
22568
|
+
const reloadDialogs = useCallback23(() => activeStateRef.current.reloadDialogs(), []);
|
|
22569
|
+
const loadMoreMessages = useCallback23(() => activeStateRef.current.loadMoreMessages(), []);
|
|
22570
|
+
const approveRequest = useCallback23((requestId) => activeStateRef.current.approveRequest(requestId), []);
|
|
22571
|
+
const rejectRequest = useCallback23(
|
|
22297
22572
|
(requestId, reason) => activeStateRef.current.rejectRequest(requestId, reason),
|
|
22298
22573
|
[]
|
|
22299
22574
|
);
|
|
22300
|
-
return
|
|
22575
|
+
return useMemo28(
|
|
22301
22576
|
() => ({
|
|
22302
22577
|
messages: activeState.messages,
|
|
22303
22578
|
isLoading: activeState.isLoading,
|
|
@@ -22334,6 +22609,11 @@ function useUnifiedChat(options) {
|
|
|
22334
22609
|
setDialogScope,
|
|
22335
22610
|
hasMoreMessages: activeState.hasMoreMessages,
|
|
22336
22611
|
loadMoreMessages,
|
|
22612
|
+
// Adapter-owned dialog list flag + capabilities (SSE with a
|
|
22613
|
+
// conversations endpoint, NATS managed mode). Forwarded verbatim —
|
|
22614
|
+
// `EmbeddableChat` gates the history UI on them.
|
|
22615
|
+
dialogsManaged: activeState.dialogsManaged,
|
|
22616
|
+
dialogCapabilities: activeState.dialogCapabilities,
|
|
22337
22617
|
// Approvals
|
|
22338
22618
|
approveRequest,
|
|
22339
22619
|
rejectRequest,
|
|
@@ -22653,7 +22933,7 @@ import { VisuallyHidden } from "@radix-ui/react-visually-hidden";
|
|
|
22653
22933
|
import { usePreventScroll } from "@react-aria/overlays";
|
|
22654
22934
|
import { isIOS } from "@react-aria/utils";
|
|
22655
22935
|
import { MessageSquare as MessageSquare3 } from "lucide-react";
|
|
22656
|
-
import React10, { useCallback as
|
|
22936
|
+
import React10, { useCallback as useCallback27, useEffect as useEffect38, useImperativeHandle as useImperativeHandle4, useMemo as useMemo30, useRef as useRef35, useState as useState47 } from "react";
|
|
22657
22937
|
|
|
22658
22938
|
// src/components/ui/drawer.tsx
|
|
22659
22939
|
import * as DialogPrimitive from "@radix-ui/react-dialog";
|
|
@@ -22661,10 +22941,10 @@ import { cva as cva2 } from "class-variance-authority";
|
|
|
22661
22941
|
import { X } from "lucide-react";
|
|
22662
22942
|
import {
|
|
22663
22943
|
forwardRef as forwardRef26,
|
|
22664
|
-
useCallback as
|
|
22665
|
-
useEffect as
|
|
22666
|
-
useRef as
|
|
22667
|
-
useState as
|
|
22944
|
+
useCallback as useCallback24,
|
|
22945
|
+
useEffect as useEffect37,
|
|
22946
|
+
useRef as useRef32,
|
|
22947
|
+
useState as useState44
|
|
22668
22948
|
} from "react";
|
|
22669
22949
|
import { jsx as jsx95, jsxs as jsxs73 } from "react/jsx-runtime";
|
|
22670
22950
|
var OVERLAY_BACKDROP_CLASS = "bg-ods-overlay";
|
|
@@ -22758,7 +23038,7 @@ function viewportSize(isHorizontal) {
|
|
|
22758
23038
|
return isHorizontal ? window.innerWidth : window.innerHeight;
|
|
22759
23039
|
}
|
|
22760
23040
|
function useResizableSize({ enabled, isHorizontal, minSize, maxSize, defaultSize, storageKey }) {
|
|
22761
|
-
const clampToViewport =
|
|
23041
|
+
const clampToViewport = useCallback24(
|
|
22762
23042
|
(value) => {
|
|
22763
23043
|
const vp = viewportSize(isHorizontal);
|
|
22764
23044
|
const effectiveMax = vp > 0 ? Math.min(maxSize, vp - 80) : maxSize;
|
|
@@ -22766,7 +23046,7 @@ function useResizableSize({ enabled, isHorizontal, minSize, maxSize, defaultSize
|
|
|
22766
23046
|
},
|
|
22767
23047
|
[isHorizontal, minSize, maxSize]
|
|
22768
23048
|
);
|
|
22769
|
-
const readInitial =
|
|
23049
|
+
const readInitial = useCallback24(() => {
|
|
22770
23050
|
if (!enabled) return defaultSize;
|
|
22771
23051
|
if (typeof window === "undefined") return defaultSize;
|
|
22772
23052
|
if (!storageKey) return clampToViewport(defaultSize);
|
|
@@ -22780,16 +23060,16 @@ function useResizableSize({ enabled, isHorizontal, minSize, maxSize, defaultSize
|
|
|
22780
23060
|
return clampToViewport(defaultSize);
|
|
22781
23061
|
}
|
|
22782
23062
|
}, [enabled, storageKey, defaultSize, clampToViewport]);
|
|
22783
|
-
const [size2, setSizeRaw] =
|
|
22784
|
-
const setSize =
|
|
22785
|
-
|
|
23063
|
+
const [size2, setSizeRaw] = useState44(readInitial);
|
|
23064
|
+
const setSize = useCallback24((next) => setSizeRaw(clampToViewport(next)), [clampToViewport]);
|
|
23065
|
+
useEffect37(() => {
|
|
22786
23066
|
if (!enabled || !storageKey || typeof window === "undefined") return;
|
|
22787
23067
|
try {
|
|
22788
23068
|
window.localStorage.setItem(storageKey, String(Math.round(size2)));
|
|
22789
23069
|
} catch {
|
|
22790
23070
|
}
|
|
22791
23071
|
}, [enabled, size2, storageKey]);
|
|
22792
|
-
|
|
23072
|
+
useEffect37(() => {
|
|
22793
23073
|
if (!enabled || typeof window === "undefined") return void 0;
|
|
22794
23074
|
const onResize = () => setSizeRaw((prev) => clampToViewport(prev));
|
|
22795
23075
|
window.addEventListener("resize", onResize);
|
|
@@ -22799,7 +23079,7 @@ function useResizableSize({ enabled, isHorizontal, minSize, maxSize, defaultSize
|
|
|
22799
23079
|
}
|
|
22800
23080
|
function DrawerResizeHandle({ side, size: size2, minSize, maxSize, onSize, ariaLabel }) {
|
|
22801
23081
|
const isHorizontal = HORIZONTAL_SIDES.has(side);
|
|
22802
|
-
const startRef =
|
|
23082
|
+
const startRef = useRef32(null);
|
|
22803
23083
|
const direction = side === "right" || side === "bottom" ? -1 : 1;
|
|
22804
23084
|
const handlePointerDown = (e) => {
|
|
22805
23085
|
if (e.button !== 0 && e.pointerType === "mouse") return;
|
|
@@ -22904,8 +23184,8 @@ var DrawerContent = forwardRef26(
|
|
|
22904
23184
|
const isHorizontal = HORIZONTAL_SIDES.has(resolvedSide);
|
|
22905
23185
|
const initialSize = defaultSize ?? (isHorizontal ? 560 : 480);
|
|
22906
23186
|
const headerHeight = useHeaderHeight();
|
|
22907
|
-
const [isMobile, setIsMobile] =
|
|
22908
|
-
|
|
23187
|
+
const [isMobile, setIsMobile] = useState44(false);
|
|
23188
|
+
useEffect37(() => {
|
|
22909
23189
|
if (typeof window === "undefined") return void 0;
|
|
22910
23190
|
const mq = window.matchMedia(`(max-width: ${mobileBreakpoint - 1}px)`);
|
|
22911
23191
|
const update = () => setIsMobile(mq.matches);
|
|
@@ -22995,7 +23275,7 @@ var DrawerFooter = ({ className, ...props }) => /* @__PURE__ */ jsx95("div", { c
|
|
|
22995
23275
|
DrawerFooter.displayName = "DrawerFooter";
|
|
22996
23276
|
|
|
22997
23277
|
// src/components/ui/hover-dropdown.tsx
|
|
22998
|
-
import { useState as
|
|
23278
|
+
import { useState as useState45, useRef as useRef33, useCallback as useCallback25 } from "react";
|
|
22999
23279
|
import { Fragment as Fragment33, jsx as jsx96, jsxs as jsxs74 } from "react/jsx-runtime";
|
|
23000
23280
|
function DefaultAnchor({ href, className, children }) {
|
|
23001
23281
|
return /* @__PURE__ */ jsx96("a", { href, className, children });
|
|
@@ -23008,10 +23288,10 @@ function HoverDropdown({
|
|
|
23008
23288
|
className,
|
|
23009
23289
|
renderAnchor
|
|
23010
23290
|
}) {
|
|
23011
|
-
const [open, setOpen] =
|
|
23012
|
-
const timeoutRef =
|
|
23013
|
-
const containerRef =
|
|
23014
|
-
const panelRef =
|
|
23291
|
+
const [open, setOpen] = useState45(false);
|
|
23292
|
+
const timeoutRef = useRef33(void 0);
|
|
23293
|
+
const containerRef = useRef33(null);
|
|
23294
|
+
const panelRef = useRef33(null);
|
|
23015
23295
|
useIsomorphicLayoutEffect(() => {
|
|
23016
23296
|
const el = panelRef.current;
|
|
23017
23297
|
const container = containerRef.current;
|
|
@@ -23039,14 +23319,14 @@ function HoverDropdown({
|
|
|
23039
23319
|
}
|
|
23040
23320
|
}
|
|
23041
23321
|
});
|
|
23042
|
-
const show =
|
|
23322
|
+
const show = useCallback25(() => {
|
|
23043
23323
|
clearTimeout(timeoutRef.current);
|
|
23044
23324
|
setOpen(true);
|
|
23045
23325
|
}, []);
|
|
23046
|
-
const hide =
|
|
23326
|
+
const hide = useCallback25(() => {
|
|
23047
23327
|
timeoutRef.current = setTimeout(() => setOpen(false), hideDelay);
|
|
23048
23328
|
}, [hideDelay]);
|
|
23049
|
-
const toggle =
|
|
23329
|
+
const toggle = useCallback25((e) => {
|
|
23050
23330
|
e.stopPropagation();
|
|
23051
23331
|
clearTimeout(timeoutRef.current);
|
|
23052
23332
|
setOpen((prev) => !prev);
|
|
@@ -23112,7 +23392,7 @@ function HoverDropdown({
|
|
|
23112
23392
|
}
|
|
23113
23393
|
|
|
23114
23394
|
// src/components/chat/hooks/use-chat-dialog-manager.ts
|
|
23115
|
-
import { useCallback as
|
|
23395
|
+
import { useCallback as useCallback26, useMemo as useMemo29, useRef as useRef34, useState as useState46 } from "react";
|
|
23116
23396
|
function useChatDialogManager({
|
|
23117
23397
|
dialogs,
|
|
23118
23398
|
activeDialogId,
|
|
@@ -23123,17 +23403,17 @@ function useChatDialogManager({
|
|
|
23123
23403
|
fetchArchivedDialogs,
|
|
23124
23404
|
unarchiveDialog
|
|
23125
23405
|
}) {
|
|
23126
|
-
const [renameTarget, setRenameTarget] =
|
|
23127
|
-
const [archiveTarget, setArchiveTarget] =
|
|
23128
|
-
const handleConfirmRename =
|
|
23406
|
+
const [renameTarget, setRenameTarget] = useState46(null);
|
|
23407
|
+
const [archiveTarget, setArchiveTarget] = useState46(null);
|
|
23408
|
+
const handleConfirmRename = useCallback26(
|
|
23129
23409
|
(name) => {
|
|
23130
23410
|
if (renameTarget) void renameDialog(renameTarget.id, name);
|
|
23131
23411
|
setRenameTarget(null);
|
|
23132
23412
|
},
|
|
23133
23413
|
[renameTarget, renameDialog]
|
|
23134
23414
|
);
|
|
23135
|
-
const [openingDialogId, setOpeningDialogId] =
|
|
23136
|
-
const handleConfirmArchive =
|
|
23415
|
+
const [openingDialogId, setOpeningDialogId] = useState46(null);
|
|
23416
|
+
const handleConfirmArchive = useCallback26(async () => {
|
|
23137
23417
|
if (archiveTarget) {
|
|
23138
23418
|
try {
|
|
23139
23419
|
await archiveDialog(archiveTarget.id);
|
|
@@ -23148,13 +23428,13 @@ function useChatDialogManager({
|
|
|
23148
23428
|
}
|
|
23149
23429
|
setArchiveTarget(null);
|
|
23150
23430
|
}, [archiveTarget, archiveDialog, activeDialogId, clearMessages]);
|
|
23151
|
-
const [archiveOpen, setArchiveOpen] =
|
|
23152
|
-
const [archivedDialogs, setArchivedDialogs] =
|
|
23153
|
-
const [archivedCursor, setArchivedCursor] =
|
|
23154
|
-
const [archivedLoading, setArchivedLoading] =
|
|
23155
|
-
const [archivedPending, setArchivedPending] =
|
|
23156
|
-
const archivedRequestIdRef =
|
|
23157
|
-
const loadArchivedPage =
|
|
23431
|
+
const [archiveOpen, setArchiveOpen] = useState46(false);
|
|
23432
|
+
const [archivedDialogs, setArchivedDialogs] = useState46([]);
|
|
23433
|
+
const [archivedCursor, setArchivedCursor] = useState46(null);
|
|
23434
|
+
const [archivedLoading, setArchivedLoading] = useState46(false);
|
|
23435
|
+
const [archivedPending, setArchivedPending] = useState46(false);
|
|
23436
|
+
const archivedRequestIdRef = useRef34(0);
|
|
23437
|
+
const loadArchivedPage = useCallback26(
|
|
23158
23438
|
async (cursor) => {
|
|
23159
23439
|
if (!fetchArchivedDialogs) return;
|
|
23160
23440
|
const requestId = ++archivedRequestIdRef.current;
|
|
@@ -23187,13 +23467,13 @@ function useChatDialogManager({
|
|
|
23187
23467
|
},
|
|
23188
23468
|
[fetchArchivedDialogs]
|
|
23189
23469
|
);
|
|
23190
|
-
const openArchive =
|
|
23470
|
+
const openArchive = useCallback26(() => {
|
|
23191
23471
|
setArchiveOpen(true);
|
|
23192
23472
|
void loadArchivedPage();
|
|
23193
23473
|
}, [loadArchivedPage]);
|
|
23194
|
-
const closeArchive =
|
|
23195
|
-
const [viewingArchivedId, setViewingArchivedId] =
|
|
23196
|
-
const handleSelectDialog =
|
|
23474
|
+
const closeArchive = useCallback26(() => setArchiveOpen(false), []);
|
|
23475
|
+
const [viewingArchivedId, setViewingArchivedId] = useState46(null);
|
|
23476
|
+
const handleSelectDialog = useCallback26(
|
|
23197
23477
|
(id) => {
|
|
23198
23478
|
setViewingArchivedId(null);
|
|
23199
23479
|
setOpeningDialogId(id);
|
|
@@ -23202,7 +23482,7 @@ function useChatDialogManager({
|
|
|
23202
23482
|
[selectDialog]
|
|
23203
23483
|
);
|
|
23204
23484
|
const isOpeningDialog = openingDialogId != null && openingDialogId === activeDialogId;
|
|
23205
|
-
const handleArchivedSelect =
|
|
23485
|
+
const handleArchivedSelect = useCallback26(
|
|
23206
23486
|
(id) => {
|
|
23207
23487
|
setArchiveOpen(false);
|
|
23208
23488
|
setOpeningDialogId(null);
|
|
@@ -23211,8 +23491,8 @@ function useChatDialogManager({
|
|
|
23211
23491
|
},
|
|
23212
23492
|
[selectDialog]
|
|
23213
23493
|
);
|
|
23214
|
-
const [restoreTarget, setRestoreTarget] =
|
|
23215
|
-
const handleConfirmRestore =
|
|
23494
|
+
const [restoreTarget, setRestoreTarget] = useState46(null);
|
|
23495
|
+
const handleConfirmRestore = useCallback26(async () => {
|
|
23216
23496
|
if (restoreTarget) {
|
|
23217
23497
|
try {
|
|
23218
23498
|
await unarchiveDialog?.(restoreTarget.id);
|
|
@@ -23226,7 +23506,7 @@ function useChatDialogManager({
|
|
|
23226
23506
|
setRestoreTarget(null);
|
|
23227
23507
|
}, [restoreTarget, unarchiveDialog]);
|
|
23228
23508
|
const isViewingArchived = viewingArchivedId != null && viewingArchivedId === activeDialogId;
|
|
23229
|
-
const handleBack =
|
|
23509
|
+
const handleBack = useCallback26(() => {
|
|
23230
23510
|
const wasArchived = isViewingArchived;
|
|
23231
23511
|
setViewingArchivedId(null);
|
|
23232
23512
|
setOpeningDialogId(null);
|
|
@@ -23234,14 +23514,14 @@ function useChatDialogManager({
|
|
|
23234
23514
|
clearMessages();
|
|
23235
23515
|
if (wasArchived) setArchiveOpen(true);
|
|
23236
23516
|
}, [isViewingArchived, selectDialog, clearMessages]);
|
|
23237
|
-
const resetToNewChat =
|
|
23517
|
+
const resetToNewChat = useCallback26(() => {
|
|
23238
23518
|
setViewingArchivedId(null);
|
|
23239
23519
|
setOpeningDialogId(null);
|
|
23240
23520
|
selectDialog(null);
|
|
23241
23521
|
clearMessages();
|
|
23242
23522
|
setArchiveOpen(false);
|
|
23243
23523
|
}, [selectDialog, clearMessages]);
|
|
23244
|
-
const activeDialog =
|
|
23524
|
+
const activeDialog = useMemo29(
|
|
23245
23525
|
() => dialogs.find((d) => d.id === activeDialogId) ?? archivedDialogs.find((d) => d.id === activeDialogId),
|
|
23246
23526
|
[dialogs, archivedDialogs, activeDialogId]
|
|
23247
23527
|
);
|
|
@@ -23304,11 +23584,11 @@ var RAIL_COLLAPSED_STORAGE_KEY = "mingo-chat-history-collapsed";
|
|
|
23304
23584
|
var NO_CONTEXT_ITEMS = [];
|
|
23305
23585
|
var RAIL_ANIM_MS = 320;
|
|
23306
23586
|
function useRailPresence(open) {
|
|
23307
|
-
const [mounted, setMounted] =
|
|
23308
|
-
const [active, setActive] =
|
|
23587
|
+
const [mounted, setMounted] = useState47(open);
|
|
23588
|
+
const [active, setActive] = useState47(false);
|
|
23309
23589
|
if (open && !mounted) setMounted(true);
|
|
23310
23590
|
if (!open && active) setActive(false);
|
|
23311
|
-
|
|
23591
|
+
useEffect38(() => {
|
|
23312
23592
|
if (open) {
|
|
23313
23593
|
let raf2 = 0;
|
|
23314
23594
|
const raf1 = requestAnimationFrame(() => {
|
|
@@ -23524,7 +23804,7 @@ function SourceChips({
|
|
|
23524
23804
|
onClose,
|
|
23525
23805
|
onDiscuss
|
|
23526
23806
|
}) {
|
|
23527
|
-
const [expanded, setExpanded] =
|
|
23807
|
+
const [expanded, setExpanded] = useState47(false);
|
|
23528
23808
|
if (cited.length === 0) {
|
|
23529
23809
|
const fallback = uncited.slice(0, FALLBACK_TOP_RETRIEVED);
|
|
23530
23810
|
if (fallback.length === 0) return null;
|
|
@@ -23631,7 +23911,7 @@ function EmbeddableChatInner({
|
|
|
23631
23911
|
const commandsUrl = runtime.endpoints.commandsUrl;
|
|
23632
23912
|
const { attachmentsEnabled, user: identityUser } = useChatIdentity();
|
|
23633
23913
|
const viewUrlPrefix = runtime.endpoints.attachmentViewUrlPrefix;
|
|
23634
|
-
|
|
23914
|
+
useEffect38(() => {
|
|
23635
23915
|
if (process.env.NODE_ENV !== "production") {
|
|
23636
23916
|
const hasOpen = open !== void 0;
|
|
23637
23917
|
const hasHandler = onOpenChange !== void 0;
|
|
@@ -23647,13 +23927,13 @@ function EmbeddableChatInner({
|
|
|
23647
23927
|
defaultProp: defaultOpen ?? false,
|
|
23648
23928
|
onChange: onOpenChange
|
|
23649
23929
|
});
|
|
23650
|
-
const [autoFocusInput] =
|
|
23930
|
+
const [autoFocusInput] = useState47(() => {
|
|
23651
23931
|
if (typeof window === "undefined") return false;
|
|
23652
23932
|
return !window.matchMedia("(pointer: coarse)").matches;
|
|
23653
23933
|
});
|
|
23654
23934
|
usePreventScroll({ isDisabled: !isOpen || shellLess });
|
|
23655
|
-
const navigatingAwayRef =
|
|
23656
|
-
|
|
23935
|
+
const navigatingAwayRef = useRef35(false);
|
|
23936
|
+
useEffect38(() => {
|
|
23657
23937
|
if (!isOpen) return void 0;
|
|
23658
23938
|
if (shellLess) return void 0;
|
|
23659
23939
|
if (typeof window === "undefined") return void 0;
|
|
@@ -23679,9 +23959,9 @@ function EmbeddableChatInner({
|
|
|
23679
23959
|
window.scrollTo(0, scrollY);
|
|
23680
23960
|
};
|
|
23681
23961
|
}, [isOpen, shellLess]);
|
|
23682
|
-
const chatInputRef =
|
|
23683
|
-
const [quickActionPreview, setQuickActionPreview] =
|
|
23684
|
-
const slashCommandsProp =
|
|
23962
|
+
const chatInputRef = useRef35(null);
|
|
23963
|
+
const [quickActionPreview, setQuickActionPreview] = useState47(null);
|
|
23964
|
+
const slashCommandsProp = useMemo30(
|
|
23685
23965
|
() => ({
|
|
23686
23966
|
fetchCommands: (prefix, signal) => fetchSlashCommands(prefix, signal, commandsUrl),
|
|
23687
23967
|
resolveSourceIcon: (sourceId) => {
|
|
@@ -23696,38 +23976,16 @@ function EmbeddableChatInner({
|
|
|
23696
23976
|
[commandsUrl]
|
|
23697
23977
|
);
|
|
23698
23978
|
const headerUserName = identityUser?.name?.trim() || [identityUser?.firstName, identityUser?.lastName].filter(Boolean).join(" ").trim() || userDisplayName?.trim() || void 0;
|
|
23699
|
-
const effectiveModes =
|
|
23979
|
+
const effectiveModes = useMemo30(() => {
|
|
23700
23980
|
if (modes) return modes;
|
|
23701
23981
|
const guideOptions = tableIdForDocumentType ? { tableIdForDocumentType } : {};
|
|
23702
23982
|
return { guide: guideOptions };
|
|
23703
23983
|
}, [modes, tableIdForDocumentType]);
|
|
23704
|
-
const mingoCaps = useMemo29(() => {
|
|
23705
|
-
if (mingoState) {
|
|
23706
|
-
return {
|
|
23707
|
-
canRename: mingoDialogCapabilities?.canRename ?? false,
|
|
23708
|
-
canArchive: mingoDialogCapabilities?.canArchive ?? false,
|
|
23709
|
-
fetchArchivedDialogs: mingoDialogCapabilities?.fetchArchivedDialogs,
|
|
23710
|
-
unarchiveDialog: mingoDialogCapabilities?.unarchiveDialog,
|
|
23711
|
-
searchQuery: mingoDialogCapabilities?.searchQuery,
|
|
23712
|
-
onSearchChange: mingoDialogCapabilities?.onSearchChange,
|
|
23713
|
-
onCopyLink: mingoDialogCapabilities?.onCopyLink
|
|
23714
|
-
};
|
|
23715
|
-
}
|
|
23716
|
-
return {
|
|
23717
|
-
canRename: !!effectiveModes.mingo?.renameDialog,
|
|
23718
|
-
canArchive: !!effectiveModes.mingo?.archiveDialog,
|
|
23719
|
-
fetchArchivedDialogs: effectiveModes.mingo?.fetchArchivedDialogs,
|
|
23720
|
-
unarchiveDialog: effectiveModes.mingo?.unarchiveDialog,
|
|
23721
|
-
searchQuery: void 0,
|
|
23722
|
-
onSearchChange: void 0,
|
|
23723
|
-
onCopyLink: void 0
|
|
23724
|
-
};
|
|
23725
|
-
}, [mingoState, mingoDialogCapabilities, effectiveModes]);
|
|
23726
23984
|
const hasMingoMode = !!effectiveModes.mingo || !!mingoState;
|
|
23727
23985
|
const initialActiveMode = controlledActiveMode ?? defaultActiveMode ?? (effectiveModes.guide ? "guide" : "mingo");
|
|
23728
|
-
const [uncontrolledActiveMode, setUncontrolledActiveMode] =
|
|
23986
|
+
const [uncontrolledActiveMode, setUncontrolledActiveMode] = useState47(initialActiveMode);
|
|
23729
23987
|
const activeMode = controlledActiveMode ?? uncontrolledActiveMode;
|
|
23730
|
-
const handleActiveModeChange =
|
|
23988
|
+
const handleActiveModeChange = useCallback27(
|
|
23731
23989
|
(next) => {
|
|
23732
23990
|
if (controlledActiveMode === void 0) {
|
|
23733
23991
|
setUncontrolledActiveMode(next);
|
|
@@ -23739,7 +23997,7 @@ function EmbeddableChatInner({
|
|
|
23739
23997
|
const { commands: commandsList, loaded: commandsLoaded } = useSlashCommandRegistry(commandsUrl, {
|
|
23740
23998
|
enabled: activeMode === "guide"
|
|
23741
23999
|
});
|
|
23742
|
-
const commandsById =
|
|
24000
|
+
const commandsById = useMemo30(() => {
|
|
23743
24001
|
const map = /* @__PURE__ */ new Map();
|
|
23744
24002
|
for (const cmd of commandsList) map.set(cmd.id, cmd);
|
|
23745
24003
|
return map;
|
|
@@ -23753,7 +24011,7 @@ function EmbeddableChatInner({
|
|
|
23753
24011
|
const effectiveGreeting = emptyStateConfig.greeting ?? emptyStateGreeting;
|
|
23754
24012
|
const effectiveEnabledRagTableIds = emptyStateUrl ? emptyStateConfig.enabledRagTableIds : enabledRagTableIds;
|
|
23755
24013
|
const effectiveSuggestedQueries = emptyStateUrl ? emptyStateConfig.suggestedQueries : suggestedQueries;
|
|
23756
|
-
const effectiveQuickActions =
|
|
24014
|
+
const effectiveQuickActions = useMemo30(
|
|
23757
24015
|
() => emptyStateUrl ? emptyStateConfig.quickActions : [],
|
|
23758
24016
|
[emptyStateUrl, emptyStateConfig.quickActions]
|
|
23759
24017
|
);
|
|
@@ -23790,10 +24048,46 @@ function EmbeddableChatInner({
|
|
|
23790
24048
|
dialogScope,
|
|
23791
24049
|
setDialogScope,
|
|
23792
24050
|
hasMoreMessages,
|
|
23793
|
-
loadMoreMessages
|
|
24051
|
+
loadMoreMessages,
|
|
24052
|
+
dialogsManaged,
|
|
24053
|
+
dialogCapabilities
|
|
23794
24054
|
} = useUnifiedChat({ modes: effectiveModes, activeMode, mingoStateOverride: mingoState });
|
|
23795
|
-
const
|
|
23796
|
-
|
|
24055
|
+
const historyListMode = activeMode === "mingo" || dialogsManaged === true;
|
|
24056
|
+
const mingoCaps = useMemo30(() => {
|
|
24057
|
+
if (dialogCapabilities) {
|
|
24058
|
+
return {
|
|
24059
|
+
canRename: dialogCapabilities.canRename ?? false,
|
|
24060
|
+
canArchive: dialogCapabilities.canArchive ?? false,
|
|
24061
|
+
fetchArchivedDialogs: dialogCapabilities.fetchArchivedDialogs,
|
|
24062
|
+
unarchiveDialog: dialogCapabilities.unarchiveDialog,
|
|
24063
|
+
searchQuery: dialogCapabilities.searchQuery,
|
|
24064
|
+
onSearchChange: dialogCapabilities.onSearchChange,
|
|
24065
|
+
onCopyLink: dialogCapabilities.onCopyLink
|
|
24066
|
+
};
|
|
24067
|
+
}
|
|
24068
|
+
if (mingoState) {
|
|
24069
|
+
return {
|
|
24070
|
+
canRename: mingoDialogCapabilities?.canRename ?? false,
|
|
24071
|
+
canArchive: mingoDialogCapabilities?.canArchive ?? false,
|
|
24072
|
+
fetchArchivedDialogs: mingoDialogCapabilities?.fetchArchivedDialogs,
|
|
24073
|
+
unarchiveDialog: mingoDialogCapabilities?.unarchiveDialog,
|
|
24074
|
+
searchQuery: mingoDialogCapabilities?.searchQuery,
|
|
24075
|
+
onSearchChange: mingoDialogCapabilities?.onSearchChange,
|
|
24076
|
+
onCopyLink: mingoDialogCapabilities?.onCopyLink
|
|
24077
|
+
};
|
|
24078
|
+
}
|
|
24079
|
+
return {
|
|
24080
|
+
canRename: !!effectiveModes.mingo?.renameDialog,
|
|
24081
|
+
canArchive: !!effectiveModes.mingo?.archiveDialog,
|
|
24082
|
+
fetchArchivedDialogs: effectiveModes.mingo?.fetchArchivedDialogs,
|
|
24083
|
+
unarchiveDialog: effectiveModes.mingo?.unarchiveDialog,
|
|
24084
|
+
searchQuery: void 0,
|
|
24085
|
+
onSearchChange: void 0,
|
|
24086
|
+
onCopyLink: void 0
|
|
24087
|
+
};
|
|
24088
|
+
}, [dialogCapabilities, mingoState, mingoDialogCapabilities, effectiveModes]);
|
|
24089
|
+
const guidePromptSentRef = useRef35(false);
|
|
24090
|
+
useEffect38(() => {
|
|
23797
24091
|
if (!guidePendingPrompt) {
|
|
23798
24092
|
guidePromptSentRef.current = false;
|
|
23799
24093
|
return;
|
|
@@ -23816,35 +24110,35 @@ function EmbeddableChatInner({
|
|
|
23816
24110
|
const { panelRef: galleryPanelRef, modal: galleryModal } = useChatAttachmentImageGallery();
|
|
23817
24111
|
const contextMaxItems = contextPicker?.maxItems ?? 10;
|
|
23818
24112
|
const contextPickerForMode = activeMode === "mingo" ? contextPicker : void 0;
|
|
23819
|
-
const [contextItems, setContextItems] =
|
|
23820
|
-
const [contextPickerOpen, setContextPickerOpen] =
|
|
23821
|
-
const [mentionQuery, setMentionQuery] =
|
|
23822
|
-
const mentionActiveRef =
|
|
23823
|
-
|
|
24113
|
+
const [contextItems, setContextItems] = useState47(NO_CONTEXT_ITEMS);
|
|
24114
|
+
const [contextPickerOpen, setContextPickerOpen] = useState47(false);
|
|
24115
|
+
const [mentionQuery, setMentionQuery] = useState47(null);
|
|
24116
|
+
const mentionActiveRef = useRef35(false);
|
|
24117
|
+
useEffect38(() => {
|
|
23824
24118
|
mentionActiveRef.current = mentionQuery !== null;
|
|
23825
24119
|
}, [mentionQuery]);
|
|
23826
|
-
const mentionKeysRef =
|
|
23827
|
-
const [contextClearedFor, setContextClearedFor] =
|
|
24120
|
+
const mentionKeysRef = useRef35(/* @__PURE__ */ new Set());
|
|
24121
|
+
const [contextClearedFor, setContextClearedFor] = useState47({ activeDialogId, activeMode });
|
|
23828
24122
|
if (contextClearedFor.activeDialogId !== activeDialogId || contextClearedFor.activeMode !== activeMode) {
|
|
23829
24123
|
setContextClearedFor({ activeDialogId, activeMode });
|
|
23830
24124
|
setContextItems(NO_CONTEXT_ITEMS);
|
|
23831
24125
|
setMentionQuery(null);
|
|
23832
24126
|
}
|
|
23833
|
-
|
|
24127
|
+
useEffect38(() => {
|
|
23834
24128
|
mentionKeysRef.current.clear();
|
|
23835
24129
|
}, [activeDialogId, activeMode]);
|
|
23836
|
-
const mentionMarkerByType =
|
|
24130
|
+
const mentionMarkerByType = useMemo30(() => {
|
|
23837
24131
|
const m = /* @__PURE__ */ new Map();
|
|
23838
24132
|
for (const t of contextPicker?.entityTypes ?? []) if (t.marker) m.set(t.type, t.marker);
|
|
23839
24133
|
return m;
|
|
23840
24134
|
}, [contextPicker?.entityTypes]);
|
|
23841
24135
|
const contextEntityTypes = contextPicker?.entityTypes;
|
|
23842
|
-
const resolveContextIcon =
|
|
24136
|
+
const resolveContextIcon = useMemo30(() => {
|
|
23843
24137
|
const byType = /* @__PURE__ */ new Map();
|
|
23844
24138
|
for (const t of contextEntityTypes ?? []) byType.set(t.type, t.icon);
|
|
23845
24139
|
return (item) => byType.get(item.type);
|
|
23846
24140
|
}, [contextEntityTypes]);
|
|
23847
|
-
const toggleContextItem =
|
|
24141
|
+
const toggleContextItem = useCallback27(
|
|
23848
24142
|
(item) => {
|
|
23849
24143
|
const key = `${item.type}:${item.id}`;
|
|
23850
24144
|
if (mentionActiveRef.current) {
|
|
@@ -23867,7 +24161,7 @@ function EmbeddableChatInner({
|
|
|
23867
24161
|
},
|
|
23868
24162
|
[contextMaxItems, contextItems, mentionMarkerByType, resolveContextIcon]
|
|
23869
24163
|
);
|
|
23870
|
-
const removeContextItem =
|
|
24164
|
+
const removeContextItem = useCallback27(
|
|
23871
24165
|
(item) => {
|
|
23872
24166
|
const key = `${item.type}:${item.id}`;
|
|
23873
24167
|
setContextItems((prev) => prev.filter((p) => `${p.type}:${p.id}` !== key));
|
|
@@ -23880,7 +24174,7 @@ function EmbeddableChatInner({
|
|
|
23880
24174
|
},
|
|
23881
24175
|
[mentionMarkerByType]
|
|
23882
24176
|
);
|
|
23883
|
-
const handleContextValueChange =
|
|
24177
|
+
const handleContextValueChange = useCallback27(
|
|
23884
24178
|
(value) => {
|
|
23885
24179
|
for (const key of Array.from(mentionKeysRef.current)) {
|
|
23886
24180
|
if (!value.includes(`@${mentionTokenOf(key, mentionMarkerByType)}`)) {
|
|
@@ -23891,32 +24185,32 @@ function EmbeddableChatInner({
|
|
|
23891
24185
|
},
|
|
23892
24186
|
[mentionMarkerByType]
|
|
23893
24187
|
);
|
|
23894
|
-
const openContextPicker =
|
|
24188
|
+
const openContextPicker = useCallback27(() => {
|
|
23895
24189
|
setMentionQuery(null);
|
|
23896
24190
|
setContextPickerOpen(true);
|
|
23897
24191
|
}, []);
|
|
23898
|
-
const closeContextPicker =
|
|
24192
|
+
const closeContextPicker = useCallback27(() => {
|
|
23899
24193
|
if (mentionActiveRef.current) {
|
|
23900
24194
|
chatInputRef.current?.removeMentionTrigger();
|
|
23901
24195
|
}
|
|
23902
24196
|
setContextPickerOpen(false);
|
|
23903
24197
|
setMentionQuery(null);
|
|
23904
24198
|
}, []);
|
|
23905
|
-
const handleMentionQueryChange =
|
|
24199
|
+
const handleMentionQueryChange = useCallback27((query) => {
|
|
23906
24200
|
setMentionQuery(query);
|
|
23907
24201
|
setContextPickerOpen(query !== null);
|
|
23908
24202
|
}, []);
|
|
23909
24203
|
const resolvedBaseRoute = baseRoute || (source === "flamingo" ? "/knowledge-base" : "/data-room");
|
|
23910
|
-
const handleClose =
|
|
23911
|
-
const handleNavigationClose =
|
|
24204
|
+
const handleClose = useCallback27(() => setIsOpen(false), [setIsOpen]);
|
|
24205
|
+
const handleNavigationClose = useCallback27(() => {
|
|
23912
24206
|
navigatingAwayRef.current = true;
|
|
23913
24207
|
setIsOpen(false);
|
|
23914
24208
|
}, [setIsOpen]);
|
|
23915
|
-
const chatPanelHandle =
|
|
24209
|
+
const chatPanelHandle = useMemo30(
|
|
23916
24210
|
() => ({ closeChat: handleNavigationClose }),
|
|
23917
24211
|
[handleNavigationClose]
|
|
23918
24212
|
);
|
|
23919
|
-
const renderEntityCard =
|
|
24213
|
+
const renderEntityCard = useCallback27(
|
|
23920
24214
|
(reference) => renderChatInlineEntityCard(reference, {
|
|
23921
24215
|
onDiscuss: discussRef,
|
|
23922
24216
|
onDisplay: displayRef,
|
|
@@ -23926,14 +24220,14 @@ function EmbeddableChatInner({
|
|
|
23926
24220
|
}),
|
|
23927
24221
|
[discussRef, displayRef, resolvedBaseRoute, chipBasePlatform, extras]
|
|
23928
24222
|
);
|
|
23929
|
-
const mingoAssistantIcon =
|
|
24223
|
+
const mingoAssistantIcon = useMemo30(
|
|
23930
24224
|
() => effectiveAssistantIcon ? /* @__PURE__ */ jsx97(EntityIcon, { icon: effectiveAssistantIcon, size: 24 }) : /* @__PURE__ */ jsx97(MingoIcon, { className: "h-6 w-6", cornerColor: "var(--ods-flamingo-cyan-base)" }),
|
|
23931
24225
|
[effectiveAssistantIcon]
|
|
23932
24226
|
);
|
|
23933
|
-
const [timestampCache] =
|
|
24227
|
+
const [timestampCache] = useState47(() => /* @__PURE__ */ new Map());
|
|
23934
24228
|
const guideUserName = activeMode === "guide" ? [identityUser?.firstName, identityUser?.lastName].filter(Boolean).join(" ").trim() || identityUser?.name?.trim() || void 0 : void 0;
|
|
23935
24229
|
const guideUserAvatar = activeMode === "guide" ? identityUser?.avatarUrl?.trim() || void 0 : void 0;
|
|
23936
|
-
const messages =
|
|
24230
|
+
const messages = useMemo30(() => {
|
|
23937
24231
|
const cache = timestampCache;
|
|
23938
24232
|
const seenIds = /* @__PURE__ */ new Set();
|
|
23939
24233
|
const mapped = rawMessages.map((m) => {
|
|
@@ -23978,7 +24272,7 @@ function EmbeddableChatInner({
|
|
|
23978
24272
|
}
|
|
23979
24273
|
return mapped;
|
|
23980
24274
|
}, [rawMessages, guideUserName, guideUserAvatar, timestampCache]);
|
|
23981
|
-
const handleSend =
|
|
24275
|
+
const handleSend = useCallback27(
|
|
23982
24276
|
(text) => {
|
|
23983
24277
|
let augmentedText = text;
|
|
23984
24278
|
if (readyAttachments.length > 0) {
|
|
@@ -24000,7 +24294,7 @@ function EmbeddableChatInner({
|
|
|
24000
24294
|
},
|
|
24001
24295
|
[sendMessage, readyAttachments, viewUrlPrefix, clearAttachments, contextItems]
|
|
24002
24296
|
);
|
|
24003
|
-
const handleAskSelect =
|
|
24297
|
+
const handleAskSelect = useCallback27(
|
|
24004
24298
|
(label) => {
|
|
24005
24299
|
void sendMessage(label).catch((err) => {
|
|
24006
24300
|
console.error("[EmbeddableChat] handleAskSelect send failed:", err);
|
|
@@ -24008,7 +24302,7 @@ function EmbeddableChatInner({
|
|
|
24008
24302
|
},
|
|
24009
24303
|
[sendMessage]
|
|
24010
24304
|
);
|
|
24011
|
-
const guideSuggestedActions =
|
|
24305
|
+
const guideSuggestedActions = useMemo30(() => {
|
|
24012
24306
|
if (effectiveQuickActions.length > 0) {
|
|
24013
24307
|
return effectiveQuickActions.map((qa) => ({
|
|
24014
24308
|
id: qa.id,
|
|
@@ -24067,9 +24361,9 @@ function EmbeddableChatInner({
|
|
|
24067
24361
|
fetchArchivedDialogs: mingoCaps.fetchArchivedDialogs,
|
|
24068
24362
|
unarchiveDialog: mingoCaps.unarchiveDialog
|
|
24069
24363
|
});
|
|
24070
|
-
const handleOpen =
|
|
24364
|
+
const handleOpen = useCallback27(() => setIsOpen(true), [setIsOpen]);
|
|
24071
24365
|
useCloseOnNavigation(handleNavigationClose, null);
|
|
24072
|
-
|
|
24366
|
+
useEffect38(() => {
|
|
24073
24367
|
const handler = (e) => {
|
|
24074
24368
|
const detail = e.detail;
|
|
24075
24369
|
if (!detail || detail.source !== source) return;
|
|
@@ -24079,7 +24373,7 @@ function EmbeddableChatInner({
|
|
|
24079
24373
|
window.addEventListener("ask-ai:open-with-ref", handler);
|
|
24080
24374
|
return () => window.removeEventListener("ask-ai:open-with-ref", handler);
|
|
24081
24375
|
}, [source, discussRef, setIsOpen]);
|
|
24082
|
-
|
|
24376
|
+
useEffect38(() => {
|
|
24083
24377
|
const handler = (e) => {
|
|
24084
24378
|
const detail = e.detail;
|
|
24085
24379
|
if (!detail || detail.source !== source) return;
|
|
@@ -24091,7 +24385,7 @@ function EmbeddableChatInner({
|
|
|
24091
24385
|
const hasMessages = messages.length > 0;
|
|
24092
24386
|
const dialogsInitialLoading = isDialogsLoading && dialogs.length === 0;
|
|
24093
24387
|
const dialogsLoadError = dialogsError && dialogs.length === 0;
|
|
24094
|
-
const hasConversation = hasMessages || isOpeningDialog || isViewingArchived || previewMode && isMessagesLoading;
|
|
24388
|
+
const hasConversation = hasMessages || isOpeningDialog || isViewingArchived || (previewMode || activeMode === "guide" && dialogsManaged === true) && isMessagesLoading;
|
|
24095
24389
|
const messagesInitialLoading = isMessagesLoading && !hasMessages;
|
|
24096
24390
|
const contentViewKey = hasConversation ? "conversation" : activeMode;
|
|
24097
24391
|
const isGuideEmpty = !hasConversation && activeMode === "guide";
|
|
@@ -24099,11 +24393,11 @@ function EmbeddableChatInner({
|
|
|
24099
24393
|
if (!isQuickActionEmpty && quickActionPreview !== null) setQuickActionPreview(null);
|
|
24100
24394
|
const guideCanReturnToMingo = isGuideEmpty && hasMingoMode;
|
|
24101
24395
|
const sourceLabel = source === "flamingo" ? "Knowledge Base" : "Data Room";
|
|
24102
|
-
const enabledSet =
|
|
24396
|
+
const enabledSet = useMemo30(
|
|
24103
24397
|
() => effectiveEnabledRagTableIds ? new Set(effectiveEnabledRagTableIds) : null,
|
|
24104
24398
|
[effectiveEnabledRagTableIds]
|
|
24105
24399
|
);
|
|
24106
|
-
const chipCommands =
|
|
24400
|
+
const chipCommands = useMemo30(() => {
|
|
24107
24401
|
const out = [];
|
|
24108
24402
|
for (const cmd of commandsById.values()) {
|
|
24109
24403
|
if (cmd.displayOrder === void 0) continue;
|
|
@@ -24119,7 +24413,7 @@ function EmbeddableChatInner({
|
|
|
24119
24413
|
return out;
|
|
24120
24414
|
}, [commandsById, enabledSet]);
|
|
24121
24415
|
const lastAssistantMsg = [...rawMessages].reverse().find((m) => m.role === "assistant");
|
|
24122
|
-
const lastSources =
|
|
24416
|
+
const lastSources = useMemo30(() => {
|
|
24123
24417
|
if (chatLoading) return void 0;
|
|
24124
24418
|
const sources = lastAssistantMsg?.sources;
|
|
24125
24419
|
if (!sources || sources.length === 0) return void 0;
|
|
@@ -24133,11 +24427,11 @@ function EmbeddableChatInner({
|
|
|
24133
24427
|
const uncited = sources.filter((s) => !seenOrder.has(s.index));
|
|
24134
24428
|
return { cited, uncited };
|
|
24135
24429
|
}, [lastAssistantMsg, chatLoading]);
|
|
24136
|
-
const [portalHost, setPortalHost] =
|
|
24137
|
-
const [panelBoundary, setPanelBoundary] =
|
|
24138
|
-
const [panelWidth, setPanelWidth] =
|
|
24139
|
-
const panelMeasureRef =
|
|
24140
|
-
|
|
24430
|
+
const [portalHost, setPortalHost] = useState47(null);
|
|
24431
|
+
const [panelBoundary, setPanelBoundary] = useState47(null);
|
|
24432
|
+
const [panelWidth, setPanelWidth] = useState47(0);
|
|
24433
|
+
const panelMeasureRef = useRef35(null);
|
|
24434
|
+
useEffect38(() => {
|
|
24141
24435
|
const el = panelMeasureRef.current;
|
|
24142
24436
|
if (!el || typeof ResizeObserver === "undefined") return void 0;
|
|
24143
24437
|
const ro = new ResizeObserver((entries) => {
|
|
@@ -24148,13 +24442,13 @@ function EmbeddableChatInner({
|
|
|
24148
24442
|
setPanelWidth(el.clientWidth);
|
|
24149
24443
|
return () => ro.disconnect();
|
|
24150
24444
|
}, []);
|
|
24151
|
-
const setPanelNode =
|
|
24445
|
+
const setPanelNode = useCallback27((node) => {
|
|
24152
24446
|
panelMeasureRef.current = node;
|
|
24153
24447
|
setPanelBoundary(node);
|
|
24154
24448
|
}, []);
|
|
24155
|
-
const [railCollapsed, setRailCollapsed] =
|
|
24449
|
+
const [railCollapsed, setRailCollapsed] = useState47(false);
|
|
24156
24450
|
const railStorageHydrated = useIsHydrated();
|
|
24157
|
-
const [railStorageRead, setRailStorageRead] =
|
|
24451
|
+
const [railStorageRead, setRailStorageRead] = useState47(false);
|
|
24158
24452
|
if (railStorageHydrated && !railStorageRead) {
|
|
24159
24453
|
setRailStorageRead(true);
|
|
24160
24454
|
try {
|
|
@@ -24162,7 +24456,7 @@ function EmbeddableChatInner({
|
|
|
24162
24456
|
} catch {
|
|
24163
24457
|
}
|
|
24164
24458
|
}
|
|
24165
|
-
const toggleRailCollapsed =
|
|
24459
|
+
const toggleRailCollapsed = useCallback27(() => {
|
|
24166
24460
|
setRailCollapsed((prev) => {
|
|
24167
24461
|
const next = !prev;
|
|
24168
24462
|
try {
|
|
@@ -24172,16 +24466,16 @@ function EmbeddableChatInner({
|
|
|
24172
24466
|
return next;
|
|
24173
24467
|
});
|
|
24174
24468
|
}, []);
|
|
24175
|
-
const [railSearchOpen, setRailSearchOpen] =
|
|
24176
|
-
const splitEligible =
|
|
24469
|
+
const [railSearchOpen, setRailSearchOpen] = useState47(false);
|
|
24470
|
+
const splitEligible = historyListMode;
|
|
24177
24471
|
const canSplit = panelWidth >= SPLIT_MIN_WIDTH;
|
|
24178
24472
|
const wideMingo = splitEligible && canSplit && !previewMode;
|
|
24179
24473
|
const splitActive = wideMingo && !railCollapsed;
|
|
24180
24474
|
const railPresence = useRailPresence(splitActive);
|
|
24181
24475
|
const showWideHeader = wideMingo || railPresence.mounted;
|
|
24182
|
-
const [composeOpen, setComposeOpen] =
|
|
24476
|
+
const [composeOpen, setComposeOpen] = useState47(false);
|
|
24183
24477
|
if (hasConversation && composeOpen) setComposeOpen(false);
|
|
24184
|
-
const isMingoMode =
|
|
24478
|
+
const isMingoMode = historyListMode;
|
|
24185
24479
|
const stackedListView = isMingoMode && !hasConversation && !archiveOpen && !wideMingo && !composeOpen;
|
|
24186
24480
|
const headerShowBack = hasConversation || guideCanReturnToMingo;
|
|
24187
24481
|
const headerTitle = hasConversation ? activeDialog?.title || "New Chat" : isGuideEmpty ? headerAssistantName ?? "Mingo Guide" : "Current Chats";
|
|
@@ -24196,7 +24490,7 @@ function EmbeddableChatInner({
|
|
|
24196
24490
|
const headerPersonName = headerOwner?.name?.trim() || headerUserName;
|
|
24197
24491
|
const headerPersonAvatarUrl = headerOwner ? headerOwner.avatarUrl?.trim() || void 0 : identityUser?.avatarUrl?.trim() || userAvatarUrl?.trim() || void 0;
|
|
24198
24492
|
const headerAvatar = headerPersonName || headerPersonAvatarUrl ? { name: headerPersonName, avatarUrl: headerPersonAvatarUrl } : void 0;
|
|
24199
|
-
const handleNewChat =
|
|
24493
|
+
const handleNewChat = useCallback27(() => {
|
|
24200
24494
|
resetToNewChat();
|
|
24201
24495
|
}, [resetToNewChat]);
|
|
24202
24496
|
useImperativeHandle4(
|
|
@@ -24217,7 +24511,9 @@ function EmbeddableChatInner({
|
|
|
24217
24511
|
const narrowMingoEmpty = isMingoMode && !hasConversation && !archiveOpen;
|
|
24218
24512
|
const narrowHeaderProps = narrowMingoEmpty ? composeOpen ? {
|
|
24219
24513
|
showBack: true,
|
|
24220
|
-
|
|
24514
|
+
// Guide's compose view is its own welcome (assistant name), not a
|
|
24515
|
+
// Mingo "New Chat".
|
|
24516
|
+
title: isGuideEmpty ? headerAssistantName ?? "Mingo Guide" : "New Chat",
|
|
24221
24517
|
subtitle: headerUserName,
|
|
24222
24518
|
avatar: headerAvatar,
|
|
24223
24519
|
backAriaLabel: "Back to chats",
|
|
@@ -24334,7 +24630,7 @@ function EmbeddableChatInner({
|
|
|
24334
24630
|
),
|
|
24335
24631
|
/* @__PURE__ */ jsxs75("div", { className: "flex min-w-0 flex-1 items-center gap-[var(--spacing-system-m)] px-[var(--spacing-system-mf)] py-[var(--spacing-system-sf)]", children: [
|
|
24336
24632
|
/* @__PURE__ */ jsxs75("div", { className: "flex min-w-0 flex-col", children: [
|
|
24337
|
-
/* @__PURE__ */ jsx97("p", { className: "truncate leading-tight text-ods-text-primary text-h3", children: headerShowBack ? headerTitle : "New Chat" }),
|
|
24633
|
+
/* @__PURE__ */ jsx97("p", { className: "truncate leading-tight text-ods-text-primary text-h3", children: headerShowBack || isGuideEmpty ? headerTitle : "New Chat" }),
|
|
24338
24634
|
headerPersonName && /* @__PURE__ */ jsx97("p", { className: "truncate leading-tight text-ods-text-secondary text-h6", children: headerPersonName })
|
|
24339
24635
|
] }),
|
|
24340
24636
|
headerAvatar ? (
|
|
@@ -25031,6 +25327,7 @@ export {
|
|
|
25031
25327
|
createChatDialogStore,
|
|
25032
25328
|
createDeltaBatcher,
|
|
25033
25329
|
useChatStreamReducer,
|
|
25330
|
+
createChatConversationsApi,
|
|
25034
25331
|
parseWireCommandOverride,
|
|
25035
25332
|
sanitizeTitleForChat,
|
|
25036
25333
|
formatSingularLookupInvocation,
|
|
@@ -25039,6 +25336,7 @@ export {
|
|
|
25039
25336
|
buildDiscussPrompt,
|
|
25040
25337
|
AUTO_CONTINUATION_DIRECTIVE_PREFIX,
|
|
25041
25338
|
buildAutoContinuationDirective,
|
|
25339
|
+
useManagedDialogList,
|
|
25042
25340
|
useSseChatAdapter,
|
|
25043
25341
|
extractIncompleteMessageState,
|
|
25044
25342
|
extractIncompleteTailState,
|
|
@@ -25063,4 +25361,4 @@ export {
|
|
|
25063
25361
|
buildStreamFrames,
|
|
25064
25362
|
EmbeddableChat
|
|
25065
25363
|
};
|
|
25066
|
-
//# sourceMappingURL=chunk-
|
|
25364
|
+
//# sourceMappingURL=chunk-XAJZIDFH.js.map
|