@anuma/sdk 2.7.0 → 3.1.0

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.
@@ -22,7 +22,6 @@ import {
22
22
  createConversationOp,
23
23
  createMemoryVaultSearchTool,
24
24
  createMessageOp,
25
- createSseClient,
26
25
  createSupersedingMemoryOp,
27
26
  createVaultEmbeddingCache,
28
27
  createVaultMemoriesBatchOp,
@@ -30,6 +29,7 @@ import {
30
29
  decryptData,
31
30
  decryptDataBatch,
32
31
  decryptDataBytes,
32
+ decryptDataBytesFromBytes,
33
33
  decryptDataWithKey,
34
34
  decryptField,
35
35
  decryptJsonField,
@@ -41,6 +41,7 @@ import {
41
41
  embedMessage,
42
42
  encryptData,
43
43
  encryptDataBatch,
44
+ encryptDataBytes,
44
45
  encryptDataWithKey,
45
46
  encryptField,
46
47
  encryptJsonField,
@@ -56,6 +57,7 @@ import {
56
57
  getConversationsByProjectOp,
57
58
  getConversationsLazyOp,
58
59
  getConversationsOp,
60
+ getConversationsPageOp,
59
61
  getEncryptionKey,
60
62
  getMemoriesNeedingTopicExtractionOp,
61
63
  getMessagesOp,
@@ -105,7 +107,7 @@ import {
105
107
  updateVaultMemoryOp,
106
108
  upsertMessageOp,
107
109
  vaultMemoryToStored
108
- } from "./chunk-Z6II54I7.mjs";
110
+ } from "./chunk-RKUNGNBF.mjs";
109
111
  import {
110
112
  createStreamingDeAnonymizer,
111
113
  resolvePiiRedactor
@@ -5498,9 +5500,11 @@ function createChunkVectorCache(maxSize = DEFAULT_CHUNK_CACHE_SIZE) {
5498
5500
  return new LRUCache(maxSize);
5499
5501
  }
5500
5502
 
5501
- // src/lib/memory/recallTool.ts
5503
+ // src/lib/memory/recallConstants.ts
5502
5504
  var RECALL_TOOL_NAME = "recall_memory";
5503
5505
  var RECALL_MAX_LIMIT = 50;
5506
+
5507
+ // src/lib/memory/recallTool.ts
5504
5508
  var DEFAULT_LIMIT = 8;
5505
5509
  var DEFAULT_BUDGET = "low";
5506
5510
  function formatEventTime(start, end, kind) {
@@ -6059,7 +6063,7 @@ function getCachedServerTools() {
6059
6063
  if (!cached) return null;
6060
6064
  const parsed = JSON.parse(cached);
6061
6065
  if (parsed.version !== CACHE_VERSION) {
6062
- clearServerToolsCache();
6066
+ removeLocalStorageCache();
6063
6067
  return null;
6064
6068
  }
6065
6069
  return parsed;
@@ -6071,37 +6075,45 @@ function isCacheExpired(cache, expirationMs = DEFAULT_CACHE_EXPIRATION_MS) {
6071
6075
  if (!cache) return true;
6072
6076
  return Date.now() - cache.timestamp > expirationMs;
6073
6077
  }
6074
- function cacheServerTools(tools, checksum) {
6075
- if (typeof localStorage === "undefined") return;
6076
- const cacheData = {
6078
+ function buildCacheEntry(tools, checksum) {
6079
+ return {
6077
6080
  tools,
6078
6081
  timestamp: Date.now(),
6079
6082
  version: CACHE_VERSION,
6080
6083
  ...checksum && { checksum }
6081
6084
  };
6085
+ }
6086
+ function writeLocalStorageCache(entry) {
6087
+ if (typeof localStorage === "undefined") return;
6082
6088
  try {
6083
- localStorage.setItem(SERVER_TOOLS_CACHE_KEY, JSON.stringify(cacheData));
6089
+ localStorage.setItem(SERVER_TOOLS_CACHE_KEY, JSON.stringify(entry));
6084
6090
  } catch (error) {
6085
6091
  getLogger().warn("[serverTools] Failed to cache tools:", error);
6086
6092
  }
6087
6093
  }
6088
- function clearServerToolsCache() {
6094
+ function removeLocalStorageCache() {
6089
6095
  if (typeof localStorage === "undefined") return;
6090
6096
  localStorage.removeItem(SERVER_TOOLS_CACHE_KEY);
6091
6097
  }
6092
- function getToolsChecksum() {
6093
- const cached = getCachedServerTools();
6094
- return cached?.checksum;
6098
+ var localStorageToolsCache = {
6099
+ get: getCachedServerTools,
6100
+ set: writeLocalStorageCache,
6101
+ clear: removeLocalStorageCache
6102
+ };
6103
+ function clearServerToolsCache(cache = localStorageToolsCache) {
6104
+ return cache.clear?.();
6105
+ }
6106
+ function getToolsChecksum(cache = localStorageToolsCache) {
6107
+ const cached = cache.get();
6108
+ return cached instanceof Promise ? cached.then((c) => c?.checksum) : cached?.checksum;
6095
6109
  }
6096
- function shouldRefreshTools(responseChecksum) {
6110
+ function shouldRefreshTools(responseChecksum, cache = localStorageToolsCache) {
6097
6111
  if (!responseChecksum) {
6098
6112
  return false;
6099
6113
  }
6100
- const cachedChecksum = getToolsChecksum();
6101
- if (!cachedChecksum) {
6102
- return true;
6103
- }
6104
- return cachedChecksum !== responseChecksum;
6114
+ const decide = (cachedChecksum2) => !cachedChecksum2 || cachedChecksum2 !== responseChecksum;
6115
+ const cachedChecksum = getToolsChecksum(cache);
6116
+ return cachedChecksum instanceof Promise ? cachedChecksum.then(decide) : decide(cachedChecksum);
6105
6117
  }
6106
6118
  async function fetchServerToolsFromApi(baseUrl, token) {
6107
6119
  const response = await fetch(`${baseUrl}/api/v1/tools`, {
@@ -6123,9 +6135,23 @@ async function getServerTools(options) {
6123
6135
  cacheExpirationMs = DEFAULT_CACHE_EXPIRATION_MS,
6124
6136
  forceRefresh = false,
6125
6137
  getToken,
6126
- apiKey
6138
+ apiKey,
6139
+ cache = localStorageToolsCache
6127
6140
  } = options;
6128
- const cached = getCachedServerTools();
6141
+ const persistCache = async (entry) => {
6142
+ try {
6143
+ await cache.set(entry);
6144
+ } catch (error) {
6145
+ getLogger().warn("[serverTools] Cache write failed (non-fatal):", error);
6146
+ }
6147
+ };
6148
+ let rawCached = null;
6149
+ try {
6150
+ rawCached = await cache.get();
6151
+ } catch (error) {
6152
+ getLogger().warn("[serverTools] Cache read failed; falling through to server fetch:", error);
6153
+ }
6154
+ const cached = rawCached && rawCached.version === CACHE_VERSION ? rawCached : null;
6129
6155
  const cacheValid = !isCacheExpired(cached, cacheExpirationMs);
6130
6156
  if (cached && cacheValid && !forceRefresh) {
6131
6157
  return cached.tools;
@@ -6146,7 +6172,7 @@ async function getServerTools(options) {
6146
6172
  }
6147
6173
  const data = await response.json();
6148
6174
  const { tools: tools2, checksum: checksum2 } = convertServerToolsResponse(data);
6149
- cacheServerTools(tools2, checksum2);
6175
+ await persistCache(buildCacheEntry(tools2, checksum2));
6150
6176
  return tools2;
6151
6177
  }
6152
6178
  if (!getToken) {
@@ -6159,7 +6185,7 @@ async function getServerTools(options) {
6159
6185
  return cached?.tools ?? [];
6160
6186
  }
6161
6187
  const { tools, checksum } = await fetchServerToolsFromApi(effectiveBaseUrl, token);
6162
- cacheServerTools(tools, checksum);
6188
+ await persistCache(buildCacheEntry(tools, checksum));
6163
6189
  return tools;
6164
6190
  } catch (error) {
6165
6191
  getLogger().error("[serverTools] Failed to fetch server tools:", error);
@@ -6543,13 +6569,14 @@ async function selectServerToolsForPrompt(options) {
6543
6569
  baseUrl,
6544
6570
  embeddingModel,
6545
6571
  cacheExpirationMs,
6572
+ cache,
6546
6573
  deferLoading
6547
6574
  } = options;
6548
6575
  if (serverToolsFilter === void 0) return [];
6549
6576
  if (Array.isArray(serverToolsFilter) && serverToolsFilter.length === 0) return [];
6550
6577
  let allServerTools;
6551
6578
  try {
6552
- allServerTools = await getServerTools({ baseUrl, cacheExpirationMs, getToken });
6579
+ allServerTools = await getServerTools({ baseUrl, cacheExpirationMs, getToken, cache });
6553
6580
  } catch {
6554
6581
  return [];
6555
6582
  }
@@ -7083,6 +7110,7 @@ var WalletPoller = class {
7083
7110
  };
7084
7111
 
7085
7112
  // src/lib/processors/encoding.ts
7113
+ var B64_ENCODE_CHUNK = 32768 * 3;
7086
7114
  async function dataUrlToArrayBuffer(dataUrl) {
7087
7115
  if (dataUrl.startsWith("blob:") || dataUrl.startsWith("http://") || dataUrl.startsWith("https://")) {
7088
7116
  const response = await fetch(dataUrl);
@@ -7105,11 +7133,16 @@ function uint8ArrayToBase64(data) {
7105
7133
  if (typeof Buffer !== "undefined") {
7106
7134
  return Buffer.from(data).toString("base64");
7107
7135
  }
7108
- let binary = "";
7109
- for (let i = 0; i < data.length; i++) {
7110
- binary += String.fromCharCode(data[i]);
7136
+ let base64 = "";
7137
+ for (let i = 0; i < data.length; i += B64_ENCODE_CHUNK) {
7138
+ const slice = data.subarray(i, i + B64_ENCODE_CHUNK);
7139
+ let binary = "";
7140
+ for (let j = 0; j < slice.length; j++) {
7141
+ binary += String.fromCharCode(slice[j]);
7142
+ }
7143
+ base64 += btoa(binary);
7111
7144
  }
7112
- return btoa(binary);
7145
+ return base64;
7113
7146
  }
7114
7147
 
7115
7148
  // src/lib/processors/ExcelProcessor.ts
@@ -7878,6 +7911,141 @@ function createCryptoPricePreProcessor(options = {}) {
7878
7911
  };
7879
7912
  }
7880
7913
 
7914
+ // src/client/core/serverSentEvents.gen.ts
7915
+ var createSseClient = ({
7916
+ onRequest,
7917
+ onSseError,
7918
+ onSseEvent,
7919
+ responseTransformer,
7920
+ responseValidator,
7921
+ sseDefaultRetryDelay,
7922
+ sseMaxRetryAttempts,
7923
+ sseMaxRetryDelay,
7924
+ sseSleepFn,
7925
+ url,
7926
+ ...options
7927
+ }) => {
7928
+ let lastEventId;
7929
+ const sleep3 = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
7930
+ const createStream = async function* () {
7931
+ let retryDelay = sseDefaultRetryDelay ?? 3e3;
7932
+ let attempt = 0;
7933
+ const signal = options.signal ?? new AbortController().signal;
7934
+ while (true) {
7935
+ if (signal.aborted) break;
7936
+ attempt++;
7937
+ const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
7938
+ if (lastEventId !== void 0) {
7939
+ headers.set("Last-Event-ID", lastEventId);
7940
+ }
7941
+ try {
7942
+ const requestInit = {
7943
+ redirect: "follow",
7944
+ ...options,
7945
+ body: options.serializedBody,
7946
+ headers,
7947
+ signal
7948
+ };
7949
+ let request = new Request(url, requestInit);
7950
+ if (onRequest) {
7951
+ request = await onRequest(url, requestInit);
7952
+ }
7953
+ const _fetch = options.fetch ?? globalThis.fetch;
7954
+ const response = await _fetch(request);
7955
+ if (!response.ok)
7956
+ throw new Error(
7957
+ `SSE failed: ${response.status} ${response.statusText}`
7958
+ );
7959
+ if (!response.body) throw new Error("No body in SSE response");
7960
+ const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
7961
+ let buffer = "";
7962
+ const abortHandler = () => {
7963
+ try {
7964
+ reader.cancel();
7965
+ } catch {
7966
+ }
7967
+ };
7968
+ signal.addEventListener("abort", abortHandler);
7969
+ try {
7970
+ while (true) {
7971
+ const { done, value } = await reader.read();
7972
+ if (done) break;
7973
+ buffer += value;
7974
+ const chunks = buffer.split("\n\n");
7975
+ buffer = chunks.pop() ?? "";
7976
+ for (const chunk of chunks) {
7977
+ const lines = chunk.split("\n");
7978
+ const dataLines = [];
7979
+ let eventName;
7980
+ for (const line of lines) {
7981
+ if (line.startsWith("data:")) {
7982
+ dataLines.push(line.replace(/^data:\s*/, ""));
7983
+ } else if (line.startsWith("event:")) {
7984
+ eventName = line.replace(/^event:\s*/, "");
7985
+ } else if (line.startsWith("id:")) {
7986
+ lastEventId = line.replace(/^id:\s*/, "");
7987
+ } else if (line.startsWith("retry:")) {
7988
+ const parsed = Number.parseInt(
7989
+ line.replace(/^retry:\s*/, ""),
7990
+ 10
7991
+ );
7992
+ if (!Number.isNaN(parsed)) {
7993
+ retryDelay = parsed;
7994
+ }
7995
+ }
7996
+ }
7997
+ let data;
7998
+ let parsedJson = false;
7999
+ if (dataLines.length) {
8000
+ const rawData = dataLines.join("\n");
8001
+ try {
8002
+ data = JSON.parse(rawData);
8003
+ parsedJson = true;
8004
+ } catch {
8005
+ data = rawData;
8006
+ }
8007
+ }
8008
+ if (parsedJson) {
8009
+ if (responseValidator) {
8010
+ await responseValidator(data);
8011
+ }
8012
+ if (responseTransformer) {
8013
+ data = await responseTransformer(data);
8014
+ }
8015
+ }
8016
+ onSseEvent?.({
8017
+ data,
8018
+ event: eventName,
8019
+ id: lastEventId,
8020
+ retry: retryDelay
8021
+ });
8022
+ if (dataLines.length) {
8023
+ yield data;
8024
+ }
8025
+ }
8026
+ }
8027
+ } finally {
8028
+ signal.removeEventListener("abort", abortHandler);
8029
+ reader.releaseLock();
8030
+ }
8031
+ break;
8032
+ } catch (error) {
8033
+ onSseError?.(error);
8034
+ if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) {
8035
+ break;
8036
+ }
8037
+ const backoff = Math.min(
8038
+ retryDelay * 2 ** (attempt - 1),
8039
+ sseMaxRetryDelay ?? 3e4
8040
+ );
8041
+ await sleep3(backoff);
8042
+ }
8043
+ }
8044
+ };
8045
+ const stream = createStream();
8046
+ return { stream };
8047
+ };
8048
+
7881
8049
  // src/lib/chat/runHooks.ts
7882
8050
  function composeHooks(hooks) {
7883
8051
  const handlers = hooks.filter((h) => h !== void 0 && h !== null);
@@ -11546,6 +11714,7 @@ export {
11546
11714
  decryptData,
11547
11715
  decryptDataBatch,
11548
11716
  decryptDataBytes,
11717
+ decryptDataBytesFromBytes,
11549
11718
  decryptDataWithKey,
11550
11719
  defaultServerToolsFilter,
11551
11720
  deleteAllVaultMemoriesForUserOp,
@@ -11564,6 +11733,7 @@ export {
11564
11733
  embedMessage,
11565
11734
  encryptData,
11566
11735
  encryptDataBatch,
11736
+ encryptDataBytes,
11567
11737
  encryptDataWithKey,
11568
11738
  ensureDefaultFoldersOp,
11569
11739
  estimateMessagesTokens,
@@ -11592,6 +11762,7 @@ export {
11592
11762
  getConversationsByProjectOp,
11593
11763
  getConversationsLazyOp,
11594
11764
  getConversationsOp,
11765
+ getConversationsPageOp,
11595
11766
  getDocumentsOp,
11596
11767
  getEncryptionKey,
11597
11768
  getImagesOp,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  recall
3
- } from "./chunk-Z6II54I7.mjs";
3
+ } from "./chunk-RKUNGNBF.mjs";
4
4
  import "./chunk-AHJT66EO.mjs";
5
5
  import "./chunk-3RPGXXPZ.mjs";
6
6
  export {
@@ -0,0 +1,25 @@
1
+ // src/clientConfig.ts
2
+ var DEFAULT_BASE_URL = "https://portal.anuma-dev.ai";
3
+ function readGlobal(key) {
4
+ if (typeof globalThis === "undefined") return void 0;
5
+ const value = globalThis[key];
6
+ return typeof value === "string" && value.length > 0 ? value : void 0;
7
+ }
8
+ function resolveBaseUrl() {
9
+ const fromProcess = typeof process !== "undefined" ? process.env.API_URL || process.env.NEXT_PUBLIC_API_URL || process.env.EXPO_PUBLIC_API_URL : void 0;
10
+ const fromGlobal = readGlobal("API_URL") ?? readGlobal("NEXT_PUBLIC_API_URL") ?? readGlobal("EXPO_PUBLIC_API_URL");
11
+ return (fromProcess || fromGlobal || DEFAULT_BASE_URL).replace(/\/+$/, "");
12
+ }
13
+ var BASE_URL = resolveBaseUrl();
14
+ var MCP_R2_DOMAIN = "4cf0e0ea50b97e72386fcf2f92a2d4e8.r2.cloudflarestorage.com";
15
+ var createClientConfig = (config) => ({
16
+ ...config,
17
+ baseUrl: BASE_URL
18
+ });
19
+
20
+ export {
21
+ resolveBaseUrl,
22
+ BASE_URL,
23
+ MCP_R2_DOMAIN,
24
+ createClientConfig
25
+ };
@@ -0,0 +1,12 @@
1
+ import {
2
+ BASE_URL,
3
+ MCP_R2_DOMAIN,
4
+ createClientConfig,
5
+ resolveBaseUrl
6
+ } from "./chunk-4ETHWSXJ.mjs";
7
+ export {
8
+ BASE_URL,
9
+ MCP_R2_DOMAIN,
10
+ createClientConfig,
11
+ resolveBaseUrl
12
+ };