@apteva/apteva-kit 0.1.31 → 0.1.33

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.mts CHANGED
@@ -1,3 +1,4 @@
1
+ import * as react from 'react';
1
2
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
3
  import { ClassValue } from 'clsx';
3
4
 
@@ -363,7 +364,17 @@ interface UseAptevaKitReturn {
363
364
  error: Error | null;
364
365
  }
365
366
 
366
- declare function Chat({ agentId, threadId, initialMessages, context, apiUrl, apiKey, useMock, initialMode, showModeToggle, onModeChange, commandVariant, planMode, onPlanModeChange, enableStreaming, showProgress, loadingText, welcomeTitle, welcomeSubtitle, welcomeIcon, suggestedPrompts, welcomeVariant, onThreadChange, onMessageSent, onAction, onFileUpload, onComplete, onError, onToolResult, placeholder, showHeader, headerTitle, enableWidgets, availableWidgets, compactWidgetContext, onWidgetRender, className, }: ChatProps): react_jsx_runtime.JSX.Element;
367
+ interface ChatHandle {
368
+ /** Send a message programmatically (as if the user typed it) */
369
+ sendMessage: (text: string) => Promise<void>;
370
+ /** Send a system/background message (not shown as user message, just triggers agent) */
371
+ sendSystemMessage: (text: string) => Promise<void>;
372
+ /** Get current messages */
373
+ getMessages: () => Message[];
374
+ /** Clear all messages */
375
+ clearMessages: () => void;
376
+ }
377
+ declare const Chat: react.ForwardRefExoticComponent<ChatProps & react.RefAttributes<ChatHandle>>;
367
378
 
368
379
  declare function Command({ agentId, command: initialCommand, context, autoExecute, allowInput, placeholder, submitButtonText, variant, useMock, planMode, onPlanModeChange, enableFileUpload, onStart, onProgress, onChunk, onComplete, onError, onFileUpload, onAction, loadingText, showProgress, enableStreaming, resultRenderer, className, }: CommandProps): react_jsx_runtime.JSX.Element;
369
380
 
@@ -474,4 +485,4 @@ declare const mockMessages: Message[];
474
485
  declare const mockThreads: Thread[];
475
486
  declare const mockWidgets: Widget[];
476
487
 
477
- export { type Action, type ActionEvent, AptevaClient, type AptevaClientConfig, type AptevaKitControl, Button, type ButtonGroupWidget, type ButtonWidget, Card, type CardWidget, type ChartWidget, Chat, type ChatMessage, type ChatProps, type ChatRequest, type ChatResponse, Command, type CommandProps, type CommandResult, type FormField, type FormWidget, type GalleryWidget, type ImageWidget, List, type ListItem, type ListWidget, type MapWidget, type Message, Prompt, type PromptProps, type SendMessageParams, Stream, type StreamChunk, type StreamProps, type SuggestedPrompt, type TableColumn, type TableWidget, type Thread, Threads, type ThreadsProps, type UseAptevaKitReturn, type Widget, Widgets, type WidgetsProps, aptevaClient, cn, getThemeScript, mockMessages, mockThreads, mockWidgets };
488
+ export { type Action, type ActionEvent, AptevaClient, type AptevaClientConfig, type AptevaKitControl, Button, type ButtonGroupWidget, type ButtonWidget, Card, type CardWidget, type ChartWidget, Chat, type ChatHandle, type ChatMessage, type ChatProps, type ChatRequest, type ChatResponse, Command, type CommandProps, type CommandResult, type FormField, type FormWidget, type GalleryWidget, type ImageWidget, List, type ListItem, type ListWidget, type MapWidget, type Message, Prompt, type PromptProps, type SendMessageParams, Stream, type StreamChunk, type StreamProps, type SuggestedPrompt, type TableColumn, type TableWidget, type Thread, Threads, type ThreadsProps, type UseAptevaKitReturn, type Widget, Widgets, type WidgetsProps, aptevaClient, cn, getThemeScript, mockMessages, mockThreads, mockWidgets };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import * as react from 'react';
1
2
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
3
  import { ClassValue } from 'clsx';
3
4
 
@@ -363,7 +364,17 @@ interface UseAptevaKitReturn {
363
364
  error: Error | null;
364
365
  }
