@webless/agent 0.10.0 → 0.10.2

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/embed.js CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  resetAgentPanel,
10
10
  resolveAgentRuntimeConfig,
11
11
  submitAgentPanel
12
- } from "./chunk-6OCODDRO.js";
12
+ } from "./chunk-Q7H4RRS4.js";
13
13
 
14
14
  // src/embed/mount.tsx
15
15
  import { createRoot } from "react-dom/client";
package/dist/react.cjs CHANGED
@@ -46,7 +46,7 @@ __export(react_exports, {
46
46
  module.exports = __toCommonJS(react_exports);
47
47
 
48
48
  // src/react/components/AgentWidget/AgentWidget.tsx
49
- var import_react15 = require("react");
49
+ var import_react16 = require("react");
50
50
 
51
51
  // src/react/page-shift.ts
52
52
  var import_react = require("react");
@@ -3802,8 +3802,7 @@ function workSummary(steps, failed, brandLabel) {
3802
3802
  )}`;
3803
3803
  const active = [...steps].reverse().find((step) => step.state === "active");
3804
3804
  if (active?.kind === "search") return "Searching this site";
3805
- if (active)
3806
- return brandLabel ? `${brandLabel} is choosing the best way to help` : "Choosing the best way to help";
3805
+ if (active) return "Reviewing your details to find the best approach";
3807
3806
  if (failed) return "Couldn\u2019t complete this request";
3808
3807
  const hasError = steps.some((step) => step.state === "error");
3809
3808
  const specialists = steps.filter(
@@ -3912,7 +3911,7 @@ function AgentActivityBubble({
3912
3911
  }
3913
3912
  ),
3914
3913
  workSummary(steps, failed, brandLabel),
3915
- active ? "\u2026" : ""
3914
+ active ? "..." : ""
3916
3915
  ] }),
3917
3916
  !active ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "agent-activity-bubble__details", children: [
3918
3917
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
@@ -4947,7 +4946,7 @@ function MessageBubble({
4947
4946
  /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
4948
4947
  import_streamdown.Streamdown,
4949
4948
  {
4950
- animated: isStreaming,
4949
+ animated: false,
4951
4950
  caret: "circle",
4952
4951
  className: "message-bubble__markdown",
4953
4952
  controls: false,
@@ -6455,14 +6454,21 @@ function AgentRail({
6455
6454
  const activeVisitorToolInput = [...visitorToolResults].reverse().find((result) => result.kind === "input");
6456
6455
  const visibleVisitorToolResults = activeVisitorToolInput ? [activeVisitorToolInput] : visitorToolResults;
6457
6456
  const activityActive = state.toolSteps.some((step) => step.state === "active");
6458
- const showActivity = state.toolSteps.length > 0 && pendingInputRequests.length === 0 && !state.pendingOffer && activityActive;
6457
+ const showActivity = state.toolSteps.length > 0 && pendingInputRequests.length === 0 && !state.pendingOffer && (activityActive || isBusy && !state.streamingText);
6458
+ const activitySteps = activityActive || !isBusy || state.streamingText ? state.toolSteps : [...state.toolSteps, {
6459
+ id: "preparing-answer",
6460
+ kind: "tool",
6461
+ label: "Preparing your answer",
6462
+ detail: "Preparing your answer",
6463
+ state: "active"
6464
+ }];
6459
6465
  const hasVisitorMessages2 = state.messages.some(
6460
6466
  (message) => message.role === "visitor"
6461
6467
  );
6462
6468
  const hasAgentResponseAfterVisitor = state.messages.some(
6463
6469
  (message) => message.role === "agent" && message.id !== "greeting"
6464
6470
  );
6465
- const showDisclaimerLabel = Boolean(resolvedDisclaimerLabel) && hasVisitorMessages2 && (hasAgentResponseAfterVisitor || state.phase === "streaming" && Boolean(state.streamingText));
6471
+ const showDisclaimerLabel = Boolean(resolvedDisclaimerLabel) && hasVisitorMessages2 && (hasAgentResponseAfterVisitor || Boolean(state.streamingText));
6466
6472
  const showIdleFollowUps = !hasVisitorMessages2 && state.followUps.length > 0;
6467
6473
  const greeting = state.messages.find(
6468
6474
  (message) => message.role === "agent" && message.id === "greeting"
@@ -6485,11 +6491,11 @@ function AgentRail({
6485
6491
  }
6486
6492
  const lastIsAgent = lastMessage?.role === "agent";
6487
6493
  const showMessageActions = state.phase === "complete" && lastIsAgent && hasVisitorMessages2 && Boolean(hideToolCardFences(lastMessage.text).trim());
6488
- const streamingMessage = state.phase === "streaming" && state.streamingText && !lastIsAgent ? {
6494
+ const streamingMessage = state.streamingText && !lastIsAgent ? {
6489
6495
  createdAt: 0,
6490
6496
  id: "streaming-response",
6491
6497
  role: "agent",
6492
- streaming: true,
6498
+ streaming: isBusy,
6493
6499
  text: state.streamingText,
6494
6500
  searchResults: (state.toolResults ?? []).filter(
6495
6501
  (result) => result.kind === "search"
@@ -6501,6 +6507,7 @@ function AgentRail({
6501
6507
  streaming: false,
6502
6508
  text: "Pick a date and time that works for you."
6503
6509
  } : null;
6510
+ const transcriptMessages = streamingMessage ? [...visibleMessages, streamingMessage] : visibleMessages;
6504
6511
  const bookingReadyText = state.streamingText || (lastIsAgent && lastMessage?.role === "agent" ? lastMessage.text : "");
6505
6512
  const waitingForBooking = !state.pendingOffer && looksLikeBookingReady(bookingReadyText) && (state.phase === "thinking" || state.phase === "running-tools" || state.phase === "streaming");
6506
6513
  const lastAgentText = lastIsAgent && lastMessage?.role === "agent" ? lastMessage.text : "";
@@ -6733,7 +6740,7 @@ function AgentRail({
6733
6740
  brandLabel: resolvedBrandLabel,
6734
6741
  brandLogoUrl: showBrandLogo ? resolvedBrandLogoUrl : void 0,
6735
6742
  failed: state.phase === "error",
6736
- steps: state.toolSteps
6743
+ steps: activitySteps
6737
6744
  }
6738
6745
  ) : null,
6739
6746
  visibleVisitorToolResults.map((result) => /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
@@ -6754,7 +6761,7 @@ function AgentRail({
6754
6761
  request.requestId
6755
6762
  ))
6756
6763
  ] }) : null,
6757
- visibleMessages.map((message, index) => /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(
6764
+ transcriptMessages.map((message, index) => /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(
6758
6765
  "div",
6759
6766
  {
6760
6767
  ref: index === lastVisitorIndex + 1 ? responseRef : void 0,
@@ -6767,7 +6774,7 @@ function AgentRail({
6767
6774
  message,
6768
6775
  bookingDisabled: isBusy,
6769
6776
  brandLogoUrl: showBrandLogo ? resolvedBrandLogoUrl : void 0,
6770
- offer: index === lastAgentIndex ? state.pendingOffer : void 0,
6777
+ offer: index === transcriptMessages.length - 1 ? state.pendingOffer : void 0,
6771
6778
  onBook
6772
6779
  }
6773
6780
  ),
@@ -6790,7 +6797,7 @@ function AgentRail({
6790
6797
  brandLabel: resolvedBrandLabel,
6791
6798
  brandLogoUrl: showBrandLogo ? resolvedBrandLogoUrl : void 0,
6792
6799
  failed: state.phase === "error",
6793
- steps: state.toolSteps
6800
+ steps: activitySteps
6794
6801
  }
6795
6802
  ) : null,
6796
6803
  visibleVisitorToolResults.map((result) => /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
@@ -6813,18 +6820,8 @@ function AgentRail({
6813
6820
  ] }) : null
6814
6821
  ]
6815
6822
  },
6816
- message.id
6823
+ message.role === "agent" && transcriptMessages[index - 1]?.role === "visitor" ? `answer-${transcriptMessages[index - 1]?.id}` : message.id
6817
6824
  )),
6818
- streamingMessage ? /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { ref: responseRef, children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
6819
- MessageBubble,
6820
- {
6821
- message: streamingMessage,
6822
- bookingDisabled: isBusy,
6823
- brandLogoUrl: showBrandLogo ? resolvedBrandLogoUrl : void 0,
6824
- offer: state.pendingOffer,
6825
- onBook
6826
- }
6827
- ) }) : null,
6828
6825
  waitingForBooking ? /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(BookingCardLoader, {}) : null,
6829
6826
  state.error ? /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("section", { className: "agent-rail__error", role: "alert", children: [
6830
6827
  /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { children: [
@@ -6887,6 +6884,7 @@ function AgentRail({
6887
6884
  }
6888
6885
 
6889
6886
  // src/react/components/AssistEdgeTab/AssistEdgeTab.tsx
6887
+ var import_react15 = require("react");
6890
6888
  var import_jsx_runtime18 = require("react/jsx-runtime");
6891
6889
  function ChatSparkIcon() {
6892
6890
  return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(
@@ -6961,16 +6959,35 @@ function ChatSparkIcon() {
6961
6959
  }
6962
6960
  );
6963
6961
  }
6964
- function TabMarkIcon({ customIconUrl }) {
6965
- const url = customIconUrl?.trim();
6966
- if (url) {
6962
+ function TabMarkIcon({
6963
+ customIconUrl,
6964
+ logoUrl
6965
+ }) {
6966
+ const custom = customIconUrl?.trim();
6967
+ const logo = logoUrl?.trim();
6968
+ const [customFailed, setCustomFailed] = (0, import_react15.useState)(false);
6969
+ const [logoFailed, setLogoFailed] = (0, import_react15.useState)(false);
6970
+ if (custom && !customFailed) {
6967
6971
  return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
6968
6972
  "img",
6969
6973
  {
6970
6974
  alt: "",
6971
6975
  "aria-hidden": true,
6972
6976
  className: "assist-edge-tab__custom-icon",
6973
- src: url
6977
+ src: custom,
6978
+ onError: () => setCustomFailed(true)
6979
+ }
6980
+ );
6981
+ }
6982
+ if (logo && !logoFailed) {
6983
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
6984
+ "img",
6985
+ {
6986
+ alt: "",
6987
+ "aria-hidden": true,
6988
+ className: "assist-edge-tab__logo",
6989
+ src: logo,
6990
+ onError: () => setLogoFailed(true)
6974
6991
  }
6975
6992
  );
6976
6993
  }
@@ -7033,13 +7050,14 @@ function AssistEdgeTab({
7033
7050
  const visibleLabel = label?.trim() || copy.label;
7034
7051
  const visibleSubLabel = subLabel?.trim() || "";
7035
7052
  const pill = mobile || side === "bottom";
7053
+ const chromeScheme = pill ? "light" : resolvedColorScheme;
7036
7054
  const ariaLabel = visibleSubLabel ? `Open ${visibleLabel} \u2014 ${visibleSubLabel}` : `Open ${visibleLabel}`;
7037
7055
  const alignment = along < 50 ? "start" : along > 50 ? "end" : "center";
7038
- const showLogo = Boolean(logoUrl?.trim()) && !customIconUrl?.trim();
7039
- const resolvedBrandColor = brandColor ?? (resolvedColorScheme === "dark" ? defaultDarkAgentRailTheme.brand : void 0);
7040
- const resolvedBorderColor = resolvedColorScheme === "dark" ? defaultDarkAgentRailTheme.border : borderColor;
7041
- const resolvedSurfaceColor = resolvedColorScheme === "dark" ? defaultDarkAgentRailTheme.surface : surfaceColor;
7042
- const resolvedTextColor = resolvedColorScheme === "dark" ? defaultDarkAgentRailTheme.text : textColor;
7056
+ const resolvedBrandColor = brandColor ?? (chromeScheme === "dark" ? defaultDarkAgentRailTheme.brand : void 0);
7057
+ const resolvedBorderColor = chromeScheme === "dark" ? defaultDarkAgentRailTheme.border : borderColor;
7058
+ const resolvedSurfaceColor = chromeScheme === "dark" ? defaultDarkAgentRailTheme.surface : surfaceColor;
7059
+ const resolvedTextColor = chromeScheme === "dark" ? defaultDarkAgentRailTheme.text : textColor;
7060
+ const markSourceKey = `${customIconUrl?.trim() ?? ""}|${logoUrl?.trim() ?? ""}`;
7043
7061
  const style = {
7044
7062
  "--tab-along": `${along}%`,
7045
7063
  "--tab-inset": `${inset}px`,
@@ -7047,16 +7065,16 @@ function AssistEdgeTab({
7047
7065
  ...brandForeground ? { "--as-visitor-text": brandForeground } : {},
7048
7066
  ...resolvedBorderColor ? { "--as-border": resolvedBorderColor } : {},
7049
7067
  ...fontFamily ? { "--as-font-display": fontFamily } : {},
7050
- ...resolvedSurfaceColor ? { "--as-surface": resolvedSurfaceColor } : {},
7051
- ...resolvedTextColor ? { "--as-text": resolvedTextColor } : {},
7052
- colorScheme: resolvedColorScheme
7068
+ ...pill ? { "--as-surface": "#ffffff", "--as-text": "#171717" } : resolvedSurfaceColor ? { "--as-surface": resolvedSurfaceColor } : {},
7069
+ ...!pill && resolvedTextColor ? { "--as-text": resolvedTextColor } : {},
7070
+ colorScheme: chromeScheme
7053
7071
  };
7054
7072
  return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(
7055
7073
  "button",
7056
7074
  {
7057
7075
  type: "button",
7058
7076
  className: `assist-edge-tab assist-edge-tab--${variant} assist-edge-tab--${side} assist-edge-tab--align-${alignment}${mobile ? " assist-edge-tab--mobile" : ""}${visible ? " is-visible" : ""}`,
7059
- "data-color-scheme": resolvedColorScheme,
7077
+ "data-color-scheme": chromeScheme,
7060
7078
  style,
7061
7079
  "aria-label": ariaLabel,
7062
7080
  "aria-hidden": !visible,
@@ -7072,18 +7090,14 @@ function AssistEdgeTab({
7072
7090
  children: [
7073
7091
  /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("span", { className: "assist-edge-tab__wash assist-edge-tab__wash--light" }),
7074
7092
  /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("span", { className: "assist-edge-tab__wash assist-edge-tab__wash--cool" }),
7075
- /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(TabMarkIcon, { customIconUrl }),
7076
- showLogo ? /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
7077
- "img",
7093
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
7094
+ TabMarkIcon,
7078
7095
  {
7079
- className: "assist-edge-tab__logo",
7080
- src: logoUrl,
7081
- alt: "",
7082
- onError: (event) => {
7083
- event.currentTarget.hidden = true;
7084
- }
7085
- }
7086
- ) : null
7096
+ customIconUrl,
7097
+ logoUrl
7098
+ },
7099
+ markSourceKey
7100
+ )
7087
7101
  ]
7088
7102
  }
7089
7103
  ),
@@ -7092,20 +7106,14 @@ function AssistEdgeTab({
7092
7106
  visibleSubLabel ? /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("span", { className: "assist-edge-tab__sublabel", children: visibleSubLabel }) : null
7093
7107
  ] })
7094
7108
  ] }) : variant === "outline" ? /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(import_jsx_runtime18.Fragment, { children: [
7095
- /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("span", { className: "assist-edge-tab__mark", "aria-hidden": "true", children: [
7096
- /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(TabMarkIcon, { customIconUrl }),
7097
- showLogo ? /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
7098
- "img",
7099
- {
7100
- className: "assist-edge-tab__logo",
7101
- src: logoUrl,
7102
- alt: "",
7103
- onError: (event) => {
7104
- event.currentTarget.hidden = true;
7105
- }
7106
- }
7107
- ) : null
7108
- ] }),
7109
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("span", { className: "assist-edge-tab__mark", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
7110
+ TabMarkIcon,
7111
+ {
7112
+ customIconUrl,
7113
+ logoUrl
7114
+ },
7115
+ markSourceKey
7116
+ ) }),
7109
7117
  /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("span", { className: "assist-edge-tab__label", children: visibleLabel }),
7110
7118
  /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(ChevronDownIcon2, {})
7111
7119
  ] }) : null,
@@ -7115,20 +7123,14 @@ function AssistEdgeTab({
7115
7123
  /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(DragDots, {})
7116
7124
  ] }) : null,
7117
7125
  !pill && variant === "fill" ? /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(import_jsx_runtime18.Fragment, { children: [
7118
- /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("span", { className: "assist-edge-tab__mark", "aria-hidden": "true", children: [
7119
- /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(TabMarkIcon, { customIconUrl }),
7120
- showLogo ? /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
7121
- "img",
7122
- {
7123
- className: "assist-edge-tab__logo",
7124
- src: logoUrl,
7125
- alt: "",
7126
- onError: (event) => {
7127
- event.currentTarget.hidden = true;
7128
- }
7129
- }
7130
- ) : null
7131
- ] }),
7126
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("span", { className: "assist-edge-tab__mark", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
7127
+ TabMarkIcon,
7128
+ {
7129
+ customIconUrl,
7130
+ logoUrl
7131
+ },
7132
+ markSourceKey
7133
+ ) }),
7132
7134
  /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("span", { className: "assist-edge-tab__label", children: visibleLabel }),
7133
7135
  /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(ChevronLeftIcon, {})
7134
7136
  ] }) : null
@@ -7213,9 +7215,9 @@ function AgentWidget({
7213
7215
  }) {
7214
7216
  const isMobile = useIsMobile();
7215
7217
  const placement = normalizeAgentPlacement(placementInput);
7216
- const railSlotRef = (0, import_react15.useRef)(null);
7217
- const [railCollapsed, setRailCollapsed] = (0, import_react15.useState)(defaultCollapsed);
7218
- const [railExpanded, setRailExpanded] = (0, import_react15.useState)(false);
7218
+ const railSlotRef = (0, import_react16.useRef)(null);
7219
+ const [railCollapsed, setRailCollapsed] = (0, import_react16.useState)(defaultCollapsed);
7220
+ const [railExpanded, setRailExpanded] = (0, import_react16.useState)(false);
7219
7221
  const pageShiftActive = shouldApplyPageShift({
7220
7222
  pageShift,
7221
7223
  isMobile,
@@ -7268,7 +7270,7 @@ function AgentWidget({
7268
7270
  } : {},
7269
7271
  ...branding?.colors?.border ? { border: branding.colors.border } : {}
7270
7272
  };
7271
- (0, import_react15.useEffect)(() => {
7273
+ (0, import_react16.useEffect)(() => {
7272
7274
  if (!registerPanelController) return;
7273
7275
  registerAgentPanelController(customerId, {
7274
7276
  open: () => setRailCollapsed(false),
@@ -7303,7 +7305,7 @@ function AgentWidget({
7303
7305
  })
7304
7306
  );
7305
7307
  }
7306
- (0, import_react15.useEffect)(() => {
7308
+ (0, import_react16.useEffect)(() => {
7307
7309
  if (railCollapsed) return;
7308
7310
  const handleKeyDown = (event) => {
7309
7311
  if (event.key === "Tab" && (isMobile || railExpanded)) {
@@ -7413,7 +7415,7 @@ function AgentWidget({
7413
7415
  }
7414
7416
 
7415
7417
  // src/react/components/AgentTranscript/AgentTranscript.tsx
7416
- var import_react16 = require("react");
7418
+ var import_react17 = require("react");
7417
7419
 
7418
7420
  // src/react/components/AgentTranscript/TranscriptActivity.tsx
7419
7421
  var import_jsx_runtime20 = require("react/jsx-runtime");
@@ -7534,7 +7536,7 @@ function AgentTranscript({
7534
7536
  const previous = entries[index - 1];
7535
7537
  const validTimestamp = Number.isFinite(date.getTime());
7536
7538
  const showTimestamp = validTimestamp && (previous ? entry.createdAt - previous.createdAt >= 5 * 60 * 1e3 || date.toISOString().slice(0, 10) !== new Date(previous.createdAt).toJSON()?.slice(0, 10) : showInitialTimestamp);
7537
- return /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(import_react16.Fragment, { children: [
7539
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(import_react17.Fragment, { children: [
7538
7540
  showTimestamp ? /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("li", { className: "agent-transcript__time-marker", children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("time", { dateTime: date.toISOString(), children: formatTimestamp(entry.createdAt) }) }) : null,
7539
7541
  entry.kind === "activity" ? /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(TranscriptActivity, { activity: entry }) : /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(
7540
7542
  "li",