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 | |
| #9 | import type { |
| #10 | AgentCard, |
| #11 | AgentService, |
| #12 | AutomatonConfig, |
| #13 | AutomatonIdentity, |
| #14 | AutomatonDatabase, |
| #15 | ClawdRuntimeClient, |
| #16 | } from "../types.js"; |
| #17 | |
| #18 | const AGENT_CARD_TYPE = |
| #19 | "https://eips.ethereum.org/EIPS/eip-8004#registration-v1"; |
| #20 | |
| #21 | /** |
| #22 | * Generate an agent card from the automaton's current state. |
| #23 | */ |
| #24 | export function generateAgentCard( |
| #25 | identity: AutomatonIdentity, |
| #26 | config: AutomatonConfig, |
| #27 | db: AutomatonDatabase, |
| #28 | ): AgentCard { |
| #29 | const services: AgentService[] = [ |
| #30 | { |
| #31 | name: "agentWallet", |
| #32 | endpoint: `eip155:8453:${identity.address}`, |
| #33 | }, |
| #34 | { |
| #35 | name: "runtime", |
| #36 | endpoint: config.clawdApiUrl, |
| #37 | }, |
| #38 | ]; |
| #39 | |
| #40 | // Add sandbox endpoint if available |
| #41 | if (identity.sandboxId) { |
| #42 | services.push({ |
| #43 | name: "sandbox", |
| #44 | endpoint: `https://${identity.sandboxId}.life.x402.wtf`, |
| #45 | }); |
| #46 | } |
| #47 | |
| #48 | const children = db.getChildren(); |
| #49 | const skills = db.getSkills(true); |
| #50 | |
| #51 | let description = `Autonomous agent running on CLAWD Cloud.`; |
| #52 | description += ` Creator: ${config.creatorAddress}.`; |
| #53 | if (skills.length > 0) { |
| #54 | description += ` Skills: ${skills.map((s) => s.name).join(", ")}.`; |
| #55 | } |
| #56 | if (children.length > 0) { |
| #57 | description += ` Children: ${children.length}.`; |
| #58 | } |
| #59 | |
| #60 | return { |
| #61 | type: AGENT_CARD_TYPE, |
| #62 | name: config.name, |
| #63 | description, |
| #64 | services, |
| #65 | x402Support: true, |
| #66 | active: true, |
| #67 | parentAgent: config.parentAddress || config.creatorAddress, |
| #68 | }; |
| #69 | } |
| #70 | |
| #71 | /** |
| #72 | * Serialize agent card to JSON string. |
| #73 | */ |
| #74 | export function serializeAgentCard(card: AgentCard): string { |
| #75 | return JSON.stringify(card, null, 2); |
| #76 | } |
| #77 | |
| #78 | /** |
| #79 | * Host the agent card at /.well-known/agent-card.json |
| #80 | * by exposing a simple HTTP server on a port. |
| #81 | */ |
| #82 | export async function hostAgentCard( |
| #83 | card: AgentCard, |
| #84 | runtime: ClawdRuntimeClient, |
| #85 | port: number = 8004, |
| #86 | ): Promise<string> { |
| #87 | const cardJson = serializeAgentCard(card); |
| #88 | |
| #89 | // Write a simple server script |
| #90 | const serverScript = ` |
| #91 | const http = require('http'); |
| #92 | const card = ${cardJson}; |
| #93 | |
| #94 | const server = http.createServer((req, res) => { |
| #95 | if (req.url === '/.well-known/agent-card.json' || req.url === '/agent-card.json') { |
| #96 | res.writeHead(200, { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*' }); |
| #97 | res.end(JSON.stringify(card, null, 2)); |
| #98 | } else { |
| #99 | res.writeHead(404); |
| #100 | res.end('Not Found'); |
| #101 | } |
| #102 | }); |
| #103 | |
| #104 | server.listen(${port}, () => console.log('Agent card server on port ${port}')); |
| #105 | `; |
| #106 | |
| #107 | await runtime.writeFile("/tmp/agent-card-server.js", serverScript); |
| #108 | |
| #109 | // Start server in background |
| #110 | await runtime.exec( |
| #111 | `node /tmp/agent-card-server.js &`, |
| #112 | 5000, |
| #113 | ); |
| #114 | |
| #115 | // Expose port |
| #116 | const portInfo = await runtime.exposePort(port); |
| #117 | |
| #118 | return `${portInfo.publicUrl}/.well-known/agent-card.json`; |
| #119 | } |
| #120 | |
| #121 | /** |
| #122 | * Write agent card to the state directory for git versioning. |
| #123 | */ |
| #124 | export async function saveAgentCard( |
| #125 | card: AgentCard, |
| #126 | runtime: ClawdRuntimeClient, |
| #127 | ): Promise<void> { |
| #128 | const cardJson = serializeAgentCard(card); |
| #129 | const home = process.env.HOME || "/root"; |
| #130 | await runtime.writeFile(`${home}/.automaton/agent-card.json`, cardJson); |
| #131 | } |
| #132 |