@kaibanjs/tools
Version:
A set of tools to work with LLMs and KaibanJS
103 lines (102 loc) • 3.57 kB
TypeScript
/**
* Jina URL to Markdown
*
* This tool integrates with Jina (https://jina.ai/), a web scraping
* and crawling service designed to turn websites into LLM-ready data.
*
* Jina allows you to extract clean, well-formatted markdown or structured data
* from websites, making it ideal for AI applications, particularly those using
* Large Language Models (LLMs).
*
* Key features of Jina:
* - Scrapes and crawls websites, even those with dynamic content
* - Converts web content into clean, LLM-ready markdown
* - Handles challenges like rate limits, JavaScript rendering, and anti-bot mechanisms
* - Offers flexible pricing plans, including a free tier for small-scale use
*
* Usage:
* const tool = new JinaUrlToMarkdown();
* const result = await tool._call({ url: 'https://example.com' });
* or
* const tool = new JinaUrlToMarkdown({ apiKey: 'your-api-key', options: { 'targetSelector': ['body', '.class', '#id'], 'retainImages': 'none' } });
* const result = await tool._call({ url: 'https://example.com' });
*
* For more information about Jina, visit: https://jina.ai/, https://r.jina.ai/docs
*/
import { StructuredTool } from '@langchain/core/tools';
import { z } from 'zod';
import ky from 'ky';
/**
* Configuration options for the Jina URL to Markdown conversion
* @interface JinaUrlToMarkdownOptions
* @property {string[]} [targetSelector] - CSS selectors to target specific elements for extraction
* @property {string} [retainImages] - Image handling strategy ('all', 'none', or specific selectors)
* @example
* {
* targetSelector: ['article', '.content', '#main'],
* retainImages: 'none'
* }
*/
type JinaUrlToMarkdownOptions = {
targetSelector?: string[];
retainImages?: string;
};
/**
* Input parameters for the Jina URL to Markdown tool
* @interface JinaUrlToMarkdownInput
* @property {string} url - The URL of the webpage to convert to markdown
* @example
* {
* url: "https://example.com/blog/post"
* }
*/
type JinaUrlToMarkdownInput = {
url: string;
};
/**
* Constructor parameters for the JinaUrlToMarkdown tool
* @interface JinaUrlToMarkdownFields
* @property {string} [apiKey] - Jina API key for authentication
* @property {JinaUrlToMarkdownOptions} [options] - Configuration options for the conversion
*/
interface JinaUrlToMarkdownFields {
apiKey?: string;
options?: JinaUrlToMarkdownOptions;
}
/**
* Successful response containing markdown content
* @typedef {string} JinaUrlToMarkdownResult
* @example
* "# Article Title\n\nThis is the content of the article..."
*/
type JinaUrlToMarkdownResult = string;
/**
* Error message returned when the conversion fails
* @typedef {string} JinaUrlToMarkdownError
* @example
* "API request failed: Client Error (404)"
*/
type JinaUrlToMarkdownError = string;
/**
* Response type that can either be markdown content or an error message
* @typedef {JinaUrlToMarkdownResult | JinaUrlToMarkdownError} JinaUrlToMarkdownResponse
*/
type JinaUrlToMarkdownResponse = JinaUrlToMarkdownResult | JinaUrlToMarkdownError;
export declare class JinaUrlToMarkdown extends StructuredTool {
name: string;
description: string;
apiKey?: string;
options: JinaUrlToMarkdownOptions;
headers: Record<string, string>;
schema: z.ZodObject<{
url: z.ZodString;
}, "strip", z.ZodTypeAny, {
url: string;
}, {
url: string;
}>;
httpClient: typeof ky;
constructor(fields?: JinaUrlToMarkdownFields);
_call(input: JinaUrlToMarkdownInput): Promise<JinaUrlToMarkdownResponse>;
}
export {};