@agentsmarket/pipeline-runtime 0.1.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.
- package/README.md +94 -0
- package/bin/webhook.mjs +11 -0
- package/dist/adapters/minimax.d.ts +31 -0
- package/dist/adapters/minimax.js +69 -0
- package/dist/adapters/openrouter.d.ts +29 -0
- package/dist/adapters/openrouter.js +71 -0
- package/dist/checkpoints.d.ts +142 -0
- package/dist/checkpoints.js +192 -0
- package/dist/composition.d.ts +90 -0
- package/dist/composition.js +108 -0
- package/dist/content-hash.d.ts +7 -0
- package/dist/content-hash.js +17 -0
- package/dist/fallback.d.ts +31 -0
- package/dist/fallback.js +76 -0
- package/dist/index.d.ts +64 -0
- package/dist/index.js +61 -0
- package/dist/model-resolver.d.ts +136 -0
- package/dist/model-resolver.js +36 -0
- package/dist/parallel.d.ts +26 -0
- package/dist/parallel.js +83 -0
- package/dist/pricing.d.ts +57 -0
- package/dist/pricing.js +135 -0
- package/dist/provider-registry.d.ts +190 -0
- package/dist/provider-registry.js +333 -0
- package/dist/resolve-vars.d.ts +91 -0
- package/dist/resolve-vars.js +203 -0
- package/dist/retry.d.ts +40 -0
- package/dist/retry.js +61 -0
- package/dist/runtime-constraints.d.ts +39 -0
- package/dist/runtime-constraints.js +60 -0
- package/dist/stage-output-refs.d.ts +79 -0
- package/dist/stage-output-refs.js +107 -0
- package/dist/stages.d.ts +247 -0
- package/dist/stages.js +633 -0
- package/dist/streaming-events.d.ts +118 -0
- package/dist/streaming-events.js +132 -0
- package/dist/types.d.ts +138 -0
- package/dist/types.js +54 -0
- package/dist/webhook.d.ts +30 -0
- package/dist/webhook.js +160 -0
- package/dist/when.d.ts +55 -0
- package/dist/when.js +165 -0
- package/package.json +42 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pipeline composition — ADR Q10.
|
|
3
|
+
*
|
|
4
|
+
* Allows inline references to other pipelines via uses: "pipeline:NAME@VERSION"
|
|
5
|
+
* (COMPOSITION_USES_PREFIX). Resolves via a fetcher callback and inlines stages
|
|
6
|
+
* with id-prefixing. v0.3 surface; no actual marketplace wiring yet (R6.7
|
|
7
|
+
* server endpoint accepts any pipeline.yaml; composition just normalizes local
|
|
8
|
+
* refs for the executor).
|
|
9
|
+
*/
|
|
10
|
+
export declare const COMPOSITION_USES_PREFIX = "pipeline:";
|
|
11
|
+
export declare const MAX_COMPOSITION_DEPTH = 4;
|
|
12
|
+
export interface PipelineRef {
|
|
13
|
+
readonly id: string;
|
|
14
|
+
readonly version?: string;
|
|
15
|
+
readonly inputs?: Readonly<Record<string, unknown>>;
|
|
16
|
+
}
|
|
17
|
+
export type PipelineFetcher = (id: string, version?: string) => Promise<PipelineLike | null>;
|
|
18
|
+
export interface PipelineLike {
|
|
19
|
+
readonly id?: string;
|
|
20
|
+
readonly name?: string;
|
|
21
|
+
readonly version?: string;
|
|
22
|
+
readonly stages: ReadonlyArray<PipelineStageLike> | PipelineStageLike[];
|
|
23
|
+
}
|
|
24
|
+
export interface PipelineStageLike {
|
|
25
|
+
readonly id: string;
|
|
26
|
+
readonly uses?: string | string[];
|
|
27
|
+
readonly depends_on?: string[];
|
|
28
|
+
[k: string]: unknown;
|
|
29
|
+
}
|
|
30
|
+
export interface ResolvedPipeline {
|
|
31
|
+
readonly ref: PipelineRef;
|
|
32
|
+
readonly pipeline: PipelineLike;
|
|
33
|
+
}
|
|
34
|
+
export interface NestedPipeline {
|
|
35
|
+
readonly parentId: string;
|
|
36
|
+
readonly nested: PipelineLike;
|
|
37
|
+
readonly prefix: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Per-pipeline composition overrides (v0.3 ADR Q4).
|
|
41
|
+
*
|
|
42
|
+
* Declared at pipeline-spec level (e.g. inside `composition:` block in the
|
|
43
|
+
* pipeline YAML). Currently a single knob — max recursion depth — used by
|
|
44
|
+
* `expandComposition` instead of the global `MAX_COMPOSITION_DEPTH` constant
|
|
45
|
+
* when the pipeline sets it.
|
|
46
|
+
*/
|
|
47
|
+
export interface CompositionConfig {
|
|
48
|
+
/** Maximum depth of nested pipeline composition refs. Must be a positive integer. */
|
|
49
|
+
readonly max_depth?: number;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Options bag accepted as the 4th arg of `expandComposition`. Kept
|
|
53
|
+
* separate from `CompositionConfig` (pipeline-level config) so the
|
|
54
|
+
* fetcher can be called with the same signature regardless of whether
|
|
55
|
+
* the caller pulls the config off a parsed YAML or hardcodes it.
|
|
56
|
+
*/
|
|
57
|
+
export interface ExpandCompositionOptions {
|
|
58
|
+
/** Overrides `MAX_COMPOSITION_DEPTH` for this expansion. */
|
|
59
|
+
readonly maxDepth?: number;
|
|
60
|
+
}
|
|
61
|
+
export declare function tryParsePipelineUses(uses: string): PipelineRef | null;
|
|
62
|
+
export declare function resolvePipelineRef(ref: PipelineRef, fetcher: PipelineFetcher): Promise<ResolvedPipeline | null>;
|
|
63
|
+
export declare function injectNestedStages(parentStages: PipelineStageLike[], nested: {
|
|
64
|
+
id: string;
|
|
65
|
+
stages: PipelineStageLike[];
|
|
66
|
+
}, prefix: string): PipelineStageLike[];
|
|
67
|
+
export declare class CompositionDepthError extends Error {
|
|
68
|
+
readonly depth: number;
|
|
69
|
+
readonly maxDepth: number;
|
|
70
|
+
constructor(depth: number, maxDepth?: number);
|
|
71
|
+
}
|
|
72
|
+
export declare class PipelineFetchError extends Error {
|
|
73
|
+
readonly id: string;
|
|
74
|
+
readonly version: string | undefined;
|
|
75
|
+
constructor(id: string, version: string | undefined);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Expand a stage list by inlining any stage whose `uses:` references another
|
|
79
|
+
* pipeline via the `pipeline:NAME@VERSION` prefix. Each recursive call adds
|
|
80
|
+
* one to `depth`; the function refuses to descend past `maxDepth` (default
|
|
81
|
+
* `MAX_COMPOSITION_DEPTH = 4`) to prevent infinite loops from cyclic refs.
|
|
82
|
+
*
|
|
83
|
+
* When `options.maxDepth` is supplied (e.g. via `composition.max_depth` in
|
|
84
|
+
* the pipeline YAML), it overrides the global default for that pipeline.
|
|
85
|
+
* The override is validated as a positive integer — passing 0, a negative
|
|
86
|
+
* number, or a non-integer throws `CompositionDepthError` immediately so
|
|
87
|
+
* the executor surfaces the spec error at validation time rather than
|
|
88
|
+
* silently falling back to the default.
|
|
89
|
+
*/
|
|
90
|
+
export declare function expandComposition(stages: PipelineStageLike[], fetcher: PipelineFetcher, depth?: number, options?: ExpandCompositionOptions): Promise<PipelineStageLike[]>;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pipeline composition — ADR Q10.
|
|
3
|
+
*
|
|
4
|
+
* Allows inline references to other pipelines via uses: "pipeline:NAME@VERSION"
|
|
5
|
+
* (COMPOSITION_USES_PREFIX). Resolves via a fetcher callback and inlines stages
|
|
6
|
+
* with id-prefixing. v0.3 surface; no actual marketplace wiring yet (R6.7
|
|
7
|
+
* server endpoint accepts any pipeline.yaml; composition just normalizes local
|
|
8
|
+
* refs for the executor).
|
|
9
|
+
*/
|
|
10
|
+
export const COMPOSITION_USES_PREFIX = 'pipeline:';
|
|
11
|
+
export const MAX_COMPOSITION_DEPTH = 4;
|
|
12
|
+
export function tryParsePipelineUses(uses) {
|
|
13
|
+
if (!uses.startsWith(COMPOSITION_USES_PREFIX))
|
|
14
|
+
return null;
|
|
15
|
+
const rest = uses.slice(COMPOSITION_USES_PREFIX.length);
|
|
16
|
+
const atIdx = rest.indexOf('@');
|
|
17
|
+
if (atIdx < 0) {
|
|
18
|
+
return { id: rest };
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
id: rest.slice(0, atIdx),
|
|
22
|
+
version: rest.slice(atIdx + 1),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export async function resolvePipelineRef(ref, fetcher) {
|
|
26
|
+
const pipeline = await fetcher(ref.id, ref.version);
|
|
27
|
+
if (!pipeline)
|
|
28
|
+
return null;
|
|
29
|
+
return { ref, pipeline };
|
|
30
|
+
}
|
|
31
|
+
export function injectNestedStages(parentStages, nested, prefix) {
|
|
32
|
+
const childPrefix = `${prefix}.${nested.id}`;
|
|
33
|
+
const renamed = nested.stages.map((s) => ({
|
|
34
|
+
...s,
|
|
35
|
+
id: `${childPrefix}.${s.id}`,
|
|
36
|
+
depends_on: s.depends_on
|
|
37
|
+
? s.depends_on.map((d) => d.includes('.') ? d : `${childPrefix}.${d}`)
|
|
38
|
+
: undefined,
|
|
39
|
+
}));
|
|
40
|
+
return [...parentStages, ...renamed];
|
|
41
|
+
}
|
|
42
|
+
export class CompositionDepthError extends Error {
|
|
43
|
+
depth;
|
|
44
|
+
maxDepth;
|
|
45
|
+
constructor(depth, maxDepth = MAX_COMPOSITION_DEPTH) {
|
|
46
|
+
super(`Pipeline composition exceeded max depth (${maxDepth}); abort to prevent infinite recursion`);
|
|
47
|
+
this.name = 'COMPOSITION_DEPTH_EXCEEDED';
|
|
48
|
+
this.depth = depth;
|
|
49
|
+
this.maxDepth = maxDepth;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export class PipelineFetchError extends Error {
|
|
53
|
+
id;
|
|
54
|
+
version;
|
|
55
|
+
constructor(id, version) {
|
|
56
|
+
const suffix = version ? `@${version}` : '';
|
|
57
|
+
super(`Pipeline fetch failed: ${id}${suffix}`);
|
|
58
|
+
this.name = 'PIPELINE_FETCH_FAILED';
|
|
59
|
+
this.id = id;
|
|
60
|
+
this.version = version;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function prefixChildStages(stages, prefix) {
|
|
64
|
+
return stages.map((s) => ({
|
|
65
|
+
...s,
|
|
66
|
+
id: `${prefix}.${s.id}`,
|
|
67
|
+
depends_on: s.depends_on?.map((d) => (d.includes('.') ? d : `${prefix}.${d}`)),
|
|
68
|
+
}));
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Expand a stage list by inlining any stage whose `uses:` references another
|
|
72
|
+
* pipeline via the `pipeline:NAME@VERSION` prefix. Each recursive call adds
|
|
73
|
+
* one to `depth`; the function refuses to descend past `maxDepth` (default
|
|
74
|
+
* `MAX_COMPOSITION_DEPTH = 4`) to prevent infinite loops from cyclic refs.
|
|
75
|
+
*
|
|
76
|
+
* When `options.maxDepth` is supplied (e.g. via `composition.max_depth` in
|
|
77
|
+
* the pipeline YAML), it overrides the global default for that pipeline.
|
|
78
|
+
* The override is validated as a positive integer — passing 0, a negative
|
|
79
|
+
* number, or a non-integer throws `CompositionDepthError` immediately so
|
|
80
|
+
* the executor surfaces the spec error at validation time rather than
|
|
81
|
+
* silently falling back to the default.
|
|
82
|
+
*/
|
|
83
|
+
export async function expandComposition(stages, fetcher, depth = 0, options = {}) {
|
|
84
|
+
const maxDepth = options.maxDepth ?? MAX_COMPOSITION_DEPTH;
|
|
85
|
+
if (!Number.isInteger(maxDepth) || maxDepth < 1) {
|
|
86
|
+
throw new CompositionDepthError(depth, maxDepth);
|
|
87
|
+
}
|
|
88
|
+
if (depth >= maxDepth) {
|
|
89
|
+
throw new CompositionDepthError(depth, maxDepth);
|
|
90
|
+
}
|
|
91
|
+
const expanded = [];
|
|
92
|
+
for (const stage of stages) {
|
|
93
|
+
if (typeof stage.uses === 'string') {
|
|
94
|
+
const ref = tryParsePipelineUses(stage.uses);
|
|
95
|
+
if (ref) {
|
|
96
|
+
const child = await fetcher(ref.id, ref.version);
|
|
97
|
+
if (!child)
|
|
98
|
+
throw new PipelineFetchError(ref.id, ref.version);
|
|
99
|
+
const childStages = await expandComposition(child.stages.map((s) => ({ ...s })), fetcher, depth + 1, { maxDepth });
|
|
100
|
+
const renamed = prefixChildStages(childStages, stage.id);
|
|
101
|
+
expanded.push(...renamed);
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
expanded.push(stage);
|
|
106
|
+
}
|
|
107
|
+
return expanded;
|
|
108
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare function bufToHex(buf: ArrayBuffer): string;
|
|
2
|
+
export declare function sha256Hex(input: string): Promise<string>;
|
|
3
|
+
export declare function computeSkillContentHash(skill: {
|
|
4
|
+
full_md?: string;
|
|
5
|
+
version?: string;
|
|
6
|
+
author_agent_id?: string;
|
|
7
|
+
}): Promise<string>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export function bufToHex(buf) {
|
|
2
|
+
const bytes = new Uint8Array(buf);
|
|
3
|
+
let out = '';
|
|
4
|
+
for (const b of bytes)
|
|
5
|
+
out += b.toString(16).padStart(2, '0');
|
|
6
|
+
return out;
|
|
7
|
+
}
|
|
8
|
+
export async function sha256Hex(input) {
|
|
9
|
+
const digest = await globalThis.crypto.subtle.digest('SHA-256', new TextEncoder().encode(input));
|
|
10
|
+
return bufToHex(digest);
|
|
11
|
+
}
|
|
12
|
+
export async function computeSkillContentHash(skill) {
|
|
13
|
+
const body = (skill.full_md ?? '').trim();
|
|
14
|
+
const version = (skill.version ?? '0.0.0').trim();
|
|
15
|
+
const author = (skill.author_agent_id ?? '').toLowerCase().trim();
|
|
16
|
+
return sha256Hex(`${body}\n---\nversion:${version}\nauthor:${author}`);
|
|
17
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { LLMProvider, GenerateOptions, GenerateResult } from './types.js';
|
|
2
|
+
import type { ZodSchema } from 'zod';
|
|
3
|
+
/**
|
|
4
|
+
* FallbackProvider — tries providers in order on failure.
|
|
5
|
+
*
|
|
6
|
+
* Use for: resilience (if MiniMax returns 5xx, retry on OpenRouter).
|
|
7
|
+
* NOT for: cost optimization (use direct provider).
|
|
8
|
+
*
|
|
9
|
+
* Strategy:
|
|
10
|
+
* 1. Try primary provider
|
|
11
|
+
* 2. On failure (any error), log + try fallback
|
|
12
|
+
* 3. If all fail, throw the last error
|
|
13
|
+
*
|
|
14
|
+
* Total attempts = providers.length
|
|
15
|
+
*
|
|
16
|
+
* Models / simpleModel / complexModel / generateJson all delegate to the
|
|
17
|
+
* primary provider (first in list). The fallback list affects only
|
|
18
|
+
* generateText (the only call that can fail at runtime).
|
|
19
|
+
*/
|
|
20
|
+
export declare class FallbackProvider implements LLMProvider {
|
|
21
|
+
readonly name = "fallback";
|
|
22
|
+
readonly providers: LLMProvider[];
|
|
23
|
+
readonly models: readonly string[];
|
|
24
|
+
readonly simpleModel: string;
|
|
25
|
+
readonly complexModel: string;
|
|
26
|
+
constructor(providers: LLMProvider[]);
|
|
27
|
+
supports(model: string): boolean;
|
|
28
|
+
generateText(prompt: string, opts: GenerateOptions): Promise<GenerateResult>;
|
|
29
|
+
generateJson<T>(prompt: string, schema: ZodSchema<T>, opts: GenerateOptions): Promise<T>;
|
|
30
|
+
}
|
|
31
|
+
export declare function createFallbackProvider(providers: LLMProvider[]): LLMProvider;
|
package/dist/fallback.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FallbackProvider — tries providers in order on failure.
|
|
3
|
+
*
|
|
4
|
+
* Use for: resilience (if MiniMax returns 5xx, retry on OpenRouter).
|
|
5
|
+
* NOT for: cost optimization (use direct provider).
|
|
6
|
+
*
|
|
7
|
+
* Strategy:
|
|
8
|
+
* 1. Try primary provider
|
|
9
|
+
* 2. On failure (any error), log + try fallback
|
|
10
|
+
* 3. If all fail, throw the last error
|
|
11
|
+
*
|
|
12
|
+
* Total attempts = providers.length
|
|
13
|
+
*
|
|
14
|
+
* Models / simpleModel / complexModel / generateJson all delegate to the
|
|
15
|
+
* primary provider (first in list). The fallback list affects only
|
|
16
|
+
* generateText (the only call that can fail at runtime).
|
|
17
|
+
*/
|
|
18
|
+
export class FallbackProvider {
|
|
19
|
+
name = 'fallback';
|
|
20
|
+
providers;
|
|
21
|
+
models;
|
|
22
|
+
simpleModel;
|
|
23
|
+
complexModel;
|
|
24
|
+
constructor(providers) {
|
|
25
|
+
if (providers.length === 0) {
|
|
26
|
+
throw new Error('FallbackProvider requires at least one provider');
|
|
27
|
+
}
|
|
28
|
+
this.providers = providers;
|
|
29
|
+
const primary = providers[0];
|
|
30
|
+
const seen = new Set();
|
|
31
|
+
const all = [];
|
|
32
|
+
for (const p of providers) {
|
|
33
|
+
for (const m of p.models) {
|
|
34
|
+
if (!seen.has(m)) {
|
|
35
|
+
seen.add(m);
|
|
36
|
+
all.push(m);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
this.models = all;
|
|
41
|
+
this.simpleModel = primary.simpleModel;
|
|
42
|
+
this.complexModel = primary.complexModel;
|
|
43
|
+
}
|
|
44
|
+
supports(model) {
|
|
45
|
+
return this.providers.some((p) => p.supports(model));
|
|
46
|
+
}
|
|
47
|
+
async generateText(prompt, opts) {
|
|
48
|
+
const errors = [];
|
|
49
|
+
for (let i = 0; i < this.providers.length; i++) {
|
|
50
|
+
const p = this.providers[i];
|
|
51
|
+
try {
|
|
52
|
+
return await p.generateText(prompt, opts);
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
errors.push({ name: p.name, error: e });
|
|
56
|
+
if (i === this.providers.length - 1)
|
|
57
|
+
break;
|
|
58
|
+
console.warn(`[fallback] ${p.name} failed: ${e instanceof Error ? e.message : String(e)}. Trying next.`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const last = errors[errors.length - 1];
|
|
62
|
+
const summary = errors.map((e) => `${e.name}: ${e.error instanceof Error ? e.error.message : String(e.error)}`).join(' | ');
|
|
63
|
+
const msg = `all providers failed (${this.providers.length} attempts): ${summary}`;
|
|
64
|
+
if (last?.error instanceof Error) {
|
|
65
|
+
last.error.message = msg;
|
|
66
|
+
throw last.error;
|
|
67
|
+
}
|
|
68
|
+
throw new Error(msg);
|
|
69
|
+
}
|
|
70
|
+
async generateJson(prompt, schema, opts) {
|
|
71
|
+
return this.providers[0].generateJson(prompt, schema, opts);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
export function createFallbackProvider(providers) {
|
|
75
|
+
return providers.length === 1 ? providers[0] : new FallbackProvider(providers);
|
|
76
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @agentsmarket/pipeline-runtime — multi-stage AI workflow executor.
|
|
3
|
+
*
|
|
4
|
+
* Public API: providers (MiniMax, OpenRouter), stage executor (executeStage,
|
|
5
|
+
* runPipelineV2), pricing (PricingResolver), model resolver.
|
|
6
|
+
*/
|
|
7
|
+
export type { LLMProvider, GenerateOptions, GenerateResult, Complexity, ProviderRegistry, TokenUsage, OutputFormat, OutputFormatViolation, } from './types.js';
|
|
8
|
+
export { resolveProvider, StageOutputFormatError, StageSkillVersionMismatchError, StageMCPConfigError, } from './types.js';
|
|
9
|
+
export { MiniMaxProvider } from './adapters/minimax.js';
|
|
10
|
+
export type { MiniMaxProviderOptions } from './adapters/minimax.js';
|
|
11
|
+
export { OpenRouterProvider } from './adapters/openrouter.js';
|
|
12
|
+
export type { OpenRouterProviderOptions } from './adapters/openrouter.js';
|
|
13
|
+
export { FallbackProvider, createFallbackProvider } from './fallback.js';
|
|
14
|
+
export { PROVIDER_REGISTRY, getProvider, validateProviderName, supportsModel, validateProviderModel, listProviders, listSupportedModels, validateR6Spec, migrateProviderField, ProviderSpecNotFoundError, ProviderModelMismatchError, LLMProviderRegistry, ProviderMismatchError, UnknownProviderError, type Provider, type ProviderSpec, type R6StageInput, type R6SpecInput, type R6ValidationResult, } from './provider-registry.js';
|
|
15
|
+
export { expandPipelineText, resolveEnvVars, resolveEnvVarsInObject, loadPipelineYaml, parseVariableSpec, MissingEnvVarError, } from './resolve-vars.js';
|
|
16
|
+
export type { EnvLike } from './resolve-vars.js';
|
|
17
|
+
export { isRetryableStatus, computeBackoffMs, RetryExhaustedError, RetryAttemptError, DEFAULT_RETRY, DEFAULT_RETRYABLE_STATUSES, } from './retry.js';
|
|
18
|
+
export type { RetryConfig, RetryBackoff } from './retry.js';
|
|
19
|
+
export { parseComparison, parseWhenLiteral, evaluateComparison, evaluateWhen, shouldSkipStage, validateWhenShape, WhenParseError, } from './when.js';
|
|
20
|
+
export type { WhenCondition, WhenCompareOp, ParsedComparison } from './when.js';
|
|
21
|
+
export { NoopEventSink, CallbackEventSink, createDefaultSink, makeStageRetriedEvent, } from './streaming-events.js';
|
|
22
|
+
export type { PipelineEvent, PipelineEventType, PipelineEventSink, StageStartedEvent, StageCompletedEvent, StageFailedEvent, StageSkippedEvent, StageRetriedEvent, PipelineStartedEvent, PipelineCompletedEvent, PipelineFailedEvent, } from './streaming-events.js';
|
|
23
|
+
export { validateRuntimeConstraints, collectRuntimeWarnings, defaultRuntimeConstraints, mergeRuntimeConstraints, } from './runtime-constraints.js';
|
|
24
|
+
export type { NetworkConstraint, RequiredSkill, RuntimeConstraints, ConstraintContext, ConstraintWarning, StageLikeForConstraints, } from './runtime-constraints.js';
|
|
25
|
+
export { groupIndependentStages, topologicalSort, extractDepIds, CyclicDependencyError, } from './parallel.js';
|
|
26
|
+
export type { ExecutionGroup } from './parallel.js';
|
|
27
|
+
export { tryParsePipelineUses, resolvePipelineRef, injectNestedStages, expandComposition, COMPOSITION_USES_PREFIX, MAX_COMPOSITION_DEPTH, CompositionDepthError, PipelineFetchError, } from './composition.js';
|
|
28
|
+
export type { PipelineRef, PipelineFetcher, ResolvedPipeline, NestedPipeline, CompositionConfig, ExpandCompositionOptions, } from './composition.js';
|
|
29
|
+
export { tryParseStageOutputRef, resolveStageOutputRefs, UnresolvedStageOutputRefError, } from './stage-output-refs.js';
|
|
30
|
+
export type { ParsedStageOutputRef } from './stage-output-refs.js';
|
|
31
|
+
export type { PricingResolver, PricingEntry } from './pricing.js';
|
|
32
|
+
export { OpenRouterPricingResolver, MiniMaxPricingResolver, StaticPricingResolver, CompositePricingResolver, createDefaultPricingResolver, } from './pricing.js';
|
|
33
|
+
export { buildCheckpoint, restoreFromCheckpoint, R2CheckpointStorage, InMemoryCheckpointStorage, CheckpointLoadError, CheckpointSaveError, CheckpointSchemaMismatchError, CHECKPOINT_SCHEMA_VERSION, } from './checkpoints.js';
|
|
34
|
+
export type { PipelineCheckpoint, CheckpointStorage, R2BucketLike, CompletedStageRecord, RestoreResult, } from './checkpoints.js';
|
|
35
|
+
export { createModelResolver, resolveModelSync, DEFAULT_MODEL, type ModelResolver, type ModelResolverOptions, type PipelineLike, type PipelineStageLike, type SkillLike, } from './model-resolver.js';
|
|
36
|
+
export { sha256Hex, computeSkillContentHash, } from './content-hash.js';
|
|
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 interface PipelineStageSpec {
|
|
39
|
+
id: string;
|
|
40
|
+
model: string;
|
|
41
|
+
system?: string;
|
|
42
|
+
prompt: string;
|
|
43
|
+
depends_on?: string[];
|
|
44
|
+
}
|
|
45
|
+
export interface PipelineSpec {
|
|
46
|
+
name: string;
|
|
47
|
+
version: string;
|
|
48
|
+
stages: PipelineStageSpec[];
|
|
49
|
+
}
|
|
50
|
+
export interface PipelineContext {
|
|
51
|
+
provider: import('./types.js').LLMProvider;
|
|
52
|
+
inputs: Record<string, unknown>;
|
|
53
|
+
outputs: Record<string, string>;
|
|
54
|
+
}
|
|
55
|
+
export interface PipelineHooks {
|
|
56
|
+
onStageStart?: (stageId: string) => void;
|
|
57
|
+
onStageComplete?: (stageId: string, ms: number, output: string) => void;
|
|
58
|
+
}
|
|
59
|
+
import type { LLMProvider } from './types.js';
|
|
60
|
+
export declare function runStage(stage: PipelineStageSpec, ctx: PipelineContext): Promise<string>;
|
|
61
|
+
export declare function runPipeline(spec: PipelineSpec, inputs: Record<string, unknown>, opts: {
|
|
62
|
+
provider: LLMProvider;
|
|
63
|
+
hooks?: PipelineHooks;
|
|
64
|
+
}): Promise<Record<string, string>>;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @agentsmarket/pipeline-runtime — multi-stage AI workflow executor.
|
|
3
|
+
*
|
|
4
|
+
* Public API: providers (MiniMax, OpenRouter), stage executor (executeStage,
|
|
5
|
+
* runPipelineV2), pricing (PricingResolver), model resolver.
|
|
6
|
+
*/
|
|
7
|
+
export { resolveProvider, StageOutputFormatError, StageSkillVersionMismatchError, StageMCPConfigError, } from './types.js';
|
|
8
|
+
export { MiniMaxProvider } from './adapters/minimax.js';
|
|
9
|
+
export { OpenRouterProvider } from './adapters/openrouter.js';
|
|
10
|
+
export { FallbackProvider, createFallbackProvider } from './fallback.js';
|
|
11
|
+
export { PROVIDER_REGISTRY, getProvider, validateProviderName, supportsModel, validateProviderModel, listProviders, listSupportedModels, validateR6Spec, migrateProviderField, ProviderSpecNotFoundError, ProviderModelMismatchError, LLMProviderRegistry, ProviderMismatchError, UnknownProviderError, } from './provider-registry.js';
|
|
12
|
+
export { expandPipelineText, resolveEnvVars, resolveEnvVarsInObject, loadPipelineYaml, parseVariableSpec, MissingEnvVarError, } from './resolve-vars.js';
|
|
13
|
+
export { isRetryableStatus, computeBackoffMs, RetryExhaustedError, RetryAttemptError, DEFAULT_RETRY, DEFAULT_RETRYABLE_STATUSES, } from './retry.js';
|
|
14
|
+
export { parseComparison, parseWhenLiteral, evaluateComparison, evaluateWhen, shouldSkipStage, validateWhenShape, WhenParseError, } from './when.js';
|
|
15
|
+
export { NoopEventSink, CallbackEventSink, createDefaultSink, makeStageRetriedEvent, } from './streaming-events.js';
|
|
16
|
+
export { validateRuntimeConstraints, collectRuntimeWarnings, defaultRuntimeConstraints, mergeRuntimeConstraints, } from './runtime-constraints.js';
|
|
17
|
+
export { groupIndependentStages, topologicalSort, extractDepIds, CyclicDependencyError, } from './parallel.js';
|
|
18
|
+
export { tryParsePipelineUses, resolvePipelineRef, injectNestedStages, expandComposition, COMPOSITION_USES_PREFIX, MAX_COMPOSITION_DEPTH, CompositionDepthError, PipelineFetchError, } from './composition.js';
|
|
19
|
+
export { tryParseStageOutputRef, resolveStageOutputRefs, UnresolvedStageOutputRefError, } from './stage-output-refs.js';
|
|
20
|
+
export { OpenRouterPricingResolver, MiniMaxPricingResolver, StaticPricingResolver, CompositePricingResolver, createDefaultPricingResolver, } from './pricing.js';
|
|
21
|
+
export { buildCheckpoint, restoreFromCheckpoint, R2CheckpointStorage, InMemoryCheckpointStorage, CheckpointLoadError, CheckpointSaveError, CheckpointSchemaMismatchError, CHECKPOINT_SCHEMA_VERSION, } from './checkpoints.js';
|
|
22
|
+
export { createModelResolver, resolveModelSync, DEFAULT_MODEL, } from './model-resolver.js';
|
|
23
|
+
export { sha256Hex, computeSkillContentHash, } from './content-hash.js';
|
|
24
|
+
export { executeStage, runPipelineV2, makeWhenResolve, parseUsesEntry, parseUsesList, validateOutputFormat, StageNotFoundError, StageForbiddenError, StageBadConfigError, } from './stages.js';
|
|
25
|
+
export async function runStage(stage, ctx) {
|
|
26
|
+
const vars = [];
|
|
27
|
+
for (const [key, val] of Object.entries(ctx.outputs)) {
|
|
28
|
+
vars.push(`\`\`\`\n${key}:\n${val}\n\`\`\``);
|
|
29
|
+
}
|
|
30
|
+
const injected = vars.length > 0
|
|
31
|
+
? `Previous stage outputs:\n${vars.join('\n\n')}\n\n---\n\n${stage.prompt}`
|
|
32
|
+
: stage.prompt;
|
|
33
|
+
let inputStr = '';
|
|
34
|
+
for (const [k, v] of Object.entries(ctx.inputs)) {
|
|
35
|
+
inputStr += `${k}: ${JSON.stringify(v)}\n`;
|
|
36
|
+
}
|
|
37
|
+
const fullPrompt = `Inputs:\n${inputStr}\n---\n\n${injected}`;
|
|
38
|
+
const result = await ctx.provider.generateText(fullPrompt, {
|
|
39
|
+
system: stage.system,
|
|
40
|
+
complexity: stage.model.includes('M3') ? 'complex' : 'simple',
|
|
41
|
+
});
|
|
42
|
+
return result.text;
|
|
43
|
+
}
|
|
44
|
+
export async function runPipeline(spec, inputs, opts) {
|
|
45
|
+
const outputs = {};
|
|
46
|
+
for (const stage of spec.stages) {
|
|
47
|
+
if (stage.depends_on) {
|
|
48
|
+
for (const dep of stage.depends_on) {
|
|
49
|
+
if (!outputs[dep])
|
|
50
|
+
throw new Error(`Stage ${stage.id} depends on missing ${dep}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
opts.hooks?.onStageStart?.(stage.id);
|
|
54
|
+
const t0 = Date.now();
|
|
55
|
+
const text = await runStage(stage, { provider: opts.provider, inputs, outputs });
|
|
56
|
+
const ms = Date.now() - t0;
|
|
57
|
+
outputs[stage.id] = text;
|
|
58
|
+
opts.hooks?.onStageComplete?.(stage.id, ms, text);
|
|
59
|
+
}
|
|
60
|
+
return outputs;
|
|
61
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model resolver — determines which model runs for a given stage.
|
|
3
|
+
*
|
|
4
|
+
* Resolution chain (high → low priority):
|
|
5
|
+
* 1. stage.model — explicit per-stage override
|
|
6
|
+
* 2. pipeline.defaults.model — pipeline-level default
|
|
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
|
|
11
|
+
*
|
|
12
|
+
* Cost of a stage is always based on the resolved model, regardless of who declared it.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* v0.2 stage schema (extends v0.1 with skill_enforcement + mcp + fs).
|
|
16
|
+
*
|
|
17
|
+
* Backward-compat: all new fields are optional. Old v0.1 stages still work.
|
|
18
|
+
*/
|
|
19
|
+
export interface PipelineStageLike {
|
|
20
|
+
id: string;
|
|
21
|
+
model?: string;
|
|
22
|
+
/** @deprecated Use `uses@version` form instead. */
|
|
23
|
+
uses?: string | string[];
|
|
24
|
+
/** @deprecated Explicit list instead of inline. */
|
|
25
|
+
uses_version?: string;
|
|
26
|
+
input?: unknown;
|
|
27
|
+
system?: string;
|
|
28
|
+
prompt?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Output format constraint for post-LLM validation.
|
|
31
|
+
* Default: 'text' (no validation).
|
|
32
|
+
*/
|
|
33
|
+
output_format?: 'text' | 'structured_json' | 'code' | 'markdown';
|
|
34
|
+
/**
|
|
35
|
+
* Required JSON keys when `output_format: structured_json`.
|
|
36
|
+
* Dotted paths supported (`key_points.0.name`).
|
|
37
|
+
* Triggers `StageOutputFormatError` if any are missing in LLM output.
|
|
38
|
+
*/
|
|
39
|
+
fields?: string[];
|
|
40
|
+
/**
|
|
41
|
+
* MCP server names available to this stage. v0.2 NEW (forward-compat).
|
|
42
|
+
* Validated against executor's MCP registry, not yet executed.
|
|
43
|
+
*/
|
|
44
|
+
mcp_servers?: string[];
|
|
45
|
+
/**
|
|
46
|
+
* Tool name allowlist from declared mcp_servers. v0.2 NEW (forward-compat).
|
|
47
|
+
* Validated against server-known tool list, not yet executed.
|
|
48
|
+
*/
|
|
49
|
+
mcp_tools?: string[];
|
|
50
|
+
/**
|
|
51
|
+
* CLI-only local working directory. v0.2 NEW.
|
|
52
|
+
* Server execution emits "working_dir_ignored_on_server" in provenance
|
|
53
|
+
* and continues with the field omitted. CLI creates the dir and exposes
|
|
54
|
+
* file helpers in stage context.
|
|
55
|
+
*/
|
|
56
|
+
working_dir?: string;
|
|
57
|
+
/**
|
|
58
|
+
* Provider name (e.g. "minimax", "openrouter"). v0.3 NEW (optional in
|
|
59
|
+
* v0.3 transition; required once pickProvider auto-dispatch is removed).
|
|
60
|
+
* Model is opaque to runtime — runtime queries provider.supports(model).
|
|
61
|
+
*/
|
|
62
|
+
provider?: string;
|
|
63
|
+
/**
|
|
64
|
+
* Conditional branch expression. v0.3 NEW.
|
|
65
|
+
* When evaluated falsy, stage is SKIPPED at runtime and produces an
|
|
66
|
+
* empty-string output. Downstream stages referencing it receive ''.
|
|
67
|
+
* Static DAG topology — branch decision is runtime, not compile-time.
|
|
68
|
+
* Reference forms (per ADR Q5): stages.X.output / inputs.X.
|
|
69
|
+
*/
|
|
70
|
+
when?: import('./when.js').WhenCondition;
|
|
71
|
+
/**
|
|
72
|
+
* Explicit stage IDs this stage depends on. v0.3 NEW (per ADR Q7).
|
|
73
|
+
* Three accepted shapes — `depends_on`, `requires`, `needs` — all
|
|
74
|
+
* contribute edges to the DAG used by `groupIndependentStages`
|
|
75
|
+
* (R10.5). All optional; absence = no upstream deps.
|
|
76
|
+
* `needs` entries are dot-paths like `stages.x.outputs.y`; the
|
|
77
|
+
* parallel module extracts the leading stage id.
|
|
78
|
+
*/
|
|
79
|
+
depends_on?: string[];
|
|
80
|
+
/** Alias of `depends_on`. v0.3 NEW (per ADR Q7). */
|
|
81
|
+
requires?: string[];
|
|
82
|
+
/** Alias of `depends_on` but with dot-path outputs. v0.3 NEW (per ADR Q7). */
|
|
83
|
+
needs?: string[];
|
|
84
|
+
/**
|
|
85
|
+
* Per-stage retry config. v0.3 NEW (R10.1, ADR Q3). Same-provider
|
|
86
|
+
* exponential/linear/fixed backoff on transient HTTP statuses
|
|
87
|
+
* (429/503 by default). Distinct from `run_if` which is a
|
|
88
|
+
* compensation gate (different provider/model).
|
|
89
|
+
*
|
|
90
|
+
* Configured at YAML-side via:
|
|
91
|
+
* retry:
|
|
92
|
+
* attempts: 5 # max attempts incl. first try (default 3)
|
|
93
|
+
* backoff: exponential # exponential|linear|fixed (default exponential)
|
|
94
|
+
* initial_ms: 500 # base delay before first retry (default 1000)
|
|
95
|
+
* retryable_status: [429,503,500] # statuses that trigger retry (default [429,503])
|
|
96
|
+
*
|
|
97
|
+
* When omitted, executor still retries transient statuses with the
|
|
98
|
+
* DEFAULT_RETRY config — R10.1.b wiring is ON by default since
|
|
99
|
+
* marketplaces have a strong interest in surviving upstream blips.
|
|
100
|
+
* Callers wanting zero-retry semantics pass `attempts: 1`.
|
|
101
|
+
*/
|
|
102
|
+
retry?: import('./retry.js').RetryConfig;
|
|
103
|
+
}
|
|
104
|
+
export interface PipelineLike {
|
|
105
|
+
name?: string;
|
|
106
|
+
version?: string;
|
|
107
|
+
defaults?: {
|
|
108
|
+
model?: string;
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
export interface SkillLike {
|
|
112
|
+
id: string;
|
|
113
|
+
name?: string;
|
|
114
|
+
/** v0.2 NEW: skill version (semver string). Defaults to '0.0.0' if absent. */
|
|
115
|
+
version?: string;
|
|
116
|
+
/** v0.2 NEW: keccak256(full_md + version + author). Server pre-computes + persists. */
|
|
117
|
+
content_hash?: string;
|
|
118
|
+
preferred_model?: string;
|
|
119
|
+
full_md?: string;
|
|
120
|
+
description?: string;
|
|
121
|
+
is_private?: number;
|
|
122
|
+
granted_to?: string;
|
|
123
|
+
author_agent_id?: string;
|
|
124
|
+
}
|
|
125
|
+
export interface ModelResolver {
|
|
126
|
+
resolve(stage: PipelineStageLike, pipeline?: PipelineLike, skill?: SkillLike): Promise<string>;
|
|
127
|
+
resolveSync(stage: PipelineStageLike, pipeline?: PipelineLike, skill?: SkillLike): string;
|
|
128
|
+
}
|
|
129
|
+
export interface ModelResolverOptions {
|
|
130
|
+
agentDefault?: string;
|
|
131
|
+
envDefault?: string;
|
|
132
|
+
hardcodedDefault?: string;
|
|
133
|
+
}
|
|
134
|
+
export declare const DEFAULT_MODEL = "MiniMax-M3";
|
|
135
|
+
export declare function createModelResolver(opts?: ModelResolverOptions): ModelResolver;
|
|
136
|
+
export declare function resolveModelSync(stage: PipelineStageLike, pipeline?: PipelineLike, skill?: SkillLike, opts?: ModelResolverOptions): string;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model resolver — determines which model runs for a given stage.
|
|
3
|
+
*
|
|
4
|
+
* Resolution chain (high → low priority):
|
|
5
|
+
* 1. stage.model — explicit per-stage override
|
|
6
|
+
* 2. pipeline.defaults.model — pipeline-level default
|
|
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
|
|
11
|
+
*
|
|
12
|
+
* Cost of a stage is always based on the resolved model, regardless of who declared it.
|
|
13
|
+
*/
|
|
14
|
+
export const DEFAULT_MODEL = 'MiniMax-M3';
|
|
15
|
+
export function createModelResolver(opts = {}) {
|
|
16
|
+
const hardcoded = opts.hardcodedDefault ?? DEFAULT_MODEL;
|
|
17
|
+
function pick(stage, pipeline, skill) {
|
|
18
|
+
return stage.model
|
|
19
|
+
?? pipeline?.defaults?.model
|
|
20
|
+
?? skill?.preferred_model
|
|
21
|
+
?? opts.agentDefault
|
|
22
|
+
?? opts.envDefault
|
|
23
|
+
?? hardcoded;
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
async resolve(stage, pipeline, skill) {
|
|
27
|
+
return pick(stage, pipeline, skill);
|
|
28
|
+
},
|
|
29
|
+
resolveSync(stage, pipeline, skill) {
|
|
30
|
+
return pick(stage, pipeline, skill);
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export function resolveModelSync(stage, pipeline, skill, opts = {}) {
|
|
35
|
+
return createModelResolver(opts).resolveSync(stage, pipeline, skill);
|
|
36
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parallel execution group detection — ADR Q7.
|
|
3
|
+
*
|
|
4
|
+
* Given a set of stages with potential depends_on / uses_version references,
|
|
5
|
+
* group them into ExecutionGroups where each group can be safely executed
|
|
6
|
+
* in parallel (no inter-stage dep inside a group).
|
|
7
|
+
*
|
|
8
|
+
* Conservative default: ambiguous deps fall back to linear order.
|
|
9
|
+
*/
|
|
10
|
+
export interface ExecutionGroup {
|
|
11
|
+
readonly parallel: boolean;
|
|
12
|
+
readonly stages: ReadonlyArray<PipelineStageDep>;
|
|
13
|
+
}
|
|
14
|
+
export interface PipelineStageDep {
|
|
15
|
+
readonly id: string;
|
|
16
|
+
readonly depends_on?: readonly string[];
|
|
17
|
+
readonly uses?: string | string[];
|
|
18
|
+
readonly uses_version?: string;
|
|
19
|
+
}
|
|
20
|
+
export declare class CyclicDependencyError extends Error {
|
|
21
|
+
readonly cycle: string[];
|
|
22
|
+
constructor(cycle: string[]);
|
|
23
|
+
}
|
|
24
|
+
export declare function extractDepIds(stage: PipelineStageDep): Set<string>;
|
|
25
|
+
export declare function topologicalSort(stages: PipelineStageDep[]): PipelineStageDep[];
|
|
26
|
+
export declare function groupIndependentStages(stages: PipelineStageDep[]): ExecutionGroup[];
|