UNPKG

@auto-browse/auto-browse

Version:
39 lines (38 loc) 1.44 kB
/** * Copyright (c) Microsoft Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { tool } from '@langchain/core/tools'; import { Context } from '../context.js'; export function defineTool(tool) { return tool; } /** * Creates a LangChain-compatible tool from our existing tool definition * This allows our tools to be used in LangChain implementations while * maintaining their original return type and functionality */ export function createLangChainTool(baseTool) { const toolInstance = tool(async (params) => { const context = await Context.getInstance(); const parsedParams = baseTool.schema.inputSchema.parse(params); const result = await context.run(baseTool, parsedParams); return result; }, { name: baseTool.schema.name, description: baseTool.schema.description, schema: baseTool.schema.inputSchema }); return toolInstance; }