@bountyagents/bountyagents-task 2026.2.279 → 2026.2.2711
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/index.js +127 -0
- package/index.ts +3 -1
- package/package.json +1 -1
- package/src/index.ts +20 -4
- package/src/worker.ts +60 -0
- package/test-worker.ts +25 -0
- /package/{test-plugin.ts → test-publisher.ts} +0 -0
package/dist/index.js
CHANGED
|
@@ -55176,6 +55176,12 @@ var taskFundSignaturePayload = (input) => canonicalStringify({
|
|
|
55176
55176
|
taskId: input.taskId,
|
|
55177
55177
|
token: input.token
|
|
55178
55178
|
});
|
|
55179
|
+
var responseSignaturePayload = (input) => canonicalStringify({
|
|
55180
|
+
kind: "task:response",
|
|
55181
|
+
taskId: input.taskId,
|
|
55182
|
+
payload: input.payload,
|
|
55183
|
+
id: input.id ?? null
|
|
55184
|
+
});
|
|
55179
55185
|
var decisionSignaturePayload = (input) => canonicalStringify({
|
|
55180
55186
|
kind: "task:decision",
|
|
55181
55187
|
responseId: input.responseId,
|
|
@@ -55188,6 +55194,12 @@ var cancelTaskSignaturePayload = (input) => canonicalStringify({
|
|
|
55188
55194
|
kind: "task:cancel",
|
|
55189
55195
|
taskId: input.taskId
|
|
55190
55196
|
});
|
|
55197
|
+
var taskSettleSignaturePayload = (input) => canonicalStringify({
|
|
55198
|
+
kind: "task:settle",
|
|
55199
|
+
taskId: input.taskId,
|
|
55200
|
+
responseId: input.responseId,
|
|
55201
|
+
workerAddress: input.workerAddress
|
|
55202
|
+
});
|
|
55191
55203
|
var taskResponsesQuerySignaturePayload = (input) => canonicalStringify({
|
|
55192
55204
|
kind: "task:response:query",
|
|
55193
55205
|
taskId: input.taskId,
|
|
@@ -55196,6 +55208,13 @@ var taskResponsesQuerySignaturePayload = (input) => canonicalStringify({
|
|
|
55196
55208
|
pageSize: input.pageSize ?? 50,
|
|
55197
55209
|
pageNum: input.pageNum ?? 0
|
|
55198
55210
|
});
|
|
55211
|
+
var workerResponsesQuerySignaturePayload = (input) => canonicalStringify({
|
|
55212
|
+
kind: "worker:response:query",
|
|
55213
|
+
workerAddress: input.workerAddress,
|
|
55214
|
+
taskId: input.taskId ?? null,
|
|
55215
|
+
pageSize: input.pageSize ?? 50,
|
|
55216
|
+
pageNum: input.pageNum ?? 0
|
|
55217
|
+
});
|
|
55199
55218
|
|
|
55200
55219
|
// src/token.ts
|
|
55201
55220
|
var parseTokenIdentifier = (token) => {
|
|
@@ -55389,6 +55408,65 @@ class BountyAgentsPublisherPlugin extends BaseBountyPlugin {
|
|
|
55389
55408
|
}
|
|
55390
55409
|
}
|
|
55391
55410
|
|
|
55411
|
+
class BountyAgentsWorkerPlugin extends BaseBountyPlugin {
|
|
55412
|
+
constructor(signer, options) {
|
|
55413
|
+
super(signer, options);
|
|
55414
|
+
this.registerTool("bountyagents.worker.task.respond", "Submit a response for an active task", submitResponsePayloadSchema, (input) => this.submitResponse(input));
|
|
55415
|
+
this.registerTool("bountyagents.worker.response.query", "List responses submitted by this worker", workerResponsesQueryPayloadSchema, (input) => this.queryWorkerResponses(input));
|
|
55416
|
+
this.registerTool("bountyagents.worker.task.query", "Search tasks with keyword, publisher and price filters", taskQueryPayloadSchema, (input) => this.queryTasks(input));
|
|
55417
|
+
}
|
|
55418
|
+
async queryTasks(payload) {
|
|
55419
|
+
const canonicalFilter = payload.filter ?? {};
|
|
55420
|
+
const pageSize = payload.pageSize ?? 50;
|
|
55421
|
+
const pageNum = payload.pageNum ?? 0;
|
|
55422
|
+
const body = {
|
|
55423
|
+
filter: canonicalFilter,
|
|
55424
|
+
sortBy: payload.sortBy ?? "created_at",
|
|
55425
|
+
pageSize,
|
|
55426
|
+
pageNum
|
|
55427
|
+
};
|
|
55428
|
+
const response = await this.request("/tasks/query", body);
|
|
55429
|
+
return tasksListSchema.parse(response).tasks;
|
|
55430
|
+
}
|
|
55431
|
+
async submitResponse(payload) {
|
|
55432
|
+
const body = {
|
|
55433
|
+
...payload,
|
|
55434
|
+
workerAddress: this.signer.address,
|
|
55435
|
+
signature: await this.signPayload(responseSignaturePayload(payload))
|
|
55436
|
+
};
|
|
55437
|
+
const response = await this.request(`/tasks/${payload.taskId}/responses`, body);
|
|
55438
|
+
return submissionResponseSchema.parse(response).response;
|
|
55439
|
+
}
|
|
55440
|
+
async queryWorkerResponses(payload) {
|
|
55441
|
+
const pageSize = payload.pageSize ?? 50;
|
|
55442
|
+
const pageNum = payload.pageNum ?? 0;
|
|
55443
|
+
const canonicalPayload = {
|
|
55444
|
+
taskId: payload.taskId,
|
|
55445
|
+
pageSize,
|
|
55446
|
+
pageNum
|
|
55447
|
+
};
|
|
55448
|
+
const body = {
|
|
55449
|
+
...canonicalPayload,
|
|
55450
|
+
workerAddress: this.signer.address,
|
|
55451
|
+
signature: await this.signPayload(workerResponsesQuerySignaturePayload({
|
|
55452
|
+
...canonicalPayload,
|
|
55453
|
+
workerAddress: this.signer.address
|
|
55454
|
+
}))
|
|
55455
|
+
};
|
|
55456
|
+
const response = await this.request("/workers/responses/query", body);
|
|
55457
|
+
return responsesListSchema.parse(response).responses;
|
|
55458
|
+
}
|
|
55459
|
+
async settleTask(payload) {
|
|
55460
|
+
const canonicalPayload = { ...payload, workerAddress: this.signer.address };
|
|
55461
|
+
const body = {
|
|
55462
|
+
...canonicalPayload,
|
|
55463
|
+
signature: await this.signPayload(taskSettleSignaturePayload(canonicalPayload))
|
|
55464
|
+
};
|
|
55465
|
+
const response = await this.request(`/tasks/${payload.taskId}/settle`, body);
|
|
55466
|
+
return settleResponseSchema.parse(response);
|
|
55467
|
+
}
|
|
55468
|
+
}
|
|
55469
|
+
|
|
55392
55470
|
// src/signers.ts
|
|
55393
55471
|
class PrivateKeySigner {
|
|
55394
55472
|
account;
|
|
@@ -55610,9 +55688,58 @@ function registerPublisherTools(api3) {
|
|
|
55610
55688
|
});
|
|
55611
55689
|
}
|
|
55612
55690
|
|
|
55691
|
+
// src/worker.ts
|
|
55692
|
+
var SERVICE_URL2 = "http://localhost:3000";
|
|
55693
|
+
var CONTRACT_ADDRESS2 = "0x55D45aFA265d0381C8A81328FfeA408D2Dd45F40";
|
|
55694
|
+
var PRIVATE_KEY2 = "0x289f92dd30c36ff24b75b48623c70dea2b428dabac7a52c5ca810bcda64d861b";
|
|
55695
|
+
async function getAvailableTask(params) {
|
|
55696
|
+
const signer = new PrivateKeySigner(PRIVATE_KEY2);
|
|
55697
|
+
const plugin = new BountyAgentsWorkerPlugin(signer, {
|
|
55698
|
+
serviceUrl: SERVICE_URL2,
|
|
55699
|
+
contractAddress: CONTRACT_ADDRESS2
|
|
55700
|
+
});
|
|
55701
|
+
const tasks = await plugin.executeTool("bountyagents.worker.task.query", {
|
|
55702
|
+
filter: {
|
|
55703
|
+
status: "active"
|
|
55704
|
+
},
|
|
55705
|
+
pageSize: params.pageSize,
|
|
55706
|
+
pageNum: params.pageNum
|
|
55707
|
+
});
|
|
55708
|
+
if (tasks.length === 0) {
|
|
55709
|
+
return null;
|
|
55710
|
+
}
|
|
55711
|
+
return tasks[0];
|
|
55712
|
+
}
|
|
55713
|
+
function registerWorkerTools(api3) {
|
|
55714
|
+
api3.registerTool({
|
|
55715
|
+
name: "get_available_task",
|
|
55716
|
+
description: "Get available active bounty task for the worker to work on and respond to.",
|
|
55717
|
+
parameters: Type.Object({
|
|
55718
|
+
pageSize: Type.Optional(Type.Number()),
|
|
55719
|
+
pageNum: Type.Optional(Type.Number()),
|
|
55720
|
+
keyword: Type.Optional(Type.String())
|
|
55721
|
+
}),
|
|
55722
|
+
async execute(_id, params) {
|
|
55723
|
+
try {
|
|
55724
|
+
const result = await getAvailableTask({
|
|
55725
|
+
pageSize: params.pageSize,
|
|
55726
|
+
pageNum: params.pageNum,
|
|
55727
|
+
keyword: ""
|
|
55728
|
+
});
|
|
55729
|
+
return json(result);
|
|
55730
|
+
} catch (error48) {
|
|
55731
|
+
return json({
|
|
55732
|
+
error: error48 instanceof Error ? error48.message : String(error48)
|
|
55733
|
+
});
|
|
55734
|
+
}
|
|
55735
|
+
}
|
|
55736
|
+
});
|
|
55737
|
+
}
|
|
55738
|
+
|
|
55613
55739
|
// index.ts
|
|
55614
55740
|
function register(api3) {
|
|
55615
55741
|
registerPublisherTools(api3);
|
|
55742
|
+
registerWorkerTools(api3);
|
|
55616
55743
|
}
|
|
55617
55744
|
export {
|
|
55618
55745
|
register as default
|
package/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { registerPublisherTools } from "./src/publisher.js";
|
|
2
|
+
import { registerWorkerTools } from "./src/worker.js";
|
|
2
3
|
|
|
3
4
|
export default function register(api: any) {
|
|
4
5
|
// api.registerCommand({
|
|
@@ -47,5 +48,6 @@ export default function register(api: any) {
|
|
|
47
48
|
// },
|
|
48
49
|
// });
|
|
49
50
|
|
|
50
|
-
|
|
51
|
+
registerPublisherTools(api);
|
|
52
|
+
registerWorkerTools(api);
|
|
51
53
|
}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -343,13 +343,29 @@ export class BountyAgentsWorkerPlugin extends BaseBountyPlugin {
|
|
|
343
343
|
(input) => this.queryWorkerResponses(input)
|
|
344
344
|
);
|
|
345
345
|
this.registerTool(
|
|
346
|
-
"bountyagents.worker.task.
|
|
347
|
-
"
|
|
348
|
-
|
|
349
|
-
(input) => this.
|
|
346
|
+
"bountyagents.worker.task.query",
|
|
347
|
+
"Search tasks with keyword, publisher and price filters",
|
|
348
|
+
taskQueryPayloadSchema,
|
|
349
|
+
(input) => this.queryTasks(input)
|
|
350
350
|
);
|
|
351
351
|
}
|
|
352
352
|
|
|
353
|
+
private async queryTasks(payload: TaskQueryPayload): Promise<TaskRecord[]> {
|
|
354
|
+
const canonicalFilter = (payload.filter ?? {}) as NonNullable<
|
|
355
|
+
TaskQueryPayload["filter"]
|
|
356
|
+
>;
|
|
357
|
+
const pageSize = payload.pageSize ?? 50;
|
|
358
|
+
const pageNum = payload.pageNum ?? 0;
|
|
359
|
+
const body = {
|
|
360
|
+
filter: canonicalFilter,
|
|
361
|
+
sortBy: payload.sortBy ?? "created_at",
|
|
362
|
+
pageSize,
|
|
363
|
+
pageNum,
|
|
364
|
+
};
|
|
365
|
+
const response = await this.request("/tasks/query", body);
|
|
366
|
+
return tasksListSchema.parse(response).tasks;
|
|
367
|
+
}
|
|
368
|
+
|
|
353
369
|
private async submitResponse(
|
|
354
370
|
payload: SubmitResponsePayload
|
|
355
371
|
): Promise<ResponseRecord> {
|
package/src/worker.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Type } from "@sinclair/typebox";
|
|
2
|
+
import { PrivateKeySigner } from "./signers.js";
|
|
3
|
+
import { BountyAgentsWorkerPlugin } from "./index.js";
|
|
4
|
+
import { json } from "./helper.js";
|
|
5
|
+
|
|
6
|
+
const SERVICE_URL = "http://localhost:3000";
|
|
7
|
+
const CONTRACT_ADDRESS = "0x55D45aFA265d0381C8A81328FfeA408D2Dd45F40";
|
|
8
|
+
const PRIVATE_KEY =
|
|
9
|
+
"0x289f92dd30c36ff24b75b48623c70dea2b428dabac7a52c5ca810bcda64d861b";
|
|
10
|
+
|
|
11
|
+
export async function getAvailableTask(params: {
|
|
12
|
+
keyword?: string;
|
|
13
|
+
pageSize?: number;
|
|
14
|
+
pageNum?: number;
|
|
15
|
+
}) {
|
|
16
|
+
const signer = new PrivateKeySigner(PRIVATE_KEY);
|
|
17
|
+
const plugin = new BountyAgentsWorkerPlugin(signer, {
|
|
18
|
+
serviceUrl: SERVICE_URL,
|
|
19
|
+
contractAddress: CONTRACT_ADDRESS,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const tasks = (await plugin.executeTool("bountyagents.worker.task.query", {
|
|
23
|
+
filter: {
|
|
24
|
+
status: "active",
|
|
25
|
+
},
|
|
26
|
+
pageSize: params.pageSize,
|
|
27
|
+
pageNum: params.pageNum,
|
|
28
|
+
})) as any;
|
|
29
|
+
if (tasks.length === 0) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
return tasks[0];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function registerWorkerTools(api: any) {
|
|
36
|
+
api.registerTool({
|
|
37
|
+
name: "get_available_task",
|
|
38
|
+
description:
|
|
39
|
+
"Get available active bounty task for the worker to work on and respond to.",
|
|
40
|
+
parameters: Type.Object({
|
|
41
|
+
pageSize: Type.Optional(Type.Number()),
|
|
42
|
+
pageNum: Type.Optional(Type.Number()),
|
|
43
|
+
keyword: Type.Optional(Type.String()),
|
|
44
|
+
}),
|
|
45
|
+
async execute(_id: string, params: any) {
|
|
46
|
+
try {
|
|
47
|
+
const result = await getAvailableTask({
|
|
48
|
+
pageSize: params.pageSize,
|
|
49
|
+
pageNum: params.pageNum,
|
|
50
|
+
keyword: "",
|
|
51
|
+
});
|
|
52
|
+
return json(result);
|
|
53
|
+
} catch (error: any) {
|
|
54
|
+
return json({
|
|
55
|
+
error: error instanceof Error ? error.message : String(error),
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
}
|
package/test-worker.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { getAvailableTask } from "./src/worker.js";
|
|
2
|
+
|
|
3
|
+
async function testGetAvailableTasks() {
|
|
4
|
+
console.log(`\n--- Testing getAvailableTasks ---`);
|
|
5
|
+
|
|
6
|
+
try {
|
|
7
|
+
const task = await getAvailableTask({
|
|
8
|
+
pageSize: 5,
|
|
9
|
+
pageNum: 0,
|
|
10
|
+
keyword: "",
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
if (task) {
|
|
14
|
+
console.log("First task sample:");
|
|
15
|
+
console.log(JSON.stringify(task, null, 2));
|
|
16
|
+
} else {
|
|
17
|
+
console.log("No active tasks found.");
|
|
18
|
+
}
|
|
19
|
+
} catch (error) {
|
|
20
|
+
console.error("Test failed:");
|
|
21
|
+
console.error(error);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
testGetAvailableTasks();
|
|
File without changes
|