@ultrst-armada/floks 2.0.17 → 2.0.19

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.19",
5
+ "sourceCommit": "d302d78e33021dad3bddcc94c688705d3f3ae8c2",
6
6
  "releaseWorkflow": "npm Release",
7
- "workflowRunId": "45017683774"
7
+ "workflowRunId": "45332991171"
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.19",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public",
@@ -1,34 +1,8 @@
1
- import {
2
- BIOME_CONFIGS,
3
- COORD_SCALE,
4
- CanvasBackground2D,
5
- CanvasErrorBoundary,
6
- ContainerNode2D,
7
- EffectNode2D,
8
- MagneticTraces2D,
9
- ModuleNode2D,
10
- NODE_CARD_WIDTH,
11
- Node2DBase,
12
- NodeRenderer2D,
13
- RecorderWaveformDisplay,
14
- RotaryKnob,
15
- SOCKET_ROW_HEIGHT,
16
- Socket2D,
17
- TriggerNode2D,
18
- Wire2D,
19
- renderSpriteIcon,
20
- useCanvas2DCoordinates,
21
- useCanvas2DMagnetic
22
- } from "./chunk-ZDADZVQ2.js";
23
1
  import {
24
2
  PredictiveGhostNodeCard,
25
3
  PredictiveHudToolbar,
26
4
  PredictiveLayer2D
27
5
  } from "./chunk-A7BSZ5QO.js";
28
- import {
29
- getSocketLocalOffset,
30
- getSocketScreenPosition
31
- } from "./chunk-FPRATI44.js";
32
6
  import {
33
7
  Tile,
34
8
  TileCreateButton,
@@ -39,6 +13,12 @@ import {
39
13
  AikoModule,
40
14
  EmbeddedAikoModule
41
15
  } from "./chunk-OH7S4XFZ.js";
16
+ import {
17
+ CanvasViewport,
18
+ InfiniteCanvas,
19
+ MiniMap,
20
+ useCanvas
21
+ } from "./chunk-34YRDZPJ.js";
42
22
  import {
43
23
  UiAuthoringBindingEditor,
44
24
  UiAuthoringInspector,
@@ -98,11 +78,31 @@ import {
98
78
  usePredictiveGraph2D
99
79
  } from "./chunk-ZSVXR3HU.js";
100
80
  import {
101
- CanvasViewport,
102
- InfiniteCanvas,
103
- MiniMap,
104
- useCanvas
105
- } from "./chunk-34YRDZPJ.js";
81
+ BIOME_CONFIGS,
82
+ COORD_SCALE,
83
+ CanvasBackground2D,
84
+ CanvasErrorBoundary,
85
+ ContainerNode2D,
86
+ EffectNode2D,
87
+ MagneticTraces2D,
88
+ ModuleNode2D,
89
+ NODE_CARD_WIDTH,
90
+ Node2DBase,
91
+ NodeRenderer2D,
92
+ RecorderWaveformDisplay,
93
+ RotaryKnob,
94
+ SOCKET_ROW_HEIGHT,
95
+ Socket2D,
96
+ TriggerNode2D,
97
+ Wire2D,
98
+ renderSpriteIcon,
99
+ useCanvas2DCoordinates,
100
+ useCanvas2DMagnetic
101
+ } from "./chunk-ZDADZVQ2.js";
102
+ import {
103
+ getSocketLocalOffset,
104
+ getSocketScreenPosition
105
+ } from "./chunk-FPRATI44.js";
106
106
 
107
107
  // src/node-graph-ui/widgets/MidpointWidgets.tsx
108
108
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
@@ -3,10 +3,10 @@ import {
3
3
  PredictiveHudToolbar,
4
4
  PredictiveLayer2D
5
5
  } from "../chunk-A7BSZ5QO.js";
6
- import "../chunk-FPRATI44.js";
7
6
  import {
8
7
  usePredictiveGraph2D
9
8
  } from "../chunk-ZSVXR3HU.js";
9
+ import "../chunk-FPRATI44.js";
10
10
  export {
11
11
  PredictiveGhostNodeCard,
12
12
  PredictiveHudToolbar,
@@ -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];
@@ -348,7 +352,7 @@ function GoogleDriveWorkspacePicker({
348
352
  onClick: handleConnect,
349
353
  disabled: connecting || !connectGoogleDrive,
350
354
  className: "border px-3 py-2 text-xs font-bold disabled:opacity-50",
351
- children: connecting ? "Connecting to Google\u2026" : connectGoogleDrive ? "Connect Google Drive" : "Google Drive authorization unavailable"
355
+ children: connecting ? "Opening Google account chooser\u2026" : connectGoogleDrive ? "Add Google account" : "Google Drive authorization unavailable"
352
356
  }
353
357
  )
354
358
  ] });
