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 { DateTime, Effect } from 'effect'; |
| 2 | import * as Arbitrary from 'effect/Arbitrary'; |
| 3 | import { Toolkit } from 'src/models/toolkits'; |
| 4 | |
| 5 | /** |
| 6 | * A fixed OAuth2 toolkit, for suites that must not inherit the randomized |
| 7 | * fields of the arbitrary-based builders below — execution paths branch on |
| 8 | * values like `no_auth` and `auth_schemes`. |
| 9 | */ |
| 10 | export const makeToolkitFixture = (slug: string, name: string = slug): Toolkit => ({ |
| 11 | name, |
| 12 | slug, |
| 13 | auth_schemes: ['OAUTH2'], |
| 14 | composio_managed_auth_schemes: ['OAUTH2'], |
| 15 | is_local_toolkit: false, |
| 16 | no_auth: false, |
| 17 | meta: { |
| 18 | description: `${name} toolkit`, |
| 19 | categories: [], |
| 20 | created_at: DateTime.makeUnsafe('2024-05-03T11:44:32.061Z'), |
| 21 | updated_at: DateTime.makeUnsafe('2024-05-03T11:44:32.061Z'), |
| 22 | available_versions: [], |
| 23 | tools_count: 0, |
| 24 | triggers_count: 0, |
| 25 | }, |
| 26 | }); |
| 27 | |
| 28 | const ToolkitArbitrary = Arbitrary.schema(Toolkit); |
| 29 | |
| 30 | const sampleToolkits = (count: number) => |
| 31 | Effect.runSync(Arbitrary.sampleEffect(ToolkitArbitrary, { count })); |
| 32 | |
| 33 | /** |
| 34 | * Creates multiple test toolkit instances by merging arbitrary generated toolkit data with the provided subset values. |
| 35 | * Useful for generating test data that maintains consistent identifiers while having realistic randomized properties. |
| 36 | */ |
| 37 | export function makeTestToolkits(inputs: Array<Pick<Toolkit, 'name' | 'slug'>>) { |
| 38 | const samples = sampleToolkits(inputs.length); |
| 39 | |
| 40 | const testToolkits = samples.map((sample, i) => ({ ...sample, ...inputs[i] })); |
| 41 | return testToolkits; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Creates a single test toolkit instance by merging arbitrary generated toolkit data with the provided subset values. |
| 46 | * Useful for generating test data that maintains consistent identifiers while having realistic randomized properties. |
| 47 | */ |
| 48 | export function makeTestToolkit(input: Pick<Toolkit, 'name' | 'slug'>) { |
| 49 | const samples = sampleToolkits(1); |
| 50 | |
| 51 | const testToolkits = samples.map((sample, i) => ({ ...sample, ...input })); |
| 52 | return testToolkits[0]; |
| 53 | } |