-
Notifications
You must be signed in to change notification settings - Fork 134
add exa search #130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
NicolasMontone
wants to merge
3
commits into
vercel-labs:main
Choose a base branch
from
NicolasMontone:monto/add-exa
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
add exa search #130
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,8 @@ | |
| "db:push": "drizzle-kit push", | ||
| "db:studio": "drizzle-kit studio", | ||
| "discover-plugins": "tsx scripts/discover-plugins.ts", | ||
| "create-plugin": "tsx scripts/create-plugin.ts" | ||
| "create-plugin": "tsx scripts/create-plugin.ts", | ||
| "workflow:runs:web": "npx workflow inspect runs --web" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove unrelated change |
||
| }, | ||
| "dependencies": { | ||
| "@ai-sdk/provider": "^2.0.0", | ||
|
|
@@ -36,6 +37,7 @@ | |
| "clsx": "^2.1.1", | ||
| "dotenv": "^17.2.3", | ||
| "drizzle-orm": "^0.44.7", | ||
| "exa-js": "^2.0.11", | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused dependency, please remove |
||
| "jotai": "^2.15.1", | ||
| "jszip": "^3.10.1", | ||
| "lucide-react": "^0.552.0", | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /** | ||
| * Code generation template for Exa Search action | ||
| * This template is used when exporting workflows to standalone Next.js projects | ||
| * It uses environment variables instead of integrationId | ||
| */ | ||
| export const searchCodegenTemplate = `import Exa from 'exa-js'; | ||
|
|
||
| export async function exaSearchStep(input: { | ||
| query: string; | ||
| numResults?: number; | ||
| type?: 'auto' | 'neural' | 'fast' | 'deep'; | ||
| }) { | ||
| "use step"; | ||
|
|
||
| const exa = new Exa(process.env.EXA_API_KEY!); | ||
|
|
||
| const result = await exa.search(input.query, { | ||
| numResults: input.numResults || 10, | ||
| type: input.type || 'auto', | ||
| }); | ||
|
|
||
| return { | ||
| results: result.results.map((r) => ({ | ||
| url: r.url, | ||
| title: r.title, | ||
| publishedDate: r.publishedDate, | ||
| author: r.author, | ||
| text: r.text, | ||
| })), | ||
| }; | ||
| }`; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| export function ExaIcon({ className }: { className?: string }) { | ||
| return ( | ||
| <svg | ||
| aria-label="Exa logo" | ||
| className={className} | ||
| fill="currentColor" | ||
| viewBox="0 0 277 100" | ||
| xmlns="http://www.w3.org/2000/svg" | ||
| > | ||
| <title>Exa</title> | ||
| <path | ||
| d="M161.632 53.2837H115.472C115.918 66.4186 125.061 72.7596 133.981 72.7596C142.9 72.7596 147.806 68.6833 150.371 62.682H160.851C158.064 73.2126 148.587 81.8182 133.981 81.8182C115.026 81.8182 104.545 68.0039 104.545 50C104.545 30.7506 117.256 18.4083 133.646 18.4083C151.931 18.4083 162.97 34.0343 161.632 53.2837ZM133.646 27.2404C124.615 27.2404 116.476 32.2226 115.584 44.4516H150.928C150.705 35.846 144.35 27.2404 133.646 27.2404Z" | ||
| fill="currentColor" | ||
| /> | ||
| <path | ||
| d="M219.201 19.4274L198.797 48.528L221.208 80.3462H209.055L192.777 57.1336L176.61 80.3462H165.014L187.09 48.9809L166.352 19.4274H178.505L193.111 40.3753L207.829 19.4274H219.201Z" | ||
| fill="currentColor" | ||
| /> | ||
| <path | ||
| d="M266.458 54.869V51.0191C248.061 52.944 236.354 55.6616 236.354 64.0408C236.354 69.8156 240.702 73.6655 247.949 73.6655C257.426 73.6655 266.458 69.2494 266.458 54.869ZM245.719 81.8182C234.458 81.8182 225.092 75.4772 225.092 64.2672C225.092 49.8868 241.036 45.6972 265.677 42.8664V41.3944C265.677 30.2976 259.545 26.561 252.075 26.561C243.712 26.561 238.806 31.2035 238.36 38.6768H227.88C228.883 25.5419 240.256 18.1818 251.963 18.1818C268.465 18.1818 275.935 26.2213 275.823 43.3193L275.712 57.3601C275.6 67.551 276.158 74.5713 277.273 80.3462H267.015C266.681 78.0815 266.346 75.5904 266.235 71.967C262.555 78.1948 256.311 81.8182 245.719 81.8182Z" | ||
| fill="currentColor" | ||
| /> | ||
| <path | ||
| fillRule="evenodd" | ||
| clipRule="evenodd" | ||
| d="M0 0H78.1818V7.46269L44.8165 50L78.1818 92.5373V100H0V0ZM39.5825 43.1172L66.6956 7.46269H12.4695L39.5825 43.1172ZM8.79612 16.3977V46.2687H31.5111L8.79612 16.3977ZM31.5111 53.7313H8.79612V83.6023L31.5111 53.7313ZM12.4695 92.5373L39.5825 56.8828L66.6956 92.5373H12.4695Z" | ||
| fill="#1F40ED" | ||
| /> | ||
| </svg> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| import type { IntegrationPlugin } from "../registry"; | ||
| import { registerIntegration } from "../registry"; | ||
| import { searchCodegenTemplate } from "./codegen/search"; | ||
| import { ExaIcon } from "./icon"; | ||
|
|
||
| const exaPlugin: IntegrationPlugin = { | ||
| type: "exa", | ||
| label: "Exa", | ||
| description: | ||
| "Semantic web search API giving AI apps fast, relevant, up-to-date results", | ||
|
|
||
| icon: ExaIcon, | ||
|
|
||
| formFields: [ | ||
| { | ||
| id: "exaApiKey", | ||
| label: "API Key", | ||
| type: "password", | ||
| placeholder: "Your Exa API key", | ||
| configKey: "exaApiKey", | ||
| envVar: "EXA_API_KEY", | ||
| helpText: "Get your API key from ", | ||
| helpLink: { | ||
| text: "Exa Dashboard", | ||
| url: "https://dashboard.exa.ai/api-keys/", | ||
| }, | ||
| }, | ||
| ], | ||
|
|
||
| testConfig: { | ||
| getTestFunction: async () => { | ||
| const { testExa } = await import("./test"); | ||
| return testExa; | ||
| }, | ||
| }, | ||
|
|
||
| dependencies: { | ||
| "exa-js": "^1.5.12", | ||
NicolasMontone marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }, | ||
|
|
||
| actions: [ | ||
| { | ||
| slug: "search", | ||
| label: "Search Web", | ||
| description: | ||
| "Perform semantic web search and retrieve relevant results with content", | ||
| category: "Exa", | ||
| stepFunction: "exaSearchStep", | ||
| stepImportPath: "search", | ||
| configFields: [ | ||
| { | ||
| key: "query", | ||
| label: "Search Query", | ||
| type: "template-input", | ||
| placeholder: "Search query or {{NodeName.query}}", | ||
| example: "latest AI research papers", | ||
| required: true, | ||
| }, | ||
| { | ||
| key: "numResults", | ||
| label: "Number of Results", | ||
| type: "number", | ||
| placeholder: "10", | ||
| min: 1, | ||
| example: "10", | ||
| }, | ||
| { | ||
| key: "type", | ||
| label: "Search Type", | ||
| type: "select", | ||
| options: [ | ||
| { value: "auto", label: "Auto" }, | ||
| { value: "neural", label: "Neural" }, | ||
| { value: "fast", label: "Fast" }, | ||
| { value: "deep", label: "Deep" }, | ||
| ], | ||
| defaultValue: "auto", | ||
| }, | ||
| ], | ||
| codegenTemplate: searchCodegenTemplate, | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| // Auto-register on import | ||
| registerIntegration(exaPlugin); | ||
|
|
||
| export default exaPlugin; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import "server-only"; | ||
|
|
||
| import Exa from "exa-js"; | ||
| import { fetchCredentials } from "@/lib/credential-fetcher"; | ||
| import { type StepInput, withStepLogging } from "@/lib/steps/step-handler"; | ||
| import { getErrorMessage } from "@/lib/utils"; | ||
|
|
||
| type ExaSearchResult = { | ||
| results: Array<{ | ||
| url: string; | ||
| title: string | null; | ||
| publishedDate?: string; | ||
| author?: string; | ||
| text?: string; | ||
| }>; | ||
| }; | ||
|
|
||
| export type ExaSearchInput = StepInput & { | ||
| integrationId?: string; | ||
| query: string; | ||
| numResults?: number; | ||
| type?: "auto" | "neural" | "fast" | "deep"; | ||
| }; | ||
|
|
||
| /** | ||
| * Search logic using Exa SDK | ||
| */ | ||
| async function search(input: ExaSearchInput): Promise<ExaSearchResult> { | ||
| const credentials = input.integrationId | ||
| ? await fetchCredentials(input.integrationId) | ||
| : {}; | ||
|
|
||
| const apiKey = credentials.EXA_API_KEY; | ||
|
|
||
| if (!apiKey) { | ||
| throw new Error("Exa API Key is not configured."); | ||
| } | ||
|
|
||
| try { | ||
| const exa = new Exa(apiKey); | ||
|
|
||
| const result = await exa.search(input.query, { | ||
| numResults: input.numResults ? Number(input.numResults) : 10, | ||
| type: input.type || "auto", | ||
| }); | ||
|
|
||
| return { | ||
| results: result.results.map((r) => ({ | ||
| url: r.url, | ||
| title: r.title, | ||
| publishedDate: r.publishedDate, | ||
| author: r.author, | ||
| text: r.text, | ||
| })), | ||
| }; | ||
| } catch (error) { | ||
| throw new Error(`Failed to search: ${getErrorMessage(error)}`); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Exa Search Step | ||
| * Performs semantic web search using Exa | ||
| */ | ||
| export async function exaSearchStep( | ||
| input: ExaSearchInput | ||
| ): Promise<ExaSearchResult> { | ||
| "use step"; | ||
| return withStepLogging(input, () => search(input)); | ||
| } | ||
NicolasMontone marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| export async function testExa(credentials: Record<string, string>) { | ||
| try { | ||
| const apiKey = credentials.EXA_API_KEY; | ||
|
|
||
| if (!apiKey) { | ||
| return { | ||
| success: false, | ||
| error: "EXA_API_KEY is required", | ||
| }; | ||
| } | ||
|
|
||
| // Use a minimal search request to validate the API key | ||
| const response = await fetch("https://api.exa.ai/search", { | ||
| method: "POST", | ||
| headers: { | ||
| "Content-Type": "application/json", | ||
| "x-api-key": apiKey, | ||
| }, | ||
| body: JSON.stringify({ | ||
| query: "test", | ||
| numResults: 1, | ||
| type: "keyword", | ||
NicolasMontone marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }), | ||
| }); | ||
|
|
||
| if (response.ok) { | ||
| return { success: true }; | ||
| } | ||
|
|
||
| const error = await response.text(); | ||
| return { success: false, error: error || "Invalid API key" }; | ||
| } catch (error) { | ||
| return { | ||
| success: false, | ||
| error: error instanceof Error ? error.message : String(error), | ||
| }; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove unrelated changes