domma-cms 1.70.0 → 1.71.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 +6 -0
- package/package.json +1 -1
- package/plugins/feedback/CHANGELOG.md +5 -0
- package/plugins/feedback/CLAUDE.md +26 -0
- package/plugins/feedback/admin/css/index.css +11 -0
- package/plugins/feedback/admin/lib/ai.js +41 -0
- package/plugins/feedback/admin/lib/kit.js +3 -1
- package/plugins/feedback/admin/views/feedback.js +1 -1
- package/plugins/feedback/admin/views/inbox.js +58 -2
- package/plugins/feedback/docs/guide.md +2 -0
- package/plugins/feedback/lib/ai-text.js +217 -0
- package/plugins/feedback/lib/receiver.js +10 -0
- package/plugins/feedback/lib/themes.js +75 -0
- package/plugins/feedback/plugin.js +39 -2
- package/plugins/feedback/plugin.json +2 -2
- package/plugins/feedback/tests/ai.test.js +248 -0
- package/plugins/free-tier.lock.json +31 -21
- package/plugins/support/CHANGELOG.md +5 -0
- package/plugins/support/CLAUDE.md +33 -0
- package/plugins/support/admin/css/index.css +14 -0
- package/plugins/support/admin/lib/ai.js +68 -0
- package/plugins/support/admin/lib/kit.js +5 -1
- package/plugins/support/admin/views/inbox.js +121 -4
- package/plugins/support/admin/views/support.js +1 -1
- package/plugins/support/docs/guide.md +5 -0
- package/plugins/support/lib/ai-text.js +217 -0
- package/plugins/support/lib/assist.js +74 -0
- package/plugins/support/lib/receiver.js +2 -1
- package/plugins/support/plugin.js +73 -3
- package/plugins/support/plugin.json +2 -2
- package/plugins/support/tests/ai.test.js +245 -0
|
@@ -25,6 +25,9 @@
|
|
|
25
25
|
* GET /reports/:id/attachments/:att a report's file
|
|
26
26
|
* GET /waypoint is Waypoint Pro here, and its projects
|
|
27
27
|
* POST /reports/:id/promote make a Waypoint issue from a report
|
|
28
|
+
* POST /themes "Summarise": the reports in the inbox's current view, grouped into
|
|
29
|
+
* themes by Claude through AI Assist (the Manager's own service, in
|
|
30
|
+
* this process; only when AI Assist is on). The latest is kept.
|
|
28
31
|
*
|
|
29
32
|
* Nothing the browser sends says who sent a report or which site it came from:
|
|
30
33
|
* the user is the session's, the site is the one the fleet token names.
|
|
@@ -39,6 +42,8 @@ import {
|
|
|
39
42
|
} from './lib/shape.js';
|
|
40
43
|
import {createStore, readUpload, sendFile} from './lib/attachments.js';
|
|
41
44
|
import {createOutbox, flush, managerApi, managerOf, mergeReports, newRef} from './lib/sender.js';
|
|
45
|
+
import {aiFailure, aiTextAvailable, cleanThemes, createKept, requestAiText} from './lib/ai-text.js';
|
|
46
|
+
import {THEMES_MAX, THEMES_SURVEY, cleanFilter, filterText, reportsInView, themesAnswers} from './lib/themes.js';
|
|
42
47
|
import {getEffectiveLevel} from '../../server/services/userRoles.js';
|
|
43
48
|
import {getPluginSettings, getPluginStates, savePluginState} from '../../server/services/plugins.js';
|
|
44
49
|
|
|
@@ -247,6 +252,7 @@ async function receiverRoutes(fastify, {can, authenticate, requirePermission, ho
|
|
|
247
252
|
const rx = receiverMod;
|
|
248
253
|
const slugOf = options.slugFromToken || rx.slugFromToken;
|
|
249
254
|
const siteNames = options.siteNames || rx.siteNames;
|
|
255
|
+
const siteHosts = options.siteHosts || rx.siteHosts;
|
|
250
256
|
// The manager's own reports are filed as `_manager` - a slug no site can have (theirs start [a-z0-9]).
|
|
251
257
|
const names = () => ({...siteNames(), [rx.MANAGER_SITE]: rx.MANAGER_NAME});
|
|
252
258
|
// Its own feedback: the level-0 role only, on top of the `feedback` send permission.
|
|
@@ -256,6 +262,8 @@ async function receiverRoutes(fastify, {can, authenticate, requirePermission, ho
|
|
|
256
262
|
const own = {preHandler: [authenticate, requirePermission('feedback', 'send'), topOnly]};
|
|
257
263
|
const dataDir = options.dataDir || path.join(HERE, 'data');
|
|
258
264
|
const ownSeen = createOutbox(dataDir, 'own.json');
|
|
265
|
+
// The latest "Summarise" result (AI Assist), shown again until the next one.
|
|
266
|
+
const kept = createKept(path.join(dataDir, 'ai.json'));
|
|
259
267
|
// The per-site brakes take their limits at each call (the cog changes them live).
|
|
260
268
|
const reportThrottle = createThrottle();
|
|
261
269
|
const fileThrottle = createThrottle();
|
|
@@ -332,7 +340,9 @@ async function receiverRoutes(fastify, {can, authenticate, requirePermission, ho
|
|
|
332
340
|
|
|
333
341
|
// ---- The inbox ----
|
|
334
342
|
|
|
335
|
-
|
|
343
|
+
// `ai`: whether "Summarise" is offered (AI Assist on, and the Manager's AI Assist service here).
|
|
344
|
+
fastify.get('/mode', can('manage'), async (request) => ({mode: 'receiver', waypoint: Boolean(waypoint()), canSend: isTopLevel(request.user),
|
|
345
|
+
ai: aiTextAvailable('themes')}));
|
|
336
346
|
|
|
337
347
|
fastify.get('/count', can('manage'), async (request) => {
|
|
338
348
|
const all = await rx.allReports();
|
|
@@ -415,8 +425,33 @@ async function receiverRoutes(fastify, {can, authenticate, requirePermission, ho
|
|
|
415
425
|
|
|
416
426
|
fastify.get('/reports', can('manage'), async () => {
|
|
417
427
|
const n = names();
|
|
428
|
+
const last = kept.get('themes');
|
|
418
429
|
return {sites: n, reports: (await rx.allReports()).map(e => ({id: e.id, ...e.data, siteName: n[e.data.site] || e.data.site,
|
|
419
|
-
createdAt: e.meta?.createdAt, updatedAt: e.meta?.updatedAt}))};
|
|
430
|
+
createdAt: e.meta?.createdAt, updatedAt: e.meta?.updatedAt})), themes: last ? cleanThemes(last) : null};
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* "Summarise" (AI Assist): the reports the inbox shows for {status, type, site, q} - its filter as it
|
|
435
|
+
* stands - grouped into themes by Claude. Only their titles and descriptions go, cleaned (lib/themes.js):
|
|
436
|
+
* no site names, people's names, emails or files. The result is kept (data/ai.json) until the next.
|
|
437
|
+
*/
|
|
438
|
+
fastify.post('/themes', can('manage'), async (request, reply) => {
|
|
439
|
+
if (!aiTextAvailable('themes')) return reply.code(403).send({error: 'Summaries come with AI Assist, in the Pro plan.'});
|
|
440
|
+
const filter = cleanFilter(request.body || {});
|
|
441
|
+
const n = names();
|
|
442
|
+
const shown = reportsInView(await rx.allReports(), filter, n);
|
|
443
|
+
const answers = themesAnswers(shown, n, siteHosts());
|
|
444
|
+
if (answers.length < 2) return reply.code(400).send({error: 'There need to be at least two reports to summarise.'});
|
|
445
|
+
const question = filterText(filter);
|
|
446
|
+
const res = await requestAiText({task: 'themes', kind: 'feedback', survey: THEMES_SURVEY, question, answers});
|
|
447
|
+
const failed = aiFailure(res, 'Claude would not summarise these reports.');
|
|
448
|
+
if (failed) return reply.code(failed.status).send(failed.body);
|
|
449
|
+
const result = cleanThemes({at: new Date().toISOString(), filter: question, answers: res.body.answers ?? answers.length,
|
|
450
|
+
summary: res.body.summary, themes: res.body.themes});
|
|
451
|
+
// Which reports it read (never shown): deleting one of them drops the summary, which may quote it.
|
|
452
|
+
try { kept.set('themes', {...result, ids: shown.slice(0, THEMES_MAX.answers).map(e => e.id)}); }
|
|
453
|
+
catch (err) { fastify.log.warn(`[feedback] summary not kept: ${err.message}`); }
|
|
454
|
+
return {...result, used: res.body.used, limit: res.body.limit};
|
|
420
455
|
});
|
|
421
456
|
|
|
422
457
|
fastify.get('/reports/:id', can('manage'), async (request, reply) => {
|
|
@@ -459,6 +494,8 @@ async function receiverRoutes(fastify, {can, authenticate, requirePermission, ho
|
|
|
459
494
|
if (!e) return reply.code(404).send({error: 'No such report.'});
|
|
460
495
|
await rx.removeReport(e.id);
|
|
461
496
|
files.removeAll(e.id);
|
|
497
|
+
// A kept summary that read this report may quote it: it goes too.
|
|
498
|
+
try { if ((kept.get('themes')?.ids || []).includes(e.id)) kept.remove('themes'); } catch { /* tidying only */ }
|
|
462
499
|
return {ok: true};
|
|
463
500
|
});
|
|
464
501
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "feedback",
|
|
3
3
|
"displayName": "Feedback",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.4.0",
|
|
5
5
|
"minCmsVersion": "1.67.2",
|
|
6
6
|
"tier": "free",
|
|
7
7
|
"description": "Tell Domma what is broken, missing or good - straight from your admin - and see what became of it: seen, planned, in progress, done, with Domma's reply.",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
],
|
|
42
42
|
"views": {
|
|
43
43
|
"plugin-feedback": {
|
|
44
|
-
"entry": "feedback/admin/views/feedback.js?v=1.
|
|
44
|
+
"entry": "feedback/admin/views/feedback.js?v=1.4.0",
|
|
45
45
|
"exportName": "feedbackView"
|
|
46
46
|
}
|
|
47
47
|
}
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* "Summarise" in the Manager's inbox (AI Assist): lib/ai-text.js, lib/themes.js, the route and the card.
|
|
3
|
+
* The Manager's AI Assist service is a stub on globalThis[Symbol.for('domma.ai-text')]: nothing reaches Claude.
|
|
4
|
+
*/
|
|
5
|
+
import {test, before, after} from 'node:test';
|
|
6
|
+
import assert from 'node:assert/strict';
|
|
7
|
+
import fs from 'node:fs/promises';
|
|
8
|
+
import os from 'node:os';
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
import Fastify from 'fastify';
|
|
11
|
+
import feedback from '../plugin.js';
|
|
12
|
+
import {aiFailure, aiTextAvailable, cleanThemes, createKept, requestAiText, scrubText, useAiAssistLookup} from '../lib/ai-text.js';
|
|
13
|
+
import {cleanFilter, filterText, reportsInView, themesAnswers} from '../lib/themes.js';
|
|
14
|
+
import {themesCard, themesQuestion, usageText} from '../admin/lib/ai.js';
|
|
15
|
+
import {buildPayload, cleanSubmission} from '../lib/shape.js';
|
|
16
|
+
import {forget, receive} from '../lib/receiver.js';
|
|
17
|
+
|
|
18
|
+
const LOCAL = Symbol.for('domma.ai-text');
|
|
19
|
+
const PLUGINS = path.resolve('config/plugins.json');
|
|
20
|
+
const COLL = path.resolve('content/collections/feedback-reports');
|
|
21
|
+
let savedPlugins;
|
|
22
|
+
let dir;
|
|
23
|
+
let app;
|
|
24
|
+
let sent = [];
|
|
25
|
+
|
|
26
|
+
/** The Manager's service, stubbed: records what it was sent, answers as told. */
|
|
27
|
+
function stubRegistry(answer = (body) => ({status: 200, body: {summary: 'Mostly saving.', answers: body.answers.length,
|
|
28
|
+
themes: [{title: 'Saving', detail: 'Work is lost on save.', count: 2, quotes: ['gone']}], used: 7, limit: 500}})) {
|
|
29
|
+
globalThis[LOCAL] = {version: 1, tasks: ['themes', 'subjects', 'draft', 'rewrite', 'summary', 'reply'],
|
|
30
|
+
run: async (body) => { sent.push(body); return answer(body); }};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const call = async (method, url, body) => {
|
|
34
|
+
const res = await app.inject({method, url, payload: body});
|
|
35
|
+
return {status: res.statusCode, body: res.json()};
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
async function file(site, report, user = {id: 'u1', name: 'Sam Smith', email: 'sam@acme.test'}) {
|
|
39
|
+
const {report: r, error} = cleanSubmission(report);
|
|
40
|
+
assert.equal(error, undefined);
|
|
41
|
+
const out = await receive(site, buildPayload({report: r, user, site, ref: `ref-${Math.random().toString(36).slice(2)}`}));
|
|
42
|
+
assert.ok(out.entry, out.error);
|
|
43
|
+
return out.entry;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
before(async () => {
|
|
47
|
+
savedPlugins = await fs.readFile(PLUGINS, 'utf8').catch(() => null);
|
|
48
|
+
await fs.rm(COLL, {recursive: true, force: true});
|
|
49
|
+
dir = await fs.mkdtemp(path.join(os.tmpdir(), 'feedback-ai-'));
|
|
50
|
+
app = Fastify();
|
|
51
|
+
await app.register(feedback, {
|
|
52
|
+
auth: {authenticate: async (req) => { req.user = {id: 'v1', name: 'Vendor', role: 'admin'}; }, requirePermission: () => async () => {}},
|
|
53
|
+
dataDir: dir, readSettings: async () => ({}), mode: 'receiver', timer: false,
|
|
54
|
+
slugFromToken: async () => null, siteNames: () => ({acme: 'Acme Ltd', beta: 'Beta Co'}),
|
|
55
|
+
siteHosts: () => ({acme: ['acme.example.test', 'acme.sites.example.test'], beta: ['beta.example.test']}),
|
|
56
|
+
hooks: {}
|
|
57
|
+
});
|
|
58
|
+
await file('acme', {type: 'bug', severity: 'major', title: 'Save loses text', description: 'Typed, saved, gone on https://acme.sites.example.test/contact. Sam here: call me on 07700 900123 or sam@acme.test', where: '/admin/#/pages'});
|
|
59
|
+
await file('beta', {type: 'bug', title: 'Save button greyed', description: 'It never comes back on Beta Co. Version 1.58.0 on 2026-11-16.'});
|
|
60
|
+
await file('acme', {type: 'feature', title: 'Dark mode', description: 'Please.'});
|
|
61
|
+
forget();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
after(async () => {
|
|
65
|
+
delete globalThis[LOCAL];
|
|
66
|
+
useAiAssistLookup(null);
|
|
67
|
+
await app?.close();
|
|
68
|
+
await fs.rm(COLL, {recursive: true, force: true});
|
|
69
|
+
await fs.rm(dir, {recursive: true, force: true});
|
|
70
|
+
if (savedPlugins === null) await fs.rm(PLUGINS, {force: true});
|
|
71
|
+
else await fs.writeFile(PLUGINS, savedPlugins);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('scrubText takes out emails, phone numbers, quoted mail and signatures, and keeps dates and versions', () => {
|
|
75
|
+
const out = scrubText('Hi,\nmail me at jo.bloggs@example.co.uk or +44 (0)20 7946 0958.\nOn 2026-11-16 we saw 1.58.0 fail.\n> earlier text\n-- \nJo Bloggs\nCEO');
|
|
76
|
+
assert.ok(!out.includes('jo.bloggs'));
|
|
77
|
+
assert.ok(!out.includes('7946'));
|
|
78
|
+
assert.ok(out.includes('[email]') && out.includes('[phone]'));
|
|
79
|
+
assert.ok(out.includes('2026-11-16') && out.includes('1.58.0'));
|
|
80
|
+
assert.ok(!out.includes('earlier text') && !out.includes('CEO'));
|
|
81
|
+
assert.equal(scrubText('On Mon, 16 Nov 2026, Jo wrote:\n> hi\n'), '');
|
|
82
|
+
assert.equal(scrubText('x'.repeat(50), 10).length, 10);
|
|
83
|
+
assert.equal(scrubText('Thanks Ann - ANN SMITH here, Annette too', 200, {names: ['Ann Smith', '']}), 'Thanks [name] - [name] here, Annette too');
|
|
84
|
+
assert.match(scrubText('a.b (c) axb', 200, {names: ['a.b', '(c)']}), /^\[name\] \(c\) axb$/);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test('scrubText: known names in any case, as whole words, and from the email address', () => {
|
|
88
|
+
const names = {names: ['Darryl Waterhouse']};
|
|
89
|
+
assert.equal(scrubText('thanks, darryl - DARRYL here. Darrylish stays. waterhouse too', 200, names), 'thanks, [name] - [name] here. Darrylish stays. [name] too');
|
|
90
|
+
// No name given ("A site admin" stands in): the email's local part still names them; "site" and "admin" stay words.
|
|
91
|
+
assert.equal(scrubText('john says the site admin page fails, Smith agrees', 200, {names: ['A site admin'], emails: ['john.smith@acme.test']}),
|
|
92
|
+
'[name] says the site admin page fails, [name] agrees');
|
|
93
|
+
assert.equal(scrubText('info is here', 200, {emails: ['info@acme.test', 'jo_ann-7@x.io']}), 'info is here');
|
|
94
|
+
assert.equal(scrubText('ask jo or ann', 200, {emails: ['jo_ann-7@x.io']}), 'ask [name] or [name]');
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test('scrubText: a greeting at the start and a sign-off with the short lines under it go', () => {
|
|
98
|
+
assert.equal(scrubText('Hi Darryl,\nThe page fails.'), 'The page fails.');
|
|
99
|
+
assert.equal(scrubText('Hello there\nThe page fails.'), 'The page fails.');
|
|
100
|
+
assert.equal(scrubText('Dear Sir or Madam, the page fails.'), 'the page fails.');
|
|
101
|
+
assert.equal(scrubText('Hey Jo, it fails again.'), 'it fails again.');
|
|
102
|
+
// Only at the start: a "hi" later is kept.
|
|
103
|
+
assert.equal(scrubText('The page fails.\nHi again, still broken.'), 'The page fails.\nHi again, still broken.');
|
|
104
|
+
assert.equal(scrubText('It fails.\n\nThanks,\nAnn Jones\nOffice manager\nAcme Ltd\nPS it is the contact page, every time I save it'),
|
|
105
|
+
'It fails.\n\nPS it is the contact page, every time I save it');
|
|
106
|
+
assert.equal(scrubText('It fails.\nKind regards\nAnn'), 'It fails.');
|
|
107
|
+
assert.equal(scrubText('It fails.\nCheers, Jo'), 'It fails.');
|
|
108
|
+
assert.equal(scrubText('It fails.\nThank you so much'), 'It fails.');
|
|
109
|
+
assert.equal(scrubText('It fails.\nBest,\nJo'), 'It fails.');
|
|
110
|
+
// Sentences that only start like one are kept.
|
|
111
|
+
assert.equal(scrubText('Best way is to save twice.\nThanks for the quick fix yesterday, it all works now.'), 'Best way is to save twice.\nThanks for the quick fix yesterday, it all works now.');
|
|
112
|
+
// A title is not a letter.
|
|
113
|
+
assert.equal(scrubText('Hi there', 200, {letter: false}), 'Hi there');
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test('scrubText: a site\'s name and domains, and links on them, go', () => {
|
|
117
|
+
const sites = {sites: ['Acme Ltd', 'acme.example.test']};
|
|
118
|
+
assert.equal(scrubText('On ACME LTD see https://www.acme.example.test/contact?x=1 and acme.example.test/pages.', 200, sites),
|
|
119
|
+
'On [site] see [site] and [site].');
|
|
120
|
+
assert.equal(scrubText('Not acme.example.testing nor https://example.test/', 200, sites), 'Not acme.example.testing nor https://example.test/');
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test('available only with AI Assist AND the Manager\'s service in this process; never throws', async () => {
|
|
124
|
+
delete globalThis[LOCAL];
|
|
125
|
+
useAiAssistLookup(() => true);
|
|
126
|
+
assert.equal(aiTextAvailable('themes'), false);
|
|
127
|
+
assert.equal((await requestAiText({task: 'themes'})).status, 503);
|
|
128
|
+
stubRegistry();
|
|
129
|
+
assert.equal(aiTextAvailable('themes'), true);
|
|
130
|
+
assert.equal(aiTextAvailable('nope'), false);
|
|
131
|
+
useAiAssistLookup(() => false);
|
|
132
|
+
assert.equal(aiTextAvailable('themes'), false);
|
|
133
|
+
assert.equal((await requestAiText({task: 'themes'})).status, 403);
|
|
134
|
+
useAiAssistLookup(() => true);
|
|
135
|
+
globalThis[LOCAL] = {version: 1, tasks: ['themes'], run: async () => { throw new Error('boom'); }};
|
|
136
|
+
assert.equal((await requestAiText({task: 'themes'})).status, 503);
|
|
137
|
+
assert.equal(aiFailure({status: 200, body: {summary: 's'}}), null);
|
|
138
|
+
assert.equal(aiFailure({status: 200, body: {declined: true, used: 1, limit: 5}}, 'No.').status, 422);
|
|
139
|
+
assert.deepEqual(aiFailure({status: 429, body: {error: 'All used.', used: 500, limit: 500}}).body, {error: 'All used.', used: 500, limit: 500});
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
test('the view: status, type, site and search as the inbox has them; the filter described without names or words', () => {
|
|
143
|
+
const e = (id, data, createdAt) => ({id, data, meta: {createdAt}});
|
|
144
|
+
const list = [e('a', {status: 'new', type: 'bug', site: 'acme', title: 'A'}, '2026-01-01'), e('b', {status: 'done', type: 'bug', site: 'beta', title: 'B'}, '2026-01-03'),
|
|
145
|
+
e('c', {status: 'planned', type: 'feature', site: 'acme', title: 'C words'}, '2026-01-02')];
|
|
146
|
+
assert.deepEqual(reportsInView(list, cleanFilter({})).map(x => x.id), ['c', 'a']);
|
|
147
|
+
assert.deepEqual(reportsInView(list, cleanFilter({status: 'all', type: 'bug'})).map(x => x.id), ['b', 'a']);
|
|
148
|
+
assert.deepEqual(reportsInView(list, cleanFilter({status: 'all', site: 'acme', q: 'words'})).map(x => x.id), ['c']);
|
|
149
|
+
assert.deepEqual(reportsInView(list, cleanFilter({status: 'all', q: 'acme ltd'}), {acme: 'Acme Ltd'}).map(x => x.id), ['c', 'a']);
|
|
150
|
+
assert.deepEqual(cleanFilter({status: 'bogus', type: 'bogus', site: 5}), {status: 'open', type: '', site: '', q: ''});
|
|
151
|
+
assert.equal(filterText(cleanFilter({status: 'new', type: 'bug'})), 'Reports marked New, Bug only');
|
|
152
|
+
const described = filterText(cleanFilter({status: 'all', site: 'acme', q: 'secret words'}));
|
|
153
|
+
assert.equal(described, 'Every report, from one site, matching a search');
|
|
154
|
+
assert.deepEqual(themesAnswers([{data: {title: 'Hi', description: '<p>Mail <b>me@x.io</b></p>'}}, {data: {title: '', description: ''}}]), ['Hi. Mail [email]']);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
test('POST /themes sends only the reports in view, as text, and keeps the result', async () => {
|
|
158
|
+
useAiAssistLookup(() => true);
|
|
159
|
+
stubRegistry();
|
|
160
|
+
sent = [];
|
|
161
|
+
assert.equal((await call('GET', '/mode')).body.ai, true);
|
|
162
|
+
const r = await call('POST', '/themes', {status: 'open', type: 'bug'});
|
|
163
|
+
assert.equal(r.status, 200, JSON.stringify(r.body));
|
|
164
|
+
assert.equal(sent.length, 1);
|
|
165
|
+
const body = sent[0];
|
|
166
|
+
assert.equal(body.task, 'themes');
|
|
167
|
+
assert.equal(body.kind, 'feedback');
|
|
168
|
+
assert.equal(body.survey, 'Feedback from Domma sites');
|
|
169
|
+
assert.equal(body.question, 'Open reports (not done or not planned), Bug only');
|
|
170
|
+
assert.equal(body.answers.length, 2);
|
|
171
|
+
const wire = JSON.stringify(body);
|
|
172
|
+
for (const secret of ['Acme', 'acme', 'Beta', 'Sam', 'sam@acme.test', '07700', '/admin/#/pages', 'Dark mode', '/contact']) assert.ok(!wire.includes(secret), secret);
|
|
173
|
+
assert.ok(body.answers.some(a => a.startsWith('Save loses text. Typed, saved, gone on [site].')), body.answers.join(' | '));
|
|
174
|
+
assert.ok(body.answers.includes('Save button greyed. It never comes back on [site]. Version 1.58.0 on 2026-11-16.'), body.answers.join(' | '));
|
|
175
|
+
assert.ok(body.answers.some(a => a.includes('[name] here: call me on [phone] or [email]')), body.answers.join(' | '));
|
|
176
|
+
assert.equal(r.body.summary, 'Mostly saving.');
|
|
177
|
+
assert.equal(r.body.answers, 2);
|
|
178
|
+
assert.equal(r.body.used, 7);
|
|
179
|
+
assert.equal(r.body.themes[0].quotes[0], 'gone');
|
|
180
|
+
// Kept: the inbox shows it again.
|
|
181
|
+
const list = await call('GET', '/reports');
|
|
182
|
+
assert.equal(list.body.themes.summary, 'Mostly saving.');
|
|
183
|
+
assert.equal(list.body.themes.filter, 'Open reports (not done or not planned), Bug only');
|
|
184
|
+
assert.equal(list.body.themes.ids, undefined, 'which reports it read stays on the server');
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
test('POST /themes: too few, no AI Assist, a decline and the allowance pass through', async () => {
|
|
188
|
+
useAiAssistLookup(() => true);
|
|
189
|
+
stubRegistry();
|
|
190
|
+
sent = [];
|
|
191
|
+
assert.equal((await call('POST', '/themes', {status: 'open', type: 'feature'})).status, 400);
|
|
192
|
+
assert.equal(sent.length, 0);
|
|
193
|
+
stubRegistry(() => ({status: 200, body: {declined: true, used: 8, limit: 500}}));
|
|
194
|
+
const declined = await call('POST', '/themes', {status: 'all'});
|
|
195
|
+
assert.equal(declined.status, 422);
|
|
196
|
+
assert.match(declined.body.error, /would not/);
|
|
197
|
+
stubRegistry(() => ({status: 429, body: {error: 'This site has used its 500 AI Assist summaries.', used: 500, limit: 500}}));
|
|
198
|
+
const spent = await call('POST', '/themes', {status: 'all'});
|
|
199
|
+
assert.equal(spent.status, 429);
|
|
200
|
+
assert.equal(spent.body.error, 'This site has used its 500 AI Assist summaries.');
|
|
201
|
+
// The failed ones did not replace the kept result.
|
|
202
|
+
assert.equal((await call('GET', '/reports')).body.themes.summary, 'Mostly saving.');
|
|
203
|
+
useAiAssistLookup(() => false);
|
|
204
|
+
assert.equal((await call('GET', '/mode')).body.ai, false);
|
|
205
|
+
assert.equal((await call('POST', '/themes', {status: 'all'})).status, 403);
|
|
206
|
+
delete globalThis[LOCAL];
|
|
207
|
+
useAiAssistLookup(() => true);
|
|
208
|
+
assert.equal((await call('GET', '/mode')).body.ai, false);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
test('the card: label, note, counts and quotes; the question names what goes and what does not', () => {
|
|
212
|
+
assert.equal(themesCard(null, {shown: 1}).canSummarise, false);
|
|
213
|
+
assert.equal(themesCard(null, {shown: 3}).label, 'Summarise');
|
|
214
|
+
assert.equal(themesCard(null, {shown: 3, busy: true}).label, 'Summarising...');
|
|
215
|
+
assert.equal(themesCard(null, {shown: 3, busy: true}).canSummarise, false);
|
|
216
|
+
const card = themesCard(cleanThemes({at: '2026-11-16T12:00:00Z', filter: 'Reports marked New', answers: 3, summary: 'S',
|
|
217
|
+
themes: [{title: 'T', detail: 'D', count: 1, quotes: ['a', 'b']}]}), {shown: 3});
|
|
218
|
+
assert.equal(card.label, 'Summarise again');
|
|
219
|
+
assert.equal(card.themes[0].countText, '1 report');
|
|
220
|
+
assert.equal(card.themes[0].quotesText, '"a" · "b"');
|
|
221
|
+
assert.match(card.note, /^AI summary of 3 reports \(Reports marked New\), /);
|
|
222
|
+
assert.match(themesQuestion(4), /4 reports.*no site names, people's names, email addresses or files/);
|
|
223
|
+
assert.equal(usageText({used: 3, limit: 500}), 'Summarised. 3 of 500 AI Assist requests used this month.');
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
test('createKept: private, read back, removed', async () => {
|
|
227
|
+
const f = path.join(dir, 'kept', 'ai.json');
|
|
228
|
+
const kept = createKept(f);
|
|
229
|
+
assert.equal(kept.get('x'), null);
|
|
230
|
+
kept.set('x', {a: 1});
|
|
231
|
+
assert.deepEqual(createKept(f).get('x'), {a: 1});
|
|
232
|
+
assert.equal((await fs.stat(f)).mode & 0o777, 0o600);
|
|
233
|
+
kept.remove('x');
|
|
234
|
+
assert.equal(kept.get('x'), null);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
test('deleting a report the kept summary read drops the summary; another report leaves it', async () => {
|
|
238
|
+
useAiAssistLookup(() => true);
|
|
239
|
+
stubRegistry();
|
|
240
|
+
const other = await file('beta', {type: 'question', title: 'How do menus work', description: 'Where are they?'});
|
|
241
|
+
forget();
|
|
242
|
+
assert.equal((await call('POST', '/themes', {status: 'open', type: 'bug'})).status, 200);
|
|
243
|
+
assert.equal((await call('DELETE', `/reports/${other.id}`)).status, 200);
|
|
244
|
+
assert.ok((await call('GET', '/reports')).body.themes, 'not read by the summary: kept');
|
|
245
|
+
const bug = (await call('GET', '/reports')).body.reports.find(r => r.type === 'bug');
|
|
246
|
+
assert.equal((await call('DELETE', `/reports/${bug.id}`)).status, 200);
|
|
247
|
+
assert.equal((await call('GET', '/reports')).body.themes, null);
|
|
248
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"note": "Written by `make sync-free-tier` in dcms-marketplace. Do not edit these plugins here - edit them there and sync.",
|
|
3
|
-
"source": "dcms-marketplace@
|
|
3
|
+
"source": "dcms-marketplace@6cd8828c",
|
|
4
4
|
"plugins": {
|
|
5
5
|
"blog": {
|
|
6
6
|
"version": "1.11.0",
|
|
@@ -126,27 +126,32 @@
|
|
|
126
126
|
}
|
|
127
127
|
},
|
|
128
128
|
"feedback": {
|
|
129
|
-
"version": "1.
|
|
129
|
+
"version": "1.4.0",
|
|
130
130
|
"files": {
|
|
131
|
-
"
|
|
132
|
-
"
|
|
131
|
+
"CHANGELOG.md": "5cf7771b3c9207ad982482c4f09d7f37b526af9bc5aed6cf17363db9fc58363f",
|
|
132
|
+
"CLAUDE.md": "32961fca7ccfe883739aad1670ff051b4d727237ca6147ce3cd107696c146162",
|
|
133
|
+
"admin/css/index.css": "68b29ccee0b4cdaa51b3addd868b308b44166956c0bcf24e25b29f4273b73a75",
|
|
134
|
+
"admin/lib/ai.js": "33a4604697ed254b011fa71dbc68794caacb872a3d86cb4c29d179377ba1de46",
|
|
133
135
|
"admin/lib/drafts.js": "3ccf8c255e72d62edf31692bc1bd464cea43ae9f135de23ce2caaedd0502eea2",
|
|
134
|
-
"admin/lib/kit.js": "
|
|
136
|
+
"admin/lib/kit.js": "46b15b55c005b31bb7b7b0b80ed45c82ed6adf6fcfbc7f2318c24ea0b3b62be6",
|
|
135
137
|
"admin/lib/settings.js": "973c1934c2241336d6ec25d98f9fd96077faf28ccab553f2c8507f404b4f8975",
|
|
136
138
|
"admin/templates/feedback.html": "a366dce78f6c3e84a7cb0ac63eba53e1980a4eb44154496a0536f5214c5bb36f",
|
|
137
|
-
"admin/views/feedback.js": "
|
|
138
|
-
"admin/views/inbox.js": "
|
|
139
|
+
"admin/views/feedback.js": "cab8b3e3f2e098ffe64d701d8ad2125b68fe8cc976e301e09f122637ceb8559d",
|
|
140
|
+
"admin/views/inbox.js": "25eba9a21ee15d2529461cb235356a94daa23a7170ad54c7d5a33b8771ea52ed",
|
|
139
141
|
"admin/views/send.js": "8079dda2dfae377b96774ecc085f6da0060b1d2189141de1cc7a59f52c7ed7c6",
|
|
140
142
|
"collections/feedback-reports.json": "a072291b52463f7785a77f5f77d36b8238ba8f89cfc2672c6642eccdb3144486",
|
|
141
143
|
"config.js": "29d9999d1028c2c11931f67fb9abdf35132430b7cf58c161681e734c0b45143a",
|
|
142
|
-
"docs/guide.md": "
|
|
144
|
+
"docs/guide.md": "6be36586ef0945c3ea9804569991c4de82045bad9647c65b64793ea3801135c2",
|
|
145
|
+
"lib/ai-text.js": "358e4066e5e8cd41552a89ebc78de9191bbbb26e820ba4d2fe16aa83b66a2082",
|
|
143
146
|
"lib/attachments.js": "b23bda973c2e7723bc485c5f2840868363a3ac4e65c153cb5abd5a3c41dba3ad",
|
|
144
147
|
"lib/cache.js": "6db2859c21a3dddcc2ec34e8380dd672fc99a6cb0d76a2b05b68086503f4ccce",
|
|
145
|
-
"lib/receiver.js": "
|
|
148
|
+
"lib/receiver.js": "a12fbb5d37ca9c1b451fd6c2e94b78c056778be1fb9f6fb1bff1134ff8cb54fa",
|
|
146
149
|
"lib/sender.js": "4c4730f8bcaf85be5bee1787b7548a79c5b351dfe19253443dd430791efd86e8",
|
|
147
150
|
"lib/shape.js": "640422f392b243f5a0f94c5acdfae55f615a5a383ec036499739c3ae70f21282",
|
|
148
|
-
"
|
|
149
|
-
"plugin.
|
|
151
|
+
"lib/themes.js": "acde9462e94da537b258a647fce9e8dd65debc575420a739ea74435050b79172",
|
|
152
|
+
"plugin.js": "a58b5c3ef87c53c8f52f6c1caa9a23b9b9231df2464ac14258180ff6e7e65c22",
|
|
153
|
+
"plugin.json": "915ea04d05e9e3f5e0aaaf5213cfd7ac7bfd60d5d55a6575074e8395f1b1943f",
|
|
154
|
+
"tests/ai.test.js": "f50f8d9c21f8a12f36305994cc13390fab00a39c0d34d97841a320a603c19f02",
|
|
150
155
|
"tests/api.test.js": "f9dca5d83f2b61b5f02f75a776aa28e6d27caa912ca2f03f4f55ead63549a690",
|
|
151
156
|
"tests/drafts.test.js": "b9bac3c1c7f3841229bdfe5294bfda78064f0f2d170b6db1ba39e7666531ac1f",
|
|
152
157
|
"tests/settings.test.js": "3a50ac89a9d114c8466fc043a66f0f1bf373e7a7ad6dba45a995468c3332b374",
|
|
@@ -307,29 +312,34 @@
|
|
|
307
312
|
}
|
|
308
313
|
},
|
|
309
314
|
"support": {
|
|
310
|
-
"version": "1.
|
|
315
|
+
"version": "1.3.0",
|
|
311
316
|
"files": {
|
|
312
|
-
"
|
|
313
|
-
"
|
|
317
|
+
"CHANGELOG.md": "da64649fcc59d9f42f5987395f3ca2ae98bcfa749d4121537233aeb6f3b00e3a",
|
|
318
|
+
"CLAUDE.md": "fe805bbe9048c0dce37e178bef34c34149ab2c2acc03766024f0daaf9f09058a",
|
|
319
|
+
"admin/css/index.css": "2e8e5a66a30aee7da4f36f8d80564e1fdadc19558c67359ae1a01a4ee56959a9",
|
|
320
|
+
"admin/lib/ai.js": "9a82ee5922bc54b20b5d108ccc9bde8791f9dac843e49d855ff6b254f3675645",
|
|
314
321
|
"admin/lib/drafts.js": "fe60c4792d34f4f92b19908ab9d030704992e463a26c0bdd6aac0284ec643d1a",
|
|
315
322
|
"admin/lib/email.js": "a159b09c00af6056363209b5373612957e3b9f9eb530e53a7e4ae1e5bbd194f5",
|
|
316
|
-
"admin/lib/kit.js": "
|
|
323
|
+
"admin/lib/kit.js": "e735309e57c676f06654434a71f26ac78ef928e056c70db998f5da66d593a258",
|
|
317
324
|
"admin/lib/settings.js": "293196cded3dbc72a092869e870a75ca587560bf76ffca3c5ab9b90c1fa09b33",
|
|
318
325
|
"admin/templates/support.html": "2bb69d0443a367a402e6160fe68f4af3e8983b578cfff9575b4df9a534fcb480",
|
|
319
326
|
"admin/views/desk.js": "8c4ac9ee5db56942d08ebc91f138a935640849ac091188f4e86c40c7a48f9156",
|
|
320
|
-
"admin/views/inbox.js": "
|
|
321
|
-
"admin/views/support.js": "
|
|
327
|
+
"admin/views/inbox.js": "9ed72ebfee3a05889c03fffa7179581b111f475368f0765991cb3d9047c0af03",
|
|
328
|
+
"admin/views/support.js": "6e54fc1b6cd059a696b6031d89d791167159d459e4c0df174efb2dd1ee720c20",
|
|
322
329
|
"collections/support-tickets.json": "55a0856bacd66c2e8f1e3c85bdf3638e5ff826560943cda854a8f2d336a88905",
|
|
323
330
|
"config.js": "eb7ccc1169fa8b2be52a213536825492fedaec5fa73fd749cba9f498dd54b503",
|
|
324
|
-
"docs/guide.md": "
|
|
331
|
+
"docs/guide.md": "942988d8d329df849401b76589d493c9e5c76af59409a3999154c54134ee009c",
|
|
332
|
+
"lib/ai-text.js": "358e4066e5e8cd41552a89ebc78de9191bbbb26e820ba4d2fe16aa83b66a2082",
|
|
333
|
+
"lib/assist.js": "5aea85ece5490328bca7e8de28f141b5350530b790e98d02e1e414840462292e",
|
|
325
334
|
"lib/attachments.js": "e3479c7fe9f01e6287126279bc9d514fd14f00b64af9082ac49596bc6a543c23",
|
|
326
335
|
"lib/cache.js": "70cc826b24cc5359597a5c83a990f6da43cadebf2ac34094aee42058240fb72d",
|
|
327
336
|
"lib/mail.js": "d14aae3a59aad6af61451863cdaaf94fc4a87810b16e1dcb9c655dda6c803b3b",
|
|
328
|
-
"lib/receiver.js": "
|
|
337
|
+
"lib/receiver.js": "7ed1ae47fab820655aa4c4ddf926b089601ea03a0bb4a5346d4b3f6736b66009",
|
|
329
338
|
"lib/sender.js": "2b308422ac60a8a2801570e06319d5972797a601640c67beee95ccab9ac64092",
|
|
330
339
|
"lib/shape.js": "d60b48410aa5582ea80451c3d831686b0e29525a958733a8bc9dfaae8eca94d2",
|
|
331
|
-
"plugin.js": "
|
|
332
|
-
"plugin.json": "
|
|
340
|
+
"plugin.js": "0426c9cd0eb696904321bfe7abbe46b8acb492d6e92d093ada2922b7ef092b44",
|
|
341
|
+
"plugin.json": "2079a5f80325f438fba2c641156c1ecfbbe642a215522c4dc45dad13f615bf44",
|
|
342
|
+
"tests/ai.test.js": "96d7217744fca946b4fe59260a5c16fca2f5a8b0772c8b9ef6260521eb70c653",
|
|
333
343
|
"tests/api.test.js": "1af65f0cba8a83c080a6e3e65544abc86fc43c8e25ca05c7f3e1ab4e3f7ac5a2",
|
|
334
344
|
"tests/drafts.test.js": "08d3920cf77b61fc92cb7785853afd8a5ff55c8851c1a7237a34464fd82e842e",
|
|
335
345
|
"tests/email.test.js": "2190b6dd7cc9afad99d2170f002343fe3dad306aa14ac718428e5df0be54ded1",
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [1.3.0] - 2026-11-16
|
|
4
|
+
|
|
5
|
+
- On the Domma server's inbox, with AI Assist: **Summarise** above a request's conversation (kept with the request), **Suggest a reply** that fills the reply box for you to edit and send yourself, and **Summarise** on the Waiting on Domma tab, grouping those requests into themes. Only the conversation's words are sent, never site names, people's names, email addresses, phone numbers or files. Sites see no change.
|
|
@@ -158,3 +158,36 @@ removes the rest. Found on the dcm click-through.
|
|
|
158
158
|
## 1.2.1
|
|
159
159
|
|
|
160
160
|
- **Email (openEmail).** Email actions go through `admin/lib/email.js`: `emailTo()` for menu actions (several people always in Bcc), `routeMailLinks(root)` for visible `mailto:` links. Core's `/admin/js/lib/mail-compose.js` (CMS 1.6.61+) opens Email Pro's compose window when the user has a mailbox there; older cores keep a cleaned, capped `mailto:` (over 1800 chars the addresses are copied instead). Stored addresses are encoded into links, or shown as text when invalid. Never set `location.href = 'mailto:…'` directly.
|
|
161
|
+
|
|
162
|
+
## Unreleased: AI Assist in the inbox (the receiver only)
|
|
163
|
+
|
|
164
|
+
- **Gate.** `GET /mode` answers `ai: {summary, reply, themes}`, each `aiTextAvailable(task)` from `lib/ai-text.js`: AI
|
|
165
|
+
Assist on (`isAiAssist()`, test seam `useAiAssistLookup`) AND the Manager's own service in this process,
|
|
166
|
+
`globalThis[Symbol.for('domma.ai-text')]` (site-manager/services/aiTextRoutes.js), offering that task. No fleet route: the
|
|
167
|
+
receiver IS the Manager; a site never offers them. The inbox renders each button only when its flag is true.
|
|
168
|
+
- **Routes** (`manage`): `POST /tickets/:id/summary` (task `summary`, kind `ticket`, title = subject, text = "Customer:" /
|
|
169
|
+
"Domma:" lines, the latest kept within 60,000 chars), `POST /tickets/:id/suggest` (task `reply`, thread from
|
|
170
|
+
`customer|us`, latest 40; returns `{text}`, writes nothing), `POST /themes` (task `themes`, kind `tickets`, the Waiting
|
|
171
|
+
on Domma tab: open and not archived, subject + the customer's words). `lib/assist.js` (PURE) builds them through
|
|
172
|
+
`scrubText()`: names on the request (customer, staff), the site's name and domain (not the slug - often a plain word),
|
|
173
|
+
emails, phone numbers, quoted mail, signatures out. Status and error text pass through (403, 400 "too little", 429,
|
|
174
|
+
503; a decline is 422; an empty reply 502).
|
|
175
|
+
- **Kept** in `data/ai.json` (`createKept`, 0600): `summary:<id>` (with the message count, so the card can say the
|
|
176
|
+
conversation moved on) comes back on `GET /tickets/:id` as `aiSummary`; `themes` on `GET /tickets`. Deleting a request
|
|
177
|
+
drops its summary.
|
|
178
|
+
- **UI.** One confirm per visit (per inbox mount) before anything goes; busy labels; toast with usage. Suggest asks
|
|
179
|
+
before replacing text in the box, and again if the box was typed in while the suggestion was on its way; it only sets
|
|
180
|
+
`draft` (so the drafts guard keeps it like typing) and never sends. Models in `admin/lib/ai.js` (PURE).
|
|
181
|
+
Tests: `tests/ai.test.js` (registry stubbed).
|
|
182
|
+
- **`scrubText()`** (lib/ai-text.js): a greeting at the start ("Hi Ann,") and a sign-off with up to three short lines
|
|
183
|
+
under it ("Thanks,\nAnn Jones\nAcme Ltd") go (`letter: false` for titles/subjects); known names match in any case as
|
|
184
|
+
whole words, with parts learnt from the email's local part (john.smith@ -> john, smith); stand-ins ("A site admin",
|
|
185
|
+
"An admin", "Domma Support") and mailbox words (info, admin, support...) are never names. A common word that is also a
|
|
186
|
+
known name ("will" for Will) goes too - the price of matching any case. Sites: names and domains, and links on them.
|
|
187
|
+
- **Site domains:** `siteDirectory()` now also gives `hosts` (every domain); `sitesOf` passes name, host and hosts.
|
|
188
|
+
- **Retention:** the kept themes record which request ids they read (`ids`, never sent to the browser); deleting one of
|
|
189
|
+
them drops the kept themes as well as its own summary.
|
|
190
|
+
- **Short threads:** `GET /tickets/:id` carries `aiChars` (the cleaned conversation's length) when summaries are on; the
|
|
191
|
+
panel disables Summarise with a hint under `SUMMARY_MIN` (200, the Manager's floor), and the route answers 400
|
|
192
|
+
without asking.
|
|
193
|
+
- `lib/ai-text.js` is the same file as Feedback's: change both.
|
|
@@ -122,3 +122,17 @@
|
|
|
122
122
|
.sp-msg-head .sp-msg-kebab { padding: 0 .3rem; opacity: .55; }
|
|
123
123
|
.sp-msg:hover .sp-msg-kebab, .sp-msg:focus-within .sp-msg-kebab { opacity: 1; }
|
|
124
124
|
.sp-msg:focus-visible { outline: 2px solid var(--dm-primary); outline-offset: 1px; }
|
|
125
|
+
|
|
126
|
+
/* AI Assist (the Manager only): a request's summary, and the waiting requests' themes */
|
|
127
|
+
.sp-ai, .sp-themes { display: grid; gap: .45rem; padding: .6rem .75rem; border: 1px dashed var(--dm-border); border-radius: var(--dm-radius-md); }
|
|
128
|
+
.sp-ai { margin: .25rem 0 .6rem; }
|
|
129
|
+
.sp-themes { margin: 0 0 .8rem; }
|
|
130
|
+
.sp-ai-bar, .sp-themes-bar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
|
|
131
|
+
.sp-ai-summary, .sp-themes-summary { margin: 0; font-weight: 500; }
|
|
132
|
+
.sp-ai-points { margin: 0; padding-left: 1.2rem; }
|
|
133
|
+
.sp-ai-points:empty { display: none; }
|
|
134
|
+
.sp-theme-list { display: grid; gap: .5rem; }
|
|
135
|
+
.sp-theme { border-left: 3px solid var(--dm-primary); padding: .15rem 0 .15rem .6rem; }
|
|
136
|
+
.sp-theme-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: .5rem; }
|
|
137
|
+
.sp-theme p { margin: .15rem 0 0; }
|
|
138
|
+
.sp-theme-quotes { font-style: italic; color: var(--dm-text-secondary); font-size: var(--dm-font-size-sm); }
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Support inbox - AI Assist on the Manager (the receiver only). PURE, so it is tested in node: what the
|
|
3
|
+
* request's summary and the waiting requests' themes show, the buttons' labels, and the questions asked.
|
|
4
|
+
*
|
|
5
|
+
* @module support/admin/lib/ai
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** 16 Nov, 14:05 - or '' for no date. */
|
|
9
|
+
export function shortStamp(iso) {
|
|
10
|
+
const d = iso ? new Date(iso) : null;
|
|
11
|
+
return d && !Number.isNaN(d.getTime()) ? d.toLocaleString('en-GB', {day: 'numeric', month: 'short', hour: '2-digit', minute: '2-digit'}) : '';
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const plural = (n, word) => `${n} ${word}${n === 1 ? '' : 's'}`;
|
|
15
|
+
|
|
16
|
+
/** The Manager summarises nothing shorter (lib/assist.js SUMMARY_MIN). */
|
|
17
|
+
export const SUMMARY_MIN = 200;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The summary atop a request's thread.
|
|
21
|
+
* @param {object|null} kept {at, messages, summary, points}
|
|
22
|
+
* @param {{busy?: string, messages?: number, chars?: number}} o busy: which AI task is running ('' none); messages: in
|
|
23
|
+
* the thread now; chars: how much of it Summarise would send (the server's count, after cleaning)
|
|
24
|
+
*/
|
|
25
|
+
export function summaryCard(kept, {busy = '', messages = 0, chars = SUMMARY_MIN} = {}) {
|
|
26
|
+
const when = shortStamp(kept?.at);
|
|
27
|
+
const moved = kept && messages > kept.messages;
|
|
28
|
+
const short = chars < SUMMARY_MIN;
|
|
29
|
+
return {
|
|
30
|
+
busy: Boolean(busy),
|
|
31
|
+
canSummarise: !busy && !short,
|
|
32
|
+
label: busy === 'summary' ? 'Summarising...' : kept ? 'Summarise again' : 'Summarise',
|
|
33
|
+
suggestLabel: busy === 'reply' ? 'Suggesting...' : 'Suggest a reply',
|
|
34
|
+
summary: kept?.summary || '',
|
|
35
|
+
points: (kept?.points || []).map((text, i) => ({key: String(i), text})),
|
|
36
|
+
note: kept ? `AI summary of ${plural(kept.messages, 'message')}${when ? `, ${when}` : ''}.${moved ? ' The conversation has moved on since.' : ''}`
|
|
37
|
+
: short ? 'Too short to summarise yet - there is little to sum up.'
|
|
38
|
+
: 'What the customer needs and where it stands, in a few lines.'
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** The themes of the requests waiting on Domma. */
|
|
43
|
+
export function themesCard(kept, {busy = false, waiting = 0} = {}) {
|
|
44
|
+
const when = shortStamp(kept?.at);
|
|
45
|
+
return {
|
|
46
|
+
canSummarise: !busy && waiting >= 2,
|
|
47
|
+
label: busy ? 'Summarising...' : kept ? 'Summarise again' : 'Summarise',
|
|
48
|
+
summary: kept?.summary || '',
|
|
49
|
+
themes: (kept?.themes || []).map((t, k) => ({
|
|
50
|
+
key: String(k), title: t.title || '', detail: t.detail || '',
|
|
51
|
+
countText: plural(t.count, 'request'),
|
|
52
|
+
quotesText: (t.quotes || []).filter(Boolean).map(q => `"${q}"`).join(' · ')
|
|
53
|
+
})),
|
|
54
|
+
note: kept ? `AI summary of ${plural(kept.answers, 'request')} waiting on Domma${when ? `, ${when}` : ''}.`
|
|
55
|
+
: waiting >= 2 ? `Group the ${waiting} requests waiting on Domma into themes.` : 'Summarising needs at least two requests waiting on Domma.'
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Asked once per visit, before anything goes to Claude. */
|
|
60
|
+
export const AI_QUESTION = 'Use AI on support requests? The words of the conversation go to Claude through AI Assist - '
|
|
61
|
+
+ 'no site names, people\'s names, email addresses, phone numbers or files. A suggested reply only fills the reply box: '
|
|
62
|
+
+ 'nothing is sent until you send it. Each use counts towards this server\'s monthly AI Assist allowance.';
|
|
63
|
+
|
|
64
|
+
export const REPLACE_QUESTION = 'Replace what is in the reply box with a suggested reply?';
|
|
65
|
+
export const REPLACE_LATE_QUESTION = 'You wrote in the reply box while the suggestion was on its way. Replace what you wrote with it?';
|
|
66
|
+
|
|
67
|
+
/** The toast after a use. */
|
|
68
|
+
export const usageText = (res, what) => (res?.limit ? `${what} ${res.used} of ${res.limit} AI Assist requests used this month.` : what);
|
|
@@ -59,7 +59,11 @@ export const api = {
|
|
|
59
59
|
remove: (id) => H.delete(`${BASE}/tickets/${seg(id)}`),
|
|
60
60
|
/** Where a file is read from: this site's own copy, or a request's on the manager. */
|
|
61
61
|
ownFileUrl: (id) => `${BASE}/attachments/${seg(id)}`,
|
|
62
|
-
ticketFileUrl: (id, att) => `${BASE}/tickets/${seg(id)}/attachments/${seg(att)}
|
|
62
|
+
ticketFileUrl: (id, att) => `${BASE}/tickets/${seg(id)}/attachments/${seg(att)}`,
|
|
63
|
+
// manager, AI Assist: a request summarised, a reply suggested (for the box only), the waiting ones' themes
|
|
64
|
+
summary: (id) => H.post(`${BASE}/tickets/${seg(id)}/summary`, {}),
|
|
65
|
+
suggest: (id) => H.post(`${BASE}/tickets/${seg(id)}/suggest`, {}),
|
|
66
|
+
themes: () => H.post(`${BASE}/themes`, {})
|
|
63
67
|
};
|
|
64
68
|
|
|
65
69
|
// ---------------------------------------------------------------------------------
|