Class: PromptObjects::Connectors::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/prompt_objects/connectors/base.rb

Overview

Base class for connectors that provide different interfaces to environments. Each connector (MCP, API, Web, etc.) inherits from this class.

Direct Known Subclasses

MCP

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(runtime:, config: {}) ⇒ Base

Returns a new instance of Base.

Parameters:

  • runtime (Runtime)

    The environment runtime

  • config (Hash) (defaults to: {})

    Connector-specific configuration



12
13
14
15
16
# File 'lib/prompt_objects/connectors/base.rb', line 12

def initialize(runtime:, config: {})
  @runtime = runtime
  @config = config
  @running = false
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



8
9
10
# File 'lib/prompt_objects/connectors/base.rb', line 8

def config
  @config
end

#runtimeObject (readonly)

Returns the value of attribute runtime.



8
9
10
# File 'lib/prompt_objects/connectors/base.rb', line 8

def runtime
  @runtime
end

Instance Method Details

#inject(target_po:, content:, workspace_session_id: nil, thread_id: nil, client_request_id: nil) ⇒ String

Route an inbound external event to a PO through the unified entry point. The message is tagged with this connector's source, so its provenance shows up in the timeline (e.g. "← discord"). This is how a Discord/Slack/ webhook connector forwards an incoming message to a Prompt-Object.

Parameters:

  • target_po (String)

    PO to deliver to

  • content (String)

    Message content

Returns:

  • (String)

    The PO's response



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/prompt_objects/connectors/base.rb', line 46

def inject(target_po:, content:, workspace_session_id: nil,
           thread_id: nil, client_request_id: nil)
  runtime.inject_message(
    target_po: target_po,
    content: content,
    from_source: "service:#{source_name}",
    workspace_session_id: workspace_session_id,
    thread_id: thread_id,
    client_request_id: client_request_id
  )
end

#running?Boolean

Whether the connector is currently running

Returns:

  • (Boolean)


29
30
31
# File 'lib/prompt_objects/connectors/base.rb', line 29

def running?
  @running
end

#source_nameString

Connector identifier for session source tracking

Returns:

  • (String)

    e.g., "mcp", "api", "web"

Raises:

  • (NotImplementedError)


35
36
37
# File 'lib/prompt_objects/connectors/base.rb', line 35

def source_name
  raise NotImplementedError, "#{self.class} must implement #source_name"
end

#startObject

Start the connector (may be blocking or non-blocking depending on implementation)

Raises:

  • (NotImplementedError)


19
20
21
# File 'lib/prompt_objects/connectors/base.rb', line 19

def start
  raise NotImplementedError, "#{self.class} must implement #start"
end

#stopObject

Stop the connector gracefully



24
25
26
# File 'lib/prompt_objects/connectors/base.rb', line 24

def stop
  @running = false
end