Module: OpenAI::WebSocket::Resource Private

Included in:
TypedResource
Defined in:
lib/openai/helpers/websocket/resource.rb,
sig/openai/helpers/websocket.rbs

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Connects generated request and event bindings to the SDK-owned runtime. Existing API helpers retain their more specific connection methods.

Instance Method Summary collapse

Instance Method Details

#connect(*path_arguments, query: {}, websocket_base_url: nil, request_options: nil, transport: nil, transport_options: {}) {|arg0| ... } ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • path_arguments (Object)
  • query: (Hash[untyped, untyped]) (defaults to: {})
  • websocket_base_url: (String, nil) (defaults to: nil)
  • request_options: (Object) (defaults to: nil)
  • transport: (Object) (defaults to: nil)
  • transport_options: (Hash[untyped, untyped]) (defaults to: {})

Yields:

Yield Parameters:

Yield Returns:

  • (Object)

Returns:

  • (Object)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/openai/helpers/websocket/resource.rb', line 10

def connect(
  *path_arguments,
  query: {},
  websocket_base_url: nil,
  request_options: nil,
  transport: nil,
  transport_options: {},
  &block
)
  request = __websocket_request(*path_arguments, query: query.dup)
  base_url = websocket_base_url&.to_s&.dup&.freeze
  error_factory = -> (url:, **options) { BindingConnectionError.new(url: url, **options) }
  ConnectionManager
    .new(
      client: @client,
      transport: transport,
      transport_options: transport_options,
      default_transport: lambda do
        AsyncWebSocketTransport.new(
          product_name: "WebSocket",
          error_class: BindingConnectionError,
          error_factory: error_factory
        )
      end,
      connection_class: TypedConnection,
      connection_options: {client_event: __websocket_client_event, server_event: __websocket_server_event},
      request: lambda do |&request_block|
        @client.with_websocket_connection_request(
          request: request,
          websocket_base_url: base_url,
          options: request_options,
          &request_block
        )
      end,
      block_error_message: "A block is required to open a WebSocket.",
      abort_after_block: -> (_connection, error) { !error.nil? },
      transport_error_factory: -> (url:, error:) {
        status = error.http_status if error.is_a?(OpenAI::Errors::WebSocketConnectionError)
        BindingConnectionError.new(url: url, http_status: status)
      }
    )
    .open(&block)
end