@e-llm-studio/instant-learning 1.3.16 → 1.3.18

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.
Files changed (99) hide show
  1. package/dist/ComponentRegistry.js +4 -0
  2. package/dist/ComponentRegistry.js.map +1 -1
  3. package/dist/cjs/ComponentRegistry.js +4 -0
  4. package/dist/cjs/ComponentRegistry.js.map +1 -1
  5. package/dist/cjs/features/IL-OTJ/ILOTJ.js +5 -1
  6. package/dist/cjs/features/IL-OTJ/ILOTJ.js.map +1 -1
  7. package/dist/cjs/features/IL-OTJ/ValueTypeWrappers/TeachMePlugin.js +13 -7
  8. package/dist/cjs/features/IL-OTJ/ValueTypeWrappers/TeachMePlugin.js.map +1 -1
  9. package/dist/cjs/features/IL-OTJ/ValueTypeWrappers/TeachMeWrapper.js +16 -9
  10. package/dist/cjs/features/IL-OTJ/ValueTypeWrappers/TeachMeWrapper.js.map +1 -1
  11. package/dist/cjs/features/IL-OTJ/_components/ChatComponents/ChatComponent.js +127 -20
  12. package/dist/cjs/features/IL-OTJ/_components/ChatComponents/ChatComponent.js.map +1 -1
  13. package/dist/cjs/features/IL-OTJ/_components/hooks/useVariantEditSession.js +21 -7
  14. package/dist/cjs/features/IL-OTJ/_components/hooks/useVariantEditSession.js.map +1 -1
  15. package/dist/cjs/features/IL-OTJ/helpers/utils.js +45 -1
  16. package/dist/cjs/features/IL-OTJ/helpers/utils.js.map +1 -1
  17. package/dist/cjs/features/IL-marketplace/components/GuidelineLibraryCard.js +1 -0
  18. package/dist/cjs/features/IL-marketplace/components/GuidelineLibraryCard.js.map +1 -1
  19. package/dist/cjs/features/IL-marketplace/components/GuidelineLibraryCard.module.css.js +2 -2
  20. package/dist/cjs/features/LearningManagement/components/InstantLearningModal.js +4 -0
  21. package/dist/cjs/features/LearningManagement/components/InstantLearningModal.js.map +1 -1
  22. package/dist/cjs/features/LearningManagement/components/InstantLearningModalDynamic.js +11 -3
  23. package/dist/cjs/features/LearningManagement/components/InstantLearningModalDynamic.js.map +1 -1
  24. package/dist/cjs/features/LearningManagement/store/useEnvStore.js +2 -0
  25. package/dist/cjs/features/LearningManagement/store/useEnvStore.js.map +1 -1
  26. package/dist/cjs/index.js +1 -0
  27. package/dist/cjs/index.js.map +1 -1
  28. package/dist/cjs/plugins/ValueTypes/Default/DefaultTeachMeRenderer.js +2 -1
  29. package/dist/cjs/plugins/ValueTypes/Default/DefaultTeachMeRenderer.js.map +1 -1
  30. package/dist/cjs/schema-driven/BPARenderer.js +7 -1
  31. package/dist/cjs/schema-driven/BPARenderer.js.map +1 -1
  32. package/dist/cjs/schema-driven/components/FileUploadField.js +782 -0
  33. package/dist/cjs/schema-driven/components/FileUploadField.js.map +1 -0
  34. package/dist/cjs/schema-driven/components/FileUploadField.module.css.js +12 -0
  35. package/dist/cjs/schema-driven/components/FileUploadField.module.css.js.map +1 -0
  36. package/dist/cjs/schema-driven/components/VariantListField.js +133 -11
  37. package/dist/cjs/schema-driven/components/VariantListField.js.map +1 -1
  38. package/dist/cjs/schema-driven/utils/fileUploadService.js +430 -0
  39. package/dist/cjs/schema-driven/utils/fileUploadService.js.map +1 -0
  40. package/dist/features/IL-OTJ/ILOTJ.js +5 -1
  41. package/dist/features/IL-OTJ/ILOTJ.js.map +1 -1
  42. package/dist/features/IL-OTJ/ValueTypeWrappers/TeachMePlugin.js +13 -7
  43. package/dist/features/IL-OTJ/ValueTypeWrappers/TeachMePlugin.js.map +1 -1
  44. package/dist/features/IL-OTJ/ValueTypeWrappers/TeachMeWrapper.js +16 -9
  45. package/dist/features/IL-OTJ/ValueTypeWrappers/TeachMeWrapper.js.map +1 -1
  46. package/dist/features/IL-OTJ/_components/ChatComponents/ChatComponent.js +127 -20
  47. package/dist/features/IL-OTJ/_components/ChatComponents/ChatComponent.js.map +1 -1
  48. package/dist/features/IL-OTJ/_components/hooks/useVariantEditSession.js +21 -8
  49. package/dist/features/IL-OTJ/_components/hooks/useVariantEditSession.js.map +1 -1
  50. package/dist/features/IL-OTJ/helpers/utils.js +45 -2
  51. package/dist/features/IL-OTJ/helpers/utils.js.map +1 -1
  52. package/dist/features/IL-marketplace/components/GuidelineLibraryCard.js +1 -0
  53. package/dist/features/IL-marketplace/components/GuidelineLibraryCard.js.map +1 -1
  54. package/dist/features/IL-marketplace/components/GuidelineLibraryCard.module.css.js +2 -2
  55. package/dist/features/LearningManagement/components/InstantLearningModal.js +4 -0
  56. package/dist/features/LearningManagement/components/InstantLearningModal.js.map +1 -1
  57. package/dist/features/LearningManagement/components/InstantLearningModalDynamic.js +11 -3
  58. package/dist/features/LearningManagement/components/InstantLearningModalDynamic.js.map +1 -1
  59. package/dist/features/LearningManagement/store/useEnvStore.js +2 -0
  60. package/dist/features/LearningManagement/store/useEnvStore.js.map +1 -1
  61. package/dist/index.js +1 -1
  62. package/dist/plugins/ValueTypes/Default/DefaultTeachMeRenderer.js +2 -1
  63. package/dist/plugins/ValueTypes/Default/DefaultTeachMeRenderer.js.map +1 -1
  64. package/dist/schema-driven/BPARenderer.js +7 -1
  65. package/dist/schema-driven/BPARenderer.js.map +1 -1
  66. package/dist/schema-driven/components/FileUploadField.js +778 -0
  67. package/dist/schema-driven/components/FileUploadField.js.map +1 -0
  68. package/dist/schema-driven/components/FileUploadField.module.css.js +8 -0
  69. package/dist/schema-driven/components/FileUploadField.module.css.js.map +1 -0
  70. package/dist/schema-driven/components/VariantListField.js +134 -12
  71. package/dist/schema-driven/components/VariantListField.js.map +1 -1
  72. package/dist/schema-driven/utils/fileUploadService.js +413 -0
  73. package/dist/schema-driven/utils/fileUploadService.js.map +1 -0
  74. package/dist/types/src/ComponentRegistry.d.ts.map +1 -1
  75. package/dist/types/src/features/IL-OTJ/ILOTJ.d.ts +3 -0
  76. package/dist/types/src/features/IL-OTJ/ILOTJ.d.ts.map +1 -1
  77. package/dist/types/src/features/IL-OTJ/ValueTypeWrappers/TeachMePlugin.d.ts.map +1 -1
  78. package/dist/types/src/features/IL-OTJ/ValueTypeWrappers/TeachMeWrapper.d.ts.map +1 -1
  79. package/dist/types/src/features/IL-OTJ/_components/ChatComponents/ChatComponent.d.ts +4 -0
  80. package/dist/types/src/features/IL-OTJ/_components/ChatComponents/ChatComponent.d.ts.map +1 -1
  81. package/dist/types/src/features/IL-OTJ/_components/hooks/useVariantEditSession.d.ts +3 -3
  82. package/dist/types/src/features/IL-OTJ/_components/hooks/useVariantEditSession.d.ts.map +1 -1
  83. package/dist/types/src/features/IL-OTJ/helpers/utils.d.ts +12 -2
  84. package/dist/types/src/features/IL-OTJ/helpers/utils.d.ts.map +1 -1
  85. package/dist/types/src/features/IL-marketplace/components/GuidelineLibraryCard.d.ts.map +1 -1
  86. package/dist/types/src/features/LearningManagement/components/InstantLearningModal.d.ts.map +1 -1
  87. package/dist/types/src/features/LearningManagement/components/InstantLearningModalDynamic.d.ts +2 -0
  88. package/dist/types/src/features/LearningManagement/components/InstantLearningModalDynamic.d.ts.map +1 -1
  89. package/dist/types/src/features/LearningManagement/store/useEnvStore.d.ts +2 -0
  90. package/dist/types/src/features/LearningManagement/store/useEnvStore.d.ts.map +1 -1
  91. package/dist/types/src/plugins/ValueTypes/Default/DefaultTeachMeRenderer.d.ts.map +1 -1
  92. package/dist/types/src/schema-driven/BPARenderer.d.ts.map +1 -1
  93. package/dist/types/src/schema-driven/components/FileUploadField.d.ts +74 -0
  94. package/dist/types/src/schema-driven/components/FileUploadField.d.ts.map +1 -0
  95. package/dist/types/src/schema-driven/components/VariantListField.d.ts.map +1 -1
  96. package/dist/types/src/schema-driven/demoSchema.d.ts.map +1 -1
  97. package/dist/types/src/schema-driven/utils/fileUploadService.d.ts +190 -0
  98. package/dist/types/src/schema-driven/utils/fileUploadService.d.ts.map +1 -0
  99. package/package.json +4 -4
