Skip to content

Commit dbc27b5

Browse files
committed
docs(acp-server): add advanced client example
Extended packages/acp-server/README.md with a richer client sample that lists agents, creates a session, requests structured output, and streams NDJSON frames from the ACP server.
1 parent ff4385f commit dbc27b5

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

packages/acp-server/README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,65 @@ The e2e script launches the server, waits for readiness, then runs `client/src/t
4141
1. Calls `GET /api/acp/agents`
4242
2. Validates that at least one agent is available
4343

44+
### “Interesting” client example
45+
Below is a minimal Node client (can live anywhere) that:
46+
1. Lists agents.
47+
2. Creates a session for the first provider.
48+
3. Sends a prompt requesting structured JSON output.
49+
4. Streams NDJSON frames and prints them as they arrive.
50+
51+
```ts
52+
import fetch from 'node-fetch';
53+
54+
const BASE_URL = process.env.ACP_BASE_URL ?? 'http://localhost:8000';
55+
const headers = process.env.ACP_TOKEN
56+
? { Authorization: `Bearer ${process.env.ACP_TOKEN}`, 'Content-Type': 'application/json' }
57+
: { 'Content-Type': 'application/json' };
58+
59+
async function main() {
60+
const agentsRes = await fetch(`${BASE_URL}/api/acp/agents`, { headers });
61+
const agents = (await agentsRes.json()).agents;
62+
const provider = agents[0].id;
63+
64+
const sessionRes = await fetch(`${BASE_URL}/api/acp/sessions`, {
65+
method: 'POST',
66+
headers,
67+
body: JSON.stringify({ provider }),
68+
});
69+
const { sessionId } = await sessionRes.json();
70+
71+
const schema = {
72+
type: 'object',
73+
properties: {
74+
summary: { type: 'string' },
75+
risks: { type: 'array', items: { type: 'string' }, minItems: 1 },
76+
},
77+
required: ['summary', 'risks'],
78+
};
79+
80+
const response = await fetch(`${BASE_URL}/api/acp/messages?stream=true`, {
81+
method: 'POST',
82+
headers,
83+
body: JSON.stringify({
84+
sessionId,
85+
content: 'Review the latest commit and explain top risks.',
86+
outputSchema: schema,
87+
}),
88+
});
89+
90+
const reader = response.body!.getReader();
91+
const decoder = new TextDecoder();
92+
while (true) {
93+
const { done, value } = await reader.read();
94+
if (done) break;
95+
process.stdout.write(decoder.decode(value));
96+
}
97+
}
98+
99+
main().catch(err => {
100+
console.error('Client failed', err);
101+
process.exit(1);
102+
});
103+
```
104+
44105
Feel free to expand the client to create sessions, send prompts, and consume streamed NDJSON frames using the same APIs demonstrated in the script.

0 commit comments

Comments
 (0)