@@ -12,7 +12,7 @@ import {
1212 ToolMessage ,
1313} from "@langchain/core/messages" ;
1414import { BaseModelProvider , BaseProvider } from "./providers/BaseModelProvider" ;
15- import { request } from "@beekeeperstudio/plugin" ;
15+ import { expandTableResult , getEncryptedData , getViewState , setEncryptedData , setTabTitle , setViewState } from "@beekeeperstudio/plugin" ;
1616import { isAbortError } from "./utils" ;
1717
1818interface Tool {
@@ -37,10 +37,6 @@ interface ViewState {
3737 conversationTitle : string ;
3838}
3939
40- interface EncryptedData {
41- anthropicApiKey : string ;
42- }
43-
4440interface 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 ;
0 commit comments