@ensembleapp/client-sdk 0.0.34 → 0.0.36

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 CHANGED
@@ -1,4 +1,4 @@
1
- import React$1, { ReactElement } from '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';
@@ -39,7 +39,7 @@ type DeprecatedChatConfig = {
39
39
  agentExecutionId?: string;
40
40
  };
41
41
  interface ApiConfig {
42
- /** The base URL where /chat and /chat/messages are hosted */
42
+ /** The base URL where /api/chat and /api/chat/messages are hosted */
43
43
  baseUrl: string;
44
44
  /** JWT token generated from Secret */
45
45
  token: string;
@@ -232,10 +232,10 @@ interface UIWidgetDefinition<TSchema extends FlexibleSchema = FlexibleSchema, TE
232
232
  render(payload: InferSchema<TSchema>, enriched: TEnriched): unknown;
233
233
  }
234
234
  /**
235
- * Helper to create customer widgets with type inference.
235
+ * Helper to create customer widgets.
236
236
  *
237
- * Provides autocomplete and type checking for widget definitions.
238
- * The render function receives typed payload based on your schema.
237
+ * Note: Uses loose typing for schema to avoid "Type instantiation is excessively deep"
238
+ * errors with complex Zod schemas. Schema is validated at runtime, not compile time.
239
239
  *
240
240
  * @example
241
241
  * ```typescript
@@ -254,7 +254,13 @@ interface UIWidgetDefinition<TSchema extends FlexibleSchema = FlexibleSchema, TE
254
254
  * });
255
255
  * ```
256
256
  */
257
- declare const createWidget: <TSchema extends FlexibleSchema, TEnriched extends EnrichedResults = EnrichedResults>({ widgetType, schema, enrich, reactDOM, render, }: UIWidgetDefinition<TSchema, TEnriched>) => UIWidgetDefinition<TSchema, TEnriched>;
257
+ declare const createWidget: <TEnriched extends EnrichedResults = EnrichedResults>(widget: {
258
+ widgetType: string;
259
+ schema: any;
260
+ enrich?: WidgetEnrichConfig;
261
+ reactDOM: CustomerReactDOM;
262
+ render(payload: any, enriched: TEnriched): unknown;
263
+ }) => UIWidgetDefinition<FlexibleSchema, TEnriched>;
258
264
 
259
265
  type DisplayMode = 'full' | 'brief';
260
266
 
@@ -321,7 +327,7 @@ interface ChatWidgetConfig extends UseChatConfig {
321
327
  /** Feedback options for assistant messages. Enabled by default. */
322
328
  feedback?: ChatWidgetFeedbackOptions;
323
329
  }
324
- declare const ChatWidget: React$1.ForwardRefExoticComponent<ChatWidgetConfig & React$1.RefAttributes<ChatWidgetHandle>>;
330
+ declare const ChatWidget: React.ForwardRefExoticComponent<ChatWidgetConfig & React.RefAttributes<ChatWidgetHandle>>;
325
331
 
326
332
  interface PopupAnchorConfig {
327
333
  enabled?: boolean;
@@ -331,13 +337,13 @@ interface PopupAnchorConfig {
331
337
  render?: (options: {
332
338
  isOpen: boolean;
333
339
  toggle: () => void;
334
- }) => React$1.ReactNode;
340
+ }) => React.ReactNode;
335
341
  closeButton?: PopupCloseConfig;
336
342
  }
337
343
  interface PopupCloseConfig {
338
344
  render?: (options: {
339
345
  toggle: () => void;
340
- }) => React$1.ReactNode;
346
+ }) => React.ReactNode;
341
347
  position?: 'top-end' | 'top-start';
342
348
  show?: boolean;
343
349
  }
@@ -389,6 +395,22 @@ declare function useFeedback({ api, threadId, agentId, agentVersion, agentExecut
389
395
  error: Error | null;
390
396
  };
391
397
 
398
+ /**
399
+ * Transforms a UIMessage into a ChatMessage with sections.
400
+ *
401
+ * Groups UIMessage.parts into step and group sections:
402
+ * - step: content between step-start markers (one LLM turn)
403
+ * - group: content within data-tag-start/end markers (sub-agent output)
404
+ *
405
+ * Parts pass through as-is - no content transformation.
406
+ * Structural markers (step-start, data-tag-*, data-transfer, data-thoughts)
407
+ * are consumed during grouping and not included in output.
408
+ *
409
+ * @param msg - The UIMessage from AI SDK
410
+ * @returns ChatMessage with sections
411
+ */
412
+ declare function transformMessage(msg: UIMessage): ChatMessage;
413
+
392
414
  /** Tool part from UIMessage - either typed tool-* or dynamic-tool */
393
415
  type ToolPart = Extract<UIMessagePart, {
394
416
  type: `tool-${string}`;
@@ -405,34 +427,84 @@ interface TagGroupDisplayProps {
405
427
  tagId: string;
406
428
  isExpanded: boolean;
407
429
  onToggle: () => void;
408
- children: React.ReactNode;
430
+ children: ReactNode;
409
431
  }
410
432
  declare function TagGroupDisplay({ tagId, isExpanded, onToggle, children, }: TagGroupDisplayProps): react_jsx_runtime.JSX.Element;
411
433
 
412
- interface RendererProps {
434
+ interface MessageRendererProps {
435
+ /** The message to render */
436
+ message: ChatMessage;
437
+ /** Widget definitions for rendering data-ui parts */
438
+ widgets?: AnyUIWidgetDefinition[];
439
+ /** Readonly mode - disables all widget interactions */
440
+ readonly?: boolean;
441
+ /** Display mode: 'brief' collapses previous steps, 'full' shows everything */
442
+ displayMode?: 'brief' | 'full';
443
+ /** Tag expansion state and handler */
444
+ tagExpansion?: {
445
+ state: Map<string, boolean>;
446
+ onToggle: (tagId: string) => void;
447
+ };
448
+ /** Optional className for the container */
449
+ className?: string;
450
+ }
451
+ /**
452
+ * MessageRenderer - content-only message renderer.
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.
478
+ *
479
+ * For a complete solution with ChatWidget bubble layout, use ChatWidget directly.
480
+ * For content-only rendering, use MessageRenderer.
481
+ */
482
+ declare function MessageWithFeedbackRenderer({ message, widgets, readonly, displayMode, tagExpansion, className, feedback, }: MessageWithFeedbackRendererProps): react_jsx_runtime.JSX.Element;
483
+
484
+ interface DisplayModeProps {
413
485
  /** Message sections to render */
414
486
  sections: ChatMessageSection[];
415
487
  /** Unique message ID for keying */
416
488
  messageId: string;
417
489
  /** Render function for individual parts (text, widgets, tool calls) */
418
- renderPart: (part: UIMessagePart, key: string) => React$1.ReactNode;
490
+ renderPart: (part: UIMessagePart, key: string) => ReactNode;
419
491
  /** Render function for group sections */
420
- renderGroup: (groupName: string, key: string, children: React$1.ReactNode) => React$1.ReactNode;
492
+ renderGroup: (groupName: string, key: string, children: ReactNode) => ReactNode;
421
493
  }
422
494
 
423
495
  /**
424
- * Full display mode renderer - shows all content without collapsing.
425
- * Each section is rendered as-is in chronological order.
426
- */
427
- declare function FullRenderer({ sections, messageId, renderPart, renderGroup, }: RendererProps): react_jsx_runtime.JSX.Element;
428
-
429
- /**
430
- * Brief display mode renderer - collapses previous steps.
496
+ * Brief display mode - collapses previous steps.
431
497
  *
432
498
  * All steps before the last one are collapsed into a single "Show more" section.
433
499
  * Groups collapse their internal content similarly.
434
500
  */
435
- declare function BriefRenderer({ sections, messageId, renderPart, renderGroup, }: RendererProps): react_jsx_runtime.JSX.Element;
501
+ declare function BriefDisplayMode({ sections, messageId, renderPart, renderGroup, }: DisplayModeProps): react_jsx_runtime.JSX.Element;
502
+
503
+ /**
504
+ * Full display mode - shows all content without collapsing.
505
+ * Each section is rendered as-is in chronological order.
506
+ */
507
+ declare function FullDisplayMode({ sections, messageId, renderPart, renderGroup, }: DisplayModeProps): react_jsx_runtime.JSX.Element;
436
508
 
437
509
  type RegisterChatWidgetsParams = {
438
510
  api: ApiConfig;
@@ -476,4 +548,4 @@ declare const getVendorCardsWidget: (isProd?: boolean) => SDKUIWidgetDefinition[
476
548
 
477
549
  declare function cn(...inputs: ClassValue[]): string;
478
550
 
479
- 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 FeedbackRating, type FeedbackState, FullRenderer, type MessageFeedback, type PopupAnchorConfig, PopupChatWidget, type PopupChatWidgetProps, type 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, useChat, useFeedback };
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 FeedbackRating, type FeedbackState, FullDisplayMode, FullDisplayMode as FullRenderer, MessageWithFeedbackRenderer as MessageBubbleRenderer, type MessageWithFeedbackRendererProps as MessageBubbleRendererProps, type MessageFeedback, MessageRenderer, type MessageRendererProps, MessageWithFeedbackRenderer, type MessageWithFeedbackRendererProps, 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 };