@allbluecn/database 0.14.1 → 0.14.3
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/browser.ts +66 -0
- package/generated/client.ts +66 -0
- package/generated/internal/class.ts +94 -4
- package/generated/internal/prismaNamespace.ts +814 -3
- package/generated/internal/prismaNamespaceBrowser.ts +138 -2
- package/generated/models/ChatThread.ts +174 -2
- package/generated/models/DesignEmbedding.ts +25 -1
- package/generated/models/HarnessArtifact.ts +1307 -0
- package/generated/models/HarnessBlob.ts +1273 -0
- package/generated/models/HarnessHostHeartbeat.ts +1125 -0
- package/generated/models/HarnessLogEntry.ts +1354 -0
- package/generated/models/HarnessLogHeader.ts +1904 -0
- package/generated/models/HarnessLogOffer.ts +1382 -0
- package/generated/models/HarnessLogSnapshot.ts +1333 -0
- package/generated/models/HarnessMetadata.ts +1255 -0
- package/generated/models/HarnessSession.ts +1504 -0
- package/generated/models.ts +9 -0
- package/migrations/20261108000000_story_generate_prompt_json_contract/migration.sql +11 -0
- package/migrations/20261108000001_design_prototype_stream_prompt_ops_contract/migration.sql +13 -0
- package/migrations/20261109000000_harness_persistence/migration.sql +156 -0
- package/migrations/20261111000000_harness_cas_tombstone/migration.sql +12 -0
- package/package.json +3 -1
- package/pg-client.ts +21 -0
- package/schema.prisma +197 -1
package/generated/models.ts
CHANGED
|
@@ -154,4 +154,13 @@ export type * from './models/AiTask.ts'
|
|
|
154
154
|
export type * from './models/AiTaskRun.ts'
|
|
155
155
|
export type * from './models/KnowledgeEmbedding.ts'
|
|
156
156
|
export type * from './models/DesignEmbedding.ts'
|
|
157
|
+
export type * from './models/HarnessLogHeader.ts'
|
|
158
|
+
export type * from './models/HarnessLogEntry.ts'
|
|
159
|
+
export type * from './models/HarnessLogOffer.ts'
|
|
160
|
+
export type * from './models/HarnessLogSnapshot.ts'
|
|
161
|
+
export type * from './models/HarnessHostHeartbeat.ts'
|
|
162
|
+
export type * from './models/HarnessMetadata.ts'
|
|
163
|
+
export type * from './models/HarnessBlob.ts'
|
|
164
|
+
export type * from './models/HarnessArtifact.ts'
|
|
165
|
+
export type * from './models/HarnessSession.ts'
|
|
157
166
|
export type * from './commonInputTypes.ts'
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
-- story.generate 内置提示词契约变更(T-M2):自研 JSONL 逐行输出 → 官方 outputSchema
|
|
2
|
+
-- 的 JSON 对象契约 {"items":[...]}(kernel builtin 同步改写)。ensurePromptSeeded
|
|
3
|
+
-- 只补缺不覆盖(幂等 seed),已部署环境的 system_prompt_templates 行仍为旧 JSONL
|
|
4
|
+
-- 正文且优先于 builtin,需本迁移同步。守卫:仅当 sections 与基线 builtin 完全一致
|
|
5
|
+
-- (即未被管理员定制过)才改写,定制行不动;WHERE 不满足时 UPDATE 0,天然幂等。
|
|
6
|
+
UPDATE "system_prompt_templates"
|
|
7
|
+
SET "sections" = '[{"id":"role","order":1,"template":"你是一个敏捷开发中的需求分析师。\n{{taskTypeInstruction}}"},{"id":"rules","order":2,"template":"输出要求(严格遵守):\n1. 输出一个 JSON 对象:{\"items\":[...]},items 为 2-5 个需求对象的数组。\n2. 每个需求对象仅允许字段:name(必填,2-50 字)。\n3. 可选字段:description、priority、labelNames。\n4. priority 仅限:urgent | high | medium | low | none。\n5. {{labelHint}}。\n6. 不要使用 markdown 代码块包裹,不要输出其他解释文字。"},{"id":"parent-story","order":3,"template":"{{parentStoryHint}}"},{"id":"requirement","order":4,"template":"{{requirement}}"}]'::jsonb,
|
|
8
|
+
"description" = '敏捷需求分析师:生成/拆解 Story(JSON 结构化输出)',
|
|
9
|
+
"updatedAt" = CURRENT_TIMESTAMP
|
|
10
|
+
WHERE "key" = 'story.generate'
|
|
11
|
+
AND "sections" = '[{"id":"role","order":1,"template":"你是一个敏捷开发中的需求分析师。\n{{taskTypeInstruction}}"},{"id":"rules","order":2,"template":"输出要求(严格遵守):\n1. 严格遵循 JSONL 格式:每行输出一个 JSON 对象,不要输出除 JSON 对象行以外的任何内容。\n2. 每行对象仅允许字段:name(必填,2-50 字)。\n3. 可选字段:description、priority、labelNames。\n4. priority 仅限:urgent | high | medium | low | none。\n5. {{labelHint}}。\n6. 不要使用 markdown 代码块包裹,不要输出数组,不要输出其他解释文字。"},{"id":"parent-story","order":3,"template":"{{parentStoryHint}}"},{"id":"requirement","order":4,"template":"{{requirement}}"}]'::jsonb;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
-- design.prototype.stream 内置提示词契约变更(T-M3):NDJSON 行协议 → 官方
|
|
2
|
+
-- outputSchema 的 JSON 对象契约 {"ops":[...]}(kernel builtin 同步改写)。ensurePromptSeeded
|
|
3
|
+
-- 只补缺不覆盖(幂等 seed),已部署环境的 system_prompt_templates 行仍为旧 NDJSON
|
|
4
|
+
-- 正文且优先于 builtin,需本迁移同步。守卫:仅当 sections 为任一已知未定制
|
|
5
|
+
-- builtin 变体(基线 94f02d408,或 ac04946f9 占位符修正前的 legacy 变体)时才
|
|
6
|
+
-- 改写,管理员定制行不动;WHERE 不满足时 UPDATE 0,天然幂等。
|
|
7
|
+
UPDATE "system_prompt_templates"
|
|
8
|
+
SET "sections" = '[{"id":"contract","order":1,"template":"你是设计画布流式生成助手。根据用户的自然语言描述,输出一个 JSON 对象,形如 {\"ops\":[...]},ops 数组按时间序包含画布操作。\n\n【输出契约(必须严格遵守)】\n1. 只输出一个 JSON 对象:{\"ops\":[操作, 操作, ...]};不要输出 markdown 代码块标记,不要输出任何解释文字\n2. 每个操作只能是以下四种之一:\n {\"op\":\"frame\",\"node\":{...}}\n {\"op\":\"nodes\",\"nodes\":[{...},{...}]}\n {\"op\":\"replace\",\"removeIds\":[\"节点id\"],\"nodes\":[{...}]}\n {\"op\":\"done\",\"message\":\"给用户的中文完成说明\"}\n3. 节点结构必须符合下方 JSON Schema;节点一律不含 parentId 字段,禁止输出 parentId(节点归属由服务端按「最近一个 frame 操作」回填)\n4. fills/strokes 仅允许 solid/linear/radial/angular 四类 paint;严禁 image 与 shader——这两类会被服务端静默丢弃\n\n【分批指令】\n5. 先输出一个 frame 操作新建目标画板(画板尺寸与内容形态匹配,如移动端页面 375x812、桌面端 1280x800)\n6. 之后按功能区块分批输出 nodes 操作:每批 3~8 个节点,一个区块一批,逐批输出,让用户看到内容逐步出现\n7. 节点的 x/y 是相对其所属画板(frame)左上角的坐标\n8. 全部节点输出完毕后,必须以一个 done 操作结束,message 用一句中文说明生成了什么\n\n{{schemaHint}}\n\n{{catalog}}\n\n【本次模式:{{mode}}】\n{{targetFrame}}\n\n【选中子树】\n{{selection}}\n\n【replace 协议(仅 regenerate 模式适用;选中子树为「(无)」时忽略本节)】\n- replace 用于重新生成选中子树:removeIds 填要删除的既有节点 id(来自选中子树),nodes 为替换后的新节点\n- 新节点的 x/y 以被替换区域左上角为原点;前端会继承 removeIds[0] 的 parentId 与位置,因此不要输出 parentId,也不要输出画板绝对坐标\n- 除归属规则外,其余输出契约与 nodes 相同,最后以 done 结束\n\n示例:\n用户:一个登录页\n输出:\n{\"ops\":[{\"op\":\"frame\",\"node\":{\"name\":\"登录页\",\"x\":0,\"y\":0,\"width\":375,\"height\":812}},{\"op\":\"nodes\",\"nodes\":[{\"type\":\"text\",\"name\":\"标题\",\"x\":24,\"y\":60,\"width\":200,\"height\":32,\"props\":{\"text\":\"欢迎回来\"}},{\"type\":\"input\",\"name\":\"用户名\",\"x\":16,\"y\":120,\"width\":343,\"height\":40,\"props\":{\"text\":\"用户名\"}}]},{\"op\":\"nodes\",\"nodes\":[{\"type\":\"input\",\"name\":\"密码\",\"x\":16,\"y\":176,\"width\":343,\"height\":40,\"props\":{\"text\":\"密码\"}},{\"type\":\"button\",\"name\":\"登录\",\"x\":16,\"y\":240,\"width\":343,\"height\":44,\"props\":{\"text\":\"登录\"}}]},{\"op\":\"done\",\"message\":\"已生成登录页:标题、两个输入框与主按钮\"}]}"}]'::jsonb,
|
|
9
|
+
"description" = '以 ops 数组 JSON 对象协议输出画布操作流(frame/nodes/replace/done),供 SSE 路由 /api/design/prototype 消费',
|
|
10
|
+
"updatedAt" = CURRENT_TIMESTAMP
|
|
11
|
+
WHERE "key" = 'design.prototype.stream'
|
|
12
|
+
AND ("sections" = '[{"id":"contract","order":1,"template":"你是设计画布流式生成助手。根据用户的自然语言描述,以 NDJSON 行协议逐行输出画布操作流。\n\n【输出契约(必须严格遵守)】\n1. 每行输出一个独立的 JSON 对象,行与行以换行分隔;不要输出 markdown 代码块标记,不要输出任何解释文字\n2. 每行只能是以下四种操作之一:\n {\"op\":\"frame\",\"node\":{\"name\":\"画板名\",\"x\":0,\"y\":0,\"width\":375,\"height\":812}}\n {\"op\":\"nodes\",\"nodes\":[{...},{...}]}\n {\"op\":\"replace\",\"removeIds\":[\"节点id\"],\"nodes\":[{...}]}\n {\"op\":\"done\",\"message\":\"给用户的中文完成说明\"}\n3. 节点结构必须符合下方 JSON Schema;节点一律不含 parentId 字段,禁止输出 parentId(节点归属由服务端按「最近一个 frame 操作」回填)\n4. fills/strokes 仅允许 solid/linear/radial/angular 四类 paint;严禁 image 与 shader——这两类会被服务端静默丢弃\n\n【分批指令】\n5. 先输出一个 frame 操作新建目标画板(画板尺寸与内容形态匹配,如移动端页面 375x812、桌面端 1280x800)\n6. 之后按功能区块分批输出 nodes 操作:每批 3~8 个节点,一个区块一批,逐批输出,让用户看到内容逐步出现\n7. 节点的 x/y 是相对其所属画板(frame)左上角的坐标\n8. 全部节点输出完毕后,必须以一个 done 操作结束,message 用一句中文说明生成了什么\n\n{{schemaHint}}\n\n{{catalog}}\n\n【本次模式:{{mode}}】\n{{targetFrame}}\n\n【选中子树】\n{{selection}}\n\n【replace 协议(仅 regenerate 模式适用;选中子树为「(无)」时忽略本节)】\n- replace 用于重新生成选中子树:removeIds 填要删除的既有节点 id(来自选中子树),nodes 为替换后的新节点\n- 新节点的 x/y 以被替换区域左上角为原点;前端会继承 removeIds[0] 的 parentId 与位置,因此不要输出 parentId,也不要输出画板绝对坐标\n- 除归属规则外,其余输出契约与 nodes 相同,最后以 done 结束\n\n示例:\n用户:一个登录页\n输出:\n{\"op\":\"frame\",\"node\":{\"name\":\"登录页\",\"x\":0,\"y\":0,\"width\":375,\"height\":812}}\n{\"op\":\"nodes\",\"nodes\":[{\"type\":\"text\",\"name\":\"标题\",\"x\":24,\"y\":60,\"width\":200,\"height\":32,\"props\":{\"text\":\"欢迎回来\"}},{\"type\":\"input\",\"name\":\"用户名\",\"x\":16,\"y\":120,\"width\":343,\"height\":40,\"props\":{\"text\":\"用户名\"}}]}\n{\"op\":\"nodes\",\"nodes\":[{\"type\":\"input\",\"name\":\"密码\",\"x\":16,\"y\":176,\"width\":343,\"height\":40,\"props\":{\"text\":\"密码\"}},{\"type\":\"button\",\"name\":\"登录\",\"x\":16,\"y\":240,\"width\":343,\"height\":44,\"props\":{\"text\":\"登录\"}}]}\n{\"op\":\"done\",\"message\":\"已生成登录页:标题、两个输入框与主按钮\"}"}]'::jsonb
|
|
13
|
+
OR "sections" = '[{"id":"contract","order":1,"template":"你是设计画布流式生成助手。根据用户的自然语言描述,以 NDJSON 行协议逐行输出画布操作流。\n\n【输出契约(必须严格遵守)】\n1. 每行输出一个独立的 JSON 对象,行与行以换行分隔;不要输出 markdown 代码块标记,不要输出任何解释文字\n2. 每行只能是以下四种操作之一:\n {\"op\":\"frame\",\"node\":{\"name\":\"画板名\",\"x\":0,\"y\":0,\"width\":375,\"height\":812}}\n {\"op\":\"nodes\",\"nodes\":[{...},{\"...\"}]}\n {\"op\":\"replace\",\"removeIds\":[\"节点id\"],\"nodes\":[{...}]}\n {\"op\":\"done\",\"message\":\"给用户的中文完成说明\"}\n3. 节点结构必须符合下方 JSON Schema;节点一律不含 parentId 字段,禁止输出 parentId(节点归属由服务端按「最近一个 frame 操作」回填)\n4. fills/strokes 仅允许 solid/linear/radial/angular 四类 paint;严禁 image 与 shader——这两类会被服务端静默丢弃\n\n【分批指令】\n5. 先输出一个 frame 操作新建目标画板(画板尺寸与内容形态匹配,如移动端页面 375x812、桌面端 1280x800)\n6. 之后按功能区块分批输出 nodes 操作:每批 3~8 个节点,一个区块一批,逐批输出,让用户看到内容逐步出现\n7. 节点的 x/y 是相对其所属画板(frame)左上角的坐标\n8. 全部节点输出完毕后,必须以一个 done 操作结束,message 用一句中文说明生成了什么\n\n{{schemaHint}}\n\n{{catalog}}\n\n【本次模式:{{mode}}】\n{{targetFrame}}\n\n【选中子树】\n{{selection}}\n\n【replace 协议(仅 regenerate 模式适用;选中子树为「(无)」时忽略本节)】\n- replace 用于重新生成选中子树:removeIds 填要删除的既有节点 id(来自选中子树),nodes 为替换后的新节点\n- 新节点的 x/y 以被替换区域左上角为原点;前端会继承 removeIds[0] 的 parentId 与位置,因此不要输出 parentId,也不要输出画板绝对坐标\n- 除归属规则外,其余输出契约与 nodes 相同,最后以 done 结束\n\n示例:\n用户:一个登录页\n输出:\n{\"op\":\"frame\",\"node\":{\"name\":\"登录页\",\"x\":0,\"y\":0,\"width\":375,\"height\":812}}\n{\"op\":\"nodes\",\"nodes\":[{\"type\":\"text\",\"name\":\"标题\",\"x\":24,\"y\":60,\"width\":200,\"height\":32,\"props\":{\"text\":\"欢迎回来\"}},{\"type\":\"input\",\"name\":\"用户名\",\"x\":16,\"y\":120,\"width\":343,\"height\":40,\"props\":{\"text\":\"用户名\"}}]}\n{\"op\":\"nodes\",\"nodes\":[{\"type\":\"input\",\"name\":\"密码\",\"x\":16,\"y\":176,\"width\":343,\"height\":40,\"props\":{\"text\":\"密码\"}},{\"type\":\"button\",\"name\":\"登录\",\"x\":16,\"y\":240,\"width\":343,\"height\":44,\"props\":{\"text\":\"登录\"}}]}\n{\"op\":\"done\",\"message\":\"已生成登录页:标题、两个输入框与主按钮\"}"}]'::jsonb);
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
-- Harness 持久化(Phase 1,六 store 载体):LogStore 五表 + 会话索引表 + 元数据 + 媒体两表
|
|
2
|
+
-- + ChatThread 会话桥接预留列。官方契约:@tanstack/ai-persistence@1.0.1 types.d.ts;设计 §4。
|
|
3
|
+
-- ⚠ 本迁移只含 harness 相关变更。live 库另有与本任务无关的历史漂移
|
|
4
|
+
-- (*sync_version 列、memory_facts/sync_* 表、design_embeddings.documentId),
|
|
5
|
+
-- 按仓约定(remove_tag_module / memory_facts 先例)一律剥离,禁止 DROP。
|
|
6
|
+
|
|
7
|
+
-- AlterTable:ChatThread 会话桥接预留列(Phase 2 T2.7;conformance 级 SessionIndexStore
|
|
8
|
+
-- 载体为独立表 harness_sessions,见 schema 注释)
|
|
9
|
+
ALTER TABLE "chat_threads" ADD COLUMN "indexMetadata" JSONB,
|
|
10
|
+
ADD COLUMN "indexRevision" INTEGER NOT NULL DEFAULT 0;
|
|
11
|
+
|
|
12
|
+
-- CreateTable:LogStore 所有权/截断/亲和头
|
|
13
|
+
CREATE TABLE "harness_log_headers" (
|
|
14
|
+
"logId" TEXT NOT NULL,
|
|
15
|
+
"harness" TEXT,
|
|
16
|
+
"affinity" TEXT,
|
|
17
|
+
"epoch" INTEGER NOT NULL DEFAULT 0,
|
|
18
|
+
"ownerId" TEXT,
|
|
19
|
+
"ownerExpiresAt" TIMESTAMP(3),
|
|
20
|
+
"released" BOOLEAN NOT NULL DEFAULT false,
|
|
21
|
+
"wakeAt" TIMESTAMP(3),
|
|
22
|
+
"firstSeq" INTEGER NOT NULL DEFAULT 1,
|
|
23
|
+
"deletedAt" TIMESTAMP(3),
|
|
24
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
25
|
+
"updatedAt" TIMESTAMP(3) NOT NULL,
|
|
26
|
+
|
|
27
|
+
CONSTRAINT "harness_log_headers_pkey" PRIMARY KEY ("logId")
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
-- CreateTable:LogStore 追加记录((logId, seq) 主键)
|
|
31
|
+
CREATE TABLE "harness_log_entries" (
|
|
32
|
+
"logId" TEXT NOT NULL,
|
|
33
|
+
"seq" INTEGER NOT NULL,
|
|
34
|
+
"record" JSONB NOT NULL,
|
|
35
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
36
|
+
|
|
37
|
+
CONSTRAINT "harness_log_entries_pkey" PRIMARY KEY ("logId","seq")
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
-- CreateTable:LogStore 输入通道 offer
|
|
41
|
+
CREATE TABLE "harness_log_offers" (
|
|
42
|
+
"id" TEXT NOT NULL,
|
|
43
|
+
"logId" TEXT NOT NULL,
|
|
44
|
+
"inputId" TEXT NOT NULL,
|
|
45
|
+
"record" JSONB NOT NULL,
|
|
46
|
+
"offeredAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
47
|
+
"consumedAt" TIMESTAMP(3),
|
|
48
|
+
|
|
49
|
+
CONSTRAINT "harness_log_offers_pkey" PRIMARY KEY ("id")
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
-- CreateTable:LogStore 最新快照
|
|
53
|
+
CREATE TABLE "harness_log_snapshots" (
|
|
54
|
+
"logId" TEXT NOT NULL,
|
|
55
|
+
"seq" INTEGER NOT NULL,
|
|
56
|
+
"version" TEXT NOT NULL,
|
|
57
|
+
"state" JSONB NOT NULL,
|
|
58
|
+
"updatedAt" TIMESTAMP(3) NOT NULL,
|
|
59
|
+
|
|
60
|
+
CONSTRAINT "harness_log_snapshots_pkey" PRIMARY KEY ("logId")
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
-- CreateTable:host 心跳
|
|
64
|
+
CREATE TABLE "harness_host_heartbeats" (
|
|
65
|
+
"hostId" TEXT NOT NULL,
|
|
66
|
+
"lastSeenAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
67
|
+
"expiresAt" TIMESTAMP(3) NOT NULL,
|
|
68
|
+
"updatedAt" TIMESTAMP(3) NOT NULL,
|
|
69
|
+
|
|
70
|
+
CONSTRAINT "harness_host_heartbeats_pkey" PRIMARY KEY ("hostId")
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
-- CreateTable:MetadataStore((namespace, key) 复合主键,version 作 CAS)
|
|
74
|
+
CREATE TABLE "harness_metadata" (
|
|
75
|
+
"namespace" TEXT NOT NULL,
|
|
76
|
+
"key" TEXT NOT NULL,
|
|
77
|
+
"value" JSONB NOT NULL,
|
|
78
|
+
"version" INTEGER NOT NULL DEFAULT 0,
|
|
79
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
80
|
+
"updatedAt" TIMESTAMP(3) NOT NULL,
|
|
81
|
+
|
|
82
|
+
CONSTRAINT "harness_metadata_pkey" PRIMARY KEY ("namespace","key")
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
-- CreateTable:BlobStore(字节;无用户/线程外键)
|
|
86
|
+
CREATE TABLE "harness_blobs" (
|
|
87
|
+
"key" TEXT NOT NULL,
|
|
88
|
+
"bytes" BYTEA NOT NULL,
|
|
89
|
+
"size" INTEGER NOT NULL,
|
|
90
|
+
"contentType" TEXT,
|
|
91
|
+
"etag" TEXT,
|
|
92
|
+
"customMetadata" JSONB,
|
|
93
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
94
|
+
"updatedAt" TIMESTAMP(3) NOT NULL,
|
|
95
|
+
|
|
96
|
+
CONSTRAINT "harness_blobs_pkey" PRIMARY KEY ("key")
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
-- CreateTable:ArtifactStore(元数据;无 GenerationRun 外键)
|
|
100
|
+
CREATE TABLE "harness_artifacts" (
|
|
101
|
+
"artifactId" TEXT NOT NULL,
|
|
102
|
+
"runId" TEXT NOT NULL,
|
|
103
|
+
"threadId" TEXT NOT NULL,
|
|
104
|
+
"blobKey" TEXT NOT NULL,
|
|
105
|
+
"name" TEXT NOT NULL,
|
|
106
|
+
"mimeType" TEXT NOT NULL,
|
|
107
|
+
"size" INTEGER NOT NULL,
|
|
108
|
+
"sourceUrl" TEXT,
|
|
109
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
110
|
+
|
|
111
|
+
CONSTRAINT "harness_artifacts_pkey" PRIMARY KEY ("artifactId")
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
-- CreateTable:SessionIndexStore 载体(独立表;复合主键 (tenantId, threadId))
|
|
115
|
+
CREATE TABLE "harness_sessions" (
|
|
116
|
+
"tenantId" TEXT NOT NULL DEFAULT '',
|
|
117
|
+
"threadId" TEXT NOT NULL,
|
|
118
|
+
"harness" TEXT,
|
|
119
|
+
"title" TEXT,
|
|
120
|
+
"parentThreadId" TEXT,
|
|
121
|
+
"parentToolCallId" TEXT,
|
|
122
|
+
"createdAt" DOUBLE PRECISION NOT NULL,
|
|
123
|
+
"updatedAt" DOUBLE PRECISION NOT NULL,
|
|
124
|
+
"revision" INTEGER NOT NULL DEFAULT 0,
|
|
125
|
+
"members" JSONB,
|
|
126
|
+
"pinned" BOOLEAN,
|
|
127
|
+
"archived" BOOLEAN,
|
|
128
|
+
"usage" JSONB,
|
|
129
|
+
"metadata" JSONB,
|
|
130
|
+
|
|
131
|
+
CONSTRAINT "harness_sessions_pkey" PRIMARY KEY ("tenantId","threadId")
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
-- CreateIndex
|
|
135
|
+
CREATE INDEX "harness_log_offers_logId_consumedAt_idx" ON "harness_log_offers"("logId", "consumedAt");
|
|
136
|
+
|
|
137
|
+
-- CreateIndex
|
|
138
|
+
CREATE UNIQUE INDEX "harness_log_offers_logId_inputId_key" ON "harness_log_offers"("logId", "inputId");
|
|
139
|
+
|
|
140
|
+
-- CreateIndex
|
|
141
|
+
CREATE INDEX "harness_artifacts_runId_createdAt_idx" ON "harness_artifacts"("runId", "createdAt");
|
|
142
|
+
|
|
143
|
+
-- CreateIndex
|
|
144
|
+
CREATE INDEX "harness_artifacts_threadId_createdAt_idx" ON "harness_artifacts"("threadId", "createdAt");
|
|
145
|
+
|
|
146
|
+
-- CreateIndex
|
|
147
|
+
CREATE INDEX "harness_sessions_tenantId_updatedAt_threadId_idx" ON "harness_sessions"("tenantId", "updatedAt", "threadId");
|
|
148
|
+
|
|
149
|
+
-- AddForeignKey
|
|
150
|
+
ALTER TABLE "harness_log_entries" ADD CONSTRAINT "harness_log_entries_logId_fkey" FOREIGN KEY ("logId") REFERENCES "harness_log_headers"("logId") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
151
|
+
|
|
152
|
+
-- AddForeignKey
|
|
153
|
+
ALTER TABLE "harness_log_offers" ADD CONSTRAINT "harness_log_offers_logId_fkey" FOREIGN KEY ("logId") REFERENCES "harness_log_headers"("logId") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
154
|
+
|
|
155
|
+
-- AddForeignKey
|
|
156
|
+
ALTER TABLE "harness_log_snapshots" ADD CONSTRAINT "harness_log_snapshots_logId_fkey" FOREIGN KEY ("logId") REFERENCES "harness_log_headers"("logId") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
-- harness CAS tombstone(再验收 P1-1):SessionIndexStore/MetadataStore 的
|
|
2
|
+
-- revision/version 此前按「行不存在即从 1 重来」计数且 delete 硬删行——重建后
|
|
3
|
+
-- revision 复用,违反官方契约「a revision does not come back after a delete」
|
|
4
|
+
-- (pre-delete 持旧 revision 的陈旧写入者可在 delete+重建后通过 setIf/upsertIf)。
|
|
5
|
+
-- 改为 tombstone:delete 置位 deletedAt(行保留、revision 不动),读路径过滤,
|
|
6
|
+
-- 重建清位并 revision+1——版本号单调跨 delete 永不复用。
|
|
7
|
+
|
|
8
|
+
-- AlterTable
|
|
9
|
+
ALTER TABLE "harness_sessions" ADD COLUMN "deletedAt" TIMESTAMP(3);
|
|
10
|
+
|
|
11
|
+
-- AlterTable
|
|
12
|
+
ALTER TABLE "harness_metadata" ADD COLUMN "deletedAt" TIMESTAMP(3);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@allbluecn/database",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.3",
|
|
4
4
|
"license": "AGPL-3.0-or-later",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.ts",
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"exports": {
|
|
26
26
|
".": "./index.ts",
|
|
27
27
|
"./get-prisma": "./get-prisma.ts",
|
|
28
|
+
"./pg-client": "./pg-client.ts",
|
|
28
29
|
"./pglite-init": "./pglite-init.ts",
|
|
29
30
|
"./pglite-seed": "./pglite-seed.ts",
|
|
30
31
|
"./cf-env": "./cf-env.ts",
|
|
@@ -52,6 +53,7 @@
|
|
|
52
53
|
"pglite-seed.ts",
|
|
53
54
|
"index.ts",
|
|
54
55
|
"get-prisma.ts",
|
|
56
|
+
"pg-client.ts",
|
|
55
57
|
"cf-env.ts",
|
|
56
58
|
"cf-env-stub.ts",
|
|
57
59
|
"cloudflare-workers.d.ts"
|
package/pg-client.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
|
+
// AllBlue - 理想之海
|
|
3
|
+
//
|
|
4
|
+
// 按连接串构建 PrismaClient(PostgreSQL / PrismaPg adapter)。
|
|
5
|
+
// 供需要「非默认连接」的调用方使用——典型:测试/压测在**独立 schema 或独立库**里
|
|
6
|
+
// 跑隔离后端(官方 conformance testkit 假定空后端,且与业务表共享时会互踩)。
|
|
7
|
+
// 默认单例见 index.ts 的 `prisma`;本工厂不缓存、每次新建,调用方负责 disconnect。
|
|
8
|
+
|
|
9
|
+
import { PrismaPg } from "@prisma/adapter-pg";
|
|
10
|
+
import { PrismaClient } from "./generated/client.ts";
|
|
11
|
+
|
|
12
|
+
/** 新建一个绑定给定连接串的 PrismaClient(PostgreSQL)。 */
|
|
13
|
+
export function createPgClient(connectionString: string): PrismaClient {
|
|
14
|
+
const adapter = new PrismaPg({
|
|
15
|
+
connectionString,
|
|
16
|
+
max: 5,
|
|
17
|
+
idleTimeoutMillis: 30_000,
|
|
18
|
+
connectionTimeoutMillis: 20_000,
|
|
19
|
+
});
|
|
20
|
+
return new PrismaClient({ adapter, log: ["error"] });
|
|
21
|
+
}
|
package/schema.prisma
CHANGED
|
@@ -367,8 +367,16 @@ model ChatThread {
|
|
|
367
367
|
engine String @default("cloud")
|
|
368
368
|
/// 本地 Agent 的授权工作目录(engine=local 时必填;仅桌面壳)
|
|
369
369
|
localCwd String?
|
|
370
|
-
/// 本地 agent 选择(engine=local 时):'
|
|
370
|
+
/// 本地 agent 选择(engine=local 时):'acp:<catalogId>';null = 未选择
|
|
371
|
+
/// (pi 内置引擎已剥离,T3.1/#643——存量 'pi' 行为脏数据,按 D13 手动清理)
|
|
371
372
|
localAgentId String?
|
|
373
|
+
/// harness 会话桥接预留(Phase 2 T2.7):会话索引 CAS 版本号与扩展元数据。
|
|
374
|
+
/// 注意:conformance 级 SessionIndexStore 载体是独立表 HarnessSession(见该模型注释,
|
|
375
|
+
/// 因官方 testkit 要求同 threadId 跨 tenant 两条 entry + members 可空 + epoch ms 精确
|
|
376
|
+
/// round-trip,ChatThread 单列主键 + userId NOT NULL + DateTime 无法满足);
|
|
377
|
+
/// 此二列供 Phase 2 侧栏 conversations serverFn 与 harness 会话桥接时做乐观并发与扩展字段。
|
|
378
|
+
indexRevision Int @default(0)
|
|
379
|
+
indexMetadata Json?
|
|
372
380
|
|
|
373
381
|
@@index([userId, updatedAt])
|
|
374
382
|
@@map("chat_threads")
|
|
@@ -3157,9 +3165,197 @@ model DesignEmbedding {
|
|
|
3157
3165
|
id String @id
|
|
3158
3166
|
content String
|
|
3159
3167
|
designPageId String?
|
|
3168
|
+
documentId String?
|
|
3160
3169
|
chunkIndex Int?
|
|
3161
3170
|
embedding Unsupported("vector(1536)")
|
|
3162
3171
|
|
|
3163
3172
|
@@index([designPageId])
|
|
3164
3173
|
@@map("design_embeddings")
|
|
3165
3174
|
}
|
|
3175
|
+
|
|
3176
|
+
// ── Harness 持久化(Phase 1,六 store 的 Prisma 载体;PG + PGlite 同方言)──────────
|
|
3177
|
+
// 官方契约真源:@tanstack/ai-persistence@1.0.1 dist/esm/types.d.ts(LogStore 15 方法、
|
|
3178
|
+
// SessionIndexStore CAS、MetadataStore getVersioned/setIf、BlobStore Range、ArtifactStore)。
|
|
3179
|
+
// 设计:docs/superpowers/specs/2026-11-07-harness-tanstack-native-redesign.md §4。
|
|
3180
|
+
|
|
3181
|
+
/// LogStore 的所有权/截断/亲和头(每 log 一行)。
|
|
3182
|
+
/// epoch 单调递增(永不下降),是 fencing 的依据;ownerId/ownerExpiresAt/released 构成
|
|
3183
|
+
/// 所有权租约;firstSeq 是截断点(truncate 后上移);deletedAt 是墓碑(删除后所有 fenced
|
|
3184
|
+
/// 写与 offerInput 拒绝,直到下次 acquireOwnership 重新打开)。epoch 计数器在 deleteLog
|
|
3185
|
+
/// 后仍保留。append 用事务 + 本行 SELECT … FOR UPDATE 锁,保证 seq 单调与 offer 消费原子。
|
|
3186
|
+
model HarnessLogHeader {
|
|
3187
|
+
logId String @id
|
|
3188
|
+
/// 运行该 log 的 harness 名(acquireOwnership 写入;首次 offer 时若为空则补)
|
|
3189
|
+
harness String?
|
|
3190
|
+
/// 该 log 被钉到的 host(= hostId);pinToWorkers 写、null 解钉
|
|
3191
|
+
affinity String?
|
|
3192
|
+
/// 所有权纪元,单调递增永不下降(fencing);NO_OWNER_EPOCH = 0
|
|
3193
|
+
epoch Int @default(0)
|
|
3194
|
+
ownerId String?
|
|
3195
|
+
/// 租约到期时刻(存储时钟 = DB now() + ttlMs)
|
|
3196
|
+
ownerExpiresAt DateTime?
|
|
3197
|
+
released Boolean @default(false)
|
|
3198
|
+
/// releaseOwnership({ wakeInMs }) 设置的唤醒时刻
|
|
3199
|
+
wakeAt DateTime?
|
|
3200
|
+
/// 截断点:第一条仍保留记录的位置(默认 1;truncate 上移,seq 计数不回退)
|
|
3201
|
+
firstSeq Int @default(1)
|
|
3202
|
+
/// 墓碑时刻;非空表示 log 已删除
|
|
3203
|
+
deletedAt DateTime?
|
|
3204
|
+
createdAt DateTime @default(now())
|
|
3205
|
+
updatedAt DateTime @updatedAt
|
|
3206
|
+
|
|
3207
|
+
entries HarnessLogEntry[]
|
|
3208
|
+
offers HarnessLogOffer[]
|
|
3209
|
+
snapshot HarnessLogSnapshot?
|
|
3210
|
+
|
|
3211
|
+
@@map("harness_log_headers")
|
|
3212
|
+
}
|
|
3213
|
+
|
|
3214
|
+
/// LogStore 的追加记录((logId, seq) 主键;seq 从 1 单调递增,record 为 JSONB)。
|
|
3215
|
+
model HarnessLogEntry {
|
|
3216
|
+
logId String
|
|
3217
|
+
seq Int
|
|
3218
|
+
record Json
|
|
3219
|
+
createdAt DateTime @default(now())
|
|
3220
|
+
|
|
3221
|
+
header HarnessLogHeader @relation(fields: [logId], references: [logId], onDelete: Cascade)
|
|
3222
|
+
|
|
3223
|
+
@@id([logId, seq])
|
|
3224
|
+
@@map("harness_log_entries")
|
|
3225
|
+
}
|
|
3226
|
+
|
|
3227
|
+
/// LogStore 的输入通道 offer(pending input;任意机器可 offer,仅 owner 经 append({consumes}) 消费)。
|
|
3228
|
+
/// inputId 在一个 log 内唯一;consumedAt 非空表示已被消费(id 保留 → 重试同 payload =
|
|
3229
|
+
/// duplicate,异 payload = conflict)。
|
|
3230
|
+
model HarnessLogOffer {
|
|
3231
|
+
id String @id @default(cuid())
|
|
3232
|
+
logId String
|
|
3233
|
+
inputId String
|
|
3234
|
+
record Json
|
|
3235
|
+
offeredAt DateTime @default(now())
|
|
3236
|
+
consumedAt DateTime?
|
|
3237
|
+
|
|
3238
|
+
header HarnessLogHeader @relation(fields: [logId], references: [logId], onDelete: Cascade)
|
|
3239
|
+
|
|
3240
|
+
@@unique([logId, inputId])
|
|
3241
|
+
@@index([logId, consumedAt])
|
|
3242
|
+
@@map("harness_log_offers")
|
|
3243
|
+
}
|
|
3244
|
+
|
|
3245
|
+
/// LogStore 的最新快照(每 log 至多一条;putSnapshot 整体替换)。
|
|
3246
|
+
model HarnessLogSnapshot {
|
|
3247
|
+
logId String @id
|
|
3248
|
+
seq Int
|
|
3249
|
+
version String
|
|
3250
|
+
state Json
|
|
3251
|
+
updatedAt DateTime @updatedAt
|
|
3252
|
+
|
|
3253
|
+
header HarnessLogHeader @relation(fields: [logId], references: [logId], onDelete: Cascade)
|
|
3254
|
+
|
|
3255
|
+
@@map("harness_log_snapshots")
|
|
3256
|
+
}
|
|
3257
|
+
|
|
3258
|
+
/// host 心跳(markHostAlive)。affinity 钉住的 host 仅在其心跳未过期时才算“活”,
|
|
3259
|
+
/// 故 owner 到期接管 / listLogsWithoutOwner 需联查本表判断 affinity host 是否仍活。
|
|
3260
|
+
model HarnessHostHeartbeat {
|
|
3261
|
+
hostId String @id
|
|
3262
|
+
lastSeenAt DateTime @default(now())
|
|
3263
|
+
/// lastSeenAt + ttlMs(存储时钟),供 affinity host 活性判断
|
|
3264
|
+
expiresAt DateTime
|
|
3265
|
+
updatedAt DateTime @updatedAt
|
|
3266
|
+
|
|
3267
|
+
@@map("harness_host_heartbeats")
|
|
3268
|
+
}
|
|
3269
|
+
|
|
3270
|
+
/// MetadataStore((namespace, key) 复合主键)。version 每次写(含 set)递增,作 CAS
|
|
3271
|
+
/// revision(getVersioned/setIf 成对实现);delete 后行移除,revision 不复返。
|
|
3272
|
+
/// 与 /api/chat 链的 ChatPersistenceMeta 隔离;决定 permissions 'always' 规则持久化。
|
|
3273
|
+
model HarnessMetadata {
|
|
3274
|
+
namespace String
|
|
3275
|
+
key String
|
|
3276
|
+
value Json
|
|
3277
|
+
version Int @default(0)
|
|
3278
|
+
/// CAS tombstone(软删标记):同 HarnessSession.deletedAt——version 单调跨
|
|
3279
|
+
/// delete 不复用(官方契约「a revision does not come back after a delete」)
|
|
3280
|
+
deletedAt DateTime?
|
|
3281
|
+
createdAt DateTime @default(now())
|
|
3282
|
+
updatedAt DateTime @updatedAt
|
|
3283
|
+
|
|
3284
|
+
@@id([namespace, key])
|
|
3285
|
+
@@map("harness_metadata")
|
|
3286
|
+
}
|
|
3287
|
+
|
|
3288
|
+
/// BlobStore(字节)。key 主键,**无用户/线程外键**(官方契约按调用方 key 存取,
|
|
3289
|
+
/// 不能复用带 userId 非空外键的 Blob 表)。bytes = PG bytea;get 支持 Range。
|
|
3290
|
+
/// 桌面 media.maxBytes 建议下调到 20MB(bytea 不宜存大对象)。
|
|
3291
|
+
model HarnessBlob {
|
|
3292
|
+
key String @id
|
|
3293
|
+
bytes Bytes
|
|
3294
|
+
size Int
|
|
3295
|
+
contentType String?
|
|
3296
|
+
etag String?
|
|
3297
|
+
customMetadata Json?
|
|
3298
|
+
createdAt DateTime @default(now())
|
|
3299
|
+
updatedAt DateTime @updatedAt
|
|
3300
|
+
|
|
3301
|
+
@@map("harness_blobs")
|
|
3302
|
+
}
|
|
3303
|
+
|
|
3304
|
+
/// ArtifactStore(媒体/工具产物元数据;字节落在 HarnessBlob.blobKey)。
|
|
3305
|
+
/// **无 GenerationRun 外键**——子代理线程 `<root>/agent/<runId>` 不是 ChatThread/
|
|
3306
|
+
/// GenerationRun 行,写入 GenerationRun 还会污染画廊。
|
|
3307
|
+
model HarnessArtifact {
|
|
3308
|
+
artifactId String @id
|
|
3309
|
+
runId String
|
|
3310
|
+
threadId String
|
|
3311
|
+
blobKey String
|
|
3312
|
+
name String
|
|
3313
|
+
mimeType String
|
|
3314
|
+
size Int
|
|
3315
|
+
sourceUrl String?
|
|
3316
|
+
createdAt DateTime @default(now())
|
|
3317
|
+
|
|
3318
|
+
@@index([runId, createdAt])
|
|
3319
|
+
@@index([threadId, createdAt])
|
|
3320
|
+
@@map("harness_artifacts")
|
|
3321
|
+
}
|
|
3322
|
+
|
|
3323
|
+
/// SessionIndexStore 载体(**独立表**)。
|
|
3324
|
+
/// ⚠ 设计 §4 原拟“建在 ChatThread 上”,但官方 conformance testkit(types.d.ts 同源)要求:
|
|
3325
|
+
/// ① 同一 threadId 在两个 tenant 下是两条 entry(ChatThread.id 单列主键无法表达);
|
|
3326
|
+
/// ② members 可为空数组(子代理线程无 owner),与 ChatThread.userId NOT NULL 冲突;
|
|
3327
|
+
/// ③ createdAt/updatedAt 以精确 JS number(epoch ms)经 toEqual round-trip。
|
|
3328
|
+
/// 故按“以类型真源为准”以独立复合主键表实现;ChatThread 的单一真源绑定(侧栏
|
|
3329
|
+
/// conversations serverFn 与 harness sessions.* 读写同一行)移到 Phase 2 会话桥接(T2.7),
|
|
3330
|
+
/// ChatThread.indexRevision/indexMetadata 为该桥接预留。
|
|
3331
|
+
/// createdAt/updatedAt 存 epoch ms,用 Float(double)承载:Date.now() < 2^53 精确,小整数亦精确。
|
|
3332
|
+
model HarnessSession {
|
|
3333
|
+
tenantId String @default("")
|
|
3334
|
+
threadId String
|
|
3335
|
+
harness String?
|
|
3336
|
+
title String?
|
|
3337
|
+
parentThreadId String?
|
|
3338
|
+
parentToolCallId String?
|
|
3339
|
+
/// epoch ms(Float 承载,精确 round-trip)
|
|
3340
|
+
createdAt Float
|
|
3341
|
+
/// epoch ms(Float 承载;list 按 desc 排序,同值按 threadId 字节序 tie-break)
|
|
3342
|
+
updatedAt Float
|
|
3343
|
+
/// CAS 版本(getVersioned/upsertIf);每次写递增
|
|
3344
|
+
revision Int @default(0)
|
|
3345
|
+
/// CAS tombstone(软删标记):行保留使 revision 单调跨 delete——官方契约
|
|
3346
|
+
/// 「a revision does not come back after a delete」;读路径(get/getVersioned/list)
|
|
3347
|
+
/// 过滤 deletedAt 非空行,delete 置位、重建(写入)清位
|
|
3348
|
+
deletedAt DateTime?
|
|
3349
|
+
/// SessionMember[](可为空数组 = 无 owner,子代理线程)
|
|
3350
|
+
members Json?
|
|
3351
|
+
pinned Boolean?
|
|
3352
|
+
archived Boolean?
|
|
3353
|
+
/// SessionIndexEntry['usage']
|
|
3354
|
+
usage Json?
|
|
3355
|
+
/// 应用自有 metadata
|
|
3356
|
+
metadata Json?
|
|
3357
|
+
|
|
3358
|
+
@@id([tenantId, threadId])
|
|
3359
|
+
@@index([tenantId, updatedAt, threadId])
|
|
3360
|
+
@@map("harness_sessions")
|
|
3361
|
+
}
|