bernard-agent 0.8.1 → 0.9.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/README.md +80 -44
- package/dist/agent.d.ts +14 -3
- package/dist/agent.js +228 -38
- package/dist/agent.js.map +1 -1
- package/dist/builtin-specialists/correction-agent.json +32 -0
- package/dist/builtin-specialists/file-wrapper.json +43 -0
- package/dist/builtin-specialists/shell-wrapper.json +50 -0
- package/dist/builtin-specialists/specialist-creator.json +32 -0
- package/dist/builtin-specialists/web-wrapper.json +38 -0
- package/dist/candidate-bootstrap.d.ts +18 -0
- package/dist/candidate-bootstrap.js +61 -0
- package/dist/candidate-bootstrap.js.map +1 -0
- package/dist/config.d.ts +126 -10
- package/dist/config.js +222 -45
- package/dist/config.js.map +1 -1
- package/dist/context.js +23 -6
- package/dist/context.js.map +1 -1
- package/dist/correction-candidates.d.ts +54 -0
- package/dist/correction-candidates.js +138 -0
- package/dist/correction-candidates.js.map +1 -0
- package/dist/correction.d.ts +67 -0
- package/dist/correction.js +138 -0
- package/dist/correction.js.map +1 -0
- package/dist/critic.js +2 -1
- package/dist/critic.js.map +1 -1
- package/dist/cron/notes-store.d.ts +41 -0
- package/dist/cron/notes-store.js +134 -0
- package/dist/cron/notes-store.js.map +1 -0
- package/dist/cron/runner.js +25 -3
- package/dist/cron/runner.js.map +1 -1
- package/dist/cron/scoped-notes-tools.d.ts +24 -0
- package/dist/cron/scoped-notes-tools.js +50 -0
- package/dist/cron/scoped-notes-tools.js.map +1 -0
- package/dist/custom-providers.d.ts +80 -0
- package/dist/custom-providers.js +238 -0
- package/dist/custom-providers.js.map +1 -0
- package/dist/fs-utils.d.ts +2 -0
- package/dist/fs-utils.js +44 -0
- package/dist/fs-utils.js.map +1 -0
- package/dist/history.js +3 -1
- package/dist/history.js.map +1 -1
- package/dist/image.d.ts +59 -0
- package/dist/image.js +228 -0
- package/dist/image.js.map +1 -0
- package/dist/index.js +72 -4
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +1 -1
- package/dist/mcp.js.map +1 -1
- package/dist/memory.d.ts +13 -0
- package/dist/memory.js +45 -4
- package/dist/memory.js.map +1 -1
- package/dist/menu.d.ts +97 -0
- package/dist/menu.js +338 -0
- package/dist/menu.js.map +1 -0
- package/dist/os-info.d.ts +22 -0
- package/dist/os-info.js +111 -0
- package/dist/os-info.js.map +1 -0
- package/dist/output.d.ts +35 -1
- package/dist/output.js +256 -45
- package/dist/output.js.map +1 -1
- package/dist/pac.d.ts +14 -2
- package/dist/pac.js +5 -5
- package/dist/pac.js.map +1 -1
- package/dist/paths.d.ts +5 -0
- package/dist/paths.js +6 -1
- package/dist/paths.js.map +1 -1
- package/dist/plan-store.d.ts +47 -0
- package/dist/plan-store.js +94 -0
- package/dist/plan-store.js.map +1 -0
- package/dist/prompt-rewriter.d.ts +29 -0
- package/dist/prompt-rewriter.js +155 -0
- package/dist/prompt-rewriter.js.map +1 -0
- package/dist/providers/index.d.ts +56 -4
- package/dist/providers/index.js +86 -5
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/profiles.d.ts +37 -0
- package/dist/providers/profiles.js +110 -0
- package/dist/providers/profiles.js.map +1 -0
- package/dist/providers/types.d.ts +11 -2
- package/dist/providers/types.js +3 -0
- package/dist/providers/types.js.map +1 -1
- package/dist/rag-query.js +15 -1
- package/dist/rag-query.js.map +1 -1
- package/dist/react.d.ts +38 -0
- package/dist/react.js +116 -0
- package/dist/react.js.map +1 -0
- package/dist/reasoning-log.d.ts +30 -0
- package/dist/reasoning-log.js +102 -0
- package/dist/reasoning-log.js.map +1 -0
- package/dist/reference-resolver.d.ts +47 -0
- package/dist/reference-resolver.js +316 -0
- package/dist/reference-resolver.js.map +1 -0
- package/dist/reference-tool-lookup.d.ts +37 -0
- package/dist/reference-tool-lookup.js +318 -0
- package/dist/reference-tool-lookup.js.map +1 -0
- package/dist/repl.js +1038 -371
- package/dist/repl.js.map +1 -1
- package/dist/setup.js +2 -1
- package/dist/setup.js.map +1 -1
- package/dist/specialist-detector.js +2 -1
- package/dist/specialist-detector.js.map +1 -1
- package/dist/specialists.d.ts +74 -3
- package/dist/specialists.js +152 -20
- package/dist/specialists.js.map +1 -1
- package/dist/structured-output.d.ts +58 -0
- package/dist/structured-output.js +138 -0
- package/dist/structured-output.js.map +1 -0
- package/dist/theme.d.ts +2 -0
- package/dist/theme.js +18 -12
- package/dist/theme.js.map +1 -1
- package/dist/tool-call-repair.d.ts +29 -0
- package/dist/tool-call-repair.js +99 -0
- package/dist/tool-call-repair.js.map +1 -0
- package/dist/tool-profiles.d.ts +70 -0
- package/dist/tool-profiles.js +385 -0
- package/dist/tool-profiles.js.map +1 -0
- package/dist/tools/activity-summary.d.ts +15 -0
- package/dist/tools/activity-summary.js +44 -0
- package/dist/tools/activity-summary.js.map +1 -0
- package/dist/tools/ask-user.d.ts +49 -0
- package/dist/tools/ask-user.js +52 -0
- package/dist/tools/ask-user.js.map +1 -0
- package/dist/tools/augment.d.ts +17 -0
- package/dist/tools/augment.js +102 -0
- package/dist/tools/augment.js.map +1 -0
- package/dist/tools/cron-logs.js +7 -0
- package/dist/tools/cron-logs.js.map +1 -1
- package/dist/tools/cron-notes.d.ts +52 -0
- package/dist/tools/cron-notes.js +105 -0
- package/dist/tools/cron-notes.js.map +1 -0
- package/dist/tools/datetime.d.ts +7 -0
- package/dist/tools/datetime.js +29 -3
- package/dist/tools/datetime.js.map +1 -1
- package/dist/tools/evaluate.d.ts +20 -0
- package/dist/tools/evaluate.js +29 -0
- package/dist/tools/evaluate.js.map +1 -0
- package/dist/tools/index.js +4 -0
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/mcp.d.ts +3 -3
- package/dist/tools/plan.d.ts +81 -0
- package/dist/tools/plan.js +108 -0
- package/dist/tools/plan.js.map +1 -0
- package/dist/tools/result-cap.d.ts +24 -0
- package/dist/tools/result-cap.js +44 -0
- package/dist/tools/result-cap.js.map +1 -0
- package/dist/tools/routine.d.ts +3 -3
- package/dist/tools/shell.d.ts +14 -1
- package/dist/tools/shell.js +86 -4
- package/dist/tools/shell.js.map +1 -1
- package/dist/tools/specialist-run.d.ts +5 -3
- package/dist/tools/specialist-run.js +115 -24
- package/dist/tools/specialist-run.js.map +1 -1
- package/dist/tools/specialist.d.ts +83 -3
- package/dist/tools/specialist.js +83 -3
- package/dist/tools/specialist.js.map +1 -1
- package/dist/tools/subagent.js +32 -14
- package/dist/tools/subagent.js.map +1 -1
- package/dist/tools/task.d.ts +5 -5
- package/dist/tools/task.js +9 -42
- package/dist/tools/task.js.map +1 -1
- package/dist/tools/think.d.ts +18 -0
- package/dist/tools/think.js +25 -0
- package/dist/tools/think.js.map +1 -0
- package/dist/tools/tool-wrapper-run.d.ts +121 -0
- package/dist/tools/tool-wrapper-run.js +382 -0
- package/dist/tools/tool-wrapper-run.js.map +1 -0
- package/dist/tools/types.d.ts +28 -2
- package/dist/tools/web-search.d.ts +31 -0
- package/dist/tools/web-search.js +172 -0
- package/dist/tools/web-search.js.map +1 -0
- package/dist/tools/wrap-with-specialist.d.ts +55 -0
- package/dist/tools/wrap-with-specialist.js +137 -0
- package/dist/tools/wrap-with-specialist.js.map +1 -0
- package/package.json +2 -2
package/dist/specialists.js
CHANGED
|
@@ -33,13 +33,64 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.SpecialistStore = void 0;
|
|
36
|
+
exports.SpecialistStore = exports.MAX_EXAMPLES_PER_LIST = void 0;
|
|
37
|
+
exports.getBuiltinSpecialistIds = getBuiltinSpecialistIds;
|
|
37
38
|
const fs = __importStar(require("node:fs"));
|
|
38
39
|
const path = __importStar(require("node:path"));
|
|
39
40
|
const paths_js_1 = require("./paths.js");
|
|
40
41
|
const reserved_names_js_1 = require("./reserved-names.js");
|
|
42
|
+
const fs_utils_js_1 = require("./fs-utils.js");
|
|
43
|
+
/** Maximum examples retained per list (oldest drop-off during correction updates). */
|
|
44
|
+
exports.MAX_EXAMPLES_PER_LIST = 10;
|
|
41
45
|
const MAX_SPECIALISTS = 50;
|
|
42
46
|
const ID_PATTERN = /^[a-z0-9](?:[a-z0-9-]{0,58}[a-z0-9])?$/;
|
|
47
|
+
/** Marker file that prevents re-seeding bundled specialists on every start. */
|
|
48
|
+
const SEED_MARKER = '.seeded-v1';
|
|
49
|
+
/**
|
|
50
|
+
* Locates the bundled `builtin-specialists` directory sitting next to the
|
|
51
|
+
* compiled/loaded `specialists.js` (or `.ts` under tsx). Returns `null` when
|
|
52
|
+
* running in an environment where the bundle was not deployed (e.g. certain
|
|
53
|
+
* test harnesses).
|
|
54
|
+
*/
|
|
55
|
+
function findBuiltinSpecialistsDir() {
|
|
56
|
+
const candidate = path.join(__dirname, 'builtin-specialists');
|
|
57
|
+
try {
|
|
58
|
+
if (fs.statSync(candidate).isDirectory())
|
|
59
|
+
return candidate;
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
// fall through
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
let cachedBuiltinIds = null;
|
|
67
|
+
/**
|
|
68
|
+
* Returns the set of specialist IDs that ship bundled with Bernard. Used to
|
|
69
|
+
* distinguish seeded specialists from user-authored ones in the UI. Result is
|
|
70
|
+
* cached after the first call — the bundle is packaged alongside the binary
|
|
71
|
+
* and does not change at runtime.
|
|
72
|
+
*/
|
|
73
|
+
function getBuiltinSpecialistIds() {
|
|
74
|
+
if (cachedBuiltinIds)
|
|
75
|
+
return cachedBuiltinIds;
|
|
76
|
+
const ids = new Set();
|
|
77
|
+
const bundledDir = findBuiltinSpecialistsDir();
|
|
78
|
+
if (!bundledDir) {
|
|
79
|
+
cachedBuiltinIds = ids;
|
|
80
|
+
return ids;
|
|
81
|
+
}
|
|
82
|
+
try {
|
|
83
|
+
for (const file of fs.readdirSync(bundledDir)) {
|
|
84
|
+
if (file.endsWith('.json'))
|
|
85
|
+
ids.add(file.replace(/\.json$/, ''));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
// fall through with whatever we collected
|
|
90
|
+
}
|
|
91
|
+
cachedBuiltinIds = ids;
|
|
92
|
+
return ids;
|
|
93
|
+
}
|
|
43
94
|
/**
|
|
44
95
|
* Disk-backed store for named specialists (reusable expert profiles).
|
|
45
96
|
*
|
|
@@ -49,6 +100,45 @@ const ID_PATTERN = /^[a-z0-9](?:[a-z0-9-]{0,58}[a-z0-9])?$/;
|
|
|
49
100
|
class SpecialistStore {
|
|
50
101
|
constructor() {
|
|
51
102
|
fs.mkdirSync(paths_js_1.SPECIALISTS_DIR, { recursive: true });
|
|
103
|
+
this.seedBundledSpecialists();
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Copies bundled specialists (shell-wrapper, file-wrapper, web-wrapper,
|
|
107
|
+
* correction-agent, specialist-creator) from the packaged `builtin-specialists`
|
|
108
|
+
* directory into the user's specialists dir on first run. A `.seeded-v1`
|
|
109
|
+
* marker prevents re-seeding on subsequent runs, so users can freely edit or
|
|
110
|
+
* delete the seeded files. Existing files with the same id are never
|
|
111
|
+
* overwritten.
|
|
112
|
+
*/
|
|
113
|
+
seedBundledSpecialists() {
|
|
114
|
+
const markerPath = path.join(paths_js_1.SPECIALISTS_DIR, SEED_MARKER);
|
|
115
|
+
if (fs.existsSync(markerPath))
|
|
116
|
+
return;
|
|
117
|
+
const bundledDir = findBuiltinSpecialistsDir();
|
|
118
|
+
if (!bundledDir)
|
|
119
|
+
return;
|
|
120
|
+
try {
|
|
121
|
+
const files = fs.readdirSync(bundledDir).filter((f) => f.endsWith('.json'));
|
|
122
|
+
for (const file of files) {
|
|
123
|
+
const src = path.join(bundledDir, file);
|
|
124
|
+
const dest = path.join(paths_js_1.SPECIALISTS_DIR, file);
|
|
125
|
+
if (fs.existsSync(dest))
|
|
126
|
+
continue; // never overwrite user-edited copies
|
|
127
|
+
try {
|
|
128
|
+
const raw = fs.readFileSync(src, 'utf-8');
|
|
129
|
+
// Parse once to catch obviously corrupt bundle files before seeding.
|
|
130
|
+
JSON.parse(raw);
|
|
131
|
+
(0, fs_utils_js_1.atomicWriteFileSync)(dest, raw);
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
// skip individual bad files; continue seeding the rest
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
fs.writeFileSync(markerPath, new Date().toISOString(), 'utf-8');
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
// seed is best-effort; never block startup
|
|
141
|
+
}
|
|
52
142
|
}
|
|
53
143
|
/**
|
|
54
144
|
* Validates a specialist ID.
|
|
@@ -105,27 +195,40 @@ class SpecialistStore {
|
|
|
105
195
|
* @throws {Error} If the ID is invalid, reserved, already taken, or the max limit is reached.
|
|
106
196
|
*/
|
|
107
197
|
create(id, name, description, systemPrompt, guidelines = [], provider, model) {
|
|
108
|
-
|
|
198
|
+
return this.createFull({ id, name, description, systemPrompt, guidelines, provider, model });
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Creates a new specialist from a full input object, supporting tool-wrapper
|
|
202
|
+
* fields (kind, targetTools, good/bad examples, structuredOutput).
|
|
203
|
+
* @throws {Error} If the ID is invalid, reserved, already taken, or the max limit is reached.
|
|
204
|
+
*/
|
|
205
|
+
createFull(input) {
|
|
206
|
+
const idError = this.validateId(input.id);
|
|
109
207
|
if (idError)
|
|
110
208
|
throw new Error(idError);
|
|
111
|
-
if (this.exists(id))
|
|
112
|
-
throw new Error(`Specialist "${id}" already exists.`);
|
|
209
|
+
if (this.exists(input.id))
|
|
210
|
+
throw new Error(`Specialist "${input.id}" already exists.`);
|
|
113
211
|
const count = this.list().length;
|
|
114
212
|
if (count >= MAX_SPECIALISTS)
|
|
115
213
|
throw new Error(`Maximum of ${MAX_SPECIALISTS} specialists reached.`);
|
|
116
214
|
const now = new Date().toISOString();
|
|
117
215
|
const specialist = {
|
|
118
|
-
id,
|
|
119
|
-
name,
|
|
120
|
-
description,
|
|
121
|
-
systemPrompt,
|
|
122
|
-
guidelines,
|
|
123
|
-
...(provider !== undefined ? { provider } : {}),
|
|
124
|
-
...(model !== undefined ? { model } : {}),
|
|
216
|
+
id: input.id,
|
|
217
|
+
name: input.name,
|
|
218
|
+
description: input.description,
|
|
219
|
+
systemPrompt: input.systemPrompt,
|
|
220
|
+
guidelines: input.guidelines ?? [],
|
|
221
|
+
...(input.provider !== undefined ? { provider: input.provider } : {}),
|
|
222
|
+
...(input.model !== undefined ? { model: input.model } : {}),
|
|
223
|
+
...(input.kind !== undefined ? { kind: input.kind } : {}),
|
|
224
|
+
...(input.targetTools !== undefined ? { targetTools: input.targetTools } : {}),
|
|
225
|
+
...(input.goodExamples !== undefined ? { goodExamples: input.goodExamples } : {}),
|
|
226
|
+
...(input.badExamples !== undefined ? { badExamples: input.badExamples } : {}),
|
|
227
|
+
...(input.structuredOutput !== undefined ? { structuredOutput: input.structuredOutput } : {}),
|
|
125
228
|
createdAt: now,
|
|
126
229
|
updatedAt: now,
|
|
127
230
|
};
|
|
128
|
-
|
|
231
|
+
(0, fs_utils_js_1.atomicWriteFileSync)(path.join(paths_js_1.SPECIALISTS_DIR, `${input.id}.json`), JSON.stringify(specialist, null, 2));
|
|
129
232
|
return specialist;
|
|
130
233
|
}
|
|
131
234
|
/**
|
|
@@ -163,10 +266,44 @@ class SpecialistStore {
|
|
|
163
266
|
specialist.model = updates.model;
|
|
164
267
|
}
|
|
165
268
|
}
|
|
269
|
+
if (updates.kind !== undefined)
|
|
270
|
+
specialist.kind = updates.kind;
|
|
271
|
+
if (updates.targetTools !== undefined)
|
|
272
|
+
specialist.targetTools = updates.targetTools;
|
|
273
|
+
if (updates.goodExamples !== undefined)
|
|
274
|
+
specialist.goodExamples = updates.goodExamples;
|
|
275
|
+
if (updates.badExamples !== undefined)
|
|
276
|
+
specialist.badExamples = updates.badExamples;
|
|
277
|
+
if (updates.structuredOutput !== undefined)
|
|
278
|
+
specialist.structuredOutput = updates.structuredOutput;
|
|
166
279
|
specialist.updatedAt = new Date().toISOString();
|
|
167
|
-
|
|
280
|
+
(0, fs_utils_js_1.atomicWriteFileSync)(path.join(paths_js_1.SPECIALISTS_DIR, `${id}.json`), JSON.stringify(specialist, null, 2));
|
|
168
281
|
return specialist;
|
|
169
282
|
}
|
|
283
|
+
/**
|
|
284
|
+
* Appends one good and one bad example to a specialist, dropping the oldest
|
|
285
|
+
* entries once the list exceeds {@link MAX_EXAMPLES_PER_LIST}. Used by the
|
|
286
|
+
* correction agent after a validated fix.
|
|
287
|
+
* @returns The updated specialist, or `undefined` if not found.
|
|
288
|
+
*/
|
|
289
|
+
appendExamples(id, good, bad) {
|
|
290
|
+
const specialist = this.get(id);
|
|
291
|
+
if (!specialist)
|
|
292
|
+
return undefined;
|
|
293
|
+
const goodList = [...(specialist.goodExamples ?? [])];
|
|
294
|
+
const badList = [...(specialist.badExamples ?? [])];
|
|
295
|
+
if (good) {
|
|
296
|
+
goodList.push(good);
|
|
297
|
+
while (goodList.length > exports.MAX_EXAMPLES_PER_LIST)
|
|
298
|
+
goodList.shift();
|
|
299
|
+
}
|
|
300
|
+
if (bad) {
|
|
301
|
+
badList.push(bad);
|
|
302
|
+
while (badList.length > exports.MAX_EXAMPLES_PER_LIST)
|
|
303
|
+
badList.shift();
|
|
304
|
+
}
|
|
305
|
+
return this.update(id, { goodExamples: goodList, badExamples: badList });
|
|
306
|
+
}
|
|
170
307
|
/** Removes a specialist by ID. Returns `true` if it existed and was deleted. */
|
|
171
308
|
delete(id) {
|
|
172
309
|
if (!ID_PATTERN.test(id))
|
|
@@ -179,20 +316,15 @@ class SpecialistStore {
|
|
|
179
316
|
}
|
|
180
317
|
/** Returns id + name + description + optional model info for all specialists, for system prompt injection. */
|
|
181
318
|
getSummaries() {
|
|
182
|
-
return this.list().map(({ id, name, description, provider, model }) => ({
|
|
319
|
+
return this.list().map(({ id, name, description, provider, model, kind }) => ({
|
|
183
320
|
id,
|
|
184
321
|
name,
|
|
185
322
|
description,
|
|
186
323
|
...(provider !== undefined ? { provider } : {}),
|
|
187
324
|
...(model !== undefined ? { model } : {}),
|
|
325
|
+
...(kind !== undefined ? { kind } : {}),
|
|
188
326
|
}));
|
|
189
327
|
}
|
|
190
|
-
/** Writes data to a `.tmp` file then renames it into place for crash-safe persistence. */
|
|
191
|
-
atomicWrite(filePath, data) {
|
|
192
|
-
const tmp = filePath + '.tmp';
|
|
193
|
-
fs.writeFileSync(tmp, data, 'utf-8');
|
|
194
|
-
fs.renameSync(tmp, filePath);
|
|
195
|
-
}
|
|
196
328
|
}
|
|
197
329
|
exports.SpecialistStore = SpecialistStore;
|
|
198
330
|
//# sourceMappingURL=specialists.js.map
|
package/dist/specialists.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"specialists.js","sourceRoot":"","sources":["../src/specialists.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"specialists.js","sourceRoot":"","sources":["../src/specialists.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0HA,0DAiBC;AA3ID,4CAA8B;AAC9B,gDAAkC;AAClC,yCAA6C;AAC7C,2DAAqD;AACrD,+CAAoD;AAoDpD,sFAAsF;AACzE,QAAA,qBAAqB,GAAG,EAAE,CAAC;AAkCxC,MAAM,eAAe,GAAG,EAAE,CAAC;AAE3B,MAAM,UAAU,GAAG,wCAAwC,CAAC;AAE5D,+EAA+E;AAC/E,MAAM,WAAW,GAAG,YAAY,CAAC;AAEjC;;;;;GAKG;AACH,SAAS,yBAAyB;IAChC,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,qBAAqB,CAAC,CAAC;IAC9D,IAAI,CAAC;QACH,IAAI,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE;YAAE,OAAO,SAAS,CA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,CAAC,CAAC,EAAE,CAAC;SACxC,CAAC,CAAC,CAAC;IACN,CAAC;CACF;AAnOD,0CAmOC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Scans a string for the first balanced JSON object starting at `start`
|
|
4
|
+
* (which must point at a `{`). Returns the slice containing the object,
|
|
5
|
+
* or `undefined` if no balanced block is found.
|
|
6
|
+
*
|
|
7
|
+
* Respects string literals so braces inside quoted strings don't break depth.
|
|
8
|
+
*/
|
|
9
|
+
export declare function extractJsonBlock(text: string, start: number): string | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* Attempts to parse a JSON object from `text` and validate it with `schema`.
|
|
12
|
+
*
|
|
13
|
+
* Strategy:
|
|
14
|
+
* 1. Try `JSON.parse` on the trimmed input directly.
|
|
15
|
+
* 2. Otherwise scan for each top-level `{` and try bracket-counted extraction.
|
|
16
|
+
*
|
|
17
|
+
* @returns The validated object on success, or `undefined` if nothing parses.
|
|
18
|
+
*/
|
|
19
|
+
export declare function parseStructuredOutput<T>(text: string, schema: z.ZodType<T>): T | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Minimal structured result emitted by tool-wrapper specialists.
|
|
22
|
+
*
|
|
23
|
+
* Intentionally narrow (no confidence scores — models are poor at calibrating
|
|
24
|
+
* those; see issue #106 discussion). `reasoning` is the most valuable field
|
|
25
|
+
* for debugging — it explains why each tool call was made.
|
|
26
|
+
*/
|
|
27
|
+
export interface WrapperResult {
|
|
28
|
+
status: 'ok' | 'error';
|
|
29
|
+
result: unknown;
|
|
30
|
+
error?: string;
|
|
31
|
+
reasoning?: string[];
|
|
32
|
+
}
|
|
33
|
+
export declare const WrapperResultSchema: z.ZodObject<{
|
|
34
|
+
status: z.ZodEnum<["ok", "error"]>;
|
|
35
|
+
result: z.ZodAny;
|
|
36
|
+
error: z.ZodOptional<z.ZodString>;
|
|
37
|
+
reasoning: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
38
|
+
}, "strip", z.ZodTypeAny, {
|
|
39
|
+
status: "error" | "ok";
|
|
40
|
+
reasoning?: string[] | undefined;
|
|
41
|
+
error?: string | undefined;
|
|
42
|
+
result?: any;
|
|
43
|
+
}, {
|
|
44
|
+
status: "error" | "ok";
|
|
45
|
+
reasoning?: string[] | undefined;
|
|
46
|
+
error?: string | undefined;
|
|
47
|
+
result?: any;
|
|
48
|
+
}>;
|
|
49
|
+
/**
|
|
50
|
+
* Wraps raw specialist text output into a {@link WrapperResult}. Missing or
|
|
51
|
+
* malformed JSON becomes a structured error (not silent success).
|
|
52
|
+
*/
|
|
53
|
+
export declare function wrapWrapperResult(text: string): WrapperResult;
|
|
54
|
+
/**
|
|
55
|
+
* Rules appended to a tool-wrapper specialist's system prompt. Instructs the
|
|
56
|
+
* child to emit a JSON object as its final message.
|
|
57
|
+
*/
|
|
58
|
+
export declare const STRUCTURED_OUTPUT_RULES = "\n\n## Output Format (STRICT)\n\nYour FINAL message MUST be a single valid JSON object with this shape and nothing else \u2014 no prose before or after, no markdown code fences:\n\n{\n \"status\": \"ok\" | \"error\",\n \"result\": <any valid JSON value representing the outcome>,\n \"error\": \"<short error message, only when status is 'error'>\",\n \"reasoning\": [\"<short rationale for each significant decision or tool call>\"]\n}\n\nRules:\n- Emit the JSON only once, as your last message.\n- `reasoning` is an array of short strings. One entry per significant tool call explaining WHY you chose it (not what it returned).\n- Never include confidence scores \u2014 the downstream pipeline ignores them.\n- If a tool call fails irrecoverably, set `status` to \"error\", put the cause in `error`, and still include your reasoning.";
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.STRUCTURED_OUTPUT_RULES = exports.WrapperResultSchema = void 0;
|
|
4
|
+
exports.extractJsonBlock = extractJsonBlock;
|
|
5
|
+
exports.parseStructuredOutput = parseStructuredOutput;
|
|
6
|
+
exports.wrapWrapperResult = wrapWrapperResult;
|
|
7
|
+
const zod_1 = require("zod");
|
|
8
|
+
/**
|
|
9
|
+
* Scans a string for the first balanced JSON object starting at `start`
|
|
10
|
+
* (which must point at a `{`). Returns the slice containing the object,
|
|
11
|
+
* or `undefined` if no balanced block is found.
|
|
12
|
+
*
|
|
13
|
+
* Respects string literals so braces inside quoted strings don't break depth.
|
|
14
|
+
*/
|
|
15
|
+
function extractJsonBlock(text, start) {
|
|
16
|
+
if (text[start] !== '{')
|
|
17
|
+
return undefined;
|
|
18
|
+
let depth = 0;
|
|
19
|
+
let inString = false;
|
|
20
|
+
let escaped = false;
|
|
21
|
+
for (let i = start; i < text.length; i++) {
|
|
22
|
+
const ch = text[i];
|
|
23
|
+
if (escaped) {
|
|
24
|
+
escaped = false;
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if (ch === '\\' && inString) {
|
|
28
|
+
escaped = true;
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (ch === '"') {
|
|
32
|
+
inString = !inString;
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (inString)
|
|
36
|
+
continue;
|
|
37
|
+
if (ch === '{')
|
|
38
|
+
depth++;
|
|
39
|
+
else if (ch === '}') {
|
|
40
|
+
depth--;
|
|
41
|
+
if (depth === 0)
|
|
42
|
+
return text.slice(start, i + 1);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Attempts to parse a JSON object from `text` and validate it with `schema`.
|
|
49
|
+
*
|
|
50
|
+
* Strategy:
|
|
51
|
+
* 1. Try `JSON.parse` on the trimmed input directly.
|
|
52
|
+
* 2. Otherwise scan for each top-level `{` and try bracket-counted extraction.
|
|
53
|
+
*
|
|
54
|
+
* @returns The validated object on success, or `undefined` if nothing parses.
|
|
55
|
+
*/
|
|
56
|
+
function parseStructuredOutput(text, schema) {
|
|
57
|
+
const trimmed = text.trim();
|
|
58
|
+
// 1. Direct parse
|
|
59
|
+
try {
|
|
60
|
+
const parsed = JSON.parse(trimmed);
|
|
61
|
+
const result = schema.safeParse(parsed);
|
|
62
|
+
if (result.success)
|
|
63
|
+
return result.data;
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
// fall through
|
|
67
|
+
}
|
|
68
|
+
// 2. Scan forward for balanced blocks
|
|
69
|
+
for (let i = 0; i < trimmed.length; i++) {
|
|
70
|
+
if (trimmed[i] === '{') {
|
|
71
|
+
const block = extractJsonBlock(trimmed, i);
|
|
72
|
+
if (block) {
|
|
73
|
+
try {
|
|
74
|
+
const parsed = JSON.parse(block);
|
|
75
|
+
const result = schema.safeParse(parsed);
|
|
76
|
+
if (result.success)
|
|
77
|
+
return result.data;
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
// try next
|
|
81
|
+
}
|
|
82
|
+
i += block.length - 1;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
exports.WrapperResultSchema = zod_1.z.object({
|
|
89
|
+
status: zod_1.z.enum(['ok', 'error']),
|
|
90
|
+
result: zod_1.z.any(),
|
|
91
|
+
error: zod_1.z.string().optional(),
|
|
92
|
+
reasoning: zod_1.z.array(zod_1.z.string()).optional(),
|
|
93
|
+
});
|
|
94
|
+
/**
|
|
95
|
+
* Wraps raw specialist text output into a {@link WrapperResult}. Missing or
|
|
96
|
+
* malformed JSON becomes a structured error (not silent success).
|
|
97
|
+
*/
|
|
98
|
+
function wrapWrapperResult(text) {
|
|
99
|
+
const parsed = parseStructuredOutput(text, exports.WrapperResultSchema);
|
|
100
|
+
if (parsed) {
|
|
101
|
+
const { status, result, error, reasoning } = parsed;
|
|
102
|
+
const out = { status, result };
|
|
103
|
+
if (error !== undefined)
|
|
104
|
+
out.error = error;
|
|
105
|
+
if (reasoning !== undefined)
|
|
106
|
+
out.reasoning = reasoning;
|
|
107
|
+
return out;
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
status: 'error',
|
|
111
|
+
result: 'Specialist did not produce valid structured output',
|
|
112
|
+
error: 'parse_failed',
|
|
113
|
+
reasoning: [text.trim().slice(0, 500)],
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Rules appended to a tool-wrapper specialist's system prompt. Instructs the
|
|
118
|
+
* child to emit a JSON object as its final message.
|
|
119
|
+
*/
|
|
120
|
+
exports.STRUCTURED_OUTPUT_RULES = `
|
|
121
|
+
|
|
122
|
+
## Output Format (STRICT)
|
|
123
|
+
|
|
124
|
+
Your FINAL message MUST be a single valid JSON object with this shape and nothing else — no prose before or after, no markdown code fences:
|
|
125
|
+
|
|
126
|
+
{
|
|
127
|
+
"status": "ok" | "error",
|
|
128
|
+
"result": <any valid JSON value representing the outcome>,
|
|
129
|
+
"error": "<short error message, only when status is 'error'>",
|
|
130
|
+
"reasoning": ["<short rationale for each significant decision or tool call>"]
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
Rules:
|
|
134
|
+
- Emit the JSON only once, as your last message.
|
|
135
|
+
- \`reasoning\` is an array of short strings. One entry per significant tool call explaining WHY you chose it (not what it returned).
|
|
136
|
+
- Never include confidence scores — the downstream pipeline ignores them.
|
|
137
|
+
- If a tool call fails irrecoverably, set \`status\` to "error", put the cause in \`error\`, and still include your reasoning.`;
|
|
138
|
+
//# sourceMappingURL=structured-output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"structured-output.js","sourceRoot":"","sources":["../src/structured-output.ts"],"names":[],"mappings":";;;AASA,4CA2BC;AAWD,sDA8BC;AA2BD,8CAeC;AAvHD,6BAAwB;AAExB;;;;;;GAMG;AACH,SAAgB,gBAAgB,CAAC,IAAY,EAAE,KAAa;IAC1D,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG;QAAE,OAAO,SAAS,CAAC;IAC1C,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,Q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AAG,MAAM,CAAC;QACpD,MAAM,GAAG,GAAkB,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;QAC9C,IAAI,KAAK,KAAK,SAAS;YAAE,GAAG,CAAC,KAAK,GAAG,KAAK,CAAC;QAC3C,IAAI,SAAS,KAAK,SAAS;YAAE,GAAG,CAAC,SAAS,GAAG,SAAS,CAAC;QACvD,OAAO,GAAG,CAAC;IACb,CAAC;IACD,OAAO;QACL,MAAM,EAAE,OAAO;QACf,MAAM,EAAE,oDAAoD;QAC5D,KAAK,EAAE,cAAc;QACrB,SAAS,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;KACvC,CAAC;AACJ,CAAC;AAED;;;GAGG;AACU,QAAA,uBAAuB,GAAG;;;;;;;;;;;;;;;;;+HAiBwF,CAAC"}
|
package/dist/theme.d.ts
CHANGED
|
@@ -25,6 +25,8 @@ export interface Theme {
|
|
|
25
25
|
success: ColorFn;
|
|
26
26
|
/** Dimmed color for de-emphasized content like conversation replays. */
|
|
27
27
|
dim: ColorFn;
|
|
28
|
+
/** Dimmed italic variant, used for secondary blocks like the `think` tool output. */
|
|
29
|
+
dimItalic: ColorFn;
|
|
28
30
|
/** Color for warning messages. */
|
|
29
31
|
warning: ColorFn;
|
|
30
32
|
/** Rotating palette of colors assigned to sub-agent prefixes. */
|
package/dist/theme.js
CHANGED
|
@@ -27,12 +27,13 @@ exports.THEMES = {
|
|
|
27
27
|
error: chalk_1.default.red,
|
|
28
28
|
success: chalk_1.default.green,
|
|
29
29
|
dim: chalk_1.default.dim,
|
|
30
|
+
dimItalic: chalk_1.default.dim.italic,
|
|
30
31
|
warning: chalk_1.default.yellow,
|
|
31
32
|
prefixColors: [chalk_1.default.magenta, chalk_1.default.blue, chalk_1.default.green, chalk_1.default.yellow],
|
|
32
33
|
ansi: {
|
|
33
34
|
prompt: '\x1b[38;2;249;115;22m',
|
|
34
|
-
hintCmd: '\x1b[
|
|
35
|
-
hintDesc: '\x1b[
|
|
35
|
+
hintCmd: '\x1b[1;38;2;249;115;22m',
|
|
36
|
+
hintDesc: '\x1b[22;38;2;115;115;115m',
|
|
36
37
|
warning: '\x1b[33m',
|
|
37
38
|
reset: '\x1b[0m',
|
|
38
39
|
},
|
|
@@ -48,6 +49,7 @@ exports.THEMES = {
|
|
|
48
49
|
error: chalk_1.default.hex('#f87171'),
|
|
49
50
|
success: chalk_1.default.hex('#34d399'),
|
|
50
51
|
dim: chalk_1.default.dim,
|
|
52
|
+
dimItalic: chalk_1.default.dim.italic,
|
|
51
53
|
warning: chalk_1.default.hex('#fbbf24'),
|
|
52
54
|
prefixColors: [
|
|
53
55
|
chalk_1.default.hex('#38bdf8'),
|
|
@@ -57,8 +59,8 @@ exports.THEMES = {
|
|
|
57
59
|
],
|
|
58
60
|
ansi: {
|
|
59
61
|
prompt: '\x1b[38;2;6;182;212m',
|
|
60
|
-
hintCmd: '\x1b[38;2;
|
|
61
|
-
hintDesc: '\x1b[38;2;
|
|
62
|
+
hintCmd: '\x1b[1;38;2;6;182;212m',
|
|
63
|
+
hintDesc: '\x1b[22;38;2;115;125;140m',
|
|
62
64
|
warning: '\x1b[38;2;251;191;36m',
|
|
63
65
|
reset: '\x1b[0m',
|
|
64
66
|
},
|
|
@@ -74,6 +76,7 @@ exports.THEMES = {
|
|
|
74
76
|
error: chalk_1.default.hex('#ef4444'),
|
|
75
77
|
success: chalk_1.default.hex('#4ade80'),
|
|
76
78
|
dim: chalk_1.default.dim,
|
|
79
|
+
dimItalic: chalk_1.default.dim.italic,
|
|
77
80
|
warning: chalk_1.default.hex('#facc15'),
|
|
78
81
|
prefixColors: [
|
|
79
82
|
chalk_1.default.hex('#4ade80'),
|
|
@@ -83,8 +86,8 @@ exports.THEMES = {
|
|
|
83
86
|
],
|
|
84
87
|
ansi: {
|
|
85
88
|
prompt: '\x1b[38;2;34;197;94m',
|
|
86
|
-
hintCmd: '\x1b[38;2;
|
|
87
|
-
hintDesc: '\x1b[38;2;
|
|
89
|
+
hintCmd: '\x1b[1;38;2;34;197;94m',
|
|
90
|
+
hintDesc: '\x1b[22;38;2;115;115;115m',
|
|
88
91
|
warning: '\x1b[38;2;250;204;21m',
|
|
89
92
|
reset: '\x1b[0m',
|
|
90
93
|
},
|
|
@@ -100,6 +103,7 @@ exports.THEMES = {
|
|
|
100
103
|
error: chalk_1.default.hex('#fb7185'),
|
|
101
104
|
success: chalk_1.default.hex('#34d399'),
|
|
102
105
|
dim: chalk_1.default.dim,
|
|
106
|
+
dimItalic: chalk_1.default.dim.italic,
|
|
103
107
|
warning: chalk_1.default.hex('#fde68a'),
|
|
104
108
|
prefixColors: [
|
|
105
109
|
chalk_1.default.hex('#f472b6'),
|
|
@@ -109,8 +113,8 @@ exports.THEMES = {
|
|
|
109
113
|
],
|
|
110
114
|
ansi: {
|
|
111
115
|
prompt: '\x1b[38;2;192;132;252m',
|
|
112
|
-
hintCmd: '\x1b[38;2;
|
|
113
|
-
hintDesc: '\x1b[38;2;
|
|
116
|
+
hintCmd: '\x1b[1;38;2;192;132;252m',
|
|
117
|
+
hintDesc: '\x1b[22;38;2;130;130;150m',
|
|
114
118
|
warning: '\x1b[38;2;253;230;138m',
|
|
115
119
|
reset: '\x1b[0m',
|
|
116
120
|
},
|
|
@@ -126,6 +130,7 @@ exports.THEMES = {
|
|
|
126
130
|
error: chalk_1.default.bold.redBright,
|
|
127
131
|
success: chalk_1.default.bold.greenBright,
|
|
128
132
|
dim: chalk_1.default.white,
|
|
133
|
+
dimItalic: chalk_1.default.white.italic,
|
|
129
134
|
warning: chalk_1.default.bold.yellowBright,
|
|
130
135
|
prefixColors: [
|
|
131
136
|
chalk_1.default.bold.magentaBright,
|
|
@@ -135,8 +140,8 @@ exports.THEMES = {
|
|
|
135
140
|
],
|
|
136
141
|
ansi: {
|
|
137
142
|
prompt: '\x1b[1;97m',
|
|
138
|
-
hintCmd: '\x1b[
|
|
139
|
-
hintDesc: '\x1b[
|
|
143
|
+
hintCmd: '\x1b[1;93m',
|
|
144
|
+
hintDesc: '\x1b[22;37m',
|
|
140
145
|
warning: '\x1b[1;93m',
|
|
141
146
|
reset: '\x1b[0m',
|
|
142
147
|
},
|
|
@@ -152,6 +157,7 @@ exports.THEMES = {
|
|
|
152
157
|
error: chalk_1.default.hex('#DC267F'),
|
|
153
158
|
success: chalk_1.default.hex('#648FFF'),
|
|
154
159
|
dim: chalk_1.default.dim,
|
|
160
|
+
dimItalic: chalk_1.default.dim.italic,
|
|
155
161
|
warning: chalk_1.default.hex('#FFB000'),
|
|
156
162
|
prefixColors: [
|
|
157
163
|
chalk_1.default.hex('#785EF0'),
|
|
@@ -161,8 +167,8 @@ exports.THEMES = {
|
|
|
161
167
|
],
|
|
162
168
|
ansi: {
|
|
163
169
|
prompt: '\x1b[38;2;100;143;255m',
|
|
164
|
-
hintCmd: '\x1b[38;2;
|
|
165
|
-
hintDesc: '\x1b[38;2;
|
|
170
|
+
hintCmd: '\x1b[1;38;2;100;143;255m',
|
|
171
|
+
hintDesc: '\x1b[22;38;2;130;130;130m',
|
|
166
172
|
warning: '\x1b[38;2;255;176;0m',
|
|
167
173
|
reset: '\x1b[0m',
|
|
168
174
|
},
|
package/dist/theme.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme.js","sourceRoot":"","sources":["../src/theme.ts"],"names":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"theme.js","sourceRoot":"","sources":["../src/theme.ts"],"names":[],"mappings":";;;;;;AAuOA,4BAEC;AAQD,4BAMC;AAGD,oCAEC;AAGD,8CAEC;AAjQD,kDAA0B;AAkD1B;;;;;GAKG;AACU,QAAA,MAAM,GAA0B;IAC3C,8CAA8C;IAC9C,OAAO,EAAE;QACP,IAAI,EAAE,SAAS;QACf,MAAM,EAAE,eAAK,CAAC,GAAG,CAAC,SAAS,CAAC;QAC5B,UAAU,EAAE,eAAK,CAAC,IAAI,CAAC,GAAG,CAAC,SAA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AAC,SAAS,CAAC;YACpB,eAAK,CAAC,GAAG,CAAC,SAAS,CAAC;YACpB,eAAK,CAAC,GAAG,CAAC,SAAS,CAAC;SACrB;QACD,IAAI,EAAE;YACJ,MAAM,EAAE,wBAAwB;YAChC,OAAO,EAAE,0BAA0B;YACnC,QAAQ,EAAE,2BAA2B;YACrC,OAAO,EAAE,sBAAsB;YAC/B,KAAK,EAAE,SAAS;SACjB;KACF;CACF,CAAC;AAEF,4DAA4D;AAC/C,QAAA,aAAa,GAAG,SAAS,CAAC;AAEvC,IAAI,cAAc,GAAW,qBAAa,CAAC;AAC3C,IAAI,WAAW,GAAU,cAAM,CAAC,qBAAa,CAAC,CAAC;AAE/C;;;GAGG;AACH,SAAgB,QAAQ;IACtB,OAAO,WAAW,CAAC;AACrB,CAAC;AAED;;;;;GAKG;AACH,SAAgB,QAAQ,CAAC,GAAW;IAClC,MAAM,KAAK,GAAG,cAAM,CAAC,GAAG,CAAC,CAAC;IAC1B,IAAI,CAAC,KAAK;QAAE,OAAO,KAAK,CAAC;IACzB,cAAc,GAAG,GAAG,CAAC;IACrB,WAAW,GAAG,KAAK,CAAC;IACpB,OAAO,IAAI,CAAC;AACd,CAAC;AAED,0DAA0D;AAC1D,SAAgB,YAAY;IAC1B,OAAO,MAAM,CAAC,IAAI,CAAC,cAAM,CAAC,CAAC;AAC7B,CAAC;AAED,6EAA6E;AAC7E,SAAgB,iBAAiB;IAC/B,OAAO,cAAc,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type ToolCallRepairFunction, type ToolSet } from 'ai';
|
|
2
|
+
import type { BernardConfig } from './config.js';
|
|
3
|
+
/** Identifies which generateText site produced the failed tool call. */
|
|
4
|
+
export type RepairLabel = 'main' | 'specialist' | 'subagent' | 'tool-wrapper' | 'cron';
|
|
5
|
+
export interface MakeRepairHookOpts {
|
|
6
|
+
config: BernardConfig;
|
|
7
|
+
/** Provider to use for the repair call. Defaults to config.provider. */
|
|
8
|
+
provider?: string;
|
|
9
|
+
/** Model to use for the repair call. Defaults to config.model. */
|
|
10
|
+
model?: string;
|
|
11
|
+
label: RepairLabel;
|
|
12
|
+
/** Optional abort signal forwarded to the repair generateText call. */
|
|
13
|
+
abortSignal?: AbortSignal;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Produces an `experimental_repairToolCall` hook for `generateText`. When the
|
|
17
|
+
* AI SDK fails to parse a model's tool-call arguments (or the model targets a
|
|
18
|
+
* nonexistent tool), the hook runs ONE focused generation asking the model to
|
|
19
|
+
* re-emit a valid tool call. Returns the corrected call, or `null` to let the
|
|
20
|
+
* SDK throw.
|
|
21
|
+
*
|
|
22
|
+
* The repair attempt is bounded to a single retry per failed tool call — no
|
|
23
|
+
* looping, no escalation. Failures are logged to the debug stream.
|
|
24
|
+
*
|
|
25
|
+
* Special-cases JSON truncation (the model packed too much content into a
|
|
26
|
+
* single string arg) by hinting at `file_write` + `shell` as the safe pattern
|
|
27
|
+
* for large payloads.
|
|
28
|
+
*/
|
|
29
|
+
export declare function makeRepairHook<TOOLS extends ToolSet>(opts: MakeRepairHookOpts): ToolCallRepairFunction<TOOLS>;
|