-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from stakpak/feat/add-sync
Feat: Add Sync
- Loading branch information
Showing
5 changed files
with
103 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use uuid::Uuid; | ||
|
||
use crate::client::{ | ||
models::{ | ||
AgentCheckpointListItem, AgentID, AgentInput, AgentSessionListItem, AgentSessionVisibility, | ||
}, | ||
Client, | ||
}; | ||
|
||
pub async fn get_or_create_session( | ||
client: &Client, | ||
agent_id: AgentID, | ||
checkpoint_id: Option<String>, | ||
input: Option<AgentInput>, | ||
) -> Result<(AgentID, AgentSessionListItem, AgentCheckpointListItem), String> { | ||
match checkpoint_id { | ||
Some(checkpoint_id) => { | ||
let checkpoint_uuid = Uuid::parse_str(&checkpoint_id).map_err(|_| { | ||
format!( | ||
"Invalid checkpoint ID '{}' - must be a valid UUID", | ||
checkpoint_id | ||
) | ||
})?; | ||
|
||
let output = client.get_agent_checkpoint(checkpoint_uuid).await?; | ||
|
||
Ok(( | ||
output.output.get_agent_id(), | ||
output.session, | ||
output.checkpoint, | ||
)) | ||
} | ||
None => { | ||
let session = client | ||
.create_agent_session( | ||
agent_id.clone(), | ||
AgentSessionVisibility::Private, | ||
input.clone(), | ||
) | ||
.await?; | ||
|
||
let checkpoint = session | ||
.checkpoints | ||
.first() | ||
.ok_or("No checkpoint found in new session")? | ||
.clone(); | ||
|
||
Ok((agent_id, session.into(), checkpoint)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters