@ensembleapp/client-sdk 0.0.35 → 0.0.37
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 +137 -51
- package/dist/index.js +5597 -5321
- package/dist/index.js.map +1 -1
- package/dist/widget/widget.global.js +48 -47
- package/dist/widget/widget.global.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import React
|
|
1
|
+
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
|
|
|
@@ -39,7 +40,7 @@ type DeprecatedChatConfig = {
|
|
|
39
40
|
agentExecutionId?: string;
|
|
40
41
|
};
|
|
41
42
|
interface ApiConfig {
|
|
42
|
-
/** The base URL where /chat and /chat/messages are hosted */
|
|
43
|
+
/** The base URL where /api/chat and /api/chat/messages are hosted */
|
|
43
44
|
baseUrl: string;
|
|
44
45
|
/** JWT token generated from Secret */
|
|
45
46
|
token: string;
|
|
@@ -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';
|
|
@@ -327,7 +388,7 @@ interface ChatWidgetConfig extends UseChatConfig {
|
|
|
327
388
|
/** Feedback options for assistant messages. Enabled by default. */
|
|
328
389
|
feedback?: ChatWidgetFeedbackOptions;
|
|
329
390
|
}
|
|
330
|
-
declare const ChatWidget: React
|
|
391
|
+
declare const ChatWidget: React.ForwardRefExoticComponent<ChatWidgetConfig & React.RefAttributes<ChatWidgetHandle>>;
|
|
331
392
|
|
|
332
393
|
interface PopupAnchorConfig {
|
|
333
394
|
enabled?: boolean;
|
|
@@ -337,13 +398,13 @@ interface PopupAnchorConfig {
|
|
|
337
398
|
render?: (options: {
|
|
338
399
|
isOpen: boolean;
|
|
339
400
|
toggle: () => void;
|
|
340
|
-
}) => React
|
|
401
|
+
}) => React.ReactNode;
|
|
341
402
|
closeButton?: PopupCloseConfig;
|
|
342
403
|
}
|
|
343
404
|
interface PopupCloseConfig {
|
|
344
405
|
render?: (options: {
|
|
345
406
|
toggle: () => void;
|
|
346
|
-
}) => React
|
|
407
|
+
}) => React.ReactNode;
|
|
347
408
|
position?: 'top-end' | 'top-start';
|
|
348
409
|
show?: boolean;
|
|
349
410
|
}
|
|
@@ -363,38 +424,44 @@ 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;
|
|
396
439
|
};
|
|
397
440
|
|
|
441
|
+
/**
|
|
442
|
+
* Transforms a UIMessage into a ChatMessage with sections.
|
|
443
|
+
*
|
|
444
|
+
* Groups UIMessage.parts into step and group sections:
|
|
445
|
+
* - step: content between step-start markers (one LLM turn)
|
|
446
|
+
* - group: content within data-tag-start/end markers (sub-agent output)
|
|
447
|
+
*
|
|
448
|
+
* Parts pass through as-is - no content transformation.
|
|
449
|
+
* Structural markers (step-start, data-tag-*, data-transfer, data-thoughts)
|
|
450
|
+
* are consumed during grouping and not included in output.
|
|
451
|
+
*
|
|
452
|
+
* @param msg - The UIMessage from AI SDK
|
|
453
|
+
* @returns ChatMessage with sections
|
|
454
|
+
*/
|
|
455
|
+
declare function transformMessage(msg: UIMessage): ChatMessage;
|
|
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
|
+
|
|
398
465
|
/** Tool part from UIMessage - either typed tool-* or dynamic-tool */
|
|
399
466
|
type ToolPart = Extract<UIMessagePart, {
|
|
400
467
|
type: `tool-${string}`;
|
|
@@ -407,38 +474,57 @@ interface ToolCallDisplayProps {
|
|
|
407
474
|
}
|
|
408
475
|
declare function ToolCallDisplay({ toolPart, className }: ToolCallDisplayProps): react_jsx_runtime.JSX.Element;
|
|
409
476
|
|
|
410
|
-
interface
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
477
|
+
interface MessageRendererProps {
|
|
478
|
+
/** The message to render */
|
|
479
|
+
message: ChatMessage;
|
|
480
|
+
/** Widget definitions for rendering data-ui parts */
|
|
481
|
+
widgets?: AnyUIWidgetDefinition[];
|
|
482
|
+
/** Readonly mode - disables all widget interactions */
|
|
483
|
+
readonly?: boolean;
|
|
484
|
+
/** Display mode: 'brief' collapses previous steps, 'full' shows everything */
|
|
485
|
+
displayMode?: 'brief' | 'full';
|
|
486
|
+
/** Tag expansion state and handler */
|
|
487
|
+
tagExpansion?: {
|
|
488
|
+
state: Map<string, boolean>;
|
|
489
|
+
onToggle: (tagId: string) => void;
|
|
490
|
+
};
|
|
491
|
+
/** Optional className for the container */
|
|
492
|
+
className?: string;
|
|
493
|
+
/** Feedback config - if provided, feedback UI will be shown */
|
|
494
|
+
feedback?: FeedbackConfig;
|
|
415
495
|
}
|
|
416
|
-
|
|
496
|
+
/**
|
|
497
|
+
* MessageRenderer - renders message content with optional feedback UI.
|
|
498
|
+
*
|
|
499
|
+
* Renders the content of a ChatMessage (text, tools, widgets, groups) and optionally
|
|
500
|
+
* displays feedback buttons for assistant messages.
|
|
501
|
+
*/
|
|
502
|
+
declare function MessageRenderer({ message, widgets, readonly, displayMode, tagExpansion, className, feedback, }: MessageRendererProps): react_jsx_runtime.JSX.Element;
|
|
417
503
|
|
|
418
|
-
interface
|
|
504
|
+
interface DisplayModeProps {
|
|
419
505
|
/** Message sections to render */
|
|
420
506
|
sections: ChatMessageSection[];
|
|
421
507
|
/** Unique message ID for keying */
|
|
422
508
|
messageId: string;
|
|
423
509
|
/** Render function for individual parts (text, widgets, tool calls) */
|
|
424
|
-
renderPart: (part: UIMessagePart, key: string) =>
|
|
510
|
+
renderPart: (part: UIMessagePart, key: string) => ReactNode;
|
|
425
511
|
/** Render function for group sections */
|
|
426
|
-
renderGroup: (groupName: string, key: string, children:
|
|
512
|
+
renderGroup: (groupName: string, key: string, children: ReactNode) => ReactNode;
|
|
427
513
|
}
|
|
428
514
|
|
|
429
515
|
/**
|
|
430
|
-
*
|
|
431
|
-
* Each section is rendered as-is in chronological order.
|
|
432
|
-
*/
|
|
433
|
-
declare function FullRenderer({ sections, messageId, renderPart, renderGroup, }: RendererProps): react_jsx_runtime.JSX.Element;
|
|
434
|
-
|
|
435
|
-
/**
|
|
436
|
-
* Brief display mode renderer - collapses previous steps.
|
|
516
|
+
* Brief display mode - collapses previous steps.
|
|
437
517
|
*
|
|
438
518
|
* All steps before the last one are collapsed into a single "Show more" section.
|
|
439
519
|
* Groups collapse their internal content similarly.
|
|
440
520
|
*/
|
|
441
|
-
declare function
|
|
521
|
+
declare function BriefDisplayMode({ sections, messageId, renderPart, renderGroup, }: DisplayModeProps): react_jsx_runtime.JSX.Element;
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* Full display mode - shows all content without collapsing.
|
|
525
|
+
* Each section is rendered as-is in chronological order.
|
|
526
|
+
*/
|
|
527
|
+
declare function FullDisplayMode({ sections, messageId, renderPart, renderGroup, }: DisplayModeProps): react_jsx_runtime.JSX.Element;
|
|
442
528
|
|
|
443
529
|
type RegisterChatWidgetsParams = {
|
|
444
530
|
api: ApiConfig;
|
|
@@ -482,4 +568,4 @@ declare const getVendorCardsWidget: (isProd?: boolean) => SDKUIWidgetDefinition[
|
|
|
482
568
|
|
|
483
569
|
declare function cn(...inputs: ClassValue[]): string;
|
|
484
570
|
|
|
485
|
-
export { type AgentVersion, type AnyUIWidgetDefinition, type ApiConfig, 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 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 };
|