2023-07-30 10:37:25 -04:00
|
|
|
import * as t from './types';
|
2023-08-05 12:10:36 -04:00
|
|
|
import * as s from './schemas';
|
2023-07-30 10:37:25 -04:00
|
|
|
import request from './request';
|
|
|
|
|
import * as endpoints from './api-endpoints';
|
|
|
|
|
|
|
|
|
|
export function getConversations(pageNumber: string): Promise<t.TGetConversationsResponse> {
|
|
|
|
|
return request.get(endpoints.conversations(pageNumber));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function abortRequestWithMessage(
|
|
|
|
|
endpoint: string,
|
|
|
|
|
abortKey: string,
|
|
|
|
|
message: string,
|
|
|
|
|
): Promise<void> {
|
|
|
|
|
return request.post(endpoints.abortRequest(endpoint), { arg: { abortKey, message } });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function deleteConversation(payload: t.TDeleteConversationRequest) {
|
|
|
|
|
//todo: this should be a DELETE request
|
|
|
|
|
return request.post(endpoints.deleteConversation(), { arg: payload });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function clearAllConversations(): Promise<unknown> {
|
|
|
|
|
return request.post(endpoints.deleteConversation(), { arg: {} });
|
|
|
|
|
}
|
|
|
|
|
|
feat: Edit AI Messages, Edit Messages in Place (#825)
* refactor: replace lodash import with specific function import
fix(api): esm imports to cjs
* refactor(Messages.tsx): convert to TS, out-source scrollToDiv logic to a custom hook
fix(ScreenshotContext.tsx): change Ref to RefObject in ScreenshotContextType
feat(useScrollToRef.ts): add useScrollToRef hook for scrolling to a ref with throttle
fix(Chat.tsx): update import path for Messages component
fix(Search.tsx): update import path for Messages component
* chore(types.ts): add TAskProps and TOptions types
refactor(useMessageHandler.ts): use TAskFunction type for ask function signature
* refactor(Message/Content): convert to TS, move Plugin component to Content dir
* feat(MessageContent.tsx): add MessageContent component for displaying and editing message content
feat(index.ts): export MessageContent component from Messages/Content directory
* wip(Message.jsx): conversion and use of new component in progress
* refactor: convert Message.jsx to TS and fix typing/imports based on changes
* refactor: add typed props and refactor MultiMessage to TS, fix typing issues resulting from the conversion
* edit message in progress
* feat: complete edit AI message logic, refactor continue logic
* feat(middleware): add validateMessageReq middleware
feat(routes): add validation for message requests using validateMessageReq middleware
feat(routes): add create, read, update, and delete routes for messages
* feat: complete frontend logic for editing messages in place
feat(messages.js): update route for updating a specific message
- Change the route for updating a message to include the messageId in the URL
- Update the request handler to use the messageId from the request parameters and the text from the request body
- Call the updateMessage function with the updated parameters
feat(MessageContent.tsx): add functionality to update a message
- Import the useUpdateMessageMutation hook from the data provider
- Destructure the conversationId, parentMessageId, and messageId from the message object
- Create a mutation function using the useUpdateMessageMutation hook
- Implement the updateMessage function to call the mutation function with the updated message parameters
- Update the messages state to reflect the updated message text
feat(api-endpoints.ts): update messages endpoint to include messageId
- Update the messages endpoint to include the messageId as an optional parameter
feat(data-service.ts): add updateMessage function
- Implement the updateMessage function to make a PUT request to
* fix(messages.js): make updateMessage function asynchronous and await its execution
* style(EditIcon): make icon active for AI message
* feat(gptPlugins/anthropic): add edit support
* fix(validateMessageReq.js): handle case when conversationId is 'new' and return empty array
feat(Message.tsx): pass message prop to SiblingSwitch component
refactor(SiblingSwitch.tsx): convert to TS
* fix(useMessageHandler.ts): remove message from currentMessages if isContinued is true
feat(useMessageHandler.ts): add support for submission messages in setMessages
fix(useServerStream.ts): remove unnecessary conditional in setMessages
fix(useServerStream.ts): remove isContinued variable from submission
* fix(continue): switch to continued message generation when continuing an earlier branch in conversation
* fix(abortMiddleware.js): fix condition to check partialText length
chore(abortMiddleware.js): add error logging when abortMessage fails
* refactor(MessageHeader.tsx): convert to TS
fix(Plugin.tsx): add default value for className prop in Plugin component
* refactor(MultiMessage.tsx): remove commented out code
docs(MultiMessage.tsx): update comment to clarify when siblingIdx is reset
* fix(GenerationButtons): optimistic state for continue button
* fix(MessageContent.tsx): add data-testid attribute to message text editor
fix(messages.spec.ts): update waitForServerStream function to include edit endpoint check
feat(messages.spec.ts): add test case for editing messages
* fix(HoverButtons & Message & useGenerations): Refactor edit functionality and related conditions
- Update enterEdit function signature and prop
- Create and utilize hideEditButton variable
- Enhance conditions for edit button visibility and active state
- Update button event handlers
- Introduce isEditableEndpoint in useGenerations and refine continueSupported condition.
* fix(useGenerations.ts): fix condition for hideEditButton to include error and searchResult
chore(data-provider): bump version to 0.1.6
fix(types.ts): add status property to TError type
* chore: bump @dqbd/tiktoken to 1.0.7
* fix(abortMiddleware.js): add required isCreatedByUser property to the error response object
* refactor(Message.tsx): remove unnecessary props from SiblingSwitch component, as setLatestMessage is firing on every switch already
refactor(SiblingSwitch.tsx): remove unused imports and code
* chore(BaseClient.js): move console.debug statements back inside if block
2023-08-22 18:44:59 -04:00
|
|
|
export function getMessagesByConvoId(conversationId: string): Promise<s.TMessage[]> {
|
|
|
|
|
return request.get(endpoints.messages(conversationId));
|
2023-07-30 10:37:25 -04:00
|
|
|
}
|
|
|
|
|
|
2023-08-05 12:10:36 -04:00
|
|
|
export function getConversationById(id: string): Promise<s.TConversation> {
|
2023-07-30 10:37:25 -04:00
|
|
|
return request.get(endpoints.conversationById(id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function updateConversation(
|
|
|
|
|
payload: t.TUpdateConversationRequest,
|
|
|
|
|
): Promise<t.TUpdateConversationResponse> {
|
|
|
|
|
return request.post(endpoints.updateConversation(), { arg: payload });
|
|
|
|
|
}
|
|
|
|
|
|
feat: Edit AI Messages, Edit Messages in Place (#825)
* refactor: replace lodash import with specific function import
fix(api): esm imports to cjs
* refactor(Messages.tsx): convert to TS, out-source scrollToDiv logic to a custom hook
fix(ScreenshotContext.tsx): change Ref to RefObject in ScreenshotContextType
feat(useScrollToRef.ts): add useScrollToRef hook for scrolling to a ref with throttle
fix(Chat.tsx): update import path for Messages component
fix(Search.tsx): update import path for Messages component
* chore(types.ts): add TAskProps and TOptions types
refactor(useMessageHandler.ts): use TAskFunction type for ask function signature
* refactor(Message/Content): convert to TS, move Plugin component to Content dir
* feat(MessageContent.tsx): add MessageContent component for displaying and editing message content
feat(index.ts): export MessageContent component from Messages/Content directory
* wip(Message.jsx): conversion and use of new component in progress
* refactor: convert Message.jsx to TS and fix typing/imports based on changes
* refactor: add typed props and refactor MultiMessage to TS, fix typing issues resulting from the conversion
* edit message in progress
* feat: complete edit AI message logic, refactor continue logic
* feat(middleware): add validateMessageReq middleware
feat(routes): add validation for message requests using validateMessageReq middleware
feat(routes): add create, read, update, and delete routes for messages
* feat: complete frontend logic for editing messages in place
feat(messages.js): update route for updating a specific message
- Change the route for updating a message to include the messageId in the URL
- Update the request handler to use the messageId from the request parameters and the text from the request body
- Call the updateMessage function with the updated parameters
feat(MessageContent.tsx): add functionality to update a message
- Import the useUpdateMessageMutation hook from the data provider
- Destructure the conversationId, parentMessageId, and messageId from the message object
- Create a mutation function using the useUpdateMessageMutation hook
- Implement the updateMessage function to call the mutation function with the updated message parameters
- Update the messages state to reflect the updated message text
feat(api-endpoints.ts): update messages endpoint to include messageId
- Update the messages endpoint to include the messageId as an optional parameter
feat(data-service.ts): add updateMessage function
- Implement the updateMessage function to make a PUT request to
* fix(messages.js): make updateMessage function asynchronous and await its execution
* style(EditIcon): make icon active for AI message
* feat(gptPlugins/anthropic): add edit support
* fix(validateMessageReq.js): handle case when conversationId is 'new' and return empty array
feat(Message.tsx): pass message prop to SiblingSwitch component
refactor(SiblingSwitch.tsx): convert to TS
* fix(useMessageHandler.ts): remove message from currentMessages if isContinued is true
feat(useMessageHandler.ts): add support for submission messages in setMessages
fix(useServerStream.ts): remove unnecessary conditional in setMessages
fix(useServerStream.ts): remove isContinued variable from submission
* fix(continue): switch to continued message generation when continuing an earlier branch in conversation
* fix(abortMiddleware.js): fix condition to check partialText length
chore(abortMiddleware.js): add error logging when abortMessage fails
* refactor(MessageHeader.tsx): convert to TS
fix(Plugin.tsx): add default value for className prop in Plugin component
* refactor(MultiMessage.tsx): remove commented out code
docs(MultiMessage.tsx): update comment to clarify when siblingIdx is reset
* fix(GenerationButtons): optimistic state for continue button
* fix(MessageContent.tsx): add data-testid attribute to message text editor
fix(messages.spec.ts): update waitForServerStream function to include edit endpoint check
feat(messages.spec.ts): add test case for editing messages
* fix(HoverButtons & Message & useGenerations): Refactor edit functionality and related conditions
- Update enterEdit function signature and prop
- Create and utilize hideEditButton variable
- Enhance conditions for edit button visibility and active state
- Update button event handlers
- Introduce isEditableEndpoint in useGenerations and refine continueSupported condition.
* fix(useGenerations.ts): fix condition for hideEditButton to include error and searchResult
chore(data-provider): bump version to 0.1.6
fix(types.ts): add status property to TError type
* chore: bump @dqbd/tiktoken to 1.0.7
* fix(abortMiddleware.js): add required isCreatedByUser property to the error response object
* refactor(Message.tsx): remove unnecessary props from SiblingSwitch component, as setLatestMessage is firing on every switch already
refactor(SiblingSwitch.tsx): remove unused imports and code
* chore(BaseClient.js): move console.debug statements back inside if block
2023-08-22 18:44:59 -04:00
|
|
|
export function updateMessage(payload: t.TUpdateMessageRequest): Promise<unknown> {
|
|
|
|
|
const { conversationId, messageId, text } = payload;
|
|
|
|
|
if (!conversationId) {
|
|
|
|
|
throw new Error('conversationId is required');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return request.put(endpoints.messages(conversationId, messageId), { text });
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-05 12:10:36 -04:00
|
|
|
export function getPresets(): Promise<s.TPreset[]> {
|
2023-07-30 10:37:25 -04:00
|
|
|
return request.get(endpoints.presets());
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-05 12:10:36 -04:00
|
|
|
export function createPreset(payload: s.TPreset): Promise<s.TPreset[]> {
|
2023-07-30 10:37:25 -04:00
|
|
|
return request.post(endpoints.presets(), payload);
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-05 12:10:36 -04:00
|
|
|
export function updatePreset(payload: s.TPreset): Promise<s.TPreset[]> {
|
2023-07-30 10:37:25 -04:00
|
|
|
return request.post(endpoints.presets(), payload);
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-05 12:10:36 -04:00
|
|
|
export function deletePreset(arg: s.TPreset | object): Promise<s.TPreset[]> {
|
2023-07-30 10:37:25 -04:00
|
|
|
return request.post(endpoints.deletePreset(), arg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getSearchEnabled(): Promise<boolean> {
|
|
|
|
|
return request.get(endpoints.searchEnabled());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getUser(): Promise<t.TUser> {
|
|
|
|
|
return request.get(endpoints.user());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const searchConversations = async (
|
|
|
|
|
q: string,
|
|
|
|
|
pageNumber: string,
|
|
|
|
|
): Promise<t.TSearchResults> => {
|
|
|
|
|
return request.get(endpoints.search(q, pageNumber));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const getAIEndpoints = () => {
|
|
|
|
|
return request.get(endpoints.aiEndpoints());
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const updateTokenCount = (text: string) => {
|
|
|
|
|
return request.post(endpoints.tokenizer(), { arg: text });
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const login = (payload: t.TLoginUser) => {
|
|
|
|
|
return request.post(endpoints.login(), payload);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const logout = () => {
|
|
|
|
|
return request.post(endpoints.logout());
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const register = (payload: t.TRegisterUser) => {
|
|
|
|
|
return request.post(endpoints.register(), payload);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const refreshToken = () => {
|
|
|
|
|
return request.post(endpoints.refreshToken());
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const getLoginGoogle = () => {
|
|
|
|
|
return request.get(endpoints.loginGoogle());
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const requestPasswordReset = (
|
|
|
|
|
payload: t.TRequestPasswordReset,
|
|
|
|
|
): Promise<t.TRequestPasswordResetResponse> => {
|
|
|
|
|
return request.post(endpoints.requestPasswordReset(), payload);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const resetPassword = (payload: t.TResetPassword) => {
|
|
|
|
|
return request.post(endpoints.resetPassword(), payload);
|
|
|
|
|
};
|
|
|
|
|
|
2023-08-05 12:10:36 -04:00
|
|
|
export const getAvailablePlugins = (): Promise<s.TPlugin[]> => {
|
2023-07-30 10:37:25 -04:00
|
|
|
return request.get(endpoints.plugins());
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const updateUserPlugins = (payload: t.TUpdateUserPlugins) => {
|
|
|
|
|
return request.post(endpoints.userPlugins(), payload);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const getStartupConfig = (): Promise<t.TStartupConfig> => {
|
|
|
|
|
return request.get(endpoints.config());
|
|
|
|
|
};
|