@undefineds.co/models 0.2.0 → 0.2.1

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 (241) hide show
  1. package/README.md +515 -125
  2. package/dist/agent.repository.d.ts +20 -40
  3. package/dist/agent.schema.d.ts +20 -1
  4. package/dist/agent.schema.js +25 -1
  5. package/dist/ai-config/index.d.ts +8 -6
  6. package/dist/ai-config/index.js +41 -23
  7. package/dist/ai-model.schema.d.ts +13 -1
  8. package/dist/ai-model.schema.js +17 -1
  9. package/dist/ai-provider.schema.d.ts +9 -1
  10. package/dist/ai-provider.schema.js +13 -1
  11. package/dist/approval.schema.d.ts +21 -1
  12. package/dist/approval.schema.js +33 -1
  13. package/dist/audit.schema.d.ts +17 -1
  14. package/dist/audit.schema.js +29 -1
  15. package/dist/chat.repository.d.ts +19 -15
  16. package/dist/chat.schema.d.ts +37 -1
  17. package/dist/chat.schema.js +47 -1
  18. package/dist/client/index.d.ts +121 -0
  19. package/dist/client/index.js +299 -0
  20. package/dist/contact.repository.d.ts +21 -21
  21. package/dist/contact.schema.d.ts +48 -1
  22. package/dist/contact.schema.js +60 -1
  23. package/dist/credential.schema.d.ts +15 -1
  24. package/dist/credential.schema.js +19 -1
  25. package/dist/discovery/index.d.ts +2 -2
  26. package/dist/discovery/index.js +2 -2
  27. package/dist/extension/extension.schema.d.ts +4 -1
  28. package/dist/extension/extension.schema.js +11 -1
  29. package/dist/extension/index.d.ts +1 -1
  30. package/dist/favorite/favorite.schema.d.ts +24 -1
  31. package/dist/favorite/favorite.schema.js +34 -1
  32. package/dist/favorite/index.d.ts +2 -2
  33. package/dist/file/file.schema.d.ts +39 -1
  34. package/dist/file/file.schema.js +51 -1
  35. package/dist/file/index.d.ts +1 -1
  36. package/dist/fixtures/contracts-chat-contact.d.ts +8 -8
  37. package/dist/fixtures/contracts-chat-contact.js +5 -9
  38. package/dist/grant.schema.d.ts +16 -1
  39. package/dist/grant.schema.js +29 -1
  40. package/dist/import/index.d.ts +1 -1
  41. package/dist/inbox-notification.schema.d.ts +9 -1
  42. package/dist/inbox-notification.schema.js +16 -1
  43. package/dist/index.d.ts +42 -43
  44. package/dist/index.js +27 -26
  45. package/dist/knowledge/index.d.ts +1 -1
  46. package/dist/knowledge/knowledge-folder.schema.d.ts +7 -1
  47. package/dist/knowledge/knowledge-folder.schema.js +6 -1
  48. package/dist/message.repository.d.ts +20 -20
  49. package/dist/message.schema.d.ts +32 -1
  50. package/dist/message.schema.js +47 -1
  51. package/dist/namespaces.d.ts +178 -1
  52. package/dist/namespaces.js +253 -1
  53. package/dist/profile.d.ts +22 -1
  54. package/dist/profile.js +88 -1
  55. package/dist/profile.repository.d.ts +105 -0
  56. package/dist/profile.repository.js +47 -0
  57. package/dist/profile.schema.d.ts +16 -0
  58. package/dist/{core/profile.js → profile.schema.js} +4 -4
  59. package/dist/repository.d.ts +49 -9
  60. package/dist/repository.js +49 -46
  61. package/dist/schema.d.ts +244 -1
  62. package/dist/schema.js +37 -1
  63. package/dist/session/index.d.ts +1 -1
  64. package/dist/session/index.js +1 -1
  65. package/dist/session/session.schema.d.ts +43 -1
  66. package/dist/session/session.schema.js +46 -1
  67. package/dist/session.repository.d.ts +61 -0
  68. package/dist/session.repository.js +8 -0
  69. package/dist/settings/index.d.ts +1 -1
  70. package/dist/settings/settings.schema.d.ts +49 -1
  71. package/dist/settings/settings.schema.js +63 -1
  72. package/dist/{governance/runtime-projections.d.ts → sidecar/persistence-mapping.d.ts} +7 -7
  73. package/dist/{governance/runtime-projections.js → sidecar/persistence-mapping.js} +7 -1
  74. package/dist/{protocols/runtime-events.d.ts → sidecar/sidecar-events.d.ts} +35 -35
  75. package/dist/{protocols/runtime-events.js → sidecar/sidecar-events.js} +21 -4
  76. package/dist/thread.repository.d.ts +15 -19
  77. package/dist/thread.schema.d.ts +30 -1
  78. package/dist/thread.schema.js +39 -1
  79. package/dist/{core/types/collaboration-rich-content.d.ts → types/collaboration-blocks.d.ts} +7 -7
  80. package/dist/types/collaboration-blocks.js +7 -0
  81. package/dist/types/message-block.d.ts +270 -0
  82. package/dist/types/message-block.js +125 -0
  83. package/dist/vocab/_namespaces.d.ts +1 -1
  84. package/dist/vocab/index.d.ts +5 -6
  85. package/dist/vocab/index.js +0 -1
  86. package/dist/vocab/message.vocab.js +1 -1
  87. package/dist/vocab/thread.vocab.d.ts +1 -2
  88. package/dist/vocab/thread.vocab.js +2 -3
  89. package/dist/watch/index.d.ts +226 -0
  90. package/dist/watch/index.js +1156 -0
  91. package/package.json +41 -39
  92. package/dist/_drizzle-solid/columns.d.ts +0 -37
  93. package/dist/_drizzle-solid/columns.js +0 -1
  94. package/dist/_drizzle-solid/pod-table.d.ts +0 -3
  95. package/dist/_drizzle-solid/pod-table.js +0 -1
  96. package/dist/_drizzle-solid/types.d.ts +0 -40
  97. package/dist/_drizzle-solid/types.js +0 -1
  98. package/dist/ai-config.d.ts +0 -1
  99. package/dist/ai-config.js +0 -1
  100. package/dist/chat.utils.d.ts +0 -3
  101. package/dist/chat.utils.js +0 -30
  102. package/dist/core/agent-provider.schema.d.ts +0 -1
  103. package/dist/core/agent-provider.schema.js +0 -1
  104. package/dist/core/agent-status.schema.d.ts +0 -12
  105. package/dist/core/agent-status.schema.js +0 -18
  106. package/dist/core/agent.schema.d.ts +0 -72
  107. package/dist/core/agent.schema.js +0 -38
  108. package/dist/core/ai-config.schema.d.ts +0 -11
  109. package/dist/core/ai-config.schema.js +0 -18
  110. package/dist/core/ai-model.schema.d.ts +0 -15
  111. package/dist/core/ai-model.schema.js +0 -21
  112. package/dist/core/ai-provider.schema.d.ts +0 -16
  113. package/dist/core/ai-provider.schema.js +0 -28
  114. package/dist/core/approval.schema.d.ts +0 -21
  115. package/dist/core/approval.schema.js +0 -33
  116. package/dist/core/audit.schema.d.ts +0 -17
  117. package/dist/core/audit.schema.js +0 -29
  118. package/dist/core/chat.schema.d.ts +0 -36
  119. package/dist/core/chat.schema.js +0 -45
  120. package/dist/core/contact.schema.d.ts +0 -47
  121. package/dist/core/contact.schema.js +0 -59
  122. package/dist/core/credential.schema.d.ts +0 -56
  123. package/dist/core/credential.schema.js +0 -40
  124. package/dist/core/extension/extension.schema.d.ts +0 -4
  125. package/dist/core/extension/extension.schema.js +0 -11
  126. package/dist/core/extension/index.d.ts +0 -1
  127. package/dist/core/extension/index.js +0 -1
  128. package/dist/core/extension.d.ts +0 -1
  129. package/dist/core/extension.js +0 -1
  130. package/dist/core/favorite/favorite.schema.d.ts +0 -24
  131. package/dist/core/favorite/favorite.schema.js +0 -34
  132. package/dist/core/favorite/index.d.ts +0 -1
  133. package/dist/core/favorite/index.js +0 -1
  134. package/dist/core/file/file.schema.d.ts +0 -39
  135. package/dist/core/file/file.schema.js +0 -51
  136. package/dist/core/file/index.d.ts +0 -1
  137. package/dist/core/file/index.js +0 -1
  138. package/dist/core/file.d.ts +0 -1
  139. package/dist/core/file.js +0 -1
  140. package/dist/core/grant.schema.d.ts +0 -16
  141. package/dist/core/grant.schema.js +0 -29
  142. package/dist/core/import/import-job.schema.d.ts +0 -5
  143. package/dist/core/import/import-job.schema.js +0 -5
  144. package/dist/core/import/index.d.ts +0 -1
  145. package/dist/core/import/index.js +0 -1
  146. package/dist/core/import.d.ts +0 -1
  147. package/dist/core/import.js +0 -1
  148. package/dist/core/inbox-notification.schema.d.ts +0 -9
  149. package/dist/core/inbox-notification.schema.js +0 -16
  150. package/dist/core/index.d.ts +0 -31
  151. package/dist/core/index.js +0 -32
  152. package/dist/core/knowledge/index.d.ts +0 -1
  153. package/dist/core/knowledge/index.js +0 -1
  154. package/dist/core/knowledge/knowledge-folder.schema.d.ts +0 -7
  155. package/dist/core/knowledge/knowledge-folder.schema.js +0 -6
  156. package/dist/core/knowledge.d.ts +0 -1
  157. package/dist/core/knowledge.js +0 -1
  158. package/dist/core/message.schema.d.ts +0 -33
  159. package/dist/core/message.schema.js +0 -49
  160. package/dist/core/namespaces.d.ts +0 -176
  161. package/dist/core/namespaces.js +0 -289
  162. package/dist/core/profile.d.ts +0 -16
  163. package/dist/core/schema.d.ts +0 -304
  164. package/dist/core/schema.js +0 -46
  165. package/dist/core/session/index.d.ts +0 -1
  166. package/dist/core/session/index.js +0 -1
  167. package/dist/core/session/session.schema.d.ts +0 -6
  168. package/dist/core/session/session.schema.js +0 -6
  169. package/dist/core/session.d.ts +0 -1
  170. package/dist/core/session.js +0 -1
  171. package/dist/core/settings/index.d.ts +0 -1
  172. package/dist/core/settings/index.js +0 -1
  173. package/dist/core/settings/settings.schema.d.ts +0 -49
  174. package/dist/core/settings/settings.schema.js +0 -63
  175. package/dist/core/settings.d.ts +0 -1
  176. package/dist/core/settings.js +0 -1
  177. package/dist/core/thread.schema.d.ts +0 -28
  178. package/dist/core/thread.schema.js +0 -36
  179. package/dist/core/types/collaboration-rich-content.js +0 -7
  180. package/dist/core/types/message-rich-content.d.ts +0 -121
  181. package/dist/core/types/message-rich-content.js +0 -85
  182. package/dist/core/vector-store.schema.d.ts +0 -25
  183. package/dist/core/vector-store.schema.js +0 -35
  184. package/dist/core/vocab/_namespaces.d.ts +0 -1
  185. package/dist/core/vocab/_namespaces.js +0 -3
  186. package/dist/core/vocab/chat.vocab.d.ts +0 -16
  187. package/dist/core/vocab/chat.vocab.js +0 -22
  188. package/dist/core/vocab/contact.vocab.d.ts +0 -21
  189. package/dist/core/vocab/contact.vocab.js +0 -22
  190. package/dist/core/vocab/index.d.ts +0 -6
  191. package/dist/core/vocab/index.js +0 -6
  192. package/dist/core/vocab/message.vocab.d.ts +0 -20
  193. package/dist/core/vocab/message.vocab.js +0 -24
  194. package/dist/core/vocab/thread.vocab.d.ts +0 -11
  195. package/dist/core/vocab/thread.vocab.js +0 -14
  196. package/dist/core/vocab/workspace.vocab.d.ts +0 -12
  197. package/dist/core/vocab/workspace.vocab.js +0 -13
  198. package/dist/core/vocab.d.ts +0 -1
  199. package/dist/core/vocab.js +0 -1
  200. package/dist/core/workspace.schema.d.ts +0 -35
  201. package/dist/core/workspace.schema.js +0 -106
  202. package/dist/core.d.ts +0 -1
  203. package/dist/core.js +0 -1
  204. package/dist/discovery/vercel.d.ts +0 -25
  205. package/dist/discovery/vercel.js +0 -95
  206. package/dist/discovery.d.ts +0 -1
  207. package/dist/discovery.js +0 -1
  208. package/dist/extension.d.ts +0 -1
  209. package/dist/extension.js +0 -1
  210. package/dist/favorite.d.ts +0 -1
  211. package/dist/favorite.js +0 -1
  212. package/dist/file.d.ts +0 -1
  213. package/dist/file.js +0 -1
  214. package/dist/governance/index.d.ts +0 -1
  215. package/dist/governance/index.js +0 -1
  216. package/dist/import.d.ts +0 -1
  217. package/dist/import.js +0 -1
  218. package/dist/knowledge.d.ts +0 -1
  219. package/dist/knowledge.js +0 -1
  220. package/dist/protocols/index.d.ts +0 -1
  221. package/dist/protocols/index.js +0 -1
  222. package/dist/session.d.ts +0 -1
  223. package/dist/session.js +0 -1
  224. package/dist/settings.d.ts +0 -1
  225. package/dist/settings.js +0 -1
  226. package/dist/types/collaboration-rich-content.d.ts +0 -52
  227. package/dist/types/collaboration-rich-content.js +0 -7
  228. package/dist/types/message-rich-content.d.ts +0 -121
  229. package/dist/types/message-rich-content.js +0 -85
  230. package/dist/vocab/governance.vocab.d.ts +0 -46
  231. package/dist/vocab/governance.vocab.js +0 -47
  232. package/dist/vocab/workspace.vocab.d.ts +0 -12
  233. package/dist/vocab/workspace.vocab.js +0 -13
  234. package/dist/vocab.d.ts +0 -1
  235. package/dist/vocab.js +0 -1
  236. package/dist/workspace.repository.d.ts +0 -45
  237. package/dist/workspace.repository.js +0 -8
  238. package/dist/workspace.schema.d.ts +0 -1
  239. package/dist/workspace.schema.js +0 -1
  240. /package/dist/{core/vocab/governance.vocab.d.ts → vocab/sidecar.vocab.d.ts} +0 -0
  241. /package/dist/{core/vocab/governance.vocab.js → vocab/sidecar.vocab.js} +0 -0
