Skip to content

Commit 3e02cd5

Browse files
committed
fix: subchat using same app capture, get threads for subchat filter by tool call id
1 parent 1200ae1 commit 3e02cd5

File tree

2 files changed

+38
-32
lines changed

2 files changed

+38
-32
lines changed

refact-agent/engine/src/cloud/subchat.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::sync::Arc;
22
use std::sync::atomic::Ordering;
33
use futures::StreamExt;
44
use crate::at_commands::at_commands::AtCommandsContext;
5+
use crate::global_context::APP_CAPTURE_ID;
56
use tokio::sync::Mutex as AMutex;
67
use crate::call_validation::{ChatMessage, ReasoningEffort};
78
use crate::cloud::{threads_req, messages_req};
@@ -71,7 +72,8 @@ pub async fn subchat(
7172
&api_key,
7273
&located_fgroup_id,
7374
&app_searchable_id,
74-
tool_call_id
75+
APP_CAPTURE_ID,
76+
Some(tool_call_id),
7577
).await?;
7678
let thread = if !existing_threads.is_empty() {
7779
info!("There are already existing threads for this tool_id: {:?}", existing_threads);
@@ -83,14 +85,13 @@ pub async fn subchat(
8385
&located_fgroup_id,
8486
ft_fexp_id,
8587
&format!("subchat_{}", ft_fexp_id),
86-
&tool_call_id,
88+
APP_CAPTURE_ID,
8789
&app_searchable_id,
8890
serde_json::json!({
89-
"tool_call_id": tool_call_id,
90-
"ft_fexp_id": ft_fexp_id,
91-
}),
91+
"tool_call_id": tool_call_id,
92+
"ft_fexp_id": ft_fexp_id,
93+
}),
9294
None,
93-
Some(parent_thread_id)
9495
).await?;
9596
let thread_messages = messages_req::convert_messages_to_thread_messages(
9697
messages, 100, 100, 1, &thread.ft_id, Some(preferences)

refact-agent/engine/src/cloud/threads_req.rs

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@ pub async fn create_thread(
3232
ft_app_searchable: &str,
3333
ft_app_specific: Value,
3434
ft_toolset: Option<Vec<Value>>,
35-
parent_ft_id: Option<String>,
3635
) -> Result<Thread, String> {
3736
use crate::cloud::graphql_client::{execute_graphql, GraphQLRequestConfig};
38-
37+
3938
let mutation = r#"
4039
mutation CreateThread($input: FThreadInput!) {
4140
thread_create(input: $input) {
@@ -64,8 +63,8 @@ pub async fn create_thread(
6463
Some(toolset) => serde_json::to_string(&toolset).map_err(|e| format!("Failed to serialize toolset: {}", e))?,
6564
None => "null".to_string(),
6665
};
67-
68-
let mut input = json!({
66+
67+
let input = json!({
6968
"owner_shared": false,
7069
"located_fgroup_id": located_fgroup_id,
7170
"ft_fexp_id": ft_fexp_id,
@@ -76,10 +75,6 @@ pub async fn create_thread(
7675
"ft_app_specific": serde_json::to_string(&ft_app_specific).unwrap(),
7776
});
7877

79-
if let Some(parent_id) = parent_ft_id {
80-
input["parent_ft_id"] = json!(parent_id);
81-
}
82-
8378
let config = GraphQLRequestConfig {
8479
address: cmd_address_url.to_string(),
8580
api_key: api_key.to_string(),
@@ -104,7 +99,7 @@ pub async fn get_thread(
10499
thread_id: &str,
105100
) -> Result<Thread, String> {
106101
use crate::cloud::graphql_client::{execute_graphql, GraphQLRequestConfig};
107-
102+
108103
let query = r#"
109104
query GetThread($id: String!) {
110105
thread_get(id: $id) {
@@ -151,12 +146,18 @@ pub async fn get_threads_app_captured(
151146
located_fgroup_id: &str,
152147
ft_app_searchable: &str,
153148
ft_app_capture: &str,
149+
tool_call_id: Option<&str>,
154150
) -> Result<Vec<Thread>, String> {
155151
use crate::cloud::graphql_client::{execute_graphql, GraphQLRequestConfig};
156-
152+
157153
let query = r#"
158-
query GetThread($located_fgroup_id: String!, $ft_app_capture: String!, $ft_app_searchable: String!) {
159-
threads_app_captured(located_fgroup_id: $located_fgroup_id, ft_app_capture: $ft_app_capture, ft_app_searchable: $ft_app_searchable) {
154+
query GetThread($located_fgroup_id: String!, $ft_app_capture: String!, $ft_app_searchable: String!, $ft_app_specific_filters: [FTAppSpecificFilter!]) {
155+
threads_app_captured(
156+
located_fgroup_id: $located_fgroup_id,
157+
ft_app_capture: $ft_app_capture,
158+
ft_app_searchable: $ft_app_searchable,
159+
ft_app_specific_filters: $ft_app_specific_filters
160+
) {
160161
owner_fuser_id
161162
owner_shared
162163
located_fgroup_id
@@ -187,7 +188,11 @@ pub async fn get_threads_app_captured(
187188
let variables = json!({
188189
"located_fgroup_id": located_fgroup_id,
189190
"ft_app_capture": ft_app_capture,
190-
"ft_app_searchable": ft_app_searchable
191+
"ft_app_searchable": ft_app_searchable,
192+
"ft_app_specific_filters": match tool_call_id {
193+
Some(id) => vec![json!({ "path": "tool_call_id", "equals": id })],
194+
None => Vec::new(),
195+
},
191196
});
192197
tracing::info!("get_threads_app_captured: address={}, located_fgroup_id={}, ft_app_capture={}, ft_app_searchable={}",
193198
config.address, located_fgroup_id, ft_app_capture, ft_app_searchable
@@ -209,15 +214,15 @@ pub async fn set_thread_toolset(
209214
ft_toolset: Vec<Value>
210215
) -> Result<Vec<Value>, String> {
211216
use crate::cloud::graphql_client::{execute_graphql, GraphQLRequestConfig};
212-
217+
213218
let mutation = r#"
214219
mutation UpdateThread($thread_id: String!, $patch: FThreadPatch!) {
215220
thread_patch(id: $thread_id, patch: $patch) {
216221
ft_toolset
217222
}
218223
}
219224
"#;
220-
225+
221226
let variables = json!({
222227
"thread_id": thread_id,
223228
"patch": {
@@ -258,12 +263,12 @@ pub async fn lock_thread(
258263
hash: &str,
259264
) -> Result<(), String> {
260265
use crate::cloud::graphql_client::{execute_graphql_bool_result, GraphQLRequestConfig};
261-
266+
262267
let worker_name = format!("refact-lsp:{hash}");
263268
let query = r#"
264269
mutation AdvanceLock($ft_id: String!, $worker_name: String!) {
265270
thread_lock(ft_id: $ft_id, worker_name: $worker_name)
266-
}
271+
}
267272
"#;
268273

269274
let config = GraphQLRequestConfig {
@@ -273,7 +278,7 @@ pub async fn lock_thread(
273278
};
274279

275280
let variables = json!({
276-
"ft_id": thread_id,
281+
"ft_id": thread_id,
277282
"worker_name": worker_name
278283
});
279284

@@ -303,7 +308,7 @@ pub async fn unlock_thread(
303308
hash: &str,
304309
) -> Result<(), String> {
305310
use crate::cloud::graphql_client::{execute_graphql_bool_result, GraphQLRequestConfig};
306-
311+
307312
let worker_name = format!("refact-lsp:{hash}");
308313
let query = r#"
309314
mutation AdvanceUnlock($ft_id: String!, $worker_name: String!) {
@@ -318,7 +323,7 @@ pub async fn unlock_thread(
318323
};
319324

320325
let variables = json!({
321-
"ft_id": thread_id,
326+
"ft_id": thread_id,
322327
"worker_name": worker_name
323328
});
324329

@@ -348,15 +353,15 @@ pub async fn set_error_thread(
348353
error: &str,
349354
) -> Result<(), String> {
350355
use crate::cloud::graphql_client::{execute_graphql_no_result, GraphQLRequestConfig};
351-
356+
352357
let mutation = r#"
353358
mutation SetThreadError($thread_id: String!, $patch: FThreadPatch!) {
354359
thread_patch(id: $thread_id, patch: $patch) {
355360
ft_error
356361
}
357362
}
358363
"#;
359-
364+
360365
let variables = json!({
361366
"thread_id": thread_id,
362367
"patch": {
@@ -369,7 +374,7 @@ pub async fn set_error_thread(
369374
api_key: api_key.to_string(),
370375
..Default::default()
371376
};
372-
377+
373378
tracing::info!("unlock_thread: address={}, thread_id={}, ft_error={}",
374379
config.address, thread_id, error
375380
);
@@ -390,16 +395,16 @@ pub async fn set_thread_confirmation_request(
390395
confirmation_request: Value,
391396
) -> Result<bool, String> {
392397
use crate::cloud::graphql_client::{execute_graphql_bool_result, GraphQLRequestConfig};
393-
398+
394399
let mutation = r#"
395400
mutation SetThreadConfirmationRequest($ft_id: String!, $confirmation_request: String!) {
396401
thread_set_confirmation_request(ft_id: $ft_id, confirmation_request: $confirmation_request)
397402
}
398403
"#;
399-
404+
400405
let confirmation_request_str = serde_json::to_string(&confirmation_request)
401406
.map_err(|e| format!("Failed to serialize confirmation request: {}", e))?;
402-
407+
403408
let variables = json!({
404409
"ft_id": thread_id,
405410
"confirmation_request": confirmation_request_str

0 commit comments

Comments
 (0)