Class: PromptObjects::Universal::SetEnvData
- Inherits:
-
Primitive
- Object
- Capability
- Primitive
- PromptObjects::Universal::SetEnvData
- Defined in:
- lib/prompt_objects/universal/set_env_data.rb
Overview
Universal capability to create or update shared data scoped to the current delegation chain. Any PO in the same delegation tree can read this data via get_env_data or list_env_data. Replaces the previous store_env_data and update_env_data (which were redundant).
Instance Attribute Summary
Attributes inherited from Capability
Instance Method Summary collapse
Methods inherited from Primitive
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
#description ⇒ Object
22 23 24 25 26 |
# File 'lib/prompt_objects/universal/set_env_data.rb', line 22 def description "Create or update a key-value pair in the shared environment data. " \ "All POs in the same delegation tree can access this data. " \ "If the key already exists, it will be overwritten." end |
#name ⇒ Object
18 19 20 |
# File 'lib/prompt_objects/universal/set_env_data.rb', line 18 def name "set_env_data" end |
#parameters ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/prompt_objects/universal/set_env_data.rb', line 28 def parameters { type: "object", properties: { key: { type: "string", description: "Namespaced identifier for the data (e.g. 'arc_task', 'findings')" }, short_description: { type: "string", description: "1-2 sentence summary of what this data contains (for discoverability via list_env_data)" }, value: { description: "The data to store (any JSON-serializable value: string, number, object, array)" } }, required: %w[key short_description value] } end |
#receive(message, context:) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/prompt_objects/universal/set_env_data.rb', line 48 def receive(, context:) key = [:key] || ["key"] short_description = [:short_description] || ["short_description"] # Key-presence check, not `||`, so a literal `false` value isn't dropped. value = .key?(:value) ? [:value] : ["value"] return "Error: 'key' is required" unless key return "Error: 'short_description' is required" unless short_description return "Error: 'value' is required" if value.nil? 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 stored_by = context.calling_po || "unknown" if context.env.respond_to?(:set_environment_data) context.env.set_environment_data( key: key, short_description: short_description, value: value, context: context ) context.bus.publish( from: stored_by, to: "env_data", message: { action: "set", key: key, short_description: short_description } ) return "Stored '#{key}' in environment data." end store.store_env_data( root_thread_id: root_thread_id, key: key, short_description: short_description, value: value, stored_by: stored_by ) context.bus.publish( from: stored_by, to: "env_data", message: { action: "set", key: key, short_description: short_description } ) context.env.notify_env_data_changed(action: "set", root_thread_id: root_thread_id, key: key, stored_by: stored_by) "Stored '#{key}' in environment data." end |