@gengage/assistant-fe 0.6.49 → 0.7.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 (51) hide show
  1. package/dist/chat/api.d.ts +1 -1
  2. package/dist/chat/components/ChatDrawer.d.ts +3 -1
  3. package/dist/chat/features/beauty-consulting/mode-controller.d.ts +1 -1
  4. package/dist/chat/features/beauty-consulting/stream-handler.d.ts +7 -1
  5. package/dist/chat/history-storage.d.ts +36 -4
  6. package/dist/chat/runtime.d.ts +73 -3
  7. package/dist/chat/utils/chat-presentation-debug.d.ts +0 -14
  8. package/dist/chat-runtime.js +1 -1
  9. package/dist/chat.iife.js +72 -72
  10. package/dist/chat.js +1 -1
  11. package/dist/common/connection-warning.d.ts +10 -0
  12. package/dist/common/indexed-db.d.ts +35 -2
  13. package/dist/common/native-webview.d.ts +1 -1
  14. package/dist/common/streaming.d.ts +6 -1
  15. package/dist/common/transport.d.ts +2 -1
  16. package/dist/common/types.d.ts +16 -0
  17. package/dist/{common-nAeMxZrn.js → common-CeuGSwJL.js} +61 -65
  18. package/dist/common.js +30 -30
  19. package/dist/{connection-warning-CDtUX-ol.js → connection-warning-C0e2byq5.js} +31 -25
  20. package/dist/{fastIntent-D45C2rEO.js → fastIntent-BI7l1oDv.js} +2 -2
  21. package/dist/global-error-toast-DvaKvPNA.js +798 -0
  22. package/dist/index.js +29 -29
  23. package/dist/native-webview-CHKpwixw.js +303 -0
  24. package/dist/native.iife.js +30 -30
  25. package/dist/native.js +1 -1
  26. package/dist/{overlay-BPZEIyo_.js → overlay-C3XzoSKd.js} +51 -32
  27. package/dist/overlay.js +6 -6
  28. package/dist/{price-formatter-CHUmYq8I.js → price-formatter-Q3wUKrl1.js} +2 -1
  29. package/dist/qna/runtime.d.ts +1 -0
  30. package/dist/qna-runtime.js +1 -1
  31. package/dist/qna.iife.js +32 -32
  32. package/dist/qna.js +1 -1
  33. package/dist/{request-response-cache-CGxwN0CV.js → request-response-cache-BLQy7llq.js} +478 -454
  34. package/dist/{runtime-CNlICVeC.js → runtime-BC8-a6Ql.js} +231 -219
  35. package/dist/runtime-BSIrZhF2.js +8889 -0
  36. package/dist/{runtime-Cg-6aUps.js → runtime-DiONTdBz.js} +230 -212
  37. package/dist/{simbut-BtaGMLLn.js → simbut-BDbb3nMH.js} +5 -5
  38. package/dist/simbut.iife.js +2 -2
  39. package/dist/simbut.js +1 -1
  40. package/dist/simrel/components/GroupTabs.d.ts +6 -0
  41. package/dist/simrel/runtime.d.ts +8 -0
  42. package/dist/{simrel-iGl2aXiY.js → simrel-CdxDIKu3.js} +15 -15
  43. package/dist/simrel-runtime.js +1 -1
  44. package/dist/simrel.iife.js +22 -22
  45. package/dist/simrel.js +2 -2
  46. package/dist/widget-base-Cvxdrqqt.js +141 -0
  47. package/package.json +1 -1
  48. package/dist/context-UTzCGyR9.js +0 -543
  49. package/dist/native-webview-CYX30O3Q.js +0 -273
  50. package/dist/runtime-COLQGOkl.js +0 -8708
  51. package/dist/widget-base-AuwRxs2X.js +0 -365
@@ -1,6 +1,6 @@
1
1
  import type { ChatTransportConfig } from '../common/api-paths.js';
2
2
  import type { ActionEnrichmentContext, ProcessActionRequest, StreamCallbacks } from '../common/transport.js';
