Top Level Namespace
Defined Under Namespace
Modules: A2ATestFramework, SSEClient
Constant Summary
collapse
- BASE_URL =
ENV.fetch("A2A_BASE_URL", "http://localhost:9292")
Instance Method Summary
collapse
-
#build_cancel_task_request(id:, metadata: nil) ⇒ Object
-
#build_delete_push_notification_config_request(id:, task_id:) ⇒ Object
-
#build_get_push_notification_config_request(id:, task_id:) ⇒ Object
-
#build_get_task_request(id:, history_length: nil) ⇒ Object
-
#build_list_push_notification_configs_request(task_id:, page_size: nil, page_token: nil) ⇒ Object
-
#build_list_tasks_request(context_id: nil, status: nil, page_size: nil, page_token: nil, history_length: nil, include_artifacts: nil) ⇒ Object
-
#build_push_notification_config(task_id:, url: "https://example.com/webhook", token: nil, authentication: nil) ⇒ Object
-
#build_send_message_request(text: "Hello, agent", task_id: nil, context_id: nil, configuration: nil, metadata: nil) ⇒ Object
— Request Builders (using A2A Schema objects) —————————-.
-
#build_subscribe_to_task_request(id:) ⇒ Object
-
#create_task!(text: "Hello, agent") ⇒ Object
Sends a message and returns the task hash from the response.
-
#get_task!(id) ⇒ Object
-
#http_delete(path, headers: {}) ⇒ Object
-
#http_get(path, headers: {}) ⇒ Object
-
#http_post(path, body, headers: {}) ⇒ Object
— HTTP Helpers ———————————————————–.
-
#parse_json(response) ⇒ Object
Instance Method Details
#build_cancel_task_request(id:, metadata: nil) ⇒ Object
87
88
89
90
91
92
|
# File 'lib/a2a_test_framework/test_helper.rb', line 87
def build_cancel_task_request(id:, metadata: nil)
A2A::Schema["Cancel Task Request"].new(
id: id,
metadata: metadata
).to_h
end
|
#build_delete_push_notification_config_request(id:, task_id:) ⇒ Object
122
123
124
125
126
127
|
# File 'lib/a2a_test_framework/test_helper.rb', line 122
def build_delete_push_notification_config_request(id:, task_id:)
A2A::Schema["Delete Task Push Notification Config Request"].new(
id: id,
task_id: task_id
).to_h
end
|
#build_get_push_notification_config_request(id:, task_id:) ⇒ Object
107
108
109
110
111
112
|
# File 'lib/a2a_test_framework/test_helper.rb', line 107
def build_get_push_notification_config_request(id:, task_id:)
A2A::Schema["Get Task Push Notification Config Request"].new(
id: id,
task_id: task_id
).to_h
end
|
#build_get_task_request(id:, history_length: nil) ⇒ Object
69
70
71
72
73
74
|
# File 'lib/a2a_test_framework/test_helper.rb', line 69
def build_get_task_request(id:, history_length: nil)
A2A::Schema["Get Task Request"].new(
id: id,
history_length: history_length
).to_h
end
|
#build_list_push_notification_configs_request(task_id:, page_size: nil, page_token: nil) ⇒ Object
114
115
116
117
118
119
120
|
# File 'lib/a2a_test_framework/test_helper.rb', line 114
def build_list_push_notification_configs_request(task_id:, page_size: nil, page_token: nil)
A2A::Schema["List Task Push Notification Configs Request"].new(
task_id: task_id,
page_size: page_size,
page_token: page_token
).to_h
end
|
#build_list_tasks_request(context_id: nil, status: nil, page_size: nil, page_token: nil, history_length: nil, include_artifacts: nil) ⇒ Object
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/a2a_test_framework/test_helper.rb', line 76
def build_list_tasks_request(context_id: nil, status: nil, page_size: nil, page_token: nil, history_length: nil, include_artifacts: nil)
A2A::Schema["List Tasks Request"].new(
context_id: context_id,
status: status,
page_size: page_size,
page_token: page_token,
history_length: history_length,
include_artifacts: include_artifacts
).to_h
end
|
#build_push_notification_config(task_id:, url: "https://example.com/webhook", token: nil, authentication: nil) ⇒ Object
98
99
100
101
102
103
104
105
|
# File 'lib/a2a_test_framework/test_helper.rb', line 98
def build_push_notification_config(task_id:, url: "https://example.com/webhook", token: nil, authentication: nil)
A2A::Schema["Task Push Notification Config"].new(
task_id: task_id,
url: url,
token: token,
authentication: authentication
).to_h
end
|
#build_send_message_request(text: "Hello, agent", task_id: nil, context_id: nil, configuration: nil, metadata: nil) ⇒ Object
— Request Builders (using A2A Schema objects) —————————-
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/a2a_test_framework/test_helper.rb', line 53
def build_send_message_request(text: "Hello, agent", task_id: nil, context_id: nil, configuration: nil, metadata: nil)
message = {
"messageId" => SecureRandom.uuid,
"role" => "ROLE_USER",
"parts" => [{ "text" => text }]
}
message["taskId"] = task_id if task_id
message["contextId"] = context_id if context_id
A2A::Schema["Send Message Request"].new(
message: message,
configuration: configuration,
metadata: metadata
).to_h
end
|
#build_subscribe_to_task_request(id:) ⇒ Object
94
95
96
|
# File 'lib/a2a_test_framework/test_helper.rb', line 94
def build_subscribe_to_task_request(id:)
A2A::Schema["Subscribe To Task Request"].new(id: id).to_h
end
|
#create_task!(text: "Hello, agent") ⇒ Object
Sends a message and returns the task hash from the response.
132
133
134
135
136
137
138
139
|
# File 'lib/a2a_test_framework/test_helper.rb', line 132
def create_task!(text: "Hello, agent")
body = build_send_message_request(text: text)
response = http_post("/message:send", body)
raise "Failed to create task: HTTP #{response.code}" unless response.code.to_i == 200
data = parse_json(response)
raise "No task in response" unless data["task"]
data["task"]
end
|
#get_task!(id) ⇒ Object
142
143
144
145
146
|
# File 'lib/a2a_test_framework/test_helper.rb', line 142
def get_task!(id)
response = http_get("/tasks/#{id}")
raise "Failed to get task: HTTP #{response.code}" unless response.code.to_i == 200
parse_json(response)
end
|
#http_delete(path, headers: {}) ⇒ Object
37
38
39
40
41
42
43
44
45
|
# File 'lib/a2a_test_framework/test_helper.rb', line 37
def http_delete(path, headers: {})
uri = URI("#{BASE_URL}#{path}")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == "https"
http.read_timeout = 30
request = Net::HTTP::Delete.new(uri.path)
.each { |k, v| request[k] = v }
http.request(request)
end
|
#http_get(path, headers: {}) ⇒ Object
27
28
29
30
31
32
33
34
35
|
# File 'lib/a2a_test_framework/test_helper.rb', line 27
def http_get(path, headers: {})
uri = URI("#{BASE_URL}#{path}")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == "https"
http.read_timeout = 30
request = Net::HTTP::Get.new(uri.request_uri)
.each { |k, v| request[k] = v }
http.request(request)
end
|
#http_post(path, body, headers: {}) ⇒ Object
— HTTP Helpers ———————————————————–
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/a2a_test_framework/test_helper.rb', line 15
def http_post(path, body, headers: {})
uri = URI("#{BASE_URL}#{path}")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == "https"
http.read_timeout = 30
request = Net::HTTP::Post.new(uri.path)
request["Content-Type"] = "application/json"
.each { |k, v| request[k] = v }
request.body = JSON.generate(body)
http.request(request)
end
|
#parse_json(response) ⇒ Object
47
48
49
|
# File 'lib/a2a_test_framework/test_helper.rb', line 47
def parse_json(response)
JSON.parse(response.body)
end
|