Skip to content

Commit c14261c

Browse files
committed
chore: resolve domain suins return readable day
1 parent d590ddb commit c14261c

File tree

5 files changed

+35
-4
lines changed

5 files changed

+35
-4
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"axios": "^1.7.9",
3838
"bignumber.js": "^9.1.2",
3939
"bn.js": "^5.2.1",
40+
"dayjs": "^1.11.13",
4041
"dotenv": "^16.4.7",
4142
"langchain": "^0.3.8",
4243
"openai": "^4.77.0",

pnpm-lock.yaml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/langchain/agent/get_sns_name_record.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ export class SuiGetSnsNameRecordTool extends Tool {
55
name = "sui_get_sns_name_record";
66
description = `Get information about a registered Sui Name Service (SNS) domain.
77
8-
Inputs (input is a string): The domain name to look up`;
8+
Inputs (input is a string): The domain name to look up
9+
10+
The output response have expirationTimestampMs in milliseconds, convert it to human readable format
11+
- the time human readable will be display main
12+
- the time in miliseconds put in the parentheses
13+
14+
`;
915

1016
constructor(private suiKit: SuiAgentKit) {
1117
super();

src/tools/sns/ get_name.ts

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { SuinsClient } from "@mysten/suins";
22
import { SuiAgentKit } from "../../index";
3-
import { NameRecord } from "@mysten/suins/dist/cjs/types";
3+
import { NameRecordX } from "../../types";
44
import logger from "../../utils/logger";
5+
import dayjs from "dayjs";
56

67
/**
78
* Get the NameRecord object for a given domain name
@@ -12,7 +13,7 @@ import logger from "../../utils/logger";
1213
export async function get_name_record(
1314
agent: SuiAgentKit,
1415
name: string,
15-
): Promise<NameRecord | null> {
16+
): Promise<NameRecordX | null> {
1617
try {
1718
const suinsClient = new SuinsClient({
1819
client: agent.client as any,
@@ -27,8 +28,18 @@ export async function get_name_record(
2728

2829
// Create a transaction block as usual in your PTBs.
2930
const nameRecord = await suinsClient.getNameRecord(name);
31+
if (!nameRecord) {
32+
return null;
33+
}
34+
35+
const humanReadableExpirationTimestampMs = dayjs(
36+
Number(nameRecord.expirationTimestampMs),
37+
).format("YYYY-MM-DD"); // Format to match expected output
3038

31-
return nameRecord;
39+
return {
40+
...nameRecord,
41+
humanReadableExpirationTimestampMs,
42+
};
3243
} catch (error: any) {
3344
logger.error(error);
3445
throw error;

src/types/index.ts

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { SuiAgentKit } from "../agent";
22
import { z } from "zod";
3+
import { NameRecord } from "@mysten/suins/dist/cjs/types";
34

45
export interface Config {
56
BASE_URL?: string;
@@ -262,3 +263,7 @@ export interface ISwapParams {
262263
inputAmount: number;
263264
slippage: number | undefined;
264265
}
266+
267+
export interface NameRecordX extends NameRecord {
268+
humanReadableExpirationTimestampMs: string;
269+
}

0 commit comments

Comments
 (0)