@cadraos/sdk 0.1.6 → 0.1.8

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.
@@ -1,6 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { Components } from 'react-markdown';
3
3
  import * as React$1 from 'react';
4
+ import React__default from 'react';
4
5
 
5
6
  interface MarkdownContentProps {
6
7
  /** Markdown content to render */
@@ -188,11 +189,19 @@ interface AttachmentFile {
188
189
  /** Original file object */
189
190
  file: File;
190
191
  /** Upload status */
191
- status: "pending" | "uploading" | "ready" | "failed";
192
+ status: "pending" | "uploading" | "processing" | "ready" | "error" | "failed";
192
193
  /** Preview URL for local display */
193
194
  previewUrl?: string;
194
195
  /** Progress percentage (0-100) */
195
- progress?: number;
196
+ progress: number;
197
+ /** File category */
198
+ category: "document" | "image" | "audio";
199
+ /** Error message when status is "error" */
200
+ error?: string;
201
+ /** Whether a thumbnail has been generated */
202
+ hasThumbnail?: boolean;
203
+ /** Override file.size for external attachments where actual File is empty */
204
+ actualSize?: number;
196
205
  }
197
206
 
198
207
  interface ChatMessageProps {
@@ -370,7 +379,11 @@ interface ExecuteInput {
370
379
  context?: Record<string, unknown>;
371
380
  /** Attachment UUIDs to include with the message (for images, documents, etc.) */
372
381
  attachmentIds?: string[];
373
- /** Team UUID for team-based execution (routes to team's lead orchestrator) */
382
+ /**
383
+ * Team UUID for team-based execution (routes to team's lead orchestrator).
384
+ * @deprecated Pass the team UUID directly as the agent/entity ID instead.
385
+ * The platform now auto-detects whether a UUID is an agent, team, or tool.
386
+ */
374
387
  teamUuid?: string;
375
388
  /** Execution options */
376
389
  options?: ExecuteOptions;
@@ -1101,14 +1114,62 @@ interface ChatAdapter {
1101
1114
  /**
1102
1115
  * Get the SSE stream URL for an execution.
1103
1116
  *
1104
- * @deprecated Prefer implementing `createStream` which provides
1105
- * fetch-based SSE with auth headers. This is kept for backward
1106
- * compatibility with EventSource-based streaming.
1117
+ * @deprecated Use `subscribeToStream` instead which provides secure
1118
+ * header-based auth. This method exposes API keys in URLs which are
1119
+ * logged by browsers, proxies, and servers.
1107
1120
  *
1108
1121
  * @param executionId - Execution UUID
1109
1122
  * @returns Full URL for SSE connection
1110
1123
  */
1111
1124
  getStreamUrl?(executionId: string): string;
1125
+ /**
1126
+ * Subscribe to SSE stream for an execution using header-based auth.
1127
+ *
1128
+ * Uses @microsoft/fetch-event-source for SSE with Authorization header.
1129
+ * This is the secure alternative to getStreamUrl() which exposed API keys
1130
+ * in URLs.
1131
+ *
1132
+ * @param executionId - Execution UUID to stream
1133
+ * @param callbacks - Event callbacks
1134
+ * @returns Cleanup function to unsubscribe
1135
+ *
1136
+ * @example
1137
+ * ```typescript
1138
+ * const unsubscribe = adapter.subscribeToStream(executionId, {
1139
+ * onEvent: (event) => console.log(event),
1140
+ * onError: (error) => console.error(error),
1141
+ * onComplete: () => console.log('Done'),
1142
+ * });
1143
+ *
1144
+ * // Later, to stop streaming:
1145
+ * unsubscribe();
1146
+ * ```
1147
+ */
1148
+ subscribeToStream?(executionId: string, callbacks: StreamSubscriptionCallbacks): () => void;
1149
+ }
1150
+ /**
1151
+ * SSE event received from the stream
1152
+ */
1153
+ interface StreamEvent {
1154
+ /** Event type (progress, tool_call, complete, failed, etc.) */
1155
+ type: string;
1156
+ /** Event ID for reconnection */
1157
+ id?: string;
1158
+ /** Event data payload */
1159
+ data: unknown;
1160
+ }
1161
+ /**
1162
+ * Callbacks for subscribeToStream
1163
+ */
1164
+ interface StreamSubscriptionCallbacks {
1165
+ /** Called for each SSE event received */
1166
+ onEvent: (event: StreamEvent) => void;
1167
+ /** Called when an error occurs */
1168
+ onError?: (error: Error) => void;
1169
+ /** Called when the stream completes (terminal event received) */
1170
+ onComplete?: () => void;
1171
+ /** Called when connection state changes */
1172
+ onConnectionChange?: (connected: boolean) => void;
1112
1173
  }
1113
1174
 
1114
1175
  interface AgentChatProps {
@@ -1167,7 +1228,7 @@ interface AgentChatProps {
1167
1228
  className?: string;
1168
1229
  /** Theme mode */
1169
1230
  theme?: ThemeMode;
1170
- /** Enable file attachments (future feature) */
1231
+ /** Enable file attachments */
1171
1232
  enableAttachments?: boolean;
1172
1233
  /** Enable markdown rendering */
1173
1234
  enableMarkdown?: boolean;
@@ -1195,6 +1256,7 @@ interface AgentChatProps {
1195
1256
  * <ChatConfigProvider config={{ baseUrl: '...', apiKey: '...' }}>
1196
1257
  * <AgentChat
1197
1258
  * agentId="agent-uuid"
1259
+ * enableAttachments
1198
1260
  * onMessage={(msg) => console.log('New message:', msg)}
1199
1261
  * />
1200
1262
  * </ChatConfigProvider>
@@ -2711,9 +2773,9 @@ declare class AISaaSClient {
2711
2773
  }
2712
2774
 
2713
2775
  /**
2714
- * Default adapter for ChatAdapter — thin wrapper around AISaaSClient
2776
+ * Default adapter for ChatAdapter — thin wrapper around CadraClient
2715
2777
  *
2716
- * Uses the AISaaSClient for all operations, providing proper auth,
2778
+ * Uses the CadraClient for all operations, providing proper auth,
2717
2779
  * retries, and streaming support out of the box.
2718
2780
  *
2719
2781
  * @module @cadraos/sdk/chat
@@ -2724,7 +2786,7 @@ declare class AISaaSClient {
2724
2786
  */
2725
2787
  interface DefaultAdapterConfig {
2726
2788
  /**
2727
- * Pre-constructed AISaaSClient (takes priority over individual options)
2789
+ * Pre-constructed CadraClient (takes priority over individual options)
2728
2790
  */
2729
2791
  client?: AISaaSClient;
2730
2792
  /**
@@ -2750,10 +2812,10 @@ interface DefaultAdapterConfig {
2750
2812
  orgId?: number;
2751
2813
  }
2752
2814
  /**
2753
- * Create a default adapter that wraps AISaaSClient
2815
+ * Create a default adapter that wraps CadraClient
2754
2816
  *
2755
2817
  * @param config - Adapter configuration
2756
- * @returns ChatAdapter implementation backed by AISaaSClient
2818
+ * @returns ChatAdapter implementation backed by CadraClient
2757
2819
  *
2758
2820
  * @example
2759
2821
  * ```typescript
@@ -2855,6 +2917,13 @@ interface UseAgentChatOptions {
2855
2917
  /** Callback fired when clarification is needed */
2856
2918
  onClarification?: (data: ClarificationData) => void;
2857
2919
  }
2920
+ /**
2921
+ * Options for sendMessage
2922
+ */
2923
+ interface SendMessageOptions {
2924
+ /** UUIDs of attached files to include with the message */
2925
+ attachmentUuids?: string[];
2926
+ }
2858
2927
  interface UseAgentChatResult {
2859
2928
  /** Current messages in the chat */
2860
2929
  messages: ChatMessage$1[];
@@ -2871,7 +2940,7 @@ interface UseAgentChatResult {
2871
2940
  /** Current clarification request if any */
2872
2941
  clarification: ClarificationData | null;
2873
2942
  /** Send a message to the agent */
2874
- sendMessage: (content: string) => Promise<void>;
2943
+ sendMessage: (content: string, options?: SendMessageOptions) => Promise<void>;
2875
2944
  /** Respond to a clarification request */
2876
2945
  respondToClarification: (response: string) => Promise<void>;
2877
2946
  /** Cancel the current execution */
@@ -2978,6 +3047,122 @@ interface UseExecutionStreamResult {
2978
3047
  */
2979
3048
  declare function useExecutionStream(options: UseExecutionStreamOptions): UseExecutionStreamResult;
2980
3049
 
3050
+ /**
3051
+ * FileDropZone - Reusable file upload component with drag-and-drop
3052
+ *
3053
+ * Supports drag-and-drop file upload with visual feedback, file validation,
3054
+ * image compression, upload progress tracking, and thumbnail previews.
3055
+ *
3056
+ * Two modes:
3057
+ * - Standalone: renders a drop zone UI (default)
3058
+ * - Wrapper: wraps children with a drag-drop overlay (when children provided)
3059
+ *
3060
+ * @packageDocumentation
3061
+ */
3062
+
3063
+ interface FileDropZoneProps {
3064
+ files: AttachmentFile[];
3065
+ onFilesChange: (files: AttachmentFile[]) => void;
3066
+ /** Upload a file. Return the UUID and presigned URL. If uploadUrl is empty, the S3 PUT step is skipped. */
3067
+ onUpload: (file: File, metadata: {
3068
+ filename: string;
3069
+ mimeType: string;
3070
+ size: number;
3071
+ }) => Promise<{
3072
+ uuid: string;
3073
+ uploadUrl: string;
3074
+ }>;
3075
+ /** Confirm the upload after S3 PUT succeeds */
3076
+ onConfirmUpload?: (uuid: string) => Promise<void>;
3077
+ /** Error callback instead of toast */
3078
+ onError?: (message: string) => void;
3079
+ maxFiles?: number;
3080
+ maxTotalSizeMB?: number;
3081
+ disabled?: boolean;
3082
+ className?: string;
3083
+ /** Restrict accepted file types, e.g. "image/*" */
3084
+ accept?: string;
3085
+ /** Compact mode for embedding in small panels */
3086
+ compact?: boolean;
3087
+ children?: React__default.ReactNode;
3088
+ }
3089
+ /** Ref interface for programmatic access to FileDropZone */
3090
+ interface FileDropZoneRef {
3091
+ /** Trigger the file selection dialog */
3092
+ openFileDialog: () => void;
3093
+ }
3094
+ declare const FileDropZone: React__default.ForwardRefExoticComponent<FileDropZoneProps & React__default.RefAttributes<FileDropZoneRef>>;
3095
+
3096
+ interface UseFileAttachmentsOptions {
3097
+ /**
3098
+ * Upload handler called immediately when files are dropped/selected.
3099
+ * Return the UUID and a presigned upload URL.
3100
+ * If uploadUrl is empty, the S3 PUT step in FileDropZone is skipped
3101
+ * (useful for direct-upload patterns where the upload happens here).
3102
+ */
3103
+ onUpload: (file: File, metadata: {
3104
+ filename: string;
3105
+ mimeType: string;
3106
+ size: number;
3107
+ }) => Promise<{
3108
+ uuid: string;
3109
+ uploadUrl: string;
3110
+ }>;
3111
+ /** Optional confirm callback after S3 PUT succeeds */
3112
+ onConfirmUpload?: (uuid: string) => Promise<void>;
3113
+ /**
3114
+ * Deferred upload handler called during prepareForSubmit().
3115
+ * Use this for two-phase upload patterns where files are uploaded to local
3116
+ * storage on drop, but a second upload to an AI service happens on submit.
3117
+ *
3118
+ * Receives the file and localUuid (from onUpload) and should return
3119
+ * the AI service's attachment UUID.
3120
+ *
3121
+ * If not provided, prepareForSubmit() returns the UUIDs from onUpload as-is.
3122
+ */
3123
+ onSubmitUpload?: (file: File, localUuid: string, metadata: {
3124
+ filename: string;
3125
+ mimeType: string;
3126
+ size: number;
3127
+ }) => Promise<string>;
3128
+ /** Error handler */
3129
+ onError?: (message: string) => void;
3130
+ /** Maximum number of files (default: 10) */
3131
+ maxFiles?: number;
3132
+ /** Maximum total upload size in MB (default: 100) */
3133
+ maxTotalSizeMB?: number;
3134
+ }
3135
+ interface UseFileAttachmentsResult {
3136
+ /** Current attachment files */
3137
+ files: AttachmentFile[];
3138
+ /**
3139
+ * Props to spread onto FileDropZone.
3140
+ * Includes: files, onFilesChange, onUpload, onConfirmUpload, onError, maxFiles, maxTotalSizeMB
3141
+ */
3142
+ dropZoneProps: Pick<FileDropZoneProps, "files" | "onFilesChange" | "onUpload" | "onConfirmUpload" | "onError" | "maxFiles" | "maxTotalSizeMB">;
3143
+ /** Remove a file by UUID */
3144
+ removeFile: (uuid: string) => void;
3145
+ /** Get UUIDs of ready (uploaded) attachments — for Cadra adapter pattern */
3146
+ getReadyUuids: () => string[];
3147
+ /** Get UUIDs of ready attachments as URLs — for direct-upload pattern where uuid IS the url */
3148
+ getReadyUrls: () => string[];
3149
+ /**
3150
+ * Two-phase submit: uploads ready files to the AI service via onSubmitUpload,
3151
+ * returns the AI service attachment UUIDs. Call this on Generate/Remix.
3152
+ * If onSubmitUpload is not configured, returns getReadyUuids().
3153
+ */
3154
+ prepareForSubmit: () => Promise<string[]>;
3155
+ /** Clear all attachments (revokes preview URLs) */
3156
+ clear: () => void;
3157
+ /** Whether any files are currently uploading */
3158
+ isUploading: boolean;
3159
+ /** Whether there are files ready to send */
3160
+ hasReadyFiles: boolean;
3161
+ /** Total number of files */
3162
+ fileCount: number;
3163
+ }
3164
+ declare function useFileAttachments(options: UseFileAttachmentsOptions): UseFileAttachmentsResult;
3165
+
2981
3166
  interface ChatContainerProps {
2982
3167
  /** Child components (MessageList, ChatInput, etc.) */
2983
3168
  children: React$1.ReactNode;
@@ -3014,6 +3199,14 @@ interface ChatInputProps {
3014
3199
  isLoading?: boolean;
3015
3200
  /** Whether to enable attachments */
3016
3201
  enableAttachments?: boolean;
3202
+ /** Current attachment files (when enableAttachments is true) */
3203
+ attachments?: AttachmentFile[];
3204
+ /** Callback to remove an attachment */
3205
+ onRemoveAttachment?: (uuid: string) => void;
3206
+ /** Ref to FileDropZone for triggering file dialog */
3207
+ dropZoneRef?: React$1.RefObject<FileDropZoneRef | null>;
3208
+ /** Whether attachments are currently uploading */
3209
+ isUploadingAttachments?: boolean;
3017
3210
  /** Additional CSS classes */
3018
3211
  className?: string;
3019
3212
  }
@@ -3031,7 +3224,7 @@ interface ChatInputProps {
3031
3224
  * />
3032
3225
  * ```
3033
3226
  */
3034
- declare function ChatInput({ onSend, onStop, placeholder, disabled, isLoading, enableAttachments, className, }: ChatInputProps): react_jsx_runtime.JSX.Element;
3227
+ declare function ChatInput({ onSend, onStop, placeholder, disabled, isLoading, enableAttachments, attachments, onRemoveAttachment, dropZoneRef, isUploadingAttachments, className, }: ChatInputProps): react_jsx_runtime.JSX.Element;
3035
3228
 
3036
3229
  interface ToolCallEntryProps {
3037
3230
  /** Tool call data */
@@ -3163,4 +3356,25 @@ declare function HelpCircleIcon({ className, ...props }: IconProps): react_jsx_r
3163
3356
  declare function DatabaseIcon({ className, ...props }: IconProps): react_jsx_runtime.JSX.Element;
3164
3357
  declare function ClockIcon({ className, ...props }: IconProps): react_jsx_runtime.JSX.Element;
3165
3358
 
3166
- export { AgentChat, type AgentChatProps, AlertCircleIcon, type Artifact$1 as Artifact, AskUserPrompt, type AskUserPromptProps, type AttachmentData, type AttachmentFile, BotIcon, type ChatAdapter, ChatConfigProvider, type ChatConfigProviderProps, ChatContainer, type ChatContainerProps, type ChatError, ChatInput, type ChatInputProps, ChatMessage, type ChatMessageProps, type ChatMessage$1 as ChatMessageType, CheckCircleIcon, CheckIcon, ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, CircleIcon, type ClarificationData, ClockIcon, CodeIcon, CopyIcon, DatabaseIcon, type DefaultAdapterConfig, DownloadIcon, type Execution, type ExecutionResult, type ExecutionStreamEvent, ExternalLinkIcon, FileIcon, FileTextIcon, HelpCircleIcon, type HistoryMessage, type IconProps, ImageIcon, ImagesIcon, type ListSessionsInput, ListTodoIcon, LoadingSpinner, MarkdownContent, type MarkdownContentProps, Maximize2Icon, MessageCircleIcon, MessageList, type MessageListProps, Minimize2Icon, PaperclipIcon, SendIcon, type SendMessageInput$1 as SendMessageInput, type SessionHistory$1 as SessionHistory, type SessionList, type SessionListItem, SparklesIcon, type StartExecutionInput, StopCircleIcon, type ThemeMode, type ThinkingBlock, type TodoItem, TodoList, type TodoListProps, type ToolCall, ToolCallEntry, type ToolCallEntryProps, type UploadUrlInput, type UploadUrlResult, type UseAgentChatOptions, type UseAgentChatResult, type UseExecutionStreamOptions, type UseExecutionStreamResult, UserIcon, XIcon, ZoomInIcon, ZoomOutIcon, createDefaultAdapter, useAgentChat, useChatConfig, useChatConfigOptional, useExecutionStream };
3359
+ /**
3360
+ * Client-side image compression using Canvas API.
3361
+ *
3362
+ * Resizes images to max 1920px on longest side and iteratively
3363
+ * reduces JPEG/WebP quality to hit a ~150KB target size.
3364
+ * Skips SVGs, non-image files, and files already under the target.
3365
+ */
3366
+ /**
3367
+ * Compress an image file to approximately targetSizeKB using Canvas API.
3368
+ *
3369
+ * - Returns the original file if it's already under targetSizeKB
3370
+ * - Skips SVGs and non-image files (returns as-is)
3371
+ * - Resizes to max 1920px on longest side
3372
+ * - Iteratively reduces quality to approach target size
3373
+ *
3374
+ * @param file - The File to compress
3375
+ * @param targetSizeKB - Target output size in KB (default: 150)
3376
+ * @returns Compressed File, or the original if no compression needed
3377
+ */
3378
+ declare function compressImage(file: File, targetSizeKB?: number): Promise<File>;
3379
+
3380
+ export { AgentChat, type AgentChatProps, AlertCircleIcon, type Artifact$1 as Artifact, AskUserPrompt, type AskUserPromptProps, type AttachmentData, type AttachmentFile, BotIcon, type ChatAdapter, ChatConfigProvider, type ChatConfigProviderProps, ChatContainer, type ChatContainerProps, type ChatError, ChatInput, type ChatInputProps, ChatMessage, type ChatMessageProps, type ChatMessage$1 as ChatMessageType, CheckCircleIcon, CheckIcon, ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, CircleIcon, type ClarificationData, ClockIcon, CodeIcon, CopyIcon, DatabaseIcon, type DefaultAdapterConfig, DownloadIcon, type Execution, type ExecutionResult, type ExecutionStreamEvent, ExternalLinkIcon, FileDropZone, type FileDropZoneProps, type FileDropZoneRef, FileIcon, FileTextIcon, HelpCircleIcon, type HistoryMessage, type IconProps, ImageIcon, ImagesIcon, type ListSessionsInput, ListTodoIcon, LoadingSpinner, MarkdownContent, type MarkdownContentProps, Maximize2Icon, MessageCircleIcon, MessageList, type MessageListProps, Minimize2Icon, PaperclipIcon, SendIcon, type SendMessageInput$1 as SendMessageInput, type SendMessageOptions, type SessionHistory$1 as SessionHistory, type SessionList, type SessionListItem, SparklesIcon, type StartExecutionInput, StopCircleIcon, type ThemeMode, type ThinkingBlock, type TodoItem, TodoList, type TodoListProps, type ToolCall, ToolCallEntry, type ToolCallEntryProps, type UploadUrlInput, type UploadUrlResult, type UseAgentChatOptions, type UseAgentChatResult, type UseExecutionStreamOptions, type UseExecutionStreamResult, type UseFileAttachmentsOptions, type UseFileAttachmentsResult, UserIcon, XIcon, ZoomInIcon, ZoomOutIcon, compressImage, createDefaultAdapter, useAgentChat, useChatConfig, useChatConfigOptional, useExecutionStream, useFileAttachments };