@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, 04:45 UTC

next
ts 45 lines 1.06 KB
Raw
1 import { extractSchemaProperties } from './extract-schema-properties';
2
3 /**
4 * Builds a minimal valid JSON payload from a JSON Schema input_schema.
5 * Used for CTA examples (e.g. composio execute "TOOL" -d '...').
6 */
7 export function buildMinimalPayloadFromSchema(
8 schema: Record<string, unknown> | null | undefined
9 ): Record<string, unknown> {
10 if (!schema || typeof schema !== 'object') {
11 return {};
12 }
13
14 const entries = extractSchemaProperties(schema);
15 if (entries.length === 0) {
16 return {};
17 }
18
19 const result: Record<string, unknown> = {};
20 for (const entry of entries) {
21 result[entry.name] = defaultForType(entry.type, entry.defaultValue);
22 }
23 return result;
24 }
25
26 function defaultForType(type: string, schemaDefault: unknown): unknown {
27 if (schemaDefault !== undefined) {
28 return schemaDefault;
29 }
30 switch (type) {
31 case 'string':
32 return '';
33 case 'number':
34 case 'integer':
35 return 0;
36 case 'boolean':
37 return false;
38 case 'array':
39 return [];
40 case 'object':
41 return {};
42 default:
43 return '';
44 }
45 }