use axum::{ Router, extract::DefaultBodyLimit, middleware, routing::{get, post}, }; use crate::{ ai_tasks::{ append_ai_text_chunk, attach_ai_result_reference, cancel_ai_task, complete_ai_stage, complete_ai_task, create_ai_task, fail_ai_task, start_ai_task, start_ai_task_stage, }, auth::require_bearer_auth, character_animation_assets::{ generate_character_animation, get_character_animation_job, get_character_workflow_cache, import_character_animation_video, list_character_animation_templates, publish_character_animation, put_role_asset_workflow, resolve_role_asset_workflow, save_character_workflow_cache, }, character_visual_assets::{ generate_character_visual, get_character_visual_job, publish_character_visual, }, creation_agent_document_input::parse_creation_agent_document_input, creation_entry_config::get_creation_entry_config_handler, hyper3d_generation::{ get_hyper3d_downloads, get_hyper3d_task_status, submit_hyper3d_image_to_model, submit_hyper3d_text_to_model, }, llm::proxy_llm_chat_completions, runtime_chat::stream_runtime_npc_chat_turn, runtime_chat_plain::{ generate_runtime_character_chat_suggestions, generate_runtime_character_chat_summary, stream_runtime_character_chat_reply, stream_runtime_npc_chat_dialogue, stream_runtime_npc_recruit_dialogue, }, runtime_save::{delete_runtime_snapshot, get_runtime_snapshot, put_runtime_snapshot}, runtime_settings::{get_runtime_settings, put_runtime_settings}, state::AppState, volcengine_speech::{ get_volcengine_speech_config, stream_volcengine_asr, stream_volcengine_tts_bidirection, stream_volcengine_tts_sse, }, }; const HYPER3D_IMAGE_TO_MODEL_BODY_LIMIT_BYTES: usize = 56 * 1024 * 1024; pub fn router(state: AppState) -> Router { Router::new() .route( "/api/llm/chat/completions", post(proxy_llm_chat_completions).route_layer(middleware::from_fn_with_state( state.clone(), require_bearer_auth, )), ) .route( "/api/speech/volcengine/config", get(get_volcengine_speech_config).route_layer(middleware::from_fn_with_state( state.clone(), require_bearer_auth, )), ) .route( "/api/speech/volcengine/asr/stream", get(stream_volcengine_asr).route_layer(middleware::from_fn_with_state( state.clone(), require_bearer_auth, )), ) .route( "/api/speech/volcengine/tts/bidirection", get(stream_volcengine_tts_bidirection).route_layer(middleware::from_fn_with_state( state.clone(), require_bearer_auth, )), ) .route( "/api/speech/volcengine/tts/sse", post(stream_volcengine_tts_sse).route_layer(middleware::from_fn_with_state( state.clone(), require_bearer_auth, )), ) .route( "/api/runtime/chat/character/suggestions", post(generate_runtime_character_chat_suggestions).route_layer( middleware::from_fn_with_state(state.clone(), require_bearer_auth), ), ) .route( "/api/runtime/chat/character/summary", post(generate_runtime_character_chat_summary).route_layer( middleware::from_fn_with_state(state.clone(), require_bearer_auth), ), ) .route( "/api/runtime/chat/character/reply/stream", post(stream_runtime_character_chat_reply).route_layer(middleware::from_fn_with_state( state.clone(), require_bearer_auth, )), ) .route( "/api/runtime/chat/npc/dialogue/stream", post(stream_runtime_npc_chat_dialogue).route_layer(middleware::from_fn_with_state( state.clone(), require_bearer_auth, )), ) .route( "/api/runtime/chat/npc/turn/stream", post(stream_runtime_npc_chat_turn).route_layer(middleware::from_fn_with_state( state.clone(), require_bearer_auth, )), ) .route( "/api/runtime/chat/npc/recruit/stream", post(stream_runtime_npc_recruit_dialogue).route_layer(middleware::from_fn_with_state( state.clone(), require_bearer_auth, )), ) .route( "/api/runtime/creation-agent/document-inputs/parse", post(parse_creation_agent_document_input).route_layer(middleware::from_fn_with_state( state.clone(), require_bearer_auth, )), ) .route( "/api/ai/tasks", post(create_ai_task).route_layer(middleware::from_fn_with_state( state.clone(), require_bearer_auth, )), ) .route( "/api/ai/tasks/{task_id}/start", post(start_ai_task).route_layer(middleware::from_fn_with_state( state.clone(), require_bearer_auth, )), ) .route( "/api/ai/tasks/{task_id}/stages/{stage_kind}/start", post(start_ai_task_stage).route_layer(middleware::from_fn_with_state( state.clone(), require_bearer_auth, )), ) .route( "/api/ai/tasks/{task_id}/chunks", post(append_ai_text_chunk).route_layer(middleware::from_fn_with_state( state.clone(), require_bearer_auth, )), ) .route( "/api/ai/tasks/{task_id}/stages/{stage_kind}/complete", post(complete_ai_stage).route_layer(middleware::from_fn_with_state( state.clone(), require_bearer_auth, )), ) .route( "/api/ai/tasks/{task_id}/references", post(attach_ai_result_reference).route_layer(middleware::from_fn_with_state( state.clone(), require_bearer_auth, )), ) .route( "/api/ai/tasks/{task_id}/complete", post(complete_ai_task).route_layer(middleware::from_fn_with_state( state.clone(), require_bearer_auth, )), ) .route( "/api/ai/tasks/{task_id}/fail", post(fail_ai_task).route_layer(middleware::from_fn_with_state( state.clone(), require_bearer_auth, )), ) .route( "/api/ai/tasks/{task_id}/cancel", post(cancel_ai_task).route_layer(middleware::from_fn_with_state( state.clone(), require_bearer_auth, )), ) .route( "/api/assets/character-visual/generate", post(generate_character_visual), ) .route( "/api/assets/character-visual/jobs/{task_id}", get(get_character_visual_job), ) .route( "/api/assets/character-visual/publish", post(publish_character_visual), ) .route( "/api/assets/character-animation/generate", post(generate_character_animation), ) .route( "/api/assets/character-animation/jobs/{task_id}", get(get_character_animation_job), ) .route( "/api/assets/character-animation/publish", post(publish_character_animation), ) .route( "/api/assets/character-animation/import-video", post(import_character_animation_video), ) .route( "/api/assets/character-animation/templates", get(list_character_animation_templates), ) .route( "/api/assets/character-workflow-cache", post(save_character_workflow_cache), ) .route( "/api/assets/character-workflow-cache/{character_id}", get(get_character_workflow_cache), ) .route( "/api/runtime/custom-world/asset-studio/role/{character_id}/workflow", post(resolve_role_asset_workflow).put(put_role_asset_workflow), ) .route( "/api/assets/hyper3d/text-to-model", post(submit_hyper3d_text_to_model).route_layer(middleware::from_fn_with_state( state.clone(), require_bearer_auth, )), ) .route( "/api/assets/hyper3d/image-to-model", post(submit_hyper3d_image_to_model) .layer(DefaultBodyLimit::max( HYPER3D_IMAGE_TO_MODEL_BODY_LIMIT_BYTES, )) .route_layer(middleware::from_fn_with_state( state.clone(), require_bearer_auth, )), ) .route( "/api/assets/hyper3d/status", post(get_hyper3d_task_status).route_layer(middleware::from_fn_with_state( state.clone(), require_bearer_auth, )), ) .route( "/api/assets/hyper3d/download", post(get_hyper3d_downloads).route_layer(middleware::from_fn_with_state( state.clone(), require_bearer_auth, )), ) .route( "/api/creation-entry/config", get(get_creation_entry_config_handler), ) .route( "/api/runtime/settings", get(get_runtime_settings) .put(put_runtime_settings) .route_layer(middleware::from_fn_with_state( state.clone(), require_bearer_auth, )), ) .route( "/api/runtime/save/snapshot", get(get_runtime_snapshot) .put(put_runtime_snapshot) .delete(delete_runtime_snapshot) .route_layer(middleware::from_fn_with_state( state.clone(), require_bearer_auth, )), ) }