domma-cms 1.57.1 → 1.58.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 +4 -0
- package/admin/js/lib/admin-assistant.js +2 -2
- package/admin/js/templates/docs/usage-chat.html +3 -2
- package/admin/js/views/launchers.js +26 -25
- package/docs/DommaFeatures.md +1 -0
- package/docs/admin-assistant.md +1 -1
- package/docs/plugin-development.md +1 -0
- package/package.json +1 -1
- package/server/routes/api/launchers.js +3 -2
- package/server/services/adminAssistant.js +3 -1
- package/server/services/aiAssist.js +44 -0
- package/server/services/chat/ai.js +5 -4
- package/server/services/plugins.js +4 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.58.0] - 2026-11-11
|
|
4
|
+
|
|
5
|
+
- **AI Assist.** AI chat answers (chat launchers, admin launchers and the admin assistant) now come with the AI Assist Tool, in the Pro plan, instead of riding on the Site Builder. A Tool switches them on with `hooks.enableAiAssist()` (paid, closed-source plugins only). Without AI Assist, chats answer from the Knowledge alone and the launcher editor says so under **AI answers**.
|
|
6
|
+
|
|
3
7
|
## [1.57.1] - 2026-11-11
|
|
4
8
|
|
|
5
9
|
- An engine update no longer deletes a site's own files in `public/images` (such as `public/images/branding`). Since the engine started shipping `public/images/characters`, the update replaced the whole folder. Now only `public/css` and `public/js` are replaced whole; in any other folder the engine ships, only its own entries are replaced.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{api as
|
|
1
|
+
import{api as I,getUser as x,isAuthenticated as k}from"../api.js";import{onceClosed as T}from"./tool-kit.js";import{mountCharacter as H}from"/public/js/character-view.mjs?v=20261111-remy-character";export function installAdminAssistant(){let v=null,u=0,w=0,s=null,t=null,i=null,h=null;const l=M.observable([]),g=M.observable(""),m=M.observable(!1),d=M.observable(""),A=()=>location.hash.slice(1).split("?")[0]||"/",C=()=>/^#\/(login|reset-password)(\?|\/|$)/.test(location.hash);function p(){u++,i?.element?.querySelector(".admin-assistant-panel")?.replaceChildren(),i?.close(!0),i=null,h?.destroy(),h=null,t?.remove(),t=null,l.value=[],g.value="",m.value=!1,d.value=""}async function $(){const a=g.peek().trim();if(!a||a.length>1e3||m.peek())return;const n=v,e=u,o=l.peek().slice(-10).map(c=>({from:c.from,text:c.text.slice(0,1e3)}));g.value="",d.value="",m.value=!0,l.value=[...l.peek(),{from:"visitor",text:a}].slice(-30);try{const c=await I.post("/admin-assistant/ask",{question:a,history:o,route:A()});if(u!==e||x()?.id!==n||!k())return;l.value=[...l.peek(),{from:"bot",text:c.answer}].slice(-30)}catch(c){u===e&&x()?.id===n&&(d.value=c.message||"Could not get an answer.")}finally{u===e&&(m.value=!1)}}function N(){if(!s?.enabled||!t)return;if(i){i.open();return}const a=s.name.replace(/[&<>"']/g,r=>({"&":"&","<":"<",">":">",'"':""","'":"'"})[r]),n=E.slideover({title:`Ask ${a}`,size:"md",position:"right"}),e=document.createElement("div");e.className="admin-assistant-panel",e.innerHTML=`<p class="text-muted">Help and drafts for the current tool. You choose what to copy and save.</p>
|
|
2
2
|
<div class="admin-assistant-messages" role="log" aria-live="polite" aria-label="Assistant conversation"></div>
|
|
3
3
|
<p role="status" data-bind-hidden="!busy.value">Thinking...</p>
|
|
4
4
|
<p class="text-danger" role="alert" data-bind-text="error.value"></p>
|
|
@@ -6,4 +6,4 @@ import{api as $,getUser as x,isAuthenticated as k}from"../api.js";import{onceClo
|
|
|
6
6
|
<textarea id="admin-assistant-question" class="form-input" maxlength="1000" rows="3" data-model="question.value" placeholder="Ask for help or a draft..."></textarea>
|
|
7
7
|
<div class="admin-assistant-actions"><button type="submit" class="btn btn-primary" data-bind-disabled="busy.value">Ask</button>
|
|
8
8
|
<button type="button" class="btn btn-secondary" data-on-click="reset" data-bind-disabled="busy.value">Clear conversation</button></div></form>
|
|
9
|
-
<small class="text-muted">Questions are sent to the site's AI service. Current page records are not attached automatically.</small>`;const o=e.querySelector('[role="log"]'),c=M.effect(()=>{o.replaceChildren();for(const r of l.value){const y=document.createElement("article");y.className=`admin-assistant-message is-${r.from}`;const q=document.createElement("strong");q.textContent=r.from==="visitor"?"You":s.name;const L=document.createElement("p");if(L.textContent=r.text,y.append(q,L),r.from==="bot"){const b=document.createElement("button");b.type="button",b.className="btn btn-sm btn-secondary",b.textContent="Copy",b.addEventListener("click",async()=>{try{await navigator.clipboard.writeText(r.text),E.toast("Copied.",{type:"success"})}catch{E.toast("Select the text to copy it.",{type:"info"})}}),y.append(b)}o.append(y)}o.scrollTop=o.scrollHeight});e.querySelector("form").addEventListener("submit",r=>{r.preventDefault()
|
|
9
|
+
<small class="text-muted">Questions are sent to the site's AI service. Current page records are not attached automatically.</small>`;const o=e.querySelector('[role="log"]'),c=M.effect(()=>{o.replaceChildren();for(const r of l.value){const y=document.createElement("article");y.className=`admin-assistant-message is-${r.from}`;const q=document.createElement("strong");q.textContent=r.from==="visitor"?"You":s.name;const L=document.createElement("p");if(L.textContent=r.text,y.append(q,L),r.from==="bot"){const b=document.createElement("button");b.type="button",b.className="btn btn-sm btn-secondary",b.textContent="Copy",b.addEventListener("click",async()=>{try{await navigator.clipboard.writeText(r.text),E.toast("Copied.",{type:"success"})}catch{E.toast("Select the text to copy it.",{type:"info"})}}),y.append(b)}o.append(y)}o.scrollTop=o.scrollHeight});e.querySelector("form").addEventListener("submit",r=>{r.preventDefault(),$()});const S=M.applyBindings({question:g,busy:m,error:d},e,{methods:{reset:()=>{l.value=[],d.value=""}}});n.element.append(e),i=n,T(n,()=>{S.dispose(),c(),i===n&&(i=null)}),s.available||(d.value="AI answers need AI Assist (in the Pro plan) on this site."),n.open()}async function f(){const a=k()&&!C()?x()?.id:null;if(a!==v&&(p(),v=a),!a)return;const n=++w;try{const e=await I.get(`/admin-assistant/config?route=${encodeURIComponent(A())}`);if(n!==w||a!==x()?.id||!k()||C())return;if(!e.enabled){p(),s=null;return}s&&(s.name!==e.name||s.character!==e.character)&&p(),s=e,t||(t=document.createElement("button"),t.type="button",t.className="admin-assistant-trigger",t.addEventListener("click",async()=>{await f(),N()}),document.body.append(t)),t.replaceChildren(),h?.destroy(),e.character&&(h=H(t,{id:e.character,portrait:!0,animated:e.animated}));const o=document.createElement("span");o.textContent=`Ask ${e.name}`,t.append(o),t.setAttribute("aria-label",`Ask ${e.name}`)}catch{n===w&&(p(),s=null)}}M.subscribe("router:afterChange",f),window.addEventListener("admin-assistant:settings",f),window.addEventListener("storage",f),window.addEventListener("hashchange",()=>{C()&&(p(),v=null)}),f()}
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
A <strong>bot</strong> answers first, straight away, from what you have taught it in the <strong>Knowledge</strong>.
|
|
12
12
|
When it cannot help, or the visitor asks for a person, the chat comes to you in <strong>Content > Chats</strong>.
|
|
13
13
|
When nobody is available, the visitor leaves their name and email instead, so nobody is left waiting. The bot is
|
|
14
|
-
called <strong>Della</strong> to begin with (rename her per launcher). With the Pro plan on a hosted site, Della
|
|
14
|
+
called <strong>Della</strong> to begin with (rename her per launcher). With <strong>AI Assist</strong> (in the Pro plan) on a hosted site, Della
|
|
15
15
|
can also answer, with AI, the questions your Knowledge does not cover - see <a href="#della-ai">AI answers</a>.</p>
|
|
16
16
|
|
|
17
17
|
<h3>Setting it up</h3>
|
|
@@ -87,7 +87,8 @@
|
|
|
87
87
|
how long ended chats are kept (90 days to begin with), and how many new chats the whole site takes in an hour
|
|
88
88
|
(300 to begin with; each visitor can start at most 6 an hour and send 120 messages).</p>
|
|
89
89
|
|
|
90
|
-
<h3 id="della-ai">AI answers (Pro plan, hosted sites)</h3>
|
|
90
|
+
<h3 id="della-ai">AI answers (AI Assist, in the Pro plan, hosted sites)</h3>
|
|
91
|
+
<p>AI answers come with the <strong>AI Assist</strong> Tool, part of the Pro plan. It also powers admin launchers and the admin assistant. Without it every chat answers from the Knowledge alone, and the launcher editor says so under <strong>AI answers</strong>.</p>
|
|
91
92
|
<p>When nothing in the Knowledge fits a question, Della asks Claude (Anthropic's AI). Claude answers only from what
|
|
92
93
|
you have given it and says it does not know rather than guess - then the chat goes on as before ("Sorry, I do not
|
|
93
94
|
know" and the offer of a person). What Claude is given with each question:</p>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{apiRequest as V,api as
|
|
1
|
+
import{apiRequest as V,api as ye}from"../api.js";import{CHARACTERS as Ge}from"../../../public/js/characters.mjs";import{addBannerAction as ke}from"../lib/plugin-chrome.js";import{helpPopovers as Se}from"../lib/help-popover.js";import{onceClosed as Je,openMenuAt as Ce,sidebarCount as Te,viewLifetime as Qe}from"../lib/tool-kit.js";import{rowPlaceKeeper as Ze}from"../lib/menu-drag.js";import{FILTERS as ea,LAUNCHER_POSITION_LABEL as $e,arrangeLaunchers as aa,blankLauncher as ta,checkLauncherForm as la,countLaunchers as na,duplicateLauncher as sa,formFromLauncher as ia,launcherFromForm as oa,launcherRow as da,moveItem as ra,previewSpot as ca}from"../lib/launchers-arrange.js";import{LAUNCHER_LIMITS as i,LAUNCHER_TOKENS as G,launcherChatAccentCss as ha,launcherColourCss as Me,launcherHref as J}from"../../../public/js/launcher-settings.mjs";const Ee=/^#\/launchers\/?(\?.*)?$/,Ae="#/launchers",Q="launchers.filter",D="launchers.draft",pa=`
|
|
2
2
|
<div class="lnx-row" data-id="{{id}}" tabindex="0" data-bind-class="rowCls">
|
|
3
3
|
<span class="lnx-grip" title="Drag to reorder" aria-hidden="true"><span data-icon="menu" data-icon-size="14"></span></span>
|
|
4
4
|
<span class="lnx-disc" data-bind-class="pill && 'is-pill'" data-bind-style="discStyle" aria-hidden="true"><span data-icon="{{icon}}"></span><span data-bind-hidden="!pill">{{label}}</span></span>
|
|
@@ -9,19 +9,19 @@ import{apiRequest as V,api as we}from"../api.js";import{CHARACTERS as Ve}from"..
|
|
|
9
9
|
</span>
|
|
10
10
|
<label class="lnx-switch" title="On or off"><input type="checkbox" class="form-switch lnx-toggle" data-bind-checked="on" aria-label="{{name}} on or off"></label>
|
|
11
11
|
<button type="button" class="lnx-kebab" aria-label="Actions for {{name}}" title="Actions">\u22EE</button>
|
|
12
|
-
</div>`,c={triggerStyle:[["icon","Disc - icon only"],["icon-text","Pill - icon and label"]],tooltipMode:[["label","The label"],["custom","Words of its own"],["off","None"]],actionType:[["modal","A page, form or block, in a modal"],["slideover","A page, form or block, in a slideover"],["chat","A chat"]],kind:[["page","Page"],["form","Form"],["block","Block"]],modalSize:[["xs","Extra small (320px)"],["sm","Small (400px)"],["md","Medium (600px)"],["lg","Large (800px)"],["xl","Extra large (1140px)"],["xxl","Huge (1400px)"],["full","Nearly full width (90%)"],["screen","Full screen"],["custom","Custom\u2026"]],modalHeight:[["auto","Fit the page"],["sm","Short (40% of the window)"],["md","Medium (60%)"],["lg","Tall (80%)"],["full","Nearly full height (90%)"],["custom","Custom\u2026"]],widthUnit:[["px","px"],["%","% of window"]],heightUnit:[["vh","% of window"],["px","px"]],side:[["right","Right"],["left","Left"]],width:[["sm","Narrow (360px)"],["md","Medium (480px)"],["lg","Wide (640px)"],["xl","Extra wide (860px)"]],devices:[["all","Phones and desktops"],["desktop","Desktops only"],["phone","Phones only"]],pagesMode:[["all","Every page"],["only","Only these pages"],["except","Every page except these"]],place:[["site","The site"],["admin","The admin"],["both","The site and the admin"]],audience:[["everyone","Everyone"],["signed-in","Signed-in people only"],["signed-out","Signed-out visitors only"]],askDetails:[["offline","When nobody is there to answer"],["always","Before the chat starts"],["never","Never"]],times:[["time","The time (09:42)"],["datetime","The date and time (10 Nov, 09:42)"],["none","Nothing"]],personButton:[["below","A button under the conversation"],["header","An icon in the chat heading"]],chatSize:[["sm","Small (340 x 500)"],["md","Medium (400 x 600)"],["lg","Large (480 x 720)"],["custom","Custom\u2026"]],background:[["","Theme (primary)"],...G.map(s=>[s,s.charAt(0).toUpperCase()+s.slice(1)]),["custom","Custom hex\u2026"]],foreground:[["","Theme (reads on the background)"],...G.map(s=>[s,s.charAt(0).toUpperCase()+s.slice(1)]),["custom","Custom hex\u2026"]]},
|
|
12
|
+
</div>`,c={triggerStyle:[["icon","Disc - icon only"],["icon-text","Pill - icon and label"]],tooltipMode:[["label","The label"],["custom","Words of its own"],["off","None"]],actionType:[["modal","A page, form or block, in a modal"],["slideover","A page, form or block, in a slideover"],["chat","A chat"]],kind:[["page","Page"],["form","Form"],["block","Block"]],modalSize:[["xs","Extra small (320px)"],["sm","Small (400px)"],["md","Medium (600px)"],["lg","Large (800px)"],["xl","Extra large (1140px)"],["xxl","Huge (1400px)"],["full","Nearly full width (90%)"],["screen","Full screen"],["custom","Custom\u2026"]],modalHeight:[["auto","Fit the page"],["sm","Short (40% of the window)"],["md","Medium (60%)"],["lg","Tall (80%)"],["full","Nearly full height (90%)"],["custom","Custom\u2026"]],widthUnit:[["px","px"],["%","% of window"]],heightUnit:[["vh","% of window"],["px","px"]],side:[["right","Right"],["left","Left"]],width:[["sm","Narrow (360px)"],["md","Medium (480px)"],["lg","Wide (640px)"],["xl","Extra wide (860px)"]],devices:[["all","Phones and desktops"],["desktop","Desktops only"],["phone","Phones only"]],pagesMode:[["all","Every page"],["only","Only these pages"],["except","Every page except these"]],place:[["site","The site"],["admin","The admin"],["both","The site and the admin"]],audience:[["everyone","Everyone"],["signed-in","Signed-in people only"],["signed-out","Signed-out visitors only"]],askDetails:[["offline","When nobody is there to answer"],["always","Before the chat starts"],["never","Never"]],times:[["time","The time (09:42)"],["datetime","The date and time (10 Nov, 09:42)"],["none","Nothing"]],personButton:[["below","A button under the conversation"],["header","An icon in the chat heading"]],chatSize:[["sm","Small (340 x 500)"],["md","Medium (400 x 600)"],["lg","Large (480 x 720)"],["custom","Custom\u2026"]],background:[["","Theme (primary)"],...G.map(s=>[s,s.charAt(0).toUpperCase()+s.slice(1)]),["custom","Custom hex\u2026"]],foreground:[["","Theme (reads on the background)"],...G.map(s=>[s,s.charAt(0).toUpperCase()+s.slice(1)]),["custom","Custom hex\u2026"]]},ua=["TL","TC","TR","ML","","MR","BL","BC","BR"],h=s=>s.map(([p,A])=>`<option value="${p}">${A}</option>`).join(""),Oe=s=>ua.map(p=>p?`<button type="button" data-pos="${p}" data-bind-class="${s}.value === '${p}' && 'is-on'" title="${$e[p]}" aria-label="${$e[p]}">${p}</button>`:'<button type="button" class="lnx-corner-mid" tabindex="-1" aria-hidden="true"></button>').join(""),ma=`
|
|
13
13
|
<div class="lnx-form">
|
|
14
14
|
<div class="lnx-section">
|
|
15
15
|
<h6><span data-icon="message-circle" data-icon-size="14"></span> The disc</h6>
|
|
16
16
|
<div class="lnx-grid2">
|
|
17
17
|
<div class="lnx-field">
|
|
18
18
|
<label class="form-label" for="lnx-f-name">Name <span data-help="Only you see this - it names the launcher in this list."></span></label>
|
|
19
|
-
<input id="lnx-f-name" class="form-input" maxlength="${
|
|
19
|
+
<input id="lnx-f-name" class="form-input" maxlength="${i.nameMax}" data-model="name.value">
|
|
20
20
|
<small class="lnx-err" data-bind-hidden="!err.value.name" data-bind-text="err.value.name"></small>
|
|
21
21
|
</div>
|
|
22
22
|
<div class="lnx-field">
|
|
23
23
|
<label class="form-label" for="lnx-f-label">Label <span data-help="What the disc says: read out to screen readers, and written on the pill when the style is Pill."></span></label>
|
|
24
|
-
<input id="lnx-f-label" class="form-input" maxlength="${
|
|
24
|
+
<input id="lnx-f-label" class="form-input" maxlength="${i.labelMax}" data-model="label.value">
|
|
25
25
|
<small class="lnx-err" data-bind-hidden="!err.value.label" data-bind-text="err.value.label"></small>
|
|
26
26
|
</div>
|
|
27
27
|
<div class="lnx-field">
|
|
@@ -30,12 +30,12 @@ import{apiRequest as V,api as we}from"../api.js";import{CHARACTERS as Ve}from"..
|
|
|
30
30
|
</div>
|
|
31
31
|
<div class="lnx-field" data-bind-hidden="tooltipMode.value !== 'custom'">
|
|
32
32
|
<label class="form-label" for="lnx-f-tip">Tooltip words</label>
|
|
33
|
-
<input id="lnx-f-tip" class="form-input" maxlength="${
|
|
33
|
+
<input id="lnx-f-tip" class="form-input" maxlength="${i.tooltipMax}" placeholder="e.g. Questions? Ask us here" data-model="tooltip.value">
|
|
34
34
|
</div>
|
|
35
35
|
<div class="lnx-field">
|
|
36
36
|
<label class="form-label" for="lnx-f-icon">Icon <span data-help="A Domma icon name - press the grid button to browse them."></span></label>
|
|
37
37
|
<div class="lnx-inline">
|
|
38
|
-
<input id="lnx-f-icon" class="form-input" maxlength="${
|
|
38
|
+
<input id="lnx-f-icon" class="form-input" maxlength="${i.iconMax}" data-model="icon.value">
|
|
39
39
|
<button type="button" class="lnx-icon-btn lnx-pick-icon" title="Browse icons"><span data-icon="grid" data-icon-size="14"></span></button>
|
|
40
40
|
</div>
|
|
41
41
|
</div>
|
|
@@ -105,7 +105,7 @@ import{apiRequest as V,api as we}from"../api.js";import{CHARACTERS as Ve}from"..
|
|
|
105
105
|
<div class="lnx-grid2">
|
|
106
106
|
<div class="lnx-field">
|
|
107
107
|
<label class="form-label" for="lnx-f-title">Title <span data-help="The heading of the modal, slideover or chat. Empty uses the label."></span></label>
|
|
108
|
-
<input id="lnx-f-title" class="form-input" maxlength="${
|
|
108
|
+
<input id="lnx-f-title" class="form-input" maxlength="${i.titleMax}" data-model="title.value">
|
|
109
109
|
</div>
|
|
110
110
|
<div class="lnx-field" data-bind-hidden="actionType.value !== 'modal'">
|
|
111
111
|
<label class="form-label" for="lnx-f-size">Modal width <span data-help="Never wider than the window: a phone always gets nearly its full width. Full screen fills the whole window, height too."></span></label>
|
|
@@ -114,7 +114,7 @@ import{apiRequest as V,api as we}from"../api.js";import{CHARACTERS as Ve}from"..
|
|
|
114
114
|
<div class="lnx-field" data-bind-hidden="actionType.value !== 'modal' || modalSize.value !== 'custom'">
|
|
115
115
|
<label class="form-label" for="lnx-f-cw">Custom width</label>
|
|
116
116
|
<div class="lnx-unit"><input id="lnx-f-cw" type="number" class="form-input" data-model="customWidth.value"
|
|
117
|
-
data-bind-min="widthUnit.value === '%' ? ${
|
|
117
|
+
data-bind-min="widthUnit.value === '%' ? ${i.widthPct[0]} : ${i.widthPx[0]}" data-bind-max="widthUnit.value === '%' ? ${i.widthPct[1]} : ${i.widthPx[1]}">
|
|
118
118
|
<select class="form-input" data-model="widthUnit.value" aria-label="Width unit">${h(c.widthUnit)}</select></div>
|
|
119
119
|
</div>
|
|
120
120
|
<div class="lnx-field" data-bind-hidden="actionType.value !== 'modal' || modalSize.value === 'screen'">
|
|
@@ -124,7 +124,7 @@ import{apiRequest as V,api as we}from"../api.js";import{CHARACTERS as Ve}from"..
|
|
|
124
124
|
<div class="lnx-field" data-bind-hidden="actionType.value !== 'modal' || modalSize.value === 'screen' || modalHeight.value !== 'custom'">
|
|
125
125
|
<label class="form-label" for="lnx-f-ch">Custom height</label>
|
|
126
126
|
<div class="lnx-unit"><input id="lnx-f-ch" type="number" class="form-input" data-model="customHeight.value"
|
|
127
|
-
data-bind-min="heightUnit.value === 'px' ? ${
|
|
127
|
+
data-bind-min="heightUnit.value === 'px' ? ${i.heightPx[0]} : ${i.heightVh[0]}" data-bind-max="heightUnit.value === 'px' ? ${i.heightPx[1]} : ${i.heightVh[1]}">
|
|
128
128
|
<select class="form-input" data-model="heightUnit.value" aria-label="Height unit">${h(c.heightUnit)}</select></div>
|
|
129
129
|
</div>
|
|
130
130
|
<div class="lnx-field" data-bind-hidden="actionType.value !== 'slideover'">
|
|
@@ -139,18 +139,18 @@ import{apiRequest as V,api as we}from"../api.js";import{CHARACTERS as Ve}from"..
|
|
|
139
139
|
<div class="lnx-grid2" data-bind-hidden="actionType.value !== 'chat'">
|
|
140
140
|
<div class="lnx-field" style="grid-column: 1 / -1">
|
|
141
141
|
<label class="form-label" for="lnx-f-character">Character</label>
|
|
142
|
-
<select id="lnx-f-character" class="form-input" data-model="character.value"><option value="">No character</option>${Object.values(
|
|
142
|
+
<select id="lnx-f-character" class="form-input" data-model="character.value"><option value="">No character</option>${Object.values(Ge).map(s=>`<option value="${s.id}">${s.name}</option>`).join("")}</select>
|
|
143
143
|
<small>Use the character's name, portrait and animated poses. Site Settings controls visibility and motion. Your custom name and picture are kept when no character is selected.</small>
|
|
144
144
|
<div data-bind-hidden="!character.value">
|
|
145
145
|
<label class="form-label" for="lnx-f-charname">Display name <span data-help-title="Display name" data-help="Leave empty to use the character's own name. An optional name changes the chat name, while keeping the selected artwork."></span></label>
|
|
146
|
-
<input id="lnx-f-charname" class="form-input" maxlength="${
|
|
146
|
+
<input id="lnx-f-charname" class="form-input" maxlength="${i.botNameMax}" placeholder="Character's own name" data-model="characterName.value">
|
|
147
147
|
</div>
|
|
148
148
|
<label class="form-label" for="lnx-f-greeting">Greeting <span data-help-title="Greeting" data-help="The first message a visitor sees when the chat opens. Words in braces are filled in from the visitor's own clock: {greeting} (Good morning / afternoon / evening), {timeofday} (morning / afternoon / evening), {day} (Monday...), {date} (10 November), {time} (09:42), {botname} and {site}. For example: {greeting}! I'm {botname} - how can I help this {timeofday}?"></span></label>
|
|
149
|
-
<textarea id="lnx-f-greeting" class="form-input" rows="2" maxlength="${
|
|
149
|
+
<textarea id="lnx-f-greeting" class="form-input" rows="2" maxlength="${i.greetingMax}" data-model="greeting.value"></textarea>
|
|
150
150
|
</div>
|
|
151
151
|
<div class="lnx-field">
|
|
152
152
|
<label class="form-label" for="lnx-f-botname">Bot's name <span data-help="Shown on the bot's answers."></span></label>
|
|
153
|
-
<input id="lnx-f-botname" data-bind-disabled="!!character.value" class="form-input" maxlength="${
|
|
153
|
+
<input id="lnx-f-botname" data-bind-disabled="!!character.value" class="form-input" maxlength="${i.botNameMax}" data-model="botName.value">
|
|
154
154
|
</div>
|
|
155
155
|
<div class="lnx-field">
|
|
156
156
|
<label class="form-label" for="lnx-f-accent">Chat colour <span data-help="This chat's own colour: its heading, the visitor's messages and the send button. Theme uses the site's primary colour, so each chat can carry its own branding."></span></label>
|
|
@@ -168,8 +168,8 @@ import{apiRequest as V,api as we}from"../api.js";import{CHARACTERS as Ve}from"..
|
|
|
168
168
|
<label class="form-label" for="lnx-f-chatsize">Chat window size <span data-help="How big the chat window opens on a computer, in pixels. It never grows past the visitor's window, and on a phone the chat always fills the screen."></span></label>
|
|
169
169
|
<select id="lnx-f-chatsize" class="form-input" data-model="chatSize.value">${h(c.chatSize)}</select>
|
|
170
170
|
<div class="lnx-grid2" data-bind-hidden="chatSize.value !== 'custom'">
|
|
171
|
-
<input type="number" class="form-input" aria-label="Chat window width in pixels" min="${
|
|
172
|
-
<input type="number" class="form-input" aria-label="Chat window height in pixels" min="${
|
|
171
|
+
<input type="number" class="form-input" aria-label="Chat window width in pixels" min="${i.chatWidth[0]}" max="${i.chatWidth[1]}" data-model="chatWidth.value">
|
|
172
|
+
<input type="number" class="form-input" aria-label="Chat window height in pixels" min="${i.chatHeight[0]}" max="${i.chatHeight[1]}" data-model="chatHeight.value">
|
|
173
173
|
</div>
|
|
174
174
|
<small class="lnx-err" data-bind-hidden="!err.value.chatWidth && !err.value.chatHeight" data-bind-text="err.value.chatWidth || err.value.chatHeight"></small>
|
|
175
175
|
</div>
|
|
@@ -189,9 +189,9 @@ import{apiRequest as V,api as we}from"../api.js";import{CHARACTERS as Ve}from"..
|
|
|
189
189
|
<small class="lnx-err" data-bind-hidden="!err.value.keepDays" data-bind-text="err.value.keepDays"></small>
|
|
190
190
|
</div>
|
|
191
191
|
<label class="lnx-check"><input type="checkbox" class="form-switch" data-model="chatResizable.value"> Visitors can resize the chat
|
|
192
|
-
<span data-help="A grip in the corner away from the disc lets visitors drag the window bigger or smaller (between ${
|
|
192
|
+
<span data-help="A grip in the corner away from the disc lets visitors drag the window bigger or smaller (between ${i.chatWidth[0]} x ${i.chatHeight[0]} and ${i.chatWidth[1]} x ${i.chatHeight[1]}). Their size is remembered in their browser; a double-click on the grip puts yours back."></span></label>
|
|
193
193
|
<div class="lnx-field" style="grid-column: 1 / -1">
|
|
194
|
-
<label class="form-label" for="lnx-f-starters">Questions to start with <span data-help="Up to ${
|
|
194
|
+
<label class="form-label" for="lnx-f-starters">Questions to start with <span data-help="Up to ${i.startersMax}, one per line: buttons under the greeting that ask the question for the visitor. They go once the chat starts."></span></label>
|
|
195
195
|
<textarea id="lnx-f-starters" class="form-input" rows="3" data-model="starters.value" placeholder="How much does it cost? Can you move my WordPress site?"></textarea>
|
|
196
196
|
<small class="lnx-err" data-bind-hidden="!err.value.starters" data-bind-text="err.value.starters"></small>
|
|
197
197
|
</div>
|
|
@@ -215,13 +215,14 @@ import{apiRequest as V,api as we}from"../api.js";import{CHARACTERS as Ve}from"..
|
|
|
215
215
|
<label class="lnx-check" data-bind-hidden="!bot.value"><input type="checkbox" class="form-switch" data-model="useKnowledge.value"> Answer from the Knowledge
|
|
216
216
|
<span data-help-title="Answer from the Knowledge" data-help="On: the bot answers from your Knowledge entries (Chats > Knowledge) first, and the AI sees them too. Off: this chat ignores the Knowledge and only the AI answers, from the boxes below - for a chat about something else, such as help in the admin."></span></label>
|
|
217
217
|
<label class="lnx-check" data-bind-hidden="!bot.value"><input type="checkbox" class="form-switch" data-model="ai.value"> AI answers what the Knowledge does not
|
|
218
|
-
<span data-help-title="AI answers" data-help="When no Knowledge entry fits, the bot asks Claude, which answers only from your Knowledge, Site Settings > AI assistant and the box below, and says it does not know rather than guess. Comes with the Pro plan on hosted sites;
|
|
218
|
+
<span data-help-title="AI answers" data-help="When no Knowledge entry fits, the bot asks Claude, which answers only from your Knowledge, Site Settings > AI assistant and the box below, and says it does not know rather than guess. Comes with AI Assist, in the Pro plan on hosted sites; without it the bot answers from the Knowledge alone."></span></label>
|
|
219
|
+
<small class="lnx-warn" style="grid-column: 1 / -1" data-bind-hidden="!bot.value || !ai.value || aiAssist.value">AI answers need AI Assist, in the Pro plan. Until this site has it, this chat answers from the Knowledge only.</small>
|
|
219
220
|
<label class="lnx-check" style="grid-column: 1 / -1" data-bind-hidden="!bot.value || !ai.value"><input type="checkbox" class="form-switch" data-model="aiUseSite.value"> Use the site's About the business
|
|
220
221
|
<span data-help-title="Site-wide settings" data-help="On: the AI starts from Site Settings > General > AI assistant > About the business and adds what you write below. Off: only what you write below - for a chat about something else entirely, such as one event or one product. The site's Rules apply either way: a launcher can add rules, never lift one."></span></label>
|
|
221
222
|
<div class="lnx-field" style="grid-column: 1 / -1" data-bind-hidden="!bot.value || !ai.value">
|
|
222
223
|
<label class="form-label" for="lnx-f-aicontext">What the AI should know for this launcher
|
|
223
224
|
<span data-help="Added to Site Settings > AI assistant > About the business (or used on its own when the site's settings are off), for chats from this launcher only - say, the products on the pages it shows on. Sent to Claude with each question, so leave out anything private."></span></label>
|
|
224
|
-
<textarea id="lnx-f-aicontext" class="form-input" rows="3" maxlength="${
|
|
225
|
+
<textarea id="lnx-f-aicontext" class="form-input" rows="3" maxlength="${i.aiContextMax}" data-model="aiContext.value"
|
|
225
226
|
placeholder="On the shop pages: we post to the UK only, orders before 2pm go the same day."></textarea>
|
|
226
227
|
</div>
|
|
227
228
|
<div class="lnx-field" data-bind-hidden="!bot.value || !ai.value">
|
|
@@ -231,7 +232,7 @@ import{apiRequest as V,api as we}from"../api.js";import{CHARACTERS as Ve}from"..
|
|
|
231
232
|
<div class="lnx-field" style="grid-column: 1 / -1" data-bind-hidden="!bot.value || !ai.value">
|
|
232
233
|
<label class="form-label" for="lnx-f-airules">Rules for this launcher
|
|
233
234
|
<span data-help="One per line: what answers from this launcher must never do or say. They add to the rules in Site Settings > AI assistant; they cannot lift one."></span></label>
|
|
234
|
-
<textarea id="lnx-f-airules" class="form-input" rows="2" maxlength="${
|
|
235
|
+
<textarea id="lnx-f-airules" class="form-input" rows="2" maxlength="${i.aiRulesMax}" data-model="aiRules.value"
|
|
235
236
|
placeholder="Only talk about orders and delivery. Never promise a delivery date."></textarea>
|
|
236
237
|
</div>
|
|
237
238
|
</div>
|
|
@@ -242,7 +243,7 @@ import{apiRequest as V,api as we}from"../api.js";import{CHARACTERS as Ve}from"..
|
|
|
242
243
|
<div class="lnx-place">
|
|
243
244
|
<div class="lnx-field">
|
|
244
245
|
<span class="form-label">Spot <span data-help="Pick a corner, the middle of an edge, or the top or bottom centre. It steps clear of other discs there - Search, Back to top, Reduce motion and your other launchers."></span></span>
|
|
245
|
-
<div class="lnx-corners lnx-corners-main" role="group" aria-label="Spot">${
|
|
246
|
+
<div class="lnx-corners lnx-corners-main" role="group" aria-label="Spot">${Oe("position")}</div>
|
|
246
247
|
</div>
|
|
247
248
|
<div class="lnx-previews">
|
|
248
249
|
<div><div class="lnx-preview"><span class="lnx-preview-bar"></span><span class="lnx-preview-disc" data-bind-style="previewStyle.value"><span data-icon="message-circle" class="lnx-preview-icon"></span><span data-bind-hidden="triggerStyle.value !== 'icon-text'" data-bind-text="label.value"></span></span></div><small>Desktop</small></div>
|
|
@@ -255,7 +256,7 @@ import{apiRequest as V,api as we}from"../api.js";import{CHARACTERS as Ve}from"..
|
|
|
255
256
|
<div class="lnx-field"><label class="form-label">From the top or bottom <span data-help="How far in from the top or bottom edge, in pixels. For a middle spot it nudges the disc down."></span></label>
|
|
256
257
|
<div class="lnx-range"><input type="range" min="0" max="300" data-model="offsetY.value" aria-label="From the top or bottom"><output data-bind-text="offsetY.value"></output></div></div>
|
|
257
258
|
<div class="lnx-field"><label class="form-label">Size <span data-help="The disc's width and height. 44px or more is easy to tap."></span></label>
|
|
258
|
-
<div class="lnx-range"><input type="range" min="${
|
|
259
|
+
<div class="lnx-range"><input type="range" min="${i.sizeMin}" max="${i.sizeMax}" data-model="size.value" aria-label="Size"><output data-bind-text="size.value"></output></div></div>
|
|
259
260
|
<div class="lnx-field" data-bind-hidden="triggerStyle.value === 'icon-text'"><label class="form-label">Roundness <span data-help="0 is a square; half the size is a circle."></span></label>
|
|
260
261
|
<div class="lnx-range"><input type="range" min="0" data-bind-max="maxRadius.value" data-model="radius.value" aria-label="Roundness"><output data-bind-text="radius.value"></output></div></div>
|
|
261
262
|
<div class="lnx-field">
|
|
@@ -268,7 +269,7 @@ import{apiRequest as V,api as we}from"../api.js";import{CHARACTERS as Ve}from"..
|
|
|
268
269
|
<div class="lnx-place" data-bind-hidden="!phoneOverride.value || devices.value === 'desktop'">
|
|
269
270
|
<div class="lnx-field">
|
|
270
271
|
<span class="form-label">Spot on phones</span>
|
|
271
|
-
<div class="lnx-corners lnx-corners-phone" role="group" aria-label="Spot on phones">${
|
|
272
|
+
<div class="lnx-corners lnx-corners-phone" role="group" aria-label="Spot on phones">${Oe("phonePosition")}</div>
|
|
272
273
|
</div>
|
|
273
274
|
<div class="lnx-grid2" style="flex:1">
|
|
274
275
|
<div class="lnx-field"><label class="form-label">From the side</label>
|
|
@@ -276,7 +277,7 @@ import{apiRequest as V,api as we}from"../api.js";import{CHARACTERS as Ve}from"..
|
|
|
276
277
|
<div class="lnx-field"><label class="form-label">From the top or bottom</label>
|
|
277
278
|
<div class="lnx-range"><input type="range" min="0" max="200" data-model="phoneOffsetY.value" aria-label="From the top or bottom on phones"><output data-bind-text="phoneOffsetY.value"></output></div></div>
|
|
278
279
|
<div class="lnx-field"><label class="form-label">Size</label>
|
|
279
|
-
<div class="lnx-range"><input type="range" min="${
|
|
280
|
+
<div class="lnx-range"><input type="range" min="${i.sizeMin}" max="${i.sizeMax}" data-model="phoneSize.value" aria-label="Size on phones"><output data-bind-text="phoneSize.value"></output></div></div>
|
|
280
281
|
</div>
|
|
281
282
|
</div>
|
|
282
283
|
</div>
|
|
@@ -312,4 +313,4 @@ import{apiRequest as V,api as we}from"../api.js";import{CHARACTERS as Ve}from"..
|
|
|
312
313
|
<button type="button" class="btn btn-sm btn-primary" data-on-click="save" data-bind-disabled="cannot.value">
|
|
313
314
|
<span data-icon="check" data-icon-size="13"></span> <span data-bind-text="saveText"></span></button>
|
|
314
315
|
</div>
|
|
315
|
-
</div>`,Z=s=>String(s??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""");function ma(s){const p=document.createElement("template");return p.innerHTML=s.trim(),p.content.firstElementChild}const T=s=>s?G.includes(s)?s:"custom":"",x=Je(Me),ee={list:()=>V("/launchers/items",{method:"GET"}),save:s=>V("/launchers/items",{method:"PUT",body:JSON.stringify({launchers:s})}),patch:(s,p)=>V(`/launchers/items/${encodeURIComponent(s)}`,{method:"PATCH",body:JSON.stringify(p)})};export const launchersView={templateUrl:"/admin/js/templates/launchers.html",async onMount(s){x.reset();const p=s.get(0).querySelector(".lnx")||s.get(0),A=()=>p.isConnected&&Me.test(location.hash),u=M.observable([]),ae=M.observable(!0),F=M.observable(""),B=M.observable(!0);let te="all";try{te=Ze.includes(S.get(Q))?S.get(Q):"all"}catch{}const $=M.observable(te),W=M.observable("");x.add(M.effect(()=>{const a=$.value;try{S.set(Q,a)}catch{}}));const K=M.observable([]);x.add(M.effect(()=>{K.value=ea(u.value,{filter:$.value,query:W.value}).map(ia)}));const Oe=M.computed(()=>la(u.value)),ze=M.computed(()=>u.value.length?"No launchers match.":"No launchers yet - New launcher in the banner makes one."),le=M.computed(()=>u.value.length>1&&($.value!=="all"||!!W.value.trim())),O=a=>u.peek().find(t=>t.id===a);let L=null;const Ne=async()=>{if(L)return L;const[a,t]=await Promise.all([we.forms.list().catch(()=>[]),we.blocks.list().catch(()=>[])]);return L={forms:(Array.isArray(a)?a:[]).map(l=>({value:l.slug,text:l.title?`${l.title} (${l.slug})`:l.slug})),blocks:(Array.isArray(t)?t:[]).map(l=>({value:l.name,text:l.description?`${l.name} - ${l.description}`:l.name}))},L};async function Le(){try{const a=await ee.list();if(!A())return;u.value=Array.isArray(a?.launchers)?a.launchers:[],F.value="",B.value=!0}catch(a){const t=String(a?.message||a);/switched off/i.test(t)?B.value=!1:F.value=`Could not load the launchers: ${t}`}finally{ae.value=!1}}async function P(a,t){try{const l=await ee.save(a);return A()&&(u.value=l.launchers),Ce(Ee),t&&E.toast(t,{type:"success"}),l.launchers}catch(l){return E.toast(`Not saved: ${l.message||l}`,{type:"error"}),null}}async function q(a,t){try{const l=await ee.patch(a.id,{enabled:t});u.value=u.peek().map(m=>m.id===a.id?l.launcher:m),Ce(Ee),E.toast(`"${a.name}" ${t?"switched on":"switched off"}.`,{type:"success",duration:2e3})}catch(l){E.toast(`Not changed: ${l.message||l}`,{type:"error"}),u.value=[...u.peek()]}}async function Ie(a){const t=u.peek(),l=t.findIndex(i=>i.id===a.id),m=na(a,t);await P([...t.slice(0,l+1),m,...t.slice(l+1)],`Duplicated as "${m.name}" - switched off until you are ready.`)}async function Pe(a){await E.confirm(`Delete the launcher "${Z(a.name)}"? It goes from every page. This cannot be undone.`)&&await P(u.peek().filter(t=>t.id!==a.id),"Launcher deleted.")}function He(a){if(a.action.type==="chat"){E.toast("A chat has nothing to open on its own - see it on any page it shows on.",{type:"info"});return}if(!a.action.ref){E.toast("Choose what it opens first.",{type:"warning"});return}window.open(`/_launcher/${encodeURIComponent(a.id)}`,"_blank","noopener")}function Re(a){const t=O(a);return t?[{header:t.name},{label:"Edit",icon:"edit",action:()=>z(t.id)},t.enabled?{label:"Switch off",icon:"pause",action:()=>q(t,!1)}:{label:"Switch on",icon:"play",action:()=>q(t,!0)},{label:"Open what it shows",icon:"external-link",action:()=>He(t)},{type:"divider"},{label:"Duplicate",icon:"copy",action:()=>Ie(t)},{type:"divider"},{label:"Delete\u2026",icon:"trash",danger:!0,action:()=>Pe(t)}]:[]}let y=null;const j=new Set;function De(a,t,l){const m=a.close.bind(a);let i=!1,b=!1;return a.close=async r=>{if(!i&&r!==!0&&t()){if(b)return;b=!0;const N=await E.confirm(l);if(b=!1,!N)return}return i=!0,m()},()=>{i=!0}}async function z(a=null,t=null){const l=a?O(a):null;if(a&&!l){E.toast("That launcher is no longer there.",{type:"warning"});return}if(y){E.toast("Finish the launcher you have open first.",{type:"info"});return}const m=!l,i=sa(l||aa(u.peek()));t&&!Object.hasOwn(t,"character")&&typeof t.useDella=="boolean"&&(t={...t,character:t.useDella?"della":""});const b={...i,refPage:i.kind==="page"?i.ref:"",refForm:i.kind==="form"?i.ref:"",refBlock:i.kind==="block"?i.ref:"",bgChoice:T(i.background),bgHex:T(i.background)==="custom"?i.background:"",fgChoice:T(i.text),fgHex:T(i.text)==="custom"?i.text:"",accentChoice:T(i.accent),accentHex:T(i.accent)==="custom"?i.accent:"",accentTextChoice:T(i.accentText),accentTextHex:T(i.accentText)==="custom"?i.accentText:"",...t||{}};delete b.useDella,delete b.ref,delete b.background,delete b.text,delete b.accent,delete b.accentText;const r=Object.fromEntries(Object.entries(b).map(([e,d])=>[e,M.observable(d)])),N=()=>Object.fromEntries(Object.keys(r).map(e=>[e,r[e].peek()])),de=e=>JSON.stringify(Object.fromEntries(Object.entries(e).map(([d,n])=>[d,typeof n=="boolean"?n:String(n??"")]))),Be=de(b),re=()=>de(N())!==Be||!!t,ce=e=>{const d=e.actionType==="chat"?"page":e.kind;return{...e,kind:d,ref:d==="form"?e.refForm:d==="block"?e.refBlock:String(e.refPage||"").trim(),background:e.bgChoice==="custom"?String(e.bgHex||"").trim():e.bgChoice,text:e.fgChoice==="custom"?String(e.fgHex||"").trim():e.fgChoice,accent:e.accentChoice==="custom"?String(e.accentHex||"").trim():e.accentChoice,accentText:e.accentTextChoice==="custom"?String(e.accentTextHex||"").trim():e.accentTextChoice}},H=()=>ce(Object.fromEntries(Object.keys(r).map(e=>[e,r[e].value]))),Y=M.computed(()=>ta(H())),R=M.observable(!1),he=(e,d)=>{const n=ra({...e,size:Number(e.size),offsetX:Number(e.offsetX),offsetY:Number(e.offsetY),phoneSize:Number(e.phoneSize),phoneOffsetX:Number(e.phoneOffsetX),phoneOffsetY:Number(e.phoneOffsetY)},d?{vw:120,vh:220,scale:.5,phone:!0}:{vw:320,vh:200,scale:.5}),f=e.triggerStyle==="icon-text"&&!d;return{left:`${n.left}px`,top:`${n.top}px`,height:`${n.size}px`,width:f?"auto":`${n.size}px`,padding:f?"0 6px":"0","border-radius":f?"999px":`${Math.round(Math.min(Number(e.radius),Number(e.size)/2)/Number(e.size)*100)}%`,"--lnx-bg":$e(e.background)||"var(--dm-primary)","--lnx-fg":$e(e.text)||"var(--dm-primary-text)"}},pe={...r,saving:R,err:M.computed(()=>Y.value.errors),warn:M.computed(()=>Y.value.warnings),cannot:M.computed(()=>R.value||Object.keys(Y.value.errors).length>0),maxRadius:M.computed(()=>Math.floor(Number(r.size.value)/2)),previewStyle:M.computed(()=>he(H(),!1)),phonePreviewStyle:M.computed(()=>he(H(),!0)),botInitial:M.computed(()=>(String(r.botName.value||"").trim()[0]||"?").toUpperCase()),avatarPreview:M.computed(()=>{const e=ca(H());return{background:e.accent||"var(--dm-primary)",color:e.accentText||"var(--dm-primary-text, #fff)"}}),saveText:m?"Create launcher":"Save",linkHref:m?"":J(l.id),linkText:m?"Create the launcher first - then it has a link":J(l.id)},We=M.effect(()=>{const e=Math.floor(Number(r.size.value)/2);Number(r.radius.peek())>e&&(r.radius.value=e)}),ue=(e,d,n)=>{let f=e.peek();return M.effect(()=>{const C=e.value;C!==f&&(f=C,d.value=n(C))})},Ke=ue(r.widthUnit,r.customWidth,e=>e==="%"?90:900),qe=ue(r.heightUnit,r.customHeight,e=>e==="px"?600:70),k=E.slideover({title:m?"New launcher":`Edit ${Z(l.name)}`,size:"lg",position:"right"}),v=ma(ua),me=await Ne().catch(()=>({forms:[],blocks:[]})),fe=(e,d,n)=>{const f=document.createElement("option");f.value="",f.textContent=d.length?"Choose\u2026":"None yet",e.appendChild(f);const C=n&&!d.some(D=>D.value===n)?[...d,{value:n,text:`${n} (missing)`}]:d;for(const D of C){const X=document.createElement("option");X.value=D.value,X.textContent=D.text,e.appendChild(X)}};fe(v.querySelector(".lnx-form-select"),me.forms,b.refForm),fe(v.querySelector(".lnx-block-select"),me.blocks,b.refBlock);let be=()=>{};async function ve(){if(!pe.cannot.peek()){R.value=!0;try{const e=oa(ce(N()),l?.id||""),d=u.peek(),n=m?[...d,e]:d.map(C=>C.id===l.id?e:C);if(!await P(n,m?`Created "${e.name}".`:"Saved."))return;be(),k.close()}finally{R.value=!1}}}k.element.appendChild(v);const je=ke(v),Ye=M.applyBindings(pe,v,{methods:{save:ve,cancel:()=>k.close()}}),_e=e=>{(e.ctrlKey||e.metaKey)&&e.key==="Enter"&&(e.preventDefault(),ve())};v.addEventListener("keydown",_e);const xe=async e=>{const d=e.target.closest(".lnx-corners button[data-pos]");if(d){const n=d.closest(".lnx-corners-phone")?"phonePosition":"position";r[n].value=d.dataset.pos;return}if(e.target.closest(".lnx-pick-icon")){const{openIconPicker:n}=await import("../lib/card-builder.js");n(f=>{r.icon.value=f});return}if(e.target.closest(".lnx-copy-link")&&!m){let n=!1;try{n=await _.copyToClipboard(J(l.id))!==!1}catch{}E.toast(n?"Link copied.":"Could not copy - select the link and copy it.",{type:n?"success":"warning"});return}if(e.target.closest(".lnx-pick-avatar")){const{pickMedia:n}=await import("../lib/media-picker.js"),f=await n({title:"Choose the bot's picture",current:r.avatar.peek()});f&&(r.avatar.value=String(f).replace(/^https?:\/\/[^/]+/i,""));return}if(e.target.closest(".lnx-clear-avatar")){r.avatar.value="";return}if(e.target.closest(".lnx-pick-page")){const{openPagePicker:n}=await import("../lib/page-picker.js");n(f=>{r.refPage.value=f})}};v.addEventListener("click",xe);const Xe=M.effect(()=>{const e=r.icon.value;v.querySelectorAll(".lnx-preview-disc").forEach(d=>{const n=document.createElement("span");n.setAttribute("data-icon",e||"message-circle"),n.className="lnx-preview-icon",d.querySelector(".lnx-preview-icon")?.replaceWith(n),I.scan(d)})}),ge={id:l?.id??null,dirty:re,values:N};y=ge,j.add(k),Ge(k,()=>{Ye.dispose(),je(),We?.(),Ke?.(),qe?.(),Xe?.(),v.removeEventListener("click",xe),j.delete(k),y===ge&&(y=null)}),be=De(k,re,"Discard the changes you have not saved?"),I.scan(v),k.open(),v.querySelector("#lnx-f-name")?.focus()}const g=p.querySelector(".lnx-list");g.innerHTML=ha;const Ue=M.applyBindings({launchers:u,loading:ae,loadError:F,toolOn:B,filter:$,query:W,rows:K,counts:Oe,emptyText:ze,dragNote:le},p,{methods:{showAll:()=>{$.value="all"},showOn:()=>{$.value="on"},showOff:()=>{$.value="off"}}});x.add(()=>Ue.dispose()),x.add(ke(p,{position:"bottom"})),x.add(M.effect(()=>{K.value,requestAnimationFrame(()=>{p.isConnected&&I.scan(g)})}));const Fe=E.contextMenu(g,{cursor:"glyph",match:".lnx-row",inherit:!1,density:"compact",items:a=>Re(a.dataset.id)});x.add(()=>Fe?.destroy?.());const ne=a=>{const t=a.target.closest(".lnx-row");if(!t||a.target.closest(".lnx-switch"))return;const l=a.target.closest(".lnx-kebab");if(l){Se(l);return}z(t.dataset.id)},se=a=>{const t=a.target.closest(".lnx-toggle"),l=t?.closest(".lnx-row"),m=l&&O(l.dataset.id);m&&q(m,t.checked)},oe=a=>{const t=a.target.closest(".lnx-row");t&&(a.key==="F10"&&a.shiftKey?(a.preventDefault(),Se(t)):a.key==="Enter"&&a.target===t&&z(t.dataset.id))};if(g.addEventListener("click",ne),g.addEventListener("change",se),g.addEventListener("keydown",oe),x.add(()=>{g.removeEventListener("click",ne),g.removeEventListener("change",se),g.removeEventListener("keydown",oe)}),typeof E.sortable=="function"){const a=Qe(),t=E.sortable(g,{items:".lnx-row",handle:".lnx-grip",key:null,keyboard:!1,onStart:a.start,onEnd:({item:l})=>a.restore(l),onSort:({item:l,from:m,to:i})=>{if(a.restore(l),le.peek()){E.toast("Clear the search and show All to reorder.",{type:"info"}),u.value=[...u.peek()];return}const b=da(u.peek(),m,i);u.value=b,P(b)}});x.add(()=>t.destroy())}ye(s,{id:"launchers-new",icon:"plus",title:"New launcher",onClick:()=>z()}),ye(s,{id:"launchers-chats",icon:"message-square",title:"Chats - the conversations from chat launchers",onClick:()=>{location.hash="#/launchers/chats"}});const ie=a=>{y?.dirty()&&(a.preventDefault(),a.returnValue="")};if(window.addEventListener("beforeunload",ie),x.add(()=>window.removeEventListener("beforeunload",ie)),x.add(()=>{if(y?.dirty())try{S.set(U,{id:y.id,values:y.values(),at:new Date().toISOString()})}catch{}[...j].forEach(a=>{try{a.close(!0)}catch{}})}),I.scan(p),await Le(),!A())return;let w=null;try{w=S.get(U)}catch{}if(w?.values){try{S.remove?S.remove(U):S.set(U,null)}catch{}const a=w.id&&O(w.id)?`your changes to "${Z(O(w.id).name)}"`:"the new launcher you started";await E.confirm(`You left ${a} unsaved. Pick up where you left off?`)&&A()&&z(w.id&&O(w.id)?w.id:null,w.values)}}};
|
|
316
|
+
</div>`,Z=s=>String(s??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""");function fa(s){const p=document.createElement("template");return p.innerHTML=s.trim(),p.content.firstElementChild}const T=s=>s?G.includes(s)?s:"custom":"",x=Qe(Ee),ee={list:()=>V("/launchers/items",{method:"GET"}),save:s=>V("/launchers/items",{method:"PUT",body:JSON.stringify({launchers:s})}),patch:(s,p)=>V(`/launchers/items/${encodeURIComponent(s)}`,{method:"PATCH",body:JSON.stringify(p)})};export const launchersView={templateUrl:"/admin/js/templates/launchers.html",async onMount(s){x.reset();const p=s.get(0).querySelector(".lnx")||s.get(0),A=()=>p.isConnected&&Ee.test(location.hash),u=M.observable([]),ae=M.observable(!0),F=M.observable(""),B=M.observable(!0);let te="all";try{te=ea.includes(S.get(Q))?S.get(Q):"all"}catch{}const $=M.observable(te),W=M.observable("");x.add(M.effect(()=>{const a=$.value;try{S.set(Q,a)}catch{}}));const K=M.observable([]);x.add(M.effect(()=>{K.value=aa(u.value,{filter:$.value,query:W.value}).map(da)}));const ze=M.computed(()=>na(u.value)),Ne=M.computed(()=>u.value.length?"No launchers match.":"No launchers yet - New launcher in the banner makes one."),le=M.computed(()=>u.value.length>1&&($.value!=="all"||!!W.value.trim())),O=a=>u.peek().find(t=>t.id===a);let ne=!0,L=null;const Ie=async()=>{if(L)return L;const[a,t]=await Promise.all([ye.forms.list().catch(()=>[]),ye.blocks.list().catch(()=>[])]);return L={forms:(Array.isArray(a)?a:[]).map(l=>({value:l.slug,text:l.title?`${l.title} (${l.slug})`:l.slug})),blocks:(Array.isArray(t)?t:[]).map(l=>({value:l.name,text:l.description?`${l.name} - ${l.description}`:l.name}))},L};async function Le(){try{const a=await ee.list();if(!A())return;u.value=Array.isArray(a?.launchers)?a.launchers:[],ne=a?.aiAssist===!0,F.value="",B.value=!0}catch(a){const t=String(a?.message||a);/switched off/i.test(t)?B.value=!1:F.value=`Could not load the launchers: ${t}`}finally{ae.value=!1}}async function P(a,t){try{const l=await ee.save(a);return A()&&(u.value=l.launchers),Te(Ae),t&&E.toast(t,{type:"success"}),l.launchers}catch(l){return E.toast(`Not saved: ${l.message||l}`,{type:"error"}),null}}async function q(a,t){try{const l=await ee.patch(a.id,{enabled:t});u.value=u.peek().map(m=>m.id===a.id?l.launcher:m),Te(Ae),E.toast(`"${a.name}" ${t?"switched on":"switched off"}.`,{type:"success",duration:2e3})}catch(l){E.toast(`Not changed: ${l.message||l}`,{type:"error"}),u.value=[...u.peek()]}}async function Pe(a){const t=u.peek(),l=t.findIndex(o=>o.id===a.id),m=sa(a,t);await P([...t.slice(0,l+1),m,...t.slice(l+1)],`Duplicated as "${m.name}" - switched off until you are ready.`)}async function He(a){await E.confirm(`Delete the launcher "${Z(a.name)}"? It goes from every page. This cannot be undone.`)&&await P(u.peek().filter(t=>t.id!==a.id),"Launcher deleted.")}function Re(a){if(a.action.type==="chat"){E.toast("A chat has nothing to open on its own - see it on any page it shows on.",{type:"info"});return}if(!a.action.ref){E.toast("Choose what it opens first.",{type:"warning"});return}window.open(`/_launcher/${encodeURIComponent(a.id)}`,"_blank","noopener")}function Ue(a){const t=O(a);return t?[{header:t.name},{label:"Edit",icon:"edit",action:()=>z(t.id)},t.enabled?{label:"Switch off",icon:"pause",action:()=>q(t,!1)}:{label:"Switch on",icon:"play",action:()=>q(t,!0)},{label:"Open what it shows",icon:"external-link",action:()=>Re(t)},{type:"divider"},{label:"Duplicate",icon:"copy",action:()=>Pe(t)},{type:"divider"},{label:"Delete\u2026",icon:"trash",danger:!0,action:()=>He(t)}]:[]}let y=null;const j=new Set;function De(a,t,l){const m=a.close.bind(a);let o=!1,b=!1;return a.close=async r=>{if(!o&&r!==!0&&t()){if(b)return;b=!0;const N=await E.confirm(l);if(b=!1,!N)return}return o=!0,m()},()=>{o=!0}}async function z(a=null,t=null){const l=a?O(a):null;if(a&&!l){E.toast("That launcher is no longer there.",{type:"warning"});return}if(y){E.toast("Finish the launcher you have open first.",{type:"info"});return}const m=!l,o=ia(l||ta(u.peek()));t&&!Object.hasOwn(t,"character")&&typeof t.useDella=="boolean"&&(t={...t,character:t.useDella?"della":""});const b={...o,refPage:o.kind==="page"?o.ref:"",refForm:o.kind==="form"?o.ref:"",refBlock:o.kind==="block"?o.ref:"",bgChoice:T(o.background),bgHex:T(o.background)==="custom"?o.background:"",fgChoice:T(o.text),fgHex:T(o.text)==="custom"?o.text:"",accentChoice:T(o.accent),accentHex:T(o.accent)==="custom"?o.accent:"",accentTextChoice:T(o.accentText),accentTextHex:T(o.accentText)==="custom"?o.accentText:"",...t||{}};delete b.useDella,delete b.ref,delete b.background,delete b.text,delete b.accent,delete b.accentText;const r=Object.fromEntries(Object.entries(b).map(([e,d])=>[e,M.observable(d)])),N=()=>Object.fromEntries(Object.keys(r).map(e=>[e,r[e].peek()])),re=e=>JSON.stringify(Object.fromEntries(Object.entries(e).map(([d,n])=>[d,typeof n=="boolean"?n:String(n??"")]))),We=re(b),ce=()=>re(N())!==We||!!t,he=e=>{const d=e.actionType==="chat"?"page":e.kind;return{...e,kind:d,ref:d==="form"?e.refForm:d==="block"?e.refBlock:String(e.refPage||"").trim(),background:e.bgChoice==="custom"?String(e.bgHex||"").trim():e.bgChoice,text:e.fgChoice==="custom"?String(e.fgHex||"").trim():e.fgChoice,accent:e.accentChoice==="custom"?String(e.accentHex||"").trim():e.accentChoice,accentText:e.accentTextChoice==="custom"?String(e.accentTextHex||"").trim():e.accentTextChoice}},H=()=>he(Object.fromEntries(Object.keys(r).map(e=>[e,r[e].value]))),Y=M.computed(()=>la(H())),R=M.observable(!1),pe=(e,d)=>{const n=ca({...e,size:Number(e.size),offsetX:Number(e.offsetX),offsetY:Number(e.offsetY),phoneSize:Number(e.phoneSize),phoneOffsetX:Number(e.phoneOffsetX),phoneOffsetY:Number(e.phoneOffsetY)},d?{vw:120,vh:220,scale:.5,phone:!0}:{vw:320,vh:200,scale:.5}),f=e.triggerStyle==="icon-text"&&!d;return{left:`${n.left}px`,top:`${n.top}px`,height:`${n.size}px`,width:f?"auto":`${n.size}px`,padding:f?"0 6px":"0","border-radius":f?"999px":`${Math.round(Math.min(Number(e.radius),Number(e.size)/2)/Number(e.size)*100)}%`,"--lnx-bg":Me(e.background)||"var(--dm-primary)","--lnx-fg":Me(e.text)||"var(--dm-primary-text)"}},ue={...r,saving:R,aiAssist:M.observable(ne),err:M.computed(()=>Y.value.errors),warn:M.computed(()=>Y.value.warnings),cannot:M.computed(()=>R.value||Object.keys(Y.value.errors).length>0),maxRadius:M.computed(()=>Math.floor(Number(r.size.value)/2)),previewStyle:M.computed(()=>pe(H(),!1)),phonePreviewStyle:M.computed(()=>pe(H(),!0)),botInitial:M.computed(()=>(String(r.botName.value||"").trim()[0]||"?").toUpperCase()),avatarPreview:M.computed(()=>{const e=ha(H());return{background:e.accent||"var(--dm-primary)",color:e.accentText||"var(--dm-primary-text, #fff)"}}),saveText:m?"Create launcher":"Save",linkHref:m?"":J(l.id),linkText:m?"Create the launcher first - then it has a link":J(l.id)},Ke=M.effect(()=>{const e=Math.floor(Number(r.size.value)/2);Number(r.radius.peek())>e&&(r.radius.value=e)}),me=(e,d,n)=>{let f=e.peek();return M.effect(()=>{const C=e.value;C!==f&&(f=C,d.value=n(C))})},qe=me(r.widthUnit,r.customWidth,e=>e==="%"?90:900),je=me(r.heightUnit,r.customHeight,e=>e==="px"?600:70),k=E.slideover({title:m?"New launcher":`Edit ${Z(l.name)}`,size:"lg",position:"right"}),v=fa(ma),fe=await Ie().catch(()=>({forms:[],blocks:[]})),be=(e,d,n)=>{const f=document.createElement("option");f.value="",f.textContent=d.length?"Choose\u2026":"None yet",e.appendChild(f);const C=n&&!d.some(U=>U.value===n)?[...d,{value:n,text:`${n} (missing)`}]:d;for(const U of C){const X=document.createElement("option");X.value=U.value,X.textContent=U.text,e.appendChild(X)}};be(v.querySelector(".lnx-form-select"),fe.forms,b.refForm),be(v.querySelector(".lnx-block-select"),fe.blocks,b.refBlock);let ve=()=>{};async function xe(){if(!ue.cannot.peek()){R.value=!0;try{const e=oa(he(N()),l?.id||""),d=u.peek(),n=m?[...d,e]:d.map(C=>C.id===l.id?e:C);if(!await P(n,m?`Created "${e.name}".`:"Saved."))return;ve(),k.close()}finally{R.value=!1}}}k.element.appendChild(v);const Ye=Se(v),_e=M.applyBindings(ue,v,{methods:{save:xe,cancel:()=>k.close()}}),Xe=e=>{(e.ctrlKey||e.metaKey)&&e.key==="Enter"&&(e.preventDefault(),xe())};v.addEventListener("keydown",Xe);const ge=async e=>{const d=e.target.closest(".lnx-corners button[data-pos]");if(d){const n=d.closest(".lnx-corners-phone")?"phonePosition":"position";r[n].value=d.dataset.pos;return}if(e.target.closest(".lnx-pick-icon")){const{openIconPicker:n}=await import("../lib/card-builder.js");n(f=>{r.icon.value=f});return}if(e.target.closest(".lnx-copy-link")&&!m){let n=!1;try{n=await _.copyToClipboard(J(l.id))!==!1}catch{}E.toast(n?"Link copied.":"Could not copy - select the link and copy it.",{type:n?"success":"warning"});return}if(e.target.closest(".lnx-pick-avatar")){const{pickMedia:n}=await import("../lib/media-picker.js"),f=await n({title:"Choose the bot's picture",current:r.avatar.peek()});f&&(r.avatar.value=String(f).replace(/^https?:\/\/[^/]+/i,""));return}if(e.target.closest(".lnx-clear-avatar")){r.avatar.value="";return}if(e.target.closest(".lnx-pick-page")){const{openPagePicker:n}=await import("../lib/page-picker.js");n(f=>{r.refPage.value=f})}};v.addEventListener("click",ge);const Ve=M.effect(()=>{const e=r.icon.value;v.querySelectorAll(".lnx-preview-disc").forEach(d=>{const n=document.createElement("span");n.setAttribute("data-icon",e||"message-circle"),n.className="lnx-preview-icon",d.querySelector(".lnx-preview-icon")?.replaceWith(n),I.scan(d)})}),we={id:l?.id??null,dirty:ce,values:N};y=we,j.add(k),Je(k,()=>{_e.dispose(),Ye(),Ke?.(),qe?.(),je?.(),Ve?.(),v.removeEventListener("click",ge),j.delete(k),y===we&&(y=null)}),ve=De(k,ce,"Discard the changes you have not saved?"),I.scan(v),k.open(),v.querySelector("#lnx-f-name")?.focus()}const g=p.querySelector(".lnx-list");g.innerHTML=pa;const Fe=M.applyBindings({launchers:u,loading:ae,loadError:F,toolOn:B,filter:$,query:W,rows:K,counts:ze,emptyText:Ne,dragNote:le},p,{methods:{showAll:()=>{$.value="all"},showOn:()=>{$.value="on"},showOff:()=>{$.value="off"}}});x.add(()=>Fe.dispose()),x.add(Se(p,{position:"bottom"})),x.add(M.effect(()=>{K.value,requestAnimationFrame(()=>{p.isConnected&&I.scan(g)})}));const Be=E.contextMenu(g,{cursor:"glyph",match:".lnx-row",inherit:!1,density:"compact",items:a=>Ue(a.dataset.id)});x.add(()=>Be?.destroy?.());const se=a=>{const t=a.target.closest(".lnx-row");if(!t||a.target.closest(".lnx-switch"))return;const l=a.target.closest(".lnx-kebab");if(l){Ce(l);return}z(t.dataset.id)},ie=a=>{const t=a.target.closest(".lnx-toggle"),l=t?.closest(".lnx-row"),m=l&&O(l.dataset.id);m&&q(m,t.checked)},oe=a=>{const t=a.target.closest(".lnx-row");t&&(a.key==="F10"&&a.shiftKey?(a.preventDefault(),Ce(t)):a.key==="Enter"&&a.target===t&&z(t.dataset.id))};if(g.addEventListener("click",se),g.addEventListener("change",ie),g.addEventListener("keydown",oe),x.add(()=>{g.removeEventListener("click",se),g.removeEventListener("change",ie),g.removeEventListener("keydown",oe)}),typeof E.sortable=="function"){const a=Ze(),t=E.sortable(g,{items:".lnx-row",handle:".lnx-grip",key:null,keyboard:!1,onStart:a.start,onEnd:({item:l})=>a.restore(l),onSort:({item:l,from:m,to:o})=>{if(a.restore(l),le.peek()){E.toast("Clear the search and show All to reorder.",{type:"info"}),u.value=[...u.peek()];return}const b=ra(u.peek(),m,o);u.value=b,P(b)}});x.add(()=>t.destroy())}ke(s,{id:"launchers-new",icon:"plus",title:"New launcher",onClick:()=>z()}),ke(s,{id:"launchers-chats",icon:"message-square",title:"Chats - the conversations from chat launchers",onClick:()=>{location.hash="#/launchers/chats"}});const de=a=>{y?.dirty()&&(a.preventDefault(),a.returnValue="")};if(window.addEventListener("beforeunload",de),x.add(()=>window.removeEventListener("beforeunload",de)),x.add(()=>{if(y?.dirty())try{S.set(D,{id:y.id,values:y.values(),at:new Date().toISOString()})}catch{}[...j].forEach(a=>{try{a.close(!0)}catch{}})}),I.scan(p),await Le(),!A())return;let w=null;try{w=S.get(D)}catch{}if(w?.values){try{S.remove?S.remove(D):S.set(D,null)}catch{}const a=w.id&&O(w.id)?`your changes to "${Z(O(w.id).name)}"`:"the new launcher you started";await E.confirm(`You left ${a} unsaved. Pick up where you left off?`)&&A()&&z(w.id&&O(w.id)?w.id:null,w.values)}}};
|
package/docs/DommaFeatures.md
CHANGED
|
@@ -1240,6 +1240,7 @@ The four Tools below were plugins until 0.67.0 and are now part of the CMS. They
|
|
|
1240
1240
|
- Hand-over: with staff available (the Chats screen open and Available on - memory presence, 75s) the chat goes to `waiting` and staff are notified (source `core:chat`, admins); with nobody available the visitor leaves name and email (`message`) unless the launcher says never; `askDetails: always` asks before putting them through. A staff reply makes it `open` and the bot stays quiet. Hourly tidy-up closes quiet chats (bot 2h, waiting/open 24h) and deletes ended ones after `retentionDays` (90) - bot-only chats with no details after 7 days - with their messages and any orphan messages, one write per collection (adapters' `removeMany`). Chats in memory are an LRU of 2000; unknown tokens are remembered for a minute. A Launchers module that is missing refuses every chat.
|
|
1241
1241
|
- Admin: **Content > Chats** (`#/launchers/chats`, `#/launchers/chats/:id`) - the inbox, waiting first, the live thread (3s poll), replies with per-chat drafts, end/delete/email in a context menu, Available switch, settings cog; sidebar badge `/api/chats/_count` (live while someone waits, red after 5 minutes). **Chats > Knowledge** (`#/launchers/knowledge`) - entries with an editor slideover (question, other ways of asking, keywords, Markdown answer, up to five buttons, on/off), Try the bot with scores, and the Unanswered list (Make an entry, add to the closest entry, dismiss). Visitor panel `public/js/launcher-chat.mjs` `mountChat(container, {launcherId, title, chat})` + `public/css/launcher-chat.css`, domma-reactive.
|
|
1242
1242
|
- Permission `chats` (`read`, `reply`, `manage`) in the Tools group; Admin is granted it once. All of it is behind the Launchers switch.
|
|
1243
|
+
- AI Assist (unreleased): the paid `ai-assist` Tool (Pro plan) calls `hooks.enableAiAssist()` (`services/aiAssist.js`, paid + closedSource only, off when the Tool is disabled). Without it `aiAvailable()` is false (chat config says `ai: false`, nothing is asked) and the admin assistant is unavailable (`requestAdminAnswer` 403). `GET /api/launchers/items` says `aiAssist`, and the launcher editor notes under AI answers when it is off. The Manager checks the `ai-assist` licence (no longer the Site Builder's).
|
|
1243
1244
|
- Della's AI answers (unreleased; Pro plan, hosted sites): when the matcher says `none`, `services/chat/ai.js` `aiAnswer()` asks the Manager (`MANAGER_URL` + `FLEET_TOKEN`, `POST /api/fleet/launcher-chat`; on dcm the in-process registry `Symbol.for('domma.launcher-chat')`) with the site's name, `assistantBrief()` (site.json `assistant.context`/`rules` from Site Settings > General > AI assistant, plus the launcher's `chat.aiContext`/`aiRules`), the enabled non-sample Knowledge (most used first, 16,000 characters), the last 10 visitor/bot messages and the question. A non-empty answer is stored as a bot message with `ai: true` (`misses` reset); empty or refused falls back to the usual "do not know". The question is still logged as unanswered. A 403 (no licence) backs off 10 minutes, a 429 (month used) 30 minutes, anything else 1 minute. Per launcher `chat.ai` (default on), `chat.aiUseSite` (default on; off = the launcher's own context only - the site's rules always apply), `chat.aiMaxPerChat` (20; `aiCount` on the session); the default bot name is now Della. A character's chat is called by the character's name, or by `chat.characterName` when set (admin: **Call her** under Use Della) - `characterChat()` in `public/js/characters.mjs` - so Della can be "Dash" on one launcher with her own artwork. Packs in `CHARACTERS`: dot, daisy, della, dash (Job Board) and remy (health care, Regimen; unreleased), each a 3x2 atlas in `public/images/characters/<id>-poses.png`. `aiContext`/`aiRules` never reach the page (`publicLauncher`). `/api/chat/config` says `ai` so the panel can say Della is an AI assistant. Manager side: `plugins/site-manager/services/launcherChatRoutes.js` (fleet token, the `ai-site-builder` licence, 2,000 answers per site per month counting "do not know", 4 at once) and `tools/launcher-chat` (Claude Haiku 5.5, low effort; fixed cached system prompt, then the owner's context and rules as a second system block; the visitor's words only in the user message; `LAUNCHER_CHAT_ANTHROPIC_KEY` read by the job alone).
|
|
1244
1245
|
- Saved chats (unreleased): preset `chat-saved` (in `CHAT_PRESET_SLUGS`, `chats.manage` through the generic API, kept out of site repos) - a copy of a chat with `note`, `outcome` (to look at / looking into it / done), visitor, page, dates, who saved it, `transcript` (plain text) and `messages`. `POST /api/chats/:id/save` (reply), `GET /api/chats/saved` and `/saved/:sid` (read), `PUT /saved/:sid` (reply; note, outcome), `DELETE /saved/:sid` (manage); at most 2,000 per site. Chats inbox: a **Saved** tab, the context-menu item **Save for a closer look…**, and an outcome/note bar on an open saved chat (`services/chat/saved.js`, `arrangeSaved()`).
|
|
1245
1246
|
- Visitor panel look (unreleased): bot and staff avatars, runs of messages grouped (name on the first, avatar on the last), gradient visitor bubbles, soft chips for links and choices, a rounded composer with the send button inside, messages easing in (still for reduced motion), and in a launcher panel the bot's avatar (with a dot while someone answers) and the status under the title. Panel 400 x 600. Per-chat branding: `chat.accent` / `chat.accentText` (a theme token or hex, `launcherColour`) and `chat.avatar` (a site address only, `launcherAvatar()`), in the page's chat block and `/api/chat/config`; the panel sets `--chat-accent` / `--chat-accent-text` on itself (`launcherChatAccentCss()`: a hex accent with no text colour gets black or white by contrast, a token its `--dm-<token>-text`), and the bot's picture replaces its initial in the heading, the typing row and its messages.
|
package/docs/admin-assistant.md
CHANGED
|
@@ -17,7 +17,7 @@ values are not attached. Conversations stay in browser memory, are cleared on si
|
|
|
17
17
|
or a user change, and can be cleared in the panel. They are not saved as visitor chats.
|
|
18
18
|
The site's shared AI context and rules are combined with the admin-specific settings.
|
|
19
19
|
|
|
20
|
-
The Manager needs the admin-assistant AI mode update. It uses the existing hosted AI
|
|
20
|
+
The site needs AI Assist (a Tool in the Pro plan) switched on; without it the assistant is unavailable. The Manager needs the admin-assistant AI mode update. It uses the existing hosted AI
|
|
21
21
|
entitlement and monthly allowance. A site with no configured AI service shows an
|
|
22
22
|
unavailable message. Older Managers are detected and asked to update; their visitor
|
|
23
23
|
answer mode is not silently used for admin assistance.
|
|
@@ -377,6 +377,7 @@ roles and notifications are stamped with it). The sections below cover the main
|
|
|
377
377
|
| `getCalendarSources()` | Read the registered calendar sources (used by the Calendar plugin) |
|
|
378
378
|
| `registerRelatedItems(kind, provider)` | Show items beside a core contact or note, with menu actions (0.79.0). Kind `message` (0.103.0): actions on an email's menu in the mail reader, `{email}`/`{name}`/`{subject}` in the url; any action can carry `permission: {resource, action}` |
|
|
379
379
|
| `enableInstantCalls()` | A paid Tool with calls switches on the CMS's instant calls ("Call Sam now…" on contacts and emails, `#/calls/new`, `/api/calls`, `/_call/<id>`). Bound to the plugin's name; refused unless the manifest is `tier: "paid"` AND `closedSource: true` (so it loads only under a licence). Disabling the plugin takes its hold off at once. Returns true when on. Call it with `?.()` - older cores lack it |
|
|
380
|
+
| `enableAiAssist()` | AI Assist switches on AI chat answers (chat launchers, admin launchers, the admin assistant; `services/aiAssist.js`). The same contract as `enableInstantCalls()`: refused unless `tier: "paid"` AND `closedSource: true`; disabling the plugin switches it off at once. Without it `aiAvailable()` is false and the admin assistant answers 403. The Manager still checks the site's `ai-assist` licence on each answer. Call it with `?.()` |
|
|
380
381
|
| `registerContactAccess(fn)` | A plugin that shares contacts says which contacts that are not the viewer's own they may read: `fn(entries, {id, roles})` resolves to the readable entry ids. Core code taking a contact id (instant calls) uses it through `readableContactIds()` |
|
|
381
382
|
| `registerSitemapSource({id, label, list})` / `sitemapChanged()` | Add public URLs to `/sitemap.xml` (and `/llms.txt`, where an item's optional `description` follows its link, 1.8.36); call `sitemapChanged()` when they change (otherwise they show within ten minutes) (0.89.0) |
|
|
382
383
|
| `notify({...})` / `resolveNotification(key)` | Raise or clear an admin notification (source ids are `<plugin>:<id>`) (0.80.0) |
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* /api/launchers behind the Tool's switch (toolGate), so it answers 404 while
|
|
4
4
|
* Launchers is switched off.
|
|
5
5
|
*
|
|
6
|
-
* GET /api/launchers/items - every launcher, in order (settings.read)
|
|
6
|
+
* GET /api/launchers/items - every launcher, in order, and whether AI Assist is on (settings.read)
|
|
7
7
|
* PUT /api/launchers/items - {launchers: [...]}: the whole list - edits, order, on/off (settings.update)
|
|
8
8
|
* PATCH /api/launchers/items/:id - a patch over one launcher, e.g. {enabled: false} (settings.update)
|
|
9
9
|
* GET /api/launchers/_count - the sidebar badge (settings.read)
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
import {
|
|
20
20
|
LAUNCHERS_ASSET_V, getLaunchers, launchersBadge, launchersForAdmin, saveLaunchers, updateLauncher
|
|
21
21
|
} from '../../services/launchers.js';
|
|
22
|
+
import {isAiAssist} from '../../services/aiAssist.js';
|
|
22
23
|
|
|
23
24
|
/** Far more than any site will want, and small enough that a runaway client cannot write megabytes into every page. */
|
|
24
25
|
const MAX_LAUNCHERS = 100;
|
|
@@ -33,7 +34,7 @@ export async function launchersRoutes(fastify, opts = {}) {
|
|
|
33
34
|
const canRead = {preHandler: [authenticate, requirePermission('settings', 'read')]};
|
|
34
35
|
const canUpdate = {preHandler: [authenticate, requirePermission('settings', 'update')]};
|
|
35
36
|
|
|
36
|
-
fastify.get('/items', canRead, async () => ({launchers: getLaunchers()}));
|
|
37
|
+
fastify.get('/items', canRead, async () => ({launchers: getLaunchers(), aiAssist: isAiAssist()}));
|
|
37
38
|
|
|
38
39
|
fastify.put('/items', canUpdate, async (request, reply) => {
|
|
39
40
|
const list = request.body?.launchers;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import {getConfig} from '../config.js';
|
|
3
3
|
import {adminAccessFor} from './adminAccess.js';
|
|
4
4
|
import {covers} from './pluginScope.js';
|
|
5
|
+
import {isAiAssist} from './aiAssist.js';
|
|
5
6
|
import {characterId, normaliseCharacterSettings} from '../../public/js/characters.mjs';
|
|
6
7
|
|
|
7
8
|
const providers = new Map();
|
|
@@ -58,10 +59,11 @@ export function adminAssistantConfig() {
|
|
|
58
59
|
const settings = normaliseAdminAssistant(site.adminAssistant);
|
|
59
60
|
const characters = normaliseCharacterSettings(site.characters);
|
|
60
61
|
return {...settings, character: characters.enabled ? settings.character : '', charactersEnabled: characters.enabled, animated: characters.animated,
|
|
61
|
-
available: Boolean(globalThis[Symbol.for('domma.launcher-chat')] || process.env.MANAGER_URL && process.env.FLEET_TOKEN)};
|
|
62
|
+
available: isAiAssist() && Boolean(globalThis[Symbol.for('domma.launcher-chat')] || process.env.MANAGER_URL && process.env.FLEET_TOKEN)};
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
export async function requestAdminAnswer(input, {env = process.env, fetchFn = fetch} = {}) {
|
|
66
|
+
if (!isAiAssist()) return {status: 403, body: {error: 'AI answers come with AI Assist, in the Pro plan.'}};
|
|
65
67
|
const local = globalThis[Symbol.for('domma.launcher-chat')];
|
|
66
68
|
if (local) return local.answer(input);
|
|
67
69
|
if (!env.MANAGER_URL || !env.FLEET_TOKEN) return {status: 503, body: {error: 'AI answers are not configured on this site.'}};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI Assist - the switch for AI chat answers on this site.
|
|
3
|
+
*
|
|
4
|
+
* Della's (and any character's) AI answers in chat launchers, admin launchers
|
|
5
|
+
* and the admin assistant come with AI Assist, a paid Tool in the Pro plan. The
|
|
6
|
+
* Tool calls `hooks.enableAiAssist()` at boot (plugins.js binds it to the
|
|
7
|
+
* plugin's name, tier and closedSource, as for Dashboard Pro): only a paid,
|
|
8
|
+
* closed-source plugin - one that loads only under a licence - may switch it on.
|
|
9
|
+
* Disabling the Tool switches it off at once (plugins.js runLifecycleHook).
|
|
10
|
+
*
|
|
11
|
+
* The Manager still checks the site's AI Assist licence on every answer; this
|
|
12
|
+
* switch only means the site does not offer or ask for answers it cannot have.
|
|
13
|
+
*
|
|
14
|
+
* @module services/aiAssist
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const owners = new Set();
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @param {{owner: string, tier: string, closedSource: boolean}} who
|
|
21
|
+
* @returns {boolean} whether it is now on
|
|
22
|
+
*/
|
|
23
|
+
export function enableAiAssist({owner, tier, closedSource} = {}) {
|
|
24
|
+
if (typeof owner !== 'string' || !owner.trim()) return false;
|
|
25
|
+
if (tier !== 'paid' || closedSource !== true) return false;
|
|
26
|
+
owners.add(owner.trim());
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The Tool that kept it on was disabled; the last one gone switches it off. */
|
|
31
|
+
export function disableAiAssist(owner) {
|
|
32
|
+
owners.delete(String(owner || '').trim());
|
|
33
|
+
return owners.size > 0;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Whether this site has AI Assist right now. */
|
|
37
|
+
export function isAiAssist() {
|
|
38
|
+
return owners.size > 0;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Tests only: forget every owner. */
|
|
42
|
+
export function _resetAiAssistForTests() {
|
|
43
|
+
owners.clear();
|
|
44
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Della's AI answers - what the chat bot says when the Knowledge has no answer.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Comes with AI Assist (a Tool in the Pro plan, services/aiAssist.js) on hosted sites, so a site holds no Claude key: the question goes to the Manager
|
|
5
5
|
* that runs the site (MANAGER_URL + FLEET_TOKEN, POST /api/fleet/launcher-chat), which checks the licence and
|
|
6
6
|
* the month's allowance and asks Claude from a short-lived job that alone reads the key. On dcm, which is the
|
|
7
7
|
* Manager, the same code is reached in this process (globalThis[Symbol.for('domma.launcher-chat')]). A site
|
|
8
|
-
* with
|
|
8
|
+
* without AI Assist, or with no Manager to ask, has no AI answers, and the bot answers from the Knowledge alone.
|
|
9
9
|
*
|
|
10
10
|
* What Claude is given: the site's name, Site Settings > AI assistant and the launcher's own context and rules
|
|
11
11
|
* (services/assistant.js), the enabled Knowledge, the last few messages of this chat and the question. It
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
*/
|
|
17
17
|
import {assistantBrief} from '../assistant.js';
|
|
18
18
|
import {knowledgeIndex, messagesAfter} from './store.js';
|
|
19
|
+
import {isAiAssist} from '../aiAssist.js';
|
|
19
20
|
|
|
20
21
|
const REGISTRY = Symbol.for('domma.launcher-chat');
|
|
21
22
|
/** What a visitor will wait for an answer. */
|
|
@@ -29,9 +30,9 @@ const BACKOFF_MS = {403: 10 * 60_000, 429: 30 * 60_000, other: 60_000};
|
|
|
29
30
|
let restUntil = 0;
|
|
30
31
|
export function _resetAi() { restUntil = 0; }
|
|
31
32
|
|
|
32
|
-
/** Whether this site has someone to ask. */
|
|
33
|
+
/** Whether this site has AI Assist and someone to ask. */
|
|
33
34
|
export function aiAvailable(env = process.env, at = Date.now()) {
|
|
34
|
-
if (at < restUntil) return false;
|
|
35
|
+
if (at < restUntil || !isAiAssist()) return false;
|
|
35
36
|
return Boolean(globalThis[REGISTRY] || (env.MANAGER_URL && env.FLEET_TOKEN));
|
|
36
37
|
}
|
|
37
38
|
|
|
@@ -43,6 +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
47
|
import {createCollection, getCollection, updateCollection} from './collections.js';
|
|
47
48
|
import * as defaultRolesService from './roles.js';
|
|
48
49
|
import {getAdminScope, normaliseAdminScope} from './roles.js';
|
|
@@ -580,6 +581,8 @@ export async function registerPlugins(fastify) {
|
|
|
580
581
|
enableInstantCalls: () => enableInstantCalls({owner: manifest.name, tier: manifest.tier || 'free', closedSource: manifest.closedSource === true}),
|
|
581
582
|
// Dashboard Pro (services/widgets.js) - the widget board; the same contract as instant calls.
|
|
582
583
|
enableDashboardPro: () => enableDashboardPro({owner: manifest.name, tier: manifest.tier || 'free', closedSource: manifest.closedSource === true}),
|
|
584
|
+
// AI Assist (services/aiAssist.js) - AI chat answers in launchers and the admin assistant; the same contract.
|
|
585
|
+
enableAiAssist: () => enableAiAssist({owner: manifest.name, tier: manifest.tier || 'free', closedSource: manifest.closedSource === true}),
|
|
583
586
|
// A widget from code (anything richer than a manifest's admin.widgets entry), owned by this plugin.
|
|
584
587
|
registerWidget: (def) => registerWidget({...def, owner: manifest.name, source: manifest.displayName || manifest.name}),
|
|
585
588
|
// Who may read a contact that is not their own (Contacts Pro's sharing) - hooks.js 7b.
|
|
@@ -1168,6 +1171,7 @@ export async function runLifecycleHook(name, hook, fastify) {
|
|
|
1168
1171
|
if (hook === 'onDisable') {
|
|
1169
1172
|
disableInstantCalls(name);
|
|
1170
1173
|
disableDashboardPro(name);
|
|
1174
|
+
disableAiAssist(name);
|
|
1171
1175
|
unregisterWidgetsFrom(name);
|
|
1172
1176
|
unregisterContactAccess(name);
|
|
1173
1177
|
unregisterDirectMessenger(name);
|