@eeacms/volto-eea-chatbot 3.0.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,133 @@
1
+ name: Betterleaks
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+
7
+ permissions:
8
+ contents: read
9
+
10
+ jobs:
11
+ scan:
12
+ name: Scan for secrets
13
+ runs-on: ubuntu-latest
14
+ env:
15
+ SMTP_URL: ${{ secrets.SMTP_URL }}
16
+ SMTP_PORT: ${{ secrets.SMTP_PORT || '25' }}
17
+ SMTP_EMAIL: ${{ secrets.SMTP_EMAIL }}
18
+ SMTP_PASSWORD: ${{ secrets.SMTP_PASSWORD }}
19
+ steps:
20
+ - name: Checkout repository
21
+ uses: actions/checkout@v4
22
+ with:
23
+ fetch-depth: 1
24
+ ref: ${{ github.event.pull_request.head.sha || github.sha }}
25
+
26
+ - name: Run Betterleaks
27
+ id: betterleaks
28
+ continue-on-error: true
29
+ uses: dortort/betterleaks-action@v0.1.0
30
+ with:
31
+ github-token: ${{ secrets.GITHUB_TOKEN }}
32
+ scan-mode: dir
33
+ scan-path: .
34
+ config: .gitleaks.toml
35
+ report-format: json
36
+ report-path: betterleaks-report.json
37
+ redact: "true"
38
+ no-color: "true"
39
+ no-banner: "true"
40
+ fail-on-leak: "true"
41
+
42
+ - name: Upload Betterleaks report
43
+ if: always()
44
+ uses: actions/upload-artifact@v4
45
+ with:
46
+ name: betterleaks-report
47
+ path: betterleaks-report.json
48
+ if-no-files-found: ignore
49
+
50
+ - name: Build Betterleaks email summary
51
+ id: leak_summary
52
+ if: steps.betterleaks.outcome == 'failure'
53
+ shell: bash
54
+ run: |
55
+ if [[ -s betterleaks-report.json ]]; then
56
+ jq -r '
57
+ def one_line:
58
+ tostring
59
+ | gsub("[\r\n]+"; " ")
60
+ | if length > 240 then .[0:240] + "..." else . end;
61
+
62
+ .[:20][]
63
+ | "- " + (.RuleID // "unknown-rule")
64
+ + " at " + (.File // "unknown-file")
65
+ + ":" + ((.StartLine // 0) | tostring)
66
+ + "\n match: " + ((.Match // .Secret // "REDACTED") | one_line)
67
+ ' betterleaks-report.json > betterleaks-email-summary.txt
68
+
69
+ count="$(jq 'length' betterleaks-report.json)"
70
+ if (( count > 20 )); then
71
+ {
72
+ echo ""
73
+ echo "... and $((count - 20)) more finding(s). Download the artifact for full details."
74
+ } >> betterleaks-email-summary.txt
75
+ fi
76
+ else
77
+ echo "No JSON report was generated. Download the workflow logs for details." > betterleaks-email-summary.txt
78
+ fi
79
+
80
+ {
81
+ echo "text<<BETTERLEAKS_SUMMARY"
82
+ cat betterleaks-email-summary.txt
83
+ echo "BETTERLEAKS_SUMMARY"
84
+ } >> "$GITHUB_OUTPUT"
85
+
86
+ - name: Resolve committer email
87
+ id: committer
88
+ if: steps.betterleaks.outcome == 'failure'
89
+ shell: bash
90
+ run: |
91
+ committer_email="$(git log -1 --format='%ce')"
92
+ author_email="$(git log -1 --format='%ae')"
93
+ email="$committer_email"
94
+ if [[ -z "$email" || "$email" == *"noreply.github.com"* ]]; then
95
+ email="$author_email"
96
+ fi
97
+ if [[ "$email" =~ ^[^[:space:]@]+@[^[:space:]@]+\.[^[:space:]@]+$ && "$email" != *"noreply.github.com"* ]]; then
98
+ echo "email=$email" >> "$GITHUB_OUTPUT"
99
+ else
100
+ echo "No deliverable committer email found; skipping Betterleaks email notification."
101
+ echo "email=" >> "$GITHUB_OUTPUT"
102
+ fi
103
+
104
+ - name: Email committer on Betterleaks failure
105
+ if: steps.betterleaks.outcome == 'failure' && steps.committer.outputs.email != '' && env.SMTP_URL != '' && env.SMTP_EMAIL != ''
106
+ uses: dawidd6/action-send-mail@v18
107
+ with:
108
+ server_address: ${{ env.SMTP_URL }}
109
+ server_port: ${{ env.SMTP_PORT }}
110
+ secure: ${{ env.SMTP_PORT == '465' }}
111
+ username: ${{ env.SMTP_EMAIL }}
112
+ password: ${{ env.SMTP_PASSWORD }}
113
+ from: ${{ env.SMTP_EMAIL }}
114
+ to: ${{ steps.committer.outputs.email }}
115
+ subject: "[Betterleaks] Secret scan failed in ${{ github.repository }}"
116
+ body: |
117
+ Betterleaks detected one or more potential secrets.
118
+
119
+ Repository: ${{ github.repository }}
120
+ Branch: ${{ github.ref_name }}
121
+ Commit: ${{ github.sha }}
122
+ Workflow run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
123
+
124
+ Findings:
125
+ ${{ steps.leak_summary.outputs.text }}
126
+
127
+ Download the betterleaks-report artifact from the workflow run for details.
128
+
129
+ - name: Fail if Betterleaks found leaks
130
+ if: steps.betterleaks.outcome == 'failure'
131
+ run: |
132
+ echo "Betterleaks detected one or more secrets. Download the betterleaks-report artifact from this workflow run for details."
133
+ exit 1
package/.gitleaks.toml ADDED
@@ -0,0 +1,89 @@
1
+ title = "Betterleaks config"
2
+
3
+ [extend]
4
+ useDefault = true
5
+
6
+ [[rules]]
7
+ id = "secret-literal-assignment"
8
+ description = "Secret-like literal assignment in source, YAML, env and config files"
9
+ regex = '''(?i)([A-Za-z0-9_.-]*(?:password|passwd|pwd|api[_-]?key|apikey|access[_-]?key|secret[_-]?access[_-]?key|private[_-]?key|client[_-]?secret|consumer[_-]?key|consumer[_-]?secret|(?:auth|access|refresh|session|api|bearer|id|jwt|csrf|xsrf|oauth)[_-]?token|translate[_-]?auth|translation[_-]?auth|auth[_-]?password|auth[_-]?key|auth[_-]?credentials|database[_-]?url|connection[_-]?string)[A-Za-z0-9_.-]*)[ \t]*[:=][ \t]*["'']?([^"''[:space:]#{}$.][^"''\n#{}]{2,})["'']?'''
10
+ secretGroup = 2
11
+ keywords = [
12
+ "password",
13
+ "passwd",
14
+ "pwd",
15
+ "api_key",
16
+ "apikey",
17
+ "access_key",
18
+ "private_key",
19
+ "client_secret",
20
+ "consumer_key",
21
+ "consumer_secret",
22
+ "auth_token",
23
+ "access_token",
24
+ "refresh_token",
25
+ "session_token",
26
+ "api_token",
27
+ "bearer_token",
28
+ "id_token",
29
+ "jwt_token",
30
+ "csrf_token",
31
+ "xsrf_token",
32
+ "oauth_token",
33
+ "translate_auth",
34
+ "translation_auth",
35
+ "auth_password",
36
+ "auth_key",
37
+ "auth_credentials",
38
+ "database_url",
39
+ "connection_string"
40
+ ]
41
+ tags = ["literal-secret"]
42
+
43
+ [[rules]]
44
+ id = "env-short-secret-assignment"
45
+ description = "Uppercase env-style PASS/TOKEN/SECRET assignment"
46
+ regex = '''\b((?:PASS|TOKEN|SECRET|[A-Z0-9_]*(?:_PASS|_TOKEN|_SECRET|PASS_|TOKEN_|SECRET_)[A-Z0-9_]*))[ \t]*[:=][ \t]*["'']?([^"''[:space:]#{}$.][^"''\n#{}]{2,})["'']?'''
47
+ secretGroup = 2
48
+ keywords = [
49
+ "PASS",
50
+ "TOKEN",
51
+ "SECRET"
52
+ ]
53
+ tags = ["env", "literal-secret"]
54
+
55
+ [[rules]]
56
+ id = "standalone-sk-token"
57
+ description = "Standalone sk-* token not attached to a secret-like variable name"
58
+ regex = '''(?i)\b(sk-[A-Za-z0-9][A-Za-z0-9_-]{20,})\b'''
59
+ secretGroup = 1
60
+ entropy = 2.5
61
+ keywords = ["sk-"]
62
+ tags = ["standalone-token", "generic"]
63
+
64
+ [[rules]]
65
+ id = "dotenv-only-jest-setup"
66
+ description = ".env may only contain the committed Jest setup lines"
67
+ path = '''(?i)(^|/)\.env$'''
68
+ regex = '''(?m)^(.+)$'''
69
+ secretGroup = 1
70
+ tags = ["file", "dotenv"]
71
+ [[rules.allowlists]]
72
+ regexTarget = "match"
73
+ regexes = [
74
+ '''^JEST_USE_SETUP=OFF # Jest configuration variables: ON, OFF\r?$''',
75
+ ]
76
+
77
+ [[rules]]
78
+ id = "forbidden-secret-file"
79
+ description = "Forbidden secret-bearing file committed to repository"
80
+ path = '''(?i)(^|/)(\.env\..*|\.npmrc|\.pypirc|id_rsa|id_ed25519|.*\.(pem|key|p12|pfx|jks|kubeconfig))$'''
81
+ regex = '''(?s).{1,}'''
82
+ tags = ["file", "secret-file"]
83
+
84
+ [[allowlists]]
85
+ description = "Allow Jenkins SonarQube token environment variable reference"
86
+ regexTarget = "match"
87
+ regexes = [
88
+ '''SONAR_AUTH_TOKEN''',
89
+ ]
package/CHANGELOG.md CHANGED
@@ -4,7 +4,38 @@ All notable changes to this project will be documented in this file. Dates are d
4
4
 
5
5
  Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
6
6
 
7
- ### [3.0.0](https://github.com/eea/volto-eea-chatbot/compare/2.0.5...3.0.0) - 7 July 2026
7
+ ### [4.0.0](https://github.com/eea/volto-eea-chatbot/compare/3.0.1...4.0.0) - 13 August 2026
8
+
9
+ #### :bug: Bug Fixes
10
+
11
+ - fix: correct 100.00% → High in ClaimModal snapshot [Tiberiu Ichim - [`2f3e620`](https://github.com/eea/volto-eea-chatbot/commit/2f3e620627faae3b050f0cb6ba1e3db4015dc5db)]
12
+ - fix: avoid Betterleaks false positive on LLM_API_KEY example [Tiberiu Ichim - [`44e05bc`](https://github.com/eea/volto-eea-chatbot/commit/44e05bc74a042e7f08cc0e6878930f9acc1964b9)]
13
+ - fix: filter skipped claims in span processor to prevent text duplication [Tiberiu Ichim - [`9477a42`](https://github.com/eea/volto-eea-chatbot/commit/9477a42d363d6961f4def628ed567a2409b316ea)]
14
+
15
+ #### :house: Internal changes
16
+
17
+ - chore: bump version to 4.0.0 (breaking change) [Tiberiu Ichim - [`e1038b6`](https://github.com/eea/volto-eea-chatbot/commit/e1038b6db64612f7c772a898b99ff802b3c133e9)]
18
+ - style: Automated code fix [eea-jenkins - [`03891e2`](https://github.com/eea/volto-eea-chatbot/commit/03891e24e48ccd0eccb55d4ed42aabbcdf34251f)]
19
+
20
+ #### :house: Documentation changes
21
+
22
+ - docs: document rag-facts-check backend dependency for quality checks [Tiberiu Ichim - [`123c7ea`](https://github.com/eea/volto-eea-chatbot/commit/123c7ea5d56ee48e6d5c787049a010b6bebd5aef)]
23
+ - docs: update README for rag-fact-checker integration [Tiberiu Ichim - [`4ae32b4`](https://github.com/eea/volto-eea-chatbot/commit/4ae32b41e838176d4a3ba1ea55367fc21e1a8cae)]
24
+
25
+ #### :hammer_and_wrench: Others
26
+
27
+ - test: update ClaimModal snapshots for categorical score labels [Tiberiu Ichim - [`3794be1`](https://github.com/eea/volto-eea-chatbot/commit/3794be1fc112b9f209a58c6577f99649350b1d59)]
28
+ - Deduplicate sources by text before sending to fact-checker [Tiberiu Ichim - [`67dc793`](https://github.com/eea/volto-eea-chatbot/commit/67dc793f955058d9ba5dbc92ea23a652e4586172)]
29
+ - Fix: use doc.content from final_documents when tool packets lack content [Tiberiu Ichim - [`4174212`](https://github.com/eea/volto-eea-chatbot/commit/4174212a90742c139ad2399f7a07feb99d619fbc)]
30
+ - Replace numeric claim scores with categorical labels [Tiberiu Ichim - [`d0aaf77`](https://github.com/eea/volto-eea-chatbot/commit/d0aaf779a69340386af81e9af4aa5147d93be388)]
31
+ - Send structured sources with document titles to fact-checker [Tiberiu Ichim - [`190c79b`](https://github.com/eea/volto-eea-chatbot/commit/190c79b2a888a7d655157e683633fd9901b8871c)]
32
+ ### [3.0.1](https://github.com/eea/volto-eea-chatbot/compare/3.0.0...3.0.1) - 7 August 2026
33
+
34
+ #### :bug: Bug Fixes
35
+
36
+ - fix: Add betterleaks github action - refs #304517 [dobri1408 - [`837c461`](https://github.com/eea/volto-eea-chatbot/commit/837c4619bd3dab3ffe06aeaabd0513c50e3066b4)]
37
+
38
+ ## [3.0.0](https://github.com/eea/volto-eea-chatbot/compare/2.0.5...3.0.0) - 7 July 2026
8
39
 
9
40
  #### :bug: Bug Fixes
10
41
 
package/README.md CHANGED
@@ -40,7 +40,7 @@ The **Volto Chatbot** block allows the integration of an AI-powered chatbot into
40
40
  | `enableShowTotalFailMessage` | Show total failure message. | Boolean | `false` |
41
41
  | `showAssistantTitle` | Display or hide the assistant's title in the chat interface. | Boolean | `true` |
42
42
  | `showAssistantDescription` | Display or hide the assistant's description in the chat interface. | Boolean | `true` |
43
- | `qualityCheck` | Show Halloumi-based automated quality check. | Dropdown | `Disabled` |
43
+ | `qualityCheck` | Show automated fact-checking of AI answers against source documents. | Dropdown | `Disabled` |
44
44
  | `onDemandInputToggle` | Sets the default state of the fact-check AI toggle. | Boolean | `true` |
45
45
  | `showTools` | Show or hide tools in the chat interface. | Array | `["internal_search_tool_start"]` |
46
46
  | `scrollToInput` | Automatically scroll the page to focus on the chat input when interacting. | Boolean | `false` |
@@ -116,6 +116,44 @@ Go to http://localhost:3000
116
116
 
117
117
  For a legacy Volto 17 project, install the package with `yarn` and restart the frontend as usual.
118
118
 
119
+ ## Quality Checks (Fact-Checking)
120
+
121
+ When `qualityCheck` is enabled, the chatbot sends AI answers and their source
122
+ documents to a fact-checking backend that extracts claims, verifies each
123
+ against the sources, and returns per-claim verdicts with evidence.
124
+
125
+ ### Backend dependency
126
+
127
+ The fact-checking feature requires the
128
+ [eea/rag-facts-check](https://github.com/eea/rag-facts-check) service running
129
+ and reachable at the URL configured in `RAG_FACT_CHECKER_URL`.
130
+
131
+ **Without this backend, quality checks will fail with a connection error.**
132
+
133
+ The backend exposes a halloumi-compatible endpoint (`POST /halloumi/generate`)
134
+ so the frontend can call it without code changes. It also provides a native
135
+ `POST /check` endpoint with a richer response schema.
136
+
137
+ ### Deploying the backend
138
+
139
+ ```bash
140
+ # Clone and build
141
+ git clone https://github.com/eea/rag-facts-check.git
142
+ cd rag-facts-check
143
+ docker build -t rag-fact-check .
144
+
145
+ # Run (requires an LLM endpoint)
146
+ # Set LLM_API_KEY to your actual API key before running
147
+ docker run -p 8000:8000 \
148
+ -e LLM_API_BASE=http://your-llm:4002/v1 \
149
+ -e LLM_API_KEY \
150
+ -e LLM_MODEL=gemma \
151
+ rag-fact-check
152
+ ```
153
+
154
+ See the [backend README](https://github.com/eea/rag-facts-check#rag-facts-check)
155
+ for full configuration options.
156
+
119
157
  ## Environment Configuration
120
158
 
121
159
  To properly configure the middleware and authenticate with the Onyx service, ensure that the following environment variables are set:
@@ -131,20 +169,13 @@ This document lists the environment variables used in the Volto Chatbot project.
131
169
  - `JEST_USE_SETUP`
132
170
  Used in Jest configuration. When set to 'ON', it enables a specific Jest setup.
133
171
 
134
- - `LLMGW_URL`
135
- The URL for the LLM Gateway service.
136
-
137
- - `LLMGW_TOKEN`
138
- The token for authenticating with the LLM Gateway service.
172
+ - `RAG_FACT_CHECKER_URL`
173
+ The base URL for the [rag-facts-check](https://github.com/eea/rag-facts-check)
174
+ fact-checking backend. Required when `qualityCheck` is enabled.
175
+ Default: `http://localhost:8000`.
139
176
 
140
177
  ### Development-specific environment variables
141
178
 
142
- - `MOCK_HALLOUMI_FILE_PATH`
143
- When set, this specifies the absolute path to the JSON file containing the mocked Halloumi response. Setting this variable enables mocking of Halloumi API calls.
144
-
145
- - `DUMP_HALLOUMI_FILE_PATH`
146
- When set, the Halloumi response will be dumped to the specified absolute file path for debugging or to create new mock files.
147
-
148
179
  - `MOCK_LLM_FILE_PATH`
149
180
  When set, this specifies the absolute path to the JSONL file containing the mocked Onyx stream response. Setting this variable enables mocking of Onyx LLM calls.
150
181
 
@@ -162,6 +193,65 @@ See [RELEASE.md](https://github.com/eea/volto-eea-chatbot/blob/master/RELEASE.md
162
193
 
163
194
  See [DEVELOP.md](https://github.com/eea/volto-eea-chatbot/blob/master/DEVELOP.md).
164
195
 
196
+ ## Secret Scanning
197
+
198
+ This repository uses the Betterleaks GitHub Action to scan the current
199
+ repository content on every push and pull request. The scan uses the rules in
200
+ `.gitleaks.toml` and uploads a `betterleaks-report` artifact when a finding is
201
+ detected.
202
+
203
+ If the optional SMTP secrets are configured, failed scans also send an email to
204
+ the last commit committer. The workflow expects these repository or
205
+ organization secrets:
206
+
207
+ - `SMTP_URL`
208
+ - `SMTP_PORT` (optional, defaults to `25`)
209
+ - `SMTP_EMAIL`
210
+ - `SMTP_PASSWORD` (optional if the SMTP server does not require authentication)
211
+
212
+ Port `465` is sent with direct TLS; other ports use the default SMTP handshake.
213
+ The email includes a short finding summary from the redacted Betterleaks report,
214
+ including the redacted matched line from each finding.
215
+
216
+ There are three common outcomes:
217
+
218
+ 1. **Everything is OK.** The `Betterleaks / Scan for secrets` check is green and
219
+ no action is needed. Regular references to runtime values are OK, for example:
220
+
221
+ ```js
222
+ const tokenFromCookie = req.universalCookies.get('auth_token');
223
+ ```
224
+
225
+ 2. **A real secret was found.** The check is red and the workflow log asks you to
226
+ download the `betterleaks-report` artifact. Open the artifact from the GitHub
227
+ Actions run and check the reported file, line and rule. Remove the committed
228
+ value, move it to the proper secret store, and rotate it if it was exposed.
229
+ A report entry looks like this:
230
+
231
+ ```json
232
+ {
233
+ "RuleID": "secret-literal-assignment",
234
+ "File": "src/config.js",
235
+ "StartLine": 12,
236
+ "Secret": "[REDACTED]"
237
+ }
238
+ ```
239
+
240
+ 3. **The finding is a false positive.** Keep the value only if it is clearly not
241
+ sensitive, such as a test fixture, placeholder, or public example. Add
242
+ `betterleaks:allow` on the same line and include a short explanation in the
243
+ pull request.
244
+
245
+ ```js
246
+ const testPassword = 'admin'; //betterleaks:allow
247
+ ```
248
+
249
+ ```yaml
250
+ password: "admin" #betterleaks:allow
251
+ ```
252
+
253
+ Do not add `betterleaks:allow` to real credentials.
254
+
165
255
  ## Copyright and license
166
256
 
167
257
  The Initial Owner of the Original Code is European Environment Agency (EEA).
package/RELEASE.md CHANGED
@@ -33,7 +33,7 @@ Release-it is a tool that automates 4 important steps in the release process:
33
33
  To configure the authentification, you need to export GITHUB_TOKEN for [GitHub](https://github.com/settings/tokens)
34
34
 
35
35
  ```
36
- export GITHUB_TOKEN=XXX-XXXXXXXXXXXXXXXXXXXXXX
36
+ export GITHUB_TOKEN="${GITHUB_TOKEN}"
37
37
  ```
38
38
 
39
39
  To configure npm, you can use the `npm login` command or use a configuration file with a TOKEN :
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-eea-chatbot",
3
- "version": "3.0.0",
3
+ "version": "4.0.0",
4
4
  "description": "@eeacms/volto-eea-chatbot: Volto add-on",
5
5
  "main": "src/index.js",
6
6
  "author": "European Environment Agency: IDM2 A-Team",
@@ -81,31 +81,21 @@ function addQualityMarkersPlugin() {
81
81
  };
82
82
  }
83
83
 
84
- export function addHalloumiContext(doc: any, text: string) {
85
- // TODO: CLEAN UP
86
- // const updatedDate = doc.updated_at
87
- // ? new Date(doc.updated_at).toLocaleString('en-GB', {
88
- // year: 'numeric',
89
- // month: 'long',
90
- // day: '2-digit',
91
- // hour: '2-digit',
92
- // minute: '2-digit',
93
- // })
94
- // : '';
95
-
96
- // const docIndex = doc.index ? `DOCUMENT ${doc.index}: ` : '';
97
- // const sources: any = { web: 'Website', file: 'File' };
98
-
99
- // const sourceType = doc.source_type
100
- // ? sources[doc.source_type] || capitalize(doc.source_type)
101
- // : '';
102
-
103
- // const header = `${docIndex}${doc.semantic_identifier}${
104
- // sourceType ? `\nSource: ${sourceType}` : ''
105
- // }${updatedDate ? `\nUpdated: ${updatedDate}` : ''}`;
106
-
107
- // return `${header}\n${text}`;
108
- return text.replace(/\u00A0/g, ' ');
84
+ /**
85
+ * Build a structured source object for the fact-checker backend.
86
+ *
87
+ * The backend accepts {text, title, source_type} dicts so it can
88
+ * include document titles in LLM prompts without polluting the raw
89
+ * text (which would break span-offset matching).
90
+ */
91
+ export function buildHalloumiSource(doc: any, text: string) {
92
+ const cleanedText = text.replace(/\u00A0/g, ' ');
93
+ return {
94
+ text: cleanedText,
95
+ title: doc.semantic_identifier || null,
96
+ source_type: doc.source_type || null,
97
+ link: doc.link || null,
98
+ };
109
99
  }
110
100
 
111
101
  function mapToolDocumentsToText(message: any) {
@@ -135,24 +125,36 @@ function getContextSources(
135
125
  const documentIdToText = mapToolDocumentsToText(message);
136
126
 
137
127
  return qualityCheckContext === 'citations'
138
- ? sources.map((doc: any) => ({
139
- ...doc,
140
- id: doc.document_id,
141
- text: documentIdToText[doc.document_id] || '',
142
- halloumiContext: addHalloumiContext(
143
- doc,
144
- documentIdToText[doc.document_id] || '',
145
- ),
146
- }))
128
+ ? sources.map((doc: any) => {
129
+ // Prefer content from tool packets (may have enriched text),
130
+ // but fall back to doc.content from final_documents.
131
+ // Without this fallback, sources sent to the fact-checker are
132
+ // empty strings when tool packets don't carry full content.
133
+ const text = documentIdToText[doc.document_id] || doc.content || '';
134
+ const cleanedText = text.replace(/\u00A0/g, ' ');
135
+ return {
136
+ ...doc,
137
+ id: doc.document_id,
138
+ text,
139
+ // Keep for ClaimSegments span highlighting (plain text)
140
+ halloumiContext: cleanedText,
141
+ // Structured source for the fact-checker backend
142
+ halloumiSource: buildHalloumiSource(doc, text),
143
+ };
144
+ })
147
145
  : (message.toolCalls || []).reduce(
148
146
  (acc: any, cur: any) => [
149
147
  ...acc,
150
- ...(cur.tool_result || []).map((doc: any) => ({
151
- ...doc,
152
- id: doc.document_id,
153
- text: doc.content,
154
- halloumiContext: addHalloumiContext(doc, doc.content),
155
- })),
148
+ ...(cur.tool_result || []).map((doc: any) => {
149
+ const cleanedText = (doc.content || '').replace(/\u00A0/g, ' ');
150
+ return {
151
+ ...doc,
152
+ id: doc.document_id,
153
+ text: doc.content,
154
+ halloumiContext: cleanedText,
155
+ halloumiSource: buildHalloumiSource(doc, doc.content || ''),
156
+ };
157
+ }),
156
158
  ], // TODO: make sure we don't add multiple times the same doc
157
159
  // TODO: this doesn't have the index for source
158
160
  [],
@@ -281,7 +283,24 @@ export function AIMessage({
281
283
  qualityCheckContext,
282
284
  );
283
285
 
284
- const stableContextSources = useDeepCompareMemoize(contextSources);
286
+ // Deduplicate sources by text content. The streaming backend often sends
287
+ // the same document in multiple packets (MESSAGE_START, SEARCH_TOOL_DELTA,
288
+ // etc.), resulting in 40+ copies of the same text. Dedup keeps the first
289
+ // occurrence, preserving order. Critical: texts must remain identical
290
+ // between frontend (span highlighting) and backend (evidence spans).
291
+ const dedupedSources = useMemo(() => {
292
+ const seen = new Set<string>();
293
+ return contextSources.filter((src: any) => {
294
+ const key = src.halloumiContext || src.halloumiSource?.text || '';
295
+ if (key && !seen.has(key)) {
296
+ seen.add(key);
297
+ return true;
298
+ }
299
+ return false;
300
+ });
301
+ }, [contextSources]);
302
+
303
+ const stableContextSources = useDeepCompareMemoize(dedupedSources);
285
304
 
286
305
  const doQualityControl =
287
306
  messageDisplayed &&
@@ -1,6 +1,6 @@
1
1
  import { Modal, ModalContent, ModalHeader } from 'semantic-ui-react';
2
2
  import cx from 'classnames';
3
- import { convertToPercentage } from '@eeacms/volto-eea-chatbot/ChatBlock/utils';
3
+ import { scoreToLabel } from '@eeacms/volto-eea-chatbot/ChatBlock/utils';
4
4
  import SVGIcon from '@eeacms/volto-eea-chatbot/ChatBlock/components/Icon';
5
5
  import { getSupportedBgColor } from './colors';
6
6
  import { ClaimSegments } from './ClaimSegments';
@@ -70,9 +70,9 @@ export function ClaimModal({ claim, markers, text, citedSources }) {
70
70
  <div className="score-badge-section">
71
71
  <div className="score-badge">
72
72
  <span className="score-percentage">
73
- {convertToPercentage(claim.score)}
73
+ {scoreToLabel(claim.score)}
74
74
  </span>
75
- <span className="score-label">Citation Support</span>
75
+ <span className="score-label">Verification</span>
76
76
  </div>
77
77
  <div className="score-progress-bar">
78
78
  <div
@@ -43,6 +43,7 @@ export function components(message, markers, citedSources) {
43
43
  const end = child.position.end.offset;
44
44
  const claims = markers.claims?.filter(
45
45
  (claim) =>
46
+ !claim.skipped &&
46
47
  claim.score !== null &&
47
48
  ((start >= claim.startOffset && end <= claim.endOffset) ||
48
49
  (start <= claim.endOffset && end >= claim.endOffset) ||
@@ -48,7 +48,16 @@ export function useQualityMarkers(
48
48
 
49
49
  React.useEffect(() => {
50
50
  async function handler() {
51
- const textSources = sources.map(({ halloumiContext }) => halloumiContext);
51
+ // Prefer structured sources (with title metadata) over plain text.
52
+ // Fall back to halloumiContext strings for backward compatibility.
53
+ const firstSource = sources[0];
54
+ const hasStructuredSources =
55
+ firstSource && typeof firstSource.halloumiSource === 'object';
56
+
57
+ const halloumiSources = hasStructuredSources
58
+ ? sources.map(({ halloumiSource }) => halloumiSource)
59
+ : sources.map(({ halloumiContext }) => halloumiContext);
60
+
52
61
  if (sources.length === 0) {
53
62
  setHalloumiResponse(empty(message, FAILURE_RATIONALE));
54
63
  return;
@@ -59,7 +68,7 @@ export function useQualityMarkers(
59
68
  try {
60
69
  const feedback = await fetchHalloumi(
61
70
  message,
62
- textSources,
71
+ halloumiSources,
63
72
  maxContextSegments,
64
73
  );
65
74
  const body = await feedback.json();