@hashgraphonline/standards-agent-kit
Version:
A modular SDK for building on-chain autonomous agents using Hashgraph Online Standards, including HCS-10 for agent discovery and communication.
74 lines (67 loc) • 2.49 kB
text/typescript
import { z } from 'zod';
import { BaseHCS6TransactionTool } from './base-hcs6-tools';
import { HCS6TransactionToolParams } from './hcs6-tool-params';
import type { TransactionResponse } from 'hedera-agent-kit';
/**
* Schema for updating a dynamic hashinal
*/
const UpdateDynamicHashinalSchema = z.object({
registryTopicId: z.string()
.describe('The registry topic ID that tracks this dynamic hashinal'),
metadata: z.record(z.unknown())
.describe('Updated metadata object for the hashinal'),
data: z.object({
base64: z.string().optional().describe('Base64 encoded data for the updated hashinal'),
url: z.string().optional().describe('URL to fetch updated data from'),
mimeType: z.string().optional().describe('MIME type of the data'),
}).optional()
.describe('Updated data to inscribe'),
memo: z.string()
.optional()
.describe('Optional memo for the update (e.g., "Level up", "Version 2.0")'),
submitKey: z.string()
.describe('Submit key for the registry (required to update)'),
});
export type UpdateDynamicHashinalInput = z.infer<typeof UpdateDynamicHashinalSchema>;
/**
* Tool for updating dynamic hashinals
*/
export class UpdateDynamicHashinalTool extends BaseHCS6TransactionTool<typeof UpdateDynamicHashinalSchema> {
name = 'updateDynamicHashinal';
description = 'Update an existing dynamic hashinal with new content while maintaining the same registry';
schema = UpdateDynamicHashinalSchema;
constructor(params: HCS6TransactionToolParams) {
super(params);
}
protected async _call(
params: UpdateDynamicHashinalInput
): Promise<TransactionResponse> {
try {
// Use the register method with the existing registry ID
const result = await this.hcs6Builder.register({
metadata: params.metadata,
data: params.data,
memo: params.memo,
registryTopicId: params.registryTopicId,
submitKey: params.submitKey,
});
if (!result.success) {
throw new Error(result.error || 'Failed to update dynamic hashinal');
}
return {
status: 'success',
data: {
registryTopicId: result.registryTopicId,
newInscriptionTopicId: result.inscriptionTopicId,
transactionId: result.transactionId,
updateMemo: params.memo,
},
};
} catch (error) {
return {
status: 'error',
message: error instanceof Error ? error.message : 'Unknown error',
};
}
}
}