@@ -0,0 +1,778 @@
1
+ import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
2
+ import { useMemo, useState, useRef, useEffect, useCallback } from 'react';
3
+ import { AlertCircle, X, Upload, FileText, Loader2, Check, Pencil } from 'lucide-react';
4
+ import { SectionWrapper } from '../../features/IL-OTJ/_components/molecules/Sections/SectionWrapper.js';
5
+ import { InputDataReasoningCard } from '../../features/IL-OTJ/_components/InputDataReasoningCard.js';
6
+ import { ButtonCognitiveIcon } from '../../features/IL-OTJ/_components/_svg/ButtonCognitiveIcon.js';
7
+ import { useDynamicFormStore } from '../store/useDynamicFormStore.js';
8
+ import useEnvStore from '../../features/LearningManagement/store/useEnvStore.js';
9
+ import { useConfigStore } from '../../features/LearningManagement/store/useConfigStore.js';
10
+ import { useLearningTemplateStore } from '../../features/LearningManagement/store/useLearningTemplateStore.js';
11
+ import useAuthStore from '../../features/LearningManagement/store/useAuthStore.js';
12
+ import { normalizeAcceptString, getGCSSignedUrl, isFileAccepted, isImageFile, uploadFilesBatch, getFileExtension, formatFileSize } from '../utils/fileUploadService.js';
13
+ import { getOptionalGuidelineRuntimeConfig } from '../../features/IL-marketplace/services/guideline.runtime.config.js';
14
+ import styles from './FileUploadField.module.css.js';
15
+
16
+ function FileUploadField(props) {
17
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
18
+ const {
19
+ id,
20
+ schema,
21
+ title = (schema == null ? void 0 : schema.title) || "Supporting documents",
22
+ subtitle = (schema == null ? void 0 : schema.subtitle) || "Upload any supporting documents, such as user journey files, technical or integration documentation, or PDFs",
23
+ value,
24
+ onChange,
25
+ readOnly = false,
26
+ required = (schema == null ? void 0 : schema.is_required) || false,
27
+ citation,
28
+ isMirage,
29
+ tierKey,
30
+ variantIndex,
31
+ state,
32
+ uiState,
33
+ enableInlineEdit = false,
34
+ hideEditControls,
35
+ parentEditing,
36
+ activeEditId,
37
+ setActiveEditId,
38
+ isAiStreaming: propAiStreaming,
39
+ accept: propAccept,
40
+ uploadType: propUploadType,
41
+ maxUploads: propMaxUploads,
42
+ bordered: propBordered,
43
+ collapsible: propCollapsible,
44
+ defaultOpen: propDefaultOpen,
45
+ openSections: propOpenSections,
46
+ setOpenSections: propSetOpenSections
47
+ } = props;
48
+ const isBordered = propBordered !== void 0 ? !!propBordered : (schema == null ? void 0 : schema.bordered) !== void 0 ? !!schema.bordered : true;
49
+ const isCollapsible = propCollapsible !== void 0 ? !!propCollapsible : (schema == null ? void 0 : schema.collapsible) !== void 0 ? !!schema.collapsible : true;
50
+ const resolvedDefaultOpen = propDefaultOpen !== void 0 ? !!propDefaultOpen : (schema == null ? void 0 : schema.default_open) !== void 0 ? !!schema.default_open : (schema == null ? void 0 : schema.defaultOpen) !== void 0 ? !!schema.defaultOpen : true;
51
+ const rawUploadType = (propUploadType || (schema == null ? void 0 : schema.upload_type) || "multiple").toString().trim().toLowerCase();
52
+ const isSingleUpload = rawUploadType === "single";
53
+ const rawMaxUploads = propMaxUploads != null ? propMaxUploads : schema == null ? void 0 : schema.max_uploads;
54
+ const effectiveMaxUploads = useMemo(() => {
55
+ if (isSingleUpload) return 1;
56
+ if (rawMaxUploads !== void 0 && rawMaxUploads !== null && rawMaxUploads !== "") {
57
+ const parsed = Number(rawMaxUploads);
58
+ if (!isNaN(parsed) && parsed > 0) return parsed;
59
+ }
60
+ return Infinity;
61
+ }, [isSingleUpload, rawMaxUploads]);
62
+ const rawAccept = propAccept || props.acceptedFormats || props.acceptedFileTypes || props.allowedExtensions || (schema == null ? void 0 : schema.accept) || (schema == null ? void 0 : schema.accepted_formats) || (schema == null ? void 0 : schema.accepted_file_types) || (schema == null ? void 0 : schema.allowed_extensions);
63
+ const normalizedAccept = useMemo(() => normalizeAcceptString(rawAccept), [rawAccept]);
64
+ const [isReasoningOpen, setIsReasoningOpen] = useState(false);
65
+ const [isDragging, setIsDragging] = useState(false);
66
+ const [isUploading, setIsUploading] = useState(false);
67
+ const [duplicateWarning, setDuplicateWarning] = useState(null);
68
+ const [formatWarning, setFormatWarning] = useState(null);
69
+ const [limitWarning, setLimitWarning] = useState(null);
70
+ const fileInputRef = useRef(null);
71
+ const { getGlobalField, getVariantField, clearAllMirages, getGlobalMirage, getVariantMirage } = useDynamicFormStore();
72
+ const dataKey = (schema == null ? void 0 : schema.data_key) || id;
73
+ const cleanKey = dataKey.replace("global.", "");
74
+ const isGlobal = dataKey.startsWith("global.") || variantIndex === void 0;
75
+ useEffect(() => {
76
+ if (!isMirage) return;
77
+ const currentMirage = isGlobal ? getGlobalMirage(cleanKey) : getVariantMirage(tierKey != null ? tierKey : "", variantIndex != null ? variantIndex : 0, cleanKey);
78
+ const currentStoreValue = isGlobal ? getGlobalField(cleanKey) : getVariantField(tierKey != null ? tierKey : "", variantIndex != null ? variantIndex : 0, cleanKey);
79
+ if (currentStoreValue !== void 0 && currentStoreValue !== currentMirage && currentStoreValue !== "") {
80
+ clearAllMirages();
81
+ }
82
+ }, [value, isMirage, isGlobal, cleanKey, tierKey, variantIndex, getGlobalMirage, getVariantMirage, getGlobalField, getVariantField, clearAllMirages]);
83
+ const envProjectId = useEnvStore((s) => s.projectId);
84
+ const configProjectId = useConfigStore(
85
+ (s) => {
86
+ var _a2, _b2;
87
+ return ((_a2 = s.configuration) == null ? void 0 : _a2.PROJECT_ID) || ((_b2 = s.configuration) == null ? void 0 : _b2.projectId);
88
+ }
89
+ );
90
+ const resolvedProjectId = props.projectId || (schema == null ? void 0 : schema.project_id) || envProjectId || configProjectId || (uiState == null ? void 0 : uiState.projectId) || (state == null ? void 0 : state.projectId) || (typeof window !== "undefined" ? window.__PROJECT_ID__ : void 0) || (typeof process !== "undefined" ? (_a = process.env) == null ? void 0 : _a.REACT_APP_PROJECT_ID : void 0) || null;
91
+ const runtimeConfig = getOptionalGuidelineRuntimeConfig();
92
+ const config = useConfigStore((s) => s.configuration);
93
+ const resolvedBaseUrl = props.gcsBaseUrl || props.backendUrl || (schema == null ? void 0 : schema.backend_url) || ((_b = runtimeConfig == null ? void 0 : runtimeConfig.apiBaseUrls) == null ? void 0 : _b.chatManagement) || (config == null ? void 0 : config.CHAT_MANAGEMENT_URL) || (config == null ? void 0 : config.VITE_BASE_API_URL) || (config == null ? void 0 : config.backendUrl) || (typeof process !== "undefined" ? (_c = process.env) == null ? void 0 : _c.VITE_BASE_API_URL : void 0) || "";
94
+ const templateToken = useLearningTemplateStore((s) => s.token);
95
+ const authUser = useAuthStore((s) => s.user);
96
+ const runtimeToken = (_e = (_d = runtimeConfig == null ? void 0 : runtimeConfig.getHostContext) == null ? void 0 : _d.call(runtimeConfig)) == null ? void 0 : _e.authToken;
97
+ const resolvedToken = templateToken || (authUser == null ? void 0 : authUser.accessToken) || runtimeToken || "";
98
+ const resolvedUserName = props.artifactUserName || ((authUser == null ? void 0 : authUser.firstname) ? `${authUser.firstname} ${authUser.lastname || ""}`.trim() : null) || (authUser == null ? void 0 : authUser.email) || ((_g = (_f = runtimeConfig == null ? void 0 : runtimeConfig.getHostContext) == null ? void 0 : _f.call(runtimeConfig)) == null ? void 0 : _g.userName) || null;
99
+ const resolvedUserEmail = props.artifactUserEmail || (authUser == null ? void 0 : authUser.email) || ((_i = (_h = runtimeConfig == null ? void 0 : runtimeConfig.getHostContext) == null ? void 0 : _h.call(runtimeConfig)) == null ? void 0 : _i.userEmail) || null;
100
+ const filesList = useMemo(() => {
101
+ if (!value) return [];
102
+ if (Array.isArray(value)) {
103
+ return value.map((item, index) => {
104
+ var _a2;
105
+ if (typeof item === "string") {
106
+ return {
107
+ id: `file-${index}-${item}`,
108
+ name: item.split("/").pop() || item,
109
+ filename: item.split("/").pop() || item,
110
+ url: item,
111
+ signedUrl: item.startsWith("http") ? item : void 0,
112
+ status: "success"
113
+ };
114
+ }
115
+ return {
116
+ id: item.id || `file-${index}`,
117
+ name: item.name || item.filename || "Uploaded Document",
118
+ filename: item.filename || item.name,
119
+ url: item.url,
120
+ signedUrl: item.signedUrl || item.signed_url || (((_a2 = item.url) == null ? void 0 : _a2.startsWith("http")) ? item.url : void 0),
121
+ previewUrl: item.previewUrl,
122
+ size: item.size,
123
+ type: item.type,
124
+ status: item.status || "success",
125
+ progress: item.progress,
126
+ error: item.error
127
+ };
128
+ });
129
+ }
130
+ if (typeof value === "string") {
131
+ try {
132
+ const parsed = JSON.parse(value);
133
+ if (Array.isArray(parsed)) {
134
+ return parsed.map((item, index) => {
135
+ var _a2;
136
+ if (typeof item === "string") {
137
+ return {
138
+ id: `file-${index}-${item}`,
139
+ name: item.split("/").pop() || item,
140
+ filename: item.split("/").pop() || item,
141
+ url: item,
142
+ signedUrl: item.startsWith("http") ? item : void 0,
143
+ status: "success"
144
+ };
145
+ }
146
+ return {
147
+ id: item.id || `file-${index}`,
148
+ name: item.name || item.filename || "Uploaded Document",
149
+ filename: item.filename || item.name,
150
+ url: item.url,
151
+ signedUrl: item.signedUrl || item.signed_url || (((_a2 = item.url) == null ? void 0 : _a2.startsWith("http")) ? item.url : void 0),
152
+ previewUrl: item.previewUrl,
153
+ size: item.size,
154
+ type: item.type,
155
+ status: item.status || "success",
156
+ progress: item.progress,
157
+ error: item.error
158
+ };
159
+ });
160
+ }
161
+ } catch (e) {
162
+ return [
163
+ {
164
+ id: "file-0",
165
+ name: value.split("/").pop() || value,
166
+ filename: value.split("/").pop() || value,
167
+ url: value,
168
+ signedUrl: value.startsWith("http") ? value : void 0,
169
+ status: "success"
170
+ }
171
+ ];
172
+ }
173
+ }
174
+ return [];
175
+ }, [value]);
176
+ const [signedUrlMap, setSignedUrlMap] = useState({});
177
+ useEffect(() => {
178
+ const filesNeedingSignedUrl = filesList.filter((f) => {
179
+ const path = f.url;
180
+ if (!path) return false;
181
+ if (f.signedUrl) return false;
182
+ if (signedUrlMap[path]) return false;
183
+ return true;
184
+ });
185
+ if (filesNeedingSignedUrl.length === 0) return;
186
+ let isMounted = true;
187
+ void Promise.all(
188
+ filesNeedingSignedUrl.map(async (file) => {
189
+ const path = file.url;
190
+ try {
191
+ const fetchedUrl = await getGCSSignedUrl(path, {
192
+ baseURL: resolvedBaseUrl,
193
+ token: resolvedToken
194
+ });
195
+ return { path, url: fetchedUrl };
196
+ } catch (e) {
197
+ return { path, url: null };
198
+ }
199
+ })
200
+ ).then((results) => {
201
+ if (!isMounted) return;
202
+ setSignedUrlMap((prev) => {
203
+ const next = { ...prev };
204
+ let hasNew = false;
205
+ results.forEach(({ path, url }) => {
206
+ if (url && next[path] !== url) {
207
+ next[path] = url;
208
+ hasNew = true;
209
+ }
210
+ });
211
+ return hasNew ? next : prev;
212
+ });
213
+ });
214
+ return () => {
215
+ isMounted = false;
216
+ };
217
+ }, [filesList, resolvedBaseUrl, resolvedToken, signedUrlMap]);
218
+ const isStreaming = propAiStreaming || (uiState == null ? void 0 : uiState.isAiStreaming) || false;
219
+ const isParentControlled = hideEditControls !== void 0 ? !!hideEditControls : false;
220
+ const isEditing = !readOnly && !isStreaming && (isParentControlled ? !!parentEditing : enableInlineEdit ? activeEditId === id : true);
221
+ const isEditingRef = useRef(isEditing);
222
+ useEffect(() => {
223
+ isEditingRef.current = isEditing;
224
+ }, [isEditing]);
225
+ const isUploadLimitReached = filesList.length >= effectiveMaxUploads;
226
+ const canUploadMore = isEditing && !isUploadLimitReached;
227
+ const helperTextContent = useMemo(() => {
228
+ const parts = [];
229
+ if (isSingleUpload) {
230
+ parts.push("Single file upload");
231
+ } else if (isFinite(effectiveMaxUploads)) {
232
+ parts.push(`Up to ${effectiveMaxUploads} files`);
233
+ }
234
+ if (normalizedAccept) {
235
+ parts.push(`Supported formats: ${normalizedAccept}`);
236
+ } else if (parts.length === 0) {
237
+ parts.push("Any file type: PDF, Word, slides, images or user journey files");
238
+ }
239
+ return parts.join(" \u2022 ");
240
+ }, [isSingleUpload, effectiveMaxUploads, normalizedAccept]);
241
+ const handleUploadFiles = useCallback(
242
+ async (rawFiles) => {
243
+ if (!isEditing || !onChange) return;
244
+ const fileArray = Array.from(rawFiles);
245
+ if (fileArray.length === 0) return;
246
+ setDuplicateWarning(null);
247
+ setFormatWarning(null);
248
+ setLimitWarning(null);
249
+ const remainingSlots = isFinite(effectiveMaxUploads) ? Math.max(0, effectiveMaxUploads - filesList.length) : Infinity;
250
+ if (remainingSlots <= 0) {
251
+ setLimitWarning(
252
+ isSingleUpload ? "Only 1 file can be uploaded. Delete the current file to upload a new one." : `Maximum upload limit of ${effectiveMaxUploads} ${effectiveMaxUploads === 1 ? "file" : "files"} reached.`
253
+ );
254
+ if (fileInputRef.current) {
255
+ fileInputRef.current.value = "";
256
+ }
257
+ return;
258
+ }
259
+ let filesToProcess = fileArray;
260
+ if (isSingleUpload && fileArray.length > 1) {
261
+ setLimitWarning("Single upload mode: only the first file was selected.");
262
+ filesToProcess = [fileArray[0]];
263
+ } else if (fileArray.length > remainingSlots) {
264
+ setLimitWarning(
265
+ `Maximum ${effectiveMaxUploads} files allowed. Only the first ${remainingSlots} ${remainingSlots === 1 ? "file was" : "files were"} accepted.`
266
+ );
267
+ filesToProcess = fileArray.slice(0, remainingSlots);
268
+ }
269
+ const validFiles = [];
270
+ const invalidFiles = [];
271
+ for (const file of filesToProcess) {
272
+ if (isFileAccepted(file, normalizedAccept)) {
273
+ validFiles.push(file);
274
+ } else {
275
+ invalidFiles.push(file);
276
+ }
277
+ }
278
+ if (invalidFiles.length > 0) {
279
+ const invalidNames = invalidFiles.map((f) => f.name).join(", ");
280
+ const message = invalidFiles.length === 1 ? `File "${invalidNames}" is not an accepted format. Accepted formats: ${normalizedAccept}` : `Files "${invalidNames}" are not accepted formats. Accepted formats: ${normalizedAccept}`;
281
+ setFormatWarning(message);
282
+ }
283
+ if (validFiles.length === 0) {
284
+ if (fileInputRef.current) {
285
+ fileInputRef.current.value = "";
286
+ }
287
+ return;
288
+ }
289
+ setIsUploading(true);
290
+ const optimisticItems = validFiles.map((file, i) => {
291
+ const isImg = isImageFile(file.name, file.type);
292
+ let previewBlobUrl = void 0;
293
+ try {
294
+ if (isImg && typeof URL !== "undefined" && typeof URL.createObjectURL === "function") {
295
+ previewBlobUrl = URL.createObjectURL(file);
296
+ }
297
+ } catch (e) {
298
+ }
299
+ return {
300
+ id: `upload-${Date.now()}-${i}-${file.name}`,
301
+ name: file.name,
302
+ filename: file.name,
303
+ size: file.size,
304
+ type: file.type,
305
+ status: "uploading",
306
+ progress: 0,
307
+ previewUrl: previewBlobUrl
308
+ };
309
+ });
310
+ let currentList = [...filesList, ...optimisticItems];
311
+ onChange(currentList);
312
+ try {
313
+ const result = await uploadFilesBatch({
314
+ projectId: resolvedProjectId || "",
315
+ files: validFiles,
316
+ baseUrl: resolvedBaseUrl,
317
+ token: resolvedToken,
318
+ artifactUserName: resolvedUserName,
319
+ artifactUserEmail: resolvedUserEmail,
320
+ onProgress: (_totalPct, fileProgressMap) => {
321
+ if (!isEditingRef.current || !fileProgressMap) return;
322
+ currentList = currentList.map((item) => {
323
+ if (item.status === "uploading" && fileProgressMap[item.name || item.filename || ""] !== void 0) {
324
+ const fileBytes = item.size || 1;
325
+ const loaded = fileProgressMap[item.name || item.filename || ""];
326
+ const pct = Math.min(99, Math.round(loaded / fileBytes * 100));
327
+ return { ...item, progress: pct };
328
+ }
329
+ return item;
330
+ });
331
+ onChange(currentList);
332
+ }
333
+ });
334
+ if (!isEditingRef.current) return;
335
+ if (result.duplicates.length > 0) {
336
+ const dupNames = result.duplicates.join(", ");
337
+ const message = result.duplicates.length === 1 ? `File "${dupNames}" already exists.` : `Files "${dupNames}" already exist.`;
338
+ setDuplicateWarning(message);
339
+ }
340
+ const updatedList = [];
341
+ for (const item of currentList) {
342
+ const optimisticMatch = optimisticItems.find((opt) => opt.id === item.id);
343
+ if (!optimisticMatch) {
344
+ updatedList.push(item);
345
+ continue;
346
+ }
347
+ const fileName = item.name || item.filename || "";
348
+ if (result.duplicates.includes(fileName)) {
349
+ continue;
350
+ }
351
+ const uploadedSuccess = result.uploaded.find(
352
+ (u) => u.name === fileName || u.filename === fileName
353
+ );
354
+ if (uploadedSuccess) {
355
+ if (uploadedSuccess.url && uploadedSuccess.signedUrl) {
356
+ setSignedUrlMap((prev) => ({
357
+ ...prev,
358
+ [uploadedSuccess.url]: uploadedSuccess.signedUrl
359
+ }));
360
+ }
361
+ updatedList.push({
362
+ ...uploadedSuccess,
363
+ id: item.id,
364
+ previewUrl: uploadedSuccess.previewUrl || item.previewUrl
365
+ });
366
+ continue;
367
+ }
368
+ const fileSpecificError = result.errors.find((err) => err.includes(fileName));
369
+ const generalError = result.errors.length > 0 ? result.errors[0] : null;
370
+ updatedList.push({
371
+ ...item,
372
+ status: "error",
373
+ error: fileSpecificError || generalError || "Failed to upload"
374
+ });
375
+ }
376
+ if (!isEditingRef.current) return;
377
+ onChange(updatedList);
378
+ } catch (err) {
379
+ if (!isEditingRef.current) return;
380
+ console.error("[FileUploadField] Upload process error:", err);
381
+ const errorList = currentList.map((item) => {
382
+ const optimisticMatch = optimisticItems.find((opt) => opt.id === item.id);
383
+ if (optimisticMatch) {
384
+ return {
385
+ ...item,
386
+ status: "error",
387
+ error: (err == null ? void 0 : err.message) || "Upload failed"
388
+ };
389
+ }
390
+ return item;
391
+ });
392
+ onChange(errorList);
393
+ } finally {
394
+ setIsUploading(false);
395
+ if (fileInputRef.current) {
396
+ fileInputRef.current.value = "";
397
+ }
398
+ }
399
+ },
400
+ [
401
+ isEditing,
402
+ onChange,
403
+ filesList,
404
+ resolvedProjectId,
405
+ resolvedBaseUrl,
406
+ resolvedToken,
407
+ resolvedUserName,
408
+ resolvedUserEmail,
409
+ normalizedAccept,
410
+ effectiveMaxUploads,
411
+ isSingleUpload
412
+ ]
413
+ );
414
+ const handleDragOver = (e) => {
415
+ e.preventDefault();
416
+ e.stopPropagation();
417
+ if (isEditing && !isDragging) {
418
+ setIsDragging(true);
419
+ }
420
+ };
421
+ const handleDragLeave = (e) => {
422
+ e.preventDefault();
423
+ e.stopPropagation();
424
+ if (isDragging) {
425
+ setIsDragging(false);
426
+ }
427
+ };
428
+ const handleDrop = (e) => {
429
+ var _a2;
430
+ e.preventDefault();
431
+ e.stopPropagation();
432
+ setIsDragging(false);
433
+ if (!isEditing) return;
434
+ if (((_a2 = e.dataTransfer) == null ? void 0 : _a2.files) && e.dataTransfer.files.length > 0) {
435
+ void handleUploadFiles(e.dataTransfer.files);
436
+ }
437
+ };
438
+ const handleNativeFileChange = (e) => {
439
+ if (!isEditing) return;
440
+ if (e.target.files && e.target.files.length > 0) {
441
+ void handleUploadFiles(e.target.files);
442
+ }
443
+ };
444
+ const handleBrowseClick = (e) => {
445
+ var _a2;
446
+ e.stopPropagation();
447
+ if (!isEditing) return;
448
+ (_a2 = fileInputRef.current) == null ? void 0 : _a2.click();
449
+ };
450
+ const handleDropzoneClick = () => {
451
+ var _a2;
452
+ if (!isEditing) return;
453
+ (_a2 = fileInputRef.current) == null ? void 0 : _a2.click();
454
+ };
455
+ const handleRemoveFile = (targetId, e) => {
456
+ e.stopPropagation();
457
+ if (!isEditing || !onChange) return;
458
+ setDuplicateWarning(null);
459
+ setFormatWarning(null);
460
+ setLimitWarning(null);
461
+ if (fileInputRef.current) {
462
+ fileInputRef.current.value = "";
463
+ }
464
+ const nextList = filesList.filter((item) => item.id !== targetId);
465
+ onChange(nextList);
466
+ };
467
+ const inlineSnapshotRef = useRef(null);
468
+ const handleInlineStart = () => {
469
+ setDuplicateWarning(null);
470
+ inlineSnapshotRef.current = JSON.parse(JSON.stringify(filesList));
471
+ setActiveEditId == null ? void 0 : setActiveEditId(id);
472
+ };
473
+ const handleInlineCancel = () => {
474
+ if (inlineSnapshotRef.current !== null && onChange) {
475
+ onChange(inlineSnapshotRef.current);
476
+ }
477
+ inlineSnapshotRef.current = null;
478
+ setDuplicateWarning(null);
479
+ setActiveEditId == null ? void 0 : setActiveEditId(null);
480
+ };
481
+ const handleInlineDone = () => {
482
+ inlineSnapshotRef.current = null;
483
+ setActiveEditId == null ? void 0 : setActiveEditId(null);
484
+ };
485
+ const inlineEditActions = enableInlineEdit && !isParentControlled && !readOnly ? isEditing ? /* @__PURE__ */ jsxs("div", { style: { display: "flex", alignItems: "center", gap: "6px" }, children: [
486
+ /* @__PURE__ */ jsxs(
487
+ "button",
488
+ {
489
+ type: "button",
490
+ title: "Apply changes",
491
+ onClick: handleInlineDone,
492
+ style: {
493
+ display: "flex",
494
+ alignItems: "center",
495
+ gap: "4px",
496
+ padding: "4px 8px",
497
+ borderRadius: "6px",
498
+ border: "1px solid var(--il-primary, #2563EB)",
499
+ backgroundColor: "var(--il-primary, #2563EB)",
500
+ color: "#ffffff",
501
+ fontSize: "12px",
502
+ fontWeight: 500,
503
+ cursor: "pointer"
504
+ },
505
+ children: [
506
+ /* @__PURE__ */ jsx(Check, { size: 14 }),
507
+ " Done"
508
+ ]
509
+ }
510
+ ),
511
+ /* @__PURE__ */ jsxs(
512
+ "button",
513
+ {
514
+ type: "button",
515
+ title: "Cancel changes",
516
+ onClick: handleInlineCancel,
517
+ style: {
518
+ display: "flex",
519
+ alignItems: "center",
520
+ gap: "4px",
521
+ padding: "4px 8px",
522
+ borderRadius: "6px",
523
+ border: "1px solid var(--il-border, #CBD5E1)",
524
+ backgroundColor: "var(--il-surface, #ffffff)",
525
+ color: "var(--il-muted, #64748B)",
526
+ fontSize: "12px",
527
+ fontWeight: 500,
528
+ cursor: "pointer"
529
+ },
530
+ children: [
531
+ /* @__PURE__ */ jsx(X, { size: 14 }),
532
+ " Cancel"
533
+ ]
534
+ }
535
+ )
536
+ ] }) : /* @__PURE__ */ jsxs(
537
+ "button",
538
+ {
539
+ type: "button",
540
+ title: "Edit",
541
+ onClick: handleInlineStart,
542
+ disabled: isStreaming,
543
+ style: {
544
+ display: "flex",
545
+ alignItems: "center",
546
+ gap: "4px",
547
+ padding: "4px 8px",
548
+ borderRadius: "6px",
549
+ border: "1px solid var(--il-border, #CBD5E1)",
550
+ backgroundColor: "var(--il-surface, #ffffff)",
551
+ color: "var(--il-muted, #64748B)",
552
+ fontSize: "12px",
553
+ fontWeight: 500,
554
+ cursor: isStreaming ? "not-allowed" : "pointer",
555
+ opacity: isStreaming ? 0.5 : 1
556
+ },
557
+ children: [
558
+ /* @__PURE__ */ jsx(Pencil, { size: 14 }),
559
+ " Edit"
560
+ ]
561
+ }
562
+ ) : null;
563
+ const headerActions = citation || inlineEditActions ? /* @__PURE__ */ jsxs("div", { style: { display: "flex", alignItems: "center", gap: "8px" }, children: [
564
+ inlineEditActions,
565
+ citation && /* @__PURE__ */ jsx(
566
+ "button",
567
+ {
568
+ type: "button",
569
+ onClick: () => setIsReasoningOpen((prev) => !prev),
570
+ style: {
571
+ background: "none",
572
+ border: "none",
573
+ padding: "4px",
574
+ cursor: "pointer",
575
+ display: "flex",
576
+ alignItems: "center",
577
+ justifyContent: "center"
578
+ },
579
+ title: "Why this value?",
580
+ "aria-label": "Toggle cognitive reasoning",
581
+ children: /* @__PURE__ */ jsx(ButtonCognitiveIcon, {})
582
+ }
583
+ )
584
+ ] }) : null;
585
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
586
+ /* @__PURE__ */ jsx(
587
+ SectionWrapper,
588
+ {
589
+ id,
590
+ required,
591
+ title,
592
+ subtitle,
593
+ collapsible: isCollapsible,
594
+ defaultOpen: resolvedDefaultOpen,
595
+ bordered: isBordered,
596
+ openSections: propOpenSections,
597
+ setOpenSections: propSetOpenSections,
598
+ readOnly: !isEditing,
599
+ headerActions,
600
+ children: /* @__PURE__ */ jsxs("div", { className: styles.container, children: [
601
+ /* @__PURE__ */ jsx(
602
+ "input",
603
+ {
604
+ ref: fileInputRef,
605
+ type: "file",
606
+ multiple: !isSingleUpload && effectiveMaxUploads > 1,
607
+ disabled: !canUploadMore,
608
+ accept: normalizedAccept,
609
+ style: { display: "none" },
610
+ onChange: handleNativeFileChange
611
+ }
612
+ ),
613
+ (duplicateWarning || formatWarning || limitWarning) && /* @__PURE__ */ jsxs("div", { className: styles.warningBanner, role: "alert", children: [
614
+ /* @__PURE__ */ jsxs("div", { className: styles.warningContent, children: [
615
+ /* @__PURE__ */ jsx(AlertCircle, { size: 16, color: "#D97706", style: { flexShrink: 0 } }),
616
+ /* @__PURE__ */ jsx("span", { className: styles.warningText, children: duplicateWarning || formatWarning || limitWarning })
617
+ ] }),
618
+ /* @__PURE__ */ jsx(
619
+ "button",
620
+ {
621
+ type: "button",
622
+ onClick: () => {
623
+ setDuplicateWarning(null);
624
+ setFormatWarning(null);
625
+ setLimitWarning(null);
626
+ },
627
+ className: styles.warningCloseBtn,
628
+ title: "Dismiss notification",
629
+ "aria-label": "Dismiss notification",
630
+ children: /* @__PURE__ */ jsx(X, { size: 14 })
631
+ }
632
+ )
633
+ ] }),
634
+ canUploadMore ? /* @__PURE__ */ jsxs(
635
+ "div",
636
+ {
637
+ className: `${styles.dropzone} ${isDragging ? styles.dropzoneActive : ""}`,
638
+ onClick: handleDropzoneClick,
639
+ onDragOver: handleDragOver,
640
+ onDragEnter: handleDragOver,
641
+ onDragLeave: handleDragLeave,
642
+ onDrop: handleDrop,
643
+ role: "button",
644
+ tabIndex: 0,
645
+ "aria-label": "Upload files dropzone",
646
+ children: [
647
+ /* @__PURE__ */ jsx("div", { className: styles.uploadIconWrapper, children: /* @__PURE__ */ jsx(Upload, { size: 24, strokeWidth: 2 }) }),
648
+ /* @__PURE__ */ jsx("p", { className: styles.promptText, children: isSingleUpload ? /* @__PURE__ */ jsxs(Fragment, { children: [
649
+ "Drag and drop a file here, or",
650
+ " ",
651
+ /* @__PURE__ */ jsx("span", { className: styles.browseLink, onClick: handleBrowseClick, children: "browse" })
652
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
653
+ "Drag and drop files here, or",
654
+ " ",
655
+ /* @__PURE__ */ jsx("span", { className: styles.browseLink, onClick: handleBrowseClick, children: "browse" })
656
+ ] }) }),
657
+ /* @__PURE__ */ jsx("p", { className: styles.helperText, children: helperTextContent })
658
+ ]
659
+ }
660
+ ) : filesList.length === 0 ? /* @__PURE__ */ jsxs(
661
+ "div",
662
+ {
663
+ className: `${styles.dropzone} ${styles.dropzoneDisabled}`,
664
+ role: "region",
665
+ "aria-label": "Upload files disabled",
666
+ children: [
667
+ /* @__PURE__ */ jsx("div", { className: styles.uploadIconWrapper, style: { color: "var(--il-muted, #94a3b8)" }, children: /* @__PURE__ */ jsx(Upload, { size: 24, strokeWidth: 2 }) }),
668
+ /* @__PURE__ */ jsx("p", { className: styles.promptText, style: { color: "var(--il-muted, #64748B)" }, children: "No documents uploaded" }),
669
+ /* @__PURE__ */ jsx("p", { className: styles.helperText, children: "Upload supporting documents by editing this section" })
670
+ ]
671
+ }
672
+ ) : null,
673
+ filesList.length > 0 && /* @__PURE__ */ jsx("div", { className: styles.fileList, children: filesList.map((file) => {
674
+ var _a2, _b2;
675
+ const extension = getFileExtension(file.name || file.filename);
676
+ const isItemUploading = file.status === "uploading";
677
+ const hasError = file.status === "error";
678
+ const isImg = isImageFile(file.name || file.filename, file.type);
679
+ const fileGcsUrl = file.url || "";
680
+ const effectiveSignedUrl = file.signedUrl || (fileGcsUrl ? signedUrlMap[fileGcsUrl] : void 0);
681
+ const effectiveLink = effectiveSignedUrl || (fileGcsUrl.startsWith("http") ? fileGcsUrl : void 0);
682
+ const effectiveImageSrc = effectiveSignedUrl || file.previewUrl || (fileGcsUrl.startsWith("http") ? fileGcsUrl : void 0);
683
+ return /* @__PURE__ */ jsxs(
684
+ "div",
685
+ {
686
+ className: `${styles.fileCard} ${hasError ? styles.fileCardError : ""}`,
687
+ children: [
688
+ /* @__PURE__ */ jsxs("div", { className: styles.fileInfoLeft, children: [
689
+ hasError ? /* @__PURE__ */ jsx("div", { className: styles.fileIcon, children: /* @__PURE__ */ jsx(AlertCircle, { size: 22, color: "#EF4444" }) }) : isImg ? effectiveImageSrc ? /* @__PURE__ */ jsx(
690
+ "a",
691
+ {
692
+ href: effectiveLink || effectiveImageSrc,
693
+ target: "_blank",
694
+ rel: "noopener noreferrer",
695
+ className: styles.imagePreviewSquare,
696
+ onClick: (e) => {
697
+ if (!effectiveLink && !effectiveImageSrc) {
698
+ e.preventDefault();
699
+ }
700
+ e.stopPropagation();
701
+ },
702
+ title: `Preview ${file.name}`,
703
+ children: /* @__PURE__ */ jsx(
704
+ "img",
705
+ {
706
+ src: effectiveImageSrc,
707
+ alt: file.name,
708
+ className: styles.imageThumbnail
709
+ }
710
+ )
711
+ }
712
+ ) : /* @__PURE__ */ jsx("div", { className: styles.imagePreviewSquare, children: /* @__PURE__ */ jsx(FileText, { size: 26, strokeWidth: 1.8, color: "#7C3AED" }) }) : /* @__PURE__ */ jsx("div", { className: styles.fileIcon, children: /* @__PURE__ */ jsx(FileText, { size: 22, strokeWidth: 1.8 }) }),
713
+ /* @__PURE__ */ jsxs("div", { className: styles.fileMeta, children: [
714
+ effectiveLink && !hasError && !isItemUploading ? /* @__PURE__ */ jsx(
715
+ "a",
716
+ {
717
+ href: effectiveLink,
718
+ target: "_blank",
719
+ rel: "noopener noreferrer",
720
+ className: styles.fileName,
721
+ title: file.name,
722
+ onClick: (e) => e.stopPropagation(),
723
+ children: file.name
724
+ }
725
+ ) : /* @__PURE__ */ jsx("span", { className: styles.fileName, title: file.name, children: file.name }),
726
+ hasError ? /* @__PURE__ */ jsx("span", { className: styles.fileErrorText, children: file.error || "Failed to upload" }) : isItemUploading ? /* @__PURE__ */ jsxs("div", { className: styles.progressContainer, children: [
727
+ /* @__PURE__ */ jsxs("span", { className: styles.progressLabel, children: [
728
+ "Uploading... ",
729
+ (_a2 = file.progress) != null ? _a2 : 0,
730
+ "%"
731
+ ] }),
732
+ /* @__PURE__ */ jsx("div", { className: styles.progressBarWrapper, children: /* @__PURE__ */ jsx(
733
+ "div",
734
+ {
735
+ className: styles.progressBarFill,
736
+ style: { width: `${Math.max((_b2 = file.progress) != null ? _b2 : 15, 10)}%` }
737
+ }
738
+ ) })
739
+ ] }) : /* @__PURE__ */ jsxs("span", { className: styles.fileType, children: [
740
+ extension,
741
+ file.size ? ` \u2022 ${formatFileSize(file.size)}` : ""
742
+ ] })
743
+ ] })
744
+ ] }),
745
+ /* @__PURE__ */ jsx("div", { className: styles.fileActionsRight, children: isItemUploading ? /* @__PURE__ */ jsx(Loader2, { size: 18, className: styles.loadingSpinner }) : isEditing ? /* @__PURE__ */ jsx(
746
+ "button",
747
+ {
748
+ type: "button",
749
+ className: styles.removeButton,
750
+ title: "Remove file",
751
+ "aria-label": `Remove ${file.name}`,
752
+ onClick: (e) => handleRemoveFile(file.id, e),
753
+ children: /* @__PURE__ */ jsx(X, { size: 18 })
754
+ }
755
+ ) : null })
756
+ ]
757
+ },
758
+ file.id
759
+ );
760
+ }) })
761
+ ] })
762
+ }
763
+ ),
764
+ citation && /* @__PURE__ */ jsx(
765
+ InputDataReasoningCard,
766
+ {
767
+ isVisible: isReasoningOpen,
768
+ citation,
769
+ citations: state == null ? void 0 : state.citations,
770
+ fieldName: title,
771
+ fieldValue: value
772
+ }
773
+ )
774
+ ] });
775
+ }
776
+
777
+ export { FileUploadField as default };
778
+ //# sourceMappingURL=FileUploadField.js.map