๐ Lighthouse Unified Integration Guide
โ FINAL IMPLEMENTATION: Unified registerTools() APIโ
This document outlines the final implementation of Lighthouse integration through a unified registerTools() method that accepts both object and array formats.
๐ฏ Overviewโ
Problem Solved: Seamless integration of Lighthouse tools without migration or special methods.
Solution: Enhanced registerTools() method that automatically detects and handles both:
- Object format:
Record<string, SimpleTool>(existing compatibility) - Array format:
Array<{ name: string; tool: SimpleTool }>(Lighthouse compatibility)
๐ง Core Implementationโ
Method Signatureโ
registerTools(tools: Record<string, SimpleTool> | Array<{ name: string; tool: SimpleTool }>): void
Automatic Format Detectionโ
registerTools(tools: Record<string, SimpleTool> | Array<{ name: string; tool: SimpleTool }>): void {
if (Array.isArray(tools)) {
// Handle array format (Lighthouse compatible)
for (const { name, tool } of tools) {
this.registerTool(name, tool);
}
} else {
// Handle object format (existing compatibility)
for (const [name, tool] of Object.entries(tools)) {
this.registerTool(name, tool);
}
}
}
๐ Lighthouse Compatibilityโ
Zod Schema Supportโ
NeuroLink already supports Zod schemas in the SimpleTool interface:
type SimpleTool = {
description: string;
parameters?: ZodSchema; // Zod support already implemented
execute: (params: ToolArgs, context?: ExecutionContext) => Promise<unknown>;
};
Example: Lighthouse Tool Integrationโ
import { NeuroLink } from "@juspay/neurolink";
import { z } from "zod";
const neurolink = new NeuroLink();
// Lighthouse tools exported as array with Zod schemas
const lighthouseTools = [
{
name: "juspay-analytics",
tool: {
description: "Analyze Juspay merchant payment data",
parameters: z.object({
merchantId: z.string().describe("Merchant identifier"),
dateRange: z.object({
start: z.string().datetime(),
end: z.string().datetime(),
}),
metrics: z
.array(z.enum(["volume", "success_rate", "avg_amount"]))
.optional(),
}),
execute: async ({ merchantId, dateRange, metrics }) => {
// Lighthouse tool implementation
return {
merchantId,
period: dateRange,
analytics: {
totalVolume: 125000,
successRate: 0.987,
avgAmount: 45.67,
},
};
},
},
},
{
name: "payment-processor",
tool: {
description: "Process payment transactions",
parameters: z.object({
amount: z.number().positive(),
currency: z.string().length(3),
paymentMethod: z.enum(["card", "upi", "wallet"]),
}),
execute: async ({ amount, currency, paymentMethod }) => {
return {
transactionId: `txn_${Date.now()}`,
status: "success",
amount,
currency,
method: paymentMethod,
};
},
},
},
];
// Register Lighthouse tools using unified API
neurolink.registerTools(lighthouseTools);
// Use in AI generation
const result = await neurolink.generate({
input: {
text: "Show me payment analytics for merchant MERCH123 for the last week",
},
provider: "google-ai",
});
๐ Compatibility Matrixโ
| Format | Type | Lighthouse Compatible | Backward Compatible | Status |
|---|---|---|---|---|
| Object | Record<string, SimpleTool> | โ ๏ธ Requires conversion | โ Yes | Existing |
| Array | Array<{ name: string; tool: SimpleTool }> | โ Direct compatibility | โ Yes | New |
๐ Migration Pathโ
Existing Codeโ
No changes required - object format continues to work:
// Existing code remains unchanged
neurolink.registerTools({
myTool: { description: "...", execute: async () => {...} }
});
New Lighthouse Integrationโ
Direct import using array format:
// Lighthouse tools can be imported directly
import { lighthouseAnalyticsTools } from "lighthouse-sdk";
neurolink.registerTools(lighthouseAnalyticsTools);
๐ Benefitsโ
- Unified API: Single method for all tool registration needs
- Zero Migration: Lighthouse tools work without conversion
- Backward Compatibility: Existing code unchanged
- Type Safety: Full TypeScript support for both formats
- Zod Integration: Native support for Zod parameter validation
- API Simplification: Removes need for separate methods
๐งช Testing Strategyโ
Format Detection Testsโ
describe("Unified registerTools()", () => {
test("should detect object format", () => {
neurolink.registerTools({ tool1: {...}, tool2: {...} });
expect(neurolink.getCustomTools().size).toBe(2);
});
test("should detect array format", () => {
neurolink.registerTools([
{ name: "tool1", tool: {...} },
{ name: "tool2", tool: {...} }
]);
expect(neurolink.getCustomTools().size).toBe(2);
});
test("should support mixed registration", () => {
neurolink.registerTools({ objectTool: {...} });
neurolink.registerTools([{ name: "arrayTool", tool: {...} }]);
expect(neurolink.getCustomTools().size).toBe(2);
});
});
Lighthouse Integration Testsโ
describe("Lighthouse Integration", () => {
test("should register Lighthouse tools with Zod schemas", () => {
const lighthouseTools = [
{
name: "analytics",
tool: {
description: "Analytics tool",
parameters: z.object({ merchantId: z.string() }),
execute: async ({ merchantId }) => ({ data: merchantId }),
},
},
];
neurolink.registerTools(lighthouseTools);
const result = await neurolink.executeTool("analytics", {
merchantId: "test",
});
expect(result.data).toBe("test");
});
});
๐ Implementation Checklistโ
- Design: Unified method signature with union types
- Detection: Automatic format detection using
Array.isArray() - Compatibility: Zod schema support verification
- Documentation: Updated README and guides
- Implementation: Modify
registerTools()method in NeuroLink class - Cleanup: Remove redundant
registerToolsFromArray()method (never existed) - Testing: Update tests for unified method
- Validation: End-to-end integration testing
๐ฎ Future Extensibilityโ
The unified approach supports future extensions:
// Future: Additional format support
registerTools(tools:
| Record<string, SimpleTool> // Object format
| Array<{ name: string; tool: SimpleTool }> // Array format
| MCPServerConfig // Future: MCP server format
| PluginManifest // Future: Plugin format
): void
This architecture ensures the API can grow with new tool formats while maintaining compatibility.