Something went wrong. Try again.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647import { Value } from '@sinclair/typebox/value';import type { ToolResult } from '@/contracts/tool';import type { SymbolInfo } from '@/contracts/code-intelligence';
const TRUNCATION_MARKER = '[truncated: additional symbols omitted]';
export function errorResult(error: unknown): ToolResult { const message = error instanceof Error ? error.message : String(error); return { content: { kind: 'error', message }, isError: true };}
export function validate( schema: Parameters<typeof Value.Check>[0], input: unknown,): ToolResult | undefined { return Value.Check(schema, input) ? undefined : { content: { kind: 'error', message: 'Invalid input' }, isError: true };}
export function location(symbol: SymbolInfo): string { const [start, end] = symbol.range ?? [0, 0]; return `offset=${start + 1} limit=${end - start + 1}`;}
export function formatSymbol(symbol: SymbolInfo): string { const signature = symbol.signature ? ` ${symbol.signature}` : ''; return `${symbol.kind} ${symbol.name} ${location(symbol)}${signature}`.slice(0, 500);}
export function capSymbolOutput( lines: string[], maxBytes: number, alreadyTruncated = false,): string { const output: string[] = []; let bytes = 0; for (const line of lines) { const nextBytes = Buffer.byteLength(line) + (output.length > 0 ? 1 : 0); if (bytes + nextBytes + Buffer.byteLength(TRUNCATION_MARKER) + 1 > maxBytes) break; output.push(line); bytes += nextBytes; } if (alreadyTruncated || output.length < lines.length) output.push(TRUNCATION_MARKER); return output.join('\n');}