@object-ui/plugin-chatbot 3.3.0 → 3.3.1

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/src/renderer.tsx DELETED
@@ -1,483 +0,0 @@
1
- /**
2
- * ObjectUI
3
- * Copyright (c) 2024-present ObjectStack Inc.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
-
9
- import { ComponentRegistry } from '@object-ui/core';
10
- import type { ChatbotSchema, ChatMessage } from '@object-ui/types';
11
- import { Chatbot } from './index';
12
- import { ChatbotEnhanced } from './ChatbotEnhanced';
13
- import { FloatingChatbot } from './FloatingChatbot';
14
- import { useObjectChat } from './useObjectChat';
15
-
16
- /**
17
- * Chatbot component for Object UI
18
- *
19
- * @remarks
20
- * This component supports two modes:
21
- *
22
- * **API Mode** (when `api` is set):
23
- * - Uses @ai-sdk/react for SSE streaming, tool-calling, and production-grade chat
24
- * - Connects to service-ai backend (e.g., /api/v1/ai/chat)
25
- * - Supports streaming, stop, reload, clear actions
26
- * - Schema fields: api, conversationId, systemPrompt, model, streamingEnabled, headers, requestBody, maxToolRoundtrips
27
- *
28
- * **Legacy Mode** (when `api` is not set):
29
- * - Local auto-response for demo/playground use
30
- * - Schema fields: autoResponse, autoResponseText, autoResponseDelay
31
- *
32
- * Both modes support the `onSend` callback:
33
- * - Signature: `onSend(content: string, messages: ChatMessage[]): void`
34
- */
35
- ComponentRegistry.register('chatbot',
36
- ({ schema, className, ...props }: { schema: ChatbotSchema & {
37
- showTimestamp?: boolean;
38
- disabled?: boolean;
39
- userAvatarUrl?: string;
40
- userAvatarFallback?: string;
41
- assistantAvatarUrl?: string;
42
- assistantAvatarFallback?: string;
43
- maxHeight?: string;
44
- autoResponse?: boolean;
45
- autoResponseText?: string;
46
- autoResponseDelay?: number;
47
- onSend?: (content: string, messages: ChatMessage[]) => void;
48
- }; className?: string; [key: string]: any }) => {
49
- const {
50
- messages,
51
- isLoading,
52
- sendMessage,
53
- } = useObjectChat({
54
- api: schema.api,
55
- initialMessages: schema.messages,
56
- conversationId: schema.conversationId,
57
- systemPrompt: schema.systemPrompt,
58
- model: schema.model,
59
- streamingEnabled: schema.streamingEnabled,
60
- headers: schema.headers,
61
- body: schema.requestBody,
62
- maxToolRoundtrips: schema.maxToolRoundtrips,
63
- onError: schema.onError,
64
- showTimestamp: schema.showTimestamp,
65
- autoResponse: schema.autoResponse,
66
- autoResponseText: schema.autoResponseText,
67
- autoResponseDelay: schema.autoResponseDelay,
68
- onSend: schema.onSend,
69
- });
70
-
71
- const handleSendMessage = (content: string) => {
72
- sendMessage(content);
73
- };
74
-
75
- return (
76
- <Chatbot
77
- messages={messages as any}
78
- placeholder={schema.placeholder}
79
- onSendMessage={handleSendMessage}
80
- disabled={schema.disabled || isLoading}
81
- showTimestamp={schema.showTimestamp}
82
- userAvatarUrl={schema.userAvatarUrl}
83
- userAvatarFallback={schema.userAvatarFallback}
84
- assistantAvatarUrl={schema.assistantAvatarUrl}
85
- assistantAvatarFallback={schema.assistantAvatarFallback}
86
- maxHeight={schema.maxHeight}
87
- className={className}
88
- {...props}
89
- />
90
- );
91
- },
92
- {
93
- namespace: 'plugin-chatbot',
94
- label: 'Chatbot',
95
- inputs: [
96
- {
97
- name: 'messages',
98
- type: 'array',
99
- label: 'Initial Messages',
100
- description: 'Array of message objects with id, role, content, and optional timestamp'
101
- },
102
- {
103
- name: 'placeholder',
104
- type: 'string',
105
- label: 'Input Placeholder',
106
- defaultValue: 'Type your message...'
107
- },
108
- {
109
- name: 'showTimestamp',
110
- type: 'boolean',
111
- label: 'Show Timestamps',
112
- defaultValue: false
113
- },
114
- {
115
- name: 'disabled',
116
- type: 'boolean',
117
- label: 'Disabled',
118
- defaultValue: false
119
- },
120
- {
121
- name: 'userAvatarUrl',
122
- type: 'string',
123
- label: 'User Avatar URL',
124
- description: 'URL of the user avatar image'
125
- },
126
- {
127
- name: 'userAvatarFallback',
128
- type: 'string',
129
- label: 'User Avatar Fallback',
130
- defaultValue: 'You',
131
- description: 'Fallback text shown when user avatar image is not available'
132
- },
133
- {
134
- name: 'assistantAvatarUrl',
135
- type: 'string',
136
- label: 'Assistant Avatar URL',
137
- description: 'URL of the assistant avatar image'
138
- },
139
- {
140
- name: 'assistantAvatarFallback',
141
- type: 'string',
142
- label: 'Assistant Avatar Fallback',
143
- defaultValue: 'AI',
144
- description: 'Fallback text shown when assistant avatar image is not available'
145
- },
146
- {
147
- name: 'maxHeight',
148
- type: 'string',
149
- label: 'Max Height',
150
- defaultValue: '500px'
151
- },
152
- {
153
- name: 'api',
154
- type: 'string',
155
- label: 'API Endpoint',
156
- description: 'Backend SSE endpoint (e.g., /api/v1/ai/chat). When set, enables streaming AI mode.'
157
- },
158
- {
159
- name: 'conversationId',
160
- type: 'string',
161
- label: 'Conversation ID',
162
- description: 'Multi-turn conversation identifier'
163
- },
164
- {
165
- name: 'systemPrompt',
166
- type: 'string',
167
- label: 'System Prompt',
168
- description: 'System prompt to configure assistant behavior'
169
- },
170
- {
171
- name: 'model',
172
- type: 'string',
173
- label: 'AI Model',
174
- description: 'AI model identifier (e.g., gpt-4o)'
175
- },
176
- {
177
- name: 'streamingEnabled',
178
- type: 'boolean',
179
- label: 'Enable Streaming',
180
- defaultValue: true
181
- },
182
- {
183
- name: 'autoResponse',
184
- type: 'boolean',
185
- label: 'Enable Auto Response (Demo)',
186
- defaultValue: false,
187
- description: 'Automatically send a response after user message (for demo purposes, ignored when API is set)'
188
- },
189
- {
190
- name: 'autoResponseText',
191
- type: 'string',
192
- label: 'Auto Response Text',
193
- defaultValue: 'Thank you for your message!'
194
- },
195
- {
196
- name: 'autoResponseDelay',
197
- type: 'number',
198
- label: 'Auto Response Delay (ms)',
199
- defaultValue: 1000
200
- },
201
- {
202
- name: 'className',
203
- type: 'string',
204
- label: 'CSS Class'
205
- }
206
- ],
207
- defaultProps: {
208
- messages: [
209
- {
210
- id: 'welcome',
211
- role: 'assistant',
212
- content: 'Hello! How can I help you today?',
213
- }
214
- ],
215
- placeholder: 'Type your message...',
216
- showTimestamp: false,
217
- disabled: false,
218
- userAvatarFallback: 'You',
219
- assistantAvatarFallback: 'AI',
220
- maxHeight: '500px',
221
- autoResponse: true,
222
- autoResponseText: 'Thank you for your message! This is an automated response.',
223
- autoResponseDelay: 1000,
224
- className: 'w-full max-w-2xl'
225
- }
226
- }
227
- );
228
-
229
- // Register Enhanced Chatbot
230
- ComponentRegistry.register('chatbot-enhanced',
231
- ({ schema, className, ...props }: { schema: ChatbotSchema & {
232
- enableMarkdown?: boolean;
233
- enableFileUpload?: boolean;
234
- showTimestamp?: boolean;
235
- disabled?: boolean;
236
- userAvatarUrl?: string;
237
- userAvatarFallback?: string;
238
- assistantAvatarUrl?: string;
239
- assistantAvatarFallback?: string;
240
- maxHeight?: string;
241
- autoResponse?: boolean;
242
- autoResponseText?: string;
243
- autoResponseDelay?: number;
244
- onSend?: (content: string, messages: ChatMessage[]) => void;
245
- onClear?: () => void;
246
- }; className?: string; [key: string]: any }) => {
247
- const {
248
- messages,
249
- isLoading,
250
- error,
251
- sendMessage,
252
- stop,
253
- reload,
254
- clear,
255
- isApiMode,
256
- } = useObjectChat({
257
- api: schema.api,
258
- initialMessages: schema.messages,
259
- conversationId: schema.conversationId,
260
- systemPrompt: schema.systemPrompt,
261
- model: schema.model,
262
- streamingEnabled: schema.streamingEnabled,
263
- headers: schema.headers,
264
- body: schema.requestBody,
265
- maxToolRoundtrips: schema.maxToolRoundtrips,
266
- onError: schema.onError,
267
- showTimestamp: schema.showTimestamp,
268
- autoResponse: schema.autoResponse,
269
- autoResponseText: schema.autoResponseText,
270
- autoResponseDelay: schema.autoResponseDelay,
271
- onSend: schema.onSend,
272
- });
273
-
274
- const handleSendMessage = (content: string, files?: File[]) => {
275
- sendMessage(content, files);
276
- };
277
-
278
- const handleClear = () => {
279
- clear();
280
- schema.onClear?.();
281
- };
282
-
283
- return (
284
- <ChatbotEnhanced
285
- messages={messages as any}
286
- placeholder={schema.placeholder}
287
- onSendMessage={handleSendMessage}
288
- onClear={handleClear}
289
- onStop={isApiMode && isLoading ? stop : undefined}
290
- onReload={isApiMode ? reload : undefined}
291
- disabled={schema.disabled}
292
- isLoading={isLoading}
293
- error={error}
294
- showTimestamp={schema.showTimestamp}
295
- userAvatarUrl={schema.userAvatarUrl}
296
- userAvatarFallback={schema.userAvatarFallback}
297
- assistantAvatarUrl={schema.assistantAvatarUrl}
298
- assistantAvatarFallback={schema.assistantAvatarFallback}
299
- maxHeight={schema.maxHeight}
300
- enableMarkdown={schema.enableMarkdown ?? true}
301
- enableFileUpload={schema.enableFileUpload ?? false}
302
- className={className}
303
- {...props}
304
- />
305
- );
306
- },
307
- {
308
- namespace: 'plugin-chatbot',
309
- label: 'Chatbot (Enhanced)',
310
- inputs: [
311
- { name: 'messages', type: 'array', label: 'Initial Messages' },
312
- { name: 'placeholder', type: 'string', label: 'Input Placeholder', defaultValue: 'Type your message...' },
313
- { name: 'showTimestamp', type: 'boolean', label: 'Show Timestamps', defaultValue: false },
314
- { name: 'disabled', type: 'boolean', label: 'Disabled', defaultValue: false },
315
- { name: 'enableMarkdown', type: 'boolean', label: 'Enable Markdown', defaultValue: true },
316
- { name: 'enableFileUpload', type: 'boolean', label: 'Enable File Upload', defaultValue: false },
317
- { name: 'userAvatarUrl', type: 'string', label: 'User Avatar URL' },
318
- { name: 'userAvatarFallback', type: 'string', label: 'User Avatar Fallback', defaultValue: 'You' },
319
- { name: 'assistantAvatarUrl', type: 'string', label: 'Assistant Avatar URL' },
320
- { name: 'assistantAvatarFallback', type: 'string', label: 'Assistant Avatar Fallback', defaultValue: 'AI' },
321
- { name: 'maxHeight', type: 'string', label: 'Max Height', defaultValue: '500px' },
322
- { name: 'api', type: 'string', label: 'API Endpoint', description: 'Backend SSE endpoint for streaming AI mode' },
323
- { name: 'conversationId', type: 'string', label: 'Conversation ID' },
324
- { name: 'systemPrompt', type: 'string', label: 'System Prompt' },
325
- { name: 'model', type: 'string', label: 'AI Model' },
326
- { name: 'streamingEnabled', type: 'boolean', label: 'Enable Streaming', defaultValue: true },
327
- { name: 'autoResponse', type: 'boolean', label: 'Enable Auto Response (Demo)', defaultValue: false },
328
- { name: 'autoResponseText', type: 'string', label: 'Auto Response Text', defaultValue: 'Thank you for your message!' },
329
- { name: 'autoResponseDelay', type: 'number', label: 'Auto Response Delay (ms)', defaultValue: 1000 },
330
- { name: 'className', type: 'string', label: 'CSS Class' }
331
- ],
332
- defaultProps: {
333
- messages: [
334
- {
335
- id: 'welcome',
336
- role: 'assistant',
337
- content: 'Hello! How can I help you today?',
338
- }
339
- ],
340
- placeholder: 'Type your message...',
341
- showTimestamp: false,
342
- disabled: false,
343
- enableMarkdown: true,
344
- enableFileUpload: false,
345
- userAvatarFallback: 'You',
346
- assistantAvatarFallback: 'AI',
347
- maxHeight: '500px',
348
- autoResponse: true,
349
- autoResponseText: 'Thank you for your message! This is an automated response.',
350
- autoResponseDelay: 1000,
351
- className: 'w-full max-w-2xl'
352
- }
353
- }
354
- );
355
-
356
- // Register Floating Chatbot (FAB widget)
357
- ComponentRegistry.register('chatbot-floating',
358
- ({ schema, className, ...props }: { schema: ChatbotSchema & {
359
- enableMarkdown?: boolean;
360
- enableFileUpload?: boolean;
361
- showTimestamp?: boolean;
362
- disabled?: boolean;
363
- userAvatarUrl?: string;
364
- userAvatarFallback?: string;
365
- assistantAvatarUrl?: string;
366
- assistantAvatarFallback?: string;
367
- autoResponse?: boolean;
368
- autoResponseText?: string;
369
- autoResponseDelay?: number;
370
- onSend?: (content: string, messages: ChatMessage[]) => void;
371
- onClear?: () => void;
372
- }; className?: string; [key: string]: any }) => {
373
- const {
374
- messages,
375
- isLoading,
376
- error,
377
- sendMessage,
378
- stop,
379
- reload,
380
- clear,
381
- isApiMode,
382
- } = useObjectChat({
383
- api: schema.api,
384
- initialMessages: schema.messages,
385
- conversationId: schema.conversationId,
386
- systemPrompt: schema.systemPrompt,
387
- model: schema.model,
388
- streamingEnabled: schema.streamingEnabled,
389
- headers: schema.headers,
390
- body: schema.requestBody,
391
- maxToolRoundtrips: schema.maxToolRoundtrips,
392
- onError: schema.onError,
393
- showTimestamp: schema.showTimestamp,
394
- autoResponse: schema.autoResponse,
395
- autoResponseText: schema.autoResponseText,
396
- autoResponseDelay: schema.autoResponseDelay,
397
- onSend: schema.onSend,
398
- });
399
-
400
- const handleSendMessage = (content: string, files?: File[]) => {
401
- sendMessage(content, files);
402
- };
403
-
404
- const handleClear = () => {
405
- clear();
406
- schema.onClear?.();
407
- };
408
-
409
- return (
410
- <FloatingChatbot
411
- floatingConfig={schema.floatingConfig}
412
- messages={messages as any}
413
- placeholder={schema.placeholder}
414
- onSendMessage={handleSendMessage}
415
- onClear={handleClear}
416
- onStop={isApiMode && isLoading ? stop : undefined}
417
- onReload={isApiMode ? reload : undefined}
418
- disabled={schema.disabled}
419
- isLoading={isLoading}
420
- error={error}
421
- showTimestamp={schema.showTimestamp}
422
- userAvatarUrl={schema.userAvatarUrl}
423
- userAvatarFallback={schema.userAvatarFallback}
424
- assistantAvatarUrl={schema.assistantAvatarUrl}
425
- assistantAvatarFallback={schema.assistantAvatarFallback}
426
- enableMarkdown={schema.enableMarkdown ?? true}
427
- enableFileUpload={schema.enableFileUpload ?? false}
428
- className={className}
429
- {...props}
430
- />
431
- );
432
- },
433
- {
434
- namespace: 'plugin-chatbot',
435
- label: 'Chatbot (Floating)',
436
- inputs: [
437
- { name: 'displayMode', type: 'string', label: 'Display Mode', defaultValue: 'floating', description: 'Set to "floating" for FAB widget' },
438
- { name: 'floatingConfig.position', type: 'string', label: 'FAB Position', defaultValue: 'bottom-right', description: 'bottom-right or bottom-left' },
439
- { name: 'floatingConfig.defaultOpen', type: 'boolean', label: 'Default Open', defaultValue: false },
440
- { name: 'floatingConfig.panelWidth', type: 'number', label: 'Panel Width', defaultValue: 400 },
441
- { name: 'floatingConfig.panelHeight', type: 'number', label: 'Panel Height', defaultValue: 520 },
442
- { name: 'floatingConfig.title', type: 'string', label: 'Panel Title', defaultValue: 'Chat' },
443
- { name: 'floatingConfig.triggerSize', type: 'number', label: 'Trigger Size', defaultValue: 56 },
444
- { name: 'messages', type: 'array', label: 'Initial Messages' },
445
- { name: 'placeholder', type: 'string', label: 'Input Placeholder', defaultValue: 'Type your message...' },
446
- { name: 'enableMarkdown', type: 'boolean', label: 'Enable Markdown', defaultValue: true },
447
- { name: 'enableFileUpload', type: 'boolean', label: 'Enable File Upload', defaultValue: false },
448
- { name: 'api', type: 'string', label: 'API Endpoint', description: 'Backend SSE endpoint for streaming AI mode' },
449
- { name: 'conversationId', type: 'string', label: 'Conversation ID' },
450
- { name: 'systemPrompt', type: 'string', label: 'System Prompt' },
451
- { name: 'model', type: 'string', label: 'AI Model' },
452
- { name: 'streamingEnabled', type: 'boolean', label: 'Enable Streaming', defaultValue: true },
453
- { name: 'autoResponse', type: 'boolean', label: 'Enable Auto Response (Demo)', defaultValue: false },
454
- { name: 'autoResponseText', type: 'string', label: 'Auto Response Text', defaultValue: 'Thank you for your message!' },
455
- { name: 'autoResponseDelay', type: 'number', label: 'Auto Response Delay (ms)', defaultValue: 1000 },
456
- { name: 'className', type: 'string', label: 'CSS Class' },
457
- ],
458
- defaultProps: {
459
- displayMode: 'floating',
460
- floatingConfig: {
461
- position: 'bottom-right',
462
- defaultOpen: false,
463
- panelWidth: 400,
464
- panelHeight: 520,
465
- title: 'Chat',
466
- triggerSize: 56,
467
- },
468
- messages: [
469
- {
470
- id: 'welcome',
471
- role: 'assistant',
472
- content: 'Hello! How can I help you today?',
473
- }
474
- ],
475
- placeholder: 'Type your message...',
476
- enableMarkdown: true,
477
- enableFileUpload: false,
478
- autoResponse: true,
479
- autoResponseText: 'Thank you for your message! This is an automated response.',
480
- autoResponseDelay: 1000,
481
- }
482
- }
483
- );