2023-02-25 09:04:32 -05:00
|
|
|
const express = require('express');
|
|
|
|
|
const crypto = require('crypto');
|
|
|
|
|
const router = express.Router();
|
2023-04-05 16:15:46 +08:00
|
|
|
const { titleConvo, askBing } = require('../../../app');
|
2023-04-11 03:26:38 +08:00
|
|
|
const { saveMessage, getConvoTitle, saveConvo, getConvo } = require('../../../models');
|
2023-03-15 15:21:04 -04:00
|
|
|
const { handleError, sendMessage, createOnProgress, handleText } = require('./handlers');
|
feat: Auth and User System (#205)
* server-side JWT auth implementation
* move oauth routes and strategies, fix bugs
* backend modifications for wiring up the frontend login and reg forms
* Add frontend data services for login and registration
* Add login and registration forms
* Implment auth context, functional client side auth
* protect routes with jwt auth
* finish local strategy (using local storage)
* Start setting up google auth
* disable token refresh, remove old auth middleware
* refactor client, add ApiErrorBoundary context
* disable google and facebook strategies
* fix: fix presets not displaying specific to user
* fix: fix issue with browser refresh
* fix: casing issue with User.js (#11)
* delete user.js to be renamed
* fix: fix casing issue with User.js
* comment out api error watcher temporarily
* fix: issue with api error watcher (#12)
* delete user.js to be renamed
* fix: fix casing issue with User.js
* comment out api error watcher temporarily
* feat: add google auth social login
* fix: make google login url dynamic based on dev/prod
* fix: bug where UI is briefly displayed before redirecting to login
* fix: fix cookie expires value for local auth
* Update README.md
* Update LOCAL_INSTALL structure
* Add local testing instructions
* Only load google strategy if client id and secret are provided
* Update .env.example files with new params
* fix issue with not redirecting to register form
* only show google login button if value is set in .env
* cleanup log messages
* Add label to button for google login on login form
* doc: fix client/server url values in .env.example
* feat: add error message details to registration failure
* Restore preventing paste on confirm password
* auto-login user after registering
* feat: forgot password (#24)
* make login/reg pages look like openai's
* add password reset data services
* new form designs similar to openai, add password reset pages
* add api's for password reset
* email utils for password reset
* remove bcrypt salt rounds from process.env
* refactor: restructure api auth code, consolidate routes (#25)
* add api's for password reset
* remove bcrypt salt rounds from process.env
* refactor: consolidate auth routes, use controller pattern
* refactor: code cleanup
* feat: migrate data to first user (#26)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes after refactor (#27)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: issue with auto-login when logging out then logging in with new browser window (#28)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: fix issue with auto-login in new tab
* doc: Update README and .env.example files with user system information (#29)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: fix issue with auto-login in new tab
* doc: update README and .env.example files
* Fixup: LOCAL_INSTALL.md PS instructions (#200) (#30)
Co-authored-by: alfredo-f <alfredo.fomitchenko@mail.polimi.it>
* feat: send user with completion to protect against abuse (#31)
* Fixup: LOCAL_INSTALL.md PS instructions (#200)
* server-side JWT auth implementation
* move oauth routes and strategies, fix bugs
* backend modifications for wiring up the frontend login and reg forms
* Add frontend data services for login and registration
* Add login and registration forms
* Implment auth context, functional client side auth
* protect routes with jwt auth
* finish local strategy (using local storage)
* Start setting up google auth
* disable token refresh, remove old auth middleware
* refactor client, add ApiErrorBoundary context
* disable google and facebook strategies
* fix: fix presets not displaying specific to user
* fix: fix issue with browser refresh
* fix: casing issue with User.js (#11)
* delete user.js to be renamed
* fix: fix casing issue with User.js
* comment out api error watcher temporarily
* feat: add google auth social login
* fix: make google login url dynamic based on dev/prod
* fix: bug where UI is briefly displayed before redirecting to login
* fix: fix cookie expires value for local auth
* Only load google strategy if client id and secret are provided
* Update .env.example files with new params
* fix issue with not redirecting to register form
* only show google login button if value is set in .env
* cleanup log messages
* Add label to button for google login on login form
* doc: fix client/server url values in .env.example
* feat: add error message details to registration failure
* Restore preventing paste on confirm password
* auto-login user after registering
* feat: forgot password (#24)
* make login/reg pages look like openai's
* add password reset data services
* new form designs similar to openai, add password reset pages
* add api's for password reset
* email utils for password reset
* remove bcrypt salt rounds from process.env
* refactor: restructure api auth code, consolidate routes (#25)
* add api's for password reset
* remove bcrypt salt rounds from process.env
* refactor: consolidate auth routes, use controller pattern
* refactor: code cleanup
* feat: migrate data to first user (#26)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes after refactor (#27)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: issue with auto-login when logging out then logging in with new browser window (#28)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: fix issue with auto-login in new tab
* doc: Update README and .env.example files with user system information (#29)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: fix issue with auto-login in new tab
* doc: update README and .env.example files
* Send user id to openai to protect against abuse
* add meilisearch to gitignore
* Remove webpack
---------
Co-authored-by: alfredo-f <alfredo.fomitchenko@mail.polimi.it>
---------
Co-authored-by: Danny Avila <110412045+danny-avila@users.noreply.github.com>
Co-authored-by: Alfredo Fomitchenko <alfredo.fomitchenko@mail.polimi.it>
2023-05-07 10:04:51 -07:00
|
|
|
const requireJwtAuth = require('../../../middleware/requireJwtAuth');
|
2023-02-25 09:04:32 -05:00
|
|
|
|
feat: Auth and User System (#205)
* server-side JWT auth implementation
* move oauth routes and strategies, fix bugs
* backend modifications for wiring up the frontend login and reg forms
* Add frontend data services for login and registration
* Add login and registration forms
* Implment auth context, functional client side auth
* protect routes with jwt auth
* finish local strategy (using local storage)
* Start setting up google auth
* disable token refresh, remove old auth middleware
* refactor client, add ApiErrorBoundary context
* disable google and facebook strategies
* fix: fix presets not displaying specific to user
* fix: fix issue with browser refresh
* fix: casing issue with User.js (#11)
* delete user.js to be renamed
* fix: fix casing issue with User.js
* comment out api error watcher temporarily
* fix: issue with api error watcher (#12)
* delete user.js to be renamed
* fix: fix casing issue with User.js
* comment out api error watcher temporarily
* feat: add google auth social login
* fix: make google login url dynamic based on dev/prod
* fix: bug where UI is briefly displayed before redirecting to login
* fix: fix cookie expires value for local auth
* Update README.md
* Update LOCAL_INSTALL structure
* Add local testing instructions
* Only load google strategy if client id and secret are provided
* Update .env.example files with new params
* fix issue with not redirecting to register form
* only show google login button if value is set in .env
* cleanup log messages
* Add label to button for google login on login form
* doc: fix client/server url values in .env.example
* feat: add error message details to registration failure
* Restore preventing paste on confirm password
* auto-login user after registering
* feat: forgot password (#24)
* make login/reg pages look like openai's
* add password reset data services
* new form designs similar to openai, add password reset pages
* add api's for password reset
* email utils for password reset
* remove bcrypt salt rounds from process.env
* refactor: restructure api auth code, consolidate routes (#25)
* add api's for password reset
* remove bcrypt salt rounds from process.env
* refactor: consolidate auth routes, use controller pattern
* refactor: code cleanup
* feat: migrate data to first user (#26)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes after refactor (#27)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: issue with auto-login when logging out then logging in with new browser window (#28)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: fix issue with auto-login in new tab
* doc: Update README and .env.example files with user system information (#29)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: fix issue with auto-login in new tab
* doc: update README and .env.example files
* Fixup: LOCAL_INSTALL.md PS instructions (#200) (#30)
Co-authored-by: alfredo-f <alfredo.fomitchenko@mail.polimi.it>
* feat: send user with completion to protect against abuse (#31)
* Fixup: LOCAL_INSTALL.md PS instructions (#200)
* server-side JWT auth implementation
* move oauth routes and strategies, fix bugs
* backend modifications for wiring up the frontend login and reg forms
* Add frontend data services for login and registration
* Add login and registration forms
* Implment auth context, functional client side auth
* protect routes with jwt auth
* finish local strategy (using local storage)
* Start setting up google auth
* disable token refresh, remove old auth middleware
* refactor client, add ApiErrorBoundary context
* disable google and facebook strategies
* fix: fix presets not displaying specific to user
* fix: fix issue with browser refresh
* fix: casing issue with User.js (#11)
* delete user.js to be renamed
* fix: fix casing issue with User.js
* comment out api error watcher temporarily
* feat: add google auth social login
* fix: make google login url dynamic based on dev/prod
* fix: bug where UI is briefly displayed before redirecting to login
* fix: fix cookie expires value for local auth
* Only load google strategy if client id and secret are provided
* Update .env.example files with new params
* fix issue with not redirecting to register form
* only show google login button if value is set in .env
* cleanup log messages
* Add label to button for google login on login form
* doc: fix client/server url values in .env.example
* feat: add error message details to registration failure
* Restore preventing paste on confirm password
* auto-login user after registering
* feat: forgot password (#24)
* make login/reg pages look like openai's
* add password reset data services
* new form designs similar to openai, add password reset pages
* add api's for password reset
* email utils for password reset
* remove bcrypt salt rounds from process.env
* refactor: restructure api auth code, consolidate routes (#25)
* add api's for password reset
* remove bcrypt salt rounds from process.env
* refactor: consolidate auth routes, use controller pattern
* refactor: code cleanup
* feat: migrate data to first user (#26)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes after refactor (#27)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: issue with auto-login when logging out then logging in with new browser window (#28)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: fix issue with auto-login in new tab
* doc: Update README and .env.example files with user system information (#29)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: fix issue with auto-login in new tab
* doc: update README and .env.example files
* Send user id to openai to protect against abuse
* add meilisearch to gitignore
* Remove webpack
---------
Co-authored-by: alfredo-f <alfredo.fomitchenko@mail.polimi.it>
---------
Co-authored-by: Danny Avila <110412045+danny-avila@users.noreply.github.com>
Co-authored-by: Alfredo Fomitchenko <alfredo.fomitchenko@mail.polimi.it>
2023-05-07 10:04:51 -07:00
|
|
|
router.post('/', requireJwtAuth, async (req, res) => {
|
2023-03-14 20:21:41 -04:00
|
|
|
const {
|
2023-03-31 03:22:57 +08:00
|
|
|
endpoint,
|
2023-03-14 20:21:41 -04:00
|
|
|
text,
|
2023-03-31 03:22:57 +08:00
|
|
|
messageId,
|
|
|
|
|
overrideParentMessageId = null,
|
2023-03-14 20:21:41 -04:00
|
|
|
parentMessageId,
|
2023-03-31 03:22:57 +08:00
|
|
|
conversationId: oldConversationId
|
2023-03-14 20:21:41 -04:00
|
|
|
} = req.body;
|
2023-03-31 03:22:57 +08:00
|
|
|
if (text.length === 0) return handleError(res, { text: 'Prompt empty or too short' });
|
|
|
|
|
if (endpoint !== 'bingAI') return handleError(res, { text: 'Illegal request' });
|
2023-03-13 14:04:47 +08:00
|
|
|
|
2023-03-31 03:22:57 +08:00
|
|
|
// build user message
|
2023-03-13 13:11:53 +08:00
|
|
|
const conversationId = oldConversationId || crypto.randomUUID();
|
2023-03-14 20:21:41 -04:00
|
|
|
const isNewConversation = !oldConversationId;
|
2023-03-31 03:22:57 +08:00
|
|
|
const userMessageId = messageId;
|
2023-03-14 20:21:41 -04:00
|
|
|
const userParentMessageId = parentMessageId || '00000000-0000-0000-0000-000000000000';
|
2023-03-13 12:35:55 +08:00
|
|
|
let userMessage = {
|
2023-03-14 20:21:41 -04:00
|
|
|
messageId: userMessageId,
|
|
|
|
|
sender: 'User',
|
|
|
|
|
text,
|
2023-03-13 12:35:55 +08:00
|
|
|
parentMessageId: userParentMessageId,
|
2023-03-14 20:21:41 -04:00
|
|
|
conversationId,
|
|
|
|
|
isCreatedByUser: true
|
|
|
|
|
};
|
2023-02-25 09:04:32 -05:00
|
|
|
|
2023-03-31 03:22:57 +08:00
|
|
|
// build endpoint option
|
2023-04-05 02:29:11 +08:00
|
|
|
let endpointOption = {};
|
|
|
|
|
if (req.body?.jailbreak)
|
|
|
|
|
endpointOption = {
|
2023-04-07 23:13:13 +08:00
|
|
|
jailbreak: req.body?.jailbreak ?? false,
|
|
|
|
|
jailbreakConversationId: req.body?.jailbreakConversationId ?? null,
|
|
|
|
|
systemMessage: req.body?.systemMessage ?? null,
|
|
|
|
|
context: req.body?.context ?? null,
|
2023-05-21 12:43:06 -04:00
|
|
|
toneStyle: req.body?.toneStyle ?? 'creative',
|
2023-04-10 00:41:34 +08:00
|
|
|
token: req.body?.token ?? null
|
2023-04-05 02:29:11 +08:00
|
|
|
};
|
|
|
|
|
else
|
|
|
|
|
endpointOption = {
|
2023-04-07 23:13:13 +08:00
|
|
|
jailbreak: req.body?.jailbreak ?? false,
|
|
|
|
|
systemMessage: req.body?.systemMessage ?? null,
|
|
|
|
|
context: req.body?.context ?? null,
|
|
|
|
|
conversationSignature: req.body?.conversationSignature ?? null,
|
|
|
|
|
clientId: req.body?.clientId ?? null,
|
|
|
|
|
invocationId: req.body?.invocationId ?? null,
|
2023-05-21 12:43:06 -04:00
|
|
|
toneStyle: req.body?.toneStyle ?? 'creative',
|
2023-04-10 00:41:34 +08:00
|
|
|
token: req.body?.token ?? null
|
2023-04-05 02:29:11 +08:00
|
|
|
};
|
2023-03-31 03:22:57 +08:00
|
|
|
|
2023-03-14 20:21:41 -04:00
|
|
|
console.log('ask log', {
|
2023-03-31 03:22:57 +08:00
|
|
|
userMessage,
|
|
|
|
|
endpointOption,
|
|
|
|
|
conversationId
|
2023-03-13 12:35:55 +08:00
|
|
|
});
|
|
|
|
|
|
2023-03-17 02:08:03 +08:00
|
|
|
if (!overrideParentMessageId) {
|
2023-04-05 02:29:11 +08:00
|
|
|
await saveMessage(userMessage);
|
feat: Auth and User System (#205)
* server-side JWT auth implementation
* move oauth routes and strategies, fix bugs
* backend modifications for wiring up the frontend login and reg forms
* Add frontend data services for login and registration
* Add login and registration forms
* Implment auth context, functional client side auth
* protect routes with jwt auth
* finish local strategy (using local storage)
* Start setting up google auth
* disable token refresh, remove old auth middleware
* refactor client, add ApiErrorBoundary context
* disable google and facebook strategies
* fix: fix presets not displaying specific to user
* fix: fix issue with browser refresh
* fix: casing issue with User.js (#11)
* delete user.js to be renamed
* fix: fix casing issue with User.js
* comment out api error watcher temporarily
* fix: issue with api error watcher (#12)
* delete user.js to be renamed
* fix: fix casing issue with User.js
* comment out api error watcher temporarily
* feat: add google auth social login
* fix: make google login url dynamic based on dev/prod
* fix: bug where UI is briefly displayed before redirecting to login
* fix: fix cookie expires value for local auth
* Update README.md
* Update LOCAL_INSTALL structure
* Add local testing instructions
* Only load google strategy if client id and secret are provided
* Update .env.example files with new params
* fix issue with not redirecting to register form
* only show google login button if value is set in .env
* cleanup log messages
* Add label to button for google login on login form
* doc: fix client/server url values in .env.example
* feat: add error message details to registration failure
* Restore preventing paste on confirm password
* auto-login user after registering
* feat: forgot password (#24)
* make login/reg pages look like openai's
* add password reset data services
* new form designs similar to openai, add password reset pages
* add api's for password reset
* email utils for password reset
* remove bcrypt salt rounds from process.env
* refactor: restructure api auth code, consolidate routes (#25)
* add api's for password reset
* remove bcrypt salt rounds from process.env
* refactor: consolidate auth routes, use controller pattern
* refactor: code cleanup
* feat: migrate data to first user (#26)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes after refactor (#27)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: issue with auto-login when logging out then logging in with new browser window (#28)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: fix issue with auto-login in new tab
* doc: Update README and .env.example files with user system information (#29)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: fix issue with auto-login in new tab
* doc: update README and .env.example files
* Fixup: LOCAL_INSTALL.md PS instructions (#200) (#30)
Co-authored-by: alfredo-f <alfredo.fomitchenko@mail.polimi.it>
* feat: send user with completion to protect against abuse (#31)
* Fixup: LOCAL_INSTALL.md PS instructions (#200)
* server-side JWT auth implementation
* move oauth routes and strategies, fix bugs
* backend modifications for wiring up the frontend login and reg forms
* Add frontend data services for login and registration
* Add login and registration forms
* Implment auth context, functional client side auth
* protect routes with jwt auth
* finish local strategy (using local storage)
* Start setting up google auth
* disable token refresh, remove old auth middleware
* refactor client, add ApiErrorBoundary context
* disable google and facebook strategies
* fix: fix presets not displaying specific to user
* fix: fix issue with browser refresh
* fix: casing issue with User.js (#11)
* delete user.js to be renamed
* fix: fix casing issue with User.js
* comment out api error watcher temporarily
* feat: add google auth social login
* fix: make google login url dynamic based on dev/prod
* fix: bug where UI is briefly displayed before redirecting to login
* fix: fix cookie expires value for local auth
* Only load google strategy if client id and secret are provided
* Update .env.example files with new params
* fix issue with not redirecting to register form
* only show google login button if value is set in .env
* cleanup log messages
* Add label to button for google login on login form
* doc: fix client/server url values in .env.example
* feat: add error message details to registration failure
* Restore preventing paste on confirm password
* auto-login user after registering
* feat: forgot password (#24)
* make login/reg pages look like openai's
* add password reset data services
* new form designs similar to openai, add password reset pages
* add api's for password reset
* email utils for password reset
* remove bcrypt salt rounds from process.env
* refactor: restructure api auth code, consolidate routes (#25)
* add api's for password reset
* remove bcrypt salt rounds from process.env
* refactor: consolidate auth routes, use controller pattern
* refactor: code cleanup
* feat: migrate data to first user (#26)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes after refactor (#27)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: issue with auto-login when logging out then logging in with new browser window (#28)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: fix issue with auto-login in new tab
* doc: Update README and .env.example files with user system information (#29)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: fix issue with auto-login in new tab
* doc: update README and .env.example files
* Send user id to openai to protect against abuse
* add meilisearch to gitignore
* Remove webpack
---------
Co-authored-by: alfredo-f <alfredo.fomitchenko@mail.polimi.it>
---------
Co-authored-by: Danny Avila <110412045+danny-avila@users.noreply.github.com>
Co-authored-by: Alfredo Fomitchenko <alfredo.fomitchenko@mail.polimi.it>
2023-05-07 10:04:51 -07:00
|
|
|
await saveConvo(req.user.id, {
|
2023-03-31 04:22:16 +08:00
|
|
|
...userMessage,
|
|
|
|
|
...endpointOption,
|
|
|
|
|
conversationId,
|
|
|
|
|
endpoint
|
|
|
|
|
});
|
2023-03-17 02:08:03 +08:00
|
|
|
}
|
2023-03-15 00:54:50 +08:00
|
|
|
|
2023-04-04 12:53:41 -04:00
|
|
|
// eslint-disable-next-line no-use-before-define
|
2023-03-15 00:54:50 +08:00
|
|
|
return await ask({
|
|
|
|
|
isNewConversation,
|
2023-03-14 20:21:41 -04:00
|
|
|
userMessage,
|
2023-03-31 03:22:57 +08:00
|
|
|
endpointOption,
|
|
|
|
|
conversationId,
|
2023-03-15 00:54:50 +08:00
|
|
|
preSendRequest: true,
|
2023-03-17 02:08:03 +08:00
|
|
|
overrideParentMessageId,
|
2023-03-14 20:21:41 -04:00
|
|
|
req,
|
|
|
|
|
res
|
2023-03-15 00:54:50 +08:00
|
|
|
});
|
2023-03-14 20:21:41 -04:00
|
|
|
});
|
2023-03-15 00:54:50 +08:00
|
|
|
|
2023-03-14 20:21:41 -04:00
|
|
|
const ask = async ({
|
2023-03-15 00:54:50 +08:00
|
|
|
isNewConversation,
|
2023-03-14 20:21:41 -04:00
|
|
|
userMessage,
|
2023-03-31 03:22:57 +08:00
|
|
|
endpointOption,
|
|
|
|
|
conversationId,
|
2023-03-15 00:54:50 +08:00
|
|
|
preSendRequest = true,
|
2023-03-31 03:22:57 +08:00
|
|
|
overrideParentMessageId = null,
|
2023-03-14 20:21:41 -04:00
|
|
|
req,
|
|
|
|
|
res
|
2023-03-15 00:54:50 +08:00
|
|
|
}) => {
|
2023-03-31 03:22:57 +08:00
|
|
|
let { text, parentMessageId: userParentMessageId, messageId: userMessageId } = userMessage;
|
2023-03-15 00:54:50 +08:00
|
|
|
|
2023-04-11 03:26:38 +08:00
|
|
|
let responseMessageId = crypto.randomUUID();
|
|
|
|
|
|
2023-02-25 09:04:32 -05:00
|
|
|
res.writeHead(200, {
|
|
|
|
|
Connection: 'keep-alive',
|
|
|
|
|
'Content-Type': 'text/event-stream',
|
|
|
|
|
'Cache-Control': 'no-cache, no-transform',
|
|
|
|
|
'Access-Control-Allow-Origin': '*',
|
|
|
|
|
'X-Accel-Buffering': 'no'
|
|
|
|
|
});
|
|
|
|
|
|
2023-03-14 20:21:41 -04:00
|
|
|
if (preSendRequest) sendMessage(res, { message: userMessage, created: true });
|
2023-03-13 13:11:53 +08:00
|
|
|
|
2023-02-25 09:04:32 -05:00
|
|
|
try {
|
2023-04-11 03:26:38 +08:00
|
|
|
let lastSavedTimestamp = 0;
|
2023-05-21 12:43:06 -04:00
|
|
|
const { onProgress: progressCallback } = createOnProgress({
|
2023-04-11 03:26:38 +08:00
|
|
|
onProgress: ({ text }) => {
|
|
|
|
|
const currentTimestamp = Date.now();
|
|
|
|
|
if (currentTimestamp - lastSavedTimestamp > 500) {
|
|
|
|
|
lastSavedTimestamp = currentTimestamp;
|
|
|
|
|
saveMessage({
|
|
|
|
|
messageId: responseMessageId,
|
|
|
|
|
sender: endpointOption?.jailbreak ? 'Sydney' : 'BingAI',
|
|
|
|
|
conversationId,
|
|
|
|
|
parentMessageId: overrideParentMessageId || userMessageId,
|
|
|
|
|
text: text,
|
|
|
|
|
unfinished: true,
|
|
|
|
|
cancelled: false,
|
|
|
|
|
error: false
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2023-03-17 03:13:42 +08:00
|
|
|
const abortController = new AbortController();
|
2023-05-26 14:32:13 -04:00
|
|
|
let bingConversationId = null;
|
|
|
|
|
if (!isNewConversation) {
|
|
|
|
|
const convo = await getConvo(req.user.id, conversationId);
|
|
|
|
|
bingConversationId = convo.bingConversationId;
|
|
|
|
|
}
|
2023-02-25 09:04:32 -05:00
|
|
|
let response = await askBing({
|
|
|
|
|
text,
|
2023-03-31 03:22:57 +08:00
|
|
|
parentMessageId: userParentMessageId,
|
2023-05-26 14:32:13 -04:00
|
|
|
conversationId: bingConversationId ?? conversationId,
|
2023-03-31 03:22:57 +08:00
|
|
|
...endpointOption,
|
|
|
|
|
onProgress: progressCallback.call(null, {
|
2023-03-14 20:21:41 -04:00
|
|
|
res,
|
|
|
|
|
text,
|
|
|
|
|
parentMessageId: overrideParentMessageId || userMessageId
|
|
|
|
|
}),
|
2023-03-17 03:13:42 +08:00
|
|
|
abortController
|
2023-02-25 09:04:32 -05:00
|
|
|
});
|
|
|
|
|
|
2023-03-15 00:54:50 +08:00
|
|
|
console.log('BING RESPONSE', response);
|
2023-02-25 09:04:32 -05:00
|
|
|
|
2023-04-07 23:13:13 +08:00
|
|
|
const newConversationId = endpointOption?.jailbreak
|
|
|
|
|
? response.jailbreakConversationId
|
|
|
|
|
: response.conversationId || conversationId;
|
2023-05-26 14:32:13 -04:00
|
|
|
const newUserMessageId =
|
2023-05-18 11:09:31 -07:00
|
|
|
response.parentMessageId || response.details.requestId || userMessageId;
|
2023-04-07 23:13:13 +08:00
|
|
|
const newResponseMessageId = response.messageId || response.details.messageId;
|
|
|
|
|
|
2023-04-05 02:29:11 +08:00
|
|
|
// STEP1 generate response message
|
2023-05-18 11:09:31 -07:00
|
|
|
response.text =
|
|
|
|
|
response.response || response.details.spokenText || '**Bing refused to answer.**';
|
2023-04-05 02:29:11 +08:00
|
|
|
|
|
|
|
|
let responseMessage = {
|
2023-05-26 14:32:13 -04:00
|
|
|
conversationId,
|
|
|
|
|
bingConversationId: newConversationId,
|
2023-04-11 03:26:38 +08:00
|
|
|
messageId: responseMessageId,
|
|
|
|
|
newMessageId: newResponseMessageId,
|
2023-05-26 14:32:13 -04:00
|
|
|
parentMessageId: overrideParentMessageId || newUserMessageId,
|
2023-04-07 23:13:13 +08:00
|
|
|
sender: endpointOption?.jailbreak ? 'Sydney' : 'BingAI',
|
2023-04-05 02:29:11 +08:00
|
|
|
text: await handleText(response, true),
|
2023-04-11 03:26:38 +08:00
|
|
|
suggestions:
|
2023-05-18 11:09:31 -07:00
|
|
|
response.details.suggestedResponses &&
|
2023-05-18 11:44:07 -07:00
|
|
|
response.details.suggestedResponses.map((s) => s.text),
|
2023-04-11 03:26:38 +08:00
|
|
|
unfinished: false,
|
|
|
|
|
cancelled: false,
|
|
|
|
|
error: false
|
2023-04-05 02:29:11 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await saveMessage(responseMessage);
|
2023-04-11 03:26:38 +08:00
|
|
|
responseMessage.messageId = newResponseMessageId;
|
2023-04-05 02:29:11 +08:00
|
|
|
|
2023-05-26 14:32:13 -04:00
|
|
|
let conversationUpdate = { conversationId, bingConversationId: newConversationId, endpoint: 'bingAI' };
|
2023-04-05 02:29:11 +08:00
|
|
|
|
|
|
|
|
if (endpointOption?.jailbreak) {
|
|
|
|
|
conversationUpdate.jailbreak = true;
|
|
|
|
|
conversationUpdate.jailbreakConversationId = response.jailbreakConversationId;
|
|
|
|
|
} else {
|
|
|
|
|
conversationUpdate.jailbreak = false;
|
|
|
|
|
conversationUpdate.conversationSignature = response.conversationSignature;
|
|
|
|
|
conversationUpdate.clientId = response.clientId;
|
|
|
|
|
conversationUpdate.invocationId = response.invocationId;
|
|
|
|
|
}
|
|
|
|
|
|
feat: Auth and User System (#205)
* server-side JWT auth implementation
* move oauth routes and strategies, fix bugs
* backend modifications for wiring up the frontend login and reg forms
* Add frontend data services for login and registration
* Add login and registration forms
* Implment auth context, functional client side auth
* protect routes with jwt auth
* finish local strategy (using local storage)
* Start setting up google auth
* disable token refresh, remove old auth middleware
* refactor client, add ApiErrorBoundary context
* disable google and facebook strategies
* fix: fix presets not displaying specific to user
* fix: fix issue with browser refresh
* fix: casing issue with User.js (#11)
* delete user.js to be renamed
* fix: fix casing issue with User.js
* comment out api error watcher temporarily
* fix: issue with api error watcher (#12)
* delete user.js to be renamed
* fix: fix casing issue with User.js
* comment out api error watcher temporarily
* feat: add google auth social login
* fix: make google login url dynamic based on dev/prod
* fix: bug where UI is briefly displayed before redirecting to login
* fix: fix cookie expires value for local auth
* Update README.md
* Update LOCAL_INSTALL structure
* Add local testing instructions
* Only load google strategy if client id and secret are provided
* Update .env.example files with new params
* fix issue with not redirecting to register form
* only show google login button if value is set in .env
* cleanup log messages
* Add label to button for google login on login form
* doc: fix client/server url values in .env.example
* feat: add error message details to registration failure
* Restore preventing paste on confirm password
* auto-login user after registering
* feat: forgot password (#24)
* make login/reg pages look like openai's
* add password reset data services
* new form designs similar to openai, add password reset pages
* add api's for password reset
* email utils for password reset
* remove bcrypt salt rounds from process.env
* refactor: restructure api auth code, consolidate routes (#25)
* add api's for password reset
* remove bcrypt salt rounds from process.env
* refactor: consolidate auth routes, use controller pattern
* refactor: code cleanup
* feat: migrate data to first user (#26)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes after refactor (#27)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: issue with auto-login when logging out then logging in with new browser window (#28)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: fix issue with auto-login in new tab
* doc: Update README and .env.example files with user system information (#29)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: fix issue with auto-login in new tab
* doc: update README and .env.example files
* Fixup: LOCAL_INSTALL.md PS instructions (#200) (#30)
Co-authored-by: alfredo-f <alfredo.fomitchenko@mail.polimi.it>
* feat: send user with completion to protect against abuse (#31)
* Fixup: LOCAL_INSTALL.md PS instructions (#200)
* server-side JWT auth implementation
* move oauth routes and strategies, fix bugs
* backend modifications for wiring up the frontend login and reg forms
* Add frontend data services for login and registration
* Add login and registration forms
* Implment auth context, functional client side auth
* protect routes with jwt auth
* finish local strategy (using local storage)
* Start setting up google auth
* disable token refresh, remove old auth middleware
* refactor client, add ApiErrorBoundary context
* disable google and facebook strategies
* fix: fix presets not displaying specific to user
* fix: fix issue with browser refresh
* fix: casing issue with User.js (#11)
* delete user.js to be renamed
* fix: fix casing issue with User.js
* comment out api error watcher temporarily
* feat: add google auth social login
* fix: make google login url dynamic based on dev/prod
* fix: bug where UI is briefly displayed before redirecting to login
* fix: fix cookie expires value for local auth
* Only load google strategy if client id and secret are provided
* Update .env.example files with new params
* fix issue with not redirecting to register form
* only show google login button if value is set in .env
* cleanup log messages
* Add label to button for google login on login form
* doc: fix client/server url values in .env.example
* feat: add error message details to registration failure
* Restore preventing paste on confirm password
* auto-login user after registering
* feat: forgot password (#24)
* make login/reg pages look like openai's
* add password reset data services
* new form designs similar to openai, add password reset pages
* add api's for password reset
* email utils for password reset
* remove bcrypt salt rounds from process.env
* refactor: restructure api auth code, consolidate routes (#25)
* add api's for password reset
* remove bcrypt salt rounds from process.env
* refactor: consolidate auth routes, use controller pattern
* refactor: code cleanup
* feat: migrate data to first user (#26)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes after refactor (#27)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: issue with auto-login when logging out then logging in with new browser window (#28)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: fix issue with auto-login in new tab
* doc: Update README and .env.example files with user system information (#29)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: fix issue with auto-login in new tab
* doc: update README and .env.example files
* Send user id to openai to protect against abuse
* add meilisearch to gitignore
* Remove webpack
---------
Co-authored-by: alfredo-f <alfredo.fomitchenko@mail.polimi.it>
---------
Co-authored-by: Danny Avila <110412045+danny-avila@users.noreply.github.com>
Co-authored-by: Alfredo Fomitchenko <alfredo.fomitchenko@mail.polimi.it>
2023-05-07 10:04:51 -07:00
|
|
|
await saveConvo(req.user.id, conversationUpdate);
|
2023-05-26 14:32:13 -04:00
|
|
|
userMessage.messageId = newUserMessageId;
|
2023-04-04 01:10:50 +08:00
|
|
|
|
|
|
|
|
// If response has parentMessageId, the fake userMessage.messageId should be updated to the real one.
|
2023-04-07 23:13:13 +08:00
|
|
|
if (!overrideParentMessageId)
|
2023-05-18 11:09:31 -07:00
|
|
|
await saveMessage({
|
|
|
|
|
...userMessage,
|
|
|
|
|
messageId: userMessageId,
|
2023-05-26 14:32:13 -04:00
|
|
|
newMessageId: newUserMessageId
|
2023-05-18 11:09:31 -07:00
|
|
|
});
|
2023-05-26 14:32:13 -04:00
|
|
|
userMessageId = newUserMessageId;
|
2023-03-14 01:24:43 +08:00
|
|
|
|
2023-03-13 12:35:55 +08:00
|
|
|
sendMessage(res, {
|
feat: Auth and User System (#205)
* server-side JWT auth implementation
* move oauth routes and strategies, fix bugs
* backend modifications for wiring up the frontend login and reg forms
* Add frontend data services for login and registration
* Add login and registration forms
* Implment auth context, functional client side auth
* protect routes with jwt auth
* finish local strategy (using local storage)
* Start setting up google auth
* disable token refresh, remove old auth middleware
* refactor client, add ApiErrorBoundary context
* disable google and facebook strategies
* fix: fix presets not displaying specific to user
* fix: fix issue with browser refresh
* fix: casing issue with User.js (#11)
* delete user.js to be renamed
* fix: fix casing issue with User.js
* comment out api error watcher temporarily
* fix: issue with api error watcher (#12)
* delete user.js to be renamed
* fix: fix casing issue with User.js
* comment out api error watcher temporarily
* feat: add google auth social login
* fix: make google login url dynamic based on dev/prod
* fix: bug where UI is briefly displayed before redirecting to login
* fix: fix cookie expires value for local auth
* Update README.md
* Update LOCAL_INSTALL structure
* Add local testing instructions
* Only load google strategy if client id and secret are provided
* Update .env.example files with new params
* fix issue with not redirecting to register form
* only show google login button if value is set in .env
* cleanup log messages
* Add label to button for google login on login form
* doc: fix client/server url values in .env.example
* feat: add error message details to registration failure
* Restore preventing paste on confirm password
* auto-login user after registering
* feat: forgot password (#24)
* make login/reg pages look like openai's
* add password reset data services
* new form designs similar to openai, add password reset pages
* add api's for password reset
* email utils for password reset
* remove bcrypt salt rounds from process.env
* refactor: restructure api auth code, consolidate routes (#25)
* add api's for password reset
* remove bcrypt salt rounds from process.env
* refactor: consolidate auth routes, use controller pattern
* refactor: code cleanup
* feat: migrate data to first user (#26)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes after refactor (#27)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: issue with auto-login when logging out then logging in with new browser window (#28)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: fix issue with auto-login in new tab
* doc: Update README and .env.example files with user system information (#29)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: fix issue with auto-login in new tab
* doc: update README and .env.example files
* Fixup: LOCAL_INSTALL.md PS instructions (#200) (#30)
Co-authored-by: alfredo-f <alfredo.fomitchenko@mail.polimi.it>
* feat: send user with completion to protect against abuse (#31)
* Fixup: LOCAL_INSTALL.md PS instructions (#200)
* server-side JWT auth implementation
* move oauth routes and strategies, fix bugs
* backend modifications for wiring up the frontend login and reg forms
* Add frontend data services for login and registration
* Add login and registration forms
* Implment auth context, functional client side auth
* protect routes with jwt auth
* finish local strategy (using local storage)
* Start setting up google auth
* disable token refresh, remove old auth middleware
* refactor client, add ApiErrorBoundary context
* disable google and facebook strategies
* fix: fix presets not displaying specific to user
* fix: fix issue with browser refresh
* fix: casing issue with User.js (#11)
* delete user.js to be renamed
* fix: fix casing issue with User.js
* comment out api error watcher temporarily
* feat: add google auth social login
* fix: make google login url dynamic based on dev/prod
* fix: bug where UI is briefly displayed before redirecting to login
* fix: fix cookie expires value for local auth
* Only load google strategy if client id and secret are provided
* Update .env.example files with new params
* fix issue with not redirecting to register form
* only show google login button if value is set in .env
* cleanup log messages
* Add label to button for google login on login form
* doc: fix client/server url values in .env.example
* feat: add error message details to registration failure
* Restore preventing paste on confirm password
* auto-login user after registering
* feat: forgot password (#24)
* make login/reg pages look like openai's
* add password reset data services
* new form designs similar to openai, add password reset pages
* add api's for password reset
* email utils for password reset
* remove bcrypt salt rounds from process.env
* refactor: restructure api auth code, consolidate routes (#25)
* add api's for password reset
* remove bcrypt salt rounds from process.env
* refactor: consolidate auth routes, use controller pattern
* refactor: code cleanup
* feat: migrate data to first user (#26)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes after refactor (#27)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: issue with auto-login when logging out then logging in with new browser window (#28)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: fix issue with auto-login in new tab
* doc: Update README and .env.example files with user system information (#29)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: fix issue with auto-login in new tab
* doc: update README and .env.example files
* Send user id to openai to protect against abuse
* add meilisearch to gitignore
* Remove webpack
---------
Co-authored-by: alfredo-f <alfredo.fomitchenko@mail.polimi.it>
---------
Co-authored-by: Danny Avila <110412045+danny-avila@users.noreply.github.com>
Co-authored-by: Alfredo Fomitchenko <alfredo.fomitchenko@mail.polimi.it>
2023-05-07 10:04:51 -07:00
|
|
|
title: await getConvoTitle(req.user.id, conversationId),
|
2023-03-14 20:21:41 -04:00
|
|
|
final: true,
|
feat: Auth and User System (#205)
* server-side JWT auth implementation
* move oauth routes and strategies, fix bugs
* backend modifications for wiring up the frontend login and reg forms
* Add frontend data services for login and registration
* Add login and registration forms
* Implment auth context, functional client side auth
* protect routes with jwt auth
* finish local strategy (using local storage)
* Start setting up google auth
* disable token refresh, remove old auth middleware
* refactor client, add ApiErrorBoundary context
* disable google and facebook strategies
* fix: fix presets not displaying specific to user
* fix: fix issue with browser refresh
* fix: casing issue with User.js (#11)
* delete user.js to be renamed
* fix: fix casing issue with User.js
* comment out api error watcher temporarily
* fix: issue with api error watcher (#12)
* delete user.js to be renamed
* fix: fix casing issue with User.js
* comment out api error watcher temporarily
* feat: add google auth social login
* fix: make google login url dynamic based on dev/prod
* fix: bug where UI is briefly displayed before redirecting to login
* fix: fix cookie expires value for local auth
* Update README.md
* Update LOCAL_INSTALL structure
* Add local testing instructions
* Only load google strategy if client id and secret are provided
* Update .env.example files with new params
* fix issue with not redirecting to register form
* only show google login button if value is set in .env
* cleanup log messages
* Add label to button for google login on login form
* doc: fix client/server url values in .env.example
* feat: add error message details to registration failure
* Restore preventing paste on confirm password
* auto-login user after registering
* feat: forgot password (#24)
* make login/reg pages look like openai's
* add password reset data services
* new form designs similar to openai, add password reset pages
* add api's for password reset
* email utils for password reset
* remove bcrypt salt rounds from process.env
* refactor: restructure api auth code, consolidate routes (#25)
* add api's for password reset
* remove bcrypt salt rounds from process.env
* refactor: consolidate auth routes, use controller pattern
* refactor: code cleanup
* feat: migrate data to first user (#26)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes after refactor (#27)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: issue with auto-login when logging out then logging in with new browser window (#28)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: fix issue with auto-login in new tab
* doc: Update README and .env.example files with user system information (#29)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: fix issue with auto-login in new tab
* doc: update README and .env.example files
* Fixup: LOCAL_INSTALL.md PS instructions (#200) (#30)
Co-authored-by: alfredo-f <alfredo.fomitchenko@mail.polimi.it>
* feat: send user with completion to protect against abuse (#31)
* Fixup: LOCAL_INSTALL.md PS instructions (#200)
* server-side JWT auth implementation
* move oauth routes and strategies, fix bugs
* backend modifications for wiring up the frontend login and reg forms
* Add frontend data services for login and registration
* Add login and registration forms
* Implment auth context, functional client side auth
* protect routes with jwt auth
* finish local strategy (using local storage)
* Start setting up google auth
* disable token refresh, remove old auth middleware
* refactor client, add ApiErrorBoundary context
* disable google and facebook strategies
* fix: fix presets not displaying specific to user
* fix: fix issue with browser refresh
* fix: casing issue with User.js (#11)
* delete user.js to be renamed
* fix: fix casing issue with User.js
* comment out api error watcher temporarily
* feat: add google auth social login
* fix: make google login url dynamic based on dev/prod
* fix: bug where UI is briefly displayed before redirecting to login
* fix: fix cookie expires value for local auth
* Only load google strategy if client id and secret are provided
* Update .env.example files with new params
* fix issue with not redirecting to register form
* only show google login button if value is set in .env
* cleanup log messages
* Add label to button for google login on login form
* doc: fix client/server url values in .env.example
* feat: add error message details to registration failure
* Restore preventing paste on confirm password
* auto-login user after registering
* feat: forgot password (#24)
* make login/reg pages look like openai's
* add password reset data services
* new form designs similar to openai, add password reset pages
* add api's for password reset
* email utils for password reset
* remove bcrypt salt rounds from process.env
* refactor: restructure api auth code, consolidate routes (#25)
* add api's for password reset
* remove bcrypt salt rounds from process.env
* refactor: consolidate auth routes, use controller pattern
* refactor: code cleanup
* feat: migrate data to first user (#26)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes after refactor (#27)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: issue with auto-login when logging out then logging in with new browser window (#28)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: fix issue with auto-login in new tab
* doc: Update README and .env.example files with user system information (#29)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: fix issue with auto-login in new tab
* doc: update README and .env.example files
* Send user id to openai to protect against abuse
* add meilisearch to gitignore
* Remove webpack
---------
Co-authored-by: alfredo-f <alfredo.fomitchenko@mail.polimi.it>
---------
Co-authored-by: Danny Avila <110412045+danny-avila@users.noreply.github.com>
Co-authored-by: Alfredo Fomitchenko <alfredo.fomitchenko@mail.polimi.it>
2023-05-07 10:04:51 -07:00
|
|
|
conversation: await getConvo(req.user.id, conversationId),
|
2023-03-14 20:21:41 -04:00
|
|
|
requestMessage: userMessage,
|
2023-04-05 02:29:11 +08:00
|
|
|
responseMessage: responseMessage
|
2023-03-13 12:35:55 +08:00
|
|
|
});
|
2023-02-25 09:04:32 -05:00
|
|
|
res.end();
|
2023-03-14 11:42:35 +08:00
|
|
|
|
2023-03-15 00:54:50 +08:00
|
|
|
if (userParentMessageId == '00000000-0000-0000-0000-000000000000') {
|
2023-05-18 11:09:31 -07:00
|
|
|
const title = await titleConvo({
|
|
|
|
|
endpoint: endpointOption?.endpoint,
|
|
|
|
|
text,
|
|
|
|
|
response: responseMessage
|
|
|
|
|
});
|
2023-03-31 03:22:57 +08:00
|
|
|
|
feat: Auth and User System (#205)
* server-side JWT auth implementation
* move oauth routes and strategies, fix bugs
* backend modifications for wiring up the frontend login and reg forms
* Add frontend data services for login and registration
* Add login and registration forms
* Implment auth context, functional client side auth
* protect routes with jwt auth
* finish local strategy (using local storage)
* Start setting up google auth
* disable token refresh, remove old auth middleware
* refactor client, add ApiErrorBoundary context
* disable google and facebook strategies
* fix: fix presets not displaying specific to user
* fix: fix issue with browser refresh
* fix: casing issue with User.js (#11)
* delete user.js to be renamed
* fix: fix casing issue with User.js
* comment out api error watcher temporarily
* fix: issue with api error watcher (#12)
* delete user.js to be renamed
* fix: fix casing issue with User.js
* comment out api error watcher temporarily
* feat: add google auth social login
* fix: make google login url dynamic based on dev/prod
* fix: bug where UI is briefly displayed before redirecting to login
* fix: fix cookie expires value for local auth
* Update README.md
* Update LOCAL_INSTALL structure
* Add local testing instructions
* Only load google strategy if client id and secret are provided
* Update .env.example files with new params
* fix issue with not redirecting to register form
* only show google login button if value is set in .env
* cleanup log messages
* Add label to button for google login on login form
* doc: fix client/server url values in .env.example
* feat: add error message details to registration failure
* Restore preventing paste on confirm password
* auto-login user after registering
* feat: forgot password (#24)
* make login/reg pages look like openai's
* add password reset data services
* new form designs similar to openai, add password reset pages
* add api's for password reset
* email utils for password reset
* remove bcrypt salt rounds from process.env
* refactor: restructure api auth code, consolidate routes (#25)
* add api's for password reset
* remove bcrypt salt rounds from process.env
* refactor: consolidate auth routes, use controller pattern
* refactor: code cleanup
* feat: migrate data to first user (#26)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes after refactor (#27)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: issue with auto-login when logging out then logging in with new browser window (#28)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: fix issue with auto-login in new tab
* doc: Update README and .env.example files with user system information (#29)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: fix issue with auto-login in new tab
* doc: update README and .env.example files
* Fixup: LOCAL_INSTALL.md PS instructions (#200) (#30)
Co-authored-by: alfredo-f <alfredo.fomitchenko@mail.polimi.it>
* feat: send user with completion to protect against abuse (#31)
* Fixup: LOCAL_INSTALL.md PS instructions (#200)
* server-side JWT auth implementation
* move oauth routes and strategies, fix bugs
* backend modifications for wiring up the frontend login and reg forms
* Add frontend data services for login and registration
* Add login and registration forms
* Implment auth context, functional client side auth
* protect routes with jwt auth
* finish local strategy (using local storage)
* Start setting up google auth
* disable token refresh, remove old auth middleware
* refactor client, add ApiErrorBoundary context
* disable google and facebook strategies
* fix: fix presets not displaying specific to user
* fix: fix issue with browser refresh
* fix: casing issue with User.js (#11)
* delete user.js to be renamed
* fix: fix casing issue with User.js
* comment out api error watcher temporarily
* feat: add google auth social login
* fix: make google login url dynamic based on dev/prod
* fix: bug where UI is briefly displayed before redirecting to login
* fix: fix cookie expires value for local auth
* Only load google strategy if client id and secret are provided
* Update .env.example files with new params
* fix issue with not redirecting to register form
* only show google login button if value is set in .env
* cleanup log messages
* Add label to button for google login on login form
* doc: fix client/server url values in .env.example
* feat: add error message details to registration failure
* Restore preventing paste on confirm password
* auto-login user after registering
* feat: forgot password (#24)
* make login/reg pages look like openai's
* add password reset data services
* new form designs similar to openai, add password reset pages
* add api's for password reset
* email utils for password reset
* remove bcrypt salt rounds from process.env
* refactor: restructure api auth code, consolidate routes (#25)
* add api's for password reset
* remove bcrypt salt rounds from process.env
* refactor: consolidate auth routes, use controller pattern
* refactor: code cleanup
* feat: migrate data to first user (#26)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes after refactor (#27)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: issue with auto-login when logging out then logging in with new browser window (#28)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: fix issue with auto-login in new tab
* doc: Update README and .env.example files with user system information (#29)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: fix issue with auto-login in new tab
* doc: update README and .env.example files
* Send user id to openai to protect against abuse
* add meilisearch to gitignore
* Remove webpack
---------
Co-authored-by: alfredo-f <alfredo.fomitchenko@mail.polimi.it>
---------
Co-authored-by: Danny Avila <110412045+danny-avila@users.noreply.github.com>
Co-authored-by: Alfredo Fomitchenko <alfredo.fomitchenko@mail.polimi.it>
2023-05-07 10:04:51 -07:00
|
|
|
await saveConvo(req.user.id, {
|
2023-03-31 03:22:57 +08:00
|
|
|
conversationId: conversationId,
|
|
|
|
|
title
|
|
|
|
|
});
|
2023-03-14 11:42:35 +08:00
|
|
|
}
|
2023-02-25 09:04:32 -05:00
|
|
|
} catch (error) {
|
|
|
|
|
console.log(error);
|
2023-03-14 20:21:41 -04:00
|
|
|
const errorMessage = {
|
2023-04-11 03:26:38 +08:00
|
|
|
messageId: responseMessageId,
|
2023-03-31 03:22:57 +08:00
|
|
|
sender: endpointOption?.jailbreak ? 'Sydney' : 'BingAI',
|
2023-03-14 20:21:41 -04:00
|
|
|
conversationId,
|
|
|
|
|
parentMessageId: overrideParentMessageId || userMessageId,
|
2023-04-11 03:26:38 +08:00
|
|
|
unfinished: false,
|
|
|
|
|
cancelled: false,
|
2023-03-14 20:21:41 -04:00
|
|
|
error: true,
|
|
|
|
|
text: error.message
|
|
|
|
|
};
|
2023-04-05 22:12:59 +08:00
|
|
|
await saveMessage(errorMessage);
|
2023-03-15 00:50:27 +08:00
|
|
|
handleError(res, errorMessage);
|
2023-02-25 09:04:32 -05:00
|
|
|
}
|
2023-03-15 00:54:50 +08:00
|
|
|
};
|
2023-02-25 09:04:32 -05:00
|
|
|
|
2023-04-07 23:13:13 +08:00
|
|
|
module.exports = router;
|