@wave-av/workflow-sdk 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/LICENSE +21 -0
- package/README.md +250 -0
- package/dist/chunk-M3UAADWT.mjs +237 -0
- package/dist/chunk-O4EIGRTS.mjs +57 -0
- package/dist/client.d.mts +141 -0
- package/dist/client.d.ts +141 -0
- package/dist/client.js +262 -0
- package/dist/client.mjs +8 -0
- package/dist/index.d.mts +173 -0
- package/dist/index.d.ts +173 -0
- package/dist/index.js +507 -0
- package/dist/index.mjs +200 -0
- package/dist/types.d.mts +615 -0
- package/dist/types.d.ts +615 -0
- package/dist/types.js +85 -0
- package/dist/types.mjs +14 -0
- package/package.json +73 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,507 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
DEFAULT_API_URL: () => DEFAULT_API_URL,
|
|
24
|
+
ExecuteWorkflowRequestSchema: () => ExecuteWorkflowRequestSchema,
|
|
25
|
+
VERSION: () => VERSION,
|
|
26
|
+
WaveWorkflowClient: () => WaveWorkflowClient,
|
|
27
|
+
WorkflowAgentSchema: () => WorkflowAgentSchema,
|
|
28
|
+
WorkflowBuilder: () => WorkflowBuilder,
|
|
29
|
+
WorkflowConfigSchema: () => WorkflowConfigSchema,
|
|
30
|
+
WorkflowDefinitionSchema: () => WorkflowDefinitionSchema,
|
|
31
|
+
WorkflowPhaseSchema: () => WorkflowPhaseSchema,
|
|
32
|
+
createClient: () => createClient
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(index_exports);
|
|
35
|
+
|
|
36
|
+
// src/types.ts
|
|
37
|
+
var import_zod = require("zod");
|
|
38
|
+
var WorkflowAgentSchema = import_zod.z.object({
|
|
39
|
+
type: import_zod.z.string().min(1),
|
|
40
|
+
config: import_zod.z.record(import_zod.z.unknown()).optional(),
|
|
41
|
+
timeout_seconds: import_zod.z.number().int().positive().optional(),
|
|
42
|
+
retry_policy: import_zod.z.object({
|
|
43
|
+
max_attempts: import_zod.z.number().int().positive(),
|
|
44
|
+
backoff_type: import_zod.z.enum(["fixed", "exponential"]),
|
|
45
|
+
initial_delay_ms: import_zod.z.number().int().positive(),
|
|
46
|
+
max_delay_ms: import_zod.z.number().int().positive().optional()
|
|
47
|
+
}).optional()
|
|
48
|
+
});
|
|
49
|
+
var WorkflowPhaseSchema = import_zod.z.object({
|
|
50
|
+
name: import_zod.z.string().min(1).max(100),
|
|
51
|
+
description: import_zod.z.string().max(500).optional(),
|
|
52
|
+
order: import_zod.z.number().int().positive(),
|
|
53
|
+
agents: import_zod.z.array(WorkflowAgentSchema),
|
|
54
|
+
condition: import_zod.z.object({
|
|
55
|
+
type: import_zod.z.enum(["expression", "previous_phase_status"]),
|
|
56
|
+
expression: import_zod.z.string().optional(),
|
|
57
|
+
required_status: import_zod.z.enum(["completed", "skipped"]).optional()
|
|
58
|
+
}).optional(),
|
|
59
|
+
on_failure: import_zod.z.enum(["fail", "skip", "retry"]).optional()
|
|
60
|
+
});
|
|
61
|
+
var WorkflowConfigSchema = import_zod.z.object({
|
|
62
|
+
timeout_seconds: import_zod.z.number().int().positive().max(86400).optional(),
|
|
63
|
+
max_retries: import_zod.z.number().int().min(0).max(10).optional(),
|
|
64
|
+
checkpoint_enabled: import_zod.z.boolean().optional(),
|
|
65
|
+
parallel_phases: import_zod.z.boolean().optional(),
|
|
66
|
+
fail_fast: import_zod.z.boolean().optional(),
|
|
67
|
+
notification_channels: import_zod.z.array(import_zod.z.string()).optional()
|
|
68
|
+
});
|
|
69
|
+
var WorkflowDefinitionSchema = import_zod.z.object({
|
|
70
|
+
name: import_zod.z.string().min(1).max(200),
|
|
71
|
+
slug: import_zod.z.string().regex(/^[a-z0-9-]+$/).min(1).max(100),
|
|
72
|
+
description: import_zod.z.string().max(1e3).optional(),
|
|
73
|
+
category: import_zod.z.string().min(1).max(50),
|
|
74
|
+
version: import_zod.z.string().regex(/^\d+\.\d+\.\d+$/),
|
|
75
|
+
phases: import_zod.z.array(WorkflowPhaseSchema).min(1),
|
|
76
|
+
config: WorkflowConfigSchema.optional(),
|
|
77
|
+
tags: import_zod.z.array(import_zod.z.string().max(50)).max(10).optional()
|
|
78
|
+
});
|
|
79
|
+
var ExecuteWorkflowRequestSchema = import_zod.z.object({
|
|
80
|
+
input_params: import_zod.z.record(import_zod.z.unknown()).optional(),
|
|
81
|
+
trigger_type: import_zod.z.enum(["manual", "api"]).optional(),
|
|
82
|
+
idempotency_key: import_zod.z.string().max(100).optional(),
|
|
83
|
+
checkpoint_id: import_zod.z.string().uuid().optional()
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// src/client.ts
|
|
87
|
+
var import_eventemitter3 = require("eventemitter3");
|
|
88
|
+
var WaveWorkflowClient = class extends import_eventemitter3.EventEmitter {
|
|
89
|
+
config;
|
|
90
|
+
headers;
|
|
91
|
+
constructor(config) {
|
|
92
|
+
super();
|
|
93
|
+
this.config = {
|
|
94
|
+
baseUrl: "https://api.wave.online",
|
|
95
|
+
timeout: 3e4,
|
|
96
|
+
debug: false,
|
|
97
|
+
...config
|
|
98
|
+
};
|
|
99
|
+
this.headers = {
|
|
100
|
+
"Authorization": `Bearer ${this.config.apiKey}`,
|
|
101
|
+
"Content-Type": "application/json",
|
|
102
|
+
"X-Organization-Id": this.config.organizationId
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
// ==========================================================================
|
|
106
|
+
// Workflow Definitions
|
|
107
|
+
// ==========================================================================
|
|
108
|
+
/**
|
|
109
|
+
* Get a workflow definition by slug
|
|
110
|
+
*/
|
|
111
|
+
async getWorkflow(slug) {
|
|
112
|
+
return this.request(`/v1/workflows/${slug}`);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* List all workflows
|
|
116
|
+
*/
|
|
117
|
+
async listWorkflows(options) {
|
|
118
|
+
const params = new URLSearchParams();
|
|
119
|
+
if (options?.category) params.set("category", options.category);
|
|
120
|
+
if (options?.status) params.set("status", options.status);
|
|
121
|
+
if (options?.limit) params.set("limit", String(options.limit));
|
|
122
|
+
if (options?.offset) params.set("offset", String(options.offset));
|
|
123
|
+
return this.request(`/v1/workflows?${params.toString()}`);
|
|
124
|
+
}
|
|
125
|
+
// ==========================================================================
|
|
126
|
+
// Workflow Executions
|
|
127
|
+
// ==========================================================================
|
|
128
|
+
/**
|
|
129
|
+
* Execute a workflow
|
|
130
|
+
*/
|
|
131
|
+
async execute(workflowSlug, request) {
|
|
132
|
+
const response = await this.request(
|
|
133
|
+
`/v1/workflows/${workflowSlug}/execute`,
|
|
134
|
+
{
|
|
135
|
+
method: "POST",
|
|
136
|
+
body: JSON.stringify(request || {})
|
|
137
|
+
}
|
|
138
|
+
);
|
|
139
|
+
return response.execution;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Get execution status
|
|
143
|
+
*/
|
|
144
|
+
async getExecution(executionId) {
|
|
145
|
+
return this.request(`/v1/executions/${executionId}`);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* List executions
|
|
149
|
+
*/
|
|
150
|
+
async listExecutions(request) {
|
|
151
|
+
const params = new URLSearchParams();
|
|
152
|
+
if (request?.workflow_id) params.set("workflow_id", request.workflow_id);
|
|
153
|
+
if (request?.status) params.set("status", request.status);
|
|
154
|
+
if (request?.limit) params.set("limit", String(request.limit));
|
|
155
|
+
if (request?.offset) params.set("offset", String(request.offset));
|
|
156
|
+
if (request?.order_by) params.set("order_by", request.order_by);
|
|
157
|
+
if (request?.order) params.set("order", request.order);
|
|
158
|
+
return this.request(`/v1/executions?${params.toString()}`);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Cancel a running execution
|
|
162
|
+
*/
|
|
163
|
+
async cancelExecution(executionId) {
|
|
164
|
+
return this.request(
|
|
165
|
+
`/v1/executions/${executionId}/cancel`,
|
|
166
|
+
{ method: "POST" }
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Pause a running execution
|
|
171
|
+
*/
|
|
172
|
+
async pauseExecution(executionId) {
|
|
173
|
+
return this.request(
|
|
174
|
+
`/v1/executions/${executionId}/pause`,
|
|
175
|
+
{ method: "POST" }
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Resume a paused execution
|
|
180
|
+
*/
|
|
181
|
+
async resumeExecution(executionId) {
|
|
182
|
+
return this.request(
|
|
183
|
+
`/v1/executions/${executionId}/resume`,
|
|
184
|
+
{ method: "POST" }
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Retry a failed execution
|
|
189
|
+
*/
|
|
190
|
+
async retryExecution(executionId, options) {
|
|
191
|
+
return this.request(
|
|
192
|
+
`/v1/executions/${executionId}/retry`,
|
|
193
|
+
{
|
|
194
|
+
method: "POST",
|
|
195
|
+
body: JSON.stringify(options || {})
|
|
196
|
+
}
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
// ==========================================================================
|
|
200
|
+
// Execution Logs
|
|
201
|
+
// ==========================================================================
|
|
202
|
+
/**
|
|
203
|
+
* Get execution logs
|
|
204
|
+
*/
|
|
205
|
+
async getLogs(executionId, options) {
|
|
206
|
+
const params = new URLSearchParams();
|
|
207
|
+
if (options?.level) params.set("level", options.level);
|
|
208
|
+
if (options?.limit) params.set("limit", String(options.limit));
|
|
209
|
+
if (options?.offset) params.set("offset", String(options.offset));
|
|
210
|
+
return this.request(`/v1/executions/${executionId}/logs?${params.toString()}`);
|
|
211
|
+
}
|
|
212
|
+
// ==========================================================================
|
|
213
|
+
// Convenience Methods
|
|
214
|
+
// ==========================================================================
|
|
215
|
+
/**
|
|
216
|
+
* Wait for an execution to complete
|
|
217
|
+
*/
|
|
218
|
+
async waitForCompletion(executionId, options) {
|
|
219
|
+
const pollInterval = options?.pollInterval || 2e3;
|
|
220
|
+
const timeout = options?.timeout || 36e5;
|
|
221
|
+
const startTime = Date.now();
|
|
222
|
+
const terminalStatuses = [
|
|
223
|
+
"completed",
|
|
224
|
+
"failed",
|
|
225
|
+
"cancelled",
|
|
226
|
+
"timeout"
|
|
227
|
+
];
|
|
228
|
+
while (Date.now() - startTime < timeout) {
|
|
229
|
+
const execution = await this.getExecution(executionId);
|
|
230
|
+
if (options?.onProgress) {
|
|
231
|
+
options.onProgress(execution);
|
|
232
|
+
}
|
|
233
|
+
if (terminalStatuses.includes(execution.status)) {
|
|
234
|
+
return execution;
|
|
235
|
+
}
|
|
236
|
+
await this.sleep(pollInterval);
|
|
237
|
+
}
|
|
238
|
+
throw new Error(`Execution ${executionId} timed out after ${timeout}ms`);
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Execute a workflow and wait for completion
|
|
242
|
+
*/
|
|
243
|
+
async executeAndWait(workflowSlug, request, waitOptions) {
|
|
244
|
+
const execution = await this.execute(workflowSlug, request);
|
|
245
|
+
return this.waitForCompletion(execution.id, waitOptions);
|
|
246
|
+
}
|
|
247
|
+
// ==========================================================================
|
|
248
|
+
// Real-time Events (WebSocket)
|
|
249
|
+
// ==========================================================================
|
|
250
|
+
/**
|
|
251
|
+
* Subscribe to real-time execution events
|
|
252
|
+
*/
|
|
253
|
+
subscribeToExecution(executionId) {
|
|
254
|
+
const wsUrl = this.config.baseUrl.replace("https://", "wss://").replace("http://", "ws://");
|
|
255
|
+
const ws = new WebSocket(
|
|
256
|
+
`${wsUrl}/v1/executions/${executionId}/events?token=${this.config.apiKey}`
|
|
257
|
+
);
|
|
258
|
+
ws.onmessage = (event) => {
|
|
259
|
+
try {
|
|
260
|
+
const data = JSON.parse(event.data);
|
|
261
|
+
this.emit(data.type, data);
|
|
262
|
+
} catch (error) {
|
|
263
|
+
this.emit("error", error);
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
ws.onerror = (error) => {
|
|
267
|
+
this.emit("error", new Error(`WebSocket error: ${error}`));
|
|
268
|
+
};
|
|
269
|
+
return () => {
|
|
270
|
+
if (ws.readyState === WebSocket.OPEN) {
|
|
271
|
+
ws.close();
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
// ==========================================================================
|
|
276
|
+
// Private Helpers
|
|
277
|
+
// ==========================================================================
|
|
278
|
+
async request(path, options) {
|
|
279
|
+
const url = `${this.config.baseUrl}${path}`;
|
|
280
|
+
if (this.config.debug) {
|
|
281
|
+
console.log(`[WaveWorkflowClient] ${options?.method || "GET"} ${url}`);
|
|
282
|
+
}
|
|
283
|
+
const controller = new AbortController();
|
|
284
|
+
const timeoutId = setTimeout(
|
|
285
|
+
() => controller.abort(),
|
|
286
|
+
this.config.timeout
|
|
287
|
+
);
|
|
288
|
+
try {
|
|
289
|
+
const response = await fetch(url, {
|
|
290
|
+
...options,
|
|
291
|
+
headers: {
|
|
292
|
+
...this.headers,
|
|
293
|
+
...options?.headers
|
|
294
|
+
},
|
|
295
|
+
signal: controller.signal
|
|
296
|
+
});
|
|
297
|
+
clearTimeout(timeoutId);
|
|
298
|
+
if (!response.ok) {
|
|
299
|
+
const error = await response.text();
|
|
300
|
+
throw new Error(`API error (${response.status}): ${error}`);
|
|
301
|
+
}
|
|
302
|
+
return response.json();
|
|
303
|
+
} catch (error) {
|
|
304
|
+
clearTimeout(timeoutId);
|
|
305
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
306
|
+
throw new Error(`Request timeout after ${this.config.timeout}ms`);
|
|
307
|
+
}
|
|
308
|
+
throw error;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
sleep(ms) {
|
|
312
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
function createClient(config) {
|
|
316
|
+
return new WaveWorkflowClient(config);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// src/builder.ts
|
|
320
|
+
var WorkflowBuilder = class {
|
|
321
|
+
definition = {
|
|
322
|
+
phases: [],
|
|
323
|
+
config: {},
|
|
324
|
+
tags: []
|
|
325
|
+
};
|
|
326
|
+
constructor(slug) {
|
|
327
|
+
this.definition.slug = slug;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Set the workflow name
|
|
331
|
+
*/
|
|
332
|
+
name(name) {
|
|
333
|
+
this.definition.name = name;
|
|
334
|
+
return this;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Set the workflow description
|
|
338
|
+
*/
|
|
339
|
+
description(description) {
|
|
340
|
+
this.definition.description = description;
|
|
341
|
+
return this;
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Set the workflow category
|
|
345
|
+
*/
|
|
346
|
+
category(category) {
|
|
347
|
+
this.definition.category = category;
|
|
348
|
+
return this;
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Set the workflow version
|
|
352
|
+
*/
|
|
353
|
+
version(version) {
|
|
354
|
+
this.definition.version = version;
|
|
355
|
+
return this;
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Add tags to the workflow
|
|
359
|
+
*/
|
|
360
|
+
tags(...tags) {
|
|
361
|
+
this.definition.tags = [...this.definition.tags || [], ...tags];
|
|
362
|
+
return this;
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Add a phase to the workflow
|
|
366
|
+
*/
|
|
367
|
+
phase(name, builder) {
|
|
368
|
+
const phaseBuilder = new PhaseBuilder(name, (this.definition.phases?.length || 0) + 1);
|
|
369
|
+
builder(phaseBuilder);
|
|
370
|
+
this.definition.phases = [...this.definition.phases || [], phaseBuilder.build()];
|
|
371
|
+
return this;
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Set workflow configuration
|
|
375
|
+
*/
|
|
376
|
+
config(config) {
|
|
377
|
+
this.definition.config = { ...this.definition.config, ...config };
|
|
378
|
+
return this;
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Set timeout in seconds
|
|
382
|
+
*/
|
|
383
|
+
timeout(seconds) {
|
|
384
|
+
this.definition.config = { ...this.definition.config, timeout_seconds: seconds };
|
|
385
|
+
return this;
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Enable checkpointing
|
|
389
|
+
*/
|
|
390
|
+
enableCheckpoints() {
|
|
391
|
+
this.definition.config = { ...this.definition.config, checkpoint_enabled: true };
|
|
392
|
+
return this;
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Set max retries
|
|
396
|
+
*/
|
|
397
|
+
maxRetries(retries) {
|
|
398
|
+
this.definition.config = { ...this.definition.config, max_retries: retries };
|
|
399
|
+
return this;
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Build and validate the workflow definition
|
|
403
|
+
*/
|
|
404
|
+
build() {
|
|
405
|
+
const result = WorkflowDefinitionSchema.safeParse(this.definition);
|
|
406
|
+
if (!result.success) {
|
|
407
|
+
const errors = result.error.issues.map((i) => `${i.path.join(".")}: ${i.message}`).join("\n");
|
|
408
|
+
throw new Error(`Invalid workflow definition:
|
|
409
|
+
${errors}`);
|
|
410
|
+
}
|
|
411
|
+
return result.data;
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Export as JSON
|
|
415
|
+
*/
|
|
416
|
+
toJSON() {
|
|
417
|
+
return JSON.stringify(this.build(), null, 2);
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
var PhaseBuilder = class {
|
|
421
|
+
phase;
|
|
422
|
+
constructor(name, order) {
|
|
423
|
+
this.phase = {
|
|
424
|
+
name,
|
|
425
|
+
order,
|
|
426
|
+
agents: []
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Set phase description
|
|
431
|
+
*/
|
|
432
|
+
description(description) {
|
|
433
|
+
this.phase.description = description;
|
|
434
|
+
return this;
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Add an agent to the phase
|
|
438
|
+
*/
|
|
439
|
+
agent(type, config) {
|
|
440
|
+
const agent = { type };
|
|
441
|
+
if (config) agent.config = config;
|
|
442
|
+
this.phase.agents = [...this.phase.agents || [], agent];
|
|
443
|
+
return this;
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* Add an agent with full configuration
|
|
447
|
+
*/
|
|
448
|
+
agentWithRetry(type, config, retryPolicy) {
|
|
449
|
+
const agent = {
|
|
450
|
+
type,
|
|
451
|
+
config,
|
|
452
|
+
retry_policy: retryPolicy
|
|
453
|
+
};
|
|
454
|
+
this.phase.agents = [...this.phase.agents || [], agent];
|
|
455
|
+
return this;
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Set conditional execution based on expression
|
|
459
|
+
*/
|
|
460
|
+
runIf(expression) {
|
|
461
|
+
this.phase.condition = {
|
|
462
|
+
type: "expression",
|
|
463
|
+
expression
|
|
464
|
+
};
|
|
465
|
+
return this;
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Set conditional execution based on previous phase status
|
|
469
|
+
*/
|
|
470
|
+
runAfter(status) {
|
|
471
|
+
this.phase.condition = {
|
|
472
|
+
type: "previous_phase_status",
|
|
473
|
+
required_status: status
|
|
474
|
+
};
|
|
475
|
+
return this;
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* Set failure behavior
|
|
479
|
+
*/
|
|
480
|
+
onFailure(behavior) {
|
|
481
|
+
this.phase.on_failure = behavior;
|
|
482
|
+
return this;
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Build the phase
|
|
486
|
+
*/
|
|
487
|
+
build() {
|
|
488
|
+
return this.phase;
|
|
489
|
+
}
|
|
490
|
+
};
|
|
491
|
+
|
|
492
|
+
// src/index.ts
|
|
493
|
+
var VERSION = "1.0.0";
|
|
494
|
+
var DEFAULT_API_URL = "https://api.wave.online";
|
|
495
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
496
|
+
0 && (module.exports = {
|
|
497
|
+
DEFAULT_API_URL,
|
|
498
|
+
ExecuteWorkflowRequestSchema,
|
|
499
|
+
VERSION,
|
|
500
|
+
WaveWorkflowClient,
|
|
501
|
+
WorkflowAgentSchema,
|
|
502
|
+
WorkflowBuilder,
|
|
503
|
+
WorkflowConfigSchema,
|
|
504
|
+
WorkflowDefinitionSchema,
|
|
505
|
+
WorkflowPhaseSchema,
|
|
506
|
+
createClient
|
|
507
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import {
|
|
2
|
+
WaveWorkflowClient,
|
|
3
|
+
createClient
|
|
4
|
+
} from "./chunk-M3UAADWT.mjs";
|
|
5
|
+
import {
|
|
6
|
+
ExecuteWorkflowRequestSchema,
|
|
7
|
+
WorkflowAgentSchema,
|
|
8
|
+
WorkflowConfigSchema,
|
|
9
|
+
WorkflowDefinitionSchema,
|
|
10
|
+
WorkflowPhaseSchema
|
|
11
|
+
} from "./chunk-O4EIGRTS.mjs";
|
|
12
|
+
|
|
13
|
+
// src/builder.ts
|
|
14
|
+
var WorkflowBuilder = class {
|
|
15
|
+
definition = {
|
|
16
|
+
phases: [],
|
|
17
|
+
config: {},
|
|
18
|
+
tags: []
|
|
19
|
+
};
|
|
20
|
+
constructor(slug) {
|
|
21
|
+
this.definition.slug = slug;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Set the workflow name
|
|
25
|
+
*/
|
|
26
|
+
name(name) {
|
|
27
|
+
this.definition.name = name;
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Set the workflow description
|
|
32
|
+
*/
|
|
33
|
+
description(description) {
|
|
34
|
+
this.definition.description = description;
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Set the workflow category
|
|
39
|
+
*/
|
|
40
|
+
category(category) {
|
|
41
|
+
this.definition.category = category;
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Set the workflow version
|
|
46
|
+
*/
|
|
47
|
+
version(version) {
|
|
48
|
+
this.definition.version = version;
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Add tags to the workflow
|
|
53
|
+
*/
|
|
54
|
+
tags(...tags) {
|
|
55
|
+
this.definition.tags = [...this.definition.tags || [], ...tags];
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Add a phase to the workflow
|
|
60
|
+
*/
|
|
61
|
+
phase(name, builder) {
|
|
62
|
+
const phaseBuilder = new PhaseBuilder(name, (this.definition.phases?.length || 0) + 1);
|
|
63
|
+
builder(phaseBuilder);
|
|
64
|
+
this.definition.phases = [...this.definition.phases || [], phaseBuilder.build()];
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Set workflow configuration
|
|
69
|
+
*/
|
|
70
|
+
config(config) {
|
|
71
|
+
this.definition.config = { ...this.definition.config, ...config };
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Set timeout in seconds
|
|
76
|
+
*/
|
|
77
|
+
timeout(seconds) {
|
|
78
|
+
this.definition.config = { ...this.definition.config, timeout_seconds: seconds };
|
|
79
|
+
return this;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Enable checkpointing
|
|
83
|
+
*/
|
|
84
|
+
enableCheckpoints() {
|
|
85
|
+
this.definition.config = { ...this.definition.config, checkpoint_enabled: true };
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Set max retries
|
|
90
|
+
*/
|
|
91
|
+
maxRetries(retries) {
|
|
92
|
+
this.definition.config = { ...this.definition.config, max_retries: retries };
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Build and validate the workflow definition
|
|
97
|
+
*/
|
|
98
|
+
build() {
|
|
99
|
+
const result = WorkflowDefinitionSchema.safeParse(this.definition);
|
|
100
|
+
if (!result.success) {
|
|
101
|
+
const errors = result.error.issues.map((i) => `${i.path.join(".")}: ${i.message}`).join("\n");
|
|
102
|
+
throw new Error(`Invalid workflow definition:
|
|
103
|
+
${errors}`);
|
|
104
|
+
}
|
|
105
|
+
return result.data;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Export as JSON
|
|
109
|
+
*/
|
|
110
|
+
toJSON() {
|
|
111
|
+
return JSON.stringify(this.build(), null, 2);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
var PhaseBuilder = class {
|
|
115
|
+
phase;
|
|
116
|
+
constructor(name, order) {
|
|
117
|
+
this.phase = {
|
|
118
|
+
name,
|
|
119
|
+
order,
|
|
120
|
+
agents: []
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Set phase description
|
|
125
|
+
*/
|
|
126
|
+
description(description) {
|
|
127
|
+
this.phase.description = description;
|
|
128
|
+
return this;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Add an agent to the phase
|
|
132
|
+
*/
|
|
133
|
+
agent(type, config) {
|
|
134
|
+
const agent = { type };
|
|
135
|
+
if (config) agent.config = config;
|
|
136
|
+
this.phase.agents = [...this.phase.agents || [], agent];
|
|
137
|
+
return this;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Add an agent with full configuration
|
|
141
|
+
*/
|
|
142
|
+
agentWithRetry(type, config, retryPolicy) {
|
|
143
|
+
const agent = {
|
|
144
|
+
type,
|
|
145
|
+
config,
|
|
146
|
+
retry_policy: retryPolicy
|
|
147
|
+
};
|
|
148
|
+
this.phase.agents = [...this.phase.agents || [], agent];
|
|
149
|
+
return this;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Set conditional execution based on expression
|
|
153
|
+
*/
|
|
154
|
+
runIf(expression) {
|
|
155
|
+
this.phase.condition = {
|
|
156
|
+
type: "expression",
|
|
157
|
+
expression
|
|
158
|
+
};
|
|
159
|
+
return this;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Set conditional execution based on previous phase status
|
|
163
|
+
*/
|
|
164
|
+
runAfter(status) {
|
|
165
|
+
this.phase.condition = {
|
|
166
|
+
type: "previous_phase_status",
|
|
167
|
+
required_status: status
|
|
168
|
+
};
|
|
169
|
+
return this;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Set failure behavior
|
|
173
|
+
*/
|
|
174
|
+
onFailure(behavior) {
|
|
175
|
+
this.phase.on_failure = behavior;
|
|
176
|
+
return this;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Build the phase
|
|
180
|
+
*/
|
|
181
|
+
build() {
|
|
182
|
+
return this.phase;
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
// src/index.ts
|
|
187
|
+
var VERSION = "1.0.0";
|
|
188
|
+
var DEFAULT_API_URL = "https://api.wave.online";
|
|
189
|
+
export {
|
|
190
|
+
DEFAULT_API_URL,
|
|
191
|
+
ExecuteWorkflowRequestSchema,
|
|
192
|
+
VERSION,
|
|
193
|
+
WaveWorkflowClient,
|
|
194
|
+
WorkflowAgentSchema,
|
|
195
|
+
WorkflowBuilder,
|
|
196
|
+
WorkflowConfigSchema,
|
|
197
|
+
WorkflowDefinitionSchema,
|
|
198
|
+
WorkflowPhaseSchema,
|
|
199
|
+
createClient
|
|
200
|
+
};
|