Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
31 changes: 31 additions & 0 deletions .commitlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"extends": ["@commitlint/config-conventional"],
"rules": {
"scope-enum": [
2,
"always",
[
"cli",
"convex",
"crawler",
"db",
"deps",
"design",
"docs",
"platform",
"plop",
"pii",
"proxy",
"rag",
"storybook",
"ui",
"web",
"webui",
"workflow"
]
],
"scope-empty": [0],
"body-max-line-length": [0],
"footer-max-line-length": [0]
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ package-lock.json
# Storybook
# ---------------------------------------------------------------------------
storybook-static/
debug-storybook.log
*.log.json

# ---------------------------------------------------------------------------
Expand Down
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,11 @@
},
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff"
},
"search.exclude": {
"**/*.pen": true
},
"files.watcherExclude": {
"**/*.pen": true
}
}
6 changes: 6 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 0 additions & 30 deletions commitlint.config.mjs

This file was deleted.

10 changes: 9 additions & 1 deletion docs/de/platform/admin/governance.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,15 @@ Eine blockierte Nachricht erreicht das Modell nie, ein blockiertes Token wird de

#### PII-Erkennung {#pii-detection}

Aktiviere automatische Erkennung und Maskierung (oder Blockierung) personenbezogener Daten in Nachrichten. Eingebaute Muster decken Email, Telefon, Kreditkarten- und IBAN-Nummern, US-Adressen und einige nationale Ausweise ab; eigene Regex-Regeln ergänzen interne Formate (Mitarbeiter-ID, Ticket-Nummern, Produkt-SKUs). Jedes Muster wählt seinen eigenen Durchsetzungsmodus. Erkannte PII in Anhängen durchläuft dieselbe Pipeline wie getippte Nachrichten.
Aktiviere automatische Erkennung personenbezogener Daten in Nachrichten. Eingebaute Muster decken **Email, Telefon, Kreditkarte, IBAN, IP-Adresse, SSN, CVC, Geburtsdaten, Postadressen (43 Sprachen) sowie nationale Ausweise und Reisepässe** ab (Personalausweis, NIR, DNI/NIE, Codice Fiscale, BSN, PESEL, UK-NI-Nummer, kanadische SIN, irische PPS, Aadhaar, chinesischer 身份证, japanische My Number, koreanische RRN und 30+ weitere). Jeder Ausweistyp nutzt die kanonische Prüfsumme (ICAO 9303, Luhn, mod-11, Verhoeff, mod-23), damit zufällige Zeichenketten keine Treffer auslösen. Eigene Regex-Regeln ergänzen interne Formate (Mitarbeiter-ID, Ticket-Nummern, Produkt-SKUs). Erkannte PII in Anhängen durchläuft dieselbe Pipeline wie getippte Nachrichten.

Drei Durchsetzungsmodi:

- **Maskieren** — jeden Treffer durch einen festen Platzhalter ersetzen (`[EMAIL]`, `[PHONE]`, …). Empfohlen für Audit-Logs und gespeicherten Chat-Verlauf, in denen der Originalwert nicht mehr benötigt wird. Einbahnstraße: das Original ist weg.
- **Blockieren** — die gesamte Nachricht ablehnen. Empfohlen, wenn deine Richtlinie keinerlei PII an Upstream-Modelle erlaubt.
- **Tokenisieren** — jeden Treffer durch ein stabiles indiziertes Token ersetzen (`[EMAIL_1]`, `[PHONE_1]`) und eine pro-Nachricht-Zuordnung im Speicher halten. Das Modell sieht nur die Tokens; die Antwort enthält die Originaldaten wieder. Empfohlen für die natürlichste Nutzererfahrung ohne Schutzverlust. Die Zuordnung bleibt nur für den Round-Trip im Speicher und wird danach verworfen — niemals geloggt.

Ein eingebautes **Test-Playground** unter Einstellungen → Governance → PII zeigt den gesamten Round-Trip live: Tippe einen Satz und beobachte Erkennung → Tokenisierung → simulierte KI-Antwort → Wiederherstellung in Echtzeit. Fahre über eine markierte Stelle, um den erkannten Datentyp zu sehen (übersetzt).

#### Moderations-Anbieter

