chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 12:58:18 +08:00
commit 6d5d58c1a9
18293 changed files with 3502153 additions and 0 deletions
@@ -0,0 +1,36 @@
"""query_data tool — returns rows from the sample financial database."""
from __future__ import annotations
import csv
import json
from pathlib import Path
from typing import Any
from claude_agent_sdk import tool
# Read the CSV once at import. The notes column can contain unquoted commas, so
# keep the first N-1 fields and join the remainder into the last column.
_CSV_PATH = Path(__file__).parent / "db.csv"
with open(_CSV_PATH, newline="") as _f:
_reader = csv.reader(_f)
_header = next(_reader)
_last = len(_header) - 1
_CACHED_DATA = [
{
**{_header[i]: (row[i] if i < len(row) else "") for i in range(_last)},
_header[_last]: ",".join(row[_last:]),
}
for row in _reader
if row
]
@tool(
"query_data",
"Query the financial database with a natural-language query. Always call "
"this before rendering a chart so the UI has data to plot.",
{"query": str},
)
async def query_data(args: dict[str, Any]) -> dict[str, Any]:
return {"content": [{"type": "text", "text": json.dumps(_CACHED_DATA)}]}