@aparte/n8n-chat 0.0.0-stage → 0.2.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 (73) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +333 -2
  3. package/dist/cards.d.ts +3 -0
  4. package/dist/cdn/chunks/chunk-7JR7KL6J.js +2 -0
  5. package/dist/cdn/chunks/chunk-7JR7KL6J.js.map +7 -0
  6. package/dist/cdn/chunks/chunk-CZ5742JA.js +2 -0
  7. package/dist/cdn/chunks/chunk-CZ5742JA.js.map +7 -0
  8. package/dist/cdn/chunks/chunk-IPWLCOPM.js +2 -0
  9. package/dist/cdn/chunks/chunk-IPWLCOPM.js.map +7 -0
  10. package/dist/cdn/chunks/chunk-IWAJFJNA.js +353 -0
  11. package/dist/cdn/chunks/chunk-IWAJFJNA.js.map +7 -0
  12. package/dist/cdn/chunks/chunk-OJFRNS5M.js +2 -0
  13. package/dist/cdn/chunks/chunk-OJFRNS5M.js.map +7 -0
  14. package/dist/cdn/chunks/chunk-VTTH7HGO.js +206 -0
  15. package/dist/cdn/chunks/chunk-VTTH7HGO.js.map +7 -0
  16. package/dist/cdn/chunks/chunk-XAWE4EAK.js +2 -0
  17. package/dist/cdn/chunks/chunk-XAWE4EAK.js.map +7 -0
  18. package/dist/cdn/chunks/de-JS3CQEVR.js +2 -0
  19. package/dist/cdn/chunks/de-JS3CQEVR.js.map +7 -0
  20. package/dist/cdn/chunks/es-OHKGLFEF.js +2 -0
  21. package/dist/cdn/chunks/es-OHKGLFEF.js.map +7 -0
  22. package/dist/cdn/chunks/fr-6S44XMU5.js +2 -0
  23. package/dist/cdn/chunks/fr-6S44XMU5.js.map +7 -0
  24. package/dist/cdn/chunks/highlight-FGIKUPIF.js +153 -0
  25. package/dist/cdn/chunks/highlight-FGIKUPIF.js.map +7 -0
  26. package/dist/cdn/chunks/it-K4WYXXDJ.js +2 -0
  27. package/dist/cdn/chunks/it-K4WYXXDJ.js.map +7 -0
  28. package/dist/cdn/chunks/items-S4LF2DJA.js +467 -0
  29. package/dist/cdn/chunks/items-S4LF2DJA.js.map +7 -0
  30. package/dist/cdn/chunks/ja-BN7TZW62.js +2 -0
  31. package/dist/cdn/chunks/ja-BN7TZW62.js.map +7 -0
  32. package/dist/cdn/chunks/ko-ARHO7UI3.js +2 -0
  33. package/dist/cdn/chunks/ko-ARHO7UI3.js.map +7 -0
  34. package/dist/cdn/chunks/link-C46K5O7X.js +493 -0
  35. package/dist/cdn/chunks/link-C46K5O7X.js.map +7 -0
  36. package/dist/cdn/chunks/media-QI5BPERX.js +797 -0
  37. package/dist/cdn/chunks/media-QI5BPERX.js.map +7 -0
  38. package/dist/cdn/chunks/order-YISYH73K.js +839 -0
  39. package/dist/cdn/chunks/order-YISYH73K.js.map +7 -0
  40. package/dist/cdn/chunks/place-UFCH3NQE.js +689 -0
  41. package/dist/cdn/chunks/place-UFCH3NQE.js.map +7 -0
  42. package/dist/cdn/chunks/plan-KQWF73QI.js +542 -0
  43. package/dist/cdn/chunks/plan-KQWF73QI.js.map +7 -0
  44. package/dist/cdn/chunks/product-7UBLOMZ7.js +660 -0
  45. package/dist/cdn/chunks/product-7UBLOMZ7.js.map +7 -0
  46. package/dist/cdn/chunks/pt-BR-R7ZRM3GG.js +2 -0
  47. package/dist/cdn/chunks/pt-BR-R7ZRM3GG.js.map +7 -0
  48. package/dist/cdn/chunks/ru-FJNIMGMU.js +2 -0
  49. package/dist/cdn/chunks/ru-FJNIMGMU.js.map +7 -0
  50. package/dist/cdn/chunks/score-O2KEAYDS.js +882 -0
  51. package/dist/cdn/chunks/score-O2KEAYDS.js.map +7 -0
  52. package/dist/cdn/chunks/stats-GSXFRGYZ.js +491 -0
  53. package/dist/cdn/chunks/stats-GSXFRGYZ.js.map +7 -0
  54. package/dist/cdn/chunks/stock-53NVFLC3.js +707 -0
  55. package/dist/cdn/chunks/stock-53NVFLC3.js.map +7 -0
  56. package/dist/cdn/chunks/weather-VI2RCU4X.js +615 -0
  57. package/dist/cdn/chunks/weather-VI2RCU4X.js.map +7 -0
  58. package/dist/cdn/chunks/zh-CN-DUCWBXJP.js +2 -0
  59. package/dist/cdn/chunks/zh-CN-DUCWBXJP.js.map +7 -0
  60. package/dist/cdn/n8n-chat.js +103 -0
  61. package/dist/cdn/n8n-chat.js.map +7 -0
  62. package/dist/create-chat.d.ts +198 -0
  63. package/dist/highlight-DDyMJYBk.js +29 -0
  64. package/dist/highlight-DDyMJYBk.js.map +1 -0
  65. package/dist/highlight.d.ts +2 -0
  66. package/dist/icons.d.ts +7 -0
  67. package/dist/index.d.ts +11 -0
  68. package/dist/index.js +618 -0
  69. package/dist/index.js.map +1 -0
  70. package/dist/strings.d.ts +40 -0
  71. package/dist/style.css +378 -0
  72. package/dist/theme.css +376 -0
  73. package/package.json +82 -5
