@webless/agent 0.9.1 → 0.9.3

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/react.cjs CHANGED
@@ -4798,6 +4798,20 @@ function InteractiveBookingCard({
4798
4798
 
4799
4799
  // src/react/components/MessageBubble/MessageBubble.tsx
4800
4800
  var import_streamdown = require("streamdown");
4801
+
4802
+ // src/react/lib/resolve-message-url.ts
4803
+ function resolveMessageUrl(safeUrl, baseUrl) {
4804
+ if (!safeUrl || !baseUrl) return safeUrl;
4805
+ try {
4806
+ const base = new URL(baseUrl);
4807
+ if (base.protocol !== "https:" && base.protocol !== "http:") return "";
4808
+ return new URL(safeUrl, base).href;
4809
+ } catch {
4810
+ return "";
4811
+ }
4812
+ }
4813
+
4814
+ // src/react/components/MessageBubble/MessageBubble.tsx
4801
4815
  var import_styles = require("streamdown/styles.css");
4802
4816
  var import_jsx_runtime7 = require("react/jsx-runtime");
4803
4817
  function normalizeDedupeText(text2) {
@@ -4840,6 +4854,7 @@ function MessageBubble({
4840
4854
  brandLogoUrl,
4841
4855
  bookingDisabled = false,
4842
4856
  bookingReadOnly = false,
4857
+ linkBaseUrl,
4843
4858
  offer,
4844
4859
  onBook
4845
4860
  }) {
@@ -4872,6 +4887,10 @@ function MessageBubble({
4872
4887
  isAnimating: isStreaming,
4873
4888
  linkSafety: { enabled: false },
4874
4889
  mode: isStreaming ? "streaming" : "static",
4890
+ urlTransform: (url, key, node) => resolveMessageUrl(
4891
+ (0, import_streamdown.defaultUrlTransform)(url, key, node) ?? "",
4892
+ key === "href" ? linkBaseUrl : void 0
4893
+ ),
4875
4894
  skipHtml: true,
4876
4895
  children: displayText
4877
4896
  }
@@ -4889,7 +4908,8 @@ function MessageBubble({
4889
4908
  /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { children: citation.label })
4890
4909
  ] }) }, citation.id)) }) : null
4891
4910
  ] });
