@@ -175,6 +175,13 @@ pub fn job_routes(
175175 . and ( warp:: body:: json ( ) )
176176 . and_then ( remove_job_handler) ;
177177
178+ let remove_jobs_route = warp:: path ( "remove_jobs" )
179+ . and ( warp:: post ( ) )
180+ . and ( with_sender ( node_commands_sender. clone ( ) ) )
181+ . and ( warp:: header :: < String > ( "authorization" ) )
182+ . and ( warp:: body:: json ( ) )
183+ . and_then ( remove_jobs_handler) ;
184+
178185 let export_messages_from_inbox_route = warp:: path ( "export_messages_from_inbox" )
179186 . and ( warp:: post ( ) )
180187 . and ( with_sender ( node_commands_sender. clone ( ) ) )
@@ -216,6 +223,7 @@ pub fn job_routes(
216223 . or ( get_message_traces_route)
217224 . or ( fork_job_messages_route)
218225 . or ( remove_job_route)
226+ . or ( remove_jobs_route)
219227 . or ( export_messages_from_inbox_route)
220228 . or ( add_messages_god_mode_route)
221229 . or ( get_job_provider_route)
@@ -285,6 +293,11 @@ pub struct RemoveJobRequest {
285293 pub job_id : String ,
286294}
287295
296+ #[ derive( Deserialize , ToSchema ) ]
297+ pub struct RemoveJobsRequest {
298+ pub job_ids : Vec < String > ,
299+ }
300+
288301#[ derive( Deserialize , ToSchema ) ]
289302pub struct ExportInboxMessagesRequest {
290303 pub inbox_name : String ,
@@ -1249,6 +1262,45 @@ pub async fn remove_job_handler(
12491262 }
12501263}
12511264
1265+ #[ utoipa:: path(
1266+ post,
1267+ path = "/v2/remove_jobs" ,
1268+ request_body = RemoveJobsRequest ,
1269+ responses(
1270+ ( status = 200 , description = "Successfully removed jobs in bulk" , body = Value ) ,
1271+ ( status = 400 , description = "Bad request" , body = APIError ) ,
1272+ ( status = 500 , description = "Internal server error" , body = APIError )
1273+ )
1274+ ) ]
1275+ pub async fn remove_jobs_handler (
1276+ node_commands_sender : Sender < NodeCommand > ,
1277+ authorization : String ,
1278+ payload : RemoveJobsRequest ,
1279+ ) -> Result < impl warp:: Reply , warp:: Rejection > {
1280+ let bearer = authorization. strip_prefix ( "Bearer " ) . unwrap_or ( "" ) . to_string ( ) ;
1281+ let ( res_sender, res_receiver) = async_channel:: bounded ( 1 ) ;
1282+ node_commands_sender
1283+ . send ( NodeCommand :: V2ApiRemoveJobs {
1284+ bearer,
1285+ job_ids : payload. job_ids ,
1286+ res : res_sender,
1287+ } )
1288+ . await
1289+ . map_err ( |_| warp:: reject:: reject ( ) ) ?;
1290+ let result = res_receiver. recv ( ) . await . map_err ( |_| warp:: reject:: reject ( ) ) ?;
1291+
1292+ match result {
1293+ Ok ( response) => {
1294+ let response = create_success_response ( response) ;
1295+ Ok ( warp:: reply:: with_status ( warp:: reply:: json ( & response) , StatusCode :: OK ) )
1296+ }
1297+ Err ( error) => Ok ( warp:: reply:: with_status (
1298+ warp:: reply:: json ( & error) ,
1299+ StatusCode :: from_u16 ( error. code ) . unwrap ( ) ,
1300+ ) ) ,
1301+ }
1302+ }
1303+
12521304#[ utoipa:: path(
12531305 post,
12541306 path = "/v2/export_messages_from_inbox" ,
@@ -1398,14 +1450,15 @@ pub async fn get_job_provider_handler(
13981450 get_message_traces_handler,
13991451 fork_job_messages_handler,
14001452 remove_job_handler,
1453+ remove_jobs_handler,
14011454 ) ,
14021455 components(
14031456 schemas( AddFileToFolder , V2SmartInbox , APIChangeJobAgentRequest , CreateJobRequest , JobConfig ,
14041457 JobMessageRequest , GetLastMessagesRequest , V2ChatMessage , GetLastMessagesWithBranchesRequest ,
14051458 UpdateJobConfigRequest , UpdateSmartInboxNameRequest , SerializedLLMProvider , JobCreationInfo ,
14061459 JobMessage , NodeApiData , LLMProviderSubset , AssociatedUI , MinimalJobScope , CallbackAction , ShinkaiName ,
14071460 LLMProviderInterface , RetryMessageRequest , UpdateJobScopeRequest , ExportInboxMessagesFormat , ExportInboxMessagesRequest ,
1408- ShinkaiSubidentityType , OpenAI , Ollama , Groq , Gemini , Exo , ShinkaiBackend , SendResponseBody , SendResponseBodyData , APIError , GetToolingLogsRequest , GetMessageTracesRequest , ForkJobMessagesRequest , RemoveJobRequest )
1461+ ShinkaiSubidentityType , OpenAI , Ollama , Groq , Gemini , Exo , ShinkaiBackend , SendResponseBody , SendResponseBodyData , APIError , GetToolingLogsRequest , GetMessageTracesRequest , ForkJobMessagesRequest , RemoveJobRequest , RemoveJobsRequest )
14091462 ) ,
14101463 tags(
14111464 ( name = "jobs" , description = "Job API endpoints" )
0 commit comments