@websolutespa/payload-plugin-bowl-llm
Version:
LLM plugin for Bowl PayloadCms plugin
71 lines (70 loc) • 1.8 kB
JavaScript
import { options } from '../options';
export const threadHandler = async (req, appId)=>{
const { payload } = req;
if (!payload) {
throw {
status: 500,
message: 'Server Error: Cannot resolve payload'
};
}
const { query } = req;
if (!query) {
throw {
status: 400,
message: 'Bad Request: locale is missing'
};
}
const { locale } = query;
if (!locale) {
throw {
status: 400,
message: 'Bad Request: locale is missing'
};
}
const { appKey, apiKey, threadId } = req.data;
if (!appKey) {
throw {
status: 401,
message: 'Unauthorized: appKey is missing'
};
}
if (!apiKey) {
throw {
status: 401,
message: 'Unauthorized: apiKey is missing'
};
}
if (!threadId) {
throw {
status: 401,
message: 'Unauthorized: threadId is missing'
};
}
const defaultLocale = payload.config.localization ? payload.config.localization.defaultLocale : 'en';
const response = await payload.find({
collection: options.slug.llmThread,
where: {
id: {
equals: threadId
},
llmApp: {
equals: appId
}
},
depth: 3,
locale: locale,
fallbackLocale: defaultLocale,
showHiddenFields: true,
pagination: false,
overrideAccess: true
});
if (!response.docs.length) {
throw {
status: 404,
message: 'Not Found: thread not found'
};
}
const thread = response.docs[0];
return thread;
};
//# sourceMappingURL=thread.handler.js.map