@ensembleapp/client-sdk 0.0.39 → 0.0.41

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,11 +1,128 @@
1
1
  import React, { ReactElement, ReactNode } from 'react';
2
2
  import * as ai from 'ai';
3
3
  import { UIMessage } from 'ai';
4
+ import z, { z as z$1 } from 'zod';
4
5
  import { FlexibleSchema, InferSchema } from '@ai-sdk/provider-utils';
5
- import z from 'zod';
6
6
  import * as react_jsx_runtime from 'react/jsx-runtime';
7
7
  import { ClassValue } from 'clsx';
8
8
 
9
+ declare const VersionSelectorSchema: z.ZodUnion<readonly [z.ZodLiteral<"latest">, z.ZodLiteral<"published">, z.ZodNumber]>;
10
+ type VersionSelector = z.infer<typeof VersionSelectorSchema>;
11
+
12
+ declare const FeedbackRatingSchema: z.ZodEnum<{
13
+ positive: "positive";
14
+ negative: "negative";
15
+ }>;
16
+ type FeedbackRating = z.infer<typeof FeedbackRatingSchema>;
17
+ interface FeedbackNote {
18
+ noteId?: string;
19
+ [key: string]: unknown;
20
+ }
21
+ interface MessageFeedback {
22
+ rating?: FeedbackRating;
23
+ improvementText?: string;
24
+ notes?: FeedbackNote[];
25
+ }
26
+
27
+ /**
28
+ * Arguments for the collect_user_input tool.
29
+ */
30
+ declare const CollectUserInputArgsSchema: z$1.ZodObject<{
31
+ title: z$1.ZodOptional<z$1.ZodString>;
32
+ description: z$1.ZodOptional<z$1.ZodString>;
33
+ fields: z$1.ZodArray<z$1.ZodDiscriminatedUnion<[z$1.ZodObject<{
34
+ type: z$1.ZodLiteral<"choices">;
35
+ name: z$1.ZodString;
36
+ label: z$1.ZodString;
37
+ options: z$1.ZodArray<z$1.ZodObject<{
38
+ label: z$1.ZodString;
39
+ value: z$1.ZodString;
40
+ description: z$1.ZodOptional<z$1.ZodString>;
41
+ }, z$1.core.$strip>>;
42
+ multiSelect: z$1.ZodOptional<z$1.ZodBoolean>;
43
+ required: z$1.ZodOptional<z$1.ZodBoolean>;
44
+ defaultValue: z$1.ZodOptional<z$1.ZodUnion<readonly [z$1.ZodString, z$1.ZodArray<z$1.ZodString>]>>;
45
+ }, z$1.core.$strip>, z$1.ZodObject<{
46
+ type: z$1.ZodLiteral<"text">;
47
+ name: z$1.ZodString;
48
+ label: z$1.ZodString;
49
+ placeholder: z$1.ZodOptional<z$1.ZodString>;
50
+ multiline: z$1.ZodOptional<z$1.ZodBoolean>;
51
+ required: z$1.ZodOptional<z$1.ZodBoolean>;
52
+ defaultValue: z$1.ZodOptional<z$1.ZodString>;
53
+ }, z$1.core.$strip>, z$1.ZodObject<{
54
+ type: z$1.ZodLiteral<"number">;
55
+ name: z$1.ZodString;
56
+ label: z$1.ZodString;
57
+ min: z$1.ZodOptional<z$1.ZodNumber>;
58
+ max: z$1.ZodOptional<z$1.ZodNumber>;
59
+ required: z$1.ZodOptional<z$1.ZodBoolean>;
60
+ defaultValue: z$1.ZodOptional<z$1.ZodNumber>;
61
+ }, z$1.core.$strip>, z$1.ZodObject<{
62
+ type: z$1.ZodLiteral<"checkbox">;
63
+ name: z$1.ZodString;
64
+ label: z$1.ZodString;
65
+ defaultValue: z$1.ZodOptional<z$1.ZodBoolean>;
66
+ }, z$1.core.$strip>, z$1.ZodObject<{
67
+ type: z$1.ZodLiteral<"date">;
68
+ name: z$1.ZodString;
69
+ label: z$1.ZodString;
70
+ required: z$1.ZodOptional<z$1.ZodBoolean>;
71
+ defaultValue: z$1.ZodOptional<z$1.ZodString>;
72
+ }, z$1.core.$strip>], "type">>;
73
+ submitLabel: z$1.ZodOptional<z$1.ZodString>;
74
+ cancelLabel: z$1.ZodOptional<z$1.ZodString>;
75
+ allowFreeformResponse: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodBoolean>>;
76
+ }, z$1.core.$strip>;
77
+ type CollectUserInputArgs = z$1.infer<typeof CollectUserInputArgsSchema>;
78
+
79
+ /**
80
+ * fetch data via tool call.
81
+ */
82
+ type ToolCallConfig = {
83
+ toolId: string;
84
+ /**
85
+ * Select the tool version (default to 'latest' if not provided).
86
+ * - 'latest': pick draft if exists, fallback to latest published version
87
+ * - 'published': pick latest published version, fallback to draft version
88
+ * - number: specific tool version (1+)
89
+ */
90
+ version?: VersionSelector;
91
+ /**
92
+ * Tool input can be literal or templated string with expressions
93
+ */
94
+ inputs?: Record<string, unknown>;
95
+ };
96
+ /**
97
+ * Widget enrichment configuration.
98
+ * Keys are used to access the enrichment results in the render function.
99
+ *
100
+ * Example:
101
+ * ```typescript
102
+ * enrich: {
103
+ * vendorDetails: { toolId: 'vendor-tool', inputs: { ids: "${vendors}" } },
104
+ * pricing: { toolId: 'pricing-tool', inputs: { ids: "${vendors}" } },
105
+ * },
106
+ * render: (payload, enriched) => {
107
+ * const vendors = enriched?.vendorDetails?.data;
108
+ * const pricing = enriched?.pricing?.data;
109
+ * }
110
+ * ```
111
+ */
112
+ type WidgetEnrichConfig = Record<string, ToolCallConfig>;
113
+ /**
114
+ * Enrichment result containing the full tool response.
115
+ * This should mirror ToolResult on server-side without debug/metadata info.
116
+ */
117
+ type EnrichmentResult<TData = unknown> = {
118
+ success: boolean;
119
+ error?: {
120
+ message?: string;
121
+ code?: string;
122
+ };
123
+ data?: TData;
124
+ };
125
+
9
126
  /** Derived part type from UIMessage */
