@anuma/sdk 3.8.0 → 3.8.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.
@@ -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,
@@ -847,7 +847,7 @@ var CompletionsStrategy = class {
847
847
  model,
848
848
  stream,
849
849
  ...temperature !== void 0 && { temperature },
850
- ...maxOutputTokens !== void 0 && { max_tokens: maxOutputTokens },
850
+ ...maxOutputTokens !== void 0 && { max_completion_tokens: maxOutputTokens },
851
851
  ...tools && { tools },
852
852
  ...toolChoice && { tool_choice: toolChoice },
853
853
  ...portal && { portal }
@@ -7722,7 +7722,10 @@ ${evidence}`;
7722
7722
  headers: { ...authHeaders, "Content-Type": "application/json" },
7723
7723
  body: JSON.stringify({
7724
7724
  model,
7725
- max_tokens: maxTokens,
7725
+ // Modern OpenAI field; the portal reads only `max_completion_tokens`
7726
+ // (the deprecated `max_tokens` is silently ignored → falls back to the
7727
+ // portal's default output cap and truncates the answer).
7728
+ max_completion_tokens: maxTokens,
7726
7729
  messages: [
7727
7730
  { role: "system", content: systemPrompt },
7728
7731
  { role: "user", content: userMessage }
@@ -8159,14 +8162,15 @@ function extractFacetText(structured) {
8159
8162
  var TOPIC_EXTRACTION_BATCH_SIZE = 10;
8160
8163
  var MAX_CHARS_PER_MEMORY = 300;
8161
8164
  var MAX_VOCABULARY_NAMES = 100;
8165
+ var MAX_COMPLETION_TOKENS = 8192;
8162
8166
  var SYSTEM_PROMPT4 = `You assign topics to saved memories for a personal memory system.
8163
8167
 
8164
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.
8165
8169
 
8166
8170
  Include only NAMED entities, skip generic/common nouns. ${ENTITY_KIND_GUIDELINES}
8167
8171
 
8168
- Output strict JSON: {"memories": [{"id": string, "entities": [{"name": string, "kind": string}]}]}
8169
- - 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
8170
8174
  - "entities" may be empty when a memory mentions no named entities \u2014 most short memories have 0-3
8171
8175
  No prose.`;
8172
8176
  async function extractEntitiesForMemories(memories, options) {
@@ -8181,8 +8185,8 @@ When a memory refers to one of these, reuse the EXACT existing name (same spelli
8181
8185
  for (let i = 0; i < memories.length; i += TOPIC_EXTRACTION_BATCH_SIZE) {
8182
8186
  const batch = memories.slice(i, i + TOPIC_EXTRACTION_BATCH_SIZE);
8183
8187
  const listing = batch.map((m) => {
8184
- const content = m.content.slice(0, MAX_CHARS_PER_MEMORY);
8185
- 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}`;
8186
8190
  }).join("\n");
