@ensembleapp/client-sdk 0.0.19 → 0.0.21

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.d.ts CHANGED
@@ -245,8 +245,12 @@ interface ChatWidgetFeedbackOptions {
245
245
  interface ChatWidgetConfig extends UseChatConfig {
246
246
  /** Title for the Chat window */
247
247
  title?: string;
248
- /** Introductory message displayed at the start of the chat for brand new threads */
249
- introMessage?: string;
248
+ /** Initial assistant message displayed at the start of the chat (if history is empty).
249
+ * Skipped if initialUserMessage is provided. */
250
+ initialAssistantMessage?: string;
251
+ /** Initial user message to send automatically when the chat loads (if history is empty).
252
+ * Use this to kick-start the conversation without requiring user input. */
253
+ initialUserMessage?: string;
250
254
  /** Placeholder text for the input box */
251
255
  inputPlaceholder?: string;
252
256
  className?: string;
@@ -257,7 +261,7 @@ interface ChatWidgetConfig extends UseChatConfig {
257
261
  /** Feedback options for assistant messages. Enabled by default. */
258
262
  feedback?: ChatWidgetFeedbackOptions;
259
263
  }
260
- declare function ChatWidget({ api, threadId, agentId, agentExecutionId, dataContext, onError, onAuthError, onFinish, onMessage, title, introMessage, inputPlaceholder, className, styles: styleProps, voice, speechToText, widgets, feedback, }: ChatWidgetConfig): react_jsx_runtime.JSX.Element;
264
+ declare function ChatWidget({ api, threadId, agentId, agentExecutionId, dataContext, onError, onAuthError, onFinish, onMessage, title, initialAssistantMessage, initialUserMessage, inputPlaceholder, className, styles: styleProps, voice, speechToText, widgets, feedback, }: ChatWidgetConfig): react_jsx_runtime.JSX.Element;
261
265
 
262
266
  interface PopupAnchorConfig {
263
267
  enabled?: boolean;
package/dist/index.js CHANGED
@@ -18684,10 +18684,9 @@ function useChat({
18684
18684
  onData?.(dataPart);
18685
18685
  }
18686
18686
  });
18687
- const [isLoadingInitial, setIsLoadingInitial] = useState(false);
18687
+ const [isLoadingInitial, setIsLoadingInitial] = useState(true);
18688
18688
  useEffect(() => {
18689
18689
  const fetchInitialMessages = async () => {
18690
- setIsLoadingInitial(true);
18691
18690
  try {
18692
18691
  const response = await fetch(`${baseUrl}/chat/messages`, {
18693
18692
  method: "GET",
@@ -24422,7 +24421,8 @@ function ChatWidget({
24422
24421
  onFinish,
24423
24422
  onMessage,
24424
24423
  title,
24425
- introMessage,
24424
+ initialAssistantMessage,
24425
+ initialUserMessage,
24426
24426
  inputPlaceholder,
24427
24427
  className,
24428
24428
  styles: styleProps,
@@ -24466,6 +24466,7 @@ function ChatWidget({
24466
24466
  const {
24467
24467
  messages,
24468
24468
  status,
24469
+ isLoadingInitial,
24469
24470
  sendMessage,
24470
24471
  stop,
24471
24472
  setMessages
@@ -24532,14 +24533,21 @@ function ChatWidget({
24532
24533
  };
24533
24534
  }, [voice]);
24534
24535
  useEffect4(() => {
24535
- if (introMessage && messages.length === 0) {
24536
+ if (initialAssistantMessage && !initialUserMessage && !isLoadingInitial && messages.length === 0) {
24536
24537
  setMessages([{
24537
24538
  id: "welcome-message",
24538
24539
  role: "assistant",
24539
- parts: [{ type: "text", text: introMessage }]
24540
+ parts: [{ type: "text", text: initialAssistantMessage }]
24540
24541
  }]);
24541
24542
  }
24542
- }, [introMessage, messages.length, setMessages]);
24543
+ }, [initialAssistantMessage, initialUserMessage, isLoadingInitial, messages.length, setMessages]);
24544
+ const initialMessageSentRef = useRef3(false);
24545
+ useEffect4(() => {
24546
+ if (initialUserMessage && !initialMessageSentRef.current && !isLoadingInitial && status === "ready" && messages.length === 0) {
24547
+ initialMessageSentRef.current = true;
24548
+ sendMessage({ text: initialUserMessage });
24549
+ }
24550
+ }, [initialUserMessage, isLoadingInitial, status, messages.length, sendMessage]);
24543
24551
  const handleScroll = useCallback4(() => {
24544
24552
  if (!scrollContainerRef.current) return;
24545
24553
  const { scrollTop, scrollHeight, clientHeight } = scrollContainerRef.current;
@@ -24908,7 +24916,7 @@ function VendorCards({ payload, enriched }) {
24908
24916
  };
24909
24917
  return /* @__PURE__ */ jsx8("div", { style: { display: "flex", flexDirection: "column", gap: "0.75rem" }, children: payload.vendors.map((v, index) => {
24910
24918
  const data = vendorData[v.vendor_id];
24911
- const name17 = data?.names?.find((n) => n.type === "org")?.value ?? "";
24919
+ const name17 = data?.names?.[0]?.value ?? "Unknown";
24912
24920
  const address = data?.location?.address;
24913
24921
  const distanceEntry = distances.find((d) => d.destinationIndex === index);
24914
24922
  const distance = distanceEntry && distanceEntry.distanceMeters ? formatDistance(distanceEntry.distanceMeters) : void 0;