@godspeedai/cognate-a2a 0.1.0 → 0.1.2
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.
- package/README.md +86 -13
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,19 +1,92 @@
|
|
|
1
1
|
# @godspeedai/cognate-a2a
|
|
2
2
|
|
|
3
|
-
Publishes a runtime agent as an A2A agent
|
|
4
|
-
`TASK_STATE_*` / `ROLE_*` string enums, not the legacy v0.3 JSON-Schema shapes).
|
|
3
|
+
Publishes a Cognate runtime agent as an [A2A](https://a2a-protocol.org) agent: one `fetch` handler that serves the agent card and a JSON-RPC `SendMessage` endpoint backed by durable runs.
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
- `GET /.well-known/agent-card.json` — the agent card (no auth required).
|
|
8
|
-
- `POST /a2a` — JSON-RPC `SendMessage`, implemented directly against the SDK's own codecs
|
|
9
|
-
(`SendMessageRequest`/`SendMessageResponse`), since the SDK's `DefaultRequestHandler`/`AgentExecutor`
|
|
10
|
-
framework targets Express, not a stateless `fetch` handler.
|
|
5
|
+
**When to use this package:** an external A2A client (another agent, a broker, a UI) should be able to discover and talk to your Cognate agent. For AG-UI front ends use [`@godspeedai/cognate-ag-ui`](https://www.npmjs.com/package/@godspeedai/cognate-ag-ui) instead; for plain HTTP/Connect clients use [`@godspeedai/cognate-protocol-connect-bun`](https://www.npmjs.com/package/@godspeedai/cognate-protocol-connect-bun).
|
|
11
6
|
|
|
12
|
-
|
|
13
|
-
message with `taskId` resolves that run's open continuation with the message text (idempotent on `messageId`).
|
|
14
|
-
`options.authenticate` gates `/a2a`; missing/invalid credentials return HTTP 401.
|
|
7
|
+
The adapter targets `@a2a-js/sdk` 1.2.1 with the v1.0 proto-JSON wire format (the `TASK_STATE_*` / `ROLE_*` enum wire values). It implements the JSON-RPC transport directly against the SDK's own codecs, so every shape on the wire is exactly what the SDK's `Client` sends and expects.
|
|
15
8
|
|
|
16
|
-
|
|
17
|
-
`completed`→`COMPLETED` (output as a `data` artifact), `failed`→`FAILED`, `cancelled`→`CANCELED`.
|
|
9
|
+
## Installation
|
|
18
10
|
|
|
19
|
-
|
|
11
|
+
```sh
|
|
12
|
+
bun add @godspeedai/cognate-a2a
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Requires [Bun](https://bun.sh) >= 1.4.0. Depends on `@a2a-js/sdk` and the `RuntimeService` types from [`@godspeedai/cognate-runtime-api`](https://www.npmjs.com/package/@godspeedai/cognate-runtime-api); you will typically also want [`@godspeedai/cognate-runtime-bun`](https://www.npmjs.com/package/@godspeedai/cognate-runtime-bun) to have a runtime to serve.
|
|
16
|
+
|
|
17
|
+
## Quick start
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { createA2AHandler } from "@godspeedai/cognate-a2a";
|
|
21
|
+
import { createRuntime } from "@godspeedai/cognate-runtime-bun";
|
|
22
|
+
|
|
23
|
+
const runtime = await createRuntime({
|
|
24
|
+
store: "./app.sqlite",
|
|
25
|
+
agents: [/* your AgentDefinitions, including "agent.refund" */],
|
|
26
|
+
policy,
|
|
27
|
+
actions,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const handler = createA2AHandler({
|
|
31
|
+
service: runtime.service,
|
|
32
|
+
agent: "agent.refund", // the runtime agent id this card serves
|
|
33
|
+
baseUrl: "https://agents.example.com", // written into the agent card
|
|
34
|
+
card: {
|
|
35
|
+
name: "Refund agent",
|
|
36
|
+
description: "Approves refunds with a human in the loop",
|
|
37
|
+
version: "1.0.0",
|
|
38
|
+
skills: [{ id: "refund", name: "Refund", description: "Process a refund request" }],
|
|
39
|
+
},
|
|
40
|
+
authenticate: (headers) => myBearerAuth(headers), // Caller | undefined | Promise<Caller>
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
Bun.serve({ port: 8080, fetch: handler });
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
An A2A client then discovers `GET /.well-known/agent-card.json` (no auth required) and sends `POST /a2a` JSON-RPC `SendMessage` requests. Using the SDK's own client:
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
import { ClientFactory, JsonRpcTransportFactory } from "@a2a-js/sdk/client";
|
|
50
|
+
|
|
51
|
+
const authenticatedFetch = (input, init) =>
|
|
52
|
+
fetch(input, { ...init, headers: { ...init?.headers, authorization: "Bearer alice" } });
|
|
53
|
+
const client = await new ClientFactory({
|
|
54
|
+
transports: [new JsonRpcTransportFactory({ fetchImpl: authenticatedFetch })],
|
|
55
|
+
}).createFromUrl("https://agents.example.com");
|
|
56
|
+
|
|
57
|
+
const first = await client.sendMessage({
|
|
58
|
+
message: { messageId: "m1", contextId: "", taskId: "", role: 1, parts: [{ content: { $case: "text", value: "refund order 7" }, metadata: undefined, filename: "", mediaType: "" }], metadata: undefined, extensions: [], referenceTaskIds: [] },
|
|
59
|
+
});
|
|
60
|
+
// first.status.state === TASK_STATE_INPUT_REQUIRED — the run waits for a human decision
|
|
61
|
+
|
|
62
|
+
const second = await client.sendMessage({
|
|
63
|
+
message: { messageId: "m2", contextId: "", taskId: first.id, role: 1, parts: [{ content: { $case: "text", value: "yes" }, metadata: undefined, filename: "", mediaType: "" }], metadata: undefined, extensions: [], referenceTaskIds: [] },
|
|
64
|
+
});
|
|
65
|
+
// second.status.state === TASK_STATE_COMPLETED, with the run output as a data artifact
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## How tasks map to runs
|
|
69
|
+
|
|
70
|
+
- The A2A task id **is** the Cognate run id.
|
|
71
|
+
- A message without a `taskId` starts a new run (idempotent on the message id); its text becomes the run input as `{ text }`.
|
|
72
|
+
- A message with a `taskId` resolves that run's open continuation, passing the message text (idempotent on the message id).
|
|
73
|
+
- Run status maps to task state: `running` → `WORKING`, `waiting` → `INPUT_REQUIRED`, `completed` → `COMPLETED`, `failed` → `FAILED`, `cancelled` → `CANCELED`.
|
|
74
|
+
- A completed task returns the run output as a `data` artifact named `output`.
|
|
75
|
+
- Requests without valid credentials get HTTP 401.
|
|
76
|
+
|
|
77
|
+
## Limitations
|
|
78
|
+
|
|
79
|
+
- `SendMessage` is the only JSON-RPC method implemented; other methods answer with a "method not found" error. There is no streaming/notification surface.
|
|
80
|
+
- The handler waits up to five seconds for the run to settle before replying; a longer-running run replies with its current state (`WORKING`), and the client polls `SendMessage` with the task id to drive it forward.
|
|
81
|
+
- A run waiting on a continuation type with no faithful task representation still surfaces as `INPUT_REQUIRED`; the continuation payload is not rendered into the task message.
|
|
82
|
+
|
|
83
|
+
## Related packages
|
|
84
|
+
|
|
85
|
+
- [`@godspeedai/cognate-ag-ui`](https://www.npmjs.com/package/@godspeedai/cognate-ag-ui) — SSE endpoint for AG-UI front ends over the same service.
|
|
86
|
+
- [`@godspeedai/cognate-protocol-connect-bun`](https://www.npmjs.com/package/@godspeedai/cognate-protocol-connect-bun) — Connect transport for the runtime service.
|
|
87
|
+
- [`@godspeedai/cognate-runtime-bun`](https://www.npmjs.com/package/@godspeedai/cognate-runtime-bun) — the runtime serving your agents.
|
|
88
|
+
- [`@godspeedai/cognate`](https://www.npmjs.com/package/@godspeedai/cognate) — the SDK umbrella.
|
|
89
|
+
|
|
90
|
+
## License
|
|
91
|
+
|
|
92
|
+
Apache-2.0
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@godspeedai/cognate-a2a",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "A2A adapter: publishes a runtime agent as an A2A agent; continuations map to input-required tasks.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@a2a-js/sdk": "1.2.1",
|
|
26
|
-
"@godspeedai/cognate-events": "^0.1.
|
|
27
|
-
"@godspeedai/cognate-runtime-api": "^0.1.
|
|
26
|
+
"@godspeedai/cognate-events": "^0.1.2",
|
|
27
|
+
"@godspeedai/cognate-runtime-api": "^0.1.2"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@godspeedai/cognate-runtime-bun": "workspace:*"
|