@anuma/sdk 6.4.2 → 6.6.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.
Files changed (32) hide show
  1. package/dist/expo/{chunk-WYARTNEN.mjs → chunk-4M6W7QLZ.mjs} +233 -8
  2. package/dist/{react/chunk-ILAWDQDE.mjs → expo/chunk-B5UPJRCU.mjs} +16 -1
  3. package/dist/expo/{chunk-DT6QNRZL.mjs → chunk-VOMDHMKH.mjs} +1 -1
  4. package/dist/{react/consolidate-AMPKH6YJ.mjs → expo/consolidate-TWE6OSSZ.mjs} +2 -2
  5. package/dist/expo/index.cjs +306 -156
  6. package/dist/expo/index.d.mts +163 -7
  7. package/dist/expo/index.d.ts +163 -7
  8. package/dist/expo/index.mjs +33 -154
  9. package/dist/expo/{recall-7FOWWX5T.mjs → recall-EZIHN5VU.mjs} +2 -2
  10. package/dist/index.cjs +71 -0
  11. package/dist/index.d.mts +121 -1
  12. package/dist/index.d.ts +121 -1
  13. package/dist/index.mjs +67 -0
  14. package/dist/react/{chunk-VMI74IUX.mjs → chunk-2ARMO2NN.mjs} +1 -1
  15. package/dist/{expo/chunk-ILAWDQDE.mjs → react/chunk-B5UPJRCU.mjs} +16 -1
  16. package/dist/react/{chunk-IO4ZCPK2.mjs → chunk-S6WPXD5N.mjs} +254 -8
  17. package/dist/{expo/consolidate-3MEWQNM3.mjs → react/consolidate-ZCGS7QUA.mjs} +2 -2
  18. package/dist/react/index.cjs +331 -206
  19. package/dist/react/index.d.mts +163 -7
  20. package/dist/react/index.d.ts +163 -7
  21. package/dist/react/index.mjs +36 -202
  22. package/dist/react/{recall-2J2755WC.mjs → recall-ROEK55FJ.mjs} +2 -2
  23. package/dist/server/{chunk-KF4HV3QE.mjs → chunk-CR5P3YIK.mjs} +1 -1
  24. package/dist/server/{chunk-EKYGWD5N.mjs → chunk-TD7SMY7C.mjs} +98 -8
  25. package/dist/server/{chunk-OBDRKQQI.mjs → chunk-VHWLLYKO.mjs} +16 -1
  26. package/dist/server/{consolidate-I6TOH7CB.mjs → consolidate-FWYK5KXB.mjs} +2 -2
  27. package/dist/server/index.cjs +158 -48
  28. package/dist/server/index.d.mts +54 -6
  29. package/dist/server/index.d.ts +54 -6
  30. package/dist/server/index.mjs +24 -43
  31. package/dist/server/{recall-IVV6EILK.mjs → recall-CGDEW2LQ.mjs} +2 -2
  32. package/package.json +1 -1