10
127
  type UIMessagePart = UIMessage['parts'][number];
11
128
  /**
@@ -35,6 +152,19 @@ interface ChatMessage {
35
152
  sections: ChatMessageSection[];
36
153
  }
37
154
 
155
+ /** Pending tool input detected from tool call (e.g., collect_user_input) */
156
+ interface PendingToolOutput {
157
+ toolCallId: string;
158
+ args: CollectUserInputArgs;
159
+ }
160
+ /** Pending tool approval detected from tool call */
161
+ interface PendingToolApproval {
162
+ toolCallId: string;
163
+ toolName: string;
164
+ args: Record<string, unknown>;
165
+ /** The approval ID required for addToolApprovalResponse */
166
+ approvalId: string;
167
+ }
38
168
  type DeprecatedChatConfig = {
39
169
  /** @deprecated use agentId instead */
40
170
  agentExecutionId?: string;
@@ -91,71 +221,22 @@ declare function useChat({ api, threadId, agentId, agentVersion, agentExecutionI
91
221
  } | undefined, options?: ai.ChatRequestOptions) => Promise<void>;
92
222
  stop: () => Promise<void>;
93
223
  setMessages: (messages: UIMessage<unknown, ai.UIDataTypes, ai.UITools>[] | ((messages: UIMessage<unknown, ai.UIDataTypes, ai.UITools>[]) => UIMessage<unknown, ai.UIDataTypes, ai.UITools>[])) => void;
94
- };
95
-
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
-
114
- /**
115
- * fetch data via tool call.
116
- */
117
- type ToolCallConfig = {
118
- toolId: string;
119
- /**
120
- * Select the tool version (default to 'latest' if not provided).
121
- * - 'latest': pick draft if exists, fallback to latest published version
122
- * - 'published': pick latest published version, fallback to draft version
123
- * - number: specific tool version (1+)
124
- */
125
- version?: VersionSelector;
126
- /**
127
- * Tool input can be literal or templated string with expressions
128
- */
129
- inputs?: Record<string, unknown>;
130
- };
131
- /**
132
- * Widget enrichment configuration.
133
- * Keys are used to access the enrichment results in the render function.
134
- *
135
- * Example:
136
- * ```typescript
137
- * enrich: {
138
- * vendorDetails: { toolId: 'vendor-tool', inputs: { ids: "${vendors}" } },
139
- * pricing: { toolId: 'pricing-tool', inputs: { ids: "${vendors}" } },
140
- * },
141
- * render: (payload, enriched) => {
142
- * const vendors = enriched?.vendorDetails?.data;
143
- * const pricing = enriched?.pricing?.data;
144
- * }
145
- * ```
146
- */
147
- type WidgetEnrichConfig = Record<string, ToolCallConfig>;
148
- /**
149
- * Enrichment result containing the full tool response.
150
- * This should mirror ToolResult on server-side without debug/metadata info.
151
- */
152
- type EnrichmentResult<TData = unknown> = {
153
- success: boolean;
154
- error?: {
155
- message?: string;
156
- code?: string;
157
- };
158
- data?: TData;
224
+ addToolOutput: <TOOL extends string>({ state, tool, toolCallId, output, errorText, }: {
225
+ state?: "output-available";
226
+ tool: TOOL;
227
+ toolCallId: string;
228
+ output: unknown;
229
+ errorText?: never;
230
+ } | {
231
+ state: "output-error";
232
+ tool: TOOL;
233
+ toolCallId: string;
234
+ output?: never;
235
+ errorText: string;
236
+ }) => Promise<void>;
237
+ addToolApprovalResponse: ai.ChatAddToolApproveResponseFunction;
238
+ pendingToolOutput: PendingToolOutput | null;
239
+ pendingToolApproval: PendingToolApproval | null;
159
240
  };
