Skip to content

Commit f1da7ff

Browse files
committed
dont use local storage to avoid data loss across different app builds
1 parent 019e7eb commit f1da7ff

File tree

10 files changed

+32
-65
lines changed

10 files changed

+32
-65
lines changed

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "bks-ai-shell",
33
"name": "AI Shell",
4-
"version": "1.0.25",
4+
"version": "1.0.27",
55
"minAppVersion": "5",
66
"description": "Ask AI to analyze your database and generate SQL queries.",
77
"author": {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
},
1515
"dependencies": {
1616
"@anthropic-ai/sdk": "^0.39.0",
17-
"@beekeeperstudio/plugin": "^1.0.11",
17+
"@beekeeperstudio/plugin": "^1.2.2",
1818
"@langchain/anthropic": "^0.3.21",
1919
"@langchain/core": "^0.3.48",
2020
"@material-symbols/font-400": "^0.31.2",

src/components/ChatInterface.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ import Dropdown from "./common/Dropdown.vue";
153153
import DropdownOption from "./common/DropdownOption.vue";
154154
import { safeJSONStringify } from "../utils";
155155
import _ from "lodash";
156-
import { request, QueryResult } from "@beekeeperstudio/plugin";
156+
import { expandTableResult, QueryResult } from "@beekeeperstudio/plugin";
157157
158158
const maxHistorySize = 50;
159159
@@ -411,7 +411,7 @@ export default {
411411
return "```json\n" + str + "\n```";
412412
},
413413
async handleResultClick(results: QueryResult[]) {
414-
await request("expandTableResult", { results });
414+
await expandTableResult(results);
415415
await this.$nextTick();
416416
if (this.isAtBottom) {
417417
this.scrollToBottom();

src/components/toolMessage/RunQueryMessage.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const TABLE_MAX_ROWS = 5;
4747
export default {
4848
props: {
4949
data: {
50-
type: Object as PropType<RunQueryResponse>,
50+
type: Object as PropType<RunQueryResponse['result']>,
5151
required: true,
5252
},
5353
},

src/config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import instructions from "../instructions.txt?raw";
22
import mongodbInstructions from "../mongodb-instructions.txt?raw";
3-
import { request } from "@beekeeperstudio/plugin";
3+
import { getConnectionInfo, getTables } from "@beekeeperstudio/plugin";
44

55
export async function getDefaultInstructions() {
6-
const response = await request("getConnectionInfo");
7-
const tables = await request("getTables").then((tables) =>
6+
const response = await getConnectionInfo();
7+
const tables = await getTables().then((tables) =>
88
tables.filter(
99
(table) =>
1010
table.schema !== "information_schema" &&

src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import json from "highlight.js/lib/languages/json";
3535
import sql from "highlight.js/lib/languages/sql";
3636
import "@beekeeperstudio/plugin/dist/eventForwarder";
3737

38-
setDebugComms(false);
38+
setDebugComms(true);
3939

4040
hljs.registerLanguage("sql", sql);
4141
hljs.registerLanguage("javascript", javascript);

src/store.ts

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
ToolMessage,
1313
} from "@langchain/core/messages";
1414
import { BaseModelProvider, BaseProvider } from "./providers/BaseModelProvider";
15-
import { request } from "@beekeeperstudio/plugin";
15+
import { expandTableResult, getEncryptedData, getViewState, setEncryptedData, setTabTitle, setViewState } from "@beekeeperstudio/plugin";
1616
import { isAbortError } from "./utils";
1717

1818
interface Tool {
@@ -37,10 +37,6 @@ interface ViewState {
3737
conversationTitle: string;
3838
}
3939

40-
interface EncryptedData {
41-
anthropicApiKey: string;
42-
}
43-
4440
interface ProviderState {
4541
providerId: ProviderId;
4642
apiKey: string;
@@ -96,13 +92,13 @@ export const useProviderStore = defineStore("providers", {
9692
},
9793
actions: {
9894
async initializeChat() {
99-
const data = await request<EncryptedData>("getEncryptedData");
100-
if (data) {
101-
this.apiKey = data.anthropicApiKey;
95+
const apiKey = await getEncryptedData("providers.anthropic.apiKey") as string;
96+
if (apiKey) {
97+
this.apiKey = apiKey;
10298
}
10399
},
104100
async initializeProvider() {
105-
const state = await request<ViewState>("getViewState");
101+
const state = await getViewState<ViewState>();
106102
if (state?.messages) {
107103
try {
108104
this.messages = mapStoredMessagesToChatMessages(state.messages);
@@ -218,7 +214,7 @@ export const useProviderStore = defineStore("providers", {
218214
const results = context.result!.results;
219215
if (results.length > 0 && results[0].rows.length > 0) {
220216
localStorage.setItem(STORAGE_KEYS.HAS_OPENED_TABLE_RESULT, "1");
221-
request("expandTableResult", { results: [results[0]] });
217+
expandTableResult([results[0]]);
222218
}
223219
}
224220

@@ -236,11 +232,9 @@ export const useProviderStore = defineStore("providers", {
236232
this.isAborting = false;
237233
this.isProcessing = false;
238234

239-
request("setViewState", {
240-
state: {
241-
messages: mapChatMessagesToStoredMessages(messages),
242-
conversationTitle: this.conversationTitle,
243-
},
235+
setViewState({
236+
messages: mapChatMessagesToStoredMessages(messages),
237+
conversationTitle: this.conversationTitle,
244238
});
245239

246240
if (!this.conversationTitle && !this.isGeneratingConversationTitle) {
@@ -251,14 +245,12 @@ export const useProviderStore = defineStore("providers", {
251245
this.messages,
252246
);
253247

254-
request("setTabTitle", { title });
248+
setTabTitle(title);
255249
this.conversationTitle = title;
256250

257-
request("setViewState", {
258-
state: {
259-
messages: mapChatMessagesToStoredMessages(messages),
260-
conversationTitle: this.conversationTitle,
261-
},
251+
setViewState({
252+
messages: mapChatMessagesToStoredMessages(messages),
253+
conversationTitle: this.conversationTitle,
262254
});
263255
} catch (e) {
264256
// If error occurs when generating title, do nothing
@@ -316,7 +308,7 @@ export const useProviderStore = defineStore("providers", {
316308
},
317309
async setApiKey(apiKey: string) {
318310
this.apiKey = apiKey;
319-
await request("setEncryptedData", { anthropicApiKey: apiKey });
311+
await setEncryptedData("providers.anthropic.apiKey", apiKey);
320312
},
321313
setModel(modelId: string) {
322314
this.pendingModelId = modelId;

src/tools/definitions.ts

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { z } from "zod";
22
import { tool } from "@langchain/core/tools";
3-
import { request } from "@beekeeperstudio/plugin";
3+
import { getColumns, getConnectionInfo, getTables, runQuery } from "@beekeeperstudio/plugin";
44
import { safeJSONStringify } from "../utils";
55

66
const getTablesInputSchema = z.object({
@@ -21,7 +21,7 @@ const runQueryInputSchema = z.object({
2121

2222
export const getConnectionInfoTool = tool(
2323
async () => {
24-
const result = await request("getConnectionInfo");
24+
const result = await getConnectionInfo();
2525
return safeJSONStringify(result);
2626
},
2727
{
@@ -33,7 +33,7 @@ export const getConnectionInfoTool = tool(
3333

3434
export const getTablesTool = tool(
3535
async (params) => {
36-
const result = await request("getTables", { schema: params.schema });
36+
const result = await getTables(params.schema);
3737
return safeJSONStringify(result);
3838
},
3939
{
@@ -45,10 +45,7 @@ export const getTablesTool = tool(
4545

4646
export const getColumnsTool = tool(
4747
async (params) => {
48-
const result = await request("getColumns", {
49-
table: params.table,
50-
schema: params.schema,
51-
});
48+
const result = await getColumns(params.table, params.schema);
5249
return safeJSONStringify(result);
5350
},
5451
{
@@ -59,20 +56,9 @@ export const getColumnsTool = tool(
5956
},
6057
);
6158

62-
export const getAllTabsTool = tool(
63-
async () => {
64-
const result = await request("getAllTabs");
65-
return safeJSONStringify(result);
66-
},
67-
{
68-
name: "get_all_tabs",
69-
description: "Get a list of all open query tabs in Beekeeper Studio",
70-
},
71-
);
72-
7359
export const runQueryTool = tool(
7460
async (params) => {
75-
const result = await request("runQuery", { query: params.query });
61+
const result = await runQuery(params.query);
7662
return safeJSONStringify(result);
7763
},
7864
{
@@ -87,6 +73,5 @@ export const tools = [
8773
getConnectionInfoTool,
8874
getTablesTool,
8975
getColumnsTool,
90-
getAllTabsTool,
9176
runQueryTool,
9277
];

src/vue-shims.d.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,3 @@ declare module '*?raw' {
88
const content: string
99
export default content
1010
}
11-
12-
// declare module '@vue/runtime-core' {
13-
// import { request } from '@beekeeperstudio/plugin'
14-
// import pluralize from 'pluralize'
15-
//
16-
// interface ComponentCustomProperties {
17-
// $request: typeof request
18-
// $pluralize: typeof pluralize
19-
// }
20-
// }

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@
4040
"@babel/helper-string-parser" "^7.25.9"
4141
"@babel/helper-validator-identifier" "^7.25.9"
4242

43-
"@beekeeperstudio/plugin@^1.0.11":
44-
version "1.0.11"
45-
resolved "https://registry.yarnpkg.com/@beekeeperstudio/plugin/-/plugin-1.0.11.tgz#55b7252481a2849f77717d5aa090b6118954b222"
46-
integrity sha512-FnqynrxPy0JC1InBfsBkbZQ84H+g+M/Frvmx6+CBD4LH3gCRXi5OsiY+2gLtCWfhNCEP5UsKKrS4KKkR7/dCkw==
43+
"@beekeeperstudio/plugin@^1.2.2":
44+
version "1.2.2"
45+
resolved "https://registry.yarnpkg.com/@beekeeperstudio/plugin/-/plugin-1.2.2.tgz#aec18f3c02d35493a8a1a566dec779906145faee"
46+
integrity sha512-JWUCjfS2POwLeO7hQfEdeuokGTfVg6ArEC6AQIqUZ87/JZgnQu3BJUUKsg2Qk73SBppm4lBdXSLa24tVVw8m0w==
4747

4848
"@cfworker/json-schema@^4.0.2":
4949
version "4.1.1"

0 commit comments

Comments
 (0)