@noodleseed/assistant 1.9.0 → 1.10.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,7 +2,7 @@ import {
2
2
  ASSISTANT_TAG_NAME,
3
3
  NoodleAssistantElement,
4
4
  registerNoodleAssistant
5
- } from "./chunk-4B3XXGRP.js";
5
+ } from "./chunk-RSNMY27B.js";
6
6
  import "./chunk-RYQBXTLR.js";
7
7
  import "./chunk-3YYTUJPJ.js";
8
8
  import "./chunk-5FUTL2UF.js";
package/dist/react.cjs CHANGED
@@ -22155,6 +22155,7 @@ function mountAssistantApp(detail, actions, options = {}) {
22155
22155
  let mountedTransport;
22156
22156
  let destroyed = false;
22157
22157
  let initialized = false;
22158
+ let hostContext = createAssistantAppHostContext(actions.theme);
22158
22159
  let destroyPromise;
22159
22160
  const renderTimer = setTimeout(() => {
22160
22161
  if (initialized || !frame.isConnected) return;
@@ -22181,7 +22182,7 @@ function mountAssistantApp(detail, actions, options = {}) {
22181
22182
  message: { text: {} }
22182
22183
  },
22183
22184
  {
22184
- hostContext: createAssistantAppHostContext(actions.theme)
22185
+ hostContext
22185
22186
  }
22186
22187
  );
22187
22188
  mountedBridge = bridge;
@@ -22256,6 +22257,7 @@ function mountAssistantApp(detail, actions, options = {}) {
22256
22257
  if (destroyed) return;
22257
22258
  initialized = true;
22258
22259
  clearTimeout(renderTimer);
22260
+ bridge.setHostContext(hostContext);
22259
22261
  const current = options.getDetail?.() ?? detail;
22260
22262
  void bridge.sendToolInput({ arguments: current.arguments ?? {} });
22261
22263
  void bridge.sendToolResult({
@@ -22271,6 +22273,11 @@ function mountAssistantApp(detail, actions, options = {}) {
22271
22273
  },
22272
22274
  { once: true }
22273
22275
  );
22276
+ const updateTheme = (theme) => {
22277
+ if (destroyed) return;
22278
+ hostContext = createAssistantAppHostContext(theme);
22279
+ if (initialized) mountedBridge?.setHostContext(hostContext);
22280
+ };
22274
22281
  const destroy = () => {
22275
22282
  if (destroyPromise) return destroyPromise;
22276
22283
  destroyed = true;
@@ -22289,9 +22296,12 @@ function mountAssistantApp(detail, actions, options = {}) {
22289
22296
  })();
22290
22297
  return destroyPromise;
22291
22298
  };
22292
- mountedApps.set(card, { destroy });
22299
+ mountedApps.set(card, { destroy, updateTheme });
22293
22300
  return card;
22294
22301
  }
22302
+ function updateAssistantAppTheme(card, theme) {
22303
+ mountedApps.get(card)?.updateTheme(theme);
22304
+ }
22295
22305
  function unmountAssistantApp(card) {
22296
22306
  return mountedApps.get(card)?.destroy() ?? Promise.resolve();
22297
22307
  }
@@ -31426,7 +31436,7 @@ function contrastWarnings(theme, mode) {
31426
31436
  for (const [role, foreground, background] of pairs) {
31427
31437
  if (!foreground || !background) continue;
31428
31438
  const ratio = contrastRatio2(foreground, background);
31429
- if (ratio >= 4.5) continue;
31439
+ if (ratio === void 0 || ratio >= 4.5) continue;
31430
31440
  warnings.push({
31431
31441
  code: "low_contrast",
31432
31442
  theme: mode,
@@ -31440,13 +31450,16 @@ function contrastWarnings(theme, mode) {
31440
31450
  return warnings;
31441
31451
  }
31442
31452
  function contrastRatio2(first, second) {
31443
- const lighter = Math.max(luminance(first), luminance(second));
31444
- const darker = Math.min(luminance(first), luminance(second));
31453
+ const firstLuminance = luminance(first);
31454
+ const secondLuminance = luminance(second);
31455
+ if (firstLuminance === void 0 || secondLuminance === void 0) return void 0;
31456
+ const lighter = Math.max(firstLuminance, secondLuminance);
31457
+ const darker = Math.min(firstLuminance, secondLuminance);
31445
31458
  return (lighter + 0.05) / (darker + 0.05);
31446
31459
  }
31447
31460
  function luminance(color) {
31448
31461
  const match = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(color);
31449
- if (!match) return 1;
31462
+ if (!match) return void 0;
31450
31463
  const values = match.slice(1).map((value) => {
31451
31464
  const channel = Number.parseInt(value, 16) / 255;
31452
31465
  return channel <= 0.04045 ? channel / 12.92 : ((channel + 0.055) / 1.055) ** 2.4;
@@ -32279,6 +32292,9 @@ var NoodleAssistantElement = class extends HTMLElementBase {
32279
32292
  })
32280
32293
  );
32281
32294
  }
32295
+ for (const app of this.shadowRoot?.querySelectorAll(".noodle-app-card") ?? []) {
32296
+ updateAssistantAppTheme(app, mode);
32297
+ }
32282
32298
  }
32283
32299
  #setSessionState(state) {
32284
32300
  this.#sessionState = state;
@@ -32462,6 +32478,7 @@ function NoodleAppView({
32462
32478
  onError
32463
32479
  }) {
32464
32480
  const container = (0, import_react.useRef)(null);
32481
+ const mounted = (0, import_react.useRef)(null);
32465
32482
  const current = (0, import_react.useRef)({ view, theme, onError });
32466
32483
  const viewId = view.id;
32467
32484
  const resourceUri = view.resourceUri;
@@ -32488,11 +32505,16 @@ function NoodleAppView({
32488
32505
  }
32489
32506
  );
32490
32507
  if (!card) return;
32508
+ mounted.current = card;
32491
32509
  host.replaceChildren(card);
32492
32510
  return () => {
32511
+ if (mounted.current === card) mounted.current = null;
32493
32512
  void unmountAssistantApp(card);
32494
32513
  };
32495
32514
  }, [client, resourceUri, viewId]);
32515
+ (0, import_react.useEffect)(() => {
32516
+ if (mounted.current) updateAssistantAppTheme(mounted.current, theme);
32517
+ }, [theme]);
32496
32518
  return (0, import_react.createElement)("div", { ref: container, className });
32497
32519
  }
32498
32520