Class: Protege::Toolkit

Inherits:
ApplicationRecord show all
Includes:
BroadcastableToolkit
Defined in:
app/models/protege/toolkit.rb

Overview

A toolkit — the first "Binding" of the extension framework. A global, dashboard-managed, reusable bundle of tools (referenced by their manifest ids) and nothing more: it says what tools travel together, not who may use them. Permission is a property of the attachment — see AgentToolkit — so the same toolkit given to two agents can be gated differently, with no tool-list duplication.

Member tools are a member_tool_ids JSON id list (a checklist over the tool manifest), reconciled against the live manifest at read time so a stale id (a tool since removed from the code) is skipped.

A toolkit may be a system toolkit — one the engine guarantees exists, identified by a stable key rather than its (renameable) display name (see Protege::SystemToolkits). The all_tools system kit is auto-maintained to hold every registered tool; default_tools is auto-attached to each new agent. System toolkits can't be deleted from the dashboard. User-created toolkits leave key nil.

Constant Summary collapse

ALL_TOOLS_KEY =

The stable key of the auto-maintained toolkit holding every registered tool.

'all_tools'
DEFAULT_TOOLS_KEY =

The stable key of the toolkit auto-attached to every new agent.

'default_tools'

Constants included from BroadcastableToolkit

BroadcastableToolkit::STREAM

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.all_toolsProtege::Toolkit?

The auto-maintained "All Tools" system toolkit, or nil before it has been synced.

Returns:



55
56
57
# File 'app/models/protege/toolkit.rb', line 55

def all_tools
  find_by(key: ALL_TOOLS_KEY)
end

.default_toolsProtege::Toolkit?

The "Default Tools" system toolkit auto-attached to new agents, or nil before it has been synced.

Returns:



62
63
64
# File 'app/models/protege/toolkit.rb', line 62

def default_tools
  find_by(key: DEFAULT_TOOLS_KEY)
end

Instance Method Details

#covers?(tool_id) ⇒ Boolean

Whether this toolkit includes a given tool id.

Parameters:

  • tool_id (Symbol, String)

    the tool id to test

Returns:

  • (Boolean)

    true when the id is a member



81
82
83
# File 'app/models/protege/toolkit.rb', line 81

def covers?(tool_id)
  member_tool_ids.map(&:to_sym).include?(tool_id.to_sym)
end

#member_toolsArray<Protege::Manifest::Entry>

The member tools that still exist, as manifest entries — stale ids (naming a removed tool) are dropped, so a toolkit tolerates a member whose tool has since been deleted from the code.

Returns:



89
90
91
92
# File 'app/models/protege/toolkit.rb', line 89

def member_tools
  ids = member_tool_ids.map(&:to_sym)
  Manifest.registered(:tool).select { |entry| ids.include?(entry.id) }
end

#system?Boolean

Whether this is an engine-managed system toolkit (carries a key) — such toolkits can't be deleted, and all_tools has its membership maintained by the engine rather than the operator.

Returns:

  • (Boolean)

    true when the toolkit is keyed



73
74
75
# File 'app/models/protege/toolkit.rb', line 73

def system?
  key.present?
end