@ozwell/react 1.0.0
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/README.md +207 -0
- package/dist/index.cjs +394 -0
- package/dist/index.d.cts +282 -0
- package/dist/index.d.ts +282 -0
- package/dist/index.js +366 -0
- package/package.json +68 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* TypeScript type definitions for @ozwell/react
|
|
5
|
+
*
|
|
6
|
+
* This file defines types for both:
|
|
7
|
+
* 1. Currently implemented features (from vanilla widget)
|
|
8
|
+
* 2. Planned future features (documented but not yet implemented)
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* MCP tool function parameter definition
|
|
12
|
+
*/
|
|
13
|
+
interface OzwellToolParameter {
|
|
14
|
+
type: string;
|
|
15
|
+
description?: string;
|
|
16
|
+
enum?: string[];
|
|
17
|
+
items?: OzwellToolParameter;
|
|
18
|
+
properties?: Record<string, OzwellToolParameter>;
|
|
19
|
+
required?: string[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* MCP tool function definition
|
|
23
|
+
*/
|
|
24
|
+
interface OzwellToolFunction {
|
|
25
|
+
name: string;
|
|
26
|
+
description: string;
|
|
27
|
+
parameters: OzwellToolParameter;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* MCP tool definition (OpenAI-compatible)
|
|
31
|
+
*/
|
|
32
|
+
interface OzwellTool {
|
|
33
|
+
type: 'function';
|
|
34
|
+
function: OzwellToolFunction;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Ozwell chat widget configuration
|
|
38
|
+
* Maps to window.OzwellChatConfig in vanilla implementation
|
|
39
|
+
*/
|
|
40
|
+
interface OzwellConfig {
|
|
41
|
+
/** API endpoint URL */
|
|
42
|
+
endpoint?: string;
|
|
43
|
+
/** Model name (e.g., 'llama3', 'gpt-4') */
|
|
44
|
+
model?: string;
|
|
45
|
+
/** System prompt for the assistant */
|
|
46
|
+
system?: string;
|
|
47
|
+
/** Welcome message shown when chat opens */
|
|
48
|
+
welcomeMessage?: string;
|
|
49
|
+
/** Input placeholder text */
|
|
50
|
+
placeholder?: string;
|
|
51
|
+
/** Chat widget title */
|
|
52
|
+
title?: string;
|
|
53
|
+
/** MCP tools available to the assistant */
|
|
54
|
+
tools?: OzwellTool[];
|
|
55
|
+
/** Enable debug mode (shows tool execution details) */
|
|
56
|
+
debug?: boolean;
|
|
57
|
+
/** OpenAI API key (for direct OpenAI endpoint usage) */
|
|
58
|
+
openaiApiKey?: string;
|
|
59
|
+
/** Custom HTTP headers */
|
|
60
|
+
headers?: Record<string, string>;
|
|
61
|
+
/** Widget frame URL (defaults to https://ozwellapi.os.mieweb.org/widget/frame/) */
|
|
62
|
+
widgetUrl?: string;
|
|
63
|
+
/** Auto-mount widget on load (default: true) */
|
|
64
|
+
autoMount?: boolean;
|
|
65
|
+
/** Enable default floating button UI (default: true) */
|
|
66
|
+
defaultUI?: boolean;
|
|
67
|
+
/** Container element ID for custom mounting */
|
|
68
|
+
containerId?: string;
|
|
69
|
+
/** Auto-open chat window when AI replies (default: false) */
|
|
70
|
+
autoOpenOnReply?: boolean;
|
|
71
|
+
/** Agent key (agnt_key-...) for authentication and server-side agent configuration */
|
|
72
|
+
apiKey?: string;
|
|
73
|
+
/** Agent ID for agent-specific configuration */
|
|
74
|
+
agentId?: string;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Props for the OzwellChat component
|
|
78
|
+
*/
|
|
79
|
+
interface OzwellChatProps extends Omit<OzwellConfig, 'autoMount'> {
|
|
80
|
+
/** Widget width (CSS value or number in pixels) */
|
|
81
|
+
width?: number | string;
|
|
82
|
+
/** Widget height (CSS value or number in pixels) */
|
|
83
|
+
height?: number | string;
|
|
84
|
+
/** Called when widget is ready */
|
|
85
|
+
onReady?: () => void;
|
|
86
|
+
/** Called when chat is opened */
|
|
87
|
+
onOpen?: () => void;
|
|
88
|
+
/** Called when chat is closed */
|
|
89
|
+
onClose?: () => void;
|
|
90
|
+
/**
|
|
91
|
+
* Called when the AI requests a tool call.
|
|
92
|
+
* The callback receives the tool name, arguments, and a sendResult function.
|
|
93
|
+
* Call sendResult(result) to send the tool result back to the widget.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```tsx
|
|
97
|
+
* onToolCall={(tool, args, sendResult) => {
|
|
98
|
+
* const result = toolHandlers[tool](args);
|
|
99
|
+
* sendResult(result);
|
|
100
|
+
* }}
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
onToolCall?: (tool: string, args: Record<string, unknown>, sendResult: (result: unknown) => void) => void;
|
|
104
|
+
/** Called when user explicitly shares data (privacy-preserving) */
|
|
105
|
+
onUserShare?: (data: unknown) => void;
|
|
106
|
+
/** Called on errors */
|
|
107
|
+
onError?: (error: OzwellError) => void;
|
|
108
|
+
/** Theme mode */
|
|
109
|
+
theme?: 'light' | 'dark' | 'auto';
|
|
110
|
+
/** Widget position */
|
|
111
|
+
position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
|
|
112
|
+
/** Primary accent color */
|
|
113
|
+
primaryColor?: string;
|
|
114
|
+
/** Auto-open chat on mount */
|
|
115
|
+
autoOpen?: boolean;
|
|
116
|
+
/** React children (for context provider pattern) */
|
|
117
|
+
children?: React.ReactNode;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Return type for useOzwell hook
|
|
121
|
+
*/
|
|
122
|
+
interface UseOzwellReturn {
|
|
123
|
+
/** Whether the widget is ready */
|
|
124
|
+
isReady: boolean;
|
|
125
|
+
/** Whether the chat is currently open */
|
|
126
|
+
isOpen: boolean;
|
|
127
|
+
/** Whether there are unread messages */
|
|
128
|
+
hasUnread: boolean;
|
|
129
|
+
/** Open the chat */
|
|
130
|
+
open: () => void;
|
|
131
|
+
/** Close the chat */
|
|
132
|
+
close: () => void;
|
|
133
|
+
/** Toggle chat open/closed */
|
|
134
|
+
toggle: () => void;
|
|
135
|
+
/** Send a message programmatically */
|
|
136
|
+
sendMessage: (content: string) => void;
|
|
137
|
+
/** Access the underlying iframe element */
|
|
138
|
+
iframe: HTMLIFrameElement | null;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Error object for onError callback
|
|
142
|
+
*/
|
|
143
|
+
interface OzwellError {
|
|
144
|
+
code: string;
|
|
145
|
+
message: string;
|
|
146
|
+
details?: unknown;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Vanilla widget API exposed on window object
|
|
150
|
+
*/
|
|
151
|
+
interface OzwellChatAPI {
|
|
152
|
+
mount: (options?: {
|
|
153
|
+
containerId?: string;
|
|
154
|
+
src?: string;
|
|
155
|
+
width?: number;
|
|
156
|
+
height?: number;
|
|
157
|
+
}) => HTMLIFrameElement;
|
|
158
|
+
configure: (config: Partial<OzwellConfig>) => void;
|
|
159
|
+
ready: () => Promise<void>;
|
|
160
|
+
/** Programmatically open the chat window */
|
|
161
|
+
open: () => void;
|
|
162
|
+
/** Programmatically close the chat window */
|
|
163
|
+
close: () => void;
|
|
164
|
+
/** Current iframe element */
|
|
165
|
+
iframe: HTMLIFrameElement | null;
|
|
166
|
+
/** Whether the chat window is currently open */
|
|
167
|
+
isOpen: boolean;
|
|
168
|
+
/** Whether there are unread messages */
|
|
169
|
+
hasUnread: boolean;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Extend Window interface for TypeScript
|
|
173
|
+
*/
|
|
174
|
+
declare global {
|
|
175
|
+
interface Window {
|
|
176
|
+
OzwellChat?: OzwellChatAPI;
|
|
177
|
+
OzwellChatConfig?: Partial<OzwellConfig>;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Script load status
|
|
182
|
+
*/
|
|
183
|
+
type ScriptLoadStatus = 'idle' | 'loading' | 'ready' | 'error';
|
|
184
|
+
/**
|
|
185
|
+
* PostMessage event data from widget
|
|
186
|
+
*/
|
|
187
|
+
interface OzwellWidgetMessage {
|
|
188
|
+
source: 'ozwell-chat-widget';
|
|
189
|
+
type: 'ready' | 'request-config' | 'closed' | 'opened' | 'tool_call' | 'assistant_response' | 'user-share' | 'error';
|
|
190
|
+
payload?: unknown;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Assistant response notification from widget (signal only, no message content)
|
|
194
|
+
*/
|
|
195
|
+
interface OzwellAssistantResponseMessage {
|
|
196
|
+
source: 'ozwell-chat-widget';
|
|
197
|
+
type: 'assistant_response';
|
|
198
|
+
/** Whether the response included tool calls */
|
|
199
|
+
hadToolCalls: boolean;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Tool call message from widget to parent
|
|
203
|
+
* Properties are at the root level (not nested in payload)
|
|
204
|
+
*/
|
|
205
|
+
interface OzwellToolCallMessage {
|
|
206
|
+
source: 'ozwell-chat-widget';
|
|
207
|
+
type: 'tool_call';
|
|
208
|
+
/** Tool function name */
|
|
209
|
+
tool: string;
|
|
210
|
+
/** Unique ID for this tool call */
|
|
211
|
+
tool_call_id: string;
|
|
212
|
+
/** Tool arguments (parsed from function.arguments) */
|
|
213
|
+
payload: Record<string, unknown>;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* PostMessage event data to widget
|
|
217
|
+
*/
|
|
218
|
+
interface OzwellParentMessage {
|
|
219
|
+
source: 'ozwell-chat-parent';
|
|
220
|
+
type: 'config' | 'tool_result';
|
|
221
|
+
payload?: unknown;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Tool result message from parent to widget
|
|
225
|
+
* Properties are at the root level (not nested in payload)
|
|
226
|
+
*/
|
|
227
|
+
interface OzwellToolResultMessage {
|
|
228
|
+
source: 'ozwell-chat-parent';
|
|
229
|
+
type: 'tool_result';
|
|
230
|
+
/** Must match the tool_call_id from the tool_call message */
|
|
231
|
+
tool_call_id: string;
|
|
232
|
+
/** Result data to send back to the LLM */
|
|
233
|
+
result: unknown;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* OzwellChat - React component wrapper for Ozwell chat widget
|
|
238
|
+
*
|
|
239
|
+
* This component loads the vanilla Ozwell widget and provides a React-friendly API.
|
|
240
|
+
* It wraps the existing ozwell-loader.js implementation rather than reimplementing it.
|
|
241
|
+
*
|
|
242
|
+
* IMPORTANT: Only render one OzwellChat component per page. Multiple instances
|
|
243
|
+
* will share global configuration (window.OzwellChatConfig) and may cause
|
|
244
|
+
* unexpected behavior. Use conditional rendering for different configurations.
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* ```tsx
|
|
248
|
+
* <OzwellChat
|
|
249
|
+
* endpoint="/v1/chat/completions"
|
|
250
|
+
* tools={[...]}
|
|
251
|
+
* onReady={() => console.log('Ready!')}
|
|
252
|
+
* />
|
|
253
|
+
* ```
|
|
254
|
+
*/
|
|
255
|
+
declare function OzwellChat(props: OzwellChatProps): react_jsx_runtime.JSX.Element;
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* useOzwell - React hook for programmatic control of Ozwell widget
|
|
259
|
+
*
|
|
260
|
+
* Provides methods to control the widget and access its state.
|
|
261
|
+
* Must be used within a component tree that has OzwellChat mounted.
|
|
262
|
+
*
|
|
263
|
+
* @example
|
|
264
|
+
* ```tsx
|
|
265
|
+
* function ChatControls() {
|
|
266
|
+
* const ozwell = useOzwell();
|
|
267
|
+
*
|
|
268
|
+
* return (
|
|
269
|
+
* <div>
|
|
270
|
+
* <button onClick={() => ozwell.open()}>Open Chat</button>
|
|
271
|
+
* <button onClick={() => ozwell.sendMessage('Hello!')}>Send Hello</button>
|
|
272
|
+
* {ozwell.isReady ? 'Ready' : 'Loading...'}
|
|
273
|
+
* </div>
|
|
274
|
+
* );
|
|
275
|
+
* }
|
|
276
|
+
* ```
|
|
277
|
+
*
|
|
278
|
+
* @returns {UseOzwellReturn} Widget control methods and state
|
|
279
|
+
*/
|
|
280
|
+
declare function useOzwell(): UseOzwellReturn;
|
|
281
|
+
|
|
282
|
+
export { type OzwellAssistantResponseMessage, OzwellChat, type OzwellChatAPI, type OzwellChatProps, type OzwellConfig, type OzwellError, type OzwellParentMessage, type OzwellTool, type OzwellToolCallMessage, type OzwellToolFunction, type OzwellToolParameter, type OzwellToolResultMessage, type OzwellWidgetMessage, type ScriptLoadStatus, type UseOzwellReturn, OzwellChat as default, useOzwell };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* TypeScript type definitions for @ozwell/react
|
|
5
|
+
*
|
|
6
|
+
* This file defines types for both:
|
|
7
|
+
* 1. Currently implemented features (from vanilla widget)
|
|
8
|
+
* 2. Planned future features (documented but not yet implemented)
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* MCP tool function parameter definition
|
|
12
|
+
*/
|
|
13
|
+
interface OzwellToolParameter {
|
|
14
|
+
type: string;
|
|
15
|
+
description?: string;
|
|
16
|
+
enum?: string[];
|
|
17
|
+
items?: OzwellToolParameter;
|
|
18
|
+
properties?: Record<string, OzwellToolParameter>;
|
|
19
|
+
required?: string[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* MCP tool function definition
|
|
23
|
+
*/
|
|
24
|
+
interface OzwellToolFunction {
|
|
25
|
+
name: string;
|
|
26
|
+
description: string;
|
|
27
|
+
parameters: OzwellToolParameter;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* MCP tool definition (OpenAI-compatible)
|
|
31
|
+
*/
|
|
32
|
+
interface OzwellTool {
|
|
33
|
+
type: 'function';
|
|
34
|
+
function: OzwellToolFunction;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Ozwell chat widget configuration
|
|
38
|
+
* Maps to window.OzwellChatConfig in vanilla implementation
|
|
39
|
+
*/
|
|
40
|
+
interface OzwellConfig {
|
|
41
|
+
/** API endpoint URL */
|
|
42
|
+
endpoint?: string;
|
|
43
|
+
/** Model name (e.g., 'llama3', 'gpt-4') */
|
|
44
|
+
model?: string;
|
|
45
|
+
/** System prompt for the assistant */
|
|
46
|
+
system?: string;
|
|
47
|
+
/** Welcome message shown when chat opens */
|
|
48
|
+
welcomeMessage?: string;
|
|
49
|
+
/** Input placeholder text */
|
|
50
|
+
placeholder?: string;
|
|
51
|
+
/** Chat widget title */
|
|
52
|
+
title?: string;
|
|
53
|
+
/** MCP tools available to the assistant */
|
|
54
|
+
tools?: OzwellTool[];
|
|
55
|
+
/** Enable debug mode (shows tool execution details) */
|
|
56
|
+
debug?: boolean;
|
|
57
|
+
/** OpenAI API key (for direct OpenAI endpoint usage) */
|
|
58
|
+
openaiApiKey?: string;
|
|
59
|
+
/** Custom HTTP headers */
|
|
60
|
+
headers?: Record<string, string>;
|
|
61
|
+
/** Widget frame URL (defaults to https://ozwellapi.os.mieweb.org/widget/frame/) */
|
|
62
|
+
widgetUrl?: string;
|
|
63
|
+
/** Auto-mount widget on load (default: true) */
|
|
64
|
+
autoMount?: boolean;
|
|
65
|
+
/** Enable default floating button UI (default: true) */
|
|
66
|
+
defaultUI?: boolean;
|
|
67
|
+
/** Container element ID for custom mounting */
|
|
68
|
+
containerId?: string;
|
|
69
|
+
/** Auto-open chat window when AI replies (default: false) */
|
|
70
|
+
autoOpenOnReply?: boolean;
|
|
71
|
+
/** Agent key (agnt_key-...) for authentication and server-side agent configuration */
|
|
72
|
+
apiKey?: string;
|
|
73
|
+
/** Agent ID for agent-specific configuration */
|
|
74
|
+
agentId?: string;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Props for the OzwellChat component
|
|
78
|
+
*/
|
|
79
|
+
interface OzwellChatProps extends Omit<OzwellConfig, 'autoMount'> {
|
|
80
|
+
/** Widget width (CSS value or number in pixels) */
|
|
81
|
+
width?: number | string;
|
|
82
|
+
/** Widget height (CSS value or number in pixels) */
|
|
83
|
+
height?: number | string;
|
|
84
|
+
/** Called when widget is ready */
|
|
85
|
+
onReady?: () => void;
|
|
86
|
+
/** Called when chat is opened */
|
|
87
|
+
onOpen?: () => void;
|
|
88
|
+
/** Called when chat is closed */
|
|
89
|
+
onClose?: () => void;
|
|
90
|
+
/**
|
|
91
|
+
* Called when the AI requests a tool call.
|
|
92
|
+
* The callback receives the tool name, arguments, and a sendResult function.
|
|
93
|
+
* Call sendResult(result) to send the tool result back to the widget.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```tsx
|
|
97
|
+
* onToolCall={(tool, args, sendResult) => {
|
|
98
|
+
* const result = toolHandlers[tool](args);
|
|
99
|
+
* sendResult(result);
|
|
100
|
+
* }}
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
onToolCall?: (tool: string, args: Record<string, unknown>, sendResult: (result: unknown) => void) => void;
|
|
104
|
+
/** Called when user explicitly shares data (privacy-preserving) */
|
|
105
|
+
onUserShare?: (data: unknown) => void;
|
|
106
|
+
/** Called on errors */
|
|
107
|
+
onError?: (error: OzwellError) => void;
|
|
108
|
+
/** Theme mode */
|
|
109
|
+
theme?: 'light' | 'dark' | 'auto';
|
|
110
|
+
/** Widget position */
|
|
111
|
+
position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
|
|
112
|
+
/** Primary accent color */
|
|
113
|
+
primaryColor?: string;
|
|
114
|
+
/** Auto-open chat on mount */
|
|
115
|
+
autoOpen?: boolean;
|
|
116
|
+
/** React children (for context provider pattern) */
|
|
117
|
+
children?: React.ReactNode;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Return type for useOzwell hook
|
|
121
|
+
*/
|
|
122
|
+
interface UseOzwellReturn {
|
|
123
|
+
/** Whether the widget is ready */
|
|
124
|
+
isReady: boolean;
|
|
125
|
+
/** Whether the chat is currently open */
|
|
126
|
+
isOpen: boolean;
|
|
127
|
+
/** Whether there are unread messages */
|
|
128
|
+
hasUnread: boolean;
|
|
129
|
+
/** Open the chat */
|
|
130
|
+
open: () => void;
|
|
131
|
+
/** Close the chat */
|
|
132
|
+
close: () => void;
|
|
133
|
+
/** Toggle chat open/closed */
|
|
134
|
+
toggle: () => void;
|
|
135
|
+
/** Send a message programmatically */
|
|
136
|
+
sendMessage: (content: string) => void;
|
|
137
|
+
/** Access the underlying iframe element */
|
|
138
|
+
iframe: HTMLIFrameElement | null;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Error object for onError callback
|
|
142
|
+
*/
|
|
143
|
+
interface OzwellError {
|
|
144
|
+
code: string;
|
|
145
|
+
message: string;
|
|
146
|
+
details?: unknown;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Vanilla widget API exposed on window object
|
|
150
|
+
*/
|
|
151
|
+
interface OzwellChatAPI {
|
|
152
|
+
mount: (options?: {
|
|
153
|
+
containerId?: string;
|
|
154
|
+
src?: string;
|
|
155
|
+
width?: number;
|
|
156
|
+
height?: number;
|
|
157
|
+
}) => HTMLIFrameElement;
|
|
158
|
+
configure: (config: Partial<OzwellConfig>) => void;
|
|
159
|
+
ready: () => Promise<void>;
|
|
160
|
+
/** Programmatically open the chat window */
|
|
161
|
+
open: () => void;
|
|
162
|
+
/** Programmatically close the chat window */
|
|
163
|
+
close: () => void;
|
|
164
|
+
/** Current iframe element */
|
|
165
|
+
iframe: HTMLIFrameElement | null;
|
|
166
|
+
/** Whether the chat window is currently open */
|
|
167
|
+
isOpen: boolean;
|
|
168
|
+
/** Whether there are unread messages */
|
|
169
|
+
hasUnread: boolean;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Extend Window interface for TypeScript
|
|
173
|
+
*/
|
|
174
|
+
declare global {
|
|
175
|
+
interface Window {
|
|
176
|
+
OzwellChat?: OzwellChatAPI;
|
|
177
|
+
OzwellChatConfig?: Partial<OzwellConfig>;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Script load status
|
|
182
|
+
*/
|
|
183
|
+
type ScriptLoadStatus = 'idle' | 'loading' | 'ready' | 'error';
|
|
184
|
+
/**
|
|
185
|
+
* PostMessage event data from widget
|
|
186
|
+
*/
|
|
187
|
+
interface OzwellWidgetMessage {
|
|
188
|
+
source: 'ozwell-chat-widget';
|
|
189
|
+
type: 'ready' | 'request-config' | 'closed' | 'opened' | 'tool_call' | 'assistant_response' | 'user-share' | 'error';
|
|
190
|
+
payload?: unknown;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Assistant response notification from widget (signal only, no message content)
|
|
194
|
+
*/
|
|
195
|
+
interface OzwellAssistantResponseMessage {
|
|
196
|
+
source: 'ozwell-chat-widget';
|
|
197
|
+
type: 'assistant_response';
|
|
198
|
+
/** Whether the response included tool calls */
|
|
199
|
+
hadToolCalls: boolean;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Tool call message from widget to parent
|
|
203
|
+
* Properties are at the root level (not nested in payload)
|
|
204
|
+
*/
|
|
205
|
+
interface OzwellToolCallMessage {
|
|
206
|
+
source: 'ozwell-chat-widget';
|
|
207
|
+
type: 'tool_call';
|
|
208
|
+
/** Tool function name */
|
|
209
|
+
tool: string;
|
|
210
|
+
/** Unique ID for this tool call */
|
|
211
|
+
tool_call_id: string;
|
|
212
|
+
/** Tool arguments (parsed from function.arguments) */
|
|
213
|
+
payload: Record<string, unknown>;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* PostMessage event data to widget
|
|
217
|
+
*/
|
|
218
|
+
interface OzwellParentMessage {
|
|
219
|
+
source: 'ozwell-chat-parent';
|
|
220
|
+
type: 'config' | 'tool_result';
|
|
221
|
+
payload?: unknown;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Tool result message from parent to widget
|
|
225
|
+
* Properties are at the root level (not nested in payload)
|
|
226
|
+
*/
|
|
227
|
+
interface OzwellToolResultMessage {
|
|
228
|
+
source: 'ozwell-chat-parent';
|
|
229
|
+
type: 'tool_result';
|
|
230
|
+
/** Must match the tool_call_id from the tool_call message */
|
|
231
|
+
tool_call_id: string;
|
|
232
|
+
/** Result data to send back to the LLM */
|
|
233
|
+
result: unknown;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* OzwellChat - React component wrapper for Ozwell chat widget
|
|
238
|
+
*
|
|
239
|
+
* This component loads the vanilla Ozwell widget and provides a React-friendly API.
|
|
240
|
+
* It wraps the existing ozwell-loader.js implementation rather than reimplementing it.
|
|
241
|
+
*
|
|
242
|
+
* IMPORTANT: Only render one OzwellChat component per page. Multiple instances
|
|
243
|
+
* will share global configuration (window.OzwellChatConfig) and may cause
|
|
244
|
+
* unexpected behavior. Use conditional rendering for different configurations.
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* ```tsx
|
|
248
|
+
* <OzwellChat
|
|
249
|
+
* endpoint="/v1/chat/completions"
|
|
250
|
+
* tools={[...]}
|
|
251
|
+
* onReady={() => console.log('Ready!')}
|
|
252
|
+
* />
|
|
253
|
+
* ```
|
|
254
|
+
*/
|
|
255
|
+
declare function OzwellChat(props: OzwellChatProps): react_jsx_runtime.JSX.Element;
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* useOzwell - React hook for programmatic control of Ozwell widget
|
|
259
|
+
*
|
|
260
|
+
* Provides methods to control the widget and access its state.
|
|
261
|
+
* Must be used within a component tree that has OzwellChat mounted.
|
|
262
|
+
*
|
|
263
|
+
* @example
|
|
264
|
+
* ```tsx
|
|
265
|
+
* function ChatControls() {
|
|
266
|
+
* const ozwell = useOzwell();
|
|
267
|
+
*
|
|
268
|
+
* return (
|
|
269
|
+
* <div>
|
|
270
|
+
* <button onClick={() => ozwell.open()}>Open Chat</button>
|
|
271
|
+
* <button onClick={() => ozwell.sendMessage('Hello!')}>Send Hello</button>
|
|
272
|
+
* {ozwell.isReady ? 'Ready' : 'Loading...'}
|
|
273
|
+
* </div>
|
|
274
|
+
* );
|
|
275
|
+
* }
|
|
276
|
+
* ```
|
|
277
|
+
*
|
|
278
|
+
* @returns {UseOzwellReturn} Widget control methods and state
|
|
279
|
+
*/
|
|
280
|
+
declare function useOzwell(): UseOzwellReturn;
|
|
281
|
+
|
|
282
|
+
export { type OzwellAssistantResponseMessage, OzwellChat, type OzwellChatAPI, type OzwellChatProps, type OzwellConfig, type OzwellError, type OzwellParentMessage, type OzwellTool, type OzwellToolCallMessage, type OzwellToolFunction, type OzwellToolParameter, type OzwellToolResultMessage, type OzwellWidgetMessage, type ScriptLoadStatus, type UseOzwellReturn, OzwellChat as default, useOzwell };
|