4892
- if (!displayText && !message.searchResults?.length && offers.length === 0) return null;
4911
+ if (!displayText && !message.searchResults?.length && offers.length === 0)
4912
+ return null;
4893
4913
  return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("article", { className: "message-bubble message-bubble--agent", children: [
4894
4914
  displayText || message.searchResults?.length ? showBrandLogo ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "message-bubble__agent-row", children: [
4895
4915
  /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "message-bubble__agent-avatar", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
@@ -7272,6 +7292,9 @@ function AgentWidget({
7272
7292
  ] });
7273
7293
  }
7274
7294
 
7295
+ // src/react/components/AgentTranscript/AgentTranscript.tsx
7296
+ var import_react16 = require("react");
7297
+
7275
7298
  // src/react/components/AgentTranscript/TranscriptActivity.tsx
7276
7299
  var import_jsx_runtime20 = require("react/jsx-runtime");
7277
7300
  var statusLabels = {
@@ -7299,16 +7322,12 @@ function RecordedResult({
7299
7322
  return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(VisitorToolResultView, { disabled: true, result });
7300
7323
  }
7301
7324
  function TranscriptActivity({
7302
- activity,
7303
- formatTimestamp
7325
+ activity
7304
7326
  }) {
7305
- const date = new Date(activity.createdAt);
7306
- const validTimestamp = Number.isFinite(date.getTime());
7307
7327
  const result = activity.result?.kind === "hidden" ? void 0 : activity.result;
7308
7328
  const heading = /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(import_jsx_runtime20.Fragment, { children: [
7309
7329
  /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("span", { children: activity.category === "specialist" ? `Specialist \xB7 ${activity.label}` : activity.label }),
7310
- activity.status !== "completed" ? /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("span", { className: "agent-transcript__activity-status", children: statusLabels[activity.status] }) : null,
7311
- validTimestamp ? /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("time", { dateTime: date.toISOString(), children: formatTimestamp(activity.createdAt) }) : null
7330
+ activity.status !== "completed" ? /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("span", { className: "agent-transcript__activity-status", children: statusLabels[activity.status] }) : null
7312
7331
  ] });
7313
7332
  return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("li", { className: "agent-transcript__activity", "data-status": activity.status, children: result ? /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("details", { children: [
7314
7333
  /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("summary", { className: "agent-transcript__activity-heading", children: heading }),
@@ -7367,10 +7386,12 @@ function AgentTranscript({
7367
7386
  activities = [],
7368
7387
  theme,
7369
7388
  colorScheme,
7389
+ linkBaseUrl,
7370
7390
  agentLabel = "Agent",
7371
7391
  visitorLabel = "Visitor",
7372
7392
  label = "Conversation transcript",
7373
- formatTimestamp = defaultTimestamp
7393
+ formatTimestamp = defaultTimestamp,
7394
+ showInitialTimestamp = true
7374
7395
  }) {
7375
7396
  const scheme = useAgentColorScheme(colorScheme);
7376
7397
  const entries = [
@@ -7388,41 +7409,32 @@ function AgentTranscript({
7388
7409
  "data-color-scheme": scheme,
7389
7410
  "aria-label": label,
7390
7411
  style: agentThemeStyle(theme, scheme),
7391
- children: entries.map((message) => {
7392
- if (message.kind === "activity")
7393
- return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
7394
- TranscriptActivity,
7395
- {
7396
- activity: message,
7397
- formatTimestamp
7398
- },
7399
- message.id
7400
- );
7401
- if (message.role === "visitor" && !message.text.trim()) return null;
7402
- const date = new Date(message.createdAt);
7412
+ children: entries.map((entry, index) => {
7413
+ const date = new Date(entry.createdAt);
7414
+ const previous = entries[index - 1];
7403
7415
  const validTimestamp = Number.isFinite(date.getTime());
7404
- return /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(
7405
- "li",
7406
- {
7407
- className: `agent-transcript__message agent-transcript__message--${message.role}`,
7408
- children: [
7409
- /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "agent-transcript__meta", children: [
7410
- /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("span", { children: message.role === "visitor" ? visitorLabel : agentLabel }),
7411
- validTimestamp ? /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("time", { dateTime: date.toISOString(), children: formatTimestamp(message.createdAt) }) : null
7412
- ] }),
7413
- message.role === "agent" ? message.toolResults?.map((result) => /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(VisitorToolResultView, { result }, result.id)) : null,
7414
- /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
7415
- MessageBubble,
7416
- {
7417
- message: message.role === "agent" ? { ...message, streaming: false } : message,
7418
- bookingReadOnly: true,
7419
- bookingDisabled: true
7420
- }
7421
- )
7422
- ]
7423
- },
7424
- message.id
7425
- );
7416
+ 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);
7417
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(import_react16.Fragment, { children: [
7418
+ 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,
7419
+ entry.kind === "activity" ? /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(TranscriptActivity, { activity: entry }) : /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(
7420
+ "li",
7421
+ {
7422
+ className: `agent-transcript__message agent-transcript__message--${entry.role}`,
7423
+ children: [
7424
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "agent-transcript__meta", children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("span", { children: entry.role === "visitor" ? visitorLabel : agentLabel }) }),
7425
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
7426
+ MessageBubble,
7427
+ {
7428
+ message: entry.role === "agent" ? { ...entry, streaming: false } : entry,
7429
+ linkBaseUrl,
7430
+ bookingReadOnly: true,
7431
+ bookingDisabled: true
7432
+ }
7433
+ )
7434
+ ]
7435
+ }
7436
+ )
7437
+ ] }, `${entry.kind}:${entry.id}`);
7426
7438
  })
7427
7439
  }
7428
7440
  );