@samchon/openapi
Version:
Universal OpenAPI to LLM function calling schemas. Transform any Swagger/OpenAPI document into type-safe schemas for OpenAI, Claude, Qwen, and more.
1 lines • 2.56 kB
Source Map (JSON)
{"version":3,"file":"LlmParametersComposer.mjs","sources":["../../src/composers/LlmParametersComposer.ts"],"sourcesContent":["import { OpenApi } from \"../OpenApi\";\nimport { IOpenApiSchemaError } from \"../structures/IOpenApiSchemaError\";\nimport { IResult } from \"../structures/IResult\";\nimport { OpenApiTypeChecker } from \"../utils/OpenApiTypeChecker\";\n\n/** @internal */\nexport namespace LlmParametersFinder {\n export const parameters = (props: {\n components: OpenApi.IComponents;\n schema: OpenApi.IJsonSchema.IObject | OpenApi.IJsonSchema.IReference;\n method: string;\n accessor?: string;\n refAccessor?: string;\n }): IResult<OpenApi.IJsonSchema.IObject, IOpenApiSchemaError> => {\n const entity: IResult<OpenApi.IJsonSchema, IOpenApiSchemaError> =\n OpenApiTypeChecker.unreference(props);\n if (entity.success === false) return entity;\n else if (OpenApiTypeChecker.isObject(entity.value) === false)\n return reportError({\n ...props,\n message: \"LLM only accepts object type as parameters.\",\n });\n else if (!!entity.value.additionalProperties)\n return reportError({\n ...props,\n message: \"LLM does not allow additional properties on parameters.\",\n });\n return {\n success: true,\n value: entity.value,\n };\n };\n\n const reportError = (props: {\n method: string;\n message: string;\n schema: OpenApi.IJsonSchema;\n accessor?: string;\n }): IResult.IFailure<IOpenApiSchemaError> => ({\n success: false,\n error: {\n method: props.method,\n message: `failed to compose LLM schema.`,\n reasons: [\n {\n schema: props.schema,\n message: props.message,\n accessor: props.accessor ?? \"$input.schema\",\n },\n ],\n },\n });\n}\n"],"names":["LlmParametersFinder","parameters","props","entity","OpenApiTypeChecker","unreference","success","isObject","value","reportError","message","additionalProperties","error","method","reasons","schema","accessor"],"mappings":";;AAMM,IAAWA;;CAAjB,SAAiBA;IACFA,oBAAAC,aAAcC;QAOzB,MAAMC,SACJC,mBAAmBC,YAAYH;QACjC,IAAIC,OAAOG,YAAY,OAAO,OAAOH,aAChC,IAAIC,mBAAmBG,SAASJ,OAAOK,WAAW,OACrD,OAAOC,YAAY;eACdP;YACHQ,SAAS;iBAER,MAAMP,OAAOK,MAAMG,sBACtB,OAAOF,YAAY;eACdP;YACHQ,SAAS;;QAEb,OAAO;YACLJ,SAAS;YACTE,OAAOL,OAAOK;;;IAIlB,MAAMC,cAAeP,UAKpB;QACCI,SAAS;QACTM,OAAO;YACLC,QAAQX,MAAMW;YACdH,SAAS;YACTI,SAAS,EACP;gBACEC,QAAQb,MAAMa;gBACdL,SAASR,MAAMQ;gBACfM,UAAUd,MAAMc,YAAY;;;;AAKrC,EA9CD,CAAiBhB,wBAAAA,sBAAmB,CAAA;;"}