Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
docs(parity): close order 018 and log what shipped, what was measured and the one owner-gated paid call
nirholas5154d165151c
diff --git a/prompts/finish/018-parity-04-agent-as-paid-api.md b/prompts/finish/018-parity-04-agent-as-paid-api.mddeleted file mode 100644index 3ac856d7f..000000000--- a/prompts/finish/018-parity-04-agent-as-paid-api.md+++ /dev/null@@ -1,74 +0,0 @@-# parity 04: sell a whole agent as a paid x402 API--How to run: paste this file's repo path into a fresh Claude Code chat in this repository and say "run this work order". Runnable now. The one real paid call at the end spends real USDC, so it is the single gated step.--## Operating clause (binding)--- Read CLAUDE.md first, then [_context/parity-00-CONTEXT.md](_context/parity-00-CONTEXT.md). CLAUDE.md overrides everything, including this file.-- Finish 100% in this session. Never end the turn with a question, an option list, or an unexecuted plan. A judgment call goes in one line of the final report; it never becomes a question that halts work.-- The only permitted stops are the CLAUDE.md stop-and-ask gates: spending real funds or any irreversible on-chain write, git push or a production deploy, committing content that names a crypto project other than $THREE, and destroying unrecoverable data. Where this order hits one, it says so, and you batch every such ask into ONE message after everything else is done.-- Never name Competitor X in anything you commit. If a reference is unavoidable, write "Competitor X".-- No mocks, no fake data, no placeholder stubs, no unfinished-work markers, no commented-out code. Real APIs and real integrations only.-- The em-dash and en-dash characters are banned in everything you write.-- Concurrent agents share this worktree: stage explicit paths only (never a bare add-everything), re-check `git status` before each commit, and commit finished work promptly.-- Before committing, run `npm run check:rules -- --paths <files you touched>`. It must exit 0.--## Why this matters--Competitor X's "x402 cloud": an owner flips "service active", sets a USD price per request, and gets a stable public endpoint; a buyer POSTs, gets a 402, pays in SOL or USDC on Solana, and the agent runs only after settlement. three.ws sells individual skills, not the agent, and the skill flow does not work end to end.--**Measured 2026-09-30 (production, read-only):**--| What | Value |-|---|---|-| Active rows in `agent_skill_prices` | 376 |-| Rows in `agent_revenue_events` (every sale ever) | 0 |-| Rows in `agent_paid_services` | 0 |-| `agent_payment_intents_status_check` | `CHECK (status IN ('pending','paid','expired','failed'))` |--`consumeIntent` in `api/_lib/x402.js` sets `status='consumed'`, which that constraint rejects, so the legacy per-skill invoke (`api/agents/x402/[action].js`) fails with a database error AFTER the buyer paid. Other defects in that legacy flow (from a code read): `pay-prep` / `pay-confirm` are session-only, so an autonomous agent cannot buy; `verifyPaid` does not check that the intent's payer is the caller; `emit402` and the manifest can name different recipients; and `emit402` links a manifest path (`/api/agents/:id/x402/:skill/manifest`) that has no route.--The standard x402 v2 stack is healthy and is what to build on: `paidEndpoint` in `api/_lib/x402-paid-endpoint.js` (networks default `['solana','base']`, Solana first), `send402` / `verifyPayment` / `settlePayment` in `api/_lib/x402-spec.js`, spent-payment guards in `api/_lib/x402/spent-payments.js`. The closest pattern to copy is `api/x402/skill-call.js`: a per-request `paidEndpoint` with a `payTo` override and an `onSettled` hook for revenue. One agent turn server-side: `api/agents/talk.js` (non-streaming, persona from `meta.brain`, returns `{response, model, usage}`); `sendMessage` in `api/_lib/agents-v1/messages.js` has the full tool loop and billing but no route.--## Step 0: re-derive the current state-- grep -n "consumed" api/_lib/x402.js- grep -rn "agent_payment_intents_status_check\|agent_payment_intents" api/_lib/migrations/*.sql | head- sed -n 150,270p api/x402/skill-call.js- sed -n 90,200p api/agents/talk.js- grep -n "resolvePayoutAddress" -A20 api/_lib/payout.js | head -30--Re-run the four production counts above with a SELECT-only throwaway script in `scripts/.tmp-*.mjs` (`DATABASE_URL` from `.env.local`; delete it after).--## Tasks--1. **Stop the legacy flow failing after payment.** A migration that widens `agent_payment_intents_status_check` to include `consumed`, with a test that runs `consumeIntent` against the real constraint definition. Fix the dead manifest link in `emit402`. Make `emit402` and the manifest resolve the recipient the same way. Bind an intent to its payer in `verifyPaid`. Each fix has a test that fails on the old code.-2. **The agent endpoint.** `POST /api/x402/agents/:agentId` (and a slug alias if agents have slugs): a per-request `paidEndpoint` priced from the agent's service config, `payTo` the agent's payout address (`resolvePayoutAddress`, Solana USDC first), handler runs one turn (extract the core of `api/agents/talk.js` into a shared function both use, rather than copying it), default mode (handler before settle, so a failed turn is never charged), and `onSettled` writes `agent_revenue_events` net of `PLATFORM_FEE_BPS` (`api/_lib/fee.js`). Body `{ "message": "...", "history": [] }` capped in size; response `{ "reply", "model", "usage" }`. Only public agents whose `embed_policy` allows it can be sold.-3. **Owner switch.** On the agent wallet's Earn tab (`src/agent-wallet-hub/tabs/earn.js` via `src/agent-economy-hub.js`): "Sell this agent as an API" toggle, price per call in USD, a short public description, then the stable endpoint URL with copy buttons, a ready `curl` showing the 402, and earnings from `agent_revenue_events`. Store the config on the agent (for example `meta.api_service = { active, price_usd, description }`), validated server-side.-4. **Discovery.** List active agent services in `/.well-known/x402.json` (it is generated; find its builder) and in the x402 catalog page, each with price, network and input schema.-5. **Docs.** `docs/x402.md` section "Sell your agent as an API" with the buyer's flow and a runnable `curl`; `docs/api-reference.md`; changelog entry.-6. **The one gated step.** Prove a real paid call on mainnet: the owner message names the agent, the price (keep it at the minimum the facilitator accepts), the payer wallet and the recipient, and asks for a yes. Everything else is proven without spending: the unpaid 402 on production shape, a verify against a malformed payment, and the handler path under test.--## Definition of done--- [ ] The constraint migration is applied (`npm run db:status` then `npm run db:migrate`); a test proves `consumeIntent` succeeds against it.-- [ ] Each legacy defect listed in task 1 has a failing-then-passing test.-- [ ] `curl -i -X POST localhost:3000/api/x402/agents/<active agent id> -d '{"message":"hi"}'` returns 402 with Solana USDC first in `accepts`, the agent's payout address as `payTo`, and the configured price.-- [ ] The owner toggle, price, endpoint and earnings render on the Earn tab, browser-verified at 375, 768 and 1440 px, both themes, zero console errors.-- [ ] Active services appear in `/.well-known/x402.json` (`npm run audit:x402-catalog` passes).-- [ ] Docs and changelog updated; the owner message for the one real paid call was sent (or the call was made on the owner's yes, with its signature in the report).--## Never blocked--| Blocker | Resolution (act, do not ask) |-|---|---|-| The agent has no payout address | Fall back exactly as `resolvePayoutAddress` does (the agent's own wallet); refuse to activate a service with no Solana address and say why in the UI. |-| The facilitator is down or the settle sponsor is dry (`x402_settle` in `/api/healthz`) | Run the `x402-economy-triage` subagent; ship the code; the live paid proof waits in the owner message. |-| LLM credits or provider errors in the turn | The turn fails before settlement, so the buyer is not charged; surface the error and test that no settlement happened. |--## Close out (required)--1. Verify every Definition of done line with the actual command output in front of you. Never claim a line you did not verify.-2. Commit with explicit paths and a subject that describes the diff (house style: `type(scope): what changed and why a reader cares`).-3. If every Definition of done line passes, delete this file in that same commit (`git rm prompts/finish/018-parity-04-agent-as-paid-api.md`) and append a dated entry to [_context/parity-PROGRESS.md](_context/parity-PROGRESS.md) with the commit SHAs. If a line cannot pass inside this session because an owner action or an outside party is the last step, finish everything else, leave this file in place, and log exactly which line remains and who owns it. Never delete this file on a partial.-4. Final report, in this order: what step 0 measured; what changed (file list with commit SHAs); evidence for each Definition of done line; the single batched owner message, if the order has a gate; one-line judgment calls. No trailing questions.diff --git a/prompts/finish/_context/parity-PROGRESS.md b/prompts/finish/_context/parity-PROGRESS.mdindex 52f821e27..bb8f663ef 100644--- a/prompts/finish/_context/parity-PROGRESS.md+++ b/prompts/finish/_context/parity-PROGRESS.md@@ -29,3 +29,11 @@ Cross-session handoff for the `parity-` orders ([parity-00-CONTEXT.md](parity-00- Creator fees: order 015's read model (`api/_lib/agent-earnings.js`) was present and is loaded lazily, so creator fees are live on entries (e.g. an entry with two coins shows 0.0324 SOL). If that module is ever absent the metric degrades to "Not measured yet", never zero.- Judgment call: a story needs a RESULT (coin, creator fees above zero, or service income above zero); conversations and actions alone do not qualify.- Not browser-exercised: the owner-only "Feature as a success story" button, because no QA account owns a Spotlight entry and creating one would write a public production entry. The consent API behind it is covered by the handler tests.++## 2026-09-30: order 018, sell a whole agent as a paid x402 API++- Shipped: legacy flow fixes and the applied `consumed` constraint migration (`5edff0a92`); shared agent turn for `/api/agents/talk` and the paid route (`198873423`); service rules and ledger `api/_lib/agent-api-service.js` (`1fd28f132`); chain-correct Solana payout fallback plus the `settled_to_wallet` migration that keeps direct-to-wallet sales out of treasury withdrawals (`4fab73f36`); discovery slice and `/x402` Agents category (`b55a31752`); Earn tab card (`51a3cc3ba`); paid route `POST /api/x402/agents/:id`, free list, owner switch `GET|PUT /api/agents/:id/api-service`, PGlite route tests (`bca757e2a`); ring-catalog exclusion by a concurrent agent (`e03e571fe`); changelog entry (`e36c66e6e`); docs, STRUCTURE row, one-click Solana wallet on the Earn card (`90e8b718e`). Several of these were committed by concurrent agents sweeping the worktree; the messages describe the content.+- Measured before the work (production, read-only): 376 active `agent_skill_prices`, 0 `agent_revenue_events`, 0 `agent_paid_services`, `agent_payment_intents_status_check` without `consumed` (now widened). Also found: `agent_identities.wallet_address` is an EVM address on most rows, so `api/_lib/payout.js` handed a 0x address to Solana payTo; fixed.+- Migrations `20260930140000_agent_payment_intents_consumed_status.sql` and `20260930141000_agent_revenue_events_settled_to_wallet.sql` are applied (the second was applied by another lane's `db:migrate`; content unchanged).+- Live state: the QA account's agent `7f7c77ff-9007-43fb-9a72-3810d4a082bd` ("My First Agent") now has a custodial Solana wallet `7RnhmSyCxEefewcx4dFdxz6Uvry6xVFr8m6YTQWUStHc` and is on sale at $0.001 as the target for the paid proof. Turn it off from its Earn tab after the proof.+- Remaining owner step (the order's single gate): one real mainnet paid call to that agent after deploy (order 919), paid by the ring payer `X4o2UuVNMxnrgkzVy97kPF5gmS6CLRCVJGB48VastML` (3.46 USDC, 0.0497 SOL on 2026-09-30). Production self-facilitator counters show 11,783 `fee_runway_exhausted` settle failures, so check `x402_settle` in `/api/healthz` before the call.