@allbluecn/database 0.12.3 → 0.14.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/generated/internal/class.ts +4 -4
- package/generated/internal/prismaNamespace.ts +4 -1
- package/generated/internal/prismaNamespaceBrowser.ts +4 -1
- package/generated/models/ChatThread.ts +199 -1
- package/migrations/20261101040000_add_chat_thread_engine/migration.sql +4 -0
- package/migrations/20261104100000_add_chat_thread_local_agent_id/migration.sql +4 -0
- package/package.json +3 -1
- package/pglite-init.ts +14 -0
- package/pglite-seed.ts +63 -0
- package/schema.prisma +6 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@allbluecn/database",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"license": "AGPL-3.0-or-later",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.ts",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
".": "./index.ts",
|
|
27
27
|
"./get-prisma": "./get-prisma.ts",
|
|
28
28
|
"./pglite-init": "./pglite-init.ts",
|
|
29
|
+
"./pglite-seed": "./pglite-seed.ts",
|
|
29
30
|
"./cf-env": "./cf-env.ts",
|
|
30
31
|
"./cf-env-stub": "./cf-env-stub.ts",
|
|
31
32
|
"./lib/share-utils": "./src/lib/share-utils.ts",
|
|
@@ -48,6 +49,7 @@
|
|
|
48
49
|
"prisma.config.ts",
|
|
49
50
|
"migrations",
|
|
50
51
|
"pglite-init.ts",
|
|
52
|
+
"pglite-seed.ts",
|
|
51
53
|
"index.ts",
|
|
52
54
|
"get-prisma.ts",
|
|
53
55
|
"cf-env.ts",
|
package/pglite-init.ts
CHANGED
|
@@ -15,6 +15,7 @@ import { PGlite } from "@electric-sql/pglite";
|
|
|
15
15
|
import { vector } from "@electric-sql/pglite-pgvector";
|
|
16
16
|
import { PrismaPGlite } from "pglite-prisma-adapter";
|
|
17
17
|
import { PrismaClient } from "./generated/client.ts";
|
|
18
|
+
import { seedAiProvidersPglite, type PgliteSeedPrisma } from "./pglite-seed.ts";
|
|
18
19
|
|
|
19
20
|
const LEDGER_DDL = `
|
|
20
21
|
CREATE TABLE IF NOT EXISTS _pglite_migrations (
|
|
@@ -74,6 +75,19 @@ export async function createPglite(options: PgliteInitOptions): Promise<PgliteHa
|
|
|
74
75
|
adapter: new PrismaPGlite(db),
|
|
75
76
|
log: ["error"],
|
|
76
77
|
}) as unknown as PrismaClient;
|
|
78
|
+
|
|
79
|
+
// 桌面没有 `prisma db seed` 步骤:迁移后 create-only 补种 AI 服务商目录
|
|
80
|
+
// (幂等,已有行跳过)。失败不阻断启动(降级为空目录,设置页可见症状),
|
|
81
|
+
// 但必须大声报错——静默空目录正是本 seed 要修的缺陷。
|
|
82
|
+
try {
|
|
83
|
+
const created = await seedAiProvidersPglite(prisma as unknown as PgliteSeedPrisma);
|
|
84
|
+
if (created > 0) {
|
|
85
|
+
console.log(`[pglite-init] AI 服务商目录 seed:新增 ${created} 条`);
|
|
86
|
+
}
|
|
87
|
+
} catch (error) {
|
|
88
|
+
console.error("[pglite-init] AI 服务商目录 seed 失败(降级为空目录):", error);
|
|
89
|
+
}
|
|
90
|
+
|
|
77
91
|
const handle = { db, prisma };
|
|
78
92
|
// 宿主协调:Electron backend entry 预热实例后,nitro 内 database/index.ts
|
|
79
93
|
// 经此共享同一 PGlite(单实例约束——同目录双实例会损坏 cluster)
|
package/pglite-seed.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
|
+
// AllBlue - 理想之海
|
|
3
|
+
// Copyright (C) 2026 AllBlue Contributors
|
|
4
|
+
|
|
5
|
+
// 桌面端(Electron + PGlite)目录 seed:AiProvider 预置服务商。
|
|
6
|
+
// 云端/web 走 `prisma db seed`(seed/seed-ai-providers.ts,同一份 SEED_AI_PROVIDERS
|
|
7
|
+
// 数据源);桌面 PGlite 初始化只有迁移步骤、没有 seed 钩子,目录表为空会导致
|
|
8
|
+
// 设置页「使用自己的 Key」无预置服务商、agent BYOK 元数据解析全跳过。
|
|
9
|
+
//
|
|
10
|
+
// 语义与 seed/seed-ai-providers.ts 默认模式逐项对齐(create-only):
|
|
11
|
+
// - 不存在 → 插入(enabled: true,sortOrder = 目录顺序)
|
|
12
|
+
// - 已存在 → 跳过(保留对元数据的修改)
|
|
13
|
+
// 映射字段若两边任一改动,必须同步另一边。
|
|
14
|
+
import { SEED_AI_PROVIDERS } from "@allbluecn/kernel";
|
|
15
|
+
|
|
16
|
+
/** prisma 最小写入面(结构类型:调用方传真实 PrismaClient 或测试桩均可) */
|
|
17
|
+
export interface PgliteSeedPrisma {
|
|
18
|
+
aiProvider: {
|
|
19
|
+
findUnique(args: { where: { providerId: string } }): Promise<unknown | null>;
|
|
20
|
+
create(args: { data: Record<string, unknown> }): Promise<unknown>;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* create-only 补种 AI 服务商目录,返回本次新增条数。单条失败 warn 后继续
|
|
26
|
+
* (一条坏数据不拖垮其余目录);调用方决定整体失败时是否阻断启动。
|
|
27
|
+
*/
|
|
28
|
+
export async function seedAiProvidersPglite(prisma: PgliteSeedPrisma): Promise<number> {
|
|
29
|
+
let created = 0;
|
|
30
|
+
for (let i = 0; i < SEED_AI_PROVIDERS.length; i++) {
|
|
31
|
+
const p = SEED_AI_PROVIDERS[i]!;
|
|
32
|
+
const data: Record<string, unknown> = {
|
|
33
|
+
providerId: p.providerId,
|
|
34
|
+
displayName: p.displayName,
|
|
35
|
+
brandName: p.brandName,
|
|
36
|
+
description: p.description,
|
|
37
|
+
category: p.category,
|
|
38
|
+
adapterKind: p.adapterKind,
|
|
39
|
+
defaultBaseUrl: p.defaultBaseUrl ?? null,
|
|
40
|
+
keyUrl: p.keyUrl ?? null,
|
|
41
|
+
docsUrl: p.docsUrl ?? null,
|
|
42
|
+
keyPlaceholder: p.keyPlaceholder ?? null,
|
|
43
|
+
iconSlug: p.iconSlug ?? null,
|
|
44
|
+
brandColor: p.brandColor,
|
|
45
|
+
badge: p.badge ?? null,
|
|
46
|
+
isLocal: p.isLocal ?? false,
|
|
47
|
+
models: p.models,
|
|
48
|
+
sortOrder: i,
|
|
49
|
+
enabled: true,
|
|
50
|
+
};
|
|
51
|
+
try {
|
|
52
|
+
const existing = await prisma.aiProvider.findUnique({
|
|
53
|
+
where: { providerId: p.providerId },
|
|
54
|
+
});
|
|
55
|
+
if (existing) continue;
|
|
56
|
+
await prisma.aiProvider.create({ data });
|
|
57
|
+
created++;
|
|
58
|
+
} catch (error) {
|
|
59
|
+
console.warn(`[pglite-seed] AiProvider ${p.providerId} 补种失败,跳过:`, error);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return created;
|
|
63
|
+
}
|
package/schema.prisma
CHANGED
|
@@ -363,6 +363,12 @@ model ChatThread {
|
|
|
363
363
|
agent UserAgent? @relation(fields: [agentId], references: [id], onDelete: SetNull)
|
|
364
364
|
workspaceId String?
|
|
365
365
|
workspace HarnessWorkspace? @relation(fields: [workspaceId], references: [id], onDelete: SetNull)
|
|
366
|
+
/// 执行引擎:cloud(服务端模型)/ local(桌面本地 Agent)
|
|
367
|
+
engine String @default("cloud")
|
|
368
|
+
/// 本地 Agent 的授权工作目录(engine=local 时必填;仅桌面壳)
|
|
369
|
+
localCwd String?
|
|
370
|
+
/// 本地 agent 选择(engine=local 时):'pi'(内置引擎,null 视同)/ 'acp:<catalogId>'
|
|
371
|
+
localAgentId String?
|
|
366
372
|
|
|
367
373
|
@@index([userId, updatedAt])
|
|
368
374
|
@@map("chat_threads")
|