@openserv-labs/client 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/LICENSE +21 -0
- package/README.md +646 -0
- package/dist/agents-api.d.ts +139 -0
- package/dist/agents-api.d.ts.map +1 -0
- package/dist/agents-api.js +182 -0
- package/dist/client.d.ts +107 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +187 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +34 -0
- package/dist/integrations-api.d.ts +34 -0
- package/dist/integrations-api.d.ts.map +1 -0
- package/dist/integrations-api.js +46 -0
- package/dist/payments-api.d.ts +126 -0
- package/dist/payments-api.d.ts.map +1 -0
- package/dist/payments-api.js +155 -0
- package/dist/provision.d.ts +194 -0
- package/dist/provision.d.ts.map +1 -0
- package/dist/provision.js +541 -0
- package/dist/tasks-api.d.ts +103 -0
- package/dist/tasks-api.d.ts.map +1 -0
- package/dist/tasks-api.js +110 -0
- package/dist/triggers-api.d.ts +254 -0
- package/dist/triggers-api.d.ts.map +1 -0
- package/dist/triggers-api.js +309 -0
- package/dist/types.d.ts +219 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/web3-api.d.ts +117 -0
- package/dist/web3-api.d.ts.map +1 -0
- package/dist/web3-api.js +185 -0
- package/dist/workflow.d.ts +27 -0
- package/dist/workflow.d.ts.map +1 -0
- package/dist/workflow.js +50 -0
- package/dist/workflows-api.d.ts +142 -0
- package/dist/workflows-api.d.ts.map +1 -0
- package/dist/workflows-api.js +357 -0
- package/package.json +70 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TasksAPI = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* API for managing tasks within workflows.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const client = new PlatformClient({ apiKey: 'your-key' });
|
|
10
|
+
*
|
|
11
|
+
* // Create a task
|
|
12
|
+
* const task = await client.tasks.create({
|
|
13
|
+
* workflowId: 123,
|
|
14
|
+
* agentId: 456,
|
|
15
|
+
* description: 'Process the data',
|
|
16
|
+
* body: 'Additional details'
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* // Create a task with dependencies
|
|
20
|
+
* const task2 = await client.tasks.create({
|
|
21
|
+
* workflowId: 123,
|
|
22
|
+
* agentId: 456,
|
|
23
|
+
* description: 'Follow-up task',
|
|
24
|
+
* dependencies: [task.id]
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
class TasksAPI {
|
|
29
|
+
client;
|
|
30
|
+
constructor(client) {
|
|
31
|
+
this.client = client;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Create a new task in a workflow.
|
|
35
|
+
* @param params - Parameters object
|
|
36
|
+
* @param params.workflowId - The workflow ID to create the task in
|
|
37
|
+
* @param params.agentId - The agent ID to assign the task to
|
|
38
|
+
* @param params.description - Short description of the task
|
|
39
|
+
* @param params.body - Detailed task body (defaults to description)
|
|
40
|
+
* @param params.input - Input data for the task
|
|
41
|
+
* @param params.dependencies - Array of task IDs this task depends on
|
|
42
|
+
* @returns The created task
|
|
43
|
+
*/
|
|
44
|
+
async create(params) {
|
|
45
|
+
const { workflowId, agentId, description, body, input, dependencies } = params;
|
|
46
|
+
const data = await this.client.post(`/workspaces/${workflowId}/task`, {
|
|
47
|
+
assignee: typeof agentId === "string" ? parseInt(agentId) : agentId,
|
|
48
|
+
description: description,
|
|
49
|
+
body: body || description,
|
|
50
|
+
input: input || "",
|
|
51
|
+
outputOptions: {
|
|
52
|
+
default: {
|
|
53
|
+
name: "Task Output",
|
|
54
|
+
type: "text",
|
|
55
|
+
instructions: "Complete the task and provide output",
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
dependencies: dependencies || [],
|
|
59
|
+
});
|
|
60
|
+
return this.get({ workflowId, id: data.id });
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Get a task by ID.
|
|
64
|
+
* @param params - Parameters object
|
|
65
|
+
* @param params.workflowId - The workflow ID
|
|
66
|
+
* @param params.id - The task ID
|
|
67
|
+
* @returns The task
|
|
68
|
+
*/
|
|
69
|
+
async get(params) {
|
|
70
|
+
return this.client.get(`/workspaces/${params.workflowId}/tasks/${params.id}`);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* List all tasks in a workflow.
|
|
74
|
+
* @param params - Parameters object
|
|
75
|
+
* @param params.workflowId - The workflow ID
|
|
76
|
+
* @returns Array of tasks
|
|
77
|
+
*/
|
|
78
|
+
async list(params) {
|
|
79
|
+
return this.client.get(`/workspaces/${params.workflowId}/tasks`);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Update an existing task.
|
|
83
|
+
* @param params - Parameters object
|
|
84
|
+
* @param params.workflowId - The workflow ID
|
|
85
|
+
* @param params.id - The task ID to update
|
|
86
|
+
* @param params.description - New description (optional)
|
|
87
|
+
* @param params.body - New body (optional)
|
|
88
|
+
* @param params.input - New input (optional)
|
|
89
|
+
* @param params.status - New status (optional)
|
|
90
|
+
* @param params.assigneeAgentId - New assignee agent ID (optional)
|
|
91
|
+
* @param params.dependencies - New dependencies (optional)
|
|
92
|
+
* @returns The updated task
|
|
93
|
+
*/
|
|
94
|
+
async update(params) {
|
|
95
|
+
const { workflowId, id, ...data } = params;
|
|
96
|
+
await this.client.put(`/workspaces/${workflowId}/tasks/${id}`, data);
|
|
97
|
+
// PUT returns success message for user auth, fetch the updated task
|
|
98
|
+
return this.get({ workflowId, id });
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Delete a task.
|
|
102
|
+
* @param params - Parameters object
|
|
103
|
+
* @param params.workflowId - The workflow ID
|
|
104
|
+
* @param params.id - The task ID to delete
|
|
105
|
+
*/
|
|
106
|
+
async delete(params) {
|
|
107
|
+
await this.client.delete(`/workspaces/${params.workflowId}/tasks/${params.id}`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.TasksAPI = TasksAPI;
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import type { PlatformClient } from "./client";
|
|
2
|
+
import type { Trigger } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Defines a single property in an input schema.
|
|
5
|
+
*/
|
|
6
|
+
export interface InputSchemaProperty {
|
|
7
|
+
type: "string" | "number" | "boolean" | "object" | "array";
|
|
8
|
+
title?: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
enum?: string[];
|
|
11
|
+
default?: unknown;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Schema defining input fields for a trigger.
|
|
15
|
+
*/
|
|
16
|
+
export interface InputSchema {
|
|
17
|
+
[key: string]: InputSchemaProperty;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Configuration for a webhook trigger.
|
|
21
|
+
*/
|
|
22
|
+
export interface WebhookTriggerConfig {
|
|
23
|
+
type: "webhook";
|
|
24
|
+
/** Input schema for webhook payload validation */
|
|
25
|
+
input?: InputSchema;
|
|
26
|
+
/** Whether to wait for workflow completion before responding */
|
|
27
|
+
waitForCompletion?: boolean;
|
|
28
|
+
/** Timeout in seconds (default: 180) */
|
|
29
|
+
timeout?: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Configuration for an x402 (paid) trigger.
|
|
33
|
+
*/
|
|
34
|
+
export interface X402TriggerConfig {
|
|
35
|
+
type: "x402";
|
|
36
|
+
/** Price in USD (e.g., "0.01") */
|
|
37
|
+
price: string;
|
|
38
|
+
/** Input schema for request validation */
|
|
39
|
+
input?: InputSchema;
|
|
40
|
+
/** Timeout in seconds (default: 180) */
|
|
41
|
+
timeout?: number;
|
|
42
|
+
/** Wallet address to receive payments */
|
|
43
|
+
walletAddress?: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Configuration for a cron (scheduled) trigger.
|
|
47
|
+
*/
|
|
48
|
+
export interface CronTriggerConfig {
|
|
49
|
+
type: "cron";
|
|
50
|
+
/** Cron expression (e.g., "0 9 * * *" for daily at 9 AM) */
|
|
51
|
+
schedule: string;
|
|
52
|
+
/** Timezone (default: "UTC") */
|
|
53
|
+
timezone?: string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Configuration for a manual trigger.
|
|
57
|
+
*/
|
|
58
|
+
export interface ManualTriggerConfig {
|
|
59
|
+
type: "manual";
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Union type for all trigger configurations.
|
|
63
|
+
*/
|
|
64
|
+
export type TriggerConfig = WebhookTriggerConfig | X402TriggerConfig | CronTriggerConfig | ManualTriggerConfig;
|
|
65
|
+
/**
|
|
66
|
+
* Factory functions for creating type-safe trigger configurations.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* import { triggers, triggerConfigToProps } from '@openserv-labs/client';
|
|
71
|
+
*
|
|
72
|
+
* // Create a webhook trigger config
|
|
73
|
+
* const webhookConfig = triggers.webhook({
|
|
74
|
+
* input: { query: { type: 'string' } },
|
|
75
|
+
* waitForCompletion: true
|
|
76
|
+
* });
|
|
77
|
+
*
|
|
78
|
+
* // Convert to API props
|
|
79
|
+
* const props = triggerConfigToProps(webhookConfig);
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export declare const triggers: {
|
|
83
|
+
/**
|
|
84
|
+
* Create a webhook trigger configuration.
|
|
85
|
+
* @param opts - Options for the webhook trigger
|
|
86
|
+
* @returns Webhook trigger configuration
|
|
87
|
+
*/
|
|
88
|
+
webhook: (opts?: {
|
|
89
|
+
input?: InputSchema;
|
|
90
|
+
waitForCompletion?: boolean;
|
|
91
|
+
timeout?: number;
|
|
92
|
+
}) => WebhookTriggerConfig;
|
|
93
|
+
/**
|
|
94
|
+
* Create an x402 (paid) trigger configuration.
|
|
95
|
+
* @param opts - Options for the x402 trigger
|
|
96
|
+
* @param opts.price - Price in USD (e.g., "0.01")
|
|
97
|
+
* @returns x402 trigger configuration
|
|
98
|
+
*/
|
|
99
|
+
x402: (opts: {
|
|
100
|
+
price: string;
|
|
101
|
+
input?: InputSchema;
|
|
102
|
+
timeout?: number;
|
|
103
|
+
walletAddress?: string;
|
|
104
|
+
}) => X402TriggerConfig;
|
|
105
|
+
/**
|
|
106
|
+
* Create a cron (scheduled) trigger configuration.
|
|
107
|
+
* @param opts - Options for the cron trigger
|
|
108
|
+
* @param opts.schedule - Cron expression
|
|
109
|
+
* @param opts.timezone - Timezone (default: "UTC")
|
|
110
|
+
* @returns Cron trigger configuration
|
|
111
|
+
*/
|
|
112
|
+
cron: (opts: {
|
|
113
|
+
schedule: string;
|
|
114
|
+
timezone?: string;
|
|
115
|
+
}) => CronTriggerConfig;
|
|
116
|
+
/**
|
|
117
|
+
* Create a manual trigger configuration.
|
|
118
|
+
* @returns Manual trigger configuration
|
|
119
|
+
*/
|
|
120
|
+
manual: () => ManualTriggerConfig;
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* Convert an InputSchema to JSON Schema format.
|
|
124
|
+
* @param input - The input schema to convert
|
|
125
|
+
* @returns JSON Schema compliant object
|
|
126
|
+
*/
|
|
127
|
+
export declare function inputSchemaToJsonSchema(input: InputSchema): Record<string, unknown>;
|
|
128
|
+
/**
|
|
129
|
+
* Convert a trigger configuration to API props format.
|
|
130
|
+
* @param config - The trigger configuration
|
|
131
|
+
* @returns Props object for the trigger API
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```typescript
|
|
135
|
+
* const config = triggers.x402({ price: '0.01' });
|
|
136
|
+
* const props = triggerConfigToProps(config);
|
|
137
|
+
* // props = { x402Pricing: '0.01', timeout: 180 }
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
export declare function triggerConfigToProps(config: TriggerConfig): Record<string, unknown>;
|
|
141
|
+
/**
|
|
142
|
+
* API for managing workflow triggers.
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```typescript
|
|
146
|
+
* const client = new PlatformClient({ apiKey: 'your-key' });
|
|
147
|
+
*
|
|
148
|
+
* // Get integration connection ID
|
|
149
|
+
* const connId = await client.integrations.getOrCreateConnection('webhook-trigger');
|
|
150
|
+
*
|
|
151
|
+
* // Create a trigger
|
|
152
|
+
* const trigger = await client.triggers.create({
|
|
153
|
+
* workflowId: 123,
|
|
154
|
+
* name: 'My Webhook',
|
|
155
|
+
* integrationConnectionId: connId,
|
|
156
|
+
* props: { waitForCompletion: true }
|
|
157
|
+
* });
|
|
158
|
+
*
|
|
159
|
+
* // Activate the trigger
|
|
160
|
+
* await client.triggers.activate({ workflowId: 123, id: trigger.id });
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
export declare class TriggersAPI {
|
|
164
|
+
private client;
|
|
165
|
+
constructor(client: PlatformClient);
|
|
166
|
+
/**
|
|
167
|
+
* Create a new trigger in a workflow.
|
|
168
|
+
* @param params - Parameters object
|
|
169
|
+
* @param params.workflowId - The workflow ID
|
|
170
|
+
* @param params.name - Name for the trigger
|
|
171
|
+
* @param params.integrationConnectionId - Integration connection ID (e.g., from getOrCreateConnection)
|
|
172
|
+
* @param params.props - Trigger properties (use triggerConfigToProps helper)
|
|
173
|
+
* @param params.trigger_name - Optional specific trigger name
|
|
174
|
+
* @returns The created trigger
|
|
175
|
+
*/
|
|
176
|
+
create(params: {
|
|
177
|
+
workflowId: number | string;
|
|
178
|
+
name: string;
|
|
179
|
+
integrationConnectionId: string;
|
|
180
|
+
props?: Record<string, unknown>;
|
|
181
|
+
trigger_name?: string;
|
|
182
|
+
}): Promise<Trigger>;
|
|
183
|
+
/**
|
|
184
|
+
* Get a trigger by ID.
|
|
185
|
+
* @param params - Parameters object
|
|
186
|
+
* @param params.workflowId - The workflow ID
|
|
187
|
+
* @param params.id - The trigger ID
|
|
188
|
+
* @returns The trigger
|
|
189
|
+
*/
|
|
190
|
+
get(params: {
|
|
191
|
+
workflowId: number | string;
|
|
192
|
+
id: string;
|
|
193
|
+
}): Promise<Trigger>;
|
|
194
|
+
/**
|
|
195
|
+
* List all triggers in a workflow.
|
|
196
|
+
* @param params - Parameters object
|
|
197
|
+
* @param params.workflowId - The workflow ID
|
|
198
|
+
* @returns Array of triggers
|
|
199
|
+
*/
|
|
200
|
+
list(params: {
|
|
201
|
+
workflowId: number | string;
|
|
202
|
+
}): Promise<Trigger[]>;
|
|
203
|
+
/**
|
|
204
|
+
* Update an existing trigger.
|
|
205
|
+
* @param params - Parameters object
|
|
206
|
+
* @param params.workflowId - The workflow ID
|
|
207
|
+
* @param params.id - The trigger ID to update
|
|
208
|
+
* @param params.props - New properties (optional)
|
|
209
|
+
* @param params.name - New name (optional)
|
|
210
|
+
* @param params.description - New description (optional)
|
|
211
|
+
* @returns The updated trigger
|
|
212
|
+
*/
|
|
213
|
+
update(params: {
|
|
214
|
+
workflowId: number | string;
|
|
215
|
+
id: string;
|
|
216
|
+
props?: Record<string, unknown>;
|
|
217
|
+
name?: string;
|
|
218
|
+
description?: string;
|
|
219
|
+
}): Promise<Trigger>;
|
|
220
|
+
/**
|
|
221
|
+
* Delete a trigger.
|
|
222
|
+
* @param params - Parameters object
|
|
223
|
+
* @param params.workflowId - The workflow ID
|
|
224
|
+
* @param params.id - The trigger ID to delete
|
|
225
|
+
*/
|
|
226
|
+
delete(params: {
|
|
227
|
+
workflowId: number | string;
|
|
228
|
+
id: string;
|
|
229
|
+
}): Promise<void>;
|
|
230
|
+
/**
|
|
231
|
+
* Activate a trigger so it can receive events.
|
|
232
|
+
* @param params - Parameters object
|
|
233
|
+
* @param params.workflowId - The workflow ID
|
|
234
|
+
* @param params.id - The trigger ID to activate
|
|
235
|
+
*/
|
|
236
|
+
activate(params: {
|
|
237
|
+
workflowId: number | string;
|
|
238
|
+
id: string;
|
|
239
|
+
}): Promise<void>;
|
|
240
|
+
/**
|
|
241
|
+
* Fire a trigger manually (for testing or manual invocation).
|
|
242
|
+
* @param params - Parameters object
|
|
243
|
+
* @param params.workflowId - The workflow ID
|
|
244
|
+
* @param params.id - The trigger ID to fire
|
|
245
|
+
* @param params.input - Optional input data as JSON string
|
|
246
|
+
* @returns Response from the trigger
|
|
247
|
+
*/
|
|
248
|
+
fire(params: {
|
|
249
|
+
workflowId: number | string;
|
|
250
|
+
id: string;
|
|
251
|
+
input?: string;
|
|
252
|
+
}): Promise<unknown>;
|
|
253
|
+
}
|
|
254
|
+
//# sourceMappingURL=triggers-api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"triggers-api.d.ts","sourceRoot":"","sources":["../src/triggers-api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAMvC;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,OAAO,CAAC;IAC3D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,CAAC,GAAG,EAAE,MAAM,GAAG,mBAAmB,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,SAAS,CAAC;IAChB,kDAAkD;IAClD,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,gEAAgE;IAChE,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,wCAAwC;IACxC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;I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AAG,OAAO,CAAC,IAAI,CAAC;IAMjB;;;;;OAKG;IACG,QAAQ,CAAC,MAAM,EAAE;QACrB,UAAU,EAAE,MAAM,GAAG,MAAM,CAAC;QAC5B,EAAE,EAAE,MAAM,CAAC;KACZ,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBjB;;;;;;;OAOG;IACG,IAAI,CAAC,MAAM,EAAE;QACjB,UAAU,EAAE,MAAM,GAAG,MAAM,CAAC;QAC5B,EAAE,EAAE,MAAM,CAAC;QACX,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,GAAG,OAAO,CAAC,OAAO,CAAC;CAQrB"}
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TriggersAPI = exports.triggers = void 0;
|
|
4
|
+
exports.inputSchemaToJsonSchema = inputSchemaToJsonSchema;
|
|
5
|
+
exports.triggerConfigToProps = triggerConfigToProps;
|
|
6
|
+
// ============================================================================
|
|
7
|
+
// Trigger Factory Functions
|
|
8
|
+
// ============================================================================
|
|
9
|
+
/**
|
|
10
|
+
* Factory functions for creating type-safe trigger configurations.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { triggers, triggerConfigToProps } from '@openserv-labs/client';
|
|
15
|
+
*
|
|
16
|
+
* // Create a webhook trigger config
|
|
17
|
+
* const webhookConfig = triggers.webhook({
|
|
18
|
+
* input: { query: { type: 'string' } },
|
|
19
|
+
* waitForCompletion: true
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* // Convert to API props
|
|
23
|
+
* const props = triggerConfigToProps(webhookConfig);
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
exports.triggers = {
|
|
27
|
+
/**
|
|
28
|
+
* Create a webhook trigger configuration.
|
|
29
|
+
* @param opts - Options for the webhook trigger
|
|
30
|
+
* @returns Webhook trigger configuration
|
|
31
|
+
*/
|
|
32
|
+
webhook: (opts) => ({
|
|
33
|
+
type: "webhook",
|
|
34
|
+
...opts,
|
|
35
|
+
}),
|
|
36
|
+
/**
|
|
37
|
+
* Create an x402 (paid) trigger configuration.
|
|
38
|
+
* @param opts - Options for the x402 trigger
|
|
39
|
+
* @param opts.price - Price in USD (e.g., "0.01")
|
|
40
|
+
* @returns x402 trigger configuration
|
|
41
|
+
*/
|
|
42
|
+
x402: (opts) => ({
|
|
43
|
+
type: "x402",
|
|
44
|
+
...opts,
|
|
45
|
+
}),
|
|
46
|
+
/**
|
|
47
|
+
* Create a cron (scheduled) trigger configuration.
|
|
48
|
+
* @param opts - Options for the cron trigger
|
|
49
|
+
* @param opts.schedule - Cron expression
|
|
50
|
+
* @param opts.timezone - Timezone (default: "UTC")
|
|
51
|
+
* @returns Cron trigger configuration
|
|
52
|
+
*/
|
|
53
|
+
cron: (opts) => ({
|
|
54
|
+
type: "cron",
|
|
55
|
+
...opts,
|
|
56
|
+
}),
|
|
57
|
+
/**
|
|
58
|
+
* Create a manual trigger configuration.
|
|
59
|
+
* @returns Manual trigger configuration
|
|
60
|
+
*/
|
|
61
|
+
manual: () => ({
|
|
62
|
+
type: "manual",
|
|
63
|
+
}),
|
|
64
|
+
};
|
|
65
|
+
// ============================================================================
|
|
66
|
+
// Helpers
|
|
67
|
+
// ============================================================================
|
|
68
|
+
/**
|
|
69
|
+
* Convert an InputSchema to JSON Schema format.
|
|
70
|
+
* @param input - The input schema to convert
|
|
71
|
+
* @returns JSON Schema compliant object
|
|
72
|
+
*/
|
|
73
|
+
function inputSchemaToJsonSchema(input) {
|
|
74
|
+
const properties = {};
|
|
75
|
+
const required = [];
|
|
76
|
+
for (const [key, prop] of Object.entries(input)) {
|
|
77
|
+
properties[key] = {
|
|
78
|
+
type: prop.type,
|
|
79
|
+
...(prop.title && { title: prop.title }),
|
|
80
|
+
...(prop.description && { description: prop.description }),
|
|
81
|
+
...(prop.enum && { enum: prop.enum }),
|
|
82
|
+
...(prop.default !== undefined && { default: prop.default }),
|
|
83
|
+
};
|
|
84
|
+
if (prop.default === undefined) {
|
|
85
|
+
required.push(key);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
90
|
+
type: "object",
|
|
91
|
+
properties,
|
|
92
|
+
required,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Convert a trigger configuration to API props format.
|
|
97
|
+
* @param config - The trigger configuration
|
|
98
|
+
* @returns Props object for the trigger API
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```typescript
|
|
102
|
+
* const config = triggers.x402({ price: '0.01' });
|
|
103
|
+
* const props = triggerConfigToProps(config);
|
|
104
|
+
* // props = { x402Pricing: '0.01', timeout: 180 }
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
function triggerConfigToProps(config) {
|
|
108
|
+
switch (config.type) {
|
|
109
|
+
case "webhook":
|
|
110
|
+
return {
|
|
111
|
+
waitForCompletion: config.waitForCompletion ?? false,
|
|
112
|
+
timeout: config.timeout ?? 180,
|
|
113
|
+
...(config.input && {
|
|
114
|
+
inputSchema: inputSchemaToJsonSchema(config.input),
|
|
115
|
+
}),
|
|
116
|
+
};
|
|
117
|
+
case "x402":
|
|
118
|
+
return {
|
|
119
|
+
x402Pricing: config.price,
|
|
120
|
+
timeout: config.timeout ?? 180,
|
|
121
|
+
...(config.walletAddress && {
|
|
122
|
+
x402WalletAddress: config.walletAddress,
|
|
123
|
+
}),
|
|
124
|
+
...(config.input && {
|
|
125
|
+
inputSchema: inputSchemaToJsonSchema(config.input),
|
|
126
|
+
}),
|
|
127
|
+
};
|
|
128
|
+
case "cron":
|
|
129
|
+
return {
|
|
130
|
+
schedule: config.schedule,
|
|
131
|
+
timezone: config.timezone || "UTC",
|
|
132
|
+
};
|
|
133
|
+
case "manual":
|
|
134
|
+
return {};
|
|
135
|
+
default:
|
|
136
|
+
return {};
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* API for managing workflow triggers.
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```typescript
|
|
144
|
+
* const client = new PlatformClient({ apiKey: 'your-key' });
|
|
145
|
+
*
|
|
146
|
+
* // Get integration connection ID
|
|
147
|
+
* const connId = await client.integrations.getOrCreateConnection('webhook-trigger');
|
|
148
|
+
*
|
|
149
|
+
* // Create a trigger
|
|
150
|
+
* const trigger = await client.triggers.create({
|
|
151
|
+
* workflowId: 123,
|
|
152
|
+
* name: 'My Webhook',
|
|
153
|
+
* integrationConnectionId: connId,
|
|
154
|
+
* props: { waitForCompletion: true }
|
|
155
|
+
* });
|
|
156
|
+
*
|
|
157
|
+
* // Activate the trigger
|
|
158
|
+
* await client.triggers.activate({ workflowId: 123, id: trigger.id });
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
class TriggersAPI {
|
|
162
|
+
client;
|
|
163
|
+
constructor(client) {
|
|
164
|
+
this.client = client;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Create a new trigger in a workflow.
|
|
168
|
+
* @param params - Parameters object
|
|
169
|
+
* @param params.workflowId - The workflow ID
|
|
170
|
+
* @param params.name - Name for the trigger
|
|
171
|
+
* @param params.integrationConnectionId - Integration connection ID (e.g., from getOrCreateConnection)
|
|
172
|
+
* @param params.props - Trigger properties (use triggerConfigToProps helper)
|
|
173
|
+
* @param params.trigger_name - Optional specific trigger name
|
|
174
|
+
* @returns The created trigger
|
|
175
|
+
*/
|
|
176
|
+
async create(params) {
|
|
177
|
+
const { workflowId, name, integrationConnectionId, props, trigger_name } = params;
|
|
178
|
+
const data = await this.client.post(`/workspaces/${workflowId}/trigger`, {
|
|
179
|
+
name,
|
|
180
|
+
// If trigger_name not specified, server will use the integration's default
|
|
181
|
+
...(trigger_name && { trigger_name }),
|
|
182
|
+
integrationConnectionId,
|
|
183
|
+
props: props || {},
|
|
184
|
+
attributes: {},
|
|
185
|
+
});
|
|
186
|
+
if (!data.id) {
|
|
187
|
+
throw new Error(`Trigger creation returned no ID. Response: ${JSON.stringify(data)}`);
|
|
188
|
+
}
|
|
189
|
+
const triggerId = data.id;
|
|
190
|
+
// The create response may include a token; capture it if present
|
|
191
|
+
const createToken = data.token;
|
|
192
|
+
// The single trigger GET endpoint doesn't include token,
|
|
193
|
+
// so fetch from list (workspace response) which includes it
|
|
194
|
+
const triggersList = await this.list({ workflowId });
|
|
195
|
+
const triggerFromList = triggersList.find((t) => t.id === triggerId);
|
|
196
|
+
if (triggerFromList) {
|
|
197
|
+
return triggerFromList;
|
|
198
|
+
}
|
|
199
|
+
// Fallback to get endpoint if not found in list (shouldn't happen)
|
|
200
|
+
const triggerDetails = await this.get({ workflowId, id: triggerId });
|
|
201
|
+
return {
|
|
202
|
+
...triggerDetails,
|
|
203
|
+
id: triggerId,
|
|
204
|
+
token: createToken,
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Get a trigger by ID.
|
|
209
|
+
* @param params - Parameters object
|
|
210
|
+
* @param params.workflowId - The workflow ID
|
|
211
|
+
* @param params.id - The trigger ID
|
|
212
|
+
* @returns The trigger
|
|
213
|
+
*/
|
|
214
|
+
async get(params) {
|
|
215
|
+
const data = await this.client.get(`/workspaces/${params.workflowId}/triggers/${params.id}`);
|
|
216
|
+
// The single trigger GET endpoint doesn't return the ID in the response,
|
|
217
|
+
// so we include it from the request parameters
|
|
218
|
+
return {
|
|
219
|
+
...data,
|
|
220
|
+
id: params.id,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* List all triggers in a workflow.
|
|
225
|
+
* @param params - Parameters object
|
|
226
|
+
* @param params.workflowId - The workflow ID
|
|
227
|
+
* @returns Array of triggers
|
|
228
|
+
*/
|
|
229
|
+
async list(params) {
|
|
230
|
+
// The list endpoint returns available integrations, not actual trigger instances
|
|
231
|
+
// To get actual triggers, we need to fetch from the workspace get endpoint
|
|
232
|
+
const workspace = await this.client.get(`/workspaces/${params.workflowId}`);
|
|
233
|
+
// The workspace response includes triggers with the full structure
|
|
234
|
+
const triggers = workspace.triggers || [];
|
|
235
|
+
// Map to Trigger type - token is in attributes.uiState.token
|
|
236
|
+
return triggers.map((t) => ({
|
|
237
|
+
id: t.id,
|
|
238
|
+
name: t.name,
|
|
239
|
+
description: t.description || undefined,
|
|
240
|
+
integrationConnectionId: t.integrationConnection?.id || "",
|
|
241
|
+
props: t.props,
|
|
242
|
+
token: t.attributes?.uiState?.token,
|
|
243
|
+
isActive: t.is_active,
|
|
244
|
+
state: t.state,
|
|
245
|
+
}));
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Update an existing trigger.
|
|
249
|
+
* @param params - Parameters object
|
|
250
|
+
* @param params.workflowId - The workflow ID
|
|
251
|
+
* @param params.id - The trigger ID to update
|
|
252
|
+
* @param params.props - New properties (optional)
|
|
253
|
+
* @param params.name - New name (optional)
|
|
254
|
+
* @param params.description - New description (optional)
|
|
255
|
+
* @returns The updated trigger
|
|
256
|
+
*/
|
|
257
|
+
async update(params) {
|
|
258
|
+
const { workflowId, id, props, name, description } = params;
|
|
259
|
+
// First get the current trigger to preserve required fields
|
|
260
|
+
const currentTrigger = await this.get({ workflowId, id });
|
|
261
|
+
return this.client.put(`/workspaces/${workflowId}/triggers/${id}`, {
|
|
262
|
+
name: name ?? currentTrigger.name,
|
|
263
|
+
description: description ?? currentTrigger.description ?? currentTrigger.name,
|
|
264
|
+
integrationConnectionId: currentTrigger.integrationConnectionId,
|
|
265
|
+
props: props ?? currentTrigger.props,
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Delete a trigger.
|
|
270
|
+
* @param params - Parameters object
|
|
271
|
+
* @param params.workflowId - The workflow ID
|
|
272
|
+
* @param params.id - The trigger ID to delete
|
|
273
|
+
*/
|
|
274
|
+
async delete(params) {
|
|
275
|
+
await this.client.delete(`/workspaces/${params.workflowId}/triggers/${params.id}`);
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Activate a trigger so it can receive events.
|
|
279
|
+
* @param params - Parameters object
|
|
280
|
+
* @param params.workflowId - The workflow ID
|
|
281
|
+
* @param params.id - The trigger ID to activate
|
|
282
|
+
*/
|
|
283
|
+
async activate(params) {
|
|
284
|
+
const currentTrigger = await this.get({
|
|
285
|
+
workflowId: params.workflowId,
|
|
286
|
+
id: params.id,
|
|
287
|
+
});
|
|
288
|
+
await this.client.put(`/workspaces/${params.workflowId}/triggers/${params.id}`, {
|
|
289
|
+
name: currentTrigger.name,
|
|
290
|
+
integrationConnectionId: currentTrigger.integrationConnectionId,
|
|
291
|
+
props: currentTrigger.props,
|
|
292
|
+
is_active: true,
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Fire a trigger manually (for testing or manual invocation).
|
|
297
|
+
* @param params - Parameters object
|
|
298
|
+
* @param params.workflowId - The workflow ID
|
|
299
|
+
* @param params.id - The trigger ID to fire
|
|
300
|
+
* @param params.input - Optional input data as JSON string
|
|
301
|
+
* @returns Response from the trigger
|
|
302
|
+
*/
|
|
303
|
+
async fire(params) {
|
|
304
|
+
return this.client.put(`/workspaces/${params.workflowId}/triggers/${params.id}/trigger`, {
|
|
305
|
+
input: params.input || "",
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
exports.TriggersAPI = TriggersAPI;
|