Skip to content

Commit

Permalink
feat(db): add code_source_id column to thread_messages table (TabbyML…
Browse files Browse the repository at this point in the history
…#3571)

* feat(db): add code_source_id column to thread_messages table

* feat(graphql/thread): add code_source_id to thread message attachments

* refactor(answer.rs): make test pass

* [autofix.ci] apply automated fixes

* [autofix.ci] apply automated fixes (attempt 2/3)

* feat(testutils): enhance mock AccessPolicy and add sample CodeSearch hits

* chore: make the test with reason Fake Repository and Useful ContextHelperInfo

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Jackson Chen <[email protected]>
  • Loading branch information
3 people authored Dec 17, 2024
1 parent 115b194 commit 7fffacb
Show file tree
Hide file tree
Showing 12 changed files with 936 additions and 792 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE thread_messages
DROP code_source_id;
2 changes: 2 additions & 0 deletions ee/tabby-db/migrations/0040_add-code-source-id-column.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE thread_messages
ADD code_source_id VARCHAR(255);
Binary file modified ee/tabby-db/schema.sqlite
Binary file not shown.
1 change: 1 addition & 0 deletions ee/tabby-db/schema/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ CREATE TABLE thread_messages(
doc_attachments BLOB,
created_at TIMESTAMP NOT NULL DEFAULT(DATETIME('now')),
updated_at TIMESTAMP NOT NULL DEFAULT(DATETIME('now')),
code_source_id VARCHAR(255),
FOREIGN KEY(thread_id) REFERENCES threads(id) ON DELETE CASCADE
);
CREATE TABLE web_documents(
Expand Down
1,298 changes: 651 additions & 647 deletions ee/tabby-db/schema/schema.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion ee/tabby-db/src/threads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ pub struct ThreadMessageDAO {
pub role: String,
pub content: String,

pub code_source_id: Option<String>,

pub code_attachments: Option<Json<Vec<ThreadMessageAttachmentCode>>>,
pub client_code_attachments: Option<Json<Vec<ThreadMessageAttachmentClientCode>>>,
pub doc_attachments: Option<Json<Vec<ThreadMessageAttachmentDoc>>>,
Expand Down Expand Up @@ -223,12 +225,14 @@ impl DbConn {
pub async fn update_thread_message_code_attachments(
&self,
message_id: i64,
code_source_id: &str,
code_attachments: &[ThreadMessageAttachmentCode],
) -> Result<()> {
let code_attachments = Json(code_attachments);
query!(
"UPDATE thread_messages SET code_attachments = ?, updated_at = DATETIME('now') WHERE id = ?",
"UPDATE thread_messages SET code_attachments = ?, code_source_id = ?, updated_at = DATETIME('now') WHERE id = ?",
code_attachments,
code_source_id,
message_id
)
.execute(&self.pool)
Expand Down Expand Up @@ -296,6 +300,7 @@ impl DbConn {
thread_id,
role,
content,
code_source_id,
code_attachments as "code_attachments: Json<Vec<ThreadMessageAttachmentCode>>",
client_code_attachments as "client_code_attachments: Json<Vec<ThreadMessageAttachmentClientCode>>",
doc_attachments as "doc_attachments: Json<Vec<ThreadMessageAttachmentDoc>>",
Expand Down Expand Up @@ -329,6 +334,7 @@ impl DbConn {
"thread_id",
"role",
"content",
"code_source_id",
"code_attachments" as "code_attachments: Json<Vec<ThreadMessageAttachmentCode>>",
"client_code_attachments" as "client_code_attachments: Json<Vec<ThreadMessageAttachmentClientCode>>",
"doc_attachments" as "doc_attachments: Json<Vec<ThreadMessageAttachmentDoc>>",
Expand Down
1 change: 1 addition & 0 deletions ee/tabby-schema/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,7 @@ type Thread {
}

type ThreadAssistantMessageAttachmentsCode {
codeSourceId: String!
hits: [MessageCodeSearchHit!]!
}

Expand Down
1 change: 1 addition & 0 deletions ee/tabby-schema/src/schema/thread/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ pub struct ThreadAssistantMessageCreated {

#[derive(GraphQLObject)]
pub struct ThreadAssistantMessageAttachmentsCode {
pub code_source_id: String,
pub hits: Vec<MessageCodeSearchHit>,
}

Expand Down
9 changes: 3 additions & 6 deletions ee/tabby-webserver/src/service/access_policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,8 @@ pub mod testutils {

use super::*;

pub async fn make_policy() -> AccessPolicy {
AccessPolicy::new(
DbConn::new_in_memory().await.unwrap(),
&ID::from("nihao".to_string()),
false,
)
/// create a mock `AccessPolicy` for testing with admin permissions
pub async fn make_policy(db: DbConn) -> AccessPolicy {
AccessPolicy::new(db.clone(), &ID::from("nihao".to_string()), true)
}
}
Loading

0 comments on commit 7fffacb

Please sign in to comment.