@hashgraphonline/conversational-agent
Version:
Hashgraph Online conversational AI agent implementing HCS-10 communication, HCS-2 registries, and content inscription on Hedera. https://hol.org
59 lines (58 loc) • 1.83 kB
JavaScript
import { BaseHederaQueryTool } from "hedera-agent-kit";
import { z } from "zod";
import { errorHasStatus, getBatchSummary, getResponseWithStructuredContent } from "./index62.js";
import { NOT_FOUND_STATUS, GATEWAY_STAMP_ERROR_MESSAGE } from "./index63.js";
const GetPostageStampSchema = z.object({
postageBatchId: z.string()
});
class GetPostageStampTool extends BaseHederaQueryTool {
constructor(params) {
const { bee, config, ...rest } = params;
super(rest);
this.name = "swarm-get-postage-stamp";
this.description = `Get a specific postage stamp based on postageBatchId.
postageBatchId: The id of the stamp which is requested.
`;
this.namespace = "swarm";
this.specificInputSchema = GetPostageStampSchema;
this.bee = bee;
this.config = config;
}
async executeQuery(input) {
const { postageBatchId } = input;
if (!postageBatchId) {
this.logger.error(
"Missing required parameter: postageBatchId."
);
throw new Error("Missing required parameter: postageBatchId.");
}
let rawPostageBatch;
try {
rawPostageBatch = await this.bee.getPostageBatch(postageBatchId);
} catch (error) {
let errorMessage = "Retrieval of postage batch failed.";
if (errorHasStatus(error, NOT_FOUND_STATUS)) {
errorMessage = GATEWAY_STAMP_ERROR_MESSAGE;
}
this.logger.error(
errorMessage,
error
);
throw new Error(errorMessage);
}
const batch = {
...rawPostageBatch,
batchID: rawPostageBatch.batchID.toHex()
};
const batchSummary = getBatchSummary(rawPostageBatch);
const content = {
raw: batch,
summary: batchSummary
};
return getResponseWithStructuredContent(content);
}
}
export {
GetPostageStampTool
};
//# sourceMappingURL=index55.js.map