@anuma/sdk 3.8.1 → 3.8.3

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.
@@ -2531,7 +2531,7 @@ async function getUnfiledVaultMemoriesOp(ctx) {
2531
2531
  (record) => vaultMemoryToStored(record, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
2532
2532
  );
2533
2533
  }
2534
- var TOPICS_EXTRACTION_VERSION = 1;
2534
+ var TOPICS_EXTRACTION_VERSION = 2;
2535
2535
  async function getMemoriesNeedingTopicExtractionOp(ctx, options) {
2536
2536
  const entityCtx = ctx.entityCtx;
2537
2537
  if (!entityCtx) {
@@ -5363,7 +5363,7 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
5363
5363
  legacy.map((r) => ({ id: r.uniqueId, content: r.content, score: r.similarity }))
5364
5364
  );
5365
5365
  }
5366
- const { recall: recall2 } = await import("./recall-YVU7OSSJ.mjs");
5366
+ const { recall: recall2 } = await import("./recall-MUFOZB6P.mjs");
5367
5367
  const result = await recall2(
5368
5368
  query,
5369
5369
  { vaultCtx, embeddingOptions, vaultCache: cache },
@@ -4997,7 +4997,7 @@ var init_operations3 = __esm({
4997
4997
  init_operations2();
4998
4998
  init_encryption2();
4999
4999
  KNOWN_TRUST_TIERS = /* @__PURE__ */ new Set(["quarantined", "trusted"]);
5000
- TOPICS_EXTRACTION_VERSION = 1;
5000
+ TOPICS_EXTRACTION_VERSION = 2;
5001
5001
  }
5002
5002
  });
5003
5003
 
@@ -16027,14 +16027,15 @@ init_portalLlm();
16027
16027
  var TOPIC_EXTRACTION_BATCH_SIZE = 10;
16028
16028
  var MAX_CHARS_PER_MEMORY = 300;
16029
16029
  var MAX_VOCABULARY_NAMES = 100;
16030
+ var MAX_COMPLETION_TOKENS = 8192;
16030
16031
  var SYSTEM_PROMPT6 = `You assign topics to saved memories for a personal memory system.
16031
16032
 
16032
16033
  Each memory is a short statement about the user. For each memory, list the NAMED entities it mentions \u2014 these become the memory's topics, used to connect related memories in a knowledge graph.
16033
16034
 
16034
16035
  Include only NAMED entities, skip generic/common nouns. ${ENTITY_KIND_GUIDELINES}
16035
16036
 
16036
- Output strict JSON: {"memories": [{"id": string, "entities": [{"name": string, "kind": string}]}]}
16037
- - exactly one element per input memory, echoing its id verbatim
16037
+ Each memory below is written as "<id>: <text>". Output strict JSON: {"memories": [{"id": string, "entities": [{"name": string, "kind": string}]}]}
16038
+ - exactly one element per input memory; copy its id EXACTLY as written (the token before the first ": "), with no brackets, quotes, or extra characters
16038
16039
  - "entities" may be empty when a memory mentions no named entities \u2014 most short memories have 0-3
16039
16040
  No prose.`;
