reddb_server/runtime/ai/
mod.rs1pub mod answer_cache_key;
16pub mod ask_response_envelope;
17pub mod ask_rql_planner;
18pub mod audit_record_builder;
19pub mod batch_client;
20pub mod cdc_enrichment;
21pub mod citation_parser;
22pub mod cost_guard;
23pub mod dedup_cache;
24pub mod determinism_decider;
25pub mod explain_plan_builder;
26pub mod grpc_ask_message;
27pub mod local_embedding;
28pub mod mcp_ask_tool;
29pub mod metrics;
30pub mod moderation;
31pub mod ner;
32pub mod pg_wire_ask_row_encoder;
33pub mod prompt_assembler;
34pub mod prompt_template;
35pub mod provider_capabilities;
36pub mod provider_failover;
37pub mod provider_gate;
38pub mod rrf_fuser;
39pub mod sources_fingerprint;
40pub mod sse_frame_encoder;
41pub mod strict_validator;
42pub mod text_chunker;
43pub mod transport;
44pub mod urn_codec;
45pub mod vision;
46
47pub(crate) fn block_on_ai<F, T>(future: F) -> crate::RedDBResult<T>
48where
49 F: std::future::Future<Output = T> + Send + 'static,
50 T: Send + 'static,
51{
52 if let Ok(handle) = tokio::runtime::Handle::try_current() {
53 if matches!(
54 handle.runtime_flavor(),
55 tokio::runtime::RuntimeFlavor::MultiThread
56 ) {
57 return Ok(tokio::task::block_in_place(|| handle.block_on(future)));
58 }
59
60 return std::thread::Builder::new()
61 .name("reddb-ai-blocking".to_string())
62 .spawn(move || {
63 let runtime = tokio::runtime::Builder::new_current_thread()
64 .enable_all()
65 .build()
66 .map_err(|err| {
67 crate::RedDBError::Query(format!("failed to start AI runtime: {err}"))
68 })?;
69 Ok(runtime.block_on(future))
70 })
71 .map_err(|err| {
72 crate::RedDBError::Query(format!("failed to spawn AI runtime thread: {err}"))
73 })?
74 .join()
75 .map_err(|_| crate::RedDBError::Query("AI runtime thread panicked".to_string()))?;
76 }
77
78 let runtime = tokio::runtime::Builder::new_current_thread()
79 .enable_all()
80 .build()
81 .map_err(|err| crate::RedDBError::Query(format!("failed to start AI runtime: {err}")))?;
82 Ok(runtime.block_on(future))
83}