@artinet/sdk 0.5.13 → 0.5.14
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 +3 -2
- package/dist/client/a2a-client.d.ts +10 -0
- package/dist/client/a2a-client.js +20 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -66,8 +66,9 @@ It has [serveral template projects](https://github.com/the-artinet-project/creat
|
|
|
66
66
|
- AgentBuilder now prefers the contextId & taskId from the calling context.
|
|
67
67
|
- In a future release the following packages will be set as peer dependancies to reduce the size of the build: `@modelcontextprotocol/sdk`, `@trpc/server`, `cors`, `express`
|
|
68
68
|
- The `history` object from `TaskAndHistory` is deprecated and no longer being updated. Use `Task.history` instead.
|
|
69
|
-
- The A2AClient now checks `/.well-known/agent-card.json` as a opposed to `/.well-known/agent.json` in-line with the A2A spec.
|
|
70
|
-
- The
|
|
69
|
+
- The `A2AClient` now checks `/.well-known/agent-card.json` as a opposed to `/.well-known/agent.json` in-line with the A2A spec.
|
|
70
|
+
- The `A2AClient` now uses uses the `AgentCard`.url if an `AgentCard` has been successfully retrieved, else it will default to the `baseUrl`.
|
|
71
|
+
- The examples folder will be removed in favor of [`create-agent`](https://github.com/the-artinet-project/create-agent).
|
|
71
72
|
|
|
72
73
|
## Installation
|
|
73
74
|
|
|
@@ -13,10 +13,20 @@ export declare class A2AClient implements Client {
|
|
|
13
13
|
private cachedAgentCard;
|
|
14
14
|
private customHeaders;
|
|
15
15
|
private fallbackPath;
|
|
16
|
+
private agentUrl;
|
|
16
17
|
/**
|
|
17
18
|
* Creates a new A2AClient instance.
|
|
18
19
|
* @param baseUrl The base URL for the A2A server.
|
|
19
20
|
* @param headers Optional custom headers to include in all requests.
|
|
21
|
+
* @param fallbackPath Optional fallback path to use if the agent card is not found at the base URL.
|
|
22
|
+
* @example
|
|
23
|
+
* const client = new A2AClient("http://localhost:4000/a2a");
|
|
24
|
+
* const card = await client.agentCard();
|
|
25
|
+
* console.log(card);
|
|
26
|
+
* @example
|
|
27
|
+
* const client = new A2AClient("http://localhost:4000/a2a", {}, "/agent-card");
|
|
28
|
+
* const card = await client.agentCard();
|
|
29
|
+
* console.log(card);
|
|
20
30
|
*/
|
|
21
31
|
constructor(baseUrl: URL | string, headers?: Record<string, string>, fallbackPath?: string);
|
|
22
32
|
/**
|
|
@@ -15,15 +15,26 @@ export class A2AClient {
|
|
|
15
15
|
cachedAgentCard = null;
|
|
16
16
|
customHeaders = {};
|
|
17
17
|
fallbackPath;
|
|
18
|
+
agentUrl;
|
|
18
19
|
/**
|
|
19
20
|
* Creates a new A2AClient instance.
|
|
20
21
|
* @param baseUrl The base URL for the A2A server.
|
|
21
22
|
* @param headers Optional custom headers to include in all requests.
|
|
23
|
+
* @param fallbackPath Optional fallback path to use if the agent card is not found at the base URL.
|
|
24
|
+
* @example
|
|
25
|
+
* const client = new A2AClient("http://localhost:4000/a2a");
|
|
26
|
+
* const card = await client.agentCard();
|
|
27
|
+
* console.log(card);
|
|
28
|
+
* @example
|
|
29
|
+
* const client = new A2AClient("http://localhost:4000/a2a", {}, "/agent-card");
|
|
30
|
+
* const card = await client.agentCard();
|
|
31
|
+
* console.log(card);
|
|
22
32
|
*/
|
|
23
33
|
constructor(baseUrl, headers = {}, fallbackPath) {
|
|
24
34
|
this.baseUrl = typeof baseUrl === "string" ? new URL(baseUrl) : baseUrl;
|
|
25
35
|
this.customHeaders = headers;
|
|
26
36
|
this.fallbackPath = fallbackPath ?? "/agent-card";
|
|
37
|
+
this.agentUrl = this.baseUrl;
|
|
27
38
|
}
|
|
28
39
|
/**
|
|
29
40
|
* Retrieves the AgentCard from the A2A server.
|
|
@@ -46,7 +57,6 @@ export class A2AClient {
|
|
|
46
57
|
throw new Error("No agent card found");
|
|
47
58
|
}
|
|
48
59
|
this.cachedAgentCard = card;
|
|
49
|
-
return this.cachedAgentCard;
|
|
50
60
|
}
|
|
51
61
|
catch (error) {
|
|
52
62
|
const fallbackUrl = new URL(this.fallbackPath, this.baseUrl);
|
|
@@ -57,13 +67,14 @@ export class A2AClient {
|
|
|
57
67
|
throw new Error("No fallback agent card found");
|
|
58
68
|
}
|
|
59
69
|
this.cachedAgentCard = fallbackCard;
|
|
60
|
-
return this.cachedAgentCard;
|
|
61
70
|
}
|
|
62
71
|
}
|
|
63
72
|
catch (error) {
|
|
64
73
|
logError("A2AClient:agentCard", "Failed to fetch or parse agent card:", error);
|
|
65
74
|
throw INTERNAL_ERROR(`Could not retrieve agent card: ${error instanceof Error ? error.message : String(error)}`);
|
|
66
75
|
}
|
|
76
|
+
this.agentUrl = new URL(this.cachedAgentCard.url, this.baseUrl);
|
|
77
|
+
return this.cachedAgentCard;
|
|
67
78
|
}
|
|
68
79
|
/**
|
|
69
80
|
* Refreshes the cached AgentCard by fetching it again from the server.
|
|
@@ -79,7 +90,7 @@ export class A2AClient {
|
|
|
79
90
|
* @returns A promise resolving to Message/Task response from the agent server or null.
|
|
80
91
|
*/
|
|
81
92
|
async sendMessage(params) {
|
|
82
|
-
return await executeJsonRpcRequest(this.
|
|
93
|
+
return await executeJsonRpcRequest(this.agentUrl, "message/send", createMessageSendParams(params), this.customHeaders);
|
|
83
94
|
}
|
|
84
95
|
/**
|
|
85
96
|
* @deprecated Use sendMessage instead.
|
|
@@ -96,7 +107,7 @@ export class A2AClient {
|
|
|
96
107
|
* @returns An AsyncIterable that yields TaskStatusUpdateEvent/TaskArtifactUpdateEvent/Task/Message payloads.
|
|
97
108
|
*/
|
|
98
109
|
sendStreamingMessage(params) {
|
|
99
|
-
return executeStreamEvents(this.
|
|
110
|
+
return executeStreamEvents(this.agentUrl, "message/stream", createMessageSendParams(params), this.customHeaders);
|
|
100
111
|
}
|
|
101
112
|
/**
|
|
102
113
|
* @deprecated Use sendStreamingMessage instead.
|
|
@@ -113,7 +124,7 @@ export class A2AClient {
|
|
|
113
124
|
* @returns A promise resolving to the Task object or null.
|
|
114
125
|
*/
|
|
115
126
|
async getTask(params) {
|
|
116
|
-
return await executeJsonRpcRequest(this.
|
|
127
|
+
return await executeJsonRpcRequest(this.agentUrl, "tasks/get", params, this.customHeaders);
|
|
117
128
|
}
|
|
118
129
|
/**
|
|
119
130
|
* Cancels a currently running task.
|
|
@@ -121,7 +132,7 @@ export class A2AClient {
|
|
|
121
132
|
* @returns A promise resolving to the updated Task object (usually canceled state) or null.
|
|
122
133
|
*/
|
|
123
134
|
async cancelTask(params) {
|
|
124
|
-
return await executeJsonRpcRequest(this.
|
|
135
|
+
return await executeJsonRpcRequest(this.agentUrl, "tasks/cancel", params, this.customHeaders);
|
|
125
136
|
}
|
|
126
137
|
/**
|
|
127
138
|
* Sets or updates the push notification config for a task.
|
|
@@ -129,7 +140,7 @@ export class A2AClient {
|
|
|
129
140
|
* @returns A promise resolving to the confirmed TaskPushNotificationConfig or null.
|
|
130
141
|
*/
|
|
131
142
|
async setTaskPushNotification(params) {
|
|
132
|
-
return await executeJsonRpcRequest(this.
|
|
143
|
+
return await executeJsonRpcRequest(this.agentUrl, "tasks/pushNotificationConfig/set", params, this.customHeaders);
|
|
133
144
|
}
|
|
134
145
|
/**
|
|
135
146
|
* Retrieves the currently configured push notification config for a task.
|
|
@@ -137,7 +148,7 @@ export class A2AClient {
|
|
|
137
148
|
* @returns A promise resolving to the TaskPushNotificationConfig or null.
|
|
138
149
|
*/
|
|
139
150
|
async getTaskPushNotification(params) {
|
|
140
|
-
return await executeJsonRpcRequest(this.
|
|
151
|
+
return await executeJsonRpcRequest(this.agentUrl, "tasks/pushNotificationConfig/get", params, this.customHeaders);
|
|
141
152
|
}
|
|
142
153
|
/**
|
|
143
154
|
* Resubscribes to an existing task's update stream.
|
|
@@ -145,7 +156,7 @@ export class A2AClient {
|
|
|
145
156
|
* @returns An AsyncIterable that yields TaskStatusUpdateEvent or TaskArtifactUpdateEvent payloads.
|
|
146
157
|
*/
|
|
147
158
|
resubscribeTask(params) {
|
|
148
|
-
return executeStreamEvents(this.
|
|
159
|
+
return executeStreamEvents(this.agentUrl, "tasks/resubscribe", params, this.customHeaders);
|
|
149
160
|
}
|
|
150
161
|
/**
|
|
151
162
|
* Checks if the server supports a specific capability based on the agent card.
|