@agentsmarket/pipeline-runtime 0.5.2 → 0.5.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 agentsmarket.world contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.d.ts CHANGED
@@ -17,7 +17,7 @@ export type { OpenAIChatProviderOptions } from './providers/openai-chat.js';
17
17
  export { AnthropicProvider } from './providers/anthropic.js';
18
18
  export type { AnthropicProviderOptions } from './providers/anthropic.js';
19
19
  export { FallbackProvider, createFallbackProvider } from './fallback.js';
20
- export { PROVIDER_REGISTRY, getProvider, validateProviderName, supportsModel, validateProviderModel, listProviders, listSupportedModels, listVisionCapableModels, isVisionCapable, assertMultimodalSupported, validateR6Spec, migrateProviderField, ProviderSpecNotFoundError, ProviderModelMismatchError, LLMProviderRegistry, ProviderMismatchError, UnknownProviderError, type Provider, type ProviderSpec, type R6StageInput, type R6SpecInput, type R6ValidationResult, } from './provider-registry.js';
20
+ export { PROVIDER_REGISTRY, getProvider, validateProviderName, supportsModel, validateProviderModel, listProviders, listSupportedModels, listVisionCapableModels, isVisionCapable, assertMultimodalSupported, validateR6Spec, R6_PROVIDER_REQUIRED, migrateProviderField, ProviderSpecNotFoundError, ProviderModelMismatchError, LLMProviderRegistry, ProviderMismatchError, UnknownProviderError, type Provider, type ProviderSpec, type R6StageInput, type R6SpecInput, type R6ValidationResult, } from './provider-registry.js';
21
21
  export { expandPipelineText, resolveEnvVars, resolveEnvVarsInObject, loadPipelineYaml, parseVariableSpec, MissingEnvVarError, } from './resolve-vars.js';
22
22
  export type { EnvLike } from './resolve-vars.js';
23
23
  export { isRetryableStatus, computeBackoffMs, RetryExhaustedError, RetryAttemptError, DEFAULT_RETRY, DEFAULT_RETRYABLE_STATUSES, } from './retry.js';
