@hashgraphonline/standards-sdk
Version:
The Hashgraph Online Standards SDK provides a complete implementation of the Hashgraph Consensus Standards (HCS), giving developers all the tools needed to build applications on Hedera.
153 lines (152 loc) • 3.96 kB
JavaScript
import { InboundTopicType } from "./standards-sdk.es15.js";
import { Logger } from "./standards-sdk.es22.js";
class AgentBuilder {
constructor() {
this.config = {};
this.logger = Logger.getInstance({
module: "AgentBuilder"
});
}
setName(name) {
this.config.name = name;
return this;
}
setAlias(alias) {
this.config.alias = alias;
return this;
}
setBio(bio) {
this.config.bio = bio;
return this;
}
/**
* @deprecated Use setBio instead
*/
setDescription(description) {
this.config.bio = description;
return this;
}
setCapabilities(capabilities) {
this.config.capabilities = capabilities;
return this;
}
/**
* @deprecated Use setType instead
*/
setAgentType(type) {
if (!this.config.metadata) {
this.config.metadata = { type };
} else {
this.config.metadata.type = type;
}
return this;
}
setType(type) {
if (!this.config.metadata) {
this.config.metadata = { type };
} else {
this.config.metadata.type = type;
}
return this;
}
setModel(model) {
if (!this.config.metadata) {
this.config.metadata = { type: "manual" };
}
this.config.metadata.model = model;
return this;
}
setCreator(creator) {
if (!this.config.metadata) {
this.config.metadata = { type: "manual" };
}
this.config.metadata.creator = creator;
return this;
}
addSocial(platform, handle) {
if (!this.config.metadata) {
this.config.metadata = { type: "manual" };
}
if (!this.config.metadata.socials) {
this.config.metadata.socials = {};
}
this.config.metadata.socials[platform] = handle;
return this;
}
addProperty(key, value) {
if (!this.config.metadata) {
this.config.metadata = { type: "manual" };
}
if (!this.config.metadata.properties) {
this.config.metadata.properties = {};
}
this.config.metadata.properties[key] = value;
return this;
}
setMetadata(metadata) {
this.config.metadata = metadata;
return this;
}
setProfilePicture(pfpBuffer, pfpFileName) {
this.config.pfpBuffer = pfpBuffer;
this.config.pfpFileName = pfpFileName;
return this;
}
setExistingProfilePicture(pfpTopicId) {
this.config.existingPfpTopicId = pfpTopicId;
return this;
}
setNetwork(network) {
this.config.network = network;
return this;
}
setInboundTopicType(inboundTopicType) {
this.config.inboundTopicType = inboundTopicType;
return this;
}
setFeeConfig(feeConfigBuilder) {
this.config.feeConfig = feeConfigBuilder;
return this;
}
setConnectionFeeConfig(feeConfigBuilder) {
this.config.connectionFeeConfig = feeConfigBuilder;
return this;
}
setExistingAccount(accountId, privateKey) {
this.config.existingAccount = { accountId, privateKey };
return this;
}
build() {
if (!this.config.name) {
throw new Error("Agent display name is required");
}
if (!this.config.bio) {
this.logger?.warn("Agent description is not set");
}
if (!this.config.pfpBuffer && !this.config.existingPfpTopicId) {
this.logger.warn("No profile picture provided or referenced.");
}
if (!this.config.network) {
throw new Error("Network is required");
}
if (!this.config.inboundTopicType) {
this.config.inboundTopicType = InboundTopicType.PUBLIC;
}
if (!this.config.capabilities) {
this.config.capabilities = [];
}
if (!this.config.metadata) {
this.config.metadata = { type: "manual" };
} else if (!this.config.metadata.type) {
this.config.metadata.type = "manual";
}
if (this.config.inboundTopicType === InboundTopicType.FEE_BASED && !this.config.feeConfig) {
throw new Error("Fee configuration is required for fee-based topics");
}
return this.config;
}
}
export {
AgentBuilder
};
//# sourceMappingURL=standards-sdk.es11.js.map