fix: various UI and server improvements
This commit is contained in:
@@ -24,13 +24,14 @@ const classifyReadError = (error: unknown): ContextFileOpenFailureReason => {
|
||||
return 'unreadable';
|
||||
};
|
||||
|
||||
const readFileContent = async (files: FilesAPI, path: string): Promise<string> => {
|
||||
const readFileContent = async (files: FilesAPI, path: string, directory?: string): Promise<string> => {
|
||||
if (files.readFile) {
|
||||
const result = await files.readFile(path);
|
||||
return result.content ?? '';
|
||||
}
|
||||
|
||||
const response = await fetch(`/api/fs/read?path=${encodeURIComponent(path)}`);
|
||||
const headers = directory ? { 'x-opencode-directory': directory } : undefined;
|
||||
const response = await fetch(`/api/fs/read?path=${encodeURIComponent(path)}`, { headers });
|
||||
if (!response.ok) {
|
||||
const errorPayload = await response.json().catch(() => ({ error: response.statusText }));
|
||||
throw new Error((errorPayload as { error?: string }).error || 'Failed to read file');
|
||||
@@ -39,9 +40,9 @@ const readFileContent = async (files: FilesAPI, path: string): Promise<string> =
|
||||
return response.text();
|
||||
};
|
||||
|
||||
export const validateContextFileOpen = async (files: FilesAPI, path: string): Promise<ContextFileOpenValidationResult> => {
|
||||
export const validateContextFileOpen = async (files: FilesAPI, path: string, directory?: string): Promise<ContextFileOpenValidationResult> => {
|
||||
try {
|
||||
const content = await readFileContent(files, path);
|
||||
const content = await readFileContent(files, path, directory);
|
||||
const lineCount = countLinesWithLimit(content, MAX_OPEN_FILE_LINES);
|
||||
if (lineCount > MAX_OPEN_FILE_LINES) {
|
||||
return { ok: false, reason: 'too-large' };
|
||||
|
||||
Reference in New Issue
Block a user