a2a-nextjs 0.1.0 → 0.1.1
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 +8 -7
- package/dist/index.d.ts +1 -0
- package/dist/index.js +5 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# a2a-nextjs
|
|
2
2
|
|
|
3
3
|
A2A protocol handler for Next.js. Translates AI SDK streams to A2A events.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
pnpm add
|
|
8
|
+
pnpm add a2a-nextjs @a2a-js/sdk
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## Usage
|
|
@@ -14,7 +14,7 @@ pnpm add @adriancooney/a2a-nextjs @a2a-js/sdk
|
|
|
14
14
|
|
|
15
15
|
```typescript
|
|
16
16
|
// lib/agents/my-agent.ts
|
|
17
|
-
import { createAgent, InMemoryTaskStore } from "
|
|
17
|
+
import { createAgent, InMemoryTaskStore } from "a2a-nextjs"
|
|
18
18
|
|
|
19
19
|
export const myAgent = createAgent({
|
|
20
20
|
card: {
|
|
@@ -41,17 +41,17 @@ export const POST = myAgent
|
|
|
41
41
|
```
|
|
42
42
|
|
|
43
43
|
```typescript
|
|
44
|
-
// app/.well-known/agent
|
|
44
|
+
// app/.well-known/a2a/agent-card/route.ts
|
|
45
45
|
import { myAgent } from "@/lib/agents/my-agent"
|
|
46
46
|
|
|
47
|
-
export const GET =
|
|
47
|
+
export const GET = myAgent.cardHandler("/api/agent")
|
|
48
48
|
```
|
|
49
49
|
|
|
50
50
|
## With Workflow + DurableAgent
|
|
51
51
|
|
|
52
52
|
```typescript
|
|
53
53
|
// lib/agents/my-agent.ts
|
|
54
|
-
import { createAgent, InMemoryTaskStore } from "
|
|
54
|
+
import { createAgent, InMemoryTaskStore } from "a2a-nextjs"
|
|
55
55
|
import { start, getRun } from "workflow/api"
|
|
56
56
|
import { runAgentWorkflow } from "@/lib/agent"
|
|
57
57
|
|
|
@@ -108,7 +108,8 @@ Creates an agent handler.
|
|
|
108
108
|
**Returns** a callable handler with:
|
|
109
109
|
|
|
110
110
|
- `(request: Request) => Promise<Response>` - POST handler
|
|
111
|
-
- `.
|
|
111
|
+
- `.cardHandler(path)` - Returns GET handler that builds card with full URL from request origin
|
|
112
|
+
- `.buildCard({ url })` - Build full AgentCard manually
|
|
112
113
|
|
|
113
114
|
### Types
|
|
114
115
|
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -198,7 +198,7 @@ function createAgent(config) {
|
|
|
198
198
|
const executor = createAIStreamExecutor(execute);
|
|
199
199
|
const handler = async function handler2(request) {
|
|
200
200
|
const url = new URL(request.url);
|
|
201
|
-
const agentCard = buildCard({ url: url.pathname });
|
|
201
|
+
const agentCard = buildCard({ url: url.origin + url.pathname });
|
|
202
202
|
const requestHandler = new DefaultRequestHandler(agentCard, taskStore, executor);
|
|
203
203
|
const transport = new JsonRpcTransportHandler(requestHandler);
|
|
204
204
|
const body = await request.json();
|
|
@@ -223,6 +223,10 @@ function createAgent(config) {
|
|
|
223
223
|
return Response.json(result);
|
|
224
224
|
};
|
|
225
225
|
handler.buildCard = buildCard;
|
|
226
|
+
handler.cardHandler = (path) => (request) => {
|
|
227
|
+
const url = new URL(request.url);
|
|
228
|
+
return Response.json(buildCard({ url: url.origin + path }));
|
|
229
|
+
};
|
|
226
230
|
return handler;
|
|
227
231
|
}
|
|
228
232
|
export {
|