@tpmjs/tools-recipe-hash
Generates a deterministic hash for a recipe/workflow using SHA-256
Export "recipeHash" not found in module
Last checked: 1/1/2026, 8:17:50 AM
Test @tpmjs/tools-recipe-hash (recipeHash) with AI-powered execution
0/2000 characters
Install this tool and use it with the AI SDK
npm install @tpmjs/tools-recipe-hashpnpm add @tpmjs/tools-recipe-hashyarn add @tpmjs/tools-recipe-hashbun add @tpmjs/tools-recipe-hashdeno add npm:@tpmjs/tools-recipe-hashimport { recipeHash } from '@tpmjs/tools-recipe-hash';import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { recipeHash } from '@tpmjs/tools-recipe-hash';
const result = await generateText({
model: openai('gpt-4o'),
tools: { recipeHash },
prompt: 'Your prompt here...',
});
console.log(result.text);Available configuration options
recipeobjectRecipe or workflow object to hash
Try to auto-extract schema from the package
Generates a deterministic SHA-256 hash for a recipe/workflow object.
npm install @tpmjs/tools-recipe-hash
import { recipeHashTool } from '@tpmjs/tools-recipe-hash'; const recipe = { name: 'Data Processing Pipeline', steps: [ { id: 'fetch', action: 'fetchData', source: 'api.example.com' }, { id: 'transform', action: 'processData', input: 'fetch.output' }, { id: 'store', action: 'saveData', input: 'transform.output' } ], version: '1.0.0' }; const result = await recipeHashTool.execute({ recipe }); console.log(result); // { // hash: 'a3f5e8c9d1b2a7f4e6c8d9a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1', // algorithm: 'SHA-256', // inputSize: 245 // }
The tool ensures deterministic hashing by:
{ b: 1, a: 2 } becomes { a: 2, b: 1 }This means these two recipes produce the same hash:
const recipe1 = { name: 'test', version: '1.0' }; const recipe2 = { version: '1.0', name: 'test' }; // Different key order const hash1 = await recipeHashTool.execute({ recipe: recipe1 }); const hash2 = await recipeHashTool.execute({ recipe: recipe2 }); console.log(hash1.hash === hash2.hash); // true
// Detect if a recipe has changed const currentHash = await recipeHashTool.execute({ recipe }); if (currentHash.hash !== storedHash) { console.log('Recipe has been modified!'); // Update version, invalidate cache, etc. }
// Cache workflow results by recipe hash const { hash } = await recipeHashTool.execute({ recipe }); const cachedResult = await cache.get(hash); if (cachedResult) { return cachedResult; // Skip execution } const result = await executeWorkflow(recipe); await cache.set(hash, result);
// Track recipe changes over time const versions = [ { hash: 'abc123...', timestamp: '2025-01-01', version: '1.0.0' }, { hash: 'def456...', timestamp: '2025-01-15', version: '1.1.0' }, { hash: 'ghi789...', timestamp: '2025-02-01', version: '1.2.0' } ]; const currentHash = await recipeHashTool.execute({ recipe }); const hasChanged = !versions.some(v => v.hash === currentHash.hash);
// Prevent duplicate recipe execution const { hash } = await recipeHashTool.execute({ recipe }); if (await isAlreadyExecuted(hash)) { throw new Error('This recipe has already been executed'); } await executeRecipe(recipe); await markAsExecuted(hash);
The inputSize field returns the size in bytes of the normalized JSON:
const result = await recipeHashTool.execute({ recipe: { name: 'Small Recipe', steps: [1, 2, 3] } }); console.log(result.inputSize); // 42 (bytes)
This is useful for:
Arrays are also supported:
const recipeArray = [ { step: 1, action: 'fetch' }, { step: 2, action: 'process' }, { step: 3, action: 'store' } ]; const result = await recipeHashTool.execute({ recipe: recipeArray });
0-9a-f (hexadecimal)try { await recipeHashTool.execute({ recipe: null }); } catch (error) { console.error(error.message); // "Recipe cannot be null or undefined" } try { await recipeHashTool.execute({ recipe: "not an object" }); } catch (error) { console.error(error.message); // "Recipe must be an object or array" }
SHA-256 hashing is fast, even for large recipes:
The normalization step adds minimal overhead.
MIT
Downloads/month
0
Quality Score