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