@agentsmarket/pipeline-runtime 0.3.0 → 0.4.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.
@@ -0,0 +1,38 @@
1
+ /**
2
+ * P5 — Server-side file output collection.
3
+ *
4
+ * Scans the outputs of every executed stage for a structured
5
+ * `produced_files` array, extracts each file's content, and validates
6
+ * against the pipeline's declared `output.files` glob patterns.
7
+ *
8
+ * Stage authors opt-in by emitting structured JSON output of the shape:
9
+ * {
10
+ * "...": "...",
11
+ * "produced_files": [
12
+ * { "name": "report.md", "content_type": "text/markdown", "content_b64": "IyBUaXRsZQo..." }
13
+ * ]
14
+ * }
15
+ *
16
+ * Pure functions only — no I/O, no Cloudflare bindings, no Node.js
17
+ * primitives beyond `atob` (available in both V8 isolates and Node ≥16).
18
+ * The caller (server invoke.ts) is responsible for uploading the decoded
19
+ * bytes to R2 and generating signed URLs.
20
+ */
21
+ import type { PipelineOutputSpec } from './output-spec.js';
22
+ export interface ProducedFile {
23
+ stage_id: string;
24
+ name: string;
25
+ size: number;
26
+ content_type: string;
27
+ content_b64: string;
28
+ }
29
+ export interface ExtractResult {
30
+ files: ProducedFile[];
31
+ errors: string[];
32
+ warnings: string[];
33
+ }
34
+ export declare const MAX_FILE_BYTES: number;
35
+ export declare const MAX_TOTAL_BYTES: number;
36
+ export declare const MAX_FILES = 100;
37
+ export declare function extractProducedFiles(stageOutputs: Record<string, string>, spec: PipelineOutputSpec): ExtractResult;
38
+ export declare function globToRegex(pattern: string): RegExp;
@@ -0,0 +1,141 @@
1
+ /**
2
+ * P5 — Server-side file output collection.
3
+ *
4
+ * Scans the outputs of every executed stage for a structured
5
+ * `produced_files` array, extracts each file's content, and validates
6
+ * against the pipeline's declared `output.files` glob patterns.
7
+ *
8
+ * Stage authors opt-in by emitting structured JSON output of the shape:
9
+ * {
10
+ * "...": "...",
11
+ * "produced_files": [
12
+ * { "name": "report.md", "content_type": "text/markdown", "content_b64": "IyBUaXRsZQo..." }
13
+ * ]
14
+ * }
15
+ *
16
+ * Pure functions only — no I/O, no Cloudflare bindings, no Node.js
17
+ * primitives beyond `atob` (available in both V8 isolates and Node ≥16).
18
+ * The caller (server invoke.ts) is responsible for uploading the decoded
19
+ * bytes to R2 and generating signed URLs.
20
+ */
21
+ export const MAX_FILE_BYTES = 10 * 1024 * 1024;
22
+ export const MAX_TOTAL_BYTES = 50 * 1024 * 1024;
23
+ export const MAX_FILES = 100;
24
+ export function extractProducedFiles(stageOutputs, spec) {
25
+ const files = [];
26
+ const errors = [];
27
+ const warnings = [];
28
+ let totalBytes = 0;
29
+ for (const [stageId, text] of Object.entries(stageOutputs)) {
30
+ let parsed;
31
+ try {
32
+ parsed = JSON.parse(text);
33
+ }
34
+ catch {
35
+ continue;
36
+ }
37
+ if (!parsed || typeof parsed !== 'object')
38
+ continue;
39
+ const obj = parsed;
40
+ const produced = obj.produced_files;
41
+ if (!Array.isArray(produced))
42
+ continue;
43
+ for (const entry of produced) {
44
+ if (!entry || typeof entry !== 'object') {
45
+ warnings.push(`stage '${stageId}' produced_files entry is not an object`);
46
+ continue;
47
+ }
48
+ const rec = entry;
49
+ const name = rec.name;
50
+ const content_b64 = rec.content_b64;
51
+ const content_type = rec.content_type ?? 'application/octet-stream';
52
+ if (typeof name !== 'string' || name.length === 0) {
53
+ errors.push(`stage '${stageId}' produced_files entry missing 'name'`);
54
+ continue;
55
+ }
56
+ if (name.includes('/') || name.includes('\\') || name.includes('..')) {
57
+ errors.push(`stage '${stageId}' produced_files name '${name}' contains path separators or traversal`);
58
+ continue;
59
+ }
60
+ if (typeof content_b64 !== 'string' || content_b64.length === 0) {
61
+ errors.push(`stage '${stageId}' produced_files entry for '${name}' missing or empty 'content_b64'`);
62
+ continue;
63
+ }
64
+ if (typeof content_type !== 'string') {
65
+ errors.push(`stage '${stageId}' produced_files entry for '${name}' has non-string 'content_type'`);
66
+ continue;
67
+ }
68
+ let decodedLen;
69
+ try {
70
+ decodedLen = atob(content_b64).length;
71
+ }
72
+ catch (e) {
73
+ errors.push(`stage '${stageId}' produced_files entry for '${name}' has invalid base64: ${e.message}`);
74
+ continue;
75
+ }
76
+ if (decodedLen > MAX_FILE_BYTES) {
77
+ errors.push(`stage '${stageId}' produced file '${name}' is ${decodedLen} bytes (max ${MAX_FILE_BYTES})`);
78
+ continue;
79
+ }
80
+ if (totalBytes + decodedLen > MAX_TOTAL_BYTES) {
81
+ errors.push(`total file size exceeds ${MAX_TOTAL_BYTES} bytes; aborted at stage '${stageId}'`);
82
+ return { files, errors, warnings };
83
+ }
84
+ if (files.length >= MAX_FILES) {
85
+ errors.push(`produced_files count exceeds ${MAX_FILES}; aborted at stage '${stageId}'`);
86
+ return { files, errors, warnings };
87
+ }
88
+ totalBytes += decodedLen;
89
+ files.push({
90
+ stage_id: stageId,
91
+ name,
92
+ size: decodedLen,
93
+ content_type,
94
+ content_b64,
95
+ });
96
+ }
97
+ }
98
+ if (spec.files && spec.files.length > 0 && files.length > 0) {
99
+ for (const pattern of spec.files) {
100
+ const regex = globToRegex(pattern);
101
+ const matches = files.some((f) => regex.test(f.name));
102
+ if (!matches) {
103
+ warnings.push(`output.files pattern '${pattern}' did not match any produced file`);
104
+ }
105
+ }
106
+ }
107
+ return { files, errors, warnings };
108
+ }
109
+ export function globToRegex(pattern) {
110
+ let regex = '';
111
+ let i = 0;
112
+ while (i < pattern.length) {
113
+ const c = pattern[i];
114
+ if (c === '*' && pattern[i + 1] === '*') {
115
+ regex += '.*';
116
+ i += 2;
117
+ if (pattern[i] === '/')
118
+ i += 1;
119
+ }
120
+ else if (c === '*') {
121
+ regex += '[^/]*';
122
+ i += 1;
123
+ }
124
+ else if (c === '?') {
125
+ regex += '[^/]';
126
+ i += 1;
127
+ }
128
+ else if (c && '.+^$()|{}[]\\'.includes(c)) {
129
+ regex += '\\' + c;
130
+ i += 1;
131
+ }
132
+ else if (c) {
133
+ regex += c;
134
+ i += 1;
135
+ }
136
+ else {
137
+ i += 1;
138
+ }
139
+ }
140
+ return new RegExp('^' + regex + '$');
141
+ }
package/dist/index.d.ts CHANGED
@@ -40,6 +40,7 @@ export { resolveInputRefs, resolveSpecialKeys, type PipelineRefContext, } from '
40
40
  export { isToolSkill, invokeToolSkill, type ToolSkillContext, type ToolSkillResult, type ToolSkillHandler, } from './tools/tool-skills.js';
