fix ask-ai bot hitting tool call limits (#7162)
Signed-off-by: The-Best-Codes <106822363+The-Best-Codes@users.noreply.github.com>
This commit is contained in:
@@ -99,10 +99,11 @@ function generateWebUrl(filePath: string): string {
|
||||
return `${baseUrl}/${urlPath}`;
|
||||
}
|
||||
|
||||
function getPreview(content: string, maxLength: number = 200): string {
|
||||
function getPreview(content: string, maxLength: number = 1000): string {
|
||||
const withoutFrontmatter = content.replace(/^---[\s\S]*?---\n/, "");
|
||||
const lines = withoutFrontmatter.split("\n");
|
||||
let preview = "";
|
||||
const contentLines: string[] = [];
|
||||
let currentLength = 0;
|
||||
|
||||
for (const line of lines) {
|
||||
const cleanLine = line
|
||||
@@ -116,19 +117,23 @@ function getPreview(content: string, maxLength: number = 200): string {
|
||||
!cleanLine.startsWith("import") &&
|
||||
!cleanLine.startsWith("export")
|
||||
) {
|
||||
preview = cleanLine;
|
||||
break;
|
||||
if (currentLength + cleanLine.length > maxLength) {
|
||||
const remaining = maxLength - currentLength;
|
||||
if (remaining > 0) {
|
||||
contentLines.push(cleanLine.substring(0, remaining) + "...");
|
||||
}
|
||||
break;
|
||||
}
|
||||
contentLines.push(cleanLine);
|
||||
currentLength += cleanLine.length + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (preview.length > maxLength) {
|
||||
preview = preview.substring(0, maxLength) + "...";
|
||||
}
|
||||
|
||||
const preview = contentLines.join("\n");
|
||||
return preview || "(No preview available)";
|
||||
}
|
||||
|
||||
export function searchDocs(query: string, limit: number = 5): SearchResult[] {
|
||||
export function searchDocs(query: string, limit: number = 15): SearchResult[] {
|
||||
const search = initializeSearch();
|
||||
const results = search.search(query).slice(0, limit);
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ function findDocFile(partialPath: string): string | null {
|
||||
function getDocChunk(
|
||||
filePath: string,
|
||||
startLine: number = 0,
|
||||
lineCount: number = 100,
|
||||
lineCount: number = 1500,
|
||||
): { fileName: string; content: string; webUrl: string } {
|
||||
const docsDir = path.resolve(getDocsDir());
|
||||
const fullPath = path.join(docsDir, filePath);
|
||||
@@ -94,7 +94,7 @@ function getDocChunk(
|
||||
export function viewDocs(
|
||||
filePaths: string | string[],
|
||||
startLine: number = 0,
|
||||
lineCount: number = 100,
|
||||
lineCount: number = 1500,
|
||||
): string {
|
||||
const paths = Array.isArray(filePaths) ? filePaths : [filePaths];
|
||||
|
||||
|
||||
@@ -16,9 +16,9 @@ export const aiTools = {
|
||||
limit: z
|
||||
.number()
|
||||
.optional()
|
||||
.describe("Maximum number of results to return (default 5)"),
|
||||
.describe("Maximum number of results to return (default 15)"),
|
||||
}),
|
||||
execute: async ({ query, limit = 5 }) => {
|
||||
execute: async ({ query, limit = 15 }) => {
|
||||
const results = searchDocs(query, limit);
|
||||
logger.verbose(
|
||||
`Searched docs for "${query}", found ${results.length} results`,
|
||||
@@ -42,7 +42,7 @@ export const aiTools = {
|
||||
filePaths: z
|
||||
.union([z.string(), z.array(z.string())])
|
||||
.describe(
|
||||
"Path or array of paths to documentation files (example: 'quickstart.md' or ['guides/managing-projects.md', 'api/overview.md'])",
|
||||
"Path or array of paths to documentation files (example: 'quickstart.md' or ['guides/managing-projects.md', 'mcp/asana-mcp.md'])",
|
||||
),
|
||||
startLine: z
|
||||
.number()
|
||||
@@ -51,9 +51,9 @@ export const aiTools = {
|
||||
lineCount: z
|
||||
.number()
|
||||
.optional()
|
||||
.describe("Number of lines to show (default 100)"),
|
||||
.describe("Number of lines to show (default 1500)"),
|
||||
}),
|
||||
execute: async ({ filePaths, startLine = 0, lineCount = 100 }) => {
|
||||
execute: async ({ filePaths, startLine = 0, lineCount = 1500 }) => {
|
||||
try {
|
||||
const result = viewDocs(filePaths, startLine, lineCount);
|
||||
const count = Array.isArray(filePaths) ? filePaths.length : 1;
|
||||
|
||||
Reference in New Issue
Block a user