@huyooo/ai-chat-storage 0.1.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.
package/dist/index.js ADDED
@@ -0,0 +1,66 @@
1
+ import {
2
+ SqliteAdapter,
3
+ backups,
4
+ embeddings,
5
+ messages,
6
+ operations,
7
+ sessions,
8
+ trash
9
+ } from "./chunk-GCKDCC3O.js";
10
+ import {
11
+ PostgresAdapter
12
+ } from "./chunk-BRWTH4LQ.js";
13
+
14
+ // src/index.ts
15
+ import { mkdirSync, existsSync } from "fs";
16
+ import { dirname } from "path";
17
+ async function createStorage(config) {
18
+ switch (config.type) {
19
+ case "sqlite": {
20
+ if (!config.sqlitePath) {
21
+ throw new Error("SQLite \u9700\u8981\u63D0\u4F9B sqlitePath \u914D\u7F6E");
22
+ }
23
+ const dir = dirname(config.sqlitePath);
24
+ if (!existsSync(dir)) {
25
+ mkdirSync(dir, { recursive: true });
26
+ }
27
+ const { SqliteAdapter: SqliteAdapter2 } = await import("./sqlite-AJRNISP2.js");
28
+ return new SqliteAdapter2(config.sqlitePath, config);
29
+ }
30
+ case "postgres": {
31
+ if (!config.postgresUrl) {
32
+ throw new Error("PostgreSQL \u9700\u8981\u63D0\u4F9B postgresUrl \u914D\u7F6E");
33
+ }
34
+ const { PostgresAdapter: PostgresAdapter2 } = await import("./postgres-PBPM2KDK.js");
35
+ return new PostgresAdapter2(config.postgresUrl, config);
36
+ }
37
+ default:
38
+ throw new Error(`\u4E0D\u652F\u6301\u7684\u5B58\u50A8\u7C7B\u578B: ${config.type}`);
39
+ }
40
+ }
41
+ function getDefaultStoragePath() {
42
+ const home = process.env.HOME || process.env.USERPROFILE || ".";
43
+ return `${home}/.ai-chat/db.sqlite`;
44
+ }
45
+ function getDefaultBackupDir() {
46
+ const home = process.env.HOME || process.env.USERPROFILE || ".";
47
+ return `${home}/.ai-chat/backups`;
48
+ }
49
+ function getDefaultTrashDir() {
50
+ const home = process.env.HOME || process.env.USERPROFILE || ".";
51
+ return `${home}/.ai-chat/trash`;
52
+ }
53
+ export {
54
+ PostgresAdapter,
55
+ SqliteAdapter,
56
+ backups,
57
+ createStorage,
58
+ embeddings,
59
+ getDefaultBackupDir,
60
+ getDefaultStoragePath,
61
+ getDefaultTrashDir,
62
+ messages,
63
+ operations,
64
+ sessions,
65
+ trash
66
+ };
@@ -0,0 +1,6 @@
1
+ import {
2
+ PostgresAdapter
3
+ } from "./chunk-BRWTH4LQ.js";
4
+ export {
5
+ PostgresAdapter
6
+ };
@@ -0,0 +1,6 @@
1
+ import {
2
+ SqliteAdapter
3
+ } from "./chunk-GCKDCC3O.js";
4
+ export {
5
+ SqliteAdapter
6
+ };
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@huyooo/ai-chat-storage",
3
+ "version": "0.1.0",
4
+ "description": "AI Chat 统一存储层 - SQLite",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./dist/index.js",
12
+ "types": "./dist/index.d.ts"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "scripts": {
19
+ "build": "tsup",
20
+ "dev": "tsup --watch",
21
+ "typecheck": "tsc --noEmit"
22
+ },
23
+ "dependencies": {
24
+ "better-sqlite3": "^11.0.0",
25
+ "drizzle-orm": "^0.38.0",
26
+ "postgres": "^3.4.7"
27
+ },
28
+ "devDependencies": {
29
+ "@types/better-sqlite3": "^7.6.11",
30
+ "tsup": "^8.3.0",
31
+ "typescript": "^5.6.3"
32
+ },
33
+ "publishConfig": {
34
+ "access": "public"
35
+ }
36
+ }