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/paths.js
CHANGED
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.CRON_LOG_FILE = exports.CRON_PID_FILE = exports.LOGS_DIR = exports.HISTORY_FILE = exports.UPDATE_CACHE_PATH = exports.MODELS_DIR = exports.SPECIALIST_CANDIDATES_DIR = exports.SPECIALISTS_DIR = exports.ROUTINES_DIR = exports.CRON_ALERTS_DIR = exports.CRON_JOBS_FILE = exports.CRON_DIR = exports.LAST_SESSION_FILE = exports.MEMORIES_FILE = exports.RAG_DIR = exports.MEMORY_DIR = exports.MCP_CONFIG_PATH = exports.ENV_PATH = exports.KEYS_PATH = exports.PREFS_PATH = exports.LEGACY_DIR = exports.STATE_DIR = exports.CACHE_DIR = exports.DATA_DIR = exports.CONFIG_DIR = void 0;
|
|
36
|
+
exports.CRON_LOG_FILE = exports.CRON_PID_FILE = exports.TOOL_WRAPPER_LOG = exports.LOGS_DIR = exports.HISTORY_FILE = exports.UPDATE_CACHE_PATH = exports.MODELS_DIR = exports.TOOL_PROFILES_DIR = exports.CORRECTION_CANDIDATES_DIR = exports.SPECIALIST_CANDIDATES_DIR = exports.SPECIALISTS_DIR = exports.ROUTINES_DIR = exports.CRON_NOTES_DIR = exports.CRON_ALERTS_DIR = exports.CRON_JOBS_FILE = exports.CRON_DIR = exports.LAST_SESSION_FILE = exports.MEMORIES_FILE = exports.RAG_DIR = exports.MEMORY_DIR = exports.CUSTOM_PROVIDERS_PATH = exports.MCP_CONFIG_PATH = exports.ENV_PATH = exports.KEYS_PATH = exports.PREFS_PATH = exports.LEGACY_DIR = exports.STATE_DIR = exports.CACHE_DIR = exports.DATA_DIR = exports.CONFIG_DIR = void 0;
|
|
37
37
|
const path = __importStar(require("node:path"));
|
|
38
38
|
const os = __importStar(require("node:os"));
|
|
39
39
|
const home = os.homedir();
|
|
@@ -62,6 +62,7 @@ exports.PREFS_PATH = path.join(exports.CONFIG_DIR, 'preferences.json');
|
|
|
62
62
|
exports.KEYS_PATH = path.join(exports.CONFIG_DIR, 'keys.json');
|
|
63
63
|
exports.ENV_PATH = path.join(exports.CONFIG_DIR, '.env');
|
|
64
64
|
exports.MCP_CONFIG_PATH = path.join(exports.CONFIG_DIR, 'mcp.json');
|
|
65
|
+
exports.CUSTOM_PROVIDERS_PATH = path.join(exports.CONFIG_DIR, 'custom-providers.json');
|
|
65
66
|
// Data
|
|
66
67
|
exports.MEMORY_DIR = path.join(exports.DATA_DIR, 'memory');
|
|
67
68
|
exports.RAG_DIR = path.join(exports.DATA_DIR, 'rag');
|
|
@@ -70,15 +71,19 @@ exports.LAST_SESSION_FILE = path.join(exports.RAG_DIR, 'last-session.txt');
|
|
|
70
71
|
exports.CRON_DIR = path.join(exports.DATA_DIR, 'cron');
|
|
71
72
|
exports.CRON_JOBS_FILE = path.join(exports.CRON_DIR, 'jobs.json');
|
|
72
73
|
exports.CRON_ALERTS_DIR = path.join(exports.CRON_DIR, 'alerts');
|
|
74
|
+
exports.CRON_NOTES_DIR = path.join(exports.CRON_DIR, 'notes');
|
|
73
75
|
exports.ROUTINES_DIR = path.join(exports.DATA_DIR, 'routines');
|
|
74
76
|
exports.SPECIALISTS_DIR = path.join(exports.DATA_DIR, 'specialists');
|
|
75
77
|
exports.SPECIALIST_CANDIDATES_DIR = path.join(exports.DATA_DIR, 'specialist-candidates');
|
|
78
|
+
exports.CORRECTION_CANDIDATES_DIR = path.join(exports.DATA_DIR, 'correction-candidates');
|
|
79
|
+
exports.TOOL_PROFILES_DIR = path.join(exports.DATA_DIR, 'tool-profiles');
|
|
76
80
|
// Cache
|
|
77
81
|
exports.MODELS_DIR = path.join(exports.CACHE_DIR, 'models');
|
|
78
82
|
exports.UPDATE_CACHE_PATH = path.join(exports.CACHE_DIR, 'update-check.json');
|
|
79
83
|
// State
|
|
80
84
|
exports.HISTORY_FILE = path.join(exports.STATE_DIR, 'conversation-history.json');
|
|
81
85
|
exports.LOGS_DIR = path.join(exports.STATE_DIR, 'logs');
|
|
86
|
+
exports.TOOL_WRAPPER_LOG = path.join(exports.LOGS_DIR, 'tool-wrappers.jsonl');
|
|
82
87
|
exports.CRON_PID_FILE = path.join(exports.STATE_DIR, 'cron-daemon.pid');
|
|
83
88
|
exports.CRON_LOG_FILE = path.join(exports.STATE_DIR, 'cron-daemon.log');
|
|
84
89
|
//# sourceMappingURL=paths.js.map
|
package/dist/paths.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAkC;AAClC,4CAA8B;AAE9B,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AC;AAC9D,QAAA,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,iBAAS,EAAE,iBAAiB,CAAC,CAAC;AACxD,QAAA,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,iBAAS,EAAE,iBAAiB,CAAC,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Status lifecycle for a plan step.
|
|
3
|
+
*
|
|
4
|
+
* Non-terminal: `pending`, `in_progress`.
|
|
5
|
+
* Terminal: `done`, `cancelled`, `error`.
|
|
6
|
+
*/
|
|
7
|
+
export type StepStatus = 'pending' | 'in_progress' | 'done' | 'cancelled' | 'error';
|
|
8
|
+
export interface Step {
|
|
9
|
+
id: number;
|
|
10
|
+
description: string;
|
|
11
|
+
/** Concrete check that proves the step succeeded. Filled at create/add. */
|
|
12
|
+
verification: string;
|
|
13
|
+
status: StepStatus;
|
|
14
|
+
/** Set when status is cancelled/error (reason) or done (alongside signoff). */
|
|
15
|
+
note?: string;
|
|
16
|
+
/** Sign-off statement attesting the verification was actually checked. Required for done. */
|
|
17
|
+
signoff?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface StepInput {
|
|
20
|
+
description: string;
|
|
21
|
+
verification: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Session-scoped plan store used by coordinator (ReAct) mode.
|
|
25
|
+
*
|
|
26
|
+
* Plans are per-turn and in-memory only. The owning Agent calls `clear()` at
|
|
27
|
+
* the start of each `processInput` so plans do not bleed across turns.
|
|
28
|
+
*/
|
|
29
|
+
export declare class PlanStore {
|
|
30
|
+
private steps;
|
|
31
|
+
create(inputs: StepInput[]): Step[];
|
|
32
|
+
add(input: StepInput): Step;
|
|
33
|
+
/** Transitions a step's status. Returns null if no step matches the id. */
|
|
34
|
+
update(id: number, status: StepStatus, opts?: {
|
|
35
|
+
note?: string;
|
|
36
|
+
signoff?: string;
|
|
37
|
+
}): Step | null;
|
|
38
|
+
view(): Step[];
|
|
39
|
+
clear(): void;
|
|
40
|
+
/** True when every step is in a terminal state (done, cancelled, error). */
|
|
41
|
+
isComplete(): boolean;
|
|
42
|
+
unresolvedCount(): number;
|
|
43
|
+
/** Cancels every non-terminal step with the given note. Returns the count cancelled. */
|
|
44
|
+
cancelAllUnresolved(note: string): number;
|
|
45
|
+
/** Renders the plan as a human-readable list for re-prompts. */
|
|
46
|
+
render(): string;
|
|
47
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PlanStore = void 0;
|
|
4
|
+
const TERMINAL_STATUSES = new Set([
|
|
5
|
+
'done',
|
|
6
|
+
'cancelled',
|
|
7
|
+
'error',
|
|
8
|
+
]);
|
|
9
|
+
/**
|
|
10
|
+
* Session-scoped plan store used by coordinator (ReAct) mode.
|
|
11
|
+
*
|
|
12
|
+
* Plans are per-turn and in-memory only. The owning Agent calls `clear()` at
|
|
13
|
+
* the start of each `processInput` so plans do not bleed across turns.
|
|
14
|
+
*/
|
|
15
|
+
class PlanStore {
|
|
16
|
+
steps = [];
|
|
17
|
+
create(inputs) {
|
|
18
|
+
this.steps = [];
|
|
19
|
+
for (const input of inputs) {
|
|
20
|
+
this.steps.push({
|
|
21
|
+
id: this.steps.length + 1,
|
|
22
|
+
description: input.description,
|
|
23
|
+
verification: input.verification,
|
|
24
|
+
status: 'pending',
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return this.view();
|
|
28
|
+
}
|
|
29
|
+
add(input) {
|
|
30
|
+
const step = {
|
|
31
|
+
id: this.steps.length + 1,
|
|
32
|
+
description: input.description,
|
|
33
|
+
verification: input.verification,
|
|
34
|
+
status: 'pending',
|
|
35
|
+
};
|
|
36
|
+
this.steps.push(step);
|
|
37
|
+
return { ...step };
|
|
38
|
+
}
|
|
39
|
+
/** Transitions a step's status. Returns null if no step matches the id. */
|
|
40
|
+
update(id, status, opts) {
|
|
41
|
+
const step = this.steps.find((s) => s.id === id);
|
|
42
|
+
if (!step)
|
|
43
|
+
return null;
|
|
44
|
+
step.status = status;
|
|
45
|
+
if (opts?.note !== undefined)
|
|
46
|
+
step.note = opts.note;
|
|
47
|
+
if (opts?.signoff !== undefined)
|
|
48
|
+
step.signoff = opts.signoff;
|
|
49
|
+
return { ...step };
|
|
50
|
+
}
|
|
51
|
+
view() {
|
|
52
|
+
return this.steps.map((s) => ({ ...s }));
|
|
53
|
+
}
|
|
54
|
+
clear() {
|
|
55
|
+
this.steps = [];
|
|
56
|
+
}
|
|
57
|
+
/** True when every step is in a terminal state (done, cancelled, error). */
|
|
58
|
+
isComplete() {
|
|
59
|
+
return this.steps.every((s) => TERMINAL_STATUSES.has(s.status));
|
|
60
|
+
}
|
|
61
|
+
unresolvedCount() {
|
|
62
|
+
return this.steps.filter((s) => !TERMINAL_STATUSES.has(s.status)).length;
|
|
63
|
+
}
|
|
64
|
+
/** Cancels every non-terminal step with the given note. Returns the count cancelled. */
|
|
65
|
+
cancelAllUnresolved(note) {
|
|
66
|
+
let count = 0;
|
|
67
|
+
for (const step of this.steps) {
|
|
68
|
+
if (!TERMINAL_STATUSES.has(step.status)) {
|
|
69
|
+
step.status = 'cancelled';
|
|
70
|
+
step.note = note;
|
|
71
|
+
count++;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return count;
|
|
75
|
+
}
|
|
76
|
+
/** Renders the plan as a human-readable list for re-prompts. */
|
|
77
|
+
render() {
|
|
78
|
+
if (this.steps.length === 0)
|
|
79
|
+
return '(no plan)';
|
|
80
|
+
return this.steps
|
|
81
|
+
.map((s) => {
|
|
82
|
+
const lines = [`${s.id}. [${s.status}] ${s.description}`];
|
|
83
|
+
lines.push(` verify: ${s.verification}`);
|
|
84
|
+
if (s.signoff)
|
|
85
|
+
lines.push(` signoff: ${s.signoff}`);
|
|
86
|
+
if (s.note)
|
|
87
|
+
lines.push(` note: ${s.note}`);
|
|
88
|
+
return lines.join('\n');
|
|
89
|
+
})
|
|
90
|
+
.join('\n');
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
exports.PlanStore = PlanStore;
|
|
94
|
+
//# sourceMappingURL=plan-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan-store.js","sourceRoot":"","sources":["../src/plan-store.ts"],"names":[],"mappings":";;;AAyBA,MAAM,iBAAiB,GAA4B,IAAI,GAAG,CAAa;IACrE,MAAM;IACN,WAAW;IACX,OAAO;CACR,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAa,SAAS;IACZ,KAAK,GAAW,EAAE,CAAC;IAE3B,MAAM,CAAC,MAAmB;QACxB,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;QAChB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;gBACd,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC;gBACzB,WAAW,EAAE,KAAK,CAAC,WAAW;gBAC9B,YAAY,EAAE,KAAK,CAAC,YAAY;gBAChC,MAAM,EAAE,SAAS;aAClB,CAAC,CAAC;QACL,CAAC;QACD,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC;IACrB,CAAC;IAED,GAAG,CAAC,KAAgB;QAClB,MAAM,IAAI,GAAS;YACjB,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC;YACzB,WAAW,EAAE,KAAK,CAAC,WAAW;YAC9B,YAAY,EAAE,KAAK,CAAC,YAAY;YAChC,MAAM,EAAE,SAAS;SAClB,CAAC;QACF,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACtB,OAAO,EAAE,GAAG,IAAI,EAAE,CAAC;IACrB,CAAC;IAED,2EAA2E;IAC3E,MAAM,CAAC,EAAU,EAAE,MAAkB,EAAE,IAA0C;QAC/E,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC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,MAAM,GAAG,WAAW,CAAC;gBAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;gBACjB,KAAK,EAAE,CAAC;YACV,CAAC;QACH,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,gEAAgE;IAChE,MAAM;QACJ,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,WAAW,CAAC;QAChD,OAAO,IAAI,CAAC,KAAK;aACd,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;YACT,MAAM,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;YAC1D,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,YAAY,EAAE,CAAC,CAAC;YAC3C,IAAI,CAAC,CAAC,OAAO;gBAAE,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;YACtD,IAAI,CAAC,CAAC,IAAI;gBAAE,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;YAC7C,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1B,CAAC,CAAC;aACD,IAAI,CAAC,IAAI,CAAC,CAAC;IAChB,CAAC;CACF;AAhFD,8BAgFC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ModelProfile } from './providers/profiles.js';
|
|
2
|
+
import type { ResolvedEntry } from './reference-resolver.js';
|
|
3
|
+
import type { BernardConfig } from './config.js';
|
|
4
|
+
/**
|
|
5
|
+
* Model-specific Prompt Rewriter — a pre-turn LLM pass that restructures the
|
|
6
|
+
* user's input for the active model family while preserving intent.
|
|
7
|
+
*
|
|
8
|
+
* Acts as a compiler preprocessor, not a planner: no new verbs, no new entities,
|
|
9
|
+
* no expanded scope. Consumes resolved entries from {@link ./reference-resolver}
|
|
10
|
+
* so concrete names can be inlined into the rewritten prompt (optional).
|
|
11
|
+
*
|
|
12
|
+
* All failure paths fall through to `{ status: 'noop' }` so the caller can
|
|
13
|
+
* default to the original user input. The LLM call uses temperature 0 for
|
|
14
|
+
* determinism.
|
|
15
|
+
*/
|
|
16
|
+
export type RewriteResult = {
|
|
17
|
+
status: 'noop';
|
|
18
|
+
} | {
|
|
19
|
+
status: 'rewritten';
|
|
20
|
+
text: string;
|
|
21
|
+
};
|
|
22
|
+
export type SkipReason = 'disabled' | 'short-or-structured' | 'conversational' | 'followup' | null;
|
|
23
|
+
/**
|
|
24
|
+
* Returns a specific reason string when the rewriter should skip, or `null` to continue.
|
|
25
|
+
* Exposed so the REPL (and tests) can log the precise skip cause.
|
|
26
|
+
*/
|
|
27
|
+
export declare function skipRewriterReason(input: string): SkipReason;
|
|
28
|
+
export declare function shouldSkipRewriter(input: string): boolean;
|
|
29
|
+
export declare function rewritePrompt(input: string, profile: ModelProfile, resolvedEntries: ResolvedEntry[], config: BernardConfig, abortSignal?: AbortSignal): Promise<RewriteResult>;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.skipRewriterReason = skipRewriterReason;
|
|
4
|
+
exports.shouldSkipRewriter = shouldSkipRewriter;
|
|
5
|
+
exports.rewritePrompt = rewritePrompt;
|
|
6
|
+
const ai_1 = require("ai");
|
|
7
|
+
const index_js_1 = require("./providers/index.js");
|
|
8
|
+
const logger_js_1 = require("./logger.js");
|
|
9
|
+
const REWRITER_MAX_TOKENS = 768;
|
|
10
|
+
/** Skip prompts shorter than this — not worth the LLM round-trip. */
|
|
11
|
+
const MIN_INPUT_CHARS = 8;
|
|
12
|
+
/**
|
|
13
|
+
* Skip prompts that already start with a structural marker (the user likely
|
|
14
|
+
* authored a formatted prompt). Keeps round-trips off short, obvious inputs.
|
|
15
|
+
*/
|
|
16
|
+
const STRUCTURED_PREFIX = /^\s*(task:|#\s|<[a-z])/i;
|
|
17
|
+
/** Reject suspiciously short rewrites relative to the source (catches truncation). */
|
|
18
|
+
const MIN_REWRITE_RATIO = 0.4;
|
|
19
|
+
/**
|
|
20
|
+
* Whole-prompt matches for conversational replies and acknowledgments. Full-match only —
|
|
21
|
+
* "ok" alone is a followup, but "ok so what I need is..." is a real request.
|
|
22
|
+
*/
|
|
23
|
+
const CONVERSATIONAL_RE = /^(ok(ay)?|thanks?|thank you|yes|yep|yeah|no|nope|sure|cool|got it|sounds good|continue|go ahead|keep going|next|and|also|why|how come|really|hmm+|what)[.!?]*$/i;
|
|
24
|
+
/**
|
|
25
|
+
* Short follow-up prefixes that key off conversation state. No nouns worth inlining,
|
|
26
|
+
* no structure to reshape — pass the prompt through to the main agent untouched.
|
|
27
|
+
*/
|
|
28
|
+
const FOLLOWUP_PREFIX_RE = /^(what about|how about|and what|why not|why is|why does|is that|does that|can you also|can you now)\b/i;
|
|
29
|
+
/**
|
|
30
|
+
* Returns a specific reason string when the rewriter should skip, or `null` to continue.
|
|
31
|
+
* Exposed so the REPL (and tests) can log the precise skip cause.
|
|
32
|
+
*/
|
|
33
|
+
function skipRewriterReason(input) {
|
|
34
|
+
const trimmed = input.trim();
|
|
35
|
+
// Check conversational / followup patterns first so they report a specific reason
|
|
36
|
+
// rather than falling through to the length check for short acknowledgments like "why?".
|
|
37
|
+
if (CONVERSATIONAL_RE.test(trimmed))
|
|
38
|
+
return 'conversational';
|
|
39
|
+
if (FOLLOWUP_PREFIX_RE.test(trimmed))
|
|
40
|
+
return 'followup';
|
|
41
|
+
if (trimmed.length < MIN_INPUT_CHARS)
|
|
42
|
+
return 'short-or-structured';
|
|
43
|
+
if (trimmed.startsWith('/'))
|
|
44
|
+
return 'short-or-structured';
|
|
45
|
+
if (STRUCTURED_PREFIX.test(trimmed))
|
|
46
|
+
return 'short-or-structured';
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
function shouldSkipRewriter(input) {
|
|
50
|
+
return skipRewriterReason(input) !== null;
|
|
51
|
+
}
|
|
52
|
+
function buildSystemPrompt(profile) {
|
|
53
|
+
return `You are a prompt preprocessor. Your job is to rewrite the user's input so a downstream "${profile.family}" model handles it reliably.
|
|
54
|
+
|
|
55
|
+
Rules:
|
|
56
|
+
- Preserve every verb, noun, and constraint the user wrote. Do not add tasks. Do not remove tasks. Do not answer the request.
|
|
57
|
+
- Treat this as a lossless structural transform, not reasoning. If in doubt, output status "noop".
|
|
58
|
+
- If resolved entities are provided, you MAY inline them verbatim to eliminate ambiguity (e.g. replace "my daughter" with "Sarah, my daughter"). Never invent or extrapolate entities.
|
|
59
|
+
- Never wrap the rewrite in the downstream wrapper (\`<user_request>\`) or in markdown code fences — the caller applies those. Lightweight structural tags like \`<task>\`, \`<context>\`, or \`<constraints>\` are allowed when the per-model hint recommends them.
|
|
60
|
+
- Per-model hint: ${profile.rewriterHint}
|
|
61
|
+
|
|
62
|
+
Output strict JSON and nothing else. One of:
|
|
63
|
+
{"status":"noop"}
|
|
64
|
+
{"status":"rewritten","text":"…"}
|
|
65
|
+
|
|
66
|
+
Prefer "noop" generously. Specifically return "noop" when the input is:
|
|
67
|
+
- A followup or clarification to a previous turn (e.g. "why not?", "what about the other one?", "and then?").
|
|
68
|
+
- An acknowledgment or conversational reply (e.g. "ok thanks", "got it", "sounds good").
|
|
69
|
+
- A short single-sentence question that is already unambiguous.
|
|
70
|
+
- Already clearly structured.
|
|
71
|
+
|
|
72
|
+
Only rewrite when the original prompt has real ambiguity or missing structure that a lossless transform can fix. When in doubt, "noop".`;
|
|
73
|
+
}
|
|
74
|
+
function buildUserMessage(input, resolvedEntries) {
|
|
75
|
+
const blocks = [`## Original user input\n${input}`];
|
|
76
|
+
if (resolvedEntries.length > 0) {
|
|
77
|
+
const lines = ['## Resolved entities (optional inlining)'];
|
|
78
|
+
for (const e of resolvedEntries) {
|
|
79
|
+
lines.push(`- "${e.phrase}" → ${e.resolvedTo}`);
|
|
80
|
+
}
|
|
81
|
+
blocks.push(lines.join('\n'));
|
|
82
|
+
}
|
|
83
|
+
return blocks.join('\n\n');
|
|
84
|
+
}
|
|
85
|
+
function parseRewriterResponse(text) {
|
|
86
|
+
const match = text.match(/\{[\s\S]*\}/);
|
|
87
|
+
if (!match)
|
|
88
|
+
return null;
|
|
89
|
+
try {
|
|
90
|
+
const parsed = JSON.parse(match[0]);
|
|
91
|
+
if (parsed?.status === 'noop')
|
|
92
|
+
return { status: 'noop' };
|
|
93
|
+
if (parsed?.status === 'rewritten' && typeof parsed.text === 'string') {
|
|
94
|
+
const trimmed = parsed.text.trim();
|
|
95
|
+
if (trimmed.length === 0)
|
|
96
|
+
return null;
|
|
97
|
+
return { status: 'rewritten', text: trimmed };
|
|
98
|
+
}
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
async function rewritePrompt(input, profile, resolvedEntries, config, abortSignal) {
|
|
106
|
+
if (!config.promptRewriter) {
|
|
107
|
+
(0, logger_js_1.debugLog)('prompt-rewriter:skip', { reason: 'disabled' });
|
|
108
|
+
return { status: 'noop' };
|
|
109
|
+
}
|
|
110
|
+
const skipReason = skipRewriterReason(input);
|
|
111
|
+
if (skipReason !== null) {
|
|
112
|
+
(0, logger_js_1.debugLog)('prompt-rewriter:skip', { reason: skipReason, input });
|
|
113
|
+
return { status: 'noop' };
|
|
114
|
+
}
|
|
115
|
+
(0, logger_js_1.debugLog)('prompt-rewriter:request', { family: profile.family, inputChars: input.length });
|
|
116
|
+
try {
|
|
117
|
+
const result = await (0, ai_1.generateText)({
|
|
118
|
+
model: (0, index_js_1.getModelForConfig)(config, config.provider, config.model),
|
|
119
|
+
providerOptions: (0, index_js_1.getProviderOptionsForConfig)(config, config.provider),
|
|
120
|
+
system: buildSystemPrompt(profile),
|
|
121
|
+
messages: [{ role: 'user', content: buildUserMessage(input, resolvedEntries) }],
|
|
122
|
+
maxSteps: 1,
|
|
123
|
+
maxTokens: REWRITER_MAX_TOKENS,
|
|
124
|
+
temperature: 0,
|
|
125
|
+
abortSignal,
|
|
126
|
+
});
|
|
127
|
+
if (!result.text) {
|
|
128
|
+
(0, logger_js_1.debugLog)('prompt-rewriter:empty-response', null);
|
|
129
|
+
return { status: 'noop' };
|
|
130
|
+
}
|
|
131
|
+
const parsed = parseRewriterResponse(result.text);
|
|
132
|
+
if (!parsed) {
|
|
133
|
+
(0, logger_js_1.debugLog)('prompt-rewriter:parse-failed', result.text.slice(0, 200));
|
|
134
|
+
return { status: 'noop' };
|
|
135
|
+
}
|
|
136
|
+
if (parsed.status === 'rewritten') {
|
|
137
|
+
if (parsed.text.length < input.length * MIN_REWRITE_RATIO) {
|
|
138
|
+
(0, logger_js_1.debugLog)('prompt-rewriter:rejected-truncation', {
|
|
139
|
+
original: input.length,
|
|
140
|
+
rewritten: parsed.text.length,
|
|
141
|
+
});
|
|
142
|
+
return { status: 'noop' };
|
|
143
|
+
}
|
|
144
|
+
(0, logger_js_1.debugLog)('prompt-rewriter:rewritten', { chars: parsed.text.length });
|
|
145
|
+
return parsed;
|
|
146
|
+
}
|
|
147
|
+
(0, logger_js_1.debugLog)('prompt-rewriter:noop', null);
|
|
148
|
+
return parsed;
|
|
149
|
+
}
|
|
150
|
+
catch (err) {
|
|
151
|
+
(0, logger_js_1.debugLog)('prompt-rewriter:error', err instanceof Error ? err.message : String(err));
|
|
152
|
+
return { status: 'noop' };
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=prompt-rewriter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-rewriter.js","sourceRoot":"","sources":["../src/prompt-rewriter.ts"],"names":[],"mappings":";;AAwDA,gDAUC;AAED,gDAEC;AAsDD,sCA4DC;AAxLD,2BAAkC;AAClC,mDAAsF;AAItF,2CAAuC;AAiBvC,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAEhC,qEAAqE;AAC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|
+
export { getModelProfile } from './profiles.js';
|
|
5
|
+
export type { ModelProfile } from './profiles.js';
|
|
6
|
+
export type { SupportedSdk } from './types.js';
|
|
7
|
+
/** Custom-provider params for `getModel()` — set when the active provider is user-defined. */
|
|
8
|
+
export interface CustomProviderInvocation {
|
|
9
|
+
/** Which installed AI-SDK to wrap. */
|
|
10
|
+
sdk: SupportedSdk;
|
|
11
|
+
/** Endpoint base URL, e.g. `http://localhost:11434/v1`. */
|
|
12
|
+
baseURL: string;
|
|
13
|
+
/** API key (some local servers accept any non-empty token). */
|
|
14
|
+
apiKey: string;
|
|
15
|
+
}
|
|
2
16
|
/**
|
|
3
17
|
* Return an AI SDK `LanguageModel` instance for the given provider and model name.
|
|
4
|
-
*
|
|
5
|
-
*
|
|
18
|
+
*
|
|
19
|
+
* For built-in providers (`anthropic`, `openai`, `xai`) the module-level singletons
|
|
20
|
+
* are used, which read API keys from environment variables. For custom providers
|
|
21
|
+
* the matching `createXxx({ baseURL, apiKey })` factory is invoked instead (cached
|
|
22
|
+
* by `(sdk, baseURL, apiKey)` so repeated calls are cheap).
|
|
23
|
+
*
|
|
24
|
+
* @param provider - Provider identifier (built-in or custom registry name).
|
|
25
|
+
* @param model - Provider-specific model identifier.
|
|
26
|
+
* @param custom - When set, build the model via the SDK factory with these options.
|
|
6
27
|
* @returns A ready-to-use `LanguageModel` backed by the requested provider.
|
|
7
|
-
* @throws {Error} If the provider string is not recognized.
|
|
28
|
+
* @throws {Error} If the provider string is not recognized and no `custom` info is supplied.
|
|
8
29
|
*/
|
|
9
|
-
export declare function getModel(provider: string, model: string): LanguageModel;
|
|
30
|
+
export declare function getModel(provider: string, model: string, custom?: CustomProviderInvocation): LanguageModel;
|
|
31
|
+
/**
|
|
32
|
+
* Resolves a `LanguageModel` for the given `provider`/`model`, automatically
|
|
33
|
+
* routing through the custom-provider registry when `provider` is user-defined.
|
|
34
|
+
*
|
|
35
|
+
* This is the call-site helper — every place in the codebase that used to call
|
|
36
|
+
* `getModel(provider, model)` should now call `getModelForConfig(config, provider, model)`
|
|
37
|
+
* so custom providers transparently take effect.
|
|
38
|
+
*/
|
|
39
|
+
export declare function getModelForConfig(config: BernardConfig, provider: string, model: string): LanguageModel;
|
|
40
|
+
/**
|
|
41
|
+
* Returns provider-specific generation options for the AI SDK.
|
|
42
|
+
*
|
|
43
|
+
* The optional `sdk` argument lets callers pass the underlying SDK family
|
|
44
|
+
* of a custom provider (its factory is OpenAI-shaped even if the name is e.g.
|
|
45
|
+
* "ollama") so the OpenAI strictSchemas escape hatch is also applied there.
|
|
46
|
+
*/
|
|
47
|
+
export declare function getProviderOptions(provider: string, sdk?: SupportedSdk): {
|
|
48
|
+
openai: {
|
|
49
|
+
strictSchemas: false;
|
|
50
|
+
};
|
|
51
|
+
} | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* Helper for the common case of resolving provider options from a `BernardConfig`
|
|
54
|
+
* by `provider` name — consults the custom-provider registry to pick the right
|
|
55
|
+
* SDK family.
|
|
56
|
+
*/
|
|
57
|
+
export declare function getProviderOptionsForConfig(config: BernardConfig, provider: string): {
|
|
58
|
+
openai: {
|
|
59
|
+
strictSchemas: false;
|
|
60
|
+
};
|
|
61
|
+
} | undefined;
|
package/dist/providers/index.js
CHANGED
|
@@ -1,26 +1,107 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getModelProfile = void 0;
|
|
3
4
|
exports.getModel = getModel;
|
|
5
|
+
exports.getModelForConfig = getModelForConfig;
|
|
6
|
+
exports.getProviderOptions = getProviderOptions;
|
|
7
|
+
exports.getProviderOptionsForConfig = getProviderOptionsForConfig;
|
|
4
8
|
const anthropic_1 = require("@ai-sdk/anthropic");
|
|
5
9
|
const openai_1 = require("@ai-sdk/openai");
|
|
6
10
|
const xai_1 = require("@ai-sdk/xai");
|
|
11
|
+
const config_js_1 = require("../config.js");
|
|
12
|
+
var profiles_js_1 = require("./profiles.js");
|
|
13
|
+
Object.defineProperty(exports, "getModelProfile", { enumerable: true, get: function () { return profiles_js_1.getModelProfile; } });
|
|
14
|
+
const customFactoryCache = new Map();
|
|
15
|
+
function getCustomFactory(custom) {
|
|
16
|
+
const cacheKey = `${custom.sdk}|${custom.baseURL}|${custom.apiKey}`;
|
|
17
|
+
const cached = customFactoryCache.get(cacheKey);
|
|
18
|
+
if (cached)
|
|
19
|
+
return cached;
|
|
20
|
+
const opts = { baseURL: custom.baseURL, apiKey: custom.apiKey };
|
|
21
|
+
const factory = custom.sdk === 'openai'
|
|
22
|
+
? (0, openai_1.createOpenAI)(opts)
|
|
23
|
+
: custom.sdk === 'anthropic'
|
|
24
|
+
? (0, anthropic_1.createAnthropic)(opts)
|
|
25
|
+
: (0, xai_1.createXai)(opts);
|
|
26
|
+
customFactoryCache.set(cacheKey, factory);
|
|
27
|
+
return factory;
|
|
28
|
+
}
|
|
7
29
|
/**
|
|
8
30
|
* Return an AI SDK `LanguageModel` instance for the given provider and model name.
|
|
9
|
-
*
|
|
10
|
-
*
|
|
31
|
+
*
|
|
32
|
+
* For built-in providers (`anthropic`, `openai`, `xai`) the module-level singletons
|
|
33
|
+
* are used, which read API keys from environment variables. For custom providers
|
|
34
|
+
* the matching `createXxx({ baseURL, apiKey })` factory is invoked instead (cached
|
|
35
|
+
* by `(sdk, baseURL, apiKey)` so repeated calls are cheap).
|
|
36
|
+
*
|
|
37
|
+
* @param provider - Provider identifier (built-in or custom registry name).
|
|
38
|
+
* @param model - Provider-specific model identifier.
|
|
39
|
+
* @param custom - When set, build the model via the SDK factory with these options.
|
|
11
40
|
* @returns A ready-to-use `LanguageModel` backed by the requested provider.
|
|
12
|
-
* @throws {Error} If the provider string is not recognized.
|
|
41
|
+
* @throws {Error} If the provider string is not recognized and no `custom` info is supplied.
|
|
13
42
|
*/
|
|
14
|
-
function getModel(provider, model) {
|
|
43
|
+
function getModel(provider, model, custom) {
|
|
44
|
+
if (custom) {
|
|
45
|
+
const factory = getCustomFactory(custom);
|
|
46
|
+
if (custom.sdk === 'openai')
|
|
47
|
+
return factory.responses(model);
|
|
48
|
+
return factory(model);
|
|
49
|
+
}
|
|
15
50
|
switch (provider) {
|
|
16
51
|
case 'anthropic':
|
|
17
52
|
return (0, anthropic_1.anthropic)(model);
|
|
18
53
|
case 'openai':
|
|
19
|
-
return
|
|
54
|
+
return openai_1.openai.responses(model);
|
|
20
55
|
case 'xai':
|
|
21
56
|
return (0, xai_1.xai)(model);
|
|
22
57
|
default:
|
|
23
58
|
throw new Error(`Unknown provider: ${provider}. Supported: anthropic, openai, xai`);
|
|
24
59
|
}
|
|
25
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Resolves a `LanguageModel` for the given `provider`/`model`, automatically
|
|
63
|
+
* routing through the custom-provider registry when `provider` is user-defined.
|
|
64
|
+
*
|
|
65
|
+
* This is the call-site helper — every place in the codebase that used to call
|
|
66
|
+
* `getModel(provider, model)` should now call `getModelForConfig(config, provider, model)`
|
|
67
|
+
* so custom providers transparently take effect.
|
|
68
|
+
*/
|
|
69
|
+
function getModelForConfig(config, provider, model) {
|
|
70
|
+
const custom = config.customProviders?.[provider];
|
|
71
|
+
if (custom) {
|
|
72
|
+
const apiKey = (0, config_js_1.getProviderApiKey)(config, provider) ?? '';
|
|
73
|
+
return getModel(provider, model, {
|
|
74
|
+
sdk: custom.sdk,
|
|
75
|
+
baseURL: custom.baseURL,
|
|
76
|
+
apiKey,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
return getModel(provider, model);
|
|
80
|
+
}
|
|
81
|
+
// Disable OpenAI strict-schemas: MCP tools commonly emit JSON Schema features
|
|
82
|
+
// (`oneOf` partial-constraint branches, untyped `items: {}`, etc.) that strict
|
|
83
|
+
// mode rejects at preflight, killing the user's turn.
|
|
84
|
+
const OPENAI_PROVIDER_OPTIONS = Object.freeze({
|
|
85
|
+
openai: Object.freeze({ strictSchemas: false }),
|
|
86
|
+
});
|
|
87
|
+
/**
|
|
88
|
+
* Returns provider-specific generation options for the AI SDK.
|
|
89
|
+
*
|
|
90
|
+
* The optional `sdk` argument lets callers pass the underlying SDK family
|
|
91
|
+
* of a custom provider (its factory is OpenAI-shaped even if the name is e.g.
|
|
92
|
+
* "ollama") so the OpenAI strictSchemas escape hatch is also applied there.
|
|
93
|
+
*/
|
|
94
|
+
function getProviderOptions(provider, sdk) {
|
|
95
|
+
const effective = sdk ?? provider;
|
|
96
|
+
return effective === 'openai' ? OPENAI_PROVIDER_OPTIONS : undefined;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Helper for the common case of resolving provider options from a `BernardConfig`
|
|
100
|
+
* by `provider` name — consults the custom-provider registry to pick the right
|
|
101
|
+
* SDK family.
|
|
102
|
+
*/
|
|
103
|
+
function getProviderOptionsForConfig(config, provider) {
|
|
104
|
+
const custom = config.customProviders?.[provider];
|
|
105
|
+
return getProviderOptions(provider, custom?.sdk);
|
|
106
|
+
}
|
|
26
107
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":";;;AAyDA,4BAqBC;AAUD,8CAeC;AAgBD,gDAMC;AAOD,kEAMC;AA1ID,iDAA+D;AAC/D,2CAAsD;AACtD,qCAA6C;AAI7C,4CAAiD;AAEjD,6CAAgD;AAAvC,8GAAA,eAAe,OAAA;AAkBxB,MAAM,kBAAkB,GAAG,IAAI,GAAG,EAAyB,CAAC;AAE5D,SAAS,gBAAgB,CAAC,MAAgC;IACxD,MAAM,QAAQ,GAAG,GAAG,MAAM,CAAC,GAAG,IAAI,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;IACpE,MAAM,MAAM,GAAG,kBAAkB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAChD,IAAI,MAAM;QA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M,MAAM,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC,QAAQ,CAAC,CAAC;IAClD,IAAI,MAAM,EAAE,CAAC;QACX,MAAM,MAAM,GAAG,IAAA,6BAAiB,EAAC,MAAM,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC;QACzD,OAAO,QAAQ,CAAC,QAAQ,EAAE,KAAK,EAAE;YAC/B,GAAG,EAAE,MAAM,CAAC,GAAG;YACf,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,MAAM;SACP,CAAC,CAAC;IACL,CAAC;IACD,OAAO,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;AACnC,CAAC;AAED,8EAA8E;AAC9E,+EAA+E;AAC/E,sDAAsD;AACtD,MAAM,uBAAuB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC5C,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,aAAa,EAAE,KAAc,EAAE,CAAC;CACzD,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,SAAgB,kBAAkB,CAChC,QAAgB,EAChB,GAAkB;IAElB,MAAM,SAAS,GAAG,GAAG,IAAI,QAAQ,CAAC;IAClC,OAAO,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,uBAAuB,CAAC,CAAC,CAAC,SAAS,CAAC;AACtE,CAAC;AAED;;;;GAIG;AACH,SAAgB,2BAA2B,CACzC,MAAqB,EACrB,QAAgB;IAEhB,MAAM,MAAM,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC,QAAQ,CAAC,CAAC;IAClD,OAAO,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;AACnD,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model-specific prompt optimization profiles.
|
|
3
|
+
*
|
|
4
|
+
* Each provider + model family has a {@link ModelProfile} that adjusts how a user
|
|
5
|
+
* message is wrapped and what short advisory block is appended to the system
|
|
6
|
+
* prompt. Profiles are resolved once per turn and applied deterministically —
|
|
7
|
+
* no extra LLM call. Cache-safe: the system-prompt suffix depends only on the
|
|
8
|
+
* selected model, not on the user's input, so the KV-cache prefix stays stable
|
|
9
|
+
* across a session with a fixed model.
|
|
10
|
+
*/
|
|
11
|
+
/** Static per-model settings applied at the agent-loop boundary. */
|
|
12
|
+
export interface ModelProfile {
|
|
13
|
+
/** Stable identifier — useful in logs and tests. */
|
|
14
|
+
readonly family: string;
|
|
15
|
+
/** Wraps the raw user input. Applied before the timestamp prefix is added. */
|
|
16
|
+
wrapUserMessage(message: string): string;
|
|
17
|
+
/** Short advisory block appended to the system prompt. Empty string = no-op. */
|
|
18
|
+
readonly systemSuffix: string;
|
|
19
|
+
/**
|
|
20
|
+
* Short per-family style hint injected into the prompt-rewriter's system
|
|
21
|
+
* prompt (see src/prompt-rewriter.ts). Tells the rewriter what structural
|
|
22
|
+
* formatting this downstream model responds best to.
|
|
23
|
+
*/
|
|
24
|
+
readonly rewriterHint: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Resolves the {@link ModelProfile} for a provider + model pair.
|
|
28
|
+
*
|
|
29
|
+
* Matching is first-match-wins and pattern-based so new models in an existing
|
|
30
|
+
* family pick up the right profile automatically. Unknown combinations fall
|
|
31
|
+
* back to a conservative passthrough profile.
|
|
32
|
+
*
|
|
33
|
+
* For custom providers (user-defined endpoints that wrap an installed AI-SDK)
|
|
34
|
+
* pass the wrapped SDK family via `sdk` so the model picks up family-specific
|
|
35
|
+
* prompt tuning regardless of the registered provider name.
|
|
36
|
+
*/
|
|
37
|
+
export declare function getModelProfile(provider: string, model: string, sdk?: 'anthropic' | 'openai' | 'xai'): ModelProfile;
|