Skip to content

Commit 08f505f

Browse files
authored
✨ feat: support new ai provider in client pglite (lobehub#5488)
* update to pglite mode * add service * 新增 DevPanel * 新增数据库预览 UI * Update useCategory.tsx * add postgres table viewer * improve table detail * fix * fix list * fix custom provider in client mode * fix build * fix tests * fix url * add test for service
1 parent aa07c40 commit 08f505f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1682
-188
lines changed

package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
"sideEffects": false,
2828
"scripts": {
2929
"build": "next build",
30-
"build:analyze": "ANALYZE=true next build",
31-
"build:docker": "DOCKER=true next build && npm run build-sitemap",
3230
"postbuild": "npm run build-sitemap && npm run build-migrate-db",
3331
"build-migrate-db": "bun run db:migrate",
3432
"build-sitemap": "tsx ./scripts/buildSitemapIndex/index.ts",
33+
"build:analyze": "ANALYZE=true next build",
34+
"build:docker": "DOCKER=true next build && npm run build-sitemap",
3535
"db:generate": "drizzle-kit generate && npm run db:generate-client",
3636
"db:generate-client": "tsx ./scripts/migrateClientDB/compile-migrations.ts",
3737
"db:migrate": "MIGRATION_DB=1 tsx ./scripts/migrateServerDB/index.ts",
@@ -59,11 +59,11 @@
5959
"start": "next start -p 3210",
6060
"stylelint": "stylelint \"src/**/*.{js,jsx,ts,tsx}\" --fix",
6161
"test": "npm run test-app && npm run test-server",
62-
"test:update": "vitest -u",
6362
"test-app": "vitest run --config vitest.config.ts",
6463
"test-app:coverage": "vitest run --config vitest.config.ts --coverage",
6564
"test-server": "vitest run --config vitest.server.config.ts",
6665
"test-server:coverage": "vitest run --config vitest.server.config.ts --coverage",
66+
"test:update": "vitest -u",
6767
"type-check": "tsc --noEmit",
6868
"webhook:ngrok": "ngrok http http://localhost:3011",
6969
"workflow:cdn": "tsx ./scripts/cdnWorkflow/index.ts",
@@ -206,6 +206,7 @@
206206
"react-layout-kit": "^1.9.1",
207207
"react-lazy-load": "^4.0.1",
208208
"react-pdf": "^9.2.1",
209+
"react-rnd": "^10.4.14",
209210
"react-scan": "^0.0.54",
210211
"react-virtuoso": "^4.12.3",
211212
"react-wrap-balancer": "^1.1.1",

src/app/(main)/discover/(detail)/provider/[slug]/features/ProviderConfig.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { memo } from 'react';
1010
import { useTranslation } from 'react-i18next';
1111
import { FlexboxProps } from 'react-layout-kit';
1212

13-
import { isServerMode } from '@/const/version';
13+
import { isDeprecatedEdition } from '@/const/version';
1414
import { DiscoverProviderItem } from '@/types/discover';
1515

1616
const useStyles = createStyles(({ css }) => ({
@@ -32,7 +32,7 @@ const ProviderConfig = memo<ProviderConfigProps>(({ data, identifier }) => {
3232

3333
const router = useRouter();
3434
const openSettings = () => {
35-
router.push(!isServerMode ? '/settings/llm' : `/settings/provider/${identifier}`);
35+
router.push(isDeprecatedEdition ? '/settings/llm' : `/settings/provider/${identifier}`);
3636
};
3737

3838
const icon = <Icon icon={SquareArrowOutUpRight} size={{ fontSize: 16 }} />;

src/app/(main)/settings/hooks/useCategory.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { useTranslation } from 'react-i18next';
77
import { Flexbox } from 'react-layout-kit';
88

99
import type { MenuProps } from '@/components/Menu';
10-
import { isServerMode } from '@/const/version';
10+
import { isDeprecatedEdition } from '@/const/version';
1111
import { SettingsTabs } from '@/store/global/initialState';
1212
import { featureFlagsSelectors, useServerConfigStore } from '@/store/serverConfig';
1313

@@ -53,7 +53,7 @@ export const useCategory = () => {
5353
},
5454
showLLM &&
5555
// TODO: Remove /llm when v2.0
56-
!isServerMode
56+
(isDeprecatedEdition
5757
? {
5858
icon: <Icon icon={Brain} />,
5959
key: SettingsTabs.LLM,
@@ -71,7 +71,7 @@ export const useCategory = () => {
7171
{t('tab.provider')}
7272
</Link>
7373
),
74-
},
74+
}),
7575

7676
enableSTT && {
7777
icon: <Icon icon={Mic2} />,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use client';
2+
3+
import { memo } from 'react';
4+
import { Flexbox } from 'react-layout-kit';
5+
import useSWR from 'swr';
6+
7+
import { aiProviderService } from '@/services/aiProvider';
8+
9+
import ModelList from '../../features/ModelList';
10+
import ProviderConfig from '../../features/ProviderConfig';
11+
12+
const ClientMode = memo<{ id: string }>(({ id }) => {
13+
const { data, isLoading } = useSWR('get-client-provider', () =>
14+
aiProviderService.getAiProviderById(id),
15+
);
16+
17+
return (
18+
<Flexbox gap={24} paddingBlock={8}>
19+
{!isLoading && data && <ProviderConfig {...data} />}
20+
<ModelList id={id} />
21+
</Flexbox>
22+
);
23+
});
24+
25+
export default ClientMode;

src/app/(main)/settings/provider/(detail)/[id]/page.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { KeyVaultsGateKeeper } from '@/server/modules/KeyVaultsEncrypt';
88
import { PagePropsWithId } from '@/types/next';
99
import { getUserAuth } from '@/utils/server/auth';
1010

11+
import ClientMode from './ClientMode';
1112
import ProviderDetail from './index';
1213

1314
const Page = async (props: PagePropsWithId) => {
@@ -33,7 +34,7 @@ const Page = async (props: PagePropsWithId) => {
3334
return <ProviderDetail {...userCard} />;
3435
}
3536

36-
return <div>not found</div>;
37+
return <ClientMode id={params.id} />;
3738
};
3839

3940
export default Page;

src/app/(main)/settings/provider/ProviderMenu/SortProviderModal/index.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ const ConfigGroupModal = memo<ConfigGroupModalProps>(({ open, onCancel, defaultI
7272
id: item.id,
7373
sort: index,
7474
}));
75-
console.log(sortMap);
7675
setLoading(true);
7776
await updateAiProviderSort(sortMap);
7877
setLoading(false);

src/database/client/migrations.json

+11
Original file line numberDiff line numberDiff line change
@@ -282,5 +282,16 @@
282282
"bps": true,
283283
"folderMillis": 1731858381716,
284284
"hash": "d8263bfefe296ed366379c7b7fc65195d12e6a1c0a9f1c96097ea28f2123fe50"
285+
},
286+
{
287+
"sql": [
288+
"CREATE TABLE \"ai_models\" (\n\t\"id\" varchar(150) NOT NULL,\n\t\"display_name\" varchar(200),\n\t\"description\" text,\n\t\"organization\" varchar(100),\n\t\"enabled\" boolean,\n\t\"provider_id\" varchar(64) NOT NULL,\n\t\"type\" varchar(20) DEFAULT 'chat' NOT NULL,\n\t\"sort\" integer,\n\t\"user_id\" text NOT NULL,\n\t\"pricing\" jsonb,\n\t\"parameters\" jsonb DEFAULT '{}'::jsonb,\n\t\"config\" jsonb,\n\t\"abilities\" jsonb DEFAULT '{}'::jsonb,\n\t\"context_window_tokens\" integer,\n\t\"source\" varchar(20),\n\t\"released_at\" varchar(10),\n\t\"accessed_at\" timestamp with time zone DEFAULT now() NOT NULL,\n\t\"created_at\" timestamp with time zone DEFAULT now() NOT NULL,\n\t\"updated_at\" timestamp with time zone DEFAULT now() NOT NULL,\n\tCONSTRAINT \"ai_models_id_provider_id_user_id_pk\" PRIMARY KEY(\"id\",\"provider_id\",\"user_id\")\n);\n",
289+
"\nCREATE TABLE \"ai_providers\" (\n\t\"id\" varchar(64) NOT NULL,\n\t\"name\" text,\n\t\"user_id\" text NOT NULL,\n\t\"sort\" integer,\n\t\"enabled\" boolean,\n\t\"fetch_on_client\" boolean,\n\t\"check_model\" text,\n\t\"logo\" text,\n\t\"description\" text,\n\t\"key_vaults\" text,\n\t\"source\" varchar(20),\n\t\"settings\" jsonb,\n\t\"accessed_at\" timestamp with time zone DEFAULT now() NOT NULL,\n\t\"created_at\" timestamp with time zone DEFAULT now() NOT NULL,\n\t\"updated_at\" timestamp with time zone DEFAULT now() NOT NULL,\n\tCONSTRAINT \"ai_providers_id_user_id_pk\" PRIMARY KEY(\"id\",\"user_id\")\n);\n",
290+
"\nALTER TABLE \"ai_models\" ADD CONSTRAINT \"ai_models_user_id_users_id_fk\" FOREIGN KEY (\"user_id\") REFERENCES \"public\".\"users\"(\"id\") ON DELETE cascade ON UPDATE no action;",
291+
"\nALTER TABLE \"ai_providers\" ADD CONSTRAINT \"ai_providers_user_id_users_id_fk\" FOREIGN KEY (\"user_id\") REFERENCES \"public\".\"users\"(\"id\") ON DELETE cascade ON UPDATE no action;"
292+
],
293+
"bps": true,
294+
"folderMillis": 1735834653361,
295+
"hash": "845a692ceabbfc3caf252a97d3e19a213bc0c433df2689900135f9cfded2cf49"
285296
}
286297
]

0 commit comments

Comments
 (0)