Expand Down
10 changes: 9 additions & 1 deletion docs/en/platform/admin/governance.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,15 @@ Open **Settings > Governance > Content safety**. Define categories (for example

#### PII detection {#pii-detection}

Enable automatic detection and masking (or blocking) of personally identifiable information in messages. Built-in patterns cover email, phone, credit-card and IBAN numbers, US-style addresses, and a few national IDs; custom regex rules let you add internal formats (employee ID, ticket numbers, product SKUs). Each pattern picks its own enforcement mode. Detected PII in attachments goes through the same pipeline as typed messages.
Enable automatic detection of personally identifiable information in messages. Built-in patterns cover **email, phone, credit-card, IBAN, IP address, SSN, CVC, dates of birth, postal addresses (43 locales), and national IDs / passports** (German Personalausweis, French NIR, Spanish DNI/NIE, Italian Codice Fiscale, Dutch BSN, Polish PESEL, UK National Insurance Number, Canadian SIN, Irish PPS, Indian Aadhaar, Chinese 身份证, Japanese My Number, Korean RRN, and 30+ more). Each ID type uses the canonical checksum (ICAO 9303, Luhn, mod-11, Verhoeff, mod-23) so randomly-shaped strings don't false-positive. Custom regex rules let you add internal formats (employee ID, ticket numbers, product SKUs). Detected PII in attachments goes through the same pipeline as typed messages.

Three enforcement modes:

- **Mask** — replace each match with a fixed placeholder (`[EMAIL]`, `[PHONE]`, …). Recommended for audit logs and stored chat history where the raw value is never needed again. One-way: the original is gone.
- **Block** — reject the entire message. Recommended when your policy forbids any PII reaching upstream models, full stop.
- **Tokenize** — replace each match with a stable indexed token (`[EMAIL_1]`, `[PHONE_1]`) and keep a per-message restore mapping. The model sees the tokens; the user sees their original details restored in the response. Recommended for the most natural UX without losing protection. The mapping is held in memory for the round-trip and discarded after — never written to logs.

A built-in **test playground** in Settings → Governance → PII shows the full round-trip live: type any sentence and watch detection → tokenization → mock AI response → restoration in real time. Hover any highlighted span to see its detected type (translated).

#### Moderation provider

Expand Down
10 changes: 9 additions & 1 deletion docs/fr/platform/admin/governance.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,15 @@ Ouvre **Paramètres > Gouvernance > Sécurité du contenu**. Définis des catég

#### Détection DCP {#pii-detection}

Active la détection automatique et le masquage (ou blocage) des données à caractère personnel dans les messages. Les patterns intégrés couvrent email, téléphone, numéros de carte et IBAN, adresses au format US et quelques identifiants nationaux ; des regex personnalisées ajoutent des formats internes (matricule, numéros de ticket, références produit). Chaque pattern a son propre mode d’application. Les DCP détectées dans les pièces jointes passent par la même pipeline que les messages saisis.
Active la détection automatique des données à caractère personnel dans les messages. Les patterns intégrés couvrent **email, téléphone, carte bancaire, IBAN, adresse IP, SSN, cryptogramme, dates de naissance, adresses postales (43 langues), ainsi que pièces d'identité et passeports nationaux** (Personalausweis, NIR, DNI/NIE, Codice Fiscale, BSN, PESEL, NI Number britannique, NAS canadien, PPS irlandais, Aadhaar, 身份证 chinois, My Number japonais, RRN coréen, et 30+ autres). Chaque type d'identifiant utilise la somme de contrôle canonique (ICAO 9303, Luhn, mod-11, Verhoeff, mod-23) pour éviter les faux positifs sur des chaînes aléatoires. Des regex personnalisées ajoutent des formats internes (matricule, numéros de ticket, références produit). Les DCP détectées dans les pièces jointes passent par la même pipeline que les messages saisis.

Trois modes d'application :

- **Masquer** — remplacer chaque correspondance par un espace réservé fixe (`[EMAIL]`, `[PHONE]`, …). Recommandé pour les journaux d'audit et l'historique de chat conservé, où la valeur d'origine n'est plus nécessaire. Sens unique : l'original est perdu.
- **Bloquer** — rejeter l'intégralité du message. Recommandé lorsque ta politique interdit toute DCP en amont des modèles.
- **Tokeniser** — remplacer chaque correspondance par un jeton indexé stable (`[EMAIL_1]`, `[PHONE_1]`) et conserver une table de restauration par message en mémoire. Le modèle ne voit que les jetons ; la réponse restitue les détails d'origine. Recommandé pour la meilleure expérience utilisateur sans perte de protection. La table de correspondance reste en mémoire le temps du round-trip puis est détruite — jamais journalisée.

Un **playground de test** intégré dans Paramètres → Gouvernance → DCP montre tout le round-trip en direct : tapez une phrase et observez détection → tokenisation → réponse IA simulée → restauration en temps réel. Survolez chaque surlignage pour voir le type de donnée détecté (traduit).

#### Fournisseur de modération

Expand Down
1 change: 1 addition & 0 deletions knip.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export default {
workspaces: {
'services/platform': {
vite: { config: ['vite.config.ts'] },
ignore: ['convex/_generated/**'],
entry: [
'app/routes/**/*.tsx',
'scripts/**/*.ts',
Expand Down
12 changes: 12 additions & 0 deletions packages/ui/.storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,23 @@ import {
import { useMemo, useState } from 'react';
import type { DecoratorFunction } from 'storybook/internal/types';

import { initServiceI18n } from '../src/i18n/init-service';
import { uiMessages } from '../src/i18n/messages';
import { ThemeContext } from '../src/theme';

import '../src/globals.css';
import '../src/markdown/globals.css';

// Bootstraps i18next with the package's own bundles so any story whose
// component calls `useT(...)` resolves real translations instead of
// rendering raw key names. Service consumers initialise the same way
// from their `lib/i18n/i18n.ts`; Storybook is the standalone harness.
initServiceI18n({
bundles: { en: {}, de: {}, fr: {} },
regional: {},
packages: [uiMessages],
});

const rootRoute = createRootRoute();

function createStoryRouter() {
Expand Down
1 change: 1 addition & 0 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"./i18n/init": "./src/i18n/init.ts",
"./i18n/init-service": "./src/i18n/init-service.ts",
"./i18n/locales": "./src/i18n/locales.ts",
"./i18n/messages": "./src/i18n/messages.ts",
"./i18n/provider": "./src/i18n/provider.tsx",
"./i18n/regional-bundles": "./src/i18n/regional-bundles.ts",
"./i18n/sync": "./src/i18n/sync.tsx",
Expand Down
90 changes: 86 additions & 4 deletions packages/ui/src/i18n/init-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,27 @@ import { collectRegionalBundles } from './regional-bundles';

type Bundle = Record<string, Record<string, unknown>>;

/**
* Translation bundles shipped by a frontend package (`@tale/ui`,
* `@tale/webui`, …). Mirrors the shape the host service uses for its
* own translations: per-locale namespace trees plus an optional
* cross-locale `global` for keys that read the same in every language
* (e.g. `languageSwitcher.locales.*` — the language names display in
* their own native form).
*/
export interface PackageMessages {
/**
* One entry per locale (`en`, `de`, `fr`, plus optional `xx-YY`
* regional codes). Each entry is a namespace → keys tree.
*/
bundles: Record<string, Bundle>;
/**
* Cross-locale keys merged into every base locale. The
* convention here matches `services/<x>/messages/global.json`.
*/
global?: Bundle;
}

interface InitServiceParams {
/** Base-locale bundles (`en`, `de`, `fr`) loaded statically by the service. */
bundles: {
Expand All @@ -18,21 +39,82 @@ interface InitServiceParams {
regional: Record<string, Bundle>;
/** Cross-namespace global keys (typically `services/<x>/messages/global.json`). */
global?: Bundle;
/**
* Per-package bundles to merge in *before* the service's own bundles, so
* any service-level key wins on conflict. Each entry is what a package
* exports from `@tale/<name>/i18n/messages`. Package namespaces should
* be scoped to the component family (`piiPlayground`,
* `languageSwitcher`, …) so they don't collide with service strings.
*/
packages?: ReadonlyArray<PackageMessages>;
}

/** Shallow merge at the namespace level — later entries win per namespace. */
function mergeBundles(...bundles: ReadonlyArray<Bundle | undefined>): Bundle {
const out: Bundle = {};
for (const b of bundles) {
if (!b) continue;
for (const [ns, value] of Object.entries(b)) {
out[ns] = { ...out[ns], ...value };
}
}
return out;
}

function packageBundle(
packages: ReadonlyArray<PackageMessages>,
locale: string,
): Bundle | undefined {
return mergeBundles(...packages.map((p) => p.bundles[locale]));
}

/**
* Thin wrapper over `initI18n` + `collectRegionalBundles` that captures the
* `services/<x>/lib/i18n/i18n.ts` boilerplate: load base bundles statically,
* `import.meta.glob` the regional variants, merge, and initialise. Every
* service does the same thing — this is the one place it lives.
* `import.meta.glob` the regional variants, layer in any package bundles,
* and initialise. Every service does the same thing — this is the one place
* it lives.
*/
export function initServiceI18n({
bundles,
regional,
global,
packages = [],
}: InitServiceParams) {
const regionalBundles = collectRegionalBundles(regional);

const merged: {
en: Bundle;
de: Bundle;
fr: Bundle;
} & Record<string, Bundle | undefined> = {
en: mergeBundles(packageBundle(packages, 'en'), bundles.en),
de: mergeBundles(packageBundle(packages, 'de'), bundles.de),
fr: mergeBundles(packageBundle(packages, 'fr'), bundles.fr),
};

// Layer remaining locales (regional overrides shipped by the service,
// extra base-locales the service registered, or regional bundles a
// package wants to ship even when the service itself has no override).
const extras = new Set<string>([
...Object.keys(bundles),
...Object.keys(regionalBundles),
...packages.flatMap((p) => Object.keys(p.bundles)),
]);
extras.delete('en');
extras.delete('de');
extras.delete('fr');
for (const locale of extras) {
const fromService = bundles[locale] ?? regionalBundles[locale];
merged[locale] = mergeBundles(packageBundle(packages, locale), fromService);
}

// Package globals fold in before the service's own global so any key
// the service redeclares overrides whatever a package shipped.
const mergedGlobal = mergeBundles(...packages.map((p) => p.global), global);

return initI18n({
bundles: { ...bundles, ...collectRegionalBundles(regional) },
global,
bundles: merged,
global: mergedGlobal,
});
}
29 changes: 29 additions & 0 deletions packages/ui/src/i18n/messages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import deMessages from '../messages/de.json';
import enMessages from '../messages/en.json';
import frMessages from '../messages/fr.json';
import globalMessages from '../messages/global.json';
import type { PackageMessages } from './init-service';

/**
* Translation bundles owned by `@tale/ui`. The host service merges these
* into its i18n instance via `initServiceI18n({ packages: [uiMessages] })`,
* so every component shipped here can call `useT(...)` without the
* consuming app duplicating the keys in its own `messages/*.json`.
*
* Locale-neutral keys (entries that read the same in every language)
* live in `global.json` and fold into every base locale — same
* convention services follow for their own `messages/global.json`.
*
* Each top-level key inside a locale bundle is a namespace scoped to
* the component family it serves (`piiPlayground`, `piiTypes`, …) —
* pick a name distinct enough that a service is unlikely to want it
* for its own keys.
*/
export const uiMessages: PackageMessages = {
bundles: {
en: enMessages,
de: deMessages,
fr: frMessages,
},
global: globalMessages,
};
1 change: 1 addition & 0 deletions packages/ui/src/messages/de.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions packages/ui/src/messages/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions packages/ui/src/messages/fr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions packages/ui/src/messages/global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
10 changes: 10 additions & 0 deletions packages/ui/src/messages/messages.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import path from 'node:path';
import { fileURLToPath } from 'node:url';

import { defineMessagesParityTests } from '../i18n-tests';

const HERE = path.dirname(fileURLToPath(import.meta.url));

defineMessagesParityTests({
messagesDir: HERE,
});
14 changes: 14 additions & 0 deletions packages/webui/.storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
import { withThemeByClassName } from '@storybook/addon-themes';
import type { Preview } from '@storybook/react';
import { initServiceI18n } from '@tale/ui/i18n/init-service';
import { uiMessages } from '@tale/ui/i18n/messages';

import { webuiMessages } from '../src/i18n/messages';

import '../src/globals.css';

// Bootstraps i18next with the package's own bundles so any story whose
// component calls `useT(...)` resolves real translations instead of
// rendering raw key names. Service consumers initialise the same way
// from their `lib/i18n/i18n.ts`; Storybook is the standalone harness.
initServiceI18n({
bundles: { en: {}, de: {}, fr: {} },
regional: {},
packages: [uiMessages, webuiMessages],
});

const preview: Preview = {
parameters: {
controls: {
Expand Down
Loading
Loading