@hashgraphonline/standards-agent-kit 0.0.32 → 0.0.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/src/init/index.d.ts +1 -0
- package/dist/cjs/src/{init.d.ts → init/init.d.ts} +16 -16
- package/dist/cjs/standards-agent-kit.cjs +1 -1
- package/dist/cjs/standards-agent-kit.cjs.map +1 -1
- package/dist/es/src/init/index.d.ts +1 -0
- package/dist/es/src/{init.d.ts → init/init.d.ts} +16 -16
- package/dist/es/standards-agent-kit.es.js +17 -17
- package/dist/es/standards-agent-kit.es10.js +65 -104
- package/dist/es/standards-agent-kit.es10.js.map +1 -1
- package/dist/es/standards-agent-kit.es11.js +371 -66
- package/dist/es/standards-agent-kit.es11.js.map +1 -1
- package/dist/es/standards-agent-kit.es12.js +153 -348
- package/dist/es/standards-agent-kit.es12.js.map +1 -1
- package/dist/es/standards-agent-kit.es13.js +105 -161
- package/dist/es/standards-agent-kit.es13.js.map +1 -1
- package/dist/es/standards-agent-kit.es14.js +48 -126
- package/dist/es/standards-agent-kit.es14.js.map +1 -1
- package/dist/es/standards-agent-kit.es15.js +108 -50
- package/dist/es/standards-agent-kit.es15.js.map +1 -1
- package/dist/es/standards-agent-kit.es16.js +239 -117
- package/dist/es/standards-agent-kit.es16.js.map +1 -1
- package/dist/es/standards-agent-kit.es17.js +120 -245
- package/dist/es/standards-agent-kit.es17.js.map +1 -1
- package/dist/es/standards-agent-kit.es2.js +321 -114
- package/dist/es/standards-agent-kit.es2.js.map +1 -1
- package/dist/es/standards-agent-kit.es23.js +15 -15
- package/dist/es/standards-agent-kit.es24.js +3 -24
- package/dist/es/standards-agent-kit.es24.js.map +1 -1
- package/dist/es/standards-agent-kit.es25.js +81 -3
- package/dist/es/standards-agent-kit.es25.js.map +1 -1
- package/dist/es/standards-agent-kit.es26.js +22 -79
- package/dist/es/standards-agent-kit.es26.js.map +1 -1
- package/dist/es/standards-agent-kit.es3.js +347 -284
- package/dist/es/standards-agent-kit.es3.js.map +1 -1
- package/dist/es/standards-agent-kit.es4.js +56 -366
- package/dist/es/standards-agent-kit.es4.js.map +1 -1
- package/dist/es/standards-agent-kit.es5.js +142 -58
- package/dist/es/standards-agent-kit.es5.js.map +1 -1
- package/dist/es/standards-agent-kit.es6.js +73 -143
- package/dist/es/standards-agent-kit.es6.js.map +1 -1
- package/dist/es/standards-agent-kit.es7.js +65 -64
- package/dist/es/standards-agent-kit.es7.js.map +1 -1
- package/dist/es/standards-agent-kit.es8.js +91 -77
- package/dist/es/standards-agent-kit.es8.js.map +1 -1
- package/dist/es/standards-agent-kit.es9.js +109 -90
- package/dist/es/standards-agent-kit.es9.js.map +1 -1
- package/dist/umd/src/init/index.d.ts +1 -0
- package/dist/umd/src/{init.d.ts → init/init.d.ts} +16 -16
- package/dist/umd/standards-agent-kit.umd.js +2 -2
- package/dist/umd/standards-agent-kit.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/init/index.ts +1 -0
- package/src/{init.ts → init/init.ts} +22 -20
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './init';
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { HCS10Client, StandardNetworkType } from '
|
|
2
|
-
import { RegisterAgentTool } from '
|
|
3
|
-
import { SendMessageTool } from '
|
|
4
|
-
import { ConnectionTool } from '
|
|
5
|
-
import { IStateManager } from '
|
|
6
|
-
import { FindRegistrationsTool } from '
|
|
7
|
-
import { InitiateConnectionTool } from '
|
|
8
|
-
import { ListConnectionsTool } from '
|
|
9
|
-
import { SendMessageToConnectionTool } from '
|
|
10
|
-
import { CheckMessagesTool } from '
|
|
11
|
-
import { ConnectionMonitorTool } from '
|
|
12
|
-
import { ManageConnectionRequestsTool } from '
|
|
13
|
-
import { AcceptConnectionRequestTool } from '
|
|
14
|
-
import { RetrieveProfileTool } from '
|
|
15
|
-
import { ListUnapprovedConnectionRequestsTool } from '
|
|
1
|
+
import { HCS10Client, StandardNetworkType } from '../hcs10/HCS10Client';
|
|
2
|
+
import { RegisterAgentTool } from '../tools/RegisterAgentTool';
|
|
3
|
+
import { SendMessageTool } from '../tools/SendMessageTool';
|
|
4
|
+
import { ConnectionTool } from '../tools/ConnectionTool';
|
|
5
|
+
import { IStateManager } from '../state/state-types';
|
|
6
|
+
import { FindRegistrationsTool } from '../tools/FindRegistrationsTool';
|
|
7
|
+
import { InitiateConnectionTool } from '../tools/InitiateConnectionTool';
|
|
8
|
+
import { ListConnectionsTool } from '../tools/ListConnectionsTool';
|
|
9
|
+
import { SendMessageToConnectionTool } from '../tools/SendMessageToConnectionTool';
|
|
10
|
+
import { CheckMessagesTool } from '../tools/CheckMessagesTool';
|
|
11
|
+
import { ConnectionMonitorTool } from '../tools/ConnectionMonitorTool';
|
|
12
|
+
import { ManageConnectionRequestsTool } from '../tools/ManageConnectionRequestsTool';
|
|
13
|
+
import { AcceptConnectionRequestTool } from '../tools/AcceptConnectionRequestTool';
|
|
14
|
+
import { RetrieveProfileTool } from '../tools/RetrieveProfileTool';
|
|
15
|
+
import { ListUnapprovedConnectionRequestsTool } from '../tools/ListUnapprovedConnectionRequestsTool';
|
|
16
16
|
export interface HCS10ClientConfig {
|
|
17
17
|
operatorId?: string;
|
|
18
18
|
operatorKey?: string;
|
|
@@ -51,7 +51,7 @@ export interface HCS10Tools {
|
|
|
51
51
|
* @param options - Initialization options
|
|
52
52
|
* @returns Object containing hcs10Client and requested tools
|
|
53
53
|
*/
|
|
54
|
-
export declare
|
|
54
|
+
export declare const initializeStandardsAgentKit: (options?: HCS10InitializationOptions) => {
|
|
55
55
|
hcs10Client: HCS10Client;
|
|
56
56
|
monitoringClient?: HCS10Client;
|
|
57
57
|
tools: Partial<HCS10Tools>;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
1
|
+
import { HCS10Client } from "./standards-agent-kit.es2.js";
|
|
2
|
+
import { RegisterAgentTool } from "./standards-agent-kit.es3.js";
|
|
3
|
+
import { SendMessageTool } from "./standards-agent-kit.es4.js";
|
|
4
|
+
import { ConnectionTool } from "./standards-agent-kit.es5.js";
|
|
5
|
+
import { SendMessageToConnectionTool } from "./standards-agent-kit.es6.js";
|
|
6
|
+
import { InitiateConnectionTool } from "./standards-agent-kit.es7.js";
|
|
7
|
+
import { ListConnectionsTool } from "./standards-agent-kit.es8.js";
|
|
8
|
+
import { CheckMessagesTool } from "./standards-agent-kit.es9.js";
|
|
9
|
+
import { FindRegistrationsTool } from "./standards-agent-kit.es10.js";
|
|
10
|
+
import { ConnectionMonitorTool } from "./standards-agent-kit.es11.js";
|
|
11
|
+
import { ManageConnectionRequestsTool } from "./standards-agent-kit.es12.js";
|
|
12
|
+
import { AcceptConnectionRequestTool } from "./standards-agent-kit.es13.js";
|
|
13
|
+
import { RetrieveProfileTool } from "./standards-agent-kit.es14.js";
|
|
14
|
+
import { ListUnapprovedConnectionRequestsTool } from "./standards-agent-kit.es15.js";
|
|
15
|
+
import { OpenConvaiState } from "./standards-agent-kit.es16.js";
|
|
16
|
+
import { initializeStandardsAgentKit } from "./standards-agent-kit.es17.js";
|
|
17
17
|
import { PluginRegistry } from "./standards-agent-kit.es18.js";
|
|
18
18
|
import { BasePlugin } from "./standards-agent-kit.es19.js";
|
|
19
19
|
import { PluginLoader } from "./standards-agent-kit.es20.js";
|
|
@@ -43,6 +43,6 @@ export {
|
|
|
43
43
|
RetrieveProfileTool,
|
|
44
44
|
SendMessageToConnectionTool,
|
|
45
45
|
SendMessageTool,
|
|
46
|
-
|
|
46
|
+
initializeStandardsAgentKit
|
|
47
47
|
};
|
|
48
48
|
//# sourceMappingURL=standards-agent-kit.es.js.map
|
|
@@ -1,132 +1,93 @@
|
|
|
1
1
|
import { StructuredTool } from "@langchain/core/tools";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import { Logger } from "@hashgraphonline/standards-sdk";
|
|
4
|
-
class
|
|
5
|
-
constructor({ hcsClient,
|
|
3
|
+
import { AIAgentCapability, Logger } from "@hashgraphonline/standards-sdk";
|
|
4
|
+
class FindRegistrationsTool extends StructuredTool {
|
|
5
|
+
constructor({ hcsClient, ...rest }) {
|
|
6
6
|
super(rest);
|
|
7
|
-
this.name = "
|
|
8
|
-
this.description =
|
|
9
|
-
Identify the target agent using their account ID (e.g., 0.0.12345) or the connection number shown in 'list_connections'.
|
|
10
|
-
By default, it only retrieves messages newer than the last check.
|
|
11
|
-
Use 'fetchLatest: true' to get the most recent messages regardless of when they arrived.
|
|
12
|
-
Use 'lastMessagesCount' to specify how many latest messages to retrieve (default 1 when fetchLatest is true).`;
|
|
7
|
+
this.name = "find_registrations";
|
|
8
|
+
this.description = "Searches the configured agent registry for HCS-10 agents. You can filter by account ID or tags. Returns basic registration info.";
|
|
13
9
|
this.schema = z.object({
|
|
14
|
-
|
|
15
|
-
"
|
|
10
|
+
accountId: z.string().optional().describe(
|
|
11
|
+
"Optional: Filter registrations by a specific Hedera account ID (e.g., 0.0.12345)."
|
|
16
12
|
),
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
),
|
|
20
|
-
lastMessagesCount: z.number().int().positive().optional().describe(
|
|
21
|
-
"When fetchLatest is true, specifies how many of the most recent messages to retrieve. Defaults to 1."
|
|
13
|
+
tags: z.array(z.nativeEnum(AIAgentCapability)).optional().describe(
|
|
14
|
+
"Optional: Filter registrations by a list of tags (API filter only)."
|
|
22
15
|
)
|
|
23
16
|
});
|
|
24
17
|
this.hcsClient = hcsClient;
|
|
25
|
-
this.
|
|
26
|
-
this.logger = Logger.getInstance({ module: "CheckMessagesTool" });
|
|
18
|
+
this.logger = Logger.getInstance({ module: "FindRegistrationsTool" });
|
|
27
19
|
}
|
|
28
20
|
async _call({
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
lastMessagesCount
|
|
21
|
+
accountId,
|
|
22
|
+
tags
|
|
32
23
|
}) {
|
|
33
|
-
const connection = this.stateManager.getConnectionByIdentifier(targetIdentifier);
|
|
34
|
-
if (!connection) {
|
|
35
|
-
return `Error: Could not find an active connection matching identifier "${targetIdentifier}". Use 'list_connections' to see active connections.`;
|
|
36
|
-
}
|
|
37
|
-
const connectionTopicId = connection.connectionTopicId;
|
|
38
|
-
const targetAgentName = connection.targetAgentName;
|
|
39
|
-
const lastProcessedTimestamp = this.stateManager.getLastTimestamp(connectionTopicId);
|
|
40
24
|
this.logger.info(
|
|
41
|
-
|
|
25
|
+
"Searching registrations with filters - Account ID",
|
|
26
|
+
JSON.stringify({
|
|
27
|
+
accountId,
|
|
28
|
+
tags
|
|
29
|
+
})
|
|
42
30
|
);
|
|
31
|
+
const options = {};
|
|
32
|
+
if (accountId) {
|
|
33
|
+
options.accountId = accountId;
|
|
34
|
+
}
|
|
35
|
+
if (tags && tags.length > 0) {
|
|
36
|
+
options.tags = tags;
|
|
37
|
+
}
|
|
38
|
+
options.network = this.hcsClient.getNetwork();
|
|
43
39
|
try {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return `No messages found on connection topic ${connectionTopicId}.`;
|
|
48
|
-
}
|
|
49
|
-
let messagesToProcess = [];
|
|
50
|
-
let latestTimestampNanos = lastProcessedTimestamp;
|
|
51
|
-
const isFetchingLatest = fetchLatest === true;
|
|
52
|
-
if (isFetchingLatest) {
|
|
53
|
-
this.logger.info("Fetching latest messages regardless of timestamp.");
|
|
54
|
-
const count = lastMessagesCount ?? 1;
|
|
55
|
-
messagesToProcess = allMessages.slice(-count);
|
|
56
|
-
} else {
|
|
57
|
-
this.logger.info(
|
|
58
|
-
`Filtering for messages newer than ${lastProcessedTimestamp}`
|
|
40
|
+
if (!this.hcsClient.standardClient) {
|
|
41
|
+
throw new Error(
|
|
42
|
+
"Standard SDK client instance is not available in HCS10Client wrapper."
|
|
59
43
|
);
|
|
60
|
-
messagesToProcess = allMessages.filter((msg) => {
|
|
61
|
-
const msgTimestampNanos = msg.timestamp * 1e6;
|
|
62
|
-
return msgTimestampNanos > lastProcessedTimestamp;
|
|
63
|
-
});
|
|
64
|
-
if (messagesToProcess.length > 0) {
|
|
65
|
-
latestTimestampNanos = messagesToProcess.reduce(
|
|
66
|
-
(maxTs, msg) => Math.max(maxTs, msg.timestamp * 1e6),
|
|
67
|
-
lastProcessedTimestamp
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
44
|
}
|
|
71
|
-
|
|
72
|
-
|
|
45
|
+
const result = await this.hcsClient.standardClient.findRegistrations(
|
|
46
|
+
options
|
|
47
|
+
);
|
|
48
|
+
if (!result.success || result.error) {
|
|
49
|
+
return `Error finding registrations: ${result.error || "Unknown error"}`;
|
|
50
|
+
}
|
|
51
|
+
if (!result.registrations || result.registrations.length === 0) {
|
|
52
|
+
return "No registrations found matching the criteria.";
|
|
73
53
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
54
|
+
let output = `Found ${result.registrations.length} registration(s):
|
|
55
|
+
`;
|
|
56
|
+
result.registrations.forEach((reg, index) => {
|
|
57
|
+
const metadata = reg.metadata;
|
|
58
|
+
output += `${index + 1}. Name: ${metadata.alias || "N/A"}
|
|
59
|
+
`;
|
|
60
|
+
output += `Description: ${metadata.bio || "N/A"}
|
|
61
|
+
`;
|
|
62
|
+
output += ` Account ID: ${reg.accountId}
|
|
77
63
|
`;
|
|
78
|
-
|
|
79
|
-
let content = msg.data;
|
|
80
|
-
try {
|
|
81
|
-
if (typeof content === "string" && content.startsWith("hcs://")) {
|
|
82
|
-
this.logger.debug(`Resolving inscribed message: ${content}`);
|
|
83
|
-
content = await this.hcsClient.getMessageContent(content);
|
|
84
|
-
this.logger.debug(`Resolved content length: ${content?.length}`);
|
|
85
|
-
}
|
|
86
|
-
let displayContent = content;
|
|
87
|
-
try {
|
|
88
|
-
const parsed = JSON.parse(content || "{}");
|
|
89
|
-
if (parsed.p === "hcs-10" && parsed.op === "message" && parsed.data) {
|
|
90
|
-
const senderOpId = parsed.operator_id || "unknown_sender";
|
|
91
|
-
displayContent = `[${senderOpId}]: ${parsed.data}`;
|
|
92
|
-
} else {
|
|
93
|
-
displayContent = content;
|
|
94
|
-
}
|
|
95
|
-
} catch (parseError) {
|
|
96
|
-
displayContent = content;
|
|
97
|
-
}
|
|
98
|
-
const messageDate = new Date(msg.timestamp);
|
|
99
|
-
outputString += `
|
|
100
|
-
[${messageDate.toLocaleString()}] (Seq: ${msg.sequence_number})
|
|
101
|
-
${displayContent}
|
|
64
|
+
output += ` Status: ${reg.status}
|
|
102
65
|
`;
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
[Error processing message Seq: ${msg.sequence_number}]
|
|
66
|
+
output += ` Model: ${metadata.properties?.model || "N/A"}
|
|
67
|
+
`;
|
|
68
|
+
if (metadata.properties?.capabilities && metadata.properties.capabilities.length > 0) {
|
|
69
|
+
output += ` Capabilities: ${metadata.properties.capabilities.join(", ")}
|
|
108
70
|
`;
|
|
109
71
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
72
|
+
if (metadata.properties) {
|
|
73
|
+
output += ` Properties: ${JSON.stringify(metadata.properties)}
|
|
74
|
+
`;
|
|
75
|
+
}
|
|
76
|
+
output += ` Inbound Topic: ${reg.inboundTopicId}
|
|
77
|
+
`;
|
|
78
|
+
output += ` Outbound Topic: ${reg.outboundTopicId}
|
|
79
|
+
`;
|
|
80
|
+
output += ` Created At: ${reg.createdAt}
|
|
81
|
+
`;
|
|
82
|
+
});
|
|
83
|
+
return output.trim();
|
|
121
84
|
} catch (error) {
|
|
122
|
-
this.logger.error(
|
|
123
|
-
|
|
124
|
-
);
|
|
125
|
-
return `Error checking messages for ${targetAgentName}: ${error instanceof Error ? error.message : String(error)}`;
|
|
85
|
+
this.logger.error(`Failed to execute findRegistrations: ${error}`);
|
|
86
|
+
return `Error searching registrations: ${error instanceof Error ? error.message : String(error)}`;
|
|
126
87
|
}
|
|
127
88
|
}
|
|
128
89
|
}
|
|
129
90
|
export {
|
|
130
|
-
|
|
91
|
+
FindRegistrationsTool
|
|
131
92
|
};
|
|
132
93
|
//# sourceMappingURL=standards-agent-kit.es10.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standards-agent-kit.es10.js","sources":["../../src/tools/CheckMessagesTool.ts"],"sourcesContent":["import { StructuredTool, ToolParams } from '@langchain/core/tools';\nimport { z } from 'zod';\nimport { HCS10Client, HCSMessageWithTimestamp } from '../hcs10/HCS10Client';\nimport { IStateManager } from '../state/state-types';\nimport { Logger } from '@hashgraphonline/standards-sdk'; // Assuming logger utility\n\nexport interface CheckMessagesToolParams extends ToolParams {\n hcsClient: HCS10Client;\n stateManager: IStateManager;\n}\n\n/**\n * A tool to check for new messages on an active HCS-10 connection topic,\n * or optionally fetch the latest messages regardless of timestamp.\n */\nexport class CheckMessagesTool extends StructuredTool {\n name = 'check_messages';\n description = `Checks for and retrieves messages from an active connection. \nIdentify the target agent using their account ID (e.g., 0.0.12345) or the connection number shown in 'list_connections'. \nBy default, it only retrieves messages newer than the last check. \nUse 'fetchLatest: true' to get the most recent messages regardless of when they arrived. \nUse 'lastMessagesCount' to specify how many latest messages to retrieve (default 1 when fetchLatest is true).`;\n schema = z.object({\n targetIdentifier: z\n .string()\n .describe(\n \"The account ID (e.g., 0.0.12345) of the target agent OR the connection number (e.g., '1', '2') from the 'list_connections' tool to check messages for.\"\n ),\n fetchLatest: z\n .boolean()\n .optional()\n .default(false)\n .describe(\n 'Set to true to fetch the latest messages even if they have been seen before, ignoring the last checked timestamp. Defaults to false (fetching only new messages).'\n ),\n lastMessagesCount: z\n .number()\n .int()\n .positive()\n .optional()\n .describe(\n 'When fetchLatest is true, specifies how many of the most recent messages to retrieve. Defaults to 1.'\n ),\n });\n\n public hcsClient: HCS10Client;\n private stateManager: IStateManager;\n private logger: Logger;\n\n constructor({ hcsClient, stateManager, ...rest }: CheckMessagesToolParams) {\n super(rest);\n this.hcsClient = hcsClient;\n this.stateManager = stateManager;\n this.logger = Logger.getInstance({ module: 'CheckMessagesTool' });\n }\n\n protected async _call({\n targetIdentifier,\n fetchLatest,\n lastMessagesCount,\n }: z.infer<this['schema']>): Promise<string> {\n const connection =\n this.stateManager.getConnectionByIdentifier(targetIdentifier);\n\n if (!connection) {\n return `Error: Could not find an active connection matching identifier \"${targetIdentifier}\". Use 'list_connections' to see active connections.`;\n }\n\n const connectionTopicId = connection.connectionTopicId;\n const targetAgentName = connection.targetAgentName;\n const lastProcessedTimestamp =\n this.stateManager.getLastTimestamp(connectionTopicId);\n\n this.logger.info(\n `Checking messages for connection with ${targetAgentName} (${connection.targetAccountId}) on topic ${connectionTopicId} (fetchLatest: ${fetchLatest}, lastCount: ${lastMessagesCount}, since: ${lastProcessedTimestamp})`\n );\n\n try {\n // 1. Get messages from the topic\n const result = await this.hcsClient.getMessages(connectionTopicId);\n const allMessages = result.messages;\n\n if (!allMessages || allMessages.length === 0) {\n return `No messages found on connection topic ${connectionTopicId}.`;\n }\n\n let messagesToProcess: HCSMessageWithTimestamp[] = [];\n let latestTimestampNanos = lastProcessedTimestamp;\n const isFetchingLatest = fetchLatest === true;\n\n if (isFetchingLatest) {\n this.logger.info('Fetching latest messages regardless of timestamp.');\n const count = lastMessagesCount ?? 1;\n messagesToProcess = allMessages.slice(-count);\n } else {\n this.logger.info(\n `Filtering for messages newer than ${lastProcessedTimestamp}`\n );\n messagesToProcess = allMessages.filter((msg) => {\n const msgTimestampNanos = msg.timestamp * 1_000_000;\n return msgTimestampNanos > lastProcessedTimestamp;\n });\n \n if (messagesToProcess.length > 0) {\n latestTimestampNanos = messagesToProcess.reduce(\n (maxTs, msg) => Math.max(maxTs, msg.timestamp * 1_000_000),\n lastProcessedTimestamp\n );\n }\n }\n\n if (messagesToProcess.length === 0) {\n return isFetchingLatest\n ? `Could not retrieve the latest message(s). No messages found on topic ${connectionTopicId}.`\n : `No new messages found for connection with ${targetAgentName} since last check.`;\n }\n\n this.logger.info(`Processing ${messagesToProcess.length} message(s).`);\n\n // 3. Process messages (resolve inscriptions, format)\n let outputString = isFetchingLatest\n ? `Latest message(s) from ${targetAgentName}:\n`\n : `New messages from ${targetAgentName}:\n`;\n\n for (const msg of messagesToProcess) {\n let content = msg.data;\n try {\n // Check for inscription HRL\n if (typeof content === 'string' && content.startsWith('hcs://')) {\n this.logger.debug(`Resolving inscribed message: ${content}`);\n content = await this.hcsClient.getMessageContent(content);\n this.logger.debug(`Resolved content length: ${content?.length}`);\n }\n\n // Attempt to parse the content as the HCS-10 structure\n let displayContent = content; // Default to raw content\n try {\n const parsed = JSON.parse(content || '{}');\n if (\n parsed.p === 'hcs-10' &&\n parsed.op === 'message' &&\n parsed.data\n ) {\n // Extract sender and actual data from standard message format\n const senderOpId = parsed.operator_id || 'unknown_sender';\n displayContent = `[${senderOpId}]: ${parsed.data}`;\n } else {\n // If not standard format, maybe just show raw stringified version\n displayContent = content; // Keep raw if parsing worked but not expected format\n }\n } catch (parseError) {\n // Content wasn't JSON, keep raw content\n displayContent = content;\n }\n\n const messageDate = new Date(msg.timestamp);\n outputString += `\\n[${messageDate.toLocaleString()}] (Seq: ${\n msg.sequence_number\n })\n${displayContent}\n`;\n } catch (error) {\n const errorMsg = `Error processing message (Seq: ${\n msg.sequence_number\n }): ${error instanceof Error ? error.message : String(error)}`;\n this.logger.error(errorMsg);\n outputString += `\\n[Error processing message Seq: ${msg.sequence_number}]\\n`;\n }\n }\n\n // 4. Update the timestamp in demo state ONLY if fetching NEW messages\n if (!isFetchingLatest && latestTimestampNanos > lastProcessedTimestamp) {\n this.logger.debug(\n `Updating timestamp for topic ${connectionTopicId} to ${latestTimestampNanos}`\n );\n this.stateManager.updateTimestamp(\n connectionTopicId,\n latestTimestampNanos\n );\n }\n\n return outputString.trim();\n } catch (error) {\n this.logger.error(\n `Failed to check messages for topic ${connectionTopicId}: ${error}`\n );\n return `Error checking messages for ${targetAgentName}: ${\n error instanceof Error ? error.message : String(error)\n }`;\n }\n }\n}\n"],"names":[],"mappings":";;;AAeO,MAAM,0BAA0B,eAAe;AAAA,EAkCpD,YAAY,EAAE,WAAW,cAAc,GAAG,QAAiC;AACzE,UAAM,IAAI;AAlCL,SAAA,OAAA;AACO,SAAA,cAAA;AAAA;AAAA;AAAA;AAAA;AAKd,SAAA,SAAS,EAAE,OAAO;AAAA,MAChB,kBAAkB,EACf,OAAA,EACA;AAAA,QACC;AAAA,MACF;AAAA,MACF,aAAa,EACV,QAAQ,EACR,WACA,QAAQ,KAAK,EACb;AAAA,QACC;AAAA,MACF;AAAA,MACF,mBAAmB,EAChB,SACA,IACA,EAAA,SACA,EAAA,SAAA,EACA;AAAA,QACC;AAAA,MAAA;AAAA,IACF,CACH;AAQC,SAAK,YAAY;AACjB,SAAK,eAAe;AACpB,SAAK,SAAS,OAAO,YAAY,EAAE,QAAQ,qBAAqB;AAAA,EAAA;AAAA,EAGlE,MAAgB,MAAM;AAAA,IACpB;AAAA,IACA;AAAA,IACA;AAAA,EAAA,GAC2C;AAC3C,UAAM,aACJ,KAAK,aAAa,0BAA0B,gBAAgB;AAE9D,QAAI,CAAC,YAAY;AACf,aAAO,mEAAmE,gBAAgB;AAAA,IAAA;AAG5F,UAAM,oBAAoB,WAAW;AACrC,UAAM,kBAAkB,WAAW;AACnC,UAAM,yBACJ,KAAK,aAAa,iBAAiB,iBAAiB;AAEtD,SAAK,OAAO;AAAA,MACV,yCAAyC,eAAe,KAAK,WAAW,eAAe,cAAc,iBAAiB,kBAAkB,WAAW,gBAAgB,iBAAiB,YAAY,sBAAsB;AAAA,IACxN;AAEI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AAI,iBAAiB;AACjB,cAAA;AACF,kBAAM,SAAS,KAAK,MAAM,WAAW,IAAI;AACzC,gBACE,OAAO,MAAM,YACb,OAAO,OAAO,aACd,OAAO,MACP;AAEM,oBAAA,aAAa,OAAO,eAAe;AACzC,+BAAiB,IAAI,UAAU,MAAM,OAAO,IAAI;AAAA,YAAA,OAC3C;AAEY,+BAAA;AAAA,YAAA;AAAA,mBAEZ,YAAY;AAEF,6BAAA;AAAA,UAAA;AAGnB,gBAAM,cAAc,IAAI,KAAK,IAAI,SAAS;AAC1B,0BAAA;AAAA,GAAM,YAAY,eAAA,CAAgB,WAChD,IAAI,eACN;AAAA,EACR,cAAc;AAAA;AAAA,iBAEC,OAAO;AACR,gBAAA,WAAW,kCACf,IAAI,eACN,MAAM,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;AACvD,eAAA,OAAO,MAAM,QAAQ;AACV,0BAAA;AAAA,iCAAoC,IAAI,eAAe;AAAA;AAAA,QAAA;AAAA,MACzE;AAIE,UAAA,CAAC,oBAAoB,uBAAuB,wBAAwB;AACtE,aAAK,OAAO;AAAA,UACV,gCAAgC,iBAAiB,OAAO,oBAAoB;AAAA,QAC9E;AACA,aAAK,aAAa;AAAA,UAChB;AAAA,UACA;AAAA,QACF;AAAA,MAAA;AAGF,aAAO,aAAa,KAAK;AAAA,aAClB,OAAO;AACd,WAAK,OAAO;AAAA,QACV,sCAAsC,iBAAiB,KAAK,KAAK;AAAA,MACnE;AACO,aAAA,+BAA+B,eAAe,KACnD,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CACvD;AAAA,IAAA;AAAA,EACF;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"standards-agent-kit.es10.js","sources":["../../src/tools/FindRegistrationsTool.ts"],"sourcesContent":["import { StructuredTool, ToolParams } from '@langchain/core/tools';\nimport { z } from 'zod';\nimport { HCS10Client } from '../hcs10/HCS10Client';\nimport {\n AIAgentCapability,\n Logger,\n RegistrationSearchOptions,\n} from '@hashgraphonline/standards-sdk';\n\nexport interface FindRegistrationsToolParams extends ToolParams {\n hcsClient: HCS10Client;\n}\n\n/**\n * A tool to search for registered HCS-10 agents using the configured registry.\n */\nexport class FindRegistrationsTool extends StructuredTool {\n name = 'find_registrations';\n description =\n 'Searches the configured agent registry for HCS-10 agents. You can filter by account ID or tags. Returns basic registration info.';\n schema = z.object({\n accountId: z\n .string()\n .optional()\n .describe(\n 'Optional: Filter registrations by a specific Hedera account ID (e.g., 0.0.12345).'\n ),\n tags: z\n .array(z.nativeEnum(AIAgentCapability))\n .optional()\n .describe(\n 'Optional: Filter registrations by a list of tags (API filter only).'\n ),\n });\n\n private hcsClient: HCS10Client;\n private logger: Logger;\n\n constructor({ hcsClient, ...rest }: FindRegistrationsToolParams) {\n super(rest);\n this.hcsClient = hcsClient;\n this.logger = Logger.getInstance({ module: 'FindRegistrationsTool' });\n }\n\n protected async _call({\n accountId,\n tags,\n }: z.infer<this['schema']>): Promise<string> {\n this.logger.info(\n 'Searching registrations with filters - Account ID',\n JSON.stringify({\n accountId,\n tags,\n })\n );\n\n const options: RegistrationSearchOptions = {};\n if (accountId) {\n options.accountId = accountId;\n }\n if (tags && tags.length > 0) {\n options.tags = tags;\n }\n options.network = this.hcsClient.getNetwork();\n\n try {\n if (!this.hcsClient.standardClient) {\n throw new Error(\n 'Standard SDK client instance is not available in HCS10Client wrapper.'\n );\n }\n const result = await this.hcsClient.standardClient.findRegistrations(\n options\n );\n\n if (!result.success || result.error) {\n return `Error finding registrations: ${\n result.error || 'Unknown error'\n }`;\n }\n\n if (!result.registrations || result.registrations.length === 0) {\n return 'No registrations found matching the criteria.';\n }\n\n // Format the results based on available data from RegistrationSearchResult\n let output = `Found ${result.registrations.length} registration(s):\\n`;\n result.registrations.forEach((reg, index: number) => {\n const metadata = reg.metadata;\n output += `${index + 1}. Name: ${metadata.alias || 'N/A'}\\n`;\n output += `Description: ${metadata.bio || 'N/A'}\\n`;\n output += ` Account ID: ${reg.accountId}\\n`;\n output += ` Status: ${reg.status}\\n`;\n output += ` Model: ${metadata.properties?.model || 'N/A'}\\n`;\n if (metadata.properties?.capabilities && metadata.properties.capabilities.length > 0) {\n output += ` Capabilities: ${metadata.properties.capabilities.join(', ')}\\n`;\n }\n if (metadata.properties) {\n output += ` Properties: ${JSON.stringify(metadata.properties)}\\n`;\n }\n output += ` Inbound Topic: ${reg.inboundTopicId}\\n`;\n output += ` Outbound Topic: ${reg.outboundTopicId}\\n`;\n output += ` Created At: ${reg.createdAt}\\n`;\n });\n\n return output.trim();\n } catch (error) {\n this.logger.error(`Failed to execute findRegistrations: ${error}`);\n return `Error searching registrations: ${\n error instanceof Error ? error.message : String(error)\n }`;\n }\n }\n}\n"],"names":[],"mappings":";;;AAgBO,MAAM,8BAA8B,eAAe;AAAA,EAsBxD,YAAY,EAAE,WAAW,GAAG,QAAqC;AAC/D,UAAM,IAAI;AAtBL,SAAA,OAAA;AAEL,SAAA,cAAA;AACF,SAAA,SAAS,EAAE,OAAO;AAAA,MAChB,WAAW,EACR,SACA,SACA,EAAA;AAAA,QACC;AAAA,MACF;AAAA,MACF,MAAM,EACH,MAAM,EAAE,WAAW,iBAAiB,CAAC,EACrC,SAAA,EACA;AAAA,QACC;AAAA,MAAA;AAAA,IACF,CACH;AAOC,SAAK,YAAY;AACjB,SAAK,SAAS,OAAO,YAAY,EAAE,QAAQ,yBAAyB;AAAA,EAAA;AAAA,EAGtE,MAAgB,MAAM;AAAA,IACpB;AAAA,IACA;AAAA,EAAA,GAC2C;AAC3C,SAAK,OAAO;AAAA,MACV;AAAA,MACA,KAAK,UAAU;AAAA,QACb;AAAA,QACA;AAAA,MACD,CAAA;AAAA,IACH;AAEA,UAAM,UAAqC,CAAC;AAC5C,QAAI,WAAW;AACb,cAAQ,YAAY;AAAA,IAAA;AAElB,QAAA,QAAQ,KAAK,SAAS,GAAG;AAC3B,cAAQ,OAAO;AAAA,IAAA;AAET,YAAA,UAAU,KAAK,UAAU,WAAW;AAExC,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