Feature/Add teams, gmail, outlook tools (#4577)

* add teams, gmail, outlook tools

* update docs link

* update credentials for oauth2

* add jira tool

* add google drive, google calendar, google sheets tools, powerpoint, excel, word doc loader

* update jira logo

* Refactor Gmail and Outlook tools to remove maxOutputLength parameter and enhance request handling. Update response formatting to include parameters in the output. Adjust Google Drive tools to simplify success messages by removing unnecessary parameter details.
This commit is contained in:
Henry Heng
2025-06-06 19:52:04 +01:00
committed by GitHub
parent 6dcb65cedb
commit 30c4180d97
62 changed files with 16832 additions and 144 deletions
+65
View File
@@ -1215,3 +1215,68 @@ export const handleDocumentLoaderDocuments = async (loader: DocumentLoader, text
return docs
}
/**
* Check if OAuth2 token is expired and refresh if needed
* @param {string} credentialId
* @param {ICommonObject} credentialData
* @param {ICommonObject} options
* @param {number} bufferTimeMs - Buffer time in milliseconds before expiry (default: 5 minutes)
* @returns {Promise<ICommonObject>}
*/
export const refreshOAuth2Token = async (
credentialId: string,
credentialData: ICommonObject,
options: ICommonObject,
bufferTimeMs: number = 5 * 60 * 1000
): Promise<ICommonObject> => {
// Check if token is expired and refresh if needed
if (credentialData.expires_at) {
const expiryTime = new Date(credentialData.expires_at)
const currentTime = new Date()
if (currentTime.getTime() > expiryTime.getTime() - bufferTimeMs) {
if (!credentialData.refresh_token) {
throw new Error('Access token is expired and no refresh token is available. Please re-authorize the credential.')
}
try {
// Import fetch dynamically to avoid issues
const fetch = (await import('node-fetch')).default
// Call the refresh API endpoint
const refreshResponse = await fetch(
`${options.baseURL || 'http://localhost:3000'}/api/v1/oauth2-credential/refresh/${credentialId}`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
}
}
)
if (!refreshResponse.ok) {
const errorData = await refreshResponse.text()
throw new Error(`Failed to refresh token: ${refreshResponse.status} ${refreshResponse.statusText} - ${errorData}`)
}
await refreshResponse.json()
// Get the updated credential data
const updatedCredentialData = await getCredentialData(credentialId, options)
return updatedCredentialData
} catch (error) {
console.error('Failed to refresh access token:', error)
throw new Error(
`Failed to refresh access token: ${
error instanceof Error ? error.message : 'Unknown error'
}. Please re-authorize the credential.`
)
}
}
}
// Token is not expired, return original data
return credentialData
}