Loading...
Loading...
Compare original and translation side by side
@openserv-labs/clientreference.mdtroubleshooting.mdexamples/@openserv-labs/clientreference.mdtroubleshooting.mdexamples/npm install @openserv-labs/clientnpm install @openserv-labs/clientprovision()run()provision()run()provision()run()examples/agent.tsKey Point:is idempotent. Call it every time your app starts - no need to checkprovision()first.isProvisioned()
provision()run()examples/agent.ts关键点:是幂等的。每次应用启动时都可以调用它——无需先检查provision()。isProvisioned()
provision()provision()agent.instance.openserv.jsonagent.instance.openserv.jsonworkflowname'Viral Content Engine''Crypto Alpha Scanner''Life Catalyst Pro'goalworkflow: {
name: 'Deep Research Pro',
goal: 'Research any topic in depth, synthesize findings from multiple sources, and produce a comprehensive report with citations',
trigger: triggers.webhook({ waitForCompletion: true, timeout: 600 }),
task: { description: 'Research the given topic' }
}workflowname'Viral Content Engine''Crypto Alpha Scanner''Life Catalyst Pro'goalworkflow: {
name: 'Deep Research Pro',
goal: '深入研究任何主题,综合多来源研究结果,并生成带引用的全面报告',
trigger: triggers.webhook({ waitForCompletion: true, timeout: 600 }),
task: { description: '研究指定主题' }
}provision()const agent = new Agent({ systemPrompt: '...' })
await provision({
agent: {
instance: agent, // Calls agent.setCredentials() automatically
name: 'my-agent',
description: '...'
},
workflow: { ... }
})
// agent now has apiKey and authToken set - ready for run()
await run(agent)OPENSERV_API_KEYprovision()const agent = new Agent({ systemPrompt: '...' })
await provision({
agent: {
instance: agent, // 自动调用agent.setCredentials()
name: 'my-agent',
description: '...'
},
workflow: { ... }
})
// agent现在已设置apiKey和authToken - 可随时调用run()
await run(agent)OPENSERV_API_KEYinterface ProvisionResult {
agentId: number
apiKey: string
authToken?: string
workflowId: number
triggerId: string
triggerToken: string
paywallUrl?: string // For x402 triggers
apiEndpoint?: string // For webhook triggers
}interface ProvisionResult {
agentId: number
apiKey: string
authToken?: string
workflowId: number
triggerId: string
triggerToken: string
paywallUrl?: string // 用于x402触发器
apiEndpoint?: string // 用于webhook触发器
}PlatformClientimport { PlatformClient } from '@openserv-labs/client'
// Using API key
const client = new PlatformClient({
apiKey: process.env.OPENSERV_USER_API_KEY
})
// Or using wallet authentication
const client = new PlatformClient()
await client.authenticate(process.env.WALLET_PRIVATE_KEY)reference.mdclient.agents.*client.workflows.*client.triggers.*client.tasks.*client.integrations.*client.payments.*client.web3.*PlatformClientimport { PlatformClient } from '@openserv-labs/client'
// 使用API密钥
const client = new PlatformClient({
apiKey: process.env.OPENSERV_USER_API_KEY
})
// 或使用钱包身份验证
const client = new PlatformClient()
await client.authenticate(process.env.WALLET_PRIVATE_KEY)reference.mdclient.agents.*client.workflows.*client.triggers.*client.tasks.*client.integrations.*client.payments.*client.web3.*triggersimport { triggers } from '@openserv-labs/client'
// Webhook (free, public endpoint)
triggers.webhook({
input: { query: { type: 'string', description: 'Search query' } },
waitForCompletion: true,
timeout: 600
})
// x402 (paid API with paywall)
triggers.x402({
name: 'AI Research Assistant',
description: 'Get comprehensive research reports on any topic',
price: '0.01',
timeout: 600,
input: {
prompt: {
type: 'string',
title: 'Your Request',
description: 'Describe what you would like the agent to do'
}
}
})
// Cron (scheduled)
triggers.cron({
schedule: '0 9 * * *', // Daily at 9 AM
timezone: 'America/New_York'
})
// Manual (platform UI only)
triggers.manual()triggersimport { triggers } from '@openserv-labs/client'
// Webhook(免费,公开端点)
triggers.webhook({
input: { query: { type: 'string', description: '搜索查询' } },
waitForCompletion: true,
timeout: 600
})
// x402(带付费墙的付费API)
triggers.x402({
name: 'AI Research Assistant',
description: '获取任意主题的全面研究报告',
price: '0.01',
timeout: 600,
input: {
prompt: {
type: 'string',
title: '你的请求',
description: '描述你希望Agent执行的操作'
}
}
})
// Cron(定时触发)
triggers.cron({
schedule: '0 9 * * *', // 每天上午9点
timezone: 'America/New_York'
})
// Manual(仅平台UI触发)
triggers.manual()Important: Always setto at least 600 seconds (10 minutes) for webhook and x402 triggers. Agents often take significant time to process requests — especially in multi-agent workflows or when performing research, content generation, or other complex tasks. A low timeout (e.g., 180s) will cause premature failures. When in doubt, err on the side of a longer timeout. For multi-agent pipelines with many sequential steps, consider 900 seconds or more.timeout
重要提示: 对于webhook和x402触发器,请始终将设置为至少600秒(10分钟)。Agent处理请求通常需要大量时间——尤其是在多Agent工作流或执行研究、内容生成等复杂任务时。较低的超时时间(如180秒)会导致提前失败。如有疑问,请设置更长的超时时间。对于包含多个连续步骤的多Agent管道,可考虑设置900秒或更长时间。timeout
triggers.x402({
name: 'Content Writer',
description: 'Generate polished content on any topic',
price: '0.01',
input: {
topic: {
type: 'string',
title: 'Content Topic',
description: 'Enter the subject you want covered'
},
style: {
type: 'string',
title: 'Writing Style',
enum: ['formal', 'casual', 'humorous'],
default: 'casual'
}
}
})triggers.x402({
name: 'Content Writer',
description: '生成任意主题的优质内容',
price: '0.01',
input: {
topic: {
type: 'string',
title: '内容主题',
description: '输入你希望覆盖的主题'
},
style: {
type: 'string',
title: '写作风格',
enum: ['formal', 'casual', 'humorous'],
default: 'casual'
}
}
})┌───────────── minute (0-59)
│ ┌───────────── hour (0-23)
│ │ ┌───────────── day of month (1-31)
│ │ │ ┌───────────── month (1-12)
│ │ │ │ ┌───────────── day of week (0-6, Sunday=0)
* * * * *0 9 * * **/5 * * * *0 9 * * 1-5┌───────────── 分钟 (0-59)
│ ┌───────────── 小时 (0-23)
│ │ ┌───────────── 日期 (1-31)
│ │ │ ┌───────────── 月份 (1-12)
│ │ │ │ ┌───────────── 星期 (0-6,周日=0)
* * * * *0 9 * * **/5 * * * *0 9 * * 1-5import { getProvisionedInfo, clearProvisionedState } from '@openserv-labs/client'
// Get stored IDs and tokens
const info = getProvisionedInfo('my-agent', 'My Awesome Workflow')
// Clear state (forces fresh creation)
clearProvisionedState()import { getProvisionedInfo, clearProvisionedState } from '@openserv-labs/client'
// 获取存储的ID和令牌
const info = getProvisionedInfo('my-agent', 'My Awesome Workflow')
// 清除状态(强制重新创建)
clearProvisionedState()discoverServices()PlatformClientimport { PlatformClient } from '@openserv-labs/client'
const client = new PlatformClient() // no API key or wallet needed
const services = await client.payments.discoverServices()
for (const service of services) {
console.log(`${service.name}: $${service.x402Pricing}`)
console.log(`URL: ${service.webhookUrl}`)
}discoverServices()PlatformClientimport { PlatformClient } from '@openserv-labs/client'
const client = new PlatformClient() // 无需API密钥或钱包
const services = await client.payments.discoverServices()
for (const service of services) {
console.log(`${service.name}: $${service.x402Pricing}`)
console.log(`URL: ${service.webhookUrl}`)
}curl -X POST https://api.openserv.ai/webhooks/trigger/TOKEN \
-H "Content-Type: application/json" \
-d '{"query": "hello world"}'curl -X POST https://api.openserv.ai/webhooks/trigger/TOKEN \
-H "Content-Type: application/json" \
-d '{"query": "hello world"}'const result = await client.payments.payWorkflow({
triggerUrl: 'https://api.openserv.ai/webhooks/x402/trigger/TOKEN',
input: { prompt: 'Hello world' }
})const result = await client.payments.payWorkflow({
triggerUrl: 'https://api.openserv.ai/webhooks/x402/trigger/TOKEN',
input: { prompt: 'Hello world' }
})| Variable | Description | Required |
|---|---|---|
| User API key (from platform) | Yes* |
| Wallet for SIWE auth | Yes* |
| Custom API URL | No |
| 环境变量 | 描述 | 是否必填 |
|---|---|---|
| 用户API密钥(来自平台) | 是* |
| 用于SIWE身份验证的钱包 | 是* |
| 自定义API地址 | 否 |
import { PlatformClient } from '@openserv-labs/client'
const client = new PlatformClient()
await client.authenticate(process.env.WALLET_PRIVATE_KEY)
const erc8004 = await client.erc8004.registerOnChain({
workflowId: result.workflowId,
privateKey: process.env.WALLET_PRIVATE_KEY!,
name: 'My Agent',
description: 'What this agent does'
})
console.log(`Agent ID: ${erc8004.agentId}`) // "8453:42"
console.log(`Explorer: ${erc8004.blockExplorerUrl}`)
console.log(`Scan: ${erc8004.scanUrl}`) // "https://www.8004scan.io/agents/base/42"chainIdrpcUrlreference.mdimport { PlatformClient } from '@openserv-labs/client'
const client = new PlatformClient()
await client.authenticate(process.env.WALLET_PRIVATE_KEY)
const erc8004 = await client.erc8004.registerOnChain({
workflowId: result.workflowId,
privateKey: process.env.WALLET_PRIVATE_KEY!,
name: 'My Agent',
description: '该Agent的功能'
})
console.log(`Agent ID: ${erc8004.agentId}`) // "8453:42"
console.log(`区块链浏览器: ${erc8004.blockExplorerUrl}`)
console.log(`扫描地址: ${erc8004.scanUrl}`) // "https://www.8004scan.io/agents/base/42"chainIdrpcUrlreference.mdawait client.workflows.delete({ id: workflowId })
await client.agents.delete({ id: agentId })
clearProvisionedState()await client.workflows.delete({ id: workflowId })
await client.agents.delete({ id: agentId })
clearProvisionedState()undefinedundefined
Or reinstall the OpenServ skills directly:
```bash
npx skills add openserv-labs/skills
或者直接重新安装OpenServ技能:
```bash
npx skills add openserv-labs/skills