Skip to content

Commit

Permalink
Merge pull request #4 from eea/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
tiberiuichim authored Aug 15, 2024
2 parents b728027 + 536fffb commit 1dadf20
Show file tree
Hide file tree
Showing 24 changed files with 1,816 additions and 7 deletions.
63 changes: 62 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,68 @@ All notable changes to this project will be documented in this file. Dates are d

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

### [0.1.2](https://github.com/eea/volto-chatbot/compare/0.1.1...0.1.2) - 13 August 2024

#### :house: Internal changes

- style: Automated code fix [eea-jenkins - [`b004b2a`](https://github.com/eea/volto-chatbot/commit/b004b2a53dd0577af755e2d8f794b82679bcb83f)]
- style: Automated code fix [eea-jenkins - [`4fd87bd`](https://github.com/eea/volto-chatbot/commit/4fd87bd39cee66bc08fb1bbec8d3458f32b7c595)]
- style: improve textarea styling, use autosize textarea - refs #270144 [kreafox - [`d9bd992`](https://github.com/eea/volto-chatbot/commit/d9bd9922796367c9b786382656b7e38e9dbd5abe)]
- style: Automated code fix [eea-jenkins - [`4afbb06`](https://github.com/eea/volto-chatbot/commit/4afbb06e70c30b5a67ceba5fadca3c6a343e1cac)]
- style: Automated code fix [eea-jenkins - [`64c7224`](https://github.com/eea/volto-chatbot/commit/64c722489293ddfebda46b87d5beda13df870eac)]
- style: add user/bot icons, improve styling - refs #270144 [kreafox - [`4d9a507`](https://github.com/eea/volto-chatbot/commit/4d9a507a09bf5b987474ca04602a230eb93951e2)]
- style: Automated code fix [eea-jenkins - [`594a313`](https://github.com/eea/volto-chatbot/commit/594a313f6c1e61b160eee46d8698fa8ab91e57db)]
- style: fix sources with long names, refs #270144 [kreafox - [`3aaafe6`](https://github.com/eea/volto-chatbot/commit/3aaafe6e82c64f0f057b8e7a61d0c066e7f842e5)]
- style: Automated code fix [eea-jenkins - [`ea192d0`](https://github.com/eea/volto-chatbot/commit/ea192d0d4ec0858af1bb115427e40d174a01094a)]
- style: Automated code fix [eea-jenkins - [`2591616`](https://github.com/eea/volto-chatbot/commit/2591616502abbffb1627076cc0593caa6010e367)]
- style: Automated code fix [eea-jenkins - [`e17c897`](https://github.com/eea/volto-chatbot/commit/e17c897f67764aa5db083952a6046c8a6b659620)]
- style: Automated code fix [eea-jenkins - [`d9f18f6`](https://github.com/eea/volto-chatbot/commit/d9f18f6ca128c1007dea24cdcc6ea419849dfbdf)]
- style: Automated code fix [eea-jenkins - [`79ad8b0`](https://github.com/eea/volto-chatbot/commit/79ad8b0a318e2e1a2b3590632c3042f77301ce90)]
- style: Automated code fix [eea-jenkins - [`6847efb`](https://github.com/eea/volto-chatbot/commit/6847efb159cfc6f0d76ae32d47bd41d53b04f24e)]

#### :hammer_and_wrench: Others

- remove log [Tiberiu Ichim - [`d49a1ab`](https://github.com/eea/volto-chatbot/commit/d49a1ab5d24924b7e7dcbe1c6cf31585e6b25c46)]
- Use message from start_mesage [Tiberiu Ichim - [`64ae9dd`](https://github.com/eea/volto-chatbot/commit/64ae9ddaf183a37338cc7eca9b958dc51b85ab7d)]
- Improve linking of docs [Tiberiu Ichim - [`9dd36f0`](https://github.com/eea/volto-chatbot/commit/9dd36f0b1b0fdc1bfc21106fb337fd5aeb1e555f)]
- Fix index of documents [Tiberiu Ichim - [`d3f3a87`](https://github.com/eea/volto-chatbot/commit/d3f3a87afef55bc3464b8ac7ca298b8e088d5b85)]
- Small style tweak [Tiberiu Ichim - [`ddac5a3`](https://github.com/eea/volto-chatbot/commit/ddac5a345782e9f2eb48c6735492b8954438d1fe)]
- refs #270144 - convert email addresses to mailto links in markdown content [kreafox - [`520cef3`](https://github.com/eea/volto-chatbot/commit/520cef39f6afae72176aa3420da214cc65d9a7bd)]
- Don't reset the submit handler [Tiberiu Ichim - [`09499e1`](https://github.com/eea/volto-chatbot/commit/09499e1ba888dabc808d01e726f5b8a6f2fdb0f2)]
- ref #270144 - rename clear button, add icon [kreafox - [`88badb9`](https://github.com/eea/volto-chatbot/commit/88badb91a77593e104fc6c96c88eeb127aa3546b)]
- ref #270144 - add clear chat button; clear input on submit [kreafox - [`b5fbd86`](https://github.com/eea/volto-chatbot/commit/b5fbd8673647212a4de4a737ab704d8e82acd316)]
- ref #270144 - sources style improvements [kreafox - [`71320e7`](https://github.com/eea/volto-chatbot/commit/71320e7413da55f5a7102d1bd3304199d5e9dc7a)]
- ref #270144 - Add loader [kreafox - [`d9dfa44`](https://github.com/eea/volto-chatbot/commit/d9dfa442d3649ea99fd45cd7fe15aa01f5c69a58)]
- Add busy indicator [Tiberiu Ichim - [`8109b0d`](https://github.com/eea/volto-chatbot/commit/8109b0d7ab4096fb95c5419eba8dfb1bc867f986)]
- Rework citations [Tiberiu Ichim - [`7607050`](https://github.com/eea/volto-chatbot/commit/76070504335989e85d2bec74611db6482adcfae4)]
- Load some remark libraries [Tiberiu Ichim - [`2800ad8`](https://github.com/eea/volto-chatbot/commit/2800ad8435ba181db089b17f16957a4b7073a3be)]
- Bump version [kreafox - [`ba4c749`](https://github.com/eea/volto-chatbot/commit/ba4c749a05255fa76d831ca3127c50666f33953b)]
- Fix ESLint warnings [kreafox - [`61aa82c`](https://github.com/eea/volto-chatbot/commit/61aa82c79c1454f41724449e98e04445645f946e)]
- Bump cypress version to fix cypress testing [kreafox - [`dcaafa1`](https://github.com/eea/volto-chatbot/commit/dcaafa1664c430f24a5dd4e3929f58fd0be03346)]
- Needs this middleware [Tiberiu Ichim - [`300913a`](https://github.com/eea/volto-chatbot/commit/300913af9538934ea1ae6e3a10210824b00bb0d5)]
- Downgrade node_fetch [Tiberiu Ichim - [`5533eec`](https://github.com/eea/volto-chatbot/commit/5533eec9ac8fba92baca2b9150d23016797f1ea5)]
- Downgrade and use react-markdown [Tiberiu Ichim - [`c7b7b9e`](https://github.com/eea/volto-chatbot/commit/c7b7b9e1ae6b07dafc5e32980dcea2945eaee062)]
- Remove console.log [Tiberiu Ichim - [`fe77c3e`](https://github.com/eea/volto-chatbot/commit/fe77c3e4fa54b32feb8a29420a0305f304cf91f5)]
- Click fix [Tiberiu Ichim - [`62d2d81`](https://github.com/eea/volto-chatbot/commit/62d2d8159548c9eea1cf4fc0ece8ea71280bed92)]
- Checkpoint [Tiberiu Ichim - [`5062748`](https://github.com/eea/volto-chatbot/commit/50627486552b4afd5a5d663b1de47830d7ede066)]
- Checkpoint [Tiberiu Ichim - [`18981b9`](https://github.com/eea/volto-chatbot/commit/18981b92206b0ff62320b8437d1edd17aeed10e2)]
- Checkpoint [Tiberiu Ichim - [`9c68214`](https://github.com/eea/volto-chatbot/commit/9c682144acb7e038a5321b1247795e555a13547a)]
- WIP [Tiberiu Ichim - [`13d75d8`](https://github.com/eea/volto-chatbot/commit/13d75d8511e81dc287bea8e4f4496f1623312a82)]
- WIP [Tiberiu Ichim - [`e4dbab8`](https://github.com/eea/volto-chatbot/commit/e4dbab83ac99fa691479539d262333350eb6cbe1)]
- WIP [Tiberiu Ichim - [`0323fe5`](https://github.com/eea/volto-chatbot/commit/0323fe533c2d28c2367cb6239f90596740bc0a6e)]
- WIP [Tiberiu Ichim - [`3b55b5c`](https://github.com/eea/volto-chatbot/commit/3b55b5c6eb5b427baee2abc024bc63ec5b93f843)]
- WIP [Tiberiu Ichim - [`1a2d3f6`](https://github.com/eea/volto-chatbot/commit/1a2d3f6d495c86e026bb95cdd529c6054f5c241c)]
- Use node-fetch in middleware [Tiberiu Ichim - [`90c9c28`](https://github.com/eea/volto-chatbot/commit/90c9c28a052c601c032a6a7ed0836c7b8456db98)]
- Before bring node-fetch [Tiberiu Ichim - [`3bfae76`](https://github.com/eea/volto-chatbot/commit/3bfae76562185e61e8ea37603deeea9e70239d0b)]
- Before bring node-fetch [Tiberiu Ichim - [`9abb1e3`](https://github.com/eea/volto-chatbot/commit/9abb1e374904e44fe52f01106ee94af31dc37ea1)]
- Add more components [Tiberiu Ichim - [`8b8fb36`](https://github.com/eea/volto-chatbot/commit/8b8fb36734bd4965214a1df5858501385b3c35dc)]
- Fix preview block when editing [Tiberiu Ichim - [`ad82d92`](https://github.com/eea/volto-chatbot/commit/ad82d92337c2b0f0984c138f975f616c3b6903d5)]
- More code [Tiberiu Ichim - [`7992323`](https://github.com/eea/volto-chatbot/commit/7992323cfaf246d208d50f9fd95803727e84e745)]
- Add block [Tiberiu Ichim - [`fe47b70`](https://github.com/eea/volto-chatbot/commit/fe47b70226f9d36e1de7918964f4e744450e18a6)]
- Add block [Tiberiu Ichim - [`58f3ecd`](https://github.com/eea/volto-chatbot/commit/58f3ecdeb8b8342e5ee87fcea01cf0fc2dd83721)]
- Add block [Tiberiu Ichim - [`6b594b7`](https://github.com/eea/volto-chatbot/commit/6b594b75997f777da93f102c3f807d37d65ba693)]
- Better errors [Tiberiu Ichim - [`78ef06c`](https://github.com/eea/volto-chatbot/commit/78ef06c789136597de2b2a5637e2aefe95184576)]
- Add middleware [Tiberiu Ichim - [`9a21d26`](https://github.com/eea/volto-chatbot/commit/9a21d266fc3e16b534dc987b823a19e090c9a4a1)]
### [0.1.1](https://github.com/eea/volto-chatbot/compare/0.1.0...0.1.1) - 1 August 2024

#### :hammer_and_wrench: Others
Expand All @@ -15,5 +77,4 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### :hammer_and_wrench: Others

- yarn bootstrap [alin - [`064d130`](https://github.com/eea/volto-chatbot/commit/064d130ad938a046a4f8dfaa3e78d2fe426c53aa)]
- Initial commit [Tiberiu Ichim - [`c9e59d3`](https://github.com/eea/volto-chatbot/commit/c9e59d3d0d91c2a40c5d215aa26d8ed982fd7856)]
24 changes: 18 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eeacms/volto-chatbot",
"version": "0.1.1",
"version": "0.1.2",
"description": "@eeacms/volto-chatbot: Volto add-on",
"main": "src/index.js",
"author": "European Environment Agency: IDM2 A-Team",
Expand All @@ -16,16 +16,16 @@
"type": "git",
"url": "git@github.com:eea/volto-chatbot.git"
},
"dependencies": {},
"devDependencies": {
"@plone/scripts": "*",
"@babel/plugin-proposal-private-methods": "7.18.6",
"@cypress/code-coverage": "^3.10.0",
"cypress-fail-fast": "^5.0.1",
"@plone/scripts": "*",
"babel-plugin-transform-class-properties": "^6.24.1",
"cypress": "13.1.0",
"cypress-fail-fast": "^5.0.1",
"husky": "^8.0.3",
"lint-staged": "^14.0.1",
"md5": "^2.3.0",
"cypress": "13.1.0"
"md5": "^2.3.0"
},
"lint-staged": {
"src/**/*.{js,jsx,ts,tsx,json}": [
Expand Down Expand Up @@ -67,5 +67,17 @@
"i18n": "make i18n",
"cypress:run": "make cypress-run",
"cypress:open": "make cypress-open"
},
"dependencies": {
"@microsoft/fetch-event-source": "2.0.1",
"fast-json-patch": "3.1.1",
"highlight.js": "11.10.0",
"marked": "13.0.3",
"node-fetch": "2.7.0",
"react-markdown": "6.0.3",
"react-textarea-autosize": "^8.5.3",
"rehype-prism-plus": "1.6.0",
"remark-gfm": "3.0.1",
"uuid": "10.0.0"
}
}
40 changes: 40 additions & 0 deletions razzle.extend.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const path = require('path');
const makeLoaderFinder = require('razzle-dev-utils/makeLoaderFinder');

const modify = (config, { target, dev }, webpack) => {
const markedPath = path.dirname(require.resolve('marked'));
const nodeFetch = path.dirname(require.resolve('node-fetch'));

const babelLoaderFinder = makeLoaderFinder('babel-loader');
const babelLoader = config.module.rules.find(babelLoaderFinder);

// config.module.rules.push({
// test: /node_modules\/vfile\//, // \/lib\/index\.js
// use: [
// {
// loader: 'imports-loader',
// options: {
// type: 'commonjs',
// // imports: ['single process/browser process'],
// },
// },
// ],
// });

const { include } = babelLoader;

include.push(markedPath);
// include.push(nodeFetch);

babelLoader.use[0].options.plugins = [
...(babelLoader.use[0].options.plugins || []),
'@babel/plugin-proposal-private-methods',
];

return config;
};

module.exports = {
plugins: (plugs) => plugs,
modify,
};
15 changes: 15 additions & 0 deletions src/ChatBlock/AutoResizeTextarea.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import TextareaAutosize from 'react-textarea-autosize';

import React from 'react';

export default React.forwardRef(function AutoResizeTextarea(
{ trigger, ...rest },
ref,
) {
return (
<>
<TextareaAutosize {...rest} ref={ref} />
{trigger}
</>
);
});
42 changes: 42 additions & 0 deletions src/ChatBlock/ChatBlockEdit.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from 'react';
import superagent from 'superagent';
import { BlockDataForm, SidebarPortal } from '@plone/volto/components';

import ChatBlockView from './ChatBlockView';
import { ChatBlockSchema } from './schema';
import withDanswerData from './withDanswerData';

const SearchBlockEdit = (props) => {
const { onChangeBlock, block, assistants } = props;

const schema = React.useMemo(
() => ChatBlockSchema({ assistants }),
[assistants],
);

return (
<div>
<ChatBlockView {...props} mode="edit" />
<SidebarPortal selected={props.selected}>
<BlockDataForm
schema={schema}
title={schema.title}
block={block}
onChangeBlock={onChangeBlock}
onChangeField={(id, value) => {
onChangeBlock(props.block, {
...props.data,
[id]: value,
});
}}
formData={props.data}
/>
</SidebarPortal>
</div>
);
};

export default withDanswerData(() => [
'assistants',
superagent.get('/_da/persona?include_deleted=false').type('json'),
])(SearchBlockEdit);
26 changes: 26 additions & 0 deletions src/ChatBlock/ChatBlockView.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react';
import withDanswerData from './withDanswerData';
import ChatWindow from './ChatWindow';
import superagent from 'superagent';

function ChatBlockView(props) {
const { assistantData } = props;

return assistantData ? (
<div>
<div>
<ChatWindow persona={assistantData} />
</div>
</div>
) : (
<div>Chatbot</div>
);
}

export default withDanswerData((props) => [
'assistantData',
typeof props.data?.assistant !== 'undefined'
? superagent.get(`/_da/persona/${props.data.assistant}`).type('json')
: null,
props.data?.assistant,
])(ChatBlockView);
120 changes: 120 additions & 0 deletions src/ChatBlock/ChatMessageBubble.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import React from 'react';
import loadable from '@loadable/component';
import { Citation } from './Citation';
import { SourceDetails } from './Source';
import { transformEmailsToLinks, SVGIcon } from './utils';
import BotIcon from './../icons/bot.svg';
import UserIcon from './../icons/user.svg';

const Markdown = loadable(() => import('react-markdown'));

const components = (message) => {
return {
a: (props) => {
const { node, ...rest } = props;
const value = rest.children;

if (value?.toString().startsWith('*')) {
return (
<div className="flex-none bg-background-800 inline-block rounded-full h-3 w-3 ml-2" />
);
} else {
return (
<Citation link={rest?.href} value={value} message={message}>
{rest.children}
</Citation>
);
}
},
p: ({ node, ...props }) => {
const children = props.children;
const text = React.Children.map(children, (child) => {
if (typeof child === 'string') {
return transformEmailsToLinks(child);
}
return child;
});

return (
<p {...props} className="text-default">
{text}
</p>
);
},
};
};

const CITATION_MATCH = /\[\d+\](?![[(\])])/gm;

function addCitations(text) {
return text.replaceAll(CITATION_MATCH, (match) => {
const number = match.match(/\d+/)[0];
return `${match}(${number})`;
});
}

export function ChatMessageBubble(props) {
const { message, isLoading, isMostRecent, libs } = props;
const { remarkGfm } = libs; // , rehypePrism
const { citations = {}, documents, type } = message;
const isUser = type === 'user';

const showLoader = isMostRecent && isLoading;

// TODO: these classes are not actually used, remove them
const colorClassName = isUser ? 'bg-lime-300' : 'bg-slate-50';
const alignmentClassName = isUser ? 'ml-auto' : 'mr-auto';

const icon = isUser ? (
<div className="circle user">
<SVGIcon name={UserIcon} size="20" color="white" />
</div>
) : (
<div className="circle assistant">
<SVGIcon name={BotIcon} size="20" color="white" />
</div>
);

// For some reason the list is shifted by one. It's all weird
const sources = Object.keys(citations).map(
(index) => documents[(parseInt(index) - 1).toString()],
);
const inverseMap = Object.entries(citations).reduce((acc, [k, v]) => {
return { ...acc, [v]: k };
}, {});

return (
<div className={`${alignmentClassName} ${colorClassName} `}>
<div className="comment">
{icon}

<div>
<Markdown
components={components(message)}
remarkPlugins={[remarkGfm]}
>
{addCitations(message.message)}
</Markdown>

{!showLoader && sources.length ? (
<>
<h5>Sources:</h5>

<div className="sources">
{sources.map((source, i) => (
<SourceDetails
source={source}
key={i}
index={inverseMap[source.db_doc_id]}
/>
))}
</div>
</>
) : (
''
)}
</div>
</div>
</div>
);
}
Loading

0 comments on commit 1dadf20

Please sign in to comment.