@agentsmarket/pipeline-runtime 0.1.3 → 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 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;
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)) {
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentsmarket/pipeline-runtime",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Runtime for executing PIPELINE.md workflows (multi-skill orchestration). Provider-agnostic (MiniMax, Claude, OpenAI).",
5
5
  "license": "MIT",
6
6
  "type": "module",