skedyul 1.7.26 → 1.7.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,802 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/cli/api/index.ts
31
+ var api_exports = {};
32
+ __export(api_exports, {
33
+ approveMigration: () => approveMigration,
34
+ apps: () => apps,
35
+ crm: () => crm,
36
+ deployWorkflow: () => deployWorkflow,
37
+ diffSchema: () => diffSchema,
38
+ getInstallation: () => getInstallation,
39
+ getWorkflow: () => getWorkflow,
40
+ getWorkflowRun: () => getWorkflowRun,
41
+ getWorkflowSchema: () => getWorkflowSchema,
42
+ getWorkplaceToken: () => getWorkplaceToken,
43
+ heartbeat: () => heartbeat,
44
+ installApp: () => installApp,
45
+ invokeTool: () => invokeTool,
46
+ linkApp: () => linkApp,
47
+ listModels: () => listModels,
48
+ listTools: () => listTools,
49
+ listWorkflowVersions: () => listWorkflowVersions,
50
+ listWorkflows: () => listWorkflows,
51
+ listWorkplaces: () => listWorkplaces,
52
+ publishWorkflow: () => publishWorkflow,
53
+ pullSchema: () => pullSchema,
54
+ pullWorkflow: () => pullWorkflow,
55
+ pushSchema: () => pushSchema,
56
+ registerEndpoint: () => registerEndpoint,
57
+ runWorkflow: () => runWorkflow,
58
+ syncResources: () => syncResources,
59
+ uninstallApp: () => uninstallApp,
60
+ unregisterEndpoint: () => unregisterEndpoint,
61
+ validateWorkflow: () => validateWorkflow,
62
+ validateWorkflowContent: () => validateWorkflowContent,
63
+ workflows: () => workflows,
64
+ workplaces: () => workplaces
65
+ });
66
+ module.exports = __toCommonJS(api_exports);
67
+
68
+ // src/cli/utils/auth.ts
69
+ var fs = __toESM(require("fs"));
70
+ var path = __toESM(require("path"));
71
+ var os = __toESM(require("os"));
72
+ var http = __toESM(require("http"));
73
+ var SKEDYUL_HOME_DIR = path.join(os.homedir(), ".skedyul");
74
+ var PROFILES_FILE = path.join(SKEDYUL_HOME_DIR, "profiles.json");
75
+ var CONFIG_FILE = path.join(SKEDYUL_HOME_DIR, "config.json");
76
+ var LEGACY_CREDENTIALS_FILE = path.join(SKEDYUL_HOME_DIR, "credentials.json");
77
+ async function callCliApi(options, endpoint, body, init) {
78
+ let url = `${options.serverUrl}/api/cli${endpoint}`;
79
+ if (init?.query) {
80
+ const params = new URLSearchParams();
81
+ for (const [key, value] of Object.entries(init.query)) {
82
+ if (value !== void 0) {
83
+ params.set(key, value);
84
+ }
85
+ }
86
+ const queryString = params.toString();
87
+ if (queryString) {
88
+ url += `?${queryString}`;
89
+ }
90
+ }
91
+ const headers = {
92
+ "Content-Type": "application/json"
93
+ };
94
+ if (options.token) {
95
+ headers["Authorization"] = `Bearer ${options.token}`;
96
+ }
97
+ const method = init?.method ?? (body !== void 0 ? "POST" : "GET");
98
+ const response = await fetch(url, {
99
+ method,
100
+ headers,
101
+ body: method === "POST" && body ? JSON.stringify(body) : void 0
102
+ });
103
+ if (!response.ok) {
104
+ const text2 = await response.text();
105
+ let message = `API error: ${response.status}`;
106
+ try {
107
+ const json = JSON.parse(text2);
108
+ if (json.error) message = json.error;
109
+ } catch {
110
+ if (text2.startsWith("<!DOCTYPE") || text2.startsWith("<html")) {
111
+ message = `API error: ${response.status} (received HTML instead of JSON \u2014 is the route registered and allowed in proxy.ts?)`;
112
+ } else if (text2) {
113
+ message = text2.slice(0, 200);
114
+ }
115
+ }
116
+ throw new Error(message);
117
+ }
118
+ const text = await response.text();
119
+ try {
120
+ return JSON.parse(text);
121
+ } catch {
122
+ throw new Error(
123
+ `Invalid JSON response from ${url} \u2014 received HTML or malformed body. Restart the web server if you added a new CLI route.`
124
+ );
125
+ }
126
+ }
127
+
128
+ // src/cli/api/context.ts
129
+ function cliApi(ctx) {
130
+ return {
131
+ serverUrl: ctx.serverUrl,
132
+ token: ctx.token
133
+ };
134
+ }
135
+ async function getWorkplaceToken(ctx, workplaceSubdomain) {
136
+ return callCliApi(cliApi(ctx), "/workplace-token", {
137
+ workplaceSubdomain
138
+ });
139
+ }
140
+ async function listWorkplaces(ctx) {
141
+ const result = await callCliApi(
142
+ cliApi(ctx),
143
+ "/workplaces",
144
+ void 0,
145
+ { method: "GET" }
146
+ );
147
+ return result.workplaces;
148
+ }
149
+ var workplaces = {
150
+ list: listWorkplaces,
151
+ getWorkplaceToken
152
+ };
153
+
154
+ // src/cli/api/crm.ts
155
+ async function listModels(ctx, workplace) {
156
+ const workplaceToken = await getWorkplaceToken(ctx, workplace);
157
+ const result = await callCliApi(
158
+ cliApi(ctx),
159
+ "/crm-models",
160
+ void 0,
161
+ { method: "GET", query: { workplaceId: workplaceToken.workplaceId } }
162
+ );
163
+ if (!result.success) {
164
+ throw new Error(result.error || "Failed to list models");
165
+ }
166
+ return result.models;
167
+ }
168
+ async function pullSchema(ctx, workplace) {
169
+ const workplaceToken = await getWorkplaceToken(ctx, workplace);
170
+ const result = await callCliApi(
171
+ cliApi(ctx),
172
+ "/crm-schema",
173
+ void 0,
174
+ { method: "GET", query: { workplaceId: workplaceToken.workplaceId } }
175
+ );
176
+ if (!result.success) {
177
+ throw new Error(result.error || "Failed to pull schema");
178
+ }
179
+ return { schema: result.schema, workplaceName: result.workplaceName };
180
+ }
181
+ async function postSchema(ctx, workplace, schema, options) {
182
+ const workplaceToken = await getWorkplaceToken(ctx, workplace);
183
+ return callCliApi(cliApi(ctx), "/crm-schema", {
184
+ workplace,
185
+ workplaceId: workplaceToken.workplaceId,
186
+ schema,
187
+ dryRun: options.dryRun ?? false,
188
+ autoApprove: options.autoApprove ?? false,
189
+ schemaName: schema.name,
190
+ schemaVersion: schema.version
191
+ });
192
+ }
193
+ async function diffSchema(ctx, workplace, schema) {
194
+ return postSchema(ctx, workplace, schema, { dryRun: true });
195
+ }
196
+ async function approveMigration(ctx, migrationId) {
197
+ await callCliApi(cliApi(ctx), "/approve-migration", { migrationId });
198
+ }
199
+ async function pushSchema(ctx, workplace, schema, options = {}) {
200
+ const result = await postSchema(ctx, workplace, schema, {
201
+ dryRun: options.dryRun ?? false,
202
+ autoApprove: options.autoApprove ?? false
203
+ });
204
+ if (!options.dryRun && options.autoApprove && result.requiresApproval && result.migrationId) {
205
+ await approveMigration(ctx, result.migrationId);
206
+ return {
207
+ ...result,
208
+ requiresApproval: false
209
+ };
210
+ }
211
+ return result;
212
+ }
213
+ var crm = {
214
+ listModels,
215
+ pullSchema,
216
+ diffSchema,
217
+ pushSchema,
218
+ approveMigration
219
+ };
220
+
221
+ // src/cli/api/workflows.ts
222
+ var import_yaml = require("yaml");
223
+
224
+ // src/workflows/types.ts
225
+ var import_v43 = require("zod/v4");
226
+
227
+ // src/events/types.ts
228
+ var import_v4 = require("zod/v4");
229
+ var ThreadEventTypeSchema = import_v4.z.enum([
230
+ // Message events
231
+ "thread.message.received",
232
+ "thread.message.sent",
233
+ "thread.attachment.received",
234
+ // Participant events
235
+ "thread.participant.joined",
236
+ "thread.participant.left",
237
+ "thread.participant.mentioned",
238
+ // Context events
239
+ "thread.context.changed",
240
+ "thread.status.changed",
241
+ // Agent/Workflow events
242
+ "thread.agent.delegated",
243
+ "thread.agent.completed",
244
+ "thread.workflow.triggered",
245
+ "thread.workflow.completed",
246
+ // Scheduled events
247
+ "thread.follow_up.due",
248
+ "thread.reminder.due",
249
+ // Signal events
250
+ "thread.signal.created"
251
+ ]);
252
+ var CustomEventTypeSchema = import_v4.z.string().regex(/^custom\.[a-z][a-z0-9_]*(\.[a-z][a-z0-9_]*)*$/, {
253
+ message: "Custom event type must match pattern: custom.{namespace}.{event}"
254
+ });
255
+ var EventTypeSchema = import_v4.z.union([ThreadEventTypeSchema, CustomEventTypeSchema]);
256
+ var ParticipantKindSchema = import_v4.z.enum(["CONTACT", "MEMBER", "AGENT", "WORKFLOW"]);
257
+ var BaseEventPayloadSchema = import_v4.z.object({
258
+ threadId: import_v4.z.string(),
259
+ workplaceId: import_v4.z.string(),
260
+ timestamp: import_v4.z.string().datetime().optional()
261
+ });
262
+ var MessageEventPayloadSchema = BaseEventPayloadSchema.extend({
263
+ message: import_v4.z.object({
264
+ id: import_v4.z.string(),
265
+ content: import_v4.z.string(),
266
+ senderId: import_v4.z.string().optional()
267
+ }),
268
+ participant: import_v4.z.object({
269
+ id: import_v4.z.string(),
270
+ kind: ParticipantKindSchema,
271
+ displayName: import_v4.z.string().optional()
272
+ }).optional(),
273
+ isFirstMessage: import_v4.z.boolean().optional(),
274
+ messageCount: import_v4.z.number().optional()
275
+ });
276
+ var ParticipantEventPayloadSchema = BaseEventPayloadSchema.extend({
277
+ participant: import_v4.z.object({
278
+ id: import_v4.z.string(),
279
+ kind: ParticipantKindSchema,
280
+ displayName: import_v4.z.string().optional(),
281
+ contactId: import_v4.z.string().optional(),
282
+ memberId: import_v4.z.string().optional(),
283
+ agentId: import_v4.z.string().optional(),
284
+ workflowId: import_v4.z.string().optional()
285
+ })
286
+ });
287
+ var ContextChangedPayloadSchema = BaseEventPayloadSchema.extend({
288
+ context: import_v4.z.object({
289
+ handle: import_v4.z.string(),
290
+ model: import_v4.z.string(),
291
+ instanceId: import_v4.z.string()
292
+ }),
293
+ change: import_v4.z.object({
294
+ field: import_v4.z.string().optional(),
295
+ oldValue: import_v4.z.unknown().optional(),
296
+ newValue: import_v4.z.unknown().optional()
297
+ }).optional()
298
+ });
299
+ var StatusChangedPayloadSchema = BaseEventPayloadSchema.extend({
300
+ oldStatus: import_v4.z.string(),
301
+ newStatus: import_v4.z.string()
302
+ });
303
+ var ScheduledEventPayloadSchema = BaseEventPayloadSchema.extend({
304
+ scheduledEventId: import_v4.z.string(),
305
+ reason: import_v4.z.string().optional(),
306
+ context: import_v4.z.record(import_v4.z.string(), import_v4.z.unknown()).optional()
307
+ });
308
+ var AgentWorkflowEventPayloadSchema = BaseEventPayloadSchema.extend({
309
+ agentId: import_v4.z.string().optional(),
310
+ workflowId: import_v4.z.string().optional(),
311
+ workflowRunId: import_v4.z.string().optional(),
312
+ outputs: import_v4.z.record(import_v4.z.string(), import_v4.z.unknown()).optional(),
313
+ error: import_v4.z.string().optional()
314
+ });
315
+ var CustomEventPayloadSchema = BaseEventPayloadSchema.extend({
316
+ data: import_v4.z.record(import_v4.z.string(), import_v4.z.unknown()).optional()
317
+ });
318
+ var ThreadEventPayloadSchema = import_v4.z.union([
319
+ MessageEventPayloadSchema,
320
+ ParticipantEventPayloadSchema,
321
+ ContextChangedPayloadSchema,
322
+ StatusChangedPayloadSchema,
323
+ ScheduledEventPayloadSchema,
324
+ AgentWorkflowEventPayloadSchema,
325
+ CustomEventPayloadSchema
326
+ ]);
327
+ var ThreadEventSchema = import_v4.z.object({
328
+ id: import_v4.z.string(),
329
+ threadId: import_v4.z.string(),
330
+ type: EventTypeSchema,
331
+ payload: ThreadEventPayloadSchema,
332
+ emittedBy: import_v4.z.string().optional(),
333
+ createdAt: import_v4.z.string().datetime()
334
+ });
335
+ var CreateThreadEventInputSchema = import_v4.z.object({
336
+ threadId: import_v4.z.string(),
337
+ type: EventTypeSchema,
338
+ payload: import_v4.z.record(import_v4.z.string(), import_v4.z.unknown()),
339
+ emittedBy: import_v4.z.string().optional()
340
+ });
341
+ var EventSubscriptionSchema = import_v4.z.object({
342
+ subscribes: import_v4.z.array(EventTypeSchema),
343
+ condition: import_v4.z.string().optional(),
344
+ cancels: import_v4.z.array(EventTypeSchema).optional(),
345
+ cancelCondition: import_v4.z.string().optional()
346
+ });
347
+ var EventWaitSchema = import_v4.z.object({
348
+ event: EventTypeSchema,
349
+ timeout: import_v4.z.string().optional(),
350
+ onTimeout: import_v4.z.string().optional()
351
+ });
352
+ var EventsConfigSchema = import_v4.z.object({
353
+ subscribes: import_v4.z.array(EventTypeSchema).optional(),
354
+ condition: import_v4.z.string().optional(),
355
+ emits: import_v4.z.array(EventTypeSchema).optional(),
356
+ waits: import_v4.z.array(EventWaitSchema).optional(),
357
+ cancels: import_v4.z.array(EventTypeSchema).optional(),
358
+ cancelCondition: import_v4.z.string().optional()
359
+ });
360
+
361
+ // src/triggers/types.ts
362
+ var import_v42 = require("zod/v4");
363
+ var CRMDataSchema = import_v42.z.object({
364
+ model: import_v42.z.string(),
365
+ instanceId: import_v42.z.string(),
366
+ data: import_v42.z.record(import_v42.z.string(), import_v42.z.unknown())
367
+ });
368
+ var SenderContextSchema = import_v42.z.object({
369
+ kind: ParticipantKindSchema,
370
+ displayName: import_v42.z.string().optional(),
371
+ crm: CRMDataSchema.optional()
372
+ });
373
+ var ThreadContextItemSchema = import_v42.z.object({
374
+ handle: import_v42.z.string(),
375
+ model: import_v42.z.string(),
376
+ instanceId: import_v42.z.string(),
377
+ data: import_v42.z.record(import_v42.z.string(), import_v42.z.unknown()).optional()
378
+ });
379
+ var ParticipantContextSchema = import_v42.z.object({
380
+ id: import_v42.z.string(),
381
+ kind: ParticipantKindSchema,
382
+ displayName: import_v42.z.string().optional(),
383
+ contactId: import_v42.z.string().optional(),
384
+ memberId: import_v42.z.string().optional(),
385
+ agentId: import_v42.z.string().optional(),
386
+ workflowId: import_v42.z.string().optional()
387
+ });
388
+ var TriggerContextSchema = import_v42.z.object({
389
+ // The event that triggered this
390
+ event: import_v42.z.object({
391
+ type: EventTypeSchema,
392
+ payload: import_v42.z.record(import_v42.z.string(), import_v42.z.unknown()),
393
+ participant: ParticipantContextSchema.optional()
394
+ }),
395
+ // Thread information
396
+ thread: import_v42.z.object({
397
+ id: import_v42.z.string(),
398
+ title: import_v42.z.string().optional(),
399
+ status: import_v42.z.string().optional(),
400
+ sender: SenderContextSchema.optional(),
401
+ context: import_v42.z.record(import_v42.z.string(), CRMDataSchema).optional(),
402
+ participants: import_v42.z.array(ParticipantContextSchema).optional()
403
+ }),
404
+ // Workplace info
405
+ workplace: import_v42.z.object({
406
+ id: import_v42.z.string(),
407
+ name: import_v42.z.string().optional(),
408
+ settings: import_v42.z.record(import_v42.z.string(), import_v42.z.unknown()).optional()
409
+ })
410
+ });
411
+ var InputMappingSchema = import_v42.z.record(import_v42.z.string(), import_v42.z.string());
412
+ var EventConditionsSchema = import_v42.z.record(import_v42.z.string(), import_v42.z.string());
413
+ var TriggerConfigSchema = import_v42.z.object({
414
+ id: import_v42.z.string(),
415
+ workflowId: import_v42.z.string(),
416
+ workflowVersionId: import_v42.z.string().optional(),
417
+ workplaceId: import_v42.z.string(),
418
+ handle: import_v42.z.string(),
419
+ // Input mappings: how to resolve workflow inputs from thread context
420
+ inputMappings: InputMappingSchema.optional(),
421
+ // Event conditions: additional workplace-specific conditions
422
+ eventConditions: EventConditionsSchema.optional(),
423
+ // Workplace-specific config overrides
424
+ config: import_v42.z.record(import_v42.z.string(), import_v42.z.unknown()).optional(),
425
+ // Trigger type and status
426
+ type: import_v42.z.string().optional(),
427
+ isEnabled: import_v42.z.boolean().optional()
428
+ });
429
+ var ResolvedTriggerSchema = import_v42.z.object({
430
+ trigger: TriggerConfigSchema,
431
+ workflow: import_v42.z.object({
432
+ id: import_v42.z.string(),
433
+ handle: import_v42.z.string(),
434
+ name: import_v42.z.string().optional(),
435
+ inputs: import_v42.z.record(import_v42.z.string(), import_v42.z.unknown()).optional(),
436
+ events: import_v42.z.object({
437
+ subscribes: import_v42.z.array(EventTypeSchema).optional(),
438
+ condition: import_v42.z.string().optional()
439
+ }).optional()
440
+ }),
441
+ inputs: import_v42.z.record(import_v42.z.string(), import_v42.z.unknown()),
442
+ context: TriggerContextSchema
443
+ });
444
+ var WorkflowInputDefinitionSchema = import_v42.z.object({
445
+ type: import_v42.z.string(),
446
+ required: import_v42.z.boolean().optional(),
447
+ description: import_v42.z.string().optional(),
448
+ default: import_v42.z.unknown().optional()
449
+ });
450
+ var WorkflowInputSchemaSchema = import_v42.z.record(import_v42.z.string(), WorkflowInputDefinitionSchema);
451
+
452
+ // src/workflows/types.ts
453
+ var WorkflowInputSchema = import_v43.z.object({
454
+ type: import_v43.z.string(),
455
+ required: import_v43.z.boolean().optional().default(false),
456
+ description: import_v43.z.string().optional(),
457
+ default: import_v43.z.unknown().optional()
458
+ });
459
+ var WorkflowStepInputSchema = import_v43.z.union([import_v43.z.string(), import_v43.z.number(), import_v43.z.boolean(), import_v43.z.record(import_v43.z.string(), import_v43.z.unknown())]);
460
+ var WorkflowStepSchema = import_v43.z.object({
461
+ // Service and command
462
+ service: import_v43.z.string(),
463
+ cmd: import_v43.z.string(),
464
+ // Dependencies
465
+ needs: import_v43.z.array(import_v43.z.string()).optional(),
466
+ // Inputs (Liquid templates supported)
467
+ inputs: import_v43.z.record(import_v43.z.string(), WorkflowStepInputSchema).optional(),
468
+ // Conditional execution
469
+ condition: import_v43.z.string().optional(),
470
+ // Retry configuration
471
+ retry: import_v43.z.object({
472
+ attempts: import_v43.z.number().optional(),
473
+ backoff: import_v43.z.enum(["linear", "exponential"]).optional()
474
+ }).optional(),
475
+ // Timeout
476
+ timeout: import_v43.z.string().optional()
477
+ });
478
+ var WorkflowRuntimeSchema = import_v43.z.object({
479
+ durable: import_v43.z.boolean().optional().default(true),
480
+ timeout: import_v43.z.string().optional(),
481
+ retry: import_v43.z.object({
482
+ attempts: import_v43.z.number().optional(),
483
+ backoff: import_v43.z.enum(["linear", "exponential"]).optional()
484
+ }).optional()
485
+ });
486
+ var WorkflowYAMLSchema = import_v43.z.object({
487
+ // Schema version
488
+ $schema: import_v43.z.string().optional(),
489
+ // Identity
490
+ handle: import_v43.z.string(),
491
+ name: import_v43.z.string(),
492
+ version: import_v43.z.string().optional(),
493
+ description: import_v43.z.string().optional(),
494
+ // Inputs this workflow needs (portable, declared in YAML)
495
+ inputs: import_v43.z.record(import_v43.z.string(), WorkflowInputSchema).optional(),
496
+ // Event subscriptions and conditions
497
+ events: EventsConfigSchema.optional(),
498
+ // Deterministic steps
499
+ steps: import_v43.z.record(import_v43.z.string(), WorkflowStepSchema),
500
+ // Runtime configuration
501
+ runtime: WorkflowRuntimeSchema.optional()
502
+ });
503
+ var WorkflowMetadataSchema = import_v43.z.object({
504
+ handle: import_v43.z.string(),
505
+ name: import_v43.z.string(),
506
+ version: import_v43.z.string().optional(),
507
+ description: import_v43.z.string().optional(),
508
+ inputs: import_v43.z.record(import_v43.z.string(), WorkflowInputDefinitionSchema).optional(),
509
+ events: EventsConfigSchema.optional()
510
+ });
511
+ var WorkflowExecutionStatusSchema = import_v43.z.enum([
512
+ "PENDING",
513
+ "RUNNING",
514
+ "COMPLETED",
515
+ "FAILED",
516
+ "CANCELLED",
517
+ "WAITING"
518
+ ]);
519
+ var WorkflowExecutionResultSchema = import_v43.z.object({
520
+ status: WorkflowExecutionStatusSchema,
521
+ outputs: import_v43.z.record(import_v43.z.string(), import_v43.z.unknown()).optional(),
522
+ error: import_v43.z.string().optional(),
523
+ startedAt: import_v43.z.string().datetime().optional(),
524
+ completedAt: import_v43.z.string().datetime().optional(),
525
+ cancelledAt: import_v43.z.string().datetime().optional(),
526
+ cancelReason: import_v43.z.string().optional()
527
+ });
528
+ function validateWorkflowYAML(workflow) {
529
+ const result = WorkflowYAMLSchema.safeParse(workflow);
530
+ if (result.success) {
531
+ return { success: true, data: result.data };
532
+ }
533
+ return { success: false, error: result.error };
534
+ }
535
+
536
+ // src/cli/api/workflows.ts
537
+ function hasPlatformWorkflowSteps(rawWorkflow) {
538
+ if (!rawWorkflow || typeof rawWorkflow !== "object") {
539
+ return false;
540
+ }
541
+ const steps = rawWorkflow.steps;
542
+ if (!steps || typeof steps !== "object") {
543
+ return false;
544
+ }
545
+ return Object.values(steps).some(
546
+ (step) => step && typeof step === "object" && typeof step.type === "string"
547
+ );
548
+ }
549
+ function validateWorkflowContent(yamlContent) {
550
+ let rawWorkflow;
551
+ try {
552
+ rawWorkflow = (0, import_yaml.parse)(yamlContent);
553
+ } catch (err) {
554
+ throw new Error(`Failed to parse YAML: ${err instanceof Error ? err.message : String(err)}`);
555
+ }
556
+ const validation = validateWorkflowYAML(rawWorkflow);
557
+ if (!validation.success) {
558
+ if (!hasPlatformWorkflowSteps(rawWorkflow)) {
559
+ const errorMessages = validation.error.issues.map((e) => ` - ${String(e.path.join(".")) || "(root)"}: ${e.message}`).join("\n");
560
+ throw new Error(`Workflow validation failed:
561
+ ${errorMessages}`);
562
+ }
563
+ }
564
+ return { content: yamlContent };
565
+ }
566
+ async function listWorkflows(ctx, workplace) {
567
+ const workplaceToken = await getWorkplaceToken(ctx, workplace);
568
+ const result = await callCliApi(cliApi(ctx), "/workflows", void 0, {
569
+ method: "GET",
570
+ query: { workplaceId: workplaceToken.workplaceId }
571
+ });
572
+ if (!result.success) {
573
+ throw new Error(result.error || "Failed to list workflows");
574
+ }
575
+ return result.workflows;
576
+ }
577
+ async function getWorkflow(ctx, workplace, handle) {
578
+ const workplaceToken = await getWorkplaceToken(ctx, workplace);
579
+ const result = await callCliApi(cliApi(ctx), "/workflows", void 0, {
580
+ method: "GET",
581
+ query: { workplaceId: workplaceToken.workplaceId, handle }
582
+ });
583
+ if (!result.success) {
584
+ throw new Error(result.error || "Failed to get workflow");
585
+ }
586
+ return result.workflow;
587
+ }
588
+ async function listWorkflowVersions(ctx, workplace, handle) {
589
+ const workplaceToken = await getWorkplaceToken(ctx, workplace);
590
+ const result = await callCliApi(cliApi(ctx), "/workflows", void 0, {
591
+ method: "GET",
592
+ query: {
593
+ workplaceId: workplaceToken.workplaceId,
594
+ handle,
595
+ action: "versions"
596
+ }
597
+ });
598
+ if (!result.success) {
599
+ throw new Error(result.error || "Failed to list versions");
600
+ }
601
+ return result.workflow.versions ?? [];
602
+ }
603
+ async function validateWorkflow(ctx, workplace, yamlContent) {
604
+ validateWorkflowContent(yamlContent);
605
+ const workplaceToken = await getWorkplaceToken(ctx, workplace);
606
+ return callCliApi(cliApi(ctx), "/workflows", {
607
+ action: "validate",
608
+ workplaceId: workplaceToken.workplaceId,
609
+ yamlContent
610
+ });
611
+ }
612
+ async function deployWorkflow(ctx, workplace, yamlContent, options = {}) {
613
+ validateWorkflowContent(yamlContent);
614
+ const workplaceToken = await getWorkplaceToken(ctx, workplace);
615
+ return callCliApi(cliApi(ctx), "/workflows", {
616
+ action: "deploy",
617
+ workplaceId: workplaceToken.workplaceId,
618
+ yamlContent,
619
+ publish: options.publish ?? true,
620
+ versionLabel: options.versionLabel
621
+ });
622
+ }
623
+ async function publishWorkflow(ctx, workplace, handle, version) {
624
+ const workplaceToken = await getWorkplaceToken(ctx, workplace);
625
+ return callCliApi(cliApi(ctx), "/workflows", {
626
+ action: "publish",
627
+ workplaceId: workplaceToken.workplaceId,
628
+ handle,
629
+ version
630
+ });
631
+ }
632
+ async function pullWorkflow(ctx, workplace, handle, version) {
633
+ const workplaceToken = await getWorkplaceToken(ctx, workplace);
634
+ return callCliApi(cliApi(ctx), "/workflows", void 0, {
635
+ method: "GET",
636
+ query: {
637
+ workplaceId: workplaceToken.workplaceId,
638
+ handle,
639
+ action: "pull",
640
+ version: version !== void 0 ? String(version) : void 0
641
+ }
642
+ });
643
+ }
644
+ async function getWorkflowSchema(ctx, workplace, handle, version) {
645
+ const workplaceToken = await getWorkplaceToken(ctx, workplace);
646
+ return callCliApi(cliApi(ctx), "/workflow-schema", void 0, {
647
+ method: "GET",
648
+ query: {
649
+ workplaceId: workplaceToken.workplaceId,
650
+ handle,
651
+ version: version !== void 0 ? String(version) : void 0
652
+ }
653
+ });
654
+ }
655
+ async function runWorkflow(ctx, workplace, handle, options = {}) {
656
+ const workplaceToken = await getWorkplaceToken(ctx, workplace);
657
+ return callCliApi(cliApi(ctx), "/workflows/run", {
658
+ workplaceId: workplaceToken.workplaceId,
659
+ handle,
660
+ version: options.version,
661
+ inputs: options.inputs ?? {}
662
+ });
663
+ }
664
+ async function getWorkflowRun(ctx, workplace, workflowRunId) {
665
+ const workplaceToken = await getWorkplaceToken(ctx, workplace);
666
+ return callCliApi(cliApi(ctx), "/workflows/run", void 0, {
667
+ method: "GET",
668
+ query: {
669
+ workplaceId: workplaceToken.workplaceId,
670
+ workflowRunId
671
+ }
672
+ });
673
+ }
674
+ var workflows = {
675
+ list: listWorkflows,
676
+ get: getWorkflow,
677
+ versions: listWorkflowVersions,
678
+ validate: validateWorkflow,
679
+ validateLocal: validateWorkflowContent,
680
+ deploy: deployWorkflow,
681
+ publish: publishWorkflow,
682
+ pull: pullWorkflow,
683
+ schema: getWorkflowSchema,
684
+ run: runWorkflow,
685
+ getRun: getWorkflowRun
686
+ };
687
+
688
+ // src/cli/api/apps.ts
689
+ async function linkApp(ctx, input) {
690
+ return callCliApi(cliApi(ctx), "/link", {
691
+ appHandle: input.appHandle,
692
+ workplaceSubdomain: input.workplaceSubdomain
693
+ });
694
+ }
695
+ async function registerEndpoint(ctx, input) {
696
+ return callCliApi(cliApi(ctx), "/register-endpoint", {
697
+ appVersionId: input.appVersionId,
698
+ invokeEndpoint: input.invokeEndpoint,
699
+ config: input.config
700
+ });
701
+ }
702
+ async function unregisterEndpoint(ctx, input) {
703
+ return callCliApi(cliApi(ctx), "/unregister-endpoint", {
704
+ appVersionId: input.appVersionId
705
+ });
706
+ }
707
+ async function heartbeat(ctx, input) {
708
+ return callCliApi(cliApi(ctx), "/heartbeat", {
709
+ appVersionId: input.appVersionId,
710
+ config: input.config
711
+ });
712
+ }
713
+ async function installApp(ctx, input) {
714
+ return callCliApi(cliApi(ctx), "/install", {
715
+ appVersionId: input.appVersionId,
716
+ env: input.env
717
+ });
718
+ }
719
+ async function uninstallApp(ctx, input) {
720
+ return callCliApi(cliApi(ctx), "/uninstall", {
721
+ appInstallationId: input.appInstallationId,
722
+ deleteFields: input.deleteFields
723
+ });
724
+ }
725
+ async function getInstallation(ctx, input) {
726
+ return callCliApi(cliApi(ctx), "/installation", {
727
+ appVersionId: input.appVersionId
728
+ });
729
+ }
730
+ async function syncResources(ctx, input) {
731
+ return callCliApi(cliApi(ctx), "/sync-resources", {
732
+ appVersionId: input.appVersionId,
733
+ workplaceSubdomain: input.workplaceSubdomain,
734
+ config: input.config
735
+ });
736
+ }
737
+ async function listTools(ctx, input) {
738
+ return callCliApi(cliApi(ctx), "/tools", void 0, {
739
+ method: "GET",
740
+ query: {
741
+ workplaceId: input.workplaceId,
742
+ name: input.name,
743
+ toolId: input.toolId,
744
+ kind: input.kind
745
+ }
746
+ });
747
+ }
748
+ async function invokeTool(ctx, input) {
749
+ return callCliApi(cliApi(ctx), "/invoke-tool", {
750
+ appInstallationId: input.appInstallationId,
751
+ toolName: input.toolName,
752
+ args: input.args ?? {},
753
+ timeout: input.timeout
754
+ });
755
+ }
756
+ var apps = {
757
+ link: linkApp,
758
+ registerEndpoint,
759
+ unregisterEndpoint,
760
+ heartbeat,
761
+ install: installApp,
762
+ uninstall: uninstallApp,
763
+ installation: getInstallation,
764
+ syncResources,
765
+ listTools,
766
+ invokeTool
767
+ };
768
+ // Annotate the CommonJS export names for ESM import in node:
769
+ 0 && (module.exports = {
770
+ approveMigration,
771
+ apps,
772
+ crm,
773
+ deployWorkflow,
774
+ diffSchema,
775
+ getInstallation,
776
+ getWorkflow,
777
+ getWorkflowRun,
778
+ getWorkflowSchema,
779
+ getWorkplaceToken,
780
+ heartbeat,
781
+ installApp,
782
+ invokeTool,
783
+ linkApp,
784
+ listModels,
785
+ listTools,
786
+ listWorkflowVersions,
787
+ listWorkflows,
788
+ listWorkplaces,
789
+ publishWorkflow,
790
+ pullSchema,
791
+ pullWorkflow,
792
+ pushSchema,
793
+ registerEndpoint,
794
+ runWorkflow,
795
+ syncResources,
796
+ uninstallApp,
797
+ unregisterEndpoint,
798
+ validateWorkflow,
799
+ validateWorkflowContent,
800
+ workflows,
801
+ workplaces
802
+ });