@@ -359,16 +363,28 @@ function GoogleDriveWorkspacePicker({
359
363
  /* @__PURE__ */ jsx3("p", { className: "text-xs font-bold", children: "Google Drive connected" }),
360
364
  /* @__PURE__ */ jsx3("p", { className: "truncate text-[10px] opacity-70", children: connection.googleEmail || connection.label || connection.name || connection.id })
361
365
  ] }),
362
- /* @__PURE__ */ jsx3(
363
- "button",
364
- {
365
- type: "button",
366
- onClick: () => void loadFolders(connection.id, folderPath[folderPath.length - 1]?.id),
367
- disabled: loading,
368
- className: "border px-2 py-1 text-[10px] disabled:opacity-50",
369
- children: loading ? "Loading\u2026" : "Refresh"
370
- }
371
- )
366
+ /* @__PURE__ */ jsxs3("div", { className: "flex shrink-0 flex-wrap gap-2", children: [
367
+ connectGoogleDrive && /* @__PURE__ */ jsx3(
368
+ "button",
369
+ {
370
+ type: "button",
371
+ onClick: () => void handleConnect(),
372
+ disabled: connecting,
373
+ className: "border px-2 py-1 text-[10px] disabled:opacity-50",
374
+ children: connecting ? "Opening Google\u2026" : "Add Google account"
375
+ }
376
+ ),
377
+ /* @__PURE__ */ jsx3(
378
+ "button",
379
+ {
380
+ type: "button",
381
+ onClick: () => void loadFolders(connection.id, folderPath[folderPath.length - 1]?.id),
382
+ disabled: loading,
383
+ className: "border px-2 py-1 text-[10px] disabled:opacity-50",
384
+ children: loading ? "Loading\u2026" : "Refresh"
385
+ }
386
+ )
387
+ ] })
372
388
  ] }),