160
241
 
161
242
  /** Matches POST /api/tools/:toolId/invoke request body */
@@ -356,14 +437,32 @@ declare const createWidget: <TEnriched extends EnrichedResults = EnrichedResults
356
437
  type DisplayMode = 'full' | 'brief';
357
438
 
358
439
  interface ChatWidgetStyles {
440
+ /**
441
+ * Theme mode: 'light', 'dark', or 'auto' (detects from user's system/app preference).
442
+ * When 'auto', the widget checks: CSS color-scheme, prefers-color-scheme media query,
443
+ * and common dark mode indicators (data-theme, class="dark", etc.)
444
+ * Default: 'auto'
445
+ */
446
+ theme?: 'light' | 'dark' | 'auto';
359
447
  primaryColor?: string;
360
448
  primaryTextColor?: string;
361
449
  backgroundColor?: string;
450
+ backgroundSecondary?: string;
451
+ backgroundTertiary?: string;
362
452
  borderColor?: string;
453
+ borderColorLight?: string;
363
454
  headerTextColor?: string;
364
455
  userBubbleTextColor?: string;
365
456
  assistantBubbleBackground?: string;
366
457
  assistantBubbleTextColor?: string;
458
+ /** Main text color */
459
+ textColor?: string;
460
+ /** Secondary/muted text color */
461
+ textSecondary?: string;
462
+ /** Muted text color (lighter than secondary) */
463
+ textMuted?: string;
464
+ /** Disabled text color */
465
+ textDisabled?: string;
367
466
  fontFamily?: string;
368
467
  borderRadius?: string;
369
468
  inputBackground?: string;
@@ -468,6 +567,35 @@ declare function useFeedback({ api, threadId, agentId, agentVersion, }: UseFeedb
468
567
  error: Error | null;
469
568
  };
470
569
 
570
+ /** Approval UI configuration returned from the server */
571
+ interface ApprovalUIConfig {
572
+ /** The message to display (evaluated from template) */
573
+ message: string;
574
+ /** Label for the approve button */
575
+ approveLabel: string;
576
+ /** Label for the deny button */
577
+ denyLabel: string;
578
+ }
579
+ interface FetchApprovalConfigOptions {
580
+ /** API configuration */
581
+ api: ApiConfig;
582
+ /** Agent ID that contains the tool */
583
+ agentId: string;
584
+ /** Agent version */
585
+ agentVersion?: AgentVersion;
586
+ /** Tool name (will be normalized on server) */
587
+ toolName: string;
588
+ /** Tool arguments for template evaluation */
589
+ args?: Record<string, unknown>;
590
+ /** Called on 401 to refresh token */
591
+ onAuthError?: () => Promise<string | null>;
592
+ }
593
+ /**
594
+ * Fetches the approval UI configuration for a tool.
595
+ * The server evaluates template expressions in message/labels with the provided args.
596
+ */
597
+ declare function fetchApprovalConfig(options: FetchApprovalConfigOptions): Promise<ApprovalUIConfig | null>;
598
+
471
599
  /**
472
600
  * Transforms a UIMessage into a ChatMessage with sections.
473
601
  *
@@ -605,4 +733,4 @@ declare const getVendorCardsWidget: (isProd?: boolean) => SDKUIWidgetDefinition[
605
733
 
606
734
  declare function cn(...inputs: ClassValue[]): string;
607
735
 
608
- 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 InvokeTool, 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 ToolInvokeRequest, type ToolInvokeResult, type ToolPart, type UIMessagePart, type UIWidgetDefinition, type UseChatConfig, type UseFeedbackConfig, type WidgetEnrichConfig, type WidgetRenderOptions, cn, createSDKWidget, createWidget, defaultChatWidgets, getVendorCardsWidget, isSDKWidget, registerChatWidgets, transformMessage, useChat, useFeedback };
736
+ export { type AgentVersion, type AnyUIWidgetDefinition, type ApiConfig, type ApprovalUIConfig, 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, type FetchApprovalConfigOptions, FullDisplayMode, FullDisplayMode as FullRenderer, type InvokeTool, type MessageContext, type MessageFeedback, MessageRenderer, type MessageRendererProps, type PendingToolApproval, type PendingToolOutput, type PopupAnchorConfig, PopupChatWidget, type PopupChatWidgetProps, type DisplayModeProps as RendererProps, type SDKUIWidgetDefinition, SDK_WIDGET_MARKER, type SubmitFeedbackParams, TagGroupDisplay, type TagGroupDisplayProps, ToolCallDisplay, type ToolCallDisplayProps, type ToolInvokeRequest, type ToolInvokeResult, type ToolPart, type UIMessagePart, type UIWidgetDefinition, type UseChatConfig, type UseFeedbackConfig, type WidgetEnrichConfig, type WidgetRenderOptions, cn, createSDKWidget, createWidget, defaultChatWidgets, fetchApprovalConfig, getVendorCardsWidget, isSDKWidget, registerChatWidgets, transformMessage, useChat, useFeedback };