@ensembleapp/client-sdk 0.0.36 → 0.0.38
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 +86 -66
- package/dist/index.js +671 -454
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/widget/widget.global.d.ts +0 -26
- package/dist/widget/widget.global.js +0 -209
- package/dist/widget/widget.global.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import React, { ReactElement, ReactNode } from 'react';
|
|
|
2
2
|
import * as ai from 'ai';
|
|
3
3
|
import { UIMessage } from 'ai';
|
|
4
4
|
import { FlexibleSchema, InferSchema } from '@ai-sdk/provider-utils';
|
|
5
|
+
import z from 'zod';
|
|
5
6
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
6
7
|
import { ClassValue } from 'clsx';
|
|
7
8
|
|
|
@@ -53,7 +54,7 @@ type UseChatConfig = DeprecatedChatConfig & {
|
|
|
53
54
|
/** Thread ID for keeping conversation history */
|
|
54
55
|
threadId: string;
|
|
55
56
|
/** Ensemble agent ID to connect to */
|
|
56
|
-
agentId
|
|
57
|
+
agentId: string;
|
|
57
58
|
/** Agent version: 'latest' (default), 'published', or a specific version number */
|
|
58
59
|
agentVersion?: AgentVersion;
|
|
59
60
|
/** additional context (anything) that needs to be passed to the LLM */
|
|
@@ -92,8 +93,24 @@ declare function useChat({ api, threadId, agentId, agentVersion, agentExecutionI
|
|
|
92
93
|
setMessages: (messages: UIMessage<unknown, ai.UIDataTypes, ai.UITools>[] | ((messages: UIMessage<unknown, ai.UIDataTypes, ai.UITools>[]) => UIMessage<unknown, ai.UIDataTypes, ai.UITools>[])) => void;
|
|
93
94
|
};
|
|
94
95
|
|
|
95
|
-
|
|
96
|
-
type VersionSelector =
|
|
96
|
+
declare const VersionSelectorSchema: z.ZodUnion<readonly [z.ZodLiteral<"latest">, z.ZodLiteral<"published">, z.ZodNumber]>;
|
|
97
|
+
type VersionSelector = z.infer<typeof VersionSelectorSchema>;
|
|
98
|
+
|
|
99
|
+
declare const FeedbackRatingSchema: z.ZodEnum<{
|
|
100
|
+
positive: "positive";
|
|
101
|
+
negative: "negative";
|
|
102
|
+
}>;
|
|
103
|
+
type FeedbackRating = z.infer<typeof FeedbackRatingSchema>;
|
|
104
|
+
interface FeedbackNote {
|
|
105
|
+
noteId?: string;
|
|
106
|
+
[key: string]: unknown;
|
|
107
|
+
}
|
|
108
|
+
interface MessageFeedback {
|
|
109
|
+
rating?: FeedbackRating;
|
|
110
|
+
improvementText?: string;
|
|
111
|
+
notes?: FeedbackNote[];
|
|
112
|
+
}
|
|
113
|
+
|
|
97
114
|
/**
|
|
98
115
|
* fetch data via tool call.
|
|
99
116
|
*/
|
|
@@ -141,6 +158,43 @@ type EnrichmentResult<TData = unknown> = {
|
|
|
141
158
|
data?: TData;
|
|
142
159
|
};
|
|
143
160
|
|
|
161
|
+
/**
|
|
162
|
+
* Client-specific types for the SDK.
|
|
163
|
+
* Core feedback types (FeedbackRating, FeedbackNote, MessageFeedback, CreateFeedbackRequest)
|
|
164
|
+
* are in @repo/agent-sdk/schemas.
|
|
165
|
+
*/
|
|
166
|
+
|
|
167
|
+
interface SubmitFeedbackParams {
|
|
168
|
+
rating?: FeedbackRating | null;
|
|
169
|
+
improvementText?: string | null;
|
|
170
|
+
notes?: FeedbackNote[];
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Feedback handlers for a specific message.
|
|
174
|
+
* messageId is not necessary here and is handled at a higher level.
|
|
175
|
+
*/
|
|
176
|
+
interface FeedbackHandlers {
|
|
177
|
+
getFeedback: () => MessageFeedback | undefined;
|
|
178
|
+
submitFeedback: (params: SubmitFeedbackParams) => Promise<MessageFeedback | null>;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Feedback configuration for MessageRenderer.
|
|
182
|
+
* Contains handlers and UI options for feedback display.
|
|
183
|
+
*/
|
|
184
|
+
interface FeedbackConfig extends FeedbackHandlers {
|
|
185
|
+
/** Whether a submission is in progress (disables interaction) */
|
|
186
|
+
loading?: boolean;
|
|
187
|
+
/** Whether comment is required for negative feedback */
|
|
188
|
+
requireCommentForNegative?: boolean;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Message-level context provided to child.
|
|
192
|
+
* Contains message-scoped data and feedback utilities.
|
|
193
|
+
*/
|
|
194
|
+
interface MessageContext extends FeedbackHandlers {
|
|
195
|
+
messageId: string;
|
|
196
|
+
}
|
|
197
|
+
|
|
144
198
|
/** Enriched results keyed by enrichment name */
|
|
145
199
|
type EnrichedResults<T = unknown> = Record<string, EnrichmentResult<T>>;
|
|
146
200
|
/** Union type for SDK to handle both customer and SDK UI widgets */
|
|
@@ -156,7 +210,9 @@ interface SDKUIWidgetDefinition<TSchema extends FlexibleSchema = FlexibleSchema,
|
|
|
156
210
|
widgetType: string;
|
|
157
211
|
schema: TSchema;
|
|
158
212
|
enrich?: WidgetEnrichConfig;
|
|
159
|
-
render(payload: InferSchema<TSchema>, enriched: TEnriched
|
|
213
|
+
render(payload: InferSchema<TSchema>, enriched: TEnriched, options: {
|
|
214
|
+
messageContext?: MessageContext;
|
|
215
|
+
}): ReactElement;
|
|
160
216
|
}
|
|
161
217
|
/** Type guard to check if a widget is an SDK-provided widget */
|
|
162
218
|
declare function isSDKWidget(widget: AnyUIWidgetDefinition): widget is SDKUIWidgetDefinition;
|
|
@@ -228,8 +284,11 @@ interface UIWidgetDefinition<TSchema extends FlexibleSchema = FlexibleSchema, TE
|
|
|
228
284
|
* Render function that receives the payload and enriched results.
|
|
229
285
|
* @param payload - The LLM-generated data matching the schema
|
|
230
286
|
* @param enriched - Enrichment results keyed by name (empty object if no enrich config)
|
|
287
|
+
* @param options - Render options (messageContext, etc.)
|
|
231
288
|
*/
|
|
232
|
-
render(payload: InferSchema<TSchema>, enriched: TEnriched
|
|
289
|
+
render(payload: InferSchema<TSchema>, enriched: TEnriched, options: {
|
|
290
|
+
messageContext?: MessageContext;
|
|
291
|
+
}): unknown;
|
|
233
292
|
}
|
|
234
293
|
/**
|
|
235
294
|
* Helper to create customer widgets.
|
|
@@ -259,7 +318,9 @@ declare const createWidget: <TEnriched extends EnrichedResults = EnrichedResults
|
|
|
259
318
|
schema: any;
|
|
260
319
|
enrich?: WidgetEnrichConfig;
|
|
261
320
|
reactDOM: CustomerReactDOM;
|
|
262
|
-
render(payload: any, enriched: TEnriched
|
|
321
|
+
render(payload: any, enriched: TEnriched, options: {
|
|
322
|
+
messageContext?: MessageContext;
|
|
323
|
+
}): unknown;
|
|
263
324
|
}) => UIWidgetDefinition<FlexibleSchema, TEnriched>;
|
|
264
325
|
|
|
265
326
|
type DisplayMode = 'full' | 'brief';
|
|
@@ -363,33 +424,15 @@ interface PopupChatWidgetProps extends ChatWidgetConfig {
|
|
|
363
424
|
}
|
|
364
425
|
declare function PopupChatWidget({ anchor, ...props }: PopupChatWidgetProps): react_jsx_runtime.JSX.Element;
|
|
365
426
|
|
|
366
|
-
type FeedbackRating = 'positive' | 'negative';
|
|
367
|
-
interface MessageFeedback {
|
|
368
|
-
id: string;
|
|
369
|
-
messageId: string;
|
|
370
|
-
rating: FeedbackRating;
|
|
371
|
-
improvementText?: string;
|
|
372
|
-
createdAt: Date;
|
|
373
|
-
}
|
|
374
|
-
interface FeedbackState {
|
|
375
|
-
rating: FeedbackRating;
|
|
376
|
-
comment?: string;
|
|
377
|
-
}
|
|
378
427
|
interface UseFeedbackConfig {
|
|
379
428
|
api: ApiConfig;
|
|
380
429
|
threadId: string;
|
|
381
|
-
agentId
|
|
430
|
+
agentId: string;
|
|
382
431
|
agentVersion?: AgentVersion;
|
|
383
|
-
agentExecutionId?: string;
|
|
384
|
-
}
|
|
385
|
-
interface SubmitFeedbackParams {
|
|
386
|
-
messageId: string;
|
|
387
|
-
rating: FeedbackRating;
|
|
388
|
-
improvementText?: string;
|
|
389
432
|
}
|
|
390
|
-
declare function useFeedback({ api, threadId, agentId, agentVersion,
|
|
391
|
-
submitFeedback: (
|
|
392
|
-
getFeedbackForMessage: (messageId: string) =>
|
|
433
|
+
declare function useFeedback({ api, threadId, agentId, agentVersion, }: UseFeedbackConfig): {
|
|
434
|
+
submitFeedback: (messageId: string, { rating, improvementText, notes }: SubmitFeedbackParams) => Promise<MessageFeedback | null>;
|
|
435
|
+
getFeedbackForMessage: (messageId: string) => MessageFeedback | undefined;
|
|
393
436
|
hasFeedback: (messageId: string) => boolean;
|
|
394
437
|
isSubmitting: string | null;
|
|
395
438
|
error: Error | null;
|
|
@@ -411,6 +454,14 @@ declare function useFeedback({ api, threadId, agentId, agentVersion, agentExecut
|
|
|
411
454
|
*/
|
|
412
455
|
declare function transformMessage(msg: UIMessage): ChatMessage;
|
|
413
456
|
|
|
457
|
+
interface TagGroupDisplayProps {
|
|
458
|
+
tagId: string;
|
|
459
|
+
isExpanded: boolean;
|
|
460
|
+
onToggle: () => void;
|
|
461
|
+
children: ReactNode;
|
|
462
|
+
}
|
|
463
|
+
declare function TagGroupDisplay({ tagId, isExpanded, onToggle, children, }: TagGroupDisplayProps): react_jsx_runtime.JSX.Element;
|
|
464
|
+
|
|
414
465
|
/** Tool part from UIMessage - either typed tool-* or dynamic-tool */
|
|
415
466
|
type ToolPart = Extract<UIMessagePart, {
|
|
416
467
|
type: `tool-${string}`;
|
|
@@ -423,14 +474,6 @@ interface ToolCallDisplayProps {
|
|
|
423
474
|
}
|
|
424
475
|
declare function ToolCallDisplay({ toolPart, className }: ToolCallDisplayProps): react_jsx_runtime.JSX.Element;
|
|
425
476
|
|
|
426
|
-
interface TagGroupDisplayProps {
|
|
427
|
-
tagId: string;
|
|
428
|
-
isExpanded: boolean;
|
|
429
|
-
onToggle: () => void;
|
|
430
|
-
children: ReactNode;
|
|
431
|
-
}
|
|
432
|
-
declare function TagGroupDisplay({ tagId, isExpanded, onToggle, children, }: TagGroupDisplayProps): react_jsx_runtime.JSX.Element;
|
|
433
|
-
|
|
434
477
|
interface MessageRendererProps {
|
|
435
478
|
/** The message to render */
|
|
436
479
|
message: ChatMessage;
|
|
@@ -447,39 +490,16 @@ interface MessageRendererProps {
|
|
|
447
490
|
};
|
|
448
491
|
/** Optional className for the container */
|
|
449
492
|
className?: string;
|
|
493
|
+
/** Feedback config - if provided, feedback UI will be shown */
|
|
494
|
+
feedback?: FeedbackConfig;
|
|
450
495
|
}
|
|
451
496
|
/**
|
|
452
|
-
* MessageRenderer -
|
|
453
|
-
*
|
|
454
|
-
* Renders the content of a ChatMessage (text, tools, widgets, groups) without
|
|
455
|
-
* any bubble layout. Use this when you want to provide your own bubble/container styling.
|
|
456
|
-
*
|
|
457
|
-
* For a complete solution with bubble layout included, use MessageBubbleRenderer.
|
|
458
|
-
*/
|
|
459
|
-
declare function MessageRenderer({ message, widgets, readonly, displayMode, tagExpansion, className, }: MessageRendererProps): react_jsx_runtime.JSX.Element;
|
|
460
|
-
|
|
461
|
-
interface MessageWithFeedbackRendererProps extends MessageRendererProps {
|
|
462
|
-
/** Feedback configuration (ignored if readonly=true) */
|
|
463
|
-
feedback?: {
|
|
464
|
-
enabled: boolean;
|
|
465
|
-
showButtons?: boolean;
|
|
466
|
-
existingRating?: FeedbackRating;
|
|
467
|
-
existingComment?: string;
|
|
468
|
-
submitting?: boolean;
|
|
469
|
-
requireCommentForNegative?: boolean;
|
|
470
|
-
onSubmit?: (rating: FeedbackRating, comment?: string) => void;
|
|
471
|
-
};
|
|
472
|
-
}
|
|
473
|
-
/**
|
|
474
|
-
* MessageWithFeedbackRenderer - message renderer with optional feedback UI.
|
|
475
|
-
*
|
|
476
|
-
* Wraps MessageRenderer and adds feedback buttons for assistant messages.
|
|
477
|
-
* Use this when you want content rendering + feedback without bubble styling.
|
|
497
|
+
* MessageRenderer - renders message content with optional feedback UI.
|
|
478
498
|
*
|
|
479
|
-
*
|
|
480
|
-
*
|
|
499
|
+
* Renders the content of a ChatMessage (text, tools, widgets, groups) and optionally
|
|
500
|
+
* displays feedback buttons for assistant messages.
|
|
481
501
|
*/
|
|
482
|
-
declare function
|
|
502
|
+
declare function MessageRenderer({ message, widgets, readonly, displayMode, tagExpansion, className, feedback, }: MessageRendererProps): react_jsx_runtime.JSX.Element;
|
|
483
503
|
|
|
484
504
|
interface DisplayModeProps {
|
|
485
505
|
/** Message sections to render */
|
|
@@ -548,4 +568,4 @@ declare const getVendorCardsWidget: (isProd?: boolean) => SDKUIWidgetDefinition[
|
|
|
548
568
|
|
|
549
569
|
declare function cn(...inputs: ClassValue[]): string;
|
|
550
570
|
|
|
551
|
-
export { type AgentVersion, type AnyUIWidgetDefinition, type ApiConfig, BriefDisplayMode, BriefDisplayMode as BriefRenderer, type ChatMessage, type ChatMessageSection, ChatWidget, type ChatWidgetFeedbackOptions, type ChatWidgetHandle, type ChatWidgetConfig as ChatWidgetProps, type ChatWidgetSpeechToTextOptions, type ChatWidgetStyles, type ChatWidgetVoiceOptions, type CustomerReactDOM, type DisplayMode, type DisplayModeProps, type EmbeddableChatWidgetConfig, type EnrichedResults, type
|
|
571
|
+
export { type AgentVersion, type AnyUIWidgetDefinition, type ApiConfig, BriefDisplayMode, BriefDisplayMode as BriefRenderer, type ChatMessage, type ChatMessageSection, ChatWidget, type ChatWidgetFeedbackOptions, type ChatWidgetHandle, type ChatWidgetConfig as ChatWidgetProps, type ChatWidgetSpeechToTextOptions, type ChatWidgetStyles, type ChatWidgetVoiceOptions, type CustomerReactDOM, type DisplayMode, type DisplayModeProps, type EmbeddableChatWidgetConfig, type EnrichedResults, type FeedbackConfig, type FeedbackHandlers, type FeedbackNote, type FeedbackRating, FullDisplayMode, FullDisplayMode as FullRenderer, type MessageContext, type MessageFeedback, MessageRenderer, type MessageRendererProps, type PopupAnchorConfig, PopupChatWidget, type PopupChatWidgetProps, type DisplayModeProps as RendererProps, type SDKUIWidgetDefinition, SDK_WIDGET_MARKER, type SubmitFeedbackParams, TagGroupDisplay, type TagGroupDisplayProps, ToolCallDisplay, type ToolCallDisplayProps, type ToolPart, type UIMessagePart, type UIWidgetDefinition, type UseChatConfig, type UseFeedbackConfig, type WidgetEnrichConfig, cn, createSDKWidget, createWidget, defaultChatWidgets, getVendorCardsWidget, isSDKWidget, registerChatWidgets, transformMessage, useChat, useFeedback };
|