@anuma/sdk 9.1.0 → 9.1.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.
@@ -28918,9 +28918,10 @@ async function getVaultRankingProjectionsOp(ctx, options) {
28918
28918
  }
28919
28919
  function baseVaultSql(ctx, options) {
28920
28920
  const clauses = [
28921
+ `"_status" is not 'deleted'`,
28921
28922
  '"is_deleted" = 0',
28922
28923
  ...options?.includeArchived ? [] : ['"archived_at" is null'],
28923
- `"trust_tier" is not 'quarantined'`,
28924
+ ...options?.includeQuarantined ? [] : [`"trust_tier" is not 'quarantined'`],
28924
28925
  '"superseded_by" is null'
28925
28926
  ];
28926
28927
  const args = [];
@@ -29406,8 +29407,17 @@ async function getMemoriesNeedingTopicExtractionOp(ctx, options) {
29406
29407
  if (!entityCtx) {
29407
29408
  throw new Error("getMemoriesNeedingTopicExtractionOp requires ctx.entityCtx");
29408
29409
  }
29409
- const conditions = [...baseVaultConditions(ctx), import_watermelondb19.Q.sortBy("created_at", import_watermelondb19.Q.desc)];
29410
- const rows = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
29410
+ let rows;
29411
+ try {
29412
+ const base = baseVaultSql(ctx);
29413
+ const sql = `select "id", "topics", "topics_user_managed", "topics_extracted_at", "topics_extracted_version", "updated_at" from "memory_vault" where ${base.sql} order by "created_at" desc`;
29414
+ rows = await ctx.vaultMemoryCollection.query(import_watermelondb19.Q.unsafeSqlQuery(sql, base.args)).unsafeFetchRaw();
29415
+ } catch (err) {
29416
+ getLogger().debug(
29417
+ "memoryVault: topic sweep SQL unavailable; use the adapter query: " + (err instanceof Error ? err.message : String(err))
29418
+ );
29419
+ rows = await ctx.vaultMemoryCollection.query(...baseVaultConditions(ctx), import_watermelondb19.Q.sortBy("created_at", import_watermelondb19.Q.desc)).unsafeFetchRaw();
29420
+ }
29411
29421
  const linkedNames = await linkedEntityNamesByMemory(
29412
29422
  entityCtx,
29413
29423
  rows.map((r) => r.id)
@@ -29466,10 +29476,19 @@ async function getMemoriesNeedingTopicExtractionOp(ctx, options) {
29466
29476
  }
29467
29477
  const orderedPendingRaw = [...stampedPendingRaw, ...pendingRaw];
29468
29478
  const limitedPendingRaw = cap !== void 0 ? orderedPendingRaw.slice(0, cap) : orderedPendingRaw;
29469
- const pending = await mapInBatches(
29470
- limitedPendingRaw,
29471
- (raw) => vaultMemoryRawToStored(raw, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
29472
- );
29479
+ const pending = [];
29480
+ for (let i = 0; i < limitedPendingRaw.length; i += 500) {
29481
+ const chunk = limitedPendingRaw.slice(i, i + 500);
29482
+ const memories = await getVaultMemoriesByIdsOp(
29483
+ ctx,
29484
+ chunk.map((raw) => raw.id)
29485
+ );
29486
+ const byId = new Map(memories.map((memory) => [memory.uniqueId, memory]));
29487
+ for (const raw of chunk) {
29488
+ const memory = byId.get(raw.id);
29489
+ if (memory) pending.push(memory);
29490
+ }
29491
+ }
29473
29492
  const applyCap = (ids) => cap !== void 0 ? ids.slice(0, cap) : ids;
29474
29493
  return {
29475
29494
  pending,
@@ -29616,10 +29635,20 @@ function assertVaultScopeForSweep(ctx) {
29616
29635
  }
29617
29636
  async function getDecayCandidatesRawOp(ctx) {
29618
29637
  assertVaultScopeForSweep(ctx);
29619
- const results = await ctx.vaultMemoryCollection.query(
29620
- ...baseVaultConditions(ctx, { includeArchived: true, includeQuarantined: true }),
29621
- import_watermelondb19.Q.where("kind", null)
29622
- ).unsafeFetchRaw();
29638
+ let results;
29639
+ try {
29640
+ const base = baseVaultSql(ctx, { includeArchived: true, includeQuarantined: true });
29641
+ const sql = `select "id", "fact_type", "event_time_end", "event_time_kind", "updated_at", "last_observed_at", "archived_at", "source", "trust_tier" from "memory_vault" where ${base.sql} and "kind" is null`;
29642
+ results = await ctx.vaultMemoryCollection.query(import_watermelondb19.Q.unsafeSqlQuery(sql, base.args)).unsafeFetchRaw();
29643
+ } catch (err) {
29644
+ getLogger().debug(
29645
+ "memoryVault: decay sweep SQL unavailable; use the adapter query: " + (err instanceof Error ? err.message : String(err))
29646
+ );
29647
+ results = await ctx.vaultMemoryCollection.query(
29648
+ ...baseVaultConditions(ctx, { includeArchived: true, includeQuarantined: true }),
29649
+ import_watermelondb19.Q.where("kind", null)
29650
+ ).unsafeFetchRaw();
29651
+ }
29623
29652
  return results.map((raw) => ({
29624
29653
  uniqueId: raw.id,
29625
29654
  factType: raw.fact_type ?? null,
@@ -5666,20 +5666,7 @@ interface DecayCandidateRaw {
5666
5666
  * not egress poison content — see the decay sweeper's `isBorderline`). */
5667
5667
  trustTier: string | null;
5668
5668
  }
5669
- /**
5670
- * Decay sweep candidate scan (PR2). Selects the plaintext columns
5671
- * `classifyDecay` (in `memory/decay`) needs via
5672
- * `unsafeFetchRaw` — NO Model per row (dodges the never-evicted RecordCache /
5673
- * web Pile-2 OOM history) and NO `content` read / decrypt (zero-knowledge).
5674
- *
5675
- * Includes archived AND quarantined rows (so archived→delete transitions and
5676
- * aged quarantined rows are seen) but excludes hard-deleted rows — the
5677
- * `baseVaultConditions` default keeps `is_deleted = false`. Excludes kinded
5678
- * (profile) memories, which never decay.
5679
- *
5680
- * Refuses to run on an unscoped multi-tenant context (see
5681
- * {@link assertVaultScopeForSweep}).
5682
- */
5669
+ /** Return the projected plaintext fields for the decay sweep within the required vault scope. */
5683
5670
  declare function getDecayCandidatesRawOp(ctx: VaultMemoryOperationsContext): Promise<DecayCandidateRaw[]>;
5684
5671
  /**
5685
5672
  * Archive a memory (decay soft state, PR2) — set `archived_at`. An archived row
@@ -5666,20 +5666,7 @@ interface DecayCandidateRaw {
5666
5666
  * not egress poison content — see the decay sweeper's `isBorderline`). */
5667
5667
  trustTier: string | null;
5668
5668
  }
5669
- /**
5670
- * Decay sweep candidate scan (PR2). Selects the plaintext columns
5671
- * `classifyDecay` (in `memory/decay`) needs via
5672
- * `unsafeFetchRaw` — NO Model per row (dodges the never-evicted RecordCache /
5673
- * web Pile-2 OOM history) and NO `content` read / decrypt (zero-knowledge).
5674
- *
5675
- * Includes archived AND quarantined rows (so archived→delete transitions and
5676
- * aged quarantined rows are seen) but excludes hard-deleted rows — the
5677
- * `baseVaultConditions` default keeps `is_deleted = false`. Excludes kinded
5678
- * (profile) memories, which never decay.
5679
- *
5680
- * Refuses to run on an unscoped multi-tenant context (see
5681
- * {@link assertVaultScopeForSweep}).
5682
- */
5669
+ /** Return the projected plaintext fields for the decay sweep within the required vault scope. */
5683
5670
  declare function getDecayCandidatesRawOp(ctx: VaultMemoryOperationsContext): Promise<DecayCandidateRaw[]>;
5684
5671
  /**
5685
5672
  * Archive a memory (decay soft state, PR2) — set `archived_at`. An archived row
@@ -27209,9 +27209,10 @@ async function getVaultRankingProjectionsOp(ctx, options) {
27209
27209
  }
27210
27210
  function baseVaultSql(ctx, options) {
27211
27211
  const clauses = [
27212
+ `"_status" is not 'deleted'`,
27212
27213
  '"is_deleted" = 0',
27213
27214
  ...options?.includeArchived ? [] : ['"archived_at" is null'],
27214
- `"trust_tier" is not 'quarantined'`,
27215
+ ...options?.includeQuarantined ? [] : [`"trust_tier" is not 'quarantined'`],
27215
27216
  '"superseded_by" is null'
27216
27217
  ];
27217
27218
  const args = [];
@@ -27697,8 +27698,17 @@ async function getMemoriesNeedingTopicExtractionOp(ctx, options) {
27697
27698
  if (!entityCtx) {
27698
27699
  throw new Error("getMemoriesNeedingTopicExtractionOp requires ctx.entityCtx");
27699
27700
  }
27700
- const conditions = [...baseVaultConditions(ctx), import_watermelondb19.Q.sortBy("created_at", import_watermelondb19.Q.desc)];
27701
- const rows = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
27701
+ let rows;
27702
+ try {
27703
+ const base = baseVaultSql(ctx);
27704
+ const sql = `select "id", "topics", "topics_user_managed", "topics_extracted_at", "topics_extracted_version", "updated_at" from "memory_vault" where ${base.sql} order by "created_at" desc`;
27705
+ rows = await ctx.vaultMemoryCollection.query(import_watermelondb19.Q.unsafeSqlQuery(sql, base.args)).unsafeFetchRaw();
27706
+ } catch (err) {
27707
+ getLogger().debug(
27708
+ "memoryVault: topic sweep SQL unavailable; use the adapter query: " + (err instanceof Error ? err.message : String(err))
27709
+ );
27710
+ rows = await ctx.vaultMemoryCollection.query(...baseVaultConditions(ctx), import_watermelondb19.Q.sortBy("created_at", import_watermelondb19.Q.desc)).unsafeFetchRaw();
27711
+ }
27702
27712
  const linkedNames = await linkedEntityNamesByMemory(
27703
27713
  entityCtx,
27704
27714
  rows.map((r) => r.id)
@@ -27757,10 +27767,19 @@ async function getMemoriesNeedingTopicExtractionOp(ctx, options) {
27757
27767
  }
27758
27768
  const orderedPendingRaw = [...stampedPendingRaw, ...pendingRaw];
27759
27769
  const limitedPendingRaw = cap !== void 0 ? orderedPendingRaw.slice(0, cap) : orderedPendingRaw;
27760
- const pending = await mapInBatches(
27761
- limitedPendingRaw,
27762
- (raw) => vaultMemoryRawToStored(raw, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
27763
- );
27770
+ const pending = [];
27771
+ for (let i = 0; i < limitedPendingRaw.length; i += 500) {
27772
+ const chunk = limitedPendingRaw.slice(i, i + 500);
27773
+ const memories = await getVaultMemoriesByIdsOp(
27774
+ ctx,
27775
+ chunk.map((raw) => raw.id)
27776
+ );
27777
+ const byId = new Map(memories.map((memory) => [memory.uniqueId, memory]));
27778
+ for (const raw of chunk) {
27779
+ const memory = byId.get(raw.id);
27780
+ if (memory) pending.push(memory);
27781
+ }
27782
+ }
27764
27783
  const applyCap = (ids) => cap !== void 0 ? ids.slice(0, cap) : ids;
27765
27784
  return {
27766
27785
  pending,
@@ -27907,10 +27926,20 @@ function assertVaultScopeForSweep(ctx) {
27907
27926
  }
27908
27927
  async function getDecayCandidatesRawOp(ctx) {
27909
27928
  assertVaultScopeForSweep(ctx);
27910
- const results = await ctx.vaultMemoryCollection.query(
27911
- ...baseVaultConditions(ctx, { includeArchived: true, includeQuarantined: true }),
27912
- import_watermelondb19.Q.where("kind", null)
27913
- ).unsafeFetchRaw();
27929
+ let results;
27930
+ try {
27931
+ const base = baseVaultSql(ctx, { includeArchived: true, includeQuarantined: true });
27932
+ const sql = `select "id", "fact_type", "event_time_end", "event_time_kind", "updated_at", "last_observed_at", "archived_at", "source", "trust_tier" from "memory_vault" where ${base.sql} and "kind" is null`;
27933
+ results = await ctx.vaultMemoryCollection.query(import_watermelondb19.Q.unsafeSqlQuery(sql, base.args)).unsafeFetchRaw();
27934
+ } catch (err) {
27935
+ getLogger().debug(
27936
+ "memoryVault: decay sweep SQL unavailable; use the adapter query: " + (err instanceof Error ? err.message : String(err))
27937
+ );
27938
+ results = await ctx.vaultMemoryCollection.query(
27939
+ ...baseVaultConditions(ctx, { includeArchived: true, includeQuarantined: true }),
27940
+ import_watermelondb19.Q.where("kind", null)
27941
+ ).unsafeFetchRaw();
27942
+ }
27914
27943
  return results.map((raw) => ({
27915
27944
  uniqueId: raw.id,
27916
27945
  factType: raw.fact_type ?? null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anuma/sdk",
3
- "version": "9.1.0",
3
+ "version": "9.1.2",
4
4
  "description": "",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",