@nestbox-ai/cli 1.0.64 → 1.0.66

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 CHANGED
@@ -52,7 +52,7 @@ Options:
52
52
  - [`document`](#document) - Manage Nestbox documents and collections
53
53
  - [`image`](#image) - Manage Nestbox images
54
54
  - [`doc-proc`](#doc-proc) - Document processing pipeline management
55
- - [`generate`](#generate) - AI-assisted configuration and project generation
55
+ - [`generate`](#generate) - AI-assisted configuration generation (Anthropic or OpenAI)
56
56
 
57
57
  ---
58
58
 
@@ -916,7 +916,7 @@ nestbox doc-proc health [options]
916
916
 
917
917
  ### `generate`
918
918
 
919
- AI-assisted generation of configuration files and project scaffolds. Uses Claude to generate validated YAML configurations from plain-English instruction files.
919
+ AI-assisted generation of configuration files and project scaffolds. Uses an AI agent (Anthropic Claude or OpenAI GPT, your choice) to produce validated YAML configurations from plain-English instruction files. The agent writes, validates against the schema, and iterates automatically until the output is valid.
920
920
 
921
921
  ---
922
922
 
@@ -950,36 +950,47 @@ nestbox generate project my-chatbot --lang js --template chatbot
950
950
 
951
951
  ### `generate doc-proc`
952
952
 
953
- Generate a document processing pipeline configuration (`config.yaml` and `eval.yaml`) from a plain-English instructions file using Claude AI.
953
+ Generate a document processing pipeline configuration (`config.yaml` and `eval.yaml`) from a plain-English instructions file using AI.
954
954
 
955
- The agent reads your instructions, writes both files, validates each against their schemas, and iterates automatically until both pass validation.
955
+ The agent reads your instructions, writes both files, validates each against their schemas, and iterates automatically until both pass validation. Supports **Anthropic Claude** and **OpenAI GPT** — provide one API key to select the provider.
956
956
 
957
957
  ```bash
958
- nestbox generate doc-proc --file <path> --output <dir> --anthropicApiKey <key> [options]
958
+ nestbox generate doc-proc --file <path> --output <dir> [--anthropicApiKey <key> | --openAiApiKey <key>] [options]
959
959
  ```
960
960
 
961
961
  **Required options:**
962
962
  - `-f, --file <path>` - Path to a Markdown file describing what the pipeline should do
963
963
  - `-o, --output <dir>` - Output directory where `config.yaml` and `eval.yaml` will be written
964
- - `--anthropicApiKey <key>` - Anthropic API key (or set `ANTHROPIC_API_KEY` env var)
964
+
965
+ **API key (one required):**
966
+ - `--anthropicApiKey <key>` - Use Claude (Anthropic). Also reads `ANTHROPIC_API_KEY` env var
967
+ - `--openAiApiKey <key>` - Use GPT (OpenAI). Also reads `OPENAI_API_KEY` env var
968
+
969
+ When both are provided, Anthropic takes precedence.
965
970
 
966
971
  **Optional options:**
967
- - `--model <model>` - Claude model ID (default: `claude-sonnet-4-6`)
972
+ - `--model <model>` - Model ID. Defaults to `claude-sonnet-4-6` (Anthropic) or `gpt-4o` (OpenAI)
968
973
  - `--maxIterations <n>` - Maximum agent iterations before giving up (default: `8`)
969
974
 
970
975
  **Output files:**
971
976
  - `config.yaml` — document processing pipeline configuration
972
977
  - `eval.yaml` — evaluation test cases for the pipeline
973
978
 
974
- **Example:**
979
+ **Examples:**
975
980
  ```bash
976
- # Using a flag for the API key
981
+ # Anthropic Claude
977
982
  nestbox generate doc-proc \
978
983
  --file ./instructions.md \
979
984
  --output ./pipeline \
980
985
  --anthropicApiKey sk-ant-...
981
986
 
982
- # Using the environment variable
987
+ # OpenAI GPT
988
+ nestbox generate doc-proc \
989
+ --file ./instructions.md \
990
+ --output ./pipeline \
991
+ --openAiApiKey sk-...
992
+
993
+ # Via environment variables
983
994
  export ANTHROPIC_API_KEY=sk-ant-...
984
995
  nestbox generate doc-proc --file ./instructions.md --output ./pipeline
985
996
  ```
@@ -1001,32 +1012,48 @@ Eval test cases:
1001
1012
 
1002
1013
  ### `generate report-composer`
1003
1014
 
1004
- Generate a GraphRAG report composer configuration (`report.yaml`) from a plain-English instructions file using Claude AI.
1015
+ Generate a GraphRAG report composer configuration (`report.yaml`) from a plain-English instructions file using AI.
1005
1016
 
1006
- The agent reads your instructions, writes the report configuration, validates it against the schema (v2.2), and iterates automatically until it passes — it will not finish until the file is valid.
1017
+ The agent reads your instructions, writes the report configuration, validates it against the schema (v2.2), and iterates automatically until it passes — it will not finish until the file is valid. Supports **Anthropic Claude** and **OpenAI GPT** — provide one API key to select the provider.
1007
1018
 
1008
1019
  ```bash
1009
- nestbox generate report-composer --file <path> --output <dir> --anthropicApiKey <key> [options]
1020
+ nestbox generate report-composer --file <path> --output <dir> [--anthropicApiKey <key> | --openAiApiKey <key>] [options]
1010
1021
  ```
1011
1022
 
1012
1023
  **Required options:**
1013
1024
  - `-f, --file <path>` - Path to a Markdown file describing the report to generate
1014
1025
  - `-o, --output <dir>` - Output directory where `report.yaml` will be written
1015
- - `--anthropicApiKey <key>` - Anthropic API key (or set `ANTHROPIC_API_KEY` env var)
1026
+
1027
+ **API key (one required):**
1028
+ - `--anthropicApiKey <key>` - Use Claude (Anthropic). Also reads `ANTHROPIC_API_KEY` env var
1029
+ - `--openAiApiKey <key>` - Use GPT (OpenAI). Also reads `OPENAI_API_KEY` env var
1030
+
1031
+ When both are provided, Anthropic takes precedence.
1016
1032
 
1017
1033
  **Optional options:**
1018
- - `--model <model>` - Claude model ID (default: `claude-sonnet-4-6`)
1034
+ - `--model <model>` - Model ID. Defaults to `claude-sonnet-4-6` (Anthropic) or `gpt-4o` (OpenAI)
1019
1035
  - `--maxIterations <n>` - Maximum agent iterations before giving up (default: `5`)
1020
1036
 
1021
1037
  **Output files:**
1022
1038
  - `report.yaml` — report composer configuration (schema version 2.2)
1023
1039
 
1024
- **Example:**
1040
+ **Examples:**
1025
1041
  ```bash
1042
+ # Anthropic Claude
1026
1043
  nestbox generate report-composer \
1027
1044
  --file ./report-instructions.md \
1028
1045
  --output ~/Downloads/my-report \
1029
1046
  --anthropicApiKey sk-ant-...
1047
+
1048
+ # OpenAI GPT
1049
+ nestbox generate report-composer \
1050
+ --file ./report-instructions.md \
1051
+ --output ~/Downloads/my-report \
1052
+ --openAiApiKey sk-...
1053
+
1054
+ # Via environment variable
1055
+ export OPENAI_API_KEY=sk-...
1056
+ nestbox generate report-composer --file ./report-instructions.md --output ~/Downloads/my-report
1030
1057
  ```
1031
1058
 
1032
1059
  **Example instructions file (`report-instructions.md`):**
@@ -0,0 +1,21 @@
1
+ export interface DocProcAgentOptions {
2
+ /** Full instruction text (from the instructions file) */
3
+ instructions: string;
4
+ /** Anthropic API key */
5
+ anthropicApiKey: string;
6
+ /** Claude model ID, e.g. "claude-sonnet-4-6" */
7
+ model?: string;
8
+ /** Maximum agentic iterations before giving up */
9
+ maxIterations?: number;
10
+ /** Called on each status update (for spinner / logging) */
11
+ onProgress?: (message: string) => void;
12
+ }
13
+ export interface DocProcAgentResult {
14
+ configYaml: string;
15
+ evalYaml: string;
16
+ iterations: number;
17
+ configValid: boolean;
18
+ evalValid: boolean;
19
+ }
20
+ export declare const DEFAULT_MODEL = "claude-sonnet-4-6";
21
+ export declare function runDocProcAgent(options: DocProcAgentOptions): Promise<DocProcAgentResult>;
@@ -0,0 +1,225 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.DEFAULT_MODEL = void 0;
16
+ exports.runDocProcAgent = runDocProcAgent;
17
+ const sdk_1 = __importDefault(require("@anthropic-ai/sdk"));
18
+ const fs_1 = __importDefault(require("fs"));
19
+ const path_1 = __importDefault(require("path"));
20
+ const js_yaml_1 = __importDefault(require("js-yaml"));
21
+ const ajv_1 = __importDefault(require("ajv"));
22
+ // ─── Constants ────────────────────────────────────────────────────────────────
23
+ const AGENTS_DIR = __dirname;
24
+ exports.DEFAULT_MODEL = 'claude-sonnet-4-6';
25
+ const DEFAULT_MAX_ITERATIONS = 8;
26
+ // ─── Helpers ─────────────────────────────────────────────────────────────────
27
+ function readLocalFile(filename) {
28
+ return fs_1.default.readFileSync(path_1.default.join(AGENTS_DIR, filename), 'utf8');
29
+ }
30
+ function validateYaml(content, schemaContent) {
31
+ var _a;
32
+ // Replace ${ENV_VAR} references with a plain string so YAML parses cleanly
33
+ // and AJV treats them as valid string values.
34
+ const preprocessed = content.replace(/\$\{[^}]+\}/g, 'env-var-placeholder');
35
+ let data;
36
+ try {
37
+ data = js_yaml_1.default.load(preprocessed);
38
+ }
39
+ catch (e) {
40
+ return { valid: false, errors: [`YAML parse error: ${e.message}`] };
41
+ }
42
+ let schema;
43
+ try {
44
+ schema = js_yaml_1.default.load(schemaContent);
45
+ }
46
+ catch (e) {
47
+ return { valid: false, errors: [`Schema parse error: ${e.message}`] };
48
+ }
49
+ const ajv = new ajv_1.default({ strict: false, allErrors: true });
50
+ // Suppress "unknown format 'uri' ignored" console warnings from AJV
51
+ ajv.addFormat('uri', () => true);
52
+ const validate = ajv.compile(schema);
53
+ const ok = validate(data);
54
+ if (ok)
55
+ return { valid: true, errors: [] };
56
+ const errors = ((_a = validate.errors) !== null && _a !== void 0 ? _a : []).map((err) => {
57
+ const loc = err.instancePath || '(root)';
58
+ return `[${loc}] ${err.message}`;
59
+ });
60
+ return { valid: false, errors };
61
+ }
62
+ // ─── System Prompt ────────────────────────────────────────────────────────────
63
+ function buildSystemPrompt() {
64
+ const systemPrompt = readLocalFile('SYSTEM_PROMPT.md');
65
+ const configGuide = readLocalFile('CONFIG_GUIDE.md');
66
+ const evalGuide = readLocalFile('EVAL_GUIDE.md');
67
+ return `${systemPrompt}\n\n---\n\n${configGuide}\n\n---\n\n${evalGuide}`;
68
+ }
69
+ // ─── Tool Definitions ─────────────────────────────────────────────────────────
70
+ const TOOLS = [
71
+ {
72
+ name: 'write_and_validate_config',
73
+ description: 'Write the config.yaml content and validate it against the schema. Returns "VALID" on success or a list of validation errors to fix.',
74
+ input_schema: {
75
+ type: 'object',
76
+ properties: {
77
+ yaml_content: {
78
+ type: 'string',
79
+ description: 'The complete YAML content for config.yaml',
80
+ },
81
+ },
82
+ required: ['yaml_content'],
83
+ },
84
+ },
85
+ {
86
+ name: 'write_and_validate_eval',
87
+ description: 'Write the eval.yaml content and validate it against the schema. Returns "VALID" on success or a list of validation errors to fix.',
88
+ input_schema: {
89
+ type: 'object',
90
+ properties: {
91
+ yaml_content: {
92
+ type: 'string',
93
+ description: 'The complete YAML content for eval.yaml',
94
+ },
95
+ },
96
+ required: ['yaml_content'],
97
+ },
98
+ },
99
+ {
100
+ name: 'finish',
101
+ description: 'Signal that both files are complete and valid. Call this only after both write_and_validate_config and write_and_validate_eval have returned "VALID".',
102
+ input_schema: {
103
+ type: 'object',
104
+ properties: {
105
+ summary: {
106
+ type: 'string',
107
+ description: 'Brief summary of what was generated and why key choices were made',
108
+ },
109
+ },
110
+ required: ['summary'],
111
+ },
112
+ },
113
+ ];
114
+ // ─── Agent ────────────────────────────────────────────────────────────────────
115
+ function runDocProcAgent(options) {
116
+ return __awaiter(this, void 0, void 0, function* () {
117
+ const { instructions, anthropicApiKey, model = exports.DEFAULT_MODEL, maxIterations = DEFAULT_MAX_ITERATIONS, onProgress = () => { }, } = options;
118
+ const configSchema = readLocalFile('config.schema.yaml');
119
+ const evalSchema = readLocalFile('eval-test-cases.schema.yaml');
120
+ const client = new sdk_1.default({ apiKey: anthropicApiKey });
121
+ let latestConfig = '';
122
+ let latestEval = '';
123
+ let configValid = false;
124
+ let evalValid = false;
125
+ let finished = false;
126
+ let iteration = 0;
127
+ function executeTool(name, input) {
128
+ var _a, _b;
129
+ if (name === 'write_and_validate_config') {
130
+ const content = (_a = input.yaml_content) !== null && _a !== void 0 ? _a : '';
131
+ latestConfig = content;
132
+ const result = validateYaml(content, configSchema);
133
+ configValid = result.valid;
134
+ if (result.valid)
135
+ return 'VALID';
136
+ return `VALIDATION ERRORS — fix all of these before calling again:\n${result.errors.map((e) => ` • ${e}`).join('\n')}`;
137
+ }
138
+ if (name === 'write_and_validate_eval') {
139
+ const content = (_b = input.yaml_content) !== null && _b !== void 0 ? _b : '';
140
+ latestEval = content;
141
+ const result = validateYaml(content, evalSchema);
142
+ evalValid = result.valid;
143
+ if (result.valid)
144
+ return 'VALID';
145
+ return `VALIDATION ERRORS — fix all of these before calling again:\n${result.errors.map((e) => ` • ${e}`).join('\n')}`;
146
+ }
147
+ if (name === 'finish') {
148
+ finished = true;
149
+ return 'Done.';
150
+ }
151
+ return `Unknown tool: ${name}`;
152
+ }
153
+ // Build the system prompt once and mark it for caching.
154
+ // On iteration 1 the prompt is written to the cache (normal price).
155
+ // On iterations 2+ the large system prompt is read from cache at
156
+ // 10% of the normal input token price.
157
+ const systemPromptText = buildSystemPrompt();
158
+ const systemPrompt = [
159
+ {
160
+ type: 'text',
161
+ text: systemPromptText,
162
+ cache_control: { type: 'ephemeral' },
163
+ },
164
+ ];
165
+ const messages = [
166
+ {
167
+ role: 'user',
168
+ content: `Here are the instructions for the pipeline you need to configure:\n\n${instructions}\n\nGenerate the config.yaml and eval.yaml files now. Use the tools to write and validate them.`,
169
+ },
170
+ ];
171
+ onProgress('Starting agent...');
172
+ while (iteration < maxIterations && !finished) {
173
+ iteration++;
174
+ onProgress(`Iteration ${iteration}/${maxIterations} — calling Claude...`);
175
+ const response = yield client.messages.create({
176
+ model,
177
+ max_tokens: 8096,
178
+ system: systemPrompt,
179
+ tools: TOOLS,
180
+ // Force Claude to call a tool every turn — prevents it from
181
+ // replying with plain text and exiting the loop prematurely.
182
+ tool_choice: { type: 'any' },
183
+ messages,
184
+ });
185
+ // Append assistant turn
186
+ messages.push({ role: 'assistant', content: response.content });
187
+ if (response.stop_reason !== 'tool_use') {
188
+ onProgress(`Agent stopped unexpectedly: ${response.stop_reason}`);
189
+ break;
190
+ }
191
+ // Process all tool calls and collect results
192
+ const toolResults = [];
193
+ for (const block of response.content) {
194
+ if (block.type !== 'tool_use')
195
+ continue;
196
+ onProgress(` → tool: ${block.name}`);
197
+ const result = executeTool(block.name, block.input);
198
+ onProgress(` ${result.startsWith('VALID') ? '✓ valid' : result.split('\n')[0]}`);
199
+ toolResults.push({
200
+ type: 'tool_result',
201
+ tool_use_id: block.id,
202
+ content: result,
203
+ });
204
+ if (finished)
205
+ break;
206
+ }
207
+ if (toolResults.length > 0) {
208
+ messages.push({ role: 'user', content: toolResults });
209
+ }
210
+ if (finished)
211
+ break;
212
+ }
213
+ if (iteration >= maxIterations && !finished) {
214
+ onProgress(`Warning: reached max iterations (${maxIterations}) without finishing.`);
215
+ }
216
+ return {
217
+ configYaml: latestConfig,
218
+ evalYaml: latestEval,
219
+ iterations: iteration,
220
+ configValid,
221
+ evalValid,
222
+ };
223
+ });
224
+ }
225
+ //# sourceMappingURL=anthropic.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../../src/agents/docProc/anthropic.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AA8IA,0CAkIC;AAhRD,4DAA0C;AAC1C,4CAAoB;AACpB,gDAAwB;AACxB,sDAA2B;AAC3B,8CAAsB;AA8BtB,iFAAiF;AAEjF,MAAM,UAAU,GAAG,SAAS,CAAC;AAChB,QAAA,aAAa,GAAG,mBAAmB,CAAC;AACjD,MAAM,sBAAsB,GAAG,CAAC,CAAC;AAEjC,gFAAgF;AAEhF,SAAS,aAAa,CAAC,QAAgB;IACrC,OAAO,YAAE,CAAC,YAAY,CAAC,cAAI,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,CAAC;AAClE,CAAC;AAED,SAAS,YAAY,CAAC,OAAe,EAAE,aAAqB;;IAC1D,2EAA2E;IAC3E,8CAA8C;IAC9C,MAAM,YAAY,GAAG,OAAO,CAAC,OA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AAE,MAAM;QACtB,CAAC;QAED,IAAI,SAAS,IAAI,aAAa,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC5C,UAAU,CAAC,oCAAoC,aAAa,sBAAsB,CAAC,CAAC;QACtF,CAAC;QAED,OAAO;YACL,UAAU,EAAE,YAAY;YACxB,QAAQ,EAAE,UAAU;YACpB,UAAU,EAAE,SAAS;YACrB,WAAW;YACX,SAAS;SACV,CAAC;IACJ,CAAC;CAAA"}
@@ -1,20 +1,2 @@
1
- export interface DocProcAgentOptions {
2
- /** Full instruction text (from the instructions file) */
3
- instructions: string;
4
- /** Anthropic API key */
5
- anthropicApiKey: string;
6
- /** Claude model ID, e.g. "claude-opus-4-6" */
7
- model?: string;
8
- /** Maximum agentic iterations before giving up */
9
- maxIterations?: number;
10
- /** Called on each status update (for spinner / logging) */
11
- onProgress?: (message: string) => void;
12
- }
13
- export interface DocProcAgentResult {
14
- configYaml: string;
15
- evalYaml: string;
16
- iterations: number;
17
- configValid: boolean;
18
- evalValid: boolean;
19
- }
20
- export declare function runDocProcAgent(options: DocProcAgentOptions): Promise<DocProcAgentResult>;
1
+ export { runDocProcAgent, DocProcAgentOptions, DocProcAgentResult, DEFAULT_MODEL as ANTHROPIC_DEFAULT_MODEL } from './anthropic';
2
+ export { runDocProcAgentWithOpenAI, DocProcOpenAIAgentOptions, DEFAULT_MODEL as OPENAI_DEFAULT_MODEL } from './openai';
@@ -1,226 +1,10 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
2
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.runDocProcAgent = runDocProcAgent;
16
- const sdk_1 = __importDefault(require("@anthropic-ai/sdk"));
17
- const fs_1 = __importDefault(require("fs"));
18
- const path_1 = __importDefault(require("path"));
19
- const js_yaml_1 = __importDefault(require("js-yaml"));
20
- const ajv_1 = __importDefault(require("ajv"));
21
- // ─── Constants ────────────────────────────────────────────────────────────────
22
- const AGENTS_DIR = __dirname;
23
- const DEFAULT_MODEL = 'claude-sonnet-4-6';
24
- const DEFAULT_MAX_ITERATIONS = 8;
25
- // ─── Helpers ─────────────────────────────────────────────────────────────────
26
- function readLocalFile(filename) {
27
- return fs_1.default.readFileSync(path_1.default.join(AGENTS_DIR, filename), 'utf8');
28
- }
29
- function validateYaml(content, schemaContent) {
30
- var _a;
31
- // Replace ${ENV_VAR} references with a plain string so YAML parses cleanly
32
- // and AJV treats them as valid string values.
33
- const preprocessed = content.replace(/\$\{[^}]+\}/g, 'env-var-placeholder');
34
- let data;
35
- try {
36
- data = js_yaml_1.default.load(preprocessed);
37
- }
38
- catch (e) {
39
- return { valid: false, errors: [`YAML parse error: ${e.message}`] };
40
- }
41
- let schema;
42
- try {
43
- schema = js_yaml_1.default.load(schemaContent);
44
- }
45
- catch (e) {
46
- return { valid: false, errors: [`Schema parse error: ${e.message}`] };
47
- }
48
- const ajv = new ajv_1.default({ strict: false, allErrors: true });
49
- // Suppress "unknown format 'uri' ignored" console warnings from AJV
50
- ajv.addFormat('uri', () => true);
51
- const validate = ajv.compile(schema);
52
- const ok = validate(data);
53
- if (ok)
54
- return { valid: true, errors: [] };
55
- const errors = ((_a = validate.errors) !== null && _a !== void 0 ? _a : []).map((err) => {
56
- const loc = err.instancePath || '(root)';
57
- return `[${loc}] ${err.message}`;
58
- });
59
- return { valid: false, errors };
60
- }
61
- // ─── System Prompt ────────────────────────────────────────────────────────────
62
- function buildSystemPrompt() {
63
- const systemPrompt = readLocalFile('SYSTEM_PROMPT.md');
64
- const configGuide = readLocalFile('CONFIG_GUIDE.md');
65
- const evalGuide = readLocalFile('EVAL_GUIDE.md');
66
- return `${systemPrompt}\n\n---\n\n${configGuide}\n\n---\n\n${evalGuide}`;
67
- }
68
- // ─── Tool Definitions ─────────────────────────────────────────────────────────
69
- const TOOLS = [
70
- {
71
- name: 'write_and_validate_config',
72
- description: 'Write the config.yaml content and validate it against the schema. Returns "VALID" on success or a list of validation errors to fix.',
73
- input_schema: {
74
- type: 'object',
75
- properties: {
76
- yaml_content: {
77
- type: 'string',
78
- description: 'The complete YAML content for config.yaml',
79
- },
80
- },
81
- required: ['yaml_content'],
82
- },
83
- },
84
- {
85
- name: 'write_and_validate_eval',
86
- description: 'Write the eval.yaml content and validate it against the schema. Returns "VALID" on success or a list of validation errors to fix.',
87
- input_schema: {
88
- type: 'object',
89
- properties: {
90
- yaml_content: {
91
- type: 'string',
92
- description: 'The complete YAML content for eval.yaml',
93
- },
94
- },
95
- required: ['yaml_content'],
96
- },
97
- },
98
- {
99
- name: 'finish',
100
- description: 'Signal that both files are complete and valid. Call this only after both write_and_validate_config and write_and_validate_eval have returned "VALID".',
101
- input_schema: {
102
- type: 'object',
103
- properties: {
104
- summary: {
105
- type: 'string',
106
- description: 'Brief summary of what was generated and why key choices were made',
107
- },
108
- },
109
- required: ['summary'],
110
- },
111
- },
112
- ];
113
- // ─── Agent ────────────────────────────────────────────────────────────────────
114
- function runDocProcAgent(options) {
115
- return __awaiter(this, void 0, void 0, function* () {
116
- const { instructions, anthropicApiKey, model = DEFAULT_MODEL, maxIterations = DEFAULT_MAX_ITERATIONS, onProgress = () => { }, } = options;
117
- const configSchema = readLocalFile('config.schema.yaml');
118
- const evalSchema = readLocalFile('eval-test-cases.schema.yaml');
119
- const client = new sdk_1.default({ apiKey: anthropicApiKey });
120
- // Mutable state updated by tool calls
121
- let latestConfig = '';
122
- let latestEval = '';
123
- let configValid = false;
124
- let evalValid = false;
125
- let finished = false;
126
- let iteration = 0;
127
- // Execute a tool call and return the result string
128
- function executeTool(name, input) {
129
- var _a, _b;
130
- if (name === 'write_and_validate_config') {
131
- const content = (_a = input.yaml_content) !== null && _a !== void 0 ? _a : '';
132
- latestConfig = content;
133
- const result = validateYaml(content, configSchema);
134
- configValid = result.valid;
135
- if (result.valid)
136
- return 'VALID';
137
- return `VALIDATION ERRORS — fix all of these before calling again:\n${result.errors.map((e) => ` • ${e}`).join('\n')}`;
138
- }
139
- if (name === 'write_and_validate_eval') {
140
- const content = (_b = input.yaml_content) !== null && _b !== void 0 ? _b : '';
141
- latestEval = content;
142
- const result = validateYaml(content, evalSchema);
143
- evalValid = result.valid;
144
- if (result.valid)
145
- return 'VALID';
146
- return `VALIDATION ERRORS — fix all of these before calling again:\n${result.errors.map((e) => ` • ${e}`).join('\n')}`;
147
- }
148
- if (name === 'finish') {
149
- finished = true;
150
- return 'Done.';
151
- }
152
- return `Unknown tool: ${name}`;
153
- }
154
- // Build the system prompt once and mark it for caching.
155
- // On iteration 1 the prompt is written to the cache (normal price).
156
- // On iterations 2+ the 20k-token system prompt is read from cache at
157
- // 10% of the normal input token price — the biggest cost lever here.
158
- const systemPromptText = buildSystemPrompt();
159
- const systemPrompt = [
160
- {
161
- type: 'text',
162
- text: systemPromptText,
163
- cache_control: { type: 'ephemeral' },
164
- },
165
- ];
166
- const messages = [
167
- {
168
- role: 'user',
169
- content: `Here are the instructions for the pipeline you need to configure:\n\n${instructions}\n\nGenerate the config.yaml and eval.yaml files now. Use the tools to write and validate them.`,
170
- },
171
- ];
172
- onProgress('Starting agent...');
173
- while (iteration < maxIterations && !finished) {
174
- iteration++;
175
- onProgress(`Iteration ${iteration}/${maxIterations} — calling Claude...`);
176
- const response = yield client.messages.create({
177
- model,
178
- max_tokens: 8096,
179
- system: systemPrompt,
180
- tools: TOOLS,
181
- // Force Claude to call a tool every turn — prevents it from
182
- // replying with plain text and exiting the loop prematurely.
183
- tool_choice: { type: 'any' },
184
- messages,
185
- });
186
- // Append assistant turn
187
- messages.push({ role: 'assistant', content: response.content });
188
- if (response.stop_reason !== 'tool_use') {
189
- onProgress(`Agent stopped unexpectedly: ${response.stop_reason}`);
190
- break;
191
- }
192
- // Process all tool calls and collect results
193
- const toolResults = [];
194
- for (const block of response.content) {
195
- if (block.type !== 'tool_use')
196
- continue;
197
- onProgress(` → tool: ${block.name}`);
198
- const result = executeTool(block.name, block.input);
199
- onProgress(` ${result.startsWith('VALID') ? '✓ valid' : result.split('\n')[0]}`);
200
- toolResults.push({
201
- type: 'tool_result',
202
- tool_use_id: block.id,
203
- content: result,
204
- });
205
- if (finished)
206
- break;
207
- }
208
- if (toolResults.length > 0) {
209
- messages.push({ role: 'user', content: toolResults });
210
- }
211
- if (finished)
212
- break;
213
- }
214
- if (iteration >= maxIterations && !finished) {
215
- onProgress(`Warning: reached max iterations (${maxIterations}) without finishing.`);
216
- }
217
- return {
218
- configYaml: latestConfig,
219
- evalYaml: latestEval,
220
- iterations: iteration,
221
- configValid,
222
- evalValid,
223
- };
224
- });
225
- }
3
+ exports.OPENAI_DEFAULT_MODEL = exports.runDocProcAgentWithOpenAI = exports.ANTHROPIC_DEFAULT_MODEL = exports.runDocProcAgent = void 0;
4
+ var anthropic_1 = require("./anthropic");
5
+ Object.defineProperty(exports, "runDocProcAgent", { enumerable: true, get: function () { return anthropic_1.runDocProcAgent; } });
6
+ Object.defineProperty(exports, "ANTHROPIC_DEFAULT_MODEL", { enumerable: true, get: function () { return anthropic_1.DEFAULT_MODEL; } });
7
+ var openai_1 = require("./openai");
8
+ Object.defineProperty(exports, "runDocProcAgentWithOpenAI", { enumerable: true, get: function () { return openai_1.runDocProcAgentWithOpenAI; } });
9
+ Object.defineProperty(exports, "OPENAI_DEFAULT_MODEL", { enumerable: true, get: function () { return openai_1.DEFAULT_MODEL; } });
226
10
  //# sourceMappingURL=index.js.map