codex_code_mode_protocol/
runtime.rs1use codex_protocol::ToolName;
2use serde::Deserialize;
3use serde::Serialize;
4use serde_json::Value as JsonValue;
5
6use crate::CellId;
7use crate::CodeModeToolKind;
8use crate::FunctionCallOutputContentItem;
9use crate::ToolDefinition;
10
11pub const DEFAULT_EXEC_YIELD_TIME_MS: u64 = 10_000;
12pub const DEFAULT_WAIT_YIELD_TIME_MS: u64 = 10_000;
13pub const DEFAULT_MAX_OUTPUT_TOKENS_PER_EXEC_CALL: usize = 10_000;
14
15#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
16pub struct ExecuteRequest {
17 pub tool_call_id: String,
18 pub enabled_tools: Vec<ToolDefinition>,
19 pub source: String,
20 pub yield_time_ms: Option<u64>,
21 pub max_output_tokens: Option<usize>,
22}
23
24#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
25pub struct WaitRequest {
26 pub cell_id: CellId,
27 pub yield_time_ms: u64,
28}
29
30#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
31pub struct WaitToPendingRequest {
32 pub cell_id: CellId,
33}
34
35#[derive(Debug, Deserialize, PartialEq, Serialize)]
36pub enum WaitOutcome {
37 LiveCell(RuntimeResponse),
38 MissingCell(RuntimeResponse),
39}
40
41#[derive(Debug, Deserialize, PartialEq, Serialize)]
42pub enum ExecuteToPendingOutcome {
43 Pending {
44 cell_id: CellId,
45 content_items: Vec<FunctionCallOutputContentItem>,
46 pending_tool_call_ids: Vec<String>,
47 },
48 Completed(RuntimeResponse),
49}
50
51#[derive(Debug, Deserialize, PartialEq, Serialize)]
52pub enum WaitToPendingOutcome {
53 LiveCell(ExecuteToPendingOutcome),
54 MissingCell(RuntimeResponse),
55}
56
57impl From<WaitOutcome> for RuntimeResponse {
58 fn from(outcome: WaitOutcome) -> Self {
59 match outcome {
60 WaitOutcome::LiveCell(response) | WaitOutcome::MissingCell(response) => response,
61 }
62 }
63}
64
65#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
66pub enum RuntimeResponse {
67 Yielded {
68 cell_id: CellId,
69 content_items: Vec<FunctionCallOutputContentItem>,
70 },
71 Terminated {
72 cell_id: CellId,
73 content_items: Vec<FunctionCallOutputContentItem>,
74 },
75 Result {
76 cell_id: CellId,
77 content_items: Vec<FunctionCallOutputContentItem>,
78 error_text: Option<String>,
79 },
80}
81
82#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
83pub struct CodeModeNestedToolCall {
84 pub cell_id: CellId,
85 pub runtime_tool_call_id: String,
86 pub tool_name: ToolName,
87 pub tool_kind: CodeModeToolKind,
88 pub input: Option<JsonValue>,
89}