@noodleseed/assistant 1.29.0 → 1.31.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.cjs CHANGED
@@ -27921,6 +27921,32 @@ function isAbortError2(error51) {
27921
27921
  return error51 instanceof DOMException && error51.name === "AbortError";
27922
27922
  }
27923
27923
 
27924
+ // src/visitor-id.ts
27925
+ var STORAGE_PREFIX = "noodleseed.assistant.visitor.";
27926
+ function randomVisitorId() {
27927
+ try {
27928
+ return globalThis.crypto.randomUUID();
27929
+ } catch {
27930
+ return void 0;
27931
+ }
27932
+ }
27933
+ function visitorIdForSource(sourceKey) {
27934
+ const key = `${STORAGE_PREFIX}${sourceKey}`;
27935
+ try {
27936
+ const stored = globalThis.localStorage?.getItem(key);
27937
+ if (typeof stored === "string" && stored.length > 0) return stored;
27938
+ } catch {
27939
+ return void 0;
27940
+ }
27941
+ const created = randomVisitorId();
27942
+ if (created === void 0) return void 0;
27943
+ try {
27944
+ globalThis.localStorage?.setItem(key, created);
27945
+ } catch {
27946
+ }
27947
+ return created;
27948
+ }
27949
+
27924
27950
  // src/client.ts
27925
27951
  var DefaultAssistantClient = class {
27926
27952
  #source;
@@ -28315,11 +28341,12 @@ var DefaultAssistantClient = class {
28315
28341
  }
28316
28342
  async #createSession(signal) {
28317
28343
  const source = this.#source;
28344
+ const visitorId = source.kind === "public" ? visitorIdForSource(sessionSourceKey({ embedId: source.embedId, serviceUrl: source.url })) : void 0;
28318
28345
  const response = await this.#requestSession(source, {
28319
28346
  method: "POST",
28320
28347
  headers: { Accept: "application/json", "Content-Type": "application/json" },
28321
28348
  body: JSON.stringify(
28322
- source.kind === "public" ? { embedId: source.embedId } : this.#context ? { context: this.#context } : {}
28349
+ source.kind === "public" ? { embedId: source.embedId, ...visitorId ? { visitorId } : {} } : this.#context ? { context: this.#context } : {}
28323
28350
  ),
28324
28351
  credentials: source.kind === "public" ? "omit" : "same-origin",
28325
28352
  signal
@@ -33190,7 +33217,7 @@ var AssistantElementWebMcpController = class {
33190
33217
  #bridge;
33191
33218
  /** Guards against a late `startWebMcpBridge` resolving after the session it belonged to is gone. */
33192
33219
  #generation = 0;
33193
- /** Called when resolved configuration arrives; the deployment's opt-in is the only source. */
33220
+ /** Called when resolved configuration arrives; the server already resolved surface over deployment. */
33194
33221
  configure(enabled) {
33195
33222
  this.#enabled = enabled;
33196
33223
  if (!enabled) this.stop();