Skip to content
Merged
9 changes: 8 additions & 1 deletion src/client/multitransport-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,17 @@ export interface RequestOptions {
export class Client {
constructor(
public readonly transport: Transport,
public readonly agentCard: AgentCard,
public agentCard: AgentCard,
Comment thread
guglielmo-san marked this conversation as resolved.
Outdated
public readonly config?: ClientConfig
) {}

async getAgentCard(): Promise<AgentCard> {
if (this.agentCard.supportsAuthenticatedExtendedCard) {
this.agentCard = await this.transport.getAuthenticatedExtendedAgentCard();
}
return this.agentCard;
}
Comment thread
guglielmo-san marked this conversation as resolved.
Outdated

/**
* Sends a message to an agent to initiate a new interaction or to continue an existing one.
* Uses blocking mode by default.
Expand Down
9 changes: 9 additions & 0 deletions src/client/transports/json_rpc_transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
CancelTaskSuccessResponse,
AgentCard,
GetTaskPushNotificationConfigParams,
GetAuthenticatedExtendedCardSuccessResponse,
} from '../../types.js';
import { A2AStreamEventData, SendMessageResult } from '../client.js';
import { RequestOptions } from '../multitransport-client.js';
Expand All @@ -48,6 +49,14 @@ export class JsonRpcTransport implements Transport {
this.customFetchImpl = options.fetchImpl;
}

async getAuthenticatedExtendedAgentCard(idOverride?: number): Promise<AgentCard> {
const rpcResponse = await this._sendRpcRequest<
unknown,
GetAuthenticatedExtendedCardSuccessResponse
>('agent/getAuthenticatedExtendedCard', {}, idOverride, undefined);
return rpcResponse.result;
}

async sendMessage(
params: MessageSendParams,
options?: RequestOptions,
Expand Down
2 changes: 2 additions & 0 deletions src/client/transports/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { A2AStreamEventData, SendMessageResult } from '../client.js';
import { RequestOptions } from '../multitransport-client.js';

export interface Transport {
getAuthenticatedExtendedAgentCard(): Promise<AgentCard>;

sendMessage(params: MessageSendParams, options?: RequestOptions): Promise<SendMessageResult>;

sendMessageStream(
Expand Down
1 change: 1 addition & 0 deletions test/client/factory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe('ClientFactory', () => {

beforeEach(() => {
mockTransport = {
getAuthenticatedExtendedAgentCard: sinon.stub(),
sendMessage: sinon.stub(),
sendMessageStream: sinon.stub(),
setTaskPushNotificationConfig: sinon.stub(),
Expand Down
16 changes: 16 additions & 0 deletions test/client/multitransport-client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe('Client', () => {

beforeEach(() => {
transport = {
getAuthenticatedExtendedAgentCard: sinon.stub(),
sendMessage: sinon.stub(),
sendMessageStream: sinon.stub(),
setTaskPushNotificationConfig: sinon.stub(),
Expand Down Expand Up @@ -53,6 +54,21 @@ describe('Client', () => {
client = new Client(transport, agentCard);
});

it('should call transport.getAuthenticatedExtendedAgentCard', async () => {
const agentCardWithExtendedSupport = { ...agentCard, supportsAuthenticatedExtendedCard: true };
const extendedAgentCard: AgentCard = {
...agentCard,
capabilities: { ...agentCard.capabilities, stateTransitionHistory: true },
};
client = new Client(transport, agentCardWithExtendedSupport);

transport.getAuthenticatedExtendedAgentCard.resolves(extendedAgentCard);
const result = await client.getAgentCard();

expect(transport.getAuthenticatedExtendedAgentCard.calledOnce).to.be.true;
expect(result).to.equal(extendedAgentCard);
});
Comment thread
guglielmo-san marked this conversation as resolved.

it('should call transport.sendMessage with default blocking=true', async () => {
const params: MessageSendParams = {
message: {
Expand Down
Loading