373
389
  folderPath.length > 0 && /* @__PURE__ */ jsxs3("div", { className: "flex flex-wrap items-center gap-2", children: [
374
390
  /* @__PURE__ */ jsx3("button", { type: "button", onClick: goBack, disabled: loading, className: "border px-2 py-1 text-[10px] disabled:opacity-50", children: "Back" }),
@@ -379,6 +395,7 @@ function GoogleDriveWorkspacePicker({
379
395
  /* @__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
396
  ] }),
381
397
  error && /* @__PURE__ */ jsx3("p", { role: "alert", className: "text-xs text-red-300", children: error }),
398
+ 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
399
  status && /* @__PURE__ */ jsx3("p", { role: "status", className: "text-xs", children: status }),
383
400
  selectedFolder && /* @__PURE__ */ jsxs3("p", { className: "text-[10px]", children: [
384
401
  "Selected workspace root: ",
@@ -527,16 +544,15 @@ function createKloksWorkspaceStorageService(invoker) {
527
544
  }
528
545
  const result = await invoker.invoke("kloks.backend.storage", "createGoogleDriveAuthorizationRequest", {
529
546
  userId,
530
- returnTo: window.location.href,
531
- callbackOrigin: window.location.origin
547
+ returnTo: window.location.href
532
548
  });
533
549
  const authorizationUrl = result?.authorizationUrl;
534
550
  if (typeof authorizationUrl !== "string") {
535
551
  throw new Error("Kloks did not return a Google Drive authorization URL.");
536
552
  }
537
553
  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.");
554
+ if (parsed.protocol !== "https:" && !(parsed.protocol === "http:" && ["localhost", "127.0.0.1", "[::1]"].includes(parsed.hostname))) {
555
+ throw new Error("Kloks returned an unsafe Google Drive authorization destination.");
540
556
  }
541
557
  window.location.assign(parsed.toString());
542
558
  },
@@ -577,22 +593,27 @@ function createKloksWorkspaceStorageService(invoker) {
577
593
  }
578
594
  function WorkspaceCreateDialog({
579
595
  open,
580
- userId = "system",
596
+ userId,
581
597
  currentUser,
582
598
  appName = "app",
583
599
  storageOptions,
584
600
  storageService = defaultWorkspaceStorageService,
585
601
  visibility,
586
602
  googleDriveConnectionId,
603
+ googleDriveErrorCode,
587
604
  onClose,
588
605
  onSubmit
589
606
  }) {
590
607
  const [loadedOptions, setLoadedOptions] = useState4([]);
591
608
  const [providerCapabilities, setProviderCapabilities] = useState4([]);
592
609
  const [connectedDriveOption, setConnectedDriveOption] = useState4(null);
610
+ const [loadedOwnerId, setLoadedOwnerId] = useState4(null);
611
+ const [refreshConnectionsVersion, setRefreshConnectionsVersion] = useState4(0);
612
+ const [verifiedGoogleDrive, setVerifiedGoogleDrive] = useState4(null);
613
+ const storageServiceRef = useRef2(storageService);
614
+ storageServiceRef.current = storageService;
593
615
  const [connectedBackblazeOption, setConnectedBackblazeOption] = useState4(null);
594
616
  const [googleDriveFolder, setGoogleDriveFolder] = useState4(null);
595
- const [verifiedGoogleDriveConnectionId, setVerifiedGoogleDriveConnectionId] = useState4(null);
596
617
  const [name, setName] = useState4("");
597
618
  const [description, setDescription] = useState4("");
598
619
  const [localFolderName, setLocalFolderName] = useState4("");
@@ -610,7 +631,13 @@ function WorkspaceCreateDialog({
610
631
  const [loadingStorage, setLoadingStorage] = useState4(false);
611
632
  const [submitting, setSubmitting] = useState4(false);
612
633
  const [error, setError] = useState4(null);
613
- const effectiveUserId = userId || currentUser?.id || "system";
634
+ const effectiveUserId = (userId && userId !== "system" ? userId : currentUser?.id) || userId || "system";
635
+ const verifiedGoogleDriveConnectionId = verifiedGoogleDrive?.userId === effectiveUserId ? verifiedGoogleDrive.connectionId : null;
636
+ const browseGoogleDriveFolders = useCallback2((connectionId, parentFolderId) => {
637
+ const browse = storageServiceRef.current.listGoogleDriveFolders;
638
+ if (!browse) return Promise.reject(new Error("Google Drive folder browsing is not configured."));
639
+ return browse(connectionId, parentFolderId, effectiveUserId);
640
+ }, [effectiveUserId]);
614
641
  useEffect2(() => {
615
642
  if (!open) return;
616
643
  setName("");
@@ -627,14 +654,18 @@ function WorkspaceCreateDialog({
627
654
  setNewBackblazeBucketName("");
628
655
  setBackblazeCredentialsTested(false);
629
656
  setConnectedDriveOption(null);
657
+ setLoadedOptions([]);
658
+ setLoadedOwnerId(null);
659
+ setProviderCapabilities([]);
630
660
  setConnectedBackblazeOption(null);
631
661
  setGoogleDriveFolder(null);
632
- setVerifiedGoogleDriveConnectionId(null);
633
- }, [open]);
662
+ setVerifiedGoogleDrive(null);
663
+ }, [open, effectiveUserId]);
634
664
  useEffect2(() => {
635
- if (!open || !storageService.listStorageProviderCapabilities) return;
665
+ const listCapabilities = storageServiceRef.current.listStorageProviderCapabilities;
666
+ if (!open || !listCapabilities) return;
636
667
  let active = true;
637
- storageService.listStorageProviderCapabilities(effectiveUserId).then((items) => {
668
+ listCapabilities(effectiveUserId).then((items) => {
638
669
  if (active) setProviderCapabilities(Array.isArray(items) ? items : []);
639
670
  }).catch((reason) => {
640
671
  if (active) setError(reason instanceof Error ? reason.message : "Unable to load storage provider capabilities.");
@@ -642,68 +673,53 @@ function WorkspaceCreateDialog({
642
673
  return () => {
643
674
  active = false;
644
675
  };
645
- }, [open, effectiveUserId, storageService]);
676
+ }, [open, effectiveUserId]);
646
677
  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]);
678
+ if (!open || !googleDriveErrorCode) return;
679
+ setError(describeGoogleDriveError({ code: googleDriveErrorCode }));
680
+ }, [open, googleDriveErrorCode]);
654
681
  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);
682
+ if (!open || !googleDriveConnectionId) return;
683
+ if (storageServiceRef.current.listStorageConnections && loadedOwnerId !== effectiveUserId) return;
684
+ const connections = storageServiceRef.current.listStorageConnections ? loadedOptions : storageOptions ?? [];
685
+ const resumed = connections.find(
686
+ (option) => option.id === googleDriveConnectionId && option.provider === "google_drive" && option.enabled !== false
687
+ );
688
+ if (!resumed) {
689
+ setError("Google Drive connection could not be restored for this account. Retry authorization.");
661
690
  return;
662
691
  }
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]);
692
+ setSelectedStorageId(resumed.id);
693
+ setBackblazeMode(false);
694
+ setDefaultStorageApplied(true);
695
+ setError(null);
696
+ }, [open, googleDriveConnectionId, effectiveUserId, loadedOwnerId, loadedOptions, storageOptions]);
683
697
  useEffect2(() => {
684
- if (!open || storageOptions) return;
698
+ if (!open) return;
685
699
  let active = true;
686
- const listConnections = storageService.listStorageConnections;
700
+ const listConnections = storageServiceRef.current.listStorageConnections;
687
701
  if (!listConnections) {
688
702
  setLoadingStorage(false);
689
- return () => {
690
- active = false;
691
- };
703
+ return;
692
704
  }
693
705
  setLoadingStorage(true);
706
+ setLoadedOwnerId(null);
707
+ setLoadedOptions([]);
694
708
  listConnections(effectiveUserId).then((options) => {
695
- if (active) setLoadedOptions(Array.isArray(options) ? options : []);
709
+ if (!active) return;
710
+ setLoadedOptions(Array.isArray(options) ? options : []);
711
+ setLoadedOwnerId(effectiveUserId);
696
712
  }).catch((reason) => {
697
- if (active) setError(reason instanceof Error ? reason.message : "Unable to load storage connections.");
713
+ if (active) setError(describeGoogleDriveError(reason));
698
714
  }).finally(() => {
699
715
  if (active) setLoadingStorage(false);
700
716
  });
701
717
  return () => {
702
718
  active = false;
703
719
  };
704
- }, [open, effectiveUserId, storageOptions, storageService]);
720
+ }, [open, effectiveUserId, refreshConnectionsVersion]);
705
721
  const availableOptions = useMemo(() => {
706
- const supplied = storageOptions ?? loadedOptions;
722
+ const supplied = storageServiceRef.current.listStorageConnections ? loadedOwnerId === effectiveUserId ? loadedOptions : [] : storageOptions ?? loadedOptions;
707
723
  const providerOrder = visibility?.storagePolicy?.providers ?? visibility?.availableStorageProviders ?? providerCapabilities.map((capability) => capability.id);
708
724
  const hidden = new Set(visibility?.hiddenStorageProviders || []);
709
725
  const enabled = supplied.filter(
@@ -720,7 +736,10 @@ function WorkspaceCreateDialog({
720
736
  const capability = providerCapabilities.find((item) => item.id === provider);
721
737
  const canAuthorize = Boolean(capability?.enabled && capability.canCreateConnection);
722
738
  const label = canAuthorize ? "Connect Google Drive" : "Google Drive authorization unavailable";
723
- return connections.length > 0 ? connections : [{ id: "google_drive", provider: "google_drive", label }];
739
+ return [
740
+ ...connections,
741
+ ...canAuthorize || connections.length === 0 ? [{ id: "google_drive", provider: "google_drive", label }] : []
742
+ ];
724
743
  }
725
744
  if (provider === "backblaze_b2") {
726
745
  const connections = [
@@ -735,29 +754,70 @@ function WorkspaceCreateDialog({
735
754
  }
736
755
  return forProvider(provider);
737
756
  });
738
- }, [storageOptions, loadedOptions, connectedDriveOption, connectedBackblazeOption, visibility, providerCapabilities]);
757
+ }, [storageOptions, loadedOptions, loadedOwnerId, effectiveUserId, connectedDriveOption, connectedBackblazeOption, visibility, providerCapabilities]);
758
+ const selectedGoogleProvider = availableOptions.find((option) => option.id === selectedStorageId)?.provider;
759
+ useEffect2(() => {
760
+ setGoogleDriveFolder(null);
761
+ }, [effectiveUserId, selectedStorageId]);
762
+ useEffect2(() => {
763
+ const identify = storageServiceRef.current.getGoogleDriveAccountIdentity;
764
+ if (!open || selectedGoogleProvider !== "google_drive" || selectedStorageId === "google_drive" || !identify) {
765
+ setVerifiedGoogleDrive(null);
766
+ return;
767
+ }
768
+ let active = true;
769
+ setVerifiedGoogleDrive(null);
770
+ identify(effectiveUserId, selectedStorageId).then((identity) => {
771
+ if (!active) return;
772
+ if (!identity || typeof identity.accountId !== "string" || !identity.accountId) {
773
+ throw new Error("Kloks did not confirm a Google Drive account identity.");
774
+ }
775
+ setVerifiedGoogleDrive({ userId: effectiveUserId, connectionId: selectedStorageId });
776
+ setConnectedDriveOption((old) => {
777
+ const base = availableOptions.find((option) => option.id === selectedStorageId);
778
+ if (!base) return old;
779
+ return { ...base, googleAccountId: identity.accountId, googleEmail: identity.email || base.googleEmail };
780
+ });
781
+ }).catch((reason) => {
782
+ if (active) {
783
+ setVerifiedGoogleDrive(null);
784
+ setError(describeGoogleDriveError(reason));
785
+ }
786
+ });
787
+ return () => {
788
+ active = false;
789
+ };
790
+ }, [open, selectedStorageId, selectedGoogleProvider, effectiveUserId]);
739
791
  useEffect2(() => {
740
- if (!open || loadingStorage || defaultStorageApplied) return;
792
+ if (!open || loadingStorage || defaultStorageApplied || googleDriveConnectionId || storageServiceRef.current.listStorageConnections && loadedOwnerId !== effectiveUserId) return;
741
793
  const primary = availableOptions.find((option) => option.role === "primary") || availableOptions.find((option) => option.provider !== "local_fs" && option.id !== "google_drive");
742
794
  const preferred = primary || availableOptions[0];
743
795
  if (preferred) setSelectedStorageId(preferred.id);
744
796
  setDefaultStorageApplied(true);
745
- }, [open, loadingStorage, availableOptions, defaultStorageApplied]);
797
+ }, [open, loadingStorage, availableOptions, defaultStorageApplied, loadedOwnerId, effectiveUserId, googleDriveConnectionId]);
746
798
  useEffect2(() => {
747
799
  if (!open) return;
800
+ const restored = googleDriveConnectionId && availableOptions.find(
801
+ (option) => option.id === googleDriveConnectionId && option.provider === "google_drive"
802
+ );
803
+ if (restored) {
804
+ if (selectedStorageId !== restored.id) setSelectedStorageId(restored.id);
805
+ return;
806
+ }
748
807
  const selectedStillExists = backblazeMode || availableOptions.some((option) => option.id === selectedStorageId);
749
808
  if (!selectedStillExists) {
750
809
  const primary = availableOptions.find((option) => option.role === "primary");
751
810
  setSelectedStorageId(primary?.id || availableOptions[0]?.id || "");
752
811
  }
753
- }, [open, availableOptions, selectedStorageId, backblazeMode]);
812
+ }, [open, availableOptions, selectedStorageId, backblazeMode, googleDriveConnectionId]);
754
813
  if (!open) return null;
