Skip to content
Kward Search API index

Class: Kward::PluginRegistry::DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/kward/plugin_registry.rb

Overview

Public DSL object yielded by Kward.plugin blocks.

Plugin files normally interact with this object only through a block:

Examples:

Register a plugin command

Kward.plugin do |plugin|
  plugin.command "hello", description: "Say hello" do |args, ctx|
    name = args.strip.empty? ? "there" : args.strip
    ctx.say "Hello, #{name}."
  end
end

Instance Method Summary collapse

Constructor Details

#initialize(registry, path) ⇒ DSL

Creates an object for trusted plugin loading and dispatch.



113
114
115
116
# File 'lib/kward/plugin_registry.rb', line 113

def initialize(registry, path)
  @registry = registry
  @path = path
end

Instance Method Details

#command(name, description: "", argument_hint: "") {|args, ctx| ... } ⇒ void

This method returns an undefined value.

Registers a slash command.

The command is available in the interactive CLI and through the RPC command bridge. Command names do not include the leading /.

Parameters:

  • name (String, #to_s)

    command name without the leading slash

  • description (String) (defaults to: "")

    short text shown in command listings

  • argument_hint (String) (defaults to: "")

    optional usage hint for arguments

Yield Parameters:

  • args (String)

    text after the command name

  • ctx (Context)

    plugin execution context



130
131
132
# File 'lib/kward/plugin_registry.rb', line 130

def command(name, description: "", argument_hint: "", &block)
  @registry.register_command(name, description: description, argument_hint: argument_hint, path: @path, &block)
end

This method returns an undefined value.

Registers or replaces the custom footer renderer.

Only one footer renderer is active. If multiple plugins register one, the later renderer replaces the earlier renderer.

Yield Parameters:

  • ctx (Context)

    plugin execution context



142
143
144
# File 'lib/kward/plugin_registry.rb', line 142

def footer(&block)
  @registry.register_footer(path: @path, &block)
end

#on_transcript_event {|event, ctx| ... } ⇒ void

This method returns an undefined value.

Registers a live transcript event observer.

Observer errors are caught and reported as warnings so a plugin cannot crash the active turn by raising from an event handler.

Yield Parameters:



155
156
157
# File 'lib/kward/plugin_registry.rb', line 155

def on_transcript_event(&block)
  @registry.register_transcript_event(path: @path, &block)
end

#prompt_context {|ctx| ... } ⇒ void

This method returns an undefined value.

Registers prompt context text injected into future system prompts.

Keep this text short and never include secrets. The returned string can be sent to the active model as part of Kward's system instructions.

Yield Parameters:

  • ctx (Context)

    plugin execution context



167
168
169
# File 'lib/kward/plugin_registry.rb', line 167

def prompt_context(&block)
  @registry.register_prompt_context(path: @path, &block)
end