diff --git a/tools/view-file.ts b/tools/view-file.ts index 8a01d0af..8e67e35b 100644 --- a/tools/view-file.ts +++ b/tools/view-file.ts @@ -24,23 +24,32 @@ export const viewFileTool = (context: ToolContext): CoreTool => { - if (!context.repo || !context.user) { + const repoOwner = owner || context.repo?.owner; + const repoName = repo || context.repo?.name; + const repoBranch = branch || context.repo?.branch || 'main'; + + if (!repoOwner || !repoName) { return { success: false, - error: "Missing repository or user information", - summary: "Failed to view file due to missing context", - details: "The tool context is missing required repository or user information." + error: "Missing repository information", + summary: "Failed to view file due to missing repository information", + details: "The repository owner or name is missing. Please provide both in the request or ensure they are set in the context." }; } - const repoOwner = owner || context.repo.owner; - const repoName = repo || context.repo.name; - const repoBranch = branch || context.repo.branch || 'main'; + if (!context.gitHubToken) { + return { + success: false, + error: "Missing GitHub token", + summary: "Failed to view file due to missing GitHub token", + details: "The GitHub token is missing. Please ensure it is provided in the context." + }; + } try { const content = await githubReadFile({ path, - token: context.gitHubToken ?? process.env.GITHUB_TOKEN ?? '', // TODO + token: context.gitHubToken, repoOwner, repoName, branch: repoBranch