@reinsjs/lowering-fetch 0.6.5 → 0.6.6
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/CHANGELOG.md +6 -0
- package/dist/index.js +20 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @reinsjs/lowering-fetch
|
|
2
2
|
|
|
3
|
+
## 0.6.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- b4ab2b8: Chat Completions: a turn that holds only thinking (cut off by a stop or a broken stream before any text or tool call) is no longer sent as an assistant message with neither `content` nor `tool_calls`. DeepSeek and OpenAI reject that message with 400, and because the timeline is replayed whole, every later request in the session failed. The whole turn is now left out and its thinking is declared `dropped` in the landings. Sessions already stuck on such a turn recover on the next request with no data repair.
|
|
8
|
+
|
|
3
9
|
## 0.6.5
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -386,7 +386,8 @@ var CHAT_LOSS_MATRIX = {
|
|
|
386
386
|
"merged-text",
|
|
387
387
|
"multiple text segments of one turn are merged into a single string (assistant.content can only be a string)",
|
|
388
388
|
"the turn holds more than one text segment"
|
|
389
|
-
)
|
|
389
|
+
),
|
|
390
|
+
dropped("none", "an empty text segment is not sent (it does not count as content)")
|
|
390
391
|
],
|
|
391
392
|
"core.model_thinking": [
|
|
392
393
|
exact(
|
|
@@ -396,7 +397,7 @@ var CHAT_LOSS_MATRIX = {
|
|
|
396
397
|
),
|
|
397
398
|
dropped(
|
|
398
399
|
"none",
|
|
399
|
-
"Chat Completions has no landing for replaying thinking (no signature, no encrypted item),
|
|
400
|
+
"Chat Completions has no landing for replaying thinking (no signature, no encrypted item), the source is another family, or the turn holds only thinking (a turn cut off while thinking is not sent at all: an assistant message needs content or tool_calls)"
|
|
400
401
|
)
|
|
401
402
|
],
|
|
402
403
|
"core.tool_call": [exact("tool_calls", "arguments is a JSON string")],
|
|
@@ -1410,6 +1411,8 @@ function liftedAttachment(item, media) {
|
|
|
1410
1411
|
const body = media.flatMap((m, i) => [{ type: "text", text: `${m.type} ${i + 1}:` }, m]);
|
|
1411
1412
|
return [header, ...item.untrustedSource ? markUntrusted2(body, item.untrustedSource).parts : body];
|
|
1412
1413
|
}
|
|
1414
|
+
var THINKING_ONLY_NOTE = "the turn holds only thinking (it was cut off before any text or tool call), and an assistant message needs content or tool_calls, so the whole turn is not sent";
|
|
1415
|
+
var EMPTY_TEXT_NOTE = "the text segment is empty, so it is not sent";
|
|
1413
1416
|
function argumentsOf(args) {
|
|
1414
1417
|
return typeof args === "string" ? args : JSON.stringify(args ?? {});
|
|
1415
1418
|
}
|
|
@@ -1428,7 +1431,7 @@ function encodeChatRequest(input) {
|
|
|
1428
1431
|
};
|
|
1429
1432
|
if (input.systemPrompt) messages.push({ role: "system", content: input.systemPrompt });
|
|
1430
1433
|
for (const item of input.ir) {
|
|
1431
|
-
if (item.kind !== "tool_result" && item.kind !== "dropped") releaseLifted();
|
|
1434
|
+
if (item.kind !== "tool_result" && item.kind !== "dropped" && item.kind !== "assistant") releaseLifted();
|
|
1432
1435
|
switch (item.kind) {
|
|
1433
1436
|
case "user": {
|
|
1434
1437
|
const c = userContent(item.parts, capabilities);
|
|
@@ -1447,7 +1450,10 @@ function encodeChatRequest(input) {
|
|
|
1447
1450
|
break;
|
|
1448
1451
|
}
|
|
1449
1452
|
case "assistant": {
|
|
1450
|
-
|
|
1453
|
+
const msg = assistantMessage(item.blocks, item.origin, target, reasoningContent, landings);
|
|
1454
|
+
if (!msg) break;
|
|
1455
|
+
releaseLifted();
|
|
1456
|
+
messages.push(msg);
|
|
1451
1457
|
break;
|
|
1452
1458
|
}
|
|
1453
1459
|
case "tool_result": {
|
|
@@ -1540,10 +1546,19 @@ function encodeChatRequest(input) {
|
|
|
1540
1546
|
return { body, landings: orderLandings(input.events, landings) };
|
|
1541
1547
|
}
|
|
1542
1548
|
function assistantMessage(blocks, origin, target, reasoningContent, landings) {
|
|
1543
|
-
const texts =
|
|
1549
|
+
const texts = [];
|
|
1550
|
+
for (const b of blocks) {
|
|
1551
|
+
if (b.type !== "text") continue;
|
|
1552
|
+
if (b.text.length === 0) land2(landings, b.event, "dropped", "none", EMPTY_TEXT_NOTE);
|
|
1553
|
+
else texts.push(b);
|
|
1554
|
+
}
|
|
1544
1555
|
const thinkings = blocks.filter((b) => b.type === "thinking");
|
|
1545
1556
|
const calls = blocks.filter((b) => b.type === "tool_call");
|
|
1546
1557
|
const foreign = foreignOrigin(origin, target);
|
|
1558
|
+
if (texts.length === 0 && calls.length === 0) {
|
|
1559
|
+
for (const t of thinkings) land2(landings, t.event, "dropped", "none", THINKING_ONLY_NOTE);
|
|
1560
|
+
return void 0;
|
|
1561
|
+
}
|
|
1547
1562
|
for (const t of texts) {
|
|
1548
1563
|
if (texts.length > 1)
|
|
1549
1564
|
land2(
|