@adminide-stack/yantra-mobile 12.0.55-alpha.2 → 12.0.55-alpha.4

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 (37) hide show
  1. package/lib/components/KeyboardComposerDock.js +2 -2
  2. package/lib/components/KeyboardComposerDock.js.map +1 -1
  3. package/lib/components/ThinkingIndicator.js +123 -35
  4. package/lib/components/ThinkingIndicator.js.map +1 -1
  5. package/lib/contexts/ChatLiveStreamContext.js +54 -0
  6. package/lib/contexts/ChatLiveStreamContext.js.map +1 -0
  7. package/lib/features/agent-chat/NativeAgentChat.js +1 -1
  8. package/lib/features/agent-chat/NativeAgentChat.js.map +1 -1
  9. package/lib/features/chat/AssistantMarkdown.js +313 -0
  10. package/lib/features/chat/AssistantMarkdown.js.map +1 -0
  11. package/lib/features/chat/ChatCodeBlock.js +94 -0
  12. package/lib/features/chat/ChatCodeBlock.js.map +1 -0
  13. package/lib/features/chat/ChatTranscript.js +8 -91
  14. package/lib/features/chat/ChatTranscript.js.map +1 -1
  15. package/lib/features/chat/emptyChatResponse.js +7 -0
  16. package/lib/features/chat/emptyChatResponse.js.map +1 -0
  17. package/lib/features/chat/preResponse.js +23 -0
  18. package/lib/features/chat/preResponse.js.map +1 -0
  19. package/lib/features/chat/streamingMarkdown.js +125 -1
  20. package/lib/features/chat/streamingMarkdown.js.map +1 -1
  21. package/lib/features/chat/toolActivity.js +19 -9
  22. package/lib/features/chat/toolActivity.js.map +1 -1
  23. package/lib/hooks/useCdecliChannel.js +118 -51
  24. package/lib/hooks/useCdecliChannel.js.map +1 -1
  25. package/lib/hooks/useChatApi.js +152 -48
  26. package/lib/hooks/useChatApi.js.map +1 -1
  27. package/lib/hooks/useChatStream.js +31 -10
  28. package/lib/hooks/useChatStream.js.map +1 -1
  29. package/lib/hooks/useLiveThinkingLabel.js +22 -0
  30. package/lib/hooks/useLiveThinkingLabel.js.map +1 -0
  31. package/lib/index.js +1 -1
  32. package/lib/index.js.map +1 -1
  33. package/lib/screens/Chat/index.js +36 -47
  34. package/lib/screens/Chat/index.js.map +1 -1
  35. package/lib/screens/Home/components/ChatHistoryLanding.js +78 -23
  36. package/lib/screens/Home/components/ChatHistoryLanding.js.map +1 -1
  37. package/package.json +4 -4
@@ -1,4 +1,4 @@
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;
1
+ import {useApolloClient}from'@apollo/client/index.js';import {SortEnum,RoomType,PostTypeEnum,AiAgentMessageRole}from'common';import {useGetChannelsByUserWithLastMessageQuery,useMessagesQuery,MessagesDocument,useAddChannelMutation,useSendMessagesMutation,OnChatMessageAddedDocument,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;
@@ -42,7 +42,6 @@ const AI_ASSISTANT_CHANNELS_QUERY_VARS = {
42
42
  }
43
43
  };
44
44
  const HISTORY_PAGE_SIZE = 10;
45
- const HISTORY_TITLE_OVERLAY_LIMIT = 20;
46
45
  function getHistoryChannelsQueryVariables(orgName, options) {
47
46
  var _a, _b;
48
47
  const trimmedOrg = typeof orgName === "string" && orgName.trim().length > 0 ? orgName.trim() : void 0;
@@ -94,41 +93,91 @@ function getChatHistoryMessagesQueryVariables(accountUserId, options) {
94
93
  value: SortEnum.Desc
95
94
  },
96
95
  type: PostTypeEnum.Aiassistant,
97
- editedBy: accountUserId
96
+ editedBy: accountUserId,
97
+ props: {
98
+ role: "user"
99
+ }
98
100
  };
99
101
  }
