@anuma/sdk 9.1.5 → 9.1.7
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/{chunk-XW3LYSDA.mjs → chunk-WRZTH4OS.mjs} +38 -13
- package/dist/expo/{consolidate-4CQJYKRK.mjs → consolidate-HKL5EGZT.mjs} +1 -1
- package/dist/expo/index.cjs +84 -31
- package/dist/expo/index.d.mts +9 -5
- package/dist/expo/index.d.ts +9 -5
- package/dist/expo/index.mjs +47 -19
- package/dist/index.cjs +47 -35
- package/dist/index.mjs +47 -35
- package/dist/react/{chunk-7QX4J7KV.mjs → chunk-RSA3S6OA.mjs} +38 -13
- package/dist/react/{consolidate-WLDYJF6J.mjs → consolidate-WFTPBHDV.mjs} +1 -1
- package/dist/react/index.cjs +109 -46
- package/dist/react/index.d.mts +9 -5
- package/dist/react/index.d.ts +9 -5
- package/dist/react/index.mjs +77 -39
- package/dist/server/{chunk-AU3Z7NBC.mjs → chunk-QEROZ4VH.mjs} +38 -13
- package/dist/server/{consolidate-B6OSCZU4.mjs → consolidate-PYED62LW.mjs} +1 -1
- package/dist/server/index.cjs +89 -27
- package/dist/server/index.d.mts +9 -5
- package/dist/server/index.d.ts +9 -5
- package/dist/server/index.mjs +52 -15
- package/dist/tools/selection/index.cjs +14 -2
- package/dist/tools/selection/index.mjs +14 -2
- package/package.json +1 -1
package/dist/server/index.cjs
CHANGED
|
@@ -15742,7 +15742,8 @@ async function callPortalJsonCompletion(req) {
|
|
|
15742
15742
|
}
|
|
15743
15743
|
const maxAttempts = Math.max(1, req.maxAttempts ?? 3);
|
|
15744
15744
|
const startedAt = Date.now();
|
|
15745
|
-
const
|
|
15745
|
+
const deadlineAt = req.totalTimeoutMs === void 0 ? void 0 : startedAt + req.totalTimeoutMs;
|
|
15746
|
+
const overBudget = () => deadlineAt !== void 0 && Date.now() >= deadlineAt;
|
|
15746
15747
|
let lastFailure;
|
|
15747
15748
|
let reinforce = false;
|
|
15748
15749
|
const giveUp = () => {
|
|
@@ -15755,17 +15756,11 @@ async function callPortalJsonCompletion(req) {
|
|
|
15755
15756
|
lastFailure = { reason: "time-budget-exhausted", attempts: attempt - 1 };
|
|
15756
15757
|
break;
|
|
15757
15758
|
}
|
|
15758
|
-
const attemptReq = req
|
|
15759
|
-
...req,
|
|
15760
|
-
timeoutMs: Math.max(
|
|
15761
|
-
1,
|
|
15762
|
-
Math.min(req.timeoutMs ?? 6e4, req.totalTimeoutMs - (Date.now() - startedAt))
|
|
15763
|
-
),
|
|
15764
|
-
...reinforce && { reinforceJsonContract: true }
|
|
15765
|
-
} : reinforce ? { ...req, reinforceJsonContract: true } : req;
|
|
15759
|
+
const attemptReq = reinforce ? { ...req, reinforceJsonContract: true } : req;
|
|
15766
15760
|
const outcome = await attemptPortalJson(
|
|
15767
15761
|
{ ...attemptReq, transport },
|
|
15768
|
-
endpoint
|
|
15762
|
+
endpoint,
|
|
15763
|
+
deadlineAt
|
|
15769
15764
|
);
|
|
15770
15765
|
if (outcome.kind === "ok") {
|
|
15771
15766
|
req.onAttempt?.({ attempt, ok: true });
|
|
@@ -15805,13 +15800,38 @@ async function callPortalJsonCompletion(req) {
|
|
|
15805
15800
|
}
|
|
15806
15801
|
return giveUp();
|
|
15807
15802
|
}
|
|
15808
|
-
async function attemptPortalJson(req, endpoint) {
|
|
15803
|
+
async function attemptPortalJson(req, endpoint, deadlineAt) {
|
|
15804
|
+
const controller = new AbortController();
|
|
15805
|
+
if (deadlineAt === void 0 || deadlineAt - Date.now() > MAX_TIMER_DELAY_MS) {
|
|
15806
|
+
return requestPortalJson(req, endpoint, controller);
|
|
15807
|
+
}
|
|
15808
|
+
const remainingMs = deadlineAt - Date.now();
|
|
15809
|
+
if (remainingMs <= 0) return TIME_BUDGET_EXHAUSTED;
|
|
15810
|
+
let timer;
|
|
15811
|
+
try {
|
|
15812
|
+
const outcome = await Promise.race([
|
|
15813
|
+
new Promise((resolve) => {
|
|
15814
|
+
timer = setTimeout(() => {
|
|
15815
|
+
resolve(TIME_BUDGET_EXHAUSTED);
|
|
15816
|
+
controller.abort();
|
|
15817
|
+
}, remainingMs);
|
|
15818
|
+
}),
|
|
15819
|
+
requestPortalJson(req, endpoint, controller, deadlineAt)
|
|
15820
|
+
]);
|
|
15821
|
+
return Date.now() >= deadlineAt ? TIME_BUDGET_EXHAUSTED : outcome;
|
|
15822
|
+
} finally {
|
|
15823
|
+
clearTimeout(timer);
|
|
15824
|
+
}
|
|
15825
|
+
}
|
|
15826
|
+
async function requestPortalJson(req, endpoint, controller, deadlineAt) {
|
|
15809
15827
|
const baseUrl = req.baseUrl ?? defaultBaseUrl();
|
|
15810
15828
|
const fetchImpl = req.fetchFn ?? fetch;
|
|
15811
|
-
const timeoutMs = req.timeoutMs ?? 6e4;
|
|
15812
15829
|
const authHeaders = await resolvePortalAuthHeaders(req, req.tag);
|
|
15830
|
+
const remainingMs = deadlineAt === void 0 ? Infinity : deadlineAt - Date.now();
|
|
15831
|
+
if (controller.signal.aborted || remainingMs <= 0) return TIME_BUDGET_EXHAUSTED;
|
|
15813
15832
|
if (authHeaders === null)
|
|
15814
15833
|
return { kind: "terminal", code: "auth-unavailable", reason: "auth unavailable (no token)" };
|
|
15834
|
+
const timeoutMs = Math.min(req.timeoutMs ?? 6e4, remainingMs);
|
|
15815
15835
|
const usesPrefill = req.transport !== "responses" && req.model.startsWith("anthropic/");
|
|
15816
15836
|
const prefill = usesPrefill ? "{" : "";
|
|
15817
15837
|
const messages = [
|
|
@@ -15821,7 +15841,6 @@ async function attemptPortalJson(req, endpoint) {
|
|
|
15821
15841
|
];
|
|
15822
15842
|
if (prefill) messages.push({ role: "assistant", content: prefill });
|
|
15823
15843
|
const supportsJsonObjectFormat = supportsResponseFormat(req.model);
|
|
15824
|
-
const controller = new AbortController();
|
|
15825
15844
|
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
15826
15845
|
const requestBody = req.transport === "responses" ? {
|
|
15827
15846
|
model: req.model,
|
|
@@ -16006,7 +16025,7 @@ function extractResponsesContent(body) {
|
|
|
16006
16025
|
const text12 = root.output.filter((item) => asRecord(item)?.type === "message").flatMap((item) => Array.isArray(item.content) ? item.content : []).map((part) => asRecord(part)?.text).filter((t) => typeof t === "string").join("");
|
|
16007
16026
|
return text12;
|
|
16008
16027
|
}
|
|
16009
|
-
var RESPONSE_FORMAT_OK, RESPONSE_SCHEMA_OK, JSON_CONTRACT_REMINDER, RESPONSES_ONLY_MODEL_PREFIXES, CHAT_TO_RESPONSES_FIELDS, FOREIGN_ENDPOINT_SUFFIX, RETRYABLE_HTTP;
|
|
16028
|
+
var RESPONSE_FORMAT_OK, RESPONSE_SCHEMA_OK, JSON_CONTRACT_REMINDER, RESPONSES_ONLY_MODEL_PREFIXES, CHAT_TO_RESPONSES_FIELDS, FOREIGN_ENDPOINT_SUFFIX, TIME_BUDGET_EXHAUSTED, MAX_TIMER_DELAY_MS, RETRYABLE_HTTP;
|
|
16010
16029
|
var init_portalLlm = __esm({
|
|
16011
16030
|
"src/lib/memory/portalLlm.ts"() {
|
|
16012
16031
|
"use strict";
|
|
@@ -16026,6 +16045,12 @@ var init_portalLlm = __esm({
|
|
|
16026
16045
|
chat: "/responses",
|
|
16027
16046
|
responses: "/chat/completions"
|
|
16028
16047
|
};
|
|
16048
|
+
TIME_BUDGET_EXHAUSTED = {
|
|
16049
|
+
kind: "terminal",
|
|
16050
|
+
code: "time-budget-exhausted",
|
|
16051
|
+
reason: "time budget exhausted"
|
|
16052
|
+
};
|
|
16053
|
+
MAX_TIMER_DELAY_MS = 2147483647;
|
|
16029
16054
|
RETRYABLE_HTTP = /* @__PURE__ */ new Set([408, 409, 425, 429]);
|
|
16030
16055
|
}
|
|
16031
16056
|
});
|
|
@@ -17661,7 +17686,14 @@ function cosineSimilarity(a, b) {
|
|
|
17661
17686
|
|
|
17662
17687
|
// src/lib/processors/encoding.ts
|
|
17663
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
|
+
}
|
|
17664
17695
|
async function dataUrlToArrayBuffer(dataUrl) {
|
|
17696
|
+
assertFileUrlAllowed(dataUrl);
|
|
17665
17697
|
if (dataUrl.startsWith("blob:") || dataUrl.startsWith("http://") || dataUrl.startsWith("https://")) {
|
|
17666
17698
|
const response = await fetch(dataUrl);
|
|
17667
17699
|
return response.arrayBuffer();
|
|
@@ -19991,7 +20023,7 @@ var mergeHeaders = (...headers) => {
|
|
|
19991
20023
|
if (!header || typeof header !== "object") {
|
|
19992
20024
|
continue;
|
|
19993
20025
|
}
|
|
19994
|
-
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);
|
|
19995
20027
|
for (const [key, value] of iterator) {
|
|
19996
20028
|
if (value === null) {
|
|
19997
20029
|
mergedHeaders.delete(key);
|
|
@@ -20267,13 +20299,25 @@ var createClient = (config = {}) => {
|
|
|
20267
20299
|
init_clientConfig();
|
|
20268
20300
|
var client = createClient(createClientConfig(createConfig()));
|
|
20269
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
|
+
|
|
20270
20314
|
// src/client/sdk.gen.ts
|
|
20271
20315
|
var postApiV1Embeddings = (options) => (options.client ?? client).post({
|
|
20272
20316
|
url: "/api/v1/embeddings",
|
|
20273
20317
|
...options,
|
|
20274
20318
|
headers: {
|
|
20275
20319
|
"Content-Type": "application/json",
|
|
20276
|
-
...options.headers
|
|
20320
|
+
...normalizeHeaders(options.headers)
|
|
20277
20321
|
}
|
|
20278
20322
|
});
|
|
20279
20323
|
|
|
@@ -29072,6 +29116,16 @@ async function updateVaultMemoryOp(ctx, id, opts) {
|
|
|
29072
29116
|
const probe = await ctx.vaultMemoryCollection.find(id);
|
|
29073
29117
|
if (probe.isDeleted || probe.supersededBy || !isOwnedByCtxUser(ctx, probe)) return null;
|
|
29074
29118
|
if (opts.freeFormOnly && isKinded(probe)) return null;
|
|
29119
|
+
const readStoredContent = probe._getRaw("content");
|
|
29120
|
+
if (opts.expectedContent !== void 0) {
|
|
29121
|
+
const current = await vaultMemoryToStored(
|
|
29122
|
+
probe,
|
|
29123
|
+
ctx.walletAddress,
|
|
29124
|
+
ctx.signMessage,
|
|
29125
|
+
ctx.embeddedWalletSigner
|
|
29126
|
+
);
|
|
29127
|
+
if (current.content !== opts.expectedContent) return null;
|
|
29128
|
+
}
|
|
29075
29129
|
const levelAfter = (current) => {
|
|
29076
29130
|
if (opts.level !== void 0) return opts.level;
|
|
29077
29131
|
if (opts.scope === void 0) return resolveMemoryLevel(current.level, current.scope);
|
|
@@ -29079,7 +29133,7 @@ async function updateVaultMemoryOp(ctx, id, opts) {
|
|
|
29079
29133
|
};
|
|
29080
29134
|
assertValidKindLevel(opts.kind !== void 0 ? opts.kind : probe.kind, levelAfter(probe));
|
|
29081
29135
|
const encryptedKindValue = await encryptKindValue(ctx, opts.kindValue);
|
|
29082
|
-
const encryptedContent = ctx.walletAddress && ctx.signMessage ? await encryptVaultMemoryContent(
|
|
29136
|
+
const encryptedContent = opts.content !== void 0 && ctx.walletAddress && ctx.signMessage ? await encryptVaultMemoryContent(
|
|
29083
29137
|
opts.content,
|
|
29084
29138
|
ctx.walletAddress,
|
|
29085
29139
|
ctx.signMessage,
|
|
@@ -29087,13 +29141,13 @@ async function updateVaultMemoryOp(ctx, id, opts) {
|
|
|
29087
29141
|
) : opts.content;
|
|
29088
29142
|
let stale = false;
|
|
29089
29143
|
const record = probe;
|
|
29090
|
-
const originalUpdatedAt = record.updatedAt.getTime();
|
|
29091
29144
|
await ctx.database.write(async () => {
|
|
29092
29145
|
await assertCanWrite2(ctx);
|
|
29093
|
-
if (record.isDeleted || record.supersededBy || !isOwnedByCtxUser(ctx, record) || opts.freeFormOnly && isKinded(record)) {
|
|
29146
|
+
if (record.isDeleted || record.supersededBy || !isOwnedByCtxUser(ctx, record) || opts.freeFormOnly && isKinded(record) || opts.expectedContent !== void 0 && record._getRaw("content") !== readStoredContent) {
|
|
29094
29147
|
stale = true;
|
|
29095
29148
|
return;
|
|
29096
29149
|
}
|
|
29150
|
+
const originalUpdatedAt = record.updatedAt.getTime();
|
|
29097
29151
|
const nextKind = opts.kind !== void 0 ? opts.kind : record.kind;
|
|
29098
29152
|
const nextLevel = levelAfter(record);
|
|
29099
29153
|
assertValidKindLevel(nextKind, nextLevel);
|
|
@@ -29109,7 +29163,7 @@ async function updateVaultMemoryOp(ctx, id, opts) {
|
|
|
29109
29163
|
replayedObservation = opts.observationSourceIds.every((id2) => observedSources.includes(id2));
|
|
29110
29164
|
}
|
|
29111
29165
|
await record.update((r) => {
|
|
29112
|
-
r._setRaw("content", encryptedContent);
|
|
29166
|
+
if (encryptedContent !== void 0) r._setRaw("content", encryptedContent);
|
|
29113
29167
|
if (opts.level !== void 0) {
|
|
29114
29168
|
r._setRaw("level", nextLevel);
|
|
29115
29169
|
r._setRaw("scope", scopeForLevel(nextLevel));
|
|
@@ -29877,7 +29931,7 @@ function classifyDecay(m, now, policy) {
|
|
|
29877
29931
|
if (m.source === "manual" || m.source === SOURCE_PHOTO) return "keep";
|
|
29878
29932
|
if (isTimeSensitiveType(m.factType) && m.eventTimeEnd !== null) {
|
|
29879
29933
|
if (m.eventTimeEnd < now - resolved.pastEventGraceMs) return "archive";
|
|
29880
|
-
|
|
29934
|
+
return "keep";
|
|
29881
29935
|
}
|
|
29882
29936
|
if (now - lastActivityAt(m) > ttlForType(m.factType, resolved)) return "archive";
|
|
29883
29937
|
return "keep";
|
|
@@ -33098,7 +33152,6 @@ async function retainWithPersistence(content, ctx, options = {}) {
|
|
|
33098
33152
|
const factTypeUpdate = pickFactTypeUpdate(existing, options.factType);
|
|
33099
33153
|
const resurrect = resurrectFields(existing);
|
|
33100
33154
|
const updated = await ctx.persistence.update(targetId, {
|
|
33101
|
-
content: existing.content,
|
|
33102
33155
|
freeFormOnly: true,
|
|
33103
33156
|
proofCountIncrement: 1,
|
|
33104
33157
|
observationSourceIds: options.sourceChunkIds,
|
|
@@ -33337,7 +33390,6 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
|
|
|
33337
33390
|
const factTypeUpdate = pickFactTypeUpdate(existing, options.factType);
|
|
33338
33391
|
const resurrect = resurrectFields(existing);
|
|
33339
33392
|
const updated = await ctx.persistence.update(decision.targetId, {
|
|
33340
|
-
content: existing.content,
|
|
33341
33393
|
freeFormOnly: true,
|
|
33342
33394
|
proofCountIncrement: 1,
|
|
33343
33395
|
observationSourceIds: options.sourceChunkIds,
|
|
@@ -33365,6 +33417,10 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
|
|
|
33365
33417
|
};
|
|
33366
33418
|
}
|
|
33367
33419
|
if (decision.action === "update" && decision.targetId && decision.content) {
|
|
33420
|
+
const expectedContent = candidates.find(
|
|
33421
|
+
(candidate) => candidate.id === decision.targetId
|
|
33422
|
+
)?.content;
|
|
33423
|
+
if (expectedContent === void 0) return null;
|
|
33368
33424
|
const existing = await ctx.persistence.get(decision.targetId);
|
|
33369
33425
|
if (!existing || existing.supersededBy) {
|
|
33370
33426
|
return abandonToRace(
|
|
@@ -33372,6 +33428,9 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
|
|
|
33372
33428
|
`update: target ${decision.targetId} ${existing ? "superseded" : "deleted"} before the write`
|
|
33373
33429
|
);
|
|
33374
33430
|
}
|
|
33431
|
+
if (existing.content !== expectedContent) {
|
|
33432
|
+
return abandonToRace(options, `update: target ${decision.targetId} edited before the write`);
|
|
33433
|
+
}
|
|
33375
33434
|
const mergedSourceIds = unionStrings(
|
|
33376
33435
|
existing.sourceChunkIds ?? [],
|
|
33377
33436
|
options.sourceChunkIds ?? []
|
|
@@ -33384,6 +33443,7 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
|
|
|
33384
33443
|
const resurrect = resurrectFields(existing);
|
|
33385
33444
|
const updated = await ctx.persistence.update(decision.targetId, {
|
|
33386
33445
|
content: decision.content,
|
|
33446
|
+
expectedContent,
|
|
33387
33447
|
freeFormOnly: true,
|
|
33388
33448
|
proofCountIncrement: 1,
|
|
33389
33449
|
observationSourceIds: options.sourceChunkIds,
|
|
@@ -33396,10 +33456,10 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
|
|
|
33396
33456
|
...factTypeUpdate !== void 0 && { factType: factTypeUpdate }
|
|
33397
33457
|
});
|
|
33398
33458
|
if (!updated) {
|
|
33399
|
-
await assertMergeTargetGoneOrThrow(ctx, decision.targetId);
|
|
33459
|
+
await assertMergeTargetGoneOrThrow(ctx, decision.targetId, expectedContent);
|
|
33400
33460
|
return abandonToRace(
|
|
33401
33461
|
options,
|
|
33402
|
-
`update: target ${decision.targetId}
|
|
33462
|
+
`update: target ${decision.targetId} changed mid-write (consolidated rewrite lost)`
|
|
33403
33463
|
);
|
|
33404
33464
|
}
|
|
33405
33465
|
cacheRowVector(
|
|
@@ -33426,9 +33486,9 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
|
|
|
33426
33486
|
);
|
|
33427
33487
|
return null;
|
|
33428
33488
|
}
|
|
33429
|
-
async function assertMergeTargetGoneOrThrow(ctx, targetId) {
|
|
33489
|
+
async function assertMergeTargetGoneOrThrow(ctx, targetId, expectedContent) {
|
|
33430
33490
|
const stillExists = await (ctx.persistence.getFresh ? ctx.persistence.getFresh(targetId) : ctx.persistence.get(targetId));
|
|
33431
|
-
if (stillExists && (stillExists.kind === null || stillExists.kind === void 0)) {
|
|
33491
|
+
if (stillExists && (stillExists.kind === null || stillExists.kind === void 0) && (expectedContent === void 0 || stillExists.content === expectedContent)) {
|
|
33432
33492
|
throw new RetainError(
|
|
33433
33493
|
"merge-not-persisted",
|
|
33434
33494
|
`retain: merge into memory ${targetId} failed to persist`
|
|
@@ -39030,6 +39090,7 @@ async function getPdfjs() {
|
|
|
39030
39090
|
return pdfjsModule;
|
|
39031
39091
|
}
|
|
39032
39092
|
async function withPdfDocument(pdfDataUrl, fn) {
|
|
39093
|
+
assertFileUrlAllowed(pdfDataUrl);
|
|
39033
39094
|
const pdfjs = await getPdfjs();
|
|
39034
39095
|
const loadingTask = pdfjs.getDocument(pdfDataUrl);
|
|
39035
39096
|
let pdf;
|
|
@@ -39824,6 +39885,7 @@ async function preprocessFiles(files, options = {}) {
|
|
|
39824
39885
|
skip("no_data");
|
|
39825
39886
|
continue;
|
|
39826
39887
|
}
|
|
39888
|
+
assertFileUrlAllowed(file.url);
|
|
39827
39889
|
const fileWithData = {
|
|
39828
39890
|
...file,
|
|
39829
39891
|
dataUrl: file.url
|
package/dist/server/index.d.mts
CHANGED
|
@@ -5287,7 +5287,8 @@ interface CreateVaultMemoryOptions {
|
|
|
5287
5287
|
geohash?: string;
|
|
5288
5288
|
}
|
|
5289
5289
|
interface UpdateVaultMemoryOptions {
|
|
5290
|
-
content
|
|
5290
|
+
content?: string;
|
|
5291
|
+
expectedContent?: string;
|
|
5291
5292
|
/** When true, the write is skipped (returns null) if the row carries a profile kind. */
|
|
5292
5293
|
freeFormOnly?: boolean;
|
|
5293
5294
|
/**
|
|
@@ -5849,9 +5850,10 @@ declare function ttlForType(factType: string | null, policy?: Partial<DecayPolic
|
|
|
5849
5850
|
* null `eventTimeEnd` is still ongoing, so this rule does not fire for it.
|
|
5850
5851
|
* 4. Age fallback — `now - updatedAt > TTL(factType)` → archive. Durable types
|
|
5851
5852
|
* have Infinity TTL, so this never fires for them; null/unknown use medium.
|
|
5852
|
-
* EXCEPTION: a `plan
|
|
5853
|
-
* (`eventTimeEnd >= now
|
|
5854
|
-
*
|
|
5853
|
+
* EXCEPTION: a `plan` / `ongoing_context` with an upcoming event or an event
|
|
5854
|
+
* within the grace period (`eventTimeEnd >= now - pastEventGraceMs`) stays
|
|
5855
|
+
* active, even after its activity TTL expires. Rule 3 archives it after the
|
|
5856
|
+
* grace period ends.
|
|
5855
5857
|
* 5. Otherwise → keep.
|
|
5856
5858
|
*
|
|
5857
5859
|
* @param m Plaintext decay inputs for one row.
|
|
@@ -6182,7 +6184,9 @@ type MemoryCreate = Pick<CreateVaultMemoryOptions, "content" | "scope" | "factTy
|
|
|
6182
6184
|
* `embedding` (with `embeddingModel`) only when you already have the new one.
|
|
6183
6185
|
* @public
|
|
6184
6186
|
*/
|
|
6185
|
-
type MemoryUpdate = Pick<UpdateVaultMemoryOptions, "
|
|
6187
|
+
type MemoryUpdate = Pick<UpdateVaultMemoryOptions, "scope" | "factType" | "eventTime" | "embedding" | "embeddingModel" | "kind" | "kindValue" | "level"> & {
|
|
6188
|
+
content: string;
|
|
6189
|
+
};
|
|
6186
6190
|
/**
|
|
6187
6191
|
* Fact-only recall. Conversation chunks are message storage, not memory, so
|
|
6188
6192
|
* the chunk-lane knobs are not part of this surface; nor is `folderId` (see
|
package/dist/server/index.d.ts
CHANGED
|
@@ -5287,7 +5287,8 @@ interface CreateVaultMemoryOptions {
|
|
|
5287
5287
|
geohash?: string;
|
|
5288
5288
|
}
|
|
5289
5289
|
interface UpdateVaultMemoryOptions {
|
|
5290
|
-
content
|
|
5290
|
+
content?: string;
|
|
5291
|
+
expectedContent?: string;
|
|
5291
5292
|
/** When true, the write is skipped (returns null) if the row carries a profile kind. */
|
|
5292
5293
|
freeFormOnly?: boolean;
|
|
5293
5294
|
/**
|
|
@@ -5849,9 +5850,10 @@ declare function ttlForType(factType: string | null, policy?: Partial<DecayPolic
|
|
|
5849
5850
|
* null `eventTimeEnd` is still ongoing, so this rule does not fire for it.
|
|
5850
5851
|
* 4. Age fallback — `now - updatedAt > TTL(factType)` → archive. Durable types
|
|
5851
5852
|
* have Infinity TTL, so this never fires for them; null/unknown use medium.
|
|
5852
|
-
* EXCEPTION: a `plan
|
|
5853
|
-
* (`eventTimeEnd >= now
|
|
5854
|
-
*
|
|
5853
|
+
* EXCEPTION: a `plan` / `ongoing_context` with an upcoming event or an event
|
|
5854
|
+
* within the grace period (`eventTimeEnd >= now - pastEventGraceMs`) stays
|
|
5855
|
+
* active, even after its activity TTL expires. Rule 3 archives it after the
|
|
5856
|
+
* grace period ends.
|
|
5855
5857
|
* 5. Otherwise → keep.
|
|
5856
5858
|
*
|
|
5857
5859
|
* @param m Plaintext decay inputs for one row.
|
|
@@ -6182,7 +6184,9 @@ type MemoryCreate = Pick<CreateVaultMemoryOptions, "content" | "scope" | "factTy
|
|
|
6182
6184
|
* `embedding` (with `embeddingModel`) only when you already have the new one.
|
|
6183
6185
|
* @public
|
|
6184
6186
|
*/
|
|
6185
|
-
type MemoryUpdate = Pick<UpdateVaultMemoryOptions, "
|
|
6187
|
+
type MemoryUpdate = Pick<UpdateVaultMemoryOptions, "scope" | "factType" | "eventTime" | "embedding" | "embeddingModel" | "kind" | "kindValue" | "level"> & {
|
|
6188
|
+
content: string;
|
|
6189
|
+
};
|
|
6186
6190
|
/**
|
|
6187
6191
|
* Fact-only recall. Conversation chunks are message storage, not memory, so
|
|
6188
6192
|
* the chunk-lane knobs are not part of this surface; nor is `folderId` (see
|
package/dist/server/index.mjs
CHANGED
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
taskTypeHeader,
|
|
14
14
|
validateEndpointOverride,
|
|
15
15
|
withInternalFlowMarker
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-QEROZ4VH.mjs";
|
|
17
17
|
import {
|
|
18
18
|
BASE_URL,
|
|
19
19
|
__commonJS,
|
|
@@ -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
|
|
|
@@ -27363,6 +27382,16 @@ async function updateVaultMemoryOp(ctx, id, opts) {
|
|
|
27363
27382
|
const probe = await ctx.vaultMemoryCollection.find(id);
|
|
27364
27383
|
if (probe.isDeleted || probe.supersededBy || !isOwnedByCtxUser(ctx, probe)) return null;
|
|
27365
27384
|
if (opts.freeFormOnly && isKinded(probe)) return null;
|
|
27385
|
+
const readStoredContent = probe._getRaw("content");
|
|
27386
|
+
if (opts.expectedContent !== void 0) {
|
|
27387
|
+
const current = await vaultMemoryToStored(
|
|
27388
|
+
probe,
|
|
27389
|
+
ctx.walletAddress,
|
|
27390
|
+
ctx.signMessage,
|
|
27391
|
+
ctx.embeddedWalletSigner
|
|
27392
|
+
);
|
|
27393
|
+
if (current.content !== opts.expectedContent) return null;
|
|
27394
|
+
}
|
|
27366
27395
|
const levelAfter = (current) => {
|
|
27367
27396
|
if (opts.level !== void 0) return opts.level;
|
|
27368
27397
|
if (opts.scope === void 0) return resolveMemoryLevel(current.level, current.scope);
|
|
@@ -27370,7 +27399,7 @@ async function updateVaultMemoryOp(ctx, id, opts) {
|
|
|
27370
27399
|
};
|
|
27371
27400
|
assertValidKindLevel(opts.kind !== void 0 ? opts.kind : probe.kind, levelAfter(probe));
|
|
27372
27401
|
const encryptedKindValue = await encryptKindValue(ctx, opts.kindValue);
|
|
27373
|
-
const encryptedContent = ctx.walletAddress && ctx.signMessage ? await encryptVaultMemoryContent(
|
|
27402
|
+
const encryptedContent = opts.content !== void 0 && ctx.walletAddress && ctx.signMessage ? await encryptVaultMemoryContent(
|
|
27374
27403
|
opts.content,
|
|
27375
27404
|
ctx.walletAddress,
|
|
27376
27405
|
ctx.signMessage,
|
|
@@ -27378,13 +27407,13 @@ async function updateVaultMemoryOp(ctx, id, opts) {
|
|
|
27378
27407
|
) : opts.content;
|
|
27379
27408
|
let stale = false;
|
|
27380
27409
|
const record = probe;
|
|
27381
|
-
const originalUpdatedAt = record.updatedAt.getTime();
|
|
27382
27410
|
await ctx.database.write(async () => {
|
|
27383
27411
|
await assertCanWrite2(ctx);
|
|
27384
|
-
if (record.isDeleted || record.supersededBy || !isOwnedByCtxUser(ctx, record) || opts.freeFormOnly && isKinded(record)) {
|
|
27412
|
+
if (record.isDeleted || record.supersededBy || !isOwnedByCtxUser(ctx, record) || opts.freeFormOnly && isKinded(record) || opts.expectedContent !== void 0 && record._getRaw("content") !== readStoredContent) {
|
|
27385
27413
|
stale = true;
|
|
27386
27414
|
return;
|
|
27387
27415
|
}
|
|
27416
|
+
const originalUpdatedAt = record.updatedAt.getTime();
|
|
27388
27417
|
const nextKind = opts.kind !== void 0 ? opts.kind : record.kind;
|
|
27389
27418
|
const nextLevel = levelAfter(record);
|
|
27390
27419
|
assertValidKindLevel(nextKind, nextLevel);
|
|
@@ -27400,7 +27429,7 @@ async function updateVaultMemoryOp(ctx, id, opts) {
|
|
|
27400
27429
|
replayedObservation = opts.observationSourceIds.every((id2) => observedSources.includes(id2));
|
|
27401
27430
|
}
|
|
27402
27431
|
await record.update((r) => {
|
|
27403
|
-
r._setRaw("content", encryptedContent);
|
|
27432
|
+
if (encryptedContent !== void 0) r._setRaw("content", encryptedContent);
|
|
27404
27433
|
if (opts.level !== void 0) {
|
|
27405
27434
|
r._setRaw("level", nextLevel);
|
|
27406
27435
|
r._setRaw("scope", scopeForLevel(nextLevel));
|
|
@@ -28167,7 +28196,7 @@ function classifyDecay(m, now, policy) {
|
|
|
28167
28196
|
if (m.source === "manual" || m.source === SOURCE_PHOTO) return "keep";
|
|
28168
28197
|
if (isTimeSensitiveType(m.factType) && m.eventTimeEnd !== null) {
|
|
28169
28198
|
if (m.eventTimeEnd < now - resolved.pastEventGraceMs) return "archive";
|
|
28170
|
-
|
|
28199
|
+
return "keep";
|
|
28171
28200
|
}
|
|
28172
28201
|
if (now - lastActivityAt(m) > ttlForType(m.factType, resolved)) return "archive";
|
|
28173
28202
|
return "keep";
|
|
@@ -31368,7 +31397,6 @@ async function retainWithPersistence(content, ctx, options = {}) {
|
|
|
31368
31397
|
const factTypeUpdate = pickFactTypeUpdate(existing, options.factType);
|
|
31369
31398
|
const resurrect = resurrectFields(existing);
|
|
31370
31399
|
const updated = await ctx.persistence.update(targetId, {
|
|
31371
|
-
content: existing.content,
|
|
31372
31400
|
freeFormOnly: true,
|
|
31373
31401
|
proofCountIncrement: 1,
|
|
31374
31402
|
observationSourceIds: options.sourceChunkIds,
|
|
@@ -31572,7 +31600,7 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
|
|
|
31572
31600
|
content: m.content,
|
|
31573
31601
|
similarity: m.similarity
|
|
31574
31602
|
}));
|
|
31575
|
-
const { consolidateMemory: doConsolidate } = await import("./consolidate-
|
|
31603
|
+
const { consolidateMemory: doConsolidate } = await import("./consolidate-PYED62LW.mjs");
|
|
31576
31604
|
const decision = await doConsolidate(trimmed, candidates, consolidateOptions);
|
|
31577
31605
|
if (decision.action === "create") return decision.fallbackReason ? null : { create: true };
|
|
31578
31606
|
if (decision.action === "supersede" && decision.content) {
|
|
@@ -31607,7 +31635,6 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
|
|
|
31607
31635
|
const factTypeUpdate = pickFactTypeUpdate(existing, options.factType);
|
|
31608
31636
|
const resurrect = resurrectFields(existing);
|
|
31609
31637
|
const updated = await ctx.persistence.update(decision.targetId, {
|
|
31610
|
-
content: existing.content,
|
|
31611
31638
|
freeFormOnly: true,
|
|
31612
31639
|
proofCountIncrement: 1,
|
|
31613
31640
|
observationSourceIds: options.sourceChunkIds,
|
|
@@ -31635,6 +31662,10 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
|
|
|
31635
31662
|
};
|
|
31636
31663
|
}
|
|
31637
31664
|
if (decision.action === "update" && decision.targetId && decision.content) {
|
|
31665
|
+
const expectedContent = candidates.find(
|
|
31666
|
+
(candidate) => candidate.id === decision.targetId
|
|
31667
|
+
)?.content;
|
|
31668
|
+
if (expectedContent === void 0) return null;
|
|
31638
31669
|
const existing = await ctx.persistence.get(decision.targetId);
|
|
31639
31670
|
if (!existing || existing.supersededBy) {
|
|
31640
31671
|
return abandonToRace(
|
|
@@ -31642,6 +31673,9 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
|
|
|
31642
31673
|
`update: target ${decision.targetId} ${existing ? "superseded" : "deleted"} before the write`
|
|
31643
31674
|
);
|
|
31644
31675
|
}
|
|
31676
|
+
if (existing.content !== expectedContent) {
|
|
31677
|
+
return abandonToRace(options, `update: target ${decision.targetId} edited before the write`);
|
|
31678
|
+
}
|
|
31645
31679
|
const mergedSourceIds = unionStrings(
|
|
31646
31680
|
existing.sourceChunkIds ?? [],
|
|
31647
31681
|
options.sourceChunkIds ?? []
|
|
@@ -31654,6 +31688,7 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
|
|
|
31654
31688
|
const resurrect = resurrectFields(existing);
|
|
31655
31689
|
const updated = await ctx.persistence.update(decision.targetId, {
|
|
31656
31690
|
content: decision.content,
|
|
31691
|
+
expectedContent,
|
|
31657
31692
|
freeFormOnly: true,
|
|
31658
31693
|
proofCountIncrement: 1,
|
|
31659
31694
|
observationSourceIds: options.sourceChunkIds,
|
|
@@ -31666,10 +31701,10 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
|
|
|
31666
31701
|
...factTypeUpdate !== void 0 && { factType: factTypeUpdate }
|
|
31667
31702
|
});
|
|
31668
31703
|
if (!updated) {
|
|
31669
|
-
await assertMergeTargetGoneOrThrow(ctx, decision.targetId);
|
|
31704
|
+
await assertMergeTargetGoneOrThrow(ctx, decision.targetId, expectedContent);
|
|
31670
31705
|
return abandonToRace(
|
|
31671
31706
|
options,
|
|
31672
|
-
`update: target ${decision.targetId}
|
|
31707
|
+
`update: target ${decision.targetId} changed mid-write (consolidated rewrite lost)`
|
|
31673
31708
|
);
|
|
31674
31709
|
}
|
|
31675
31710
|
cacheRowVector(
|
|
@@ -31696,9 +31731,9 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
|
|
|
31696
31731
|
);
|
|
31697
31732
|
return null;
|
|
31698
31733
|
}
|
|
31699
|
-
async function assertMergeTargetGoneOrThrow(ctx, targetId) {
|
|
31734
|
+
async function assertMergeTargetGoneOrThrow(ctx, targetId, expectedContent) {
|
|
31700
31735
|
const stillExists = await (ctx.persistence.getFresh ? ctx.persistence.getFresh(targetId) : ctx.persistence.get(targetId));
|
|
31701
|
-
if (stillExists && (stillExists.kind === null || stillExists.kind === void 0)) {
|
|
31736
|
+
if (stillExists && (stillExists.kind === null || stillExists.kind === void 0) && (expectedContent === void 0 || stillExists.content === expectedContent)) {
|
|
31702
31737
|
throw new RetainError(
|
|
31703
31738
|
"merge-not-persisted",
|
|
31704
31739
|
`retain: merge into memory ${targetId} failed to persist`
|
|
@@ -37270,6 +37305,7 @@ async function getPdfjs() {
|
|
|
37270
37305
|
return pdfjsModule;
|
|
37271
37306
|
}
|
|
37272
37307
|
async function withPdfDocument(pdfDataUrl, fn) {
|
|
37308
|
+
assertFileUrlAllowed(pdfDataUrl);
|
|
37273
37309
|
const pdfjs = await getPdfjs();
|
|
37274
37310
|
const loadingTask = pdfjs.getDocument(pdfDataUrl);
|
|
37275
37311
|
let pdf;
|
|
@@ -38058,6 +38094,7 @@ async function preprocessFiles(files, options = {}) {
|
|
|
38058
38094
|
skip("no_data");
|
|
38059
38095
|
continue;
|
|
38060
38096
|
}
|
|
38097
|
+
assertFileUrlAllowed(file.url);
|
|
38061
38098
|
const fileWithData = {
|
|
38062
38099
|
...file,
|
|
38063
38100
|
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
|
|