Spaces:
Runtime error
Runtime error
Download src/agents/coder/tools/compile-solidity.ts from TALP-Project/multi-agent-smart-contracts: direct link, hf CLI and curl.
- Browser
- Download file 1.51 kB
-
https://huggingface.co/spaces/TALP-Project/multi-agent-smart-contracts/resolve/main/src/agents/coder/tools/compile-solidity.ts
- Command line
-
hf download hf://spaces/TALP-Project/multi-agent-smart-contracts/src/agents/coder/tools/compile-solidity.ts
-
curl -L -o compile-solidity.ts https://huggingface.co/spaces/TALP-Project/multi-agent-smart-contracts/resolve/main/src/agents/coder/tools/compile-solidity.ts
1.51 kB
| import { tool } from "langchain"; | |
| import { z } from "zod"; | |
| import solc from "solc"; | |
| /** | |
| * Tool que compila c贸digo Solidity usando solc e retorna erros/warnings. | |
| */ | |
| export const compileSolidityTool = tool( | |
| async (input) => { | |
| const compilerInput = { | |
| language: "Solidity", | |
| sources: { | |
| [input.filename]: { content: input.sourceCode }, | |
| }, | |
| settings: { | |
| outputSelection: { | |
| "*": { "*": ["abi", "evm.bytecode.object"] }, | |
| }, | |
| }, | |
| }; | |
| const output = JSON.parse(solc.compile(JSON.stringify(compilerInput))); | |
| const errors = (output.errors || []) | |
| .filter((e: { severity: string }) => e.severity === "error") | |
| .map((e: { formattedMessage: string }) => e.formattedMessage); | |
| const warnings = (output.errors || []) | |
| .filter((e: { severity: string }) => e.severity === "warning") | |
| .map((e: { formattedMessage: string }) => e.formattedMessage); | |
| const contracts = output.contracts?.[input.filename] || {}; | |
| const contractNames = Object.keys(contracts); | |
| return { | |
| success: errors.length === 0, | |
| errors, | |
| warnings, | |
| contracts: contractNames, | |
| }; | |
| }, | |
| { | |
| name: "compilar_solidity", | |
| description: "Compila c贸digo Solidity com solc e retorna erros, warnings e contratos encontrados.", | |
| schema: z.object({ | |
| sourceCode: z.string().describe("C贸digo-fonte Solidity completo"), | |
| filename: z.string().default("Contract.sol").describe("Nome do arquivo .sol"), | |
| }), | |
| }, | |
| ); | |