@ahoy-ai/web 0.0.0-stage → 0.1.1

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"launcher.d.ts","sourceRoot":"","sources":["../../../src/loader/launcher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAQvD,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,kDAAkD;IAClD,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,2CAA2C;IAC3C,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED;;;GAGG;AACH,qBAAa,QAAQ;IAQjB,OAAO,CAAC,QAAQ,CAAC,GAAG;IAPtB,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,iBAAiB,CAAC;IACnC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAkB;IACxC,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,MAAM,CAAK;gBAGA,GAAG,EAAE,QAAQ,EAC9B,OAAO,EAAE,eAAe;IAiF1B,WAAW,CAAC,QAAQ,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI;IAOnE,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAI/B,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAK7B,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAK9B,WAAW,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI;IAIpC,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAIlC,KAAK,IAAI,IAAI;IAIb,MAAM,IAAI,IAAI;IAId,OAAO,CAAC,MAAM;CAOf"}
@@ -0,0 +1,135 @@
1
+ import { Z_INDEX, css } from './style.js';
2
+ const SVG = 'http://www.w3.org/2000/svg';
3
+ /** A speech bubble (24 px grid). */
4
+ const CHAT_ICON = 'M4 5.5A2.5 2.5 0 0 1 6.5 3h11A2.5 2.5 0 0 1 20 5.5v9a2.5 2.5 0 0 1-2.5 2.5H10l-4.2 3.6A.5.5 0 0 1 5 20.2V17h0a2.5 2.5 0 0 1-1-2Z';
5
+ /**
6
+ * The round accent button with a chat icon and an unread badge (ADR 0017 D4), in a shadow
7
+ * root so the site's CSS can't reach it.
8
+ */
9
+ export class Launcher {
10
+ doc;
11
+ host;
12
+ button;
13
+ badge;
14
+ label;
15
+ unread = 0;
16
+ constructor(doc, options) {
17
+ this.doc = doc;
18
+ this.label = options.label;
19
+ this.host = doc.createElement('div');
20
+ this.host.setAttribute('data-ahoy', 'launcher');
21
+ css(this.host, { position: 'fixed', 'z-index': String(Z_INDEX), margin: '0' });
22
+ const root = this.host.attachShadow ? this.host.attachShadow({ mode: 'open' }) : this.host;
23
+ const button = doc.createElement('button');
24
+ button.type = 'button';
25
+ button.setAttribute('aria-haspopup', 'dialog');
26
+ button.setAttribute('aria-expanded', 'false');
27
+ button.setAttribute('aria-controls', options.controls);
28
+ css(button, {
29
+ all: 'initial',
30
+ display: 'flex',
31
+ 'align-items': 'center',
32
+ 'justify-content': 'center',
33
+ width: '56px',
34
+ height: '56px',
35
+ 'border-radius': '50%',
36
+ cursor: 'pointer',
37
+ 'box-shadow': '0 6px 20px rgba(15, 23, 42, 0.24)',
38
+ transition: 'transform .15s ease',
39
+ position: 'relative',
40
+ outline: 'none',
41
+ });
42
+ button.addEventListener('click', options.onClick);
43
+ button.addEventListener('pointerenter', () => css(button, { transform: 'scale(1.06)' }));
44
+ button.addEventListener('pointerleave', () => css(button, { transform: 'none' }));
45
+ // A visible focus ring for keyboard users (no stylesheet: see style.ts).
46
+ button.addEventListener('focus', () => {
47
+ if (safeMatches(button, ':focus-visible')) {
48
+ css(button, { 'box-shadow': '0 0 0 3px #ffffff, 0 0 0 6px #111827' });
49
+ }
50
+ });
51
+ button.addEventListener('blur', () => css(button, { 'box-shadow': '0 6px 20px rgba(15, 23, 42, 0.24)' }));
52
+ const svg = doc.createElementNS(SVG, 'svg');
53
+ svg.setAttribute('viewBox', '0 0 24 24');
54
+ svg.setAttribute('width', '28');
55
+ svg.setAttribute('height', '28');
56
+ svg.setAttribute('aria-hidden', 'true');
57
+ svg.setAttribute('focusable', 'false');
58
+ const path = doc.createElementNS(SVG, 'path');
59
+ path.setAttribute('d', CHAT_ICON);
60
+ path.setAttribute('fill', '#ffffff');
61
+ svg.appendChild(path);
62
+ button.appendChild(svg);
63
+ const badge = doc.createElement('span');
64
+ badge.setAttribute('aria-hidden', 'true');
65
+ css(badge, {
66
+ all: 'initial',
67
+ position: 'absolute',
68
+ top: '-4px',
69
+ right: '-4px',
70
+ 'min-width': '20px',
71
+ height: '20px',
72
+ padding: '0 6px',
73
+ 'box-sizing': 'border-box',
74
+ 'border-radius': '10px',
75
+ background: '#d92d20',
76
+ color: '#ffffff',
77
+ font: '600 12px/20px system-ui, -apple-system, "Segoe UI", Roboto, sans-serif',
78
+ 'text-align': 'center',
79
+ border: '2px solid #ffffff',
80
+ display: 'none',
81
+ });
82
+ button.appendChild(badge);
83
+ root.appendChild(button);
84
+ this.button = button;
85
+ this.badge = badge;
86
+ this.setPosition(options.position, options.bottomOffset);
87
+ this.setAccent(options.accent);
88
+ this.render();
89
+ }
90
+ setPosition(position, bottomOffset) {
91
+ css(this.host, {
92
+ bottom: `${bottomOffset}px`,
93
+ ...(position === 'left' ? { left: '20px', right: 'auto' } : { right: '20px', left: 'auto' }),
94
+ });
95
+ }
96
+ setAccent(accent) {
97
+ css(this.button, { background: accent });
98
+ }
99
+ setLabel(label) {
100
+ this.label = label;
101
+ this.render();
102
+ }
103
+ setUnread(count) {
104
+ this.unread = Math.max(0, Math.floor(count));
105
+ this.render();
106
+ }
107
+ setExpanded(expanded) {
108
+ this.button.setAttribute('aria-expanded', String(expanded));
109
+ }
110
+ setVisible(visible) {
111
+ css(this.host, { display: visible ? 'block' : 'none' });
112
+ }
113
+ focus() {
114
+ this.button.focus();
115
+ }
116
+ remove() {
117
+ this.host.remove();
118
+ }
119
+ render() {
120
+ const n = this.unread;
121
+ this.badge.textContent = n > 99 ? '99+' : String(n);
122
+ css(this.badge, { display: n > 0 ? 'block' : 'none' });
123
+ // The badge is aria-hidden; the count is part of the name ("Support, 2 unread").
124
+ this.button.setAttribute('aria-label', n > 0 ? `${this.label} (${n})` : this.label);
125
+ }
126
+ }
127
+ function safeMatches(el, selector) {
128
+ try {
129
+ return el.matches(selector);
130
+ }
131
+ catch {
132
+ return true;
133
+ }
134
+ }
135
+ //# sourceMappingURL=launcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"launcher.js","sourceRoot":"","sources":["../../../src/loader/launcher.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAE1C,MAAM,GAAG,GAAG,4BAA4B,CAAC;AACzC,oCAAoC;AACpC,MAAM,SAAS,GACb,kIAAkI,CAAC;AAarI;;;GAGG;AACH,MAAM,OAAO,QAAQ;IAQA;IAPV,IAAI,CAAc;IAClB,MAAM,CAAoB;IAClB,KAAK,CAAkB;IAChC,KAAK,CAAS;IACd,MAAM,GAAG,CAAC,CAAC;IAEnB,YACmB,GAAa,EAC9B,OAAwB;QADP,QAAG,GAAH,GAAG,CAAU;QAG9B,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QACrC,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;QAChD,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,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C,IAAI,CAAC,KAAK,CAAC,CAAC;IACtF,CAAC;CACF;AAED,SAAS,WAAW,CAAC,EAAW,EAAE,QAAgB;IAChD,IAAI,CAAC;QACH,OAAO,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC9B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function watchNavigation(win: Window, listener: (path: string) => void): () => void;
2
+ //# sourceMappingURL=navigation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"navigation.d.ts","sourceRoot":"","sources":["../../../src/loader/navigation.ts"],"names":[],"mappings":"AAQA,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,GAAG,MAAM,IAAI,CA2BzF"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Calls `listener` with `location.pathname` whenever it changes: `history.pushState` and
3
+ * `replaceState` (single-page apps) and `popstate` (back and forward). The query string and hash
4
+ * are never sent (ADR 0017: the `page` message carries the path only).
5
+ */
6
+ const PATCHED = Symbol.for('ahoy.history');
7
+ const EVENT = 'ahoy:locationchange';
8
+ export function watchNavigation(win, listener) {
9
+ const history = win.history;
10
+ if (!history[PATCHED]) {
11
+ history[PATCHED] = true;
12
+ for (const method of ['pushState', 'replaceState']) {
13
+ const original = history[method];
14
+ history[method] = function (...args) {
15
+ const result = original.apply(this, args);
16
+ win.dispatchEvent(new Event(EVENT));
17
+ return result;
18
+ };
19
+ }
20
+ }
21
+ let last = null;
22
+ const check = () => {
23
+ const path = win.location.pathname || '/';
24
+ if (path === last)
25
+ return;
26
+ last = path;
27
+ listener(path);
28
+ };
29
+ win.addEventListener('popstate', check);
30
+ win.addEventListener(EVENT, check);
31
+ check();
32
+ return () => {
33
+ win.removeEventListener('popstate', check);
34
+ win.removeEventListener(EVENT, check);
35
+ };
36
+ }
37
+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CAAC,CAAC;IACnC,KAAK,EAAE,CAAC;IACR,OAAO,GAAG,EAAE;QACV,GAAG,CAAC,mBAAmB,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;QAC3C,GAAG,CAAC,mBAAmB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACxC,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Styles are set through the CSSOM (`style.setProperty`) only: a site whose Content-Security-Policy
3
+ * has no `style-src 'unsafe-inline'` still renders the launcher (ADR 0017 "Content Security
4
+ * Policy": strict sites allow only the script and the frame). `important` keeps host rules out.
5
+ */
6
+ export declare function css(el: HTMLElement | SVGElement, styles: Record<string, string>): void;
7
+ /** Highest z-index a site is likely to leave free (the panel stays above the launcher). */
8
+ export declare const Z_INDEX = 2147483000;
9
+ //# sourceMappingURL=style.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"style.d.ts","sourceRoot":"","sources":["../../../src/loader/style.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,GAAG,CAAC,EAAE,EAAE,WAAW,GAAG,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAItF;AAED,2FAA2F;AAC3F,eAAO,MAAM,OAAO,aAAa,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Styles are set through the CSSOM (`style.setProperty`) only: a site whose Content-Security-Policy
3
+ * has no `style-src 'unsafe-inline'` still renders the launcher (ADR 0017 "Content Security
4
+ * Policy": strict sites allow only the script and the frame). `important` keeps host rules out.
5
+ */
6
+ export function css(el, styles) {
7
+ for (const [name, value] of Object.entries(styles)) {
8
+ el.style.setProperty(name, value, 'important');
9
+ }
10
+ }
11
+ /** Highest z-index a site is likely to leave free (the panel stays above the launcher). */
12
+ export const Z_INDEX = 2147483000;
13
+ //# sourceMappingURL=style.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"style.js","sourceRoot":"","sources":["../../../src/loader/style.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,GAAG,CAAC,EAA4B,EAAE,MAA8B;IAC9E,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACnD,EAAE,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC;IACjD,CAAC;AACH,CAAC;AAED,2FAA2F;AAC3F,MAAM,CAAC,MAAM,OAAO,GAAG,UAAU,CAAC"}
@@ -0,0 +1,120 @@
1
+ /**
2
+ * The postMessage protocol between the loader (host page) and the panel (iframe on Ahoy's CDN),
3
+ * ADR 0017 "Embedding model". Every message is `{ channel: 'ahoy', protocol, type, payload? }`;
4
+ * both sides check `event.origin` and `event.source` before reading it.
5
+ */
6
+ import type { AhoyAppearance, AhoyEnvironment, AhoyEvent, AhoyIdentity, AhoyMetadata, AhoyVerifiedIdentity } from '@ahoy-ai/core';
7
+ /** Bumped only by a breaking change, together with the CDN path (`/web/v2/`). */
8
+ export declare const PROTOCOL = 1;
9
+ /** Protocols this build understands (a panel accepts every loader protocol of its major). */
10
+ export declare const SUPPORTED_PROTOCOLS: readonly number[];
11
+ export declare const CHANNEL = "ahoy";
12
+ export type LauncherPosition = 'right' | 'left';
13
+ export interface ConfigurePayload {
14
+ appId: string;
15
+ environment: AhoyEnvironment;
16
+ /** The host page's origin, as the loader sees it. */
17
+ hostOrigin: string;
18
+ /** The interface language the host asked for (`data-language`, `configure({ language })`). */
19
+ language?: string;
20
+ /** `document.documentElement.lang`, the fallback after `language` and before the browser's. */
21
+ pageLanguage?: string;
22
+ appearance?: AhoyAppearance;
23
+ /** A local or self-hosted API; the panel uses it only when `environment` is `development`. */
24
+ apiUrl?: string;
25
+ /**
26
+ * The launcher side the site set in code, if any. It wins over the published design's side;
27
+ * the panel answers the side in effect in `ready`.
28
+ */
29
+ position?: LauncherPosition;
30
+ protocol: number;
31
+ }
32
+ export interface ReadyPayload {
33
+ accent: string;
34
+ /** The launcher's side and its distance from the bottom (px, 0 to 200; ADR 0017 phase 4). */
35
+ position: LauncherPosition;
36
+ bottomOffset: number;
37
+ title: string;
38
+ protocol: number;
39
+ }
40
+ export type ResizeMode = 'panel' | 'full';
41
+ /** Loader → panel. */
42
+ export type HostMessage = {
43
+ type: 'configure';
44
+ payload: ConfigurePayload;
45
+ } | {
46
+ type: 'identify';
47
+ payload: [AhoyIdentity | AhoyVerifiedIdentity];
48
+ } | {
49
+ type: 'setMetadata';
50
+ payload: [AhoyMetadata, {
51
+ merge?: boolean;
52
+ }?];
53
+ } | {
54
+ type: 'track';
55
+ payload: [string, ...unknown[]];
56
+ } | {
57
+ type: 'logout';
58
+ } | {
59
+ type: 'deleteData';
60
+ } | {
61
+ type: 'runSetupCheck';
62
+ } | {
63
+ type: 'open';
64
+ } | {
65
+ type: 'close';
66
+ } | {
67
+ type: 'page';
68
+ payload: {
69
+ path: string;
70
+ };
71
+ };
72
+ /** Panel → loader. */
73
+ export type PanelMessage = {
74
+ type: 'ready';
75
+ payload: ReadyPayload;
76
+ } | {
77
+ type: 'unread';
78
+ payload: {
79
+ count: number;
80
+ };
81
+ } | {
82
+ type: 'resize';
83
+ payload: {
84
+ mode: ResizeMode;
85
+ height: number;
86
+ };
87
+ } | {
88
+ type: 'event';
89
+ payload: AhoyEvent;
90
+ } | {
91
+ type: 'opened';
92
+ } | {
93
+ type: 'closed';
94
+ }
95
+ /**
96
+ * The panel stopped for good (origin not in the app's allowed websites, invalid
97
+ * configuration): the loader removes the launcher and stops the handshake until a reload.
98
+ */
99
+ | {
100
+ type: 'stopped';
101
+ };
102
+ export type Envelope<M> = M & {
103
+ channel: typeof CHANNEL;
104
+ protocol: number;
105
+ };
106
+ export declare const HOST_TYPES: ReadonlySet<string>;
107
+ export declare const PANEL_TYPES: ReadonlySet<string>;
108
+ export declare function envelope<M extends {
109
+ type: string;
110
+ }>(message: M): Envelope<M>;
111
+ /**
112
+ * The message if `data` is an Ahoy envelope of a known type and protocol, else null. Origin and
113
+ * source are the caller's checks.
114
+ */
115
+ export declare function readMessage<M extends {
116
+ type: string;
117
+ }>(data: unknown, types: ReadonlySet<string>): Envelope<M> | null;
118
+ /** `scheme://host[:port]` of a URL, or null (CONTRACT rule 3 normalization: lowercase, no path). */
119
+ export declare function originOf(url: string | null | undefined): string | null;
120
+ //# sourceMappingURL=protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../src/protocol.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EACf,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,oBAAoB,EACrB,MAAM,eAAe,CAAC;AAEvB,iFAAiF;AACjF,eAAO,MAAM,QAAQ,IAAI,CAAC;AAC1B,6FAA6F;AAC7F,eAAO,MAAM,mBAAmB,EAAE,SAAS,MAAM,EAAQ,CAAC;AAC1D,eAAO,MAAM,OAAO,SAAS,CAAC;AAE9B,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG,MAAM,CAAC;AAEhD,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,eAAe,CAAC;IAC7B,qDAAqD;IACrD,UAAU,EAAE,MAAM,CAAC;IACnB,8FAA8F;IAC9F,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,+FAA+F;IAC/F,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,cAAc,CAAC;IAC5B,8FAA8F;IAC9F,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,QAAQ,CAAC,EAAE,gBAAgB,CAAC;IAC5B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,6FAA6F;IAC7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QAAE,IAAI,EAAE,UAAU,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,GACjE;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,SAAS,CAAA;CAAE,GACrC;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAClB;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE;AACpB;;;GAGG;GACD;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,CAAC;AAExB,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG;IAAE,OAAO,EAAE,OAAO,OAAO,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAE5E,eAAO,MAAM,UAAU,EAAE,WAAW,CAAC,MAAM,CAWzC,CAAC;AAEH,eAAO,MAAM,WAAW,EAAE,WAAW,CAAC,MAAM,CAQ1C,CAAC;AAEH,wBAAgB,QAAQ,CAAC,CAAC,SAAS;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,EAAE,OAAO,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAE5E;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,EACpD,IAAI,EAAE,OAAO,EACb,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,GACzB,QAAQ,CAAC,CAAC,CAAC,GAAG,IAAI,CAMpB;AAED,oGAAoG;AACpG,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAStE"}
@@ -0,0 +1,58 @@
1
+ /** Bumped only by a breaking change, together with the CDN path (`/web/v2/`). */
2
+ export const PROTOCOL = 1;
3
+ /** Protocols this build understands (a panel accepts every loader protocol of its major). */
4
+ export const SUPPORTED_PROTOCOLS = [1];
5
+ export const CHANNEL = 'ahoy';
6
+ export const HOST_TYPES = new Set([
7
+ 'configure',
8
+ 'identify',
9
+ 'setMetadata',
10
+ 'track',
11
+ 'logout',
12
+ 'deleteData',
13
+ 'runSetupCheck',
14
+ 'open',
15
+ 'close',
16
+ 'page',
17
+ ]);
18
+ export const PANEL_TYPES = new Set([
19
+ 'ready',
20
+ 'unread',
21
+ 'resize',
22
+ 'event',
23
+ 'opened',
24
+ 'closed',
25
+ 'stopped',
26
+ ]);
27
+ export function envelope(message) {
28
+ return { channel: CHANNEL, protocol: PROTOCOL, ...message };
29
+ }
30
+ /**
31
+ * The message if `data` is an Ahoy envelope of a known type and protocol, else null. Origin and
32
+ * source are the caller's checks.
33
+ */
34
+ export function readMessage(data, types) {
35
+ if (!data || typeof data !== 'object')
36
+ return null;
37
+ const m = data;
38
+ if (m.channel !== CHANNEL || typeof m.type !== 'string' || !types.has(m.type))
39
+ return null;
40
+ if (typeof m.protocol !== 'number' || !SUPPORTED_PROTOCOLS.includes(m.protocol))
41
+ return null;
42
+ return data;
43
+ }
44
+ /** `scheme://host[:port]` of a URL, or null (CONTRACT rule 3 normalization: lowercase, no path). */
45
+ export function originOf(url) {
46
+ if (!url)
47
+ return null;
48
+ try {
49
+ const { protocol, host } = new URL(url);
50
+ if (protocol !== 'http:' && protocol !== 'https:')
51
+ return null;
52
+ return `${protocol}//${host}`.toLowerCase();
53
+ }
54
+ catch {
55
+ return null;
56
+ }
57
+ }
58
+ //# sourceMappingURL=protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../src/protocol.ts"],"names":[],"mappings":"AAcA,iFAAiF;AACjF,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,CAAC;AAC1B,6FAA6F;AAC7F,MAAM,CAAC,MAAM,mBAAmB,GAAsB,CAAC,CAAC,CAAC,CAAC;AAC1D,MAAM,CAAC,MAAM,OAAO,GAAG,MAAM,CAAC;AAgE9B,MAAM,CAAC,MAAM,UAAU,GAAwB,IAAI,GAAG,CAAC;IACrD,WAAW;IACX,UAAU;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GAAG,QAAQ,KAAK,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAC9C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,3 @@
1
+ /** This package's version, kept in sync with package.json by a test. Sent as `X-Ahoy-Sdk: web/<version>`. */
2
+ export declare const WEB_VERSION = "0.1.1";
3
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,6GAA6G;AAC7G,eAAO,MAAM,WAAW,UAAU,CAAC"}
@@ -0,0 +1,3 @@
1
+ /** This package's version, kept in sync with package.json by a test. Sent as `X-Ahoy-Sdk: web/<version>`. */
2
+ export const WEB_VERSION = '0.1.1';
3
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,6GAA6G;AAC7G,MAAM,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,71 @@
1
1
  {
2
2
  "name": "@ahoy-ai/web",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.1",
4
+ "description": "In-app support chat for websites and web apps: an AI agent that answers from your docs and hands off to your team. The loader for bundlers; the script tag is served from Ahoy's CDN.",
5
+ "keywords": [
6
+ "support",
7
+ "chat",
8
+ "live-chat",
9
+ "customer-support",
10
+ "helpdesk",
11
+ "ai",
12
+ "ai-agent",
13
+ "web",
14
+ "widget",
15
+ "messenger"
16
+ ],
17
+ "homepage": "https://dev.ahoysupport.com/docs/",
18
+ "license": "MIT",
19
+ "author": "NOJU LLC",
20
+ "type": "module",
21
+ "sideEffects": false,
22
+ "main": "./dist/esm/index.js",
23
+ "types": "./dist/esm/index.d.ts",
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/esm/index.d.ts",
27
+ "default": "./dist/esm/index.js"
28
+ },
29
+ "./package.json": "./package.json"
30
+ },
31
+ "files": [
32
+ "dist/esm",
33
+ "dist/ahoy.js",
34
+ "!dist/**/*.tsbuildinfo",
35
+ "CHANGELOG.md"
36
+ ],
37
+ "publishConfig": {
38
+ "access": "public"
39
+ },
40
+ "dependencies": {
41
+ "@ahoy-ai/core": "0.1.1"
42
+ },
43
+ "devDependencies": {
44
+ "@axe-core/playwright": "^4.14.0",
45
+ "@babel/core": "^7.29.13",
46
+ "@babel/plugin-transform-modules-commonjs": "^7.29.7",
47
+ "@babel/plugin-transform-react-jsx": "^7.29.7",
48
+ "@babel/preset-typescript": "^7.29.7",
49
+ "@playwright/test": "^1.65.0",
50
+ "@types/jest": "^29.5.14",
51
+ "@types/node": "^22.20.5",
52
+ "@types/ws": "^8.18.2",
53
+ "babel-jest": "^29.7.0",
54
+ "esbuild": "^0.28.2",
55
+ "fake-indexeddb": "^6.2.8",
56
+ "jest": "^29.7.0",
57
+ "jest-environment-jsdom": "^29.7.0",
58
+ "preact": "^10.29.8",
59
+ "typescript": "~5.9.3",
60
+ "ws": "^8.22.2"
61
+ },
62
+ "scripts": {
63
+ "build": "rm -rf dist && tsc -p tsconfig.build.json && node scripts/build.mjs",
64
+ "typecheck": "tsc --noEmit -p tsconfig.json",
65
+ "test": "jest",
66
+ "size": "node scripts/check-size.mjs",
67
+ "dev": "node scripts/dev-server.mjs",
68
+ "e2e": "playwright test",
69
+ "mock:api": "node e2e/mock-api.mjs"
70
+ }
6
71
  }