Loading...
Loading...
Compare original and translation side by side
create_lucid_agentundefinedcreate_lucid_agentundefined
The MCP tool automatically handles:
- Setup payment (if agent has paid entrypoints)
- SIWE authentication with your server wallet
- x402 payment signature generation
- Agent creation with PAYMENT-SIGNATURE header
MCP工具会自动处理以下内容:
- 设置支付(若Agent包含付费入口点)
- 使用服务器钱包完成SIWE身份验证
- 生成x402支付签名
- 携带PAYMENT-SIGNATURE头创建Agentimport { createX402Payment } from '@lucid-agents/payments';
import { privateKeyToAccount } from 'viem/accounts';
import { baseSepolia } from 'viem/chains';
const account = privateKeyToAccount(`0x${WALLET_PRIVATE_KEY}`);
// Step 1: Setup payment (for paid agents)
const setupPayment = await createX402Payment({
account,
chain: baseSepolia,
resource: {
url: 'https://api.daydreams.systems/api/agents/setup-payment',
description: 'Agent setup payment',
mimeType: 'application/json',
},
amount: '10000', // 0.01 USDC setup fee
asset: '0x036CbD53842c5426634e7929541eC2318f3dCF7e', // USDC
payTo: '0xPlatformWallet', // Platform wallet
});
await fetch('https://api.daydreams.systems/api/agents/setup-payment', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'PAYMENT-SIGNATURE': btoa(JSON.stringify(setupPayment)),
},
body: JSON.stringify({
slug: 'my-agent',
network: 'eip155:84532',
facilitatorUrl: 'https://facilitator.daydreams.systems',
}),
});
// Step 2: Create agent with wallet auth
const createPayment = await createX402Payment({
account,
chain: baseSepolia,
resource: {
url: 'https://api.daydreams.systems/api/agents',
description: 'Agent creation',
mimeType: 'application/json',
},
amount: '0', // Free for auth
asset: '0x036CbD53842c5426634e7929541eC2318f3dCF7e',
payTo: account.address,
});
const response = await fetch('https://api.daydreams.systems/api/agents', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'PAYMENT-SIGNATURE': btoa(JSON.stringify(createPayment)),
},
body: JSON.stringify({
slug: 'my-agent',
name: 'My Agent',
description: 'Agent description',
entrypoints: [{
key: 'chat',
description: 'Chat endpoint',
handlerType: 'js',
handlerConfig: {
code: "return { message: 'Hello from ' + input.name };",
},
price: '10000',
}],
}),
});
const agent = await response.json();import { createX402Payment } from '@lucid-agents/payments';
import { privateKeyToAccount } from 'viem/accounts';
import { baseSepolia } from 'viem/chains';
const account = privateKeyToAccount(`0x${WALLET_PRIVATE_KEY}`);
// 步骤1:设置支付(针对付费Agent)
const setupPayment = await createX402Payment({
account,
chain: baseSepolia,
resource: {
url: 'https://api.daydreams.systems/api/agents/setup-payment',
description: 'Agent setup payment',
mimeType: 'application/json',
},
amount: '10000', // 0.01 USDC 安装费用
asset: '0x036CbD53842c5426634e7929541eC2318f3dCF7e', // USDC
payTo: '0xPlatformWallet', // 平台钱包
});
await fetch('https://api.daydreams.systems/api/agents/setup-payment', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'PAYMENT-SIGNATURE': btoa(JSON.stringify(setupPayment)),
},
body: JSON.stringify({
slug: 'my-agent',
network: 'eip155:84532',
facilitatorUrl: 'https://facilitator.daydreams.systems',
}),
});
// 步骤2:使用钱包身份验证创建Agent
const createPayment = await createX402Payment({
account,
chain: baseSepolia,
resource: {
url: 'https://api.daydreams.systems/api/agents',
description: 'Agent creation',
mimeType: 'application/json',
},
amount: '0', // 身份验证免费
asset: '0x036CbD53842c5426634e7929541eC2318f3dCF7e',
payTo: account.address,
});
const response = await fetch('https://api.daydreams.systems/api/agents', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'PAYMENT-SIGNATURE': btoa(JSON.stringify(createPayment)),
},
body: JSON.stringify({
slug: 'my-agent',
name: 'My Agent',
description: 'Agent description',
entrypoints: [{
key: 'chat',
description: 'Chat endpoint',
handlerType: 'js',
handlerConfig: {
code: "return { message: 'Hello from ' + input.name };",
},
price: '10000',
}],
}),
});
const agent = await response.json();scripts/create-agent-with-payment-auth.tsscripts/test-setup-payment-x402.tsscripts/create-agent-with-payment-auth.tsscripts/test-setup-payment-x402.ts(async () => { ${code} })()inputinput{ "input": <payload> }<payload>inputconsolefetchhandlerConfig.network.allowedHostsrequireimportprocess(async () => { ${code} })()inputinput{ "input": <payload> }<payload>inputconsolefetchhandlerConfig.network.allowedHostsrequireimportprocessoutputusage: { total_tokens: 0 }outputusage: { total_tokens: 0 }handlerConfig.timeoutMshandlerConfig.timeoutMshandlerConfig.network.allowedHosts["*"]["api.example.com"]["*.example.com"]handlerConfig.network.timeoutMsallowedHostsfetchhandlerConfig.network.allowedHosts["*"]["api.example.com"]["*.example.com"]handlerConfig.network.timeoutMsallowedHostsfetchctxinputinputinput.textctx.input{ output, usage }outputusagectxinputinputinput.textctx.input{ output, usage }outputusagereturn { echoed: input };return { text: input.text };const res = await fetch(`https://api.example.com/data?q=${encodeURIComponent(input.q)}`);
const data = await res.json();
return data;// This handler might take longer, so we override the timeout
// Note: timeoutMs is set in handlerConfig, not in the code itself
return await someSlowOperation(input);return { echoed: input };return { text: input.text };const res = await fetch(`https://api.example.com/data?q=${encodeURIComponent(input.q)}`);
const data = await res.json();
return data;// 该处理程序可能耗时较长,因此我们覆盖默认超时时间
// 注意:timeoutMs需在handlerConfig中设置,而非代码内部
return await someSlowOperation(input);create_lucid_agentcreate_lucid_agentcreate_lucid_agentslugnamedescriptionentrypointskeydescriptionhandlerType"js"handlerConfigcodetimeoutMsnetworkallowedHoststimeoutMsinputSchemaoutputSchemapricenetworkidentityConfigchainIdrpcUrlregistryAddressautoRegistertrustModelstrustOverridesversionnetworkcreate_lucid_agentslugnamedescriptionentrypointskeydescriptionhandlerType"js"handlerConfigcodetimeoutMsnetworkallowedHoststimeoutMsinputSchemaoutputSchemapricenetworkidentityConfigchainIdrpcUrlregistryAddressautoRegistertrustModelstrustOverridesversionnetworkpricepaymentsConfigpayTonetwork"ethereum"facilitatorUrl"https://facilitator.daydreams.systems"paymentsConfigpaymentsConfigpricepaymentsConfigpayTonetwork"ethereum"facilitatorUrl"https://facilitator.daydreams.systems"paymentsConfigpaymentsConfigidentityConfigwalletsConfig.agentwalletsConfig.agentidentityConfigidentityConfigwalletsConfig.agentwalletsConfig.agentidentityConfigpriceidslugnamedescriptioninvokeUrlidslugnamedescriptioninvokeUrlinvokeUrlPOST /agents/{agentId}/entrypoints/{key}/invokeinput{ "input": { "text": "Hello" } }sessionIdmetadatainputinputinvokeUrlPOST /agents/{agentId}/entrypoints/{key}/invokeinput{ "input": { "text": "Hello" } }sessionIdmetadatainputinput// Create a simple echo agent
await create_lucid_agent({
slug: "echo-agent",
name: "Echo Agent",
description: "Echoes input back",
entrypoints: [
{
key: "echo",
description: "Echo the input",
handlerType: "js",
handlerConfig: {
code: "return { echoed: input };"
}
}
]
});
// Create a paid agent with fetch
await create_lucid_agent({
slug: "weather-agent",
name: "Weather Agent",
description: "Fetches weather data",
entrypoints: [
{
key: "get-weather",
description: "Get weather by city",
handlerType: "js",
handlerConfig: {
code: `
const res = await fetch(\`https://api.weather.com/data?city=\${encodeURIComponent(input.city)}\`);
const data = await res.json();
return data;
`,
network: {
allowedHosts: ["api.weather.com"]
}
},
price: "1000" // 0.001 USDC
}
]
});
// Create agent with identity config
await create_lucid_agent({
slug: "identity-agent",
name: "Identity Agent",
description: "Agent with ERC-8004 identity",
entrypoints: [
{
key: "process",
handlerType: "js",
handlerConfig: {
code: "return { result: input };"
}
}
],
identityConfig: {
chainId: 1, // Ethereum mainnet
autoRegister: true,
trustModels: ["feedback", "inference-validation"]
}
});// 创建一个简单的回显Agent
await create_lucid_agent({
slug: "echo-agent",
name: "Echo Agent",
description: "Echoes input back",
entrypoints: [
{
key: "echo",
description: "Echo the input",
handlerType: "js",
handlerConfig: {
code: "return { echoed: input };"
}
}
]
});
// 创建一个支持网络请求的付费Agent
await create_lucid_agent({
slug: "weather-agent",
name: "Weather Agent",
description: "Fetches weather data",
entrypoints: [
{
key: "get-weather",
description: "Get weather by city",
handlerType: "js",
handlerConfig: {
code: `
const res = await fetch(\`https://api.weather.com/data?city=\${encodeURIComponent(input.city)}\`);
const data = await res.json();
return data;
`,
network: {
allowedHosts: ["api.weather.com"]
}
},
price: "1000" // 0.001 USDC
}
]
});
// 创建带有身份配置的Agent
await create_lucid_agent({
slug: "identity-agent",
name: "Identity Agent",
description: "Agent with ERC-8004 identity",
entrypoints: [
{
key: "process",
handlerType: "js",
handlerConfig: {
code: "return { result: input };"
}
}
],
identityConfig: {
chainId: 1, // 以太坊主网
autoRegister: true,
trustModels: ["feedback", "inference-validation"]
}
});packages/hono-runtime/src/runtime/workers/js-worker.tspackages/hono-runtime/src/handlers/js.tspackages/hono-runtime/src/openapi/schemas.tspackages/hono-runtime/src/runtime/workers/js-worker.tspackages/hono-runtime/src/handlers/js.tspackages/hono-runtime/src/openapi/schemas.ts