@reinsjs/lowering-fetch 0.5.1 → 0.5.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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @reinsjs/lowering-fetch
2
2
 
3
+ ## 0.5.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 2569456: Tool call arguments that the model double-encoded as a JSON string are now unwrapped one level on the read side when the inner value is a plain object (tolerating raw control characters such as unescaped newlines inside string literals), and the `core.tool_call` payload records `meta: { argumentsUnwrapped: true }`. Arguments that do not decode to an object are stored as the original wire text, so `args` is a string only when it is exactly what the model sent; previously the tool could receive a string while the replayed history showed a different value. The Anthropic Messages line no longer replaces a string `content_block_start.input` with `{}`. core adds `decodeToolArgumentsText` / `unwrapToolArguments` / `toolCallArgumentsMeta` and the optional `ToolCallPayload.meta` field.
8
+ - Updated dependencies [2569456]
9
+ - @reinsjs/core@0.7.0
10
+
3
11
  ## 0.5.1
4
12
 
5
13
  ### Patch Changes
package/dist/index.js CHANGED
@@ -1,3 +1,10 @@
1
+ // src/anthropic/from-stream.ts
2
+ import {
3
+ decodeToolArgumentsText,
4
+ toolCallArgumentsMeta,
5
+ unwrapToolArguments
6
+ } from "@reinsjs/core";
7
+
1
8
  // src/usage.ts
2
9
  function costOf(usage, cost) {
3
10
  if (!cost) return void 0;
@@ -13,13 +20,10 @@ function str(v) {
13
20
  function num(v) {
14
21
  return typeof v === "number" && Number.isFinite(v) ? v : void 0;
15
22
  }
16
- function parseInput(json, fallback) {
17
- if (json.trim() === "") return typeof fallback === "object" && fallback !== null ? fallback : {};
18
- try {
19
- return JSON.parse(json);
20
- } catch {
21
- return json;
22
- }
23
+ function decodeInput(json, fallback) {
24
+ if (json.trim() !== "") return decodeToolArgumentsText(json);
25
+ if (typeof fallback === "string") return unwrapToolArguments(fallback);
26
+ return { args: typeof fallback === "object" && fallback !== null ? fallback : {}, unwrapped: false };
23
27
  }
24
28
  var AnthropicAssembly = class {
25
29
  blocks = /* @__PURE__ */ new Map();
@@ -54,14 +58,21 @@ var AnthropicAssembly = class {
54
58
  if (b.text.length > 0)
55
59
  out.push({ type: "core.model_text", actor: "model", payload: { text: b.text }, replay });
56
60
  break;
57
- case "tool_use":
61
+ case "tool_use": {
62
+ const decoded = decodeInput(b.json, b.input);
58
63
  out.push({
59
64
  type: "core.tool_call",
60
65
  actor: "model",
61
- payload: { toolCallId: b.id, name: b.name, args: parseInput(b.json, b.input) },
66
+ payload: {
67
+ toolCallId: b.id,
68
+ name: b.name,
69
+ args: decoded.args,
70
+ ...toolCallArgumentsMeta(decoded)
71
+ },
62
72
  replay
63
73
  });
64
74
  break;
75
+ }
65
76
  case "other":
66
77
  break;
67
78
  }
@@ -1072,6 +1083,10 @@ function capabilitiesOf(model) {
1072
1083
  }
1073
1084
 
1074
1085
  // src/chat/from-stream.ts
1086
+ import {
1087
+ decodeToolArgumentsText as decodeToolArgumentsText2,
1088
+ toolCallArgumentsMeta as toolCallArgumentsMeta2
1089
+ } from "@reinsjs/core";
1075
1090
  var ChatAssembly = class {
1076
1091
  reasoning = "";
1077
1092
  text = "";
@@ -1097,24 +1112,17 @@ var ChatAssembly = class {
1097
1112
  if (this.text.length > 0)
1098
1113
  out.push({ type: "core.model_text", actor: "model", payload: { text: this.text }, replay });
1099
1114
  for (const [, c] of [...this.calls.entries()].sort((a, b) => a[0] - b[0])) {
1115
+ const decoded = decodeToolArgumentsText2(c.args);
1100
1116
  out.push({
1101
1117
  type: "core.tool_call",
1102
1118
  actor: "model",
1103
- payload: { toolCallId: c.id, name: c.name, args: parseArguments(c.args) },
1119
+ payload: { toolCallId: c.id, name: c.name, args: decoded.args, ...toolCallArgumentsMeta2(decoded) },
1104
1120
  replay
1105
1121
  });
1106
1122
  }
1107
1123
  return out;
1108
1124
  }
1109
1125
  };
1110
- function parseArguments(raw) {
1111
- if (raw.trim() === "") return {};
1112
- try {
1113
- return JSON.parse(raw);
1114
- } catch {
1115
- return raw;
1116
- }
1117
- }
1118
1126
  function num2(v) {
1119
1127
  return typeof v === "number" && Number.isFinite(v) ? v : void 0;
1120
1128
  }
@@ -1688,20 +1696,16 @@ function endpointOf(model) {
1688
1696
  }
1689
1697
 
1690
1698
  // src/responses/from-stream.ts
1699
+ import {
1700
+ decodeToolArgumentsText as decodeToolArgumentsText3,
1701
+ toolCallArgumentsMeta as toolCallArgumentsMeta3
1702
+ } from "@reinsjs/core";
1691
1703
  function str2(v) {
1692
1704
  return typeof v === "string" ? v : void 0;
1693
1705
  }
1694
1706
  function num3(v) {
1695
1707
  return typeof v === "number" && Number.isFinite(v) ? v : void 0;
1696
1708
  }
1697
- function parseArguments2(raw) {
1698
- if (raw.trim() === "") return {};
1699
- try {
1700
- return JSON.parse(raw);
1701
- } catch {
1702
- return raw;
1703
- }
1704
- }
1705
1709
  function reasoningText(item, fallback) {
1706
1710
  if (!item) return fallback;
1707
1711
  const summary = (item.summary ?? []).map((s) => str2(s.text) ?? "").filter((t) => t.length > 0);
@@ -1810,15 +1814,22 @@ var ResponsesAssembly = class {
1810
1814
  if (s.phase) replay.phase = s.phase;
1811
1815
  out.push({ type: "core.model_text", actor: "model", payload: { text: s.text }, replay });
1812
1816
  break;
1813
- case "function_call":
1817
+ case "function_call": {
1814
1818
  if (s.id) replay.itemId = s.id;
1819
+ const decoded = decodeToolArgumentsText3(s.args);
1815
1820
  out.push({
1816
1821
  type: "core.tool_call",
1817
1822
  actor: "model",
1818
- payload: { toolCallId: s.callId, name: s.name, args: parseArguments2(s.args) },
1823
+ payload: {
1824
+ toolCallId: s.callId,
1825
+ name: s.name,
1826
+ args: decoded.args,
1827
+ ...toolCallArgumentsMeta3(decoded)
1828
+ },
1819
1829
  replay
1820
1830
  });
1821
1831
  break;
1832
+ }
1822
1833
  case "other":
1823
1834
  break;
1824
1835
  }