@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, 04:45 UTC

next
ts 34 lines 1.02 KB
Raw
1 import { NextRequest, NextResponse } from 'next/server';
2 import { searchDocs, shouldRunEagerDocsSearch } from '@/agent/lib/docs-search';
3
4 const EAGER_PREVIEW_LIMIT = 3;
5
6 export async function POST(request: NextRequest) {
7 try {
8 const body = (await request.json()) as { message?: unknown };
9 const message = typeof body.message === 'string' ? body.message.trim() : '';
10
11 if (message.length < 3) {
12 return NextResponse.json({ sources: [] });
13 }
14
15 if (!shouldRunEagerDocsSearch(message)) {
16 return NextResponse.json({ sources: [] });
17 }
18
19 const result = searchDocs(message, {
20 limit: EAGER_PREVIEW_LIMIT,
21 hydrateContent: false,
22 invocation: 'eager_preview',
23 });
24
25 return NextResponse.json({
26 sources: result.results.map(({ title, url }) => ({ title, url })),
27 });
28 } catch (error) {
29 console.warn('[docs-agent:eager_preview] failed', {
30 error: error instanceof Error ? error.message : String(error),
31 });
32 return NextResponse.json({ sources: [] }, { status: 500 });
33 }
34 }