365
366
 
366
- declare function Chat({ agentId, threadId, initialMessages, context, apiUrl, apiKey, useMock, initialMode, showModeToggle, onModeChange, commandVariant, planMode, onPlanModeChange, enableStreaming, showProgress, loadingText, welcomeTitle, welcomeSubtitle, welcomeIcon, suggestedPrompts, welcomeVariant, onThreadChange, onMessageSent, onAction, onFileUpload, onComplete, onError, onToolResult, placeholder, showHeader, headerTitle, enableWidgets, availableWidgets, compactWidgetContext, onWidgetRender, className, }: ChatProps): react_jsx_runtime.JSX.Element;
367
+ interface ChatHandle {
368
+ /** Send a message programmatically (as if the user typed it) */
369
+ sendMessage: (text: string) => Promise<void>;
370
+ /** Send a system/background message (not shown as user message, just triggers agent) */
371
+ sendSystemMessage: (text: string) => Promise<void>;
372
+ /** Get current messages */
373
+ getMessages: () => Message[];
374
+ /** Clear all messages */
375
+ clearMessages: () => void;
376
+ }
377
+ declare const Chat: react.ForwardRefExoticComponent<ChatProps & react.RefAttributes<ChatHandle>>;
367
378
 
368
379
  declare function Command({ agentId, command: initialCommand, context, autoExecute, allowInput, placeholder, submitButtonText, variant, useMock, planMode, onPlanModeChange, enableFileUpload, onStart, onProgress, onChunk, onComplete, onError, onFileUpload, onAction, loadingText, showProgress, enableStreaming, resultRenderer, className, }: CommandProps): react_jsx_runtime.JSX.Element;
369
380
 
@@ -474,4 +485,4 @@ declare const mockMessages: Message[];
474
485
  declare const mockThreads: Thread[];
475
486
  declare const mockWidgets: Widget[];
476
487
 
477
- export { type Action, type ActionEvent, AptevaClient, type AptevaClientConfig, type AptevaKitControl, Button, type ButtonGroupWidget, type ButtonWidget, Card, type CardWidget, type ChartWidget, Chat, type ChatMessage, type ChatProps, type ChatRequest, type ChatResponse, Command, type CommandProps, type CommandResult, type FormField, type FormWidget, type GalleryWidget, type ImageWidget, List, type ListItem, type ListWidget, type MapWidget, type Message, Prompt, type PromptProps, type SendMessageParams, Stream, type StreamChunk, type StreamProps, type SuggestedPrompt, type TableColumn, type TableWidget, type Thread, Threads, type ThreadsProps, type UseAptevaKitReturn, type Widget, Widgets, type WidgetsProps, aptevaClient, cn, getThemeScript, mockMessages, mockThreads, mockWidgets };
488
+ export { type Action, type ActionEvent, AptevaClient, type AptevaClientConfig, type AptevaKitControl, Button, type ButtonGroupWidget, type ButtonWidget, Card, type CardWidget, type ChartWidget, Chat, type ChatHandle, type ChatMessage, type ChatProps, type ChatRequest, type ChatResponse, Command, type CommandProps, type CommandResult, type FormField, type FormWidget, type GalleryWidget, type ImageWidget, List, type ListItem, type ListWidget, type MapWidget, type Message, Prompt, type PromptProps, type SendMessageParams, Stream, type StreamChunk, type StreamProps, type SuggestedPrompt, type TableColumn, type TableWidget, type Thread, Threads, type ThreadsProps, type UseAptevaKitReturn, type Widget, Widgets, type WidgetsProps, aptevaClient, cn, getThemeScript, mockMessages, mockThreads, mockWidgets };
package/dist/index.js CHANGED
@@ -2256,7 +2256,7 @@ var aptevaClient = new AptevaClient();
2256
2256
 
2257
2257
  // src/components/Chat/Chat.tsx
2258
2258
 
