mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-17 04:50:51 +00:00
30 lines
820 B
TypeScript
30 lines
820 B
TypeScript
import type { GatewayRequestHandlers } from "./types.js";
|
|
import {
|
|
ErrorCodes,
|
|
errorShape,
|
|
formatValidationErrors,
|
|
validateModelsListParams,
|
|
} from "../protocol/index.js";
|
|
|
|
export const modelsHandlers: GatewayRequestHandlers = {
|
|
"models.list": async ({ params, respond, context }) => {
|
|
if (!validateModelsListParams(params)) {
|
|
respond(
|
|
false,
|
|
undefined,
|
|
errorShape(
|
|
ErrorCodes.INVALID_REQUEST,
|
|
`invalid models.list params: ${formatValidationErrors(validateModelsListParams.errors)}`,
|
|
),
|
|
);
|
|
return;
|
|
}
|
|
try {
|
|
const models = await context.loadGatewayModelCatalog();
|
|
respond(true, { models }, undefined);
|
|
} catch (err) {
|
|
respond(false, undefined, errorShape(ErrorCodes.UNAVAILABLE, String(err)));
|
|
}
|
|
},
|
|
};
|