import { Injectable } from '@nestjs/common'; import { ToolInterface, WorkflowInterface, getBlockArgsSchema, getBlockConfig, getBlockTool } from '@loopstack/common'; import { WorkflowType } from '@loopstack/contracts/dist/types'; @Injectable() export class AiToolsHelperService { getTools(tools: string[], parent: WorkflowInterface): Record | undefined { // using any instead of ToolSet bc ai sdk types have some nesting issue const toolDefinitions: Record = {}; for (const toolName of tools) { const tool = getBlockTool(parent, toolName); if (!tool) { throw new Error(`Tool with name ${toolName} not available in Workflow context.`); } const inputSchema = getBlockArgsSchema(tool); const config = getBlockConfig(tool); if (!config) { throw new Error(`Block ${tool.constructor.name} is missing @BlockConfig decorator`); } if (inputSchema) { toolDefinitions[toolName] = { description: config.description, inputSchema, } as unknown; // using unknown bc ai sdk types have some nesting issue } } return Object.keys(toolDefinitions).length ? toolDefinitions : undefined; } }