@undefineds.co/models 0.1.0 → 0.2.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/README.md +125 -515
- package/dist/core/file/file.schema.d.ts +1 -1
- package/dist/core/file/file.schema.js +1 -1
- package/dist/core/index.d.ts +4 -4
- package/dist/core/index.js +3 -3
- package/dist/core/schema.d.ts +1 -1
- package/dist/core/schema.js +1 -1
- package/dist/core/types/{collaboration-blocks.d.ts → collaboration-rich-content.d.ts} +7 -7
- package/dist/core/types/collaboration-rich-content.js +7 -0
- package/dist/core/types/message-rich-content.d.ts +121 -0
- package/dist/core/types/message-rich-content.js +85 -0
- package/dist/fixtures/contracts-chat-contact.d.ts +4 -4
- package/dist/fixtures/contracts-chat-contact.js +8 -4
- package/dist/governance/index.d.ts +1 -0
- package/dist/governance/index.js +1 -0
- package/dist/{sidecar/persistence-mapping.d.ts → governance/runtime-projections.d.ts} +3 -3
- package/dist/{sidecar/persistence-mapping.js → governance/runtime-projections.js} +1 -7
- package/dist/index.d.ts +10 -7
- package/dist/index.js +11 -8
- package/dist/protocols/index.d.ts +1 -0
- package/dist/protocols/index.js +1 -0
- package/dist/{sidecar/sidecar-events.d.ts → protocols/runtime-events.d.ts} +11 -11
- package/dist/{sidecar/sidecar-events.js → protocols/runtime-events.js} +4 -21
- package/dist/schema.d.ts +1 -1
- package/dist/schema.js +1 -1
- package/dist/types/{collaboration-blocks.d.ts → collaboration-rich-content.d.ts} +7 -7
- package/dist/types/collaboration-rich-content.js +7 -0
- package/dist/types/message-rich-content.d.ts +121 -0
- package/dist/types/message-rich-content.js +85 -0
- package/package.json +9 -2
- package/dist/core/types/collaboration-blocks.js +0 -7
- package/dist/core/types/message-block.d.ts +0 -270
- package/dist/core/types/message-block.js +0 -125
- package/dist/sidecar/index.d.ts +0 -2
- package/dist/sidecar/index.js +0 -2
- package/dist/types/collaboration-blocks.js +0 -7
- package/dist/types/message-block.d.ts +0 -270
- package/dist/types/message-block.js +0 -125
- /package/dist/core/vocab/{sidecar.vocab.d.ts → governance.vocab.d.ts} +0 -0
- /package/dist/core/vocab/{sidecar.vocab.js → governance.vocab.js} +0 -0
- /package/dist/vocab/{sidecar.vocab.d.ts → governance.vocab.d.ts} +0 -0
- /package/dist/vocab/{sidecar.vocab.js → governance.vocab.js} +0 -0
package/README.md
CHANGED
|
@@ -1,578 +1,188 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@undefineds.co/models`
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
>
|
|
5
|
-
> 使用 `drizzle-solid` ORM,兼容标准 RDF 词汇表(VCARD, FOAF, SIOC, DCTerms 等)
|
|
3
|
+
Solid-first shared SDK for `undefineds.co` data contracts.
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
## 定位
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
`@undefineds.co/models` 不是单纯的 schema 仓库,它是一个 **SDK**:
|
|
10
8
|
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
- [设计原则](#设计原则)
|
|
9
|
+
- 提供共享的 Solid/RDF 数据模型、词汇表和类型
|
|
10
|
+
- 提供 SDK 级的数据访问描述符与通用 helper
|
|
11
|
+
- 提供影响面足够大的公开协议合同
|
|
12
|
+
- 提供可跨产品复用的治理域 helper,例如审批 / 审计 / 通知投影
|
|
16
13
|
|
|
17
|
-
|
|
14
|
+
它不负责:
|
|
18
15
|
|
|
19
|
-
|
|
16
|
+
- UI
|
|
17
|
+
- 具体运行时进程
|
|
18
|
+
- 某个产品专属的 server / worker / transport 实现
|
|
19
|
+
- 绑定 `xpod` 或 `linx` 的产品编排逻辑
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
## 核心原则
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
- `models` 本身就是 SDK
|
|
24
|
+
- 著名协议且影响面够大,可以先作为 SDK 能力进入
|
|
25
|
+
- 等影响面足够大,再晋升成 `xpod` 一等 API
|
|
24
26
|
|
|
25
|
-
|
|
26
|
-
2. **Contact** - 联系人管理(支持自然人和 AI)
|
|
27
|
-
3. **Chat & Message** - 聊天会话和消息
|
|
28
|
-
4. **File** - 文件管理
|
|
29
|
-
5. **Favorite** - 收藏夹
|
|
30
|
-
6. **Settings** - 用户设置
|
|
31
|
-
7. **AI Assistant** - AI 助手配置
|
|
27
|
+
换句话说:
|
|
32
28
|
|
|
33
|
-
|
|
29
|
+
- **协议合同** 可以进 `models`
|
|
30
|
+
- **共享治理 helper** 可以进 `models`
|
|
31
|
+
- **产品专属执行逻辑** 不应该进 `models`
|
|
34
32
|
|
|
35
|
-
|
|
36
|
-
- **Knowledge Folder** - 知识库文件夹
|
|
37
|
-
- **Extension** - 扩展
|
|
38
|
-
- **Model Credential** - 模型凭证
|
|
39
|
-
- **Import Job** - 导入任务
|
|
33
|
+
## 包含什么
|
|
40
34
|
|
|
41
|
-
|
|
35
|
+
### 1. 共享数据模型
|
|
42
36
|
|
|
43
|
-
|
|
37
|
+
例如:
|
|
44
38
|
|
|
45
|
-
|
|
39
|
+
- `profile`
|
|
40
|
+
- `contact`
|
|
41
|
+
- `chat` / `thread` / `message`
|
|
42
|
+
- `workspace`
|
|
43
|
+
- `favorite`
|
|
44
|
+
- `settings`
|
|
45
|
+
- `agent`
|
|
46
|
+
- `approval` / `audit` / `grant` / `inboxNotification`
|
|
46
47
|
|
|
47
|
-
|
|
48
|
+
这些模型描述的是稳定的 Pod 数据面,而不是某个 UI 或运行时实现。
|
|
48
49
|
|
|
49
|
-
|
|
50
|
-
|--------|------|------|
|
|
51
|
-
| **VCARD** | 联系人信息 | [RFC 6350](https://www.w3.org/TR/vcard-rdf/) |
|
|
52
|
-
| **FOAF** | 人和社交关系 | [FOAF Vocabulary](http://xmlns.com/foaf/spec/) |
|
|
53
|
-
| **SIOC** | 社交内容和讨论 | [SIOC Ontology](http://rdfs.org/sioc/spec/) |
|
|
54
|
-
| **DCTerms** | 元数据(创建时间、作者等) | [Dublin Core](https://www.dublincore.org/specifications/dublin-core/dcmi-terms/) |
|
|
55
|
-
| **Schema.org** | 结构化数据 | [Schema.org](https://schema.org/) |
|
|
56
|
-
| **LDP** | Linked Data Platform | [LDP Spec](https://www.w3.org/TR/ldp/) |
|
|
50
|
+
### 2. RDF 词汇表与命名空间
|
|
57
51
|
|
|
58
|
-
|
|
52
|
+
包内统一暴露标准词汇表和 `undefineds.co` 自定义词汇表,避免下游各自拼 IRI。
|
|
59
53
|
|
|
60
|
-
|
|
54
|
+
例如:
|
|
61
55
|
|
|
62
|
-
|
|
56
|
+
- `VCARD`
|
|
57
|
+
- `FOAF`
|
|
58
|
+
- `SIOC`
|
|
59
|
+
- `DCTerms`
|
|
60
|
+
- `WF`
|
|
61
|
+
- `UDFS`
|
|
62
|
+
- `ApprovalVocab`
|
|
63
|
+
- `AuditVocab`
|
|
63
64
|
|
|
64
|
-
|
|
65
|
+
### 3. SDK 级 repository / helper
|
|
65
66
|
|
|
66
|
-
|
|
67
|
+
`repository` 相关导出属于 SDK 能力的一部分,因为它们封装的是共享的数据访问约定,而不是某个产品运行时。
|
|
67
68
|
|
|
68
|
-
|
|
69
|
+
例如:
|
|
69
70
|
|
|
70
|
-
|
|
71
|
+
- `definePodRepository`
|
|
72
|
+
- `createRepositoryDescriptor`
|
|
73
|
+
- `findExactRecord`
|
|
74
|
+
- `updateExactRecord`
|
|
75
|
+
- `deleteExactRecord`
|
|
71
76
|
|
|
72
|
-
|
|
77
|
+
### 4. 协议合同
|
|
73
78
|
|
|
74
|
-
|
|
75
|
-
```typescript
|
|
76
|
-
{
|
|
77
|
-
displayName: string; // vcard:fn
|
|
78
|
-
nickname: string; // foaf:nick
|
|
79
|
-
avatarUrl: string; // vcard:hasPhoto
|
|
80
|
-
note: string; // vcard:note
|
|
81
|
-
region: string; // vcard:region
|
|
82
|
-
gender: string; // vcard:gender
|
|
83
|
-
favorite: string; // linx:favorite
|
|
84
|
-
inbox: string; // ldp:inbox
|
|
85
|
-
}
|
|
86
|
-
```
|
|
79
|
+
当某个协议具有足够公共性和影响面时,可以进入 `models` 作为 SDK 合同。
|
|
87
80
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
### 2. Contact(联系人)
|
|
91
|
-
|
|
92
|
-
**文件路径**: `src/contact/contact.schema.ts`
|
|
93
|
-
|
|
94
|
-
**RDF 类**: `vcard:Individual`
|
|
95
|
-
|
|
96
|
-
**支持类型**: `person`, `ai`, `organization`, `group`
|
|
97
|
-
|
|
98
|
-
**核心字段**:
|
|
99
|
-
```typescript
|
|
100
|
-
{
|
|
101
|
-
// 姓名
|
|
102
|
-
fullName: string; // vcard:fn ⭐ 必需
|
|
103
|
-
givenName: string; // vcard:givenName
|
|
104
|
-
familyName: string; // vcard:familyName
|
|
105
|
-
nickname: string; // foaf:nick
|
|
106
|
-
|
|
107
|
-
// 联系方式
|
|
108
|
-
email: string; // vcard:hasEmail
|
|
109
|
-
telephone: string; // vcard:hasTelephone
|
|
110
|
-
mobile: string;
|
|
111
|
-
|
|
112
|
-
// 地址
|
|
113
|
-
homeAddress: string; // vcard:hasAddress (JSON)
|
|
114
|
-
workAddress: string;
|
|
115
|
-
|
|
116
|
-
// 组织
|
|
117
|
-
organization: string; // vcard:organizationName
|
|
118
|
-
title: string; // vcard:title
|
|
119
|
-
|
|
120
|
-
// Solid 身份
|
|
121
|
-
webId: string; // foaf:weblog
|
|
122
|
-
|
|
123
|
-
// AI 联系人
|
|
124
|
-
aiAssistantId: string; // linx:aiAssistant
|
|
125
|
-
|
|
126
|
-
// 关系和标签
|
|
127
|
-
relationship: string; // vcard:hasRelated
|
|
128
|
-
tags: string; // dcterms:subject (JSON)
|
|
129
|
-
}
|
|
130
|
-
```
|
|
81
|
+
当前这类能力放在:
|
|
131
82
|
|
|
132
|
-
|
|
133
|
-
- `CONTACT_TYPES`: `person`, `ai`, `organization`, `group`
|
|
134
|
-
- `RELATIONSHIP_TYPES`: `friend`, `family`, `colleague`, `acquaintance`, `other`
|
|
135
|
-
|
|
136
|
-
---
|
|
137
|
-
|
|
138
|
-
### 3. Chat(聊天会话)
|
|
139
|
-
|
|
140
|
-
**文件路径**: `src/chat/chat.schema.ts`
|
|
141
|
-
|
|
142
|
-
**RDF 类**: `schema:ConversationThread`
|
|
143
|
-
|
|
144
|
-
**字段**:
|
|
145
|
-
```typescript
|
|
146
|
-
{
|
|
147
|
-
title: string; // dcterms:title ⭐ 必需
|
|
148
|
-
description: string; // dcterms:description
|
|
149
|
-
conversationType: string; // linx:conversationType (direct, group, ai)
|
|
150
|
-
status: string; // linx:status (active, archived, deleted)
|
|
151
|
-
participants: array; // linx:participants (WebID 数组)
|
|
152
|
-
creator: string; // dcterms:creator
|
|
153
|
-
createdAt: timestamp; // dcterms:created
|
|
154
|
-
modifiedAt: timestamp; // dcterms:modified
|
|
155
|
-
lastMessage: string; // linx:lastMessage
|
|
156
|
-
lastMessageAt: timestamp; // linx:lastMessageAt
|
|
157
|
-
pinnedAt: timestamp; // linx:pinnedAt
|
|
158
|
-
}
|
|
159
|
-
```
|
|
83
|
+
- `@undefineds.co/models/protocols`
|
|
160
84
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
### 4. Message(聊天消息)
|
|
164
|
-
|
|
165
|
-
**文件路径**: `src/chat/message.schema.ts`
|
|
166
|
-
|
|
167
|
-
**RDF 类**: `schema:Message`
|
|
168
|
-
|
|
169
|
-
**字段**:
|
|
170
|
-
```typescript
|
|
171
|
-
{
|
|
172
|
-
content: string; // sioc:content ⭐ 必需 (支持 Markdown)
|
|
173
|
-
messageType: string; // linx:messageType (text, image, file, system)
|
|
174
|
-
messageStatus: string; // linx:messageStatus (sending, sent, delivered, read, failed)
|
|
175
|
-
conversationId: string; // linx:conversation
|
|
176
|
-
replyTo: string; // sioc:replyOf
|
|
177
|
-
sender: string; // dcterms:creator (WebID)
|
|
178
|
-
senderName: string; // foaf:name
|
|
179
|
-
createdAt: timestamp; // dcterms:created
|
|
180
|
-
modifiedAt: timestamp; // dcterms:modified (编辑时间)
|
|
181
|
-
deletedAt: timestamp; // linx:deletedAt (软删除)
|
|
182
|
-
readBy: string; // linx:readBy (JSON)
|
|
183
|
-
|
|
184
|
-
// 附件(如果是文件/图片消息)
|
|
185
|
-
attachmentUri: string; // schema:about
|
|
186
|
-
attachmentName: string; // schema:name
|
|
187
|
-
attachmentSize: integer; // schema:fileSize
|
|
188
|
-
attachmentMime: string; // schema:encodingFormat
|
|
189
|
-
}
|
|
190
|
-
```
|
|
85
|
+
例如当前的:
|
|
191
86
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
**文件路径**: `src/file/file.schema.ts`
|
|
197
|
-
|
|
198
|
-
**RDF 类**: `schema:MediaObject`
|
|
199
|
-
|
|
200
|
-
**字段**:
|
|
201
|
-
```typescript
|
|
202
|
-
{
|
|
203
|
-
name: string; // schema:name ⭐ 必需
|
|
204
|
-
description: string; // schema:description
|
|
205
|
-
mimeType: string; // schema:encodingFormat
|
|
206
|
-
size: integer; // schema:fileSize
|
|
207
|
-
hash: string; // linx:fileHash (SHA-256)
|
|
208
|
-
podUri: string; // dcterms:identifier (Pod 中的 URI)
|
|
209
|
-
localPath: string; // linx:localPath (本地路径)
|
|
210
|
-
syncStatus: string; // linx:syncStatus (synced, pending, conflict, error)
|
|
211
|
-
owner: string; // dcterms:creator
|
|
212
|
-
sharedWith: string; // linx:participants (JSON)
|
|
213
|
-
folder: string; // linx:conversation
|
|
214
|
-
tags: string; // dcterms:subject (JSON)
|
|
215
|
-
starred: boolean; // linx:favorite
|
|
216
|
-
createdAt: timestamp; // dcterms:created
|
|
217
|
-
modifiedAt: timestamp; // dcterms:modified
|
|
218
|
-
}
|
|
219
|
-
```
|
|
87
|
+
- 归一化运行时事件合同 `tool.call`
|
|
88
|
+
- `session.state`
|
|
89
|
+
- `tool.control`
|
|
90
|
+
- `inbox.approval`
|
|
220
91
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
### 6. Favorite(收藏)
|
|
224
|
-
|
|
225
|
-
**文件路径**: `src/favorite/favorite.schema.ts`
|
|
226
|
-
|
|
227
|
-
**RDF 类**: `schema:CreativeWork`
|
|
228
|
-
|
|
229
|
-
**支持收藏类型**: `message`, `file`, `contact`, `link`, `note`
|
|
230
|
-
|
|
231
|
-
**字段**:
|
|
232
|
-
```typescript
|
|
233
|
-
{
|
|
234
|
-
title: string; // dcterms:title ⭐ 必需
|
|
235
|
-
description: string; // dcterms:description
|
|
236
|
-
favoriteType: string; // linx:favoriteType
|
|
237
|
-
targetUri: string; // linx:favoriteTarget ⭐ 必需
|
|
238
|
-
|
|
239
|
-
// 快照(避免查询原始资源)
|
|
240
|
-
snapshotContent: string; // schema:text
|
|
241
|
-
snapshotAuthor: string; // schema:author
|
|
242
|
-
snapshotCreatedAt: timestamp; // schema:dateCreated
|
|
243
|
-
|
|
244
|
-
owner: string; // dcterms:creator
|
|
245
|
-
folder: string; // linx:conversation
|
|
246
|
-
tags: string; // dcterms:subject (JSON)
|
|
247
|
-
favoredAt: timestamp; // linx:favoredAt
|
|
248
|
-
createdAt: timestamp; // dcterms:created
|
|
249
|
-
modifiedAt: timestamp; // dcterms:modified
|
|
250
|
-
pinnedAt: timestamp; // linx:pinnedAt
|
|
251
|
-
}
|
|
252
|
-
```
|
|
92
|
+
这些合同描述“事件长什么样”,不描述“产品怎么处理它”。
|
|
253
93
|
|
|
254
|
-
|
|
94
|
+
### 5. 治理域 helper
|
|
255
95
|
|
|
256
|
-
|
|
96
|
+
审批 / 审计 / 通知这类能力本身属于共享数据面,因此可以像 `favorite` 一样,提供 SDK 级 helper。
|
|
257
97
|
|
|
258
|
-
|
|
98
|
+
当前这类能力放在:
|
|
259
99
|
|
|
260
|
-
|
|
100
|
+
- `@undefineds.co/models/governance`
|
|
261
101
|
|
|
262
|
-
|
|
263
|
-
```typescript
|
|
264
|
-
{
|
|
265
|
-
key: string; // linx:settingKey ⭐ 必需(唯一)
|
|
266
|
-
value: string; // linx:settingValue (JSON 字符串)
|
|
267
|
-
valueType: string; // linx:settingType (string, number, boolean, json)
|
|
268
|
-
category: string; // dcterms:type (ui, ai, sync, privacy, notifications)
|
|
269
|
-
label: string; // dcterms:title
|
|
270
|
-
description: string; // dcterms:description
|
|
271
|
-
owner: string; // dcterms:creator
|
|
272
|
-
isSensitive: boolean; // linx:status (是否加密)
|
|
273
|
-
createdAt: timestamp; // dcterms:created
|
|
274
|
-
modifiedAt: timestamp; // dcterms:modified
|
|
275
|
-
}
|
|
276
|
-
```
|
|
102
|
+
它们负责:
|
|
277
103
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
UI_THEME: "ui.theme"
|
|
282
|
-
UI_LANGUAGE: "ui.language"
|
|
283
|
-
UI_SIDEBAR_WIDTH: "ui.sidebar.width"
|
|
284
|
-
UI_LIST_PANEL_WIDTH: "ui.listPanel.width"
|
|
285
|
-
|
|
286
|
-
// AI 设置
|
|
287
|
-
AI_DEFAULT_ASSISTANT: "ai.defaultAssistant"
|
|
288
|
-
AI_AUTO_REPLY: "ai.autoReply"
|
|
289
|
-
AI_STREAMING: "ai.streaming"
|
|
290
|
-
|
|
291
|
-
// 同步设置
|
|
292
|
-
SYNC_AUTO: "sync.auto"
|
|
293
|
-
SYNC_INTERVAL: "sync.interval"
|
|
294
|
-
SYNC_WIFI_ONLY: "sync.wifiOnly"
|
|
295
|
-
|
|
296
|
-
// 隐私设置
|
|
297
|
-
PRIVACY_READ_RECEIPTS: "privacy.readReceipts"
|
|
298
|
-
PRIVACY_ONLINE_STATUS: "privacy.onlineStatus"
|
|
299
|
-
PRIVACY_TYPING_INDICATOR: "privacy.typingIndicator"
|
|
300
|
-
|
|
301
|
-
// 通知设置
|
|
302
|
-
NOTIFICATIONS_ENABLED: "notifications.enabled"
|
|
303
|
-
NOTIFICATIONS_SOUND: "notifications.sound"
|
|
304
|
-
NOTIFICATIONS_DESKTOP: "notifications.desktop"
|
|
305
|
-
|
|
306
|
-
// Pod 设置
|
|
307
|
-
POD_AUTO_CONNECT: "pod.autoConnect"
|
|
308
|
-
POD_CACHE_SIZE: "pod.cacheSize"
|
|
309
|
-
```
|
|
104
|
+
- 定义稳定的投影字段
|
|
105
|
+
- 定义运行时事件到 Pod 行的共享映射规则
|
|
106
|
+
- 提供纯函数级判断 helper
|
|
310
107
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
### 8. AI Assistant(AI 助手配置)
|
|
314
|
-
|
|
315
|
-
**文件路径**: `src/agent.schema.ts`
|
|
316
|
-
|
|
317
|
-
**RDF 类**: `foaf:Agent`
|
|
318
|
-
|
|
319
|
-
**字段**:
|
|
320
|
-
```typescript
|
|
321
|
-
{
|
|
322
|
-
// 基础信息
|
|
323
|
-
name: string; // foaf:name ⭐ 必需
|
|
324
|
-
nickname: string; // foaf:nick
|
|
325
|
-
description: string; // dcterms:description
|
|
326
|
-
avatarUrl: string; // foaf:depiction
|
|
327
|
-
assistantType: string; // dcterms:type (system, custom, shared)
|
|
328
|
-
|
|
329
|
-
// 模型配置
|
|
330
|
-
provider: string; // linx:aiProvider (openai, anthropic, ollama, custom)
|
|
331
|
-
modelId: string; // linx:aiModel (gpt-4, claude-3, llama2)
|
|
332
|
-
systemPrompt: string; // linx:systemPrompt
|
|
333
|
-
|
|
334
|
-
// 模型参数
|
|
335
|
-
temperature: float; // linx:temperature (0-2)
|
|
336
|
-
maxTokens: integer; // linx:maxTokens
|
|
337
|
-
topP: float;
|
|
338
|
-
frequencyPenalty: float;
|
|
339
|
-
presencePenalty: float;
|
|
340
|
-
|
|
341
|
-
// 功能配置
|
|
342
|
-
enableStreaming: boolean;
|
|
343
|
-
enableFunctionCalling: boolean;
|
|
344
|
-
allowedFunctions: string; // JSON 数组
|
|
345
|
-
|
|
346
|
-
// Pod 访问权限
|
|
347
|
-
podAccessLevel: string; // linx:status (read, write, full)
|
|
348
|
-
allowedContainers: string; // JSON 数组
|
|
349
|
-
|
|
350
|
-
// 共享
|
|
351
|
-
owner: string; // dcterms:creator
|
|
352
|
-
isPublic: boolean;
|
|
353
|
-
sharedWith: string; // JSON
|
|
354
|
-
|
|
355
|
-
// 统计
|
|
356
|
-
messageCount: integer;
|
|
357
|
-
lastUsedAt: timestamp;
|
|
358
|
-
|
|
359
|
-
status: string; // linx:status (active, disabled, archived)
|
|
360
|
-
createdAt: timestamp;
|
|
361
|
-
modifiedAt: timestamp;
|
|
362
|
-
}
|
|
363
|
-
```
|
|
108
|
+
它们不负责:
|
|
364
109
|
|
|
365
|
-
|
|
366
|
-
-
|
|
367
|
-
-
|
|
110
|
+
- 发请求
|
|
111
|
+
- 起服务
|
|
112
|
+
- 做本地/远端进程管理
|
|
113
|
+
- 执行产品策略
|
|
368
114
|
|
|
369
|
-
|
|
115
|
+
## 不包含什么
|
|
370
116
|
|
|
371
|
-
|
|
117
|
+
以下内容不应进入 `models`:
|
|
372
118
|
|
|
373
|
-
|
|
119
|
+
- `linx` 专属页面逻辑
|
|
120
|
+
- `xpod` 专属运行时实现
|
|
121
|
+
- 某个 ACP / Matrix 客户端的具体网络接入
|
|
122
|
+
- 某个产品独有的自动审批策略
|
|
123
|
+
- worker / 长驻运行时 / daemon 进程生命周期管理
|
|
374
124
|
|
|
375
|
-
|
|
376
|
-
yarn workspace @linq/models install
|
|
377
|
-
```
|
|
125
|
+
## 公开入口
|
|
378
126
|
|
|
379
|
-
###
|
|
127
|
+
### 根入口
|
|
380
128
|
|
|
381
|
-
```
|
|
129
|
+
```ts
|
|
382
130
|
import {
|
|
383
|
-
// 词汇表
|
|
384
|
-
LINQ, SIOC, DCTerms, SCHEMA,
|
|
385
|
-
|
|
386
|
-
// 模型表
|
|
387
|
-
contactTable,
|
|
388
131
|
chatTable,
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
// 类型
|
|
396
|
-
type ContactRow,
|
|
397
|
-
type ChatRow,
|
|
398
|
-
type MessageRow,
|
|
399
|
-
|
|
400
|
-
// 常量
|
|
401
|
-
CONTACT_TYPES,
|
|
402
|
-
SETTING_KEYS,
|
|
403
|
-
AI_PROVIDERS,
|
|
404
|
-
} from "@linq/models";
|
|
405
|
-
```
|
|
406
|
-
|
|
407
|
-
### 查询示例
|
|
408
|
-
|
|
409
|
-
```typescript
|
|
410
|
-
// 查询联系人
|
|
411
|
-
const contacts = await db
|
|
412
|
-
.select()
|
|
413
|
-
.from(contactTable)
|
|
414
|
-
.where(eq(contactTable.contactType, CONTACT_TYPES.PERSON));
|
|
415
|
-
|
|
416
|
-
// 创建聊天会话
|
|
417
|
-
const newChat = await db
|
|
418
|
-
.insert(chatTable)
|
|
419
|
-
.values({
|
|
420
|
-
title: "与 Alice 的对话",
|
|
421
|
-
conversationType: "direct",
|
|
422
|
-
participants: ["https://alice.solidcommunity.net/profile/card#me"],
|
|
423
|
-
creator: session.webId,
|
|
424
|
-
status: "active",
|
|
425
|
-
});
|
|
426
|
-
|
|
427
|
-
// 发送消息
|
|
428
|
-
const newMessage = await db
|
|
429
|
-
.insert(messageTable)
|
|
430
|
-
.values({
|
|
431
|
-
content: "你好,Alice!",
|
|
432
|
-
messageType: "text",
|
|
433
|
-
conversationId: chatId,
|
|
434
|
-
sender: session.webId,
|
|
435
|
-
senderName: "Bob",
|
|
436
|
-
messageStatus: "sent",
|
|
437
|
-
});
|
|
438
|
-
|
|
439
|
-
// 查询设置
|
|
440
|
-
const theme = await db
|
|
441
|
-
.select()
|
|
442
|
-
.from(settingsTable)
|
|
443
|
-
.where(eq(settingsTable.key, SETTING_KEYS.UI_THEME))
|
|
444
|
-
.limit(1);
|
|
445
|
-
|
|
446
|
-
// 创建 AI 助手
|
|
447
|
-
const assistant = await db
|
|
448
|
-
.insert(aiAssistantTable)
|
|
449
|
-
.values({
|
|
450
|
-
name: "LinX 助手",
|
|
451
|
-
provider: AI_PROVIDERS.OPENAI,
|
|
452
|
-
modelId: AI_MODELS.GPT_4,
|
|
453
|
-
systemPrompt: "你是 LinX 的智能助手...",
|
|
454
|
-
temperature: 0.7,
|
|
455
|
-
maxTokens: 2048,
|
|
456
|
-
owner: session.webId,
|
|
457
|
-
});
|
|
132
|
+
contactTable,
|
|
133
|
+
chatRepository,
|
|
134
|
+
definePodRepository,
|
|
135
|
+
ApprovalVocab,
|
|
136
|
+
} from '@undefineds.co/models'
|
|
458
137
|
```
|
|
459
138
|
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
## 设计原则
|
|
463
|
-
|
|
464
|
-
### 1. 遵循 Solid 标准
|
|
465
|
-
|
|
466
|
-
- ✅ 优先使用标准 RDF 词汇表(VCARD, FOAF, SIOC, DCTerms)
|
|
467
|
-
- ✅ 仅在必要时使用自定义词汇表(`linx:` 命名空间)
|
|
468
|
-
- ✅ 所有数据存储在 Pod 的 LDP 容器中
|
|
469
|
-
- ✅ 使用标准 RDF 类(`vcard:Individual`, `schema:Message` 等)
|
|
470
|
-
|
|
471
|
-
### 2. 类型安全
|
|
472
|
-
|
|
473
|
-
- ✅ 使用 `drizzle-solid` 提供的类型推断
|
|
474
|
-
- ✅ 导出 `Row`, `Insert`, `Update` 类型
|
|
475
|
-
- ✅ 定义常量枚举(`CONTACT_TYPES`, `SETTING_KEYS` 等)
|
|
476
|
-
|
|
477
|
-
### 3. 可扩展性
|
|
478
|
-
|
|
479
|
-
- ✅ 支持软删除(`deletedAt` 字段)
|
|
480
|
-
- ✅ 支持 JSON 字段存储复杂数据(标签、数组等)
|
|
481
|
-
- ✅ 预留扩展字段(`tags`, `metadata`)
|
|
482
|
-
|
|
483
|
-
### 4. 互操作性
|
|
484
|
-
|
|
485
|
-
- ✅ 与其他 Solid 应用兼容
|
|
486
|
-
- ✅ 使用标准的 RDF 谓词
|
|
487
|
-
- ✅ 遵循 SolidOS 的数据规范
|
|
139
|
+
### 协议入口
|
|
488
140
|
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
---
|
|
496
|
-
|
|
497
|
-
## 开发指南
|
|
498
|
-
|
|
499
|
-
### 添加新模型
|
|
500
|
-
|
|
501
|
-
1. 在 `src/<entity>/` 创建 `<entity>.schema.ts`
|
|
502
|
-
2. 使用 `podTable` 定义表结构
|
|
503
|
-
3. 选择合适的 RDF 类和谓词
|
|
504
|
-
4. 导出类型:`Row`, `Insert`, `Update`
|
|
505
|
-
5. 在 `src/<entity>/index.ts` 导出
|
|
506
|
-
6. 在 `src/index.ts` 添加导出
|
|
507
|
-
7. 更新本 README
|
|
508
|
-
|
|
509
|
-
### 修改现有模型
|
|
510
|
-
|
|
511
|
-
⚠️ **注意**:修改模型可能影响现有数据!
|
|
512
|
-
|
|
513
|
-
- 添加字段:安全(向后兼容)
|
|
514
|
-
- 删除字段:危险(需要数据迁移)
|
|
515
|
-
- 重命名字段:危险(需要数据迁移)
|
|
516
|
-
- 修改类型:危险(需要数据迁移)
|
|
517
|
-
|
|
518
|
-
### 测试
|
|
519
|
-
|
|
520
|
-
```bash
|
|
521
|
-
# 运行测试(待添加)
|
|
522
|
-
yarn workspace @linq/models test
|
|
523
|
-
|
|
524
|
-
# 类型检查
|
|
525
|
-
yarn workspace @linq/models typecheck
|
|
141
|
+
```ts
|
|
142
|
+
import {
|
|
143
|
+
RuntimeEventSchema,
|
|
144
|
+
ToolCallEventSchema,
|
|
145
|
+
} from '@undefineds.co/models/protocols'
|
|
526
146
|
```
|
|
527
147
|
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
## 参考资料
|
|
531
|
-
|
|
532
|
-
### Solid 规范
|
|
533
|
-
- [Solid Protocol](https://solidproject.org/TR/protocol)
|
|
534
|
-
- [Linked Data Platform (LDP)](https://www.w3.org/TR/ldp/)
|
|
535
|
-
- [WebID Profile](https://www.w3.org/2005/Incubator/webid/spec/)
|
|
536
|
-
|
|
537
|
-
### RDF 词汇表
|
|
538
|
-
- [VCARD Ontology](https://www.w3.org/TR/vcard-rdf/)
|
|
539
|
-
- [FOAF Vocabulary](http://xmlns.com/foaf/spec/)
|
|
540
|
-
- [SIOC Ontology](http://rdfs.org/sioc/spec/)
|
|
541
|
-
- [Dublin Core Terms](https://www.dublincore.org/specifications/dublin-core/dcmi-terms/)
|
|
542
|
-
- [Schema.org](https://schema.org/)
|
|
543
|
-
|
|
544
|
-
### 工具
|
|
545
|
-
- [Drizzle ORM](https://orm.drizzle.team/)
|
|
546
|
-
- [Inrupt Solid Client](https://docs.inrupt.com/developer-tools/javascript/client-libraries/)
|
|
547
|
-
|
|
548
|
-
---
|
|
148
|
+
### 治理入口
|
|
549
149
|
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
| | | - 完善 Contact 模型(完整 VCARD 字段) |
|
|
557
|
-
| | | - 创建 Chat & Message 模型 |
|
|
558
|
-
| | | - 创建 File 模型 |
|
|
559
|
-
| | | - 创建 Favorite 模型 |
|
|
560
|
-
| | | - 创建 Settings 模型 |
|
|
561
|
-
| | | - 创建 AI Assistant 模型 |
|
|
562
|
-
| | | - 重组 index.ts 导出 |
|
|
563
|
-
|
|
564
|
-
---
|
|
565
|
-
|
|
566
|
-
## 许可证
|
|
150
|
+
```ts
|
|
151
|
+
import {
|
|
152
|
+
RuntimeEventProjectionRules,
|
|
153
|
+
isToolWaitingApproval,
|
|
154
|
+
} from '@undefineds.co/models/governance'
|
|
155
|
+
```
|
|
567
156
|
|
|
568
|
-
|
|
157
|
+
## 边界判断
|
|
569
158
|
|
|
159
|
+
遇到新能力时,按下面判断:
|
|
570
160
|
|
|
161
|
+
### 应该放进 `models`
|
|
571
162
|
|
|
163
|
+
- 是共享数据结构
|
|
164
|
+
- 是共享 RDF 词汇表
|
|
165
|
+
- 是共享 repository / helper
|
|
166
|
+
- 是公开协议合同
|
|
167
|
+
- 是跨产品都可复用的纯函数级治理 helper
|
|
572
168
|
|
|
169
|
+
### 不该放进 `models`
|
|
573
170
|
|
|
171
|
+
- 只服务某一个产品
|
|
172
|
+
- 需要依赖具体运行时环境
|
|
173
|
+
- 本质是 transport / daemon / server 实现
|
|
174
|
+
- 带有明显产品策略或产品默认行为
|
|
574
175
|
|
|
176
|
+
## 与 `xpod` 的关系
|
|
575
177
|
|
|
178
|
+
`models` 提供共享 SDK 面。
|
|
576
179
|
|
|
180
|
+
`xpod` 可以在其上继续提供更高层的一等 API、服务实现和运行时能力。
|
|
181
|
+
当某个协议或治理流程稳定且影响面足够大时,再考虑晋升为 `xpod` 一等 API。
|
|
577
182
|
|
|
183
|
+
## 开发约定
|
|
578
184
|
|
|
185
|
+
- 优先使用 Solid / RDF 叙事,而不是 SQL 表叙事
|
|
186
|
+
- 优先复用标准词汇表,缺失时再扩展 `UDFS`
|
|
187
|
+
- 共享真相先进入 `models`
|
|
188
|
+
- 产品特化行为留在产品层
|