diff --git a/app/[database]/hook.ts b/app/[database]/hook.ts
index 723028a2..2791e13f 100644
--- a/app/[database]/hook.ts
+++ b/app/[database]/hook.ts
@@ -1,15 +1,15 @@
-import * as d3 from "d3"
-import { useParams } from "next/navigation"
import { useEffect, useState } from "react"
+import { useParams } from "next/navigation"
+import * as d3 from "d3"
-import { usePeer } from "@/hooks/use-peer"
-import { useSqlite, useSqliteStore } from "@/hooks/use-sqlite"
import { MsgType } from "@/lib/const"
import { getSqliteProxy } from "@/lib/sqlite/proxy"
import { getWorker } from "@/lib/sqlite/worker"
import { useAppStore } from "@/lib/store/app-store"
import { useAppRuntimeStore } from "@/lib/store/runtime-store"
import { uuidv4 } from "@/lib/utils"
+import { usePeer } from "@/hooks/use-peer"
+import { useSqlite, useSqliteStore } from "@/hooks/use-sqlite"
import { useConfigStore } from "../settings/store"
@@ -45,6 +45,20 @@ export const useLastOpenedDatabase = () => {
return lastOpenedDatabase
}
+export const useLastOpenedTable = () => {
+ const { lastOpenedTable, setLastOpenedTable } = useAppStore()
+ const { isShareMode } = useAppRuntimeStore()
+ const { table, database } = useParams()
+
+ useEffect(() => {
+ if (!isShareMode && table && database) {
+ setLastOpenedTable(`${database}/${table}`)
+ }
+ }, [isShareMode, setLastOpenedTable, table, database])
+
+ return lastOpenedTable
+}
+
export const useLayoutInit = () => {
const { database } = useParams()
const { setInitialized, setSqliteProxy: setSqlWorker } = useSqliteStore()
@@ -53,6 +67,7 @@ export const useLayoutInit = () => {
const { sqlite } = useSqlite(database)
useLastOpenedDatabase()
+ useLastOpenedTable()
const { initPeer } = usePeer()
diff --git a/app/[database]/store.ts b/app/[database]/store.ts
index 82934efb..576715d2 100644
--- a/app/[database]/store.ts
+++ b/app/[database]/store.ts
@@ -1,3 +1,4 @@
+import { ChatCompletionResponseMessage } from "openai"
import { create } from "zustand"
import { sqlToJSONSchema2 } from "@/lib/sqlite/helper"
@@ -8,6 +9,9 @@ interface IDatabaseAppState {
isAiOpen: boolean
setIsAiOpen: (isAiOpen: boolean) => void
+ aiMessages: ChatCompletionResponseMessage[]
+ setAiMessages: (aiMessages: ChatCompletionResponseMessage[]) => void
+
currentTableSchema: string
setCurrentTableSchema: (currentTableSchema: string) => void
@@ -29,6 +33,9 @@ export const useDatabaseAppStore = create
()((set) => ({
isAiOpen: false,
setIsAiOpen: (isAiOpen) => set({ isAiOpen }),
+ aiMessages: [],
+ setAiMessages: (aiMessages) => set({ aiMessages }),
+
currentTableSchema: "",
setCurrentTableSchema: (currentTableSchema) => set({ currentTableSchema }),
diff --git a/app/settings/ai/ai-form.tsx b/app/settings/ai/ai-form.tsx
index 3803c7cc..dac985fd 100644
--- a/app/settings/ai/ai-form.tsx
+++ b/app/settings/ai/ai-form.tsx
@@ -28,7 +28,47 @@ const AIConfigFormSchema = z.object({
})
export type AIConfigFormValues = z.infer
-export const AutoRunScopes = ["SQL.SELECT", "SQL.INSERT", "D3.CHART"]
+export const AutoRunScopesWithDesc = [
+ {
+ value: "SQL.SELECT",
+ description: "Select data from a SQL table.",
+ },
+ {
+ value: "SQL.INSERT",
+ description: "Insert data into a SQL table.",
+ },
+ {
+ value: "SQL.UPDATE",
+ description: "Update data in a SQL table.",
+ },
+ {
+ value: "SQL.DELETE",
+ description: "Delete data from a SQL table.",
+ },
+ {
+ value: "SQL.ALTER",
+ description: "Alter a SQL table.",
+ },
+ {
+ value: "SQL.CREATE",
+ description: "Create a SQL table.",
+ },
+ {
+ value: "SQL.DROP",
+ description: "Drop a SQL table.",
+ },
+ {
+ value: "UI.REFRESH",
+ description: "Refresh the UI after SQL execution.",
+ },
+ {
+ value: "D3.CHART",
+ description: "Create a D3 chart.",
+ },
+]
+
+export const AutoRunScopes = AutoRunScopesWithDesc.map((item) => item.value)
+
// This can come from your database or API.
const defaultValues: Partial = {
// name: "Your name",
@@ -48,6 +88,7 @@ export function AIConfigForm() {
function onSubmit(data: AIConfigFormValues) {
setAiConfig(data)
+ // data.token = "sk-**********"
toast({
title: "You submitted the following values:",
description: (
@@ -68,7 +109,11 @@ export function AIConfigForm() {
Token
-
+
This is the token used to access the OpenAI API.
@@ -89,32 +134,34 @@ export function AIConfigForm() {
run.
- {AutoRunScopes.map((_item) => (
+ {AutoRunScopesWithDesc.map(({ value: key, description }) => (