@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.
@@ -5177,6 +5177,32 @@ function isAbortError2(error) {
5177
5177
  return error instanceof DOMException && error.name === "AbortError";
5178
5178
  }
5179
5179
 
5180
+ // src/visitor-id.ts
5181
+ var STORAGE_PREFIX = "noodleseed.assistant.visitor.";
5182
+ function randomVisitorId() {
5183
+ try {
5184
+ return globalThis.crypto.randomUUID();
5185
+ } catch {
5186
+ return void 0;
5187
+ }
5188
+ }
5189
+ function visitorIdForSource(sourceKey) {
5190
+ const key = `${STORAGE_PREFIX}${sourceKey}`;
5191
+ try {
5192
+ const stored = globalThis.localStorage?.getItem(key);
5193
+ if (typeof stored === "string" && stored.length > 0) return stored;
5194
+ } catch {
5195
+ return void 0;
5196
+ }
5197
+ const created = randomVisitorId();
5198
+ if (created === void 0) return void 0;
5199
+ try {
5200
+ globalThis.localStorage?.setItem(key, created);
5201
+ } catch {
5202
+ }
5203
+ return created;
5204
+ }
5205
+
5180
5206
  // src/client.ts
5181
5207
  var DefaultAssistantClient = class {
5182
5208
  #source;
@@ -5571,11 +5597,12 @@ var DefaultAssistantClient = class {
5571
5597
  }
5572
5598
  async #createSession(signal) {
5573
5599
  const source = this.#source;
5600
+ const visitorId = source.kind === "public" ? visitorIdForSource(sessionSourceKey({ embedId: source.embedId, serviceUrl: source.url })) : void 0;
5574
5601
  const response = await this.#requestSession(source, {
5575
5602
  method: "POST",
5576
5603
  headers: { Accept: "application/json", "Content-Type": "application/json" },
5577
5604
  body: JSON.stringify(
5578
- source.kind === "public" ? { embedId: source.embedId } : this.#context ? { context: this.#context } : {}
5605
+ source.kind === "public" ? { embedId: source.embedId, ...visitorId ? { visitorId } : {} } : this.#context ? { context: this.#context } : {}
5579
5606
  ),
5580
5607
  credentials: source.kind === "public" ? "omit" : "same-origin",
5581
5608
  signal
@@ -5771,4 +5798,4 @@ export {
5771
5798
  sessionSourceKey,
5772
5799
  createAssistantClient
5773
5800
  };
5774
- //# sourceMappingURL=chunk-3VZ3M5BE.js.map
5801
+ //# sourceMappingURL=chunk-5EVZFPTD.js.map