@noodleseed/assistant 1.14.0 → 1.15.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.
@@ -1,8 +1,9 @@
1
1
  import {
2
2
  AssistantClientError,
3
3
  copyAssistantModelContext,
4
- createAssistantClient
5
- } from "./chunk-RITHSCTD.js";
4
+ createAssistantClient,
5
+ sessionSourceKey
6
+ } from "./chunk-RRJIK473.js";
6
7
  import {
7
8
  _enum,
8
9
  _null,
@@ -7620,6 +7621,10 @@ var NoodleAssistantElement = class extends HTMLElementBase {
7620
7621
  #appearanceStyleSnapshot = /* @__PURE__ */ new Map();
7621
7622
  #scroll = new AssistantElementScrollController();
7622
7623
  sessionEndpoint = "";
7624
+ /** Public mount: the non-secret embed id `noodle deploy` printed. Mutually exclusive with the above. */
7625
+ embedId = "";
7626
+ /** Only for a dev or self-hosted service; the published snippet needs no origin. */
7627
+ serviceUrl = "";
7623
7628
  get appearance() {
7624
7629
  return this.#hostAppearance;
7625
7630
  }
@@ -7674,6 +7679,8 @@ var NoodleAssistantElement = class extends HTMLElementBase {
7674
7679
  connectedCallback() {
7675
7680
  if (!this.shadowRoot) this.attachShadow({ mode: "open" });
7676
7681
  if (!this.sessionEndpoint) this.sessionEndpoint = this.getAttribute("session-endpoint") ?? "";
7682
+ if (!this.embedId) this.embedId = this.getAttribute("embed-id") ?? "";
7683
+ if (!this.serviceUrl) this.serviceUrl = this.getAttribute("service-url") ?? "";
7677
7684
  this.#media = globalThis.matchMedia?.("(prefers-color-scheme: dark)");
7678
7685
  this.#media?.addEventListener("change", this.#handleSystemTheme);
7679
7686
  document.addEventListener("keydown", this.#handleDocumentKeydown);
@@ -7845,26 +7852,31 @@ var NoodleAssistantElement = class extends HTMLElementBase {
7845
7852
  }
7846
7853
  };
7847
7854
  #ensureClient() {
7848
- if (this.#client && this.#clientEndpoint === this.sessionEndpoint) return this.#client;
7855
+ const key = sessionSourceKey(this);
7856
+ if (this.#client && this.#clientEndpoint === key) return this.#client;
7849
7857
  this.#client?.abort();
7850
7858
  this.#unsubscribeClient?.();
7851
7859
  this.#sessionBootstrap = void 0;
7852
- const client = createAssistantClient({
7853
- sessionEndpoint: this.sessionEndpoint,
7860
+ const behavior = {
7854
7861
  ...this.#context ? { context: this.#context } : {},
7855
7862
  clientContext: browserClientContext,
7856
7863
  ...this.#pageContext ? { pageContext: this.#pageContext } : {},
7857
7864
  ...this.#modelContext ? { modelContext: this.#modelContext } : {}
7858
- });
7865
+ };
7866
+ const client = this.embedId ? createAssistantClient({
7867
+ embedId: this.embedId,
7868
+ ...this.serviceUrl ? { serviceUrl: this.serviceUrl } : {},
7869
+ ...behavior
7870
+ }) : createAssistantClient({ sessionEndpoint: this.sessionEndpoint, ...behavior });
7859
7871
  this.#client = client;
7860
- this.#clientEndpoint = this.sessionEndpoint;
7872
+ this.#clientEndpoint = key;
7861
7873
  this.#unsubscribeClient = client.subscribe((event) => {
7862
7874
  if (this.#client === client) this.#handleClientEvent(event);
7863
7875
  });
7864
7876
  return client;
7865
7877
  }
7866
7878
  #primeSession() {
7867
- if (!this.sessionEndpoint) return;
7879
+ if (!this.sessionEndpoint && !this.embedId) return;
7868
7880
  const client = this.#ensureClient();
7869
7881
  const generation = this.#conversationGeneration;
7870
7882
  this.#setSessionState("loading");
@@ -7988,23 +8000,30 @@ var NoodleAssistantElement = class extends HTMLElementBase {
7988
8000
  }
7989
8001
  const detail = error instanceof AssistantClientError ? error.detail : { code: fallbackCode, retryable: false };
7990
8002
  this.#appendRecoveryError(
7991
- detail.code === "session_expired" ? this.#appearance.labels.sessionExpired : this.#appearance.labels.unavailable
8003
+ detail.code === "session_expired" ? this.#appearance.labels.sessionExpired : this.#appearance.labels.unavailable,
8004
+ // A spent or switched-off daily budget offers no retry. Reconnecting cannot succeed, and every
8005
+ // open tab trying is exactly the load the cap was set to refuse — so the button goes, not just
8006
+ // the alarming words. A spent *session* keeps it: reconnect mints a fresh one, which is the fix.
8007
+ detail.retryable !== false || detail.serviceCode === void 0
7992
8008
  );
7993
8009
  this.#dispatchError(detail);
7994
8010
  }
7995
- #appendRecoveryError(message) {
8011
+ #appendRecoveryError(message, offerRetry = true) {
7996
8012
  if (!this.#messages) return;
7997
8013
  this.#messages.querySelector(".conversation-error")?.remove();
7998
8014
  const error = document.createElement("section");
7999
8015
  error.className = "conversation-error";
8000
- error.setAttribute("role", "alert");
8016
+ error.setAttribute("role", offerRetry ? "alert" : "status");
8001
8017
  const text2 = document.createElement("p");
8002
8018
  text2.textContent = message;
8003
- const retry = document.createElement("button");
8004
- retry.type = "button";
8005
- retry.textContent = this.#appearance.labels.reconnect;
8006
- retry.addEventListener("click", () => this.reconnect());
8007
- error.append(text2, retry);
8019
+ error.append(text2);
8020
+ if (offerRetry) {
8021
+ const retry = document.createElement("button");
8022
+ retry.type = "button";
8023
+ retry.textContent = this.#appearance.labels.reconnect;
8024
+ retry.addEventListener("click", () => this.reconnect());
8025
+ error.append(retry);
8026
+ }
8008
8027
  this.#messages.append(error);
8009
8028
  this.#revealLatest();
8010
8029
  }
@@ -8221,4 +8240,4 @@ export {
8221
8240
  dompurify/dist/purify.es.mjs:
8222
8241
  (*! @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 *)
8223
8242
  */
8224
- //# sourceMappingURL=chunk-7WXGZJCA.js.map
8243
+ //# sourceMappingURL=chunk-SUHNNWKP.js.map