@adminide-stack/yantra-mobile 12.0.53-alpha.1 → 12.0.53-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/lib/components/KeyboardComposerDock.js +41 -5
  2. package/lib/components/KeyboardComposerDock.js.map +1 -1
  3. package/lib/features/attachments/ComposerAttachMenu.js +189 -0
  4. package/lib/features/attachments/ComposerAttachMenu.js.map +1 -0
  5. package/lib/features/attachments/useImageAttachments.js +23 -15
  6. package/lib/features/attachments/useImageAttachments.js.map +1 -1
  7. package/lib/features/canvas/canvasBoardsSnapshot.js +37 -0
  8. package/lib/features/canvas/canvasBoardsSnapshot.js.map +1 -0
  9. package/lib/features/canvas/nativeViewerRegistry.js +9 -1
  10. package/lib/features/canvas/nativeViewerRegistry.js.map +1 -1
  11. package/lib/features/chat/ChatTranscript.js +7 -0
  12. package/lib/features/chat/ChatTranscript.js.map +1 -1
  13. package/lib/features/chat/chatHistorySnapshot.js +103 -0
  14. package/lib/features/chat/chatHistorySnapshot.js.map +1 -0
  15. package/lib/graphql/typePolicies.js +139 -0
  16. package/lib/graphql/typePolicies.js.map +1 -0
  17. package/lib/hooks/useChatApi.js +202 -25
  18. package/lib/hooks/useChatApi.js.map +1 -1
  19. package/lib/hooks/useChatStream.js +56 -30
  20. package/lib/hooks/useChatStream.js.map +1 -1
  21. package/lib/index.js +1 -1
  22. package/lib/index.js.map +1 -1
  23. package/lib/module.js +5 -2
  24. package/lib/module.js.map +1 -1
  25. package/lib/screens/Chat/index.js +7 -35
  26. package/lib/screens/Chat/index.js.map +1 -1
  27. package/lib/screens/Home/HomeScreen.js +18 -31
  28. package/lib/screens/Home/HomeScreen.js.map +1 -1
  29. package/lib/screens/Home/components/CanvasPrewarm.js +3 -2
  30. package/lib/screens/Home/components/CanvasPrewarm.js.map +1 -1
  31. package/lib/screens/Home/components/ChatHistoryLanding.js +46 -8
  32. package/lib/screens/Home/components/ChatHistoryLanding.js.map +1 -1
  33. package/lib/state/chatThreadMerge.js +76 -2
  34. package/lib/state/chatThreadMerge.js.map +1 -1
  35. package/package.json +3 -3
@@ -1,4 +1,4 @@
1
- import {useApolloClient}from'@apollo/client/index.js';import {SortEnum,RoomType,PostTypeEnum,AiAgentMessageRole}from'common';import {useGetChannelsByUserWithLastMessageQuery,useMessagesQuery,useAddChannelMutation,useSendMessagesMutation,MessagesDocument,GetChannelsByUserWithLastMessageDocument}from'common/graphql';import {useMemo,useCallback}from'react';import {v4}from'uuid';import {isAttachedCaption,historyAttachmentTitle,attachmentsFromUserContent}from'../features/attachments/historyAttachmentLabel.js';var __defProp = Object.defineProperty;
1
+ import {useApolloClient}from'@apollo/client/index.js';import {SortEnum,RoomType,PostTypeEnum,AiAgentMessageRole}from'common';import {useGetChannelsByUserWithLastMessageQuery,useMessagesQuery,useAddChannelMutation,useSendMessagesMutation,OnChatMessageAddedDocument,MessagesDocument,GetChannelsByUserWithLastMessageDocument}from'common/graphql';import {useMemo,useCallback,useEffect}from'react';import {v4}from'uuid';import {isAttachedCaption,historyAttachmentTitle,attachmentsFromUserContent}from'../features/attachments/historyAttachmentLabel.js';import {stripAskUser}from'../features/chat/askUser.js';import {parseToolActivity}from'../features/chat/toolActivity.js';var __defProp = Object.defineProperty;
2
2
  var __defProps = Object.defineProperties;
3
3
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
4
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
@@ -81,11 +81,7 @@ function getThreadMessagesQueryVariables(sessionId) {
81
81
  return {
82
82
  channelId: sessionId,
83
83
  limit: MESSAGES_PAGE_LIMIT,
84
- skip: 0,
85
- sort: {
86
- key: "createdAt",
87
- value: SortEnum.Asc
88
- }
84
+ skip: 0
89
85
  };
90
86
  }
