@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,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pipeline event stream — used by integrations (Action log groups, dashboards,
|
|
3
|
+
* cost trackers, etc.) to react to pipeline execution without coupling to the
|
|
4
|
+
* executor's internal control flow.
|
|
5
|
+
*
|
|
6
|
+
* ADR Q4 ("Streaming events"). v0.3 surface; emit() sinks are user-replaceable.
|
|
7
|
+
*
|
|
8
|
+
* Default no-op sink is fine for plain CLI usage. Replace with a richer sink
|
|
9
|
+
* when integrating into a UI / webhook / log aggregator.
|
|
10
|
+
*/
|
|
11
|
+
export type PipelineEventType = 'pipeline.started' | 'pipeline.completed' | 'pipeline.failed' | 'stage.started' | 'stage.completed' | 'stage.failed' | 'stage.skipped' | 'stage.retry';
|
|
12
|
+
interface PipelineEventBase {
|
|
13
|
+
readonly type: PipelineEventType;
|
|
14
|
+
readonly at: string;
|
|
15
|
+
}
|
|
16
|
+
export interface PipelineLifecycleEvent extends PipelineEventBase {
|
|
17
|
+
readonly type: 'pipeline.started' | 'pipeline.completed' | 'pipeline.failed';
|
|
18
|
+
readonly pipelineName?: string;
|
|
19
|
+
readonly pipelineVersion?: string;
|
|
20
|
+
readonly stageCount?: number;
|
|
21
|
+
readonly totalMs?: number;
|
|
22
|
+
readonly error?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface StageLifecycleEvent extends PipelineEventBase {
|
|
25
|
+
readonly type: 'stage.started' | 'stage.completed' | 'stage.failed' | 'stage.skipped';
|
|
26
|
+
readonly stageId: string;
|
|
27
|
+
readonly ms?: number;
|
|
28
|
+
readonly costMicroUsdc?: number;
|
|
29
|
+
readonly model?: string;
|
|
30
|
+
readonly reason?: 'when-false' | 'error' | 'normal';
|
|
31
|
+
readonly error?: string;
|
|
32
|
+
readonly output?: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Emitted once per retry attempt by `runWithRetry` whenever a retryable
|
|
36
|
+
* error triggers another attempt. Field names and the `at` timestamp
|
|
37
|
+
* match the camelCase + ISO-8601 convention used by every other
|
|
38
|
+
* `PipelineEvent`.
|
|
39
|
+
*/
|
|
40
|
+
export interface StageRetriedEvent {
|
|
41
|
+
readonly type: 'stage.retry';
|
|
42
|
+
readonly stageId: string;
|
|
43
|
+
readonly attempt: number;
|
|
44
|
+
readonly maxAttempts: number;
|
|
45
|
+
readonly errorMessage: string;
|
|
46
|
+
readonly errorStatus?: number;
|
|
47
|
+
readonly nextBackoffMs: number;
|
|
48
|
+
readonly at: string;
|
|
49
|
+
}
|
|
50
|
+
export type PipelineEvent = PipelineLifecycleEvent | StageLifecycleEvent | StageRetriedEvent;
|
|
51
|
+
export type PipelineStartedEvent = PipelineLifecycleEvent;
|
|
52
|
+
export type PipelineCompletedEvent = PipelineLifecycleEvent;
|
|
53
|
+
export type PipelineFailedEvent = PipelineLifecycleEvent;
|
|
54
|
+
export type StageStartedEvent = StageLifecycleEvent;
|
|
55
|
+
export type StageCompletedEvent = StageLifecycleEvent;
|
|
56
|
+
export type StageFailedEvent = StageLifecycleEvent;
|
|
57
|
+
export type StageSkippedEvent = StageLifecycleEvent;
|
|
58
|
+
export interface PipelineEventSink {
|
|
59
|
+
emit(event: PipelineEvent): void;
|
|
60
|
+
on(type: PipelineEventType, handler: (event: PipelineEvent) => void): () => void;
|
|
61
|
+
onAny(handler: (event: PipelineEvent) => void): () => void;
|
|
62
|
+
}
|
|
63
|
+
export declare class NoopEventSink implements PipelineEventSink {
|
|
64
|
+
emit(_event: PipelineEvent): void;
|
|
65
|
+
on(_type: PipelineEventType, _handler: (event: PipelineEvent) => void): () => void;
|
|
66
|
+
onAny(_handler: (event: PipelineEvent) => void): () => void;
|
|
67
|
+
}
|
|
68
|
+
export declare class CallbackEventSink implements PipelineEventSink {
|
|
69
|
+
private readonly config;
|
|
70
|
+
private subscribers;
|
|
71
|
+
private anySubscribers;
|
|
72
|
+
constructor(config?: {
|
|
73
|
+
onEvent?: (event: PipelineEvent) => void;
|
|
74
|
+
});
|
|
75
|
+
emit(event: PipelineEvent): void;
|
|
76
|
+
on(type: PipelineEventType, handler: (event: PipelineEvent) => void): () => void;
|
|
77
|
+
onAny(handler: (event: PipelineEvent) => void): () => void;
|
|
78
|
+
}
|
|
79
|
+
export declare function createDefaultSink(): PipelineEventSink;
|
|
80
|
+
export declare function nowIso(): string;
|
|
81
|
+
export declare function makeStartedEvent(args: {
|
|
82
|
+
pipelineName?: string;
|
|
83
|
+
pipelineVersion?: string;
|
|
84
|
+
stageCount: number;
|
|
85
|
+
}): PipelineLifecycleEvent;
|
|
86
|
+
export declare function makeCompletedEvent(args: {
|
|
87
|
+
pipelineName?: string;
|
|
88
|
+
pipelineVersion?: string;
|
|
89
|
+
totalMs: number;
|
|
90
|
+
}): PipelineLifecycleEvent;
|
|
91
|
+
export declare function makeFailedEvent(args: {
|
|
92
|
+
pipelineName?: string;
|
|
93
|
+
pipelineVersion?: string;
|
|
94
|
+
totalMs?: number;
|
|
95
|
+
error: string;
|
|
96
|
+
}): PipelineLifecycleEvent;
|
|
97
|
+
export declare function makeStageStartedEvent(stageId: string): StageLifecycleEvent;
|
|
98
|
+
export declare function makeStageCompletedEvent(args: {
|
|
99
|
+
stageId: string;
|
|
100
|
+
ms: number;
|
|
101
|
+
costMicroUsdc: number;
|
|
102
|
+
model: string;
|
|
103
|
+
output: string;
|
|
104
|
+
}): StageLifecycleEvent;
|
|
105
|
+
export declare function makeStageSkippedEvent(stageId: string): StageLifecycleEvent;
|
|
106
|
+
export declare function makeStageFailedEvent(args: {
|
|
107
|
+
stageId: string;
|
|
108
|
+
error: string;
|
|
109
|
+
}): StageLifecycleEvent;
|
|
110
|
+
export declare function makeStageRetriedEvent(args: {
|
|
111
|
+
stageId: string;
|
|
112
|
+
attempt: number;
|
|
113
|
+
maxAttempts: number;
|
|
114
|
+
errorMessage: string;
|
|
115
|
+
errorStatus?: number;
|
|
116
|
+
nextBackoffMs: number;
|
|
117
|
+
}): StageRetriedEvent;
|
|
118
|
+
export {};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pipeline event stream — used by integrations (Action log groups, dashboards,
|
|
3
|
+
* cost trackers, etc.) to react to pipeline execution without coupling to the
|
|
4
|
+
* executor's internal control flow.
|
|
5
|
+
*
|
|
6
|
+
* ADR Q4 ("Streaming events"). v0.3 surface; emit() sinks are user-replaceable.
|
|
7
|
+
*
|
|
8
|
+
* Default no-op sink is fine for plain CLI usage. Replace with a richer sink
|
|
9
|
+
* when integrating into a UI / webhook / log aggregator.
|
|
10
|
+
*/
|
|
11
|
+
export class NoopEventSink {
|
|
12
|
+
emit(_event) { }
|
|
13
|
+
on(_type, _handler) {
|
|
14
|
+
return () => undefined;
|
|
15
|
+
}
|
|
16
|
+
onAny(_handler) {
|
|
17
|
+
return () => undefined;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export class CallbackEventSink {
|
|
21
|
+
config;
|
|
22
|
+
subscribers = new Map();
|
|
23
|
+
anySubscribers = new Set();
|
|
24
|
+
constructor(config = {}) {
|
|
25
|
+
this.config = config;
|
|
26
|
+
}
|
|
27
|
+
emit(event) {
|
|
28
|
+
if (this.config.onEvent) {
|
|
29
|
+
try {
|
|
30
|
+
this.config.onEvent(event);
|
|
31
|
+
}
|
|
32
|
+
catch { /* sink failures must not break executor */ }
|
|
33
|
+
}
|
|
34
|
+
const typed = this.subscribers.get(event.type);
|
|
35
|
+
if (typed) {
|
|
36
|
+
for (const handler of typed) {
|
|
37
|
+
try {
|
|
38
|
+
handler(event);
|
|
39
|
+
}
|
|
40
|
+
catch { /* same */ }
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (this.anySubscribers.size > 0) {
|
|
44
|
+
for (const handler of this.anySubscribers) {
|
|
45
|
+
try {
|
|
46
|
+
handler(event);
|
|
47
|
+
}
|
|
48
|
+
catch { /* same */ }
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
on(type, handler) {
|
|
53
|
+
let set = this.subscribers.get(type);
|
|
54
|
+
if (!set) {
|
|
55
|
+
set = new Set();
|
|
56
|
+
this.subscribers.set(type, set);
|
|
57
|
+
}
|
|
58
|
+
set.add(handler);
|
|
59
|
+
return () => { set.delete(handler); };
|
|
60
|
+
}
|
|
61
|
+
onAny(handler) {
|
|
62
|
+
this.anySubscribers.add(handler);
|
|
63
|
+
return () => { this.anySubscribers.delete(handler); };
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
export function createDefaultSink() {
|
|
67
|
+
return new NoopEventSink();
|
|
68
|
+
}
|
|
69
|
+
export function nowIso() {
|
|
70
|
+
return new Date().toISOString();
|
|
71
|
+
}
|
|
72
|
+
export function makeStartedEvent(args) {
|
|
73
|
+
return {
|
|
74
|
+
type: 'pipeline.started',
|
|
75
|
+
at: nowIso(),
|
|
76
|
+
pipelineName: args.pipelineName,
|
|
77
|
+
pipelineVersion: args.pipelineVersion,
|
|
78
|
+
stageCount: args.stageCount,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
export function makeCompletedEvent(args) {
|
|
82
|
+
return {
|
|
83
|
+
type: 'pipeline.completed',
|
|
84
|
+
at: nowIso(),
|
|
85
|
+
pipelineName: args.pipelineName,
|
|
86
|
+
pipelineVersion: args.pipelineVersion,
|
|
87
|
+
totalMs: args.totalMs,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
export function makeFailedEvent(args) {
|
|
91
|
+
return {
|
|
92
|
+
type: 'pipeline.failed',
|
|
93
|
+
at: nowIso(),
|
|
94
|
+
pipelineName: args.pipelineName,
|
|
95
|
+
pipelineVersion: args.pipelineVersion,
|
|
96
|
+
totalMs: args.totalMs,
|
|
97
|
+
error: args.error,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
export function makeStageStartedEvent(stageId) {
|
|
101
|
+
return { type: 'stage.started', at: nowIso(), stageId, reason: 'normal' };
|
|
102
|
+
}
|
|
103
|
+
export function makeStageCompletedEvent(args) {
|
|
104
|
+
return {
|
|
105
|
+
type: 'stage.completed',
|
|
106
|
+
at: nowIso(),
|
|
107
|
+
stageId: args.stageId,
|
|
108
|
+
ms: args.ms,
|
|
109
|
+
costMicroUsdc: args.costMicroUsdc,
|
|
110
|
+
model: args.model,
|
|
111
|
+
output: args.output,
|
|
112
|
+
reason: 'normal',
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
export function makeStageSkippedEvent(stageId) {
|
|
116
|
+
return { type: 'stage.skipped', at: nowIso(), stageId, reason: 'when-false' };
|
|
117
|
+
}
|
|
118
|
+
export function makeStageFailedEvent(args) {
|
|
119
|
+
return { type: 'stage.failed', at: nowIso(), stageId: args.stageId, error: args.error, reason: 'error' };
|
|
120
|
+
}
|
|
121
|
+
export function makeStageRetriedEvent(args) {
|
|
122
|
+
return {
|
|
123
|
+
type: 'stage.retry',
|
|
124
|
+
stageId: args.stageId,
|
|
125
|
+
attempt: args.attempt,
|
|
126
|
+
maxAttempts: args.maxAttempts,
|
|
127
|
+
errorMessage: args.errorMessage,
|
|
128
|
+
...(args.errorStatus !== undefined ? { errorStatus: args.errorStatus } : {}),
|
|
129
|
+
nextBackoffMs: args.nextBackoffMs,
|
|
130
|
+
at: nowIso(),
|
|
131
|
+
};
|
|
132
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider abstraction for Pipeline execution.
|
|
3
|
+
*
|
|
4
|
+
* Pipelines reference models by name (e.g. "MiniMax-M2.7"). The runtime looks up
|
|
5
|
+
* a provider that knows that model, calls it, and returns the output.
|
|
6
|
+
*
|
|
7
|
+
* This indirection lets us swap providers (MiniMax -> Claude -> OpenAI) without
|
|
8
|
+
* changing Pipeline specs.
|
|
9
|
+
*/
|
|
10
|
+
export type Complexity = 'simple' | 'complex';
|
|
11
|
+
export interface GenerateOptions {
|
|
12
|
+
/** 'simple' uses simpleModel, 'complex' uses complexModel. Default: 'simple'. */
|
|
13
|
+
complexity?: Complexity;
|
|
14
|
+
/** Max output tokens. Default: 2048. */
|
|
15
|
+
maxTokens?: number;
|
|
16
|
+
/** Temperature 0-1. Default: 0.7. */
|
|
17
|
+
temperature?: number;
|
|
18
|
+
/** System prompt (optional). */
|
|
19
|
+
system?: string;
|
|
20
|
+
/** Stop sequences. */
|
|
21
|
+
stopSequences?: string[];
|
|
22
|
+
/** Provider-specific model id (e.g. "anthropic/claude-3.5-sonnet" for OpenRouter). */
|
|
23
|
+
model?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface TokenUsage {
|
|
26
|
+
inputTokens: number;
|
|
27
|
+
outputTokens: number;
|
|
28
|
+
}
|
|
29
|
+
export interface GenerateResult {
|
|
30
|
+
text: string;
|
|
31
|
+
usage: TokenUsage;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Output format constraint. v0.2 NEW.
|
|
35
|
+
*
|
|
36
|
+
* - 'text' (default) — free-form, no validation
|
|
37
|
+
* - 'structured_json' — post-LLM JSON.parse + assert all `fields` keys exist
|
|
38
|
+
* - 'code' / 'markdown' — declared but no validation in v0.2 (v0.3 will lint)
|
|
39
|
+
*
|
|
40
|
+
* Validation behaviour is enforced by executeStage (server + CLI shared).
|
|
41
|
+
*/
|
|
42
|
+
export type OutputFormat = 'text' | 'structured_json' | 'code' | 'markdown';
|
|
43
|
+
export interface OutputFormatViolation {
|
|
44
|
+
/** Path to the missing field (e.g. `suggestions` or `key_points.0`). */
|
|
45
|
+
path: string;
|
|
46
|
+
reason: string;
|
|
47
|
+
}
|
|
48
|
+
export declare class StageOutputFormatError extends Error {
|
|
49
|
+
readonly violations: OutputFormatViolation[];
|
|
50
|
+
constructor(violations: OutputFormatViolation[]);
|
|
51
|
+
}
|
|
52
|
+
export declare class StageSkillVersionMismatchError extends Error {
|
|
53
|
+
readonly requested: string;
|
|
54
|
+
readonly actual: string;
|
|
55
|
+
constructor(requested: string, actual: string);
|
|
56
|
+
}
|
|
57
|
+
export declare class StageMCPConfigError extends Error {
|
|
58
|
+
readonly unknownServers: string[];
|
|
59
|
+
readonly unknownTools: string[];
|
|
60
|
+
constructor(unknownServers: string[], unknownTools: string[]);
|
|
61
|
+
}
|
|
62
|
+
export interface LLMProvider {
|
|
63
|
+
/** Provider display name (e.g. "minimax", "claude"). */
|
|
64
|
+
readonly name: string;
|
|
65
|
+
/** Models this provider handles. */
|
|
66
|
+
readonly models: readonly string[];
|
|
67
|
+
/** Default model for 'simple' tasks (test gen, docs). */
|
|
68
|
+
readonly simpleModel: string;
|
|
69
|
+
/** Default model for 'complex' tasks (analyze, refactor). */
|
|
70
|
+
readonly complexModel: string;
|
|
71
|
+
supports(model: string): boolean;
|
|
72
|
+
/** Generate text completion. */
|
|
73
|
+
generateText(prompt: string, opts?: GenerateOptions): Promise<GenerateResult>;
|
|
74
|
+
/** Generate structured JSON (parsed). Throws on parse error. */
|
|
75
|
+
generateJson<T>(prompt: string, schema: import('zod').ZodSchema<T>, opts?: GenerateOptions): Promise<T>;
|
|
76
|
+
}
|
|
77
|
+
/** Resolve which provider to use for a given model name. */
|
|
78
|
+
export type ProviderRegistry = Record<string, LLMProvider>;
|
|
79
|
+
/** Pick the right provider from a registry based on a model name. */
|
|
80
|
+
export declare function resolveProvider(registry: ProviderRegistry, model: string): LLMProvider;
|
|
81
|
+
export interface PricingTier {
|
|
82
|
+
/** Display name of the tier (e.g. "Free", "Pro", "Enterprise"). */
|
|
83
|
+
tier: string;
|
|
84
|
+
/** Price in USDC (whole units, not micro). Omit for free / contact-sales tiers. */
|
|
85
|
+
price_usdc?: number;
|
|
86
|
+
/** Monthly API call allowance. Omit when usage is unmetered. */
|
|
87
|
+
calls_per_month?: number;
|
|
88
|
+
/** Per-call overage price in USDC. Omit when no overage is offered. */
|
|
89
|
+
overage_usdc?: number;
|
|
90
|
+
}
|
|
91
|
+
export interface PublicPreview {
|
|
92
|
+
/** Plain-text body shown when no long_description_md is set. */
|
|
93
|
+
text?: string;
|
|
94
|
+
/** One-line marketing tagline (≤120 chars recommended). */
|
|
95
|
+
tagline?: string;
|
|
96
|
+
/** Absolute URL to the hero image (PNG/JPG/WebP, ≤2 MB). */
|
|
97
|
+
hero_image?: string;
|
|
98
|
+
/** Absolute URL to a demo video (MP4 or YouTube embed). */
|
|
99
|
+
demo_video?: string;
|
|
100
|
+
/** Gallery of additional screenshot URLs (3-5 recommended). */
|
|
101
|
+
screenshots?: string[];
|
|
102
|
+
/** Subscription / one-off pricing tiers; first tier is the headline price. */
|
|
103
|
+
pricing_tiers?: PricingTier[];
|
|
104
|
+
/** Call-to-action target (e.g. doc URL, sign-up URL). */
|
|
105
|
+
cta_url?: string;
|
|
106
|
+
/** Long-form Markdown description for the detail page body. */
|
|
107
|
+
long_description_md?: string;
|
|
108
|
+
}
|
|
109
|
+
export interface Skill {
|
|
110
|
+
/** Canonical skill id, e.g. "skill_<uuid>". */
|
|
111
|
+
id: string;
|
|
112
|
+
/** Skill display name (kebab-case recommended). */
|
|
113
|
+
name: string;
|
|
114
|
+
/** Short description (≤280 chars). */
|
|
115
|
+
description: string;
|
|
116
|
+
/** Semver version for this row. */
|
|
117
|
+
version: string;
|
|
118
|
+
/** Price in micro-USDC. 0 = free. */
|
|
119
|
+
price_usdc: number;
|
|
120
|
+
/** True when the skill has no purchase gate. */
|
|
121
|
+
is_free: boolean;
|
|
122
|
+
/** True when the skill is private (access gated by `granted_to`). */
|
|
123
|
+
is_private: boolean;
|
|
124
|
+
/** Public markdown body shown on the listing / detail page. */
|
|
125
|
+
public_md: string;
|
|
126
|
+
/** JSON-stringified tags array. */
|
|
127
|
+
tags: string[];
|
|
128
|
+
/** ISO 8601 creation timestamp. */
|
|
129
|
+
created_at: string;
|
|
130
|
+
/** Total invocation count (free + paid). */
|
|
131
|
+
invocation_count: number;
|
|
132
|
+
/** Long-form Markdown description for landing pages. */
|
|
133
|
+
description_long?: string;
|
|
134
|
+
/** Absolute URL to hero image. */
|
|
135
|
+
hero_image?: string;
|
|
136
|
+
/** Absolute URL to demo video (MP4 or YouTube embed). */
|
|
137
|
+
demo_video?: string;
|
|
138
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider abstraction for Pipeline execution.
|
|
3
|
+
*
|
|
4
|
+
* Pipelines reference models by name (e.g. "MiniMax-M2.7"). The runtime looks up
|
|
5
|
+
* a provider that knows that model, calls it, and returns the output.
|
|
6
|
+
*
|
|
7
|
+
* This indirection lets us swap providers (MiniMax -> Claude -> OpenAI) without
|
|
8
|
+
* changing Pipeline specs.
|
|
9
|
+
*/
|
|
10
|
+
export class StageOutputFormatError extends Error {
|
|
11
|
+
violations;
|
|
12
|
+
constructor(violations) {
|
|
13
|
+
super(`Output format violations: ${violations.map(v => `${v.path}: ${v.reason}`).join('; ')}`);
|
|
14
|
+
this.name = 'OUTPUT_FORMAT_VIOLATION';
|
|
15
|
+
this.violations = violations;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export class StageSkillVersionMismatchError extends Error {
|
|
19
|
+
requested;
|
|
20
|
+
actual;
|
|
21
|
+
constructor(requested, actual) {
|
|
22
|
+
super(`Skill version pin requested '@${requested}' but actual version is '${actual}'`);
|
|
23
|
+
this.name = 'SKILL_VERSION_MISMATCH';
|
|
24
|
+
this.requested = requested;
|
|
25
|
+
this.actual = actual;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export class StageMCPConfigError extends Error {
|
|
29
|
+
unknownServers;
|
|
30
|
+
unknownTools;
|
|
31
|
+
constructor(unknownServers, unknownTools) {
|
|
32
|
+
const parts = [];
|
|
33
|
+
if (unknownServers.length)
|
|
34
|
+
parts.push(`unknown mcp_servers: ${unknownServers.join(', ')}`);
|
|
35
|
+
if (unknownTools.length)
|
|
36
|
+
parts.push(`unknown mcp_tools: ${unknownTools.join(', ')}`);
|
|
37
|
+
super(`MCP config invalid (${parts.join('; ')})`);
|
|
38
|
+
this.name = 'MCP_CONFIG_INVALID';
|
|
39
|
+
this.unknownServers = unknownServers;
|
|
40
|
+
this.unknownTools = unknownTools;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/** Pick the right provider from a registry based on a model name. */
|
|
44
|
+
export function resolveProvider(registry, model) {
|
|
45
|
+
for (const provider of Object.values(registry)) {
|
|
46
|
+
if (provider.models.includes(model))
|
|
47
|
+
return provider;
|
|
48
|
+
}
|
|
49
|
+
// Default to first registered provider if no exact match
|
|
50
|
+
const first = Object.values(registry)[0];
|
|
51
|
+
if (!first)
|
|
52
|
+
throw new Error('No LLM providers registered');
|
|
53
|
+
return first;
|
|
54
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bob's Pipeline Webhook — HTTP entry point for pipeline execution.
|
|
3
|
+
*
|
|
4
|
+
* POST /v1/pipelines/:name/invoke
|
|
5
|
+
* Body: { inputs: Record<string, unknown>, payment_proof?: string }
|
|
6
|
+
* Returns: {
|
|
7
|
+
* ok: true,
|
|
8
|
+
* pipeline, version, outputs, duration_ms,
|
|
9
|
+
* provenance: {
|
|
10
|
+
* spec_hash, inputs_hash, output_hash, ts, operator, sig
|
|
11
|
+
* }
|
|
12
|
+
* }
|
|
13
|
+
*
|
|
14
|
+
* Sandbox v1 (Priority A):
|
|
15
|
+
* - spec_hash: sha256 of pipeline YAML (computed at load, embedded in response)
|
|
16
|
+
* - inputs_hash: sha256(JSON.stringify(inputs))
|
|
17
|
+
* - output_hash: sha256(JSON.stringify(outputs))
|
|
18
|
+
* - sig: EIP-191 sign({spec_hash, inputs_hash, output_hash, ts, pipeline, version}) with OPERATOR_PRIVATE_KEY
|
|
19
|
+
*
|
|
20
|
+
* MVP: trusts payment_proof (no on-chain verification). Phase 2: verify tx.
|
|
21
|
+
*
|
|
22
|
+
* Run:
|
|
23
|
+
* OPERATOR_PRIVATE_KEY=0x... node bin/webhook.mjs # signed provenance
|
|
24
|
+
* node bin/webhook.mjs # unsigned provenance (operator=null)
|
|
25
|
+
*/
|
|
26
|
+
declare const _default: {
|
|
27
|
+
port: number;
|
|
28
|
+
fetch: (request: Request, env?: unknown, executionCtx?: import("hono").ExecutionContext) => Response | Promise<Response>;
|
|
29
|
+
};
|
|
30
|
+
export default _default;
|
package/dist/webhook.js
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bob's Pipeline Webhook — HTTP entry point for pipeline execution.
|
|
3
|
+
*
|
|
4
|
+
* POST /v1/pipelines/:name/invoke
|
|
5
|
+
* Body: { inputs: Record<string, unknown>, payment_proof?: string }
|
|
6
|
+
* Returns: {
|
|
7
|
+
* ok: true,
|
|
8
|
+
* pipeline, version, outputs, duration_ms,
|
|
9
|
+
* provenance: {
|
|
10
|
+
* spec_hash, inputs_hash, output_hash, ts, operator, sig
|
|
11
|
+
* }
|
|
12
|
+
* }
|
|
13
|
+
*
|
|
14
|
+
* Sandbox v1 (Priority A):
|
|
15
|
+
* - spec_hash: sha256 of pipeline YAML (computed at load, embedded in response)
|
|
16
|
+
* - inputs_hash: sha256(JSON.stringify(inputs))
|
|
17
|
+
* - output_hash: sha256(JSON.stringify(outputs))
|
|
18
|
+
* - sig: EIP-191 sign({spec_hash, inputs_hash, output_hash, ts, pipeline, version}) with OPERATOR_PRIVATE_KEY
|
|
19
|
+
*
|
|
20
|
+
* MVP: trusts payment_proof (no on-chain verification). Phase 2: verify tx.
|
|
21
|
+
*
|
|
22
|
+
* Run:
|
|
23
|
+
* OPERATOR_PRIVATE_KEY=0x... node bin/webhook.mjs # signed provenance
|
|
24
|
+
* node bin/webhook.mjs # unsigned provenance (operator=null)
|
|
25
|
+
*/
|
|
26
|
+
import { Hono } from 'hono';
|
|
27
|
+
import { createHash } from 'node:crypto';
|
|
28
|
+
import { readFileSync, existsSync, readdirSync } from 'node:fs';
|
|
29
|
+
import * as path from 'node:path';
|
|
30
|
+
import * as yaml from 'js-yaml';
|
|
31
|
+
import { Wallet } from 'ethers';
|
|
32
|
+
import { MiniMaxProvider } from './adapters/minimax.js';
|
|
33
|
+
import { runPipeline } from './index.js';
|
|
34
|
+
const PORT = parseInt(process.env.PORT || '8788', 10);
|
|
35
|
+
const PIPELINES_DIR = path.join(import.meta.dirname || path.dirname(new URL(import.meta.url).pathname), '..', 'pipelines');
|
|
36
|
+
function sha256Hex(s) {
|
|
37
|
+
return createHash('sha256').update(s).digest('hex');
|
|
38
|
+
}
|
|
39
|
+
function canonicalJson(value) {
|
|
40
|
+
return JSON.stringify(value, Object.keys(value).sort());
|
|
41
|
+
}
|
|
42
|
+
function loadPipeline(name) {
|
|
43
|
+
const safe = name.replace(/[^a-z0-9-]/gi, '');
|
|
44
|
+
const p = path.join(PIPELINES_DIR, `${safe}.yaml`);
|
|
45
|
+
if (!existsSync(p)) {
|
|
46
|
+
throw new Error(`Pipeline not found: ${name}`);
|
|
47
|
+
}
|
|
48
|
+
const text = readFileSync(p, 'utf-8');
|
|
49
|
+
const spec = yaml.load(text);
|
|
50
|
+
if (!spec.stages || !Array.isArray(spec.stages)) {
|
|
51
|
+
throw new Error('Invalid pipeline spec: missing stages[]');
|
|
52
|
+
}
|
|
53
|
+
return { spec, spec_hash: sha256Hex(text) };
|
|
54
|
+
}
|
|
55
|
+
function injectVars(template, vars) {
|
|
56
|
+
return template.replace(/\{\{(\w+)\}\}/g, (_, k) => vars[k] ?? '');
|
|
57
|
+
}
|
|
58
|
+
function getOperator() {
|
|
59
|
+
const pk = process.env.OPERATOR_PRIVATE_KEY;
|
|
60
|
+
if (!pk)
|
|
61
|
+
return null;
|
|
62
|
+
try {
|
|
63
|
+
const w = new Wallet(pk.startsWith('0x') ? pk : '0x' + pk);
|
|
64
|
+
return { address: w.address.toLowerCase(), sign: (msg) => w.signMessageSync(msg) };
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const app = new Hono();
|
|
71
|
+
app.get('/', (c) => c.json({
|
|
72
|
+
service: 'pipeline-webhook',
|
|
73
|
+
status: 'ok',
|
|
74
|
+
pipelines_dir: PIPELINES_DIR,
|
|
75
|
+
env: {
|
|
76
|
+
port: PORT,
|
|
77
|
+
minimax_key_set: !!process.env.MINIMAX_API_KEY,
|
|
78
|
+
operator_key_set: !!process.env.OPERATOR_PRIVATE_KEY,
|
|
79
|
+
},
|
|
80
|
+
}));
|
|
81
|
+
app.get('/v1/pipelines', (c) => {
|
|
82
|
+
try {
|
|
83
|
+
const list = readdirSync(PIPELINES_DIR);
|
|
84
|
+
return c.json({ pipelines: list.filter((f) => f.endsWith('.yaml')).map((f) => f.replace(/\.yaml$/, '')) });
|
|
85
|
+
}
|
|
86
|
+
catch (e) {
|
|
87
|
+
return c.json({ pipelines: [], error: e instanceof Error ? e.message : String(e) });
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
app.post('/v1/pipelines/:name/invoke', async (c) => {
|
|
91
|
+
const name = c.req.param('name');
|
|
92
|
+
const body = await c.req.json().catch(() => ({}));
|
|
93
|
+
const inputs = body.inputs || {};
|
|
94
|
+
const paymentProof = body.payment_proof;
|
|
95
|
+
if (paymentProof) {
|
|
96
|
+
console.log(`[payment] proof=${paymentProof.slice(0, 20)}...`);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
console.log(`[payment] MOCK MODE — no proof provided`);
|
|
100
|
+
}
|
|
101
|
+
let spec;
|
|
102
|
+
let specHash;
|
|
103
|
+
try {
|
|
104
|
+
const loaded = loadPipeline(name);
|
|
105
|
+
spec = loaded.spec;
|
|
106
|
+
specHash = loaded.spec_hash;
|
|
107
|
+
}
|
|
108
|
+
catch (e) {
|
|
109
|
+
return c.json({ error: e instanceof Error ? e.message : String(e) }, 404);
|
|
110
|
+
}
|
|
111
|
+
const inputsHash = sha256Hex(canonicalJson(inputs));
|
|
112
|
+
const provider = new MiniMaxProvider();
|
|
113
|
+
const t0 = Date.now();
|
|
114
|
+
try {
|
|
115
|
+
const stages = spec.stages.map((s) => ({
|
|
116
|
+
...s,
|
|
117
|
+
prompt: injectVars(s.prompt, inputs),
|
|
118
|
+
}));
|
|
119
|
+
const outputs = await runPipeline({ name: spec.name, version: spec.version, stages }, inputs, { provider });
|
|
120
|
+
const outputHash = sha256Hex(canonicalJson(outputs));
|
|
121
|
+
const ts = Date.now();
|
|
122
|
+
const operator = getOperator();
|
|
123
|
+
let sig = null;
|
|
124
|
+
if (operator) {
|
|
125
|
+
const message = `pipeline:${spec.name}\nversion:${spec.version}\nspec_hash:${specHash}\ninputs_hash:${inputsHash}\noutput_hash:${outputHash}\nts:${ts}`;
|
|
126
|
+
sig = operator.sign(message);
|
|
127
|
+
}
|
|
128
|
+
return c.json({
|
|
129
|
+
ok: true,
|
|
130
|
+
pipeline: spec.name,
|
|
131
|
+
version: spec.version,
|
|
132
|
+
outputs,
|
|
133
|
+
duration_ms: Date.now() - t0,
|
|
134
|
+
provenance: {
|
|
135
|
+
spec_hash: specHash,
|
|
136
|
+
inputs_hash: inputsHash,
|
|
137
|
+
output_hash: outputHash,
|
|
138
|
+
ts,
|
|
139
|
+
operator: operator?.address ?? null,
|
|
140
|
+
sig,
|
|
141
|
+
algorithm: sig ? 'eip191' : null,
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
catch (e) {
|
|
146
|
+
console.error(`[error]`, e);
|
|
147
|
+
return c.json({
|
|
148
|
+
error: e instanceof Error ? e.message : String(e),
|
|
149
|
+
pipeline: spec.name,
|
|
150
|
+
}, 500);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
console.log(`[boot] listening on http://localhost:${PORT}`);
|
|
154
|
+
console.log(`[boot] pipelines dir: ${PIPELINES_DIR}`);
|
|
155
|
+
console.log(`[boot] minimax: ${process.env.MINIMAX_API_KEY ? 'configured' : 'NOT CONFIGURED (set MINIMAX_API_KEY)'}`);
|
|
156
|
+
console.log(`[boot] operator: ${process.env.OPERATOR_PRIVATE_KEY ? 'configured (signed provenance)' : 'NOT CONFIGURED (unsigned provenance)'}`);
|
|
157
|
+
export default {
|
|
158
|
+
port: PORT,
|
|
159
|
+
fetch: app.fetch,
|
|
160
|
+
};
|
package/dist/when.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* R10.2 — `when` DSL per ADR Q5.
|
|
3
|
+
*
|
|
4
|
+
* Pure-comparison DSL. No JS expressions, no I/O. Reuses existing
|
|
5
|
+
* `expandPipelineText` for `{{ stages.x.outputs.y }}` template resolution.
|
|
6
|
+
*
|
|
7
|
+
* YAML shape (either form):
|
|
8
|
+
*
|
|
9
|
+
* when: "stages.x.outputs.category == 'bug'" # single comparison
|
|
10
|
+
* when:
|
|
11
|
+
* all: # all-must-be-true
|
|
12
|
+
* - "stages.x.outputs.category == 'bug'"
|
|
13
|
+
* - "stages.x.outputs.confidence > 0.7"
|
|
14
|
+
* when:
|
|
15
|
+
* any: # at-least-one
|
|
16
|
+
* - "stages.x.outputs.severity == 'P0'"
|
|
17
|
+
* - "stages.x.outputs.severity == 'P1'"
|
|
18
|
+
*
|
|
19
|
+
* Supported operators: ==, !=, <, >, <=, >=, in, not in. Anything else
|
|
20
|
+
* rejected at validator time.
|
|
21
|
+
*
|
|
22
|
+
* DAG semantics: when-missed stages are SKIPPED at execution time. They
|
|
23
|
+
* produce null outputs. The DAG topology itself is static — branch
|
|
24
|
+
* decisions happen at execution time, not compile time.
|
|
25
|
+
*/
|
|
26
|
+
export type WhenCondition = string | {
|
|
27
|
+
all: string[];
|
|
28
|
+
} | {
|
|
29
|
+
any: string[];
|
|
30
|
+
};
|
|
31
|
+
export type WhenCompareOp = '==' | '!=' | '<' | '>' | '<=' | '>=' | 'in' | 'not in';
|
|
32
|
+
export interface ParsedComparison {
|
|
33
|
+
lhs: string;
|
|
34
|
+
op: WhenCompareOp;
|
|
35
|
+
rhs: string;
|
|
36
|
+
}
|
|
37
|
+
export declare class WhenParseError extends Error {
|
|
38
|
+
readonly expression: string;
|
|
39
|
+
readonly reason: string;
|
|
40
|
+
constructor(expression: string, reason: string);
|
|
41
|
+
}
|
|
42
|
+
export declare function parseComparison(expr: string): ParsedComparison | null;
|
|
43
|
+
export declare function parseWhenLiteral(s: string): string | number | boolean;
|
|
44
|
+
export declare function evaluateComparison(parsed: ParsedComparison, resolve: (template: string) => string): boolean;
|
|
45
|
+
export declare function evaluateWhen(condition: WhenCondition, resolve: (template: string) => string): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Check whether an evaluated when condition was a "true" result, suitable
|
|
48
|
+
* for executor-stage-skip decision.
|
|
49
|
+
*/
|
|
50
|
+
export declare function shouldSkipStage(condition: WhenCondition, resolve: (t: string) => string): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Validate shape only. Returns first error string or null. Does NOT
|
|
53
|
+
* execute evaluation — just structural soundness.
|
|
54
|
+
*/
|
|
55
|
+
export declare function validateWhenShape(condition: unknown): string | null;
|