@kodaris/krubble-app-components 1.0.125 → 1.0.126

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.
@@ -3347,11 +3347,6 @@
3347
3347
  // --- Lifecycle ---
3348
3348
  connectedCallback() {
3349
3349
  super.connectedCallback();
3350
- // Capture the consumer's targeting BEFORE we default `load` below: a custom
3351
- // `load` or an explicitly-set `conversation-id` means the consumer owns which
3352
- // conversation shows, so the tab-scoped resume must not override it.
3353
- const usesBuiltInLoad = !this.load;
3354
- const consumerSetConversationId = this.conversationId != null;
3355
3350
  // Default to loading a conversation's messages when the consumer hasn't
3356
3351
  // provided their own `load`. With `conversationId` set we rebuild that
3357
3352
  // conversation; with none set the user wants a NEW conversation, so we start
@@ -3439,49 +3434,49 @@
3439
3434
  // most-recent one. The pinned id lives in sessionStorage (per-tab — unlike
3440
3435
  // localStorage it isn't shared across tabs, so two tabs can sit on different
3441
3436
  // conversations). We resolve the id FIRST, then run the built-in load so it
3442
- // rebuilds the right transcript. Skipped when the consumer owns targeting (a
3443
- // custom `load` or an explicit `conversation-id`) or in inline mode (embedded
3444
- // as a page — the host route, not the tab, decides the conversation).
3445
- const resolveConversationId = () => {
3446
- if (this.variant !== 'floating' || !usesBuiltInLoad || consumerSetConversationId) {
3447
- return Promise.resolve();
3448
- }
3437
+ // rebuilds the right transcript. Skipped when the consumer owns targeting (an
3438
+ // explicit `conversation-id`) or in inline mode (embedded as a page — the host
3439
+ // route, not the tab, decides the conversation).
3440
+ let resolveConversationId = Promise.resolve();
3441
+ if (this.variant === 'floating' && this.conversationId == null) {
3449
3442
  const stored = Number(sessionStorage.getItem('kr-chatbot-conversation-id'));
3450
3443
  if (stored > 0) {
3451
3444
  this.conversationId = stored;
3452
3445
  // Fetch the conversation so the header shows its title on reload (the
3453
3446
  // transcript load doesn't carry it). Best-effort — the header falls back
3454
3447
  // to the default label if this fails.
3455
- return krubbleHttp.Http.fetch({ url: `/api/system/conversation/${stored}` })
3448
+ resolveConversationId = krubbleHttp.Http.fetch({ url: `/api/system/conversation/${stored}` })
3456
3449
  .then((r) => r.json())
3457
3450
  .then((res) => {
3458
3451
  this._conversationTitle = res?.data?.title || '';
3459
3452
  })
3460
3453
  .catch(() => { });
3461
3454
  }
3462
- // Fresh tab, nothing pinned yet — resume the user's most recent conversation
3463
- // (404 when they have none, which leaves us blank for a new one).
3464
- return krubbleHttp.Http.fetch({ url: '/api/system/conversation/last' })
3465
- .then((r) => {
3466
- if (!r.ok) {
3467
- return;
3468
- }
3469
- return r.json().then((res) => {
3470
- const id = res?.data?.conversationID;
3471
- if (typeof id === 'number') {
3472
- this.conversationId = id;
3473
- this._conversationTitle = res?.data?.title || '';
3474
- this._persistConversationId();
3455
+ else {
3456
+ // Fresh tab, nothing pinned yet — resume the user's most recent conversation
3457
+ // (404 when they have none, which leaves us blank for a new one).
3458
+ resolveConversationId = krubbleHttp.Http.fetch({ url: '/api/system/conversation/last' })
3459
+ .then((r) => {
3460
+ if (!r.ok) {
3461
+ return;
3475
3462
  }
3476
- });
3477
- })
3478
- .catch(() => { });
3479
- };
3463
+ return r.json().then((res) => {
3464
+ const id = res?.data?.conversationID;
3465
+ if (typeof id === 'number') {
3466
+ this.conversationId = id;
3467
+ this._conversationTitle = res?.data?.title || '';
3468
+ this._persistConversationId();
3469
+ }
3470
+ });
3471
+ })
3472
+ .catch(() => { });
3473
+ }
3474
+ }
3480
3475
  // `this.load` is always set by here (defaulted above when the consumer didn't
3481
3476
  // supply one), so capture it for the async chain — TS can't narrow the nullable
3482
3477
  // property across the promise boundary.
3483
3478
  const load = this.load;
3484
- resolveConversationId().then(() => load()).then((messages) => {
3479
+ resolveConversationId.then(() => load()).then((messages) => {
3485
3480
  if (messages && messages.length) {
3486
3481
  this.messages = messages;
3487
3482
  }
@@ -3731,6 +3726,13 @@
3731
3726
  * embeds and custom-`load` consumers own their own targeting.
3732
3727
  */
3733
3728
  _persistConversationId() {
3729
+ // Floating-only: inline embeds (and custom-`load` consumers) own their own
3730
+ // targeting and never resume from this key, so they must not write it either —
3731
+ // otherwise an inline chat sharing the page/origin would clobber the floating
3732
+ // widget's pinned id.
3733
+ if (this.variant !== 'floating') {
3734
+ return;
3735
+ }
3734
3736
  try {
3735
3737
  if (this.conversationId != null) {
3736
3738
  sessionStorage.setItem('kr-chatbot-conversation-id', String(this.conversationId));