Skip to content

Commit 4ad73c1

Browse files
refactor: rename ClientFactory.createFromAgentCardUrl -> createFromUrl (#242)
# Description `createFromAgentCardUrl` may give a wrong impression that full URL has to be provided, rename and add examples. Not yet released, `AgentCardResolver` and the method were added in #225. --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent 1ca8c8b commit 4ad73c1

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/client/factory.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,18 @@ export class ClientFactory {
136136
/**
137137
* Downloads agent card using AgentCardResolver from options
138138
* and creates a new client from the downloaded card.
139+
*
140+
* @example
141+
* ```ts
142+
* const factory = new ClientFactory(); // use default options and default {@link AgentCardResolver}.
143+
* const client1 = await factory.createFromUrl('https://example.com'); // /.well-known/agent-card.json is used by default
144+
* const client2 = await factory.createFromUrl('https://example.com', '/my-agent-card.json'); // specify custom path
145+
* const client3 = await factory.createFromUrl('https://example.com/my-agent-card.json', ''); // specify full URL and set path to empty
146+
* ```
139147
*/
140-
async createFromAgentCardUrl(baseUrl: string, path?: string): Promise<Client> {
148+
async createFromUrl(baseUrl: string, path?: string): Promise<Client> {
141149
const agentCard = await this.agentCardResolver.resolve(baseUrl, path);
142-
return await this.createFromAgentCard(agentCard);
150+
return this.createFromAgentCard(agentCard);
143151
}
144152
}
145153

test/client/factory.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ describe('ClientFactory', () => {
172172
cardResolver,
173173
});
174174

175-
await factory.createFromAgentCardUrl('http://transport1.com');
175+
await factory.createFromUrl('http://transport1.com');
176176

177177
expect(mockTransportFactory1.create.calledOnce);
178178
expect(cardResolver.resolve.calledOnceWith('http://transport1.com')).to.be.true;
@@ -187,7 +187,7 @@ describe('ClientFactory', () => {
187187
cardResolver,
188188
});
189189

190-
await factory.createFromAgentCardUrl('http://transport1.com', 'a2a/my-agent-card.json');
190+
await factory.createFromUrl('http://transport1.com', 'a2a/my-agent-card.json');
191191

192192
expect(mockTransportFactory1.create.calledOnce);
193193
expect(cardResolver.resolve.calledOnceWith('http://transport1.com', 'a2a/my-agent-card.json'))

0 commit comments

Comments
 (0)