@anuma/sdk 6.4.2 → 6.5.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-WYARTNEN.mjs → chunk-NCP3VGRX.mjs} +232 -7
- package/dist/expo/index.cjs +268 -153
- package/dist/expo/index.d.mts +163 -7
- package/dist/expo/index.d.ts +163 -7
- package/dist/expo/index.mjs +12 -148
- package/dist/expo/{recall-7FOWWX5T.mjs → recall-ISSI7RMD.mjs} +1 -1
- package/dist/index.cjs +71 -0
- package/dist/index.d.mts +121 -1
- package/dist/index.d.ts +121 -1
- package/dist/index.mjs +67 -0
- package/dist/react/{chunk-IO4ZCPK2.mjs → chunk-OB5HFCLB.mjs} +253 -7
- package/dist/react/index.cjs +293 -203
- package/dist/react/index.d.mts +163 -7
- package/dist/react/index.d.ts +163 -7
- package/dist/react/index.mjs +15 -196
- package/dist/react/{recall-2J2755WC.mjs → recall-DQJINKEY.mjs} +1 -1
- package/dist/server/{chunk-EKYGWD5N.mjs → chunk-BZEAYCBV.mjs} +97 -7
- package/dist/server/index.cjs +120 -45
- package/dist/server/index.d.mts +54 -6
- package/dist/server/index.d.ts +54 -6
- package/dist/server/index.mjs +3 -37
- package/dist/server/{recall-IVV6EILK.mjs → recall-CZFWWOVF.mjs} +1 -1
- package/package.json +1 -1
package/dist/expo/index.cjs
CHANGED
|
@@ -43,6 +43,166 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
43
43
|
return result;
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
+
// src/lib/chat/toolResultMessage.ts
|
|
47
|
+
function buildToolResultContent(results) {
|
|
48
|
+
const entries = results.map((r) => `Tool "${r.name}" returned: ${JSON.stringify(r.result)}`);
|
|
49
|
+
const framing = HEADER.length + FOOTER.length + ENTRY_SEPARATOR.length * Math.max(0, entries.length - 1);
|
|
50
|
+
const summary = capEntries(entries, MAX_PERSISTED_TOOL_RESULT_CHARS - framing).join(
|
|
51
|
+
ENTRY_SEPARATOR
|
|
52
|
+
);
|
|
53
|
+
return `${HEADER}${summary}${FOOTER}`;
|
|
54
|
+
}
|
|
55
|
+
function capToolResultEntries(entries, budget) {
|
|
56
|
+
return capEntries(entries, budget);
|
|
57
|
+
}
|
|
58
|
+
function capEntries(entries, budget) {
|
|
59
|
+
const smallestFirst = entries.map((_, index) => index).sort((a, b) => entries[a].length - entries[b].length);
|
|
60
|
+
const capped = [...entries];
|
|
61
|
+
let remaining = budget;
|
|
62
|
+
let unassigned = entries.length;
|
|
63
|
+
for (const index of smallestFirst) {
|
|
64
|
+
capped[index] = truncateEntry(entries[index], Math.floor(remaining / unassigned));
|
|
65
|
+
remaining -= capped[index].length;
|
|
66
|
+
unassigned--;
|
|
67
|
+
}
|
|
68
|
+
return capped;
|
|
69
|
+
}
|
|
70
|
+
function truncateEntry(entry, allowance) {
|
|
71
|
+
if (entry.length <= allowance) return entry;
|
|
72
|
+
const keep = allowance - truncationMarker(entry.length).length;
|
|
73
|
+
if (keep <= 0) return entry.slice(0, Math.max(0, allowance));
|
|
74
|
+
return `${entry.slice(0, keep)}${truncationMarker(entry.length - keep)}`;
|
|
75
|
+
}
|
|
76
|
+
function truncationMarker(omitted) {
|
|
77
|
+
return `
|
|
78
|
+
|
|
79
|
+
... (tool output truncated, ${omitted} characters omitted)`;
|
|
80
|
+
}
|
|
81
|
+
var HEADER, FOOTER, ENTRY_SEPARATOR, TOOL_RESULT_FOOTER_LINE, MAX_PERSISTED_TOOL_RESULT_CHARS;
|
|
82
|
+
var init_toolResultMessage = __esm({
|
|
83
|
+
"src/lib/chat/toolResultMessage.ts"() {
|
|
84
|
+
"use strict";
|
|
85
|
+
HEADER = "[Tool Execution Results]\n\n";
|
|
86
|
+
FOOTER = "\n\nBased on these results, continue with the task.";
|
|
87
|
+
ENTRY_SEPARATOR = "\n\n";
|
|
88
|
+
TOOL_RESULT_FOOTER_LINE = FOOTER.trim();
|
|
89
|
+
MAX_PERSISTED_TOOL_RESULT_CHARS = 1e5;
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// src/lib/chat/toolResults.ts
|
|
94
|
+
function isToolResultsRow(row) {
|
|
95
|
+
if (row.origin === TOOL_RESULT_ORIGIN) return true;
|
|
96
|
+
if (typeof row.origin === "string") return false;
|
|
97
|
+
if (row.role !== "user" || !row.content.startsWith(TOOL_RESULTS_PREFIX)) return false;
|
|
98
|
+
return parseToolResultSegments(row.content).length > 0;
|
|
99
|
+
}
|
|
100
|
+
function parseToolResultSegments(content) {
|
|
101
|
+
const segments = [];
|
|
102
|
+
for (const raw of content.split("\n")) {
|
|
103
|
+
const line = raw.trim();
|
|
104
|
+
const match = TOOL_LINE.exec(line);
|
|
105
|
+
if (match) {
|
|
106
|
+
segments.push({ name: match[1], line });
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
const current = segments[segments.length - 1];
|
|
110
|
+
if (!current || line === "" || line === TOOL_RESULT_FOOTER_LINE) continue;
|
|
111
|
+
if (line === TOOL_RESULTS_PREFIX) continue;
|
|
112
|
+
current.line = `${current.line}
|
|
113
|
+
${line}`;
|
|
114
|
+
}
|
|
115
|
+
return segments;
|
|
116
|
+
}
|
|
117
|
+
function prepareToolResultsForReplay(rows, options) {
|
|
118
|
+
if (options.fold) {
|
|
119
|
+
return foldToolResultsRows(rows, {
|
|
120
|
+
exclude: options.exclude,
|
|
121
|
+
placeholder: options.placeholder
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
return rows.filter((row) => !isToolResultsRow(row));
|
|
125
|
+
}
|
|
126
|
+
function foldToolResultsRows(rows, options) {
|
|
127
|
+
const exclude = new Set(options?.exclude ?? []);
|
|
128
|
+
const out = [];
|
|
129
|
+
const pending = [];
|
|
130
|
+
const assistantIndexById = /* @__PURE__ */ new Map();
|
|
131
|
+
for (const row of rows) {
|
|
132
|
+
if (isToolResultsRow(row)) {
|
|
133
|
+
pending.push({ row, insertionPoint: out.length });
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
out.push(row);
|
|
137
|
+
if (row.role === "assistant" && row.uniqueId) {
|
|
138
|
+
assistantIndexById.set(row.uniqueId, out.length - 1);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
const byTarget = /* @__PURE__ */ new Map();
|
|
142
|
+
for (const { row, insertionPoint } of pending) {
|
|
143
|
+
const target = resolveFoldTarget(out, row, insertionPoint, assistantIndexById);
|
|
144
|
+
if (target === void 0) continue;
|
|
145
|
+
const group = byTarget.get(target);
|
|
146
|
+
if (group) group.push(row);
|
|
147
|
+
else byTarget.set(target, [row]);
|
|
148
|
+
}
|
|
149
|
+
for (const [target, groupedRows] of byTarget) {
|
|
150
|
+
const assistant = out[target];
|
|
151
|
+
const kept = groupedRows.flatMap((row) => parseToolResultSegments(row.content)).filter((segment) => !exclude.has(segment.name));
|
|
152
|
+
if (kept.length > 0) {
|
|
153
|
+
out[target] = { ...assistant, content: appendToolResults(assistant.content, kept) };
|
|
154
|
+
} else if (!assistant.content.trim() && options?.placeholder) {
|
|
155
|
+
out[target] = { ...assistant, content: options.placeholder };
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return out;
|
|
159
|
+
}
|
|
160
|
+
function resolveFoldTarget(out, row, insertionPoint, assistantIndexById) {
|
|
161
|
+
const linked = row.parentMessageId ? assistantIndexById.get(row.parentMessageId) : void 0;
|
|
162
|
+
if (linked !== void 0) return linked;
|
|
163
|
+
let previous;
|
|
164
|
+
for (let i = insertionPoint - 1; i >= 0; i--) {
|
|
165
|
+
if (out[i].role === "assistant") {
|
|
166
|
+
previous = i;
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
let next;
|
|
171
|
+
for (let i = insertionPoint; i < out.length; i++) {
|
|
172
|
+
if (out[i].role === "assistant") {
|
|
173
|
+
next = i;
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
if (previous === void 0) return next;
|
|
178
|
+
if (next === void 0) return previous;
|
|
179
|
+
return next - insertionPoint < insertionPoint - previous ? next : previous;
|
|
180
|
+
}
|
|
181
|
+
function appendToolResults(assistantContent, kept) {
|
|
182
|
+
const framing = TOOL_RESULTS_PREFIX.length + 1 + (kept.length - 1);
|
|
183
|
+
const capped = capToolResultEntries(
|
|
184
|
+
kept.map((segment) => segment.line),
|
|
185
|
+
MAX_FOLDED_APPENDIX_CHARS - framing
|
|
186
|
+
);
|
|
187
|
+
const appendix = `${TOOL_RESULTS_PREFIX}
|
|
188
|
+
${capped.join("\n")}`;
|
|
189
|
+
return assistantContent.trim() ? `${assistantContent}
|
|
190
|
+
|
|
191
|
+
${appendix}` : appendix;
|
|
192
|
+
}
|
|
193
|
+
var TOOL_RESULTS_PREFIX, DISPLAY_CARD_PLACEHOLDER, TOOL_LINE, TOOL_RESULT_ORIGIN, MAX_FOLDED_APPENDIX_CHARS;
|
|
194
|
+
var init_toolResults = __esm({
|
|
195
|
+
"src/lib/chat/toolResults.ts"() {
|
|
196
|
+
"use strict";
|
|
197
|
+
init_toolResultMessage();
|
|
198
|
+
TOOL_RESULTS_PREFIX = "[Tool Execution Results]";
|
|
199
|
+
DISPLAY_CARD_PLACEHOLDER = "[displayed a card to the user with the tool result]";
|
|
200
|
+
TOOL_LINE = /^Tool "([^"]+)" returned: (.*)$/;
|
|
201
|
+
TOOL_RESULT_ORIGIN = "tool_result";
|
|
202
|
+
MAX_FOLDED_APPENDIX_CHARS = 2e4;
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
|
|
46
206
|
// src/lib/logger.ts
|
|
47
207
|
function setLogger(logger) {
|
|
48
208
|
currentLogger = logger;
|
|
@@ -885,6 +1045,76 @@ var init_vector = __esm({
|
|
|
885
1045
|
}
|
|
886
1046
|
});
|
|
887
1047
|
|
|
1048
|
+
// src/lib/processors/encoding.ts
|
|
1049
|
+
function uint8ArrayToBase64(data) {
|
|
1050
|
+
if (typeof Buffer !== "undefined") {
|
|
1051
|
+
return Buffer.from(data).toString("base64");
|
|
1052
|
+
}
|
|
1053
|
+
let base64 = "";
|
|
1054
|
+
for (let i = 0; i < data.length; i += B64_ENCODE_CHUNK) {
|
|
1055
|
+
const slice = data.subarray(i, i + B64_ENCODE_CHUNK);
|
|
1056
|
+
let binary = "";
|
|
1057
|
+
for (let j = 0; j < slice.length; j++) {
|
|
1058
|
+
binary += String.fromCharCode(slice[j]);
|
|
1059
|
+
}
|
|
1060
|
+
base64 += btoa(binary);
|
|
1061
|
+
}
|
|
1062
|
+
return base64;
|
|
1063
|
+
}
|
|
1064
|
+
function base64ToUint8Array(base64) {
|
|
1065
|
+
if (typeof Buffer !== "undefined") {
|
|
1066
|
+
const buf = Buffer.from(base64, "base64");
|
|
1067
|
+
return new Uint8Array(buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength));
|
|
1068
|
+
}
|
|
1069
|
+
const binary = atob(base64);
|
|
1070
|
+
const bytes = new Uint8Array(binary.length);
|
|
1071
|
+
for (let i = 0; i < binary.length; i++) {
|
|
1072
|
+
bytes[i] = binary.charCodeAt(i);
|
|
1073
|
+
}
|
|
1074
|
+
return bytes;
|
|
1075
|
+
}
|
|
1076
|
+
var B64_ENCODE_CHUNK;
|
|
1077
|
+
var init_encoding = __esm({
|
|
1078
|
+
"src/lib/processors/encoding.ts"() {
|
|
1079
|
+
"use strict";
|
|
1080
|
+
B64_ENCODE_CHUNK = 32768 * 3;
|
|
1081
|
+
}
|
|
1082
|
+
});
|
|
1083
|
+
|
|
1084
|
+
// src/lib/memoryEngine/vectorEncoding.ts
|
|
1085
|
+
function encodeChunkVector(vector) {
|
|
1086
|
+
const f32 = vector instanceof Float32Array ? vector : Float32Array.from(vector);
|
|
1087
|
+
return uint8ArrayToBase64(new Uint8Array(f32.buffer, f32.byteOffset, f32.byteLength));
|
|
1088
|
+
}
|
|
1089
|
+
function decodeChunkVector(vector, onMalformed) {
|
|
1090
|
+
if (!vector || vector.length === 0) return new Float32Array(0);
|
|
1091
|
+
if (typeof vector !== "string") return Float32Array.from(vector);
|
|
1092
|
+
if (vector.length % 4 !== 0 || !CANONICAL_BASE64.test(vector)) {
|
|
1093
|
+
onMalformed?.();
|
|
1094
|
+
return new Float32Array(0);
|
|
1095
|
+
}
|
|
1096
|
+
try {
|
|
1097
|
+
const bytes = base64ToUint8Array(vector);
|
|
1098
|
+
if (bytes.byteLength === 0 || bytes.byteLength % BYTES_PER_FLOAT32 !== 0) {
|
|
1099
|
+
onMalformed?.();
|
|
1100
|
+
return new Float32Array(0);
|
|
1101
|
+
}
|
|
1102
|
+
return new Float32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / BYTES_PER_FLOAT32);
|
|
1103
|
+
} catch {
|
|
1104
|
+
onMalformed?.();
|
|
1105
|
+
return new Float32Array(0);
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
var BYTES_PER_FLOAT32, CANONICAL_BASE64;
|
|
1109
|
+
var init_vectorEncoding = __esm({
|
|
1110
|
+
"src/lib/memoryEngine/vectorEncoding.ts"() {
|
|
1111
|
+
"use strict";
|
|
1112
|
+
init_encoding();
|
|
1113
|
+
BYTES_PER_FLOAT32 = 4;
|
|
1114
|
+
CANONICAL_BASE64 = /^[A-Za-z0-9+/]+={0,2}$/;
|
|
1115
|
+
}
|
|
1116
|
+
});
|
|
1117
|
+
|
|
888
1118
|
// src/lib/db/encryption-utils.ts
|
|
889
1119
|
function isEncrypted(value) {
|
|
890
1120
|
const prefix = value.startsWith("enc:v3:") ? "enc:v3:" : value.startsWith("enc:v2:") ? "enc:v2:" : null;
|
|
@@ -1989,6 +2219,7 @@ async function searchChunksOp(ctx, queryVector, options) {
|
|
|
1989
2219
|
const messages = await ctx.messagesCollection.query(...queryConditions).fetch();
|
|
1990
2220
|
const candidates = [];
|
|
1991
2221
|
let staleSkipped = 0;
|
|
2222
|
+
let unreadableVectors = 0;
|
|
1992
2223
|
for (const message of messages) {
|
|
1993
2224
|
const msgConvId = String(message._getRaw("conversation_id"));
|
|
1994
2225
|
if (!activeConversationIds.has(msgConvId)) continue;
|
|
@@ -2026,7 +2257,9 @@ async function searchChunksOp(ctx, queryVector, options) {
|
|
|
2026
2257
|
const chunks = await readJsonField(message, "chunks", ctx.walletAddress);
|
|
2027
2258
|
if (chunks && chunks.length > 0) {
|
|
2028
2259
|
const vectors = chunks.map(
|
|
2029
|
-
(chunk) => chunk.vector
|
|
2260
|
+
(chunk) => decodeChunkVector(chunk.vector, () => {
|
|
2261
|
+
unreadableVectors++;
|
|
2262
|
+
})
|
|
2030
2263
|
);
|
|
2031
2264
|
chunkCache?.set(message.id, { version, chunks: vectors });
|
|
2032
2265
|
for (let ci = 0; ci < chunks.length; ci++) {
|
|
@@ -2057,6 +2290,11 @@ async function searchChunksOp(ctx, queryVector, options) {
|
|
|
2057
2290
|
`searchChunksOp: skipped ${staleSkipped} messages whose embedding model differs from the current model (${embeddingModel}) \u2014 re-embed via chunkAndEmbedAllMessages`
|
|
2058
2291
|
);
|
|
2059
2292
|
}
|
|
2293
|
+
if (unreadableVectors > 0) {
|
|
2294
|
+
getLogger().warn(
|
|
2295
|
+
`searchChunksOp: could not read ${unreadableVectors} chunk vectors and left them out of ranking \u2014 the stored value is corrupt, so those chunks stay unsearchable until the message is re-embedded via chunkAndEmbedAllMessages`
|
|
2296
|
+
);
|
|
2297
|
+
}
|
|
2060
2298
|
const topK = candidates.sort((a, b) => b.similarity - a.similarity).slice(0, limit);
|
|
2061
2299
|
const uniqueMessages = /* @__PURE__ */ new Map();
|
|
2062
2300
|
for (const c of topK) uniqueMessages.set(c.message.id, c.message);
|
|
@@ -2150,6 +2388,7 @@ var init_operations = __esm({
|
|
|
2150
2388
|
init_useEncryption();
|
|
2151
2389
|
init_logger();
|
|
2152
2390
|
init_vector();
|
|
2391
|
+
init_vectorEncoding();
|
|
2153
2392
|
init_encryption_utils();
|
|
2154
2393
|
init_conversationEncryption();
|
|
2155
2394
|
init_encryption();
|
|
@@ -3426,6 +3665,11 @@ var init_generate = __esm({
|
|
|
3426
3665
|
});
|
|
3427
3666
|
|
|
3428
3667
|
// src/lib/memoryEngine/embeddings.ts
|
|
3668
|
+
function isNonEmbeddableOrigin(origin, reembedDiscarded = false) {
|
|
3669
|
+
if (typeof origin !== "string") return false;
|
|
3670
|
+
if (reembedDiscarded && origin === CHUNKS_DISCARDED_ORIGIN) return false;
|
|
3671
|
+
return NON_EMBEDDABLE_ORIGINS.has(origin);
|
|
3672
|
+
}
|
|
3429
3673
|
async function embedMessage(ctx, messageId, options) {
|
|
3430
3674
|
const message = await getMessageOp(ctx, messageId);
|
|
3431
3675
|
if (!message) {
|
|
@@ -3434,7 +3678,7 @@ async function embedMessage(ctx, messageId, options) {
|
|
|
3434
3678
|
if (message.vector && message.vector.length > 0) {
|
|
3435
3679
|
return message;
|
|
3436
3680
|
}
|
|
3437
|
-
if (message.origin
|
|
3681
|
+
if (isNonEmbeddableOrigin(message.origin)) {
|
|
3438
3682
|
return message;
|
|
3439
3683
|
}
|
|
3440
3684
|
if (isEncrypted(message.content)) {
|
|
@@ -3470,7 +3714,7 @@ async function embedAllMessages(ctx, options, filter) {
|
|
|
3470
3714
|
if (message.role === "system") {
|
|
3471
3715
|
continue;
|
|
3472
3716
|
}
|
|
3473
|
-
if (message.origin
|
|
3717
|
+
if (isNonEmbeddableOrigin(message.origin, filter?.reembedDiscarded)) {
|
|
3474
3718
|
continue;
|
|
3475
3719
|
}
|
|
3476
3720
|
considered++;
|
|
@@ -3510,7 +3754,7 @@ async function chunkAndEmbedMessage(ctx, messageId, options) {
|
|
|
3510
3754
|
if (message.chunks && message.chunks.length > 0) {
|
|
3511
3755
|
return message;
|
|
3512
3756
|
}
|
|
3513
|
-
if (message.origin
|
|
3757
|
+
if (isNonEmbeddableOrigin(message.origin)) {
|
|
3514
3758
|
return message;
|
|
3515
3759
|
}
|
|
3516
3760
|
if (isEncrypted(message.content)) {
|
|
@@ -3558,7 +3802,7 @@ async function chunkAndEmbedAllMessages(ctx, options, filter) {
|
|
|
3558
3802
|
if (hasVector && !filter?.rechunkExisting && !isStale) continue;
|
|
3559
3803
|
if (filter?.roles && !filter.roles.includes(message.role)) continue;
|
|
3560
3804
|
if (message.role === "system") continue;
|
|
3561
|
-
if (message.origin
|
|
3805
|
+
if (isNonEmbeddableOrigin(message.origin, filter?.reembedDiscarded)) continue;
|
|
3562
3806
|
considered++;
|
|
3563
3807
|
if (isEncrypted(message.content)) {
|
|
3564
3808
|
stillEncrypted++;
|
|
@@ -3627,10 +3871,11 @@ async function chunkAndEmbedAllMessages(ctx, options, filter) {
|
|
|
3627
3871
|
}
|
|
3628
3872
|
return embeddedCount;
|
|
3629
3873
|
}
|
|
3630
|
-
var DEFAULT_MIN_CONTENT_LENGTH,
|
|
3874
|
+
var DEFAULT_MIN_CONTENT_LENGTH, CHUNKS_DISCARDED_ORIGIN, NON_EMBEDDABLE_ORIGINS;
|
|
3631
3875
|
var init_embeddings = __esm({
|
|
3632
3876
|
"src/lib/memoryEngine/embeddings.ts"() {
|
|
3633
3877
|
"use strict";
|
|
3878
|
+
init_toolResults();
|
|
3634
3879
|
init_operations();
|
|
3635
3880
|
init_encryption_utils();
|
|
3636
3881
|
init_logger();
|
|
@@ -3639,7 +3884,8 @@ var init_embeddings = __esm({
|
|
|
3639
3884
|
init_generate();
|
|
3640
3885
|
init_generate();
|
|
3641
3886
|
DEFAULT_MIN_CONTENT_LENGTH = 10;
|
|
3642
|
-
|
|
3887
|
+
CHUNKS_DISCARDED_ORIGIN = "chunks_discarded";
|
|
3888
|
+
NON_EMBEDDABLE_ORIGINS = /* @__PURE__ */ new Set([TOOL_RESULT_ORIGIN, CHUNKS_DISCARDED_ORIGIN]);
|
|
3643
3889
|
}
|
|
3644
3890
|
});
|
|
3645
3891
|
|
|
@@ -9073,6 +9319,7 @@ For "noop": no content (existing memory is already correct); targetId is that me
|
|
|
9073
9319
|
// src/expo/index.ts
|
|
9074
9320
|
var index_exports = {};
|
|
9075
9321
|
__export(index_exports, {
|
|
9322
|
+
CHUNKS_DISCARDED_ORIGIN: () => CHUNKS_DISCARDED_ORIGIN,
|
|
9076
9323
|
ChatConversation: () => Conversation,
|
|
9077
9324
|
ChatMessage: () => Message,
|
|
9078
9325
|
ConversationMemoryModel: () => ConversationMemory,
|
|
@@ -9113,6 +9360,7 @@ __export(index_exports, {
|
|
|
9113
9360
|
StoredVaultFolderModel: () => VaultFolder,
|
|
9114
9361
|
StoredVaultMemoryModel: () => VaultMemory,
|
|
9115
9362
|
StreamExpiredError: () => StreamExpiredError,
|
|
9363
|
+
TOOL_RESULT_ORIGIN: () => TOOL_RESULT_ORIGIN,
|
|
9116
9364
|
TOPICS_EXTRACTION_VERSION: () => TOPICS_EXTRACTION_VERSION,
|
|
9117
9365
|
TOPIC_EXTRACTION_BATCH_SIZE: () => TOPIC_EXTRACTION_BATCH_SIZE,
|
|
9118
9366
|
TREND_RECENT_WINDOW_DAYS: () => TREND_RECENT_WINDOW_DAYS,
|
|
@@ -9170,6 +9418,7 @@ __export(index_exports, {
|
|
|
9170
9418
|
createVaultMemoryOp: () => createVaultMemoryOp,
|
|
9171
9419
|
createWeatherPreProcessor: () => createWeatherPreProcessor,
|
|
9172
9420
|
createWebSearchPreProcessor: () => createWebSearchPreProcessor,
|
|
9421
|
+
decodeChunkVector: () => decodeChunkVector,
|
|
9173
9422
|
decryptConversationTitle: () => decryptConversationTitle,
|
|
9174
9423
|
deleteAllVaultMemoriesForUserOp: () => deleteAllVaultMemoriesForUserOp,
|
|
9175
9424
|
deleteVaultFolderOp: () => deleteVaultFolderOp,
|
|
@@ -9179,6 +9428,7 @@ __export(index_exports, {
|
|
|
9179
9428
|
eagerEmbedContent: () => eagerEmbedContent,
|
|
9180
9429
|
embedAllMessages: () => embedAllMessages,
|
|
9181
9430
|
embedMessage: () => embedMessage,
|
|
9431
|
+
encodeChunkVector: () => encodeChunkVector,
|
|
9182
9432
|
ensureDefaultFoldersOp: () => ensureDefaultFoldersOp,
|
|
9183
9433
|
exchangeNotionCode: () => exchangeNotionCode,
|
|
9184
9434
|
extractAndLinkEntitiesForMemoriesOp: () => extractAndLinkEntitiesForMemoriesOp,
|
|
@@ -14141,152 +14391,9 @@ async function cleanupConversationSummary(database, conversationId) {
|
|
|
14141
14391
|
}
|
|
14142
14392
|
}
|
|
14143
14393
|
|
|
14144
|
-
// src/
|
|
14145
|
-
|
|
14146
|
-
|
|
14147
|
-
var ENTRY_SEPARATOR = "\n\n";
|
|
14148
|
-
var TOOL_RESULT_FOOTER_LINE = FOOTER.trim();
|
|
14149
|
-
var MAX_PERSISTED_TOOL_RESULT_CHARS = 1e5;
|
|
14150
|
-
function buildToolResultContent(results) {
|
|
14151
|
-
const entries = results.map((r) => `Tool "${r.name}" returned: ${JSON.stringify(r.result)}`);
|
|
14152
|
-
const framing = HEADER.length + FOOTER.length + ENTRY_SEPARATOR.length * Math.max(0, entries.length - 1);
|
|
14153
|
-
const summary = capEntries(entries, MAX_PERSISTED_TOOL_RESULT_CHARS - framing).join(
|
|
14154
|
-
ENTRY_SEPARATOR
|
|
14155
|
-
);
|
|
14156
|
-
return `${HEADER}${summary}${FOOTER}`;
|
|
14157
|
-
}
|
|
14158
|
-
function capToolResultEntries(entries, budget) {
|
|
14159
|
-
return capEntries(entries, budget);
|
|
14160
|
-
}
|
|
14161
|
-
function capEntries(entries, budget) {
|
|
14162
|
-
const smallestFirst = entries.map((_, index) => index).sort((a, b) => entries[a].length - entries[b].length);
|
|
14163
|
-
const capped = [...entries];
|
|
14164
|
-
let remaining = budget;
|
|
14165
|
-
let unassigned = entries.length;
|
|
14166
|
-
for (const index of smallestFirst) {
|
|
14167
|
-
capped[index] = truncateEntry(entries[index], Math.floor(remaining / unassigned));
|
|
14168
|
-
remaining -= capped[index].length;
|
|
14169
|
-
unassigned--;
|
|
14170
|
-
}
|
|
14171
|
-
return capped;
|
|
14172
|
-
}
|
|
14173
|
-
function truncateEntry(entry, allowance) {
|
|
14174
|
-
if (entry.length <= allowance) return entry;
|
|
14175
|
-
const keep = allowance - truncationMarker(entry.length).length;
|
|
14176
|
-
if (keep <= 0) return entry.slice(0, Math.max(0, allowance));
|
|
14177
|
-
return `${entry.slice(0, keep)}${truncationMarker(entry.length - keep)}`;
|
|
14178
|
-
}
|
|
14179
|
-
function truncationMarker(omitted) {
|
|
14180
|
-
return `
|
|
14181
|
-
|
|
14182
|
-
... (tool output truncated, ${omitted} characters omitted)`;
|
|
14183
|
-
}
|
|
14184
|
-
|
|
14185
|
-
// src/lib/chat/toolResults.ts
|
|
14186
|
-
var TOOL_RESULTS_PREFIX = "[Tool Execution Results]";
|
|
14187
|
-
var DISPLAY_CARD_PLACEHOLDER = "[displayed a card to the user with the tool result]";
|
|
14188
|
-
var TOOL_LINE = /^Tool "([^"]+)" returned: (.*)$/;
|
|
14189
|
-
var TOOL_RESULT_ORIGIN = "tool_result";
|
|
14190
|
-
function isToolResultsRow(row) {
|
|
14191
|
-
if (row.origin === TOOL_RESULT_ORIGIN) return true;
|
|
14192
|
-
if (typeof row.origin === "string") return false;
|
|
14193
|
-
if (row.role !== "user" || !row.content.startsWith(TOOL_RESULTS_PREFIX)) return false;
|
|
14194
|
-
return parseToolResultSegments(row.content).length > 0;
|
|
14195
|
-
}
|
|
14196
|
-
function parseToolResultSegments(content) {
|
|
14197
|
-
const segments = [];
|
|
14198
|
-
for (const raw of content.split("\n")) {
|
|
14199
|
-
const line = raw.trim();
|
|
14200
|
-
const match = TOOL_LINE.exec(line);
|
|
14201
|
-
if (match) {
|
|
14202
|
-
segments.push({ name: match[1], line });
|
|
14203
|
-
continue;
|
|
14204
|
-
}
|
|
14205
|
-
const current = segments[segments.length - 1];
|
|
14206
|
-
if (!current || line === "" || line === TOOL_RESULT_FOOTER_LINE) continue;
|
|
14207
|
-
if (line === TOOL_RESULTS_PREFIX) continue;
|
|
14208
|
-
current.line = `${current.line}
|
|
14209
|
-
${line}`;
|
|
14210
|
-
}
|
|
14211
|
-
return segments;
|
|
14212
|
-
}
|
|
14213
|
-
function prepareToolResultsForReplay(rows, options) {
|
|
14214
|
-
if (options.fold) {
|
|
14215
|
-
return foldToolResultsRows(rows, {
|
|
14216
|
-
exclude: options.exclude,
|
|
14217
|
-
placeholder: options.placeholder
|
|
14218
|
-
});
|
|
14219
|
-
}
|
|
14220
|
-
return rows.filter((row) => !isToolResultsRow(row));
|
|
14221
|
-
}
|
|
14222
|
-
function foldToolResultsRows(rows, options) {
|
|
14223
|
-
const exclude = new Set(options?.exclude ?? []);
|
|
14224
|
-
const out = [];
|
|
14225
|
-
const pending = [];
|
|
14226
|
-
const assistantIndexById = /* @__PURE__ */ new Map();
|
|
14227
|
-
for (const row of rows) {
|
|
14228
|
-
if (isToolResultsRow(row)) {
|
|
14229
|
-
pending.push({ row, insertionPoint: out.length });
|
|
14230
|
-
continue;
|
|
14231
|
-
}
|
|
14232
|
-
out.push(row);
|
|
14233
|
-
if (row.role === "assistant" && row.uniqueId) {
|
|
14234
|
-
assistantIndexById.set(row.uniqueId, out.length - 1);
|
|
14235
|
-
}
|
|
14236
|
-
}
|
|
14237
|
-
const byTarget = /* @__PURE__ */ new Map();
|
|
14238
|
-
for (const { row, insertionPoint } of pending) {
|
|
14239
|
-
const target = resolveFoldTarget(out, row, insertionPoint, assistantIndexById);
|
|
14240
|
-
if (target === void 0) continue;
|
|
14241
|
-
const group = byTarget.get(target);
|
|
14242
|
-
if (group) group.push(row);
|
|
14243
|
-
else byTarget.set(target, [row]);
|
|
14244
|
-
}
|
|
14245
|
-
for (const [target, groupedRows] of byTarget) {
|
|
14246
|
-
const assistant = out[target];
|
|
14247
|
-
const kept = groupedRows.flatMap((row) => parseToolResultSegments(row.content)).filter((segment) => !exclude.has(segment.name));
|
|
14248
|
-
if (kept.length > 0) {
|
|
14249
|
-
out[target] = { ...assistant, content: appendToolResults(assistant.content, kept) };
|
|
14250
|
-
} else if (!assistant.content.trim() && options?.placeholder) {
|
|
14251
|
-
out[target] = { ...assistant, content: options.placeholder };
|
|
14252
|
-
}
|
|
14253
|
-
}
|
|
14254
|
-
return out;
|
|
14255
|
-
}
|
|
14256
|
-
function resolveFoldTarget(out, row, insertionPoint, assistantIndexById) {
|
|
14257
|
-
const linked = row.parentMessageId ? assistantIndexById.get(row.parentMessageId) : void 0;
|
|
14258
|
-
if (linked !== void 0) return linked;
|
|
14259
|
-
let previous;
|
|
14260
|
-
for (let i = insertionPoint - 1; i >= 0; i--) {
|
|
14261
|
-
if (out[i].role === "assistant") {
|
|
14262
|
-
previous = i;
|
|
14263
|
-
break;
|
|
14264
|
-
}
|
|
14265
|
-
}
|
|
14266
|
-
let next;
|
|
14267
|
-
for (let i = insertionPoint; i < out.length; i++) {
|
|
14268
|
-
if (out[i].role === "assistant") {
|
|
14269
|
-
next = i;
|
|
14270
|
-
break;
|
|
14271
|
-
}
|
|
14272
|
-
}
|
|
14273
|
-
if (previous === void 0) return next;
|
|
14274
|
-
if (next === void 0) return previous;
|
|
14275
|
-
return next - insertionPoint < insertionPoint - previous ? next : previous;
|
|
14276
|
-
}
|
|
14277
|
-
var MAX_FOLDED_APPENDIX_CHARS = 2e4;
|
|
14278
|
-
function appendToolResults(assistantContent, kept) {
|
|
14279
|
-
const framing = TOOL_RESULTS_PREFIX.length + 1 + (kept.length - 1);
|
|
14280
|
-
const capped = capToolResultEntries(
|
|
14281
|
-
kept.map((segment) => segment.line),
|
|
14282
|
-
MAX_FOLDED_APPENDIX_CHARS - framing
|
|
14283
|
-
);
|
|
14284
|
-
const appendix = `${TOOL_RESULTS_PREFIX}
|
|
14285
|
-
${capped.join("\n")}`;
|
|
14286
|
-
return assistantContent.trim() ? `${assistantContent}
|
|
14287
|
-
|
|
14288
|
-
${appendix}` : appendix;
|
|
14289
|
-
}
|
|
14394
|
+
// src/expo/useChatStorage.ts
|
|
14395
|
+
init_toolResultMessage();
|
|
14396
|
+
init_toolResults();
|
|
14290
14397
|
|
|
14291
14398
|
// src/lib/db/chat/lazyDecrypt.ts
|
|
14292
14399
|
init_useEncryption();
|
|
@@ -18722,6 +18829,9 @@ function createMemoryEngineTool(storageCtx, embeddingOptions, searchOptions, cal
|
|
|
18722
18829
|
};
|
|
18723
18830
|
}
|
|
18724
18831
|
|
|
18832
|
+
// src/lib/memoryEngine/index.ts
|
|
18833
|
+
init_vectorEncoding();
|
|
18834
|
+
|
|
18725
18835
|
// src/expo/useChatStorage.ts
|
|
18726
18836
|
init_constants();
|
|
18727
18837
|
|
|
@@ -23208,6 +23318,7 @@ async function _ensureDefaultFoldersImpl(ctx) {
|
|
|
23208
23318
|
}
|
|
23209
23319
|
|
|
23210
23320
|
// src/expo/index.ts
|
|
23321
|
+
init_toolResults();
|
|
23211
23322
|
init_logger();
|
|
23212
23323
|
|
|
23213
23324
|
// src/react/LoggerProvider.tsx
|
|
@@ -24128,6 +24239,7 @@ function createNotionTools(getAccessToken, requestNotionAccess) {
|
|
|
24128
24239
|
}
|
|
24129
24240
|
// Annotate the CommonJS export names for ESM import in node:
|
|
24130
24241
|
0 && (module.exports = {
|
|
24242
|
+
CHUNKS_DISCARDED_ORIGIN,
|
|
24131
24243
|
ChatConversation,
|
|
24132
24244
|
ChatMessage,
|
|
24133
24245
|
ConversationMemoryModel,
|
|
@@ -24168,6 +24280,7 @@ function createNotionTools(getAccessToken, requestNotionAccess) {
|
|
|
24168
24280
|
StoredVaultFolderModel,
|
|
24169
24281
|
StoredVaultMemoryModel,
|
|
24170
24282
|
StreamExpiredError,
|
|
24283
|
+
TOOL_RESULT_ORIGIN,
|
|
24171
24284
|
TOPICS_EXTRACTION_VERSION,
|
|
24172
24285
|
TOPIC_EXTRACTION_BATCH_SIZE,
|
|
24173
24286
|
TREND_RECENT_WINDOW_DAYS,
|
|
@@ -24225,6 +24338,7 @@ function createNotionTools(getAccessToken, requestNotionAccess) {
|
|
|
24225
24338
|
createVaultMemoryOp,
|
|
24226
24339
|
createWeatherPreProcessor,
|
|
24227
24340
|
createWebSearchPreProcessor,
|
|
24341
|
+
decodeChunkVector,
|
|
24228
24342
|
decryptConversationTitle,
|
|
24229
24343
|
deleteAllVaultMemoriesForUserOp,
|
|
24230
24344
|
deleteVaultFolderOp,
|
|
@@ -24234,6 +24348,7 @@ function createNotionTools(getAccessToken, requestNotionAccess) {
|
|
|
24234
24348
|
eagerEmbedContent,
|
|
24235
24349
|
embedAllMessages,
|
|
24236
24350
|
embedMessage,
|
|
24351
|
+
encodeChunkVector,
|
|
24237
24352
|
ensureDefaultFoldersOp,
|
|
24238
24353
|
exchangeNotionCode,
|
|
24239
24354
|
extractAndLinkEntitiesForMemoriesOp,
|