@ensembleapp/client-sdk 0.0.26 → 0.0.28

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,99 +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
- /** @minimum 1 */
9
- type VersionSelector = 'latest' | 'published' | number;
8
+ /** Derived part type from UIMessage */
9
+ type UIMessagePart = UIMessage['parts'][number];
10
10
  /**
11
- * fetch data via tool call.
12
- */
13
- type ToolCallConfig = {
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
- * 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
- * ```
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 WidgetEnrichConfig = Record<string, ToolCallConfig>;
44
- /**
45
- * Enrichment result containing the full tool response.
46
- * This should mirror ToolResult on server-side without debug/metadata info.
47
- */
48
- type EnrichmentResult<TData = unknown> = {
49
- success: boolean;
50
- error?: {
51
- message?: string;
52
- code?: string;
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
- };
64
-
65
- interface ToolCallContent {
66
- type: 'tool-call';
67
- toolName: string;
68
- input?: Record<string, unknown>;
69
- state: 'pending' | 'output-available' | 'error';
70
- output?: unknown;
71
- }
72
- type ChatContentItem = string | UIWidget | ToolCallContent;
73
- /** A grouped section of sub-agent output, wrapped by data-tag-start/end markers */
74
- interface TagGroup {
75
- tagId: string;
76
- content: ChatContentItem[];
77
- /** Index into content[] where the last step begins (for promoting only final output) */
78
- lastStepStartIndex?: number;
79
- }
80
- /** A single section in the message, rendered in chronological order */
81
- type MessageSection = {
82
- type: 'content';
83
- item: ChatContentItem;
18
+ type ChatMessageSection = {
19
+ type: 'step';
20
+ parts: UIMessagePart[];
84
21
  } | {
85
- type: 'tag-group';
86
- group: TagGroup;
22
+ type: 'group';
23
+ groupName: string;
24
+ parts: UIMessagePart[];
87
25
  };
26
+ /**
27
+ * ChatMessage = our UIMessage abstraction to account for step and groupings
28
+ * Passes through id, role, metadata. Replaces parts with sections.
29
+ */
88
30
  interface ChatMessage {
89
31
  id: string;
90
32
  role: 'user' | 'assistant';
91
- /** Ordered sections: content items and tag groups interleaved chronologically */
92
- sections: MessageSection[];
93
- thoughts?: (string | UIWidget)[];
94
- createdAt?: Date;
33
+ metadata?: unknown;
34
+ sections: ChatMessageSection[];
95
35
  }
96
- type DisplayMode = 'full' | 'brief';
97
36
 
98
37
  type DeprecatedChatConfig = {
99
38
  /** @deprecated use agentId instead */
@@ -106,6 +45,8 @@ interface ApiConfig {
106
45
  token: string;
107
46
  headers?: Record<string, string>;
108
47
  }
48
+ /** Agent version selector: 'latest' (default), 'published', or a specific version number */
49
+ type AgentVersion = 'latest' | 'published' | number;
109
50
  type UseChatConfig = DeprecatedChatConfig & {
110
51
  /** The server API configuration */
111
52
  api: ApiConfig;
@@ -113,10 +54,10 @@ type UseChatConfig = DeprecatedChatConfig & {
113
54
  threadId: string;
114
55
  /** Ensemble agent ID to connect to */
115
56
  agentId?: string;
57
+ /** Agent version: 'latest' (default), 'published', or a specific version number */
58
+ agentVersion?: AgentVersion;
116
59
  /** additional context (anything) that needs to be passed to the LLM */
117
60
  dataContext?: unknown;
118
- /** Display mode: 'brief' (default) shows only last block per step, 'full' shows everything */
119
- displayMode?: DisplayMode;
120
61
  onError?: (error: Error) => void;
121
62
  /** Called when API returns 401/unauthorized (e.g., token expiry). Return a new token to retry the request. */
122
63
  onAuthError?: () => Promise<string | null>;
@@ -124,7 +65,7 @@ type UseChatConfig = DeprecatedChatConfig & {
124
65
  onData?: (data: any) => void;
125
66
  onMessage?: (message: UIMessage) => void;
126
67
  };
127
- declare function useChat({ api, threadId, agentId, agentExecutionId, dataContext, displayMode, onError, onAuthError, onFinish, onData, onMessage, }: UseChatConfig): {
68
+ declare function useChat({ api, threadId, agentId, agentVersion, agentExecutionId, dataContext, onError, onAuthError, onFinish, onData, onMessage, }: UseChatConfig): {
128
69
  messages: ChatMessage[];
129
70
  status: ai.ChatStatus;
130
71
  isLoadingInitial: boolean;
@@ -151,35 +92,53 @@ declare function useChat({ api, threadId, agentId, agentExecutionId, dataContext
151
92
  setMessages: (messages: UIMessage<unknown, ai.UIDataTypes, ai.UITools>[] | ((messages: UIMessage<unknown, ai.UIDataTypes, ai.UITools>[]) => UIMessage<unknown, ai.UIDataTypes, ai.UITools>[])) => void;
152
93
  };
153
94
 
154
- type FeedbackRating = 'positive' | 'negative';
155
- interface MessageFeedback {
156
- id: string;
157
- messageId: string;
158
- rating: FeedbackRating;
159
- improvementText?: string;
160
- createdAt: Date;
161
- }
162
- interface FeedbackState {
163
- rating: FeedbackRating;
164
- comment?: string;
165
- }
166
- interface UseFeedbackConfig {
167
- api: ApiConfig;
168
- threadId: string;
169
- agentId?: string;
170
- agentExecutionId?: string;
171
- }
172
- interface SubmitFeedbackParams {
173
- messageId: string;
174
- rating: FeedbackRating;
175
- improvementText?: string;
176
- }
177
- declare function useFeedback({ api, threadId, agentId, agentExecutionId, }: UseFeedbackConfig): {
178
- submitFeedback: ({ messageId, rating, improvementText }: SubmitFeedbackParams) => Promise<MessageFeedback | null>;
179
- getFeedbackForMessage: (messageId: string) => FeedbackState | undefined;
180
- hasFeedback: (messageId: string) => boolean;
181
- isSubmitting: string | null;
182
- error: Error | null;
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;
183
142
  };
184
143
 
185
144
  /** Enriched results keyed by enrichment name */
@@ -209,6 +168,8 @@ interface UIWidgetDefinition<TSchema extends AnyZodObject = AnyZodObject, TEnric
209
168
  }
210
169
  declare const createWidget: <TSchema extends AnyZodObject, TEnriched extends EnrichedResults = EnrichedResults>({ widgetType, schema, enrich, render, }: UIWidgetDefinition<TSchema, TEnriched>) => UIWidgetDefinition<TSchema, TEnriched>;
211
170
 
171
+ type DisplayMode = 'full' | 'brief';
172
+
212
173
  interface ChatWidgetStyles {
213
174
  primaryColor?: string;
214
175
  primaryTextColor?: string;
@@ -246,11 +207,9 @@ interface ChatWidgetFeedbackOptions {
246
207
  /** Require comment when giving negative feedback. Default: false */
247
208
  requireCommentForNegative?: boolean;
248
209
  }
249
- interface ChatWidgetConfig extends Omit<UseChatConfig, 'displayMode'> {
210
+ interface ChatWidgetConfig extends UseChatConfig {
250
211
  /** Title for the Chat window */
251
212
  title?: string;
252
- /** Display mode: 'brief' (default) shows only last block per step, 'full' shows everything */
253
- displayMode?: DisplayMode;
254
213
  /** Initial assistant message displayed at the start of the chat (if history is empty).
255
214
  * Skipped if initialUserMessage is provided. */
256
215
  initialAssistantMessage?: string;
@@ -259,6 +218,8 @@ interface ChatWidgetConfig extends Omit<UseChatConfig, 'displayMode'> {
259
218
  initialUserMessage?: string;
260
219
  /** Placeholder text for the input box */
261
220
  inputPlaceholder?: string;
221
+ /** Display mode: 'brief' (default) collapses previous steps, 'full' shows everything */
222
+ displayMode?: DisplayMode;
262
223
  className?: string;
263
224
  styles?: ChatWidgetStyles;
264
225
  voice?: ChatWidgetVoiceOptions;
@@ -267,7 +228,7 @@ interface ChatWidgetConfig extends Omit<UseChatConfig, 'displayMode'> {
267
228
  /** Feedback options for assistant messages. Enabled by default. */
268
229
  feedback?: ChatWidgetFeedbackOptions;
269
230
  }
270
- declare function ChatWidget({ api, threadId, agentId, agentExecutionId, dataContext, displayMode, 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;
271
232
 
272
233
  interface PopupAnchorConfig {
273
234
  enabled?: boolean;
@@ -303,11 +264,49 @@ interface PopupChatWidgetProps extends ChatWidgetConfig {
303
264
  }
304
265
  declare function PopupChatWidget({ anchor, ...props }: PopupChatWidgetProps): react_jsx_runtime.JSX.Element;
305
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
+ }>;
306
305
  interface ToolCallDisplayProps {
307
- toolCall: ToolCallContent;
306
+ toolPart: ToolPart;
308
307
  className?: string;
309
308
  }
310
- declare function ToolCallDisplay({ toolCall, className }: ToolCallDisplayProps): react_jsx_runtime.JSX.Element;
309
+ declare function ToolCallDisplay({ toolPart, className }: ToolCallDisplayProps): react_jsx_runtime.JSX.Element;
311
310
 
312
311
  interface TagGroupDisplayProps {
313
312
  tagId: string;
@@ -317,6 +316,31 @@ interface TagGroupDisplayProps {
317
316
  }
318
317
  declare function TagGroupDisplay({ tagId, isExpanded, onToggle, children, }: TagGroupDisplayProps): react_jsx_runtime.JSX.Element;
319
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
+
320
344
  type RegisterChatWidgetsParams = {
321
345
  api: ApiConfig;
322
346
  threadId: string;
@@ -357,4 +381,4 @@ declare const getVendorCardsWidget: (isProd?: boolean) => UIWidgetDefinition[];
357
381
 
358
382
  declare function cn(...inputs: ClassValue[]): string;
359
383
 
360
- export { type ApiConfig, type ChatContentItem, type ChatMessage, ChatWidget, type ChatWidgetFeedbackOptions, type ChatWidgetConfig as ChatWidgetProps, type ChatWidgetSpeechToTextOptions, type ChatWidgetStyles, type ChatWidgetVoiceOptions, type DisplayMode, type EmbeddableChatWidgetConfig, type EnrichedResults, 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, createWidget, defaultChatWidgets, getVendorCardsWidget, registerChatWidgets, useChat, useFeedback };
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 };