@@ -44,7 +44,7 @@ export { executeStage, runPipelineV2, makeWhenResolve, parseUsesEntry, parseUses
44
44
  export { validateInputs, formatInputErrors, type InputDecl, type InputSpec, type InputValidationError, } from './validate-inputs.js';
45
45
  export { validateMultimodalInput, type MultimodalValidationError, type MultimodalValidationResult, } from './validate-inputs.js';
46
46
  export { parseMediaUrl, detectMime, isImageMime, isAudioMime, isVideoMime, SUPPORTED_IMAGE_MIME, SUPPORTED_AUDIO_MIME, SUPPORTED_VIDEO_MIME, toAnthropicContent, type ParsedMedia, type AnthropicContentBlock, } from './adapters/multimodal-convert.js';
47
- export { resolveInputRefs, resolveSpecialKeys, resolveDoubleBraceRefs, type PipelineRefContext, type DoubleBraceContext, } from './pipeline-refs.js';
47
+ export { resolveInputRefs, containsInputRef, resolveSpecialKeys, resolveDoubleBraceRefs, type PipelineRefContext, type DoubleBraceContext, } from './pipeline-refs.js';
48
48
  export { isToolSkill, invokeToolSkill, type ToolSkillContext, type ToolSkillResult, type ToolSkillHandler, } from './tools/tool-skills.js';
49
49
  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';
50
50
  export { validateJsonSchema, MAX_VALIDATION_DEPTH, type JsonSchema, type JsonSchemaType, type OutputValidationViolation, type OutputValidationResult, } from './output-schema.js';
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ export { OpenRouterProvider } from './adapters/openrouter.js';
11
11
  export { OpenAIChatProvider } from './providers/openai-chat.js';
12
12
  export { AnthropicProvider } from './providers/anthropic.js';
13
13
  export { FallbackProvider, createFallbackProvider } from './fallback.js';
14
- export { PROVIDER_REGISTRY, getProvider, validateProviderName, supportsModel, validateProviderModel, listProviders, listSupportedModels, listVisionCapableModels, isVisionCapable, assertMultimodalSupported, validateR6Spec, migrateProviderField, ProviderSpecNotFoundError, ProviderModelMismatchError, LLMProviderRegistry, ProviderMismatchError, UnknownProviderError, } from './provider-registry.js';
14
+ export { PROVIDER_REGISTRY, getProvider, validateProviderName, supportsModel, validateProviderModel, listProviders, listSupportedModels, listVisionCapableModels, isVisionCapable, assertMultimodalSupported, validateR6Spec, R6_PROVIDER_REQUIRED, migrateProviderField, ProviderSpecNotFoundError, ProviderModelMismatchError, LLMProviderRegistry, ProviderMismatchError, UnknownProviderError, } from './provider-registry.js';
15
15
  export { expandPipelineText, resolveEnvVars, resolveEnvVarsInObject, loadPipelineYaml, parseVariableSpec, MissingEnvVarError, } from './resolve-vars.js';
16
16
  export { isRetryableStatus, computeBackoffMs, RetryExhaustedError, RetryAttemptError, DEFAULT_RETRY, DEFAULT_RETRYABLE_STATUSES, } from './retry.js';
17
17
  export { parseComparison, parseWhenLiteral, evaluateComparison, evaluateWhen, shouldSkipStage, validateWhenShape, WhenParseError, } from './when.js';
@@ -28,7 +28,7 @@ export { executeStage, runPipelineV2, makeWhenResolve, parseUsesEntry, parseUses
28
28
  export { validateInputs, formatInputErrors, } from './validate-inputs.js';
29
29
  export { validateMultimodalInput, } from './validate-inputs.js';
30
30
  export { parseMediaUrl, detectMime, isImageMime, isAudioMime, isVideoMime, SUPPORTED_IMAGE_MIME, SUPPORTED_AUDIO_MIME, SUPPORTED_VIDEO_MIME, toAnthropicContent, } from './adapters/multimodal-convert.js';
31
- export { resolveInputRefs, resolveSpecialKeys, resolveDoubleBraceRefs, } from './pipeline-refs.js';
31
+ export { resolveInputRefs, containsInputRef, resolveSpecialKeys, resolveDoubleBraceRefs, } from './pipeline-refs.js';
32
32
  export { isToolSkill, invokeToolSkill, } from './tools/tool-skills.js';
33
33
  export { validateOutputSpec, DEFAULT_OUTPUT_FORMAT, DEFAULT_OUTPUT_DELIVERY, DEFAULT_OUTPUT_EXPIRES_IN, MIN_OUTPUT_EXPIRES_IN, MAX_OUTPUT_EXPIRES_IN, } from './output-spec.js';
34
34
  export { validateJsonSchema, MAX_VALIDATION_DEPTH, } from './output-schema.js';
@@ -58,6 +58,27 @@ export interface PipelineStageLike {
58
58
  * returns no text at all. Raise it per stage rather than globally.
59
59
  */
60
60
  maxTokens?: number;
61
+ /**
62
+ * Provider-facing sampling parameters.
63
+ *
64
+ * The CLI validates this block (`cli/src/lib/pipeline-spec.ts:284`) but until
65
+ * now nothing in the runtime read it, so `model_params.temperature: 0` was
66
+ * accepted by a spec, passed every check, and then discarded — the adapter
67
+ * default of 0.7 was used instead, with no warning anywhere. `maxTokens` above
68
+ * is read at both `generateText` call sites in `stages.ts`; these were not.
69
+ *
70
+ * `response_format` and `provider_params` are validated but still ignored:
71
+ * the first duplicates the stage's own `output_format`, and the second has no
72
+ * destination in `GenerateOptions`.
73
+ */
74
+ model_params?: {
75
+ temperature?: number;
76
+ max_tokens?: number;
77
+ top_p?: number;
78
+ seed?: number;
79
+ stop?: string[];
80
+ reasoning_effort?: 'low' | 'medium' | 'high';
81
+ };
61
82
  /**
62
83
  * MCP server names available to this stage. v0.2 NEW (forward-compat).
63
84
  * Validated against executor's MCP registry, not yet executed.
@@ -47,6 +47,18 @@ export interface DoubleBraceContext {
47
47
  visiting?: Set<string>;
48
48
  }
49
49
  export declare function resolveDoubleBraceRefs(value: unknown, ctx: DoubleBraceContext): unknown;
50
+ /**
51
+ * Whether a value carries an input reference (`$input.X` / `${input.X}`).
52
+ *
53
+ * Callers that must inspect a value BEFORE inputs are known use this to tell
54
+ * "this is a literal" from "this will be substituted later". Spec validation is
55
+ * the case that matters: `provider: ${input.provider}` cannot be checked against
56
+ * the provider registry at that point, because the actual value is not known yet.
57
+ *
58
+ * Lives here so the ref syntax has one definition — a second copy of the pattern
59
+ * in a consumer would drift the moment either side gains a form.
60
+ */
61
+ export declare function containsInputRef(value: unknown): boolean;
50
62
  export declare function resolveInputRefs(value: unknown, ctx: PipelineRefContext): unknown;
51
63
  /**
52
64
  * Substitute built-in special keys (\$today, \$now, \$year, \$month, \$weekday)
@@ -183,7 +183,28 @@ export function resolveDoubleBraceRefs(value, ctx) {
183
183
  }
184
184
  return value;
185
185
  }
186
- const INPUT_REF_PATTERN = /\$\{\s*input\.([A-Za-z_][A-Za-z0-9_]*)\s*\}|\$input\.([A-Za-z_][A-Za-z0-9_]*)/g;
186
+ /**
187
+ * Whether a value carries an input reference (`$input.X` / `${input.X}`).
188
+ *
189
+ * Callers that must inspect a value BEFORE inputs are known use this to tell
190
+ * "this is a literal" from "this will be substituted later". Spec validation is
191
+ * the case that matters: `provider: ${input.provider}` cannot be checked against
192
+ * the provider registry at that point, because the actual value is not known yet.
193
+ *
194
+ * Lives here so the ref syntax has one definition — a second copy of the pattern
195
+ * in a consumer would drift the moment either side gains a form.
196
+ */
197
+ export function containsInputRef(value) {
198
+ return typeof value === 'string' && INPUT_REF_PROBE.test(value);
199
+ }
200
+ // One definition of the ref syntax, two regexes over it. Substitution needs the
201
+ // global flag; the predicate must NOT have it — a global regex carries
202
+ // `lastIndex` between `.test()` calls, so `containsInputRef` answered
203
+ // true/false/true for the same string and every second stage that used
204
+ // `${input.provider}` was validated as a literal.
205
+ const INPUT_REF_SRC = String.raw `\$\{\s*input\.([A-Za-z_][A-Za-z0-9_]*)\s*\}|\$input\.([A-Za-z_][A-Za-z0-9_]*)`;
206
+ const INPUT_REF_PATTERN = new RegExp(INPUT_REF_SRC, 'g');
207
+ const INPUT_REF_PROBE = new RegExp(INPUT_REF_SRC);
187
208
  const STAGE_OUTPUT_REF_PATTERN = /\$\{\s*stages\.([A-Za-z_][A-Za-z0-9_.-]*)\.output\s*\}|\$stages\.([A-Za-z_][A-Za-z0-9_.-]*)\.output/g;
188
209
  const SPECIAL_KEYS = {
189
210
  today: () => new Date().toISOString().slice(0, 10),
@@ -153,6 +153,15 @@ export interface R6ValidationResult {
153
153
  * 3. The stage's effective model = `stage.model ?? spec.defaults?.model ?? 'MiniMax-M3'`.
154
154
  * Stages using `uses:` (skill invocation) skip the gate entirely.
155
155
  */
156
+ /**
157
+ * The R6 remedy text, in one place.
158
+ *
159
+ * It used to name only `provider: minimax`, and that is how all six canonical
160
+ * pipelines came to hardcode it — the message was followed literally. Since a
161
+ * stage can now take its provider from a pipeline input, the message has to say
162
+ * so, otherwise the same trap is re-set for the next author.
163
+ */
164
+ export declare const R6_PROVIDER_REQUIRED: string;
156
165
  export declare function validateR6Spec(spec: R6SpecInput): R6ValidationResult;
157
166
  /**
158
167
  * One-shot migration: adds `provider: minimax` to every LLM stage
@@ -226,6 +226,17 @@ export function listSupportedModels(providerName) {
226
226
  * 3. The stage's effective model = `stage.model ?? spec.defaults?.model ?? 'MiniMax-M3'`.
227
227
  * Stages using `uses:` (skill invocation) skip the gate entirely.
228
228
  */
229
+ /**
230
+ * The R6 remedy text, in one place.
231
+ *
232
+ * It used to name only `provider: minimax`, and that is how all six canonical
233
+ * pipelines came to hardcode it — the message was followed literally. Since a
234
+ * stage can now take its provider from a pipeline input, the message has to say
235
+ * so, otherwise the same trap is re-set for the next author.
236
+ */
237
+ export const R6_PROVIDER_REQUIRED = `R6 requires explicit 'provider:' field (auto-dispatch by model name removed). ` +
238
+ `Add 'provider: minimax' (or openrouter/openai/anthropic/replicate), or pick it ` +
239
+ `per run with provider: \${input.provider} and a declared default under inputs:.`;
229
240
  export function validateR6Spec(spec) {
230
241
  const errors = [];
231
242
  const stages = spec.stages ?? [];
@@ -240,14 +251,18 @@ export function validateR6Spec(spec) {
240
251
  continue;
241
252
  const stageLabel = `Stage '${stage.id ?? '<no-id>'}'`;
242
253
  if (typeof stage.provider !== 'string' || stage.provider.length === 0) {
243
- errors.push(`${stageLabel}: R6 requires explicit 'provider:' field ` +
244
- `(auto-dispatch by model name removed). Add 'provider: minimax' ` +
245
- `(or openrouter/openai/anthropic/replicate).`);
254
+ errors.push(`${stageLabel}: ${R6_PROVIDER_REQUIRED}`);
246
255
  continue;
247
256
  }
248
257
  const effectiveModel = hasModel
249
258
  ? stage.model
250
259
  : (spec.defaults?.model ?? 'MiniMax-M3');
260
+ // A provider or model that will be substituted from pipeline inputs has no
261
+ // value yet at spec-validation time — this function only sees the spec. The
262
+ // runtime resolves both fields before dispatch and rejects an unknown
263
+ // provider there, against the real value.
264
+ if (containsInputRef(stage.provider) || containsInputRef(effectiveModel))
265
+ continue;
251
266
  try {
252
267
  validateProviderModel(stage.provider, effectiveModel);
253
268
  }
@@ -324,6 +339,7 @@ export class ProviderModelMismatchError extends Error {
324
339
  }
325
340
  }
326
341
  import { MultimodalModelUnsupportedError } from './multimodal.js';
342
+ import { containsInputRef } from './pipeline-refs.js';
327
343
  /**
328
344
  * Thrown when a stage declares `provider: X` but X is not in the
329
345
  * registry passed to the executor.
package/dist/stages.js CHANGED
@@ -260,6 +260,26 @@ export class StageBadConfigError extends Error {
260
260
  this.name = 'BAD_STAGE';
261
261
  }
262
262
  }
263
+ /**
264
+ * Substitute `${input.X}` / `$input.X` references in `stage.provider` and
265
+ * `stage.model` before they reach the resolver. Same walking strategy that
266
+ * already runs over `chainedInput` (stage arguments) at line ~830; literals
267
+ * pass through unchanged and unresolved references stay as their text form
268
+ * (matching resolveInputRefs:266 — pipeline-refs.ts).
269
+ *
270
+ * Returns a shallow clone when at least one field actually changes; returns
271
+ * the same `stage` object otherwise so we don't allocate per-call.
272
+ */
273
+ function resolveStageMetaRefs(stage, inputs) {
274
+ const resolvedProvider = resolveInputRefs(stage.provider, { inputs, previousOutputs: {} });
275
+ const resolvedModelRaw = resolveInputRefs(stage.model, { inputs, previousOutputs: {} });
276
+ const resolvedModel = typeof resolvedModelRaw === 'string' ? resolvedModelRaw : stage.model;
277
+ const providerChanged = typeof resolvedProvider === 'string' && resolvedProvider !== stage.provider;
278
+ const modelChanged = typeof stage.model === 'string' && resolvedModel !== stage.model;
279
+ if (!providerChanged && !modelChanged)
280
+ return stage;
281
+ return { ...stage, provider: resolvedProvider, model: resolvedModel };
282
+ }
263
283
  function resolveStageProvider(deps, stage, model) {
264
284
  // F12: --mock must override explicit per-stage `provider:` declarations,
265
285
  // otherwise canonical seeded pipelines (which all declare
@@ -395,6 +415,32 @@ async function runWithRetry(op, retry, retryCtx) {
395
415
  }
396
416
  // Fallback constant (kept local — retry.ts owns the canonical list).
397
417
  const DEFAULT_RETRYABLE_STATUSES_FALLBACK = [429, 503];
418
+ /**
419
+ * `model_params` (snake_case in a spec) → `GenerateOptions` (camelCase).
420
+ *
421
+ * Returns an empty object when the stage sets nothing, so spreading it at a call
422
+ * site adds no keys and every adapter keeps its own default. `max_tokens` is
423
+ * mapped too even though `stage.maxTokens` wins at the call sites: a spec that
424
+ * sets only `model_params.max_tokens` should not silently get 4096.
425
+ */
426
+ function stageModelParams(stage) {
427
+ const mp = stage.model_params;
428
+ if (!mp)
429
+ return {};
430
+ return {
431
+ temperature: mp.temperature,
432
+ topP: mp.top_p,
433
+ seed: mp.seed,
434
+ stopSequences: mp.stop,
435
+ reasoningEffort: mp.reasoning_effort,
436
+ };
437
+ }
438
+ function resolveMaxTokens(stage) {
439
+ if (Number.isFinite(stage.maxTokens))
440
+ return stage.maxTokens;
441
+ const fromParams = stage.model_params?.max_tokens;
442
+ return Number.isFinite(fromParams) ? fromParams : 4096;
443
+ }
398
444
  export async function executeStage(stage, pipeline, ctx, deps,
399
445
  /**
400
446
  * Appended to the prompt on a validation retry. `output_retry` used to
@@ -640,7 +686,8 @@ correctionHint) {
640
686
  model,
641
687
  system: resolvedSystem,
642
688
  complexity: stage.model?.includes('M3') || stage.model?.includes('opus') ? 'complex' : 'simple',
643
- maxTokens: Number.isFinite(stage.maxTokens) ? stage.maxTokens : 4096,
689
+ maxTokens: resolveMaxTokens(stage),
690
+ ...stageModelParams(stage),
644
691
  fields: stage.fields,
645
692
  outputFormat: stage.output_format,
646
693
  messages: correctionHint
@@ -664,7 +711,8 @@ correctionHint) {
664
711
  model,
665
712
  system: resolvedSystem,
666
713
  complexity: stage.model?.includes('M3') || stage.model?.includes('opus') ? 'complex' : 'simple',
667
- maxTokens: Number.isFinite(stage.maxTokens) ? stage.maxTokens : 4096,
714
+ maxTokens: resolveMaxTokens(stage),
715
+ ...stageModelParams(stage),
668
716
  fields: stage.fields,
669
717
  outputFormat: stage.output_format,
670
718
  });
@@ -717,16 +765,21 @@ async function runOneStage(stage, shared) {
717
765
  for (const w of collectRuntimeWarnings(stage, shared.constraints)) {
718
766
  shared.emit({ type: 'stage.started', at: new Date().toISOString(), stageId, reason: 'normal' });
719
767
  }
768
+ // Substitute `${input.X}` references in provider/model before the resolver
769
+ // sees them. Without this a stage like `provider: ${input.provider}` reaches
770
+ // the registry with the verbatim string and throws
771
+ // `Provider '${input.provider}' is not registered`. Literals pass through.
772
+ const effectiveStage = resolveStageMetaRefs(stage, shared.opts.inputs);
720
773
  const t0 = Date.now();
721
774
  try {
722
- const stageModel = stage.model ?? shared.opts.spec.defaults?.model ?? 'MiniMax-M3';
775
+ const stageModel = effectiveStage.model ?? shared.opts.spec.defaults?.model ?? 'MiniMax-M3';
723
776
  const stageDeps = shared.opts.providerResolver
724
777
  ? { ...shared.opts.deps, provider: shared.opts.providerResolver(stageModel) }
725
778
  : shared.opts.deps;
726
779
  const stageDepsWithSink = shared.opts.eventSink
727
780
  ? { ...stageDeps, eventSink: shared.opts.eventSink }
728
781
  : stageDeps;
729
- const result = await runStageWithOutputValidation(stage, shared.opts.spec, { inputs: shared.opts.inputs, previousOutputs: shared.outputs }, stageDepsWithSink);
782
+ const result = await runStageWithOutputValidation(effectiveStage, shared.opts.spec, { inputs: shared.opts.inputs, previousOutputs: shared.outputs }, stageDepsWithSink);
730
783
  const ms = Date.now() - t0;
731
784
  shared.outputs[stageId] = result.output;
732
785
  shared.stageTimings.push({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentsmarket/pipeline-runtime",
3
- "version": "0.5.2",
3
+ "version": "0.5.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",
@@ -9,13 +9,6 @@
9
9
  "dist",
10
10
  "README.md"
11
11
  ],
12
- "scripts": {
13
- "build": "tsc",
14
- "test": "vitest run",
15
- "test:coverage": "vitest run --coverage",
16
- "dev": "tsx src/index.ts",
17
- "lint": "tsc --noEmit"
18
- },
19
12
  "dependencies": {
20
13
  "@anthropic-ai/sdk": "^0.125.0",
21
14
  "@hono/node-server": "^1.13.0",
@@ -41,5 +34,13 @@
41
34
  "publishConfig": {
42
35
  "access": "public"
43
36
  },
44
- "types": "./dist/index.d.ts"
45
- }
37
+ "types": "./dist/index.d.ts",
38
+ "scripts": {
39
+ "build": "tsc",
40
+ "test": "vitest run",
41
+ "test:coverage": "vitest run --coverage",
42
+ "dev": "tsx src/index.ts",
43
+ "lint": "tsc --noEmit",
44
+ "typecheck": "tsc --noEmit -p tsconfig.json"
45
+ }
46
+ }