Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 21, 04:45 UTC
| 1 | import type { PiSessionToolOptions } from './types'; |
| 2 | |
| 3 | export const normalizeToolkits = (value: unknown): string[] | undefined => { |
| 4 | const toolkits = Array.isArray(value) |
| 5 | ? value.filter((item): item is string => typeof item === 'string' && item.trim().length > 0) |
| 6 | : typeof value === 'string' && value.trim().length > 0 |
| 7 | ? [value] |
| 8 | : []; |
| 9 | const unique = [...new Set(toolkits.map(toolkit => toolkit.trim()))]; |
| 10 | return unique.length > 0 ? unique : undefined; |
| 11 | }; |
| 12 | |
| 13 | export const maybeTransform = async ( |
| 14 | options: Pick<PiSessionToolOptions, 'transformResult'>, |
| 15 | params: Parameters<NonNullable<PiSessionToolOptions['transformResult']>>[0] |
| 16 | ): Promise<unknown> => (options.transformResult ? options.transformResult(params) : params.value); |
| 17 | |
| 18 | export const stringValue = (value: unknown): string | undefined => |
| 19 | typeof value === 'string' && value.trim().length > 0 ? value.trim() : undefined; |
| 20 | |
| 21 | export const toolkitFromToolSlug = (toolSlug: string): string | undefined => { |
| 22 | const normalized = toolSlug.trim().toLowerCase(); |
| 23 | if (!normalized || normalized.startsWith('composio_')) return undefined; |
| 24 | |
| 25 | const knownPrefixes: Array<[string, string]> = [ |
| 26 | ['google_calendar_', 'googlecalendar'], |
| 27 | ['google_drive_', 'googledrive'], |
| 28 | ['microsoft_teams_', 'microsoftteams'], |
| 29 | ]; |
| 30 | for (const [prefix, toolkit] of knownPrefixes) { |
| 31 | if (normalized.startsWith(prefix)) return toolkit; |
| 32 | } |
| 33 | |
| 34 | const [prefix] = normalized.split('_'); |
| 35 | return prefix || undefined; |
| 36 | }; |