forked from lobehub/lobe-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/lobehub/lobe-chat
- Loading branch information
Showing
8 changed files
with
115 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { PGliteWorker } from '@electric-sql/pglite/worker'; | ||
|
||
import { InitMeta } from './type'; | ||
|
||
export const initPgliteWorker = async (meta: InitMeta) => { | ||
const worker = await PGliteWorker.create( | ||
new Worker(new URL('pglite.worker.ts', import.meta.url)), | ||
{ meta }, | ||
); | ||
|
||
// 监听 worker 状态变化 | ||
worker.onLeaderChange(() => { | ||
console.log('Worker leader changed, isLeader:', worker?.isLeader); | ||
}); | ||
|
||
return worker as PGliteWorker; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { worker } from '@electric-sql/pglite/worker'; | ||
|
||
import { InitMeta } from './type'; | ||
|
||
worker({ | ||
async init(options) { | ||
const { wasmModule, fsBundle, vectorBundlePath, dbName } = options.meta as InitMeta; | ||
const { PGlite } = await import('@electric-sql/pglite'); | ||
|
||
return new PGlite({ | ||
dataDir: `idb://${dbName}`, | ||
extensions: { | ||
vector: { | ||
name: 'pgvector', | ||
setup: async (pglite, options) => { | ||
return { bundlePath: new URL(vectorBundlePath), options }; | ||
}, | ||
}, | ||
}, | ||
fsBundle, | ||
relaxedDurability: true, | ||
wasmModule, | ||
}); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export interface InitMeta { | ||
dbName: string; | ||
fsBundle: Blob; | ||
vectorBundlePath: string; | ||
wasmModule: WebAssembly.Module; | ||
} |