@gemina/elements 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/dist/chat.cjs ADDED
@@ -0,0 +1,488 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/chat.tsx
21
+ var chat_exports = {};
22
+ __export(chat_exports, {
23
+ GeminaChat: () => GeminaChat
24
+ });
25
+ module.exports = __toCommonJS(chat_exports);
26
+ var import_react = require("react");
27
+ var import_sdk = require("@gemina/sdk");
28
+
29
+ // src/version.ts
30
+ var VERSION = "0.1.0";
31
+
32
+ // src/chat.tsx
33
+ var import_jsx_runtime = require("react/jsx-runtime");
34
+ var HEBREW_RE = /[\u0590-\u05FF]/;
35
+ function httpStatus(error) {
36
+ if (error !== null && typeof error === "object" && "response" in error) {
37
+ const response = error.response;
38
+ if (response !== null && typeof response === "object" && typeof response.status === "number") {
39
+ return response.status;
40
+ }
41
+ }
42
+ return void 0;
43
+ }
44
+ var SESSION_EXPIRED_TEXT = "Session expired \u2014 please reload the page or sign in again.";
45
+ var RATE_LIMIT_TEXT = "You're sending messages too quickly \u2014 try again shortly.";
46
+ var PLAN_GATE_TEXT = "Document Intelligence isn't enabled on this plan.";
47
+ var GENERIC_ERROR_TEXT = "Something went wrong and your message wasn't answered.";
48
+ function normalizeCitations(citations) {
49
+ if (!Array.isArray(citations)) {
50
+ return [];
51
+ }
52
+ const ids = [];
53
+ for (const item of citations) {
54
+ if (typeof item === "string" && item.length > 0) {
55
+ ids.push(item);
56
+ } else if (item !== null && typeof item === "object" && typeof item.documentId === "string") {
57
+ ids.push(item.documentId);
58
+ }
59
+ }
60
+ return ids;
61
+ }
62
+ var DARK_VARS = `
63
+ --gemina-chat-bg: #101418;
64
+ --gemina-chat-fg: #e6e9ee;
65
+ --gemina-chat-border: #2a323c;
66
+ --gemina-chat-accent: #4c8dff;
67
+ --gemina-chat-accent-fg: #ffffff;
68
+ --gemina-chat-assistant-bg: #1c232b;
69
+ --gemina-chat-assistant-fg: #e6e9ee;
70
+ --gemina-chat-muted: #98a2b3;
71
+ --gemina-chat-error: #f97066;
72
+ --gemina-chat-low-confidence: #f7b27a;
73
+ `;
74
+ var CHAT_CSS = `
75
+ .gemina-chat {
76
+ --gemina-chat-bg: #ffffff;
77
+ --gemina-chat-fg: #1a1d21;
78
+ --gemina-chat-border: #d9dce1;
79
+ --gemina-chat-accent: #2f6fed;
80
+ --gemina-chat-accent-fg: #ffffff;
81
+ --gemina-chat-assistant-bg: #f2f4f7;
82
+ --gemina-chat-assistant-fg: #1a1d21;
83
+ --gemina-chat-muted: #667085;
84
+ --gemina-chat-error: #b42318;
85
+ --gemina-chat-low-confidence: #b54708;
86
+ --gemina-chat-radius: 10px;
87
+ --gemina-chat-font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
88
+
89
+ box-sizing: border-box;
90
+ display: flex;
91
+ flex-direction: column;
92
+ min-height: 320px;
93
+ max-height: 600px;
94
+ background: var(--gemina-chat-bg);
95
+ color: var(--gemina-chat-fg);
96
+ border: 1px solid var(--gemina-chat-border);
97
+ border-radius: var(--gemina-chat-radius);
98
+ font-family: var(--gemina-chat-font);
99
+ font-size: 14px;
100
+ line-height: 1.5;
101
+ }
102
+ .gemina-chat *, .gemina-chat *::before, .gemina-chat *::after { box-sizing: border-box; }
103
+ .gemina-chat--dark { ${DARK_VARS} }
104
+ @media (prefers-color-scheme: dark) {
105
+ .gemina-chat--auto { ${DARK_VARS} }
106
+ }
107
+ .gemina-chat__log {
108
+ flex: 1;
109
+ overflow-y: auto;
110
+ padding: 12px;
111
+ display: flex;
112
+ flex-direction: column;
113
+ gap: 8px;
114
+ }
115
+ .gemina-chat__msg {
116
+ max-width: 85%;
117
+ padding: 8px 12px;
118
+ border-radius: var(--gemina-chat-radius);
119
+ white-space: pre-wrap;
120
+ overflow-wrap: break-word;
121
+ }
122
+ .gemina-chat__msg--user {
123
+ align-self: flex-end;
124
+ background: var(--gemina-chat-accent);
125
+ color: var(--gemina-chat-accent-fg);
126
+ }
127
+ .gemina-chat--rtl .gemina-chat__msg--user, .gemina-chat[dir="rtl"] .gemina-chat__msg--user {
128
+ align-self: flex-start;
129
+ }
130
+ .gemina-chat--rtl .gemina-chat__msg--assistant, .gemina-chat[dir="rtl"] .gemina-chat__msg--assistant {
131
+ align-self: flex-end;
132
+ }
133
+ .gemina-chat__msg--assistant {
134
+ align-self: flex-start;
135
+ background: var(--gemina-chat-assistant-bg);
136
+ color: var(--gemina-chat-assistant-fg);
137
+ }
138
+ .gemina-chat__msg--low-confidence {
139
+ border: 1px dashed var(--gemina-chat-low-confidence);
140
+ }
141
+ .gemina-chat__low-confidence-note {
142
+ margin-top: 6px;
143
+ font-size: 12px;
144
+ color: var(--gemina-chat-low-confidence);
145
+ }
146
+ .gemina-chat__citations {
147
+ display: flex;
148
+ flex-wrap: wrap;
149
+ gap: 4px;
150
+ margin-top: 6px;
151
+ }
152
+ .gemina-chat__citation {
153
+ font: inherit;
154
+ font-size: 12px;
155
+ padding: 2px 8px;
156
+ border-radius: 999px;
157
+ border: 1px solid var(--gemina-chat-border);
158
+ background: transparent;
159
+ color: var(--gemina-chat-accent);
160
+ cursor: pointer;
161
+ }
162
+ .gemina-chat__citation:hover { border-color: var(--gemina-chat-accent); }
163
+ .gemina-chat__msg--error {
164
+ align-self: flex-start;
165
+ background: transparent;
166
+ border: 1px solid var(--gemina-chat-error);
167
+ color: var(--gemina-chat-error);
168
+ }
169
+ .gemina-chat__retry {
170
+ font: inherit;
171
+ font-size: 12px;
172
+ margin-top: 6px;
173
+ display: block;
174
+ padding: 2px 10px;
175
+ border-radius: var(--gemina-chat-radius);
176
+ border: 1px solid var(--gemina-chat-error);
177
+ background: transparent;
178
+ color: var(--gemina-chat-error);
179
+ cursor: pointer;
180
+ }
181
+ .gemina-chat__typing {
182
+ align-self: flex-start;
183
+ color: var(--gemina-chat-muted);
184
+ font-size: 12px;
185
+ padding: 0 4px;
186
+ }
187
+ .gemina-chat__composer {
188
+ display: flex;
189
+ gap: 8px;
190
+ padding: 10px;
191
+ border-top: 1px solid var(--gemina-chat-border);
192
+ }
193
+ .gemina-chat__input {
194
+ flex: 1;
195
+ resize: none;
196
+ font: inherit;
197
+ color: inherit;
198
+ background: transparent;
199
+ border: 1px solid var(--gemina-chat-border);
200
+ border-radius: var(--gemina-chat-radius);
201
+ padding: 8px 10px;
202
+ min-height: 38px;
203
+ }
204
+ .gemina-chat__input:focus {
205
+ outline: 2px solid var(--gemina-chat-accent);
206
+ outline-offset: -1px;
207
+ }
208
+ .gemina-chat__send {
209
+ font: inherit;
210
+ align-self: flex-end;
211
+ border: none;
212
+ border-radius: var(--gemina-chat-radius);
213
+ background: var(--gemina-chat-accent);
214
+ color: var(--gemina-chat-accent-fg);
215
+ padding: 8px 16px;
216
+ cursor: pointer;
217
+ }
218
+ .gemina-chat__send:disabled { opacity: 0.5; cursor: default; }
219
+ `;
220
+ var STYLE_ATTR = "data-gemina-chat";
221
+ function ensureStylesInjected() {
222
+ if (typeof document === "undefined") {
223
+ return;
224
+ }
225
+ if (document.head.querySelector(`style[${STYLE_ATTR}]`) !== null) {
226
+ return;
227
+ }
228
+ const style = document.createElement("style");
229
+ style.setAttribute(STYLE_ATTR, VERSION);
230
+ style.textContent = CHAT_CSS;
231
+ document.head.appendChild(style);
232
+ }
233
+ function GeminaChat(props) {
234
+ const {
235
+ tokenManager,
236
+ baseUrl,
237
+ endUserId,
238
+ theme = "auto",
239
+ dir = "auto",
240
+ placeholder = "Ask about your documents\u2026",
241
+ onCitationClick,
242
+ className
243
+ } = props;
244
+ const [messages, setMessages] = (0, import_react.useState)([]);
245
+ const [draft, setDraft] = (0, import_react.useState)("");
246
+ const [busy, setBusy] = (0, import_react.useState)(false);
247
+ const nextIdRef = (0, import_react.useRef)(0);
248
+ const mountedRef = (0, import_react.useRef)(false);
249
+ const logRef = (0, import_react.useRef)(null);
250
+ (0, import_react.useEffect)(() => {
251
+ mountedRef.current = true;
252
+ ensureStylesInjected();
253
+ return () => {
254
+ mountedRef.current = false;
255
+ };
256
+ }, []);
257
+ (0, import_react.useEffect)(() => {
258
+ const log = logRef.current;
259
+ if (log !== null) {
260
+ log.scrollTop = log.scrollHeight;
261
+ }
262
+ }, [messages, busy]);
263
+ const appendMessage = (0, import_react.useCallback)((message) => {
264
+ const id = nextIdRef.current++;
265
+ setMessages((prev) => [...prev, { ...message, id }]);
266
+ }, []);
267
+ const chatOnce = (0, import_react.useCallback)(
268
+ (token, message) => {
269
+ const client = import_sdk.GeminaClient.withSessionToken(token, baseUrl);
270
+ return client.chat.chatQuery({ chatQueryInDTO: { message, endUserId } });
271
+ },
272
+ [baseUrl, endUserId]
273
+ );
274
+ const queryWithRetry = (0, import_react.useCallback)(
275
+ async (message) => {
276
+ const token = await tokenManager.getToken();
277
+ try {
278
+ return await chatOnce(token, message);
279
+ } catch (error) {
280
+ if (httpStatus(error) !== 401) {
281
+ throw error;
282
+ }
283
+ tokenManager.invalidate();
284
+ const freshToken = await tokenManager.getToken();
285
+ return await chatOnce(freshToken, message);
286
+ }
287
+ },
288
+ [tokenManager, chatOnce]
289
+ );
290
+ const performSend = (0, import_react.useCallback)(
291
+ async (text) => {
292
+ setBusy(true);
293
+ try {
294
+ const result = await queryWithRetry(text);
295
+ if (!mountedRef.current) {
296
+ return;
297
+ }
298
+ appendMessage({
299
+ role: "assistant",
300
+ text: result.answer,
301
+ citations: normalizeCitations(result.citations),
302
+ confident: result.confident !== false
303
+ });
304
+ } catch (error) {
305
+ if (!mountedRef.current) {
306
+ return;
307
+ }
308
+ const status = httpStatus(error);
309
+ if (status === 401) {
310
+ appendMessage({ role: "error", text: SESSION_EXPIRED_TEXT });
311
+ } else if (status === 429) {
312
+ appendMessage({ role: "error", text: RATE_LIMIT_TEXT });
313
+ } else if (status === 402 || status === 403) {
314
+ appendMessage({ role: "error", text: PLAN_GATE_TEXT });
315
+ } else {
316
+ appendMessage({ role: "error", text: GENERIC_ERROR_TEXT, retryText: text });
317
+ }
318
+ } finally {
319
+ if (mountedRef.current) {
320
+ setBusy(false);
321
+ }
322
+ }
323
+ },
324
+ [queryWithRetry, appendMessage]
325
+ );
326
+ const submitDraft = (0, import_react.useCallback)(() => {
327
+ const text = draft.trim();
328
+ if (text.length === 0 || busy) {
329
+ return;
330
+ }
331
+ setDraft("");
332
+ appendMessage({ role: "user", text });
333
+ void performSend(text);
334
+ }, [draft, busy, appendMessage, performSend]);
335
+ const retryMessage = (0, import_react.useCallback)(
336
+ (failed) => {
337
+ if (busy || failed.retryText === void 0) {
338
+ return;
339
+ }
340
+ const text = failed.retryText;
341
+ setMessages((prev) => prev.filter((message) => message.id !== failed.id));
342
+ void performSend(text);
343
+ },
344
+ [busy, performSend]
345
+ );
346
+ const handleKeyDown = (0, import_react.useCallback)(
347
+ (event) => {
348
+ if (event.key === "Enter" && !event.shiftKey) {
349
+ event.preventDefault();
350
+ submitDraft();
351
+ }
352
+ },
353
+ [submitDraft]
354
+ );
355
+ const handleSubmit = (0, import_react.useCallback)(
356
+ (event) => {
357
+ event.preventDefault();
358
+ submitDraft();
359
+ },
360
+ [submitDraft]
361
+ );
362
+ let effectiveDir;
363
+ if (dir === "auto") {
364
+ let lastUserText = "";
365
+ for (let i = messages.length - 1; i >= 0; i--) {
366
+ const message = messages[i];
367
+ if (message !== void 0 && message.role === "user") {
368
+ lastUserText = message.text;
369
+ break;
370
+ }
371
+ }
372
+ effectiveDir = HEBREW_RE.test(lastUserText) ? "rtl" : "ltr";
373
+ } else {
374
+ effectiveDir = dir;
375
+ }
376
+ const bubbleDir = dir === "auto" ? "auto" : void 0;
377
+ const rootClassName = [
378
+ "gemina-chat",
379
+ `gemina-chat--${theme}`,
380
+ effectiveDir === "rtl" ? "gemina-chat--rtl" : "",
381
+ className ?? ""
382
+ ].filter((part) => part.length > 0).join(" ");
383
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: rootClassName, dir: effectiveDir, children: [
384
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
385
+ "div",
386
+ {
387
+ ref: logRef,
388
+ role: "log",
389
+ "aria-live": "polite",
390
+ "aria-busy": busy,
391
+ "aria-label": "Chat messages",
392
+ className: "gemina-chat__log",
393
+ children: [
394
+ messages.map((message) => {
395
+ if (message.role === "user") {
396
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
397
+ "div",
398
+ {
399
+ className: "gemina-chat__msg gemina-chat__msg--user",
400
+ dir: bubbleDir,
401
+ children: message.text
402
+ },
403
+ message.id
404
+ );
405
+ }
406
+ if (message.role === "assistant") {
407
+ const lowConfidence = !message.confident;
408
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
409
+ "div",
410
+ {
411
+ className: "gemina-chat__msg gemina-chat__msg--assistant" + (lowConfidence ? " gemina-chat__msg--low-confidence" : ""),
412
+ dir: bubbleDir,
413
+ children: [
414
+ message.text,
415
+ lowConfidence && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "gemina-chat__low-confidence-note", children: "Low confidence \u2014 please verify against the cited documents." }),
416
+ message.citations.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "gemina-chat__citations", children: message.citations.map((documentId, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
417
+ "button",
418
+ {
419
+ type: "button",
420
+ className: "gemina-chat__citation",
421
+ title: `Open document ${documentId}`,
422
+ onClick: () => onCitationClick?.(documentId),
423
+ children: documentId
424
+ },
425
+ `${documentId}-${index}`
426
+ )) })
427
+ ]
428
+ },
429
+ message.id
430
+ );
431
+ }
432
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
433
+ "div",
434
+ {
435
+ role: "alert",
436
+ className: "gemina-chat__msg gemina-chat__msg--error",
437
+ children: [
438
+ message.text,
439
+ message.retryText !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
440
+ "button",
441
+ {
442
+ type: "button",
443
+ className: "gemina-chat__retry",
444
+ onClick: () => retryMessage(message),
445
+ children: "Retry"
446
+ }
447
+ )
448
+ ]
449
+ },
450
+ message.id
451
+ );
452
+ }),
453
+ busy && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "gemina-chat__typing", children: "Thinking\u2026" })
454
+ ]
455
+ }
456
+ ),
457
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("form", { className: "gemina-chat__composer", onSubmit: handleSubmit, children: [
458
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
459
+ "textarea",
460
+ {
461
+ className: "gemina-chat__input",
462
+ "aria-label": "Chat message",
463
+ rows: 1,
464
+ value: draft,
465
+ placeholder,
466
+ dir: bubbleDir,
467
+ onChange: (event) => setDraft(event.target.value),
468
+ onKeyDown: handleKeyDown
469
+ }
470
+ ),
471
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
472
+ "button",
473
+ {
474
+ type: "submit",
475
+ className: "gemina-chat__send",
476
+ "aria-label": "Send message",
477
+ disabled: busy || draft.trim().length === 0,
478
+ children: "Send"
479
+ }
480
+ )
481
+ ] })
482
+ ] });
483
+ }
484
+ // Annotate the CommonJS export names for ESM import in node:
485
+ 0 && (module.exports = {
486
+ GeminaChat
487
+ });
488
+ //# sourceMappingURL=chat.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/chat.tsx","../src/version.ts"],"sourcesContent":["/**\n * <GeminaChat> — drop-in chat UI over Gemina Document Intelligence.\n *\n * Auth flows exclusively through a {@link GeminaTokenManager}: the component\n * asks it for a short-lived session token per turn and calls\n * `POST /v1/chat/query` through `@gemina/sdk`. It never sees — and cannot\n * accept — a Gemina API key (the token manager throws on API-key-shaped\n * credentials).\n *\n * SSR-safe: no `window`/`document` access at import time; styles are\n * injected on mount.\n */\nimport { useCallback, useEffect, useRef, useState } from 'react';\nimport type * as React from 'react';\nimport { GeminaClient } from '@gemina/sdk';\nimport type { ChatQueryOutDTO } from '@gemina/sdk';\nimport type { GeminaTokenManager } from './token-manager';\nimport { VERSION } from './version';\n\n/** Visual theme. `\"auto\"` follows `prefers-color-scheme`. */\nexport type GeminaChatTheme = 'light' | 'dark' | 'auto';\n\n/**\n * Text direction. `\"auto\"` flips the widget to RTL when the user's latest\n * message contains Hebrew, and lets each bubble resolve its own direction.\n */\nexport type GeminaChatDirection = 'ltr' | 'rtl' | 'auto';\n\nexport interface GeminaChatProps {\n /** Token source. Required — see {@link GeminaTokenManager}. */\n tokenManager: GeminaTokenManager;\n /** Gemina API base URL (default `https://api.gemina.co`). */\n baseUrl?: string;\n /**\n * Optional end-user id forwarded with each query. On the session-token\n * path the token's SIGNED scope always wins server-side — this is a\n * hint, not a security control.\n */\n endUserId?: string;\n /** Visual theme (default `\"auto\"`). */\n theme?: GeminaChatTheme;\n /** Text direction (default `\"auto\"`). */\n dir?: GeminaChatDirection;\n /** Input placeholder text. */\n placeholder?: string;\n /** Called with the cited `documentId` when a citation chip is clicked. */\n onCitationClick?: (documentId: string) => void;\n /** Extra class name(s) for the root element (e.g. to override CSS vars). */\n className?: string;\n}\n\ninterface UserMessage {\n id: number;\n role: 'user';\n text: string;\n}\n\ninterface AssistantMessage {\n id: number;\n role: 'assistant';\n text: string;\n citations: string[];\n confident: boolean;\n}\n\ninterface ErrorMessage {\n id: number;\n role: 'error';\n text: string;\n /** Present only when a retry is offered; holds the original user text. */\n retryText?: string;\n}\n\ntype ChatMessage = UserMessage | AssistantMessage | ErrorMessage;\n\n/** `Omit` that distributes over each member of a union. */\ntype DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;\n\ntype ChatMessageInput = DistributiveOmit<ChatMessage, 'id'>;\n\n/** Hebrew Unicode block (U+0590–U+05FF). */\nconst HEBREW_RE = /[\\u0590-\\u05FF]/;\n\n/**\n * Extract an HTTP status from a thrown value by shape rather than\n * `instanceof ResponseError` — robust against duplicated `@gemina/sdk`\n * copies in a bundle (class identity is not shared across copies).\n */\nfunction httpStatus(error: unknown): number | undefined {\n if (error !== null && typeof error === 'object' && 'response' in error) {\n const response = (error as { response?: unknown }).response;\n if (\n response !== null &&\n typeof response === 'object' &&\n typeof (response as { status?: unknown }).status === 'number'\n ) {\n return (response as { status: number }).status;\n }\n }\n return undefined;\n}\n\nconst SESSION_EXPIRED_TEXT = 'Session expired — please reload the page or sign in again.';\nconst RATE_LIMIT_TEXT = \"You're sending messages too quickly — try again shortly.\";\nconst PLAN_GATE_TEXT = \"Document Intelligence isn't enabled on this plan.\";\nconst GENERIC_ERROR_TEXT = \"Something went wrong and your message wasn't answered.\";\n\n/**\n * The API reports citations as an array of `documentId` strings; normalize\n * defensively so `{ documentId }` objects also work if the shape evolves.\n */\nfunction normalizeCitations(citations: unknown): string[] {\n if (!Array.isArray(citations)) {\n return [];\n }\n const ids: string[] = [];\n for (const item of citations) {\n if (typeof item === 'string' && item.length > 0) {\n ids.push(item);\n } else if (\n item !== null &&\n typeof item === 'object' &&\n typeof (item as { documentId?: unknown }).documentId === 'string'\n ) {\n ids.push((item as { documentId: string }).documentId);\n }\n }\n return ids;\n}\n\n// --- Styles -----------------------------------------------------------------\n// Hand-rolled, no UI deps. Everything is scoped under .gemina-chat and driven\n// by CSS custom properties so host apps can re-theme without touching the DOM.\n\nconst DARK_VARS = `\n --gemina-chat-bg: #101418;\n --gemina-chat-fg: #e6e9ee;\n --gemina-chat-border: #2a323c;\n --gemina-chat-accent: #4c8dff;\n --gemina-chat-accent-fg: #ffffff;\n --gemina-chat-assistant-bg: #1c232b;\n --gemina-chat-assistant-fg: #e6e9ee;\n --gemina-chat-muted: #98a2b3;\n --gemina-chat-error: #f97066;\n --gemina-chat-low-confidence: #f7b27a;\n`;\n\nconst CHAT_CSS = `\n.gemina-chat {\n --gemina-chat-bg: #ffffff;\n --gemina-chat-fg: #1a1d21;\n --gemina-chat-border: #d9dce1;\n --gemina-chat-accent: #2f6fed;\n --gemina-chat-accent-fg: #ffffff;\n --gemina-chat-assistant-bg: #f2f4f7;\n --gemina-chat-assistant-fg: #1a1d21;\n --gemina-chat-muted: #667085;\n --gemina-chat-error: #b42318;\n --gemina-chat-low-confidence: #b54708;\n --gemina-chat-radius: 10px;\n --gemina-chat-font: system-ui, -apple-system, \"Segoe UI\", Roboto, sans-serif;\n\n box-sizing: border-box;\n display: flex;\n flex-direction: column;\n min-height: 320px;\n max-height: 600px;\n background: var(--gemina-chat-bg);\n color: var(--gemina-chat-fg);\n border: 1px solid var(--gemina-chat-border);\n border-radius: var(--gemina-chat-radius);\n font-family: var(--gemina-chat-font);\n font-size: 14px;\n line-height: 1.5;\n}\n.gemina-chat *, .gemina-chat *::before, .gemina-chat *::after { box-sizing: border-box; }\n.gemina-chat--dark { ${DARK_VARS} }\n@media (prefers-color-scheme: dark) {\n .gemina-chat--auto { ${DARK_VARS} }\n}\n.gemina-chat__log {\n flex: 1;\n overflow-y: auto;\n padding: 12px;\n display: flex;\n flex-direction: column;\n gap: 8px;\n}\n.gemina-chat__msg {\n max-width: 85%;\n padding: 8px 12px;\n border-radius: var(--gemina-chat-radius);\n white-space: pre-wrap;\n overflow-wrap: break-word;\n}\n.gemina-chat__msg--user {\n align-self: flex-end;\n background: var(--gemina-chat-accent);\n color: var(--gemina-chat-accent-fg);\n}\n.gemina-chat--rtl .gemina-chat__msg--user, .gemina-chat[dir=\"rtl\"] .gemina-chat__msg--user {\n align-self: flex-start;\n}\n.gemina-chat--rtl .gemina-chat__msg--assistant, .gemina-chat[dir=\"rtl\"] .gemina-chat__msg--assistant {\n align-self: flex-end;\n}\n.gemina-chat__msg--assistant {\n align-self: flex-start;\n background: var(--gemina-chat-assistant-bg);\n color: var(--gemina-chat-assistant-fg);\n}\n.gemina-chat__msg--low-confidence {\n border: 1px dashed var(--gemina-chat-low-confidence);\n}\n.gemina-chat__low-confidence-note {\n margin-top: 6px;\n font-size: 12px;\n color: var(--gemina-chat-low-confidence);\n}\n.gemina-chat__citations {\n display: flex;\n flex-wrap: wrap;\n gap: 4px;\n margin-top: 6px;\n}\n.gemina-chat__citation {\n font: inherit;\n font-size: 12px;\n padding: 2px 8px;\n border-radius: 999px;\n border: 1px solid var(--gemina-chat-border);\n background: transparent;\n color: var(--gemina-chat-accent);\n cursor: pointer;\n}\n.gemina-chat__citation:hover { border-color: var(--gemina-chat-accent); }\n.gemina-chat__msg--error {\n align-self: flex-start;\n background: transparent;\n border: 1px solid var(--gemina-chat-error);\n color: var(--gemina-chat-error);\n}\n.gemina-chat__retry {\n font: inherit;\n font-size: 12px;\n margin-top: 6px;\n display: block;\n padding: 2px 10px;\n border-radius: var(--gemina-chat-radius);\n border: 1px solid var(--gemina-chat-error);\n background: transparent;\n color: var(--gemina-chat-error);\n cursor: pointer;\n}\n.gemina-chat__typing {\n align-self: flex-start;\n color: var(--gemina-chat-muted);\n font-size: 12px;\n padding: 0 4px;\n}\n.gemina-chat__composer {\n display: flex;\n gap: 8px;\n padding: 10px;\n border-top: 1px solid var(--gemina-chat-border);\n}\n.gemina-chat__input {\n flex: 1;\n resize: none;\n font: inherit;\n color: inherit;\n background: transparent;\n border: 1px solid var(--gemina-chat-border);\n border-radius: var(--gemina-chat-radius);\n padding: 8px 10px;\n min-height: 38px;\n}\n.gemina-chat__input:focus {\n outline: 2px solid var(--gemina-chat-accent);\n outline-offset: -1px;\n}\n.gemina-chat__send {\n font: inherit;\n align-self: flex-end;\n border: none;\n border-radius: var(--gemina-chat-radius);\n background: var(--gemina-chat-accent);\n color: var(--gemina-chat-accent-fg);\n padding: 8px 16px;\n cursor: pointer;\n}\n.gemina-chat__send:disabled { opacity: 0.5; cursor: default; }\n`;\n\nconst STYLE_ATTR = 'data-gemina-chat';\n\n/**\n * Inject the widget stylesheet once per document (idempotent across\n * instances; intentionally not removed on unmount so sibling instances and\n * quick remounts never flash unstyled).\n */\nfunction ensureStylesInjected(): void {\n if (typeof document === 'undefined') {\n return;\n }\n if (document.head.querySelector(`style[${STYLE_ATTR}]`) !== null) {\n return;\n }\n const style = document.createElement('style');\n style.setAttribute(STYLE_ATTR, VERSION);\n style.textContent = CHAT_CSS;\n document.head.appendChild(style);\n}\n\n/**\n * Embeddable Gemina Document Intelligence chat.\n *\n * ```tsx\n * <GeminaChat\n * tokenManager={tokenManager}\n * onCitationClick={(documentId) => openDocument(documentId)}\n * />\n * ```\n */\nexport function GeminaChat(props: GeminaChatProps): React.JSX.Element {\n const {\n tokenManager,\n baseUrl,\n endUserId,\n theme = 'auto',\n dir = 'auto',\n placeholder = 'Ask about your documents…',\n onCitationClick,\n className,\n } = props;\n\n const [messages, setMessages] = useState<ChatMessage[]>([]);\n const [draft, setDraft] = useState('');\n const [busy, setBusy] = useState(false);\n const nextIdRef = useRef(0);\n const mountedRef = useRef(false);\n const logRef = useRef<HTMLDivElement | null>(null);\n\n useEffect(() => {\n mountedRef.current = true;\n ensureStylesInjected();\n return () => {\n mountedRef.current = false;\n };\n }, []);\n\n // Keep the newest message in view.\n useEffect(() => {\n const log = logRef.current;\n if (log !== null) {\n log.scrollTop = log.scrollHeight;\n }\n }, [messages, busy]);\n\n const appendMessage = useCallback((message: ChatMessageInput) => {\n const id = nextIdRef.current++;\n setMessages((prev) => [...prev, { ...message, id }]);\n }, []);\n\n const chatOnce = useCallback(\n (token: string, message: string): Promise<ChatQueryOutDTO> => {\n const client = GeminaClient.withSessionToken(token, baseUrl);\n return client.chat.chatQuery({ chatQueryInDTO: { message, endUserId } });\n },\n [baseUrl, endUserId],\n );\n\n /** One turn, with the mandated 401-invalidate-retry-once behavior. */\n const queryWithRetry = useCallback(\n async (message: string): Promise<ChatQueryOutDTO> => {\n const token = await tokenManager.getToken();\n try {\n return await chatOnce(token, message);\n } catch (error) {\n if (httpStatus(error) !== 401) {\n throw error;\n }\n // Token likely expired mid-session: drop it, re-mint via the\n // tenant backend, retry exactly once. A second 401 propagates.\n tokenManager.invalidate();\n const freshToken = await tokenManager.getToken();\n return await chatOnce(freshToken, message);\n }\n },\n [tokenManager, chatOnce],\n );\n\n const performSend = useCallback(\n async (text: string) => {\n setBusy(true);\n try {\n const result = await queryWithRetry(text);\n if (!mountedRef.current) {\n return;\n }\n appendMessage({\n role: 'assistant',\n text: result.answer,\n citations: normalizeCitations(result.citations),\n confident: result.confident !== false,\n });\n } catch (error) {\n if (!mountedRef.current) {\n return;\n }\n const status = httpStatus(error);\n if (status === 401) {\n appendMessage({ role: 'error', text: SESSION_EXPIRED_TEXT });\n } else if (status === 429) {\n appendMessage({ role: 'error', text: RATE_LIMIT_TEXT });\n } else if (status === 402 || status === 403) {\n appendMessage({ role: 'error', text: PLAN_GATE_TEXT });\n } else {\n appendMessage({ role: 'error', text: GENERIC_ERROR_TEXT, retryText: text });\n }\n } finally {\n if (mountedRef.current) {\n setBusy(false);\n }\n }\n },\n [queryWithRetry, appendMessage],\n );\n\n const submitDraft = useCallback(() => {\n const text = draft.trim();\n if (text.length === 0 || busy) {\n return;\n }\n setDraft('');\n appendMessage({ role: 'user', text });\n void performSend(text);\n }, [draft, busy, appendMessage, performSend]);\n\n const retryMessage = useCallback(\n (failed: ErrorMessage) => {\n if (busy || failed.retryText === undefined) {\n return;\n }\n const text = failed.retryText;\n // Replace the error entry; the original user bubble is still there.\n setMessages((prev) => prev.filter((message) => message.id !== failed.id));\n void performSend(text);\n },\n [busy, performSend],\n );\n\n const handleKeyDown = useCallback(\n (event: React.KeyboardEvent<HTMLTextAreaElement>) => {\n if (event.key === 'Enter' && !event.shiftKey) {\n event.preventDefault();\n submitDraft();\n }\n },\n [submitDraft],\n );\n\n const handleSubmit = useCallback(\n (event: React.FormEvent<HTMLFormElement>) => {\n event.preventDefault();\n submitDraft();\n },\n [submitDraft],\n );\n\n // dir=\"auto\": follow the user's latest message (Hebrew → RTL); individual\n // bubbles additionally resolve their own direction via dir=\"auto\".\n let effectiveDir: 'ltr' | 'rtl';\n if (dir === 'auto') {\n let lastUserText = '';\n for (let i = messages.length - 1; i >= 0; i--) {\n const message = messages[i];\n if (message !== undefined && message.role === 'user') {\n lastUserText = message.text;\n break;\n }\n }\n effectiveDir = HEBREW_RE.test(lastUserText) ? 'rtl' : 'ltr';\n } else {\n effectiveDir = dir;\n }\n const bubbleDir = dir === 'auto' ? 'auto' : undefined;\n\n const rootClassName = [\n 'gemina-chat',\n `gemina-chat--${theme}`,\n effectiveDir === 'rtl' ? 'gemina-chat--rtl' : '',\n className ?? '',\n ]\n .filter((part) => part.length > 0)\n .join(' ');\n\n return (\n <div className={rootClassName} dir={effectiveDir}>\n <div\n ref={logRef}\n role=\"log\"\n aria-live=\"polite\"\n aria-busy={busy}\n aria-label=\"Chat messages\"\n className=\"gemina-chat__log\"\n >\n {messages.map((message) => {\n if (message.role === 'user') {\n return (\n <div\n key={message.id}\n className=\"gemina-chat__msg gemina-chat__msg--user\"\n dir={bubbleDir}\n >\n {message.text}\n </div>\n );\n }\n if (message.role === 'assistant') {\n const lowConfidence = !message.confident;\n return (\n <div\n key={message.id}\n className={\n 'gemina-chat__msg gemina-chat__msg--assistant' +\n (lowConfidence ? ' gemina-chat__msg--low-confidence' : '')\n }\n dir={bubbleDir}\n >\n {message.text}\n {lowConfidence && (\n <div className=\"gemina-chat__low-confidence-note\">\n Low confidence — please verify against the cited documents.\n </div>\n )}\n {message.citations.length > 0 && (\n <div className=\"gemina-chat__citations\">\n {message.citations.map((documentId, index) => (\n <button\n key={`${documentId}-${index}`}\n type=\"button\"\n className=\"gemina-chat__citation\"\n title={`Open document ${documentId}`}\n onClick={() => onCitationClick?.(documentId)}\n >\n {documentId}\n </button>\n ))}\n </div>\n )}\n </div>\n );\n }\n return (\n <div\n key={message.id}\n role=\"alert\"\n className=\"gemina-chat__msg gemina-chat__msg--error\"\n >\n {message.text}\n {message.retryText !== undefined && (\n <button\n type=\"button\"\n className=\"gemina-chat__retry\"\n onClick={() => retryMessage(message)}\n >\n Retry\n </button>\n )}\n </div>\n );\n })}\n {busy && <div className=\"gemina-chat__typing\">Thinking…</div>}\n </div>\n <form className=\"gemina-chat__composer\" onSubmit={handleSubmit}>\n <textarea\n className=\"gemina-chat__input\"\n aria-label=\"Chat message\"\n rows={1}\n value={draft}\n placeholder={placeholder}\n dir={bubbleDir}\n onChange={(event) => setDraft(event.target.value)}\n onKeyDown={handleKeyDown}\n />\n <button\n type=\"submit\"\n className=\"gemina-chat__send\"\n aria-label=\"Send message\"\n disabled={busy || draft.trim().length === 0}\n >\n Send\n </button>\n </form>\n </div>\n );\n}\n","/** Package version. Keep in sync with package.json. */\nexport const VERSION = '0.1.0';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAYA,mBAAyD;AAEzD,iBAA6B;;;ACbtB,IAAM,UAAU;;;AD6fT;AA7ad,IAAM,YAAY;AAOlB,SAAS,WAAW,OAAoC;AACtD,MAAI,UAAU,QAAQ,OAAO,UAAU,YAAY,cAAc,OAAO;AACtE,UAAM,WAAY,MAAiC;AACnD,QACE,aAAa,QACb,OAAO,aAAa,YACpB,OAAQ,SAAkC,WAAW,UACrD;AACA,aAAQ,SAAgC;AAAA,IAC1C;AAAA,EACF;AACA,SAAO;AACT;AAEA,IAAM,uBAAuB;AAC7B,IAAM,kBAAkB;AACxB,IAAM,iBAAiB;AACvB,IAAM,qBAAqB;AAM3B,SAAS,mBAAmB,WAA8B;AACxD,MAAI,CAAC,MAAM,QAAQ,SAAS,GAAG;AAC7B,WA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kB,UAAU;AAAA,wBAE1C;AAAA;AAAA,sBANI,GAAG,UAAU,IAAI,KAAK;AAAA,oBAO7B,CACD,GACH;AAAA;AAAA;AAAA,gBA1BG,QAAQ;AAAA,cA4Bf;AAAA,YAEJ;AACA,mBACE;AAAA,cAAC;AAAA;AAAA,gBAEC,MAAK;AAAA,gBACL,WAAU;AAAA,gBAET;AAAA,0BAAQ;AAAA,kBACR,QAAQ,cAAc,UACrB;AAAA,oBAAC;AAAA;AAAA,sBACC,MAAK;AAAA,sBACL,WAAU;AAAA,sBACV,SAAS,MAAM,aAAa,OAAO;AAAA,sBACpC;AAAA;AAAA,kBAED;AAAA;AAAA;AAAA,cAZG,QAAQ;AAAA,YAcf;AAAA,UAEJ,CAAC;AAAA,UACA,QAAQ,4CAAC,SAAI,WAAU,uBAAsB,4BAAS;AAAA;AAAA;AAAA,IACzD;AAAA,IACA,6CAAC,UAAK,WAAU,yBAAwB,UAAU,cAChD;AAAA;AAAA,QAAC;AAAA;AAAA,UACC,WAAU;AAAA,UACV,cAAW;AAAA,UACX,MAAM;AAAA,UACN,OAAO;AAAA,UACP;AAAA,UACA,KAAK;AAAA,UACL,UAAU,CAAC,UAAU,SAAS,MAAM,OAAO,KAAK;AAAA,UAChD,WAAW;AAAA;AAAA,MACb;AAAA,MACA;AAAA,QAAC;AAAA;AAAA,UACC,MAAK;AAAA,UACL,WAAU;AAAA,UACV,cAAW;AAAA,UACX,UAAU,QAAQ,MAAM,KAAK,EAAE,WAAW;AAAA,UAC3C;AAAA;AAAA,MAED;AAAA,OACF;AAAA,KACF;AAEJ;","names":[]}
@@ -0,0 +1,45 @@
1
+ import * as React from 'react';
2
+ import { GeminaTokenManager } from './token-manager.cjs';
3
+
4
+ /** Visual theme. `"auto"` follows `prefers-color-scheme`. */
5
+ type GeminaChatTheme = 'light' | 'dark' | 'auto';
6
+ /**
7
+ * Text direction. `"auto"` flips the widget to RTL when the user's latest
8
+ * message contains Hebrew, and lets each bubble resolve its own direction.
9
+ */
10
+ type GeminaChatDirection = 'ltr' | 'rtl' | 'auto';
11
+ interface GeminaChatProps {
12
+ /** Token source. Required — see {@link GeminaTokenManager}. */
13
+ tokenManager: GeminaTokenManager;
14
+ /** Gemina API base URL (default `https://api.gemina.co`). */
15
+ baseUrl?: string;
16
+ /**
17
+ * Optional end-user id forwarded with each query. On the session-token
18
+ * path the token's SIGNED scope always wins server-side — this is a
19
+ * hint, not a security control.
20
+ */
21
+ endUserId?: string;
22
+ /** Visual theme (default `"auto"`). */
23
+ theme?: GeminaChatTheme;
24
+ /** Text direction (default `"auto"`). */
25
+ dir?: GeminaChatDirection;
26
+ /** Input placeholder text. */
27
+ placeholder?: string;
28
+ /** Called with the cited `documentId` when a citation chip is clicked. */
29
+ onCitationClick?: (documentId: string) => void;
30
+ /** Extra class name(s) for the root element (e.g. to override CSS vars). */
31
+ className?: string;
32
+ }
33
+ /**
34
+ * Embeddable Gemina Document Intelligence chat.
35
+ *
36
+ * ```tsx
37
+ * <GeminaChat
38
+ * tokenManager={tokenManager}
39
+ * onCitationClick={(documentId) => openDocument(documentId)}
40
+ * />
41
+ * ```
42
+ */
43
+ declare function GeminaChat(props: GeminaChatProps): React.JSX.Element;
44
+
45
+ export { GeminaChat, type GeminaChatDirection, type GeminaChatProps, type GeminaChatTheme };
package/dist/chat.d.ts ADDED
@@ -0,0 +1,45 @@
1
+ import * as React from 'react';
2
+ import { GeminaTokenManager } from './token-manager.js';
3
+
4
+ /** Visual theme. `"auto"` follows `prefers-color-scheme`. */
5
+ type GeminaChatTheme = 'light' | 'dark' | 'auto';
6
+ /**
7
+ * Text direction. `"auto"` flips the widget to RTL when the user's latest
8
+ * message contains Hebrew, and lets each bubble resolve its own direction.
9
+ */
10
+ type GeminaChatDirection = 'ltr' | 'rtl' | 'auto';
11
+ interface GeminaChatProps {
12
+ /** Token source. Required — see {@link GeminaTokenManager}. */
13
+ tokenManager: GeminaTokenManager;
14
+ /** Gemina API base URL (default `https://api.gemina.co`). */
15
+ baseUrl?: string;
16
+ /**
17
+ * Optional end-user id forwarded with each query. On the session-token
18
+ * path the token's SIGNED scope always wins server-side — this is a
19
+ * hint, not a security control.
20
+ */
21
+ endUserId?: string;
22
+ /** Visual theme (default `"auto"`). */
23
+ theme?: GeminaChatTheme;
24
+ /** Text direction (default `"auto"`). */
25
+ dir?: GeminaChatDirection;
26
+ /** Input placeholder text. */
27
+ placeholder?: string;
28
+ /** Called with the cited `documentId` when a citation chip is clicked. */
29
+ onCitationClick?: (documentId: string) => void;
30
+ /** Extra class name(s) for the root element (e.g. to override CSS vars). */
31
+ className?: string;
32
+ }
33
+ /**
34
+ * Embeddable Gemina Document Intelligence chat.
35
+ *
36
+ * ```tsx
37
+ * <GeminaChat
38
+ * tokenManager={tokenManager}
39
+ * onCitationClick={(documentId) => openDocument(documentId)}
40
+ * />
41
+ * ```
42
+ */
43
+ declare function GeminaChat(props: GeminaChatProps): React.JSX.Element;
44
+
45
+ export { GeminaChat, type GeminaChatDirection, type GeminaChatProps, type GeminaChatTheme };
package/dist/chat.js ADDED
@@ -0,0 +1,7 @@
1
+ import {
2
+ GeminaChat
3
+ } from "./chunk-Q22PGVGS.js";
4
+ export {
5
+ GeminaChat
6
+ };
7
+ //# sourceMappingURL=chat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}