diff --git a/src/langchain/index.ts b/src/langchain/index.ts index 68cd157..4e64556 100644 --- a/src/langchain/index.ts +++ b/src/langchain/index.ts @@ -32,10 +32,10 @@ export class SolanaBalanceTool extends Tool { try { // Parse input as JSON if provided, otherwise use empty object const parsedInput = input ? JSON.parse(input) : {}; - + // Validate and execute using the action const result = await this.action.handler(this.solanaKit, parsedInput); - + return JSON.stringify(result); } catch (error: any) { return JSON.stringify({ @@ -60,10 +60,10 @@ export class SolanaTransferTool extends Tool { try { // Parse input as JSON const parsedInput = JSON.parse(input); - + // Validate and execute using the action const result = await this.action.handler(this.solanaKit, parsedInput); - + return JSON.stringify(result); } catch (error: any) { return JSON.stringify({ @@ -88,10 +88,10 @@ export class SolanaDeployTokenTool extends Tool { try { // Parse input as JSON const parsedInput = JSON.parse(input); - + // Validate and execute using the action const result = await this.action.handler(this.solanaKit, parsedInput); - + return JSON.stringify(result); } catch (error: any) { return JSON.stringify({ @@ -116,10 +116,10 @@ export class SolanaDeployCollectionTool extends Tool { try { // Parse input as JSON const parsedInput = JSON.parse(input); - + // Validate and execute using the action const result = await this.action.handler(this.solanaKit, parsedInput); - + return JSON.stringify(result); } catch (error: any) { return JSON.stringify({ @@ -144,10 +144,10 @@ export class SolanaMintNFTTool extends Tool { try { // Parse input as JSON const parsedInput = JSON.parse(input); - + // Validate and execute using the action const result = await this.action.handler(this.solanaKit, parsedInput); - + return JSON.stringify(result); } catch (error: any) { return JSON.stringify({ @@ -172,10 +172,10 @@ export class SolanaTradeTool extends Tool { try { // Parse input as JSON const parsedInput = JSON.parse(input); - + // Validate and execute using the action const result = await this.action.handler(this.solanaKit, parsedInput); - + return JSON.stringify(result); } catch (error: any) { return JSON.stringify({ @@ -200,7 +200,7 @@ export class SolanaRequestFundsTool extends Tool { try { // No input needed for this action const result = await this.action.handler(this.solanaKit, {}); - + return JSON.stringify(result); } catch (error: any) { return JSON.stringify({ @@ -1151,7 +1151,7 @@ export class SolanaCreateGibworkTask extends Tool { } export function createSolanaTools(solanaKit: SolanaAgentKit) { - const tools = [ + return [ new SolanaBalanceTool(solanaKit), new SolanaTransferTool(solanaKit), new SolanaDeployTokenTool(solanaKit), @@ -1185,7 +1185,4 @@ export function createSolanaTools(solanaKit: SolanaAgentKit) { new SolanaResolveAllDomainsTool(solanaKit), new SolanaCreateGibworkTask(solanaKit), ]; - - // Convert LangChain tools to our Action interface - return tools.map(tool => wrapLangChainTool(tool, solanaKit)); } diff --git a/test/index.ts b/test/index.ts index 10a2003..5aae92e 100644 --- a/test/index.ts +++ b/test/index.ts @@ -35,52 +35,6 @@ validateEnvironment(); const WALLET_DATA_FILE = "wallet_data.txt"; -// Convert our Action interface to LangChain Tool -function convertActionToTool(action: Action, solanaAgent: SolanaAgentKit): Tool { - class ActionTool extends Tool { - name = action.name; - description = action.description; - - async _call(input: string): Promise { - try { - let parsedInput; - try { - // Try to parse as JSON first - parsedInput = input ? JSON.parse(input) : {}; - } catch { - // If JSON parsing fails, use the raw input string - parsedInput = { input }; - } - - // Validate input against schema if available - if (action.schema) { - try { - parsedInput = action.schema.parse(parsedInput); - } catch (validationError: any) { - return JSON.stringify({ - status: "error", - message: `Invalid input: ${validationError.message}`, - code: "VALIDATION_ERROR" - }); - } - } - - const result = await action.handler(solanaAgent, parsedInput); - return JSON.stringify(result); - } catch (error: any) { - console.error("Action execution error:", error); - return JSON.stringify({ - status: "error", - message: error.message, - code: error.code || "UNKNOWN_ERROR" - }); - } - } - } - - return new ActionTool(); -} - async function initializeAgent() { try { const llm = new ChatOpenAI({ @@ -104,10 +58,8 @@ async function initializeAgent() { process.env.OPENAI_API_KEY!, ); - const actions = createSolanaTools(solanaAgent); - // Convert our Actions to LangChain Tools - const tools = actions.map(action => convertActionToTool(action, solanaAgent)); - + const tools = createSolanaTools(solanaAgent); + const memory = new MemorySaver(); const config = { configurable: { thread_id: "Solana Agent Kit!" } };