File size: 640 Bytes
d9494a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { isDefined } from '@/utils/validation/isDefined';
import {
  DEFAULT_TOOL_INPUT_SCHEMA,
  type InputJsonSchema,
} from '@/logic-function';

export const getInputSchemaFromSourceCode = async (
  sourceCode: string,
): Promise<InputJsonSchema> => {
  const { getFunctionInputSchema } =
    await import('./get-function-input-schema');
  const inputSchema = getFunctionInputSchema(sourceCode);

  const firstParam = inputSchema[0];

  if (firstParam?.type === 'object' && isDefined(firstParam.properties)) {
    return {
      type: 'object',
      properties: firstParam.properties,
    };
  }

  return DEFAULT_TOOL_INPUT_SCHEMA;
};