Class: PromptObjects::Universal::DispatchPO
Overview
Enqueue independent PO work and return its durable identity immediately.
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
Instance Method Details
#description ⇒ Object
11
12
13
14
|
# File 'lib/prompt_objects/universal/dispatch_po.rb', line 11
def description
"Dispatch work to an allowed Prompt Object without waiting for its response. " \
"Returns run_id and thread_id; use get_run_status or join_runs when the result is needed later."
end
|
#name ⇒ Object
9
|
# File 'lib/prompt_objects/universal/dispatch_po.rb', line 9
def name = "dispatch_po"
|
#parameters ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/prompt_objects/universal/dispatch_po.rb', line 16
def parameters
{
type: "object",
properties: {
target_po: { type: "string", description: "Prompt Object listed in your capabilities" },
message: { type: "string", description: "Work to enqueue" },
thread_id: { type: "string", description: "Optional existing target thread" },
lifetime: {
type: "string", enum: %w[attached detached],
description: "attached cancels with the parent; detached may finish independently"
},
on_complete: {
type: "string",
description: "Optional follow-up instruction enqueued on your thread when the child finishes"
}
},
required: %w[target_po message]
}
end
|
#receive(message, context:) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/prompt_objects/universal/dispatch_po.rb', line 36
def receive(message, context:)
target = message[:target_po] || message["target_po"]
content = message[:message] || message["message"]
raise Error, "target_po is required" if target.to_s.empty?
raise Error, "message is required" if content.to_s.empty?
result = context.env.dispatch_run(
target_po: target,
content: content,
context: context,
thread_id: message[:thread_id] || message["thread_id"],
lifetime: message[:lifetime] || message["lifetime"] || "attached",
on_complete: message[:on_complete] || message["on_complete"]
)
JSON.generate(result)
end
|