algocline_core/execution/resume.rs
1//! Resume-related types for the `ExecutionService` layer.
2
3use serde::{Deserialize, Serialize};
4
5use super::cancel::{CancelInfo, FailureInfo};
6use super::state::ExecutionResult;
7use crate::TokenUsage;
8
9/// Payload supplied to [`crate::execution::ExecutionService::resume`].
10///
11/// Must match the pause kind of the session being resumed: a `Single`-paused session
12/// requires `Single`, a `Batch`-paused session requires `Batch`.
13#[derive(Debug, Clone, Serialize, Deserialize)]
14#[serde(tag = "payload_kind", rename_all = "snake_case")]
15pub enum ResumePayload {
16 /// Resume a session that is waiting for a single LLM response.
17 Single {
18 /// The LLM response text.
19 response: String,
20 /// Token usage metadata for this response, if available.
21 usage: Option<TokenUsage>,
22 /// Identifies the query this response corresponds to.
23 query_id: String,
24 },
25 /// Resume a session that is waiting for multiple LLM responses.
26 Batch(Vec<QueryResponse>),
27}
28
29/// A single LLM response in a [`ResumePayload::Batch`].
30///
31/// Note: this type is distinct from the legacy `algocline_core::QueryResponse`
32/// (re-exported via `engine_api.rs`) to avoid naming conflicts. Access this type
33/// via `algocline_core::execution::QueryResponse`.
34#[derive(Debug, Clone, Serialize, Deserialize)]
35pub struct QueryResponse {
36 /// Identifies the query this response is for.
37 pub query_id: String,
38 /// The LLM response text.
39 pub response: String,
40 /// Token usage metadata for this response, if available.
41 pub usage: Option<TokenUsage>,
42}
43
44/// Outcome returned by [`crate::execution::ExecutionService::resume`].
45#[derive(Debug, Clone, Serialize, Deserialize)]
46#[serde(tag = "outcome", rename_all = "snake_case")]
47pub enum ResumeOutcome {
48 /// The session accepted the response and is continuing execution.
49 Continued,
50 /// The session reached a terminal state after processing the response.
51 Terminal(TerminalOutcome),
52}
53
54/// Terminal outcome for a session — carried by [`ResumeOutcome::Terminal`] and
55/// by [`crate::execution::ExecutionService::await_terminal`].
56#[derive(Debug, Clone, Serialize, Deserialize)]
57#[serde(tag = "terminal", rename_all = "snake_case")]
58pub enum TerminalOutcome {
59 /// The session completed successfully.
60 Done(ExecutionResult),
61 /// The session was cancelled cooperatively.
62 Cancelled(CancelInfo),
63 /// The session ended with an error.
64 Failed(FailureInfo),
65}