chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
[
|
||||
{
|
||||
"id": "root",
|
||||
"component": "Row",
|
||||
"children": {
|
||||
"componentId": "flight-card",
|
||||
"path": "/flights"
|
||||
},
|
||||
"gap": 16
|
||||
},
|
||||
{
|
||||
"id": "flight-card",
|
||||
"component": "FlightCard",
|
||||
"airline": { "path": "airline" },
|
||||
"airlineLogo": { "path": "airlineLogo" },
|
||||
"flightNumber": { "path": "flightNumber" },
|
||||
"origin": { "path": "origin" },
|
||||
"destination": { "path": "destination" },
|
||||
"date": { "path": "date" },
|
||||
"departureTime": { "path": "departureTime" },
|
||||
"arrivalTime": { "path": "arrivalTime" },
|
||||
"duration": { "path": "duration" },
|
||||
"status": { "path": "status" },
|
||||
"price": { "path": "price" },
|
||||
"action": {
|
||||
"event": {
|
||||
"name": "book_flight",
|
||||
"context": {
|
||||
"flightNumber": { "path": "flightNumber" },
|
||||
"origin": { "path": "origin" },
|
||||
"destination": { "path": "destination" },
|
||||
"price": { "path": "price" }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,64 @@
|
||||
"""Dynamic A2UI tool: LLM-generated UI from conversation context.
|
||||
|
||||
A secondary LLM (langchain_openai) generates v0.9 A2UI components via a
|
||||
structured tool call. The generate_a2ui tool wraps the output as
|
||||
a2ui_operations, which the middleware/runtime detects and renders
|
||||
automatically. Identical surface to the canonical demo's tool —
|
||||
implementation differs only by the secondary-LLM wiring.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from typing import Any, Dict, List
|
||||
|
||||
from copilotkit import a2ui
|
||||
from langchain_core.messages import SystemMessage
|
||||
from langchain_openai import ChatOpenAI
|
||||
from pydantic import BaseModel, Field
|
||||
from strands import tool
|
||||
|
||||
CATALOG_ID = "copilotkit://app-dashboard-catalog"
|
||||
|
||||
|
||||
class _A2UIRenderArgs(BaseModel):
|
||||
surfaceId: str = "dynamic-surface"
|
||||
catalogId: str = CATALOG_ID
|
||||
components: List[Dict[str, Any]] = Field(default_factory=list)
|
||||
data: Dict[str, Any] = Field(default_factory=dict)
|
||||
|
||||
|
||||
@tool
|
||||
def generate_a2ui(user_intent: str) -> str:
|
||||
"""Generate dynamic A2UI components based on the conversation.
|
||||
|
||||
A secondary LLM designs the UI schema and data. The result is returned
|
||||
as an a2ui_operations container for the runtime to detect and render.
|
||||
"""
|
||||
model = ChatOpenAI(model="gpt-4.1")
|
||||
model_with_tool = model.bind_tools(
|
||||
[_A2UIRenderArgs.model_json_schema()],
|
||||
tool_choice={
|
||||
"type": "function",
|
||||
"function": {"name": "_A2UIRenderArgs"},
|
||||
},
|
||||
)
|
||||
try:
|
||||
response = model_with_tool.invoke([SystemMessage(content=user_intent)])
|
||||
except Exception as exc: # surface LLM/network failures
|
||||
return json.dumps({"error": f"dynamic-a2ui LLM call failed: {exc}"})
|
||||
|
||||
if not response.tool_calls:
|
||||
return json.dumps({"error": "LLM did not emit dynamic A2UI arguments"})
|
||||
|
||||
args = response.tool_calls[0]["args"]
|
||||
parsed = _A2UIRenderArgs.model_validate(args)
|
||||
|
||||
ops = [
|
||||
a2ui.create_surface(parsed.surfaceId, catalog_id=parsed.catalogId),
|
||||
a2ui.update_components(parsed.surfaceId, parsed.components),
|
||||
]
|
||||
if parsed.data:
|
||||
ops.append(a2ui.update_data_model(parsed.surfaceId, parsed.data))
|
||||
|
||||
return a2ui.render(operations=ops)
|
||||
@@ -0,0 +1,61 @@
|
||||
"""Fixed-schema A2UI tool: flight search results.
|
||||
|
||||
Schema is loaded from a JSON file. Only the data changes per invocation.
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
from typing import List
|
||||
|
||||
from copilotkit import a2ui
|
||||
from pydantic import BaseModel
|
||||
from strands import tool
|
||||
|
||||
CATALOG_ID = "copilotkit://app-dashboard-catalog"
|
||||
SURFACE_ID = "flight-search-results"
|
||||
FLIGHT_SCHEMA = a2ui.load_schema(
|
||||
Path(__file__).parent / "a2ui" / "schemas" / "flight_schema.json"
|
||||
)
|
||||
|
||||
|
||||
class Flight(BaseModel):
|
||||
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
|
||||
def search_flights(flights: List[Flight]) -> str:
|
||||
"""Search for flights and display the results as rich cards.
|
||||
|
||||
Return exactly 2 flights. Each flight must have: id, airline (e.g.
|
||||
"United Airlines"), airlineLogo (Google favicon API URL like
|
||||
"https://www.google.com/s2/favicons?domain=united.com&sz=128"),
|
||||
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,
|
||||
https://placehold.co/12/ef4444/ef4444.png for Cancelled), and price
|
||||
(e.g. "$289").
|
||||
"""
|
||||
# Strands @tool passes plain dicts to the function body, so ``flights``
|
||||
# is a list of dicts here. Validate to enforce the schema, then dump
|
||||
# for a2ui rendering.
|
||||
flights_payload = [Flight.model_validate(f).model_dump() for f in flights]
|
||||
return a2ui.render(
|
||||
operations=[
|
||||
a2ui.create_surface(SURFACE_ID, catalog_id=CATALOG_ID),
|
||||
a2ui.update_components(SURFACE_ID, FLIGHT_SCHEMA),
|
||||
a2ui.update_data_model(SURFACE_ID, {"flights": flights_payload}),
|
||||
],
|
||||
)
|
||||
@@ -0,0 +1,41 @@
|
||||
date,category,subcategory,amount,type,notes
|
||||
2026-01-05,Revenue,Enterprise Subscriptions,28000,income,3 new enterprise customers (Acme Corp, TechFlow, DataViz Inc)
|
||||
2026-01-05,Revenue,Pro Tier Upgrades,18000,income,24 users upgraded from free to pro
|
||||
2026-01-08,Revenue,API Usage Overages,9500,income,High API usage from top 5 customers
|
||||
2026-01-10,Expenses,Engineering Salaries,42000,expense,7 engineers + 2 contractors
|
||||
2026-01-10,Expenses,Product Team,18000,expense,PM and 2 designers
|
||||
2026-01-12,Expenses,AWS Infrastructure,8200,expense,Increased compute for new AI features
|
||||
2026-01-15,Expenses,Marketing - Paid Ads,12000,expense,Google Ads and LinkedIn campaigns
|
||||
2026-01-18,Revenue,Consulting Services,14500,income,Custom integration for Acme Corp
|
||||
2026-01-20,Expenses,Customer Success,15000,expense,3 CSMs + support tools (Intercom)
|
||||
2026-01-22,Expenses,AI Model Costs,4200,expense,OpenAI API usage for product features
|
||||
2026-01-25,Revenue,Marketplace Sales,12800,income,Template and plugin sales
|
||||
2026-01-28,Expenses,Office & Equipment,3500,expense,New laptops and coworking spaces
|
||||
2026-02-03,Revenue,Enterprise Subscriptions,31000,income,2 new customers + expansion from TechFlow
|
||||
2026-02-03,Revenue,Pro Tier Upgrades,22500,income,31 upgrades + reduced churn
|
||||
2026-02-05,Revenue,API Usage Overages,11800,income,DataViz Inc heavy API usage spike
|
||||
2026-02-07,Expenses,Engineering Salaries,42000,expense,Same headcount as January
|
||||
2026-02-07,Expenses,Product Team,18000,expense,No changes to product team
|
||||
2026-02-10,Expenses,AWS Infrastructure,9500,expense,Traffic spike from viral social post
|
||||
2026-02-12,Expenses,Marketing - Paid Ads,15000,expense,Increased ad spend for Q1 push
|
||||
2026-02-14,Revenue,Consulting Services,18000,income,2 custom projects (TechFlow + new client)
|
||||
2026-02-18,Expenses,Customer Success,16500,expense,Hired 1 additional CSM
|
||||
2026-02-20,Expenses,AI Model Costs,5800,expense,Increased usage from new AI features launch
|
||||
2026-02-22,Revenue,Marketplace Sales,14200,income,Top template hit featured list
|
||||
2026-02-25,Expenses,Conference & Travel,4500,expense,Team attended SaaS Conference 2026
|
||||
2026-02-27,Revenue,Partnership Revenue,11500,income,Referral fees from integration partners
|
||||
2026-03-02,Revenue,Enterprise Subscriptions,35000,income,Major win: Fortune 500 customer signed
|
||||
2026-03-02,Revenue,Pro Tier Upgrades,26000,income,42 upgrades - best month yet
|
||||
2026-03-05,Revenue,API Usage Overages,13200,income,Consistent high usage across top tier
|
||||
2026-03-08,Expenses,Engineering Salaries,48000,expense,Hired 1 senior engineer for AI team
|
||||
2026-03-08,Expenses,Product Team,21000,expense,Promoted designer to senior level
|
||||
2026-03-10,Expenses,AWS Infrastructure,11000,expense,Scaled infrastructure for enterprise client
|
||||
2026-03-12,Expenses,Marketing - Paid Ads,18000,expense,Doubled down on successful campaigns
|
||||
2026-03-14,Revenue,Consulting Services,21500,income,Fortune 500 onboarding + 2 other projects
|
||||
2026-03-16,Expenses,Customer Success,19500,expense,Hired dedicated enterprise CSM
|
||||
2026-03-18,Expenses,AI Model Costs,7200,expense,Fortune 500 client heavy AI usage
|
||||
2026-03-20,Revenue,Marketplace Sales,15800,income,3 new templates in top 10
|
||||
2026-03-22,Expenses,Sales & BD,12000,expense,Hired first sales rep for enterprise
|
||||
2026-03-24,Revenue,Partnership Revenue,14200,income,New integration partnerships launched
|
||||
2026-03-26,Expenses,Security & Compliance,6500,expense,SOC 2 audit and security tools
|
||||
2026-03-28,Revenue,Training & Workshops,10200,income,Conducted 2 customer training sessions
|
||||
|
@@ -0,0 +1,20 @@
|
||||
import csv
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from strands import tool
|
||||
|
||||
# Read data at module load time to avoid file I/O issues in sandboxed
|
||||
# tool execution environments.
|
||||
_csv_path = Path(__file__).parent / "db.csv"
|
||||
with open(_csv_path) as _f:
|
||||
_cached_data = list(csv.DictReader(_f))
|
||||
|
||||
|
||||
@tool
|
||||
def query_data(query: str) -> str:
|
||||
"""Query the database with a natural-language query.
|
||||
|
||||
Always call this before rendering a chart so the UI has data to plot.
|
||||
"""
|
||||
return json.dumps(_cached_data)
|
||||
@@ -0,0 +1,42 @@
|
||||
from uuid import uuid4
|
||||
|
||||
from pydantic import BaseModel
|
||||
from strands import tool
|
||||
|
||||
|
||||
class Todo(BaseModel):
|
||||
id: str = ""
|
||||
title: str
|
||||
description: str
|
||||
emoji: str
|
||||
status: str = "pending" # "pending" | "completed"
|
||||
|
||||
|
||||
@tool
|
||||
def manage_todos(todos: list[Todo]) -> str:
|
||||
"""Manage the current todos.
|
||||
|
||||
IMPORTANT: Always pass the full list, not just new items. Each todo
|
||||
should have a title, description, emoji, and status (pending/completed).
|
||||
"""
|
||||
# Strands @tool passes ``model_dump()`` output, so list elements arrive
|
||||
# as plain dicts. Rehydrate before accessing fields.
|
||||
todos = [Todo.model_validate(t) for t in todos]
|
||||
for todo in todos:
|
||||
if not todo.id:
|
||||
todo.id = str(uuid4())
|
||||
return "Successfully updated todos"
|
||||
|
||||
|
||||
@tool
|
||||
def get_todos() -> str:
|
||||
"""Get the current todos.
|
||||
|
||||
The current list is injected into the prompt by the state context
|
||||
builder, so this tool just acknowledges that and tells the model to
|
||||
read it from there.
|
||||
"""
|
||||
return "See the current todos list already provided in the conversation context."
|
||||
|
||||
|
||||
todo_tools = [manage_todos, get_todos]
|
||||
Reference in New Issue
Block a user