@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.
@@ -0,0 +1,219 @@
1
+ export interface Agent {
2
+ id: number;
3
+ name: string;
4
+ capabilities_description: string;
5
+ endpoint_url: string;
6
+ approval_status: string;
7
+ is_listed_on_marketplace: boolean;
8
+ is_trading_agent: boolean;
9
+ scopes: Record<string, unknown> | string[];
10
+ }
11
+ export interface Category {
12
+ id: number;
13
+ name: string;
14
+ description?: string | null;
15
+ }
16
+ export interface MarketplaceAgent {
17
+ id: number;
18
+ name: string;
19
+ capabilities_description: string;
20
+ avatar_url?: string | null;
21
+ author_name: string;
22
+ approval_status: "approved" | "rejected" | "pending" | "in-development";
23
+ scopes: Record<string, unknown>;
24
+ isOwner?: boolean | null;
25
+ categories: Category[];
26
+ kind: "openserv" | "external";
27
+ isBuiltByAgentBuilder: boolean;
28
+ is_trading_agent: boolean;
29
+ }
30
+ export interface MarketplaceAgentsResponse {
31
+ items: MarketplaceAgent[];
32
+ total: number;
33
+ page: number;
34
+ pageSize: number;
35
+ totalPages: number;
36
+ hasPrivateAgents: boolean;
37
+ }
38
+ export interface PaginatedResponse<T> {
39
+ items: T[];
40
+ }
41
+ export interface IdResponse {
42
+ id: number;
43
+ }
44
+ export interface ApiKeyResponse {
45
+ apiKey: string;
46
+ }
47
+ export interface AuthTokenResponse {
48
+ authToken: string;
49
+ authTokenHash: string;
50
+ }
51
+ export interface NonceResponse {
52
+ nonce: string;
53
+ message?: string;
54
+ }
55
+ export interface VerifyResponse {
56
+ success: boolean;
57
+ apiKey: string;
58
+ }
59
+ export interface TriggerDefinition {
60
+ id?: string;
61
+ name: string;
62
+ type?: "x402" | "webhook" | "cron" | "manual";
63
+ integrationConnectionId?: string;
64
+ props?: Record<string, unknown>;
65
+ }
66
+ export interface TaskDefinition {
67
+ id?: number;
68
+ name: string;
69
+ agentId: number | string;
70
+ description: string;
71
+ body?: string;
72
+ input?: string;
73
+ dependencies?: string[];
74
+ }
75
+ export interface EdgeDefinition {
76
+ from: string;
77
+ to: string;
78
+ }
79
+ export interface WorkflowConfig {
80
+ name: string;
81
+ goal?: string;
82
+ agentIds: (number | string)[];
83
+ triggers?: TriggerDefinition[];
84
+ tasks?: TaskDefinition[];
85
+ edges?: EdgeDefinition[];
86
+ }
87
+ export interface Trigger {
88
+ id: string;
89
+ name: string;
90
+ description?: string;
91
+ integrationConnectionId: string;
92
+ props: Record<string, unknown>;
93
+ url?: string;
94
+ webhookUrl?: string;
95
+ token?: string;
96
+ isActive?: boolean;
97
+ state?: string;
98
+ }
99
+ export interface Task {
100
+ id: number;
101
+ name?: string;
102
+ description: string;
103
+ assigneeAgentId: number;
104
+ body?: string;
105
+ status: string;
106
+ dependencies: Array<{
107
+ dependency_task_id: number;
108
+ } | number>;
109
+ }
110
+ export interface Edge {
111
+ from: {
112
+ type: string;
113
+ id: string | number;
114
+ };
115
+ to: {
116
+ type: string;
117
+ id: string | number;
118
+ };
119
+ }
120
+ export interface WorkflowData {
121
+ id: number;
122
+ name: string;
123
+ goal: string;
124
+ status: string;
125
+ triggers: Trigger[];
126
+ tasks: Task[];
127
+ edges: Edge[];
128
+ agents: Agent[];
129
+ }
130
+ /**
131
+ * Configuration for USDC top-up payments.
132
+ * Returned by the platform to enable wallet-based credit purchases.
133
+ */
134
+ export interface UsdcTopupConfig {
135
+ /** Address that receives USDC payments */
136
+ receiverAddress: string;
137
+ /** USDC token contract address on the target chain */
138
+ usdcContractAddress: string;
139
+ /** Chain ID (e.g., 8453 for Base) */
140
+ chainId: number;
141
+ /** Human-readable network name (e.g., "base") */
142
+ network: string;
143
+ /** Conversion rate: USDC to credits (1 USDC = 1 USD = 100_000_000 credits) */
144
+ rateUsdcToCredits: number;
145
+ }
146
+ /**
147
+ * Request to verify a USDC top-up transaction.
148
+ */
149
+ export interface UsdcVerifyRequest {
150
+ /** The transaction hash of the USDC transfer */
151
+ txHash: string;
152
+ /**
153
+ * For non-wallet users: the address that sent the USDC.
154
+ * Required when the user is authenticated via email/Google rather than wallet.
155
+ */
156
+ payerAddress?: string;
157
+ /**
158
+ * For non-wallet users: signature proving ownership of the sending wallet.
159
+ * The signature should be over the message: "Verify USDC top-up: {txHash}"
160
+ */
161
+ signature?: string;
162
+ }
163
+ /**
164
+ * Response from verifying a USDC top-up transaction.
165
+ */
166
+ export interface UsdcVerifyResponse {
167
+ /** Whether the verification was successful */
168
+ success: boolean;
169
+ /** Number of credits added to the user's wallet */
170
+ creditsAdded: number;
171
+ /** Original USDC amount as a string (with decimals) */
172
+ usdcAmount: string;
173
+ }
174
+ /**
175
+ * Result from the high-level topUp method.
176
+ */
177
+ export interface UsdcTopupResult {
178
+ /** Whether the top-up was successful */
179
+ success: boolean;
180
+ /** The transaction hash of the USDC transfer */
181
+ txHash: string;
182
+ /** Number of credits added to the user's wallet */
183
+ creditsAdded: number;
184
+ /** USDC amount transferred (with decimals) */
185
+ usdcAmount: string;
186
+ /** Network where the transaction was sent */
187
+ network: string;
188
+ /** Chain ID of the network */
189
+ chainId: number;
190
+ }
191
+ /**
192
+ * Request parameters for paying and executing an x402 workflow.
193
+ */
194
+ export interface X402PaymentRequest {
195
+ /** The x402 trigger URL to pay for (webhookUrl from discoverServices or trigger.webhookUrl) */
196
+ triggerUrl: string;
197
+ /** Wallet private key for payment (or uses WALLET_PRIVATE_KEY env var) */
198
+ privateKey?: string;
199
+ /** Input data to pass to the workflow */
200
+ input?: Record<string, unknown>;
201
+ }
202
+ /**
203
+ * Result from paying and executing an x402 workflow.
204
+ */
205
+ export interface X402PaymentResult {
206
+ /** Whether the payment and execution were successful */
207
+ success: boolean;
208
+ /** The payment transaction hash (may be empty - x402 handles internally) */
209
+ txHash: string;
210
+ /** The price paid in USD (may be empty - x402 handles internally) */
211
+ price: string;
212
+ /** The workflow response data */
213
+ response: unknown;
214
+ /** Network where the payment was made */
215
+ network: string;
216
+ /** Chain ID of the network */
217
+ chainId: number;
218
+ }
219
+ //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MAAM,WAAW,kBAAkB;IACjC,+FAA+F;IAC/F,UAAU,EAAE,MAAM,CAAC;IACnB,0EAA0E;IAC1E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,yCAAyC;IACzC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,wDAAwD;IACxD,OAAO,EAAE,OAAO,CAAC;IACjB,4EAA4E;IAC5E,MAAM,EAAE,MAAM,CAAC;IACf,qEAAqE;IACrE,KAAK,EAAE,MAAM,CAAC;IACd,iCAAiC;IACjC,QAAQ,EAAE,OAAO,CAAC;IAClB,yCAAyC;IACzC,OAAO,EAAE,MAAM,CAAC;IAChB,8BAA8B;IAC9B,OAAO,EAAE,MAAM,CAAC;CACjB"}
package/dist/types.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ // ============================================================================
3
+ // API Response Types (raw platform responses)
4
+ // ============================================================================
5
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,117 @@
1
+ import type { PlatformClient } from "./client";
2
+ import type { UsdcTopupConfig, UsdcTopupResult, UsdcVerifyRequest, UsdcVerifyResponse } from "./types";
3
+ /**
4
+ * API for Web3 operations including USDC top-up for credits.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * const client = new PlatformClient();
9
+ *
10
+ * // Simple one-liner to top up with USDC - auto-authenticates with wallet
11
+ * const result = await client.web3.topUp({
12
+ * privateKey: process.env.WALLET_PRIVATE_KEY,
13
+ * amountUsd: 10 // $10 worth of USDC
14
+ * });
15
+ * console.log(`Added ${result.creditsAdded} credits`);
16
+ *
17
+ * // Or use the lower-level methods for more control
18
+ * const config = await client.web3.getUsdcTopupConfig();
19
+ * // ... send USDC manually ...
20
+ * const verifyResult = await client.web3.verifyUsdcTransaction({ txHash: '0x...' });
21
+ * ```
22
+ */
23
+ export declare class Web3API {
24
+ private client;
25
+ constructor(client: PlatformClient);
26
+ /**
27
+ * Get the configuration for USDC top-up payments.
28
+ *
29
+ * Returns the receiver address, USDC contract address, chain ID, and conversion rate
30
+ * needed to send a USDC payment for credit top-up.
31
+ *
32
+ * @returns USDC top-up configuration
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * const config = await client.web3.getUsdcTopupConfig();
37
+ * // config.receiverAddress - Address to send USDC to
38
+ * // config.usdcContractAddress - USDC token contract
39
+ * // config.chainId - Target chain (e.g., 8453 for Base)
40
+ * // config.network - Network name (e.g., "base")
41
+ * // config.rateUsdcToCredits - 1 USDC = 100_000_000 credits
42
+ * ```
43
+ */
44
+ getUsdcTopupConfig(): Promise<UsdcTopupConfig>;
45
+ /**
46
+ * Verify a USDC transaction and add credits to the user's wallet.
47
+ *
48
+ * After sending USDC to the receiver address, call this method with the
49
+ * transaction hash to verify the payment and receive credits.
50
+ *
51
+ * For wallet-authenticated users, the sender address is verified automatically.
52
+ * For email/Google-authenticated users, you must provide a signature proving
53
+ * ownership of the sending wallet.
54
+ *
55
+ * @param params - Verification parameters
56
+ * @param params.txHash - The transaction hash of the USDC transfer
57
+ * @param params.payerAddress - (Optional) For non-wallet users: the address that sent the USDC
58
+ * @param params.signature - (Optional) For non-wallet users: signature over "Verify USDC top-up: {txHash}"
59
+ * @returns Verification result with credits added
60
+ *
61
+ * @example
62
+ * ```typescript
63
+ * // For wallet-authenticated users
64
+ * const result = await client.web3.verifyUsdcTransaction({
65
+ * txHash: '0xabc123...'
66
+ * });
67
+ *
68
+ * // For email/Google-authenticated users
69
+ * const message = `Verify USDC top-up: ${txHash}`;
70
+ * const signature = await wallet.signMessage(message);
71
+ * const result = await client.web3.verifyUsdcTransaction({
72
+ * txHash: '0xabc123...',
73
+ * payerAddress: '0xYourWallet...',
74
+ * signature
75
+ * });
76
+ *
77
+ * console.log(`Added ${result.creditsAdded} credits (${result.usdcAmount} USDC)`);
78
+ * ```
79
+ */
80
+ verifyUsdcTransaction(params: UsdcVerifyRequest): Promise<UsdcVerifyResponse>;
81
+ /**
82
+ * Top up credits by sending USDC from your wallet.
83
+ *
84
+ * This is a high-level method that handles the entire flow:
85
+ * 1. Auto-authenticates with wallet if no API key is set
86
+ * 2. Fetches the USDC top-up configuration
87
+ * 3. Sends USDC from your wallet to the receiver
88
+ * 4. Waits for transaction confirmation
89
+ * 5. Signs a verification message
90
+ * 6. Verifies the transaction and adds credits
91
+ *
92
+ * @param params - Top-up parameters
93
+ * @param params.privateKey - Wallet private key (or uses WALLET_PRIVATE_KEY env var)
94
+ * @param params.amountUsd - Amount in USD to top up (e.g., 10 for $10)
95
+ * @param params.rpcUrl - (Optional) Custom RPC URL for the chain
96
+ * @returns Top-up result with credits added and transaction details
97
+ *
98
+ * @example
99
+ * ```typescript
100
+ * // Top up $10 worth of credits - only wallet key needed!
101
+ * const result = await client.web3.topUp({
102
+ * privateKey: process.env.WALLET_PRIVATE_KEY,
103
+ * amountUsd: 10
104
+ * });
105
+ *
106
+ * console.log(`Transaction: ${result.txHash}`);
107
+ * console.log(`Added ${result.creditsAdded} credits`);
108
+ * console.log(`USDC spent: ${result.usdcAmount}`);
109
+ * ```
110
+ */
111
+ topUp(params: {
112
+ privateKey?: string;
113
+ amountUsd: number;
114
+ rpcUrl?: string;
115
+ }): Promise<UsdcTopupResult>;
116
+ }
117
+ //# sourceMappingURL=web3-api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web3-api.d.ts","sourceRoot":"","sources":["../src/web3-api.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,KAAK,EACV,eAAe,EACf,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,SAAS,CAAC;AAajB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,OAAO;IACN,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,cAAc;IAE1C;;;;;;;;;;;;;;;;;OAiBG;IACG,kBAAkB,IAAI,OAAO,CAAC,eAAe,CAAC;IAIpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;IACG,qBAAqB,CACzB,MAAM,EAAE,iBAAiB,GACxB,OAAO,CAAC,kBAAkB,CAAC;IAO9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACG,KAAK,CAAC,MAAM,EAAE;QAClB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,SAAS,EAAE,MAAM,CAAC;QAClB,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,GAAG,OAAO,CAAC,eAAe,CAAC;CAyF7B"}
@@ -0,0 +1,185 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Web3API = void 0;
4
+ const ethers_1 = require("ethers");
5
+ // ERC20 Transfer ABI (minimal)
6
+ const ERC20_ABI = [
7
+ "function transfer(address to, uint256 amount) returns (bool)",
8
+ "function balanceOf(address owner) view returns (uint256)",
9
+ ];
10
+ // Known RPC URLs for supported chains
11
+ const CHAIN_RPC_URLS = {
12
+ 8453: "https://mainnet.base.org", // Base mainnet
13
+ };
14
+ /**
15
+ * API for Web3 operations including USDC top-up for credits.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const client = new PlatformClient();
20
+ *
21
+ * // Simple one-liner to top up with USDC - auto-authenticates with wallet
22
+ * const result = await client.web3.topUp({
23
+ * privateKey: process.env.WALLET_PRIVATE_KEY,
24
+ * amountUsd: 10 // $10 worth of USDC
25
+ * });
26
+ * console.log(`Added ${result.creditsAdded} credits`);
27
+ *
28
+ * // Or use the lower-level methods for more control
29
+ * const config = await client.web3.getUsdcTopupConfig();
30
+ * // ... send USDC manually ...
31
+ * const verifyResult = await client.web3.verifyUsdcTransaction({ txHash: '0x...' });
32
+ * ```
33
+ */
34
+ class Web3API {
35
+ client;
36
+ constructor(client) {
37
+ this.client = client;
38
+ }
39
+ /**
40
+ * Get the configuration for USDC top-up payments.
41
+ *
42
+ * Returns the receiver address, USDC contract address, chain ID, and conversion rate
43
+ * needed to send a USDC payment for credit top-up.
44
+ *
45
+ * @returns USDC top-up configuration
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * const config = await client.web3.getUsdcTopupConfig();
50
+ * // config.receiverAddress - Address to send USDC to
51
+ * // config.usdcContractAddress - USDC token contract
52
+ * // config.chainId - Target chain (e.g., 8453 for Base)
53
+ * // config.network - Network name (e.g., "base")
54
+ * // config.rateUsdcToCredits - 1 USDC = 100_000_000 credits
55
+ * ```
56
+ */
57
+ async getUsdcTopupConfig() {
58
+ return this.client.get("/config/topup/usdc");
59
+ }
60
+ /**
61
+ * Verify a USDC transaction and add credits to the user's wallet.
62
+ *
63
+ * After sending USDC to the receiver address, call this method with the
64
+ * transaction hash to verify the payment and receive credits.
65
+ *
66
+ * For wallet-authenticated users, the sender address is verified automatically.
67
+ * For email/Google-authenticated users, you must provide a signature proving
68
+ * ownership of the sending wallet.
69
+ *
70
+ * @param params - Verification parameters
71
+ * @param params.txHash - The transaction hash of the USDC transfer
72
+ * @param params.payerAddress - (Optional) For non-wallet users: the address that sent the USDC
73
+ * @param params.signature - (Optional) For non-wallet users: signature over "Verify USDC top-up: {txHash}"
74
+ * @returns Verification result with credits added
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * // For wallet-authenticated users
79
+ * const result = await client.web3.verifyUsdcTransaction({
80
+ * txHash: '0xabc123...'
81
+ * });
82
+ *
83
+ * // For email/Google-authenticated users
84
+ * const message = `Verify USDC top-up: ${txHash}`;
85
+ * const signature = await wallet.signMessage(message);
86
+ * const result = await client.web3.verifyUsdcTransaction({
87
+ * txHash: '0xabc123...',
88
+ * payerAddress: '0xYourWallet...',
89
+ * signature
90
+ * });
91
+ *
92
+ * console.log(`Added ${result.creditsAdded} credits (${result.usdcAmount} USDC)`);
93
+ * ```
94
+ */
95
+ async verifyUsdcTransaction(params) {
96
+ return this.client.post("/web3/transactions/usdc/verify", params);
97
+ }
98
+ /**
99
+ * Top up credits by sending USDC from your wallet.
100
+ *
101
+ * This is a high-level method that handles the entire flow:
102
+ * 1. Auto-authenticates with wallet if no API key is set
103
+ * 2. Fetches the USDC top-up configuration
104
+ * 3. Sends USDC from your wallet to the receiver
105
+ * 4. Waits for transaction confirmation
106
+ * 5. Signs a verification message
107
+ * 6. Verifies the transaction and adds credits
108
+ *
109
+ * @param params - Top-up parameters
110
+ * @param params.privateKey - Wallet private key (or uses WALLET_PRIVATE_KEY env var)
111
+ * @param params.amountUsd - Amount in USD to top up (e.g., 10 for $10)
112
+ * @param params.rpcUrl - (Optional) Custom RPC URL for the chain
113
+ * @returns Top-up result with credits added and transaction details
114
+ *
115
+ * @example
116
+ * ```typescript
117
+ * // Top up $10 worth of credits - only wallet key needed!
118
+ * const result = await client.web3.topUp({
119
+ * privateKey: process.env.WALLET_PRIVATE_KEY,
120
+ * amountUsd: 10
121
+ * });
122
+ *
123
+ * console.log(`Transaction: ${result.txHash}`);
124
+ * console.log(`Added ${result.creditsAdded} credits`);
125
+ * console.log(`USDC spent: ${result.usdcAmount}`);
126
+ * ```
127
+ */
128
+ async topUp(params) {
129
+ const privateKey = params.privateKey || process.env.WALLET_PRIVATE_KEY;
130
+ if (!privateKey) {
131
+ throw new Error("Private key is required. Provide it as a parameter or set WALLET_PRIVATE_KEY env var.");
132
+ }
133
+ if (params.amountUsd <= 0) {
134
+ throw new Error("Amount must be greater than 0");
135
+ }
136
+ // Step 0: Auto-authenticate with wallet if no API key is set
137
+ if (!this.client.rawClient.defaults.headers.common["x-openserv-key"]) {
138
+ await this.client.authenticate(privateKey);
139
+ }
140
+ // Step 1: Get USDC top-up configuration
141
+ const config = await this.getUsdcTopupConfig();
142
+ // Get RPC URL for the chain
143
+ const rpcUrl = params.rpcUrl ||
144
+ CHAIN_RPC_URLS[config.chainId] ||
145
+ `https://rpc.ankr.com/${config.network}`;
146
+ // Step 2: Create wallet and connect to the chain
147
+ const provider = new ethers_1.ethers.JsonRpcProvider(rpcUrl);
148
+ const wallet = new ethers_1.ethers.Wallet(privateKey, provider);
149
+ // Step 3: Check USDC balance
150
+ const usdcContract = new ethers_1.ethers.Contract(config.usdcContractAddress, ERC20_ABI, wallet);
151
+ // USDC has 6 decimals
152
+ const amountInSmallestUnit = ethers_1.ethers.parseUnits(params.amountUsd.toString(), 6);
153
+ const balance = await usdcContract.getFunction("balanceOf")(wallet.address);
154
+ if (balance < amountInSmallestUnit) {
155
+ const balanceFormatted = ethers_1.ethers.formatUnits(balance, 6);
156
+ throw new Error(`Insufficient USDC balance. Have: ${balanceFormatted} USDC, need: ${params.amountUsd} USDC`);
157
+ }
158
+ // Step 4: Send USDC transfer
159
+ const tx = await usdcContract.getFunction("transfer")(config.receiverAddress, amountInSmallestUnit);
160
+ // Step 5: Wait for confirmation
161
+ const receipt = await tx.wait();
162
+ if (!receipt || receipt.status !== 1) {
163
+ throw new Error("Transaction failed or was reverted");
164
+ }
165
+ const txHash = receipt.hash;
166
+ // Step 6: Sign verification message
167
+ const verificationMessage = `Verify USDC top-up: ${txHash}`;
168
+ const signature = await wallet.signMessage(verificationMessage);
169
+ // Step 7: Verify transaction and add credits
170
+ const verifyResult = await this.verifyUsdcTransaction({
171
+ txHash,
172
+ payerAddress: wallet.address,
173
+ signature,
174
+ });
175
+ return {
176
+ success: verifyResult.success,
177
+ txHash,
178
+ creditsAdded: verifyResult.creditsAdded,
179
+ usdcAmount: verifyResult.usdcAmount,
180
+ network: config.network,
181
+ chainId: config.chainId,
182
+ };
183
+ }
184
+ }
185
+ exports.Web3API = Web3API;
@@ -0,0 +1,27 @@
1
+ import type { PlatformClient } from "./client";
2
+ import type { TriggerDefinition, TaskDefinition, EdgeDefinition, WorkflowData, Trigger, Task, Edge, Agent } from "./types";
3
+ export declare class Workflow {
4
+ readonly id: number;
5
+ readonly name: string;
6
+ readonly goal: string;
7
+ status: string;
8
+ triggers: Trigger[];
9
+ tasks: Task[];
10
+ edges: Edge[];
11
+ agents: Agent[];
12
+ private client;
13
+ constructor(data: WorkflowData, client: PlatformClient);
14
+ /**
15
+ * Sync the workflow with a new configuration (declarative update)
16
+ */
17
+ sync(config: {
18
+ triggers?: TriggerDefinition[];
19
+ tasks?: TaskDefinition[];
20
+ edges?: EdgeDefinition[];
21
+ }): Promise<void>;
22
+ /**
23
+ * Set the workflow to running state
24
+ */
25
+ setRunning(): Promise<void>;
26
+ }
27
+ //# sourceMappingURL=workflow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow.d.ts","sourceRoot":"","sources":["../src/workflow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,KAAK,EACV,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,YAAY,EACZ,OAAO,EACP,IAAI,EACJ,IAAI,EACJ,KAAK,EACN,MAAM,SAAS,CAAC;AAEjB,qBAAa,QAAQ;IACnB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,MAAM,EAAE,KAAK,EAAE,CAAC;IAEhB,OAAO,CAAC,MAAM,CAAiB;gBAEnB,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,cAAc;IAYtD;;OAEG;IACG,IAAI,CAAC,MAAM,EAAE;QACjB,QAAQ,CAAC,EAAE,iBAAiB,EAAE,CAAC;QAC/B,KAAK,CAAC,EAAE,cAAc,EAAE,CAAC;QACzB,KAAK,CAAC,EAAE,cAAc,EAAE,CAAC;KAC1B,GAAG,OAAO,CAAC,IAAI,CAAC;IAgBjB;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;CAIlC"}
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Workflow = void 0;
4
+ class Workflow {
5
+ id;
6
+ name;
7
+ goal;
8
+ status;
9
+ triggers;
10
+ tasks;
11
+ edges;
12
+ agents;
13
+ client;
14
+ constructor(data, client) {
15
+ this.id = data.id;
16
+ this.name = data.name;
17
+ this.goal = data.goal;
18
+ this.status = data.status;
19
+ this.triggers = data.triggers;
20
+ this.tasks = data.tasks;
21
+ this.edges = data.edges;
22
+ this.agents = data.agents;
23
+ this.client = client;
24
+ }
25
+ /**
26
+ * Sync the workflow with a new configuration (declarative update)
27
+ */
28
+ async sync(config) {
29
+ await this.client.workflows.sync({
30
+ id: this.id,
31
+ triggers: config.triggers,
32
+ tasks: config.tasks,
33
+ edges: config.edges,
34
+ });
35
+ // Refresh local state
36
+ const updated = await this.client.workflows.get({ id: this.id });
37
+ this.triggers = updated.triggers;
38
+ this.tasks = updated.tasks;
39
+ this.edges = updated.edges;
40
+ this.status = updated.status;
41
+ }
42
+ /**
43
+ * Set the workflow to running state
44
+ */
45
+ async setRunning() {
46
+ await this.client.workflows.setRunning({ id: this.id });
47
+ this.status = "running";
48
+ }
49
+ }
50
+ exports.Workflow = Workflow;