Files
copilotkit__copilotkit/examples/integrations/claude-sdk-python/agent/src/a2ui_fixed_schema.py
Tyler Slaton c6061f2e47 fix(examples): address CodeRabbit review on Claude Agent SDK starters
Resolve the real issues surfaced by CodeRabbit on the new claude-sdk-python /
claude-sdk-typescript starters (frontend files are shared, so most fixes apply
to both):

- Fix two type errors that `ignoreBuildErrors` was masking: `JSX.IntrinsicElements`
  -> `React.JSX.IntrinsicElements` (@types/react 19) and the Recharts `<Bar shape>`
  callback type; then drop the blanket `typescript.ignoreBuildErrors` from
  next.config.ts so source type-checks. The Dockerfile's build-time patch still
  re-adds it for the `next@latest` Docker build, so deploy behavior is unchanged.
- Fix Tailwind v4 CSS-variable syntax: `bg-[--x]` -> `bg-[var(--x)]`, and
  `border-3` -> `border-[3px]` (border-3 is not a utility -> invisible spinner).
- Harden the agent tools: omit the empty ANTHROPIC_API_KEY, wrap the Anthropic
  call in try/catch (TS + Python), normalize the AGENT_URL trailing slash, and
  make the Flight schema's id/airlineLogo/statusIcon required to match the
  "must have" tool description.
- Minor a11y: mode-toggle `aria-pressed`/`type`/`role`, headless-chat `<form>`
  + `aria-label` (Enter-to-submit).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-09 17:27:28 -07:00

65 lines
2.0 KiB
Python

"""Fixed-schema A2UI tool — flight search results.
The A2UI component schema is loaded from JSON; only the flight data changes per
call. The tool result carries ``a2ui_operations``, which the frontend renders.
"""
from __future__ import annotations
from pathlib import Path
from typing import Any, TypedDict
from claude_agent_sdk import tool
from copilotkit import a2ui
CATALOG_ID = "copilotkit://app-dashboard-catalog"
FLIGHT_SURFACE_ID = "flight-search-results"
FLIGHT_SCHEMA = a2ui.load_schema(
Path(__file__).parent / "a2ui" / "schemas" / "flight_schema.json"
)
class Flight(TypedDict):
id: str
airline: str
airlineLogo: str
flightNumber: str
origin: str
destination: str
date: str
departureTime: str
arrivalTime: str
duration: str
status: str
statusIcon: str
price: str
@tool(
"search_flights",
"Search for flights and display the results as rich cards. Return exactly 2 "
"flights. Each flight must have: id, airline, airlineLogo (Google favicon API "
"URL for the airline domain), flightNumber, origin, destination, date (e.g. "
'"Tue, Mar 18" — use near-future dates), departureTime, arrivalTime, duration '
'(e.g. "4h 25m"), status (e.g. "On Time" or "Delayed"), statusIcon (colored '
"dot URL: https://placehold.co/12/22c55e/22c55e.png for On Time, "
'https://placehold.co/12/eab308/eab308.png for Delayed), and price (e.g. "$289").',
{"flights": list[Flight]},
)
async def search_flights(args: dict[str, Any]) -> dict[str, Any]:
flights = args.get("flights", [])
return {
"content": [
{
"type": "text",
"text": a2ui.render(
operations=[
a2ui.create_surface(FLIGHT_SURFACE_ID, catalog_id=CATALOG_ID),
a2ui.update_components(FLIGHT_SURFACE_ID, FLIGHT_SCHEMA),
a2ui.update_data_model(FLIGHT_SURFACE_ID, {"flights": flights}),
]
),
}
]
}