Skip to content

Commit

Permalink
Merge branch 'main' into Iframe-for-Zanichelli-Demo
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanorosanelli committed Jan 8, 2025
2 parents 0d1ea49 + f4a6acd commit d882504
Show file tree
Hide file tree
Showing 54 changed files with 814 additions and 398 deletions.
55 changes: 49 additions & 6 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
NUXT_API_BASE_URL=http://localhost:8000
NUXT_API_SECRET={secret_token}

## INTEGRATION - uncomment to change integration (default: brevia)
#NUXT_PUBLIC_INTEGRATION=bedita

## SESSION
# NUXT_BREVIA_SESSION_NAME=Brevia
# NUXT_BREVIA_SESSION_SECRET=DEV-super-secret-session-secret!!
Expand All @@ -12,11 +9,55 @@ NUXT_API_SECRET={secret_token}
## Supported roles are: "admin", "user" -- if not specified, "admin" is assumed
# NUXT_BREVIA_AUTH_CREDENTIALS='[{"username":"gustavo","password":"supporto","name":"Gustavo Supporto", "roles": ["user"]}]'

### BEDITA INTEGRATION
## MULTI-PROJECT SETUP
## edit an uncomment `NUXT_PROJECTS` to enable multi-project setup
## you can define multiple projects with different API base URLs and secrets using a JSON object
## every project must have a unique name
# NUXT_PROJECTS='{
# "Project 1": {
# "apiBaseUrl": "https://project1-api.example.com",
# "apiSecret": "#####"
# },
# "Project 2": {
# "apiBaseUrl": "https://project2-api.example.com",
# "apiSecret": "#####"
# }
# }'
## uncomment to enable or disable the `/project-login/{project}` page
## If enabled login is available only on `/project-login/{project}` where
## {project} must match a project unique name in `NUXT_PROJECTS` - match is performed
## with lowercase versions and with `-` instead of spaces.
## E.g. `/project-login/project-1` will use `"Project 1"` configuration in the above sample
## whereas `/project-login/project-3` will raise a 404 error page
# NUXT_PUBLIC_PROJECT_LOGIN=true

### BEDITA INTEGRATION ###

## INTEGRATION - uncomment to change integration (default: brevia)
#NUXT_PUBLIC_INTEGRATION=bedita

## Single project BEdita API setup - this BEdita API instance must have the `brevia-bedita` plugin installed
## and must be configured to use the same `NUXT_API_BASE_URL` used here
# NUXT_BEDITA_API_BASE_URL=http://bedita-api.localhost
# NUXT_BEDITA_API_KEY={bedita_api_key}

## Multi project BEdita API setup
## Edit an uncomment `NUXT_BEDITA_PROJECTS` to enable multi-project setup.
## You can define multiple projects with different API base URLs and secrets using a JSON object.
## Every project must have the same unique name as in `NUXT_PROJECTS` and every BEdita API instance
## must have the `brevia-bedita` plugin installed and configured to use the same `NUXT_API_BASE_URL` used in the
## corresponding `NUXT_PROJECTS` configuration
# NUXT_BEDITA_PROJECTS='{
# "Project 1": {
# "apiBaseUrl": "https://project1-bedita-api.example.com",
# "apiKey": "#####"
# },
# "Project 2": {
# "apiBaseUrl": "https://project2-bedita-api.example.com",
# "apiKey": "#####"
# }
# }'

## SESSION
# NUXT_BEDITA_SESSION_NAME=Brevia
# NUXT_BEDITA_SESSION_SECRET=DEV-super-secret-session-secret!!
Expand All @@ -29,7 +70,9 @@ NUXT_API_SECRET={secret_token}
## INTEGRATION FEATURES
# NUXT_PUBLIC_BEDITA_FEATURES_SIGNUP=true

# APP
### END BEDITA INTEGRATION ###

## APP FEATURES
# NUXT_PUBLIC_MAX_USER_CHATBOTS=2
# NUXT_PUBLIC_APP_NAME=BREVIA
# NUXT_PUBLIC_APP_DESCRIPTION=AI-powered tools by Atlas
Expand All @@ -38,7 +81,7 @@ NUXT_API_SECRET={secret_token}
# Overwrites the `gtag.id` module option
# NUXT_PUBLIC_GTAG_ID=G-XXXXXXXXXX

# DEMO
## DEMO FEATURES
# NUXT_PUBLIC_DEMO_MAX_CHAT_MESSAGES=30
# NUXT_PUBLIC_DEMO_MAX_CHAT_FILES=3
# NUXT_PUBLIC_DEMO_MAX_CHAT_QUESTIONS=20
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ node_modules
.DS_Store
.history
.vscode

feature_items.json
118 changes: 108 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,126 @@ npm install

## Environment variables

Copy `.env.sample` in `.env` and set at least
On a development environment you can use a `.env` file in the root of the project simply by copying the `.env.sample` file. This file can however be used as a reference for usable environment variables.

