@lobehub/lobehub 2.0.0-next.191 → 2.0.0-next.192
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/e2e/docs/testing-tips.md +30 -0
- package/e2e/src/steps/discover/smoke.steps.ts +11 -33
- package/locales/zh-CN/auth.json +1 -1
- package/package.json +1 -2
- package/packages/database/package.json +1 -1
- package/packages/database/src/client/db.test.ts +19 -144
- package/packages/database/src/client/db.ts +26 -234
- package/packages/database/src/models/__tests__/_util.ts +19 -3
- package/src/app/[variants]/(main)/settings/provider/features/ModelList/ModelItem.tsx +8 -7
- package/src/libs/next/config/define-config.ts +1 -1
- package/packages/database/src/client/pglite.ts +0 -17
- package/packages/database/src/client/pglite.worker.ts +0 -25
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,31 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog
|
|
4
4
|
|
|
5
|
+
## [Version 2.0.0-next.192](https://github.com/lobehub/lobe-chat/compare/v2.0.0-next.191...v2.0.0-next.192)
|
|
6
|
+
|
|
7
|
+
<sup>Released on **2026-01-02**</sup>
|
|
8
|
+
|
|
9
|
+
#### 🐛 Bug Fixes
|
|
10
|
+
|
|
11
|
+
- **misc**: Fix model edit icon missing.
|
|
12
|
+
|
|
13
|
+
<br/>
|
|
14
|
+
|
|
15
|
+
<details>
|
|
16
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
17
|
+
|
|
18
|
+
#### What's fixed
|
|
19
|
+
|
|
20
|
+
- **misc**: Fix model edit icon missing, closes [#11105](https://github.com/lobehub/lobe-chat/issues/11105) ([0f88995](https://github.com/lobehub/lobe-chat/commit/0f88995))
|
|
21
|
+
|
|
22
|
+
</details>
|
|
23
|
+
|
|
24
|
+
<div align="right">
|
|
25
|
+
|
|
26
|
+
[](#readme-top)
|
|
27
|
+
|
|
28
|
+
</div>
|
|
29
|
+
|
|
5
30
|
## [Version 2.0.0-next.191](https://github.com/lobehub/lobe-chat/compare/v2.0.0-next.190...v2.0.0-next.191)
|
|
6
31
|
|
|
7
32
|
<sup>Released on **2026-01-02**</sup>
|
package/changelog/v1.json
CHANGED
package/e2e/docs/testing-tips.md
CHANGED
|
@@ -64,6 +64,36 @@ HEADLESS=false pnpm exec cucumber-js --config cucumber.config.js --tags "@smoke"
|
|
|
64
64
|
|
|
65
65
|
## 常见问题
|
|
66
66
|
|
|
67
|
+
### waitForLoadState ('networkidle') 超时
|
|
68
|
+
|
|
69
|
+
**原因**: `networkidle` 表示 500ms 内没有网络请求。在 CI 环境中,由于分析脚本、外部资源加载、轮询等持续网络活动,这个状态可能永远无法达到。
|
|
70
|
+
|
|
71
|
+
**错误示例**:
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
page.waitForLoadState: Timeout 10000ms exceeded.
|
|
75
|
+
=========================== logs ===========================
|
|
76
|
+
"load" event fired
|
|
77
|
+
============================================================
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
**解决**:
|
|
81
|
+
|
|
82
|
+
- **避免使用 `networkidle`** - 这是不可靠的等待策略
|
|
83
|
+
- **直接等待目标元素** - 使用 `expect(element).toBeVisible({ timeout: 30_000 })` 替代
|
|
84
|
+
- 如果必须等待页面加载完成,使用 `domcontentloaded` 或 `load` 事件
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
// ❌ 不推荐 - networkidle 在 CI 中容易超时
|
|
88
|
+
await this.page.waitForLoadState('networkidle', { timeout: 10_000 });
|
|
89
|
+
const element = this.page.locator('[data-testid="my-element"]');
|
|
90
|
+
await expect(element).toBeVisible();
|
|
91
|
+
|
|
92
|
+
// ✅ 推荐 - 直接等待目标元素
|
|
93
|
+
const element = this.page.locator('[data-testid="my-element"]');
|
|
94
|
+
await expect(element).toBeVisible({ timeout: 30_000 });
|
|
95
|
+
```
|
|
96
|
+
|
|
67
97
|
### 测试超时 (function timed out)
|
|
68
98
|
|
|
69
99
|
**原因**: 元素定位失败或等待时间不足
|
|
@@ -9,50 +9,40 @@ import { CustomWorld } from '../../support/world';
|
|
|
9
9
|
|
|
10
10
|
// Home Page Steps
|
|
11
11
|
Then('I should see the featured assistants section', async function (this: CustomWorld) {
|
|
12
|
-
await this.page.waitForLoadState('networkidle', { timeout: 10_000 });
|
|
13
|
-
|
|
14
12
|
// Look for "Featured Agents" heading text (i18n key: home.featuredAssistants)
|
|
15
13
|
// Supports: en-US "Featured Agents", zh-CN "推荐助理"
|
|
16
14
|
const featuredSection = this.page
|
|
17
15
|
.getByRole('heading', { name: /featured agents|推荐助理/i })
|
|
18
16
|
.first();
|
|
19
|
-
await expect(featuredSection).toBeVisible({ timeout:
|
|
17
|
+
await expect(featuredSection).toBeVisible({ timeout: 30_000 });
|
|
20
18
|
});
|
|
21
19
|
|
|
22
20
|
Then('I should see the featured MCP tools section', async function (this: CustomWorld) {
|
|
23
|
-
await this.page.waitForLoadState('networkidle', { timeout: 10_000 });
|
|
24
|
-
|
|
25
21
|
// Look for "Featured Skills" heading text (i18n key: home.featuredTools)
|
|
26
22
|
// Supports: en-US "Featured Skills", zh-CN "推荐技能"
|
|
27
23
|
const mcpSection = this.page.getByRole('heading', { name: /featured skills|推荐技能/i }).first();
|
|
28
|
-
await expect(mcpSection).toBeVisible({ timeout:
|
|
24
|
+
await expect(mcpSection).toBeVisible({ timeout: 30_000 });
|
|
29
25
|
});
|
|
30
26
|
|
|
31
27
|
// Assistant List Page Steps
|
|
32
28
|
Then('I should see the search bar', async function (this: CustomWorld) {
|
|
33
|
-
await this.page.waitForLoadState('networkidle', { timeout: 10_000 });
|
|
34
|
-
|
|
35
29
|
// SearchBar component has data-testid="search-bar"
|
|
36
30
|
const searchBar = this.page.locator('[data-testid="search-bar"]').first();
|
|
37
|
-
await expect(searchBar).toBeVisible({ timeout:
|
|
31
|
+
await expect(searchBar).toBeVisible({ timeout: 30_000 });
|
|
38
32
|
});
|
|
39
33
|
|
|
40
34
|
Then('I should see the category menu', async function (this: CustomWorld) {
|
|
41
|
-
await this.page.waitForLoadState('networkidle', { timeout: 10_000 });
|
|
42
|
-
|
|
43
35
|
// CategoryMenu component has data-testid="category-menu"
|
|
44
36
|
const categoryMenu = this.page.locator('[data-testid="category-menu"]').first();
|
|
45
|
-
await expect(categoryMenu).toBeVisible({ timeout:
|
|
37
|
+
await expect(categoryMenu).toBeVisible({ timeout: 30_000 });
|
|
46
38
|
});
|
|
47
39
|
|
|
48
40
|
Then('I should see assistant cards', async function (this: CustomWorld) {
|
|
49
|
-
await this.page.waitForLoadState('networkidle', { timeout: 10_000 });
|
|
50
|
-
|
|
51
41
|
// Look for assistant items by data-testid
|
|
52
42
|
const assistantItems = this.page.locator('[data-testid="assistant-item"]');
|
|
53
43
|
|
|
54
44
|
// Wait for at least one item to be visible
|
|
55
|
-
await expect(assistantItems.first()).toBeVisible({ timeout:
|
|
45
|
+
await expect(assistantItems.first()).toBeVisible({ timeout: 30_000 });
|
|
56
46
|
|
|
57
47
|
// Check we have multiple items
|
|
58
48
|
const count = await assistantItems.count();
|
|
@@ -60,22 +50,18 @@ Then('I should see assistant cards', async function (this: CustomWorld) {
|
|
|
60
50
|
});
|
|
61
51
|
|
|
62
52
|
Then('I should see pagination controls', async function (this: CustomWorld) {
|
|
63
|
-
await this.page.waitForLoadState('networkidle', { timeout: 10_000 });
|
|
64
|
-
|
|
65
53
|
// Pagination component has data-testid="pagination"
|
|
66
54
|
const pagination = this.page.locator('[data-testid="pagination"]').first();
|
|
67
|
-
await expect(pagination).toBeVisible({ timeout:
|
|
55
|
+
await expect(pagination).toBeVisible({ timeout: 30_000 });
|
|
68
56
|
});
|
|
69
57
|
|
|
70
58
|
// Model List Page Steps
|
|
71
59
|
Then('I should see model cards', async function (this: CustomWorld) {
|
|
72
|
-
await this.page.waitForLoadState('networkidle', { timeout: 10_000 });
|
|
73
|
-
|
|
74
60
|
// Model items have data-testid="model-item"
|
|
75
61
|
const modelItems = this.page.locator('[data-testid="model-item"]');
|
|
76
62
|
|
|
77
63
|
// Wait for at least one item to be visible
|
|
78
|
-
await expect(modelItems.first()).toBeVisible({ timeout:
|
|
64
|
+
await expect(modelItems.first()).toBeVisible({ timeout: 30_000 });
|
|
79
65
|
|
|
80
66
|
// Check we have multiple items
|
|
81
67
|
const count = await modelItems.count();
|
|
@@ -83,22 +69,18 @@ Then('I should see model cards', async function (this: CustomWorld) {
|
|
|
83
69
|
});
|
|
84
70
|
|
|
85
71
|
Then('I should see the sort dropdown', async function (this: CustomWorld) {
|
|
86
|
-
await this.page.waitForLoadState('networkidle', { timeout: 10_000 });
|
|
87
|
-
|
|
88
72
|
// SortButton has data-testid="sort-dropdown"
|
|
89
73
|
const sortDropdown = this.page.locator('[data-testid="sort-dropdown"]').first();
|
|
90
|
-
await expect(sortDropdown).toBeVisible({ timeout:
|
|
74
|
+
await expect(sortDropdown).toBeVisible({ timeout: 30_000 });
|
|
91
75
|
});
|
|
92
76
|
|
|
93
77
|
// Provider List Page Steps
|
|
94
78
|
Then('I should see provider cards', async function (this: CustomWorld) {
|
|
95
|
-
await this.page.waitForLoadState('networkidle', { timeout: 10_000 });
|
|
96
|
-
|
|
97
79
|
// Look for provider items by data-testid
|
|
98
80
|
const providerItems = this.page.locator('[data-testid="provider-item"]');
|
|
99
81
|
|
|
100
82
|
// Wait for at least one item to be visible
|
|
101
|
-
await expect(providerItems.first()).toBeVisible({ timeout:
|
|
83
|
+
await expect(providerItems.first()).toBeVisible({ timeout: 30_000 });
|
|
102
84
|
|
|
103
85
|
// Check we have multiple items
|
|
104
86
|
const count = await providerItems.count();
|
|
@@ -107,13 +89,11 @@ Then('I should see provider cards', async function (this: CustomWorld) {
|
|
|
107
89
|
|
|
108
90
|
// MCP List Page Steps
|
|
109
91
|
Then('I should see MCP cards', async function (this: CustomWorld) {
|
|
110
|
-
await this.page.waitForLoadState('networkidle', { timeout: 10_000 });
|
|
111
|
-
|
|
112
92
|
// Look for MCP items by data-testid
|
|
113
93
|
const mcpItems = this.page.locator('[data-testid="mcp-item"]');
|
|
114
94
|
|
|
115
95
|
// Wait for at least one item to be visible
|
|
116
|
-
await expect(mcpItems.first()).toBeVisible({ timeout:
|
|
96
|
+
await expect(mcpItems.first()).toBeVisible({ timeout: 30_000 });
|
|
117
97
|
|
|
118
98
|
// Check we have multiple items
|
|
119
99
|
const count = await mcpItems.count();
|
|
@@ -121,9 +101,7 @@ Then('I should see MCP cards', async function (this: CustomWorld) {
|
|
|
121
101
|
});
|
|
122
102
|
|
|
123
103
|
Then('I should see the category filter', async function (this: CustomWorld) {
|
|
124
|
-
await this.page.waitForLoadState('networkidle', { timeout: 10_000 });
|
|
125
|
-
|
|
126
104
|
// CategoryMenu component has data-testid="category-menu" (shared across list pages)
|
|
127
105
|
const categoryFilter = this.page.locator('[data-testid="category-menu"]').first();
|
|
128
|
-
await expect(categoryFilter).toBeVisible({ timeout:
|
|
106
|
+
await expect(categoryFilter).toBeVisible({ timeout: 30_000 });
|
|
129
107
|
});
|
package/locales/zh-CN/auth.json
CHANGED
|
@@ -214,7 +214,7 @@
|
|
|
214
214
|
"stats.topicsRank.right": "消息数",
|
|
215
215
|
"stats.topicsRank.title": "话题内容量",
|
|
216
216
|
"stats.updatedAt": "更新至",
|
|
217
|
-
"stats.welcome": "{{
|
|
217
|
+
"stats.welcome": "{{username}},这是你与 {{appName}} 一起记录协作的第 <span>{{days}}</span> 天",
|
|
218
218
|
"stats.words": "累计字数",
|
|
219
219
|
"tab.apikey": "API Key",
|
|
220
220
|
"tab.profile": "账号",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobehub/lobehub",
|
|
3
|
-
"version": "2.0.0-next.
|
|
3
|
+
"version": "2.0.0-next.192",
|
|
4
4
|
"description": "LobeHub - an open-source,comprehensive AI Agent framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"framework",
|
|
@@ -154,7 +154,6 @@
|
|
|
154
154
|
"@codesandbox/sandpack-react": "^2.20.0",
|
|
155
155
|
"@dnd-kit/core": "^6.3.1",
|
|
156
156
|
"@dnd-kit/utilities": "^3.2.2",
|
|
157
|
-
"@electric-sql/pglite": "0.2.17",
|
|
158
157
|
"@emotion/react": "^11.14.0",
|
|
159
158
|
"@fal-ai/client": "^1.8.0",
|
|
160
159
|
"@formkit/auto-animate": "^0.9.0",
|
|
@@ -23,11 +23,11 @@
|
|
|
23
23
|
"ws": "^8.18.3"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
+
"@electric-sql/pglite": "^0.3.14",
|
|
26
27
|
"dotenv": "^17.2.3",
|
|
27
28
|
"fake-indexeddb": "^6.2.5"
|
|
28
29
|
},
|
|
29
30
|
"peerDependencies": {
|
|
30
|
-
"@electric-sql/pglite": "^0.2.17",
|
|
31
31
|
"dayjs": ">=1.11.19",
|
|
32
32
|
"drizzle-orm": ">=0.44.7",
|
|
33
33
|
"nanoid": ">=5.1.6",
|
|
@@ -1,18 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PGlite } from '@electric-sql/pglite';
|
|
2
2
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
3
3
|
|
|
4
|
-
import { DatabaseManager } from './db';
|
|
5
|
-
|
|
6
|
-
// Mock 所有外部依赖
|
|
7
4
|
vi.mock('@electric-sql/pglite', () => ({
|
|
8
|
-
|
|
9
|
-
IdbFs: vi.fn(),
|
|
10
|
-
PGlite: vi.fn(),
|
|
11
|
-
MemoryFS: vi.fn(),
|
|
5
|
+
PGlite: vi.fn(() => ({})),
|
|
12
6
|
}));
|
|
13
7
|
|
|
14
8
|
vi.mock('@electric-sql/pglite/vector', () => ({
|
|
15
|
-
default: vi.fn(),
|
|
16
9
|
vector: vi.fn(),
|
|
17
10
|
}));
|
|
18
11
|
|
|
@@ -24,154 +17,36 @@ vi.mock('drizzle-orm/pglite', () => ({
|
|
|
24
17
|
})),
|
|
25
18
|
}));
|
|
26
19
|
|
|
27
|
-
let manager: DatabaseManager;
|
|
28
|
-
let progressEvents: ClientDBLoadingProgress[] = [];
|
|
29
|
-
let stateChanges: DatabaseLoadingState[] = [];
|
|
30
|
-
|
|
31
|
-
let callbacks = {
|
|
32
|
-
onProgress: vi.fn((progress: ClientDBLoadingProgress) => {
|
|
33
|
-
progressEvents.push(progress);
|
|
34
|
-
}),
|
|
35
|
-
onStateChange: vi.fn((state: DatabaseLoadingState) => {
|
|
36
|
-
stateChanges.push(state);
|
|
37
|
-
}),
|
|
38
|
-
};
|
|
39
|
-
|
|
40
20
|
beforeEach(() => {
|
|
41
21
|
vi.clearAllMocks();
|
|
42
|
-
|
|
43
|
-
stateChanges = [];
|
|
44
|
-
|
|
45
|
-
callbacks = {
|
|
46
|
-
onProgress: vi.fn((progress: ClientDBLoadingProgress) => {
|
|
47
|
-
progressEvents.push(progress);
|
|
48
|
-
}),
|
|
49
|
-
onStateChange: vi.fn((state: DatabaseLoadingState) => {
|
|
50
|
-
stateChanges.push(state);
|
|
51
|
-
}),
|
|
52
|
-
};
|
|
53
|
-
// @ts-expect-error
|
|
54
|
-
DatabaseManager['instance'] = undefined;
|
|
55
|
-
manager = DatabaseManager.getInstance();
|
|
22
|
+
vi.resetModules();
|
|
56
23
|
});
|
|
57
24
|
|
|
58
25
|
describe('DatabaseManager', () => {
|
|
59
|
-
describe('
|
|
60
|
-
it(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
DatabaseLoadingState.Initializing,
|
|
68
|
-
DatabaseLoadingState.LoadingDependencies,
|
|
69
|
-
DatabaseLoadingState.LoadingWasm,
|
|
70
|
-
DatabaseLoadingState.Migrating,
|
|
71
|
-
DatabaseLoadingState.Finished,
|
|
72
|
-
DatabaseLoadingState.Ready,
|
|
73
|
-
]);
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
timeout: 15000,
|
|
77
|
-
},
|
|
78
|
-
);
|
|
79
|
-
|
|
80
|
-
it('should report dependencies loading progress', async () => {
|
|
81
|
-
await manager.initialize(callbacks);
|
|
82
|
-
|
|
83
|
-
// 验证依赖加载进度回调
|
|
84
|
-
const dependencyProgress = progressEvents.filter((e) => e.phase === 'dependencies');
|
|
85
|
-
expect(dependencyProgress.length).toBeGreaterThan(0);
|
|
86
|
-
expect(dependencyProgress[dependencyProgress.length - 1]).toEqual(
|
|
87
|
-
expect.objectContaining({
|
|
88
|
-
phase: 'dependencies',
|
|
89
|
-
progress: 100,
|
|
90
|
-
costTime: expect.any(Number),
|
|
91
|
-
}),
|
|
92
|
-
);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('should report WASM loading progress', async () => {
|
|
96
|
-
await manager.initialize(callbacks);
|
|
97
|
-
|
|
98
|
-
// 验证 WASM 加载进度回调
|
|
99
|
-
const wasmProgress = progressEvents.filter((e) => e.phase === 'wasm');
|
|
100
|
-
// expect(wasmProgress.length).toBeGreaterThan(0);
|
|
101
|
-
expect(wasmProgress[wasmProgress.length - 1]).toEqual(
|
|
102
|
-
expect.objectContaining({
|
|
103
|
-
phase: 'wasm',
|
|
104
|
-
progress: 100,
|
|
105
|
-
costTime: expect.any(Number),
|
|
106
|
-
}),
|
|
107
|
-
);
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it('should handle initialization errors', async () => {
|
|
111
|
-
// 模拟加载失败
|
|
112
|
-
vi.spyOn(global, 'fetch').mockRejectedValueOnce(new Error('Network error'));
|
|
113
|
-
|
|
114
|
-
await expect(manager.initialize(callbacks)).rejects.toThrow();
|
|
115
|
-
expect(stateChanges).toContain(DatabaseLoadingState.Error);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it('should only initialize once when called multiple times', async () => {
|
|
119
|
-
const firstInit = manager.initialize(callbacks);
|
|
120
|
-
const secondInit = manager.initialize(callbacks);
|
|
121
|
-
|
|
122
|
-
await Promise.all([firstInit, secondInit]);
|
|
123
|
-
|
|
124
|
-
// 验证回调只被调用一次
|
|
125
|
-
const readyStateCount = stateChanges.filter(
|
|
126
|
-
(state) => state === DatabaseLoadingState.Ready,
|
|
127
|
-
).length;
|
|
128
|
-
expect(readyStateCount).toBe(1);
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
describe('Progress Calculation', () => {
|
|
133
|
-
it('should report progress between 0 and 100', async () => {
|
|
134
|
-
await manager.initialize(callbacks);
|
|
135
|
-
|
|
136
|
-
// 验证所有进度值都在有效范围内
|
|
137
|
-
progressEvents.forEach((event) => {
|
|
138
|
-
expect(event.progress).toBeGreaterThanOrEqual(0);
|
|
139
|
-
expect(event.progress).toBeLessThanOrEqual(100);
|
|
26
|
+
describe('initializeDB', () => {
|
|
27
|
+
it('should initialize database with PGlite', async () => {
|
|
28
|
+
const { initializeDB } = await import('./db');
|
|
29
|
+
await initializeDB();
|
|
30
|
+
|
|
31
|
+
expect(PGlite).toHaveBeenCalledWith('idb://lobechat', {
|
|
32
|
+
extensions: { vector: expect.any(Function) },
|
|
33
|
+
relaxedDurability: true,
|
|
140
34
|
});
|
|
141
35
|
});
|
|
142
36
|
|
|
143
|
-
it('should
|
|
144
|
-
await
|
|
145
|
-
|
|
146
|
-
// 验证最终进度回调包含耗时信息
|
|
147
|
-
const finalProgress = progressEvents[progressEvents.length - 1];
|
|
148
|
-
expect(finalProgress.costTime).toBeGreaterThan(0);
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
describe('Error Handling', () => {
|
|
153
|
-
it('should handle missing callbacks gracefully', async () => {
|
|
154
|
-
// 测试没有提供回调的情况
|
|
155
|
-
await expect(manager.initialize()).resolves.toBeDefined();
|
|
156
|
-
});
|
|
37
|
+
it('should only initialize once when called multiple times', async () => {
|
|
38
|
+
const { initializeDB } = await import('./db');
|
|
39
|
+
await Promise.all([initializeDB(), initializeDB()]);
|
|
157
40
|
|
|
158
|
-
|
|
159
|
-
// 只提供部分回调
|
|
160
|
-
await expect(manager.initialize({ onProgress: callbacks.onProgress })).resolves.toBeDefined();
|
|
161
|
-
await expect(
|
|
162
|
-
manager.initialize({ onStateChange: callbacks.onStateChange }),
|
|
163
|
-
).resolves.toBeDefined();
|
|
41
|
+
expect(PGlite).toHaveBeenCalledTimes(1);
|
|
164
42
|
});
|
|
165
43
|
});
|
|
166
44
|
|
|
167
|
-
describe('
|
|
168
|
-
it('should throw error when accessing database before initialization', () => {
|
|
169
|
-
expect(() => manager.db).toThrow('Database not initialized');
|
|
170
|
-
});
|
|
171
|
-
|
|
45
|
+
describe('clientDB proxy', () => {
|
|
172
46
|
it('should provide access to database after initialization', async () => {
|
|
173
|
-
await
|
|
174
|
-
|
|
47
|
+
const { clientDB, initializeDB } = await import('./db');
|
|
48
|
+
await initializeDB();
|
|
49
|
+
expect(clientDB).toBeDefined();
|
|
175
50
|
});
|
|
176
51
|
});
|
|
177
52
|
});
|
|
@@ -1,53 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
DatabaseLoadingState,
|
|
4
|
-
type MigrationSQL,
|
|
5
|
-
type MigrationTableItem,
|
|
6
|
-
} from '@lobechat/types';
|
|
1
|
+
import { PGlite } from '@electric-sql/pglite';
|
|
2
|
+
import { vector } from '@electric-sql/pglite/vector';
|
|
7
3
|
import { sql } from 'drizzle-orm';
|
|
8
4
|
import { PgliteDatabase, drizzle } from 'drizzle-orm/pglite';
|
|
9
5
|
import { Md5 } from 'ts-md5';
|
|
10
6
|
|
|
11
|
-
import { sleep } from '@/utils/sleep';
|
|
12
|
-
|
|
13
7
|
import migrations from '../core/migrations.json';
|
|
14
8
|
import { DrizzleMigrationModel } from '../models/drizzleMigration';
|
|
15
9
|
import * as schema from '../schemas';
|
|
16
10
|
|
|
17
11
|
const pgliteSchemaHashCache = 'LOBE_CHAT_PGLITE_SCHEMA_HASH';
|
|
18
|
-
|
|
19
12
|
const DB_NAME = 'lobechat';
|
|
20
|
-
type DrizzleInstance = PgliteDatabase<typeof schema>;
|
|
21
13
|
|
|
22
|
-
|
|
23
|
-
error: Error;
|
|
24
|
-
migrationTableItems: MigrationTableItem[];
|
|
25
|
-
migrationsSQL: MigrationSQL[];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface DatabaseLoadingCallbacks {
|
|
29
|
-
onError?: (error: onErrorState) => void;
|
|
30
|
-
onProgress?: (progress: ClientDBLoadingProgress) => void;
|
|
31
|
-
onStateChange?: (state: DatabaseLoadingState) => void;
|
|
32
|
-
}
|
|
14
|
+
type DrizzleInstance = PgliteDatabase<typeof schema>;
|
|
33
15
|
|
|
34
|
-
|
|
16
|
+
class DatabaseManager {
|
|
35
17
|
private static instance: DatabaseManager;
|
|
36
18
|
private dbInstance: DrizzleInstance | null = null;
|
|
37
19
|
private initPromise: Promise<DrizzleInstance> | null = null;
|
|
38
|
-
private callbacks?: DatabaseLoadingCallbacks;
|
|
39
20
|
private isLocalDBSchemaSynced = false;
|
|
40
21
|
|
|
41
|
-
// CDN configuration
|
|
42
|
-
private static WASM_CDN_URL =
|
|
43
|
-
'https://registry.npmmirror.com/@electric-sql/pglite/0.2.17/files/dist/postgres.wasm';
|
|
44
|
-
|
|
45
|
-
private static FSBUNDLER_CDN_URL =
|
|
46
|
-
'https://registry.npmmirror.com/@electric-sql/pglite/0.2.17/files/dist/postgres.data';
|
|
47
|
-
|
|
48
|
-
private static VECTOR_CDN_URL =
|
|
49
|
-
'https://registry.npmmirror.com/@electric-sql/pglite/0.2.17/files/dist/vector.tar.gz';
|
|
50
|
-
|
|
51
22
|
private constructor() {}
|
|
52
23
|
|
|
53
24
|
static getInstance() {
|
|
@@ -57,108 +28,8 @@ export class DatabaseManager {
|
|
|
57
28
|
return DatabaseManager.instance;
|
|
58
29
|
}
|
|
59
30
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const start = Date.now();
|
|
63
|
-
this.callbacks?.onStateChange?.(DatabaseLoadingState.LoadingWasm);
|
|
64
|
-
|
|
65
|
-
const response = await fetch(DatabaseManager.WASM_CDN_URL);
|
|
66
|
-
|
|
67
|
-
const contentLength = Number(response.headers.get('Content-Length')) || 0;
|
|
68
|
-
const reader = response.body?.getReader();
|
|
69
|
-
|
|
70
|
-
if (!reader) throw new Error('Failed to start WASM download');
|
|
71
|
-
|
|
72
|
-
let receivedLength = 0;
|
|
73
|
-
const chunks: Uint8Array[] = [];
|
|
74
|
-
|
|
75
|
-
// Read data stream
|
|
76
|
-
// eslint-disable-next-line no-constant-condition
|
|
77
|
-
while (true) {
|
|
78
|
-
const { done, value } = await reader.read();
|
|
79
|
-
|
|
80
|
-
if (done) break;
|
|
81
|
-
|
|
82
|
-
chunks.push(value);
|
|
83
|
-
receivedLength += value.length;
|
|
84
|
-
|
|
85
|
-
// Calculate and report progress
|
|
86
|
-
const progress = Math.min(Math.round((receivedLength / contentLength) * 100), 100);
|
|
87
|
-
this.callbacks?.onProgress?.({
|
|
88
|
-
phase: 'wasm',
|
|
89
|
-
progress,
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// Merge data chunks
|
|
94
|
-
const wasmBytes = new Uint8Array(receivedLength);
|
|
95
|
-
let position = 0;
|
|
96
|
-
for (const chunk of chunks) {
|
|
97
|
-
wasmBytes.set(chunk, position);
|
|
98
|
-
position += chunk.length;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
this.callbacks?.onProgress?.({
|
|
102
|
-
costTime: Date.now() - start,
|
|
103
|
-
phase: 'wasm',
|
|
104
|
-
progress: 100,
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
// Compile WASM module
|
|
108
|
-
return WebAssembly.compile(wasmBytes);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
private fetchFsBundle = async () => {
|
|
112
|
-
const res = await fetch(DatabaseManager.FSBUNDLER_CDN_URL);
|
|
113
|
-
|
|
114
|
-
return await res.blob();
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
// Asynchronously load PGlite related dependencies
|
|
118
|
-
private async loadDependencies() {
|
|
119
|
-
const start = Date.now();
|
|
120
|
-
this.callbacks?.onStateChange?.(DatabaseLoadingState.LoadingDependencies);
|
|
121
|
-
|
|
122
|
-
const imports = [
|
|
123
|
-
import('@electric-sql/pglite').then((m) => ({
|
|
124
|
-
IdbFs: m.IdbFs,
|
|
125
|
-
MemoryFS: m.MemoryFS,
|
|
126
|
-
PGlite: m.PGlite,
|
|
127
|
-
})),
|
|
128
|
-
import('@electric-sql/pglite/vector'),
|
|
129
|
-
this.fetchFsBundle(),
|
|
130
|
-
];
|
|
131
|
-
|
|
132
|
-
let loaded = 0;
|
|
133
|
-
const results = await Promise.all(
|
|
134
|
-
imports.map(async (importPromise) => {
|
|
135
|
-
const result = await importPromise;
|
|
136
|
-
loaded += 1;
|
|
137
|
-
|
|
138
|
-
// Calculate loading progress
|
|
139
|
-
this.callbacks?.onProgress?.({
|
|
140
|
-
phase: 'dependencies',
|
|
141
|
-
progress: Math.min(Math.round((loaded / imports.length) * 100), 100),
|
|
142
|
-
});
|
|
143
|
-
return result;
|
|
144
|
-
}),
|
|
145
|
-
);
|
|
146
|
-
|
|
147
|
-
this.callbacks?.onProgress?.({
|
|
148
|
-
costTime: Date.now() - start,
|
|
149
|
-
phase: 'dependencies',
|
|
150
|
-
progress: 100,
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
// @ts-ignore
|
|
154
|
-
const [{ PGlite, IdbFs, MemoryFS }, { vector }, fsBundle] = results;
|
|
155
|
-
|
|
156
|
-
return { IdbFs, MemoryFS, PGlite, fsBundle, vector };
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// Database migration method
|
|
160
|
-
private async migrate(skipMultiRun = false): Promise<DrizzleInstance> {
|
|
161
|
-
if (this.isLocalDBSchemaSynced && skipMultiRun) return this.db;
|
|
31
|
+
private async migrate(): Promise<DrizzleInstance> {
|
|
32
|
+
if (this.isLocalDBSchemaSynced) return this.db;
|
|
162
33
|
|
|
163
34
|
let hash: string | undefined;
|
|
164
35
|
if (typeof localStorage !== 'undefined') {
|
|
@@ -179,17 +50,13 @@ export class DatabaseManager {
|
|
|
179
50
|
}
|
|
180
51
|
} catch (error) {
|
|
181
52
|
console.warn('Error checking table existence, proceeding with migration', error);
|
|
182
|
-
// If query fails, continue migration to ensure safety
|
|
183
53
|
}
|
|
184
54
|
}
|
|
185
55
|
}
|
|
186
56
|
|
|
187
57
|
const start = Date.now();
|
|
188
58
|
try {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
// refs: https://github.com/drizzle-team/drizzle-orm/discussions/2532
|
|
192
|
-
// @ts-expect-error
|
|
59
|
+
// @ts-expect-error - migrate internal API
|
|
193
60
|
await this.db.dialect.migrate(migrations, this.db.session, {});
|
|
194
61
|
|
|
195
62
|
if (typeof localStorage !== 'undefined' && hash) {
|
|
@@ -197,7 +64,6 @@ export class DatabaseManager {
|
|
|
197
64
|
}
|
|
198
65
|
|
|
199
66
|
this.isLocalDBSchemaSynced = true;
|
|
200
|
-
|
|
201
67
|
console.info(`🗂 Migration success, take ${Date.now() - start}ms`);
|
|
202
68
|
} catch (cause) {
|
|
203
69
|
console.error('❌ Local database schema migration failed', cause);
|
|
@@ -207,95 +73,32 @@ export class DatabaseManager {
|
|
|
207
73
|
return this.db;
|
|
208
74
|
}
|
|
209
75
|
|
|
210
|
-
|
|
211
|
-
async initialize(callbacks?: DatabaseLoadingCallbacks): Promise<DrizzleInstance> {
|
|
76
|
+
async initialize(): Promise<DrizzleInstance> {
|
|
212
77
|
if (this.initPromise) return this.initPromise;
|
|
213
78
|
|
|
214
|
-
this.callbacks = callbacks;
|
|
215
|
-
|
|
216
79
|
this.initPromise = (async () => {
|
|
217
|
-
|
|
218
|
-
if (this.dbInstance) return this.dbInstance;
|
|
219
|
-
|
|
220
|
-
const time = Date.now();
|
|
221
|
-
// Initialize database
|
|
222
|
-
this.callbacks?.onStateChange?.(DatabaseLoadingState.Initializing);
|
|
223
|
-
|
|
224
|
-
// Load dependencies
|
|
225
|
-
const { fsBundle, PGlite, MemoryFS, IdbFs, vector } = await this.loadDependencies();
|
|
226
|
-
|
|
227
|
-
// Load and compile WASM module
|
|
228
|
-
const wasmModule = await this.loadWasmModule();
|
|
229
|
-
|
|
230
|
-
const { initPgliteWorker } = await import('./pglite');
|
|
231
|
-
|
|
232
|
-
let db: typeof PGlite;
|
|
233
|
-
|
|
234
|
-
// make db as web worker if worker is available
|
|
235
|
-
// https://github.com/lobehub/lobe-chat/issues/5785
|
|
236
|
-
if (typeof Worker !== 'undefined' && typeof navigator.locks !== 'undefined') {
|
|
237
|
-
db = await initPgliteWorker({
|
|
238
|
-
dbName: DB_NAME,
|
|
239
|
-
fsBundle: fsBundle as Blob,
|
|
240
|
-
vectorBundlePath: DatabaseManager.VECTOR_CDN_URL,
|
|
241
|
-
wasmModule,
|
|
242
|
-
});
|
|
243
|
-
} else {
|
|
244
|
-
// in edge runtime or test runtime, we don't have worker
|
|
245
|
-
db = new PGlite({
|
|
246
|
-
extensions: { vector },
|
|
247
|
-
fs: typeof window === 'undefined' ? new MemoryFS(DB_NAME) : new IdbFs(DB_NAME),
|
|
248
|
-
relaxedDurability: true,
|
|
249
|
-
wasmModule,
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
this.dbInstance = drizzle({ client: db, schema });
|
|
80
|
+
if (this.dbInstance) return this.dbInstance;
|
|
254
81
|
|
|
255
|
-
|
|
82
|
+
const time = Date.now();
|
|
256
83
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
84
|
+
// 直接使用 pglite,自动处理 wasm 加载
|
|
85
|
+
const pglite = new PGlite(`idb://${DB_NAME}`, {
|
|
86
|
+
extensions: { vector },
|
|
87
|
+
relaxedDurability: true,
|
|
88
|
+
});
|
|
261
89
|
|
|
262
|
-
|
|
90
|
+
this.dbInstance = drizzle({ client: pglite, schema });
|
|
263
91
|
|
|
264
|
-
|
|
265
|
-
} catch (e) {
|
|
266
|
-
this.initPromise = null;
|
|
267
|
-
this.callbacks?.onStateChange?.(DatabaseLoadingState.Error);
|
|
268
|
-
const error = e as Error;
|
|
92
|
+
await this.migrate();
|
|
269
93
|
|
|
270
|
-
|
|
271
|
-
let migrationsTableData: MigrationTableItem[] = [];
|
|
272
|
-
try {
|
|
273
|
-
// Attempt to query migration table
|
|
274
|
-
const drizzleMigration = new DrizzleMigrationModel(this.db as any);
|
|
275
|
-
migrationsTableData = await drizzleMigration.getMigrationList();
|
|
276
|
-
} catch (queryError) {
|
|
277
|
-
console.error('Failed to query migrations table:', queryError);
|
|
278
|
-
}
|
|
94
|
+
console.log(`✅ Database initialized in ${Date.now() - time}ms`);
|
|
279
95
|
|
|
280
|
-
|
|
281
|
-
error: {
|
|
282
|
-
message: error.message,
|
|
283
|
-
name: error.name,
|
|
284
|
-
stack: error.stack,
|
|
285
|
-
},
|
|
286
|
-
migrationTableItems: migrationsTableData,
|
|
287
|
-
migrationsSQL: migrations,
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
console.error(error);
|
|
291
|
-
throw error;
|
|
292
|
-
}
|
|
96
|
+
return this.dbInstance;
|
|
293
97
|
})();
|
|
294
98
|
|
|
295
99
|
return this.initPromise;
|
|
296
100
|
}
|
|
297
101
|
|
|
298
|
-
// Get database instance
|
|
299
102
|
get db(): DrizzleInstance {
|
|
300
103
|
if (!this.dbInstance) {
|
|
301
104
|
throw new Error('Database not initialized. Please call initialize() first.');
|
|
@@ -303,7 +106,6 @@ export class DatabaseManager {
|
|
|
303
106
|
return this.dbInstance;
|
|
304
107
|
}
|
|
305
108
|
|
|
306
|
-
// Create proxy object
|
|
307
109
|
createProxy(): DrizzleInstance {
|
|
308
110
|
return new Proxy({} as DrizzleInstance, {
|
|
309
111
|
get: (target, prop) => {
|
|
@@ -313,7 +115,7 @@ export class DatabaseManager {
|
|
|
313
115
|
}
|
|
314
116
|
|
|
315
117
|
async resetDatabase(): Promise<void> {
|
|
316
|
-
// 1. Close existing PGlite connection
|
|
118
|
+
// 1. Close existing PGlite connection
|
|
317
119
|
if (this.dbInstance) {
|
|
318
120
|
try {
|
|
319
121
|
// @ts-ignore
|
|
@@ -321,31 +123,28 @@ export class DatabaseManager {
|
|
|
321
123
|
console.log('PGlite instance closed successfully.');
|
|
322
124
|
} catch (e) {
|
|
323
125
|
console.error('Error closing PGlite instance:', e);
|
|
324
|
-
// Even if closing fails, continue with deletion attempt; IndexedDB onblocked or onerror will handle subsequent issues
|
|
325
126
|
}
|
|
326
127
|
}
|
|
327
128
|
|
|
328
129
|
// 2. Reset database instance and initialization state
|
|
329
130
|
this.dbInstance = null;
|
|
330
131
|
this.initPromise = null;
|
|
331
|
-
this.isLocalDBSchemaSynced = false;
|
|
132
|
+
this.isLocalDBSchemaSynced = false;
|
|
332
133
|
|
|
333
134
|
// 3. Delete IndexedDB database
|
|
334
135
|
return new Promise<void>((resolve, reject) => {
|
|
335
|
-
// Check if IndexedDB is available
|
|
336
136
|
if (typeof indexedDB === 'undefined') {
|
|
337
137
|
console.warn('IndexedDB is not available, cannot delete database');
|
|
338
|
-
resolve();
|
|
138
|
+
resolve();
|
|
339
139
|
return;
|
|
340
140
|
}
|
|
341
141
|
|
|
342
|
-
const dbName = `/pglite/${DB_NAME}`;
|
|
142
|
+
const dbName = `/pglite/${DB_NAME}`;
|
|
343
143
|
const request = indexedDB.deleteDatabase(dbName);
|
|
344
144
|
|
|
345
145
|
request.onsuccess = () => {
|
|
346
146
|
console.log(`✅ Database '${dbName}' reset successfully`);
|
|
347
147
|
|
|
348
|
-
// Clear locally stored schema hash
|
|
349
148
|
if (typeof localStorage !== 'undefined') {
|
|
350
149
|
localStorage.removeItem(pgliteSchemaHashCache);
|
|
351
150
|
}
|
|
@@ -365,14 +164,10 @@ export class DatabaseManager {
|
|
|
365
164
|
};
|
|
366
165
|
|
|
367
166
|
request.onblocked = (event) => {
|
|
368
|
-
|
|
369
|
-
console.warn(
|
|
370
|
-
`Deletion of database '${dbName}' is blocked. This usually means other connections (e.g., in other tabs) are still open. Event:`,
|
|
371
|
-
event,
|
|
372
|
-
);
|
|
167
|
+
console.warn(`Deletion of database '${dbName}' is blocked.`, event);
|
|
373
168
|
reject(
|
|
374
169
|
new Error(
|
|
375
|
-
`Failed to reset database '${dbName}' because it is blocked by other open connections
|
|
170
|
+
`Failed to reset database '${dbName}' because it is blocked by other open connections.`,
|
|
376
171
|
),
|
|
377
172
|
);
|
|
378
173
|
};
|
|
@@ -383,12 +178,9 @@ export class DatabaseManager {
|
|
|
383
178
|
// Export singleton
|
|
384
179
|
const dbManager = DatabaseManager.getInstance();
|
|
385
180
|
|
|
386
|
-
// Keep original clientDB export unchanged
|
|
387
181
|
export const clientDB = dbManager.createProxy();
|
|
388
182
|
|
|
389
|
-
|
|
390
|
-
export const initializeDB = (callbacks?: DatabaseLoadingCallbacks) =>
|
|
391
|
-
dbManager.initialize(callbacks);
|
|
183
|
+
export const initializeDB = () => dbManager.initialize();
|
|
392
184
|
|
|
393
185
|
export const resetClientDatabase = async () => {
|
|
394
186
|
await dbManager.resetDatabase();
|
|
@@ -1,14 +1,30 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PGlite } from '@electric-sql/pglite';
|
|
2
|
+
import { vector } from '@electric-sql/pglite/vector';
|
|
3
|
+
import { drizzle } from 'drizzle-orm/pglite';
|
|
4
|
+
|
|
5
|
+
import migrations from '../../core/migrations.json';
|
|
6
|
+
import * as schema from '../../schemas';
|
|
2
7
|
import { LobeChatDatabase } from '../../type';
|
|
3
8
|
|
|
4
9
|
const isServerDBMode = process.env.TEST_SERVER_DB === '1';
|
|
5
10
|
|
|
11
|
+
let testClientDB: ReturnType<typeof drizzle<typeof schema>> | null = null;
|
|
12
|
+
|
|
6
13
|
export const getTestDB = async () => {
|
|
7
14
|
if (isServerDBMode) {
|
|
8
15
|
const { getTestDBInstance } = await import('../../core/dbForTest');
|
|
9
16
|
return await getTestDBInstance();
|
|
10
17
|
}
|
|
11
18
|
|
|
12
|
-
|
|
13
|
-
|
|
19
|
+
if (testClientDB) return testClientDB as unknown as LobeChatDatabase;
|
|
20
|
+
|
|
21
|
+
// 直接使用 pglite 内置资源,不需要从 CDN 下载
|
|
22
|
+
const pglite = new PGlite({ extensions: { vector } });
|
|
23
|
+
|
|
24
|
+
testClientDB = drizzle({ client: pglite, schema });
|
|
25
|
+
|
|
26
|
+
// @ts-expect-error - migrate internal API
|
|
27
|
+
await testClientDB.dialect.migrate(migrations, testClientDB.session, {});
|
|
28
|
+
|
|
29
|
+
return testClientDB as unknown as LobeChatDatabase;
|
|
14
30
|
};
|
|
@@ -22,13 +22,14 @@ import ModelConfigModal from './ModelConfigModal';
|
|
|
22
22
|
import { ProviderSettingsContext } from './ProviderSettingsContext';
|
|
23
23
|
|
|
24
24
|
const styles = createStaticStyles(({ css, cx }) => {
|
|
25
|
-
const config = css`
|
|
26
|
-
opacity: 0;
|
|
27
|
-
transition: all 100ms ease-in-out;
|
|
28
|
-
`;
|
|
29
|
-
|
|
30
25
|
return {
|
|
31
|
-
config
|
|
26
|
+
config: cx(
|
|
27
|
+
'model-item-config',
|
|
28
|
+
css`
|
|
29
|
+
opacity: 0;
|
|
30
|
+
transition: all 100ms ease-in-out;
|
|
31
|
+
`,
|
|
32
|
+
),
|
|
32
33
|
container: css`
|
|
33
34
|
position: relative;
|
|
34
35
|
border-radius: ${cssVar.borderRadiusLG}px;
|
|
@@ -37,7 +38,7 @@ const styles = createStaticStyles(({ css, cx }) => {
|
|
|
37
38
|
&:hover {
|
|
38
39
|
background-color: ${cssVar.colorFillTertiary};
|
|
39
40
|
|
|
40
|
-
|
|
41
|
+
.model-item-config {
|
|
41
42
|
opacity: 1;
|
|
42
43
|
}
|
|
43
44
|
}
|
|
@@ -311,7 +311,7 @@ export function defineConfig(config: CustomNextConfig) {
|
|
|
311
311
|
],
|
|
312
312
|
|
|
313
313
|
// when external packages in dev mode with turbopack, this config will lead to bundle error
|
|
314
|
-
serverExternalPackages:
|
|
314
|
+
serverExternalPackages: ['pdfkit'],
|
|
315
315
|
|
|
316
316
|
transpilePackages: ['pdfjs-dist', 'mermaid', 'better-auth-harmony'],
|
|
317
317
|
turbopack: {
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { PGliteWorker } from '@electric-sql/pglite/worker';
|
|
2
|
-
|
|
3
|
-
import { InitMeta } from './type';
|
|
4
|
-
|
|
5
|
-
export const initPgliteWorker = async (meta: InitMeta) => {
|
|
6
|
-
const worker = await PGliteWorker.create(
|
|
7
|
-
new Worker(new URL('pglite.worker.ts', import.meta.url)),
|
|
8
|
-
{ meta },
|
|
9
|
-
);
|
|
10
|
-
|
|
11
|
-
// Listen for worker status changes
|
|
12
|
-
worker.onLeaderChange(() => {
|
|
13
|
-
console.log('Worker leader changed, isLeader:', worker?.isLeader);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
return worker as PGliteWorker;
|
|
17
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { worker } from '@electric-sql/pglite/worker';
|
|
2
|
-
|
|
3
|
-
import { InitMeta } from './type';
|
|
4
|
-
|
|
5
|
-
worker({
|
|
6
|
-
async init(options) {
|
|
7
|
-
const { wasmModule, fsBundle, vectorBundlePath, dbName } = options.meta as InitMeta;
|
|
8
|
-
const { PGlite } = await import('@electric-sql/pglite');
|
|
9
|
-
|
|
10
|
-
return new PGlite({
|
|
11
|
-
dataDir: `idb://${dbName}`,
|
|
12
|
-
extensions: {
|
|
13
|
-
vector: {
|
|
14
|
-
name: 'pgvector',
|
|
15
|
-
setup: async (pglite, options) => {
|
|
16
|
-
return { bundlePath: new URL(vectorBundlePath), options };
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
fsBundle,
|
|
21
|
-
relaxedDurability: true,
|
|
22
|
-
wasmModule,
|
|
23
|
-
});
|
|
24
|
-
},
|
|
25
|
-
});
|