forked from a2aproject/a2a-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA2AClientExtensions.cs
More file actions
132 lines (120 loc) · 4.14 KB
/
A2AClientExtensions.cs
File metadata and controls
132 lines (120 loc) · 4.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
using System.Net.ServerSentEvents;
using System.Text.Json;
namespace A2A;
/// <summary>
/// Extension methods for the <see cref="A2AClient"/> class making its API more
/// convenient for certain use-cases.
/// </summary>
public static class A2AClientExtensions
{
/// <inheritdoc cref="A2AClient.SendMessageAsync(MessageSendParams, CancellationToken)"/>
public static Task<A2AResponse> SendMessageAsync(
this A2AClient client,
Message message,
MessageSendConfiguration? configuration = null,
Dictionary<string, JsonElement>? metadata = null,
CancellationToken cancellationToken = default)
{
if (client is null)
{
throw new ArgumentNullException(nameof(client));
}
return client.SendMessageAsync(
new MessageSendParams
{
Message = message,
Configuration = configuration,
Metadata = metadata
},
cancellationToken);
}
/// <inheritdoc cref="A2AClient.CancelTaskAsync(TaskIdParams, CancellationToken)"/>
public static Task<AgentTask> CancelTaskAsync(
this A2AClient client,
string taskId,
Dictionary<string, JsonElement>? metadata = null,
CancellationToken cancellationToken = default)
{
if (client is null)
{
throw new ArgumentNullException(nameof(client));
}
return client.CancelTaskAsync(
new TaskIdParams
{
Id = taskId,
Metadata = metadata
},
cancellationToken);
}
/// <inheritdoc cref="A2AClient.SetPushNotificationAsync(TaskPushNotificationConfig, CancellationToken)"/>
public static Task<TaskPushNotificationConfig> SetPushNotificationAsync(
this A2AClient client,
string taskId,
string url,
string? configId = null,
string? token = null,
PushNotificationAuthenticationInfo? authentication = null,
CancellationToken cancellationToken = default)
{
if (client is null)
{
throw new ArgumentNullException(nameof(client));
}
return client.SetPushNotificationAsync(
new TaskPushNotificationConfig
{
TaskId = taskId,
PushNotificationConfig = new PushNotificationConfig
{
Id = configId,
Url = url,
Token = token,
Authentication = authentication
}
},
cancellationToken);
}
/// <inheritdoc cref="A2AClient.GetPushNotificationAsync(GetTaskPushNotificationConfigParams, CancellationToken)"/>
public static Task<TaskPushNotificationConfig> GetPushNotificationAsync(
this A2AClient client,
string taskId,
string configId,
Dictionary<string, JsonElement>? metadata = null,
CancellationToken cancellationToken = default)
{
if (client is null)
{
throw new ArgumentNullException(nameof(client));
}
return client.GetPushNotificationAsync(
new GetTaskPushNotificationConfigParams
{
Id = taskId,
PushNotificationConfigId = configId,
Metadata = metadata
},
cancellationToken);
}
/// <inheritdoc cref="A2AClient.SendMessageStreamingAsync(MessageSendParams, CancellationToken)"/>
public static IAsyncEnumerable<SseItem<A2AEvent>> SendMessageStreamingAsync(
this A2AClient client,
Message message,
MessageSendConfiguration? configuration = null,
Dictionary<string, JsonElement>? metadata = null,
CancellationToken cancellationToken = default)
{
if (client is null)
{
throw new ArgumentNullException(nameof(client));
}
return client.SendMessageStreamingAsync(
new MessageSendParams
{
Message = message,
Configuration = configuration,
Metadata = metadata
},
cancellationToken);
}
}