91
87
  function getChatHistoryMessagesQueryVariables(accountUserId, options) {
@@ -148,6 +144,7 @@ function useChatHistorySessionsFromMessages(accountUserId, options) {
148
144
  // Later visits read the cache — no repeated network hit.
149
145
  fetchPolicy: "cache-first",
150
146
  nextFetchPolicy: "cache-first",
147
+ returnPartialData: true,
151
148
  context: {
152
149
  cacheKey: "new-chat-history-messages"
153
150
  }
@@ -214,7 +211,7 @@ function cleanMessageText(raw) {
214
211
  return raw.replace(ACTIVE_CONNECTORS_PREFIX_RE, "").replace(/\s+/g, " ").trim();
215
212
  }
216
213
  function isTransientHistoryText(text) {
217
- const t = cleanMessageText(text);
214
+ const t = cleanHistoryPreview(text) || cleanMessageText(text);
218
215
  if (!t) return true;
219
216
  if (/^thinking[.…]*$/i.test(t)) return true;
220
217
  if (/^let me check on that requested skill/i.test(t)) return true;
@@ -231,10 +228,14 @@ function looksLikeAssistantReply(text, role) {
231
228
  return false;
232
229
  }
233
230
  function cleanHistoryPreview(raw) {
234
- let t = cleanMessageText(raw);
231
+ const withoutAsk = stripAskUser(raw);
232
+ const {
233
+ text: withoutTools
234
+ } = parseToolActivity(withoutAsk, false);
235
+ let t = cleanMessageText(withoutTools);
235
236
  t = t.replace(/^(thinking[.…]*\s*)+/i, "").trim();
236
237
  t = t.replace(/^let me check on that requested skill[^\n.!?]*[.!?-]?\s*/i, "").trim();
237
- t = t.replace(/^(?:⚙️[^\n]*\n)+\s*/g, "").trim();
238
+ t = t.replace(/^(?:[⚙🔧⚙️⚠][^\n]*\n)+\s*/gu, "").trim();
238
239
  return t;
239
240
  }
240
241
  function buildSessionFromChannel(channel) {
@@ -297,25 +298,121 @@ function chatHistorySessionsFromChannels(data) {
297
298
  return channels.filter((c) => Boolean(c == null ? void 0 : c.id) && (!(c == null ? void 0 : c.type) || c.type === RoomType.Aiassistant)).map((c) => buildSessionFromChannel(c)).filter((row) => row !== null).sort((a, b) => b.updatedAt.getTime() - a.updatedAt.getTime());
298
299
  }
299
300
  const rememberedHistoryTitles = /* @__PURE__ */ new Map();
301
+ const rememberedHistoryListeners = /* @__PURE__ */ new Set();
302
+ function subscribeRememberedHistory(listener) {
303
+ rememberedHistoryListeners.add(listener);
304
+ return () => {
305
+ rememberedHistoryListeners.delete(listener);
306
+ };
307
+ }
308
+ function mergeRememberedHistory(channelId, patch, notify = true) {
309
+ var _a, _b;
310
+ const existing = (_a = rememberedHistoryTitles.get(channelId)) != null ? _a : {};
311
+ const next = {
312
+ title: patch.title || existing.title,
313
+ preview: patch.preview || existing.preview,
314
+ isAttachment: (_b = patch.isAttachment) != null ? _b : existing.isAttachment
315
+ };
316
+ rememberedHistoryTitles.set(channelId, next);
317
+ if (notify && (next.title !== existing.title || next.preview !== existing.preview)) {
318
+ rememberedHistoryListeners.forEach((fn) => fn());
319
+ }
320
+ return next;
321
+ }
300
322
  function rememberHistoryTitle(session) {
301
- var _a;
302
- if (session.isPlaceholder) return;
303
- const title = (_a = session.title) == null ? void 0 : _a.trim();
304
- if (!title || /^new chat$/i.test(title) || isTransientHistoryText(title)) return;
305
- rememberedHistoryTitles.set(session.channelId, {
306
- title,
323
+ var _a, _b;
324
+ const title = session.isPlaceholder || /^new chat$/i.test(session.title) ? "" : (_a = session.title) == null ? void 0 : _a.trim();
325
+ const preview = ((_b = session.preview) == null ? void 0 : _b.trim()) && !isTransientHistoryText(session.preview) ? session.preview.trim() : "";
326
+ if (title && isTransientHistoryText(title) && !preview) return;
327
+ if (!title && !preview) return;
328
+ mergeRememberedHistory(session.channelId, __spreadProps(__spreadValues(__spreadValues({}, title && !isTransientHistoryText(title) ? {
329
+ title
330
+ } : {}), preview ? {
331
+ preview
332
+ } : {}), {
307
333
  isAttachment: session.isAttachment
334
+ }), false);
335
+ }
336
+ function deriveHistoryTitleFromPrompt(rawPrompt) {
337
+ const cleaned = cleanMessageText(rawPrompt);
338
+ if (!cleaned || isTransientHistoryText(cleaned) || /^new chat$/i.test(cleaned)) return "";
339
+ if (cleaned.length <= 64) return cleaned;
340
+ return `${cleaned.slice(0, 64).trim()}...`;
341
+ }
342
+ function patchChannelHistoryTitle(client, channelId, rawPrompt) {
343
+ const cleaned = deriveHistoryTitleFromPrompt(rawPrompt);
344
+ if (!channelId || !cleaned) return;
345
+ mergeRememberedHistory(channelId, {
346
+ title: cleaned,
347
+ isAttachment: isAttachedCaption(cleaned)
348
+ });
349
+ const channelCacheId = client.cache.identify({
350
+ __typename: "Channel",
351
+ id: channelId
352
+ });
353
+ if (!channelCacheId) return;
354
+ try {
355
+ client.cache.modify({
356
+ id: channelCacheId,
357
+ fields: {
358
+ title(existing) {
359
+ return cleanChannelTitle(existing) ? existing : cleaned;
360
+ }
361
+ // Do not touch updatedAt here. Bumping it on open/hydrate moves the
362
+ // row to TODAY / "now". Activity time is only written when the user
363
+ // actually sends (touchChannelHistoryUpdatedAt).
364
+ }
365
+ });
366
+ } catch (err) {
367
+ console.warn("[useChatApi] patchChannelHistoryTitle failed:", err);
368
+ }
369
+ }
370
+ function touchChannelHistoryUpdatedAt(client, channelId) {
371
+ if (!channelId) return;
372
+ const channelCacheId = client.cache.identify({
373
+ __typename: "Channel",
374
+ id: channelId
375
+ });
376
+ if (!channelCacheId) return;
377
+ try {
378
+ client.cache.modify({
379
+ id: channelCacheId,
380
+ fields: {
381
+ updatedAt() {
382
+ return (/* @__PURE__ */ new Date()).toISOString();
383
+ }
384
+ }
385
+ });
386
+ } catch (err) {
387
+ console.warn("[useChatApi] touchChannelHistoryUpdatedAt failed:", err);
388
+ }
389
+ }
390
+ function patchChannelHistoryPreview(channelId, rawPreview) {
391
+ var _a, _b;
392
+ if (!channelId) return;
393
+ const preview = cleanHistoryPreview(rawPreview);
394
+ if (!preview || isTransientHistoryText(preview) || isAttachedCaption(preview)) return;
395
+ const title = (_b = (_a = rememberedHistoryTitles.get(channelId)) == null ? void 0 : _a.title) != null ? _b : "";
396
+ if (title && preview === title) return;
397
+ mergeRememberedHistory(channelId, {
398
+ preview
308
399
  });
309
400
  }
310
401
  function applyRememberedHistoryTitles(rows) {
311
402
  return rows.map((row) => {
403
+ var _a;
312
404
  rememberHistoryTitle(row);
313
- if (!row.isPlaceholder && !/^new chat$/i.test(row.title)) return row;
314
405
  const mem = rememberedHistoryTitles.get(row.channelId);
315
406
  if (!mem) return row;
407
+ const titleMissing = row.isPlaceholder || /^new chat$/i.test(row.title);
408
+ const previewMissing = !((_a = row.preview) == null ? void 0 : _a.trim());
409
+ if (!titleMissing && !previewMissing) return row;
410
+ const nextTitle = titleMissing && mem.title ? mem.title : row.title;
411
+ const nextPreview = previewMissing && mem.preview && mem.preview !== nextTitle ? mem.preview : row.preview;
316
412
  return __spreadProps(__spreadValues({}, row), {
317
- title: mem.title,
318
- isPlaceholder: false,
413
+ title: nextTitle,
414
+ preview: nextPreview,
415
+ isPlaceholder: titleMissing && mem.title ? false : row.isPlaceholder,
319
416
  isAttachment: mem.isAttachment || row.isAttachment
320
417
  });
321
418
  });
@@ -366,6 +463,7 @@ function useChatHistorySessionsFromChannels(orgName, options) {
366
463
  // / createChannel cache writes, not per-visit network hits.
367
464
  fetchPolicy: "cache-first",
368
465
  nextFetchPolicy: "cache-first",
466
+ returnPartialData: true,
369
467
  context: {
370
468
  cacheKey: "chat-history-channels-list"
371
469
  }
@@ -382,6 +480,11 @@ function useChatHistorySessionsFromChannels(orgName, options) {
382
480
  sourceChannelCount
383
481
  };
384
482
  }
483
+ function usePrefetchChatHistory(orgName) {
484
+ return useChatHistorySessionsFromChannels(orgName, {
485
+ skip: !orgName
486
+ });
487
+ }
385
488
  function stripModelCostHeader(content) {
386
489
  const normalized = content.replace(/\r\n/g, "\n");
387
490
  return normalized.replace(/^\s*(?:[^\w\n]+\s*)?[a-z0-9][a-z0-9._-]*\s*\(\s*\$[\d.]+\s*\/\s*MTok\s+in\s*\)\s*\n+/i, "");
@@ -483,19 +586,23 @@ function mapPostToChatMessageUI(post, fallbackChannelId) {
483
586
  };
484
587
  }
485
588
  function useChatMessages(sessionId, options) {
589
+ const client = useApolloClient();
486
590
  const {
487
591
  data,
488
592
  loading,
489
593
  error,
490
- refetch
594
+ refetch,
595
+ subscribeToMore
491
596
  } = useMessagesQuery({
492
597
  variables: sessionId ? getThreadMessagesQueryVariables(sessionId) : void 0,
493
598
  skip: !sessionId || (void 0 ),
494
- // cache-first + `messages` typePolicy (keyed by channelId). Opening a thread
495
- // that was already loaded does not refetch. New channels still hit the
496
- // network once. saveMessages writes new posts into this cache slot.
497
- fetchPolicy: "cache-first",
599
+ // Same as browser: paint cache immediately, then hit the network so a thread
600
+ // opened from history is not stuck on a cache-first snapshot that only has
601
+ // the latest user post (assistant replies persist after the first query).
602
+ fetchPolicy: "cache-and-network",
498
603
  nextFetchPolicy: "cache-first",
604
+ errorPolicy: "all",
605
+ notifyOnNetworkStatusChange: true,
499
606
  /**
500
607
  * Cache key is per-channel so switching sessions doesn't read another channel's response.
501
608
  * Keeping this as a constant ('messages-list') used to cause cross-session bleed in the
@@ -505,12 +612,77 @@ function useChatMessages(sessionId, options) {
505
612
  cacheKey: sessionId ? `messages-list:${sessionId}` : "messages-list"
506
613
  }
507
614
  });
615
+ useEffect(() => {
616
+ if (!sessionId || (void 0 )) return;
617
+ const unsubscribe = subscribeToMore({
618
+ document: OnChatMessageAddedDocument,
619
+ variables: {
620
+ channelId: sessionId
621
+ },
622
+ updateQuery: (prev, {
623
+ subscriptionData
624
+ }) => {
625
+ var _a, _b, _c, _d, _e;
626
+ const post = (_a = subscriptionData == null ? void 0 : subscriptionData.data) == null ? void 0 : _a.chatMessageAdded;
627
+ if (!(post == null ? void 0 : post.id)) return prev;
628
+ if (!(prev == null ? void 0 : prev.messages)) return prev;
629
+ const existing = (_b = prev.messages.data) != null ? _b : [];
630
+ const idx = existing.findIndex((row) => (row == null ? void 0 : row.id) === post.id);
631
+ let nextData;
632
+ let nextTotal;
633
+ if (idx >= 0) {
634
+ nextData = [...existing.slice(0, idx), post, ...existing.slice(idx + 1)];
635
+ nextTotal = (_c = prev.messages.totalCount) != null ? _c : existing.length;
636
+ } else {
637
+ nextData = [...existing, post];
638
+ nextTotal = ((_d = prev.messages.totalCount) != null ? _d : existing.length) + 1;
639
+ const parentId = (_e = post.parentId) != null ? _e : null;
640
+ if (parentId) {
641
+ nextData = nextData.map((root) => {
642
+ var _a2, _b2, _c2, _d2, _e2, _f, _g;
643
+ if ((root == null ? void 0 : root.id) !== parentId) return root;
644
+ const replies = (_b2 = (_a2 = root.replies) == null ? void 0 : _a2.data) != null ? _b2 : [];
645
+ if (replies.some((reply) => (reply == null ? void 0 : reply.id) === post.id)) return root;
646
+ return __spreadProps(__spreadValues({}, root), {
647
+ replies: __spreadProps(__spreadValues({}, (_c2 = root.replies) != null ? _c2 : {}), {
648
+ __typename: (_e2 = (_d2 = root.replies) == null ? void 0 : _d2.__typename) != null ? _e2 : "Messages",
649
+ data: [...replies, post],
650
+ totalCount: ((_g = (_f = root.replies) == null ? void 0 : _f.totalCount) != null ? _g : replies.length) + 1
651
+ })
652
+ });
653
+ });
654
+ }
655
+ }
656
+ const seen = /* @__PURE__ */ new Set();
657
+ nextData = nextData.filter((row) => {
658
+ if (!(row == null ? void 0 : row.id) || seen.has(row.id)) return false;
659
+ seen.add(row.id);
660
+ return true;
661
+ });
662
+ return __spreadProps(__spreadValues({}, prev), {
663
+ messages: __spreadProps(__spreadValues({}, prev.messages), {
664
+ data: nextData,
665
+ totalCount: nextTotal
666
+ })
667
+ });
668
+ },
669
+ onError: (err) => {
670
+ console.error("[useChatMessages] subscribeToMore error:", err);
671
+ }
672
+ });
673
+ return () => unsubscribe();
674
+ }, [sessionId, void 0 , subscribeToMore, client]);
508
675
  const messagesLoaded = data !== void 0;
509
676
  const messages = useMemo(() => {
510
677
  var _a, _b;
511
678
  if (!sessionId) return [];
512
679
  const rows = (_b = (_a = data == null ? void 0 : data.messages) == null ? void 0 : _a.data) != null ? _b : [];
513
- return flattenPostsWithReplies(rows, sessionId);
680
+ const ownRows = rows.filter((post) => {
681
+ var _a2;
682
+ const postChannelId = (_a2 = post == null ? void 0 : post.channel) == null ? void 0 : _a2.id;
683
+ return !postChannelId || postChannelId === sessionId;
684
+ });
685
+ return flattenPostsWithReplies(ownRows, sessionId);
514
686
  }, [data, sessionId]);
515
687
  return {
516
688
  messages,
@@ -768,13 +940,18 @@ function useChatMutations() {
768
940
  }
769
941
  };
770
942
  }, [client, sendMessagesMutation]);
943
+ const patchChannelTitle = useCallback((channelId, rawPrompt, bumpActivity = false) => {
944
+ patchChannelHistoryTitle(client, channelId, rawPrompt);
945
+ if (bumpActivity) touchChannelHistoryUpdatedAt(client, channelId);
946
+ }, [client]);
771
947
  return {
772
948
  createChannel,
773
949
  createSession: createChannel,
774
950
  saveMessages,
951
+ patchChannelTitle,
775
952
  loading: {
776
953
  create: createChannelLoading,
777
954
  saveMessages: sendMessagesLoading
778
955
  }
779
956
  };
780
- }export{AI_ASSISTANT_CHANNELS_QUERY_VARS,HISTORY_PAGE_SIZE,HISTORY_QUERY_BASE,buildSessionFromChannel,chatHistorySessionsFromChannels,chatHistorySessionsFromMessages,enrichHistorySessionsWithUserPrompts,getChatHistoryChannelRefetchQueries,getChatHistoryMessagesQueryVariables,getHistoryChannelsQueryVariables,useChatHistorySessionsFromChannels,useChatHistorySessionsFromMessages,useChatMessages,useChatMutations};//# sourceMappingURL=useChatApi.js.map
957
+ }export{AI_ASSISTANT_CHANNELS_QUERY_VARS,HISTORY_PAGE_SIZE,HISTORY_QUERY_BASE,buildSessionFromChannel,chatHistorySessionsFromChannels,chatHistorySessionsFromMessages,enrichHistorySessionsWithUserPrompts,getChatHistoryChannelRefetchQueries,getChatHistoryMessagesQueryVariables,getHistoryChannelsQueryVariables,patchChannelHistoryPreview,patchChannelHistoryTitle,subscribeRememberedHistory,touchChannelHistoryUpdatedAt,useChatHistorySessionsFromChannels,useChatHistorySessionsFromMessages,useChatMessages,useChatMutations,usePrefetchChatHistory};//# sourceMappingURL=useChatApi.js.map