-
Notifications
You must be signed in to change notification settings - Fork 32
feat: stream zeroclaw sidecar responses via ChatDelta events #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
2592383
5c5d846
1348570
3a7eaa9
57cc7f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ use serde_json::Value; | |
|
|
||
| use super::process::run_zeroclaw_message; | ||
| use super::session::{append_history, build_prompt_with_history, reset_history}; | ||
| use super::streaming::run_zeroclaw_streaming_turn; | ||
|
|
||
| pub struct ZeroclawDoctorAdapter; | ||
|
|
||
|
|
@@ -116,6 +117,59 @@ impl ZeroclawDoctorAdapter { | |
| } | ||
| } | ||
|
|
||
| impl ZeroclawDoctorAdapter { | ||
| pub async fn start_streaming<F>( | ||
| &self, | ||
| key: &RuntimeSessionKey, | ||
| message: &str, | ||
| on_delta: F, | ||
| ) -> Result<Vec<RuntimeEvent>, RuntimeError> | ||
| where | ||
| F: Fn(&str) + Send + Sync + 'static, | ||
| { | ||
| let prompt = Self::doctor_domain_prompt(key, message); | ||
| let assistant_events = run_zeroclaw_streaming_turn( | ||
| key, | ||
| &prompt, | ||
| true, | ||
| None, | ||
| on_delta, | ||
| Self::normalize_doctor_output, | ||
| Self::parse_tool_intent, | ||
| Self::map_error, | ||
| ) | ||
| .await?; | ||
| let session_key = key.storage_key(); | ||
| append_history(&session_key, "system", &prompt); | ||
|
Comment on lines
+141
to
+143
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In Useful? React with 👍 / 👎. |
||
| Ok(assistant_events) | ||
| } | ||
|
|
||
| pub async fn send_streaming<F>( | ||
| &self, | ||
| key: &RuntimeSessionKey, | ||
| message: &str, | ||
| on_delta: F, | ||
| ) -> Result<Vec<RuntimeEvent>, RuntimeError> | ||
| where | ||
| F: Fn(&str) + Send + Sync + 'static, | ||
| { | ||
| let prompt = build_prompt_with_history(&key.storage_key(), message); | ||
| let guarded = Self::doctor_domain_prompt(key, &prompt); | ||
| let assistant_events = run_zeroclaw_streaming_turn( | ||
| key, | ||
| &guarded, | ||
| false, | ||
| Some(message), | ||
| on_delta, | ||
| Self::normalize_doctor_output, | ||
| Self::parse_tool_intent, | ||
| Self::map_error, | ||
| ) | ||
| .await?; | ||
| Ok(assistant_events) | ||
| } | ||
| } | ||
|
|
||
| impl RuntimeAdapter for ZeroclawDoctorAdapter { | ||
| fn engine_name(&self) -> &'static str { | ||
| "zeroclaw" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ use serde_json::json; | |
|
|
||
| use super::process::run_zeroclaw_message; | ||
| use super::session::{append_history, build_prompt_with_history_preamble, reset_history}; | ||
| use super::streaming::run_zeroclaw_streaming_turn; | ||
|
|
||
| pub struct ZeroclawInstallAdapter; | ||
|
|
||
|
|
@@ -67,6 +68,63 @@ impl ZeroclawInstallAdapter { | |
| } | ||
| } | ||
|
|
||
| impl ZeroclawInstallAdapter { | ||
| pub async fn start_streaming<F>( | ||
| &self, | ||
| key: &RuntimeSessionKey, | ||
| message: &str, | ||
| on_delta: F, | ||
| ) -> Result<Vec<RuntimeEvent>, RuntimeError> | ||
| where | ||
| F: Fn(&str) + Send + Sync + 'static, | ||
| { | ||
| let session_key = key.storage_key(); | ||
| reset_history(&session_key); | ||
| let prompt = Self::install_domain_prompt(key, message); | ||
| let assistant_events = run_zeroclaw_streaming_turn( | ||
| key, | ||
| &prompt, | ||
| true, | ||
| None, | ||
| on_delta, | ||
| |text| text, | ||
| Self::parse_tool_intent, | ||
| Self::map_error, | ||
| ) | ||
| .await?; | ||
| append_history(&session_key, "system", &prompt); | ||
| Ok(assistant_events) | ||
| } | ||
|
|
||
| pub async fn send_streaming<F>( | ||
| &self, | ||
| key: &RuntimeSessionKey, | ||
| message: &str, | ||
| on_delta: F, | ||
| ) -> Result<Vec<RuntimeEvent>, RuntimeError> | ||
| where | ||
| F: Fn(&str) + Send + Sync + 'static, | ||
| { | ||
| let session_key = key.storage_key(); | ||
| append_history(&session_key, "user", message); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Useful? React with 👍 / 👎. |
||
| let preamble = format!("{}\n", crate::prompt_templates::install_history_preamble()); | ||
| let prompt = build_prompt_with_history_preamble(&session_key, message, &preamble); | ||
| let guarded = Self::install_domain_prompt(key, &prompt); | ||
| let assistant_events = run_zeroclaw_streaming_turn( | ||
| key, | ||
| &guarded, | ||
| false, | ||
| Some(message), | ||
| on_delta, | ||
| |text| text, | ||
| Self::parse_tool_intent, | ||
| Self::map_error, | ||
| ) | ||
| .await?; | ||
| Ok(assistant_events) | ||
| } | ||
| } | ||
|
|
||
| impl RuntimeAdapter for ZeroclawInstallAdapter { | ||
| fn engine_name(&self) -> &'static str { | ||
| "zeroclaw" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| pub mod adapter; | ||
| mod streaming; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BS: |
||
| pub mod install_adapter; | ||
| pub mod process; | ||
| pub mod sanitize; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.