@ensembleapp/client-sdk 0.0.25 → 0.0.27
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 +147 -117
- package/dist/index.js +22741 -22543
- package/dist/index.js.map +1 -1
- package/dist/widget/widget.global.js +43 -43
- package/dist/widget/widget.global.js.map +1 -1
- package/lib/{components → chat}/ChatWidget.css +42 -0
- package/package.json +4 -3
- package/lib/widgets/default-widgets.css +0 -85
package/dist/index.d.ts
CHANGED
|
@@ -1,66 +1,38 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
1
2
|
import * as ai from 'ai';
|
|
2
3
|
import { UIMessage } from 'ai';
|
|
3
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
4
|
import z, { AnyZodObject } from 'zod';
|
|
5
5
|
import React$1 from 'react';
|
|
6
6
|
import { ClassValue } from 'clsx';
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
type
|
|
8
|
+
/** Derived part type from UIMessage */
|
|
9
|
+
type UIMessagePart = UIMessage['parts'][number];
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
toolId: string;
|
|
15
|
-
/**
|
|
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+)
|
|
20
|
-
*/
|
|
21
|
-
version?: VersionSelector;
|
|
22
|
-
/**
|
|
23
|
-
* Tool input can be literal or templated string with expressions
|
|
24
|
-
*/
|
|
25
|
-
inputs?: Record<string, unknown>;
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* Widget enrichment configuration.
|
|
29
|
-
* Keys are used to access the enrichment results in the render function.
|
|
11
|
+
* ChatMessageSection = a block of content
|
|
12
|
+
* - step: one LLM turn's output (content between step-start markers)
|
|
13
|
+
* - group: sub-agent output (content within data-tag-start/end markers)
|
|
30
14
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
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
|
-
* ```
|
|
15
|
+
* Parts are raw UIMessagePart from AI SDK - no transformation.
|
|
16
|
+
* Structural markers (step-start, data-tag-start/end, data-transfer) are consumed during grouping.
|
|
42
17
|
*/
|
|
43
|
-
type
|
|
18
|
+
type ChatMessageSection = {
|
|
19
|
+
type: 'step';
|
|
20
|
+
parts: UIMessagePart[];
|
|
21
|
+
} | {
|
|
22
|
+
type: 'group';
|
|
23
|
+
groupName: string;
|
|
24
|
+
parts: UIMessagePart[];
|
|
25
|
+
};
|
|
44
26
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
27
|
+
* ChatMessage = our UIMessage abstraction to account for step and groupings
|
|
28
|
+
* Passes through id, role, metadata. Replaces parts with sections.
|
|
47
29
|
*/
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
data?: TData;
|
|
55
|
-
};
|
|
56
|
-
/** Widget output shape sent to the client */
|
|
57
|
-
type UIWidget = {
|
|
58
|
-
widgetType: string;
|
|
59
|
-
/** LLM-generated data based on the widget schema specified by the client */
|
|
60
|
-
payload: unknown;
|
|
61
|
-
/** Server-injected enrichment results from tool calls, keyed by enrichment name */
|
|
62
|
-
enriched?: Record<string, EnrichmentResult>;
|
|
63
|
-
};
|
|
30
|
+
interface ChatMessage {
|
|
31
|
+
id: string;
|
|
32
|
+
role: 'user' | 'assistant';
|
|
33
|
+
metadata?: unknown;
|
|
34
|
+
sections: ChatMessageSection[];
|
|
35
|
+
}
|
|
64
36
|
|
|
65
37
|
type DeprecatedChatConfig = {
|
|
66
38
|
/** @deprecated use agentId instead */
|
|
@@ -73,6 +45,8 @@ interface ApiConfig {
|
|
|
73
45
|
token: string;
|
|
74
46
|
headers?: Record<string, string>;
|
|
75
47
|
}
|
|
48
|
+
/** Agent version selector: 'latest' (default), 'published', or a specific version number */
|
|
49
|
+
type AgentVersion = 'latest' | 'published' | number;
|
|
76
50
|
type UseChatConfig = DeprecatedChatConfig & {
|
|
77
51
|
/** The server API configuration */
|
|
78
52
|
api: ApiConfig;
|
|
@@ -80,6 +54,8 @@ type UseChatConfig = DeprecatedChatConfig & {
|
|
|
80
54
|
threadId: string;
|
|
81
55
|
/** Ensemble agent ID to connect to */
|
|
82
56
|
agentId?: string;
|
|
57
|
+
/** Agent version: 'latest' (default), 'published', or a specific version number */
|
|
58
|
+
agentVersion?: AgentVersion;
|
|
83
59
|
/** additional context (anything) that needs to be passed to the LLM */
|
|
84
60
|
dataContext?: unknown;
|
|
85
61
|
onError?: (error: Error) => void;
|
|
@@ -89,38 +65,7 @@ type UseChatConfig = DeprecatedChatConfig & {
|
|
|
89
65
|
onData?: (data: any) => void;
|
|
90
66
|
onMessage?: (message: UIMessage) => void;
|
|
91
67
|
};
|
|
92
|
-
|
|
93
|
-
type: 'tool-call';
|
|
94
|
-
toolName: string;
|
|
95
|
-
input?: Record<string, unknown>;
|
|
96
|
-
state: 'pending' | 'output-available' | 'error';
|
|
97
|
-
output?: unknown;
|
|
98
|
-
}
|
|
99
|
-
type ChatContentItem = string | UIWidget | ToolCallContent;
|
|
100
|
-
/** A grouped section of sub-agent output, wrapped by data-tag-start/end markers */
|
|
101
|
-
interface TagGroup {
|
|
102
|
-
tagId: string;
|
|
103
|
-
content: ChatContentItem[];
|
|
104
|
-
/** Index into content[] where the last step begins (for promoting only final output) */
|
|
105
|
-
lastStepStartIndex?: number;
|
|
106
|
-
}
|
|
107
|
-
/** A single section in the message, rendered in chronological order */
|
|
108
|
-
type MessageSection = {
|
|
109
|
-
type: 'content';
|
|
110
|
-
item: ChatContentItem;
|
|
111
|
-
} | {
|
|
112
|
-
type: 'tag-group';
|
|
113
|
-
group: TagGroup;
|
|
114
|
-
};
|
|
115
|
-
interface ChatMessage {
|
|
116
|
-
id: string;
|
|
117
|
-
role: 'user' | 'assistant';
|
|
118
|
-
/** Ordered sections: content items and tag groups interleaved chronologically */
|
|
119
|
-
sections: MessageSection[];
|
|
120
|
-
thoughts?: (string | UIWidget)[];
|
|
121
|
-
createdAt?: Date;
|
|
122
|
-
}
|
|
123
|
-
declare function useChat({ api, threadId, agentId, agentExecutionId, dataContext, onError, onAuthError, onFinish, onData, onMessage, }: UseChatConfig): {
|
|
68
|
+
declare function useChat({ api, threadId, agentId, agentVersion, agentExecutionId, dataContext, onError, onAuthError, onFinish, onData, onMessage, }: UseChatConfig): {
|
|
124
69
|
messages: ChatMessage[];
|
|
125
70
|
status: ai.ChatStatus;
|
|
126
71
|
isLoadingInitial: boolean;
|
|
@@ -147,35 +92,53 @@ declare function useChat({ api, threadId, agentId, agentExecutionId, dataContext
|
|
|
147
92
|
setMessages: (messages: UIMessage<unknown, ai.UIDataTypes, ai.UITools>[] | ((messages: UIMessage<unknown, ai.UIDataTypes, ai.UITools>[]) => UIMessage<unknown, ai.UIDataTypes, ai.UITools>[])) => void;
|
|
148
93
|
};
|
|
149
94
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
95
|
+
/** @minimum 1 */
|
|
96
|
+
type VersionSelector = 'latest' | 'published' | number;
|
|
97
|
+
/**
|
|
98
|
+
* fetch data via tool call.
|
|
99
|
+
*/
|
|
100
|
+
type ToolCallConfig = {
|
|
101
|
+
toolId: string;
|
|
102
|
+
/**
|
|
103
|
+
* Select the tool version (default to 'latest' if not provided).
|
|
104
|
+
* - 'latest': pick draft if exists, fallback to latest published version
|
|
105
|
+
* - 'published': pick latest published version, fallback to draft version
|
|
106
|
+
* - number: specific tool version (1+)
|
|
107
|
+
*/
|
|
108
|
+
version?: VersionSelector;
|
|
109
|
+
/**
|
|
110
|
+
* Tool input can be literal or templated string with expressions
|
|
111
|
+
*/
|
|
112
|
+
inputs?: Record<string, unknown>;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Widget enrichment configuration.
|
|
116
|
+
* Keys are used to access the enrichment results in the render function.
|
|
117
|
+
*
|
|
118
|
+
* Example:
|
|
119
|
+
* ```typescript
|
|
120
|
+
* enrich: {
|
|
121
|
+
* vendorDetails: { toolId: 'vendor-tool', inputs: { ids: "${vendors}" } },
|
|
122
|
+
* pricing: { toolId: 'pricing-tool', inputs: { ids: "${vendors}" } },
|
|
123
|
+
* },
|
|
124
|
+
* render: (payload, enriched) => {
|
|
125
|
+
* const vendors = enriched?.vendorDetails?.data;
|
|
126
|
+
* const pricing = enriched?.pricing?.data;
|
|
127
|
+
* }
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
type WidgetEnrichConfig = Record<string, ToolCallConfig>;
|
|
131
|
+
/**
|
|
132
|
+
* Enrichment result containing the full tool response.
|
|
133
|
+
* This should mirror ToolResult on server-side without debug/metadata info.
|
|
134
|
+
*/
|
|
135
|
+
type EnrichmentResult<TData = unknown> = {
|
|
136
|
+
success: boolean;
|
|
137
|
+
error?: {
|
|
138
|
+
message?: string;
|
|
139
|
+
code?: string;
|
|
140
|
+
};
|
|
141
|
+
data?: TData;
|
|
179
142
|
};
|
|
180
143
|
|
|
181
144
|
/** Enriched results keyed by enrichment name */
|
|
@@ -205,6 +168,8 @@ interface UIWidgetDefinition<TSchema extends AnyZodObject = AnyZodObject, TEnric
|
|
|
205
168
|
}
|
|
206
169
|
declare const createWidget: <TSchema extends AnyZodObject, TEnriched extends EnrichedResults = EnrichedResults>({ widgetType, schema, enrich, render, }: UIWidgetDefinition<TSchema, TEnriched>) => UIWidgetDefinition<TSchema, TEnriched>;
|
|
207
170
|
|
|
171
|
+
type DisplayMode = 'full' | 'brief';
|
|
172
|
+
|
|
208
173
|
interface ChatWidgetStyles {
|
|
209
174
|
primaryColor?: string;
|
|
210
175
|
primaryTextColor?: string;
|
|
@@ -253,6 +218,8 @@ interface ChatWidgetConfig extends UseChatConfig {
|
|
|
253
218
|
initialUserMessage?: string;
|
|
254
219
|
/** Placeholder text for the input box */
|
|
255
220
|
inputPlaceholder?: string;
|
|
221
|
+
/** Display mode: 'brief' (default) collapses previous steps, 'full' shows everything */
|
|
222
|
+
displayMode?: DisplayMode;
|
|
256
223
|
className?: string;
|
|
257
224
|
styles?: ChatWidgetStyles;
|
|
258
225
|
voice?: ChatWidgetVoiceOptions;
|
|
@@ -261,7 +228,7 @@ interface ChatWidgetConfig extends UseChatConfig {
|
|
|
261
228
|
/** Feedback options for assistant messages. Enabled by default. */
|
|
262
229
|
feedback?: ChatWidgetFeedbackOptions;
|
|
263
230
|
}
|
|
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;
|
|
231
|
+
declare function ChatWidget({ api, threadId, agentId, agentVersion, agentExecutionId, dataContext, displayMode, onError, onAuthError, onFinish, onMessage, title, initialAssistantMessage, initialUserMessage, inputPlaceholder, className, styles: styleProps, voice, speechToText, widgets, feedback, }: ChatWidgetConfig): react_jsx_runtime.JSX.Element;
|
|
265
232
|
|
|
266
233
|
interface PopupAnchorConfig {
|
|
267
234
|
enabled?: boolean;
|
|
@@ -297,11 +264,49 @@ interface PopupChatWidgetProps extends ChatWidgetConfig {
|
|
|
297
264
|
}
|
|
298
265
|
declare function PopupChatWidget({ anchor, ...props }: PopupChatWidgetProps): react_jsx_runtime.JSX.Element;
|
|
299
266
|
|
|
267
|
+
type FeedbackRating = 'positive' | 'negative';
|
|
268
|
+
interface MessageFeedback {
|
|
269
|
+
id: string;
|
|
270
|
+
messageId: string;
|
|
271
|
+
rating: FeedbackRating;
|
|
272
|
+
improvementText?: string;
|
|
273
|
+
createdAt: Date;
|
|
274
|
+
}
|
|
275
|
+
interface FeedbackState {
|
|
276
|
+
rating: FeedbackRating;
|
|
277
|
+
comment?: string;
|
|
278
|
+
}
|
|
279
|
+
interface UseFeedbackConfig {
|
|
280
|
+
api: ApiConfig;
|
|
281
|
+
threadId: string;
|
|
282
|
+
agentId?: string;
|
|
283
|
+
agentVersion?: AgentVersion;
|
|
284
|
+
agentExecutionId?: string;
|
|
285
|
+
}
|
|
286
|
+
interface SubmitFeedbackParams {
|
|
287
|
+
messageId: string;
|
|
288
|
+
rating: FeedbackRating;
|
|
289
|
+
improvementText?: string;
|
|
290
|
+
}
|
|
291
|
+
declare function useFeedback({ api, threadId, agentId, agentVersion, agentExecutionId, }: UseFeedbackConfig): {
|
|
292
|
+
submitFeedback: ({ messageId, rating, improvementText }: SubmitFeedbackParams) => Promise<MessageFeedback | null>;
|
|
293
|
+
getFeedbackForMessage: (messageId: string) => FeedbackState | undefined;
|
|
294
|
+
hasFeedback: (messageId: string) => boolean;
|
|
295
|
+
isSubmitting: string | null;
|
|
296
|
+
error: Error | null;
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
/** Tool part from UIMessage - either typed tool-* or dynamic-tool */
|
|
300
|
+
type ToolPart = Extract<UIMessagePart, {
|
|
301
|
+
type: `tool-${string}`;
|
|
302
|
+
} | {
|
|
303
|
+
type: 'dynamic-tool';
|
|
304
|
+
}>;
|
|
300
305
|
interface ToolCallDisplayProps {
|
|
301
|
-
|
|
306
|
+
toolPart: ToolPart;
|
|
302
307
|
className?: string;
|
|
303
308
|
}
|
|
304
|
-
declare function ToolCallDisplay({
|
|
309
|
+
declare function ToolCallDisplay({ toolPart, className }: ToolCallDisplayProps): react_jsx_runtime.JSX.Element;
|
|
305
310
|
|
|
306
311
|
interface TagGroupDisplayProps {
|
|
307
312
|
tagId: string;
|
|
@@ -311,6 +316,31 @@ interface TagGroupDisplayProps {
|
|
|
311
316
|
}
|
|
312
317
|
declare function TagGroupDisplay({ tagId, isExpanded, onToggle, children, }: TagGroupDisplayProps): react_jsx_runtime.JSX.Element;
|
|
313
318
|
|
|
319
|
+
interface RendererProps {
|
|
320
|
+
/** Message sections to render */
|
|
321
|
+
sections: ChatMessageSection[];
|
|
322
|
+
/** Unique message ID for keying */
|
|
323
|
+
messageId: string;
|
|
324
|
+
/** Render function for individual parts (text, widgets, tool calls) */
|
|
325
|
+
renderPart: (part: UIMessagePart, key: string) => React$1.ReactNode;
|
|
326
|
+
/** Render function for group sections */
|
|
327
|
+
renderGroup: (groupName: string, key: string, children: React$1.ReactNode) => React$1.ReactNode;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Full display mode renderer - shows all content without collapsing.
|
|
332
|
+
* Each section is rendered as-is in chronological order.
|
|
333
|
+
*/
|
|
334
|
+
declare function FullRenderer({ sections, messageId, renderPart, renderGroup, }: RendererProps): react_jsx_runtime.JSX.Element;
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Brief display mode renderer - collapses previous steps.
|
|
338
|
+
*
|
|
339
|
+
* All steps before the last one are collapsed into a single "Show more" section.
|
|
340
|
+
* Groups collapse their internal content similarly.
|
|
341
|
+
*/
|
|
342
|
+
declare function BriefRenderer({ sections, messageId, renderPart, renderGroup, }: RendererProps): react_jsx_runtime.JSX.Element;
|
|
343
|
+
|
|
314
344
|
type RegisterChatWidgetsParams = {
|
|
315
345
|
api: ApiConfig;
|
|
316
346
|
threadId: string;
|
|
@@ -351,4 +381,4 @@ declare const getVendorCardsWidget: (isProd?: boolean) => UIWidgetDefinition[];
|
|
|
351
381
|
|
|
352
382
|
declare function cn(...inputs: ClassValue[]): string;
|
|
353
383
|
|
|
354
|
-
export { type
|
|
384
|
+
export { type AgentVersion, type ApiConfig, BriefRenderer, type ChatMessage, type ChatMessageSection, ChatWidget, type ChatWidgetFeedbackOptions, type ChatWidgetConfig as ChatWidgetProps, type ChatWidgetSpeechToTextOptions, type ChatWidgetStyles, type ChatWidgetVoiceOptions, type DisplayMode, type EmbeddableChatWidgetConfig, type EnrichedResults, type FeedbackRating, type FeedbackState, FullRenderer, type MessageFeedback, type PopupAnchorConfig, PopupChatWidget, type PopupChatWidgetProps, type RendererProps, type SubmitFeedbackParams, TagGroupDisplay, type TagGroupDisplayProps, ToolCallDisplay, type ToolCallDisplayProps, type ToolPart, type UIMessagePart, type UIWidgetDefinition, type UseChatConfig, type UseFeedbackConfig, type WidgetEnrichConfig, cn, createWidget, defaultChatWidgets, getVendorCardsWidget, registerChatWidgets, useChat, useFeedback };
|