domma-cms 1.59.0 → 1.61.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.
- package/CHANGELOG.md +17 -0
- package/admin/css/admin.css +1 -1
- package/admin/index.html +7 -1
- package/admin/js/app.js +7 -2
- package/admin/js/lib/ai-assist-settings-arrange.js +1 -0
- package/admin/js/lib/ai-assist.js +1 -0
- package/admin/js/lib/chat-presence.js +1 -0
- package/admin/js/lib/chat-toast.js +2 -2
- package/admin/js/lib/notifications-arrange.js +1 -1
- package/admin/js/lib/site-settings-arrange.js +3 -3
- package/admin/js/templates/ai-assist-builders.html +29 -0
- package/admin/js/templates/ai-assist-settings.html +80 -0
- package/admin/js/templates/chats.html +1 -1
- package/admin/js/templates/docs/usage-chat.html +20 -7
- package/admin/js/templates/settings.html +7 -27
- package/admin/js/views/ai-assist-builders.js +1 -0
- package/admin/js/views/ai-assist-settings.js +1 -0
- package/admin/js/views/chat-knowledge.js +6 -6
- package/admin/js/views/chats.js +4 -4
- package/admin/js/views/index.js +1 -1
- package/admin/js/views/login.js +1 -1
- package/admin/js/views/settings.js +3 -3
- package/docs/DommaFeatures.md +1 -1
- package/docs/plugin-development.md +26 -0
- package/package.json +1 -1
- package/server/routes/api/admin-assistant.js +14 -1
- package/server/routes/api/auth.js +4 -1
- package/server/routes/api/theme.js +2 -6
- package/server/server.js +12 -0
- package/server/services/aiAssist.js +79 -0
- package/server/services/chat/ai.js +1 -1
- package/server/services/chat/conversation.js +12 -4
- package/server/services/plugins.js +9 -1
- package/server/services/themeSettings.js +11 -0
|
@@ -38,7 +38,86 @@ export function isAiAssist() {
|
|
|
38
38
|
return owners.size > 0;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
/** The AI Assist screen (admin #/ai-assist): Chats, Knowledge and Settings when the Tool is on. */
|
|
42
|
+
export const AI_ASSIST_CHATS = '#/ai-assist/chats';
|
|
43
|
+
export const LAUNCHER_CHATS = '#/launchers/chats';
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Where the staff answer chats: AI Assist owns every chat on a site that has it;
|
|
47
|
+
* a site without it keeps the plain Chats screen under Launchers.
|
|
48
|
+
*/
|
|
49
|
+
export function chatsHome() {
|
|
50
|
+
return isAiAssist() ? AI_ASSIST_CHATS : LAUNCHER_CHATS;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// ---------------------------------------------------------------------------
|
|
54
|
+
// Builders: AI chats of other Tools, listed on AI Assist's Builders tab
|
|
55
|
+
// ---------------------------------------------------------------------------
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* plugin name -> its builder entry. A plugin declares one in plugin.json:
|
|
59
|
+
*
|
|
60
|
+
* "admin": {"aiAssist": {"label": "Site Builder", "url": "#/plugins/ai-site-builder",
|
|
61
|
+
* "list": "/api/plugins/ai-site-builder/conversations", "permission": "ai-builder",
|
|
62
|
+
* "character": "dot"}}
|
|
63
|
+
*
|
|
64
|
+
* `url` must be the plugin's own admin screen and `list` its own API: AI Assist only
|
|
65
|
+
* links to the plugin and reads its list with the viewer's own token, so the plugin's
|
|
66
|
+
* routes still decide what each person sees. Registered by the loader for enabled plugins.
|
|
67
|
+
*/
|
|
68
|
+
const builders = new Map();
|
|
69
|
+
const SLUG = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* What is wrong with a plugin's `admin.aiAssist` block, or ''.
|
|
73
|
+
*
|
|
74
|
+
* @param {string} plugin - the manifest name
|
|
75
|
+
* @param {object} block
|
|
76
|
+
*/
|
|
77
|
+
export function aiAssistBuilderProblem(plugin, block) {
|
|
78
|
+
if (!SLUG.test(String(plugin || ''))) return 'invalid plugin name';
|
|
79
|
+
if (!block || typeof block !== 'object' || Array.isArray(block)) return 'admin.aiAssist must be an object';
|
|
80
|
+
const own = (re) => new RegExp(re.replace('<p>', plugin.replace(/-/g, '\\-')));
|
|
81
|
+
if (typeof block.label !== 'string' || !block.label.trim() || block.label.length > 40) return 'label must be text of up to 40 characters';
|
|
82
|
+
if (typeof block.url !== 'string' || !own('^#/plugins/<p>(/[a-z0-9-]+)*$').test(block.url)) return `url must be this plugin's own screen (#/plugins/${plugin}...)`;
|
|
83
|
+
if (typeof block.list !== 'string' || !own('^/api/plugins/<p>(/[a-z0-9-]+)+$').test(block.list)) return `list must be this plugin's own API (/api/plugins/${plugin}/...)`;
|
|
84
|
+
if (typeof block.permission !== 'string' || !/^[a-z0-9][a-z0-9.-]{0,79}$/.test(block.permission)) return 'permission is required';
|
|
85
|
+
if (block.character !== undefined && (typeof block.character !== 'string' || !SLUG.test(block.character))) return 'character must be a character id';
|
|
86
|
+
return '';
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Register a loaded plugin's builder entry; returns the problem ('' when registered). */
|
|
90
|
+
export function registerAiAssistBuilder(plugin, block) {
|
|
91
|
+
const problem = aiAssistBuilderProblem(plugin, block);
|
|
92
|
+
if (problem) return problem;
|
|
93
|
+
builders.set(plugin, {plugin, label: block.label.trim(), url: block.url, list: block.list, permission: block.permission,
|
|
94
|
+
...(block.character ? {character: block.character} : {})});
|
|
95
|
+
return '';
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** The plugin was switched off: its chats leave the Builders tab at once, not at the next restart. */
|
|
99
|
+
export function unregisterAiAssistBuilder(plugin) {
|
|
100
|
+
return builders.delete(String(plugin || ''));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* The builders this viewer may open: they hold the entry's permission (the resource or
|
|
105
|
+
* any action of it), and a confined user's admin scope covers its screen.
|
|
106
|
+
*
|
|
107
|
+
* @param {{permissions: string[], adminScope?: {allow?: string[]}|null}} access - services/adminAccess.js adminAccessFor()
|
|
108
|
+
* @param {(prefix: string, path: string) => boolean} covers - services/pluginScope.js covers()
|
|
109
|
+
*/
|
|
110
|
+
export function aiAssistBuildersFor(access, covers) {
|
|
111
|
+
const perms = access?.permissions || [];
|
|
112
|
+
const holds = (p) => perms.includes(p) || perms.some(x => x.startsWith(`${p}.`)) || perms.includes(p.split('.')[0]);
|
|
113
|
+
const scope = access?.adminScope;
|
|
114
|
+
const inScope = (url) => !scope || (scope.allow || []).some(prefix => covers(prefix, url.slice(1)));
|
|
115
|
+
return [...builders.values()].filter(b => holds(b.permission) && inScope(b.url))
|
|
116
|
+
.map(({plugin, label, url, list, character}) => ({plugin, label, url, list, ...(character ? {character} : {})}));
|
|
117
|
+
}
|
|
118
|
+
|
|
41
119
|
/** Tests only: forget every owner. */
|
|
42
120
|
export function _resetAiAssistForTests() {
|
|
43
121
|
owners.clear();
|
|
122
|
+
builders.clear();
|
|
44
123
|
}
|
|
@@ -22,7 +22,7 @@ const REGISTRY = Symbol.for('domma.launcher-chat');
|
|
|
22
22
|
/** What a visitor will wait for an answer. */
|
|
23
23
|
const ASK_MS = 25_000;
|
|
24
24
|
/** Knowledge and chat sent at most: a reply is a few sentences, the prompt need not be a book. */
|
|
25
|
-
export const KNOWLEDGE_CHARS =
|
|
25
|
+
export const KNOWLEDGE_CHARS = 48_000;
|
|
26
26
|
export const HISTORY_MESSAGES = 10;
|
|
27
27
|
/** After the Manager says no (no licence, the month's answers used), ask again only after this. */
|
|
28
28
|
const BACKOFF_MS = {403: 10 * 60_000, 429: 30 * 60_000, other: 60_000};
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
*/
|
|
23
23
|
import {match} from './matcher.js';
|
|
24
24
|
import {notify, registerNotificationSource, resolveNotification} from '../notify.js';
|
|
25
|
+
import {chatsHome} from '../aiAssist.js';
|
|
25
26
|
import {
|
|
26
27
|
addMessage, cleanText, countHit, forgetSession, getSession, knowledgeIndex, listSessions, logUnanswered, messagesAfter,
|
|
27
28
|
patchSession, removeSession, removeSessionsAndOrphans, renderAnswer, staffAvailable, withChat
|
|
@@ -86,10 +87,17 @@ function raise(session, kind) {
|
|
|
86
87
|
const notice = kind === 'message'
|
|
87
88
|
? {severity: 'info', title: `${who} left a message in chat`, body: `Nobody was available, so they left their details${d.visitorEmail ? ` (${d.visitorEmail})` : ''}.${about}${where}`}
|
|
88
89
|
: {severity: 'warning', title: `${who} wants to talk to a person`, body: `They are waiting in chat now.${about}${where}`};
|
|
89
|
-
return notify({...notice, source: SOURCE, dedupeKey: noticeKey(session.id), link:
|
|
90
|
+
return notify({...notice, source: SOURCE, dedupeKey: noticeKey(session.id), link: chatsHome()}).catch(() => null);
|
|
90
91
|
}
|
|
91
92
|
|
|
92
|
-
|
|
93
|
+
/**
|
|
94
|
+
* Someone took the chat, or it ended: its "wants a person" and "started a chat"
|
|
95
|
+
* notices are settled, which also closes their pop-ups in every admin (chat-toast.js).
|
|
96
|
+
*/
|
|
97
|
+
const settle = (id) => Promise.all([
|
|
98
|
+
resolveNotification(noticeKey(id), SOURCE).catch(() => 0),
|
|
99
|
+
resolveNotification(`chat-started:${id}`, STARTED_SOURCE).catch(() => 0)
|
|
100
|
+
]);
|
|
93
101
|
|
|
94
102
|
/** What the admins are told about the chat: the visitor's words (as the Chats screen shows them) and the page. */
|
|
95
103
|
const quoted = (text) => `"${cleanText(text, 200).replace(/\n/g, ' ')}"`;
|
|
@@ -100,7 +108,7 @@ function raiseStarted(session, text, chat) {
|
|
|
100
108
|
const where = d.page ? `\nPage: ${d.page}` : '';
|
|
101
109
|
const who = chat.bot ? `${chat.botName || 'The bot'} is answering.` : 'It is waiting for a person.';
|
|
102
110
|
return notify({severity: 'info', title: `${d.visitorName || 'A visitor'} started a chat`, body: `${quoted(text)}\n\n${who}${where}`,
|
|
103
|
-
source: STARTED_SOURCE, dedupeKey: `chat-started:${session.id}`, link:
|
|
111
|
+
source: STARTED_SOURCE, dedupeKey: `chat-started:${session.id}`, link: chatsHome()}).catch(() => null);
|
|
104
112
|
}
|
|
105
113
|
|
|
106
114
|
/** The AI turned a question down. One notice per chat, said again in place for the next. */
|
|
@@ -109,7 +117,7 @@ function raiseDeclined(session, text, chat) {
|
|
|
109
117
|
const where = d.page ? `\nPage: ${d.page}` : '';
|
|
110
118
|
return notify({severity: 'info', title: `${chat.botName || 'The bot'} turned down a question in chat`,
|
|
111
119
|
body: `${d.visitorName || 'A visitor'} asked: ${quoted(text)}\n\nIt is off-topic or against the launcher's rules, so it was not answered.${where}`,
|
|
112
|
-
source: DECLINED_SOURCE, dedupeKey: `chat-declined:${session.id}`, link:
|
|
120
|
+
source: DECLINED_SOURCE, dedupeKey: `chat-declined:${session.id}`, link: chatsHome()}).catch(() => null);
|
|
113
121
|
}
|
|
114
122
|
|
|
115
123
|
// ---------------------------------------------------------------------------
|
|
@@ -43,7 +43,7 @@ import {disableInstantCalls, enableInstantCalls, grantInstantCallsOnce} from './
|
|
|
43
43
|
import {claimHosts} from './hostClaims.js';
|
|
44
44
|
import {pluginSafeFetch} from './outbound.js';
|
|
45
45
|
import {disableDashboardPro, enableDashboardPro, registerWidget, unregisterWidgetsFrom} from './widgets.js';
|
|
46
|
-
import {disableAiAssist, enableAiAssist} from './aiAssist.js';
|
|
46
|
+
import {disableAiAssist, enableAiAssist, registerAiAssistBuilder, unregisterAiAssistBuilder} from './aiAssist.js';
|
|
47
47
|
import {createCollection, getCollection, updateCollection} from './collections.js';
|
|
48
48
|
import * as defaultRolesService from './roles.js';
|
|
49
49
|
import {getAdminScope, normaliseAdminScope} from './roles.js';
|
|
@@ -624,6 +624,13 @@ export async function registerPlugins(fastify) {
|
|
|
624
624
|
}
|
|
625
625
|
}
|
|
626
626
|
|
|
627
|
+
// AI Assist's Builders tab (services/aiAssist.js): this plugin's AI chats, linked
|
|
628
|
+
// from there. Only its own screen and API are accepted.
|
|
629
|
+
if (manifest.admin?.aiAssist) {
|
|
630
|
+
const problem = registerAiAssistBuilder(manifest.name, manifest.admin.aiAssist);
|
|
631
|
+
if (problem) fastify.log.warn(`[plugins] admin.aiAssist for "${manifest.name}" skipped: ${problem}`);
|
|
632
|
+
}
|
|
633
|
+
|
|
627
634
|
// Dashboard widgets the manifest offers (services/widgets.js) - drawn by the admin
|
|
628
635
|
// from their `kind` and `dataUrl`, so a Tool needs no code to have one.
|
|
629
636
|
for (const def of manifest.admin?.widgets || []) {
|
|
@@ -1172,6 +1179,7 @@ export async function runLifecycleHook(name, hook, fastify) {
|
|
|
1172
1179
|
disableInstantCalls(name);
|
|
1173
1180
|
disableDashboardPro(name);
|
|
1174
1181
|
disableAiAssist(name);
|
|
1182
|
+
unregisterAiAssistBuilder(name);
|
|
1175
1183
|
unregisterWidgetsFrom(name);
|
|
1176
1184
|
unregisterContactAccess(name);
|
|
1177
1185
|
unregisterDirectMessenger(name);
|
|
@@ -368,6 +368,17 @@ export function compileCustomThemeCss(ids = null) {
|
|
|
368
368
|
.join('\n\n');
|
|
369
369
|
}
|
|
370
370
|
|
|
371
|
+
/** Presentation shared by authenticated admin and anonymous sign-in screens.
|
|
372
|
+
* Callers choose the id; sign-in exposes only the saved admin theme.
|
|
373
|
+
*/
|
|
374
|
+
export function adminThemePresentation(id, cfg = {}) {
|
|
375
|
+
const theme = id || cfg.adminTheme || DEFAULT_THEME;
|
|
376
|
+
const {dommaTheme, customClass} = resolveThemeClasses(theme, cfg);
|
|
377
|
+
return {theme, dommaTheme, customClass, css: customClass ? compileCustomThemeCss([theme]) : '',
|
|
378
|
+
font: {family: cfg.font?.adminFamily || '', stylesheet: cfg.font?.stylesheet || ''},
|
|
379
|
+
sidebar: cfg.adminSidebar !== false};
|
|
380
|
+
}
|
|
381
|
+
|
|
371
382
|
/**
|
|
372
383
|
* The page-head `<style>` for the custom themes a page can show, or ''. Only
|
|
373
384
|
* those: every theme a Roller keeps is ~250 tokens, and an unused draft's
|