diff --git a/server/package.json b/server/package.json index b83eae82..13710f79 100644 --- a/server/package.json +++ b/server/package.json @@ -31,6 +31,8 @@ "@fastify/sensible": "^5.0.0", "@fastify/session": "^10.5.0", "@fastify/static": "^6.10.2", + "@fastify/swagger": "^8.12.1", + "@fastify/swagger-ui": "^2.0.1", "@ffmpeg.wasm/core-mt": "^0.12.0", "@ffmpeg.wasm/main": "^0.12.0", "@google-ai/generativelanguage": "^2.0.0", diff --git a/server/src/app.ts b/server/src/app.ts index bae34591..39373b5f 100644 --- a/server/src/app.ts +++ b/server/src/app.ts @@ -8,7 +8,8 @@ import { FastifySSEPlugin } from "@waylaidwanderer/fastify-sse-v2"; import fastifyCookie from "@fastify/cookie"; import fastifySession from "@fastify/session"; import { getSessionSecret, isCookieSecure } from "./utils/session"; - +import swagger from "@fastify/swagger"; +import swaggerUi from "@fastify/swagger-ui"; declare module "fastify" { interface Session { is_bot_allowed: boolean; @@ -21,7 +22,7 @@ const options: AppOptions = {}; const app: FastifyPluginAsync = async ( fastify, - opts, + opts ): Promise => { void fastify.register(cors); @@ -34,6 +35,21 @@ const app: FastifyPluginAsync = async ( }, }); + void fastify.register(swagger); + + void fastify.register(swaggerUi, { + routePrefix: "/docs", + staticCSP: true, + transformStaticCSP: (header: string) => header, + theme: { + title: "Dialoqbots API Docs", + }, + uiConfig: { + docExpansion: "none", + withCredentials: true, + }, + }); + void fastify.register(AutoLoad, { dir: join(__dirname, "plugins"), options: opts, diff --git a/server/src/routes/api/v1/admin/schema/index.ts b/server/src/routes/api/v1/admin/schema/index.ts index 226ced95..8a63e915 100644 --- a/server/src/routes/api/v1/admin/schema/index.ts +++ b/server/src/routes/api/v1/admin/schema/index.ts @@ -1,6 +1,15 @@ import { FastifySchema } from "fastify"; export const dialoqbaseSettingsSchema: FastifySchema = { + tags: ["Admin"], + summary: "API to get dialoqbase settings", + headers: { + type: "object", + properties: { + Authorization: { type: "string" }, + }, + required: ["Authorization"], + }, response: { 200: { noOfBotsPerUser: { type: "number" }, @@ -11,6 +20,15 @@ export const dialoqbaseSettingsSchema: FastifySchema = { }; export const updateDialoqbaseSettingsSchema: FastifySchema = { + tags: ["Admin"], + summary: "API to update dialoqbase settings", + headers: { + type: "object", + properties: { + Authorization: { type: "string" }, + }, + required: ["Authorization"], + }, body: { type: "object", properties: { @@ -35,6 +53,15 @@ export const updateDialoqbaseSettingsSchema: FastifySchema = { }; export const getAllUsersSchema: FastifySchema = { + tags: ["Admin"], + summary: "API to get all users", + headers: { + type: "object", + properties: { + Authorization: { type: "string" }, + }, + required: ["Authorization"], + }, response: { 200: { type: "array", @@ -54,6 +81,15 @@ export const getAllUsersSchema: FastifySchema = { }; export const resetUserPasswordByAdminSchema: FastifySchema = { + tags: ["Admin"], + summary: "API to reset user password by admin", + headers: { + type: "object", + properties: { + Authorization: { type: "string" }, + }, + required: ["Authorization"], + }, body: { type: "object", properties: { @@ -73,6 +109,15 @@ export const resetUserPasswordByAdminSchema: FastifySchema = { }; export const registerUserByAdminSchema: FastifySchema = { + tags: ["Admin"], + summary: "API to register user by admin", + headers: { + type: "object", + properties: { + Authorization: { type: "string" }, + }, + required: ["Authorization"], + }, body: { type: "object", properties: { @@ -90,4 +135,4 @@ export const registerUserByAdminSchema: FastifySchema = { }, }, }, -}; \ No newline at end of file +}; diff --git a/server/src/routes/api/v1/admin/schema/model.ts b/server/src/routes/api/v1/admin/schema/model.ts index 7013ed89..acb86eb7 100644 --- a/server/src/routes/api/v1/admin/schema/model.ts +++ b/server/src/routes/api/v1/admin/schema/model.ts @@ -1,8 +1,27 @@ import { FastifySchema } from "fastify"; -export const getAllModelsSchema: FastifySchema = {}; +export const getAllModelsSchema: FastifySchema = { + tags: ["Admin"], + summary: "API to get all models", + headers: { + type: "object", + properties: { + Authorization: { type: "string" }, + }, + required: ["Authorization"], + }, +}; export const fetchModelFromInputedUrlSchema: FastifySchema = { + tags: ["Admin"], + summary: "API to fetch avialable model from inputed url", + headers: { + type: "object", + properties: { + Authorization: { type: "string" }, + }, + required: ["Authorization"], + }, body: { type: "object", properties: { @@ -13,6 +32,15 @@ export const fetchModelFromInputedUrlSchema: FastifySchema = { }; export const saveModelFromInputedUrlSchema: FastifySchema = { + tags: ["Admin"], + summary: "API to save model from inputed url", + headers: { + type: "object", + properties: { + Authorization: { type: "string" }, + }, + required: ["Authorization"], + }, body: { type: "object", properties: { @@ -26,6 +54,15 @@ export const saveModelFromInputedUrlSchema: FastifySchema = { }; export const toogleModelSchema: FastifySchema = { + tags: ["Admin"], + summary: "API to toogle model", + headers: { + type: "object", + properties: { + Authorization: { type: "string" }, + }, + required: ["Authorization"], + }, body: { type: "object", properties: { diff --git a/server/src/routes/api/v1/bot/appearance/schema/index.ts b/server/src/routes/api/v1/bot/appearance/schema/index.ts index 1de3fb4b..0299b01c 100644 --- a/server/src/routes/api/v1/bot/appearance/schema/index.ts +++ b/server/src/routes/api/v1/bot/appearance/schema/index.ts @@ -1,6 +1,15 @@ import { FastifySchema } from "fastify"; export const getBotAppearanceByIdSchema: FastifySchema = { + tags: ["Bot", "Appearance"], + summary: "API to get bot appearance by id", + headers: { + type: "object", + properties: { + Authorization: { type: "string" }, + }, + required: ["Authorization"], + }, params: { type: "object", properties: { @@ -12,6 +21,15 @@ export const getBotAppearanceByIdSchema: FastifySchema = { }; export const saveBotAppearanceSchema: FastifySchema = { + tags: ["Bot", "Appearance"], + summary: "API to save bot appearance by id", + headers: { + type: "object", + properties: { + Authorization: { type: "string" }, + }, + required: ["Authorization"], + }, params: { type: "object", properties: { diff --git a/server/src/routes/api/v1/bot/conversations/schema/index.ts b/server/src/routes/api/v1/bot/conversations/schema/index.ts index aede8fd5..ba5dc4a6 100644 --- a/server/src/routes/api/v1/bot/conversations/schema/index.ts +++ b/server/src/routes/api/v1/bot/conversations/schema/index.ts @@ -2,6 +2,15 @@ import { FastifySchema } from "fastify"; import { CHANNELS } from "../../../../../../utils/intergation"; export const getChatHistoryByTypeSchema: FastifySchema = { + tags: ["Bot", "Conversation"], + headers: { + type: "object", + properties: { + Authorization: { type: "string" }, + }, + required: ["Authorization"], + }, + summary: "Get chat history by intergation type", params: { type: "object", required: ["id", "type"], @@ -17,23 +26,30 @@ export const getChatHistoryByTypeSchema: FastifySchema = { }, }; - - export const getChatHistoryByChatIdSchema: FastifySchema = { - params: { - type: "object", - required: ["id", "type", "chat_id"], - properties: { - id: { - type: "string", - }, - type: { - type: "string", - enum: CHANNELS, - }, - chat_id: { - type: "string", - } - }, + tags: ["Bot", "Conversation"], + headers: { + type: "object", + properties: { + Authorization: { type: "string" }, }, + required: ["Authorization"], + }, + summary: "Get chat history by chat id", + params: { + type: "object", + required: ["id", "type", "chat_id"], + properties: { + id: { + type: "string", + }, + type: { + type: "string", + enum: CHANNELS, + }, + chat_id: { + type: "string", + }, + }, + }, }; diff --git a/server/src/routes/api/v1/bot/index.ts b/server/src/routes/api/v1/bot/index.ts index ef80fc0b..c5bc2fb9 100644 --- a/server/src/routes/api/v1/bot/index.ts +++ b/server/src/routes/api/v1/bot/index.ts @@ -13,7 +13,7 @@ import { refreshSourceByIdHandler, updateBotByIdHandler, getCreateBotConfigHandler, - getBotByIdSettingsHandler + getBotByIdSettingsHandler, } from "./handlers"; import { addNewSourceByIdSchema, @@ -118,6 +118,17 @@ const root: FastifyPluginAsync = async (fastify, _): Promise => { "/", { onRequest: [fastify.authenticate], + schema: { + tags: ["Bot"], + summary: "API to get all bots", + headers: { + type: "object", + properties: { + Authorization: { type: "string" }, + }, + required: ["Authorization"], + }, + }, }, getAllBotsHandler ); @@ -127,6 +138,17 @@ const root: FastifyPluginAsync = async (fastify, _): Promise => { "/upload", { onRequest: [fastify.authenticate], + schema: { + tags: ["Bot"], + summary: "API to upload pdf", + headers: { + type: "object", + properties: { + Authorization: { type: "string" }, + }, + required: ["Authorization"], + }, + }, }, createBotFileHandler ); @@ -136,12 +158,32 @@ const root: FastifyPluginAsync = async (fastify, _): Promise => { "/:id/source/upload", { onRequest: [fastify.authenticate], + schema: { + tags: ["Bot"], + summary: "API to upload pdf", + headers: { + type: "object", + properties: { + Authorization: { type: "string" }, + }, + required: ["Authorization"], + }, + }, }, addNewSourceFileByIdHandler ); // get bot config - fastify.get("/config", getCreateBotConfigHandler); + fastify.get( + "/config", + { + schema: { + tags: ["Bot"], + summary: "API to get bot configuraion", + }, + }, + getCreateBotConfigHandler + ); // get bot settings by id fastify.get( diff --git a/server/src/routes/api/v1/bot/integration/index.ts b/server/src/routes/api/v1/bot/integration/index.ts index 0579d2df..8501bb6d 100644 --- a/server/src/routes/api/v1/bot/integration/index.ts +++ b/server/src/routes/api/v1/bot/integration/index.ts @@ -47,14 +47,41 @@ const root: FastifyPluginAsync = async (fastify, _): Promise => { fastify.get( "/:id", { + schema: { + tags: ["Bot", "Integration"], + summary: "Get all bot channels", + headers: { + type: "object", + properties: { + Authorization: { type: "string" }, + }, + required: ["Authorization"], + }, + }, onRequest: [fastify.authenticate], }, getChannelsByProvider ); // whatsapp integration - fastify.get("/:id/whatsapp", {}, whatsappIntergationHandler); - fastify.post("/:id/whatsapp", {}, whatsappIntergationHandlerPost); + fastify.get( + "/:id/whatsapp", + { + schema: { + hide: true, + }, + }, + whatsappIntergationHandler + ); + fastify.post( + "/:id/whatsapp", + { + schema: { + hide: true, + }, + }, + whatsappIntergationHandlerPost + ); // api key integration fastify.get( diff --git a/server/src/routes/api/v1/bot/integration/schema/index.ts b/server/src/routes/api/v1/bot/integration/schema/index.ts index e062f6d5..623b6e3e 100644 --- a/server/src/routes/api/v1/bot/integration/schema/index.ts +++ b/server/src/routes/api/v1/bot/integration/schema/index.ts @@ -2,6 +2,15 @@ import { FastifySchema } from "fastify"; import { CHANNELS } from "../../../../../../utils/intergation"; export const createIntergationSchema: FastifySchema = { + tags: ["Bot", "Integration"], + summary: "API to create bot integration", + headers: { + type: "object", + properties: { + Authorization: { type: "string" }, + }, + required: ["Authorization"], + }, params: { type: "object", required: ["id"], @@ -27,6 +36,15 @@ export const createIntergationSchema: FastifySchema = { }; export const pauseOrResumeIntergationSchema: FastifySchema = { + tags: ["Bot", "Integration"], + summary: "API to pause or resume bot integration", + headers: { + type: "object", + properties: { + Authorization: { type: "string" }, + }, + required: ["Authorization"], + }, params: { type: "object", required: ["id"], @@ -49,6 +67,15 @@ export const pauseOrResumeIntergationSchema: FastifySchema = { }; export const generateAPIKeySchema: FastifySchema = { + tags: ["Bot", "Integration"], + summary: "API to generate API key for bot integration", + headers: { + type: "object", + properties: { + Authorization: { type: "string" }, + }, + required: ["Authorization"], + }, params: { type: "object", required: ["id"], @@ -61,6 +88,15 @@ export const generateAPIKeySchema: FastifySchema = { }; export const regenerateAPIKeySchema: FastifySchema = { + tags: ["Bot", "Integration"], + summary: "API to regenerate API key for bot integration", + headers: { + type: "object", + properties: { + Authorization: { type: "string" }, + }, + required: ["Authorization"], + }, params: { type: "object", required: ["id"], @@ -73,6 +109,15 @@ export const regenerateAPIKeySchema: FastifySchema = { }; export const getAPIIntegrationSchema: FastifySchema = { + tags: ["Bot", "Integration"], + summary: "API to get API key for bot integration", + headers: { + type: "object", + properties: { + Authorization: { type: "string" }, + }, + required: ["Authorization"], + }, params: { type: "object", required: ["id"], diff --git a/server/src/routes/api/v1/bot/playground/schema/index.ts b/server/src/routes/api/v1/bot/playground/schema/index.ts index de1308a6..dad501b7 100644 --- a/server/src/routes/api/v1/bot/playground/schema/index.ts +++ b/server/src/routes/api/v1/bot/playground/schema/index.ts @@ -1,6 +1,15 @@ import { FastifySchema } from "fastify"; export const chatRequestSchema: FastifySchema = { + tags: ["Bot", "Playground"], + summary: "API to send message to bot on playground", + headers: { + type: "object", + properties: { + Authorization: { type: "string" }, + }, + required: ["Authorization"], + }, params: { type: "object", required: ["id"], @@ -28,6 +37,15 @@ export const chatRequestSchema: FastifySchema = { }; export const chatRequestStreamSchema: FastifySchema = { + tags: ["Bot", "Playground"], + summary: "API to get stream of message from bot on playground", + headers: { + type: "object", + properties: { + Authorization: { type: "string" }, + }, + required: ["Authorization"], + }, params: { type: "object", required: ["id"], @@ -39,8 +57,16 @@ export const chatRequestStreamSchema: FastifySchema = { }, }; - export const chatPlaygroundHistorySchema: FastifySchema = { + tags: ["Bot", "Playground"], + summary: "API to get history of message from bot on playground", + headers: { + type: "object", + properties: { + Authorization: { type: "string" }, + }, + required: ["Authorization"], + }, params: { type: "object", required: ["id"], @@ -53,6 +79,15 @@ export const chatPlaygroundHistorySchema: FastifySchema = { }; export const chatPlaygroundHistoryIdSchema: FastifySchema = { + tags: ["Bot", "Playground"], + summary: "API to get history of message from bot on playground by history id", + headers: { + type: "object", + properties: { + Authorization: { type: "string" }, + }, + required: ["Authorization"], + }, params: { type: "object", required: ["id", "history_id"], @@ -62,13 +97,21 @@ export const chatPlaygroundHistoryIdSchema: FastifySchema = { }, history_id: { type: "string", - } + }, }, }, }; - export const audioSettingsSchema: FastifySchema = { + tags: ["Bot", "Playground"], + summary: "API to get audio settings from bot on playground", + headers: { + type: "object", + properties: { + Authorization: { type: "string" }, + }, + required: ["Authorization"], + }, params: { type: "object", required: ["id"], @@ -90,4 +133,4 @@ export const audioSettingsSchema: FastifySchema = { }, }, }, -}; \ No newline at end of file +}; diff --git a/server/src/routes/api/v1/bot/schema/index.ts b/server/src/routes/api/v1/bot/schema/index.ts index 37631fff..081797f6 100644 --- a/server/src/routes/api/v1/bot/schema/index.ts +++ b/server/src/routes/api/v1/bot/schema/index.ts @@ -2,6 +2,14 @@ import { FastifySchema } from "fastify"; import { SUPPORTED_SOURCE_TYPES } from "../../../../../utils/datasource"; export const createBotSchema: FastifySchema = { + tags: ["Bot"], + headers: { + type: "object", + properties: { + Authorization: { type: "string" }, + }, + required: ["Authorization"], + }, body: { type: "object", properties: { @@ -35,6 +43,14 @@ export const createBotSchema: FastifySchema = { }; export const getBotByIdSchema: FastifySchema = { + tags: ["Bot"], + headers: { + type: "object", + properties: { + Authorization: { type: "string" }, + }, + required: ["Authorization"], + }, params: { type: "object", required: ["id"], @@ -47,6 +63,14 @@ export const getBotByIdSchema: FastifySchema = { }; export const addNewSourceByIdSchema: FastifySchema = { + tags: ["Bot"], + headers: { + type: "object", + properties: { + Authorization: { type: "string" }, + }, + required: ["Authorization"], + }, params: { type: "object", required: ["id"], @@ -82,6 +106,14 @@ export const addNewSourceByIdSchema: FastifySchema = { }; export const updateBotByIdSchema: FastifySchema = { + tags: ["Bot"], + headers: { + type: "object", + properties: { + Authorization: { type: "string" }, + }, + required: ["Authorization"], + }, params: { type: "object", required: ["id"], @@ -127,7 +159,7 @@ export const updateBotByIdSchema: FastifySchema = { }, bot_model_api_key: { type: "string", - } + }, }, }, }; diff --git a/server/src/routes/api/v1/user/root.ts b/server/src/routes/api/v1/user/root.ts index 9c9a5716..647f7236 100644 --- a/server/src/routes/api/v1/user/root.ts +++ b/server/src/routes/api/v1/user/root.ts @@ -21,7 +21,7 @@ const root: FastifyPluginAsync = async (fastify, _): Promise => { { schema: userLoginSchema, }, - userLoginHandler, + userLoginHandler ); fastify.post( @@ -30,7 +30,7 @@ const root: FastifyPluginAsync = async (fastify, _): Promise => { schema: updateProfileSchema, onRequest: [fastify.authenticate], }, - updateProfileHandler, + updateProfileHandler ); fastify.post( @@ -39,7 +39,7 @@ const root: FastifyPluginAsync = async (fastify, _): Promise => { schema: updatePasswordSchema, onRequest: [fastify.authenticate], }, - updatePasswordHandler, + updatePasswordHandler ); fastify.get( @@ -47,7 +47,7 @@ const root: FastifyPluginAsync = async (fastify, _): Promise => { { schema: isRegisterationAllowedSchema, }, - isRegisterationAllowedHandler, + isRegisterationAllowedHandler ); fastify.post( @@ -55,25 +55,47 @@ const root: FastifyPluginAsync = async (fastify, _): Promise => { { schema: userRegisterSchema, }, - registerUserHandler, + registerUserHandler ); fastify.get( "/is-admin", { onRequest: [fastify.authenticate], + schema: { + tags: ["User"], + summary: "Check if user is admin", + headers: { + type: "object", + properties: { + Authorization: { type: "string" }, + }, + required: ["Authorization"], + }, + }, }, async (request, reply) => { reply.send({ is_admin: request.user.is_admin }); - }, + } ); fastify.get( "/me", { onRequest: [fastify.authenticate], + schema: { + tags: ["User"], + summary: "Get user profile", + headers: { + type: "object", + properties: { + Authorization: { type: "string" }, + }, + required: ["Authorization"], + }, + }, }, - meHandler, + meHandler ); }; diff --git a/server/src/routes/api/v1/user/schema/index.ts b/server/src/routes/api/v1/user/schema/index.ts index 98d19a20..cd0ef591 100644 --- a/server/src/routes/api/v1/user/schema/index.ts +++ b/server/src/routes/api/v1/user/schema/index.ts @@ -1,6 +1,8 @@ import { FastifySchema } from "fastify"; export const userLoginSchema: FastifySchema = { + tags: ["User"], + summary: "API to login user", body: { type: "object", required: ["username", "password"], @@ -16,6 +18,15 @@ export const userLoginSchema: FastifySchema = { }; export const updateProfileSchema: FastifySchema = { + tags: ["User"], + summary: "API to update user profile", + headers: { + type: "object", + properties: { + Authorization: { type: "string" }, + }, + required: ["Authorization"], + }, body: { type: "object", required: ["username", "email"], @@ -31,6 +42,15 @@ export const updateProfileSchema: FastifySchema = { }; export const updatePasswordSchema: FastifySchema = { + tags: ["User"], + summary: "API to update user password", + headers: { + type: "object", + properties: { + Authorization: { type: "string" }, + }, + required: ["Authorization"], + }, body: { type: "object", required: ["oldPassword", "newPassword"], @@ -45,10 +65,22 @@ export const updatePasswordSchema: FastifySchema = { }, }; -export const isRegisterationAllowedSchema: FastifySchema = {}; - +export const isRegisterationAllowedSchema: FastifySchema = { + tags: ["User"], + summary: "API to check if registeration is allowed", + response: { + 200: { + type: "object", + properties: { + isRegistrationAllowed: { type: "boolean" }, + }, + } + } +}; export const userRegisterSchema: FastifySchema = { + tags: ["User"], + summary: "API to register user", body: { type: "object", required: ["username", "password", "email"], diff --git a/server/src/routes/api/v1/view/root.ts b/server/src/routes/api/v1/view/root.ts index 305fb270..0450bdc0 100644 --- a/server/src/routes/api/v1/view/root.ts +++ b/server/src/routes/api/v1/view/root.ts @@ -3,32 +3,40 @@ import * as fs from "fs/promises"; import { join } from "path"; const root: FastifyPluginAsync = async (fastify, _): Promise => { - fastify.get("/*", async (request, reply) => { - try { - //@ts-ignore - const filePath = request.params["*"]; - const path = join(__dirname, `../../../../../${filePath}`); - const file = await fs.readFile(path); - const ext = filePath.split(".").pop(); - // set content type - if (ext === "pdf") { - reply.header("Content-Type", "application/pdf"); - } else if (ext === "mp3") { - reply.header("Content-Type", "audio/mpeg"); - } else if (ext === "mp4") { - reply.header("Content-Type", "video/mp4"); - } else if (ext === "png" || ext === "jpg" || ext === "jpeg") { - reply.header("Content-Type", "image/jpeg"); - } else if (ext === "json") { - reply.header("Content-Type", "application/json"); - } else { - reply.header("Content-Type", "text/plain"); + fastify.get( + "/*", + { + schema: { + hide: true, + }, + }, + async (request, reply) => { + try { + //@ts-ignore + const filePath = request.params["*"]; + const path = join(__dirname, `../../../../../${filePath}`); + const file = await fs.readFile(path); + const ext = filePath.split(".").pop(); + // set content type + if (ext === "pdf") { + reply.header("Content-Type", "application/pdf"); + } else if (ext === "mp3") { + reply.header("Content-Type", "audio/mpeg"); + } else if (ext === "mp4") { + reply.header("Content-Type", "video/mp4"); + } else if (ext === "png" || ext === "jpg" || ext === "jpeg") { + reply.header("Content-Type", "image/jpeg"); + } else if (ext === "json") { + reply.header("Content-Type", "application/json"); + } else { + reply.header("Content-Type", "text/plain"); + } + return file; + } catch (error) { + return reply.status(404).send("Not Found"); } - return file; - } catch (error) { - return reply.status(404).send("Not Found"); } - }); + ); }; export default root; diff --git a/server/src/routes/api/v1/voice/root.ts b/server/src/routes/api/v1/voice/root.ts index 5d0246f2..14e16c98 100644 --- a/server/src/routes/api/v1/voice/root.ts +++ b/server/src/routes/api/v1/voice/root.ts @@ -2,9 +2,32 @@ import { FastifyPluginAsync } from "fastify"; import { voiceTTSHandler } from "./handlers/post.handler"; const root: FastifyPluginAsync = async (fastify, _): Promise => { - fastify.post("/11labs/tts", { - onRequest: [fastify.authenticate], - }, voiceTTSHandler); + fastify.post( + "/11labs/tts", + { + onRequest: [fastify.authenticate], + schema: { + tags: ["Voice"], + headers: { + type: "object", + properties: { + Authorization: { type: "string" }, + }, + required: ["Authorization"], + }, + summary: "API to get voice from text", + body: { + type: "object", + properties: { + text: { type: "string" }, + voice_id: { type: "string" }, + }, + required: ["text", "voice_id"], + }, + }, + }, + voiceTTSHandler + ); }; export default root; diff --git a/server/src/routes/bot/root.ts b/server/src/routes/bot/root.ts index bddd0ca7..e5d59139 100644 --- a/server/src/routes/bot/root.ts +++ b/server/src/routes/bot/root.ts @@ -46,9 +46,28 @@ const root: FastifyPluginAsync = async (fastify, _): Promise => { chatRequestAPIHandler ); - fastify.get("/:id", async (request, reply) => { - return reply.sendFile("bot.html"); - }); + fastify.get( + "/:id", + { + schema: { + tags: ["Widget"], + summary: "Get widget", + hide: true, + params: { + type: "object", + required: ["id"], + properties: { + id: { + type: "string", + }, + }, + }, + }, + }, + async (request, reply) => { + return reply.sendFile("bot.html"); + } + ); }; export default root; diff --git a/server/src/routes/bot/schema/index.ts b/server/src/routes/bot/schema/index.ts index 6ce891c4..3d836861 100644 --- a/server/src/routes/bot/schema/index.ts +++ b/server/src/routes/bot/schema/index.ts @@ -1,6 +1,8 @@ import { FastifySchema } from "fastify"; export const chatRequestSchema: FastifySchema = { + tags: ["Widget"], + summary: "API to send message to bot", params: { type: "object", required: ["id"], @@ -25,6 +27,8 @@ export const chatRequestSchema: FastifySchema = { }; export const chatStyleSchema: FastifySchema = { + tags: ["Widget"], + summary: "API to get style of widget", params: { type: "object", required: ["id"], @@ -37,6 +41,8 @@ export const chatStyleSchema: FastifySchema = { }; export const chatRequestStreamSchema: FastifySchema = { + tags: ["Widget"], + summary: "API to get stream of message from bot", params: { type: "object", required: ["id"], @@ -61,6 +67,8 @@ export const chatRequestStreamSchema: FastifySchema = { }; export const chatAPIRequestSchema: FastifySchema = { + tags: ["Widget"], + summary: "Public API to send message to bot on widget", headers: { type: "object", required: ["x-api-key"], diff --git a/server/yarn.lock b/server/yarn.lock index c2ebd32f..1dbec1d3 100644 --- a/server/yarn.lock +++ b/server/yarn.lock @@ -459,6 +459,18 @@ fastify-plugin "^4.0.0" safe-stable-stringify "^2.3.1" +"@fastify/static@^6.0.0": + version "6.12.0" + resolved "https://registry.yarnpkg.com/@fastify/static/-/static-6.12.0.tgz#f3d55dda201c072bae0593e5d45dde8fd235c288" + integrity sha512-KK1B84E6QD/FcQWxDI2aiUCwHxMJBI1KeCUzm1BwYpPY1b742+jeKruGHP2uOluuM6OkBPI8CIANrXcCRtC2oQ== + dependencies: + "@fastify/accept-negotiator" "^1.0.0" + "@fastify/send" "^2.0.0" + content-disposition "^0.5.3" + fastify-plugin "^4.0.0" + glob "^8.0.1" + p-limit "^3.1.0" + "@fastify/static@^6.10.2": version "6.10.2" resolved "https://registry.yarnpkg.com/@fastify/static/-/static-6.10.2.tgz#dfaaccfa191a4ba85ea8e3926853c9e6d979e67f" @@ -472,6 +484,28 @@ p-limit "^3.1.0" readable-stream "^4.0.0" +"@fastify/swagger-ui@^2.0.1": + version "2.0.1" + resolved "https://registry.yarnpkg.com/@fastify/swagger-ui/-/swagger-ui-2.0.1.tgz#453bfa4142da9255581b061a8125c6d75ee6b6ee" + integrity sha512-sQnufSdQ5kJxaTxBisWYQjkunECuRymYRZYEZEEPpmLUzzZoS22tDLVumb3c1TV4MAlD3L1LTLpxLSXcFL+OZw== + dependencies: + "@fastify/static" "^6.0.0" + fastify-plugin "^4.0.0" + openapi-types "^12.0.2" + rfdc "^1.3.0" + yaml "^2.2.2" + +"@fastify/swagger@^8.12.1": + version "8.12.1" + resolved "https://registry.yarnpkg.com/@fastify/swagger/-/swagger-8.12.1.tgz#ff3436311a0ac157003fd8c2a38be3f565015bbb" + integrity sha512-0GATwS+a1QHHhTYtyZfoIpRD5lL1XlDSiV2DqsTVMQxKpL18kx5o6oMz0l0rtFr4883XIGiRuvTv2rxFRIxp4Q== + dependencies: + fastify-plugin "^4.0.0" + json-schema-resolver "^2.0.0" + openapi-types "^12.0.0" + rfdc "^1.3.0" + yaml "^2.2.2" + "@ffmpeg.wasm/core-mt@^0.12.0": version "0.12.0" resolved "https://registry.yarnpkg.com/@ffmpeg.wasm/core-mt/-/core-mt-0.12.0.tgz#a6e8604d6ccd3f0c9c14ead8ccfd4168b931f38c" @@ -3993,6 +4027,15 @@ json-buffer@3.0.1: resolved "https://registry.yarnpkg.com/json-buffer/-/json-buffer-3.0.1.tgz#9338802a30d3b6605fbe0613e094008ca8c05a13" integrity sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ== +json-schema-resolver@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/json-schema-resolver/-/json-schema-resolver-2.0.0.tgz#d17fdf53560e6bc9af084b930fee27f6ce4a03b6" + integrity sha512-pJ4XLQP4Q9HTxl6RVDLJ8Cyh1uitSs0CzDBAz1uoJ4sRD/Bk7cFSXL1FUXDW3zJ7YnfliJx6eu8Jn283bpZ4Yg== + dependencies: + debug "^4.1.1" + rfdc "^1.1.4" + uri-js "^4.2.2" + json-schema-traverse@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz#ae7bcb3656ab77a73ba5c49bf654f38e6b6860e2" @@ -4771,7 +4814,7 @@ openai@^4.19.0: node-fetch "^2.6.7" web-streams-polyfill "^3.2.1" -openapi-types@^12.1.3: +openapi-types@^12.0.0, openapi-types@^12.0.2, openapi-types@^12.1.3: version "12.1.3" resolved "https://registry.yarnpkg.com/openapi-types/-/openapi-types-12.1.3.tgz#471995eb26c4b97b7bd356aacf7b91b73e777dd3" integrity sha512-N4YtSYJqghVu4iek2ZUvcN/0aqH1kRDuNqzcycDxhOUpg7GdvLa2F3DgS6yBNhInhv2r/6I0Flkn7CqL8+nIcw== @@ -5489,7 +5532,7 @@ reusify@^1.0.0, reusify@^1.0.4: resolved "https://registry.yarnpkg.com/reusify/-/reusify-1.0.4.tgz#90da382b1e126efc02146e90845a88db12925d76" integrity sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw== -rfdc@^1.2.0, rfdc@^1.3.0: +rfdc@^1.1.4, rfdc@^1.2.0, rfdc@^1.3.0: version "1.3.0" resolved "https://registry.yarnpkg.com/rfdc/-/rfdc-1.3.0.tgz#d0b7c441ab2720d05dc4cf26e01c89631d9da08b" integrity sha512-V2hovdzFbOi77/WajaSMXk2OLm+xNIeQdMMuB7icj7bk6zi2F8GGAxigcnDFpJHbNyNcgyJDiP+8nOrY5cZGrA== @@ -6575,6 +6618,11 @@ yaml@^2.2.1: resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.3.1.tgz#02fe0975d23cd441242aa7204e09fc28ac2ac33b" integrity sha512-2eHWfjaoXgTBC2jNM1LRef62VQa0umtvRiDSk6HSzW7RvS5YtkabJrwYLLEKWBc8a5U2PTSCs+dJjUTJdlHsWQ== +yaml@^2.2.2: + version "2.3.4" + resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.3.4.tgz#53fc1d514be80aabf386dc6001eb29bf3b7523b2" + integrity sha512-8aAvwVUSHpfEqTQ4w/KMlf3HcRdt50E5ODIQJBw1fQ5RL34xabzxtUlzTXVqc4rkZsPbvrXKWnABCD7kWSmocA== + yargs-parser@^18.1.2: version "18.1.3" resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-18.1.3.tgz#be68c4975c6b2abf469236b0c870362fab09a7b0"