@meetsmore-oss/use-ai-client 1.11.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
  }
@@ -23799,6 +23813,11 @@ var UseAIClient = class {
23799
23813
  if (e.subtype === "message" && this._currentReasoningBlocks.length > 0) {
23800
23814
  const lastBlock = this._currentReasoningBlocks[this._currentReasoningBlocks.length - 1];
23801
23815
  lastBlock.encryptedValue = e.encryptedValue;
23816
+ } else if (e.subtype === "tool-call" && e.entityId) {
23817
+ const tc = this._currentAssistantToolCalls.find((tc2) => tc2.id === e.entityId);
23818
+ if (tc) {
23819
+ tc.encryptedValue = e.encryptedValue;
23820
+ }
23802
23821
  }
23803
23822
  } else if (event.type === EventType.TOOL_CALL_RESULT) {
23804
23823
  const e = event;
@@ -38263,35 +38282,89 @@ var LocalStorageChatRepository = class {
38263
38282
  }
38264
38283
  };
38265
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
+
38266
38326
  // src/hooks/useChatManagement.ts
38267
38327
  import { useState as useState7, useCallback as useCallback5, useRef as useRef5, useEffect as useEffect5 } from "react";
38268
38328
 
38269
38329
  // src/utils/messageConversion.ts
38270
38330
  function transformMessagesToClientFormat(persistedMessages) {
38271
38331
  return persistedMessages.map((msg) => {
38272
- const textContent = getTextFromContent(msg.content);
38273
38332
  switch (msg.role) {
38274
38333
  case "tool":
38275
38334
  return {
38276
38335
  id: msg.id,
38277
38336
  role: "tool",
38278
- content: textContent,
38337
+ content: getTextFromContent(msg.content),
38279
38338
  toolCallId: msg.toolCallId || ""
38280
38339
  };
38281
38340
  case "assistant":
38282
38341
  return {
38283
38342
  id: msg.id,
38284
38343
  role: "assistant",
38285
- content: textContent,
38344
+ content: getTextFromContent(msg.content),
38286
38345
  ...msg.toolCalls && msg.toolCalls.length > 0 ? { toolCalls: msg.toolCalls } : {},
38287
38346
  ...msg.reasoningParts && msg.reasoningParts.length > 0 ? { reasoningParts: msg.reasoningParts } : {}
38288
38347
  };
38289
- case "user":
38290
- return {
38291
- id: msg.id,
38292
- role: "user",
38293
- content: textContent
38294
- };
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
+ }
38295
38368
  }
38296
38369
  });
38297
38370
  }
@@ -38464,7 +38537,7 @@ function useChatManagement({
38464
38537
  };
38465
38538
  chat.messages.push(newMessage);
38466
38539
  if (!chat.title) {
38467
- const text5 = getTextFromContent(content3);
38540
+ const text5 = getDisplayTextFromContent(content3);
38468
38541
  if (text5) {
38469
38542
  chat.title = generateChatTitle(text5);
38470
38543
  }
@@ -38508,7 +38581,7 @@ function useChatManagement({
38508
38581
  if (!chat.title) {
38509
38582
  const firstUserMessage = chat.messages.find((msg) => msg.role === "user");
38510
38583
  if (firstUserMessage) {
38511
- const textContent = getTextFromContent(firstUserMessage.content);
38584
+ const textContent = getDisplayTextFromContent(firstUserMessage.content);
38512
38585
  if (textContent) {
38513
38586
  chat.title = generateChatTitle(textContent);
38514
38587
  }
@@ -39611,27 +39684,10 @@ function UseAIProvider({
39611
39684
  let persistedContent = message;
39612
39685
  let multimodalContent;
39613
39686
  if (attachments && attachments.length > 0) {
39614
- const persistedParts = [];
39615
- if (message.trim()) {
39616
- persistedParts.push({ type: "text", text: message });
39617
- }
39618
- for (const attachment of attachments) {
39619
- persistedParts.push({
39620
- type: "file",
39621
- file: {
39622
- name: attachment.file.name,
39623
- size: attachment.file.size,
39624
- mimeType: attachment.file.type
39625
- }
39626
- });
39627
- }
39628
- persistedContent = persistedParts;
39629
- if (activeChatId) {
39630
- await chatManagement.saveUserMessage(activeChatId, persistedContent);
39631
- }
39632
39687
  serverEvents.setLoading(true);
39688
+ let fileContent;
39633
39689
  try {
39634
- const fileContent = await processAttachments(attachments, {
39690
+ fileContent = await processAttachments(attachments, {
39635
39691
  getCurrentChat: chatManagement.getCurrentChat,
39636
39692
  backend: fileUploadConfig?.backend,
39637
39693
  transformers: fileUploadConfig?.transformers,
@@ -39639,17 +39695,21 @@ function UseAIProvider({
39639
39695
  setFileProcessingState(state);
39640
39696
  }
39641
39697
  });
39642
- multimodalContent = [];
39643
- if (message.trim()) {
39644
- multimodalContent.push({ type: "text", text: message });
39645
- }
39646
- multimodalContent.push(...fileContent);
39647
39698
  } catch (error48) {
39648
39699
  serverEvents.setLoading(false);
39649
39700
  throw error48;
39650
39701
  } finally {
39651
39702
  setFileProcessingState(null);
39652
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);
39653
39713
  } else {
39654
39714
  if (activeChatId) {
39655
39715
  await chatManagement.saveUserMessage(activeChatId, persistedContent);