@@ -1,10 +1,12 @@
1
1
  import {
2
+ CHUNKS_DISCARDED_ORIGIN,
2
3
  DEFAULT_API_EMBEDDING_MODEL,
3
4
  DEFAULT_CHUNK_OVERLAP,
4
5
  DEFAULT_CHUNK_SIZE,
5
6
  DEFAULT_MIN_CHUNK_SIZE,
6
7
  DEFAULT_MIN_CONTENT_LENGTH,
7
8
  DEFAULT_VAULT_CACHE_SIZE,
9
+ DISPLAY_CARD_PLACEHOLDER,
8
10
  EMBEDDINGS_DEGRADED_EMPTY,
9
11
  ENTITY_FANOUT,
10
12
  ENTITY_KINDS,
@@ -15,6 +17,7 @@ import {
15
17
  RECALL_MAX_LIMIT,
16
18
  RECALL_TOOL_NAME,
17
19
  RerankerUnavailableError,
20
+ TOOL_RESULT_ORIGIN,
18
21
  TOPICS_EXTRACTION_VERSION,
19
22
  TREND_RECENT_WINDOW_DAYS,
20
23
  TREND_STALE_WINDOW_DAYS,
@@ -23,6 +26,8 @@ import {
23
26
  assertVaultScopeForSweep,
24
27
  backfillMemoryEntityUserIdsOp,
25
28
  backfillMemoryTopicsOp,
29
+ base64ToUint8Array,
30
+ buildToolResultContent,
26
31
  capHopsForDensity,
27
32
  chunkAndEmbedAllMessages,
28
33
  chunkAndEmbedMessage,
@@ -47,6 +52,8 @@ import {
47
52
  createVaultEmbeddingCache,
48
53
  createVaultMemoriesBatchOp,
49
54
  createVaultMemoryOp,
55
+ dataUrlToArrayBuffer,
56
+ decodeChunkVector,
50
57
  decomposeQuery,
51
58
  decryptData,
52
59
  decryptDataBatch,
@@ -62,6 +69,7 @@ import {
62
69
  eagerEmbedContent,
63
70
  embedAllMessages,
64
71
  embedMessage,
72
+ encodeChunkVector,
65
73
  encryptData,
66
74
  encryptDataBatch,
67
75
  encryptDataBytes,
@@ -134,6 +142,7 @@ import {
134
142
  postAuthOauthByProviderRefresh,
135
143
  postAuthOauthByProviderRevoke,
136
144
  preEmbedVaultMemories,
145
+ prepareToolResultsForReplay,
137
146
  prepareVaultCandidates,
138
147
  rankPreparedVaultCandidates,
139
148
  recall,
@@ -156,6 +165,7 @@ import {
156
165
  summarizeObservationTrends,
157
166
  supersedeVaultMemoryOp,
158
167
  traverseGraphLane,
168
+ uint8ArrayToBase64,
159
169
  updateConversationPinnedOp,
160
170
  updateConversationProjectOp,
161
171
  updateConversationTitleOp,
@@ -168,15 +178,16 @@ import {
168
178
  updateVaultMemoryOp,
169
179
  useEncryption,
170
180
  vaultMemoryToStored
171
- } from "./chunk-IO4ZCPK2.mjs";
181
+ } from "./chunk-S6WPXD5N.mjs";
172
182
  import {
173
183
  PiiRedactor,
174
184
  createStreamingDeAnonymizer,
175
185
  isPiiRedactor,
176
186
  notifyConsolidationFallback,
177
187
  resolvePiiRedactor
178
- } from "./chunk-VMI74IUX.mjs";
188
+ } from "./chunk-2ARMO2NN.mjs";
179
189
  import {
190
+ INTERNAL_FLOW_MARKER,
180
191
  callPortalJsonCompletion,
181
192
  consoleLogger,
182
193
  extractJsonCandidate,
@@ -185,8 +196,9 @@ import {
185
196
  resolvePortalAuthHeaders,
186
197
  setLogger,
187
198
  supportsResponseFormat,
188
- validateEndpointOverride
189
- } from "./chunk-ILAWDQDE.mjs";
199
+ validateEndpointOverride,
200
+ withInternalFlowMarker
201
+ } from "./chunk-B5UPJRCU.mjs";
190
202
  import {
191
203
  BASE_URL,
192
204
  MCP_R2_DOMAIN,
@@ -5142,7 +5154,17 @@ async function callSummarizationLlm(prompt, model, token, baseUrl) {
5142
5154
  body: JSON.stringify({
5143
5155
  model,
5144
5156
  stream: false,
5145
- messages: [{ role: "user", content: prompt }]
5157
+ // The marker rides a system message because this call has no other
5158
+ // provenance: it posts to the MAIN chat endpoint (not /utility/*), carries no
5159
+ // conversationId, and its prompt is neither the app's chat base prompt nor any
5160
+ // registered flow fingerprint — so without this it reads as markerless, i.e.
5161
+ // as a scripted abuser. Progressive summarization runs for every free-tier
5162
+ // long conversation, so at the PORTAL_DETECTION_REJECT_MARKERLESS flip it
5163
+ // would 403 and silently fall back to verbatim history (context bloat + cost).
5164
+ messages: [
5165
+ { role: "system", content: INTERNAL_FLOW_MARKER },
5166
+ { role: "user", content: prompt }
5167
+ ]
5146
5168
  }),
5147
5169
  signal: controller.signal
5148
5170
  });
@@ -5346,153 +5368,6 @@ async function cleanupConversationSummary(database, conversationId) {
5346
5368
  }
5347
5369
  }
5348
5370
 
5349
- // src/lib/chat/toolResultMessage.ts
5350
- var HEADER = "[Tool Execution Results]\n\n";
5351
- var FOOTER = "\n\nBased on these results, continue with the task.";
5352
- var ENTRY_SEPARATOR = "\n\n";
5353
- var TOOL_RESULT_FOOTER_LINE = FOOTER.trim();
5354
- var MAX_PERSISTED_TOOL_RESULT_CHARS = 1e5;
5355
- function buildToolResultContent(results) {
5356
- const entries = results.map((r) => `Tool "${r.name}" returned: ${JSON.stringify(r.result)}`);
5357
- const framing = HEADER.length + FOOTER.length + ENTRY_SEPARATOR.length * Math.max(0, entries.length - 1);
5358
- const summary = capEntries(entries, MAX_PERSISTED_TOOL_RESULT_CHARS - framing).join(
5359
- ENTRY_SEPARATOR
5360
- );
5361
- return `${HEADER}${summary}${FOOTER}`;
5362
- }
5363
- function capToolResultEntries(entries, budget) {
5364
- return capEntries(entries, budget);
5365
- }
5366
- function capEntries(entries, budget) {
5367
- const smallestFirst = entries.map((_, index) => index).sort((a, b) => entries[a].length - entries[b].length);
5368
- const capped = [...entries];
5369
- let remaining = budget;
5370
- let unassigned = entries.length;
5371
- for (const index of smallestFirst) {
5372
- capped[index] = truncateEntry(entries[index], Math.floor(remaining / unassigned));
5373
- remaining -= capped[index].length;
5374
- unassigned--;
5375
- }
5376
- return capped;
5377
- }
5378
- function truncateEntry(entry, allowance) {
5379
- if (entry.length <= allowance) return entry;
5380
- const keep = allowance - truncationMarker(entry.length).length;
5381
- if (keep <= 0) return entry.slice(0, Math.max(0, allowance));
5382
- return `${entry.slice(0, keep)}${truncationMarker(entry.length - keep)}`;
5383
- }
5384
- function truncationMarker(omitted) {
5385
- return `
5386
-
5387
- ... (tool output truncated, ${omitted} characters omitted)`;
5388
- }
5389
-
5390
- // src/lib/chat/toolResults.ts
5391
- var TOOL_RESULTS_PREFIX = "[Tool Execution Results]";
5392
- var DISPLAY_CARD_PLACEHOLDER = "[displayed a card to the user with the tool result]";
5393
- var TOOL_LINE = /^Tool "([^"]+)" returned: (.*)$/;
5394
- var TOOL_RESULT_ORIGIN = "tool_result";
5395
- function isToolResultsRow(row) {
5396
- if (row.origin === TOOL_RESULT_ORIGIN) return true;
5397
- if (typeof row.origin === "string") return false;
5398
- if (row.role !== "user" || !row.content.startsWith(TOOL_RESULTS_PREFIX)) return false;
5399
- return parseToolResultSegments(row.content).length > 0;
5400
- }
5401
- function parseToolResultSegments(content) {
5402
- const segments = [];
5403
- for (const raw of content.split("\n")) {
5404
- const line = raw.trim();
5405
- const match = TOOL_LINE.exec(line);
5406
- if (match) {
5407
- segments.push({ name: match[1], line });
5408
- continue;
5409
- }
5410
- const current = segments[segments.length - 1];
5411
- if (!current || line === "" || line === TOOL_RESULT_FOOTER_LINE) continue;
5412
- if (line === TOOL_RESULTS_PREFIX) continue;
5413
- current.line = `${current.line}
5414
- ${line}`;
5415
- }
5416
- return segments;
5417
- }
5418
- function prepareToolResultsForReplay(rows, options) {
5419
- if (options.fold) {
5420
- return foldToolResultsRows(rows, {
5421
- exclude: options.exclude,
5422
- placeholder: options.placeholder
5423
- });
5424
- }
5425
- return rows.filter((row) => !isToolResultsRow(row));
5426
- }
5427
- function foldToolResultsRows(rows, options) {
5428
- const exclude = new Set(options?.exclude ?? []);
5429
- const out = [];
5430
- const pending = [];
5431
- const assistantIndexById = /* @__PURE__ */ new Map();
5432
- for (const row of rows) {
5433
- if (isToolResultsRow(row)) {
5434
- pending.push({ row, insertionPoint: out.length });
5435
- continue;
5436
- }
5437
- out.push(row);
5438
- if (row.role === "assistant" && row.uniqueId) {
5439
- assistantIndexById.set(row.uniqueId, out.length - 1);
5440
- }
5441
- }
5442
- const byTarget = /* @__PURE__ */ new Map();
5443
- for (const { row, insertionPoint } of pending) {
5444
- const target = resolveFoldTarget(out, row, insertionPoint, assistantIndexById);
5445
- if (target === void 0) continue;
5446
- const group = byTarget.get(target);
5447
- if (group) group.push(row);
5448
- else byTarget.set(target, [row]);
5449
- }
5450
- for (const [target, groupedRows] of byTarget) {
5451
- const assistant = out[target];
5452
- const kept = groupedRows.flatMap((row) => parseToolResultSegments(row.content)).filter((segment) => !exclude.has(segment.name));
5453
- if (kept.length > 0) {
5454
- out[target] = { ...assistant, content: appendToolResults(assistant.content, kept) };
5455
- } else if (!assistant.content.trim() && options?.placeholder) {
5456
- out[target] = { ...assistant, content: options.placeholder };
5457
- }
5458
- }
5459
- return out;
5460
- }
5461
- function resolveFoldTarget(out, row, insertionPoint, assistantIndexById) {
5462
- const linked = row.parentMessageId ? assistantIndexById.get(row.parentMessageId) : void 0;
5463
- if (linked !== void 0) return linked;
5464
- let previous;
5465
- for (let i = insertionPoint - 1; i >= 0; i--) {
5466
- if (out[i].role === "assistant") {
5467
- previous = i;
5468
- break;
5469
- }
5470
- }
5471
- let next;
5472
- for (let i = insertionPoint; i < out.length; i++) {
5473
- if (out[i].role === "assistant") {
5474
- next = i;
5475
- break;
5476
- }
5477
- }
5478
- if (previous === void 0) return next;
5479
- if (next === void 0) return previous;
5480
- return next - insertionPoint < insertionPoint - previous ? next : previous;
5481
- }
5482
- var MAX_FOLDED_APPENDIX_CHARS = 2e4;
5483
- function appendToolResults(assistantContent, kept) {
5484
- const framing = TOOL_RESULTS_PREFIX.length + 1 + (kept.length - 1);
5485
- const capped = capToolResultEntries(
5486
- kept.map((segment) => segment.line),
5487
- MAX_FOLDED_APPENDIX_CHARS - framing
5488
- );
5489
- const appendix = `${TOOL_RESULTS_PREFIX}
5490
- ${capped.join("\n")}`;
5491
- return assistantContent.trim() ? `${assistantContent}
5492
-
5493
- ${appendix}` : appendix;
5494
- }
5495
-
5496
5371
  // src/lib/db/chat/lazyDecrypt.ts
5497
5372
  var LRU_CAPACITY = 256;
5498
5373
  var titleCache = /* @__PURE__ */ new Map();
@@ -7804,7 +7679,7 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
7804
7679
  content: m.content,
7805
7680
  similarity: m.similarity
7806
7681
  }));