16040
16041
  async function extractEntitiesForMemories(memories, options) {
@@ -16049,8 +16050,8 @@ When a memory refers to one of these, reuse the EXACT existing name (same spelli
16049
16050
  for (let i = 0; i < memories.length; i += TOPIC_EXTRACTION_BATCH_SIZE) {
16050
16051
  const batch = memories.slice(i, i + TOPIC_EXTRACTION_BATCH_SIZE);
16051
16052
  const listing = batch.map((m) => {
16052
- const content = m.content.slice(0, MAX_CHARS_PER_MEMORY);
16053
- return `[${m.id}] ${redactor ? redactor.redactText(content).text : content}`;
16053
+ const content = m.content.slice(0, MAX_CHARS_PER_MEMORY).replace(/\s+/g, " ").trim();
16054
+ return `${m.id}: ${redactor ? redactor.redactText(content).text : content}`;
16054
16055
  }).join("\n");
16055
16056
  const parsed = await callPortalJsonCompletion({
16056
16057
  ...options.apiKey !== void 0 && { apiKey: options.apiKey },
@@ -16066,6 +16067,7 @@ ${listing}
16066
16067
 
16067
16068
  List each memory's named entities.`,
16068
16069
  tag: "memory/topics",
16070
+ extra: { max_completion_tokens: MAX_COMPLETION_TOKENS },
16069
16071
  ...options.fetchFn && { fetchFn: options.fetchFn },
16070
16072
  ...options.maxAttempts !== void 0 && { maxAttempts: options.maxAttempts },
16071
16073
  ...options.timeoutMs !== void 0 && { timeoutMs: options.timeoutMs },
@@ -16109,9 +16111,11 @@ function parseTopicResponse(parsed, validIds) {
16109
16111
  for (const raw of list) {
16110
16112
  if (typeof raw !== "object" || raw === null) continue;
16111
16113
  const obj = raw;
16112
- if (typeof obj.id !== "string" || !validIds.has(obj.id) || out.has(obj.id)) continue;
16114
+ if (typeof obj.id !== "string") continue;
16115
+ const id = obj.id.trim().replace(/:$/, "").replace(/^\[([\s\S]*)\]$/, "$1").trim();
16116
+ if (!validIds.has(id) || out.has(id)) continue;
16113
16117
  const entities = Array.isArray(obj.entities) ? parseEntities(obj.entities) : [];
16114
- out.set(obj.id, entities);
16118
+ out.set(id, entities);
16115
16119
  }
16116
16120
  return out;
16117
16121
  }
@@ -5879,7 +5879,7 @@ declare function getUnfiledVaultMemoriesOp(ctx: VaultMemoryOperationsContext): P
5879
5879
  * by the next sweep, so topic-quality improvements propagate across the existing
5880
5880
  * vault. The worker's `limit` drains that re-extraction across sweeps.
5881
5881
  */
5882
- declare const TOPICS_EXTRACTION_VERSION = 1;
5882
+ declare const TOPICS_EXTRACTION_VERSION = 2;
5883
5883
  /**
5884
5884
  * Result of {@link getMemoriesNeedingTopicExtractionOp}: which memories the
5885
5885
  * background topic worker should run LLM entity extraction on, and which it
@@ -5879,7 +5879,7 @@ declare function getUnfiledVaultMemoriesOp(ctx: VaultMemoryOperationsContext): P
5879
5879
  * by the next sweep, so topic-quality improvements propagate across the existing
5880
5880
  * vault. The worker's `limit` drains that re-extraction across sweeps.
5881
5881
  */
5882
- declare const TOPICS_EXTRACTION_VERSION = 1;
5882
+ declare const TOPICS_EXTRACTION_VERSION = 2;
5883
5883
  /**
5884
5884
  * Result of {@link getMemoriesNeedingTopicExtractionOp}: which memories the
5885
5885
  * background topic worker should run LLM entity extraction on, and which it
@@ -108,7 +108,7 @@ import {
108
108
  upsertMessageOp,
109
109
  useEncryption,
110
110
  vaultMemoryToStored
111
- } from "./chunk-AAB7OG7Q.mjs";
111
+ } from "./chunk-IFZZQPRO.mjs";
112
112
  import {
113
113
  PII_PATTERNS,
114
114
  PiiRedactor,
@@ -8162,14 +8162,15 @@ function extractFacetText(structured) {
8162
8162
  var TOPIC_EXTRACTION_BATCH_SIZE = 10;
8163
8163
  var MAX_CHARS_PER_MEMORY = 300;
8164
8164
  var MAX_VOCABULARY_NAMES = 100;
8165
+ var MAX_COMPLETION_TOKENS = 8192;
8165
8166
  var SYSTEM_PROMPT4 = `You assign topics to saved memories for a personal memory system.
8166
8167
 
8167
8168
  Each memory is a short statement about the user. For each memory, list the NAMED entities it mentions \u2014 these become the memory's topics, used to connect related memories in a knowledge graph.
8168
8169
 
8169
8170
  Include only NAMED entities, skip generic/common nouns. ${ENTITY_KIND_GUIDELINES}
8170
8171
 
8171
- Output strict JSON: {"memories": [{"id": string, "entities": [{"name": string, "kind": string}]}]}
8172
- - exactly one element per input memory, echoing its id verbatim
8172
+ Each memory below is written as "<id>: <text>". Output strict JSON: {"memories": [{"id": string, "entities": [{"name": string, "kind": string}]}]}
8173
+ - exactly one element per input memory; copy its id EXACTLY as written (the token before the first ": "), with no brackets, quotes, or extra characters
8173
8174
  - "entities" may be empty when a memory mentions no named entities \u2014 most short memories have 0-3
8174
8175
  No prose.`;
8175
8176
  async function extractEntitiesForMemories(memories, options) {
@@ -8184,8 +8185,8 @@ When a memory refers to one of these, reuse the EXACT existing name (same spelli
8184
8185
  for (let i = 0; i < memories.length; i += TOPIC_EXTRACTION_BATCH_SIZE) {
8185
8186
  const batch = memories.slice(i, i + TOPIC_EXTRACTION_BATCH_SIZE);
8186
8187
  const listing = batch.map((m) => {
8187
- const content = m.content.slice(0, MAX_CHARS_PER_MEMORY);
8188
- return `[${m.id}] ${redactor ? redactor.redactText(content).text : content}`;
8188
+ const content = m.content.slice(0, MAX_CHARS_PER_MEMORY).replace(/\s+/g, " ").trim();
8189
+ return `${m.id}: ${redactor ? redactor.redactText(content).text : content}`;
8189
8190
  }).join("\n");
8190
8191
  const parsed = await callPortalJsonCompletion({
8191
8192
  ...options.apiKey !== void 0 && { apiKey: options.apiKey },
@@ -8201,6 +8202,7 @@ ${listing}
8201
8202
 
8202
8203
  List each memory's named entities.`,
8203
8204
  tag: "memory/topics",
8205
+ extra: { max_completion_tokens: MAX_COMPLETION_TOKENS },
8204
8206
  ...options.fetchFn && { fetchFn: options.fetchFn },
8205
8207
  ...options.maxAttempts !== void 0 && { maxAttempts: options.maxAttempts },
8206
8208
  ...options.timeoutMs !== void 0 && { timeoutMs: options.timeoutMs },
@@ -8244,9 +8246,11 @@ function parseTopicResponse(parsed, validIds) {
8244
8246
  for (const raw of list) {
8245
8247
  if (typeof raw !== "object" || raw === null) continue;
8246
8248
  const obj = raw;
8247
- if (typeof obj.id !== "string" || !validIds.has(obj.id) || out.has(obj.id)) continue;
8249
+ if (typeof obj.id !== "string") continue;
8250
+ const id = obj.id.trim().replace(/:$/, "").replace(/^\[([\s\S]*)\]$/, "$1").trim();
8251
+ if (!validIds.has(id) || out.has(id)) continue;
8248
8252
  const entities = Array.isArray(obj.entities) ? parseEntities(obj.entities) : [];
8249
- out.set(obj.id, entities);
8253
+ out.set(id, entities);
8250
8254
  }
8251
8255
  return out;
8252
8256
  }
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  recall
3
- } from "./chunk-AAB7OG7Q.mjs";
3
+ } from "./chunk-IFZZQPRO.mjs";
4
4
  import "./chunk-BOY27A2C.mjs";
5
5
  import "./chunk-GYKJOWEO.mjs";
6
6
  export {
@@ -2738,7 +2738,7 @@ async function getUnfiledVaultMemoriesOp(ctx) {
2738
2738
  (record) => vaultMemoryToStored(record, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
2739
2739
  );
2740
2740
  }
2741
- var TOPICS_EXTRACTION_VERSION = 1;
2741
+ var TOPICS_EXTRACTION_VERSION = 2;
2742
2742
  async function getMemoriesNeedingTopicExtractionOp(ctx, options) {
2743
2743
  const entityCtx = ctx.entityCtx;
2744
2744
  if (!entityCtx) {
@@ -5641,7 +5641,7 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
5641
5641
  legacy.map((r) => ({ id: r.uniqueId, content: r.content, score: r.similarity }))
5642
5642
  );
5643
5643
  }
5644
- const { recall: recall2 } = await import("./recall-CCA4VTDK.mjs");
5644
+ const { recall: recall2 } = await import("./recall-JUERXQA7.mjs");
5645
5645
  const result = await recall2(
5646
5646
  query,
5647
5647
  { vaultCtx, embeddingOptions, vaultCache: cache },
@@ -5275,7 +5275,7 @@ var init_operations3 = __esm({
5275
5275
  init_operations2();
5276
5276
  init_encryption2();
5277
5277
  KNOWN_TRUST_TIERS = /* @__PURE__ */ new Set(["quarantined", "trusted"]);
5278
- TOPICS_EXTRACTION_VERSION = 1;
5278
+ TOPICS_EXTRACTION_VERSION = 2;
5279
5279
  }
5280
5280
  });
5281
5281
 
@@ -17317,14 +17317,15 @@ init_portalLlm();
17317
17317
  var TOPIC_EXTRACTION_BATCH_SIZE = 10;
17318
17318
  var MAX_CHARS_PER_MEMORY = 300;
17319
17319
  var MAX_VOCABULARY_NAMES = 100;
17320
+ var MAX_COMPLETION_TOKENS = 8192;
17320
17321
  var SYSTEM_PROMPT6 = `You assign topics to saved memories for a personal memory system.
17321
17322
 
17322
17323
  Each memory is a short statement about the user. For each memory, list the NAMED entities it mentions \u2014 these become the memory's topics, used to connect related memories in a knowledge graph.
17323
17324
 
17324
17325
  Include only NAMED entities, skip generic/common nouns. ${ENTITY_KIND_GUIDELINES}
17325
17326
 
17326
- Output strict JSON: {"memories": [{"id": string, "entities": [{"name": string, "kind": string}]}]}
17327
- - exactly one element per input memory, echoing its id verbatim
17327
+ Each memory below is written as "<id>: <text>". Output strict JSON: {"memories": [{"id": string, "entities": [{"name": string, "kind": string}]}]}
17328
+ - exactly one element per input memory; copy its id EXACTLY as written (the token before the first ": "), with no brackets, quotes, or extra characters
17328
17329
  - "entities" may be empty when a memory mentions no named entities \u2014 most short memories have 0-3
17329
17330
  No prose.`;
17330
17331
  async function extractEntitiesForMemories(memories, options) {
@@ -17339,8 +17340,8 @@ When a memory refers to one of these, reuse the EXACT existing name (same spelli
17339
17340
  for (let i = 0; i < memories.length; i += TOPIC_EXTRACTION_BATCH_SIZE) {
17340
17341
  const batch = memories.slice(i, i + TOPIC_EXTRACTION_BATCH_SIZE);
17341
17342
  const listing = batch.map((m) => {
17342
- const content = m.content.slice(0, MAX_CHARS_PER_MEMORY);
17343
- return `[${m.id}] ${redactor ? redactor.redactText(content).text : content}`;
17343
+ const content = m.content.slice(0, MAX_CHARS_PER_MEMORY).replace(/\s+/g, " ").trim();
17344
+ return `${m.id}: ${redactor ? redactor.redactText(content).text : content}`;
17344
17345
  }).join("\n");
17345
17346
  const parsed = await callPortalJsonCompletion({
17346
17347
  ...options.apiKey !== void 0 && { apiKey: options.apiKey },
@@ -17356,6 +17357,7 @@ ${listing}
17356
17357
 
17357
17358
  List each memory's named entities.`,
17358
17359
  tag: "memory/topics",
17360
+ extra: { max_completion_tokens: MAX_COMPLETION_TOKENS },
17359
17361
  ...options.fetchFn && { fetchFn: options.fetchFn },
17360
17362
  ...options.maxAttempts !== void 0 && { maxAttempts: options.maxAttempts },
17361
17363
  ...options.timeoutMs !== void 0 && { timeoutMs: options.timeoutMs },
@@ -17399,9 +17401,11 @@ function parseTopicResponse(parsed, validIds) {
17399
17401
  for (const raw of list) {
17400
17402
  if (typeof raw !== "object" || raw === null) continue;
17401
17403
  const obj = raw;
17402
- if (typeof obj.id !== "string" || !validIds.has(obj.id) || out.has(obj.id)) continue;
17404
+ if (typeof obj.id !== "string") continue;
17405
+ const id = obj.id.trim().replace(/:$/, "").replace(/^\[([\s\S]*)\]$/, "$1").trim();
17406
+ if (!validIds.has(id) || out.has(id)) continue;
17403
17407
  const entities = Array.isArray(obj.entities) ? parseEntities(obj.entities) : [];
17404
- out.set(obj.id, entities);
17408
+ out.set(id, entities);
17405
17409
  }
17406
17410
  return out;
17407
17411
  }
@@ -7208,7 +7208,7 @@ declare function getUnfiledVaultMemoriesOp(ctx: VaultMemoryOperationsContext): P
7208
7208
  * by the next sweep, so topic-quality improvements propagate across the existing
7209
7209
  * vault. The worker's `limit` drains that re-extraction across sweeps.
7210
7210
  */
7211
- declare const TOPICS_EXTRACTION_VERSION = 1;
7211
+ declare const TOPICS_EXTRACTION_VERSION = 2;
7212
7212
  /**
7213
7213
  * Result of {@link getMemoriesNeedingTopicExtractionOp}: which memories the
7214
7214
  * background topic worker should run LLM entity extraction on, and which it
@@ -7208,7 +7208,7 @@ declare function getUnfiledVaultMemoriesOp(ctx: VaultMemoryOperationsContext): P
7208
7208
  * by the next sweep, so topic-quality improvements propagate across the existing
7209
7209
  * vault. The worker's `limit` drains that re-extraction across sweeps.
7210
7210
  */
7211
- declare const TOPICS_EXTRACTION_VERSION = 1;
7211
+ declare const TOPICS_EXTRACTION_VERSION = 2;
7212
7212
  /**
7213
7213
  * Result of {@link getMemoriesNeedingTopicExtractionOp}: which memories the
7214
7214
  * background topic worker should run LLM entity extraction on, and which it
@@ -149,7 +149,7 @@ import {
149
149
  updateVaultMemoryOp,
150
150
  useEncryption,
151
151
  vaultMemoryToStored
152
- } from "./chunk-3LUACMDC.mjs";
152
+ } from "./chunk-35BHTCK4.mjs";
153
153
  import {
154
154
  PiiRedactor,
155
155
  createStreamingDeAnonymizer,
@@ -8975,14 +8975,15 @@ function extractFacetText(structured) {
8975
8975
  var TOPIC_EXTRACTION_BATCH_SIZE = 10;
8976
8976
  var MAX_CHARS_PER_MEMORY = 300;
8977
8977
  var MAX_VOCABULARY_NAMES = 100;
8978
+ var MAX_COMPLETION_TOKENS = 8192;
8978
8979
  var SYSTEM_PROMPT4 = `You assign topics to saved memories for a personal memory system.
8979
8980
 
8980
8981
  Each memory is a short statement about the user. For each memory, list the NAMED entities it mentions \u2014 these become the memory's topics, used to connect related memories in a knowledge graph.
8981
8982
 
8982
8983
  Include only NAMED entities, skip generic/common nouns. ${ENTITY_KIND_GUIDELINES}
8983
8984
 
8984
- Output strict JSON: {"memories": [{"id": string, "entities": [{"name": string, "kind": string}]}]}
8985
- - exactly one element per input memory, echoing its id verbatim
8985
+ Each memory below is written as "<id>: <text>". Output strict JSON: {"memories": [{"id": string, "entities": [{"name": string, "kind": string}]}]}
8986
+ - exactly one element per input memory; copy its id EXACTLY as written (the token before the first ": "), with no brackets, quotes, or extra characters
8986
8987
  - "entities" may be empty when a memory mentions no named entities \u2014 most short memories have 0-3
8987
8988
  No prose.`;
8988
8989
  async function extractEntitiesForMemories(memories, options) {
@@ -8997,8 +8998,8 @@ When a memory refers to one of these, reuse the EXACT existing name (same spelli
8997
8998
  for (let i = 0; i < memories.length; i += TOPIC_EXTRACTION_BATCH_SIZE) {
8998
8999
  const batch = memories.slice(i, i + TOPIC_EXTRACTION_BATCH_SIZE);
8999
9000
  const listing = batch.map((m) => {
9000
- const content = m.content.slice(0, MAX_CHARS_PER_MEMORY);
9001
- return `[${m.id}] ${redactor ? redactor.redactText(content).text : content}`;
9001
+ const content = m.content.slice(0, MAX_CHARS_PER_MEMORY).replace(/\s+/g, " ").trim();
9002
+ return `${m.id}: ${redactor ? redactor.redactText(content).text : content}`;
9002
9003
  }).join("\n");
9003
9004
  const parsed = await callPortalJsonCompletion({
9004
9005
  ...options.apiKey !== void 0 && { apiKey: options.apiKey },
@@ -9014,6 +9015,7 @@ ${listing}
9014
9015
 
9015
9016
  List each memory's named entities.`,
9016
9017
  tag: "memory/topics",
9018
+ extra: { max_completion_tokens: MAX_COMPLETION_TOKENS },
9017
9019
  ...options.fetchFn && { fetchFn: options.fetchFn },
9018
9020
  ...options.maxAttempts !== void 0 && { maxAttempts: options.maxAttempts },
9019
9021
  ...options.timeoutMs !== void 0 && { timeoutMs: options.timeoutMs },
@@ -9057,9 +9059,11 @@ function parseTopicResponse(parsed, validIds) {
9057
9059
  for (const raw of list) {
9058
9060
  if (typeof raw !== "object" || raw === null) continue;
9059
9061
  const obj = raw;
9060
- if (typeof obj.id !== "string" || !validIds.has(obj.id) || out.has(obj.id)) continue;
9062
+ if (typeof obj.id !== "string") continue;
9063
+ const id = obj.id.trim().replace(/:$/, "").replace(/^\[([\s\S]*)\]$/, "$1").trim();
9064
+ if (!validIds.has(id) || out.has(id)) continue;
9061
9065
  const entities = Array.isArray(obj.entities) ? parseEntities(obj.entities) : [];
9062
- out.set(obj.id, entities);
9066
+ out.set(id, entities);
9063
9067
  }
9064
9068
  return out;
9065
9069
  }
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  recall
3
- } from "./chunk-3LUACMDC.mjs";
3
+ } from "./chunk-35BHTCK4.mjs";
4
4
  import "./chunk-BOY27A2C.mjs";
5
5
  import "./chunk-GYKJOWEO.mjs";
6
6
  export {
@@ -16733,7 +16733,7 @@ async function getUnfiledVaultMemoriesOp(ctx) {
16733
16733
  (record) => vaultMemoryToStored(record, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
16734
16734
  );
16735
16735
  }
16736
- var TOPICS_EXTRACTION_VERSION = 1;
16736
+ var TOPICS_EXTRACTION_VERSION = 2;
16737
16737
  async function getMemoriesNeedingTopicExtractionOp(ctx, options) {
16738
16738
  const entityCtx = ctx.entityCtx;
16739
16739
  if (!entityCtx) {
@@ -19554,7 +19554,7 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
19554
19554
  legacy.map((r) => ({ id: r.uniqueId, content: r.content, score: r.similarity }))
19555
19555
  );
19556
19556
  }
19557
- const { recall: recall2 } = await import("./recall-XEOLXA6P.mjs");
19557
+ const { recall: recall2 } = await import("./recall-XZ6WLFPJ.mjs");
19558
19558
  const result = await recall2(
19559
19559
  query,
19560
19560
  { vaultCtx, embeddingOptions, vaultCache: cache },
@@ -17764,7 +17764,7 @@ var init_operations3 = __esm({
17764
17764
  init_operations2();
17765
17765
  init_encryption2();
17766
17766
  KNOWN_TRUST_TIERS = /* @__PURE__ */ new Set(["quarantined", "trusted"]);
17767
- TOPICS_EXTRACTION_VERSION = 1;
17767
+ TOPICS_EXTRACTION_VERSION = 2;
17768
17768
  }
17769
17769
  });
17770
17770
 
@@ -29183,14 +29183,15 @@ init_portalLlm();
29183
29183
  var TOPIC_EXTRACTION_BATCH_SIZE = 10;
29184
29184
  var MAX_CHARS_PER_MEMORY = 300;
29185
29185
  var MAX_VOCABULARY_NAMES = 100;
29186
+ var MAX_COMPLETION_TOKENS = 8192;
29186
29187
  var SYSTEM_PROMPT6 = `You assign topics to saved memories for a personal memory system.
29187
29188
 
29188
29189
  Each memory is a short statement about the user. For each memory, list the NAMED entities it mentions \u2014 these become the memory's topics, used to connect related memories in a knowledge graph.
29189
29190
 
29190
29191
  Include only NAMED entities, skip generic/common nouns. ${ENTITY_KIND_GUIDELINES}
29191
29192
 
29192
- Output strict JSON: {"memories": [{"id": string, "entities": [{"name": string, "kind": string}]}]}
29193
- - exactly one element per input memory, echoing its id verbatim
29193
+ Each memory below is written as "<id>: <text>". Output strict JSON: {"memories": [{"id": string, "entities": [{"name": string, "kind": string}]}]}
29194
+ - exactly one element per input memory; copy its id EXACTLY as written (the token before the first ": "), with no brackets, quotes, or extra characters
29194
29195
  - "entities" may be empty when a memory mentions no named entities \u2014 most short memories have 0-3
29195
29196
  No prose.`;
29196
29197
  async function extractEntitiesForMemories(memories, options) {
@@ -29205,8 +29206,8 @@ When a memory refers to one of these, reuse the EXACT existing name (same spelli
29205
29206
  for (let i = 0; i < memories.length; i += TOPIC_EXTRACTION_BATCH_SIZE) {
29206
29207
  const batch = memories.slice(i, i + TOPIC_EXTRACTION_BATCH_SIZE);
29207
29208
  const listing = batch.map((m) => {
29208
- const content = m.content.slice(0, MAX_CHARS_PER_MEMORY);
29209
- return `[${m.id}] ${redactor ? redactor.redactText(content).text : content}`;
29209
+ const content = m.content.slice(0, MAX_CHARS_PER_MEMORY).replace(/\s+/g, " ").trim();
29210
+ return `${m.id}: ${redactor ? redactor.redactText(content).text : content}`;
29210
29211
  }).join("\n");
29211
29212
  const parsed = await callPortalJsonCompletion({
29212
29213
  ...options.apiKey !== void 0 && { apiKey: options.apiKey },
@@ -29222,6 +29223,7 @@ ${listing}
29222
29223
 
29223
29224
  List each memory's named entities.`,
29224
29225
  tag: "memory/topics",
29226
+ extra: { max_completion_tokens: MAX_COMPLETION_TOKENS },
29225
29227
  ...options.fetchFn && { fetchFn: options.fetchFn },
29226
29228
  ...options.maxAttempts !== void 0 && { maxAttempts: options.maxAttempts },
29227
29229
  ...options.timeoutMs !== void 0 && { timeoutMs: options.timeoutMs },
@@ -29265,9 +29267,11 @@ function parseTopicResponse(parsed, validIds) {
29265
29267
  for (const raw of list) {
29266
29268
  if (typeof raw !== "object" || raw === null) continue;
29267
29269
  const obj = raw;
29268
- if (typeof obj.id !== "string" || !validIds.has(obj.id) || out.has(obj.id)) continue;
29270
+ if (typeof obj.id !== "string") continue;
29271
+ const id = obj.id.trim().replace(/:$/, "").replace(/^\[([\s\S]*)\]$/, "$1").trim();
29272
+ if (!validIds.has(id) || out.has(id)) continue;
29269
29273
  const entities = Array.isArray(obj.entities) ? parseEntities(obj.entities) : [];
29270
- out.set(obj.id, entities);
29274
+ out.set(id, entities);
29271
29275
  }
29272
29276
  return out;
29273
29277
  }
@@ -5805,7 +5805,7 @@ declare function getUnfiledVaultMemoriesOp(ctx: VaultMemoryOperationsContext): P
5805
5805
  * by the next sweep, so topic-quality improvements propagate across the existing
5806
5806
  * vault. The worker's `limit` drains that re-extraction across sweeps.
5807
5807
  */
5808
- declare const TOPICS_EXTRACTION_VERSION = 1;
5808
+ declare const TOPICS_EXTRACTION_VERSION = 2;
5809
5809
  /**
5810
5810
  * Result of {@link getMemoriesNeedingTopicExtractionOp}: which memories the
5811
5811
  * background topic worker should run LLM entity extraction on, and which it
@@ -5805,7 +5805,7 @@ declare function getUnfiledVaultMemoriesOp(ctx: VaultMemoryOperationsContext): P
5805
5805
  * by the next sweep, so topic-quality improvements propagate across the existing
5806
5806
  * vault. The worker's `limit` drains that re-extraction across sweeps.
5807
5807
  */
5808
- declare const TOPICS_EXTRACTION_VERSION = 1;
5808
+ declare const TOPICS_EXTRACTION_VERSION = 2;
5809
5809
  /**
5810
5810
  * Result of {@link getMemoriesNeedingTopicExtractionOp}: which memories the
5811
5811
  * background topic worker should run LLM entity extraction on, and which it
@@ -125,7 +125,7 @@ import {
125
125
  updateVaultMemoryOp,
126
126
  upsertMessageOp,
127
127
  vaultMemoryToStored
128
- } from "./chunk-LSKFJNLF.mjs";
128
+ } from "./chunk-GKN5NJKZ.mjs";
129
129
  import {
130
130
  createStreamingDeAnonymizer,
131
131
  resolvePiiRedactor
@@ -7063,14 +7063,15 @@ function extractFacetText(structured) {
7063
7063
  var TOPIC_EXTRACTION_BATCH_SIZE = 10;
7064
7064
  var MAX_CHARS_PER_MEMORY = 300;
7065
7065
  var MAX_VOCABULARY_NAMES = 100;
7066
+ var MAX_COMPLETION_TOKENS = 8192;
7066
7067
  var SYSTEM_PROMPT4 = `You assign topics to saved memories for a personal memory system.
7067
7068
 
7068
7069
  Each memory is a short statement about the user. For each memory, list the NAMED entities it mentions \u2014 these become the memory's topics, used to connect related memories in a knowledge graph.
7069
7070
 
7070
7071
  Include only NAMED entities, skip generic/common nouns. ${ENTITY_KIND_GUIDELINES}
7071
7072
 
7072
- Output strict JSON: {"memories": [{"id": string, "entities": [{"name": string, "kind": string}]}]}
7073
- - exactly one element per input memory, echoing its id verbatim
7073
+ Each memory below is written as "<id>: <text>". Output strict JSON: {"memories": [{"id": string, "entities": [{"name": string, "kind": string}]}]}
7074
+ - exactly one element per input memory; copy its id EXACTLY as written (the token before the first ": "), with no brackets, quotes, or extra characters
7074
7075
  - "entities" may be empty when a memory mentions no named entities \u2014 most short memories have 0-3
7075
7076
  No prose.`;
7076
7077
  async function extractEntitiesForMemories(memories, options) {
@@ -7085,8 +7086,8 @@ When a memory refers to one of these, reuse the EXACT existing name (same spelli
7085
7086
  for (let i = 0; i < memories.length; i += TOPIC_EXTRACTION_BATCH_SIZE) {
7086
7087
  const batch = memories.slice(i, i + TOPIC_EXTRACTION_BATCH_SIZE);
7087
7088
  const listing = batch.map((m) => {
7088
- const content = m.content.slice(0, MAX_CHARS_PER_MEMORY);
7089
- return `[${m.id}] ${redactor ? redactor.redactText(content).text : content}`;
7089
+ const content = m.content.slice(0, MAX_CHARS_PER_MEMORY).replace(/\s+/g, " ").trim();
7090
+ return `${m.id}: ${redactor ? redactor.redactText(content).text : content}`;
7090
7091
  }).join("\n");
7091
7092
  const parsed = await callPortalJsonCompletion({
7092
7093
  ...options.apiKey !== void 0 && { apiKey: options.apiKey },
@@ -7102,6 +7103,7 @@ ${listing}
7102
7103
 
7103
7104
  List each memory's named entities.`,
7104
7105
  tag: "memory/topics",
7106
+ extra: { max_completion_tokens: MAX_COMPLETION_TOKENS },
7105
7107
  ...options.fetchFn && { fetchFn: options.fetchFn },
7106
7108
  ...options.maxAttempts !== void 0 && { maxAttempts: options.maxAttempts },
7107
7109
  ...options.timeoutMs !== void 0 && { timeoutMs: options.timeoutMs },
@@ -7145,9 +7147,11 @@ function parseTopicResponse(parsed, validIds) {
7145
7147
  for (const raw of list) {
7146
7148
  if (typeof raw !== "object" || raw === null) continue;
7147
7149
  const obj = raw;
7148
- if (typeof obj.id !== "string" || !validIds.has(obj.id) || out.has(obj.id)) continue;
7150
+ if (typeof obj.id !== "string") continue;
7151
+ const id = obj.id.trim().replace(/:$/, "").replace(/^\[([\s\S]*)\]$/, "$1").trim();
7152
+ if (!validIds.has(id) || out.has(id)) continue;
7149
7153
  const entities = Array.isArray(obj.entities) ? parseEntities(obj.entities) : [];
7150
- out.set(obj.id, entities);
7154
+ out.set(id, entities);
7151
7155
  }
7152
7156
  return out;
7153
7157
  }
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  recall
3
- } from "./chunk-LSKFJNLF.mjs";
3
+ } from "./chunk-GKN5NJKZ.mjs";
4
4
  import "./chunk-MIXEASUP.mjs";
5
5
  import "./chunk-3RPGXXPZ.mjs";
6
6
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anuma/sdk",
3
- "version": "3.8.1",
3
+ "version": "3.8.3",
4
4
  "description": "",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
@@ -140,6 +140,7 @@
140
140
  "check-exports": "publint && attw --pack --ignore-rules no-resolution false-cjs && node scripts/assert-no-client-self-import.mjs",
141
141
  "check": "pnpm run lint && pnpm run knip && pnpm run format && pnpm run generate",
142
142
  "eval:extraction": "tsx test/memory/src/extraction/benchmark.test.ts",
143
+ "eval:topic": "tsx test/memory/src/topic/benchmark.ts",
143
144
  "eval:consolidation": "tsx test/memory/src/consolidation/benchmark.test.ts"
144
145
  },
145
146
  "repository": {