diff --git a/sim/app/tools/github/commit.ts b/sim/app/tools/github/commit.ts index 5a2828799d..d55cdcb837 100644 --- a/sim/app/tools/github/commit.ts +++ b/sim/app/tools/github/commit.ts @@ -46,7 +46,7 @@ export const latestCommitTool: ToolConfig { + transformResponse: async (response, params) => { if (!response.ok) { throw new Error(`GitHub API error: ${response.statusText}`) } @@ -56,6 +56,48 @@ export const latestCommitTool: ToolConfig 0) { + for (const file of files) { + const fileDetail = { + filename: file.filename, + additions: file.additions, + deletions: file.deletions, + changes: file.changes, + status: file.status, + raw_url: file.raw_url, + blob_url: file.blob_url, + patch: file.patch, + content: undefined as string | undefined, + } + + // Only try to fetch content for files that are not too large and not deleted + if (file.status !== 'removed' && file.raw_url) { + try { + // Fetch the raw file content + const contentResponse = await fetch(file.raw_url, { + headers: { + Authorization: `Bearer ${params?.apiKey}`, + 'X-GitHub-Api-Version': '2022-11-28', + }, + }) + + if (contentResponse.ok) { + fileDetail.content = await contentResponse.text() + } + } catch (error) { + console.error(`Failed to fetch content for ${file.filename}:`, error) + } + } + + fileDetailsWithContent.push(fileDetail) + } + } + return { success: true, output: { @@ -81,6 +123,7 @@ export const latestCommitTool: ToolConfig 0 ? fileDetailsWithContent : undefined, }, }, } diff --git a/sim/app/tools/github/types.ts b/sim/app/tools/github/types.ts index 8ba0747cca..25e2d672ab 100644 --- a/sim/app/tools/github/types.ts +++ b/sim/app/tools/github/types.ts @@ -97,6 +97,17 @@ interface CommitMetadata { deletions: number total: number } + files?: Array<{ + filename: string + additions: number + deletions: number + changes: number + status: string + raw_url: string + blob_url: string + patch?: string + content?: string + }> } interface RepoMetadata {