|
1 | 1 | use std::error::Error;
|
2 |
| -use std::fmt::{Debug, Display, Formatter}; |
| 2 | +use std::fmt::Debug; |
3 | 3 |
|
4 | 4 | use async_trait::async_trait;
|
5 | 5 | use log::info;
|
6 | 6 | use reqwest::Url;
|
7 |
| -use reqwest::header::HeaderMap; |
8 | 7 | use serde::{Deserialize, Serialize};
|
9 | 8 |
|
10 | 9 | use ag_ui_client::agent::{AgentError, AgentStateMutation, RunAgentParams};
|
| 10 | +use ag_ui_client::core::AgentState; |
| 11 | +use ag_ui_client::core::event::{StateDeltaEvent, StateSnapshotEvent}; |
| 12 | +use ag_ui_client::core::types::Message; |
11 | 13 | use ag_ui_client::subscriber::{AgentSubscriber, AgentSubscriberParams};
|
12 | 14 | use ag_ui_client::{Agent, HttpAgent};
|
13 |
| -use ag_ui_core::event::{StateDeltaEvent, StateSnapshotEvent}; |
14 |
| -use ag_ui_core::types::ids::MessageId; |
15 |
| -use ag_ui_core::types::message::Message; |
16 |
| -use ag_ui_core::{AgentState, FwdProps, JsonValue}; |
17 | 15 |
|
18 | 16 | #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Hash)]
|
| 17 | +#[serde(rename_all = "lowercase")] |
19 | 18 | pub enum StepStatus {
|
20 |
| - #[serde(rename = "pending")] |
21 | 19 | Pending,
|
22 |
| - #[serde(rename = "completed")] |
23 | 20 | Completed,
|
24 | 21 | }
|
25 | 22 |
|
26 |
| -impl Display for StepStatus { |
27 |
| - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { |
28 |
| - match self { |
29 |
| - StepStatus::Pending => write!(f, "pending"), |
30 |
| - StepStatus::Completed => write!(f, "completed"), |
31 |
| - } |
32 |
| - } |
33 |
| -} |
34 |
| - |
35 | 23 | impl Default for StepStatus {
|
36 | 24 | fn default() -> Self {
|
37 | 25 | StepStatus::Pending
|
@@ -71,14 +59,11 @@ impl GenerativeUiSubscriber {
|
71 | 59 | }
|
72 | 60 |
|
73 | 61 | #[async_trait]
|
74 |
| -impl<FwdPropsT> AgentSubscriber<Plan, FwdPropsT> for GenerativeUiSubscriber |
75 |
| -where |
76 |
| - FwdPropsT: FwdProps + Debug, |
77 |
| -{ |
| 62 | +impl AgentSubscriber<Plan, ()> for GenerativeUiSubscriber { |
78 | 63 | async fn on_state_snapshot_event(
|
79 | 64 | &self,
|
80 | 65 | event: &StateSnapshotEvent<Plan>,
|
81 |
| - _params: AgentSubscriberParams<'async_trait, Plan, FwdPropsT>, |
| 66 | + _params: AgentSubscriberParams<'async_trait, Plan, ()>, |
82 | 67 | ) -> Result<AgentStateMutation<Plan>, AgentError> {
|
83 | 68 | info!("State snapshot received:");
|
84 | 69 | let plan = &event.snapshot;
|
|
96 | 81 | async fn on_state_delta_event(
|
97 | 82 | &self,
|
98 | 83 | event: &StateDeltaEvent,
|
99 |
| - _params: AgentSubscriberParams<'async_trait, Plan, FwdPropsT>, |
| 84 | + _params: AgentSubscriberParams<'async_trait, Plan, ()>, |
100 | 85 | ) -> Result<AgentStateMutation<Plan>, AgentError> {
|
101 | 86 | info!("State delta received:");
|
102 | 87 | for patch in &event.delta {
|
@@ -131,7 +116,7 @@ where
|
131 | 116 |
|
132 | 117 | async fn on_state_changed(
|
133 | 118 | &self,
|
134 |
| - params: AgentSubscriberParams<'async_trait, Plan, FwdPropsT>, |
| 119 | + params: AgentSubscriberParams<'async_trait, Plan, ()>, |
135 | 120 | ) -> Result<(), AgentError> {
|
136 | 121 | info!("Overall state changed");
|
137 | 122 | let completed_steps = params
|
@@ -162,20 +147,16 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
162 | 147 | // Create the HTTP agent
|
163 | 148 | let agent = HttpAgent::builder().with_url(base_url).build()?;
|
164 | 149 |
|
| 150 | + let message = Message::new_user( |
| 151 | + "I need to organize a birthday party for my friend. Can you help me \ |
| 152 | + create a plan? When you have created the plan, please fully execute it.", |
| 153 | + ); |
| 154 | + |
165 | 155 | let subscriber = GenerativeUiSubscriber::new();
|
166 | 156 |
|
167 | 157 | // Create run parameters for testing generative UI with planning
|
168 |
| - let params = RunAgentParams { |
169 |
| - messages: vec![Message::User { |
170 |
| - id: MessageId::random(), |
171 |
| - content: "I need to organize a birthday party for my friend. Can you help me \ |
172 |
| - create a plan? When you have created the plan, please fully execute it." |
173 |
| - .into(), |
174 |
| - name: None, |
175 |
| - }], |
176 |
| - forwarded_props: Some(JsonValue::Null), |
177 |
| - ..Default::default() |
178 |
| - }; |
| 158 | + // State & FwdProps types are defined by GenerativeUiSubscriber |
| 159 | + let params = RunAgentParams::new_typed().add_message(message); |
179 | 160 |
|
180 | 161 | info!("Starting generative UI agent run...");
|
181 | 162 | info!("Testing planning functionality with state snapshots and deltas");
|
|
0 commit comments