Skip to content

feat: Ask (pay-as-you-go grounded AI answers) + fix SQL to DBML on DBML input - #3

Merged
ralyodio merged 4 commits into
mainfrom
feat/ask
Nov 30, 2026
Merged

ralyodio merged 4 commits into
mainfrom
feat/ask

Conversation

@ralyodio

Copy link
Copy Markdown
Contributor

Ask: pay-as-you-go AI answers for a person, by personal link

  • /ask/<token>: the personal link signs in (only a SHA-256 of the token is stored; a cookie keeps /ask working too). Operator can re-issue (old link dies) or revoke.
  • One plain page, 20px+ type, high contrast: "You are signed in as Brian. Balance: $X.XX. Each question costs 5 cents.", a question box, a schema box (DBML or SQL, auto-detected; SQL converted to DBML), one big Ask button, and every past question and answer, newest first, rendered by the server. The last schema is pre-filled from the account (localStorage is only a cache).
  • Waiting shows "Working on it, this can take up to 2 minutes. N seconds so far." Answers run in the background and the page polls, so no proxy timeout applies.
  • Grounding: before the model, the engine runs on the schema (summary, every review finding with rule ids, exact SQL for a named dialect). The model is told to use only those names and to say when unsure. For convert/review questions the exact checker output is appended verbatim.
  • Models: @profullstack/ai-providers, c0mpute first (4B models that are live), OpenAI/Anthropic alternating fallback when keys are set. Provider, model, tokens, cost and time stored per answer (/admin/api/costs).
  • Billing: prepaid balance in cents, ledger with unique (reason, ref). 5 cents per answered question (ASK_PRICE_CENTS); failures and timeouts are free and say so. One question at a time per account. Questions caught by a restart are marked failed, not charged.
  • Top-ups: $5 / $10 / $20 via the CoinPay hosted checkout of the dbml.db business; credited by the signed webhook (verifyWebhook) or by the return page checking the session. No subscriptions.
  • Storage: SQLite (node:sqlite) in /data, the c0mpute app state dir (--state /data --snapshot-secs 30); /admin/api/backup + bin/admin.js backup for an off-node copy.
  • Operator: /admin/api/* with ADMIN_KEY (vault), bin/admin.js create|list|credit|link|revoke|costs|backup.
  • Home page: big "Ask a question about your schema" button.

Fix: SQL to DBML on DBML input

The playground posted the default DBML sample to /api/v1/sql-to-dbml and showed a parser error. Now the page detects DBML and says "That's DBML. Paste SQL (CREATE TABLE ...) to convert it, or use DBML to SQL." with a link that loads an SQL example. The API, /convert, the sql_to_dbml MCP tool and dbml from-sql add the hint input looks like DBML, not SQL; use /api/v1/dbml-to-sql.

Tests: 28 pass (Ask flow with a stubbed model: grounding, charge, no charge on failure, low balance, webhook signature and idempotency, link re-issue; DBML detection shared by page and server; API/convert/MCP hint).

🤖 Generated with Claude Code

ralyodio and others added 3 commits November 30, 2026 19:57
… input

Ask: /ask/<token> personal link (hashed token, cookie, re-issue/revoke), big
plain page with full history newest first and the last schema pre-filled.
Questions are answered in the background (poll), grounded in the engine's
summary, review findings and exact SQL; the exact checker output is appended
for convert/review questions. c0mpute first via @profullstack/ai-providers,
OpenAI/Anthropic fallback when keys are set. 5 cents per answered question,
failures free. Prepaid balance in SQLite in /data (c0mpute state), ledger
with unique refs, CoinPay hosted checkout top-ups (5/10/20) credited by the
signed webhook or the return page. Operator API + bin/admin.js (create,
credit, link, revoke, costs, backup). Provider, tokens and cost per answer
are stored for repricing.

Fix: SQL to DBML on DBML input. The playground no longer posts DBML to
sql-to-dbml (it says so and offers an SQL example); the API, convert, MCP
and CLI add the hint 'input looks like DBML, not SQL; use /api/v1/dbml-to-sql'.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…reasoning, 2500 tokens

- Refs imported from SQL carry optional relations ('0..*'); the review read
  the foreign key on the wrong side and flagged a false ref_target_not_unique.
- A peer node can drop a job; retry with the other 4B model on a fresh router
  (the shared one parks c0mpute for 30 s).
- qwen3 streams its reasoning as text ending in </think>: keep what follows;
  reasoning-only text is not an answer. maxTokens 900 cut answers short.
- Prompt: PostgreSQL when no database is named.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e live 4B models

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ralyodio
ralyodio marked this pull request as ready for review November 30, 2026 20:16
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ralyodio
ralyodio merged commit 6a77e8f into main Nov 30, 2026
@ralyodio
ralyodio deleted the feat/ask branch November 30, 2026 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant