repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | /** |
| #2 | * Agent Card |
| #3 | * |
| #4 | * Generates and manages the agent's self-description card. |
| #5 | * This is the JSON document pointed to by the ERC-8004 agentURI. |
| #6 | * Can be hosted on IPFS or served at /.well-known/agent-card.json |
| #7 | */ |
| #8 | const AGENT_CARD_TYPE = "https://eips.ethereum.org/EIPS/eip-8004#registration-v1"; |
| #9 | /** |
| #10 | * Generate an agent card from the automaton's current state. |
| #11 | */ |
| #12 | export function generateAgentCard(identity, config, db) { |
| #13 | const services = [ |
| #14 | { |
| #15 | name: "agentWallet", |
| #16 | endpoint: `eip155:8453:${identity.address}`, |
| #17 | }, |
| #18 | { |
| #19 | name: "runtime", |
| #20 | endpoint: config.clawdApiUrl, |
| #21 | }, |
| #22 | ]; |
| #23 | // Add sandbox endpoint if available |
| #24 | if (identity.sandboxId) { |
| #25 | services.push({ |
| #26 | name: "sandbox", |
| #27 | endpoint: `https://${identity.sandboxId}.life.x402.wtf`, |
| #28 | }); |
| #29 | } |
| #30 | const children = db.getChildren(); |
| #31 | const skills = db.getSkills(true); |
| #32 | let description = `Autonomous agent running on CLAWD Cloud.`; |
| #33 | description += ` Creator: ${config.creatorAddress}.`; |
| #34 | if (skills.length > 0) { |
| #35 | description += ` Skills: ${skills.map((s) => s.name).join(", ")}.`; |
| #36 | } |
| #37 | if (children.length > 0) { |
| #38 | description += ` Children: ${children.length}.`; |
| #39 | } |
| #40 | return { |
| #41 | type: AGENT_CARD_TYPE, |
| #42 | name: config.name, |
| #43 | description, |
| #44 | services, |
| #45 | x402Support: true, |
| #46 | active: true, |
| #47 | parentAgent: config.parentAddress || config.creatorAddress, |
| #48 | }; |
| #49 | } |
| #50 | /** |
| #51 | * Serialize agent card to JSON string. |
| #52 | */ |
| #53 | export function serializeAgentCard(card) { |
| #54 | return JSON.stringify(card, null, 2); |
| #55 | } |
| #56 | /** |
| #57 | * Host the agent card at /.well-known/agent-card.json |
| #58 | * by exposing a simple HTTP server on a port. |
| #59 | */ |
| #60 | export async function hostAgentCard(card, runtime, port = 8004) { |
| #61 | const cardJson = serializeAgentCard(card); |
| #62 | // Write a simple server script |
| #63 | const serverScript = ` |
| #64 | const http = require('http'); |
| #65 | const card = ${cardJson}; |
| #66 | |
| #67 | const server = http.createServer((req, res) => { |
| #68 | if (req.url === '/.well-known/agent-card.json' || req.url === '/agent-card.json') { |
| #69 | res.writeHead(200, { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*' }); |
| #70 | res.end(JSON.stringify(card, null, 2)); |
| #71 | } else { |
| #72 | res.writeHead(404); |
| #73 | res.end('Not Found'); |
| #74 | } |
| #75 | }); |
| #76 | |
| #77 | server.listen(${port}, () => console.log('Agent card server on port ${port}')); |
| #78 | `; |
| #79 | await runtime.writeFile("/tmp/agent-card-server.js", serverScript); |
| #80 | // Start server in background |
| #81 | await runtime.exec(`node /tmp/agent-card-server.js &`, 5000); |
| #82 | // Expose port |
| #83 | const portInfo = await runtime.exposePort(port); |
| #84 | return `${portInfo.publicUrl}/.well-known/agent-card.json`; |
| #85 | } |
| #86 | /** |
| #87 | * Write agent card to the state directory for git versioning. |
| #88 | */ |
| #89 | export async function saveAgentCard(card, runtime) { |
| #90 | const cardJson = serializeAgentCard(card); |
| #91 | const home = process.env.HOME || "/root"; |
| #92 | await runtime.writeFile(`${home}/.automaton/agent-card.json`, cardJson); |
| #93 | } |
| #94 | //# sourceMappingURL=agent-card.js.map |