@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.
66 lines (59 loc) • 2.06 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 creating a dynamic hashinal registry
*/
const CreateDynamicRegistrySchema = z.object({
ttl: z.number()
.min(3600)
.default(86400)
.describe('Time-to-live in seconds (minimum 3600 seconds/1 hour)'),
adminKey: z.union([z.boolean(), z.string()])
.optional()
.describe('Admin key for the registry topic. Can be boolean (use operator key) or a public key string'),
submitKey: z.union([z.boolean(), z.string()])
.optional()
.describe('Submit key for the registry topic. Can be boolean (use operator key) or a public key string'),
});
export type CreateDynamicRegistryInput = z.infer<typeof CreateDynamicRegistrySchema>;
/**
* Tool for creating HCS-6 dynamic registries
*/
export class CreateDynamicRegistryTool extends BaseHCS6TransactionTool<typeof CreateDynamicRegistrySchema> {
name = 'createDynamicRegistry';
description = 'Create a new HCS-6 dynamic registry for managing evolving content';
schema = CreateDynamicRegistrySchema;
constructor(params: HCS6TransactionToolParams) {
super(params);
}
protected async _call(
params: CreateDynamicRegistryInput
): Promise<TransactionResponse> {
try {
const result = await this.hcs6Builder.createRegistry({
ttl: params.ttl,
adminKey: params.adminKey,
submitKey: params.submitKey,
});
if (!result.success) {
throw new Error(result.error || 'Failed to create dynamic registry');
}
return {
status: 'success',
data: {
topicId: result.topicId,
transactionId: result.transactionId,
ttl: params.ttl,
memo: `hcs-6:1:${params.ttl}`,
},
};
} catch (error) {
return {
status: 'error',
message: error instanceof Error ? error.message : 'Unknown error',
};
}
}
}