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 | * CLAWD Convex Client |
| #3 | * |
| #4 | * Lightweight HTTP client for the automaton to communicate with |
| #5 | * the CLAWD Convex backend for agent tracking, heartbeats, and |
| #6 | * key-value data storage. |
| #7 | * |
| #8 | * Uses the Convex HTTP actions defined in convex/clawd/http.ts. |
| #9 | * No external dependencies needed — just uses fetch. |
| #10 | */ |
| #11 | /** |
| #12 | * Creates a CLAWD Convex client for the automaton. |
| #13 | */ |
| #14 | export function createConvexClient(options) { |
| #15 | const baseUrl = options.siteUrl.replace(/\/$/, ''); |
| #16 | const defaultAgentId = options.agentId; |
| #17 | /** |
| #18 | * Make an HTTP request to a CLAWD endpoint. |
| #19 | */ |
| #20 | async function request(method, path, body) { |
| #21 | const url = `${baseUrl}${path}`; |
| #22 | const headers = { |
| #23 | 'Content-Type': 'application/json', |
| #24 | }; |
| #25 | if (defaultAgentId) { |
| #26 | headers['X-Agent-Id'] = defaultAgentId; |
| #27 | } |
| #28 | const resp = await fetch(url, { |
| #29 | method, |
| #30 | headers, |
| #31 | body: body ? JSON.stringify(body) : undefined, |
| #32 | }); |
| #33 | if (!resp.ok) { |
| #34 | const text = await resp.text(); |
| #35 | throw new Error(`Convex API error: ${method} ${path} -> ${resp.status}: ${text}`); |
| #36 | } |
| #37 | return resp.json(); |
| #38 | } |
| #39 | /** |
| #40 | * Register / install an agent. |
| #41 | */ |
| #42 | async function registerAgent(params) { |
| #43 | return request('POST', '/clawd/register', { |
| #44 | agentId: params.agentId, |
| #45 | name: params.name, |
| #46 | installMethod: params.installMethod || 'automaton', |
| #47 | source: params.source, |
| #48 | metadata: params.metadata, |
| #49 | address: params.address, |
| #50 | tags: params.tags, |
| #51 | }); |
| #52 | } |
| #53 | /** |
| #54 | * Push a heartbeat. |
| #55 | */ |
| #56 | async function sendHeartbeat(params) { |
| #57 | return request('POST', '/clawd/heartbeat', { |
| #58 | agentId: params.agentId, |
| #59 | state: params.state, |
| #60 | creditsCents: params.creditsCents, |
| #61 | usdcBalance: params.usdcBalance, |
| #62 | uptimeSeconds: params.uptimeSeconds, |
| #63 | version: params.version, |
| #64 | sandboxId: params.sandboxId, |
| #65 | turnCount: params.turnCount, |
| #66 | skillCount: params.skillCount, |
| #67 | tier: params.tier, |
| #68 | statusPayload: params.statusPayload, |
| #69 | }); |
| #70 | } |
| #71 | /** |
| #72 | * Store key-value data for an agent. |
| #73 | */ |
| #74 | async function setData(params) { |
| #75 | return request('POST', '/clawd/data', { |
| #76 | agentId: params.agentId, |
| #77 | key: params.key, |
| #78 | value: params.value, |
| #79 | contentType: params.contentType, |
| #80 | tags: params.tags, |
| #81 | }); |
| #82 | } |
| #83 | /** |
| #84 | * Retrieve data for an agent by key. |
| #85 | */ |
| #86 | async function getData(params) { |
| #87 | return request('GET', `/clawd/data?agentId=${encodeURIComponent(params.agentId)}&key=${encodeURIComponent(params.key)}`); |
| #88 | } |
| #89 | /** |
| #90 | * List all data keys for an agent. |
| #91 | */ |
| #92 | async function listData(params) { |
| #93 | return request('GET', `/clawd/data/list?agentId=${encodeURIComponent(params.agentId)}`); |
| #94 | } |
| #95 | /** |
| #96 | * Get agent info + latest heartbeat. |
| #97 | */ |
| #98 | async function getAgent(params) { |
| #99 | return request('GET', `/clawd/agent?agentId=${encodeURIComponent(params.agentId)}`); |
| #100 | } |
| #101 | /** |
| #102 | * List all agents (optionally only active ones). |
| #103 | */ |
| #104 | async function listAgents(params) { |
| #105 | const activeParam = params?.activeOnly ? '?active=true' : ''; |
| #106 | return request('GET', `/clawd/agents${activeParam}`); |
| #107 | } |
| #108 | return { |
| #109 | registerAgent, |
| #110 | sendHeartbeat, |
| #111 | setData, |
| #112 | getData, |
| #113 | listData, |
| #114 | getAgent, |
| #115 | listAgents, |
| #116 | }; |
| #117 | } |
| #118 | //# sourceMappingURL=convex-client.js.map |