feat: add exa web search source (#124)

This commit is contained in:
2026-06-13 00:46:53 +01:00
committed by GitHub
parent 877b955493
commit ef7301ab18
15 changed files with 906 additions and 38 deletions

View File

@@ -66,6 +66,14 @@ export function SourceConfigPanel({ source, onUpdate }: SourceConfigPanelProps)
return creds
}
function buildReplaceBody(enabledValue: boolean): Parameters<typeof replaceSource>[1] {
const body: Parameters<typeof replaceSource>[1] = { enabled: enabledValue }
if (Object.keys(source.fields).length > 0) {
body.config = getUserConfig()
}
return body
}
function invalidate() {
queryClient.invalidateQueries({ queryKey: ["sourceConfig", source.id] })
queryClient.invalidateQueries({ queryKey: ["configs"] })
@@ -79,10 +87,7 @@ export function SourceConfigPanel({ source, onUpdate }: SourceConfigPanelProps)
(v) => typeof v === "string" && v.length > 0,
)
const body: Parameters<typeof replaceSource>[1] = {
enabled,
config: getUserConfig(),
}
const body = buildReplaceBody(enabled)
if (hasCredentials && source.perUserCredentials) {
body.credentials = credentialFields
}
@@ -104,8 +109,7 @@ export function SourceConfigPanel({ source, onUpdate }: SourceConfigPanelProps)
})
const toggleMutation = useMutation({
mutationFn: (checked: boolean) =>
replaceSource(source.id, { enabled: checked, config: getUserConfig() }),
mutationFn: (checked: boolean) => replaceSource(source.id, buildReplaceBody(checked)),
onSuccess(_data, checked) {
invalidate()
toast.success(`Source ${checked ? "enabled" : "disabled"}`)
@@ -116,7 +120,7 @@ export function SourceConfigPanel({ source, onUpdate }: SourceConfigPanelProps)
})
const deleteMutation = useMutation({
mutationFn: () => replaceSource(source.id, { enabled: false, config: {} }),
mutationFn: () => replaceSource(source.id, buildReplaceBody(false)),
onSuccess() {
setDirty({})
invalidate()

View File

@@ -151,6 +151,12 @@ const sourceDefinitions: SourceDefinition[] = [
},
},
},
{
id: "freya.web-search",
name: "Web Search",
description: "Exa web search action. Requires EXA_API_KEY on the backend.",
fields: {},
},
]
export function fetchSources(): Promise<SourceDefinition[]> {
@@ -174,7 +180,7 @@ export async function fetchConfigs(): Promise<SourceConfig[]> {
export async function replaceSource(
sourceId: string,
body: { enabled: boolean; config: unknown; credentials?: Record<string, unknown> },
body: { enabled: boolean; config?: unknown; credentials?: Record<string, unknown> },
): Promise<void> {
const res = await fetch(`${serverBase()}/sources/${sourceId}`, {
method: "PUT",