@meetsmore-oss/use-ai-client 1.12.0 → 1.12.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/bundled.js CHANGED
@@ -1557,7 +1557,17 @@ function getTextFromContent(content3) {
1557
1557
  if (typeof content3 === "string") {
1558
1558
  return content3;
1559
1559
  }
1560
- return content3.filter((part) => part.type === "text").map((part) => part.text).join("\n");
1560
+ return content3.flatMap((part) => {
1561
+ if (part.type === "text") return [part.text];
1562
+ if (part.type === "transformed_file") return [part.text];
1563
+ return [];
1564
+ }).join("\n");
1565
+ }
1566
+ function getDisplayTextFromContent(content3) {
1567
+ if (typeof content3 === "string") {
1568
+ return content3;
1569
+ }
1570
+ return content3.flatMap((part) => part.type === "text" ? [part.text] : []).join("\n");
1561
1571
  }
1562
1572
 
1563
1573
  // src/utils/mergeAssistantMessages.ts
@@ -14841,7 +14851,7 @@ function UseAIChatPanel({
14841
14851
  if (displayMessages.length > 0) {
14842
14852
  const firstUserMsg = displayMessages.find((m) => m.role === "user");
14843
14853
  if (firstUserMsg) {
14844
- const textContent = getTextFromContent(firstUserMsg.content);
14854
+ const textContent = getDisplayTextFromContent(firstUserMsg.content);
14845
14855
  const maxLength = 30;
14846
14856
  return textContent.length > maxLength ? textContent.substring(0, maxLength) + "..." : textContent || strings.header.newChat;
14847
14857
  }
@@ -15147,7 +15157,7 @@ function UseAIChatPanel({
15147
15157
  {
15148
15158
  style: {
15149
15159
  display: "grid",
15150
- gridTemplateColumns: "repeat(2, 1fr)",
15160
+ gridTemplateColumns: "1fr",
15151
15161
  gap: "8px",
15152
15162
  width: "100%",
15153
15163
  maxWidth: "320px"
@@ -15223,7 +15233,7 @@ function UseAIChatPanel({
15223
15233
  "data-testid": "save-command-button",
15224
15234
  onClick: (e) => {
15225
15235
  e.stopPropagation();
15226
- const messageText = getTextFromContent(message.content);
15236
+ const messageText = getDisplayTextFromContent(message.content);
15227
15237
  slashCommands.startSavingCommand(message.id, messageText);
15228
15238
  },
15229
15239
  title: "Save as slash command",
@@ -15293,13 +15303,17 @@ function UseAIChatPanel({
15293
15303
  }
15294
15304
  ),
15295
15305
  /* @__PURE__ */ jsx12(MarkdownContent, { content: getTextFromContent(message.content) })
15296
- ] }) : getTextFromContent(message.content)
15306
+ ] }) : (
15307
+ // User/tool bubbles: display-only text so transformed_file
15308
+ // (e.g. OCR body) isn't dumped into the chat bubble.
15309
+ getDisplayTextFromContent(message.content)
15310
+ )
15297
15311
  ]
15298
15312
  }
15299
15313
  ),
15300
15314
  slashCommands.renderInlineSaveUI({
15301
15315
  messageId: message.id,
15302
- messageText: getTextFromContent(message.content)
15316
+ messageText: getDisplayTextFromContent(message.content)
15303
15317
  })
15304
15318
  ]
15305
15319
  }
@@ -38268,35 +38282,89 @@ var LocalStorageChatRepository = class {
38268
38282
  }
38269
38283
  };
38270
38284
 
38285
+ // src/fileUpload/buildPersistedParts.ts
38286
+ function buildPersistedParts(message, attachments, fileContent) {
38287
+ const parts2 = [];
38288
+ if (message.trim()) {
38289
+ parts2.push({ type: "text", text: message });
38290
+ }
38291
+ const transformedByKey = /* @__PURE__ */ new Map();
38292
+ for (const part of fileContent) {
38293
+ if (part.type === "transformed_file") {
38294
+ const key = `${part.originalFile.name}:${part.originalFile.size}:${part.originalFile.mimeType}`;
38295
+ const list3 = transformedByKey.get(key);
38296
+ if (list3) {
38297
+ list3.push(part);
38298
+ } else {
38299
+ transformedByKey.set(key, [part]);
38300
+ }
38301
+ }
38302
+ }
38303
+ for (const attachment of attachments) {
38304
+ const key = `${attachment.file.name}:${attachment.file.size}:${attachment.file.type}`;
38305
+ const transformed = transformedByKey.get(key)?.shift();
38306
+ if (transformed) {
38307
+ parts2.push({
38308
+ type: "transformed_file",
38309
+ text: transformed.text,
38310
+ originalFile: transformed.originalFile
38311
+ });
38312
+ } else {
38313
+ parts2.push({
38314
+ type: "file",
38315
+ file: {
38316
+ name: attachment.file.name,
38317
+ size: attachment.file.size,
38318
+ mimeType: attachment.file.type
38319
+ }
38320
+ });
38321
+ }
38322
+ }
38323
+ return parts2;
38324
+ }
38325
+
38271
38326
  // src/hooks/useChatManagement.ts
38272
38327
  import { useState as useState7, useCallback as useCallback5, useRef as useRef5, useEffect as useEffect5 } from "react";
38273
38328
 
38274
38329
  // src/utils/messageConversion.ts
