Add agent discovery Link headers#450
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (2)
📝 WalkthroughWalkthroughAdds agent discovery: a linkset-based API catalog generator, a dynamic route serving it at /.well-known/api-catalog with proper headers, and a Next.js root header that advertises the catalog and docs. Changes
Sequence DiagramsequenceDiagram
participant Client
participant Server as Next.js
participant Lib as agent-discovery
participant Route as /.well-known/api-catalog
Client->>Server: GET /
Server->>Server: run headers()
Server->>Lib: read AGENT_DISCOVERY_LINK_HEADER
Server-->>Client: Response with Link header (catalog + docs)
Client->>Route: GET /.well-known/api-catalog
Route->>Route: derive origin from request URL
Route->>Lib: buildApiCatalog(origin)
Lib-->>Route: linkset JSON
Route-->>Client: 200 application/linkset+json + Link self header
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Review rate limit: 0/5 reviews remaining, refill in 48 minutes and 3 seconds. Comment |
Benchmark Results407 benchmarks Interpreted: 🟢 356 improved · 🔴 7 regressed · 44 unchanged · avg +9.0% arraybuffer.js — Interp: 🟢 9, 5 unch. · avg +8.2% · Bytecode: 🟢 2, 🔴 5, 7 unch. · avg -1.4%
arrays.js — Interp: 🟢 19 · avg +9.2% · Bytecode: 🔴 16, 3 unch. · avg -6.0%
async-await.js — Interp: 🟢 5, 1 unch. · avg +7.5% · Bytecode: 🟢 1, 🔴 1, 4 unch. · avg +0.8%
async-generators.js — Interp: 🟢 2 · avg +10.4% · Bytecode: 🔴 1, 1 unch. · avg -2.6%
base64.js — Interp: 🟢 10 · avg +9.1% · Bytecode: 🔴 8, 2 unch. · avg -4.7%
classes.js — Interp: 🟢 23, 8 unch. · avg +6.5% · Bytecode: 🟢 3, 🔴 9, 19 unch. · avg -2.4%
closures.js — Interp: 🟢 11 · avg +8.5% · Bytecode: 🔴 8, 3 unch. · avg -5.2%
collections.js — Interp: 🟢 12 · avg +10.3% · Bytecode: 🟢 3, 🔴 2, 7 unch. · avg +0.3%
csv.js — Interp: 🟢 12, 1 unch. · avg +10.6% · Bytecode: 🔴 13 · avg -9.1%
destructuring.js — Interp: 🟢 22 · avg +9.5% · Bytecode: 🟢 1, 🔴 11, 10 unch. · avg -3.3%
fibonacci.js — Interp: 🟢 8 · avg +8.8% · Bytecode: 🔴 2, 6 unch. · avg -0.8%
float16array.js — Interp: 🟢 28, 🔴 4 · avg +4.4% · Bytecode: 🟢 7, 🔴 14, 11 unch. · avg +1.9%
for-of.js — Interp: 🟢 1, 6 unch. · avg +0.7% · Bytecode: 7 unch. · avg +0.2%
generators.js — Interp: 🟢 4 · avg +13.9% · Bytecode: 🔴 4 · avg -8.1%
iterators.js — Interp: 🟢 36, 6 unch. · avg +7.0% · Bytecode: 🟢 15, 🔴 9, 18 unch. · avg +2.1%
json.js — Interp: 🟢 20 · avg +9.2% · Bytecode: 🔴 20 · avg -11.3%
jsx.jsx — Interp: 🟢 21 · avg +7.6% · Bytecode: 🔴 14, 7 unch. · avg -5.1%
modules.js — Interp: 🟢 9 · avg +9.1% · Bytecode: 🔴 9 · avg -8.1%
numbers.js — Interp: 🟢 9, 2 unch. · avg +6.5% · Bytecode: 🟢 1, 🔴 9, 1 unch. · avg -6.2%
objects.js — Interp: 🟢 7 · avg +15.1% · Bytecode: 🔴 6, 1 unch. · avg -11.1%
promises.js — Interp: 🟢 10, 2 unch. · avg +5.5% · Bytecode: 🟢 1, 🔴 4, 7 unch. · avg -1.7%
regexp.js — Interp: 🟢 8, 3 unch. · avg +4.7% · Bytecode: 🔴 11 · avg -6.7%
strings.js — Interp: 🟢 19 · avg +13.0% · Bytecode: 🔴 19 · avg -8.5%
tsv.js — Interp: 🟢 9 · avg +11.3% · Bytecode: 🔴 8, 1 unch. · avg -8.3%
typed-arrays.js — Interp: 🟢 17, 🔴 2, 3 unch. · avg +16.4% · Bytecode: 🟢 7, 🔴 8, 7 unch. · avg -9.6%
uint8array-encoding.js — Interp: 🟢 13, 5 unch. · avg +4.2% · Bytecode: 🟢 3, 🔴 10, 5 unch. · avg -0.9%
weak-collections.js — Interp: 🟢 12, 🔴 1, 2 unch. · avg +25.5% · Bytecode: 🟢 3, 🔴 9, 3 unch. · avg +2.5%
Measured on ubuntu-latest x64. Benchmark ranges compare cached main-branch min/max ops/sec with the PR run; overlapping ranges are treated as unchanged noise. Percentage deltas are secondary context. |
Suite Timing
Measured on ubuntu-latest x64. |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
website/src/app/.well-known/api-catalog/route.ts (1)
6-12: Prefer an absolute URI forrel="self"in theLinkheaderUsing an absolute URI here improves consistency with
anchorand removes client-side ambiguity around relative resolution.Proposed update
export function GET(req: Request) { const origin = new URL(req.url).origin; + const self = new URL(API_CATALOG_PATH, origin).toString(); return new Response(JSON.stringify(buildApiCatalog(origin), null, 2), { headers: { "Content-Type": 'application/linkset+json; profile="https://www.rfc-editor.org/info/rfc9727"; charset=utf-8', - Link: `<${API_CATALOG_PATH}>; rel="self"; type="application/linkset+json"`, + Link: `<${self}>; rel="self"; type="application/linkset+json"`, }, }); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@website/src/app/.well-known/api-catalog/route.ts` around lines 6 - 12, The Link header currently uses the relative API_CATALOG_PATH which can cause ambiguous resolution; change it to an absolute URI by resolving API_CATALOG_PATH against the request origin (use the same origin you pass to buildApiCatalog from req.url) and put that absolute URL in the Link header (e.g. via new URL(API_CATALOG_PATH, origin) or equivalent) while keeping the rest of the header values identical; update the Link value creation near where origin, buildApiCatalog, and API_CATALOG_PATH are referenced.website/src/__tests__/agent-discovery.test.ts (1)
49-51: Reduce order-coupling in endpoint assertionThis assertion is slightly brittle because it depends on array ordering. Prefer containment-based matching so reordering doesn’t break intent.
Proposed update
- expect(body.linkset[0].item[0].href).toBe( - "https://example.test/api/execute", - ); + expect(body.linkset[0].item).toContainEqual({ + href: "https://example.test/api/execute", + type: "application/json", + });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@website/src/__tests__/agent-discovery.test.ts` around lines 49 - 51, The assertion currently depends on indexing into body.linkset[0].item[0].href which is order-sensitive; change it to a containment-based check that scans the item array for the expected href (e.g., map item entries to their hrefs and assert the resulting array contains "https://example.test/api/execute" or use Array.prototype.some to assert any item.href matches) so the test passes even if items are reordered; update the assertion referencing body.linkset[0].item (in agent-discovery.test.ts) accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@website/src/__tests__/agent-discovery.test.ts`:
- Around line 49-51: The assertion currently depends on indexing into
body.linkset[0].item[0].href which is order-sensitive; change it to a
containment-based check that scans the item array for the expected href (e.g.,
map item entries to their hrefs and assert the resulting array contains
"https://example.test/api/execute" or use Array.prototype.some to assert any
item.href matches) so the test passes even if items are reordered; update the
assertion referencing body.linkset[0].item (in agent-discovery.test.ts)
accordingly.
In `@website/src/app/.well-known/api-catalog/route.ts`:
- Around line 6-12: The Link header currently uses the relative API_CATALOG_PATH
which can cause ambiguous resolution; change it to an absolute URI by resolving
API_CATALOG_PATH against the request origin (use the same origin you pass to
buildApiCatalog from req.url) and put that absolute URL in the Link header (e.g.
via new URL(API_CATALOG_PATH, origin) or equivalent) while keeping the rest of
the header values identical; update the Link value creation near where origin,
buildApiCatalog, and API_CATALOG_PATH are referenced.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 917d7f5b-4925-4083-bc64-86a04253acb6
📒 Files selected for processing (4)
website/next.config.tswebsite/src/__tests__/agent-discovery.test.tswebsite/src/app/.well-known/api-catalog/route.tswebsite/src/lib/agent-discovery.ts
Summary
Linkheaders on the homepage forapi-catalogandservice-docdiscovery./.well-known/api-catalogas anapplication/linkset+jsonroute listing public API endpoints and docs.Verification
bun run lintbun testbun run buildcurl -I http://localhost:3210/confirmedrel="api-catalog"andrel="service-doc"headers.curl http://localhost:3210/.well-known/api-catalogreturned Linkset JSON.