@ensembleapp/client-sdk 0.0.21 → 0.0.23
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 +7 -11
- package/dist/index.js +104 -105
- package/dist/index.js.map +1 -1
- package/dist/widget/widget.global.js +26 -26
- package/dist/widget/widget.global.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -83,8 +83,8 @@ type UseChatConfig = DeprecatedChatConfig & {
|
|
|
83
83
|
/** additional context (anything) that needs to be passed to the LLM */
|
|
84
84
|
dataContext?: unknown;
|
|
85
85
|
onError?: (error: Error) => void;
|
|
86
|
-
/** Called when API returns 401/unauthorized (e.g., token expiry) */
|
|
87
|
-
onAuthError?: () =>
|
|
86
|
+
/** Called when API returns 401/unauthorized (e.g., token expiry). Return a new token to retry the request. */
|
|
87
|
+
onAuthError?: () => Promise<string | null>;
|
|
88
88
|
onFinish?: (message: any) => void;
|
|
89
89
|
onData?: (data: any) => void;
|
|
90
90
|
onMessage?: (message: UIMessage) => void;
|
|
@@ -315,18 +315,13 @@ type RegisterChatWidgetsParams = {
|
|
|
315
315
|
api: ApiConfig;
|
|
316
316
|
threadId: string;
|
|
317
317
|
widgets: UIWidgetDefinition[];
|
|
318
|
+
/** Called when API returns 401/unauthorized. Return a new token to retry the request. */
|
|
319
|
+
onAuthError?: () => Promise<string | null>;
|
|
318
320
|
};
|
|
319
321
|
/**
|
|
320
322
|
* Registers widget definitions for a specific thread so the server can render them.
|
|
321
323
|
*/
|
|
322
|
-
declare function registerChatWidgets({ api, threadId, widgets, }: RegisterChatWidgetsParams): Promise<void>;
|
|
323
|
-
|
|
324
|
-
interface ChatWidgetInstance {
|
|
325
|
-
updateProps: (props: Partial<ChatWidgetConfig>) => void;
|
|
326
|
-
updateTheme: (styles: ChatWidgetStyles) => void;
|
|
327
|
-
unmount: () => void;
|
|
328
|
-
}
|
|
329
|
-
declare const createChatWidget: (target: HTMLElement, props: ChatWidgetConfig) => ChatWidgetInstance;
|
|
324
|
+
declare function registerChatWidgets({ api, threadId, widgets, onAuthError, }: RegisterChatWidgetsParams): Promise<void>;
|
|
330
325
|
|
|
331
326
|
/**
|
|
332
327
|
* Embeddable Chat Widget
|
|
@@ -351,7 +346,8 @@ declare global {
|
|
|
351
346
|
}
|
|
352
347
|
|
|
353
348
|
declare const defaultChatWidgets: UIWidgetDefinition[];
|
|
349
|
+
declare const getVendorCardsWidget: (isProd?: boolean) => UIWidgetDefinition[];
|
|
354
350
|
|
|
355
351
|
declare function cn(...inputs: ClassValue[]): string;
|
|
356
352
|
|
|
357
|
-
export { type ApiConfig, type ChatContentItem, type ChatMessage, ChatWidget, type ChatWidgetFeedbackOptions, type
|
|
353
|
+
export { type ApiConfig, type ChatContentItem, type ChatMessage, ChatWidget, type ChatWidgetFeedbackOptions, type ChatWidgetConfig as ChatWidgetProps, type ChatWidgetSpeechToTextOptions, type ChatWidgetStyles, type ChatWidgetVoiceOptions, type EmbeddableChatWidgetConfig, type EnrichedResults, type FeedbackRating, type FeedbackState, type MessageFeedback, type MessageSection, type PopupAnchorConfig, PopupChatWidget, type PopupChatWidgetProps, type SubmitFeedbackParams, type TagGroup, TagGroupDisplay, type TagGroupDisplayProps, type ToolCallContent, ToolCallDisplay, type ToolCallDisplayProps, type UIWidgetDefinition, type UseChatConfig, type UseFeedbackConfig, type WidgetEnrichConfig, cn, createWidget, defaultChatWidgets, getVendorCardsWidget, registerChatWidgets, useChat, useFeedback };
|
package/dist/index.js
CHANGED
|
@@ -18628,6 +18628,26 @@ var DefaultChatTransport = class extends HttpChatTransport {
|
|
|
18628
18628
|
|
|
18629
18629
|
// lib/hooks/useChat.ts
|
|
18630
18630
|
import { useEffect, useMemo, useRef, useState } from "react";
|
|
18631
|
+
function createAuthAwareFetch(tokenRef, onAuthError) {
|
|
18632
|
+
return async (input, init) => {
|
|
18633
|
+
const doFetch = (token) => fetch(input, {
|
|
18634
|
+
...init,
|
|
18635
|
+
headers: {
|
|
18636
|
+
...init?.headers,
|
|
18637
|
+
Authorization: `Bearer ${token}`
|
|
18638
|
+
}
|
|
18639
|
+
});
|
|
18640
|
+
const response = await doFetch(tokenRef.current);
|
|
18641
|
+
if (response.status === 401 && onAuthError) {
|
|
18642
|
+
const newToken = await onAuthError();
|
|
18643
|
+
if (newToken) {
|
|
18644
|
+
tokenRef.current = newToken;
|
|
18645
|
+
return doFetch(newToken);
|
|
18646
|
+
}
|
|
18647
|
+
}
|
|
18648
|
+
return response;
|
|
18649
|
+
};
|
|
18650
|
+
}
|
|
18631
18651
|
function useChat({
|
|
18632
18652
|
api,
|
|
18633
18653
|
threadId,
|
|
@@ -18643,11 +18663,19 @@ function useChat({
|
|
|
18643
18663
|
const { baseUrl, token, headers: customHeaders = {} } = api;
|
|
18644
18664
|
const dataContextRef = useRef(dataContext);
|
|
18645
18665
|
dataContextRef.current = dataContext;
|
|
18666
|
+
const tokenRef = useRef(token);
|
|
18667
|
+
tokenRef.current = token;
|
|
18668
|
+
const onAuthErrorRef = useRef(onAuthError);
|
|
18669
|
+
onAuthErrorRef.current = onAuthError;
|
|
18670
|
+
const authFetch = useMemo(
|
|
18671
|
+
() => createAuthAwareFetch(tokenRef, async () => onAuthErrorRef.current?.() ?? null),
|
|
18672
|
+
[]
|
|
18673
|
+
);
|
|
18646
18674
|
const transport = useMemo(() => new DefaultChatTransport({
|
|
18647
18675
|
api: `${baseUrl}/chat`,
|
|
18676
|
+
fetch: authFetch,
|
|
18648
18677
|
headers: {
|
|
18649
18678
|
"Content-Type": "application/json",
|
|
18650
|
-
Authorization: `Bearer ${token}`,
|
|
18651
18679
|
"thread-id": threadId,
|
|
18652
18680
|
...agentId ? { "agent-id": agentId } : {},
|
|
18653
18681
|
...agentExecutionId ? { "agent-execution-id": agentExecutionId } : {},
|
|
@@ -18663,7 +18691,7 @@ function useChat({
|
|
|
18663
18691
|
}
|
|
18664
18692
|
};
|
|
18665
18693
|
}
|
|
18666
|
-
}), [baseUrl,
|
|
18694
|
+
}), [baseUrl, authFetch, threadId, agentId, agentExecutionId, customHeaders]);
|
|
18667
18695
|
const {
|
|
18668
18696
|
messages,
|
|
18669
18697
|
status,
|
|
@@ -18688,17 +18716,13 @@ function useChat({
|
|
|
18688
18716
|
useEffect(() => {
|
|
18689
18717
|
const fetchInitialMessages = async () => {
|
|
18690
18718
|
try {
|
|
18691
|
-
const response = await
|
|
18719
|
+
const response = await authFetch(`${baseUrl}/chat/messages`, {
|
|
18692
18720
|
method: "GET",
|
|
18693
18721
|
headers: {
|
|
18694
|
-
Authorization: `Bearer ${token}`,
|
|
18695
18722
|
"thread-id": threadId
|
|
18696
18723
|
}
|
|
18697
18724
|
});
|
|
18698
18725
|
if (!response.ok) {
|
|
18699
|
-
if (response.status === 401) {
|
|
18700
|
-
onAuthError?.();
|
|
18701
|
-
}
|
|
18702
18726
|
throw new Error(`Failed to fetch messages: ${response.statusText}`);
|
|
18703
18727
|
}
|
|
18704
18728
|
const data = await response.json();
|
|
@@ -18714,7 +18738,7 @@ function useChat({
|
|
|
18714
18738
|
}
|
|
18715
18739
|
};
|
|
18716
18740
|
fetchInitialMessages();
|
|
18717
|
-
}, [agentExecutionId, agentId, baseUrl,
|
|
18741
|
+
}, [agentExecutionId, agentId, authFetch, baseUrl, onError, setMessages, threadId]);
|
|
18718
18742
|
useEffect(() => {
|
|
18719
18743
|
if (!onMessage || messages.length === 0) return;
|
|
18720
18744
|
const lastMessage = messages[messages.length - 1];
|
|
@@ -23666,7 +23690,8 @@ var toJsonSchema = zodToJsonSchema;
|
|
|
23666
23690
|
async function registerChatWidgets({
|
|
23667
23691
|
api,
|
|
23668
23692
|
threadId,
|
|
23669
|
-
widgets
|
|
23693
|
+
widgets,
|
|
23694
|
+
onAuthError
|
|
23670
23695
|
}) {
|
|
23671
23696
|
const widgetSchemas = widgets.map(({ widgetType, schema, enrich }) => {
|
|
23672
23697
|
const extendedSchema = schema.extend({
|
|
@@ -23678,8 +23703,8 @@ async function registerChatWidgets({
|
|
|
23678
23703
|
enrich
|
|
23679
23704
|
};
|
|
23680
23705
|
});
|
|
23681
|
-
const { baseUrl,
|
|
23682
|
-
const
|
|
23706
|
+
const { baseUrl, headers: customHeaders = {} } = api;
|
|
23707
|
+
const doFetch = (token) => fetch(`${baseUrl}/chat/widgets`, {
|
|
23683
23708
|
method: "POST",
|
|
23684
23709
|
headers: {
|
|
23685
23710
|
"Content-Type": "application/json",
|
|
@@ -23689,6 +23714,13 @@ async function registerChatWidgets({
|
|
|
23689
23714
|
},
|
|
23690
23715
|
body: JSON.stringify({ widgetSchemas })
|
|
23691
23716
|
});
|
|
23717
|
+
let response = await doFetch(api.token);
|
|
23718
|
+
if (response.status === 401 && onAuthError) {
|
|
23719
|
+
const newToken = await onAuthError();
|
|
23720
|
+
if (newToken) {
|
|
23721
|
+
response = await doFetch(newToken);
|
|
23722
|
+
}
|
|
23723
|
+
}
|
|
23692
23724
|
if (!response.ok) {
|
|
23693
23725
|
const message = await response.text().catch(() => response.statusText);
|
|
23694
23726
|
throw new Error(`Failed to register chat widgets: ${response.status} ${message}`);
|
|
@@ -24625,12 +24657,12 @@ function ChatWidget({
|
|
|
24625
24657
|
if (!widgets || widgets.length === 0) return;
|
|
24626
24658
|
const alreadyRegistered = lastRegisteredRef.current.threadId === threadId && lastRegisteredRef.current.widgets === widgets;
|
|
24627
24659
|
if (alreadyRegistered) return;
|
|
24628
|
-
registerChatWidgets({ api, threadId, widgets }).then(() => {
|
|
24660
|
+
registerChatWidgets({ api, threadId, widgets, onAuthError }).then(() => {
|
|
24629
24661
|
lastRegisteredRef.current = { threadId, widgets };
|
|
24630
24662
|
}).catch((err) => {
|
|
24631
24663
|
console.error("Failed to register chat widgets", err);
|
|
24632
24664
|
});
|
|
24633
|
-
}, [api, threadId, widgets]);
|
|
24665
|
+
}, [api, threadId, widgets, onAuthError]);
|
|
24634
24666
|
return /* @__PURE__ */ jsxs5(
|
|
24635
24667
|
"div",
|
|
24636
24668
|
{
|
|
@@ -24834,45 +24866,6 @@ function PopupChatWidget({ anchor, ...props }) {
|
|
|
24834
24866
|
] });
|
|
24835
24867
|
}
|
|
24836
24868
|
|
|
24837
|
-
// lib/createChatWidget.tsx
|
|
24838
|
-
import { createRoot } from "react-dom/client";
|
|
24839
|
-
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
24840
|
-
var createChatWidget = (target, props) => {
|
|
24841
|
-
if (!target) {
|
|
24842
|
-
throw new Error("createChatWidget requires a valid DOM element to mount into.");
|
|
24843
|
-
}
|
|
24844
|
-
const root2 = createRoot(target);
|
|
24845
|
-
let currentProps = props;
|
|
24846
|
-
const render = () => {
|
|
24847
|
-
root2.render(/* @__PURE__ */ jsx7(ChatWidget, { ...currentProps }));
|
|
24848
|
-
};
|
|
24849
|
-
render();
|
|
24850
|
-
const mergeStyles = (nextStyles) => ({
|
|
24851
|
-
...currentProps.styles,
|
|
24852
|
-
...nextStyles
|
|
24853
|
-
});
|
|
24854
|
-
return {
|
|
24855
|
-
updateProps(nextProps) {
|
|
24856
|
-
currentProps = {
|
|
24857
|
-
...currentProps,
|
|
24858
|
-
...nextProps,
|
|
24859
|
-
styles: mergeStyles(nextProps.styles)
|
|
24860
|
-
};
|
|
24861
|
-
render();
|
|
24862
|
-
},
|
|
24863
|
-
updateTheme(nextStyles) {
|
|
24864
|
-
currentProps = {
|
|
24865
|
-
...currentProps,
|
|
24866
|
-
styles: mergeStyles(nextStyles)
|
|
24867
|
-
};
|
|
24868
|
-
render();
|
|
24869
|
-
},
|
|
24870
|
-
unmount() {
|
|
24871
|
-
root2.unmount();
|
|
24872
|
-
}
|
|
24873
|
-
};
|
|
24874
|
-
};
|
|
24875
|
-
|
|
24876
24869
|
// lib/model.ts
|
|
24877
24870
|
var createWidget = ({
|
|
24878
24871
|
widgetType,
|
|
@@ -24887,7 +24880,7 @@ var createWidget = ({
|
|
|
24887
24880
|
});
|
|
24888
24881
|
|
|
24889
24882
|
// lib/widgets/VendorCards.tsx
|
|
24890
|
-
import { jsx as
|
|
24883
|
+
import { jsx as jsx7, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
24891
24884
|
var vendorCardsSchema = zod_default.object({
|
|
24892
24885
|
fromLocation: zod_default.string().describe("The location the user is searching for"),
|
|
24893
24886
|
fromCoordinates: zod_default.object({
|
|
@@ -24905,7 +24898,7 @@ var vendorCardsSchema = zod_default.object({
|
|
|
24905
24898
|
}).describe("displaying a list of vendor cards. Use this widget to represent data from CareNetwork vendor search tool.");
|
|
24906
24899
|
function VendorCards({ payload, enriched }) {
|
|
24907
24900
|
if (!enriched || !enriched.vendorDetails || !enriched.distanceMatrix) {
|
|
24908
|
-
return /* @__PURE__ */
|
|
24901
|
+
return /* @__PURE__ */ jsx7("div", { children: "Outdated vendor-cards widget" });
|
|
24909
24902
|
}
|
|
24910
24903
|
const { vendorDetails, distanceMatrix } = enriched;
|
|
24911
24904
|
const vendorData = vendorDetails?.data ?? {};
|
|
@@ -24914,7 +24907,7 @@ function VendorCards({ payload, enriched }) {
|
|
|
24914
24907
|
const miles = meters / 1609.34;
|
|
24915
24908
|
return miles < 0.1 ? "< 0.1 mi" : `${miles.toFixed(1)} mi`;
|
|
24916
24909
|
};
|
|
24917
|
-
return /* @__PURE__ */
|
|
24910
|
+
return /* @__PURE__ */ jsx7("div", { style: { display: "flex", flexDirection: "column", gap: "0.75rem" }, children: payload.vendors.map((v, index) => {
|
|
24918
24911
|
const data = vendorData[v.vendor_id];
|
|
24919
24912
|
const name17 = data?.names?.[0]?.value ?? "Unknown";
|
|
24920
24913
|
const address = data?.location?.address;
|
|
@@ -24940,8 +24933,8 @@ function VendorCards({ payload, enriched }) {
|
|
|
24940
24933
|
fontSize: "0.875rem"
|
|
24941
24934
|
},
|
|
24942
24935
|
children: [
|
|
24943
|
-
/* @__PURE__ */
|
|
24944
|
-
/* @__PURE__ */
|
|
24936
|
+
/* @__PURE__ */ jsx7("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "flex-start" }, children: /* @__PURE__ */ jsxs7("div", { style: { display: "flex", alignItems: "center", gap: "0.5rem" }, children: [
|
|
24937
|
+
/* @__PURE__ */ jsx7("div", { style: {
|
|
24945
24938
|
width: "2rem",
|
|
24946
24939
|
height: "2rem",
|
|
24947
24940
|
borderRadius: "9999px",
|
|
@@ -24953,20 +24946,20 @@ function VendorCards({ payload, enriched }) {
|
|
|
24953
24946
|
fontSize: "0.875rem",
|
|
24954
24947
|
color: "#374151"
|
|
24955
24948
|
}, children: name17.charAt(0).toUpperCase() }),
|
|
24956
|
-
/* @__PURE__ */
|
|
24949
|
+
/* @__PURE__ */ jsx7("span", { style: { fontWeight: 600, fontSize: "1rem", color: "#111827" }, children: name17 })
|
|
24957
24950
|
] }) }),
|
|
24958
24951
|
/* @__PURE__ */ jsxs7("div", { style: { display: "flex", alignItems: "center", gap: "0.5rem", color: "#6b7280" }, children: [
|
|
24959
|
-
/* @__PURE__ */
|
|
24960
|
-
/* @__PURE__ */
|
|
24952
|
+
/* @__PURE__ */ jsx7("span", { style: { color: "#facc15" }, children: "\u2605" }),
|
|
24953
|
+
/* @__PURE__ */ jsx7("span", { children: avgRating?.toFixed(1) ?? "\u2014" }),
|
|
24961
24954
|
/* @__PURE__ */ jsxs7("span", { style: { color: "#9ca3af" }, children: [
|
|
24962
24955
|
"(",
|
|
24963
24956
|
reviewCount ?? 0,
|
|
24964
24957
|
" reviews)"
|
|
24965
24958
|
] })
|
|
24966
24959
|
] }),
|
|
24967
|
-
address && /* @__PURE__ */
|
|
24960
|
+
address && /* @__PURE__ */ jsx7("div", { style: { color: "#6b7280" }, children: address }),
|
|
24968
24961
|
distance && /* @__PURE__ */ jsxs7("div", { style: { display: "flex", alignItems: "center", gap: "0.25rem", color: "#6b7280" }, children: [
|
|
24969
|
-
/* @__PURE__ */
|
|
24962
|
+
/* @__PURE__ */ jsx7("span", { children: "\u{1F4CD}" }),
|
|
24970
24963
|
/* @__PURE__ */ jsxs7("span", { children: [
|
|
24971
24964
|
distance,
|
|
24972
24965
|
" from ",
|
|
@@ -24974,7 +24967,7 @@ function VendorCards({ payload, enriched }) {
|
|
|
24974
24967
|
] })
|
|
24975
24968
|
] }),
|
|
24976
24969
|
hourlyRate && /* @__PURE__ */ jsxs7("div", { style: { display: "flex", alignItems: "center", gap: "0.25rem", color: "#6b7280" }, children: [
|
|
24977
|
-
/* @__PURE__ */
|
|
24970
|
+
/* @__PURE__ */ jsx7("span", { children: "\u{1F4B0}" }),
|
|
24978
24971
|
/* @__PURE__ */ jsxs7("span", { children: [
|
|
24979
24972
|
"Rate: $",
|
|
24980
24973
|
hourlyRate,
|
|
@@ -24982,9 +24975,9 @@ function VendorCards({ payload, enriched }) {
|
|
|
24982
24975
|
] })
|
|
24983
24976
|
] }),
|
|
24984
24977
|
v.notes && /* @__PURE__ */ jsxs7("div", { style: { color: "#374151", marginTop: "0.4rem" }, children: [
|
|
24985
|
-
/* @__PURE__ */
|
|
24986
|
-
/* @__PURE__ */
|
|
24987
|
-
/* @__PURE__ */
|
|
24978
|
+
/* @__PURE__ */ jsx7("span", { style: { marginRight: "0.25rem" }, children: "\u2728" }),
|
|
24979
|
+
/* @__PURE__ */ jsx7("strong", { children: "Recommendation notes" }),
|
|
24980
|
+
/* @__PURE__ */ jsx7("div", { style: { marginLeft: "1.25rem", marginTop: "0.25rem", color: "#6b7280" }, children: v.notes })
|
|
24988
24981
|
] }),
|
|
24989
24982
|
/* @__PURE__ */ jsxs7("div", { style: {
|
|
24990
24983
|
display: "flex",
|
|
@@ -24995,19 +24988,19 @@ function VendorCards({ payload, enriched }) {
|
|
|
24995
24988
|
borderTop: "1px solid #f3f4f6"
|
|
24996
24989
|
}, children: [
|
|
24997
24990
|
verification?.verified && /* @__PURE__ */ jsxs7("span", { style: { display: "flex", alignItems: "center", gap: "0.25rem", color: "#22c55e", fontSize: "0.75rem" }, children: [
|
|
24998
|
-
/* @__PURE__ */
|
|
24991
|
+
/* @__PURE__ */ jsx7("span", { style: { fontSize: "0.875rem" }, children: "\u2713" }),
|
|
24999
24992
|
" Verified"
|
|
25000
24993
|
] }),
|
|
25001
24994
|
booleans?.is_agency_insured && /* @__PURE__ */ jsxs7("span", { style: { display: "flex", alignItems: "center", gap: "0.25rem", color: "#22c55e", fontSize: "0.75rem" }, children: [
|
|
25002
|
-
/* @__PURE__ */
|
|
24995
|
+
/* @__PURE__ */ jsx7("span", { style: { fontSize: "0.875rem" }, children: "\u2713" }),
|
|
25003
24996
|
" Insured"
|
|
25004
24997
|
] }),
|
|
25005
24998
|
booleans?.free_in_home_evaluation && /* @__PURE__ */ jsxs7("span", { style: { display: "flex", alignItems: "center", gap: "0.25rem", color: "#3b82f6", fontSize: "0.75rem" }, children: [
|
|
25006
|
-
/* @__PURE__ */
|
|
24999
|
+
/* @__PURE__ */ jsx7("span", { style: { fontSize: "0.875rem" }, children: "\u{1F3E0}" }),
|
|
25007
25000
|
" Free In-Home Evaluation"
|
|
25008
25001
|
] }),
|
|
25009
25002
|
booleans?.can_request_same_caregiver && /* @__PURE__ */ jsxs7("span", { style: { display: "flex", alignItems: "center", gap: "0.25rem", color: "#6b7280", fontSize: "0.75rem" }, children: [
|
|
25010
|
-
/* @__PURE__ */
|
|
25003
|
+
/* @__PURE__ */ jsx7("span", { style: { fontSize: "0.875rem" }, children: "\u{1F464}" }),
|
|
25011
25004
|
" Same Caregiver Available"
|
|
25012
25005
|
] })
|
|
25013
25006
|
] })
|
|
@@ -25019,7 +25012,7 @@ function VendorCards({ payload, enriched }) {
|
|
|
25019
25012
|
}
|
|
25020
25013
|
|
|
25021
25014
|
// lib/widgets/default-widgets.tsx
|
|
25022
|
-
import { jsx as
|
|
25015
|
+
import { jsx as jsx8, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
25023
25016
|
var defaultChatWidgets = [
|
|
25024
25017
|
createWidget({
|
|
25025
25018
|
widgetType: "person-card",
|
|
@@ -25028,7 +25021,7 @@ var defaultChatWidgets = [
|
|
|
25028
25021
|
photoUri: zod_default.string().optional().describe("URL to a photo of the person"),
|
|
25029
25022
|
details: zod_default.record(zod_default.any()).optional()
|
|
25030
25023
|
}).describe("showing a person card with name, photo and additional details"),
|
|
25031
|
-
render: (payload) => /* @__PURE__ */
|
|
25024
|
+
render: (payload) => /* @__PURE__ */ jsx8(
|
|
25032
25025
|
"div",
|
|
25033
25026
|
{
|
|
25034
25027
|
style: {
|
|
@@ -25042,7 +25035,7 @@ var defaultChatWidgets = [
|
|
|
25042
25035
|
boxShadow: "0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06)"
|
|
25043
25036
|
},
|
|
25044
25037
|
children: /* @__PURE__ */ jsxs8("div", { style: { display: "flex", alignItems: "flex-start", gap: "0.75rem" }, children: [
|
|
25045
|
-
payload.photoUri && /* @__PURE__ */
|
|
25038
|
+
payload.photoUri && /* @__PURE__ */ jsx8(
|
|
25046
25039
|
"img",
|
|
25047
25040
|
{
|
|
25048
25041
|
src: payload.photoUri,
|
|
@@ -25058,13 +25051,13 @@ var defaultChatWidgets = [
|
|
|
25058
25051
|
}
|
|
25059
25052
|
),
|
|
25060
25053
|
/* @__PURE__ */ jsxs8("div", { style: { flex: 1, minWidth: 0 }, children: [
|
|
25061
|
-
/* @__PURE__ */
|
|
25062
|
-
payload.details ? /* @__PURE__ */
|
|
25054
|
+
/* @__PURE__ */ jsx8("div", { style: { fontWeight: 600, fontSize: "1rem", color: "#111827", marginBottom: "0.25rem" }, children: payload.name }),
|
|
25055
|
+
payload.details ? /* @__PURE__ */ jsx8("div", { style: { display: "flex", flexDirection: "column", gap: "0.25rem" }, children: Object.entries(payload.details).map(([key, value]) => /* @__PURE__ */ jsxs8("div", { style: { display: "flex", gap: "0.5rem", fontSize: "0.875rem" }, children: [
|
|
25063
25056
|
/* @__PURE__ */ jsxs8("span", { style: { color: "#6b7280", fontWeight: 500, minWidth: "fit-content" }, children: [
|
|
25064
25057
|
key,
|
|
25065
25058
|
":"
|
|
25066
25059
|
] }),
|
|
25067
|
-
/* @__PURE__ */
|
|
25060
|
+
/* @__PURE__ */ jsx8("span", { style: { color: "#374151" }, children: String(value) })
|
|
25068
25061
|
] }, key)) }) : null
|
|
25069
25062
|
] })
|
|
25070
25063
|
] })
|
|
@@ -25077,7 +25070,7 @@ var defaultChatWidgets = [
|
|
|
25077
25070
|
uri: zod_default.string().url(),
|
|
25078
25071
|
text: zod_default.string().optional()
|
|
25079
25072
|
}).describe("rendering a clickable link"),
|
|
25080
|
-
render: (payload) => /* @__PURE__ */
|
|
25073
|
+
render: (payload) => /* @__PURE__ */ jsx8(
|
|
25081
25074
|
"a",
|
|
25082
25075
|
{
|
|
25083
25076
|
href: payload.uri,
|
|
@@ -25109,45 +25102,51 @@ var defaultChatWidgets = [
|
|
|
25109
25102
|
children: payload.text || payload.uri
|
|
25110
25103
|
}
|
|
25111
25104
|
)
|
|
25112
|
-
})
|
|
25113
|
-
|
|
25114
|
-
|
|
25115
|
-
|
|
25116
|
-
|
|
25117
|
-
|
|
25118
|
-
|
|
25119
|
-
|
|
25120
|
-
|
|
25121
|
-
|
|
25105
|
+
})
|
|
25106
|
+
];
|
|
25107
|
+
var getVendorCardsWidget = (isProd) => {
|
|
25108
|
+
const vendorDetailsToolId = isProd ? "86dc78e28f933225750d9bcff7c94b18-CPgsswom7FkUYvplmy6H" : "CPgsswom7FkUYvplmy6H";
|
|
25109
|
+
const distanceMatrixToolId = isProd ? "86dc78e28f933225750d9bcff7c94b18-DwsbeKAxOctXSGgghvW8" : "DwsbeKAxOctXSGgghvW8";
|
|
25110
|
+
return [
|
|
25111
|
+
createWidget({
|
|
25112
|
+
widgetType: "vendor-cards",
|
|
25113
|
+
schema: vendorCardsSchema,
|
|
25114
|
+
enrich: {
|
|
25115
|
+
/** fetch vendor details from the list of IDs */
|
|
25116
|
+
vendorDetails: {
|
|
25117
|
+
toolId: vendorDetailsToolId,
|
|
25118
|
+
inputs: {
|
|
25119
|
+
vendorIds: "${vendors|map('vendor_id')|join(',')}"
|
|
25120
|
+
}
|
|
25121
|
+
},
|
|
25122
|
+
/* calculate distance from user to each vendor */
|
|
25123
|
+
distanceMatrix: {
|
|
25124
|
+
toolId: distanceMatrixToolId,
|
|
25125
|
+
inputs: {
|
|
25126
|
+
origin: "${fromCoordinates}",
|
|
25127
|
+
destinations: "${vendors|map('vendorCoordinates')}"
|
|
25128
|
+
}
|
|
25122
25129
|
}
|
|
25123
25130
|
},
|
|
25124
|
-
|
|
25125
|
-
|
|
25126
|
-
|
|
25127
|
-
|
|
25128
|
-
|
|
25129
|
-
destinations: "${vendors|map('vendorCoordinates')}"
|
|
25131
|
+
render: (payload, enriched) => /* @__PURE__ */ jsx8(
|
|
25132
|
+
VendorCards,
|
|
25133
|
+
{
|
|
25134
|
+
payload,
|
|
25135
|
+
enriched
|
|
25130
25136
|
}
|
|
25131
|
-
|
|
25132
|
-
}
|
|
25133
|
-
|
|
25134
|
-
|
|
25135
|
-
{
|
|
25136
|
-
payload,
|
|
25137
|
-
enriched
|
|
25138
|
-
}
|
|
25139
|
-
)
|
|
25140
|
-
})
|
|
25141
|
-
];
|
|
25137
|
+
)
|
|
25138
|
+
})
|
|
25139
|
+
];
|
|
25140
|
+
};
|
|
25142
25141
|
export {
|
|
25143
25142
|
ChatWidget,
|
|
25144
25143
|
PopupChatWidget,
|
|
25145
25144
|
TagGroupDisplay,
|
|
25146
25145
|
ToolCallDisplay,
|
|
25147
25146
|
cn,
|
|
25148
|
-
createChatWidget,
|
|
25149
25147
|
createWidget,
|
|
25150
25148
|
defaultChatWidgets,
|
|
25149
|
+
getVendorCardsWidget,
|
|
25151
25150
|
registerChatWidgets,
|
|
25152
25151
|
useChat,
|
|
25153
25152
|
useFeedback
|