3
- export type { ActionEnrichmentContext, BackendRequestMeta, InjectorAdapter, ProcessActionRequest, StreamCallbacks, } from '../common/transport.js';
3
+ export type { ActionEnrichmentContext, BackendRequestMeta, ProcessActionRequest, StreamCallbacks, } from '../common/transport.js';
4
4
  /**
5
5
  * Enriches action payloads with fields the backend expects.
6
6
  * Only adds fields that are not already present in the payload.
@@ -148,6 +148,7 @@ export declare class ChatDrawer {
148
148
  private _beautyPhotoStepEl;
149
149
  private _cartToastEl;
150
150
  private _cartToastTimerId;
151
+ private _dragCloseTimerId;
151
152
  private _renderPhotoAnalysisCard;
152
153
  private _createLegacyHeaderPoweredBy;
153
154
  private _createFooterAttribution;
@@ -326,7 +327,6 @@ export declare class ChatDrawer {
326
327
  private _createLoadingSequence;
327
328
  private _applyLoadingSteps;
328
329
  private _normalizeLoadingSteps;
329
- private _uniqueLoadingSteps;
330
330
  private _clearLoadingBindingInterval;
331
331
  private _destroyLoadingBinding;
332
332
  private _updateSendEnabled;
@@ -373,6 +373,8 @@ export declare class ChatDrawer {
373
373
  }>): void;
374
374
  /** Clear input-area chips. */
375
375
  clearInputAreaChips(): void;
376
+ /** Remove the active focus-trap keydown handler without restoring focus. */
377
+ private _detachTrapHandler;
376
378
  /** Activate focus trap — Tab/Shift+Tab cycles within the drawer. */
377
379
  trapFocus(): void;
378
380
  /** Release the focus trap and restore previously focused element. */
@@ -40,7 +40,7 @@ export declare class AssistantModeController {
40
40
  * Returns true if the mode actually switched.
41
41
  */
42
42
  handleRedirect(redirectPayload: unknown): boolean;
43
- /** Switch to a new assistant mode. */
43
+ /** Switch to a new assistant mode. No-op if already in that mode. */
44
44
  switchMode(mode: AssistantMode): void;
45
45
  /**
46
46
  * Derive mode and ui_hints from a backend CONTEXT panel payload.
@@ -30,7 +30,13 @@ export interface BeautyStreamContext {
30
30
  ensureRendered: () => void;
31
31
  cancelTypewriter: () => void;
32
32
  sendSkipMessage: () => void;
33
- streamDone: boolean;
33
+ /**
34
+ * Live getter for stream-completion state. Must be a getter (not a snapshot
35
+ * boolean) because the context is built early — while the stream is still
36
+ * open (streamDone === false) — but onSkip can fire after the stream finishes.
37
+ * A snapshot would always read false and silently drop the post-stream skip.
38
+ */
39
+ isStreamDone: () => boolean;
34
40
  }
35
41
  /**
36
42
  * Handle a beauty-specific UISpec component during stream processing.
@@ -1,4 +1,5 @@
1
1
  import type { BackendContext, UISpec } from '../common/types.js';
2
+ import type { GengageIndexedDB } from '../common/indexed-db.js';
2
3
  import type { ChatMessage } from './types.js';
3
4
  import type { PanelSource } from './panel-manager.js';
4
5
  type LegacyThumbnailEntry = {
@@ -72,18 +73,49 @@ export interface SaveHistorySessionParams {
72
73
  sku?: string | undefined;
73
74
  attachmentPlaceholder?: string | undefined;
74
75
  }
76
+ /**
77
+ * The chat-history archive (past chat sessions).
78
+ *
79
+ * Backed by IndexedDB so bulk history is NOT kept in the origin-shared
80
+ * localStorage. A lightweight index is hydrated into memory at init so the
81
+ * history panel can list sessions synchronously; full records are read lazily
82
+ * (async `loadSession`) and writes go through to IndexedDB behind a small mutex.
83
+ * Existing localStorage history is migrated into IndexedDB once, on `hydrate()`.
84
+ */
75
85
  export declare class ChatHistoryStorage {
76
86
  private readonly _appId;
77
87
  private readonly _userId;
78
- private readonly _storage;
88
+ private readonly _db;
89
+ private readonly _localStorage;
79
90
  private readonly _scope;
80
- constructor(_appId: string, _userId: string, _storage?: Storage | null);
91
+ /** Lightweight index, newest-first; the synchronous read surface. */
92
+ private _index;
93
+ private _hydrated;
94
+ /** Serializes write-through so concurrent saves/deletes don't race. */
95
+ private _writeChain;
96
+ constructor(_appId: string, _userId: string, _db: GengageIndexedDB | null, _localStorage?: Storage | null);
97
+ /**
98
+ * Migrate any legacy localStorage history into IndexedDB, then load the index
99
+ * into memory. Idempotent; safe to await once after the DB is open.
100
+ */
101
+ hydrate(): Promise<void>;
81
102
  createHistoryId(): string;
82
103
  findSessionId(sourceSessionId: string, createdAt: string): string | null;
83
104
  listSessions(): ChatHistoryIndexEntry[];
84
- loadSession(historyId: string): ChatHistorySessionRecord | null;
105
+ /** Resolves once all queued write-through operations have settled. */
106
+ flush(): Promise<void>;
107
+ loadSession(historyId: string): Promise<ChatHistorySessionRecord | null>;
108
+ /**
109
+ * Build and persist a history record. The record is built synchronously (it
110
+ * reads live panel DOM) and the in-memory index is updated synchronously so
111
+ * callers see it immediately; the IndexedDB write happens asynchronously
112
+ * behind the write mutex. Returns the built record, or null when there is
113
+ * nothing worth saving / no backing store.
114
+ */
85
115
  saveSession(params: SaveHistorySessionParams): ChatHistorySessionRecord | null;
86
116
  deleteSession(historyId: string): void;
87
- private _commitRecord;
117
+ /** Queue a best-effort IndexedDB write; failures are swallowed (persistence is best-effort). */
118
+ private _enqueueWrite;
119
+ private _migrateFromLocalStorage;
88
120
  }
