@agentsmarket/pipeline-runtime 0.2.1 → 0.3.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.
@@ -0,0 +1,61 @@
1
+ /**
2
+ * P2.1 — analyzeCapabilities: pure function over a parsed pipeline spec.
3
+ *
4
+ * Derives a structured `PipelineCapabilities` object that lets callers
5
+ * reason about what a pipeline does WITHOUT executing it. Used by:
6
+ * - Server: include in every pipeline response (P2.2)
7
+ * - MCP tools: search_pipelines can filter by capabilities
8
+ * - Marketplace UI: show "this pipeline uses OpenAI", "produces files"
9
+ *
10
+ * Derivation rules:
11
+ * network : required if any stage uses an LLM provider or skill
12
+ * forbidden if all stages are pure (no LLM, no skill)
13
+ * optional otherwise
14
+ * requires_env : ${VAR} names extracted from all string fields (deduped, sorted)
15
+ * produces_files : any stage has working_dir OR top-level output.files non-empty
16
+ * produces_format: union of stage-level output_format values
17
+ * stages_count : spec.stages.length
18
+ * has_parallel : any stage declares parallel OR has dependency edges to siblings
19
+ * has_composition: any stage uses pipeline:NAME@VERSION (composition)
20
+ * has_when : any stage has a non-empty when clause
21
+ * has_retry : any stage declares a retry config
22
+ *
23
+ * Pure function — no I/O, no DB. Safe to call on parsed YAML.
24
+ */
25
+ export type NetworkCapability = 'required' | 'optional' | 'forbidden';
26
+ export interface PipelineCapabilities {
27
+ network: NetworkCapability;
28
+ requires_env: string[];
29
+ produces_files: boolean;
30
+ produces_format: string[];
31
+ stages_count: number;
32
+ has_parallel: boolean;
33
+ has_composition: boolean;
34
+ has_when: boolean;
35
+ has_retry: boolean;
36
+ capabilities_schema_version: 1;
37
+ }
38
+ export interface PipelineStageLikeForCaps {
39
+ id?: string;
40
+ provider?: string;
41
+ uses?: unknown;
42
+ working_dir?: string;
43
+ output_format?: string;
44
+ parallel?: boolean | string;
45
+ when?: unknown;
46
+ retry?: unknown;
47
+ depends_on?: string[];
48
+ requires?: string[];
49
+ needs?: string[];
50
+ prompt?: string;
51
+ system?: string;
52
+ input?: unknown;
53
+ }
54
+ export interface PipelineSpecLikeForCaps {
55
+ name?: string;
56
+ stages?: PipelineStageLikeForCaps[];
57
+ output?: {
58
+ files?: unknown;
59
+ } | null;
60
+ }
61
+ export declare function analyzeCapabilities(spec: PipelineSpecLikeForCaps | null | undefined): PipelineCapabilities;
@@ -0,0 +1,161 @@
1
+ /**
2
+ * P2.1 — analyzeCapabilities: pure function over a parsed pipeline spec.
3
+ *
4
+ * Derives a structured `PipelineCapabilities` object that lets callers
5
+ * reason about what a pipeline does WITHOUT executing it. Used by:
6
+ * - Server: include in every pipeline response (P2.2)
7
+ * - MCP tools: search_pipelines can filter by capabilities
8
+ * - Marketplace UI: show "this pipeline uses OpenAI", "produces files"
9
+ *
10
+ * Derivation rules:
11
+ * network : required if any stage uses an LLM provider or skill
12
+ * forbidden if all stages are pure (no LLM, no skill)
13
+ * optional otherwise
14
+ * requires_env : ${VAR} names extracted from all string fields (deduped, sorted)
15
+ * produces_files : any stage has working_dir OR top-level output.files non-empty
16
+ * produces_format: union of stage-level output_format values
17
+ * stages_count : spec.stages.length
18
+ * has_parallel : any stage declares parallel OR has dependency edges to siblings
19
+ * has_composition: any stage uses pipeline:NAME@VERSION (composition)
20
+ * has_when : any stage has a non-empty when clause
21
+ * has_retry : any stage declares a retry config
22
+ *
23
+ * Pure function — no I/O, no DB. Safe to call on parsed YAML.
24
+ */
25
+ const ENV_VAR_RE = /\$\{([A-Z_][A-Z0-9_]*)(?::-[^}]*)?\}/g;
26
+ const PIPELINE_REF_RE = /^pipeline:[A-Za-z0-9_.-]+(?:@[A-Za-z0-9_.-]+)?$/;
27
+ export function analyzeCapabilities(spec) {
28
+ const stages = spec?.stages ?? [];
29
+ return {
30
+ network: deriveNetwork(stages),
31
+ requires_env: deriveRequiresEnv(spec ?? {}, stages),
32
+ produces_files: deriveProducesFiles(spec ?? {}, stages),
33
+ produces_format: deriveProducesFormat(stages),
34
+ stages_count: stages.length,
35
+ has_parallel: deriveHasParallel(stages),
36
+ has_composition: deriveHasComposition(stages),
37
+ has_when: deriveHasWhen(stages),
38
+ has_retry: deriveHasRetry(stages),
39
+ capabilities_schema_version: 1,
40
+ };
41
+ }
42
+ function deriveNetwork(stages) {
43
+ let hasLLM = false;
44
+ let hasSkill = false;
45
+ let hasAny = stages.length > 0;
46
+ for (const s of stages) {
47
+ if (typeof s.provider === 'string' && s.provider.length > 0)
48
+ hasLLM = true;
49
+ const uses = s.uses;
50
+ if (typeof uses === 'string' && uses.length > 0)
51
+ hasSkill = true;
52
+ else if (Array.isArray(uses) && uses.length > 0)
53
+ hasSkill = true;
54
+ }
55
+ if (hasLLM || hasSkill)
56
+ return 'required';
57
+ if (!hasAny)
58
+ return 'forbidden';
59
+ return 'forbidden';
60
+ }
61
+ function collectStrings(value, out) {
62
+ if (typeof value === 'string') {
63
+ out.push(value);
64
+ return;
65
+ }
66
+ if (Array.isArray(value)) {
67
+ for (const item of value)
68
+ collectStrings(item, out);
69
+ return;
70
+ }
71
+ if (value && typeof value === 'object') {
72
+ for (const v of Object.values(value)) {
73
+ collectStrings(v, out);
74
+ }
75
+ }
76
+ }
77
+ function deriveRequiresEnv(spec, stages) {
78
+ const strings = [];
79
+ if (spec?.name)
80
+ strings.push(spec.name);
81
+ for (const s of stages) {
82
+ collectStrings(s.prompt, strings);
83
+ collectStrings(s.system, strings);
84
+ collectStrings(s.input, strings);
85
+ }
86
+ const names = new Set();
87
+ for (const text of strings) {
88
+ const re = new RegExp(ENV_VAR_RE.source, 'g');
89
+ let m;
90
+ while ((m = re.exec(text)) !== null) {
91
+ if (m[1])
92
+ names.add(m[1]);
93
+ }
94
+ }
95
+ return Array.from(names).sort();
96
+ }
97
+ function deriveProducesFiles(spec, stages) {
98
+ const out = spec?.output;
99
+ if (out && Array.isArray(out.files) && out.files.length > 0)
100
+ return true;
101
+ for (const s of stages) {
102
+ if (typeof s.working_dir === 'string' && s.working_dir.length > 0)
103
+ return true;
104
+ }
105
+ return false;
106
+ }
107
+ function deriveProducesFormat(stages) {
108
+ const formats = new Set();
109
+ for (const s of stages) {
110
+ if (typeof s.output_format === 'string' && s.output_format.length > 0) {
111
+ formats.add(s.output_format);
112
+ }
113
+ }
114
+ return Array.from(formats).sort();
115
+ }
116
+ function deriveHasParallel(stages) {
117
+ for (const s of stages) {
118
+ if (s.parallel === true || s.parallel === 'true')
119
+ return true;
120
+ }
121
+ const depsCount = new Map();
122
+ for (const s of stages) {
123
+ const deps = [
124
+ ...(Array.isArray(s.depends_on) ? s.depends_on : []),
125
+ ...(Array.isArray(s.requires) ? s.requires : []),
126
+ ...(Array.isArray(s.needs) ? s.needs : []),
127
+ ];
128
+ if (deps.length > 0) {
129
+ const key = deps.join('|');
130
+ depsCount.set(key, (depsCount.get(key) ?? 0) + 1);
131
+ if ((depsCount.get(key) ?? 0) > 1)
132
+ return true;
133
+ }
134
+ }
135
+ return false;
136
+ }
137
+ function deriveHasComposition(stages) {
138
+ for (const s of stages) {
139
+ const uses = s.uses;
140
+ if (typeof uses === 'string' && PIPELINE_REF_RE.test(uses))
141
+ return true;
142
+ if (Array.isArray(uses) && uses.some((u) => typeof u === 'string' && PIPELINE_REF_RE.test(u))) {
143
+ return true;
144
+ }
145
+ }
146
+ return false;
147
+ }
148
+ function deriveHasWhen(stages) {
149
+ for (const s of stages) {
150
+ if (s.when && typeof s.when === 'object')
151
+ return true;
152
+ }
153
+ return false;
154
+ }
155
+ function deriveHasRetry(stages) {
156
+ for (const s of stages) {
157
+ if (s.retry && typeof s.retry === 'object')
158
+ return true;
159
+ }
160
+ return false;
161
+ }
package/dist/index.d.ts CHANGED
@@ -38,6 +38,8 @@ export { executeStage, runPipelineV2, makeWhenResolve, parseUsesEntry, parseUses
38
38
  export { validateInputs, formatInputErrors, type InputDecl, type InputSpec, type InputValidationError, } from './validate-inputs.js';
39
39
  export { resolveInputRefs, resolveSpecialKeys, type PipelineRefContext, } from './pipeline-refs.js';
40
40
  export { isToolSkill, invokeToolSkill, type ToolSkillContext, type ToolSkillResult, type ToolSkillHandler, } from './tools/tool-skills.js';
41
+ export { validateOutputSpec, DEFAULT_OUTPUT_FORMAT, DEFAULT_OUTPUT_DELIVERY, DEFAULT_OUTPUT_EXPIRES_IN, MIN_OUTPUT_EXPIRES_IN, MAX_OUTPUT_EXPIRES_IN, type PipelineOutputSpec, type PipelineOutputDelivery, type PipelineOutputFormat, type PipelineOutputSpecError, } from './output-spec.js';
42
+ export { analyzeCapabilities, type PipelineCapabilities, type NetworkCapability, type PipelineSpecLikeForCaps, type PipelineStageLikeForCaps, } from './capabilities.js';
41
43
  export interface PipelineStageSpec {
42
44
  id: string;
43
45
  model: string;
package/dist/index.js CHANGED
@@ -25,6 +25,8 @@ export { executeStage, runPipelineV2, makeWhenResolve, parseUsesEntry, parseUses
25
25
  export { validateInputs, formatInputErrors, } from './validate-inputs.js';
26
26
  export { resolveInputRefs, resolveSpecialKeys, } from './pipeline-refs.js';
27
27
  export { isToolSkill, invokeToolSkill, } from './tools/tool-skills.js';
28
+ export { validateOutputSpec, DEFAULT_OUTPUT_FORMAT, DEFAULT_OUTPUT_DELIVERY, DEFAULT_OUTPUT_EXPIRES_IN, MIN_OUTPUT_EXPIRES_IN, MAX_OUTPUT_EXPIRES_IN, } from './output-spec.js';
29
+ export { analyzeCapabilities, } from './capabilities.js';
28
30
  export async function runStage(stage, ctx) {
29
31
  const vars = [];
30
32
  for (const [key, val] of Object.entries(ctx.outputs)) {
@@ -5,9 +5,14 @@
5
5
  * 1. stage.model — explicit per-stage override
6
6
  * 2. pipeline.defaults.model — pipeline-level default
7
7
  * 3. skill.preferred_model — skill's recommendation (if stage uses a skill)
8
- * 4. agentConfig.default_model — from CLI config (~/.config/agentsmarket/config.json)
9
- * 5. envDefault — AGENTSMARKET_DEFAULT_MODEL env var
10
- * 6. "MiniMax-M3" — hardcoded fallback
8
+ * 4. pipeline.preferred_model — pipeline author's hint (v0.5 NEW; DB column
9
+ * on server, top-level YAML field on CLI).
10
+ * Weaker than `defaults.model` — author can
11
+ * override per-stage; weaker than skill's own
12
+ * hint because skill knows its own shape best.
13
+ * 5. agentConfig.default_model — from CLI config (~/.config/agentsmarket/config.json)
14
+ * 6. envDefault — AGENTSMARKET_DEFAULT_MODEL env var
15
+ * 7. "MiniMax-M3" — hardcoded fallback
11
16
  *
12
17
  * Cost of a stage is always based on the resolved model, regardless of who declared it.
13
18
  */
@@ -107,6 +112,8 @@ export interface PipelineLike {
107
112
  defaults?: {
108
113
  model?: string;
109
114
  };
115
+ preferred_model?: string;
116
+ output?: import('./output-spec.js').PipelineOutputSpec;
110
117
  }
111
118
  export interface SkillLike {
112
119
  id: string;
@@ -5,9 +5,14 @@
5
5
  * 1. stage.model — explicit per-stage override
6
6
  * 2. pipeline.defaults.model — pipeline-level default
7
7
  * 3. skill.preferred_model — skill's recommendation (if stage uses a skill)
8
- * 4. agentConfig.default_model — from CLI config (~/.config/agentsmarket/config.json)
9
- * 5. envDefault — AGENTSMARKET_DEFAULT_MODEL env var
10
- * 6. "MiniMax-M3" — hardcoded fallback
8
+ * 4. pipeline.preferred_model — pipeline author's hint (v0.5 NEW; DB column
9
+ * on server, top-level YAML field on CLI).
10
+ * Weaker than `defaults.model` — author can
11
+ * override per-stage; weaker than skill's own
12
+ * hint because skill knows its own shape best.
13
+ * 5. agentConfig.default_model — from CLI config (~/.config/agentsmarket/config.json)
14
+ * 6. envDefault — AGENTSMARKET_DEFAULT_MODEL env var
15
+ * 7. "MiniMax-M3" — hardcoded fallback
11
16
  *
12
17
  * Cost of a stage is always based on the resolved model, regardless of who declared it.
13
18
  */
@@ -18,6 +23,7 @@ export function createModelResolver(opts = {}) {
18
23
  return stage.model
19
24
  ?? pipeline?.defaults?.model
20
25
  ?? skill?.preferred_model
26
+ ?? pipeline?.preferred_model
21
27
  ?? opts.agentDefault
22
28
  ?? opts.envDefault
23
29
  ?? hardcoded;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * P1.1 — PipelineOutputSpec type + validateOutputSpec pure function.
3
+ *
4
+ * The top-level `output` block in a pipeline YAML declares what the
5
+ * pipeline produces after all stages complete. Two concerns:
6
+ *
7
+ * - format : how the output is shaped (text / json / zip / files)
8
+ * - delivery : how the caller receives it (inline body or signed URL)
9
+ *
10
+ * Glob patterns in `files` are matched against the pipeline's working
11
+ * directory after execution. P1.2 wires CLI glob tracking; P5 (deferred)
12
+ * wires R2 upload + signed URLs server-side.
13
+ */
14
+ export type PipelineOutputDelivery = 'inline' | 'signed_url';
15
+ export type PipelineOutputFormat = 'text' | 'json' | 'zip' | 'files';
16
+ export interface PipelineOutputSpec {
17
+ format: PipelineOutputFormat;
18
+ files?: string[];
19
+ delivery: PipelineOutputDelivery;
20
+ expires_in?: number;
21
+ }
22
+ export interface PipelineOutputSpecError {
23
+ field: string;
24
+ error: string;
25
+ }
26
+ export declare const DEFAULT_OUTPUT_FORMAT: PipelineOutputFormat;
27
+ export declare const DEFAULT_OUTPUT_DELIVERY: PipelineOutputDelivery;
28
+ export declare const DEFAULT_OUTPUT_EXPIRES_IN = 86400;
29
+ export declare const MIN_OUTPUT_EXPIRES_IN = 60;
30
+ export declare const MAX_OUTPUT_EXPIRES_IN = 604800;
31
+ export declare function validateOutputSpec(raw: unknown): {
32
+ ok: true;
33
+ value: PipelineOutputSpec;
34
+ } | {
35
+ ok: false;
36
+ errors: PipelineOutputSpecError[];
37
+ };
@@ -0,0 +1,120 @@
1
+ /**
2
+ * P1.1 — PipelineOutputSpec type + validateOutputSpec pure function.
3
+ *
4
+ * The top-level `output` block in a pipeline YAML declares what the
5
+ * pipeline produces after all stages complete. Two concerns:
6
+ *
7
+ * - format : how the output is shaped (text / json / zip / files)
8
+ * - delivery : how the caller receives it (inline body or signed URL)
9
+ *
10
+ * Glob patterns in `files` are matched against the pipeline's working
11
+ * directory after execution. P1.2 wires CLI glob tracking; P5 (deferred)
12
+ * wires R2 upload + signed URLs server-side.
13
+ */
14
+ export const DEFAULT_OUTPUT_FORMAT = 'text';
15
+ export const DEFAULT_OUTPUT_DELIVERY = 'inline';
16
+ export const DEFAULT_OUTPUT_EXPIRES_IN = 86_400;
17
+ export const MIN_OUTPUT_EXPIRES_IN = 60;
18
+ export const MAX_OUTPUT_EXPIRES_IN = 604_800;
19
+ export function validateOutputSpec(raw) {
20
+ if (raw === undefined || raw === null) {
21
+ return {
22
+ ok: true,
23
+ value: {
24
+ format: DEFAULT_OUTPUT_FORMAT,
25
+ delivery: DEFAULT_OUTPUT_DELIVERY,
26
+ },
27
+ };
28
+ }
29
+ if (typeof raw !== 'object' || Array.isArray(raw)) {
30
+ return {
31
+ ok: false,
32
+ errors: [{ field: 'output', error: 'output must be an object' }],
33
+ };
34
+ }
35
+ const spec = raw;
36
+ const errors = [];
37
+ const format = typeof spec.format === 'string' ? spec.format : DEFAULT_OUTPUT_FORMAT;
38
+ if (!['text', 'json', 'zip', 'files'].includes(format)) {
39
+ errors.push({
40
+ field: 'output.format',
41
+ error: `format must be one of: text, json, zip, files (got '${format}')`,
42
+ });
43
+ }
44
+ const delivery = typeof spec.delivery === 'string' ? spec.delivery : DEFAULT_OUTPUT_DELIVERY;
45
+ if (!['inline', 'signed_url'].includes(delivery)) {
46
+ errors.push({
47
+ field: 'output.delivery',
48
+ error: `delivery must be one of: inline, signed_url (got '${delivery}')`,
49
+ });
50
+ }
51
+ let files;
52
+ if (spec.files !== undefined) {
53
+ if (!Array.isArray(spec.files)) {
54
+ errors.push({
55
+ field: 'output.files',
56
+ error: 'files must be an array of glob strings',
57
+ });
58
+ }
59
+ else if (spec.files.length === 0) {
60
+ errors.push({
61
+ field: 'output.files',
62
+ error: 'files must contain at least one glob pattern',
63
+ });
64
+ }
65
+ else {
66
+ const invalid = spec.files.filter((f) => typeof f !== 'string' || f.length === 0);
67
+ if (invalid.length > 0) {
68
+ errors.push({
69
+ field: 'output.files',
70
+ error: `files contains non-string or empty entries: ${JSON.stringify(invalid)}`,
71
+ });
72
+ }
73
+ else {
74
+ files = spec.files;
75
+ }
76
+ }
77
+ }
78
+ let expires_in;
79
+ if (spec.expires_in !== undefined) {
80
+ if (typeof spec.expires_in !== 'number' || !Number.isInteger(spec.expires_in)) {
81
+ errors.push({
82
+ field: 'output.expires_in',
83
+ error: 'expires_in must be an integer (seconds)',
84
+ });
85
+ }
86
+ else if (spec.expires_in < MIN_OUTPUT_EXPIRES_IN ||
87
+ spec.expires_in > MAX_OUTPUT_EXPIRES_IN) {
88
+ errors.push({
89
+ field: 'output.expires_in',
90
+ error: `expires_in must be between ${MIN_OUTPUT_EXPIRES_IN} and ${MAX_OUTPUT_EXPIRES_IN} seconds (got ${spec.expires_in})`,
91
+ });
92
+ }
93
+ else {
94
+ expires_in = spec.expires_in;
95
+ }
96
+ }
97
+ if (format === 'files' && (!files || files.length === 0)) {
98
+ errors.push({
99
+ field: 'output.files',
100
+ error: 'format "files" requires a non-empty files array (glob patterns)',
101
+ });
102
+ }
103
+ if (delivery === 'signed_url' && expires_in === undefined) {
104
+ errors.push({
105
+ field: 'output.expires_in',
106
+ error: 'delivery "signed_url" requires expires_in (60 ≤ seconds ≤ 604800)',
107
+ });
108
+ }
109
+ if (errors.length > 0)
110
+ return { ok: false, errors };
111
+ const value = {
112
+ format: format,
113
+ delivery: delivery,
114
+ };
115
+ if (files !== undefined)
116
+ value.files = files;
117
+ if (expires_in !== undefined)
118
+ value.expires_in = expires_in;
119
+ return { ok: true, value };
120
+ }
package/dist/webhook.js CHANGED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentsmarket/pipeline-runtime",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
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",