Class: MockServer::A2A::A2aMockBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/mockserver/a2a.rb

Instance Method Summary collapse

Constructor Details

#initialize(path = '/a2a') ⇒ A2aMockBuilder

Returns a new instance of A2aMockBuilder.



101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/mockserver/a2a.rb', line 101

def initialize(path = '/a2a')
  @path = path.is_a?(String) ? path : '/a2a'
  @agent_card_path = '/.well-known/agent.json'
  @agent_name = 'MockAgent'
  @agent_description = 'A mock A2A agent'
  @agent_version = '1.0.0'
  @agent_url = nil
  @skills = []
  @task_handlers = []
  @default_task_response = 'Task completed successfully'
  @streaming = false
  @streaming_method = 'message/stream'
  @push_notification_url = nil
end

Instance Method Details

#add_skill(skill) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



192
193
194
# File 'lib/mockserver/a2a.rb', line 192

def add_skill(skill)
  @skills << skill
end

#add_task_handler(handler) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



197
198
199
# File 'lib/mockserver/a2a.rb', line 197

def add_task_handler(handler)
  @task_handlers << handler
end

#apply_to(client) ⇒ Array<Expectation>

Returns:



222
223
224
# File 'lib/mockserver/a2a.rb', line 222

def apply_to(client)
  client.upsert(*build.map { |h| RawExpectation.new(h) })
end

#buildArray<Hash>

Returns the ordered list of expectations.

Returns:

  • (Array<Hash>)

    the ordered list of expectations



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/mockserver/a2a.rb', line 202

def build
  expectations = [build_agent_card_expectation]

  @task_handlers.each { |handler| expectations << build_custom_task_handler(handler) }

  expectations << build_streaming_expectation if @streaming

  if @push_notification_url
    expectations << build_push_notification_config_expectation
    expectations << build_push_notification_delivery_expectation
  else
    expectations << build_tasks_send_expectation
  end
  expectations << build_tasks_get_expectation
  expectations << build_tasks_cancel_expectation

  expectations
end

#on_task_sendA2aTaskHandlerBuilder



187
188
189
# File 'lib/mockserver/a2a.rb', line 187

def on_task_send
  A2aTaskHandlerBuilder.new(self)
end

#with_agent_card_path(path) ⇒ self

Returns:

  • (self)


141
142
143
144
# File 'lib/mockserver/a2a.rb', line 141

def with_agent_card_path(path)
  @agent_card_path = path
  self
end

#with_agent_description(description) ⇒ self

Returns:

  • (self)


123
124
125
126
# File 'lib/mockserver/a2a.rb', line 123

def with_agent_description(description)
  @agent_description = description
  self
end

#with_agent_name(name) ⇒ self

Returns:

  • (self)


117
118
119
120
# File 'lib/mockserver/a2a.rb', line 117

def with_agent_name(name)
  @agent_name = name
  self
end

#with_agent_url(url) ⇒ self

Returns:

  • (self)


135
136
137
138
# File 'lib/mockserver/a2a.rb', line 135

def with_agent_url(url)
  @agent_url = url
  self
end

#with_agent_version(version) ⇒ self

Returns:

  • (self)


129
130
131
132
# File 'lib/mockserver/a2a.rb', line 129

def with_agent_version(version)
  @agent_version = version
  self
end

#with_default_task_response(response) ⇒ self

Returns:

  • (self)


147
148
149
150
# File 'lib/mockserver/a2a.rb', line 147

def with_default_task_response(response)
  @default_task_response = response
  self
end

#with_push_notifications(webhook_url) ⇒ self

Advertise + mock A2A push notifications. The agent card reports capabilities.pushNotifications: true, tasks/pushNotificationConfig/set echoes the registered config, and each tasks/send additionally POSTs the completed task to webhook_url while still returning the JSON-RPC task response to the caller.

Returns:

  • (self)


176
177
178
179
# File 'lib/mockserver/a2a.rb', line 176

def with_push_notifications(webhook_url)
  @push_notification_url = webhook_url
  self
end

#with_skill(id) ⇒ A2aSkillBuilder

Returns:



182
183
184
# File 'lib/mockserver/a2a.rb', line 182

def with_skill(id)
  A2aSkillBuilder.new(self, id)
end

#with_streamingself

Advertise + mock the A2A streaming capability. The agent card reports capabilities.streaming: true and the streaming JSON-RPC method (default message/stream) returns an SSE stream of status/artifact update events.

Returns:

  • (self)


156
157
158
159
# File 'lib/mockserver/a2a.rb', line 156

def with_streaming
  @streaming = true
  self
end

#with_streaming_method(method) ⇒ self

Override the JSON-RPC method that triggers the streaming response. Implies #with_streaming.

Returns:

  • (self)


164
165
166
167
168
# File 'lib/mockserver/a2a.rb', line 164

def with_streaming_method(method)
  @streaming_method = method
  @streaming = true
  self
end