@lobehub/chat 1.104.5 → 1.105.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/changelog/v1.json +9 -0
- package/package.json +1 -1
- package/src/app/[variants]/(main)/profile/apikey/Client.tsx +209 -0
- package/src/app/[variants]/(main)/profile/apikey/features/ApiKeyDatePicker/index.tsx +39 -0
- package/src/app/[variants]/(main)/profile/apikey/features/ApiKeyDisplay/index.tsx +60 -0
- package/src/app/[variants]/(main)/profile/apikey/features/ApiKeyModal/index.tsx +58 -0
- package/src/app/[variants]/(main)/profile/apikey/features/EditableCell/index.tsx +223 -0
- package/src/app/[variants]/(main)/profile/apikey/features/index.ts +3 -0
- package/src/app/[variants]/(main)/profile/apikey/page.tsx +32 -0
- package/src/app/[variants]/(main)/profile/hooks/useCategory.tsx +12 -1
- package/src/config/featureFlags/schema.ts +7 -0
- package/src/database/migrations/0029_add_apikey_manage.sql +16 -0
- package/src/database/migrations/meta/0029_snapshot.json +6166 -0
- package/src/database/migrations/meta/_journal.json +7 -0
- package/src/database/models/apiKey.ts +116 -0
- package/src/database/schemas/apiKey.ts +25 -0
- package/src/database/schemas/index.ts +1 -0
- package/src/database/schemas/rbac.ts +11 -1
- package/src/locales/default/auth.ts +54 -0
- package/src/server/routers/lambda/apiKey.ts +80 -0
- package/src/server/routers/lambda/index.ts +2 -0
- package/src/store/global/initialState.ts +1 -0
- package/src/store/serverConfig/selectors.test.ts +1 -0
- package/src/types/apiKey.ts +12 -0
- package/src/utils/apiKey.ts +60 -0
@@ -1,5 +1,5 @@
|
|
1
1
|
import { Icon } from '@lobehub/ui';
|
2
|
-
import { ChartColumnBigIcon, ShieldCheck, UserCircle } from 'lucide-react';
|
2
|
+
import { ChartColumnBigIcon, KeyIcon, ShieldCheck, UserCircle } from 'lucide-react';
|
3
3
|
import Link from 'next/link';
|
4
4
|
import { useTranslation } from 'react-i18next';
|
5
5
|
|
@@ -7,12 +7,14 @@ import type { MenuProps } from '@/components/Menu';
|
|
7
7
|
import { enableAuth } from '@/const/auth';
|
8
8
|
import { isDeprecatedEdition } from '@/const/version';
|
9
9
|
import { ProfileTabs } from '@/store/global/initialState';
|
10
|
+
import { featureFlagsSelectors, useServerConfigStore } from '@/store/serverConfig';
|
10
11
|
import { useUserStore } from '@/store/user';
|
11
12
|
import { authSelectors } from '@/store/user/slices/auth/selectors';
|
12
13
|
|
13
14
|
export const useCategory = () => {
|
14
15
|
const { t } = useTranslation('auth');
|
15
16
|
const [isLoginWithClerk] = useUserStore((s) => [authSelectors.isLoginWithClerk(s)]);
|
17
|
+
const { showApiKeyManage } = useServerConfigStore(featureFlagsSelectors);
|
16
18
|
|
17
19
|
const cateItems: MenuProps['items'] = [
|
18
20
|
{
|
@@ -43,6 +45,15 @@ export const useCategory = () => {
|
|
43
45
|
</Link>
|
44
46
|
),
|
45
47
|
},
|
48
|
+
!!showApiKeyManage && {
|
49
|
+
icon: <Icon icon={KeyIcon} />,
|
50
|
+
key: ProfileTabs.APIKey,
|
51
|
+
label: (
|
52
|
+
<Link href={'/profile/apikey'} onClick={(e) => e.preventDefault()}>
|
53
|
+
{t('tab.apikey')}
|
54
|
+
</Link>
|
55
|
+
),
|
56
|
+
},
|
46
57
|
].filter(Boolean) as MenuProps['items'];
|
47
58
|
|
48
59
|
return cateItems;
|
@@ -16,6 +16,9 @@ export const FeatureFlagsSchema = z.object({
|
|
16
16
|
openai_api_key: z.boolean().optional(),
|
17
17
|
openai_proxy_url: z.boolean().optional(),
|
18
18
|
|
19
|
+
// profile
|
20
|
+
api_key_manage: z.boolean().optional(),
|
21
|
+
|
19
22
|
create_session: z.boolean().optional(),
|
20
23
|
edit_agent: z.boolean().optional(),
|
21
24
|
|
@@ -56,6 +59,8 @@ export const DEFAULT_FEATURE_FLAGS: IFeatureFlags = {
|
|
56
59
|
openai_api_key: true,
|
57
60
|
openai_proxy_url: true,
|
58
61
|
|
62
|
+
api_key_manage: false,
|
63
|
+
|
59
64
|
create_session: true,
|
60
65
|
edit_agent: true,
|
61
66
|
|
@@ -97,6 +102,8 @@ export const mapFeatureFlagsEnvToState = (config: IFeatureFlags) => {
|
|
97
102
|
showOpenAIApiKey: config.openai_api_key,
|
98
103
|
showOpenAIProxyUrl: config.openai_proxy_url,
|
99
104
|
|
105
|
+
showApiKeyManage: config.api_key_manage,
|
106
|
+
|
100
107
|
enablePlugins: config.plugins,
|
101
108
|
showDalle: config.dalle,
|
102
109
|
showChangelog: config.changelog,
|
@@ -0,0 +1,16 @@
|
|
1
|
+
CREATE TABLE IF NOT EXISTS "api_keys" (
|
2
|
+
"id" integer PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY (sequence name "api_keys_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
|
3
|
+
"name" varchar(256) NOT NULL,
|
4
|
+
"key" varchar(256) NOT NULL,
|
5
|
+
"enabled" boolean DEFAULT true,
|
6
|
+
"expires_at" timestamp with time zone,
|
7
|
+
"last_used_at" timestamp with time zone,
|
8
|
+
"user_id" text NOT NULL,
|
9
|
+
"accessed_at" timestamp with time zone DEFAULT now() NOT NULL,
|
10
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
11
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
|
12
|
+
CONSTRAINT "api_keys_key_unique" UNIQUE("key")
|
13
|
+
);
|
14
|
+
--> statement-breakpoint
|
15
|
+
ALTER TABLE "rbac_roles" ADD COLUMN "metadata" jsonb DEFAULT '{}'::jsonb;--> statement-breakpoint
|
16
|
+
ALTER TABLE "api_keys" ADD CONSTRAINT "api_keys_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;
|