@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
package/dist/parallel.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
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 class CyclicDependencyError extends Error {
|
|
11
|
+
cycle;
|
|
12
|
+
constructor(cycle) {
|
|
13
|
+
super(`Cyclic dependency detected among stages: ${cycle.join(' -> ')}`);
|
|
14
|
+
this.cycle = cycle;
|
|
15
|
+
this.name = 'CyclicDependencyError';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export function extractDepIds(stage) {
|
|
19
|
+
const deps = new Set();
|
|
20
|
+
if (stage.depends_on) {
|
|
21
|
+
for (const d of stage.depends_on)
|
|
22
|
+
deps.add(d);
|
|
23
|
+
}
|
|
24
|
+
return deps;
|
|
25
|
+
}
|
|
26
|
+
export function topologicalSort(stages) {
|
|
27
|
+
const byId = new Map();
|
|
28
|
+
for (const s of stages) {
|
|
29
|
+
if (byId.has(s.id))
|
|
30
|
+
throw new CyclicDependencyError([s.id, s.id]);
|
|
31
|
+
byId.set(s.id, s);
|
|
32
|
+
}
|
|
33
|
+
const visited = new Set();
|
|
34
|
+
const onStack = new Set();
|
|
35
|
+
const out = [];
|
|
36
|
+
function visit(s, path) {
|
|
37
|
+
if (visited.has(s.id))
|
|
38
|
+
return;
|
|
39
|
+
if (onStack.has(s.id)) {
|
|
40
|
+
throw new CyclicDependencyError([...path, s.id]);
|
|
41
|
+
}
|
|
42
|
+
onStack.add(s.id);
|
|
43
|
+
for (const dep of extractDepIds(s)) {
|
|
44
|
+
const target = byId.get(dep);
|
|
45
|
+
if (target)
|
|
46
|
+
visit(target, [...path, s.id]);
|
|
47
|
+
}
|
|
48
|
+
onStack.delete(s.id);
|
|
49
|
+
visited.add(s.id);
|
|
50
|
+
out.push(s);
|
|
51
|
+
}
|
|
52
|
+
for (const s of stages)
|
|
53
|
+
visit(s, []);
|
|
54
|
+
return out;
|
|
55
|
+
}
|
|
56
|
+
export function groupIndependentStages(stages) {
|
|
57
|
+
if (stages.length === 0)
|
|
58
|
+
return [];
|
|
59
|
+
const sorted = topologicalSort(stages);
|
|
60
|
+
const groups = [];
|
|
61
|
+
for (const stage of sorted) {
|
|
62
|
+
const deps = extractDepIds(stage);
|
|
63
|
+
const stageIdsInPriorGroups = new Set();
|
|
64
|
+
let placed = false;
|
|
65
|
+
for (let g = 0; g < groups.length; g++) {
|
|
66
|
+
const allDepsInPriorGroups = Array.from(deps).every((d) => stageIdsInPriorGroups.has(d));
|
|
67
|
+
if (allDepsInPriorGroups) {
|
|
68
|
+
groups[g] = { parallel: groups[g].parallel, stages: [...groups[g].stages, stage] };
|
|
69
|
+
placed = true;
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
for (const s of groups[g].stages)
|
|
73
|
+
stageIdsInPriorGroups.add(s.id);
|
|
74
|
+
}
|
|
75
|
+
if (!placed) {
|
|
76
|
+
groups.push({ parallel: true, stages: [stage] });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (groups.length === 1 && groups[0].stages.length === 1) {
|
|
80
|
+
return [{ parallel: false, stages: groups[0].stages }];
|
|
81
|
+
}
|
|
82
|
+
return groups;
|
|
83
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pricing resolver — converts LLM token usage to micro-USDC cost.
|
|
3
|
+
*
|
|
4
|
+
* Strategy:
|
|
5
|
+
* - OpenRouter: fetch pricing from https://openrouter.ai/api/v1/models (cached 1h)
|
|
6
|
+
* - MiniMax: hardcoded table (no public pricing API)
|
|
7
|
+
* - Fallback: error if model unknown (don't silently bill $0)
|
|
8
|
+
*
|
|
9
|
+
* OpenRouter pricing format: per-token USD ($/M tokens), we convert to micro-USDC.
|
|
10
|
+
* 1 USDC = 1_000_000 micro-USDC = $1.00
|
|
11
|
+
*/
|
|
12
|
+
export interface TokenUsage {
|
|
13
|
+
inputTokens: number;
|
|
14
|
+
outputTokens: number;
|
|
15
|
+
}
|
|
16
|
+
export interface PricingEntry {
|
|
17
|
+
input: number;
|
|
18
|
+
output: number;
|
|
19
|
+
}
|
|
20
|
+
export interface PricingResolver {
|
|
21
|
+
resolveCostUsd(model: string, usage: TokenUsage): Promise<number>;
|
|
22
|
+
resolveCostMicroUsdc(model: string, usage: TokenUsage): Promise<number>;
|
|
23
|
+
}
|
|
24
|
+
export declare class OpenRouterPricingResolver implements PricingResolver {
|
|
25
|
+
private readonly opts;
|
|
26
|
+
private cache;
|
|
27
|
+
private fetched;
|
|
28
|
+
private fetchPromise;
|
|
29
|
+
constructor(opts?: {
|
|
30
|
+
apiKey?: string;
|
|
31
|
+
baseURL?: string;
|
|
32
|
+
});
|
|
33
|
+
private fetchAll;
|
|
34
|
+
private getPricing;
|
|
35
|
+
resolveCostUsd(model: string, usage: TokenUsage): Promise<number>;
|
|
36
|
+
resolveCostMicroUsdc(model: string, usage: TokenUsage): Promise<number>;
|
|
37
|
+
}
|
|
38
|
+
export declare class MiniMaxPricingResolver implements PricingResolver {
|
|
39
|
+
resolveCostUsd(model: string, usage: TokenUsage): Promise<number>;
|
|
40
|
+
resolveCostMicroUsdc(model: string, usage: TokenUsage): Promise<number>;
|
|
41
|
+
}
|
|
42
|
+
export declare class StaticPricingResolver implements PricingResolver {
|
|
43
|
+
private readonly table;
|
|
44
|
+
constructor(table: Record<string, PricingEntry>);
|
|
45
|
+
resolveCostUsd(model: string, usage: TokenUsage): Promise<number>;
|
|
46
|
+
resolveCostMicroUsdc(model: string, usage: TokenUsage): Promise<number>;
|
|
47
|
+
}
|
|
48
|
+
export declare class CompositePricingResolver implements PricingResolver {
|
|
49
|
+
private readonly resolvers;
|
|
50
|
+
constructor(resolvers: PricingResolver[]);
|
|
51
|
+
resolveCostUsd(model: string, usage: TokenUsage): Promise<number>;
|
|
52
|
+
resolveCostMicroUsdc(model: string, usage: TokenUsage): Promise<number>;
|
|
53
|
+
}
|
|
54
|
+
export declare function createDefaultPricingResolver(opts?: {
|
|
55
|
+
openrouterApiKey?: string;
|
|
56
|
+
openrouterBaseURL?: string;
|
|
57
|
+
}): PricingResolver;
|
package/dist/pricing.js
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pricing resolver — converts LLM token usage to micro-USDC cost.
|
|
3
|
+
*
|
|
4
|
+
* Strategy:
|
|
5
|
+
* - OpenRouter: fetch pricing from https://openrouter.ai/api/v1/models (cached 1h)
|
|
6
|
+
* - MiniMax: hardcoded table (no public pricing API)
|
|
7
|
+
* - Fallback: error if model unknown (don't silently bill $0)
|
|
8
|
+
*
|
|
9
|
+
* OpenRouter pricing format: per-token USD ($/M tokens), we convert to micro-USDC.
|
|
10
|
+
* 1 USDC = 1_000_000 micro-USDC = $1.00
|
|
11
|
+
*/
|
|
12
|
+
const PRICING_CACHE_TTL_MS = 60 * 60 * 1000;
|
|
13
|
+
const USDC_PER_USD = 1_000_000;
|
|
14
|
+
const MINIMAX_PRICING = {
|
|
15
|
+
'MiniMax-M2.7': { input: 0.20, output: 0.80 },
|
|
16
|
+
'MiniMax-M2.7-highspeed': { input: 0.10, output: 0.40 },
|
|
17
|
+
'MiniMax-M3': { input: 2.00, output: 8.00 },
|
|
18
|
+
};
|
|
19
|
+
export class OpenRouterPricingResolver {
|
|
20
|
+
opts;
|
|
21
|
+
cache = new Map();
|
|
22
|
+
fetched = false;
|
|
23
|
+
fetchPromise = null;
|
|
24
|
+
constructor(opts = {}) {
|
|
25
|
+
this.opts = opts;
|
|
26
|
+
}
|
|
27
|
+
async fetchAll() {
|
|
28
|
+
if (this.fetched)
|
|
29
|
+
return;
|
|
30
|
+
if (this.fetchPromise)
|
|
31
|
+
return this.fetchPromise;
|
|
32
|
+
this.fetchPromise = (async () => {
|
|
33
|
+
const url = `${this.opts.baseURL ?? 'https://openrouter.ai/api'}/v1/models`;
|
|
34
|
+
const headers = { 'Content-Type': 'application/json' };
|
|
35
|
+
if (this.opts.apiKey)
|
|
36
|
+
headers['Authorization'] = `Bearer ${this.opts.apiKey}`;
|
|
37
|
+
const res = await fetch(url, { headers });
|
|
38
|
+
if (!res.ok)
|
|
39
|
+
throw new Error(`OpenRouter pricing fetch failed: ${res.status}`);
|
|
40
|
+
const data = await res.json();
|
|
41
|
+
for (const m of data.data) {
|
|
42
|
+
if (m.pricing?.prompt && m.pricing?.completion) {
|
|
43
|
+
this.cache.set(m.id, {
|
|
44
|
+
prompt: parseFloat(m.pricing.prompt),
|
|
45
|
+
completion: parseFloat(m.pricing.completion),
|
|
46
|
+
ts: Date.now(),
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
this.fetched = true;
|
|
51
|
+
})();
|
|
52
|
+
return this.fetchPromise;
|
|
53
|
+
}
|
|
54
|
+
async getPricing(modelId) {
|
|
55
|
+
if (!this.fetched)
|
|
56
|
+
await this.fetchAll();
|
|
57
|
+
const cached = this.cache.get(modelId);
|
|
58
|
+
if (!cached)
|
|
59
|
+
return null;
|
|
60
|
+
if (Date.now() - cached.ts > PRICING_CACHE_TTL_MS) {
|
|
61
|
+
this.fetched = false;
|
|
62
|
+
this.fetchPromise = null;
|
|
63
|
+
this.cache.delete(modelId);
|
|
64
|
+
return this.fetchAll().then(() => this.cache.get(modelId) ?? null);
|
|
65
|
+
}
|
|
66
|
+
return cached;
|
|
67
|
+
}
|
|
68
|
+
async resolveCostUsd(model, usage) {
|
|
69
|
+
const pricing = await this.getPricing(model);
|
|
70
|
+
if (!pricing)
|
|
71
|
+
throw new Error(`OpenRouter pricing not found for model: ${model}`);
|
|
72
|
+
return (usage.inputTokens * pricing.prompt + usage.outputTokens * pricing.completion);
|
|
73
|
+
}
|
|
74
|
+
async resolveCostMicroUsdc(model, usage) {
|
|
75
|
+
const usd = await this.resolveCostUsd(model, usage);
|
|
76
|
+
return Math.ceil(usd * USDC_PER_USD);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
export class MiniMaxPricingResolver {
|
|
80
|
+
async resolveCostUsd(model, usage) {
|
|
81
|
+
const pricing = MINIMAX_PRICING[model];
|
|
82
|
+
if (!pricing) {
|
|
83
|
+
throw new Error(`MiniMax pricing not found for model: ${model}. Known: ${Object.keys(MINIMAX_PRICING).join(', ')}`);
|
|
84
|
+
}
|
|
85
|
+
return (usage.inputTokens * pricing.input + usage.outputTokens * pricing.output) / 1_000_000;
|
|
86
|
+
}
|
|
87
|
+
async resolveCostMicroUsdc(model, usage) {
|
|
88
|
+
const usd = await this.resolveCostUsd(model, usage);
|
|
89
|
+
return Math.ceil(usd * USDC_PER_USD);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
export class StaticPricingResolver {
|
|
93
|
+
table;
|
|
94
|
+
constructor(table) {
|
|
95
|
+
this.table = table;
|
|
96
|
+
}
|
|
97
|
+
async resolveCostUsd(model, usage) {
|
|
98
|
+
const pricing = this.table[model];
|
|
99
|
+
if (!pricing)
|
|
100
|
+
throw new Error(`Pricing not found for model: ${model}`);
|
|
101
|
+
return (usage.inputTokens * pricing.input + usage.outputTokens * pricing.output) / 1_000_000;
|
|
102
|
+
}
|
|
103
|
+
async resolveCostMicroUsdc(model, usage) {
|
|
104
|
+
const usd = await this.resolveCostUsd(model, usage);
|
|
105
|
+
return Math.ceil(usd * USDC_PER_USD);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
export class CompositePricingResolver {
|
|
109
|
+
resolvers;
|
|
110
|
+
constructor(resolvers) {
|
|
111
|
+
this.resolvers = resolvers;
|
|
112
|
+
}
|
|
113
|
+
async resolveCostUsd(model, usage) {
|
|
114
|
+
const errors = [];
|
|
115
|
+
for (const r of this.resolvers) {
|
|
116
|
+
try {
|
|
117
|
+
return await r.resolveCostUsd(model, usage);
|
|
118
|
+
}
|
|
119
|
+
catch (e) {
|
|
120
|
+
errors.push(e.message);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
throw new Error(`No resolver priced '${model}': ${errors.join(' | ')}`);
|
|
124
|
+
}
|
|
125
|
+
async resolveCostMicroUsdc(model, usage) {
|
|
126
|
+
const usd = await this.resolveCostUsd(model, usage);
|
|
127
|
+
return Math.ceil(usd * USDC_PER_USD);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
export function createDefaultPricingResolver(opts = {}) {
|
|
131
|
+
return new CompositePricingResolver([
|
|
132
|
+
new MiniMaxPricingResolver(),
|
|
133
|
+
new OpenRouterPricingResolver({ apiKey: opts.openrouterApiKey, baseURL: opts.openrouterBaseURL }),
|
|
134
|
+
]);
|
|
135
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider registry — static metadata + runtime class.
|
|
3
|
+
*
|
|
4
|
+
* R6 (Pipeline v0.3) — Provider ≠ Model separation.
|
|
5
|
+
*
|
|
6
|
+
* Every pipeline stage MUST declare both `provider:` and `model:`.
|
|
7
|
+
* Auto-dispatch by model name (v0.2 `pickProvider`) was removed in
|
|
8
|
+
* R6. The `PROVIDER_REGISTRY` constant below is the single source
|
|
9
|
+
* of truth for *which models each provider supports*.
|
|
10
|
+
*
|
|
11
|
+
* Two-layer design:
|
|
12
|
+
*
|
|
13
|
+
* 1. Static `PROVIDER_REGISTRY` (this file) — pure data: name,
|
|
14
|
+
* display name, supportedModels allowlist, baseUrl, env var.
|
|
15
|
+
* Use for: schema validation, CLI help text, `validate()`
|
|
16
|
+
* command. Pure module, no I/O.
|
|
17
|
+
*
|
|
18
|
+
* 2. Runtime `LLMProviderRegistry` class (this file) — wraps the
|
|
19
|
+
* set of *instantiated* `LLMProvider` objects available to the
|
|
20
|
+
* executor (depends on env keys present). Use for: actual
|
|
21
|
+
* request execution. Constructed once per pipeline-run.
|
|
22
|
+
*
|
|
23
|
+
* The static registry declares 5 providers (openai, anthropic,
|
|
24
|
+
* minimax, openrouter, replicate). The runtime class currently
|
|
25
|
+
* instantiates only those with env keys configured (minimax +
|
|
26
|
+
* openrouter). openai/anthropic/replicate land when their SDK
|
|
27
|
+
* adapters ship (post-R6).
|
|
28
|
+
*
|
|
29
|
+
* TODO production: replace the static allowlists with dynamic
|
|
30
|
+
* /models fetches against each provider's API; cache with TTL.
|
|
31
|
+
*/
|
|
32
|
+
export type Provider = 'openai' | 'anthropic' | 'minimax' | 'openrouter' | 'replicate';
|
|
33
|
+
/**
|
|
34
|
+
* ProviderSpec — declarative metadata for one provider.
|
|
35
|
+
*
|
|
36
|
+
* `supportedModels` is an explicit allowlist. Special value `'*'`
|
|
37
|
+
* means "routes any model name" (used by openrouter, the universal
|
|
38
|
+
* gateway). Every other provider is a closed allowlist — explicit
|
|
39
|
+
* model IDs only.
|
|
40
|
+
*
|
|
41
|
+
* `apiKeyEnvVar` names the env var the runtime reads. Optional —
|
|
42
|
+
* providers without API keys (e.g. local mocks) omit it.
|
|
43
|
+
*/
|
|
44
|
+
export interface ProviderSpec {
|
|
45
|
+
readonly name: Provider;
|
|
46
|
+
readonly displayName: string;
|
|
47
|
+
readonly supportedModels: readonly string[];
|
|
48
|
+
readonly baseUrl?: string;
|
|
49
|
+
readonly apiKeyEnvVar?: string;
|
|
50
|
+
}
|
|
51
|
+
export declare const PROVIDER_REGISTRY: Readonly<Record<Provider, ProviderSpec>>;
|
|
52
|
+
/**
|
|
53
|
+
* Look up a provider by name. Returns null for unknown names —
|
|
54
|
+
* use {@link validateProviderName} when an exception is desired.
|
|
55
|
+
*/
|
|
56
|
+
export declare function getProvider(name: string): ProviderSpec | null;
|
|
57
|
+
/**
|
|
58
|
+
* Like {@link getProvider} but throws `ProviderSpecNotFoundError`
|
|
59
|
+
* on unknown names. Use at trust boundaries (CLI validate, server
|
|
60
|
+
* publish) where a misspelled provider must fail-fast with a clear
|
|
61
|
+
* message instead of silently returning null.
|
|
62
|
+
*/
|
|
63
|
+
export declare function validateProviderName(name: string): Provider;
|
|
64
|
+
/**
|
|
65
|
+
* Does the provider support this model?
|
|
66
|
+
*
|
|
67
|
+
* - exact match against `supportedModels` → true
|
|
68
|
+
* - provider has `'*'` in supportedModels → true (openrouter)
|
|
69
|
+
* - otherwise → false
|
|
70
|
+
*
|
|
71
|
+
* Pure function; safe to call from validators and tests.
|
|
72
|
+
*/
|
|
73
|
+
export declare function supportsModel(providerName: Provider, modelName: string): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Combined check: validate provider name AND model membership.
|
|
76
|
+
* Returns the normalized `{ provider, model }` tuple.
|
|
77
|
+
*
|
|
78
|
+
* Throws `ProviderSpecNotFoundError` (unknown provider) or
|
|
79
|
+
* `ProviderModelMismatchError` (provider exists but model is not
|
|
80
|
+
* in its allowlist) with messages that include the full supported
|
|
81
|
+
* model list for fast debugging.
|
|
82
|
+
*/
|
|
83
|
+
export declare function validateProviderModel(providerName: string, modelName: string): {
|
|
84
|
+
provider: Provider;
|
|
85
|
+
model: string;
|
|
86
|
+
};
|
|
87
|
+
/** All provider specs, in registry-insertion order. */
|
|
88
|
+
export declare function listProviders(): ProviderSpec[];
|
|
89
|
+
/**
|
|
90
|
+
* Models the provider supports (or `['*']` for gateways).
|
|
91
|
+
* Returns the same readonly tuple as `spec.supportedModels` —
|
|
92
|
+
* consumers should treat it as read-only.
|
|
93
|
+
*/
|
|
94
|
+
export declare function listSupportedModels(providerName: Provider): readonly string[];
|
|
95
|
+
/**
|
|
96
|
+
* Stage shape consumed by {@link validateR6Stage} — minimal subset
|
|
97
|
+
* of PipelineStageLike needed for provider/model gating. Defined
|
|
98
|
+
* locally so callers don't have to import the full stage interface.
|
|
99
|
+
*/
|
|
100
|
+
export interface R6StageInput {
|
|
101
|
+
readonly id?: string;
|
|
102
|
+
readonly provider?: string;
|
|
103
|
+
readonly model?: string;
|
|
104
|
+
readonly uses?: unknown;
|
|
105
|
+
readonly prompt?: string;
|
|
106
|
+
}
|
|
107
|
+
export interface R6SpecInput {
|
|
108
|
+
readonly stages?: readonly R6StageInput[];
|
|
109
|
+
readonly defaults?: {
|
|
110
|
+
readonly model?: string;
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Result of {@link validateR6Spec} — `errors` is the array of
|
|
115
|
+
* human-readable failure messages (empty when valid). Each entry is
|
|
116
|
+
* pre-formatted with `Stage '<id>':` prefix for direct console output.
|
|
117
|
+
*/
|
|
118
|
+
export interface R6ValidationResult {
|
|
119
|
+
readonly errors: readonly string[];
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Pure validator for the R6 (Provider ≠ Model) schema rules. Used
|
|
123
|
+
* by both CLI (`agentsmarket validate`, `agentsmarket run` preflight)
|
|
124
|
+
* and server (`POST /v1/pipelines` publish gate). No env access,
|
|
125
|
+
* no I/O — safe to call from tests and CLI completion.
|
|
126
|
+
*
|
|
127
|
+
* Rules enforced:
|
|
128
|
+
* 1. Every LLM stage (model OR prompt-only) MUST declare `provider:`.
|
|
129
|
+
* Auto-dispatch by model name was removed in R6.
|
|
130
|
+
* 2. The (provider, model) pair MUST be in `PROVIDER_REGISTRY`.
|
|
131
|
+
* `provider.supports(model)` is the source of truth.
|
|
132
|
+
* 3. The stage's effective model = `stage.model ?? spec.defaults?.model ?? 'MiniMax-M3'`.
|
|
133
|
+
* Stages using `uses:` (skill invocation) skip the gate entirely.
|
|
134
|
+
*/
|
|
135
|
+
export declare function validateR6Spec(spec: R6SpecInput): R6ValidationResult;
|
|
136
|
+
/**
|
|
137
|
+
* One-shot migration: adds `provider: minimax` to every LLM stage
|
|
138
|
+
* that lacks a provider field. Legacy v0.2 pipelines relied on
|
|
139
|
+
* auto-dispatch; R6 requires explicit declaration. Idempotent —
|
|
140
|
+
* re-running on an already-migrated spec is a no-op.
|
|
141
|
+
*
|
|
142
|
+
* Returns a NEW spec object (input not mutated). Stages that already
|
|
143
|
+
* declare any provider (openai, anthropic, openrouter, replicate, …)
|
|
144
|
+
* are passed through unchanged.
|
|
145
|
+
*/
|
|
146
|
+
export declare function migrateProviderField<T extends {
|
|
147
|
+
stages?: Array<Record<string, unknown>>;
|
|
148
|
+
}>(spec: T, defaultProvider?: Provider): T;
|
|
149
|
+
/** Thrown when a string doesn't match any registered provider. */
|
|
150
|
+
export declare class ProviderSpecNotFoundError extends Error {
|
|
151
|
+
readonly providerName: string;
|
|
152
|
+
readonly availableProviders: readonly string[];
|
|
153
|
+
constructor(providerName: string, availableProviders: readonly string[]);
|
|
154
|
+
}
|
|
155
|
+
/** Thrown when a (provider, model) pair is invalid for the provider. */
|
|
156
|
+
export declare class ProviderModelMismatchError extends Error {
|
|
157
|
+
readonly providerName: string;
|
|
158
|
+
readonly model: string;
|
|
159
|
+
readonly availableModels: readonly string[];
|
|
160
|
+
constructor(providerName: string, model: string, availableModels: readonly string[]);
|
|
161
|
+
}
|
|
162
|
+
import type { LLMProvider } from './types.js';
|
|
163
|
+
/**
|
|
164
|
+
* Thrown when a stage declares `provider: X` but X is not in the
|
|
165
|
+
* registry passed to the executor.
|
|
166
|
+
*/
|
|
167
|
+
export declare class UnknownProviderError extends Error {
|
|
168
|
+
readonly providerName: string;
|
|
169
|
+
readonly registeredNames: readonly string[];
|
|
170
|
+
constructor(providerName: string, registeredNames: readonly string[]);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Thrown when a registered provider does not support the requested
|
|
174
|
+
* model. Fail-fast per ADR Q1 (R6.6 consumes this at validate time;
|
|
175
|
+
* runtime executor is defense-in-depth).
|
|
176
|
+
*/
|
|
177
|
+
export declare class ProviderMismatchError extends Error {
|
|
178
|
+
readonly providerName: string;
|
|
179
|
+
readonly model: string;
|
|
180
|
+
readonly availableModels: readonly string[];
|
|
181
|
+
constructor(providerName: string, model: string, availableModels: readonly string[]);
|
|
182
|
+
}
|
|
183
|
+
export declare class LLMProviderRegistry {
|
|
184
|
+
private readonly byName;
|
|
185
|
+
constructor(providers: readonly LLMProvider[]);
|
|
186
|
+
resolve(name: string): LLMProvider;
|
|
187
|
+
resolveWithSupports(name: string, model: string): LLMProvider;
|
|
188
|
+
hasName(name: string): boolean;
|
|
189
|
+
names(): readonly string[];
|
|
190
|
+
}
|