@allbluecn/database 0.6.0 → 0.9.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 (103) hide show
  1. package/LICENSE +661 -0
  2. package/dist/get-prisma.d.ts +1 -0
  3. package/dist/get-prisma.js +7 -0
  4. package/generated/browser.ts +85 -0
  5. package/generated/client.ts +85 -0
  6. package/generated/commonInputTypes.ts +106 -46
  7. package/generated/internal/class.ts +174 -4
  8. package/generated/internal/prismaNamespace.ts +1698 -151
  9. package/generated/internal/prismaNamespaceBrowser.ts +279 -7
  10. package/generated/models/AiProviderConfig.ts +100 -1
  11. package/generated/models/AiStreamChunk.ts +1159 -0
  12. package/generated/models/AiUsageLog.ts +91 -31
  13. package/generated/models/Blob.ts +1428 -0
  14. package/generated/models/BusinessAgentBinding.ts +1553 -0
  15. package/generated/models/ChatInterrupt.ts +42 -1
  16. package/generated/models/ChatMessage.ts +58 -29
  17. package/generated/models/ChatPersistenceMeta.ts +1121 -0
  18. package/generated/models/ChatRun.ts +166 -1
  19. package/generated/models/ChatThread.ts +294 -1
  20. package/generated/models/CodeSnippet.ts +1555 -0
  21. package/generated/models/DesktopSetting.ts +1059 -0
  22. package/generated/models/EmailLog.ts +1345 -0
  23. package/generated/models/EmailPreference.ts +1257 -0
  24. package/generated/models/EmailSubscriber.ts +1233 -0
  25. package/generated/models/EmailVerificationToken.ts +1380 -0
  26. package/generated/models/GenerationRun.ts +193 -1
  27. package/generated/models/HarnessPlugin.ts +1677 -0
  28. package/generated/models/HarnessWorkspace.ts +1650 -0
  29. package/generated/models/InvitationCode.ts +65 -9
  30. package/generated/models/NotificationPreference.ts +27 -1
  31. package/generated/models/OAuthProviderConfig.ts +1227 -0
  32. package/generated/models/Plan.ts +115 -1
  33. package/generated/models/SandboxInstance.ts +1277 -0
  34. package/generated/models/SystemPromptTemplate.ts +1583 -0
  35. package/generated/models/SystemPromptVersion.ts +1459 -0
  36. package/generated/models/User.ts +5759 -823
  37. package/generated/models/UserAgent.ts +250 -1
  38. package/generated/models/Workspace.ts +3 -1
  39. package/generated/models/WorkspaceFile.ts +1535 -0
  40. package/generated/models.ts +17 -0
  41. package/generated-sqlite/browser.ts +90 -0
  42. package/generated-sqlite/client.ts +90 -0
  43. package/generated-sqlite/commonInputTypes.ts +192 -78
  44. package/generated-sqlite/internal/class.ts +184 -4
  45. package/generated-sqlite/internal/prismaNamespace.ts +1786 -138
  46. package/generated-sqlite/internal/prismaNamespaceBrowser.ts +291 -7
  47. package/generated-sqlite/models/AiProviderConfig.ts +100 -1
  48. package/generated-sqlite/models/AiStreamChunk.ts +1157 -0
  49. package/generated-sqlite/models/AiUsageLog.ts +91 -31
  50. package/generated-sqlite/models/Blob.ts +1425 -0
  51. package/generated-sqlite/models/BusinessAgentBinding.ts +1549 -0
  52. package/generated-sqlite/models/ChatInterrupt.ts +42 -1
  53. package/generated-sqlite/models/ChatMessage.ts +58 -29
  54. package/generated-sqlite/models/ChatPersistenceMeta.ts +1119 -0
  55. package/generated-sqlite/models/ChatRun.ts +174 -1
  56. package/generated-sqlite/models/ChatThread.ts +293 -1
  57. package/generated-sqlite/models/CodeSnippet.ts +1552 -0
  58. package/generated-sqlite/models/DesktopSetting.ts +1057 -0
  59. package/generated-sqlite/models/EmailLog.ts +1343 -0
  60. package/generated-sqlite/models/EmailPreference.ts +1255 -0
  61. package/generated-sqlite/models/EmailSubscriber.ts +1231 -0
  62. package/generated-sqlite/models/EmailVerificationToken.ts +1377 -0
  63. package/generated-sqlite/models/GenerationRun.ts +193 -1
  64. package/generated-sqlite/models/HarnessPlugin.ts +1674 -0
  65. package/generated-sqlite/models/HarnessWorkspace.ts +1647 -0
  66. package/generated-sqlite/models/InvitationCode.ts +65 -9
  67. package/generated-sqlite/models/NotificationPreference.ts +1313 -0
  68. package/generated-sqlite/models/OAuthProviderConfig.ts +1225 -0
  69. package/generated-sqlite/models/PageVersion.ts +0 -8
  70. package/generated-sqlite/models/Plan.ts +115 -1
  71. package/generated-sqlite/models/SandboxInstance.ts +1283 -0
  72. package/generated-sqlite/models/SystemPromptTemplate.ts +1581 -0
  73. package/generated-sqlite/models/SystemPromptVersion.ts +1456 -0
  74. package/generated-sqlite/models/User.ts +5345 -701
  75. package/generated-sqlite/models/UserAgent.ts +250 -1
  76. package/generated-sqlite/models/Workspace.ts +3 -1
  77. package/generated-sqlite/models/WorkspaceFile.ts +1532 -0
  78. package/generated-sqlite/models.ts +18 -0
  79. package/get-prisma.ts +6 -0
  80. package/index.ts +11 -6
  81. package/migrations/20260911120000_add_pgvector_tables/migration.sql +28 -0
  82. package/migrations/20260911171433_email_auth_invitation/migration.sql +80 -0
  83. package/migrations/20260912032616_email_p4_p8/migration.sql +42 -0
  84. package/migrations/20260914002427_ai_p0_durable_runs_meta/migration.sql +15 -0
  85. package/migrations/20260914041010_ai_p0_interrupt_requested_at/migration.sql +15 -0
  86. package/migrations/20260914041909_ai_p0_message_tool_call_id/migration.sql +2 -0
  87. package/migrations/20260914042448_ai_p0_message_content_json/migration.sql +27 -0
  88. package/migrations/20260914150229_harness_plugin/migration.sql +27 -0
  89. package/migrations/20260914174404_prompt_platform_agents/migration.sql +67 -0
  90. package/migrations/20260915090000_add_memory_facts/migration.sql +22 -0
  91. package/migrations/20260915124417_ai_p3_sandbox_durable/migration.sql +48 -0
  92. package/migrations/20260915150034_sandbox_instance_updatedat_bigint/migration.sql +2 -0
  93. package/migrations/20260915154000_add_code_snippets/migration.sql +31 -0
  94. package/migrations/20260916090000_ai_usage_log_nullable_workspace/migration.sql +10 -0
  95. package/migrations/20260916192752_add_ai_source_mode/migration.sql +13 -0
  96. package/migrations/20260917044512_harness_workspace/migration.sql +47 -0
  97. package/migrations/20260917100000_add_media_plan_limits/migration.sql +3 -0
  98. package/migrations/20260917163433_add_generation_run_linked_target/migration.sql +2 -0
  99. package/migrations/20260920050606_add_blob_table/migration.sql +17 -0
  100. package/migrations/20260920093412_add_byteplus_voice_fields/migration.sql +3 -0
  101. package/package.json +8 -3
  102. package/schema.prisma +413 -99
  103. package/schema.sqlite.prisma +865 -543
