@aparte/n8n-chat 0.1.0 → 0.3.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.
Files changed (86) hide show
  1. package/README.md +230 -16
  2. package/dist/cards.d.ts +3 -0
  3. package/dist/cdn/chunks/chunk-E55C7UF2.js +2 -0
  4. package/dist/cdn/chunks/chunk-E55C7UF2.js.map +7 -0
  5. package/dist/cdn/chunks/chunk-F2QIT4NR.js +206 -0
  6. package/dist/cdn/chunks/chunk-F2QIT4NR.js.map +7 -0
  7. package/dist/cdn/chunks/chunk-F2TNPBN3.js +2 -0
  8. package/dist/cdn/chunks/chunk-F2TNPBN3.js.map +7 -0
  9. package/dist/cdn/chunks/chunk-KY2H3HIJ.js +2 -0
  10. package/dist/cdn/chunks/chunk-KY2H3HIJ.js.map +7 -0
  11. package/dist/cdn/chunks/chunk-VLHCX6EH.js +356 -0
  12. package/dist/cdn/chunks/chunk-VLHCX6EH.js.map +7 -0
  13. package/dist/cdn/chunks/chunk-XC2SVYFR.js +2 -0
  14. package/dist/cdn/chunks/chunk-XC2SVYFR.js.map +7 -0
  15. package/dist/cdn/chunks/de-M5OVUL5F.js +2 -0
  16. package/dist/cdn/chunks/de-M5OVUL5F.js.map +7 -0
  17. package/dist/cdn/chunks/es-JUSLSPF7.js +2 -0
  18. package/dist/cdn/chunks/es-JUSLSPF7.js.map +7 -0
  19. package/dist/cdn/chunks/fr-Z2Y3375Z.js +2 -0
  20. package/dist/cdn/chunks/fr-Z2Y3375Z.js.map +7 -0
  21. package/dist/cdn/chunks/{highlight-HDJ3ROJ4.js → highlight-ADUWBKTT.js} +2 -2
  22. package/dist/cdn/chunks/{highlight-HDJ3ROJ4.js.map → highlight-ADUWBKTT.js.map} +1 -1
  23. package/dist/cdn/chunks/it-N53LIIX5.js +2 -0
  24. package/dist/cdn/chunks/it-N53LIIX5.js.map +7 -0
  25. package/dist/cdn/chunks/items-GTJKLFZT.js +467 -0
  26. package/dist/cdn/chunks/items-GTJKLFZT.js.map +7 -0
  27. package/dist/cdn/chunks/ja-LJHMBKJ4.js +2 -0
  28. package/dist/cdn/chunks/ja-LJHMBKJ4.js.map +7 -0
  29. package/dist/cdn/chunks/ko-XAQOC75B.js +2 -0
  30. package/dist/cdn/chunks/ko-XAQOC75B.js.map +7 -0
  31. package/dist/cdn/chunks/link-L4C4K5GE.js +493 -0
  32. package/dist/cdn/chunks/link-L4C4K5GE.js.map +7 -0
  33. package/dist/cdn/chunks/media-EOQEOMXK.js +797 -0
  34. package/dist/cdn/chunks/media-EOQEOMXK.js.map +7 -0
  35. package/dist/cdn/chunks/order-T5L422AO.js +839 -0
  36. package/dist/cdn/chunks/order-T5L422AO.js.map +7 -0
  37. package/dist/cdn/chunks/place-UD2C3U5F.js +689 -0
  38. package/dist/cdn/chunks/place-UD2C3U5F.js.map +7 -0
  39. package/dist/cdn/chunks/plan-JJ3Z64NU.js +542 -0
  40. package/dist/cdn/chunks/plan-JJ3Z64NU.js.map +7 -0
  41. package/dist/cdn/chunks/product-FNGKWEQP.js +676 -0
  42. package/dist/cdn/chunks/product-FNGKWEQP.js.map +7 -0
  43. package/dist/cdn/chunks/pt-BR-KMZM3WTU.js +2 -0
  44. package/dist/cdn/chunks/pt-BR-KMZM3WTU.js.map +7 -0
  45. package/dist/cdn/chunks/ru-3AG5HYY2.js +2 -0
  46. package/dist/cdn/chunks/ru-3AG5HYY2.js.map +7 -0
  47. package/dist/cdn/chunks/score-3CGZEPWP.js +882 -0
  48. package/dist/cdn/chunks/score-3CGZEPWP.js.map +7 -0
  49. package/dist/cdn/chunks/stats-FGZCRFFK.js +491 -0
  50. package/dist/cdn/chunks/stats-FGZCRFFK.js.map +7 -0
  51. package/dist/cdn/chunks/stock-E72GAUMB.js +707 -0
  52. package/dist/cdn/chunks/stock-E72GAUMB.js.map +7 -0
  53. package/dist/cdn/chunks/weather-5ZNWC2WM.js +615 -0
  54. package/dist/cdn/chunks/weather-5ZNWC2WM.js.map +7 -0
  55. package/dist/cdn/chunks/zh-CN-DL6ZWLGA.js +2 -0
  56. package/dist/cdn/chunks/zh-CN-DL6ZWLGA.js.map +7 -0
  57. package/dist/cdn/n8n-chat.js +57 -51
  58. package/dist/cdn/n8n-chat.js.map +4 -4
  59. package/dist/create-chat.d.ts +43 -8
  60. package/dist/index.d.ts +2 -0
  61. package/dist/index.js +87 -41
  62. package/dist/index.js.map +1 -1
  63. package/dist/strings.d.ts +1 -1
  64. package/dist/style.css +9 -1
  65. package/dist/theme.css +8 -0
  66. package/package.json +7 -6
  67. package/dist/cdn/chunks/chunk-MU6PIUJC.js +0 -206
  68. package/dist/cdn/chunks/chunk-MU6PIUJC.js.map +0 -7
  69. package/dist/cdn/chunks/de-WJNL5YNK.js +0 -2
  70. package/dist/cdn/chunks/de-WJNL5YNK.js.map +0 -7
  71. package/dist/cdn/chunks/es-DV5N3CXP.js +0 -2
  72. package/dist/cdn/chunks/es-DV5N3CXP.js.map +0 -7
  73. package/dist/cdn/chunks/fr-YU75PBOR.js +0 -2
  74. package/dist/cdn/chunks/fr-YU75PBOR.js.map +0 -7
  75. package/dist/cdn/chunks/it-DZTHWNO3.js +0 -2
  76. package/dist/cdn/chunks/it-DZTHWNO3.js.map +0 -7
  77. package/dist/cdn/chunks/ja-QO442LBN.js +0 -2
  78. package/dist/cdn/chunks/ja-QO442LBN.js.map +0 -7
  79. package/dist/cdn/chunks/ko-EGFZJCXQ.js +0 -2
  80. package/dist/cdn/chunks/ko-EGFZJCXQ.js.map +0 -7
  81. package/dist/cdn/chunks/pt-BR-526LHI67.js +0 -2
  82. package/dist/cdn/chunks/pt-BR-526LHI67.js.map +0 -7
  83. package/dist/cdn/chunks/ru-5WNEMKNP.js +0 -2
  84. package/dist/cdn/chunks/ru-5WNEMKNP.js.map +0 -7
  85. package/dist/cdn/chunks/zh-CN-ABSHNLG6.js +0 -2
  86. package/dist/cdn/chunks/zh-CN-ABSHNLG6.js.map +0 -7
