fwdloop 0.15.0 → 0.16.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 +106 -31
- package/package.json +2 -2
- package/src/authoring.js +23 -11
- package/src/closers.js +5 -0
- package/src/config.js +66 -4
- package/src/declaration.js +25 -1
- package/src/draft-steps.js +79 -0
- package/src/drafter.js +54 -15
- package/src/flowmodel.js +30 -0
- package/src/input-facts.js +12 -3
- package/src/keysfile.js +51 -16
- package/src/model-step.js +13 -11
- package/src/monthly.js +9 -1
- package/src/panel/author.js +81 -22
- package/src/panel/authorcard.js +25 -17
- package/src/panel/authorflows.js +33 -18
- package/src/panel/authorresume.js +9 -8
- package/src/panel/authorstart.js +11 -9
- package/src/panel/data.js +3 -3
- package/src/panel/index.html +516 -146
- package/src/panel/resume.js +3 -3
- package/src/panel/server.js +4 -3
- package/src/panel/settings.js +138 -80
- package/src/panel/spawn.js +15 -9
- package/src/provider.js +136 -178
- package/src/providershapes.js +7 -7
- package/src/runner.js +38 -22
- package/src/thinking.js +55 -0
- package/types/authoring.d.ts +11 -4
- package/types/closers.d.ts +2 -0
- package/types/config.d.ts +9 -1
- package/types/draft-steps.d.ts +14 -0
- package/types/drafter.d.ts +13 -10
- package/types/flowmodel.d.ts +16 -0
- package/types/input-facts.d.ts +6 -1
- package/types/keysfile.d.ts +23 -6
- package/types/model-step.d.ts +1 -1
- package/types/monthly.d.ts +1 -0
- package/types/panel/author.d.ts +44 -6
- package/types/panel/authorcard.d.ts +21 -8
- package/types/panel/authorflows.d.ts +29 -6
- package/types/panel/authorresume.d.ts +2 -1
- package/types/panel/authorstart.d.ts +16 -6
- package/types/panel/data.d.ts +2 -2
- package/types/panel/resume.d.ts +2 -1
- package/types/panel/server.d.ts +3 -1
- package/types/panel/settings.d.ts +3 -1
- package/types/panel/spawn.d.ts +13 -4
- package/types/provider.d.ts +94 -284
- package/types/providershapes.d.ts +3 -4
- package/types/runner.d.ts +2 -4
- package/types/thinking.d.ts +25 -0
package/src/thinking.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// M4d amendment 7: bareagent decides whether a model's thinking can be changed - not our code, not a table of ours.
|
|
2
|
+
// ONE function wraps bareagent's `thinkingSupport(provider, model, { baseUrl })` (bare-agent >= 0.52, 'bare-agent/providers'): a pure lookup that returns
|
|
3
|
+
// `{ switchable: true | false | 'unverified', off, on, note }`. We return just `switchable`. Its first argument is bareagent's own provider KIND,
|
|
4
|
+
// not our row's API shape id, so a shape id is mapped to its kind here. A shape with no kind, or an answer that is not that object, is 'unverified'
|
|
5
|
+
// (the Chat "Thinking on" box then works and bareagent errors loudly at the call).
|
|
6
|
+
// The row's Base URL is the 3rd argument: bareagent picks the specific kind from the model id / Base URL host exactly as its request path does (0.52).
|
|
7
|
+
// A call whose model can't switch no longer throws: bareagent runs it and reports `thinkingStatus`; the sentences for that are `thinkingSay` below.
|
|
8
|
+
import * as providers from 'bare-agent/providers';
|
|
9
|
+
|
|
10
|
+
/** The sentence under a greyed "Thinking on" box (amendment 7 item 2). */
|
|
11
|
+
export const THINKING_FIXED_SAY = "can't change this for this model";
|
|
12
|
+
|
|
13
|
+
/** Our API shape id -> bareagent's provider kind. */
|
|
14
|
+
const KIND_OF_SHAPE = Object.freeze({ 'anthropic-api': 'anthropic', 'openai-api': 'openai', 'gemini-api': 'gemini' });
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @param {string} shape the row's API shape @param {string} model
|
|
18
|
+
* @param {{ impl?: unknown, baseUrl?: string }} [opts] `impl` is a test seam: the function standing in for bareagent's export (default: the installed export); `baseUrl` is the row's Base URL
|
|
19
|
+
* @returns {true|false|'unverified'}
|
|
20
|
+
*/
|
|
21
|
+
export function thinkingSupport(shape, model, { impl = /** @type {any} */ (providers).thinkingSupport, baseUrl } = {}) {
|
|
22
|
+
const kind = /** @type {Record<string, string>} */ (KIND_OF_SHAPE)[shape];
|
|
23
|
+
if (typeof impl !== 'function' || kind === undefined) return 'unverified';
|
|
24
|
+
let answer;
|
|
25
|
+
try { answer = impl(kind, model, baseUrl === undefined || baseUrl === '' ? undefined : { baseUrl }); } catch { return 'unverified'; }
|
|
26
|
+
const s = answer !== null && typeof answer === 'object' ? answer.switchable : undefined;
|
|
27
|
+
return s === true || s === false ? s : 'unverified';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** bareagent's `thinkingStatus` values, worst first (its own order: ignored > unsupported > unknown > applied). */
|
|
31
|
+
const WORST_FIRST = Object.freeze(['ignored', 'unsupported', 'unknown', 'applied']);
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The worst of a draft's per-round statuses; `null` when no round carried one.
|
|
35
|
+
* @param {Array<string|null|undefined>} statuses @returns {string|null}
|
|
36
|
+
*/
|
|
37
|
+
export function worstThinkingStatus(statuses) {
|
|
38
|
+
return WORST_FIRST.find((s) => statuses.includes(s)) ?? null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** The note beside the Chat "Thinking on" box, before any draft, for a model bareagent has not checked (M4d am11 item 2). */
|
|
42
|
+
export const THINKING_UNVERIFIED_SAY = 'thinking off (not verified for this model)';
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The ONE place the thinking words live (M4d am11: bareloop's words). The ✗ line shown in the Chat list when thinking did not go as asked.
|
|
46
|
+
* The words are fixed strings, never built from what was asked: they say what the model did (bareloop's code-owned words).
|
|
47
|
+
* 'applied' (and no status) says nothing here (the list's own "thinking on ✓" / "thinking off ✓" covers it).
|
|
48
|
+
* @param {string|null} status @returns {string|null}
|
|
49
|
+
*/
|
|
50
|
+
export function thinkingSay(status) {
|
|
51
|
+
if (status === 'ignored') return 'thinking on (the model thought anyway)';
|
|
52
|
+
if (status === 'unsupported') return "thinking on (this model can't change it)";
|
|
53
|
+
if (status === 'unknown') return 'thinking off (not confirmed)';
|
|
54
|
+
return null;
|
|
55
|
+
}
|
package/types/authoring.d.ts
CHANGED
|
@@ -86,13 +86,15 @@ export function draftKeyRefusal(slot: string, env: Record<string, string | undef
|
|
|
86
86
|
*
|
|
87
87
|
* Test seam: `provider`/`rates`/`modelId` are injected; without them a live provider is built.
|
|
88
88
|
*/
|
|
89
|
-
export function draftToDir({ proseFile, dir, root, name, slot, model, budgetUsd, env, provider, rates, modelId, noQuestions, }: {
|
|
89
|
+
export function draftToDir({ proseFile, dir, root, name, slot, model, draftThinking, keyNames, budgetUsd, env, provider, rates, modelId, noQuestions, }: {
|
|
90
90
|
proseFile: any;
|
|
91
91
|
dir: any;
|
|
92
92
|
root: any;
|
|
93
93
|
name: any;
|
|
94
|
-
slot
|
|
94
|
+
slot: any;
|
|
95
95
|
model: any;
|
|
96
|
+
draftThinking?: "on" | "off" | undefined;
|
|
97
|
+
keyNames: any;
|
|
96
98
|
budgetUsd?: number | undefined;
|
|
97
99
|
env?: NodeJS.ProcessEnv | undefined;
|
|
98
100
|
provider: any;
|
|
@@ -148,14 +150,15 @@ export function draftToDir({ proseFile, dir, root, name, slot, model, budgetUsd,
|
|
|
148
150
|
* `sessionDir` (the panel's draft folder: card, notes, every change) widens the setup record; the CLI has none, so its record is the one plan folder.
|
|
149
151
|
* M6: `replaces: {flowHash}` (a draft opened from an existing signed job, carrying that job's signature hash) makes this sign REPLACE that job
|
|
150
152
|
* (`writeFlow` checks the hash is still the job's); without it a taken name is refused as ever.
|
|
151
|
-
* @param {{dir: any, approve?: any, signedBy: any, signedAt?: string, env?: Record<string, string|undefined>, sessionDir?: string, replaces?: {flowHash: string}}} a
|
|
153
|
+
* @param {{dir: any, approve?: any, signedBy: any, signedAt?: string, env?: Record<string, string|undefined>, keyNames?: string[], sessionDir?: string, replaces?: {flowHash: string}}} a
|
|
152
154
|
*/
|
|
153
|
-
export function signDraft({ dir, approve, signedBy, signedAt, env, sessionDir, replaces, }: {
|
|
155
|
+
export function signDraft({ dir, approve, signedBy, signedAt, env, keyNames, sessionDir, replaces, }: {
|
|
154
156
|
dir: any;
|
|
155
157
|
approve?: any;
|
|
156
158
|
signedBy: any;
|
|
157
159
|
signedAt?: string;
|
|
158
160
|
env?: Record<string, string | undefined>;
|
|
161
|
+
keyNames?: string[];
|
|
159
162
|
sessionDir?: string;
|
|
160
163
|
replaces?: {
|
|
161
164
|
flowHash: string;
|
|
@@ -175,6 +178,10 @@ export function signDraft({ dir, approve, signedBy, signedAt, env, sessionDir, r
|
|
|
175
178
|
ok: false;
|
|
176
179
|
red: string;
|
|
177
180
|
};
|
|
181
|
+
modelRecord: {
|
|
182
|
+
ok: boolean;
|
|
183
|
+
recorded: boolean;
|
|
184
|
+
};
|
|
178
185
|
};
|
|
179
186
|
export const DRAFT_BUDGET_USD: 0.1;
|
|
180
187
|
export const SPEC_HASH_FILE: "spec.hash";
|
package/types/closers.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/** An input with cells (M4d amendment 8): a file whose name ends `.csv`. The one decider for "this input can be cited". */
|
|
2
|
+
export function isCellsPath(p: any): boolean;
|
|
1
3
|
/**
|
|
2
4
|
* `green` close: every field in `artifact.fields`, in declared order,
|
|
3
5
|
* resolves and matches its cite. First red wins.
|
package/types/config.d.ts
CHANGED
|
@@ -22,6 +22,14 @@ export function configDoorHome(): {
|
|
|
22
22
|
};
|
|
23
23
|
/** One provider field's value problem in plain words, or null when fine. Shared by validateDoc and the route. */
|
|
24
24
|
export function providerFieldProblem(field: any, v: any): string | null;
|
|
25
|
+
/**
|
|
26
|
+
* THE one rule for a slot's model lines (M4d amendment 3 items 7-8), used by config validation and the Settings
|
|
27
|
+
* route. A price is a PAIR (`inPerM` and `outPerM`, each a finite number >= 0 — 0 / 0 typed is a chosen price,
|
|
28
|
+
* recorded so it is never unknown) or neither (null / absent). A ticked line (`use`) needs both. Plain words, or null.
|
|
29
|
+
* @param {any} list
|
|
30
|
+
* @returns {string|null}
|
|
31
|
+
*/
|
|
32
|
+
export function modelsProblem(list: any): string | null;
|
|
25
33
|
/**
|
|
26
34
|
* The parsed, validated document. `{}` when the file is missing. THROWS ConfigError when the file is
|
|
27
35
|
* there but unreadable, not a JSON object, or holds an invalid known field — never `{}` for those.
|
|
@@ -33,7 +41,7 @@ export function readConfig(opts?: {
|
|
|
33
41
|
}): Record<string, any>;
|
|
34
42
|
/**
|
|
35
43
|
* Apply a patch and write. `null` deletes a field. Top-level fields shallow-merge; `prices` merges
|
|
36
|
-
* per slot, then per field (`prices.<slot> = null` clears the slot, `prices.<slot>.<field> = null`
|
|
44
|
+
* per slot, then per field; `models.<slot>` is replaced whole (`prices.<slot> = null` clears the slot, `prices.<slot>.<field> = null`
|
|
37
45
|
* clears the field). Everything is validated before anything is written; a refusal leaves the file
|
|
38
46
|
* untouched.
|
|
39
47
|
* @param {Record<string, any>} patch
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {{ log: any, declaration: any }} p `log` = the draft's log.json (parsed), `declaration` = declaration.json or declaration.rejected.json (parsed)
|
|
3
|
+
* @returns {Array<{ id: string, label: string, status: 'done'|'failed', details: string[], reds?: string[] }> | null}
|
|
4
|
+
*/
|
|
5
|
+
export function draftStepList({ log, declaration }: {
|
|
6
|
+
log: any;
|
|
7
|
+
declaration: any;
|
|
8
|
+
}): Array<{
|
|
9
|
+
id: string;
|
|
10
|
+
label: string;
|
|
11
|
+
status: "done" | "failed";
|
|
12
|
+
details: string[];
|
|
13
|
+
reds?: string[];
|
|
14
|
+
}> | null;
|
package/types/drafter.d.ts
CHANGED
|
@@ -253,11 +253,11 @@ export function goalForLine(fromLine: any, lines: any): any;
|
|
|
253
253
|
*
|
|
254
254
|
* @returns {Promise<{ok:boolean, declaration:object|null, reds:string[], rounds:number, calls:number, spendComplete:boolean,
|
|
255
255
|
* costUsd:number|null, modelReturned:string|null, modelId?:string, price?:object|null, tokens?:object|null, structureRetries:number, revisions:number, stop:string|null, log:object[],
|
|
256
|
-
* questions?:{line:number, question:string}[], droppedQuestions?:object[], notChecked?:string[]}>}
|
|
256
|
+
* questions?:{line:number, question:string}[], droppedQuestions?:object[], notChecked?:string[], thinking?:{asked:string, status:string|null, say:string|null}, inputs?:{role:string, detail:string}[]}>}
|
|
257
257
|
*/
|
|
258
|
-
export function draft({ proseText, slot, model, provider: injected, rates: injectedRates, modelId: injectedModelId, env, budgetUsd, skills, makeProviderFn, onBook, offerQuestions, }: {
|
|
258
|
+
export function draft({ proseText, slot, model, provider: injected, rates: injectedRates, modelId: injectedModelId, env, budgetUsd, skills, makeProviderFn, onBook, offerQuestions, draftThinking, }: {
|
|
259
259
|
proseText: any;
|
|
260
|
-
slot
|
|
260
|
+
slot: any;
|
|
261
261
|
model: any;
|
|
262
262
|
provider: any;
|
|
263
263
|
rates: any;
|
|
@@ -268,6 +268,7 @@ export function draft({ proseText, slot, model, provider: injected, rates: injec
|
|
|
268
268
|
makeProviderFn?: typeof makeProvider | undefined;
|
|
269
269
|
onBook: any;
|
|
270
270
|
offerQuestions?: boolean | undefined;
|
|
271
|
+
draftThinking?: "on" | "off" | undefined;
|
|
271
272
|
}): Promise<{
|
|
272
273
|
ok: boolean;
|
|
273
274
|
declaration: object | null;
|
|
@@ -290,6 +291,15 @@ export function draft({ proseText, slot, model, provider: injected, rates: injec
|
|
|
290
291
|
}[];
|
|
291
292
|
droppedQuestions?: object[];
|
|
292
293
|
notChecked?: string[];
|
|
294
|
+
thinking?: {
|
|
295
|
+
asked: string;
|
|
296
|
+
status: string | null;
|
|
297
|
+
say: string | null;
|
|
298
|
+
};
|
|
299
|
+
inputs?: {
|
|
300
|
+
role: string;
|
|
301
|
+
detail: string;
|
|
302
|
+
}[];
|
|
293
303
|
}>;
|
|
294
304
|
export const MAX_STRUCTURE_RETRIES: 2;
|
|
295
305
|
export const MAX_REVISIONS: 2;
|
|
@@ -305,11 +315,4 @@ export const CHECKABLE: readonly string[];
|
|
|
305
315
|
export const NOTCHECKED_PROMPT: string;
|
|
306
316
|
/** Try 3 only, and only after tries 1 and 2 both failed validation. No digit and no number word anywhere (a test greps this): the machine, not the prompt, bounds the count. */
|
|
307
317
|
export const QUESTIONS_PROMPT: string;
|
|
308
|
-
export const DRAFT_PROVIDER_OPTIONS: Readonly<{
|
|
309
|
-
thinking: Readonly<{
|
|
310
|
-
type: "disabled";
|
|
311
|
-
}>;
|
|
312
|
-
timeoutMs: 300000;
|
|
313
|
-
deadlineMs: 240000;
|
|
314
|
-
}>;
|
|
315
318
|
import { makeProvider } from './provider.js';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {string} dir a draft folder or a flow folder
|
|
3
|
+
* @returns {{ slot: string, model: string }|null} null when there is no usable record (missing, unreadable, or not a name and a model id)
|
|
4
|
+
*/
|
|
5
|
+
export function readModelRecord(dir: string): {
|
|
6
|
+
slot: string;
|
|
7
|
+
model: string;
|
|
8
|
+
} | null;
|
|
9
|
+
/**
|
|
10
|
+
* Write the record once (never over an existing one). @param {string} dir @param {{ slot: string, model: string }} pick
|
|
11
|
+
*/
|
|
12
|
+
export function writeModelRecord(dir: string, { slot, model }: {
|
|
13
|
+
slot: string;
|
|
14
|
+
model: string;
|
|
15
|
+
}): void;
|
|
16
|
+
export const MODEL_FILE: "model.json";
|
package/types/input-facts.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @param {Array<{kind?:string, role:string, path:string}>} sources arbiter.sources
|
|
3
|
-
*
|
|
3
|
+
* `list` (M4d am10) is one `{role, detail}` per readable input for the Chat card's list (a CSV: its columns; text: its headings); never hashed.
|
|
4
|
+
* @returns {{ok:boolean, inputFacts:Record<string,string[]>, info:string[], list:Array<{role:string, detail:string}>, reds:string[]}}
|
|
4
5
|
*/
|
|
5
6
|
export function readInputFacts(sources: Array<{
|
|
6
7
|
kind?: string;
|
|
@@ -10,5 +11,9 @@ export function readInputFacts(sources: Array<{
|
|
|
10
11
|
ok: boolean;
|
|
11
12
|
inputFacts: Record<string, string[]>;
|
|
12
13
|
info: string[];
|
|
14
|
+
list: Array<{
|
|
15
|
+
role: string;
|
|
16
|
+
detail: string;
|
|
17
|
+
}>;
|
|
13
18
|
reds: string[];
|
|
14
19
|
};
|
package/types/keysfile.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE rule for what may be a key name (hamr's ruling, branch-review): it looks like an API key, `…_KEY` in capitals. Used at every gate:
|
|
3
|
+
* the `names` Settings lists, the env pass-through, and the routes that take a slot name. A `NODE_OPTIONS` line is not a key.
|
|
4
|
+
* @param {unknown} name @returns {name is string}
|
|
5
|
+
*/
|
|
6
|
+
export function isKeyName(name: unknown): name is string;
|
|
1
7
|
/**
|
|
2
8
|
* `~/.config/fwdloop`, or an injected override. The CLI/panel door honors the test-only
|
|
3
9
|
* `FWDLOOP_CONFIG_HOME` through `keysForDoor` (two gates, like the other test seams).
|
|
@@ -25,20 +31,29 @@ export function parseKeysText(text: string): Record<string, string>;
|
|
|
25
31
|
* @property {string} path the keys file's path as shown to people
|
|
26
32
|
* @property {boolean} exists the file is there (true after a create)
|
|
27
33
|
* @property {string[]} names the NAMES the file defines with a value (sorted; never values)
|
|
28
|
-
* @property {string[]} shellOnly the
|
|
34
|
+
* @property {string[]} shellOnly the configured key names that only the shell sets (file empty/absent)
|
|
35
|
+
* @property {string[]} keyNames the NAMES of the keys that are set up in Settings and hold a value in `env` (the scrub list's names; never values)
|
|
29
36
|
* @property {string|null} refusal a plain sentence when `ok` is false, else null
|
|
30
37
|
* @property {Record<string,string|undefined>} env shell env with the file filling the names the
|
|
31
38
|
* shell does not set; on a refusal just a copy of the shell env (no file value). THE ONLY
|
|
32
39
|
* place file values leave this module.
|
|
33
40
|
*/
|
|
34
41
|
/**
|
|
35
|
-
*
|
|
36
|
-
* @param {
|
|
42
|
+
* The key VALUES of the named keys in an env: the scrub list. The names come from a load's `keyNames`.
|
|
43
|
+
* @param {Record<string,string|undefined>} env @param {readonly string[]|undefined} names
|
|
44
|
+
* @returns {string[]}
|
|
45
|
+
*/
|
|
46
|
+
export function keyValues(env: Record<string, string | undefined>, names: readonly string[] | undefined): string[];
|
|
47
|
+
/**
|
|
48
|
+
* Load the keys file over an env. A missing file is created (0600) and is not a refusal. `configured` = the key names that have a row
|
|
49
|
+
* set up in Settings (`config.providers`): only those file values reach `env`.
|
|
50
|
+
* @param {{ env?: Record<string,string|undefined>, home?: string, configured?: string[] }} [opts]
|
|
37
51
|
* @returns {KeysLoad}
|
|
38
52
|
*/
|
|
39
53
|
export function loadKeysEnv(opts?: {
|
|
40
54
|
env?: Record<string, string | undefined>;
|
|
41
55
|
home?: string;
|
|
56
|
+
configured?: string[];
|
|
42
57
|
}): KeysLoad;
|
|
43
58
|
/**
|
|
44
59
|
* The door helper the CLI and the panel call. Loads the file only when the caller is on the
|
|
@@ -54,8 +69,6 @@ export function keysForDoor(deps?: {
|
|
|
54
69
|
}): KeysLoad & {
|
|
55
70
|
skipped: boolean;
|
|
56
71
|
};
|
|
57
|
-
/** The key names fwdloop knows (one per provider slot). */
|
|
58
|
-
export const KEY_NAMES: readonly ("SYNTHETIC_API_KEY" | "DEEPSEEK_API_KEY")[];
|
|
59
72
|
export type KeysLoad = {
|
|
60
73
|
/**
|
|
61
74
|
* false = refused: nothing that needs a key may run
|
|
@@ -74,9 +87,13 @@ export type KeysLoad = {
|
|
|
74
87
|
*/
|
|
75
88
|
names: string[];
|
|
76
89
|
/**
|
|
77
|
-
* the
|
|
90
|
+
* the configured key names that only the shell sets (file empty/absent)
|
|
78
91
|
*/
|
|
79
92
|
shellOnly: string[];
|
|
93
|
+
/**
|
|
94
|
+
* the NAMES of the keys that are set up in Settings and hold a value in `env` (the scrub list's names; never values)
|
|
95
|
+
*/
|
|
96
|
+
keyNames: string[];
|
|
80
97
|
/**
|
|
81
98
|
* a plain sentence when `ok` is false, else null
|
|
82
99
|
*/
|
package/types/model-step.d.ts
CHANGED
|
@@ -80,7 +80,7 @@ export function buildEmitArtifactSchema(stepClass: any): Readonly<{
|
|
|
80
80
|
}>;
|
|
81
81
|
/**
|
|
82
82
|
* @param {object} opts
|
|
83
|
-
* @param {string} [opts.slot] - a
|
|
83
|
+
* @param {string} [opts.slot] - a provider row (the name of a key in the keys file); required when `provider` isn't injected.
|
|
84
84
|
* @param {string} [opts.model] - overrides the slot's default model.
|
|
85
85
|
* @param {string} opts.spendPath - the run's spend.jsonl (never a second ledger).
|
|
86
86
|
* @param {any} [opts.provider] - an injected provider (tests only; production always builds live via `slot`).
|
package/types/monthly.d.ts
CHANGED
package/types/panel/author.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @param {{ root: string, home?: string, skipMonthly?: boolean, loadEnv: () => { ok: boolean, env: Record<string, string|undefined>, refusal: string|null }, bin?: string, childRunning?: (dir: string) => boolean }} opts
|
|
2
|
+
* @param {{ root: string, home?: string, skipMonthly?: boolean, loadEnv: () => { ok: boolean, env: Record<string, string|undefined>, refusal: string|null, keyNames?: string[] }, bin?: string, childRunning?: (dir: string) => boolean, thinkingSupport?: typeof bareagentThinkingSupport }} opts
|
|
3
3
|
* `loadEnv` is the keys-file door (`keysForDoor`): called before EVERY spawn and every reply that quotes a log, so editing
|
|
4
4
|
* the file needs no restart. Its `env` is BOTH the child's spawn env AND the scrub list (POC (a), M4d wiring rule).
|
|
5
5
|
*/
|
|
@@ -11,9 +11,11 @@ export function createAuthor(opts: {
|
|
|
11
11
|
ok: boolean;
|
|
12
12
|
env: Record<string, string | undefined>;
|
|
13
13
|
refusal: string | null;
|
|
14
|
+
keyNames?: string[];
|
|
14
15
|
};
|
|
15
16
|
bin?: string;
|
|
16
17
|
childRunning?: (dir: string) => boolean;
|
|
18
|
+
thinkingSupport?: typeof bareagentThinkingSupport;
|
|
17
19
|
}): {
|
|
18
20
|
flows: () => {
|
|
19
21
|
status: number;
|
|
@@ -51,8 +53,13 @@ export function createAuthor(opts: {
|
|
|
51
53
|
};
|
|
52
54
|
jobLines: any;
|
|
53
55
|
hasSend: boolean;
|
|
54
|
-
capFloorUsd:
|
|
56
|
+
capFloorUsd: number;
|
|
55
57
|
floorText: string;
|
|
58
|
+
model: {
|
|
59
|
+
slot: string;
|
|
60
|
+
model: string;
|
|
61
|
+
label: string;
|
|
62
|
+
} | null;
|
|
56
63
|
flow: string;
|
|
57
64
|
capUsd: any;
|
|
58
65
|
roles: any;
|
|
@@ -127,8 +134,13 @@ export function createAuthor(opts: {
|
|
|
127
134
|
};
|
|
128
135
|
jobLines: any;
|
|
129
136
|
hasSend: boolean;
|
|
130
|
-
capFloorUsd:
|
|
137
|
+
capFloorUsd: number;
|
|
131
138
|
floorText: string;
|
|
139
|
+
model: {
|
|
140
|
+
slot: string;
|
|
141
|
+
model: string;
|
|
142
|
+
label: string;
|
|
143
|
+
} | null;
|
|
132
144
|
flow: string;
|
|
133
145
|
capUsd: any;
|
|
134
146
|
roles: any;
|
|
@@ -183,18 +195,43 @@ export function createAuthor(opts: {
|
|
|
183
195
|
* `GET /api/author/monthly-check?cap=<usd>`: the note under Cap, one read-only check. `{ text, red }` is what to show (red =
|
|
184
196
|
* the cap does not fit this month); `floorUsd` is the smallest cap that funds one round of a model step, for the page's
|
|
185
197
|
* `needs at least $X per run` line. A cap that is not a number above 0 gets no note. Never spends, never writes.
|
|
186
|
-
* @param {unknown} cap @param {string|null} [spent] what a resumed run has already spent (amendment 4 item 4)
|
|
198
|
+
* @param {unknown} cap @param {string|null} [spent] what a resumed run has already spent (amendment 4 item 4) @param {{ provider?: string, model?: string, flow?: string }|null} [pick] the card's picked model, or (a Resume) the flow whose recorded model it is: its own prices are the floor (M4d am6)
|
|
187
199
|
*/
|
|
188
|
-
monthlyCheck(cap: unknown, spent?: string | null
|
|
200
|
+
monthlyCheck(cap: unknown, spent?: string | null, pick?: {
|
|
201
|
+
provider?: string;
|
|
202
|
+
model?: string;
|
|
203
|
+
flow?: string;
|
|
204
|
+
} | null): {
|
|
189
205
|
status: number;
|
|
190
206
|
body: {
|
|
191
207
|
ok: boolean;
|
|
192
208
|
text: string;
|
|
193
209
|
red: boolean;
|
|
194
|
-
floorUsd:
|
|
210
|
+
floorUsd: number;
|
|
195
211
|
floorText: string;
|
|
196
212
|
};
|
|
197
213
|
};
|
|
214
|
+
/**
|
|
215
|
+
* `GET /api/author/models` (M4d amendment 6 item 6): what Chat's Model menu offers - every ticked, priced line of a provider whose key is set up, as
|
|
216
|
+
* "provider · model" - and, per line, whether "Thinking on" can change (`canChange`; bareagent's answer through `src/thinking.js`, am7). Read-only.
|
|
217
|
+
*/
|
|
218
|
+
models(): {
|
|
219
|
+
status: number;
|
|
220
|
+
body: {
|
|
221
|
+
ok: boolean;
|
|
222
|
+
lines: {
|
|
223
|
+
thinking: {
|
|
224
|
+
support: boolean | "unverified";
|
|
225
|
+
canChange: boolean;
|
|
226
|
+
say: string;
|
|
227
|
+
};
|
|
228
|
+
slot: string;
|
|
229
|
+
model: string;
|
|
230
|
+
label: string;
|
|
231
|
+
}[];
|
|
232
|
+
say: string;
|
|
233
|
+
};
|
|
234
|
+
};
|
|
198
235
|
/** `GET /api/author/start/:startId`: the start's phase, read from its files. @param {string} id */
|
|
199
236
|
startGet(id: string): {
|
|
200
237
|
status: number;
|
|
@@ -348,3 +385,4 @@ export function createAuthor(opts: {
|
|
|
348
385
|
};
|
|
349
386
|
/** Up to 2 revises per draft (amendment 14 item 3); a revise is used once its `draft-<n>/` exists (a refusal at $0 makes none). */
|
|
350
387
|
export const MAX_REVISES: 2;
|
|
388
|
+
import { thinkingSupport as bareagentThinkingSupport } from '../thinking.js';
|
|
@@ -66,6 +66,9 @@ export function cardFields(body: any): {
|
|
|
66
66
|
flow: any;
|
|
67
67
|
flowHash: any;
|
|
68
68
|
} | undefined;
|
|
69
|
+
thinking?: boolean | undefined;
|
|
70
|
+
provider?: string | undefined;
|
|
71
|
+
model?: string | undefined;
|
|
69
72
|
flowName: string;
|
|
70
73
|
job: string;
|
|
71
74
|
destination: string;
|
|
@@ -133,13 +136,22 @@ export function checkInputRows(rows: {
|
|
|
133
136
|
/**
|
|
134
137
|
* M4e amendment 4 item 2: the smallest per-run cap that funds ONE round of the first model step. The runner halts a step when
|
|
135
138
|
* `spent + ceiling > cap` (`runStepRalph`), and every ordinary (non-ask) step is a model step, so the floor is the runner's own
|
|
136
|
-
* per-round
|
|
139
|
+
* per-round hold (the picked model's own Settings prices times the token bounds) as soon as the job has one such line; a job of only asks spends nothing before its stop.
|
|
137
140
|
* ONE function: the card's Draft check, Sign, and the page's note all read it. Returns 0 when no step needs a round.
|
|
138
|
-
* @param {string} jobText
|
|
141
|
+
* @param {string} jobText @param {string} [home] the config home the panel reads Settings from (default: the process door)
|
|
142
|
+
* @param {{ slot?: string, provider?: string, model?: string }|null} [pick] the job's picked model (M4d amendment 6): its own Settings prices are the hold (a card names its key as `provider`)
|
|
139
143
|
*/
|
|
140
|
-
export function capFloorUsd(jobText: string
|
|
141
|
-
|
|
142
|
-
|
|
144
|
+
export function capFloorUsd(jobText: string, home?: string, pick?: {
|
|
145
|
+
slot?: string;
|
|
146
|
+
provider?: string;
|
|
147
|
+
model?: string;
|
|
148
|
+
} | null): number;
|
|
149
|
+
/** The floor itself, for a caller that already knows whether the job has a step that is not an ask (a signed flow: any step off an ask line). @param {boolean} hasRoundStep @param {string} [home] @param {{ slot?: string, provider?: string, model?: string }|null} [pick] */
|
|
150
|
+
export function capFloorFor(hasRoundStep: boolean, home?: string, pick?: {
|
|
151
|
+
slot?: string;
|
|
152
|
+
provider?: string;
|
|
153
|
+
model?: string;
|
|
154
|
+
} | null): number;
|
|
143
155
|
/** The one sentence for a cap under the floor (red under Cap, and the Draft / sign refusal). @param {number} floorUsd */
|
|
144
156
|
export function capFloorText(floorUsd: number): string;
|
|
145
157
|
/**
|
|
@@ -153,12 +165,13 @@ export function destinationRefusal(dest: string, root: string): string | null;
|
|
|
153
165
|
/**
|
|
154
166
|
* Every $0 check on the card, before any spawn (scope 6). Collects all refusals so the page can name every box.
|
|
155
167
|
* @param {ReturnType<typeof cardFields>} card
|
|
156
|
-
* @param {{ root: string,
|
|
168
|
+
* @param {{ root: string, keys?: string[], home?: string }} ctx `keys` = the provider key values (the keys load's scrub list): a key value typed into any box is refused; `home` = the config home Settings is read from (the cap floor)
|
|
157
169
|
* @returns {{ ok: true, prose: string }|{ ok: false, refusals: {field: string, say: string}[] }}
|
|
158
170
|
*/
|
|
159
|
-
export function checkCard(card: ReturnType<typeof cardFields>, { root,
|
|
171
|
+
export function checkCard(card: ReturnType<typeof cardFields>, { root, keys, home }: {
|
|
160
172
|
root: string;
|
|
161
|
-
|
|
173
|
+
keys?: string[];
|
|
174
|
+
home?: string;
|
|
162
175
|
}): {
|
|
163
176
|
ok: true;
|
|
164
177
|
prose: string;
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* What the Run / Resume forms show of a signed flow (read from its own files, never from a model): the job lines as the signed text has them
|
|
3
3
|
* (an ask line carries its question and its wait), the values the open boxes start from, and the cap floor. Amendment 5 item 2: all the rest is dimmed.
|
|
4
|
-
* @param {any} read `readFlow`'s ok result
|
|
4
|
+
* @param {any} read `readFlow`'s ok result @param {string} [home] the config home Settings is read from @param {string} [flowDir] the signed flow's folder: the model recorded beside it is the one it runs with (M4d amendment 6)
|
|
5
|
+
* @param {{ slot: string, model: string }|null} [picked] a flow with no record runs with the model picked in Chat (M4d amendment 7b): its price is the cap floor
|
|
5
6
|
*/
|
|
6
|
-
export function formFacts(read: any
|
|
7
|
+
export function formFacts(read: any, home?: string, flowDir?: string, picked?: {
|
|
8
|
+
slot: string;
|
|
9
|
+
model: string;
|
|
10
|
+
} | null): {
|
|
7
11
|
values: {
|
|
8
12
|
capUsd: number;
|
|
9
13
|
destination: string | null;
|
|
@@ -11,11 +15,16 @@ export function formFacts(read: any): {
|
|
|
11
15
|
};
|
|
12
16
|
jobLines: any;
|
|
13
17
|
hasSend: boolean;
|
|
14
|
-
capFloorUsd:
|
|
18
|
+
capFloorUsd: number;
|
|
15
19
|
floorText: string;
|
|
20
|
+
model: {
|
|
21
|
+
slot: string;
|
|
22
|
+
model: string;
|
|
23
|
+
label: string;
|
|
24
|
+
} | null;
|
|
16
25
|
};
|
|
17
26
|
/**
|
|
18
|
-
* @param {{ root: string, home?: string, skipMonthly?: boolean, loadEnv: () => { ok: boolean, env: Record<string, string|undefined>, refusal: string|null }, starter: ReturnType<typeof import('./authorstart.js').createStarter>, monthlyClaim: (usd: number) => any }} opts
|
|
27
|
+
* @param {{ root: string, home?: string, skipMonthly?: boolean, loadEnv: () => { ok: boolean, env: Record<string, string|undefined>, refusal: string|null }, starter: ReturnType<typeof import('./authorstart.js').createStarter>, monthlyClaim: (usd: number) => any, modelRefusal: (card: any, loaded: any) => { field: string, say: string }[] }} opts
|
|
19
28
|
*/
|
|
20
29
|
export function createFlowsDoor(opts: {
|
|
21
30
|
root: string;
|
|
@@ -28,6 +37,10 @@ export function createFlowsDoor(opts: {
|
|
|
28
37
|
};
|
|
29
38
|
starter: ReturnType<typeof import("./authorstart.js").createStarter>;
|
|
30
39
|
monthlyClaim: (usd: number) => any;
|
|
40
|
+
modelRefusal: (card: any, loaded: any) => {
|
|
41
|
+
field: string;
|
|
42
|
+
say: string;
|
|
43
|
+
}[];
|
|
31
44
|
}): {
|
|
32
45
|
/** M6 amendments 1 and 3: the sentence that says why this flow cannot be edited now, or null (the sign route's check). @param {string} name */
|
|
33
46
|
editBlock(name: string): string | null;
|
|
@@ -68,8 +81,13 @@ export function createFlowsDoor(opts: {
|
|
|
68
81
|
};
|
|
69
82
|
jobLines: any;
|
|
70
83
|
hasSend: boolean;
|
|
71
|
-
capFloorUsd:
|
|
84
|
+
capFloorUsd: number;
|
|
72
85
|
floorText: string;
|
|
86
|
+
model: {
|
|
87
|
+
slot: string;
|
|
88
|
+
model: string;
|
|
89
|
+
label: string;
|
|
90
|
+
} | null;
|
|
73
91
|
flow: string;
|
|
74
92
|
capUsd: any;
|
|
75
93
|
roles: any;
|
|
@@ -150,8 +168,13 @@ export function createFlowsDoor(opts: {
|
|
|
150
168
|
};
|
|
151
169
|
jobLines: any;
|
|
152
170
|
hasSend: boolean;
|
|
153
|
-
capFloorUsd:
|
|
171
|
+
capFloorUsd: number;
|
|
154
172
|
floorText: string;
|
|
173
|
+
model: {
|
|
174
|
+
slot: string;
|
|
175
|
+
model: string;
|
|
176
|
+
label: string;
|
|
177
|
+
} | null;
|
|
155
178
|
flow: string;
|
|
156
179
|
capUsd: any;
|
|
157
180
|
roles: any;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @param {{ root: string, loadEnv: () => { ok: boolean, env: Record<string, string|undefined>, refusal: string|null }, monthlyClaim: (usd: number) => any, starter: ReturnType<typeof import('./authorstart.js').createStarter> }} opts
|
|
2
|
+
* @param {{ root: string, home?: string, loadEnv: () => { ok: boolean, env: Record<string, string|undefined>, refusal: string|null }, monthlyClaim: (usd: number) => any, starter: ReturnType<typeof import('./authorstart.js').createStarter> }} opts
|
|
3
3
|
*/
|
|
4
4
|
export function createResumeDoor(opts: {
|
|
5
5
|
root: string;
|
|
6
|
+
home?: string;
|
|
6
7
|
loadEnv: () => {
|
|
7
8
|
ok: boolean;
|
|
8
9
|
env: Record<string, string | undefined>;
|
|
@@ -21,11 +21,11 @@ export function createStarter(opts: {
|
|
|
21
21
|
* `runId` '' = no typed id: the start CLAIMS the next `run-<n>` itself (claimRunId, folder created exclusively; amendment 3).
|
|
22
22
|
* `values` (M4e amendment 5 item 3): the human's signed values for THIS run (the page's second click), written once into the run's own
|
|
23
23
|
* folder as `signed-values.json` BEFORE the spawn; the run then uses them (`pickRunValues`). None = the flow's own.
|
|
24
|
-
* @param {{ kind: 'run'|'sign', flow: string, runId: string, sources: {role: string, path: string}[], values?: any }} a
|
|
25
|
-
* @param {Record<string, string|undefined
|
|
24
|
+
* @param {{ kind: 'run'|'sign', flow: string, runId: string, sources: {role: string, path: string}[], values?: any, pick?: {slot: string, model: string}|null }} a
|
|
25
|
+
* @param {{ env: Record<string, string|undefined>, keyNames?: string[] }} loaded the keys load: its env is the child's env AND (with its key names) the scrub list
|
|
26
26
|
* @returns {{ status: number, body: any }}
|
|
27
27
|
*/
|
|
28
|
-
start({ kind, flow, runId, sources, values, }: {
|
|
28
|
+
start({ kind, flow, runId, sources, values, pick, }: {
|
|
29
29
|
kind: "run" | "sign";
|
|
30
30
|
flow: string;
|
|
31
31
|
runId: string;
|
|
@@ -34,7 +34,14 @@ export function createStarter(opts: {
|
|
|
34
34
|
path: string;
|
|
35
35
|
}[];
|
|
36
36
|
values?: any;
|
|
37
|
-
|
|
37
|
+
pick?: {
|
|
38
|
+
slot: string;
|
|
39
|
+
model: string;
|
|
40
|
+
} | null;
|
|
41
|
+
}, loaded: {
|
|
42
|
+
env: Record<string, string | undefined>;
|
|
43
|
+
keyNames?: string[];
|
|
44
|
+
}): {
|
|
38
45
|
status: number;
|
|
39
46
|
body: any;
|
|
40
47
|
};
|
|
@@ -42,14 +49,17 @@ export function createStarter(opts: {
|
|
|
42
49
|
* Start `fwdloop continue <runId>` (M4e amendment 4 item 4): Resume of a stopped or cap-halted run, after the door wrote the run's new
|
|
43
50
|
* signed values version. The same detached-child shape as `start`; the start folder reads as `starting` until the child consumes
|
|
44
51
|
* `halt.json`, then `started`; a child that died with `halt.json` still there is `refused` with its own sentence. One start at a time per flow.
|
|
45
|
-
* @param {{ flow: string, runId: string, version: number }} a @param {Record<string, string|undefined
|
|
52
|
+
* @param {{ flow: string, runId: string, version: number }} a @param {{ env: Record<string, string|undefined>, keyNames?: string[] }} loaded the keys load
|
|
46
53
|
* @returns {{ status: number, body: any }}
|
|
47
54
|
*/
|
|
48
55
|
startContinue({ flow, runId, version }: {
|
|
49
56
|
flow: string;
|
|
50
57
|
runId: string;
|
|
51
58
|
version: number;
|
|
52
|
-
},
|
|
59
|
+
}, loaded: {
|
|
60
|
+
env: Record<string, string | undefined>;
|
|
61
|
+
keyNames?: string[];
|
|
62
|
+
}): {
|
|
53
63
|
status: number;
|
|
54
64
|
body: any;
|
|
55
65
|
};
|
package/types/panel/data.d.ts
CHANGED
|
@@ -224,8 +224,8 @@ export function costDisplay(spentUsd: number | null | undefined, spendComplete:
|
|
|
224
224
|
* never a stale first-attempt value. `null` (never a guess) when no row in
|
|
225
225
|
* this run ever named one (e.g. every step is `hitl`, no model step ran).
|
|
226
226
|
* No provider/API-kind field exists in ANY book (`src/provider.js`'s
|
|
227
|
-
*
|
|
228
|
-
*
|
|
227
|
+
* a provider row maps to a model, but nothing writes which
|
|
228
|
+
* row served a given run back to `audit.jsonl`/`spend.jsonl`) — provider is
|
|
229
229
|
* never shown alongside it (hamr's own instruction: "if the provider isn't
|
|
230
230
|
* in any book, show model only").
|
|
231
231
|
* @param {any[]} auditRows
|
package/types/panel/resume.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @param {{ root: string, env?: Record<string, string|undefined>, loadEnv?: () => { ok: boolean, env: Record<string, string|undefined>, refusal: string|null }, bin?: string, logDir?: string,
|
|
2
|
+
* @param {{ root: string, env?: Record<string, string|undefined>, loadEnv?: () => { ok: boolean, env: Record<string, string|undefined>, refusal: string|null, keyNames?: string[] }, bin?: string, logDir?: string,
|
|
3
3
|
* maxTries?: number, windowMs?: number, slotMs?: number }} opts
|
|
4
4
|
* `loadEnv` (M4d: the keys-file door, called before EVERY spawn so editing the file needs no panel restart) returns the merged env
|
|
5
5
|
* that is BOTH the child's spawn env AND its scrub list, or a refusal sentence that becomes the attempt's refusal (nothing spawns).
|
|
@@ -16,6 +16,7 @@ export function createResumer(opts: {
|
|
|
16
16
|
ok: boolean;
|
|
17
17
|
env: Record<string, string | undefined>;
|
|
18
18
|
refusal: string | null;
|
|
19
|
+
keyNames?: string[];
|
|
19
20
|
};
|
|
20
21
|
bin?: string;
|
|
21
22
|
logDir?: string;
|