@anuma/sdk 3.3.0 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/index.cjs +793 -1420
- package/dist/client/index.d.mts +406 -402
- package/dist/client/index.d.ts +406 -402
- package/dist/client/index.mjs +793 -1420
- package/dist/expo/{chunk-NMZMXIUM.mjs → chunk-C7PGRFBG.mjs} +82 -9
- package/dist/expo/index.cjs +234 -168
- package/dist/expo/index.d.mts +70 -1
- package/dist/expo/index.d.ts +70 -1
- package/dist/expo/index.mjs +144 -156
- package/dist/expo/{recall-7FUJRHOI.mjs → recall-7ZX6T2VD.mjs} +1 -1
- package/dist/index.cjs +453 -783
- package/dist/index.d.mts +491 -487
- package/dist/index.d.ts +491 -487
- package/dist/index.mjs +453 -783
- package/dist/react/{chunk-GZRK43CA.mjs → chunk-CGC3UJHM.mjs} +82 -9
- package/dist/react/index.cjs +305 -290
- package/dist/react/index.d.mts +453 -380
- package/dist/react/index.d.ts +453 -380
- package/dist/react/index.mjs +215 -278
- package/dist/react/{recall-YZGWZC5W.mjs → recall-OTUNGQHQ.mjs} +1 -1
- package/dist/server/{chunk-NVTMJWFA.mjs → chunk-LUDHA4X4.mjs} +82 -9
- package/dist/server/index.cjs +124 -30
- package/dist/server/index.d.mts +70 -1
- package/dist/server/index.d.ts +70 -1
- package/dist/server/index.mjs +34 -18
- package/dist/server/{recall-76WPPKLR.mjs → recall-GWRWPGE4.mjs} +1 -1
- package/dist/tools/selection/index.cjs +3 -0
- package/dist/tools/selection/index.mjs +3 -0
- package/package.json +2 -2
package/dist/expo/index.cjs
CHANGED
|
@@ -2103,6 +2103,9 @@ async function withEmbeddingRetry(call) {
|
|
|
2103
2103
|
}
|
|
2104
2104
|
}
|
|
2105
2105
|
if (threw) throw lastThrown;
|
|
2106
|
+
if (last?.error instanceof Error && last.response?.status === void 0) {
|
|
2107
|
+
throw last.error;
|
|
2108
|
+
}
|
|
2106
2109
|
return last;
|
|
2107
2110
|
}
|
|
2108
2111
|
function isFatalEmbeddingError(err) {
|
|
@@ -5069,6 +5072,48 @@ var init_graphTraversal = __esm({
|
|
|
5069
5072
|
}
|
|
5070
5073
|
});
|
|
5071
5074
|
|
|
5075
|
+
// src/lib/memory/observationTrend.ts
|
|
5076
|
+
function toMs(value) {
|
|
5077
|
+
return value instanceof Date ? value.getTime() : value;
|
|
5078
|
+
}
|
|
5079
|
+
function classifyObservationTrend(input, now = Date.now()) {
|
|
5080
|
+
const createdMs = toMs(input.createdAt);
|
|
5081
|
+
if (!Number.isFinite(createdMs) || !Number.isFinite(now)) return "stable";
|
|
5082
|
+
const lastMsRaw = input.lastObservedAt;
|
|
5083
|
+
const lastMs = lastMsRaw !== null && lastMsRaw !== void 0 && Number.isFinite(lastMsRaw) ? Math.max(createdMs, lastMsRaw) : createdMs;
|
|
5084
|
+
const proofs = Math.max(1, input.proofCount ?? 1);
|
|
5085
|
+
const ageDays2 = Math.max(0, (now - createdMs) / DAY_MS2);
|
|
5086
|
+
const daysSinceLast = Math.max(0, (now - lastMs) / DAY_MS2);
|
|
5087
|
+
if (daysSinceLast >= TREND_STALE_WINDOW_DAYS) return "stale";
|
|
5088
|
+
if (daysSinceLast >= TREND_RECENT_WINDOW_DAYS) return "weakening";
|
|
5089
|
+
if (ageDays2 <= TREND_RECENT_WINDOW_DAYS && proofs <= 2) return "new";
|
|
5090
|
+
if (proofs >= 3) return "strengthening";
|
|
5091
|
+
if (proofs >= 2 && ageDays2 > TREND_RECENT_WINDOW_DAYS) return "strengthening";
|
|
5092
|
+
return "stable";
|
|
5093
|
+
}
|
|
5094
|
+
function summarizeObservationTrends(inputs, now = Date.now()) {
|
|
5095
|
+
const counts = {
|
|
5096
|
+
new: 0,
|
|
5097
|
+
strengthening: 0,
|
|
5098
|
+
stable: 0,
|
|
5099
|
+
weakening: 0,
|
|
5100
|
+
stale: 0
|
|
5101
|
+
};
|
|
5102
|
+
for (const input of inputs) {
|
|
5103
|
+
counts[classifyObservationTrend(input, now)]++;
|
|
5104
|
+
}
|
|
5105
|
+
return counts;
|
|
5106
|
+
}
|
|
5107
|
+
var DAY_MS2, TREND_RECENT_WINDOW_DAYS, TREND_STALE_WINDOW_DAYS;
|
|
5108
|
+
var init_observationTrend = __esm({
|
|
5109
|
+
"src/lib/memory/observationTrend.ts"() {
|
|
5110
|
+
"use strict";
|
|
5111
|
+
DAY_MS2 = 1e3 * 60 * 60 * 24;
|
|
5112
|
+
TREND_RECENT_WINDOW_DAYS = 30;
|
|
5113
|
+
TREND_STALE_WINDOW_DAYS = 90;
|
|
5114
|
+
}
|
|
5115
|
+
});
|
|
5116
|
+
|
|
5072
5117
|
// src/lib/memory/queryTemporal.ts
|
|
5073
5118
|
function startOfDay(ts) {
|
|
5074
5119
|
const d = new Date(ts);
|
|
@@ -5468,7 +5513,7 @@ async function recall(query, ctx, options = {}) {
|
|
|
5468
5513
|
const fuseStart = nowMs();
|
|
5469
5514
|
if (types.length === 1 || factResults.length === 0 || chunkResults.length === 0) {
|
|
5470
5515
|
const memories2 = [
|
|
5471
|
-
...factResults.map(toFactMemory),
|
|
5516
|
+
...factResults.map((r) => toFactMemory(r, options.now)),
|
|
5472
5517
|
...chunkResults.map(toChunkMemory)
|
|
5473
5518
|
];
|
|
5474
5519
|
memories2.sort((a, b) => b.score - a.score);
|
|
@@ -5489,7 +5534,7 @@ async function recall(query, ctx, options = {}) {
|
|
|
5489
5534
|
const fused = rrfFuse([factRanking, chunkRanking], options.rrfK);
|
|
5490
5535
|
const byId = /* @__PURE__ */ new Map();
|
|
5491
5536
|
for (const r of factResults) {
|
|
5492
|
-
const m = toFactMemory(r);
|
|
5537
|
+
const m = toFactMemory(r, options.now);
|
|
5493
5538
|
m.score = fused.get(`fact:${r.uniqueId}`) ?? 0;
|
|
5494
5539
|
if (!m.scoreBreakdown) m.scoreBreakdown = {};
|
|
5495
5540
|
m.scoreBreakdown.fused = r.similarity;
|
|
@@ -5538,7 +5583,10 @@ async function recall(query, ctx, options = {}) {
|
|
|
5538
5583
|
...vaultSize !== void 0 && { vaultSize }
|
|
5539
5584
|
};
|
|
5540
5585
|
}
|
|
5541
|
-
function toFactMemory(r) {
|
|
5586
|
+
function toFactMemory(r, now) {
|
|
5587
|
+
const createdAt = r.createdAt ?? /* @__PURE__ */ new Date(0);
|
|
5588
|
+
const proofCount = r.proofCount ?? void 0;
|
|
5589
|
+
const lastObservedAt = r.lastObservedAt ?? null;
|
|
5542
5590
|
return {
|
|
5543
5591
|
id: r.uniqueId,
|
|
5544
5592
|
kind: "fact",
|
|
@@ -5554,6 +5602,18 @@ function toFactMemory(r) {
|
|
|
5554
5602
|
// (and UI reading them) carry the fact's type. Undefined when untyped.
|
|
5555
5603
|
...r.factType !== void 0 && { factType: r.factType },
|
|
5556
5604
|
...r.sourceChunkIds !== void 0 && r.sourceChunkIds !== null && { sourceChunkIds: r.sourceChunkIds },
|
|
5605
|
+
...proofCount !== void 0 && proofCount !== null && { proofCount },
|
|
5606
|
+
...lastObservedAt !== null && { lastObservedAt },
|
|
5607
|
+
// C2 — algorithmic trend from evidence timestamps (no LLM). Honor
|
|
5608
|
+
// RecallOptions.now so back-dated eval harnesses get consistent labels.
|
|
5609
|
+
observationTrend: classifyObservationTrend(
|
|
5610
|
+
{
|
|
5611
|
+
createdAt,
|
|
5612
|
+
lastObservedAt,
|
|
5613
|
+
proofCount
|
|
5614
|
+
},
|
|
5615
|
+
now ?? Date.now()
|
|
5616
|
+
),
|
|
5557
5617
|
// r.similarity from searchVaultMemoriesWithSize is the fused score
|
|
5558
5618
|
// (cosine + BM25 + RRF + recency + proof) when useFusion=true (the
|
|
5559
5619
|
// default) and pure cosine when useFusion=false. The breakdown
|
|
@@ -5562,7 +5622,7 @@ function toFactMemory(r) {
|
|
|
5562
5622
|
content: r.content,
|
|
5563
5623
|
score: r.similarity,
|
|
5564
5624
|
scoreBreakdown: { fused: r.similarity },
|
|
5565
|
-
createdAt
|
|
5625
|
+
createdAt,
|
|
5566
5626
|
updatedAt: r.updatedAt ?? /* @__PURE__ */ new Date(0)
|
|
5567
5627
|
};
|
|
5568
5628
|
}
|
|
@@ -5645,6 +5705,7 @@ var init_recall = __esm({
|
|
|
5645
5705
|
init_embeddings();
|
|
5646
5706
|
init_searchTool();
|
|
5647
5707
|
init_graphTraversal();
|
|
5708
|
+
init_observationTrend();
|
|
5648
5709
|
init_queryEntities();
|
|
5649
5710
|
init_queryTemporal();
|
|
5650
5711
|
init_rrf();
|
|
@@ -6240,6 +6301,7 @@ async function searchVaultMemoriesWithSize(query, vaultCtx, embeddingOptions, ca
|
|
|
6240
6301
|
createdAt: m.createdAt,
|
|
6241
6302
|
updatedAt: m.updatedAt,
|
|
6242
6303
|
proofCount: m.proofCount,
|
|
6304
|
+
lastObservedAt: m.lastObservedAt,
|
|
6243
6305
|
eventTimeStart: m.eventTimeStart,
|
|
6244
6306
|
sourceChunkIds: m.sourceChunkIds,
|
|
6245
6307
|
eventTimeEnd: m.eventTimeEnd,
|
|
@@ -6256,13 +6318,27 @@ async function searchVaultMemoriesWithSize(query, vaultCtx, embeddingOptions, ca
|
|
|
6256
6318
|
);
|
|
6257
6319
|
}
|
|
6258
6320
|
}
|
|
6259
|
-
const
|
|
6260
|
-
memories.map((m) => [
|
|
6321
|
+
const metaById = new Map(
|
|
6322
|
+
memories.map((m) => [
|
|
6323
|
+
m.uniqueId,
|
|
6324
|
+
{
|
|
6325
|
+
createdAt: m.createdAt,
|
|
6326
|
+
updatedAt: m.updatedAt,
|
|
6327
|
+
proofCount: m.proofCount,
|
|
6328
|
+
lastObservedAt: m.lastObservedAt
|
|
6329
|
+
}
|
|
6330
|
+
])
|
|
6261
6331
|
);
|
|
6262
6332
|
const stampTimestamps = (out) => {
|
|
6263
6333
|
const results2 = out.results.map((r) => {
|
|
6264
|
-
const
|
|
6265
|
-
return
|
|
6334
|
+
const meta = metaById.get(r.uniqueId);
|
|
6335
|
+
return meta ? {
|
|
6336
|
+
...r,
|
|
6337
|
+
createdAt: meta.createdAt,
|
|
6338
|
+
updatedAt: meta.updatedAt,
|
|
6339
|
+
proofCount: meta.proofCount,
|
|
6340
|
+
lastObservedAt: meta.lastObservedAt
|
|
6341
|
+
} : r;
|
|
6266
6342
|
});
|
|
6267
6343
|
return {
|
|
6268
6344
|
results: results2,
|
|
@@ -6704,6 +6780,8 @@ __export(index_exports, {
|
|
|
6704
6780
|
StreamExpiredError: () => StreamExpiredError,
|
|
6705
6781
|
TOPICS_EXTRACTION_VERSION: () => TOPICS_EXTRACTION_VERSION,
|
|
6706
6782
|
TOPIC_EXTRACTION_BATCH_SIZE: () => TOPIC_EXTRACTION_BATCH_SIZE,
|
|
6783
|
+
TREND_RECENT_WINDOW_DAYS: () => TREND_RECENT_WINDOW_DAYS,
|
|
6784
|
+
TREND_STALE_WINDOW_DAYS: () => TREND_STALE_WINDOW_DAYS,
|
|
6707
6785
|
VAULT_SIZE_HOP_CAP: () => VAULT_SIZE_HOP_CAP,
|
|
6708
6786
|
WalletPoller: () => WalletPoller,
|
|
6709
6787
|
addConversationMemoriesOp: () => addConversationMemoriesOp,
|
|
@@ -6719,6 +6797,7 @@ __export(index_exports, {
|
|
|
6719
6797
|
classifyCryptoPriceBatch: () => classifyCryptoPriceBatch,
|
|
6720
6798
|
classifyDecay: () => classifyDecay,
|
|
6721
6799
|
classifyInjectionCandidates: () => classifyInjectionCandidates,
|
|
6800
|
+
classifyObservationTrend: () => classifyObservationTrend,
|
|
6722
6801
|
classifyStockPrice: () => classifyStockPrice,
|
|
6723
6802
|
classifyStockPriceBatch: () => classifyStockPriceBatch,
|
|
6724
6803
|
classifyWeather: () => classifyWeather,
|
|
@@ -6818,6 +6897,7 @@ __export(index_exports, {
|
|
|
6818
6897
|
stampTopicsExtractedAtOp: () => stampTopicsExtractedAtOp,
|
|
6819
6898
|
streamCancelPath: () => streamCancelPath,
|
|
6820
6899
|
streamReplayPath: () => streamReplayPath,
|
|
6900
|
+
summarizeObservationTrends: () => summarizeObservationTrends,
|
|
6821
6901
|
supersedeVaultMemoryOp: () => supersedeVaultMemoryOp,
|
|
6822
6902
|
synthesizeProfile: () => synthesizeProfile,
|
|
6823
6903
|
traverseGraphLane: () => traverseGraphLane,
|
|
@@ -7022,7 +7102,7 @@ function createWebSearchPreProcessor(options = {}) {
|
|
|
7022
7102
|
init_clientConfig();
|
|
7023
7103
|
|
|
7024
7104
|
// src/client/core/serverSentEvents.gen.ts
|
|
7025
|
-
|
|
7105
|
+
function createSseClient({
|
|
7026
7106
|
onRequest,
|
|
7027
7107
|
onSseError,
|
|
7028
7108
|
onSseEvent,
|
|
@@ -7034,7 +7114,7 @@ var createSseClient = ({
|
|
|
7034
7114
|
sseSleepFn,
|
|
7035
7115
|
url,
|
|
7036
7116
|
...options
|
|
7037
|
-
})
|
|
7117
|
+
}) {
|
|
7038
7118
|
let lastEventId;
|
|
7039
7119
|
const sleep4 = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
7040
7120
|
const createStream = async function* () {
|
|
@@ -7062,10 +7142,7 @@ var createSseClient = ({
|
|
|
7062
7142
|
}
|
|
7063
7143
|
const _fetch = options.fetch ?? globalThis.fetch;
|
|
7064
7144
|
const response = await _fetch(request);
|
|
7065
|
-
if (!response.ok)
|
|
7066
|
-
throw new Error(
|
|
7067
|
-
`SSE failed: ${response.status} ${response.statusText}`
|
|
7068
|
-
);
|
|
7145
|
+
if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
|
|
7069
7146
|
if (!response.body) throw new Error("No body in SSE response");
|
|
7070
7147
|
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
|
|
7071
7148
|
let buffer = "";
|
|
@@ -7081,6 +7158,7 @@ var createSseClient = ({
|
|
|
7081
7158
|
const { done, value } = await reader.read();
|
|
7082
7159
|
if (done) break;
|
|
7083
7160
|
buffer += value;
|
|
7161
|
+
buffer = buffer.replace(/\r\n?/g, "\n");
|
|
7084
7162
|
const chunks = buffer.split("\n\n");
|
|
7085
7163
|
buffer = chunks.pop() ?? "";
|
|
7086
7164
|
for (const chunk of chunks) {
|
|
@@ -7095,10 +7173,7 @@ var createSseClient = ({
|
|
|
7095
7173
|
} else if (line.startsWith("id:")) {
|
|
7096
7174
|
lastEventId = line.replace(/^id:\s*/, "");
|
|
7097
7175
|
} else if (line.startsWith("retry:")) {
|
|
7098
|
-
const parsed = Number.parseInt(
|
|
7099
|
-
line.replace(/^retry:\s*/, ""),
|
|
7100
|
-
10
|
|
7101
|
-
);
|
|
7176
|
+
const parsed = Number.parseInt(line.replace(/^retry:\s*/, ""), 10);
|
|
7102
7177
|
if (!Number.isNaN(parsed)) {
|
|
7103
7178
|
retryDelay = parsed;
|
|
7104
7179
|
}
|
|
@@ -7144,17 +7219,14 @@ var createSseClient = ({
|
|
|
7144
7219
|
if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) {
|
|
7145
7220
|
break;
|
|
7146
7221
|
}
|
|
7147
|
-
const backoff = Math.min(
|
|
7148
|
-
retryDelay * 2 ** (attempt - 1),
|
|
7149
|
-
sseMaxRetryDelay ?? 3e4
|
|
7150
|
-
);
|
|
7222
|
+
const backoff = Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 3e4);
|
|
7151
7223
|
await sleep4(backoff);
|
|
7152
7224
|
}
|
|
7153
7225
|
}
|
|
7154
7226
|
};
|
|
7155
7227
|
const stream = createStream();
|
|
7156
7228
|
return { stream };
|
|
7157
|
-
}
|
|
7229
|
+
}
|
|
7158
7230
|
|
|
7159
7231
|
// src/lib/chat/toolLoop.ts
|
|
7160
7232
|
init_clientConfig();
|
|
@@ -10613,10 +10685,7 @@ var import_react = require("react");
|
|
|
10613
10685
|
|
|
10614
10686
|
// src/client/core/bodySerializer.gen.ts
|
|
10615
10687
|
var jsonBodySerializer = {
|
|
10616
|
-
bodySerializer: (body) => JSON.stringify(
|
|
10617
|
-
body,
|
|
10618
|
-
(_key, value) => typeof value === "bigint" ? value.toString() : value
|
|
10619
|
-
)
|
|
10688
|
+
bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value)
|
|
10620
10689
|
};
|
|
10621
10690
|
|
|
10622
10691
|
// src/client/core/pathSerializer.gen.ts
|
|
@@ -10718,11 +10787,7 @@ var serializeObjectParam = ({
|
|
|
10718
10787
|
if (style !== "deepObject" && !explode) {
|
|
10719
10788
|
let values = [];
|
|
10720
10789
|
Object.entries(value).forEach(([key, v]) => {
|
|
10721
|
-
values = [
|
|
10722
|
-
...values,
|
|
10723
|
-
key,
|
|
10724
|
-
allowReserved ? v : encodeURIComponent(v)
|
|
10725
|
-
];
|
|
10790
|
+
values = [...values, key, allowReserved ? v : encodeURIComponent(v)];
|
|
10726
10791
|
});
|
|
10727
10792
|
const joinedValues2 = values.join(",");
|
|
10728
10793
|
switch (style) {
|
|
@@ -10805,10 +10870,7 @@ var defaultPathSerializer = ({ path, url: _url }) => {
|
|
|
10805
10870
|
continue;
|
|
10806
10871
|
}
|
|
10807
10872
|
if (Array.isArray(value)) {
|
|
10808
|
-
url = url.replace(
|
|
10809
|
-
match,
|
|
10810
|
-
serializeArrayParam({ explode, name, style, value })
|
|
10811
|
-
);
|
|
10873
|
+
url = url.replace(match, serializeArrayParam({ explode, name, style, value }));
|
|
10812
10874
|
continue;
|
|
10813
10875
|
}
|
|
10814
10876
|
if (typeof value === "object") {
|
|
@@ -10903,9 +10965,7 @@ var getParseAs = (contentType) => {
|
|
|
10903
10965
|
if (cleanContent === "multipart/form-data") {
|
|
10904
10966
|
return "formData";
|
|
10905
10967
|
}
|
|
10906
|
-
if (["application/", "audio/", "image/", "video/"].some(
|
|
10907
|
-
(type) => cleanContent.startsWith(type)
|
|
10908
|
-
)) {
|
|
10968
|
+
if (["application/", "audio/", "image/", "video/"].some((type) => cleanContent.startsWith(type))) {
|
|
10909
10969
|
return "blob";
|
|
10910
10970
|
}
|
|
10911
10971
|
if (cleanContent.startsWith("text/")) {
|
|
@@ -10922,11 +10982,8 @@ var checkForExistence = (options, name) => {
|
|
|
10922
10982
|
}
|
|
10923
10983
|
return false;
|
|
10924
10984
|
};
|
|
10925
|
-
|
|
10926
|
-
security
|
|
10927
|
-
...options
|
|
10928
|
-
}) => {
|
|
10929
|
-
for (const auth of security) {
|
|
10985
|
+
async function setAuthParams(options) {
|
|
10986
|
+
for (const auth of options.security ?? []) {
|
|
10930
10987
|
if (checkForExistence(options, auth.name)) {
|
|
10931
10988
|
continue;
|
|
10932
10989
|
}
|
|
@@ -10951,7 +11008,7 @@ var setAuthParams = async ({
|
|
|
10951
11008
|
break;
|
|
10952
11009
|
}
|
|
10953
11010
|
}
|
|
10954
|
-
}
|
|
11011
|
+
}
|
|
10955
11012
|
var buildUrl = (options) => {
|
|
10956
11013
|
const url = getUrl({
|
|
10957
11014
|
baseUrl: options.baseUrl,
|
|
@@ -11103,10 +11160,7 @@ var createClient = (config = {}) => {
|
|
|
11103
11160
|
serializedBody: void 0
|
|
11104
11161
|
};
|
|
11105
11162
|
if (opts.security) {
|
|
11106
|
-
await setAuthParams(
|
|
11107
|
-
...opts,
|
|
11108
|
-
security: opts.security
|
|
11109
|
-
});
|
|
11163
|
+
await setAuthParams(opts);
|
|
11110
11164
|
}
|
|
11111
11165
|
if (opts.requestValidator) {
|
|
11112
11166
|
await opts.requestValidator(opts);
|
|
@@ -11117,105 +11171,115 @@ var createClient = (config = {}) => {
|
|
|
11117
11171
|
if (opts.body === void 0 || opts.serializedBody === "") {
|
|
11118
11172
|
opts.headers.delete("Content-Type");
|
|
11119
11173
|
}
|
|
11120
|
-
const
|
|
11121
|
-
|
|
11174
|
+
const resolvedOpts = opts;
|
|
11175
|
+
const url = buildUrl(resolvedOpts);
|
|
11176
|
+
return { opts: resolvedOpts, url };
|
|
11122
11177
|
};
|
|
11123
11178
|
const request = async (options) => {
|
|
11124
|
-
const
|
|
11125
|
-
|
|
11126
|
-
|
|
11127
|
-
|
|
11179
|
+
const throwOnError = options.throwOnError ?? _config.throwOnError;
|
|
11180
|
+
let response;
|
|
11181
|
+
try {
|
|
11182
|
+
const { opts, url } = await beforeRequest(options);
|
|
11183
|
+
for (const fn of interceptors.request.fns) {
|
|
11184
|
+
if (fn) {
|
|
11185
|
+
await fn(opts);
|
|
11186
|
+
}
|
|
11128
11187
|
}
|
|
11129
|
-
|
|
11130
|
-
|
|
11131
|
-
|
|
11132
|
-
|
|
11133
|
-
|
|
11134
|
-
|
|
11135
|
-
|
|
11136
|
-
|
|
11137
|
-
|
|
11138
|
-
|
|
11188
|
+
const _fetch = opts.fetch;
|
|
11189
|
+
const requestInit = {
|
|
11190
|
+
...opts,
|
|
11191
|
+
body: getValidRequestBody(opts)
|
|
11192
|
+
};
|
|
11193
|
+
response = await _fetch(url, requestInit);
|
|
11194
|
+
for (const fn of interceptors.response.fns) {
|
|
11195
|
+
if (fn) {
|
|
11196
|
+
response = await fn(response, opts);
|
|
11197
|
+
}
|
|
11139
11198
|
}
|
|
11140
|
-
|
|
11141
|
-
|
|
11142
|
-
|
|
11143
|
-
|
|
11144
|
-
|
|
11145
|
-
|
|
11146
|
-
|
|
11147
|
-
|
|
11199
|
+
const result = {
|
|
11200
|
+
response
|
|
11201
|
+
};
|
|
11202
|
+
if (response.ok) {
|
|
11203
|
+
const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
|
|
11204
|
+
if (response.status === 204 || response.headers.get("Content-Length") === "0") {
|
|
11205
|
+
let emptyData;
|
|
11206
|
+
switch (parseAs) {
|
|
11207
|
+
case "arrayBuffer":
|
|
11208
|
+
case "blob":
|
|
11209
|
+
case "text":
|
|
11210
|
+
emptyData = await response[parseAs]();
|
|
11211
|
+
break;
|
|
11212
|
+
case "formData":
|
|
11213
|
+
emptyData = new FormData();
|
|
11214
|
+
break;
|
|
11215
|
+
case "stream":
|
|
11216
|
+
emptyData = response.body;
|
|
11217
|
+
break;
|
|
11218
|
+
case "json":
|
|
11219
|
+
default:
|
|
11220
|
+
emptyData = {};
|
|
11221
|
+
break;
|
|
11222
|
+
}
|
|
11223
|
+
return {
|
|
11224
|
+
data: emptyData,
|
|
11225
|
+
...result
|
|
11226
|
+
};
|
|
11227
|
+
}
|
|
11228
|
+
let data;
|
|
11148
11229
|
switch (parseAs) {
|
|
11149
11230
|
case "arrayBuffer":
|
|
11150
11231
|
case "blob":
|
|
11232
|
+
case "formData":
|
|
11151
11233
|
case "text":
|
|
11152
|
-
|
|
11234
|
+
data = await response[parseAs]();
|
|
11153
11235
|
break;
|
|
11154
|
-
case "
|
|
11155
|
-
|
|
11236
|
+
case "json": {
|
|
11237
|
+
const text12 = await response.text();
|
|
11238
|
+
data = text12 ? JSON.parse(text12) : {};
|
|
11156
11239
|
break;
|
|
11240
|
+
}
|
|
11157
11241
|
case "stream":
|
|
11158
|
-
|
|
11159
|
-
|
|
11160
|
-
|
|
11161
|
-
|
|
11162
|
-
|
|
11163
|
-
|
|
11242
|
+
return {
|
|
11243
|
+
data: response.body,
|
|
11244
|
+
...result
|
|
11245
|
+
};
|
|
11246
|
+
}
|
|
11247
|
+
if (parseAs === "json") {
|
|
11248
|
+
if (opts.responseValidator) {
|
|
11249
|
+
await opts.responseValidator(data);
|
|
11250
|
+
}
|
|
11251
|
+
if (opts.responseTransformer) {
|
|
11252
|
+
data = await opts.responseTransformer(data);
|
|
11253
|
+
}
|
|
11164
11254
|
}
|
|
11165
11255
|
return {
|
|
11166
|
-
data
|
|
11256
|
+
data,
|
|
11167
11257
|
...result
|
|
11168
11258
|
};
|
|
11169
11259
|
}
|
|
11170
|
-
|
|
11171
|
-
|
|
11172
|
-
|
|
11173
|
-
|
|
11174
|
-
|
|
11175
|
-
case "json":
|
|
11176
|
-
case "text":
|
|
11177
|
-
data = await response[parseAs]();
|
|
11178
|
-
break;
|
|
11179
|
-
case "stream":
|
|
11180
|
-
return {
|
|
11181
|
-
data: response.body,
|
|
11182
|
-
...result
|
|
11183
|
-
};
|
|
11260
|
+
const textError = await response.text();
|
|
11261
|
+
let jsonError;
|
|
11262
|
+
try {
|
|
11263
|
+
jsonError = JSON.parse(textError);
|
|
11264
|
+
} catch {
|
|
11184
11265
|
}
|
|
11185
|
-
|
|
11186
|
-
|
|
11187
|
-
|
|
11188
|
-
|
|
11189
|
-
if (
|
|
11190
|
-
|
|
11266
|
+
throw jsonError ?? textError;
|
|
11267
|
+
} catch (error) {
|
|
11268
|
+
let finalError = error;
|
|
11269
|
+
for (const fn of interceptors.error.fns) {
|
|
11270
|
+
if (fn) {
|
|
11271
|
+
finalError = await fn(finalError, response, options);
|
|
11191
11272
|
}
|
|
11192
11273
|
}
|
|
11274
|
+
finalError = finalError || {};
|
|
11275
|
+
if (throwOnError) {
|
|
11276
|
+
throw finalError;
|
|
11277
|
+
}
|
|
11193
11278
|
return {
|
|
11194
|
-
|
|
11195
|
-
|
|
11279
|
+
error: finalError,
|
|
11280
|
+
response
|
|
11196
11281
|
};
|
|
11197
11282
|
}
|
|
11198
|
-
const textError = await response.text();
|
|
11199
|
-
let jsonError;
|
|
11200
|
-
try {
|
|
11201
|
-
jsonError = JSON.parse(textError);
|
|
11202
|
-
} catch {
|
|
11203
|
-
}
|
|
11204
|
-
const error = jsonError ?? textError;
|
|
11205
|
-
let finalError = error;
|
|
11206
|
-
for (const fn of interceptors.error.fns) {
|
|
11207
|
-
if (fn) {
|
|
11208
|
-
finalError = await fn(error, response, opts);
|
|
11209
|
-
}
|
|
11210
|
-
}
|
|
11211
|
-
finalError = finalError || {};
|
|
11212
|
-
if (opts.throwOnError) {
|
|
11213
|
-
throw finalError;
|
|
11214
|
-
}
|
|
11215
|
-
return {
|
|
11216
|
-
error: finalError,
|
|
11217
|
-
...result
|
|
11218
|
-
};
|
|
11219
11283
|
};
|
|
11220
11284
|
const makeMethodFn = (method) => (options) => request({ ...options, method });
|
|
11221
11285
|
const makeSseFn = (method) => async (options) => {
|
|
@@ -11223,15 +11287,10 @@ var createClient = (config = {}) => {
|
|
|
11223
11287
|
return createSseClient({
|
|
11224
11288
|
...opts,
|
|
11225
11289
|
body: opts.body,
|
|
11226
|
-
headers: opts.headers,
|
|
11227
11290
|
method,
|
|
11228
11291
|
onRequest: async (url2, init) => {
|
|
11229
11292
|
let request2 = new Request(url2, init);
|
|
11230
|
-
const requestInit = {
|
|
11231
|
-
...init,
|
|
11232
|
-
method: init.method,
|
|
11233
|
-
url: url2
|
|
11234
|
-
};
|
|
11293
|
+
const requestInit = { ...init, url: url2 };
|
|
11235
11294
|
for (const fn of interceptors.request.fns) {
|
|
11236
11295
|
if (fn) {
|
|
11237
11296
|
await fn(requestInit);
|
|
@@ -11240,11 +11299,13 @@ var createClient = (config = {}) => {
|
|
|
11240
11299
|
}
|
|
11241
11300
|
return request2;
|
|
11242
11301
|
},
|
|
11302
|
+
serializedBody: getValidRequestBody(opts),
|
|
11243
11303
|
url
|
|
11244
11304
|
});
|
|
11245
11305
|
};
|
|
11306
|
+
const _buildUrl = (options) => buildUrl({ ..._config, ...options });
|
|
11246
11307
|
return {
|
|
11247
|
-
buildUrl,
|
|
11308
|
+
buildUrl: _buildUrl,
|
|
11248
11309
|
connect: makeMethodFn("CONNECT"),
|
|
11249
11310
|
delete: makeMethodFn("DELETE"),
|
|
11250
11311
|
get: makeMethodFn("GET"),
|
|
@@ -11277,34 +11338,17 @@ init_clientConfig();
|
|
|
11277
11338
|
var client = createClient(createClientConfig(createConfig()));
|
|
11278
11339
|
|
|
11279
11340
|
// src/client/sdk.gen.ts
|
|
11280
|
-
var getApiV1CreditsBalance = (options) => {
|
|
11281
|
-
|
|
11282
|
-
|
|
11283
|
-
|
|
11284
|
-
|
|
11285
|
-
|
|
11286
|
-
|
|
11287
|
-
|
|
11288
|
-
|
|
11289
|
-
|
|
11290
|
-
|
|
11291
|
-
};
|
|
11292
|
-
var postApiV1CreditsPurchase = (options) => {
|
|
11293
|
-
return (options.client ?? client).post({
|
|
11294
|
-
url: "/api/v1/credits/purchase",
|
|
11295
|
-
...options,
|
|
11296
|
-
headers: {
|
|
11297
|
-
"Content-Type": "application/json",
|
|
11298
|
-
...options.headers
|
|
11299
|
-
}
|
|
11300
|
-
});
|
|
11301
|
-
};
|
|
11302
|
-
var getApiV1Models = (options) => {
|
|
11303
|
-
return (options?.client ?? client).get({
|
|
11304
|
-
url: "/api/v1/models",
|
|
11305
|
-
...options
|
|
11306
|
-
});
|
|
11307
|
-
};
|
|
11341
|
+
var getApiV1CreditsBalance = (options) => (options?.client ?? client).get({ url: "/api/v1/credits/balance", ...options });
|
|
11342
|
+
var getApiV1CreditsPacks = (options) => (options?.client ?? client).get({ url: "/api/v1/credits/packs", ...options });
|
|
11343
|
+
var postApiV1CreditsPurchase = (options) => (options.client ?? client).post({
|
|
11344
|
+
url: "/api/v1/credits/purchase",
|
|
11345
|
+
...options,
|
|
11346
|
+
headers: {
|
|
11347
|
+
"Content-Type": "application/json",
|
|
11348
|
+
...options.headers
|
|
11349
|
+
}
|
|
11350
|
+
});
|
|
11351
|
+
var getApiV1Models = (options) => (options?.client ?? client).get({ url: "/api/v1/models", ...options });
|
|
11308
11352
|
|
|
11309
11353
|
// src/react/useCredits.ts
|
|
11310
11354
|
init_clientConfig();
|
|
@@ -14736,12 +14780,12 @@ function createChunkVectorCache(maxSize = DEFAULT_CHUNK_CACHE_SIZE) {
|
|
|
14736
14780
|
|
|
14737
14781
|
// src/lib/memory/decay.ts
|
|
14738
14782
|
init_logger();
|
|
14739
|
-
var
|
|
14740
|
-
var SHORT_TTL_MS = 30 *
|
|
14741
|
-
var MEDIUM_TTL_MS = 180 *
|
|
14783
|
+
var DAY_MS3 = 24 * 60 * 60 * 1e3;
|
|
14784
|
+
var SHORT_TTL_MS = 30 * DAY_MS3;
|
|
14785
|
+
var MEDIUM_TTL_MS = 180 * DAY_MS3;
|
|
14742
14786
|
var NEVER_TTL_MS = Number.POSITIVE_INFINITY;
|
|
14743
|
-
var HARD_DELETE_WINDOW_MS = 30 *
|
|
14744
|
-
var PAST_EVENT_GRACE_MS = 7 *
|
|
14787
|
+
var HARD_DELETE_WINDOW_MS = 30 * DAY_MS3;
|
|
14788
|
+
var PAST_EVENT_GRACE_MS = 7 * DAY_MS3;
|
|
14745
14789
|
var DEFAULT_DECAY_POLICY = {
|
|
14746
14790
|
ttlByType: {
|
|
14747
14791
|
identity: NEVER_TTL_MS,
|
|
@@ -15001,6 +15045,7 @@ function createDecaySweeper(options) {
|
|
|
15001
15045
|
|
|
15002
15046
|
// src/lib/memory/index.ts
|
|
15003
15047
|
init_graphTraversal();
|
|
15048
|
+
init_observationTrend();
|
|
15004
15049
|
init_recall();
|
|
15005
15050
|
|
|
15006
15051
|
// src/lib/memory/recallTool.ts
|
|
@@ -15367,6 +15412,7 @@ init_logger();
|
|
|
15367
15412
|
init_constants();
|
|
15368
15413
|
init_embeddings();
|
|
15369
15414
|
init_vector();
|
|
15415
|
+
init_observationTrend();
|
|
15370
15416
|
var DEFAULT_SYNTHESIS_MODEL = "inclusionai/ling-2.6-flash";
|
|
15371
15417
|
var DEFAULT_FACET_RECALL_LIMIT = 20;
|
|
15372
15418
|
var DEFAULT_FACET_MAX_TOKENS = 512;
|
|
@@ -15452,6 +15498,13 @@ async function synthesizeProfile(ctx, options = {}) {
|
|
|
15452
15498
|
includeSuperseded: true
|
|
15453
15499
|
});
|
|
15454
15500
|
const watermark = computeVaultWatermark(memories);
|
|
15501
|
+
const observationTrends = summarizeObservationTrends(
|
|
15502
|
+
memories.filter((m) => !m.isDeleted && m.supersededBy === null).map((m) => ({
|
|
15503
|
+
createdAt: m.createdAt,
|
|
15504
|
+
lastObservedAt: m.lastObservedAt,
|
|
15505
|
+
proofCount: m.proofCount
|
|
15506
|
+
}))
|
|
15507
|
+
);
|
|
15455
15508
|
const presentIds = new Set(memories.map((m) => m.uniqueId));
|
|
15456
15509
|
const hasStaleSections = previous?.sections.some((s) => s.stale);
|
|
15457
15510
|
const citesMissingFact = previous?.sections.some(
|
|
@@ -15459,10 +15512,14 @@ async function synthesizeProfile(ctx, options = {}) {
|
|
|
15459
15512
|
);
|
|
15460
15513
|
if (previous && previous.vaultWatermark === watermark && !hasStaleSections && !citesMissingFact) {
|
|
15461
15514
|
const sameOrder = previous.sections.length === facets.length && facets.every((f, i) => previous.sections[i]?.key === f.key);
|
|
15462
|
-
if (sameOrder)
|
|
15515
|
+
if (sameOrder) {
|
|
15516
|
+
if (trendsEqual(previous.observationTrends, observationTrends)) return previous;
|
|
15517
|
+
return { ...previous, observationTrends };
|
|
15518
|
+
}
|
|
15463
15519
|
return {
|
|
15464
15520
|
...previous,
|
|
15465
|
-
sections: facets.map((f) => previous.sections.find((s) => s.key === f.key))
|
|
15521
|
+
sections: facets.map((f) => previous.sections.find((s) => s.key === f.key)),
|
|
15522
|
+
observationTrends
|
|
15466
15523
|
};
|
|
15467
15524
|
}
|
|
15468
15525
|
const staleKeys = await computeStaleFacetKeys(ctx, memories, facets, previous, watermark);
|
|
@@ -15495,6 +15552,7 @@ async function synthesizeProfile(ctx, options = {}) {
|
|
|
15495
15552
|
sections,
|
|
15496
15553
|
vaultWatermark: watermark,
|
|
15497
15554
|
config,
|
|
15555
|
+
observationTrends,
|
|
15498
15556
|
generatedAt: Date.now()
|
|
15499
15557
|
};
|
|
15500
15558
|
}
|
|
@@ -15505,6 +15563,10 @@ function configMatches(a, b) {
|
|
|
15505
15563
|
function facetsSignature(facets) {
|
|
15506
15564
|
return facets.map((f) => JSON.stringify([f.key, f.label, f.query, f.guidance])).sort().join("\n");
|
|
15507
15565
|
}
|
|
15566
|
+
function trendsEqual(a, b) {
|
|
15567
|
+
if (!a) return false;
|
|
15568
|
+
return a.new === b.new && a.strengthening === b.strengthening && a.stable === b.stable && a.weakening === b.weakening && a.stale === b.stale;
|
|
15569
|
+
}
|
|
15508
15570
|
function changeTime(m) {
|
|
15509
15571
|
return Math.max(m.updatedAt.getTime(), m.supersededAt ?? 0, m.lastObservedAt ?? 0);
|
|
15510
15572
|
}
|
|
@@ -21259,6 +21321,8 @@ function createNotionTools(getAccessToken, requestNotionAccess) {
|
|
|
21259
21321
|
StreamExpiredError,
|
|
21260
21322
|
TOPICS_EXTRACTION_VERSION,
|
|
21261
21323
|
TOPIC_EXTRACTION_BATCH_SIZE,
|
|
21324
|
+
TREND_RECENT_WINDOW_DAYS,
|
|
21325
|
+
TREND_STALE_WINDOW_DAYS,
|
|
21262
21326
|
VAULT_SIZE_HOP_CAP,
|
|
21263
21327
|
WalletPoller,
|
|
21264
21328
|
addConversationMemoriesOp,
|
|
@@ -21274,6 +21338,7 @@ function createNotionTools(getAccessToken, requestNotionAccess) {
|
|
|
21274
21338
|
classifyCryptoPriceBatch,
|
|
21275
21339
|
classifyDecay,
|
|
21276
21340
|
classifyInjectionCandidates,
|
|
21341
|
+
classifyObservationTrend,
|
|
21277
21342
|
classifyStockPrice,
|
|
21278
21343
|
classifyStockPriceBatch,
|
|
21279
21344
|
classifyWeather,
|
|
@@ -21373,6 +21438,7 @@ function createNotionTools(getAccessToken, requestNotionAccess) {
|
|
|
21373
21438
|
stampTopicsExtractedAtOp,
|
|
21374
21439
|
streamCancelPath,
|
|
21375
21440
|
streamReplayPath,
|
|
21441
|
+
summarizeObservationTrends,
|
|
21376
21442
|
supersedeVaultMemoryOp,
|
|
21377
21443
|
synthesizeProfile,
|
|
21378
21444
|
traverseGraphLane,
|