2259
- function Chat({
2259
+ var Chat = _react.forwardRef.call(void 0, function Chat2({
2260
2260
  agentId,
2261
2261
  threadId,
2262
2262
  initialMessages = [],
@@ -2299,7 +2299,7 @@ function Chat({
2299
2299
  compactWidgetContext = false,
2300
2300
  onWidgetRender,
2301
2301
  className
2302
- }) {
2302
+ }, ref) {
2303
2303
  const [messages, setMessages] = _react.useState.call(void 0, initialMessages);
2304
2304
  const [isLoading, setIsLoading] = _react.useState.call(void 0, false);
2305
2305
  const [currentThreadId, setCurrentThreadId] = _react.useState.call(void 0, threadId || null);
@@ -2318,6 +2318,21 @@ function Chat({
2318
2318
  const [internalPlanMode, setInternalPlanMode] = _react.useState.call(void 0, planMode);
2319
2319
  const [showSettingsMenu, setShowSettingsMenu] = _react.useState.call(void 0, false);
2320
2320
  const fileInputRef = _react.useRef.call(void 0, null);
2321
+ const handleSendMessageRef = _react.useRef.call(void 0, null);
2322
+ _react.useImperativeHandle.call(void 0, ref, () => ({
2323
+ sendMessage: async (text) => {
2324
+ if (handleSendMessageRef.current) {
2325
+ await handleSendMessageRef.current(text);
2326
+ }
2327
+ },
2328
+ sendSystemMessage: async (text) => {
2329
+ if (handleSendMessageRef.current) {
2330
+ await handleSendMessageRef.current(text, void 0, true);
2331
+ }
2332
+ },
2333
+ getMessages: () => messages,
2334
+ clearMessages: () => setMessages([])
2335
+ }), [messages]);
2321
2336
  const effectiveContext = _react.useMemo.call(void 0, () => {
2322
2337
  if (!enableWidgets) return context;
2323
2338
  const widgetContext = compactWidgetContext ? generateCompactWidgetContext(availableWidgets) : generateWidgetContext(availableWidgets);
@@ -2360,19 +2375,21 @@ ${widgetContext}` : widgetContext;
2360
2375
  }
2361
2376
  };
2362
2377
  const defaultPlaceholder = mode === "chat" ? "Type a message..." : "Enter your command...";
2363
- const handleSendMessage = async (text, files) => {
2378
+ const handleSendMessage = async (text, files, isSystem) => {
2364
2379
  const hasFiles = files && files.length > 0;
2365
2380
  const fileNames = hasFiles ? files.map((f) => f.name) : [];
2366
2381
  const displayContent = hasFiles ? `${text}${text ? "\n" : ""}[Attached: ${fileNames.join(", ")}]` : text;
2367
- const userMessage = {
2368
- id: `msg-${Date.now()}`,
2369
- role: "user",
2370
- content: displayContent,
2371
- timestamp: /* @__PURE__ */ new Date(),
2372
- metadata: hasFiles ? { attachments: fileNames } : void 0
2373
- };
2374
- setMessages((prev) => [...prev, userMessage]);
2375
- _optionalChain([onMessageSent, 'optionalCall', _58 => _58(userMessage)]);
2382
+ if (!isSystem) {
2383
+ const userMessage = {
2384
+ id: `msg-${Date.now()}`,
2385
+ role: "user",
2386
+ content: displayContent,
2387
+ timestamp: /* @__PURE__ */ new Date(),
2388
+ metadata: hasFiles ? { attachments: fileNames } : void 0
2389
+ };
2390
+ setMessages((prev) => [...prev, userMessage]);
2391
+ _optionalChain([onMessageSent, 'optionalCall', _58 => _58(userMessage)]);
2392
+ }
2376
2393
  setIsLoading(true);
2377
2394
  try {
2378
2395
  const messagePayload = await buildMessageWithAttachments(text, files);
@@ -2561,6 +2578,7 @@ ${widgetContext}` : widgetContext;
2561
2578
  setIsLoading(false);
2562
2579
  }
2563
2580
  };
2581
+ handleSendMessageRef.current = handleSendMessage;
2564
2582
  const executeCommand = async (commandOverride, files) => {
2565
2583
  const currentCommand = commandOverride || commandInput;
2566
2584
  if (!currentCommand.trim() && (!files || files.length === 0)) {
@@ -2858,7 +2876,7 @@ ${planToExecute}`;
2858
2876
  `
2859
2877
  } })
2860
2878
  ] });
2861
- }
2879
+ });
2862
2880
 
2863
2881
  // src/components/Chat/CommandOutput.tsx
2864
2882