Class: LanguageOperator::Dsl::Context

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/language_operator/dsl/context.rb

Overview

DSL context for defining tools

Provides the evaluation context for tool definition files. Tools are defined using the tool method within this context.

Examples:

Tool definition file

tool "search" do
  description "Search the web"

  parameter :query do
    description "Search query"
    type :string
    required true
  end

  execute do |params|
    http_get("https://api.search.com?q=#{params[:query]}")
  end
end

Constant Summary collapse

HTTP =

Provide access to HTTP and Shell helper classes as constants

LanguageOperator::Dsl::HTTP
Shell =
LanguageOperator::Dsl::Shell

Instance Method Summary collapse

Methods included from Helpers

#env_get, #env_required, #error, #parse_csv, #run_command, #shell_escape, #success, #truncate, #validate_email, #validate_phone, #validate_url

Constructor Details

#initialize(registry) ⇒ Context

Initialize context with registry

Parameters:

  • Tool registry



34
35
36
# File 'lib/language_operator/dsl/context.rb', line 34

def initialize(registry)
  @registry = registry
end

Instance Method Details

#tool(name) { ... } ⇒ void

This method returns an undefined value.

Define a tool

Yields:

  • Tool definition block

Parameters:

  • Tool name



43
44
45
46
47
# File 'lib/language_operator/dsl/context.rb', line 43

def tool(name, &)
  tool_def = ToolDefinition.new(name)
  tool_def.instance_eval(&) if block_given?
  @registry.register(tool_def)
end