Upload APIKeyManager.tsx
Browse files
app/components/chat/APIKeyManager.tsx
CHANGED
@@ -2,6 +2,7 @@ import React, { useState, useEffect } from 'react';
|
|
2 |
import { IconButton } from '~/components/ui/IconButton';
|
3 |
import { Switch } from '~/components/ui/Switch';
|
4 |
import type { ProviderInfo } from '~/types/model';
|
|
|
5 |
|
6 |
interface APIKeyManagerProps {
|
7 |
provider: ProviderInfo;
|
@@ -11,6 +12,23 @@ interface APIKeyManagerProps {
|
|
11 |
labelForGetApiKey?: string;
|
12 |
}
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
export const APIKeyManager: React.FC<APIKeyManagerProps> = ({
|
15 |
provider,
|
16 |
apiKey,
|
|
|
2 |
import { IconButton } from '~/components/ui/IconButton';
|
3 |
import { Switch } from '~/components/ui/Switch';
|
4 |
import type { ProviderInfo } from '~/types/model';
|
5 |
+
import Cookies from 'js-cookie';
|
6 |
|
7 |
interface APIKeyManagerProps {
|
8 |
provider: ProviderInfo;
|
|
|
12 |
labelForGetApiKey?: string;
|
13 |
}
|
14 |
|
15 |
+
const apiKeyMemoizeCache: { [k: string]: Record<string, string> } = {};
|
16 |
+
|
17 |
+
export function getApiKeysFromCookies() {
|
18 |
+
const storedApiKeys = Cookies.get('apiKeys');
|
19 |
+
let parsedKeys = {};
|
20 |
+
|
21 |
+
if (storedApiKeys) {
|
22 |
+
parsedKeys = apiKeyMemoizeCache[storedApiKeys];
|
23 |
+
|
24 |
+
if (!parsedKeys) {
|
25 |
+
parsedKeys = apiKeyMemoizeCache[storedApiKeys] = JSON.parse(storedApiKeys);
|
26 |
+
}
|
27 |
+
}
|
28 |
+
|
29 |
+
return parsedKeys;
|
30 |
+
}
|
31 |
+
|
32 |
export const APIKeyManager: React.FC<APIKeyManagerProps> = ({
|
33 |
provider,
|
34 |
apiKey,
|