mirror of
https://github.com/simstudioai/sim.git
synced 2026-04-06 03:00:16 -04:00
87 lines
2.2 KiB
TypeScript
87 lines
2.2 KiB
TypeScript
import { ToolConfig, ToolResponse } from '../types'
|
|
|
|
export interface ReadUrlParams {
|
|
url: string
|
|
useReaderLMv2?: boolean
|
|
gatherLinks?: boolean
|
|
jsonResponse?: boolean
|
|
apiKey?: string
|
|
}
|
|
|
|
export interface ReadUrlResponse extends ToolResponse {
|
|
output: {
|
|
content: string
|
|
}
|
|
}
|
|
|
|
export const readUrlTool: ToolConfig<ReadUrlParams, ReadUrlResponse> = {
|
|
id: 'jina_readurl',
|
|
name: 'Jina Reader',
|
|
description:
|
|
'Extract and process web content into clean, LLM-friendly text using Jina AI Reader. Supports advanced content parsing, link gathering, and multiple output formats with configurable processing options.',
|
|
version: '1.0.0',
|
|
|
|
params: {
|
|
url: {
|
|
type: 'string',
|
|
required: true,
|
|
description: 'The URL to read and convert to markdown',
|
|
},
|
|
useReaderLMv2: {
|
|
type: 'boolean',
|
|
description: 'Whether to use ReaderLM-v2 for better quality',
|
|
},
|
|
gatherLinks: {
|
|
type: 'boolean',
|
|
description: 'Whether to gather all links at the end',
|
|
},
|
|
jsonResponse: {
|
|
type: 'boolean',
|
|
description: 'Whether to return response in JSON format',
|
|
},
|
|
apiKey: {
|
|
type: 'string',
|
|
requiredForToolCall: true,
|
|
description: 'Your Jina AI API key',
|
|
},
|
|
},
|
|
|
|
request: {
|
|
url: (params: ReadUrlParams) => {
|
|
return `https://r.jina.ai/https://${params.url.replace(/^https?:\/\//, '')}`
|
|
},
|
|
method: 'GET',
|
|
headers: (params: ReadUrlParams) => {
|
|
// Start with base headers
|
|
const headers: Record<string, string> = {
|
|
Accept: params.jsonResponse ? 'application/json' : 'text/plain',
|
|
Authorization: `Bearer ${params.apiKey}`,
|
|
}
|
|
|
|
// Add conditional headers based on boolean values
|
|
if (params.useReaderLMv2 === true) {
|
|
headers['X-Respond-With'] = 'readerlm-v2'
|
|
}
|
|
if (params.gatherLinks === true) {
|
|
headers['X-With-Links-Summary'] = 'true'
|
|
}
|
|
|
|
return headers
|
|
},
|
|
},
|
|
|
|
transformResponse: async (response: Response) => {
|
|
const content = await response.text()
|
|
return {
|
|
success: response.ok,
|
|
output: {
|
|
content,
|
|
},
|
|
}
|
|
},
|
|
|
|
transformError: (error) => {
|
|
return error instanceof Error ? error.message : 'Failed to read URL'
|
|
},
|
|
}
|