Skip to content

Commit

Permalink
fix(answer): properly handle user input attachment (#2865)
Browse files Browse the repository at this point in the history
* fix(answer): properly handle user input attachment

* update

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
wsxiaoys and autofix-ci[bot] authored Aug 13, 2024
1 parent 5d818ee commit 0c38d77
Show file tree
Hide file tree
Showing 12 changed files with 187 additions and 90 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion ee/tabby-db/src/threads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ pub struct ThreadMessageAttachmentDoc {

#[derive(Serialize, Deserialize)]
pub struct ThreadMessageAttachmentCode {
pub filepath: Option<String>,
pub git_url: String,
pub language: String,
pub filepath: String,
pub content: String,
pub start_line: usize,
}

impl DbConn {
Expand Down
6 changes: 4 additions & 2 deletions ee/tabby-schema/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -396,10 +396,12 @@ type MessageAttachment {
doc: [MessageAttachmentDoc!]!
}

"If you want to change the struct, please make sure the change is backward compatible."
type MessageAttachmentCode {
filepath: String
gitUrl: String!
filepath: String!
language: String!
content: String!
startLine: Int!
}

type MessageAttachmentDoc {
Expand Down
6 changes: 6 additions & 0 deletions ee/tabby-schema/src/dao.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,17 +233,23 @@ impl TryFrom<UserEventDAO> for UserEvent {
impl From<ThreadMessageAttachmentCode> for thread::MessageAttachmentCode {
fn from(value: ThreadMessageAttachmentCode) -> Self {
Self {
git_url: value.git_url,
filepath: value.filepath,
language: value.language,
content: value.content,
start_line: value.start_line as i32,
}
}
}

impl From<&thread::MessageAttachmentCode> for ThreadMessageAttachmentCode {
fn from(val: &thread::MessageAttachmentCode) -> Self {
ThreadMessageAttachmentCode {
git_url: val.git_url.clone(),
filepath: val.filepath.clone(),
language: val.language.clone(),
content: val.content.clone(),
start_line: val.start_line as usize,
}
}
}
Expand Down
18 changes: 15 additions & 3 deletions ee/tabby-schema/src/schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,13 @@ impl Subscription {
let thread_id = thread.create(&user.id, &input.thread).await?;

thread
.create_run(&thread_id, &input.options, true, true)
.create_run(
&thread_id,
&input.options,
input.thread.user_message.attachments.as_ref(),
true,
true,
)
.await
}

Expand Down Expand Up @@ -1029,8 +1035,14 @@ impl Subscription {
svc.append_user_message(&input.thread_id, &input.additional_user_message)
.await?;

svc.create_run(&input.thread_id, &input.options, true, false)
.await
svc.create_run(
&input.thread_id,
&input.options,
input.additional_user_message.attachments.as_ref(),
true,
false,
)
.await
}
}

Expand Down
1 change: 1 addition & 0 deletions ee/tabby-schema/src/schema/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub trait ThreadService: Send + Sync {
&self,
id: &ID,
options: &ThreadRunOptionsInput,
attachment_input: Option<&MessageAttachmentInput>,
yield_last_user_message: bool,
yield_thread_created: bool,
) -> Result<ThreadRunStream>;
Expand Down
5 changes: 2 additions & 3 deletions ee/tabby-schema/src/schema/thread/inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,13 @@ pub struct CreateThreadRunInput {
pub options: ThreadRunOptionsInput,
}

#[derive(GraphQLInputObject)]
#[derive(GraphQLInputObject, Clone)]
pub struct MessageAttachmentInput {
pub code: Vec<MessageAttachmentCodeInput>,
}

#[derive(GraphQLInputObject)]
#[derive(GraphQLInputObject, Clone)]
pub struct MessageAttachmentCodeInput {
pub filepath: Option<String>,

pub content: String,
}
6 changes: 4 additions & 2 deletions ee/tabby-schema/src/schema/thread/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ pub struct MessageAttachment {
pub doc: Vec<MessageAttachmentDoc>,
}

/// If you want to change the struct, please make sure the change is backward compatible.
#[derive(GraphQLObject, Clone)]
pub struct MessageAttachmentCode {
pub filepath: Option<String>,
pub git_url: String,
pub filepath: String,
pub language: String,
pub content: String,
pub start_line: i32,
}

#[derive(GraphQLObject, Clone)]
Expand Down
1 change: 1 addition & 0 deletions ee/tabby-webserver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,4 @@ tabby-db = { path = "../../ee/tabby-db", features = ["testutils"] }
tabby-common = { path = "../../crates/tabby-common", features = ["testutils"] }
serial_test = { workspace = true }
temp_testdir = { workspace = true }
insta = { workspace = true, features = ["yaml", "redactions"] }
Loading

0 comments on commit 0c38d77

Please sign in to comment.