7807
- const { consolidateMemory: doConsolidate } = await import("./consolidate-AMPKH6YJ.mjs");
7682
+ const { consolidateMemory: doConsolidate } = await import("./consolidate-ZCGS7QUA.mjs");
7808
7683
  const decision = await doConsolidate(trimmed, candidates, consolidateOptions);
7809
7684
  if (decision.action === "create") return null;
7810
7685
  if (decision.action === "supersede" && decision.content) {
@@ -9506,7 +9381,10 @@ async function synthesizeFacet(facet, ctx, options, prior) {
9506
9381
  limit,
9507
9382
  types: ["fact"],
9508
9383
  maxTokens: DEFAULT_FACET_MAX_TOKENS,
9509
- systemPrompt: buildFacetSystemPrompt(facet),
9384
+ // Profile-facet synthesis is a background op, so it marks its own prompt.
9385
+ // reflect() itself must NOT mark — it also serves the user's own questions,
9386
+ // and that traffic is chat, not an internal flow. See ../internalFlowMarker.
9387
+ systemPrompt: withInternalFlowMarker(buildFacetSystemPrompt(facet)),
9510
9388
  responseSchema: facetResponseSchema(facet.key),
9511
9389
  memories
9512
9390
  });
@@ -10456,54 +10334,6 @@ function createMemoryVaultTool(vaultCtx, options, embeddingOptions, cache) {
10456
10334
  };
