mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
623707ab58
Add implementation for the `wait` tool. For this we consider all status different from `PendingInit` and `Running` as terminal. The `wait` tool call will return either after a given timeout or when the tool reaches a non-terminal status. A few points to note: * The usage of a channel is preferred to prevent some races (just looping on `get_status()` could "miss" a terminal status) * The order of operations is very important, we need to first subscribe and then check the last known status to prevent race conditions * If the channel gets dropped, we return an error on purpose
50 lines
1.3 KiB
Rust
50 lines
1.3 KiB
Rust
use crate::agent::AgentStatus;
|
|
use crate::codex::Codex;
|
|
use crate::error::Result as CodexResult;
|
|
use crate::protocol::Event;
|
|
use crate::protocol::Op;
|
|
use crate::protocol::Submission;
|
|
use std::path::PathBuf;
|
|
use tokio::sync::watch;
|
|
|
|
pub struct CodexThread {
|
|
codex: Codex,
|
|
rollout_path: PathBuf,
|
|
}
|
|
|
|
/// Conduit for the bidirectional stream of messages that compose a thread
|
|
/// (formerly called a conversation) in Codex.
|
|
impl CodexThread {
|
|
pub(crate) fn new(codex: Codex, rollout_path: PathBuf) -> Self {
|
|
Self {
|
|
codex,
|
|
rollout_path,
|
|
}
|
|
}
|
|
|
|
pub async fn submit(&self, op: Op) -> CodexResult<String> {
|
|
self.codex.submit(op).await
|
|
}
|
|
|
|
/// Use sparingly: this is intended to be removed soon.
|
|
pub async fn submit_with_id(&self, sub: Submission) -> CodexResult<()> {
|
|
self.codex.submit_with_id(sub).await
|
|
}
|
|
|
|
pub async fn next_event(&self) -> CodexResult<Event> {
|
|
self.codex.next_event().await
|
|
}
|
|
|
|
pub async fn agent_status(&self) -> AgentStatus {
|
|
self.codex.agent_status().await
|
|
}
|
|
|
|
pub(crate) fn subscribe_status(&self) -> watch::Receiver<AgentStatus> {
|
|
self.codex.agent_status.clone()
|
|
}
|
|
|
|
pub fn rollout_path(&self) -> PathBuf {
|
|
self.rollout_path.clone()
|
|
}
|
|
}
|