Modified jina block/tool, simplified checklist to evaluate each item as an individual sub-block for serializer/executor consistency

This commit is contained in:
Waleed Latif
2025-02-05 02:45:17 -08:00
parent 70aa37414b
commit 5b274dadf3
3 changed files with 47 additions and 80 deletions

View File

@@ -2,7 +2,6 @@ import { Label } from '@/components/ui/label'
import { Checkbox } from '@/components/ui/checkbox'
import { useSubBlockValue } from '../hooks/use-sub-block-value'
import { cn } from '@/lib/utils'
import { useEffect } from 'react'
interface CheckboxListProps {
blockId: string
@@ -19,38 +18,6 @@ export function CheckboxList({
options,
layout,
}: CheckboxListProps) {
const [value, setValue] = useSubBlockValue(blockId, subBlockId)
// Initialize values with all options set to false by default
const values = (() => {
const defaultValues = options.reduce(
(acc, option) => ({
...acc,
[option.id]: false,
}),
{}
)
return {
...defaultValues,
...(typeof value === 'object' && value !== null ? value : {}),
}
})() as Record<string, boolean>
// Move initialization to useEffect
useEffect(() => {
if (value === null) {
setValue(values)
}
}, [value, setValue, values])
const handleCheckedChange = (id: string, checked: boolean) => {
setValue({
...values,
[id]: checked,
})
}
return (
<div
className={cn(
@@ -59,23 +26,24 @@ export function CheckboxList({
'pt-1'
)}
>
{options.map((option) => (
<div key={option.id} className="flex items-center space-x-2">
<Checkbox
id={`${blockId}-${subBlockId}-${option.id}`}
checked={Boolean(values[option.id])}
onCheckedChange={(checked) =>
handleCheckedChange(option.id, checked as boolean)
}
/>
<Label
htmlFor={`${blockId}-${subBlockId}-${option.id}`}
className="text-sm font-normal leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70 cursor-pointer"
>
{option.label}
</Label>
</div>
))}
{options.map((option) => {
const [value, setValue] = useSubBlockValue(blockId, option.id)
return (
<div key={option.id} className="flex items-center space-x-2">
<Checkbox
id={`${blockId}-${option.id}`}
checked={Boolean(value)}
onCheckedChange={(checked) => setValue(checked as boolean)}
/>
<Label
htmlFor={`${blockId}-${option.id}`}
className="text-sm font-normal leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70 cursor-pointer"
>
{option.label}
</Label>
</div>
)
})}
</div>
)
}

View File

@@ -9,7 +9,7 @@ export const JinaBlock: BlockConfig<ReadUrlResponse> = {
description: 'Convert website content into text',
bgColor: '#333333',
icon: JinaAIIcon,
category: 'tools',
category: 'tools'
},
tools: {
access: ['jina_readurl']
@@ -18,9 +18,9 @@ export const JinaBlock: BlockConfig<ReadUrlResponse> = {
inputs: {
url: { type: 'string', required: true },
useReaderLMv2: { type: 'boolean', required: false },
removeImages: { type: 'boolean', required: false },
gatherLinks: { type: 'boolean', required: false },
jsonResponse: { type: 'boolean', required: false }
jsonResponse: { type: 'boolean', required: false },
apiKey: { type: 'string', required: true }
},
outputs: {
response: {
@@ -35,18 +35,17 @@ export const JinaBlock: BlockConfig<ReadUrlResponse> = {
title: 'URL',
type: 'short-input',
layout: 'full',
placeholder: 'Enter URL to read',
placeholder: 'Enter URL to extract content from'
},
{
id: 'options',
title: 'Options',
type: 'checkbox-list',
layout: 'half',
layout: 'full',
options: [
{ label: 'Use ReaderLM v2', id: 'useReaderLMv2' },
{ label: 'Remove Images', id: 'removeImages' },
{ label: 'Gather Links', id: 'gatherLinks' },
{ label: 'JSON Response', id: 'jsonResponse' }
{ id: 'useReaderLMv2', label: 'Use Reader LM v2' },
{ id: 'gatherLinks', label: 'Gather Links' },
{ id: 'jsonResponse', label: 'JSON Response' }
]
},
{
@@ -54,9 +53,9 @@ export const JinaBlock: BlockConfig<ReadUrlResponse> = {
title: 'API Key',
type: 'short-input',
layout: 'full',
placeholder: 'Enter API Key (optional)',
placeholder: 'Enter your Jina API key',
password: true
}
],
},
]
}
}

View File

@@ -3,7 +3,6 @@ import { ToolConfig, ToolResponse } from '../types'
export interface ReadUrlParams {
url: string
useReaderLMv2?: boolean
removeImages?: boolean
gatherLinks?: boolean
jsonResponse?: boolean
apiKey?: string
@@ -31,10 +30,6 @@ export const readUrlTool: ToolConfig<ReadUrlParams, ReadUrlResponse> = {
type: 'boolean',
description: 'Whether to use ReaderLM-v2 for better quality'
},
removeImages: {
type: 'boolean',
description: 'Whether to remove all images from the response'
},
gatherLinks: {
type: 'boolean',
description: 'Whether to gather all links at the end'
@@ -51,21 +46,26 @@ export const readUrlTool: ToolConfig<ReadUrlParams, ReadUrlResponse> = {
request: {
url: (params: ReadUrlParams) => {
const baseUrl = `https://r.jina.ai/https://${params.url.replace(/^https?:\/\//, '')}`
const queryParams = new URLSearchParams()
if (params.useReaderLMv2) queryParams.append('use_readerlm_v2', 'true')
if (params.removeImages) queryParams.append('remove_images', 'true')
if (params.gatherLinks) queryParams.append('gather_links', 'true')
if (params.jsonResponse) queryParams.append('json_response', 'true')
return `${baseUrl}${queryParams.toString() ? '?' + queryParams.toString() : ''}`
return `https://r.jina.ai/https://${params.url.replace(/^https?:\/\//, '')}`
},
method: 'GET',
headers: (params: ReadUrlParams) => ({
'Content-Type': 'application/json',
'Authorization': `Bearer ${params.apiKey}`
})
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) => {