libfx 0.0.10-dev.1208.g8578e5771980 → 0.0.10-dev.1210.gf651bb13ae4d
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/README.md +6 -4
- package/fx-sdk.js +15 -0
- package/fx-term.wasm +0 -0
- package/node.cjs +14 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -73,12 +73,14 @@ blocks. It returns an async iterable of normalized events:
|
|
|
73
73
|
|
|
74
74
|
- `text_delta`
|
|
75
75
|
- `reasoning_delta` when supplied by the provider
|
|
76
|
-
- `tool_start`
|
|
76
|
+
- `tool_start` with `id`, `name`, and the tool's `input` object. Inputs over
|
|
77
|
+
64 KiB of JSON arrive as an `inputPreview` string prefix plus
|
|
78
|
+
`inputTruncated: true` instead; the tool still receives complete arguments.
|
|
77
79
|
- `tool_end`
|
|
78
80
|
|
|
79
|
-
Consume the turn while it runs, then await `turn.result`.
|
|
80
|
-
backpressured: a slow reader pauses production
|
|
81
|
-
event queue. Awaiting only `turn.result` can wait for an unread stream to drain.
|
|
81
|
+
Consume the turn while it runs, then await `turn.result`. Streamed text and
|
|
82
|
+
tool results are lossless and backpressured: a slow reader pauses production
|
|
83
|
+
instead of growing an unlimited event queue. Awaiting only `turn.result` can wait for an unread stream to drain.
|
|
82
84
|
If you only need the result, explicitly discard events:
|
|
83
85
|
|
|
84
86
|
```js
|
package/fx-sdk.js
CHANGED
|
@@ -28,6 +28,9 @@ const maxPromptImagesBytes = 8 * 1024 * 1024;
|
|
|
28
28
|
// envelope allowance covers the method key and request id.
|
|
29
29
|
const maxPromptFrameBytes = 8 * 1024 * 1024;
|
|
30
30
|
const promptFrameEnvelopeBytes = 128;
|
|
31
|
+
// tool_start events carry a bounded preview of the tool input; larger inputs
|
|
32
|
+
// are marked truncated instead of dropped or sent whole.
|
|
33
|
+
const maxToolStartInputBytes = 64 * 1024;
|
|
31
34
|
|
|
32
35
|
function boundedString(value, name, maxBytes, required) {
|
|
33
36
|
if (value === undefined && !required) return undefined;
|
|
@@ -1611,6 +1614,7 @@ export async function createFxAgent(options = {}) {
|
|
|
1611
1614
|
type: "tool_start",
|
|
1612
1615
|
id: update.toolCallId,
|
|
1613
1616
|
name: toolNames.get(update.toolCallId),
|
|
1617
|
+
...toolStartInput(update.rawInput),
|
|
1614
1618
|
};
|
|
1615
1619
|
}
|
|
1616
1620
|
if (update.sessionUpdate === "tool_call_update" &&
|
|
@@ -1661,6 +1665,17 @@ export async function createFxAgent(options = {}) {
|
|
|
1661
1665
|
return result;
|
|
1662
1666
|
}
|
|
1663
1667
|
|
|
1668
|
+
// The input object rides the event when it fits the preview budget; larger
|
|
1669
|
+
// inputs become a bounded JSON prefix plus an explicit marker.
|
|
1670
|
+
function toolStartInput(rawInput) {
|
|
1671
|
+
if (rawInput === undefined || rawInput === null) return {};
|
|
1672
|
+
const serialized = JSON.stringify(rawInput);
|
|
1673
|
+
if (serialized === undefined) return {};
|
|
1674
|
+
const bytes = encoder.encode(serialized);
|
|
1675
|
+
if (bytes.length <= maxToolStartInputBytes) return { input: rawInput };
|
|
1676
|
+
return { inputTruncated: true, inputPreview: decoder.decode(utf8Prefix(bytes, maxToolStartInputBytes)) };
|
|
1677
|
+
}
|
|
1678
|
+
|
|
1664
1679
|
function startTurn(input, promptOptions) {
|
|
1665
1680
|
const prompt = normalizePromptInput(input);
|
|
1666
1681
|
if (encoder.encode(JSON.stringify({ sessionId: "", prompt })).length + promptFrameEnvelopeBytes > maxPromptFrameBytes) {
|
package/fx-term.wasm
CHANGED
|
Binary file
|
package/node.cjs
CHANGED
|
@@ -200,6 +200,7 @@ var maxPromptImageDataBytes = 5 * 1024 * 1024;
|
|
|
200
200
|
var maxPromptImagesBytes = 8 * 1024 * 1024;
|
|
201
201
|
var maxPromptFrameBytes = 8 * 1024 * 1024;
|
|
202
202
|
var promptFrameEnvelopeBytes = 128;
|
|
203
|
+
var maxToolStartInputBytes = 64 * 1024;
|
|
203
204
|
function boundedString(value, name, maxBytes, required) {
|
|
204
205
|
if (value === undefined && !required)
|
|
205
206
|
return;
|
|
@@ -2015,7 +2016,8 @@ async function createFxAgent(options = {}) {
|
|
|
2015
2016
|
return {
|
|
2016
2017
|
type: "tool_start",
|
|
2017
2018
|
id: update.toolCallId,
|
|
2018
|
-
name: toolNames.get(update.toolCallId)
|
|
2019
|
+
name: toolNames.get(update.toolCallId),
|
|
2020
|
+
...toolStartInput(update.rawInput)
|
|
2019
2021
|
};
|
|
2020
2022
|
}
|
|
2021
2023
|
if (update.sessionUpdate === "tool_call_update" && (update.status === "completed" || update.status === "failed")) {
|
|
@@ -2081,6 +2083,17 @@ async function createFxAgent(options = {}) {
|
|
|
2081
2083
|
result.reasoningTokens = usage.reasoningTokens;
|
|
2082
2084
|
return result;
|
|
2083
2085
|
}
|
|
2086
|
+
function toolStartInput(rawInput) {
|
|
2087
|
+
if (rawInput === undefined || rawInput === null)
|
|
2088
|
+
return {};
|
|
2089
|
+
const serialized = JSON.stringify(rawInput);
|
|
2090
|
+
if (serialized === undefined)
|
|
2091
|
+
return {};
|
|
2092
|
+
const bytes = encoder.encode(serialized);
|
|
2093
|
+
if (bytes.length <= maxToolStartInputBytes)
|
|
2094
|
+
return { input: rawInput };
|
|
2095
|
+
return { inputTruncated: true, inputPreview: decoder.decode(utf8Prefix(bytes, maxToolStartInputBytes)) };
|
|
2096
|
+
}
|
|
2084
2097
|
function startTurn(input, promptOptions) {
|
|
2085
2098
|
const prompt = normalizePromptInput(input);
|
|
2086
2099
|
if (encoder.encode(JSON.stringify({ sessionId: "", prompt })).length + promptFrameEnvelopeBytes > maxPromptFrameBytes) {
|