@lobehub/chat 1.104.4 → 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.
Files changed (27) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/changelog/v1.json +18 -0
  3. package/package.json +1 -1
  4. package/src/app/[variants]/(main)/profile/apikey/Client.tsx +209 -0
  5. package/src/app/[variants]/(main)/profile/apikey/features/ApiKeyDatePicker/index.tsx +39 -0
  6. package/src/app/[variants]/(main)/profile/apikey/features/ApiKeyDisplay/index.tsx +60 -0
  7. package/src/app/[variants]/(main)/profile/apikey/features/ApiKeyModal/index.tsx +58 -0
  8. package/src/app/[variants]/(main)/profile/apikey/features/EditableCell/index.tsx +223 -0
  9. package/src/app/[variants]/(main)/profile/apikey/features/index.ts +3 -0
  10. package/src/app/[variants]/(main)/profile/apikey/page.tsx +32 -0
  11. package/src/app/[variants]/(main)/profile/hooks/useCategory.tsx +12 -1
  12. package/src/app/[variants]/(main)/settings/_layout/Desktop/index.tsx +1 -1
  13. package/src/config/featureFlags/schema.ts +7 -0
  14. package/src/database/migrations/0029_add_apikey_manage.sql +16 -0
  15. package/src/database/migrations/meta/0029_snapshot.json +6166 -0
  16. package/src/database/migrations/meta/_journal.json +7 -0
  17. package/src/database/models/apiKey.ts +116 -0
  18. package/src/database/schemas/apiKey.ts +25 -0
  19. package/src/database/schemas/index.ts +1 -0
  20. package/src/database/schemas/rbac.ts +11 -1
  21. package/src/locales/default/auth.ts +54 -0
  22. package/src/server/routers/lambda/apiKey.ts +80 -0
  23. package/src/server/routers/lambda/index.ts +2 -0
  24. package/src/store/global/initialState.ts +1 -0
  25. package/src/store/serverConfig/selectors.test.ts +1 -0
  26. package/src/types/apiKey.ts +12 -0
  27. package/src/utils/apiKey.ts +60 -0
@@ -0,0 +1,32 @@
1
+ import { notFound } from 'next/navigation';
2
+
3
+ import { serverFeatureFlags } from '@/config/featureFlags';
4
+ import { metadataModule } from '@/server/metadata';
5
+ import { translation } from '@/server/translation';
6
+ import { DynamicLayoutProps } from '@/types/next';
7
+ import { RouteVariants } from '@/utils/server/routeVariants';
8
+
9
+ import Page from '../../settings/system-agent';
10
+ import Client from './Client';
11
+
12
+ export const generateMetadata = async (props: DynamicLayoutProps) => {
13
+ const locale = await RouteVariants.getLocale(props);
14
+ const { t } = await translation('auth', locale);
15
+ return metadataModule.generate({
16
+ description: t('header.desc'),
17
+ title: t('tab.apikey'),
18
+ url: '/profile/apikey',
19
+ });
20
+ };
21
+
22
+ const page = () => {
23
+ const { showApiKeyManage } = serverFeatureFlags();
24
+
25
+ if (!showApiKeyManage) return notFound();
26
+
27
+ return <Client />;
28
+ };
29
+
30
+ Page.displayName = 'ApiKey';
31
+
32
+ export default page;
@@ -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;
@@ -36,7 +36,7 @@ const Layout = memo<LayoutProps>(({ children, category }) => {
36
36
  height={'100%'}
37
37
  horizontal={md}
38
38
  ref={ref}
39
- style={{ background: theme.colorBgContainer, flex: '1', position: 'relative', width: '0' }}
39
+ style={{ background: theme.colorBgContainer, flex: '1', position: 'relative' }}
40
40
  >
41
41
  {md ? (
42
42
  <SideBar>{category}</SideBar>
@@ -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;