Skip to main content
Glama

mcp-google-sheets

add-action-util.ts2.81 kB
import { applyFunctionToValuesSync, isString } from '../../common' import { FlowAction } from '../actions/action' import { FlowVersion } from '../flow-version' import { flowStructureUtil } from '../util/flow-structure-util' function mapToNewNames(flowVersion: FlowVersion, clonedActions: FlowAction[]): Record<string, string> { const existingNames = flowStructureUtil.getAllSteps(flowVersion.trigger) .map(step => step.name) const oldStepNames = clonedActions.flatMap(clonedAction => flowStructureUtil.getAllSteps(clonedAction).map(step => step.name)) return oldStepNames.reduce((nameMap, oldName) => { const newName = flowStructureUtil.findUnusedName(existingNames) existingNames.push(newName) return { ...nameMap, [oldName]: newName } }, {} as Record<string, string>) } type ReplaceOldStepNameWithNewOneProps = { input: string oldStepName: string newStepName: string } function replaceOldStepNameWithNewOne({ input, oldStepName, newStepName, }: ReplaceOldStepNameWithNewOneProps): string { const regex = /{{(.*?)}}/g // Regular expression to match strings inside {{ }} return input.replace(regex, (match, content) => { // Replace the content inside {{ }} using the provided function const replacedContent = content.replaceAll( new RegExp(`\\b${oldStepName}\\b`, 'g'), `${newStepName}`, ) // Reconstruct the {{ }} with the replaced content return `{{${replacedContent}}}` }) } function clone(step: FlowAction, oldNameToNewName: Record<string, string>): FlowAction { step.displayName = `${step.displayName} Copy` step.name = oldNameToNewName[step.name] if ('input' in step.settings) { Object.keys(oldNameToNewName).forEach((oldName) => { const settings = step.settings as { input: unknown } settings.input = applyFunctionToValuesSync( settings.input, (value: unknown) => { if (isString(value)) { return replaceOldStepNameWithNewOne({ input: value, oldStepName: oldName, newStepName: oldNameToNewName[oldName], }) } return value }, ) }) } if (step.settings.sampleData) { step.settings = { ...step.settings, sampleData: { ...step.settings.sampleData, sampleDataFileId: undefined, sampleDataInputFileId: undefined, lastTestDate: undefined, }, } } return step } export const addActionUtils = { mapToNewNames, clone, }

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/activepieces/activepieces'

If you have feedback or need assistance with the MCP directory API, please join our Discord server