@noodleseed/assistant 1.29.0 → 1.30.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/index.js CHANGED
@@ -2,9 +2,9 @@ import {
2
2
  ASSISTANT_TAG_NAME,
3
3
  NoodleAssistantElement,
4
4
  registerNoodleAssistant
5
- } from "./chunk-DOWFW3KA.js";
5
+ } from "./chunk-T4PS6P2W.js";
6
6
  import "./chunk-XKTUXFGX.js";
7
- import "./chunk-3VZ3M5BE.js";
7
+ import "./chunk-5EVZFPTD.js";
8
8
  import "./chunk-P223CYPO.js";
9
9
  import "./chunk-3YYTUJPJ.js";
10
10
  import "./chunk-5FUTL2UF.js";
@@ -23409,6 +23409,9 @@ function resolveSessionSource(options) {
23409
23409
  }
23410
23410
  return { kind: "exchange", url: sessionEndpoint };
23411
23411
  }
23412
+ function sessionSourceKey(options) {
23413
+ return `${options.embedId ?? ""}|${options.serviceUrl ?? ""}|${options.sessionEndpoint ?? ""}`;
23414
+ }
23412
23415
 
23413
23416
  // src/transcript-replay.ts
23414
23417
  function parseTranscriptEntries(value) {
@@ -23578,6 +23581,32 @@ function isAbortError2(error51) {
23578
23581
  return error51 instanceof DOMException && error51.name === "AbortError";
23579
23582
  }
23580
23583
 
23584
+ // src/visitor-id.ts
23585
+ var STORAGE_PREFIX = "noodleseed.assistant.visitor.";
23586
+ function randomVisitorId() {
23587
+ try {
23588
+ return globalThis.crypto.randomUUID();
23589
+ } catch {
23590
+ return void 0;
23591
+ }
23592
+ }
23593
+ function visitorIdForSource(sourceKey) {
23594
+ const key = `${STORAGE_PREFIX}${sourceKey}`;
23595
+ try {
23596
+ const stored = globalThis.localStorage?.getItem(key);
23597
+ if (typeof stored === "string" && stored.length > 0) return stored;
23598
+ } catch {
23599
+ return void 0;
23600
+ }
23601
+ const created = randomVisitorId();
23602
+ if (created === void 0) return void 0;
23603
+ try {
23604
+ globalThis.localStorage?.setItem(key, created);
23605
+ } catch {
23606
+ }
23607
+ return created;
23608
+ }
23609
+
23581
23610
  // src/client.ts
23582
23611
  var DefaultAssistantClient = class {
23583
23612
  #source;
@@ -23972,11 +24001,12 @@ var DefaultAssistantClient = class {
23972
24001
  }
23973
24002
  async #createSession(signal) {
23974
24003
  const source = this.#source;
24004
+ const visitorId = source.kind === "public" ? visitorIdForSource(sessionSourceKey({ embedId: source.embedId, serviceUrl: source.url })) : void 0;
23975
24005
  const response = await this.#requestSession(source, {
23976
24006
  method: "POST",
23977
24007
  headers: { Accept: "application/json", "Content-Type": "application/json" },
23978
24008
  body: JSON.stringify(
23979
- source.kind === "public" ? { embedId: source.embedId } : this.#context ? { context: this.#context } : {}
24009
+ source.kind === "public" ? { embedId: source.embedId, ...visitorId ? { visitorId } : {} } : this.#context ? { context: this.#context } : {}
23980
24010
  ),
23981
24011
  credentials: source.kind === "public" ? "omit" : "same-origin",
23982
24012
  signal