@anuma/sdk 9.1.6 → 9.1.8
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/client/index.cjs +106 -94
- package/dist/client/index.mjs +106 -94
- package/dist/expo/index.cjs +56 -9
- package/dist/expo/index.mjs +56 -9
- package/dist/index.cjs +47 -35
- package/dist/index.mjs +47 -35
- package/dist/react/index.cjs +70 -14
- package/dist/react/index.mjs +70 -14
- package/dist/server/index.cjs +64 -8
- package/dist/server/index.mjs +64 -8
- package/dist/tools/selection/index.cjs +14 -2
- package/dist/tools/selection/index.mjs +14 -2
- package/package.json +1 -1
package/dist/react/index.mjs
CHANGED
|
@@ -1748,7 +1748,14 @@ function cosineSimilarity(a, b) {
|
|
|
1748
1748
|
|
|
1749
1749
|
// src/lib/processors/encoding.ts
|
|
1750
1750
|
var B64_ENCODE_CHUNK = 32768 * 3;
|
|
1751
|
+
function assertFileUrlAllowed(dataUrl) {
|
|
1752
|
+
const isNode = typeof process !== "undefined" && Boolean(process.versions?.node);
|
|
1753
|
+
if (isNode && !dataUrl.startsWith("data:") && !dataUrl.startsWith("blob:")) {
|
|
1754
|
+
throw new Error("Server file preprocessing requires a data URL or blob URL.");
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1751
1757
|
async function dataUrlToArrayBuffer(dataUrl) {
|
|
1758
|
+
assertFileUrlAllowed(dataUrl);
|
|
1752
1759
|
if (dataUrl.startsWith("blob:") || dataUrl.startsWith("http://") || dataUrl.startsWith("https://")) {
|
|
1753
1760
|
const response = await fetch(dataUrl);
|
|
1754
1761
|
return response.arrayBuffer();
|
|
@@ -4404,7 +4411,7 @@ var mergeHeaders = (...headers) => {
|
|
|
4404
4411
|
if (!header || typeof header !== "object") {
|
|
4405
4412
|
continue;
|
|
4406
4413
|
}
|
|
4407
|
-
const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
|
|
4414
|
+
const iterator = Array.isArray(header) || header instanceof Headers ? headersEntries(new Headers(header)) : Object.entries(header);
|
|
4408
4415
|
for (const [key, value] of iterator) {
|
|
4409
4416
|
if (value === null) {
|
|
4410
4417
|
mergedHeaders.delete(key);
|
|
@@ -4679,6 +4686,18 @@ var createClient = (config = {}) => {
|
|
|
4679
4686
|
// src/client/client.gen.ts
|
|
4680
4687
|
var client = createClient(createClientConfig(createConfig()));
|
|
4681
4688
|
|
|
4689
|
+
// src/clientHeaders.ts
|
|
4690
|
+
function normalizeHeaders(headers) {
|
|
4691
|
+
if (headers instanceof Headers || Array.isArray(headers)) {
|
|
4692
|
+
const normalized = /* @__PURE__ */ Object.create(null);
|
|
4693
|
+
new Headers(headers).forEach((value, name) => {
|
|
4694
|
+
normalized[name] = value;
|
|
4695
|
+
});
|
|
4696
|
+
return normalized;
|
|
4697
|
+
}
|
|
4698
|
+
return headers;
|
|
4699
|
+
}
|
|
4700
|
+
|
|
4682
4701
|
// src/client/sdk.gen.ts
|
|
4683
4702
|
var getApiV1Config = (options) => (options?.client ?? client).get({ url: "/api/v1/config", ...options });
|
|
4684
4703
|
var getApiV1CreditsBalance = (options) => (options?.client ?? client).get({ url: "/api/v1/credits/balance", ...options });
|
|
@@ -4688,7 +4707,7 @@ var postApiV1CreditsPurchase = (options) => (options.client ?? client).post({
|
|
|
4688
4707
|
...options,
|
|
4689
4708
|
headers: {
|
|
4690
4709
|
"Content-Type": "application/json",
|
|
4691
|
-
...options.headers
|
|
4710
|
+
...normalizeHeaders(options.headers)
|
|
4692
4711
|
}
|
|
4693
4712
|
});
|
|
4694
4713
|
var postApiV1Embeddings = (options) => (options.client ?? client).post({
|
|
@@ -4696,7 +4715,7 @@ var postApiV1Embeddings = (options) => (options.client ?? client).post({
|
|
|
4696
4715
|
...options,
|
|
4697
4716
|
headers: {
|
|
4698
4717
|
"Content-Type": "application/json",
|
|
4699
|
-
...options.headers
|
|
4718
|
+
...normalizeHeaders(options.headers)
|
|
4700
4719
|
}
|
|
4701
4720
|
});
|
|
4702
4721
|
var getApiV1Models = (options) => (options?.client ?? client).get({ url: "/api/v1/models", ...options });
|
|
@@ -4705,7 +4724,7 @@ var postApiV1PhoneCalls = (options) => (options.client ?? client).post({
|
|
|
4705
4724
|
...options,
|
|
4706
4725
|
headers: {
|
|
4707
4726
|
"Content-Type": "application/json",
|
|
4708
|
-
...options.headers
|
|
4727
|
+
...normalizeHeaders(options.headers)
|
|
4709
4728
|
}
|
|
4710
4729
|
});
|
|
4711
4730
|
var getApiV1PhoneCallsByCallId = (options) => (options.client ?? client).get({ url: "/api/v1/phone-calls/{call_id}", ...options });
|
|
@@ -4714,7 +4733,7 @@ var postApiV1SubscriptionsCancel = (options) => (options?.client ?? client).post
|
|
|
4714
4733
|
...options,
|
|
4715
4734
|
headers: {
|
|
4716
4735
|
"Content-Type": "application/json",
|
|
4717
|
-
...options?.headers
|
|
4736
|
+
...normalizeHeaders(options?.headers)
|
|
4718
4737
|
}
|
|
4719
4738
|
});
|
|
4720
4739
|
var postApiV1SubscriptionsCreateCheckoutSession = (options) => (options.client ?? client).post({
|
|
@@ -4722,7 +4741,7 @@ var postApiV1SubscriptionsCreateCheckoutSession = (options) => (options.client ?
|
|
|
4722
4741
|
...options,
|
|
4723
4742
|
headers: {
|
|
4724
4743
|
"Content-Type": "application/json",
|
|
4725
|
-
...options.headers
|
|
4744
|
+
...normalizeHeaders(options.headers)
|
|
4726
4745
|
}
|
|
4727
4746
|
});
|
|
4728
4747
|
var postApiV1SubscriptionsCustomerPortal = (options) => (options.client ?? client).post({
|
|
@@ -4730,7 +4749,7 @@ var postApiV1SubscriptionsCustomerPortal = (options) => (options.client ?? clien
|
|
|
4730
4749
|
...options,
|
|
4731
4750
|
headers: {
|
|
4732
4751
|
"Content-Type": "application/json",
|
|
4733
|
-
...options.headers
|
|
4752
|
+
...normalizeHeaders(options.headers)
|
|
4734
4753
|
}
|
|
4735
4754
|
});
|
|
4736
4755
|
var postApiV1SubscriptionsRenew = (options) => (options?.client ?? client).post({ url: "/api/v1/subscriptions/renew", ...options });
|
|
@@ -4741,7 +4760,7 @@ var postApiV1WalletsBinding = (options) => (options.client ?? client).post({
|
|
|
4741
4760
|
...options,
|
|
4742
4761
|
headers: {
|
|
4743
4762
|
"Content-Type": "application/json",
|
|
4744
|
-
...options.headers
|
|
4763
|
+
...normalizeHeaders(options.headers)
|
|
4745
4764
|
}
|
|
4746
4765
|
});
|
|
4747
4766
|
var postApiV1WalletsBindingNonce = (options) => (options?.client ?? client).post({ url: "/api/v1/wallets/binding/nonce", ...options });
|
|
@@ -14812,10 +14831,10 @@ async function getVaultRankingProjectionsOp(ctx, options) {
|
|
|
14812
14831
|
function baseVaultSql(ctx, options) {
|
|
14813
14832
|
const clauses = [
|
|
14814
14833
|
`"_status" is not 'deleted'`,
|
|
14815
|
-
'"is_deleted" = 0',
|
|
14834
|
+
...options?.includeDeleted ? [] : ['"is_deleted" = 0'],
|
|
14816
14835
|
...options?.includeArchived ? [] : ['"archived_at" is null'],
|
|
14817
14836
|
...options?.includeQuarantined ? [] : [`"trust_tier" is not 'quarantined'`],
|
|
14818
|
-
'"superseded_by" is null'
|
|
14837
|
+
...options?.includeSuperseded ? [] : ['"superseded_by" is null']
|
|
14819
14838
|
];
|
|
14820
14839
|
const args = [];
|
|
14821
14840
|
if (ctx.userId !== void 0) {
|
|
@@ -14824,6 +14843,38 @@ function baseVaultSql(ctx, options) {
|
|
|
14824
14843
|
}
|
|
14825
14844
|
return { sql: clauses.join(" and "), args };
|
|
14826
14845
|
}
|
|
14846
|
+
async function getVaultProfileMetadataOp(ctx, options) {
|
|
14847
|
+
const mapRaw = (raw) => ({
|
|
14848
|
+
uniqueId: raw.id,
|
|
14849
|
+
scope: raw.scope ?? "",
|
|
14850
|
+
createdAt: new Date(raw.created_at),
|
|
14851
|
+
updatedAt: new Date(raw.updated_at),
|
|
14852
|
+
lastObservedAt: raw.last_observed_at ?? null,
|
|
14853
|
+
supersededAt: raw.superseded_at ?? null,
|
|
14854
|
+
supersededBy: raw.superseded_by ?? null,
|
|
14855
|
+
isDeleted: raw.is_deleted === true || raw.is_deleted === 1,
|
|
14856
|
+
proofCount: raw.proof_count ?? null
|
|
14857
|
+
});
|
|
14858
|
+
const listOptions = { ...options, includeDeleted: true, includeSuperseded: true };
|
|
14859
|
+
let rows;
|
|
14860
|
+
try {
|
|
14861
|
+
const base = baseVaultSql(ctx, listOptions);
|
|
14862
|
+
const clauses = [base.sql, `"_status" != 'deleted'`];
|
|
14863
|
+
const args = [...base.args];
|
|
14864
|
+
if (options?.scopes?.length) {
|
|
14865
|
+
clauses.push(`"scope" in (${options.scopes.map(() => "?").join(",")})`);
|
|
14866
|
+
args.push(...options.scopes);
|
|
14867
|
+
}
|
|
14868
|
+
const sql = `select "id", "scope", "created_at", "updated_at", "last_observed_at", "superseded_at", "superseded_by", "is_deleted", "proof_count" from "memory_vault" where ${clauses.join(" and ")}`;
|
|
14869
|
+
rows = await ctx.vaultMemoryCollection.query(Q9.unsafeSqlQuery(sql, args)).unsafeFetchRaw();
|
|
14870
|
+
} catch (err) {
|
|
14871
|
+
getLogger().debug(
|
|
14872
|
+
"memoryVault: getVaultProfileMetadataOp uses the query fallback: " + (err instanceof Error ? err.message : String(err))
|
|
14873
|
+
);
|
|
14874
|
+
rows = await ctx.vaultMemoryCollection.query(...vaultListConditions(ctx, listOptions)).unsafeFetchRaw();
|
|
14875
|
+
}
|
|
14876
|
+
return rows.map(mapRaw);
|
|
14877
|
+
}
|
|
14827
14878
|
async function getVaultCandidateKeysOp(ctx, options) {
|
|
14828
14879
|
const mapRaw = (raw) => ({
|
|
14829
14880
|
uniqueId: raw.id,
|
|
@@ -24981,7 +25032,7 @@ async function synthesizeProfile(ctx, options = {}) {
|
|
|
24981
25032
|
};
|
|
24982
25033
|
const previous = options.previous && options.previous.version === PROFILE_DOC_VERSION && configMatches(options.previous.config, config) ? options.previous : void 0;
|
|
24983
25034
|
const listOptions = { scopes, includeDeleted: true, includeSuperseded: true };
|
|
24984
|
-
const [memories, projections] = store ? await Promise.all([store.list(listOptions), store.listProjections(listOptions)]) : [await
|
|
25035
|
+
const [memories, projections] = store ? await Promise.all([store.list(listOptions), store.listProjections(listOptions)]) : [await getVaultProfileMetadataOp(vaultCtx, { scopes }), []];
|
|
24985
25036
|
const watermark = computeVaultWatermark(memories);
|
|
24986
25037
|
const observationTrends = summarizeObservationTrends(
|
|
24987
25038
|
memories.filter((m) => !m.isDeleted && m.supersededBy === null).map((m) => ({
|
|
@@ -25017,7 +25068,8 @@ async function synthesizeProfile(ctx, options = {}) {
|
|
|
25017
25068
|
previous,
|
|
25018
25069
|
watermark,
|
|
25019
25070
|
options.reviewedMemoryIds,
|
|
25020
|
-
previousUnreadable
|
|
25071
|
+
previousUnreadable,
|
|
25072
|
+
store ? void 0 : (ids) => getVaultEmbeddingsByIdsOp(vaultCtx, ids)
|
|
25021
25073
|
);
|
|
25022
25074
|
const memoriesById = new Map(memories.map((memory) => [memory.uniqueId, memory]));
|
|
25023
25075
|
const fallbackPriors = /* @__PURE__ */ new Map();
|
|
@@ -25104,7 +25156,7 @@ function computeVaultWatermark(memories) {
|
|
|
25104
25156
|
}
|
|
25105
25157
|
return max;
|
|
25106
25158
|
}
|
|
25107
|
-
async function computeStaleFacetKeys(ctx, memories, facets, previous, watermark, reviewedMemoryIds, previouslyUnreadable) {
|
|
25159
|
+
async function computeStaleFacetKeys(ctx, memories, facets, previous, watermark, reviewedMemoryIds, previouslyUnreadable, loadEmbeddings) {
|
|
25108
25160
|
const allKeys = new Set(facets.map((f) => f.key));
|
|
25109
25161
|
if (previous && watermark < previous.vaultWatermark) return allKeys;
|
|
25110
25162
|
if (!previous) return allKeys;
|
|
@@ -25137,7 +25189,9 @@ async function computeStaleFacetKeys(ctx, memories, facets, previous, watermark,
|
|
|
25137
25189
|
toAttribute = toAttribute.filter((m) => allowed.has(m.uniqueId));
|
|
25138
25190
|
}
|
|
25139
25191
|
if (toAttribute.length > 0) {
|
|
25140
|
-
const
|
|
25192
|
+
const candidates = loadEmbeddings ? await loadEmbeddings(toAttribute.map((m) => m.uniqueId)) : toAttribute;
|
|
25193
|
+
if (candidates.length !== toAttribute.length) return allKeys;
|
|
25194
|
+
const attributed = await attributeFacts(ctx, candidates, facets);
|
|
25141
25195
|
if (attributed === null) return allKeys;
|
|
25142
25196
|
for (const k of attributed) stale.add(k);
|
|
25143
25197
|
}
|
|
@@ -27701,6 +27755,7 @@ async function getPdfjs() {
|
|
|
27701
27755
|
return pdfjsModule;
|
|
27702
27756
|
}
|
|
27703
27757
|
async function withPdfDocument(pdfDataUrl, fn) {
|
|
27758
|
+
assertFileUrlAllowed(pdfDataUrl);
|
|
27704
27759
|
const pdfjs = await getPdfjs();
|
|
27705
27760
|
const loadingTask = pdfjs.getDocument(pdfDataUrl);
|
|
27706
27761
|
let pdf;
|
|
@@ -28497,6 +28552,7 @@ async function preprocessFiles(files, options = {}) {
|
|
|
28497
28552
|
skip("no_data");
|
|
28498
28553
|
continue;
|
|
28499
28554
|
}
|
|
28555
|
+
assertFileUrlAllowed(file.url);
|
|
28500
28556
|
const fileWithData = {
|
|
28501
28557
|
...file,
|
|
28502
28558
|
dataUrl: file.url
|
package/dist/server/index.cjs
CHANGED
|
@@ -17686,7 +17686,14 @@ function cosineSimilarity(a, b) {
|
|
|
17686
17686
|
|
|
17687
17687
|
// src/lib/processors/encoding.ts
|
|
17688
17688
|
var B64_ENCODE_CHUNK = 32768 * 3;
|
|
17689
|
+
function assertFileUrlAllowed(dataUrl) {
|
|
17690
|
+
const isNode = typeof process !== "undefined" && Boolean(process.versions?.node);
|
|
17691
|
+
if (isNode && !dataUrl.startsWith("data:") && !dataUrl.startsWith("blob:")) {
|
|
17692
|
+
throw new Error("Server file preprocessing requires a data URL or blob URL.");
|
|
17693
|
+
}
|
|
17694
|
+
}
|
|
17689
17695
|
async function dataUrlToArrayBuffer(dataUrl) {
|
|
17696
|
+
assertFileUrlAllowed(dataUrl);
|
|
17690
17697
|
if (dataUrl.startsWith("blob:") || dataUrl.startsWith("http://") || dataUrl.startsWith("https://")) {
|
|
17691
17698
|
const response = await fetch(dataUrl);
|
|
17692
17699
|
return response.arrayBuffer();
|
|
@@ -20016,7 +20023,7 @@ var mergeHeaders = (...headers) => {
|
|
|
20016
20023
|
if (!header || typeof header !== "object") {
|
|
20017
20024
|
continue;
|
|
20018
20025
|
}
|
|
20019
|
-
const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
|
|
20026
|
+
const iterator = Array.isArray(header) || header instanceof Headers ? headersEntries(new Headers(header)) : Object.entries(header);
|
|
20020
20027
|
for (const [key, value] of iterator) {
|
|
20021
20028
|
if (value === null) {
|
|
20022
20029
|
mergedHeaders.delete(key);
|
|
@@ -20292,13 +20299,25 @@ var createClient = (config = {}) => {
|
|
|
20292
20299
|
init_clientConfig();
|
|
20293
20300
|
var client = createClient(createClientConfig(createConfig()));
|
|
20294
20301
|
|
|
20302
|
+
// src/clientHeaders.ts
|
|
20303
|
+
function normalizeHeaders(headers) {
|
|
20304
|
+
if (headers instanceof Headers || Array.isArray(headers)) {
|
|
20305
|
+
const normalized = /* @__PURE__ */ Object.create(null);
|
|
20306
|
+
new Headers(headers).forEach((value, name) => {
|
|
20307
|
+
normalized[name] = value;
|
|
20308
|
+
});
|
|
20309
|
+
return normalized;
|
|
20310
|
+
}
|
|
20311
|
+
return headers;
|
|
20312
|
+
}
|
|
20313
|
+
|
|
20295
20314
|
// src/client/sdk.gen.ts
|
|
20296
20315
|
var postApiV1Embeddings = (options) => (options.client ?? client).post({
|
|
20297
20316
|
url: "/api/v1/embeddings",
|
|
20298
20317
|
...options,
|
|
20299
20318
|
headers: {
|
|
20300
20319
|
"Content-Type": "application/json",
|
|
20301
|
-
...options.headers
|
|
20320
|
+
...normalizeHeaders(options.headers)
|
|
20302
20321
|
}
|
|
20303
20322
|
});
|
|
20304
20323
|
|
|
@@ -28952,10 +28971,10 @@ async function getVaultRankingProjectionsOp(ctx, options) {
|
|
|
28952
28971
|
function baseVaultSql(ctx, options) {
|
|
28953
28972
|
const clauses = [
|
|
28954
28973
|
`"_status" is not 'deleted'`,
|
|
28955
|
-
'"is_deleted" = 0',
|
|
28974
|
+
...options?.includeDeleted ? [] : ['"is_deleted" = 0'],
|
|
28956
28975
|
...options?.includeArchived ? [] : ['"archived_at" is null'],
|
|
28957
28976
|
...options?.includeQuarantined ? [] : [`"trust_tier" is not 'quarantined'`],
|
|
28958
|
-
'"superseded_by" is null'
|
|
28977
|
+
...options?.includeSuperseded ? [] : ['"superseded_by" is null']
|
|
28959
28978
|
];
|
|
28960
28979
|
const args = [];
|
|
28961
28980
|
if (ctx.userId !== void 0) {
|
|
@@ -28964,6 +28983,38 @@ function baseVaultSql(ctx, options) {
|
|
|
28964
28983
|
}
|
|
28965
28984
|
return { sql: clauses.join(" and "), args };
|
|
28966
28985
|
}
|
|
28986
|
+
async function getVaultProfileMetadataOp(ctx, options) {
|
|
28987
|
+
const mapRaw = (raw) => ({
|
|
28988
|
+
uniqueId: raw.id,
|
|
28989
|
+
scope: raw.scope ?? "",
|
|
28990
|
+
createdAt: new Date(raw.created_at),
|
|
28991
|
+
updatedAt: new Date(raw.updated_at),
|
|
28992
|
+
lastObservedAt: raw.last_observed_at ?? null,
|
|
28993
|
+
supersededAt: raw.superseded_at ?? null,
|
|
28994
|
+
supersededBy: raw.superseded_by ?? null,
|
|
28995
|
+
isDeleted: raw.is_deleted === true || raw.is_deleted === 1,
|
|
28996
|
+
proofCount: raw.proof_count ?? null
|
|
28997
|
+
});
|
|
28998
|
+
const listOptions = { ...options, includeDeleted: true, includeSuperseded: true };
|
|
28999
|
+
let rows;
|
|
29000
|
+
try {
|
|
29001
|
+
const base = baseVaultSql(ctx, listOptions);
|
|
29002
|
+
const clauses = [base.sql, `"_status" != 'deleted'`];
|
|
29003
|
+
const args = [...base.args];
|
|
29004
|
+
if (options?.scopes?.length) {
|
|
29005
|
+
clauses.push(`"scope" in (${options.scopes.map(() => "?").join(",")})`);
|
|
29006
|
+
args.push(...options.scopes);
|
|
29007
|
+
}
|
|
29008
|
+
const sql = `select "id", "scope", "created_at", "updated_at", "last_observed_at", "superseded_at", "superseded_by", "is_deleted", "proof_count" from "memory_vault" where ${clauses.join(" and ")}`;
|
|
29009
|
+
rows = await ctx.vaultMemoryCollection.query(import_watermelondb19.Q.unsafeSqlQuery(sql, args)).unsafeFetchRaw();
|
|
29010
|
+
} catch (err) {
|
|
29011
|
+
getLogger().debug(
|
|
29012
|
+
"memoryVault: getVaultProfileMetadataOp uses the query fallback: " + (err instanceof Error ? err.message : String(err))
|
|
29013
|
+
);
|
|
29014
|
+
rows = await ctx.vaultMemoryCollection.query(...vaultListConditions(ctx, listOptions)).unsafeFetchRaw();
|
|
29015
|
+
}
|
|
29016
|
+
return rows.map(mapRaw);
|
|
29017
|
+
}
|
|
28967
29018
|
async function getVaultCandidateKeysOp(ctx, options) {
|
|
28968
29019
|
const mapRaw = (raw) => ({
|
|
28969
29020
|
uniqueId: raw.id,
|
|
@@ -36698,7 +36749,7 @@ async function synthesizeProfile(ctx, options = {}) {
|
|
|
36698
36749
|
};
|
|
36699
36750
|
const previous = options.previous && options.previous.version === PROFILE_DOC_VERSION && configMatches(options.previous.config, config) ? options.previous : void 0;
|
|
36700
36751
|
const listOptions = { scopes, includeDeleted: true, includeSuperseded: true };
|
|
36701
|
-
const [memories, projections] = store ? await Promise.all([store.list(listOptions), store.listProjections(listOptions)]) : [await
|
|
36752
|
+
const [memories, projections] = store ? await Promise.all([store.list(listOptions), store.listProjections(listOptions)]) : [await getVaultProfileMetadataOp(vaultCtx, { scopes }), []];
|
|
36702
36753
|
const watermark = computeVaultWatermark(memories);
|
|
36703
36754
|
const observationTrends = summarizeObservationTrends(
|
|
36704
36755
|
memories.filter((m) => !m.isDeleted && m.supersededBy === null).map((m) => ({
|
|
@@ -36734,7 +36785,8 @@ async function synthesizeProfile(ctx, options = {}) {
|
|
|
36734
36785
|
previous,
|
|
36735
36786
|
watermark,
|
|
36736
36787
|
options.reviewedMemoryIds,
|
|
36737
|
-
previousUnreadable
|
|
36788
|
+
previousUnreadable,
|
|
36789
|
+
store ? void 0 : (ids) => getVaultEmbeddingsByIdsOp(vaultCtx, ids)
|
|
36738
36790
|
);
|
|
36739
36791
|
const memoriesById = new Map(memories.map((memory) => [memory.uniqueId, memory]));
|
|
36740
36792
|
const fallbackPriors = /* @__PURE__ */ new Map();
|
|
@@ -36821,7 +36873,7 @@ function computeVaultWatermark(memories) {
|
|
|
36821
36873
|
}
|
|
36822
36874
|
return max;
|
|
36823
36875
|
}
|
|
36824
|
-
async function computeStaleFacetKeys(ctx, memories, facets, previous, watermark, reviewedMemoryIds, previouslyUnreadable) {
|
|
36876
|
+
async function computeStaleFacetKeys(ctx, memories, facets, previous, watermark, reviewedMemoryIds, previouslyUnreadable, loadEmbeddings) {
|
|
36825
36877
|
const allKeys = new Set(facets.map((f) => f.key));
|
|
36826
36878
|
if (previous && watermark < previous.vaultWatermark) return allKeys;
|
|
36827
36879
|
if (!previous) return allKeys;
|
|
@@ -36854,7 +36906,9 @@ async function computeStaleFacetKeys(ctx, memories, facets, previous, watermark,
|
|
|
36854
36906
|
toAttribute = toAttribute.filter((m) => allowed.has(m.uniqueId));
|
|
36855
36907
|
}
|
|
36856
36908
|
if (toAttribute.length > 0) {
|
|
36857
|
-
const
|
|
36909
|
+
const candidates = loadEmbeddings ? await loadEmbeddings(toAttribute.map((m) => m.uniqueId)) : toAttribute;
|
|
36910
|
+
if (candidates.length !== toAttribute.length) return allKeys;
|
|
36911
|
+
const attributed = await attributeFacts(ctx, candidates, facets);
|
|
36858
36912
|
if (attributed === null) return allKeys;
|
|
36859
36913
|
for (const k of attributed) stale.add(k);
|
|
36860
36914
|
}
|
|
@@ -39071,6 +39125,7 @@ async function getPdfjs() {
|
|
|
39071
39125
|
return pdfjsModule;
|
|
39072
39126
|
}
|
|
39073
39127
|
async function withPdfDocument(pdfDataUrl, fn) {
|
|
39128
|
+
assertFileUrlAllowed(pdfDataUrl);
|
|
39074
39129
|
const pdfjs = await getPdfjs();
|
|
39075
39130
|
const loadingTask = pdfjs.getDocument(pdfDataUrl);
|
|
39076
39131
|
let pdf;
|
|
@@ -39865,6 +39920,7 @@ async function preprocessFiles(files, options = {}) {
|
|
|
39865
39920
|
skip("no_data");
|
|
39866
39921
|
continue;
|
|
39867
39922
|
}
|
|
39923
|
+
assertFileUrlAllowed(file.url);
|
|
39868
39924
|
const fileWithData = {
|
|
39869
39925
|
...file,
|
|
39870
39926
|
dataUrl: file.url
|
package/dist/server/index.mjs
CHANGED
|
@@ -15987,7 +15987,14 @@ function cosineSimilarity(a, b) {
|
|
|
15987
15987
|
|
|
15988
15988
|
// src/lib/processors/encoding.ts
|
|
15989
15989
|
var B64_ENCODE_CHUNK = 32768 * 3;
|
|
15990
|
+
function assertFileUrlAllowed(dataUrl) {
|
|
15991
|
+
const isNode = typeof process !== "undefined" && Boolean(process.versions?.node);
|
|
15992
|
+
if (isNode && !dataUrl.startsWith("data:") && !dataUrl.startsWith("blob:")) {
|
|
15993
|
+
throw new Error("Server file preprocessing requires a data URL or blob URL.");
|
|
15994
|
+
}
|
|
15995
|
+
}
|
|
15990
15996
|
async function dataUrlToArrayBuffer(dataUrl) {
|
|
15997
|
+
assertFileUrlAllowed(dataUrl);
|
|
15991
15998
|
if (dataUrl.startsWith("blob:") || dataUrl.startsWith("http://") || dataUrl.startsWith("https://")) {
|
|
15992
15999
|
const response = await fetch(dataUrl);
|
|
15993
16000
|
return response.arrayBuffer();
|
|
@@ -18311,7 +18318,7 @@ var mergeHeaders = (...headers) => {
|
|
|
18311
18318
|
if (!header || typeof header !== "object") {
|
|
18312
18319
|
continue;
|
|
18313
18320
|
}
|
|
18314
|
-
const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
|
|
18321
|
+
const iterator = Array.isArray(header) || header instanceof Headers ? headersEntries(new Headers(header)) : Object.entries(header);
|
|
18315
18322
|
for (const [key, value] of iterator) {
|
|
18316
18323
|
if (value === null) {
|
|
18317
18324
|
mergedHeaders.delete(key);
|
|
@@ -18586,13 +18593,25 @@ var createClient = (config = {}) => {
|
|
|
18586
18593
|
// src/client/client.gen.ts
|
|
18587
18594
|
var client = createClient(createClientConfig(createConfig()));
|
|
18588
18595
|
|
|
18596
|
+
// src/clientHeaders.ts
|
|
18597
|
+
function normalizeHeaders(headers) {
|
|
18598
|
+
if (headers instanceof Headers || Array.isArray(headers)) {
|
|
18599
|
+
const normalized = /* @__PURE__ */ Object.create(null);
|
|
18600
|
+
new Headers(headers).forEach((value, name) => {
|
|
18601
|
+
normalized[name] = value;
|
|
18602
|
+
});
|
|
18603
|
+
return normalized;
|
|
18604
|
+
}
|
|
18605
|
+
return headers;
|
|
18606
|
+
}
|
|
18607
|
+
|
|
18589
18608
|
// src/client/sdk.gen.ts
|
|
18590
18609
|
var postApiV1Embeddings = (options) => (options.client ?? client).post({
|
|
18591
18610
|
url: "/api/v1/embeddings",
|
|
18592
18611
|
...options,
|
|
18593
18612
|
headers: {
|
|
18594
18613
|
"Content-Type": "application/json",
|
|
18595
|
-
...options.headers
|
|
18614
|
+
...normalizeHeaders(options.headers)
|
|
18596
18615
|
}
|
|
18597
18616
|
});
|
|
18598
18617
|
|
|
@@ -27218,10 +27237,10 @@ async function getVaultRankingProjectionsOp(ctx, options) {
|
|
|
27218
27237
|
function baseVaultSql(ctx, options) {
|
|
27219
27238
|
const clauses = [
|
|
27220
27239
|
`"_status" is not 'deleted'`,
|
|
27221
|
-
'"is_deleted" = 0',
|
|
27240
|
+
...options?.includeDeleted ? [] : ['"is_deleted" = 0'],
|
|
27222
27241
|
...options?.includeArchived ? [] : ['"archived_at" is null'],
|
|
27223
27242
|
...options?.includeQuarantined ? [] : [`"trust_tier" is not 'quarantined'`],
|
|
27224
|
-
'"superseded_by" is null'
|
|
27243
|
+
...options?.includeSuperseded ? [] : ['"superseded_by" is null']
|
|
27225
27244
|
];
|
|
27226
27245
|
const args = [];
|
|
27227
27246
|
if (ctx.userId !== void 0) {
|
|
@@ -27230,6 +27249,38 @@ function baseVaultSql(ctx, options) {
|
|
|
27230
27249
|
}
|
|
27231
27250
|
return { sql: clauses.join(" and "), args };
|
|
27232
27251
|
}
|
|
27252
|
+
async function getVaultProfileMetadataOp(ctx, options) {
|
|
27253
|
+
const mapRaw = (raw) => ({
|
|
27254
|
+
uniqueId: raw.id,
|
|
27255
|
+
scope: raw.scope ?? "",
|
|
27256
|
+
createdAt: new Date(raw.created_at),
|
|
27257
|
+
updatedAt: new Date(raw.updated_at),
|
|
27258
|
+
lastObservedAt: raw.last_observed_at ?? null,
|
|
27259
|
+
supersededAt: raw.superseded_at ?? null,
|
|
27260
|
+
supersededBy: raw.superseded_by ?? null,
|
|
27261
|
+
isDeleted: raw.is_deleted === true || raw.is_deleted === 1,
|
|
27262
|
+
proofCount: raw.proof_count ?? null
|
|
27263
|
+
});
|
|
27264
|
+
const listOptions = { ...options, includeDeleted: true, includeSuperseded: true };
|
|
27265
|
+
let rows;
|
|
27266
|
+
try {
|
|
27267
|
+
const base = baseVaultSql(ctx, listOptions);
|
|
27268
|
+
const clauses = [base.sql, `"_status" != 'deleted'`];
|
|
27269
|
+
const args = [...base.args];
|
|
27270
|
+
if (options?.scopes?.length) {
|
|
27271
|
+
clauses.push(`"scope" in (${options.scopes.map(() => "?").join(",")})`);
|
|
27272
|
+
args.push(...options.scopes);
|
|
27273
|
+
}
|
|
27274
|
+
const sql = `select "id", "scope", "created_at", "updated_at", "last_observed_at", "superseded_at", "superseded_by", "is_deleted", "proof_count" from "memory_vault" where ${clauses.join(" and ")}`;
|
|
27275
|
+
rows = await ctx.vaultMemoryCollection.query(import_watermelondb19.Q.unsafeSqlQuery(sql, args)).unsafeFetchRaw();
|
|
27276
|
+
} catch (err) {
|
|
27277
|
+
getLogger().debug(
|
|
27278
|
+
"memoryVault: getVaultProfileMetadataOp uses the query fallback: " + (err instanceof Error ? err.message : String(err))
|
|
27279
|
+
);
|
|
27280
|
+
rows = await ctx.vaultMemoryCollection.query(...vaultListConditions(ctx, listOptions)).unsafeFetchRaw();
|
|
27281
|
+
}
|
|
27282
|
+
return rows.map(mapRaw);
|
|
27283
|
+
}
|
|
27233
27284
|
async function getVaultCandidateKeysOp(ctx, options) {
|
|
27234
27285
|
const mapRaw = (raw) => ({
|
|
27235
27286
|
uniqueId: raw.id,
|
|
@@ -34920,7 +34971,7 @@ async function synthesizeProfile(ctx, options = {}) {
|
|
|
34920
34971
|
};
|
|
34921
34972
|
const previous = options.previous && options.previous.version === PROFILE_DOC_VERSION && configMatches(options.previous.config, config) ? options.previous : void 0;
|
|
34922
34973
|
const listOptions = { scopes, includeDeleted: true, includeSuperseded: true };
|
|
34923
|
-
const [memories, projections] = store ? await Promise.all([store.list(listOptions), store.listProjections(listOptions)]) : [await
|
|
34974
|
+
const [memories, projections] = store ? await Promise.all([store.list(listOptions), store.listProjections(listOptions)]) : [await getVaultProfileMetadataOp(vaultCtx, { scopes }), []];
|
|
34924
34975
|
const watermark = computeVaultWatermark(memories);
|
|
34925
34976
|
const observationTrends = summarizeObservationTrends(
|
|
34926
34977
|
memories.filter((m) => !m.isDeleted && m.supersededBy === null).map((m) => ({
|
|
@@ -34956,7 +35007,8 @@ async function synthesizeProfile(ctx, options = {}) {
|
|
|
34956
35007
|
previous,
|
|
34957
35008
|
watermark,
|
|
34958
35009
|
options.reviewedMemoryIds,
|
|
34959
|
-
previousUnreadable
|
|
35010
|
+
previousUnreadable,
|
|
35011
|
+
store ? void 0 : (ids) => getVaultEmbeddingsByIdsOp(vaultCtx, ids)
|
|
34960
35012
|
);
|
|
34961
35013
|
const memoriesById = new Map(memories.map((memory) => [memory.uniqueId, memory]));
|
|
34962
35014
|
const fallbackPriors = /* @__PURE__ */ new Map();
|
|
@@ -35043,7 +35095,7 @@ function computeVaultWatermark(memories) {
|
|
|
35043
35095
|
}
|
|
35044
35096
|
return max;
|
|
35045
35097
|
}
|
|
35046
|
-
async function computeStaleFacetKeys(ctx, memories, facets, previous, watermark, reviewedMemoryIds, previouslyUnreadable) {
|
|
35098
|
+
async function computeStaleFacetKeys(ctx, memories, facets, previous, watermark, reviewedMemoryIds, previouslyUnreadable, loadEmbeddings) {
|
|
35047
35099
|
const allKeys = new Set(facets.map((f) => f.key));
|
|
35048
35100
|
if (previous && watermark < previous.vaultWatermark) return allKeys;
|
|
35049
35101
|
if (!previous) return allKeys;
|
|
@@ -35076,7 +35128,9 @@ async function computeStaleFacetKeys(ctx, memories, facets, previous, watermark,
|
|
|
35076
35128
|
toAttribute = toAttribute.filter((m) => allowed.has(m.uniqueId));
|
|
35077
35129
|
}
|
|
35078
35130
|
if (toAttribute.length > 0) {
|
|
35079
|
-
const
|
|
35131
|
+
const candidates = loadEmbeddings ? await loadEmbeddings(toAttribute.map((m) => m.uniqueId)) : toAttribute;
|
|
35132
|
+
if (candidates.length !== toAttribute.length) return allKeys;
|
|
35133
|
+
const attributed = await attributeFacts(ctx, candidates, facets);
|
|
35080
35134
|
if (attributed === null) return allKeys;
|
|
35081
35135
|
for (const k of attributed) stale.add(k);
|
|
35082
35136
|
}
|
|
@@ -37286,6 +37340,7 @@ async function getPdfjs() {
|
|
|
37286
37340
|
return pdfjsModule;
|
|
37287
37341
|
}
|
|
37288
37342
|
async function withPdfDocument(pdfDataUrl, fn) {
|
|
37343
|
+
assertFileUrlAllowed(pdfDataUrl);
|
|
37289
37344
|
const pdfjs = await getPdfjs();
|
|
37290
37345
|
const loadingTask = pdfjs.getDocument(pdfDataUrl);
|
|
37291
37346
|
let pdf;
|
|
@@ -38074,6 +38129,7 @@ async function preprocessFiles(files, options = {}) {
|
|
|
38074
38129
|
skip("no_data");
|
|
38075
38130
|
continue;
|
|
38076
38131
|
}
|
|
38132
|
+
assertFileUrlAllowed(file.url);
|
|
38077
38133
|
const fileWithData = {
|
|
38078
38134
|
...file,
|
|
38079
38135
|
dataUrl: file.url
|
|
@@ -643,7 +643,7 @@ var mergeHeaders = (...headers) => {
|
|
|
643
643
|
if (!header || typeof header !== "object") {
|
|
644
644
|
continue;
|
|
645
645
|
}
|
|
646
|
-
const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
|
|
646
|
+
const iterator = Array.isArray(header) || header instanceof Headers ? headersEntries(new Headers(header)) : Object.entries(header);
|
|
647
647
|
for (const [key, value] of iterator) {
|
|
648
648
|
if (value === null) {
|
|
649
649
|
mergedHeaders.delete(key);
|
|
@@ -919,13 +919,25 @@ var createClient = (config = {}) => {
|
|
|
919
919
|
init_clientConfig();
|
|
920
920
|
var client = createClient(createClientConfig(createConfig()));
|
|
921
921
|
|
|
922
|
+
// src/clientHeaders.ts
|
|
923
|
+
function normalizeHeaders(headers) {
|
|
924
|
+
if (headers instanceof Headers || Array.isArray(headers)) {
|
|
925
|
+
const normalized = /* @__PURE__ */ Object.create(null);
|
|
926
|
+
new Headers(headers).forEach((value, name) => {
|
|
927
|
+
normalized[name] = value;
|
|
928
|
+
});
|
|
929
|
+
return normalized;
|
|
930
|
+
}
|
|
931
|
+
return headers;
|
|
932
|
+
}
|
|
933
|
+
|
|
922
934
|
// src/client/sdk.gen.ts
|
|
923
935
|
var postApiV1Embeddings = (options) => (options.client ?? client).post({
|
|
924
936
|
url: "/api/v1/embeddings",
|
|
925
937
|
...options,
|
|
926
938
|
headers: {
|
|
927
939
|
"Content-Type": "application/json",
|
|
928
|
-
...options.headers
|
|
940
|
+
...normalizeHeaders(options.headers)
|
|
929
941
|
}
|
|
930
942
|
});
|
|
931
943
|
|
|
@@ -525,7 +525,7 @@ var mergeHeaders = (...headers) => {
|
|
|
525
525
|
if (!header || typeof header !== "object") {
|
|
526
526
|
continue;
|
|
527
527
|
}
|
|
528
|
-
const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
|
|
528
|
+
const iterator = Array.isArray(header) || header instanceof Headers ? headersEntries(new Headers(header)) : Object.entries(header);
|
|
529
529
|
for (const [key, value] of iterator) {
|
|
530
530
|
if (value === null) {
|
|
531
531
|
mergedHeaders.delete(key);
|
|
@@ -800,13 +800,25 @@ var createClient = (config = {}) => {
|
|
|
800
800
|
// src/client/client.gen.ts
|
|
801
801
|
var client = createClient(createClientConfig(createConfig()));
|
|
802
802
|
|
|
803
|
+
// src/clientHeaders.ts
|
|
804
|
+
function normalizeHeaders(headers) {
|
|
805
|
+
if (headers instanceof Headers || Array.isArray(headers)) {
|
|
806
|
+
const normalized = /* @__PURE__ */ Object.create(null);
|
|
807
|
+
new Headers(headers).forEach((value, name) => {
|
|
808
|
+
normalized[name] = value;
|
|
809
|
+
});
|
|
810
|
+
return normalized;
|
|
811
|
+
}
|
|
812
|
+
return headers;
|
|
813
|
+
}
|
|
814
|
+
|
|
803
815
|
// src/client/sdk.gen.ts
|
|
804
816
|
var postApiV1Embeddings = (options) => (options.client ?? client).post({
|
|
805
817
|
url: "/api/v1/embeddings",
|
|
806
818
|
...options,
|
|
807
819
|
headers: {
|
|
808
820
|
"Content-Type": "application/json",
|
|
809
|
-
...options.headers
|
|
821
|
+
...normalizeHeaders(options.headers)
|
|
810
822
|
}
|
|
811
823
|
});
|
|
812
824
|
|