@anuma/sdk 6.21.0 → 6.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/expo/{chunk-CIMZZ7GQ.mjs → chunk-6BULYLRY.mjs} +92 -8
- package/dist/expo/index.cjs +776 -168
- package/dist/expo/index.d.mts +152 -11
- package/dist/expo/index.d.ts +152 -11
- package/dist/expo/index.mjs +531 -20
- package/dist/{react/recall-7Q3V337H.mjs → expo/recall-CUTJWQDQ.mjs} +1 -1
- package/dist/memory/context.cjs +183 -0
- package/dist/memory/context.d.mts +936 -0
- package/dist/memory/context.d.ts +936 -0
- package/dist/memory/context.mjs +157 -0
- package/dist/react/{chunk-AVYB5IXC.mjs → chunk-GPLMMMZN.mjs} +1 -1
- package/dist/react/{chunk-JRVAUZHM.mjs → chunk-K4N52PSK.mjs} +93 -9
- package/dist/react/{consolidate-URHGJT7I.mjs → consolidate-XKS6IZFC.mjs} +2 -2
- package/dist/react/index.cjs +891 -276
- package/dist/react/index.d.mts +210 -11
- package/dist/react/index.d.ts +210 -11
- package/dist/react/index.mjs +584 -71
- package/dist/{expo/recall-FQQGE6A2.mjs → react/recall-LFHIWONV.mjs} +2 -2
- package/dist/server/{chunk-4DSDATYG.mjs → chunk-FEDRFVHD.mjs} +182 -98
- package/dist/server/index.cjs +830 -222
- package/dist/server/index.d.mts +151 -7
- package/dist/server/index.d.ts +151 -7
- package/dist/server/index.mjs +524 -13
- package/dist/server/{recall-HA4UX4BB.mjs → recall-Z2WJGXOL.mjs} +1 -1
- package/dist/telemetry/index.d.mts +7 -1
- package/dist/telemetry/index.d.ts +7 -1
- package/package.json +8 -1
- package/dist/react/{chunk-WUG6GTHO.mjs → chunk-MHZB6KIX.mjs} +8 -8
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/lib/memory/context.ts
|
|
21
|
+
var context_exports = {};
|
|
22
|
+
__export(context_exports, {
|
|
23
|
+
assembleMemoryContext: () => assembleMemoryContext,
|
|
24
|
+
shouldRecallMemory: () => shouldRecallMemory
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(context_exports);
|
|
27
|
+
function shouldRecallMemory(query) {
|
|
28
|
+
const normalized = query.trim().toLowerCase().replace(/[.!?。!?¡¿]+$/u, "").replace(/^[¡¿]+/u, "");
|
|
29
|
+
return normalized.length > 0 && !/^(hi|hi there|hello|hey|yes|no|yep|nope|sure|k|ok|okay|thanks|thank you|thank you very much|thanks a lot|cool|great|got it|sounds good|hola|buenos días|buenas|sí|si|gracias|muchas gracias|vale|bonjour|salut|oui|non|merci|merci beaucoup|d'accord|hallo|guten tag|ja|nein|danke|danke schön|alles klar|olá|obrigado|obrigada|ciao|grazie|sì|你好|谢谢|好的|こんにちは|ありがとう|안녕하세요|감사합니다)$/u.test(
|
|
30
|
+
normalized
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
async function assembleMemoryContext(options) {
|
|
34
|
+
const { query, recall, loadFacts, loadSessionRefs } = options;
|
|
35
|
+
const memoryIds = options.memoryIds ?? options.recallOptions?.memoryIds;
|
|
36
|
+
const ranked = shouldRecallMemory(query);
|
|
37
|
+
const degraded = [];
|
|
38
|
+
const guard = async (lane, run, fallback) => {
|
|
39
|
+
try {
|
|
40
|
+
return await run();
|
|
41
|
+
} catch (error) {
|
|
42
|
+
degraded.push(lane);
|
|
43
|
+
try {
|
|
44
|
+
options.onDegraded?.(lane, error);
|
|
45
|
+
} catch {
|
|
46
|
+
}
|
|
47
|
+
return fallback;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const scoped = memoryIds !== void 0 || options.recallOptions?.scopes !== void 0 || options.recallOptions?.folderId !== void 0;
|
|
51
|
+
const allowed = memoryIds !== void 0 ? new Set(memoryIds) : void 0;
|
|
52
|
+
const filters = {
|
|
53
|
+
...options.recallOptions?.scopes && { scopes: options.recallOptions.scopes },
|
|
54
|
+
...options.recallOptions?.folderId !== void 0 && {
|
|
55
|
+
folderId: options.recallOptions.folderId
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const active = (m) => !m.isDeleted && !m.archivedAt && !m.supersededBy && m.trustTier !== "quarantined" && (!allowed || allowed.has(m.uniqueId));
|
|
59
|
+
const asItem = (m, lane, score = 1) => ({
|
|
60
|
+
id: m.uniqueId,
|
|
61
|
+
content: m.content,
|
|
62
|
+
score,
|
|
63
|
+
lane,
|
|
64
|
+
sourceIds: m.sourceChunkIds ?? []
|
|
65
|
+
});
|
|
66
|
+
const empty = {
|
|
67
|
+
memories: [],
|
|
68
|
+
usedBudget: options.recallOptions?.budget ?? "low",
|
|
69
|
+
reranked: false,
|
|
70
|
+
candidateCount: 0
|
|
71
|
+
};
|
|
72
|
+
const [facts, episodes, profile, session] = await Promise.all([
|
|
73
|
+
ranked ? guard(
|
|
74
|
+
"fact",
|
|
75
|
+
() => recall(query, { ...options.recallOptions, types: ["fact"], limit: 20, memoryIds }),
|
|
76
|
+
empty
|
|
77
|
+
) : empty,
|
|
78
|
+
ranked && !scoped && options.includeEpisodes !== false ? guard(
|
|
79
|
+
"episode",
|
|
80
|
+
() => recall(query, {
|
|
81
|
+
...options.recallOptions,
|
|
82
|
+
types: ["chunk"],
|
|
83
|
+
limit: 4,
|
|
84
|
+
minScore: 0.5,
|
|
85
|
+
onDiagnostics: void 0
|
|
86
|
+
}),
|
|
87
|
+
empty
|
|
88
|
+
) : empty,
|
|
89
|
+
loadFacts ? guard(
|
|
90
|
+
"profile",
|
|
91
|
+
async () => {
|
|
92
|
+
const stable = await loadFacts({
|
|
93
|
+
...filters,
|
|
94
|
+
memoryIds,
|
|
95
|
+
factTypes: ["identity", "preference", "constraint", "relationship"],
|
|
96
|
+
limit: 8
|
|
97
|
+
});
|
|
98
|
+
const dynamic = await loadFacts({
|
|
99
|
+
...filters,
|
|
100
|
+
memoryIds,
|
|
101
|
+
factTypes: ["ongoing_context", "plan"],
|
|
102
|
+
limit: 4
|
|
103
|
+
});
|
|
104
|
+
return [...stable, ...dynamic].filter(active).map((m) => asItem(m, "profile"));
|
|
105
|
+
},
|
|
106
|
+
[]
|
|
107
|
+
) : [],
|
|
108
|
+
loadFacts && loadSessionRefs ? guard(
|
|
109
|
+
"session",
|
|
110
|
+
async () => {
|
|
111
|
+
const refs = (await loadSessionRefs()).filter((r) => !allowed || allowed.has(r.memoryId)).sort((a, b) => b.score - a.score).slice(0, 10);
|
|
112
|
+
if (!refs.length) return [];
|
|
113
|
+
const rows = await loadFacts({ ...filters, memoryIds: refs.map((r) => r.memoryId) });
|
|
114
|
+
const byId = new Map(rows.filter(active).map((m) => [m.uniqueId, m]));
|
|
115
|
+
return refs.flatMap((ref) => {
|
|
116
|
+
const m = byId.get(ref.memoryId);
|
|
117
|
+
return m ? [asItem(m, "session", ref.score)] : [];
|
|
118
|
+
});
|
|
119
|
+
},
|
|
120
|
+
[]
|
|
121
|
+
) : []
|
|
122
|
+
]);
|
|
123
|
+
const toItems = (result, lane) => result.memories.filter((m) => !allowed || allowed.has(m.id)).map((m) => ({
|
|
124
|
+
id: m.id,
|
|
125
|
+
content: m.content,
|
|
126
|
+
score: m.score,
|
|
127
|
+
lane,
|
|
128
|
+
...lane === "fact" && { recalled: true },
|
|
129
|
+
sourceIds: m.sourceChunkIds ?? (m.messageId ? [m.messageId] : [])
|
|
130
|
+
}));
|
|
131
|
+
const recalledFacts = toItems(facts, "fact");
|
|
132
|
+
const recalledScores = /* @__PURE__ */ new Map();
|
|
133
|
+
const recalledContentScores = /* @__PURE__ */ new Map();
|
|
134
|
+
for (const item of recalledFacts) {
|
|
135
|
+
recalledScores.set(item.id, Math.max(recalledScores.get(item.id) ?? -Infinity, item.score));
|
|
136
|
+
const content = item.content.trim();
|
|
137
|
+
recalledContentScores.set(
|
|
138
|
+
content,
|
|
139
|
+
Math.max(recalledContentScores.get(content) ?? -Infinity, item.score)
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
const rankedProfile = profile.map((item) => {
|
|
143
|
+
const score = Math.max(
|
|
144
|
+
recalledScores.get(item.id) ?? -Infinity,
|
|
145
|
+
recalledContentScores.get(item.content.trim()) ?? -Infinity
|
|
146
|
+
);
|
|
147
|
+
return score === -Infinity ? item : { ...item, score, recalled: true };
|
|
148
|
+
});
|
|
149
|
+
const lanes = [
|
|
150
|
+
[rankedProfile, 2e3],
|
|
151
|
+
[recalledFacts, 6e3],
|
|
152
|
+
[toItems(episodes, "episode"), 3e3],
|
|
153
|
+
[session, 1e3]
|
|
154
|
+
];
|
|
155
|
+
const items = [];
|
|
156
|
+
const seenIds = /* @__PURE__ */ new Set();
|
|
157
|
+
const seenContent = /* @__PURE__ */ new Set();
|
|
158
|
+
let remaining = Math.max(0, options.maxChars ?? 12e3);
|
|
159
|
+
let truncated = false;
|
|
160
|
+
for (const [candidates, laneBudget] of lanes) {
|
|
161
|
+
let laneRemaining = Math.min(laneBudget, remaining);
|
|
162
|
+
for (const item of candidates) {
|
|
163
|
+
const content = item.content?.trim();
|
|
164
|
+
const key = `${item.lane === "episode" ? "episode" : "fact"}:${item.id}`;
|
|
165
|
+
if (!content || seenIds.has(key) || seenContent.has(content)) continue;
|
|
166
|
+
if (content.length > laneRemaining) {
|
|
167
|
+
truncated = true;
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
items.push({ ...item, content });
|
|
171
|
+
seenIds.add(key);
|
|
172
|
+
seenContent.add(content);
|
|
173
|
+
remaining -= content.length;
|
|
174
|
+
laneRemaining -= content.length;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return { items, ranked, rankedCount: recalledFacts.length, degraded, truncated };
|
|
178
|
+
}
|
|
179
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
180
|
+
0 && (module.exports = {
|
|
181
|
+
assembleMemoryContext,
|
|
182
|
+
shouldRecallMemory
|
|
183
|
+
});
|