inline
This commit is contained in:
@@ -1,23 +1,13 @@
|
||||
use crate::editor_agent::editor_tools::common::{
|
||||
editor_agent_image_mud_points, EditorAgentPricedTool, EditorToolContext,
|
||||
EditorAgentPricedTool, EditorToolContext, editor_agent_image_mud_points,
|
||||
};
|
||||
use crate::editor_agent::utils::ImageId;
|
||||
use crate::editor_generation_config::EditorGenerationPricingConfig;
|
||||
use crate::editor_project::{
|
||||
edit_editor_image_for_owner, EditorGenerationCaller, EditorImageEditRequest,
|
||||
};
|
||||
use crate::http_error::AppError;
|
||||
use crate::request_context::RequestContext;
|
||||
use crate::state::AppState;
|
||||
use axum::http::StatusCode;
|
||||
use module_editor_agent::agent::tool::{Tool, ToolFailure, ToolFailureKind};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{json, Value};
|
||||
use shared_contracts::api::ApiSuccessEnvelope;
|
||||
use shared_contracts::assets::EditorCanvasGenerationCompletionPayload;
|
||||
use serde_json::{Value, json};
|
||||
use std::error::Error;
|
||||
use std::fmt::Display;
|
||||
use crate::editor_agent::editor_tools::common;
|
||||
|
||||
pub struct EditImageTool {
|
||||
pub context: EditorToolContext,
|
||||
@@ -104,8 +94,7 @@ impl Tool for EditImageTool {
|
||||
args: Self::Args,
|
||||
) -> impl Future<Output = Result<Self::Output, Self::Error>> + Send {
|
||||
async move {
|
||||
self.validate_context_images(&args)?;
|
||||
if let Some(error) = Self::validate_args(&args) {
|
||||
if let Some(error) = self.validate_args(&args) {
|
||||
return Err(error);
|
||||
}
|
||||
Ok(EditImageToolOutput {
|
||||
@@ -157,26 +146,20 @@ pub struct EditorImageEditResult {
|
||||
|
||||
impl EditImageTool {
|
||||
/// Validate the semantic correctness of the arguments.
|
||||
fn validate_args(args: &EditImageToolArgs) -> Option<EditImageError> {
|
||||
fn validate_args(&self, args: &EditImageToolArgs) -> Option<EditImageError> {
|
||||
if args.prompt.trim().is_empty() {
|
||||
return Some(EditImageError::PromptNotProvided);
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// Validate that all referenced images exist in the context.
|
||||
fn validate_context_images(&self, args: &EditImageToolArgs) -> Result<(), EditImageError> {
|
||||
if !self.context.contains_image(&args.object_image_id) {
|
||||
return Err(EditImageError::AssetNotFound(args.object_image_id.clone()));
|
||||
return Some(EditImageError::AssetNotFound(args.object_image_id.clone()));
|
||||
}
|
||||
|
||||
for ref_id in &args.reference_image_ids {
|
||||
if !self.context.contains_image(ref_id) {
|
||||
return Err(EditImageError::AssetNotFound(ref_id.clone()));
|
||||
return Some(EditImageError::AssetNotFound(ref_id.clone()));
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
None
|
||||
}
|
||||
|
||||
pub fn format_execute_message(
|
||||
@@ -200,4 +183,3 @@ impl EditImageTool {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user