755
814
  const selectedOption = availableOptions.find((option) => option.id === selectedStorageId) || availableOptions[0] || NO_STORAGE_OPTION;
756
815
  const googleDriveCapability = providerCapabilities.find((capability) => capability.id === "google_drive");
757
816
  const backblazeCapability = providerCapabilities.find((capability) => capability.id === "backblaze_b2");
758
817
  const canCreateBackblazeConnection = Boolean(backblazeCapability?.enabled && backblazeCapability.canCreateConnection);
759
818
  const canAuthorizeGoogleDrive = Boolean(googleDriveCapability?.enabled && googleDriveCapability.canCreateConnection);
760
- const googleDriveConnection = selectedOption.provider === "google_drive" && selectedOption.id !== "google_drive" ? selectedOption : void 0;
819
+ const unverifiedDriveConnection = selectedOption.provider === "google_drive" && selectedOption.id !== "google_drive" ? selectedOption : void 0;
820
+ const googleDriveConnection = verifiedGoogleDriveConnectionId === unverifiedDriveConnection?.id ? unverifiedDriveConnection : void 0;
761
821
  const hiddenFields = new Set(visibility?.hiddenFields || []);
762
822
  const userName = currentUser?.username || currentUser?.name || currentUser?.email?.split("@")[0] || "user";
