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