Skip to content

Commit 6b32fb7

Browse files
committed
chore: code format
1 parent 5d3b993 commit 6b32fb7

File tree

12 files changed

+159
-148
lines changed

12 files changed

+159
-148
lines changed

.github/workflows/publish.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: 'publish'
1+
name: publish
22

33
on:
44
workflow_dispatch:
@@ -14,11 +14,11 @@ jobs:
1414
fail-fast: false
1515
matrix:
1616
include:
17-
- platform: 'macos-latest' # for Arm based macs (M1 and above).
18-
args: '--target aarch64-apple-darwin'
19-
- platform: 'macos-latest' # for Intel based macs.
20-
args: '--target x86_64-apple-darwin'
21-
- platform: 'windows-latest'
17+
- platform: macos-latest # for Arm based macs (M1 and above).
18+
args: --target aarch64-apple-darwin
19+
- platform: macos-latest # for Intel based macs.
20+
args: --target x86_64-apple-darwin
21+
- platform: windows-latest
2222
args: ''
2323

2424
runs-on: ${{ matrix.platform }}
@@ -33,7 +33,7 @@ jobs:
3333
uses: actions/setup-node@v4
3434
with:
3535
node-version: lts/*
36-
cache: 'pnpm' # Set this to npm, yarn or pnpm.
36+
cache: pnpm # Set this to npm, yarn or pnpm.
3737

3838
- name: install Rust stable
3939
uses: dtolnay/rust-toolchain@stable # Set this to dtolnay/rust-toolchain@nightly
@@ -44,7 +44,7 @@ jobs:
4444
- name: Rust cache
4545
uses: swatinem/rust-cache@v2
4646
with:
47-
workspaces: './src-tauri -> target'
47+
workspaces: ./src-tauri -> target
4848

4949
- name: install frontend dependencies
5050
# If you don't have `beforeBuildCommand` configured you may want to build your frontend here too.
@@ -55,8 +55,8 @@ jobs:
5555
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5656
with:
5757
tagName: v__VERSION__ # the action automatically replaces \_\_VERSION\_\_ with the app version.
58-
releaseName: 'v__VERSION__'
59-
releaseBody: 'See the assets to download this version and install.'
58+
releaseName: v__VERSION__
59+
releaseBody: See the assets to download this version and install.
6060
releaseDraft: true
6161
prerelease: false
62-
args: ${{ matrix.args }}
62+
args: ${{ matrix.args }}

app/components/AsssistantPopover.vue

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,22 @@ import { platform } from '@tauri-apps/plugin-os'
33
import ChevronUpDown from '~icons/heroicons/chevron-up-down'
44
import Sparkles from '~icons/heroicons/sparkles-solid'
55
6-
const props = defineProps<{
7-
table?: string
8-
cursor?: Database
9-
}>()
10-
116
const IS_MACOS = platform() === 'macos'
127
13-
const { cursor, table } = toRefs(props)
148
const router = useRouter()
159
const domRef = ref()
1610
const msgRefs = useTemplateRef('msgRef')
1711
const { focused } = useFocus(domRef)
1812
const { enter } = useMagicKeys()
1913
const isLoading = ref(false)
2014
const { md } = useMdit()
21-
const isReady = computed(() => !!cursor.value)
2215
2316
const { model: modelKey } = storeToRefs(useSettingsStore())
17+
const { system } = storeToRefs(useAssistantStore())
2418
const model = computed(() => MODULES.find(m => m.model === modelKey.value) ?? {})
2519
26-
const { data, prompt, messages, execute, system } = useStreamText({
20+
const { data, prompt, messages, execute } = useStreamText({
21+
system,
2722
onFinish() {
2823
messages.value.push({
2924
role: 'assistant',
@@ -36,15 +31,6 @@ const { data, prompt, messages, execute, system } = useStreamText({
3631
},
3732
})
3833
39-
watchImmediate(() => [isReady.value, table.value], async ([v, t]) => {
40-
if (v) {
41-
const prompt = await generateTableSchemaPromptWithIndexRows([t], cursor.value!)
42-
system.value = usePromptTemplate(TABLE_ASSISTANT_SYSTEM_PROMPT, {
43-
tableInfo: prompt,
44-
}).value
45-
}
46-
})
47-
4834
const conversation = computed(() => {
4935
return {
5036
messages: data.value ? [...messages.value, { role: 'assistant', content: data.value }] : messages.value,

app/composables/useAi.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { type CoreMessage, streamText } from 'ai'
22

33
export interface UseStreamTextOptions {
4+
system?: MaybeRef<string>
45
onFinish?: () => void
56
}
67

@@ -43,7 +44,6 @@ export function useAiProvider() {
4344

4445
export function useStreamText(options: UseStreamTextOptions = {}) {
4546
const data = ref('')
46-
const system = ref('')
4747
const prompt = ref('')
4848
const messages = ref<CoreMessage[]>([])
4949
const { model } = useAiProvider()
@@ -62,7 +62,7 @@ export function useStreamText(options: UseStreamTextOptions = {}) {
6262
const result = streamText({
6363
model: model.value,
6464
messages: [
65-
system.value ? { role: 'system', content: system.value } : undefined,
65+
unref(options.system) ? { role: 'system', content: unref(options.system) } : undefined,
6666
...messages.value,
6767
].filter(Boolean) as CoreMessage[],
6868
onFinish,
@@ -77,7 +77,6 @@ export function useStreamText(options: UseStreamTextOptions = {}) {
7777

7878
return {
7979
data,
80-
system,
8180
prompt,
8281
messages,
8382
execute,

app/pages/[id].vue

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ const cursor = computed(() => cursors.value[id.value])
2020
const instance = ref<Database | undefined>(undefined)
2121
const db = computed(() => parseConnectionURL(instance.value?.path).database)
2222
const { isFullscreen } = useTauriWindow()
23-
const table = useRouteParams<string>('name', '')
2423
2524
const tabs = computed(() => [
2625
cursor.value ? { key: 'id-tables-name', icon: CircleStack } : undefined,
@@ -45,6 +44,10 @@ const abort = watchImmediate(connections, async (cnxs) => {
4544
}
4645
})
4746
47+
function onNavi(key: string) {
48+
router.replace({ name: key })
49+
}
50+
4851
provide('__TABLITE:CURSOR', instance)
4952
5053
preloadRouteComponents({ name: 'id-queries' })
@@ -62,14 +65,14 @@ preloadRouteComponents({ name: 'id-queries' })
6265
</Button>
6366
</div>
6467

65-
<AsssistantPopover :table="table" :cursor="instance" />
68+
<AsssistantPopover />
6669
</div>
6770

6871
<Separator />
6972

7073
<div class="flex flex-1 h-0">
7174
<div class="flex flex-col items-center flex-shrink-0 border-r border-r-zinc-200 bg-zinc-100">
72-
<div v-for="tab in tabs" :key="tab.key" class="flex items-center cursor-pointer justify-center relative" :class="[route.name === tab.key ? 'bg-zinc-200 text-zinc-600' : 'text-zinc-600/50 hover:text-zinc-600']" @click="router.replace({ name: tab.key })">
75+
<div v-for="tab in tabs" :key="tab.key" class="flex items-center cursor-pointer justify-center relative" :class="[route.name === tab.key ? 'bg-zinc-200 text-zinc-600' : 'text-zinc-600/50 hover:text-zinc-600']" @click="onNavi(tab.key)">
7376
<component :is="tab.icon" class="flex-shrink-0 size-[18px] m-4" />
7477
<div v-if="route.name === tab.key" class="absolute top-0 bottom-0 left-0 w-0.5 bg-zinc-800" />
7578
</div>

app/pages/[id]/histories/index.vue

Lines changed: 0 additions & 3 deletions
This file was deleted.

app/pages/[id]/queries/index.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ definePageMeta({
1919
keepalive: true,
2020
})
2121
22+
defineAssistantContext({
23+
system: '',
24+
})
25+
2226
let editor: monaco.editor.IStandaloneCodeEditor
2327
2428
const PLATFORM = platform()

app/pages/[id]/settings/index.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<script setup lang="ts">
22
import { hash } from 'ohash'
33
4+
defineAssistantContext({
5+
system: '',
6+
})
7+
48
const store = useSettingsStore()
59
const { language, alias, tags, googleAPIKey, deepseekApiKey, openrouterApiKey, model } = storeToRefs(store)
610
const { connections } = storeToRefs(useConnectionStore())

app/pages/[id]/tables/[[name]].vue

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,29 @@ definePageMeta({
1818
})
1919
2020
const cursor = inject<Ref<Database> | undefined>('__TABLITE:CURSOR', undefined)
21-
const selectedTable = useRouteParams('name', '')
22-
const { data, limit, offset, count, structure, primaryKeys, isLoading, backend, where, setup, execute } = useTable(selectedTable, cursor)
21+
const table = useRouteParams('name', '')
22+
const { data, limit, offset, count, structure, primaryKeys, isLoading, backend, where, execute } = useTable(table, cursor)
2323
const mode = ref('data')
2424
const columns = computed(() => structure.value.map(({ columnName }) => columnName))
2525
const changes = ref<Record<string, any>>({})
2626
const updates = ref<Update[]>([])
2727
const inserts = ref<Record<string, any>[]>([])
2828
const deletes = ref<string[]>([])
2929
const selectedRowKeys = ref([])
30+
const isReady = computed(() => !!cursor.value)
31+
32+
watchImmediate(() => [isReady.value, table.value], async ([v, t]) => {
33+
if (v) {
34+
defineAssistantContext({
35+
async system() {
36+
const prompt = await generateTableSchemaPromptWithIndexRows([t], cursor.value!)
37+
return usePromptTemplate(TABLE_ASSISTANT_SYSTEM_PROMPT, {
38+
tableInfo: prompt,
39+
})
40+
},
41+
})
42+
}
43+
})
3044
3145
const page = computed({
3246
get() {
@@ -69,7 +83,7 @@ const hasChanged = computed(() => {
6983
async function onSelectTable() {
7084
toast.dismiss()
7185
where.value = ''
72-
changes.value = { [selectedTable.value]: {} }
86+
changes.value = { [table.value]: {} }
7387
page.value = 1
7488
inserts.value = []
7589
deletes.value = []
@@ -88,7 +102,7 @@ async function onApplyFliters(value: string) {
88102
}
89103
90104
async function onDisvardChanges() {
91-
changes.value = selectedTable.value ? { [selectedTable.value]: {} } : {}
105+
changes.value = table.value ? { [table.value]: {} } : {}
92106
inserts.value = []
93107
deletes.value = []
94108
toast.dismiss()
@@ -120,14 +134,14 @@ function onOpenUpdatesPreview(visible: boolean) {
120134
121135
for (const _n of inserts.value) {
122136
const keys = Object.keys(_n)
123-
sqls.push(`INSERT INTO \`${selectedTable.value}\` (${keys.join(', ')}) VALUES (${keys.map(k => normalizeQueryValue(_n[k], dataTypeMap.value[k])).join(', ')})`)
137+
sqls.push(`INSERT INTO \`${table.value}\` (${keys.join(', ')}) VALUES (${keys.map(k => normalizeQueryValue(_n[k], dataTypeMap.value[k])).join(', ')})`)
124138
}
125139
126140
for (const _d of deletes.value) {
127141
try {
128142
const json = JSON.parse(_d)
129143
const where = Object.entries(json).map(([k, v]) => `${k} = ${normalizeQueryValue(v, dataTypeMap.value[k])}`).join(' AND ')
130-
sqls.push(`DELETE FROM \`${selectedTable.value}\` WHERE ${where}`)
144+
sqls.push(`DELETE FROM \`${table.value}\` WHERE ${where}`)
131145
}
132146
catch {
133147
continue
@@ -154,7 +168,7 @@ async function onSave() {
154168
toast.dismiss()
155169
await applyUpdates()
156170
await execute()
157-
changes.value = selectedTable.value ? { [selectedTable.value]: {} } : {}
171+
changes.value = table.value ? { [table.value]: {} } : {}
158172
updates.value = []
159173
inserts.value = []
160174
deletes.value = []
@@ -177,21 +191,21 @@ function onDeleteRecords() {
177191
<div class="flex-1 h-full w-full flex flex-col">
178192
<ResizablePanelGroup direction="horizontal" class="h-0 flex-1 w-full">
179193
<ResizablePanel :default-size="22" :min-size="10" :max-size="50">
180-
<TableSelector v-model:value="selectedTable" :cursor="cursor" :loading="isLoading" @after-select="onSelectTable" />
194+
<TableSelector v-model:value="table" :cursor="cursor" :loading="isLoading" @after-select="onSelectTable" />
181195
</ResizablePanel>
182196

183197
<ResizableHandle />
184198

185199
<ResizablePanel class="h-full bg-white">
186-
<div v-if="!selectedTable" class="w-full h-full flex items-center justify-center flex-col cursor-default">
200+
<div v-if="!table" class="w-full h-full flex items-center justify-center flex-col cursor-default">
187201
<TextHoverEffect class="w-1/2 px-1" :stroke-width="1" text="TABLITE" />
188202
</div>
189203

190-
<div v-show="selectedTable" class="flex flex-col h-full">
204+
<div v-show="table" class="flex flex-col h-full">
191205
<div class="p-4 flex justify-between items-center">
192206
<div class="ml-2 flex-1">
193207
<div class="font-semibold uppercase cursor-default">
194-
{{ selectedTable }}
208+
{{ table }}
195209
</div>
196210
</div>
197211

@@ -229,7 +243,7 @@ function onDeleteRecords() {
229243

230244
<div class="w-full h-0 flex-1 flex flex-col bg-zinc-50 -m-px">
231245
<VisTable
232-
v-model:changes="changes[selectedTable]"
246+
v-model:changes="changes[table]"
233247
v-model:inserts="inserts"
234248
v-model:selected-row-keys="selectedRowKeys"
235249
editable

components.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
"lib": "@/lib"
1818
},
1919
"iconLibrary": "lucide"
20-
}
20+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"ai": "^4.1.61",
3030
"destr": "^2.0.3",
3131
"embla-carousel-vue": "^8.5.2",
32+
"klona": "^2.0.6",
3233
"lucide-vue-next": "^0.469.0",
3334
"markdown-it": "^14.1.0",
3435
"monaco-editor": "^0.52.2",

0 commit comments

Comments
 (0)