Skip to main content

RunningTask

Struct RunningTask 

Source
pub struct RunningTask {
Show 15 fields pub task_id: String, pub typed_id: Option<TaskId>, pub task_type: TaskType, pub events_log: Mutex<Vec<String>>, pub status: Mutex<RunningStatus>, pub cancel: CancellationToken, pub started_ms: i64, pub ended_ms: Mutex<Option<i64>>, pub detail: Mutex<Value>, pub announced: AtomicBool, pub ended: Notify, pub inbox: OnceLock<Arc<dyn TaskInbox>>, pub usage: Mutex<Option<Usage>>, pub structured_output: OnceLock<Value>, pub waiting_for: Mutex<Vec<String>>, /* private fields */
}
Expand description

一件属于会话、在会话里继续跑的工作:子 Agent、团队成员、执行中的 Shell…… 输出(append_output)/ events_log / status 由跑它的那段代码追加;TaskOutput 工具与宿主的 session.taskOutput 读快照,或按字节偏移接着读; TaskStop 与宿主的 session.stopTask 触发 cancel token。

Fields§

§task_id: String§typed_id: Option<TaskId>§task_type: TaskType§events_log: Mutex<Vec<String>>

工具调用与结果的可读日志(每行一条)

§status: Mutex<RunningStatus>§cancel: CancellationToken

What the work runs under: cancelling it stops the work.

§started_ms: i64

Unix millis.

§ended_ms: Mutex<Option<i64>>

Unix millis; None while it runs.

§detail: Mutex<Value>

What a viewer needs to tell this task from another: the command, the sub-agent’s type, the tool call it belongs to.

§announced: AtomicBool

Whether its start was announced; a task that never was ends silently.

§ended: Notify

Woken once ended_ms is set — see RunningTask::wait_ended.

§inbox: OnceLock<Arc<dyn TaskInbox>>

Where messages for the work go while it runs; set by work that can take them (a sub-agent), absent for the rest.

§usage: Mutex<Option<Usage>>

What the work’s own model calls have cost so far; None for work that makes none (a shell command).

§structured_output: OnceLock<Value>

What a sub-agent with an output schema handed in.

§waiting_for: Mutex<Vec<String>>

The questions the work is waiting on the host to answer, by prompt id.

Implementations§

Source§

impl RunningTask

Source

pub const PROGRESS_FRAME_BYTES: usize

The most of the new output one task_progress carries.

Source

pub const OUTPUT_KEPT_BYTES: usize

The most of a streamed output (a shell command’s, a monitor’s) a task keeps; beyond it the oldest goes.

Source

pub fn new(task_id: String, task_type: TaskType) -> Self

Create a new running task with defaults.

Source

pub fn with_cancel( task_id: String, task_type: TaskType, cancel: CancellationToken, ) -> Self

A running task whose work runs under cancel.

Source

pub fn report_to(&self, events: Sender<TaskEvent>)

Where this task’s task_* events go; set once, by the session that registers it.

Source

pub fn add_usage(&self, call: Usage)

Count one more model call of this task’s work.

Source

pub fn begin_waiting(&self, prompt_id: &str)

The work is waiting on the host’s answer to prompt_id.

Source

pub fn end_waiting(&self, prompt_id: &str)

The question prompt_id was answered, or given up on.

Source

pub fn update_detail(&self, change: impl FnOnce(&mut Value))

Change what detail holds, then report task_updated.

Source

pub fn streams_output(&self) -> bool

Whether what the work prints is streamed as it runs (task_progress): a shell command’s, a monitor’s, a program’s and an MCP task’s status lines. A sub-agent’s output is its final answer, reported when it finishes.

Source

pub fn report_progress(&self)

Send what the work printed since the last task_progress, if anything. Nothing goes out once the output is closed, so none can follow task_finished.

Source

pub fn close_output(&self) -> bool

End the output: what the work printed since the last task_progress goes out as the last one, and nothing is added after. false if it was already closed.

Source

pub fn output_closed(&self) -> bool

Source

pub fn has_ended(&self) -> bool

Source

pub async fn wait_ended(&self)

Resolves once the task has ended (at once if it already has).

Source

pub fn append_output(&self, text: &str)

Add to the output as the work produces it, keeping its last Self::OUTPUT_KEPT_BYTES. Nothing is added once it is closed.

Source

pub fn output_text(&self) -> String

All of the output still kept.

Source

pub fn output_tail(&self, max_bytes: usize) -> OutputSlice

The last max_bytes of the output.

Source

pub fn output_from(&self, from_byte: u64) -> Result<OutputSlice, u64>

The output from byte from_byte of everything ever appended to its end, as much of it as is still kept. Err carries the end when from_byte is past it.

Source

pub fn info(&self) -> TaskInfo

This task as hosts see it (session.tasks, task_* events).

Trait Implementations§

Source§

impl Debug for RunningTask

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more