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