89
121
  export {};
@@ -86,6 +86,22 @@ export declare class GengageChat extends BaseWidget<ChatWidgetConfig> {
86
86
  private _pdpLaunched;
87
87
  private _plpLaunched;
88
88
  private _homepageLaunched;
89
+ /**
90
+ * True ONLY when this widget actually restored a non-empty thread that now owns the
91
+ * surface. When set, the generic page-context auto-launch (homepage/PLP greeting) is
92
+ * suppressed so the restored thread — and its in-flight continuation — are not
93
+ * clobbered by a "Merhaba!" welcome. See R1 (yataş store-finder nav clobber).
94
+ *
95
+ * INVARIANT (regression #1 fix): this flag is tied to ACTUAL restored on-screen
96
+ * content, never to mere restore-KEY presence. If a restore no-ops (stale/missing
97
+ * session, cross-SKU guard, IDB absent, empty thread, rejected freshness token) the
98
+ * flag stays/returns false so the NORMAL greeting/auto-launch fires — the surface is
99
+ * never left blank.
100
+ */
101
+ private _restorePending;
102
+ /** One-shot gate for an assistant-driven soft navigation update in the same document. */
103
+ private _assistantSoftNavigationPending;
104
+ private _assistantSoftNavigationTimer;
89
105
  private _entryContextPrimed;
90
106
  /** True while a silent context-prime launch (PDP/PLP/homepage) is in flight. */
91
107
  private _contextPrimingInFlight;
@@ -177,6 +193,42 @@ export declare class GengageChat extends BaseWidget<ChatWidgetConfig> {
177
193
  }): void;
178
194
  close(): void;
179
195
  saveSession(sessionId: string, sku: string): void;
196
+ /**
197
+ * Set the restore handoff marker for an assistant-driven PAGE navigation that has
198
+ * no associated product (R1, e.g. the store-finder redirect). Mirrors saveSession()
199
+ * but without a SKU — the destination is not a PDP, so there is nothing to gate the
200
+ * restore on. The restore session id alone tells the re-mounted widget "the chat
201
+ * navigated you here; restore the thread and continue, do not auto-launch a greeting".
202
+ *
203
+ * Only stamps the marker when there is a real session id to restore; otherwise it is
204
+ * a no-op (a user/site navigation should stay a fresh session).
205
+ */
206
+ saveSessionForNavigation(): void;
207
+ /** Read the persisted same-document nav sequence (0 when absent/corrupt). */
208
+ private _readNavSeq;
209
+ /**
210
+ * Stamp the freshness token onto the current restore marker: bump the nav seq and
211
+ * record it (with a timestamp) so the immediately-following mount can recognize this
212
+ * marker as fresh. Best-effort — non-fatal if sessionStorage is unavailable.
213
+ */
214
+ private _stampRestoreFreshnessToken;
215
+ /**
216
+ * True when the current restore marker was produced by the immediately-preceding
217
+ * navigation (its token's seq matches the current nav seq). A stale/stranded marker
218
+ * — or one with no/corrupt token (e.g. an empty-SKU saveSession) — is NOT fresh.
219
+ */
220
+ private _isRestoreMarkerFresh;
221
+ /**
222
+ * Clear the restore marker and its freshness token in one place — the single
223
+ * guaranteed-consume point so a marker never strands. Called on mount (onInit, after
224
+ * the freshness decision) and on any state reset (_resetForNewPage / soft-nav).
225
+ * Leaves gengage_nav_seq intact: it is the monotonic clock, not part of the marker.
226
+ */
227
+ private _clearRestoreMarker;
228
+ private _markAssistantSoftNavigationPending;
229
+ private _clearAssistantSoftNavigationPending;
230
+ private _expireAssistantSoftNavigationIfUnclaimed;
231
+ private _scheduleAssistantSoftNavigationExpiry;
180
232
  get isOpen(): boolean;