@@ -1 +1,39 @@
1
- export { threadTable, } from './core.js';
1
+ import { uri, boolean, object, podTable, string, timestamp, id } from '@undefineds.co/drizzle-solid';
2
+ import { UDFS, DCTerms, SIOC, LINX_CHAT } from './namespaces.js';
3
+ /**
4
+ * Thread schema.
5
+ *
6
+ * CP0 baseline:
7
+ * - Chat is a pure channel/place.
8
+ * - Thread carries execution context needed for collaboration/audit.
9
+ *
10
+ * Storage structure (aligned with xpod):
11
+ * - Thread stored as fragment in Chat's index.ttl
12
+ * - Location: /.data/chat/{chat}/index.ttl#{id}
13
+ *
14
+ * NOTE:
15
+ * - `thread.workspace` is a storage-layer reference (URI) to a container/resource in CSS/Pod.
16
+ * - It is NOT the same thing as the runtime create API payload `workspace: { path, copy }`.
17
+ * - Runtime path/copy is an execution-time interface shape; persistence should keep the
18
+ * container URI here and store portable metadata with that container/resource.
19
+ */
20
+ export const threadTable = podTable('thread', {
21
+ id: id('id'),
22
+ // Belongs to chat. Stored as an RDF URI; short ids are resolved via chatTable's URI template by the ORM.
23
+ chat: uri('chat').predicate(SIOC.has_parent).notNull().link('chats'),
24
+ // Display / state
25
+ title: string('title').predicate(DCTerms.title),
26
+ starred: boolean('starred').predicate(UDFS.favorite).default(false),
27
+ // Storage-layer execution context reference: container/resource URI
28
+ workspace: uri('workspace').predicate(LINX_CHAT.workspace),
29
+ // Generic execution metadata shared by CLI/App runtimes.
30
+ metadata: object('metadata').predicate(UDFS.metadata),
31
+ createdAt: timestamp('createdAt').predicate(DCTerms.created).notNull().defaultNow(),
32
+ updatedAt: timestamp('updatedAt').predicate(DCTerms.modified).notNull().defaultNow(),
33
+ }, {
34
+ base: '/.data/chat/',
35
+ sparqlEndpoint: '/.data/chat/-/sparql',
36
+ type: SIOC.Thread,
37
+ namespace: UDFS,
38
+ subjectTemplate: '{chat}/index.ttl#{id}',
39
+ });
@@ -1,12 +1,12 @@
1
1
  /**
2
- * Wave A CP0: collaboration-related rich content items.
2
+ * Wave A CP0: collaboration-related richContent block contracts.
3
3
  *
4
- * These are data contracts stored in `MessageRow.richContent.items`.
5
- * They intentionally omit presentation/runtime wrapper fields.
4
+ * These are minimal JSON shapes stored in MessageRow.richContent and consumed by downstream UIs.
5
+ * They intentionally do NOT include UI block runtime fields (id/createdAt/status, etc.).
6
6
  */
