UNPKG

@hashgraphonline/conversational-agent

Version:

Hashgraph Online conversational AI agent implementing HCS-10 communication, HCS-2 registries, and content inscription on Hedera. https://hol.org

76 lines (75 loc) 2.64 kB
import { BaseHederaQueryTool } from "hedera-agent-kit"; import { z } from "zod"; import { getResponseWithStructuredContent } from "./index62.js"; import { GATEWAY_TAG_ERROR_MESSAGE } from "./index63.js"; const QueryUploadProgressSchema = z.object({ tagId: z.string() }); class QueryUploadProgressTool extends BaseHederaQueryTool { constructor(params) { const { bee, config, ...rest } = params; super(rest); this.name = "swarm-query-upload-progress"; this.description = `Query upload progress for a specific upload session identified with the returned Tag ID. tagId: Tag ID returned by swarm-upload-file and swarm-upload-folder tools to track upload progress. `; this.namespace = "swarm"; this.specificInputSchema = QueryUploadProgressSchema; this.bee = bee; this.config = config; } async executeQuery(input) { if (!input?.tagId) { this.logger.error( "Missing required parameter: tagId." ); throw new Error("Missing required parameter: tagId."); } const tagUid = Number.parseInt(input.tagId, 10); if (Number.isNaN(tagUid)) { this.logger.error( "Invalid tagId format. Expected a numeric string." ); throw new Error("Invalid tagId format. Expected a numeric string."); } try { const tag = await this.bee.retrieveTag(tagUid); const synced = tag.synced ?? 0; const seen = tag.seen ?? 0; const processed = synced + seen; const total = tag.split ?? 0; const startedAt = tag.startedAt; const processedPercentage = total > 0 ? Math.round(processed / total * 100) : 0; const isComplete = processedPercentage === 100; let tagDeleted = false; if (isComplete) { try { await this.bee.deleteTag(tagUid); tagDeleted = true; } catch { } } return getResponseWithStructuredContent({ processedPercentage, message: isComplete ? "Upload completed successfully." : `Upload progress: ${processedPercentage}% processed`, startedAt, tagAddress: tag.address }); } catch (error) { let errorMessage = `Failed to retrieve upload progress: ${error?.message ?? "Unknown error"}`; const status = error?.status ?? error?.response?.status; if (status === 404) { errorMessage = `Tag with ID ${input.tagId} does not exist or has been deleted. ` + GATEWAY_TAG_ERROR_MESSAGE; } this.logger.error( errorMessage, error ); throw new Error(errorMessage); } } } export { QueryUploadProgressTool }; //# sourceMappingURL=index53.js.map