Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/en/tools-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,13 @@ Queue a Veo video or Imagen image generation job on `JobQueue`. Returns a `JobVi
| :--- | :--- | :--- | :--- |
| `prompt` | `string` | Yes | Text prompt that `flow-mcp` sends to Google Flow. |
| `mode` | `string` | No | `"video"` (default) or `"image"`. |
| `model` | `string` | No | Model override. Defaults to `"veo-3.1-fast"` (`video`) or `"nano-banana-2"` (`image`). |
| `aspect` | `string` | No | Aspect ratio: `"16:9"` (default), `"9:16"`, or `"1:1"`. |
| `model` | `string` | No | Model override. Defaults to `"veo_3_1_lite"` (`video`) or `"nano-banana-2"` (`image`). |
| `aspect` | `string` | No | Aspect ratio: `"16:9"` (default), `"9:16"`, or `"1:1"` (`image` mode only). |
| `count` | `integer` | No | Output batch count in `1..=4`. Default `2`. |
| `frames` | `string[]` | No | Local reference or keyframe image paths to upload before submission. |
| `asset_ids` | `string[]` | No | Existing project image asset IDs to attach as ingredients or frames. |
| `characters` | `string[]` | No | Character IDs or names to attach to the prompt controls. |
| `video_type` | `string` | No | Video generation mode: `"frames"` or `"ingredients"`. |
| `characters` | `string[]` | No | Character IDs or names to attach to the prompt controls (`"ingredients"` mode or `image` mode). |
| `video_type` | `string` | No | Video generation mode: `"ingredients"` (default) or `"frames"`. |
| `duration` | `string` | No | Video duration setting (for example `"5s"` or `"8s"`). |
| `resolution` | `string` | No | Video resolution setting (for example `"720p"`, `"1080p"`, or `"4K"`). |
| `name` | `string` | No | Optional scene or asset label for the job. |
Expand Down
8 changes: 4 additions & 4 deletions docs/ja/tools-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,13 @@ Google Flow でキャラクターボイスピッカーを開き、リスト全
| :--- | :--- | :--- | :--- |
| `prompt` | `string` | はい | `flow-mcp` が Google Flow へ送信するテキストプロンプト。 |
| `mode` | `string` | いいえ | `"video"`(既定)または `"image"`。 |
| `model` | `string` | いいえ | モデル上書き。既定は `"veo-3.1-fast"`(`video`)または `"nano-banana-2"`(`image`)。 |
| `aspect` | `string` | いいえ | アスペクト比:`"16:9"`(既定)、`"9:16"`、または `"1:1"`。 |
| `model` | `string` | いいえ | モデル上書き。既定は `"veo_3_1_lite"`(`video`)または `"nano-banana-2"`(`image`)。 |
| `aspect` | `string` | いいえ | アスペクト比:`"16:9"`(既定)、`"9:16"`、または `"1:1"`(`image` モードのみ)。 |
| `count` | `integer` | いいえ | 出力バッチ数(`1..=4`)。既定は `2`。 |
| `frames` | `string[]` | いいえ | 送信前にアップロードするローカル参照またはキーフレーム画像パス。 |
| `asset_ids` | `string[]` | いいえ | 素材またはフレームとして添付する既存プロジェクト画像アセット ID。 |
| `characters` | `string[]` | いいえ | プロンプトコントロールへ添付するキャラクター ID または名前。 |
| `video_type` | `string` | いいえ | 動画生成モード:`"frames"` または `"ingredients"`。 |
| `characters` | `string[]` | いいえ | プロンプトコントロールへ添付するキャラクター ID または名前(`"ingredients"` モードまたは `image` モード)。 |
| `video_type` | `string` | いいえ | 動画生成モード:`"ingredients"`(既定)または `"frames"`。 |
| `duration` | `string` | いいえ | 動画尺設定(たとえば `"5s"` または `"8s"`)。 |
| `resolution` | `string` | いいえ | 動画解像度設定(たとえば `"720p"`、`"1080p"`、または `"4K"`)。 |
| `name` | `string` | いいえ | ジョブ用の任意のシーンまたはアセットラベル。 |
Expand Down
8 changes: 4 additions & 4 deletions docs/zh-CN/tools-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,13 @@ flow-mcp [OPTIONS] <COMMAND>
| :--- | :--- | :--- | :--- |
| `prompt` | `string` | 是 | `flow-mcp` 发送给 Google Flow 的文本提示词。 |
| `mode` | `string` | 否 | `"video"`(默认)或 `"image"`。 |
| `model` | `string` | 否 | 模型覆盖。默认为 `"veo-3.1-fast"`(`video`)或 `"nano-banana-2"`(`image`)。 |
| `aspect` | `string` | 否 | 画面比例:`"16:9"`(默认)、`"9:16"` 或 `"1:1"`。 |
| `model` | `string` | 否 | 模型覆盖。默认为 `"veo_3_1_lite"`(`video`)或 `"nano-banana-2"`(`image`)。 |
| `aspect` | `string` | 否 | 画面比例:`"16:9"`(默认)、`"9:16"` 或 `"1:1"`(仅限 `image` 模式)。 |
| `count` | `integer` | 否 | 输出批次数量,范围 `1..=4`。默认 `2`。 |
| `frames` | `string[]` | 否 | 提交前上传的本地参考图像或关键帧路径。 |
| `asset_ids` | `string[]` | 否 | 作为素材或关键帧附加的既有项目图像资产 ID。 |
| `characters` | `string[]` | 否 | 附加到提示词控件的角色 ID 或名称。 |
| `video_type` | `string` | 否 | 视频生成模式:`"frames"` 或 `"ingredients"`。 |
| `characters` | `string[]` | 否 | 附加到提示词控件的角色 ID 或名称(`"ingredients"` 模式或 `image` 模式)。 |
| `video_type` | `string` | 否 | 视频生成模式:`"ingredients"`(默认)或 `"frames"`。 |
| `duration` | `string` | 否 | 视频时长设置(例如 `"5s"` 或 `"8s"`)。 |
| `resolution` | `string` | 否 | 视频分辨率设置(例如 `"720p"`、`"1080p"` 或 `"4K"`)。 |
| `name` | `string` | 否 | 任务的可选场景或资产标签。 |
Expand Down
143 changes: 129 additions & 14 deletions src/generation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ pub(crate) struct GenerateParams {
pub(crate) prompt: String,
/// Generation mode: "video" (default) or "image".
pub(crate) mode: Option<String>,
/// Model name override (defaults to "veo-3.1-fast" for video or "nano-banana-2" for image).
/// Model name override (defaults to "veo_3_1_lite" for video or "nano-banana-2" for image).
pub(crate) model: Option<String>,
/// Output aspect ratio: "16:9" (default), "9:16", or "1:1".
/// Output aspect ratio: "16:9" (default), "9:16", or "1:1" (image mode only).
pub(crate) aspect: Option<String>,
/// Output count from 1 to 4 (default 2).
#[schemars(range(min = 1, max = 4))]
Expand All @@ -55,7 +55,7 @@ pub(crate) struct GenerateParams {
pub(crate) asset_ids: Option<Vec<String>>,
/// Existing character IDs or names to attach to video or image generation.
pub(crate) characters: Option<Vec<String>>,
/// Video generation mode (`"frames"` or `"ingredients"`).
/// Video generation mode: "ingredients" (default) or "frames".
pub(crate) video_type: Option<String>,
/// Video duration setting (for example `"5s"` or `"8s"`).
pub(crate) duration: Option<String>,
Expand Down Expand Up @@ -87,11 +87,127 @@ struct AssetWaitSpec<'a> {
submit_summary: &'a str,
}

/// Normalizes `mode`, `video_type`, `aspect`, and `model` on `scene` and validates constraints.
pub(crate) fn normalize_generation_scene(scene: &mut SceneParams) -> Result<()> {
let raw_mode = scene
.mode
.as_deref()
.map(str::trim)
.filter(|s| !s.is_empty())
.unwrap_or("video");
let mode = if raw_mode.eq_ignore_ascii_case("image")
|| raw_mode.eq_ignore_ascii_case("character")
|| raw_mode.eq_ignore_ascii_case("scene")
{
"image"
} else {
"video"
};
scene.mode = Some(mode.to_string());

let aspect = scene
.aspect
.as_deref()
.map(str::trim)
.filter(|s| !s.is_empty())
.unwrap_or("16:9")
.to_string();
if mode == "video" && (aspect == "1:1" || aspect.eq_ignore_ascii_case("square")) {
anyhow::bail!(
"Video generation does not support aspect ratio '{aspect}'; use '16:9' or '9:16'"
);
}
scene.aspect = Some(aspect);

if mode == "video" {
let normalized_vt = match scene
.video_type
.as_deref()
.map(str::trim)
.filter(|s| !s.is_empty())
{
None => "ingredients",
Some(vt)
if vt.eq_ignore_ascii_case("ingredients")
|| vt.eq_ignore_ascii_case("ingredient")
|| vt.eq_ignore_ascii_case("references")
|| vt.eq_ignore_ascii_case("video_ingredients")
|| vt.eq_ignore_ascii_case("video_references") =>
{
"ingredients"
}
Some(vt)
if vt.eq_ignore_ascii_case("frames")
|| vt.eq_ignore_ascii_case("frame")
|| vt.eq_ignore_ascii_case("video_frames") =>
{
"frames"
}
Some(other) => anyhow::bail!(
"Unsupported video_type '{other}'; expected 'ingredients' or 'frames'"
),
};
if normalized_vt == "frames" {
if scene
.characters
.as_ref()
.is_some_and(|chars| chars.iter().any(|c| !c.trim().is_empty()))
{
anyhow::bail!(
"Frame mode does not support character ingredients; use video_type 'ingredients'"
);
}
let ref_count = scene.frames.as_ref().map_or(0, Vec::len)
+ scene.asset_ids.as_ref().map_or(0, Vec::len);
anyhow::ensure!(
ref_count <= 2,
"Frame mode accepts at most two references, got {ref_count}"
);
}
scene.video_type = Some(normalized_vt.to_string());
} else {
scene.video_type = None;
}

let resolved_model = match scene
.model
.as_deref()
.map(str::trim)
.filter(|s| !s.is_empty())
{
None => {
if mode == "image" {
"nano-banana-2".to_string()
} else {
"veo_3_1_lite".to_string()
}
}
Some(m)
if m.eq_ignore_ascii_case("veo-3.1-fast") || m.eq_ignore_ascii_case("veo_3_1_fast") =>
{
"veo_3_1_lite".to_string()
}
Some(m) => m.to_string(),
};
scene.model = Some(resolved_model);
Ok(())
}

/// Configures generation controls, uploads reference frames, writes prompt text, and submits.
async fn apply_generation_controls(
engine: &ChromeEngine,
scene: &SceneParams,
) -> Result<serde_json::Value> {
let mut normalized;
let scene = if scene.mode.is_some() || scene.edit_from.is_none() && scene.aspect.is_some() {
normalized = scene.clone();
if normalized.mode.is_some() {
normalize_generation_scene(&mut normalized)?;
}
&normalized
} else {
scene
};
validate_local_files(scene.frames.as_deref(), "Reference image").await?;

let raw_mode = scene.mode.as_deref().unwrap_or("video");
Expand All @@ -103,8 +219,13 @@ async fn apply_generation_controls(
let model = scene.model.as_deref().unwrap_or(if mode == "image" {
"nano-banana-2"
} else {
"veo-3.1-fast"
"veo_3_1_lite"
});
let video_type = if scene.mode.is_some() && mode == "video" {
Some(scene.video_type.as_deref().unwrap_or("ingredients"))
} else {
scene.video_type.as_deref()
};
let count = scene.count.unwrap_or(2).clamp(1, 4);

let cfg = json!({
Expand All @@ -115,7 +236,7 @@ async fn apply_generation_controls(
"prompt": scene.prompt,
"asset_ids": scene.asset_ids,
"characters": scene.characters,
"video_type": scene.video_type,
"video_type": video_type,
"duration": scene.duration,
"resolution": scene.resolution,
});
Expand Down Expand Up @@ -525,17 +646,11 @@ pub(crate) async fn run_generation(
scene: &SceneParams,
on_progress: ProgressCallback,
) -> Result<(Vec<String>, Vec<String>, Vec<String>)> {
let mut normalized_scene = scene.clone();
normalize_generation_scene(&mut normalized_scene)?;
let scene = &normalized_scene;
ensure_project_workspace_root(engine).await?;
ensure_flow_store(engine).await?;
if scene.video_type.as_deref() == Some("frames") {
let count = scene.frames.as_ref().map_or(0, Vec::len)
+ scene.asset_ids.as_ref().map_or(0, Vec::len)
+ scene.characters.as_ref().map_or(0, Vec::len);
anyhow::ensure!(
count <= 2,
"Frame mode accepts at most two references, got {count}"
);
}
// Upload local frames into the library first and attach them as assets, so that the
// uploaded tiles are not counted as generated outputs.
let uploaded_scene;
Expand Down
1 change: 1 addition & 0 deletions src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ impl FlowService {
resolution: req.resolution,
..Default::default()
};
generation::normalize_generation_scene(&mut scene)?;
characters::apply_character_look(&self.db, &mut scene).await?;
Ok(self.queue.enqueue(scene).await)
}
Expand Down
Loading
Loading