@@ -21,11 +21,21 @@ export type * from './models/ChatThread.ts'
21
21
  export type * from './models/ChatMessage.ts'
22
22
  export type * from './models/ChatRun.ts'
23
23
  export type * from './models/ChatInterrupt.ts'
24
+ export type * from './models/ChatPersistenceMeta.ts'
25
+ export type * from './models/HarnessPlugin.ts'
26
+ export type * from './models/SystemPromptTemplate.ts'
27
+ export type * from './models/SystemPromptVersion.ts'
28
+ export type * from './models/BusinessAgentBinding.ts'
24
29
  export type * from './models/GenerationRun.ts'
25
30
  export type * from './models/LoginLog.ts'
26
31
  export type * from './models/InvitationCode.ts'
27
32
  export type * from './models/InvitationUse.ts'
28
33
  export type * from './models/PasswordResetToken.ts'
34
+ export type * from './models/EmailVerificationToken.ts'
35
+ export type * from './models/EmailLog.ts'
36
+ export type * from './models/EmailPreference.ts'
37
+ export type * from './models/OAuthProviderConfig.ts'
38
+ export type * from './models/EmailSubscriber.ts'
29
39
  export type * from './models/KnowledgeBase.ts'
30
40
  export type * from './models/ProjectKnowledgeBase.ts'
31
41
  export type * from './models/WorkspaceKnowledgeBase.ts'
@@ -92,4 +102,12 @@ export type * from './models/DeveloperLog.ts'
92
102
  export type * from './models/Story.ts'
93
103
  export type * from './models/Iteration.ts'
94
104
  export type * from './models/IterationAutoSchedule.ts'
105
+ export type * from './models/NotificationPreference.ts'
106
+ export type * from './models/CodeSnippet.ts'
107
+ export type * from './models/SandboxInstance.ts'
108
+ export type * from './models/AiStreamChunk.ts'
109
+ export type * from './models/DesktopSetting.ts'
110
+ export type * from './models/HarnessWorkspace.ts'
111
+ export type * from './models/WorkspaceFile.ts'
112
+ export type * from './models/Blob.ts'
95
113
  export type * from './commonInputTypes.ts'
package/get-prisma.ts ADDED
@@ -0,0 +1,6 @@
1
+ import type { PrismaClient } from "./generated/client";
2
+
3
+ export async function getPrisma(): Promise<PrismaClient> {
4
+ const { prisma } = await import("./index");
5
+ return prisma;
6
+ }
package/index.ts CHANGED
@@ -15,9 +15,14 @@
15
15
  // You should have received a copy of the GNU Affero General Public License
16
16
  // along with this program. If not, see <https://www.gnu.org/licenses/>.
17
17
 
