opencode-ruby — idiomatic Ruby client for OpenCode (HTTP + SSE). Hand-rolled, opinionated Ruby SDK with block-form streaming, value- object responses, and automatic SSE reconnection. Pluggable Opencode::Instrumentation adapter for routing events to ActiveSupport::Notifications, OpenTelemetry, stdout, or any custom emitter. Companion to opencode-rails for AR-coupled Rails apps. What this version ships: - Opencode::Client (Net::HTTP + SSE) - Opencode::Reply / Reply::Result / ReplyObserver - Opencode::Tracer, Opencode::Prompts - Opencode::ResponseParser, ToolPart, PartSource, Todo - Opencode::Instrumentation (instrument + notify) - Opencode::Error and seven subclasses - examples/conversation_recipe.rb — canonical Rails wiring blueprint 15 smoke tests. CI on Ruby 3.2/3.3/3.4. Ruby >= 3.2. Runtime dep: activesupport >= 6.1, < 9.0. See CHANGELOG.md for the alpha1 -> alpha2 delta.
29 lines
1008 B
Ruby
29 lines
1008 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Opencode
|
|
class Error < StandardError
|
|
attr_reader :response
|
|
|
|
def initialize(message = nil, response: nil)
|
|
@response = response
|
|
super(message)
|
|
end
|
|
end
|
|
|
|
class ConnectionError < Error; end
|
|
class TimeoutError < Error; end
|
|
class SessionNotFoundError < Error; end
|
|
class StaleSessionError < Error; end
|
|
# Raised by stream_events when meaningful (non-`server.*`) events stop
|
|
# arriving for longer than the caller's `idle_stream_timeout` window,
|
|
# even though the SSE socket itself is still alive (heartbeats are
|
|
# still flowing). Distinct from StaleSessionError, which fires when
|
|
# the session never produced any events in the first place. This one
|
|
# fires when the session WAS producing events and then went silent —
|
|
# the classic "OpenAI stream wedged mid-turn while the SSE keep-
|
|
# alive ticks on" failure mode.
|
|
class IdleStreamError < Error; end
|
|
class ServerError < Error; end
|
|
class BadRequestError < Error; end
|
|
end
|