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
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatExamples = formatExamples;
|
|
4
|
+
exports.buildChildTools = buildChildTools;
|
|
5
|
+
exports.captureLastToolCall = captureLastToolCall;
|
|
6
|
+
exports.captureToolCalls = captureToolCalls;
|
|
7
|
+
exports.dispatchToolWrapper = dispatchToolWrapper;
|
|
8
|
+
exports.renderWrapperParentView = renderWrapperParentView;
|
|
9
|
+
exports.createToolWrapperRunTool = createToolWrapperRunTool;
|
|
10
|
+
const ai_1 = require("ai");
|
|
11
|
+
const zod_1 = require("zod");
|
|
12
|
+
const index_js_1 = require("../providers/index.js");
|
|
13
|
+
const index_js_2 = require("./index.js");
|
|
14
|
+
const subagent_js_1 = require("./subagent.js");
|
|
15
|
+
const task_js_1 = require("./task.js");
|
|
16
|
+
const specialist_run_js_1 = require("./specialist-run.js");
|
|
17
|
+
const task_js_2 = require("./task.js");
|
|
18
|
+
const output_js_1 = require("../output.js");
|
|
19
|
+
const logger_js_1 = require("../logger.js");
|
|
20
|
+
const memory_context_js_1 = require("../memory-context.js");
|
|
21
|
+
const agent_pool_js_1 = require("./agent-pool.js");
|
|
22
|
+
const config_js_1 = require("../config.js");
|
|
23
|
+
const os_info_js_1 = require("../os-info.js");
|
|
24
|
+
const structured_output_js_1 = require("../structured-output.js");
|
|
25
|
+
const reasoning_log_js_1 = require("../reasoning-log.js");
|
|
26
|
+
const result_cap_js_1 = require("./result-cap.js");
|
|
27
|
+
/** Fraction of config.maxSteps allocated to a tool-wrapper run. Mirrors task/specialist ratios. */
|
|
28
|
+
const TOOL_WRAPPER_STEP_RATIO = 0.5;
|
|
29
|
+
/** Formats good/bad examples as a markdown block appended to the child's system prompt. */
|
|
30
|
+
function formatExamples(specialist) {
|
|
31
|
+
const parts = [];
|
|
32
|
+
const good = specialist.goodExamples ?? [];
|
|
33
|
+
const bad = specialist.badExamples ?? [];
|
|
34
|
+
if (good.length > 0) {
|
|
35
|
+
parts.push('\n\n## Good Examples (follow these patterns)');
|
|
36
|
+
for (const ex of good) {
|
|
37
|
+
parts.push(`\n- Input: ${ex.input}\n Call: ${ex.call}`);
|
|
38
|
+
if (ex.note)
|
|
39
|
+
parts.push(`\n Note: ${ex.note}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (bad.length > 0) {
|
|
43
|
+
parts.push('\n\n## Bad Examples (AVOID these patterns)');
|
|
44
|
+
for (const ex of bad) {
|
|
45
|
+
parts.push(`\n- Input: ${ex.input}\n Bad call: ${ex.call}\n Error observed: ${ex.error}\n Correct approach: ${ex.fix}`);
|
|
46
|
+
if (ex.note)
|
|
47
|
+
parts.push(`\n Note: ${ex.note}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return parts.join('');
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Builds the full tool registry a tool-wrapper specialist could possibly
|
|
54
|
+
* reach, then intersects with `targetTools` when set. Persona/tool-wrapper
|
|
55
|
+
* specialists get strict isolation; meta specialists typically pass
|
|
56
|
+
* `targetTools` that include dispatch tools (specialist, tool_wrapper_run)
|
|
57
|
+
* for recursive orchestration.
|
|
58
|
+
*/
|
|
59
|
+
function buildChildTools(specialist, fullRegistry) {
|
|
60
|
+
const targets = specialist.targetTools;
|
|
61
|
+
if (!targets || targets.length === 0) {
|
|
62
|
+
// No filter specified — expose everything. Common for meta specialists.
|
|
63
|
+
return fullRegistry;
|
|
64
|
+
}
|
|
65
|
+
const filtered = {};
|
|
66
|
+
for (const name of targets) {
|
|
67
|
+
if (fullRegistry[name])
|
|
68
|
+
filtered[name] = fullRegistry[name];
|
|
69
|
+
}
|
|
70
|
+
return filtered;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Captures the last tool call observed in a `generateText` result.
|
|
74
|
+
* Used to populate `attemptedCall` on correction candidates.
|
|
75
|
+
*/
|
|
76
|
+
function captureLastToolCall(steps) {
|
|
77
|
+
if (!steps || steps.length === 0)
|
|
78
|
+
return '(no tool call)';
|
|
79
|
+
for (let i = steps.length - 1; i >= 0; i--) {
|
|
80
|
+
const step = steps[i];
|
|
81
|
+
const calls = step?.toolCalls ?? [];
|
|
82
|
+
if (calls.length > 0) {
|
|
83
|
+
const tc = calls[calls.length - 1];
|
|
84
|
+
try {
|
|
85
|
+
return `${tc.toolName} ${JSON.stringify(tc.args).slice(0, 600)}`;
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
return `${tc.toolName} (unserializable args)`;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return '(no tool call)';
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Builds a compact record of tool calls for the reasoning log.
|
|
96
|
+
*/
|
|
97
|
+
function captureToolCalls(steps) {
|
|
98
|
+
if (!steps)
|
|
99
|
+
return [];
|
|
100
|
+
const out = [];
|
|
101
|
+
for (const step of steps) {
|
|
102
|
+
const calls = step?.toolCalls ?? [];
|
|
103
|
+
const results = step?.toolResults ?? [];
|
|
104
|
+
for (let i = 0; i < calls.length; i++) {
|
|
105
|
+
const tc = calls[i];
|
|
106
|
+
const tr = results[i];
|
|
107
|
+
const resultText = tr?.result === undefined ? '' : String(tr.result);
|
|
108
|
+
out.push({
|
|
109
|
+
tool: tc.toolName,
|
|
110
|
+
args: tc.args,
|
|
111
|
+
resultPreview: resultText.slice(0, 300),
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return out;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Core dispatch for tool-wrapper specialists. Used by both the explicit
|
|
119
|
+
* `tool_wrapper_run` tool and the shim layer that routes raw tool calls
|
|
120
|
+
* (e.g. `shell`) through their corresponding wrapper specialist.
|
|
121
|
+
*
|
|
122
|
+
* Returns a {@link WrapperResult} so callers can shape the parent-facing
|
|
123
|
+
* response however they like (JSON envelope, raw result, error string).
|
|
124
|
+
* Pool acquisition, reasoning logging, and correction-candidate enqueue
|
|
125
|
+
* happen inside.
|
|
126
|
+
*/
|
|
127
|
+
async function dispatchToolWrapper(args, deps) {
|
|
128
|
+
const { specialistId, input, context, provider, model, abortSignal, runLabel } = args;
|
|
129
|
+
const { config, options, memoryStore, specialistStore, correctionStore, mcpTools, ragStore, routineStore, candidateStore, } = deps;
|
|
130
|
+
const specialist = specialistStore.get(specialistId);
|
|
131
|
+
if (!specialist) {
|
|
132
|
+
return {
|
|
133
|
+
status: 'error',
|
|
134
|
+
result: `No specialist found with id "${specialistId}".`,
|
|
135
|
+
error: 'not_found',
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
const kind = specialist.kind ?? 'persona';
|
|
139
|
+
if (kind === 'persona') {
|
|
140
|
+
return {
|
|
141
|
+
status: 'error',
|
|
142
|
+
result: `Specialist "${specialistId}" is a persona specialist. Use specialist_run instead, or update its kind to "tool-wrapper".`,
|
|
143
|
+
error: 'wrong_kind',
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
const resolution = (0, config_js_1.resolveProviderAndModel)({
|
|
147
|
+
provider,
|
|
148
|
+
model,
|
|
149
|
+
specialistProvider: specialist.provider,
|
|
150
|
+
specialistModel: specialist.model,
|
|
151
|
+
config,
|
|
152
|
+
});
|
|
153
|
+
if (!resolution.ok) {
|
|
154
|
+
const hint = resolution.isCustom
|
|
155
|
+
? `Run: bernard add-key ${resolution.provider} <key>`
|
|
156
|
+
: `Set ${resolution.envVar} or run: bernard add-key ${resolution.provider} <key>`;
|
|
157
|
+
return {
|
|
158
|
+
status: 'error',
|
|
159
|
+
result: `No API key for provider "${resolution.provider}". ${hint}.`,
|
|
160
|
+
error: 'no_api_key',
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
const { provider: resolvedProvider, model: resolvedModel } = resolution;
|
|
164
|
+
const slot = (0, agent_pool_js_1.acquireSlot)();
|
|
165
|
+
if (!slot) {
|
|
166
|
+
return {
|
|
167
|
+
status: 'error',
|
|
168
|
+
result: `Maximum concurrent agents (${agent_pool_js_1.MAX_CONCURRENT_AGENTS}) reached.`,
|
|
169
|
+
error: 'pool_exhausted',
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
const id = slot.id;
|
|
173
|
+
const prefix = `wrap:${id}`;
|
|
174
|
+
const label = runLabel ?? `[${kind}] ${specialist.name}`;
|
|
175
|
+
(0, output_js_1.printSpecialistStart)(id, label, input);
|
|
176
|
+
try {
|
|
177
|
+
const baseTools = (0, index_js_2.createTools)(options, memoryStore, mcpTools, routineStore, specialistStore, candidateStore, config);
|
|
178
|
+
const fullRegistry = {
|
|
179
|
+
...baseTools,
|
|
180
|
+
agent: (0, subagent_js_1.createSubAgentTool)(config, options, memoryStore, mcpTools, ragStore),
|
|
181
|
+
task: (0, task_js_1.createTaskTool)(config, options, memoryStore, mcpTools, ragStore, routineStore),
|
|
182
|
+
specialist_run: (0, specialist_run_js_1.createSpecialistRunTool)(config, options, memoryStore, specialistStore, mcpTools, ragStore),
|
|
183
|
+
tool_wrapper_run: createToolWrapperRunTool(config, options, memoryStore, specialistStore, correctionStore, mcpTools, ragStore, routineStore, candidateStore),
|
|
184
|
+
};
|
|
185
|
+
const childTools = buildChildTools(specialist, fullRegistry);
|
|
186
|
+
let systemPrompt = specialist.systemPrompt;
|
|
187
|
+
if (specialist.guidelines.length > 0) {
|
|
188
|
+
systemPrompt += '\n\nGuidelines:\n' + specialist.guidelines.map((g) => `- ${g}`).join('\n');
|
|
189
|
+
}
|
|
190
|
+
systemPrompt += '\n\n' + (0, os_info_js_1.osPromptBlock)();
|
|
191
|
+
systemPrompt += formatExamples(specialist);
|
|
192
|
+
// Default to structured output for tool-wrapper specialists unless explicitly disabled.
|
|
193
|
+
const wantStructured = specialist.structuredOutput ?? kind === 'tool-wrapper';
|
|
194
|
+
if (wantStructured) {
|
|
195
|
+
systemPrompt += structured_output_js_1.STRUCTURED_OUTPUT_RULES;
|
|
196
|
+
}
|
|
197
|
+
systemPrompt += (0, memory_context_js_1.buildMemoryContext)({
|
|
198
|
+
memoryStore,
|
|
199
|
+
ragResults: undefined,
|
|
200
|
+
includeScratch: true,
|
|
201
|
+
});
|
|
202
|
+
if (Object.keys(childTools).length > 0) {
|
|
203
|
+
systemPrompt += `\n\nAvailable tools for this run: ${Object.keys(childTools).join(', ')}`;
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
systemPrompt +=
|
|
207
|
+
'\n\nNo tools are available for this run. Produce the structured output based on reasoning alone.';
|
|
208
|
+
}
|
|
209
|
+
let userMessage = `Request: ${input}`;
|
|
210
|
+
if (context)
|
|
211
|
+
userMessage += `\n\nContext: ${context}`;
|
|
212
|
+
const maxSteps = Math.max(2, Math.ceil(config.maxSteps * TOOL_WRAPPER_STEP_RATIO));
|
|
213
|
+
const onStepFinish = ({ text, toolCalls, toolResults }) => {
|
|
214
|
+
for (const tc of toolCalls ?? []) {
|
|
215
|
+
(0, output_js_1.printToolCall)(tc.toolName, tc.args, prefix);
|
|
216
|
+
}
|
|
217
|
+
for (const tr of toolResults ?? []) {
|
|
218
|
+
(0, output_js_1.printToolResult)(tr.toolName, tr.result, prefix);
|
|
219
|
+
}
|
|
220
|
+
if (text)
|
|
221
|
+
(0, output_js_1.printAssistantText)(text, prefix);
|
|
222
|
+
};
|
|
223
|
+
// Lazy import to avoid a top-level cycle (tool-call-repair → providers).
|
|
224
|
+
const { makeRepairHook } = await import('../tool-call-repair.js');
|
|
225
|
+
const repairHook = makeRepairHook({
|
|
226
|
+
config,
|
|
227
|
+
provider: resolvedProvider,
|
|
228
|
+
model: resolvedModel,
|
|
229
|
+
label: 'tool-wrapper',
|
|
230
|
+
abortSignal,
|
|
231
|
+
});
|
|
232
|
+
const result = await (0, ai_1.generateText)({
|
|
233
|
+
model: (0, index_js_1.getModelForConfig)(config, resolvedProvider, resolvedModel),
|
|
234
|
+
providerOptions: (0, index_js_1.getProviderOptionsForConfig)(config, resolvedProvider),
|
|
235
|
+
tools: childTools,
|
|
236
|
+
maxSteps,
|
|
237
|
+
maxTokens: config.maxTokens,
|
|
238
|
+
system: systemPrompt,
|
|
239
|
+
messages: [{ role: 'user', content: userMessage }],
|
|
240
|
+
abortSignal,
|
|
241
|
+
experimental_prepareStep: wantStructured ? (0, task_js_2.makeLastStepTextOnly)(maxSteps) : undefined,
|
|
242
|
+
experimental_repairToolCall: repairHook,
|
|
243
|
+
onStepFinish,
|
|
244
|
+
});
|
|
245
|
+
(0, output_js_1.printSpecialistEnd)(id);
|
|
246
|
+
const wrapped = wantStructured
|
|
247
|
+
? (0, structured_output_js_1.wrapWrapperResult)(result.text)
|
|
248
|
+
: { status: 'ok', result: result.text };
|
|
249
|
+
(0, reasoning_log_js_1.appendReasoningLog)({
|
|
250
|
+
ts: new Date().toISOString(),
|
|
251
|
+
specialistId,
|
|
252
|
+
input,
|
|
253
|
+
toolCalls: captureToolCalls(result.steps),
|
|
254
|
+
finalOutput: wrapped.result,
|
|
255
|
+
status: wrapped.status === 'ok'
|
|
256
|
+
? 'ok'
|
|
257
|
+
: wrapped.error === 'parse_failed'
|
|
258
|
+
? 'parse_failed'
|
|
259
|
+
: 'error',
|
|
260
|
+
...(wrapped.error !== undefined ? { error: wrapped.error } : {}),
|
|
261
|
+
...(wrapped.reasoning !== undefined ? { reasoning: wrapped.reasoning } : {}),
|
|
262
|
+
});
|
|
263
|
+
if (wrapped.status === 'error' && kind === 'tool-wrapper') {
|
|
264
|
+
try {
|
|
265
|
+
correctionStore.enqueue({
|
|
266
|
+
specialistId,
|
|
267
|
+
input,
|
|
268
|
+
attemptedCall: captureLastToolCall(result.steps),
|
|
269
|
+
error: wrapped.error ?? String(wrapped.result),
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
catch (err) {
|
|
273
|
+
(0, logger_js_1.debugLog)('tool-wrapper:correction-enqueue:error', err instanceof Error ? err.message : String(err));
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return wrapped;
|
|
277
|
+
}
|
|
278
|
+
catch (err) {
|
|
279
|
+
(0, output_js_1.printSpecialistEnd)(id);
|
|
280
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
281
|
+
(0, reasoning_log_js_1.appendReasoningLog)({
|
|
282
|
+
ts: new Date().toISOString(),
|
|
283
|
+
specialistId,
|
|
284
|
+
input,
|
|
285
|
+
toolCalls: [],
|
|
286
|
+
finalOutput: message,
|
|
287
|
+
status: 'error',
|
|
288
|
+
error: 'runtime_error',
|
|
289
|
+
});
|
|
290
|
+
return { status: 'error', result: message, error: 'runtime_error' };
|
|
291
|
+
}
|
|
292
|
+
finally {
|
|
293
|
+
(0, agent_pool_js_1.releaseSlot)();
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Strips internal fields (`reasoning`) from a wrapper result before it crosses
|
|
298
|
+
* back into the parent agent's context, and caps the `result` field so the
|
|
299
|
+
* outer JSON envelope stays parseable when the wrapper output is large. The
|
|
300
|
+
* reasoning array is already persisted to the JSONL trace via
|
|
301
|
+
* {@link appendReasoningLog}; the parent doesn't need it.
|
|
302
|
+
*
|
|
303
|
+
* The cap is applied to the `result` field *before* serialization rather than
|
|
304
|
+
* to the serialized envelope, so a truncated payload never produces invalid
|
|
305
|
+
* JSON.
|
|
306
|
+
*/
|
|
307
|
+
function renderWrapperParentView(wrapped, maxChars = result_cap_js_1.SUBAGENT_RESULT_MAX_CHARS) {
|
|
308
|
+
const errorLen = wrapped.error?.length ?? 0;
|
|
309
|
+
const resultBudget = Math.max(256, maxChars - errorLen - 80);
|
|
310
|
+
const cappedResult = typeof wrapped.result === 'string'
|
|
311
|
+
? (0, result_cap_js_1.capSubagentResult)(wrapped.result, resultBudget)
|
|
312
|
+
: (() => {
|
|
313
|
+
const asJson = JSON.stringify(wrapped.result);
|
|
314
|
+
if (asJson === undefined || asJson.length <= resultBudget)
|
|
315
|
+
return wrapped.result;
|
|
316
|
+
return (0, result_cap_js_1.capSubagentResult)(asJson, resultBudget);
|
|
317
|
+
})();
|
|
318
|
+
const parentView = wrapped.status === 'ok'
|
|
319
|
+
? { status: 'ok', result: cappedResult }
|
|
320
|
+
: {
|
|
321
|
+
status: 'error',
|
|
322
|
+
result: cappedResult,
|
|
323
|
+
...(wrapped.error !== undefined ? { error: wrapped.error } : {}),
|
|
324
|
+
};
|
|
325
|
+
return JSON.stringify(parentView);
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Creates the `tool_wrapper_run` tool for structured, isolated tool-wrapper
|
|
329
|
+
* specialist execution with validated JSON output and failure-learning.
|
|
330
|
+
*
|
|
331
|
+
* Unlike `specialist_run` (plain-text persona execution), this dispatch:
|
|
332
|
+
* - only runs specialists with `kind` in `'tool-wrapper' | 'meta'`
|
|
333
|
+
* - restricts the child's tool set to the specialist's `targetTools`
|
|
334
|
+
* - injects OS context + good/bad examples + structured-output rules
|
|
335
|
+
* - forces a JSON final message via `experimental_prepareStep`
|
|
336
|
+
* - parses through a Zod schema and logs runs that reach `generateText`
|
|
337
|
+
* to the reasoning log (guard failures return early without logging)
|
|
338
|
+
* - enqueues a correction candidate on error for end-of-session learning
|
|
339
|
+
* - strips `reasoning` and caps the JSON envelope before returning to the
|
|
340
|
+
* parent agent — the full reasoning lives in the JSONL trace only
|
|
341
|
+
*/
|
|
342
|
+
function createToolWrapperRunTool(config, options, memoryStore, specialistStore, correctionStore, mcpTools, ragStore, routineStore, candidateStore) {
|
|
343
|
+
return (0, ai_1.tool)({
|
|
344
|
+
description: 'Dispatch to a saved tool-wrapper specialist that handles a concrete tool or CLI (e.g. shell-wrapper, file-wrapper). Returns JSON {status, result, error?}. Use this for tool-heavy operations where domain-specific examples and error handling reduce misuse. Also used to invoke meta specialists (specialist-creator, correction-agent).',
|
|
345
|
+
parameters: zod_1.z.object({
|
|
346
|
+
specialistId: zod_1.z
|
|
347
|
+
.string()
|
|
348
|
+
.describe('The ID of the tool-wrapper or meta specialist to invoke (e.g. "shell-wrapper").'),
|
|
349
|
+
input: zod_1.z
|
|
350
|
+
.string()
|
|
351
|
+
.describe('The natural-language request to hand to the specialist. Be specific — the specialist has no prior context.'),
|
|
352
|
+
context: zod_1.z
|
|
353
|
+
.string()
|
|
354
|
+
.optional()
|
|
355
|
+
.describe('Optional additional context (file paths, prior findings, constraints).'),
|
|
356
|
+
provider: zod_1.z.string().optional().describe('Optional provider override for this invocation.'),
|
|
357
|
+
model: zod_1.z.string().optional().describe('Optional model override for this invocation.'),
|
|
358
|
+
}),
|
|
359
|
+
execute: async ({ specialistId, input, context, provider, model }, execOptions) => {
|
|
360
|
+
const wrapped = await dispatchToolWrapper({
|
|
361
|
+
specialistId,
|
|
362
|
+
input,
|
|
363
|
+
context,
|
|
364
|
+
provider,
|
|
365
|
+
model,
|
|
366
|
+
abortSignal: execOptions.abortSignal,
|
|
367
|
+
}, {
|
|
368
|
+
config,
|
|
369
|
+
options,
|
|
370
|
+
memoryStore,
|
|
371
|
+
specialistStore,
|
|
372
|
+
correctionStore,
|
|
373
|
+
mcpTools,
|
|
374
|
+
ragStore,
|
|
375
|
+
routineStore,
|
|
376
|
+
candidateStore,
|
|
377
|
+
});
|
|
378
|
+
return renderWrapperParentView(wrapped);
|
|
379
|
+
},
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
//# sourceMappingURL=tool-wrapper-run.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-wrapper-run.js","sourceRoot":"","sources":["../../src/tools/tool-wrapper-run.ts"],"names":[],"mappings":";;AAsCA,wCAqBC;AASD,0CAcC;AAMD,kDAeC;AAKD,4CAsBC;AAqCD,kDA4NC;AAaD,0DAyBC;AAiBD,4DAyDC;AAnfD,2BAAwC;AACxC,6BAAwB;AACxB,oDAAuF;AACvF,yCAA2D;AAC3D,+CAAmD;AACnD,uCAA2C;AAC3C,2DAA8D;AAC9D,uCAAiD;AACjD,4CAMsB;AACtB,4CAAwC;AACxC,4DAA0D;AAC1D,mDAAkF;AAClF,4CAA2E;AAO3E,8CAA8C;AAC9C,kEAIiC;AACjC,0DAAyD;AACzD,mDAA+E;AAE/E,mGAAmG;AACnG,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAEpC,2FAA2F;AAC3F,SAAgB,cAAc,CAAC,UAAsB;IACnD,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,MAAM,IAAI,GAAG,UAAU,CAAC,YAAY,IAAI,EAAE,CAAC;IAC3C,MAAM,GAAG,GAAG,UAAU,CAAC,WAAW,IAAI,EAAE,CAAC;IACzC,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACpB,KAAK,CAAC,IAAI,CAAC,8CAA8C,CAAC,CAAC;QAC3D,KAAK,MAAM,EAAE,IAAI,IAAI,EAAE,CAAC;YACtB,K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package/dist/tools/types.d.ts
CHANGED
|
@@ -1,9 +1,35 @@
|
|
|
1
|
+
/** A single question for the `askUser` callback. */
|
|
2
|
+
export interface AskUserQuestion {
|
|
3
|
+
question: string;
|
|
4
|
+
choices?: string[];
|
|
5
|
+
/** When true and `choices` is present, the implementation appends an escape-hatch row that falls back to free-form input. */
|
|
6
|
+
allowOther: boolean;
|
|
7
|
+
/** Optional label for the escape-hatch row; defaults to a generic "Other" wording. */
|
|
8
|
+
otherLabel?: string;
|
|
9
|
+
}
|
|
10
|
+
/** Result of an `askUser` batch interaction. `answered` is aligned by index with the input questions. */
|
|
11
|
+
export type AskUserBatchResult = {
|
|
12
|
+
answers: string[];
|
|
13
|
+
} | {
|
|
14
|
+
cancelled: true;
|
|
15
|
+
answered: string[];
|
|
16
|
+
};
|
|
1
17
|
/** Options shared by all tool implementations. */
|
|
2
18
|
export interface ToolOptions {
|
|
3
19
|
/** Maximum time in milliseconds a shell command may run before being killed. */
|
|
4
20
|
shellTimeout: number;
|
|
5
|
-
/**
|
|
6
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Callback that prompts the user for confirmation before executing a dangerous command.
|
|
23
|
+
* The optional `signal` lets callers abort the prompt (e.g. when the user presses Esc).
|
|
24
|
+
*/
|
|
25
|
+
confirmDangerous: (command: string, signal?: AbortSignal) => Promise<boolean>;
|
|
26
|
+
/**
|
|
27
|
+
* Callback that asks the user one or more questions in sequence. The
|
|
28
|
+
* implementation owns any progress UI (e.g. a tab strip for batches of
|
|
29
|
+
* 2+). On mid-batch cancellation, returns whatever was answered so far.
|
|
30
|
+
* Omitted in non-interactive environments (cron daemon).
|
|
31
|
+
*/
|
|
32
|
+
askUser?: (questions: AskUserQuestion[], signal?: AbortSignal) => Promise<AskUserBatchResult>;
|
|
7
33
|
}
|
|
8
34
|
/** Outcome of a shell tool invocation. */
|
|
9
35
|
export interface ShellResult {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** One search result. Kept minimal so the LLM can cheaply decide which URLs to `web_read`. */
|
|
3
|
+
export interface SearchResult {
|
|
4
|
+
title: string;
|
|
5
|
+
url: string;
|
|
6
|
+
snippet: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Creates the `web_search` tool.
|
|
10
|
+
*
|
|
11
|
+
* Provider chain: Brave (`BRAVE_API_KEY`) → Tavily (`TAVILY_API_KEY`) →
|
|
12
|
+
* DuckDuckGo HTML scrape (no key). When every provider fails, the tool
|
|
13
|
+
* returns a diagnostic message and suggests calling `web_read` with a known
|
|
14
|
+
* URL instead — this keeps the specialist-creator meta-agent productive even
|
|
15
|
+
* without API keys.
|
|
16
|
+
*/
|
|
17
|
+
export declare function createWebSearchTool(): import("ai").Tool<z.ZodObject<{
|
|
18
|
+
query: z.ZodString;
|
|
19
|
+
limit: z.ZodOptional<z.ZodNumber>;
|
|
20
|
+
}, "strip", z.ZodTypeAny, {
|
|
21
|
+
query: string;
|
|
22
|
+
limit?: number | undefined;
|
|
23
|
+
}, {
|
|
24
|
+
query: string;
|
|
25
|
+
limit?: number | undefined;
|
|
26
|
+
}>, string> & {
|
|
27
|
+
execute: (args: {
|
|
28
|
+
query: string;
|
|
29
|
+
limit?: number | undefined;
|
|
30
|
+
}, options: import("ai").ToolExecutionOptions) => PromiseLike<string>;
|
|
31
|
+
};
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createWebSearchTool = createWebSearchTool;
|
|
4
|
+
const ai_1 = require("ai");
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const node_html_parser_1 = require("node-html-parser");
|
|
7
|
+
const DEFAULT_LIMIT = 5;
|
|
8
|
+
const MAX_LIMIT = 10;
|
|
9
|
+
const FETCH_TIMEOUT_MS = 12_000;
|
|
10
|
+
const USER_AGENT = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36';
|
|
11
|
+
/** Try Brave Search API. Returns `undefined` when the provider is unavailable or errors. */
|
|
12
|
+
async function searchBrave(query, limit) {
|
|
13
|
+
const apiKey = process.env.BRAVE_API_KEY;
|
|
14
|
+
if (!apiKey)
|
|
15
|
+
return undefined;
|
|
16
|
+
try {
|
|
17
|
+
const url = new URL('https://api.search.brave.com/res/v1/web/search');
|
|
18
|
+
url.searchParams.set('q', query);
|
|
19
|
+
url.searchParams.set('count', String(limit));
|
|
20
|
+
const res = await fetch(url.toString(), {
|
|
21
|
+
signal: AbortSignal.timeout(FETCH_TIMEOUT_MS),
|
|
22
|
+
headers: {
|
|
23
|
+
Accept: 'application/json',
|
|
24
|
+
'X-Subscription-Token': apiKey,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
if (!res.ok)
|
|
28
|
+
return undefined;
|
|
29
|
+
const data = (await res.json());
|
|
30
|
+
const results = data.web?.results ?? [];
|
|
31
|
+
return results.slice(0, limit).map((r) => ({
|
|
32
|
+
title: String(r.title ?? ''),
|
|
33
|
+
url: String(r.url ?? ''),
|
|
34
|
+
snippet: String(r.description ?? ''),
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/** Try Tavily search API. Returns `undefined` when the provider is unavailable or errors. */
|
|
42
|
+
async function searchTavily(query, limit) {
|
|
43
|
+
const apiKey = process.env.TAVILY_API_KEY;
|
|
44
|
+
if (!apiKey)
|
|
45
|
+
return undefined;
|
|
46
|
+
try {
|
|
47
|
+
const res = await fetch('https://api.tavily.com/search', {
|
|
48
|
+
method: 'POST',
|
|
49
|
+
signal: AbortSignal.timeout(FETCH_TIMEOUT_MS),
|
|
50
|
+
headers: { 'Content-Type': 'application/json' },
|
|
51
|
+
body: JSON.stringify({
|
|
52
|
+
api_key: apiKey,
|
|
53
|
+
query,
|
|
54
|
+
max_results: limit,
|
|
55
|
+
search_depth: 'basic',
|
|
56
|
+
}),
|
|
57
|
+
});
|
|
58
|
+
if (!res.ok)
|
|
59
|
+
return undefined;
|
|
60
|
+
const data = (await res.json());
|
|
61
|
+
const results = data.results ?? [];
|
|
62
|
+
return results.slice(0, limit).map((r) => ({
|
|
63
|
+
title: String(r.title ?? ''),
|
|
64
|
+
url: String(r.url ?? ''),
|
|
65
|
+
snippet: String(r.content ?? r.snippet ?? ''),
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* DuckDuckGo HTML scrape. No API key required but output is fragile to layout
|
|
74
|
+
* changes. Used as a last-resort fallback so specialist-creator can still do
|
|
75
|
+
* rough research without any paid API.
|
|
76
|
+
*/
|
|
77
|
+
async function searchDuckDuckGo(query, limit) {
|
|
78
|
+
try {
|
|
79
|
+
const url = new URL('https://html.duckduckgo.com/html/');
|
|
80
|
+
url.searchParams.set('q', query);
|
|
81
|
+
const res = await fetch(url.toString(), {
|
|
82
|
+
signal: AbortSignal.timeout(FETCH_TIMEOUT_MS),
|
|
83
|
+
headers: { 'User-Agent': USER_AGENT, Accept: 'text/html' },
|
|
84
|
+
});
|
|
85
|
+
if (!res.ok)
|
|
86
|
+
return undefined;
|
|
87
|
+
const html = await res.text();
|
|
88
|
+
const root = (0, node_html_parser_1.parse)(html);
|
|
89
|
+
const results = [];
|
|
90
|
+
const nodes = root.querySelectorAll('.result');
|
|
91
|
+
for (const node of nodes) {
|
|
92
|
+
if (results.length >= limit)
|
|
93
|
+
break;
|
|
94
|
+
const anchor = node.querySelector('a.result__a');
|
|
95
|
+
const snippetEl = node.querySelector('.result__snippet');
|
|
96
|
+
const title = anchor?.text.trim() ?? '';
|
|
97
|
+
let href = anchor?.getAttribute('href') ?? '';
|
|
98
|
+
// DuckDuckGo wraps results in a redirect like //duckduckgo.com/l/?uddg=<encoded>
|
|
99
|
+
if (href.startsWith('//duckduckgo.com/l/') || href.includes('duckduckgo.com/l/')) {
|
|
100
|
+
try {
|
|
101
|
+
const parsed = new URL(href.startsWith('//') ? `https:${href}` : href);
|
|
102
|
+
const uddg = parsed.searchParams.get('uddg');
|
|
103
|
+
if (uddg)
|
|
104
|
+
href = decodeURIComponent(uddg);
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
/* leave as-is */
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const snippet = snippetEl?.text.trim() ?? '';
|
|
111
|
+
if (title && href)
|
|
112
|
+
results.push({ title, url: href, snippet });
|
|
113
|
+
}
|
|
114
|
+
return results;
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
return undefined;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function formatResults(results) {
|
|
121
|
+
if (results.length === 0)
|
|
122
|
+
return 'No results found.';
|
|
123
|
+
return results
|
|
124
|
+
.map((r, i) => `${i + 1}. ${r.title}\n ${r.url}${r.snippet ? `\n ${r.snippet.slice(0, 300)}` : ''}`)
|
|
125
|
+
.join('\n\n');
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Creates the `web_search` tool.
|
|
129
|
+
*
|
|
130
|
+
* Provider chain: Brave (`BRAVE_API_KEY`) → Tavily (`TAVILY_API_KEY`) →
|
|
131
|
+
* DuckDuckGo HTML scrape (no key). When every provider fails, the tool
|
|
132
|
+
* returns a diagnostic message and suggests calling `web_read` with a known
|
|
133
|
+
* URL instead — this keeps the specialist-creator meta-agent productive even
|
|
134
|
+
* without API keys.
|
|
135
|
+
*/
|
|
136
|
+
function createWebSearchTool() {
|
|
137
|
+
return (0, ai_1.tool)({
|
|
138
|
+
description: 'Search the web and return a ranked list of {title, url, snippet} results. Use before web_read when you do not yet know the right URL. Provider chain: Brave → Tavily → DuckDuckGo (no API key required for the fallback).',
|
|
139
|
+
parameters: zod_1.z.object({
|
|
140
|
+
query: zod_1.z
|
|
141
|
+
.string()
|
|
142
|
+
.describe('The search query. Prefer specific phrasing over generic keywords.'),
|
|
143
|
+
limit: zod_1.z
|
|
144
|
+
.number()
|
|
145
|
+
.int()
|
|
146
|
+
.min(1)
|
|
147
|
+
.max(MAX_LIMIT)
|
|
148
|
+
.optional()
|
|
149
|
+
.describe(`Maximum results to return (default ${DEFAULT_LIMIT}, max ${MAX_LIMIT}).`),
|
|
150
|
+
}),
|
|
151
|
+
execute: async ({ query, limit }) => {
|
|
152
|
+
const cappedLimit = Math.min(Math.max(1, limit ?? DEFAULT_LIMIT), MAX_LIMIT);
|
|
153
|
+
const attempts = [
|
|
154
|
+
['brave', () => searchBrave(query, cappedLimit)],
|
|
155
|
+
['tavily', () => searchTavily(query, cappedLimit)],
|
|
156
|
+
['duckduckgo', () => searchDuckDuckGo(query, cappedLimit)],
|
|
157
|
+
];
|
|
158
|
+
const failures = [];
|
|
159
|
+
for (const [name, fn] of attempts) {
|
|
160
|
+
const results = await fn();
|
|
161
|
+
if (results && results.length > 0) {
|
|
162
|
+
return `Provider: ${name}\n\n${formatResults(results)}`;
|
|
163
|
+
}
|
|
164
|
+
failures.push(name);
|
|
165
|
+
}
|
|
166
|
+
return (`web_search returned no results (tried: ${failures.join(', ')}). ` +
|
|
167
|
+
'If you know a likely documentation URL, call web_read directly. ' +
|
|
168
|
+
'To enable higher-quality search, set BRAVE_API_KEY or TAVILY_API_KEY.');
|
|
169
|
+
},
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=web-search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-search.js","sourceRoot":"","sources":["../../src/tools/web-search.ts"],"names":[],"mappings":";;AAwIA,kDAsCC;AA9KD,2BAA0B;AAC1B,6BAAwB;AACxB,uDAAyC;AASzC,MAAM,aAAa,GAAG,CAAC,CAAC;AACxB,MAAM,SAAS,GAAG,EAAE,CAAC;AACrB,MAAM,gBAAgB,GAAG,MAAM,CAAC;A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