mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-29 05:01:10 +03:00
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:
@@ -0,0 +1,424 @@
|
||||
import { convertMultiOptionsToStringArray, getCredentialData, getCredentialParam, refreshOAuth2Token } from '../../../src/utils'
|
||||
import { createGoogleSheetsTools } from './core'
|
||||
import type { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface'
|
||||
|
||||
class GoogleSheets_Tools implements INode {
|
||||
label: string
|
||||
name: string
|
||||
version: number
|
||||
type: string
|
||||
icon: string
|
||||
category: string
|
||||
description: string
|
||||
baseClasses: string[]
|
||||
credential: INodeParams
|
||||
inputs: INodeParams[]
|
||||
|
||||
constructor() {
|
||||
this.label = 'Google Sheets'
|
||||
this.name = 'googleSheetsTool'
|
||||
this.version = 1.0
|
||||
this.type = 'GoogleSheets'
|
||||
this.icon = 'google-sheets.svg'
|
||||
this.category = 'Tools'
|
||||
this.description = 'Perform Google Sheets operations such as managing spreadsheets, reading and writing values'
|
||||
this.baseClasses = ['Tool']
|
||||
this.credential = {
|
||||
label: 'Connect Credential',
|
||||
name: 'credential',
|
||||
type: 'credential',
|
||||
credentialNames: ['googleSheetsOAuth2']
|
||||
}
|
||||
this.inputs = [
|
||||
{
|
||||
label: 'Type',
|
||||
name: 'sheetsType',
|
||||
type: 'options',
|
||||
description: 'Type of Google Sheets operation',
|
||||
options: [
|
||||
{
|
||||
label: 'Spreadsheet',
|
||||
name: 'spreadsheet'
|
||||
},
|
||||
{
|
||||
label: 'Values',
|
||||
name: 'values'
|
||||
}
|
||||
]
|
||||
},
|
||||
// Spreadsheet Actions
|
||||
{
|
||||
label: 'Spreadsheet Actions',
|
||||
name: 'spreadsheetActions',
|
||||
type: 'multiOptions',
|
||||
description: 'Actions to perform on spreadsheets',
|
||||
options: [
|
||||
{
|
||||
label: 'Create Spreadsheet',
|
||||
name: 'createSpreadsheet'
|
||||
},
|
||||
{
|
||||
label: 'Get Spreadsheet',
|
||||
name: 'getSpreadsheet'
|
||||
},
|
||||
{
|
||||
label: 'Update Spreadsheet',
|
||||
name: 'updateSpreadsheet'
|
||||
}
|
||||
],
|
||||
show: {
|
||||
sheetsType: ['spreadsheet']
|
||||
}
|
||||
},
|
||||
// Values Actions
|
||||
{
|
||||
label: 'Values Actions',
|
||||
name: 'valuesActions',
|
||||
type: 'multiOptions',
|
||||
description: 'Actions to perform on sheet values',
|
||||
options: [
|
||||
{
|
||||
label: 'Get Values',
|
||||
name: 'getValues'
|
||||
},
|
||||
{
|
||||
label: 'Update Values',
|
||||
name: 'updateValues'
|
||||
},
|
||||
{
|
||||
label: 'Append Values',
|
||||
name: 'appendValues'
|
||||
},
|
||||
{
|
||||
label: 'Clear Values',
|
||||
name: 'clearValues'
|
||||
},
|
||||
{
|
||||
label: 'Batch Get Values',
|
||||
name: 'batchGetValues'
|
||||
},
|
||||
{
|
||||
label: 'Batch Update Values',
|
||||
name: 'batchUpdateValues'
|
||||
},
|
||||
{
|
||||
label: 'Batch Clear Values',
|
||||
name: 'batchClearValues'
|
||||
}
|
||||
],
|
||||
show: {
|
||||
sheetsType: ['values']
|
||||
}
|
||||
},
|
||||
// Spreadsheet Parameters
|
||||
{
|
||||
label: 'Spreadsheet ID',
|
||||
name: 'spreadsheetId',
|
||||
type: 'string',
|
||||
description: 'The ID of the spreadsheet',
|
||||
show: {
|
||||
sheetsType: ['spreadsheet', 'values']
|
||||
},
|
||||
additionalParams: true,
|
||||
optional: true
|
||||
},
|
||||
{
|
||||
label: 'Title',
|
||||
name: 'title',
|
||||
type: 'string',
|
||||
description: 'The title of the spreadsheet',
|
||||
show: {
|
||||
spreadsheetActions: ['createSpreadsheet', 'updateSpreadsheet']
|
||||
},
|
||||
additionalParams: true,
|
||||
optional: true
|
||||
},
|
||||
{
|
||||
label: 'Sheet Count',
|
||||
name: 'sheetCount',
|
||||
type: 'number',
|
||||
description: 'Number of sheets to create',
|
||||
default: 1,
|
||||
show: {
|
||||
spreadsheetActions: ['createSpreadsheet']
|
||||
},
|
||||
additionalParams: true,
|
||||
optional: true
|
||||
},
|
||||
// Values Parameters
|
||||
{
|
||||
label: 'Range',
|
||||
name: 'range',
|
||||
type: 'string',
|
||||
description: 'The range to read/write (e.g., A1:B2, Sheet1!A1:C10)',
|
||||
show: {
|
||||
valuesActions: ['getValues', 'updateValues', 'clearValues']
|
||||
},
|
||||
additionalParams: true,
|
||||
optional: true
|
||||
},
|
||||
{
|
||||
label: 'Ranges',
|
||||
name: 'ranges',
|
||||
type: 'string',
|
||||
description: 'Comma-separated list of ranges for batch operations',
|
||||
show: {
|
||||
valuesActions: ['batchGetValues', 'batchClearValues']
|
||||
},
|
||||
additionalParams: true,
|
||||
optional: true
|
||||
},
|
||||
{
|
||||
label: 'Values',
|
||||
name: 'values',
|
||||
type: 'string',
|
||||
description: 'JSON array of values to write (e.g., [["A1", "B1"], ["A2", "B2"]])',
|
||||
show: {
|
||||
valuesActions: ['updateValues', 'appendValues', 'batchUpdateValues']
|
||||
},
|
||||
additionalParams: true,
|
||||
optional: true
|
||||
},
|
||||
{
|
||||
label: 'Value Input Option',
|
||||
name: 'valueInputOption',
|
||||
type: 'options',
|
||||
description: 'How input data should be interpreted',
|
||||
options: [
|
||||
{
|
||||
label: 'Raw',
|
||||
name: 'RAW'
|
||||
},
|
||||
{
|
||||
label: 'User Entered',
|
||||
name: 'USER_ENTERED'
|
||||
}
|
||||
],
|
||||
default: 'USER_ENTERED',
|
||||
show: {
|
||||
valuesActions: ['updateValues', 'appendValues', 'batchUpdateValues']
|
||||
},
|
||||
additionalParams: true,
|
||||
optional: true
|
||||
},
|
||||
{
|
||||
label: 'Value Render Option',
|
||||
name: 'valueRenderOption',
|
||||
type: 'options',
|
||||
description: 'How values should be represented in the output',
|
||||
options: [
|
||||
{
|
||||
label: 'Formatted Value',
|
||||
name: 'FORMATTED_VALUE'
|
||||
},
|
||||
{
|
||||
label: 'Unformatted Value',
|
||||
name: 'UNFORMATTED_VALUE'
|
||||
},
|
||||
{
|
||||
label: 'Formula',
|
||||
name: 'FORMULA'
|
||||
}
|
||||
],
|
||||
default: 'FORMATTED_VALUE',
|
||||
show: {
|
||||
valuesActions: ['getValues', 'batchGetValues']
|
||||
},
|
||||
additionalParams: true,
|
||||
optional: true
|
||||
},
|
||||
{
|
||||
label: 'Date Time Render Option',
|
||||
name: 'dateTimeRenderOption',
|
||||
type: 'options',
|
||||
description: 'How dates, times, and durations should be represented',
|
||||
options: [
|
||||
{
|
||||
label: 'Serial Number',
|
||||
name: 'SERIAL_NUMBER'
|
||||
},
|
||||
{
|
||||
label: 'Formatted String',
|
||||
name: 'FORMATTED_STRING'
|
||||
}
|
||||
],
|
||||
default: 'FORMATTED_STRING',
|
||||
show: {
|
||||
valuesActions: ['getValues', 'batchGetValues']
|
||||
},
|
||||
additionalParams: true,
|
||||
optional: true
|
||||
},
|
||||
{
|
||||
label: 'Insert Data Option',
|
||||
name: 'insertDataOption',
|
||||
type: 'options',
|
||||
description: 'How data should be inserted',
|
||||
options: [
|
||||
{
|
||||
label: 'Overwrite',
|
||||
name: 'OVERWRITE'
|
||||
},
|
||||
{
|
||||
label: 'Insert Rows',
|
||||
name: 'INSERT_ROWS'
|
||||
}
|
||||
],
|
||||
default: 'OVERWRITE',
|
||||
show: {
|
||||
valuesActions: ['appendValues']
|
||||
},
|
||||
additionalParams: true,
|
||||
optional: true
|
||||
},
|
||||
{
|
||||
label: 'Include Grid Data',
|
||||
name: 'includeGridData',
|
||||
type: 'boolean',
|
||||
description: 'True if grid data should be returned',
|
||||
default: false,
|
||||
show: {
|
||||
spreadsheetActions: ['getSpreadsheet']
|
||||
},
|
||||
additionalParams: true,
|
||||
optional: true
|
||||
},
|
||||
{
|
||||
label: 'Major Dimension',
|
||||
name: 'majorDimension',
|
||||
type: 'options',
|
||||
description: 'The major dimension that results should use',
|
||||
options: [
|
||||
{
|
||||
label: 'Rows',
|
||||
name: 'ROWS'
|
||||
},
|
||||
{
|
||||
label: 'Columns',
|
||||
name: 'COLUMNS'
|
||||
}
|
||||
],
|
||||
default: 'ROWS',
|
||||
show: {
|
||||
valuesActions: ['getValues', 'updateValues', 'appendValues', 'batchGetValues', 'batchUpdateValues']
|
||||
},
|
||||
additionalParams: true,
|
||||
optional: true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
|
||||
const sheetsType = nodeData.inputs?.sheetsType as string
|
||||
|
||||
let credentialData = await getCredentialData(nodeData.credential ?? '', options)
|
||||
credentialData = await refreshOAuth2Token(nodeData.credential ?? '', credentialData, options)
|
||||
const accessToken = getCredentialParam('access_token', credentialData, nodeData)
|
||||
|
||||
if (!accessToken) {
|
||||
throw new Error('No access token found in credential')
|
||||
}
|
||||
|
||||
// Get all actions based on type
|
||||
let actions: string[] = []
|
||||
|
||||
if (sheetsType === 'spreadsheet') {
|
||||
actions = convertMultiOptionsToStringArray(nodeData.inputs?.spreadsheetActions)
|
||||
} else if (sheetsType === 'values') {
|
||||
actions = convertMultiOptionsToStringArray(nodeData.inputs?.valuesActions)
|
||||
}
|
||||
|
||||
// Create default params object based on inputs
|
||||
const defaultParams: any = {}
|
||||
|
||||
// Spreadsheet-specific default params
|
||||
if (sheetsType === 'spreadsheet') {
|
||||
actions.forEach((action) => {
|
||||
const params: any = {}
|
||||
|
||||
// Common spreadsheet parameters
|
||||
if (nodeData.inputs?.spreadsheetId) params.spreadsheetId = nodeData.inputs.spreadsheetId
|
||||
|
||||
if (action === 'createSpreadsheet') {
|
||||
if (nodeData.inputs?.title) params.title = nodeData.inputs.title
|
||||
if (nodeData.inputs?.sheetCount) params.sheetCount = nodeData.inputs.sheetCount
|
||||
}
|
||||
|
||||
if (action === 'getSpreadsheet') {
|
||||
if (nodeData.inputs?.ranges) params.ranges = nodeData.inputs.ranges
|
||||
if (nodeData.inputs?.includeGridData !== undefined) params.includeGridData = nodeData.inputs.includeGridData
|
||||
}
|
||||
|
||||
if (action === 'updateSpreadsheet') {
|
||||
if (nodeData.inputs?.title) params.title = nodeData.inputs.title
|
||||
}
|
||||
|
||||
defaultParams[action] = params
|
||||
})
|
||||
}
|
||||
|
||||
// Values-specific default params
|
||||
if (sheetsType === 'values') {
|
||||
actions.forEach((action) => {
|
||||
const params: any = {}
|
||||
|
||||
// Common values parameters
|
||||
if (nodeData.inputs?.spreadsheetId) params.spreadsheetId = nodeData.inputs.spreadsheetId
|
||||
|
||||
if (action === 'getValues') {
|
||||
if (nodeData.inputs?.range) params.range = nodeData.inputs.range
|
||||
if (nodeData.inputs?.valueRenderOption) params.valueRenderOption = nodeData.inputs.valueRenderOption
|
||||
if (nodeData.inputs?.dateTimeRenderOption) params.dateTimeRenderOption = nodeData.inputs.dateTimeRenderOption
|
||||
if (nodeData.inputs?.majorDimension) params.majorDimension = nodeData.inputs.majorDimension
|
||||
}
|
||||
|
||||
if (action === 'updateValues') {
|
||||
if (nodeData.inputs?.range) params.range = nodeData.inputs.range
|
||||
if (nodeData.inputs?.values) params.values = nodeData.inputs.values
|
||||
if (nodeData.inputs?.valueInputOption) params.valueInputOption = nodeData.inputs.valueInputOption
|
||||
if (nodeData.inputs?.majorDimension) params.majorDimension = nodeData.inputs.majorDimension
|
||||
}
|
||||
|
||||
if (action === 'appendValues') {
|
||||
if (nodeData.inputs?.range) params.range = nodeData.inputs.range
|
||||
if (nodeData.inputs?.values) params.values = nodeData.inputs.values
|
||||
if (nodeData.inputs?.valueInputOption) params.valueInputOption = nodeData.inputs.valueInputOption
|
||||
if (nodeData.inputs?.insertDataOption) params.insertDataOption = nodeData.inputs.insertDataOption
|
||||
if (nodeData.inputs?.majorDimension) params.majorDimension = nodeData.inputs.majorDimension
|
||||
}
|
||||
|
||||
if (action === 'clearValues') {
|
||||
if (nodeData.inputs?.range) params.range = nodeData.inputs.range
|
||||
}
|
||||
|
||||
if (action === 'batchGetValues') {
|
||||
if (nodeData.inputs?.ranges) params.ranges = nodeData.inputs.ranges
|
||||
if (nodeData.inputs?.valueRenderOption) params.valueRenderOption = nodeData.inputs.valueRenderOption
|
||||
if (nodeData.inputs?.dateTimeRenderOption) params.dateTimeRenderOption = nodeData.inputs.dateTimeRenderOption
|
||||
if (nodeData.inputs?.majorDimension) params.majorDimension = nodeData.inputs.majorDimension
|
||||
}
|
||||
|
||||
if (action === 'batchUpdateValues') {
|
||||
if (nodeData.inputs?.values) params.values = nodeData.inputs.values
|
||||
if (nodeData.inputs?.valueInputOption) params.valueInputOption = nodeData.inputs.valueInputOption
|
||||
}
|
||||
|
||||
if (action === 'batchClearValues') {
|
||||
if (nodeData.inputs?.ranges) params.ranges = nodeData.inputs.ranges
|
||||
}
|
||||
|
||||
defaultParams[action] = params
|
||||
})
|
||||
}
|
||||
|
||||
const tools = createGoogleSheetsTools({
|
||||
accessToken,
|
||||
actions,
|
||||
defaultParams
|
||||
})
|
||||
|
||||
return tools
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { nodeClass: GoogleSheets_Tools }
|
||||
@@ -0,0 +1,631 @@
|
||||
import { z } from 'zod'
|
||||
import fetch from 'node-fetch'
|
||||
import { DynamicStructuredTool } from '../OpenAPIToolkit/core'
|
||||
import { TOOL_ARGS_PREFIX } from '../../../src/agents'
|
||||
|
||||
export const desc = `Use this when you want to access Google Sheets API for managing spreadsheets and values`
|
||||
|
||||
export interface Headers {
|
||||
[key: string]: string
|
||||
}
|
||||
|
||||
export interface Body {
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
export interface RequestParameters {
|
||||
headers?: Headers
|
||||
body?: Body
|
||||
url?: string
|
||||
description?: string
|
||||
name?: string
|
||||
actions?: string[]
|
||||
accessToken?: string
|
||||
defaultParams?: any
|
||||
}
|
||||
|
||||
// Define schemas for different Google Sheets operations
|
||||
|
||||
// Spreadsheet Schemas
|
||||
const CreateSpreadsheetSchema = z.object({
|
||||
title: z.string().describe('The title of the spreadsheet'),
|
||||
sheetCount: z.number().optional().default(1).describe('Number of sheets to create'),
|
||||
locale: z.string().optional().describe('The locale of the spreadsheet (e.g., en_US)'),
|
||||
timeZone: z.string().optional().describe('The time zone of the spreadsheet (e.g., America/New_York)')
|
||||
})
|
||||
|
||||
const GetSpreadsheetSchema = z.object({
|
||||
spreadsheetId: z.string().describe('The ID of the spreadsheet to retrieve'),
|
||||
ranges: z.string().optional().describe('Comma-separated list of ranges to retrieve'),
|
||||
includeGridData: z.boolean().optional().default(false).describe('True if grid data should be returned')
|
||||
})
|
||||
|
||||
const UpdateSpreadsheetSchema = z.object({
|
||||
spreadsheetId: z.string().describe('The ID of the spreadsheet to update'),
|
||||
title: z.string().optional().describe('New title for the spreadsheet'),
|
||||
locale: z.string().optional().describe('New locale for the spreadsheet'),
|
||||
timeZone: z.string().optional().describe('New time zone for the spreadsheet')
|
||||
})
|
||||
|
||||
// Values Schemas
|
||||
const GetValuesSchema = z.object({
|
||||
spreadsheetId: z.string().describe('The ID of the spreadsheet'),
|
||||
range: z.string().describe('The A1 notation of the range to retrieve values from'),
|
||||
valueRenderOption: z
|
||||
.enum(['FORMATTED_VALUE', 'UNFORMATTED_VALUE', 'FORMULA'])
|
||||
.optional()
|
||||
.default('FORMATTED_VALUE')
|
||||
.describe('How values should be represented'),
|
||||
dateTimeRenderOption: z
|
||||
.enum(['SERIAL_NUMBER', 'FORMATTED_STRING'])
|
||||
.optional()
|
||||
.default('FORMATTED_STRING')
|
||||
.describe('How dates should be represented'),
|
||||
majorDimension: z.enum(['ROWS', 'COLUMNS']).optional().default('ROWS').describe('The major dimension that results should use')
|
||||
})
|
||||
|
||||
const UpdateValuesSchema = z.object({
|
||||
spreadsheetId: z.string().describe('The ID of the spreadsheet'),
|
||||
range: z.string().describe('The A1 notation of the range to update'),
|
||||
values: z.string().describe('JSON array of values to write (e.g., [["A1", "B1"], ["A2", "B2"]])'),
|
||||
valueInputOption: z.enum(['RAW', 'USER_ENTERED']).optional().default('USER_ENTERED').describe('How input data should be interpreted'),
|
||||
majorDimension: z.enum(['ROWS', 'COLUMNS']).optional().default('ROWS').describe('The major dimension of the values')
|
||||
})
|
||||
|
||||
const AppendValuesSchema = z.object({
|
||||
spreadsheetId: z.string().describe('The ID of the spreadsheet'),
|
||||
range: z.string().describe('The A1 notation of the range to append to'),
|
||||
values: z.string().describe('JSON array of values to append'),
|
||||
valueInputOption: z.enum(['RAW', 'USER_ENTERED']).optional().default('USER_ENTERED').describe('How input data should be interpreted'),
|
||||
insertDataOption: z.enum(['OVERWRITE', 'INSERT_ROWS']).optional().default('OVERWRITE').describe('How data should be inserted'),
|
||||
majorDimension: z.enum(['ROWS', 'COLUMNS']).optional().default('ROWS').describe('The major dimension of the values')
|
||||
})
|
||||
|
||||
const ClearValuesSchema = z.object({
|
||||
spreadsheetId: z.string().describe('The ID of the spreadsheet'),
|
||||
range: z.string().describe('The A1 notation of the range to clear')
|
||||
})
|
||||
|
||||
const BatchGetValuesSchema = z.object({
|
||||
spreadsheetId: z.string().describe('The ID of the spreadsheet'),
|
||||
ranges: z.string().describe('Comma-separated list of ranges to retrieve'),
|
||||
valueRenderOption: z
|
||||
.enum(['FORMATTED_VALUE', 'UNFORMATTED_VALUE', 'FORMULA'])
|
||||
.optional()
|
||||
.default('FORMATTED_VALUE')
|
||||
.describe('How values should be represented'),
|
||||
dateTimeRenderOption: z
|
||||
.enum(['SERIAL_NUMBER', 'FORMATTED_STRING'])
|
||||
.optional()
|
||||
.default('FORMATTED_STRING')
|
||||
.describe('How dates should be represented'),
|
||||
majorDimension: z.enum(['ROWS', 'COLUMNS']).optional().default('ROWS').describe('The major dimension that results should use')
|
||||
})
|
||||
|
||||
const BatchUpdateValuesSchema = z.object({
|
||||
spreadsheetId: z.string().describe('The ID of the spreadsheet'),
|
||||
valueInputOption: z.enum(['RAW', 'USER_ENTERED']).optional().default('USER_ENTERED').describe('How input data should be interpreted'),
|
||||
values: z
|
||||
.string()
|
||||
.describe('JSON array of value ranges to update (e.g., [{"range": "A1:B2", "values": [["A1", "B1"], ["A2", "B2"]]}])'),
|
||||
includeValuesInResponse: z.boolean().optional().default(false).describe('Whether to return the updated values in the response')
|
||||
})
|
||||
|
||||
const BatchClearValuesSchema = z.object({
|
||||
spreadsheetId: z.string().describe('The ID of the spreadsheet'),
|
||||
ranges: z.string().describe('Comma-separated list of ranges to clear')
|
||||
})
|
||||
|
||||
class BaseGoogleSheetsTool extends DynamicStructuredTool {
|
||||
protected accessToken: string = ''
|
||||
|
||||
constructor(args: any) {
|
||||
super(args)
|
||||
this.accessToken = args.accessToken ?? ''
|
||||
}
|
||||
|
||||
async makeGoogleSheetsRequest({
|
||||
endpoint,
|
||||
method = 'GET',
|
||||
body,
|
||||
params
|
||||
}: {
|
||||
endpoint: string
|
||||
method?: string
|
||||
body?: any
|
||||
params?: any
|
||||
}): Promise<string> {
|
||||
const url = `https://sheets.googleapis.com/v4/${endpoint}`
|
||||
|
||||
const headers = {
|
||||
Authorization: `Bearer ${this.accessToken}`,
|
||||
'Content-Type': 'application/json',
|
||||
Accept: 'application/json',
|
||||
...this.headers
|
||||
}
|
||||
|
||||
const response = await fetch(url, {
|
||||
method,
|
||||
headers,
|
||||
body: body ? JSON.stringify(body) : undefined
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text()
|
||||
throw new Error(`Google Sheets API Error ${response.status}: ${response.statusText} - ${errorText}`)
|
||||
}
|
||||
|
||||
const data = await response.text()
|
||||
return data + TOOL_ARGS_PREFIX + JSON.stringify(params)
|
||||
}
|
||||
}
|
||||
|
||||
// Spreadsheet Tools
|
||||
class CreateSpreadsheetTool extends BaseGoogleSheetsTool {
|
||||
defaultParams: any
|
||||
|
||||
constructor(args: any) {
|
||||
const toolInput = {
|
||||
name: 'create_spreadsheet',
|
||||
description: 'Create a new Google Spreadsheet',
|
||||
schema: CreateSpreadsheetSchema,
|
||||
baseUrl: '',
|
||||
method: 'POST',
|
||||
headers: {}
|
||||
}
|
||||
super({
|
||||
...toolInput,
|
||||
accessToken: args.accessToken
|
||||
})
|
||||
this.defaultParams = args.defaultParams || {}
|
||||
}
|
||||
|
||||
async _call(arg: any): Promise<string> {
|
||||
const params = { ...arg, ...this.defaultParams }
|
||||
|
||||
const body: any = {
|
||||
properties: {
|
||||
title: params.title
|
||||
}
|
||||
}
|
||||
|
||||
if (params.locale) body.properties.locale = params.locale
|
||||
if (params.timeZone) body.properties.timeZone = params.timeZone
|
||||
|
||||
// Add sheets if specified
|
||||
if (params.sheetCount && params.sheetCount > 1) {
|
||||
body.sheets = []
|
||||
for (let i = 0; i < params.sheetCount; i++) {
|
||||
body.sheets.push({
|
||||
properties: {
|
||||
title: i === 0 ? 'Sheet1' : `Sheet${i + 1}`
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return await this.makeGoogleSheetsRequest({
|
||||
endpoint: 'spreadsheets',
|
||||
method: 'POST',
|
||||
body,
|
||||
params
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
class GetSpreadsheetTool extends BaseGoogleSheetsTool {
|
||||
defaultParams: any
|
||||
|
||||
constructor(args: any) {
|
||||
const toolInput = {
|
||||
name: 'get_spreadsheet',
|
||||
description: 'Get a Google Spreadsheet by ID',
|
||||
schema: GetSpreadsheetSchema,
|
||||
baseUrl: '',
|
||||
method: 'GET',
|
||||
headers: {}
|
||||
}
|
||||
super({
|
||||
...toolInput,
|
||||
accessToken: args.accessToken
|
||||
})
|
||||
this.defaultParams = args.defaultParams || {}
|
||||
}
|
||||
|
||||
async _call(arg: any): Promise<string> {
|
||||
const params = { ...arg, ...this.defaultParams }
|
||||
const queryParams = new URLSearchParams()
|
||||
|
||||
if (params.ranges) {
|
||||
params.ranges.split(',').forEach((range: string) => {
|
||||
queryParams.append('ranges', range.trim())
|
||||
})
|
||||
}
|
||||
if (params.includeGridData) queryParams.append('includeGridData', 'true')
|
||||
|
||||
const queryString = queryParams.toString()
|
||||
const endpoint = `spreadsheets/${params.spreadsheetId}${queryString ? `?${queryString}` : ''}`
|
||||
|
||||
return await this.makeGoogleSheetsRequest({
|
||||
endpoint,
|
||||
method: 'GET',
|
||||
params
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
class UpdateSpreadsheetTool extends BaseGoogleSheetsTool {
|
||||
defaultParams: any
|
||||
|
||||
constructor(args: any) {
|
||||
const toolInput = {
|
||||
name: 'update_spreadsheet',
|
||||
description: 'Update a Google Spreadsheet properties',
|
||||
schema: UpdateSpreadsheetSchema,
|
||||
baseUrl: '',
|
||||
method: 'POST',
|
||||
headers: {}
|
||||
}
|
||||
super({
|
||||
...toolInput,
|
||||
accessToken: args.accessToken
|
||||
})
|
||||
this.defaultParams = args.defaultParams || {}
|
||||
}
|
||||
|
||||
async _call(arg: any): Promise<string> {
|
||||
const params = { ...arg, ...this.defaultParams }
|
||||
|
||||
const requests = []
|
||||
if (params.title || params.locale || params.timeZone) {
|
||||
const updateProperties: any = {}
|
||||
if (params.title) updateProperties.title = params.title
|
||||
if (params.locale) updateProperties.locale = params.locale
|
||||
if (params.timeZone) updateProperties.timeZone = params.timeZone
|
||||
|
||||
requests.push({
|
||||
updateSpreadsheetProperties: {
|
||||
properties: updateProperties,
|
||||
fields: Object.keys(updateProperties).join(',')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const body = { requests }
|
||||
|
||||
return await this.makeGoogleSheetsRequest({
|
||||
endpoint: `spreadsheets/${params.spreadsheetId}:batchUpdate`,
|
||||
method: 'POST',
|
||||
body,
|
||||
params
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Values Tools
|
||||
class GetValuesTool extends BaseGoogleSheetsTool {
|
||||
defaultParams: any
|
||||
|
||||
constructor(args: any) {
|
||||
const toolInput = {
|
||||
name: 'get_values',
|
||||
description: 'Get values from a Google Spreadsheet range',
|
||||
schema: GetValuesSchema,
|
||||
baseUrl: '',
|
||||
method: 'GET',
|
||||
headers: {}
|
||||
}
|
||||
super({
|
||||
...toolInput,
|
||||
accessToken: args.accessToken
|
||||
})
|
||||
this.defaultParams = args.defaultParams || {}
|
||||
}
|
||||
|
||||
async _call(arg: any): Promise<string> {
|
||||
const params = { ...arg, ...this.defaultParams }
|
||||
const queryParams = new URLSearchParams()
|
||||
|
||||
if (params.valueRenderOption) queryParams.append('valueRenderOption', params.valueRenderOption)
|
||||
if (params.dateTimeRenderOption) queryParams.append('dateTimeRenderOption', params.dateTimeRenderOption)
|
||||
if (params.majorDimension) queryParams.append('majorDimension', params.majorDimension)
|
||||
|
||||
const queryString = queryParams.toString()
|
||||
const encodedRange = encodeURIComponent(params.range)
|
||||
const endpoint = `spreadsheets/${params.spreadsheetId}/values/${encodedRange}${queryString ? `?${queryString}` : ''}`
|
||||
|
||||
return await this.makeGoogleSheetsRequest({
|
||||
endpoint,
|
||||
method: 'GET',
|
||||
params
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
class UpdateValuesTool extends BaseGoogleSheetsTool {
|
||||
defaultParams: any
|
||||
|
||||
constructor(args: any) {
|
||||
const toolInput = {
|
||||
name: 'update_values',
|
||||
description: 'Update values in a Google Spreadsheet range',
|
||||
schema: UpdateValuesSchema,
|
||||
baseUrl: '',
|
||||
method: 'PUT',
|
||||
headers: {}
|
||||
}
|
||||
super({
|
||||
...toolInput,
|
||||
accessToken: args.accessToken
|
||||
})
|
||||
this.defaultParams = args.defaultParams || {}
|
||||
}
|
||||
|
||||
async _call(arg: any): Promise<string> {
|
||||
const params = { ...arg, ...this.defaultParams }
|
||||
|
||||
let values
|
||||
try {
|
||||
values = JSON.parse(params.values)
|
||||
} catch (error) {
|
||||
throw new Error('Values must be a valid JSON array')
|
||||
}
|
||||
|
||||
const body = {
|
||||
values,
|
||||
majorDimension: params.majorDimension || 'ROWS'
|
||||
}
|
||||
|
||||
const queryParams = new URLSearchParams()
|
||||
queryParams.append('valueInputOption', params.valueInputOption || 'USER_ENTERED')
|
||||
|
||||
const encodedRange = encodeURIComponent(params.range)
|
||||
const endpoint = `spreadsheets/${params.spreadsheetId}/values/${encodedRange}?${queryParams.toString()}`
|
||||
|
||||
return await this.makeGoogleSheetsRequest({
|
||||
endpoint,
|
||||
method: 'PUT',
|
||||
body,
|
||||
params
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
class AppendValuesTool extends BaseGoogleSheetsTool {
|
||||
defaultParams: any
|
||||
|
||||
constructor(args: any) {
|
||||
const toolInput = {
|
||||
name: 'append_values',
|
||||
description: 'Append values to a Google Spreadsheet range',
|
||||
schema: AppendValuesSchema,
|
||||
baseUrl: '',
|
||||
method: 'POST',
|
||||
headers: {}
|
||||
}
|
||||
super({
|
||||
...toolInput,
|
||||
accessToken: args.accessToken
|
||||
})
|
||||
this.defaultParams = args.defaultParams || {}
|
||||
}
|
||||
|
||||
async _call(arg: any): Promise<string> {
|
||||
const params = { ...arg, ...this.defaultParams }
|
||||
|
||||
let values
|
||||
try {
|
||||
values = JSON.parse(params.values)
|
||||
} catch (error) {
|
||||
throw new Error('Values must be a valid JSON array')
|
||||
}
|
||||
|
||||
const body = {
|
||||
values,
|
||||
majorDimension: params.majorDimension || 'ROWS'
|
||||
}
|
||||
|
||||
const queryParams = new URLSearchParams()
|
||||
queryParams.append('valueInputOption', params.valueInputOption || 'USER_ENTERED')
|
||||
queryParams.append('insertDataOption', params.insertDataOption || 'OVERWRITE')
|
||||
|
||||
const encodedRange = encodeURIComponent(params.range)
|
||||
const endpoint = `spreadsheets/${params.spreadsheetId}/values/${encodedRange}:append?${queryParams.toString()}`
|
||||
|
||||
return await this.makeGoogleSheetsRequest({
|
||||
endpoint,
|
||||
method: 'POST',
|
||||
body,
|
||||
params
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
class ClearValuesTool extends BaseGoogleSheetsTool {
|
||||
defaultParams: any
|
||||
|
||||
constructor(args: any) {
|
||||
const toolInput = {
|
||||
name: 'clear_values',
|
||||
description: 'Clear values from a Google Spreadsheet range',
|
||||
schema: ClearValuesSchema,
|
||||
baseUrl: '',
|
||||
method: 'POST',
|
||||
headers: {}
|
||||
}
|
||||
super({
|
||||
...toolInput,
|
||||
accessToken: args.accessToken
|
||||
})
|
||||
this.defaultParams = args.defaultParams || {}
|
||||
}
|
||||
|
||||
async _call(arg: any): Promise<string> {
|
||||
const params = { ...arg, ...this.defaultParams }
|
||||
|
||||
const encodedRange = encodeURIComponent(params.range)
|
||||
const endpoint = `spreadsheets/${params.spreadsheetId}/values/${encodedRange}:clear`
|
||||
|
||||
return await this.makeGoogleSheetsRequest({
|
||||
endpoint,
|
||||
method: 'POST',
|
||||
body: {},
|
||||
params
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
class BatchGetValuesTool extends BaseGoogleSheetsTool {
|
||||
defaultParams: any
|
||||
|
||||
constructor(args: any) {
|
||||
const toolInput = {
|
||||
name: 'batch_get_values',
|
||||
description: 'Get values from multiple Google Spreadsheet ranges',
|
||||
schema: BatchGetValuesSchema,
|
||||
baseUrl: '',
|
||||
method: 'GET',
|
||||
headers: {}
|
||||
}
|
||||
super({
|
||||
...toolInput,
|
||||
accessToken: args.accessToken
|
||||
})
|
||||
this.defaultParams = args.defaultParams || {}
|
||||
}
|
||||
|
||||
async _call(arg: any): Promise<string> {
|
||||
const params = { ...arg, ...this.defaultParams }
|
||||
const queryParams = new URLSearchParams()
|
||||
|
||||
// Add ranges
|
||||
params.ranges.split(',').forEach((range: string) => {
|
||||
queryParams.append('ranges', range.trim())
|
||||
})
|
||||
|
||||
if (params.valueRenderOption) queryParams.append('valueRenderOption', params.valueRenderOption)
|
||||
if (params.dateTimeRenderOption) queryParams.append('dateTimeRenderOption', params.dateTimeRenderOption)
|
||||
if (params.majorDimension) queryParams.append('majorDimension', params.majorDimension)
|
||||
|
||||
const endpoint = `spreadsheets/${params.spreadsheetId}/values:batchGet?${queryParams.toString()}`
|
||||
|
||||
return await this.makeGoogleSheetsRequest({
|
||||
endpoint,
|
||||
method: 'GET',
|
||||
params
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
class BatchUpdateValuesTool extends BaseGoogleSheetsTool {
|
||||
defaultParams: any
|
||||
|
||||
constructor(args: any) {
|
||||
const toolInput = {
|
||||
name: 'batch_update_values',
|
||||
description: 'Update values in multiple Google Spreadsheet ranges',
|
||||
schema: BatchUpdateValuesSchema,
|
||||
baseUrl: '',
|
||||
method: 'POST',
|
||||
headers: {}
|
||||
}
|
||||
super({
|
||||
...toolInput,
|
||||
accessToken: args.accessToken
|
||||
})
|
||||
this.defaultParams = args.defaultParams || {}
|
||||
}
|
||||
|
||||
async _call(arg: any): Promise<string> {
|
||||
const params = { ...arg, ...this.defaultParams }
|
||||
|
||||
let valueRanges
|
||||
try {
|
||||
valueRanges = JSON.parse(params.values)
|
||||
} catch (error) {
|
||||
throw new Error('Values must be a valid JSON array of value ranges')
|
||||
}
|
||||
|
||||
const body = {
|
||||
valueInputOption: params.valueInputOption || 'USER_ENTERED',
|
||||
data: valueRanges,
|
||||
includeValuesInResponse: params.includeValuesInResponse || false
|
||||
}
|
||||
|
||||
const endpoint = `spreadsheets/${params.spreadsheetId}/values:batchUpdate`
|
||||
|
||||
return await this.makeGoogleSheetsRequest({
|
||||
endpoint,
|
||||
method: 'POST',
|
||||
body,
|
||||
params
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
class BatchClearValuesTool extends BaseGoogleSheetsTool {
|
||||
defaultParams: any
|
||||
|
||||
constructor(args: any) {
|
||||
const toolInput = {
|
||||
name: 'batch_clear_values',
|
||||
description: 'Clear values from multiple Google Spreadsheet ranges',
|
||||
schema: BatchClearValuesSchema,
|
||||
baseUrl: '',
|
||||
method: 'POST',
|
||||
headers: {}
|
||||
}
|
||||
super({
|
||||
...toolInput,
|
||||
accessToken: args.accessToken
|
||||
})
|
||||
this.defaultParams = args.defaultParams || {}
|
||||
}
|
||||
|
||||
async _call(arg: any): Promise<string> {
|
||||
const params = { ...arg, ...this.defaultParams }
|
||||
|
||||
const ranges = params.ranges.split(',').map((range: string) => range.trim())
|
||||
const body = { ranges }
|
||||
|
||||
const endpoint = `spreadsheets/${params.spreadsheetId}/values:batchClear`
|
||||
|
||||
return await this.makeGoogleSheetsRequest({
|
||||
endpoint,
|
||||
method: 'POST',
|
||||
body,
|
||||
params
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export const createGoogleSheetsTools = (args?: RequestParameters): DynamicStructuredTool[] => {
|
||||
const { actions = [], accessToken, defaultParams } = args || {}
|
||||
const tools: DynamicStructuredTool[] = []
|
||||
|
||||
// Define all available tools
|
||||
const toolClasses = {
|
||||
// Spreadsheet tools
|
||||
createSpreadsheet: CreateSpreadsheetTool,
|
||||
getSpreadsheet: GetSpreadsheetTool,
|
||||
updateSpreadsheet: UpdateSpreadsheetTool,
|
||||
// Values tools
|
||||
getValues: GetValuesTool,
|
||||
updateValues: UpdateValuesTool,
|
||||
appendValues: AppendValuesTool,
|
||||
clearValues: ClearValuesTool,
|
||||
batchGetValues: BatchGetValuesTool,
|
||||
batchUpdateValues: BatchUpdateValuesTool,
|
||||
batchClearValues: BatchClearValuesTool
|
||||
}
|
||||
|
||||
// Create tools based on requested actions
|
||||
actions.forEach((action) => {
|
||||
const ToolClass = toolClasses[action as keyof typeof toolClasses]
|
||||
if (ToolClass) {
|
||||
tools.push(new ToolClass({ accessToken, defaultParams }))
|
||||
}
|
||||
})
|
||||
|
||||
return tools
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48" width="96px" height="96px"><path fill="#43a047" d="M37,45H11c-1.657,0-3-1.343-3-3V6c0-1.657,1.343-3,3-3h19l10,10v29C40,43.657,38.657,45,37,45z"/><path fill="#c8e6c9" d="M40 13L30 13 30 3z"/><path fill="#2e7d32" d="M30 13L40 23 40 13z"/><path fill="#e8f5e9" d="M31,23H17h-2v2v2v2v2v2v2v2h18v-2v-2v-2v-2v-2v-2v-2H31z M17,25h4v2h-4V25z M17,29h4v2h-4V29z M17,33h4v2h-4V33z M31,35h-8v-2h8V35z M31,31h-8v-2h8V31z M31,27h-8v-2h8V27z"/></svg>
|
||||
|
After Width: | Height: | Size: 495 B |
Reference in New Issue
Block a user