mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-07 01:47:47 +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]>
117 lines
3.6 KiB
Rust
117 lines
3.6 KiB
Rust
use aether_data_contracts::repository::video_tasks::{StoredVideoTask, VideoTaskLookupKey};
|
|
use aether_data_contracts::DataLayerError;
|
|
use async_trait::async_trait;
|
|
|
|
use crate::{
|
|
map_gemini_stored_task_to_read_response, map_openai_stored_task_to_read_response,
|
|
resolve_video_task_read_lookup_key, LocalVideoTaskReadResponse,
|
|
};
|
|
|
|
#[async_trait]
|
|
pub trait StoredVideoTaskReadSide: Send + Sync {
|
|
async fn find_stored_video_task(
|
|
&self,
|
|
key: VideoTaskLookupKey<'_>,
|
|
) -> Result<Option<StoredVideoTask>, DataLayerError>;
|
|
|
|
async fn find_stored_video_task_for_user(
|
|
&self,
|
|
key: VideoTaskLookupKey<'_>,
|
|
user_id: &str,
|
|
) -> Result<Option<StoredVideoTask>, DataLayerError>;
|
|
}
|
|
|
|
pub async fn read_data_backed_video_task_response(
|
|
state: &impl StoredVideoTaskReadSide,
|
|
route_family: Option<&str>,
|
|
request_path: &str,
|
|
) -> Result<Option<LocalVideoTaskReadResponse>, DataLayerError> {
|
|
read_data_backed_video_task_response_inner(state, route_family, request_path, None).await
|
|
}
|
|
|
|
pub async fn read_data_backed_video_task_response_for_user(
|
|
state: &impl StoredVideoTaskReadSide,
|
|
route_family: Option<&str>,
|
|
request_path: &str,
|
|
user_id: &str,
|
|
) -> Result<Option<LocalVideoTaskReadResponse>, DataLayerError> {
|
|
let user_id = user_id.trim();
|
|
if user_id.is_empty() {
|
|
return Ok(None);
|
|
}
|
|
read_data_backed_video_task_response_inner(state, route_family, request_path, Some(user_id))
|
|
.await
|
|
}
|
|
|
|
async fn read_data_backed_video_task_response_inner(
|
|
state: &impl StoredVideoTaskReadSide,
|
|
route_family: Option<&str>,
|
|
request_path: &str,
|
|
user_id: Option<&str>,
|
|
) -> Result<Option<LocalVideoTaskReadResponse>, DataLayerError> {
|
|
match route_family {
|
|
Some("openai") => read_openai_video_task_response(state, request_path, user_id).await,
|
|
Some("gemini") => read_gemini_video_task_response(state, request_path, user_id).await,
|
|
_ => Ok(None),
|
|
}
|
|
}
|
|
|
|
async fn read_openai_video_task_response(
|
|
state: &impl StoredVideoTaskReadSide,
|
|
request_path: &str,
|
|
user_id: Option<&str>,
|
|
) -> Result<Option<LocalVideoTaskReadResponse>, DataLayerError> {
|
|
let Some(lookup) = resolve_video_task_read_lookup_key(Some("openai"), request_path) else {
|
|
return Ok(None);
|
|
};
|
|
|
|
let task = match user_id {
|
|
Some(user_id) => {
|
|
state
|
|
.find_stored_video_task_for_user(lookup, user_id)
|
|
.await?
|
|
}
|
|
None => state.find_stored_video_task(lookup).await?,
|
|
};
|
|
let Some(mut task) = task else {
|
|
return Ok(None);
|
|
};
|
|
|
|
if !matches!(task.provider_api_format.as_deref(), Some("openai:video")) {
|
|
return Ok(None);
|
|
}
|
|
|
|
if request_path.starts_with("/openai/v1/videos/") {
|
|
task.client_api_format = Some("openai:video".into());
|
|
}
|
|
Ok(Some(map_openai_stored_task_to_read_response(task)))
|
|
}
|
|
|
|
async fn read_gemini_video_task_response(
|
|
state: &impl StoredVideoTaskReadSide,
|
|
request_path: &str,
|
|
user_id: Option<&str>,
|
|
) -> Result<Option<LocalVideoTaskReadResponse>, DataLayerError> {
|
|
let Some(lookup) = resolve_video_task_read_lookup_key(Some("gemini"), request_path) else {
|
|
return Ok(None);
|
|
};
|
|
|
|
let task = match user_id {
|
|
Some(user_id) => {
|
|
state
|
|
.find_stored_video_task_for_user(lookup, user_id)
|
|
.await?
|
|
}
|
|
None => state.find_stored_video_task(lookup).await?,
|
|
};
|
|
let Some(task) = task else {
|
|
return Ok(None);
|
|
};
|
|
|
|
if !matches!(task.provider_api_format.as_deref(), Some("gemini:video")) {
|
|
return Ok(None);
|
|
}
|
|
|
|
Ok(Some(map_gemini_stored_task_to_read_response(task)))
|
|
}
|