181
233
  /**
182
234
  * Register a callback for integration events (e.g. 'gengage-cart-add', 'gengage-product-favorite').
@@ -262,6 +314,7 @@ export declare class GengageChat extends BaseWidget<ChatWidgetConfig> {
262
314
  private _flushQueuedUserMessages;
263
315
  /** Apply ui_hints from the backend CONTEXT event — delegates to mode controller. */
264
316
  private _applyUiHints;
317
+ /** Returns true if the redirect actually switched the assistant mode. */
265
318
  private _handleRedirectMetadata;
266
319
  private _sendAction;
267
320
  /** Return messages visible at the current thread cursor. */
@@ -318,11 +371,10 @@ export declare class GengageChat extends BaseWidget<ChatWidgetConfig> {
318
371
  private _productNumber;
319
372
  /** Rewind the conversation to the given thread. */
320
373
  private _rollbackToThread;
321
- private _persistHistoryToLocalStorage;
374
+ private _persistHistory;
322
375
  private _persistConversationState;
323
376
  private _persistConversationStateForNavigation;
324
377
  private _formatHistoryTimestamp;
325
- private _resolvePanelRestorePreviewLabel;
326
378
  private _resolveHistoryPreviewText;
327
379
  private _openHistoryPanel;
328
380
  private _buildHistoryPageEl;
@@ -339,11 +391,29 @@ export declare class GengageChat extends BaseWidget<ChatWidgetConfig> {
339
391
  private _hasUnavailableProductContext;
340
392
  private _ensureAssistantMessageRendered;
341
393
  private _saveSessionAndOpenURL;
394
+ /**
395
+ * Assistant-driven page navigation (R1): persist the thread, stamp the restore
396
+ * handoff marker, then navigate. On the SPA re-mount the widget restores the thread
397
+ * and continues its flow — the homepage/PLP auto-launch greeting is suppressed
398
+ * (see _restorePending / _primeOpenPageContext) so the assistant's answer is not
399
+ * clobbered by a generic welcome. Same-origin only; cross-origin/new-tab callers
400
+ * keep the raw navigation since the current page (and its thread) is not replaced.
401
+ *
402
+ * The restore-key stamp is the durable "the chat initiated this navigation" marker
403
+ * across the navigation boundary — we distinguish assistant-vs-user navigation by
404
+ * WHO called this (an assistant action handler), never by inspecting the URL.
405
+ */
406
+ private _navigateAssistantDriven;
342
407
  private _loadPayload;
343
408
  /**
344
409
  * Attempt to restore chat session from IndexedDB.
345
- * Always restores when IDB has session data for the current sessionId.
410
+ * Restores when IDB has non-empty session data for the current sessionId AND an
411
+ * explicit handoff is pending.
346
412
  * Best-effort — failures are silently ignored.
413
+ *
414
+ * @returns true ONLY when a non-empty thread was actually replayed onto the surface.
415
+ * Every no-op/early-return path returns false so the caller leaves the normal
416
+ * greeting/auto-launch enabled (regression #1: never suppress launch over nothing).
347
417
  */
348
418
  private _restoreFromIndexedDB;
349
419
  /**
@@ -1,18 +1,4 @@
1
1
  /**
2
2
  * Opt-in debug logging for chat presentation (query ?chat_debug=1 or localStorage gengage_chat_debug=1).
3
3
  */
4
- type Entry = {
5
- seq: number;
6
- time: string;
7
- scope: string;
8
- message: string;
9
- payload?: unknown;
10
- };
11
- declare global {
12
- interface Window {
13
- __gengageChatPresentationDebugLog?: Entry[];
14
- __gengageChatPresentationDebugSeq?: number;
15
- }
16
- }
17
4
  export declare function logChatPresentation(scope: string, message: string, payload?: unknown): void;
18
- export {};
@@ -1,4 +1,4 @@
1
- import { c as e, d as t, f as r, i as s, l as n, n as i, r as l, s as C, t as c, u as d } from "./runtime-COLQGOkl.js";
1
+ import { c as e, d as t, f as r, i as s, l as n, n as i, r as l, s as C, t as c, u as d } from "./runtime-BSIrZhF2.js";
2
2
  export {
3
3
  d as CHAT_SCROLL_ELEMENT_ID,
4
4
  s as ChatPresentationState,