@botdojo/chat-sdk 0.0.2 → 0.0.4

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 CHANGED
@@ -52,12 +52,12 @@ function App() {
52
52
  tools: {
53
53
  get_page_title: {
54
54
  description: 'Get the current page title',
55
- parameters: { type: 'object', properties: {} },
55
+ inputSchema: { type: 'object', properties: {} },
56
56
  execute: async () => document.title
57
57
  },
58
58
  scroll_to_section: {
59
59
  description: 'Scroll to a specific section',
60
- parameters: {
60
+ inputSchema: {
61
61
  type: 'object',
62
62
  properties: {
63
63
  section: { type: 'string', description: 'Section ID' }
@@ -418,7 +418,7 @@ const modelContext = {
418
418
  {
419
419
  name: 'showProductCard',
420
420
  description: 'Display a product card in the chat',
421
- arguments: {
421
+ inputSchema: {
422
422
  type: 'object',
423
423
  properties: {
424
424
  product_id: { type: 'string' }
package/lib/index.d.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  import React$1 from 'react';
2
2
  import { ModelContext, BotDojoConnector as BotDojoConnector$1 } from '@botdojo/sdk-canvas';
3
3
  export { BotDojoConnector } from '@botdojo/sdk-canvas';
4
- import { ModelContext as ModelContext$1 } from '@botdojo/sdk-types';
5
- export { ModelContext, ModelContextMessage, ModelContextPrompt, ModelContextResource, ResourceContent, ResourceProvider, ResourceTemplate, ToolDefinition, ToolExecutionContext, ToolResponse, ToolResponseAction, actions, toolResponse } from '@botdojo/sdk-types';
4
+ import { ModelContext as ModelContext$1, FlowRequestStep, TokenUpdate } from '@botdojo/sdk-types';
5
+ export { FlowCanvas, FlowRequestStep, ModelContext, ModelContextMessage, ModelContextPrompt, ModelContextResource, ResourceContent, ResourceProvider, ResourceTemplate, TokenUpdate, ToolDefinition, ToolExecutionContext, ToolResponse, ToolResponseAction, actions, toolResponse } from '@botdojo/sdk-types';
6
+ import { ChatMessage as ChatMessage$1 } from 'botdojo-core/lib/src/store/session';
7
+ import { FlowCanvasType } from 'botdojo-core/lib/src/store/flowRequest';
6
8
  import * as react_jsx_runtime from 'react/jsx-runtime';
7
9
 
8
10
  /**
@@ -147,9 +149,9 @@ interface BotDojoChatProps {
147
149
  */
148
150
  backgroundColor?: string;
149
151
  /**
150
- * Theme mode: 'light' or 'dark'
152
+ * Theme mode: 'light', 'dark', 'modern-light', or 'modern-dark'
151
153
  */
152
- theme?: 'light' | 'dark';
154
+ theme?: 'light' | 'dark' | 'modern-light' | 'modern-dark';
153
155
  /**
154
156
  * Font size for chat text
155
157
  */
@@ -179,6 +181,11 @@ interface BotDojoChatProps {
179
181
  * URL for voice icon
180
182
  */
181
183
  voiceIcon?: string;
184
+ /**
185
+ * Hide the bot/agent icon completely
186
+ * @default false
187
+ */
188
+ hideBotIcon?: boolean;
182
189
  /**
183
190
  * Start a new session instead of resuming
184
191
  * @default false
@@ -273,6 +280,435 @@ interface BotDojoChatProps {
273
280
  */
274
281
  declare const BotDojoChat: React$1.FC<BotDojoChatProps>;
275
282
 
283
+ /**
284
+ * Chat status during flow execution
285
+ */
286
+ type ChatStatus = 'idle' | 'running' | 'completed' | 'error';
287
+ /**
288
+ * Token event fired when new text token is received
289
+ */
290
+ interface HeadlessTokenEvent {
291
+ type: 'token';
292
+ token: string;
293
+ messageId?: string;
294
+ }
295
+ /**
296
+ * Step event fired for intermediate flow steps
297
+ */
298
+ interface HeadlessStepEvent {
299
+ type: 'step';
300
+ step: string;
301
+ data?: any;
302
+ }
303
+ /**
304
+ * Status change event
305
+ */
306
+ interface HeadlessStatusEvent {
307
+ type: 'status';
308
+ status: ChatStatus;
309
+ error?: string;
310
+ }
311
+ /**
312
+ * Message event with full message data
313
+ */
314
+ interface HeadlessMessageEvent {
315
+ type: 'message';
316
+ role: 'user' | 'assistant' | 'system';
317
+ content: string;
318
+ messageId: string;
319
+ }
320
+ /**
321
+ * Configuration for the chat
322
+ */
323
+ interface ChatConfig {
324
+ welcomeMessage?: string;
325
+ messageHistory?: Array<{
326
+ role: 'user' | 'assistant' | 'system';
327
+ content: string;
328
+ }>;
329
+ placeholder?: string;
330
+ systemPrompt?: string;
331
+ }
332
+ /**
333
+ * Props for HeadlessChat component
334
+ */
335
+ interface HeadlessChatProps {
336
+ /**
337
+ * BotDojo API key (required)
338
+ * The API key contains all flow configuration needed
339
+ */
340
+ apiKey: string;
341
+ /**
342
+ * Model context with tools, prompts, and resources
343
+ * Tools should include `execute` functions directly in their definitions
344
+ */
345
+ modelContext?: ModelContext | ModelContext[];
346
+ /**
347
+ * Base URL for the headless embed iframe
348
+ * @default 'http://localhost:3000' (development)
349
+ */
350
+ baseUrl?: string;
351
+ /**
352
+ * Initial chat configuration
353
+ */
354
+ config?: ChatConfig;
355
+ /**
356
+ * Callback when status changes (idle, running, completed, error)
357
+ */
358
+ onStatusChange?: (status: ChatStatus, error?: string) => void;
359
+ /**
360
+ * Callback when new token is received
361
+ */
362
+ onToken?: (token: string, messageId?: string) => void;
363
+ /**
364
+ * Callback when intermediate step is executed
365
+ */
366
+ onStep?: (step: any, messageId?: string) => void;
367
+ /**
368
+ * Callback when canvas is attached to a step
369
+ */
370
+ onCanvas?: (canvasData: any, stepId: string, messageId?: string) => void;
371
+ /**
372
+ * Callback when a new message starts
373
+ */
374
+ onMessageStart?: (role: 'user' | 'assistant' | 'system', messageId: string) => void;
375
+ /**
376
+ * Callback when a message is complete
377
+ */
378
+ onMessageComplete?: (messageId: string, content: string) => void;
379
+ /**
380
+ * Callback when message is received (full message)
381
+ * @deprecated Use onMessageComplete instead
382
+ */
383
+ onMessage?: (role: 'user' | 'assistant' | 'system', content: string, messageId: string) => void;
384
+ /**
385
+ * Callback when iframe is loaded and ready
386
+ */
387
+ onReady?: () => void;
388
+ /**
389
+ * Callback when error occurs
390
+ */
391
+ onError?: (error: string) => void;
392
+ }
393
+ /**
394
+ * HeadlessChat component
395
+ *
396
+ * A headless version of BotDojoChat that uses an iframe for BotDojo API communication
397
+ * but lets you control the UI completely. Events are sent via postMessage.
398
+ *
399
+ * @example
400
+ * ```tsx
401
+ * const [messages, setMessages] = useState([]);
402
+ * const [status, setStatus] = useState('idle');
403
+ * const headlessRef = useRef(null);
404
+ *
405
+ * return (
406
+ * <div>
407
+ * <HeadlessChat
408
+ * apiKey="your-api-key"
409
+ * ref={headlessRef}
410
+ * onStatusChange={(status) => setStatus(status)}
411
+ * onToken={(token) => console.log('Token:', token)}
412
+ * onMessage={(role, content, id) => {
413
+ * setMessages(prev => [...prev, { role, content, id }]);
414
+ * }}
415
+ * />
416
+ * <YourCustomUI
417
+ * messages={messages}
418
+ * status={status}
419
+ * onSend={(text) => headlessRef.current?.sendMessage(text)}
420
+ * />
421
+ * </div>
422
+ * );
423
+ * ```
424
+ */
425
+ declare const HeadlessChat: React$1.ForwardRefExoticComponent<HeadlessChatProps & React$1.RefAttributes<HeadlessChatHandle>>;
426
+ /**
427
+ * Handle for controlling HeadlessChat imperatively via ref
428
+ */
429
+ interface HeadlessChatHandle {
430
+ /**
431
+ * Send a message to the chat
432
+ * @param input - The flow input object (e.g., { text_input: 'hello' })
433
+ */
434
+ sendMessage: (input: any) => void;
435
+ /**
436
+ * Update chat configuration
437
+ */
438
+ updateConfig: (config: ChatConfig) => void;
439
+ /**
440
+ * Clear chat history
441
+ */
442
+ clearHistory: () => void;
443
+ /**
444
+ * Cancel current flow execution
445
+ */
446
+ cancelExecution: () => void;
447
+ /**
448
+ * Get current status
449
+ */
450
+ getStatus: () => ChatStatus;
451
+ /**
452
+ * Check if iframe is ready
453
+ */
454
+ isReady: () => boolean;
455
+ }
456
+
457
+ /**
458
+ * Headless Chat Types
459
+ *
460
+ * Types for the Headless Chat SDK. These types build on BotDojo's core types
461
+ * (FlowRequestIntermediateStep, TokenUpdate, FlowCanvas) and add minimal wrapper
462
+ * types for the React state management layer.
463
+ */
464
+
465
+ /**
466
+ * Canvas action from MCP-UI embedded iframe
467
+ */
468
+ interface CanvasAction {
469
+ type: 'intent' | 'notify' | 'prompt' | 'link' | 'tool' | 'update' | 'message';
470
+ canvasId: string;
471
+ payload: any;
472
+ }
473
+ /**
474
+ * Chat message for headless rendering
475
+ * Wraps BotDojo's ChatMessage with additional UI state
476
+ */
477
+ interface ChatMessage {
478
+ id: string;
479
+ role: 'user' | 'assistant' | 'system';
480
+ content: string;
481
+ timestamp: Date;
482
+ status: 'sending' | 'streaming' | 'complete' | 'error';
483
+ steps: FlowRequestStep[];
484
+ }
485
+ interface HeadlessChatState {
486
+ isReady: boolean;
487
+ error: Error | null;
488
+ messages: ChatMessage[];
489
+ status: 'idle' | 'loading' | 'streaming' | 'error';
490
+ sessionId: string | null;
491
+ }
492
+ type HeadlessEvent = {
493
+ type: 'ready';
494
+ } | {
495
+ type: 'error';
496
+ error: string;
497
+ messageId?: string;
498
+ stepId?: string;
499
+ } | {
500
+ type: 'message_start';
501
+ messageId: string;
502
+ role: 'user' | 'assistant' | 'system';
503
+ } | {
504
+ type: 'message_complete';
505
+ messageId: string;
506
+ content: string;
507
+ } | {
508
+ type: 'step_update';
509
+ messageId: string;
510
+ step: FlowRequestStep;
511
+ } | {
512
+ type: 'token';
513
+ messageId: string;
514
+ tokenUpdate: TokenUpdate;
515
+ } | {
516
+ type: 'session_hydrated';
517
+ sessionId: string;
518
+ messages: ChatMessage$1[];
519
+ } | {
520
+ type: 'request_aborted';
521
+ };
522
+ type HeadlessAction = {
523
+ type: 'READY';
524
+ } | {
525
+ type: 'ERROR';
526
+ error: Error;
527
+ } | {
528
+ type: 'SET_SESSION';
529
+ sessionId: string;
530
+ } | {
531
+ type: 'MESSAGE_START';
532
+ messageId: string;
533
+ role: string;
534
+ } | {
535
+ type: 'MESSAGE_COMPLETE';
536
+ messageId: string;
537
+ content: string;
538
+ } | {
539
+ type: 'STEP_UPDATE';
540
+ messageId: string;
541
+ step: FlowRequestStep;
542
+ } | {
543
+ type: 'TOKEN';
544
+ messageId: string;
545
+ tokenUpdate: TokenUpdate;
546
+ } | {
547
+ type: 'SESSION_HYDRATED';
548
+ sessionId: string;
549
+ messages: ChatMessage$1[];
550
+ } | {
551
+ type: 'REQUEST_ABORTED';
552
+ } | {
553
+ type: 'SEND_MESSAGE';
554
+ text: string;
555
+ };
556
+ interface BotDojoChatHook {
557
+ state: {
558
+ status: 'idle' | 'loading' | 'streaming' | 'error';
559
+ isReady: boolean;
560
+ error: Error | null;
561
+ };
562
+ actions: {
563
+ sendMessage: (text: string) => void;
564
+ abortRequest: () => void;
565
+ bargeInRequest: (text: string) => void;
566
+ setSessionId: (sessionId: string) => void;
567
+ reload: () => void;
568
+ };
569
+ }
570
+ interface ChatMessagesHook {
571
+ messages: ChatMessage[];
572
+ currentMessage: ChatMessage | null;
573
+ isStreaming: boolean;
574
+ }
575
+ interface ChatStatusHook {
576
+ status: 'idle' | 'loading' | 'streaming' | 'error';
577
+ isReady: boolean;
578
+ error: Error | null;
579
+ sessionId: string | null;
580
+ }
581
+ interface ChatActionsHook {
582
+ sendMessage: (text: string) => void;
583
+ abortRequest: () => void;
584
+ bargeInRequest: (text: string) => void;
585
+ setSessionId: (sessionId: string) => void;
586
+ reload: () => void;
587
+ }
588
+ interface BotDojoChatProviderProps {
589
+ apiKey: string;
590
+ modelContext?: ModelContext$1 | ModelContext$1[];
591
+ baseUrl?: string;
592
+ sessionId?: string;
593
+ newSession?: boolean;
594
+ children: React.ReactNode;
595
+ onError?: (error: Error) => void;
596
+ onReady?: () => void;
597
+ onSessionCreated?: (sessionId: string) => void;
598
+ onSessionHydrated?: (messageCount: number) => void;
599
+ onConnectorInit?: (connector: BotDojoConnector$1) => void;
600
+ onConnectorError?: (error: Error) => void;
601
+ /**
602
+ * Handler for canvas intent messages (user expressed intent for host to act on)
603
+ * @param intent - The user's intent (e.g., 'add-to-cart', 'checkout')
604
+ * @param params - Parameters for the intent
605
+ * @param canvasId - ID of the canvas that sent the intent
606
+ * @returns Promise resolving to result, or void
607
+ */
608
+ onCanvasIntent?: (intent: string, params: any, canvasId: string) => Promise<any> | void;
609
+ /**
610
+ * Handler for canvas notify messages (canvas already acted, informing host of side effects)
611
+ * @param message - The notification message
612
+ * @param params - Additional notification parameters
613
+ * @param canvasId - ID of the canvas that sent the notification
614
+ */
615
+ onCanvasNotify?: (message: string, params: any, canvasId: string) => void;
616
+ /**
617
+ * Handler for canvas prompt messages (canvas wants AI agent to respond)
618
+ * @param prompt - The prompt/question for the AI
619
+ * @param params - Additional prompt parameters
620
+ * @param canvasId - ID of the canvas that sent the prompt
621
+ * @returns Promise resolving to AI response, or void to use default behavior
622
+ */
623
+ onCanvasPrompt?: (prompt: string, params: any, canvasId: string) => Promise<string> | void;
624
+ /**
625
+ * Handler for canvas link messages (canvas wants to navigate to URL)
626
+ * @param url - The URL to navigate to
627
+ * @param target - Target window ('_blank', '_self', etc.)
628
+ * @param canvasId - ID of the canvas that sent the link request
629
+ */
630
+ onCanvasLink?: (url: string, target: string, canvasId: string) => void;
631
+ /**
632
+ * Unified handler for all canvas actions (alternative to specific handlers)
633
+ * @param action - The canvas action
634
+ * @returns Promise resolving to result, or void. Return undefined to fall back to default behavior.
635
+ */
636
+ onCanvasAction?: (action: CanvasAction) => Promise<any> | void;
637
+ }
638
+
639
+ /**
640
+ * BotDojo Chat Provider
641
+ *
642
+ * Main provider component for Headless Chat with full RPC/Connector support.
643
+ *
644
+ * This component:
645
+ * 1. Creates a hidden iframe with /embed/headless
646
+ * 2. Initializes BotDojoConnector for model context and tool calls
647
+ * 3. Sets up RPCConnection for parent-embed communication
648
+ * 4. Manages canvas iframe bridges for tool call routing
649
+ * 5. Listens to postMessage events from iframe
650
+ * 6. Updates React state via reducer
651
+ * 7. Exposes state, connector, and actions via context
652
+ */
653
+
654
+ declare function BotDojoChatProvider(props: BotDojoChatProviderProps): JSX.Element;
655
+
656
+ /**
657
+ * useBotDojoChat Hook
658
+ *
659
+ * Main hook that provides both state and actions
660
+ */
661
+
662
+ declare function useBotDojoChat(): BotDojoChatHook;
663
+
664
+ /**
665
+ * useChatMessages Hook
666
+ *
667
+ * Provides access to messages array and streaming state
668
+ */
669
+
670
+ declare function useChatMessages(): ChatMessagesHook;
671
+
672
+ /**
673
+ * useChatStatus Hook
674
+ *
675
+ * Provides chat status information
676
+ */
677
+
678
+ declare function useChatStatus(): ChatStatusHook;
679
+
680
+ /**
681
+ * useChatActions Hook
682
+ *
683
+ * Provides action dispatchers for controlling chat
684
+ */
685
+
686
+ declare function useChatActions(): ChatActionsHook;
687
+
688
+ /**
689
+ * BotDojoCanvasFrame Component
690
+ *
691
+ * Creates and manages a canvas iframe in the parent window. This component:
692
+ * 1. Creates an iframe for the canvas page
693
+ * 2. Registers with BotDojoChatProvider for canvas bridge management
694
+ * 3. Handles canvas tool calls and event forwarding via provider
695
+ *
696
+ * Note: This is for the PARENT page to render canvas iframes.
697
+ * For canvas pages running inside iframes, use BotDojoCanvas from @botdojo/sdk-canvas.
698
+ *
699
+ * Canvas updates flow: BotDojo API → /embed/headless → parent provider → BotDojoCanvasFrame → canvas iframe
700
+ */
701
+
702
+ interface BotDojoCanvasFrameProps {
703
+ canvasId: string;
704
+ canvasData: any;
705
+ canvasType?: FlowCanvasType;
706
+ width?: string | number;
707
+ height?: string | number;
708
+ style?: React$1.CSSProperties;
709
+ }
710
+ declare function BotDojoCanvasFrame(props: BotDojoCanvasFrameProps): JSX.Element;
711
+
276
712
  interface BotDojoChatConfig {
277
713
  apiKey: string;
278
714
  mode: BotDojoChatDisplayMode;
@@ -282,7 +718,7 @@ interface BotDojoChatConfig {
282
718
  height?: string;
283
719
  accentColor: string;
284
720
  backgroundColor: string;
285
- theme?: 'light' | 'dark';
721
+ theme?: 'light' | 'dark' | 'modern-light' | 'modern-dark';
286
722
  fontSize?: string;
287
723
  flowVersion: string;
288
724
  flowHeaders?: Record<string, any>;
@@ -381,4 +817,4 @@ declare function MockCanvasProvider({ children, mockCanvasData, onSendMessage, d
381
817
  */
382
818
  declare function useBotDojoCanvas(): UseBotDojoCanvasReturn;
383
819
 
384
- export { BotDojoCanvasProvider, type BotDojoCanvasProviderProps, BotDojoChat, type BotDojoChatConfig, BotDojoChatConfigurator, type BotDojoChatConfiguratorProps, type BotDojoChatControl, type BotDojoChatDisplayMode, type BotDojoChatProps, type CanvasEvent, MockCanvasProvider, type MockCanvasProviderProps, type PopupOptions, type SidePanelOptions, type UseBotDojoCanvasReturn, useBotDojoCanvas };
820
+ export { BotDojoCanvasFrame, type BotDojoCanvasFrameProps, BotDojoCanvasProvider, type BotDojoCanvasProviderProps, BotDojoChat, type BotDojoChatConfig, BotDojoChatConfigurator, type BotDojoChatConfiguratorProps, type BotDojoChatControl, type BotDojoChatDisplayMode, type BotDojoChatHook, type BotDojoChatProps, BotDojoChatProvider, type BotDojoChatProviderProps, type CanvasAction, type CanvasEvent, type ChatActionsHook, type ChatConfig, type ChatMessage, type ChatMessagesHook, type ChatStatus, type ChatStatusHook, type HeadlessAction, HeadlessChat, type HeadlessChatHandle, type HeadlessChatProps, type HeadlessChatState, type HeadlessEvent, type HeadlessMessageEvent, type HeadlessStatusEvent, type HeadlessStepEvent, type HeadlessTokenEvent, MockCanvasProvider, type MockCanvasProviderProps, type PopupOptions, type SidePanelOptions, type UseBotDojoCanvasReturn, useBotDojoCanvas, useBotDojoChat, useChatActions, useChatMessages, useChatStatus };