@hashgraphonline/conversational-agent 0.2.217 → 0.2.218
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/esm/index11.js +1 -1
- package/dist/esm/index22.js +1 -1
- package/dist/esm/index24.js +3 -3
- package/dist/esm/index34.js +3 -3
- package/dist/esm/index43.js +26 -4
- package/dist/esm/index43.js.map +1 -1
- package/dist/esm/index45.js +64 -309
- package/dist/esm/index45.js.map +1 -1
- package/dist/esm/index46.js +61 -173
- package/dist/esm/index46.js.map +1 -1
- package/dist/esm/index47.js +54 -7
- package/dist/esm/index47.js.map +1 -1
- package/dist/esm/index48.js +73 -50
- package/dist/esm/index48.js.map +1 -1
- package/dist/esm/index49.js +44 -40
- package/dist/esm/index49.js.map +1 -1
- package/dist/esm/index50.js +48 -30
- package/dist/esm/index50.js.map +1 -1
- package/dist/esm/index51.js +95 -74
- package/dist/esm/index51.js.map +1 -1
- package/dist/esm/index52.js +24 -45
- package/dist/esm/index52.js.map +1 -1
- package/dist/esm/index53.js +58 -50
- package/dist/esm/index53.js.map +1 -1
- package/dist/esm/index54.js +77 -101
- package/dist/esm/index54.js.map +1 -1
- package/dist/esm/index55.js +90 -30
- package/dist/esm/index55.js.map +1 -1
- package/dist/esm/index56.js +75 -50
- package/dist/esm/index56.js.map +1 -1
- package/dist/esm/index57.js +5 -97
- package/dist/esm/index57.js.map +1 -1
- package/dist/esm/index58.js +309 -102
- package/dist/esm/index58.js.map +1 -1
- package/dist/esm/index59.js +170 -91
- package/dist/esm/index59.js.map +1 -1
- package/dist/esm/index6.js +12 -12
- package/dist/esm/index60.js +6 -26
- package/dist/esm/index60.js.map +1 -1
- package/package.json +2 -2
package/dist/esm/index52.js
CHANGED
|
@@ -1,66 +1,38 @@
|
|
|
1
1
|
import { BaseHederaQueryTool } from "hedera-agent-kit";
|
|
2
|
-
import { Size, Duration } from "@ethersphere/bee-js";
|
|
3
2
|
import { z } from "zod";
|
|
4
|
-
import {
|
|
5
|
-
import { NOT_FOUND_STATUS, GATEWAY_STAMP_ERROR_MESSAGE
|
|
6
|
-
const
|
|
7
|
-
postageBatchId: z.string()
|
|
8
|
-
duration: z.string().optional(),
|
|
9
|
-
size: z.number().optional()
|
|
3
|
+
import { errorHasStatus, getBatchSummary, getResponseWithStructuredContent } from "./index62.js";
|
|
4
|
+
import { NOT_FOUND_STATUS, GATEWAY_STAMP_ERROR_MESSAGE } from "./index63.js";
|
|
5
|
+
const GetPostageStampSchema = z.object({
|
|
6
|
+
postageBatchId: z.string()
|
|
10
7
|
});
|
|
11
|
-
class
|
|
8
|
+
class GetPostageStampTool extends BaseHederaQueryTool {
|
|
12
9
|
constructor(params) {
|
|
13
10
|
const { bee, config, ...rest } = params;
|
|
14
11
|
super(rest);
|
|
15
|
-
this.name = "swarm-
|
|
16
|
-
this.description = `
|
|
17
|
-
postageBatchId: The id of the
|
|
18
|
-
size: The storage size in MB (Megabytes). These other size units convert like this to MB: 1 byte = 0.000001 MB, 1 KB = 0.001 MB, 1GB= 1000MB.
|
|
19
|
-
duration: Duration for which the data should be stored. Time to live of the postage stamp, e.g. 1d - 1 day, 1w - 1 week, 1month - 1 month.
|
|
12
|
+
this.name = "swarm-get-postage-stamp";
|
|
13
|
+
this.description = `Get a specific postage stamp based on postageBatchId.
|
|
14
|
+
postageBatchId: The id of the stamp which is requested.
|
|
20
15
|
`;
|
|
21
16
|
this.namespace = "swarm";
|
|
22
|
-
this.specificInputSchema =
|
|
17
|
+
this.specificInputSchema = GetPostageStampSchema;
|
|
23
18
|
this.bee = bee;
|
|
24
19
|
this.config = config;
|
|
25
20
|
}
|
|
26
21
|
async executeQuery(input) {
|
|
27
|
-
const { postageBatchId
|
|
22
|
+
const { postageBatchId } = input;
|
|
28
23
|
if (!postageBatchId) {
|
|
29
24
|
this.logger.error(
|
|
30
25
|
"Missing required parameter: postageBatchId."
|
|
31
26
|
);
|
|
32
27
|
throw new Error("Missing required parameter: postageBatchId.");
|
|
33
|
-
} else if (!duration && !size) {
|
|
34
|
-
this.logger.error(
|
|
35
|
-
"You need at least one parameter from duration and size."
|
|
36
|
-
);
|
|
37
|
-
throw new Error("You need at least one parameter from duration and size.");
|
|
38
|
-
}
|
|
39
|
-
const extendSize = !!size ? Size.fromMegabytes(size) : Size.fromBytes(1);
|
|
40
|
-
let extendDuration = Duration.ZERO;
|
|
41
|
-
try {
|
|
42
|
-
if (duration) {
|
|
43
|
-
extendDuration = Duration.fromMilliseconds(makeDate(duration));
|
|
44
|
-
}
|
|
45
|
-
} catch (makeDateError) {
|
|
46
|
-
this.logger.error(
|
|
47
|
-
"Invalid parameter: duration."
|
|
48
|
-
);
|
|
49
|
-
throw new Error("Invalid parameter: duration.");
|
|
50
28
|
}
|
|
51
|
-
let
|
|
29
|
+
let rawPostageBatch;
|
|
52
30
|
try {
|
|
53
|
-
|
|
54
|
-
postageBatchId,
|
|
55
|
-
extendSize,
|
|
56
|
-
extendDuration
|
|
57
|
-
);
|
|
31
|
+
rawPostageBatch = await this.bee.getPostageBatch(postageBatchId);
|
|
58
32
|
} catch (error) {
|
|
59
|
-
let errorMessage = "
|
|
33
|
+
let errorMessage = "Retrieval of postage batch failed.";
|
|
60
34
|
if (errorHasStatus(error, NOT_FOUND_STATUS)) {
|
|
61
35
|
errorMessage = GATEWAY_STAMP_ERROR_MESSAGE;
|
|
62
|
-
} else if (errorHasStatus(error, BAD_REQUEST_STATUS)) {
|
|
63
|
-
errorMessage = getErrorMessage(error);
|
|
64
36
|
}
|
|
65
37
|
this.logger.error(
|
|
66
38
|
errorMessage,
|
|
@@ -68,12 +40,19 @@ class ExtendPostageStampTool extends BaseHederaQueryTool {
|
|
|
68
40
|
);
|
|
69
41
|
throw new Error(errorMessage);
|
|
70
42
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
43
|
+
const batch = {
|
|
44
|
+
...rawPostageBatch,
|
|
45
|
+
batchID: rawPostageBatch.batchID.toHex()
|
|
46
|
+
};
|
|
47
|
+
const batchSummary = getBatchSummary(rawPostageBatch);
|
|
48
|
+
const content = {
|
|
49
|
+
raw: batch,
|
|
50
|
+
summary: batchSummary
|
|
51
|
+
};
|
|
52
|
+
return getResponseWithStructuredContent(content);
|
|
74
53
|
}
|
|
75
54
|
}
|
|
76
55
|
export {
|
|
77
|
-
|
|
56
|
+
GetPostageStampTool
|
|
78
57
|
};
|
|
79
58
|
//# sourceMappingURL=index52.js.map
|
package/dist/esm/index52.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index52.js","sources":["../../src/plugins/community/swarm/tools/
|
|
1
|
+
{"version":3,"file":"index52.js","sources":["../../src/plugins/community/swarm/tools/GetPostageStampTool.ts"],"sourcesContent":["import {\r\n type GenericPluginContext,\r\n BaseHederaQueryTool,\r\n type HederaAgentKit,\r\n} from \"hedera-agent-kit\";\r\nimport { Bee } from \"@ethersphere/bee-js\";\r\nimport { z } from \"zod\";\r\nimport {\r\n PostageBatchCurated,\r\n PostageBatchSummary,\r\n ResponseContent,\r\n} from \"../model\";\r\nimport {\r\n errorHasStatus,\r\n getBatchSummary,\r\n getResponseWithStructuredContent,\r\n ToolResponse,\r\n} from \"../utils\";\r\nimport { GATEWAY_STAMP_ERROR_MESSAGE, NOT_FOUND_STATUS } from \"../constants\";\r\nimport { SwarmConfig } from \"../config\";\r\n\r\nconst GetPostageStampSchema = z.object({\r\n postageBatchId: z.string(),\r\n});\r\n\r\nexport class GetPostageStampTool extends BaseHederaQueryTool<typeof GetPostageStampSchema> {\r\n name = \"swarm-get-postage-stamp\";\r\n description = `Get a specific postage stamp based on postageBatchId.\r\n postageBatchId: The id of the stamp which is requested.\r\n `;\r\n namespace = \"swarm\";\r\n specificInputSchema = GetPostageStampSchema;\r\n bee: Bee;\r\n config: SwarmConfig;\r\n \r\n constructor(params: {\r\n hederaKit: HederaAgentKit;\r\n config: SwarmConfig;\r\n logger?: GenericPluginContext['logger'];\r\n bee: Bee;\r\n }) {\r\n const { bee, config, ...rest } = params;\r\n super(rest);\r\n this.bee = bee;\r\n this.config = config;\r\n }\r\n\r\n protected async executeQuery(\r\n input: z.infer<typeof GetPostageStampSchema>\r\n ): Promise<ToolResponse | string> {\r\n const { postageBatchId } = input;\r\n if (!postageBatchId) {\r\n this.logger.error(\r\n 'Missing required parameter: postageBatchId.'\r\n );\r\n\r\n throw new Error(\"Missing required parameter: postageBatchId.\");\r\n }\r\n\r\n let rawPostageBatch;\r\n\r\n try {\r\n rawPostageBatch = await this.bee.getPostageBatch(postageBatchId);\r\n } catch (error) {\r\n let errorMessage = 'Retrieval of postage batch failed.';\r\n \r\n if (errorHasStatus(error, NOT_FOUND_STATUS)) {\r\n errorMessage = GATEWAY_STAMP_ERROR_MESSAGE;\r\n }\r\n\r\n this.logger.error(\r\n errorMessage,\r\n error\r\n );\r\n\r\n throw new Error(errorMessage);\r\n }\r\n\r\n const batch: PostageBatchCurated = {\r\n ...rawPostageBatch,\r\n batchID: rawPostageBatch.batchID.toHex(),\r\n };\r\n const batchSummary: PostageBatchSummary = getBatchSummary(rawPostageBatch);\r\n\r\n const content: ResponseContent<PostageBatchCurated, PostageBatchSummary> = {\r\n raw: batch,\r\n summary: batchSummary,\r\n };\r\n\r\n return getResponseWithStructuredContent(content);\r\n }\r\n}\r\n"],"names":[],"mappings":";;;;AAqBA,MAAM,wBAAwB,EAAE,OAAO;AAAA,EACrC,gBAAgB,EAAE,OAAA;AACpB,CAAC;AAEM,MAAM,4BAA4B,oBAAkD;AAAA,EAUzF,YAAY,QAKT;AACD,UAAM,EAAE,KAAK,QAAQ,GAAG,SAAS;AACjC,UAAM,IAAI;AAhBZ,SAAA,OAAO;AACP,SAAA,cAAc;AAAA;AAAA;AAGd,SAAA,YAAY;AACZ,SAAA,sBAAsB;AAYpB,SAAK,MAAM;AACX,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,MAAgB,aACZ,OAC8B;AAChC,UAAM,EAAE,mBAAmB;AAC3B,QAAI,CAAC,gBAAgB;AACnB,WAAK,OAAO;AAAA,QACV;AAAA,MAAA;AAGF,YAAM,IAAI,MAAM,6CAA6C;AAAA,IAC/D;AAEA,QAAI;AAEJ,QAAI;AACF,wBAAkB,MAAM,KAAK,IAAI,gBAAgB,cAAc;AAAA,IACjE,SAAS,OAAO;AACd,UAAI,eAAe;AAEnB,UAAI,eAAe,OAAO,gBAAgB,GAAG;AAC3C,uBAAe;AAAA,MACjB;AAEA,WAAK,OAAO;AAAA,QACV;AAAA,QACA;AAAA,MAAA;AAGF,YAAM,IAAI,MAAM,YAAY;AAAA,IAC9B;AAEA,UAAM,QAA6B;AAAA,MACjC,GAAG;AAAA,MACH,SAAS,gBAAgB,QAAQ,MAAA;AAAA,IAAM;AAEzC,UAAM,eAAoC,gBAAgB,eAAe;AAEzE,UAAM,UAAqE;AAAA,MACzE,KAAK;AAAA,MACL,SAAS;AAAA,IAAA;AAGX,WAAO,iCAAiC,OAAO;AAAA,EACjD;AACF;"}
|
package/dist/esm/index53.js
CHANGED
|
@@ -1,75 +1,83 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Wallet } from "@ethereumjs/wallet";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
import crypto from "crypto";
|
|
4
|
+
import { hexToBytes, errorHasStatus, getErrorMessage, getResponseWithStructuredContent } from "./index62.js";
|
|
5
|
+
import { BaseHederaQueryTool } from "hedera-agent-kit";
|
|
6
|
+
import { BAD_REQUEST_STATUS } from "./index63.js";
|
|
7
|
+
const ReadFeedSchema = z.object({
|
|
8
|
+
memoryTopic: z.string(),
|
|
9
|
+
owner: z.string().optional()
|
|
7
10
|
});
|
|
8
|
-
class
|
|
11
|
+
class ReadFeedTool extends BaseHederaQueryTool {
|
|
9
12
|
constructor(params) {
|
|
10
13
|
const { bee, config, ...rest } = params;
|
|
11
14
|
super(rest);
|
|
12
|
-
this.name = "swarm-
|
|
13
|
-
this.description = `
|
|
14
|
-
|
|
15
|
+
this.name = "swarm-read-feed";
|
|
16
|
+
this.description = `Retrieve the latest data from the feed of a given topic.
|
|
17
|
+
memoryTopic: Feed topic.
|
|
18
|
+
owner: When accessing external memory or feed, ethereum address of the owner must be set.
|
|
15
19
|
`;
|
|
16
20
|
this.namespace = "swarm";
|
|
17
|
-
this.specificInputSchema =
|
|
21
|
+
this.specificInputSchema = ReadFeedSchema;
|
|
18
22
|
this.bee = bee;
|
|
19
23
|
this.config = config;
|
|
20
24
|
}
|
|
21
25
|
async executeQuery(input) {
|
|
22
|
-
|
|
26
|
+
const { memoryTopic, owner } = input;
|
|
27
|
+
if (!memoryTopic) {
|
|
23
28
|
this.logger.error(
|
|
24
|
-
"Missing required parameter:
|
|
29
|
+
"Missing required parameter: memoryTopic."
|
|
25
30
|
);
|
|
26
|
-
throw new Error("Missing required parameter:
|
|
31
|
+
throw new Error("Missing required parameter: memoryTopic.");
|
|
27
32
|
}
|
|
28
|
-
|
|
29
|
-
if (
|
|
30
|
-
this.logger.error(
|
|
31
|
-
|
|
32
|
-
);
|
|
33
|
-
throw new Error("Invalid tagId format. Expected a numeric string.");
|
|
33
|
+
this.logger.info(`[API] Downloading text from Swarm feed with topic: ${memoryTopic}.`);
|
|
34
|
+
if (!this.config.beeFeedPK) {
|
|
35
|
+
this.logger.error("Feed private key not configured.");
|
|
36
|
+
throw new Error("Feed private key not configured.");
|
|
34
37
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
38
|
+
let topic = memoryTopic;
|
|
39
|
+
if (topic.startsWith("0x")) {
|
|
40
|
+
topic = topic.slice(2);
|
|
41
|
+
}
|
|
42
|
+
const isHexString = /^[0-9a-fA-F]{64}$/.test(topic);
|
|
43
|
+
if (!isHexString) {
|
|
44
|
+
const hash = crypto.createHash("sha256").update(memoryTopic).digest("hex");
|
|
45
|
+
topic = hash;
|
|
46
|
+
}
|
|
47
|
+
const topicBytes = hexToBytes(topic);
|
|
48
|
+
let feedOwner = owner;
|
|
49
|
+
if (!feedOwner) {
|
|
50
|
+
const feedPrivateKey = hexToBytes(this.config.beeFeedPK);
|
|
51
|
+
const signer = new Wallet(feedPrivateKey);
|
|
52
|
+
feedOwner = signer.getAddressString().slice(2);
|
|
53
|
+
} else {
|
|
54
|
+
if (feedOwner.startsWith("0x")) {
|
|
55
|
+
feedOwner = feedOwner.slice(2);
|
|
56
|
+
}
|
|
57
|
+
if (feedOwner.length !== 40) {
|
|
58
|
+
this.logger.error("Owner must be a valid Ethereum address.");
|
|
59
|
+
throw new Error("Owner must be a valid Ethereum address.");
|
|
51
60
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
61
|
+
}
|
|
62
|
+
let textData;
|
|
63
|
+
try {
|
|
64
|
+
const feedReader = this.bee.makeFeedReader(topicBytes, feedOwner);
|
|
65
|
+
const latestUpdate = await feedReader.downloadPayload();
|
|
66
|
+
textData = latestUpdate.payload.toUtf8();
|
|
58
67
|
} catch (error) {
|
|
59
|
-
let errorMessage =
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
errorMessage = `Tag with ID ${input.tagId} does not exist or has been deleted. ` + GATEWAY_TAG_ERROR_MESSAGE;
|
|
68
|
+
let errorMessage = "Reading feed failed.";
|
|
69
|
+
if (errorHasStatus(error, BAD_REQUEST_STATUS)) {
|
|
70
|
+
errorMessage = getErrorMessage(error);
|
|
63
71
|
}
|
|
64
|
-
this.logger.error(
|
|
65
|
-
errorMessage,
|
|
66
|
-
error
|
|
67
|
-
);
|
|
72
|
+
this.logger.error(errorMessage, error);
|
|
68
73
|
throw new Error(errorMessage);
|
|
69
74
|
}
|
|
75
|
+
return getResponseWithStructuredContent({
|
|
76
|
+
textData
|
|
77
|
+
});
|
|
70
78
|
}
|
|
71
79
|
}
|
|
72
80
|
export {
|
|
73
|
-
|
|
81
|
+
ReadFeedTool
|
|
74
82
|
};
|
|
75
83
|
//# sourceMappingURL=index53.js.map
|
package/dist/esm/index53.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index53.js","sources":["../../src/plugins/community/swarm/tools/
|
|
1
|
+
{"version":3,"file":"index53.js","sources":["../../src/plugins/community/swarm/tools/ReadFeedTool.ts"],"sourcesContent":["import { Bee } from \"@ethersphere/bee-js\";\r\nimport { Wallet } from \"@ethereumjs/wallet\";\r\nimport { z } from \"zod\";\r\nimport crypto from \"crypto\";\r\nimport { errorHasStatus, getErrorMessage, getResponseWithStructuredContent, hexToBytes, ToolResponse } from \"../utils\";\r\nimport { BaseHederaQueryTool, GenericPluginContext, HederaAgentKit } from \"hedera-agent-kit\";\r\nimport { SwarmConfig } from \"../config\";\r\nimport { BAD_REQUEST_STATUS } from \"../constants\";\r\n\r\nconst ReadFeedSchema = z.object({\r\n memoryTopic: z.string(),\r\n owner: z.string().optional()\r\n});\r\n\r\nexport class ReadFeedTool extends BaseHederaQueryTool<typeof ReadFeedSchema> {\r\n name = \"swarm-read-feed\";\r\n description = `Retrieve the latest data from the feed of a given topic.\r\n memoryTopic: Feed topic.\r\n owner: When accessing external memory or feed, ethereum address of the owner must be set.\r\n `;\r\n namespace = \"swarm\";\r\n specificInputSchema = ReadFeedSchema;\r\n bee: Bee;\r\n config: SwarmConfig;\r\n \r\n constructor(params: {\r\n hederaKit: HederaAgentKit;\r\n config: SwarmConfig;\r\n logger?: GenericPluginContext['logger'];\r\n bee: Bee;\r\n }) {\r\n const { bee, config, ...rest } = params;\r\n super(rest);\r\n this.bee = bee;\r\n this.config = config;\r\n }\r\n\r\n protected async executeQuery(\r\n input: z.infer<typeof ReadFeedSchema>\r\n ): Promise<ToolResponse | string> {\r\n const { memoryTopic, owner } = input;\r\n\r\n if (!memoryTopic) {\r\n this.logger.error(\r\n 'Missing required parameter: memoryTopic.'\r\n );\r\n\r\n throw new Error('Missing required parameter: memoryTopic.');\r\n }\r\n\r\n this.logger.info(`[API] Downloading text from Swarm feed with topic: ${memoryTopic}.`);\r\n\r\n if (!this.config.beeFeedPK) {\r\n this.logger.error('Feed private key not configured.');\r\n\r\n throw new Error('Feed private key not configured.');\r\n }\r\n\r\n // Process topic - if not a hex string, hash it\r\n let topic = memoryTopic;\r\n if (topic.startsWith(\"0x\")) {\r\n topic = topic.slice(2);\r\n }\r\n const isHexString = /^[0-9a-fA-F]{64}$/.test(topic);\r\n\r\n if (!isHexString) {\r\n // Hash the topic string using SHA-256\r\n const hash = crypto.createHash(\"sha256\").update(memoryTopic).digest(\"hex\");\r\n topic = hash;\r\n }\r\n\r\n // Convert topic string to bytes\r\n const topicBytes = hexToBytes(topic);\r\n\r\n let feedOwner = owner;\r\n if (!feedOwner) {\r\n const feedPrivateKey = hexToBytes(this.config.beeFeedPK);\r\n const signer = new Wallet(feedPrivateKey);\r\n feedOwner = signer.getAddressString().slice(2);\r\n } else {\r\n if (feedOwner.startsWith(\"0x\")) {\r\n feedOwner = feedOwner.slice(2);\r\n }\r\n if (feedOwner.length !== 40) {\r\n this.logger.error('Owner must be a valid Ethereum address.');\r\n\r\n throw new Error('Owner must be a valid Ethereum address.');\r\n }\r\n }\r\n\r\n let textData;\r\n \r\n try {\r\n const feedReader = this.bee.makeFeedReader(topicBytes, feedOwner);\r\n const latestUpdate = await feedReader.downloadPayload();\r\n textData = latestUpdate.payload.toUtf8();\r\n } catch (error) {\r\n let errorMessage = 'Reading feed failed.';\r\n if (errorHasStatus(error, BAD_REQUEST_STATUS)) {\r\n errorMessage = getErrorMessage(error);\r\n }\r\n this.logger.error(errorMessage, error);\r\n throw new Error(errorMessage);\r\n }\r\n \r\n return getResponseWithStructuredContent({\r\n textData,\r\n });\r\n }\r\n}\r\n"],"names":[],"mappings":";;;;;;AASA,MAAM,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,CAAC;AAAA,MAC/B;AACA,UAAI,UAAU,WAAW,IAAI;AAC3B,aAAK,OAAO,MAAM,yCAAyC;AAE3D,cAAM,IAAI,MAAM,yCAAyC;AAAA,MAC3D;AAAA,IACF;AAEA,QAAI;AAEJ,QAAI;AACF,YAAM,aAAa,KAAK,IAAI,eAAe,YAAY,SAAS;AAChE,YAAM,eAAe,MAAM,WAAW,gBAAA;AACtC,iBAAW,aAAa,QAAQ,OAAA;AAAA,IAClC,SAAS,OAAO;AACd,UAAI,eAAe;AACnB,UAAI,eAAe,OAAO,kBAAkB,GAAG;AAC7C,uBAAe,gBAAgB,KAAK;AAAA,MACtC;AACA,WAAK,OAAO,MAAM,cAAc,KAAK;AACrC,YAAM,IAAI,MAAM,YAAY;AAAA,IAC9B;AAEA,WAAO,iCAAiC;AAAA,MACtC;AAAA,IAAA,CACD;AAAA,EACH;AACF;"}
|
package/dist/esm/index54.js
CHANGED
|
@@ -1,124 +1,100 @@
|
|
|
1
|
-
import { MantarayNode } from "@ethersphere/bee-js";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
import fs from "fs";
|
|
4
|
-
import path from "path";
|
|
5
1
|
import { BaseHederaQueryTool } from "hedera-agent-kit";
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import crypto from "crypto";
|
|
4
|
+
import { getUploadPostageBatchId, hexToBytes, errorHasStatus, getErrorMessage, getResponseWithStructuredContent } from "./index62.js";
|
|
5
|
+
import { BAD_REQUEST_STATUS } from "./index63.js";
|
|
6
|
+
import { Wallet } from "@ethereumjs/wallet";
|
|
7
|
+
const UpdateFeedSchema = z.object({
|
|
8
|
+
data: z.string(),
|
|
9
|
+
memoryTopic: z.string(),
|
|
10
|
+
postageBatchId: z.string().optional()
|
|
10
11
|
});
|
|
11
|
-
class
|
|
12
|
+
class UpdateFeedTool extends BaseHederaQueryTool {
|
|
12
13
|
constructor(params) {
|
|
13
14
|
const { bee, config, ...rest } = params;
|
|
14
15
|
super(rest);
|
|
15
|
-
this.name = "swarm-
|
|
16
|
-
this.description = `
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
`;
|
|
16
|
+
this.name = "swarm-update-feed";
|
|
17
|
+
this.description = `Update the feed of a given topic with new data.
|
|
18
|
+
data: Arbitrary string to upload.
|
|
19
|
+
memoryTopic: If provided, uploads the data to a feed with this topic. It is the label of the memory that can be used later to retrieve the data instead of its content hash. If not a hex string, it will be hashed to create a feed topic.
|
|
20
|
+
postageBatchId: The postage stamp batch ID which will be used to perform the upload, if it is provided.`;
|
|
21
21
|
this.namespace = "swarm";
|
|
22
|
-
this.specificInputSchema =
|
|
22
|
+
this.specificInputSchema = UpdateFeedSchema;
|
|
23
23
|
this.bee = bee;
|
|
24
24
|
this.config = config;
|
|
25
25
|
}
|
|
26
26
|
async executeQuery(input) {
|
|
27
|
-
const {
|
|
28
|
-
if (!
|
|
27
|
+
const { data, memoryTopic, postageBatchId: inputPostageBatchId } = input;
|
|
28
|
+
if (!data) {
|
|
29
|
+
this.logger.error(
|
|
30
|
+
"Missing required parameter: data."
|
|
31
|
+
);
|
|
32
|
+
throw new Error("Missing required parameter: data.");
|
|
33
|
+
} else if (!memoryTopic) {
|
|
29
34
|
this.logger.error(
|
|
30
|
-
"Missing required parameter:
|
|
35
|
+
"Missing required parameter: topic."
|
|
31
36
|
);
|
|
32
|
-
throw new Error("Missing required parameter:
|
|
37
|
+
throw new Error("Missing required parameter: topic.");
|
|
33
38
|
}
|
|
34
|
-
|
|
35
|
-
let isManifest = false;
|
|
36
|
-
let node;
|
|
39
|
+
let postageBatchId = "";
|
|
37
40
|
try {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
postageBatchId = await getUploadPostageBatchId(
|
|
42
|
+
inputPostageBatchId,
|
|
43
|
+
this.bee,
|
|
44
|
+
this.config
|
|
45
|
+
);
|
|
41
46
|
} catch (error) {
|
|
47
|
+
let errorMessage = "Update feed failed.";
|
|
48
|
+
if (error instanceof Error) {
|
|
49
|
+
errorMessage = error.message;
|
|
50
|
+
}
|
|
51
|
+
this.logger.error(errorMessage);
|
|
52
|
+
throw new Error(errorMessage);
|
|
53
|
+
}
|
|
54
|
+
const binaryData = Buffer.from(data);
|
|
55
|
+
if (!this.config.beeFeedPK) {
|
|
56
|
+
this.logger.error("Feed private key not configured.");
|
|
57
|
+
throw new Error("Feed private key not configured.");
|
|
42
58
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (!fs.existsSync(nodeDestFolder)) {
|
|
65
|
-
await promisify(fs.mkdir)(nodeDestFolder, { recursive: true });
|
|
66
|
-
}
|
|
67
|
-
const data = await this.bee.downloadData(node2.targetAddress);
|
|
68
|
-
await promisify(fs.writeFile)(
|
|
69
|
-
path.join(destinationFolder, node2.fullPathString),
|
|
70
|
-
data.toUint8Array()
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return {
|
|
75
|
-
content: [
|
|
76
|
-
{
|
|
77
|
-
type: "text",
|
|
78
|
-
text: JSON.stringify(
|
|
79
|
-
{
|
|
80
|
-
reference,
|
|
81
|
-
manifestNodeCount: nodes.length,
|
|
82
|
-
savedTo: destinationFolder,
|
|
83
|
-
message: `Manifest content (${nodes.length} files) successfully downloaded to ${destinationFolder}`
|
|
84
|
-
},
|
|
85
|
-
null,
|
|
86
|
-
2
|
|
87
|
-
)
|
|
88
|
-
}
|
|
89
|
-
]
|
|
90
|
-
};
|
|
91
|
-
} else {
|
|
92
|
-
const nodes = node.collect();
|
|
93
|
-
const filesList = nodes.map((node2) => ({
|
|
94
|
-
path: node2.fullPathString || "/",
|
|
95
|
-
targetAddress: Array.from(node2.targetAddress).map((e) => e.toString(16).padStart(2, "0")).join(""),
|
|
96
|
-
metadata: node2.metadata
|
|
97
|
-
}));
|
|
98
|
-
return {
|
|
99
|
-
content: [
|
|
100
|
-
{
|
|
101
|
-
type: "text",
|
|
102
|
-
text: JSON.stringify(
|
|
103
|
-
{
|
|
104
|
-
reference,
|
|
105
|
-
type: "manifest",
|
|
106
|
-
files: filesList,
|
|
107
|
-
message: "This is a manifest with multiple files. Provide a filePath to download all files or download individual files using their specific references."
|
|
108
|
-
},
|
|
109
|
-
null,
|
|
110
|
-
2
|
|
111
|
-
)
|
|
112
|
-
}
|
|
113
|
-
]
|
|
114
|
-
};
|
|
59
|
+
let topic = memoryTopic;
|
|
60
|
+
if (topic.startsWith("0x")) {
|
|
61
|
+
topic = topic.slice(2);
|
|
62
|
+
}
|
|
63
|
+
const isHexString = /^[0-9a-fA-F]{64}$/.test(memoryTopic);
|
|
64
|
+
if (!isHexString) {
|
|
65
|
+
const hash = crypto.createHash("sha256").update(memoryTopic).digest("hex");
|
|
66
|
+
topic = hash;
|
|
67
|
+
}
|
|
68
|
+
const topicBytes = hexToBytes(topic);
|
|
69
|
+
const feedPrivateKey = hexToBytes(this.config.beeFeedPK);
|
|
70
|
+
const signer = new Wallet(feedPrivateKey);
|
|
71
|
+
const owner = signer.getAddressString().slice(2);
|
|
72
|
+
let result;
|
|
73
|
+
try {
|
|
74
|
+
const feedWriter = this.bee.makeFeedWriter(topicBytes, feedPrivateKey);
|
|
75
|
+
result = await feedWriter.uploadPayload(postageBatchId, binaryData);
|
|
76
|
+
} catch (error) {
|
|
77
|
+
let errorMessage = "Unable to update feed.";
|
|
78
|
+
if (errorHasStatus(error, BAD_REQUEST_STATUS)) {
|
|
79
|
+
errorMessage = getErrorMessage(error);
|
|
115
80
|
}
|
|
116
|
-
|
|
117
|
-
|
|
81
|
+
this.logger.error(
|
|
82
|
+
errorMessage,
|
|
83
|
+
error
|
|
84
|
+
);
|
|
85
|
+
throw new Error(errorMessage);
|
|
118
86
|
}
|
|
87
|
+
const reference = result.reference.toString();
|
|
88
|
+
return getResponseWithStructuredContent({
|
|
89
|
+
reference,
|
|
90
|
+
topicString: memoryTopic,
|
|
91
|
+
topic,
|
|
92
|
+
feedUrl: `${this.bee.url}/feeds/${owner}/${topic}`,
|
|
93
|
+
message: "Data successfully uploaded to Swarm and linked to feed."
|
|
94
|
+
});
|
|
119
95
|
}
|
|
120
96
|
}
|
|
121
97
|
export {
|
|
122
|
-
|
|
98
|
+
UpdateFeedTool
|
|
123
99
|
};
|
|
124
100
|
//# sourceMappingURL=index54.js.map
|
package/dist/esm/index54.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index54.js","sources":["../../src/plugins/community/swarm/tools/
|
|
1
|
+
{"version":3,"file":"index54.js","sources":["../../src/plugins/community/swarm/tools/UpdateFeedTool.ts"],"sourcesContent":["import {\r\n BaseHederaQueryTool,\r\n HederaAgentKit,\r\n type GenericPluginContext,\r\n} from \"hedera-agent-kit\";\r\nimport { Bee } from \"@ethersphere/bee-js\";\r\nimport { z } from \"zod\";\r\nimport crypto from \"crypto\";\r\nimport {\r\n errorHasStatus,\r\n getErrorMessage,\r\n getResponseWithStructuredContent,\r\n getUploadPostageBatchId,\r\n hexToBytes,\r\n ToolResponse,\r\n} from \"../utils\";\r\nimport { BAD_REQUEST_STATUS } from \"../constants\";\r\nimport { Wallet } from \"@ethereumjs/wallet\";\r\nimport { SwarmConfig } from \"../config\";\r\n\r\nconst UpdateFeedSchema = z.object({\r\n data: z.string(),\r\n memoryTopic: z.string(),\r\n postageBatchId: z.string().optional(),\r\n});\r\n\r\nexport class UpdateFeedTool extends BaseHederaQueryTool<typeof UpdateFeedSchema> {\r\n name = \"swarm-update-feed\";\r\n description = `Update the feed of a given topic with new data.\r\n data: Arbitrary string to upload.\r\n memoryTopic: If provided, uploads the data to a feed with this topic. It is the label of the memory that can be used later to retrieve the data instead of its content hash. If not a hex string, it will be hashed to create a feed topic.\r\n postageBatchId: The postage stamp batch ID which will be used to perform the upload, if it is provided.`;\r\n namespace = \"swarm\";\r\n specificInputSchema = UpdateFeedSchema;\r\n bee: Bee;\r\n config: SwarmConfig;\r\n \r\n constructor(params: {\r\n hederaKit: HederaAgentKit;\r\n config: SwarmConfig;\r\n logger?: GenericPluginContext['logger'];\r\n bee: Bee;\r\n }) {\r\n const { bee, config, ...rest } = params;\r\n super(rest);\r\n this.bee = bee;\r\n this.config = config;\r\n }\r\n \r\n protected async executeQuery(\r\n input: z.infer<typeof UpdateFeedSchema>\r\n ): Promise<ToolResponse | string> {\r\n const { data, memoryTopic, postageBatchId: inputPostageBatchId } = input;\r\n if (!data) {\r\n this.logger.error(\r\n 'Missing required parameter: data.'\r\n );\r\n\r\n throw new Error('Missing required parameter: data.');\r\n } else if (!memoryTopic) {\r\n this.logger.error(\r\n 'Missing required parameter: topic.'\r\n );\r\n\r\n throw new Error('Missing required parameter: topic.');\r\n }\r\n \r\n let postageBatchId = \"\";\r\n\r\n try {\r\n postageBatchId = await getUploadPostageBatchId(\r\n inputPostageBatchId,\r\n this.bee,\r\n this.config,\r\n );\r\n } catch (error) {\r\n let errorMessage = 'Update feed failed.';\r\n if (error instanceof Error) {\r\n errorMessage = error.message;\r\n }\r\n this.logger.error(errorMessage);\r\n\r\n throw new Error(errorMessage);\r\n }\r\n\r\n const binaryData = Buffer.from(data);\r\n\r\n // Feed upload if memoryTopic is specified\r\n if (!this.config.beeFeedPK) {\r\n this.logger.error('Feed private key not configured.');\r\n\r\n throw new Error('Feed private key not configured.');\r\n }\r\n\r\n // Process topic - if not a hex string, hash it\r\n let topic = memoryTopic;\r\n if (topic.startsWith(\"0x\")) {\r\n topic = topic.slice(2);\r\n }\r\n const isHexString = /^[0-9a-fA-F]{64}$/.test(memoryTopic);\r\n\r\n if (!isHexString) {\r\n // Hash the topic string using SHA-256\r\n const hash = crypto\r\n .createHash(\"sha256\")\r\n .update(memoryTopic)\r\n .digest(\"hex\");\r\n topic = hash;\r\n }\r\n\r\n // Convert topic string to bytes\r\n const topicBytes = hexToBytes(topic);\r\n\r\n const feedPrivateKey = hexToBytes(this.config.beeFeedPK);\r\n const signer = new Wallet(feedPrivateKey);\r\n const owner = signer.getAddressString().slice(2);\r\n\r\n let result;\r\n\r\n try {\r\n const feedWriter = this.bee.makeFeedWriter(topicBytes, feedPrivateKey);\r\n\r\n result = await feedWriter.uploadPayload(postageBatchId!, binaryData);\r\n } catch (error) {\r\n let errorMessage = 'Unable to update feed.';\r\n\r\n if (errorHasStatus(error, BAD_REQUEST_STATUS)) {\r\n errorMessage = getErrorMessage(error);\r\n }\r\n\r\n this.logger.error(\r\n errorMessage,\r\n error\r\n );\r\n \r\n throw new Error(errorMessage);\r\n }\r\n\r\n const reference = result.reference.toString();\r\n\r\n return getResponseWithStructuredContent({\r\n reference,\r\n topicString: memoryTopic,\r\n topic: topic,\r\n feedUrl: `${this.bee.url}/feeds/${owner}/${topic}`,\r\n message: 'Data successfully uploaded to Swarm and linked to feed.',\r\n });\r\n }\r\n}\r\n"],"names":[],"mappings":";;;;;;AAoBA,MAAM,mBAAmB,EAAE,OAAO;AAAA,EAChC,MAAM,EAAE,OAAA;AAAA,EACR,aAAa,EAAE,OAAA;AAAA,EACf,gBAAgB,EAAE,OAAA,EAAS,SAAA;AAC7B,CAAC;AAEM,MAAM,uBAAuB,oBAA6C;AAAA,EAW/E,YAAY,QAKT;AACD,UAAM,EAAE,KAAK,QAAQ,GAAG,SAAS;AACjC,UAAM,IAAI;AAjBZ,SAAA,OAAO;AACP,SAAA,cAAc;AAAA;AAAA;AAAA;AAId,SAAA,YAAY;AACZ,SAAA,sBAAsB;AAYpB,SAAK,MAAM;AACX,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,MAAgB,aACZ,OAC8B;AAChC,UAAM,EAAE,MAAM,aAAa,gBAAgB,wBAAyB;A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