(
&self,
prompt: String,
attachments: Vec<AttachmentObject>,
history: Option<Vec<MessageObject>>,
)
| 3494 | /// @param history - Optional conversation history |
| 3495 | #[napi] |
| 3496 | pub async fn stream_with_attachments( |
| 3497 | &self, |
| 3498 | prompt: String, |
| 3499 | attachments: Vec<AttachmentObject>, |
| 3500 | history: Option<Vec<MessageObject>>, |
| 3501 | ) -> napi::Result<EventStream> { |
| 3502 | let rust_attachments = js_attachments_to_rust(&attachments); |
| 3503 | let rust_history = history.map(|h| js_messages_to_rust(&h)).transpose()?; |
| 3504 | let session = self.inner.clone(); |
| 3505 | let (rx, _handle) = get_runtime() |
| 3506 | .spawn(async move { |
| 3507 | session |
| 3508 | .stream_with_attachments(&prompt, &rust_attachments, rust_history.as_deref()) |
| 3509 | .await |
| 3510 | }) |
| 3511 | .await |
| 3512 | .map_err(|e| napi::Error::from_reason(format!("Task join error: {e}")))? |
| 3513 | .map_err(|e| napi::Error::from_reason(format!("Failed to start stream: {e}")))?; |
| 3514 | Ok(EventStream { |
| 3515 | rx: Arc::new(tokio::sync::Mutex::new(rx)), |
| 3516 | done: Arc::new(AtomicBool::new(false)), |
| 3517 | }) |
| 3518 | } |
| 3519 | |
| 3520 | /// Return the session's conversation history. |
| 3521 | #[napi] |
no test coverage detected