@@ -3,7 +3,10 @@ import type {
33 MicrosoftExcelReadResponse ,
44 MicrosoftExcelToolParams ,
55} from '@/tools/microsoft_excel/types'
6- import { trimTrailingEmptyRowsAndColumns } from '@/tools/microsoft_excel/utils'
6+ import {
7+ getSpreadsheetWebUrl ,
8+ trimTrailingEmptyRowsAndColumns ,
9+ } from '@/tools/microsoft_excel/utils'
710import type { ToolConfig } from '@/tools/types'
811
912export const readTool : ToolConfig < MicrosoftExcelToolParams , MicrosoftExcelReadResponse > = {
@@ -126,10 +129,13 @@ export const readTool: ToolConfig<MicrosoftExcelToolParams, MicrosoftExcelReadRe
126129
127130 const values = trimTrailingEmptyRowsAndColumns ( rawValues )
128131
132+ // Fetch the browser-accessible web URL
133+ const webUrl = await getSpreadsheetWebUrl ( spreadsheetIdFromUrl , accessToken )
134+
129135 const metadata = {
130136 spreadsheetId : spreadsheetIdFromUrl ,
131137 properties : { } ,
132- spreadsheetUrl : `https://graph.microsoft.com/v1.0/me/drive/items/ ${ spreadsheetIdFromUrl } ` ,
138+ spreadsheetUrl : webUrl ,
133139 }
134140
135141 const result : MicrosoftExcelReadResponse = {
@@ -155,10 +161,17 @@ export const readTool: ToolConfig<MicrosoftExcelToolParams, MicrosoftExcelReadRe
155161 const urlParts = response . url . split ( '/drive/items/' )
156162 const spreadsheetId = urlParts [ 1 ] ?. split ( '/' ) [ 0 ] || ''
157163
164+ // Fetch the browser-accessible web URL
165+ const accessToken = params ?. accessToken
166+ if ( ! accessToken ) {
167+ throw new Error ( 'Access token is required' )
168+ }
169+ const webUrl = await getSpreadsheetWebUrl ( spreadsheetId , accessToken )
170+
158171 const metadata = {
159172 spreadsheetId,
160173 properties : { } ,
161- spreadsheetUrl : `https://graph.microsoft.com/v1.0/me/drive/items/ ${ spreadsheetId } ` ,
174+ spreadsheetUrl : webUrl ,
162175 }
163176
164177 const address : string = data . address || data . addressLocal || data . range || ''
0 commit comments