mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-20 15:02:02 +00:00
📖 fix: Verify Agents OpenAPI contracts and disable external reporting (#16028)
This commit is contained in:
parent
a26a6709ff
commit
44af4d3789
15 changed files with 746 additions and 21 deletions
|
|
@ -23,6 +23,8 @@ export type ResponseContract = {
|
|||
schema?: ZodTypeAny;
|
||||
/** A hand-written media-type object, used when there is no Zod schema. */
|
||||
content?: RawContent;
|
||||
/** Hand-written media types added alongside a generated JSON schema. */
|
||||
additionalContent?: RawContent;
|
||||
};
|
||||
|
||||
export type EndpointContract = {
|
||||
|
|
@ -69,7 +71,10 @@ function buildResponses(responses: ResponseContract[]): Record<string, unknown>
|
|||
if (response.schema) {
|
||||
result[response.status] = {
|
||||
description: response.description,
|
||||
content: { 'application/json': { schema: response.schema } },
|
||||
content: {
|
||||
'application/json': { schema: response.schema },
|
||||
...response.additionalContent,
|
||||
},
|
||||
};
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import {
|
|||
import {
|
||||
errorMessageResponseSchema,
|
||||
accountDeletionResponseSchema,
|
||||
genericServerErrorContent,
|
||||
messageResponseSchema,
|
||||
jsonParseErrorSchema,
|
||||
} from './errors';
|
||||
|
|
@ -78,7 +79,6 @@ const agentFileDeletedSchema = z.object({
|
|||
id: z.string(),
|
||||
deleted: z.literal(true),
|
||||
});
|
||||
|
||||
export const agentComponentSchemas: Record<string, ZodTypeAny> = {
|
||||
AgentCreateRequest: agentCreateRequestSchema,
|
||||
AgentUpdateRequest: agentUpdateRequestSchema,
|
||||
|
|
@ -115,8 +115,10 @@ const errorResponses = [
|
|||
},
|
||||
{
|
||||
status: 500,
|
||||
description: 'Internal server error',
|
||||
description:
|
||||
'Internal server error. Errors normalized by the route use JSON; the final application error controller sends a text body with the text/html media type.',
|
||||
schema: z.union([agentManagementErrorSchema, errorMessageResponseSchema]),
|
||||
additionalContent: genericServerErrorContent,
|
||||
},
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,15 @@
|
|||
import { z } from 'zod';
|
||||
import type { RawContent } from './adapter';
|
||||
|
||||
/** String fallbacks that Express serves as `text/html` from the final application error controller. */
|
||||
export const genericServerErrorContent: RawContent = {
|
||||
'text/html': {
|
||||
schema: {
|
||||
type: 'string',
|
||||
enum: ['An unknown error occurred.', 'Processing error in ErrorController.'],
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* The flat `{ error }` envelope the auth middleware sends for 401 (`{ error: 'Unauthorized' }`)
|
||||
|
|
|
|||
|
|
@ -38,7 +38,11 @@ const DOCS_HTML = `<!DOCTYPE html>
|
|||
var script = document.createElement('script');
|
||||
script.src = apiBase + '/docs/assets/swagger-ui-bundle.js';
|
||||
script.onload = function () {
|
||||
window.ui = SwaggerUIBundle({ url: apiBase + '/openapi.json', dom_id: '#swagger-ui' });
|
||||
window.ui = SwaggerUIBundle({
|
||||
url: apiBase + '/openapi.json',
|
||||
dom_id: '#swagger-ui',
|
||||
validatorUrl: null,
|
||||
});
|
||||
};
|
||||
document.body.appendChild(script);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import {
|
|||
import {
|
||||
errorMessageResponseSchema,
|
||||
accountDeletionResponseSchema,
|
||||
genericServerErrorContent,
|
||||
messageResponseSchema,
|
||||
jsonParseErrorSchema,
|
||||
} from './errors';
|
||||
|
|
@ -37,7 +38,6 @@ const skillFileUpdatedSchema = z.object({
|
|||
relativePath: z.string(),
|
||||
bytes: z.number().int().nonnegative(),
|
||||
});
|
||||
|
||||
export const skillComponentSchemas: Record<string, ZodTypeAny> = {
|
||||
SkillFrontmatterValue: skillFrontmatterValueSchema,
|
||||
Skill: skillManagementResponseSchema,
|
||||
|
|
@ -74,8 +74,10 @@ const errorResponses = [
|
|||
},
|
||||
{
|
||||
status: 500,
|
||||
description: 'Internal server error',
|
||||
description:
|
||||
'Internal server error. Errors normalized by the route use JSON; the final application error controller sends a text body with the text/html media type.',
|
||||
schema: z.union([agentManagementErrorSchema, errorMessageResponseSchema]),
|
||||
additionalContent: genericServerErrorContent,
|
||||
},
|
||||
];
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue