1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//! # AgentAI Video
//!
//! Video generation for [AgentAI](https://crates.io/crates/agentai). Video APIs are
//! asynchronous: [`VideoProvider::submit`] sends a request and returns a [`VideoJob`], which you
//! follow with [`VideoProvider::status`] and, when it is [`JobStatus::Completed`], fetch with
//! [`VideoProvider::download`]. Polling is up to the caller.
//!
//! ```rust,no_run
//! use std::time::Duration;
//! use agentai_video::{JobStatus, VideoRequest, from_model};
//!
//! # async fn run() -> Result<(), Box<dyn std::error::Error>> {
//! // The provider comes from the prefix of the model name, its settings from environment
//! // variables (`COMFY_SERVE_BASE_URL` here)
//! let provider = from_model("comfy-serve::wan-2.2")?;
//! let job = provider
//! .submit(VideoRequest::new("A lighthouse at dawn").with_duration(5))
//! .await?;
//! loop {
//! match provider.status(&job).await? {
//! JobStatus::Completed => break,
//! JobStatus::Failed(message) => return Err(message.into()),
//! JobStatus::Gone => return Err("the job is gone".into()),
//! _ => tokio::time::sleep(Duration::from_secs(5)).await,
//! }
//! }
//! let video = provider.download(&job).await?; // a `Media`, base64 or a URL
//! # Ok(())
//! # }
//! ```
//!
//! A [`VideoJob`] can be stored (serde) and given back, possibly to a new provider, after a
//! restart: `status`, `download` and `cancel` need no model. A job does not record which provider
//! made it, so store the provider and model name next to it.
//!
//! ## Inputs
//!
//! [`VideoRequest::with_inputs`] takes [`VideoInputs`], one of three modes:
//!
//! - `None` (the default): text-to-video.
//! - `Frames { first, last }`: image-to-video, from a first frame, a last frame or both.
//! - `References(`[`VideoReferences`]`)`: reference-to-video, from reference images, videos and
//! audio.
//!
//! Frames and references exclude each other. A provider that cannot send some input returns
//! [`VideoError::Unsupported`]. Options you do not set (duration, resolution, aspect ratio, seed)
//! are not sent, and values are not checked here: the API reports the ones it does not accept.
//!
//! ## Models
//!
//! [`list_models`] (or [`VideoProvider::list_models`]) returns [`VideoModel`]s with the durations,
//! resolutions, aspect ratios and input kinds a model accepts, where the provider says so. `None`
//! in one of these lists means the provider does not say, not that the option is unsupported:
//! offer it and let the server answer. `Some(vec![])` means there is nothing to choose.
//!
//! ## Providers
//!
//! | Prefix | Settings | Cancel | Inputs |
//! |--------|----------|--------|--------|
//! | `comfy-serve` | `COMFY_SERVE_BASE_URL` (required), `COMFY_SERVE_API_KEY` (optional) | yes | first and last frames; image, video and audio references; files are uploaded as multipart |
//! | `openrouter` | `OPENROUTER_API_KEY` (required), `OPENROUTER_BASE_URL` (optional) | no | first and last frames and image references, sent as URLs or data URLs |
//!
//! To set the key and base URL in code, or to change timeouts or the proxy, build the provider
//! yourself and give it your own client:
//!
//! ```rust,ignore
//! // `reqwest::Client` needs `reqwest` in your dependencies; `ReqwestClient` and the other HTTP
//! // types are re-exported from this crate
//! use agentai_video::ReqwestClient;
//! use agentai_video::provider::comfy_serve::ComfyServeVideoProvider;
//!
//! let client = reqwest::Client::builder().build().unwrap();
//! let provider = ComfyServeVideoProvider::new("wan-2.2", "", "http://localhost:8000")
//! .with_http_client(ReqwestClient::from_client(client));
//! ```
//!
//! The HTTP types ([`HttpClient`], [`HttpRequest`], [`HttpResponse`], [`HttpError`],
//! [`ReqwestClient`]), [`Media`] and [`mime`] are re-exported, so this crate is enough to use a
//! provider with your own client or to implement [`VideoProvider`] for another API.
//!
//! ## Files
//!
//! [`mime::from_path`] guesses the type of an input file from its name, and
//! [`Media::extension`] gives the file extension of a downloaded video's type:
//!
//! ```rust,no_run
//! # use agentai_video::{Media, ReqwestClient, VideoInputs, VideoRequest, mime};
//! # async fn run(video: Media) -> Result<(), Box<dyn std::error::Error>> {
//! let path = "first.jpg";
//! let first = Media::from_bytes(mime::from_path(path).ok_or("unknown type")?, std::fs::read(path)?);
//! let request = VideoRequest::new("The scene comes alive").with_inputs(VideoInputs::Frames {
//! first: Some(first),
//! last: None,
//! });
//! // ... submit, poll, download ...
//! let bytes = video.bytes(&ReqwestClient::new()).await?;
//! std::fs::write(format!("video.{}", video.extension()), bytes)?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Limits
//!
//! - Files travel in memory as [`Media`] (base64 or a URL), so large videos are held whole.
//! - There is no waiting helper (the loop above is yours to write, with your timing and your
//! runtime), no retries and no timeouts of its own.
//! - There are no agent tools: this crate does not depend on `agentai`.
//!
//! ## Features
compile_error!;
pub use ;
pub use mime;
pub use ;
pub use ;