Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"@openrouter/ai-sdk-provider": "^1.5.3",
"secure-json-parse": "^4.1.0",
"@xmldom/xmldom": "^0.8.11",
"@tavily/core": "^0.6.1",
"zod": "^4.1.13"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export {
} from "./tools";

export type { ChatService, BrowserService } from "./service";
export { ExaSearchService } from "./service";
export { ExaSearchService, TavilySearchService } from "./service";

export {
sub,
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/service/chat-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default interface ChatService {
livecrawl?: "fallback" | "preferred";
type?: "auto" | "fast" | "deep";
contextMaxCharacters?: number;
provider?: "exa" | "tavily";
}
): Promise<WebSearchResult[]>;
}
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/service/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ChatService } from "./chat-service";
import { BrowserService } from "./browser-service";
export { ExaSearchService } from "./exa-search";
export { TavilySearchService } from "./tavily-search";

export type { ChatService, BrowserService };
51 changes: 51 additions & 0 deletions packages/core/src/service/tavily-search.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { tavily } from "@tavily/core";

export interface TavilySearchOptions {
query: string;
maxResults?: number;
searchDepth?: "basic" | "advanced";
topic?: "general" | "news" | "finance";
}

/**
* Service for performing web searches using Tavily API
* Returns raw formatted content optimized for LLM consumption
*/
export class TavilySearchService {
/**
* Performs a web search and returns formatted content from Tavily
* @param options Search options
* @param apiKey Tavily API key for authentication
* @returns Raw text content formatted for LLM consumption
*/
static async search(
options: TavilySearchOptions,
apiKey: string
): Promise<string> {
const {
query,
maxResults = 8,
searchDepth = "advanced",
topic = "general"
} = options;

const client = tavily({ apiKey });

const response = await client.search(query, {
maxResults,
searchDepth,
topic
});

if (!response.results || response.results.length === 0) {
return "No search results found. Please try a different query.";
}

return response.results
.map(
(result: { title: string; url: string; content: string }) =>
`Title: ${result.title}\nURL: ${result.url}\nContent: ${result.content}`
)
.join("\n\n---\n\n");
}
}