@360vier/ai-chat-core 0.0.0-stage → 0.0.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/LICENSE +21 -0
- package/README.md +37 -2
- package/dist/chunk-45NFWKPO.js +1 -0
- package/dist/index.d.ts +133 -0
- package/dist/index.js +1 -0
- package/dist/rules.d.ts +69 -0
- package/dist/rules.js +1 -0
- package/package.json +35 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 360VIER
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,38 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @360vier/ai-chat-core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Configuration schema, page-rule matcher and snapshot projection for the 360VIER AI-Chat widget.
|
|
4
|
+
The same code runs in the browser, in Node and in Deno (standard Web APIs only, no `node:*`).
|
|
5
|
+
|
|
6
|
+
```sh
|
|
7
|
+
npm install @360vier/ai-chat-core
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Entry points
|
|
11
|
+
|
|
12
|
+
| Import | What it holds | Dependencies |
|
|
13
|
+
| ----------------------------- | ----------------------------------------------------------------------------- | ------------ |
|
|
14
|
+
| `@360vier/ai-chat-core` | `validateWidgetConfig`, `buildPublicSnapshot`, `importLegacyWordPress`, types | `zod` |
|
|
15
|
+
| `@360vier/ai-chat-core/rules` | `matchPageRules`, `resolvePage`, path helpers (under 1 kB brotli) | none |
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { validateWidgetConfig, buildPublicSnapshot } from "@360vier/ai-chat-core"
|
|
19
|
+
import { resolvePage } from "@360vier/ai-chat-core/rules"
|
|
20
|
+
|
|
21
|
+
const result = validateWidgetConfig(input)
|
|
22
|
+
if (result.ok) {
|
|
23
|
+
const snapshot = buildPublicSnapshot(result.value, "rev-1") // server-only fields are removed
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
- `zod` stays internal: callers get plain TypeScript types and functions, so the package works next to
|
|
28
|
+
zod 3 and zod 4 in the same project.
|
|
29
|
+
- Rule patterns: `/kontakt` matches one path, `/leistungen/*` matches the path and everything below it,
|
|
30
|
+
`*` inside a pattern matches one segment, `/*` matches every path.
|
|
31
|
+
|
|
32
|
+
## Status
|
|
33
|
+
|
|
34
|
+
Version 0.x: the schema is a draft and changes with the platform. Pin the exact version.
|
|
35
|
+
|
|
36
|
+
## License
|
|
37
|
+
|
|
38
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var f=/[.+?^${}()|[\]\\]/g;function c(i){let e=i.trim();return/^[a-z][a-z0-9+.-]*:\/\//i.test(e)&&(e=new URL(e).pathname),e=e.replace(/[?#].*$/,""),e.startsWith("/")||(e="/"+e),e=e.replace(/\/{2,}/g,"/"),e.length>1&&(e=e.replace(/\/+$/,"")),e}function u(i,e){let n=c(i),s=n.split("/")[1];if(s&&e.some(t=>t.toLowerCase()===s.toLowerCase())){let t=n.slice(s.length+1);return t===""?"/":t}return n}function p(i){let e=c(i);if(e==="/*")return{pattern:e,regex:/^\/.*$/,specificity:0};let n=e.endsWith("/*"),t=(n?e.slice(0,-2):e).split("/").filter(Boolean),o=t.map(g=>g==="*"?"[^/]+":g.replace(f,"\\$&")).join("/"),a=t.length===0?"":"/"+o,r=new RegExp("^"+a+(n?"(?:/.*)?":"")+(t.length===0&&!n?"/":"")+"$"),l=t.filter(g=>g!=="*").length;return{pattern:e,regex:r,specificity:l*10+(n?0:5)}}function m(i,e){return p(i).regex.test(c(e))}function h(i,e,n={}){let s=u(e,n.locales??[]);return i.map((t,o)=>({rule:t,index:o,compiled:p(t.match)})).filter(({compiled:t})=>t.regex.test(s)).sort((t,o)=>t.compiled.specificity-o.compiled.specificity||t.index-o.index).map(({rule:t})=>t)}function y(i,e,n,s,t={}){let o=h(e,n,t),a={display:i.display,hidden:i.display==="hidden",questions:i.questions,greeting:i.greeting,ruleIds:o.map(r=>r.id)};for(let r of o){r.display==="hidden"?(a.display="hidden",a.hidden=!0):r.display&&r.display!=="inherit"&&(a.display=r.display,a.hidden=!1);let l=r.questions?.[s]?.map(d=>d.trim()).filter(Boolean)??[];l.length>0&&(a.questions=l);let g=r.greeting?.[s]?.trim();g&&(a.greeting=g)}return a}export{c as a,u as b,p as c,m as d,h as e,y as f};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
export { CompiledPattern, MatchOptions, PageBase, PageRule, ResolvedPage, RuleDisplay, compilePattern, matchPageRules, matchesPattern, normalizePath, resolvePage, stripLocalePrefix } from './rules.js';
|
|
2
|
+
|
|
3
|
+
/** Whether a CSS custom property may go into the theme (same rule as the schema). */
|
|
4
|
+
declare function isAllowedToken(name: string, value: string): boolean;
|
|
5
|
+
interface WidgetRule {
|
|
6
|
+
id: string;
|
|
7
|
+
match: string;
|
|
8
|
+
display: "inherit" | "shown" | "hidden";
|
|
9
|
+
questions?: Record<string, string[]> | undefined;
|
|
10
|
+
greeting?: Record<string, string> | undefined;
|
|
11
|
+
/** Server only: never part of the public snapshot. */
|
|
12
|
+
promptAddition?: string | undefined;
|
|
13
|
+
}
|
|
14
|
+
interface WidgetLocaleTexts {
|
|
15
|
+
greeting?: string | undefined;
|
|
16
|
+
placeholder?: string | undefined;
|
|
17
|
+
messagePlaceholder?: string | undefined;
|
|
18
|
+
footer?: string | undefined;
|
|
19
|
+
headerTitle?: string | undefined;
|
|
20
|
+
emptyStateTitle?: string | undefined;
|
|
21
|
+
emptyStateSubtitle?: string | undefined;
|
|
22
|
+
teaser?: string | undefined;
|
|
23
|
+
}
|
|
24
|
+
interface WidgetConfigDocument {
|
|
25
|
+
locales: string[];
|
|
26
|
+
display: "shown" | "hidden";
|
|
27
|
+
theme: {
|
|
28
|
+
tokens: Record<string, string>;
|
|
29
|
+
backdrop: {
|
|
30
|
+
color: string;
|
|
31
|
+
opacity: number;
|
|
32
|
+
};
|
|
33
|
+
autoContrast: boolean;
|
|
34
|
+
fonts: {
|
|
35
|
+
heading?: string | undefined;
|
|
36
|
+
body?: string | undefined;
|
|
37
|
+
};
|
|
38
|
+
avatar?: string | undefined;
|
|
39
|
+
};
|
|
40
|
+
launcher: {
|
|
41
|
+
mode: "bubble" | "sticky_bar";
|
|
42
|
+
position: "left" | "right";
|
|
43
|
+
size: "xs" | "sm" | "md" | "lg" | "xl" | "2xl";
|
|
44
|
+
showBubble: boolean;
|
|
45
|
+
icon?: string | undefined;
|
|
46
|
+
collapseAfterPx: number;
|
|
47
|
+
restoreNearBottomPx: number;
|
|
48
|
+
};
|
|
49
|
+
teaser: {
|
|
50
|
+
enabled: boolean;
|
|
51
|
+
delayS: number;
|
|
52
|
+
frequencyDays: number;
|
|
53
|
+
scrollScreens: number;
|
|
54
|
+
};
|
|
55
|
+
tracking: {
|
|
56
|
+
enabled: boolean;
|
|
57
|
+
};
|
|
58
|
+
texts: Record<string, WidgetLocaleTexts>;
|
|
59
|
+
questions: Record<string, string[]>;
|
|
60
|
+
messageRatingEnabled: boolean;
|
|
61
|
+
rules: WidgetRule[];
|
|
62
|
+
/** Server only: never part of the public snapshot. */
|
|
63
|
+
server: {
|
|
64
|
+
useChainOfThought: boolean;
|
|
65
|
+
sourcesSimilarityThreshold: number;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
type PublicRule = Omit<WidgetRule, "promptAddition">;
|
|
69
|
+
type PublicSnapshot = Omit<WidgetConfigDocument, "rules" | "server"> & {
|
|
70
|
+
version: string;
|
|
71
|
+
rules: PublicRule[];
|
|
72
|
+
};
|
|
73
|
+
interface ValidationIssue {
|
|
74
|
+
path: string;
|
|
75
|
+
message: string;
|
|
76
|
+
}
|
|
77
|
+
type ValidationResult = {
|
|
78
|
+
ok: true;
|
|
79
|
+
value: WidgetConfigDocument;
|
|
80
|
+
} | {
|
|
81
|
+
ok: false;
|
|
82
|
+
issues: ValidationIssue[];
|
|
83
|
+
};
|
|
84
|
+
declare function validateWidgetConfig(input: unknown): ValidationResult;
|
|
85
|
+
/** Projects a valid document onto the public snapshot: removes every server-only field. */
|
|
86
|
+
declare function buildPublicSnapshot(doc: WidgetConfigDocument, version: string): PublicSnapshot;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Import of the settings of WordPress plugin 1.8 (the option `dhsv100_ai_chat_plugin_settings`)
|
|
90
|
+
* into a widget config document. Plugin 2.0 calls it behind its import button; the platform
|
|
91
|
+
* validates and publishes the result.
|
|
92
|
+
*
|
|
93
|
+
* It reads the option the way 1.8 reads it (SettingsOverlay::to_document()): a field that is
|
|
94
|
+
* absent or empty is left out, so the widget's defaults (the 1.8 defaults) apply; a value that
|
|
95
|
+
* cannot be converted is left out and reported in `skipped`. Nothing here throws on bad input.
|
|
96
|
+
*
|
|
97
|
+
* WordPress-only facts come in through the context: attachment IDs become URLs, page IDs
|
|
98
|
+
* become paths. The plugin knows them, core does not.
|
|
99
|
+
*/
|
|
100
|
+
|
|
101
|
+
interface LegacyImportContext {
|
|
102
|
+
/** The site's default language, e.g. "de". */
|
|
103
|
+
locale: string;
|
|
104
|
+
/** Per-language overrides of translatable fields (WPML), keyed by language code. */
|
|
105
|
+
languageOverrides?: Record<string, unknown>;
|
|
106
|
+
/** URL of a media attachment, or null when it no longer exists. */
|
|
107
|
+
attachmentUrl: (id: number) => string | null;
|
|
108
|
+
/** Path of a page (e.g. "/kontakt"), or null when it no longer exists. */
|
|
109
|
+
pagePath: (id: number) => string | null;
|
|
110
|
+
}
|
|
111
|
+
interface LegacySkipped {
|
|
112
|
+
/** Option key, e.g. "appearance.bubble_size" or "en.texts.footer_text". */
|
|
113
|
+
field: string;
|
|
114
|
+
reason: string;
|
|
115
|
+
}
|
|
116
|
+
type LegacyImportResult = {
|
|
117
|
+
ok: true;
|
|
118
|
+
document: WidgetConfigDocument;
|
|
119
|
+
/** From general.api_url: where the platform runs and which chat client this site uses. */
|
|
120
|
+
connector: string | null;
|
|
121
|
+
clientId: string | null;
|
|
122
|
+
/** general.allowed_domains, for the platform's origin rules (not part of the widget config). */
|
|
123
|
+
allowedOrigins: string[];
|
|
124
|
+
skipped: LegacySkipped[];
|
|
125
|
+
} | {
|
|
126
|
+
ok: false;
|
|
127
|
+
issues: ValidationIssue[];
|
|
128
|
+
skipped: LegacySkipped[];
|
|
129
|
+
};
|
|
130
|
+
declare function importLegacyWordPress(option: unknown, context: LegacyImportContext): LegacyImportResult;
|
|
131
|
+
|
|
132
|
+
export { buildPublicSnapshot, importLegacyWordPress, isAllowedToken, validateWidgetConfig };
|
|
133
|
+
export type { LegacyImportContext, LegacyImportResult, LegacySkipped, PublicRule, PublicSnapshot, ValidationIssue, ValidationResult, WidgetConfigDocument, WidgetLocaleTexts, WidgetRule };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as z,b as M,c as J,d as F,e as K,f as Q}from"./chunk-45NFWKPO.js";import{z as n}from"zod";var S=/^--[A-Za-z0-9_-]{1,64}$/,R=/[;{}<>\\]|@import|(?:url|image-set|-webkit-image-set|image|cross-fade|element|src|expression)\s*\(/i;function v(o,t){return S.test(o)&&!R.test(t)}var I=n.record(n.string(),n.string()).superRefine((o,t)=>{for(let[e,r]of Object.entries(o))S.test(e)||t.addIssue({code:"custom",path:[e],message:"Token name must be -- plus 1 to 64 letters, digits, - or _"}),R.test(r)&&t.addIssue({code:"custom",path:[e],message:"Token value contains a forbidden character or function"})}),A=n.record(n.string(),n.array(n.string().max(120)).max(6)),W=n.record(n.string(),n.string().max(200)),j=n.enum(["inherit","shown","hidden"]),P=n.object({id:n.string().min(1),match:n.string().min(1).startsWith("/"),display:j.default("inherit"),questions:A.optional(),greeting:W.optional(),promptAddition:n.string().max(4e3).optional()}),N=n.object({greeting:n.string().max(200).optional(),placeholder:n.string().max(2e3).optional(),messagePlaceholder:n.string().max(2e3).optional(),footer:n.string().max(2e3).optional(),headerTitle:n.string().max(2e3).optional(),emptyStateTitle:n.string().max(2e3).optional(),emptyStateSubtitle:n.string().max(2e3).optional(),teaser:n.string().max(120).optional()}),D=n.string().regex(/^#([0-9a-f]{3}|[0-9a-f]{6})$/i),p=n.url({protocol:/^https?$/}),E=n.object({locales:n.array(n.string().min(2)).min(1),display:n.enum(["shown","hidden"]).default("shown"),theme:n.object({tokens:I.default({}),backdrop:n.object({color:D.default("#000000"),opacity:n.number().int().min(0).max(100).default(15)}).default({color:"#000000",opacity:15}),autoContrast:n.boolean().default(!0),fonts:n.object({heading:p.optional(),body:p.optional()}).default({}),avatar:p.optional()}).default({tokens:{},backdrop:{color:"#000000",opacity:15},autoContrast:!0,fonts:{}}),launcher:n.object({mode:n.enum(["bubble","sticky_bar"]).default("bubble"),position:n.enum(["left","right"]).default("right"),size:n.enum(["xs","sm","md","lg","xl","2xl"]).default("lg"),showBubble:n.boolean().default(!0),icon:p.optional(),collapseAfterPx:n.number().int().min(0).max(1e5).default(400),restoreNearBottomPx:n.number().int().min(0).max(1e5).default(240)}).default({mode:"bubble",position:"right",size:"lg",showBubble:!0,collapseAfterPx:400,restoreNearBottomPx:240}),teaser:n.object({enabled:n.boolean().default(!1),delayS:n.number().int().min(0).max(120).default(5),frequencyDays:n.number().int().min(0).max(365).default(7),scrollScreens:n.number().min(0).max(20).default(0)}).default({enabled:!1,delayS:5,frequencyDays:7,scrollScreens:0}),tracking:n.object({enabled:n.boolean().default(!0)}).default({enabled:!0}),texts:n.record(n.string(),N),questions:A.default({}),messageRatingEnabled:n.boolean().default(!1),rules:n.array(P).default([]),server:n.object({useChainOfThought:n.boolean().default(!1),sourcesSimilarityThreshold:n.number().min(0).max(1).default(.7)}).default({useChainOfThought:!1,sourcesSimilarityThreshold:.7})});function L(o){let t=E.safeParse(o);return t.success?{ok:!0,value:t.data}:{ok:!1,issues:t.error.issues.map(e=>({path:e.path.map(String).join("."),message:e.message}))}}function G(o,t){let{server:e,...r}=o;return{...r,version:t,rules:o.rules.map(({promptAddition:i,...s})=>s)}}var d=o=>typeof o=="object"&&o!==null&&!Array.isArray(o),$=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,q=[["texts.placeholder_text","placeholder"],["texts.message_placeholder","messagePlaceholder"],["texts.footer_text","footer"],["texts.header_title","headerTitle"],["texts.empty_state_title","emptyStateTitle"],["texts.empty_state_subtitle","emptyStateSubtitle"],["appearance.teaser_text","teaser",120]],g=class{constructor(t,e=""){this.data=t;this.prefix=e}data;prefix;skipped=[];raw(t){let e=this.data;for(let r of t.split("."))e=d(e)?e[r]:void 0;if(!(e===null||e===""||Array.isArray(e)&&e.length===0))return e}skip(t,e){this.skipped.push({field:this.prefix+t,reason:e})}bool(t){let e=this.raw(t);if(e===void 0)return;let r=String(e).trim().toLowerCase();return e===!0||["1","true","on","yes"].includes(r)?!0:e===!1||["0","false","off","no",""].includes(r)?!1:this.skip(t,"cannot be converted to bool")}number(t,e,r,i){let s=this.raw(t);if(s===void 0)return;let a=typeof s=="number"?s:typeof s=="string"?Number(s.trim()):NaN;if(!Number.isFinite(a))return this.skip(t,`cannot be converted to ${i?"int":"float"}`);let l=Math.min(r,Math.max(e,a));return i?Math.round(l):Math.round(l*100)/100}string(t,e){let r=this.raw(t);if(r!==void 0)return typeof r!="string"?this.skip(t,"cannot be converted to string"):e===void 0?r:[...r].slice(0,e).join("")}oneOf(t,e){let r=this.string(t);if(r!==void 0)return e.includes(r)?r:this.skip(t,`must be one of ${e.join(", ")}`)}list(t){let e=this.raw(t);if(e!==void 0)return Array.isArray(e)?e.filter(r=>typeof r=="string"):this.skip(t,"cannot be converted to list")}ids(t){let e=this.raw(t);return e===void 0?[]:Array.isArray(e)?e.map(Number).filter(r=>Number.isInteger(r)&&r>0):this.skip(t,"cannot be converted to list")??[]}};function B(o){let t=o.raw("appearance.style_config");if(t===void 0)return{};let e=t;if(typeof t=="string")try{e=JSON.parse(t)}catch{return o.skip("appearance.style_config","is not valid JSON"),{}}if(!d(e))return o.skip("appearance.style_config","is not an object"),{};let r={};for(let[i,s]of Object.entries(e)){let a=i.startsWith("--")?i:`--${i}`;if(typeof s!="string"||!v(a,s)){o.skip(`appearance.style_config.${a}`,"is not an allowed CSS custom property");continue}r[a]=s}return r}function f(o,t,e){let r=o.number(t,0,Number.MAX_SAFE_INTEGER,!0);if(r)return e.attachmentUrl(r)??o.skip(t,`attachment ${r} not found`)}function O(o){let t={};for(let[e,r,i]of q){let s=o.string(e,i);s!==void 0&&(t[r]=s)}return t}function U(o,t){let e=o.oneOf("appearance.visibility",["show","hide","show_on_selected"])??"show";if(e==="show")return{display:"shown",rules:[]};if(e==="hide")return{display:"hidden",rules:[]};let r=[];for(let i of o.ids("appearance.selected_pages")){let s=t.pagePath(i);if(!s){o.skip("appearance.selected_pages",`page ${i} not found`);continue}r.push({id:`wp-page-${i}`,match:s,display:"shown"})}return{display:"hidden",rules:r}}function V(o){let t=o.string("general.api_url");if(t===void 0)return{connector:null,clientId:null};try{let e=new URL(t),r=e.searchParams.get("clientId");return{connector:e.origin,clientId:r&&$.test(r)?r:null}}catch{return o.skip("general.api_url","is not a URL"),{connector:null,clientId:null}}}function Y(o,t){let e=new g(d(o)?o:{});d(o)||e.skip("","the option is not an object");let{display:r,rules:i}=U(e,t),{connector:s,clientId:a}=V(e),l=t.locale,x={[l]:O(e)},m={},k=e.list("prompts.prompt_templates");k&&(m[l]=k);let _=[l];for(let[u,w]of Object.entries(t.languageOverrides??{})){if(u===l)continue;if(!d(w)){e.skip(u,"the language override is not an object");continue}let h=new g(w,`${u}.`);x[u]=O(h);let T=h.list("prompts.prompt_templates");T&&(m[u]=T),e.skipped.push(...h.skipped),_.push(u)}let c={locales:_,display:r,theme:{tokens:B(e),backdrop:{color:e.string("appearance.backdrop_color")?.toLowerCase(),opacity:e.number("appearance.backdrop_opacity",0,100,!0)},autoContrast:e.bool("appearance.auto_contrast"),fonts:{heading:f(e,"appearance.custom_font",t),body:f(e,"appearance.custom_body_font",t)},avatar:f(e,"appearance.placeholder_image",t)},launcher:{mode:e.oneOf("appearance.launcher_mode",["bubble","sticky_bar"])??"bubble",size:e.oneOf("appearance.bubble_size",["xs","sm","md","lg","xl","2xl"]),showBubble:e.bool("appearance.show_bubble"),icon:f(e,"appearance.toggle_icon",t),collapseAfterPx:e.number("appearance.launcher_collapse_after_px",0,1e5,!0),restoreNearBottomPx:e.number("appearance.launcher_restore_near_bottom_px",0,1e5,!0)},teaser:{enabled:e.bool("appearance.teaser_enabled"),delayS:e.number("appearance.teaser_delay_s",0,120,!0),frequencyDays:e.number("appearance.teaser_frequency_days",0,365,!0),scrollScreens:e.number("appearance.teaser_scroll_screens",0,20,!1)},tracking:{enabled:e.bool("general.tracking_enabled")},texts:x,questions:m,rules:i,server:{useChainOfThought:e.bool("general.use_chain_of_thought"),sourcesSimilarityThreshold:e.number("general.sources_similarity_threshold",0,1,!1)}};c.theme.backdrop.color!==void 0&&!/^#([0-9a-f]{3}|[0-9a-f]{6})$/.test(c.theme.backdrop.color)&&(e.skip("appearance.backdrop_color","must be a hex colour like #112233"),c.theme.backdrop.color=void 0);let C=[...new Set(e.list("general.allowed_domains")??[])],b=L(y(c));return b.ok?{ok:!0,document:b.value,connector:s,clientId:a,allowedOrigins:C,skipped:e.skipped}:{ok:!1,issues:b.issues,skipped:e.skipped}}function y(o){return Array.isArray(o)?o.map(y):d(o)?Object.fromEntries(Object.entries(o).filter(([,t])=>t!==void 0).map(([t,e])=>[t,y(e)])):o}export{G as buildPublicSnapshot,J as compilePattern,Y as importLegacyWordPress,v as isAllowedToken,K as matchPageRules,F as matchesPattern,z as normalizePath,Q as resolvePage,M as stripLocalePrefix,L as validateWidgetConfig};
|
package/dist/rules.d.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Page rules: which rule applies to which page path.
|
|
3
|
+
*
|
|
4
|
+
* This entry point has no dependencies (no zod), so the browser loader can import it and stay
|
|
5
|
+
* small. The platform uses the same functions in the chat function, so a pattern such as
|
|
6
|
+
* `/leistungen/*` means the same thing on both sides.
|
|
7
|
+
*
|
|
8
|
+
* Pattern syntax:
|
|
9
|
+
* - `/kontakt` matches only `/kontakt`.
|
|
10
|
+
* - `/leistungen/*` matches `/leistungen` itself and every path below it, at any depth.
|
|
11
|
+
* - `*` inside a pattern (`/blog/*\/kommentare`) matches exactly one path segment.
|
|
12
|
+
* - `/*` matches every path.
|
|
13
|
+
* Query, hash and a trailing slash are ignored.
|
|
14
|
+
*/
|
|
15
|
+
/** What a rule does with the launcher. `inherit` keeps the base setting. */
|
|
16
|
+
type RuleDisplay = "inherit" | "hidden" | (string & {});
|
|
17
|
+
interface PageRule {
|
|
18
|
+
id: string;
|
|
19
|
+
match: string;
|
|
20
|
+
display?: RuleDisplay;
|
|
21
|
+
/** Questions at the launcher per locale. A non-empty list replaces the base questions. */
|
|
22
|
+
questions?: Record<string, string[]>;
|
|
23
|
+
/** Greeting per locale. A non-empty value replaces the base greeting. */
|
|
24
|
+
greeting?: Record<string, string>;
|
|
25
|
+
}
|
|
26
|
+
interface CompiledPattern {
|
|
27
|
+
pattern: string;
|
|
28
|
+
regex: RegExp;
|
|
29
|
+
/** Higher is more specific: 10 per fixed segment, plus 5 for an exact (non-branch) pattern. */
|
|
30
|
+
specificity: number;
|
|
31
|
+
}
|
|
32
|
+
/** Turns a path or a full URL into a normalised path: leading slash, no query, hash or trailing slash. */
|
|
33
|
+
declare function normalizePath(pathOrUrl: string): string;
|
|
34
|
+
/**
|
|
35
|
+
* Removes a leading locale segment (`/en/leistungen` → `/leistungen`) when that segment is one of
|
|
36
|
+
* the given locales. Rules are written without the locale prefix.
|
|
37
|
+
*/
|
|
38
|
+
declare function stripLocalePrefix(path: string, locales: readonly string[]): string;
|
|
39
|
+
declare function compilePattern(pattern: string): CompiledPattern;
|
|
40
|
+
declare function matchesPattern(pattern: string, path: string): boolean;
|
|
41
|
+
interface MatchOptions {
|
|
42
|
+
/** Locales whose prefix is stripped from the path before matching. */
|
|
43
|
+
locales?: readonly string[];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Returns the rules that apply to a path, from least to most specific. Rules with the same
|
|
47
|
+
* specificity keep their configured order.
|
|
48
|
+
*/
|
|
49
|
+
declare function matchPageRules<R extends Pick<PageRule, "match">>(rules: readonly R[], pathOrUrl: string, options?: MatchOptions): R[];
|
|
50
|
+
interface PageBase {
|
|
51
|
+
display: string;
|
|
52
|
+
questions: string[];
|
|
53
|
+
greeting: string;
|
|
54
|
+
}
|
|
55
|
+
interface ResolvedPage {
|
|
56
|
+
display: string;
|
|
57
|
+
hidden: boolean;
|
|
58
|
+
questions: string[];
|
|
59
|
+
greeting: string;
|
|
60
|
+
/** Ids of all matching rules, least specific first. */
|
|
61
|
+
ruleIds: string[];
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Resolves what the launcher shows on a page: per field the most specific rule that sets it wins.
|
|
65
|
+
*/
|
|
66
|
+
declare function resolvePage(base: PageBase, rules: readonly PageRule[], pathOrUrl: string, locale: string, options?: MatchOptions): ResolvedPage;
|
|
67
|
+
|
|
68
|
+
export { compilePattern, matchPageRules, matchesPattern, normalizePath, resolvePage, stripLocalePrefix };
|
|
69
|
+
export type { CompiledPattern, MatchOptions, PageBase, PageRule, ResolvedPage, RuleDisplay };
|
package/dist/rules.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a,b,c,d,e,f}from"./chunk-45NFWKPO.js";export{c as compilePattern,e as matchPageRules,d as matchesPattern,a as normalizePath,f as resolvePage,b as stripLocalePrefix};
|
package/package.json
CHANGED
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@360vier/ai-chat-core",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Config schema, page-rule matcher and snapshot projection for the 360VIER AI-Chat widget.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/360vier/ai-chat-widget.git",
|
|
11
|
+
"directory": "packages/core"
|
|
12
|
+
},
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./rules": {
|
|
19
|
+
"types": "./dist/rules.d.ts",
|
|
20
|
+
"default": "./dist/rules.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsup",
|
|
28
|
+
"typecheck": "tsc -p tsconfig.json"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"zod": "4.6.7"
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public",
|
|
35
|
+
"provenance": false
|
|
36
|
+
}
|
|
37
|
+
}
|