diff --git a/ee/app/assets/javascripts/ai/tanuki_bot/store/actions.js b/ee/app/assets/javascripts/ai/tanuki_bot/store/actions.js index c63754f2c6b8bba06ee1abcb2bc483128d029097..a65a1068966100cf1d432ae8aaea1a32557beab2 100644 --- a/ee/app/assets/javascripts/ai/tanuki_bot/store/actions.js +++ b/ee/app/assets/javascripts/ai/tanuki_bot/store/actions.js @@ -9,31 +9,12 @@ const proxyMessageContent = (message, propsToUpdate) => { }; }; -const parseRawContent = (msgContent) => { - try { - const parsedContent = JSON.parse(msgContent); - - // JSON.parse does not throw when parsing Strings that are coerced to primary data types, like Number or Boolean. - // JSON.parse("1") would return 1 (Number), same as JSON.parse("false"), which returns false (Boolean). - // We therefore check if the parsed response is really an Object. - // This will be solved with https://gitlab.com/gitlab-org/gitlab/-/issues/423315 when we no longer receive - // potential JSON as a string. - if (typeof parsedContent === 'object') { - return parsedContent.content; - } - } catch { - // no-op - } - return msgContent; -}; - export const addDuoChatMessage = async ({ commit }, messageData = { content: '' }) => { const { errors = [], content = '' } = messageData || {}; const msgContent = content || errors.join('; '); if (msgContent) { - const parsedContent = parseRawContent(msgContent); - const message = proxyMessageContent(messageData, { content: parsedContent }); + const message = proxyMessageContent(messageData, { content: msgContent }); if (message.role.toLowerCase() === GENIE_CHAT_MODEL_ROLES.system) { commit(types.ADD_TOOL_MESSAGE, message); diff --git a/ee/spec/frontend/ai/tanuki_bot/store/actions_spec.js b/ee/spec/frontend/ai/tanuki_bot/store/actions_spec.js index daabbf2d5b150e1d7ca0b2fc9231e6255ebcffb3..de20153593c563cac32d4306f89244450fbb463d 100644 --- a/ee/spec/frontend/ai/tanuki_bot/store/actions_spec.js +++ b/ee/spec/frontend/ai/tanuki_bot/store/actions_spec.js @@ -24,11 +24,7 @@ describe('TanukiBot Store Actions', () => { const aiContentResponse = { content, }; - const oldDocumentationResponse = { - content: JSON.stringify({ content, sources: extras.sources }), - extras, - }; - const newDocumentationResponse = { + const documentationResponse = { content, extras, }; @@ -37,8 +33,7 @@ describe('TanukiBot Store Actions', () => { messageData | expectedPayload ${aiContentResponse} | ${{ content, role: GENIE_CHAT_MODEL_ROLES.user }} ${{ ...aiContentResponse, role: GENIE_CHAT_MODEL_ROLES.assistant }} | ${{ content, role: GENIE_CHAT_MODEL_ROLES.assistant }} - ${oldDocumentationResponse} | ${{ content, extras, role: GENIE_CHAT_MODEL_ROLES.user }} - ${newDocumentationResponse} | ${{ content, extras, role: GENIE_CHAT_MODEL_ROLES.user }} + ${documentationResponse} | ${{ content, extras, role: GENIE_CHAT_MODEL_ROLES.user }} `( 'should commit the correct mutations for "$messageData" response', ({ messageData, expectedPayload }) => {