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

next
ts 50 lines 2.1 KB
Raw
1 import { defineTool } from 'eve/tools';
2 import { z } from 'zod';
3 import { buildIndex, extractSections, readPageByUrl, toCleanMarkdown } from '../lib/docs';
4
5 /**
6 * read_doc — read the full content of a Composio docs page.
7 *
8 * Pass a URL from search_docs (or the concept map) and get the page's cleaned
9 * Markdown so you can answer from real content instead of a snippet.
10 */
11
12 const MAX_CHARS = 12000;
13
14 export default defineTool({
15 description:
16 'Read the full Markdown content of a Composio docs page or Knowledge Base guide by its URL (e.g. "/docs/authentication" or "/kb/guide/<slug>"). Returns the page content plus its `sections` (with anchors). Use this on the most relevant pages from search_docs before answering, and link the specific section anchor (e.g. /docs/how-composio-works#users) when your answer comes from one.',
17 inputSchema: z.object({
18 url: z.string().min(1).describe('The page URL, e.g. "/docs/authentication" or "/docs/configuring-sessions".'),
19 }),
20 async execute({ url }) {
21 const clean = url.split('#')[0].split('?')[0].replace(/\/$/, '');
22 const page = readPageByUrl(url);
23 if (page) {
24 const markdown = toCleanMarkdown(page.raw);
25 const truncated = markdown.length > MAX_CHARS;
26 return {
27 found: true,
28 url: clean,
29 title: page.title,
30 sections: extractSections(markdown),
31 truncated,
32 content: truncated ? `${markdown.slice(0, MAX_CHARS)}\n\n…(truncated)` : markdown,
33 };
34 }
35 // Fallback: the page may be indexed even if its source file can't be read
36 // directly (e.g. a different runtime layout). Return the indexed text.
37 const indexed = buildIndex().find((p) => p.url === clean);
38 if (indexed && indexed.text) {
39 const truncated = indexed.text.length > MAX_CHARS;
40 return {
41 found: true,
42 url: clean,
43 title: indexed.title,
44 truncated,
45 content: truncated ? `${indexed.text.slice(0, MAX_CHARS)}\n\n…(truncated)` : indexed.text,
46 };
47 }
48 return { found: false, url, message: `No docs page found for "${url}". Use search_docs to find a valid URL.` };
49 },
50 });