@shumai-one/shumai 0.0.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.
@@ -0,0 +1,778 @@
1
+ generator client {
2
+ provider = "prisma-client"
3
+ output = "../src/generated/prisma"
4
+ binaryTargets = ["native", "linux-musl-openssl-3.0.x"]
5
+ previewFeatures = ["postgresqlExtensions"]
6
+ }
7
+
8
+ generator json {
9
+ provider = "prisma-json-types-generator"
10
+ allowAny = false
11
+ }
12
+
13
+ datasource db {
14
+ provider = "postgresql"
15
+ extensions = [vector]
16
+ }
17
+
18
+ // ----------------------------------------------------------------------
19
+ // Enums
20
+ // ----------------------------------------------------------------------
21
+
22
+ enum UserType {
23
+ human
24
+ agent
25
+ }
26
+
27
+ enum AssetType {
28
+ folder
29
+ file
30
+ share
31
+ root
32
+ attachment
33
+ version_stack
34
+ share_root
35
+ symlink
36
+ }
37
+
38
+ enum AssetStatus {
39
+ uploading
40
+ uploaded
41
+ processing
42
+ processed
43
+ trashed
44
+ pending_purge
45
+ }
46
+
47
+ enum StorageKeyStatus {
48
+ active
49
+ purging
50
+ }
51
+
52
+ enum InviteRole {
53
+ editor
54
+ reviewer
55
+ }
56
+
57
+ enum MetadataFieldScope {
58
+ SYSTEM
59
+ TEAM
60
+ PROJECT
61
+ }
62
+
63
+ enum NotificationType {
64
+ comment_created
65
+ reply_created
66
+ mention
67
+ successful_file_uploaded
68
+ metadata_field_updated_status
69
+ new_user_join_team
70
+ new_user_join_project
71
+ }
72
+
73
+ enum ProjectMemberRole {
74
+ owner
75
+ editor
76
+ reviewer
77
+ }
78
+
79
+ enum TaskType {
80
+ upload
81
+ }
82
+
83
+ enum TaskStatus {
84
+ pending
85
+ uploading
86
+ completed
87
+ failed
88
+ }
89
+
90
+ enum TeamMemberRole {
91
+ owner
92
+ editor
93
+ reviewer
94
+ }
95
+
96
+ enum TeamMemberScope {
97
+ team
98
+ project
99
+ }
100
+
101
+ enum WorkflowTaskType {
102
+ transcode
103
+ ai_metadata_autofill
104
+ chat
105
+ ai_embedding
106
+ query_embedding_for_search
107
+ agent_tool_call
108
+ }
109
+
110
+ enum WorkflowTaskStatus {
111
+ pending
112
+ processing
113
+ completed
114
+ failed
115
+ }
116
+
117
+ // ----------------------------------------------------------------------
118
+ // Models
119
+ // ----------------------------------------------------------------------
120
+
121
+ model User {
122
+ id String @id @default(ulid())
123
+ type UserType @default(human)
124
+ name String
125
+ email String @unique
126
+ emailVerified Boolean @default(false) @map("email_verified")
127
+ image String?
128
+ password String?
129
+ /// [AgentSettings]
130
+ agentSettings Json? @map("agent_settings")
131
+ guestEmail String? @map("guest_email")
132
+ createdAt DateTime @default(now()) @map("created_at")
133
+ updatedAt DateTime @updatedAt @map("updated_at")
134
+
135
+ assets Asset[] @relation("UserToAsset")
136
+ authTokens AuthToken[] @relation("UserToAuthToken")
137
+ tasks Task[] @relation("UserToTask")
138
+ teamMembers TeamMember[] @relation("UserToTeamMember")
139
+ comments AssetComment[] @relation("UserToAssetComment")
140
+ createdInvites Invite[] @relation("UserToInvite")
141
+ createdNotifications Notification[] @relation("UserToCreatedNotification")
142
+ notifications Notification[] @relation("UserToNotification")
143
+ sessions Session[]
144
+ accounts Account[]
145
+ agent Agent?
146
+ agentSessions AgentSession[]
147
+ userMetadata UserMetadata[] @relation("UserToUserMetadata")
148
+ collections Collection[] @relation("UserToCollection")
149
+ shareLinks ShareLink[] @relation("UserToShareLink")
150
+
151
+ @@map("users")
152
+ }
153
+
154
+ model Session {
155
+ id String @id @default(ulid())
156
+ expiresAt DateTime @map("expires_at")
157
+ token String @unique
158
+ createdAt DateTime @default(now()) @map("created_at")
159
+ updatedAt DateTime @updatedAt @map("updated_at")
160
+ ipAddress String? @map("ip_address")
161
+ userAgent String? @map("user_agent")
162
+ userId String @map("user_id")
163
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
164
+
165
+ @@map("sessions")
166
+ }
167
+
168
+ model Account {
169
+ id String @id @default(ulid())
170
+ accountId String @map("account_id")
171
+ providerId String @map("provider_id")
172
+ userId String @map("user_id")
173
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
174
+ accessToken String? @map("access_token")
175
+ refreshToken String? @map("refresh_token")
176
+ idToken String? @map("id_token")
177
+ accessTokenExpiresAt DateTime? @map("access_token_expires_at")
178
+ refreshTokenExpiresAt DateTime? @map("refresh_token_expires_at")
179
+ scope String?
180
+ password String?
181
+ createdAt DateTime @default(now()) @map("created_at")
182
+ updatedAt DateTime @updatedAt @map("updated_at")
183
+
184
+ @@map("accounts")
185
+ }
186
+
187
+ model Verification {
188
+ id String @id @default(ulid())
189
+ identifier String
190
+ value String
191
+ expiresAt DateTime @map("expires_at")
192
+ createdAt DateTime? @default(now()) @map("created_at")
193
+ updatedAt DateTime? @updatedAt @map("updated_at")
194
+
195
+ @@map("verifications")
196
+ }
197
+
198
+ model AuthToken {
199
+ id String @id @default(ulid())
200
+ accessToken String @unique @map("access_token")
201
+ refreshToken String @unique @map("refresh_token")
202
+ accessTokenExpiresAt DateTime @map("access_token_expires_at")
203
+ refreshTokenExpiresAt DateTime @map("refresh_token_expires_at")
204
+
205
+ userId String @map("user_id")
206
+ user User @relation("UserToAuthToken", fields: [userId], references: [id])
207
+
208
+ @@map("auth_tokens")
209
+ }
210
+
211
+ model Team {
212
+ id String @id @default(ulid())
213
+ name String
214
+ /// [Settings]
215
+ settings Json? @default("{}")
216
+ createdAt DateTime @default(now()) @map("created_at")
217
+ updatedAt DateTime @updatedAt @map("updated_at")
218
+
219
+ rootFolderId String? @unique @map("root_folder_id")
220
+ rootFolder Asset? @relation("TeamToRootFolder", fields: [rootFolderId], references: [id])
221
+
222
+ members TeamMember[] @relation("TeamToTeamMember")
223
+ projects Project[] @relation("TeamToProject")
224
+ metadataFields MetadataField[] @relation("TeamToMetadataField")
225
+ invites Invite[] @relation("TeamToInvite")
226
+ notifications Notification[] @relation("TeamToNotification")
227
+ userMetadata UserMetadata[] @relation("TeamToUserMetadata")
228
+ providers Provider[] @relation("TeamToProvider")
229
+ skills Skill[] @relation("TeamToSkill")
230
+ sandbox Sandbox? @relation("TeamToSandbox")
231
+ agents Agent[] @relation("TeamToAgent")
232
+
233
+ @@map("teams")
234
+ }
235
+
236
+ model Sandbox {
237
+ id String @id @default(ulid())
238
+ allowedDomains String[] @default(["npmjs.org", "*.npmjs.org", "registry.npmjs.org", "registry.yarnpkg.com", "pypi.org", "*.pypi.org", "github.com", "*.github.com", "api.github.com", "raw.githubusercontent.com"])
239
+ createdAt DateTime @default(now()) @map("created_at")
240
+ updatedAt DateTime @updatedAt @map("updated_at")
241
+
242
+ teamId String @unique @map("team_id")
243
+ team Team @relation("TeamToSandbox", fields: [teamId], references: [id], onDelete: Cascade)
244
+
245
+ @@map("sandboxes")
246
+ }
247
+
248
+ model Skill {
249
+ id String @id @default(ulid())
250
+ name String
251
+ description String?
252
+ /// [SkillConfig]
253
+ config Json? @default("{}")
254
+ assetId String @map("asset_id")
255
+ hash String @map("hash")
256
+ createdAt DateTime @default(now()) @map("created_at")
257
+ updatedAt DateTime @updatedAt @map("updated_at")
258
+
259
+ teamId String @map("team_id")
260
+ team Team @relation("TeamToSkill", fields: [teamId], references: [id], onDelete: Cascade)
261
+
262
+ agentSkills AgentSkill[]
263
+
264
+ @@unique([teamId, name])
265
+ @@map("skills")
266
+ }
267
+
268
+ model TeamMember {
269
+ id String @id @default(ulid())
270
+ role TeamMemberRole
271
+ scope TeamMemberScope @default(team)
272
+
273
+ teamId String @map("team_id")
274
+ team Team @relation("TeamToTeamMember", fields: [teamId], references: [id])
275
+
276
+ userId String @map("user_id")
277
+ user User @relation("UserToTeamMember", fields: [userId], references: [id], onDelete: Cascade)
278
+
279
+ projectMembers ProjectMember[] @relation("TeamMemberToProjectMember")
280
+ lastReadNotificationId String? @unique @map("last_read_notification_id")
281
+ lastReadNotification Notification? @relation("TeamMemberToLastReadNotification", fields: [lastReadNotificationId], references: [id])
282
+
283
+ @@map("team_members")
284
+ @@unique([teamId, userId], name: "teamIdUserId")
285
+ }
286
+
287
+ model Project {
288
+ id String @id @default(ulid())
289
+ name String
290
+ coverImageKey String? @map("cover_image_key")
291
+ /// [MetadataOverrides]
292
+ metadataOverrides Json? @map("metadata_overrides")
293
+ enableNotification Boolean @default(true) @map("enable_notification")
294
+ createdAt DateTime @default(now()) @map("created_at")
295
+ updatedAt DateTime @updatedAt @map("updated_at")
296
+
297
+ teamId String @map("team_id")
298
+ team Team @relation("TeamToProject", fields: [teamId], references: [id])
299
+
300
+ rootFolderId String? @unique @map("root_folder_id")
301
+ rootFolder Asset? @relation("ProjectToRootFolder", fields: [rootFolderId], references: [id])
302
+
303
+ shareRootId String? @unique @map("share_root_id")
304
+ shareRoot Asset? @relation("ProjectToShareRoot", fields: [shareRootId], references: [id])
305
+
306
+ members ProjectMember[] @relation("ProjectToProjectMember")
307
+ assets Asset[] @relation("ProjectToAsset")
308
+ metadataFields MetadataField[] @relation("ProjectToMetadataField")
309
+ invites Invite[] @relation("ProjectToInvite")
310
+ notifications Notification[] @relation("ProjectToNotification")
311
+ shareLinks ShareLink[] @relation("ProjectToShareLink")
312
+ collections Collection[] @relation("ProjectToCollection")
313
+
314
+ @@map("projects")
315
+ @@index([createdAt])
316
+ @@index([updatedAt])
317
+ }
318
+
319
+ model ProjectMember {
320
+ id String @id @default(ulid())
321
+ role ProjectMemberRole
322
+
323
+ projectId String @map("project_id")
324
+ project Project @relation("ProjectToProjectMember", fields: [projectId], references: [id], onDelete: Cascade)
325
+
326
+ teamMemberId String @map("team_member_id")
327
+ teamMember TeamMember @relation("TeamMemberToProjectMember", fields: [teamMemberId], references: [id])
328
+
329
+ @@map("project_members")
330
+ @@unique([projectId, teamMemberId], name: "projectIdTeamMemberId")
331
+ }
332
+
333
+ model ShareLink {
334
+ id String @id @default(ulid())
335
+ name String
336
+ expireAt DateTime? @map("expire_at")
337
+ password String?
338
+ isDisabled Boolean @default(false) @map("is_disabled")
339
+ defaultSortOrder String? @map("default_sort_order")
340
+ /// [ShareLinkFieldVisibility]
341
+ fieldVisibility Json? @map("field_visibility")
342
+ createdAt DateTime @default(now()) @map("created_at")
343
+ updatedAt DateTime @updatedAt @map("updated_at")
344
+
345
+ projectId String @map("project_id")
346
+ project Project @relation("ProjectToShareLink", fields: [projectId], references: [id], onDelete: Cascade)
347
+
348
+ rootFolderId String @unique @map("root_folder_id")
349
+ rootFolder Asset @relation("ShareLinkToRootFolder", fields: [rootFolderId], references: [id])
350
+
351
+ creatorId String? @map("creator_id")
352
+ creator User? @relation("UserToShareLink", fields: [creatorId], references: [id])
353
+
354
+ @@map("share_links")
355
+ }
356
+
357
+ model Asset {
358
+ id String @id @default(ulid())
359
+ name String @default("")
360
+ nameNgram String[] @default([]) @map("name_ngram")
361
+ type AssetType
362
+ mediaType String? @map("media_type")
363
+ fileCount Int @default(0) @map("file_count")
364
+ sizeByte Int @default(0) @map("size_byte")
365
+ status AssetStatus
366
+ transcodeTaskId String? @map("transcode_task_id")
367
+ /// [MediaInfo]
368
+ media Json?
369
+ isDeleted Boolean @default(false) @map("is_deleted")
370
+ deletedAt DateTime? @map("deleted_at")
371
+ sortIndex String? @map("sort_index")
372
+ createdAt DateTime @default(now()) @map("created_at")
373
+ updatedAt DateTime @updatedAt @map("updated_at")
374
+
375
+ parentId String? @map("parent_id")
376
+ parent Asset? @relation("AssetChildren", fields: [parentId], references: [id])
377
+ children Asset[] @relation("AssetChildren")
378
+
379
+ targetId String? @map("target_id")
380
+ target Asset? @relation("SymlinkTarget", fields: [targetId], references: [id])
381
+ symlinks Asset[] @relation("SymlinkTarget")
382
+
383
+ storageKeyId String? @map("storage_key_id")
384
+ storageKey StorageKey? @relation(fields: [storageKeyId], references: [id])
385
+
386
+ metadataValues AssetMetadataValue[] @relation("AssetToMetadataValues")
387
+
388
+ creatorId String? @map("creator_id")
389
+ creator User? @relation("UserToAsset", fields: [creatorId], references: [id])
390
+
391
+ taskId String? @map("task_id")
392
+ task Task? @relation("TaskToAsset", fields: [taskId], references: [id])
393
+
394
+ projectId String? @map("project_id")
395
+ project Project? @relation("ProjectToAsset", fields: [projectId], references: [id])
396
+
397
+ comments AssetComment[] @relation("AssetToComment")
398
+ commentAttachments AssetCommentAttachment[] @relation("AssetToCommentAttachment")
399
+ notifications Notification[] @relation("AssetToNotification")
400
+ embeddings AssetEmbedding[] @relation("AssetToEmbedding")
401
+
402
+ teamRootFolder Team? @relation("TeamToRootFolder")
403
+ projectRootFolder Project? @relation("ProjectToRootFolder")
404
+ projectShareRoot Project? @relation("ProjectToShareRoot")
405
+ shareLinkRootFolder ShareLink? @relation("ShareLinkToRootFolder")
406
+ agentSessions AgentSession[] @relation("AssetToAgentSession")
407
+
408
+ @@map("assets")
409
+ @@index([type])
410
+ @@index([status])
411
+ @@index([createdAt])
412
+ @@index([updatedAt])
413
+ @@index([sortIndex])
414
+ @@index([isDeleted])
415
+ @@index([deletedAt])
416
+ @@index([name], name: "assets_name_idx")
417
+ @@index([nameNgram], type: Gin)
418
+ @@unique([parentId, targetId], name: "parentIdTargetId")
419
+ }
420
+
421
+ model StorageKey {
422
+ id String @id @default(ulid())
423
+ key String @unique
424
+ status StorageKeyStatus @default(active)
425
+ createdAt DateTime @default(now()) @map("created_at")
426
+ updatedAt DateTime @updatedAt @map("updated_at")
427
+ assets Asset[]
428
+
429
+ @@map("storage_keys")
430
+ }
431
+
432
+ model AssetMetadataValue {
433
+ id String @id @default(ulid())
434
+ assetId String @map("asset_id")
435
+ fieldKey String @map("field_key") // key from MetadataField
436
+
437
+ stringValue String? @map("string_value")
438
+ numberValue Float? @map("number_value")
439
+ booleanValue Boolean? @map("boolean_value")
440
+ jsonValue Json? @map("json_value")
441
+ dateValue DateTime? @map("date_value")
442
+
443
+ asset Asset @relation("AssetToMetadataValues", fields: [assetId], references: [id], onDelete: Cascade)
444
+
445
+ @@unique([assetId, fieldKey])
446
+ @@index([numberValue])
447
+ @@index([stringValue])
448
+ @@index([booleanValue])
449
+ @@index([dateValue])
450
+ @@index([jsonValue], type: Gin)
451
+ @@map("asset_metadata_values")
452
+ }
453
+
454
+ model AssetComment {
455
+ id String @id @default(ulid())
456
+ message String?
457
+ /// [AnnotationList]
458
+ annotation Json?
459
+ second Float?
460
+ sessionId String? @map("session_id")
461
+ session AgentSession? @relation(fields: [sessionId], references: [id], onDelete: SetNull)
462
+ createdAt DateTime @default(now()) @map("created_at")
463
+ updatedAt DateTime @updatedAt @map("updated_at")
464
+
465
+ assetId String @map("asset_id")
466
+ asset Asset @relation("AssetToComment", fields: [assetId], references: [id], onDelete: Cascade)
467
+
468
+ creatorId String? @map("creator_id")
469
+ creator User? @relation("UserToAssetComment", fields: [creatorId], references: [id])
470
+
471
+ replyToId String? @map("reply_to_id")
472
+ replyTo AssetComment? @relation("CommentReplies", fields: [replyToId], references: [id], onDelete: Cascade)
473
+ replies AssetComment[] @relation("CommentReplies")
474
+
475
+ attachments AssetCommentAttachment[] @relation("CommentToAttachment")
476
+
477
+ @@map("asset_comments")
478
+ }
479
+
480
+ model AssetCommentAttachment {
481
+ id String @id @default(ulid())
482
+ createdAt DateTime @default(now()) @map("created_at")
483
+ updatedAt DateTime @updatedAt @map("updated_at")
484
+
485
+ commentId String @map("comment_id")
486
+ comment AssetComment @relation("CommentToAttachment", fields: [commentId], references: [id], onDelete: Cascade)
487
+
488
+ assetId String @map("asset_id")
489
+ asset Asset @relation("AssetToCommentAttachment", fields: [assetId], references: [id], onDelete: Cascade)
490
+
491
+ @@map("asset_comment_attachments")
492
+ }
493
+
494
+ model AssetEmbedding {
495
+ id String @id @default(ulid())
496
+ embedding Unsupported("vector(1536)")?
497
+ startTime Float? @map("start_time")
498
+ endTime Float? @map("end_time")
499
+ createdAt DateTime @default(now()) @map("created_at")
500
+ updatedAt DateTime @updatedAt @map("updated_at")
501
+
502
+ assetId String @map("asset_id")
503
+ asset Asset @relation("AssetToEmbedding", fields: [assetId], references: [id], onDelete: Cascade)
504
+
505
+ @@index([embedding], name: "AssetEmbedding_embedding_idx")
506
+ @@map("asset_embeddings")
507
+ }
508
+
509
+ model Invite {
510
+ id String @id @default(ulid())
511
+ code String @unique
512
+ role InviteRole?
513
+ used Boolean @default(false)
514
+ createdAt DateTime @default(now()) @map("created_at")
515
+ updatedAt DateTime @updatedAt @map("updated_at")
516
+
517
+ teamId String @map("team_id")
518
+ team Team @relation("TeamToInvite", fields: [teamId], references: [id])
519
+
520
+ projectId String? @map("project_id")
521
+ project Project? @relation("ProjectToInvite", fields: [projectId], references: [id], onDelete: Cascade)
522
+
523
+ inviterId String @map("inviter_id")
524
+ inviter User @relation("UserToInvite", fields: [inviterId], references: [id])
525
+
526
+ @@map("invites")
527
+ }
528
+
529
+ model MetadataField {
530
+ id String @id @default(ulid())
531
+ key String @unique
532
+ scope MetadataFieldScope?
533
+ /// [FieldConfig]
534
+ config Json?
535
+ readOnly Boolean @default(false) @map("read_only")
536
+ aiAutofill Boolean @default(false) @map("ai_autofill")
537
+ description String @default("")
538
+
539
+ teamId String? @map("team_id")
540
+ team Team? @relation("TeamToMetadataField", fields: [teamId], references: [id])
541
+
542
+ projectId String? @map("project_id")
543
+ project Project? @relation("ProjectToMetadataField", fields: [projectId], references: [id], onDelete: Cascade)
544
+
545
+ @@map("metadata_fields")
546
+ }
547
+
548
+ model Notification {
549
+ id String @id @default(ulid())
550
+ type NotificationType?
551
+ createdAt DateTime @default(now()) @map("created_at")
552
+ updatedAt DateTime @updatedAt @map("updated_at")
553
+
554
+ teamId String @map("team_id")
555
+ team Team @relation("TeamToNotification", fields: [teamId], references: [id])
556
+
557
+ projectId String? @map("project_id")
558
+ project Project? @relation("ProjectToNotification", fields: [projectId], references: [id], onDelete: Cascade)
559
+
560
+ creatorId String? @map("creator_id")
561
+ creator User? @relation("UserToCreatedNotification", fields: [creatorId], references: [id])
562
+
563
+ assetId String? @map("asset_id")
564
+ asset Asset? @relation("AssetToNotification", fields: [assetId], references: [id], onDelete: Cascade)
565
+
566
+ taskId String? @map("task_id")
567
+ task Task? @relation("TaskToNotification", fields: [taskId], references: [id])
568
+
569
+ userId String? @map("user_id")
570
+ user User? @relation("UserToNotification", fields: [userId], references: [id])
571
+
572
+ readByMembers TeamMember? @relation("TeamMemberToLastReadNotification")
573
+
574
+ @@map("notifications")
575
+ }
576
+
577
+ model SystemSettings {
578
+ id String @id @default(ulid())
579
+ key String @unique
580
+ /// [SystemSettingsValue]
581
+ value Json?
582
+ createdAt DateTime @default(now()) @map("created_at")
583
+ updatedAt DateTime @updatedAt @map("updated_at")
584
+
585
+ @@map("system_settings")
586
+ @@index([key])
587
+ }
588
+
589
+ model Task {
590
+ id String @id @default(ulid())
591
+ type TaskType?
592
+ status TaskStatus @default(pending)
593
+ name String?
594
+ total Int?
595
+ uploaded Int @default(0)
596
+ createdAt DateTime @default(now()) @map("created_at")
597
+ updatedAt DateTime @updatedAt @map("updated_at")
598
+
599
+ creatorId String? @map("creator_id")
600
+ creator User? @relation("UserToTask", fields: [creatorId], references: [id])
601
+
602
+ assets Asset[] @relation("TaskToAsset")
603
+ notifications Notification[] @relation("TaskToNotification")
604
+
605
+ @@map("tasks")
606
+ }
607
+
608
+ model WorkflowTask {
609
+ id String @id @default(ulid())
610
+ uid String @default(uuid()) @db.Uuid
611
+ teamId String? @map("team_id")
612
+ projectId String? @map("project_id")
613
+ assetId String @map("asset_id")
614
+ type WorkflowTaskType?
615
+ status WorkflowTaskStatus?
616
+ /// [WorkflowTaskPayload]
617
+ payload Json?
618
+ /// [WorkflowTaskOutput]
619
+ output Json?
620
+ heartbeat DateTime?
621
+ inputTokens Int @default(0) @map("input_tokens")
622
+ outputTokens Int @default(0) @map("output_tokens")
623
+ model String?
624
+ createdAt DateTime @default(now()) @map("created_at")
625
+ updatedAt DateTime @updatedAt @map("updated_at")
626
+
627
+ @@map("workflow_tasks")
628
+ @@index([status, heartbeat])
629
+ @@index([assetId, type])
630
+ @@index([teamId])
631
+ @@index([projectId])
632
+ @@index([type])
633
+ }
634
+ enum AgentType {
635
+ chat
636
+ autofill
637
+ embedding
638
+ }
639
+
640
+ model Agent {
641
+ id String @id
642
+ user User @relation(fields: [id], references: [id], onDelete: Cascade)
643
+ type AgentType
644
+ enabled Boolean @default(true)
645
+ soul String? @db.Text
646
+ providerId String? @map("provider_id")
647
+ provider Provider? @relation("ProviderToAgent", fields: [providerId], references: [id], onDelete: SetNull)
648
+ modelId String? @map("model_id")
649
+ modelRef Model? @relation("ModelToAgent", fields: [modelId], references: [id], onDelete: SetNull)
650
+
651
+ teamId String @map("team_id")
652
+ team Team @relation("TeamToAgent", fields: [teamId], references: [id], onDelete: Cascade)
653
+
654
+ /// [AgentConfig]
655
+ config Json
656
+ createdAt DateTime @default(now()) @map("created_at")
657
+ updatedAt DateTime @updatedAt @map("updated_at")
658
+ agentSessions AgentSession[]
659
+ skills AgentSkill[]
660
+
661
+ @@map("agents")
662
+ }
663
+
664
+ model AgentSkill {
665
+ id String @id @default(ulid())
666
+ agentId String @map("agent_id")
667
+ agent Agent @relation(fields: [agentId], references: [id], onDelete: Cascade)
668
+ skillId String @map("skill_id")
669
+ skill Skill @relation(fields: [skillId], references: [id], onDelete: Cascade)
670
+ createdAt DateTime @default(now()) @map("created_at")
671
+ updatedAt DateTime @updatedAt @map("updated_at")
672
+
673
+ @@unique([agentId, skillId])
674
+ @@map("agent_skills")
675
+ }
676
+
677
+ model AgentSession {
678
+ id String @id @default(ulid())
679
+ agentId String @map("agent_id")
680
+ agent Agent @relation(fields: [agentId], references: [id], onDelete: Cascade)
681
+ userId String? @map("user_id")
682
+ user User? @relation(fields: [userId], references: [id], onDelete: SetNull)
683
+ cwd String
684
+ leafId String? @map("leaf_id")
685
+ assetId String? @map("asset_id")
686
+ asset Asset? @relation("AssetToAgentSession", fields: [assetId], references: [id], onDelete: Cascade)
687
+ userCommentId String? @map("user_comment_id")
688
+ createdAt DateTime @default(now()) @map("created_at")
689
+ updatedAt DateTime @updatedAt @map("updated_at")
690
+ entries AgentSessionEntry[]
691
+ comments AssetComment[]
692
+
693
+ @@map("agent_sessions")
694
+ }
695
+
696
+ model AgentSessionEntry {
697
+ id String @id // Uses ULID generated by pi-coding-agent
698
+ sessionId String @map("session_id")
699
+ session AgentSession @relation(fields: [sessionId], references: [id], onDelete: Cascade)
700
+ /// [PiSessionEntry]
701
+ entry Json
702
+
703
+ @@map("agent_session_entries")
704
+ @@index([sessionId])
705
+ }
706
+
707
+ model UserMetadata {
708
+ id String @id @default(ulid())
709
+ key String
710
+ /// [UserMetadataValue]
711
+ value Json
712
+ createdAt DateTime @default(now()) @map("created_at")
713
+ updatedAt DateTime @updatedAt @map("updated_at")
714
+
715
+ userId String @map("user_id")
716
+ user User @relation("UserToUserMetadata", fields: [userId], references: [id], onDelete: Cascade)
717
+
718
+ teamId String @map("team_id")
719
+ team Team @relation("TeamToUserMetadata", fields: [teamId], references: [id], onDelete: Cascade)
720
+
721
+ @@unique([userId, teamId, key], name: "userIdTeamIdKey")
722
+ @@map("user_metadata")
723
+ }
724
+
725
+ model Model {
726
+ id String @id @default(ulid())
727
+ modelId String @map("model_id")
728
+ name String @default("")
729
+ /// [ModelConfig]
730
+ config Json
731
+ createdAt DateTime @default(now()) @map("created_at")
732
+ updatedAt DateTime @updatedAt @map("updated_at")
733
+
734
+ providerId String @map("provider_id")
735
+ provider Provider @relation("ProviderToModel", fields: [providerId], references: [id], onDelete: Cascade)
736
+
737
+ agents Agent[] @relation("ModelToAgent")
738
+
739
+ @@unique([providerId, modelId])
740
+ @@map("models")
741
+ }
742
+
743
+ model Provider {
744
+ id String @id @default(ulid())
745
+ name String
746
+ isBuiltin Boolean @default(false) @map("is_builtin")
747
+ /// [ProviderConfig]
748
+ config Json
749
+ createdAt DateTime @default(now()) @map("created_at")
750
+ updatedAt DateTime @updatedAt @map("updated_at")
751
+
752
+ teamId String @map("team_id")
753
+ team Team @relation("TeamToProvider", fields: [teamId], references: [id], onDelete: Cascade)
754
+
755
+ models Model[] @relation("ProviderToModel")
756
+ agents Agent[] @relation("ProviderToAgent")
757
+
758
+ @@unique([teamId, name])
759
+ @@map("providers")
760
+ }
761
+
762
+ model Collection {
763
+ id String @id @default(ulid())
764
+ name String
765
+ /// [CollectionFilter]
766
+ filter Json
767
+ createdAt DateTime @default(now()) @map("created_at")
768
+ updatedAt DateTime @updatedAt @map("updated_at")
769
+
770
+ projectId String @map("project_id")
771
+ project Project @relation("ProjectToCollection", fields: [projectId], references: [id], onDelete: Cascade)
772
+
773
+ creatorId String? @map("creator_id")
774
+ creator User? @relation("UserToCollection", fields: [creatorId], references: [id])
775
+
776
+ @@index([projectId, createdAt(sort: Desc)])
777
+ @@map("collections")
778
+ }