luzia-widget 0.0.0-stage → 0.1.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sergio Deri
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,21 @@
1
- # Temporary Holding Version
1
+ # luzia-widget
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The luzIA chat widget: a framework-free `<luzia-widget>` Web Component that Visitors use to chat with the Agent about the Owner. A floating bubble by default, or an inline chat with `mode="inline"`.
4
+
5
+ On any site, load the self-registering script bundle (a single file, no dependencies):
6
+
7
+ ```html
8
+ <script type="module" src="https://cdn.jsdelivr.net/npm/luzia-widget/dist/luzia-widget.js"></script>
9
+ <luzia-widget endpoint="https://your-luzia-server.vercel.app/api/luzia" contact="you@example.com"></luzia-widget>
10
+ ```
11
+
12
+ With a bundler:
13
+
14
+ ```ts
15
+ import { defineLuziaWidget } from 'luzia-widget';
16
+ defineLuziaWidget();
17
+ ```
18
+
19
+ Attributes: `endpoint`, `contact`, `greeting`, `suggested-questions` (JSON array), `mode` (`bubble` | `inline`), `theme` (`light` | `dark` | `auto`), `avatar` (image URL shown large at the top of the chat, like a video call; luzIA's icon when unset). Theme colours are `--luzia-*` CSS custom properties. See the [root README](../../README.md#widget) for details. For React, use [`luzia-react`](../react).
20
+
21
+ `pnpm build` emits the module build and `dist/luzia-widget.js` (the script bundle, built with esbuild from `src/register.ts`).
@@ -0,0 +1,14 @@
1
+ import type { LuziaRequestError } from './chat-client.ts';
2
+ /** Server error codes meaning the conversation itself hit a limit (see `luzia-core` limits). */
3
+ export declare const CONVERSATION_LIMIT_CODE = "conversation_limit_reached";
4
+ export declare const MESSAGE_TOO_LONG_CODE = "message_too_long";
5
+ /**
6
+ * What the Visitor is told after a failed request:
7
+ * - `limit`: the conversation is over; offers the Owner's contact.
8
+ * - `too-long`: the last message was rejected; the Visitor can shorten it.
9
+ * - `unavailable`: anything else (network, provider, server); offers the Owner's contact.
10
+ */
11
+ export type FailureKind = 'limit' | 'too-long' | 'unavailable';
12
+ export declare function failureKind(error: LuziaRequestError): FailureKind;
13
+ /** Renders the alert for `kind` into `alert`, with the Owner's `contact` when it helps the Visitor. */
14
+ export declare function renderAlert(alert: HTMLElement, kind: FailureKind | null, contact: string): void;
package/dist/alert.js ADDED
@@ -0,0 +1,46 @@
1
+ /** Server error codes meaning the conversation itself hit a limit (see `luzia-core` limits). */
2
+ export const CONVERSATION_LIMIT_CODE = 'conversation_limit_reached';
3
+ export const MESSAGE_TOO_LONG_CODE = 'message_too_long';
4
+ export function failureKind(error) {
5
+ if (error.code === CONVERSATION_LIMIT_CODE)
6
+ return 'limit';
7
+ if (error.code === MESSAGE_TOO_LONG_CODE)
8
+ return 'too-long';
9
+ return 'unavailable';
10
+ }
11
+ const MESSAGES = {
12
+ limit: "You've reached the message limit for this conversation.",
13
+ 'too-long': 'That message is too long. Please shorten it and try again.',
14
+ unavailable: 'luzIA is unavailable right now. Please try again later.',
15
+ };
16
+ /** Renders the alert for `kind` into `alert`, with the Owner's `contact` when it helps the Visitor. */
17
+ export function renderAlert(alert, kind, contact) {
18
+ alert.hidden = kind === null;
19
+ alert.replaceChildren();
20
+ if (kind === null)
21
+ return;
22
+ alert.append(MESSAGES[kind]);
23
+ const value = contact.trim();
24
+ if (kind === 'too-long' || !value)
25
+ return;
26
+ alert.append(' You can get in touch directly: ', contactNode(value), '.');
27
+ }
28
+ /** An email address becomes a `mailto:` link, an http(s) URL a link, anything else plain text. */
29
+ function contactNode(contact) {
30
+ const href = /^[^\s@/]+@[^\s@/]+\.[^\s@/]+$/.test(contact)
31
+ ? `mailto:${contact}`
32
+ : /^https?:\/\/\S+$/i.test(contact)
33
+ ? contact
34
+ : null;
35
+ if (!href)
36
+ return document.createTextNode(contact);
37
+ const link = document.createElement('a');
38
+ link.href = href;
39
+ link.textContent = contact;
40
+ if (!href.startsWith('mailto:')) {
41
+ link.target = '_blank';
42
+ link.rel = 'noopener noreferrer';
43
+ }
44
+ return link;
45
+ }
46
+ //# sourceMappingURL=alert.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"alert.js","sourceRoot":"","sources":["../src/alert.ts"],"names":[],"mappings":"AAEA,gGAAgG;AAChG,MAAM,CAAC,MAAM,uBAAuB,GAAG,4BAA4B,CAAC;AACpE,MAAM,CAAC,MAAM,qBAAqB,GAAG,kBAAkB,CAAC;AAUxD,MAAM,UAAU,WAAW,CAAC,KAAwB;IAClD,IAAI,KAAK,CAAC,IAAI,KAAK,uBAAuB;QAAE,OAAO,OAAO,CAAC;IAC3D,IAAI,KAAK,CAAC,IAAI,KAAK,qBAAqB;QAAE,OAAO,UAAU,CAAC;IAC5D,OAAO,aAAa,CAAC;AACvB,CAAC;AAED,MAAM,QAAQ,GAA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AAC;IACnC,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,20 @@
1
+ /** One turn of the conversation, in the shape the luzIA server accepts. */
2
+ export interface ChatMessage {
3
+ role: 'user' | 'assistant';
4
+ content: string;
5
+ }
6
+ /**
7
+ * Why a request to the luzIA server failed: a server error code from the
8
+ * `{ error: { code, message } }` body, or `network_error` when no usable
9
+ * response arrived (offline, server down, stream cut off).
10
+ */
11
+ export declare class LuziaRequestError extends Error {
12
+ readonly code: string;
13
+ readonly status: number | undefined;
14
+ constructor(code: string, message: string, status?: number);
15
+ }
16
+ /**
17
+ * Sends the conversation to the luzIA server and yields the Agent's reply text
18
+ * piece by piece as it streams in. Throws {@link LuziaRequestError}.
19
+ */
20
+ export declare function streamReply(endpoint: string, messages: readonly ChatMessage[], signal?: AbortSignal): AsyncGenerator<string, void, undefined>;
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Why a request to the luzIA server failed: a server error code from the
3
+ * `{ error: { code, message } }` body, or `network_error` when no usable
4
+ * response arrived (offline, server down, stream cut off).
5
+ */
6
+ export class LuziaRequestError extends Error {
7
+ code;
8
+ status;
9
+ constructor(code, message, status) {
10
+ super(message);
11
+ this.name = 'LuziaRequestError';
12
+ this.code = code;
13
+ this.status = status;
14
+ }
15
+ }
16
+ /**
17
+ * Sends the conversation to the luzIA server and yields the Agent's reply text
18
+ * piece by piece as it streams in. Throws {@link LuziaRequestError}.
19
+ */
20
+ export async function* streamReply(endpoint, messages, signal) {
21
+ let response;
22
+ try {
23
+ response = await fetch(endpoint, {
24
+ method: 'POST',
25
+ headers: { 'content-type': 'application/json' },
26
+ body: JSON.stringify({ messages }),
27
+ signal,
28
+ });
29
+ }
30
+ catch (cause) {
31
+ if (signal?.aborted)
32
+ return;
33
+ throw new LuziaRequestError('network_error', describe(cause));
34
+ }
35
+ if (!response.ok)
36
+ throw await errorFrom(response);
37
+ if (!response.body)
38
+ throw new LuziaRequestError('network_error', 'The reply had no body.', response.status);
39
+ const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
40
+ try {
41
+ for (;;) {
42
+ const { done, value } = await reader.read();
43
+ if (done)
44
+ return;
45
+ if (value)
46
+ yield value;
47
+ }
48
+ }
49
+ catch (cause) {
50
+ if (signal?.aborted)
51
+ return;
52
+ throw new LuziaRequestError('network_error', describe(cause), response.status);
53
+ }
54
+ finally {
55
+ reader.releaseLock();
56
+ }
57
+ }
58
+ async function errorFrom(response) {
59
+ const body = await response.json().catch(() => undefined);
60
+ const error = body?.error;
61
+ return new LuziaRequestError(typeof error?.code === 'string' ? error.code : 'http_error', typeof error?.message === 'string' ? error.message : `The server answered ${response.status}.`, response.status);
62
+ }
63
+ function describe(cause) {
64
+ return cause instanceof Error ? cause.message : String(cause);
65
+ }
66
+ //# sourceMappingURL=chat-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat-client.js","sourceRoot":"","sources":["../src/chat-client.ts"],"names":[],"mappings":"AAMA;;;;GAIG;AACH,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IACjC,IAAI,CAAS;IACb,MAAM,CAAqB;IAEpC,YAAY,IAAY,EAAE,OAAe,EAAE,MAAe;QACxD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;QAChC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,WAAW,CAChC,QAAgB,EAChB,QAAgC,EAChC,MAAoB;IAEpB,IAAI,QAAkB,CAAC;IACvB,IAAI,CAAC;QACH,QAAQ,GAAG,MAAM,KAAK,CAAC,QAAQ,EAAE;YAC/B,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;YAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,QAAQ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,IAAI,iBAAiB,CAC1B,OAAO,KAAK,EAAE,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,EAC3D,OAAO,KAAK,EAAE,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,uBAAuB,QAAQ,CAAC,MAAM,GAAG,EAC9F,QAAQ,CAAC,MAAM,CAChB,CAAC;AACJ,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAChE,CAAC"}
@@ -0,0 +1,49 @@
1
+ import { LuziaRequestError, type ChatMessage } from './chat-client.ts';
2
+ /** `streaming` while a reply is arriving; `error` after the last request failed. */
3
+ export type ConversationStatus = 'idle' | 'streaming' | 'error';
4
+ /** An immutable snapshot; every change produces a new one. */
5
+ export interface ConversationState {
6
+ /** The conversation so far. While streaming, the last message is the partial reply. */
7
+ readonly messages: readonly ChatMessage[];
8
+ readonly status: ConversationStatus;
9
+ /** Why the last request failed, when `status` is `error`. */
10
+ readonly error: LuziaRequestError | null;
11
+ /**
12
+ * The Visitor message the last failed request took back out of `messages`
13
+ * because no reply to it arrived, so the view can give it back for editing.
14
+ * Keeping it would make the next send carry two Visitor turns in a row.
15
+ */
16
+ readonly unsent: string | null;
17
+ }
18
+ export interface ConversationOptions {
19
+ /** Where to send the conversation; read at send time so it can change. */
20
+ endpoint: () => string;
21
+ /** Messages to start from (e.g. a restored conversation). */
22
+ messages?: readonly ChatMessage[];
23
+ }
24
+ type Listener = (state: ConversationState) => void;
25
+ /**
26
+ * The Visitor's conversation with the Agent, independent of any DOM. Sending
27
+ * a message posts the whole conversation and grows the Agent's reply as it
28
+ * streams. The view subscribes and renders each snapshot.
29
+ */
30
+ export declare class Conversation {
31
+ #private;
32
+ constructor(options: ConversationOptions);
33
+ get state(): ConversationState;
34
+ /** Calls `listener` on every change. Returns an unsubscribe function. */
35
+ subscribe(listener: Listener): () => void;
36
+ /**
37
+ * Sends a Visitor message and streams the reply. Returns `false` (and does
38
+ * nothing) when the text is blank or a reply is still streaming.
39
+ */
40
+ send(text: string): boolean;
41
+ /** Stops a streaming reply, keeping what has arrived so far. */
42
+ abort(): void;
43
+ /**
44
+ * Starts over from `messages` (by default, an empty conversation). Any
45
+ * streaming reply is cancelled and discarded.
46
+ */
47
+ reset(messages?: readonly ChatMessage[]): void;
48
+ }
49
+ export {};
@@ -0,0 +1,93 @@
1
+ import { LuziaRequestError, streamReply } from './chat-client.js';
2
+ /**
3
+ * The Visitor's conversation with the Agent, independent of any DOM. Sending
4
+ * a message posts the whole conversation and grows the Agent's reply as it
5
+ * streams. The view subscribes and renders each snapshot.
6
+ */
7
+ export class Conversation {
8
+ #state;
9
+ #listeners = new Set();
10
+ #options;
11
+ #abort = null;
12
+ constructor(options) {
13
+ this.#options = options;
14
+ this.#state = { messages: options.messages ?? [], status: 'idle', error: null, unsent: null };
15
+ }
16
+ get state() {
17
+ return this.#state;
18
+ }
19
+ /** Calls `listener` on every change. Returns an unsubscribe function. */
20
+ subscribe(listener) {
21
+ this.#listeners.add(listener);
22
+ return () => this.#listeners.delete(listener);
23
+ }
24
+ /**
25
+ * Sends a Visitor message and streams the reply. Returns `false` (and does
26
+ * nothing) when the text is blank or a reply is still streaming.
27
+ */
28
+ send(text) {
29
+ const content = text.trim();
30
+ if (!content || this.#state.status === 'streaming')
31
+ return false;
32
+ void this.#stream([...this.#state.messages, { role: 'user', content }]);
33
+ return true;
34
+ }
35
+ /** Stops a streaming reply, keeping what has arrived so far. */
36
+ abort() {
37
+ this.#abort?.abort();
38
+ }
39
+ /**
40
+ * Starts over from `messages` (by default, an empty conversation). Any
41
+ * streaming reply is cancelled and discarded.
42
+ */
43
+ reset(messages = []) {
44
+ const streaming = this.#abort;
45
+ this.#abort = null;
46
+ streaming?.abort();
47
+ this.#set({ messages, status: 'idle', error: null, unsent: null });
48
+ }
49
+ async #stream(history) {
50
+ const abort = new AbortController();
51
+ this.#abort = abort;
52
+ let reply = '';
53
+ this.#set({ messages: [...history, { role: 'assistant', content: reply }], status: 'streaming', error: null, unsent: null });
54
+ try {
55
+ for await (const piece of streamReply(this.#options.endpoint(), history, abort.signal)) {
56
+ if (this.#abort !== abort)
57
+ return;
58
+ reply += piece;
59
+ this.#set({ ...this.#state, messages: [...history, { role: 'assistant', content: reply }] });
60
+ }
61
+ if (this.#abort !== abort)
62
+ return; // reset while streaming
63
+ this.#set({ messages: withReply(history, reply), status: 'idle', error: null, unsent: null });
64
+ }
65
+ catch (cause) {
66
+ if (this.#abort !== abort)
67
+ return;
68
+ const error = cause instanceof LuziaRequestError ? cause : new LuziaRequestError('network_error', String(cause));
69
+ // A reply that broke off mid-stream is kept, so the conversation still alternates.
70
+ // A message nothing arrived for is taken back out (see `unsent`).
71
+ if (reply) {
72
+ this.#set({ messages: withReply(history, reply), status: 'error', error, unsent: null });
73
+ }
74
+ else {
75
+ this.#set({ messages: history.slice(0, -1), status: 'error', error, unsent: history.at(-1)?.content ?? null });
76
+ }
77
+ }
78
+ finally {
79
+ if (this.#abort === abort)
80
+ this.#abort = null;
81
+ }
82
+ }
83
+ #set(state) {
84
+ this.#state = state;
85
+ for (const listener of this.#listeners)
86
+ listener(state);
87
+ }
88
+ }
89
+ /** Drops the reply placeholder when nothing arrived. */
90
+ function withReply(history, reply) {
91
+ return reply ? [...history, { role: 'assistant', content: reply }] : history;
92
+ }
93
+ //# sourceMappingURL=conversation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conversation.js","sourceRoot":"","sources":["../src/conversation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAoB,MAAM,kBAAkB,CAAC;AA6BpF;;;;GAIG;AACH,MAAM,OAAO,YAAY;IACvB,MAAM,CAAoB;IAC1B,UAAU,G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CAAC;AAC/E,CAAC"}
@@ -0,0 +1,76 @@
1
+ import { Conversation } from './conversation.ts';
2
+ /** Tag name the widget is registered under. */
3
+ export declare const LUZIA_WIDGET_TAG = "luzia-widget";
4
+ /**
5
+ * How an Owner configures the widget. Each option is an attribute on
6
+ * `<luzia-widget>` (kebab-case) and a prop on the React wrapper.
7
+ */
8
+ export interface LuziaWidgetConfig {
9
+ /** URL of the luzIA server handler, e.g. `/api/luzia`. */
10
+ endpoint: string;
11
+ /**
12
+ * How Visitors can reach the Owner (an email address, a URL or any short
13
+ * text), shown when luzIA is unavailable or the conversation limit is hit.
14
+ */
15
+ contact?: string;
16
+ /** First thing the Visitor sees in the chat. Display only: never sent to the server. */
17
+ greeting?: string;
18
+ /**
19
+ * Questions the Visitor can click to send, shown until the conversation
20
+ * starts. As an attribute: a JSON array of strings, e.g.
21
+ * `suggested-questions='["What role is she looking for?", "Is she open to remote work?"]'`.
22
+ */
23
+ suggestedQuestions?: readonly string[];
24
+ /**
25
+ * `bubble` (default): a floating button in the corner that opens the chat.
26
+ * `inline`: the chat is rendered inside the element itself, always open,
27
+ * so it can live in a page section.
28
+ */
29
+ mode?: LuziaWidgetMode;
30
+ /**
31
+ * `light` (default), `dark`, or `auto` to follow the Visitor's
32
+ * `prefers-color-scheme`. Colours are CSS custom properties (see styles.ts).
33
+ */
34
+ theme?: LuziaWidgetTheme;
35
+ /**
36
+ * URL of an image shown large and centred at the top of the chat, like a video call (the
37
+ * Owner's photo, a logo…). Without one, luzIA's own icon is shown.
38
+ */
39
+ avatar?: string;
40
+ }
41
+ export type LuziaWidgetMode = 'bubble' | 'inline';
42
+ export type LuziaWidgetTheme = 'light' | 'dark' | 'auto';
43
+ declare const BaseElement: typeof HTMLElement;
44
+ /**
45
+ * `<luzia-widget endpoint="/api/luzia">`: a floating bubble that opens a chat
46
+ * panel where the Visitor talks to the Agent, or with `mode="inline"` the chat
47
+ * itself, embedded where the element sits. Attributes (see
48
+ * {@link LuziaWidgetConfig}): `endpoint`, `contact`, `greeting`,
49
+ * `suggested-questions` (JSON array of strings), `mode`, `theme` and `avatar`. Each is
50
+ * also a property (`suggestedQuestions` takes an array).
51
+ *
52
+ * State lives in a {@link Conversation}; this element only renders its
53
+ * snapshots and forwards Visitor input to it.
54
+ */
55
+ export declare class LuziaWidgetElement extends BaseElement implements LuziaWidgetConfig {
56
+ #private;
57
+ readonly conversation: Conversation;
58
+ get endpoint(): string;
59
+ set endpoint(value: string);
60
+ get contact(): string;
61
+ set contact(value: string);
62
+ get greeting(): string;
63
+ set greeting(value: string);
64
+ get suggestedQuestions(): string[];
65
+ set suggestedQuestions(value: readonly string[]);
66
+ get mode(): LuziaWidgetMode;
67
+ set mode(value: LuziaWidgetMode);
68
+ get theme(): LuziaWidgetTheme;
69
+ set theme(value: LuziaWidgetTheme);
70
+ get avatar(): string;
71
+ set avatar(value: string);
72
+ static get observedAttributes(): string[];
73
+ connectedCallback(): void;
74
+ attributeChangedCallback(): void;
75
+ }
76
+ export {};