@anuma/sdk 10.9.0 → 10.10.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/{consolidate-7QUL3TOE.mjs → consolidate-QBV3DDHU.mjs} +1 -1
- package/dist/expo/index.cjs +2493 -2168
- package/dist/expo/index.d.mts +958 -868
- package/dist/expo/index.d.ts +958 -868
- package/dist/expo/index.mjs +2013 -1692
- package/dist/react/index.cjs +115 -85
- package/dist/react/index.d.mts +711 -710
- package/dist/react/index.d.ts +711 -710
- package/dist/react/index.mjs +115 -85
- package/dist/server/index.cjs +19 -13
- package/dist/server/index.d.mts +4 -2
- package/dist/server/index.d.ts +4 -2
- package/dist/server/index.mjs +19 -13
- package/package.json +1 -1
- package/dist/expo/{chunk-4SOUKJD5.mjs → chunk-VNTEHEGI.mjs} +957 -957
package/dist/react/index.mjs
CHANGED
|
@@ -3538,7 +3538,7 @@ async function updateMessageErrorOp(ctx, uniqueId, error) {
|
|
|
3538
3538
|
}
|
|
3539
3539
|
await ctx.database.write(async () => {
|
|
3540
3540
|
await message.update((msg) => {
|
|
3541
|
-
msg._setRaw("error", error);
|
|
3541
|
+
msg._setRaw("error", error ?? "");
|
|
3542
3542
|
});
|
|
3543
3543
|
});
|
|
3544
3544
|
return messageToStored(message, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner);
|
|
@@ -6485,6 +6485,67 @@ async function openInboxItem(item, keyPair) {
|
|
|
6485
6485
|
}
|
|
6486
6486
|
return opened;
|
|
6487
6487
|
}
|
|
6488
|
+
function inboxReplaces(row, opened) {
|
|
6489
|
+
if (row.error) return true;
|
|
6490
|
+
return row.wasStopped === true && opened.status === "completed";
|
|
6491
|
+
}
|
|
6492
|
+
async function clearTurnErrors(backend, answer) {
|
|
6493
|
+
const parentId = answer.parentMessageId;
|
|
6494
|
+
if (parentId) {
|
|
6495
|
+
const [parent] = await backend.getMessagesByIds([parentId]);
|
|
6496
|
+
if (parent?.error) await backend.updateMessageError(parentId, null);
|
|
6497
|
+
}
|
|
6498
|
+
if (!answer.error) return answer;
|
|
6499
|
+
return await backend.updateMessageError(answer.uniqueId, null) ?? answer;
|
|
6500
|
+
}
|
|
6501
|
+
async function deliverInboxAnswers(options) {
|
|
6502
|
+
const { inbox, keyPair, backend, store } = options;
|
|
6503
|
+
const results = [];
|
|
6504
|
+
for (const item of await inbox.list()) {
|
|
6505
|
+
let opened;
|
|
6506
|
+
try {
|
|
6507
|
+
opened = await openInboxItem(item, keyPair);
|
|
6508
|
+
} catch (err) {
|
|
6509
|
+
results.push({
|
|
6510
|
+
id: item.id,
|
|
6511
|
+
conversationId: null,
|
|
6512
|
+
status: "unreadable",
|
|
6513
|
+
assistantMessage: null,
|
|
6514
|
+
error: err instanceof Error ? err.message : String(err)
|
|
6515
|
+
});
|
|
6516
|
+
continue;
|
|
6517
|
+
}
|
|
6518
|
+
const base = { id: item.id, conversationId: opened.conversation_id };
|
|
6519
|
+
try {
|
|
6520
|
+
const messageId = opened.assistant_message_id ?? `msg_bg_${opened.inference_id}`;
|
|
6521
|
+
const [found] = await backend.getMessagesByIds([messageId]);
|
|
6522
|
+
const existing = found && inboxReplaces(found, opened) ? void 0 : found;
|
|
6523
|
+
if (!found) {
|
|
6524
|
+
const parent = opened.parent_message_id;
|
|
6525
|
+
const ownsTurn = parent ? (await backend.getMessagesByIds([parent])).length > 0 : await backend.getConversation(opened.conversation_id) !== null;
|
|
6526
|
+
if (!ownsTurn) {
|
|
6527
|
+
results.push({ ...base, status: "elsewhere", assistantMessage: null });
|
|
6528
|
+
continue;
|
|
6529
|
+
}
|
|
6530
|
+
}
|
|
6531
|
+
const stored2 = existing ?? await store(opened, messageId);
|
|
6532
|
+
await inbox.remove(item.id);
|
|
6533
|
+
results.push({
|
|
6534
|
+
...base,
|
|
6535
|
+
status: existing ? "delivered" : "stored",
|
|
6536
|
+
assistantMessage: stored2
|
|
6537
|
+
});
|
|
6538
|
+
} catch (err) {
|
|
6539
|
+
results.push({
|
|
6540
|
+
...base,
|
|
6541
|
+
status: "retry",
|
|
6542
|
+
assistantMessage: null,
|
|
6543
|
+
error: err instanceof Error ? err.message : String(err)
|
|
6544
|
+
});
|
|
6545
|
+
}
|
|
6546
|
+
}
|
|
6547
|
+
return results;
|
|
6548
|
+
}
|
|
6488
6549
|
|
|
6489
6550
|
// src/lib/chat/reservationReceipts.ts
|
|
6490
6551
|
var ACTIONS = [
|
|
@@ -7961,6 +8022,13 @@ function createErrorResult(message, onError) {
|
|
|
7961
8022
|
function isAbortError(err) {
|
|
7962
8023
|
return err instanceof Error && err.name === "AbortError";
|
|
7963
8024
|
}
|
|
8025
|
+
var ProviderStreamError = class extends Error {
|
|
8026
|
+
constructor(message, code) {
|
|
8027
|
+
super(message);
|
|
8028
|
+
this.name = "ProviderStreamError";
|
|
8029
|
+
this.code = code;
|
|
8030
|
+
}
|
|
8031
|
+
};
|
|
7964
8032
|
function getInStreamErrorMessage(chunk) {
|
|
7965
8033
|
if (!chunk || typeof chunk !== "object") return null;
|
|
7966
8034
|
const obj = chunk;
|
|
@@ -8247,7 +8315,7 @@ var CompletionsStrategy = class {
|
|
|
8247
8315
|
processStreamChunk(chunk, accumulator) {
|
|
8248
8316
|
const result = { content: null, thinking: null };
|
|
8249
8317
|
const inStreamErr = getInStreamErrorMessage(chunk);
|
|
8250
|
-
if (inStreamErr) throw new
|
|
8318
|
+
if (inStreamErr) throw new ProviderStreamError(inStreamErr);
|
|
8251
8319
|
const rawChunk = chunk;
|
|
8252
8320
|
const typedChunk = rawChunk.response && rawChunk.type === "response" ? rawChunk.response : chunk;
|
|
8253
8321
|
if (typedChunk.id && !accumulator.responseId) {
|
|
@@ -9098,7 +9166,7 @@ var ResponsesStrategy = class {
|
|
|
9098
9166
|
const result = { content: null, thinking: null };
|
|
9099
9167
|
const typedChunk = chunk;
|
|
9100
9168
|
const inStreamErr = getInStreamErrorMessage(chunk);
|
|
9101
|
-
if (inStreamErr) throw new
|
|
9169
|
+
if (inStreamErr) throw new ProviderStreamError(inStreamErr);
|
|
9102
9170
|
if (typedChunk.type === "response.failed") {
|
|
9103
9171
|
const resp = typedChunk.response;
|
|
9104
9172
|
const err = resp?.error;
|
|
@@ -9115,9 +9183,12 @@ var ResponsesStrategy = class {
|
|
|
9115
9183
|
}
|
|
9116
9184
|
}
|
|
9117
9185
|
const label = code ? `[${code}] ` : "";
|
|
9118
|
-
throw new
|
|
9186
|
+
throw new ProviderStreamError(
|
|
9187
|
+
`${label}${message || "Upstream request failed"}`,
|
|
9188
|
+
code || void 0
|
|
9189
|
+
);
|
|
9119
9190
|
}
|
|
9120
|
-
throw new
|
|
9191
|
+
throw new ProviderStreamError("Upstream request failed (response.failed)");
|
|
9121
9192
|
}
|
|
9122
9193
|
if (typedChunk.type === "response" && typedChunk.response) {
|
|
9123
9194
|
const resp = typedChunk.response;
|
|
@@ -9741,13 +9812,6 @@ function isRetriableStreamError(err) {
|
|
|
9741
9812
|
if (msg.includes("connection refused") || msg.includes("connect error")) return true;
|
|
9742
9813
|
return false;
|
|
9743
9814
|
}
|
|
9744
|
-
var ProviderStreamError = class extends Error {
|
|
9745
|
-
constructor(message, code) {
|
|
9746
|
-
super(message);
|
|
9747
|
-
this.name = "ProviderStreamError";
|
|
9748
|
-
this.code = code;
|
|
9749
|
-
}
|
|
9750
|
-
};
|
|
9751
9815
|
function extractProviderStreamError(chunk) {
|
|
9752
9816
|
if (!chunk || typeof chunk !== "object") return null;
|
|
9753
9817
|
const errField = chunk.error;
|
|
@@ -10128,6 +10192,7 @@ async function runToolLoop(options) {
|
|
|
10128
10192
|
thinking: redactor.deAnonymize(acc.thinking)
|
|
10129
10193
|
}) : strategy.buildFinalResponse(acc);
|
|
10130
10194
|
const finalContentText = (acc) => redactor ? redactor.deAnonymize(acc.content) : acc.content;
|
|
10195
|
+
let streamingAccumulator = null;
|
|
10131
10196
|
try {
|
|
10132
10197
|
let sseError = null;
|
|
10133
10198
|
let apiTools = toolsToApiFormat(tools, resolved);
|
|
@@ -10279,6 +10344,7 @@ async function runToolLoop(options) {
|
|
|
10279
10344
|
}
|
|
10280
10345
|
});
|
|
10281
10346
|
accumulator = createStreamAccumulator(model || void 0);
|
|
10347
|
+
streamingAccumulator = accumulator;
|
|
10282
10348
|
contentSmoother = new StreamSmoother((text16) => {
|
|
10283
10349
|
if (emitData) emitData(text16);
|
|
10284
10350
|
}, smoothing);
|
|
@@ -10789,6 +10855,7 @@ Executing tool: ${toolInfo}
|
|
|
10789
10855
|
}
|
|
10790
10856
|
});
|
|
10791
10857
|
currentAccumulator = createStreamAccumulator(model || void 0);
|
|
10858
|
+
streamingAccumulator = currentAccumulator;
|
|
10792
10859
|
contContentSmoother = new StreamSmoother((text16) => {
|
|
10793
10860
|
if (emitData) emitData(text16);
|
|
10794
10861
|
}, smoothing);
|
|
@@ -10986,7 +11053,7 @@ Executing tool: ${toolInfo}
|
|
|
10986
11053
|
const statusCode = err instanceof Error && "statusCode" in err ? err.statusCode : void 0;
|
|
10987
11054
|
const connectionLost = !(err instanceof ProviderStreamError) && !(err instanceof SseError);
|
|
10988
11055
|
return {
|
|
10989
|
-
data: null,
|
|
11056
|
+
data: connectionLost && streamingAccumulator ? buildResponseFinal(streamingAccumulator) : null,
|
|
10990
11057
|
error: errorMsg,
|
|
10991
11058
|
statusCode,
|
|
10992
11059
|
...connectionLost ? { connectionLost: true } : {}
|
|
@@ -38233,82 +38300,45 @@ function useChatStorage(options) {
|
|
|
38233
38300
|
await inbox.putPublicKey(publicKey);
|
|
38234
38301
|
registeredInboxKeyRef.current = { inbox, publicKey };
|
|
38235
38302
|
}
|
|
38236
|
-
|
|
38237
|
-
|
|
38238
|
-
|
|
38239
|
-
|
|
38240
|
-
|
|
38241
|
-
|
|
38242
|
-
|
|
38243
|
-
|
|
38244
|
-
|
|
38245
|
-
|
|
38246
|
-
|
|
38247
|
-
|
|
38303
|
+
return deliverInboxAnswers({
|
|
38304
|
+
inbox,
|
|
38305
|
+
keyPair,
|
|
38306
|
+
backend,
|
|
38307
|
+
store: async (opened, messageId) => {
|
|
38308
|
+
const { redactor } = resolveCallPii(
|
|
38309
|
+
void 0,
|
|
38310
|
+
piiRedaction,
|
|
38311
|
+
() => getConversationRedactor(opened.conversation_id, nerDetectorRef.current)
|
|
38312
|
+
);
|
|
38313
|
+
const knownToolCallEventIds = await backend.getToolCallEventIds(opened.conversation_id);
|
|
38314
|
+
const { fields, fileIds } = await toAssistantMessageFields(
|
|
38315
|
+
opened.response,
|
|
38316
|
+
opened.conversation_id,
|
|
38317
|
+
knownToolCallEventIds
|
|
38318
|
+
);
|
|
38319
|
+
const upserted = await backend.upsertMessage({
|
|
38320
|
+
...fields,
|
|
38321
|
+
content: redactor ? redactor.deAnonymize(fields.content) : fields.content,
|
|
38322
|
+
thinking: redactor && fields.thinking ? redactor.deAnonymize(fields.thinking) : fields.thinking,
|
|
38323
|
+
conversationId: opened.conversation_id,
|
|
38324
|
+
role: "assistant",
|
|
38325
|
+
model: opened.model,
|
|
38326
|
+
parentMessageId: opened.parent_message_id ?? void 0,
|
|
38327
|
+
wasStopped: opened.status === "tool_request",
|
|
38328
|
+
uniqueId: messageId
|
|
38248
38329
|
});
|
|
38249
|
-
|
|
38250
|
-
|
|
38251
|
-
|
|
38252
|
-
|
|
38253
|
-
|
|
38254
|
-
|
|
38255
|
-
if (!existing) {
|
|
38256
|
-
const parent = opened.parent_message_id;
|
|
38257
|
-
const ownsTurn = parent ? (await backend.getMessagesByIds([parent])).length > 0 : await backend.getConversation(opened.conversation_id) !== null;
|
|
38258
|
-
if (!ownsTurn) {
|
|
38259
|
-
results.push({ ...base, status: "elsewhere", assistantMessage: null });
|
|
38260
|
-
continue;
|
|
38261
|
-
}
|
|
38262
|
-
}
|
|
38263
|
-
let stored2 = existing;
|
|
38264
|
-
if (!stored2) {
|
|
38265
|
-
const { redactor } = resolveCallPii(
|
|
38266
|
-
void 0,
|
|
38267
|
-
piiRedaction,
|
|
38268
|
-
() => getConversationRedactor(opened.conversation_id, nerDetectorRef.current)
|
|
38269
|
-
);
|
|
38270
|
-
const knownToolCallEventIds = await backend.getToolCallEventIds(opened.conversation_id);
|
|
38271
|
-
const { fields, fileIds } = await toAssistantMessageFields(
|
|
38272
|
-
opened.response,
|
|
38273
|
-
opened.conversation_id,
|
|
38274
|
-
knownToolCallEventIds
|
|
38275
|
-
);
|
|
38276
|
-
stored2 = await backend.createMessage({
|
|
38277
|
-
...fields,
|
|
38278
|
-
content: redactor ? redactor.deAnonymize(fields.content) : fields.content,
|
|
38279
|
-
thinking: redactor && fields.thinking ? redactor.deAnonymize(fields.thinking) : fields.thinking,
|
|
38280
|
-
conversationId: opened.conversation_id,
|
|
38281
|
-
role: "assistant",
|
|
38282
|
-
model: opened.model,
|
|
38283
|
-
parentMessageId: opened.parent_message_id ?? void 0,
|
|
38284
|
-
wasStopped: opened.status === "tool_request" ? true : void 0,
|
|
38285
|
-
uniqueId: messageId
|
|
38286
|
-
});
|
|
38287
|
-
if (fileIds.length > 0) {
|
|
38288
|
-
try {
|
|
38289
|
-
await updateMediaMessageIdBatchOp(mediaCtx, fileIds, stored2.uniqueId);
|
|
38290
|
-
} catch (err) {
|
|
38291
|
-
getLogger().warn("[useChatStorage] Failed to link inbox media:", err);
|
|
38292
|
-
}
|
|
38330
|
+
const stored2 = await clearTurnErrors(backend, upserted);
|
|
38331
|
+
if (fileIds.length > 0) {
|
|
38332
|
+
try {
|
|
38333
|
+
await updateMediaMessageIdBatchOp(mediaCtx, fileIds, stored2.uniqueId);
|
|
38334
|
+
} catch (err) {
|
|
38335
|
+
getLogger().warn("[useChatStorage] Failed to link inbox media:", err);
|
|
38293
38336
|
}
|
|
38294
|
-
void embedMessageAsync(stored2, (text16) => redactor ? redactor.maskText(text16) : text16);
|
|
38295
38337
|
}
|
|
38296
|
-
|
|
38297
|
-
|
|
38298
|
-
...base,
|
|
38299
|
-
status: existing ? "delivered" : "stored",
|
|
38300
|
-
assistantMessage: stored2
|
|
38301
|
-
});
|
|
38302
|
-
} catch (err) {
|
|
38303
|
-
results.push({
|
|
38304
|
-
...base,
|
|
38305
|
-
status: "retry",
|
|
38306
|
-
assistantMessage: null,
|
|
38307
|
-
error: err instanceof Error ? err.message : String(err)
|
|
38308
|
-
});
|
|
38338
|
+
void embedMessageAsync(stored2, (text16) => redactor ? redactor.maskText(text16) : text16);
|
|
38339
|
+
return stored2;
|
|
38309
38340
|
}
|
|
38310
|
-
}
|
|
38311
|
-
return results;
|
|
38341
|
+
});
|
|
38312
38342
|
}, [
|
|
38313
38343
|
inbox,
|
|
38314
38344
|
walletAddress,
|
package/dist/server/index.cjs
CHANGED
|
@@ -19113,7 +19113,7 @@ async function updateMessageErrorOp(ctx, uniqueId, error) {
|
|
|
19113
19113
|
}
|
|
19114
19114
|
await ctx.database.write(async () => {
|
|
19115
19115
|
await message.update((msg) => {
|
|
19116
|
-
msg._setRaw("error", error);
|
|
19116
|
+
msg._setRaw("error", error ?? "");
|
|
19117
19117
|
});
|
|
19118
19118
|
});
|
|
19119
19119
|
return messageToStored(message, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner);
|
|
@@ -22327,6 +22327,13 @@ function createStreamAccumulator(initialModel) {
|
|
|
22327
22327
|
function isAbortError(err) {
|
|
22328
22328
|
return err instanceof Error && err.name === "AbortError";
|
|
22329
22329
|
}
|
|
22330
|
+
var ProviderStreamError = class extends Error {
|
|
22331
|
+
constructor(message, code) {
|
|
22332
|
+
super(message);
|
|
22333
|
+
this.name = "ProviderStreamError";
|
|
22334
|
+
this.code = code;
|
|
22335
|
+
}
|
|
22336
|
+
};
|
|
22330
22337
|
function getInStreamErrorMessage(chunk) {
|
|
22331
22338
|
if (!chunk || typeof chunk !== "object") return null;
|
|
22332
22339
|
const obj = chunk;
|
|
@@ -22613,7 +22620,7 @@ var CompletionsStrategy = class {
|
|
|
22613
22620
|
processStreamChunk(chunk, accumulator) {
|
|
22614
22621
|
const result = { content: null, thinking: null };
|
|
22615
22622
|
const inStreamErr = getInStreamErrorMessage(chunk);
|
|
22616
|
-
if (inStreamErr) throw new
|
|
22623
|
+
if (inStreamErr) throw new ProviderStreamError(inStreamErr);
|
|
22617
22624
|
const rawChunk = chunk;
|
|
22618
22625
|
const typedChunk = rawChunk.response && rawChunk.type === "response" ? rawChunk.response : chunk;
|
|
22619
22626
|
if (typedChunk.id && !accumulator.responseId) {
|
|
@@ -23464,7 +23471,7 @@ var ResponsesStrategy = class {
|
|
|
23464
23471
|
const result = { content: null, thinking: null };
|
|
23465
23472
|
const typedChunk = chunk;
|
|
23466
23473
|
const inStreamErr = getInStreamErrorMessage(chunk);
|
|
23467
|
-
if (inStreamErr) throw new
|
|
23474
|
+
if (inStreamErr) throw new ProviderStreamError(inStreamErr);
|
|
23468
23475
|
if (typedChunk.type === "response.failed") {
|
|
23469
23476
|
const resp = typedChunk.response;
|
|
23470
23477
|
const err = resp?.error;
|
|
@@ -23481,9 +23488,12 @@ var ResponsesStrategy = class {
|
|
|
23481
23488
|
}
|
|
23482
23489
|
}
|
|
23483
23490
|
const label = code ? `[${code}] ` : "";
|
|
23484
|
-
throw new
|
|
23491
|
+
throw new ProviderStreamError(
|
|
23492
|
+
`${label}${message || "Upstream request failed"}`,
|
|
23493
|
+
code || void 0
|
|
23494
|
+
);
|
|
23485
23495
|
}
|
|
23486
|
-
throw new
|
|
23496
|
+
throw new ProviderStreamError("Upstream request failed (response.failed)");
|
|
23487
23497
|
}
|
|
23488
23498
|
if (typedChunk.type === "response" && typedChunk.response) {
|
|
23489
23499
|
const resp = typedChunk.response;
|
|
@@ -24107,13 +24117,6 @@ function isRetriableStreamError(err) {
|
|
|
24107
24117
|
if (msg.includes("connection refused") || msg.includes("connect error")) return true;
|
|
24108
24118
|
return false;
|
|
24109
24119
|
}
|
|
24110
|
-
var ProviderStreamError = class extends Error {
|
|
24111
|
-
constructor(message, code) {
|
|
24112
|
-
super(message);
|
|
24113
|
-
this.name = "ProviderStreamError";
|
|
24114
|
-
this.code = code;
|
|
24115
|
-
}
|
|
24116
|
-
};
|
|
24117
24120
|
function extractProviderStreamError(chunk) {
|
|
24118
24121
|
if (!chunk || typeof chunk !== "object") return null;
|
|
24119
24122
|
const errField = chunk.error;
|
|
@@ -24494,6 +24497,7 @@ async function runToolLoop(options) {
|
|
|
24494
24497
|
thinking: redactor.deAnonymize(acc.thinking)
|
|
24495
24498
|
}) : strategy.buildFinalResponse(acc);
|
|
24496
24499
|
const finalContentText = (acc) => redactor ? redactor.deAnonymize(acc.content) : acc.content;
|
|
24500
|
+
let streamingAccumulator = null;
|
|
24497
24501
|
try {
|
|
24498
24502
|
let sseError = null;
|
|
24499
24503
|
let apiTools = toolsToApiFormat(tools, resolved);
|
|
@@ -24645,6 +24649,7 @@ async function runToolLoop(options) {
|
|
|
24645
24649
|
}
|
|
24646
24650
|
});
|
|
24647
24651
|
accumulator = createStreamAccumulator(model || void 0);
|
|
24652
|
+
streamingAccumulator = accumulator;
|
|
24648
24653
|
contentSmoother = new StreamSmoother((text12) => {
|
|
24649
24654
|
if (emitData) emitData(text12);
|
|
24650
24655
|
}, smoothing);
|
|
@@ -25155,6 +25160,7 @@ Executing tool: ${toolInfo}
|
|
|
25155
25160
|
}
|
|
25156
25161
|
});
|
|
25157
25162
|
currentAccumulator = createStreamAccumulator(model || void 0);
|
|
25163
|
+
streamingAccumulator = currentAccumulator;
|
|
25158
25164
|
contContentSmoother = new StreamSmoother((text12) => {
|
|
25159
25165
|
if (emitData) emitData(text12);
|
|
25160
25166
|
}, smoothing);
|
|
@@ -25352,7 +25358,7 @@ Executing tool: ${toolInfo}
|
|
|
25352
25358
|
const statusCode = err instanceof Error && "statusCode" in err ? err.statusCode : void 0;
|
|
25353
25359
|
const connectionLost = !(err instanceof ProviderStreamError) && !(err instanceof SseError);
|
|
25354
25360
|
return {
|
|
25355
|
-
data: null,
|
|
25361
|
+
data: connectionLost && streamingAccumulator ? buildResponseFinal(streamingAccumulator) : null,
|
|
25356
25362
|
error: errorMsg,
|
|
25357
25363
|
statusCode,
|
|
25358
25364
|
...connectionLost ? { connectionLost: true } : {}
|
package/dist/server/index.d.mts
CHANGED
|
@@ -2301,6 +2301,8 @@ declare const INFERENCE_ID_HEADER = "X-Inference-ID";
|
|
|
2301
2301
|
*/
|
|
2302
2302
|
type StreamResumeHandle = {
|
|
2303
2303
|
inferenceId: string;
|
|
2304
|
+
/** The reply id the storage hook writes this turn's answer under, when it chose one. */
|
|
2305
|
+
assistantMessageId?: string;
|
|
2304
2306
|
/** The RESOLVED api type (never "auto") — resolveApiType() already ran inside runToolLoop. */
|
|
2305
2307
|
apiType: Exclude<ApiType, "auto">;
|
|
2306
2308
|
model?: string;
|
|
@@ -3868,7 +3870,7 @@ declare function stripLegacyChunkTextOp(ctx: StorageOperationsContext): Promise<
|
|
|
3868
3870
|
* sorted by `updatedAt`.
|
|
3869
3871
|
*/
|
|
3870
3872
|
declare function encryptToolCallEventsOp(ctx: StorageOperationsContext): Promise<number>;
|
|
3871
|
-
declare function updateMessageErrorOp(ctx: StorageOperationsContext, uniqueId: string, error: string): Promise<StoredMessage | null>;
|
|
3873
|
+
declare function updateMessageErrorOp(ctx: StorageOperationsContext, uniqueId: string, error: string | null): Promise<StoredMessage | null>;
|
|
3872
3874
|
/**
|
|
3873
3875
|
* Update the feedback (like/dislike) for a message.
|
|
3874
3876
|
* Each regenerated response can have its own independent feedback.
|
|
@@ -4057,7 +4059,7 @@ interface ChatStorageAdapter {
|
|
|
4057
4059
|
createMessage(options: CreateMessageOptions): Promise<StoredMessage>;
|
|
4058
4060
|
updateMessageEmbedding(uniqueId: string, vector: number[], embeddingModel: string): Promise<StoredMessage | null>;
|
|
4059
4061
|
updateMessageChunks(uniqueId: string, chunks: MessageChunk[], embeddingModel: string): Promise<StoredMessage | null>;
|
|
4060
|
-
updateMessageError(uniqueId: string, error: string): Promise<StoredMessage | null>;
|
|
4062
|
+
updateMessageError(uniqueId: string, error: string | null): Promise<StoredMessage | null>;
|
|
4061
4063
|
updateMessageFeedback(uniqueId: string, feedback: MessageFeedback): Promise<StoredMessage | null>;
|
|
4062
4064
|
/**
|
|
4063
4065
|
* Replace a message's attached media ids (`fileIds`). Used to attach a
|
package/dist/server/index.d.ts
CHANGED
|
@@ -2301,6 +2301,8 @@ declare const INFERENCE_ID_HEADER = "X-Inference-ID";
|
|
|
2301
2301
|
*/
|
|
2302
2302
|
type StreamResumeHandle = {
|
|
2303
2303
|
inferenceId: string;
|
|
2304
|
+
/** The reply id the storage hook writes this turn's answer under, when it chose one. */
|
|
2305
|
+
assistantMessageId?: string;
|
|
2304
2306
|
/** The RESOLVED api type (never "auto") — resolveApiType() already ran inside runToolLoop. */
|
|
2305
2307
|
apiType: Exclude<ApiType, "auto">;
|
|
2306
2308
|
model?: string;
|
|
@@ -3868,7 +3870,7 @@ declare function stripLegacyChunkTextOp(ctx: StorageOperationsContext): Promise<
|
|
|
3868
3870
|
* sorted by `updatedAt`.
|
|
3869
3871
|
*/
|
|
3870
3872
|
declare function encryptToolCallEventsOp(ctx: StorageOperationsContext): Promise<number>;
|
|
3871
|
-
declare function updateMessageErrorOp(ctx: StorageOperationsContext, uniqueId: string, error: string): Promise<StoredMessage | null>;
|
|
3873
|
+
declare function updateMessageErrorOp(ctx: StorageOperationsContext, uniqueId: string, error: string | null): Promise<StoredMessage | null>;
|
|
3872
3874
|
/**
|
|
3873
3875
|
* Update the feedback (like/dislike) for a message.
|
|
3874
3876
|
* Each regenerated response can have its own independent feedback.
|
|
@@ -4057,7 +4059,7 @@ interface ChatStorageAdapter {
|
|
|
4057
4059
|
createMessage(options: CreateMessageOptions): Promise<StoredMessage>;
|
|
4058
4060
|
updateMessageEmbedding(uniqueId: string, vector: number[], embeddingModel: string): Promise<StoredMessage | null>;
|
|
4059
4061
|
updateMessageChunks(uniqueId: string, chunks: MessageChunk[], embeddingModel: string): Promise<StoredMessage | null>;
|
|
4060
|
-
updateMessageError(uniqueId: string, error: string): Promise<StoredMessage | null>;
|
|
4062
|
+
updateMessageError(uniqueId: string, error: string | null): Promise<StoredMessage | null>;
|
|
4061
4063
|
updateMessageFeedback(uniqueId: string, feedback: MessageFeedback): Promise<StoredMessage | null>;
|
|
4062
4064
|
/**
|
|
4063
4065
|
* Replace a message's attached media ids (`fileIds`). Used to attach a
|
package/dist/server/index.mjs
CHANGED
|
@@ -17405,7 +17405,7 @@ async function updateMessageErrorOp(ctx, uniqueId, error) {
|
|
|
17405
17405
|
}
|
|
17406
17406
|
await ctx.database.write(async () => {
|
|
17407
17407
|
await message.update((msg) => {
|
|
17408
|
-
msg._setRaw("error", error);
|
|
17408
|
+
msg._setRaw("error", error ?? "");
|
|
17409
17409
|
});
|
|
17410
17410
|
});
|
|
17411
17411
|
return messageToStored(message, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner);
|
|
@@ -20596,6 +20596,13 @@ function createStreamAccumulator(initialModel) {
|
|
|
20596
20596
|
function isAbortError(err) {
|
|
20597
20597
|
return err instanceof Error && err.name === "AbortError";
|
|
20598
20598
|
}
|
|
20599
|
+
var ProviderStreamError = class extends Error {
|
|
20600
|
+
constructor(message, code) {
|
|
20601
|
+
super(message);
|
|
20602
|
+
this.name = "ProviderStreamError";
|
|
20603
|
+
this.code = code;
|
|
20604
|
+
}
|
|
20605
|
+
};
|
|
20599
20606
|
function getInStreamErrorMessage(chunk) {
|
|
20600
20607
|
if (!chunk || typeof chunk !== "object") return null;
|
|
20601
20608
|
const obj = chunk;
|
|
@@ -20882,7 +20889,7 @@ var CompletionsStrategy = class {
|
|
|
20882
20889
|
processStreamChunk(chunk, accumulator) {
|
|
20883
20890
|
const result = { content: null, thinking: null };
|
|
20884
20891
|
const inStreamErr = getInStreamErrorMessage(chunk);
|
|
20885
|
-
if (inStreamErr) throw new
|
|
20892
|
+
if (inStreamErr) throw new ProviderStreamError(inStreamErr);
|
|
20886
20893
|
const rawChunk = chunk;
|
|
20887
20894
|
const typedChunk = rawChunk.response && rawChunk.type === "response" ? rawChunk.response : chunk;
|
|
20888
20895
|
if (typedChunk.id && !accumulator.responseId) {
|
|
@@ -21733,7 +21740,7 @@ var ResponsesStrategy = class {
|
|
|
21733
21740
|
const result = { content: null, thinking: null };
|
|
21734
21741
|
const typedChunk = chunk;
|
|
21735
21742
|
const inStreamErr = getInStreamErrorMessage(chunk);
|
|
21736
|
-
if (inStreamErr) throw new
|
|
21743
|
+
if (inStreamErr) throw new ProviderStreamError(inStreamErr);
|
|
21737
21744
|
if (typedChunk.type === "response.failed") {
|
|
21738
21745
|
const resp = typedChunk.response;
|
|
21739
21746
|
const err = resp?.error;
|
|
@@ -21750,9 +21757,12 @@ var ResponsesStrategy = class {
|
|
|
21750
21757
|
}
|
|
21751
21758
|
}
|
|
21752
21759
|
const label = code ? `[${code}] ` : "";
|
|
21753
|
-
throw new
|
|
21760
|
+
throw new ProviderStreamError(
|
|
21761
|
+
`${label}${message || "Upstream request failed"}`,
|
|
21762
|
+
code || void 0
|
|
21763
|
+
);
|
|
21754
21764
|
}
|
|
21755
|
-
throw new
|
|
21765
|
+
throw new ProviderStreamError("Upstream request failed (response.failed)");
|
|
21756
21766
|
}
|
|
21757
21767
|
if (typedChunk.type === "response" && typedChunk.response) {
|
|
21758
21768
|
const resp = typedChunk.response;
|
|
@@ -22376,13 +22386,6 @@ function isRetriableStreamError(err) {
|
|
|
22376
22386
|
if (msg.includes("connection refused") || msg.includes("connect error")) return true;
|
|
22377
22387
|
return false;
|
|
22378
22388
|
}
|
|
22379
|
-
var ProviderStreamError = class extends Error {
|
|
22380
|
-
constructor(message, code) {
|
|
22381
|
-
super(message);
|
|
22382
|
-
this.name = "ProviderStreamError";
|
|
22383
|
-
this.code = code;
|
|
22384
|
-
}
|
|
22385
|
-
};
|
|
22386
22389
|
function extractProviderStreamError(chunk) {
|
|
22387
22390
|
if (!chunk || typeof chunk !== "object") return null;
|
|
22388
22391
|
const errField = chunk.error;
|
|
@@ -22763,6 +22766,7 @@ async function runToolLoop(options) {
|
|
|
22763
22766
|
thinking: redactor.deAnonymize(acc.thinking)
|
|
22764
22767
|
}) : strategy.buildFinalResponse(acc);
|
|
22765
22768
|
const finalContentText = (acc) => redactor ? redactor.deAnonymize(acc.content) : acc.content;
|
|
22769
|
+
let streamingAccumulator = null;
|
|
22766
22770
|
try {
|
|
22767
22771
|
let sseError = null;
|
|
22768
22772
|
let apiTools = toolsToApiFormat(tools, resolved);
|
|
@@ -22914,6 +22918,7 @@ async function runToolLoop(options) {
|
|
|
22914
22918
|
}
|
|
22915
22919
|
});
|
|
22916
22920
|
accumulator = createStreamAccumulator(model || void 0);
|
|
22921
|
+
streamingAccumulator = accumulator;
|
|
22917
22922
|
contentSmoother = new StreamSmoother((text12) => {
|
|
22918
22923
|
if (emitData) emitData(text12);
|
|
22919
22924
|
}, smoothing);
|
|
@@ -23424,6 +23429,7 @@ Executing tool: ${toolInfo}
|
|
|
23424
23429
|
}
|
|
23425
23430
|
});
|
|
23426
23431
|
currentAccumulator = createStreamAccumulator(model || void 0);
|
|
23432
|
+
streamingAccumulator = currentAccumulator;
|
|
23427
23433
|
contContentSmoother = new StreamSmoother((text12) => {
|
|
23428
23434
|
if (emitData) emitData(text12);
|
|
23429
23435
|
}, smoothing);
|
|
@@ -23621,7 +23627,7 @@ Executing tool: ${toolInfo}
|
|
|
23621
23627
|
const statusCode = err instanceof Error && "statusCode" in err ? err.statusCode : void 0;
|
|
23622
23628
|
const connectionLost = !(err instanceof ProviderStreamError) && !(err instanceof SseError);
|
|
23623
23629
|
return {
|
|
23624
|
-
data: null,
|
|
23630
|
+
data: connectionLost && streamingAccumulator ? buildResponseFinal(streamingAccumulator) : null,
|
|
23625
23631
|
error: errorMsg,
|
|
23626
23632
|
statusCode,
|
|
23627
23633
|
...connectionLost ? { connectionLost: true } : {}
|