@ultrst-armada/floks 2.0.17 → 2.0.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.
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "schema": 1,
3
3
  "packageName": "@ultrst-armada/floks",
4
- "version": "2.0.17",
5
- "sourceCommit": "ef88a21b4aa085183369bb69024c3d23f3ee3558",
4
+ "version": "2.0.18",
5
+ "sourceCommit": "62287ab556bd87fcfa3e8af1d6345ecb515076de",
6
6
  "releaseWorkflow": "npm Release",
7
- "workflowRunId": "45017683774"
7
+ "workflowRunId": "45114224479"
8
8
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultrst-armada/floks",
3
- "version": "2.0.17",
3
+ "version": "2.0.18",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public",
@@ -67,6 +67,12 @@ import {
67
67
  skipoDarkTheme,
68
68
  useMonaco
69
69
  } from "./chunk-KAKAFGVH.js";
70
+ import {
71
+ CanvasViewport,
72
+ InfiniteCanvas,
73
+ MiniMap,
74
+ useCanvas
75
+ } from "./chunk-34YRDZPJ.js";
70
76
  import {
71
77
  FodModule,
72
78
  authorizedRemoteCategories,
@@ -97,12 +103,6 @@ import {
97
103
  import {
98
104
  usePredictiveGraph2D
99
105
  } from "./chunk-ZSVXR3HU.js";
100
- import {
101
- CanvasViewport,
102
- InfiniteCanvas,
103
- MiniMap,
104
- useCanvas
105
- } from "./chunk-34YRDZPJ.js";
106
106
 
107
107
  // src/node-graph-ui/widgets/MidpointWidgets.tsx
108
108
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
@@ -202,11 +202,11 @@ var WorkspaceSecondaryClonesPanel = ({ workspace, onClonesUpdated, onClose }) =>
202
202
  };
203
203
 
204
204
  // src/components/workspace/WorkspaceCreateDialog.tsx
205
- import { useEffect as useEffect2, useMemo, useState as useState4 } from "react";
205
+ import { useCallback as useCallback2, useEffect as useEffect2, useMemo, useRef as useRef2, useState as useState4 } from "react";
206
206
  import { HardDrive as HardDrive3, Loader2 } from "lucide-react";
207
207
 
208
208
  // src/components/workspace/GoogleDriveWorkspacePicker.tsx
209
- import { useCallback, useEffect, useState as useState3 } from "react";
209
+ import { useCallback, useEffect, useRef, useState as useState3 } from "react";
210
210
  import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
211
211
  function getErrorCode(error) {
212
212
  if (!error || typeof error !== "object") return "";
@@ -214,20 +214,26 @@ function getErrorCode(error) {
214
214
  if (typeof candidate.code === "string") return candidate.code.toUpperCase();
215
215
  if (error.name === "AbortError") return "GOOGLE_DRIVE_CANCELLED";
216
216
  const status = candidate.status ?? candidate.response?.status;
217
- return status === 401 ? "GOOGLE_DRIVE_AUTH_EXPIRED" : status === 403 ? "GOOGLE_DRIVE_ACCESS_DENIED" : "";
217
+ return status === 401 ? "GOOGLE_DRIVE_AUTH_EXPIRED" : status === 403 ? "GOOGLE_DRIVE_ACCESS_DENIED" : status === 404 ? "GOOGLE_DRIVE_CONNECTION_REVOKED" : status === 429 ? "SERVICE_UNAVAILABLE" : "";
218
218
  }
219
219
  function describeGoogleDriveError(error) {
220
220
  const code = getErrorCode(error);
221
221
  if (code.includes("CANCEL") || code === "ACCESS_DENIED" || code === "OAUTH_ACCESS_DENIED") {
222
222
  return "Google Drive authorization was cancelled or declined. No connection was added.";
223
223
  }
224
+ if (code.includes("REVOKED") || code === "INVALID_GRANT" || code === "GOOGLE_DRIVE_CONNECTION_NOT_FOUND") {
225
+ return "Google Drive access was revoked or the connection was removed. Reconnect your Google account.";
226
+ }
227
+ if (code.includes("MISSING_CONNECTION") || code.includes("AUTH_FAILED")) {
228
+ return "Google Drive authorization did not return a usable connection. Retry authorization.";
229
+ }
224
230
  if (code.includes("EXPIRED") || code === "UNAUTHENTICATED") {
225
231
  return "Your Google Drive authorization has expired. Reconnect your Google account to continue.";
226
232
  }
227
233
  if (code.includes("DENIED") || code.includes("FORBIDDEN")) {
228
234
  return "Google Drive access was not granted. Authorize Drive access and try again.";
229
235
  }
230
- if (code.includes("UNAVAILABLE") || code.includes("SERVICE_UNAVAILABLE")) {
236
+ if (code.includes("UNAVAILABLE") || code.includes("SERVICE_UNAVAILABLE") || code.includes("RETRY")) {
231
237
  return "Google Drive is currently unavailable. Check Drive access and try again.";
232
238
  }
233
239
  if (error instanceof Error && error.message) return error.message;
@@ -248,31 +254,48 @@ function GoogleDriveWorkspacePicker({
248
254
  const [folderPath, setFolderPath] = useState3([]);
249
255
  const [error, setError] = useState3(null);
250
256
  const [status, setStatus] = useState3(null);
257
+ const [authorizationErrorCode, setAuthorizationErrorCode] = useState3("");
258
+ const listFoldersRef = useRef(listGoogleDriveFolders);
259
+ listFoldersRef.current = listGoogleDriveFolders;
260
+ const latestRequest = useRef(0);
251
261
  const loadFolders = useCallback(async (connectionId, parentFolderId) => {
252
- if (!listGoogleDriveFolders) {
262
+ const request = ++latestRequest.current;
263
+ const browse = listFoldersRef.current;
264
+ if (!browse) {
253
265
  setFolders([]);
254
266
  setError("Google Drive folder browsing is not configured for this storage service.");
255
- return;
267
+ return false;
256
268
  }
257
269
  setLoading(true);
258
270
  setError(null);
271
+ setAuthorizationErrorCode("");
259
272
  try {
260
- const items = await listGoogleDriveFolders(connectionId, parentFolderId, userId);
273
+ const items = await browse(connectionId, parentFolderId, userId);
274
+ if (request !== latestRequest.current) return false;
261
275
  setFolders(Array.isArray(items) ? items.filter((item) => item && typeof item.id === "string" && typeof item.name === "string") : []);
276
+ return true;
262
277
  } catch (reason) {
278
+ if (request !== latestRequest.current) return false;
263
279
  setFolders([]);
280
+ setAuthorizationErrorCode(getErrorCode(reason));
264
281
  setError(describeGoogleDriveError(reason));
282
+ return false;
265
283
  } finally {
266
- setLoading(false);
284
+ if (request === latestRequest.current) setLoading(false);
267
285
  }
268
- }, [listGoogleDriveFolders, userId]);
286
+ }, [userId]);
269
287
  useEffect(() => {
288
+ latestRequest.current += 1;
270
289
  setFolderPath([]);
271
290
  setFolders([]);
272
291
  setError(null);
273
292
  setStatus(null);
293
+ setAuthorizationErrorCode("");
274
294
  if (connection?.id) void loadFolders(connection.id);
275
- }, [connection?.id, loadFolders]);
295
+ return () => {
296
+ latestRequest.current += 1;
297
+ };
298
+ }, [connection?.id, userId, loadFolders]);
276
299
  const handleConnect = async () => {
277
300
  if (!connectGoogleDrive) {
278
301
  setError("Google Drive authorization is not configured for this storage service.");
@@ -301,34 +324,15 @@ function GoogleDriveWorkspacePicker({
301
324
  }
302
325
  };
303
326
  const openFolder = async (folder) => {
304
- if (!connection) return;
305
- setLoading(true);
306
- setError(null);
307
- try {
308
- const items = await listGoogleDriveFolders?.(connection.id, folder.id, userId);
309
- setFolders(Array.isArray(items) ? items : []);
327
+ if (connection && await loadFolders(connection.id, folder.id)) {
310
328
  setFolderPath((current) => [...current, { id: folder.id, name: folder.name }]);
311
- } catch (reason) {
312
- setError(describeGoogleDriveError(reason));
313
- } finally {
314
- setLoading(false);
315
329
  }
316
330
  };
317
331
  const goBack = async () => {
318
332
  if (!connection || folderPath.length === 0) return;
319
333
  const nextPath = folderPath.slice(0, -1);
320
334
  const parentFolderId = nextPath[nextPath.length - 1]?.id;
321
- setLoading(true);
322
- setError(null);
323
- try {
324
- const items = await listGoogleDriveFolders?.(connection.id, parentFolderId, userId);
325
- setFolders(Array.isArray(items) ? items : []);
326
- setFolderPath(nextPath);
327
- } catch (reason) {
328
- setError(describeGoogleDriveError(reason));
329
- } finally {
330
- setLoading(false);
331
- }
335
+ if (await loadFolders(connection.id, parentFolderId)) setFolderPath(nextPath);
332
336
  };
333
337
  const selectCurrentFolder = () => {
334
338
  const current = folderPath[folderPath.length - 1];
@@ -379,6 +383,7 @@ function GoogleDriveWorkspacePicker({
379
383
  /* @__PURE__ */ jsx3("button", { type: "button", onClick: selectCurrentFolder, disabled: loading, className: "ml-auto border px-2 py-1 text-[10px] font-bold disabled:opacity-50", children: "Use this folder" })
380
384
  ] }),
381
385
  error && /* @__PURE__ */ jsx3("p", { role: "alert", className: "text-xs text-red-300", children: error }),
386
+ error && (authorizationErrorCode.includes("EXPIRED") || authorizationErrorCode.includes("REVOKED") || authorizationErrorCode === "INVALID_GRANT") && connectGoogleDrive && /* @__PURE__ */ jsx3("button", { type: "button", onClick: () => void handleConnect(), disabled: connecting, className: "border px-2 py-1 text-[10px] disabled:opacity-50", children: connecting ? "Reconnecting\u2026" : "Reconnect Google Drive" }),
382
387
  status && /* @__PURE__ */ jsx3("p", { role: "status", className: "text-xs", children: status }),
383
388
  selectedFolder && /* @__PURE__ */ jsxs3("p", { className: "text-[10px]", children: [
384
389
  "Selected workspace root: ",
@@ -527,16 +532,15 @@ function createKloksWorkspaceStorageService(invoker) {
527
532
  }
528
533
  const result = await invoker.invoke("kloks.backend.storage", "createGoogleDriveAuthorizationRequest", {
529
534
  userId,
530
- returnTo: window.location.href,
531
- callbackOrigin: window.location.origin
535
+ returnTo: window.location.href
532
536
  });
533
537
  const authorizationUrl = result?.authorizationUrl;
534
538
  if (typeof authorizationUrl !== "string") {
535
539
  throw new Error("Kloks did not return a Google Drive authorization URL.");
536
540
  }
537
541
  const parsed = new URL(authorizationUrl);
538
- if (parsed.origin !== "https://accounts.google.com") {
539
- throw new Error("Kloks returned an untrusted Google Drive authorization destination.");
542
+ if (parsed.protocol !== "https:" && !(parsed.protocol === "http:" && ["localhost", "127.0.0.1", "[::1]"].includes(parsed.hostname))) {
543
+ throw new Error("Kloks returned an unsafe Google Drive authorization destination.");
540
544
  }
541
545
  window.location.assign(parsed.toString());
542
546
  },
@@ -577,22 +581,27 @@ function createKloksWorkspaceStorageService(invoker) {
577
581
  }
578
582
  function WorkspaceCreateDialog({
579
583
  open,
580
- userId = "system",
584
+ userId,
581
585
  currentUser,
582
586
  appName = "app",
583
587
  storageOptions,
584
588
  storageService = defaultWorkspaceStorageService,
585
589
  visibility,
586
590
  googleDriveConnectionId,
591
+ googleDriveErrorCode,
587
592
  onClose,
588
593
  onSubmit
589
594
  }) {
590
595
  const [loadedOptions, setLoadedOptions] = useState4([]);
591
596
  const [providerCapabilities, setProviderCapabilities] = useState4([]);
592
597
  const [connectedDriveOption, setConnectedDriveOption] = useState4(null);
598
+ const [loadedOwnerId, setLoadedOwnerId] = useState4(null);
599
+ const [refreshConnectionsVersion, setRefreshConnectionsVersion] = useState4(0);
600
+ const [verifiedGoogleDrive, setVerifiedGoogleDrive] = useState4(null);
601
+ const storageServiceRef = useRef2(storageService);
602
+ storageServiceRef.current = storageService;
593
603
  const [connectedBackblazeOption, setConnectedBackblazeOption] = useState4(null);
594
604
  const [googleDriveFolder, setGoogleDriveFolder] = useState4(null);
595
- const [verifiedGoogleDriveConnectionId, setVerifiedGoogleDriveConnectionId] = useState4(null);
596
605
  const [name, setName] = useState4("");
597
606
  const [description, setDescription] = useState4("");
598
607
  const [localFolderName, setLocalFolderName] = useState4("");
@@ -610,7 +619,13 @@ function WorkspaceCreateDialog({
610
619
  const [loadingStorage, setLoadingStorage] = useState4(false);
611
620
  const [submitting, setSubmitting] = useState4(false);
612
621
  const [error, setError] = useState4(null);
613
- const effectiveUserId = userId || currentUser?.id || "system";
622
+ const effectiveUserId = (userId && userId !== "system" ? userId : currentUser?.id) || userId || "system";
623
+ const verifiedGoogleDriveConnectionId = verifiedGoogleDrive?.userId === effectiveUserId ? verifiedGoogleDrive.connectionId : null;
624
+ const browseGoogleDriveFolders = useCallback2((connectionId, parentFolderId) => {
625
+ const browse = storageServiceRef.current.listGoogleDriveFolders;
626
+ if (!browse) return Promise.reject(new Error("Google Drive folder browsing is not configured."));
627
+ return browse(connectionId, parentFolderId, effectiveUserId);
628
+ }, [effectiveUserId]);
614
629
  useEffect2(() => {
615
630
  if (!open) return;
616
631
  setName("");
@@ -627,14 +642,18 @@ function WorkspaceCreateDialog({
627
642
  setNewBackblazeBucketName("");
628
643
  setBackblazeCredentialsTested(false);
629
644
  setConnectedDriveOption(null);
645
+ setLoadedOptions([]);
646
+ setLoadedOwnerId(null);
647
+ setProviderCapabilities([]);
630
648
  setConnectedBackblazeOption(null);
631
649
  setGoogleDriveFolder(null);
632
- setVerifiedGoogleDriveConnectionId(null);
633
- }, [open]);
650
+ setVerifiedGoogleDrive(null);
651
+ }, [open, effectiveUserId]);
634
652
  useEffect2(() => {
635
- if (!open || !storageService.listStorageProviderCapabilities) return;
653
+ const listCapabilities = storageServiceRef.current.listStorageProviderCapabilities;
654
+ if (!open || !listCapabilities) return;
636
655
  let active = true;
637
- storageService.listStorageProviderCapabilities(effectiveUserId).then((items) => {
656
+ listCapabilities(effectiveUserId).then((items) => {
638
657
  if (active) setProviderCapabilities(Array.isArray(items) ? items : []);
639
658
  }).catch((reason) => {
640
659
  if (active) setError(reason instanceof Error ? reason.message : "Unable to load storage provider capabilities.");
@@ -642,68 +661,53 @@ function WorkspaceCreateDialog({
642
661
  return () => {
643
662
  active = false;
644
663
  };
645
- }, [open, effectiveUserId, storageService]);
664
+ }, [open, effectiveUserId]);
646
665
  useEffect2(() => {
647
- if (!open || !googleDriveConnectionId) return;
648
- const exists = (storageOptions ?? loadedOptions).some((option) => option.id === googleDriveConnectionId);
649
- if (exists) {
650
- setSelectedStorageId(googleDriveConnectionId);
651
- setBackblazeMode(false);
652
- }
653
- }, [open, googleDriveConnectionId, storageOptions, loadedOptions]);
666
+ if (!open || !googleDriveErrorCode) return;
667
+ setError(describeGoogleDriveError({ code: googleDriveErrorCode }));
668
+ }, [open, googleDriveErrorCode]);
654
669
  useEffect2(() => {
655
- if (!open || !storageService.getGoogleDriveAccountIdentity) return;
656
- const connection = (storageOptions ?? loadedOptions).find(
657
- (option) => option.id === selectedStorageId && option.provider === "google_drive"
658
- ) || (connectedDriveOption?.id === selectedStorageId ? connectedDriveOption : void 0);
659
- if (!connection) {
660
- setVerifiedGoogleDriveConnectionId(null);
670
+ if (!open || !googleDriveConnectionId) return;
671
+ if (storageServiceRef.current.listStorageConnections && loadedOwnerId !== effectiveUserId) return;
672
+ const connections = storageServiceRef.current.listStorageConnections ? loadedOptions : storageOptions ?? [];
673
+ const resumed = connections.find(
674
+ (option) => option.id === googleDriveConnectionId && option.provider === "google_drive" && option.enabled !== false
675
+ );
676
+ if (!resumed) {
677
+ setError("Google Drive connection could not be restored for this account. Retry authorization.");
661
678
  return;
662
679
  }
663
- let active = true;
664
- setVerifiedGoogleDriveConnectionId(null);
665
- storageService.getGoogleDriveAccountIdentity(effectiveUserId, connection.id).then((identity) => {
666
- if (!active) return;
667
- setConnectedDriveOption({
668
- ...connection,
669
- googleAccountId: identity.accountId,
670
- googleEmail: identity.email || connection.googleEmail
671
- });
672
- setVerifiedGoogleDriveConnectionId(connection.id);
673
- }).catch((reason) => {
674
- if (active) {
675
- setVerifiedGoogleDriveConnectionId(null);
676
- setError(reason instanceof Error ? reason.message : "Unable to verify the Google Drive account identity.");
677
- }
678
- });
679
- return () => {
680
- active = false;
681
- };
682
- }, [open, selectedStorageId, storageOptions, loadedOptions, connectedDriveOption, effectiveUserId, storageService]);
680
+ setSelectedStorageId(resumed.id);
681
+ setBackblazeMode(false);
682
+ setDefaultStorageApplied(true);
683
+ setError(null);
684
+ }, [open, googleDriveConnectionId, effectiveUserId, loadedOwnerId, loadedOptions, storageOptions]);
683
685
  useEffect2(() => {
684
- if (!open || storageOptions) return;
686
+ if (!open) return;
685
687
  let active = true;
686
- const listConnections = storageService.listStorageConnections;
688
+ const listConnections = storageServiceRef.current.listStorageConnections;
687
689
  if (!listConnections) {
688
690
  setLoadingStorage(false);
689
- return () => {
690
- active = false;
691
- };
691
+ return;
692
692
  }
693
693
  setLoadingStorage(true);
694
+ setLoadedOwnerId(null);
695
+ setLoadedOptions([]);
694
696
  listConnections(effectiveUserId).then((options) => {
695
- if (active) setLoadedOptions(Array.isArray(options) ? options : []);
697
+ if (!active) return;
698
+ setLoadedOptions(Array.isArray(options) ? options : []);
699
+ setLoadedOwnerId(effectiveUserId);
696
700
  }).catch((reason) => {
697
- if (active) setError(reason instanceof Error ? reason.message : "Unable to load storage connections.");
701
+ if (active) setError(describeGoogleDriveError(reason));
698
702
  }).finally(() => {
699
703
  if (active) setLoadingStorage(false);
700
704
  });
701
705
  return () => {
702
706
  active = false;
703
707
  };
704
- }, [open, effectiveUserId, storageOptions, storageService]);
708
+ }, [open, effectiveUserId, refreshConnectionsVersion]);
705
709
  const availableOptions = useMemo(() => {
706
- const supplied = storageOptions ?? loadedOptions;
710
+ const supplied = storageServiceRef.current.listStorageConnections ? loadedOwnerId === effectiveUserId ? loadedOptions : [] : storageOptions ?? loadedOptions;
707
711
  const providerOrder = visibility?.storagePolicy?.providers ?? visibility?.availableStorageProviders ?? providerCapabilities.map((capability) => capability.id);
708
712
  const hidden = new Set(visibility?.hiddenStorageProviders || []);
709
713
  const enabled = supplied.filter(
@@ -720,7 +724,10 @@ function WorkspaceCreateDialog({
720
724
  const capability = providerCapabilities.find((item) => item.id === provider);
721
725
  const canAuthorize = Boolean(capability?.enabled && capability.canCreateConnection);
722
726
  const label = canAuthorize ? "Connect Google Drive" : "Google Drive authorization unavailable";
723
- return connections.length > 0 ? connections : [{ id: "google_drive", provider: "google_drive", label }];
727
+ return [
728
+ ...connections,
729
+ ...canAuthorize || connections.length === 0 ? [{ id: "google_drive", provider: "google_drive", label }] : []
730
+ ];
724
731
  }
725
732
  if (provider === "backblaze_b2") {
726
733
  const connections = [
@@ -735,29 +742,70 @@ function WorkspaceCreateDialog({
735
742
  }
736
743
  return forProvider(provider);
737
744
  });
738
- }, [storageOptions, loadedOptions, connectedDriveOption, connectedBackblazeOption, visibility, providerCapabilities]);
745
+ }, [storageOptions, loadedOptions, loadedOwnerId, effectiveUserId, connectedDriveOption, connectedBackblazeOption, visibility, providerCapabilities]);
746
+ const selectedGoogleProvider = availableOptions.find((option) => option.id === selectedStorageId)?.provider;
747
+ useEffect2(() => {
748
+ setGoogleDriveFolder(null);
749
+ }, [effectiveUserId, selectedStorageId]);
750
+ useEffect2(() => {
751
+ const identify = storageServiceRef.current.getGoogleDriveAccountIdentity;
752
+ if (!open || selectedGoogleProvider !== "google_drive" || selectedStorageId === "google_drive" || !identify) {
753
+ setVerifiedGoogleDrive(null);
754
+ return;
755
+ }
756
+ let active = true;
757
+ setVerifiedGoogleDrive(null);
758
+ identify(effectiveUserId, selectedStorageId).then((identity) => {
759
+ if (!active) return;
760
+ if (!identity || typeof identity.accountId !== "string" || !identity.accountId) {
761
+ throw new Error("Kloks did not confirm a Google Drive account identity.");
762
+ }
763
+ setVerifiedGoogleDrive({ userId: effectiveUserId, connectionId: selectedStorageId });
764
+ setConnectedDriveOption((old) => {
765
+ const base = availableOptions.find((option) => option.id === selectedStorageId);
766
+ if (!base) return old;
767
+ return { ...base, googleAccountId: identity.accountId, googleEmail: identity.email || base.googleEmail };
768
+ });
769
+ }).catch((reason) => {
770
+ if (active) {
771
+ setVerifiedGoogleDrive(null);
772
+ setError(describeGoogleDriveError(reason));
773
+ }
774
+ });
775
+ return () => {
776
+ active = false;
777
+ };
778
+ }, [open, selectedStorageId, selectedGoogleProvider, effectiveUserId]);
739
779
  useEffect2(() => {
740
- if (!open || loadingStorage || defaultStorageApplied) return;
780
+ if (!open || loadingStorage || defaultStorageApplied || googleDriveConnectionId || storageServiceRef.current.listStorageConnections && loadedOwnerId !== effectiveUserId) return;
741
781
  const primary = availableOptions.find((option) => option.role === "primary") || availableOptions.find((option) => option.provider !== "local_fs" && option.id !== "google_drive");
742
782
  const preferred = primary || availableOptions[0];
743
783
  if (preferred) setSelectedStorageId(preferred.id);
744
784
  setDefaultStorageApplied(true);
745
- }, [open, loadingStorage, availableOptions, defaultStorageApplied]);
785
+ }, [open, loadingStorage, availableOptions, defaultStorageApplied, loadedOwnerId, effectiveUserId, googleDriveConnectionId]);
746
786
  useEffect2(() => {
747
787
  if (!open) return;
788
+ const restored = googleDriveConnectionId && availableOptions.find(
789
+ (option) => option.id === googleDriveConnectionId && option.provider === "google_drive"
790
+ );
791
+ if (restored) {
792
+ if (selectedStorageId !== restored.id) setSelectedStorageId(restored.id);
793
+ return;
794
+ }
748
795
  const selectedStillExists = backblazeMode || availableOptions.some((option) => option.id === selectedStorageId);
749
796
  if (!selectedStillExists) {
750
797
  const primary = availableOptions.find((option) => option.role === "primary");
751
798
  setSelectedStorageId(primary?.id || availableOptions[0]?.id || "");
752
799
  }
753
- }, [open, availableOptions, selectedStorageId, backblazeMode]);
800
+ }, [open, availableOptions, selectedStorageId, backblazeMode, googleDriveConnectionId]);
754
801
  if (!open) return null;
755
802
  const selectedOption = availableOptions.find((option) => option.id === selectedStorageId) || availableOptions[0] || NO_STORAGE_OPTION;
756
803
  const googleDriveCapability = providerCapabilities.find((capability) => capability.id === "google_drive");
757
804
  const backblazeCapability = providerCapabilities.find((capability) => capability.id === "backblaze_b2");
758
805
  const canCreateBackblazeConnection = Boolean(backblazeCapability?.enabled && backblazeCapability.canCreateConnection);
759
806
  const canAuthorizeGoogleDrive = Boolean(googleDriveCapability?.enabled && googleDriveCapability.canCreateConnection);
760
- const googleDriveConnection = selectedOption.provider === "google_drive" && selectedOption.id !== "google_drive" ? selectedOption : void 0;
807
+ const unverifiedDriveConnection = selectedOption.provider === "google_drive" && selectedOption.id !== "google_drive" ? selectedOption : void 0;
808
+ const googleDriveConnection = verifiedGoogleDriveConnectionId === unverifiedDriveConnection?.id ? unverifiedDriveConnection : void 0;
761
809
  const hiddenFields = new Set(visibility?.hiddenFields || []);
762
810
  const userName = currentUser?.username || currentUser?.name || currentUser?.email?.split("@")[0] || "user";
763
811
  const folderPreview = formatWorkspaceFolderPreview(appName, userName, name || "workspace");
@@ -892,16 +940,6 @@ function WorkspaceCreateDialog({
892
940
  setSubmitting(true);
893
941
  setError(null);
894
942
  try {
895
- if (selectedOption.provider === "google_drive" && googleDriveFolder) {
896
- if (!googleDriveConnection || !storageService.selectGoogleDriveRootFolder) {
897
- throw new Error("Google Drive root selection is not configured through the canonical Kloks storage service.");
898
- }
899
- await storageService.selectGoogleDriveRootFolder(
900
- effectiveUserId,
901
- googleDriveConnection.id,
902
- googleDriveFolder.id
903
- );
904
- }
905
943
  const option = selectedOption.provider === "local_fs" ? { ...selectedOption, localFolderName: localFolderName.trim() || selectedOption.localFolderName || name.trim() } : selectedOption.provider === "google_drive" && googleDriveFolder ? {
906
944
  ...selectedOption,
907
945
  googleRootFolderId: googleDriveFolder.id,
@@ -1097,21 +1135,31 @@ function WorkspaceCreateDialog({
1097
1135
  " Loading storage connections\u2026"
1098
1136
  ] }) : availableOptions.length === 0 ? /* @__PURE__ */ jsx4("p", { className: "text-[10px]", style: { color: muted }, children: "This application has not enabled a workspace storage provider." }) : /* @__PURE__ */ jsx4("p", { className: "text-[10px]", style: { color: muted }, children: "Choose from the storage providers explicitly enabled by this application." })
1099
1137
  ] }),
1100
- selectedOption.provider === "google_drive" && /* @__PURE__ */ jsx4(
1138
+ selectedOption.provider === "google_drive" && unverifiedDriveConnection && !googleDriveConnection ? /* @__PURE__ */ jsxs4("div", { role: "status", className: "border p-3 text-xs", children: [
1139
+ "Google Drive account verification is required before browsing folders.",
1140
+ canAuthorizeGoogleDrive && /* @__PURE__ */ jsx4("p", { className: "mt-2", children: "You can choose \u201CConnect Google Drive\u201D in the storage selector to reconnect or add an account." })
1141
+ ] }) : selectedOption.provider === "google_drive" && /* @__PURE__ */ jsx4(
1101
1142
  GoogleDriveWorkspacePicker,
1102
1143
  {
1103
1144
  userId: effectiveUserId,
1104
1145
  connection: googleDriveConnection,
1105
1146
  connectGoogleDrive: canAuthorizeGoogleDrive ? storageService.connectGoogleDrive : void 0,
1106
- listGoogleDriveFolders: storageService.listGoogleDriveFolders ? (connectionId, parentFolderId) => storageService.listGoogleDriveFolders(connectionId, parentFolderId, effectiveUserId) : void 0,
1147
+ listGoogleDriveFolders: storageService.listGoogleDriveFolders ? browseGoogleDriveFolders : void 0,
1107
1148
  selectedFolder: googleDriveFolder,
1108
1149
  onConnected: (connection) => {
1109
1150
  if (connection.provider !== "google_drive") {
1110
1151
  setError("The storage service returned a non-Google Drive connection.");
1111
1152
  return;
1112
1153
  }
1154
+ if (!connection.id || connection.id === "google_drive") {
1155
+ setError("Kloks did not return an opaque Google Drive connection ID.");
1156
+ return;
1157
+ }
1113
1158
  setConnectedDriveOption(connection);
1114
1159
  setSelectedStorageId(connection.id);
1160
+ if (storageServiceRef.current.listStorageConnections) {
1161
+ setRefreshConnectionsVersion((version) => version + 1);
1162
+ }
1115
1163
  setGoogleDriveFolder(null);
1116
1164
  setError(null);
1117
1165
  },
@@ -1182,20 +1230,24 @@ function WorkspaceTilesMenu({
1182
1230
  error = null
1183
1231
  }) {
1184
1232
  const store = useFloksFrnlStore();
1185
- const effectiveUserId = userId || currentUser?.id || "system";
1233
+ const effectiveUserId = (userId && userId !== "system" ? userId : currentUser?.id) || userId || "system";
1186
1234
  const generated = useId().replace(/[:/]/g, "");
1187
1235
  const componentId = `workspaceTilesMenu.${generated}`;
1188
1236
  const [creating, setCreating] = useState5(false);
1189
1237
  const [googleDriveConnectionId, setGoogleDriveConnectionId] = useState5();
1238
+ const [googleDriveErrorCode, setGoogleDriveErrorCode] = useState5();
1190
1239
  useEffect3(() => {
1191
1240
  if (typeof window === "undefined") return;
1192
1241
  const url = new URL(window.location.href);
1193
1242
  const connected = url.searchParams.get("googleDriveConnected") === "1";
1194
1243
  const failed = url.searchParams.get("googleDriveError") === "1";
1195
1244
  const connectionId = url.searchParams.get("googleDriveConnectionId") || void 0;
1245
+ const rawErrorCode = url.searchParams.get("googleDriveErrorCode");
1246
+ const errorCode = rawErrorCode && /^[A-Za-z0-9_:-]{1,80}$/.test(rawErrorCode) ? rawErrorCode : "GOOGLE_DRIVE_AUTH_FAILED";
1196
1247
  if (connected || failed) {
1197
1248
  setCreating(true);
1198
- setGoogleDriveConnectionId(connectionId);
1249
+ setGoogleDriveConnectionId(connected ? connectionId : void 0);
1250
+ setGoogleDriveErrorCode(failed ? errorCode : connected && !connectionId ? "GOOGLE_DRIVE_MISSING_CONNECTION" : void 0);
1199
1251
  url.searchParams.delete("googleDriveConnected");
1200
1252
  url.searchParams.delete("googleDriveError");
1201
1253
  url.searchParams.delete("googleDriveConnectionId");
@@ -1203,6 +1255,14 @@ function WorkspaceTilesMenu({
1203
1255
  window.history.replaceState(window.history.state, "", url.toString());
1204
1256
  }
1205
1257
  }, []);
1258
+ const [callbackOwner, setCallbackOwner] = useState5(effectiveUserId);
1259
+ useEffect3(() => {
1260
+ if (callbackOwner === effectiveUserId) return;
1261
+ setCallbackOwner(effectiveUserId);
1262
+ setGoogleDriveConnectionId(void 0);
1263
+ setGoogleDriveErrorCode(void 0);
1264
+ setCreating(false);
1265
+ }, [callbackOwner, effectiveUserId]);
1206
1266
  const handlers = useMemo2(() => ({
1207
1267
  "workspaceTilesMenu.idle.select": (value) => onSelectWorkspace(value),
1208
1268
  "workspaceTilesMenu.idle.create": () => setCreating(true),
@@ -1246,7 +1306,11 @@ function WorkspaceTilesMenu({
1246
1306
  ] })
1247
1307
  }
1248
1308
  ),
1249
- /* @__PURE__ */ jsx5(WorkspaceCreateDialog, { open: creating, userId: effectiveUserId, currentUser, appName, storageOptions, storageService, visibility, googleDriveConnectionId, onClose: () => setCreating(false), onSubmit: onCreateWorkspace })
1309
+ /* @__PURE__ */ jsx5(WorkspaceCreateDialog, { open: creating, userId: effectiveUserId, currentUser, appName, storageOptions, storageService, visibility, googleDriveConnectionId, googleDriveErrorCode, onClose: () => {
1310
+ setCreating(false);
1311
+ setGoogleDriveConnectionId(void 0);
1312
+ setGoogleDriveErrorCode(void 0);
1313
+ }, onSubmit: onCreateWorkspace })
1250
1314
  ] });
1251
1315
  }
1252
1316
 
@@ -1282,7 +1346,7 @@ var WorkspaceGate = ({
1282
1346
  description: w.description || "Workspace vault for workflows and graph state",
1283
1347
  workspacePath: w.workspacePath || "./projects",
1284
1348
  storageProvider: w.storageProvider || w.storage?.provider || "local_fs",
1285
- storageConnectionId: w.storageConnectionId || w.storage?.storageConnectionId,
1349
+ storageConnectionId: w.storageConnectionId || w.storage?.connectionId,
1286
1350
  b2BucketName: w.b2BucketName || w.storage?.b2BucketName,
1287
1351
  b2Endpoint: w.b2Endpoint || w.storage?.b2Endpoint,
1288
1352
  b2Region: w.b2Region || w.storage?.b2Region,
@@ -1290,7 +1354,7 @@ var WorkspaceGate = ({
1290
1354
  metadata: w.metadata
1291
1355
  }));
1292
1356
  }, [workspaces]);
1293
- const effectiveUserId = userId || currentUser?.id || "system";
1357
+ const effectiveUserId = (userId && userId !== "system" ? userId : currentUser?.id) || userId || "system";
1294
1358
  return /* @__PURE__ */ jsx6(
1295
1359
  "div",
1296
1360
  {
@@ -124,6 +124,7 @@ export interface WorkspaceCreateDialogProps {
124
124
  storageService?: WorkspaceStorageService;
125
125
  visibility?: WorkspaceCreateDialogVisibility;
126
126
  googleDriveConnectionId?: string;
127
+ googleDriveErrorCode?: string;
127
128
  onClose: () => void;
128
129
  onSubmit: (input: WorkspaceCreateInput) => Promise<void> | void;
129
130
  }
@@ -144,4 +145,4 @@ export interface KloksServiceInvoker {
144
145
  * exchanges OAuth codes, persists tokens, or calls provider APIs directly.
145
146
  */
146
147
  export declare function createKloksWorkspaceStorageService(invoker: KloksServiceInvoker): WorkspaceStorageService;
147
- export declare function WorkspaceCreateDialog({ open, userId, currentUser, appName, storageOptions, storageService, visibility, googleDriveConnectionId, onClose, onSubmit, }: WorkspaceCreateDialogProps): React.JSX.Element;
148
+ export declare function WorkspaceCreateDialog({ open, userId, currentUser, appName, storageOptions, storageService, visibility, googleDriveConnectionId, googleDriveErrorCode, onClose, onSubmit, }: WorkspaceCreateDialogProps): React.JSX.Element;
@@ -12,7 +12,7 @@ import {
12
12
  describeGoogleDriveError,
13
13
  formatWorkspaceFolderPreview,
14
14
  workspaceTilesMenuDefinition
15
- } from "../../chunk-FVOZFKV7.js";
15
+ } from "../../chunk-EHKGMGSD.js";
16
16
  import "../../chunk-DEKSKDSF.js";
17
17
  import "../../chunk-2YP2RPJY.js";
18
18
  export {
@@ -1,3 +1,10 @@
1
+ import {
2
+ MIDI_MAX,
3
+ MIDI_MIN,
4
+ MIDI_TIMELINE_HEIGHT,
5
+ MidiTimeline,
6
+ MusicalTimeline
7
+ } from "./chunk-HXTM3RSQ.js";
1
8
  import {
2
9
  GoogleDriveWorkspacePicker,
3
10
  WORKSPACE_TILES_MENU_REQUIRED_SERVICES,
@@ -12,14 +19,7 @@ import {
12
19
  describeGoogleDriveError,
13
20
  formatWorkspaceFolderPreview,
14
21
  workspaceTilesMenuDefinition
15
- } from "./chunk-FVOZFKV7.js";
16
- import {
17
- MIDI_MAX,
18
- MIDI_MIN,
19
- MIDI_TIMELINE_HEIGHT,
20
- MidiTimeline,
21
- MusicalTimeline
22
- } from "./chunk-HXTM3RSQ.js";
22
+ } from "./chunk-EHKGMGSD.js";
23
23
  import {
24
24
  ConfirmDialog,
25
25
  CopyableErrorAlert,