@@ -1,8 +1,22 @@
1
+ /**
2
+ * createChat — n8n's chat widget, drawn by aparté, from the same call.
3
+ *
4
+ * The options are `@n8n/chat`'s, under its names and with its defaults, so a page swaps
5
+ * the import and keeps its call: the same webhook, the same session key in the browser
6
+ * (a visitor keeps their conversation across the switch), the same `--chat--*` variables
7
+ * read by the n8n theme. What it adds is what the original lacks: a handle to open, close,
8
+ * send and reset; a real new conversation; French; history without the tool steps; errors
9
+ * that say what to change in n8n; and no style leaking into the page.
10
+ */
11
+ import { AparteConfig } from '@aparte/core';
1
12
  import type { AparteLocale } from '@aparte/core';
2
13
  import type { ChatStrings } from './strings.js';
3
14
  /** `createChat`'s options: `@n8n/chat`'s, under its names and with its defaults. */
4
15
  export interface ChatOptions {
5
- /** The Chat Trigger's production URL, the one that ends in `/chat`. */
16
+ /**
17
+ * The Chat Trigger's production URL, the one that ends in `/chat`. A relative URL is read
18
+ * against the page's address, as a link would be.
19
+ */
6
20
  webhookUrl: string;
7
21
  /**
8
22
  * `headers` are sent with every request, read each time — so an object you change later
@@ -20,11 +34,12 @@ export interface ChatOptions {
20
34
  */
21
35
  target?: string | Element;
22
36
  /**
23
- * `'window'` floats a button in the corner that opens the chat; `'fullscreen'` fills the
24
- * target, which needs a height.
37
+ * `'window'` floats a button in the corner that opens the chat; `'embedded'` sits in the
38
+ * page as a block, filling the target, which needs a height. `'fullscreen'` is the same
39
+ * as `'embedded'`: the name `@n8n/chat` gives it, kept so its setup carries over.
25
40
  * @default 'window'
26
41
  */
27
- mode?: 'window' | 'fullscreen';
42
+ mode?: 'window' | 'embedded' | 'fullscreen';
28
43
  /**
29
44
  * A ✕ in the header, in window mode. Without it the button in the corner closes the
30
45
  * chat, and on a phone, where the open chat covers the page, it moves to the top corner.
@@ -50,7 +65,7 @@ export interface ChatOptions {
50
65
  /**
51
66
  * The language, as a tag (`'de'`, `'pt-BR'`, `'fr-CA'`): the chrome's words come from
52
67
  * `i18n[defaultLanguage]` over the built-in ones, the chat's own from aparté's locale,
53
- * loaded for that language alone. Nine ship, all left to right: English, French, Spanish,
68
+ * loaded for that language alone. Ten ship, all left to right: English, French, Spanish,
54
69
  * Portuguese (Brazil), German, Italian, Russian, Japanese, Korean and Chinese
55
70
  * (Simplified); another tag reads in English, or in the `locale` you give.
56
71
  * @default 'en'
@@ -74,9 +89,13 @@ export interface ChatOptions {
74
89
  */
75
90
  locale?: AparteLocale;
76
91
  /** Let the person attach files; n8n receives them as `files`. @default false */
77
- allowFileUploads?: boolean;
92
+ allowFileUploads?: boolean | {
93
+ value: boolean;
94
+ };
78
95
  /** What the file picker offers, as an `accept` list (`'image/*,.pdf'`). @default any */
79
- allowedFilesMimeTypes?: string;
96
+ allowedFilesMimeTypes?: string | {
97
+ value: string;
98
+ };
80
99
  /** Accepted for compatibility: a streamed answer and a whole one are both read. */
81
100
  enableStreaming?: boolean;
82
101
  /** Called with the message before it is sent, and awaited. */
@@ -122,6 +141,22 @@ export interface ChatOptions {
122
141
  * here; this one takes functions, which any framework can call into.
123
142
  */
124
143
  messageComponents?: Record<string, (args: Record<string, unknown>) => HTMLElement | string>;
144
+ /**
145
+ * Draw a ```card-<name> code block of JSON in an answer as that rich card (`true` by
146
+ * default): weather, items, product, place, stats, order, stock, plan, score, media,
147
+ * link. Each card's code is fetched the first time it appears. `false` shows the block as
148
+ * code, as n8n's own widget does.
149
+ */
150
+ cards?: boolean;
151
+ /**
152
+ * Extend the chat with aparté's plugins and your own cards: called once with the widget's
153
+ * config, before the first message. What it returns, if a function, runs on `destroy()`.
154
+ *
155
+ * @example
156
+ * import { setupKatex } from '@aparte/plugin-katex';
157
+ * createChat({ webhookUrl, setup: (config) => setupKatex({}, config) });
158
+ */
159
+ setup?: (config: AparteConfig) => void | (() => void);
125
160
  }
126
161
  /** A `messageHistory` entry: text, or a component drawn by `messageComponents`. */
127
162
  export type ChatHistoryMessage = {
@@ -147,7 +182,7 @@ export interface ChatResponse {
147
182
  }
148
183
  /** What `createChat` returns: the widget, and what a page can do with it. */
149
184
  export interface Chat {
150
- /** The widget's root element: `<aparte-launcher>` in window mode, a `div` in fullscreen. */
185
+ /** The widget's root element: `<aparte-launcher>` in window mode, a `div` when embedded. */
151
186
  readonly element: HTMLElement;
152
187
  /** The session the conversation runs in. */
153
188
  readonly sessionId: string;
package/dist/index.d.ts CHANGED
@@ -9,3 +9,5 @@
9
9
  export { createChat } from './create-chat.js';
10
10
  export type { Chat, ChatOptions, ChatResponse } from './create-chat.js';
11
11
  export type { ChatStrings } from './strings.js';
12
+ export { defineCard, el, glyph, safeUrl, webUrl, formatNumber, formatPrice, formatDay, formatWhen } from '@aparte/plugin-cards';
13
+ export type { CardDefinition, CardContext, AparteCardSegment } from '@aparte/plugin-cards';
package/dist/index.js CHANGED
@@ -1,6 +1,22 @@
1
1
  import { uuid, AparteConfig, AparteErrorCode, attachConfig, AparteClient, AparteError, registerSegmentRenderer } from "@aparte/core";
2
2
  import { setupMarkedStreamingProvider } from "@aparte/plugin-marked/streaming";
3
3
  import { setupN8nButtons, createN8nRunner, loadN8nHistory } from "@aparte/runner-n8n";
4
+ import { setupCardFences } from "@aparte/plugin-cards";
5
+ import { defineCard, el, formatDay, formatNumber, formatPrice, formatWhen, glyph, safeUrl, webUrl } from "@aparte/plugin-cards";
6
+ const CARDS = {
7
+ weather: () => import("@aparte/plugin-cards/weather"),
8
+ items: () => import("@aparte/plugin-cards/items"),
9
+ product: () => import("@aparte/plugin-cards/product"),
10
+ place: () => import("@aparte/plugin-cards/place"),
11
+ stats: () => import("@aparte/plugin-cards/stats"),
12
+ order: () => import("@aparte/plugin-cards/order"),
13
+ stock: () => import("@aparte/plugin-cards/stock"),
14
+ plan: () => import("@aparte/plugin-cards/plan"),
15
+ score: () => import("@aparte/plugin-cards/score"),
16
+ media: () => import("@aparte/plugin-cards/media"),
17
+ link: () => import("@aparte/plugin-cards/link")
18
+ };
19
+ const setupCards = (config) => setupCardFences({ config, load: CARDS });
4
20
  const bubble = '<svg class="aparte-icon" viewBox="0 0 24 24" fill="currentColor"><path d="M5.5 3.5h13a3 3 0 0 1 3 3v8.5a3 3 0 0 1-3 3h-6.2l-4.8 3.6a.6.6 0 0 1-1-.5v-3.1H5.5a3 3 0 0 1-3-3V6.5a3 3 0 0 1 3-3Z"/></svg>';
5
21
  const chevron = '<svg class="aparte-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="m6 9.5 6 6 6-6"/></svg>';
6
22
  const plane = '<svg class="aparte-icon" viewBox="0 0 24 24" fill="currentColor"><path d="M3.4 20.2 21 12.6a.7.7 0 0 0 0-1.2L3.4 3.8a.6.6 0 0 0-.9.7L5 11l8 1-8 1-2.5 6.5a.6.6 0 0 0 .9.7Z"/></svg>';
@@ -165,6 +181,16 @@ function initialMessagesFor(language) {
165
181
  function loadLocale(language) {
166
182
  return LANGUAGES[shippedLanguage(language)].locale?.();
167
183
  }
184
+ function absoluteUrl(url) {
185
+ if (typeof url !== "string" || !url.trim()) {
186
+ throw new TypeError("[aparte] n8n: createChat needs webhookUrl, the Chat Trigger's production URL, the one that ends in /chat.");
187
+ }
188
+ try {
189
+ return new URL(url, typeof document === "undefined" ? void 0 : document.baseURI).href;
190
+ } catch {
191
+ throw new TypeError(`[aparte] n8n: webhookUrl "${url}" is not a URL. Use the Chat Trigger's production URL, the one that ends in /chat.`);
192
+ }
193
+ }
168
194
  const STORAGE_KEY = "n8n-chat/sessionId";
169
195
  const WORKFLOW_ERROR = "N8N_WORKFLOW_ERROR";
170
196
  const componentsByChat = /* @__PURE__ */ new WeakMap();
@@ -211,13 +237,13 @@ function resolveTarget(target) {
211
237
  if (typeof target !== "string") return target;
212
238
  const found = document.querySelector(target);
213
239
  if (found) return found;
214
- const el2 = document.createElement("div");
215
- if (target.startsWith("#")) el2.id = target.slice(1);
216
- else if (target.startsWith(".")) el2.className = target.slice(1);
217
- document.body.appendChild(el2);
218
- return el2;
240
+ const el22 = document.createElement("div");
241
+ if (target.startsWith("#")) el22.id = target.slice(1);
242
+ else if (target.startsWith(".")) el22.className = target.slice(1);
243
+ document.body.appendChild(el22);
244
+ return el22;
219
245
  }
220
- function el(tag, className, text) {
246
+ function el2(tag, className, text) {
221
247
  const node = document.createElement(tag);
222
248
  if (className) node.className = className;
223
249
  if (text !== void 0) node.textContent = text;
@@ -225,6 +251,7 @@ function el(tag, className, text) {
225
251
  }
226
252
  let instances = 0;
227
253
  function createChat(options) {
254
+ const webhookUrl = absoluteUrl(options.webhookUrl);
228
255
  const mode = options.mode ?? "window";
229
256
  const language = options.defaultLanguage ?? "en";
230
257
  const strings = stringsFor(language, options.i18n);
@@ -232,13 +259,15 @@ function createChat(options) {
232
259
  const initial = options.initialMessages ?? initialMessagesFor(language);
233
260
  const instance = ++instances;
234
261
  const titleId = `aparte-n8n-title-${instance}`;
262
+ const returning = loadPrevious && !options.sessionId && Boolean(read(STORAGE_KEY));
235
263
  let sessionId = options.sessionId ?? (loadPrevious ? read(STORAGE_KEY) : void 0) ?? uuid();
236
264
  if (loadPrevious && !options.sessionId) write(STORAGE_KEY, sessionId);
237
265
  const config = new AparteConfig();
238
266
  if (options.locale) config.setLocale(options.locale);
239
267
  let destroyed = false;
268
+ let beforeSetup = config.getLocale();
240
269
  void loadLocale(language)?.then((locale) => {
241
- if (!destroyed && !options.locale) config.setLocale(locale);
270
+ if (!destroyed && !options.locale && config.getLocale() === beforeSetup) config.setLocale(locale);
242
271
  }, (error) => console.warn("[aparte] n8n: the chat's language could not be loaded; it stays in English.", error));
243
272
  config.registerIcons(N8N_ICONS);
244
273
  if (options.enableMessageActions) {
@@ -247,18 +276,19 @@ function createChat(options) {
247
276
  }
248
277
  config.setHostHandlers({ attachmentPreview: true, filePreview: true });
249
278
  setupN8nButtons(config);
279
+ const stopCards = options.cards === false ? void 0 : setupCards(config);
250
280
  config.setErrorRenderer(({ message, sentence, code }) => {
251
281
  const workflow = code === WORKFLOW_ERROR;
252
- const card2 = el("div", "aparte-segment aparte-alert aparte-alert--danger aparte-segment-error");
282
+ const card2 = el2("div", "aparte-segment aparte-alert aparte-alert--danger aparte-segment-error");
253
283
  if (code) card2.setAttribute("data-error-code", workflow ? AparteErrorCode.PROVIDER_ERROR : code);
254
- const icon = el("span", "aparte-alert__icon");
284
+ const icon = el2("span", "aparte-alert__icon");
255
285
  icon.innerHTML = config.getIcon("error") || "⚠";
256
- const body = el("div", "aparte-alert__body");
286
+ const body = el2("div", "aparte-alert__body");
257
287
  body.append(
258
- el("div", "aparte-alert__title", config.t("error")),
259
- el("div", "aparte-alert__message", workflow ? config.t("errorNoAnswer") : sentence ?? message)
288
+ el2("div", "aparte-alert__title", config.t("error")),
289
+ el2("div", "aparte-alert__message", workflow ? config.t("errorNoAnswer") : sentence ?? message)
260
290
  );
261
- if (workflow && message) body.append(el("p", "aparte-n8n__error-detail", message));
291
+ if (workflow && message) body.append(el2("p", "aparte-n8n__error-detail", message));
262
292
  card2.append(icon, body);
263
293
  return card2;
264
294
  });
@@ -268,58 +298,62 @@ function createChat(options) {
268
298
  highlighter ??= import("./highlight-DDyMJYBk.js").then((m) => m.createHighlighter());
269
299
  return (await highlighter)(code, lang);
270
300
  });
271
- const card = el("section", "aparte-n8n__window");
301
+ beforeSetup = config.getLocale();
302
+ const stopSetup = options.setup?.(config);
303
+ const card = el2("section", "aparte-n8n__window");
272
304
  card.setAttribute("aria-labelledby", titleId);
273
- const header = el("header", "aparte-n8n__header");
274
- const heading = el("div", "aparte-n8n__heading");
275
- const title = el("p", "aparte-n8n__title", strings.title);
305
+ const header = el2("header", "aparte-n8n__header");
306
+ const heading = el2("div", "aparte-n8n__heading");
307
+ const title = el2("p", "aparte-n8n__title", strings.title);
276
308
  title.id = titleId;
277
309
  heading.append(title);
278
- if (strings.subtitle) heading.append(el("p", "aparte-n8n__subtitle", strings.subtitle));
310
+ if (strings.subtitle) heading.append(el2("p", "aparte-n8n__subtitle", strings.subtitle));
279
311
  header.append(heading);
280
312
  if (mode === "window" && options.showWindowCloseButton) {
281
- const close = el("button", "aparte-btn aparte-btn--icon aparte-btn--ghost aparte-n8n__close");
313
+ const close = el2("button", "aparte-btn aparte-btn--icon aparte-btn--ghost aparte-n8n__close");
282
314
  close.type = "button";
283
315
  close.setAttribute("aria-label", strings.closeButtonTooltip);
284
316
  close.setAttribute("data-aparte-launcher-close", "");
285
- const icon = el("aparte-icon");
317
+ const icon = el2("aparte-icon");
286
318
  icon.setAttribute("name", "close");
287
319
  close.append(icon);
288
320
  header.append(close);
289
321
  }
290
- const chat = el("aparte-chat", "aparte-n8n__chat");
322
+ const chat = el2("aparte-chat", "aparte-n8n__chat");
291
323
  chat.id = `aparte-n8n-chat-${instance}`;
292
324
  if (options.messageComponents) {
293
325
  registerComponentRenderer();
294
326
  componentsByChat.set(chat, options.messageComponents);
295
327
  }
296
- const composer = el("aparte-composer");
328
+ const composer = el2("aparte-composer");
297
329
  composer.setAttribute("placeholder", strings.inputPlaceholder);
298
330
  let suggestions;
299
331
  if (options.suggestions?.length) {
300
- suggestions = el("aparte-suggestions");
332
+ suggestions = el2("aparte-suggestions");
301
333
  suggestions.setAttribute("suggestions", JSON.stringify(options.suggestions.map((text) => ({ label: text, prompt: text }))));
302
334
  composer.append(suggestions);
303
335
  }
304
- const shell = el("div", "aparte-composer-shell");
305
- const row = el("div", "aparte-composer-row");
306
- row.append(el("aparte-composer-input"));
307
- if (options.allowFileUploads) {
308
- shell.append(el("aparte-composer-attachments"));
309
- const add = el("aparte-composer-add-attachment");
310
- if (options.allowedFilesMimeTypes) add.setAttribute("accept", options.allowedFilesMimeTypes);
336
+ const shell = el2("div", "aparte-composer-shell");
337
+ const row = el2("div", "aparte-composer-row");
338
+ row.append(el2("aparte-composer-input"));
339
+ const allowFiles = typeof options.allowFileUploads === "object" ? options.allowFileUploads?.value : options.allowFileUploads;
340
+ const acceptFiles = typeof options.allowedFilesMimeTypes === "object" ? options.allowedFilesMimeTypes?.value : options.allowedFilesMimeTypes;
341
+ if (allowFiles) {
342
+ shell.append(el2("aparte-composer-attachments"));
343
+ const add = el2("aparte-composer-add-attachment");
344
+ if (acceptFiles) add.setAttribute("accept", acceptFiles);
311
345
  row.append(add);
312
346
  }
313
- row.append(el("aparte-composer-send"));
347
+ row.append(el2("aparte-composer-send"));
314
348
  shell.append(row);
315
349
  composer.append(shell);
316
- chat.append(el("aparte-chat-viewport"), el("aparte-elicitation"), composer);
350
+ chat.append(el2("aparte-chat-viewport"), el2("aparte-elicitation"), composer);
317
351
  card.append(header, chat);
318
- if (strings.footer) card.append(el("p", "aparte-n8n__footer", strings.footer));
352
+ if (strings.footer) card.append(el2("p", "aparte-n8n__footer", strings.footer));
319
353
  let welcome;
320
- if (options.showWelcomeScreen) {
321
- welcome = el("div", "aparte-n8n__welcome");
322
- const start = el("button", "aparte-btn aparte-btn--primary aparte-btn--solid aparte-n8n__start", strings.getStarted);
354
+ if (options.showWelcomeScreen && !returning) {
355
+ welcome = el2("div", "aparte-n8n__welcome");
356
+ const start = el2("button", "aparte-btn aparte-btn--primary aparte-btn--solid aparte-n8n__start", strings.getStarted);
323
357
  start.type = "button";
324
358
  start.addEventListener("click", () => {
325
359
  welcome.hidden = true;
@@ -332,10 +366,10 @@ function createChat(options) {
332
366
  }
333
367
  let root;
334
368
  if (mode === "window") {
335
- root = el("aparte-launcher", "aparte-n8n aparte-n8n--window");
369
+ root = el2("aparte-launcher", "aparte-n8n aparte-n8n--window");
336
370
  root.append(card);
337
371
  } else {
338
- root = el("div", "aparte-n8n aparte-n8n--fullscreen");
372
+ root = el2("div", "aparte-n8n aparte-n8n--fullscreen");
339
373
  root.append(card);
340
374
  }
341
375
  const scheme = options.colorScheme ?? "light";
@@ -388,7 +422,7 @@ function createChat(options) {
388
422
  const ticket = ++loaded;
389
423
  historyRequest = new AbortController();
390
424
  void loadN8nHistory({
391
- webhookUrl: options.webhookUrl,
425
+ webhookUrl,
392
426
  sessionId,
393
427
  ...options.metadata ? { metadata: options.metadata } : {},
394
428
  ...options.chatSessionKey ? { chatSessionKey: options.chatSessionKey } : {},
@@ -452,7 +486,7 @@ function createChat(options) {
452
486
  window.addEventListener("aparte-message-aborted", onStopped);
453
487
  let runSession = sessionId;
454
488
  const runner = createN8nRunner({
455
- webhookUrl: options.webhookUrl,
489
+ webhookUrl,
456
490
  sessionId: () => runSession,
457
491
  headers: () => ({ ...options.webhookConfig?.headers ?? {} }),
458
492
  ...options.fetch ? { fetch: options.fetch } : {},
@@ -551,11 +585,14 @@ function createChat(options) {
551
585
  if (typeof options.disabled === "object" ? options.disabled?.value : options.disabled) setDisabled(true);
552
586
  const launcher = () => mode === "window" ? root : void 0;
553
587
  const destroy = () => {
588
+ if (destroyed) return;
554
589
  destroyed = true;
555
590
  historyRequest?.abort();
556
591
  queued.length = 0;
557
592
  window.removeEventListener("aparte-message-aborted", onStopped);
558
593
  client.stop();
594
+ stopCards?.();
595
+ if (typeof stopSetup === "function") stopSetup();
559
596
  root.remove();
560
597
  };
561
598
  return {
@@ -588,6 +625,15 @@ function createChat(options) {
588
625
  };
589
626
  }
590
627
  export {
591
- createChat
628
+ createChat,
629
+ defineCard,
630
+ el,
631
+ formatDay,
632
+ formatNumber,
633
+ formatPrice,
634
+ formatWhen,
635
+ glyph,
636
+ safeUrl,
637
+ webUrl
592
638
  };
593
639
  //# sourceMappingURL=index.js.map