mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-09 02:47:45 +08:00
Expose the xAI Imagine image and video surfaces on top of the `xai` provider, and make the shared OpenAI video-task layer survive the production configuration they need. Native video requests live under /v1 (generations, edits, extensions, with /v1/videos as a creation alias that only selects xAI candidates); the OpenAI-compatible adapter stays under /openai/v1/videos and maps `seconds` / `size` onto numeric duration, aspect ratio and resolution. Clients receive an opaque Aether task ID scoped to the owning user; polling uses the upstream task ID and the original credential, and completed downloads fetch the returned media URL without forwarding provider authorization to the media host. Three fixes to the shared video layer are required for this to work outside tests: - OpenAI/xAI task persistence now supplies a stable 16-character short_id, which the PostgreSQL schema requires. Existing rows keep their original value across reconstruction, so no schema change or historical rewrite is needed. - Task retrieval and content downloads are admitted by the production GET execution gate, and reconstructed tasks resolve proxy nodes, system proxy defaults, tunnel affinity and transport profiles through the same deployment resolver used for creation. A configured proxy route no longer silently becomes a direct request after restart. - When the gateway also serves the frontend, /openai/v1/videos and its subpaths bypass the static SPA handler. Otherwise a video query returns HTTP 200 with text/html instead of the task JSON. Co-Authored-By: Claude Opus 5 <[email protected]>
137 lines
5.3 KiB
Rust
137 lines
5.3 KiB
Rust
use aether_contracts::ExecutionPlan;
|
|
use aether_data_contracts::repository::video_tasks::{
|
|
StoredVideoTask, VideoTaskStatus as StoredVideoTaskStatus,
|
|
};
|
|
use serde_json::{Map, Value};
|
|
use std::collections::BTreeMap;
|
|
|
|
use crate::{
|
|
context_text, non_empty_owned, LocalVideoTaskPersistence, LocalVideoTaskStatus,
|
|
LocalVideoTaskTransport, LocalVideoTaskTransportBridgeInput,
|
|
};
|
|
|
|
impl LocalVideoTaskTransport {
|
|
pub fn from_plan(plan: &ExecutionPlan) -> Option<Self> {
|
|
let upstream_base_url = match plan.provider_api_format.as_str() {
|
|
"openai:video" => trim_openai_video_resource_root(&plan.url)?,
|
|
"gemini:video" => plan.url.split("/v1beta/").next()?.to_string(),
|
|
_ => return None,
|
|
};
|
|
if upstream_base_url.is_empty() {
|
|
return None;
|
|
}
|
|
Some(Self {
|
|
upstream_base_url,
|
|
provider_name: plan.provider_name.clone(),
|
|
provider_id: plan.provider_id.clone(),
|
|
endpoint_id: plan.endpoint_id.clone(),
|
|
key_id: plan.key_id.clone(),
|
|
headers: plan.headers.clone(),
|
|
content_type: plan.content_type.clone(),
|
|
model_name: plan.model_name.clone(),
|
|
proxy: plan.proxy.clone(),
|
|
transport_profile: plan.transport_profile.clone(),
|
|
timeouts: plan.timeouts.clone(),
|
|
})
|
|
}
|
|
|
|
pub fn from_bridge_input(input: LocalVideoTaskTransportBridgeInput) -> Self {
|
|
let mut headers = BTreeMap::new();
|
|
headers.insert(input.auth_header, input.auth_value);
|
|
|
|
Self {
|
|
upstream_base_url: input.upstream_base_url,
|
|
provider_name: input.provider_name,
|
|
provider_id: input.provider_id,
|
|
endpoint_id: input.endpoint_id,
|
|
key_id: input.key_id,
|
|
headers,
|
|
content_type: input.content_type,
|
|
model_name: input.model_name,
|
|
proxy: input.proxy,
|
|
transport_profile: input.transport_profile,
|
|
timeouts: input.timeouts,
|
|
}
|
|
}
|
|
}
|
|
|
|
fn trim_openai_video_resource_root(url: &str) -> Option<String> {
|
|
let base = url.split_once('?').map(|(base, _)| base).unwrap_or(url);
|
|
let (root, suffix) = base.rsplit_once("/videos")?;
|
|
if !suffix.is_empty() && !suffix.starts_with('/') {
|
|
return None;
|
|
}
|
|
Some(root.to_string())
|
|
}
|
|
|
|
impl LocalVideoTaskPersistence {
|
|
pub fn from_report_context(report_context: &Map<String, Value>, plan: &ExecutionPlan) -> Self {
|
|
Self {
|
|
request_id: context_text(report_context, "request_id")
|
|
.unwrap_or_else(|| plan.request_id.clone()),
|
|
username: context_text(report_context, "username"),
|
|
api_key_name: context_text(report_context, "api_key_name"),
|
|
client_api_format: if report_context
|
|
.get("video_client_protocol")
|
|
.and_then(Value::as_str)
|
|
== Some("xai")
|
|
{
|
|
"xai:video".to_string()
|
|
} else {
|
|
context_text(report_context, "client_api_format")
|
|
.unwrap_or_else(|| plan.client_api_format.clone())
|
|
},
|
|
provider_api_format: context_text(report_context, "provider_api_format")
|
|
.unwrap_or_else(|| plan.provider_api_format.clone()),
|
|
original_request_body: report_context
|
|
.get("original_request_body")
|
|
.cloned()
|
|
.unwrap_or_else(|| Value::Object(Map::new())),
|
|
format_converted: report_context
|
|
.get("format_converted")
|
|
.and_then(Value::as_bool)
|
|
.unwrap_or(false),
|
|
}
|
|
}
|
|
|
|
pub fn from_stored_task(task: &StoredVideoTask) -> Option<Self> {
|
|
let client_api_format = non_empty_owned(task.client_api_format.as_ref())
|
|
.or_else(|| non_empty_owned(task.provider_api_format.as_ref()))?;
|
|
let provider_api_format = non_empty_owned(task.provider_api_format.as_ref())
|
|
.or_else(|| non_empty_owned(task.client_api_format.as_ref()))?;
|
|
|
|
Some(Self {
|
|
request_id: task.request_id.clone(),
|
|
username: task.username.clone(),
|
|
api_key_name: task.api_key_name.clone(),
|
|
client_api_format,
|
|
provider_api_format,
|
|
original_request_body: task.original_request_body.clone().unwrap_or_else(|| {
|
|
serde_json::json!({
|
|
"prompt": task.prompt,
|
|
"seconds": task.duration_seconds,
|
|
"resolution": task.resolution,
|
|
"aspect_ratio": task.aspect_ratio,
|
|
"size": task.size,
|
|
})
|
|
}),
|
|
format_converted: task.format_converted,
|
|
})
|
|
}
|
|
}
|
|
|
|
impl LocalVideoTaskStatus {
|
|
pub fn as_database_status(self) -> StoredVideoTaskStatus {
|
|
match self {
|
|
Self::Submitted => StoredVideoTaskStatus::Submitted,
|
|
Self::Queued => StoredVideoTaskStatus::Queued,
|
|
Self::Processing => StoredVideoTaskStatus::Processing,
|
|
Self::Completed => StoredVideoTaskStatus::Completed,
|
|
Self::Failed => StoredVideoTaskStatus::Failed,
|
|
Self::Cancelled => StoredVideoTaskStatus::Cancelled,
|
|
Self::Expired => StoredVideoTaskStatus::Expired,
|
|
Self::Deleted => StoredVideoTaskStatus::Deleted,
|
|
}
|
|
}
|
|
}
|