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, 06:00 UTC
| 1 | import { dequal } from 'dequal/lite'; |
| 2 | |
| 3 | import type { ZodBackend } from '../backend/types'; |
| 4 | import type { Serializable } from '../types'; |
| 5 | |
| 6 | export const parseLiteralValues = <S>( |
| 7 | values: ReadonlyArray<Serializable>, |
| 8 | backend: ZodBackend<S> |
| 9 | ): S => { |
| 10 | if (values.length === 0) return backend.never(); |
| 11 | |
| 12 | if (values.every(value => value === null || typeof value !== 'object')) { |
| 13 | const primitives = values as ReadonlyArray<string | number | boolean | null>; |
| 14 | if (primitives.length === 1) return backend.literal(primitives[0]); |
| 15 | if (primitives.every(value => typeof value === 'string')) { |
| 16 | return backend.enum(primitives as [string, ...string[]]); |
| 17 | } |
| 18 | return backend.union(primitives.map(value => backend.literal(value)) as unknown as [S, S]); |
| 19 | } |
| 20 | |
| 21 | return backend.predicate(value => values.some(candidate => dequal(value, candidate))); |
| 22 | }; |