102
+ function getHistoryChannelMessagesQueryVariables(channelId, options) {
103
+ var _a, _b;
104
+ return {
105
+ channelId,
106
+ limit: (_a = void 0 ) != null ? _a : HISTORY_PAGE_SIZE,
107
+ skip: (_b = void 0 ) != null ? _b : 0,
108
+ sort: {
109
+ key: "updatedAt",
110
+ value: SortEnum.Desc
111
+ },
112
+ type: PostTypeEnum.Aiassistant
113
+ };
114
+ }
115
+ function postChannelId(post) {
116
+ var _a;
117
+ if (((_a = post == null ? void 0 : post.channel) == null ? void 0 : _a.id) != null) return String(post.channel.id);
118
+ if (typeof (post == null ? void 0 : post.channel) === "string") return post.channel;
119
+ return "";
120
+ }
121
+ function postRole(post) {
122
+ var _a, _b, _c, _d, _e, _f;
123
+ const contents = (_c = coerceJsonObject((_a = post == null ? void 0 : post.propsConfiguration) == null ? void 0 : _a.contents)) != null ? _c : coerceJsonObject((_b = post == null ? void 0 : post.propsConfiguration) == null ? void 0 : _b.content);
124
+ return String((_f = (_e = (_d = post == null ? void 0 : post.props) == null ? void 0 : _d.role) != null ? _e : contents == null ? void 0 : contents.role) != null ? _f : "").toUpperCase();
125
+ }
100
126
  function chatHistorySessionsFromMessages(data) {
101
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
127
+ var _a, _b;
102
128
  const rows = (_a = data == null ? void 0 : data.messages) == null ? void 0 : _a.data;
103
129
  if (!(rows == null ? void 0 : rows.length)) return [];
104
- const seen = /* @__PURE__ */ new Set();
105
- const sessions = [];
130
+ const byChannel = /* @__PURE__ */ new Map();
106
131
  for (const post of rows) {
107
- const channelId = ((_b = post == null ? void 0 : post.channel) == null ? void 0 : _b.id) != null ? String(post.channel.id) : typeof (post == null ? void 0 : post.channel) === "string" ? post.channel : "";
108
- if (!channelId || seen.has(channelId)) continue;
109
- const rawTitle = String((_c = post == null ? void 0 : post.message) != null ? _c : "").replace(/\s+/g, " ").trim();
110
- const role = String((_k = (_j = (_g = (_d = post == null ? void 0 : post.props) == null ? void 0 : _d.role) != null ? _g : (_f = (_e = post == null ? void 0 : post.propsConfiguration) == null ? void 0 : _e.contents) == null ? void 0 : _f.role) != null ? _j : (_i = (_h = post == null ? void 0 : post.propsConfiguration) == null ? void 0 : _h.content) == null ? void 0 : _i.role) != null ? _k : "").toUpperCase();
111
- if (isTransientHistoryText(rawTitle) || looksLikeAssistantReply(rawTitle, role)) continue;
112
- seen.add(channelId);
132
+ const channelId = postChannelId(post);
133
+ if (!channelId) continue;
134
+ const raw = cleanMessageText(String((_b = post == null ? void 0 : post.message) != null ? _b : ""));
135
+ const role = postRole(post);
113
136
  const updatedAt = (post == null ? void 0 : post.updatedAt) ? new Date(post.updatedAt) : /* @__PURE__ */ new Date();
114
137
  const createdAt = (post == null ? void 0 : post.createdAt) ? new Date(post.createdAt) : updatedAt;
115
- const isAttachment = isAttachedCaption(rawTitle);
116
- const title = isAttachment ? historyAttachmentTitle(rawTitle) : rawTitle || "New chat";
138
+ if (!byChannel.has(channelId)) {
139
+ byChannel.set(channelId, {
140
+ title: "",
141
+ preview: "",
142
+ updatedAt,
143
+ createdAt,
144
+ isAttachment: false
145
+ });
146
+ }
147
+ const row = byChannel.get(channelId);
148
+ if (updatedAt.getTime() > row.updatedAt.getTime()) row.updatedAt = updatedAt;
149
+ const isUser = role === "USER" || !role && raw && !looksLikeAssistantReply(raw, role) && !isTransientHistoryText(raw);
150
+ if (isUser && !row.title && !isTransientHistoryText(raw)) {
151
+ const isAttachment = isAttachedCaption(raw);
152
+ row.title = isAttachment ? historyAttachmentTitle(raw) : raw;
153
+ row.isAttachment = isAttachment;
154
+ continue;
155
+ }
156
+ if (!row.preview && raw && (role === "ASSISTANT" || role === "AI" || role === "BOT" || role === "AGENT" || looksLikeAssistantReply(raw, role))) {
157
+ const preview = cleanHistoryPreview(raw);
158
+ if (preview && !isTransientHistoryText(preview) && preview !== row.title) {
159
+ row.preview = preview;
160
+ }
161
+ }
162
+ }
163
+ const sessions = [];
164
+ for (const [channelId, row] of byChannel) {
165
+ if (!row.title) continue;
117
166
  sessions.push({
118
167
  channelId,
119
- title,
120
- preview: "",
168
+ title: row.title,
169
+ preview: row.preview,
121
170
  mode: "chat",
122
- updatedAt,
123
- createdAt,
124
- isPlaceholder: !rawTitle && !isAttachment,
125
- isAttachment
171
+ updatedAt: row.updatedAt,
172
+ createdAt: row.createdAt,
173
+ isPlaceholder: false,
174
+ isAttachment: row.isAttachment
126
175
  });
127
176
  }
128
177
  return sessions;
129
178
  }
