Consolidated separate tavily blocks into one

This commit is contained in:
Waleed Latif
2025-02-10 12:10:59 -08:00
parent 83c88f3990
commit 05ad0846f8
3 changed files with 107 additions and 79 deletions

View File

@@ -1,104 +1,70 @@
import { TavilyIcon } from '@/components/icons'
import { ExtractResponse } from '@/tools/tavily/extract'
import { SearchResponse } from '@/tools/tavily/search'
import { TavilyExtractResponse, TavilySearchResponse } from '@/tools/tavily/types'
import { BlockConfig } from '../types'
export const TavilySearchBlock: BlockConfig<SearchResponse> = {
type: 'tavily_search',
toolbar: {
title: 'Tavily Search',
description: 'Search the web using Tavily AI',
bgColor: '#0066FF',
icon: TavilyIcon,
category: 'tools',
},
tools: {
access: ['tavily_search'],
},
workflow: {
inputs: {
query: { type: 'string', required: true },
apiKey: { type: 'string', required: true },
max_results: { type: 'number', required: false },
},
outputs: {
response: {
type: {
query: 'string',
results: 'json',
response_time: 'number',
},
},
},
subBlocks: [
{
id: 'query',
title: 'Search Query',
type: 'short-input',
layout: 'full',
placeholder: 'Enter your search query...',
},
{
id: 'max_results',
title: 'Max Results',
type: 'dropdown',
layout: 'half',
options: ['5', '10', '15', '20'],
},
{
id: 'apiKey',
title: 'API Key',
type: 'short-input',
layout: 'full',
placeholder: 'Enter your Tavily API key',
password: true,
},
],
},
}
type TavilyResponse = TavilySearchResponse | TavilyExtractResponse
export const TavilyExtractBlock: BlockConfig<ExtractResponse> = {
type: 'tavily_extract',
export const TavilyBlock: BlockConfig<TavilyResponse> = {
type: 'tavily_block',
toolbar: {
title: 'Tavily Extract',
description: 'Scrape website content',
title: 'Tavily',
description: 'Search and extract information using Tavily AI',
bgColor: '#0066FF',
icon: TavilyIcon,
category: 'tools',
},
tools: {
access: ['tavily_extract'],
access: ['tavily_search', 'tavily_extract'],
config: {
tool: (params) => {
switch (params.operation) {
case 'tavily_search':
return 'tavily_search'
case 'tavily_extract':
return 'tavily_extract'
default:
return 'tavily_search'
}
},
},
},
workflow: {
inputs: {
urls: { type: 'string', required: true },
operation: { type: 'string', required: true },
apiKey: { type: 'string', required: true },
// Search operation
query: { type: 'string', required: false },
maxResults: { type: 'number', required: false },
// Extract operation
urls: { type: 'string', required: false },
extract_depth: { type: 'string', required: false },
},
outputs: {
response: {
type: {
results: 'json',
failed_results: 'any',
response_time: 'number',
answer: 'any',
query: 'string',
content: 'string',
title: 'string',
url: 'string',
},
},
},
subBlocks: [
// Operation selector
{
id: 'urls',
title: 'URL',
type: 'short-input',
layout: 'full',
placeholder: 'Enter URL to extract content from...',
},
{
id: 'extract_depth',
title: 'Extract Depth',
id: 'operation',
title: 'Operation',
type: 'dropdown',
layout: 'half',
options: ['basic', 'advanced'],
layout: 'full',
options: [
{ label: 'Search', id: 'tavily_search' },
{ label: 'Extract Content', id: 'tavily_extract' },
],
value: () => 'tavily_search',
},
// API Key (common)
{
id: 'apiKey',
title: 'API Key',
@@ -107,6 +73,41 @@ export const TavilyExtractBlock: BlockConfig<ExtractResponse> = {
placeholder: 'Enter your Tavily API key',
password: true,
},
// Search operation inputs
{
id: 'query',
title: 'Search Query',
type: 'long-input',
layout: 'full',
placeholder: 'Enter your search query...',
condition: { field: 'operation', value: 'tavily_search' },
},
{
id: 'maxResults',
title: 'Max Results',
type: 'short-input',
layout: 'full',
placeholder: '5',
condition: { field: 'operation', value: 'tavily_search' },
},
// Extract operation inputs
{
id: 'urls',
title: 'URL',
type: 'long-input',
layout: 'full',
placeholder: 'Enter URL to extract content from...',
condition: { field: 'operation', value: 'tavily_extract' },
},
{
id: 'extract_depth',
title: 'Extract Depth',
type: 'dropdown',
layout: 'full',
options: ['basic', 'advanced'],
value: () => 'basic',
condition: { field: 'operation', value: 'tavily_extract' },
},
],
},
}

View File

@@ -12,7 +12,7 @@ import { NotionBlock } from './blocks/notion'
import { RouterBlock } from './blocks/router'
import { SerperBlock } from './blocks/serper'
import { SlackMessageBlock } from './blocks/slack'
import { TavilyExtractBlock, TavilySearchBlock } from './blocks/tavily'
import { TavilyBlock } from './blocks/tavily'
import { TranslateBlock } from './blocks/translate'
import { XBlock } from './blocks/x'
import { YouTubeSearchBlock } from './blocks/youtube'
@@ -31,8 +31,7 @@ export {
GitHubBlock,
ConditionBlock,
SerperBlock,
TavilySearchBlock,
TavilyExtractBlock,
TavilyBlock,
RouterBlock,
YouTubeSearchBlock,
NotionBlock,
@@ -54,8 +53,7 @@ const blocks: Record<string, BlockConfig> = {
slack_message: SlackMessageBlock,
github_repo_info: GitHubBlock,
serper_search: SerperBlock,
tavily_search: TavilySearchBlock,
tavily_extract: TavilyExtractBlock,
tavily_block: TavilyBlock,
youtube_search: YouTubeSearchBlock,
notion_reader: NotionBlock,
gmail_block: GmailBlock,

29
tools/tavily/types.ts Normal file
View File

@@ -0,0 +1,29 @@
import { ToolResponse } from '../types'
export interface TavilySearchResult {
title: string
url: string
content: string
score: number
images?: string[]
raw_content?: string
}
export interface TavilySearchResponse extends ToolResponse {
output: {
results: TavilySearchResult[]
answer?: string
query: string
images?: string[]
rawContent?: string
}
}
export interface TavilyExtractResponse extends ToolResponse {
output: {
content: string
title: string
url: string
rawContent?: string
}
}