a2a-rails 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -1
- data/README.md +145 -86
- data/lib/a2a/rails/client.rb +2 -1
- data/lib/a2a/rails/dispatcher.rb +10 -0
- data/lib/a2a/rails/errors.rb +1 -0
- data/lib/a2a/rails/protocol/agent2agent_adapter.rb +12 -2
- data/lib/a2a/rails/protocol/part_data.rb +89 -0
- data/lib/a2a/rails/protocol/request_handler.rb +63 -14
- data/lib/a2a/rails/protocol/task_mapper.rb +1 -1
- data/lib/a2a/rails/skill.rb +2 -0
- data/lib/a2a/rails/task/active_record_store.rb +29 -2
- data/lib/a2a/rails/task/lifecycle.rb +1 -0
- data/lib/a2a/rails/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7810ba3ee58350b09b8239ff5b4ffec63ec1a21fbe6ece6b670af6678ad4ce55
|
|
4
|
+
data.tar.gz: 553c7f4e6290a20f0ccb0698f0568d057ff6d29a43d8706ed982de3223382bda
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 100976286a6676996729e2834f4ee5f27cc939cb2b9c6a6d2ee3120cc0d4bfc8669cf72c24e3e131b8f034f5902c0e26892968085413117343727c507c24f595
|
|
7
|
+
data.tar.gz: 32199a0dc4cd86318b3c98a819876e3e74efabfa330cc2fb5184482575d80a5370eac6f8ca3dfd4403249cf186a71f5b6ba980a222fdd67420857c6debe06fd9
|
data/CHANGELOG.md
CHANGED
|
@@ -4,7 +4,24 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
-
## [0.
|
|
7
|
+
## [0.4.0] — release preparation (not yet published)
|
|
8
|
+
|
|
9
|
+
> Packaging and verification only. See the [0.4.0 release checklist](docs/release/v0.4.0-preparation.md).
|
|
10
|
+
|
|
11
|
+
- Add opt-in inbound JSON object Data Parts on Skills declaring
|
|
12
|
+
`application/json`; the input contract is enforced after Routing and before
|
|
13
|
+
Handler execution or Task admission.
|
|
14
|
+
- Preserve nested JSON nulls and exact application keys through SDK
|
|
15
|
+
serialization, Task history and results. No database migration or SDK
|
|
16
|
+
dependency change. Existing text, Task and direct Message flows remain.
|
|
17
|
+
- Keep Hash and Array Data output; the Rails Client now reads both. Object-only
|
|
18
|
+
is a Rails Server **input** restriction, not an output restriction.
|
|
19
|
+
- See the [structured Data guide](docs/guides/structured-data.md) for the
|
|
20
|
+
normalized MIME type, accepted values and rollout instructions.
|
|
21
|
+
|
|
22
|
+
## [0.3.0] - 2026-10-10 (published stable release)
|
|
23
|
+
|
|
24
|
+
> **Published after explicit maintainer GO.** [GitHub Release v0.3.0](https://github.com/cuichangquan/a2a-rails/releases/tag/v0.3.0) · [RubyGems a2a-rails 0.3.0](https://rubygems.org/gems/a2a-rails/versions/0.3.0). Immutable annotated tag targets commit `772f63fc814123f39b40bafd7403f3ef9a59788e`; the Gem SHA256 is `90a7d8d32bdd19ebc97046a3307c483cc0798b06afcd79df4931cfc5a4ead40f`. Exact final-main CI **49/49 jobs passed**. Gem uploaded without rebuilding; original RubyGems package was fetched and matched. [Step 31-6 publication record](docs/release/v0.3.0-publication-record.md).
|
|
8
25
|
|
|
9
26
|
`0.3.0` advances the outbound A2A Client tested in `0.3.0.rc1` while retaining the existing Rails A2A Server default. [Release verification record](docs/release/v0.3.0-stable-candidate-record.md) and [Step 31 tracking issue](https://github.com/cuichangquan/a2a-rails/issues/120) contain the dated CI/provenance history. Consult [GitHub Releases](https://github.com/cuichangquan/a2a-rails/releases) or [RubyGems versions](https://rubygems.org/gems/a2a-rails/versions) for actual publication status; source versions and CI artifacts alone are not public releases.
|
|
10
27
|
|
data/README.md
CHANGED
|
@@ -1,81 +1,24 @@
|
|
|
1
1
|
# a2a-rails
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
<img src="docs/assets/a2a-rails-infographics.png">
|
|
5
|
-
<br/>
|
|
6
|
-
<br/>
|
|
7
|
-
<img src="docs/assets/a2a-rails-infographics-en.png">
|
|
8
|
-
|
|
9
|
-
Rails-native integration for exposing Rails applications as A2A v1.0 agents.
|
|
10
|
-
|
|
11
|
-
> **v0.3.0.rc1 prerelease history (2026-10-10):** `0.3.0.rc1` is published on [RubyGems](https://rubygems.org/gems/a2a-rails/versions/0.3.0.rc1) and as a [GitHub Pre-release](https://github.com/cuichangquan/a2a-rails/releases/tag/v0.3.0-rc1). It adds the outbound Rails Client and Client-only mode. Install with `gem install a2a-rails -v 0.3.0.rc1`, or pin `gem "a2a-rails", "0.3.0.rc1"` in your Gemfile. Stable `0.2.0` remains available. RC1 is not stable `0.3.0`, an independent audit, or public-production approval; see the [publication record](docs/release/v0.3.0-rc1-publication-record.md) and [Client guide](docs/guides/outbound-a2a-client.md).
|
|
12
|
-
|
|
13
|
-
> **Release status (2026-10-08):** **`0.2.0` is published as a stable release** on [RubyGems](https://rubygems.org/gems/a2a-rails/versions/0.2.0) and [GitHub](https://github.com/cuichangquan/a2a-rails/releases/tag/v0.2.0). It includes the Rails/Zeitwerk and migration-generator fixes after rc2. The public Gem matches the verified artifact byte-for-byte; see the [publication record](docs/release/v0.2.0-publication-record.md).
|
|
14
|
-
|
|
15
|
-
- RubyGems: https://rubygems.org/gems/a2a-rails
|
|
16
|
-
- Published version list: https://rubygems.org/gems/a2a-rails/versions
|
|
17
|
-
- Earlier stable release `0.2.0`: https://github.com/cuichangquan/a2a-rails/releases/tag/v0.2.0
|
|
18
|
-
- Previous stable release: https://github.com/cuichangquan/a2a-rails/releases/tag/v0.1.0
|
|
19
|
-
- Changelog: [CHANGELOG.md](CHANGELOG.md)
|
|
20
|
-
- Release record: [v0.2.0 publication record](docs/release/v0.2.0-publication-record.md)
|
|
21
|
-
- **Security policy / 脆弱性報告:** [SECURITY.md](SECURITY.md) — confidential vulnerability reporting, current assurance boundaries and production responsibilities.
|
|
22
|
-
- **v0.3.x prerelease policy:** [Risk-based release gates](docs/release/step-29-5u-risk-based-oss-release-policy.md) — independently commissioned external audit is **recommended but optional**, not a known vulnerability or RubyGems requirement. Technical security checks, no known unresolved Critical/High findings, exact Gem provenance and explicit maintainer release approval remain mandatory; [optional community review #113](https://github.com/cuichangquan/a2a-rails/issues/113). **Check the published-version list for the current stable version; package publication and public-production deployment are separate decisions.**
|
|
23
|
-
- **Release evidence & upgrading:** [Step 31 release-readiness record](docs/release/v0.3.0-stable-readiness.md) · [RC1 feedback snapshot](docs/release/v0.3.0-rc1-feedback-and-upgrade-readiness.md) · [v0.2.0 → v0.3.0 upgrade guide](docs/release/upgrading-v0.2.0-to-v0.3.md) · [v0.1.0 → v0.2.0 guide](docs/release/upgrading-v0.1.0-to-v0.2.md). Check [RubyGems](https://rubygems.org/gems/a2a-rails/versions) for availability. Gem distribution does **not** authorize public Agent exposure.
|
|
24
|
-
- **Roadmap / 次にやること:** [ROADMAP.md](ROADMAP.md) · [Step 31 / Issue #120](https://github.com/cuichangquan/a2a-rails/issues/120) for the `0.3.0` release-evaluation and publication decisions. [Issue #11](https://github.com/cuichangquan/a2a-rails/issues/11) still governs public-production deployment; the [historical `0.2.0` release record](docs/release/v0.2.0-stable-readiness.md) is separate.
|
|
25
|
-
- **Official A2A TCK results:** [Pinned JSON-RPC MUST report and reproduction](docs/testing/official-a2a-tck.md) — after Step 17-4: **63 passed / 1 failed / 171 skipped / 30 deselected** (pytest). The remaining `CORE-SEND-003` mismatch is tracked [upstream in #202](https://github.com/a2aproject/a2a-tck/issues/202). The TCK workflow is informational, **not** an A2A conformance certificate.
|
|
26
|
-
|
|
27
|
-
- [A2Aの全体像(日本語・A4 1枚PDF)](docs/guides/a2a-protocol-overview-ja.pdf) — 登場人物・依頼の流れ・主要用語・MCPとの違いをまとめた学習資料。
|
|
28
|
-
- [A2A at a glance (English, A4 one-page PDF)](docs/guides/a2a-protocol-overview-en.pdf) — Roles, workflow, key terms, and how MCP fits.
|
|
29
|
-
|
|
30
|
-
## Runnable Rails Demo / 実際に動くサンプル ⭐
|
|
31
|
-
|
|
32
|
-
**[a2a-rails-demo — independent Rails 8 Echo Agent](https://github.com/cuichangquan/a2a-rails-demo)**
|
|
33
|
-
|
|
34
|
-
Run a complete standalone Rails Agent using the **published RubyGems `a2a-rails = 0.2.0`** (not a Git source checkout). The separate Demo covers Agent Card discovery, JSON-RPC v1.0 SendMessage **Task and direct Message**, GetTask, ListTasks and error handling.
|
|
35
|
-
|
|
36
|
-
- [Demo Quick Start, code and example curl requests](https://github.com/cuichangquan/a2a-rails-demo#quick-start).
|
|
37
|
-
- [Demo GitHub Actions smoke](https://github.com/cuichangquan/a2a-rails-demo/actions/workflows/smoke.yml) — independent Rails 8.1.0 / Ruby 3.4.10 HTTP smoke **16/16 checks passed** against published Gem `0.2.0` ([Step 28 Demo PR #2, merged](https://github.com/cuichangquan/a2a-rails-demo/pull/2), [passing PR CI](https://github.com/cuichangquan/a2a-rails-demo/actions/runs/37736426834)). The CI also confirms `A2A::Rails::VERSION == "0.2.0"`, RubyGems as the dependency source, and the demo's production-startup refusal.
|
|
38
|
-
- **Local-only development/test** demo: no trusted verifier or durable Task store, **not** an internet-facing production template. See [production security](docs/guides/production-security.md).
|
|
39
|
-
|
|
40
|
-
### Outbound Client-only Rails Demo / 外部A2A Agentを呼び出すサンプル
|
|
41
|
-
|
|
42
|
-
**[a2a-rails-client-demo — standalone Rails 8 Client](https://github.com/cuichangquan/a2a-rails-client-demo)**
|
|
43
|
-
|
|
44
|
-
Independent Rails application using **published RubyGems `a2a-rails = 0.3.0.rc1`** with `server_enabled = false`. Demonstrates Agent Card discovery, SendMessage **Task or direct Message**, GetTask and ListTasks with exact HTTPS origin allowlisting. [Client-only CI PASS](https://github.com/cuichangquan/a2a-rails-client-demo/actions/runs/38048228531) and [independent Rails-to-Rails pinned-TLS CI PASS](https://github.com/cuichangquan/a2a-rails-client-demo/actions/runs/38048228488): the published RC1 Client calls an independently installed **published 0.2.0 Server** over real TLS using a **loopback-only test bridge and test-only pinned policy override**, including actual Echo business logic. This is **not** a public-DNS/public-CA, no-injection or production deployment test. The existing Server demo and shipped security policy remain unchanged; see [Step 30 #117](https://github.com/cuichangquan/a2a-rails/issues/117).
|
|
45
|
-
|
|
3
|
+
Rails-native A2A v1.0 integration: expose Rails business logic as an Agent, call remote Agents, or do both. Application handlers use Ruby Hashes rather than SDK request objects.
|
|
46
4
|
|
|
47
|
-
|
|
5
|
+
> **Latest stable release (2026-10-10): [a2a-rails v0.3.0](https://github.com/cuichangquan/a2a-rails/releases/tag/v0.3.0) is now published on [RubyGems](https://rubygems.org/gems/a2a-rails/versions/0.3.0).** It adds the outbound Rails A2A Client and optional Client-only mode while preserving the existing Server default. [Official publication & SHA256 record](docs/release/v0.3.0-publication-record.md). **Gem publication is not approval to run an anonymous/public production Agent; deployment #11 remains separate.**
|
|
48
6
|
|
|
49
|
-
|
|
7
|
+
## Choose your starting point
|
|
50
8
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
a2a-rails
|
|
57
|
-
↓
|
|
58
|
-
Rails Application
|
|
59
|
-
↓
|
|
60
|
-
Business Logic
|
|
61
|
-
```
|
|
9
|
+
| Goal | Setup | Next step |
|
|
10
|
+
| --- | --- | --- |
|
|
11
|
+
| Expose a Rails Agent | Server enabled by default | [Server Quick Start](#server-quick-start-local-development) |
|
|
12
|
+
| Call an external Agent only | Set `server_enabled = false`; no Agent scaffold | [Client-only Quick Start](#client-only-quick-start) |
|
|
13
|
+
| Serve and call Agents | Keep Server enabled and construct a Client | Server setup plus [Client guide](docs/guides/outbound-a2a-client.md) |
|
|
62
14
|
|
|
63
|
-
The
|
|
15
|
+
The current stable line includes the outbound Client (0.3.0), optional ActiveRecord Task storage and ActiveJob execution (since 0.2.0). Execution is synchronous and Task storage is process-local by default. Streaming, push notifications and gRPC are unsupported.
|
|
64
16
|
|
|
65
|
-
|
|
66
|
-
- A2A Agent Card generation;
|
|
67
|
-
- automatically mounted A2A HTTP endpoints;
|
|
68
|
-
- synchronous Task execution by default, plus opt-in ActiveJob-backed async Task execution in published `0.2.0`;
|
|
69
|
-
- SDK-independent Handler inputs;
|
|
70
|
-
- a process-local MemoryStore by default, plus an optional durable ActiveRecordStore in `0.2.0`;
|
|
71
|
-
- Rails generators for initial setup;
|
|
72
|
-
- an internal Protocol Adapter boundary around the upstream SDK;
|
|
73
|
-
- **in 0.3.x**, a Rails outbound `A2A::Rails::Client` with strict HTTPS Agent Card discovery, A2A v1.0 JSON-RPC communication and optional Client-only mode.
|
|
17
|
+
## Host and security responsibilities
|
|
74
18
|
|
|
75
|
-
|
|
19
|
+
The Server Quick Start is for local development/test. Outside those environments, the Server fails closed without a host authenticator. The host must supply credential verification, business authorization, TLS/proxy restrictions, rate limits and execution budgets. Multi-worker Task access needs a shared durable Task store; async production execution also needs a durable queue. See [authentication](docs/guides/authentication.md), [production security](docs/guides/production-security.md) and [SECURITY.md](SECURITY.md).
|
|
76
20
|
|
|
77
|
-
|
|
78
|
-
> **Versioned security note:** The original **v0.1.0** did not implement per-caller Task authorization. **0.2.0 and the subsequent 0.3.x line** include a host-owned authentication hook, principal-scoped Task operations and fail-closed non-development/test behavior. **Neither version supplies your identity provider or business authorization, and publication does not approve an anonymously exposed production endpoint.** See [SECURITY.md](SECURITY.md), [authentication guide](docs/guides/authentication.md) and [deployment #11](https://github.com/cuichangquan/a2a-rails/issues/11).
|
|
21
|
+
The outbound Client requires explicitly approved HTTPS origins and public IPv4 destinations. The host supplies origin-scoped credentials, safe logging and reconciliation after ambiguous timeouts. Never weaken SSRF/TLS policy to connect this Client to the localhost Server example. See [Client security and limitations](docs/guides/outbound-a2a-client.md).
|
|
79
22
|
|
|
80
23
|
## Requirements
|
|
81
24
|
|
|
@@ -91,24 +34,53 @@ The original v0.1.0 baseline was verified against:
|
|
|
91
34
|
|
|
92
35
|
## Installation
|
|
93
36
|
|
|
94
|
-
|
|
37
|
+
In an existing Rails application, pin the published stable Gem:
|
|
95
38
|
|
|
96
39
|
```bash
|
|
97
|
-
bundle add a2a-rails
|
|
40
|
+
bundle add a2a-rails --version '= 0.3.0'
|
|
98
41
|
```
|
|
99
42
|
|
|
100
|
-
|
|
43
|
+
If you need a fresh app first (with a supported Rails installed):
|
|
101
44
|
|
|
102
45
|
```bash
|
|
103
|
-
|
|
104
|
-
|
|
46
|
+
rails new echo_app --minimal --skip-active-record
|
|
47
|
+
cd echo_app
|
|
48
|
+
bundle add a2a-rails --version '= 0.3.0'
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Then choose Server or Client-only setup below. No explicit Engine mount is needed.
|
|
52
|
+
|
|
53
|
+
## Client-only Quick Start
|
|
54
|
+
|
|
55
|
+
Create `config/initializers/a2a_rails.rb` before booting Rails:
|
|
56
|
+
|
|
57
|
+
```ruby
|
|
58
|
+
A2A::Rails.configure do |config|
|
|
59
|
+
config.server_enabled = false
|
|
60
|
+
end
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
No Agent or Handler is required; both inbound A2A paths remain unmounted. Restart Rails after changing this setting. In `bin/rails console`, construct a Client for an Agent you are authorized to call:
|
|
64
|
+
|
|
65
|
+
```ruby
|
|
66
|
+
client = A2A::Rails::Client.new(
|
|
67
|
+
agent_card_url: "https://your-agent.example/.well-known/agent-card.json",
|
|
68
|
+
allowed_origins: ["https://your-agent.example"]
|
|
69
|
+
)
|
|
70
|
+
card = client.agent_card
|
|
71
|
+
result = client.send_message(message: {
|
|
72
|
+
message_id: SecureRandom.uuid,
|
|
73
|
+
role: "ROLE_USER",
|
|
74
|
+
parts: [{ text: "Hello" }]
|
|
75
|
+
})
|
|
76
|
+
result.kind # => :task or :message
|
|
105
77
|
```
|
|
106
78
|
|
|
107
|
-
|
|
79
|
+
Replace the placeholder with a real approved HTTPS Agent. For an authenticated Agent, configure credential callbacks bound to the exact receiving origin; see the [Client guide](docs/guides/outbound-a2a-client.md) for credentials, Task operations, errors and timeout handling. See the [existing Client demo](https://github.com/cuichangquan/a2a-rails-client-demo) for isolated TLS verification.
|
|
108
80
|
|
|
109
|
-
## Quick Start
|
|
81
|
+
## Server Quick Start (local development)
|
|
110
82
|
|
|
111
|
-
|
|
83
|
+
Use the published `a2a-rails 0.3.0` Gem installed above in development. The Echo flow uses synchronous execution and MemoryStore; no database or queue is required. If you previously selected Client-only mode, remove `server_enabled = false` and restart Rails.
|
|
112
84
|
|
|
113
85
|
### 1. Generate the setup
|
|
114
86
|
|
|
@@ -189,7 +161,7 @@ The Agent class name remains a String until an A2A endpoint resolves it, preserv
|
|
|
189
161
|
Start Rails:
|
|
190
162
|
|
|
191
163
|
```bash
|
|
192
|
-
bin/rails server
|
|
164
|
+
bin/rails server -b 127.0.0.1
|
|
193
165
|
```
|
|
194
166
|
|
|
195
167
|
Then request the Agent Card:
|
|
@@ -233,7 +205,56 @@ result.task.status.state == TASK_STATE_COMPLETED
|
|
|
233
205
|
Artifact Text Part == "Echo: Hello"
|
|
234
206
|
```
|
|
235
207
|
|
|
236
|
-
See [
|
|
208
|
+
See the [historical v0.1 Quick Start design](docs/design/quick-start.md) for the original generator contract. For a complete working app, use the [existing Rails demo](https://github.com/cuichangquan/a2a-rails-demo).
|
|
209
|
+
|
|
210
|
+
## Runnable Rails Demo / 実際に動くサンプル ⭐
|
|
211
|
+
|
|
212
|
+
**[a2a-rails-demo — independent Rails 8 Echo Agent](https://github.com/cuichangquan/a2a-rails-demo)**
|
|
213
|
+
|
|
214
|
+
Run a complete standalone Rails Agent using the **published RubyGems `a2a-rails = 0.3.0`** (not a Git source checkout). The separate Demo covers Agent Card discovery, JSON-RPC v1.0 SendMessage **Task and direct Message**, GetTask, ListTasks and error handling.
|
|
215
|
+
|
|
216
|
+
- [Demo Quick Start, code and example curl requests](https://github.com/cuichangquan/a2a-rails-demo#quick-start).
|
|
217
|
+
- [Demo GitHub Actions smoke](https://github.com/cuichangquan/a2a-rails-demo/actions/workflows/smoke.yml) — independent Rails 8.1.4 / Ruby 3.4.10 HTTP smoke against published stable Gem `0.3.0` ([Step 32 Server PR #3, merged](https://github.com/cuichangquan/a2a-rails-demo/pull/3), [passing CI](https://github.com/cuichangquan/a2a-rails-demo/actions/runs/38097407649)). Verifies the actual published Gem and dependency versions, Task/direct Message/GetTask/ListTasks/CancelTask and refusal to boot in production. The historical [Step 28 v0.2.0 smoke](https://github.com/cuichangquan/a2a-rails-demo/actions/runs/37736426834) is preserved separately.
|
|
218
|
+
- **Local-only development/test** demo: no trusted verifier or durable Task store, **not** an internet-facing production template. See [production security](docs/guides/production-security.md).
|
|
219
|
+
|
|
220
|
+
### Outbound Client-only Rails Demo / 外部A2A Agentを呼び出すサンプル
|
|
221
|
+
|
|
222
|
+
**[a2a-rails-client-demo — standalone Rails 8 Client](https://github.com/cuichangquan/a2a-rails-client-demo)**
|
|
223
|
+
|
|
224
|
+
Independent Client-only Rails application **now tested against published stable RubyGems `a2a-rails = 0.3.0`** with `server_enabled = false`. It discovers Agent Cards and calls SendMessage (Task/direct Message), GetTask and ListTasks using exact HTTPS origin allowlisting. [Stable Client CI PASS](https://github.com/cuichangquan/a2a-rails-client-demo/actions/runs/38097502077) and [independent Rails-to-Rails pinned-TLS CI PASS](https://github.com/cuichangquan/a2a-rails-client-demo/actions/runs/38097502218) use **published stable 0.3.0 on both Rails sides** and actual Server Echo business logic ([Step 32 Client PR #3](https://github.com/cuichangquan/a2a-rails-client-demo/pull/3)). The loopback-only bridge uses an ephemeral test CA and isolated test-only policy override; production Client SSRF/TLS protections are not relaxed. This is **not** a direct public-DNS/public-CA or production deployment test. Historical RC1 Client ↔ 0.2.0 Server evidence remains [in Step 30](https://github.com/cuichangquan/a2a-rails/issues/117).
|
|
225
|
+
|
|
226
|
+
## What is a2a-rails?
|
|
227
|
+
|
|
228
|
+
`a2a-rails` provides inbound Server and outbound Client APIs for Rails applications.
|
|
229
|
+
|
|
230
|
+
```text
|
|
231
|
+
A2A Protocol
|
|
232
|
+
↓
|
|
233
|
+
Ruby A2A SDK
|
|
234
|
+
↓
|
|
235
|
+
a2a-rails
|
|
236
|
+
↓
|
|
237
|
+
Rails Application
|
|
238
|
+
↓
|
|
239
|
+
Business Logic
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
The Gem provides:
|
|
243
|
+
|
|
244
|
+
- a Rails-native Agent / Skill DSL;
|
|
245
|
+
- A2A Agent Card generation;
|
|
246
|
+
- automatically mounted A2A HTTP endpoints;
|
|
247
|
+
- synchronous Task execution by default, plus opt-in ActiveJob-backed async Task execution in published `0.2.0`;
|
|
248
|
+
- SDK-independent Handler inputs;
|
|
249
|
+
- a process-local MemoryStore by default, plus an optional durable ActiveRecordStore in `0.2.0`;
|
|
250
|
+
- Rails generators for initial setup;
|
|
251
|
+
- an internal Protocol Adapter boundary around the upstream SDK;
|
|
252
|
+
- **in 0.3.x**, a Rails outbound `A2A::Rails::Client` with strict HTTPS Agent Card discovery, A2A v1.0 JSON-RPC communication and optional Client-only mode.
|
|
253
|
+
|
|
254
|
+
The current release supports Server and Client use and remains **non-streaming**.
|
|
255
|
+
|
|
256
|
+
> [!WARNING]
|
|
257
|
+
> **Versioned security note:** The original **v0.1.0** did not implement per-caller Task authorization. **0.2.0 and the subsequent 0.3.x line** include a host-owned authentication hook, principal-scoped Task operations and fail-closed non-development/test behavior. **Neither version supplies your identity provider or business authorization, and publication does not approve an anonymously exposed production endpoint.** See [SECURITY.md](SECURITY.md), [authentication guide](docs/guides/authentication.md) and [deployment #11](https://github.com/cuichangquan/a2a-rails/issues/11).
|
|
237
258
|
|
|
238
259
|
## Public Rails API
|
|
239
260
|
|
|
@@ -277,7 +298,7 @@ For multiple Skills, the application supplies a Router. The Router receives `ski
|
|
|
277
298
|
|
|
278
299
|
## HTTP Endpoints
|
|
279
300
|
|
|
280
|
-
|
|
301
|
+
With Server enabled (the default), the Gem automatically exposes:
|
|
281
302
|
|
|
282
303
|
```text
|
|
283
304
|
GET /.well-known/agent-card.json
|
|
@@ -307,7 +328,6 @@ Rate limiting, application-specific authorization and production deployment safe
|
|
|
307
328
|
|
|
308
329
|
Do **not** interpret successful source-tree CI or a merge to `main` as publication of a new RubyGems release.
|
|
309
330
|
|
|
310
|
-
|
|
311
331
|
## Agent Card
|
|
312
332
|
|
|
313
333
|
Agent Cards are generated from the Agent / Skill DSL.
|
|
@@ -322,6 +342,17 @@ Behavior in v0.1:
|
|
|
322
342
|
- Streaming, Push Notifications, and Extended Agent Cards are disabled;
|
|
323
343
|
- generated Cards pass the `agent2agent 2.0.0` Agent Card schema.
|
|
324
344
|
|
|
345
|
+
### Structured Data input (unreleased 0.4.0 candidate)
|
|
346
|
+
|
|
347
|
+
Declare `input_modes: ["application/json"]` on each Skill that accepts Data.
|
|
348
|
+
The selected Skill receives a normal Ruby Hash containing the JSON object, with
|
|
349
|
+
its original string keys and nested values intact. A Router selects a Skill
|
|
350
|
+
before this opt-in is checked; sending Data alone does not select a Skill
|
|
351
|
+
automatically. Legacy text-only handlers do not receive Data. See the
|
|
352
|
+
[structured Data guide](docs/guides/structured-data.md) for a complete Handler,
|
|
353
|
+
Client call, storage behavior and limits. Published 0.3.0 does not accept
|
|
354
|
+
inbound Data.
|
|
355
|
+
|
|
325
356
|
## Task Lifecycle
|
|
326
357
|
|
|
327
358
|
Internally, `a2a-rails` keeps SDK-independent Task states:
|
|
@@ -430,7 +461,7 @@ lib/generators/a2a/rails/
|
|
|
430
461
|
└── templates/
|
|
431
462
|
```
|
|
432
463
|
|
|
433
|
-
## v0.1
|
|
464
|
+
## Historical v0.1 scope
|
|
434
465
|
|
|
435
466
|
Included:
|
|
436
467
|
|
|
@@ -467,7 +498,7 @@ Not included in v0.1:
|
|
|
467
498
|
- LLM Agent Framework
|
|
468
499
|
- Orchestration Framework
|
|
469
500
|
|
|
470
|
-
##
|
|
501
|
+
## Historical v0.1.0 verification
|
|
471
502
|
|
|
472
503
|
The v0.1.0 release candidate completed:
|
|
473
504
|
|
|
@@ -531,12 +562,33 @@ The CI matrix covers:
|
|
|
531
562
|
|
|
532
563
|
Known warning-enabled output from upstream `agent2agent 2.0.0` can include circular-require, indentation, and URI-parser warnings. Those warnings are distinct from the Rack-environment INFO logging that `a2a-rails` suppresses at the Rails-facing adapter boundary.
|
|
533
564
|
|
|
534
|
-
## Release
|
|
565
|
+
## Release history and evidence
|
|
566
|
+
|
|
567
|
+
> **Historical v0.3.0.rc1 pre-release (2026-10-10):** `0.3.0.rc1` is published on [RubyGems](https://rubygems.org/gems/a2a-rails/versions/0.3.0.rc1) and as a [GitHub Pre-release](https://github.com/cuichangquan/a2a-rails/releases/tag/v0.3.0-rc1). It adds the outbound Rails Client and Client-only mode. Stable `0.2.0` remains available. RC1 is not stable `0.3.0`, an independent audit, or public-production approval; see the [publication record](docs/release/v0.3.0-rc1-publication-record.md) and [Client guide](docs/guides/outbound-a2a-client.md).
|
|
568
|
+
|
|
569
|
+
> **Release status (2026-10-08):** **`0.2.0` is published as a stable release** on [RubyGems](https://rubygems.org/gems/a2a-rails/versions/0.2.0) and [GitHub](https://github.com/cuichangquan/a2a-rails/releases/tag/v0.2.0). It includes the Rails/Zeitwerk and migration-generator fixes after rc2. The public Gem matches the verified artifact byte-for-byte; see the [publication record](docs/release/v0.2.0-publication-record.md).
|
|
570
|
+
|
|
571
|
+
- RubyGems: https://rubygems.org/gems/a2a-rails
|
|
572
|
+
- **Current stable `0.3.0`:** [GitHub Release](https://github.com/cuichangquan/a2a-rails/releases/tag/v0.3.0) · [RubyGems](https://rubygems.org/gems/a2a-rails/versions/0.3.0) · [exact public SHA256 and provenance](docs/release/v0.3.0-publication-record.md)
|
|
573
|
+
- Published version list: https://rubygems.org/gems/a2a-rails/versions
|
|
574
|
+
- Earlier stable release `0.2.0`: https://github.com/cuichangquan/a2a-rails/releases/tag/v0.2.0
|
|
575
|
+
- Previous stable release: https://github.com/cuichangquan/a2a-rails/releases/tag/v0.1.0
|
|
576
|
+
- Changelog: [CHANGELOG.md](CHANGELOG.md)
|
|
577
|
+
- Release record: [v0.3.0 publication record](docs/release/v0.3.0-publication-record.md) · [historical v0.2.0 publication record](docs/release/v0.2.0-publication-record.md)
|
|
578
|
+
- **Security policy / 脆弱性報告:** [SECURITY.md](SECURITY.md) — confidential vulnerability reporting, current assurance boundaries and production responsibilities.
|
|
579
|
+
- **v0.3.x prerelease policy:** [Risk-based release gates](docs/release/step-29-5u-risk-based-oss-release-policy.md) — independently commissioned external audit is **recommended but optional**, not a known vulnerability or RubyGems requirement. Technical security checks, no known unresolved Critical/High findings, exact Gem provenance and explicit maintainer release approval remain mandatory; [optional community review #113](https://github.com/cuichangquan/a2a-rails/issues/113). **Check the published-version list for the current stable version; package publication and public-production deployment are separate decisions.**
|
|
580
|
+
- **Release evidence & upgrading:** [Step 31 release-readiness record](docs/release/v0.3.0-stable-readiness.md) · [RC1 feedback snapshot](docs/release/v0.3.0-rc1-feedback-and-upgrade-readiness.md) · [v0.2.0 → v0.3.0 upgrade guide](docs/release/upgrading-v0.2.0-to-v0.3.md) · [v0.1.0 → v0.2.0 guide](docs/release/upgrading-v0.1.0-to-v0.2.md). Check [RubyGems](https://rubygems.org/gems/a2a-rails/versions) for availability. Gem distribution does **not** authorize public Agent exposure.
|
|
581
|
+
- **低コスト検証 / Cost-efficient verification:** [Step 33 validation levels, offline decision helper and read-only GCP inventory](docs/testing/cost-efficient-validation.md) — reuse existing CI before new billable infrastructure; cloud operations require separate approval.
|
|
582
|
+
- **Roadmap / 次にやること:** [ROADMAP.md](ROADMAP.md) · [Step 31 / Issue #120](https://github.com/cuichangquan/a2a-rails/issues/120) for the `0.3.0` release-evaluation and publication decisions. [Issue #11](https://github.com/cuichangquan/a2a-rails/issues/11) still governs public-production deployment; the [historical `0.2.0` release record](docs/release/v0.2.0-stable-readiness.md) is separate.
|
|
583
|
+
- **Official A2A TCK results:** [Pinned JSON-RPC MUST report and reproduction](docs/testing/official-a2a-tck.md) — after Step 17-4: **63 passed / 1 failed / 171 skipped / 30 deselected** (pytest). The remaining `CORE-SEND-003` mismatch is tracked [upstream in #202](https://github.com/a2aproject/a2a-tck/issues/202). The TCK workflow is informational, **not** an A2A conformance certificate.
|
|
584
|
+
|
|
585
|
+
- [A2Aの全体像(日本語・A4 1枚PDF)](docs/guides/a2a-protocol-overview-ja.pdf) — 登場人物・依頼の流れ・主要用語・MCPとの違いをまとめた学習資料。
|
|
586
|
+
- [A2A at a glance (English, A4 one-page PDF)](docs/guides/a2a-protocol-overview-en.pdf) — Roles, workflow, key terms, and how MCP fits.
|
|
535
587
|
|
|
536
588
|
- [CHANGELOG](CHANGELOG.md)
|
|
537
|
-
- [
|
|
589
|
+
- [Historical 0.3.0 pre-publication readiness](docs/release/v0.3.0-stable-readiness.md)
|
|
538
590
|
- [Step 31-4 RC1 feedback evidence and risks](docs/release/v0.3.0-rc1-feedback-and-upgrade-readiness.md)
|
|
539
|
-
- [Upgrading from v0.2.0 to
|
|
591
|
+
- [Upgrading from v0.2.0 to v0.3.0](docs/release/upgrading-v0.2.0-to-v0.3.md)
|
|
540
592
|
- [RC1 feedback / bug report template](https://github.com/cuichangquan/a2a-rails/issues/new?template=rc1-feedback.md)
|
|
541
593
|
- [v0.1.0 Release Notes](docs/release/v0.1.0.md)
|
|
542
594
|
- [v0.1.0 Release Checklist](docs/release/v0.1.0-checklist.md)
|
|
@@ -554,6 +606,13 @@ Known warning-enabled output from upstream `agent2agent 2.0.0` can include circu
|
|
|
554
606
|
|
|
555
607
|
The Gem is available as open source under the terms of the MIT License. See [LICENSE](LICENSE).
|
|
556
608
|
|
|
609
|
+
## Protocol illustrations
|
|
610
|
+
|
|
611
|
+
<img src="docs/assets/a2a-rails-infographics.png">
|
|
612
|
+
<br/>
|
|
613
|
+
<br/>
|
|
614
|
+
<img src="docs/assets/a2a-rails-infographics-en.png">
|
|
615
|
+
|
|
557
616
|
## Official A2A Resources / A2A公式資料
|
|
558
617
|
|
|
559
618
|
- [A2A Protocol overview / A2Aの全体像(日本語・A4 1枚PDF)](docs/guides/a2a-protocol-overview-ja.pdf) — 公式資料をもとに作成した学習資料(2026-10-07)。
|
data/lib/a2a/rails/client.rb
CHANGED
|
@@ -183,7 +183,8 @@ module A2A
|
|
|
183
183
|
end
|
|
184
184
|
validate_remote_protocol_keys!(part, operation)
|
|
185
185
|
type = kinds.find { |key| part.key?(key) }
|
|
186
|
-
|
|
186
|
+
value = part[type]
|
|
187
|
+
valid_value = type == "data" ? value.is_a?(Hash) || value.is_a?(Array) : value.is_a?(String)
|
|
187
188
|
unless valid_value
|
|
188
189
|
raise InvalidResponseError.new(:invalid_message_part, operation: operation)
|
|
189
190
|
end
|
data/lib/a2a/rails/dispatcher.rb
CHANGED
|
@@ -27,6 +27,7 @@ module A2A
|
|
|
27
27
|
def plan(message:, context:)
|
|
28
28
|
validate!
|
|
29
29
|
skill = select_skill(message: message, context: context)
|
|
30
|
+
verify_skill_input!(skill, message)
|
|
30
31
|
|
|
31
32
|
ExecutionPlan.new(
|
|
32
33
|
agent_class_name: @agent.name,
|
|
@@ -38,6 +39,7 @@ module A2A
|
|
|
38
39
|
def execute(plan:, message:, context:)
|
|
39
40
|
validate!
|
|
40
41
|
skill = declared_skill(plan.skill_id)
|
|
42
|
+
verify_skill_input!(skill, message)
|
|
41
43
|
handler_context = context.merge(skill_id: skill.id)
|
|
42
44
|
|
|
43
45
|
skill.handler.call(message: message, context: handler_context)
|
|
@@ -64,6 +66,14 @@ module A2A
|
|
|
64
66
|
declared_skill(selected_id, selected)
|
|
65
67
|
end
|
|
66
68
|
|
|
69
|
+
def verify_skill_input!(skill, message)
|
|
70
|
+
parts = message[:parts] if message.is_a?(Hash)
|
|
71
|
+
return unless parts.is_a?(Array) && parts.any? { |part| part.is_a?(Hash) && part.key?(:data) }
|
|
72
|
+
return if skill.input_modes&.include?(Skill::DATA_INPUT_MODE)
|
|
73
|
+
|
|
74
|
+
raise UnsupportedSkillInputError, "Selected skill does not accept JSON Data Parts"
|
|
75
|
+
end
|
|
76
|
+
|
|
67
77
|
def declared_skill(skill_id, original = skill_id)
|
|
68
78
|
@agent.skills.find { |skill| skill.id == skill_id } ||
|
|
69
79
|
raise(UnknownSkillError, "Router selected unknown skill: #{original.inspect}")
|
data/lib/a2a/rails/errors.rb
CHANGED
|
@@ -5,6 +5,7 @@ require "rack"
|
|
|
5
5
|
require "stringio"
|
|
6
6
|
require_relative "adapter"
|
|
7
7
|
require_relative "task_mapper"
|
|
8
|
+
require_relative "part_data"
|
|
8
9
|
|
|
9
10
|
module A2A
|
|
10
11
|
module Rails
|
|
@@ -90,7 +91,14 @@ module A2A
|
|
|
90
91
|
request = env.fetch("a2a.request")
|
|
91
92
|
validate_request!(request)
|
|
92
93
|
|
|
93
|
-
|
|
94
|
+
params = request.to_h
|
|
95
|
+
if operation == "SendMessage"
|
|
96
|
+
# The binding retains the parsed original params before Definition
|
|
97
|
+
# recursively removes nil values. Preserve Data only after the
|
|
98
|
+
# usual SDK validation; Rails still validates its input contract.
|
|
99
|
+
params = PartData.restore_request(params, env["a2a.body"])
|
|
100
|
+
end
|
|
101
|
+
result = @request_handler.call(operation: operation, params: params)
|
|
94
102
|
schema(RESPONSE_SCHEMAS.fetch(operation), result)
|
|
95
103
|
rescue A2A::Rails::TaskNotFoundError => error
|
|
96
104
|
raise A2A::TaskNotFoundError.new(error.task_id)
|
|
@@ -128,7 +136,9 @@ module A2A
|
|
|
128
136
|
def schema(name, value)
|
|
129
137
|
object = A2A::Protocol::JsonSchema[name].new(value)
|
|
130
138
|
object.valid!
|
|
131
|
-
|
|
139
|
+
# Return the SDK-normalized protocol shape, with only opaque Data
|
|
140
|
+
# restored. The SDK binding remains responsible for JSON-RPC output.
|
|
141
|
+
PartData.restore_response(name, object.to_h, value)
|
|
132
142
|
end
|
|
133
143
|
end
|
|
134
144
|
end
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module A2A
|
|
4
|
+
module Rails
|
|
5
|
+
module Protocol
|
|
6
|
+
# Local compatibility boundary for agent2agent 2.0's recursive nil
|
|
7
|
+
# compaction. Protocol fields still use the SDK's normalization; only
|
|
8
|
+
# Part content is restored from the original plain-Ruby representation.
|
|
9
|
+
# In particular, this does not change metadata serialization.
|
|
10
|
+
module PartData
|
|
11
|
+
CONTENT_FIELDS = %w[text data raw url].freeze
|
|
12
|
+
|
|
13
|
+
module_function
|
|
14
|
+
|
|
15
|
+
def restore_request(params, original)
|
|
16
|
+
return params unless params.is_a?(Hash) && original.is_a?(Hash)
|
|
17
|
+
|
|
18
|
+
restore_message(params["message"], original["message"], request: true)
|
|
19
|
+
params
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def restore_response(name, normalized, original)
|
|
23
|
+
case name
|
|
24
|
+
when "Send Message Response"
|
|
25
|
+
restore_message(normalized["message"], original["message"])
|
|
26
|
+
restore_task(normalized["task"], original["task"])
|
|
27
|
+
when "Task"
|
|
28
|
+
restore_task(normalized, original)
|
|
29
|
+
when "List Tasks Response"
|
|
30
|
+
each_pair(normalized["tasks"], original["tasks"]) do |task, source|
|
|
31
|
+
restore_task(task, source)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
normalized
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def restore_task(task, original)
|
|
38
|
+
return unless task.is_a?(Hash) && original.is_a?(Hash)
|
|
39
|
+
|
|
40
|
+
each_pair(task["history"], original["history"]) do |message, source|
|
|
41
|
+
restore_message(message, source)
|
|
42
|
+
end
|
|
43
|
+
each_pair(task["artifacts"], original["artifacts"]) do |artifact, source|
|
|
44
|
+
restore_message(artifact, source)
|
|
45
|
+
end
|
|
46
|
+
status = task["status"]
|
|
47
|
+
source_status = original["status"]
|
|
48
|
+
if status.is_a?(Hash) && source_status.is_a?(Hash)
|
|
49
|
+
restore_message(status["message"], source_status["message"])
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def restore_message(message, original, request: false)
|
|
54
|
+
return unless message.is_a?(Hash) && original.is_a?(Hash)
|
|
55
|
+
|
|
56
|
+
each_pair(message["parts"], original["parts"]) do |part, source|
|
|
57
|
+
next unless part.is_a?(Hash) && source.is_a?(Hash)
|
|
58
|
+
|
|
59
|
+
# Preserve original kind-field presence so the Rails input contract
|
|
60
|
+
# can reject ambiguous Parts even when one field is JSON null.
|
|
61
|
+
fields = request ? CONTENT_FIELDS : ["data"]
|
|
62
|
+
fields.each { |field| part[field] = copy(source[field]) if source.key?(field) }
|
|
63
|
+
next unless request && source.key?("data")
|
|
64
|
+
|
|
65
|
+
# Accept the same alternate spelling as the SDK, but avoid
|
|
66
|
+
# choosing a Data media type based on field order.
|
|
67
|
+
keys = %w[mediaType media_type].select { |key| source.key?(key) }
|
|
68
|
+
if keys.size > 1
|
|
69
|
+
raise InvalidRequestError, "Data Part must not specify mediaType more than once"
|
|
70
|
+
end
|
|
71
|
+
part["mediaType"] = source.fetch(keys.first) if keys.one?
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def each_pair(values, originals)
|
|
76
|
+
return unless values.is_a?(Array) && originals.is_a?(Array)
|
|
77
|
+
|
|
78
|
+
values.each_with_index { |value, index| yield value, originals[index] }
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def copy(value)
|
|
82
|
+
Marshal.load(Marshal.dump(value))
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
private_class_method :restore_task, :restore_message, :each_pair, :copy
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
@@ -43,11 +43,27 @@ module A2A
|
|
|
43
43
|
return send_direct_message(message, context_id)
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
preflight = nil
|
|
47
|
+
routing_error = nil
|
|
48
|
+
task = @lifecycle.create(message: message, context_id: context_id) do |draft|
|
|
49
|
+
next unless message.fetch(:parts).any? { |part| part.key?(:data) }
|
|
50
|
+
|
|
51
|
+
# The router gets the final task context, but unsupported Data
|
|
52
|
+
# must not create a Task or consume the owner's storage quota.
|
|
53
|
+
begin
|
|
54
|
+
preflight = @dispatcher.plan(message: message, context: execution_context(draft))
|
|
55
|
+
rescue UnsupportedSkillInputError => error
|
|
56
|
+
raise ContentTypeNotSupportedError, error.message
|
|
57
|
+
rescue StandardError => error
|
|
58
|
+
routing_error = error
|
|
59
|
+
end
|
|
60
|
+
end
|
|
47
61
|
context = execution_context(task)
|
|
48
62
|
|
|
49
63
|
plan = begin
|
|
50
|
-
|
|
64
|
+
raise routing_error if routing_error
|
|
65
|
+
|
|
66
|
+
preflight || @dispatcher.plan(message: message, context: context)
|
|
51
67
|
rescue RejectedTask => error
|
|
52
68
|
task = @lifecycle.reject(task.fetch(:id), error)
|
|
53
69
|
nil
|
|
@@ -121,6 +137,8 @@ module A2A
|
|
|
121
137
|
context: { task_id: nil, context_id: context_id }
|
|
122
138
|
)
|
|
123
139
|
{ "message" => @task_mapper.dump_direct_message(result, context_id: context_id) }
|
|
140
|
+
rescue UnsupportedSkillInputError => error
|
|
141
|
+
raise ContentTypeNotSupportedError, error.message
|
|
124
142
|
rescue StandardError
|
|
125
143
|
# No Task exists to record a FAILED status. Never send application
|
|
126
144
|
# exception details or unsupported result values to A2A callers.
|
|
@@ -199,7 +217,10 @@ module A2A
|
|
|
199
217
|
raise TaskContinuationNotSupportedError, "Task continuation is not supported in v0.1"
|
|
200
218
|
end
|
|
201
219
|
|
|
202
|
-
normalized_parts = parts.map { |part|
|
|
220
|
+
normalized_parts = parts.map { |part| normalize_part(part) }
|
|
221
|
+
if normalized_parts.any? { |part| part.key?(:data) } && normalized_parts.any? { |part| part.key?(:text) }
|
|
222
|
+
raise ContentTypeNotSupportedError, "Text and JSON Data Parts cannot be mixed in one Message"
|
|
223
|
+
end
|
|
203
224
|
message = {
|
|
204
225
|
message_id: message_id,
|
|
205
226
|
role: :user,
|
|
@@ -210,27 +231,55 @@ module A2A
|
|
|
210
231
|
[message, context_id]
|
|
211
232
|
end
|
|
212
233
|
|
|
213
|
-
def
|
|
214
|
-
|
|
215
|
-
|
|
234
|
+
def normalize_part(part)
|
|
235
|
+
types = part.is_a?(Hash) ? part.keys & %w[text data raw url] : []
|
|
236
|
+
if types.size > 1
|
|
237
|
+
raise InvalidRequestError, "Each Part must specify exactly one content kind"
|
|
216
238
|
end
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
239
|
+
|
|
240
|
+
normalized = case types.first
|
|
241
|
+
when "data"
|
|
242
|
+
normalize_data_part(part)
|
|
243
|
+
when "text"
|
|
244
|
+
normalize_text_part(part)
|
|
245
|
+
else
|
|
246
|
+
raise ContentTypeNotSupportedError, "Only text and JSON Data Parts are supported"
|
|
220
247
|
end
|
|
248
|
+
|
|
221
249
|
metadata = part["metadata"]
|
|
222
250
|
unless metadata.nil? || metadata.is_a?(Hash)
|
|
223
251
|
raise InvalidRequestError, "part metadata must be an object"
|
|
224
252
|
end
|
|
225
|
-
|
|
226
|
-
normalized = {
|
|
227
|
-
text: part["text"],
|
|
228
|
-
media_type: part["mediaType"].to_s.empty? ? "text/plain" : part["mediaType"]
|
|
229
|
-
}
|
|
230
253
|
normalized[:metadata] = copy(metadata) if metadata
|
|
231
254
|
normalized
|
|
232
255
|
end
|
|
233
256
|
|
|
257
|
+
def normalize_data_part(part)
|
|
258
|
+
data = part["data"]
|
|
259
|
+
unless data.is_a?(Hash)
|
|
260
|
+
raise InvalidRequestError, "Data Part input must be a JSON object"
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
media_type = part.fetch("mediaType", Skill::DATA_INPUT_MODE)
|
|
264
|
+
unless media_type == Skill::DATA_INPUT_MODE
|
|
265
|
+
raise ContentTypeNotSupportedError, "Data Part mediaType must be application/json when specified"
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
{ data: copy(data), media_type: media_type }
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
def normalize_text_part(part)
|
|
272
|
+
unless part["text"].is_a?(String)
|
|
273
|
+
raise ContentTypeNotSupportedError, "Text Part content must be a String"
|
|
274
|
+
end
|
|
275
|
+
|
|
276
|
+
media_type = part["mediaType"]
|
|
277
|
+
unless media_type.nil? || media_type.is_a?(String)
|
|
278
|
+
raise InvalidRequestError, "mediaType must be a String"
|
|
279
|
+
end
|
|
280
|
+
{ text: part["text"], media_type: media_type.to_s.empty? ? "text/plain" : media_type }
|
|
281
|
+
end
|
|
282
|
+
|
|
234
283
|
def validate_list_filters!(params)
|
|
235
284
|
if params.key?("contextId") && !params["contextId"].nil? && !params["contextId"].is_a?(String)
|
|
236
285
|
raise InvalidRequestError, "contextId must be a String"
|
|
@@ -104,7 +104,7 @@ module A2A
|
|
|
104
104
|
result["raw"] = part[:raw] if part.key?(:raw)
|
|
105
105
|
result["url"] = part[:url] if part.key?(:url)
|
|
106
106
|
result["filename"] = part[:filename] if part.key?(:filename)
|
|
107
|
-
if part.key?(:raw) || part.key?(:url)
|
|
107
|
+
if part.key?(:raw) || part.key?(:url) || part.key?(:data)
|
|
108
108
|
result["mediaType"] = part[:media_type] if part.key?(:media_type)
|
|
109
109
|
end
|
|
110
110
|
result["metadata"] = copy(part[:metadata]) if part.key?(:metadata)
|
data/lib/a2a/rails/skill.rb
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
module A2A
|
|
4
4
|
module Rails
|
|
5
5
|
class Skill
|
|
6
|
+
DATA_INPUT_MODE = "application/json"
|
|
7
|
+
|
|
6
8
|
attr_reader :id, :name, :description, :tags, :handler, :examples, :input_modes, :output_modes, :execution_mode
|
|
7
9
|
|
|
8
10
|
def initialize(id:, description:, tags:, handler:, name: nil, examples: nil, input_modes: nil, output_modes: nil, execution_mode: nil)
|
|
@@ -413,11 +413,38 @@ module A2A
|
|
|
413
413
|
}
|
|
414
414
|
|
|
415
415
|
task[:status][:message] = deep_symbolize(record.status_message) unless record.status_message.nil?
|
|
416
|
-
task[:history] =
|
|
417
|
-
task[:artifacts] =
|
|
416
|
+
task[:history] = deserialize_part_entries(record.history) unless record.history.nil?
|
|
417
|
+
task[:artifacts] = deserialize_part_entries(record.artifacts) unless record.artifacts.nil?
|
|
418
418
|
task
|
|
419
419
|
end
|
|
420
420
|
|
|
421
|
+
# The persistence envelope uses Ruby symbols; JSON inside the data
|
|
422
|
+
# field of a protocol Part is opaque. Do not treat a key named "data"
|
|
423
|
+
# inside metadata (or inside another arbitrary object) as a Part.
|
|
424
|
+
def deserialize_part_entries(entries)
|
|
425
|
+
return deep_symbolize(entries) unless entries.is_a?(Array)
|
|
426
|
+
|
|
427
|
+
entries.map do |entry|
|
|
428
|
+
next deep_symbolize(entry) unless entry.is_a?(Hash)
|
|
429
|
+
|
|
430
|
+
entry.each_with_object({}) do |(key, value), result|
|
|
431
|
+
result[key.to_sym] = if key == "parts" && value.is_a?(Array)
|
|
432
|
+
value.map { |part| deserialize_part(part) }
|
|
433
|
+
else
|
|
434
|
+
deep_symbolize(value)
|
|
435
|
+
end
|
|
436
|
+
end
|
|
437
|
+
end
|
|
438
|
+
end
|
|
439
|
+
|
|
440
|
+
def deserialize_part(part)
|
|
441
|
+
return deep_symbolize(part) unless part.is_a?(Hash)
|
|
442
|
+
|
|
443
|
+
part.each_with_object({}) do |(key, value), result|
|
|
444
|
+
result[key.to_sym] = key == "data" ? value : deep_symbolize(value)
|
|
445
|
+
end
|
|
446
|
+
end
|
|
447
|
+
|
|
421
448
|
def deep_stringify(value)
|
|
422
449
|
case value
|
|
423
450
|
when Hash
|
data/lib/a2a/rails/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: a2a-rails
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- cuichangquan
|
|
@@ -244,6 +244,7 @@ files:
|
|
|
244
244
|
- lib/a2a/rails/file_artifact.rb
|
|
245
245
|
- lib/a2a/rails/protocol/adapter.rb
|
|
246
246
|
- lib/a2a/rails/protocol/agent2agent_adapter.rb
|
|
247
|
+
- lib/a2a/rails/protocol/part_data.rb
|
|
247
248
|
- lib/a2a/rails/protocol/request_handler.rb
|
|
248
249
|
- lib/a2a/rails/protocol/task_mapper.rb
|
|
249
250
|
- lib/a2a/rails/request_guard.rb
|