@anuma/sdk 6.15.0 → 6.15.2
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-3V3BBJLH.mjs → chunk-4Z2X4UYQ.mjs} +7 -1
- package/dist/expo/{chunk-DIUQLXEH.mjs → chunk-A2G6TRUK.mjs} +1 -1
- package/dist/expo/{chunk-LUSKQQDD.mjs → chunk-JXN7LD6B.mjs} +41 -17
- package/dist/{react/consolidate-Y2XWEZRQ.mjs → expo/consolidate-ZM5JNULQ.mjs} +2 -2
- package/dist/expo/index.cjs +179 -104
- package/dist/expo/index.mjs +143 -92
- package/dist/expo/{recall-GKYVPD2B.mjs → recall-TGRI5MN4.mjs} +2 -2
- package/dist/react/{chunk-3V3BBJLH.mjs → chunk-4Z2X4UYQ.mjs} +7 -1
- package/dist/react/{chunk-2GNOTRG4.mjs → chunk-7X7BNMGS.mjs} +1 -1
- package/dist/react/{chunk-PDKKPAXP.mjs → chunk-TVPCH7ZZ.mjs} +45 -21
- package/dist/{expo/consolidate-GTMXZZ4C.mjs → react/consolidate-7NMKF7UC.mjs} +2 -2
- package/dist/react/index.cjs +183 -108
- package/dist/react/index.mjs +143 -92
- package/dist/react/{recall-5HNAFHLL.mjs → recall-OKNLU335.mjs} +2 -2
- package/dist/server/{chunk-JPLFOSB2.mjs → chunk-4LPSEROP.mjs} +1 -1
- package/dist/server/{chunk-H4G3DLDJ.mjs → chunk-BSCEZOIW.mjs} +7 -1
- package/dist/server/{chunk-2QFK4L7Y.mjs → chunk-K7H7ICPK.mjs} +21 -21
- package/dist/server/{consolidate-CMMDTZ37.mjs → consolidate-MSAXASHL.mjs} +2 -2
- package/dist/server/index.cjs +136 -93
- package/dist/server/index.mjs +118 -77
- package/dist/server/{recall-EODNEKIA.mjs → recall-YXJATOSD.mjs} +2 -2
- package/package.json +1 -1
package/dist/expo/index.mjs
CHANGED
|
@@ -84,6 +84,7 @@ import {
|
|
|
84
84
|
getMessageSkeletonsOp,
|
|
85
85
|
getMessagesOp,
|
|
86
86
|
getMessagesPageOp,
|
|
87
|
+
getToolCallEventIdsOp,
|
|
87
88
|
getToolCallEvents,
|
|
88
89
|
getToolsChecksum,
|
|
89
90
|
getUnfiledVaultMemoriesOp,
|
|
@@ -132,7 +133,7 @@ import {
|
|
|
132
133
|
upsertMessageOp,
|
|
133
134
|
useEncryption,
|
|
134
135
|
vaultMemoryToStored
|
|
135
|
-
} from "./chunk-
|
|
136
|
+
} from "./chunk-JXN7LD6B.mjs";
|
|
136
137
|
import {
|
|
137
138
|
PII_PATTERNS,
|
|
138
139
|
PiiRedactor,
|
|
@@ -140,21 +141,23 @@ import {
|
|
|
140
141
|
isPiiRedactor,
|
|
141
142
|
notifyConsolidationFallback,
|
|
142
143
|
resolvePiiRedactor
|
|
143
|
-
} from "./chunk-
|
|
144
|
+
} from "./chunk-A2G6TRUK.mjs";
|
|
144
145
|
import {
|
|
145
146
|
INTERNAL_FLOW_MARKER,
|
|
146
147
|
callPortalJsonCompletion,
|
|
147
148
|
consoleLogger,
|
|
149
|
+
extractCompletionContent,
|
|
148
150
|
extractJsonCandidate,
|
|
149
151
|
getLogger,
|
|
150
152
|
noopLogger,
|
|
153
|
+
requiresResponsesTransport,
|
|
151
154
|
resolvePortalAuthHeaders,
|
|
152
155
|
setLogger,
|
|
153
156
|
supportsResponseFormat,
|
|
154
157
|
taskTypeHeader,
|
|
155
158
|
validateEndpointOverride,
|
|
156
159
|
withInternalFlowMarker
|
|
157
|
-
} from "./chunk-
|
|
160
|
+
} from "./chunk-4Z2X4UYQ.mjs";
|
|
158
161
|
import {
|
|
159
162
|
BASE_URL,
|
|
160
163
|
MCP_R2_DOMAIN,
|
|
@@ -6868,7 +6871,7 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
|
|
|
6868
6871
|
content: m.content,
|
|
6869
6872
|
similarity: m.similarity
|
|
6870
6873
|
}));
|
|
6871
|
-
const { consolidateMemory: doConsolidate } = await import("./consolidate-
|
|
6874
|
+
const { consolidateMemory: doConsolidate } = await import("./consolidate-ZM5JNULQ.mjs");
|
|
6872
6875
|
const decision = await doConsolidate(trimmed, candidates, consolidateOptions);
|
|
6873
6876
|
if (decision.action === "create") return null;
|
|
6874
6877
|
if (decision.action === "supersede" && decision.content) {
|
|
@@ -8092,6 +8095,9 @@ var DEFAULT_BASE_URL = BASE_URL;
|
|
|
8092
8095
|
var DEFAULT_MODEL3 = "anthropic/claude-sonnet-4-6";
|
|
8093
8096
|
var DEFAULT_MAX_TOKENS = 4096;
|
|
8094
8097
|
var REQUEST_TIMEOUT_MS = 6e4;
|
|
8098
|
+
var MIN_RETRY_BUDGET_MS = 2e3;
|
|
8099
|
+
var MIN_RESPONSES_OUTPUT_TOKENS = 2048;
|
|
8100
|
+
var SCHEMA_FALLBACK_SKIP_STATUSES = /* @__PURE__ */ new Set([401, 403, 404, 408, 409, 413, 425, 429]);
|
|
8095
8101
|
var DEFAULT_SYSTEM_PROMPT = `You are a personal assistant with access to the user's memory. Answer the user's question using the supplied memories as evidence.
|
|
8096
8102
|
|
|
8097
8103
|
Rules:
|
|
@@ -8123,14 +8129,9 @@ ${m.content}`).join("\n\n");
|
|
|
8123
8129
|
const baseUrl = options.baseUrl ?? DEFAULT_BASE_URL;
|
|
8124
8130
|
const model = options.llmModel ?? DEFAULT_MODEL3;
|
|
8125
8131
|
const wantsStructured = !!options.responseSchema;
|
|
8126
|
-
const
|
|
8132
|
+
const useResponsesTransport = requiresResponsesTransport(model);
|
|
8133
|
+
const sendResponseFormat = wantsStructured && !useResponsesTransport && supportsResponseFormat(model, "json_schema");
|
|
8127
8134
|
const basePrompt = options.systemPrompt ?? DEFAULT_SYSTEM_PROMPT;
|
|
8128
|
-
const systemPrompt = wantsStructured && !sendResponseFormat ? `${basePrompt}
|
|
8129
|
-
|
|
8130
|
-
Respond with ONLY a single JSON object conforming to this JSON Schema, with no prose, comments, or code fences:
|
|
8131
|
-
${JSON.stringify(
|
|
8132
|
-
options.responseSchema
|
|
8133
|
-
)}` : basePrompt;
|
|
8134
8135
|
const userMessage = [
|
|
8135
8136
|
`Question:
|
|
8136
8137
|
${trimmed}`,
|
|
@@ -8140,85 +8141,121 @@ ${evidence}`
|
|
|
8140
8141
|
].join("\n\n");
|
|
8141
8142
|
const maxTokens = options.maxTokens ?? DEFAULT_MAX_TOKENS;
|
|
8142
8143
|
const fetchImpl = options.fetchFn ?? fetch;
|
|
8144
|
+
const buildBody = (useResponseFormat) => {
|
|
8145
|
+
const systemPrompt = wantsStructured && !useResponseFormat ? `${basePrompt}
|
|
8146
|
+
|
|
8147
|
+
Respond with ONLY a single JSON object conforming to this JSON Schema, with no prose, comments, or code fences:
|
|
8148
|
+
${JSON.stringify(
|
|
8149
|
+
options.responseSchema
|
|
8150
|
+
)}` : basePrompt;
|
|
8151
|
+
const messages = [
|
|
8152
|
+
{ role: "system", content: systemPrompt },
|
|
8153
|
+
{ role: "user", content: userMessage }
|
|
8154
|
+
];
|
|
8155
|
+
if (useResponsesTransport) {
|
|
8156
|
+
return JSON.stringify({
|
|
8157
|
+
model,
|
|
8158
|
+
// Same system+user pair under the Responses-API field names: `input`
|
|
8159
|
+
// for the turns, `max_output_tokens` for the cap. Sending the
|
|
8160
|
+
// chat-completions spelling here is silently ignored, which caps the
|
|
8161
|
+
// answer at the portal default.
|
|
8162
|
+
input: messages,
|
|
8163
|
+
max_output_tokens: Math.max(maxTokens, MIN_RESPONSES_OUTPUT_TOKENS)
|
|
8164
|
+
});
|
|
8165
|
+
}
|
|
8166
|
+
return JSON.stringify({
|
|
8167
|
+
model,
|
|
8168
|
+
// Modern OpenAI field; the portal reads only `max_completion_tokens`
|
|
8169
|
+
// (the deprecated `max_tokens` is silently ignored → falls back to the
|
|
8170
|
+
// portal's default output cap and truncates the answer).
|
|
8171
|
+
max_completion_tokens: maxTokens,
|
|
8172
|
+
messages,
|
|
8173
|
+
...useResponseFormat && {
|
|
8174
|
+
response_format: {
|
|
8175
|
+
type: "json_schema",
|
|
8176
|
+
json_schema: { name: "reflect_output", schema: options.responseSchema }
|
|
8177
|
+
}
|
|
8178
|
+
}
|
|
8179
|
+
});
|
|
8180
|
+
};
|
|
8143
8181
|
const log = getLogger();
|
|
8144
8182
|
const authHeaders = await resolvePortalAuthHeaders(options, "memory/reflect");
|
|
8145
8183
|
if (authHeaders === null) return baseResult;
|
|
8146
|
-
const controller = new AbortController();
|
|
8147
8184
|
const deadline = Date.now() + REQUEST_TIMEOUT_MS;
|
|
8148
8185
|
const remaining = () => Math.max(0, deadline - Date.now());
|
|
8149
|
-
const
|
|
8150
|
-
|
|
8151
|
-
|
|
8152
|
-
|
|
8153
|
-
|
|
8154
|
-
|
|
8155
|
-
|
|
8156
|
-
|
|
8157
|
-
|
|
8158
|
-
|
|
8159
|
-
|
|
8160
|
-
|
|
8161
|
-
|
|
8162
|
-
|
|
8163
|
-
|
|
8164
|
-
|
|
8165
|
-
|
|
8166
|
-
|
|
8167
|
-
|
|
8168
|
-
|
|
8169
|
-
|
|
8170
|
-
|
|
8171
|
-
|
|
8172
|
-
|
|
8173
|
-
|
|
8174
|
-
|
|
8175
|
-
}
|
|
8176
|
-
}
|
|
8177
|
-
}),
|
|
8178
|
-
signal: controller.signal
|
|
8179
|
-
});
|
|
8180
|
-
} catch (err) {
|
|
8186
|
+
const endpoint = useResponsesTransport ? "/api/v1/responses" : "/api/v1/chat/completions";
|
|
8187
|
+
const sendOnce = async (useResponseFormat) => {
|
|
8188
|
+
const controller = new AbortController();
|
|
8189
|
+
const timer = setTimeout(() => controller.abort(), remaining());
|
|
8190
|
+
let response;
|
|
8191
|
+
try {
|
|
8192
|
+
response = await fetchImpl(`${baseUrl}${endpoint}`, {
|
|
8193
|
+
method: "POST",
|
|
8194
|
+
// No task type unless the caller named one — an undeclared task adds no
|
|
8195
|
+
// header at all, which is what keeps user-facing reflect() unlabelled.
|
|
8196
|
+
headers: {
|
|
8197
|
+
...authHeaders,
|
|
8198
|
+
...taskTypeHeader(options.taskType),
|
|
8199
|
+
"Content-Type": "application/json"
|
|
8200
|
+
},
|
|
8201
|
+
body: buildBody(useResponseFormat),
|
|
8202
|
+
signal: controller.signal
|
|
8203
|
+
});
|
|
8204
|
+
} catch (err) {
|
|
8205
|
+
clearTimeout(timer);
|
|
8206
|
+
log.warn("[memory/reflect] portal request failed", {
|
|
8207
|
+
err: err instanceof Error ? err.message : String(err),
|
|
8208
|
+
baseUrl
|
|
8209
|
+
});
|
|
8210
|
+
return { kind: "error" };
|
|
8211
|
+
}
|
|
8181
8212
|
clearTimeout(timer);
|
|
8182
|
-
|
|
8183
|
-
|
|
8184
|
-
|
|
8213
|
+
if (!response.ok) {
|
|
8214
|
+
return { kind: "http", status: response.status, statusText: response.statusText };
|
|
8215
|
+
}
|
|
8216
|
+
const bodyTimer = setTimeout(() => controller.abort(), remaining());
|
|
8217
|
+
try {
|
|
8218
|
+
const body = await response.json();
|
|
8219
|
+
clearTimeout(bodyTimer);
|
|
8220
|
+
return { kind: "ok", body };
|
|
8221
|
+
} catch (err) {
|
|
8222
|
+
clearTimeout(bodyTimer);
|
|
8223
|
+
log.warn("[memory/reflect] failed to parse portal response body", {
|
|
8224
|
+
err: err instanceof Error ? err.message : String(err)
|
|
8225
|
+
});
|
|
8226
|
+
return { kind: "error" };
|
|
8227
|
+
}
|
|
8228
|
+
};
|
|
8229
|
+
let attempt = await sendOnce(sendResponseFormat);
|
|
8230
|
+
let schemaFallbackUsed = false;
|
|
8231
|
+
const budgetLeftMs = remaining();
|
|
8232
|
+
if (attempt.kind === "http" && sendResponseFormat && !SCHEMA_FALLBACK_SKIP_STATUSES.has(attempt.status) && budgetLeftMs >= MIN_RETRY_BUDGET_MS) {
|
|
8233
|
+
log.warn("[memory/reflect] response_format json_schema rejected; retrying schema-in-prompt", {
|
|
8234
|
+
status: attempt.status,
|
|
8235
|
+
statusText: attempt.statusText,
|
|
8236
|
+
model,
|
|
8237
|
+
taskType: options.taskType,
|
|
8238
|
+
budgetLeftMs
|
|
8185
8239
|
});
|
|
8186
|
-
|
|
8240
|
+
schemaFallbackUsed = true;
|
|
8241
|
+
attempt = await sendOnce(false);
|
|
8187
8242
|
}
|
|
8188
|
-
|
|
8189
|
-
if (
|
|
8243
|
+
if (attempt.kind === "error") return baseResult;
|
|
8244
|
+
if (attempt.kind === "http") {
|
|
8190
8245
|
log.warn("[memory/reflect] portal returned non-OK", {
|
|
8191
|
-
status:
|
|
8192
|
-
statusText:
|
|
8193
|
-
|
|
8194
|
-
|
|
8195
|
-
}
|
|
8196
|
-
const bodyTimer = setTimeout(() => controller.abort(), remaining());
|
|
8197
|
-
let body;
|
|
8198
|
-
try {
|
|
8199
|
-
body = await response.json();
|
|
8200
|
-
} catch (err) {
|
|
8201
|
-
clearTimeout(bodyTimer);
|
|
8202
|
-
log.warn("[memory/reflect] failed to parse portal response body", {
|
|
8203
|
-
err: err instanceof Error ? err.message : String(err)
|
|
8246
|
+
status: attempt.status,
|
|
8247
|
+
statusText: attempt.statusText,
|
|
8248
|
+
// Distinguishes "the fallback ran and still failed" from "never tried".
|
|
8249
|
+
schemaFallbackUsed
|
|
8204
8250
|
});
|
|
8205
8251
|
return baseResult;
|
|
8206
8252
|
}
|
|
8207
|
-
|
|
8208
|
-
return parseAnswer(body, baseResult, !!options.responseSchema);
|
|
8253
|
+
return parseAnswer(attempt.body, baseResult, !!options.responseSchema);
|
|
8209
8254
|
}
|
|
8210
8255
|
function parseAnswer(body, base, parseSchema) {
|
|
8211
8256
|
if (typeof body !== "object" || body === null) return base;
|
|
8212
8257
|
const obj = body;
|
|
8213
|
-
const
|
|
8214
|
-
let text12 = "";
|
|
8215
|
-
if (Array.isArray(choices) && choices.length > 0) {
|
|
8216
|
-
const message = choices[0].message;
|
|
8217
|
-
if (typeof message === "object" && message !== null) {
|
|
8218
|
-
const content = message.content;
|
|
8219
|
-
if (typeof content === "string") text12 = content;
|
|
8220
|
-
}
|
|
8221
|
-
}
|
|
8258
|
+
const text12 = extractCompletionContent(obj) ?? "";
|
|
8222
8259
|
const usage = obj.usage;
|
|
8223
8260
|
let structuredOutput;
|
|
8224
8261
|
if (parseSchema && text12) {
|
|
@@ -8230,14 +8267,19 @@ function parseAnswer(body, base, parseSchema) {
|
|
|
8230
8267
|
});
|
|
8231
8268
|
}
|
|
8232
8269
|
}
|
|
8270
|
+
const promptTokens = usage?.prompt_tokens ?? usage?.input_tokens ?? 0;
|
|
8271
|
+
const completionTokens = usage?.completion_tokens ?? usage?.output_tokens ?? 0;
|
|
8233
8272
|
return {
|
|
8234
8273
|
text: text12,
|
|
8235
8274
|
...structuredOutput !== void 0 && { structuredOutput },
|
|
8236
8275
|
basedOn: base.basedOn,
|
|
8237
8276
|
usage: {
|
|
8238
|
-
promptTokens
|
|
8239
|
-
completionTokens
|
|
8240
|
-
|
|
8277
|
+
promptTokens,
|
|
8278
|
+
completionTokens,
|
|
8279
|
+
// Derived when absent: the Responses API reports the two component counts
|
|
8280
|
+
// and does not always send a total, which would otherwise report zero
|
|
8281
|
+
// spend for a call that plainly cost something.
|
|
8282
|
+
totalTokens: usage?.total_tokens ?? promptTokens + completionTokens
|
|
8241
8283
|
}
|
|
8242
8284
|
};
|
|
8243
8285
|
}
|
|
@@ -11509,22 +11551,31 @@ function useChatStorage(options) {
|
|
|
11509
11551
|
const serverToolsPromise = getTokenRef.current && !(Array.isArray(serverToolsFilter) && serverToolsFilter.length === 0) ? fetchServerToolsSettled(getTokenRef.current) : null;
|
|
11510
11552
|
const userMessageEmbeddingPromise = getTokenRef.current && contentForStorage.length >= MIN_CONTENT_LENGTH_FOR_TOOLS && (isServerToolsFunction && !(serverToolsConfig?.deferLoading?.enabled && effectiveApiType === "responses") || !!clientTools?.length) ? embedForToolsSettled(getTokenRef.current) : null;
|
|
11511
11553
|
let messagesToSend;
|
|
11512
|
-
const
|
|
11513
|
-
const knownToolCallEventIds = /* @__PURE__ */ new Set();
|
|
11514
|
-
for (const msg of storedMessages) {
|
|
11515
|
-
if (msg.toolCallEvents) {
|
|
11516
|
-
for (const evt of msg.toolCallEvents) {
|
|
11517
|
-
if (evt.id) knownToolCallEventIds.add(evt.id);
|
|
11518
|
-
}
|
|
11519
|
-
}
|
|
11520
|
-
}
|
|
11554
|
+
const knownToolCallEventIds = await getToolCallEventIdsOp(storageCtx, convId);
|
|
11521
11555
|
if (includeHistory) {
|
|
11522
|
-
|
|
11523
|
-
|
|
11524
|
-
|
|
11525
|
-
|
|
11526
|
-
|
|
11527
|
-
|
|
11556
|
+
let tail = [];
|
|
11557
|
+
let replayableMessages = [];
|
|
11558
|
+
let beforeMessageId;
|
|
11559
|
+
let boundaryExcludeUniqueIds;
|
|
11560
|
+
for (; ; ) {
|
|
11561
|
+
const page = await getMessagesPageOp(storageCtx, convId, {
|
|
11562
|
+
limit: maxHistoryMessages,
|
|
11563
|
+
beforeMessageId,
|
|
11564
|
+
boundaryExcludeUniqueIds
|
|
11565
|
+
});
|
|
11566
|
+
if (page.length === 0) break;
|
|
11567
|
+
tail = [...page, ...tail];
|
|
11568
|
+
const validMessages = tail.filter((msg) => !msg.error);
|
|
11569
|
+
replayableMessages = prepareToolResultsForReplay(validMessages, {
|
|
11570
|
+
fold: foldToolResultsInHistoryRef.current === true,
|
|
11571
|
+
exclude: toolResultsHistoryExcludeRef.current,
|
|
11572
|
+
placeholder: DISPLAY_CARD_PLACEHOLDER
|
|
11573
|
+
});
|
|
11574
|
+
if (replayableMessages.length >= maxHistoryMessages) break;
|
|
11575
|
+
if (page.length < maxHistoryMessages) break;
|
|
11576
|
+
beforeMessageId = page[0].messageId;
|
|
11577
|
+
boundaryExcludeUniqueIds = tail.filter((msg) => msg.messageId === beforeMessageId).map((msg) => msg.uniqueId);
|
|
11578
|
+
}
|
|
11528
11579
|
const limitedMessages = replayableMessages.slice(-maxHistoryMessages);
|
|
11529
11580
|
const foldedHistory = limitedMessages;
|
|
11530
11581
|
if (summarizeHistory && !getTokenRef.current) {
|
|
@@ -70,6 +70,10 @@ function supportsResponseFormat(model, variant = "json_object") {
|
|
|
70
70
|
const allow = variant === "json_schema" ? RESPONSE_SCHEMA_OK : RESPONSE_FORMAT_OK;
|
|
71
71
|
return model.split("/").some((seg) => allow.has(seg));
|
|
72
72
|
}
|
|
73
|
+
var RESPONSES_ONLY_MODEL_PREFIXES = ["gpt-5.6"];
|
|
74
|
+
function requiresResponsesTransport(model) {
|
|
75
|
+
return model.split("/").some((seg) => RESPONSES_ONLY_MODEL_PREFIXES.some((prefix) => seg.startsWith(prefix)));
|
|
76
|
+
}
|
|
73
77
|
var CHAT_TO_RESPONSES_FIELDS = {
|
|
74
78
|
max_completion_tokens: "max_output_tokens"
|
|
75
79
|
};
|
|
@@ -424,7 +428,9 @@ export {
|
|
|
424
428
|
withInternalFlowMarker,
|
|
425
429
|
taskTypeHeader,
|
|
426
430
|
supportsResponseFormat,
|
|
431
|
+
requiresResponsesTransport,
|
|
427
432
|
resolvePortalAuthHeaders,
|
|
428
433
|
callPortalJsonCompletion,
|
|
429
|
-
extractJsonCandidate
|
|
434
|
+
extractJsonCandidate,
|
|
435
|
+
extractCompletionContent
|
|
430
436
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
callPortalJsonCompletion,
|
|
3
3
|
getLogger
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-4Z2X4UYQ.mjs";
|
|
5
5
|
import {
|
|
6
6
|
BASE_URL,
|
|
7
7
|
createClientConfig
|
|
@@ -1773,6 +1773,29 @@ async function getMessageSkeletonsOp(ctx, convId) {
|
|
|
1773
1773
|
}
|
|
1774
1774
|
return skeletons;
|
|
1775
1775
|
}
|
|
1776
|
+
async function getToolCallEventIdsOp(ctx, convId) {
|
|
1777
|
+
const results = await ctx.messagesCollection.query(Q.where("conversation_id", convId)).unsafeFetchRaw();
|
|
1778
|
+
const ids = /* @__PURE__ */ new Set();
|
|
1779
|
+
for (const raw of results) {
|
|
1780
|
+
const value = raw.tool_call_events;
|
|
1781
|
+
if (!value) continue;
|
|
1782
|
+
let events;
|
|
1783
|
+
if (typeof value === "string") {
|
|
1784
|
+
try {
|
|
1785
|
+
events = JSON.parse(value);
|
|
1786
|
+
} catch {
|
|
1787
|
+
continue;
|
|
1788
|
+
}
|
|
1789
|
+
} else if (Array.isArray(value)) {
|
|
1790
|
+
events = value;
|
|
1791
|
+
}
|
|
1792
|
+
if (!Array.isArray(events)) continue;
|
|
1793
|
+
for (const evt of events) {
|
|
1794
|
+
if (evt && evt.id) ids.add(evt.id);
|
|
1795
|
+
}
|
|
1796
|
+
}
|
|
1797
|
+
return ids;
|
|
1798
|
+
}
|
|
1776
1799
|
async function clearMessagesOp(ctx, convId) {
|
|
1777
1800
|
const messages = await ctx.messagesCollection.query(Q.where("conversation_id", convId)).fetch();
|
|
1778
1801
|
await ctx.database.write(async () => {
|
|
@@ -2002,14 +2025,14 @@ function resolveChunkText(content, chunk, chunksInRow) {
|
|
|
2002
2025
|
if (covered !== content.length) return content;
|
|
2003
2026
|
return content.slice(start, end);
|
|
2004
2027
|
}
|
|
2005
|
-
async function
|
|
2006
|
-
const
|
|
2007
|
-
if (!
|
|
2008
|
-
if (walletAddress && isEncrypted(
|
|
2009
|
-
return await decryptJsonField(
|
|
2028
|
+
async function readRawJsonField(raw, column, walletAddress) {
|
|
2029
|
+
const value = raw[column];
|
|
2030
|
+
if (!value) return void 0;
|
|
2031
|
+
if (walletAddress && isEncrypted(value)) {
|
|
2032
|
+
return await decryptJsonField(value, walletAddress);
|
|
2010
2033
|
}
|
|
2011
2034
|
try {
|
|
2012
|
-
return JSON.parse(
|
|
2035
|
+
return JSON.parse(value);
|
|
2013
2036
|
} catch {
|
|
2014
2037
|
return void 0;
|
|
2015
2038
|
}
|
|
@@ -2022,12 +2045,12 @@ async function searchMessagesOp(ctx, queryVector, options) {
|
|
|
2022
2045
|
activeConversations.map((c) => String(c._getRaw("conversation_id")))
|
|
2023
2046
|
);
|
|
2024
2047
|
const queryConditions = conversationId ? [Q.where("conversation_id", conversationId)] : [];
|
|
2025
|
-
const messages = await ctx.messagesCollection.query(...queryConditions).
|
|
2048
|
+
const messages = await ctx.messagesCollection.query(...queryConditions).unsafeFetchRaw();
|
|
2026
2049
|
const candidates = [];
|
|
2027
2050
|
for (const message of messages) {
|
|
2028
|
-
const msgConvId = String(message.
|
|
2051
|
+
const msgConvId = String(message.conversation_id);
|
|
2029
2052
|
if (!activeConversationIds.has(msgConvId)) continue;
|
|
2030
|
-
const messageVector = await
|
|
2053
|
+
const messageVector = await readRawJsonField(message, "vector", ctx.walletAddress);
|
|
2031
2054
|
if (!messageVector || messageVector.length === 0) continue;
|
|
2032
2055
|
const similarity = cosineSimilarity(queryVector, messageVector);
|
|
2033
2056
|
if (similarity >= minSimilarity) {
|
|
@@ -2037,7 +2060,7 @@ async function searchMessagesOp(ctx, queryVector, options) {
|
|
|
2037
2060
|
const topK = candidates.sort((a, b) => b.similarity - a.similarity).slice(0, limit);
|
|
2038
2061
|
return Promise.all(
|
|
2039
2062
|
topK.map(async ({ message, similarity }) => {
|
|
2040
|
-
const stored = await
|
|
2063
|
+
const stored = await messageRawToStored(
|
|
2041
2064
|
message,
|
|
2042
2065
|
ctx.walletAddress,
|
|
2043
2066
|
ctx.signMessage,
|
|
@@ -2061,21 +2084,21 @@ async function searchChunksOp(ctx, queryVector, options) {
|
|
|
2061
2084
|
activeConversations.map((c) => String(c._getRaw("conversation_id")))
|
|
2062
2085
|
);
|
|
2063
2086
|
const queryConditions = conversationId ? [Q.where("conversation_id", conversationId)] : [];
|
|
2064
|
-
const messages = await ctx.messagesCollection.query(...queryConditions).
|
|
2087
|
+
const messages = await ctx.messagesCollection.query(...queryConditions).unsafeFetchRaw();
|
|
2065
2088
|
const candidates = [];
|
|
2066
2089
|
let staleSkipped = 0;
|
|
2067
2090
|
let unreadableVectors = 0;
|
|
2068
2091
|
for (const message of messages) {
|
|
2069
|
-
const msgConvId = String(message.
|
|
2092
|
+
const msgConvId = String(message.conversation_id);
|
|
2070
2093
|
if (!activeConversationIds.has(msgConvId)) continue;
|
|
2071
2094
|
if (embeddingModel) {
|
|
2072
|
-
const storedModel = message.
|
|
2095
|
+
const storedModel = message.embedding_model;
|
|
2073
2096
|
if (storedModel !== null && storedModel !== void 0 && storedModel !== embeddingModel) {
|
|
2074
2097
|
staleSkipped++;
|
|
2075
2098
|
continue;
|
|
2076
2099
|
}
|
|
2077
2100
|
}
|
|
2078
|
-
const version = Number(message.
|
|
2101
|
+
const version = Number(message.updated_at) || 0;
|
|
2079
2102
|
const cached = chunkCache?.get(message.id);
|
|
2080
2103
|
if (cached && cached.version === version) {
|
|
2081
2104
|
if (cached.chunks.length > 0) {
|
|
@@ -2099,7 +2122,7 @@ async function searchChunksOp(ctx, queryVector, options) {
|
|
|
2099
2122
|
}
|
|
2100
2123
|
continue;
|
|
2101
2124
|
}
|
|
2102
|
-
const chunks = await
|
|
2125
|
+
const chunks = await readRawJsonField(message, "chunks", ctx.walletAddress);
|
|
2103
2126
|
if (chunks && chunks.length > 0) {
|
|
2104
2127
|
const vectors = chunks.map(
|
|
2105
2128
|
(chunk) => decodeChunkVector(chunk.vector, () => {
|
|
@@ -2120,7 +2143,7 @@ async function searchChunksOp(ctx, queryVector, options) {
|
|
|
2120
2143
|
}
|
|
2121
2144
|
}
|
|
2122
2145
|
} else {
|
|
2123
|
-
const messageVector = await
|
|
2146
|
+
const messageVector = await readRawJsonField(message, "vector", ctx.walletAddress);
|
|
2124
2147
|
if (!messageVector || messageVector.length === 0) continue;
|
|
2125
2148
|
const fallback = Float32Array.from(messageVector);
|
|
2126
2149
|
chunkCache?.set(message.id, { version, chunks: [], fallback });
|
|
@@ -2146,7 +2169,7 @@ async function searchChunksOp(ctx, queryVector, options) {
|
|
|
2146
2169
|
const storedById = new Map(
|
|
2147
2170
|
await Promise.all(
|
|
2148
2171
|
Array.from(uniqueMessages, async ([id, m]) => {
|
|
2149
|
-
const stored = await
|
|
2172
|
+
const stored = await messageRawToStored(
|
|
2150
2173
|
m,
|
|
2151
2174
|
ctx.walletAddress,
|
|
2152
2175
|
ctx.signMessage,
|
|
@@ -2164,8 +2187,8 @@ async function searchChunksOp(ctx, queryVector, options) {
|
|
|
2164
2187
|
await Promise.all(
|
|
2165
2188
|
Array.from(needsChunkText, async (id) => {
|
|
2166
2189
|
const m = uniqueMessages.get(id);
|
|
2167
|
-
const parsed = await
|
|
2168
|
-
const version = Number(m.
|
|
2190
|
+
const parsed = await readRawJsonField(m, "chunks", ctx.walletAddress);
|
|
2191
|
+
const version = Number(m.updated_at) || 0;
|
|
2169
2192
|
if (parsed) chunkStateByMsgId.set(id, { version, chunks: parsed });
|
|
2170
2193
|
})
|
|
2171
2194
|
);
|
|
@@ -7169,7 +7192,7 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
|
|
|
7169
7192
|
subQueries = decomp.subQueries;
|
|
7170
7193
|
}
|
|
7171
7194
|
}
|
|
7172
|
-
const { recall: recall2 } = await import("./recall-
|
|
7195
|
+
const { recall: recall2 } = await import("./recall-OKNLU335.mjs");
|
|
7173
7196
|
let recallDegraded = [];
|
|
7174
7197
|
const result = await recall2(
|
|
7175
7198
|
query,
|
|
@@ -8195,6 +8218,7 @@ export {
|
|
|
8195
8218
|
getMessageCountOp,
|
|
8196
8219
|
getMessagesPageOp,
|
|
8197
8220
|
getMessageSkeletonsOp,
|
|
8221
|
+
getToolCallEventIdsOp,
|
|
8198
8222
|
clearMessagesOp,
|
|
8199
8223
|
createMessageOp,
|
|
8200
8224
|
getMessageOp,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
notifyConsolidationFallback,
|
|
3
3
|
resolvePiiRedactor
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-7X7BNMGS.mjs";
|
|
5
5
|
import {
|
|
6
6
|
callPortalJsonCompletion
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-4Z2X4UYQ.mjs";
|
|
8
8
|
import "./chunk-GYKJOWEO.mjs";
|
|
9
9
|
|
|
10
10
|
// src/lib/memory/consolidate.ts
|