@@ -0,0 +1,198 @@
1
+ import type { AparteLocale } from '@aparte/core';
2
+ import type { ChatStrings } from './strings.js';
3
+ /** `createChat`'s options: `@n8n/chat`'s, under its names and with its defaults. */
4
+ export interface ChatOptions {
5
+ /**
6
+ * The Chat Trigger's production URL, the one that ends in `/chat`. A relative URL is read
7
+ * against the page's address, as a link would be.
8
+ */
9
+ webhookUrl: string;
10
+ /**
11
+ * `headers` are sent with every request, read each time — so an object you change later
12
+ * (a refreshed token) is honoured. `method` is accepted for compatibility: every request
13
+ * is a POST, which is what n8n answers for streaming and files.
14
+ */
15
+ webhookConfig?: {
16
+ method?: 'GET' | 'POST';
17
+ headers?: Record<string, string>;
18
+ };
19
+ /**
20
+ * Where the widget mounts: an element, or a selector. A selector that matches nothing
21
+ * gets a `div` with that id (or class) at the end of the body.
22
+ * @default '#n8n-chat'
23
+ */
24
+ target?: string | Element;
25
+ /**
26
+ * `'window'` floats a button in the corner that opens the chat; `'embedded'` sits in the
27
+ * page as a block, filling the target, which needs a height. `'fullscreen'` is the same
28
+ * as `'embedded'`: the name `@n8n/chat` gives it, kept so its setup carries over.
29
+ * @default 'window'
30
+ */
31
+ mode?: 'window' | 'embedded' | 'fullscreen';
32
+ /**
33
+ * A ✕ in the header, in window mode. Without it the button in the corner closes the
34
+ * chat, and on a phone, where the open chat covers the page, it moves to the top corner.
35
+ * @default false, as n8n's widget
36
+ */
37
+ showWindowCloseButton?: boolean;
38
+ /** Show a screen with a "New Conversation" button before the chat. @default false */
39
+ showWelcomeScreen?: boolean;
40
+ /**
41
+ * Keep the session in the browser (`localStorage`, key `n8n-chat/sessionId`, the one
42
+ * n8n's widget uses) and show its earlier messages again on load. Needs the Chat
43
+ * Trigger's *Load Previous Session* set to *From Memory*, its memory connected to the
44
+ * trigger too. Off: each page load is a new conversation.
45
+ * @default true
46
+ */
47
+ loadPreviousSession?: boolean;
48
+ /** Use this session instead of the stored one (your app's conversation id). */
49
+ sessionId?: string;
50
+ /** @default 'chatInput', the Chat Trigger's */
51
+ chatInputKey?: string;
52
+ /** @default 'sessionId', the Chat Trigger's */
53
+ chatSessionKey?: string;
54
+ /**
55
+ * The language, as a tag (`'de'`, `'pt-BR'`, `'fr-CA'`): the chrome's words come from
56
+ * `i18n[defaultLanguage]` over the built-in ones, the chat's own from aparté's locale,
57
+ * loaded for that language alone. Nine ship, all left to right: English, French, Spanish,
58
+ * Portuguese (Brazil), German, Italian, Russian, Japanese, Korean and Chinese
59
+ * (Simplified); another tag reads in English, or in the `locale` you give.
60
+ * @default 'en'
61
+ */
62
+ defaultLanguage?: string;
63
+ /** Messages shown first, from the assistant; neither sent nor kept. @default n8n's two */
64
+ initialMessages?: string[];
65
+ /**
66
+ * A conversation to show when n8n has none for the session — after the first messages,
67
+ * as n8n's widget shows it. Shown, not sent: n8n's memory does not hold it.
68
+ */
69
+ messageHistory?: ChatHistoryMessage[];
70
+ /** Sent with every message, as `metadata` in the trigger's output. */
71
+ metadata?: Record<string, unknown>;
72
+ /** The chrome's words, by language, over the built-in ones. */
73
+ i18n?: Record<string, Partial<ChatStrings>>;
74
+ /**
75
+ * The chat's own words — its buttons, its error card, its screen-reader names — for a
76
+ * language aparté does not ship: an `AparteLocale` (see the localization guide).
77
+ * @default English, or French for `defaultLanguage: 'fr'`
78
+ */
79
+ locale?: AparteLocale;
80
+ /** Let the person attach files; n8n receives them as `files`. @default false */
81
+ allowFileUploads?: boolean;
82
+ /** What the file picker offers, as an `accept` list (`'image/*,.pdf'`). @default any */
83
+ allowedFilesMimeTypes?: string;
84
+ /** Accepted for compatibility: a streamed answer and a whole one are both read. */
85
+ enableStreaming?: boolean;
86
+ /** Called with the message before it is sent, and awaited. */
87
+ beforeMessageSent?: (message: string) => void | Promise<void>;
88
+ /**
89
+ * Called with the message and the answer once the answer is complete, after the turn —
90
+ * a hook that throws or takes its time changes nothing on screen. The answer reads like
91
+ * either of n8n's: `output` (a whole answer), `message` and `hasReceivedChunks` (a
92
+ * streamed one).
93
+ */
94
+ afterMessageSent?: (message: string, response?: ChatResponse) => void | Promise<void>;
95
+ /** Accepted for compatibility: n8n's widget never read it. Theme with CSS variables. */
96
+ theme?: unknown;
97
+ /**
98
+ * Questions offered above the input until the first message, one press to send.
99
+ * @default none
100
+ */
101
+ suggestions?: string[];
102
+ /**
103
+ * The color scheme: light like n8n's widget, dark, or the visitor's own.
104
+ * @default 'light'
105
+ */
106
+ colorScheme?: 'light' | 'dark' | 'auto';
107
+ /** Every request to n8n goes through it: a proxy, a test, a recorded demo. @default the global `fetch` */
108
+ fetch?: typeof fetch;
109
+ /**
110
+ * Block the input, as n8n's `disabled`: `true`, or n8n's `{ value }` (a Vue ref), read once
111
+ * when the widget mounts. `setDisabled()` on the handle changes it later.
112
+ * @default false
113
+ */
114
+ disabled?: boolean | {
115
+ value: boolean;
116
+ };
117
+ /**
118
+ * Two actions on the person's own messages, as n8n's widget has them: send the message
119
+ * again, with its files, and put its text back in the input.
120
+ * @default false
121
+ */
122
+ enableMessageActions?: boolean;
123
+ /**
124
+ * What draws a `messageHistory` entry of `type: 'component'`: the function under its `key`
125
+ * gets its `arguments` and returns an element or HTML. n8n's widget takes Vue components
126
+ * here; this one takes functions, which any framework can call into.
127
+ */
128
+ messageComponents?: Record<string, (args: Record<string, unknown>) => HTMLElement | string>;
129
+ /**
130
+ * Draw a ```card-<name> code block of JSON in an answer as that rich card (`true` by
131
+ * default): weather, items, product, place, stats, order, stock, plan, score, media,
132
+ * link. Each card's code is fetched the first time it appears. `false` shows the block as
133
+ * code, as n8n's own widget does.
134
+ */
135
+ cards?: boolean;
136
+ }
137
+ /** A `messageHistory` entry: text, or a component drawn by `messageComponents`. */
138
+ export type ChatHistoryMessage = {
139
+ type?: 'text';
140
+ text: string;
141
+ sender: 'user' | 'bot';
142
+ transparent?: boolean;
143
+ } | {
144
+ type: 'component';
145
+ key: string;
146
+ arguments?: Record<string, unknown>;
147
+ sender: 'user' | 'bot';
148
+ transparent?: boolean;
149
+ };
150
+ /** The answer `afterMessageSent` receives, shaped like both of `@n8n/chat`'s. */
151
+ export interface ChatResponse {
152
+ /** The answer's text, as a whole answer's `output`. */
153
+ output: string;
154
+ /** The answer's text, as a streamed answer's `message`. */
155
+ message: string;
156
+ /** Whether any text arrived. */
157
+ hasReceivedChunks: boolean;
158
+ }
159
+ /** What `createChat` returns: the widget, and what a page can do with it. */
160
+ export interface Chat {
161
+ /** The widget's root element: `<aparte-launcher>` in window mode, a `div` when embedded. */
162
+ readonly element: HTMLElement;
163
+ /** The session the conversation runs in. */
164
+ readonly sessionId: string;
165
+ /** Open the chat (window mode). */
166
+ open(): void;
167
+ /** Close the chat (window mode). */
168
+ close(): void;
169
+ /** Open it when closed, close it when open (window mode). */
170
+ toggle(): void;
171
+ /**
172
+ * Send a message as the person. While an answer is on its way, it waits for it; what
173
+ * the person is typing is left as it is.
174
+ */
175
+ send(text: string): void;
176
+ /**
177
+ * Start a new conversation: the answer on its way stops, the first messages come back,
178
+ * and a new session starts — unless you gave `sessionId`, which is yours to change.
179
+ */
180
+ reset(): void;
181
+ /** Block the input, or let the person type again. */
182
+ setDisabled(disabled: boolean): void;
183
+ /** Remove the widget and stop its client. */
184
+ destroy(): void;
185
+ /** The same as `destroy()`, under the name of the Vue app n8n's widget returns. */
186
+ unmount(): void;
187
+ }
188
+ /**
189
+ * Mount n8n's chat widget, drawn by aparté: the same options as `@n8n/chat`'s
190
+ * `createChat`, and a handle to drive it.
191
+ *
192
+ * @example
193
+ * import { createChat } from '@aparte/n8n-chat';
194
+ * import '@aparte/n8n-chat/style.css';
195
+ *
196
+ * createChat({ webhookUrl: 'https://your-n8n.example.com/webhook/<id>/chat' });
197
+ */
198
+ export declare function createChat(options: ChatOptions): Chat;
@@ -0,0 +1,29 @@
1
+ import { AparteConfig } from "@aparte/core";
2
+ import { setupShikiProviderFromHighlighter } from "@aparte/plugin-shiki/core";
3
+ import { createHighlighterCore } from "shiki/core";
4
+ import { createJavaScriptRegexEngine } from "shiki/engine/javascript";
5
+ import bash from "@shikijs/langs/bash";
6
+ import css from "@shikijs/langs/css";
7
+ import html from "@shikijs/langs/html";
8
+ import javascript from "@shikijs/langs/javascript";
9
+ import json from "@shikijs/langs/json";
10
+ import python from "@shikijs/langs/python";
11
+ import sql from "@shikijs/langs/sql";
12
+ import typescript from "@shikijs/langs/typescript";
13
+ import yaml from "@shikijs/langs/yaml";
14
+ import githubDark from "@shikijs/themes/github-dark";
15
+ import githubLight from "@shikijs/themes/github-light";
16
+ async function createHighlighter() {
17
+ const highlighter = await createHighlighterCore({
18
+ themes: [githubLight, githubDark],
19
+ langs: [bash, css, html, javascript, json, python, sql, typescript, yaml],
20
+ engine: createJavaScriptRegexEngine()
21
+ });
22
+ const own = new AparteConfig();
23
+ setupShikiProviderFromHighlighter(highlighter, { theme: { light: "github-light", dark: "github-dark" } }, own);
24
+ return (code, lang) => own.highlightCode(code, lang);
25
+ }
26
+ export {
27
+ createHighlighter
28
+ };
29
+ //# sourceMappingURL=highlight-DDyMJYBk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"highlight-DDyMJYBk.js","sources":["../src/highlight.ts"],"sourcesContent":["/**\r\n * Code in an answer, highlighted — loaded the first time an answer holds code, so a page\r\n * whose visitors never see a code block never downloads a grammar.\r\n *\r\n * A fixed set of languages through shiki's core and its JavaScript engine, built here rather\r\n * than through `@aparte/plugin-shiki`'s main entry: that one maps every language shiki knows\r\n * to a file of its own (302 of them). A language outside the set reads as plain text. The\r\n * colors follow the widget's scheme, light or dark.\r\n */\r\nimport { AparteConfig } from '@aparte/core';\r\nimport { setupShikiProviderFromHighlighter } from '@aparte/plugin-shiki/core';\r\nimport { createHighlighterCore } from 'shiki/core';\r\nimport { createJavaScriptRegexEngine } from 'shiki/engine/javascript';\r\nimport bash from '@shikijs/langs/bash';\r\nimport css from '@shikijs/langs/css';\r\nimport html from '@shikijs/langs/html';\r\nimport javascript from '@shikijs/langs/javascript';\r\nimport json from '@shikijs/langs/json';\r\nimport python from '@shikijs/langs/python';\r\nimport sql from '@shikijs/langs/sql';\r\nimport typescript from '@shikijs/langs/typescript';\r\nimport yaml from '@shikijs/langs/yaml';\r\nimport githubDark from '@shikijs/themes/github-dark';\r\nimport githubLight from '@shikijs/themes/github-light';\r\n\r\n/** Highlight `code` as `lang`: shiki's HTML, or the code as plain text in a language it lacks. */\r\nexport async function createHighlighter(): Promise<(code: string, lang: string) => Promise<string>> {\r\n const highlighter = await createHighlighterCore({\r\n themes: [githubLight, githubDark],\r\n langs: [bash, css, html, javascript, json, python, sql, typescript, yaml],\r\n engine: createJavaScriptRegexEngine(),\r\n });\r\n // The plugin's provider (its plain-text fallback, its light/dark pair) on a config of its\r\n // own, called from the widget's: the widget's config keeps one provider, this lazy one.\r\n const own = new AparteConfig();\r\n setupShikiProviderFromHighlighter(highlighter, { theme: { light: 'github-light', dark: 'github-dark' } }, own);\r\n return (code, lang) => own.highlightCode(code, lang);\r\n}\r\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AA0BA,eAAsB,oBAA8E;AAChG,QAAM,cAAc,MAAM,sBAAsB;AAAA,IAC5C,QAAQ,CAAC,aAAa,UAAU;AAAA,IAChC,OAAO,CAAC,MAAM,KAAK,MAAM,YAAY,MAAM,QAAQ,KAAK,YAAY,IAAI;AAAA,IACxE,QAAQ,4BAAA;AAAA,EAA4B,CACvC;AAGD,QAAM,MAAM,IAAI,aAAA;AAChB,oCAAkC,aAAa,EAAE,OAAO,EAAE,OAAO,gBAAgB,MAAM,gBAAc,GAAK,GAAG;AAC7G,SAAO,CAAC,MAAM,SAAS,IAAI,cAAc,MAAM,IAAI;AACvD;"}
@@ -0,0 +1,2 @@
1
+ /** Highlight `code` as `lang`: shiki's HTML, or the code as plain text in a language it lacks. */
2
+ export declare function createHighlighter(): Promise<(code: string, lang: string) => Promise<string>>;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The n8n widget's icons, drawn for this package in its manner: a filled speech bubble on the
3
+ * button in the corner, a chevron when the chat is open, a filled paper plane to send. Sized
4
+ * by the container (`--aparte-icon-size`), like every aparté glyph.
5
+ */
6
+ /** What `createChat` registers on its widget's config: the launcher's two, and send. */
7
+ export declare const N8N_ICONS: Record<string, () => string>;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @aparte/n8n-chat — n8n's chat widget, drawn by aparté.
3
+ *
4
+ * `createChat()` takes `@n8n/chat`'s options and mounts the same widget — a button in the
5
+ * corner, or a chat that fills its target — on an n8n Chat Trigger, through
6
+ * `@aparte/runner-n8n`. `style.css` is aparté's stylesheet with the n8n theme;
7
+ * `theme.css` is the theme alone, for a chat you compose yourself.
8
+ */
9
+ export { createChat } from './create-chat.js';
10
+ export type { Chat, ChatOptions, ChatResponse } from './create-chat.js';
11
+ export type { ChatStrings } from './strings.js';