@anuma/sdk 10.2.5 → 10.3.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.
@@ -15940,11 +15940,11 @@ async function requestPortalJson(req, endpoint, controller, deadlineAt) {
15940
15940
  let value;
15941
15941
  try {
15942
15942
  value = JSON.parse(candidate);
15943
- } catch (err) {
15943
+ } catch {
15944
15944
  return {
15945
15945
  kind: "retryable",
15946
15946
  code: "invalid-json",
15947
- reason: `completion was not valid JSON: ${err.message}`
15947
+ reason: "invalid-json"
15948
15948
  };
15949
15949
  }
15950
15950
  if (value === null) {
@@ -29818,7 +29818,7 @@ async function backfillMemoryTopicsOp(ctx, memoryIds) {
29818
29818
  const chunkIds = uniqueIds.slice(i, i + CHUNK);
29819
29819
  await ctx.database.write(async () => {
29820
29820
  await assertCanWrite2(ctx);
29821
- const writes = [];
29821
+ const records = [];
29822
29822
  for (const id of chunkIds) {
29823
29823
  let record;
29824
29824
  try {
@@ -29828,13 +29828,40 @@ async function backfillMemoryTopicsOp(ctx, memoryIds) {
29828
29828
  }
29829
29829
  if (record.isDeleted || !isOwnedByCtxUser(ctx, record)) continue;
29830
29830
  if (parseTopics(record.topics) !== null) continue;
29831
- const links = await entityCtx.memoryEntityCollection.query(import_watermelondb19.Q.where("memory_id", id)).unsafeFetchRaw();
29832
- const entityIds = links.map((l) => String(l.entity_id));
29833
- if (entityIds.length === 0) continue;
29834
- const entities = await entityCtx.entityCollection.query(import_watermelondb19.Q.where("id", import_watermelondb19.Q.oneOf(entityIds))).fetch();
29835
- if (entities.length === 0) continue;
29831
+ records.push(record);
29832
+ }
29833
+ if (records.length === 0) return;
29834
+ const links = await entityCtx.memoryEntityCollection.query(import_watermelondb19.Q.where("memory_id", import_watermelondb19.Q.oneOf(records.map((record) => record.id)))).unsafeFetchRaw();
29835
+ const entityIds = Array.from(new Set(links.map((link) => String(link.entity_id))));
29836
+ const entitiesById = /* @__PURE__ */ new Map();
29837
+ for (let j = 0; j < entityIds.length; j += CHUNK) {
29838
+ const entities = await entityCtx.entityCollection.query(import_watermelondb19.Q.where("id", import_watermelondb19.Q.oneOf(entityIds.slice(j, j + CHUNK)))).fetch();
29839
+ for (const entity of entities) entitiesById.set(entity.id, entity);
29840
+ }
29841
+ const entitiesByMemory = /* @__PURE__ */ new Map();
29842
+ for (const link of links) {
29843
+ const entity = entitiesById.get(String(link.entity_id));
29844
+ if (!entity) continue;
29845
+ const memoryId = String(link.memory_id);
29846
+ let entities = entitiesByMemory.get(memoryId);
29847
+ if (!entities) {
29848
+ entities = /* @__PURE__ */ new Set();
29849
+ entitiesByMemory.set(memoryId, entities);
29850
+ }
29851
+ entities.add(entity);
29852
+ }
29853
+ const writes = [];
29854
+ for (const record of records) {
29855
+ const entities = entitiesByMemory.get(record.id);
29856
+ if (!entities?.size) continue;
29836
29857
  const source = record.topicsUserManaged ? "user" : "auto";
29837
- const write = await resolveMemoryTopicsWrite(entityCtx, id, entities, [], source);
29858
+ const write = await resolveMemoryTopicsWrite(
29859
+ entityCtx,
29860
+ record.id,
29861
+ Array.from(entities),
29862
+ [],
29863
+ source
29864
+ );
29838
29865
  if (write) writes.push(write);
29839
29866
  }
29840
29867
  if (writes.length === 0) return;
@@ -13,7 +13,7 @@ import {
13
13
  taskTypeHeader,
14
14
  validateEndpointOverride,
15
15
  withInternalFlowMarker
16
- } from "./chunk-QK62YWBH.mjs";
16
+ } from "./chunk-BIMEZT3O.mjs";
17
17
  import {
18
18
  BASE_URL,
19
19
  __commonJS,
@@ -28076,7 +28076,7 @@ async function backfillMemoryTopicsOp(ctx, memoryIds) {
28076
28076
  const chunkIds = uniqueIds.slice(i, i + CHUNK);
28077
28077
  await ctx.database.write(async () => {
28078
28078
  await assertCanWrite2(ctx);
28079
- const writes = [];
28079
+ const records = [];
28080
28080
  for (const id of chunkIds) {
28081
28081
  let record;
28082
28082
  try {
@@ -28086,13 +28086,40 @@ async function backfillMemoryTopicsOp(ctx, memoryIds) {
28086
28086
  }
28087
28087
  if (record.isDeleted || !isOwnedByCtxUser(ctx, record)) continue;
28088
28088
  if (parseTopics(record.topics) !== null) continue;
28089
- const links = await entityCtx.memoryEntityCollection.query(import_watermelondb19.Q.where("memory_id", id)).unsafeFetchRaw();
28090
- const entityIds = links.map((l) => String(l.entity_id));
28091
- if (entityIds.length === 0) continue;
28092
- const entities = await entityCtx.entityCollection.query(import_watermelondb19.Q.where("id", import_watermelondb19.Q.oneOf(entityIds))).fetch();
28093
- if (entities.length === 0) continue;
28089
+ records.push(record);
28090
+ }
28091
+ if (records.length === 0) return;
28092
+ const links = await entityCtx.memoryEntityCollection.query(import_watermelondb19.Q.where("memory_id", import_watermelondb19.Q.oneOf(records.map((record) => record.id)))).unsafeFetchRaw();
28093
+ const entityIds = Array.from(new Set(links.map((link) => String(link.entity_id))));
28094
+ const entitiesById = /* @__PURE__ */ new Map();
28095
+ for (let j = 0; j < entityIds.length; j += CHUNK) {
28096
+ const entities = await entityCtx.entityCollection.query(import_watermelondb19.Q.where("id", import_watermelondb19.Q.oneOf(entityIds.slice(j, j + CHUNK)))).fetch();
28097
+ for (const entity of entities) entitiesById.set(entity.id, entity);
28098
+ }
28099
+ const entitiesByMemory = /* @__PURE__ */ new Map();
28100
+ for (const link of links) {
28101
+ const entity = entitiesById.get(String(link.entity_id));
28102
+ if (!entity) continue;
28103
+ const memoryId = String(link.memory_id);
28104
+ let entities = entitiesByMemory.get(memoryId);
28105
+ if (!entities) {
28106
+ entities = /* @__PURE__ */ new Set();
28107
+ entitiesByMemory.set(memoryId, entities);
28108
+ }
28109
+ entities.add(entity);
28110
+ }
28111
+ const writes = [];
28112
+ for (const record of records) {
28113
+ const entities = entitiesByMemory.get(record.id);
28114
+ if (!entities?.size) continue;
28094
28115
  const source = record.topicsUserManaged ? "user" : "auto";
28095
- const write = await resolveMemoryTopicsWrite(entityCtx, id, entities, [], source);
28116
+ const write = await resolveMemoryTopicsWrite(
28117
+ entityCtx,
28118
+ record.id,
28119
+ Array.from(entities),
28120
+ [],
28121
+ source
28122
+ );
28096
28123
  if (write) writes.push(write);
28097
28124
  }
28098
28125
  if (writes.length === 0) return;
@@ -31790,7 +31817,7 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
31790
31817
  content: m.content,
31791
31818
  similarity: m.similarity
31792
31819
  }));
31793
- const { consolidateMemory: doConsolidate } = await import("./consolidate-NW4UVA6T.mjs");
31820
+ const { consolidateMemory: doConsolidate } = await import("./consolidate-JZJYY3SZ.mjs");
31794
31821
  const decision = await doConsolidate(trimmed, candidates, consolidateOptions);
31795
31822
  if (decision.action === "create") return decision.fallbackReason ? null : { create: true };
31796
31823
  if (decision.action === "supersede" && decision.content) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anuma/sdk",
3
- "version": "10.2.5",
3
+ "version": "10.3.0",
4
4
  "description": "",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",