Skip to content
Clone

feat(sagent): add collaboration and sandbox tables

ZhenYi committed
parent db1be6a commit 491f98e Browse files

8 files changed

+188 −0

File tree 8
Added lib/models/src/sagent/agent_artifact.rs View lib/models/src/sagent/agent_artifact.rs
@@ -0,0 +1,24 @@
1use sea_orm::entity::prelude::*;
2use time::OffsetDateTime;
3use uuid::Uuid;
4
5#[sea_orm::model]
6#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
7#[sea_orm(table_name = "agent_artifact")]
8pub struct Model {
9 #[sea_orm(primary_key, auto_increment = false)]
10 pub id: Uuid,
11 pub agent_id: Uuid,
12 pub run_id: Option<Uuid>,
13 pub kind: String,
14 pub name: String,
15 pub mime: Option<String>,
16 pub size: i64,
17 pub storage_key: String,
18 pub created_by: Option<Uuid>,
19 pub created_at: OffsetDateTime,
20 #[sea_orm(belongs_to, from = "agent_id", to = "id")]
21 pub agent: BelongsTo<super::agent::Entity>,
22}
23
24impl ActiveModelBehavior for ActiveModel {}
Added lib/models/src/sagent/agent_label.rs View lib/models/src/sagent/agent_label.rs
@@ -0,0 +1,24 @@
1use sea_orm::entity::prelude::*;
2use time::OffsetDateTime;
3use uuid::Uuid;
4
5#[sea_orm::model]
6#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
7#[sea_orm(table_name = "agent_label")]
8pub struct Model {
9 #[sea_orm(primary_key, auto_increment = false)]
10 pub id: Uuid,
11 pub dir_id: Uuid,
12 pub name: String,
13 pub exclusive: bool,
14 pub exclusive_order: i32,
15 pub description: Option<String>,
16 pub color: String,
17 pub is_archived: bool,
18 pub created_at: OffsetDateTime,
19 pub updated_at: Option<OffsetDateTime>,
20 #[sea_orm(belongs_to, from = "dir_id", to = "id")]
21 pub dir: BelongsTo<super::super::dir::dirs::Entity>,
22}
23
24impl ActiveModelBehavior for ActiveModel {}
Added lib/models/src/sagent/agent_member.rs View lib/models/src/sagent/agent_member.rs
@@ -0,0 +1,51 @@
1use sea_orm::entity::prelude::*;
2use serde::{Deserialize, Serialize};
3use time::OffsetDateTime;
4use uuid::Uuid;
5
6#[derive(
7 Debug,
8 Clone,
9 Copy,
10 PartialEq,
11 Eq,
12 Default,
13 EnumIter,
14 DeriveActiveEnum,
15 Serialize,
16 Deserialize,
17 utoipa::ToSchema,
18)]
19#[serde(rename_all = "snake_case")]
20#[sea_orm(rs_type = "i16", db_type = "SmallInteger")]
21pub enum AgentMemberKind {
22 #[default]
23 #[sea_orm(num_value = 0)]
24 Assignee,
25 #[sea_orm(num_value = 1)]
26 Mentioned,
27 #[sea_orm(num_value = 2)]
28 Participant,
29}
30
31#[sea_orm::model]
32#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
33#[sea_orm(table_name = "agent_member")]
34pub struct Model {
35 #[sea_orm(primary_key, auto_increment = false)]
36 pub id: Uuid,
37 #[sea_orm(unique_key = "agent_user_kind")]
38 pub agent_id: Uuid,
39 #[sea_orm(unique_key = "agent_user_kind")]
40 pub user_id: Uuid,
41 #[sea_orm(unique_key = "agent_user_kind")]
42 pub kind: AgentMemberKind,
43 pub created_at: OffsetDateTime,
44 pub updated_at: Option<OffsetDateTime>,
45 #[sea_orm(belongs_to, from = "agent_id", to = "id")]
46 pub agent: BelongsTo<super::agent::Entity>,
47 #[sea_orm(belongs_to, from = "user_id", to = "uid")]
48 pub user: BelongsTo<super::super::users::user::Entity>,
49}
50
51impl ActiveModelBehavior for ActiveModel {}
Added lib/models/src/sagent/agent_relation_label.rs View lib/models/src/sagent/agent_relation_label.rs
@@ -0,0 +1,22 @@
1use sea_orm::entity::prelude::*;
2use time::OffsetDateTime;
3use uuid::Uuid;
4
5#[sea_orm::model]
6#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
7#[sea_orm(table_name = "agent_relation_label")]
8pub struct Model {
9 #[sea_orm(primary_key, auto_increment = false)]
10 pub id: Uuid,
11 #[sea_orm(unique_key = "agent_label")]
12 pub agent_id: Uuid,
13 #[sea_orm(unique_key = "agent_label")]
14 pub label_id: Uuid,
15 pub created_at: OffsetDateTime,
16 #[sea_orm(belongs_to, from = "agent_id", to = "id")]
17 pub agent: BelongsTo<super::agent::Entity>,
18 #[sea_orm(belongs_to, from = "label_id", to = "id")]
19 pub label: BelongsTo<super::agent_label::Entity>,
20}
21
22impl ActiveModelBehavior for ActiveModel {}
Added lib/models/src/sagent/agent_relation_repo.rs View lib/models/src/sagent/agent_relation_repo.rs
@@ -0,0 +1,24 @@
1use sea_orm::entity::prelude::*;
2use time::OffsetDateTime;
3use uuid::Uuid;
4
5#[sea_orm::model]
6#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
7#[sea_orm(table_name = "agent_relation_repo")]
8pub struct Model {
9 #[sea_orm(primary_key, auto_increment = false)]
10 pub id: Uuid,
11 #[sea_orm(unique_key = "agent_repo")]
12 pub agent_id: Uuid,
13 #[sea_orm(unique_key = "agent_repo")]
14 pub repo_id: Uuid,
15 pub ref_name: Option<String>,
16 pub sub_path: Option<String>,
17 pub created_at: OffsetDateTime,
18 #[sea_orm(belongs_to, from = "agent_id", to = "id")]
19 pub agent: BelongsTo<super::agent::Entity>,
20 #[sea_orm(belongs_to, from = "repo_id", to = "id")]
21 pub repo: BelongsTo<super::super::repo::repos::Entity>,
22}
23
24impl ActiveModelBehavior for ActiveModel {}
Added lib/models/src/sagent/agent_user.rs View lib/models/src/sagent/agent_user.rs
@@ -0,0 +1,25 @@
1use sea_orm::entity::prelude::*;
2use time::OffsetDateTime;
3use uuid::Uuid;
4
5#[sea_orm::model]
6#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
7#[sea_orm(table_name = "agent_user")]
8pub struct Model {
9 #[sea_orm(primary_key, auto_increment = false)]
10 pub id: Uuid,
11 #[sea_orm(unique_key = "uid_agent")]
12 pub uid: Uuid,
13 #[sea_orm(unique_key = "uid_agent")]
14 pub agent_id: Uuid,
15 #[sea_orm(default_value = "0")]
16 pub last_read_seq: i64,
17 pub created_at: OffsetDateTime,
18 pub updated_at: Option<OffsetDateTime>,
19 #[sea_orm(belongs_to, from = "uid", to = "uid")]
20 pub user: BelongsTo<super::super::users::user::Entity>,
21 #[sea_orm(belongs_to, from = "agent_id", to = "id")]
22 pub agent: BelongsTo<super::agent::Entity>,
23}
24
25impl ActiveModelBehavior for ActiveModel {}
Modified lib/models/src/sagent/mod.rs View lib/models/src/sagent/mod.rs
@@ -1,7 +1,13 @@
11#![allow(clippy::module_inception)]
22
33pub mod agent;
4pub mod agent_artifact;
45pub mod agent_event_line;
6pub mod agent_label;
7pub mod agent_member;
58pub mod agent_message;
9pub mod agent_relation_label;
10pub mod agent_relation_repo;
11pub mod agent_user;
612pub mod agent_watch;
713pub mod agents;
Modified lib/models/schema_extras.sql View lib/models/schema_extras.sql
@@ -326,3 +326,15 @@
326326 ON agent_message (agent_id, created_at DESC);
327327CREATE INDEX IF NOT EXISTS idx_agent_event_line_agent_created
328328 ON agent_event_line (agent_id, created_at DESC);
329CREATE INDEX IF NOT EXISTS idx_agent_label_dir
330 ON agent_label (dir_id, is_archived);
331CREATE INDEX IF NOT EXISTS idx_agent_relation_label_label
332 ON agent_relation_label (label_id);
333CREATE INDEX IF NOT EXISTS idx_agent_member_user
334 ON agent_member (user_id, kind);
335CREATE INDEX IF NOT EXISTS idx_agent_user_agent
336 ON agent_user (agent_id);
337CREATE INDEX IF NOT EXISTS idx_agent_relation_repo_repo
338 ON agent_relation_repo (repo_id);
339CREATE INDEX IF NOT EXISTS idx_agent_artifact_agent_created
340 ON agent_artifact (agent_id, created_at DESC);