fwdloop 0.11.0 → 0.13.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 +248 -27
- package/package.json +1 -1
- package/src/ask.js +3 -0
- package/src/authoring.js +103 -13
- package/src/books.js +23 -2
- package/src/canrun.js +36 -0
- package/src/config.js +256 -0
- package/src/declaration.js +72 -2
- package/src/drafter.js +53 -11
- package/src/draftspend.js +70 -0
- package/src/flow.js +43 -0
- package/src/keysfile.js +180 -0
- package/src/liveness.js +1 -1
- package/src/model-step.js +43 -8
- package/src/monthly.js +276 -0
- package/src/panel/author.js +482 -0
- package/src/panel/authorcard.js +297 -0
- package/src/panel/authorflows.js +312 -0
- package/src/panel/authorresume.js +149 -0
- package/src/panel/authorstart.js +257 -0
- package/src/panel/authorvalues.js +110 -0
- package/src/panel/data.js +228 -34
- package/src/panel/index.html +2073 -124
- package/src/panel/resume.js +14 -11
- package/src/panel/server.js +150 -117
- package/src/panel/settings.js +270 -0
- package/src/panel/spawn.js +77 -0
- package/src/provider.js +189 -43
- package/src/providershapes.js +19 -0
- package/src/runner.js +639 -85
- package/src/runvalues.js +178 -0
- package/src/send.js +10 -3
- package/src/setup.js +120 -0
- package/types/authoring.d.ts +24 -2
- package/types/books.d.ts +14 -2
- package/types/canrun.d.ts +32 -0
- package/types/config.d.ts +52 -0
- package/types/declaration.d.ts +9 -1
- package/types/drafter.d.ts +18 -2
- package/types/draftspend.d.ts +21 -0
- package/types/flow.d.ts +23 -0
- package/types/keysfile.d.ts +90 -0
- package/types/liveness.d.ts +2 -2
- package/types/model-step.d.ts +6 -2
- package/types/monthly.d.ts +130 -0
- package/types/panel/author.d.ts +335 -0
- package/types/panel/authorcard.d.ts +120 -0
- package/types/panel/authorflows.d.ts +175 -0
- package/types/panel/authorresume.d.ts +32 -0
- package/types/panel/authorstart.d.ts +115 -0
- package/types/panel/authorvalues.d.ts +62 -0
- package/types/panel/data.d.ts +103 -12
- package/types/panel/resume.d.ts +8 -1
- package/types/panel/server.d.ts +19 -33
- package/types/panel/settings.d.ts +23 -0
- package/types/panel/spawn.d.ts +30 -0
- package/types/provider.d.ts +123 -70
- package/types/providershapes.d.ts +11 -0
- package/types/runner.d.ts +120 -5
- package/types/runvalues.d.ts +97 -0
- package/types/send.d.ts +5 -1
- package/types/setup.d.ts +83 -0
package/src/provider.js
CHANGED
|
@@ -21,7 +21,9 @@ import {
|
|
|
21
21
|
} from 'node:fs';
|
|
22
22
|
import { dirname, basename } from 'node:path';
|
|
23
23
|
import { readFileInside } from './flow.js';
|
|
24
|
-
import {
|
|
24
|
+
import { readConfig, configDoorHome } from './config.js';
|
|
25
|
+
import { OpenAI, Anthropic, Gemini } from 'bare-agent/providers';
|
|
26
|
+
import { SHAPES } from './providershapes.js';
|
|
25
27
|
|
|
26
28
|
/**
|
|
27
29
|
* F28 (2026-09-15) / BA-27 (bare-agent >=0.47.0): DeepSeek sometimes emits a
|
|
@@ -57,6 +59,7 @@ export const PROVIDER_SLOTS = Object.freeze({
|
|
|
57
59
|
baseUrl: 'https://api.synthetic.new/openai/v1',
|
|
58
60
|
envVar: 'SYNTHETIC_API_KEY',
|
|
59
61
|
defaultModel: 'hf:Qwen/Qwen3.8-27B',
|
|
62
|
+
shape: 'openai-api',
|
|
60
63
|
legacyMaxTokens: false,
|
|
61
64
|
}),
|
|
62
65
|
deepseek: Object.freeze({
|
|
@@ -65,17 +68,55 @@ export const PROVIDER_SLOTS = Object.freeze({
|
|
|
65
68
|
// F22: 'deepseek-v4-flash' is retired, routed to DeepSeek-V4.1-Flash —
|
|
66
69
|
// request the live name so request === served.
|
|
67
70
|
defaultModel: 'deepseek-flash',
|
|
71
|
+
shape: 'openai-api',
|
|
68
72
|
// F11: DeepSeek ignores `max_completion_tokens`; only the legacy
|
|
69
73
|
// `max_tokens` key bounds output.
|
|
70
74
|
legacyMaxTokens: true,
|
|
71
75
|
}),
|
|
72
76
|
});
|
|
73
77
|
|
|
78
|
+
/**
|
|
79
|
+
* THE one lookup of a slot's model, API shape and address (M4d amendment 1). Every model call (run,
|
|
80
|
+
* resume, model step, drafter), Test, Balance and the spend rows read the slot through this and nothing
|
|
81
|
+
* else: a value saved on the Settings page (`config.providers[slot]`) wins per field, else the code
|
|
82
|
+
* default above. A blank saved Base URL means the default FOR THE EFFECTIVE SHAPE: the slot's own code
|
|
83
|
+
* address while the shape is the slot's code shape, else that shape's vendor address ('' = bare-agent's own).
|
|
84
|
+
* Unknown slot throws. `config` is already-read config (see `readPriceConfig`); no I/O here.
|
|
85
|
+
* @param {string} slotName
|
|
86
|
+
* @param {{ config?: Record<string, any> }} [opts]
|
|
87
|
+
* @returns {{ slot: string, envVar: string, legacyMaxTokens: boolean,
|
|
88
|
+
* model: string, shape: string, baseUrl: string,
|
|
89
|
+
* defaults: { model: string, shape: string, baseUrl: string } }}
|
|
90
|
+
*/
|
|
91
|
+
export function resolveSlot(slotName, { config = {} } = {}) {
|
|
92
|
+
if (!Object.hasOwn(PROVIDER_SLOTS, slotName)) {
|
|
93
|
+
throw new Error(`unknown provider slot "${slotName}" — known slots: ${Object.keys(PROVIDER_SLOTS).join(', ')}`);
|
|
94
|
+
}
|
|
95
|
+
const def = PROVIDER_SLOTS[slotName];
|
|
96
|
+
const saved = (config.providers && Object.hasOwn(config.providers, slotName)) ? config.providers[slotName] : {};
|
|
97
|
+
const shape = saved.shape ?? def.shape;
|
|
98
|
+
const defaultBaseUrl = shape === def.shape ? def.baseUrl : (SHAPES.find((x) => x.id === shape)?.defaultUrl ?? '');
|
|
99
|
+
const savedUrl = typeof saved.baseUrl === 'string' ? saved.baseUrl.replace(/\/+$/, '') : '';
|
|
100
|
+
return {
|
|
101
|
+
slot: slotName,
|
|
102
|
+
envVar: def.envVar,
|
|
103
|
+
legacyMaxTokens: def.legacyMaxTokens === true && shape === 'openai-api',
|
|
104
|
+
model: saved.model ?? def.defaultModel,
|
|
105
|
+
shape,
|
|
106
|
+
baseUrl: savedUrl !== '' ? savedUrl : defaultBaseUrl,
|
|
107
|
+
defaults: { model: def.defaultModel, shape: def.shape, baseUrl: defaultBaseUrl },
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
74
111
|
/**
|
|
75
112
|
* List-rate ceilings (USD/1K tokens), hand-entered — see
|
|
76
|
-
* poc/m0/spend.mjs@76a3607 for sourcing notes per row.
|
|
77
|
-
*
|
|
78
|
-
*
|
|
113
|
+
* poc/m0/spend.mjs@76a3607 for sourcing notes per row. This table is the DEFAULT
|
|
114
|
+
* price: a price set in Settings (`~/.config/fwdloop/config.json` `prices`, per
|
|
115
|
+
* provider slot) wins over a row here, per field, through `resolvePrices` below —
|
|
116
|
+
* the one lookup every model call is booked and cap-checked by (M4d, signed
|
|
117
|
+
* 2026-10-05; that REPLACES the 2026-09-21 "edit a row here, never a runtime
|
|
118
|
+
* flag" ruling). Cached input is priced as input
|
|
119
|
+
* (M4d amendment 2): a row has no cache rate.
|
|
79
120
|
*/
|
|
80
121
|
export const RATES_BY_SUFFIX = {
|
|
81
122
|
'zai-org/GLM-5.2': { in: 0.0006, out: 0.0022, source: 'published' },
|
|
@@ -88,7 +129,10 @@ export const RATES_BY_SUFFIX = {
|
|
|
88
129
|
'syn:large:text': { in: 0.0006, out: 0.0025, source: 'ceiling' },
|
|
89
130
|
'syn:small:text': { in: 0.0006, out: 0.0025, source: 'ceiling' },
|
|
90
131
|
'deepseek-v4-flash': { in: 0.00044, out: 0.00132, source: 'published' }, // F22: retired name, historical rows only
|
|
91
|
-
|
|
132
|
+
// DeepSeek-V4.1-Flash, peak. Source: https://api-docs.deepseek.com/quick_start/pricing/ (fetched
|
|
133
|
+
// 2026-10-05: cache miss $0.30, output $1.20 per 1M). The cache-hit
|
|
134
|
+
// price is deliberately not used: cached input books at `in` (M4d amendment 2, signed 2026-10-06).
|
|
135
|
+
'deepseek-flash': { in: 0.0003, out: 0.0012, source: 'published' },
|
|
92
136
|
'deepseek-v4-pro': { in: 0.00132, out: 0.00396, source: 'published' },
|
|
93
137
|
};
|
|
94
138
|
|
|
@@ -96,6 +140,8 @@ export const RATES_BY_SUFFIX = {
|
|
|
96
140
|
* Strip an `hf:` routing prefix and look up `suffix` with `Object.hasOwn` —
|
|
97
141
|
* never plain truthiness/`in`, which would let a suffix like `"constructor"`
|
|
98
142
|
* resolve to an inherited `Object.prototype` member.
|
|
143
|
+
* @param {string|null|undefined} modelId
|
|
144
|
+
* @param {Record<string, any>} [ratesTable]
|
|
99
145
|
*/
|
|
100
146
|
export function lookupRate(modelId, ratesTable = RATES_BY_SUFFIX) {
|
|
101
147
|
if (!modelId) return null;
|
|
@@ -120,17 +166,84 @@ export function resolveModelRate(modelId, ratesTable = RATES_BY_SUFFIX) {
|
|
|
120
166
|
export const CEILING_INPUT_TOKENS = 32000;
|
|
121
167
|
export const CEILING_OUTPUT_TOKENS = 16000;
|
|
122
168
|
|
|
169
|
+
const perM = (per1K) => Number((per1K * 1000).toPrecision(12));
|
|
170
|
+
|
|
123
171
|
/**
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
* the HIGHEST
|
|
172
|
+
* THE one price lookup (M4d scope item 6): every model call — run, resume, model step, drafter —
|
|
173
|
+
* is booked and cap-checked from this. Per field: a Settings price (`config.prices[slot]`, USD per
|
|
174
|
+
* 1M -> per 1K) wins, else the code table's row, else the table's HIGHEST entry for that field
|
|
175
|
+
* (an unknown model; unknown cost is never 0). M4d amendment 2: cached input is priced AS input —
|
|
176
|
+
* `cacheReadMult` is always 1; a saved `cachedInPerM` and a row's `cacheIn` are never read here.
|
|
177
|
+
*
|
|
178
|
+
* @param {string} modelId
|
|
179
|
+
* @param {{ slot?: string, config?: Record<string, any>, ratesTable?: Record<string, any> }} [opts]
|
|
180
|
+
* @returns {{
|
|
181
|
+
* rates: { in: number, out: number, cacheReadMult?: number },
|
|
182
|
+
* perM: { inPerM: number, cachedInPerM: number, outPerM: number },
|
|
183
|
+
* source: { in: 'settings'|'table'|'ceiling', cachedIn: 'input', out: 'settings'|'table'|'ceiling' },
|
|
184
|
+
* suffix: string|null,
|
|
185
|
+
* }}
|
|
127
186
|
*/
|
|
128
|
-
export function
|
|
187
|
+
export function resolvePrices(modelId, { slot, config = {}, ratesTable = RATES_BY_SUFFIX } = {}) {
|
|
129
188
|
const resolved = lookupRate(modelId, ratesTable);
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
189
|
+
const row = resolved ? resolved.rates : null;
|
|
190
|
+
const set = (slot !== undefined && config.prices && Object.hasOwn(config.prices, slot)) ? config.prices[slot] : {};
|
|
191
|
+
const ceilingOf = (field) => Math.max(...Object.values(ratesTable).map((r) => r[field]));
|
|
192
|
+
const field = (settingsKey, rowField) => {
|
|
193
|
+
if (set[settingsKey] !== undefined) return { v: set[settingsKey] / 1000, src: 'settings' };
|
|
194
|
+
if (row) return { v: row[rowField], src: 'table' };
|
|
195
|
+
return { v: ceilingOf(rowField), src: 'ceiling' };
|
|
196
|
+
};
|
|
197
|
+
const inF = field('inPerM', 'in');
|
|
198
|
+
const outF = field('outPerM', 'out');
|
|
199
|
+
/** @type {{ in: number, out: number, cacheReadMult: number }} */
|
|
200
|
+
const rates = { in: inF.v, out: outF.v, cacheReadMult: 1 };
|
|
201
|
+
return {
|
|
202
|
+
rates,
|
|
203
|
+
perM: { inPerM: perM(inF.v), cachedInPerM: perM(inF.v), outPerM: perM(outF.v) },
|
|
204
|
+
source: { in: /** @type {any} */ (inF.src), cachedIn: 'input', out: /** @type {any} */ (outF.src) },
|
|
205
|
+
suffix: resolved ? resolved.suffix : null,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* The `price` object a spend row records: the per-1M numbers the call was booked at and where each
|
|
211
|
+
* came from. From a `resolvePrices` result; or from INJECTED rates (tests) with source "injected".
|
|
212
|
+
* @param {{ perM: any, source: any }|null|undefined} prices
|
|
213
|
+
* @param {{ in: number, out: number, cacheReadMult?: number }|null|undefined} [injectedRates]
|
|
214
|
+
*/
|
|
215
|
+
export function priceRecord(prices, injectedRates) {
|
|
216
|
+
if (prices) return { ...prices.perM, source: prices.source };
|
|
217
|
+
if (!injectedRates) return null;
|
|
218
|
+
return {
|
|
219
|
+
inPerM: perM(injectedRates.in),
|
|
220
|
+
cachedInPerM: perM(injectedRates.in * (injectedRates.cacheReadMult ?? 0.1)),
|
|
221
|
+
outPerM: perM(injectedRates.out),
|
|
222
|
+
source: 'injected',
|
|
133
223
|
};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* The config a model call is priced against, read at the door: `{}` when no config applies
|
|
228
|
+
* (a test process with no `FWDLOOP_CONFIG_HOME`), else the validated `config.json`. A broken
|
|
229
|
+
* config THROWS (ConfigError) — a run's charge never changes silently.
|
|
230
|
+
* @param {string} [home] explicit config home (a test); default: the door's home
|
|
231
|
+
*/
|
|
232
|
+
export function readPriceConfig(home) {
|
|
233
|
+
if (home !== undefined) return readConfig({ home });
|
|
234
|
+
const door = configDoorHome();
|
|
235
|
+
return door.skip ? {} : readConfig({ home: door.home });
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* The ceiling cost (USD) of one round of `modelId` — never 0, never null.
|
|
240
|
+
* A known model prices at its own rate; an unknown/missing model prices at
|
|
241
|
+
* the HIGHEST in/out rate anywhere in `ratesTable`. `opts.prices` (a
|
|
242
|
+
* `resolvePrices` result, e.g. from `makeProvider`) makes the cap check use the
|
|
243
|
+
* SAME price the round is booked at.
|
|
244
|
+
*/
|
|
245
|
+
export function ceilingCostUsd(modelId, ratesTable = RATES_BY_SUFFIX, opts = {}) {
|
|
246
|
+
const { rates } = opts.prices ?? resolvePrices(modelId, { ratesTable });
|
|
134
247
|
return (CEILING_INPUT_TOKENS / 1000) * rates.in + (CEILING_OUTPUT_TOKENS / 1000) * rates.out;
|
|
135
248
|
}
|
|
136
249
|
|
|
@@ -195,7 +308,9 @@ export function appendSpendRow(path, row) {
|
|
|
195
308
|
+ '— the signed hash records the request, not what ran',
|
|
196
309
|
);
|
|
197
310
|
}
|
|
198
|
-
|
|
311
|
+
// M4d piece 3: the writer stamps `at` (after the spread: a caller can never set it) so month spend can be read
|
|
312
|
+
// off each run's own books. Rows written before M4d carry none.
|
|
313
|
+
appendFileSync(path, `${JSON.stringify({ ...row, at: new Date().toISOString(), modelMatch })}\n`);
|
|
199
314
|
}
|
|
200
315
|
|
|
201
316
|
// F48 round 3: both readers below take a full path (`<runDir>/spend.jsonl`,
|
|
@@ -205,23 +320,38 @@ export function appendSpendRow(path, row) {
|
|
|
205
320
|
// a symlinked `spend.jsonl` (or a symlinked run-dir ancestor) reads as
|
|
206
321
|
// "missing", never as some outside file's content folded into a cap check
|
|
207
322
|
// or shown on the panel.
|
|
323
|
+
// A row with no booked cost is repriced at ITS OWN booked price's ceiling when it recorded one
|
|
324
|
+
// (M4d: forward only — today's Settings price never re-prices an old row), else at the code table's.
|
|
325
|
+
function rowCeilingUsd(row) {
|
|
326
|
+
const p = row.price;
|
|
327
|
+
if (p && typeof p === 'object' && Number.isFinite(p.inPerM) && p.inPerM > 0 && Number.isFinite(p.outPerM) && p.outPerM > 0) {
|
|
328
|
+
return (CEILING_INPUT_TOKENS / 1e6) * p.inPerM + (CEILING_OUTPUT_TOKENS / 1e6) * p.outPerM;
|
|
329
|
+
}
|
|
330
|
+
return ceilingCostUsd(row.model);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* The one rule for what a spend row costs: `usd` and whether it is `complete`. An incomplete row (a call
|
|
335
|
+
* died unmetered, or a round was left unpriced) counts its priced floor PLUS one ceiling per unmetered call
|
|
336
|
+
* (unknown cost is never 0). Same shape as poc/m6a/batch.mjs rowCostUsd.
|
|
337
|
+
* @param {any} row
|
|
338
|
+
* @returns {{usd: number, complete: boolean}}
|
|
339
|
+
*/
|
|
340
|
+
export function spendRowCost(row) {
|
|
341
|
+
if (row.spendComplete === false) {
|
|
342
|
+
const unmetered = Number.isInteger(row.calls) && Number.isInteger(row.rounds) ? Math.max(1, row.calls - row.rounds) : 1;
|
|
343
|
+
return { usd: (row.costUsd ?? 0) + unmetered * rowCeilingUsd(row), complete: false };
|
|
344
|
+
}
|
|
345
|
+
if (row.costUsd === null || row.costUsd === undefined) return { usd: rowCeilingUsd(row), complete: false };
|
|
346
|
+
return { usd: row.costUsd, complete: true };
|
|
347
|
+
}
|
|
348
|
+
|
|
208
349
|
function readSpendTotal(path) {
|
|
209
350
|
const result = readFileInside(dirname(path), basename(path));
|
|
210
351
|
if (!result.ok) return 0;
|
|
211
352
|
const lines = result.text.split('\n').filter((l) => l.trim());
|
|
212
353
|
let total = 0;
|
|
213
|
-
for (const line of lines)
|
|
214
|
-
const row = JSON.parse(line);
|
|
215
|
-
// An incomplete row (a call died unmetered) counts its priced floor PLUS one
|
|
216
|
-
// ceiling per unmetered call — never only the floor (unknown cost is never
|
|
217
|
-
// 0). Same shape as poc/m6a/batch.mjs rowCostUsd.
|
|
218
|
-
if (row.spendComplete === false) {
|
|
219
|
-
const unmetered = Number.isInteger(row.calls) && Number.isInteger(row.rounds) ? Math.max(1, row.calls - row.rounds) : 1;
|
|
220
|
-
total += (row.costUsd ?? 0) + unmetered * ceilingCostUsd(row.model);
|
|
221
|
-
} else {
|
|
222
|
-
total += row.costUsd === null || row.costUsd === undefined ? ceilingCostUsd(row.model) : row.costUsd;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
354
|
+
for (const line of lines) total += spendRowCost(JSON.parse(line)).usd;
|
|
225
355
|
return total;
|
|
226
356
|
}
|
|
227
357
|
|
|
@@ -267,7 +397,7 @@ export function assertUnderGlobalCap(path, capUsd) {
|
|
|
267
397
|
* @param {Record<string,string|undefined>} [env]
|
|
268
398
|
*/
|
|
269
399
|
export function checkKeyPreflight(slotName, env = process.env) {
|
|
270
|
-
const slotDef = PROVIDER_SLOTS[slotName];
|
|
400
|
+
const slotDef = Object.hasOwn(PROVIDER_SLOTS, slotName) ? PROVIDER_SLOTS[slotName] : null;
|
|
271
401
|
if (!slotDef) return { ok: false, message: `key: unknown provider slot "${slotName}"` };
|
|
272
402
|
const varName = slotDef.envVar;
|
|
273
403
|
const value = env[varName];
|
|
@@ -295,38 +425,54 @@ export function checkKeyPreflight(slotName, env = process.env) {
|
|
|
295
425
|
* values this project uses.
|
|
296
426
|
*
|
|
297
427
|
* @param {string} slotName
|
|
298
|
-
* @param {{ model?: string, timeoutMs?: number, deadlineMs?: number, thinking?: object|null }} [options]
|
|
428
|
+
* @param {{ model?: string, timeoutMs?: number, deadlineMs?: number, thinking?: object|null, env?: Record<string,string|undefined>, configHome?: string }} [options]
|
|
429
|
+
* `configHome` (a test) is where `config.json` prices are read; default: the door's home (`readPriceConfig`).
|
|
430
|
+
* `env` (M4d: the merged shell+keys-file env; default process.env) is where the key is read.
|
|
299
431
|
* `thinking` (bare-agent >=0.49) is sent verbatim as body.thinking; unset/null leaves the body unchanged.
|
|
300
|
-
* @returns {{ provider: any, rates: {in:number, out:number}, modelId: string, suffix: string, slot: string }}
|
|
432
|
+
* @returns {{ provider: any, rates: {in:number, out:number, cacheReadMult?:number}, modelId: string, suffix: string|null, slot: string, prices: ReturnType<typeof resolvePrices> }}
|
|
301
433
|
*/
|
|
302
434
|
export function makeProvider(slotName, options = {}) {
|
|
303
|
-
const {
|
|
304
|
-
|
|
305
|
-
|
|
435
|
+
const {
|
|
436
|
+
model, timeoutMs, deadlineMs, thinking, env = process.env, configHome,
|
|
437
|
+
} = options;
|
|
438
|
+
if (!Object.hasOwn(PROVIDER_SLOTS, slotName)) {
|
|
306
439
|
throw new Error(`unknown provider slot "${slotName}" — known slots: ${Object.keys(PROVIDER_SLOTS).join(', ')}`);
|
|
307
440
|
}
|
|
308
441
|
|
|
309
|
-
const keyCheck = checkKeyPreflight(slotName);
|
|
442
|
+
const keyCheck = checkKeyPreflight(slotName, env);
|
|
310
443
|
if (!keyCheck.ok) throw new Error(keyCheck.message);
|
|
311
444
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
const
|
|
445
|
+
// A broken config throws by name here; it never falls back to the code defaults or the table, so a
|
|
446
|
+
// run's model, address or charge cannot change silently.
|
|
447
|
+
const config = readPriceConfig(configHome);
|
|
448
|
+
const slot = resolveSlot(slotName, { config });
|
|
449
|
+
const apiKey = env[slot.envVar];
|
|
450
|
+
const modelId = model ?? slot.model;
|
|
451
|
+
// The ONE price lookup (a Settings price wins over the table; a model the table doesn't know prices
|
|
452
|
+
// at the table's highest rate, suffix null — unknown cost is never 0).
|
|
453
|
+
const prices = resolvePrices(modelId, { slot: slotName, config });
|
|
454
|
+
const { rates } = prices;
|
|
455
|
+
const suffix = prices.suffix;
|
|
315
456
|
|
|
316
|
-
const
|
|
457
|
+
const common = {
|
|
317
458
|
apiKey,
|
|
318
459
|
model: modelId,
|
|
319
|
-
baseUrl: slot.baseUrl,
|
|
320
|
-
legacyMaxTokens: slot.legacyMaxTokens === true,
|
|
321
|
-
// bare-agent >=0.48: opt in to the raw broken tool-call arguments on
|
|
322
|
-
// `malformedToolCall` (capped upstream at 500 chars). Not exposeErrorBody.
|
|
323
|
-
exposeMalformedArgs: true,
|
|
460
|
+
...(slot.baseUrl !== '' ? { baseUrl: slot.baseUrl } : {}),
|
|
324
461
|
...(timeoutMs !== undefined ? { timeoutMs } : {}),
|
|
325
462
|
...(deadlineMs !== undefined ? { deadlineMs } : {}),
|
|
326
463
|
...(thinking != null ? { thinking } : {}),
|
|
327
|
-
}
|
|
464
|
+
};
|
|
465
|
+
const provider = slot.shape === 'anthropic-api' ? new Anthropic(common)
|
|
466
|
+
: slot.shape === 'gemini-api' ? new Gemini(common)
|
|
467
|
+
: new MalformedToolCallTolerantOpenAI({
|
|
468
|
+
...common,
|
|
469
|
+
legacyMaxTokens: slot.legacyMaxTokens,
|
|
470
|
+
// bare-agent >=0.48: opt in to the raw broken tool-call arguments on
|
|
471
|
+
// `malformedToolCall` (capped upstream at 500 chars). Not exposeErrorBody.
|
|
472
|
+
exposeMalformedArgs: true,
|
|
473
|
+
});
|
|
328
474
|
|
|
329
475
|
return {
|
|
330
|
-
provider, rates, modelId, suffix, slot: slotName,
|
|
476
|
+
provider, rates, modelId, suffix, slot: slotName, prices,
|
|
331
477
|
};
|
|
332
478
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// borrowed-from: bareloop src/providerrows.js@5a5a811 (`SHAPES` only)
|
|
2
|
+
// M4d amendment 1 (docs/wiki/the-module-ladder.md, "M4d" Amendment 1): the API shapes the Settings
|
|
3
|
+
// Providers dropdown offers. Only a shape `makeProvider` (src/provider.js) can really build is listed:
|
|
4
|
+
// bare-agent/providers exports OpenAI, Anthropic and Gemini with the same constructor options we pass
|
|
5
|
+
// (`apiKey`, `model`, `baseUrl`, `timeoutMs`, `deadlineMs`). Kept in its own file so config.js can
|
|
6
|
+
// validate a shape without importing provider.js (which imports config.js).
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* `id` is the value saved in config.json; `defaultUrl` is the host a blank Base URL means for a slot
|
|
10
|
+
* that has no code default of its own on this shape ('' = bare-agent's own default for that vendor).
|
|
11
|
+
* @type {readonly {id: string, label: string, defaultUrl: string}[]}
|
|
12
|
+
*/
|
|
13
|
+
export const SHAPES = Object.freeze([
|
|
14
|
+
Object.freeze({ id: 'anthropic-api', label: 'Anthropic', defaultUrl: 'https://api.anthropic.com/v1' }),
|
|
15
|
+
Object.freeze({ id: 'openai-api', label: 'OpenAI-compatible', defaultUrl: 'https://api.openai.com/v1' }),
|
|
16
|
+
Object.freeze({ id: 'gemini-api', label: 'Gemini', defaultUrl: '' }),
|
|
17
|
+
]);
|
|
18
|
+
|
|
19
|
+
export const SHAPE_IDS = Object.freeze(SHAPES.map((s) => s.id));
|