@devries-cameron20 / composio Mirror · read-only
Fork 0

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

next
ts 22 lines 615 Bytes
Raw
1 import type { JsonSchemaObject } from '../types';
2
3 export function extendSchemaWithMessage<
4 TZod,
5 TJson extends JsonSchemaObject,
6 TKey extends keyof TJson,
7 >(
8 zodSchema: TZod,
9 jsonSchema: TJson,
10 key: TKey,
11 extend: (zodSchema: TZod, value: NonNullable<TJson[TKey]>, errorMessage?: string) => TZod
12 ) {
13 const value = jsonSchema[key];
14
15 if (value !== undefined) {
16 const errorMessage = (jsonSchema as unknown as { errorMessage?: Record<string, string> })
17 .errorMessage?.[key as string];
18 return extend(zodSchema, value as NonNullable<TJson[TKey]>, errorMessage);
19 }
20
21 return zodSchema;
22 }