diff --git a/packages/web/src/components/ConversationForm.tsx b/packages/web/src/components/ConversationForm.tsx index cbca377..5ed7d5b 100644 --- a/packages/web/src/components/ConversationForm.tsx +++ b/packages/web/src/components/ConversationForm.tsx @@ -53,9 +53,11 @@ const ConversationFormProvided = ({ - - - + {!hideAppSettings && ( + + + + )} {currentTab !== "app" && ( @@ -65,10 +67,8 @@ const ConversationFormProvided = ({ {form.values.save && ( This conversation will be saved to your browser's - local storage, along with your API key, if - specified. Make sure that you trust the device you - are using and that you are not using a shared - device. + local storage. Make sure the device you're using is + trusted and not shared with anyone else. )} diff --git a/packages/web/src/contexts/providers/PersistenceProvider.tsx b/packages/web/src/contexts/providers/PersistenceProvider.tsx index d50cac8..0661c49 100644 --- a/packages/web/src/contexts/providers/PersistenceProvider.tsx +++ b/packages/web/src/contexts/providers/PersistenceProvider.tsx @@ -12,16 +12,18 @@ import useCallableFunctions from "../../hooks/useCallableFunctions"; import { PersistenceCallableFunction } from "../../entities/persistenceCallableFunction"; import { STORAGEKEY_PERSISTENCE } from "../../config/constants"; import { persistenceVersion } from "../../entities/migrations/persistence"; +import useSettings from "../../hooks/useSettings"; interface PersistenceProviderProps { children?: React.ReactNode; } const PersistenceProvider = ({ children }: PersistenceProviderProps) => { + const { settings } = useSettings(); + const { conversations, addConversation, - setActiveConversation, getConversationName, setConversationName, getConversationLastEdit, @@ -234,9 +236,14 @@ const PersistenceProvider = ({ children }: PersistenceProviderProps) => { const { name, lastEdited, ...conversationJson } = persistence.conversations[i]; const newConversation = addConversation( - await Conversation.fromJSON(conversationJson) + await Conversation.fromJSON({ + ...conversationJson, + config: { + ...conversationJson.config, + apiKey: settings.apiKey || undefined, + }, + }) ); - if (i === 0) setActiveConversation(newConversation.id, true); addPersistedConversationId(newConversation.id); setConversationName(newConversation.id, name); setConversationLastEdit(newConversation.id, lastEdited); @@ -284,9 +291,9 @@ const PersistenceProvider = ({ children }: PersistenceProviderProps) => { persistence.functions, persistence.functionsImportWarning, persistence.functionsWarning, - setActiveConversation, setConversationLastEdit, setConversationName, + settings.apiKey, ]); // Save conversations on change diff --git a/packages/web/src/entities/migrations/persistence/1688740831717_remove-api-key.ts b/packages/web/src/entities/migrations/persistence/1688740831717_remove-api-key.ts new file mode 100644 index 0000000..26e19aa --- /dev/null +++ b/packages/web/src/entities/migrations/persistence/1688740831717_remove-api-key.ts @@ -0,0 +1,18 @@ +export const migratePersistenceRemoveApiKey = ( + value: Record +): Record => { + if (!value.conversations || !Array.isArray(value.conversations)) + return value; + + value.conversations = value.conversations.map((conversation) => { + if (conversation.config?.apiKey === undefined) return conversation; + const { apiKey, ...config } = conversation.config; + + return { + ...conversation, + config, + }; + }); + + return value; +}; diff --git a/packages/web/src/entities/migrations/persistence/index.ts b/packages/web/src/entities/migrations/persistence/index.ts index f6bd905..5f3317b 100644 --- a/packages/web/src/entities/migrations/persistence/index.ts +++ b/packages/web/src/entities/migrations/persistence/index.ts @@ -1,7 +1,9 @@ import { migratePersistenceInitial } from "./1688489405401_initial"; +import { migratePersistenceRemoveApiKey } from "./1688740831717_remove-api-key"; const migrations: ((value: Record) => Record)[] = [ migratePersistenceInitial, + migratePersistenceRemoveApiKey, ]; export const persistenceVersion = migrations.length; diff --git a/packages/web/src/entities/persistenceConversation.ts b/packages/web/src/entities/persistenceConversation.ts index 38a37e0..975b657 100644 --- a/packages/web/src/entities/persistenceConversation.ts +++ b/packages/web/src/entities/persistenceConversation.ts @@ -4,6 +4,10 @@ import { conversationSchema } from "gpt-turbo"; export const persistenceConversationSchema = conversationSchema.extend({ name: z.string(), lastEdited: z.number(), + config: conversationSchema.shape.config + .unwrap() + .omit({ apiKey: true }) + .optional(), }); export type PersistenceConversation = z.infer<