@agentsmarket/pipeline-runtime 0.1.2 → 0.1.4
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/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/stages.d.ts +8 -0
- package/dist/stages.js +2 -0
- package/dist/validate-inputs.d.ts +43 -0
- package/dist/validate-inputs.js +113 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -35,6 +35,7 @@ export type { PipelineCheckpoint, CheckpointStorage, R2BucketLike, CompletedStag
|
|
|
35
35
|
export { createModelResolver, resolveModelSync, DEFAULT_MODEL, type ModelResolver, type ModelResolverOptions, type PipelineLike, type PipelineStageLike, type SkillLike, } from './model-resolver.js';
|
|
36
36
|
export { sha256Hex, computeSkillContentHash, } from './content-hash.js';
|
|
37
37
|
export { executeStage, runPipelineV2, makeWhenResolve, parseUsesEntry, parseUsesList, validateOutputFormat, StageNotFoundError, StageForbiddenError, StageBadConfigError, type StageExecutorDeps, type StageContext, type StageExecutionResult, type RunPipelineOptions, type RunPipelineResult, type NestedCallRecord, type ResolvedUse, type SkillInvocationDetail, type MCPValidationResult, type MCPDetail, } from './stages.js';
|
|
38
|
+
export { validateInputs, formatInputErrors, type InputDecl, type InputSpec, type InputValidationError, } from './validate-inputs.js';
|
|
38
39
|
export interface PipelineStageSpec {
|
|
39
40
|
id: string;
|
|
40
41
|
model: string;
|
|
@@ -55,6 +56,7 @@ export interface PipelineContext {
|
|
|
55
56
|
export interface PipelineHooks {
|
|
56
57
|
onStageStart?: (stageId: string) => void;
|
|
57
58
|
onStageComplete?: (stageId: string, ms: number, output: string) => void;
|
|
59
|
+
onLlmResponse?: (stageId: string, rawText: string, model: string) => void;
|
|
58
60
|
}
|
|
59
61
|
import type { LLMProvider } from './types.js';
|
|
60
62
|
export declare function runStage(stage: PipelineStageSpec, ctx: PipelineContext): Promise<string>;
|
package/dist/index.js
CHANGED
|
@@ -22,6 +22,7 @@ export { buildCheckpoint, restoreFromCheckpoint, R2CheckpointStorage, InMemoryCh
|
|
|
22
22
|
export { createModelResolver, resolveModelSync, DEFAULT_MODEL, } from './model-resolver.js';
|
|
23
23
|
export { sha256Hex, computeSkillContentHash, } from './content-hash.js';
|
|
24
24
|
export { executeStage, runPipelineV2, makeWhenResolve, parseUsesEntry, parseUsesList, validateOutputFormat, StageNotFoundError, StageForbiddenError, StageBadConfigError, } from './stages.js';
|
|
25
|
+
export { validateInputs, formatInputErrors, } from './validate-inputs.js';
|
|
25
26
|
export async function runStage(stage, ctx) {
|
|
26
27
|
const vars = [];
|
|
27
28
|
for (const [key, val] of Object.entries(ctx.outputs)) {
|
package/dist/stages.d.ts
CHANGED
|
@@ -82,6 +82,14 @@ export interface StageExecutorDeps {
|
|
|
82
82
|
pricing: PricingResolver;
|
|
83
83
|
modelResolver: ModelResolver;
|
|
84
84
|
fetchSkill: (skillId: string) => Promise<SkillLike | null>;
|
|
85
|
+
/**
|
|
86
|
+
* F24 debug hook. Fires after `provider.generateText` returns but
|
|
87
|
+
* before `validateOutputFormat`. Lets the CLI capture the raw LLM
|
|
88
|
+
* text and surface it when validation fails (e.g. "Output format
|
|
89
|
+
* violations: takeaway_1: key missing" without `--debug` you never
|
|
90
|
+
* see what the model actually returned).
|
|
91
|
+
*/
|
|
92
|
+
onLlmResponse?: (stageId: string, rawText: string, model: string) => void;
|
|
85
93
|
/**
|
|
86
94
|
* Optional pipeline fetcher for composition refs (R10.7.b, ADR Q10).
|
|
87
95
|
* When supplied, runPipelineV2 walks the spec once before the loop and
|
package/dist/stages.js
CHANGED
|
@@ -363,6 +363,7 @@ export async function executeStage(stage, pipeline, ctx, deps) {
|
|
|
363
363
|
? resolveStageOutputRefs(chainedInput, ctx.previousOutputs)
|
|
364
364
|
: chainedInput;
|
|
365
365
|
const { result, durationMs } = await invokeSkill(skill, resolvedInput, previousContext, label, stageProvider, stage.retry, retryCtx, stage.output_format);
|
|
366
|
+
deps.onLlmResponse?.(`${stage.id}:${use.id}`, result.text, skillModel);
|
|
366
367
|
lastResult = result;
|
|
367
368
|
chainedInput = { input_from_previous_skill: result.text };
|
|
368
369
|
nestedCalls.push({
|
|
@@ -408,6 +409,7 @@ export async function executeStage(stage, pipeline, ctx, deps) {
|
|
|
408
409
|
}), stage.retry, retryCtx);
|
|
409
410
|
const result = ran.value;
|
|
410
411
|
const costMicroUsdc = await deps.pricing.resolveCostMicroUsdc(model, result.usage);
|
|
412
|
+
deps.onLlmResponse?.(stage.id, result.text, model);
|
|
411
413
|
validateOutputFormat(result.text, stage.output_format, stage.fields);
|
|
412
414
|
return {
|
|
413
415
|
output: result.text,
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pre-flight input validation for pipeline execution.
|
|
3
|
+
*
|
|
4
|
+
* Catches the common UX trap: user runs `pipeline call daily-news-digest`
|
|
5
|
+
* without `--inputs urls=...`, pipeline silently starts, fetch stage fails
|
|
6
|
+
* 4.4s later with a confusing deep-stage error. This check fails fast
|
|
7
|
+
* with a clear "missing required input" message before any stage runs.
|
|
8
|
+
*
|
|
9
|
+
* Called from:
|
|
10
|
+
* - CLI runCommand (packages/cli/src/commands/run.ts)
|
|
11
|
+
* - Server /v1/pipelines/:slug/run endpoint (packages/server/src/routes/pipelines.ts)
|
|
12
|
+
*
|
|
13
|
+
* Behavior:
|
|
14
|
+
* - Iterates spec.inputs (Record<string, InputDecl>)
|
|
15
|
+
* - For each `required: true` input, asserts the value is present AND
|
|
16
|
+
* matches the declared type (string|integer|number|boolean|array|object)
|
|
17
|
+
* - For arrays with declared `items.type`, asserts every item matches
|
|
18
|
+
* - Returns null if all checks pass, else a list of human-readable errors
|
|
19
|
+
*
|
|
20
|
+
* NOTE: This is intentionally permissive on unknown inputs (no error if
|
|
21
|
+
* spec.inputs is missing or input has extra keys). Permissiveness on the
|
|
22
|
+
* "extra" axis avoids breaking ad-hoc CLI invocations; strictness is only
|
|
23
|
+
* on the "missing required" axis.
|
|
24
|
+
*/
|
|
25
|
+
export interface InputDecl {
|
|
26
|
+
type?: 'string' | 'integer' | 'number' | 'boolean' | 'array' | 'object';
|
|
27
|
+
required?: boolean;
|
|
28
|
+
items?: {
|
|
29
|
+
type?: string;
|
|
30
|
+
description?: string;
|
|
31
|
+
};
|
|
32
|
+
default?: unknown;
|
|
33
|
+
description?: string;
|
|
34
|
+
}
|
|
35
|
+
export type InputSpec = Record<string, InputDecl>;
|
|
36
|
+
export interface InputValidationError {
|
|
37
|
+
field: string;
|
|
38
|
+
reason: 'missing' | 'wrong_type' | 'empty_array' | 'wrong_item_type';
|
|
39
|
+
expected?: string;
|
|
40
|
+
got?: string;
|
|
41
|
+
}
|
|
42
|
+
export declare function validateInputs(specInputs: InputSpec | undefined, provided: Record<string, unknown>): InputValidationError[];
|
|
43
|
+
export declare function formatInputErrors(errors: InputValidationError[], inputs?: InputSpec): string;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pre-flight input validation for pipeline execution.
|
|
3
|
+
*
|
|
4
|
+
* Catches the common UX trap: user runs `pipeline call daily-news-digest`
|
|
5
|
+
* without `--inputs urls=...`, pipeline silently starts, fetch stage fails
|
|
6
|
+
* 4.4s later with a confusing deep-stage error. This check fails fast
|
|
7
|
+
* with a clear "missing required input" message before any stage runs.
|
|
8
|
+
*
|
|
9
|
+
* Called from:
|
|
10
|
+
* - CLI runCommand (packages/cli/src/commands/run.ts)
|
|
11
|
+
* - Server /v1/pipelines/:slug/run endpoint (packages/server/src/routes/pipelines.ts)
|
|
12
|
+
*
|
|
13
|
+
* Behavior:
|
|
14
|
+
* - Iterates spec.inputs (Record<string, InputDecl>)
|
|
15
|
+
* - For each `required: true` input, asserts the value is present AND
|
|
16
|
+
* matches the declared type (string|integer|number|boolean|array|object)
|
|
17
|
+
* - For arrays with declared `items.type`, asserts every item matches
|
|
18
|
+
* - Returns null if all checks pass, else a list of human-readable errors
|
|
19
|
+
*
|
|
20
|
+
* NOTE: This is intentionally permissive on unknown inputs (no error if
|
|
21
|
+
* spec.inputs is missing or input has extra keys). Permissiveness on the
|
|
22
|
+
* "extra" axis avoids breaking ad-hoc CLI invocations; strictness is only
|
|
23
|
+
* on the "missing required" axis.
|
|
24
|
+
*/
|
|
25
|
+
export function validateInputs(specInputs, provided) {
|
|
26
|
+
if (!specInputs)
|
|
27
|
+
return [];
|
|
28
|
+
const errors = [];
|
|
29
|
+
for (const [field, decl] of Object.entries(specInputs)) {
|
|
30
|
+
const value = provided[field];
|
|
31
|
+
const present = value !== undefined && value !== null;
|
|
32
|
+
if (decl.required && !present) {
|
|
33
|
+
errors.push({ field, reason: 'missing', expected: decl.type ?? 'any' });
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (!present)
|
|
37
|
+
continue;
|
|
38
|
+
const expectedType = decl.type;
|
|
39
|
+
if (expectedType) {
|
|
40
|
+
const actualType = jsTypeOf(value);
|
|
41
|
+
if (!typeMatches(expectedType, actualType, value)) {
|
|
42
|
+
const gotMsg = expectedType === 'integer' && actualType === 'number'
|
|
43
|
+
? (Number.isInteger(value) ? 'number' : 'float')
|
|
44
|
+
: actualType;
|
|
45
|
+
errors.push({
|
|
46
|
+
field,
|
|
47
|
+
reason: 'wrong_type',
|
|
48
|
+
expected: expectedType,
|
|
49
|
+
got: gotMsg,
|
|
50
|
+
});
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (expectedType === 'array' && Array.isArray(value)) {
|
|
54
|
+
if (value.length === 0 && decl.required) {
|
|
55
|
+
errors.push({ field, reason: 'empty_array', expected: 'non-empty array' });
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (decl.items?.type && value.length > 0) {
|
|
59
|
+
for (let i = 0; i < value.length; i++) {
|
|
60
|
+
const itemType = jsTypeOf(value[i]);
|
|
61
|
+
if (!typeMatches(decl.items.type, itemType, value[i])) {
|
|
62
|
+
errors.push({
|
|
63
|
+
field,
|
|
64
|
+
reason: 'wrong_item_type',
|
|
65
|
+
expected: `${decl.items.type}[]`,
|
|
66
|
+
got: `${itemType}[${i}]`,
|
|
67
|
+
});
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return errors;
|
|
76
|
+
}
|
|
77
|
+
export function formatInputErrors(errors, inputs) {
|
|
78
|
+
if (errors.length === 0)
|
|
79
|
+
return '';
|
|
80
|
+
const lines = [];
|
|
81
|
+
for (const e of errors) {
|
|
82
|
+
const desc = inputs?.[e.field]?.description;
|
|
83
|
+
const typeHint = inputs?.[e.field]?.type
|
|
84
|
+
? ` (${inputs[e.field].type}${inputs[e.field].items ? `<${inputs[e.field].items.type}>` : ''})`
|
|
85
|
+
: '';
|
|
86
|
+
const descSuffix = desc ? ` — ${desc}` : '';
|
|
87
|
+
if (e.reason === 'missing') {
|
|
88
|
+
lines.push(` - ${e.field}${typeHint}: required${descSuffix}`);
|
|
89
|
+
}
|
|
90
|
+
else if (e.reason === 'empty_array') {
|
|
91
|
+
lines.push(` - ${e.field}${typeHint}: must not be empty${descSuffix}`);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
lines.push(` - ${e.field}${typeHint}: expected ${e.expected}, got ${e.got}${descSuffix}`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return lines.join('\n');
|
|
98
|
+
}
|
|
99
|
+
function jsTypeOf(value) {
|
|
100
|
+
if (Array.isArray(value))
|
|
101
|
+
return 'array';
|
|
102
|
+
if (value === null)
|
|
103
|
+
return 'null';
|
|
104
|
+
return typeof value;
|
|
105
|
+
}
|
|
106
|
+
function typeMatches(expected, actual, value) {
|
|
107
|
+
if (expected === 'integer' && actual === 'number') {
|
|
108
|
+
return Number.isInteger(value);
|
|
109
|
+
}
|
|
110
|
+
if (expected === 'number' && actual === 'number')
|
|
111
|
+
return true;
|
|
112
|
+
return expected === actual;
|
|
113
|
+
}
|
package/package.json
CHANGED