class OpenUI::Rails::Configuration
Global, process-wide configuration for the gem.
OpenUI::Rails.configure do |config| config.transport = :turbo config.library_spec_path = Rails.root.join("config/openui/library.spec.json") config.runtime_assets = :self_hosted end
Constants
- ASSET_STRATEGIES
-
Runtime asset strategies supported by the gem.
- DEFAULT_ACTIONS_ENDPOINT
-
Default engine endpoint for action submissions.
- DEFAULT_IDEMPOTENCY_TTL
-
Lifetime of an action idempotency claim, in seconds.
- DEFAULT_PENDING_BYTE_LIMIT
-
Buffer size before the bridge emits a delta, in bytes.
- DEFAULT_STREAM_BYTE_LIMIT
-
Maximum response size passed through the stream bridge, in bytes.
- TRANSPORTS
-
Transport names accepted by the host preference setting.
Attributes
The registry of callable actions. Lazily created so require order does not matter and host apps can replace it if they wish.
@return [Actions::Registry]
Public Class Methods
Source
# File lib/openui/rails/configuration.rb, line 42 def initialize @transport = :turbo @runtime_assets = :self_hosted @library_spec_path = nil @prompt_path = nil @library_name = :chat @actions_endpoint = DEFAULT_ACTIONS_ENDPOINT @surface_id_param = :surface_id @stream_byte_limit = DEFAULT_STREAM_BYTE_LIMIT @pending_byte_limit = DEFAULT_PENDING_BYTE_LIMIT @idempotency_ttl = DEFAULT_IDEMPOTENCY_TTL @idempotency_store = nil @authorize_action = nil @on_error = nil @action_registry = nil @surface_resolver = nil @actor_resolver = nil @runtime_version = nil @runtime_url = nil @runtime_integrity = nil @local_runtime_path = "/openui" end
Create the default integration settings.
@return [Configuration]
Public Instance Methods
Source
# File lib/openui/rails/configuration.rb, line 189 def actor_resolver=(callable) unless callable.nil? || callable.respond_to?(:call) raise ConfigurationError, "actor_resolver must respond to #call" end @actor_resolver = callable end
Set the callable that resolves the current actor from the engine controller.
@param callable [#call, nil] receives the engine controller
@return [#call, nil]
# File lib/openui/rails/configuration.rb, line 150 def idempotency_scope=(callable) unless callable.nil? || callable.respond_to?(:call) raise ConfigurationError, "idempotency_scope must respond to #call" end @idempotency_scope = callable end
Set a callable that returns a stable actor and tenant idempotency scope.
@param callable [#call, nil] receives an Actions::Invocation
@return [#call, nil]
Source
# File lib/openui/rails/configuration.rb, line 200 def idempotency_store @idempotency_store ||= Actions::Idempotency::MemoryStore.new end
Return the configured store, creating a process-local memory store by default.
@return [#claim, #record]
Source
# File lib/openui/rails/configuration.rb, line 127 def idempotency_store=(store) unless store.nil? || (store.respond_to?(:claim) && store.respond_to?(:record)) raise ConfigurationError, "idempotency_store must respond to #claim and #record" end @idempotency_store = store end
Set the store used to claim and record action idempotency keys. A shared store must implement the atomic contract described in the configuration guide.
@param store [#claim, #record, nil]
@return [#claim, #record]
Source
# File lib/openui/rails/configuration.rb, line 215 def library_fingerprint library_manifest&.fingerprint end
Fingerprint of the pinned library manifest, or nil when unconfigured.
@return [String, nil]
Source
# File lib/openui/rails/configuration.rb, line 222 def library_manifest return @library_manifest if defined?(@library_manifest) && @library_manifest path = library_spec_path return nil if path.nil? @library_manifest = LibraryManifest.load(path) end
Memoized manifest for the configured library_spec_path.
@return [LibraryManifest, nil]
Source
# File lib/openui/rails/configuration.rb, line 67 def library_name deprecated_setting(:library_name) @library_name end
@deprecated Has no effect: the runtime library comes from the loaded
bundle and its manifest. Removed in 1.0.
Source
# File lib/openui/rails/configuration.rb, line 73 def library_name=(value) deprecated_setting(:library_name) @library_name = value end
@deprecated Has no effect. Removed in 1.0.
Source
# File lib/openui/rails/configuration.rb, line 140 def library_spec_path=(path) @library_spec_path = path reset! end
Set the manifest path and clear the cached manifest.
@param path [String, Pathname, nil]
@return [String, Pathname, nil]
Source
# File lib/openui/rails/configuration.rb, line 236 def reset! remove_instance_variable(:@library_manifest) if defined?(@library_manifest) self end
Drop memoized derived state (used after config changes and in tests). The action registry and idempotency store are runtime state and are preserved so re-configuring does not silently unregister actions.
@return [self]
Source
# File lib/openui/rails/configuration.rb, line 110 def runtime_assets=(value) value = value.to_sym if value.respond_to?(:to_sym) unless ASSET_STRATEGIES.include?(value) raise ConfigurationError, "unsupported runtime_assets #{value.inspect}; expected one of #{ASSET_STRATEGIES.inspect}" end @runtime_assets = value end
Choose self-hosted or externally served runtime assets.
@param value [Symbol] :self_hosted or :external
@return [Symbol]
Source
# File lib/openui/rails/configuration.rb, line 80 def surface_id_param deprecated_setting(:surface_id_param) @surface_id_param end
@deprecated Has no effect: action requests always use the surface_id
key. Removed in 1.0.
Source
# File lib/openui/rails/configuration.rb, line 86 def surface_id_param=(value) deprecated_setting(:surface_id_param) @surface_id_param = value end
@deprecated Has no effect. Removed in 1.0.
Source
# File lib/openui/rails/configuration.rb, line 176 def surface_resolver=(callable) unless callable.nil? || callable.respond_to?(:call) raise ConfigurationError, "surface_resolver must respond to #call" end @surface_resolver = callable end
Set the resolver that loads a surface inside the actorβs permitted scope.
@param callable [#call, nil] receives surface_id, actor, and context
@return [#call, nil]
Source
# File lib/openui/rails/configuration.rb, line 96 def transport=(value) value = value.to_sym if value.respond_to?(:to_sym) unless TRANSPORTS.include?(value) raise ConfigurationError, "unsupported transport #{value.inspect}; expected one of #{TRANSPORTS.inspect}" end @transport = value end
Set the preferred host stream transport.
@param value [Symbol] :turbo, :action_cable, or :none
@return [Symbol]
Source
# File lib/openui/rails/configuration.rb, line 247 def validate! raise ConfigurationError, "library_spec_path is not configured" if library_spec_path.nil? if runtime_assets == :external && (runtime_url.nil? || runtime_url.empty?) raise ConfigurationError, "runtime_assets :external requires an explicit, version-pinned runtime_url" end unless pending_byte_limit.is_a?(Integer) && stream_byte_limit.is_a?(Integer) && pending_byte_limit > 0 && stream_byte_limit > 0 raise ConfigurationError, "stream byte limits must be positive" end if pending_byte_limit > stream_byte_limit raise ConfigurationError, "pending_byte_limit must not exceed stream_byte_limit" end unless idempotency_ttl.is_a?(Numeric) && idempotency_ttl.finite? && idempotency_ttl > 0 raise ConfigurationError, "idempotency_ttl must be positive" end reset! library_manifest PromptBuilder.load(self) if prompt_path true end
Explicit host readiness check. Not run during boot: the generator and runtime-fetch task must work before library files have been created.
@return [true]
@raise [ConfigurationError, ManifestError] when required settings or files are invalid