7
7
  export type ToolRisk = 'low' | 'medium' | 'high';
8
8
  export type ToolApprovalStatus = 'pending' | 'approved' | 'rejected' | 'auto_approved';
9
- export interface ToolApprovalRichContentItem {
9
+ export interface ToolApprovalBlock {
10
10
  type: 'tool_approval';
11
11
  toolCallId: string;
12
12
  toolName: string;
@@ -24,7 +24,7 @@ export interface ToolApprovalRichContentItem {
24
24
  inboxItemId?: string;
25
25
  }
26
26
  export type TaskProgressStepStatus = 'pending' | 'running' | 'done' | 'error' | 'skipped';
27
- export interface TaskProgressRichContentItem {
27
+ export interface TaskProgressBlock {
28
28
  type: 'task_progress';
29
29
  taskId: string;
30
30
  title: string;
@@ -39,7 +39,7 @@ export interface TaskProgressRichContentItem {
39
39
  totalSteps: number;
40
40
  }
41
41
  export type ToolCallStatus = 'calling' | 'waiting_approval' | 'running' | 'done' | 'error';
42
- export interface ToolCallRichContentItem {
42
+ export interface ToolCallBlock {
43
43
  type: 'tool';
44
44
  toolCallId: string;
45
45
  toolName: string;
@@ -49,4 +49,4 @@ export interface ToolCallRichContentItem {
49
49
  error?: string;
50
50
  duration?: number;
51
51
  }
52
- export type CollaborationRichContentItem = ToolApprovalRichContentItem | TaskProgressRichContentItem | ToolCallRichContentItem;
52
+ export type CollaborationRichBlock = ToolApprovalBlock | TaskProgressBlock | ToolCallBlock;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Wave A CP0: collaboration-related richContent block contracts.
3
+ *
4
+ * These are minimal JSON shapes stored in MessageRow.richContent and consumed by downstream UIs.
5
+ * They intentionally do NOT include UI block runtime fields (id/createdAt/status, etc.).
6
+ */
7
+ export {};
@@ -0,0 +1,270 @@
1
+ import type { ToolApprovalStatus, ToolCallStatus, TaskProgressStepStatus } from './collaboration-blocks';
2
+ /**
3
+ * Message Block Types - 基于 Cherry Studio 的 block-based 消息系统
4
+ *
5
+ * 将消息内容拆分为多个块(blocks),支持:
6
+ * - 主文本 (Markdown)
7
+ * - 思考过程 (CoT/Reasoning)
8
+ * - 工具调用
9
+ * - 图片/文件
10
+ * - 引用/搜索结果
11
+ * - 错误信息
12
+ */
13
+ export declare enum MessageBlockType {
14
+ /** 未知类型,用于流式响应开始前 */
15
+ UNKNOWN = "unknown",
16
+ /** 主要文本内容(Markdown) */
17
+ MAIN_TEXT = "main_text",
18
+ /** 思考过程(Claude、DeepSeek R1、OpenAI o-系列等) */
19
+ THINKING = "thinking",
20
+ /** 图片内容 */
21
+ IMAGE = "image",
22
+ /** 代码块(独立可运行) */
23
+ CODE = "code",
24
+ /** 工具调用及响应 */
25
+ TOOL = "tool",
26
+ /** 工具审批卡片 */
27
+ TOOL_APPROVAL = "tool_approval",
28
+ /** 任务进度卡片 */
29
+ TASK_PROGRESS = "task_progress",
30
+ /** 文件内容 */
31
+ FILE = "file",
32
+ /** 错误信息 */
33
+ ERROR = "error",
34
+ /** 引用类型(Web 搜索、知识库等) */
35
+ CITATION = "citation"
36
+ }
37
+ export declare enum MessageBlockStatus {
38
+ /** 等待处理 */
39
+ PENDING = "pending",
40
+ /** 正在处理,等待接收 */
41
+ PROCESSING = "processing",
42
+ /** 正在流式接收 */
43
+ STREAMING = "streaming",
44
+ /** 处理成功 */
45
+ SUCCESS = "success",
46
+ /** 处理错误 */
47
+ ERROR = "error",
48
+ /** 处理暂停 */
49
+ PAUSED = "paused"
50
+ }
51
+ export interface BaseMessageBlock {
52
+ /** 块 ID */
53
+ id: string;
54
+ /** 所属消息 ID */
55
+ messageId: string;
56
+ /** 块类型 */
57
+ type: MessageBlockType;
58
+ /** 创建时间 */
59
+ createdAt: string;
60
+ /** 更新时间 */
61
+ updatedAt?: string;
62
+ /** 块状态 */
63
+ status: MessageBlockStatus;
64
+ /** 使用的模型 */
65
+ model?: {
66
+ id: string;
67
+ name: string;
68
+ provider: string;
69
+ };
70
+ /** 通用元数据 */
71
+ metadata?: Record<string, unknown>;
72
+ /** 错误信息 */
73
+ error?: {
74
+ code?: string;
75
+ message: string;
76
+ details?: unknown;
77
+ };
78
+ }
79
+ export interface PlaceholderMessageBlock extends BaseMessageBlock {
80
+ type: MessageBlockType.UNKNOWN;
81
+ }
82
+ export interface MainTextMessageBlock extends BaseMessageBlock {
83
+ type: MessageBlockType.MAIN_TEXT;
84
+ /** Markdown 内容 */
85
+ content: string;
86
+ /** 关联的知识库 ID */
87
+ knowledgeBaseIds?: string[];
88
+ /** 引用参考 */
89
+ citationReferences?: Array<{
90
+ citationBlockId?: string;
91
+ url?: string;
92
+ title?: string;
93
+ }>;
94
+ }
95
+ export interface ThinkingMessageBlock extends BaseMessageBlock {
96
+ type: MessageBlockType.THINKING;
97
+ /** 思考内容 */
98
+ content: string;
99
+ /** 思考耗时(毫秒) */
100
+ thinkingDuration?: number;
101
+ }
102
+ export interface CodeMessageBlock extends BaseMessageBlock {
103
+ type: MessageBlockType.CODE;
104
+ /** 代码内容 */
105
+ content: string;
106
+ /** 代码语言 */
107
+ language: string;
108
+ /** 是否可执行 */
109
+ executable?: boolean;
110
+ /** 执行结果 */
111
+ executionResult?: {
112
+ output?: string;
113
+ error?: string;
114
+ exitCode?: number;
115
+ };
116
+ }
117
+ export interface ImageMessageBlock extends BaseMessageBlock {
118
+ type: MessageBlockType.IMAGE;
119
+ /** 图片 URL */
120
+ url?: string;
121
+ /** 本地文件路径 */
122
+ filePath?: string;
123
+ /** 图片元数据 */
124
+ metadata?: BaseMessageBlock['metadata'] & {
125
+ /** 生成提示词 */
126
+ prompt?: string;
127
+ /** 负面提示词 */
128
+ negativePrompt?: string;
129
+ /** 原始文件名 */
130
+ fileName?: string;
131
+ /** 文件大小 */
132
+ fileSize?: number;
133
+ /** 宽度 */
134
+ width?: number;
135
+ /** 高度 */
136
+ height?: number;
137
+ };
138
+ }
139
+ export interface ToolMessageBlock extends BaseMessageBlock {
140
+ type: MessageBlockType.TOOL;
141
+ /** 协作链路中的工具调用 ID(与 CP0 ToolCallBlock 对齐) */
142
+ toolCallId?: string;
143
+ /** 工具 ID */
144
+ toolId: string;
145
+ /** 工具名称 */
146
+ toolName: string;
147
+ /** 调用参数 */
148
+ arguments?: Record<string, unknown>;
149
+ /** 响应内容 */
150
+ content?: string | object;
151
+ /** CP0 协作契约状态(waiting_approval / running / done ...) */
152
+ toolStatus?: ToolCallStatus;
153
+ /** 执行结果(CP0 ToolCallBlock.result) */
154
+ result?: unknown;
155
+ /** 错误信息(CP0 ToolCallBlock.error) */
156
+ toolError?: string;
157
+ /** 耗时(ms) */
158
+ duration?: number;
159
+ /** 工具元数据 */
160
+ metadata?: BaseMessageBlock['metadata'] & {
161
+ /** 是否来自 MCP */
162
+ isMcp?: boolean;
163
+ /** MCP 服务器名称 */
164
+ mcpServer?: string;
165
+ };
166
+ }
167
+ export interface ToolApprovalMessageBlock extends BaseMessageBlock {
168
+ type: MessageBlockType.TOOL_APPROVAL;
169
+ toolCallId: string;
170
+ toolName: string;
171
+ toolDescription: string;
172
+ arguments: Record<string, unknown>;
173
+ risk: 'low' | 'medium' | 'high';
174
+ approvalStatus: ToolApprovalStatus;
175
+ approvedBy?: string;
176
+ approvedAt?: string;
177
+ decisionBy?: string;
178
+ decisionRole?: 'human' | 'secretary' | 'system';
179
+ onBehalfOf?: string;
180
+ reason?: string;
181
+ policyVersion?: string;
182
+ inboxItemId?: string;
183
+ }
184
+ export interface TaskProgressMessageBlock extends BaseMessageBlock {
185
+ type: MessageBlockType.TASK_PROGRESS;
186
+ taskId: string;
187
+ title: string;
188
+ steps: Array<{
189
+ id: string;
190
+ label: string;
191
+ status: TaskProgressStepStatus;
192
+ detail?: string;
193
+ duration?: number;
194
+ }>;
195
+ currentStep: number;
196
+ totalSteps: number;
197
+ }
198
+ export interface CitationMessageBlock extends BaseMessageBlock {
199
+ type: MessageBlockType.CITATION;
200
+ /** Web 搜索结果 */
201
+ webSearch?: {
202
+ query: string;
203
+ results: Array<{
204
+ title: string;
205
+ url: string;
206
+ snippet?: string;
207
+ favicon?: string;
208
+ }>;
209
+ };
210
+ /** 知识库引用 */
211
+ knowledge?: Array<{
212
+ id: string;
213
+ title: string;
214
+ content: string;
215
+ source?: string;
216
+ }>;
217
+ }
218
+ export interface FileMessageBlock extends BaseMessageBlock {
219
+ type: MessageBlockType.FILE;
220
+ /** 文件名 */
221
+ fileName: string;
222
+ /** 文件路径或 URL */
223
+ fileUrl: string;
224
+ /** 文件大小 */
225
+ fileSize?: number;
226
+ /** MIME 类型 */
227
+ mimeType?: string;
228
+ }
229
+ export interface ErrorMessageBlock extends BaseMessageBlock {
230
+ type: MessageBlockType.ERROR;
231
+ /** 错误消息 */
232
+ message: string;
233
+ /** 是否可重试 */
234
+ retryable?: boolean;
235
+ }
236
+ export type MessageBlock = PlaceholderMessageBlock | MainTextMessageBlock | ThinkingMessageBlock | CodeMessageBlock | ImageMessageBlock | ToolMessageBlock | ToolApprovalMessageBlock | TaskProgressMessageBlock | FileMessageBlock | ErrorMessageBlock | CitationMessageBlock;
237
+ /**
238
+ * 消息的 richContent JSON 结构
239
+ * 存储在 Message.richContent 字段中
240
+ */
241
+ export interface MessageRichContent {
242
+ /** 向后兼容:思考内容 */
243
+ thought?: string;
244
+ /** 向后兼容:工具调用 */
245
+ toolInvocations?: Array<{
246
+ id: string;
247
+ toolName: string;
248
+ input: unknown;
249
+ output?: unknown;
250
+ error?: string;
251
+ }>;
252
+ /** 新的块系统 */
253
+ blocks?: MessageBlock[];
254
+ }
255
+ /**
256
+ * 创建块的工厂函数
257
+ */
258
+ export declare function createMessageBlock<T extends MessageBlock>(type: T['type'], messageId: string, partial: Omit<T, 'id' | 'messageId' | 'type' | 'createdAt' | 'status'>): T;
259
+ /**
260
+ * 判断块类型
261
+ */
262
+ export declare function isBlockType<T extends MessageBlock>(block: MessageBlock, type: T['type']): block is T;
263
+ /**
264
+ * 从 richContent JSON 解析块
265
+ */
266
+ export declare function parseMessageBlocks(richContent: string | null | undefined): MessageBlock[];
267
+ /**
268
+ * 序列化块到 richContent JSON
269
+ */
270
+ export declare function serializeMessageBlocks(blocks: MessageBlock[]): string;
@@ -0,0 +1,125 @@
1
+ /**
2
+ * Message Block Types - 基于 Cherry Studio 的 block-based 消息系统
3
+ *
4
+ * 将消息内容拆分为多个块(blocks),支持:
5
+ * - 主文本 (Markdown)
6
+ * - 思考过程 (CoT/Reasoning)
7
+ * - 工具调用
8
+ * - 图片/文件
9
+ * - 引用/搜索结果
10
+ * - 错误信息
11
+ */
12
+ // 块类型枚举
13
+ export var MessageBlockType;
14
+ (function (MessageBlockType) {
15
+ /** 未知类型,用于流式响应开始前 */
16
+ MessageBlockType["UNKNOWN"] = "unknown";
17
+ /** 主要文本内容(Markdown) */
18
+ MessageBlockType["MAIN_TEXT"] = "main_text";
19
+ /** 思考过程(Claude、DeepSeek R1、OpenAI o-系列等) */
20
+ MessageBlockType["THINKING"] = "thinking";
21
+ /** 图片内容 */
22
+ MessageBlockType["IMAGE"] = "image";
23
+ /** 代码块(独立可运行) */
24
+ MessageBlockType["CODE"] = "code";
25
+ /** 工具调用及响应 */
26
+ MessageBlockType["TOOL"] = "tool";
27
+ /** 工具审批卡片 */
28
+ MessageBlockType["TOOL_APPROVAL"] = "tool_approval";
29
+ /** 任务进度卡片 */
30
+ MessageBlockType["TASK_PROGRESS"] = "task_progress";
31
+ /** 文件内容 */
32
+ MessageBlockType["FILE"] = "file";
33
+ /** 错误信息 */
34
+ MessageBlockType["ERROR"] = "error";
35
+ /** 引用类型(Web 搜索、知识库等) */
36
+ MessageBlockType["CITATION"] = "citation";
37
+ })(MessageBlockType || (MessageBlockType = {}));
38
+ // 块状态定义
39
+ export var MessageBlockStatus;
40
+ (function (MessageBlockStatus) {
41
+ /** 等待处理 */
42
+ MessageBlockStatus["PENDING"] = "pending";
43
+ /** 正在处理,等待接收 */
44
+ MessageBlockStatus["PROCESSING"] = "processing";
45
+ /** 正在流式接收 */
46
+ MessageBlockStatus["STREAMING"] = "streaming";
47
+ /** 处理成功 */
48
+ MessageBlockStatus["SUCCESS"] = "success";
49
+ /** 处理错误 */
50
+ MessageBlockStatus["ERROR"] = "error";
51
+ /** 处理暂停 */
52
+ MessageBlockStatus["PAUSED"] = "paused";
53
+ })(MessageBlockStatus || (MessageBlockStatus = {}));
54
+ /**
55
+ * 创建块的工厂函数
56
+ */
57
+ export function createMessageBlock(type, messageId, partial) {
58
+ const id = `block-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
59
+ return {
60
+ id,
61
+ messageId,
62
+ type,
63
+ createdAt: new Date().toISOString(),
64
+ status: MessageBlockStatus.PENDING,
65
+ ...partial,
66
+ };
67
+ }
68
+ /**
69
+ * 判断块类型
70
+ */
71
+ export function isBlockType(block, type) {
72
+ return block.type === type;
73
+ }
74
+ /**
75
+ * 从 richContent JSON 解析块
76
+ */
77
+ export function parseMessageBlocks(richContent) {
78
+ if (!richContent)
79
+ return [];
80
+ try {
81
+ const parsed = JSON.parse(richContent);
82
+ // 如果有新的块系统,直接返回
83
+ if (parsed.blocks && parsed.blocks.length > 0) {
84
+ return parsed.blocks;
85
+ }
86
+ // 向后兼容:转换旧格式
87
+ const blocks = [];
88
+ if (parsed.thought) {
89
+ blocks.push({
90
+ id: 'legacy-thought',
91
+ messageId: '',
92
+ type: MessageBlockType.THINKING,
93
+ content: parsed.thought,
94
+ createdAt: new Date().toISOString(),
95
+ status: MessageBlockStatus.SUCCESS,
96
+ });
97
+ }
98
+ if (parsed.toolInvocations) {
99
+ parsed.toolInvocations.forEach((ti, index) => {
100
+ blocks.push({
101
+ id: `legacy-tool-${index}`,
102
+ messageId: '',
103
+ type: MessageBlockType.TOOL,
104
+ toolId: ti.id,
105
+ toolName: ti.toolName,
106
+ arguments: ti.input,
107
+ content: ti.output ?? ti.error,
108
+ createdAt: new Date().toISOString(),
109
+ status: ti.error ? MessageBlockStatus.ERROR : MessageBlockStatus.SUCCESS,
110
+ });
111
+ });
112
+ }
113
+ return blocks;
114
+ }
115
+ catch {
116
+ return [];
117
+ }
118
+ }
119
+ /**
120
+ * 序列化块到 richContent JSON
121
+ */
122
+ export function serializeMessageBlocks(blocks) {
123
+ const content = { blocks };
124
+ return JSON.stringify(content);
125
+ }
@@ -1 +1 @@
1
- export * from '../namespaces.js';
1
+ export * from '../namespaces';
@@ -1,6 +1,5 @@
1
- export * from './_namespaces.js';
2
- export * from './chat.vocab.js';
3
- export * from './message.vocab.js';
4
- export * from './contact.vocab.js';
5
- export * from './thread.vocab.js';
6
- export * from './workspace.vocab.js';
1
+ export * from './_namespaces';
2
+ export * from './chat.vocab';
3
+ export * from './message.vocab';
4
+ export * from './contact.vocab';
5
+ export * from './thread.vocab';
@@ -3,4 +3,3 @@ export * from './chat.vocab.js';
3
3
  export * from './message.vocab.js';
4
4
  export * from './contact.vocab.js';
5
5
  export * from './thread.vocab.js';
6
- export * from './workspace.vocab.js';
@@ -1,7 +1,7 @@
1
1
  import { DCTerms, FOAF, LINX_MSG, SCHEMA, SIOC, UDFS, WF } from '../namespaces.js';
2
2
  export const MessageVocab = {
3
3
  // Existing
4
- thread: SIOC.hasContainer,
4
+ thread: SIOC.has_member,
5
5
  chat: WF.message,
6
6
  maker: FOAF.maker,
7
7
  role: UDFS.messageType,
@@ -1,8 +1,7 @@
1
1
  export declare const ThreadVocab: {
2
- readonly chatId: string;
2
+ readonly chat: string;
3
3
  readonly title: string;
4
4
  readonly starred: string;
5
- readonly status: string;
6
5
  readonly metadata: string;
7
6
  readonly createdAt: string;
8
7
  readonly updatedAt: string;
@@ -1,13 +1,12 @@
1
1
  import { DCTerms, LINX_CHAT, SIOC, UDFS } from '../namespaces.js';
2
2
  export const ThreadVocab = {
3
- chatId: SIOC.has_parent,
3
+ chat: SIOC.has_parent,
4
4
  title: DCTerms.title,
5
5
  starred: UDFS.favorite,
6
- status: UDFS.status,
7
6
  metadata: UDFS.metadata,
8
7
  createdAt: DCTerms.created,
9
8
  updatedAt: DCTerms.modified,
10
- // Execution context: workspace container (Agent@workspace)
9
+ // Execution context: workspace URI for the runnable root
11
10
  workspace: LINX_CHAT.workspace,
12
11
  // Type marker (for SPARQL convenience)
13
12
  type: SIOC.Thread,