@noodleseed/assistant 1.8.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.
@@ -1,4 +1,4 @@
1
- import { a as AssistantConfiguration } from './appearance-DowzFJjh.js';
1
+ import { A as AssistantConfiguration } from './appearance-Cc-eqSbp.js';
2
2
  import { ChatStatus, UIMessage } from 'ai';
3
3
 
4
4
  type AssistantJsonValue = string | number | boolean | null | readonly AssistantJsonValue[] | {
@@ -226,4 +226,4 @@ declare class AssistantClientError extends Error {
226
226
  }
227
227
  declare function createAssistantClient<TPageContext extends AssistantPageContext = AssistantContext>(options: CreateAssistantClientOptions<TPageContext>): AssistantClient<TPageContext>;
228
228
 
229
- export { type AssistantPageContext as A, type AssistantInteractionStatus as B, type CreateAssistantClientOptions as C, type AssistantJsonValue as D, type AssistantSessionResponse as E, type AssistantToolCompletedDetail as F, type AssistantToolCompletedEvent as G, type AssistantToolProposedDetail as H, type AssistantToolProposedEvent as I, type AssistantToolResultData as J, type AssistantUIDataTypes as K, type AssistantUIMessage as L, type AssistantUnrecognizedEvent as M, type AssistantViewData as N, createAssistantClient as O, type AssistantContext as a, type AssistantChatState as b, type AssistantClient as c, type AssistantModelContextUpdate as d, type AssistantClientEvent as e, type AssistantErrorDetail as f, type AssistantViewAvailableDetail as g, type AssistantInteractionResponse as h, type AssistantEvent as i, type AssistantViewAvailableEvent as j, type AssistantChatError as k, type AssistantClientContext as l, AssistantClientError as m, type AssistantClientLifecycleEvent as n, type AssistantConfirmationData as o, type AssistantContentDetail as p, type AssistantContentEvent as q, type AssistantContextValue as r, type AssistantDoneEvent as s, type AssistantErrorEvent as t, type AssistantErrorEventDetail as u, type AssistantInputRequestData as v, type AssistantInputRequestedDetail as w, type AssistantInputRequestedEvent as x, type AssistantInteractionResolvedDetail as y, type AssistantInteractionResolvedEvent as z };
229
+ export { type AssistantPageContext as A, type AssistantInteractionStatus as B, type CreateAssistantClientOptions as C, type AssistantJsonValue as D, type AssistantSessionResponse as E, type AssistantToolCompletedDetail as F, type AssistantToolCompletedEvent as G, type AssistantToolProposedDetail as H, type AssistantToolProposedEvent as I, type AssistantToolResultData as J, type AssistantUIDataTypes as K, type AssistantUIMessage as L, type AssistantUnrecognizedEvent as M, type AssistantViewData as N, createAssistantClient as O, type AssistantContext as a, type AssistantChatState as b, type AssistantClient as c, type AssistantViewAvailableDetail as d, type AssistantModelContextUpdate as e, type AssistantClientEvent as f, type AssistantErrorDetail as g, type AssistantInteractionResponse as h, type AssistantEvent as i, type AssistantViewAvailableEvent as j, type AssistantChatError as k, type AssistantClientContext as l, AssistantClientError as m, type AssistantClientLifecycleEvent as n, type AssistantConfirmationData as o, type AssistantContentDetail as p, type AssistantContentEvent as q, type AssistantContextValue as r, type AssistantDoneEvent as s, type AssistantErrorEvent as t, type AssistantErrorEventDetail as u, type AssistantInputRequestData as v, type AssistantInputRequestedDetail as w, type AssistantInputRequestedEvent as x, type AssistantInteractionResolvedDetail as y, type AssistantInteractionResolvedEvent as z };
@@ -1,4 +1,4 @@
1
- import { a as AssistantConfiguration } from './appearance-DowzFJjh.cjs';
1
+ import { A as AssistantConfiguration } from './appearance-Cc-eqSbp.cjs';
2
2
  import { ChatStatus, UIMessage } from 'ai';
3
3
 
4
4
  type AssistantJsonValue = string | number | boolean | null | readonly AssistantJsonValue[] | {
@@ -226,4 +226,4 @@ declare class AssistantClientError extends Error {
226
226
  }
227
227
  declare function createAssistantClient<TPageContext extends AssistantPageContext = AssistantContext>(options: CreateAssistantClientOptions<TPageContext>): AssistantClient<TPageContext>;
228
228
 
229
- export { type AssistantPageContext as A, type AssistantInteractionStatus as B, type CreateAssistantClientOptions as C, type AssistantJsonValue as D, type AssistantSessionResponse as E, type AssistantToolCompletedDetail as F, type AssistantToolCompletedEvent as G, type AssistantToolProposedDetail as H, type AssistantToolProposedEvent as I, type AssistantToolResultData as J, type AssistantUIDataTypes as K, type AssistantUIMessage as L, type AssistantUnrecognizedEvent as M, type AssistantViewData as N, createAssistantClient as O, type AssistantContext as a, type AssistantChatState as b, type AssistantClient as c, type AssistantModelContextUpdate as d, type AssistantClientEvent as e, type AssistantErrorDetail as f, type AssistantViewAvailableDetail as g, type AssistantInteractionResponse as h, type AssistantEvent as i, type AssistantViewAvailableEvent as j, type AssistantChatError as k, type AssistantClientContext as l, AssistantClientError as m, type AssistantClientLifecycleEvent as n, type AssistantConfirmationData as o, type AssistantContentDetail as p, type AssistantContentEvent as q, type AssistantContextValue as r, type AssistantDoneEvent as s, type AssistantErrorEvent as t, type AssistantErrorEventDetail as u, type AssistantInputRequestData as v, type AssistantInputRequestedDetail as w, type AssistantInputRequestedEvent as x, type AssistantInteractionResolvedDetail as y, type AssistantInteractionResolvedEvent as z };
229
+ export { type AssistantPageContext as A, type AssistantInteractionStatus as B, type CreateAssistantClientOptions as C, type AssistantJsonValue as D, type AssistantSessionResponse as E, type AssistantToolCompletedDetail as F, type AssistantToolCompletedEvent as G, type AssistantToolProposedDetail as H, type AssistantToolProposedEvent as I, type AssistantToolResultData as J, type AssistantUIDataTypes as K, type AssistantUIMessage as L, type AssistantUnrecognizedEvent as M, type AssistantViewData as N, createAssistantClient as O, type AssistantContext as a, type AssistantChatState as b, type AssistantClient as c, type AssistantViewAvailableDetail as d, type AssistantModelContextUpdate as e, type AssistantClientEvent as f, type AssistantErrorDetail as g, type AssistantInteractionResponse as h, type AssistantEvent as i, type AssistantViewAvailableEvent as j, type AssistantChatError as k, type AssistantClientContext as l, AssistantClientError as m, type AssistantClientLifecycleEvent as n, type AssistantConfirmationData as o, type AssistantContentDetail as p, type AssistantContentEvent as q, type AssistantContextValue as r, type AssistantDoneEvent as s, type AssistantErrorEvent as t, type AssistantErrorEventDetail as u, type AssistantInputRequestData as v, type AssistantInputRequestedDetail as w, type AssistantInputRequestedEvent as x, type AssistantInteractionResolvedDetail as y, type AssistantInteractionResolvedEvent as z };
package/dist/client.d.cts CHANGED
@@ -1,3 +1,3 @@
1
- import './appearance-DowzFJjh.cjs';
2
- export { k as AssistantChatError, b as AssistantChatState, c as AssistantClient, l as AssistantClientContext, m as AssistantClientError, e as AssistantClientEvent, n as AssistantClientLifecycleEvent, o as AssistantConfirmationData, p as AssistantContentDetail, q as AssistantContentEvent, a as AssistantContext, r as AssistantContextValue, s as AssistantDoneEvent, t as AssistantErrorEvent, u as AssistantErrorEventDetail, v as AssistantInputRequestData, w as AssistantInputRequestedDetail, x as AssistantInputRequestedEvent, y as AssistantInteractionResolvedDetail, z as AssistantInteractionResolvedEvent, h as AssistantInteractionResponse, B as AssistantInteractionStatus, D as AssistantJsonValue, d as AssistantModelContextUpdate, A as AssistantPageContext, E as AssistantSessionResponse, F as AssistantToolCompletedDetail, G as AssistantToolCompletedEvent, H as AssistantToolProposedDetail, I as AssistantToolProposedEvent, J as AssistantToolResultData, K as AssistantUIDataTypes, L as AssistantUIMessage, M as AssistantUnrecognizedEvent, g as AssistantViewAvailableDetail, j as AssistantViewAvailableEvent, N as AssistantViewData, C as CreateAssistantClientOptions, O as createAssistantClient } from './client-BxoNZkWp.cjs';
1
+ import './appearance-Cc-eqSbp.cjs';
2
+ export { k as AssistantChatError, b as AssistantChatState, c as AssistantClient, l as AssistantClientContext, m as AssistantClientError, f as AssistantClientEvent, n as AssistantClientLifecycleEvent, o as AssistantConfirmationData, p as AssistantContentDetail, q as AssistantContentEvent, a as AssistantContext, r as AssistantContextValue, s as AssistantDoneEvent, t as AssistantErrorEvent, u as AssistantErrorEventDetail, v as AssistantInputRequestData, w as AssistantInputRequestedDetail, x as AssistantInputRequestedEvent, y as AssistantInteractionResolvedDetail, z as AssistantInteractionResolvedEvent, h as AssistantInteractionResponse, B as AssistantInteractionStatus, D as AssistantJsonValue, e as AssistantModelContextUpdate, A as AssistantPageContext, E as AssistantSessionResponse, F as AssistantToolCompletedDetail, G as AssistantToolCompletedEvent, H as AssistantToolProposedDetail, I as AssistantToolProposedEvent, J as AssistantToolResultData, K as AssistantUIDataTypes, L as AssistantUIMessage, M as AssistantUnrecognizedEvent, d as AssistantViewAvailableDetail, j as AssistantViewAvailableEvent, N as AssistantViewData, C as CreateAssistantClientOptions, O as createAssistantClient } from './client-CsmtpD1z.cjs';
3
3
  import 'ai';
package/dist/client.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import './appearance-DowzFJjh.js';
2
- export { k as AssistantChatError, b as AssistantChatState, c as AssistantClient, l as AssistantClientContext, m as AssistantClientError, e as AssistantClientEvent, n as AssistantClientLifecycleEvent, o as AssistantConfirmationData, p as AssistantContentDetail, q as AssistantContentEvent, a as AssistantContext, r as AssistantContextValue, s as AssistantDoneEvent, t as AssistantErrorEvent, u as AssistantErrorEventDetail, v as AssistantInputRequestData, w as AssistantInputRequestedDetail, x as AssistantInputRequestedEvent, y as AssistantInteractionResolvedDetail, z as AssistantInteractionResolvedEvent, h as AssistantInteractionResponse, B as AssistantInteractionStatus, D as AssistantJsonValue, d as AssistantModelContextUpdate, A as AssistantPageContext, E as AssistantSessionResponse, F as AssistantToolCompletedDetail, G as AssistantToolCompletedEvent, H as AssistantToolProposedDetail, I as AssistantToolProposedEvent, J as AssistantToolResultData, K as AssistantUIDataTypes, L as AssistantUIMessage, M as AssistantUnrecognizedEvent, g as AssistantViewAvailableDetail, j as AssistantViewAvailableEvent, N as AssistantViewData, C as CreateAssistantClientOptions, O as createAssistantClient } from './client-ERQCAH_0.js';
1
+ import './appearance-Cc-eqSbp.js';
2
+ export { k as AssistantChatError, b as AssistantChatState, c as AssistantClient, l as AssistantClientContext, m as AssistantClientError, f as AssistantClientEvent, n as AssistantClientLifecycleEvent, o as AssistantConfirmationData, p as AssistantContentDetail, q as AssistantContentEvent, a as AssistantContext, r as AssistantContextValue, s as AssistantDoneEvent, t as AssistantErrorEvent, u as AssistantErrorEventDetail, v as AssistantInputRequestData, w as AssistantInputRequestedDetail, x as AssistantInputRequestedEvent, y as AssistantInteractionResolvedDetail, z as AssistantInteractionResolvedEvent, h as AssistantInteractionResponse, B as AssistantInteractionStatus, D as AssistantJsonValue, e as AssistantModelContextUpdate, A as AssistantPageContext, E as AssistantSessionResponse, F as AssistantToolCompletedDetail, G as AssistantToolCompletedEvent, H as AssistantToolProposedDetail, I as AssistantToolProposedEvent, J as AssistantToolResultData, K as AssistantUIDataTypes, L as AssistantUIMessage, M as AssistantUnrecognizedEvent, d as AssistantViewAvailableDetail, j as AssistantViewAvailableEvent, N as AssistantViewData, C as CreateAssistantClientOptions, O as createAssistantClient } from './client-B803xZVn.js';
3
3
  import 'ai';
package/dist/index.cjs CHANGED
@@ -22121,6 +22121,8 @@ function createAssistantAppHostContext(theme) {
22121
22121
  };
22122
22122
  }
22123
22123
  var APP_RENDER_TIMEOUT_MS = 1e4;
22124
+ var APP_TEARDOWN_TIMEOUT_MS = 1e3;
22125
+ var mountedApps = /* @__PURE__ */ new WeakMap();
22124
22126
  function resolveSandboxUrl(value) {
22125
22127
  if (!value) return void 0;
22126
22128
  try {
@@ -22149,7 +22151,12 @@ function mountAssistantApp(detail, actions, options = {}) {
22149
22151
  if (sandboxUrl) frame.src = sandboxUrl;
22150
22152
  else frame.srcdoc = PROXY_DOCUMENT;
22151
22153
  card.append(frame);
22154
+ let mountedBridge;
22155
+ let mountedTransport;
22156
+ let destroyed = false;
22152
22157
  let initialized = false;
22158
+ let hostContext = createAssistantAppHostContext(actions.theme);
22159
+ let destroyPromise;
22153
22160
  const renderTimer = setTimeout(() => {
22154
22161
  if (initialized || !frame.isConnected) return;
22155
22162
  const note = document.createElement("div");
@@ -22161,6 +22168,7 @@ function mountAssistantApp(detail, actions, options = {}) {
22161
22168
  frame.addEventListener(
22162
22169
  "load",
22163
22170
  () => {
22171
+ if (destroyed) return;
22164
22172
  const target = frame.contentWindow;
22165
22173
  if (!target) return;
22166
22174
  const bridge = new DX(
@@ -22174,22 +22182,27 @@ function mountAssistantApp(detail, actions, options = {}) {
22174
22182
  message: { text: {} }
22175
22183
  },
22176
22184
  {
22177
- hostContext: createAssistantAppHostContext(actions.theme)
22185
+ hostContext
22178
22186
  }
22179
22187
  );
22188
+ mountedBridge = bridge;
22180
22189
  bridge.onsandboxready = () => {
22190
+ if (destroyed) return;
22191
+ const current = options.getDetail?.() ?? detail;
22181
22192
  void bridge.sendSandboxResourceReady({
22182
- html: detail.html,
22193
+ html: current.html,
22183
22194
  sandbox: "allow-scripts allow-forms",
22184
- ...detail.resourceMeta ?? {}
22195
+ ...current.resourceMeta ?? {}
22185
22196
  });
22186
22197
  };
22187
22198
  bridge.onsizechange = ({ height }) => {
22199
+ if (destroyed) return;
22188
22200
  if (typeof height === "number" && Number.isFinite(height)) {
22189
22201
  frame.style.height = `${Math.min(1200, Math.max(120, Math.ceil(height)))}px`;
22190
22202
  }
22191
22203
  };
22192
22204
  bridge.onmessage = async ({ content }) => {
22205
+ if (destroyed) return {};
22193
22206
  const text3 = content.flatMap(
22194
22207
  (part) => part.type === "text" && typeof part.text === "string" ? [part.text] : []
22195
22208
  ).join("\n").trim();
@@ -22197,13 +22210,16 @@ function mountAssistantApp(detail, actions, options = {}) {
22197
22210
  return {};
22198
22211
  };
22199
22212
  bridge.onupdatemodelcontext = async (update) => {
22213
+ if (destroyed) return {};
22200
22214
  actions.updateModelContext(update);
22201
22215
  return {};
22202
22216
  };
22203
22217
  bridge.onopenlink = async ({ url: url2 }) => {
22218
+ if (destroyed) return { isError: true };
22219
+ const current = options.getDetail?.() ?? detail;
22204
22220
  const allowed = isAllowedAppLink(
22205
22221
  url2,
22206
- detail.allowedOpenDomains ?? [],
22222
+ current.allowedOpenDomains ?? [],
22207
22223
  globalThis.location?.href ?? "https://invalid.example"
22208
22224
  );
22209
22225
  if (!allowed) return { isError: true };
@@ -22212,30 +22228,80 @@ function mountAssistantApp(detail, actions, options = {}) {
22212
22228
  };
22213
22229
  bridge.onrequestdisplaymode = async ({ mode }) => {
22214
22230
  const accepted = mode === "fullscreen" ? "fullscreen" : "inline";
22231
+ if (destroyed) return { mode: accepted };
22215
22232
  card.toggleAttribute("data-fullscreen", accepted === "fullscreen");
22216
22233
  return { mode: accepted };
22217
22234
  };
22218
- bridge.oncalltool = async (params) => await actions.client.requestApp("tools/call", params);
22219
- bridge.onlistresources = async (params) => await actions.client.requestApp("resources/list", params ?? {});
22220
- bridge.onreadresource = async (params) => await actions.client.requestApp("resources/read", params);
22235
+ bridge.oncalltool = async (params) => {
22236
+ if (destroyed) {
22237
+ return {
22238
+ content: [{ type: "text", text: "App view is closing." }],
22239
+ isError: true
22240
+ };
22241
+ }
22242
+ return await actions.client.requestApp("tools/call", params);
22243
+ };
22244
+ bridge.onlistresources = async (params) => {
22245
+ if (destroyed) {
22246
+ return { resources: [] };
22247
+ }
22248
+ return await actions.client.requestApp("resources/list", params ?? {});
22249
+ };
22250
+ bridge.onreadresource = async (params) => {
22251
+ if (destroyed) {
22252
+ return { contents: [] };
22253
+ }
22254
+ return await actions.client.requestApp("resources/read", params);
22255
+ };
22221
22256
  bridge.oninitialized = () => {
22257
+ if (destroyed) return;
22222
22258
  initialized = true;
22223
22259
  clearTimeout(renderTimer);
22224
- void bridge.sendToolInput({ arguments: detail.arguments ?? {} });
22260
+ bridge.setHostContext(hostContext);
22261
+ const current = options.getDetail?.() ?? detail;
22262
+ void bridge.sendToolInput({ arguments: current.arguments ?? {} });
22225
22263
  void bridge.sendToolResult({
22226
- content: [{ type: "text", text: JSON.stringify(detail.result) }],
22227
- ...typeof detail.result === "object" && detail.result !== null && !Array.isArray(detail.result) ? { structuredContent: detail.result } : {}
22264
+ content: [{ type: "text", text: JSON.stringify(current.result) }],
22265
+ ...typeof current.result === "object" && current.result !== null && !Array.isArray(current.result) ? { structuredContent: current.result } : {}
22228
22266
  });
22229
22267
  };
22230
- void bridge.connect(new E(target, target)).catch(() => {
22231
- clearTimeout(renderTimer);
22232
- card.remove();
22268
+ const transport = new E(target, target);
22269
+ mountedTransport = transport;
22270
+ void bridge.connect(transport).catch(() => {
22271
+ void destroy();
22233
22272
  });
22234
22273
  },
22235
22274
  { once: true }
22236
22275
  );
22276
+ const updateTheme = (theme) => {
22277
+ if (destroyed) return;
22278
+ hostContext = createAssistantAppHostContext(theme);
22279
+ if (initialized) mountedBridge?.setHostContext(hostContext);
22280
+ };
22281
+ const destroy = () => {
22282
+ if (destroyPromise) return destroyPromise;
22283
+ destroyed = true;
22284
+ clearTimeout(renderTimer);
22285
+ destroyPromise = (async () => {
22286
+ try {
22287
+ if (initialized) {
22288
+ await mountedBridge?.teardownResource({}, { timeout: APP_TEARDOWN_TIMEOUT_MS });
22289
+ }
22290
+ } catch {
22291
+ }
22292
+ await mountedTransport?.close().catch(() => {
22293
+ });
22294
+ card.remove();
22295
+ mountedApps.delete(card);
22296
+ })();
22297
+ return destroyPromise;
22298
+ };
22299
+ mountedApps.set(card, { destroy, updateTheme });
22237
22300
  return card;
22238
22301
  }
22302
+ function updateAssistantAppTheme(card, theme) {
22303
+ mountedApps.get(card)?.updateTheme(theme);
22304
+ }
22239
22305
 
22240
22306
  // src/appearance.ts
22241
22307
  var common = {
@@ -31367,7 +31433,7 @@ function contrastWarnings(theme, mode) {
31367
31433
  for (const [role, foreground, background] of pairs) {
31368
31434
  if (!foreground || !background) continue;
31369
31435
  const ratio = contrastRatio2(foreground, background);
31370
- if (ratio >= 4.5) continue;
31436
+ if (ratio === void 0 || ratio >= 4.5) continue;
31371
31437
  warnings.push({
31372
31438
  code: "low_contrast",
31373
31439
  theme: mode,
@@ -31381,13 +31447,16 @@ function contrastWarnings(theme, mode) {
31381
31447
  return warnings;
31382
31448
  }
31383
31449
  function contrastRatio2(first, second) {
31384
- const lighter = Math.max(luminance(first), luminance(second));
31385
- const darker = Math.min(luminance(first), luminance(second));
31450
+ const firstLuminance = luminance(first);
31451
+ const secondLuminance = luminance(second);
31452
+ if (firstLuminance === void 0 || secondLuminance === void 0) return void 0;
31453
+ const lighter = Math.max(firstLuminance, secondLuminance);
31454
+ const darker = Math.min(firstLuminance, secondLuminance);
31386
31455
  return (lighter + 0.05) / (darker + 0.05);
31387
31456
  }
31388
31457
  function luminance(color) {
31389
31458
  const match = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(color);
31390
- if (!match) return 1;
31459
+ if (!match) return void 0;
31391
31460
  const values = match.slice(1).map((value) => {
31392
31461
  const channel = Number.parseInt(value, 16) / 255;
31393
31462
  return channel <= 0.04045 ? channel / 12.92 : ((channel + 0.055) / 1.055) ** 2.4;
@@ -32220,6 +32289,9 @@ var NoodleAssistantElement = class extends HTMLElementBase {
32220
32289
  })
32221
32290
  );
32222
32291
  }
32292
+ for (const app of this.shadowRoot?.querySelectorAll(".noodle-app-card") ?? []) {
32293
+ updateAssistantAppTheme(app, mode);
32294
+ }
32223
32295
  }
32224
32296
  #setSessionState(state) {
32225
32297
  this.#sessionState = state;