Class: Kward::PluginTabHost
- Inherits:
-
Object
- Object
- Kward::PluginTabHost
- Defined in:
- lib/kward/tabs/driver.rb
Overview
Dependencies and instance-scoped services made available to a plugin chat factory without exposing CLI or workspace-session internals.
Constant Summary collapse
- SURFACES =
%i[local rpc transport shared].freeze
Instance Attribute Summary collapse
-
#capabilities ⇒ Object
readonly
Returns the value of attribute capabilities.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#plugin_id ⇒ Object
readonly
Returns the value of attribute plugin_id.
-
#scope_key ⇒ Object
readonly
Returns the value of attribute scope_key.
-
#storage ⇒ Object
readonly
Returns the value of attribute storage.
-
#surface ⇒ Object
readonly
Returns the value of attribute surface.
-
#type_id ⇒ Object
readonly
Returns the value of attribute type_id.
-
#workspace_root ⇒ Object
readonly
Returns the value of attribute workspace_root.
Instance Method Summary collapse
-
#background(name: nil, cancellation: nil, &block) ⇒ Object
Starts cooperative background work owned by this chat instance.
-
#initialize(client:, workspace_root:, plugin_host: nil, type_id: nil, surface: :local, scope_key: "default", capabilities: nil, config: nil, storage: nil, logger: nil, env: ENV) ⇒ PluginTabHost
constructor
A new instance of PluginTabHost.
-
#on_cleanup(resource = nil, &block) ⇒ Object
(also: #manage)
Registers cleanup that runs when the chat instance closes.
-
#secret(key, env: nil) ⇒ Object
Reads a secret from private plugin config, an explicit environment variable, or the plugin's conventional KWARD_PLUGIN_* variable.
-
#shutdown(timeout: PluginResources::DEFAULT_SHUTDOWN_TIMEOUT) ⇒ Object
private
Cancels chat-owned work and invokes cleanup callbacks.
Constructor Details
#initialize(client:, workspace_root:, plugin_host: nil, type_id: nil, surface: :local, scope_key: "default", capabilities: nil, config: nil, storage: nil, logger: nil, env: ENV) ⇒ PluginTabHost
Returns a new instance of PluginTabHost.
106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/kward/tabs/driver.rb', line 106 def initialize(client:, workspace_root:, plugin_host: nil, type_id: nil, surface: :local, scope_key: "default", capabilities: nil, config: nil, storage: nil, logger: nil, env: ENV) @client = client @workspace_root = workspace_root @plugin_id = plugin_host&.id @type_id = required_value(type_id || @plugin_id || "anonymous", "plugin chat type id").freeze @surface = normalize_surface(surface) @scope_key = required_value(scope_key, "plugin chat scope key").freeze @capabilities = capabilities || PluginChatCapabilities.legacy @config = freeze_config(config || plugin_host&.config || ConfigFiles.plugin_config(storage_owner_id)) @storage = PluginScopedStore.new(storage || plugin_host&.storage || default_storage, storage_namespace) @logger = logger || plugin_host&.logger || default_logger @env = env @resources = PluginResources.new(name: "Kward plugin chat #{@type_id}", warning_sink: ConfigFiles.warning_sink).tap(&:activate!) end |
Instance Attribute Details
#capabilities ⇒ Object (readonly)
Returns the value of attribute capabilities.
103 104 105 |
# File 'lib/kward/tabs/driver.rb', line 103 def capabilities @capabilities end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
103 104 105 |
# File 'lib/kward/tabs/driver.rb', line 103 def client @client end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
103 104 105 |
# File 'lib/kward/tabs/driver.rb', line 103 def config @config end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
103 104 105 |
# File 'lib/kward/tabs/driver.rb', line 103 def logger @logger end |
#plugin_id ⇒ Object (readonly)
Returns the value of attribute plugin_id.
103 104 105 |
# File 'lib/kward/tabs/driver.rb', line 103 def plugin_id @plugin_id end |
#scope_key ⇒ Object (readonly)
Returns the value of attribute scope_key.
103 104 105 |
# File 'lib/kward/tabs/driver.rb', line 103 def scope_key @scope_key end |
#storage ⇒ Object (readonly)
Returns the value of attribute storage.
103 104 105 |
# File 'lib/kward/tabs/driver.rb', line 103 def storage @storage end |
#surface ⇒ Object (readonly)
Returns the value of attribute surface.
103 104 105 |
# File 'lib/kward/tabs/driver.rb', line 103 def surface @surface end |
#type_id ⇒ Object (readonly)
Returns the value of attribute type_id.
103 104 105 |
# File 'lib/kward/tabs/driver.rb', line 103 def type_id @type_id end |
#workspace_root ⇒ Object (readonly)
Returns the value of attribute workspace_root.
103 104 105 |
# File 'lib/kward/tabs/driver.rb', line 103 def workspace_root @workspace_root end |
Instance Method Details
#background(name: nil, cancellation: nil, &block) ⇒ Object
Starts cooperative background work owned by this chat instance.
122 123 124 |
# File 'lib/kward/tabs/driver.rb', line 122 def background(name: nil, cancellation: nil, &block) @resources.background(name: name, cancellation: cancellation, &block) end |
#on_cleanup(resource = nil, &block) ⇒ Object Also known as: manage
Registers cleanup that runs when the chat instance closes.
127 128 129 |
# File 'lib/kward/tabs/driver.rb', line 127 def on_cleanup(resource = nil, &block) @resources.on_cleanup(resource, &block) end |
#secret(key, env: nil) ⇒ Object
Reads a secret from private plugin config, an explicit environment variable, or the plugin's conventional KWARD_PLUGIN_* variable.
135 136 137 138 139 140 141 |
# File 'lib/kward/tabs/driver.rb', line 135 def secret(key, env: nil) key = required_value(key, "secret key") value = config[key] value = @env[env.to_s] if value.nil? && env value = @env[default_secret_env_name(key)] if value.nil? value.to_s unless value.nil? end |
#shutdown(timeout: PluginResources::DEFAULT_SHUTDOWN_TIMEOUT) ⇒ 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.
Cancels chat-owned work and invokes cleanup callbacks.
145 146 147 148 |
# File 'lib/kward/tabs/driver.rb', line 145 def shutdown(timeout: PluginResources::DEFAULT_SHUTDOWN_TIMEOUT) @resources.shutdown(timeout: timeout) self end |