Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

next
ts 21 lines 673 Bytes
Raw
1 import { parseSchema } from './parse-schema';
2 import type { ParseContext } from '../context';
3 import type { JsonSchemaObject, JsonSchema } from '../types';
4
5 export const parseAnyOf = <S>(
6 jsonSchema: JsonSchemaObject & { anyOf: JsonSchema[] },
7 ctx: ParseContext<S>
8 ): S => {
9 return jsonSchema.anyOf.length
10 ? jsonSchema.anyOf.length === 1
11 ? parseSchema(jsonSchema.anyOf[0], {
12 ...ctx,
13 path: [...ctx.path, 'anyOf', 0],
14 })
15 : ctx.backend.union(
16 jsonSchema.anyOf.map((schema, i) =>
17 parseSchema(schema, { ...ctx, path: [...ctx.path, 'anyOf', i] })
18 ) as [S, S]
19 )
20 : ctx.backend.any();
21 };