Update duckdb tool and support .duckdb files#16
Conversation
Greptile SummaryThis PR extends the DuckDB tool to support Key changes:
Confidence Score: 3/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant UI as DataFileUpload
participant Svc as duckdbService
participant W as duckdbWorker
participant DB as DuckDB WASM
UI->>Svc: registerDatabaseFile(name, File)
Svc->>W: postMessage {type: registerDatabaseHandle, handle: File}
W->>DB: registerFileHandle(name, handle, BROWSER_FILEREADER)
W->>DB: ATTACH 'name' AS "alias" (READ_ONLY)
alt ATTACH fails
DB-->>W: error
W->>DB: dropFile(name)
W-->>Svc: {success: false, error}
else ATTACH succeeds
DB-->>W: ok
W-->>Svc: {success: true, dbAlias}
end
Svc-->>UI: {success, dbAlias}
UI->>Svc: execute(SELECT table_schema, table_name FROM information_schema.tables ...)
Svc-->>UI: rows[]
loop for each table
UI->>Svc: describeTable("alias"."schema"."table")
Svc-->>UI: columns[]
end
UI->>Store: updateDataFileStatus(fileId, true, {tables, dbName})
|
| @@ -485,7 +498,11 @@ export function ToolsBar({ | |||
| if (toolId === "sql_query") { | |||
| return ( | |||
| <div className="pt-2 border-t mt-2"> | |||
There was a problem hiding this comment.
MCP tool auto-enables on config open, not on actual server connection
Opening the MCP config dialog now immediately enables the mcp tool — even if the user is just browsing the dialog and doesn't add any servers. This is different from the file_search and sql_query cases, where the tool is only enabled once the user actually selects a resource (a vector store or uploads a file).
The previous code passed onOpenMCPConfig directly, which could also be undefined; this change makes onOpenConfig always a defined function. If MCPServerStatus conditionally renders its config button based on whether onOpenConfig is defined, this change would always show that button even when there is no config handler — worth verifying.
Consider tying ensureEnabled("mcp") to an event that signals a server was actually connected/configured rather than the dialog being opened.
Prompt To Fix With AI
This is a comment left during a code review.
Path: ui/src/components/ToolsBar/ToolsBar.tsx
Line: 490-500
Comment:
**MCP tool auto-enables on config *open*, not on actual server connection**
Opening the MCP config dialog now immediately enables the `mcp` tool — even if the user is just browsing the dialog and doesn't add any servers. This is different from the `file_search` and `sql_query` cases, where the tool is only enabled once the user actually selects a resource (a vector store or uploads a file).
The previous code passed `onOpenMCPConfig` directly, which could also be `undefined`; this change makes `onOpenConfig` always a defined function. If `MCPServerStatus` conditionally renders its config button based on whether `onOpenConfig` is defined, this change would always show that button even when there is no config handler — worth verifying.
Consider tying `ensureEnabled("mcp")` to an event that signals a server was actually connected/configured rather than the dialog being opened.
How can I resolve this? If you propose a fix, please make it concise.| <span className="text-muted-foreground shrink-0">{FILE_TYPE_LABELS[file.type]}</span> | ||
| {chipDetail && <span className="text-muted-foreground shrink-0">{chipDetail}</span>} | ||
| {hasSchema && !isLoading && ( |
There was a problem hiding this comment.
Unquoted identifiers in query hint produce misleading SQL
schemaName and tableName are interpolated directly into the hint string without quoting. A table named my events or a reserved-word like order will produce a hint like SELECT * FROM db.main.my events or SELECT * FROM db.main.order — both invalid SQL that will confuse users who copy it directly.
dbName is always safe (sanitised by deriveDbAlias), but the other two come directly from information_schema:
| <span className="text-muted-foreground shrink-0">{FILE_TYPE_LABELS[file.type]}</span> | |
| {chipDetail && <span className="text-muted-foreground shrink-0">{chipDetail}</span>} | |
| {hasSchema && !isLoading && ( | |
| <p className="text-xs text-muted-foreground mb-2 font-mono"> | |
| SELECT * FROM "{dbName}"."{table.schemaName}"."{table.tableName}" | |
| </p> |
Prompt To Fix With AI
This is a comment left during a code review.
Path: ui/src/components/DataFileUpload/DataFileUpload.tsx
Line: 405-407
Comment:
**Unquoted identifiers in query hint produce misleading SQL**
`schemaName` and `tableName` are interpolated directly into the hint string without quoting. A table named `my events` or a reserved-word like `order` will produce a hint like `SELECT * FROM db.main.my events` or `SELECT * FROM db.main.order` — both invalid SQL that will confuse users who copy it directly.
`dbName` is always safe (sanitised by `deriveDbAlias`), but the other two come directly from `information_schema`:
```suggestion
<p className="text-xs text-muted-foreground mb-2 font-mono">
SELECT * FROM "{dbName}"."{table.schemaName}"."{table.tableName}"
</p>
```
How can I resolve this? If you propose a fix, please make it concise.| const hasColumns = file.columns && file.columns.length > 0; | ||
| const hasTables = file.tables && file.tables.length > 0; | ||
| const isDatabase = file.type === "duckdb"; | ||
| const hasSchema = hasColumns || hasTables; |
There was a problem hiding this comment.
Non-unique React key across schemas
The key prop here only uses the table name. If two different schemas in the same database both contain a table called orders (or any other matching name), React will encounter duplicate keys and silently skip rendering one of the entries. The key should be a composite of both the schema and the table name to stay unique across the full set of tables.
Prompt To Fix With AI
This is a comment left during a code review.
Path: ui/src/components/DataFileUpload/DataFileUpload.tsx
Line: 377
Comment:
**Non-unique React key across schemas**
The `key` prop here only uses the table name. If two different schemas in the same database both contain a table called `orders` (or any other matching name), React will encounter duplicate keys and silently skip rendering one of the entries. The key should be a composite of both the schema and the table name to stay unique across the full set of tables.
How can I resolve this? If you propose a fix, please make it concise.
No description provided.