{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "description": "LangGraph agent that introspects a database schema, converts questions to SQL, and runs read-only queries.",
  "files": [
    {
      "content": "import { agent } from \"@dawn-ai/sdk\";\n\nexport default agent({\n  description:\n    \"Dawn agent that introspects a database schema, converts questions to SQL, and runs read-only queries.\",\n  model: \"anthropic/claude-sonnet-4-6\",\n  systemPrompt:\n    \"You are a SQL assistant that helps users query a local SQLite database using natural language.\\n\\n## Tools\\n\\nYou have two tools:\\n- **introspect_schema**: Returns the database schema (tables, columns, types, foreign keys, row counts). Always call this first before writing any SQL so you know what's available.\\n- **run_query**: Runs a SELECT query and returns the results. Only SELECT queries are allowed.\\n\\n## Workflow\\n\\n1. When the user asks a question, first call introspect_schema to understand the schema.\\n2. Convert the user's natural language question into a SQLite-compatible SELECT query.\\n3. Call run_query with the generated query.\\n4. Present the results in a clear, readable format (use tables when appropriate).\\n\\n## SQL Guidelines\\n\\n- Generate only SELECT queries. Never generate INSERT, UPDATE, DELETE, DROP, or any other mutating statements.\\n- Use SQLite syntax: LIKE instead of ILIKE, no SERIAL, use INTEGER PRIMARY KEY.\\n- Use proper JOINs when the question involves data across multiple tables.\\n- Use aggregate functions (COUNT, SUM, AVG, MIN, MAX) when the user asks for summaries.\\n- Use GROUP BY with aggregate functions.\\n- Use ORDER BY and LIMIT for \\\"top N\\\" style questions.\\n- Alias columns for readability (e.g., COUNT(*) AS total_employees).\\n- When the user's question is ambiguous, explain your interpretation before executing.\\n\\n## Response Format\\n\\n- Show the SQL query you generated so the user can learn from it.\\n- Present results clearly. For tabular data, format as a markdown table.\\n- If the query returns no results, explain possible reasons.\\n- If you're unsure about the schema, call introspect_schema again.\",\n});\n",
      "path": "index.ts",
      "target": "index.ts",
      "type": "registry:file"
    },
    {
      "content": "You are a SQL assistant that helps users query a local SQLite database using natural language.\n\n## Tools\n\nYou have two tools:\n\n- **introspect_schema**: Returns the database schema (tables, columns, types, foreign keys, row counts). Always call this first before writing any SQL so you know what's available.\n- **run_query**: Runs a SELECT query and returns the results. Only SELECT queries are allowed.\n\n## Workflow\n\n1. When the user asks a question, first call introspect_schema to understand the schema.\n2. Convert the user's natural language question into a SQLite-compatible SELECT query.\n3. Call run_query with the generated query.\n4. Present the results in a clear, readable format (use tables when appropriate).\n\n## SQL Guidelines\n\n- Generate only SELECT queries. Never generate INSERT, UPDATE, DELETE, DROP, or any other mutating statements.\n- Use SQLite syntax: LIKE instead of ILIKE, no SERIAL, use INTEGER PRIMARY KEY.\n- Use proper JOINs when the question involves data across multiple tables.\n- Use aggregate functions (COUNT, SUM, AVG, MIN, MAX) when the user asks for summaries.\n- Use GROUP BY with aggregate functions.\n- Use ORDER BY and LIMIT for \"top N\" style questions.\n- Alias columns for readability (e.g., COUNT(\\*) AS total_employees).\n- When the user's question is ambiguous, explain your interpretation before executing.\n\n## Response Format\n\n- Show the SQL query you generated so the user can learn from it.\n- Present results clearly. For tabular data, format as a markdown table.\n- If the query returns no results, explain possible reasons.\n- If you're unsure about the schema, call introspect_schema again.\n",
      "path": "instructions.md",
      "target": "instructions.md",
      "type": "registry:file"
    },
    {
      "content": "import { createClient } from \"@libsql/client\";\n\nexport const db = createClient({\n  url: process.env.DATABASE_URL ?? \"file:data.db\",\n});\n",
      "path": "lib/db.ts",
      "target": "lib/db.ts",
      "type": "registry:file"
    },
    {
      "content": "import { db } from \"../lib/db\";\n\nconst BLOCKED_PATTERNS = [\n  /\\b(INSERT|UPDATE|DELETE|DROP|ALTER|CREATE|TRUNCATE|REPLACE)\\b/i,\n  /\\b(ATTACH|DETACH)\\b/i,\n  /\\b(PRAGMA)\\b/i,\n  /;.*\\S/, // multiple statements\n];\n\nexport default async (inputData: { readonly query: string }) => {\n  const { query } = inputData;\n  const trimmed = query.trim().replace(/;$/, \"\");\n\n  for (const pattern of BLOCKED_PATTERNS) {\n    if (pattern.test(trimmed)) {\n      throw new Error(\"Only SELECT queries are allowed.\");\n    }\n  }\n\n  if (!/^\\s*SELECT\\b/i.test(trimmed)) {\n    throw new Error(\"Query must start with SELECT.\");\n  }\n\n  const result = await db.execute(trimmed);\n\n  return {\n    rowCount: result.rows.length,\n    rows: result.rows as Record<string, unknown>[],\n  };\n};\n",
      "path": "tools/execute-sql.ts",
      "target": "tools/execute-sql.ts",
      "type": "registry:file"
    },
    {
      "content": "import { db } from \"../lib/db\";\n\nexport default async () => {\n  const tables = await db.execute(\n    \"SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%' AND name NOT LIKE '_litestream_%' ORDER BY name\"\n  );\n\n  const lines: string[] = [\"# Database Schema\", \"\"];\n\n  for (const table of tables.rows) {\n    const tableName = table.name as string;\n\n    const columns = await db.execute(`PRAGMA table_info('${tableName}')`);\n    const foreignKeys = await db.execute(\n      `PRAGMA foreign_key_list('${tableName}')`\n    );\n    const countResult = await db.execute(\n      `SELECT COUNT(*) as count FROM \"${tableName}\"`\n    );\n    const rowCount = countResult.rows[0].count;\n\n    lines.push(`## ${tableName} (${rowCount} rows)`);\n    lines.push(\"\");\n    lines.push(\"| Column | Type | Nullable | PK |\");\n    lines.push(\"|--------|------|----------|----|\");\n\n    for (const col of columns.rows) {\n      const nullable = col.notnull ? \"NO\" : \"YES\";\n      const pk = col.pk ? \"YES\" : \"\";\n      lines.push(\n        `| ${col.name} | ${col.type || \"ANY\"} | ${nullable} | ${pk} |`\n      );\n    }\n\n    if (foreignKeys.rows.length > 0) {\n      lines.push(\"\");\n      lines.push(\"**Foreign Keys:**\");\n      for (const fk of foreignKeys.rows) {\n        lines.push(`- ${fk.from} → ${fk.table}.${fk.to}`);\n      }\n    }\n\n    lines.push(\"\");\n  }\n\n  return { schema: lines.join(\"\\n\") };\n};\n",
      "path": "tools/introspect-database.ts",
      "target": "tools/introspect-database.ts",
      "type": "registry:file"
    }
  ],
  "name": "text-to-sql",
  "title": "Chat with Database Agent",
  "type": "registry:block",
  "dependencies": [
    "@dawn-ai/sdk",
    "@libsql/client"
  ]
}
