feat: add admin/internal database API with CRUD, read-only query, and natural-language SQL endpoints

Add a new `/dbapi` router package providing a generic database API over `dataset`, restricted to admin sessions, admin API keys, and the internal gateway key. Includes:

- `tables.py`: list all tables and inspect table schemas
- `crud.py`: full CRUD operations (GET, POST, PATCH, DELETE) with soft-delete awareness, born-live inserts, `?include_deleted`, `.../restore`, and `?hard=true` purge
- `query.py`: validated read-only SELECT execution via sqlglot parsing, classification, and EXPLAIN dry-run; async query jobs with WebSocket streaming via `DbApiJobService`
- `nl.py`: natural-language-to-SQL conversion using the platform AI gateway with re-prompting until validation passes

Also register `DbApiJobService` and `PubSubService` in the service manager, add `DBAPI_DIR` to config data paths, and force cleartext `http://` connections to HTTP/1.1 in `curl_transport` to fix large request failures against uvicorn's HTTP/1.1-only internal gateway.
This commit is contained in:
2026-06-14 23:00:30 +00:00
parent 96521e8757
commit d31ccba6c1
69 changed files with 3278 additions and 12 deletions
+8 -4
View File
@@ -2537,13 +2537,14 @@ async def handle_mentions(dp: DevPlace, answered: set[str]) -> None:
reply = await _agent_answer_for_devplace(
f"You were @-mentioned in a DevPlace post. The message to you is:\n\n{message}\n\n"
f"Do what it asks, then answer it directly. Your reply is posted verbatim as a "
f"comment, so write it as botje talking to the user — not as a report about what you did.",
f"comment, so write it as botje talking to the user — not as a report about what you did. "
f"Keep the entire reply within 1000 characters (the comment length limit).",
context=f"Post URL: {DEVPLACE_URL}/posts/{slug}",
)
dp.call(
"comments.create",
content=reply[:5000],
content=reply.strip()[:1000],
target_uid=post_uid,
target_type="post",
)
@@ -2597,10 +2598,13 @@ async def handle_dms(dp: DevPlace, answered: set[str]) -> None:
try:
reply = await _agent_answer_for_devplace(
content,
context=f"The user @{other_name} (uid {other_uid}) sent you a direct message.",
context=(
f"The user @{other_name} (uid {other_uid}) sent you a direct message. "
f"Keep the entire reply within 2000 characters (the message length limit)."
),
)
dp.call("messages.send", content=reply[:5000], receiver_uid=other_uid)
dp.call("messages.send", content=reply.strip()[:2000], receiver_uid=other_uid)
logger.info("Replied to DM from @%s", other_name)
except (xmlrpc.client.Fault, Exception) as e: