@aid-framework/generator-ts-vercel 0.0.0 → 0.1.39
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/LICENSE +201 -0
- package/README.md +164 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/emit/agents.d.ts +62 -0
- package/dist/emit/agents.d.ts.map +1 -0
- package/dist/emit/agents.js +256 -0
- package/dist/emit/agents.js.map +1 -0
- package/dist/emit/business.d.ts +23 -0
- package/dist/emit/business.d.ts.map +1 -0
- package/dist/emit/business.js +414 -0
- package/dist/emit/business.js.map +1 -0
- package/dist/emit/control.d.ts +40 -0
- package/dist/emit/control.d.ts.map +1 -0
- package/dist/emit/control.js +108 -0
- package/dist/emit/control.js.map +1 -0
- package/dist/emit/file.d.ts +64 -0
- package/dist/emit/file.d.ts.map +1 -0
- package/dist/emit/file.js +80 -0
- package/dist/emit/file.js.map +1 -0
- package/dist/emit/guardrails.d.ts +45 -0
- package/dist/emit/guardrails.d.ts.map +1 -0
- package/dist/emit/guardrails.js +192 -0
- package/dist/emit/guardrails.js.map +1 -0
- package/dist/emit/infrastructure.d.ts +15 -0
- package/dist/emit/infrastructure.d.ts.map +1 -0
- package/dist/emit/infrastructure.js +238 -0
- package/dist/emit/infrastructure.js.map +1 -0
- package/dist/emit/pipelines.d.ts +46 -0
- package/dist/emit/pipelines.d.ts.map +1 -0
- package/dist/emit/pipelines.js +1015 -0
- package/dist/emit/pipelines.js.map +1 -0
- package/dist/emit/prompts.d.ts +14 -0
- package/dist/emit/prompts.d.ts.map +1 -0
- package/dist/emit/prompts.js +61 -0
- package/dist/emit/prompts.js.map +1 -0
- package/dist/emit/retrieval.d.ts +19 -0
- package/dist/emit/retrieval.d.ts.map +1 -0
- package/dist/emit/retrieval.js +206 -0
- package/dist/emit/retrieval.js.map +1 -0
- package/dist/emit/schemas.d.ts +22 -0
- package/dist/emit/schemas.d.ts.map +1 -0
- package/dist/emit/schemas.js +145 -0
- package/dist/emit/schemas.js.map +1 -0
- package/dist/emit/text.d.ts +86 -0
- package/dist/emit/text.d.ts.map +1 -0
- package/dist/emit/text.js +242 -0
- package/dist/emit/text.js.map +1 -0
- package/dist/emit/tools.d.ts +15 -0
- package/dist/emit/tools.d.ts.map +1 -0
- package/dist/emit/tools.js +225 -0
- package/dist/emit/tools.js.map +1 -0
- package/dist/errors.d.ts +12 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +16 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +47 -0
- package/dist/index.js.map +1 -0
- package/dist/manifest.d.ts +48 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/manifest.js +88 -0
- package/dist/manifest.js.map +1 -0
- package/dist/names.d.ts +57 -0
- package/dist/names.d.ts.map +1 -0
- package/dist/names.js +294 -0
- package/dist/names.js.map +1 -0
- package/dist/placeholders.d.ts +48 -0
- package/dist/placeholders.d.ts.map +1 -0
- package/dist/placeholders.js +114 -0
- package/dist/placeholders.js.map +1 -0
- package/dist/plan.d.ts +18 -0
- package/dist/plan.d.ts.map +1 -0
- package/dist/plan.js +81 -0
- package/dist/plan.js.map +1 -0
- package/dist/validate.d.ts +88 -0
- package/dist/validate.d.ts.map +1 -0
- package/dist/validate.js +790 -0
- package/dist/validate.js.map +1 -0
- package/package.json +43 -14
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `generated/evals/*` and `generated/business/*`.
|
|
3
|
+
*
|
|
4
|
+
* An eval module is generated, not constructed at run time: the dataset, the metrics and
|
|
5
|
+
* the gate thresholds are all IR inputs, so the harness a failure points at is reviewable
|
|
6
|
+
* in the diff that changed it.
|
|
7
|
+
*
|
|
8
|
+
* A business module is the opposite: generated exactly once and then owned by the
|
|
9
|
+
* application. `planRegeneration` never overwrites it, which is why the seed has to
|
|
10
|
+
* compile and fail loudly rather than compile and return a plausible lie.
|
|
11
|
+
*/
|
|
12
|
+
import { className, literal, propertyKey, toSnakeCase } from '../names.js';
|
|
13
|
+
import { business, businessToolPath, evalModulePath, generated, paths, } from './file.js';
|
|
14
|
+
import { arrayLiteral, exportStatement, fits, importStatement, moduleText, objectLiteral, seedText, sortStatements, } from './text.js';
|
|
15
|
+
function metricExpression(metric, indent = '') {
|
|
16
|
+
switch (metric.kind) {
|
|
17
|
+
case 'exact':
|
|
18
|
+
return `new ExactMatch({ name: ${literal('exact')} })`;
|
|
19
|
+
case 'contains':
|
|
20
|
+
return `new NormalizedContains({ name: ${literal('contains')} })`;
|
|
21
|
+
case 'json-schema':
|
|
22
|
+
return `new JsonSchemaValid({ name: ${literal('json-schema')} })`;
|
|
23
|
+
case 'assert': {
|
|
24
|
+
// The parsed predicate lives in a module-level `ASSERT_EXPR` constant, so it
|
|
25
|
+
// travels as data and the generated eval needs no parser of its own and cannot
|
|
26
|
+
// disagree with the one that validated the spec. Hoisting it also keeps the
|
|
27
|
+
// emission one short line whatever the expression's depth.
|
|
28
|
+
const entries = [
|
|
29
|
+
['name', literal('assert')],
|
|
30
|
+
['expr', 'ASSERT_EXPR'],
|
|
31
|
+
['message', literal(metric.message)],
|
|
32
|
+
];
|
|
33
|
+
const inline = `new AssertMetric(${objectLiteral(entries, '')})`;
|
|
34
|
+
// The declared message is prose of unbounded length, so the element is the one
|
|
35
|
+
// thing in `metrics()` that can exceed the width on its own; the object spreads
|
|
36
|
+
// over lines exactly as `biome` spreads it when that happens.
|
|
37
|
+
return fits(indent, inline) ? inline : `new AssertMetric(${objectLiteral(entries, indent)})`;
|
|
38
|
+
}
|
|
39
|
+
default:
|
|
40
|
+
return 'unsupportedMetric';
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* A JSON literal that breaks across lines when it does not fit.
|
|
45
|
+
*
|
|
46
|
+
* `literal` renders one line always, and a predicate AST nests three or four objects
|
|
47
|
+
* deep, so reusing it here would emit lines past the formatter's width. Rendered at
|
|
48
|
+
* indent `''` from a `const`, the continuation lines land exactly where `biome` puts
|
|
49
|
+
* them, which is what keeps the generated file format-clean in CI.
|
|
50
|
+
*/
|
|
51
|
+
function jsonLiteral(value, indent) {
|
|
52
|
+
if (Array.isArray(value)) {
|
|
53
|
+
return arrayLiteral(value.map((item) => jsonLiteral(item, `${indent} `)), indent);
|
|
54
|
+
}
|
|
55
|
+
if (value !== null && typeof value === 'object') {
|
|
56
|
+
const entries = Object.entries(value)
|
|
57
|
+
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
|
|
58
|
+
.map(([key, item]) => [propertyKey(key), jsonLiteral(item, `${indent} `)]);
|
|
59
|
+
return objectLiteral(entries, indent);
|
|
60
|
+
}
|
|
61
|
+
return literal(value);
|
|
62
|
+
}
|
|
63
|
+
/** The retriever a retrieval eval samples: the eval's own pipeline, else the only one. */
|
|
64
|
+
export function evalRetriever(ir, evalShape) {
|
|
65
|
+
if (evalShape.target.kind === 'pipeline') {
|
|
66
|
+
const pipeline = ir.pipelines.find((candidate) => candidate.id === evalShape.target.id);
|
|
67
|
+
const step = pipeline?.steps.find((candidate) => candidate.kind === 'retrieve');
|
|
68
|
+
if (step !== undefined && step.kind === 'retrieve')
|
|
69
|
+
return step.retriever;
|
|
70
|
+
}
|
|
71
|
+
return ir.retrievers.length === 1 ? ir.retrievers[0]?.id : undefined;
|
|
72
|
+
}
|
|
73
|
+
function loadDataset(evalShape) {
|
|
74
|
+
const uri = evalShape.dataset.uri;
|
|
75
|
+
if (uri === undefined) {
|
|
76
|
+
return [
|
|
77
|
+
' // The spec declares no dataset file, so the suite cannot be loaded from the',
|
|
78
|
+
' // repository. Supply cases with Dataset.fromRecords before running it.',
|
|
79
|
+
` throw new ConfigurationError(${literal(`eval ${evalShape.id} declares no dataset file`)});`,
|
|
80
|
+
];
|
|
81
|
+
}
|
|
82
|
+
return [` return Dataset.fromPath(new URL(${literal(`../../${uri}`)}, import.meta.url));`];
|
|
83
|
+
}
|
|
84
|
+
function datasetBody(evalShape) {
|
|
85
|
+
return [
|
|
86
|
+
'/**',
|
|
87
|
+
` * Load the dataset the \`${evalShape.id}\` eval declares.`,
|
|
88
|
+
' *',
|
|
89
|
+
' * Read lazily rather than at import time: the dataset is a file, and importing a',
|
|
90
|
+
' * module should not be able to throw because of the working directory.',
|
|
91
|
+
' */',
|
|
92
|
+
'export function dataset(): Dataset {',
|
|
93
|
+
...loadDataset(evalShape),
|
|
94
|
+
'}',
|
|
95
|
+
];
|
|
96
|
+
}
|
|
97
|
+
function gateBody(evalShape, metrics) {
|
|
98
|
+
const maxRegression = literal(evalShape.gate.maxRegression);
|
|
99
|
+
// A floor belongs to the metric it floors. An `assert` metric is only meaningful when
|
|
100
|
+
// every case passes, so it carries the declared floor and the runtime checks that floor
|
|
101
|
+
// before it looks at the regression delta -- a tolerance cannot excuse a false assertion.
|
|
102
|
+
const floor = evalShape.gate.minMean;
|
|
103
|
+
const extra = floor === undefined ? '' : ', minMean: floors[metric]';
|
|
104
|
+
const list = arrayLiteral(metrics.map((metric) => literal(metric)), ' ');
|
|
105
|
+
const inline = ` const thresholds = ${list}.map((metric) => new Threshold({ metric, maxRegression: ${maxRegression}${extra} }));`;
|
|
106
|
+
return [
|
|
107
|
+
'/**',
|
|
108
|
+
// A spec with no declared floor emits the prose it always emitted, so the shipped
|
|
109
|
+
// example stays byte for byte what it was.
|
|
110
|
+
...(floor === undefined
|
|
111
|
+
? [
|
|
112
|
+
' * The gate the spec asks for: one absolute-free threshold per emitted metric, each',
|
|
113
|
+
' * allowing the declared regression. `minMean` stays unset because the spec carries no',
|
|
114
|
+
' * floor, and a floor the spec did not ask for would fail a run for the wrong reason.',
|
|
115
|
+
]
|
|
116
|
+
: [
|
|
117
|
+
' * The gate the spec asks for: one threshold per emitted metric, each allowing the',
|
|
118
|
+
' * declared regression. `minMean` is set only for the metric the spec floored, and a',
|
|
119
|
+
' * floor the spec did not ask for would fail a run for the wrong reason.',
|
|
120
|
+
]),
|
|
121
|
+
' */',
|
|
122
|
+
'export function gate(): BaselineGate {',
|
|
123
|
+
...(floor === undefined
|
|
124
|
+
? []
|
|
125
|
+
: [` const floors: Record<string, number> = { assert: ${literal(floor)} };`]),
|
|
126
|
+
...(fits('', inline)
|
|
127
|
+
? [inline]
|
|
128
|
+
: [
|
|
129
|
+
` const thresholds = ${list}.map(`,
|
|
130
|
+
` (metric) => new Threshold({ metric, maxRegression: ${maxRegression}${extra} }),`,
|
|
131
|
+
' );',
|
|
132
|
+
]),
|
|
133
|
+
' return new BaselineGate(thresholds, { metrics: metrics() });',
|
|
134
|
+
'}',
|
|
135
|
+
];
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* The `@aid-framework/runtime` names a plain eval module needs: only the metrics the spec
|
|
139
|
+
* actually asks for, because the emitted module has no other way to use one.
|
|
140
|
+
*/
|
|
141
|
+
function plainEvalImports(evalShape, metrics) {
|
|
142
|
+
const names = metrics.map((metric) => metric.kind);
|
|
143
|
+
return [
|
|
144
|
+
...(names.includes('assert') ? [{ name: 'AssertMetric', type: false }] : []),
|
|
145
|
+
{ name: 'BaselineGate', type: false },
|
|
146
|
+
...(evalShape.dataset.uri === undefined ? [{ name: 'ConfigurationError', type: false }] : []),
|
|
147
|
+
{ name: 'Dataset', type: false },
|
|
148
|
+
...(names.includes('exact') ? [{ name: 'ExactMatch', type: false }] : []),
|
|
149
|
+
{ name: 'GatewayRunner', type: false },
|
|
150
|
+
...(names.includes('json-schema') ? [{ name: 'JsonSchemaValid', type: false }] : []),
|
|
151
|
+
...(names.includes('contains') ? [{ name: 'NormalizedContains', type: false }] : []),
|
|
152
|
+
{ name: 'Threshold', type: false },
|
|
153
|
+
{ name: 'runEvaluation', type: false },
|
|
154
|
+
{ name: 'EvalBaseline', type: true },
|
|
155
|
+
{ name: 'EvalRun', type: true },
|
|
156
|
+
{ name: 'GateResult', type: true },
|
|
157
|
+
{ name: 'Metric', type: true },
|
|
158
|
+
];
|
|
159
|
+
}
|
|
160
|
+
function plainEvalModule(evalShape) {
|
|
161
|
+
const metrics = evalShape.metrics.filter((metric) => metric.kind !== 'retrieval');
|
|
162
|
+
const names = metrics.map((metric) => metric.kind);
|
|
163
|
+
const asserted = metrics.find((metric) => metric.kind === 'assert');
|
|
164
|
+
const header = [
|
|
165
|
+
importStatement('@aid-framework/runtime', plainEvalImports(evalShape, metrics)),
|
|
166
|
+
importStatement('../gateway/index.js', [{ name: 'buildGateway', type: false }]),
|
|
167
|
+
].join('\n');
|
|
168
|
+
const body = [
|
|
169
|
+
...datasetBody(evalShape),
|
|
170
|
+
'',
|
|
171
|
+
...(asserted === undefined || asserted.kind !== 'assert'
|
|
172
|
+
? []
|
|
173
|
+
: [
|
|
174
|
+
'/**',
|
|
175
|
+
' * The asserted predicate. The IR parsed and checked it, so the generated eval',
|
|
176
|
+
' * carries it as data: no expression string is ever evaluated here.',
|
|
177
|
+
' */',
|
|
178
|
+
`const ASSERT_EXPR = ${jsonLiteral(asserted.expr, '')};`,
|
|
179
|
+
'',
|
|
180
|
+
]),
|
|
181
|
+
'/** The metrics the spec asks for, in declaration order. */',
|
|
182
|
+
'export function metrics(): readonly Metric[] {',
|
|
183
|
+
...(() => {
|
|
184
|
+
const items = metrics.map((metric) => metricExpression(metric, ' '));
|
|
185
|
+
const inline = ` return [${items.join(', ')}];`;
|
|
186
|
+
return fits('', inline)
|
|
187
|
+
? [inline]
|
|
188
|
+
: [' return [', ...items.map((item) => ` ${item},`), ' ];'];
|
|
189
|
+
})(),
|
|
190
|
+
'}',
|
|
191
|
+
'',
|
|
192
|
+
...gateBody(evalShape, names),
|
|
193
|
+
'',
|
|
194
|
+
'/** Sample the suite and return the run a baseline gate compares against. */',
|
|
195
|
+
'export async function sample(options: { readonly runs?: number } = {}): Promise<EvalRun> {',
|
|
196
|
+
' const gateway = buildGateway();',
|
|
197
|
+
` const runner = new GatewayRunner(gateway, ${literal('default')}, {});`,
|
|
198
|
+
' return await runEvaluation(dataset(), (entry) => runner.run(entry), metrics(), {',
|
|
199
|
+
` runs: options.runs ?? ${literal(evalShape.gate.samples)},`,
|
|
200
|
+
' });',
|
|
201
|
+
'}',
|
|
202
|
+
'',
|
|
203
|
+
'/** Decide whether a run regressed against its baseline. */',
|
|
204
|
+
'export function evaluate(run: EvalRun, baseline: EvalBaseline): GateResult {',
|
|
205
|
+
' return gate().evaluate(run, baseline);',
|
|
206
|
+
'}',
|
|
207
|
+
].join('\n');
|
|
208
|
+
return moduleText(header, body);
|
|
209
|
+
}
|
|
210
|
+
function retrievalEvalModule(ir, evalShape, metric) {
|
|
211
|
+
const retriever = evalRetriever(ir, evalShape);
|
|
212
|
+
const expectDocs = metric.kind === 'retrieval' ? [...metric.expectDocs] : [];
|
|
213
|
+
const k = metric.kind === 'retrieval' ? metric.k : 5;
|
|
214
|
+
const header = [
|
|
215
|
+
importStatement('@aid-framework/runtime', [
|
|
216
|
+
{ name: 'ConfigurationError', type: false },
|
|
217
|
+
{ name: 'Dataset', type: false },
|
|
218
|
+
{ name: 'RetrievalCase', type: false },
|
|
219
|
+
{ name: 'RetrievalGate', type: false },
|
|
220
|
+
{ name: 'RetrievalMetricSpec', type: false },
|
|
221
|
+
{ name: 'Threshold', type: false },
|
|
222
|
+
{ name: 'retrievalMetrics', type: false },
|
|
223
|
+
{ name: 'EvalBaseline', type: true },
|
|
224
|
+
{ name: 'EvalRun', type: true },
|
|
225
|
+
{ name: 'GateResult', type: true },
|
|
226
|
+
]),
|
|
227
|
+
importStatement('../retrieval/index.js', [{ name: 'buildRetrievers', type: false }]),
|
|
228
|
+
].join('\n');
|
|
229
|
+
const body = [
|
|
230
|
+
"// The expected documents and `k` are the IR's `retrieval` metric node, so every case",
|
|
231
|
+
'// in this dataset asks the same question of the same pages: the IR carries the',
|
|
232
|
+
'// expectation on the metric, not per case, and inventing a per-case split here would',
|
|
233
|
+
'// be an expectation no spec declared.',
|
|
234
|
+
`const EXPECT_DOCS: readonly string[] = ${arrayLiteral(expectDocs.map((doc) => literal(doc)), '')};`,
|
|
235
|
+
`const TOP_K = ${literal(k)};`,
|
|
236
|
+
`const RETRIEVER = ${literal(retriever ?? '')};`,
|
|
237
|
+
'',
|
|
238
|
+
...datasetBody(evalShape),
|
|
239
|
+
'',
|
|
240
|
+
'/** One ranked, cited result per case, scored by the metrics retrieval ships. */',
|
|
241
|
+
'export function cases(data: Dataset): readonly RetrievalCase[] {',
|
|
242
|
+
' const spec = new RetrievalMetricSpec({ expectDocs: [...EXPECT_DOCS], k: TOP_K });',
|
|
243
|
+
' return data.cases.map((entry) =>',
|
|
244
|
+
' RetrievalCase.fromSpec({ caseId: entry.id, query: entry.input, spec }),',
|
|
245
|
+
' );',
|
|
246
|
+
'}',
|
|
247
|
+
'',
|
|
248
|
+
'/**',
|
|
249
|
+
' * The retrieval gate. Thresholds come from the metrics the runtime produces rather',
|
|
250
|
+
' * than from names repeated here, so no threshold can name a metric that no longer',
|
|
251
|
+
' * exists.',
|
|
252
|
+
' */',
|
|
253
|
+
'export function gate(): RetrievalGate {',
|
|
254
|
+
` const maxRegression = ${literal(evalShape.gate.maxRegression)};`,
|
|
255
|
+
' const metrics = retrievalMetrics();',
|
|
256
|
+
...(() => {
|
|
257
|
+
const inline = ` const thresholds = metrics.map((metric) => new Threshold({ metric: metric.name, maxRegression }));`;
|
|
258
|
+
return fits('', inline)
|
|
259
|
+
? [inline]
|
|
260
|
+
: [
|
|
261
|
+
' const thresholds = metrics.map(',
|
|
262
|
+
' (metric) => new Threshold({ metric: metric.name, maxRegression }),',
|
|
263
|
+
' );',
|
|
264
|
+
];
|
|
265
|
+
})(),
|
|
266
|
+
' return new RetrievalGate(thresholds, { metrics });',
|
|
267
|
+
'}',
|
|
268
|
+
'',
|
|
269
|
+
'/** Sample the suite and return the run a baseline gate compares against. */',
|
|
270
|
+
'export async function sample(options: { readonly runs?: number } = {}): Promise<EvalRun> {',
|
|
271
|
+
' const retriever = buildRetrievers().get(RETRIEVER);',
|
|
272
|
+
' if (retriever === undefined) {',
|
|
273
|
+
` throw new ConfigurationError(\`retriever \${RETRIEVER} is not built\`);`,
|
|
274
|
+
' }',
|
|
275
|
+
' const data = dataset();',
|
|
276
|
+
' return await gate().sample(cases(data), retriever, {',
|
|
277
|
+
` runs: options.runs ?? ${literal(evalShape.gate.samples)},`,
|
|
278
|
+
' dataset: data.name,',
|
|
279
|
+
' datasetVersion: data.version,',
|
|
280
|
+
' });',
|
|
281
|
+
'}',
|
|
282
|
+
'',
|
|
283
|
+
'/** Decide whether a run regressed against its baseline. */',
|
|
284
|
+
'export function evaluate(run: EvalRun, baseline: EvalBaseline): GateResult {',
|
|
285
|
+
' return gate().evaluate(run, baseline);',
|
|
286
|
+
'}',
|
|
287
|
+
].join('\n');
|
|
288
|
+
return moduleText(header, body);
|
|
289
|
+
}
|
|
290
|
+
function evalModule(ir, evalShape) {
|
|
291
|
+
const retrieval = evalShape.metrics.find((metric) => metric.kind === 'retrieval');
|
|
292
|
+
if (retrieval !== undefined)
|
|
293
|
+
return retrievalEvalModule(ir, evalShape, retrieval);
|
|
294
|
+
return plainEvalModule(evalShape);
|
|
295
|
+
}
|
|
296
|
+
export function emitEvalModules(ir) {
|
|
297
|
+
return ir.evals.map((evalShape) => generated(evalModulePath(toSnakeCase(evalShape.id)), evalModule(ir, evalShape)));
|
|
298
|
+
}
|
|
299
|
+
export function emitEvalsIndex(ir) {
|
|
300
|
+
const lines = ir.evals.length === 0
|
|
301
|
+
? ['// This project declares no evals.']
|
|
302
|
+
: ir.evals.map((evalShape) => {
|
|
303
|
+
const pascal = className(evalShape.id);
|
|
304
|
+
const stem = toSnakeCase(evalShape.id);
|
|
305
|
+
return exportStatement(`./${stem}.js`, [
|
|
306
|
+
['dataset', `${camelId(evalShape.id)}Dataset`],
|
|
307
|
+
['evaluate', `evaluate${pascal}`],
|
|
308
|
+
['gate', `${camelId(evalShape.id)}Gate`],
|
|
309
|
+
['sample', `sample${pascal}`],
|
|
310
|
+
]);
|
|
311
|
+
});
|
|
312
|
+
return generated(paths.evalsIndex, moduleText(...lines));
|
|
313
|
+
}
|
|
314
|
+
function camelId(id) {
|
|
315
|
+
const pascal = className(id);
|
|
316
|
+
return `${pascal.charAt(0).toLowerCase()}${pascal.slice(1)}`;
|
|
317
|
+
}
|
|
318
|
+
function businessToolSeed(tool) {
|
|
319
|
+
const handler = `${className(tool.id)}Handler`;
|
|
320
|
+
const header = [
|
|
321
|
+
importStatement('@aid-framework/runtime', [{ name: 'ConfigurationError', type: false }]),
|
|
322
|
+
importStatement(`../../generated/contracts/${tool.id}.js`, [{ name: handler, type: true }]),
|
|
323
|
+
].join('\n');
|
|
324
|
+
const body = [
|
|
325
|
+
'/**',
|
|
326
|
+
` * The business implementation of \`${tool.id}\`.`,
|
|
327
|
+
' *',
|
|
328
|
+
' * Created once and never overwritten: edit this file freely. Replace the throw with',
|
|
329
|
+
' * the real lookup; the handler signature is the contract the pipeline calls through.',
|
|
330
|
+
' */',
|
|
331
|
+
`export const ${camelId(tool.id)}: ${handler} = async (context, request) => {`,
|
|
332
|
+
' void request;',
|
|
333
|
+
' throw new ConfigurationError(',
|
|
334
|
+
` \`\${context.name} has no business implementation yet: fill in ${paths.businessToolsIndex.replace('index.ts', `${tool.id}.ts`)}\`,`,
|
|
335
|
+
' );',
|
|
336
|
+
'};',
|
|
337
|
+
].join('\n');
|
|
338
|
+
return seedText(header, body);
|
|
339
|
+
}
|
|
340
|
+
export function emitBusinessToolSeeds(ir) {
|
|
341
|
+
return ir.tools.map((tool) => business(businessToolPath(tool.id), businessToolSeed(tool)));
|
|
342
|
+
}
|
|
343
|
+
export function emitBusinessToolsIndex(ir) {
|
|
344
|
+
const imports = [...ir.tools]
|
|
345
|
+
.sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0))
|
|
346
|
+
.map((tool) => importStatement(`./${tool.id}.js`, [{ name: camelId(tool.id), type: false }]));
|
|
347
|
+
const entries = ir.tools.map((tool) => ` ${propertyKey(tool.id)}: ${camelId(tool.id)},`);
|
|
348
|
+
return business(paths.businessToolsIndex, seedText(imports.join('\n'), [
|
|
349
|
+
'/**',
|
|
350
|
+
' * Every hand-written tool implementation, keyed by the IR tool id.',
|
|
351
|
+
' *',
|
|
352
|
+
' * The generated executor reads this map, so a new tool is added here and nowhere',
|
|
353
|
+
' * else. The `unknown` value type is deliberate: the generated adapter is what',
|
|
354
|
+
' * pins each entry to its declared handler type.',
|
|
355
|
+
' */',
|
|
356
|
+
'export const IMPLEMENTATIONS: Readonly<Record<string, unknown>> = {',
|
|
357
|
+
...entries,
|
|
358
|
+
'};',
|
|
359
|
+
].join('\n')));
|
|
360
|
+
}
|
|
361
|
+
export function emitBusinessPromptsIndex(ir) {
|
|
362
|
+
void ir;
|
|
363
|
+
return business(paths.businessPromptsIndex, seedText(`import type { PromptTemplate } from '@aid-framework/runtime';`, [
|
|
364
|
+
'/**',
|
|
365
|
+
' * Prompt overrides, layered over the generated templates at build time.',
|
|
366
|
+
' *',
|
|
367
|
+
' * Register a template with the same name and version as a generated one to replace',
|
|
368
|
+
' * its wording without touching generated code. Empty by default.',
|
|
369
|
+
' */',
|
|
370
|
+
'export const OVERRIDES: readonly PromptTemplate[] = [];',
|
|
371
|
+
].join('\n')));
|
|
372
|
+
}
|
|
373
|
+
export function emitBusinessIndex(ir) {
|
|
374
|
+
void ir;
|
|
375
|
+
return business(paths.businessIndex, seedText('// The hand-written tier: implementations, prompt overrides, and the rest.', sortStatements([
|
|
376
|
+
{
|
|
377
|
+
from: './prompts/index.js',
|
|
378
|
+
text: exportStatement('./prompts/index.js', [['OVERRIDES', 'OVERRIDES']]),
|
|
379
|
+
},
|
|
380
|
+
{
|
|
381
|
+
from: './tools/index.js',
|
|
382
|
+
text: exportStatement('./tools/index.js', [['IMPLEMENTATIONS', 'IMPLEMENTATIONS']]),
|
|
383
|
+
},
|
|
384
|
+
]).join('\n')));
|
|
385
|
+
}
|
|
386
|
+
export function emitGeneratedIndex(ir) {
|
|
387
|
+
void ir;
|
|
388
|
+
const statements = [
|
|
389
|
+
{ from: './deps.js', names: ['buildDeps', 'Deps', 'getDeps', 'setDeps'] },
|
|
390
|
+
{
|
|
391
|
+
from: './gateway/index.js',
|
|
392
|
+
names: ['ALIASES', 'FALLBACKS', 'buildGateway', 'defaultProviders'],
|
|
393
|
+
},
|
|
394
|
+
{ from: './observability.js', names: ['generatedCapabilities'] },
|
|
395
|
+
{ from: './pipelines/index.js', names: undefined },
|
|
396
|
+
{ from: './prompts/index.js', names: ['buildPrompts'] },
|
|
397
|
+
{ from: './requests.js', names: undefined },
|
|
398
|
+
{ from: './routes/index.js', names: undefined },
|
|
399
|
+
{ from: './schemas.js', names: undefined },
|
|
400
|
+
{ from: './tools/index.js', names: ['buildExecutor', 'buildTools'] },
|
|
401
|
+
];
|
|
402
|
+
const lines = [
|
|
403
|
+
'/** The generated surface of this application, as one import. */',
|
|
404
|
+
'',
|
|
405
|
+
...sortStatements(statements.map((statement) => ({
|
|
406
|
+
from: statement.from,
|
|
407
|
+
text: statement.names === undefined
|
|
408
|
+
? `export * from '${statement.from}';`
|
|
409
|
+
: exportStatement(statement.from, statement.names.map((name) => [name, name])),
|
|
410
|
+
}))),
|
|
411
|
+
];
|
|
412
|
+
return generated(paths.generatedIndex, moduleText(lines.join('\n')));
|
|
413
|
+
}
|
|
414
|
+
//# sourceMappingURL=business.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"business.js","sourceRoot":"","sources":["../../src/emit/business.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC3E,OAAO,EACL,QAAQ,EACR,gBAAgB,EAEhB,cAAc,EACd,SAAS,EACT,KAAK,GACN,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,YAAY,EAEZ,eAAe,EACf,IAAI,EACJ,eAAe,EACf,UAAU,EACV,aAAa,EACb,QAAQ,EACR,cAAc,GACf,MAAM,WAAW,CAA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CAAC,IAAI;YACpB,IAAI,EACF,SAAS,CAAC,KAAK,KAAK,SAAS;gBAC3B,CAAC,CAAC,kBAAkB,SAAS,CAAC,IAAI,IAAI;gBACtC,CAAC,CAAC,eAAe,CACb,SAAS,CAAC,IAAI,EACd,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,CAAU,CAAC,CACrD;SACR,CAAC,CAAC,CACJ;KACF,CAAC;IACF,OAAO,SAAS,CAAC,KAAK,CAAC,cAAc,EAAE,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACvE,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `generated/control.ts`.
|
|
3
|
+
*
|
|
4
|
+
* Emitted for every plan, because every emitted route seeds its pipeline from it: the
|
|
5
|
+
* values here are what a run starts from, and a route that skipped them would run
|
|
6
|
+
* differently from one that did. Only the composite steps depend on the two constants,
|
|
7
|
+
* but the seeding is uniform so there is one code path rather than two.
|
|
8
|
+
*
|
|
9
|
+
* The split matters and is not cosmetic. The runtime's `branch`/`parallel`/`map`/
|
|
10
|
+
* `reduce` take their concurrency limiter from the *context*, not from an option: each
|
|
11
|
+
* one calls `limiterFor(context, …)`, which reads `LIMITER_KEY` and refuses to run when
|
|
12
|
+
* it does not hold a `ConcurrencyLimiter`. So the cap is not something a step can pass
|
|
13
|
+
* down — it has to be seeded into the `PipelineContext` before the first step runs,
|
|
14
|
+
* which is why it lands here rather than in a step module. `deps.ts` cannot hold it
|
|
15
|
+
* either: `Deps` is what a step reaches for, and by the time a step runs the composite
|
|
16
|
+
* has already read the context.
|
|
17
|
+
*
|
|
18
|
+
* The principal is seeded for the same reason and one more: `branch`'s `when` is
|
|
19
|
+
* evaluated against the principal and nothing else, and an app with no auth layer has
|
|
20
|
+
* no other source for one. `Principal`'s defaults are the anonymous-but-authenticated
|
|
21
|
+
* caller, so `isAuthenticated()` is true and both role and scope sets are empty — a
|
|
22
|
+
* predicate is answered rather than left undefined.
|
|
23
|
+
*/
|
|
24
|
+
import type { IR } from '@aid-framework/ir';
|
|
25
|
+
import { type EmittedFile } from './file.js';
|
|
26
|
+
/**
|
|
27
|
+
* The smallest `concurrency` any declared deployment asks for.
|
|
28
|
+
*
|
|
29
|
+
* The spec layer refuses a composite step in a document that declares no
|
|
30
|
+
* `deployments.concurrency`, so a pipeline that reaches this emitter always has one to
|
|
31
|
+
* read. The *smallest* wins rather than the first or the largest: a deployment is a
|
|
32
|
+
* capacity promise, and a fan-out that drew from a larger one would run wider than the
|
|
33
|
+
* narrowest platform that hosts the same app.
|
|
34
|
+
*/
|
|
35
|
+
export declare function concurrencyLimit(ir: IR): number;
|
|
36
|
+
/** The module body. */
|
|
37
|
+
export declare function controlModule(ir: IR): string;
|
|
38
|
+
/** `generated/control.ts`. */
|
|
39
|
+
export declare function emitControl(ir: IR): EmittedFile;
|
|
40
|
+
//# sourceMappingURL=control.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"control.d.ts","sourceRoot":"","sources":["../../src/emit/control.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,KAAK,WAAW,EAAoB,MAAM,WAAW,CAAC;AAG/D;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,EAAE,GAAG,MAAM,CAK/C;AAED,uBAAuB;AACvB,wBAAgB,aAAa,CAAC,EAAE,EAAE,EAAE,GAAG,MAAM,CA6D5C;AAED,8BAA8B;AAC9B,wBAAgB,WAAW,CAAC,EAAE,EAAE,EAAE,GAAG,WAAW,CAE/C"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `generated/control.ts`.
|
|
3
|
+
*
|
|
4
|
+
* Emitted for every plan, because every emitted route seeds its pipeline from it: the
|
|
5
|
+
* values here are what a run starts from, and a route that skipped them would run
|
|
6
|
+
* differently from one that did. Only the composite steps depend on the two constants,
|
|
7
|
+
* but the seeding is uniform so there is one code path rather than two.
|
|
8
|
+
*
|
|
9
|
+
* The split matters and is not cosmetic. The runtime's `branch`/`parallel`/`map`/
|
|
10
|
+
* `reduce` take their concurrency limiter from the *context*, not from an option: each
|
|
11
|
+
* one calls `limiterFor(context, …)`, which reads `LIMITER_KEY` and refuses to run when
|
|
12
|
+
* it does not hold a `ConcurrencyLimiter`. So the cap is not something a step can pass
|
|
13
|
+
* down — it has to be seeded into the `PipelineContext` before the first step runs,
|
|
14
|
+
* which is why it lands here rather than in a step module. `deps.ts` cannot hold it
|
|
15
|
+
* either: `Deps` is what a step reaches for, and by the time a step runs the composite
|
|
16
|
+
* has already read the context.
|
|
17
|
+
*
|
|
18
|
+
* The principal is seeded for the same reason and one more: `branch`'s `when` is
|
|
19
|
+
* evaluated against the principal and nothing else, and an app with no auth layer has
|
|
20
|
+
* no other source for one. `Principal`'s defaults are the anonymous-but-authenticated
|
|
21
|
+
* caller, so `isAuthenticated()` is true and both role and scope sets are empty — a
|
|
22
|
+
* predicate is answered rather than left undefined.
|
|
23
|
+
*/
|
|
24
|
+
import { generated, paths } from './file.js';
|
|
25
|
+
import { importStatement, moduleText } from './text.js';
|
|
26
|
+
/**
|
|
27
|
+
* The smallest `concurrency` any declared deployment asks for.
|
|
28
|
+
*
|
|
29
|
+
* The spec layer refuses a composite step in a document that declares no
|
|
30
|
+
* `deployments.concurrency`, so a pipeline that reaches this emitter always has one to
|
|
31
|
+
* read. The *smallest* wins rather than the first or the largest: a deployment is a
|
|
32
|
+
* capacity promise, and a fan-out that drew from a larger one would run wider than the
|
|
33
|
+
* narrowest platform that hosts the same app.
|
|
34
|
+
*/
|
|
35
|
+
export function concurrencyLimit(ir) {
|
|
36
|
+
const declared = ir.deployments
|
|
37
|
+
.map((deployment) => deployment.concurrency)
|
|
38
|
+
.filter((value) => value !== undefined);
|
|
39
|
+
return declared.length === 0 ? 1 : Math.min(...declared);
|
|
40
|
+
}
|
|
41
|
+
/** The module body. */
|
|
42
|
+
export function controlModule(ir) {
|
|
43
|
+
const imports = importStatement('@aid-framework/runtime', [
|
|
44
|
+
{ name: 'ConcurrencyLimiter', type: false },
|
|
45
|
+
{ name: 'LIMITER_KEY', type: false },
|
|
46
|
+
{ name: 'PipelineContext', type: true },
|
|
47
|
+
{ name: 'PRINCIPAL_KEY', type: false },
|
|
48
|
+
{ name: 'Principal', type: false },
|
|
49
|
+
]);
|
|
50
|
+
const limit = [
|
|
51
|
+
'/**',
|
|
52
|
+
' * The smallest `concurrency` any deployment in this spec declares.',
|
|
53
|
+
' *',
|
|
54
|
+
' * Every composite step draws its fan-out from this one cap, so `parallel`, `map` and',
|
|
55
|
+
' * `reduce` cannot between them run wider than the narrowest platform the app runs on.',
|
|
56
|
+
' */',
|
|
57
|
+
`export const CONCURRENCY_LIMIT = ${concurrencyLimit(ir)};`,
|
|
58
|
+
].join('\n');
|
|
59
|
+
const principal = [
|
|
60
|
+
'/**',
|
|
61
|
+
' * The caller a request runs as.',
|
|
62
|
+
' *',
|
|
63
|
+
" * There is no auth layer, so the principal is `Principal`'s default: authenticated,",
|
|
64
|
+
' * with no roles and no scopes. A `branch` predicate is answered from this rather than',
|
|
65
|
+
' * left undefined, which is what makes `isAuthenticated()` true and `hasRole(...)`',
|
|
66
|
+
' * false instead of unanswered -- both are answers a spec may branch on.',
|
|
67
|
+
' */',
|
|
68
|
+
'const PRINCIPAL = new Principal();',
|
|
69
|
+
'',
|
|
70
|
+
'/**',
|
|
71
|
+
' * The principal this run is seeded with.',
|
|
72
|
+
' *',
|
|
73
|
+
' * An `agent` step passes this to the agent loop, so an agent sees the same caller the',
|
|
74
|
+
' * pipeline around it branched on: its guardrails, its `humanInTheLoop` predicate and',
|
|
75
|
+
' * its memory key all price against one principal rather than two that happen to agree',
|
|
76
|
+
' * today. Falls back to the seeded default when a caller replaced the context, which is',
|
|
77
|
+
' * the same fallback the loop applies to an absent `principal`.',
|
|
78
|
+
' */',
|
|
79
|
+
'export function principalOf(context: PipelineContext): Principal {',
|
|
80
|
+
' const found = context.get(PRINCIPAL_KEY);',
|
|
81
|
+
' return found instanceof Principal ? found : PRINCIPAL;',
|
|
82
|
+
'}',
|
|
83
|
+
].join('\n');
|
|
84
|
+
const seeded = [
|
|
85
|
+
'/**',
|
|
86
|
+
' * The values a pipeline run starts from.',
|
|
87
|
+
' *',
|
|
88
|
+
' * `event` is the request the route parsed. The other two are seeded here, before',
|
|
89
|
+
" * `Pipeline.run`, because the runtime's composites read them from the context:",
|
|
90
|
+
' * `branch`/`parallel`/`map`/`reduce` raise a configuration error when `LIMITER_KEY`',
|
|
91
|
+
' * holds no limiter, and `branch` evaluates its `when` against `PRINCIPAL_KEY` and',
|
|
92
|
+
' * nothing else. Neither is an option a step can pass down.',
|
|
93
|
+
' */',
|
|
94
|
+
'export function seeded(event: unknown): Record<string, unknown> {',
|
|
95
|
+
' return {',
|
|
96
|
+
' event,',
|
|
97
|
+
' [LIMITER_KEY]: new ConcurrencyLimiter(CONCURRENCY_LIMIT),',
|
|
98
|
+
' [PRINCIPAL_KEY]: PRINCIPAL,',
|
|
99
|
+
' };',
|
|
100
|
+
'}',
|
|
101
|
+
].join('\n');
|
|
102
|
+
return moduleText(imports, limit, principal, seeded);
|
|
103
|
+
}
|
|
104
|
+
/** `generated/control.ts`. */
|
|
105
|
+
export function emitControl(ir) {
|
|
106
|
+
return generated(paths.control, controlModule(ir));
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=control.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"control.js","sourceRoot":"","sources":["../../src/emit/control.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAGH,OAAO,EAAoB,SAAS,EAAE,KAAK,EAAE,MAAM,WAAW,C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