@anuma/sdk 7.3.1 → 7.3.3
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-AF37N5Z6.mjs → chunk-XW3LYSDA.mjs} +9 -4
- package/dist/expo/{consolidate-TOITBD6W.mjs → consolidate-4CQJYKRK.mjs} +25 -5
- package/dist/expo/index.cjs +77 -15
- package/dist/expo/index.d.mts +3 -1
- package/dist/expo/index.d.ts +3 -1
- package/dist/expo/index.mjs +49 -9
- package/dist/react/{chunk-TGLAOFVA.mjs → chunk-7QX4J7KV.mjs} +9 -4
- package/dist/react/{consolidate-ZEINV2LX.mjs → consolidate-WLDYJF6J.mjs} +25 -5
- package/dist/react/index.cjs +77 -15
- package/dist/react/index.d.mts +3 -1
- package/dist/react/index.d.ts +3 -1
- package/dist/react/index.mjs +49 -9
- package/dist/server/{chunk-WCG5BFI6.mjs → chunk-AU3Z7NBC.mjs} +9 -4
- package/dist/server/{consolidate-WY6BHODK.mjs → consolidate-B6OSCZU4.mjs} +25 -5
- package/dist/server/index.cjs +77 -15
- package/dist/server/index.d.mts +3 -1
- package/dist/server/index.d.ts +3 -1
- package/dist/server/index.mjs +49 -9
- package/package.json +1 -1
package/dist/server/index.cjs
CHANGED
|
@@ -15674,6 +15674,13 @@ function splitEndpoint(endpoint) {
|
|
|
15674
15674
|
rest: cut === -1 ? "" : endpoint.slice(cut)
|
|
15675
15675
|
};
|
|
15676
15676
|
}
|
|
15677
|
+
function endpointForTransport(endpoint, transport) {
|
|
15678
|
+
const { path, rest } = splitEndpoint(endpoint);
|
|
15679
|
+
const foreign = FOREIGN_ENDPOINT_SUFFIX[transport];
|
|
15680
|
+
if (!path.endsWith(foreign)) return endpoint;
|
|
15681
|
+
const own = FOREIGN_ENDPOINT_SUFFIX[transport === "chat" ? "responses" : "chat"];
|
|
15682
|
+
return `${path.slice(0, -foreign.length)}${own}${rest}`;
|
|
15683
|
+
}
|
|
15677
15684
|
function assertTransportMatchesEndpoint(transport, endpoint) {
|
|
15678
15685
|
const foreign = FOREIGN_ENDPOINT_SUFFIX[transport];
|
|
15679
15686
|
if (!splitEndpoint(endpoint).path.endsWith(foreign)) return;
|
|
@@ -15730,10 +15737,7 @@ async function callPortalJsonCompletion(req) {
|
|
|
15730
15737
|
throw new Error(overrideValidation.message);
|
|
15731
15738
|
}
|
|
15732
15739
|
endpoint = overrideValidation.endpoint;
|
|
15733
|
-
|
|
15734
|
-
if (autoUpgraded && path.endsWith("/chat/completions")) {
|
|
15735
|
-
endpoint = `${path.slice(0, -"/chat/completions".length)}/responses${rest}`;
|
|
15736
|
-
}
|
|
15740
|
+
if (autoUpgraded) endpoint = endpointForTransport(endpoint, transport);
|
|
15737
15741
|
assertTransportMatchesEndpoint(transport, endpoint);
|
|
15738
15742
|
}
|
|
15739
15743
|
const maxAttempts = Math.max(1, req.maxAttempts ?? 3);
|
|
@@ -16079,14 +16083,23 @@ async function consolidateMemory(newContent, candidates, options) {
|
|
|
16079
16083
|
|
|
16080
16084
|
Existing memories (top ${candidates.length} by cosine):
|
|
16081
16085
|
${candidateText}`;
|
|
16086
|
+
const model = options.model ?? DEFAULT_CONSOLIDATION_MODEL;
|
|
16087
|
+
const viaResponses = requiresResponsesTransport(model);
|
|
16088
|
+
const endpointOverride = options.endpointOverride === void 0 ? void 0 : endpointForTransport(options.endpointOverride, viaResponses ? "responses" : "chat");
|
|
16082
16089
|
let parsed;
|
|
16090
|
+
let failure;
|
|
16083
16091
|
try {
|
|
16084
16092
|
parsed = await callPortalJsonCompletion({
|
|
16093
|
+
onFailure: (f) => {
|
|
16094
|
+
failure = f;
|
|
16095
|
+
},
|
|
16085
16096
|
...options.apiKey !== void 0 && { apiKey: options.apiKey },
|
|
16086
16097
|
...options.getToken !== void 0 && { getToken: options.getToken },
|
|
16087
16098
|
...options.baseUrl !== void 0 && { baseUrl: options.baseUrl },
|
|
16099
|
+
...endpointOverride !== void 0 && { endpointOverride },
|
|
16088
16100
|
taskType: "memory_consolidate",
|
|
16089
|
-
model
|
|
16101
|
+
model,
|
|
16102
|
+
...viaResponses ? { transport: "responses", reasoning: { effort: "low" } } : { transport: "chat" },
|
|
16090
16103
|
systemPrompt: SYSTEM_PROMPT3,
|
|
16091
16104
|
userMessage,
|
|
16092
16105
|
tag: "memory/consolidate",
|
|
@@ -16098,7 +16111,7 @@ ${candidateText}`;
|
|
|
16098
16111
|
} catch (err) {
|
|
16099
16112
|
return degrade("llm_error", fallback, options, err);
|
|
16100
16113
|
}
|
|
16101
|
-
if (parsed === null) return degrade(
|
|
16114
|
+
if (parsed === null) return degrade(fallbackReasonFor(failure), fallback, options, failure);
|
|
16102
16115
|
const validIds = new Set(candidates.map((c) => c.id));
|
|
16103
16116
|
const result = validate2(parsed, trimmed, validIds);
|
|
16104
16117
|
if (!result) return degrade("invalid_response", fallback, options);
|
|
@@ -16111,6 +16124,11 @@ ${candidateText}`;
|
|
|
16111
16124
|
}
|
|
16112
16125
|
return reportRefusal(result, options);
|
|
16113
16126
|
}
|
|
16127
|
+
function fallbackReasonFor(failure) {
|
|
16128
|
+
if (failure?.reason === "time-budget-exhausted") return "llm_timeout";
|
|
16129
|
+
if (failure?.reason === "content-flagged") return "content_flagged";
|
|
16130
|
+
return "llm_error";
|
|
16131
|
+
}
|
|
16114
16132
|
function reportRefusal(result, options) {
|
|
16115
16133
|
if (result.fallbackReason) {
|
|
16116
16134
|
notifyConsolidationFallback(result.fallbackReason, options.onFallback);
|
|
@@ -16184,7 +16202,7 @@ var init_consolidate = __esm({
|
|
|
16184
16202
|
init_redactor();
|
|
16185
16203
|
init_consolidationFallback();
|
|
16186
16204
|
init_portalLlm();
|
|
16187
|
-
DEFAULT_CONSOLIDATION_MODEL = "
|
|
16205
|
+
DEFAULT_CONSOLIDATION_MODEL = "openai/gpt-6-luna";
|
|
16188
16206
|
DEFAULT_CONSOLIDATE_ATTEMPTS = 3;
|
|
16189
16207
|
DEFAULT_CONSOLIDATE_TOTAL_TIMEOUT_MS = 2e4;
|
|
16190
16208
|
SYSTEM_PROMPT3 = `You consolidate a new memory against existing memories from the same user.
|
|
@@ -16224,7 +16242,11 @@ OUTPUT \u2014 strict JSON, no prose:
|
|
|
16224
16242
|
For "create": content is the new memory verbatim (or a slight refinement); omit targetId/targetIds.
|
|
16225
16243
|
For "update": content is the merged richest-version, \u226480 words; targetId is the single memory to update.
|
|
16226
16244
|
For "supersede": content is the NEW fact only (\u226480 words); "targetIds" lists EVERY stale memory being retired (all candidates describing the same now-changed attribute). You MUST also name the subjects: "newSubject" for the new memory, and one entry in "targetSubjects" for EACH memory you are retiring (use "targetSubject" as well when you retire a single memory). List a subject ONLY for the memories you are actually retiring, not for every candidate you were shown. Write the plain subject, not a sentence: "the user", "the user's sister", "the user's manager", "Biscuit the dog". Rule 1a means a supersede is only valid when every one of those subjects is the SAME as "newSubject"; name them and check them against each other before you commit to the action. If ANY of them differs, the answer is "create" \u2014 do not retire the ones that match and keep the rest, because a group that mixes subjects was grouped wrongly in the first place. A subjectless fact ("Lives in Denver", "Works at Riverbend") is about "the user" \u2014 the extractor omits the subject when it is the user, so treat the absence of a subject as the user, never as unknown.
|
|
16227
|
-
For "noop": no content (existing memory is already correct); targetId is that memory
|
|
16245
|
+
For "noop": no content (existing memory is already correct); targetId is that memory.
|
|
16246
|
+
|
|
16247
|
+
ADDING TO AN INTRODUCED ENTITY (check this before choosing "create"): when an existing memory only introduces or names someone or something in the user's life ("User has a cat named Mochi", "User's sister is called Ana") and the new memory gives an attribute of that SAME entity that the existing memory does not state yet (its age, breed, job, home city), choose "update": targetId is that memory and content folds both into one sentence ("User has a cat named Mochi, who is four years old."). The "dog's name vs dog's age" example above means two memories that each already state a different attribute stay separate; a memory that only introduces the entity absorbs the next attribute about it. If the existing memory already states a value and the new memory changes it, that is "supersede" (rule 4), not this.
|
|
16248
|
+
|
|
16249
|
+
CARRY FORWARD UNCHANGED DETAILS (every "update" and "supersede"): a memory can hold several details at once, such as one folded from an introduction and an attribute ("User's sister Ana lives in Paris"). content replaces ONLY the value that changed and keeps every other detail of the memory it replaces, the subject's relation to the user and name above all: "Ana lives in London" against "User's sister Ana lives in Paris" is "supersede" with content "User's sister Ana lives in London", never just "Ana lives in London". Name the subject the same way on both sides: here "newSubject" and "targetSubjects" are both "the user's sister Ana".`;
|
|
16228
16250
|
USER_SUBJECT_ALIASES = /* @__PURE__ */ new Set(["user", "themselves", "themself", "they", "me", "self"]);
|
|
16229
16251
|
}
|
|
16230
16252
|
});
|
|
@@ -16828,7 +16850,7 @@ function onKeyAvailable(address, callback) {
|
|
|
16828
16850
|
callbacks.add(callback);
|
|
16829
16851
|
return () => {
|
|
16830
16852
|
callbacks.delete(callback);
|
|
16831
|
-
if (callbacks.size === 0) {
|
|
16853
|
+
if (callbacks.size === 0 && keyAvailableCallbacks.get(address) === callbacks) {
|
|
16832
16854
|
keyAvailableCallbacks.delete(address);
|
|
16833
16855
|
}
|
|
16834
16856
|
};
|
|
@@ -33697,7 +33719,12 @@ function createAutoExtractor(options) {
|
|
|
33697
33719
|
...baseUrl !== void 0 && { baseUrl }
|
|
33698
33720
|
};
|
|
33699
33721
|
};
|
|
33700
|
-
const
|
|
33722
|
+
const consolidateEndpoint = options.consolidate?.endpointOverride ?? options.extract.endpointOverride;
|
|
33723
|
+
const consolidateOptions = options.consolidate ? {
|
|
33724
|
+
...options.consolidate,
|
|
33725
|
+
...subPassAuth(options.consolidate.baseUrl),
|
|
33726
|
+
...consolidateEndpoint !== void 0 && { endpointOverride: consolidateEndpoint }
|
|
33727
|
+
} : void 0;
|
|
33701
33728
|
const injectionClassifierOptions = options.injectionClassifier ? { ...options.injectionClassifier, ...subPassAuth(options.injectionClassifier.baseUrl) } : void 0;
|
|
33702
33729
|
if (!options.memoryStore && options.retainCtx.vaultCtx.entityCtx && !options.entityCtx) {
|
|
33703
33730
|
getLogger().warn(
|
|
@@ -36880,10 +36907,20 @@ function batchError(result) {
|
|
|
36880
36907
|
var AccountFailureError = class extends Error {
|
|
36881
36908
|
};
|
|
36882
36909
|
var LockedSourcesError = class extends Error {
|
|
36883
|
-
constructor(persistentIds) {
|
|
36884
|
-
|
|
36910
|
+
constructor(persistentIds, locked) {
|
|
36911
|
+
const counts = /* @__PURE__ */ new Map();
|
|
36912
|
+
for (const message of locked) {
|
|
36913
|
+
const version = /^enc:(v\d+):/.exec(message.content)?.[1] ?? "unknown";
|
|
36914
|
+
const key = `${message.decryptionStatus ?? "no_status"}:${version}`;
|
|
36915
|
+
counts.set(key, (counts.get(key) ?? 0) + 1);
|
|
36916
|
+
}
|
|
36917
|
+
const summary = [...counts].map(([key, count]) => `${key}=${count}`).join(", ");
|
|
36918
|
+
super(`Source messages are locked; retained for retry (${summary})`);
|
|
36885
36919
|
this.persistentIds = persistentIds;
|
|
36886
36920
|
}
|
|
36921
|
+
get awaitingKey() {
|
|
36922
|
+
return this.persistentIds.length === 0;
|
|
36923
|
+
}
|
|
36887
36924
|
};
|
|
36888
36925
|
function splitTurns(messages) {
|
|
36889
36926
|
const turns = [];
|
|
@@ -36937,6 +36974,8 @@ function createDurableAutoExtractor(options) {
|
|
|
36937
36974
|
const attempts = /* @__PURE__ */ new Map();
|
|
36938
36975
|
const sessionFailures = /* @__PURE__ */ new Map();
|
|
36939
36976
|
const skippedThisSession = /* @__PURE__ */ new Set();
|
|
36977
|
+
const awaitingKey = /* @__PURE__ */ new Set();
|
|
36978
|
+
let keyEpoch = 0;
|
|
36940
36979
|
const clock = options.now ?? Date.now;
|
|
36941
36980
|
const reportError = (error, conversationId) => {
|
|
36942
36981
|
try {
|
|
@@ -37130,13 +37169,15 @@ function createDurableAutoExtractor(options) {
|
|
|
37130
37169
|
for (const job of pending) {
|
|
37131
37170
|
if (disposed) break;
|
|
37132
37171
|
const attempted = attempts.get(job.id) ?? 0;
|
|
37133
|
-
if (attempted >= MAX_ATTEMPTS || skippedThisSession.has(job.id))
|
|
37172
|
+
if (attempted >= MAX_ATTEMPTS || skippedThisSession.has(job.id) || awaitingKey.has(job.id))
|
|
37173
|
+
continue;
|
|
37134
37174
|
if (processed >= MAX_JOBS_PER_PASS) {
|
|
37135
37175
|
scheduleAfterSuccess = true;
|
|
37136
37176
|
break;
|
|
37137
37177
|
}
|
|
37138
37178
|
processed++;
|
|
37139
37179
|
const conversationId = String(job._getRaw("conversation_id"));
|
|
37180
|
+
const epochAtRead = keyEpoch;
|
|
37140
37181
|
let ids = [];
|
|
37141
37182
|
let loaded = [];
|
|
37142
37183
|
try {
|
|
@@ -37190,12 +37231,15 @@ function createDurableAutoExtractor(options) {
|
|
|
37190
37231
|
);
|
|
37191
37232
|
continue;
|
|
37192
37233
|
}
|
|
37193
|
-
const locked = loaded.filter(
|
|
37234
|
+
const locked = loaded.filter(
|
|
37235
|
+
(message) => !!message && isEncrypted(message.content)
|
|
37236
|
+
);
|
|
37194
37237
|
if (locked.length) {
|
|
37195
37238
|
throw new LockedSourcesError(
|
|
37196
37239
|
locked.flatMap(
|
|
37197
37240
|
(message) => message.decryptionStatus === "auth_mismatch" || message.decryptionStatus === "invalid_payload" ? [message.uniqueId] : []
|
|
37198
|
-
)
|
|
37241
|
+
),
|
|
37242
|
+
locked
|
|
37199
37243
|
);
|
|
37200
37244
|
}
|
|
37201
37245
|
const messages = loaded.flatMap(
|
|
@@ -37249,6 +37293,12 @@ function createDurableAutoExtractor(options) {
|
|
|
37249
37293
|
scheduleAfterSuccess = true;
|
|
37250
37294
|
} catch (error) {
|
|
37251
37295
|
if (disposed) break;
|
|
37296
|
+
if (error instanceof LockedSourcesError && error.awaitingKey) {
|
|
37297
|
+
reportError(error, conversationId);
|
|
37298
|
+
if (keyEpoch === epochAtRead) awaitingKey.add(job.id);
|
|
37299
|
+
else scheduleAfterSuccess = true;
|
|
37300
|
+
continue;
|
|
37301
|
+
}
|
|
37252
37302
|
attempts.set(job.id, attempted + 1);
|
|
37253
37303
|
retry = true;
|
|
37254
37304
|
reportError(error, conversationId);
|
|
@@ -37276,7 +37326,18 @@ function createDurableAutoExtractor(options) {
|
|
|
37276
37326
|
activeBatch?.abort(options.signal?.reason);
|
|
37277
37327
|
if (timer !== void 0) clearTimeout(timer);
|
|
37278
37328
|
options.signal?.removeEventListener("abort", dispose);
|
|
37329
|
+
unsubscribeKey?.();
|
|
37279
37330
|
}
|
|
37331
|
+
const unsubscribeKey = vault.walletAddress ? onKeyAvailable(vault.walletAddress, () => {
|
|
37332
|
+
keyEpoch++;
|
|
37333
|
+
if (!awaitingKey.size) return;
|
|
37334
|
+
awaitingKey.clear();
|
|
37335
|
+
if (timer !== void 0) {
|
|
37336
|
+
clearTimeout(timer);
|
|
37337
|
+
timer = void 0;
|
|
37338
|
+
}
|
|
37339
|
+
schedule(0);
|
|
37340
|
+
}) : void 0;
|
|
37280
37341
|
if (options.signal?.aborted) dispose();
|
|
37281
37342
|
else options.signal?.addEventListener("abort", dispose, { once: true });
|
|
37282
37343
|
schedule(0);
|
|
@@ -37366,6 +37427,7 @@ function createDurableAutoExtractor(options) {
|
|
|
37366
37427
|
(r) => r._setRaw("message_ids", JSON.stringify([.../* @__PURE__ */ new Set([...idsOf(job), ...fresh])]))
|
|
37367
37428
|
);
|
|
37368
37429
|
attempts.delete(job.id);
|
|
37430
|
+
awaitingKey.delete(job.id);
|
|
37369
37431
|
} else {
|
|
37370
37432
|
await jobs.create((r) => {
|
|
37371
37433
|
r._setRaw("owner_key", owner);
|
package/dist/server/index.d.mts
CHANGED
|
@@ -4503,7 +4503,7 @@ type RetainSource = "manual" | "auto-extracted" | "capsule";
|
|
|
4503
4503
|
* rate of exactly zero is as likely to mean "the fields are being omitted" as
|
|
4504
4504
|
* "the mistake never happens". Check compliance before reading zero as health.
|
|
4505
4505
|
*/
|
|
4506
|
-
type ConsolidationFallbackReason = "llm_error" | "invalid_response" | "target_vanished"
|
|
4506
|
+
type ConsolidationFallbackReason = "llm_error" | "llm_timeout" | "content_flagged" | "invalid_response" | "target_vanished"
|
|
4507
4507
|
/**
|
|
4508
4508
|
* A `supersede` was downgraded to `create` because the model's own stated
|
|
4509
4509
|
* subjects disagreed: the new fact is about someone other than the fact it
|
|
@@ -4542,6 +4542,7 @@ interface RetainOptions {
|
|
|
4542
4542
|
consolidateOptions?: PortalLlmAuth & {
|
|
4543
4543
|
baseUrl?: string;
|
|
4544
4544
|
model?: string;
|
|
4545
|
+
endpointOverride?: string;
|
|
4545
4546
|
/**
|
|
4546
4547
|
* Invoked when the consolidator degrades to its "create" fallback
|
|
4547
4548
|
* instead of returning a real decision — `llm_error` for network /
|
|
@@ -9174,6 +9175,7 @@ interface CreateAutoExtractorOptions {
|
|
|
9174
9175
|
baseUrl?: string;
|
|
9175
9176
|
/** Override the consolidation model. Default: see `consolidate.ts`. */
|
|
9176
9177
|
model?: string;
|
|
9178
|
+
endpointOverride?: string;
|
|
9177
9179
|
/**
|
|
9178
9180
|
* Notified on each degraded create-fallback (LLM failure or
|
|
9179
9181
|
* schema-violating response). See
|
package/dist/server/index.d.ts
CHANGED
|
@@ -4503,7 +4503,7 @@ type RetainSource = "manual" | "auto-extracted" | "capsule";
|
|
|
4503
4503
|
* rate of exactly zero is as likely to mean "the fields are being omitted" as
|
|
4504
4504
|
* "the mistake never happens". Check compliance before reading zero as health.
|
|
4505
4505
|
*/
|
|
4506
|
-
type ConsolidationFallbackReason = "llm_error" | "invalid_response" | "target_vanished"
|
|
4506
|
+
type ConsolidationFallbackReason = "llm_error" | "llm_timeout" | "content_flagged" | "invalid_response" | "target_vanished"
|
|
4507
4507
|
/**
|
|
4508
4508
|
* A `supersede` was downgraded to `create` because the model's own stated
|
|
4509
4509
|
* subjects disagreed: the new fact is about someone other than the fact it
|
|
@@ -4542,6 +4542,7 @@ interface RetainOptions {
|
|
|
4542
4542
|
consolidateOptions?: PortalLlmAuth & {
|
|
4543
4543
|
baseUrl?: string;
|
|
4544
4544
|
model?: string;
|
|
4545
|
+
endpointOverride?: string;
|
|
4545
4546
|
/**
|
|
4546
4547
|
* Invoked when the consolidator degrades to its "create" fallback
|
|
4547
4548
|
* instead of returning a real decision — `llm_error` for network /
|
|
@@ -9174,6 +9175,7 @@ interface CreateAutoExtractorOptions {
|
|
|
9174
9175
|
baseUrl?: string;
|
|
9175
9176
|
/** Override the consolidation model. Default: see `consolidate.ts`. */
|
|
9176
9177
|
model?: string;
|
|
9178
|
+
endpointOverride?: string;
|
|
9177
9179
|
/**
|
|
9178
9180
|
* Notified on each degraded create-fallback (LLM failure or
|
|
9179
9181
|
* schema-violating response). See
|
package/dist/server/index.mjs
CHANGED
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
taskTypeHeader,
|
|
14
14
|
validateEndpointOverride,
|
|
15
15
|
withInternalFlowMarker
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-AU3Z7NBC.mjs";
|
|
17
17
|
import {
|
|
18
18
|
BASE_URL,
|
|
19
19
|
__commonJS,
|
|
@@ -15181,7 +15181,7 @@ function onKeyAvailable(address, callback) {
|
|
|
15181
15181
|
callbacks.add(callback);
|
|
15182
15182
|
return () => {
|
|
15183
15183
|
callbacks.delete(callback);
|
|
15184
|
-
if (callbacks.size === 0) {
|
|
15184
|
+
if (callbacks.size === 0 && keyAvailableCallbacks.get(address) === callbacks) {
|
|
15185
15185
|
keyAvailableCallbacks.delete(address);
|
|
15186
15186
|
}
|
|
15187
15187
|
};
|
|
@@ -31273,7 +31273,7 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
|
|
|
31273
31273
|
content: m.content,
|
|
31274
31274
|
similarity: m.similarity
|
|
31275
31275
|
}));
|
|
31276
|
-
const { consolidateMemory: doConsolidate } = await import("./consolidate-
|
|
31276
|
+
const { consolidateMemory: doConsolidate } = await import("./consolidate-B6OSCZU4.mjs");
|
|
31277
31277
|
const decision = await doConsolidate(trimmed, candidates, consolidateOptions);
|
|
31278
31278
|
if (decision.action === "create") return decision.fallbackReason ? null : { create: true };
|
|
31279
31279
|
if (decision.action === "supersede" && decision.content) {
|
|
@@ -31989,7 +31989,12 @@ function createAutoExtractor(options) {
|
|
|
31989
31989
|
...baseUrl !== void 0 && { baseUrl }
|
|
31990
31990
|
};
|
|
31991
31991
|
};
|
|
31992
|
-
const
|
|
31992
|
+
const consolidateEndpoint = options.consolidate?.endpointOverride ?? options.extract.endpointOverride;
|
|
31993
|
+
const consolidateOptions = options.consolidate ? {
|
|
31994
|
+
...options.consolidate,
|
|
31995
|
+
...subPassAuth(options.consolidate.baseUrl),
|
|
31996
|
+
...consolidateEndpoint !== void 0 && { endpointOverride: consolidateEndpoint }
|
|
31997
|
+
} : void 0;
|
|
31993
31998
|
const injectionClassifierOptions = options.injectionClassifier ? { ...options.injectionClassifier, ...subPassAuth(options.injectionClassifier.baseUrl) } : void 0;
|
|
31994
31999
|
if (!options.memoryStore && options.retainCtx.vaultCtx.entityCtx && !options.entityCtx) {
|
|
31995
32000
|
getLogger().warn(
|
|
@@ -35151,10 +35156,20 @@ function batchError(result) {
|
|
|
35151
35156
|
var AccountFailureError = class extends Error {
|
|
35152
35157
|
};
|
|
35153
35158
|
var LockedSourcesError = class extends Error {
|
|
35154
|
-
constructor(persistentIds) {
|
|
35155
|
-
|
|
35159
|
+
constructor(persistentIds, locked) {
|
|
35160
|
+
const counts = /* @__PURE__ */ new Map();
|
|
35161
|
+
for (const message of locked) {
|
|
35162
|
+
const version = /^enc:(v\d+):/.exec(message.content)?.[1] ?? "unknown";
|
|
35163
|
+
const key = `${message.decryptionStatus ?? "no_status"}:${version}`;
|
|
35164
|
+
counts.set(key, (counts.get(key) ?? 0) + 1);
|
|
35165
|
+
}
|
|
35166
|
+
const summary = [...counts].map(([key, count]) => `${key}=${count}`).join(", ");
|
|
35167
|
+
super(`Source messages are locked; retained for retry (${summary})`);
|
|
35156
35168
|
this.persistentIds = persistentIds;
|
|
35157
35169
|
}
|
|
35170
|
+
get awaitingKey() {
|
|
35171
|
+
return this.persistentIds.length === 0;
|
|
35172
|
+
}
|
|
35158
35173
|
};
|
|
35159
35174
|
function splitTurns(messages) {
|
|
35160
35175
|
const turns = [];
|
|
@@ -35208,6 +35223,8 @@ function createDurableAutoExtractor(options) {
|
|
|
35208
35223
|
const attempts = /* @__PURE__ */ new Map();
|
|
35209
35224
|
const sessionFailures = /* @__PURE__ */ new Map();
|
|
35210
35225
|
const skippedThisSession = /* @__PURE__ */ new Set();
|
|
35226
|
+
const awaitingKey = /* @__PURE__ */ new Set();
|
|
35227
|
+
let keyEpoch = 0;
|
|
35211
35228
|
const clock = options.now ?? Date.now;
|
|
35212
35229
|
const reportError = (error, conversationId) => {
|
|
35213
35230
|
try {
|
|
@@ -35401,13 +35418,15 @@ function createDurableAutoExtractor(options) {
|
|
|
35401
35418
|
for (const job of pending) {
|
|
35402
35419
|
if (disposed) break;
|
|
35403
35420
|
const attempted = attempts.get(job.id) ?? 0;
|
|
35404
|
-
if (attempted >= MAX_ATTEMPTS || skippedThisSession.has(job.id))
|
|
35421
|
+
if (attempted >= MAX_ATTEMPTS || skippedThisSession.has(job.id) || awaitingKey.has(job.id))
|
|
35422
|
+
continue;
|
|
35405
35423
|
if (processed >= MAX_JOBS_PER_PASS) {
|
|
35406
35424
|
scheduleAfterSuccess = true;
|
|
35407
35425
|
break;
|
|
35408
35426
|
}
|
|
35409
35427
|
processed++;
|
|
35410
35428
|
const conversationId = String(job._getRaw("conversation_id"));
|
|
35429
|
+
const epochAtRead = keyEpoch;
|
|
35411
35430
|
let ids = [];
|
|
35412
35431
|
let loaded = [];
|
|
35413
35432
|
try {
|
|
@@ -35461,12 +35480,15 @@ function createDurableAutoExtractor(options) {
|
|
|
35461
35480
|
);
|
|
35462
35481
|
continue;
|
|
35463
35482
|
}
|
|
35464
|
-
const locked = loaded.filter(
|
|
35483
|
+
const locked = loaded.filter(
|
|
35484
|
+
(message) => !!message && isEncrypted(message.content)
|
|
35485
|
+
);
|
|
35465
35486
|
if (locked.length) {
|
|
35466
35487
|
throw new LockedSourcesError(
|
|
35467
35488
|
locked.flatMap(
|
|
35468
35489
|
(message) => message.decryptionStatus === "auth_mismatch" || message.decryptionStatus === "invalid_payload" ? [message.uniqueId] : []
|
|
35469
|
-
)
|
|
35490
|
+
),
|
|
35491
|
+
locked
|
|
35470
35492
|
);
|
|
35471
35493
|
}
|
|
35472
35494
|
const messages = loaded.flatMap(
|
|
@@ -35520,6 +35542,12 @@ function createDurableAutoExtractor(options) {
|
|
|
35520
35542
|
scheduleAfterSuccess = true;
|
|
35521
35543
|
} catch (error) {
|
|
35522
35544
|
if (disposed) break;
|
|
35545
|
+
if (error instanceof LockedSourcesError && error.awaitingKey) {
|
|
35546
|
+
reportError(error, conversationId);
|
|
35547
|
+
if (keyEpoch === epochAtRead) awaitingKey.add(job.id);
|
|
35548
|
+
else scheduleAfterSuccess = true;
|
|
35549
|
+
continue;
|
|
35550
|
+
}
|
|
35523
35551
|
attempts.set(job.id, attempted + 1);
|
|
35524
35552
|
retry = true;
|
|
35525
35553
|
reportError(error, conversationId);
|
|
@@ -35547,7 +35575,18 @@ function createDurableAutoExtractor(options) {
|
|
|
35547
35575
|
activeBatch?.abort(options.signal?.reason);
|
|
35548
35576
|
if (timer !== void 0) clearTimeout(timer);
|
|
35549
35577
|
options.signal?.removeEventListener("abort", dispose);
|
|
35578
|
+
unsubscribeKey?.();
|
|
35550
35579
|
}
|
|
35580
|
+
const unsubscribeKey = vault.walletAddress ? onKeyAvailable(vault.walletAddress, () => {
|
|
35581
|
+
keyEpoch++;
|
|
35582
|
+
if (!awaitingKey.size) return;
|
|
35583
|
+
awaitingKey.clear();
|
|
35584
|
+
if (timer !== void 0) {
|
|
35585
|
+
clearTimeout(timer);
|
|
35586
|
+
timer = void 0;
|
|
35587
|
+
}
|
|
35588
|
+
schedule(0);
|
|
35589
|
+
}) : void 0;
|
|
35551
35590
|
if (options.signal?.aborted) dispose();
|
|
35552
35591
|
else options.signal?.addEventListener("abort", dispose, { once: true });
|
|
35553
35592
|
schedule(0);
|
|
@@ -35637,6 +35676,7 @@ function createDurableAutoExtractor(options) {
|
|
|
35637
35676
|
(r) => r._setRaw("message_ids", JSON.stringify([.../* @__PURE__ */ new Set([...idsOf(job), ...fresh])]))
|
|
35638
35677
|
);
|
|
35639
35678
|
attempts.delete(job.id);
|
|
35679
|
+
awaitingKey.delete(job.id);
|
|
35640
35680
|
} else {
|
|
35641
35681
|
await jobs.create((r) => {
|
|
35642
35682
|
r._setRaw("owner_key", owner);
|