@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 OpenServ Labs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,646 @@
|
|
|
1
|
+
# OpenServ Platform Client
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@openserv-labs/client)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
[](https://www.typescriptlang.org/)
|
|
6
|
+
|
|
7
|
+
A TypeScript client for interacting with the OpenServ Platform API. Manage agents, workflows, tasks, and triggers programmatically.
|
|
8
|
+
|
|
9
|
+
> **Note**: This is the platform client for API operations. If you want to build AI agents, see [@openserv-labs/sdk](https://github.com/openserv-labs/sdk).
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @openserv-labs/client
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { PlatformClient } from '@openserv-labs/client'
|
|
21
|
+
|
|
22
|
+
const client = new PlatformClient({
|
|
23
|
+
apiKey: process.env.OPENSERV_USER_API_KEY
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
// List all agents
|
|
27
|
+
const agents = await client.agents.list()
|
|
28
|
+
|
|
29
|
+
// Create a workflow
|
|
30
|
+
const workflow = await client.workflows.create({
|
|
31
|
+
name: 'My Workflow',
|
|
32
|
+
goal: 'Process data automatically',
|
|
33
|
+
agentIds: [123, 456]
|
|
34
|
+
})
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Authentication
|
|
38
|
+
|
|
39
|
+
### API Key Authentication
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
const client = new PlatformClient({
|
|
43
|
+
apiKey: 'your-api-key'
|
|
44
|
+
})
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Or set the `OPENSERV_USER_API_KEY` environment variable:
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
const client = new PlatformClient() // Uses OPENSERV_USER_API_KEY env var
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Wallet Authentication (SIWE)
|
|
54
|
+
|
|
55
|
+
Authenticate using an Ethereum wallet (EIP-4361):
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
const client = new PlatformClient()
|
|
59
|
+
const apiKey = await client.authenticate(process.env.WALLET_PRIVATE_KEY)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## API Reference
|
|
63
|
+
|
|
64
|
+
### Agents
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
// List all agents
|
|
68
|
+
const agents = await client.agents.list()
|
|
69
|
+
|
|
70
|
+
// Get agent by ID
|
|
71
|
+
const agent = await client.agents.get({ id: 123 })
|
|
72
|
+
|
|
73
|
+
// Search your own agents by name/description
|
|
74
|
+
const myAgents = await client.agents.searchOwned({ query: 'my-agent' })
|
|
75
|
+
|
|
76
|
+
// Search all marketplace agents (semantic search)
|
|
77
|
+
const marketplaceResults = await client.agents.listMarketplace({ search: 'data processing' })
|
|
78
|
+
|
|
79
|
+
// Create an agent
|
|
80
|
+
// endpoint_url is optional when using @openserv-labs/sdk v2.0.0+ (auto-set by run())
|
|
81
|
+
const agent = await client.agents.create({
|
|
82
|
+
name: 'My Agent',
|
|
83
|
+
capabilities_description: 'Agent capabilities description',
|
|
84
|
+
endpoint_url: 'https://my-agent.example.com' // Optional for dev, required for production
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
// Update an agent
|
|
88
|
+
await client.agents.update({
|
|
89
|
+
id: 123,
|
|
90
|
+
name: 'Updated Name',
|
|
91
|
+
capabilities_description: 'Updated description',
|
|
92
|
+
endpoint_url: 'https://new-endpoint.example.com' // Only if changing the endpoint
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
// Delete an agent
|
|
96
|
+
await client.agents.delete({ id: 123 })
|
|
97
|
+
|
|
98
|
+
// Get agent API key
|
|
99
|
+
const apiKey = await client.agents.getApiKey({ id: 123 })
|
|
100
|
+
|
|
101
|
+
// Generate and save auth token for agent security
|
|
102
|
+
const { authToken, authTokenHash } = await client.agents.generateAuthToken()
|
|
103
|
+
await client.agents.saveAuthToken({ id: 123, authTokenHash })
|
|
104
|
+
|
|
105
|
+
// List marketplace agents (public agents from other developers)
|
|
106
|
+
const marketplace = await client.agents.listMarketplace({
|
|
107
|
+
search: 'data processing', // Optional search query
|
|
108
|
+
page: 1,
|
|
109
|
+
pageSize: 20,
|
|
110
|
+
showPrivateAgents: true // Include your own private agents
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
console.log(`Found ${marketplace.total} agents`)
|
|
114
|
+
for (const agent of marketplace.items) {
|
|
115
|
+
console.log(`${agent.name} by ${agent.author_name}`)
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Workflows
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
// Create a workflow
|
|
123
|
+
const workflow = await client.workflows.create({
|
|
124
|
+
name: 'Data Pipeline',
|
|
125
|
+
goal: 'Process and analyze data',
|
|
126
|
+
agentIds: [123, 456]
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
// Get a workflow
|
|
130
|
+
const workflow = await client.workflows.get({ id: 789 })
|
|
131
|
+
|
|
132
|
+
// List all workflows
|
|
133
|
+
const workflows = await client.workflows.list()
|
|
134
|
+
|
|
135
|
+
// Update a workflow
|
|
136
|
+
await client.workflows.update({
|
|
137
|
+
id: 789,
|
|
138
|
+
name: 'Updated Pipeline',
|
|
139
|
+
goal: 'New goal'
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
// Delete a workflow
|
|
143
|
+
await client.workflows.delete({ id: 789 })
|
|
144
|
+
|
|
145
|
+
// Set workflow to running state
|
|
146
|
+
await client.workflows.setRunning({ id: 789 })
|
|
147
|
+
|
|
148
|
+
// Sync workflow configuration
|
|
149
|
+
await client.workflows.sync({
|
|
150
|
+
id: 789,
|
|
151
|
+
triggers: [{ name: 'webhook', type: 'webhook' }],
|
|
152
|
+
tasks: [{ name: 'process', agentId: 123, description: 'Process data' }],
|
|
153
|
+
edges: [{ from: 'trigger:webhook', to: 'task:process' }]
|
|
154
|
+
})
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### Tasks
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
// Create a task
|
|
161
|
+
const task = await client.tasks.create({
|
|
162
|
+
workflowId: 789,
|
|
163
|
+
agentId: 123,
|
|
164
|
+
description: 'Process the data',
|
|
165
|
+
body: 'Additional task details',
|
|
166
|
+
dependencies: [456] // Optional task dependencies
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
// Get a task
|
|
170
|
+
const task = await client.tasks.get({ workflowId: 789, id: 1 })
|
|
171
|
+
|
|
172
|
+
// List tasks in a workflow
|
|
173
|
+
const tasks = await client.tasks.list({ workflowId: 789 })
|
|
174
|
+
|
|
175
|
+
// Update a task
|
|
176
|
+
await client.tasks.update({
|
|
177
|
+
workflowId: 789,
|
|
178
|
+
id: 1,
|
|
179
|
+
description: 'Updated description',
|
|
180
|
+
status: 'in-progress'
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
// Delete a task
|
|
184
|
+
await client.tasks.delete({ workflowId: 789, id: 1 })
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### Triggers
|
|
188
|
+
|
|
189
|
+
```typescript
|
|
190
|
+
import { triggers, triggerConfigToProps } from '@openserv-labs/client'
|
|
191
|
+
|
|
192
|
+
// Create a webhook trigger
|
|
193
|
+
const trigger = await client.triggers.create({
|
|
194
|
+
workflowId: 789,
|
|
195
|
+
name: 'My Webhook',
|
|
196
|
+
type: 'webhook',
|
|
197
|
+
props: triggerConfigToProps(
|
|
198
|
+
triggers.webhook({
|
|
199
|
+
waitForCompletion: true,
|
|
200
|
+
timeout: 300
|
|
201
|
+
})
|
|
202
|
+
)
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
// Create a cron trigger
|
|
206
|
+
const cronTrigger = await client.triggers.create({
|
|
207
|
+
workflowId: 789,
|
|
208
|
+
name: 'Daily Job',
|
|
209
|
+
type: 'cron',
|
|
210
|
+
props: triggerConfigToProps(
|
|
211
|
+
triggers.cron({
|
|
212
|
+
schedule: '0 9 * * *',
|
|
213
|
+
timezone: 'America/New_York'
|
|
214
|
+
})
|
|
215
|
+
)
|
|
216
|
+
})
|
|
217
|
+
|
|
218
|
+
// Create an x402 (paid) trigger
|
|
219
|
+
const paidTrigger = await client.triggers.create({
|
|
220
|
+
workflowId: 789,
|
|
221
|
+
name: 'Paid API',
|
|
222
|
+
type: 'x402',
|
|
223
|
+
props: triggerConfigToProps(
|
|
224
|
+
triggers.x402({
|
|
225
|
+
price: '0.01',
|
|
226
|
+
input: {
|
|
227
|
+
query: { type: 'string', description: 'Search query' }
|
|
228
|
+
}
|
|
229
|
+
})
|
|
230
|
+
)
|
|
231
|
+
})
|
|
232
|
+
|
|
233
|
+
// Get a trigger
|
|
234
|
+
const trigger = await client.triggers.get({ workflowId: 789, id: 'trigger-id' })
|
|
235
|
+
|
|
236
|
+
// List triggers
|
|
237
|
+
const allTriggers = await client.triggers.list({ workflowId: 789 })
|
|
238
|
+
|
|
239
|
+
// Update a trigger
|
|
240
|
+
await client.triggers.update({
|
|
241
|
+
workflowId: 789,
|
|
242
|
+
id: 'trigger-id',
|
|
243
|
+
name: 'Updated Name',
|
|
244
|
+
props: { timeout: 600 }
|
|
245
|
+
})
|
|
246
|
+
|
|
247
|
+
// Activate a trigger
|
|
248
|
+
await client.triggers.activate({ workflowId: 789, id: 'trigger-id' })
|
|
249
|
+
|
|
250
|
+
// Fire a trigger manually
|
|
251
|
+
await client.triggers.fire({
|
|
252
|
+
workflowId: 789,
|
|
253
|
+
id: 'trigger-id',
|
|
254
|
+
payload: { data: 'test' }
|
|
255
|
+
})
|
|
256
|
+
|
|
257
|
+
// Delete a trigger
|
|
258
|
+
await client.triggers.delete({ workflowId: 789, id: 'trigger-id' })
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### Payments (x402)
|
|
262
|
+
|
|
263
|
+
Pay for and execute x402-protected workflows programmatically.
|
|
264
|
+
|
|
265
|
+
> **Note**: Set `WALLET_PRIVATE_KEY` in your environment. The client uses it automatically for x402 payments using the [x402 protocol](https://www.x402.org/).
|
|
266
|
+
|
|
267
|
+
```typescript
|
|
268
|
+
// Pay and execute an x402 workflow - just set WALLET_PRIVATE_KEY env var
|
|
269
|
+
const client = new PlatformClient()
|
|
270
|
+
const result = await client.payments.payWorkflow({
|
|
271
|
+
triggerUrl: 'https://api.openserv.ai/webhooks/x402/trigger/...',
|
|
272
|
+
input: { prompt: 'Generate a summary' }
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
console.log(`Response: ${JSON.stringify(result.response)}`)
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
The `payWorkflow` method handles the entire x402 payment flow automatically:
|
|
279
|
+
|
|
280
|
+
1. Creates a payment-enabled fetch wrapper using your wallet
|
|
281
|
+
2. Makes a request to the trigger URL
|
|
282
|
+
3. Automatically handles the 402 Payment Required response
|
|
283
|
+
4. Signs and submits the USDC payment on Base
|
|
284
|
+
5. Retries the request with payment proof
|
|
285
|
+
6. Returns the workflow response
|
|
286
|
+
|
|
287
|
+
#### Discover x402 services
|
|
288
|
+
|
|
289
|
+
```typescript
|
|
290
|
+
// List available paid services on the platform
|
|
291
|
+
const services = await client.payments.discoverServices()
|
|
292
|
+
|
|
293
|
+
for (const service of services) {
|
|
294
|
+
console.log(`${service.name}: $${service.x402Pricing}`)
|
|
295
|
+
console.log(`URL: ${service.webhookUrl}`)
|
|
296
|
+
console.log(`By: ${service.ownerDisplayName}`)
|
|
297
|
+
}
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
#### Get trigger preflight info
|
|
301
|
+
|
|
302
|
+
```typescript
|
|
303
|
+
// Get pricing and input schema before paying
|
|
304
|
+
const preflight = await client.payments.getTriggerPreflight({
|
|
305
|
+
token: 'abc123def456' // Extract from webhook URL
|
|
306
|
+
})
|
|
307
|
+
|
|
308
|
+
console.log(`Price: ${preflight.x402Pricing}`)
|
|
309
|
+
console.log(`Pay to: ${preflight.x402WalletAddress}`)
|
|
310
|
+
console.log(`Input schema: ${JSON.stringify(preflight.jsonSchema)}`)
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
### Integrations
|
|
314
|
+
|
|
315
|
+
Manage integration connections for triggers and external services.
|
|
316
|
+
|
|
317
|
+
```typescript
|
|
318
|
+
// List all integration connections for your account
|
|
319
|
+
const connections = await client.integrations.listConnections()
|
|
320
|
+
|
|
321
|
+
for (const conn of connections) {
|
|
322
|
+
console.log(`${conn.integrationDisplayName} (${conn.integrationType})`)
|
|
323
|
+
console.log(` ID: ${conn.id}`)
|
|
324
|
+
console.log(` Integration: ${conn.integrationName}`)
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// Create a custom integration connection
|
|
328
|
+
await client.integrations.connect({
|
|
329
|
+
identifier: 'webhook-trigger',
|
|
330
|
+
props: {} // Optional properties
|
|
331
|
+
})
|
|
332
|
+
|
|
333
|
+
// Get or create a connection (useful for trigger setup)
|
|
334
|
+
const connectionId = await client.integrations.getOrCreateConnection('webhook-trigger')
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
### Web3 / USDC Top-up
|
|
338
|
+
|
|
339
|
+
Add credits to your account by paying with USDC.
|
|
340
|
+
|
|
341
|
+
> **Note**: Set `WALLET_PRIVATE_KEY` in your environment. The client uses it automatically for payments and SIWE authentication.
|
|
342
|
+
|
|
343
|
+
```typescript
|
|
344
|
+
// Simple one-liner - just set WALLET_PRIVATE_KEY env var
|
|
345
|
+
const client = new PlatformClient()
|
|
346
|
+
const result = await client.web3.topUp({ amountUsd: 10 })
|
|
347
|
+
|
|
348
|
+
console.log(`Transaction: ${result.txHash}`)
|
|
349
|
+
console.log(`Added ${result.creditsAdded} credits`)
|
|
350
|
+
console.log(`USDC spent: ${result.usdcAmount}`)
|
|
351
|
+
console.log(`Network: ${result.network}`)
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
The `topUp` method handles the entire flow:
|
|
355
|
+
|
|
356
|
+
1. Fetches USDC configuration from the platform
|
|
357
|
+
2. Checks your USDC balance
|
|
358
|
+
3. Sends USDC to the platform's receiver address
|
|
359
|
+
4. Waits for transaction confirmation
|
|
360
|
+
5. Signs a verification message
|
|
361
|
+
6. Verifies and adds credits to your account
|
|
362
|
+
|
|
363
|
+
#### Lower-level methods
|
|
364
|
+
|
|
365
|
+
For more control, use the individual methods:
|
|
366
|
+
|
|
367
|
+
```typescript
|
|
368
|
+
// Get USDC top-up configuration
|
|
369
|
+
const config = await client.web3.getUsdcTopupConfig()
|
|
370
|
+
console.log(`Send USDC to ${config.receiverAddress} on ${config.network}`)
|
|
371
|
+
console.log(`Chain ID: ${config.chainId}`)
|
|
372
|
+
console.log(`USDC Contract: ${config.usdcContractAddress}`)
|
|
373
|
+
console.log(`Rate: 1 USDC = ${config.rateUsdcToCredits} credits`)
|
|
374
|
+
|
|
375
|
+
// After sending USDC manually, verify the transaction
|
|
376
|
+
const result = await client.web3.verifyUsdcTransaction({
|
|
377
|
+
txHash: '0xabc123...',
|
|
378
|
+
payerAddress: '0xYourWallet...', // Required for non-wallet-authenticated users
|
|
379
|
+
signature: '0x...' // Sign "Verify USDC top-up: {txHash}"
|
|
380
|
+
})
|
|
381
|
+
console.log(`Added ${result.creditsAdded} credits`)
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
## Workflow Object
|
|
385
|
+
|
|
386
|
+
When you retrieve a workflow, you get a `Workflow` object with helper methods:
|
|
387
|
+
|
|
388
|
+
```typescript
|
|
389
|
+
const workflow = await client.workflows.get({ id: 789 })
|
|
390
|
+
|
|
391
|
+
// Access workflow properties
|
|
392
|
+
console.log(workflow.id, workflow.name, workflow.goal)
|
|
393
|
+
console.log(workflow.status) // 'draft', 'running', etc.
|
|
394
|
+
console.log(workflow.triggers) // Array of triggers
|
|
395
|
+
console.log(workflow.tasks) // Array of tasks
|
|
396
|
+
console.log(workflow.edges) // Graph edges
|
|
397
|
+
console.log(workflow.agents) // Assigned agents
|
|
398
|
+
|
|
399
|
+
// Sync configuration declaratively
|
|
400
|
+
await workflow.sync({
|
|
401
|
+
triggers: [{ name: 'api', type: 'webhook' }],
|
|
402
|
+
tasks: [{ name: 'work', agentId: 123, description: 'Do work' }],
|
|
403
|
+
edges: [{ from: 'trigger:api', to: 'task:work' }]
|
|
404
|
+
})
|
|
405
|
+
|
|
406
|
+
// Start the workflow
|
|
407
|
+
await workflow.setRunning()
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
## Provision API
|
|
411
|
+
|
|
412
|
+
The `provision()` function provides a simple way to deploy agents and workflows in one call. It's designed to work seamlessly with [@openserv-labs/sdk](https://github.com/openserv-labs/sdk) for building AI agents.
|
|
413
|
+
|
|
414
|
+
### About `endpointUrl`
|
|
415
|
+
|
|
416
|
+
The `endpointUrl` parameter is **optional** when using `@openserv-labs/sdk` v2.0.0+. Here's why:
|
|
417
|
+
|
|
418
|
+
- **Development**: When you call `run(agent)` from the SDK, it automatically registers your agent with the OpenServ agents proxy (`https://agents-proxy.openserv.ai`), which tunnels requests to your local machine. No `endpointUrl` needed.
|
|
419
|
+
- **Production**: If you're deploying your agent to a publicly accessible URL (e.g., your own server, cloud function, or container), provide the `endpointUrl` so the platform knows where to reach your agent.
|
|
420
|
+
|
|
421
|
+
### Development Example (No endpointUrl)
|
|
422
|
+
|
|
423
|
+
When developing locally with the SDK, you can omit `endpointUrl`:
|
|
424
|
+
|
|
425
|
+
```typescript
|
|
426
|
+
import { provision, triggers } from '@openserv-labs/client'
|
|
427
|
+
import { Agent, run } from '@openserv-labs/sdk'
|
|
428
|
+
|
|
429
|
+
// Step 1: Provision the agent and workflow (no endpointUrl needed for dev)
|
|
430
|
+
const result = await provision({
|
|
431
|
+
agent: {
|
|
432
|
+
name: 'my-agent',
|
|
433
|
+
description: 'Handles API requests'
|
|
434
|
+
},
|
|
435
|
+
workflow: {
|
|
436
|
+
name: 'api-workflow',
|
|
437
|
+
trigger: triggers.webhook({
|
|
438
|
+
input: { query: { type: 'string' } },
|
|
439
|
+
waitForCompletion: true
|
|
440
|
+
}),
|
|
441
|
+
task: {
|
|
442
|
+
description: 'Process incoming API requests and return results'
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
})
|
|
446
|
+
|
|
447
|
+
console.log(result.agentId) // Created agent ID
|
|
448
|
+
console.log(result.apiKey) // Agent API key
|
|
449
|
+
console.log(result.apiEndpoint) // Webhook URL to call
|
|
450
|
+
|
|
451
|
+
// Step 2: Create and run the agent (SDK auto-updates endpoint to agents-proxy)
|
|
452
|
+
const agent = new Agent({
|
|
453
|
+
systemPrompt: 'You are a helpful assistant.'
|
|
454
|
+
})
|
|
455
|
+
|
|
456
|
+
run(agent) // Automatically connects to agents-proxy.openserv.ai
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
### Production Example (With endpointUrl)
|
|
460
|
+
|
|
461
|
+
When deploying to production with a publicly accessible URL:
|
|
462
|
+
|
|
463
|
+
```typescript
|
|
464
|
+
import { provision, triggers } from '@openserv-labs/client'
|
|
465
|
+
|
|
466
|
+
const result = await provision({
|
|
467
|
+
agent: {
|
|
468
|
+
name: 'my-agent',
|
|
469
|
+
description: 'Handles API requests',
|
|
470
|
+
endpointUrl: 'https://my-agent.example.com' // Your production URL
|
|
471
|
+
},
|
|
472
|
+
workflow: {
|
|
473
|
+
name: 'api-workflow',
|
|
474
|
+
trigger: triggers.webhook({
|
|
475
|
+
input: { query: { type: 'string' } },
|
|
476
|
+
waitForCompletion: true
|
|
477
|
+
}),
|
|
478
|
+
task: {
|
|
479
|
+
description: 'Process incoming API requests and return results'
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
})
|
|
483
|
+
|
|
484
|
+
console.log(result.apiEndpoint) // Webhook URL to call
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
### More Examples
|
|
488
|
+
|
|
489
|
+
```typescript
|
|
490
|
+
import { provision, triggers, isProvisioned, getProvisionedInfo, clearProvisionedState } from '@openserv-labs/client'
|
|
491
|
+
|
|
492
|
+
// Provision with x402 (paid) trigger
|
|
493
|
+
const paidResult = await provision({
|
|
494
|
+
agent: {
|
|
495
|
+
name: 'paid-agent',
|
|
496
|
+
description: 'Premium AI service',
|
|
497
|
+
endpointUrl: 'https://paid-agent.example.com' // Required for production
|
|
498
|
+
},
|
|
499
|
+
workflow: {
|
|
500
|
+
name: 'paid-workflow',
|
|
501
|
+
trigger: triggers.x402({
|
|
502
|
+
price: '0.01',
|
|
503
|
+
input: { prompt: { type: 'string' } }
|
|
504
|
+
}),
|
|
505
|
+
task: {
|
|
506
|
+
description: 'Process paid requests and deliver premium results'
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
})
|
|
510
|
+
|
|
511
|
+
console.log(paidResult.paywallUrl) // Public paywall URL for payments
|
|
512
|
+
|
|
513
|
+
// Check if already provisioned (uses .openserv.json state file)
|
|
514
|
+
if (isProvisioned('my-agent', 'api-workflow')) {
|
|
515
|
+
const info = getProvisionedInfo('my-agent', 'api-workflow')
|
|
516
|
+
console.log('Already provisioned:', info)
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
// Clear provisioned state (does not delete from platform)
|
|
520
|
+
clearProvisionedState()
|
|
521
|
+
```
|
|
522
|
+
|
|
523
|
+
### Provision with Cron Trigger
|
|
524
|
+
|
|
525
|
+
```typescript
|
|
526
|
+
const cronResult = await provision({
|
|
527
|
+
agent: {
|
|
528
|
+
name: 'scheduled-agent',
|
|
529
|
+
description: 'Runs scheduled tasks',
|
|
530
|
+
endpointUrl: 'https://scheduled-agent.example.com' // Required for production
|
|
531
|
+
},
|
|
532
|
+
workflow: {
|
|
533
|
+
name: 'daily-job',
|
|
534
|
+
trigger: triggers.cron({
|
|
535
|
+
schedule: '0 9 * * *', // Daily at 9 AM
|
|
536
|
+
timezone: 'America/New_York'
|
|
537
|
+
}),
|
|
538
|
+
task: {
|
|
539
|
+
description: 'Execute daily data processing and send reports'
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
})
|
|
543
|
+
```
|
|
544
|
+
|
|
545
|
+
## Trigger Factory Functions
|
|
546
|
+
|
|
547
|
+
Use the `triggers` factory for type-safe trigger configuration:
|
|
548
|
+
|
|
549
|
+
```typescript
|
|
550
|
+
import { triggers, triggerConfigToProps } from '@openserv-labs/client'
|
|
551
|
+
|
|
552
|
+
// Webhook trigger
|
|
553
|
+
triggers.webhook({
|
|
554
|
+
input: { message: { type: 'string' } },
|
|
555
|
+
waitForCompletion: true,
|
|
556
|
+
timeout: 180
|
|
557
|
+
})
|
|
558
|
+
|
|
559
|
+
// Cron trigger
|
|
560
|
+
triggers.cron({
|
|
561
|
+
schedule: '0 */6 * * *', // Every 6 hours
|
|
562
|
+
timezone: 'UTC'
|
|
563
|
+
})
|
|
564
|
+
|
|
565
|
+
// x402 (paid) trigger
|
|
566
|
+
triggers.x402({
|
|
567
|
+
price: '0.05',
|
|
568
|
+
input: { prompt: { type: 'string', description: 'User prompt' } },
|
|
569
|
+
timeout: 300,
|
|
570
|
+
walletAddress: '0x...'
|
|
571
|
+
})
|
|
572
|
+
|
|
573
|
+
// Manual trigger
|
|
574
|
+
triggers.manual()
|
|
575
|
+
```
|
|
576
|
+
|
|
577
|
+
## Environment Variables
|
|
578
|
+
|
|
579
|
+
| Variable | Description | Required |
|
|
580
|
+
| ----------------------- | ------------------------------------- | ---------------------------- |
|
|
581
|
+
| `OPENSERV_USER_API_KEY` | Your OpenServ user API key | For most API operations |
|
|
582
|
+
| `OPENSERV_API_URL` | Custom API URL (for testing) | No |
|
|
583
|
+
| `WALLET_PRIVATE_KEY` | Wallet private key for blockchain ops | For top-up and x402 payments |
|
|
584
|
+
|
|
585
|
+
**Authentication options:**
|
|
586
|
+
|
|
587
|
+
- Use `OPENSERV_USER_API_KEY` for API key authentication
|
|
588
|
+
- Use `WALLET_PRIVATE_KEY` for wallet-based (SIWE) authentication
|
|
589
|
+
|
|
590
|
+
**For Web3 operations:** Just set `WALLET_PRIVATE_KEY` - the client automatically uses it for blockchain transactions and handles SIWE authentication. No need to pass it explicitly in API calls.
|
|
591
|
+
|
|
592
|
+
## Types
|
|
593
|
+
|
|
594
|
+
All types are exported for TypeScript users:
|
|
595
|
+
|
|
596
|
+
```typescript
|
|
597
|
+
import type {
|
|
598
|
+
// Domain types
|
|
599
|
+
Agent,
|
|
600
|
+
Workflow,
|
|
601
|
+
WorkflowConfig,
|
|
602
|
+
WorkflowData,
|
|
603
|
+
Task,
|
|
604
|
+
Trigger,
|
|
605
|
+
TriggerDefinition,
|
|
606
|
+
TaskDefinition,
|
|
607
|
+
EdgeDefinition,
|
|
608
|
+
Edge,
|
|
609
|
+
// Marketplace types
|
|
610
|
+
MarketplaceAgent,
|
|
611
|
+
MarketplaceAgentsResponse,
|
|
612
|
+
Category,
|
|
613
|
+
// Integration types
|
|
614
|
+
IntegrationConnection,
|
|
615
|
+
// Trigger config types
|
|
616
|
+
TriggerConfig,
|
|
617
|
+
WebhookTriggerConfig,
|
|
618
|
+
X402TriggerConfig,
|
|
619
|
+
CronTriggerConfig,
|
|
620
|
+
ManualTriggerConfig,
|
|
621
|
+
InputSchema,
|
|
622
|
+
InputSchemaProperty,
|
|
623
|
+
// API response types
|
|
624
|
+
PaginatedResponse,
|
|
625
|
+
IdResponse,
|
|
626
|
+
ApiKeyResponse,
|
|
627
|
+
NonceResponse,
|
|
628
|
+
VerifyResponse,
|
|
629
|
+
// Web3 types
|
|
630
|
+
UsdcTopupConfig,
|
|
631
|
+
UsdcTopupResult,
|
|
632
|
+
UsdcVerifyRequest,
|
|
633
|
+
UsdcVerifyResponse,
|
|
634
|
+
// x402 Payment types
|
|
635
|
+
X402PaymentRequest,
|
|
636
|
+
X402PaymentResult,
|
|
637
|
+
// Provision types
|
|
638
|
+
ProvisionConfig,
|
|
639
|
+
ProvisionResult,
|
|
640
|
+
Logger
|
|
641
|
+
} from '@openserv-labs/client'
|
|
642
|
+
```
|
|
643
|
+
|
|
644
|
+
## License
|
|
645
|
+
|
|
646
|
+
MIT License - see [LICENSE](LICENSE) for details.
|