Class: PromptObjects::Universal::GetEnvData

Inherits:
Primitive show all
Defined in:
lib/prompt_objects/universal/get_env_data.rb

Overview

Universal capability to retrieve shared data by key from the current delegation chain.

Instance Attribute Summary

Attributes inherited from Capability

#state

Instance Method Summary collapse

Methods inherited from Primitive

#initialize

Methods inherited from Capability

#descriptor, execution_policy, execution_policy_definition, #execution_policy_definition, #execution_policy_signature, #initialize, #resolved_execution_policy

Constructor Details

This class inherits a constructor from PromptObjects::Primitive

Instance Method Details

#descriptionObject



13
14
15
16
# File 'lib/prompt_objects/universal/get_env_data.rb', line 13

def description
  "Retrieve a specific key's full value from the shared environment data. " \
  "Use list_env_data first to see what keys are available."
end

#nameObject



9
10
11
# File 'lib/prompt_objects/universal/get_env_data.rb', line 9

def name
  "get_env_data"
end

#parametersObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/prompt_objects/universal/get_env_data.rb', line 18

def parameters
  {
    type: "object",
    properties: {
      key: {
        type: "string",
        description: "The key to retrieve"
      }
    },
    required: ["key"]
  }
end

#receive(message, context:) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/prompt_objects/universal/get_env_data.rb', line 31

def receive(message, context:)
  key = message[:key] || message["key"]
  return "Error: 'key' is required" unless key

  root_thread_id = context.env_data_scope
  return "Error: Could not resolve thread scope (no active session)" unless root_thread_id

  store = context.env.session_store
  return "Error: Session store not available" unless store

  entry = if context.env.respond_to?(:get_environment_data)
            context.env.get_environment_data(key: key, context: context)
          else
            store.get_env_data(root_thread_id: root_thread_id, key: key)
          end
  return "Key '#{key}' not found in environment data." unless entry

  context.bus.publish(
    from: context.calling_po || "unknown",
    to: "env_data",
    message: { action: "get", key: key }
  )

  JSON.generate(entry[:value])
end