763
823
  const folderPreview = formatWorkspaceFolderPreview(appName, userName, name || "workspace");
@@ -892,16 +952,6 @@ function WorkspaceCreateDialog({
892
952
  setSubmitting(true);
893
953
  setError(null);
894
954
  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
955
  const option = selectedOption.provider === "local_fs" ? { ...selectedOption, localFolderName: localFolderName.trim() || selectedOption.localFolderName || name.trim() } : selectedOption.provider === "google_drive" && googleDriveFolder ? {
906
956
  ...selectedOption,
907
957
  googleRootFolderId: googleDriveFolder.id,
@@ -988,7 +1038,7 @@ function WorkspaceCreateDialog({
988
1038
  disabled: loadingStorage || submitting,
989
1039
  className: "h-10 min-w-0 flex-1 border px-2 text-xs",
990
1040
  style: { backgroundColor: background, borderColor: border },
991
- children: availableOptions.map((option) => /* @__PURE__ */ jsx4("option", { value: option.id, children: providerLabel(option) + " \u2014 " + (option.label || option.name || option.id) }, option.id))
1041
+ children: availableOptions.map((option) => /* @__PURE__ */ jsx4("option", { value: option.id, children: providerLabel(option) + " \u2014 " + (option.provider === "google_drive" && option.googleEmail ? option.googleEmail : option.label || option.name || option.id) }, option.id))
992
1042
  }
993
1043
  ) }),
994
1044
  !hiddenFields.has("backblaze") && backblazeMode && /* @__PURE__ */ jsx4("div", { className: "mt-3 space-y-3 border-t pt-3", style: { borderColor: border }, children: /* @__PURE__ */ jsxs4("div", { className: "space-y-2 border p-3", style: { borderColor: border, backgroundColor: background }, children: [
@@ -1097,21 +1147,31 @@ function WorkspaceCreateDialog({
1097
1147
  " Loading storage connections\u2026"
1098
1148
  ] }) : 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
1149
  ] }),
1100
- selectedOption.provider === "google_drive" && /* @__PURE__ */ jsx4(
1150
+ selectedOption.provider === "google_drive" && unverifiedDriveConnection && !googleDriveConnection ? /* @__PURE__ */ jsxs4("div", { role: "status", className: "border p-3 text-xs", children: [
1151
+ "Google Drive account verification is required before browsing folders.",
1152
+ 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." })
1153
+ ] }) : selectedOption.provider === "google_drive" && /* @__PURE__ */ jsx4(
1101
1154
  GoogleDriveWorkspacePicker,
1102
1155
  {
1103
1156
  userId: effectiveUserId,
1104
1157
  connection: googleDriveConnection,
1105
1158
  connectGoogleDrive: canAuthorizeGoogleDrive ? storageService.connectGoogleDrive : void 0,
1106
- listGoogleDriveFolders: storageService.listGoogleDriveFolders ? (connectionId, parentFolderId) => storageService.listGoogleDriveFolders(connectionId, parentFolderId, effectiveUserId) : void 0,
1159
+ listGoogleDriveFolders: storageService.listGoogleDriveFolders ? browseGoogleDriveFolders : void 0,
1107
1160
  selectedFolder: googleDriveFolder,
1108
1161
  onConnected: (connection) => {
1109
1162
  if (connection.provider !== "google_drive") {
1110
1163
  setError("The storage service returned a non-Google Drive connection.");
1111
1164
  return;
1112
1165
  }
1166
+ if (!connection.id || connection.id === "google_drive") {
1167
+ setError("Kloks did not return an opaque Google Drive connection ID.");
1168
+ return;
1169
+ }
1113
1170
  setConnectedDriveOption(connection);
1114
1171
  setSelectedStorageId(connection.id);
1172
+ if (storageServiceRef.current.listStorageConnections) {
1173
+ setRefreshConnectionsVersion((version) => version + 1);
1174
+ }
1115
1175
  setGoogleDriveFolder(null);
1116
1176
  setError(null);
1117
1177
  },
@@ -1182,20 +1242,24 @@ function WorkspaceTilesMenu({
1182
1242
  error = null
1183
1243
  }) {
1184
1244
  const store = useFloksFrnlStore();
1185
- const effectiveUserId = userId || currentUser?.id || "system";
1245
+ const effectiveUserId = (userId && userId !== "system" ? userId : currentUser?.id) || userId || "system";
1186
1246
  const generated = useId().replace(/[:/]/g, "");
1187
1247
  const componentId = `workspaceTilesMenu.${generated}`;
1188
1248
  const [creating, setCreating] = useState5(false);
1189
1249
  const [googleDriveConnectionId, setGoogleDriveConnectionId] = useState5();
1250
+ const [googleDriveErrorCode, setGoogleDriveErrorCode] = useState5();
1190
1251
  useEffect3(() => {
1191
1252
  if (typeof window === "undefined") return;
1192
1253
  const url = new URL(window.location.href);
1193
1254
  const connected = url.searchParams.get("googleDriveConnected") === "1";
1194
1255
  const failed = url.searchParams.get("googleDriveError") === "1";
1195
1256
  const connectionId = url.searchParams.get("googleDriveConnectionId") || void 0;
1257
+ const rawErrorCode = url.searchParams.get("googleDriveErrorCode");
1258
+ const errorCode = rawErrorCode && /^[A-Za-z0-9_:-]{1,80}$/.test(rawErrorCode) ? rawErrorCode : "GOOGLE_DRIVE_AUTH_FAILED";
1196
1259
  if (connected || failed) {
1197
1260
  setCreating(true);
1198
- setGoogleDriveConnectionId(connectionId);
1261
+ setGoogleDriveConnectionId(connected ? connectionId : void 0);
1262
+ setGoogleDriveErrorCode(failed ? errorCode : connected && !connectionId ? "GOOGLE_DRIVE_MISSING_CONNECTION" : void 0);
1199
1263
  url.searchParams.delete("googleDriveConnected");
1200
1264
  url.searchParams.delete("googleDriveError");
1201
1265
  url.searchParams.delete("googleDriveConnectionId");
@@ -1203,6 +1267,14 @@ function WorkspaceTilesMenu({
1203
1267
  window.history.replaceState(window.history.state, "", url.toString());
1204
1268
  }
1205
1269
  }, []);
1270
+ const [callbackOwner, setCallbackOwner] = useState5(effectiveUserId);
1271
+ useEffect3(() => {
1272
+ if (callbackOwner === effectiveUserId) return;
1273
+ setCallbackOwner(effectiveUserId);
1274
+ setGoogleDriveConnectionId(void 0);
1275
+ setGoogleDriveErrorCode(void 0);
1276
+ setCreating(false);
1277
+ }, [callbackOwner, effectiveUserId]);
1206
1278
  const handlers = useMemo2(() => ({
1207
1279
  "workspaceTilesMenu.idle.select": (value) => onSelectWorkspace(value),
1208
1280
  "workspaceTilesMenu.idle.create": () => setCreating(true),
@@ -1246,7 +1318,11 @@ function WorkspaceTilesMenu({
1246
1318
  ] })
1247
1319
  }
1248
1320
  ),
1249
- /* @__PURE__ */ jsx5(WorkspaceCreateDialog, { open: creating, userId: effectiveUserId, currentUser, appName, storageOptions, storageService, visibility, googleDriveConnectionId, onClose: () => setCreating(false), onSubmit: onCreateWorkspace })
1321
+ /* @__PURE__ */ jsx5(WorkspaceCreateDialog, { open: creating, userId: effectiveUserId, currentUser, appName, storageOptions, storageService, visibility, googleDriveConnectionId, googleDriveErrorCode, onClose: () => {
1322
+ setCreating(false);
1323
+ setGoogleDriveConnectionId(void 0);
1324
+ setGoogleDriveErrorCode(void 0);
1325
+ }, onSubmit: onCreateWorkspace })
1250
1326
  ] });
1251
1327
  }
1252
1328
 
@@ -1282,7 +1358,7 @@ var WorkspaceGate = ({
1282
1358
  description: w.description || "Workspace vault for workflows and graph state",
1283
1359
  workspacePath: w.workspacePath || "./projects",
1284
1360
  storageProvider: w.storageProvider || w.storage?.provider || "local_fs",
1285
- storageConnectionId: w.storageConnectionId || w.storage?.storageConnectionId,
1361
+ storageConnectionId: w.storageConnectionId || w.storage?.connectionId,
1286
1362
  b2BucketName: w.b2BucketName || w.storage?.b2BucketName,
1287
1363
  b2Endpoint: w.b2Endpoint || w.storage?.b2Endpoint,
1288
1364
  b2Region: w.b2Region || w.storage?.b2Region,
@@ -1290,7 +1366,7 @@ var WorkspaceGate = ({
1290
1366
  metadata: w.metadata
1291
1367
  }));
1292
1368
  }, [workspaces]);
1293
- const effectiveUserId = userId || currentUser?.id || "system";
1369
+ const effectiveUserId = (userId && userId !== "system" ? userId : currentUser?.id) || userId || "system";
1294
1370
  return /* @__PURE__ */ jsx6(
1295
1371
  "div",
1296
1372
  {
@@ -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-54NS4UKS.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-54NS4UKS.js";
23
23
  import {
24
24
  ConfirmDialog,
25
25
  CopyableErrorAlert,