Skip to content

[#993] Redesign Link AI Writer flow: fetch tokenURI first, pre-fill agent data#995

Merged
realproject7 merged 4 commits intomainfrom
task/993-redesign-link-ai-writer
Apr 24, 2026
Merged

[#993] Redesign Link AI Writer flow: fetch tokenURI first, pre-fill agent data#995
realproject7 merged 4 commits intomainfrom
task/993-redesign-link-ai-writer

Conversation

@realproject7
Copy link
Copy Markdown
Owner

Summary

Fixes #993

  • New GET /api/user/lookup-agent endpoint: fetches agent data via balanceOftokenOfOwnerByIndextokenURI RPC calls; supports manual agent ID fallback when enumeration isn't available
  • Simplified POST /api/user/link-agent: accepts pre-fetched agent metadata from frontend (no RPC calls during linking), stores agent_id/name/description/genre in DB
  • Redesigned LinkAIWriter component: multi-step flow — enter OWS wallet → click Lookup → view agent info card → paste binding signature → link
  • Fixed erc8004.ts: added tokenURI to ABI, getAgentMetadata/getAgentMetadataById now try tokenURI first (falls back to agentURI)
  • Version bump 1.0.2 → 1.1.0

Test plan

  • Enter OWS wallet address + click Lookup → agent info card displays
  • Agent ID is pre-filled from lookup (user doesn't type it)
  • When tokenOfOwnerByIndex fails, manual agent ID input appears
  • Only binding signature needs manual paste after lookup
  • Profile shows correct agent name after linking
  • Direct registration flow remains unchanged
  • Build passes (npm run build)

🤖 Generated with Claude Code

…data

- Add GET /api/user/lookup-agent endpoint: fetches agent via balanceOf +
  tokenOfOwnerByIndex + tokenURI, with manual ID fallback
- Simplify POST /api/user/link-agent: accept pre-fetched agent metadata
  (no RPC calls during linking step)
- Redesign LinkAIWriter component to multi-step flow: wallet input with
  Lookup button → agent info card → binding signature → link
- Fix erc8004.ts: add tokenURI to ABI, prefer tokenURI over agentURI
  (agentURI reverts on this contract)
- Bump version 1.0.2 → 1.1.0

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 24, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
plotlink Ignored Ignored Apr 24, 2026 6:39am

Request Review

Copy link
Copy Markdown
Collaborator

@project7-interns project7-interns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: REQUEST CHANGES

Summary

The lookup-first UX is headed in the right direction, but the server now trusts client-supplied agent metadata during linking and it still drops part of the tokenURI payload that the issue requires us to persist.

Findings

  • [high] POST /api/user/link-agent writes agentId / agentName / agentDescription / agentGenre straight from the request body into the OWS user row after only verifying the wallet signatures. A caller can bypass the lookup endpoint and submit arbitrary metadata for any OWS wallet they control, which poisons the cached agent record and breaks the intended server-side ownership guarantee.
    • File: src/app/api/user/link-agent/route.ts:129
    • Suggestion: Do not trust these fields from the client. Re-derive the canonical agent data server-side, or have the lookup endpoint mint a server-verifiable payload/signature that the link endpoint verifies before writing metadata.
  • [medium] The new flow still does not persist the full tokenURI data required by the issue. lookup-agent returns llmModel and registeredAt, but LinkAIWriter never sends them and link-agent never stores them, so OWS rows remain inconsistent with direct registration and the "ALL agent data from tokenURI" requirement is not met.
    • File: src/components/AgentRegister.tsx:133
    • Suggestion: Include the missing metadata fields in the POST body and persist them to the corresponding DB columns (agent_llm_model, agent_registered_at).

Decision

Requesting changes because the current link route crosses a trust boundary incorrectly and the stored agent record is still incomplete relative to the issue requirements.

realproject7 and others added 2 commits April 24, 2026 15:36
…n lookup-agent

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…RI on-chain

- link-agent now verifies agentId ownership via ownerOf() and fetches
  canonical metadata from tokenURI server-side (prevents client poisoning)
- All fields stored: agent_name, agent_description, agent_genre,
  agent_llm_model, agent_registered_at
- Frontend simplified to only pass agentId (metadata comes from chain)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@project7-interns project7-interns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: REQUEST CHANGES

Summary

The server-side trust boundary is fixed, but the link route still fails open: it can return success even when the supplied agentId cannot be verified or its metadata cannot be fetched, which leaves the OWS row incomplete while the user sees a successful link.

Findings

  • [medium] POST /api/user/link-agent catches all RPC/metadata lookup failures and still returns { ok: true }. Because the frontend now always sends agentId from the lookup step, a failure here means the link completes without agent_id / agent_name / agent_description / agent_genre / agent_llm_model / agent_registered_at, violating the issue requirement that the DB be populated from tokenURI and making the success state misleading.
    • File: src/app/api/user/link-agent/route.ts:141
    • Suggestion: When agentId is present, fail the request if ownerOf(agentId) does not match owsWallet or if canonical metadata cannot be resolved. Only succeed once the verified metadata has been written.

Decision

Requesting changes because the route still allows a false-success path that skips the required metadata persistence.

ownerOf/tokenURI failures now return 502 instead of silently
proceeding. If agentId is provided, ownership and metadata
must be verified — no silent fallthrough.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@project7-interns project7-interns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: APPROVE

Summary

The link flow now verifies canonical agent ownership/metadata server-side and fails closed when that verification cannot be completed. The lookup-first UX and metadata persistence match the issue requirements.

Findings

  • None.

Decision

Approving. The previous trust-boundary and false-success issues are addressed. Note that e2e and lint-and-typecheck were still pending at the time of review.

@realproject7 realproject7 merged commit c8f3cc6 into main Apr 24, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Redesign Link AI Writer flow: fetch tokenURI first, pre-fill agent data

2 participants