@ensembleapp/client-sdk 0.0.14 → 0.0.15
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 +50 -45
- package/dist/index.js +13 -11
- package/dist/index.js.map +1 -1
- package/dist/widget/widget.global.js +2 -2
- package/dist/widget/widget.global.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -5,42 +5,43 @@ import React$1, { ReactNode } from 'react';
|
|
|
5
5
|
import z, { AnyZodObject } from 'zod';
|
|
6
6
|
import { ClassValue } from 'clsx';
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* Version selector for tools. This should mirror VersionSelector on server-side
|
|
10
|
-
* - 'latest': prefer draft (v0), fallback to last published
|
|
11
|
-
* - 'published': prefer last published, fallback to draft
|
|
12
|
-
* - number: specific version (1+)
|
|
13
|
-
*/
|
|
8
|
+
/** @minimum 1 */
|
|
14
9
|
type VersionSelector = 'latest' | 'published' | number;
|
|
15
10
|
/**
|
|
16
|
-
*
|
|
17
|
-
* Uses JEXL expressions to build tool inputs from the widget payload.
|
|
11
|
+
* fetch data via tool call.
|
|
18
12
|
*/
|
|
19
|
-
type
|
|
20
|
-
/** Tool ID to call for enrichment */
|
|
13
|
+
type ToolCallConfig = {
|
|
21
14
|
toolId: string;
|
|
22
15
|
/**
|
|
23
|
-
*
|
|
24
|
-
* - 'latest':
|
|
25
|
-
* - 'published':
|
|
26
|
-
* - number: specific version (1+)
|
|
16
|
+
* Select the tool version (default to 'latest' if not provided).
|
|
17
|
+
* - 'latest': pick draft if exists, fallback to latest published version
|
|
18
|
+
* - 'published': pick latest published version, fallback to draft version
|
|
19
|
+
* - number: specific tool version (1+)
|
|
27
20
|
*/
|
|
28
21
|
version?: VersionSelector;
|
|
29
22
|
/**
|
|
30
|
-
*
|
|
31
|
-
* Expressions are evaluated with $ as the payload root (auto-normalized).
|
|
32
|
-
* Use ${...} syntax for JEXL expressions, or literal values.
|
|
33
|
-
*
|
|
34
|
-
* Examples:
|
|
35
|
-
* - "${vendors|map('id')|join(',')}" → "v1,v2,v3"
|
|
36
|
-
* - "${limit}" → 10
|
|
37
|
-
* - "static value" → "static value"
|
|
38
|
-
*
|
|
39
|
-
* If omitted, the entire payload is passed as tool input.
|
|
23
|
+
* Tool input can be literal or templated string with expressions
|
|
40
24
|
*/
|
|
41
25
|
inputs?: Record<string, unknown>;
|
|
42
26
|
};
|
|
43
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Widget enrichment configuration.
|
|
29
|
+
* Keys are used to access the enrichment results in the render function.
|
|
30
|
+
*
|
|
31
|
+
* Example:
|
|
32
|
+
* ```typescript
|
|
33
|
+
* enrich: {
|
|
34
|
+
* vendorDetails: { toolId: 'vendor-tool', inputs: { ids: "${vendors}" } },
|
|
35
|
+
* pricing: { toolId: 'pricing-tool', inputs: { ids: "${vendors}" } },
|
|
36
|
+
* },
|
|
37
|
+
* render: (payload, enriched) => {
|
|
38
|
+
* const vendors = enriched?.vendorDetails?.data;
|
|
39
|
+
* const pricing = enriched?.pricing?.data;
|
|
40
|
+
* }
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
type WidgetEnrichConfig = Record<string, ToolCallConfig>;
|
|
44
|
+
/** Enrichment result containing the full tool response. This should mirror ToolResult on server-side. */
|
|
44
45
|
type EnrichmentResult$1 = {
|
|
45
46
|
success: boolean;
|
|
46
47
|
error?: {
|
|
@@ -55,8 +56,8 @@ type UIWidget = {
|
|
|
55
56
|
widgetType: string;
|
|
56
57
|
/** LLM-generated data based on the widget schema specified by the client */
|
|
57
58
|
payload: unknown;
|
|
58
|
-
/** Server-injected enrichment
|
|
59
|
-
|
|
59
|
+
/** Server-injected enrichment results from tool calls, keyed by enrichment name */
|
|
60
|
+
enriched?: Record<string, EnrichmentResult$1>;
|
|
60
61
|
};
|
|
61
62
|
|
|
62
63
|
type DeprecatedChatConfig = {
|
|
@@ -175,8 +176,7 @@ declare function useFeedback({ api, threadId, agentId, agentExecutionId, }: UseF
|
|
|
175
176
|
error: Error | null;
|
|
176
177
|
};
|
|
177
178
|
|
|
178
|
-
/** Enrichment result containing the full tool response - this should mirror ToolResult
|
|
179
|
-
* OR maybe we should declare ToolResult here? */
|
|
179
|
+
/** Enrichment result containing the full tool response - this should mirror ToolResult */
|
|
180
180
|
interface EnrichmentResult<TData = unknown> {
|
|
181
181
|
success: boolean;
|
|
182
182
|
error?: {
|
|
@@ -186,27 +186,32 @@ interface EnrichmentResult<TData = unknown> {
|
|
|
186
186
|
data?: TData;
|
|
187
187
|
metadata?: Record<string, unknown>;
|
|
188
188
|
}
|
|
189
|
-
/**
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
*/
|
|
193
|
-
interface WidgetRenderProps<TPayload, TEnrichedData = unknown> {
|
|
194
|
-
/** The validated widget payload matching the schema */
|
|
195
|
-
payload: TPayload;
|
|
196
|
-
/** Server-injected enrichment result (only present if widget has enrich config) */
|
|
197
|
-
enrichedResult?: EnrichmentResult<TEnrichedData>;
|
|
198
|
-
}
|
|
199
|
-
interface UIWidgetDefinition<TSchema extends AnyZodObject = AnyZodObject, TEnrichedData = unknown> {
|
|
189
|
+
/** Enriched results keyed by enrichment name */
|
|
190
|
+
type EnrichedResults<T = unknown> = Record<string, EnrichmentResult<T>>;
|
|
191
|
+
interface UIWidgetDefinition<TSchema extends AnyZodObject = AnyZodObject, TEnriched extends EnrichedResults = EnrichedResults> {
|
|
200
192
|
widgetType: string;
|
|
201
193
|
schema: TSchema;
|
|
202
194
|
/**
|
|
203
|
-
* Optional enrichment config - if provided, server will call
|
|
204
|
-
*
|
|
195
|
+
* Optional enrichment config - if provided, server will call the tools to enrich the data.
|
|
196
|
+
* Keys are used to access results in the render function.
|
|
197
|
+
*
|
|
198
|
+
* Example:
|
|
199
|
+
* ```typescript
|
|
200
|
+
* enrich: {
|
|
201
|
+
* vendorDetails: { toolId: 'vendor-tool', inputs: { ids: "${vendors}" } },
|
|
202
|
+
* pricing: { toolId: 'pricing-tool', inputs: { ids: "${vendors}" } },
|
|
203
|
+
* }
|
|
204
|
+
* ```
|
|
205
205
|
*/
|
|
206
206
|
enrich?: WidgetEnrichConfig;
|
|
207
|
-
|
|
207
|
+
/**
|
|
208
|
+
* Render function that receives the payload and enriched results.
|
|
209
|
+
* @param payload - The LLM-generated data matching the schema
|
|
210
|
+
* @param enriched - Enrichment results keyed by name (empty object if no enrich config)
|
|
211
|
+
*/
|
|
212
|
+
render(payload: z.infer<TSchema>, enriched: TEnriched): ReactNode;
|
|
208
213
|
}
|
|
209
|
-
declare const createWidget: <TSchema extends AnyZodObject,
|
|
214
|
+
declare const createWidget: <TSchema extends AnyZodObject, TEnriched extends EnrichedResults = EnrichedResults>({ widgetType, schema, enrich, render, }: UIWidgetDefinition<TSchema, TEnriched>) => UIWidgetDefinition<TSchema, TEnriched>;
|
|
210
215
|
|
|
211
216
|
interface ChatWidgetStyles {
|
|
212
217
|
primaryColor?: string;
|
|
@@ -353,4 +358,4 @@ declare const defaultChatWidgets: UIWidgetDefinition[];
|
|
|
353
358
|
|
|
354
359
|
declare function cn(...inputs: ClassValue[]): string;
|
|
355
360
|
|
|
356
|
-
export { type ApiConfig, type ChatContentItem, type ChatMessage, ChatWidget, type ChatWidgetFeedbackOptions, type ChatWidgetInstance, type ChatWidgetConfig as ChatWidgetProps, type ChatWidgetSpeechToTextOptions, type ChatWidgetStyles, type ChatWidgetVoiceOptions, type EmbeddableChatWidgetConfig, type EnrichmentResult, 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,
|
|
361
|
+
export { type ApiConfig, type ChatContentItem, type ChatMessage, ChatWidget, type ChatWidgetFeedbackOptions, type ChatWidgetInstance, type ChatWidgetConfig as ChatWidgetProps, type ChatWidgetSpeechToTextOptions, type ChatWidgetStyles, type ChatWidgetVoiceOptions, type EmbeddableChatWidgetConfig, type EnrichedResults, type EnrichmentResult, 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, createChatWidget, createWidget, defaultChatWidgets, registerChatWidgets, useChat, useFeedback };
|
package/dist/index.js
CHANGED
|
@@ -23670,12 +23670,12 @@ async function registerChatWidgets({
|
|
|
23670
23670
|
widgets
|
|
23671
23671
|
}) {
|
|
23672
23672
|
const widgetSchemas = widgets.map(({ widgetType, schema, enrich }) => {
|
|
23673
|
-
|
|
23673
|
+
const extendedSchema = schema.extend({
|
|
23674
23674
|
widgetType: zod_default.literal(widgetType)
|
|
23675
23675
|
});
|
|
23676
23676
|
return {
|
|
23677
23677
|
widgetType,
|
|
23678
|
-
schema: toJsonSchema(
|
|
23678
|
+
schema: toJsonSchema(extendedSchema),
|
|
23679
23679
|
enrich
|
|
23680
23680
|
};
|
|
23681
23681
|
});
|
|
@@ -24273,7 +24273,7 @@ function MessageItemComponent({
|
|
|
24273
24273
|
] }, key);
|
|
24274
24274
|
}
|
|
24275
24275
|
const widget = item;
|
|
24276
|
-
return /* @__PURE__ */ jsx5("div", { className: "chat-widget__widget", children: widgetDef.render(
|
|
24276
|
+
return /* @__PURE__ */ jsx5("div", { className: "chat-widget__widget", children: widgetDef.render(widget.payload, widget.enriched ?? {}) }, key);
|
|
24277
24277
|
}
|
|
24278
24278
|
return null;
|
|
24279
24279
|
};
|
|
@@ -24875,7 +24875,7 @@ var createWidget = ({
|
|
|
24875
24875
|
widgetType,
|
|
24876
24876
|
schema,
|
|
24877
24877
|
enrich,
|
|
24878
|
-
render
|
|
24878
|
+
render
|
|
24879
24879
|
});
|
|
24880
24880
|
|
|
24881
24881
|
// lib/widgets/default-widgets.tsx
|
|
@@ -24888,7 +24888,7 @@ var defaultChatWidgets = [
|
|
|
24888
24888
|
profileUri: zod_default.string().optional(),
|
|
24889
24889
|
details: zod_default.record(zod_default.any()).optional()
|
|
24890
24890
|
}).describe("showing a person card with name, photo and additional details"),
|
|
24891
|
-
render: (
|
|
24891
|
+
render: (payload) => /* @__PURE__ */ jsx8(
|
|
24892
24892
|
"div",
|
|
24893
24893
|
{
|
|
24894
24894
|
style: {
|
|
@@ -24937,7 +24937,7 @@ var defaultChatWidgets = [
|
|
|
24937
24937
|
uri: zod_default.string().url(),
|
|
24938
24938
|
text: zod_default.string().optional()
|
|
24939
24939
|
}).describe("rendering a clickable link"),
|
|
24940
|
-
render: (
|
|
24940
|
+
render: (payload) => /* @__PURE__ */ jsx8(
|
|
24941
24941
|
"a",
|
|
24942
24942
|
{
|
|
24943
24943
|
href: payload.uri,
|
|
@@ -24980,14 +24980,16 @@ var defaultChatWidgets = [
|
|
|
24980
24980
|
}))
|
|
24981
24981
|
}).describe("displaying a list of vendor cards with rankings and reasons. Only use this widget when calling Care Network vendor search tools."),
|
|
24982
24982
|
enrich: {
|
|
24983
|
-
|
|
24984
|
-
|
|
24985
|
-
|
|
24983
|
+
vendorDetails: {
|
|
24984
|
+
toolId: "CPgsswom7FkUYvplmy6H",
|
|
24985
|
+
inputs: {
|
|
24986
|
+
vendorIds: "${vendors|map('vendor_id')|join(',')}"
|
|
24987
|
+
}
|
|
24986
24988
|
}
|
|
24987
24989
|
},
|
|
24988
|
-
render: (
|
|
24990
|
+
render: (payload, { vendorDetails }) => {
|
|
24989
24991
|
const typedPayload = payload;
|
|
24990
|
-
const vendorData =
|
|
24992
|
+
const vendorData = vendorDetails?.data ?? {};
|
|
24991
24993
|
const formatLanguage = (code3) => {
|
|
24992
24994
|
const langMap = { en: "English", es: "Spanish", zh: "Chinese", fr: "French" };
|
|
24993
24995
|
return langMap[code3.trim()] || code3.trim();
|