@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.
@@ -11,7 +11,7 @@ import {
11
11
  parseAssistantConfiguration,
12
12
  publicConfigurationUrl,
13
13
  sessionSourceKey
14
- } from "./chunk-3VZ3M5BE.js";
14
+ } from "./chunk-5EVZFPTD.js";
15
15
 
16
16
  // src/appearance.ts
17
17
  var common = {
@@ -5975,4 +5975,4 @@ export {
5975
5975
  dompurify/dist/purify.es.mjs:
5976
5976
  (*! @license DOMPurify 3.4.11 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.4.11/LICENSE *)
5977
5977
  */
5978
- //# sourceMappingURL=chunk-DOWFW3KA.js.map
5978
+ //# sourceMappingURL=chunk-T4PS6P2W.js.map
package/dist/client.cjs CHANGED
@@ -23408,6 +23408,9 @@ function resolveSessionSource(options) {
23408
23408
  }
23409
23409
  return { kind: "exchange", url: sessionEndpoint };
23410
23410
  }
23411
+ function sessionSourceKey(options) {
23412
+ return `${options.embedId ?? ""}|${options.serviceUrl ?? ""}|${options.sessionEndpoint ?? ""}`;
23413
+ }
23411
23414
 
23412
23415
  // src/transcript-replay.ts
23413
23416
  function parseTranscriptEntries(value) {
@@ -23577,6 +23580,32 @@ function isAbortError2(error51) {
23577
23580
  return error51 instanceof DOMException && error51.name === "AbortError";
23578
23581
  }
23579
23582
 
23583
+ // src/visitor-id.ts
23584
+ var STORAGE_PREFIX = "noodleseed.assistant.visitor.";
23585
+ function randomVisitorId() {
23586
+ try {
23587
+ return globalThis.crypto.randomUUID();
23588
+ } catch {
23589
+ return void 0;
23590
+ }
23591
+ }
23592
+ function visitorIdForSource(sourceKey) {
23593
+ const key = `${STORAGE_PREFIX}${sourceKey}`;
23594
+ try {
23595
+ const stored = globalThis.localStorage?.getItem(key);
23596
+ if (typeof stored === "string" && stored.length > 0) return stored;
23597
+ } catch {
23598
+ return void 0;
23599
+ }
23600
+ const created = randomVisitorId();
23601
+ if (created === void 0) return void 0;
23602
+ try {
23603
+ globalThis.localStorage?.setItem(key, created);
23604
+ } catch {
23605
+ }
23606
+ return created;
23607
+ }
23608
+
23580
23609
  // src/client.ts
23581
23610
  var DefaultAssistantClient = class {
23582
23611
  #source;
@@ -23971,11 +24000,12 @@ var DefaultAssistantClient = class {
23971
24000
  }
23972
24001
  async #createSession(signal) {
23973
24002
  const source = this.#source;
24003
+ const visitorId = source.kind === "public" ? visitorIdForSource(sessionSourceKey({ embedId: source.embedId, serviceUrl: source.url })) : void 0;
23974
24004
  const response = await this.#requestSession(source, {
23975
24005
  method: "POST",
23976
24006
  headers: { Accept: "application/json", "Content-Type": "application/json" },
23977
24007
  body: JSON.stringify(
23978
- source.kind === "public" ? { embedId: source.embedId } : this.#context ? { context: this.#context } : {}
24008
+ source.kind === "public" ? { embedId: source.embedId, ...visitorId ? { visitorId } : {} } : this.#context ? { context: this.#context } : {}
23979
24009
  ),
23980
24010
  credentials: source.kind === "public" ? "omit" : "same-origin",
23981
24011
  signal