Class: RubyCoded::Chat::CodexBridge

Inherits:
Object
  • Object
show all
Includes:
BridgeCommon, ErrorHandling, RequestBuilder, SSEParser, TokenManager, ToolHandling
Defined in:
lib/ruby_coded/chat/codex_bridge.rb,
lib/ruby_coded/chat/codex_bridge/sse_parser.rb,
lib/ruby_coded/chat/codex_bridge/token_manager.rb,
lib/ruby_coded/chat/codex_bridge/tool_approval.rb,
lib/ruby_coded/chat/codex_bridge/tool_handling.rb,
lib/ruby_coded/chat/codex_bridge/error_handling.rb,
lib/ruby_coded/chat/codex_bridge/request_builder.rb

Overview

HTTP client for the ChatGPT Codex backend (Responses API). Implements the same public interface as LLMBridge so App can swap between them based on the active auth_method.

Defined Under Namespace

Modules: ErrorHandling, RequestBuilder, SSEParser, TokenManager, ToolApproval, ToolHandling

Constant Summary collapse

CODEX_BASE_URL =
"https://chatgpt.com"
CODEX_RESPONSES_PATH =
"/backend-api/codex/responses"
DEFAULT_MODEL =
"gpt-5.4"
MAX_RATE_LIMIT_RETRIES =
2
RATE_LIMIT_BASE_DELAY =
2
MAX_WRITE_TOOL_ROUNDS =
Tools::ExecutionPolicy::MAX_WRITE_TOOL_ROUNDS
MAX_TOTAL_TOOL_ROUNDS =
Tools::ExecutionPolicy::MAX_TOTAL_TOOL_ROUNDS
MAX_TOOL_RESULT_CHARS =
10_000

Constants included from ErrorHandling

ErrorHandling::UNSUPPORTED_MODEL_PATTERN

Constants included from TokenManager

TokenManager::TOKEN_REFRESH_BUFFER

Constants included from RequestBuilder

RequestBuilder::CODEX_HEADERS_BASE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BridgeCommon

included

Constructor Details

#initialize(state, credentials_store:, auth_manager:, project_root: Dir.pwd, skill_catalog: nil) ⇒ CodexBridge

Returns a new instance of CodexBridge.



59
60
61
62
63
64
65
66
# File 'lib/ruby_coded/chat/codex_bridge.rb', line 59

def initialize(state, credentials_store:, auth_manager:, project_root: Dir.pwd, skill_catalog: nil)
  @state = state
  @credentials_store = credentials_store
  @auth_manager = auth_manager
  @project_root = project_root
  @skill_catalog = skill_catalog || RubyCoded::Skills::Catalog.new(project_root: @project_root)
  initialize_runtime_state
end

Instance Attribute Details

#modeObject (readonly)

Returns the value of attribute mode.



57
58
59
# File 'lib/ruby_coded/chat/codex_bridge.rb', line 57

def mode
  @mode
end

#project_rootObject (readonly)

Returns the value of attribute project_root.



57
58
59
# File 'lib/ruby_coded/chat/codex_bridge.rb', line 57

def project_root
  @project_root
end

Instance Method Details

#initialize_runtime_stateObject



68
69
70
71
72
73
74
75
76
# File 'lib/ruby_coded/chat/codex_bridge.rb', line 68

def initialize_runtime_state
  @cancel_requested = false
  @mode = RuntimeMode.chat
  @model = @state.model
  @conversation_history = []
  setup_agent_pipeline!
  reset_call_counts
  @conn = build_connection
end

#reset_agent_session!Object



93
94
95
96
# File 'lib/ruby_coded/chat/codex_bridge.rb', line 93

def reset_agent_session!
  @policy.reset_counters!
  @conversation_history = []
end

#reset_chat!(model_name) ⇒ Object



88
89
90
91
# File 'lib/ruby_coded/chat/codex_bridge.rb', line 88

def reset_chat!(model_name)
  @model = model_name
  @conversation_history = []
end

#send_async(input) ⇒ Object



78
79
80
81
82
83
84
85
86
# File 'lib/ruby_coded/chat/codex_bridge.rb', line 78

def send_async(input)
  prepare_send(input)
  @conversation_history << { role: "user", content: input }
  Thread.new do
    attempt_with_retries(input)
  ensure
    @state.streaming = false
  end
end