npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

tools-llm

v1.1.1

Published

Biblioteca minimalista para executar funções via marcadores em texto.

Downloads

649

Readme

tools-llm

Biblioteca/Library minimalista para executar funções de texto com marcadores inline.


PT-BR

Sintaxe suportada

Modo padrão (substitui pelo retorno da função):

  • [[funcao]]
  • [[funcao:param1]]
  • [[funcao:param1,param2,param3]]

Modo silencioso (executa e remove marcador):

  • [[!funcao]]
  • [[!funcao:param1]]
  • [[!funcao:param1,param2,param3]]

Comportamento

  • Executa a função apenas se ela existir em tools
  • Suporta funções síncronas e assíncronas
  • Resolve marcadores da esquerda para a direita
  • Converte retorno automaticamente para string no modo padrão
  • Modo silencioso (!) executa a função e ignora o retorno
  • No modo silencioso, o marcador é removido do texto final
  • Marcadores desconhecidos são preservados (inclusive silenciosos)
  • Se a função lançar erro, o marcador é preservado
  • Detecta automaticamente quando um parâmetro é JSON válido

Instalação

npm install tools-llm

Uso (PT-BR)

import { executarTools, executeMutedTools } from "tools-llm";
// ou: import executarTools from "tools-llm";

const tools = {
  data_agora() {
    return "24/06/2026";
  },
  async clima(cidade) {
    return cidade === "Recife" ? "32°C" : "N/A";
  },
  somar(a, b) {
    return Number(a) + Number(b);
  },
  processar(payload) {
    return payload.cidade;
  },
  async registrarLog(msg) {
    // side effect
    return "OK";
  }
};

const texto = `Hoje é [[data_agora]]
Clima: [[clima:Recife]]
Soma: [[somar:10,20]]
JSON: [[processar:{"cidade":"Recife","temp":32}]]

[[!registrarLog:usuario entrou]]

Favorito: [[Naruto]]`;

const resultado = await executarTools(texto, tools);

console.log(resultado);
/*
Hoje é 24/06/2026
Clima: 32°C
Soma: 30
JSON: Recife


Favorito: [[Naruto]]
*/

const resultadoLista = await executeMutedTools(texto, tools);
console.log(resultadoLista);
/*
[
  { tool: "data_agora", result: "24/06/2026" },
  { tool: "clima", result: "32°C" },
  { tool: "somar", result: 30 },
  { tool: "processar", result: "Recife" },
  { tool: "registrarLog", result: "OK" }
]
*/

API (PT-BR)

  • await executarTools(texto, tools): Retorna uma String com o texto modificado (marcadores substituídos pelos retornos das funções).
  • await executeMutedTools(texto, tools): Executa as funções e retorna uma lista de objetos (Array<{ tool: string, result: any }>) com os resultados. Não substitui o texto original e ignora a restrição de "silencioso" (!).

EN

Supported syntax

Default mode (replaces with function return):

  • [[functionName]]
  • [[functionName:param1]]
  • [[functionName:param1,param2,param3]]

Silent mode (executes and removes marker):

  • [[!functionName]]
  • [[!functionName:param1]]
  • [[!functionName:param1,param2,param3]]

Behavior

  • Executes only if the function exists in tools
  • Supports sync and async functions
  • Resolves markers left to right
  • Converts return values to string in default mode
  • Silent mode (!) executes the function and ignores return value
  • In silent mode, marker is removed from final text
  • Unknown markers are preserved (including silent markers)
  • If a function throws, the marker is preserved
  • Automatically detects valid JSON parameters

Installation

npm install tools-llm

Usage (EN)

import { executeTools, executeMutedTools } from "tools-llm";
// or: import executarTools from "tools-llm";

const tools = {
  date_now() {
    return "24/06/2026";
  },
  async weather(city) {
    return city === "Recife" ? "32°C" : "N/A";
  },
  sum(a, b) {
    return Number(a) + Number(b);
  },
  process(payload) {
    return payload.city;
  },
  async saveMemory(key, value) {
    // side effect
    return "OK";
  }
};

const text = `Today is [[date_now]]
Weather: [[weather:Recife]]
Sum: [[sum:10,20]]
JSON: [[process:{"city":"Recife","temp":32}]]

[[!saveMemory:name,Caio]]

Favorite: [[Naruto]]`;

const result = await executeTools(text, tools);

console.log(result);
/*
Today is 24/06/2026
Weather: 32°C
Sum: 30
JSON: Recife


Favorite: [[Naruto]]
*/

const resultList = await executeMutedTools(text, tools);
console.log(resultList);
/*
[
  { tool: "date_now", result: "24/06/2026" },
  { tool: "weather", result: "32°C" },
  { tool: "sum", result: 30 },
  { tool: "process", result: "Recife" },
  { tool: "saveMemory", result: "OK" }
]
*/

API (EN)

  • await executeTools(text, tools) (alias de executarTools): Returns a String with the text modified (markers replaced by the functions' return values).
  • await executeMutedTools(text, tools): Executes the functions and returns an array of objects (Array<{ tool: string, result: any }>) with the results. It does not replace the original text and ignores the "silent" restriction (!).

Notas/Notes

  • JSON válido vira objeto/array/valor nativo via JSON.parse
  • Texto comum continua string
  • Parâmetros com vírgulas internas em JSON são tratados corretamente
  • Compatível com Node.js e navegador (ESM)
  • Exports disponíveis:
    • executarTools
    • executeTools
    • executeMutedTools
    • default (executarTools)