38275
38330
  function transformMessagesToClientFormat(persistedMessages) {
38276
38331
  return persistedMessages.map((msg) => {
38277
- const textContent = getTextFromContent(msg.content);
38278
38332
  switch (msg.role) {
38279
38333
  case "tool":
38280
38334
  return {
38281
38335
  id: msg.id,
38282
38336
  role: "tool",
38283
- content: textContent,
38337
+ content: getTextFromContent(msg.content),
38284
38338
  toolCallId: msg.toolCallId || ""
38285
38339
  };
38286
38340
  case "assistant":
38287
38341
  return {
38288
38342
  id: msg.id,
38289
38343
  role: "assistant",
38290
- content: textContent,
38344
+ content: getTextFromContent(msg.content),
38291
38345
  ...msg.toolCalls && msg.toolCalls.length > 0 ? { toolCalls: msg.toolCalls } : {},
38292
38346
  ...msg.reasoningParts && msg.reasoningParts.length > 0 ? { reasoningParts: msg.reasoningParts } : {}
38293
38347
  };
38294
- case "user":
38295
- return {
38296
- id: msg.id,
38297
- role: "user",
38298
- content: textContent
38299
- };
38348
+ case "user": {
38349
+ if (typeof msg.content === "string") {
38350
+ return { id: msg.id, role: "user", content: msg.content };
38351
+ }
38352
+ const parts2 = msg.content.flatMap((p) => {
38353
+ if (p.type === "text") {
38354
+ return [{ type: "text", text: p.text }];
38355
+ }
38356
+ if (p.type === "transformed_file") {
38357
+ return [{
38358
+ type: "text",
38359
+ text: `[Content of file "${p.originalFile.name}" (${p.originalFile.mimeType})]:
38360
+
38361
+ ${p.text}`
38362
+ }];
38363
+ }
38364
+ return [];
38365
+ });
38366
+ return { id: msg.id, role: "user", content: parts2 };
38367
+ }
38300
38368
  }
38301
38369
  });
38302
38370
  }
@@ -38469,7 +38537,7 @@ function useChatManagement({
38469
38537
  };
38470
38538
  chat.messages.push(newMessage);
38471
38539
  if (!chat.title) {
38472
- const text5 = getTextFromContent(content3);
38540
+ const text5 = getDisplayTextFromContent(content3);
38473
38541
  if (text5) {
38474
38542
  chat.title = generateChatTitle(text5);
38475
38543
  }
@@ -38513,7 +38581,7 @@ function useChatManagement({
38513
38581
  if (!chat.title) {
38514
38582
  const firstUserMessage = chat.messages.find((msg) => msg.role === "user");
38515
38583
  if (firstUserMessage) {
38516
- const textContent = getTextFromContent(firstUserMessage.content);
38584
+ const textContent = getDisplayTextFromContent(firstUserMessage.content);
38517
38585
  if (textContent) {
38518
38586
  chat.title = generateChatTitle(textContent);
38519
38587
  }
@@ -39616,27 +39684,10 @@ function UseAIProvider({
39616
39684
  let persistedContent = message;
39617
39685
  let multimodalContent;
39618
39686
  if (attachments && attachments.length > 0) {
39619
- const persistedParts = [];
39620
- if (message.trim()) {
39621
- persistedParts.push({ type: "text", text: message });
39622
- }
39623
- for (const attachment of attachments) {
39624
- persistedParts.push({
39625
- type: "file",
39626
- file: {
39627
- name: attachment.file.name,
39628
- size: attachment.file.size,
39629
- mimeType: attachment.file.type
39630
- }
39631
- });
39632
- }
39633
- persistedContent = persistedParts;
39634
- if (activeChatId) {
39635
- await chatManagement.saveUserMessage(activeChatId, persistedContent);
39636
- }
39637
39687
  serverEvents.setLoading(true);
39688
+ let fileContent;
39638
39689
  try {
39639
- const fileContent = await processAttachments(attachments, {
39690
+ fileContent = await processAttachments(attachments, {
39640
39691
  getCurrentChat: chatManagement.getCurrentChat,
39641
39692
  backend: fileUploadConfig?.backend,
39642
39693
  transformers: fileUploadConfig?.transformers,
@@ -39644,17 +39695,21 @@ function UseAIProvider({
39644
39695
  setFileProcessingState(state);
39645
39696
  }
39646
39697
  });
39647
- multimodalContent = [];
39648
- if (message.trim()) {
39649
- multimodalContent.push({ type: "text", text: message });
39650
- }
39651
- multimodalContent.push(...fileContent);
39652
39698
  } catch (error48) {
39653
39699
  serverEvents.setLoading(false);
39654
39700
  throw error48;
39655
39701
  } finally {
39656
39702
  setFileProcessingState(null);
39657
39703
  }
39704
+ persistedContent = buildPersistedParts(message, attachments, fileContent);
39705
+ if (activeChatId) {
39706
+ await chatManagement.saveUserMessage(activeChatId, persistedContent);
39707
+ }
39708
+ multimodalContent = [];
39709
+ if (message.trim()) {
39710
+ multimodalContent.push({ type: "text", text: message });
39711
+ }
39712
+ multimodalContent.push(...fileContent);
39658
39713
  } else {
39659
39714
  if (activeChatId) {
39660
39715
  await chatManagement.saveUserMessage(activeChatId, persistedContent);