@ensembleapp/client-sdk 0.0.48 → 0.0.50

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,128 +1,12 @@
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
+ import { CollectUserInputArgs, MessageFeedback, FeedbackRating, FeedbackNote, EnrichmentResult, WidgetEnrichConfig } from '@repo/agent-sdk/schemas';
5
+ export { FeedbackNote, FeedbackRating, MessageFeedback, WidgetEnrichConfig } from '@repo/agent-sdk/schemas';
5
6
  import { FlexibleSchema, InferSchema } from '@ai-sdk/provider-utils';
6
7
  import * as react_jsx_runtime from 'react/jsx-runtime';
7
8
  import { ClassValue } from 'clsx';
8
9
 
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
-
126
10
  /** Derived part type from UIMessage */
127
11
  type UIMessagePart = UIMessage['parts'][number];
128
12
  /**
@@ -196,8 +80,17 @@ type UseChatConfig = DeprecatedChatConfig & {
196
80
  onFinish?: (message: any) => void;
197
81
  onData?: (data: any) => void;
198
82
  onMessage?: (message: UIMessage) => void;
83
+ /** Called when usage data is received (input/output token counts and percentages) */
84
+ onUsage?: (usage: {
85
+ inputTokens: number;
86
+ outputTokens: number;
87
+ maxInputTokens?: number;
88
+ maxOutputTokens?: number;
89
+ inputTokensPercent?: number;
90
+ outputTokensPercent?: number;
91
+ }) => void;
199
92
  };
200
- declare function useChat({ api, threadId, agentId, agentVersion, agentExecutionId, dataContext, onError, onAuthError, onFinish, onData, onMessage, }: UseChatConfig): {
93
+ declare function useChat({ api, threadId, agentId, agentVersion, agentExecutionId, dataContext, onError, onAuthError, onFinish, onData, onMessage, onUsage, }: UseChatConfig): {
201
94
  messages: ChatMessage[];
202
95
  status: ai.ChatStatus;
203
96
  isLoadingInitial: boolean;
@@ -224,19 +117,7 @@ declare function useChat({ api, threadId, agentId, agentVersion, agentExecutionI
224
117
  sendStructuredMessage: (text: string, payload: StructuredMessagePayload) => Promise<void>;
225
118
  stop: () => Promise<void>;
226
119
  setMessages: (messages: UIMessage<unknown, ai.UIDataTypes, ai.UITools>[] | ((messages: UIMessage<unknown, ai.UIDataTypes, ai.UITools>[]) => UIMessage<unknown, ai.UIDataTypes, ai.UITools>[])) => void;
227
- addToolOutput: <TOOL extends string>({ state, tool, toolCallId, output, errorText, }: {
228
- state?: "output-available";
229
- tool: TOOL;
230
- toolCallId: string;
231
- output: unknown;
232
- errorText?: never;
233
- } | {
234
- state: "output-error";
235
- tool: TOOL;
236
- toolCallId: string;
237
- output?: never;
238
- errorText: string;
239
- }) => Promise<void>;
120
+ addToolOutput: ai.ChatAddToolOutputFunction<UIMessage<unknown, ai.UIDataTypes, ai.UITools>>;
240
121
  addToolApprovalResponse: ai.ChatAddToolApproveResponseFunction;
241
122
  pendingToolOutput: PendingToolOutput | null;
242
123
  pendingToolApproval: PendingToolApproval | null;
@@ -756,4 +637,4 @@ declare const getVendorCardsWidget: (isProd?: boolean) => SDKUIWidgetDefinition[
756
637
 
757
638
  declare function cn(...inputs: ClassValue[]): string;
758
639
 
759
- 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 StructuredMessagePayload, 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 };
640
+ 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 FetchApprovalConfigOptions, FullDisplayMode, FullDisplayMode as FullRenderer, 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, fetchApprovalConfig, getVendorCardsWidget, isSDKWidget, registerChatWidgets, transformMessage, useChat, useFeedback };