@aglyn/plugins-ai 1.30.0 → 1.32.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/README.md +2 -1
- package/package.json +17 -17
- package/src/lib/components/site-chat-api.d.ts +38 -0
- package/src/lib/components/site-chat-api.js +65 -0
- package/src/lib/components/site-chat-api.js.map +1 -0
- package/src/lib/components/site-chat-card.component.d.ts +31 -0
- package/src/lib/components/site-chat-card.component.js +474 -0
- package/src/lib/components/site-chat-card.component.js.map +1 -0
- package/src/lib/components/site-chat-panel.d.ts +38 -0
- package/src/lib/components/site-chat-panel.js +749 -0
- package/src/lib/components/site-chat-panel.js.map +1 -0
- package/src/lib/components/site-chat-runtime.d.ts +29 -0
- package/src/lib/components/site-chat-runtime.js +166 -0
- package/src/lib/components/site-chat-runtime.js.map +1 -0
- package/src/lib/declarations.js +5 -0
- package/src/lib/declarations.js.map +1 -1
- package/src/lib/model/site-chat.d.ts +219 -0
- package/src/lib/model/site-chat.js +200 -0
- package/src/lib/model/site-chat.js.map +1 -0
- package/src/lib/plugin.js +10 -0
- package/src/lib/plugin.js.map +1 -1
- package/src/lib/runtime/ai-palette.generated.js +124 -0
- package/src/lib/runtime/ai-palette.generated.js.map +1 -1
- package/src/lib/server/site-chat-enricher.d.ts +29 -0
- package/src/lib/server/site-chat-enricher.js +41 -0
- package/src/lib/server/site-chat-enricher.js.map +1 -0
- package/src/lib/server/site-chat-owner-routes.d.ts +56 -0
- package/src/lib/server/site-chat-owner-routes.js +209 -0
- package/src/lib/server/site-chat-owner-routes.js.map +1 -0
- package/src/lib/server/site-chat-page-reads.d.ts +23 -0
- package/src/lib/server/site-chat-page-reads.js +32 -0
- package/src/lib/server/site-chat-page-reads.js.map +1 -0
- package/src/lib/server/site-chat-platform.d.ts +25 -0
- package/src/lib/server/site-chat-platform.js +405 -0
- package/src/lib/server/site-chat-platform.js.map +1 -0
- package/src/lib/server/site-chat-prompt.d.ts +83 -0
- package/src/lib/server/site-chat-prompt.js +166 -0
- package/src/lib/server/site-chat-prompt.js.map +1 -0
- package/src/lib/server/site-chat-session.d.ts +33 -0
- package/src/lib/server/site-chat-session.js +105 -0
- package/src/lib/server/site-chat-session.js.map +1 -0
- package/src/lib/server/site-chat-visitor-routes.d.ts +46 -0
- package/src/lib/server/site-chat-visitor-routes.js +105 -0
- package/src/lib/server/site-chat-visitor-routes.js.map +1 -0
- package/src/lib/server/site-chat.d.ts +119 -0
- package/src/lib/server/site-chat.js +500 -0
- package/src/lib/server/site-chat.js.map +1 -0
- package/src/lib/server.js +4 -0
- package/src/lib/server.js.map +1 -1
- package/src/lib/site-server.d.ts +23 -0
- package/src/lib/site-server.js +41 -0
- package/src/lib/site-server.js.map +1 -0
- package/src/lib/site.d.ts +23 -0
- package/src/lib/site.js +33 -0
- package/src/lib/site.js.map +1 -0
- package/src/lib/usage/site-chat-meter.d.ts +68 -0
- package/src/lib/usage/site-chat-meter.js +125 -0
- package/src/lib/usage/site-chat-meter.js.map +1 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import type { SitePageEnricher } from '@aglyn/aglyn/plugin-manager/site-page-hooks';
|
|
18
|
+
export interface SiteChatEnricherDeps {
|
|
19
|
+
readSettings: (hostId: string) => Promise<unknown>;
|
|
20
|
+
flagOn: (orgId: string) => Promise<boolean>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The page's chat slice (AGL-4250): a page the chat shows on carries the
|
|
24
|
+
* greeting, the suggested questions and what the chat may do; every other
|
|
25
|
+
* page carries nothing, so the site bundle loads the chat runtime only where
|
|
26
|
+
* the chat is. The answer to "is it on" is the door's own, rung for rung, so
|
|
27
|
+
* a launcher never shows for a door that would answer 404.
|
|
28
|
+
*/
|
|
29
|
+
export declare function createSiteChatPageEnricher(deps: SiteChatEnricherDeps): SitePageEnricher;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/ import { resolveEffectivePlan } from "@aglyn/aglyn/app-utils/plan-entitlements";
|
|
17
|
+
import { isAiOnForSite } from "../model/ai-site-switch.js";
|
|
18
|
+
import { readStoredSiteChatSettings, SITE_CHAT_PAGE_PROP, siteChatOnPlan, siteChatSliceForPage } from "../model/site-chat.js";
|
|
19
|
+
/**
|
|
20
|
+
* The page's chat slice (AGL-4250): a page the chat shows on carries the
|
|
21
|
+
* greeting, the suggested questions and what the chat may do; every other
|
|
22
|
+
* page carries nothing, so the site bundle loads the chat runtime only where
|
|
23
|
+
* the chat is. The answer to "is it on" is the door's own, rung for rung, so
|
|
24
|
+
* a launcher never shows for a door that would answer 404.
|
|
25
|
+
*/ export function createSiteChatPageEnricher(deps) {
|
|
26
|
+
return async ({ hostId, host, org, path, pathUnknown })=>{
|
|
27
|
+
var _ref, _ref1;
|
|
28
|
+
if (!hostId || !org) return {};
|
|
29
|
+
if (!siteChatOnPlan(resolveEffectivePlan(org)) || !isAiOnForSite(org, host)) return {};
|
|
30
|
+
const settings = readStoredSiteChatSettings(await deps.readSettings(hostId));
|
|
31
|
+
const slice = siteChatSliceForPage(settings, path, Boolean(pathUnknown));
|
|
32
|
+
if (!slice) return {};
|
|
33
|
+
const orgId = String((_ref = (_ref1 = org == null ? void 0 : org.$id) != null ? _ref1 : host == null ? void 0 : host.orgId) != null ? _ref : '');
|
|
34
|
+
if (!orgId || !await deps.flagOn(orgId)) return {};
|
|
35
|
+
return {
|
|
36
|
+
[SITE_CHAT_PAGE_PROP]: slice
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
//# sourceMappingURL=site-chat-enricher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/server/site-chat-enricher.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { SitePageEnricher } from '@aglyn/aglyn/plugin-manager/site-page-hooks'\nimport { resolveEffectivePlan } from '@aglyn/aglyn/app-utils/plan-entitlements'\nimport { isAiOnForSite } from '../model/ai-site-switch'\nimport {\n readStoredSiteChatSettings,\n SITE_CHAT_PAGE_PROP,\n siteChatOnPlan,\n siteChatSliceForPage,\n} from '../model/site-chat'\n\nexport interface SiteChatEnricherDeps {\n readSettings: (hostId: string) => Promise<unknown>\n flagOn: (orgId: string) => Promise<boolean>\n}\n\n/**\n * The page's chat slice (AGL-4250): a page the chat shows on carries the\n * greeting, the suggested questions and what the chat may do; every other\n * page carries nothing, so the site bundle loads the chat runtime only where\n * the chat is. The answer to \"is it on\" is the door's own, rung for rung, so\n * a launcher never shows for a door that would answer 404.\n */\nexport function createSiteChatPageEnricher(deps: SiteChatEnricherDeps): SitePageEnricher {\n return async ({ hostId, host, org, path, pathUnknown }) => {\n if (!hostId || !org) return {}\n if (!siteChatOnPlan(resolveEffectivePlan(org)) || !isAiOnForSite(org, host)) return {}\n const settings = readStoredSiteChatSettings(await deps.readSettings(hostId))\n const slice = siteChatSliceForPage(settings, path, Boolean(pathUnknown))\n if (!slice) return {}\n const orgId = String(org?.$id ?? host?.orgId ?? '')\n if (!orgId || !(await deps.flagOn(orgId))) return {}\n return { [SITE_CHAT_PAGE_PROP]: slice }\n }\n}\n"],"names":["resolveEffectivePlan","isAiOnForSite","readStoredSiteChatSettings","SITE_CHAT_PAGE_PROP","siteChatOnPlan","siteChatSliceForPage","createSiteChatPageEnricher","deps","hostId","host","org","path","pathUnknown","settings","readSettings","slice","Boolean","orgId","String","$id","flagOn"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAGD,SAASA,oBAAoB,QAAQ,2CAA0C;AAC/E,SAASC,aAAa,QAAQ,6BAAyB;AACvD,SACEC,0BAA0B,EAC1BC,mBAAmB,EACnBC,cAAc,EACdC,oBAAoB,QACf,wBAAoB;AAO3B;;;;;;CAMC,GACD,OAAO,SAASC,2BAA2BC,IAA0B;IACnE,OAAO,OAAO,EAAEC,MAAM,EAAEC,IAAI,EAAEC,GAAG,EAAEC,IAAI,EAAEC,WAAW,EAAE;YAM/BF;QALrB,IAAI,CAACF,UAAU,CAACE,KAAK,OAAO,CAAC;QAC7B,IAAI,CAACN,eAAeJ,qBAAqBU,SAAS,CAACT,cAAcS,KAAKD,OAAO,OAAO,CAAC;QACrF,MAAMI,WAAWX,2BAA2B,MAAMK,KAAKO,YAAY,CAACN;QACpE,MAAMO,QAAQV,qBAAqBQ,UAAUF,MAAMK,QAAQJ;QAC3D,IAAI,CAACG,OAAO,OAAO,CAAC;QACpB,MAAME,QAAQC,QAAOR,gBAAAA,uBAAAA,IAAKS,GAAG,oBAAIV,wBAAAA,KAAMQ,KAAK,YAAvBP,OAA2B;QAChD,IAAI,CAACO,SAAS,CAAE,MAAMV,KAAKa,MAAM,CAACH,QAAS,OAAO,CAAC;QACnD,OAAO;YAAE,CAACd,oBAAoB,EAAEY;QAAM;IACxC;AACF"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import type { PluginApiHandler } from '@aglyn/aglyn/app-utils/api-plugins';
|
|
18
|
+
import { type SiteChatConversationSummary, type SiteChatMonth, type SiteChatSettings, type SiteChatTurn } from '../model/site-chat';
|
|
19
|
+
/**
|
|
20
|
+
* The owner's site chat doors on the console (AGL-4250):
|
|
21
|
+
*
|
|
22
|
+
* - `GET|POST ai/site-chat/settings?hostId=` — the chat's settings card: on
|
|
23
|
+
* or off, the greeting, suggested questions, opening message, what it may
|
|
24
|
+
* do, the pages it shows on and the monthly cap; with what the plan allows
|
|
25
|
+
* and this month's figures. Writing takes "Manage site settings".
|
|
26
|
+
* - `GET ai/site-chat/conversations?hostId=[&id=]` — the site's visitor
|
|
27
|
+
* conversations, newest first, or one conversation's turns. Any member of
|
|
28
|
+
* the site may read them.
|
|
29
|
+
*/
|
|
30
|
+
export interface SiteChatOwnerDeps {
|
|
31
|
+
verifyIdToken: (token: string) => Promise<{
|
|
32
|
+
uid: string;
|
|
33
|
+
staff?: boolean;
|
|
34
|
+
}>;
|
|
35
|
+
isEmailUnverified: (error: unknown) => boolean;
|
|
36
|
+
readSiteAccess: (hostId: string) => Promise<{
|
|
37
|
+
memberRoles: Record<string, unknown>;
|
|
38
|
+
memberPermissions?: unknown;
|
|
39
|
+
orgId: string | null;
|
|
40
|
+
} | null>;
|
|
41
|
+
readPlan: (orgId: string) => Promise<string>;
|
|
42
|
+
flagOn: (orgId: string) => Promise<boolean>;
|
|
43
|
+
siteLocked: (hostId: string) => Promise<boolean>;
|
|
44
|
+
readSettings: (hostId: string) => Promise<unknown>;
|
|
45
|
+
writeSettings: (hostId: string, settings: SiteChatSettings, uid: string) => Promise<void>;
|
|
46
|
+
dropSiteCache: (hostId: string) => Promise<boolean>;
|
|
47
|
+
readMonth: (orgId: string, hostId: string) => Promise<SiteChatMonth>;
|
|
48
|
+
listConversations: (hostId: string, limit: number) => Promise<SiteChatConversationSummary[]>;
|
|
49
|
+
readConversation: (hostId: string, id: string) => Promise<{
|
|
50
|
+
summary: SiteChatConversationSummary;
|
|
51
|
+
turns: SiteChatTurn[];
|
|
52
|
+
handOff: unknown;
|
|
53
|
+
} | null>;
|
|
54
|
+
}
|
|
55
|
+
export declare function createSiteChatSettingsHandler(deps: SiteChatOwnerDeps): PluginApiHandler;
|
|
56
|
+
export declare function createSiteChatConversationsHandler(deps: SiteChatOwnerDeps): PluginApiHandler;
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/ import { holdsSiteKey, siteKeyRefusal } from "@aglyn/aglyn/app-utils/host-permissions";
|
|
17
|
+
import { isRefusedIdToken } from "@aglyn/tenant-data-admin/server/id-token-refusal";
|
|
18
|
+
import { normalizeSiteChatSettings, readStoredSiteChatSettings, SITE_CHAT_DEFAULT_SETTINGS, siteChatCeiling, siteChatOnPlan, siteChatPlanCredits } from "../model/site-chat.js";
|
|
19
|
+
const HOST_ID = /^[A-Za-z0-9_-]{1,128}$/;
|
|
20
|
+
const CONVERSATION_ID = /^[0-9a-f]{32}$/;
|
|
21
|
+
const bearerOf = (req)=>{
|
|
22
|
+
var _ref;
|
|
23
|
+
const header = req.headers['authorization'];
|
|
24
|
+
const value = String((_ref = Array.isArray(header) ? header[0] : header) != null ? _ref : '');
|
|
25
|
+
return value.startsWith('Bearer ') ? value.slice('Bearer '.length) : '';
|
|
26
|
+
};
|
|
27
|
+
const bodyOf = (req)=>{
|
|
28
|
+
var _req_body;
|
|
29
|
+
if (typeof req.body === 'string') {
|
|
30
|
+
try {
|
|
31
|
+
return JSON.parse(req.body);
|
|
32
|
+
} catch (unused) {
|
|
33
|
+
return {};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return (_req_body = req.body) != null ? _req_body : {};
|
|
37
|
+
};
|
|
38
|
+
async function authorize(deps, req, hostId) {
|
|
39
|
+
const token = bearerOf(req);
|
|
40
|
+
if (!token) return {
|
|
41
|
+
status: 401,
|
|
42
|
+
body: {
|
|
43
|
+
error: 'Unauthenticated'
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
let decoded;
|
|
47
|
+
try {
|
|
48
|
+
decoded = await deps.verifyIdToken(token);
|
|
49
|
+
} catch (error) {
|
|
50
|
+
if (deps.isEmailUnverified(error)) {
|
|
51
|
+
return {
|
|
52
|
+
status: 403,
|
|
53
|
+
body: {
|
|
54
|
+
error: 'Verify your email to continue',
|
|
55
|
+
reason: 'email-unverified'
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
if (!isRefusedIdToken(error)) throw error;
|
|
60
|
+
return {
|
|
61
|
+
status: 401,
|
|
62
|
+
body: {
|
|
63
|
+
error: 'Unauthenticated'
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
const access = await deps.readSiteAccess(hostId);
|
|
68
|
+
if (!access) return {
|
|
69
|
+
status: 404,
|
|
70
|
+
body: {
|
|
71
|
+
error: 'Unknown site'
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const staff = decoded.staff === true;
|
|
75
|
+
if (!staff && !access.memberRoles[decoded.uid]) {
|
|
76
|
+
return {
|
|
77
|
+
status: 403,
|
|
78
|
+
body: {
|
|
79
|
+
error: 'You are not a member of this site'
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
caller: {
|
|
85
|
+
uid: decoded.uid,
|
|
86
|
+
staff,
|
|
87
|
+
access
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
export function createSiteChatSettingsHandler(deps) {
|
|
92
|
+
return async (req, res)=>{
|
|
93
|
+
var _ref;
|
|
94
|
+
if (req.method !== 'GET' && req.method !== 'POST') return res.status(405).json({
|
|
95
|
+
error: 'Method not allowed'
|
|
96
|
+
});
|
|
97
|
+
const body = req.method === 'POST' ? bodyOf(req) : {};
|
|
98
|
+
const hostId = String((_ref = req.method === 'GET' ? req.query['hostId'] : body['hostId']) != null ? _ref : '');
|
|
99
|
+
if (!HOST_ID.test(hostId)) return res.status(400).json({
|
|
100
|
+
error: 'Missing site'
|
|
101
|
+
});
|
|
102
|
+
try {
|
|
103
|
+
var _body_settings;
|
|
104
|
+
const auth = await authorize(deps, req, hostId);
|
|
105
|
+
if ('status' in auth) return res.status(auth.status).json(auth.body);
|
|
106
|
+
const { caller } = auth;
|
|
107
|
+
const canManage = caller.staff || holdsSiteKey(caller.access, caller.uid, 'site.manage');
|
|
108
|
+
const orgId = caller.access.orgId;
|
|
109
|
+
const [plan, released] = orgId ? await Promise.all([
|
|
110
|
+
deps.readPlan(orgId),
|
|
111
|
+
deps.flagOn(orgId)
|
|
112
|
+
]) : [
|
|
113
|
+
'free',
|
|
114
|
+
false
|
|
115
|
+
];
|
|
116
|
+
// A released-off feature does not exist; staff preview it.
|
|
117
|
+
if (!released && !caller.staff) return res.status(404).json({
|
|
118
|
+
error: 'Not found'
|
|
119
|
+
});
|
|
120
|
+
const planCredits = siteChatPlanCredits(plan);
|
|
121
|
+
if (req.method === 'GET') {
|
|
122
|
+
const settings = readStoredSiteChatSettings(await deps.readSettings(hostId));
|
|
123
|
+
const answer = {
|
|
124
|
+
settings,
|
|
125
|
+
canManage,
|
|
126
|
+
onPlan: siteChatOnPlan(plan),
|
|
127
|
+
released,
|
|
128
|
+
planCredits,
|
|
129
|
+
ceiling: siteChatCeiling(planCredits, settings.monthlyCreditCap),
|
|
130
|
+
month: orgId ? await deps.readMonth(orgId, hostId).catch(()=>null) : null
|
|
131
|
+
};
|
|
132
|
+
return res.status(200).json(answer);
|
|
133
|
+
}
|
|
134
|
+
if (!canManage) return res.status(403).json({
|
|
135
|
+
error: siteKeyRefusal('site.manage')
|
|
136
|
+
});
|
|
137
|
+
if (await deps.siteLocked(hostId)) {
|
|
138
|
+
return res.status(423).json({
|
|
139
|
+
error: 'This site is locked and cannot take changes right now.'
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
const result = normalizeSiteChatSettings((_body_settings = body['settings']) != null ? _body_settings : SITE_CHAT_DEFAULT_SETTINGS);
|
|
143
|
+
if ('error' in result) return res.status(400).json({
|
|
144
|
+
error: result.error
|
|
145
|
+
});
|
|
146
|
+
if (result.settings.enabled && !siteChatOnPlan(plan)) {
|
|
147
|
+
return res.status(402).json({
|
|
148
|
+
error: 'Site chat is included from the Starter plan up.',
|
|
149
|
+
reason: 'plan'
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
await deps.writeSettings(hostId, result.settings, caller.uid);
|
|
153
|
+
const refreshed = await deps.dropSiteCache(hostId).catch(()=>false);
|
|
154
|
+
return res.status(200).json({
|
|
155
|
+
settings: result.settings,
|
|
156
|
+
canManage,
|
|
157
|
+
refreshed
|
|
158
|
+
});
|
|
159
|
+
} catch (error) {
|
|
160
|
+
console.error('[ai/site-chat/settings]', error);
|
|
161
|
+
return res.status(500).json({
|
|
162
|
+
error: 'That did not go through. Try again.'
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
export function createSiteChatConversationsHandler(deps) {
|
|
168
|
+
return async (req, res)=>{
|
|
169
|
+
var _req_query_hostId, _req_query_id;
|
|
170
|
+
if (req.method !== 'GET') return res.status(405).json({
|
|
171
|
+
error: 'Method not allowed'
|
|
172
|
+
});
|
|
173
|
+
const hostId = String((_req_query_hostId = req.query['hostId']) != null ? _req_query_hostId : '');
|
|
174
|
+
if (!HOST_ID.test(hostId)) return res.status(400).json({
|
|
175
|
+
error: 'Missing site'
|
|
176
|
+
});
|
|
177
|
+
const id = String((_req_query_id = req.query['id']) != null ? _req_query_id : '');
|
|
178
|
+
if (id && !CONVERSATION_ID.test(id)) return res.status(400).json({
|
|
179
|
+
error: 'Unknown conversation'
|
|
180
|
+
});
|
|
181
|
+
try {
|
|
182
|
+
const auth = await authorize(deps, req, hostId);
|
|
183
|
+
if ('status' in auth) return res.status(auth.status).json(auth.body);
|
|
184
|
+
const orgId = auth.caller.access.orgId;
|
|
185
|
+
if (!auth.caller.staff && !(orgId && await deps.flagOn(orgId))) {
|
|
186
|
+
return res.status(404).json({
|
|
187
|
+
error: 'Not found'
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
if (id) {
|
|
191
|
+
const conversation = await deps.readConversation(hostId, id);
|
|
192
|
+
if (!conversation) return res.status(404).json({
|
|
193
|
+
error: 'Unknown conversation'
|
|
194
|
+
});
|
|
195
|
+
return res.status(200).json(conversation);
|
|
196
|
+
}
|
|
197
|
+
return res.status(200).json({
|
|
198
|
+
conversations: await deps.listConversations(hostId, 50)
|
|
199
|
+
});
|
|
200
|
+
} catch (error) {
|
|
201
|
+
console.error('[ai/site-chat/conversations]', error);
|
|
202
|
+
return res.status(500).json({
|
|
203
|
+
error: 'That did not load. Try again.'
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
//# sourceMappingURL=site-chat-owner-routes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/server/site-chat-owner-routes.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { PluginApiHandler, PluginApiRequest } from '@aglyn/aglyn/app-utils/api-plugins'\nimport { holdsSiteKey, siteKeyRefusal } from '@aglyn/aglyn/app-utils/host-permissions'\nimport { isRefusedIdToken } from '@aglyn/tenant-data-admin/server/id-token-refusal'\nimport {\n normalizeSiteChatSettings,\n readStoredSiteChatSettings,\n SITE_CHAT_DEFAULT_SETTINGS,\n siteChatCeiling,\n siteChatOnPlan,\n siteChatPlanCredits,\n type SiteChatConversationSummary,\n type SiteChatMonth,\n type SiteChatSettings,\n type SiteChatSettingsAnswer,\n type SiteChatTurn,\n} from '../model/site-chat'\n\n/**\n * The owner's site chat doors on the console (AGL-4250):\n *\n * - `GET|POST ai/site-chat/settings?hostId=` — the chat's settings card: on\n * or off, the greeting, suggested questions, opening message, what it may\n * do, the pages it shows on and the monthly cap; with what the plan allows\n * and this month's figures. Writing takes \"Manage site settings\".\n * - `GET ai/site-chat/conversations?hostId=[&id=]` — the site's visitor\n * conversations, newest first, or one conversation's turns. Any member of\n * the site may read them.\n */\n\nexport interface SiteChatOwnerDeps {\n verifyIdToken: (token: string) => Promise<{ uid: string; staff?: boolean }>\n isEmailUnverified: (error: unknown) => boolean\n readSiteAccess: (hostId: string) => Promise<{\n memberRoles: Record<string, unknown>\n memberPermissions?: unknown\n orgId: string | null\n } | null>\n readPlan: (orgId: string) => Promise<string>\n flagOn: (orgId: string) => Promise<boolean>\n siteLocked: (hostId: string) => Promise<boolean>\n readSettings: (hostId: string) => Promise<unknown>\n writeSettings: (hostId: string, settings: SiteChatSettings, uid: string) => Promise<void>\n dropSiteCache: (hostId: string) => Promise<boolean>\n readMonth: (orgId: string, hostId: string) => Promise<SiteChatMonth>\n listConversations: (hostId: string, limit: number) => Promise<SiteChatConversationSummary[]>\n readConversation: (\n hostId: string,\n id: string,\n ) => Promise<{ summary: SiteChatConversationSummary; turns: SiteChatTurn[]; handOff: unknown } | null>\n}\n\n\nconst HOST_ID = /^[A-Za-z0-9_-]{1,128}$/\nconst CONVERSATION_ID = /^[0-9a-f]{32}$/\n\nconst bearerOf = (req: PluginApiRequest): string => {\n const header = req.headers['authorization']\n const value = String((Array.isArray(header) ? header[0] : header) ?? '')\n return value.startsWith('Bearer ') ? value.slice('Bearer '.length) : ''\n}\n\nconst bodyOf = (req: PluginApiRequest): Record<string, unknown> => {\n if (typeof req.body === 'string') {\n try {\n return JSON.parse(req.body) as Record<string, unknown>\n } catch {\n return {}\n }\n }\n return (req.body ?? {}) as Record<string, unknown>\n}\n\ntype Caller = { uid: string; staff: boolean; access: NonNullable<Awaited<ReturnType<SiteChatOwnerDeps['readSiteAccess']>>> }\n\nasync function authorize(\n deps: SiteChatOwnerDeps,\n req: PluginApiRequest,\n hostId: string,\n): Promise<{ caller: Caller } | { status: number; body: Record<string, unknown> }> {\n const token = bearerOf(req)\n if (!token) return { status: 401, body: { error: 'Unauthenticated' } }\n let decoded: { uid: string; staff?: boolean }\n try {\n decoded = await deps.verifyIdToken(token)\n } catch (error) {\n if (deps.isEmailUnverified(error)) {\n return { status: 403, body: { error: 'Verify your email to continue', reason: 'email-unverified' } }\n }\n if (!isRefusedIdToken(error)) throw error\n return { status: 401, body: { error: 'Unauthenticated' } }\n }\n const access = await deps.readSiteAccess(hostId)\n if (!access) return { status: 404, body: { error: 'Unknown site' } }\n const staff = decoded.staff === true\n if (!staff && !access.memberRoles[decoded.uid]) {\n return { status: 403, body: { error: 'You are not a member of this site' } }\n }\n return { caller: { uid: decoded.uid, staff, access } }\n}\n\nexport function createSiteChatSettingsHandler(deps: SiteChatOwnerDeps): PluginApiHandler {\n return async (req, res) => {\n if (req.method !== 'GET' && req.method !== 'POST') return res.status(405).json({ error: 'Method not allowed' })\n const body = req.method === 'POST' ? bodyOf(req) : {}\n const hostId = String((req.method === 'GET' ? req.query['hostId'] : body['hostId']) ?? '')\n if (!HOST_ID.test(hostId)) return res.status(400).json({ error: 'Missing site' })\n try {\n const auth = await authorize(deps, req, hostId)\n if ('status' in auth) return res.status(auth.status).json(auth.body)\n const { caller } = auth\n const canManage = caller.staff || holdsSiteKey(caller.access, caller.uid, 'site.manage')\n const orgId = caller.access.orgId\n const [plan, released] = orgId\n ? await Promise.all([deps.readPlan(orgId), deps.flagOn(orgId)])\n : ['free', false]\n // A released-off feature does not exist; staff preview it.\n if (!released && !caller.staff) return res.status(404).json({ error: 'Not found' })\n const planCredits = siteChatPlanCredits(plan)\n\n if (req.method === 'GET') {\n const settings = readStoredSiteChatSettings(await deps.readSettings(hostId))\n const answer: SiteChatSettingsAnswer = {\n settings,\n canManage,\n onPlan: siteChatOnPlan(plan),\n released,\n planCredits,\n ceiling: siteChatCeiling(planCredits, settings.monthlyCreditCap),\n month: orgId ? await deps.readMonth(orgId, hostId).catch(() => null) : null,\n }\n return res.status(200).json(answer)\n }\n\n if (!canManage) return res.status(403).json({ error: siteKeyRefusal('site.manage') })\n if (await deps.siteLocked(hostId)) {\n return res.status(423).json({ error: 'This site is locked and cannot take changes right now.' })\n }\n const result = normalizeSiteChatSettings(body['settings'] ?? SITE_CHAT_DEFAULT_SETTINGS)\n if ('error' in result) return res.status(400).json({ error: result.error })\n if (result.settings.enabled && !siteChatOnPlan(plan)) {\n return res.status(402).json({ error: 'Site chat is included from the Starter plan up.', reason: 'plan' })\n }\n await deps.writeSettings(hostId, result.settings, caller.uid)\n const refreshed = await deps.dropSiteCache(hostId).catch(() => false)\n return res.status(200).json({ settings: result.settings, canManage, refreshed })\n } catch (error) {\n console.error('[ai/site-chat/settings]', error)\n return res.status(500).json({ error: 'That did not go through. Try again.' })\n }\n }\n}\n\nexport function createSiteChatConversationsHandler(deps: SiteChatOwnerDeps): PluginApiHandler {\n return async (req, res) => {\n if (req.method !== 'GET') return res.status(405).json({ error: 'Method not allowed' })\n const hostId = String(req.query['hostId'] ?? '')\n if (!HOST_ID.test(hostId)) return res.status(400).json({ error: 'Missing site' })\n const id = String(req.query['id'] ?? '')\n if (id && !CONVERSATION_ID.test(id)) return res.status(400).json({ error: 'Unknown conversation' })\n try {\n const auth = await authorize(deps, req, hostId)\n if ('status' in auth) return res.status(auth.status).json(auth.body)\n const orgId = auth.caller.access.orgId\n if (!auth.caller.staff && !(orgId && (await deps.flagOn(orgId)))) {\n return res.status(404).json({ error: 'Not found' })\n }\n if (id) {\n const conversation = await deps.readConversation(hostId, id)\n if (!conversation) return res.status(404).json({ error: 'Unknown conversation' })\n return res.status(200).json(conversation)\n }\n return res.status(200).json({ conversations: await deps.listConversations(hostId, 50) })\n } catch (error) {\n console.error('[ai/site-chat/conversations]', error)\n return res.status(500).json({ error: 'That did not load. Try again.' })\n }\n }\n}\n"],"names":["holdsSiteKey","siteKeyRefusal","isRefusedIdToken","normalizeSiteChatSettings","readStoredSiteChatSettings","SITE_CHAT_DEFAULT_SETTINGS","siteChatCeiling","siteChatOnPlan","siteChatPlanCredits","HOST_ID","CONVERSATION_ID","bearerOf","req","Array","header","headers","value","String","isArray","startsWith","slice","length","bodyOf","body","JSON","parse","authorize","deps","hostId","token","status","error","decoded","verifyIdToken","isEmailUnverified","reason","access","readSiteAccess","staff","memberRoles","uid","caller","createSiteChatSettingsHandler","res","method","json","query","test","auth","canManage","orgId","plan","released","Promise","all","readPlan","flagOn","planCredits","settings","readSettings","answer","onPlan","ceiling","monthlyCreditCap","month","readMonth","catch","siteLocked","result","enabled","writeSettings","refreshed","dropSiteCache","console","createSiteChatConversationsHandler","id","conversation","readConversation","conversations","listConversations"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAGD,SAASA,YAAY,EAAEC,cAAc,QAAQ,0CAAyC;AACtF,SAASC,gBAAgB,QAAQ,mDAAkD;AACnF,SACEC,yBAAyB,EACzBC,0BAA0B,EAC1BC,0BAA0B,EAC1BC,eAAe,EACfC,cAAc,EACdC,mBAAmB,QAMd,wBAAoB;AAqC3B,MAAMC,UAAU;AAChB,MAAMC,kBAAkB;AAExB,MAAMC,WAAW,CAACC;QAEMC;IADtB,MAAMC,SAASF,IAAIG,OAAO,CAAC,gBAAgB;IAC3C,MAAMC,QAAQC,QAAQJ,OAAAA,MAAMK,OAAO,CAACJ,UAAUA,MAAM,CAAC,EAAE,GAAGA,kBAApCD,OA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Q+C;gBACzD,IAAI,CAACC,cAAc,OAAOjC,IAAIb,MAAM,CAAC,KAAKe,IAAI,CAAC;oBAAEd,OAAO;gBAAuB;gBAC/E,OAAOY,IAAIb,MAAM,CAAC,KAAKe,IAAI,CAAC+B;YAC9B;YACA,OAAOjC,IAAIb,MAAM,CAAC,KAAKe,IAAI,CAAC;gBAAEiC,eAAe,MAAMnD,KAAKoD,iBAAiB,CAACnD,QAAQ;YAAI;QACxF,EAAE,OAAOG,OAAO;YACd0C,QAAQ1C,KAAK,CAAC,gCAAgCA;YAC9C,OAAOY,IAAIb,MAAM,CAAC,KAAKe,IAAI,CAAC;gBAAEd,OAAO;YAAgC;QACvE;IACF;AACF"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* The two reads a page render makes for the site chat (AGL-4250): the
|
|
19
|
+
* owner's settings document and the release flag. Their own module, so the
|
|
20
|
+
* render path reaches these and never the door, its provider or its meters.
|
|
21
|
+
*/
|
|
22
|
+
export declare function readSiteChatSettingsDoc(hostId: string): Promise<unknown>;
|
|
23
|
+
export declare function siteChatReleasedFor(orgId: string): Promise<boolean>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/ import { isServerReleaseFlagOnForOrg } from "@aglyn/tenant-data-admin/server/release-flags";
|
|
17
|
+
import { firebaseAdmin } from "@aglyn/tenant-data-admin/server/firebase-admin";
|
|
18
|
+
import { SITE_CHAT_RELEASE_FLAG, SITE_CHAT_SETTINGS_COLLECTION, SITE_CHAT_SETTINGS_DOC } from "../model/site-chat.js";
|
|
19
|
+
/**
|
|
20
|
+
* The two reads a page render makes for the site chat (AGL-4250): the
|
|
21
|
+
* owner's settings document and the release flag. Their own module, so the
|
|
22
|
+
* render path reaches these and never the door, its provider or its meters.
|
|
23
|
+
*/ export async function readSiteChatSettingsDoc(hostId) {
|
|
24
|
+
var _snapshot_data;
|
|
25
|
+
const snapshot = await firebaseAdmin.app().firestore().collection('hosts').doc(hostId).collection(SITE_CHAT_SETTINGS_COLLECTION).doc(SITE_CHAT_SETTINGS_DOC).get();
|
|
26
|
+
return snapshot.exists ? (_snapshot_data = snapshot.data()) != null ? _snapshot_data : null : null;
|
|
27
|
+
}
|
|
28
|
+
export function siteChatReleasedFor(orgId) {
|
|
29
|
+
return isServerReleaseFlagOnForOrg(SITE_CHAT_RELEASE_FLAG, orgId);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=site-chat-page-reads.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/server/site-chat-page-reads.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { isServerReleaseFlagOnForOrg } from '@aglyn/tenant-data-admin/server/release-flags'\nimport { firebaseAdmin } from '@aglyn/tenant-data-admin/server/firebase-admin'\nimport {\n SITE_CHAT_RELEASE_FLAG,\n SITE_CHAT_SETTINGS_COLLECTION,\n SITE_CHAT_SETTINGS_DOC,\n} from '../model/site-chat'\n\n/**\n * The two reads a page render makes for the site chat (AGL-4250): the\n * owner's settings document and the release flag. Their own module, so the\n * render path reaches these and never the door, its provider or its meters.\n */\n\nexport async function readSiteChatSettingsDoc(hostId: string): Promise<unknown> {\n const snapshot = await firebaseAdmin\n .app()\n .firestore()\n .collection('hosts')\n .doc(hostId)\n .collection(SITE_CHAT_SETTINGS_COLLECTION)\n .doc(SITE_CHAT_SETTINGS_DOC)\n .get()\n return snapshot.exists ? (snapshot.data() ?? null) : null\n}\n\nexport function siteChatReleasedFor(orgId: string): Promise<boolean> {\n return isServerReleaseFlagOnForOrg(SITE_CHAT_RELEASE_FLAG as never, orgId)\n}\n"],"names":["isServerReleaseFlagOnForOrg","firebaseAdmin","SITE_CHAT_RELEASE_FLAG","SITE_CHAT_SETTINGS_COLLECTION","SITE_CHAT_SETTINGS_DOC","readSiteChatSettingsDoc","hostId","snapshot","app","firestore","collection","doc","get","exists","data","siteChatReleasedFor","orgId"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,2BAA2B,QAAQ,gDAA+C;AAC3F,SAASC,aAAa,QAAQ,iDAAgD;AAC9E,SACEC,sBAAsB,EACtBC,6BAA6B,EAC7BC,sBAAsB,QACjB,wBAAoB;AAE3B;;;;CAIC,GAED,OAAO,eAAeC,wBAAwBC,MAAc;QAShCC;IAR1B,MAAMA,WAAW,MAAMN,cACpBO,GAAG,GACHC,SAAS,GACTC,UAAU,CAAC,SACXC,GAAG,CAACL,QACJI,UAAU,CAACP,+BACXQ,GAAG,CAACP,wBACJQ,GAAG;IACN,OAAOL,SAASM,MAAM,IAAIN,iBAAAA,SAASO,IAAI,cAAbP,iBAAmB,OAAQ;AACvD;AAEA,OAAO,SAASQ,oBAAoBC,KAAa;IAC/C,OAAOhB,4BAA4BE,wBAAiCc;AACtE"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import { type SiteChatDeps, type SiteChatSite } from './site-chat';
|
|
18
|
+
export declare const siteChatPlatformDeps: SiteChatDeps;
|
|
19
|
+
/** The door, built once per process. */
|
|
20
|
+
export declare function siteChatDoor(): (request: Request) => Promise<Response>;
|
|
21
|
+
export type { SiteChatSite };
|
|
22
|
+
export declare function siteChatHistoryDoor(): (request: Request) => Promise<Response>;
|
|
23
|
+
export declare function siteChatHandOffDoor(): (request: Request) => Promise<Response>;
|
|
24
|
+
export declare function siteChatSettingsDoor(): import("@aglyn/aglyn/src").PluginApiHandler;
|
|
25
|
+
export declare function siteChatConversationsDoor(): import("@aglyn/aglyn/src").PluginApiHandler;
|