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 | export interface SchemaPropertyEntry { |
| 2 | readonly name: string; |
| 3 | readonly type: string; |
| 4 | readonly label: 'required' | 'optional'; |
| 5 | readonly description?: string; |
| 6 | readonly hasDefault: boolean; |
| 7 | readonly defaultValue: unknown; |
| 8 | } |
| 9 | |
| 10 | export function extractSchemaProperties( |
| 11 | schema: Record<string, unknown> |
| 12 | ): ReadonlyArray<SchemaPropertyEntry> { |
| 13 | const properties = schema['properties'] as Record<string, Record<string, unknown>> | undefined; |
| 14 | if (!properties || Object.keys(properties).length === 0) { |
| 15 | return []; |
| 16 | } |
| 17 | |
| 18 | const requiredArr = (schema['required'] as string[] | undefined) ?? []; |
| 19 | const requiredSet = new Set(requiredArr); |
| 20 | |
| 21 | return Object.entries(properties).map(([name, prop]) => { |
| 22 | const type = (prop['type'] as string) ?? 'unknown'; |
| 23 | const label = requiredSet.has(name) ? 'required' : 'optional'; |
| 24 | const description = prop['description'] as string | undefined; |
| 25 | const hasDefault = Object.prototype.hasOwnProperty.call(prop, 'default'); |
| 26 | const defaultValue = hasDefault ? prop['default'] : undefined; |
| 27 | return { |
| 28 | name, |
| 29 | type, |
| 30 | label, |
| 31 | description, |
| 32 | hasDefault, |
| 33 | defaultValue, |
| 34 | }; |
| 35 | }); |
| 36 | } |