🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@toolroute/hook

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@toolroute/hook

Auto-route every agent task through ToolRoute. Install once, every task gets the best tool and model recommendation.

latest
Source
npmnpm
Version
1.0.2
Version published
Weekly downloads
10
42.86%
Maintainers
1
Weekly downloads
 
Created
Source

@toolroute/hook

Auto-route every agent task through ToolRoute. Install once — every task gets the best MCP server and LLM model recommendation, automatically.

Install

npm install @toolroute/hook

Quick Start

import { createHook } from '@toolroute/hook'

const hook = createHook({
  agentName: 'my-agent',
  verbose: true, // logs routing decisions
})

// Register (optional, earns 2x credits)
await hook.register()

// Wrap any task — routing + reporting happens automatically
const result = await hook.run('scrape competitor pricing data', async (routing) => {
  console.log(`Best tool: ${routing.skillName}`) // e.g., "Firecrawl MCP"
  console.log(`Best model: ${routing.model}`)    // e.g., "claude-haiku-4-5-20251001"
  console.log(`Confidence: ${routing.confidence}`)

  // ... your actual task logic here ...
  return { prices: [29, 49, 99] }
})

console.log(result.data)          // { prices: [29, 49, 99] }
console.log(result.executionMs)   // 1847
console.log(result.creditsEarned) // 5

Just Route (no wrapper)

const routing = await hook.route('draft an email to a client')
// routing.skill → "gmail-mcp"
// routing.model → "claude-haiku-4-5-20251001"
// routing.confidence → 0.87

A/B Testing

// Set bypass: true to skip routing — compare routed vs unrouted performance
const hook = createHook({ bypass: Math.random() > 0.5 })

How It Works

  • Before your task — calls POST /api/route with your task description
  • Returns routing context — best skill, model, alternatives, confidence score
  • You execute — use the recommendation (or ignore it)
  • After your task — reports outcome to ToolRoute (fire-and-forget)
  • Earns credits — 3-10 credits per report, 2x if verified

Changelog

1.0.2 (2026-05-20)

  • Fix: hook.route() returned model: null for every call because it read recommended_model.alias / .recommended_alias — fields that don't exist on the /api/route response. Now reads recommended_model.slug.
  • Fix: hook.run() called reportOutcome() twice per task on the success path (once in the finally block, once after). Telemetry was double-counted. Now fires exactly one POST /api/contributions per task on both success and failure paths.

1.0.1

  • Initial public release.

Keywords

toolroute

FAQs

Package last updated on 20 May 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts