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
| 1 | import { liteClient } from 'algoliasearch/lite'; |
| 2 | import type { AlgoliaDocsRecord } from '@/lib/search-index'; |
| 3 | import { ALGOLIA_DEFAULT_APP_ID, ALGOLIA_DEFAULT_INDEX_NAME } from '@/lib/search-index'; |
| 4 | |
| 5 | function requireEnv(name: string, fallback?: string): string { |
| 6 | const value = process.env[name] ?? fallback; |
| 7 | if (!value) throw new Error(`Missing required environment variable: ${name}`); |
| 8 | return value; |
| 9 | } |
| 10 | |
| 11 | const appId = requireEnv('ALGOLIA_APP_ID', process.env.NEXT_PUBLIC_ALGOLIA_APP_ID ?? ALGOLIA_DEFAULT_APP_ID); |
| 12 | const searchApiKey = requireEnv( |
| 13 | 'ALGOLIA_SEARCH_API_KEY', |
| 14 | process.env.NEXT_PUBLIC_ALGOLIA_SEARCH_API_KEY ?? process.env.ALGOLIA_ADMIN_API_KEY, |
| 15 | ); |
| 16 | const indexName = process.env.ALGOLIA_INDEX_NAME ?? process.env.NEXT_PUBLIC_ALGOLIA_INDEX_NAME ?? ALGOLIA_DEFAULT_INDEX_NAME; |
| 17 | const queries = process.argv.slice(2); |
| 18 | |
| 19 | if (queries.length === 0) { |
| 20 | queries.push( |
| 21 | 'quickstart', |
| 22 | 'oauth auth config', |
| 23 | 'create connected account', |
| 24 | 'gmail send email', |
| 25 | 'tool router session search', |
| 26 | 'webhook verification', |
| 27 | ); |
| 28 | } |
| 29 | |
| 30 | const client = liteClient(appId, searchApiKey); |
| 31 | |
| 32 | for (const query of queries) { |
| 33 | const result = await client.searchForHits<AlgoliaDocsRecord>({ |
| 34 | requests: [ |
| 35 | { |
| 36 | type: 'default', |
| 37 | indexName, |
| 38 | query, |
| 39 | hitsPerPage: 5, |
| 40 | distinct: true, |
| 41 | getRankingInfo: true, |
| 42 | clickAnalytics: true, |
| 43 | }, |
| 44 | ], |
| 45 | }); |
| 46 | |
| 47 | const response = result.results[0]; |
| 48 | console.log(`\n## ${query}`); |
| 49 | response.hits.forEach((hit, index) => { |
| 50 | const section = hit.section ? ` — ${hit.section}` : ''; |
| 51 | const snippet = hit.content.replace(/\s+/g, ' ').slice(0, 180); |
| 52 | console.log(`${index + 1}. ${hit.title}${section}`); |
| 53 | console.log(` ${hit.url}`); |
| 54 | console.log(` ${snippet}${snippet.length === 180 ? '…' : ''}`); |
| 55 | }); |
| 56 | } |