@hashgraphonline/conversational-agent 0.2.111 → 0.2.201
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/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/mcp/types.d.ts +14 -3
- package/dist/esm/index10.js +1 -1
- package/dist/esm/index15.js +11 -6
- package/dist/esm/index15.js.map +1 -1
- package/dist/esm/index21.js +1 -1
- package/dist/esm/index23.js +2 -2
- package/dist/esm/index33.js +3 -3
- package/dist/esm/index37.js +1 -1
- package/dist/esm/index42.js +95 -5
- package/dist/esm/index42.js.map +1 -1
- package/dist/esm/index43.js +7 -322
- package/dist/esm/index43.js.map +1 -1
- package/dist/esm/index44.js +24 -181
- package/dist/esm/index44.js.map +1 -1
- package/dist/esm/index45.js +4 -6
- package/dist/esm/index45.js.map +1 -1
- package/dist/esm/index46.js +319 -24
- package/dist/esm/index46.js.map +1 -1
- package/dist/esm/index47.js +174 -85
- package/dist/esm/index47.js.map +1 -1
- package/dist/types/mcp/types.d.ts +14 -3
- package/package.json +2 -3
- package/src/mcp/mcp-client-manager.ts +14 -7
- package/src/mcp/types.ts +15 -3
- package/src/plugins/hbar/AccountBuilder.ts +1 -1
package/dist/cjs/mcp/types.d.ts
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Minimal MCP Tool shape used internally to avoid external type dependency resolution issues.
|
|
3
|
+
* Aligns with MCP tool metadata returned by listTools.
|
|
4
|
+
*/
|
|
5
|
+
export interface BaseMCPTool {
|
|
6
|
+
name: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
/**
|
|
9
|
+
* JSON Schema describing input parameters for the tool.
|
|
10
|
+
* Kept as unknown and validated/converted at the boundary.
|
|
11
|
+
*/
|
|
12
|
+
inputSchema?: unknown;
|
|
13
|
+
}
|
|
3
14
|
export interface MCPServerConfig {
|
|
4
15
|
name: string;
|
|
5
16
|
command: string;
|
|
@@ -16,7 +27,7 @@ export interface MCPServerConfig {
|
|
|
16
27
|
*/
|
|
17
28
|
toolDescriptions?: Record<string, string>;
|
|
18
29
|
}
|
|
19
|
-
export interface MCPToolInfo extends
|
|
30
|
+
export interface MCPToolInfo extends BaseMCPTool {
|
|
20
31
|
serverName: string;
|
|
21
32
|
}
|
|
22
33
|
export interface MCPConnectionStatus {
|
package/dist/esm/index10.js
CHANGED
|
@@ -4,7 +4,7 @@ import { Logger } from "@hashgraphonline/standards-sdk";
|
|
|
4
4
|
import { fieldTypeRegistry } from "./index12.js";
|
|
5
5
|
import { fieldGuidanceRegistry } from "./index13.js";
|
|
6
6
|
import "./index41.js";
|
|
7
|
-
import { FIELD_PRIORITIES } from "./
|
|
7
|
+
import { FIELD_PRIORITIES } from "./index43.js";
|
|
8
8
|
function isZodObjectSchema(schema) {
|
|
9
9
|
return typeof schema === "object" && schema !== null && "shape" in schema;
|
|
10
10
|
}
|
package/dist/esm/index15.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Client } from "@modelcontextprotocol/sdk/client/index";
|
|
2
|
-
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio";
|
|
1
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
|
+
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
3
3
|
import { MCPContentProcessor } from "./index16.js";
|
|
4
4
|
class MCPClientManager {
|
|
5
5
|
constructor(logger, contentStorage) {
|
|
@@ -40,10 +40,15 @@ class MCPClientManager {
|
|
|
40
40
|
await client.connect(transport);
|
|
41
41
|
this.clients.set(config.name, client);
|
|
42
42
|
const toolsResponse = await client.listTools();
|
|
43
|
-
const toolsWithServer = toolsResponse.tools.map((tool) =>
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
const toolsWithServer = toolsResponse.tools.map((tool) => {
|
|
44
|
+
const t = tool;
|
|
45
|
+
const { description, ...rest } = t;
|
|
46
|
+
const base = description !== void 0 && typeof description === "string" ? { ...rest, description } : { ...rest };
|
|
47
|
+
return {
|
|
48
|
+
...base,
|
|
49
|
+
serverName: config.name
|
|
50
|
+
};
|
|
51
|
+
});
|
|
47
52
|
this.tools.set(config.name, toolsWithServer);
|
|
48
53
|
this.logger.info(`Connected to MCP server ${config.name} with ${toolsWithServer.length} tools`);
|
|
49
54
|
return {
|
package/dist/esm/index15.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index15.js","sources":["../../src/mcp/mcp-client-manager.ts"],"sourcesContent":["import { Client } from '@modelcontextprotocol/sdk/client/index';\nimport { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio';\nimport type { MCPServerConfig, MCPToolInfo, MCPConnectionStatus } from './types';\nimport { Logger } from '@hashgraphonline/standards-sdk';\nimport type { ContentStorage } from '../memory/content-storage';\nimport { MCPContentProcessor } from './content-processor';\n\n/**\n * Manages connections to MCP servers and tool discovery\n */\nexport class MCPClientManager {\n private clients: Map<string, Client> = new Map();\n private tools: Map<string, MCPToolInfo[]> = new Map();\n private logger: Logger;\n private contentProcessor?: MCPContentProcessor;\n\n constructor(logger: Logger, contentStorage?: ContentStorage) {\n this.logger = logger;\n if (contentStorage) {\n this.contentProcessor = new MCPContentProcessor(contentStorage, logger);\n }\n }\n\n /**\n * Connect to an MCP server and discover its tools\n */\n async connectServer(config: MCPServerConfig): Promise<MCPConnectionStatus> {\n try {\n if (this.isServerConnected(config.name)) {\n return {\n serverName: config.name,\n connected: false,\n error: `Server ${config.name} is already connected`,\n tools: [],\n };\n }\n\n if (config.transport && config.transport !== 'stdio') {\n throw new Error(`Transport ${config.transport} not yet supported`);\n }\n\n const transport = new StdioClientTransport({\n command: config.command,\n args: config.args,\n ...(config.env && { env: config.env }),\n });\n\n const client = new Client({\n name: `conversational-agent-${config.name}`,\n version: '1.0.0',\n }, {\n capabilities: {},\n });\n\n await client.connect(transport);\n this.clients.set(config.name, client);\n\n const toolsResponse = await client.listTools();\n const toolsWithServer: MCPToolInfo[] = toolsResponse.tools.map(tool => ({\n ...tool,\n serverName: config.name,\n }));\n\n this.tools.set(config.name, toolsWithServer);\n this.logger.info(`Connected to MCP server ${config.name} with ${toolsWithServer.length} tools`);\n\n return {\n serverName: config.name,\n connected: true,\n tools: toolsWithServer,\n };\n } catch (error) {\n this.logger.error(`Failed to connect to MCP server ${config.name}:`, error);\n return {\n serverName: config.name,\n connected: false,\n error: error instanceof Error ? error.message : 'Unknown error',\n tools: [],\n };\n }\n }\n\n /**\n * Execute a tool on a specific MCP server\n */\n async executeTool(serverName: string, toolName: string, args: Record<string, unknown>): Promise<unknown> {\n const client = this.clients.get(serverName);\n if (!client) {\n throw new Error(`MCP server ${serverName} not connected`);\n }\n\n this.logger.debug(`Executing MCP tool ${toolName} on server ${serverName}`, args);\n\n try {\n const result = await client.callTool({\n name: toolName,\n arguments: args,\n });\n\n if (this.contentProcessor) {\n const processed = await this.contentProcessor.processResponse(result, serverName, toolName);\n \n if (processed.wasProcessed) {\n this.logger.debug(\n `Processed MCP response from ${serverName}::${toolName}`,\n {\n referenceCreated: processed.referenceCreated,\n originalSize: processed.originalSize,\n errors: processed.errors\n }\n );\n\n if (processed.errors && processed.errors.length > 0) {\n this.logger.warn(`Content processing warnings for ${serverName}::${toolName}:`, processed.errors);\n }\n }\n\n return processed.content;\n }\n\n return result;\n } catch (error) {\n this.logger.error(`Error executing MCP tool ${toolName}:`, error);\n throw error;\n }\n }\n\n /**\n * Disconnect all MCP servers\n */\n async disconnectAll(): Promise<void> {\n for (const [name, client] of this.clients) {\n try {\n await client.close();\n this.logger.info(`Disconnected from MCP server ${name}`);\n } catch (error) {\n this.logger.error(`Error disconnecting MCP server ${name}:`, error);\n }\n }\n this.clients.clear();\n this.tools.clear();\n }\n\n /**\n * Get all discovered tools from all connected servers\n */\n getAllTools(): MCPToolInfo[] {\n const allTools: MCPToolInfo[] = [];\n for (const tools of this.tools.values()) {\n allTools.push(...tools);\n }\n return allTools;\n }\n\n /**\n * Get tools from a specific server\n */\n getServerTools(serverName: string): MCPToolInfo[] {\n return this.tools.get(serverName) || [];\n }\n\n /**\n * Check if a server is connected\n */\n isServerConnected(serverName: string): boolean {\n return this.clients.has(serverName);\n }\n\n /**\n * Get list of connected server names\n */\n getConnectedServers(): string[] {\n return Array.from(this.clients.keys());\n }\n\n /**\n * Enable content processing with content storage\n */\n enableContentProcessing(contentStorage: ContentStorage): void {\n this.contentProcessor = new MCPContentProcessor(contentStorage, this.logger);\n this.logger.info('Content processing enabled for MCP responses');\n }\n\n /**\n * Disable content processing\n */\n disableContentProcessing(): void {\n delete this.contentProcessor;\n this.logger.info('Content processing disabled for MCP responses');\n }\n\n /**\n * Check if content processing is enabled\n */\n isContentProcessingEnabled(): boolean {\n return this.contentProcessor !== undefined;\n }\n\n /**\n * Analyze a response without processing it (for testing/debugging)\n */\n analyzeResponseContent(response: unknown): unknown {\n if (!this.contentProcessor) {\n throw new Error('Content processing is not enabled');\n }\n return this.contentProcessor.analyzeResponse(response);\n }\n}"],"names":[],"mappings":";;;AAUO,MAAM,iBAAiB;AAAA,EAM5B,YAAY,QAAgB,gBAAiC;AAL7D,SAAQ,8BAAmC,IAAA;AAC3C,SAAQ,4BAAwC,IAAA;AAK9C,SAAK,SAAS;AACd,QAAI,gBAAgB;AAClB,WAAK,mBAAmB,IAAI,oBAAoB,gBAAgB,MAAM;AAAA,IACxE;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,cAAc,QAAuD;AACzE,QAAI;AACF,UAAI,KAAK,kBAAkB,OAAO,IAAI,GAAG;AACvC,eAAO;AAAA,UACL,YAAY,OAAO;AAAA,UACnB,WAAW;AAAA,UACX,OAAO,UAAU,OAAO,IAAI;AAAA,UAC5B,OAAO,CAAA;AAAA,QAAC;AAAA,MAEZ;AAEA,UAAI,OAAO,aAAa,OAAO,cAAc,SAAS;AACpD,cAAM,IAAI,MAAM,aA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AChD,WAAO,KAAK,MAAM,IAAI,UAAU,KAAK,CAAA;AAAA,EACvC;AAAA;AAAA;AAAA;AAAA,EAKA,kBAAkB,YAA6B;AAC7C,WAAO,KAAK,QAAQ,IAAI,UAAU;AAAA,EACpC;AAAA;AAAA;AAAA;AAAA,EAKA,sBAAgC;AAC9B,WAAO,MAAM,KAAK,KAAK,QAAQ,MAAM;AAAA,EACvC;AAAA;AAAA;AAAA;AAAA,EAKA,wBAAwB,gBAAsC;AAC5D,SAAK,mBAAmB,IAAI,oBAAoB,gBAAgB,KAAK,MAAM;AAC3E,SAAK,OAAO,KAAK,8CAA8C;AAAA,EACjE;AAAA;AAAA;AAAA;AAAA,EAKA,2BAAiC;AAC/B,WAAO,KAAK;AACZ,SAAK,OAAO,KAAK,+CAA+C;AAAA,EAClE;AAAA;AAAA;AAAA;AAAA,EAKA,6BAAsC;AACpC,WAAO,KAAK,qBAAqB;AAAA,EACnC;AAAA;AAAA;AAAA;AAAA,EAKA,uBAAuB,UAA4B;AACjD,QAAI,CAAC,KAAK,kBAAkB;AAC1B,YAAM,IAAI,MAAM,mCAAmC;AAAA,IACrD;AACA,WAAO,KAAK,iBAAiB,gBAAgB,QAAQ;AAAA,EACvD;AACF;"}
|
|
1
|
+
{"version":3,"file":"index15.js","sources":["../../src/mcp/mcp-client-manager.ts"],"sourcesContent":["import { Client } from '@modelcontextprotocol/sdk/client/index.js';\nimport { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';\nimport type { MCPServerConfig, MCPToolInfo, MCPConnectionStatus } from './types';\nimport { Logger } from '@hashgraphonline/standards-sdk';\nimport type { ContentStorage } from '../memory/content-storage';\nimport { MCPContentProcessor } from './content-processor';\n\n/**\n * Manages connections to MCP servers and tool discovery\n */\nexport class MCPClientManager {\n private clients: Map<string, Client> = new Map();\n private tools: Map<string, MCPToolInfo[]> = new Map();\n private logger: Logger;\n private contentProcessor?: MCPContentProcessor;\n\n constructor(logger: Logger, contentStorage?: ContentStorage) {\n this.logger = logger;\n if (contentStorage) {\n this.contentProcessor = new MCPContentProcessor(contentStorage, logger);\n }\n }\n\n /**\n * Connect to an MCP server and discover its tools\n */\n async connectServer(config: MCPServerConfig): Promise<MCPConnectionStatus> {\n try {\n if (this.isServerConnected(config.name)) {\n return {\n serverName: config.name,\n connected: false,\n error: `Server ${config.name} is already connected`,\n tools: [],\n };\n }\n\n if (config.transport && config.transport !== 'stdio') {\n throw new Error(`Transport ${config.transport} not yet supported`);\n }\n\n const transport = new StdioClientTransport({\n command: config.command,\n args: config.args,\n ...(config.env && { env: config.env }),\n });\n\n const client = new Client({\n name: `conversational-agent-${config.name}`,\n version: '1.0.0',\n }, {\n capabilities: {},\n });\n\n await client.connect(transport);\n this.clients.set(config.name, client);\n\n const toolsResponse = await client.listTools();\n const toolsWithServer: MCPToolInfo[] = toolsResponse.tools.map((tool: unknown) => {\n const t = tool as { description?: string } & Record<string, unknown>;\n const { description, ...rest } = t;\n const base = description !== undefined && typeof description === 'string'\n ? { ...rest, description }\n : { ...rest };\n return {\n ...(base as Omit<MCPToolInfo, 'serverName'>),\n serverName: config.name,\n } as MCPToolInfo;\n });\n\n this.tools.set(config.name, toolsWithServer);\n this.logger.info(`Connected to MCP server ${config.name} with ${toolsWithServer.length} tools`);\n\n return {\n serverName: config.name,\n connected: true,\n tools: toolsWithServer,\n };\n } catch (error) {\n this.logger.error(`Failed to connect to MCP server ${config.name}:`, error);\n return {\n serverName: config.name,\n connected: false,\n error: error instanceof Error ? error.message : 'Unknown error',\n tools: [],\n };\n }\n }\n\n /**\n * Execute a tool on a specific MCP server\n */\n async executeTool(serverName: string, toolName: string, args: Record<string, unknown>): Promise<unknown> {\n const client = this.clients.get(serverName);\n if (!client) {\n throw new Error(`MCP server ${serverName} not connected`);\n }\n\n this.logger.debug(`Executing MCP tool ${toolName} on server ${serverName}`, args);\n\n try {\n const result = await client.callTool({\n name: toolName,\n arguments: args,\n });\n\n if (this.contentProcessor) {\n const processed = await this.contentProcessor.processResponse(result, serverName, toolName);\n \n if (processed.wasProcessed) {\n this.logger.debug(\n `Processed MCP response from ${serverName}::${toolName}`,\n {\n referenceCreated: processed.referenceCreated,\n originalSize: processed.originalSize,\n errors: processed.errors\n }\n );\n\n if (processed.errors && processed.errors.length > 0) {\n this.logger.warn(`Content processing warnings for ${serverName}::${toolName}:`, processed.errors);\n }\n }\n\n return processed.content;\n }\n\n return result;\n } catch (error) {\n this.logger.error(`Error executing MCP tool ${toolName}:`, error);\n throw error;\n }\n }\n\n /**\n * Disconnect all MCP servers\n */\n async disconnectAll(): Promise<void> {\n for (const [name, client] of this.clients) {\n try {\n await client.close();\n this.logger.info(`Disconnected from MCP server ${name}`);\n } catch (error) {\n this.logger.error(`Error disconnecting MCP server ${name}:`, error);\n }\n }\n this.clients.clear();\n this.tools.clear();\n }\n\n /**\n * Get all discovered tools from all connected servers\n */\n getAllTools(): MCPToolInfo[] {\n const allTools: MCPToolInfo[] = [];\n for (const tools of this.tools.values()) {\n allTools.push(...tools);\n }\n return allTools;\n }\n\n /**\n * Get tools from a specific server\n */\n getServerTools(serverName: string): MCPToolInfo[] {\n return this.tools.get(serverName) || [];\n }\n\n /**\n * Check if a server is connected\n */\n isServerConnected(serverName: string): boolean {\n return this.clients.has(serverName);\n }\n\n /**\n * Get list of connected server names\n */\n getConnectedServers(): string[] {\n return Array.from(this.clients.keys());\n }\n\n /**\n * Enable content processing with content storage\n */\n enableContentProcessing(contentStorage: ContentStorage): void {\n this.contentProcessor = new MCPContentProcessor(contentStorage, this.logger);\n this.logger.info('Content processing enabled for MCP responses');\n }\n\n /**\n * Disable content processing\n */\n disableContentProcessing(): void {\n delete this.contentProcessor;\n this.logger.info('Content processing disabled for MCP responses');\n }\n\n /**\n * Check if content processing is enabled\n */\n isContentProcessingEnabled(): boolean {\n return this.contentProcessor !== undefined;\n }\n\n /**\n * Analyze a response without processing it (for testing/debugging)\n */\n analyzeResponseContent(response: unknown): unknown {\n if (!this.contentProcessor) {\n throw new Error('Content processing is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AK;AACZ,SAAK,OAAO,KAAK,+CAA+C;AAAA,EAClE;AAAA;AAAA;AAAA;AAAA,EAKA,6BAAsC;AACpC,WAAO,KAAK,qBAAqB;AAAA,EACnC;AAAA;AAAA;AAAA;AAAA,EAKA,uBAAuB,UAA4B;AACjD,QAAI,CAAC,KAAK,kBAAkB;AAC1B,YAAM,IAAI,MAAM,mCAAmC;AAAA,IACrD;AACA,WAAO,KAAK,iBAAiB,gBAAgB,QAAQ;AAAA,EACvD;AACF;"}
|
package/dist/esm/index21.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ReferenceIdGenerator } from "./index22.js";
|
|
2
|
-
import { DEFAULT_CONTENT_REFERENCE_CONFIG, ContentReferenceError } from "./
|
|
2
|
+
import { DEFAULT_CONTENT_REFERENCE_CONFIG, ContentReferenceError } from "./index44.js";
|
|
3
3
|
const _ContentStorage = class _ContentStorage {
|
|
4
4
|
constructor(maxStorage = _ContentStorage.DEFAULT_MAX_STORAGE, referenceConfig) {
|
|
5
5
|
this.messages = [];
|
package/dist/esm/index23.js
CHANGED
|
@@ -12,8 +12,8 @@ import "langchain/agents";
|
|
|
12
12
|
import "zod-to-json-schema";
|
|
13
13
|
import "./index12.js";
|
|
14
14
|
import "@langchain/core/prompts";
|
|
15
|
-
import "@modelcontextprotocol/sdk/client/index";
|
|
16
|
-
import "@modelcontextprotocol/sdk/client/stdio";
|
|
15
|
+
import "@modelcontextprotocol/sdk/client/index.js";
|
|
16
|
+
import "@modelcontextprotocol/sdk/client/stdio.js";
|
|
17
17
|
import "./index18.js";
|
|
18
18
|
import "@langchain/core/messages";
|
|
19
19
|
import "./index19.js";
|
package/dist/esm/index33.js
CHANGED
|
@@ -8,11 +8,11 @@ import { MCPClientManager } from "./index15.js";
|
|
|
8
8
|
import { convertMCPToolToLangChain } from "./index17.js";
|
|
9
9
|
import { SmartMemoryManager } from "./index18.js";
|
|
10
10
|
import { ResponseFormatter } from "./index35.js";
|
|
11
|
-
import { ERROR_MESSAGES } from "./
|
|
11
|
+
import { ERROR_MESSAGES } from "./index45.js";
|
|
12
12
|
import "./index41.js";
|
|
13
13
|
import { SystemMessage, AIMessage, HumanMessage } from "@langchain/core/messages";
|
|
14
|
-
import { ToolRegistry } from "./
|
|
15
|
-
import { ExecutionPipeline } from "./
|
|
14
|
+
import { ToolRegistry } from "./index46.js";
|
|
15
|
+
import { ExecutionPipeline } from "./index47.js";
|
|
16
16
|
import { FormEngine } from "./index11.js";
|
|
17
17
|
function hasHashLinkBlock(metadata) {
|
|
18
18
|
if (!metadata || typeof metadata !== "object") {
|
package/dist/esm/index37.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { AccountBuilder } from "./
|
|
2
|
+
import { AccountBuilder } from "./index42.js";
|
|
3
3
|
import { BaseHederaTransactionTool } from "hedera-agent-kit";
|
|
4
4
|
const HbarTransferInputSchema = z.object({
|
|
5
5
|
accountId: z.string().describe('Account ID for the transfer (e.g., "0.0.xxxx").'),
|
package/dist/esm/index42.js
CHANGED
|
@@ -1,8 +1,98 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { TransferTransaction, AccountId, Hbar } from "@hashgraph/sdk";
|
|
2
|
+
import BigNumber from "bignumber.js";
|
|
3
|
+
import { BaseServiceBuilder } from "hedera-agent-kit";
|
|
4
|
+
class AccountBuilder extends BaseServiceBuilder {
|
|
5
|
+
constructor(hederaKit) {
|
|
6
|
+
super(hederaKit);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Transfers HBAR between accounts with proper decimal handling
|
|
10
|
+
*/
|
|
11
|
+
transferHbar(params, isUserInitiated = true) {
|
|
12
|
+
this.clearNotes();
|
|
13
|
+
const transaction = new TransferTransaction();
|
|
14
|
+
if (!params.transfers || params.transfers.length === 0) {
|
|
15
|
+
throw new Error("HbarTransferParams must include at least one transfer.");
|
|
16
|
+
}
|
|
17
|
+
let netZeroInTinybars = new BigNumber(0);
|
|
18
|
+
let userTransferProcessedForScheduling = false;
|
|
19
|
+
if (isUserInitiated && this.kit.userAccountId && this.kit.operationalMode === "provideBytes" && params.transfers.length === 1) {
|
|
20
|
+
const receiverTransfer = params.transfers[0];
|
|
21
|
+
const amountValue = typeof receiverTransfer.amount === "string" || typeof receiverTransfer.amount === "number" ? receiverTransfer.amount : receiverTransfer.amount.toString();
|
|
22
|
+
const amountBigNum = new BigNumber(amountValue);
|
|
23
|
+
if (amountBigNum.isPositive()) {
|
|
24
|
+
const recipientAccountId = typeof receiverTransfer.accountId === "string" ? AccountId.fromString(receiverTransfer.accountId) : receiverTransfer.accountId;
|
|
25
|
+
const roundedAmount = amountBigNum.toFixed(8, BigNumber.ROUND_DOWN);
|
|
26
|
+
const sdkHbarAmount = Hbar.fromString(roundedAmount);
|
|
27
|
+
this.logger.info(
|
|
28
|
+
`[AccountBuilder.transferHbar] Configuring user-initiated scheduled transfer: ${sdkHbarAmount.toString()} from ${this.kit.userAccountId} to ${recipientAccountId.toString()}`
|
|
29
|
+
);
|
|
30
|
+
this.addNote(
|
|
31
|
+
`Configured HBAR transfer from your account (${this.kit.userAccountId}) to ${recipientAccountId.toString()} for ${sdkHbarAmount.toString()}.`
|
|
32
|
+
);
|
|
33
|
+
transaction.addHbarTransfer(recipientAccountId, sdkHbarAmount);
|
|
34
|
+
transaction.addHbarTransfer(
|
|
35
|
+
AccountId.fromString(this.kit.userAccountId),
|
|
36
|
+
sdkHbarAmount.negated()
|
|
37
|
+
);
|
|
38
|
+
userTransferProcessedForScheduling = true;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (!userTransferProcessedForScheduling) {
|
|
42
|
+
const processedTransfers = [];
|
|
43
|
+
for (const transferInput of params.transfers) {
|
|
44
|
+
const accountId = typeof transferInput.accountId === "string" ? AccountId.fromString(transferInput.accountId) : transferInput.accountId;
|
|
45
|
+
const amountValue = typeof transferInput.amount === "string" || typeof transferInput.amount === "number" ? transferInput.amount : transferInput.amount.toString();
|
|
46
|
+
const amountBigNum = new BigNumber(amountValue);
|
|
47
|
+
const roundedAmount = amountBigNum.toFixed(8, BigNumber.ROUND_DOWN);
|
|
48
|
+
this.logger.info(
|
|
49
|
+
`Processing transfer: ${amountValue} HBAR (rounded to ${roundedAmount}) for account ${accountId.toString()}`
|
|
50
|
+
);
|
|
51
|
+
const sdkHbarAmount = Hbar.fromString(roundedAmount);
|
|
52
|
+
processedTransfers.push({
|
|
53
|
+
accountId,
|
|
54
|
+
amount: amountBigNum,
|
|
55
|
+
hbar: sdkHbarAmount
|
|
56
|
+
});
|
|
57
|
+
const tinybarsContribution = sdkHbarAmount.toTinybars();
|
|
58
|
+
netZeroInTinybars = netZeroInTinybars.plus(
|
|
59
|
+
tinybarsContribution.toString()
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
if (!netZeroInTinybars.isZero()) {
|
|
63
|
+
this.logger.warn(
|
|
64
|
+
`Transfer sum not zero: ${netZeroInTinybars.toString()} tinybars off. Adjusting last transfer.`
|
|
65
|
+
);
|
|
66
|
+
if (processedTransfers.length > 0) {
|
|
67
|
+
const lastTransfer = processedTransfers[processedTransfers.length - 1];
|
|
68
|
+
const adjustment = netZeroInTinybars.dividedBy(-1e8);
|
|
69
|
+
const adjustedAmount = lastTransfer.amount.plus(adjustment);
|
|
70
|
+
const adjustedRounded = adjustedAmount.toFixed(
|
|
71
|
+
8,
|
|
72
|
+
BigNumber.ROUND_DOWN
|
|
73
|
+
);
|
|
74
|
+
lastTransfer.hbar = Hbar.fromString(adjustedRounded);
|
|
75
|
+
this.logger.info(
|
|
76
|
+
`Adjusted last transfer for ${lastTransfer.accountId.toString()} to ${adjustedRounded} HBAR`
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
for (const transfer of processedTransfers) {
|
|
81
|
+
transaction.addHbarTransfer(transfer.accountId, transfer.hbar);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (typeof params.memo !== "undefined") {
|
|
85
|
+
if (params.memo === null) {
|
|
86
|
+
this.logger.warn("Received null for memo in transferHbar.");
|
|
87
|
+
} else {
|
|
88
|
+
transaction.setTransactionMemo(params.memo);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
this.setCurrentTransaction(transaction);
|
|
92
|
+
return this;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
5
95
|
export {
|
|
6
|
-
|
|
96
|
+
AccountBuilder
|
|
7
97
|
};
|
|
8
98
|
//# sourceMappingURL=index42.js.map
|
package/dist/esm/index42.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index42.js","sources":["../../src/
|
|
1
|
+
{"version":3,"file":"index42.js","sources":["../../src/plugins/hbar/AccountBuilder.ts"],"sourcesContent":["import { AccountId, Hbar, TransferTransaction } from '@hashgraph/sdk';\nimport BigNumber from 'bignumber.js';\nimport { HederaAgentKit, BaseServiceBuilder } from 'hedera-agent-kit';\nimport { HbarTransferParams } from './types';\n\n/**\n * Custom AccountBuilder that properly handles HBAR decimal conversion\n */\nexport class AccountBuilder extends BaseServiceBuilder {\n constructor(hederaKit: HederaAgentKit) {\n super(hederaKit);\n }\n\n /**\n * Transfers HBAR between accounts with proper decimal handling\n */\n public transferHbar(\n params: HbarTransferParams,\n isUserInitiated: boolean = true\n ): this {\n this.clearNotes();\n const transaction = new TransferTransaction();\n\n if (!params.transfers || params.transfers.length === 0) {\n throw new Error('HbarTransferParams must include at least one transfer.');\n }\n\n let netZeroInTinybars = new BigNumber(0);\n let userTransferProcessedForScheduling = false;\n\n if (\n isUserInitiated &&\n this.kit.userAccountId &&\n (this.kit.operationalMode as string) === 'provideBytes' &&\n params.transfers.length === 1\n ) {\n const receiverTransfer = params.transfers[0];\n const amountValue =\n typeof receiverTransfer.amount === 'string' ||\n typeof receiverTransfer.amount === 'number'\n ? receiverTransfer.amount\n : receiverTransfer.amount.toString();\n\n const amountBigNum = new BigNumber(amountValue);\n\n if (amountBigNum.isPositive()) {\n const recipientAccountId =\n typeof receiverTransfer.accountId === 'string'\n ? AccountId.fromString(receiverTransfer.accountId)\n : receiverTransfer.accountId;\n\n const roundedAmount = amountBigNum.toFixed(8, BigNumber.ROUND_DOWN);\n const sdkHbarAmount = Hbar.fromString(roundedAmount);\n\n this.logger.info(\n `[AccountBuilder.transferHbar] Configuring user-initiated scheduled transfer: ${sdkHbarAmount.toString()} from ${\n this.kit.userAccountId\n } to ${recipientAccountId.toString()}`\n );\n\n this.addNote(\n `Configured HBAR transfer from your account (${\n this.kit.userAccountId\n }) to ${recipientAccountId.toString()} for ${sdkHbarAmount.toString()}.`\n );\n\n transaction.addHbarTransfer(recipientAccountId, sdkHbarAmount);\n transaction.addHbarTransfer(\n AccountId.fromString(this.kit.userAccountId),\n sdkHbarAmount.negated()\n );\n\n userTransferProcessedForScheduling = true;\n }\n }\n\n if (!userTransferProcessedForScheduling) {\n const processedTransfers: Array<{\n accountId: AccountId;\n amount: BigNumber;\n hbar: Hbar;\n }> = [];\n\n for (const transferInput of params.transfers) {\n const accountId =\n typeof transferInput.accountId === 'string'\n ? AccountId.fromString(transferInput.accountId)\n : transferInput.accountId;\n\n const amountValue =\n typeof transferInput.amount === 'string' ||\n typeof transferInput.amount === 'number'\n ? transferInput.amount\n : transferInput.amount.toString();\n\n const amountBigNum = new BigNumber(amountValue);\n const roundedAmount = amountBigNum.toFixed(8, BigNumber.ROUND_DOWN);\n\n this.logger.info(\n `Processing transfer: ${amountValue} HBAR (rounded to ${roundedAmount}) for account ${accountId.toString()}`\n );\n\n const sdkHbarAmount = Hbar.fromString(roundedAmount);\n processedTransfers.push({\n accountId,\n amount: amountBigNum,\n hbar: sdkHbarAmount,\n });\n\n const tinybarsContribution = sdkHbarAmount.toTinybars();\n netZeroInTinybars = netZeroInTinybars.plus(\n tinybarsContribution.toString()\n );\n }\n\n if (!netZeroInTinybars.isZero()) {\n this.logger.warn(\n `Transfer sum not zero: ${netZeroInTinybars.toString()} tinybars off. Adjusting last transfer.`\n );\n\n if (processedTransfers.length > 0) {\n const lastTransfer =\n processedTransfers[processedTransfers.length - 1];\n const adjustment = netZeroInTinybars.dividedBy(-100000000);\n const adjustedAmount = lastTransfer.amount.plus(adjustment);\n const adjustedRounded = adjustedAmount.toFixed(\n 8,\n BigNumber.ROUND_DOWN\n );\n lastTransfer.hbar = Hbar.fromString(adjustedRounded);\n\n this.logger.info(\n `Adjusted last transfer for ${lastTransfer.accountId.toString()} to ${adjustedRounded} HBAR`\n );\n }\n }\n\n for (const transfer of processedTransfers) {\n transaction.addHbarTransfer(transfer.accountId, transfer.hbar);\n }\n }\n\n if (typeof params.memo !== 'undefined') {\n if (params.memo === null) {\n this.logger.warn('Received null for memo in transferHbar.');\n } else {\n transaction.setTransactionMemo(params.memo);\n }\n }\n\n this.setCurrentTransaction(transaction);\n return this;\n }\n}\n"],"names":[],"mappings":";;;AAQO,MAAM,uBAAuB,mBAAmB;AAAA,EACrD,YAAY,WAA2B;AACrC,UAAM,SAAS;AAAA,EACjB;AAAA;AAAA;AAAA;AAAA,EAKO,aACL,QACA,kBAA2B,MACrB;AACN,SAAK,WAAA;AACL,UAAM,cAAc,IAAI,oBAAA;AAExB,QAAI,CAAC,OAAO,aAAa,OAAO,UAAU,WAAW,GAAG;AACtD,YAAM,IAAI,MAAM,wDAAwD;AAAA,IAC1E;AAEA,QAAI,oBAAoB,IAAI,UAAU,CAAC;AACvC,QAAI,qCAAqC;AAEzC,QACE,mBACA,KAAK,IAAI,iBACR,KAAK,IAAI,oBAA+B,kBACzC,OAAO,UAAU,WAAW,GAC5B;AACA,YAAM,mBAAmB,OAAO,UAAU,CAAC;AAC3C,YAAM,cACJ,OAAO,iBAAiB,WAAW,YACnC,OAAO,iBAAiB,WAAW,WAC/B,iBAAiB,SACjB,iBAAiB,OAAO,SAAA;AAE9B,YAAM,eAAe,IAAI,UAAU,WAAW;AAE9C,UAAI,aAAa,cAAc;AAC7B,cAAM,qBACJ,O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AAEA,UAAI,CAAC,kBAAkB,UAAU;AAC/B,aAAK,OAAO;AAAA,UACV,0BAA0B,kBAAkB,SAAA,CAAU;AAAA,QAAA;AAGxD,YAAI,mBAAmB,SAAS,GAAG;AACjC,gBAAM,eACJ,mBAAmB,mBAAmB,SAAS,CAAC;AAClD,gBAAM,aAAa,kBAAkB,UAAU,IAAU;AACzD,gBAAM,iBAAiB,aAAa,OAAO,KAAK,UAAU;AAC1D,gBAAM,kBAAkB,eAAe;AAAA,YACrC;AAAA,YACA,UAAU;AAAA,UAAA;AAEZ,uBAAa,OAAO,KAAK,WAAW,eAAe;AAEnD,eAAK,OAAO;AAAA,YACV,8BAA8B,aAAa,UAAU,SAAA,CAAU,OAAO,eAAe;AAAA,UAAA;AAAA,QAEzF;AAAA,MACF;AAEA,iBAAW,YAAY,oBAAoB;AACzC,oBAAY,gBAAgB,SAAS,WAAW,SAAS,IAAI;AAAA,MAC/D;AAAA,IACF;AAEA,QAAI,OAAO,OAAO,SAAS,aAAa;AACtC,UAAI,OAAO,SAAS,MAAM;AACxB,aAAK,OAAO,KAAK,yCAAyC;AAAA,MAC5D,OAAO;AACL,oBAAY,mBAAmB,OAAO,IAAI;AAAA,MAC5C;AAAA,IACF;AAEA,SAAK,sBAAsB,WAAW;AACtC,WAAO;AAAA,EACT;AACF;"}
|
package/dist/esm/index43.js
CHANGED
|
@@ -1,325 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class ToolRegistry {
|
|
8
|
-
constructor(logger) {
|
|
9
|
-
this.tools = /* @__PURE__ */ new Map();
|
|
10
|
-
this.formGenerator = new FormGenerator();
|
|
11
|
-
this.logger = logger || new Logger({ module: "ToolRegistry" });
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Register a tool with the registry
|
|
15
|
-
*/
|
|
16
|
-
registerTool(tool, options = {}) {
|
|
17
|
-
const capabilities = this.analyzeToolCapabilities(tool);
|
|
18
|
-
const metadata = {
|
|
19
|
-
name: tool.name,
|
|
20
|
-
version: "1.0.0",
|
|
21
|
-
category: options.metadata?.category || "core",
|
|
22
|
-
description: tool.description,
|
|
23
|
-
capabilities,
|
|
24
|
-
dependencies: [],
|
|
25
|
-
schema: tool.schema,
|
|
26
|
-
...options.metadata
|
|
27
|
-
};
|
|
28
|
-
try {
|
|
29
|
-
if (!metadata.entityResolutionPreferences) {
|
|
30
|
-
const schemaRecord = tool.schema;
|
|
31
|
-
const rawPrefs = schemaRecord && typeof schemaRecord === "object" && schemaRecord["_entityResolutionPreferences"];
|
|
32
|
-
if (rawPrefs && typeof rawPrefs === "object") {
|
|
33
|
-
metadata.entityResolutionPreferences = rawPrefs;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
} catch {
|
|
37
|
-
}
|
|
38
|
-
try {
|
|
39
|
-
const schemaRecord = tool.schema;
|
|
40
|
-
const schemaDef = schemaRecord && schemaRecord._def;
|
|
41
|
-
if (schemaDef?.typeName === "ZodObject") {
|
|
42
|
-
const shape = typeof schemaDef.shape === "function" ? schemaDef.shape?.() || {} : schemaDef.shape || {};
|
|
43
|
-
const metadataField = shape["metadata"];
|
|
44
|
-
const isStringArray = !!metadataField && metadataField._def?.typeName === "ZodArray" && metadataField._def?.type?._def?.typeName === "ZodString";
|
|
45
|
-
if (isStringArray && typeof tool.description === "string") {
|
|
46
|
-
if (!metadata.entityResolutionPreferences) {
|
|
47
|
-
metadata.entityResolutionPreferences = {
|
|
48
|
-
inscription: "hrl"
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
const note = " NOTE: When referencing inscriptions or media, provide canonical Hashlink Resource Locators (e.g., hcs://<standard>/<topicId>) rather than external URLs or embedded JSON.";
|
|
52
|
-
if (!tool.description.includes("Hashlink Resource Locators")) {
|
|
53
|
-
tool.description = `${tool.description}${note}`;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
} catch {
|
|
58
|
-
}
|
|
59
|
-
let finalTool = tool;
|
|
60
|
-
let wrapper;
|
|
61
|
-
if (this.shouldWrapTool(tool, capabilities, options)) {
|
|
62
|
-
wrapper = wrapToolWithFormValidation(
|
|
63
|
-
tool,
|
|
64
|
-
this.formGenerator,
|
|
65
|
-
{
|
|
66
|
-
requireAllFields: false,
|
|
67
|
-
skipFields: ["metaOptions"],
|
|
68
|
-
...options.wrapperConfig
|
|
69
|
-
}
|
|
70
|
-
);
|
|
71
|
-
finalTool = wrapper;
|
|
72
|
-
}
|
|
73
|
-
try {
|
|
74
|
-
if (metadata.entityResolutionPreferences) {
|
|
75
|
-
finalTool["entityResolutionPreferences"] = metadata.entityResolutionPreferences;
|
|
76
|
-
}
|
|
77
|
-
} catch {
|
|
78
|
-
}
|
|
79
|
-
const entry = {
|
|
80
|
-
tool: finalTool,
|
|
81
|
-
metadata,
|
|
82
|
-
wrapper,
|
|
83
|
-
originalTool: tool,
|
|
84
|
-
options: {
|
|
85
|
-
priority: capabilities.priority,
|
|
86
|
-
capability: "basic",
|
|
87
|
-
// Default capability
|
|
88
|
-
enabled: true,
|
|
89
|
-
// All tools are enabled by default
|
|
90
|
-
namespace: metadata.category
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
this.tools.set(tool.name, entry);
|
|
94
|
-
try {
|
|
95
|
-
const metaFG = metadata.fieldGuidance;
|
|
96
|
-
if (metaFG) {
|
|
97
|
-
fieldGuidanceRegistry.registerToolConfiguration(metaFG);
|
|
98
|
-
}
|
|
99
|
-
const provider = metadata.fieldGuidanceProvider;
|
|
100
|
-
if (provider) {
|
|
101
|
-
const pattern = metaFG?.toolPattern ?? tool.name;
|
|
102
|
-
fieldGuidanceRegistry.registerToolProvider(pattern, provider, {
|
|
103
|
-
id: `${tool.name}:field-guidance-provider`,
|
|
104
|
-
priority: 0
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
} catch {
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Get a tool by name
|
|
112
|
-
*/
|
|
113
|
-
getTool(name) {
|
|
114
|
-
return this.tools.get(name) || null;
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Get tools by capability
|
|
118
|
-
*/
|
|
119
|
-
getToolsByCapability(capability, value) {
|
|
120
|
-
const results = [];
|
|
121
|
-
for (const entry of this.tools.values()) {
|
|
122
|
-
if (value !== void 0) {
|
|
123
|
-
if (entry.metadata.capabilities[capability] === value) {
|
|
124
|
-
results.push(entry);
|
|
125
|
-
}
|
|
126
|
-
} else if (entry.metadata.capabilities[capability]) {
|
|
127
|
-
results.push(entry);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
return results;
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Get tools by query
|
|
134
|
-
*/
|
|
135
|
-
getToolsByQuery(query) {
|
|
136
|
-
const results = [];
|
|
137
|
-
for (const entry of this.tools.values()) {
|
|
138
|
-
let matches = true;
|
|
139
|
-
if (query.name && entry.metadata.name !== query.name) {
|
|
140
|
-
matches = false;
|
|
141
|
-
}
|
|
142
|
-
if (query.category && entry.metadata.category !== query.category) {
|
|
143
|
-
matches = false;
|
|
144
|
-
}
|
|
145
|
-
if (query.capabilities) {
|
|
146
|
-
for (const [key, value] of Object.entries(query.capabilities)) {
|
|
147
|
-
if (entry.metadata.capabilities[key] !== value) {
|
|
148
|
-
matches = false;
|
|
149
|
-
break;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
if (matches) {
|
|
154
|
-
results.push(entry);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
return results;
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Get all registered tools
|
|
161
|
-
*/
|
|
162
|
-
getAllTools() {
|
|
163
|
-
return Array.from(this.tools.values()).map((entry) => entry.tool);
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Get all registry entries
|
|
167
|
-
*/
|
|
168
|
-
getAllRegistryEntries() {
|
|
169
|
-
return Array.from(this.tools.values());
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Get all tool names
|
|
173
|
-
*/
|
|
174
|
-
getToolNames() {
|
|
175
|
-
return Array.from(this.tools.keys());
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Get tools by priority
|
|
179
|
-
*/
|
|
180
|
-
getToolsByPriority(priority) {
|
|
181
|
-
return this.getToolsByCapability("priority", priority);
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Get enabled tools (all tools are considered enabled by default)
|
|
185
|
-
*/
|
|
186
|
-
getEnabledTools() {
|
|
187
|
-
return this.getAllRegistryEntries();
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Get tools by namespace/category
|
|
191
|
-
*/
|
|
192
|
-
getToolsByNamespace(namespace) {
|
|
193
|
-
if (!namespace) {
|
|
194
|
-
return this.getAllRegistryEntries();
|
|
195
|
-
}
|
|
196
|
-
return this.getToolsByQuery({ category: namespace });
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* Check if registry has capability
|
|
200
|
-
*/
|
|
201
|
-
hasCapability(capability) {
|
|
202
|
-
for (const entry of this.tools.values()) {
|
|
203
|
-
if (entry.metadata.capabilities[capability]) {
|
|
204
|
-
return true;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
return false;
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* Update tool options (metadata)
|
|
211
|
-
*/
|
|
212
|
-
updateToolOptions(name, options) {
|
|
213
|
-
const entry = this.tools.get(name);
|
|
214
|
-
if (!entry) {
|
|
215
|
-
return false;
|
|
216
|
-
}
|
|
217
|
-
entry.metadata = { ...entry.metadata, ...options };
|
|
218
|
-
return true;
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* Check if a tool is registered
|
|
222
|
-
*/
|
|
223
|
-
hasTool(name) {
|
|
224
|
-
return this.tools.has(name);
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* Unregister a tool
|
|
228
|
-
*/
|
|
229
|
-
unregisterTool(name) {
|
|
230
|
-
return this.tools.delete(name);
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* Clear all tools
|
|
234
|
-
*/
|
|
235
|
-
clear() {
|
|
236
|
-
this.tools.clear();
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* Analyze tool capabilities
|
|
240
|
-
*/
|
|
241
|
-
analyzeToolCapabilities(tool) {
|
|
242
|
-
const implementsFormValidatable = isFormValidatable(tool);
|
|
243
|
-
const hasRenderConfig = this.hasRenderConfig(tool);
|
|
244
|
-
const isZodObjectLike = this.isZodObjectLike(tool.schema);
|
|
245
|
-
const supportsFormValidation = implementsFormValidatable || hasRenderConfig;
|
|
246
|
-
const requiresWrapper = supportsFormValidation && isZodObjectLike;
|
|
247
|
-
let priority = "medium";
|
|
248
|
-
let category = "core";
|
|
249
|
-
if (supportsFormValidation && requiresWrapper) {
|
|
250
|
-
priority = "critical";
|
|
251
|
-
} else if (supportsFormValidation) {
|
|
252
|
-
priority = "high";
|
|
253
|
-
} else if (tool.description?.toLowerCase().includes("query") || tool.description?.toLowerCase().includes("search")) {
|
|
254
|
-
priority = "low";
|
|
255
|
-
}
|
|
256
|
-
const toolAsAny = tool;
|
|
257
|
-
if (tool.constructor.name.includes("MCP") || toolAsAny.isMCPTool) {
|
|
258
|
-
category = "mcp";
|
|
259
|
-
} else if (toolAsAny.isExtension || tool.constructor.name.includes("Extension")) {
|
|
260
|
-
category = "extension";
|
|
261
|
-
}
|
|
262
|
-
return {
|
|
263
|
-
supportsFormValidation,
|
|
264
|
-
requiresWrapper,
|
|
265
|
-
priority,
|
|
266
|
-
category
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* Check if tool has render configuration
|
|
271
|
-
*/
|
|
272
|
-
hasRenderConfig(tool) {
|
|
273
|
-
const schema = tool.schema;
|
|
274
|
-
return !!(schema && schema._renderConfig);
|
|
275
|
-
}
|
|
276
|
-
/**
|
|
277
|
-
* Determine if tool should be wrapped
|
|
278
|
-
*/
|
|
279
|
-
shouldWrapTool(tool, capabilities, options) {
|
|
280
|
-
if (options.skipWrapper) {
|
|
281
|
-
return false;
|
|
282
|
-
}
|
|
283
|
-
if (options.forceWrapper) {
|
|
284
|
-
return true;
|
|
285
|
-
}
|
|
286
|
-
return capabilities.requiresWrapper;
|
|
287
|
-
}
|
|
288
|
-
/**
|
|
289
|
-
* Check if schema is ZodObject-like
|
|
290
|
-
*/
|
|
291
|
-
isZodObjectLike(schema) {
|
|
292
|
-
if (!schema || typeof schema !== "object") {
|
|
293
|
-
return false;
|
|
294
|
-
}
|
|
295
|
-
const schemaRecord = schema;
|
|
296
|
-
const schemaDef = schemaRecord._def;
|
|
297
|
-
return schema instanceof z.ZodObject || schemaDef?.typeName === "ZodObject" || "shape" in schemaRecord && typeof schemaRecord.shape === "object";
|
|
298
|
-
}
|
|
299
|
-
/**
|
|
300
|
-
* Get statistics about the registry
|
|
301
|
-
*/
|
|
302
|
-
getStatistics() {
|
|
303
|
-
const stats = {
|
|
304
|
-
totalTools: this.tools.size,
|
|
305
|
-
wrappedTools: 0,
|
|
306
|
-
unwrappedTools: 0,
|
|
307
|
-
categoryCounts: { core: 0, extension: 0, mcp: 0 },
|
|
308
|
-
priorityCounts: { low: 0, medium: 0, high: 0, critical: 0 }
|
|
309
|
-
};
|
|
310
|
-
for (const entry of this.tools.values()) {
|
|
311
|
-
if (entry.wrapper) {
|
|
312
|
-
stats.wrappedTools++;
|
|
313
|
-
} else {
|
|
314
|
-
stats.unwrappedTools++;
|
|
315
|
-
}
|
|
316
|
-
stats.categoryCounts[entry.metadata.category]++;
|
|
317
|
-
stats.priorityCounts[entry.metadata.capabilities.priority]++;
|
|
318
|
-
}
|
|
319
|
-
return stats;
|
|
320
|
-
}
|
|
321
|
-
}
|
|
1
|
+
const FIELD_PRIORITIES = {
|
|
2
|
+
ESSENTIAL: "essential",
|
|
3
|
+
COMMON: "common",
|
|
4
|
+
ADVANCED: "advanced",
|
|
5
|
+
EXPERT: "expert"
|
|
6
|
+
};
|
|
322
7
|
export {
|
|
323
|
-
|
|
8
|
+
FIELD_PRIORITIES
|
|
324
9
|
};
|
|
325
10
|
//# sourceMappingURL=index43.js.map
|