@ensembleapp/client-sdk 0.0.5 → 0.0.6
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 +103 -19
- package/dist/index.js +21280 -6192
- package/dist/index.js.map +1 -1
- package/lib/components/ChatWidget.css +3 -3
- package/package.json +13 -6
- package/dist/schemas-n2u83F_H.d.ts +0 -19
- package/dist/schemas.d.ts +0 -4
- package/dist/schemas.js +0 -1
- package/dist/schemas.js.map +0 -1
- package/dist/widget/widget.global.d.ts +0 -22
- package/dist/widget/widget.global.js +0 -177
- package/dist/widget/widget.global.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import * as ai from 'ai';
|
|
2
2
|
import { UIMessage } from 'ai';
|
|
3
|
-
import {
|
|
4
|
-
export { W as WidgetDefinition, c as createWidget } from './schemas-n2u83F_H.js';
|
|
3
|
+
import { UIWidget } from '@repo/agent-sdk/schemas';
|
|
5
4
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
6
|
-
import React from 'react';
|
|
5
|
+
import React$1, { ReactNode } from 'react';
|
|
6
|
+
import z, { AnyZodObject } from 'zod';
|
|
7
7
|
import { ClassValue } from 'clsx';
|
|
8
|
-
import 'json-schema';
|
|
9
|
-
import 'zod';
|
|
10
8
|
|
|
9
|
+
type DeprecatedChatConfig = {
|
|
10
|
+
/** @deprecated use agentId instead */
|
|
11
|
+
agentExecutionId?: string;
|
|
12
|
+
};
|
|
11
13
|
interface ApiConfig {
|
|
12
14
|
/** The base URL where /chat and /chat/messages are hosted */
|
|
13
15
|
baseUrl: string;
|
|
@@ -15,15 +17,13 @@ interface ApiConfig {
|
|
|
15
17
|
token: string;
|
|
16
18
|
headers?: Record<string, string>;
|
|
17
19
|
}
|
|
18
|
-
|
|
20
|
+
type UseChatConfig = DeprecatedChatConfig & {
|
|
19
21
|
/** The server API configuration */
|
|
20
22
|
api: ApiConfig;
|
|
21
23
|
/** Thread ID for keeping conversation history */
|
|
22
24
|
threadId: string;
|
|
23
|
-
/**
|
|
25
|
+
/** Ensemble agent ID to connect to */
|
|
24
26
|
agentId?: string;
|
|
25
|
-
/** The Agent Orchestration ID that this chat connects to. Either agentId or agentExecutionId must be provided */
|
|
26
|
-
agentExecutionId?: string;
|
|
27
27
|
/** additional context (anything) that needs to be passed to the LLM */
|
|
28
28
|
dataContext?: unknown;
|
|
29
29
|
onError?: (error: Error) => void;
|
|
@@ -32,11 +32,35 @@ interface UseChatConfig {
|
|
|
32
32
|
onFinish?: (message: any) => void;
|
|
33
33
|
onData?: (data: any) => void;
|
|
34
34
|
onMessage?: (message: UIMessage) => void;
|
|
35
|
+
};
|
|
36
|
+
interface ToolCallContent {
|
|
37
|
+
type: 'tool-call';
|
|
38
|
+
toolName: string;
|
|
39
|
+
input?: Record<string, unknown>;
|
|
40
|
+
state: 'pending' | 'output-available' | 'error';
|
|
41
|
+
output?: unknown;
|
|
42
|
+
}
|
|
43
|
+
type ChatContentItem = string | UIWidget | ToolCallContent;
|
|
44
|
+
/** A grouped section of sub-agent output, wrapped by data-tag-start/end markers */
|
|
45
|
+
interface TagGroup {
|
|
46
|
+
tagId: string;
|
|
47
|
+
content: ChatContentItem[];
|
|
48
|
+
/** Index into content[] where the last step begins (for promoting only final output) */
|
|
49
|
+
lastStepStartIndex?: number;
|
|
35
50
|
}
|
|
51
|
+
/** A single section in the message, rendered in chronological order */
|
|
52
|
+
type MessageSection = {
|
|
53
|
+
type: 'content';
|
|
54
|
+
item: ChatContentItem;
|
|
55
|
+
} | {
|
|
56
|
+
type: 'tag-group';
|
|
57
|
+
group: TagGroup;
|
|
58
|
+
};
|
|
36
59
|
interface ChatMessage {
|
|
37
60
|
id: string;
|
|
38
61
|
role: 'user' | 'assistant';
|
|
39
|
-
|
|
62
|
+
/** Ordered sections: content items and tag groups interleaved chronologically */
|
|
63
|
+
sections: MessageSection[];
|
|
40
64
|
thoughts?: (string | UIWidget)[];
|
|
41
65
|
createdAt?: Date;
|
|
42
66
|
}
|
|
@@ -67,6 +91,44 @@ declare function useChat({ api, threadId, agentId, agentExecutionId, dataContext
|
|
|
67
91
|
setMessages: (messages: UIMessage<unknown, ai.UIDataTypes, ai.UITools>[] | ((messages: UIMessage<unknown, ai.UIDataTypes, ai.UITools>[]) => UIMessage<unknown, ai.UIDataTypes, ai.UITools>[])) => void;
|
|
68
92
|
};
|
|
69
93
|
|
|
94
|
+
type FeedbackRating = 'positive' | 'negative';
|
|
95
|
+
interface MessageFeedback {
|
|
96
|
+
id: string;
|
|
97
|
+
messageId: string;
|
|
98
|
+
rating: FeedbackRating;
|
|
99
|
+
improvementText?: string;
|
|
100
|
+
createdAt: Date;
|
|
101
|
+
}
|
|
102
|
+
interface FeedbackState {
|
|
103
|
+
rating: FeedbackRating;
|
|
104
|
+
comment?: string;
|
|
105
|
+
}
|
|
106
|
+
interface UseFeedbackConfig {
|
|
107
|
+
api: ApiConfig;
|
|
108
|
+
threadId: string;
|
|
109
|
+
agentId?: string;
|
|
110
|
+
agentExecutionId?: string;
|
|
111
|
+
}
|
|
112
|
+
interface SubmitFeedbackParams {
|
|
113
|
+
messageId: string;
|
|
114
|
+
rating: FeedbackRating;
|
|
115
|
+
improvementText?: string;
|
|
116
|
+
}
|
|
117
|
+
declare function useFeedback({ api, threadId, agentId, agentExecutionId, }: UseFeedbackConfig): {
|
|
118
|
+
submitFeedback: ({ messageId, rating, improvementText }: SubmitFeedbackParams) => Promise<MessageFeedback | null>;
|
|
119
|
+
getFeedbackForMessage: (messageId: string) => FeedbackState | undefined;
|
|
120
|
+
hasFeedback: (messageId: string) => boolean;
|
|
121
|
+
isSubmitting: string | null;
|
|
122
|
+
error: Error | null;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
interface UIWidgetDefinition<TSchema extends AnyZodObject = AnyZodObject> {
|
|
126
|
+
widgetType: string;
|
|
127
|
+
schema: TSchema;
|
|
128
|
+
render(widget: z.infer<TSchema>): ReactNode;
|
|
129
|
+
}
|
|
130
|
+
declare const createWidget: <TSchema extends AnyZodObject>({ widgetType, schema, render, }: UIWidgetDefinition<TSchema>) => UIWidgetDefinition<TSchema>;
|
|
131
|
+
|
|
70
132
|
interface ChatWidgetStyles {
|
|
71
133
|
primaryColor?: string;
|
|
72
134
|
primaryTextColor?: string;
|
|
@@ -98,6 +160,12 @@ interface ChatWidgetSpeechToTextOptions {
|
|
|
98
160
|
onError?: (message: string) => void;
|
|
99
161
|
finalDelay?: number;
|
|
100
162
|
}
|
|
163
|
+
interface ChatWidgetFeedbackOptions {
|
|
164
|
+
/** Enable feedback buttons on assistant messages. Default: true */
|
|
165
|
+
enabled?: boolean;
|
|
166
|
+
/** Require comment when giving negative feedback. Default: false */
|
|
167
|
+
requireCommentForNegative?: boolean;
|
|
168
|
+
}
|
|
101
169
|
interface ChatWidgetConfig extends UseChatConfig {
|
|
102
170
|
/** Title for the Chat window */
|
|
103
171
|
title?: string;
|
|
@@ -110,8 +178,10 @@ interface ChatWidgetConfig extends UseChatConfig {
|
|
|
110
178
|
voice?: ChatWidgetVoiceOptions;
|
|
111
179
|
speechToText?: ChatWidgetSpeechToTextOptions;
|
|
112
180
|
widgets?: UIWidgetDefinition[];
|
|
181
|
+
/** Feedback options for assistant messages. Enabled by default. */
|
|
182
|
+
feedback?: ChatWidgetFeedbackOptions;
|
|
113
183
|
}
|
|
114
|
-
declare function ChatWidget({ api, threadId, agentId, agentExecutionId, dataContext, onError, onAuthError, onFinish, onMessage, title, introMessage, inputPlaceholder, className, styles: styleProps, voice, speechToText, widgets, }: ChatWidgetConfig): react_jsx_runtime.JSX.Element;
|
|
184
|
+
declare function ChatWidget({ api, threadId, agentId, agentExecutionId, dataContext, onError, onAuthError, onFinish, onMessage, title, introMessage, inputPlaceholder, className, styles: styleProps, voice, speechToText, widgets, feedback, }: ChatWidgetConfig): react_jsx_runtime.JSX.Element;
|
|
115
185
|
|
|
116
186
|
interface PopupAnchorConfig {
|
|
117
187
|
enabled?: boolean;
|
|
@@ -121,13 +191,13 @@ interface PopupAnchorConfig {
|
|
|
121
191
|
render?: (options: {
|
|
122
192
|
isOpen: boolean;
|
|
123
193
|
toggle: () => void;
|
|
124
|
-
}) => React.ReactNode;
|
|
194
|
+
}) => React$1.ReactNode;
|
|
125
195
|
closeButton?: PopupCloseConfig;
|
|
126
196
|
}
|
|
127
197
|
interface PopupCloseConfig {
|
|
128
198
|
render?: (options: {
|
|
129
199
|
toggle: () => void;
|
|
130
|
-
}) => React.ReactNode;
|
|
200
|
+
}) => React$1.ReactNode;
|
|
131
201
|
position?: 'top-end' | 'top-start';
|
|
132
202
|
show?: boolean;
|
|
133
203
|
}
|
|
@@ -147,12 +217,19 @@ interface PopupChatWidgetProps extends ChatWidgetConfig {
|
|
|
147
217
|
}
|
|
148
218
|
declare function PopupChatWidget({ anchor, ...props }: PopupChatWidgetProps): react_jsx_runtime.JSX.Element;
|
|
149
219
|
|
|
150
|
-
interface
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
unmount: () => void;
|
|
220
|
+
interface ToolCallDisplayProps {
|
|
221
|
+
toolCall: ToolCallContent;
|
|
222
|
+
className?: string;
|
|
154
223
|
}
|
|
155
|
-
declare
|
|
224
|
+
declare function ToolCallDisplay({ toolCall, className }: ToolCallDisplayProps): react_jsx_runtime.JSX.Element;
|
|
225
|
+
|
|
226
|
+
interface TagGroupDisplayProps {
|
|
227
|
+
tagId: string;
|
|
228
|
+
isExpanded: boolean;
|
|
229
|
+
onToggle: () => void;
|
|
230
|
+
children: React.ReactNode;
|
|
231
|
+
}
|
|
232
|
+
declare function TagGroupDisplay({ tagId, isExpanded, onToggle, children, }: TagGroupDisplayProps): react_jsx_runtime.JSX.Element;
|
|
156
233
|
|
|
157
234
|
type RegisterChatWidgetsParams = {
|
|
158
235
|
api: ApiConfig;
|
|
@@ -164,6 +241,13 @@ type RegisterChatWidgetsParams = {
|
|
|
164
241
|
*/
|
|
165
242
|
declare function registerChatWidgets({ api, threadId, widgets, }: RegisterChatWidgetsParams): Promise<void>;
|
|
166
243
|
|
|
244
|
+
interface ChatWidgetInstance {
|
|
245
|
+
updateProps: (props: Partial<ChatWidgetConfig>) => void;
|
|
246
|
+
updateTheme: (styles: ChatWidgetStyles) => void;
|
|
247
|
+
unmount: () => void;
|
|
248
|
+
}
|
|
249
|
+
declare const createChatWidget: (target: HTMLElement, props: ChatWidgetConfig) => ChatWidgetInstance;
|
|
250
|
+
|
|
167
251
|
/**
|
|
168
252
|
* Embeddable Chat Widget
|
|
169
253
|
*
|
|
@@ -190,4 +274,4 @@ declare const defaultChatWidgets: UIWidgetDefinition[];
|
|
|
190
274
|
|
|
191
275
|
declare function cn(...inputs: ClassValue[]): string;
|
|
192
276
|
|
|
193
|
-
export { type ApiConfig, type ChatMessage, ChatWidget, type ChatWidgetInstance, type ChatWidgetConfig as ChatWidgetProps, type ChatWidgetSpeechToTextOptions, type ChatWidgetStyles, type ChatWidgetVoiceOptions, type EmbeddableChatWidgetConfig, type PopupAnchorConfig, PopupChatWidget, type PopupChatWidgetProps,
|
|
277
|
+
export { type ApiConfig, type ChatContentItem, type ChatMessage, ChatWidget, type ChatWidgetFeedbackOptions, type ChatWidgetInstance, type ChatWidgetConfig as ChatWidgetProps, type ChatWidgetSpeechToTextOptions, type ChatWidgetStyles, type ChatWidgetVoiceOptions, type EmbeddableChatWidgetConfig, 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, cn, createChatWidget, createWidget, defaultChatWidgets, registerChatWidgets, useChat, useFeedback };
|