41
41
  export { validateOutputSpec, DEFAULT_OUTPUT_FORMAT, DEFAULT_OUTPUT_DELIVERY, DEFAULT_OUTPUT_EXPIRES_IN, MIN_OUTPUT_EXPIRES_IN, MAX_OUTPUT_EXPIRES_IN, type PipelineOutputSpec, type PipelineOutputDelivery, type PipelineOutputFormat, type PipelineOutputSpecError, } from './output-spec.js';
42
42
  export { analyzeCapabilities, type PipelineCapabilities, type NetworkCapability, type PipelineSpecLikeForCaps, type PipelineStageLikeForCaps, } from './capabilities.js';
43
+ export { extractProducedFiles, globToRegex, MAX_FILE_BYTES, MAX_TOTAL_BYTES, MAX_FILES, type ProducedFile, type ExtractResult, } from './file-output.js';
43
44
  export interface PipelineStageSpec {
44
45
  id: string;
45
46
  model: string;
package/dist/index.js CHANGED
@@ -27,6 +27,7 @@ export { resolveInputRefs, resolveSpecialKeys, } from './pipeline-refs.js';
27
27
  export { isToolSkill, invokeToolSkill, } from './tools/tool-skills.js';
28
28
  export { validateOutputSpec, DEFAULT_OUTPUT_FORMAT, DEFAULT_OUTPUT_DELIVERY, DEFAULT_OUTPUT_EXPIRES_IN, MIN_OUTPUT_EXPIRES_IN, MAX_OUTPUT_EXPIRES_IN, } from './output-spec.js';
29
29
  export { analyzeCapabilities, } from './capabilities.js';
30
+ export { extractProducedFiles, globToRegex, MAX_FILE_BYTES, MAX_TOTAL_BYTES, MAX_FILES, } from './file-output.js';
30
31
  export async function runStage(stage, ctx) {
31
32
  const vars = [];
32
33
  for (const [key, val] of Object.entries(ctx.outputs)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentsmarket/pipeline-runtime",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Runtime for executing PIPELINE.md workflows (multi-skill orchestration). Provider-agnostic (MiniMax, Claude, OpenAI).",
5
5
  "license": "MIT",
6
6
  "type": "module",