10457
10335
  }
10458
10336
 
10459
- // src/lib/processors/encoding.ts
10460
- var B64_ENCODE_CHUNK = 32768 * 3;
10461
- async function dataUrlToArrayBuffer(dataUrl) {
10462
- if (dataUrl.startsWith("blob:") || dataUrl.startsWith("http://") || dataUrl.startsWith("https://")) {
10463
- const response = await fetch(dataUrl);
10464
- return response.arrayBuffer();
10465
- }
10466
- const base64 = dataUrl.split(",")[1];
10467
- if (typeof Buffer !== "undefined") {
10468
- const buf = Buffer.from(base64, "base64");
10469
- return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
10470
- }
10471
- const binary = atob(base64);
10472
- const buffer = new ArrayBuffer(binary.length);
10473
- const view = new Uint8Array(buffer);
10474
- for (let i = 0; i < binary.length; i++) {
10475
- view[i] = binary.charCodeAt(i);
10476
- }
10477
- return buffer;
10478
- }
10479
- function uint8ArrayToBase64(data) {
10480
- if (typeof Buffer !== "undefined") {
10481
- return Buffer.from(data).toString("base64");
10482
- }
10483
- let base64 = "";
10484
- for (let i = 0; i < data.length; i += B64_ENCODE_CHUNK) {
10485
- const slice = data.subarray(i, i + B64_ENCODE_CHUNK);
10486
- let binary = "";
10487
- for (let j = 0; j < slice.length; j++) {
10488
- binary += String.fromCharCode(slice[j]);
10489
- }
10490
- base64 += btoa(binary);
10491
- }
10492
- return base64;
10493
- }
10494
- function base64ToUint8Array(base64) {
10495
- if (typeof Buffer !== "undefined") {
10496
- const buf = Buffer.from(base64, "base64");
10497
- return new Uint8Array(buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength));
10498
- }
10499
- const binary = atob(base64);
10500
- const bytes = new Uint8Array(binary.length);
10501
- for (let i = 0; i < binary.length; i++) {
10502
- bytes[i] = binary.charCodeAt(i);
10503
- }
10504
- return bytes;
10505
- }
10506
-
10507
10337
  // src/lib/processors/ExcelProcessor.ts
