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 { describe, expect, it } from 'vitest'; |
| 2 | import { createToolkitIndex } from 'src/generation/create-toolkit-index'; |
| 3 | import { makeTestToolkits } from 'test/__utils__/models/toolkits'; |
| 4 | import { TRIGGER_TYPES_GMAIL } from 'test/__mocks__/trigger-types-gmail'; |
| 5 | |
| 6 | describe('createToolkitIndex', () => { |
| 7 | it('[Given] empty toolkits, tools, triggerTypes [Then] it returns an empty index', () => { |
| 8 | const index = createToolkitIndex({ |
| 9 | toolkits: [], |
| 10 | typeableTools: { withTypes: false, tools: [] }, |
| 11 | triggerTypes: [], |
| 12 | }); |
| 13 | |
| 14 | expect(index).toEqual({}); |
| 15 | }); |
| 16 | |
| 17 | it('[Given] only toolkits and no tools or triggerTypes [Then] it returns an index with empty tools and triggerTypes', () => { |
| 18 | const toolkits = makeTestToolkits([ |
| 19 | { |
| 20 | name: 'Gmail', |
| 21 | slug: 'gmail', |
| 22 | }, |
| 23 | { |
| 24 | name: 'Slack Helper', |
| 25 | slug: 'slack', |
| 26 | }, |
| 27 | ]); |
| 28 | |
| 29 | const index = createToolkitIndex({ |
| 30 | toolkits, |
| 31 | typeableTools: { withTypes: false, tools: [] }, |
| 32 | triggerTypes: [], |
| 33 | }); |
| 34 | |
| 35 | expect(index).toEqual({ |
| 36 | GMAIL: { |
| 37 | slug: 'gmail', |
| 38 | typeableTools: { withTypes: false, value: {} }, |
| 39 | triggerTypes: {}, |
| 40 | }, |
| 41 | SLACK: { |
| 42 | slug: 'slack', |
| 43 | typeableTools: { withTypes: false, value: {} }, |
| 44 | triggerTypes: {}, |
| 45 | }, |
| 46 | }); |
| 47 | }); |
| 48 | |
| 49 | it('[Given] valid toolkits, tools, triggerTypes [Then] it builds an index based on toolkits', () => { |
| 50 | const toolkits = makeTestToolkits([ |
| 51 | { |
| 52 | name: 'Gmail', |
| 53 | slug: 'gmail', |
| 54 | }, |
| 55 | { |
| 56 | name: 'Slack Helper', |
| 57 | slug: 'slack', |
| 58 | }, |
| 59 | ]); |
| 60 | |
| 61 | const GMAIL_NEW_GMAIL_MESSAGE = TRIGGER_TYPES_GMAIL.find( |
| 62 | triggerType => triggerType.slug === 'GMAIL_NEW_GMAIL_MESSAGE' |
| 63 | )!; |
| 64 | |
| 65 | const tools = ['GMAIL_CREATE_EMAIL_DRAFT', 'GMAIL_DELETE_MESSAGE', 'GMAIL_FETCH_EMAILS']; |
| 66 | const triggerTypes = [GMAIL_NEW_GMAIL_MESSAGE]; |
| 67 | |
| 68 | const index = createToolkitIndex({ |
| 69 | toolkits, |
| 70 | typeableTools: { withTypes: false, tools }, |
| 71 | triggerTypes, |
| 72 | }); |
| 73 | |
| 74 | expect(index).toEqual({ |
| 75 | GMAIL: { |
| 76 | slug: 'gmail', |
| 77 | typeableTools: { |
| 78 | withTypes: false, |
| 79 | value: { |
| 80 | CREATE_EMAIL_DRAFT: 'GMAIL_CREATE_EMAIL_DRAFT', |
| 81 | DELETE_MESSAGE: 'GMAIL_DELETE_MESSAGE', |
| 82 | FETCH_EMAILS: 'GMAIL_FETCH_EMAILS', |
| 83 | }, |
| 84 | }, |
| 85 | triggerTypes: { |
| 86 | NEW_GMAIL_MESSAGE: GMAIL_NEW_GMAIL_MESSAGE, |
| 87 | }, |
| 88 | }, |
| 89 | SLACK: { |
| 90 | slug: 'slack', |
| 91 | typeableTools: { withTypes: false, value: {} }, |
| 92 | triggerTypes: {}, |
| 93 | }, |
| 94 | }); |
| 95 | }); |
| 96 | }); |