libfx 0.0.9 → 0.0.10-dev.1203.gdf2292744991
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 +22 -3
- package/fx-core.wasm +0 -0
- package/fx-sdk.js +42 -1
- package/fx-term.wasm +0 -0
- package/libfx.darwin-arm64.node +0 -0
- package/libfx.darwin-x64.node +0 -0
- package/libfx.linux-arm64.node +0 -0
- package/libfx.linux-x64.node +0 -0
- package/node.cjs +35 -2
- package/node.js +3 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -41,9 +41,25 @@ await agent.close();
|
|
|
41
41
|
Agent configuration uses named options; `env` is reserved for
|
|
42
42
|
`createFxTerminal()`.
|
|
43
43
|
|
|
44
|
+
`effort` sets the reasoning effort for models that advertise effort levels. It
|
|
45
|
+
uses the same vocabulary as the fx CLI's `--effort` flag: `"default"` leaves
|
|
46
|
+
the choice to the model, and named levels such as `"low"`, `"medium"`,
|
|
47
|
+
`"high"`, or `"xhigh"` request a specific level. A named level is validated
|
|
48
|
+
against the selected model's advertised levels at creation; an unsupported
|
|
49
|
+
level rejects with an error (code `LIBFX_UNSUPPORTED_EFFORT`) naming the
|
|
50
|
+
supported set. When `effort` is omitted or `"default"`, the model default
|
|
51
|
+
applies.
|
|
52
|
+
|
|
53
|
+
`fast` enables the fast lane for models that advertise one, matching the fx
|
|
54
|
+
CLI's `--fast` flag. Enabling it is validated against the selected model at
|
|
55
|
+
creation; a model without a fast path rejects with an error (code
|
|
56
|
+
`LIBFX_UNSUPPORTED_FAST`). When `fast` is omitted or `false`, the model
|
|
57
|
+
default applies.
|
|
58
|
+
|
|
44
59
|
The host selects the model. Agent creation does not fetch the Gateway model
|
|
45
|
-
catalog
|
|
46
|
-
|
|
60
|
+
catalog unless `effort` requests a named level or `fast` is enabled. Prompting
|
|
61
|
+
can resolve model capabilities and context capacity through the supplied
|
|
62
|
+
`fetch`; fx caches that metadata for the agent.
|
|
47
63
|
|
|
48
64
|
`onEvent` receives runtime diagnostics separately from model output. Transport
|
|
49
65
|
events report request start, response status and elapsed time, safe Gateway
|
|
@@ -95,7 +111,10 @@ or a history change. The next prompt can run normally.
|
|
|
95
111
|
|
|
96
112
|
The checkpoint contains conversation history and usage only. The host owns
|
|
97
113
|
durable storage and must resupply models, credentials, instructions, tools,
|
|
98
|
-
MCP clients, and skill records.
|
|
114
|
+
MCP clients, and skill records. Reasoning effort and fast mode are
|
|
115
|
+
agent-creation options and are not stored in a checkpoint: recreate the agent
|
|
116
|
+
with new `effort` or `fast` values to change them, the same path as switching
|
|
117
|
+
models.
|
|
99
118
|
|
|
100
119
|
## Models
|
|
101
120
|
|
package/fx-core.wasm
CHANGED
|
Binary file
|
package/fx-sdk.js
CHANGED
|
@@ -10,6 +10,8 @@ const workspaceOutputLimit = 64 * 1024;
|
|
|
10
10
|
const maxInstructionsBytes = 64 * 1024;
|
|
11
11
|
const maxApiKeyBytes = 64 * 1024;
|
|
12
12
|
const maxModelBytes = 1024;
|
|
13
|
+
// Matches the kernel's ReasoningEffort.max_name_bytes.
|
|
14
|
+
const maxEffortBytes = 64;
|
|
13
15
|
const maxUrlBytes = 16 * 1024;
|
|
14
16
|
const maxModelCatalogBytes = 4 * 1024 * 1024;
|
|
15
17
|
const maxModelCatalogEntries = 10_000;
|
|
@@ -44,6 +46,27 @@ function validateGatewayChatUrl(value) {
|
|
|
44
46
|
}
|
|
45
47
|
}
|
|
46
48
|
|
|
49
|
+
// Mirrors the kernel's ReasoningEffort.parse: "auto"/"adaptive"/"default" pick
|
|
50
|
+
// the model default; anything else must be a bounded effort name.
|
|
51
|
+
function normalizeEffort(value) {
|
|
52
|
+
if (value === undefined) return undefined;
|
|
53
|
+
boundedString(value, "effort", maxEffortBytes, false);
|
|
54
|
+
if (!/^[A-Za-z0-9._-]+$/.test(value)) {
|
|
55
|
+
throw new TypeError('effort must use only letters, digits, ".", "-", or "_"');
|
|
56
|
+
}
|
|
57
|
+
return value;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Mirrors the CLI's --fast/--no-fast toggle: a strict boolean, with undefined
|
|
61
|
+
// leaving the model default in place.
|
|
62
|
+
function normalizeFast(value) {
|
|
63
|
+
if (value === undefined) return undefined;
|
|
64
|
+
if (typeof value !== "boolean") {
|
|
65
|
+
throw new TypeError("fast must be a boolean");
|
|
66
|
+
}
|
|
67
|
+
return value;
|
|
68
|
+
}
|
|
69
|
+
|
|
47
70
|
function normalizeAgentOptions(value) {
|
|
48
71
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
49
72
|
throw new TypeError("createFxAgent() options must be an object");
|
|
@@ -54,6 +77,8 @@ function normalizeAgentOptions(value) {
|
|
|
54
77
|
}
|
|
55
78
|
options.apiKey = boundedString(options.apiKey, "apiKey", maxApiKeyBytes, true);
|
|
56
79
|
options.model = boundedString(options.model, "model", maxModelBytes, false);
|
|
80
|
+
options.effort = normalizeEffort(options.effort);
|
|
81
|
+
options.fast = normalizeFast(options.fast);
|
|
57
82
|
validateGatewayChatUrl(options.gatewayChatUrl);
|
|
58
83
|
return options;
|
|
59
84
|
}
|
|
@@ -62,10 +87,26 @@ function agentEnvironment(options) {
|
|
|
62
87
|
return {
|
|
63
88
|
AI_GATEWAY_API_KEY: options.apiKey,
|
|
64
89
|
...(options.model === undefined ? {} : { FX_MODEL: options.model }),
|
|
90
|
+
...(options.effort === undefined ? {} : { FX_EFFORT: options.effort }),
|
|
91
|
+
...(options.fast === undefined ? {} : { FX_FAST: options.fast ? "true" : "false" }),
|
|
65
92
|
...(options.gatewayChatUrl === undefined ? {} : { FX_GATEWAY_CHAT_URL: options.gatewayChatUrl }),
|
|
66
93
|
};
|
|
67
94
|
}
|
|
68
95
|
|
|
96
|
+
// The kernel rejects an unsupported effort or fast lane during initialize;
|
|
97
|
+
// these messages originate only from that validation, so the rejection is
|
|
98
|
+
// safe to retype.
|
|
99
|
+
function agentBootstrapError(error) {
|
|
100
|
+
if (error instanceof Error &&
|
|
101
|
+
(error.message === "Invalid reasoning effort" || error.message.startsWith("Reasoning effort"))) {
|
|
102
|
+
error.code ??= "LIBFX_UNSUPPORTED_EFFORT";
|
|
103
|
+
}
|
|
104
|
+
if (error instanceof Error && error.message.startsWith("Fast mode")) {
|
|
105
|
+
error.code ??= "LIBFX_UNSUPPORTED_FAST";
|
|
106
|
+
}
|
|
107
|
+
return error;
|
|
108
|
+
}
|
|
109
|
+
|
|
69
110
|
async function cancelResponseBody(response) {
|
|
70
111
|
try {
|
|
71
112
|
await response.body?.cancel();
|
|
@@ -1490,7 +1531,7 @@ export async function createFxAgent(options = {}) {
|
|
|
1490
1531
|
try { runtime.abortHostEffects(); } catch {}
|
|
1491
1532
|
try { runtime.closeStdin(); } catch {}
|
|
1492
1533
|
try { await runtime.exited; } catch {}
|
|
1493
|
-
throw error;
|
|
1534
|
+
throw agentBootstrapError(error);
|
|
1494
1535
|
}
|
|
1495
1536
|
|
|
1496
1537
|
const agent = {
|
package/fx-term.wasm
CHANGED
|
Binary file
|
package/libfx.darwin-arm64.node
CHANGED
|
Binary file
|
package/libfx.darwin-x64.node
CHANGED
|
Binary file
|
package/libfx.linux-arm64.node
CHANGED
|
Binary file
|
package/libfx.linux-x64.node
CHANGED
|
Binary file
|
package/node.cjs
CHANGED
|
@@ -188,6 +188,7 @@ var workspaceOutputLimit = 64 * 1024;
|
|
|
188
188
|
var maxInstructionsBytes = 64 * 1024;
|
|
189
189
|
var maxApiKeyBytes = 64 * 1024;
|
|
190
190
|
var maxModelBytes = 1024;
|
|
191
|
+
var maxEffortBytes = 64;
|
|
191
192
|
var maxUrlBytes = 16 * 1024;
|
|
192
193
|
var maxModelCatalogBytes = 4 * 1024 * 1024;
|
|
193
194
|
var maxModelCatalogEntries = 1e4;
|
|
@@ -227,6 +228,23 @@ function validateGatewayChatUrl(value) {
|
|
|
227
228
|
throw new TypeError("gatewayChatUrl must use the canonical Gateway or explicit loopback HTTP");
|
|
228
229
|
}
|
|
229
230
|
}
|
|
231
|
+
function normalizeEffort(value) {
|
|
232
|
+
if (value === undefined)
|
|
233
|
+
return;
|
|
234
|
+
boundedString(value, "effort", maxEffortBytes, false);
|
|
235
|
+
if (!/^[A-Za-z0-9._-]+$/.test(value)) {
|
|
236
|
+
throw new TypeError('effort must use only letters, digits, ".", "-", or "_"');
|
|
237
|
+
}
|
|
238
|
+
return value;
|
|
239
|
+
}
|
|
240
|
+
function normalizeFast(value) {
|
|
241
|
+
if (value === undefined)
|
|
242
|
+
return;
|
|
243
|
+
if (typeof value !== "boolean") {
|
|
244
|
+
throw new TypeError("fast must be a boolean");
|
|
245
|
+
}
|
|
246
|
+
return value;
|
|
247
|
+
}
|
|
230
248
|
function normalizeAgentOptions(value) {
|
|
231
249
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
232
250
|
throw new TypeError("createFxAgent() options must be an object");
|
|
@@ -237,6 +255,8 @@ function normalizeAgentOptions(value) {
|
|
|
237
255
|
}
|
|
238
256
|
options.apiKey = boundedString(options.apiKey, "apiKey", maxApiKeyBytes, true);
|
|
239
257
|
options.model = boundedString(options.model, "model", maxModelBytes, false);
|
|
258
|
+
options.effort = normalizeEffort(options.effort);
|
|
259
|
+
options.fast = normalizeFast(options.fast);
|
|
240
260
|
validateGatewayChatUrl(options.gatewayChatUrl);
|
|
241
261
|
return options;
|
|
242
262
|
}
|
|
@@ -244,9 +264,20 @@ function agentEnvironment(options) {
|
|
|
244
264
|
return {
|
|
245
265
|
AI_GATEWAY_API_KEY: options.apiKey,
|
|
246
266
|
...options.model === undefined ? {} : { FX_MODEL: options.model },
|
|
267
|
+
...options.effort === undefined ? {} : { FX_EFFORT: options.effort },
|
|
268
|
+
...options.fast === undefined ? {} : { FX_FAST: options.fast ? "true" : "false" },
|
|
247
269
|
...options.gatewayChatUrl === undefined ? {} : { FX_GATEWAY_CHAT_URL: options.gatewayChatUrl }
|
|
248
270
|
};
|
|
249
271
|
}
|
|
272
|
+
function agentBootstrapError(error) {
|
|
273
|
+
if (error instanceof Error && (error.message === "Invalid reasoning effort" || error.message.startsWith("Reasoning effort"))) {
|
|
274
|
+
error.code ??= "LIBFX_UNSUPPORTED_EFFORT";
|
|
275
|
+
}
|
|
276
|
+
if (error instanceof Error && error.message.startsWith("Fast mode")) {
|
|
277
|
+
error.code ??= "LIBFX_UNSUPPORTED_FAST";
|
|
278
|
+
}
|
|
279
|
+
return error;
|
|
280
|
+
}
|
|
250
281
|
async function cancelResponseBody(response) {
|
|
251
282
|
try {
|
|
252
283
|
await response.body?.cancel();
|
|
@@ -1902,7 +1933,7 @@ async function createFxAgent(options = {}) {
|
|
|
1902
1933
|
try {
|
|
1903
1934
|
await runtime.exited;
|
|
1904
1935
|
} catch {}
|
|
1905
|
-
throw error;
|
|
1936
|
+
throw agentBootstrapError(error);
|
|
1906
1937
|
}
|
|
1907
1938
|
const agent = {
|
|
1908
1939
|
prompt(input, promptOptions = {}) {
|
|
@@ -2439,12 +2470,14 @@ async function getBackendInfo(value = {}) {
|
|
|
2439
2470
|
}
|
|
2440
2471
|
}
|
|
2441
2472
|
function createNativeCoreRuntime(addon, options) {
|
|
2442
|
-
const { apiKey, model, gatewayChatUrl } = options;
|
|
2473
|
+
const { apiKey, model, effort, fast, gatewayChatUrl } = options;
|
|
2443
2474
|
const core = addon.createCore({
|
|
2444
2475
|
apiKey,
|
|
2445
2476
|
home: options.home ?? import_node_os.homedir(),
|
|
2446
2477
|
workspaceRoot: options.workspaceRoot ?? process.cwd(),
|
|
2447
2478
|
...model === undefined ? {} : { model },
|
|
2479
|
+
...effort === undefined ? {} : { effort },
|
|
2480
|
+
...fast === undefined ? {} : { fast },
|
|
2448
2481
|
...gatewayChatUrl === undefined ? {} : { gatewayChatUrl }
|
|
2449
2482
|
});
|
|
2450
2483
|
let readyFd;
|
package/node.js
CHANGED
|
@@ -345,12 +345,14 @@ export async function getBackendInfo(value = {}) {
|
|
|
345
345
|
}
|
|
346
346
|
|
|
347
347
|
function createNativeCoreRuntime(addon, options) {
|
|
348
|
-
const { apiKey, model, gatewayChatUrl } = options;
|
|
348
|
+
const { apiKey, model, effort, fast, gatewayChatUrl } = options;
|
|
349
349
|
const core = addon.createCore({
|
|
350
350
|
apiKey,
|
|
351
351
|
home: options.home ?? homedir(),
|
|
352
352
|
workspaceRoot: options.workspaceRoot ?? process.cwd(),
|
|
353
353
|
...(model === undefined ? {} : { model }),
|
|
354
|
+
...(effort === undefined ? {} : { effort }),
|
|
355
|
+
...(fast === undefined ? {} : { fast }),
|
|
354
356
|
...(gatewayChatUrl === undefined ? {} : { gatewayChatUrl }),
|
|
355
357
|
});
|
|
356
358
|
let readyFd;
|