10508
10338
  if (typeof process !== "undefined" && typeof process.umask !== "function") {
10509
10339
  process.umask = (_mask) => 18;
@@ -25156,6 +24986,7 @@ export {
25156
24986
  BUILT_IN_TOOL_SETS,
25157
24987
  BackupAuthProvider,
25158
24988
  BlobUrlManager,
24989
+ CHUNKS_DISCARDED_ORIGIN,
25159
24990
  ChartCard,
25160
24991
  ChartContainer,
25161
24992
  ChartLegend,
@@ -25232,6 +25063,7 @@ export {
25232
25063
  VaultMemory as StoredVaultMemoryModel,
25233
25064
  StreamExpiredError,
25234
25065
  THEME_ATTRS,
25066
+ TOOL_RESULT_ORIGIN,
25235
25067
  TOPICS_EXTRACTION_VERSION,
25236
25068
  TOPIC_EXTRACTION_BATCH_SIZE,
25237
25069
  TREND_RECENT_WINDOW_DAYS,
@@ -25309,6 +25141,7 @@ export {
25309
25141
  createVaultMemoryOp,
25310
25142
  createWeatherPreProcessor,
25311
25143
  createWebSearchPreProcessor,
25144
+ decodeChunkVector,
25312
25145
  decryptConversationTitle,
25313
25146
  decryptData,
25314
25147
  decryptDataBatch,
@@ -25331,6 +25164,7 @@ export {
25331
25164
  eagerEmbedContent,
25332
25165
  embedAllMessages,
25333
25166
  embedMessage,
25167
+ encodeChunkVector,
25334
25168
  encryptData,
25335
25169
  encryptDataBatch,
25336
25170
  encryptDataBytes,
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  recall
3
- } from "./chunk-IO4ZCPK2.mjs";
4
- import "./chunk-ILAWDQDE.mjs";
3
+ } from "./chunk-S6WPXD5N.mjs";
4
+ import "./chunk-B5UPJRCU.mjs";
5
5
  import "./chunk-GYKJOWEO.mjs";
6
6
  export {
7
7
  recall
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getLogger
3
- } from "./chunk-OBDRKQQI.mjs";
3
+ } from "./chunk-VHWLLYKO.mjs";
4
4
 
5
5
  // src/lib/pii/patterns.ts
6
6
  function luhnCheck(digits) {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  callPortalJsonCompletion,
3
3
  getLogger
4
- } from "./chunk-OBDRKQQI.mjs";
4
+ } from "./chunk-VHWLLYKO.mjs";
5
5
  import {
6
6
  BASE_URL,
7
7
  __commonJS,
@@ -15115,6 +15115,77 @@ function cosineSimilarity(a, b) {
15115
15115
  return denom === 0 ? 0 : dot / denom;
15116
15116
  }
15117
15117
 
15118
+ // src/lib/processors/encoding.ts
15119
+ var B64_ENCODE_CHUNK = 32768 * 3;
15120
+ async function dataUrlToArrayBuffer(dataUrl) {
15121
+ if (dataUrl.startsWith("blob:") || dataUrl.startsWith("http://") || dataUrl.startsWith("https://")) {
15122
+ const response = await fetch(dataUrl);
15123
+ return response.arrayBuffer();
15124
+ }
15125
+ const base64 = dataUrl.split(",")[1];
15126
+ if (typeof Buffer !== "undefined") {
15127
+ const buf = Buffer.from(base64, "base64");
15128
+ return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
15129
+ }
15130
+ const binary = atob(base64);
15131
+ const buffer = new ArrayBuffer(binary.length);
15132
+ const view = new Uint8Array(buffer);
15133
+ for (let i = 0; i < binary.length; i++) {
15134
+ view[i] = binary.charCodeAt(i);
15135
+ }
15136
+ return buffer;
15137
+ }
15138
+ function uint8ArrayToBase64(data) {
15139
+ if (typeof Buffer !== "undefined") {
15140
+ return Buffer.from(data).toString("base64");
15141
+ }
15142
+ let base64 = "";
15143
+ for (let i = 0; i < data.length; i += B64_ENCODE_CHUNK) {
15144
+ const slice = data.subarray(i, i + B64_ENCODE_CHUNK);
15145
+ let binary = "";
15146
+ for (let j = 0; j < slice.length; j++) {
15147
+ binary += String.fromCharCode(slice[j]);
15148
+ }
15149
+ base64 += btoa(binary);
15150
+ }
15151
+ return base64;
15152
+ }
15153
+ function base64ToUint8Array(base64) {
15154
+ if (typeof Buffer !== "undefined") {
15155
+ const buf = Buffer.from(base64, "base64");
15156
+ return new Uint8Array(buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength));
15157
+ }
15158
+ const binary = atob(base64);
15159
+ const bytes = new Uint8Array(binary.length);
15160
+ for (let i = 0; i < binary.length; i++) {
15161
+ bytes[i] = binary.charCodeAt(i);
15162
+ }
15163
+ return bytes;
15164
+ }
15165
+
15166
+ // src/lib/memoryEngine/vectorEncoding.ts
15167
+ var BYTES_PER_FLOAT32 = 4;
15168
+ var CANONICAL_BASE64 = /^[A-Za-z0-9+/]+={0,2}$/;
15169
+ function decodeChunkVector(vector, onMalformed) {
15170
+ if (!vector || vector.length === 0) return new Float32Array(0);
15171
+ if (typeof vector !== "string") return Float32Array.from(vector);
15172
+ if (vector.length % 4 !== 0 || !CANONICAL_BASE64.test(vector)) {
15173
+ onMalformed?.();
15174
+ return new Float32Array(0);
15175
+ }
15176
+ try {
15177
+ const bytes = base64ToUint8Array(vector);
15178
+ if (bytes.byteLength === 0 || bytes.byteLength % BYTES_PER_FLOAT32 !== 0) {
15179
+ onMalformed?.();
15180
+ return new Float32Array(0);
15181
+ }
15182
+ return new Float32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / BYTES_PER_FLOAT32);
15183
+ } catch {
15184
+ onMalformed?.();
15185
+ return new Float32Array(0);
15186
+ }
15187
+ }
15188
+
15118
15189
  // src/lib/db/encryption-utils.ts
