fwdloop 0.5.0 → 0.7.0
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/bin/fwdloop +559 -0
- package/package.json +7 -3
- package/src/ask.js +360 -7
- package/src/books.js +209 -2
- package/src/declaration.js +12 -1
- package/src/flow.js +247 -2
- package/src/index.js +9 -2
- package/src/model-step.js +153 -14
- package/src/panel/data.js +1589 -0
- package/src/panel/index.html +2377 -0
- package/src/panel/server.js +268 -0
- package/src/primitives.js +136 -41
- package/src/provider.js +57 -41
- package/src/runner.js +1231 -137
- package/src/send.js +20 -1
- package/src/types.js +18 -0
- package/types/ask.d.ts +95 -1
- package/types/books.d.ts +70 -2
- package/types/flow.d.ts +135 -0
- package/types/index.d.ts +5 -2
- package/types/panel/data.d.ts +433 -0
- package/types/panel/server.d.ts +45 -0
- package/types/primitives.d.ts +29 -0
- package/types/provider.d.ts +11 -0
- package/types/runner.d.ts +135 -26
- package/types/types.d.ts +41 -0
package/src/provider.js
CHANGED
|
@@ -17,53 +17,36 @@
|
|
|
17
17
|
// against src/'s ESM style; src never imports from poc/.
|
|
18
18
|
|
|
19
19
|
import {
|
|
20
|
-
appendFileSync,
|
|
20
|
+
appendFileSync, mkdirSync,
|
|
21
21
|
} from 'node:fs';
|
|
22
|
-
import { dirname } from 'node:path';
|
|
22
|
+
import { dirname, basename } from 'node:path';
|
|
23
|
+
import { readFileInside } from './flow.js';
|
|
23
24
|
import { OpenAI } from 'bare-agent/providers';
|
|
24
25
|
|
|
25
26
|
/**
|
|
26
|
-
* F28 (2026-09-15): DeepSeek sometimes emits a
|
|
27
|
-
* `function.arguments` is not valid JSON.
|
|
28
|
-
*
|
|
29
|
-
* round already succeeded
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
27
|
+
* F28 (2026-09-15) / BA-27 (bare-agent >=0.47.0): DeepSeek sometimes emits a
|
|
28
|
+
* tool-call whose `function.arguments` is not valid JSON. Before 0.47,
|
|
29
|
+
* bare-agent's own `generate()` threw a bare `SyntaxError` AFTER the HTTP
|
|
30
|
+
* round already succeeded — losing the billed round and hanging metering.
|
|
31
|
+
* As of 0.47, `OpenAI.generate()` (bare-agent/src/provider-openai.js, via
|
|
32
|
+
* `provider-toolcalls.js`'s `parseToolCalls`) no longer throws: it resolves
|
|
33
|
+
* normally with `toolCalls: []` and a `malformedToolCall: { name, error }`
|
|
34
|
+
* field already on the result. As of 0.48 the constructor option
|
|
35
|
+
* `exposeMalformedArgs: true` (set in `makeProvider`) adds `rawArguments`
|
|
36
|
+
* (capped upstream at 500 chars, `rawTruncated: true` when clipped). `Loop.run()` does not forward unknown
|
|
37
|
+
* `generate()` fields into its own return, so this wrapper ALSO stashes the
|
|
38
|
+
* marker on the instance (`this.lastMalformedToolCall`, reset at the top of
|
|
39
|
+
* every `generate()` call) — the one channel `runModelStepOnPrimitives`
|
|
40
|
+
* (same provider reference) can read after `loop.run()` returns. We require
|
|
41
|
+
* bare-agent >=0.47 (package.json `^0.47.0`) and never patch around its
|
|
42
|
+
* private response internals.
|
|
35
43
|
*/
|
|
36
44
|
class MalformedToolCallTolerantOpenAI extends OpenAI {
|
|
37
|
-
async _request(path, body, timeoutMs, deadlineMs) {
|
|
38
|
-
const data = await super._request(path, body, timeoutMs, deadlineMs);
|
|
39
|
-
this._lastData = data;
|
|
40
|
-
return data;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
45
|
async generate(messages, tools = [], options = {}) {
|
|
44
46
|
this.lastMalformedToolCall = null;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (!(err instanceof SyntaxError)) throw err;
|
|
49
|
-
const msg = this._lastData?.choices?.[0]?.message;
|
|
50
|
-
const toolCalls = msg?.tool_calls;
|
|
51
|
-
if (!Array.isArray(toolCalls) || toolCalls.length === 0) throw err;
|
|
52
|
-
const tc = toolCalls[0];
|
|
53
|
-
const rawArguments = typeof tc?.function?.arguments === 'string'
|
|
54
|
-
? tc.function.arguments.slice(0, 500)
|
|
55
|
-
: '';
|
|
56
|
-
const malformedToolCall = { name: tc?.function?.name ?? null, rawArguments, error: err.message };
|
|
57
|
-
this.lastMalformedToolCall = malformedToolCall;
|
|
58
|
-
return {
|
|
59
|
-
text: msg.content || '',
|
|
60
|
-
toolCalls: [],
|
|
61
|
-
model: this._lastData.model || this.model,
|
|
62
|
-
stopReason: 'tool_use',
|
|
63
|
-
usage: this._normalizeUsage(this._lastData.usage),
|
|
64
|
-
malformedToolCall,
|
|
65
|
-
};
|
|
66
|
-
}
|
|
47
|
+
const result = await super.generate(messages, tools, options);
|
|
48
|
+
if (result.malformedToolCall) this.lastMalformedToolCall = result.malformedToolCall;
|
|
49
|
+
return result;
|
|
67
50
|
}
|
|
68
51
|
}
|
|
69
52
|
|
|
@@ -215,9 +198,17 @@ export function appendSpendRow(path, row) {
|
|
|
215
198
|
appendFileSync(path, `${JSON.stringify({ ...row, modelMatch })}\n`);
|
|
216
199
|
}
|
|
217
200
|
|
|
201
|
+
// F48 round 3: both readers below take a full path (`<runDir>/spend.jsonl`,
|
|
202
|
+
// as every call site already builds it) but go through `readFileInside`
|
|
203
|
+
// (`src/flow.js`) using `dirname(path)` as the containment boundary and
|
|
204
|
+
// `basename(path)` as the checked relative name — no call site changes, and
|
|
205
|
+
// a symlinked `spend.jsonl` (or a symlinked run-dir ancestor) reads as
|
|
206
|
+
// "missing", never as some outside file's content folded into a cap check
|
|
207
|
+
// or shown on the panel.
|
|
218
208
|
function readSpendTotal(path) {
|
|
219
|
-
|
|
220
|
-
|
|
209
|
+
const result = readFileInside(dirname(path), basename(path));
|
|
210
|
+
if (!result.ok) return 0;
|
|
211
|
+
const lines = result.text.split('\n').filter((l) => l.trim());
|
|
221
212
|
let total = 0;
|
|
222
213
|
for (const line of lines) {
|
|
223
214
|
const row = JSON.parse(line);
|
|
@@ -226,6 +217,28 @@ function readSpendTotal(path) {
|
|
|
226
217
|
return total;
|
|
227
218
|
}
|
|
228
219
|
|
|
220
|
+
/**
|
|
221
|
+
* `appendSpendRow`'s own sibling reader (M4a piece 2, docs/wiki/the-module-
|
|
222
|
+
* ladder.md M4a scope item 2: "one reader per book") — every row as written,
|
|
223
|
+
* raw, in file order. `[]` when the file doesn't exist yet, and a malformed
|
|
224
|
+
* line is skipped rather than thrown on (an honest best-effort read, same
|
|
225
|
+
* posture as `src/books.js`'s readers — a caller that needs to know the row
|
|
226
|
+
* count decides how to treat a gap, this function never crashes over it).
|
|
227
|
+
* @param {string} path
|
|
228
|
+
* @returns {any[]}
|
|
229
|
+
*/
|
|
230
|
+
export function readSpendRows(path) {
|
|
231
|
+
const result = readFileInside(dirname(path), basename(path));
|
|
232
|
+
if (!result.ok) return [];
|
|
233
|
+
const rows = [];
|
|
234
|
+
for (const line of result.text.split('\n')) {
|
|
235
|
+
const trimmed = line.trim();
|
|
236
|
+
if (trimmed.length === 0) continue;
|
|
237
|
+
try { rows.push(JSON.parse(trimmed)); } catch { /* malformed line: skip, never crash the read */ }
|
|
238
|
+
}
|
|
239
|
+
return rows;
|
|
240
|
+
}
|
|
241
|
+
|
|
229
242
|
/** Throws once total spend (every null row repriced at its ceiling) is at
|
|
230
243
|
* or over `capUsd`. */
|
|
231
244
|
export function assertUnderGlobalCap(path, capUsd) {
|
|
@@ -296,6 +309,9 @@ export function makeProvider(slotName, options = {}) {
|
|
|
296
309
|
model: modelId,
|
|
297
310
|
baseUrl: slot.baseUrl,
|
|
298
311
|
legacyMaxTokens: slot.legacyMaxTokens === true,
|
|
312
|
+
// bare-agent >=0.48: opt in to the raw broken tool-call arguments on
|
|
313
|
+
// `malformedToolCall` (capped upstream at 500 chars). Not exposeErrorBody.
|
|
314
|
+
exposeMalformedArgs: true,
|
|
299
315
|
...(timeoutMs !== undefined ? { timeoutMs } : {}),
|
|
300
316
|
...(deadlineMs !== undefined ? { deadlineMs } : {}),
|
|
301
317
|
});
|