@devries-cameron20 / composio Mirror · read-only
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 03:37 UTC

next
ts 38 lines 1.14 KB
Raw
1 import {
2 getAlgoliaSearchDocuments,
3 type AlgoliaDocsRecord,
4 } from '@/lib/search-index';
5 import { getAuthGuideRegistry, validateAuthGuideUrls } from './auth-guides';
6
7 export interface SearchReplacementClient {
8 replaceAllObjects(input: {
9 indexName: string;
10 objects: AlgoliaDocsRecord[];
11 }): Promise<unknown>;
12 }
13
14 export interface SearchReplacementOptions {
15 fetchImpl?: typeof fetch;
16 validateExternal?: boolean;
17 beforeReplace?: (records: AlgoliaDocsRecord[]) => Promise<void>;
18 }
19
20 export async function buildCompleteSearchReplacement(
21 options: SearchReplacementOptions = {},
22 ): Promise<AlgoliaDocsRecord[]> {
23 if (options.validateExternal !== false) {
24 await validateAuthGuideUrls(getAuthGuideRegistry(), options.fetchImpl);
25 }
26 return getAlgoliaSearchDocuments();
27 }
28
29 export async function replaceSearchDocuments(
30 client: SearchReplacementClient,
31 indexName: string,
32 options: SearchReplacementOptions = {},
33 ): Promise<AlgoliaDocsRecord[]> {
34 const records = await buildCompleteSearchReplacement(options);
35 await options.beforeReplace?.(records);
36 await client.replaceAllObjects({ indexName, objects: records });
37 return records;
38 }