8187
8191
  const parsed = await callPortalJsonCompletion({
8188
8192
  ...options.apiKey !== void 0 && { apiKey: options.apiKey },
@@ -8198,6 +8202,7 @@ ${listing}
8198
8202
 
8199
8203
  List each memory's named entities.`,
8200
8204
  tag: "memory/topics",
8205
+ extra: { max_completion_tokens: MAX_COMPLETION_TOKENS },
8201
8206
  ...options.fetchFn && { fetchFn: options.fetchFn },
8202
8207
  ...options.maxAttempts !== void 0 && { maxAttempts: options.maxAttempts },
8203
8208
  ...options.timeoutMs !== void 0 && { timeoutMs: options.timeoutMs },
@@ -8241,9 +8246,11 @@ function parseTopicResponse(parsed, validIds) {
8241
8246
  for (const raw of list) {
8242
8247
  if (typeof raw !== "object" || raw === null) continue;
8243
8248
  const obj = raw;
8244
- 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;
8245
8252
  const entities = Array.isArray(obj.entities) ? parseEntities(obj.entities) : [];
8246
- out.set(obj.id, entities);
8253
+ out.set(id, entities);
8247
8254
  }
8248
8255
  return out;
8249
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 {
package/dist/index.d.mts CHANGED
@@ -1729,6 +1729,12 @@ type HandlersCreditBalanceResponse = {
1729
1729
  * Total credits ever received (1 credit = $0.01)
1730
1730
  */
1731
1731
  lifetime_credits: number;
1732
+ /**
1733
+ * NextResetDate is the next monthly credit refill date (ISO8601), keyed on the
1734
+ * credit_expiry_day anchor — the same anchor the monthly claim uses, NOT the grant
1735
+ * expires_at (which is anchor+1). Display-only; does not affect reset logic.
1736
+ */
1737
+ next_reset_date?: string;
1732
1738
  /**
1733
1739
  * "basic" or "pro"
1734
1740
  */
@@ -2130,13 +2136,22 @@ type HandlersSetSubscriptionTierRequest = {
2130
2136
  */
2131
2137
  app_id?: number;
2132
2138
  /**
2133
- * "basic" or "pro"
2139
+ * "month" or "year"; ignored for basic
2140
+ */
2141
+ interval?: string;
2142
+ /**
2143
+ * "basic", "starter", or "pro"
2134
2144
  */
2135
2145
  tier?: string;
2136
2146
  user_address?: string;
2137
2147
  };
2138
2148
  type HandlersSetSubscriptionTierResponse = {
2149
+ changed?: boolean;
2150
+ interval?: string;
2139
2151
  message?: string;
2152
+ scheduled_interval?: string;
2153
+ scheduled_tier?: string;
2154
+ status: string;
2140
2155
  success: boolean;
2141
2156
  tier: string;
2142
2157
  user_address: string;
@@ -2461,8 +2476,10 @@ type HandlersUserLookupEnrollment = {
2461
2476
  created_at?: string;
2462
2477
  id?: number;
2463
2478
  lifetime_credits?: number;
2479
+ payment_provider?: string;
2464
2480
  pro_activated_at?: string;
2465
2481
  starter_activated_at?: string;
2482
+ subscription_source?: string;
2466
2483
  subscription_tier?: string;
2467
2484
  updated_at?: string;
2468
2485
  };
@@ -2482,7 +2499,10 @@ type HandlersUserLookupResponse = {
2482
2499
  account?: HandlersUserLookupAccount;
2483
2500
  enrollments?: Array<HandlersUserLookupEnrollment>;
2484
2501
  portal_account_exists?: boolean;
2502
+ primary_app_id?: number;
2485
2503
  privy?: HandlersUserLookupPrivy;
2504
+ subscription?: HandlersSubscriptionStatusResponse;
2505
+ subscription_error?: string;
2486
2506
  text_registrations?: Array<HandlersUserLookupTextReg>;
2487
2507
  };
2488
2508
  type HandlersUserLookupTextReg = {
@@ -4321,14 +4341,30 @@ type PostApiV1AdminSubscriptionTierErrors = {
4321
4341
  * Unauthorized
4322
4342
  */
4323
4343
  401: ResponseErrorResponse;
4344
+ /**
4345
+ * Payment Required
4346
+ */
4347
+ 402: ResponseErrorResponse;
4324
4348
  /**
4325
4349
  * Not Found
4326
4350
  */
4327
4351
  404: ResponseErrorResponse;
4352
+ /**
4353
+ * Conflict
4354
+ */
4355
+ 409: ResponseErrorResponse;
4328
4356
  /**
4329
4357
  * Internal Server Error
4330
4358
  */
4331
4359
  500: ResponseErrorResponse;
4360
+ /**
4361
+ * Bad Gateway
4362
+ */
4363
+ 502: ResponseErrorResponse;
4364
+ /**
4365
+ * Service Unavailable
4366
+ */
4367
+ 503: ResponseErrorResponse;
4332
4368
  };
4333
4369
  type PostApiV1AdminSubscriptionTierError = PostApiV1AdminSubscriptionTierErrors[keyof PostApiV1AdminSubscriptionTierErrors];
4334
4370
  type PostApiV1AdminSubscriptionTierResponses = {
@@ -6704,7 +6740,7 @@ declare const postApiV1AdminSeedApps: <ThrowOnError extends boolean = false>(opt
6704
6740
  /**
6705
6741
  * Set user subscription tier
6706
6742
  *
6707
- * Sets a user's subscription tier (basic, starter, or pro). Requires admin API key.
6743
+ * Updates an existing Stripe subscription. Upgrades apply immediately, downgrades and basic-tier cancellations apply at period end. RevenueCat/staking users and users without an active Stripe subscription are rejected. Requires admin API key.
6708
6744
  */
6709
6745
  declare const postApiV1AdminSubscriptionTier: <ThrowOnError extends boolean = false>(options: Options<PostApiV1AdminSubscriptionTierData, ThrowOnError>) => RequestResult<PostApiV1AdminSubscriptionTierResponses, PostApiV1AdminSubscriptionTierErrors, ThrowOnError>;
6710
6746
  /**
package/dist/index.d.ts CHANGED
@@ -1729,6 +1729,12 @@ type HandlersCreditBalanceResponse = {
1729
1729
  * Total credits ever received (1 credit = $0.01)
1730
1730
  */
1731
1731
  lifetime_credits: number;
1732
+ /**
1733
+ * NextResetDate is the next monthly credit refill date (ISO8601), keyed on the
1734
+ * credit_expiry_day anchor — the same anchor the monthly claim uses, NOT the grant
1735
+ * expires_at (which is anchor+1). Display-only; does not affect reset logic.
1736
+ */
1737
+ next_reset_date?: string;
1732
1738
  /**
1733
1739
  * "basic" or "pro"
1734
1740
  */
@@ -2130,13 +2136,22 @@ type HandlersSetSubscriptionTierRequest = {
2130
2136
  */
2131
2137
  app_id?: number;
2132
2138
  /**
2133
- * "basic" or "pro"
2139
+ * "month" or "year"; ignored for basic
2140
+ */
2141
+ interval?: string;
2142
+ /**
2143
+ * "basic", "starter", or "pro"
2134
2144
  */
2135
2145
  tier?: string;
2136
2146
  user_address?: string;
2137
2147
  };
2138
2148
  type HandlersSetSubscriptionTierResponse = {
2149
+ changed?: boolean;
2150
+ interval?: string;
2139
2151
  message?: string;
2152
+ scheduled_interval?: string;
2153
+ scheduled_tier?: string;
2154
+ status: string;
2140
2155
  success: boolean;
2141
2156
  tier: string;
2142
2157
  user_address: string;
@@ -2461,8 +2476,10 @@ type HandlersUserLookupEnrollment = {
2461
2476
  created_at?: string;
2462
2477
  id?: number;
2463
2478
  lifetime_credits?: number;
2479
+ payment_provider?: string;
2464
2480
  pro_activated_at?: string;
2465
2481
  starter_activated_at?: string;
2482
+ subscription_source?: string;
2466
2483
  subscription_tier?: string;
2467
2484
  updated_at?: string;
2468
2485
  };
@@ -2482,7 +2499,10 @@ type HandlersUserLookupResponse = {
2482
2499
  account?: HandlersUserLookupAccount;
2483
2500
  enrollments?: Array<HandlersUserLookupEnrollment>;
2484
2501
  portal_account_exists?: boolean;
2502
+ primary_app_id?: number;
2485
2503
  privy?: HandlersUserLookupPrivy;
2504
+ subscription?: HandlersSubscriptionStatusResponse;
2505
+ subscription_error?: string;
2486
2506
  text_registrations?: Array<HandlersUserLookupTextReg>;
2487
2507
  };
2488
2508
  type HandlersUserLookupTextReg = {
@@ -4321,14 +4341,30 @@ type PostApiV1AdminSubscriptionTierErrors = {
4321
4341
  * Unauthorized
4322
4342
  */
4323
4343
  401: ResponseErrorResponse;
4344
+ /**
4345
+ * Payment Required
4346
+ */
4347
+ 402: ResponseErrorResponse;
4324
4348
  /**
4325
4349
  * Not Found
4326
4350
  */
4327
4351
  404: ResponseErrorResponse;
4352
+ /**
4353
+ * Conflict
4354
+ */
4355
+ 409: ResponseErrorResponse;
4328
4356
  /**
4329
4357
  * Internal Server Error
4330
4358
  */
4331
4359
  500: ResponseErrorResponse;
4360
+ /**
4361
+ * Bad Gateway
4362
+ */
4363
+ 502: ResponseErrorResponse;
4364
+ /**
4365
+ * Service Unavailable
4366
+ */
4367
+ 503: ResponseErrorResponse;
4332
4368
  };
4333
4369
  type PostApiV1AdminSubscriptionTierError = PostApiV1AdminSubscriptionTierErrors[keyof PostApiV1AdminSubscriptionTierErrors];
4334
4370
  type PostApiV1AdminSubscriptionTierResponses = {
@@ -6704,7 +6740,7 @@ declare const postApiV1AdminSeedApps: <ThrowOnError extends boolean = false>(opt
6704
6740
  /**
6705
6741
  * Set user subscription tier
6706
6742
  *
6707
- * Sets a user's subscription tier (basic, starter, or pro). Requires admin API key.
6743
+ * Updates an existing Stripe subscription. Upgrades apply immediately, downgrades and basic-tier cancellations apply at period end. RevenueCat/staking users and users without an active Stripe subscription are rejected. Requires admin API key.
6708
6744
  */
6709
6745
  declare const postApiV1AdminSubscriptionTier: <ThrowOnError extends boolean = false>(options: Options<PostApiV1AdminSubscriptionTierData, ThrowOnError>) => RequestResult<PostApiV1AdminSubscriptionTierResponses, PostApiV1AdminSubscriptionTierErrors, ThrowOnError>;
6710
6746
  /**
@@ -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-Z7BWJ67X.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
 
@@ -8977,7 +8977,7 @@ var CompletionsStrategy = class {
8977
8977
  model,
8978
8978
  stream,
8979
8979
  ...temperature !== void 0 && { temperature },
8980
- ...maxOutputTokens !== void 0 && { max_tokens: maxOutputTokens },
8980
+ ...maxOutputTokens !== void 0 && { max_completion_tokens: maxOutputTokens },
8981
8981
  ...tools && { tools },
8982
8982
  ...toolChoice && { tool_choice: toolChoice },
8983
8983
  ...portal && { portal }
@@ -16862,7 +16862,10 @@ ${evidence}`;
16862
16862
  headers: { ...authHeaders, "Content-Type": "application/json" },
16863
16863
  body: JSON.stringify({
16864
16864
  model,
16865
- max_tokens: maxTokens,
16865
+ // Modern OpenAI field; the portal reads only `max_completion_tokens`
16866
+ // (the deprecated `max_tokens` is silently ignored → falls back to the
16867
+ // portal's default output cap and truncates the answer).
16868
+ max_completion_tokens: maxTokens,
16866
16869
  messages: [
16867
16870
  { role: "system", content: systemPrompt },
16868
16871
  { role: "user", content: userMessage }
@@ -17314,14 +17317,15 @@ init_portalLlm();
17314
17317
  var TOPIC_EXTRACTION_BATCH_SIZE = 10;
17315
17318
  var MAX_CHARS_PER_MEMORY = 300;
17316
17319
  var MAX_VOCABULARY_NAMES = 100;
17320
+ var MAX_COMPLETION_TOKENS = 8192;
17317
17321
  var SYSTEM_PROMPT6 = `You assign topics to saved memories for a personal memory system.
17318
17322
 
17319
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.
17320
17324
 
17321
17325
  Include only NAMED entities, skip generic/common nouns. ${ENTITY_KIND_GUIDELINES}
17322
17326
 
17323
- Output strict JSON: {"memories": [{"id": string, "entities": [{"name": string, "kind": string}]}]}
17324
- - 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
17325
17329
  - "entities" may be empty when a memory mentions no named entities \u2014 most short memories have 0-3
17326
17330
  No prose.`;
17327
17331
  async function extractEntitiesForMemories(memories, options) {
@@ -17336,8 +17340,8 @@ When a memory refers to one of these, reuse the EXACT existing name (same spelli
17336
17340
  for (let i = 0; i < memories.length; i += TOPIC_EXTRACTION_BATCH_SIZE) {
17337
17341
  const batch = memories.slice(i, i + TOPIC_EXTRACTION_BATCH_SIZE);
17338
17342
  const listing = batch.map((m) => {
17339
- const content = m.content.slice(0, MAX_CHARS_PER_MEMORY);
17340
- 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}`;
17341
17345
  }).join("\n");
17342
17346
  const parsed = await callPortalJsonCompletion({
17343
17347
  ...options.apiKey !== void 0 && { apiKey: options.apiKey },
@@ -17353,6 +17357,7 @@ ${listing}
17353
17357
 
17354
17358
  List each memory's named entities.`,
17355
17359
  tag: "memory/topics",
17360
+ extra: { max_completion_tokens: MAX_COMPLETION_TOKENS },
17356
17361
  ...options.fetchFn && { fetchFn: options.fetchFn },
17357
17362
  ...options.maxAttempts !== void 0 && { maxAttempts: options.maxAttempts },
17358
17363
  ...options.timeoutMs !== void 0 && { timeoutMs: options.timeoutMs },
@@ -17396,9 +17401,11 @@ function parseTopicResponse(parsed, validIds) {
17396
17401
  for (const raw of list) {
17397
17402
  if (typeof raw !== "object" || raw === null) continue;
17398
17403
  const obj = raw;
17399
- 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;
17400
17407
  const entities = Array.isArray(obj.entities) ? parseEntities(obj.entities) : [];
17401
- out.set(obj.id, entities);
17408
+ out.set(id, entities);
17402
17409
  }
17403
17410
  return out;
17404
17411
  }
@@ -920,6 +920,12 @@ type HandlersCreditBalanceResponse = {
920
920
  * Total credits ever received (1 credit = $0.01)
921
921
  */
922
922
  lifetime_credits: number;
923
+ /**
924
+ * NextResetDate is the next monthly credit refill date (ISO8601), keyed on the
925
+ * credit_expiry_day anchor — the same anchor the monthly claim uses, NOT the grant
926
+ * expires_at (which is anchor+1). Display-only; does not affect reset logic.
927
+ */
928
+ next_reset_date?: string;
923
929
  /**
924
930
  * "basic" or "pro"
925
931
  */
@@ -7202,7 +7208,7 @@ declare function getUnfiledVaultMemoriesOp(ctx: VaultMemoryOperationsContext): P
7202
7208
  * by the next sweep, so topic-quality improvements propagate across the existing
7203
7209
  * vault. The worker's `limit` drains that re-extraction across sweeps.
7204
7210
  */
7205
- declare const TOPICS_EXTRACTION_VERSION = 1;
7211
+ declare const TOPICS_EXTRACTION_VERSION = 2;
7206
7212
  /**
7207
7213
  * Result of {@link getMemoriesNeedingTopicExtractionOp}: which memories the
7208
7214
  * background topic worker should run LLM entity extraction on, and which it
@@ -920,6 +920,12 @@ type HandlersCreditBalanceResponse = {
920
920
  * Total credits ever received (1 credit = $0.01)
921
921
  */
922
922
  lifetime_credits: number;
923
+ /**
924
+ * NextResetDate is the next monthly credit refill date (ISO8601), keyed on the
925
+ * credit_expiry_day anchor — the same anchor the monthly claim uses, NOT the grant
926
+ * expires_at (which is anchor+1). Display-only; does not affect reset logic.
927
+ */
928
+ next_reset_date?: string;
923
929
  /**
924
930
  * "basic" or "pro"
925
931
  */
@@ -7202,7 +7208,7 @@ declare function getUnfiledVaultMemoriesOp(ctx: VaultMemoryOperationsContext): P
7202
7208
  * by the next sweep, so topic-quality improvements propagate across the existing
7203
7209
  * vault. The worker's `limit` drains that re-extraction across sweeps.
7204
7210
  */
7205
- declare const TOPICS_EXTRACTION_VERSION = 1;
7211
+ declare const TOPICS_EXTRACTION_VERSION = 2;
7206
7212
  /**
7207
7213
  * Result of {@link getMemoriesNeedingTopicExtractionOp}: which memories the
7208
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-3VPEZDYL.mjs";
152
+ } from "./chunk-35BHTCK4.mjs";
153
153
  import {
154
154
  PiiRedactor,
155
155
  createStreamingDeAnonymizer,
@@ -720,7 +720,7 @@ var CompletionsStrategy = class {
720
720
  model,
721
721
  stream,
722
722
  ...temperature !== void 0 && { temperature },
723
- ...maxOutputTokens !== void 0 && { max_tokens: maxOutputTokens },
723
+ ...maxOutputTokens !== void 0 && { max_completion_tokens: maxOutputTokens },
724
724
  ...tools && { tools },
725
725
  ...toolChoice && { tool_choice: toolChoice },
726
726
  ...portal && { portal }
@@ -8535,7 +8535,10 @@ ${evidence}`;
8535
8535
  headers: { ...authHeaders, "Content-Type": "application/json" },
8536
8536
  body: JSON.stringify({
8537
8537
  model,
8538
- max_tokens: maxTokens,
8538
+ // Modern OpenAI field; the portal reads only `max_completion_tokens`
8539
+ // (the deprecated `max_tokens` is silently ignored → falls back to the
8540
+ // portal's default output cap and truncates the answer).
8541
+ max_completion_tokens: maxTokens,
8539
8542
  messages: [
8540
8543
  { role: "system", content: systemPrompt },
8541
8544
  { role: "user", content: userMessage }
@@ -8972,14 +8975,15 @@ function extractFacetText(structured) {
8972
8975
  var TOPIC_EXTRACTION_BATCH_SIZE = 10;
8973
8976
  var MAX_CHARS_PER_MEMORY = 300;
8974
8977
  var MAX_VOCABULARY_NAMES = 100;
8978
+ var MAX_COMPLETION_TOKENS = 8192;
8975
8979
  var SYSTEM_PROMPT4 = `You assign topics to saved memories for a personal memory system.
8976
8980
 
8977
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.
8978
8982
 
8979
8983
  Include only NAMED entities, skip generic/common nouns. ${ENTITY_KIND_GUIDELINES}
8980
8984
 
8981
- Output strict JSON: {"memories": [{"id": string, "entities": [{"name": string, "kind": string}]}]}
8982
- - 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
8983
8987
  - "entities" may be empty when a memory mentions no named entities \u2014 most short memories have 0-3
8984
8988
  No prose.`;
8985
8989
  async function extractEntitiesForMemories(memories, options) {
@@ -8994,8 +8998,8 @@ When a memory refers to one of these, reuse the EXACT existing name (same spelli
8994
8998
  for (let i = 0; i < memories.length; i += TOPIC_EXTRACTION_BATCH_SIZE) {
8995
8999
  const batch = memories.slice(i, i + TOPIC_EXTRACTION_BATCH_SIZE);
8996
9000
  const listing = batch.map((m) => {
8997
- const content = m.content.slice(0, MAX_CHARS_PER_MEMORY);
8998
- 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}`;
8999
9003
  }).join("\n");
9000
9004
  const parsed = await callPortalJsonCompletion({
9001
9005
  ...options.apiKey !== void 0 && { apiKey: options.apiKey },
@@ -9011,6 +9015,7 @@ ${listing}
9011
9015
 
9012
9016
  List each memory's named entities.`,
9013
9017
  tag: "memory/topics",
9018
+ extra: { max_completion_tokens: MAX_COMPLETION_TOKENS },
9014
9019
  ...options.fetchFn && { fetchFn: options.fetchFn },
9015
9020
  ...options.maxAttempts !== void 0 && { maxAttempts: options.maxAttempts },
9016
9021
  ...options.timeoutMs !== void 0 && { timeoutMs: options.timeoutMs },
@@ -9054,9 +9059,11 @@ function parseTopicResponse(parsed, validIds) {
9054
9059
  for (const raw of list) {
9055
9060
  if (typeof raw !== "object" || raw === null) continue;
9056
9061
  const obj = raw;
9057
- 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;
9058
9065
  const entities = Array.isArray(obj.entities) ? parseEntities(obj.entities) : [];
9059
- out.set(obj.id, entities);
9066
+ out.set(id, entities);
9060
9067
  }
9061
9068
  return out;
9062
9069
  }
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  recall
3
- } from "./chunk-3VPEZDYL.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
 
@@ -28728,7 +28728,10 @@ ${evidence}`;
28728
28728
  headers: { ...authHeaders, "Content-Type": "application/json" },
28729
28729
  body: JSON.stringify({
28730
28730
  model,
28731
- max_tokens: maxTokens,
28731
+ // Modern OpenAI field; the portal reads only `max_completion_tokens`
28732
+ // (the deprecated `max_tokens` is silently ignored → falls back to the
28733
+ // portal's default output cap and truncates the answer).
28734
+ max_completion_tokens: maxTokens,
28732
28735
  messages: [
28733
28736
  { role: "system", content: systemPrompt },
28734
28737
  { role: "user", content: userMessage }
@@ -29180,14 +29183,15 @@ init_portalLlm();
29180
29183
  var TOPIC_EXTRACTION_BATCH_SIZE = 10;
29181
29184
  var MAX_CHARS_PER_MEMORY = 300;
29182
29185
  var MAX_VOCABULARY_NAMES = 100;
29186
+ var MAX_COMPLETION_TOKENS = 8192;
29183
29187
  var SYSTEM_PROMPT6 = `You assign topics to saved memories for a personal memory system.
29184
29188
 
29185
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.
29186
29190
 
29187
29191
  Include only NAMED entities, skip generic/common nouns. ${ENTITY_KIND_GUIDELINES}
29188
29192
 
29189
- Output strict JSON: {"memories": [{"id": string, "entities": [{"name": string, "kind": string}]}]}
29190
- - 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
29191
29195
  - "entities" may be empty when a memory mentions no named entities \u2014 most short memories have 0-3
29192
29196
  No prose.`;
29193
29197
  async function extractEntitiesForMemories(memories, options) {
@@ -29202,8 +29206,8 @@ When a memory refers to one of these, reuse the EXACT existing name (same spelli
29202
29206
  for (let i = 0; i < memories.length; i += TOPIC_EXTRACTION_BATCH_SIZE) {
29203
29207
  const batch = memories.slice(i, i + TOPIC_EXTRACTION_BATCH_SIZE);
29204
29208
  const listing = batch.map((m) => {
29205
- const content = m.content.slice(0, MAX_CHARS_PER_MEMORY);
29206
- 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}`;
29207
29211
  }).join("\n");
29208
29212
  const parsed = await callPortalJsonCompletion({
29209
29213
  ...options.apiKey !== void 0 && { apiKey: options.apiKey },
@@ -29219,6 +29223,7 @@ ${listing}
29219
29223
 
29220
29224
  List each memory's named entities.`,
29221
29225
  tag: "memory/topics",
29226
+ extra: { max_completion_tokens: MAX_COMPLETION_TOKENS },
29222
29227
  ...options.fetchFn && { fetchFn: options.fetchFn },
29223
29228
  ...options.maxAttempts !== void 0 && { maxAttempts: options.maxAttempts },
29224
29229
  ...options.timeoutMs !== void 0 && { timeoutMs: options.timeoutMs },
@@ -29262,9 +29267,11 @@ function parseTopicResponse(parsed, validIds) {
29262
29267
  for (const raw of list) {
29263
29268
  if (typeof raw !== "object" || raw === null) continue;
29264
29269
  const obj = raw;
29265
- 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;
29266
29273
  const entities = Array.isArray(obj.entities) ? parseEntities(obj.entities) : [];
29267
- out.set(obj.id, entities);
29274
+ out.set(id, entities);
29268
29275
  }
29269
29276
  return out;
29270
29277
  }
@@ -31887,7 +31894,7 @@ var CompletionsStrategy = class {
31887
31894
  model,
31888
31895
  stream,
31889
31896
  ...temperature !== void 0 && { temperature },
31890
- ...maxOutputTokens !== void 0 && { max_tokens: maxOutputTokens },
31897
+ ...maxOutputTokens !== void 0 && { max_completion_tokens: maxOutputTokens },
31891
31898
  ...tools && { tools },
31892
31899
  ...toolChoice && { tool_choice: toolChoice },
31893
31900
  ...portal && { portal }
@@ -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