@magemetrics/ai 0.11.3 → 0.11.5

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.
@@ -6,6 +6,7 @@ import { DirectAuthProvider } from '@magemetrics/core';
6
6
  import { ExternalAuthProvider } from '@magemetrics/core';
7
7
  import { ExternalAuthProviderConfig } from '@magemetrics/core';
8
8
  import { FetchNextPageOptions } from '@tanstack/react-query';
9
+ import { FileUIPart } from 'ai';
9
10
  import { ForwardRefExoticComponent } from 'react';
10
11
  import { InfiniteData } from '@tanstack/react-query';
11
12
  import { InfiniteQueryObserverResult } from '@tanstack/react-query';
@@ -92,6 +93,7 @@ declare interface ChatComponent extends default_2.MemoExoticComponent<(props: Ch
92
93
  export declare interface ChatContextValue {
93
94
  flowId: string | undefined | null;
94
95
  enableSpeechToText?: boolean;
96
+ enableFileUpload?: boolean;
95
97
  }
96
98
 
97
99
  /**
@@ -142,9 +144,10 @@ export declare interface ChatInputContextValue {
142
144
  isAwaitingUserAnswer: boolean;
143
145
  onRetry?: () => void;
144
146
  onStop?: () => void;
145
- sendMessage: (text: string, isEditing: boolean) => void;
147
+ sendMessage: (text: string, isEditing: boolean, files?: FileUIPart[]) => void;
146
148
  lastUserMessage?: string;
147
149
  enableSpeechToText?: boolean;
150
+ enableFileUpload?: boolean;
148
151
  }
149
152
 
150
153
  declare const ChatInputDefault: default_2.FC;
@@ -152,6 +155,7 @@ declare const ChatInputDefault: default_2.FC;
152
155
  declare interface ChatProps {
153
156
  flowId: string | undefined | null;
154
157
  enableSpeechToText?: boolean;
158
+ enableFileUpload?: boolean;
155
159
  children?: default_2.ReactNode;
156
160
  }
157
161
 
@@ -205,6 +209,7 @@ declare interface ConfigurableChatComponent extends default_2.FC<ConfigurableCha
205
209
  declare type ConfigurableChatComponentProps = {
206
210
  flowId: string | undefined | null;
207
211
  enableSpeechToText?: boolean;
212
+ enableFileUpload?: boolean;
208
213
  disableCanvas?: boolean;
209
214
  children?: default_2.ReactNode;
210
215
  /**
@@ -214,6 +219,15 @@ declare type ConfigurableChatComponentProps = {
214
219
  appearance?: AppearanceConfig;
215
220
  };
216
221
 
222
+ /** Context usage — the modal reuses an ancestor `MageMetricsContextProvider`. */
223
+ declare type ContextManagedModalProps = ManagedModalInnerProps & {
224
+ apiKey?: never;
225
+ externalJwt?: never;
226
+ apiUrl?: never;
227
+ components?: never;
228
+ applicationName?: never;
229
+ };
230
+
217
231
  /** @deprecated This type is no longer used and will be removed in a future version. */
218
232
  declare type ControlledModalProps = {
219
233
  visible: boolean;
@@ -227,6 +241,7 @@ declare interface ConversationContentProps {
227
241
  topBar?: React.ReactNode;
228
242
  disableCanvas?: boolean;
229
243
  enableSpeechToText?: boolean;
244
+ enableFileUpload?: boolean;
230
245
  children?: React.ReactNode;
231
246
  }
232
247
 
@@ -271,6 +286,51 @@ export { ExternalAuthProvider }
271
286
 
272
287
  export { ExternalAuthProviderConfig }
273
288
 
289
+ export declare interface FileAttachment {
290
+ /** Unique ID for this attachment (for React keys and removal) */
291
+ id: string;
292
+ /** Original file name */
293
+ filename: string;
294
+ /** File size in bytes */
295
+ size: number;
296
+ /** The FileUIPart ready to be sent via sendMessage */
297
+ filePart: FileUIPart;
298
+ /** Validation error, if any */
299
+ error?: string;
300
+ }
301
+
302
+ export declare interface FileUploadConfig {
303
+ /** Maximum file size per file in bytes. Default: 10 * 1024 * 1024 (10 MB) */
304
+ maxFileSize?: number;
305
+ /** Maximum combined file size in bytes. Default: 20 * 1024 * 1024 (20 MB) */
306
+ maxCombinedSize?: number;
307
+ }
308
+
309
+ export declare interface FileUploadController {
310
+ /** Currently attached files (valid and invalid) */
311
+ attachments: FileAttachment[];
312
+ /** Whether all attachments are valid and ready to send */
313
+ isReady: boolean;
314
+ /** Whether any file is currently being read (FileReader in progress) */
315
+ isProcessing: boolean;
316
+ /** Total size of all valid attachments in bytes */
317
+ totalSize: number;
318
+ /** Combined size limit error, if total exceeds maxCombinedSize */
319
+ combinedSizeError?: string;
320
+ /** Add files from a FileList (e.g., from an input[type=file]) */
321
+ addFiles: (files: FileList) => void;
322
+ /** Remove a specific attachment by ID */
323
+ removeFile: (id: string) => void;
324
+ /** Clear all attachments */
325
+ clearFiles: () => void;
326
+ /** Get all valid FileUIParts for sendMessage */
327
+ getFileParts: () => FileUIPart[];
328
+ /** Open the native file picker (programmatic trigger) */
329
+ openFilePicker: () => void;
330
+ /** Ref to attach to a hidden file input element */
331
+ fileInputRef: React.RefObject<HTMLInputElement | null>;
332
+ }
333
+
274
334
  /**
275
335
  * This module handles the formatting and normalization of table cell values for display and sorting.
276
336
  *
@@ -450,23 +510,18 @@ declare type MageMetricsPublicContextProviderProps = PropsWithChildren<Pick<Mage
450
510
 
451
511
  export declare const ManagedModal: React.FC<ManagedModalProps>;
452
512
 
453
- declare type ManagedModalBaseProps = ModalProps & {
454
- /** API key for authenticating with the MageMetrics service */
455
- apiKey: string;
456
- /** External JWT token for user authentication */
457
- externalJwt: string;
458
- /** Base URL for the MageMetrics API */
459
- apiUrl: string;
513
+ /**
514
+ * Props shared by both standalone and context-aware usage of `ManagedModal`.
515
+ * These are the props that `ManagedModalInner` actually consumes — they have
516
+ * nothing to do with provider initialisation.
517
+ */
518
+ declare type ManagedModalInnerProps = ModalProps & {
460
519
  /** Whether to disable canvas functionality in conversations */
461
520
  disableCanvas?: boolean;
462
521
  /** Whether to render data freshness info in the conversation header */
463
522
  showDataFreshness?: boolean;
464
523
  /** Where to persist modal state (localStorage, queryParam, or none) */
465
524
  persist?: PersistenceOptions;
466
- /** Custom component overrides for extending functionality */
467
- components?: Components;
468
- /** Application name to associate with flows created through this modal */
469
- applicationName?: string;
470
525
  /**
471
526
  * Appearance configuration for customizing the visual style.
472
527
  * Includes brand colors and modal-specific styling options.
@@ -479,10 +534,7 @@ declare type ManagedModalBaseProps = ModalProps & {
479
534
  };
480
535
  };
481
536
 
482
- /**
483
- * Props for ManagedModal component.
484
- */
485
- declare type ManagedModalProps = ManagedModalBaseProps;
537
+ declare type ManagedModalProps = StandaloneManagedModalProps | ContextManagedModalProps;
486
538
 
487
539
  declare const MessagesContainer: default_2.FC;
488
540
 
@@ -610,6 +662,32 @@ export declare const StandaloneDataTable: React.FC<{
610
662
  onStateChange?: (state: DataTableState) => void;
611
663
  }>;
612
664
 
665
+ /**
666
+ * Props for ManagedModal component.
667
+ *
668
+ * When rendered inside a `MageMetricsContextProvider`, the modal reuses the
669
+ * parent context instead of creating a duplicate. In that case `apiKey`,
670
+ * `externalJwt`, `apiUrl`, `components`, and `applicationName` must **not**
671
+ * be passed (they are inherited from the parent provider).
672
+ *
673
+ * When rendered standalone (no parent context), `apiKey`, `externalJwt`, and
674
+ * `apiUrl` are **required**, and `components`/`applicationName` may optionally
675
+ * be provided.
676
+ */
677
+ /** Standalone usage — the modal creates its own `MageMetricsContextProvider`. */
678
+ declare type StandaloneManagedModalProps = ManagedModalInnerProps & {
679
+ /** API key for authenticating with the MageMetrics service */
680
+ apiKey: string;
681
+ /** External JWT token for user authentication */
682
+ externalJwt: string;
683
+ /** Base URL for the MageMetrics API */
684
+ apiUrl: string;
685
+ /** Custom component overrides for extending functionality */
686
+ components?: Components;
687
+ /** Application name to associate with flows created through this modal */
688
+ applicationName?: string;
689
+ };
690
+
613
691
  declare type StartOptions = DisplayControlProps & {
614
692
  /** Label text displayed above the chat launcher input */
615
693
  label?: string;
@@ -619,6 +697,8 @@ declare type StartOptions = DisplayControlProps & {
619
697
  autoFocus?: boolean;
620
698
  /** Whether speech-to-text controls should be shown */
621
699
  enableSpeechToText?: boolean;
700
+ /** Whether file upload should be enabled in the chat input */
701
+ enableFileUpload?: boolean;
622
702
  };
623
703
 
624
704
  declare type TableFilters = Record<string, TableFilterValue>;
@@ -928,6 +1008,8 @@ export declare const useDownloadReportData: (options?: UseMutationOptions<Export
928
1008
  mutateAsync: UseMutateAsyncFunction<ExportReportDataResult, Error, ExportReportDataParams, unknown>;
929
1009
  };
930
1010
 
1011
+ export declare function useFileUpload(config?: FileUploadConfig): FileUploadController;
1012
+
931
1013
  export declare const useMageMetricsApiUrl: () => string;
932
1014
 
933
1015
  export declare const useMageMetricsClient: () => MageMetricsClient;
@@ -1083,22 +1165,13 @@ withTitle: boolean;
1083
1165
  exportingEnabled?: boolean;
1084
1166
  } & RefAttributes<HTMLDivElement>>;
1085
1167
 
1086
- export declare type WebComponentManagedModalProps = ManagedModalProps & {
1168
+ export declare type WebComponentManagedModalProps = StandaloneManagedModalProps & {
1087
1169
  enableCsvDownload: boolean;
1088
1170
  };
1089
1171
 
1090
1172
  export { }
1091
1173
 
1092
1174
 
1093
- declare module "react" {
1094
- namespace JSX {
1095
- interface IntrinsicElements {
1096
- "magemetrics-ai": WebComponentManagedModalProps;
1097
- }
1098
- }
1099
- }
1100
-
1101
-
1102
1175
  declare module "react" {
1103
1176
  namespace JSX {
1104
1177
  interface IntrinsicElements {