@prompd/core 0.5.0-beta.10
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/LICENSE +21 -0
- package/README.md +127 -0
- package/dist/index.cjs +4716 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2929 -0
- package/dist/index.d.ts +2929 -0
- package/dist/index.js +4627 -0
- package/dist/index.js.map +1 -0
- package/package.json +61 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,2929 @@
|
|
|
1
|
+
import * as nunjucks from 'nunjucks';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* File System Abstraction (core, environment-agnostic).
|
|
5
|
+
*
|
|
6
|
+
* Defines the IFileSystem interface and the in-memory implementation used for
|
|
7
|
+
* browser + server compilation. The Node-backed NodeFileSystem and the adm-zip
|
|
8
|
+
* .pdpkg helpers live in @prompd/cli (they need Node APIs). Path operations here
|
|
9
|
+
* are inlined as POSIX so this module has zero Node imports.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* File system interface that can be implemented for different storage backends.
|
|
13
|
+
*/
|
|
14
|
+
interface IFileSystem {
|
|
15
|
+
/** Check if a file or directory exists. */
|
|
16
|
+
exists(filePath: string): boolean | Promise<boolean>;
|
|
17
|
+
/** Read a file's contents as a UTF-8 string. */
|
|
18
|
+
readFile(filePath: string): string | Promise<string>;
|
|
19
|
+
/** Check if a path is a directory. */
|
|
20
|
+
isDirectory(filePath: string): boolean | Promise<boolean>;
|
|
21
|
+
/** List files in a directory. */
|
|
22
|
+
readdir(dirPath: string): string[] | Promise<string[]>;
|
|
23
|
+
/** Resolve a path (for package resolution). */
|
|
24
|
+
resolve(...pathSegments: string[]): string;
|
|
25
|
+
/** Get the directory name of a path. */
|
|
26
|
+
dirname(filePath: string): string;
|
|
27
|
+
/** Join path segments. */
|
|
28
|
+
join(...pathSegments: string[]): string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* In-memory file system for browser + server-side compilation.
|
|
32
|
+
* Files are provided as a map of path -> content.
|
|
33
|
+
*/
|
|
34
|
+
declare class MemoryFileSystem implements IFileSystem {
|
|
35
|
+
private files;
|
|
36
|
+
constructor(files?: Record<string, string>);
|
|
37
|
+
/** Add or update a file in the in-memory file system. */
|
|
38
|
+
addFile(filePath: string, content: string): void;
|
|
39
|
+
/** Add multiple files at once. */
|
|
40
|
+
addFiles(files: Record<string, string>): void;
|
|
41
|
+
exists(filePath: string): boolean;
|
|
42
|
+
readFile(filePath: string): string;
|
|
43
|
+
isDirectory(filePath: string): boolean;
|
|
44
|
+
readdir(dirPath: string): string[];
|
|
45
|
+
resolve(...pathSegments: string[]): string;
|
|
46
|
+
dirname(filePath: string): string;
|
|
47
|
+
join(...pathSegments: string[]): string;
|
|
48
|
+
/** Get the virtual file system path for a package. */
|
|
49
|
+
getPackagePath(packageName: string, version: string): string;
|
|
50
|
+
/** Get all files under an optional base path. */
|
|
51
|
+
getAllFiles(basePath?: string): Map<string, string>;
|
|
52
|
+
/** Calculate total size (bytes) and file count under a base path. */
|
|
53
|
+
getTotalSize(basePath: string): {
|
|
54
|
+
size: number;
|
|
55
|
+
files: number;
|
|
56
|
+
};
|
|
57
|
+
/** Normalize path to forward slashes, drop leading ./ and /, no trailing slash. */
|
|
58
|
+
protected normalizePath(filePath: string): string;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Async backend for files NOT held in memory by a HybridFileSystem. Paths are
|
|
62
|
+
* normalized relative keys (forward slashes, no leading ./ or /), matching the
|
|
63
|
+
* keys MemoryFileSystem uses. readFile resolves null when the file is absent.
|
|
64
|
+
*
|
|
65
|
+
* This is how a host streams files lazily — e.g. a browser
|
|
66
|
+
* FileSystemDirectoryHandle, or a registry/package fetch — without loading the
|
|
67
|
+
* whole tree up front.
|
|
68
|
+
*/
|
|
69
|
+
interface AsyncFileBackend {
|
|
70
|
+
/** Read a file's UTF-8 contents; resolve null when it does not exist. */
|
|
71
|
+
readFile(path: string): Promise<string | null>;
|
|
72
|
+
/** Optional: report whether a path is a directory. */
|
|
73
|
+
isDirectory?(path: string): Promise<boolean>;
|
|
74
|
+
/** Optional: list a directory's immediate entry names. */
|
|
75
|
+
readdir?(path: string): Promise<string[]>;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* In-memory file system with an async fall-through backend.
|
|
79
|
+
*
|
|
80
|
+
* Files placed in memory (constructor map / addFile) are served SYNCHRONOUSLY,
|
|
81
|
+
* so the synchronous Nunjucks {% include %} loader keeps working for them —
|
|
82
|
+
* pre-load the .prmd sources a compilation can {% include %} or inherit. Any
|
|
83
|
+
* path NOT in memory is read from the async backend, returning a Promise that
|
|
84
|
+
* the compiler's awaiting stages (inherits:, package context, asset extraction)
|
|
85
|
+
* consume. This lets a browser compile a folder of prompts: load the .prmd
|
|
86
|
+
* sources up front, stream binary/context assets on demand.
|
|
87
|
+
*
|
|
88
|
+
* Known limitation: the synchronous Nunjucks {% include %} loader cannot read
|
|
89
|
+
* backend-only files (it gets a Promise and throws a "requires synchronous"
|
|
90
|
+
* error). So anything {% include %}'d must be in memory — pre-load every source
|
|
91
|
+
* a compilation can include (the web host pre-loads all .prmd/.md). inherits:
|
|
92
|
+
* has no such limit; it resolves through the async stages.
|
|
93
|
+
*
|
|
94
|
+
* Composes (does not extend) MemoryFileSystem so the in-memory methods keep
|
|
95
|
+
* their strict sync return types and existing consumers are untouched.
|
|
96
|
+
*/
|
|
97
|
+
declare class HybridFileSystem implements IFileSystem {
|
|
98
|
+
private mem;
|
|
99
|
+
private backend;
|
|
100
|
+
constructor(files: Record<string, string> | undefined, backend: AsyncFileBackend);
|
|
101
|
+
/** Add or update an in-memory (synchronously-served) file. */
|
|
102
|
+
addFile(filePath: string, content: string): void;
|
|
103
|
+
/** Add multiple in-memory files at once. */
|
|
104
|
+
addFiles(files: Record<string, string>): void;
|
|
105
|
+
exists(filePath: string): boolean | Promise<boolean>;
|
|
106
|
+
readFile(filePath: string): string | Promise<string>;
|
|
107
|
+
isDirectory(filePath: string): boolean | Promise<boolean>;
|
|
108
|
+
readdir(dirPath: string): string[] | Promise<string[]>;
|
|
109
|
+
resolve(...pathSegments: string[]): string;
|
|
110
|
+
dirname(filePath: string): string;
|
|
111
|
+
join(...pathSegments: string[]): string;
|
|
112
|
+
/** Normalize to the same relative keys MemoryFileSystem uses, for backend lookups. */
|
|
113
|
+
private normalize;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Code file extensions that need frontmatter protection for security.
|
|
118
|
+
* These files will have prompd content frontmatter added to make them non-executable.
|
|
119
|
+
* Used by: CLI packager, registry security validation, frontend file selection
|
|
120
|
+
*/
|
|
121
|
+
declare const CODE_EXTENSIONS: readonly [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".py", ".pyw", ".pyi", ".sh", ".bash", ".zsh", ".fish", ".ps1", ".psm1", ".psd1", ".bat", ".cmd", ".rb", ".rake", ".gemspec", ".go", ".rs", ".c", ".cpp", ".cc", ".cxx", ".h", ".hpp", ".hxx", ".java", ".kt", ".kts", ".scala", ".groovy", ".cs", ".fs", ".vb", ".php", ".phtml", ".pl", ".pm", ".swift", ".lua", ".r", ".R", ".jl", ".ex", ".exs", ".erl", ".hs", ".lhs", ".vue", ".svelte", ".sql"];
|
|
122
|
+
/**
|
|
123
|
+
* Map file extensions to content type names for frontmatter metadata.
|
|
124
|
+
*/
|
|
125
|
+
declare const CONTENT_TYPES: Record<string, string>;
|
|
126
|
+
/**
|
|
127
|
+
* Check if a file extension requires frontmatter protection.
|
|
128
|
+
*/
|
|
129
|
+
declare function needsFrontmatterProtection(filePath: string): boolean;
|
|
130
|
+
/**
|
|
131
|
+
* Get the content type for a file extension.
|
|
132
|
+
*/
|
|
133
|
+
declare function getContentType(filePath: string): string;
|
|
134
|
+
/**
|
|
135
|
+
* Package types supported by the prompd ecosystem.
|
|
136
|
+
* Defined in prompd.json under the "type" field.
|
|
137
|
+
*/
|
|
138
|
+
type PackageType = 'package' | 'workflow' | 'skill' | 'node-template';
|
|
139
|
+
/**
|
|
140
|
+
* Maps each PackageType to its install directory name.
|
|
141
|
+
* e.g., .prompd/packages/, .prompd/workflows/, .prompd/skills/, .prompd/templates/
|
|
142
|
+
*/
|
|
143
|
+
declare const PACKAGE_TYPE_DIRS: Record<PackageType, string>;
|
|
144
|
+
/**
|
|
145
|
+
* All valid package type strings, for validation.
|
|
146
|
+
*/
|
|
147
|
+
declare const VALID_PACKAGE_TYPES: readonly string[];
|
|
148
|
+
/**
|
|
149
|
+
* Maps tool names to their native skill deployment directories.
|
|
150
|
+
* Used by `prompd install --tools <tool>` to deploy skills into tool-native locations.
|
|
151
|
+
*/
|
|
152
|
+
declare const TOOL_DEPLOY_DIRS: Record<string, string>;
|
|
153
|
+
/**
|
|
154
|
+
* Check if a string is a valid PackageType.
|
|
155
|
+
*/
|
|
156
|
+
declare function isValidPackageType(type: string): type is PackageType;
|
|
157
|
+
/**
|
|
158
|
+
* Get the install directory name for a given package type.
|
|
159
|
+
* Defaults to 'packages' for unknown types.
|
|
160
|
+
*/
|
|
161
|
+
declare function getInstallDirForType(type: string): string;
|
|
162
|
+
interface PrompdParameter {
|
|
163
|
+
name: string;
|
|
164
|
+
/**
|
|
165
|
+
* string — plain text
|
|
166
|
+
* number — integer or float
|
|
167
|
+
* integer — whole number only
|
|
168
|
+
* float — decimal number
|
|
169
|
+
* boolean — true / false
|
|
170
|
+
* array — JSON array (untyped elements)
|
|
171
|
+
* object — plain key-value object (non-array)
|
|
172
|
+
* json — any JSON value: objects, arrays of objects, nested structures, etc.
|
|
173
|
+
* file — file path; caller supplies file content as a string
|
|
174
|
+
* base64 — base64-encoded binary data (images, blobs, streams)
|
|
175
|
+
* date — calendar date "YYYY-MM-DD"; default may be a relative expression
|
|
176
|
+
* (now, today, now-7d, now+1w, now-3m, now-1y) resolved at compile time
|
|
177
|
+
* datetime — date + time "YYYY-MM-DDTHH:mm:ss"; same relative-default support
|
|
178
|
+
* (now, now-2h, now-30min) resolved at compile time
|
|
179
|
+
*/
|
|
180
|
+
type: 'string' | 'number' | 'integer' | 'float' | 'boolean' | 'array' | 'object' | 'json' | 'file' | 'base64' | 'date' | 'datetime';
|
|
181
|
+
description?: string;
|
|
182
|
+
required?: boolean;
|
|
183
|
+
default?: any;
|
|
184
|
+
pattern?: string;
|
|
185
|
+
minimum?: number;
|
|
186
|
+
maximum?: number;
|
|
187
|
+
enum?: string[];
|
|
188
|
+
}
|
|
189
|
+
interface UsingPackage {
|
|
190
|
+
name: string;
|
|
191
|
+
prefix?: string;
|
|
192
|
+
}
|
|
193
|
+
interface PrompdMetadata {
|
|
194
|
+
id: string;
|
|
195
|
+
name?: string;
|
|
196
|
+
description?: string;
|
|
197
|
+
version?: string;
|
|
198
|
+
parameters?: PrompdParameter[];
|
|
199
|
+
variables?: PrompdParameter[];
|
|
200
|
+
system?: string | string[];
|
|
201
|
+
context?: string | string[];
|
|
202
|
+
task?: string | string[];
|
|
203
|
+
user?: string | string[];
|
|
204
|
+
assistant?: string | string[];
|
|
205
|
+
response?: string | string[];
|
|
206
|
+
output?: string | string[];
|
|
207
|
+
requires?: string[];
|
|
208
|
+
provider?: string;
|
|
209
|
+
model?: string;
|
|
210
|
+
temperature?: number;
|
|
211
|
+
max_tokens?: number;
|
|
212
|
+
using?: string | UsingPackage[] | Record<string, string>;
|
|
213
|
+
inherits?: string;
|
|
214
|
+
override?: Record<string, string | null>;
|
|
215
|
+
}
|
|
216
|
+
interface PrompdFile {
|
|
217
|
+
metadata: PrompdMetadata;
|
|
218
|
+
content: string;
|
|
219
|
+
sections: Record<string, string>;
|
|
220
|
+
}
|
|
221
|
+
interface CustomProvider {
|
|
222
|
+
apiKey?: string;
|
|
223
|
+
baseUrl: string;
|
|
224
|
+
enabled: boolean;
|
|
225
|
+
models: string[];
|
|
226
|
+
type: string;
|
|
227
|
+
}
|
|
228
|
+
interface RegistryConfig {
|
|
229
|
+
url: string;
|
|
230
|
+
api_key?: string;
|
|
231
|
+
token?: string;
|
|
232
|
+
username?: string;
|
|
233
|
+
}
|
|
234
|
+
interface ProviderConfig {
|
|
235
|
+
baseUrl?: string;
|
|
236
|
+
timeout?: number;
|
|
237
|
+
maxRetries?: number;
|
|
238
|
+
extraHeaders?: Record<string, string>;
|
|
239
|
+
extraParams?: Record<string, any>;
|
|
240
|
+
}
|
|
241
|
+
interface Config {
|
|
242
|
+
apiKeys: Record<string, string>;
|
|
243
|
+
defaultProvider?: string;
|
|
244
|
+
defaultModel?: string;
|
|
245
|
+
customProviders: Record<string, CustomProvider>;
|
|
246
|
+
providerConfigs?: Record<string, ProviderConfig>;
|
|
247
|
+
registry: {
|
|
248
|
+
default?: string;
|
|
249
|
+
registries: Record<string, RegistryConfig>;
|
|
250
|
+
};
|
|
251
|
+
scopes: Record<string, string>;
|
|
252
|
+
namespaces?: Record<string, string>;
|
|
253
|
+
currentNamespace?: string;
|
|
254
|
+
maxRetries?: number;
|
|
255
|
+
timeout?: number;
|
|
256
|
+
verbose?: boolean;
|
|
257
|
+
}
|
|
258
|
+
interface LLMResponse {
|
|
259
|
+
success: boolean;
|
|
260
|
+
response?: string;
|
|
261
|
+
error?: string;
|
|
262
|
+
content?: string;
|
|
263
|
+
usage?: {
|
|
264
|
+
promptTokens: number;
|
|
265
|
+
completionTokens: number;
|
|
266
|
+
totalTokens: number;
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
interface ValidationIssue {
|
|
270
|
+
level: 'error' | 'warning' | 'info';
|
|
271
|
+
message: string;
|
|
272
|
+
line?: number;
|
|
273
|
+
column?: number;
|
|
274
|
+
}
|
|
275
|
+
interface ExecuteOptions {
|
|
276
|
+
provider: string;
|
|
277
|
+
model: string;
|
|
278
|
+
apiKey?: string;
|
|
279
|
+
output?: string;
|
|
280
|
+
params?: Record<string, any>;
|
|
281
|
+
paramFiles?: string[];
|
|
282
|
+
version?: string;
|
|
283
|
+
metaSystem?: string;
|
|
284
|
+
metaContext?: string;
|
|
285
|
+
metaUser?: string;
|
|
286
|
+
verbose?: boolean;
|
|
287
|
+
registryUrl?: string;
|
|
288
|
+
workspaceRoot?: string;
|
|
289
|
+
fileSystem?: IFileSystem;
|
|
290
|
+
temperature?: number;
|
|
291
|
+
maxTokens?: number;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Environment-agnostic .prmd parser. Pure string -> structure; no file system.
|
|
296
|
+
* The Node CLI subclasses this to add fs-backed parseFile()/validateFile().
|
|
297
|
+
*/
|
|
298
|
+
declare class PrompdParser {
|
|
299
|
+
parseContent(content: string, _filePath?: string): PrompdFile;
|
|
300
|
+
/**
|
|
301
|
+
* Parse + validate .prmd content. Pure (no file system) so it runs in the
|
|
302
|
+
* browser. Returns parse errors as a single issue when content is malformed.
|
|
303
|
+
*/
|
|
304
|
+
validateContent(content: string, _filePath?: string): ValidationIssue[];
|
|
305
|
+
protected validatePrompdFile(prompd: PrompdFile): ValidationIssue[];
|
|
306
|
+
private isValidSemver;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Custom error classes for Prompd CLI.
|
|
311
|
+
*/
|
|
312
|
+
declare class PrompdError extends Error {
|
|
313
|
+
constructor(message: string);
|
|
314
|
+
}
|
|
315
|
+
declare class ParseError extends PrompdError {
|
|
316
|
+
constructor(message: string);
|
|
317
|
+
}
|
|
318
|
+
declare class ValidationError extends PrompdError {
|
|
319
|
+
constructor(message: string);
|
|
320
|
+
}
|
|
321
|
+
declare class CompilationError extends PrompdError {
|
|
322
|
+
constructor(message: string);
|
|
323
|
+
}
|
|
324
|
+
declare class SecurityError extends PrompdError {
|
|
325
|
+
constructor(message: string);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Compilation pipeline types and interfaces.
|
|
330
|
+
*
|
|
331
|
+
* This module defines the core types used throughout the 6-stage compilation pipeline,
|
|
332
|
+
* mirroring the Python CLI's architecture for feature parity.
|
|
333
|
+
*/
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Options for resolving a package reference to a path.
|
|
337
|
+
*/
|
|
338
|
+
interface ResolvePackageOptions {
|
|
339
|
+
fileSystem?: IFileSystem;
|
|
340
|
+
registryUrl?: string;
|
|
341
|
+
workspaceRoot?: string;
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Injectable package resolver. The Node CLI provides a disk/registry-backed
|
|
345
|
+
* implementation; the browser omits it (single-file compile only), in which
|
|
346
|
+
* case stages that need package/inherits resolution emit a diagnostic instead
|
|
347
|
+
* of importing Node-only code.
|
|
348
|
+
*/
|
|
349
|
+
interface IPackageResolver {
|
|
350
|
+
resolvePackage(packageRef: string, options: ResolvePackageOptions): Promise<string>;
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Stages of the compilation pipeline.
|
|
354
|
+
*/
|
|
355
|
+
declare enum CompilationStage {
|
|
356
|
+
LEXICAL_ANALYSIS = "lexical_analysis",
|
|
357
|
+
DEPENDENCY_RESOLUTION = "dependency_resolution",
|
|
358
|
+
SEMANTIC_ANALYSIS = "semantic_analysis",
|
|
359
|
+
ASSET_EXTRACTION = "asset_extraction",
|
|
360
|
+
TEMPLATE_PROCESSING = "template_processing",
|
|
361
|
+
CODE_GENERATION = "code_generation"
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Resolved package information.
|
|
365
|
+
*/
|
|
366
|
+
interface ResolvedPackage {
|
|
367
|
+
path: string;
|
|
368
|
+
prefix?: string;
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Structured diagnostic message with location information.
|
|
372
|
+
* Used for both errors and warnings to enable IDE integration.
|
|
373
|
+
*/
|
|
374
|
+
interface CompilationDiagnostic {
|
|
375
|
+
/** The diagnostic message */
|
|
376
|
+
message: string;
|
|
377
|
+
/** Severity level */
|
|
378
|
+
severity: 'error' | 'warning' | 'info';
|
|
379
|
+
/** Source stage that generated this diagnostic */
|
|
380
|
+
source?: string;
|
|
381
|
+
/** Starting line number (1-indexed) */
|
|
382
|
+
line?: number;
|
|
383
|
+
/** Starting column number (1-indexed) */
|
|
384
|
+
column?: number;
|
|
385
|
+
/** Ending line number (1-indexed) */
|
|
386
|
+
endLine?: number;
|
|
387
|
+
/** Ending column number (1-indexed) */
|
|
388
|
+
endColumn?: number;
|
|
389
|
+
/** Optional error code for quick-fix identification */
|
|
390
|
+
code?: string;
|
|
391
|
+
/** File path if different from main source file */
|
|
392
|
+
file?: string;
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Context passed between compilation stages.
|
|
396
|
+
*
|
|
397
|
+
* Accumulates data as it flows through the pipeline, collecting errors,
|
|
398
|
+
* warnings, and transforming content at each stage.
|
|
399
|
+
*/
|
|
400
|
+
declare class CompilationContext {
|
|
401
|
+
sourceFile: string;
|
|
402
|
+
metadata?: PrompdMetadata;
|
|
403
|
+
content?: string;
|
|
404
|
+
/** Raw source content for line number calculation */
|
|
405
|
+
rawSource?: string;
|
|
406
|
+
dependencies: {
|
|
407
|
+
imports?: Record<string, ResolvedPackage>;
|
|
408
|
+
inherits?: string;
|
|
409
|
+
};
|
|
410
|
+
parameters: Record<string, any>;
|
|
411
|
+
contexts: string[];
|
|
412
|
+
/** Legacy string errors for backward compatibility */
|
|
413
|
+
errors: string[];
|
|
414
|
+
/** Legacy string warnings for backward compatibility */
|
|
415
|
+
warnings: string[];
|
|
416
|
+
/** Structured diagnostics with location information */
|
|
417
|
+
diagnostics: CompilationDiagnostic[];
|
|
418
|
+
outputFormat: string;
|
|
419
|
+
compiledResult?: string | Uint8Array;
|
|
420
|
+
verbose: boolean;
|
|
421
|
+
fileSystem: IFileSystem;
|
|
422
|
+
registryUrl?: string;
|
|
423
|
+
workspaceRoot?: string;
|
|
424
|
+
packageResolver?: IPackageResolver;
|
|
425
|
+
constructor(sourceFile: string, options?: CompilationOptions);
|
|
426
|
+
/**
|
|
427
|
+
* Add an error to the compilation context (legacy string format).
|
|
428
|
+
*/
|
|
429
|
+
addError(message: string): void;
|
|
430
|
+
/**
|
|
431
|
+
* Add a warning to the compilation context (legacy string format).
|
|
432
|
+
*/
|
|
433
|
+
addWarning(message: string): void;
|
|
434
|
+
/**
|
|
435
|
+
* Add a structured diagnostic with location information.
|
|
436
|
+
*/
|
|
437
|
+
addDiagnostic(diagnostic: CompilationDiagnostic): void;
|
|
438
|
+
/**
|
|
439
|
+
* Find line and column for a pattern in the raw source.
|
|
440
|
+
* Returns 1-indexed line and column numbers.
|
|
441
|
+
*/
|
|
442
|
+
findLocation(pattern: string | RegExp): {
|
|
443
|
+
line: number;
|
|
444
|
+
column: number;
|
|
445
|
+
endLine: number;
|
|
446
|
+
endColumn: number;
|
|
447
|
+
} | null;
|
|
448
|
+
/**
|
|
449
|
+
* Check if compilation has errors.
|
|
450
|
+
*/
|
|
451
|
+
hasErrors(): boolean;
|
|
452
|
+
/**
|
|
453
|
+
* Get all diagnostics (errors and warnings).
|
|
454
|
+
*/
|
|
455
|
+
getDiagnostics(): CompilationDiagnostic[];
|
|
456
|
+
/**
|
|
457
|
+
* Get only error diagnostics.
|
|
458
|
+
*/
|
|
459
|
+
getErrors(): CompilationDiagnostic[];
|
|
460
|
+
/**
|
|
461
|
+
* Get only warning diagnostics.
|
|
462
|
+
*/
|
|
463
|
+
getWarnings(): CompilationDiagnostic[];
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Options for compilation.
|
|
467
|
+
*/
|
|
468
|
+
interface CompilationOptions {
|
|
469
|
+
outputFormat?: string;
|
|
470
|
+
parameters?: Record<string, any>;
|
|
471
|
+
outputFile?: string;
|
|
472
|
+
verbose?: boolean;
|
|
473
|
+
fileSystem?: IFileSystem;
|
|
474
|
+
/** Injected package resolver (Node CLI provides disk/registry; browser omits). */
|
|
475
|
+
packageResolver?: IPackageResolver;
|
|
476
|
+
/** Registry URL for package resolution. Defaults to https://registry.prompdhub.ai in production. */
|
|
477
|
+
registryUrl?: string;
|
|
478
|
+
/** Root directory for workspace (for package cache location). */
|
|
479
|
+
workspaceRoot?: string;
|
|
480
|
+
/**
|
|
481
|
+
* When true, skip required parameter validation.
|
|
482
|
+
* Use this for validation/diagnostics during editing when parameters won't be provided.
|
|
483
|
+
* When false (default), required parameters are validated during execution.
|
|
484
|
+
*/
|
|
485
|
+
validateOnly?: boolean;
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* Abstract base interface for compiler pipeline stages.
|
|
489
|
+
*/
|
|
490
|
+
interface CompilerStage {
|
|
491
|
+
/**
|
|
492
|
+
* Process the compilation context through this stage.
|
|
493
|
+
*/
|
|
494
|
+
process(context: CompilationContext): Promise<void>;
|
|
495
|
+
/**
|
|
496
|
+
* Get the name of this compilation stage.
|
|
497
|
+
*/
|
|
498
|
+
getName(): string;
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* Represents a compiled prompt ready for formatting.
|
|
502
|
+
*/
|
|
503
|
+
interface CompiledPrompt {
|
|
504
|
+
metadata?: PrompdMetadata;
|
|
505
|
+
content?: string;
|
|
506
|
+
contexts: string[];
|
|
507
|
+
parameters: Record<string, any>;
|
|
508
|
+
verbose: boolean;
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
* Protocol for output format plugins.
|
|
512
|
+
*/
|
|
513
|
+
interface OutputFormatter {
|
|
514
|
+
name: string;
|
|
515
|
+
fileExtension: string;
|
|
516
|
+
mimeType: string;
|
|
517
|
+
/**
|
|
518
|
+
* Format the compiled prompt into the target format.
|
|
519
|
+
*/
|
|
520
|
+
format(compiled: CompiledPrompt): Promise<string>;
|
|
521
|
+
}
|
|
522
|
+
/**
|
|
523
|
+
* Information about a markdown section.
|
|
524
|
+
*/
|
|
525
|
+
interface SectionInfo {
|
|
526
|
+
id: string;
|
|
527
|
+
headingText: string;
|
|
528
|
+
content: string;
|
|
529
|
+
startLine: number;
|
|
530
|
+
endLine: number;
|
|
531
|
+
headingLevel: number;
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* Security configuration for file operations.
|
|
535
|
+
*/
|
|
536
|
+
interface SecurityConfig {
|
|
537
|
+
maxFileSize: number;
|
|
538
|
+
allowedExtensions: string[];
|
|
539
|
+
maxTemplateDepth: number;
|
|
540
|
+
templateTimeout: number;
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* Default security configuration.
|
|
544
|
+
*/
|
|
545
|
+
declare const DEFAULT_SECURITY_CONFIG: SecurityConfig;
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* Compilation pipeline orchestrator.
|
|
549
|
+
*
|
|
550
|
+
* Manages the execution of the 6-stage compilation pipeline, ensuring stages
|
|
551
|
+
* run in order and errors are properly propagated.
|
|
552
|
+
*/
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* The main compiler pipeline orchestrator.
|
|
556
|
+
*/
|
|
557
|
+
declare class CompilerPipeline {
|
|
558
|
+
private stages;
|
|
559
|
+
private securityConfig;
|
|
560
|
+
constructor(stages?: CompilerStage[], securityConfig?: SecurityConfig);
|
|
561
|
+
/**
|
|
562
|
+
* Register a compilation stage.
|
|
563
|
+
*/
|
|
564
|
+
registerStage(stage: CompilerStage): void;
|
|
565
|
+
/**
|
|
566
|
+
* Execute the compilation pipeline.
|
|
567
|
+
*
|
|
568
|
+
* @param source - Path to .prmd file or package reference
|
|
569
|
+
* @param options - Compilation options
|
|
570
|
+
* @returns Compilation context with result or errors
|
|
571
|
+
*/
|
|
572
|
+
execute(source: string, options?: CompilationOptions): Promise<CompilationContext>;
|
|
573
|
+
/**
|
|
574
|
+
* Resolve source to file path (handles package references).
|
|
575
|
+
*
|
|
576
|
+
* @param source - Package reference or file path
|
|
577
|
+
* @param fileSystem - File system to use for resolution
|
|
578
|
+
* @param customFileSystem - Optional custom file system (used to detect in-memory mode)
|
|
579
|
+
* @param registryUrl - Optional registry URL for package resolution
|
|
580
|
+
* @param workspaceRoot - Optional workspace root for package cache location
|
|
581
|
+
*/
|
|
582
|
+
private resolveSource;
|
|
583
|
+
/**
|
|
584
|
+
* Find all .prmd files in a directory.
|
|
585
|
+
*
|
|
586
|
+
* @param dir - Directory path
|
|
587
|
+
* @param fileSystem - File system to use
|
|
588
|
+
*/
|
|
589
|
+
private findPromdFiles;
|
|
590
|
+
/**
|
|
591
|
+
* Get registered stages.
|
|
592
|
+
*/
|
|
593
|
+
getStages(): CompilerStage[];
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* Pure package-reference helpers.
|
|
598
|
+
*
|
|
599
|
+
* These are the parts of the CLI's package-resolver that are environment-agnostic
|
|
600
|
+
* (string parsing + path-safety checks). The Node-only disk/registry resolution
|
|
601
|
+
* (`resolvePackage`, base-dir lookups) lives in @prompd/cli and is injected via
|
|
602
|
+
* IPackageResolver. Path operations are inlined as POSIX so this stays node-free.
|
|
603
|
+
*/
|
|
604
|
+
/**
|
|
605
|
+
* Strip a file path suffix from a package reference.
|
|
606
|
+
* @example "@ns/pkg@1.0.0/prompts/file.prmd" -> "@ns/pkg@1.0.0"
|
|
607
|
+
*/
|
|
608
|
+
declare function stripFilePath(packageRef: string): string;
|
|
609
|
+
/**
|
|
610
|
+
* Parse package reference into name and version. Strips any file path suffix.
|
|
611
|
+
*/
|
|
612
|
+
declare function parsePackageReference(packageRef: string): {
|
|
613
|
+
name: string;
|
|
614
|
+
version: string;
|
|
615
|
+
scope?: string;
|
|
616
|
+
};
|
|
617
|
+
/**
|
|
618
|
+
* Parse a package reference that may include a file path within the package.
|
|
619
|
+
* Format: @namespace/package@version/path/to/file.prmd
|
|
620
|
+
*/
|
|
621
|
+
declare function parsePackageReferenceWithPath(packageRef: string): {
|
|
622
|
+
name: string;
|
|
623
|
+
version: string;
|
|
624
|
+
scope?: string;
|
|
625
|
+
filePath?: string;
|
|
626
|
+
};
|
|
627
|
+
/**
|
|
628
|
+
* Validate package reference format. Accepts optional file path suffix.
|
|
629
|
+
*/
|
|
630
|
+
declare function isValidPackageReference(packageRef: string): boolean;
|
|
631
|
+
/**
|
|
632
|
+
* Resolve a file path within a package (POSIX, path-traversal safe).
|
|
633
|
+
*/
|
|
634
|
+
declare function resolvePackageFile(packagePath: string, filePath: string): string;
|
|
635
|
+
|
|
636
|
+
/**
|
|
637
|
+
* Language Mapping Utilities
|
|
638
|
+
*
|
|
639
|
+
* Centralized file extension to programming language mappings
|
|
640
|
+
* used across the compilation pipeline for:
|
|
641
|
+
* - Wrapping extracted code files in markdown code blocks
|
|
642
|
+
* - Filtering code blocks based on context file types
|
|
643
|
+
*/
|
|
644
|
+
/**
|
|
645
|
+
* Map of file extensions to primary markdown code block language identifier.
|
|
646
|
+
* Used when wrapping extracted code files in markdown code blocks.
|
|
647
|
+
*/
|
|
648
|
+
declare const EXTENSION_TO_LANGUAGE: Record<string, string>;
|
|
649
|
+
/**
|
|
650
|
+
* Map of file extensions to all valid code block language identifiers.
|
|
651
|
+
* Used when filtering code blocks - includes aliases (e.g., 'ts' for 'typescript').
|
|
652
|
+
*/
|
|
653
|
+
declare const EXTENSION_TO_LANGUAGE_ALIASES: Record<string, string[]>;
|
|
654
|
+
/**
|
|
655
|
+
* Get the primary language identifier for a file extension.
|
|
656
|
+
* @param ext - File extension (e.g., '.ts')
|
|
657
|
+
* @returns Primary language identifier or undefined
|
|
658
|
+
*/
|
|
659
|
+
declare function getLanguageForExtension(ext: string): string | undefined;
|
|
660
|
+
/**
|
|
661
|
+
* Get all valid language identifiers (including aliases) for a file extension.
|
|
662
|
+
* @param ext - File extension (e.g., '.ts')
|
|
663
|
+
* @returns Array of language identifiers or empty array
|
|
664
|
+
*/
|
|
665
|
+
declare function getLanguageAliasesForExtension(ext: string): string[];
|
|
666
|
+
|
|
667
|
+
/**
|
|
668
|
+
* Minimal POSIX path helpers so @prompd/core needs no Node 'path' import.
|
|
669
|
+
* The in-memory/virtual file system uses POSIX-style paths throughout.
|
|
670
|
+
*/
|
|
671
|
+
declare function normalizePosix(p: string): string;
|
|
672
|
+
declare function joinPosix(...segments: string[]): string;
|
|
673
|
+
/** POSIX-style resolve relative to a base (absolute segments win). */
|
|
674
|
+
declare function resolvePosix(base: string, p: string): string;
|
|
675
|
+
declare function dirnamePosix(p: string): string;
|
|
676
|
+
declare function basenamePosix(p: string): string;
|
|
677
|
+
declare function isAbsolutePosix(p: string): boolean;
|
|
678
|
+
/** Return the extension including the dot (e.g. ".prmd"), or "" if none. */
|
|
679
|
+
declare function extname(p: string): string;
|
|
680
|
+
/**
|
|
681
|
+
* Prompd source file extensions. A .prmd is just markdown (.md) with YAML
|
|
682
|
+
* frontmatter, so both are treated as first-class prompt sources.
|
|
683
|
+
*/
|
|
684
|
+
declare const PROMPD_EXTENSIONS: readonly [".prmd", ".md"];
|
|
685
|
+
/** True if the path is a Prompd source file (.prmd or .md). */
|
|
686
|
+
declare function isPrompdFile(p: string): boolean;
|
|
687
|
+
|
|
688
|
+
/**
|
|
689
|
+
* Lexical Analysis Stage - Parse YAML frontmatter + Markdown content.
|
|
690
|
+
*
|
|
691
|
+
* This stage parses the .prmd file into structured metadata and content,
|
|
692
|
+
* populating the compilation context for subsequent stages.
|
|
693
|
+
*/
|
|
694
|
+
|
|
695
|
+
declare class LexicalAnalysisStage implements CompilerStage {
|
|
696
|
+
private parser;
|
|
697
|
+
constructor();
|
|
698
|
+
process(context: CompilationContext): Promise<void>;
|
|
699
|
+
/**
|
|
700
|
+
* Convert YAML-defined sections (system, user, assistant, etc.) to markdown sections.
|
|
701
|
+
* These are appended to the content after any markdown-defined sections.
|
|
702
|
+
*/
|
|
703
|
+
private injectYamlSections;
|
|
704
|
+
getName(): string;
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
/**
|
|
708
|
+
* Dependency Resolution Stage
|
|
709
|
+
*
|
|
710
|
+
* Resolves 'using:' imports and 'inherits:' chains, handling both local file
|
|
711
|
+
* paths and package references with alias resolution.
|
|
712
|
+
*
|
|
713
|
+
* This is a direct port of the Python CLI's DependencyResolutionStage.
|
|
714
|
+
*/
|
|
715
|
+
|
|
716
|
+
declare class DependencyResolutionStage implements CompilerStage {
|
|
717
|
+
/**
|
|
718
|
+
* Resolve a package reference via the injected resolver. Absent in the browser
|
|
719
|
+
* (single-file compile), where package/inherits resolution is the backend's job.
|
|
720
|
+
*/
|
|
721
|
+
private resolvePackage;
|
|
722
|
+
process(context: CompilationContext): Promise<void>;
|
|
723
|
+
/**
|
|
724
|
+
* Process the 'using' field for package imports.
|
|
725
|
+
*/
|
|
726
|
+
private processUsingField;
|
|
727
|
+
/**
|
|
728
|
+
* Resolve a single package import.
|
|
729
|
+
*/
|
|
730
|
+
private resolvePackageImport;
|
|
731
|
+
/**
|
|
732
|
+
* Process the 'inherits' field.
|
|
733
|
+
*/
|
|
734
|
+
private processInheritsField;
|
|
735
|
+
/**
|
|
736
|
+
* Process content reference fields (system, context, user, assistant, response) for alias resolution.
|
|
737
|
+
*/
|
|
738
|
+
private processContentFieldAliases;
|
|
739
|
+
/**
|
|
740
|
+
* Resolve alias prefixes in file paths.
|
|
741
|
+
*
|
|
742
|
+
* Examples:
|
|
743
|
+
* - "@pkg/templates/file.prmd" with "@pkg" aliased to "@scope/package@version"
|
|
744
|
+
* becomes "@scope/package@version/templates/file.prmd"
|
|
745
|
+
*/
|
|
746
|
+
private resolveAliasInPath;
|
|
747
|
+
getName(): string;
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
/**
|
|
751
|
+
* Semantic Analysis Stage - Validate parameters and references.
|
|
752
|
+
*
|
|
753
|
+
* This stage validates the semantic correctness of the prompt, checks required
|
|
754
|
+
* parameters, applies default values, and validates parameter types.
|
|
755
|
+
*/
|
|
756
|
+
|
|
757
|
+
declare class SemanticAnalysisStage implements CompilerStage {
|
|
758
|
+
process(context: CompilationContext): Promise<void>;
|
|
759
|
+
/**
|
|
760
|
+
* Validate parameter type.
|
|
761
|
+
*/
|
|
762
|
+
private validateParameterType;
|
|
763
|
+
/**
|
|
764
|
+
* Coerce a parameter value to its declared type.
|
|
765
|
+
* CLI args always arrive as strings; this converts them to the correct runtime type
|
|
766
|
+
* before the value is handed to the template engine.
|
|
767
|
+
* Already-correct types (e.g. from a JSON params file) are passed through unchanged.
|
|
768
|
+
*/
|
|
769
|
+
private coerceParameterValue;
|
|
770
|
+
/**
|
|
771
|
+
* Validate required metadata fields (id, name, version).
|
|
772
|
+
*/
|
|
773
|
+
private validateRequiredMetadata;
|
|
774
|
+
getName(): string;
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
/**
|
|
778
|
+
* Template Processing Stage
|
|
779
|
+
*
|
|
780
|
+
* Processes Jinja2/Nunjucks templates, package references, and section overrides.
|
|
781
|
+
* This is the most complex stage, handling:
|
|
782
|
+
* - Nunjucks template rendering with custom filters (fromcsv, fromjson, tojson, lines)
|
|
783
|
+
* - Package reference resolution and content injection
|
|
784
|
+
* - Inheritance processing with section-aware merging
|
|
785
|
+
* - Enhanced variable substitution with nested property access
|
|
786
|
+
*/
|
|
787
|
+
|
|
788
|
+
declare class TemplateProcessingStage implements CompilerStage {
|
|
789
|
+
private sectionProcessor;
|
|
790
|
+
private nunjucksEnv;
|
|
791
|
+
constructor();
|
|
792
|
+
/**
|
|
793
|
+
* Register custom Jinja2/Nunjucks filters for data transformation.
|
|
794
|
+
*/
|
|
795
|
+
private registerFilters;
|
|
796
|
+
/**
|
|
797
|
+
* Parse CSV string into array of record objects.
|
|
798
|
+
*/
|
|
799
|
+
private parseCsv;
|
|
800
|
+
/**
|
|
801
|
+
* Parse a single CSV line, handling quoted values.
|
|
802
|
+
*/
|
|
803
|
+
private parseCsvLine;
|
|
804
|
+
process(context: CompilationContext): Promise<void>;
|
|
805
|
+
/**
|
|
806
|
+
* Process package references (e.g., @prefix/path/to/file).
|
|
807
|
+
*/
|
|
808
|
+
private processPackageReferences;
|
|
809
|
+
/**
|
|
810
|
+
* Load a resource from a package.
|
|
811
|
+
*/
|
|
812
|
+
private loadPackageResource;
|
|
813
|
+
/**
|
|
814
|
+
* Process inheritance with section-aware merging.
|
|
815
|
+
*/
|
|
816
|
+
private processInheritance;
|
|
817
|
+
/**
|
|
818
|
+
* Process standalone overrides (without inheritance).
|
|
819
|
+
*/
|
|
820
|
+
private processStandaloneOverrides;
|
|
821
|
+
/**
|
|
822
|
+
* Filter code blocks in content based on context file types.
|
|
823
|
+
*
|
|
824
|
+
* When context files are attached (e.g., .ts files), this method filters
|
|
825
|
+
* the prompt content to only keep code blocks that match those file types.
|
|
826
|
+
*
|
|
827
|
+
* Example:
|
|
828
|
+
* - If context contains "typescript-examples.ts", keep only ```typescript blocks
|
|
829
|
+
* - Non-code content and unmatched code blocks are preserved as plain text
|
|
830
|
+
*
|
|
831
|
+
* @param context - The compilation context with extracted contexts
|
|
832
|
+
* @param content - The markdown content to filter
|
|
833
|
+
* @returns Filtered content with only matching code blocks
|
|
834
|
+
*/
|
|
835
|
+
private filterCodeBlocksByContext;
|
|
836
|
+
/**
|
|
837
|
+
* Extract file extensions from context metadata.
|
|
838
|
+
* Context can be a single file path string or an array of file paths.
|
|
839
|
+
*/
|
|
840
|
+
private extractContextExtensions;
|
|
841
|
+
/**
|
|
842
|
+
* Filter code blocks in markdown content, keeping only those with matching languages.
|
|
843
|
+
*
|
|
844
|
+
* @param content - Markdown content with code blocks
|
|
845
|
+
* @param allowedLanguages - Set of allowed language identifiers (lowercase)
|
|
846
|
+
* @param verbose - Whether to log filtering actions
|
|
847
|
+
* @returns Object with filtered content and count of removed blocks
|
|
848
|
+
*/
|
|
849
|
+
private filterCodeBlocks;
|
|
850
|
+
/**
|
|
851
|
+
* Process template with Jinja2/Nunjucks.
|
|
852
|
+
* Uses a context-aware environment with PrompdLoader to support {% include %}.
|
|
853
|
+
*/
|
|
854
|
+
private processTemplate;
|
|
855
|
+
/**
|
|
856
|
+
* Resolve relative {% include %} paths in content to absolute paths.
|
|
857
|
+
* This ensures that when parent content is merged into a child file,
|
|
858
|
+
* the includes still resolve correctly relative to the parent's directory.
|
|
859
|
+
*/
|
|
860
|
+
private resolveIncludePaths;
|
|
861
|
+
/**
|
|
862
|
+
* Register custom filters on a Nunjucks environment.
|
|
863
|
+
*/
|
|
864
|
+
private registerFiltersOnEnv;
|
|
865
|
+
/**
|
|
866
|
+
* Enhanced simple substitution with nested property access.
|
|
867
|
+
* Supports both single brace {var} and double brace {{var}} syntax for backward compatibility.
|
|
868
|
+
*/
|
|
869
|
+
private enhancedSimpleSubstitution;
|
|
870
|
+
/**
|
|
871
|
+
* Escape special regex characters.
|
|
872
|
+
*/
|
|
873
|
+
private escapeRegex;
|
|
874
|
+
/**
|
|
875
|
+
* Validate that all file references in a parent .prmd's metadata actually exist.
|
|
876
|
+
* Called during inheritance processing because AssetExtractionStage only runs on
|
|
877
|
+
* the child file's metadata — the parent is only parsed, never fully compiled.
|
|
878
|
+
*/
|
|
879
|
+
private validateParentFileReferences;
|
|
880
|
+
getName(): string;
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
/**
|
|
884
|
+
* Code Generation Stage
|
|
885
|
+
*
|
|
886
|
+
* Generates output in the target format using registered formatters.
|
|
887
|
+
*/
|
|
888
|
+
|
|
889
|
+
declare class CodeGenerationStage implements CompilerStage {
|
|
890
|
+
private formatters;
|
|
891
|
+
constructor(formatters?: Map<string, OutputFormatter>);
|
|
892
|
+
/**
|
|
893
|
+
* Register a new output formatter.
|
|
894
|
+
*/
|
|
895
|
+
registerFormatter(formatter: OutputFormatter): void;
|
|
896
|
+
process(context: CompilationContext): Promise<void>;
|
|
897
|
+
getName(): string;
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
/**
|
|
901
|
+
* Section Override Processing
|
|
902
|
+
*
|
|
903
|
+
* Provides complete functionality for parsing, validating, and applying
|
|
904
|
+
* section-based content overrides in prompd template inheritance.
|
|
905
|
+
*
|
|
906
|
+
* This is a direct port of the Python CLI's SectionOverrideProcessor.
|
|
907
|
+
*/
|
|
908
|
+
|
|
909
|
+
declare class SectionOverrideProcessor {
|
|
910
|
+
/** Max override file size (DoS protection). */
|
|
911
|
+
private static readonly MAX_OVERRIDE_SIZE;
|
|
912
|
+
private headingPattern;
|
|
913
|
+
private sectionIdPattern;
|
|
914
|
+
constructor();
|
|
915
|
+
/**
|
|
916
|
+
* Pattern to detect any section-id comment (for validation)
|
|
917
|
+
*/
|
|
918
|
+
private detectSectionIdComment;
|
|
919
|
+
/**
|
|
920
|
+
* Extract all sections from markdown content.
|
|
921
|
+
*/
|
|
922
|
+
extractSections(content: string): Map<string, SectionInfo>;
|
|
923
|
+
/**
|
|
924
|
+
* Apply overrides and merge parent/child sections.
|
|
925
|
+
*/
|
|
926
|
+
applyOverrides(parentSections: Map<string, SectionInfo>, childSections: Map<string, SectionInfo>, overrides: Record<string, string | null>, baseDir: string, verbose?: boolean, fileSystem?: IFileSystem): Promise<string>;
|
|
927
|
+
/**
|
|
928
|
+
* Load override content from a file.
|
|
929
|
+
*/
|
|
930
|
+
loadOverrideContent(overridePath: string, baseDir: string, fileSystem?: IFileSystem): Promise<string>;
|
|
931
|
+
/**
|
|
932
|
+
* Resolve override path with security checks.
|
|
933
|
+
*/
|
|
934
|
+
private resolveOverridePath;
|
|
935
|
+
/**
|
|
936
|
+
* Generate a section ID from heading text (kebab-case).
|
|
937
|
+
*/
|
|
938
|
+
private generateSectionId;
|
|
939
|
+
/**
|
|
940
|
+
* Validate section ID format.
|
|
941
|
+
*/
|
|
942
|
+
private validateSectionId;
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
/**
|
|
946
|
+
* Custom Nunjucks Loader for Prompd Files
|
|
947
|
+
*
|
|
948
|
+
* This loader enables {% include %} directives in .prmd files with compile-aware behavior:
|
|
949
|
+
* - .prmd files: Parses and returns only the body content (frontmatter stripped)
|
|
950
|
+
* - Other files (.md, .txt, etc.): Returns raw content as-is
|
|
951
|
+
*
|
|
952
|
+
* Features:
|
|
953
|
+
* - Workspace-aware path resolution (relative to source file)
|
|
954
|
+
* - Circular include detection
|
|
955
|
+
* - Compile-on-demand for .prmd files
|
|
956
|
+
*/
|
|
957
|
+
|
|
958
|
+
/**
|
|
959
|
+
* Options for the Prompd loader.
|
|
960
|
+
*/
|
|
961
|
+
interface PrompdLoaderOptions {
|
|
962
|
+
/** File system abstraction (real FS or in-memory) */
|
|
963
|
+
fileSystem: IFileSystem;
|
|
964
|
+
/** Base directory for resolving relative paths */
|
|
965
|
+
baseDir: string;
|
|
966
|
+
/** Enable verbose logging */
|
|
967
|
+
verbose?: boolean;
|
|
968
|
+
/** Maximum include depth to prevent infinite recursion */
|
|
969
|
+
maxDepth?: number;
|
|
970
|
+
/** Unique compilation ID for tracking include stack across loader instances */
|
|
971
|
+
compilationId?: string;
|
|
972
|
+
}
|
|
973
|
+
/**
|
|
974
|
+
* Loader result with source content and metadata.
|
|
975
|
+
* Matches Nunjucks LoaderSource interface.
|
|
976
|
+
*/
|
|
977
|
+
interface LoaderResult {
|
|
978
|
+
src: string;
|
|
979
|
+
path: string;
|
|
980
|
+
noCache: boolean;
|
|
981
|
+
}
|
|
982
|
+
/**
|
|
983
|
+
* Custom Nunjucks loader that handles .prmd files specially.
|
|
984
|
+
*
|
|
985
|
+
* When a .prmd file is included, this loader:
|
|
986
|
+
* 1. Parses the frontmatter
|
|
987
|
+
* 2. Extracts only the body content
|
|
988
|
+
* 3. Returns the body for inclusion
|
|
989
|
+
*
|
|
990
|
+
* This allows prompts to be composed from other prompts without
|
|
991
|
+
* duplicating frontmatter or metadata.
|
|
992
|
+
*/
|
|
993
|
+
declare class PrompdLoader extends nunjucks.Loader {
|
|
994
|
+
async: boolean;
|
|
995
|
+
private fileSystem;
|
|
996
|
+
private baseDir;
|
|
997
|
+
private verbose;
|
|
998
|
+
private maxDepth;
|
|
999
|
+
private parser;
|
|
1000
|
+
private compilationId;
|
|
1001
|
+
constructor(options: PrompdLoaderOptions);
|
|
1002
|
+
/**
|
|
1003
|
+
* Get the include stack for this compilation.
|
|
1004
|
+
*/
|
|
1005
|
+
private getIncludeStack;
|
|
1006
|
+
/**
|
|
1007
|
+
* Clean up the global stack after compilation is complete.
|
|
1008
|
+
* Should be called when the top-level compilation finishes.
|
|
1009
|
+
*/
|
|
1010
|
+
static cleanupCompilation(compilationId: string): void;
|
|
1011
|
+
/**
|
|
1012
|
+
* Get the source content for a template.
|
|
1013
|
+
* This is the main entry point called by Nunjucks.
|
|
1014
|
+
* Throws an error if the file is not found (required by Nunjucks interface).
|
|
1015
|
+
*/
|
|
1016
|
+
getSource(name: string): LoaderResult;
|
|
1017
|
+
/**
|
|
1018
|
+
* Load and process a file.
|
|
1019
|
+
* Note: We do NOT remove from stack after loading because Nunjucks will process
|
|
1020
|
+
* the returned content which may contain more includes. The stack tracks the
|
|
1021
|
+
* entire include chain during a single compilation.
|
|
1022
|
+
*/
|
|
1023
|
+
private loadFile;
|
|
1024
|
+
/**
|
|
1025
|
+
* Process a .prmd file: parse frontmatter and return only the body.
|
|
1026
|
+
*/
|
|
1027
|
+
private processPrompdFile;
|
|
1028
|
+
/**
|
|
1029
|
+
* Resolve a path relative to the base directory.
|
|
1030
|
+
*/
|
|
1031
|
+
private resolvePath;
|
|
1032
|
+
/**
|
|
1033
|
+
* Create a child loader for nested includes.
|
|
1034
|
+
* The child loader shares the compilation ID to use the same include stack.
|
|
1035
|
+
*/
|
|
1036
|
+
createChildLoader(newBaseDir: string): PrompdLoader;
|
|
1037
|
+
/**
|
|
1038
|
+
* Get the compilation ID for this loader.
|
|
1039
|
+
* Useful for cleanup after compilation.
|
|
1040
|
+
*/
|
|
1041
|
+
getCompilationId(): string;
|
|
1042
|
+
}
|
|
1043
|
+
/**
|
|
1044
|
+
* Create a Nunjucks environment configured with the Prompd loader.
|
|
1045
|
+
*
|
|
1046
|
+
* @param options - Loader options
|
|
1047
|
+
* @returns Configured Nunjucks environment
|
|
1048
|
+
*/
|
|
1049
|
+
declare function createPrompdEnvironment(options: PrompdLoaderOptions): nunjucks.Environment;
|
|
1050
|
+
|
|
1051
|
+
/**
|
|
1052
|
+
* Markdown Output Formatter
|
|
1053
|
+
*
|
|
1054
|
+
* Formats compiled prompts as human-readable markdown with optional YAML frontmatter.
|
|
1055
|
+
*/
|
|
1056
|
+
|
|
1057
|
+
declare class MarkdownFormatter implements OutputFormatter {
|
|
1058
|
+
name: string;
|
|
1059
|
+
fileExtension: string;
|
|
1060
|
+
mimeType: string;
|
|
1061
|
+
format(compiled: CompiledPrompt): Promise<string>;
|
|
1062
|
+
/**
|
|
1063
|
+
* Clean metadata dictionary for YAML display, converting complex objects to strings.
|
|
1064
|
+
*/
|
|
1065
|
+
private cleanMetadataForDisplay;
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
/**
|
|
1069
|
+
* OpenAI API JSON Formatter
|
|
1070
|
+
*
|
|
1071
|
+
* Formats compiled prompts for OpenAI API consumption with proper message structure.
|
|
1072
|
+
*/
|
|
1073
|
+
|
|
1074
|
+
declare class OpenAIFormatter implements OutputFormatter {
|
|
1075
|
+
name: string;
|
|
1076
|
+
fileExtension: string;
|
|
1077
|
+
mimeType: string;
|
|
1078
|
+
format(compiled: CompiledPrompt): Promise<string>;
|
|
1079
|
+
/**
|
|
1080
|
+
* Parse all sections from markdown content.
|
|
1081
|
+
*/
|
|
1082
|
+
private parseSections;
|
|
1083
|
+
/**
|
|
1084
|
+
* Convert section name to message role.
|
|
1085
|
+
*/
|
|
1086
|
+
private sectionToRole;
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
/**
|
|
1090
|
+
* Anthropic Claude API JSON Formatter
|
|
1091
|
+
*
|
|
1092
|
+
* Formats compiled prompts for Anthropic Claude API with system field and messages.
|
|
1093
|
+
*/
|
|
1094
|
+
|
|
1095
|
+
declare class AnthropicFormatter implements OutputFormatter {
|
|
1096
|
+
name: string;
|
|
1097
|
+
fileExtension: string;
|
|
1098
|
+
mimeType: string;
|
|
1099
|
+
format(compiled: CompiledPrompt): Promise<string>;
|
|
1100
|
+
/**
|
|
1101
|
+
* Parse all sections from markdown content.
|
|
1102
|
+
*/
|
|
1103
|
+
private parseSections;
|
|
1104
|
+
/**
|
|
1105
|
+
* Convert section name to message role.
|
|
1106
|
+
*/
|
|
1107
|
+
private sectionToRole;
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
/**
|
|
1111
|
+
* @prompd/core compiler — environment-agnostic assembly.
|
|
1112
|
+
*
|
|
1113
|
+
* Assembles the browser/server-safe compilation pipeline:
|
|
1114
|
+
* Lexical -> Dependency -> Semantic -> Template -> CodeGeneration
|
|
1115
|
+
*
|
|
1116
|
+
* The binary AssetExtractionStage (sharp/pdf/exceljs/mammoth) is Node-only and
|
|
1117
|
+
* lives in @prompd/cli, which assembles the full pipeline. Package/inheritance
|
|
1118
|
+
* resolution is injected via IPackageResolver (also Node-only); without it, the
|
|
1119
|
+
* dependency stage emits a diagnostic and single-file compilation still works.
|
|
1120
|
+
*/
|
|
1121
|
+
|
|
1122
|
+
/**
|
|
1123
|
+
* Default browser/server-safe stage set (no binary asset extraction).
|
|
1124
|
+
*/
|
|
1125
|
+
declare function createCoreStages(): CompilerStage[];
|
|
1126
|
+
/**
|
|
1127
|
+
* High-level compiler. Defaults to the core (browser-safe) stage set; callers
|
|
1128
|
+
* such as @prompd/cli pass a custom stage list (adding asset extraction).
|
|
1129
|
+
*/
|
|
1130
|
+
declare class PrompdCompiler {
|
|
1131
|
+
protected pipeline: CompilerPipeline;
|
|
1132
|
+
protected securityConfig: SecurityConfig;
|
|
1133
|
+
constructor(options?: {
|
|
1134
|
+
stages?: CompilerStage[];
|
|
1135
|
+
securityConfig?: SecurityConfig;
|
|
1136
|
+
});
|
|
1137
|
+
/**
|
|
1138
|
+
* Compile a .prmd source to a string. Throws CompilationError on errors.
|
|
1139
|
+
*/
|
|
1140
|
+
compile(source: string, options?: CompilationOptions): Promise<string>;
|
|
1141
|
+
/**
|
|
1142
|
+
* Compile and return the full context (output + diagnostics, no throw).
|
|
1143
|
+
*/
|
|
1144
|
+
compileWithContext(source: string, options?: CompilationOptions): Promise<CompilationContext>;
|
|
1145
|
+
/** Access the underlying pipeline (advanced customization). */
|
|
1146
|
+
getPipeline(): CompilerPipeline;
|
|
1147
|
+
}
|
|
1148
|
+
/**
|
|
1149
|
+
* Convenience function for quick single-file compilation.
|
|
1150
|
+
*/
|
|
1151
|
+
declare function compile(source: string, outputFormat?: string, parameters?: Record<string, any>, options?: Omit<CompilationOptions, 'outputFormat' | 'parameters'>): Promise<string>;
|
|
1152
|
+
|
|
1153
|
+
/**
|
|
1154
|
+
* Workflow Types - TypeScript interfaces for .pdflow files
|
|
1155
|
+
*/
|
|
1156
|
+
interface WorkflowFile {
|
|
1157
|
+
version: string;
|
|
1158
|
+
metadata: WorkflowMetadata;
|
|
1159
|
+
parameters?: WorkflowParameter[];
|
|
1160
|
+
using?: PackageAlias[];
|
|
1161
|
+
variables?: WorkflowVariable[];
|
|
1162
|
+
nodes: WorkflowNode[];
|
|
1163
|
+
edges: WorkflowEdge[];
|
|
1164
|
+
errorHandling?: ErrorHandlingConfig;
|
|
1165
|
+
execution?: ExecutionConfig;
|
|
1166
|
+
}
|
|
1167
|
+
interface WorkflowMetadata {
|
|
1168
|
+
id: string;
|
|
1169
|
+
name: string;
|
|
1170
|
+
description?: string;
|
|
1171
|
+
author?: string;
|
|
1172
|
+
version?: string;
|
|
1173
|
+
tags?: string[];
|
|
1174
|
+
}
|
|
1175
|
+
interface WorkflowParameter {
|
|
1176
|
+
name: string;
|
|
1177
|
+
type: 'string' | 'number' | 'boolean' | 'array' | 'object' | 'integer' | 'date' | 'datetime';
|
|
1178
|
+
required?: boolean;
|
|
1179
|
+
description?: string;
|
|
1180
|
+
default?: unknown;
|
|
1181
|
+
enum?: string[];
|
|
1182
|
+
min?: number;
|
|
1183
|
+
max?: number;
|
|
1184
|
+
}
|
|
1185
|
+
interface PackageAlias {
|
|
1186
|
+
name: string;
|
|
1187
|
+
prefix: string;
|
|
1188
|
+
}
|
|
1189
|
+
interface WorkflowVariable {
|
|
1190
|
+
name: string;
|
|
1191
|
+
type: string;
|
|
1192
|
+
scope?: 'workflow' | 'node';
|
|
1193
|
+
default?: unknown;
|
|
1194
|
+
}
|
|
1195
|
+
type WorkflowNodeType = 'trigger' | 'prompt' | 'provider' | 'condition' | 'loop' | 'parallel' | 'merge' | 'transformer' | 'api' | 'tool' | 'tool-call-parser' | 'tool-call-router' | 'agent' | 'chat-agent' | 'guardrail' | 'callback' | 'checkpoint' | 'user-input' | 'error-handler' | 'command' | 'claude-code' | 'workflow' | 'mcp-tool' | 'code' | 'memory' | 'output' | 'web-search' | 'database-query';
|
|
1196
|
+
interface WorkflowNode {
|
|
1197
|
+
id: string;
|
|
1198
|
+
type: WorkflowNodeType;
|
|
1199
|
+
position: {
|
|
1200
|
+
x: number;
|
|
1201
|
+
y: number;
|
|
1202
|
+
};
|
|
1203
|
+
data: TriggerNodeData | PromptNodeData | ProviderNodeData | ConditionNodeData | LoopNodeData | ParallelNodeData | MergeNodeData | TransformerNodeData | ApiNodeData | ToolNodeData | ToolCallParserNodeData | ToolCallRouterNodeData | AgentNodeData | ChatAgentNodeData | GuardrailNodeData | CallbackNodeData | UserInputNodeData | ErrorHandlerNodeData | CommandNodeData | ClaudeCodeNodeData | WorkflowNodeData | McpToolNodeData | CodeNodeData | MemoryNodeData | OutputNodeData | WebSearchNodeData;
|
|
1204
|
+
/** Parent node ID for compound nodes (loop/parallel containers) */
|
|
1205
|
+
parentId?: string;
|
|
1206
|
+
/** Extent for child nodes - 'parent' constrains to parent bounds */
|
|
1207
|
+
extent?: 'parent' | [number, number, number, number];
|
|
1208
|
+
/** Whether this node is expandable (container nodes) */
|
|
1209
|
+
expandParent?: boolean;
|
|
1210
|
+
/** Width for resizable container nodes */
|
|
1211
|
+
width?: number;
|
|
1212
|
+
/** Height for resizable container nodes */
|
|
1213
|
+
height?: number;
|
|
1214
|
+
/** Style overrides */
|
|
1215
|
+
style?: Record<string, unknown>;
|
|
1216
|
+
}
|
|
1217
|
+
interface BaseNodeData {
|
|
1218
|
+
label: string;
|
|
1219
|
+
/** Disable this node to skip it during workflow execution */
|
|
1220
|
+
disabled?: boolean;
|
|
1221
|
+
/** Lock the node to prevent dragging/moving */
|
|
1222
|
+
locked?: boolean;
|
|
1223
|
+
/** Reference to ErrorHandler node for this node's errors */
|
|
1224
|
+
errorHandlerNodeId?: string;
|
|
1225
|
+
/** Override: stop workflow immediately on error (ignores errorHandler) */
|
|
1226
|
+
failFast?: boolean;
|
|
1227
|
+
/** Reference to a Connection for external service access (SSH, Database, HTTP API, etc.) */
|
|
1228
|
+
connectionId?: string;
|
|
1229
|
+
/**
|
|
1230
|
+
* Docking configuration - when this node is docked to another node's handle.
|
|
1231
|
+
* Docked nodes appear as mini 24px circle previews attached to the host handle.
|
|
1232
|
+
*/
|
|
1233
|
+
dockedTo?: {
|
|
1234
|
+
/** ID of the host node this node is docked to */
|
|
1235
|
+
nodeId: string;
|
|
1236
|
+
/** Handle ID on the host node (e.g., 'rejected', 'onError', 'output') */
|
|
1237
|
+
handleId: string;
|
|
1238
|
+
};
|
|
1239
|
+
/** Saved width before docking (for restoring on undock) */
|
|
1240
|
+
_preDockWidth?: number;
|
|
1241
|
+
/** Saved height before docking (for restoring on undock) */
|
|
1242
|
+
_preDockHeight?: number;
|
|
1243
|
+
/** Saved position before docking (for restoring on undock) */
|
|
1244
|
+
_preDockPosition?: {
|
|
1245
|
+
x: number;
|
|
1246
|
+
y: number;
|
|
1247
|
+
};
|
|
1248
|
+
[key: string]: unknown;
|
|
1249
|
+
}
|
|
1250
|
+
/** Node types that can be docked to handles */
|
|
1251
|
+
declare const DOCKABLE_NODE_TYPES: WorkflowNodeType[];
|
|
1252
|
+
/** Handle configurations that accept docked nodes */
|
|
1253
|
+
declare const DOCKABLE_HANDLES: Array<{
|
|
1254
|
+
nodeType: WorkflowNodeType;
|
|
1255
|
+
handleId: string;
|
|
1256
|
+
position: {
|
|
1257
|
+
side: 'left' | 'right' | 'bottom';
|
|
1258
|
+
topPercent: number;
|
|
1259
|
+
};
|
|
1260
|
+
acceptsTypes: WorkflowNodeType[];
|
|
1261
|
+
}>;
|
|
1262
|
+
/**
|
|
1263
|
+
* TriggerNodeData - Workflow entry point configuration
|
|
1264
|
+
*
|
|
1265
|
+
* Trigger types:
|
|
1266
|
+
* - manual: User clicks "Run" button (default)
|
|
1267
|
+
* - webhook: HTTP POST to a generated endpoint
|
|
1268
|
+
* - schedule: Cron expression or interval-based
|
|
1269
|
+
* - file-watch: File system changes (Electron only)
|
|
1270
|
+
* - event: Internal event from another workflow
|
|
1271
|
+
*
|
|
1272
|
+
* Every workflow should have exactly one TriggerNode as its entry point.
|
|
1273
|
+
* The trigger node has no inputs and one output that starts the workflow.
|
|
1274
|
+
*/
|
|
1275
|
+
interface TriggerNodeData extends BaseNodeData {
|
|
1276
|
+
/** Type of trigger */
|
|
1277
|
+
triggerType: 'manual' | 'webhook' | 'schedule' | 'file-watch' | 'event';
|
|
1278
|
+
/** Description of when/how this workflow runs */
|
|
1279
|
+
description?: string;
|
|
1280
|
+
/** Webhook path suffix (e.g., '/my-workflow' -> POST /api/webhooks/my-workflow) */
|
|
1281
|
+
webhookPath?: string;
|
|
1282
|
+
/** Secret for HMAC signature validation */
|
|
1283
|
+
webhookSecret?: string;
|
|
1284
|
+
/** HTTP methods to accept (default: POST only) */
|
|
1285
|
+
webhookMethods?: ('GET' | 'POST' | 'PUT')[];
|
|
1286
|
+
/** Whether to require authentication */
|
|
1287
|
+
webhookRequireAuth?: boolean;
|
|
1288
|
+
/** Schedule type */
|
|
1289
|
+
scheduleType?: 'cron' | 'interval';
|
|
1290
|
+
/** Cron expression (e.g., '0 9 * * *' for 9am daily) */
|
|
1291
|
+
scheduleCron?: string;
|
|
1292
|
+
/** Interval in milliseconds (e.g., 60000 for every minute) */
|
|
1293
|
+
scheduleIntervalMs?: number;
|
|
1294
|
+
/** Timezone for cron expressions (default: UTC) */
|
|
1295
|
+
scheduleTimezone?: string;
|
|
1296
|
+
/** Whether schedule is currently active */
|
|
1297
|
+
scheduleEnabled?: boolean;
|
|
1298
|
+
/** Glob patterns for files to watch */
|
|
1299
|
+
fileWatchPaths?: string[];
|
|
1300
|
+
/** Events to trigger on */
|
|
1301
|
+
fileWatchEvents?: ('create' | 'modify' | 'delete')[];
|
|
1302
|
+
/** Debounce time in ms to batch rapid changes */
|
|
1303
|
+
fileWatchDebounceMs?: number;
|
|
1304
|
+
/** Whether to watch subdirectories */
|
|
1305
|
+
fileWatchRecursive?: boolean;
|
|
1306
|
+
/** Event name to listen for */
|
|
1307
|
+
eventName?: string;
|
|
1308
|
+
/** Optional filter expression for event data */
|
|
1309
|
+
eventFilter?: string;
|
|
1310
|
+
/** Schema for data this trigger provides to the workflow */
|
|
1311
|
+
outputSchema?: JsonSchema;
|
|
1312
|
+
}
|
|
1313
|
+
interface PromptNodeData extends BaseNodeData {
|
|
1314
|
+
/** Source type: 'file' for .prmd file reference, 'raw' for inline text */
|
|
1315
|
+
sourceType?: 'file' | 'raw';
|
|
1316
|
+
/** Path to .prmd file or package reference (used when sourceType is 'file' or undefined) */
|
|
1317
|
+
source: string;
|
|
1318
|
+
/** Raw prompt text (used when sourceType is 'raw') */
|
|
1319
|
+
rawPrompt?: string;
|
|
1320
|
+
/** Reference to a provider node ID, or inline provider name */
|
|
1321
|
+
provider?: string;
|
|
1322
|
+
/** Model name (used with inline provider, ignored if providerNodeId is set) */
|
|
1323
|
+
model?: string;
|
|
1324
|
+
/** Reference to a provider node by ID (preferred over inline provider/model) */
|
|
1325
|
+
providerNodeId?: string;
|
|
1326
|
+
parameters?: Record<string, string>;
|
|
1327
|
+
context?: {
|
|
1328
|
+
previous_output?: 'auto' | string;
|
|
1329
|
+
};
|
|
1330
|
+
outputMapping?: Record<string, string>;
|
|
1331
|
+
inputSchema?: JsonSchema;
|
|
1332
|
+
outputSchema?: JsonSchema;
|
|
1333
|
+
/** Temperature override (0-2) — overrides frontmatter hint, overridden by provider node */
|
|
1334
|
+
temperature?: number;
|
|
1335
|
+
/** Max tokens override — overrides frontmatter hint, overridden by provider node */
|
|
1336
|
+
maxTokens?: number;
|
|
1337
|
+
/** Guardrail configuration (for content filtering/validation) */
|
|
1338
|
+
guardrail?: {
|
|
1339
|
+
/** Whether the guardrail is enabled */
|
|
1340
|
+
enabled?: boolean;
|
|
1341
|
+
/** Output mode when guardrail passes */
|
|
1342
|
+
outputMode?: 'passthrough' | 'original' | 'reject-message';
|
|
1343
|
+
/** Expected response format from LLM */
|
|
1344
|
+
expectedFormat?: 'json' | 'text';
|
|
1345
|
+
/** JSON field to check for rejection status */
|
|
1346
|
+
rejectionField?: string;
|
|
1347
|
+
/** Pass when field is true or false */
|
|
1348
|
+
passWhen?: 'true' | 'false';
|
|
1349
|
+
/** Action to take when guardrail fails */
|
|
1350
|
+
failAction?: 'error' | 'stop' | 'continue';
|
|
1351
|
+
/** Custom message when rejected */
|
|
1352
|
+
customRejectMessage?: string;
|
|
1353
|
+
/** Custom rejection expression (advanced) - overrides simple field check */
|
|
1354
|
+
rejectionExpression?: string;
|
|
1355
|
+
};
|
|
1356
|
+
}
|
|
1357
|
+
/**
|
|
1358
|
+
* ProviderNodeData - LLM provider configuration node
|
|
1359
|
+
*
|
|
1360
|
+
* Centralizes provider/model selection so multiple prompt nodes can reference
|
|
1361
|
+
* the same provider configuration. This makes it easy to switch providers
|
|
1362
|
+
* across an entire workflow.
|
|
1363
|
+
*/
|
|
1364
|
+
interface ProviderNodeData extends BaseNodeData {
|
|
1365
|
+
/** Provider ID (e.g., 'openai', 'anthropic', 'google') */
|
|
1366
|
+
providerId: string;
|
|
1367
|
+
/** Model ID (e.g., 'gpt-4o', 'claude-sonnet-4-20250514') */
|
|
1368
|
+
model: string;
|
|
1369
|
+
/** Optional description for this provider configuration */
|
|
1370
|
+
description?: string;
|
|
1371
|
+
/** Temperature override (0-2) */
|
|
1372
|
+
temperature?: number;
|
|
1373
|
+
/** Max tokens override */
|
|
1374
|
+
maxTokens?: number;
|
|
1375
|
+
}
|
|
1376
|
+
interface ConditionNodeData extends BaseNodeData {
|
|
1377
|
+
conditions: ConditionBranch[];
|
|
1378
|
+
default?: string;
|
|
1379
|
+
}
|
|
1380
|
+
interface ConditionBranch {
|
|
1381
|
+
id: string;
|
|
1382
|
+
expression: string;
|
|
1383
|
+
target: string;
|
|
1384
|
+
}
|
|
1385
|
+
interface LoopNodeData extends BaseNodeData {
|
|
1386
|
+
loopType: 'while' | 'for-each' | 'count';
|
|
1387
|
+
condition?: string;
|
|
1388
|
+
items?: string;
|
|
1389
|
+
itemVariable?: string;
|
|
1390
|
+
count?: number;
|
|
1391
|
+
maxIterations: number;
|
|
1392
|
+
body: string[];
|
|
1393
|
+
onComplete?: string;
|
|
1394
|
+
/** Whether the container is collapsed (hides child nodes) */
|
|
1395
|
+
collapsed?: boolean;
|
|
1396
|
+
}
|
|
1397
|
+
interface ParallelNodeData extends BaseNodeData {
|
|
1398
|
+
/** Execution mode: 'broadcast' (container) or 'fork' (edge-based branches) */
|
|
1399
|
+
mode: 'broadcast' | 'fork';
|
|
1400
|
+
/** Number of output handles in fork mode */
|
|
1401
|
+
forkCount?: number;
|
|
1402
|
+
/** Custom labels for fork branches (indexed by branch number) */
|
|
1403
|
+
forkLabels?: string[];
|
|
1404
|
+
branches: ParallelBranch[];
|
|
1405
|
+
waitFor: 'all' | 'any' | 'race';
|
|
1406
|
+
mergeStrategy: 'object' | 'array' | 'first';
|
|
1407
|
+
/** Whether the container is collapsed (hides child nodes) */
|
|
1408
|
+
collapsed?: boolean;
|
|
1409
|
+
}
|
|
1410
|
+
interface ParallelBranch {
|
|
1411
|
+
id: string;
|
|
1412
|
+
label?: string;
|
|
1413
|
+
nodes: string[];
|
|
1414
|
+
}
|
|
1415
|
+
interface MergeNodeData extends BaseNodeData {
|
|
1416
|
+
inputs: string[];
|
|
1417
|
+
mergeAs: 'object' | 'array';
|
|
1418
|
+
/**
|
|
1419
|
+
* Merge mode determines how the merge node behaves:
|
|
1420
|
+
* - 'wait': Waits for all connected inputs to have outputs before executing (default)
|
|
1421
|
+
* - 'transform': Executes immediately with whatever inputs are available (router/passthrough)
|
|
1422
|
+
*/
|
|
1423
|
+
mode?: 'wait' | 'transform';
|
|
1424
|
+
}
|
|
1425
|
+
/**
|
|
1426
|
+
* TransformerNodeData - Data transformation node
|
|
1427
|
+
*
|
|
1428
|
+
* Transform, reshape, or filter data using templates with {{ variable }} syntax.
|
|
1429
|
+
* Supports multiple transform modes for different use cases.
|
|
1430
|
+
*
|
|
1431
|
+
* Transform Modes:
|
|
1432
|
+
* - template: JSON template with {{ }} variable interpolation
|
|
1433
|
+
* - jq: JQ-style query expressions (future)
|
|
1434
|
+
* - javascript: Inline JS expression (sandboxed)
|
|
1435
|
+
*
|
|
1436
|
+
* Variables:
|
|
1437
|
+
* - {{ previous_output }} - Output from the connected input node
|
|
1438
|
+
* - {{ node_id.property }} - Access specific node outputs
|
|
1439
|
+
* - {{ workflow.param_name }} - Workflow parameters
|
|
1440
|
+
*/
|
|
1441
|
+
interface TransformerNodeData extends BaseNodeData {
|
|
1442
|
+
/** Transform mode */
|
|
1443
|
+
mode: 'template' | 'jq' | 'expression';
|
|
1444
|
+
/** JSON template string with {{ variable }} syntax (for template mode) */
|
|
1445
|
+
template?: string;
|
|
1446
|
+
/** JQ-style query expression (for jq mode, future) */
|
|
1447
|
+
jqExpression?: string;
|
|
1448
|
+
/** JavaScript expression that returns transformed value (for expression mode) */
|
|
1449
|
+
expression?: string;
|
|
1450
|
+
/** Input variable name (defaults to 'input') */
|
|
1451
|
+
inputVariable?: string;
|
|
1452
|
+
/** Whether to pass through unchanged if transform fails */
|
|
1453
|
+
passthroughOnError?: boolean;
|
|
1454
|
+
/** Description of what this transform does */
|
|
1455
|
+
description?: string;
|
|
1456
|
+
transform?: string;
|
|
1457
|
+
}
|
|
1458
|
+
interface ApiNodeData extends BaseNodeData {
|
|
1459
|
+
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
1460
|
+
url: string;
|
|
1461
|
+
headers?: Record<string, string>;
|
|
1462
|
+
body?: string;
|
|
1463
|
+
retryPolicy?: RetryPolicy;
|
|
1464
|
+
}
|
|
1465
|
+
/**
|
|
1466
|
+
* ToolNodeData - Unified tool execution node
|
|
1467
|
+
*
|
|
1468
|
+
* Supports five tool types:
|
|
1469
|
+
* - function: Call a registered function/callback provided to the workflow executor
|
|
1470
|
+
* - mcp: Call a tool exposed by an MCP (Model Context Protocol) server
|
|
1471
|
+
* - http: Make an HTTP request (similar to ApiNodeData but unified interface)
|
|
1472
|
+
* - command: Execute a whitelisted shell command (npm, git, python, etc.)
|
|
1473
|
+
* - code: Execute code snippets (TypeScript/JavaScript, Python, or C#)
|
|
1474
|
+
*
|
|
1475
|
+
* Use cases:
|
|
1476
|
+
* - Database lookups
|
|
1477
|
+
* - Code execution
|
|
1478
|
+
* - External API integration
|
|
1479
|
+
* - MCP-compatible AI tools
|
|
1480
|
+
* - Custom business logic
|
|
1481
|
+
* - Shell command execution
|
|
1482
|
+
* - Data transformation via code
|
|
1483
|
+
*/
|
|
1484
|
+
interface ToolNodeData extends BaseNodeData {
|
|
1485
|
+
/** Tool type determines how the tool is invoked */
|
|
1486
|
+
toolType: 'function' | 'mcp' | 'http' | 'command' | 'code';
|
|
1487
|
+
/** Tool name - for function/mcp types, this identifies the tool to call */
|
|
1488
|
+
toolName: string;
|
|
1489
|
+
/** Description shown in the node and used for documentation */
|
|
1490
|
+
description?: string;
|
|
1491
|
+
/** Input parameters - template expressions supported */
|
|
1492
|
+
parameters?: Record<string, unknown>;
|
|
1493
|
+
/** Parameter schema for validation and UI generation */
|
|
1494
|
+
parameterSchema?: {
|
|
1495
|
+
type: 'object';
|
|
1496
|
+
properties?: Record<string, {
|
|
1497
|
+
type: string;
|
|
1498
|
+
description?: string;
|
|
1499
|
+
default?: unknown;
|
|
1500
|
+
enum?: string[];
|
|
1501
|
+
}>;
|
|
1502
|
+
required?: string[];
|
|
1503
|
+
};
|
|
1504
|
+
/** HTTP method (only for http type) */
|
|
1505
|
+
httpMethod?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
1506
|
+
/** URL template (only for http type) */
|
|
1507
|
+
httpUrl?: string;
|
|
1508
|
+
/** HTTP headers (only for http type) */
|
|
1509
|
+
httpHeaders?: Record<string, string>;
|
|
1510
|
+
/** Request body template (only for http type) */
|
|
1511
|
+
httpBody?: string;
|
|
1512
|
+
/** MCP server URL (only for mcp type) */
|
|
1513
|
+
mcpServerUrl?: string;
|
|
1514
|
+
/** MCP server name/identifier (alternative to URL for configured servers) */
|
|
1515
|
+
mcpServerName?: string;
|
|
1516
|
+
/** The executable to run (must be in allowed list or custom commands) */
|
|
1517
|
+
commandExecutable?: string;
|
|
1518
|
+
/** Action/subcommand (e.g., 'run' for npm, 'status' for git) */
|
|
1519
|
+
commandAction?: string;
|
|
1520
|
+
/** Arguments template (supports {{ }} expressions) */
|
|
1521
|
+
commandArgs?: string;
|
|
1522
|
+
/** Working directory (relative to workspace) */
|
|
1523
|
+
commandCwd?: string;
|
|
1524
|
+
/** Whether this command requires user approval before execution */
|
|
1525
|
+
commandRequiresApproval?: boolean;
|
|
1526
|
+
/** Custom command ID (references CustomCommandConfig from connections) */
|
|
1527
|
+
customCommandId?: string;
|
|
1528
|
+
/** Programming language for code execution */
|
|
1529
|
+
codeLanguage?: 'typescript' | 'javascript' | 'python' | 'csharp';
|
|
1530
|
+
/** The code snippet to execute */
|
|
1531
|
+
codeSnippet?: string;
|
|
1532
|
+
/** Variable name for previous_output (default: 'input') */
|
|
1533
|
+
codeInputVariable?: string;
|
|
1534
|
+
/** For TS/JS: execution context */
|
|
1535
|
+
codeExecutionContext?: 'isolated' | 'main';
|
|
1536
|
+
/** Timeout in milliseconds */
|
|
1537
|
+
timeout?: number;
|
|
1538
|
+
/** Retry policy for failed executions */
|
|
1539
|
+
retryPolicy?: RetryPolicy;
|
|
1540
|
+
/** Transform the result before passing to next node */
|
|
1541
|
+
outputTransform?: string;
|
|
1542
|
+
}
|
|
1543
|
+
/**
|
|
1544
|
+
* ToolCallParserNodeData - Parse LLM output for tool call requests
|
|
1545
|
+
*
|
|
1546
|
+
* This node detects and extracts tool calls from LLM responses, enabling
|
|
1547
|
+
* agentic workflows where the LLM decides which tools to call.
|
|
1548
|
+
*
|
|
1549
|
+
* Supported formats:
|
|
1550
|
+
* - openai: OpenAI function calling format (tool_calls array)
|
|
1551
|
+
* - anthropic: Anthropic tool_use blocks
|
|
1552
|
+
* - xml: XML-style <tool_call> tags
|
|
1553
|
+
* - json: Generic JSON with configurable field names
|
|
1554
|
+
* - auto: Automatically detect format
|
|
1555
|
+
*
|
|
1556
|
+
* Output structure:
|
|
1557
|
+
* {
|
|
1558
|
+
* hasToolCall: boolean,
|
|
1559
|
+
* toolName: string | null,
|
|
1560
|
+
* toolParameters: Record<string, unknown> | null,
|
|
1561
|
+
* remainingText: string, // Text after tool call extraction
|
|
1562
|
+
* rawToolCall: unknown, // Original tool call data
|
|
1563
|
+
* format: string // Detected format
|
|
1564
|
+
* }
|
|
1565
|
+
*/
|
|
1566
|
+
interface ToolCallParserNodeData extends BaseNodeData {
|
|
1567
|
+
/** Format to parse - 'auto' will attempt to detect */
|
|
1568
|
+
format: 'auto' | 'openai' | 'anthropic' | 'xml' | 'json';
|
|
1569
|
+
/** For 'json' format: field name containing the tool name */
|
|
1570
|
+
jsonToolNameField?: string;
|
|
1571
|
+
/** For 'json' format: field name containing the parameters */
|
|
1572
|
+
jsonParametersField?: string;
|
|
1573
|
+
/** For 'xml' format: tag name for tool calls (default: 'tool_call') */
|
|
1574
|
+
xmlTagName?: string;
|
|
1575
|
+
/** List of valid tool names - if provided, only these will be recognized */
|
|
1576
|
+
allowedTools?: string[];
|
|
1577
|
+
/** What to do if no tool call is found */
|
|
1578
|
+
noToolCallBehavior: 'passthrough' | 'error' | 'default';
|
|
1579
|
+
/** Default tool to use if noToolCallBehavior is 'default' */
|
|
1580
|
+
defaultTool?: string;
|
|
1581
|
+
defaultParameters?: Record<string, unknown>;
|
|
1582
|
+
}
|
|
1583
|
+
/**
|
|
1584
|
+
* ToolCallRouterNodeData - Container node for grouping Tool nodes
|
|
1585
|
+
*
|
|
1586
|
+
* This node acts as a container that groups Tool nodes together and routes
|
|
1587
|
+
* tool calls from Agent nodes to the appropriate Tool node based on tool name.
|
|
1588
|
+
*
|
|
1589
|
+
* Usage:
|
|
1590
|
+
* 1. Create a ToolCallRouter node on the canvas
|
|
1591
|
+
* 2. Drag Tool nodes inside the container (they become children via parentId)
|
|
1592
|
+
* 3. Connect Agent's onCheckpoint handle to router's toolCall input
|
|
1593
|
+
* 4. Connect router's toolResult output back to Agent's toolResult input
|
|
1594
|
+
*
|
|
1595
|
+
* The router automatically collects tool schemas from child Tool nodes and
|
|
1596
|
+
* dispatches tool calls to the matching Tool node for execution.
|
|
1597
|
+
*/
|
|
1598
|
+
interface ToolCallRouterNodeData extends BaseNodeData {
|
|
1599
|
+
/** How tool calls are matched to Tool nodes */
|
|
1600
|
+
routingMode: 'name-match' | 'pattern' | 'fallback';
|
|
1601
|
+
/** Behavior when no Tool node matches the requested tool name */
|
|
1602
|
+
onNoMatch: 'error' | 'passthrough' | 'fallback-tool';
|
|
1603
|
+
/** ID of a Tool node inside this router to use as fallback */
|
|
1604
|
+
fallbackToolId?: string;
|
|
1605
|
+
/** Whether the container is collapsed (hides child nodes) */
|
|
1606
|
+
collapsed?: boolean;
|
|
1607
|
+
}
|
|
1608
|
+
interface OutputNodeData extends BaseNodeData {
|
|
1609
|
+
outputSchema?: JsonSchema;
|
|
1610
|
+
result?: unknown;
|
|
1611
|
+
}
|
|
1612
|
+
/**
|
|
1613
|
+
* ErrorHandlerNodeData - Workflow-level error handling configuration
|
|
1614
|
+
*
|
|
1615
|
+
* Error handling is configured as a **workflow-level node** that other nodes
|
|
1616
|
+
* reference by ID (similar to how nodes reference Provider nodes). This avoids
|
|
1617
|
+
* cluttering the graph with inline error edges.
|
|
1618
|
+
*
|
|
1619
|
+
* Nodes reference an ErrorHandler via `errorHandlerNodeId` in BaseNodeData.
|
|
1620
|
+
* When an error occurs, the executor routes it to the referenced ErrorHandler
|
|
1621
|
+
* for retry, fallback, or notification handling.
|
|
1622
|
+
*
|
|
1623
|
+
* Strategies:
|
|
1624
|
+
* - retry: Attempt the operation again with backoff
|
|
1625
|
+
* - fallback: Return a fallback value or execute a fallback node
|
|
1626
|
+
* - notify: Send notification (webhook, log) and continue
|
|
1627
|
+
* - ignore: Swallow the error and continue with null/undefined
|
|
1628
|
+
* - rethrow: Re-throw the error to stop execution
|
|
1629
|
+
*
|
|
1630
|
+
* Visual representation:
|
|
1631
|
+
* - Displayed in "Error Handlers" section of NodePalette
|
|
1632
|
+
* - Rose/red color theme
|
|
1633
|
+
* - Dashed border to indicate "config node" vs "flow node"
|
|
1634
|
+
* - No edges - referenced by ID from other nodes
|
|
1635
|
+
*/
|
|
1636
|
+
interface ErrorHandlerNodeData extends BaseNodeData {
|
|
1637
|
+
/** Error handling strategy */
|
|
1638
|
+
strategy: 'retry' | 'fallback' | 'notify' | 'ignore' | 'rethrow';
|
|
1639
|
+
/** Retry policy */
|
|
1640
|
+
retry?: {
|
|
1641
|
+
/** Maximum number of retry attempts */
|
|
1642
|
+
maxAttempts: number;
|
|
1643
|
+
/** Initial backoff delay in milliseconds */
|
|
1644
|
+
backoffMs: number;
|
|
1645
|
+
/** Backoff multiplier for exponential backoff (e.g., 2 for doubling) */
|
|
1646
|
+
backoffMultiplier?: number;
|
|
1647
|
+
/** Maximum backoff delay in milliseconds */
|
|
1648
|
+
maxBackoffMs?: number;
|
|
1649
|
+
/** Error codes/patterns that should trigger a retry (empty = retry all) */
|
|
1650
|
+
retryOn?: string[];
|
|
1651
|
+
/** Error codes/patterns that should NOT trigger a retry */
|
|
1652
|
+
noRetryOn?: string[];
|
|
1653
|
+
};
|
|
1654
|
+
/** Fallback value or node when all retries exhausted or strategy is 'fallback' */
|
|
1655
|
+
fallback?: {
|
|
1656
|
+
/** Type of fallback */
|
|
1657
|
+
type: 'value' | 'template' | 'node';
|
|
1658
|
+
/** Static value to return (when type is 'value') */
|
|
1659
|
+
value?: unknown;
|
|
1660
|
+
/** Template expression to evaluate (when type is 'template') */
|
|
1661
|
+
template?: string;
|
|
1662
|
+
/** Node ID to execute as fallback (when type is 'node') */
|
|
1663
|
+
nodeId?: string;
|
|
1664
|
+
};
|
|
1665
|
+
/** Notification settings */
|
|
1666
|
+
notify?: {
|
|
1667
|
+
/** Webhook URL to POST error details */
|
|
1668
|
+
webhookUrl?: string;
|
|
1669
|
+
/** HTTP headers for webhook */
|
|
1670
|
+
webhookHeaders?: Record<string, string>;
|
|
1671
|
+
/** Whether to include stack trace in notification */
|
|
1672
|
+
includeStack?: boolean;
|
|
1673
|
+
/** Whether to include node input/context in notification */
|
|
1674
|
+
includeContext?: boolean;
|
|
1675
|
+
/** Custom message template (supports {{ error.message }}, {{ node.id }}, etc.) */
|
|
1676
|
+
messageTemplate?: string;
|
|
1677
|
+
};
|
|
1678
|
+
/** Logging settings */
|
|
1679
|
+
log?: {
|
|
1680
|
+
/** Log level for this error handler */
|
|
1681
|
+
level: 'error' | 'warn' | 'info' | 'debug';
|
|
1682
|
+
/** Whether to include the node data that caused the error */
|
|
1683
|
+
includeNodeData?: boolean;
|
|
1684
|
+
/** Whether to include input data */
|
|
1685
|
+
includeInput?: boolean;
|
|
1686
|
+
};
|
|
1687
|
+
/** Only handle errors matching these conditions */
|
|
1688
|
+
conditions?: {
|
|
1689
|
+
/** Error codes/patterns to match (regex supported) */
|
|
1690
|
+
errorCodes?: string[];
|
|
1691
|
+
/** Error message patterns to match (regex supported) */
|
|
1692
|
+
messagePatterns?: string[];
|
|
1693
|
+
/** Node types this handler applies to */
|
|
1694
|
+
nodeTypes?: WorkflowNodeType[];
|
|
1695
|
+
};
|
|
1696
|
+
/** Description of this error handler */
|
|
1697
|
+
description?: string;
|
|
1698
|
+
}
|
|
1699
|
+
/**
|
|
1700
|
+
* CheckpointNodeData - Configurable observation point for workflow execution
|
|
1701
|
+
*
|
|
1702
|
+
* The Checkpoint node is a flexible observation/control point that can:
|
|
1703
|
+
* - Log data to console and execution history
|
|
1704
|
+
* - Pause execution in debug mode (breakpoint)
|
|
1705
|
+
* - Gate execution requiring human approval (production use)
|
|
1706
|
+
* - Send webhook notifications to external systems
|
|
1707
|
+
*
|
|
1708
|
+
* Pre-Node Aware: The checkpoint detects what type of node feeds into it
|
|
1709
|
+
* and can subscribe to specific events from that node (e.g., Agent iterations).
|
|
1710
|
+
*
|
|
1711
|
+
* All behaviors are toggleable and can be combined.
|
|
1712
|
+
*/
|
|
1713
|
+
interface CallbackNodeData extends BaseNodeData {
|
|
1714
|
+
/** Custom name for this checkpoint (shown in logs/UI) */
|
|
1715
|
+
checkpointName?: string;
|
|
1716
|
+
/** Description of what this checkpoint monitors */
|
|
1717
|
+
description?: string;
|
|
1718
|
+
/** Log checkpoint data to console/stdout */
|
|
1719
|
+
logToConsole?: boolean;
|
|
1720
|
+
/** Store checkpoint data in execution history for later review */
|
|
1721
|
+
logToHistory?: boolean;
|
|
1722
|
+
/** Pause execution when running in debug mode (breakpoint) */
|
|
1723
|
+
pauseInDebug?: boolean;
|
|
1724
|
+
/** Require human approval before continuing (works in production) */
|
|
1725
|
+
requireApproval?: boolean;
|
|
1726
|
+
/** Send HTTP webhook notification */
|
|
1727
|
+
sendWebhook?: boolean;
|
|
1728
|
+
/** Include the previous node's output in checkpoint data */
|
|
1729
|
+
capturePreviousOutput?: boolean;
|
|
1730
|
+
/** Include timestamp and execution duration */
|
|
1731
|
+
captureTimestamp?: boolean;
|
|
1732
|
+
/** Include full execution context (all variables, workflow state) */
|
|
1733
|
+
captureFullContext?: boolean;
|
|
1734
|
+
/** Custom message template (supports {{ }} expressions) */
|
|
1735
|
+
message?: string;
|
|
1736
|
+
/** Title shown in approval dialog */
|
|
1737
|
+
approvalTitle?: string;
|
|
1738
|
+
/** Instructions for the reviewer */
|
|
1739
|
+
approvalInstructions?: string;
|
|
1740
|
+
/** Timeout in ms to wait for approval (0 = wait indefinitely) */
|
|
1741
|
+
approvalTimeoutMs?: number;
|
|
1742
|
+
/** What to do if approval times out */
|
|
1743
|
+
approvalTimeoutAction?: 'continue' | 'fail' | 'skip';
|
|
1744
|
+
/** Webhook URL to POST checkpoint data */
|
|
1745
|
+
webhookUrl?: string;
|
|
1746
|
+
/** Custom headers to include in webhook request */
|
|
1747
|
+
webhookHeaders?: Record<string, string>;
|
|
1748
|
+
/** Whether to wait for webhook acknowledgment before continuing */
|
|
1749
|
+
webhookWaitForAck?: boolean;
|
|
1750
|
+
/** Timeout in ms to wait for acknowledgment (0 = no timeout) */
|
|
1751
|
+
webhookAckTimeoutMs?: number;
|
|
1752
|
+
/**
|
|
1753
|
+
* Detected type of the node connected to this checkpoint's input.
|
|
1754
|
+
* This is auto-populated and used to show relevant options in the UI.
|
|
1755
|
+
* @readonly - Set automatically, not user-configurable
|
|
1756
|
+
*/
|
|
1757
|
+
_detectedSourceType?: WorkflowNodeType;
|
|
1758
|
+
/** Include full iteration history from agent execution */
|
|
1759
|
+
agentCaptureIterations?: boolean;
|
|
1760
|
+
/** Include conversation/message history */
|
|
1761
|
+
agentCaptureConversation?: boolean;
|
|
1762
|
+
/** Include tool call details and results */
|
|
1763
|
+
agentCaptureToolCalls?: boolean;
|
|
1764
|
+
/** Include agent's thinking/reasoning (if available) */
|
|
1765
|
+
agentCaptureThinking?: boolean;
|
|
1766
|
+
/**
|
|
1767
|
+
* Event types to listen for when connected to an Agent's onCheckpoint handle.
|
|
1768
|
+
* If empty or undefined, listens to all event types.
|
|
1769
|
+
*/
|
|
1770
|
+
listenTo?: AgentCheckpointEventType[];
|
|
1771
|
+
/** Capture current iteration index */
|
|
1772
|
+
loopCaptureIteration?: boolean;
|
|
1773
|
+
/** Capture loop variable value */
|
|
1774
|
+
loopCaptureVariable?: boolean;
|
|
1775
|
+
/** Include the compiled prompt that was sent to the LLM */
|
|
1776
|
+
promptCaptureCompiled?: boolean;
|
|
1777
|
+
/** Include token usage stats */
|
|
1778
|
+
promptCaptureTokens?: boolean;
|
|
1779
|
+
/** @deprecated Use individual behavior toggles instead */
|
|
1780
|
+
mode?: 'passthrough' | 'pause' | 'report';
|
|
1781
|
+
/** @deprecated Use capturePreviousOutput instead */
|
|
1782
|
+
includePreviousOutput?: boolean;
|
|
1783
|
+
/** @deprecated Use captureFullContext instead */
|
|
1784
|
+
includeNextNodeInfo?: boolean;
|
|
1785
|
+
/** @deprecated Use webhookWaitForAck instead */
|
|
1786
|
+
waitForAck?: boolean;
|
|
1787
|
+
/** @deprecated Use webhookAckTimeoutMs instead */
|
|
1788
|
+
ackTimeoutMs?: number;
|
|
1789
|
+
/** @deprecated Use agentCaptureIterations instead */
|
|
1790
|
+
agentIncludeIterationHistory?: boolean;
|
|
1791
|
+
/** @deprecated Use agentCaptureConversation instead */
|
|
1792
|
+
agentIncludeConversationHistory?: boolean;
|
|
1793
|
+
/** @deprecated Use agentCaptureToolCalls instead */
|
|
1794
|
+
agentIncludeToolCalls?: boolean;
|
|
1795
|
+
}
|
|
1796
|
+
/**
|
|
1797
|
+
* UserInputNodeData - Pause workflow and collect user input
|
|
1798
|
+
*
|
|
1799
|
+
* This node pauses execution and waits for user input. It can be used for:
|
|
1800
|
+
* - Interactive chat loops (user message -> LLM -> user message -> ...)
|
|
1801
|
+
* - Human-in-the-loop approval workflows
|
|
1802
|
+
* - Data collection mid-workflow
|
|
1803
|
+
* - Debugging with manual input injection
|
|
1804
|
+
*
|
|
1805
|
+
* The node provides context (previous output, conversation history) to help
|
|
1806
|
+
* the user understand what input is needed.
|
|
1807
|
+
*/
|
|
1808
|
+
interface UserInputNodeData extends BaseNodeData {
|
|
1809
|
+
/** Prompt message shown to the user (supports {{ }} template expressions) */
|
|
1810
|
+
prompt: string;
|
|
1811
|
+
/** Type of input to collect */
|
|
1812
|
+
inputType: 'text' | 'textarea' | 'choice' | 'confirm' | 'number';
|
|
1813
|
+
/** Choices for 'choice' input type */
|
|
1814
|
+
choices?: string[];
|
|
1815
|
+
/** Placeholder text for input field */
|
|
1816
|
+
placeholder?: string;
|
|
1817
|
+
/** Default value for the input */
|
|
1818
|
+
defaultValue?: string;
|
|
1819
|
+
/** Whether input is required to continue */
|
|
1820
|
+
required?: boolean;
|
|
1821
|
+
/** Whether to show the previous node's output to the user */
|
|
1822
|
+
showContext?: boolean;
|
|
1823
|
+
/** Custom template for displaying context (supports {{ previous_output }}, {{ variables }}) */
|
|
1824
|
+
contextTemplate?: string;
|
|
1825
|
+
/** Timeout in ms (0 = wait indefinitely) */
|
|
1826
|
+
timeout?: number;
|
|
1827
|
+
}
|
|
1828
|
+
/**
|
|
1829
|
+
* CommandNodeData - Execute whitelisted shell commands
|
|
1830
|
+
*
|
|
1831
|
+
* This node executes shell commands with proper security controls:
|
|
1832
|
+
* - Commands can be whitelisted by admin
|
|
1833
|
+
* - Arguments are passed safely (not interpolated into command string)
|
|
1834
|
+
* - Output is captured and parsed
|
|
1835
|
+
* - Requires approval for sensitive operations
|
|
1836
|
+
*/
|
|
1837
|
+
interface CommandNodeData extends BaseNodeData {
|
|
1838
|
+
/** Command template (supports {{ }} expressions for arguments) */
|
|
1839
|
+
command: string;
|
|
1840
|
+
/** Command arguments (safer than string interpolation) */
|
|
1841
|
+
args?: string[];
|
|
1842
|
+
/** Working directory (relative to workspace) */
|
|
1843
|
+
cwd?: string;
|
|
1844
|
+
/** Environment variables to set */
|
|
1845
|
+
env?: Record<string, string>;
|
|
1846
|
+
/** Timeout in milliseconds */
|
|
1847
|
+
timeoutMs?: number;
|
|
1848
|
+
/** Output parsing format */
|
|
1849
|
+
outputFormat: 'text' | 'json' | 'lines';
|
|
1850
|
+
/** Whether this command requires user approval before execution */
|
|
1851
|
+
requiresApproval?: boolean;
|
|
1852
|
+
/** Description shown in approval dialog */
|
|
1853
|
+
approvalMessage?: string;
|
|
1854
|
+
}
|
|
1855
|
+
/**
|
|
1856
|
+
* WebSearchNodeData - Search the web via configurable provider
|
|
1857
|
+
*
|
|
1858
|
+
* Uses the connection system to configure which search provider to use.
|
|
1859
|
+
* Supports SearXNG (free, no key), Brave Search, and Tavily.
|
|
1860
|
+
*/
|
|
1861
|
+
interface WebSearchNodeData extends BaseNodeData {
|
|
1862
|
+
/** Search query template (supports {{ }} expressions) */
|
|
1863
|
+
query: string;
|
|
1864
|
+
/** Maximum number of results to return (default: 5) */
|
|
1865
|
+
resultCount?: number;
|
|
1866
|
+
/** Search provider: 'searxng' (free, default), 'brave', or 'tavily' */
|
|
1867
|
+
provider?: 'searxng' | 'brave' | 'tavily';
|
|
1868
|
+
/** API key for Brave/Tavily providers */
|
|
1869
|
+
apiKey?: string;
|
|
1870
|
+
/** SearXNG instance URL (default: https://search.sapti.me) */
|
|
1871
|
+
instanceUrl?: string;
|
|
1872
|
+
}
|
|
1873
|
+
/**
|
|
1874
|
+
* ClaudeCodeNodeData - Claude Code agent with SSH support for remote development
|
|
1875
|
+
*
|
|
1876
|
+
* This node encapsulates a full Claude Code agent that can:
|
|
1877
|
+
* - Connect to local or remote systems via SSH
|
|
1878
|
+
* - Execute multi-turn development tasks
|
|
1879
|
+
* - Use file editing, command execution, and web tools
|
|
1880
|
+
* - Stream progress back to the workflow
|
|
1881
|
+
*/
|
|
1882
|
+
interface ClaudeCodeNodeData extends BaseNodeData {
|
|
1883
|
+
/** Connection type and configuration */
|
|
1884
|
+
connection: {
|
|
1885
|
+
type: 'local' | 'ssh';
|
|
1886
|
+
/** SSH settings (when type === 'ssh') */
|
|
1887
|
+
ssh?: {
|
|
1888
|
+
/** Reference to SSH connection from Connections Panel */
|
|
1889
|
+
connectionId?: string;
|
|
1890
|
+
/** Or inline config (deprecated - use connectionId) */
|
|
1891
|
+
host?: string;
|
|
1892
|
+
port?: number;
|
|
1893
|
+
username?: string;
|
|
1894
|
+
authMethod?: 'key' | 'agent';
|
|
1895
|
+
keyPath?: string;
|
|
1896
|
+
};
|
|
1897
|
+
};
|
|
1898
|
+
/** Task configuration */
|
|
1899
|
+
task: {
|
|
1900
|
+
/** Main task description (supports {{ }} template expressions) */
|
|
1901
|
+
prompt: string;
|
|
1902
|
+
/** Optional system prompt override */
|
|
1903
|
+
systemPrompt?: string;
|
|
1904
|
+
/** Working directory on target (relative or absolute) */
|
|
1905
|
+
workingDirectory?: string;
|
|
1906
|
+
/** Files to include as context (glob patterns) */
|
|
1907
|
+
contextFiles?: string[];
|
|
1908
|
+
};
|
|
1909
|
+
/** Execution constraints */
|
|
1910
|
+
constraints: {
|
|
1911
|
+
/** Maximum agent turns before forcing completion */
|
|
1912
|
+
maxTurns?: number;
|
|
1913
|
+
/** Allowed tool categories */
|
|
1914
|
+
allowedTools?: ('read' | 'write' | 'execute' | 'web')[];
|
|
1915
|
+
/** Blocked file patterns (security) */
|
|
1916
|
+
blockedPaths?: string[];
|
|
1917
|
+
/** Require approval for write operations */
|
|
1918
|
+
requireApprovalForWrites?: boolean;
|
|
1919
|
+
/** Timeout for entire execution (ms) */
|
|
1920
|
+
timeoutMs?: number;
|
|
1921
|
+
};
|
|
1922
|
+
/** Output configuration */
|
|
1923
|
+
output: {
|
|
1924
|
+
/** What to return as node output */
|
|
1925
|
+
format: 'final-response' | 'full-conversation' | 'files-changed' | 'structured';
|
|
1926
|
+
/** For structured output - JSON schema to enforce */
|
|
1927
|
+
schema?: JsonSchema;
|
|
1928
|
+
/** Include execution metadata (tokens, duration, etc.) */
|
|
1929
|
+
includeMetadata?: boolean;
|
|
1930
|
+
};
|
|
1931
|
+
}
|
|
1932
|
+
/**
|
|
1933
|
+
* WorkflowNodeData - Invoke another .pdflow as a sub-workflow
|
|
1934
|
+
*
|
|
1935
|
+
* This enables workflow composition:
|
|
1936
|
+
* - Call reusable workflow modules
|
|
1937
|
+
* - Pass parameters and receive outputs
|
|
1938
|
+
* - Support for recursive workflows (with depth limit)
|
|
1939
|
+
*/
|
|
1940
|
+
interface WorkflowNodeData extends BaseNodeData {
|
|
1941
|
+
/** Source workflow path or package reference */
|
|
1942
|
+
source: string;
|
|
1943
|
+
/** Parameter mapping (input to sub-workflow) */
|
|
1944
|
+
parameters: Record<string, string>;
|
|
1945
|
+
/** Output mapping (sub-workflow output to this node's output) */
|
|
1946
|
+
outputMapping?: Record<string, string>;
|
|
1947
|
+
/** Execution options */
|
|
1948
|
+
timeout?: number;
|
|
1949
|
+
/** Whether to pass parent workflow variables */
|
|
1950
|
+
inheritVariables?: boolean;
|
|
1951
|
+
/** Maximum recursion depth (to prevent infinite loops) */
|
|
1952
|
+
maxDepth?: number;
|
|
1953
|
+
}
|
|
1954
|
+
/**
|
|
1955
|
+
* McpToolNodeData - Execute tools from external MCP servers
|
|
1956
|
+
*
|
|
1957
|
+
* This node connects to external MCP servers and executes their tools.
|
|
1958
|
+
* Unlike the generic Tool node, this is specifically for MCP protocol
|
|
1959
|
+
* and supports MCP-specific features like resources and prompts.
|
|
1960
|
+
*/
|
|
1961
|
+
interface McpToolNodeData extends BaseNodeData {
|
|
1962
|
+
/** Reference to MCP server connection from Connections Panel */
|
|
1963
|
+
connectionId?: string;
|
|
1964
|
+
/** Or inline MCP server config (deprecated - use connectionId) */
|
|
1965
|
+
serverConfig?: {
|
|
1966
|
+
serverUrl?: string;
|
|
1967
|
+
serverName?: string;
|
|
1968
|
+
transport?: 'stdio' | 'http' | 'websocket';
|
|
1969
|
+
};
|
|
1970
|
+
/** Tool name to execute */
|
|
1971
|
+
toolName: string;
|
|
1972
|
+
/** Parameter mapping (supports {{ }} expressions) */
|
|
1973
|
+
parameters: Record<string, string>;
|
|
1974
|
+
/** Timeout for tool execution (ms) */
|
|
1975
|
+
timeoutMs?: number;
|
|
1976
|
+
/** Whether to include tool result in conversation context */
|
|
1977
|
+
includeInContext?: boolean;
|
|
1978
|
+
}
|
|
1979
|
+
/**
|
|
1980
|
+
* CodeNodeData - Execute code snippets in various languages
|
|
1981
|
+
*
|
|
1982
|
+
* Supports:
|
|
1983
|
+
* - TypeScript/JavaScript: Runs in isolated VM context or via temp file
|
|
1984
|
+
* - Python: Executes via python -c or temp file
|
|
1985
|
+
* - C#: Executes via dotnet-script or compiled temp file
|
|
1986
|
+
*
|
|
1987
|
+
* The previous_output is available as a variable (default name: 'input')
|
|
1988
|
+
*/
|
|
1989
|
+
interface CodeNodeData extends BaseNodeData {
|
|
1990
|
+
/** Programming language */
|
|
1991
|
+
language: 'typescript' | 'javascript' | 'python' | 'csharp';
|
|
1992
|
+
/** The code to execute */
|
|
1993
|
+
code: string;
|
|
1994
|
+
/** Variable name for the input (previous_output), default: 'input' */
|
|
1995
|
+
inputVariable?: string;
|
|
1996
|
+
/** For TS/JS: run in isolated VM or main context */
|
|
1997
|
+
executionContext?: 'isolated' | 'main';
|
|
1998
|
+
/** Timeout in milliseconds (default: 30000) */
|
|
1999
|
+
timeoutMs?: number;
|
|
2000
|
+
/** Description of what this code does */
|
|
2001
|
+
description?: string;
|
|
2002
|
+
}
|
|
2003
|
+
/**
|
|
2004
|
+
* MemoryNodeData - Configurable memory storage node
|
|
2005
|
+
*
|
|
2006
|
+
* Supports multiple memory patterns:
|
|
2007
|
+
* - 'kv': Key-value store for passing state between nodes
|
|
2008
|
+
* - 'conversation': Message history with sliding window for chat context
|
|
2009
|
+
* - 'cache': Time-based caching for expensive operations
|
|
2010
|
+
*
|
|
2011
|
+
* Memory is scoped to workflow execution by default, but can be
|
|
2012
|
+
* persisted across executions via the 'persistent' flag.
|
|
2013
|
+
*
|
|
2014
|
+
* Handles:
|
|
2015
|
+
* - input (left) - Data to store or key to retrieve
|
|
2016
|
+
* - output (right) - Retrieved value or confirmation
|
|
2017
|
+
*/
|
|
2018
|
+
/** Memory operation type */
|
|
2019
|
+
type MemoryOperation = 'get' | 'set' | 'delete' | 'clear' | 'list' | 'append';
|
|
2020
|
+
/** Operations available per memory mode */
|
|
2021
|
+
declare const MEMORY_OPERATIONS_BY_MODE: Record<string, MemoryOperation[]>;
|
|
2022
|
+
interface MemoryNodeData extends BaseNodeData {
|
|
2023
|
+
/** Memory operation mode */
|
|
2024
|
+
mode: 'kv' | 'conversation' | 'cache';
|
|
2025
|
+
/**
|
|
2026
|
+
* Operations this node can perform (multi-select).
|
|
2027
|
+
* When multiple operations are enabled, the input data's `operation` field
|
|
2028
|
+
* determines which to execute, or defaults to the first enabled operation.
|
|
2029
|
+
*/
|
|
2030
|
+
operations: MemoryOperation[];
|
|
2031
|
+
/**
|
|
2032
|
+
* Key for the value (supports {{ }} template expressions).
|
|
2033
|
+
* Used in kv and cache modes.
|
|
2034
|
+
*/
|
|
2035
|
+
key?: string;
|
|
2036
|
+
/**
|
|
2037
|
+
* Value to store (supports {{ }} template expressions).
|
|
2038
|
+
* Used with 'set' operation. If not provided, uses input data.
|
|
2039
|
+
*/
|
|
2040
|
+
value?: string;
|
|
2041
|
+
/**
|
|
2042
|
+
* Default value to return if key doesn't exist.
|
|
2043
|
+
* Used with 'get' operation.
|
|
2044
|
+
*/
|
|
2045
|
+
defaultValue?: string;
|
|
2046
|
+
/**
|
|
2047
|
+
* Conversation/thread identifier (supports {{ }} expressions).
|
|
2048
|
+
* Allows multiple separate conversation histories.
|
|
2049
|
+
*/
|
|
2050
|
+
conversationId?: string;
|
|
2051
|
+
/**
|
|
2052
|
+
* Role for the message being appended ('user', 'assistant', 'system').
|
|
2053
|
+
* Used with 'append' operation in conversation mode.
|
|
2054
|
+
*/
|
|
2055
|
+
messageRole?: 'user' | 'assistant' | 'system';
|
|
2056
|
+
/**
|
|
2057
|
+
* Maximum messages to retain in sliding window.
|
|
2058
|
+
* Older messages are removed when limit is exceeded.
|
|
2059
|
+
* Set to 0 for unlimited.
|
|
2060
|
+
*/
|
|
2061
|
+
maxMessages?: number;
|
|
2062
|
+
/**
|
|
2063
|
+
* Include system messages in the sliding window count.
|
|
2064
|
+
* If false, system messages are always retained.
|
|
2065
|
+
*/
|
|
2066
|
+
includeSystemInWindow?: boolean;
|
|
2067
|
+
/**
|
|
2068
|
+
* Time-to-live in seconds for cached values.
|
|
2069
|
+
* After TTL expires, 'get' returns defaultValue or undefined.
|
|
2070
|
+
* Set to 0 for no expiration.
|
|
2071
|
+
*/
|
|
2072
|
+
ttlSeconds?: number;
|
|
2073
|
+
/**
|
|
2074
|
+
* Refresh TTL on read (sliding expiration).
|
|
2075
|
+
* If true, reading a value resets its TTL.
|
|
2076
|
+
*/
|
|
2077
|
+
refreshOnRead?: boolean;
|
|
2078
|
+
/**
|
|
2079
|
+
* Memory scope:
|
|
2080
|
+
* - 'execution': Cleared when workflow execution completes (default)
|
|
2081
|
+
* - 'workflow': Persists across executions of this workflow
|
|
2082
|
+
* - 'global': Shared across all workflows (use with caution)
|
|
2083
|
+
*/
|
|
2084
|
+
scope?: 'execution' | 'workflow' | 'global';
|
|
2085
|
+
/**
|
|
2086
|
+
* Namespace to isolate this memory from others.
|
|
2087
|
+
* Useful for avoiding key collisions in global scope.
|
|
2088
|
+
*/
|
|
2089
|
+
namespace?: string;
|
|
2090
|
+
/**
|
|
2091
|
+
* What to output after the operation:
|
|
2092
|
+
* - 'value': The retrieved/stored value
|
|
2093
|
+
* - 'success': Boolean indicating success
|
|
2094
|
+
* - 'metadata': Object with value, timestamp, ttl info
|
|
2095
|
+
* - 'passthrough': Pass input through unchanged
|
|
2096
|
+
*/
|
|
2097
|
+
outputMode?: 'value' | 'success' | 'metadata' | 'passthrough';
|
|
2098
|
+
}
|
|
2099
|
+
interface DatabaseQueryNodeData extends BaseNodeData {
|
|
2100
|
+
/** Reference to a saved database connection */
|
|
2101
|
+
connectionId: string;
|
|
2102
|
+
/** Query type determines how the query is executed */
|
|
2103
|
+
queryType: 'select' | 'insert' | 'update' | 'delete' | 'raw' | 'aggregate';
|
|
2104
|
+
/** SQL query, MongoDB JSON query document, or Redis command */
|
|
2105
|
+
query: string;
|
|
2106
|
+
/** JSON-encoded parameter array for parameterized queries (SQL only) */
|
|
2107
|
+
parameters?: string;
|
|
2108
|
+
/** MongoDB collection name (only for MongoDB connections) */
|
|
2109
|
+
collection?: string;
|
|
2110
|
+
/** Maximum rows to return (default 1000) */
|
|
2111
|
+
maxRows?: number;
|
|
2112
|
+
/** Query timeout in milliseconds (default 30000) */
|
|
2113
|
+
timeoutMs?: number;
|
|
2114
|
+
}
|
|
2115
|
+
/**
|
|
2116
|
+
* CustomCommandConfig - User-defined allowed commands
|
|
2117
|
+
*
|
|
2118
|
+
* Stored in the Connections panel, these allow users to whitelist
|
|
2119
|
+
* additional shell commands for use in Tool nodes.
|
|
2120
|
+
*/
|
|
2121
|
+
interface CustomCommandConfig {
|
|
2122
|
+
/** Unique identifier */
|
|
2123
|
+
id: string;
|
|
2124
|
+
/** The executable name (e.g., 'cargo', 'terraform', 'kubectl') */
|
|
2125
|
+
executable: string;
|
|
2126
|
+
/** Allowed actions/subcommands (if empty, any args allowed with validation) */
|
|
2127
|
+
allowedActions?: string[];
|
|
2128
|
+
/** Human-readable description */
|
|
2129
|
+
description?: string;
|
|
2130
|
+
/** Whether to require approval before execution */
|
|
2131
|
+
requiresApproval: boolean;
|
|
2132
|
+
/** When this command was added */
|
|
2133
|
+
addedAt: number;
|
|
2134
|
+
}
|
|
2135
|
+
/**
|
|
2136
|
+
* Built-in allowed executables for command tool type
|
|
2137
|
+
*/
|
|
2138
|
+
declare const BUILTIN_COMMAND_EXECUTABLES: readonly [{
|
|
2139
|
+
readonly executable: "npm";
|
|
2140
|
+
readonly description: "Node.js package manager";
|
|
2141
|
+
readonly actions: readonly ["run", "install", "test", "build", "start"];
|
|
2142
|
+
}, {
|
|
2143
|
+
readonly executable: "npx";
|
|
2144
|
+
readonly description: "Execute npm packages";
|
|
2145
|
+
readonly actions: readonly [];
|
|
2146
|
+
}, {
|
|
2147
|
+
readonly executable: "node";
|
|
2148
|
+
readonly description: "Node.js runtime";
|
|
2149
|
+
readonly actions: readonly [];
|
|
2150
|
+
}, {
|
|
2151
|
+
readonly executable: "yarn";
|
|
2152
|
+
readonly description: "Yarn package manager";
|
|
2153
|
+
readonly actions: readonly ["run", "install", "test", "build", "start"];
|
|
2154
|
+
}, {
|
|
2155
|
+
readonly executable: "pnpm";
|
|
2156
|
+
readonly description: "PNPM package manager";
|
|
2157
|
+
readonly actions: readonly ["run", "install", "test", "build", "start"];
|
|
2158
|
+
}, {
|
|
2159
|
+
readonly executable: "git";
|
|
2160
|
+
readonly description: "Version control";
|
|
2161
|
+
readonly actions: readonly ["status", "add", "commit", "push", "pull", "log", "diff", "branch"];
|
|
2162
|
+
}, {
|
|
2163
|
+
readonly executable: "python";
|
|
2164
|
+
readonly description: "Python interpreter";
|
|
2165
|
+
readonly actions: readonly [];
|
|
2166
|
+
}, {
|
|
2167
|
+
readonly executable: "python3";
|
|
2168
|
+
readonly description: "Python 3 interpreter";
|
|
2169
|
+
readonly actions: readonly [];
|
|
2170
|
+
}, {
|
|
2171
|
+
readonly executable: "pip";
|
|
2172
|
+
readonly description: "Python package manager";
|
|
2173
|
+
readonly actions: readonly ["install", "list", "show"];
|
|
2174
|
+
}, {
|
|
2175
|
+
readonly executable: "prompd";
|
|
2176
|
+
readonly description: "Prompd CLI";
|
|
2177
|
+
readonly actions: readonly ["compile", "run", "validate", "package"];
|
|
2178
|
+
}, {
|
|
2179
|
+
readonly executable: "dotnet";
|
|
2180
|
+
readonly description: ".NET CLI";
|
|
2181
|
+
readonly actions: readonly ["build", "run", "test", "publish"];
|
|
2182
|
+
}, {
|
|
2183
|
+
readonly executable: "tsc";
|
|
2184
|
+
readonly description: "TypeScript compiler";
|
|
2185
|
+
readonly actions: readonly [];
|
|
2186
|
+
}, {
|
|
2187
|
+
readonly executable: "eslint";
|
|
2188
|
+
readonly description: "JavaScript linter";
|
|
2189
|
+
readonly actions: readonly [];
|
|
2190
|
+
}, {
|
|
2191
|
+
readonly executable: "prettier";
|
|
2192
|
+
readonly description: "Code formatter";
|
|
2193
|
+
readonly actions: readonly [];
|
|
2194
|
+
}, {
|
|
2195
|
+
readonly executable: "echo";
|
|
2196
|
+
readonly description: "Print text";
|
|
2197
|
+
readonly actions: readonly [];
|
|
2198
|
+
}];
|
|
2199
|
+
/**
|
|
2200
|
+
* AgentIterationRecord - Record of a single agent iteration for debugging
|
|
2201
|
+
*/
|
|
2202
|
+
interface AgentIterationRecord {
|
|
2203
|
+
iteration: number;
|
|
2204
|
+
timestamp: number;
|
|
2205
|
+
llmInput: {
|
|
2206
|
+
systemPrompt: string;
|
|
2207
|
+
conversationHistory: Array<{
|
|
2208
|
+
role: string;
|
|
2209
|
+
content: string;
|
|
2210
|
+
}>;
|
|
2211
|
+
};
|
|
2212
|
+
llmOutput: {
|
|
2213
|
+
response: string;
|
|
2214
|
+
hasToolCall: boolean;
|
|
2215
|
+
toolName?: string;
|
|
2216
|
+
toolParams?: Record<string, unknown>;
|
|
2217
|
+
};
|
|
2218
|
+
toolExecution?: {
|
|
2219
|
+
toolName: string;
|
|
2220
|
+
parameters: Record<string, unknown>;
|
|
2221
|
+
result: unknown;
|
|
2222
|
+
error?: string;
|
|
2223
|
+
durationMs: number;
|
|
2224
|
+
};
|
|
2225
|
+
durationMs: number;
|
|
2226
|
+
}
|
|
2227
|
+
/**
|
|
2228
|
+
* AgentCheckpointEvent - Events emitted by Agent nodes during execution
|
|
2229
|
+
*
|
|
2230
|
+
* Agent nodes emit these events through their onCheckpoint handle, allowing
|
|
2231
|
+
* connected Callback nodes to observe and react to agent execution.
|
|
2232
|
+
*
|
|
2233
|
+
* Event types:
|
|
2234
|
+
* - toolCall: Agent is requesting a tool execution
|
|
2235
|
+
* - iteration: Agent completed an iteration of the ReAct loop
|
|
2236
|
+
* - thinking: Agent emitted reasoning/chain-of-thought
|
|
2237
|
+
* - error: An error occurred during agent execution
|
|
2238
|
+
* - complete: Agent finished execution
|
|
2239
|
+
*/
|
|
2240
|
+
type AgentCheckpointEventType = 'toolCall' | 'iteration' | 'thinking' | 'error' | 'complete';
|
|
2241
|
+
interface AgentCheckpointEvent {
|
|
2242
|
+
/** Type of event */
|
|
2243
|
+
type: AgentCheckpointEventType;
|
|
2244
|
+
/** When the event occurred */
|
|
2245
|
+
timestamp: number;
|
|
2246
|
+
/** Current iteration number (1-indexed) */
|
|
2247
|
+
iteration: number;
|
|
2248
|
+
/** Node ID of the agent that emitted this event */
|
|
2249
|
+
agentNodeId: string;
|
|
2250
|
+
/** Event-specific data */
|
|
2251
|
+
data: ToolCallEventData | IterationEventData | ThinkingEventData | ErrorEventData | CompleteEventData;
|
|
2252
|
+
}
|
|
2253
|
+
/** Data for 'toolCall' events - agent is requesting tool execution */
|
|
2254
|
+
interface ToolCallEventData {
|
|
2255
|
+
toolName: string;
|
|
2256
|
+
parameters: Record<string, unknown>;
|
|
2257
|
+
/** Tool schema for validation (if available) */
|
|
2258
|
+
schema?: {
|
|
2259
|
+
type: 'object';
|
|
2260
|
+
properties?: Record<string, {
|
|
2261
|
+
type: string;
|
|
2262
|
+
description?: string;
|
|
2263
|
+
}>;
|
|
2264
|
+
required?: string[];
|
|
2265
|
+
};
|
|
2266
|
+
}
|
|
2267
|
+
/** Data for 'iteration' events - agent completed a ReAct loop iteration */
|
|
2268
|
+
interface IterationEventData {
|
|
2269
|
+
iterationNumber: number;
|
|
2270
|
+
llmInput: {
|
|
2271
|
+
systemPrompt: string;
|
|
2272
|
+
messages: Array<{
|
|
2273
|
+
role: string;
|
|
2274
|
+
content: string;
|
|
2275
|
+
}>;
|
|
2276
|
+
};
|
|
2277
|
+
llmOutput: {
|
|
2278
|
+
response: string;
|
|
2279
|
+
hasToolCall: boolean;
|
|
2280
|
+
toolName?: string;
|
|
2281
|
+
toolParams?: Record<string, unknown>;
|
|
2282
|
+
};
|
|
2283
|
+
durationMs: number;
|
|
2284
|
+
}
|
|
2285
|
+
/** Data for 'thinking' events - agent's reasoning/chain-of-thought */
|
|
2286
|
+
interface ThinkingEventData {
|
|
2287
|
+
thought: string;
|
|
2288
|
+
}
|
|
2289
|
+
/** Data for 'error' events - an error occurred */
|
|
2290
|
+
interface ErrorEventData {
|
|
2291
|
+
message: string;
|
|
2292
|
+
code?: string;
|
|
2293
|
+
stack?: string;
|
|
2294
|
+
recoverable: boolean;
|
|
2295
|
+
}
|
|
2296
|
+
/** Data for 'complete' events - agent finished execution */
|
|
2297
|
+
interface CompleteEventData {
|
|
2298
|
+
finalResponse: string;
|
|
2299
|
+
totalIterations: number;
|
|
2300
|
+
totalDurationMs: number;
|
|
2301
|
+
stopReason: 'max-iterations' | 'stop-phrase' | 'no-tool-call' | 'error' | 'completed';
|
|
2302
|
+
}
|
|
2303
|
+
/**
|
|
2304
|
+
* AgentNodeData - Autonomous AI agent with tool-use loop
|
|
2305
|
+
*
|
|
2306
|
+
* Implements a ReAct-style (Reasoning + Acting) agent that:
|
|
2307
|
+
* 1. Sends a prompt to an LLM with tool definitions
|
|
2308
|
+
* 2. Parses the response for tool calls
|
|
2309
|
+
* 3. Executes requested tools
|
|
2310
|
+
* 4. Feeds results back to the LLM
|
|
2311
|
+
* 5. Repeats until LLM provides final answer or max iterations reached
|
|
2312
|
+
*
|
|
2313
|
+
* This encapsulates the common "agentic loop" pattern into a single node.
|
|
2314
|
+
*
|
|
2315
|
+
* Debug Mode:
|
|
2316
|
+
* When debugConfig.debugMode is enabled, the agent emits detailed traces at
|
|
2317
|
+
* internal checkpoints and can optionally pause at each checkpoint (like breakpoints).
|
|
2318
|
+
* Iteration history is stored in the node output for downstream analysis.
|
|
2319
|
+
*/
|
|
2320
|
+
interface AgentNodeData extends BaseNodeData {
|
|
2321
|
+
/** System prompt that defines the agent's behavior and available tools */
|
|
2322
|
+
systemPrompt: string;
|
|
2323
|
+
/** Initial user message / task description (supports {{ }} template expressions) */
|
|
2324
|
+
userPrompt: string;
|
|
2325
|
+
/** Reference to a Provider node by ID (preferred - enables centralized config) */
|
|
2326
|
+
providerNodeId?: string;
|
|
2327
|
+
/** Inline LLM provider (fallback if no providerNodeId) */
|
|
2328
|
+
provider?: string;
|
|
2329
|
+
/** Inline model (fallback if no providerNodeId) */
|
|
2330
|
+
model?: string;
|
|
2331
|
+
/** Tool definitions available to the agent (legacy - prefer toolRouterNodeId) */
|
|
2332
|
+
tools: AgentTool[];
|
|
2333
|
+
/** Reference to a ToolCallRouter node by ID (preferred over inline tools) */
|
|
2334
|
+
toolRouterNodeId?: string;
|
|
2335
|
+
/** Maximum number of tool-use iterations before stopping */
|
|
2336
|
+
maxIterations: number;
|
|
2337
|
+
/** Format for tool calls in LLM responses */
|
|
2338
|
+
toolCallFormat: 'auto' | 'openai' | 'anthropic' | 'xml' | 'json';
|
|
2339
|
+
/** What to output when agent completes */
|
|
2340
|
+
outputMode: 'final-response' | 'full-conversation' | 'last-tool-result';
|
|
2341
|
+
/** Whether to include conversation history in context */
|
|
2342
|
+
includeHistory?: boolean;
|
|
2343
|
+
/** Stop phrases that indicate the agent is done (in addition to no tool call) */
|
|
2344
|
+
stopPhrases?: string[];
|
|
2345
|
+
/** Temperature for LLM calls */
|
|
2346
|
+
temperature?: number;
|
|
2347
|
+
/** Timeout per LLM call in ms */
|
|
2348
|
+
llmTimeout?: number;
|
|
2349
|
+
}
|
|
2350
|
+
/**
|
|
2351
|
+
* GuardrailNodeData - Input validation node with success/rejected branching
|
|
2352
|
+
*
|
|
2353
|
+
* Validates input against a system prompt and routes to success or rejected paths.
|
|
2354
|
+
* Uses an LLM to evaluate the input and determine if it passes validation.
|
|
2355
|
+
*
|
|
2356
|
+
* Handles:
|
|
2357
|
+
* - input (left, top) - Data to validate
|
|
2358
|
+
* - rejected (left, bottom) - Source handle for routing rejected input back
|
|
2359
|
+
*
|
|
2360
|
+
* Outputs:
|
|
2361
|
+
* - output (right) - Validated input passes through on success
|
|
2362
|
+
*
|
|
2363
|
+
* The guardrail evaluates the input using the configured provider and system prompt,
|
|
2364
|
+
* then uses the passExpression to determine if the result indicates pass or fail.
|
|
2365
|
+
*/
|
|
2366
|
+
interface GuardrailNodeData extends BaseNodeData {
|
|
2367
|
+
/** System prompt that defines the validation criteria */
|
|
2368
|
+
systemPrompt: string;
|
|
2369
|
+
/** Reference to a Provider node by ID for LLM evaluation */
|
|
2370
|
+
providerNodeId?: string;
|
|
2371
|
+
/** Inline provider (fallback if no providerNodeId) */
|
|
2372
|
+
provider?: string;
|
|
2373
|
+
/** Inline model (fallback if no providerNodeId) */
|
|
2374
|
+
model?: string;
|
|
2375
|
+
/**
|
|
2376
|
+
* Expression to evaluate pass/fail from the LLM response.
|
|
2377
|
+
* Supports {{ }} template syntax with access to the parsed response.
|
|
2378
|
+
*
|
|
2379
|
+
* Examples:
|
|
2380
|
+
* - "{{ score >= 0.8 }}" - Pass if score is 0.8 or higher
|
|
2381
|
+
* - "{{ !rejected }}" - Pass if rejected is falsy
|
|
2382
|
+
* - "{{ score >= 0.8 && !rejected }}" - Combined conditions
|
|
2383
|
+
*
|
|
2384
|
+
* The expression is evaluated against the parsed JSON response from the LLM.
|
|
2385
|
+
* If the LLM returns a non-JSON response, it's wrapped as { response: "..." }
|
|
2386
|
+
*/
|
|
2387
|
+
passExpression?: string;
|
|
2388
|
+
/**
|
|
2389
|
+
* Numeric threshold for pass/fail (alternative to passExpression).
|
|
2390
|
+
* If the LLM response contains a 'score' field, this threshold is used.
|
|
2391
|
+
* Input passes if score >= scoreThreshold.
|
|
2392
|
+
*/
|
|
2393
|
+
scoreThreshold?: number;
|
|
2394
|
+
/** Temperature for LLM evaluation (default: 0 for deterministic) */
|
|
2395
|
+
temperature?: number;
|
|
2396
|
+
/** Timeout for LLM call in ms */
|
|
2397
|
+
timeout?: number;
|
|
2398
|
+
/** Description of what this guardrail validates */
|
|
2399
|
+
description?: string;
|
|
2400
|
+
}
|
|
2401
|
+
/**
|
|
2402
|
+
* ChatAgentNodeData - Composite container for conversational AI agent pattern
|
|
2403
|
+
*
|
|
2404
|
+
* Bundles the common pattern of: User Input → Guardrail → AI Agent ↔ Tool Router
|
|
2405
|
+
* into a single, configurable node with checkpoints at each stage.
|
|
2406
|
+
*
|
|
2407
|
+
* When collapsed: Shows as a single node with key metrics
|
|
2408
|
+
* When expanded: Shows all internal nodes for detailed editing
|
|
2409
|
+
*
|
|
2410
|
+
* Internal nodes (auto-created):
|
|
2411
|
+
* - UserInput: Collects user message
|
|
2412
|
+
* - Guardrail: Validates input before processing
|
|
2413
|
+
* - Agent: AI agent with ReAct loop
|
|
2414
|
+
* - ToolRouter: Container for available tools
|
|
2415
|
+
*
|
|
2416
|
+
* Handles:
|
|
2417
|
+
* - input (left) - Workflow data / conversation context
|
|
2418
|
+
* - output (right) - Final agent response
|
|
2419
|
+
* - rejected (left, bottom) - Guardrail rejection path
|
|
2420
|
+
*/
|
|
2421
|
+
interface ChatAgentNodeData extends BaseNodeData {
|
|
2422
|
+
/** Whether the container is collapsed (shows as single node) */
|
|
2423
|
+
collapsed?: boolean;
|
|
2424
|
+
/** Saved dimensions when expanded */
|
|
2425
|
+
_savedWidth?: number;
|
|
2426
|
+
_savedHeight?: number;
|
|
2427
|
+
/**
|
|
2428
|
+
* Agent prompt source type:
|
|
2429
|
+
* - 'raw': Inline text prompt (agentSystemPrompt field)
|
|
2430
|
+
* - 'file': Reference to .prmd file or package (agentPromptSource field)
|
|
2431
|
+
*/
|
|
2432
|
+
agentPromptSourceType?: 'raw' | 'file';
|
|
2433
|
+
/** System prompt for the AI agent (used when agentPromptSourceType is 'raw' or not set) */
|
|
2434
|
+
agentSystemPrompt: string;
|
|
2435
|
+
/** Source file for agent prompt (used when agentPromptSourceType is 'file') - local .prmd path or package reference */
|
|
2436
|
+
agentPromptSource?: string;
|
|
2437
|
+
/** Initial user prompt template (supports {{ }} expressions) */
|
|
2438
|
+
agentUserPrompt?: string;
|
|
2439
|
+
/** Reference to Provider node for LLM */
|
|
2440
|
+
providerNodeId?: string;
|
|
2441
|
+
/** Inline provider (fallback) */
|
|
2442
|
+
provider?: string;
|
|
2443
|
+
/** Inline model (fallback) */
|
|
2444
|
+
model?: string;
|
|
2445
|
+
/** Maximum ReAct loop iterations */
|
|
2446
|
+
maxIterations?: number;
|
|
2447
|
+
/** Tool call format detection */
|
|
2448
|
+
toolCallFormat?: 'auto' | 'openai' | 'anthropic' | 'xml' | 'json';
|
|
2449
|
+
/** What to output when complete */
|
|
2450
|
+
outputMode?: 'final-response' | 'full-conversation' | 'last-tool-result';
|
|
2451
|
+
/** Temperature for LLM calls */
|
|
2452
|
+
temperature?: number;
|
|
2453
|
+
/**
|
|
2454
|
+
* Loop mode for the chat agent:
|
|
2455
|
+
* - 'single-turn': Execute once and return (no looping)
|
|
2456
|
+
* - 'multi-turn': Continue until stop condition or max iterations
|
|
2457
|
+
* - 'until-complete': Loop until agent signals completion
|
|
2458
|
+
* - 'user-driven': Loop back for user input after each response
|
|
2459
|
+
*/
|
|
2460
|
+
loopMode?: 'single-turn' | 'multi-turn' | 'until-complete' | 'user-driven';
|
|
2461
|
+
/**
|
|
2462
|
+
* Condition expression to continue looping (for multi-turn mode).
|
|
2463
|
+
* Evaluated after each iteration. Loop continues while this is true.
|
|
2464
|
+
* Uses {{ }} template syntax with access to iteration context.
|
|
2465
|
+
*
|
|
2466
|
+
* Examples:
|
|
2467
|
+
* - "{{ iteration < 5 }}" - Continue for 5 iterations
|
|
2468
|
+
* - "{{ !response.includes('DONE') }}" - Until response contains DONE
|
|
2469
|
+
* - "{{ tools_used > 0 }}" - Continue if tools were used
|
|
2470
|
+
*/
|
|
2471
|
+
loopCondition?: string;
|
|
2472
|
+
/**
|
|
2473
|
+
* Stop phrases that signal the agent is done.
|
|
2474
|
+
* If the response contains any of these, the loop terminates.
|
|
2475
|
+
*/
|
|
2476
|
+
stopPhrases?: string[];
|
|
2477
|
+
/**
|
|
2478
|
+
* Whether to prompt for user input after each agent response (for user-driven mode).
|
|
2479
|
+
* When true, the loop pauses for user input before continuing.
|
|
2480
|
+
*/
|
|
2481
|
+
loopOnUserInput?: boolean;
|
|
2482
|
+
/**
|
|
2483
|
+
* Minimum number of iterations before stop condition is checked.
|
|
2484
|
+
* Ensures the agent runs at least this many times.
|
|
2485
|
+
*/
|
|
2486
|
+
minIterations?: number;
|
|
2487
|
+
/**
|
|
2488
|
+
* Delay between iterations in milliseconds.
|
|
2489
|
+
* Useful for rate limiting or allowing processing time.
|
|
2490
|
+
*/
|
|
2491
|
+
iterationDelayMs?: number;
|
|
2492
|
+
/** Whether guardrail is enabled */
|
|
2493
|
+
guardrailEnabled?: boolean;
|
|
2494
|
+
/** Guardrail system prompt */
|
|
2495
|
+
guardrailSystemPrompt?: string;
|
|
2496
|
+
/** Reference to Provider node for guardrail LLM (can be different from agent's provider) */
|
|
2497
|
+
guardrailProviderNodeId?: string;
|
|
2498
|
+
/** Inline provider for guardrail (fallback if no guardrailProviderNodeId) */
|
|
2499
|
+
guardrailProvider?: string;
|
|
2500
|
+
/** Inline model for guardrail (fallback if no guardrailProviderNodeId) */
|
|
2501
|
+
guardrailModel?: string;
|
|
2502
|
+
/** Temperature for guardrail LLM evaluation (default: 0 for deterministic) */
|
|
2503
|
+
guardrailTemperature?: number;
|
|
2504
|
+
/** Pass/fail expression */
|
|
2505
|
+
guardrailPassExpression?: string;
|
|
2506
|
+
/** Score threshold alternative */
|
|
2507
|
+
guardrailScoreThreshold?: number;
|
|
2508
|
+
/** Output mode when guardrail passes */
|
|
2509
|
+
guardrailOutputMode?: 'passthrough' | 'original' | 'reject-message';
|
|
2510
|
+
/** Expected response format from guardrail LLM */
|
|
2511
|
+
guardrailExpectedFormat?: 'json' | 'text';
|
|
2512
|
+
/** JSON field to check for rejection status */
|
|
2513
|
+
guardrailRejectionField?: string;
|
|
2514
|
+
/** Pass when field is true or false */
|
|
2515
|
+
guardrailPassWhen?: 'true' | 'false';
|
|
2516
|
+
/** Action to take when guardrail fails */
|
|
2517
|
+
guardrailFailAction?: 'error' | 'stop' | 'continue';
|
|
2518
|
+
/** Custom message when rejected */
|
|
2519
|
+
guardrailCustomRejectMessage?: string;
|
|
2520
|
+
/** Custom rejection expression (advanced) - overrides simple field check */
|
|
2521
|
+
guardrailRejectionExpression?: string;
|
|
2522
|
+
/** Whether to prompt for user input at start of each iteration */
|
|
2523
|
+
userInputEnabled?: boolean;
|
|
2524
|
+
/** Prompt message shown to user */
|
|
2525
|
+
userInputPrompt?: string;
|
|
2526
|
+
/** Input type */
|
|
2527
|
+
userInputType?: 'text' | 'textarea' | 'choice' | 'confirm';
|
|
2528
|
+
/** Placeholder text */
|
|
2529
|
+
userInputPlaceholder?: string;
|
|
2530
|
+
/** Whether to show previous context to user */
|
|
2531
|
+
userInputShowContext?: boolean;
|
|
2532
|
+
/** Inline tool definitions (for simple cases) */
|
|
2533
|
+
tools?: AgentTool[];
|
|
2534
|
+
/** Reference to external ToolRouter node (for complex tool setups) */
|
|
2535
|
+
toolRouterNodeId?: string;
|
|
2536
|
+
/** Checkpoint settings for different stages */
|
|
2537
|
+
checkpoints?: {
|
|
2538
|
+
/** On user input received */
|
|
2539
|
+
onUserInput?: ChatAgentCheckpointConfig;
|
|
2540
|
+
/** Before guardrail validation */
|
|
2541
|
+
beforeGuardrail?: ChatAgentCheckpointConfig;
|
|
2542
|
+
/** After guardrail (pass or reject) */
|
|
2543
|
+
afterGuardrail?: ChatAgentCheckpointConfig;
|
|
2544
|
+
/** Before each agent iteration */
|
|
2545
|
+
onIterationStart?: ChatAgentCheckpointConfig;
|
|
2546
|
+
/** After each agent iteration */
|
|
2547
|
+
onIterationEnd?: ChatAgentCheckpointConfig;
|
|
2548
|
+
/** When agent requests a tool call */
|
|
2549
|
+
onToolCall?: ChatAgentCheckpointConfig;
|
|
2550
|
+
/** After tool execution returns */
|
|
2551
|
+
onToolResult?: ChatAgentCheckpointConfig;
|
|
2552
|
+
/** When agent completes */
|
|
2553
|
+
onAgentComplete?: ChatAgentCheckpointConfig;
|
|
2554
|
+
};
|
|
2555
|
+
/** IDs of internal nodes (auto-created, managed by the container) */
|
|
2556
|
+
_internalNodes?: {
|
|
2557
|
+
userInputId?: string;
|
|
2558
|
+
guardrailId?: string;
|
|
2559
|
+
agentId?: string;
|
|
2560
|
+
toolRouterId?: string;
|
|
2561
|
+
};
|
|
2562
|
+
}
|
|
2563
|
+
/**
|
|
2564
|
+
* Checkpoint configuration for ChatAgentNode stages
|
|
2565
|
+
*/
|
|
2566
|
+
interface ChatAgentCheckpointConfig {
|
|
2567
|
+
/** Whether this checkpoint is enabled */
|
|
2568
|
+
enabled: boolean;
|
|
2569
|
+
/** Pause execution at this point (debug mode) */
|
|
2570
|
+
pause?: boolean;
|
|
2571
|
+
/** Log to console */
|
|
2572
|
+
logToConsole?: boolean;
|
|
2573
|
+
/** Log to execution history */
|
|
2574
|
+
logToHistory?: boolean;
|
|
2575
|
+
/** Require approval to continue */
|
|
2576
|
+
requireApproval?: boolean;
|
|
2577
|
+
/** Send webhook notification */
|
|
2578
|
+
sendWebhook?: boolean;
|
|
2579
|
+
webhookUrl?: string;
|
|
2580
|
+
/** Custom message template */
|
|
2581
|
+
message?: string;
|
|
2582
|
+
/** Include full context in checkpoint data */
|
|
2583
|
+
includeFullContext?: boolean;
|
|
2584
|
+
}
|
|
2585
|
+
/**
|
|
2586
|
+
* Tool definition for an agent
|
|
2587
|
+
*/
|
|
2588
|
+
interface AgentTool {
|
|
2589
|
+
/** Unique tool name */
|
|
2590
|
+
name: string;
|
|
2591
|
+
/** Description shown to the LLM */
|
|
2592
|
+
description: string;
|
|
2593
|
+
/** JSON schema for tool parameters */
|
|
2594
|
+
parameters?: {
|
|
2595
|
+
type: 'object';
|
|
2596
|
+
properties?: Record<string, {
|
|
2597
|
+
type: string;
|
|
2598
|
+
description?: string;
|
|
2599
|
+
enum?: string[];
|
|
2600
|
+
default?: unknown;
|
|
2601
|
+
}>;
|
|
2602
|
+
required?: string[];
|
|
2603
|
+
};
|
|
2604
|
+
/** How this tool is executed */
|
|
2605
|
+
toolType: 'function' | 'http' | 'mcp' | 'workflow' | 'command' | 'code' | 'web-search' | 'database-query';
|
|
2606
|
+
/** For HTTP tools */
|
|
2607
|
+
httpConfig?: {
|
|
2608
|
+
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
2609
|
+
url: string;
|
|
2610
|
+
headers?: Record<string, string>;
|
|
2611
|
+
bodyTemplate?: string;
|
|
2612
|
+
};
|
|
2613
|
+
/** For MCP tools */
|
|
2614
|
+
mcpConfig?: {
|
|
2615
|
+
serverUrl?: string;
|
|
2616
|
+
serverName?: string;
|
|
2617
|
+
};
|
|
2618
|
+
/** For workflow tools - execute a sub-workflow */
|
|
2619
|
+
workflowConfig?: {
|
|
2620
|
+
workflowPath: string;
|
|
2621
|
+
};
|
|
2622
|
+
/** For command tools - execute shell commands */
|
|
2623
|
+
commandConfig?: {
|
|
2624
|
+
executable: string;
|
|
2625
|
+
action?: string;
|
|
2626
|
+
args?: string;
|
|
2627
|
+
cwd?: string;
|
|
2628
|
+
requiresApproval?: boolean;
|
|
2629
|
+
};
|
|
2630
|
+
/** For code tools - execute code snippets */
|
|
2631
|
+
codeConfig?: {
|
|
2632
|
+
language: 'typescript' | 'javascript' | 'python' | 'csharp';
|
|
2633
|
+
snippet: string;
|
|
2634
|
+
inputVariable?: string;
|
|
2635
|
+
executionContext?: 'isolated' | 'main';
|
|
2636
|
+
};
|
|
2637
|
+
}
|
|
2638
|
+
/**
|
|
2639
|
+
* WorkflowEdge uses React Flow's standard edge format directly.
|
|
2640
|
+
* This eliminates conversion overhead and makes debugging easier.
|
|
2641
|
+
*/
|
|
2642
|
+
interface WorkflowEdge {
|
|
2643
|
+
id: string;
|
|
2644
|
+
source: string;
|
|
2645
|
+
target: string;
|
|
2646
|
+
sourceHandle?: string;
|
|
2647
|
+
targetHandle?: string;
|
|
2648
|
+
animated?: boolean;
|
|
2649
|
+
label?: string;
|
|
2650
|
+
}
|
|
2651
|
+
interface ErrorHandlingConfig {
|
|
2652
|
+
onError: 'continue' | 'stop' | 'retry';
|
|
2653
|
+
retryPolicy?: RetryPolicy;
|
|
2654
|
+
fallbackNode?: string;
|
|
2655
|
+
}
|
|
2656
|
+
interface RetryPolicy {
|
|
2657
|
+
enabled: boolean;
|
|
2658
|
+
maxRetries: number;
|
|
2659
|
+
backoffMs: number;
|
|
2660
|
+
backoffMultiplier?: number;
|
|
2661
|
+
}
|
|
2662
|
+
interface ExecutionConfig {
|
|
2663
|
+
timeout?: number;
|
|
2664
|
+
parallelism?: {
|
|
2665
|
+
enabled: boolean;
|
|
2666
|
+
maxConcurrency: number;
|
|
2667
|
+
};
|
|
2668
|
+
logging?: {
|
|
2669
|
+
level: 'debug' | 'info' | 'warn' | 'error';
|
|
2670
|
+
includeTimings?: boolean;
|
|
2671
|
+
};
|
|
2672
|
+
caching?: {
|
|
2673
|
+
enabled: boolean;
|
|
2674
|
+
ttlMs: number;
|
|
2675
|
+
};
|
|
2676
|
+
}
|
|
2677
|
+
interface JsonSchema {
|
|
2678
|
+
type: 'string' | 'number' | 'boolean' | 'array' | 'object' | 'integer';
|
|
2679
|
+
properties?: Record<string, JsonSchema>;
|
|
2680
|
+
items?: JsonSchema;
|
|
2681
|
+
required?: string[];
|
|
2682
|
+
minLength?: number;
|
|
2683
|
+
maxLength?: number;
|
|
2684
|
+
minimum?: number;
|
|
2685
|
+
maximum?: number;
|
|
2686
|
+
enum?: unknown[];
|
|
2687
|
+
}
|
|
2688
|
+
interface WorkflowValidationError {
|
|
2689
|
+
nodeId?: string;
|
|
2690
|
+
connectionId?: string;
|
|
2691
|
+
field?: string;
|
|
2692
|
+
message: string;
|
|
2693
|
+
code: string;
|
|
2694
|
+
}
|
|
2695
|
+
interface WorkflowValidationWarning {
|
|
2696
|
+
nodeId?: string;
|
|
2697
|
+
message: string;
|
|
2698
|
+
code: string;
|
|
2699
|
+
}
|
|
2700
|
+
type WorkflowExecutionStatus = 'idle' | 'running' | 'paused' | 'completed' | 'failed';
|
|
2701
|
+
type NodeExecutionStatus = 'pending' | 'running' | 'paused' | 'completed' | 'failed' | 'skipped';
|
|
2702
|
+
interface WorkflowExecutionState {
|
|
2703
|
+
workflowId: string;
|
|
2704
|
+
status: WorkflowExecutionStatus;
|
|
2705
|
+
currentNodeId?: string;
|
|
2706
|
+
nodeStates: Record<string, NodeExecutionState>;
|
|
2707
|
+
nodeOutputs: Record<string, unknown>;
|
|
2708
|
+
variables: Record<string, unknown>;
|
|
2709
|
+
errors: WorkflowExecutionError[];
|
|
2710
|
+
startTime?: number;
|
|
2711
|
+
endTime?: number;
|
|
2712
|
+
/** Memory storage for MemoryNode operations */
|
|
2713
|
+
memory?: {
|
|
2714
|
+
/** Key-value store (by namespace or root) */
|
|
2715
|
+
kv: Record<string, unknown>;
|
|
2716
|
+
/** Conversation histories (by conversation ID) */
|
|
2717
|
+
conversation: Record<string, unknown[]>;
|
|
2718
|
+
/** Cache entries with TTL (by namespace or root) */
|
|
2719
|
+
cache: Record<string, unknown>;
|
|
2720
|
+
};
|
|
2721
|
+
}
|
|
2722
|
+
interface NodeExecutionState {
|
|
2723
|
+
nodeId: string;
|
|
2724
|
+
status: NodeExecutionStatus;
|
|
2725
|
+
startTime?: number;
|
|
2726
|
+
endTime?: number;
|
|
2727
|
+
output?: unknown;
|
|
2728
|
+
error?: string;
|
|
2729
|
+
retryCount: number;
|
|
2730
|
+
streamingContent?: string;
|
|
2731
|
+
}
|
|
2732
|
+
interface WorkflowExecutionError {
|
|
2733
|
+
nodeId?: string;
|
|
2734
|
+
message: string;
|
|
2735
|
+
stack?: string;
|
|
2736
|
+
timestamp: number;
|
|
2737
|
+
}
|
|
2738
|
+
interface WorkflowResult {
|
|
2739
|
+
success: boolean;
|
|
2740
|
+
output?: unknown;
|
|
2741
|
+
nodeOutputs: Record<string, unknown>;
|
|
2742
|
+
errors: WorkflowExecutionError[];
|
|
2743
|
+
metrics: {
|
|
2744
|
+
totalDuration: number;
|
|
2745
|
+
nodeMetrics: Record<string, {
|
|
2746
|
+
duration: number;
|
|
2747
|
+
tokens?: number;
|
|
2748
|
+
}>;
|
|
2749
|
+
};
|
|
2750
|
+
}
|
|
2751
|
+
/**
|
|
2752
|
+
* WorkflowConnectionType - Types of external connections managed in the Connections panel
|
|
2753
|
+
*
|
|
2754
|
+
* Connections are managed in a dedicated panel (not canvas nodes) to scale to
|
|
2755
|
+
* hundreds of connection types. Nodes reference connections by ID.
|
|
2756
|
+
*/
|
|
2757
|
+
type WorkflowConnectionType = 'ssh' | 'database' | 'http-api' | 'slack' | 'github' | 'mcp-server' | 'websocket' | 'custom';
|
|
2758
|
+
type WorkflowConnectionStatus = 'disconnected' | 'connecting' | 'connected' | 'error';
|
|
2759
|
+
/**
|
|
2760
|
+
* WorkflowConnection - External service connection managed in the Connections panel
|
|
2761
|
+
*
|
|
2762
|
+
* Stored separately from workflow nodes - connections are workflow-scoped resources
|
|
2763
|
+
* that can be referenced by multiple nodes via connectionId.
|
|
2764
|
+
*/
|
|
2765
|
+
interface WorkflowConnection {
|
|
2766
|
+
id: string;
|
|
2767
|
+
name: string;
|
|
2768
|
+
type: WorkflowConnectionType;
|
|
2769
|
+
status: WorkflowConnectionStatus;
|
|
2770
|
+
lastConnected?: number;
|
|
2771
|
+
lastError?: string;
|
|
2772
|
+
config: WorkflowConnectionConfig;
|
|
2773
|
+
}
|
|
2774
|
+
/** Union type for all connection configs */
|
|
2775
|
+
type WorkflowConnectionConfig = SSHConnectionConfig | DatabaseConnectionConfig | HttpApiConnectionConfig | SlackConnectionConfig | GitHubConnectionConfig | McpServerConnectionConfig | WebSocketConnectionConfig | CustomConnectionConfig;
|
|
2776
|
+
interface SSHConnectionConfig {
|
|
2777
|
+
type: 'ssh';
|
|
2778
|
+
host: string;
|
|
2779
|
+
port?: number;
|
|
2780
|
+
username: string;
|
|
2781
|
+
authMethod: 'key' | 'password' | 'agent';
|
|
2782
|
+
keyPath?: string;
|
|
2783
|
+
}
|
|
2784
|
+
interface DatabaseConnectionConfig {
|
|
2785
|
+
type: 'database';
|
|
2786
|
+
dbType: 'postgresql' | 'mysql' | 'mongodb' | 'redis' | 'sqlite';
|
|
2787
|
+
host?: string;
|
|
2788
|
+
port?: number;
|
|
2789
|
+
database: string;
|
|
2790
|
+
username?: string;
|
|
2791
|
+
ssl?: boolean;
|
|
2792
|
+
connectionString?: string;
|
|
2793
|
+
}
|
|
2794
|
+
interface HttpApiConnectionConfig {
|
|
2795
|
+
type: 'http-api';
|
|
2796
|
+
baseUrl: string;
|
|
2797
|
+
authType: 'none' | 'bearer' | 'api-key' | 'basic' | 'oauth2';
|
|
2798
|
+
headers?: Record<string, string>;
|
|
2799
|
+
apiKeyHeader?: string;
|
|
2800
|
+
}
|
|
2801
|
+
interface SlackConnectionConfig {
|
|
2802
|
+
type: 'slack';
|
|
2803
|
+
workspace: string;
|
|
2804
|
+
defaultChannel?: string;
|
|
2805
|
+
}
|
|
2806
|
+
interface GitHubConnectionConfig {
|
|
2807
|
+
type: 'github';
|
|
2808
|
+
owner?: string;
|
|
2809
|
+
repo?: string;
|
|
2810
|
+
baseUrl?: string;
|
|
2811
|
+
}
|
|
2812
|
+
interface McpServerConnectionConfig {
|
|
2813
|
+
type: 'mcp-server';
|
|
2814
|
+
serverUrl: string;
|
|
2815
|
+
serverName: string;
|
|
2816
|
+
transport: 'stdio' | 'http' | 'websocket';
|
|
2817
|
+
}
|
|
2818
|
+
interface WebSocketConnectionConfig {
|
|
2819
|
+
type: 'websocket';
|
|
2820
|
+
url: string;
|
|
2821
|
+
protocols?: string[];
|
|
2822
|
+
headers?: Record<string, string>;
|
|
2823
|
+
}
|
|
2824
|
+
interface CustomConnectionConfig {
|
|
2825
|
+
type: 'custom';
|
|
2826
|
+
[key: string]: unknown;
|
|
2827
|
+
}
|
|
2828
|
+
|
|
2829
|
+
/**
|
|
2830
|
+
* Workflow Parser - Parse and validate .pdflow JSON files
|
|
2831
|
+
* Converts between .pdflow format and React Flow format
|
|
2832
|
+
*/
|
|
2833
|
+
|
|
2834
|
+
interface WorkflowCanvasNode {
|
|
2835
|
+
id: string;
|
|
2836
|
+
type: string;
|
|
2837
|
+
position: {
|
|
2838
|
+
x: number;
|
|
2839
|
+
y: number;
|
|
2840
|
+
};
|
|
2841
|
+
data: BaseNodeData;
|
|
2842
|
+
parentId?: string;
|
|
2843
|
+
extent?: 'parent';
|
|
2844
|
+
width?: number;
|
|
2845
|
+
height?: number;
|
|
2846
|
+
selected?: boolean;
|
|
2847
|
+
dragging?: boolean;
|
|
2848
|
+
[key: string]: unknown;
|
|
2849
|
+
}
|
|
2850
|
+
interface WorkflowCanvasEdge {
|
|
2851
|
+
id: string;
|
|
2852
|
+
source: string;
|
|
2853
|
+
target: string;
|
|
2854
|
+
sourceHandle?: string | null;
|
|
2855
|
+
targetHandle?: string | null;
|
|
2856
|
+
animated?: boolean;
|
|
2857
|
+
label?: string;
|
|
2858
|
+
selected?: boolean;
|
|
2859
|
+
[key: string]: unknown;
|
|
2860
|
+
}
|
|
2861
|
+
interface ParsedWorkflow {
|
|
2862
|
+
file: WorkflowFile;
|
|
2863
|
+
nodes: WorkflowCanvasNode[];
|
|
2864
|
+
edges: WorkflowCanvasEdge[];
|
|
2865
|
+
errors: WorkflowValidationError[];
|
|
2866
|
+
warnings: WorkflowValidationWarning[];
|
|
2867
|
+
}
|
|
2868
|
+
/**
|
|
2869
|
+
* Parse a .pdflow JSON string into a ParsedWorkflow
|
|
2870
|
+
*/
|
|
2871
|
+
declare function parseWorkflow(json: string): ParsedWorkflow;
|
|
2872
|
+
/**
|
|
2873
|
+
* Serialize a workflow back to JSON string
|
|
2874
|
+
*/
|
|
2875
|
+
declare function serializeWorkflow(file: WorkflowFile, nodes: WorkflowCanvasNode[], edges: WorkflowCanvasEdge[]): string;
|
|
2876
|
+
/**
|
|
2877
|
+
* Create an empty workflow file
|
|
2878
|
+
*/
|
|
2879
|
+
declare function createEmptyWorkflow(): WorkflowFile;
|
|
2880
|
+
/**
|
|
2881
|
+
* Create a new workflow node
|
|
2882
|
+
*
|
|
2883
|
+
* IMPORTANT: When adding a new node type, you MUST update THREE places:
|
|
2884
|
+
* 1. This switch statement (createWorkflowNode) - add a case with default data
|
|
2885
|
+
* 2. getDefaultLabel() below - add the default label for the node type
|
|
2886
|
+
* 3. nodes/index.ts - add the component to nodeTypes registry
|
|
2887
|
+
*
|
|
2888
|
+
* If you only add to nodes/index.ts without adding a case here, the node
|
|
2889
|
+
* will render as "UNKNOWN: <type>" because createWorkflowNode falls back
|
|
2890
|
+
* to a generic tool node for unhandled types.
|
|
2891
|
+
*/
|
|
2892
|
+
declare function createWorkflowNode(type: WorkflowNodeType, position: {
|
|
2893
|
+
x: number;
|
|
2894
|
+
y: number;
|
|
2895
|
+
}, id?: string): WorkflowNode;
|
|
2896
|
+
/**
|
|
2897
|
+
* Build execution order using topological sort
|
|
2898
|
+
*
|
|
2899
|
+
* Important: Child nodes (nodes with parentId) are EXCLUDED from the main execution order.
|
|
2900
|
+
* They are executed by their parent container node (loop, parallel), not by the main executor.
|
|
2901
|
+
*
|
|
2902
|
+
* Excludes:
|
|
2903
|
+
* - Internal back-edges that would create cycles (e.g., loop-end -> container)
|
|
2904
|
+
* - Child nodes that belong to container nodes (they have parentId set)
|
|
2905
|
+
*/
|
|
2906
|
+
declare function getExecutionOrder(workflow: ParsedWorkflow): string[];
|
|
2907
|
+
|
|
2908
|
+
/**
|
|
2909
|
+
* Centralized Workflow Validation System
|
|
2910
|
+
*
|
|
2911
|
+
* Validates workflow structure, edges, and node configurations.
|
|
2912
|
+
* Returns errors (blocking issues) and warnings (non-blocking suggestions).
|
|
2913
|
+
*/
|
|
2914
|
+
|
|
2915
|
+
interface ValidationResult {
|
|
2916
|
+
errors: WorkflowValidationError[];
|
|
2917
|
+
warnings: WorkflowValidationWarning[];
|
|
2918
|
+
isValid: boolean;
|
|
2919
|
+
}
|
|
2920
|
+
/**
|
|
2921
|
+
* Validates an entire workflow
|
|
2922
|
+
*/
|
|
2923
|
+
declare function validateWorkflow(workflow: WorkflowFile): ValidationResult;
|
|
2924
|
+
/**
|
|
2925
|
+
* Quick validation for real-time feedback (lighter weight)
|
|
2926
|
+
*/
|
|
2927
|
+
declare function validateWorkflowQuick(workflow: WorkflowFile): Pick<ValidationResult, 'isValid'>;
|
|
2928
|
+
|
|
2929
|
+
export { type AgentCheckpointEvent, type AgentCheckpointEventType, type AgentIterationRecord, type AgentNodeData, type AgentTool, AnthropicFormatter, type ApiNodeData, type AsyncFileBackend, BUILTIN_COMMAND_EXECUTABLES, type BaseNodeData, CODE_EXTENSIONS, CONTENT_TYPES, type CallbackNodeData, type ChatAgentCheckpointConfig, type ChatAgentNodeData, type ClaudeCodeNodeData, CodeGenerationStage, type CodeNodeData, type CommandNodeData, CompilationContext, type CompilationDiagnostic, CompilationError, type CompilationOptions, CompilationStage, type CompiledPrompt, CompilerPipeline, type CompilerStage, type CompleteEventData, type ConditionBranch, type ConditionNodeData, type Config, type CustomCommandConfig, type CustomConnectionConfig, type CustomProvider, DEFAULT_SECURITY_CONFIG, DOCKABLE_HANDLES, DOCKABLE_NODE_TYPES, type DatabaseConnectionConfig, type DatabaseQueryNodeData, DependencyResolutionStage, EXTENSION_TO_LANGUAGE, EXTENSION_TO_LANGUAGE_ALIASES, type ErrorEventData, type ErrorHandlerNodeData, type ErrorHandlingConfig, type ExecuteOptions, type ExecutionConfig, type GitHubConnectionConfig, type GuardrailNodeData, type HttpApiConnectionConfig, HybridFileSystem, type IFileSystem, type IPackageResolver, type IterationEventData, type JsonSchema, type LLMResponse, LexicalAnalysisStage, type LoopNodeData, MEMORY_OPERATIONS_BY_MODE, MarkdownFormatter, type McpServerConnectionConfig, type McpToolNodeData, MemoryFileSystem, type MemoryNodeData, type MemoryOperation, type MergeNodeData, type NodeExecutionState, type NodeExecutionStatus, OpenAIFormatter, type OutputFormatter, type OutputNodeData, PACKAGE_TYPE_DIRS, PROMPD_EXTENSIONS, type PackageAlias, type PackageType, type ParallelBranch, type ParallelNodeData, ParseError, type ParsedWorkflow, PrompdCompiler, PrompdError, type PrompdFile, PrompdLoader, type PrompdMetadata, type PrompdParameter, PrompdParser, type PromptNodeData, type ProviderConfig, type ProviderNodeData, type RegistryConfig, type ResolvePackageOptions, type ResolvedPackage, type RetryPolicy, type SSHConnectionConfig, type SectionInfo, SectionOverrideProcessor, type SecurityConfig, SecurityError, SemanticAnalysisStage, type SlackConnectionConfig, TOOL_DEPLOY_DIRS, TemplateProcessingStage, type ThinkingEventData, type ToolCallEventData, type ToolCallParserNodeData, type ToolCallRouterNodeData, type ToolNodeData, type TransformerNodeData, type TriggerNodeData, type UserInputNodeData, type UsingPackage, VALID_PACKAGE_TYPES, ValidationError, type ValidationIssue, type ValidationResult, type WebSearchNodeData, type WebSocketConnectionConfig, type WorkflowConnection, type WorkflowConnectionConfig, type WorkflowConnectionStatus, type WorkflowConnectionType, type WorkflowEdge, type WorkflowExecutionError, type WorkflowExecutionState, type WorkflowExecutionStatus, type WorkflowFile, type WorkflowMetadata, type WorkflowNode, type WorkflowNodeData, type WorkflowNodeType, type WorkflowParameter, type WorkflowResult, type WorkflowValidationError, type WorkflowValidationWarning, type WorkflowVariable, basenamePosix, compile, createCoreStages, createEmptyWorkflow, createPrompdEnvironment, createWorkflowNode, dirnamePosix, extname, getContentType, getExecutionOrder, getInstallDirForType, getLanguageAliasesForExtension, getLanguageForExtension, isAbsolutePosix, isPrompdFile, isValidPackageReference, isValidPackageType, joinPosix, needsFrontmatterProtection, normalizePosix, parsePackageReference, parsePackageReferenceWithPath, parseWorkflow, resolvePackageFile, resolvePosix, serializeWorkflow, stripFilePath, validateWorkflow, validateWorkflowQuick };
|