Module: Insika::Commands::AgentPayload

Defined in:
lib/insika/commands/agent_payload.rb

Overview

Shared normalization for the agent-authoring payload. The transport delivers string keys (JSON); internal dispatch uses symbols. Here: symbolize the top level, keep only the fields buildable by AgentProfile, and re-symbolize the fields the runtime consumes as symbols (provider, policies, limits keys) — same rule as StoredProfileSource.

Constant Summary collapse

FIELDS =

Fields accepted by AgentProfile.build (order irrelevant).

%i[id model provider base_prompt prompt_files tools_allow tools_deny
tools_allow_groups skills context_providers workflows_allow policies
prompt_refs limits approvals_required capabilities subagents tools_deferred
memory params model_policy guardrails refinement capabilities_declared
edge_stream metadata].freeze

Class Method Summary collapse

Class Method Details

.attrs(payload) ⇒ Object

payload (string|symbol keys) -> Hash of attrs ready for AgentProfile.build.



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/insika/commands/agent_payload.rb', line 21

def attrs(payload)
  h = symbolize(payload)
  out = {}
  FIELDS.each { |f| out[f] = h[f] if h.key?(f) }
  out[:provider] = presence(out[:provider])&.to_sym if out.key?(:provider)
  out[:policies] = Array(out[:policies]).map(&:to_sym) if out.key?(:policies)
  out[:limits] = out[:limits].transform_keys(&:to_sym) if out[:limits].is_a?(Hash)
  # generation params (v2, §10) consumed by symbol key (temperature/max_tokens/thinking).
  out[:params] = out[:params].transform_keys(&:to_sym) if out[:params].is_a?(Hash)
  out
end

.presence(str) ⇒ Object

Stable name used by the handlers; the rule lives in Insika::Coercion.



38
# File 'lib/insika/commands/agent_payload.rb', line 38

def presence(str) = Insika::Coercion.presence(str)

.symbolize(payload) ⇒ Object



33
34
35
# File 'lib/insika/commands/agent_payload.rb', line 33

def symbolize(payload)
  (payload || {}).each_with_object({}) { |(k, v), acc| acc[k.to_sym] = v }
end