@anuma/sdk 6.26.0 → 6.26.2

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/index.mjs CHANGED
@@ -2860,6 +2860,46 @@ async function decryptField(value, address) {
2860
2860
  return result.value;
2861
2861
  }
2862
2862
 
2863
+ // src/lib/chat/fileContext.ts
2864
+ var ATTACHED_FILES_OPEN_TAG = "<attached_files>";
2865
+ var ATTACHED_FILES_CLOSE_TAG = "</attached_files>";
2866
+ var ATTACHED_FILES_PREFIX = `${ATTACHED_FILES_OPEN_TAG}
2867
+ The user attached the following file(s) to this message. Their extracted contents are below; when the user refers to "the attached file", "this file" or "the document", they mean these.`;
2868
+ function isAttachedFilesText(text) {
2869
+ return typeof text === "string" && text.startsWith(ATTACHED_FILES_PREFIX) && text.endsWith(ATTACHED_FILES_CLOSE_TAG);
2870
+ }
2871
+ function buildAttachedFilesText(fileContext) {
2872
+ return `${ATTACHED_FILES_PREFIX}
2873
+
2874
+ ${fileContext}
2875
+ ${ATTACHED_FILES_CLOSE_TAG}`;
2876
+ }
2877
+ function attachFileContextToLastUserMessage(messages, fileContext) {
2878
+ if (!fileContext.trim()) return messages;
2879
+ let lastUserIndex = -1;
2880
+ for (let i = messages.length - 1; i >= 0; i--) {
2881
+ if (messages[i].role === "user") {
2882
+ lastUserIndex = i;
2883
+ break;
2884
+ }
2885
+ }
2886
+ if (lastUserIndex === -1) return messages;
2887
+ const message = messages[lastUserIndex];
2888
+ const existing = message.content ?? [];
2889
+ let insertAt = 0;
2890
+ existing.forEach((part, index) => {
2891
+ if (part.type === "text") insertAt = index + 1;
2892
+ });
2893
+ const filePart = {
2894
+ type: "text",
2895
+ text: buildAttachedFilesText(fileContext)
2896
+ };
2897
+ const content = [...existing.slice(0, insertAt), filePart, ...existing.slice(insertAt)];
2898
+ const result = [...messages];
2899
+ result[lastUserIndex] = { ...message, content };
2900
+ return result;
2901
+ }
2902
+
2863
2903
  // src/lib/chat/useChat/strategies/types.ts
2864
2904
  function isChatCompletionResponse(r) {
2865
2905
  if (r.object === "response") return false;
@@ -2946,6 +2986,26 @@ function cosineInt8(a, scaleA, b, scaleB) {
2946
2986
  return sim > 1 ? 1 : sim < -1 ? -1 : sim;
2947
2987
  }
2948
2988
 
2989
+ // src/lib/processors/fileStatusNotes.ts
2990
+ var DEFAULT_MAX_FILE_SIZE_BYTES = 10 * 1024 * 1024;
2991
+ function formatMegabytes(bytes) {
2992
+ const mb = bytes / (1024 * 1024);
2993
+ return `${Number.isInteger(mb) ? mb : mb.toFixed(1)} MB`;
2994
+ }
2995
+ function formatFileProcessingNotes(statuses, options = {}) {
2996
+ const maxFileSizeBytes = options.maxFileSizeBytes ?? DEFAULT_MAX_FILE_SIZE_BYTES;
2997
+ const why = {
2998
+ too_large: `the file is larger than ${formatMegabytes(maxFileSizeBytes)}`,
2999
+ unsupported_type: "its file type is not supported for reading",
3000
+ no_data: "its contents were not available to the app",
3001
+ empty: "no text or images could be extracted from it (it may be blank)",
3002
+ timeout: "reading it took too long and was stopped",
3003
+ error: "its text could not be extracted (it may be password-protected or damaged)"
3004
+ };
3005
+ const lines = statuses.filter((s) => s.status === "skipped" || s.status === "failed").map((s) => `[${s.fileName} could not be read: ${why[s.reason ?? "error"]}]`);
3006
+ return lines.length > 0 ? lines.join("\n") : null;
3007
+ }
3008
+
2949
3009
  // src/lib/db/chat/lazyDecrypt.ts
2950
3010
  var LRU_CAPACITY = 256;
2951
3011
  var titleCache = /* @__PURE__ */ new Map();
@@ -3677,6 +3737,8 @@ export {
3677
3737
  activatedToolSetNames,
3678
3738
  analyzeStyle,
3679
3739
  applyToolSets,
3740
+ attachFileContextToLastUserMessage,
3741
+ buildAttachedFilesText,
3680
3742
  buildConnectorGuidance,
3681
3743
  buildDeniedToolsRider,
3682
3744
  buildSystemPrompt,
@@ -3702,6 +3764,7 @@ export {
3702
3764
  dequantizeEmbedding,
3703
3765
  encodeChunkVector,
3704
3766
  expandToolSetsAdditive,
3767
+ formatFileProcessingNotes,
3705
3768
  getApiV1AdminApps,
3706
3769
  getApiV1AdminAppsByAppIdApiKeys,
3707
3770
  getApiV1AdminAppsByAppIdApiKeysById,
@@ -3741,6 +3804,7 @@ export {
3741
3804
  getImageModel,
3742
3805
  getLogger,
3743
3806
  getToolCallEvents,
3807
+ isAttachedFilesText,
3744
3808
  isPiiRedactor,
3745
3809
  noopLogger,
3746
3810
  patchApiV1DeveloperAppsByAppUuid,