@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/react/index.cjs
CHANGED
|
@@ -875,7 +875,8 @@ async function callPortalJsonCompletion(req) {
|
|
|
875
875
|
}
|
|
876
876
|
const maxAttempts = Math.max(1, req.maxAttempts ?? 3);
|
|
877
877
|
const startedAt = Date.now();
|
|
878
|
-
const
|
|
878
|
+
const deadlineAt = req.totalTimeoutMs === void 0 ? void 0 : startedAt + req.totalTimeoutMs;
|
|
879
|
+
const overBudget = () => deadlineAt !== void 0 && Date.now() >= deadlineAt;
|
|
879
880
|
let lastFailure;
|
|
880
881
|
let reinforce = false;
|
|
881
882
|
const giveUp = () => {
|
|
@@ -888,17 +889,11 @@ async function callPortalJsonCompletion(req) {
|
|
|
888
889
|
lastFailure = { reason: "time-budget-exhausted", attempts: attempt - 1 };
|
|
889
890
|
break;
|
|
890
891
|
}
|
|
891
|
-
const attemptReq = req
|
|
892
|
-
...req,
|
|
893
|
-
timeoutMs: Math.max(
|
|
894
|
-
1,
|
|
895
|
-
Math.min(req.timeoutMs ?? 6e4, req.totalTimeoutMs - (Date.now() - startedAt))
|
|
896
|
-
),
|
|
897
|
-
...reinforce && { reinforceJsonContract: true }
|
|
898
|
-
} : reinforce ? { ...req, reinforceJsonContract: true } : req;
|
|
892
|
+
const attemptReq = reinforce ? { ...req, reinforceJsonContract: true } : req;
|
|
899
893
|
const outcome2 = await attemptPortalJson(
|
|
900
894
|
{ ...attemptReq, transport },
|
|
901
|
-
endpoint
|
|
895
|
+
endpoint,
|
|
896
|
+
deadlineAt
|
|
902
897
|
);
|
|
903
898
|
if (outcome2.kind === "ok") {
|
|
904
899
|
req.onAttempt?.({ attempt, ok: true });
|
|
@@ -938,13 +933,38 @@ async function callPortalJsonCompletion(req) {
|
|
|
938
933
|
}
|
|
939
934
|
return giveUp();
|
|
940
935
|
}
|
|
941
|
-
async function attemptPortalJson(req, endpoint) {
|
|
936
|
+
async function attemptPortalJson(req, endpoint, deadlineAt) {
|
|
937
|
+
const controller = new AbortController();
|
|
938
|
+
if (deadlineAt === void 0 || deadlineAt - Date.now() > MAX_TIMER_DELAY_MS) {
|
|
939
|
+
return requestPortalJson(req, endpoint, controller);
|
|
940
|
+
}
|
|
941
|
+
const remainingMs = deadlineAt - Date.now();
|
|
942
|
+
if (remainingMs <= 0) return TIME_BUDGET_EXHAUSTED;
|
|
943
|
+
let timer;
|
|
944
|
+
try {
|
|
945
|
+
const outcome2 = await Promise.race([
|
|
946
|
+
new Promise((resolve) => {
|
|
947
|
+
timer = setTimeout(() => {
|
|
948
|
+
resolve(TIME_BUDGET_EXHAUSTED);
|
|
949
|
+
controller.abort();
|
|
950
|
+
}, remainingMs);
|
|
951
|
+
}),
|
|
952
|
+
requestPortalJson(req, endpoint, controller, deadlineAt)
|
|
953
|
+
]);
|
|
954
|
+
return Date.now() >= deadlineAt ? TIME_BUDGET_EXHAUSTED : outcome2;
|
|
955
|
+
} finally {
|
|
956
|
+
clearTimeout(timer);
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
async function requestPortalJson(req, endpoint, controller, deadlineAt) {
|
|
942
960
|
const baseUrl = req.baseUrl ?? defaultBaseUrl();
|
|
943
961
|
const fetchImpl = req.fetchFn ?? fetch;
|
|
944
|
-
const timeoutMs = req.timeoutMs ?? 6e4;
|
|
945
962
|
const authHeaders = await resolvePortalAuthHeaders(req, req.tag);
|
|
963
|
+
const remainingMs = deadlineAt === void 0 ? Infinity : deadlineAt - Date.now();
|
|
964
|
+
if (controller.signal.aborted || remainingMs <= 0) return TIME_BUDGET_EXHAUSTED;
|
|
946
965
|
if (authHeaders === null)
|
|
947
966
|
return { kind: "terminal", code: "auth-unavailable", reason: "auth unavailable (no token)" };
|
|
967
|
+
const timeoutMs = Math.min(req.timeoutMs ?? 6e4, remainingMs);
|
|
948
968
|
const usesPrefill = req.transport !== "responses" && req.model.startsWith("anthropic/");
|
|
949
969
|
const prefill = usesPrefill ? "{" : "";
|
|
950
970
|
const messages = [
|
|
@@ -954,7 +974,6 @@ async function attemptPortalJson(req, endpoint) {
|
|
|
954
974
|
];
|
|
955
975
|
if (prefill) messages.push({ role: "assistant", content: prefill });
|
|
956
976
|
const supportsJsonObjectFormat = supportsResponseFormat(req.model);
|
|
957
|
-
const controller = new AbortController();
|
|
958
977
|
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
959
978
|
const requestBody = req.transport === "responses" ? {
|
|
960
979
|
model: req.model,
|
|
@@ -1139,7 +1158,7 @@ function extractResponsesContent(body) {
|
|
|
1139
1158
|
const text14 = 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("");
|
|
1140
1159
|
return text14;
|
|
1141
1160
|
}
|
|
1142
|
-
var RESPONSE_FORMAT_OK, RESPONSE_SCHEMA_OK, JSON_CONTRACT_REMINDER, RESPONSES_ONLY_MODEL_PREFIXES, CHAT_TO_RESPONSES_FIELDS, FOREIGN_ENDPOINT_SUFFIX, RETRYABLE_HTTP;
|
|
1161
|
+
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;
|
|
1143
1162
|
var init_portalLlm = __esm({
|
|
1144
1163
|
"src/lib/memory/portalLlm.ts"() {
|
|
1145
1164
|
"use strict";
|
|
@@ -1159,6 +1178,12 @@ var init_portalLlm = __esm({
|
|
|
1159
1178
|
chat: "/responses",
|
|
1160
1179
|
responses: "/chat/completions"
|
|
1161
1180
|
};
|
|
1181
|
+
TIME_BUDGET_EXHAUSTED = {
|
|
1182
|
+
kind: "terminal",
|
|
1183
|
+
code: "time-budget-exhausted",
|
|
1184
|
+
reason: "time budget exhausted"
|
|
1185
|
+
};
|
|
1186
|
+
MAX_TIMER_DELAY_MS = 2147483647;
|
|
1162
1187
|
RETRYABLE_HTTP = /* @__PURE__ */ new Set([408, 409, 425, 429]);
|
|
1163
1188
|
}
|
|
1164
1189
|
});
|
|
@@ -3550,7 +3575,14 @@ function cosineSimilarity(a, b) {
|
|
|
3550
3575
|
|
|
3551
3576
|
// src/lib/processors/encoding.ts
|
|
3552
3577
|
var B64_ENCODE_CHUNK = 32768 * 3;
|
|
3578
|
+
function assertFileUrlAllowed(dataUrl) {
|
|
3579
|
+
const isNode = typeof process !== "undefined" && Boolean(process.versions?.node);
|
|
3580
|
+
if (isNode && !dataUrl.startsWith("data:") && !dataUrl.startsWith("blob:")) {
|
|
3581
|
+
throw new Error("Server file preprocessing requires a data URL or blob URL.");
|
|
3582
|
+
}
|
|
3583
|
+
}
|
|
3553
3584
|
async function dataUrlToArrayBuffer(dataUrl) {
|
|
3585
|
+
assertFileUrlAllowed(dataUrl);
|
|
3554
3586
|
if (dataUrl.startsWith("blob:") || dataUrl.startsWith("http://") || dataUrl.startsWith("https://")) {
|
|
3555
3587
|
const response = await fetch(dataUrl);
|
|
3556
3588
|
return response.arrayBuffer();
|
|
@@ -6212,7 +6244,7 @@ var mergeHeaders = (...headers) => {
|
|
|
6212
6244
|
if (!header || typeof header !== "object") {
|
|
6213
6245
|
continue;
|
|
6214
6246
|
}
|
|
6215
|
-
const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
|
|
6247
|
+
const iterator = Array.isArray(header) || header instanceof Headers ? headersEntries(new Headers(header)) : Object.entries(header);
|
|
6216
6248
|
for (const [key, value] of iterator) {
|
|
6217
6249
|
if (value === null) {
|
|
6218
6250
|
mergedHeaders.delete(key);
|
|
@@ -6488,6 +6520,18 @@ var createClient = (config = {}) => {
|
|
|
6488
6520
|
init_clientConfig();
|
|
6489
6521
|
var client = createClient(createClientConfig(createConfig()));
|
|
6490
6522
|
|
|
6523
|
+
// src/clientHeaders.ts
|
|
6524
|
+
function normalizeHeaders(headers) {
|
|
6525
|
+
if (headers instanceof Headers || Array.isArray(headers)) {
|
|
6526
|
+
const normalized = /* @__PURE__ */ Object.create(null);
|
|
6527
|
+
new Headers(headers).forEach((value, name) => {
|
|
6528
|
+
normalized[name] = value;
|
|
6529
|
+
});
|
|
6530
|
+
return normalized;
|
|
6531
|
+
}
|
|
6532
|
+
return headers;
|
|
6533
|
+
}
|
|
6534
|
+
|
|
6491
6535
|
// src/client/sdk.gen.ts
|
|
6492
6536
|
var getApiV1Config = (options) => (options?.client ?? client).get({ url: "/api/v1/config", ...options });
|
|
6493
6537
|
var getApiV1CreditsBalance = (options) => (options?.client ?? client).get({ url: "/api/v1/credits/balance", ...options });
|
|
@@ -6497,7 +6541,7 @@ var postApiV1CreditsPurchase = (options) => (options.client ?? client).post({
|
|
|
6497
6541
|
...options,
|
|
6498
6542
|
headers: {
|
|
6499
6543
|
"Content-Type": "application/json",
|
|
6500
|
-
...options.headers
|
|
6544
|
+
...normalizeHeaders(options.headers)
|
|
6501
6545
|
}
|
|
6502
6546
|
});
|
|
6503
6547
|
var postApiV1Embeddings = (options) => (options.client ?? client).post({
|
|
@@ -6505,7 +6549,7 @@ var postApiV1Embeddings = (options) => (options.client ?? client).post({
|
|
|
6505
6549
|
...options,
|
|
6506
6550
|
headers: {
|
|
6507
6551
|
"Content-Type": "application/json",
|
|
6508
|
-
...options.headers
|
|
6552
|
+
...normalizeHeaders(options.headers)
|
|
6509
6553
|
}
|
|
6510
6554
|
});
|
|
6511
6555
|
var getApiV1Models = (options) => (options?.client ?? client).get({ url: "/api/v1/models", ...options });
|
|
@@ -6514,7 +6558,7 @@ var postApiV1PhoneCalls = (options) => (options.client ?? client).post({
|
|
|
6514
6558
|
...options,
|
|
6515
6559
|
headers: {
|
|
6516
6560
|
"Content-Type": "application/json",
|
|
6517
|
-
...options.headers
|
|
6561
|
+
...normalizeHeaders(options.headers)
|
|
6518
6562
|
}
|
|
6519
6563
|
});
|
|
6520
6564
|
var getApiV1PhoneCallsByCallId = (options) => (options.client ?? client).get({ url: "/api/v1/phone-calls/{call_id}", ...options });
|
|
@@ -6523,7 +6567,7 @@ var postApiV1SubscriptionsCancel = (options) => (options?.client ?? client).post
|
|
|
6523
6567
|
...options,
|
|
6524
6568
|
headers: {
|
|
6525
6569
|
"Content-Type": "application/json",
|
|
6526
|
-
...options?.headers
|
|
6570
|
+
...normalizeHeaders(options?.headers)
|
|
6527
6571
|
}
|
|
6528
6572
|
});
|
|
6529
6573
|
var postApiV1SubscriptionsCreateCheckoutSession = (options) => (options.client ?? client).post({
|
|
@@ -6531,7 +6575,7 @@ var postApiV1SubscriptionsCreateCheckoutSession = (options) => (options.client ?
|
|
|
6531
6575
|
...options,
|
|
6532
6576
|
headers: {
|
|
6533
6577
|
"Content-Type": "application/json",
|
|
6534
|
-
...options.headers
|
|
6578
|
+
...normalizeHeaders(options.headers)
|
|
6535
6579
|
}
|
|
6536
6580
|
});
|
|
6537
6581
|
var postApiV1SubscriptionsCustomerPortal = (options) => (options.client ?? client).post({
|
|
@@ -6539,7 +6583,7 @@ var postApiV1SubscriptionsCustomerPortal = (options) => (options.client ?? clien
|
|
|
6539
6583
|
...options,
|
|
6540
6584
|
headers: {
|
|
6541
6585
|
"Content-Type": "application/json",
|
|
6542
|
-
...options.headers
|
|
6586
|
+
...normalizeHeaders(options.headers)
|
|
6543
6587
|
}
|
|
6544
6588
|
});
|
|
6545
6589
|
var postApiV1SubscriptionsRenew = (options) => (options?.client ?? client).post({ url: "/api/v1/subscriptions/renew", ...options });
|
|
@@ -6550,7 +6594,7 @@ var postApiV1WalletsBinding = (options) => (options.client ?? client).post({
|
|
|
6550
6594
|
...options,
|
|
6551
6595
|
headers: {
|
|
6552
6596
|
"Content-Type": "application/json",
|
|
6553
|
-
...options.headers
|
|
6597
|
+
...normalizeHeaders(options.headers)
|
|
6554
6598
|
}
|
|
6555
6599
|
});
|
|
6556
6600
|
var postApiV1WalletsBindingNonce = (options) => (options?.client ?? client).post({ url: "/api/v1/wallets/binding/nonce", ...options });
|
|
@@ -16788,6 +16832,16 @@ async function updateVaultMemoryOp(ctx, id2, opts) {
|
|
|
16788
16832
|
const probe = await ctx.vaultMemoryCollection.find(id2);
|
|
16789
16833
|
if (probe.isDeleted || probe.supersededBy || !isOwnedByCtxUser(ctx, probe)) return null;
|
|
16790
16834
|
if (opts.freeFormOnly && isKinded(probe)) return null;
|
|
16835
|
+
const readStoredContent = probe._getRaw("content");
|
|
16836
|
+
if (opts.expectedContent !== void 0) {
|
|
16837
|
+
const current = await vaultMemoryToStored(
|
|
16838
|
+
probe,
|
|
16839
|
+
ctx.walletAddress,
|
|
16840
|
+
ctx.signMessage,
|
|
16841
|
+
ctx.embeddedWalletSigner
|
|
16842
|
+
);
|
|
16843
|
+
if (current.content !== opts.expectedContent) return null;
|
|
16844
|
+
}
|
|
16791
16845
|
const levelAfter = (current) => {
|
|
16792
16846
|
if (opts.level !== void 0) return opts.level;
|
|
16793
16847
|
if (opts.scope === void 0) return resolveMemoryLevel(current.level, current.scope);
|
|
@@ -16795,7 +16849,7 @@ async function updateVaultMemoryOp(ctx, id2, opts) {
|
|
|
16795
16849
|
};
|
|
16796
16850
|
assertValidKindLevel(opts.kind !== void 0 ? opts.kind : probe.kind, levelAfter(probe));
|
|
16797
16851
|
const encryptedKindValue = await encryptKindValue(ctx, opts.kindValue);
|
|
16798
|
-
const encryptedContent = ctx.walletAddress && ctx.signMessage ? await encryptVaultMemoryContent(
|
|
16852
|
+
const encryptedContent = opts.content !== void 0 && ctx.walletAddress && ctx.signMessage ? await encryptVaultMemoryContent(
|
|
16799
16853
|
opts.content,
|
|
16800
16854
|
ctx.walletAddress,
|
|
16801
16855
|
ctx.signMessage,
|
|
@@ -16803,13 +16857,13 @@ async function updateVaultMemoryOp(ctx, id2, opts) {
|
|
|
16803
16857
|
) : opts.content;
|
|
16804
16858
|
let stale = false;
|
|
16805
16859
|
const record2 = probe;
|
|
16806
|
-
const originalUpdatedAt = record2.updatedAt.getTime();
|
|
16807
16860
|
await ctx.database.write(async () => {
|
|
16808
16861
|
await assertCanWrite2(ctx);
|
|
16809
|
-
if (record2.isDeleted || record2.supersededBy || !isOwnedByCtxUser(ctx, record2) || opts.freeFormOnly && isKinded(record2)) {
|
|
16862
|
+
if (record2.isDeleted || record2.supersededBy || !isOwnedByCtxUser(ctx, record2) || opts.freeFormOnly && isKinded(record2) || opts.expectedContent !== void 0 && record2._getRaw("content") !== readStoredContent) {
|
|
16810
16863
|
stale = true;
|
|
16811
16864
|
return;
|
|
16812
16865
|
}
|
|
16866
|
+
const originalUpdatedAt = record2.updatedAt.getTime();
|
|
16813
16867
|
const nextKind = opts.kind !== void 0 ? opts.kind : record2.kind;
|
|
16814
16868
|
const nextLevel = levelAfter(record2);
|
|
16815
16869
|
assertValidKindLevel(nextKind, nextLevel);
|
|
@@ -16825,7 +16879,7 @@ async function updateVaultMemoryOp(ctx, id2, opts) {
|
|
|
16825
16879
|
replayedObservation = opts.observationSourceIds.every((id3) => observedSources.includes(id3));
|
|
16826
16880
|
}
|
|
16827
16881
|
await record2.update((r) => {
|
|
16828
|
-
r._setRaw("content", encryptedContent);
|
|
16882
|
+
if (encryptedContent !== void 0) r._setRaw("content", encryptedContent);
|
|
16829
16883
|
if (opts.level !== void 0) {
|
|
16830
16884
|
r._setRaw("level", nextLevel);
|
|
16831
16885
|
r._setRaw("scope", scopeForLevel(nextLevel));
|
|
@@ -17593,7 +17647,7 @@ function classifyDecay(m, now, policy) {
|
|
|
17593
17647
|
if (m.source === "manual" || m.source === SOURCE_PHOTO) return "keep";
|
|
17594
17648
|
if (isTimeSensitiveType(m.factType) && m.eventTimeEnd !== null) {
|
|
17595
17649
|
if (m.eventTimeEnd < now - resolved.pastEventGraceMs) return "archive";
|
|
17596
|
-
|
|
17650
|
+
return "keep";
|
|
17597
17651
|
}
|
|
17598
17652
|
if (now - lastActivityAt(m) > ttlForType(m.factType, resolved)) return "archive";
|
|
17599
17653
|
return "keep";
|
|
@@ -21119,7 +21173,6 @@ async function retainWithPersistence(content, ctx, options = {}) {
|
|
|
21119
21173
|
const factTypeUpdate = pickFactTypeUpdate(existing, options.factType);
|
|
21120
21174
|
const resurrect = resurrectFields(existing);
|
|
21121
21175
|
const updated = await ctx.persistence.update(targetId, {
|
|
21122
|
-
content: existing.content,
|
|
21123
21176
|
freeFormOnly: true,
|
|
21124
21177
|
proofCountIncrement: 1,
|
|
21125
21178
|
observationSourceIds: options.sourceChunkIds,
|
|
@@ -21358,7 +21411,6 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
|
|
|
21358
21411
|
const factTypeUpdate = pickFactTypeUpdate(existing, options.factType);
|
|
21359
21412
|
const resurrect = resurrectFields(existing);
|
|
21360
21413
|
const updated = await ctx.persistence.update(decision.targetId, {
|
|
21361
|
-
content: existing.content,
|
|
21362
21414
|
freeFormOnly: true,
|
|
21363
21415
|
proofCountIncrement: 1,
|
|
21364
21416
|
observationSourceIds: options.sourceChunkIds,
|
|
@@ -21386,6 +21438,10 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
|
|
|
21386
21438
|
};
|
|
21387
21439
|
}
|
|
21388
21440
|
if (decision.action === "update" && decision.targetId && decision.content) {
|
|
21441
|
+
const expectedContent = candidates.find(
|
|
21442
|
+
(candidate) => candidate.id === decision.targetId
|
|
21443
|
+
)?.content;
|
|
21444
|
+
if (expectedContent === void 0) return null;
|
|
21389
21445
|
const existing = await ctx.persistence.get(decision.targetId);
|
|
21390
21446
|
if (!existing || existing.supersededBy) {
|
|
21391
21447
|
return abandonToRace(
|
|
@@ -21393,6 +21449,9 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
|
|
|
21393
21449
|
`update: target ${decision.targetId} ${existing ? "superseded" : "deleted"} before the write`
|
|
21394
21450
|
);
|
|
21395
21451
|
}
|
|
21452
|
+
if (existing.content !== expectedContent) {
|
|
21453
|
+
return abandonToRace(options, `update: target ${decision.targetId} edited before the write`);
|
|
21454
|
+
}
|
|
21396
21455
|
const mergedSourceIds = unionStrings(
|
|
21397
21456
|
existing.sourceChunkIds ?? [],
|
|
21398
21457
|
options.sourceChunkIds ?? []
|
|
@@ -21405,6 +21464,7 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
|
|
|
21405
21464
|
const resurrect = resurrectFields(existing);
|
|
21406
21465
|
const updated = await ctx.persistence.update(decision.targetId, {
|
|
21407
21466
|
content: decision.content,
|
|
21467
|
+
expectedContent,
|
|
21408
21468
|
freeFormOnly: true,
|
|
21409
21469
|
proofCountIncrement: 1,
|
|
21410
21470
|
observationSourceIds: options.sourceChunkIds,
|
|
@@ -21417,10 +21477,10 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
|
|
|
21417
21477
|
...factTypeUpdate !== void 0 && { factType: factTypeUpdate }
|
|
21418
21478
|
});
|
|
21419
21479
|
if (!updated) {
|
|
21420
|
-
await assertMergeTargetGoneOrThrow(ctx, decision.targetId);
|
|
21480
|
+
await assertMergeTargetGoneOrThrow(ctx, decision.targetId, expectedContent);
|
|
21421
21481
|
return abandonToRace(
|
|
21422
21482
|
options,
|
|
21423
|
-
`update: target ${decision.targetId}
|
|
21483
|
+
`update: target ${decision.targetId} changed mid-write (consolidated rewrite lost)`
|
|
21424
21484
|
);
|
|
21425
21485
|
}
|
|
21426
21486
|
cacheRowVector(
|
|
@@ -21447,9 +21507,9 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
|
|
|
21447
21507
|
);
|
|
21448
21508
|
return null;
|
|
21449
21509
|
}
|
|
21450
|
-
async function assertMergeTargetGoneOrThrow(ctx, targetId) {
|
|
21510
|
+
async function assertMergeTargetGoneOrThrow(ctx, targetId, expectedContent) {
|
|
21451
21511
|
const stillExists = await (ctx.persistence.getFresh ? ctx.persistence.getFresh(targetId) : ctx.persistence.get(targetId));
|
|
21452
|
-
if (stillExists && (stillExists.kind === null || stillExists.kind === void 0)) {
|
|
21512
|
+
if (stillExists && (stillExists.kind === null || stillExists.kind === void 0) && (expectedContent === void 0 || stillExists.content === expectedContent)) {
|
|
21453
21513
|
throw new RetainError(
|
|
21454
21514
|
"merge-not-persisted",
|
|
21455
21515
|
`retain: merge into memory ${targetId} failed to persist`
|
|
@@ -24887,16 +24947,16 @@ function createRemoteMemoryPipeline(options) {
|
|
|
24887
24947
|
create: (input) => write(createRow(input), 0),
|
|
24888
24948
|
update: async (id2, patch) => {
|
|
24889
24949
|
const existing = await get(id2);
|
|
24890
|
-
if (!existing || patch.freeFormOnly && existing.kind !== null && existing.kind !== void 0)
|
|
24950
|
+
if (!existing || patch.expectedContent !== void 0 && existing.content !== patch.expectedContent || patch.freeFormOnly && existing.kind !== null && existing.kind !== void 0)
|
|
24891
24951
|
return null;
|
|
24892
24952
|
const snapshot = snapshots.get(id2);
|
|
24893
24953
|
const memory = {
|
|
24894
24954
|
...snapshot.memory,
|
|
24895
|
-
content: patch.content,
|
|
24955
|
+
content: patch.content ?? snapshot.memory.content,
|
|
24896
24956
|
updated_at: patch.preserveUpdatedAt ? snapshot.memory.updated_at : Math.max(Date.now(), (snapshot.memory.topics_extracted_at ?? 0) + 1)
|
|
24897
24957
|
};
|
|
24898
24958
|
if (patch.scope !== void 0) memory.scope = patch.scope;
|
|
24899
|
-
if (patch.embedding === void 0 && patch.content !== snapshot.memory.content) {
|
|
24959
|
+
if (patch.embedding === void 0 && patch.content !== void 0 && patch.content !== snapshot.memory.content) {
|
|
24900
24960
|
delete memory.embedding;
|
|
24901
24961
|
delete memory.embedding_model;
|
|
24902
24962
|
}
|
|
@@ -29578,6 +29638,7 @@ async function getPdfjs() {
|
|
|
29578
29638
|
return pdfjsModule;
|
|
29579
29639
|
}
|
|
29580
29640
|
async function withPdfDocument(pdfDataUrl, fn) {
|
|
29641
|
+
assertFileUrlAllowed(pdfDataUrl);
|
|
29581
29642
|
const pdfjs = await getPdfjs();
|
|
29582
29643
|
const loadingTask = pdfjs.getDocument(pdfDataUrl);
|
|
29583
29644
|
let pdf;
|
|
@@ -30380,6 +30441,7 @@ async function preprocessFiles(files, options = {}) {
|
|
|
30380
30441
|
skip("no_data");
|
|
30381
30442
|
continue;
|
|
30382
30443
|
}
|
|
30444
|
+
assertFileUrlAllowed(file.url);
|
|
30383
30445
|
const fileWithData = {
|
|
30384
30446
|
...file,
|
|
30385
30447
|
dataUrl: file.url
|
|
@@ -38650,17 +38712,24 @@ var import_react20 = require("react");
|
|
|
38650
38712
|
init_clientConfig();
|
|
38651
38713
|
function useTools(options) {
|
|
38652
38714
|
const { getToken, baseUrl = BASE_URL, includeTools, autoFetch = true } = options;
|
|
38653
|
-
const [
|
|
38715
|
+
const [allTools, setAllTools] = (0, import_react20.useState)([]);
|
|
38654
38716
|
const [checksum, setChecksum] = (0, import_react20.useState)(getToolsChecksum2);
|
|
38655
38717
|
const [isLoading, setIsLoading] = (0, import_react20.useState)(false);
|
|
38656
38718
|
const [error, setError] = (0, import_react20.useState)(null);
|
|
38719
|
+
const includeToolsRef = (0, import_react20.useRef)(includeTools);
|
|
38720
|
+
if (includeTools !== includeToolsRef.current && (includeTools === void 0 || includeToolsRef.current === void 0 || includeTools.length !== includeToolsRef.current.length || includeTools.some((name, i) => name !== includeToolsRef.current?.[i]))) {
|
|
38721
|
+
includeToolsRef.current = includeTools;
|
|
38722
|
+
}
|
|
38723
|
+
const stableIncludeTools = includeToolsRef.current;
|
|
38724
|
+
const tools = (0, import_react20.useMemo)(
|
|
38725
|
+
() => filterServerTools(allTools, stableIncludeTools),
|
|
38726
|
+
[allTools, stableIncludeTools]
|
|
38727
|
+
);
|
|
38657
38728
|
const getTokenRef = (0, import_react20.useRef)(getToken);
|
|
38658
38729
|
const baseUrlRef = (0, import_react20.useRef)(baseUrl);
|
|
38659
|
-
const includeToolsRef = (0, import_react20.useRef)(includeTools);
|
|
38660
38730
|
(0, import_react20.useEffect)(() => {
|
|
38661
38731
|
getTokenRef.current = getToken;
|
|
38662
38732
|
baseUrlRef.current = baseUrl;
|
|
38663
|
-
includeToolsRef.current = includeTools;
|
|
38664
38733
|
});
|
|
38665
38734
|
const fetchTools = (0, import_react20.useCallback)(async (forceRefresh = false) => {
|
|
38666
38735
|
setIsLoading(true);
|
|
@@ -38671,8 +38740,7 @@ function useTools(options) {
|
|
|
38671
38740
|
baseUrl: baseUrlRef.current,
|
|
38672
38741
|
forceRefresh
|
|
38673
38742
|
});
|
|
38674
|
-
|
|
38675
|
-
setTools(filteredTools);
|
|
38743
|
+
setAllTools(fetchedTools);
|
|
38676
38744
|
setChecksum(getToolsChecksum2());
|
|
38677
38745
|
} catch (err) {
|
|
38678
38746
|
setError(err instanceof Error ? err : new Error(String(err)));
|
|
@@ -38696,11 +38764,6 @@ function useTools(options) {
|
|
|
38696
38764
|
},
|
|
38697
38765
|
[refresh]
|
|
38698
38766
|
);
|
|
38699
|
-
(0, import_react20.useEffect)(() => {
|
|
38700
|
-
if (tools.length > 0 && includeTools !== void 0) {
|
|
38701
|
-
setTools((currentTools) => filterServerTools(currentTools, includeTools));
|
|
38702
|
-
}
|
|
38703
|
-
}, [includeTools, tools.length]);
|
|
38704
38767
|
const hasFetchedRef = (0, import_react20.useRef)(false);
|
|
38705
38768
|
(0, import_react20.useEffect)(() => {
|
|
38706
38769
|
if (autoFetch && !hasFetchedRef.current) {
|
package/dist/react/index.d.mts
CHANGED
|
@@ -6185,7 +6185,8 @@ interface CreateVaultMemoryOptions {
|
|
|
6185
6185
|
geohash?: string;
|
|
6186
6186
|
}
|
|
6187
6187
|
interface UpdateVaultMemoryOptions {
|
|
6188
|
-
content
|
|
6188
|
+
content?: string;
|
|
6189
|
+
expectedContent?: string;
|
|
6189
6190
|
/** When true, the write is skipped (returns null) if the row carries a profile kind. */
|
|
6190
6191
|
freeFormOnly?: boolean;
|
|
6191
6192
|
/**
|
|
@@ -6878,9 +6879,10 @@ declare function ttlForType(factType: string | null, policy?: Partial<DecayPolic
|
|
|
6878
6879
|
* null `eventTimeEnd` is still ongoing, so this rule does not fire for it.
|
|
6879
6880
|
* 4. Age fallback — `now - updatedAt > TTL(factType)` → archive. Durable types
|
|
6880
6881
|
* have Infinity TTL, so this never fires for them; null/unknown use medium.
|
|
6881
|
-
* EXCEPTION: a `plan
|
|
6882
|
-
* (`eventTimeEnd >= now
|
|
6883
|
-
*
|
|
6882
|
+
* EXCEPTION: a `plan` / `ongoing_context` with an upcoming event or an event
|
|
6883
|
+
* within the grace period (`eventTimeEnd >= now - pastEventGraceMs`) stays
|
|
6884
|
+
* active, even after its activity TTL expires. Rule 3 archives it after the
|
|
6885
|
+
* grace period ends.
|
|
6884
6886
|
* 5. Otherwise → keep.
|
|
6885
6887
|
*
|
|
6886
6888
|
* @param m Plaintext decay inputs for one row.
|
|
@@ -7211,7 +7213,9 @@ type MemoryCreate = Pick<CreateVaultMemoryOptions, "content" | "scope" | "factTy
|
|
|
7211
7213
|
* `embedding` (with `embeddingModel`) only when you already have the new one.
|
|
7212
7214
|
* @public
|
|
7213
7215
|
*/
|
|
7214
|
-
type MemoryUpdate = Pick<UpdateVaultMemoryOptions, "
|
|
7216
|
+
type MemoryUpdate = Pick<UpdateVaultMemoryOptions, "scope" | "factType" | "eventTime" | "embedding" | "embeddingModel" | "kind" | "kindValue" | "level"> & {
|
|
7217
|
+
content: string;
|
|
7218
|
+
};
|
|
7215
7219
|
/**
|
|
7216
7220
|
* Fact-only recall. Conversation chunks are message storage, not memory, so
|
|
7217
7221
|
* the chunk-lane knobs are not part of this surface; nor is `folderId` (see
|
package/dist/react/index.d.ts
CHANGED
|
@@ -6185,7 +6185,8 @@ interface CreateVaultMemoryOptions {
|
|
|
6185
6185
|
geohash?: string;
|
|
6186
6186
|
}
|
|
6187
6187
|
interface UpdateVaultMemoryOptions {
|
|
6188
|
-
content
|
|
6188
|
+
content?: string;
|
|
6189
|
+
expectedContent?: string;
|
|
6189
6190
|
/** When true, the write is skipped (returns null) if the row carries a profile kind. */
|
|
6190
6191
|
freeFormOnly?: boolean;
|
|
6191
6192
|
/**
|
|
@@ -6878,9 +6879,10 @@ declare function ttlForType(factType: string | null, policy?: Partial<DecayPolic
|
|
|
6878
6879
|
* null `eventTimeEnd` is still ongoing, so this rule does not fire for it.
|
|
6879
6880
|
* 4. Age fallback — `now - updatedAt > TTL(factType)` → archive. Durable types
|
|
6880
6881
|
* have Infinity TTL, so this never fires for them; null/unknown use medium.
|
|
6881
|
-
* EXCEPTION: a `plan
|
|
6882
|
-
* (`eventTimeEnd >= now
|
|
6883
|
-
*
|
|
6882
|
+
* EXCEPTION: a `plan` / `ongoing_context` with an upcoming event or an event
|
|
6883
|
+
* within the grace period (`eventTimeEnd >= now - pastEventGraceMs`) stays
|
|
6884
|
+
* active, even after its activity TTL expires. Rule 3 archives it after the
|
|
6885
|
+
* grace period ends.
|
|
6884
6886
|
* 5. Otherwise → keep.
|
|
6885
6887
|
*
|
|
6886
6888
|
* @param m Plaintext decay inputs for one row.
|
|
@@ -7211,7 +7213,9 @@ type MemoryCreate = Pick<CreateVaultMemoryOptions, "content" | "scope" | "factTy
|
|
|
7211
7213
|
* `embedding` (with `embeddingModel`) only when you already have the new one.
|
|
7212
7214
|
* @public
|
|
7213
7215
|
*/
|
|
7214
|
-
type MemoryUpdate = Pick<UpdateVaultMemoryOptions, "
|
|
7216
|
+
type MemoryUpdate = Pick<UpdateVaultMemoryOptions, "scope" | "factType" | "eventTime" | "embedding" | "embeddingModel" | "kind" | "kindValue" | "level"> & {
|
|
7217
|
+
content: string;
|
|
7218
|
+
};
|
|
7215
7219
|
/**
|
|
7216
7220
|
* Fact-only recall. Conversation chunks are message storage, not memory, so
|
|
7217
7221
|
* the chunk-lane knobs are not part of this surface; nor is `folderId` (see
|