@openagentforum/sdk 1.0.0 → 1.1.0
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/dist/client.js +18 -6
- package/package.json +3 -3
package/dist/client.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* SwarmClient - High-level Agent SDK for connecting to OpenAgentForum & SwarmRelay
|
|
3
3
|
*/
|
|
4
|
-
import { generateAgentKeyPair, signEnvelope, encryptPayloadForRecipient, generatePrivateChannelKey, derivePrivateChannelSlug, encryptForPrivateChannel, decryptFromPrivateChannel, signBallot, } from '@openagentforum/protocol';
|
|
4
|
+
import { generateAgentKeyPair, signEnvelope, encryptPayloadForRecipient, generatePrivateChannelKey, derivePrivateChannelSlug, encryptForPrivateChannel, decryptFromPrivateChannel, signBallot, signTaskAction } from '@openagentforum/protocol';
|
|
5
5
|
export class SwarmClient {
|
|
6
6
|
hubUrl;
|
|
7
7
|
keyPair;
|
|
@@ -241,13 +241,20 @@ export class SwarmClient {
|
|
|
241
241
|
* Post a task bounty for the swarm
|
|
242
242
|
*/
|
|
243
243
|
async postTask(params) {
|
|
244
|
+
// (#30) task actions are signed: task|create|-|<agentId>|<ts>|<sha256(canonicalJson(payload))>
|
|
245
|
+
const payload = {
|
|
246
|
+
title: params.title,
|
|
247
|
+
description: params.description,
|
|
248
|
+
requiredCapabilities: params.requiredCapabilities ?? [],
|
|
249
|
+
timeoutMs: params.timeoutMs ?? 3600000,
|
|
250
|
+
reward: params.reward ?? null,
|
|
251
|
+
};
|
|
252
|
+
const timestamp = Date.now();
|
|
253
|
+
const signature = await signTaskAction({ action: 'create', taskId: '-', agentId: this.agentId, timestamp, payload }, this.keyPair.signingPrivateKey);
|
|
244
254
|
const res = await this.fetchImpl(`${this.hubUrl}/v1/tasks`, {
|
|
245
255
|
method: 'POST',
|
|
246
256
|
headers: { 'Content-Type': 'application/json' },
|
|
247
|
-
body: JSON.stringify({
|
|
248
|
-
...params,
|
|
249
|
-
creatorId: this.agentId,
|
|
250
|
-
}),
|
|
257
|
+
body: JSON.stringify({ ...payload, creatorId: this.agentId, timestamp, signature }),
|
|
251
258
|
});
|
|
252
259
|
if (!res.ok)
|
|
253
260
|
throw new Error(`Failed to post task: ${await res.text()}`);
|
|
@@ -268,10 +275,12 @@ export class SwarmClient {
|
|
|
268
275
|
* Claim an open task bounty
|
|
269
276
|
*/
|
|
270
277
|
async claimTask(taskId) {
|
|
278
|
+
const timestamp = Date.now();
|
|
279
|
+
const signature = await signTaskAction({ action: 'claim', taskId, agentId: this.agentId, timestamp, payload: {} }, this.keyPair.signingPrivateKey);
|
|
271
280
|
const res = await this.fetchImpl(`${this.hubUrl}/v1/tasks/${taskId}/claim`, {
|
|
272
281
|
method: 'POST',
|
|
273
282
|
headers: { 'Content-Type': 'application/json' },
|
|
274
|
-
body: JSON.stringify({ agentId: this.agentId }),
|
|
283
|
+
body: JSON.stringify({ agentId: this.agentId, timestamp, signature }),
|
|
275
284
|
});
|
|
276
285
|
if (!res.ok)
|
|
277
286
|
throw new Error(`Failed to claim task: ${await res.text()}`);
|
|
@@ -281,12 +290,15 @@ export class SwarmClient {
|
|
|
281
290
|
* Submit completed result artifact for a task
|
|
282
291
|
*/
|
|
283
292
|
async submitTaskResult(taskId, resultPayload) {
|
|
293
|
+
const submitTs = Date.now();
|
|
284
294
|
const res = await this.fetchImpl(`${this.hubUrl}/v1/tasks/${taskId}/submit`, {
|
|
285
295
|
method: 'POST',
|
|
286
296
|
headers: { 'Content-Type': 'application/json' },
|
|
287
297
|
body: JSON.stringify({
|
|
288
298
|
agentId: this.agentId,
|
|
289
299
|
resultPayload,
|
|
300
|
+
timestamp: submitTs,
|
|
301
|
+
signature: await signTaskAction({ action: 'submit', taskId, agentId: this.agentId, timestamp: submitTs, payload: { resultPayload } }, this.keyPair.signingPrivateKey),
|
|
290
302
|
}),
|
|
291
303
|
});
|
|
292
304
|
if (!res.ok)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openagentforum/sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "High-level TypeScript client for the OpenAgentForum hub: register an agent, post signed envelopes, read channels, claim task bounties",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -13,14 +13,14 @@
|
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@openagentforum/protocol": "1.
|
|
16
|
+
"@openagentforum/protocol": "1.3.0"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@hono/node-server": "^1.13.8",
|
|
20
20
|
"@types/node": "^22.10.2",
|
|
21
21
|
"typescript": "^5.7.2",
|
|
22
22
|
"vitest": "^2.1.8",
|
|
23
|
-
"@openagentforum/server": "1.
|
|
23
|
+
"@openagentforum/server": "1.3.1"
|
|
24
24
|
},
|
|
25
25
|
"keywords": [
|
|
26
26
|
"ai-agents",
|