15119
15190
  var ENCRYPTION_PREFIX = "enc:v3:";
15120
15191
  function isEncrypted(value) {
@@ -16052,6 +16123,7 @@ async function searchChunksOp(ctx, queryVector, options) {
16052
16123
  const messages = await ctx.messagesCollection.query(...queryConditions).fetch();
16053
16124
  const candidates = [];
16054
16125
  let staleSkipped = 0;
16126
+ let unreadableVectors = 0;
16055
16127
  for (const message of messages) {
16056
16128
  const msgConvId = String(message._getRaw("conversation_id"));
16057
16129
  if (!activeConversationIds.has(msgConvId)) continue;
@@ -16089,7 +16161,9 @@ async function searchChunksOp(ctx, queryVector, options) {
16089
16161
  const chunks = await readJsonField(message, "chunks", ctx.walletAddress);
16090
16162
  if (chunks && chunks.length > 0) {
16091
16163
  const vectors = chunks.map(
16092
- (chunk) => chunk.vector && chunk.vector.length > 0 ? Float32Array.from(chunk.vector) : new Float32Array(0)
16164
+ (chunk) => decodeChunkVector(chunk.vector, () => {
16165
+ unreadableVectors++;
16166
+ })
16093
16167
  );
16094
16168
  chunkCache?.set(message.id, { version, chunks: vectors });
16095
16169
  for (let ci = 0; ci < chunks.length; ci++) {
@@ -16120,6 +16194,11 @@ async function searchChunksOp(ctx, queryVector, options) {
16120
16194
  `searchChunksOp: skipped ${staleSkipped} messages whose embedding model differs from the current model (${embeddingModel}) \u2014 re-embed via chunkAndEmbedAllMessages`
16121
16195
  );
16122
16196
  }
16197
+ if (unreadableVectors > 0) {
16198
+ getLogger().warn(
16199
+ `searchChunksOp: could not read ${unreadableVectors} chunk vectors and left them out of ranking \u2014 the stored value is corrupt, so those chunks stay unsearchable until the message is re-embedded via chunkAndEmbedAllMessages`
16200
+ );
16201
+ }
16123
16202
  const topK = candidates.sort((a, b) => b.similarity - a.similarity).slice(0, limit);
16124
16203
  const uniqueMessages = /* @__PURE__ */ new Map();
16125
16204
  for (const c of topK) uniqueMessages.set(c.message.id, c.message);
@@ -17695,6 +17774,9 @@ async function updateVaultMemoryEmbeddingOp(ctx, id, embedding, embeddingModel)
17695
17774
  // src/lib/memoryEngine/constants.ts
17696
17775
  var DEFAULT_API_EMBEDDING_MODEL = "qwen/qwen3-embedding-8b";
17697
17776
 
17777
+ // src/lib/chat/toolResults.ts
17778
+ var TOOL_RESULT_ORIGIN = "tool_result";
17779
+
17698
17780
  // src/lib/memoryEngine/chunking.ts
17699
17781
  var DEFAULT_CHUNK_SIZE = 400;
17700
17782
  var DEFAULT_CHUNK_OVERLAP = 50;
@@ -18820,7 +18902,13 @@ async function generateEmbeddings(texts, options) {
18820
18902
 
18821
18903
  // src/lib/memoryEngine/embeddings.ts
18822
18904
  var DEFAULT_MIN_CONTENT_LENGTH = 10;
18823
- var NON_EMBEDDABLE_ORIGIN = "tool_result";
18905
+ var CHUNKS_DISCARDED_ORIGIN = "chunks_discarded";
18906
+ var NON_EMBEDDABLE_ORIGINS = /* @__PURE__ */ new Set([TOOL_RESULT_ORIGIN, CHUNKS_DISCARDED_ORIGIN]);
18907
+ function isNonEmbeddableOrigin(origin, reembedDiscarded = false) {
18908
+ if (typeof origin !== "string") return false;
18909
+ if (reembedDiscarded && origin === CHUNKS_DISCARDED_ORIGIN) return false;
18910
+ return NON_EMBEDDABLE_ORIGINS.has(origin);
18911
+ }
18824
18912
  async function embedMessage(ctx, messageId, options) {
18825
18913
  const message = await getMessageOp(ctx, messageId);
18826
18914
  if (!message) {
@@ -18829,7 +18917,7 @@ async function embedMessage(ctx, messageId, options) {
18829
18917
  if (message.vector && message.vector.length > 0) {
18830
18918
  return message;
18831
18919
  }
18832
- if (message.origin === NON_EMBEDDABLE_ORIGIN) {
18920
+ if (isNonEmbeddableOrigin(message.origin)) {
18833
18921
  return message;
18834
18922
  }
18835
18923
  if (isEncrypted(message.content)) {
@@ -18865,7 +18953,7 @@ async function embedAllMessages(ctx, options, filter) {
18865
18953
  if (message.role === "system") {
18866
18954
  continue;
18867
18955
  }
18868
- if (message.origin === NON_EMBEDDABLE_ORIGIN) {
18956
+ if (isNonEmbeddableOrigin(message.origin, filter?.reembedDiscarded)) {
18869
18957
  continue;
18870
18958
  }
18871
18959
  considered++;
@@ -18905,7 +18993,7 @@ async function chunkAndEmbedMessage(ctx, messageId, options) {
18905
18993
  if (message.chunks && message.chunks.length > 0) {
18906
18994
  return message;
18907
18995
  }
18908
- if (message.origin === NON_EMBEDDABLE_ORIGIN) {
18996
+ if (isNonEmbeddableOrigin(message.origin)) {
18909
18997
  return message;
18910
18998
  }
18911
18999
  if (isEncrypted(message.content)) {
@@ -18953,7 +19041,7 @@ async function chunkAndEmbedAllMessages(ctx, options, filter) {
18953
19041
  if (hasVector && !filter?.rechunkExisting && !isStale) continue;
18954
19042
  if (filter?.roles && !filter.roles.includes(message.role)) continue;
18955
19043
  if (message.role === "system") continue;
18956
- if (message.origin === NON_EMBEDDABLE_ORIGIN) continue;
19044
+ if (isNonEmbeddableOrigin(message.origin, filter?.reembedDiscarded)) continue;
18957
19045
  considered++;
18958
19046
  if (isEncrypted(message.content)) {
18959
19047
  stillEncrypted++;
@@ -20757,7 +20845,7 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
20757
20845
  subQueries = decomp.subQueries;
20758
20846
  }
20759
20847
  }
20760
- const { recall: recall2 } = await import("./recall-IVV6EILK.mjs");
20848
+ const { recall: recall2 } = await import("./recall-CGDEW2LQ.mjs");
20761
20849
  let recallDegraded = [];
20762
20850
  const result = await recall2(
20763
20851
  query,
@@ -21746,6 +21834,8 @@ export {
21746
21834
  encryptJsonField,
21747
21835
  decryptJsonField,
21748
21836
  cosineSimilarity,
21837
+ dataUrlToArrayBuffer,
21838
+ uint8ArrayToBase64,
21749
21839
  stripToolCalls,
21750
21840
  generateConversationId,
21751
21841
  conversationToStoredRaw,
@@ -32,6 +32,14 @@ function validateEndpointOverride(override) {
32
32
  return { valid: true, endpoint: trimmed.startsWith("/") ? trimmed : `/${trimmed}` };
33
33
  }
34
34
 
35
+ // src/lib/internalFlowMarker.ts
36
+ var INTERNAL_FLOW_MARKER = "Anuma internal first-party flow (not user chat).";
37
+ function withInternalFlowMarker(systemPrompt) {
38
+ if (systemPrompt.includes(INTERNAL_FLOW_MARKER)) return systemPrompt;
39
+ return `${INTERNAL_FLOW_MARKER}
40
+ ${systemPrompt}`;
41
+ }
42
+
35
43
  // src/lib/memory/portalLlm.ts
36
44
  function defaultBaseUrl() {
37
45
  return typeof process !== "undefined" && process.env?.ANUMA_PORTAL_BASE_URL || BASE_URL;
@@ -138,7 +146,12 @@ async function attemptPortalJson(req, endpoint) {
138
146
  const isAnthropic = req.model.startsWith("anthropic/");
139
147
  const prefill = isAnthropic ? "{" : "";
140
148
  const messages = [
141
- { role: "system", content: req.systemPrompt },
149
+ // Every caller of this helper is a first-party BACKGROUND op (fact extraction,
150
+ // topic sweep, consolidation, classifiers, graph traversal, query
151
+ // decomposition). Marking here — the one place they all funnel through — is what
152
+ // keeps the portal's detector reading them as genuine rather than markerless.
153
+ // See ../internalFlowMarker.
154
+ { role: "system", content: withInternalFlowMarker(req.systemPrompt) },
142
155
  { role: "user", content: req.userMessage }
143
156
  ];
144
157
  if (prefill) messages.push({ role: "assistant", content: prefill });
@@ -273,6 +286,8 @@ function extractCompletionContent(body) {
273
286
 
274
287
  export {
275
288
  getLogger,
289
+ INTERNAL_FLOW_MARKER,
290
+ withInternalFlowMarker,
276
291
  validateEndpointOverride,
277
292
  supportsResponseFormat,
278
293
  resolvePortalAuthHeaders,
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  notifyConsolidationFallback,
3
3
  resolvePiiRedactor
4
- } from "./chunk-KF4HV3QE.mjs";
4
+ } from "./chunk-CR5P3YIK.mjs";
5
5
  import {
6
6
  callPortalJsonCompletion
7
- } from "./chunk-OBDRKQQI.mjs";
7
+ } from "./chunk-VHWLLYKO.mjs";
8
8
  import "./chunk-3RPGXXPZ.mjs";
9
9
 
10
10
  // src/lib/memory/consolidate.ts