130
179
  function useChatHistorySessionsFromMessages(accountUserId, options) {
131
- var _a, _b, _c;
180
+ var _a, _b, _c, _d, _e;
132
181
  const skip = (options == null ? void 0 : options.skip) || !accountUserId;
133
182
  const {
134
183
  data,
@@ -136,13 +185,9 @@ function useChatHistorySessionsFromMessages(accountUserId, options) {
136
185
  error,
137
186
  refetch
138
187
  } = useMessagesQuery({
139
- variables: accountUserId ? getChatHistoryMessagesQueryVariables(accountUserId, {
140
- limit: HISTORY_TITLE_OVERLAY_LIMIT
141
- }) : void 0,
188
+ variables: accountUserId ? getChatHistoryMessagesQueryVariables(accountUserId) : void 0,
142
189
  skip,
143
- // cache-first + `messages` typePolicy (keyed by editedBy/type/props).
144
- // Later visits read the cache — no repeated network hit.
145
- fetchPolicy: "cache-first",
190
+ fetchPolicy: "cache-and-network",
146
191
  nextFetchPolicy: "cache-first",
147
192
  returnPartialData: true,
148
193
  context: {
@@ -151,33 +196,57 @@ function useChatHistorySessionsFromMessages(accountUserId, options) {
151
196
  });
152
197
  const sessions = useMemo(() => chatHistorySessionsFromMessages(data), [data]);
153
198
  const sourcePostCount = (_c = (_b = (_a = data == null ? void 0 : data.messages) == null ? void 0 : _a.data) == null ? void 0 : _b.length) != null ? _c : 0;
199
+ const totalCount = (_e = (_d = data == null ? void 0 : data.messages) == null ? void 0 : _d.totalCount) != null ? _e : 0;
154
200
  return {
155
201
  sessions,
156
202
  loading,
157
203
  error,
158
204
  refetch,
159
- sourcePostCount
205
+ sourcePostCount,
206
+ totalCount
160
207
  };
161
208
  }
209
+ function coerceJsonObject(value) {
210
+ if (!value) return null;
211
+ if (typeof value === "string") {
212
+ const trimmed = value.trim();
213
+ if (!trimmed) return null;
214
+ try {
215
+ const parsed = JSON.parse(trimmed);
216
+ return parsed && typeof parsed === "object" ? parsed : null;
217
+ } catch (e) {
218
+ return null;
219
+ }
220
+ }
221
+ if (typeof value === "object") return value;
222
+ return null;
223
+ }
224
+ function lastMessageContents(lastMessage) {
225
+ var _a;
226
+ const cfg = lastMessage == null ? void 0 : lastMessage.propsConfiguration;
227
+ return (_a = coerceJsonObject(cfg == null ? void 0 : cfg.contents)) != null ? _a : coerceJsonObject(cfg == null ? void 0 : cfg.content);
228
+ }
162
229
  function getLastMessageRole(lastMessage) {
163
- var _a, _b, _c, _d, _e, _f, _g, _h;
164
- return String((_h = (_g = (_e = (_b = (_a = lastMessage == null ? void 0 : lastMessage.propsConfiguration) == null ? void 0 : _a.contents) == null ? void 0 : _b.role) != null ? _e : (_d = (_c = lastMessage == null ? void 0 : lastMessage.propsConfiguration) == null ? void 0 : _c.content) == null ? void 0 : _d.role) != null ? _g : (_f = lastMessage == null ? void 0 : lastMessage.props) == null ? void 0 : _f.role) != null ? _h : "").toUpperCase();
230
+ var _a, _b, _c;
231
+ const contents = lastMessageContents(lastMessage);
232
+ return String((_c = (_b = contents == null ? void 0 : contents.role) != null ? _b : (_a = lastMessage == null ? void 0 : lastMessage.props) == null ? void 0 : _a.role) != null ? _c : "").toUpperCase();
165
233
  }
166
234
  function getParentUserPrompt(lastMessage) {
167
- var _a, _b, _c;
168
- const parent = (_b = (_a = lastMessage == null ? void 0 : lastMessage.propsConfiguration) == null ? void 0 : _a.contents) == null ? void 0 : _b.parent;
169
- if (!parent) return "";
170
- return String((_c = parent == null ? void 0 : parent.message) != null ? _c : "").trim();
235
+ var _a;
236
+ const contents = lastMessageContents(lastMessage);
237
+ const parent = contents == null ? void 0 : contents.parent;
238
+ if (!parent || typeof parent === "string") return "";
239
+ return String((_a = parent == null ? void 0 : parent.message) != null ? _a : "").trim();
171
240
  }
172
241
  function isBuildLastMessage(lastMessage) {
173
- var _a, _b, _c, _d, _e, _f, _g, _h;
242
+ var _a, _b, _c, _d;
174
243
  if (!lastMessage) return false;
175
- const contents = (_a = lastMessage.propsConfiguration) == null ? void 0 : _a.contents;
176
- const mode = String((_g = (_f = (_d = contents == null ? void 0 : contents.mode) != null ? _d : (_c = (_b = lastMessage.propsConfiguration) == null ? void 0 : _b.content) == null ? void 0 : _c.mode) != null ? _f : (_e = lastMessage == null ? void 0 : lastMessage.props) == null ? void 0 : _e.mode) != null ? _g : "").toLowerCase();
244
+ const contents = lastMessageContents(lastMessage);
245
+ const mode = String((_c = (_b = contents == null ? void 0 : contents.mode) != null ? _b : (_a = lastMessage == null ? void 0 : lastMessage.props) == null ? void 0 : _a.mode) != null ? _c : "").toLowerCase();
177
246
  if (mode === "build" || mode === "workflow") return true;
178
247
  const fragment = contents == null ? void 0 : contents.fragment;
179
248
  if ((fragment == null ? void 0 : fragment.sandboxUrl) || (fragment == null ? void 0 : fragment.sandboxId)) return true;
180
- if (String((_h = contents == null ? void 0 : contents.template) != null ? _h : "").trim()) return true;
249
+ if (String((_d = contents == null ? void 0 : contents.template) != null ? _d : "").trim()) return true;
181
250
  return false;
182
251
  }
183
252
  function detectMode(channel) {
@@ -224,7 +293,7 @@ function looksLikeAssistantReply(text, role) {
224
293
  if (role === "USER") return false;
225
294
  const t = text.trim();
226
295
  if (/^(let me |i'll |i will |sure[,.] |here's |here is )/i.test(t)) return true;
227
- if (t.length > 180) return true;
296
+ if (!role && t.length > 180) return true;
228
297
  return false;
229
298
  }
230
299
  function cleanHistoryPreview(raw) {
@@ -316,7 +385,9 @@ function mergeRememberedHistory(channelId, patch, notify = true) {
316
385
  };
317
386
  rememberedHistoryTitles.set(channelId, next);
318
387
  if (notify && (next.title !== existing.title || next.preview !== existing.preview || next.running !== existing.running)) {
319
- rememberedHistoryListeners.forEach((fn) => fn());
388
+ queueMicrotask(() => {
389
+ rememberedHistoryListeners.forEach((fn) => fn());
390
+ });
320
391
  }
321
392
  return next;
322
393
  }
@@ -474,6 +545,43 @@ function enrichHistorySessionsWithUserPrompts(fromChannels, fromMessages) {
474
545
  }
475
546
  return applyRememberedHistoryTitles(merged);
476
547
  }
548
+ function seedRememberedHistoryFromSessions(sessions) {
549
+ if (!(sessions == null ? void 0 : sessions.length)) return;
550
+ for (const session of sessions) rememberHistoryTitle(session);
551
+ }
552
+ async function fetchHistorySessionsForChannels(client, channelIds) {
553
+ const unique = [...new Set(channelIds.map((id) => String(id || "").trim()).filter(Boolean))];
554
+ if (!unique.length) return [];
555
+ const pages = await Promise.all(unique.map(async (channelId) => {
556
+ var _a, _b, _c;
557
+ try {
558
+ const result = await client.query({
559
+ query: MessagesDocument,
560
+ variables: getHistoryChannelMessagesQueryVariables(channelId),
561
+ fetchPolicy: "network-only",
562
+ context: {
563
+ cacheKey: "chat-history-channel-messages"
564
+ }
565
+ });
566
+ const posts = ((_c = (_b = (_a = result.data) == null ? void 0 : _a.messages) == null ? void 0 : _b.data) != null ? _c : []).map((post) => {
567
+ var _a2;
568
+ return __spreadProps(__spreadValues({}, post), {
569
+ channel: ((_a2 = post == null ? void 0 : post.channel) == null ? void 0 : _a2.id) ? post.channel : {
570
+ id: channelId
571
+ }
572
+ });
573
+ });
574
+ return chatHistorySessionsFromMessages({
575
+ messages: {
576
+ data: posts
577
+ }
578
+ });
579
+ } catch (e) {
580
+ return [];
581
+ }
582
+ }));
583
+ return pages.flat();
584
+ }
477
585
  function useChatHistorySessionsFromChannels(orgName, options) {
478
586
  var _a, _b;
479
587
  const skip = (options == null ? void 0 : options.skip) || !orgName;
@@ -486,11 +594,7 @@ function useChatHistorySessionsFromChannels(orgName, options) {
486
594
  } = useGetChannelsByUserWithLastMessageQuery({
487
595
  variables,
488
596
  skip,
489
- // cache-first + `channelsByUser` typePolicy (keyArgs drop skip/limit/sort).
490
- // Later navigations read the canonical list from cache — no repeated
491
- // GetChannelsByUserWithLastMessage. Freshness comes from pull-to-refresh
492
- // / createChannel cache writes, not per-visit network hits.
493
- fetchPolicy: "cache-first",
597
+ fetchPolicy: "cache-and-network",
494
598
  nextFetchPolicy: "cache-first",
495
599
  returnPartialData: true,
496
600
  context: {
@@ -708,8 +812,8 @@ function useChatMessages(sessionId, options) {
708
812
  const rows = (_b = (_a = data == null ? void 0 : data.messages) == null ? void 0 : _a.data) != null ? _b : [];
709
813
  const ownRows = rows.filter((post) => {
710
814
  var _a2;
711
- const postChannelId = (_a2 = post == null ? void 0 : post.channel) == null ? void 0 : _a2.id;
712
- return !postChannelId || postChannelId === sessionId;
815
+ const postChannelId2 = (_a2 = post == null ? void 0 : post.channel) == null ? void 0 : _a2.id;
816
+ return !postChannelId2 || postChannelId2 === sessionId;
713
817
  });
714
818
  return flattenPostsWithReplies(ownRows, sessionId);
715
819
  }, [data, sessionId]);
@@ -983,4 +1087,4 @@ function useChatMutations() {
983
1087
  saveMessages: sendMessagesLoading
984
1088
  }
985
1089
  };
986
- }export{AI_ASSISTANT_CHANNELS_QUERY_VARS,HISTORY_PAGE_SIZE,HISTORY_QUERY_BASE,buildSessionFromChannel,chatHistorySessionsFromChannels,chatHistorySessionsFromMessages,clearChannelHistoryRunning,enrichHistorySessionsWithUserPrompts,getChatHistoryChannelRefetchQueries,getChatHistoryMessagesQueryVariables,getHistoryChannelsQueryVariables,markChannelHistoryRunning,patchChannelHistoryPreview,patchChannelHistoryTitle,subscribeRememberedHistory,touchChannelHistoryUpdatedAt,useChatHistorySessionsFromChannels,useChatHistorySessionsFromMessages,useChatMessages,useChatMutations,usePrefetchChatHistory};//# sourceMappingURL=useChatApi.js.map
1090
+ }export{AI_ASSISTANT_CHANNELS_QUERY_VARS,HISTORY_PAGE_SIZE,HISTORY_QUERY_BASE,buildSessionFromChannel,chatHistorySessionsFromChannels,chatHistorySessionsFromMessages,clearChannelHistoryRunning,enrichHistorySessionsWithUserPrompts,fetchHistorySessionsForChannels,getChatHistoryChannelRefetchQueries,getChatHistoryMessagesQueryVariables,getHistoryChannelMessagesQueryVariables,getHistoryChannelsQueryVariables,markChannelHistoryRunning,patchChannelHistoryPreview,patchChannelHistoryTitle,seedRememberedHistoryFromSessions,subscribeRememberedHistory,touchChannelHistoryUpdatedAt,useChatHistorySessionsFromChannels,useChatHistorySessionsFromMessages,useChatMessages,useChatMutations,usePrefetchChatHistory};//# sourceMappingURL=useChatApi.js.map