mirror of
https://github.com/RightNow-AI/openfang.git
synced 2026-08-14 08:52:02 +00:00
image pipeline
This commit is contained in:
@@ -379,7 +379,7 @@ async fn stream_response(
|
||||
|
||||
let (mut rx, _handle) = state
|
||||
.kernel
|
||||
.send_message_streaming(agent_id, message, Some(kernel_handle), None, None)
|
||||
.send_message_streaming(agent_id, message, Some(kernel_handle), None, None, None)
|
||||
.map_err(|e| format!("Streaming setup failed: {e}"))?;
|
||||
|
||||
let (tx, stream_rx) = tokio::sync::mpsc::channel::<Result<SseEvent, Infallible>>(64);
|
||||
|
||||
@@ -358,21 +358,24 @@ pub async fn send_message(
|
||||
);
|
||||
}
|
||||
|
||||
// Resolve file attachments into image content blocks
|
||||
if !req.attachments.is_empty() {
|
||||
// Resolve file attachments into image content blocks.
|
||||
// Pass them as content_blocks so the LLM receives them in the current turn
|
||||
// (not as a separate session message which the LLM may not process).
|
||||
let content_blocks = if !req.attachments.is_empty() {
|
||||
let image_blocks = resolve_attachments(&req.attachments);
|
||||
if !image_blocks.is_empty() {
|
||||
inject_attachments_into_session(&state.kernel, agent_id, image_blocks);
|
||||
}
|
||||
}
|
||||
if image_blocks.is_empty() { None } else { Some(image_blocks) }
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let kernel_handle: Arc<dyn KernelHandle> = state.kernel.clone() as Arc<dyn KernelHandle>;
|
||||
match state
|
||||
.kernel
|
||||
.send_message_with_handle(
|
||||
.send_message_with_handle_and_blocks(
|
||||
agent_id,
|
||||
&req.message,
|
||||
Some(kernel_handle),
|
||||
content_blocks,
|
||||
req.sender_id,
|
||||
req.sender_name,
|
||||
)
|
||||
@@ -1412,6 +1415,7 @@ pub async fn send_message_stream(
|
||||
Some(kernel_handle),
|
||||
req.sender_id,
|
||||
req.sender_name,
|
||||
None, // SSE streaming doesn't support image attachments yet
|
||||
) {
|
||||
Ok(pair) => pair,
|
||||
Err(e) => {
|
||||
|
||||
@@ -439,6 +439,7 @@ async fn handle_text_message(
|
||||
|
||||
// Resolve file attachments into image content blocks
|
||||
let mut has_images = false;
|
||||
let mut ws_content_blocks: Option<Vec<openfang_types::message::ContentBlock>> = None;
|
||||
if let Some(attachments) = parsed["attachments"].as_array() {
|
||||
let refs: Vec<crate::types::AttachmentRef> = attachments
|
||||
.iter()
|
||||
@@ -448,11 +449,7 @@ async fn handle_text_message(
|
||||
let image_blocks = crate::routes::resolve_attachments(&refs);
|
||||
if !image_blocks.is_empty() {
|
||||
has_images = true;
|
||||
crate::routes::inject_attachments_into_session(
|
||||
&state.kernel,
|
||||
agent_id,
|
||||
image_blocks,
|
||||
);
|
||||
ws_content_blocks = Some(image_blocks);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -508,6 +505,7 @@ async fn handle_text_message(
|
||||
Some(kernel_handle),
|
||||
None,
|
||||
None,
|
||||
ws_content_blocks,
|
||||
) {
|
||||
Ok((mut rx, handle)) => {
|
||||
// Forward stream events to WebSocket with debouncing.
|
||||
|
||||
@@ -303,7 +303,7 @@ pub fn spawn_inprocess_stream(
|
||||
// send_message_streaming() finds the reactor.
|
||||
let _guard = rt.enter();
|
||||
|
||||
match kernel.send_message_streaming(agent_id, &message, None, None, None) {
|
||||
match kernel.send_message_streaming(agent_id, &message, None, None, None, None) {
|
||||
Ok((mut rx, handle)) => {
|
||||
rt.block_on(async {
|
||||
while let Some(ev) = rx.recv().await {
|
||||
|
||||
@@ -1605,6 +1605,7 @@ impl OpenFangKernel {
|
||||
kernel_handle: Option<Arc<dyn KernelHandle>>,
|
||||
sender_id: Option<String>,
|
||||
sender_name: Option<String>,
|
||||
content_blocks: Option<Vec<openfang_types::message::ContentBlock>>,
|
||||
) -> KernelResult<(
|
||||
tokio::sync::mpsc::Receiver<StreamEvent>,
|
||||
tokio::task::JoinHandle<KernelResult<AgentLoopResult>>,
|
||||
@@ -1960,7 +1961,7 @@ impl OpenFangKernel {
|
||||
Some(&kernel_clone.hooks),
|
||||
ctx_window,
|
||||
Some(&kernel_clone.process_manager),
|
||||
None, // content_blocks (streaming path uses text only for now)
|
||||
content_blocks,
|
||||
)
|
||||
.await;
|
||||
|
||||
|
||||
@@ -303,7 +303,7 @@ async fn test_wasm_agent_streaming_fallback() {
|
||||
let agent_id = kernel.spawn_agent(manifest).unwrap();
|
||||
|
||||
let (mut rx, handle) = kernel
|
||||
.send_message_streaming(agent_id, "Hi!", None, None, None)
|
||||
.send_message_streaming(agent_id, "Hi!", None, None, None, None)
|
||||
.expect("Streaming should start");
|
||||
|
||||
// Collect all stream events
|
||||
|
||||
Reference in New Issue
Block a user