@ensembleapp/client-sdk 0.0.55 → 0.0.56

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
@@ -86,6 +86,12 @@ interface ChatUsageData {
86
86
  * part is not a usage part.
87
87
  */
88
88
  declare function extractUsageData(dataPart: unknown): ChatUsageData | null;
89
+ /**
90
+ * Build the GET /chat/messages URL for loading initial history. Appends
91
+ * `?limit=<n>` when `messagesToLoad` is provided (a positive number), otherwise
92
+ * returns the base URL so the server default applies.
93
+ */
94
+ declare function buildMessagesUrl(baseUrl: string, messagesToLoad?: number): string;
89
95
  type UseChatConfig = DeprecatedChatConfig & {
90
96
  /** The server API configuration */
91
97
  api: ApiConfig;
@@ -97,6 +103,8 @@ type UseChatConfig = DeprecatedChatConfig & {
97
103
  agentVersion?: AgentVersion;
98
104
  /** additional context (anything) that needs to be passed to the LLM */
99
105
  dataContext?: unknown;
106
+ /** Number of most-recent messages to load into the chat on open/reload. Defaults to the server's default. */
107
+ messagesToLoad?: number;
100
108
  onError?: (error: Error) => void;
101
109
  /** Called when API returns 401/unauthorized (e.g., token expiry). Return a new token to retry the request. */
102
110
  onAuthError?: () => Promise<string | null>;
@@ -106,7 +114,7 @@ type UseChatConfig = DeprecatedChatConfig & {
106
114
  /** Called when usage data is received (token counts/percentages and message-history stats) */
107
115
  onUsage?: (usage: ChatUsageData) => void;
108
116
  };
109
- declare function useChat({ api, threadId, agentId, agentVersion, agentExecutionId, dataContext, onError, onAuthError, onFinish, onData, onMessage, onUsage, }: UseChatConfig): {
117
+ declare function useChat({ api, threadId, agentId, agentVersion, agentExecutionId, dataContext, messagesToLoad, onError, onAuthError, onFinish, onData, onMessage, onUsage, }: UseChatConfig): {
110
118
  messages: ChatMessage[];
111
119
  status: ai.ChatStatus;
112
120
  isLoadingInitial: boolean;
@@ -661,4 +669,4 @@ declare const getVendorCardsWidget: (isProd?: boolean) => SDKUIWidgetDefinition[
661
669
 
662
670
  declare function cn(...inputs: ClassValue[]): string;
663
671
 
664
- export { type AgentVersion, type AnyUIWidgetDefinition, type ApiConfig, type ApprovalUIConfig, BriefDisplayMode, BriefDisplayMode as BriefRenderer, type ChatMessage, type ChatMessageSection, type ChatUsageData, 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 FetchApprovalConfigOptions, FullDisplayMode, FullDisplayMode as FullRenderer, HideToolsDisplayMode, HideToolsDisplayMode as HideToolsRenderer, type InvokeTool, type MessageContext, MessageRenderer, type MessageRendererProps, type PendingToolApproval, type PendingToolOutput, type PopupAnchorConfig, PopupChatWidget, type PopupChatWidgetProps, type DisplayModeProps as RendererProps, type SDKUIWidgetDefinition, SDK_WIDGET_MARKER, type StructuredMessagePayload, type SubmitFeedbackParams, TagGroupDisplay, type TagGroupDisplayProps, ToolCallDisplay, type ToolCallDisplayProps, type ToolInvokeRequest, type ToolInvokeResult, type ToolPart, type UIMessagePart, type UIWidgetDefinition, type UseChatConfig, type UseFeedbackConfig, type WidgetRenderOptions, cn, createSDKWidget, createWidget, defaultChatWidgets, extractUsageData, fetchApprovalConfig, getVendorCardsWidget, isSDKWidget, registerChatWidgets, transformMessage, useChat, useFeedback };
672
+ export { type AgentVersion, type AnyUIWidgetDefinition, type ApiConfig, type ApprovalUIConfig, BriefDisplayMode, BriefDisplayMode as BriefRenderer, type ChatMessage, type ChatMessageSection, type ChatUsageData, 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 FetchApprovalConfigOptions, FullDisplayMode, FullDisplayMode as FullRenderer, HideToolsDisplayMode, HideToolsDisplayMode as HideToolsRenderer, type InvokeTool, type MessageContext, MessageRenderer, type MessageRendererProps, type PendingToolApproval, type PendingToolOutput, type PopupAnchorConfig, PopupChatWidget, type PopupChatWidgetProps, type DisplayModeProps as RendererProps, type SDKUIWidgetDefinition, SDK_WIDGET_MARKER, type StructuredMessagePayload, type SubmitFeedbackParams, TagGroupDisplay, type TagGroupDisplayProps, ToolCallDisplay, type ToolCallDisplayProps, type ToolInvokeRequest, type ToolInvokeResult, type ToolPart, type UIMessagePart, type UIWidgetDefinition, type UseChatConfig, type UseFeedbackConfig, type WidgetRenderOptions, buildMessagesUrl, cn, createSDKWidget, createWidget, defaultChatWidgets, extractUsageData, fetchApprovalConfig, getVendorCardsWidget, isSDKWidget, registerChatWidgets, transformMessage, useChat, useFeedback };
package/dist/index.js CHANGED
@@ -4226,6 +4226,13 @@ function extractUsageData(dataPart) {
4226
4226
  }
4227
4227
  return null;
4228
4228
  }
4229
+ function buildMessagesUrl(baseUrl, messagesToLoad) {
4230
+ const base = `${baseUrl}/chat/messages`;
4231
+ if (messagesToLoad != null && Number.isFinite(messagesToLoad) && messagesToLoad > 0) {
4232
+ return `${base}?limit=${messagesToLoad}`;
4233
+ }
4234
+ return base;
4235
+ }
4229
4236
  var EMPTY_HEADERS = {};
4230
4237
  function useChat({
4231
4238
  api,
@@ -4234,6 +4241,7 @@ function useChat({
4234
4241
  agentVersion,
4235
4242
  agentExecutionId,
4236
4243
  dataContext,
4244
+ messagesToLoad,
4237
4245
  onError,
4238
4246
  onAuthError,
4239
4247
  onFinish,
@@ -4338,7 +4346,7 @@ function useChat({
4338
4346
  const fetchInitialMessages = async () => {
4339
4347
  hasFetchedRef.current = true;
4340
4348
  try {
4341
- const response = await authFetch(`${baseUrl}/chat/messages`, {
4349
+ const response = await authFetch(buildMessagesUrl(baseUrl, messagesToLoad), {
4342
4350
  method: "GET",
4343
4351
  headers: {
4344
4352
  "thread-id": threadId,
@@ -4362,7 +4370,7 @@ function useChat({
4362
4370
  }
4363
4371
  };
4364
4372
  fetchInitialMessages();
4365
- }, [agentExecutionId, agentId, authFetch, baseUrl, customHeadersKey, threadId]);
4373
+ }, [agentExecutionId, agentId, authFetch, baseUrl, customHeadersKey, threadId, messagesToLoad]);
4366
4374
  useEffect(() => {
4367
4375
  if (!onMessage || messages.length === 0) return;
4368
4376
  const lastMessage = messages[messages.length - 1];
@@ -9725,6 +9733,7 @@ var ChatWidget = forwardRef(function ChatWidget2({
9725
9733
  agentVersion,
9726
9734
  agentExecutionId,
9727
9735
  dataContext,
9736
+ messagesToLoad,
9728
9737
  displayMode = "brief",
9729
9738
  onError,
9730
9739
  onAuthError,
@@ -9833,6 +9842,7 @@ var ChatWidget = forwardRef(function ChatWidget2({
9833
9842
  agentVersion,
9834
9843
  agentExecutionId: agentExecutionId ?? void 0,
9835
9844
  dataContext,
9845
+ messagesToLoad,
9836
9846
  onError,
9837
9847
  onAuthError,
9838
9848
  onFinish,
@@ -10958,6 +10968,7 @@ export {
10958
10968
  SDK_WIDGET_MARKER,
10959
10969
  TagGroupDisplay,
10960
10970
  ToolCallDisplay,
10971
+ buildMessagesUrl,
10961
10972
  cn,
10962
10973
  createSDKWidget,
10963
10974
  createWidget,