codex_runtime/adapters/web/
types.rs1use serde::{Deserialize, Serialize};
2use serde_json::Value;
3use thiserror::Error;
4
5#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
6#[serde(rename_all = "camelCase")]
7pub struct CreateSessionRequest {
8 pub artifact_id: String,
9 pub model: Option<String>,
10 pub thread_id: Option<String>,
11}
12
13#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
14#[serde(rename_all = "camelCase")]
15pub struct CreateSessionResponse {
16 pub session_id: String,
17 pub thread_id: String,
18}
19
20#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
21#[serde(rename_all = "camelCase")]
22pub struct CloseSessionResponse {
23 pub thread_id: String,
24 pub archived: bool,
25}
26
27#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
28#[serde(rename_all = "camelCase")]
29pub struct CreateTurnRequest {
30 pub task: Value,
31}
32
33#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
34#[serde(rename_all = "camelCase")]
35pub struct CreateTurnResponse {
36 pub turn_id: String,
37}
38
39#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
40#[serde(rename_all = "camelCase")]
41pub struct ApprovalResponsePayload {
42 #[serde(default)]
43 pub decision: Option<Value>,
44 #[serde(default)]
45 pub result: Option<Value>,
46}
47
48#[derive(Clone, Copy, Debug, PartialEq, Eq)]
49pub struct WebAdapterConfig {
50 pub session_event_channel_capacity: usize,
51 pub session_approval_channel_capacity: usize,
52}
53
54impl Default for WebAdapterConfig {
55 fn default() -> Self {
56 Self {
57 session_event_channel_capacity: 512,
58 session_approval_channel_capacity: 128,
59 }
60 }
61}
62
63#[derive(Clone, Debug, Error, PartialEq, Eq)]
64pub enum WebError {
65 #[error("invalid session")]
66 InvalidSession,
67 #[error("runtime already bound to a web adapter")]
68 AlreadyBound,
69 #[error("invalid approval")]
70 InvalidApproval,
71 #[error("invalid config: {0}")]
72 InvalidConfig(String),
73 #[error("invalid turn payload")]
74 InvalidTurnPayload,
75 #[error("invalid approval payload")]
76 InvalidApprovalPayload,
77 #[error(
78 "incompatible plugin contract: expected=v{expected_major}.{expected_minor} actual=v{actual_major}.{actual_minor}"
79 )]
80 IncompatibleContract {
81 expected_major: u16,
82 expected_minor: u16,
83 actual_major: u16,
84 actual_minor: u16,
85 },
86 #[error("forbidden")]
87 Forbidden,
88 #[error("session is closing")]
89 SessionClosing,
90 #[error(
91 "session thread conflict: thread={thread_id} existing_artifact={existing_artifact_id} requested_artifact={requested_artifact_id}"
92 )]
93 SessionThreadConflict {
94 thread_id: String,
95 existing_artifact_id: String,
96 requested_artifact_id: String,
97 },
98 #[error("internal error: {0}")]
99 Internal(String),
100}