-
Notifications
You must be signed in to change notification settings - Fork 450
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/switchboard-feed-simulation
- Loading branch information
Showing
6 changed files
with
132 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: Check LangChain Tool Names | ||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
check-langchain-tool-names: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: pnpm/action-setup@v3 | ||
with: | ||
version: 9.4.0 | ||
|
||
- name: Install node-gyp prerequisites | ||
run: sudo apt update && sudo apt install -y build-essential python3 pkg-config libudev-dev libusb-1.0-0-dev | ||
|
||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: "23" | ||
cache: "pnpm" | ||
|
||
- name: Install dependencies | ||
run: pnpm install -r --no-frozen-lockfile | ||
|
||
- run: pnpm run check-tool-names:langchain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,8 @@ | |
"lint": "eslint . --ext .ts", | ||
"lint:fix": "eslint . --ext .ts --fix", | ||
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", | ||
"prepare": "husky" | ||
"tool-summary": "tsx src/utils/analyzeTools.ts", | ||
"check-tool-names:langchain": "tsx scripts/check-langchain-tool-duplicates.ts" | ||
}, | ||
"engines": { | ||
"node": ">=22.0.0", | ||
|
@@ -94,4 +95,4 @@ | |
"typescript": "^5.7.2" | ||
}, | ||
"packageManager": "[email protected]" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { Keypair } from "@solana/web3.js"; | ||
import { SolanaAgentKit } from "../src"; | ||
import { createSolanaTools } from "../src/langchain/index"; | ||
import { Tool } from "langchain/tools"; | ||
import bs58 from "bs58"; | ||
|
||
function findDuplicateNames(tools: Tool[]): Map<string, string[]> { | ||
const nameMap = new Map<string, string[]>(); | ||
|
||
tools.forEach((tool) => { | ||
const existing = nameMap.get(tool.name) || []; | ||
nameMap.set(tool.name, [...existing, tool.constructor.name]); | ||
}); | ||
|
||
const duplicates = new Map<string, string[]>(); | ||
nameMap.forEach((classes, name) => { | ||
if (classes.length > 1) { | ||
duplicates.set(name, classes); | ||
} | ||
}); | ||
|
||
return duplicates; | ||
} | ||
|
||
function findDuplicateClasses(tools: Tool[]): Map<string, string[]> { | ||
const classMap = new Map<string, string[]>(); | ||
|
||
tools.forEach((tool) => { | ||
const className = tool.constructor.name; | ||
const existing = classMap.get(className) || []; | ||
classMap.set(className, [...existing, tool.name]); | ||
}); | ||
|
||
// Filter to only classes with multiple names | ||
const duplicates = new Map<string, string[]>(); | ||
classMap.forEach((names, className) => { | ||
if (names.length > 1) { | ||
duplicates.set(className, names); | ||
} | ||
}); | ||
|
||
return duplicates; | ||
} | ||
|
||
async function main() { | ||
const kit = new SolanaAgentKit( | ||
process.env.SOLANA_PRIVATE_KEY || | ||
bs58.encode(Buffer.from(Keypair.generate().secretKey)), | ||
process.env.RPC_URL || "", | ||
{ OPENAI_API_KEY: process.env.OPENAI_API_KEY || "" }, | ||
); | ||
|
||
const tools = createSolanaTools(kit); | ||
const nameDuplicates = findDuplicateNames(tools); | ||
const classDuplicates = findDuplicateClasses(tools); | ||
|
||
let hasErrors = false; | ||
const errorMessages: string[] = []; | ||
|
||
if (nameDuplicates.size > 0) { | ||
hasErrors = true; | ||
errorMessages.push("❌ Duplicate tool names detected:"); | ||
nameDuplicates.forEach((classes, name) => { | ||
errorMessages.push( | ||
`\nName: ${name}`, | ||
`Used by classes:`, | ||
...classes.map((c) => `- ${c}`), | ||
); | ||
}); | ||
} | ||
|
||
if (classDuplicates.size > 0) { | ||
hasErrors = true; | ||
errorMessages.push("\n❌ Classes used for multiple tools:"); | ||
classDuplicates.forEach((names, className) => { | ||
errorMessages.push( | ||
`\nClass: ${className}`, | ||
"Used for tools:", | ||
...names.map((name) => `- ${name}`), | ||
); | ||
}); | ||
} | ||
|
||
if (hasErrors) { | ||
console.error(errorMessages.join("\n")); | ||
process.exit(1); | ||
} | ||
|
||
console.log( | ||
"✅ All checks passed:\n- No duplicate tool names\n- No classes reused for multiple tools", | ||
); | ||
process.exit(0); | ||
} | ||
|
||
main().catch((err) => { | ||
console.error("Script failed:", err); | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters