@anuma/sdk 6.37.0 → 6.38.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.
- package/dist/expo/index.cjs +224 -86
- package/dist/expo/index.d.mts +33 -3
- package/dist/expo/index.d.ts +33 -3
- package/dist/expo/index.mjs +224 -86
- package/dist/react/index.cjs +224 -86
- package/dist/react/index.d.mts +33 -3
- package/dist/react/index.d.ts +33 -3
- package/dist/react/index.mjs +224 -86
- package/dist/server/index.cjs +44 -8
- package/dist/server/index.d.mts +58 -3
- package/dist/server/index.d.ts +58 -3
- package/dist/server/index.mjs +44 -8
- package/package.json +1 -1
package/dist/react/index.cjs
CHANGED
|
@@ -5997,7 +5997,7 @@ function extractUserMessageFromMessages(messages) {
|
|
|
5997
5997
|
}
|
|
5998
5998
|
|
|
5999
5999
|
// src/lib/db/chat/operations.ts
|
|
6000
|
-
function messageToStoredRaw(message,
|
|
6000
|
+
function messageToStoredRaw(message, projection2) {
|
|
6001
6001
|
const convId = String(message._getRaw("conversation_id"));
|
|
6002
6002
|
const parseJsonField = (rawValue) => {
|
|
6003
6003
|
if (!rawValue) return void 0;
|
|
@@ -6011,7 +6011,7 @@ function messageToStoredRaw(message, projection) {
|
|
|
6011
6011
|
}
|
|
6012
6012
|
return rawValue;
|
|
6013
6013
|
};
|
|
6014
|
-
const skipEmbeddings =
|
|
6014
|
+
const skipEmbeddings = projection2?.skipEmbeddings === true;
|
|
6015
6015
|
const sourcesRaw = message._getRaw("sources");
|
|
6016
6016
|
const vectorRaw = skipEmbeddings ? null : message._getRaw("vector");
|
|
6017
6017
|
const chunksRaw = skipEmbeddings ? null : message._getRaw("chunks");
|
|
@@ -6045,8 +6045,8 @@ function messageToStoredRaw(message, projection) {
|
|
|
6045
6045
|
origin: message.origin
|
|
6046
6046
|
};
|
|
6047
6047
|
}
|
|
6048
|
-
async function messageToStored(message, walletAddress, signMessage, embeddedWalletSigner,
|
|
6049
|
-
const baseMessage = messageToStoredRaw(message,
|
|
6048
|
+
async function messageToStored(message, walletAddress, signMessage, embeddedWalletSigner, projection2) {
|
|
6049
|
+
const baseMessage = messageToStoredRaw(message, projection2);
|
|
6050
6050
|
if (walletAddress) {
|
|
6051
6051
|
return await decryptMessageFields(
|
|
6052
6052
|
baseMessage,
|
|
@@ -6060,7 +6060,7 @@ async function messageToStored(message, walletAddress, signMessage, embeddedWall
|
|
|
6060
6060
|
function rawDate(value) {
|
|
6061
6061
|
return new Date(typeof value === "number" ? value : 0);
|
|
6062
6062
|
}
|
|
6063
|
-
function messageRawToStoredRaw(raw,
|
|
6063
|
+
function messageRawToStoredRaw(raw, projection2) {
|
|
6064
6064
|
const parseJsonField = (rawValue) => {
|
|
6065
6065
|
if (!rawValue) return void 0;
|
|
6066
6066
|
if (typeof rawValue === "string") {
|
|
@@ -6073,7 +6073,7 @@ function messageRawToStoredRaw(raw, projection) {
|
|
|
6073
6073
|
}
|
|
6074
6074
|
return rawValue;
|
|
6075
6075
|
};
|
|
6076
|
-
const skipEmbeddings =
|
|
6076
|
+
const skipEmbeddings = projection2?.skipEmbeddings === true;
|
|
6077
6077
|
const vectorRaw = skipEmbeddings ? null : raw.vector;
|
|
6078
6078
|
const chunksRaw = skipEmbeddings ? null : raw.chunks;
|
|
6079
6079
|
return {
|
|
@@ -6104,8 +6104,8 @@ function messageRawToStoredRaw(raw, projection) {
|
|
|
6104
6104
|
origin: raw.origin
|
|
6105
6105
|
};
|
|
6106
6106
|
}
|
|
6107
|
-
async function messageRawToStored(raw, walletAddress, signMessage, embeddedWalletSigner,
|
|
6108
|
-
const baseMessage = messageRawToStoredRaw(raw,
|
|
6107
|
+
async function messageRawToStored(raw, walletAddress, signMessage, embeddedWalletSigner, projection2) {
|
|
6108
|
+
const baseMessage = messageRawToStoredRaw(raw, projection2);
|
|
6109
6109
|
if (walletAddress) {
|
|
6110
6110
|
return await decryptMessageFields(
|
|
6111
6111
|
baseMessage,
|
|
@@ -15908,22 +15908,35 @@ async function vaultMemoryRawToStored(raw, walletAddress, signMessage, embeddedW
|
|
|
15908
15908
|
return stored2;
|
|
15909
15909
|
}
|
|
15910
15910
|
async function getAllVaultMemoriesOp(ctx, options) {
|
|
15911
|
-
const
|
|
15911
|
+
const results = await ctx.vaultMemoryCollection.query(...vaultListConditions(ctx, options), ...vaultListOrder(options)).unsafeFetchRaw();
|
|
15912
|
+
return mapInBatches(
|
|
15913
|
+
results,
|
|
15914
|
+
(raw) => vaultMemoryRawToStored(raw, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
|
|
15915
|
+
);
|
|
15916
|
+
}
|
|
15917
|
+
function vaultListConditions(ctx, options) {
|
|
15918
|
+
return [
|
|
15912
15919
|
...baseVaultConditions(ctx, options),
|
|
15913
15920
|
...options?.scopes?.length ? [import_watermelondb23.Q.where("scope", import_watermelondb23.Q.oneOf(options.scopes))] : [],
|
|
15914
15921
|
...visibilityConditions(options?.visibility),
|
|
15915
15922
|
...levelConditions(options?.levels),
|
|
15916
15923
|
...options?.kinds?.length ? [import_watermelondb23.Q.where("kind", import_watermelondb23.Q.oneOf(options.kinds))] : [],
|
|
15917
15924
|
...options?.folderId !== void 0 ? [import_watermelondb23.Q.where("folder_id", options.folderId)] : [],
|
|
15918
|
-
...options?.factTypes?.length ? [import_watermelondb23.Q.where("fact_type", import_watermelondb23.Q.oneOf(options.factTypes))] : []
|
|
15925
|
+
...options?.factTypes?.length ? [import_watermelondb23.Q.where("fact_type", import_watermelondb23.Q.oneOf(options.factTypes))] : []
|
|
15926
|
+
];
|
|
15927
|
+
}
|
|
15928
|
+
function vaultListOrder(options) {
|
|
15929
|
+
return [
|
|
15919
15930
|
import_watermelondb23.Q.sortBy(options?.since ? "updated_at" : "created_at", import_watermelondb23.Q.desc),
|
|
15920
15931
|
...options?.limit !== null && options?.limit !== void 0 && options.limit > 0 ? [import_watermelondb23.Q.take(options.limit)] : []
|
|
15921
15932
|
];
|
|
15922
|
-
|
|
15923
|
-
|
|
15924
|
-
|
|
15925
|
-
|
|
15926
|
-
|
|
15933
|
+
}
|
|
15934
|
+
async function getVaultMemoryProjectionsOp(ctx, options) {
|
|
15935
|
+
const results = await ctx.vaultMemoryCollection.query(...vaultListConditions(ctx, options), ...vaultListOrder(options)).unsafeFetchRaw();
|
|
15936
|
+
return results.map((raw) => ({
|
|
15937
|
+
...vaultMemoryRawToRankable(raw),
|
|
15938
|
+
topicsUserManaged: raw.topics_user_managed === true || raw.topics_user_managed === 1
|
|
15939
|
+
}));
|
|
15927
15940
|
}
|
|
15928
15941
|
function vaultMemoryRawToRankable(raw) {
|
|
15929
15942
|
return {
|
|
@@ -23064,6 +23077,7 @@ function createLocalMemoryStore(options) {
|
|
|
23064
23077
|
};
|
|
23065
23078
|
const vaultCache = options.vaultCache ?? createVaultEmbeddingCache();
|
|
23066
23079
|
const ownedBy = userId !== void 0 ? [import_watermelondb32.Q.where("user_id", userId)] : [];
|
|
23080
|
+
const linksOwnedBy = userId === void 0 ? [] : options.allowUnscopedRows ? [import_watermelondb32.Q.or(import_watermelondb32.Q.where("user_id", userId), import_watermelondb32.Q.where("user_id", null))] : [import_watermelondb32.Q.where("user_id", userId)];
|
|
23067
23081
|
const watchedColumns = [
|
|
23068
23082
|
"content",
|
|
23069
23083
|
"scope",
|
|
@@ -23106,6 +23120,29 @@ function createLocalMemoryStore(options) {
|
|
|
23106
23120
|
},
|
|
23107
23121
|
memoriesByTopics: (names) => getMemoriesByEntityNamesOp(entityCtx, names),
|
|
23108
23122
|
topicsByMemories: (memoryIds) => getEntitiesByMemoryIdsOp(entityCtx, memoryIds),
|
|
23123
|
+
listTopics: async () => {
|
|
23124
|
+
const links = await entityCtx.memoryEntityCollection.query(...linksOwnedBy).fetch();
|
|
23125
|
+
const members = /* @__PURE__ */ new Map();
|
|
23126
|
+
for (const link of links) {
|
|
23127
|
+
const entityId = String(link.entityId);
|
|
23128
|
+
const set = members.get(entityId) ?? /* @__PURE__ */ new Set();
|
|
23129
|
+
set.add(String(link.memoryId));
|
|
23130
|
+
members.set(entityId, set);
|
|
23131
|
+
}
|
|
23132
|
+
const entities = userId === void 0 ? await entityCtx.entityCollection.query().fetch() : members.size ? await entityCtx.entityCollection.query(import_watermelondb32.Q.where("id", import_watermelondb32.Q.oneOf([...members.keys()]))).fetch() : [];
|
|
23133
|
+
const byName = /* @__PURE__ */ new Map();
|
|
23134
|
+
for (const entity of entities) {
|
|
23135
|
+
const count2 = members.get(entity.id)?.size ?? 0;
|
|
23136
|
+
const existing = byName.get(entity.canonicalName);
|
|
23137
|
+
byName.set(entity.canonicalName, {
|
|
23138
|
+
name: entity.canonicalName,
|
|
23139
|
+
kind: existing?.kind ?? entity.kind ?? null,
|
|
23140
|
+
memoryCount: (existing?.memoryCount ?? 0) + count2
|
|
23141
|
+
});
|
|
23142
|
+
}
|
|
23143
|
+
return [...byName.values()].sort((a, b) => a.name.localeCompare(b.name));
|
|
23144
|
+
},
|
|
23145
|
+
listProjections: (listOptions) => getVaultMemoryProjectionsOp(vaultCtx, listOptions),
|
|
23109
23146
|
create: async (input) => {
|
|
23110
23147
|
const created = await createVaultMemoryOp(vaultCtx, input);
|
|
23111
23148
|
if (input.embedding === void 0) embedInBackground(created);
|
|
@@ -23167,7 +23204,6 @@ function createLocalMemoryStore(options) {
|
|
|
23167
23204
|
);
|
|
23168
23205
|
const subscriptions = [memories.subscribe(afterFirst())];
|
|
23169
23206
|
if (subscribeOptions?.topics) {
|
|
23170
|
-
const linksOwnedBy = userId === void 0 ? [] : options.allowUnscopedRows ? [import_watermelondb32.Q.or(import_watermelondb32.Q.where("user_id", userId), import_watermelondb32.Q.where("user_id", null))] : [import_watermelondb32.Q.where("user_id", userId)];
|
|
23171
23207
|
subscriptions.push(
|
|
23172
23208
|
entityCtx.memoryEntityCollection.query(...linksOwnedBy).observe().subscribe(afterFirst())
|
|
23173
23209
|
);
|
|
@@ -23577,6 +23613,31 @@ async function createRemoteMemoryPersistence(options) {
|
|
|
23577
23613
|
throw new Error("Invalid nearby candidate response");
|
|
23578
23614
|
return result;
|
|
23579
23615
|
};
|
|
23616
|
+
const fetchQueryPage = async (queryOptions) => {
|
|
23617
|
+
const { signal, ...query } = queryOptions;
|
|
23618
|
+
if (query.limit !== void 0 && (!Number.isInteger(query.limit) || query.limit < 1 || query.limit > 200))
|
|
23619
|
+
throw new Error("Page limit must be 1\u2013200");
|
|
23620
|
+
for (const [key, max] of queryListLimits) {
|
|
23621
|
+
const values = query[key];
|
|
23622
|
+
if (values && values.length > max)
|
|
23623
|
+
throw new Error(`Query ${key} accepts at most ${max} entries (got ${values.length})`);
|
|
23624
|
+
}
|
|
23625
|
+
const page = await request(
|
|
23626
|
+
"/memories/query",
|
|
23627
|
+
{
|
|
23628
|
+
method: "POST",
|
|
23629
|
+
body: JSON.stringify(
|
|
23630
|
+
Object.fromEntries(
|
|
23631
|
+
queryFields.filter((key) => query[key] !== void 0).map((key) => [key, query[key]])
|
|
23632
|
+
)
|
|
23633
|
+
)
|
|
23634
|
+
},
|
|
23635
|
+
signal
|
|
23636
|
+
);
|
|
23637
|
+
if (!record(page) || !Array.isArray(page.items) || page.next_cursor !== void 0 && typeof page.next_cursor !== "string" || page.changes_cursor !== void 0 && typeof page.changes_cursor !== "string")
|
|
23638
|
+
throw new Error("Invalid nearby private-memory page");
|
|
23639
|
+
return page;
|
|
23640
|
+
};
|
|
23580
23641
|
const candidateSet = async (embedding, candidateOptions = {}) => {
|
|
23581
23642
|
const result = await fetchCandidates(embedding, candidateOptions, true);
|
|
23582
23643
|
if (!Number.isSafeInteger(result.total_count) || result.total_count < 0 || !Number.isSafeInteger(result.unavailable_count) || result.unavailable_count < 0)
|
|
@@ -23655,34 +23716,27 @@ async function createRemoteMemoryPersistence(options) {
|
|
|
23655
23716
|
return Promise.all(result.items.map((item, i) => decodeCommitted(item, prepared[i])));
|
|
23656
23717
|
},
|
|
23657
23718
|
query: async (queryOptions = {}) => {
|
|
23658
|
-
const
|
|
23659
|
-
if (query.limit !== void 0 && (!Number.isInteger(query.limit) || query.limit < 1 || query.limit > 200))
|
|
23660
|
-
throw new Error("Page limit must be 1\u2013200");
|
|
23661
|
-
for (const [key, max] of queryListLimits) {
|
|
23662
|
-
const values = query[key];
|
|
23663
|
-
if (values && values.length > max)
|
|
23664
|
-
throw new Error(`Query ${key} accepts at most ${max} entries (got ${values.length})`);
|
|
23665
|
-
}
|
|
23666
|
-
const page = await request(
|
|
23667
|
-
"/memories/query",
|
|
23668
|
-
{
|
|
23669
|
-
method: "POST",
|
|
23670
|
-
body: JSON.stringify(
|
|
23671
|
-
Object.fromEntries(
|
|
23672
|
-
queryFields.filter((key) => query[key] !== void 0).map((key) => [key, query[key]])
|
|
23673
|
-
)
|
|
23674
|
-
)
|
|
23675
|
-
},
|
|
23676
|
-
signal
|
|
23677
|
-
);
|
|
23678
|
-
if (!record(page) || !Array.isArray(page.items) || page.next_cursor !== void 0 && typeof page.next_cursor !== "string" || page.changes_cursor !== void 0 && typeof page.changes_cursor !== "string")
|
|
23679
|
-
throw new Error("Invalid nearby private-memory page");
|
|
23719
|
+
const page = await fetchQueryPage(queryOptions);
|
|
23680
23720
|
return {
|
|
23681
23721
|
...await decodeAll(page.items),
|
|
23682
23722
|
...page.next_cursor !== void 0 && { next_cursor: page.next_cursor },
|
|
23683
23723
|
...page.changes_cursor !== void 0 && { changes_cursor: page.changes_cursor }
|
|
23684
23724
|
};
|
|
23685
23725
|
},
|
|
23726
|
+
queryMetadata: async (queryOptions = {}) => {
|
|
23727
|
+
const page = await fetchQueryPage(queryOptions);
|
|
23728
|
+
return {
|
|
23729
|
+
items: page.items.map((item) => {
|
|
23730
|
+
const {
|
|
23731
|
+
memory: { content: _content, kind_value: _kindValue, ...memory },
|
|
23732
|
+
version,
|
|
23733
|
+
server_updated_at
|
|
23734
|
+
} = memoryRecord(item);
|
|
23735
|
+
return { memory, version, server_updated_at };
|
|
23736
|
+
}),
|
|
23737
|
+
...page.next_cursor !== void 0 && { next_cursor: page.next_cursor }
|
|
23738
|
+
};
|
|
23739
|
+
},
|
|
23686
23740
|
candidateSet,
|
|
23687
23741
|
candidates: async (embedding, candidateOptions = {}) => decodeAll((await fetchCandidates(embedding, candidateOptions, false)).items)
|
|
23688
23742
|
};
|
|
@@ -24075,6 +24129,19 @@ function createRemoteMemoryPipeline(options) {
|
|
|
24075
24129
|
// src/lib/memory/store/remoteStore.ts
|
|
24076
24130
|
var import_uuid6 = require("uuid");
|
|
24077
24131
|
init_logger();
|
|
24132
|
+
function projection({ memory }) {
|
|
24133
|
+
return {
|
|
24134
|
+
uniqueId: memory.memory_id,
|
|
24135
|
+
scope: memory.scope,
|
|
24136
|
+
folderId: memory.folder_id ?? null,
|
|
24137
|
+
embedding: memory.embedding?.length ? JSON.stringify(memory.embedding) : null,
|
|
24138
|
+
embeddingModel: memory.embedding_model ?? null,
|
|
24139
|
+
createdAt: new Date(memory.created_at),
|
|
24140
|
+
updatedAt: new Date(memory.updated_at),
|
|
24141
|
+
lastObservedAt: memory.last_observed_at ?? null,
|
|
24142
|
+
topicsUserManaged: memory.topics_user_managed ?? false
|
|
24143
|
+
};
|
|
24144
|
+
}
|
|
24078
24145
|
function relevant(change, options) {
|
|
24079
24146
|
return options.includeDeleted ? change === "membership" : change !== "embedding" || !!options.embeddings;
|
|
24080
24147
|
}
|
|
@@ -24109,6 +24176,9 @@ function bounded(filters, key) {
|
|
|
24109
24176
|
if (!values || values.length <= MAX_QUERY_FILTER) return [filters];
|
|
24110
24177
|
return chunks(values, MAX_QUERY_FILTER).map((chunk) => ({ ...filters, [key]: chunk }));
|
|
24111
24178
|
}
|
|
24179
|
+
function maxOf(options) {
|
|
24180
|
+
return options.limit && options.limit > 0 ? options.limit : Infinity;
|
|
24181
|
+
}
|
|
24112
24182
|
function chunks(values, size) {
|
|
24113
24183
|
const out = [];
|
|
24114
24184
|
for (let i = 0; i < values.length; i += size) out.push(values.slice(i, i + size));
|
|
@@ -24180,26 +24250,49 @@ function createRemoteMemoryStore(options) {
|
|
|
24180
24250
|
for (const subscriber of [...subscribers])
|
|
24181
24251
|
if (relevant(change, subscriber.options)) safely(subscriber.onChange);
|
|
24182
24252
|
};
|
|
24183
|
-
const
|
|
24253
|
+
const pages = async (read, filters, max = Infinity) => {
|
|
24184
24254
|
const records = [];
|
|
24185
24255
|
let cursor2;
|
|
24186
24256
|
do {
|
|
24187
|
-
const page = await
|
|
24257
|
+
const page = await read({
|
|
24188
24258
|
...filters,
|
|
24189
24259
|
limit: Math.min(200, Math.max(1, max - records.length)),
|
|
24190
24260
|
...cursor2 && { cursor: cursor2 }
|
|
24191
24261
|
});
|
|
24192
|
-
warnFailed(page.failed);
|
|
24262
|
+
if (page.failed) warnFailed(page.failed);
|
|
24193
24263
|
records.push(...page.items);
|
|
24194
24264
|
cursor2 = page.next_cursor;
|
|
24195
24265
|
} while (cursor2 && records.length < max);
|
|
24196
24266
|
return records.slice(0, max);
|
|
24197
24267
|
};
|
|
24198
|
-
const
|
|
24268
|
+
const decrypted = (options2) => persistence.query(options2);
|
|
24269
|
+
const metadata = (options2) => persistence.queryMetadata(options2);
|
|
24270
|
+
const enumerate = (filters, max = Infinity) => pages(decrypted, filters, max);
|
|
24271
|
+
const enumerateIds = async (read, ids, filters) => (await Promise.all(
|
|
24199
24272
|
chunks([...new Set(ids)], MAX_QUERY_IDS).map(
|
|
24200
|
-
(memory_ids) =>
|
|
24273
|
+
(memory_ids) => pages(read, { ...filters, memory_ids })
|
|
24201
24274
|
)
|
|
24202
24275
|
)).flat();
|
|
24276
|
+
const listFilters = (listOptions) => ({
|
|
24277
|
+
...stateFilters(listOptions),
|
|
24278
|
+
include_embeddings: true,
|
|
24279
|
+
order: listOptions.since ? "updated" : "created",
|
|
24280
|
+
...listOptions.scopes?.length && { scopes: listOptions.scopes },
|
|
24281
|
+
...listOptions.factTypes?.length && { fact_types: listOptions.factTypes },
|
|
24282
|
+
...listOptions.visibility?.length && { visibility: listOptions.visibility },
|
|
24283
|
+
...listOptions.since && { updated_after: listOptions.since.getTime() }
|
|
24284
|
+
});
|
|
24285
|
+
const listRows = async (read, listOptions, filters, max) => {
|
|
24286
|
+
const variants = bounded(filters, "scopes").flatMap((f) => bounded(f, "fact_types"));
|
|
24287
|
+
if (!listOptions.memoryIds && variants.length === 1) return pages(read, filters, max);
|
|
24288
|
+
const fetched = await Promise.all(
|
|
24289
|
+
variants.map(
|
|
24290
|
+
(variant) => listOptions.memoryIds ? enumerateIds(read, listOptions.memoryIds, variant) : pages(read, variant, max)
|
|
24291
|
+
)
|
|
24292
|
+
);
|
|
24293
|
+
const time = (row) => filters.order === "updated" ? row.memory.updated_at : row.memory.created_at;
|
|
24294
|
+
return [...new Map(fetched.flat().map((r) => [r.memory.memory_id, r])).values()].sort((a, b) => time(b) - time(a) || (a.memory.memory_id < b.memory.memory_id ? 1 : -1)).slice(0, max);
|
|
24295
|
+
};
|
|
24203
24296
|
const queues = /* @__PURE__ */ new Map();
|
|
24204
24297
|
const serialized = (id, task) => {
|
|
24205
24298
|
const run = (queues.get(id) ?? Promise.resolve()).then(task, task);
|
|
@@ -24241,12 +24334,15 @@ function createRemoteMemoryStore(options) {
|
|
|
24241
24334
|
};
|
|
24242
24335
|
const newRow = (input) => {
|
|
24243
24336
|
const now = Date.now();
|
|
24244
|
-
const scope = input
|
|
24337
|
+
const { level, scope } = resolveCreateLevel(input);
|
|
24338
|
+
assertValidKindLevel(input.kind, level);
|
|
24245
24339
|
return {
|
|
24246
24340
|
memory_id: (0, import_uuid6.v7)(),
|
|
24247
24341
|
content: input.content,
|
|
24248
24342
|
scope,
|
|
24249
|
-
level
|
|
24343
|
+
level,
|
|
24344
|
+
...input.kind !== void 0 && input.kind !== null && { kind: input.kind },
|
|
24345
|
+
...typeof input.kindValue === "string" && { kind_value: input.kindValue },
|
|
24250
24346
|
created_at: now,
|
|
24251
24347
|
updated_at: now,
|
|
24252
24348
|
is_deleted: false,
|
|
@@ -24275,6 +24371,30 @@ function createRemoteMemoryStore(options) {
|
|
|
24275
24371
|
return records.map((record2) => stored(record2.memory));
|
|
24276
24372
|
};
|
|
24277
24373
|
const asStored = (record2) => record2 ? stored(record2.memory) : null;
|
|
24374
|
+
const withKnownKinds = async (topics) => {
|
|
24375
|
+
const unkinded = [
|
|
24376
|
+
...new Set(topics.filter((t) => !t.kind).map((t) => normalizeEntityName(t.name)))
|
|
24377
|
+
];
|
|
24378
|
+
if (unkinded.length === 0) return topics;
|
|
24379
|
+
const kinds = /* @__PURE__ */ new Map();
|
|
24380
|
+
for (const names of chunks(unkinded, MAX_QUERY_TOPICS)) {
|
|
24381
|
+
for (const { memory } of await pages(metadata, {
|
|
24382
|
+
topics: names,
|
|
24383
|
+
include_archived: true,
|
|
24384
|
+
include_quarantined: true,
|
|
24385
|
+
include_superseded: true
|
|
24386
|
+
})) {
|
|
24387
|
+
for (const topic of parseTopics(memory.topics) ?? []) {
|
|
24388
|
+
const name = normalizeEntityName(topic.name);
|
|
24389
|
+
if (topic.kind && !kinds.has(name)) kinds.set(name, topic.kind);
|
|
24390
|
+
}
|
|
24391
|
+
}
|
|
24392
|
+
}
|
|
24393
|
+
return topics.map((topic) => {
|
|
24394
|
+
const kind = topic.kind ?? kinds.get(normalizeEntityName(topic.name));
|
|
24395
|
+
return kind ? { ...topic, kind } : topic;
|
|
24396
|
+
});
|
|
24397
|
+
};
|
|
24278
24398
|
const everyState = {
|
|
24279
24399
|
include_deleted: true,
|
|
24280
24400
|
include_archived: true,
|
|
@@ -24351,30 +24471,34 @@ function createRemoteMemoryStore(options) {
|
|
|
24351
24471
|
});
|
|
24352
24472
|
};
|
|
24353
24473
|
return {
|
|
24354
|
-
list: async (listOptions = {}) =>
|
|
24355
|
-
|
|
24356
|
-
|
|
24357
|
-
|
|
24358
|
-
|
|
24359
|
-
|
|
24360
|
-
|
|
24361
|
-
|
|
24362
|
-
|
|
24363
|
-
|
|
24364
|
-
|
|
24365
|
-
|
|
24366
|
-
|
|
24367
|
-
|
|
24368
|
-
|
|
24369
|
-
|
|
24370
|
-
|
|
24371
|
-
|
|
24372
|
-
|
|
24373
|
-
|
|
24374
|
-
|
|
24375
|
-
|
|
24376
|
-
|
|
24377
|
-
|
|
24474
|
+
list: async (listOptions = {}) => (await listRows(decrypted, listOptions, listFilters(listOptions), maxOf(listOptions))).map(
|
|
24475
|
+
(r) => stored(r.memory)
|
|
24476
|
+
),
|
|
24477
|
+
listProjections: async (listOptions = {}) => (await listRows(metadata, listOptions, listFilters(listOptions), maxOf(listOptions))).map(
|
|
24478
|
+
projection
|
|
24479
|
+
),
|
|
24480
|
+
listTopics: async () => {
|
|
24481
|
+
const topics = /* @__PURE__ */ new Map();
|
|
24482
|
+
for (const { memory } of await pages(metadata, {
|
|
24483
|
+
include_archived: true,
|
|
24484
|
+
include_quarantined: true,
|
|
24485
|
+
include_superseded: true
|
|
24486
|
+
})) {
|
|
24487
|
+
for (const topic of parseTopics(memory.topics) ?? []) {
|
|
24488
|
+
const name = normalizeEntityName(topic.name);
|
|
24489
|
+
if (!name) continue;
|
|
24490
|
+
const entry = topics.get(name) ?? {
|
|
24491
|
+
name,
|
|
24492
|
+
kind: null,
|
|
24493
|
+
memoryCount: 0,
|
|
24494
|
+
members: /* @__PURE__ */ new Set()
|
|
24495
|
+
};
|
|
24496
|
+
entry.kind ?? (entry.kind = topic.kind ?? null);
|
|
24497
|
+
entry.members.add(memory.memory_id);
|
|
24498
|
+
topics.set(name, entry);
|
|
24499
|
+
}
|
|
24500
|
+
}
|
|
24501
|
+
return [...topics.values()].map(({ members, ...topic }) => ({ ...topic, memoryCount: members.size })).sort((a, b) => a.name.localeCompare(b.name));
|
|
24378
24502
|
},
|
|
24379
24503
|
get: async (id) => asStored(await live(id)),
|
|
24380
24504
|
listArchived: async () => (await enumerate({ archived_only: true, order: "archived", include_embeddings: true })).map(
|
|
@@ -24383,10 +24507,10 @@ function createRemoteMemoryStore(options) {
|
|
|
24383
24507
|
memoriesByTopics: async (names) => {
|
|
24384
24508
|
const wanted = new Set(names.map(normalizeEntityName).filter(Boolean));
|
|
24385
24509
|
const out = /* @__PURE__ */ new Map();
|
|
24386
|
-
const
|
|
24510
|
+
const pages2 = await Promise.all(
|
|
24387
24511
|
chunks([...wanted], MAX_QUERY_TOPICS).map((topics) => enumerate({ topics }))
|
|
24388
24512
|
);
|
|
24389
|
-
for (const { memory } of
|
|
24513
|
+
for (const { memory } of pages2.flat()) {
|
|
24390
24514
|
const matched = [...canonicalTopics(memory)].filter((name) => wanted.has(name));
|
|
24391
24515
|
if (matched.length) out.set(memory.memory_id, new Set(matched));
|
|
24392
24516
|
}
|
|
@@ -24394,7 +24518,7 @@ function createRemoteMemoryStore(options) {
|
|
|
24394
24518
|
},
|
|
24395
24519
|
topicsByMemories: async (memoryIds) => {
|
|
24396
24520
|
const out = /* @__PURE__ */ new Map();
|
|
24397
|
-
for (const { memory } of await enumerateIds(memoryIds, {
|
|
24521
|
+
for (const { memory } of await enumerateIds(decrypted, memoryIds, {
|
|
24398
24522
|
include_archived: true,
|
|
24399
24523
|
include_superseded: true,
|
|
24400
24524
|
include_quarantined: true
|
|
@@ -24427,15 +24551,26 @@ function createRemoteMemoryStore(options) {
|
|
|
24427
24551
|
update: async (id, patch) => {
|
|
24428
24552
|
const saved = await mutate(id, "edit", (memory) => {
|
|
24429
24553
|
if (memory.superseded_by) return null;
|
|
24554
|
+
const level = patch.level !== void 0 ? patch.level : patch.scope !== void 0 ? levelForScopeChange({ level: memory.level, scope: memory.scope }, patch.scope) : resolveMemoryLevel(memory.level, memory.scope);
|
|
24555
|
+
const kind = patch.kind !== void 0 ? patch.kind : memory.kind;
|
|
24556
|
+
assertValidKindLevel(kind, level);
|
|
24430
24557
|
memory.content = patch.content;
|
|
24431
24558
|
memory.updated_at = Date.now();
|
|
24432
|
-
if (patch.
|
|
24433
|
-
memory.level =
|
|
24434
|
-
|
|
24435
|
-
|
|
24436
|
-
|
|
24559
|
+
if (patch.level !== void 0) {
|
|
24560
|
+
memory.level = level;
|
|
24561
|
+
memory.scope = scopeForLevel(level);
|
|
24562
|
+
} else if (patch.scope !== void 0) {
|
|
24563
|
+
memory.level = level;
|
|
24437
24564
|
memory.scope = patch.scope;
|
|
24438
24565
|
}
|
|
24566
|
+
if (patch.kind !== void 0) {
|
|
24567
|
+
if (patch.kind === null) delete memory.kind;
|
|
24568
|
+
else memory.kind = patch.kind;
|
|
24569
|
+
}
|
|
24570
|
+
if (patch.kindValue !== void 0) {
|
|
24571
|
+
if (patch.kindValue === null) delete memory.kind_value;
|
|
24572
|
+
else memory.kind_value = patch.kindValue;
|
|
24573
|
+
}
|
|
24439
24574
|
if (patch.factType !== void 0) memory.fact_type = patch.factType ?? void 0;
|
|
24440
24575
|
if (patch.eventTime !== void 0) {
|
|
24441
24576
|
memory.event_time_start = patch.eventTime?.start ?? void 0;
|
|
@@ -24490,16 +24625,19 @@ function createRemoteMemoryStore(options) {
|
|
|
24490
24625
|
notify("edit", [await persistence.put(memory, record2)]);
|
|
24491
24626
|
return true;
|
|
24492
24627
|
}),
|
|
24493
|
-
setTopics: async (memoryId, topics) =>
|
|
24494
|
-
await
|
|
24495
|
-
|
|
24496
|
-
|
|
24497
|
-
|
|
24498
|
-
|
|
24499
|
-
|
|
24500
|
-
|
|
24628
|
+
setTopics: async (memoryId, topics) => {
|
|
24629
|
+
const chosen = await withKnownKinds(topicInputs(topics, "user"));
|
|
24630
|
+
return asStored(
|
|
24631
|
+
await mutate(memoryId, "edit", (memory) => ({
|
|
24632
|
+
...memory,
|
|
24633
|
+
topics: serializeTopics(mergeTopics([], chosen)),
|
|
24634
|
+
topics_user_managed: true,
|
|
24635
|
+
topics_updated_at: Date.now()
|
|
24636
|
+
}))
|
|
24637
|
+
);
|
|
24638
|
+
},
|
|
24501
24639
|
addTopics: async (memoryId, topics) => {
|
|
24502
|
-
const added = topicInputs(topics, "auto");
|
|
24640
|
+
const added = await withKnownKinds(topicInputs(topics, "auto"));
|
|
24503
24641
|
const saved = await mutate(memoryId, "edit", (memory) => ({
|
|
24504
24642
|
...memory,
|
|
24505
24643
|
topics: serializeTopics(mergeTopics(parseTopics(memory.topics) ?? [], added)),
|