18
- import { PrismaClient } from "./generated/client";
18
+ // 加载 .env(从 process.cwd())— 生产环境已注入 env var 时 dotenv 不覆盖,
19
+ // 本地 dev 从 apps/web/.env 或 repo 根读取 DATABASE_URL 等。
20
+ // 缺失会导致 Prisma 回退到默认连接串(DB 名 = 当前 OS 用户名,报 3D000)。
21
+ import "dotenv/config";
22
+
23
+ import { PrismaClient } from "./generated/client.ts";
19
24
  import { PrismaPg } from "@prisma/adapter-pg";
20
- import { Prisma } from "./generated/client";
25
+ import { Prisma } from "./generated/client.ts";
21
26
  import { registerPrismaSeam } from "@allbluecn/kernel";
22
27
 
23
28
  const globalForPrisma = globalThis as unknown as {
@@ -30,11 +35,11 @@ async function createPrismaClient(): Promise<PrismaClient> {
30
35
  if (provider === "sqlite") {
31
36
  // 桌面端:先初始化本地 SQLite(建关系表 + 向量虚拟表),再创建 PrismaClient
32
37
  const dbPath = process.env.DATABASE_URL!.replace(/^file:/, "");
33
- const { initDesktopDb } = await import("./desktop-init");
38
+ const { initDesktopDb } = await import("./desktop-init.ts");
34
39
  await initDesktopDb(dbPath);
35
40
 
36
41
  // 动态 import:避免 better-sqlite3/sqlite 依赖被打进服务器 bundle(桌面端专用)
37
- const sqliteMod = await import("./generated-sqlite/client");
42
+ const sqliteMod = await import("./generated-sqlite/client.ts");
38
43
  const adapterMod = await import("@prisma/adapter-better-sqlite3");
39
44
  // 导出名是 PrismaBetterSqlite3(Sqlite 中 l 小写,非 SQLite)
40
45
  const adapter = new adapterMod.PrismaBetterSqlite3({
@@ -68,5 +73,5 @@ if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;
68
73
  registerPrismaSeam(prisma as unknown as import("@allbluecn/kernel").PrismaSeam);
69
74
 
70
75
  export { Prisma };
71
- export type { PrismaClient } from "./generated/client";
72
- export type { SubscriptionStatus } from "./generated/enums";
76
+ export type { PrismaClient } from "./generated/client.ts";
77
+ export type { SubscriptionStatus } from "./generated/enums.ts";
@@ -0,0 +1,28 @@
1
+ -- pgvector 原生向量表(非 Prisma 模型,由 apps/web/src/lib/vector-store/pg-vector-store.ts 以 raw SQL 读写)
2
+ -- 此前仅在开发库手工建表,缺失即报 42P01(relation does not exist)。
3
+ -- 幂等:IF NOT EXISTS,已手工建过表的库安全跳过。
4
+ CREATE EXTENSION IF NOT EXISTS vector;
5
+
6
+ CREATE TABLE IF NOT EXISTS "knowledge_embeddings" (
7
+ "id" TEXT NOT NULL,
8
+ "content" TEXT NOT NULL,
9
+ "kbId" TEXT,
10
+ "documentId" TEXT,
11
+ "prdPageId" TEXT,
12
+ "chunkIndex" INTEGER,
13
+ "embedding" vector(1536) NOT NULL,
14
+ CONSTRAINT "knowledge_embeddings_pkey" PRIMARY KEY ("id")
15
+ );
16
+
17
+ CREATE TABLE IF NOT EXISTS "prd_embeddings" (
18
+ "id" TEXT NOT NULL,
19
+ "content" TEXT NOT NULL,
20
+ "prdPageId" TEXT,
21
+ "chunkIndex" INTEGER,
22
+ "embedding" vector(1536) NOT NULL,
23
+ CONSTRAINT "prd_embeddings_pkey" PRIMARY KEY ("id")
24
+ );
25
+
26
+ CREATE INDEX IF NOT EXISTS "knowledge_embeddings_kbid_idx" ON "knowledge_embeddings"("kbId");
27
+ CREATE INDEX IF NOT EXISTS "knowledge_embeddings_documentid_idx" ON "knowledge_embeddings"("documentId");
28
+ CREATE INDEX IF NOT EXISTS "prd_embeddings_prdpageid_idx" ON "prd_embeddings"("prdPageId");
@@ -0,0 +1,80 @@
1
+ -- AlterTable
2
+ ALTER TABLE "invitation_codes" ADD COLUMN "createdById" TEXT,
3
+ ADD COLUMN "disabledAt" TIMESTAMP(3);
4
+
5
+ -- CreateTable
6
+ CREATE TABLE "email_verification_tokens" (
7
+ "id" TEXT NOT NULL,
8
+ "token" TEXT NOT NULL,
9
+ "userId" TEXT NOT NULL,
10
+ "expiresAt" TIMESTAMP(3) NOT NULL,
11
+ "usedAt" TIMESTAMP(3),
12
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
13
+
14
+ CONSTRAINT "email_verification_tokens_pkey" PRIMARY KEY ("id")
15
+ );
16
+
17
+ -- CreateTable
18
+ CREATE TABLE "email_logs" (
19
+ "id" TEXT NOT NULL,
20
+ "to" TEXT NOT NULL,
21
+ "templateKey" TEXT NOT NULL,
22
+ "category" TEXT NOT NULL,
23
+ "status" TEXT NOT NULL,
24
+ "provider" TEXT NOT NULL,
25
+ "messageId" TEXT,
26
+ "dedupeKey" TEXT,
27
+ "error" TEXT,
28
+ "userId" TEXT,
29
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
30
+ "sentAt" TIMESTAMP(3),
31
+
32
+ CONSTRAINT "email_logs_pkey" PRIMARY KEY ("id")
33
+ );
34
+
35
+ -- CreateTable
36
+ CREATE TABLE "email_preferences" (
37
+ "userId" TEXT NOT NULL,
38
+ "unsubscribedAll" BOOLEAN NOT NULL DEFAULT false,
39
+ "unsubscribedCategories" JSONB NOT NULL DEFAULT '[]',
40
+ "suppressed" BOOLEAN NOT NULL DEFAULT false,
41
+
42
+ CONSTRAINT "email_preferences_pkey" PRIMARY KEY ("userId")
43
+ );
44
+
45
+ -- CreateIndex
46
+ CREATE UNIQUE INDEX "email_verification_tokens_token_key" ON "email_verification_tokens"("token");
47
+
48
+ -- CreateIndex
49
+ CREATE UNIQUE INDEX "email_logs_dedupeKey_key" ON "email_logs"("dedupeKey");
50
+
51
+ -- CreateIndex
52
+ CREATE INDEX "email_logs_to_createdAt_idx" ON "email_logs"("to", "createdAt");
53
+
54
+ -- CreateIndex
55
+ CREATE INDEX "email_logs_userId_createdAt_idx" ON "email_logs"("userId", "createdAt");
56
+
57
+ -- CreateIndex
58
+ CREATE INDEX "email_logs_status_idx" ON "email_logs"("status");
59
+
60
+ -- AddForeignKey
61
+ ALTER TABLE "email_verification_tokens" ADD CONSTRAINT "email_verification_tokens_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
62
+
63
+ -- AddForeignKey
64
+ ALTER TABLE "email_preferences" ADD CONSTRAINT "email_preferences_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
65
+
66
+ -- 存量邮箱小写归一(注册流程从此统一 toLowerCase 写入)。
67
+ -- 零数据丢失策略:只归一,绝不删除任何用户行。
68
+ -- users.email 为 @unique,若线上已存在仅大小写不同的重复邮箱,直接 LOWER 会撞唯一约束
69
+ -- 导致整个迁移事务回滚。此处显式检测并 RAISE EXCEPTION,交人工裁决(手动改邮箱或合并账号)
70
+ -- 后再应用迁移,避免静默改邮箱或删账号造成的不可逆后果。
71
+ DO $$
72
+ DECLARE n integer;
73
+ BEGIN
74
+ SELECT count(*) INTO n
75
+ FROM (SELECT 1 FROM "users" GROUP BY LOWER("email") HAVING count(*) > 1) AS dupes;
76
+ IF n > 0 THEN
77
+ RAISE EXCEPTION '发现 % 组大小写重复邮箱,请先人工处理(改邮箱或合并账号)再应用本迁移', n;
78
+ END IF;
79
+ UPDATE "users" SET "email" = LOWER("email") WHERE "email" != LOWER("email");
80
+ END $$;
@@ -0,0 +1,42 @@
1
+ -- AlterTable
2
+ ALTER TABLE "notification_preferences" ADD COLUMN "emailCategories" JSONB NOT NULL DEFAULT '{}';
3
+
4
+ -- CreateTable
5
+ CREATE TABLE "oauth_provider_configs" (
6
+ "id" TEXT NOT NULL,
7
+ "provider" TEXT NOT NULL,
8
+ "clientId" TEXT NOT NULL,
9
+ "clientSecret" TEXT NOT NULL,
10
+ "enabled" BOOLEAN NOT NULL DEFAULT false,
11
+ "extra" JSONB,
12
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
13
+ "updatedAt" TIMESTAMP(3) NOT NULL,
14
+
15
+ CONSTRAINT "oauth_provider_configs_pkey" PRIMARY KEY ("id")
16
+ );
17
+
18
+ -- CreateTable
19
+ CREATE TABLE "email_subscribers" (
20
+ "id" TEXT NOT NULL,
21
+ "email" TEXT NOT NULL,
22
+ "locale" TEXT NOT NULL DEFAULT 'zh',
23
+ "confirmToken" TEXT NOT NULL,
24
+ "confirmedAt" TIMESTAMP(3),
25
+ "unsubscribedAt" TIMESTAMP(3),
26
+ "source" TEXT NOT NULL DEFAULT 'changelog',
27
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
28
+
29
+ CONSTRAINT "email_subscribers_pkey" PRIMARY KEY ("id")
30
+ );
31
+
32
+ -- CreateIndex
33
+ CREATE UNIQUE INDEX "oauth_provider_configs_provider_key" ON "oauth_provider_configs"("provider");
34
+
35
+ -- CreateIndex
36
+ CREATE UNIQUE INDEX "email_subscribers_email_key" ON "email_subscribers"("email");
37
+
38
+ -- CreateIndex
39
+ CREATE UNIQUE INDEX "email_subscribers_confirmToken_key" ON "email_subscribers"("confirmToken");
40
+
41
+ -- CreateIndex
42
+ CREATE INDEX "email_subscribers_confirmedAt_unsubscribedAt_idx" ON "email_subscribers"("confirmedAt", "unsubscribedAt");
@@ -0,0 +1,15 @@
1
+ -- AlterTable
2
+ ALTER TABLE "chat_runs" ADD COLUMN "cancelRequested" BOOLEAN,
3
+ ADD COLUMN "driverEpoch" INTEGER,
4
+ ADD COLUMN "sandboxKey" TEXT;
5
+
6
+ -- CreateTable
7
+ CREATE TABLE "chat_persistence_meta" (
8
+ "namespace" TEXT NOT NULL,
9
+ "key" TEXT NOT NULL,
10
+ "value" JSONB NOT NULL,
11
+ "updatedAt" TIMESTAMP(3) NOT NULL
12
+ );
13
+
14
+ -- CreateIndex
15
+ CREATE UNIQUE INDEX "chat_persistence_meta_namespace_key_key" ON "chat_persistence_meta"("namespace", "key");
@@ -0,0 +1,15 @@
1
+ /*
2
+ Warnings:
3
+
4
+ - You are about to drop the `knowledge_embeddings` table. If the table is not empty, all the data it contains will be lost.
5
+ - You are about to drop the `prd_embeddings` table. If the table is not empty, all the data it contains will be lost.
6
+
7
+ */
8
+ -- AlterTable
9
+ ALTER TABLE "chat_interrupts" ADD COLUMN "requestedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;
10
+
11
+ -- DropTable
12
+ DROP TABLE "knowledge_embeddings";
13
+
14
+ -- DropTable
15
+ DROP TABLE "prd_embeddings";
@@ -0,0 +1,2 @@
1
+ -- AlterTable
2
+ ALTER TABLE "chat_messages" ADD COLUMN "toolCallId" TEXT;
@@ -0,0 +1,27 @@
1
+ /*
2
+ 安全迁移:ChatMessage.content 从 TEXT 改为 JSONB(round-trip 无损)。
3
+
4
+ 三步法避免数据丢失:
5
+ 1. 加新列 content_new(JSONB)
6
+ 2. 回填:旧 TEXT 用 to_jsonb 转为 JSON 字符串(保留语义)
7
+ 3. 删旧列 + 重命名新列
8
+
9
+ 旧数据示例:
10
+ - "hello world" (TEXT) → "hello world" (JSONB 字符串)
11
+ - 数组内容(新格式)直接写入 content_new,不经回填
12
+
13
+ 注意:to_jsonb('hello'::text) 生成 JSON 字符串 "hello"(带引号),
14
+ 与 Prisma Json 类型读回时的 string 语义一致。
15
+ */
16
+
17
+ -- 1. 加新列
18
+ ALTER TABLE "chat_messages" ADD COLUMN "content_new" JSONB;
19
+
20
+ -- 2. 回填旧数据(TEXT → JSON 字符串)
21
+ UPDATE "chat_messages" SET "content_new" = to_jsonb("content") WHERE "content" IS NOT NULL;
22
+
23
+ -- 3. 删旧列
24
+ ALTER TABLE "chat_messages" DROP COLUMN "content";
25
+
26
+ -- 4. 重命名新列
27
+ ALTER TABLE "chat_messages" RENAME COLUMN "content_new" TO "content";
@@ -0,0 +1,27 @@
1
+ -- CreateTable
2
+ CREATE TABLE "harness_plugins" (
3
+ "id" TEXT NOT NULL,
4
+ "userId" TEXT NOT NULL,
5
+ "name" TEXT NOT NULL,
6
+ "purpose" TEXT NOT NULL,
7
+ "codeHost" TEXT,
8
+ "codeClient" TEXT,
9
+ "tools" JSONB NOT NULL DEFAULT '[]',
10
+ "version" INTEGER NOT NULL DEFAULT 1,
11
+ "status" TEXT NOT NULL DEFAULT 'defined',
12
+ "lastError" TEXT,
13
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
14
+ "updatedAt" TIMESTAMP(3) NOT NULL,
15
+ "isDeleted" BOOLEAN NOT NULL DEFAULT false,
16
+
17
+ CONSTRAINT "harness_plugins_pkey" PRIMARY KEY ("id")
18
+ );
19
+
20
+ -- CreateIndex
21
+ CREATE INDEX "harness_plugins_userId_idx" ON "harness_plugins"("userId");
22
+
23
+ -- CreateIndex
24
+ CREATE UNIQUE INDEX "harness_plugins_userId_name_key" ON "harness_plugins"("userId", "name");
25
+
26
+ -- AddForeignKey
27
+ ALTER TABLE "harness_plugins" ADD CONSTRAINT "harness_plugins_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
@@ -0,0 +1,67 @@
1
+ -- AlterTable
2
+ ALTER TABLE "user_agents" ADD COLUMN "isDefault" BOOLEAN NOT NULL DEFAULT false;
3
+
4
+ -- CreateTable
5
+ CREATE TABLE "system_prompt_templates" (
6
+ "id" TEXT NOT NULL,
7
+ "key" TEXT NOT NULL,
8
+ "name" TEXT NOT NULL,
9
+ "description" TEXT,
10
+ "sections" JSONB NOT NULL DEFAULT '[]',
11
+ "variables" JSONB NOT NULL DEFAULT '[]',
12
+ "version" INTEGER NOT NULL DEFAULT 1,
13
+ "isActive" BOOLEAN NOT NULL DEFAULT true,
14
+ "isProtected" BOOLEAN NOT NULL DEFAULT false,
15
+ "updatedBy" TEXT,
16
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
17
+ "updatedAt" TIMESTAMP(3) NOT NULL,
18
+
19
+ CONSTRAINT "system_prompt_templates_pkey" PRIMARY KEY ("id")
20
+ );
21
+
22
+ -- CreateTable
23
+ CREATE TABLE "system_prompt_versions" (
24
+ "id" TEXT NOT NULL,
25
+ "templateId" TEXT NOT NULL,
26
+ "version" INTEGER NOT NULL,
27
+ "sections" JSONB NOT NULL,
28
+ "note" TEXT,
29
+ "createdBy" TEXT,
30
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
31
+
32
+ CONSTRAINT "system_prompt_versions_pkey" PRIMARY KEY ("id")
33
+ );
34
+
35
+ -- CreateTable
36
+ CREATE TABLE "business_agent_bindings" (
37
+ "id" TEXT NOT NULL,
38
+ "userId" TEXT NOT NULL,
39
+ "bizKey" TEXT NOT NULL,
40
+ "agentId" TEXT NOT NULL,
41
+ "workspaceId" TEXT,
42
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
43
+ "updatedAt" TIMESTAMP(3) NOT NULL,
44
+
45
+ CONSTRAINT "business_agent_bindings_pkey" PRIMARY KEY ("id")
46
+ );
47
+
48
+ -- CreateIndex
49
+ CREATE UNIQUE INDEX "system_prompt_templates_key_key" ON "system_prompt_templates"("key");
50
+
51
+ -- CreateIndex
52
+ CREATE UNIQUE INDEX "system_prompt_versions_templateId_version_key" ON "system_prompt_versions"("templateId", "version");
53
+
54
+ -- CreateIndex
55
+ CREATE INDEX "business_agent_bindings_userId_idx" ON "business_agent_bindings"("userId");
56
+
57
+ -- CreateIndex
58
+ CREATE UNIQUE INDEX "business_agent_bindings_userId_bizKey_key" ON "business_agent_bindings"("userId", "bizKey");
59
+
60
+ -- AddForeignKey
61
+ ALTER TABLE "system_prompt_versions" ADD CONSTRAINT "system_prompt_versions_templateId_fkey" FOREIGN KEY ("templateId") REFERENCES "system_prompt_templates"("id") ON DELETE CASCADE ON UPDATE CASCADE;
62
+
63
+ -- AddForeignKey
64
+ ALTER TABLE "business_agent_bindings" ADD CONSTRAINT "business_agent_bindings_agentId_fkey" FOREIGN KEY ("agentId") REFERENCES "user_agents"("id") ON DELETE CASCADE ON UPDATE CASCADE;
65
+
66
+ -- AddForeignKey
67
+ ALTER TABLE "business_agent_bindings" ADD CONSTRAINT "business_agent_bindings_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
@@ -0,0 +1,22 @@
1
+ -- 跨会话记忆事实表(pgvector 原生向量表,非 Prisma 模型)
2
+ -- Prisma 无法表达 pgvector 的 vector 类型,故与 knowledge_embeddings / prd_embeddings
3
+ -- 同族:不入 schema.prisma,由迁移链建表、由 appsRust/src/server/ai-gateway/memory/
4
+ -- pgvector-adapter.ts 以 raw SQL 读写。SQLite 端不设对应表(桌面端不挂 memory middleware)。
5
+ -- 幂等:IF NOT EXISTS,已手工建过表的库安全跳过。
6
+ CREATE EXTENSION IF NOT EXISTS vector;
7
+
8
+ CREATE TABLE IF NOT EXISTS "memory_facts" (
9
+ "id" TEXT NOT NULL,
10
+ "userId" TEXT NOT NULL,
11
+ "threadId" TEXT NOT NULL,
12
+ "content" TEXT NOT NULL,
13
+ "embedding" vector(1536) NOT NULL,
14
+ "createdAt" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
15
+ CONSTRAINT "memory_facts_pkey" PRIMARY KEY ("id")
16
+ );
17
+
18
+ -- recall 路径:按 userId 过滤后按余弦距离排序
19
+ CREATE INDEX IF NOT EXISTS "memory_facts_userid_createdat_idx" ON "memory_facts"("userId", "createdAt" DESC);
20
+
21
+ -- admin 面板 / devtools 溯源:按会话维度列出
22
+ CREATE INDEX IF NOT EXISTS "memory_facts_threadid_idx" ON "memory_facts"("threadId");
@@ -0,0 +1,48 @@
1
+ -- AlterTable
2
+ ALTER TABLE "ai_usage_logs" ADD COLUMN "activity" TEXT;
3
+
4
+ -- AlterTable
5
+ ALTER TABLE "chat_threads" ADD COLUMN "sandboxPolicy" TEXT NOT NULL DEFAULT 'readonly';
6
+
7
+ -- AlterTable
8
+ ALTER TABLE "generation_runs" ADD COLUMN "activity" TEXT,
9
+ ADD COLUMN "artifacts" JSONB,
10
+ ADD COLUMN "model" TEXT,
11
+ ADD COLUMN "provider" TEXT,
12
+ ADD COLUMN "usage" JSONB;
13
+
14
+ -- AlterTable
15
+ ALTER TABLE "plans" ADD COLUMN "sandboxMinutesMonthly" INTEGER;
16
+
17
+ -- AlterTable
18
+ ALTER TABLE "user_agents" ADD COLUMN "harnessKind" TEXT;
19
+
20
+ -- CreateTable
21
+ CREATE TABLE "sandbox_instances" (
22
+ "key" TEXT NOT NULL,
23
+ "provider" TEXT NOT NULL,
24
+ "providerSandboxId" TEXT NOT NULL,
25
+ "latestSnapshotId" TEXT,
26
+ "threadId" TEXT NOT NULL,
27
+ "latestRunId" TEXT,
28
+ "updatedAt" INTEGER NOT NULL,
29
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
30
+
31
+ CONSTRAINT "sandbox_instances_pkey" PRIMARY KEY ("key")
32
+ );
33
+
34
+ -- CreateTable
35
+ CREATE TABLE "ai_stream_chunks" (
36
+ "id" BIGSERIAL NOT NULL,
37
+ "runId" TEXT NOT NULL,
38
+ "chunk" JSONB NOT NULL,
39
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
40
+
41
+ CONSTRAINT "ai_stream_chunks_pkey" PRIMARY KEY ("id")
42
+ );
43
+
44
+ -- CreateIndex
45
+ CREATE INDEX "sandbox_instances_threadId_idx" ON "sandbox_instances"("threadId");
46
+
47
+ -- CreateIndex
48
+ CREATE INDEX "ai_stream_chunks_runId_id_idx" ON "ai_stream_chunks"("runId", "id");
@@ -0,0 +1,2 @@
1
+ -- AlterTable
2
+ ALTER TABLE "sandbox_instances" ALTER COLUMN "updatedAt" SET DATA TYPE BIGINT;
@@ -0,0 +1,31 @@
1
+ -- 编排模式可复用片段表(CodeSnippet)
2
+ -- 用户保存的跨请求编排逻辑,运行时经 getSnippetBindings 暴露为 snippet_<name> 绑定,
3
+ -- 片段函数体在嵌套沙箱内执行并可调用 external_* 工具。见
4
+ -- apps/web/src/server/ai-gateway/code-mode/snippets.ts。
5
+
6
+ -- CreateTable
7
+ CREATE TABLE "code_snippets" (
8
+ "id" TEXT NOT NULL,
9
+ "userId" TEXT NOT NULL,
10
+ "name" TEXT NOT NULL,
11
+ "title" TEXT NOT NULL,
12
+ "description" TEXT NOT NULL,
13
+ "params" JSONB NOT NULL DEFAULT '{}',
14
+ "code" TEXT NOT NULL,
15
+ "enabled" BOOLEAN NOT NULL DEFAULT true,
16
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
17
+ "updatedAt" TIMESTAMP(3) NOT NULL,
18
+ "isDeleted" BOOLEAN NOT NULL DEFAULT false,
19
+
20
+ CONSTRAINT "code_snippets_pkey" PRIMARY KEY ("id")
21
+ );
22
+
23
+ -- CreateIndex
24
+ CREATE INDEX "code_snippets_userId_enabled_isDeleted_idx" ON "code_snippets"("userId", "enabled", "isDeleted");
25
+
26
+ -- CreateIndex
27
+ CREATE UNIQUE INDEX "code_snippets_userId_name_key" ON "code_snippets"("userId", "name");
28
+
29
+ -- AddForeignKey
30
+ ALTER TABLE "code_snippets" ADD CONSTRAINT "code_snippets_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
31
+
@@ -0,0 +1,10 @@
1
+ -- AlterTable
2
+ -- 配额按 userId 计,工作区仅作归属维度:尚无工作区的用户也必须能落计量行。
3
+ -- FK 仍为 RESTRICT(与 20260811153719 一致),workspace 删除前由 serverFn 先删日志。
4
+ ALTER TABLE "ai_usage_logs" DROP CONSTRAINT "ai_usage_logs_workspaceId_fkey";
5
+
6
+ -- AlterTable
7
+ ALTER TABLE "ai_usage_logs" ALTER COLUMN "workspaceId" DROP NOT NULL;
8
+
9
+ -- AddForeignKey
10
+ ALTER TABLE "ai_usage_logs" ADD CONSTRAINT "ai_usage_logs_workspaceId_fkey" FOREIGN KEY ("workspaceId") REFERENCES "workspaces"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
@@ -0,0 +1,13 @@
1
+ -- AlterTable
2
+ ALTER TABLE "ai_provider_configs" ADD COLUMN "agentMeta" JSONB;
3
+
4
+ -- AlterTable
5
+ ALTER TABLE "users" ADD COLUMN "aiSourceMode" TEXT;
6
+
7
+ -- CreateTable
8
+ CREATE TABLE "desktop_settings" (
9
+ "key" TEXT NOT NULL,
10
+ "value" JSONB NOT NULL,
11
+
12
+ CONSTRAINT "desktop_settings_pkey" PRIMARY KEY ("key")
13
+ );
@@ -0,0 +1,47 @@
1
+ -- AlterTable
2
+ ALTER TABLE "chat_threads" ADD COLUMN "workspaceId" TEXT;
3
+
4
+ -- CreateTable
5
+ CREATE TABLE "harness_workspaces" (
6
+ "id" TEXT NOT NULL,
7
+ "name" TEXT NOT NULL,
8
+ "ownerId" TEXT NOT NULL,
9
+ "kind" TEXT NOT NULL DEFAULT 'cloud',
10
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
11
+ "updatedAt" TIMESTAMP(3) NOT NULL,
12
+
13
+ CONSTRAINT "harness_workspaces_pkey" PRIMARY KEY ("id")
14
+ );
15
+
16
+ -- CreateTable
17
+ CREATE TABLE "workspace_files" (
18
+ "id" TEXT NOT NULL,
19
+ "workspaceId" TEXT NOT NULL,
20
+ "path" TEXT NOT NULL,
21
+ "mimeType" TEXT NOT NULL DEFAULT 'application/octet-stream',
22
+ "size" INTEGER NOT NULL DEFAULT 0,
23
+ "content" TEXT,
24
+ "source" TEXT NOT NULL DEFAULT 'upload',
25
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
26
+ "updatedAt" TIMESTAMP(3) NOT NULL,
27
+
28
+ CONSTRAINT "workspace_files_pkey" PRIMARY KEY ("id")
29
+ );
30
+
31
+ -- CreateIndex
32
+ CREATE INDEX "harness_workspaces_ownerId_updatedAt_idx" ON "harness_workspaces"("ownerId", "updatedAt");
33
+
34
+ -- CreateIndex
35
+ CREATE INDEX "workspace_files_workspaceId_idx" ON "workspace_files"("workspaceId");
36
+
37
+ -- CreateIndex
38
+ CREATE UNIQUE INDEX "workspace_files_workspaceId_path_key" ON "workspace_files"("workspaceId", "path");
39
+
40
+ -- AddForeignKey
41
+ ALTER TABLE "chat_threads" ADD CONSTRAINT "chat_threads_workspaceId_fkey" FOREIGN KEY ("workspaceId") REFERENCES "harness_workspaces"("id") ON DELETE SET NULL ON UPDATE CASCADE;
42
+
43
+ -- AddForeignKey
44
+ ALTER TABLE "harness_workspaces" ADD CONSTRAINT "harness_workspaces_ownerId_fkey" FOREIGN KEY ("ownerId") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
45
+
46
+ -- AddForeignKey
47
+ ALTER TABLE "workspace_files" ADD CONSTRAINT "workspace_files_workspaceId_fkey" FOREIGN KEY ("workspaceId") REFERENCES "harness_workspaces"("id") ON DELETE CASCADE ON UPDATE CASCADE;
@@ -0,0 +1,3 @@
1
+ -- AlterTable: P4c 媒体生成计划限额(mediaGenerationsMonthly / galleryStorageMb)
2
+ ALTER TABLE "plans" ADD COLUMN IF NOT EXISTS "mediaGenerationsMonthly" INTEGER;
3
+ ALTER TABLE "plans" ADD COLUMN IF NOT EXISTS "galleryStorageMb" INTEGER;
@@ -0,0 +1,2 @@
1
+ -- AlterTable
2
+ ALTER TABLE "generation_runs" ADD COLUMN "linkedTarget" JSONB;
@@ -0,0 +1,17 @@
1
+ -- CreateTable
2
+ CREATE TABLE "blobs" (
3
+ "id" TEXT NOT NULL,
4
+ "mimeType" TEXT NOT NULL,
5
+ "bytes" BYTEA NOT NULL,
6
+ "size" INTEGER NOT NULL,
7
+ "userId" TEXT NOT NULL,
8
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
9
+
10
+ CONSTRAINT "blobs_pkey" PRIMARY KEY ("id")
11
+ );
12
+
13
+ -- CreateIndex
14
+ CREATE INDEX "blobs_userId_idx" ON "blobs"("userId");
15
+
16
+ -- AddForeignKey
17
+ ALTER TABLE "blobs" ADD CONSTRAINT "blobs_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
@@ -0,0 +1,3 @@
1
+ -- AlterTable
2
+ ALTER TABLE "ai_provider_configs" ADD COLUMN "voiceApiKey" TEXT,
3
+ ADD COLUMN "voiceBaseUrl" TEXT;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allbluecn/database",
3
- "version": "0.6.0",
3
+ "version": "0.9.0",
4
4
  "license": "AGPL-3.0-or-later",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -15,7 +15,7 @@
15
15
  "pg": "^8.22.0",
16
16
  "sqlite-vec": "^0.1.9",
17
17
  "bcryptjs": "^3.0.2",
18
- "@allbluecn/kernel": "0.6.1"
18
+ "@allbluecn/kernel": "0.9.0"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@types/better-sqlite3": "^7.6.13",
@@ -26,6 +26,10 @@
26
26
  },
27
27
  "exports": {
28
28
  ".": "./index.ts",
29
+ "./get-prisma": {
30
+ "types": "./dist/get-prisma.d.ts",
31
+ "default": "./dist/get-prisma.js"
32
+ },
29
33
  "./lib/share-utils": {
30
34
  "types": "./dist/lib/share-utils.d.ts",
31
35
  "default": "./dist/lib/share-utils.js"
@@ -52,7 +56,8 @@
52
56
  "migrations",
53
57
  "desktop-init.ts",
54
58
  "desktop-init.d.ts",
55
- "index.ts"
59
+ "index.ts",
60
+ "get-prisma.ts"
56
61
  ],
57
62
  "publishConfig": {
58
63
  "access": "public"