@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.
@@ -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;