The only required variables for **Brevia App** are: `NUXT_API_BASE_URL` and `NUXT_BREVIA_SESSION_SECRET`. See below for more details. With these env vars you can run a minimal version with default access credentials.

### Brevia API

* `NUXT_API_BASE_URL` Brevia API base URL
* `NUXT_API_SECRET` Brevia API secret
* `NUXT_API_SECRET` Brevia API secret, use it if an access token is required by the API

### Session

Configure the session settings with the following variables:

```bash
## SESSION
NUXT_BREVIA_SESSION_NAME=Brevia
NUXT_BREVIA_SESSION_SECRET=example-32-characters-long-secret-key
```

* `NUXT_BREVIA_SESSION_NAME` (optional, default: `Brevia`) - The name of the session cookie.
* `NUXT_BREVIA_SESSION_SECRET` - A secret used to encrypt/decrypt the session cookie. It must be **at least 32 chars**.

### Authentication

Brevia, by design, does not have a real authentication and authorization system. Instead, it has a minimal access control with username and password and two possible roles (`admin` and `user`) that can be defined through a simple `NUXT_BREVIA_AUTH_CREDENTIALS` environment variable.

If you want to use a real authentication and authorization system, it is advisable to use an integration with a CMS, a document system or other types of software that already manage these topics much better than Brevia could. An integration with the BEdita CMS is available as a reference.

Usage example:

```bash
NUXT_BREVIA_AUTH_CREDENTIALS='[{"username":"tizio","password":"incognito","name":"Tizio Incognito", "roles": ["user"]}]'
```

If `NUXT_BREVIA_AUTH_CREDENTIALS` is not set, you can log in using the default credentials:

* Username: `brevia`
* Password: `brevia`

### Multi-project setup

Through `NUXT_PROJECTS` env var you can enable multi-project setup.

With these env vars you can run a minimal version with default access credentials.
You can define multiple projects with different API base URLs and secrets using a JSON object.Every project must have a unique name.

To change the access credentials edit `NUXT_BREVIA_AUTH_CREDENTIALS` and set some simple basic username/password items.
```bash
NUXT_PROJECTS='{
"Project 1": {
"apiBaseUrl": "https://project1-api.example.com",
"apiSecret": "#####"
},
"Project 2": {
"apiBaseUrl": "https://project2-api.example.com",
"apiSecret": "#####"
}
}'
```

If `NUXT_PROJECTS` is set the default `NUXT_API_BASE_URL` and `NUXT_API_SECRET` vars are ignored and as default the login page will show a dropdown to select the project to log in to.

You may also set the `NUXT_PUBLIC_PROJECT_LOGIN` env var to `true` to enable the `/project-login/{project}` page.

If enabled login is available only on `/project-login/{project}` where `{project}` must match a project unique name in `NUXT_PROJECTS` - match is performed with lowercase versions and with hyphens ('-') instead of spaces.

To activate BEdita integration edit:
If enabled, using the above `NUXT_PROJECTS` example:

* `NUXT_BEDITA_API_BASE_URL` BEdita API base URL
* `NUXT_BEDITA_API_KEY` BEdita API KEY
* `NUXT_BEDITA_SESSION_NAME` (optional, default is `bedita`) The name used for session cookie
* `NUXT_BEDITA_SESSION_SECRET` The secret used to crypt/decrypt the session stored in cookie. It must be **at least 32 chars**.
* `/project-login/project-1` will use `"Project 1"` configuration
* `/project-login/project-2` will use `"Project 2"` configuration
* `/project-login/project-3` will raise a 404 error page

## BEdita Integration

To activate BEdita integration, configure the following variables:

```bash
## BEDITA INTEGRATION
NUXT_PUBLIC_INTEGRATION=bedita
NUXT_BEDITA_API_BASE_URL=<BEDITA API BASE URL>
NUXT_BEDITA_API_KEY=<BEDITA API KEY>
NUXT_BEDITA_SESSION_NAME=bedita
NUXT_BEDITA_SESSION_SECRET=<BEDITA SESSION SECRET>
```

* `NUXT_PUBLIC_INTEGRATION` - Integration type, set to `bedita` to enable BEdita integration.
* `NUXT_BEDITA_API_BASE_URL` - BEdita API base URL.
* `NUXT_BEDITA_API_KEY` - BEdita API key.
* `NUXT_BEDITA_SESSION_NAME` (optional, default is `bedita`) - The name used for the session cookie.
* `NUXT_BEDITA_SESSION_SECRET` - The secret used to encrypt/decrypt the session stored in the cookie. It must be **at least 32 chars**.

### Recaptcha

To enable/disable Recaptcha you should edit these vars:

* `NUXT_PUBLIC_RECAPTCHA_ENABLED` (optional, default is `false`) Enable or disable Recaptcha
* `NUXT_PUBLIC_RECAPTCHA_ENABLED` (optional, default is `false`) Enable or disable Recaptcha
* `NUXT_PUBLIC_RECAPTCHA_SITE_KEY` (required if Recaptcha is enabled) Recaptcha site key
* `NUXT_BEDITA_RECAPTCHA_SECRET_KEY` (required if Recaptcha is enabled) Recaptcha secret key

### Multi-project BEdita setup

By editing `NUXT_BEDITA_PROJECTS` you can enable multi-project setup using BEdita integration.
Just like in `NUXT_PROJECTS` you can define multiple projects with different API base URLs and secrets using a JSON object.

Every project must have the same unique name as in `NUXT_PROJECTS` and every BEdita API instance
must have the `brevia-bedita` plugin installed and configured to use the same `NUXT_API_BASE_URL` used in the corresponding `NUXT_PROJECTS` configuration

Here `NUXT_BEDITA_PROJECTS` configuration sample for the `NUXT_PROJECTS` configuration example above:

```bash
NUXT_BEDITA_PROJECTS='{
"Project 1": {
"apiBaseUrl": "https://project1-bedita-api.example.com",
"apiKey": "#####"
},
"Project 2": {
"apiBaseUrl": "https://project2-bedita-api.example.com",
"apiKey": "#####"
}
}'
```

## Development Server

Start the development server on `http://localhost:3000`
Expand Down
1 change: 1 addition & 0 deletions components/AppModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<LazyDialogShowFeedback v-if="$isOpenModal('ShowAnswerFeedback')" v-bind="modalStore.activeModalProps" />
<LazyDialogChatDocuments v-if="$isOpenModal('ChatDocuments')" v-bind="modalStore.activeModalProps" @enlarge-window="largerModal = true" />
<LazyDialogDocumentChunks v-if="$isOpenModal('SeeDocumentChunks')" v-bind="modalStore.activeModalProps" @enlarge-window="largerModal = true" />
<LazyDialogSystemInfo v-if="$isOpenModal('DialogSystemInfo')" v-bind="modalStore.activeModalProps" />
</div>
</div>
</div>
Expand Down
64 changes: 64 additions & 0 deletions components/Dialog/SystemInfo.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<template>
<div class="space-y-8 leading-tight">
<div class="flex justify-between items-center pb-4 mb-4 s\m:mb-5">
<h3 class="text-xl font-semibold text-gray-900">{{ $t('SYSTEM_INFO') }}</h3>
<Icon class="text-2xl hover:cursor-pointer hover:bg-sky-100" name="ph:x-bold" @click="$closeModal()" />
</div>

<div class="gap-3 tracking-wider">
<span class="col-span-3 justify-self-end whitespace-nowrap">
Brevia App <strong>v{{ appVersion }}</strong>
</span>
</div>

<hr class="border-t border-gray-300" />

<div class="gap-3 tracking-wider">
<template v-if="versions?.brevia">
<span class="col-span-3 justify-self-end whitespace-nowrap">
Brevia API <strong>v{{ versions.brevia }}</strong>
</span>
<br />
</template>
<template v-if="versions?.apiName && versions?.apiVersion">
<span class="col-span-3 justify-self-end whitespace-nowrap">
{{ versions.apiName }} API <strong>v{{ versions.apiVersion }}</strong>
</span>
<br />
</template>
<span class="col-span-3 justify-self-end whitespace-nowrap">
API Base URL <strong>{{ versions.baseUrl }}</strong>
</span>
</div>

<hr v-if="integration !== 'brevia'" class="border-t border-gray-300" />

<div v-if="integration !== 'brevia'" class="gap-3 tracking-wider">
<template v-if="integrationVersions?.get(integration)">
<span class="col-span-3 justify-self-end whitespace-nowrap">
{{ integrationName }} API <strong>v{{ integrationVersions?.get(integration) }}</strong>
</span>
<br />
</template>
<template v-if="integrationVersions?.get('apiName') && integrationVersions?.get('apiVersion')">
<span class="col-span-3 justify-self-end whitespace-nowrap">
{{ integrationVersions?.get('apiName') }} API <strong>v{{ integrationVersions?.get('apiVersion') }}</strong>
</span>
<br />
</template>
<span class="col-span-3 justify-self-end whitespace-nowrap">
API Base URL <strong>{{ integrationVersions?.get('baseUrl') }}</strong>
</span>
</div>
</div>
</template>

<script lang="ts" setup>
const appVersion = useRuntimeConfig().public.version;
const response = await fetch('/api/brevia/versions');
const versions = await response.json();
const integration = useIntegration();
const integrationName = integration.charAt(0).toUpperCase() + integration.slice(1);
const integrationVersions = await useIntegrationVersion();
</script>
Loading

0 comments on commit d882504

Please sign in to comment.