@reinsjs/lowering-fetch 0.6.4 → 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 CHANGED
@@ -1,5 +1,26 @@
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
+
9
+ ## 0.6.5
10
+
11
+ ### Patch Changes
12
+
13
+ - 884c840: Session run status. Every `runLoop` run now starts with `core.tools_bound` (carrying `marksEnd: true`) and ends with exactly one end marker: `core.run_paused` as before, or the new model-invisible `core.run_ended` with `status: "done" | "handoff" | "error"`. `core.run_paused` gains `awaiting` (the pending calls waiting on an approval — with `requestedAt` —, a client tool or a sub-agent) and `stopped: true` for a user stop. A `core.error` the loop retries past, or one recorded for a throwing `pullInput`, gets no `run_ended`; an error that ends the run is written together with its `run_ended`.
14
+
15
+ `runStatusOf({ held, lastMarker })` classifies a session as running / paused / done / handoff / error / interrupted / idle / unknown from a lease flag and `lastRunMarker(timeline)`. `@reinsjs/store-pg` adds `pgRunStates(client, sessionIds)`: one SQL statement reads the leases and each session's last marker, so a session list never sees a gap between "lease released" and "outcome written". "Running" is only known for runs started through the server handler with a lease registry (`createAgent` + `pgStores`).
16
+
17
+ Log shape changes: on a resumed run `core.tools_bound` now comes before `core.run_resumed` / `core.approval_decision`, and `RunResult.lastSeq` of a done or handoff run points at its `run_ended`. Live streams carry one more event (a `CUSTOM` frame in AG-UI). The TanStack adapter writes `run_ended` too, but its `tools_bound` carries no `marksEnd` and its `run_paused` no `awaiting` / `stopped`. Lowerings drop `run_ended` like other operational events.
18
+
19
+ **Rolling upgrade:** `@reinsjs/core` 0.13 and earlier reject sessions that contain `core.run_ended` (unknown event type). Upgrade every instance to the same core version at once, and do not roll back past 0.14 once such sessions exist. Sessions whose last run finished before the upgrade read `unknown`.
20
+
21
+ - Updated dependencies [884c840]
22
+ - @reinsjs/core@0.14.0
23
+
3
24
  ## 0.6.4
4
25
 
5
26
  ### Patch Changes
package/dist/index.js CHANGED
@@ -352,6 +352,9 @@ var NOT_SENT = {
352
352
  "marks that a call began executing, for resume and stop handling; the model learns the outcome from tool_result"
353
353
  )
354
354
  ],
355
+ "core.run_ended": [
356
+ dropped("none", "marks how a run ended, for hosts tracking session status; the model never sees it")
357
+ ],
355
358
  "core.error": [
356
359
  dropped(
357
360
  "none",
@@ -383,7 +386,8 @@ var CHAT_LOSS_MATRIX = {
383
386
  "merged-text",
384
387
  "multiple text segments of one turn are merged into a single string (assistant.content can only be a string)",
385
388
  "the turn holds more than one text segment"
386
- )
389
+ ),
390
+ dropped("none", "an empty text segment is not sent (it does not count as content)")
387
391
  ],
388
392
  "core.model_thinking": [
389
393
  exact(
@@ -393,7 +397,7 @@ var CHAT_LOSS_MATRIX = {
393
397
  ),
394
398
  dropped(
395
399
  "none",
396
- "Chat Completions has no landing for replaying thinking (no signature, no encrypted item), or the source is another family"
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)"
397
401
  )
398
402
  ],
399
403
  "core.tool_call": [exact("tool_calls", "arguments is a JSON string")],
@@ -703,6 +707,7 @@ function eventsToIr(input) {
703
707
  case "core.handoff":
704
708
  case "core.tools_bound":
705
709
  case "core.tool_started":
710
+ case "core.run_ended":
706
711
  case "core.error":
707
712
  items.push({ kind: "dropped", event: e, note: NOT_SENT_NOTE });
708
713
  break;
@@ -1406,6 +1411,8 @@ function liftedAttachment(item, media) {
1406
1411
  const body = media.flatMap((m, i) => [{ type: "text", text: `${m.type} ${i + 1}:` }, m]);
1407
1412
  return [header, ...item.untrustedSource ? markUntrusted2(body, item.untrustedSource).parts : body];
1408
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";
1409
1416
  function argumentsOf(args) {
1410
1417
  return typeof args === "string" ? args : JSON.stringify(args ?? {});
1411
1418
  }
@@ -1424,7 +1431,7 @@ function encodeChatRequest(input) {
1424
1431
  };
1425
1432
  if (input.systemPrompt) messages.push({ role: "system", content: input.systemPrompt });
1426
1433
  for (const item of input.ir) {
1427
- if (item.kind !== "tool_result" && item.kind !== "dropped") releaseLifted();
1434
+ if (item.kind !== "tool_result" && item.kind !== "dropped" && item.kind !== "assistant") releaseLifted();
1428
1435
  switch (item.kind) {
1429
1436
  case "user": {
1430
1437
  const c = userContent(item.parts, capabilities);
@@ -1443,7 +1450,10 @@ function encodeChatRequest(input) {
1443
1450
  break;
1444
1451
  }
1445
1452
  case "assistant": {
1446
- messages.push(assistantMessage(item.blocks, item.origin, target, reasoningContent, landings));
1453
+ const msg = assistantMessage(item.blocks, item.origin, target, reasoningContent, landings);
1454
+ if (!msg) break;
1455
+ releaseLifted();
1456
+ messages.push(msg);
1447
1457
  break;
1448
1458
  }
1449
1459
  case "tool_result": {
@@ -1536,10 +1546,19 @@ function encodeChatRequest(input) {
1536
1546
  return { body, landings: orderLandings(input.events, landings) };
1537
1547
  }
1538
1548
  function assistantMessage(blocks, origin, target, reasoningContent, landings) {
1539
- const texts = blocks.filter((b) => b.type === "text");
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
+ }
1540
1555
  const thinkings = blocks.filter((b) => b.type === "thinking");
1541
1556
  const calls = blocks.filter((b) => b.type === "tool_call");
1542
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
+ }
1543
1562
  for (const t of texts) {
1544
1563
  if (texts.length > 1)
1545
1564
  land2(