@agentsmarket/pipeline-runtime 0.1.5 → 0.1.6

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
@@ -36,6 +36,7 @@ export { createModelResolver, resolveModelSync, DEFAULT_MODEL, type ModelResolve
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
38
  export { validateInputs, formatInputErrors, type InputDecl, type InputSpec, type InputValidationError, } from './validate-inputs.js';
39
+ export { resolveInputRefs, type PipelineRefContext, } from './pipeline-refs.js';
39
40
  export interface PipelineStageSpec {
40
41
  id: string;
41
42
  model: string;
package/dist/index.js CHANGED
@@ -23,6 +23,7 @@ export { createModelResolver, resolveModelSync, DEFAULT_MODEL, } from './model-r
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
25
  export { validateInputs, formatInputErrors, } from './validate-inputs.js';
26
+ export { resolveInputRefs, } from './pipeline-refs.js';
26
27
  export async function runStage(stage, ctx) {
27
28
  const vars = [];
28
29
  for (const [key, val] of Object.entries(ctx.outputs)) {
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Resolve pipeline-level template references in skill chain input blocks.
3
+ *
4
+ * Supports two reference flavors (both with and without braces):
5
+ * - `$input.X` / `${input.X}` → ctx.inputs[X]
6
+ * - `$stages.X.output` / `${stages.X.output}` → ctx.previousOutputs[X]
7
+ *
8
+ * Scope (F26-min): only the skill-chain `input:` block is resolved.
9
+ * Prompts keep their existing behavior (LLM interprets literal refs
10
+ * as context markers — works because LLMs are smart).
11
+ *
12
+ * Why "leave literal if missing" instead of throwing:
13
+ * The skill may receive partial input and choose to return an
14
+ * error JSON (which downstream stages can handle). Throwing
15
+ * would short-circuit that and bury the real cause one layer
16
+ * deeper. The pipeline author can still catch missing inputs at
17
+ * spec-validation time by adding `required: true` to spec.inputs.
18
+ *
19
+ * Recursion: objects and arrays are walked; primitives pass through.
20
+ * Strings get the regex substitution. Numbers, booleans, null return
21
+ * unchanged.
22
+ */
23
+ export interface PipelineRefContext {
24
+ inputs: Record<string, unknown>;
25
+ previousOutputs: Record<string, string>;
26
+ }
27
+ export declare function resolveInputRefs(value: unknown, ctx: PipelineRefContext): unknown;
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Resolve pipeline-level template references in skill chain input blocks.
3
+ *
4
+ * Supports two reference flavors (both with and without braces):
5
+ * - `$input.X` / `${input.X}` → ctx.inputs[X]
6
+ * - `$stages.X.output` / `${stages.X.output}` → ctx.previousOutputs[X]
7
+ *
8
+ * Scope (F26-min): only the skill-chain `input:` block is resolved.
9
+ * Prompts keep their existing behavior (LLM interprets literal refs
10
+ * as context markers — works because LLMs are smart).
11
+ *
12
+ * Why "leave literal if missing" instead of throwing:
13
+ * The skill may receive partial input and choose to return an
14
+ * error JSON (which downstream stages can handle). Throwing
15
+ * would short-circuit that and bury the real cause one layer
16
+ * deeper. The pipeline author can still catch missing inputs at
17
+ * spec-validation time by adding `required: true` to spec.inputs.
18
+ *
19
+ * Recursion: objects and arrays are walked; primitives pass through.
20
+ * Strings get the regex substitution. Numbers, booleans, null return
21
+ * unchanged.
22
+ */
23
+ const INPUT_REF_PATTERN = /\$\{?\s*input\.([A-Za-z_][A-Za-z0-9_]*)\s*\}?/g;
24
+ const STAGE_OUTPUT_REF_PATTERN = /\$\{?\s*stages\.([A-Za-z_][A-Za-z0-9_.-]*)\.output\s*\}?/g;
25
+ export function resolveInputRefs(value, ctx) {
26
+ if (typeof value === 'string') {
27
+ return resolveStringRefs(value, ctx);
28
+ }
29
+ if (Array.isArray(value)) {
30
+ return value.map((v) => resolveInputRefs(v, ctx));
31
+ }
32
+ if (value && typeof value === 'object') {
33
+ const out = {};
34
+ for (const [k, v] of Object.entries(value)) {
35
+ out[k] = resolveInputRefs(v, ctx);
36
+ }
37
+ return out;
38
+ }
39
+ return value;
40
+ }
41
+ function resolveStringRefs(text, ctx) {
42
+ let out = text;
43
+ out = out.replace(INPUT_REF_PATTERN, (match, key) => {
44
+ if (Object.prototype.hasOwnProperty.call(ctx.inputs, key)) {
45
+ const v = ctx.inputs[key];
46
+ return stringifyValue(v);
47
+ }
48
+ return match;
49
+ });
50
+ out = out.replace(STAGE_OUTPUT_REF_PATTERN, (match, stageId) => {
51
+ if (Object.prototype.hasOwnProperty.call(ctx.previousOutputs, stageId)) {
52
+ return ctx.previousOutputs[stageId] ?? '';
53
+ }
54
+ return match;
55
+ });
56
+ return out;
57
+ }
58
+ function stringifyValue(v) {
59
+ if (typeof v === 'string')
60
+ return v;
61
+ if (v === null || v === undefined)
62
+ return '';
63
+ return JSON.stringify(v);
64
+ }
package/dist/stages.js CHANGED
@@ -16,6 +16,7 @@ import { StageOutputFormatError, StageSkillVersionMismatchError, StageMCPConfigE
16
16
  import { createModelResolver, } from './model-resolver.js';
17
17
  import { computeSkillContentHash } from './content-hash.js';
18
18
  import { shouldSkipStage } from './when.js';
19
+ import { resolveInputRefs } from './pipeline-refs.js';
19
20
  import { isRetryableStatus, computeBackoffMs, RetryExhaustedError, DEFAULT_RETRY, } from './retry.js';
20
21
  import { NoopEventSink, makeStartedEvent as makePipelineStartedEvent, makeCompletedEvent as makePipelineCompletedEvent, makeFailedEvent as makePipelineFailedEvent, makeStageStartedEvent, makeStageCompletedEvent, makeStageSkippedEvent, makeStageFailedEvent, makeStageRetriedEvent, } from './streaming-events.js';
21
22
  import { validateRuntimeConstraints, collectRuntimeWarnings, defaultRuntimeConstraints, } from './runtime-constraints.js';
@@ -361,7 +362,7 @@ export async function executeStage(stage, pipeline, ctx, deps) {
361
362
  const stageProvider = resolveStageProvider(deps, stage, skillModel);
362
363
  const resolvedInput = typeof chainedInput === 'string'
363
364
  ? resolveStageOutputRefs(chainedInput, ctx.previousOutputs)
364
- : chainedInput;
365
+ : resolveInputRefs(chainedInput, { inputs: ctx.inputs, previousOutputs: ctx.previousOutputs });
365
366
  const { result, durationMs } = await invokeSkill(skill, resolvedInput, previousContext, label, stageProvider, stage.retry, retryCtx, stage.output_format);
366
367
  deps.onLlmResponse?.(`${stage.id}:${use.id}`, result.text, skillModel);
367
368
  lastResult = result;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentsmarket/pipeline-runtime",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
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",