@trustgraph/react-state 1.7.3 → 2.1.0

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 (53) hide show
  1. package/dist/index.cjs +578 -320
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.ts +8 -2
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.esm.js +563 -320
  6. package/dist/index.esm.js.map +1 -1
  7. package/dist/model/schema-types.d.ts +16 -0
  8. package/dist/model/schema-types.d.ts.map +1 -0
  9. package/dist/state/agent-tools.d.ts +1 -1
  10. package/dist/state/agent-tools.d.ts.map +1 -1
  11. package/dist/state/auth.d.ts +36 -0
  12. package/dist/state/auth.d.ts.map +1 -0
  13. package/dist/state/chunked-download.d.ts.map +1 -1
  14. package/dist/state/chunked-upload.d.ts.map +1 -1
  15. package/dist/state/collections.d.ts.map +1 -1
  16. package/dist/state/document-embeddings-query.d.ts.map +1 -1
  17. package/dist/state/document-metadata.d.ts +1 -1
  18. package/dist/state/document-metadata.d.ts.map +1 -1
  19. package/dist/state/embeddings.d.ts +1 -1
  20. package/dist/state/embeddings.d.ts.map +1 -1
  21. package/dist/state/explainability.d.ts.map +1 -1
  22. package/dist/state/flow-blueprints.d.ts +1 -1
  23. package/dist/state/flow-blueprints.d.ts.map +1 -1
  24. package/dist/state/flow-parameters.d.ts.map +1 -1
  25. package/dist/state/flows.d.ts +1 -1
  26. package/dist/state/flows.d.ts.map +1 -1
  27. package/dist/state/graph-query.d.ts +1 -1
  28. package/dist/state/knowledge-cores.d.ts +2 -2
  29. package/dist/state/knowledge-cores.d.ts.map +1 -1
  30. package/dist/state/library.d.ts.map +1 -1
  31. package/dist/state/llm-models.d.ts +2 -2
  32. package/dist/state/llm-models.d.ts.map +1 -1
  33. package/dist/state/mcp-tools.d.ts +1 -1
  34. package/dist/state/mcp-tools.d.ts.map +1 -1
  35. package/dist/state/nlp-query.d.ts.map +1 -1
  36. package/dist/state/ontologies.d.ts.map +1 -1
  37. package/dist/state/processing.d.ts.map +1 -1
  38. package/dist/state/prompts.d.ts.map +1 -1
  39. package/dist/state/provenance.d.ts.map +1 -1
  40. package/dist/state/row-embeddings-query.d.ts.map +1 -1
  41. package/dist/state/rows-query.d.ts.map +1 -1
  42. package/dist/state/schemas.d.ts.map +1 -1
  43. package/dist/state/settings.d.ts +1 -1
  44. package/dist/state/structured-query.d.ts.map +1 -1
  45. package/dist/state/token-costs.d.ts +2 -2
  46. package/dist/state/token-costs.d.ts.map +1 -1
  47. package/dist/state/triples.d.ts +5 -10
  48. package/dist/state/triples.d.ts.map +1 -1
  49. package/dist/state/workspace.d.ts +32 -0
  50. package/dist/state/workspace.d.ts.map +1 -0
  51. package/dist/utils/explainability.d.ts +4 -2
  52. package/dist/utils/explainability.d.ts.map +1 -1
  53. package/package.json +8 -7
package/dist/index.cjs CHANGED
@@ -150,148 +150,6 @@ const useSessionStore = zustand.create()((set) => ({
150
150
  })),
151
151
  }));
152
152
 
153
- const useConversation = zustand.create()((set) => ({
154
- messages: [],
155
- input: "",
156
- chatMode: "graph-rag",
157
- setMessages: (v) => set(() => ({
158
- messages: v,
159
- })),
160
- addMessage: (role, text, type, explainSessionId) => set((state) => ({
161
- messages: [
162
- ...state.messages,
163
- {
164
- role: role,
165
- text: text,
166
- type: type || "normal",
167
- explainSessionId,
168
- },
169
- ],
170
- })),
171
- updateLastMessage: (text, explainSessionId) => set((state) => {
172
- if (state.messages.length === 0)
173
- return state;
174
- const messages = [...state.messages];
175
- messages[messages.length - 1] = {
176
- ...messages[messages.length - 1],
177
- text: text,
178
- ...(explainSessionId !== undefined && { explainSessionId }),
179
- };
180
- return { messages };
181
- }),
182
- setInput: (v) => set(() => ({
183
- input: v,
184
- })),
185
- setChatMode: (mode) => set(() => ({
186
- chatMode: mode,
187
- })),
188
- }));
189
-
190
- // Zustand state management library for creating stores
191
- /**
192
- * Zustand store for managing the main workbench application state
193
- * Provides centralized state management for tool navigation and entity selection
194
- */
195
- const useWorkbenchStateStore = zustand.create()((set) => ({
196
- // Initial state values
197
- selected: undefined, // No entity selected by default
198
- tool: "chat", // Default tool is the chat interface
199
- entities: [], // Empty entities list by default
200
- // Entity selection functions
201
- setSelected: (e) => set(() => ({
202
- selected: e,
203
- })),
204
- // Clear the current entity selection
205
- unsetSelected: () => set(() => ({
206
- selected: undefined,
207
- })),
208
- // Tool/page navigation function
209
- setTool: (v) => set(() => ({
210
- tool: v,
211
- })),
212
- // Update the list of available entities
213
- setEntities: (v) => set(() => ({
214
- entities: v,
215
- })),
216
- }));
217
-
218
- // Zustand state management library for creating stores
219
- /**
220
- * Zustand store for managing document loading state
221
- * Provides centralized state management for the document upload/loading workflow
222
- */
223
- const useLoadStateStore = zustand.create()((set) => ({
224
- // Initial state values
225
- title: "", // Empty title by default
226
- comments: "", // Empty comments by default
227
- url: "", // Empty URL by default
228
- keywords: [], // No keywords by default
229
- operation: "upload-pdf", // Default operation is PDF upload
230
- files: [], // No files selected by default
231
- uploaded: [], // No files uploaded yet
232
- text: "", // Empty text content by default
233
- // Setter functions for document metadata
234
- setTitle: (v) => set(() => ({
235
- title: v,
236
- })),
237
- setComments: (v) => set(() => ({
238
- comments: v,
239
- })),
240
- setUrl: (v) => set(() => ({
241
- url: v,
242
- })),
243
- setKeywords: (v) => set(() => ({
244
- keywords: v,
245
- })),
246
- // Setter function for processing operation type
247
- setOperation: (v) => set(() => ({
248
- operation: v,
249
- })),
250
- // Setter functions for file management
251
- setFiles: (v) => set(() => ({
252
- files: v,
253
- })),
254
- setUploaded: (v) => set(() => ({
255
- uploaded: v,
256
- })),
257
- // Add a single file to the uploaded list (preserving existing uploads)
258
- addUploaded: (v) => set((state) => ({
259
- uploaded: [...state.uploaded, v],
260
- })),
261
- setText: (v) => set(() => ({
262
- text: v,
263
- })),
264
- // Remove a specific file from the selected files list
265
- removeFile: (v) => set((state) => ({
266
- files: Array.from(state.files).filter((f) => f != v),
267
- })),
268
- // Text upload counter management
269
- textUploads: 0, // Initial counter value
270
- setTextUploads: (v) => set(() => ({
271
- textUploads: v,
272
- })),
273
- // Increment the text upload counter (useful for generating unique IDs)
274
- incTextUploads: () => set((state) => ({
275
- textUploads: state.textUploads + 1,
276
- })),
277
- }));
278
-
279
- // Zustand store for managing search functionality state
280
- const useSearchStateStore = zustand.create()((set) => ({
281
- // Initial state: no search results and empty search input
282
- rows: [],
283
- input: "",
284
- // Replace the entire rows array with new search results
285
- // Note: This completely overwrites the previous results
286
- setRows: (v) => set(() => ({
287
- rows: v,
288
- })),
289
- // Update the search input string (typically bound to search input field)
290
- setInput: (v) => set(() => ({
291
- input: v,
292
- })),
293
- }));
294
-
295
153
  const DEFAULT_SETTINGS = {
296
154
  user: "trustgraph", // Default user ID
297
155
  collection: "default", // Default collection ID
@@ -510,6 +368,453 @@ const useSettings = () => {
510
368
  };
511
369
  };
512
370
 
371
+ // Active workspace is tied to the authenticated session, so it lives in
372
+ // sessionStorage alongside the auth token rather than localStorage.
373
+ const WORKSPACE_STORAGE_KEY = "tg.workspace.active";
374
+ const readSession$1 = () => {
375
+ try {
376
+ return sessionStorage.getItem(WORKSPACE_STORAGE_KEY);
377
+ }
378
+ catch {
379
+ return null;
380
+ }
381
+ };
382
+ const writeSession$1 = (value) => {
383
+ try {
384
+ if (value === null)
385
+ sessionStorage.removeItem(WORKSPACE_STORAGE_KEY);
386
+ else
387
+ sessionStorage.setItem(WORKSPACE_STORAGE_KEY, value);
388
+ }
389
+ catch {
390
+ /* ignore */
391
+ }
392
+ };
393
+ const useWorkspaceStore = zustand.create((set) => ({
394
+ activeWorkspace: readSession$1(),
395
+ generation: 0,
396
+ initActiveWorkspace: (id) => set((s) => {
397
+ if (s.activeWorkspace)
398
+ return s;
399
+ writeSession$1(id);
400
+ return { activeWorkspace: id };
401
+ }),
402
+ setActiveWorkspace: (id) => {
403
+ writeSession$1(id);
404
+ set((s) => ({ activeWorkspace: id, generation: s.generation + 1 }));
405
+ },
406
+ bumpGeneration: () => set((s) => ({ generation: s.generation + 1 })),
407
+ clearActiveWorkspace: () => {
408
+ writeSession$1(null);
409
+ set({ activeWorkspace: null });
410
+ },
411
+ }));
412
+ // Discover the workspaces the caller can access (one for an ordinary
413
+ // user, all for an admin — driven entirely by what the gateway returns).
414
+ const useWorkspaces = () => {
415
+ const socket = reactProvider.useSocket();
416
+ const connectionState = reactProvider.useConnectionState();
417
+ const isSocketReady = connectionState?.status === "authenticated";
418
+ const query = reactQuery.useQuery({
419
+ queryKey: ["workspaces"],
420
+ enabled: isSocketReady,
421
+ queryFn: () => socket.iam().listMyWorkspaces(),
422
+ });
423
+ return {
424
+ workspaces: query.data || [],
425
+ isLoading: query.isLoading,
426
+ isError: query.isError,
427
+ error: query.error,
428
+ refetch: query.refetch,
429
+ };
430
+ };
431
+ // The caller's own user record, including their home/default workspace.
432
+ const useWhoami = () => {
433
+ const socket = reactProvider.useSocket();
434
+ const connectionState = reactProvider.useConnectionState();
435
+ const isSocketReady = connectionState?.status === "authenticated";
436
+ const query = reactQuery.useQuery({
437
+ queryKey: ["whoami"],
438
+ enabled: isSocketReady,
439
+ queryFn: () => socket.iam().whoami(),
440
+ });
441
+ return {
442
+ whoami: query.data,
443
+ isLoading: query.isLoading,
444
+ isError: query.isError,
445
+ error: query.error,
446
+ refetch: query.refetch,
447
+ };
448
+ };
449
+ // Bootstrap + keep the socket's outbound workspace in sync. Mount once,
450
+ // high in the tree (e.g. in the authenticated app shell).
451
+ const useWorkspaceSync = () => {
452
+ const socket = reactProvider.useSocket();
453
+ const activeWorkspace = useWorkspaceStore((s) => s.activeWorkspace);
454
+ const initActiveWorkspace = useWorkspaceStore((s) => s.initActiveWorkspace);
455
+ const setActiveWorkspace = useWorkspaceStore((s) => s.setActiveWorkspace);
456
+ const { whoami } = useWhoami();
457
+ const { workspaces } = useWorkspaces();
458
+ // Until we know the stored workspace is valid, don't stamp it on the
459
+ // socket — use empty string so the gateway falls back to the token's
460
+ // default. This prevents a stale/deleted workspace in sessionStorage
461
+ // from poisoning every request (including the whoami/list calls we
462
+ // need to detect the problem).
463
+ const validated = workspaces.length > 0 && activeWorkspace
464
+ ? workspaces.some((w) => w.id === activeWorkspace)
465
+ : false;
466
+ // Adopt the user's default workspace when we have no active one yet.
467
+ react.useEffect(() => {
468
+ if (!activeWorkspace && whoami?.default_workspace) {
469
+ initActiveWorkspace(whoami.default_workspace);
470
+ }
471
+ }, [activeWorkspace, whoami, initActiveWorkspace]);
472
+ // If the stored workspace no longer exists, fall back to the user's
473
+ // default workspace.
474
+ react.useEffect(() => {
475
+ if (!activeWorkspace || !whoami?.default_workspace || workspaces.length === 0)
476
+ return;
477
+ if (!validated) {
478
+ setActiveWorkspace(whoami.default_workspace);
479
+ }
480
+ }, [activeWorkspace, workspaces, whoami, validated, setActiveWorkspace]);
481
+ // Only stamp a validated workspace onto the socket.
482
+ // Bump generation so hooks that depend on it re-fire with the
483
+ // workspace now set on the socket.
484
+ const bumpGeneration = useWorkspaceStore((s) => s.bumpGeneration);
485
+ react.useEffect(() => {
486
+ socket.workspace = validated ? activeWorkspace : "";
487
+ if (validated)
488
+ bumpGeneration();
489
+ }, [socket, activeWorkspace, validated, bumpGeneration]);
490
+ };
491
+ // Active workspace + the switcher action for components.
492
+ const useWorkspace = () => {
493
+ const socket = reactProvider.useSocket();
494
+ const queryClient = reactQuery.useQueryClient();
495
+ const activeWorkspace = useWorkspaceStore((s) => s.activeWorkspace);
496
+ const generation = useWorkspaceStore((s) => s.generation);
497
+ const setActiveWorkspace = useWorkspaceStore((s) => s.setActiveWorkspace);
498
+ const setFlowId = useSessionStore((s) => s.setFlowId);
499
+ const { updateSetting } = useSettings();
500
+ const { workspaces } = useWorkspaces();
501
+ const { whoami } = useWhoami();
502
+ // Switching workspace is a full context reset: collections, flows,
503
+ // documents and config all re-scope. Reset the inner context (flow +
504
+ // collection) to defaults and invalidate every cache so all pages
505
+ // refetch under the new workspace.
506
+ const switchWorkspace = react.useCallback((id) => {
507
+ if (!id || id === activeWorkspace)
508
+ return;
509
+ // Set synchronously so refetches triggered below already carry it.
510
+ socket.workspace = id;
511
+ setActiveWorkspace(id);
512
+ setFlowId("default");
513
+ updateSetting("collection", "default");
514
+ // Wipe workspace-scoped caches so stale data from the previous
515
+ // workspace can't bleed through, then invalidate to trigger refetches.
516
+ const keep = ["workspaces", "whoami", "settings"];
517
+ queryClient.removeQueries({
518
+ predicate: (q) => !keep.includes(q.queryKey[0]),
519
+ });
520
+ queryClient.invalidateQueries();
521
+ }, [
522
+ activeWorkspace,
523
+ socket,
524
+ setActiveWorkspace,
525
+ setFlowId,
526
+ updateSetting,
527
+ queryClient,
528
+ ]);
529
+ return {
530
+ activeWorkspace,
531
+ workspaces,
532
+ defaultWorkspace: whoami?.default_workspace ?? null,
533
+ generation,
534
+ switchWorkspace,
535
+ };
536
+ };
537
+
538
+ const useConversation = zustand.create()((set) => ({
539
+ messages: [],
540
+ input: "",
541
+ chatMode: "graph-rag",
542
+ setMessages: (v) => set(() => ({
543
+ messages: v,
544
+ })),
545
+ addMessage: (role, text, type, explainSessionId) => set((state) => ({
546
+ messages: [
547
+ ...state.messages,
548
+ {
549
+ role: role,
550
+ text: text,
551
+ type: type || "normal",
552
+ explainSessionId,
553
+ },
554
+ ],
555
+ })),
556
+ updateLastMessage: (text, explainSessionId) => set((state) => {
557
+ if (state.messages.length === 0)
558
+ return state;
559
+ const messages = [...state.messages];
560
+ messages[messages.length - 1] = {
561
+ ...messages[messages.length - 1],
562
+ text: text,
563
+ ...(explainSessionId !== undefined && { explainSessionId }),
564
+ };
565
+ return { messages };
566
+ }),
567
+ setInput: (v) => set(() => ({
568
+ input: v,
569
+ })),
570
+ setChatMode: (mode) => set(() => ({
571
+ chatMode: mode,
572
+ })),
573
+ }));
574
+
575
+ // Zustand state management library for creating stores
576
+ /**
577
+ * Zustand store for managing the main workbench application state
578
+ * Provides centralized state management for tool navigation and entity selection
579
+ */
580
+ const useWorkbenchStateStore = zustand.create()((set) => ({
581
+ // Initial state values
582
+ selected: undefined, // No entity selected by default
583
+ tool: "chat", // Default tool is the chat interface
584
+ entities: [], // Empty entities list by default
585
+ // Entity selection functions
586
+ setSelected: (e) => set(() => ({
587
+ selected: e,
588
+ })),
589
+ // Clear the current entity selection
590
+ unsetSelected: () => set(() => ({
591
+ selected: undefined,
592
+ })),
593
+ // Tool/page navigation function
594
+ setTool: (v) => set(() => ({
595
+ tool: v,
596
+ })),
597
+ // Update the list of available entities
598
+ setEntities: (v) => set(() => ({
599
+ entities: v,
600
+ })),
601
+ }));
602
+
603
+ // Zustand state management library for creating stores
604
+ /**
605
+ * Zustand store for managing document loading state
606
+ * Provides centralized state management for the document upload/loading workflow
607
+ */
608
+ const useLoadStateStore = zustand.create()((set) => ({
609
+ // Initial state values
610
+ title: "", // Empty title by default
611
+ comments: "", // Empty comments by default
612
+ url: "", // Empty URL by default
613
+ keywords: [], // No keywords by default
614
+ operation: "upload-pdf", // Default operation is PDF upload
615
+ files: [], // No files selected by default
616
+ uploaded: [], // No files uploaded yet
617
+ text: "", // Empty text content by default
618
+ // Setter functions for document metadata
619
+ setTitle: (v) => set(() => ({
620
+ title: v,
621
+ })),
622
+ setComments: (v) => set(() => ({
623
+ comments: v,
624
+ })),
625
+ setUrl: (v) => set(() => ({
626
+ url: v,
627
+ })),
628
+ setKeywords: (v) => set(() => ({
629
+ keywords: v,
630
+ })),
631
+ // Setter function for processing operation type
632
+ setOperation: (v) => set(() => ({
633
+ operation: v,
634
+ })),
635
+ // Setter functions for file management
636
+ setFiles: (v) => set(() => ({
637
+ files: v,
638
+ })),
639
+ setUploaded: (v) => set(() => ({
640
+ uploaded: v,
641
+ })),
642
+ // Add a single file to the uploaded list (preserving existing uploads)
643
+ addUploaded: (v) => set((state) => ({
644
+ uploaded: [...state.uploaded, v],
645
+ })),
646
+ setText: (v) => set(() => ({
647
+ text: v,
648
+ })),
649
+ // Remove a specific file from the selected files list
650
+ removeFile: (v) => set((state) => ({
651
+ files: Array.from(state.files).filter((f) => f != v),
652
+ })),
653
+ // Text upload counter management
654
+ textUploads: 0, // Initial counter value
655
+ setTextUploads: (v) => set(() => ({
656
+ textUploads: v,
657
+ })),
658
+ // Increment the text upload counter (useful for generating unique IDs)
659
+ incTextUploads: () => set((state) => ({
660
+ textUploads: state.textUploads + 1,
661
+ })),
662
+ }));
663
+
664
+ // Zustand store for managing search functionality state
665
+ const useSearchStateStore = zustand.create()((set) => ({
666
+ // Initial state: no search results and empty search input
667
+ rows: [],
668
+ input: "",
669
+ // Replace the entire rows array with new search results
670
+ // Note: This completely overwrites the previous results
671
+ setRows: (v) => set(() => ({
672
+ rows: v,
673
+ })),
674
+ // Update the search input string (typically bound to search input field)
675
+ setInput: (v) => set(() => ({
676
+ input: v,
677
+ })),
678
+ }));
679
+
680
+ const TOKEN_STORAGE_KEY = "tg.auth.token";
681
+ const EXPIRES_STORAGE_KEY = "tg.auth.expires";
682
+ const readSession = (key) => {
683
+ try {
684
+ return sessionStorage.getItem(key);
685
+ }
686
+ catch {
687
+ return null;
688
+ }
689
+ };
690
+ const writeSession = (key, value) => {
691
+ try {
692
+ if (value === null)
693
+ sessionStorage.removeItem(key);
694
+ else
695
+ sessionStorage.setItem(key, value);
696
+ }
697
+ catch {
698
+ /* ignore */
699
+ }
700
+ };
701
+ const initialToken = readSession(TOKEN_STORAGE_KEY);
702
+ const initialExpires = readSession(EXPIRES_STORAGE_KEY);
703
+ const useAuthStore = zustand.create((set) => ({
704
+ token: initialToken,
705
+ jwtExpires: initialExpires,
706
+ status: initialToken ? "authenticated" : "idle",
707
+ error: null,
708
+ setToken: (token, expires) => {
709
+ writeSession(TOKEN_STORAGE_KEY, token);
710
+ writeSession(EXPIRES_STORAGE_KEY, expires ?? null);
711
+ set({
712
+ token,
713
+ jwtExpires: expires ?? null,
714
+ status: "authenticated",
715
+ error: null,
716
+ });
717
+ },
718
+ clearToken: () => {
719
+ writeSession(TOKEN_STORAGE_KEY, null);
720
+ writeSession(EXPIRES_STORAGE_KEY, null);
721
+ set({
722
+ token: null,
723
+ jwtExpires: null,
724
+ status: "idle",
725
+ error: null,
726
+ });
727
+ },
728
+ setStatus: (status, error) => set({ status, error: error ?? null }),
729
+ }));
730
+ // Module-level AuthApi singleton. Configurable via configureAuthApi() — the
731
+ // demo (or any consumer) can override URLs / fetchImpl before any hook
732
+ // runs.
733
+ let authApiSingleton = client.createAuthApi();
734
+ const configureAuthApi = (options) => {
735
+ authApiSingleton = client.createAuthApi(options);
736
+ };
737
+ const getAuthApi = () => authApiSingleton;
738
+ const useAuth = () => {
739
+ const token = useAuthStore((s) => s.token);
740
+ const jwtExpires = useAuthStore((s) => s.jwtExpires);
741
+ const status = useAuthStore((s) => s.status);
742
+ const error = useAuthStore((s) => s.error);
743
+ return {
744
+ token,
745
+ jwtExpires,
746
+ status,
747
+ error,
748
+ isAuthenticated: status === "authenticated" && !!token,
749
+ };
750
+ };
751
+ const useLogin = () => {
752
+ const setToken = useAuthStore((s) => s.setToken);
753
+ const setStatus = useAuthStore((s) => s.setStatus);
754
+ const status = useAuthStore((s) => s.status);
755
+ const error = useAuthStore((s) => s.error);
756
+ const login = react.useCallback(async (username, password, default_workspace) => {
757
+ setStatus("logging-in", null);
758
+ try {
759
+ const result = await getAuthApi().login(username, password, default_workspace);
760
+ setToken(result.jwt, result.jwtExpires);
761
+ return true;
762
+ }
763
+ catch (e) {
764
+ const message = e instanceof client.AuthError
765
+ ? e.message
766
+ : e instanceof Error
767
+ ? e.message
768
+ : "login failed";
769
+ setStatus("auth-failed", message);
770
+ return false;
771
+ }
772
+ }, [setToken, setStatus]);
773
+ return {
774
+ login,
775
+ isLoading: status === "logging-in",
776
+ error,
777
+ };
778
+ };
779
+ const useLogout = () => {
780
+ const clearToken = useAuthStore((s) => s.clearToken);
781
+ return react.useCallback(() => clearToken(), [clearToken]);
782
+ };
783
+ const useBootstrapStatus = () => {
784
+ const [phase, setPhase] = react.useState("checking");
785
+ const [error, setError] = react.useState(null);
786
+ const cancelled = react.useRef(false);
787
+ const check = react.useCallback(async () => {
788
+ setPhase("checking");
789
+ setError(null);
790
+ try {
791
+ const result = await getAuthApi().bootstrapStatus();
792
+ if (cancelled.current)
793
+ return;
794
+ setPhase(result.bootstrapAvailable ? "needs-bootstrap" : "normal");
795
+ }
796
+ catch (e) {
797
+ if (cancelled.current)
798
+ return;
799
+ const message = e instanceof Error ? e.message : "bootstrap-status failed";
800
+ // Distinguish "service unreachable" (likely pre-bootstrap or down)
801
+ // from other errors. The IAM spec doesn't define a separate signal
802
+ // for pre-bootstrap, so we treat any failure to reach the endpoint
803
+ // as pre-bootstrap territory and let the operator interpret.
804
+ setError(message);
805
+ setPhase("pre-bootstrap");
806
+ }
807
+ }, []);
808
+ react.useEffect(() => {
809
+ cancelled.current = false;
810
+ check();
811
+ return () => {
812
+ cancelled.current = true;
813
+ };
814
+ }, [check]);
815
+ return { phase, error, refetch: check };
816
+ };
817
+
513
818
  /**
514
819
  * Custom hook for managing flow operations
515
820
  * Provides functionality for fetching, deleting, and creating flows
@@ -524,8 +829,7 @@ const useFlows = () => {
524
829
  // Hook for displaying user notifications
525
830
  const notify = useNotification();
526
831
  // Only enable queries when socket is connected and ready
527
- const isSocketReady = connectionState?.status === "authenticated" ||
528
- connectionState?.status === "unauthenticated";
832
+ const isSocketReady = connectionState?.status === "authenticated";
529
833
  /**
530
834
  * Query for fetching all flows
531
835
  * Uses React Query for caching and background refetching
@@ -746,8 +1050,7 @@ const useLibrary = () => {
746
1050
  // Hook for displaying user notifications
747
1051
  const notify = useNotification();
748
1052
  // Only enable queries when socket is connected and ready
749
- const isSocketReady = connectionState?.status === "authenticated" ||
750
- connectionState?.status === "unauthenticated";
1053
+ const isSocketReady = connectionState?.status === "authenticated";
751
1054
  /**
752
1055
  * Query for fetching all documents from the library
753
1056
  * Uses React Query for caching and background refetching
@@ -916,57 +1219,35 @@ const useLibrary = () => {
916
1219
  };
917
1220
  };
918
1221
 
919
- // @ts-nocheck
920
- /**
921
- * Custom hook for managing token cost operations
922
- * Provides functionality for fetching, deleting, and updating token costs
923
- * for AI models
924
- * @returns {Object} Token cost state and operations
925
- */
926
1222
  const useTriples = ({ flow, s, p, o, limit, collection }) => {
927
- // WebSocket connection for communicating with the configuration service
928
1223
  const socket = reactProvider.useSocket();
929
- // Hook for displaying user notifications
930
1224
  const notify = useNotification();
931
- // Settings for default collection
932
1225
  const { settings } = useSettings();
933
- // Session state for default flow ID
1226
+ const connectionState = reactProvider.useConnectionState();
1227
+ const isSocketReady = connectionState?.status === "authenticated";
934
1228
  const sessionFlowId = useSessionStore((state) => state.flowId);
935
- // Use explicit param if provided, otherwise fall back to session state
936
1229
  const effectiveFlow = flow ?? sessionFlowId;
937
- /**
938
- * Query for fetching all token costs
939
- * Uses React Query for caching and background refetching
940
- */
1230
+ const effectiveCollection = collection || settings.collection;
941
1231
  const query = reactQuery.useQuery({
942
- queryKey: ["triples", { flow: effectiveFlow, s, p, o, limit }],
1232
+ queryKey: ["triples", { flow: effectiveFlow, s, p, o, limit, collection: effectiveCollection }],
1233
+ enabled: isSocketReady,
943
1234
  queryFn: () => {
944
1235
  return socket
945
1236
  .flow(effectiveFlow)
946
- .triplesQuery(s, p, o, limit, collection || settings.collection)
947
- .then((x) => {
948
- if (x["error"]) {
949
- console.log("Error:", x);
950
- throw x.error.message;
951
- }
952
- return x;
953
- })
1237
+ .triplesQuery(s, p, o, limit, effectiveCollection)
954
1238
  .catch((err) => {
955
- console.log("Error:", err);
956
- notify.error(err);
1239
+ const message = err instanceof Error ? err.message : String(err);
1240
+ notify.error(message);
1241
+ throw err;
957
1242
  });
958
1243
  },
959
1244
  });
960
- // Show loading indicators for long-running operations
961
1245
  useActivity(query.isLoading, "Loading triples");
962
- // Return token cost state and operations for use in components
963
1246
  return {
964
- // Token cost query state
965
- triples: query.data,
1247
+ triples: (query.data ?? []),
966
1248
  isLoading: query.isLoading,
967
1249
  isError: query.isError,
968
1250
  error: query.error,
969
- // Manual refetch function
970
1251
  refetch: query.refetch,
971
1252
  };
972
1253
  };
@@ -1926,7 +2207,7 @@ const useExplainabilityStore = zustand.create()((set, get) => ({
1926
2207
  const TG_ACTION = client.TG + "action";
1927
2208
  const TG_ARGUMENTS = client.TG + "arguments";
1928
2209
  const TG_SUBAGENT_GOAL = client.TG + "subagentGoal";
1929
- const TG_CONCEPT = client.TG + "concept";
2210
+ const TG_CONCEPT = client.TG_CONCEPT;
1930
2211
  const TG_ENTITY = client.TG + "entity";
1931
2212
  // RDF type URIs
1932
2213
  const TG_AGENT_QUESTION = client.TG + "AgentQuestion";
@@ -2034,20 +2315,41 @@ function extractCommonFields(triples) {
2034
2315
  return { label, derivedFrom };
2035
2316
  }
2036
2317
  /**
2037
- * Extract inline edges from triples (tg:edge quoted triples).
2318
+ * Extract inline edges from triples (tg:edge quoted triples + concept/score).
2319
+ * Groups by edge selection subject URI to associate edge, concept, and score.
2038
2320
  * Returns SelectedEdge objects with URIs — labels resolved later.
2039
2321
  */
2040
2322
  function extractInlineEdges(triples) {
2041
- const edges = [];
2323
+ const bySubject = new Map();
2042
2324
  for (const t of triples) {
2043
- if (getTermValue$1(t.p) === client.TG_EDGE && t.o.t === "t" && t.o.tr) {
2325
+ const s = getTermValue$1(t.s);
2326
+ const p = getTermValue$1(t.p);
2327
+ if (p === client.TG_EDGE && t.o.t === "t" && t.o.tr) {
2044
2328
  const edge = extractQuotedTriple(t.o);
2045
2329
  if (edge) {
2046
- edges.push({ edge });
2330
+ const existing = bySubject.get(s) || { edge };
2331
+ existing.edge = edge;
2332
+ bySubject.set(s, existing);
2333
+ }
2334
+ }
2335
+ else if (p === TG_CONCEPT) {
2336
+ const concept = getTermValue$1(t.o);
2337
+ if (concept) {
2338
+ const existing = bySubject.get(s) || { edge: { s: "", p: "", o: "" } };
2339
+ existing.concept = concept;
2340
+ bySubject.set(s, existing);
2341
+ }
2342
+ }
2343
+ else if (p === client.TG_SCORE) {
2344
+ const scoreStr = getTermValue$1(t.o);
2345
+ if (scoreStr) {
2346
+ const existing = bySubject.get(s) || { edge: { s: "", p: "", o: "" } };
2347
+ existing.score = parseFloat(scoreStr);
2348
+ bySubject.set(s, existing);
2047
2349
  }
2048
2350
  }
2049
2351
  }
2050
- return edges;
2352
+ return Array.from(bySubject.values()).filter(se => se.edge.s !== "");
2051
2353
  }
2052
2354
  // ── Parsers ─────────────────────────────────────────────────────────
2053
2355
  function parseQuestionTriples(explainId, explainGraph, triples) {
@@ -2111,15 +2413,21 @@ function parseSynthesisTriples(explainId, explainGraph, triples) {
2111
2413
  }
2112
2414
  function parseEdgeSelectionTriples(triples) {
2113
2415
  let edge = null;
2114
- let reasoning = null;
2416
+ let concept = null;
2417
+ let score = null;
2115
2418
  for (const triple of triples) {
2116
2419
  const p = getTermValue$1(triple.p);
2117
2420
  if (p === client.TG_EDGE)
2118
2421
  edge = extractQuotedTriple(triple.o);
2119
- else if (p === client.TG_REASONING)
2120
- reasoning = getTermValue$1(triple.o);
2422
+ else if (p === TG_CONCEPT)
2423
+ concept = getTermValue$1(triple.o);
2424
+ else if (p === client.TG_SCORE) {
2425
+ const v = getTermValue$1(triple.o);
2426
+ if (v)
2427
+ score = parseFloat(v);
2428
+ }
2121
2429
  }
2122
- return { edge, reasoning };
2430
+ return { edge, concept, score };
2123
2431
  }
2124
2432
  function parseGroundingTriples(explainId, explainGraph, triples) {
2125
2433
  const { label, derivedFrom } = extractCommonFields(triples);
@@ -2250,8 +2558,7 @@ const useProvenance = (options = {}) => {
2250
2558
  * Check if connected
2251
2559
  */
2252
2560
  const isConnected = react.useCallback(() => {
2253
- return (connectionState?.status === "authenticated" ||
2254
- connectionState?.status === "unauthenticated");
2561
+ return (connectionState?.status === "authenticated");
2255
2562
  }, [connectionState]);
2256
2563
  /**
2257
2564
  * Query for rdfs:label of a URI
@@ -2437,12 +2744,13 @@ const useExplainability = (options = {}) => {
2437
2744
  const resolveEdge = react.useCallback(async (edgeSelUri, allTriples) => {
2438
2745
  // Filter embedded triples for this edge selection URI
2439
2746
  const edgeTriples = allTriples.filter((t) => getTermValue$1(t.s) === edgeSelUri);
2440
- const { edge, reasoning } = parseEdgeSelectionTriples(edgeTriples);
2747
+ const { edge, concept, score } = parseEdgeSelectionTriples(edgeTriples);
2441
2748
  if (!edge)
2442
2749
  return null;
2443
2750
  const selectedEdge = {
2444
2751
  edge,
2445
- reasoning: reasoning || undefined,
2752
+ concept: concept || undefined,
2753
+ score: score ?? undefined,
2446
2754
  };
2447
2755
  // Kick off label resolution and provenance in parallel
2448
2756
  const [labels, provenanceChains] = await Promise.all([
@@ -2922,8 +3230,7 @@ const useStructuredQuery = () => {
2922
3230
  // Settings for default collection
2923
3231
  const { settings } = useSettings();
2924
3232
  // Only enable operations when socket is connected and ready
2925
- const isSocketReady = connectionState?.status === "authenticated" ||
2926
- connectionState?.status === "unauthenticated";
3233
+ const isSocketReady = connectionState?.status === "authenticated";
2927
3234
  // Mutation for executing structured queries from natural language
2928
3235
  const structuredQueryMutation = reactQuery.useMutation({
2929
3236
  mutationFn: async ({ question, collection, }) => {
@@ -2979,8 +3286,7 @@ const useRowEmbeddingsQuery = ({ flow } = {}) => {
2979
3286
  const sessionFlowId = useSessionStore((state) => state.flowId);
2980
3287
  const { settings } = useSettings();
2981
3288
  const effectiveFlow = flow ?? sessionFlowId;
2982
- const isSocketReady = connectionState?.status === "authenticated" ||
2983
- connectionState?.status === "unauthenticated";
3289
+ const isSocketReady = connectionState?.status === "authenticated";
2984
3290
  const mutation = reactQuery.useMutation({
2985
3291
  mutationFn: async ({ vectors, schemaName, collection, indexName, limit = 10, }) => {
2986
3292
  if (!isSocketReady) {
@@ -3020,8 +3326,7 @@ const useDocumentEmbeddingsQuery = ({ flow } = {}) => {
3020
3326
  const sessionFlowId = useSessionStore((state) => state.flowId);
3021
3327
  const { settings } = useSettings();
3022
3328
  const effectiveFlow = flow ?? sessionFlowId;
3023
- const isSocketReady = connectionState?.status === "authenticated" ||
3024
- connectionState?.status === "unauthenticated";
3329
+ const isSocketReady = connectionState?.status === "authenticated";
3025
3330
  const mutation = reactQuery.useMutation({
3026
3331
  mutationFn: async ({ vectors, user, collection, limit = 10, }) => {
3027
3332
  if (!isSocketReady) {
@@ -3067,8 +3372,7 @@ const useRowsQuery = ({ flow } = {}) => {
3067
3372
  // Settings for default collection
3068
3373
  const { settings } = useSettings();
3069
3374
  // Only enable operations when socket is connected and ready
3070
- const isSocketReady = connectionState?.status === "authenticated" ||
3071
- connectionState?.status === "unauthenticated";
3375
+ const isSocketReady = connectionState?.status === "authenticated";
3072
3376
  // Mutation for executing GraphQL rows queries
3073
3377
  const rowsQueryMutation = reactQuery.useMutation({
3074
3378
  mutationFn: async ({ query, collection, variables, operationName, }) => {
@@ -3117,8 +3421,7 @@ const useEmbeddings = ({ flow, term }) => {
3117
3421
  const socket = reactProvider.useSocket();
3118
3422
  const connectionState = reactProvider.useConnectionState();
3119
3423
  // Only enable queries when socket is connected and ready
3120
- const isSocketReady = connectionState?.status === "authenticated" ||
3121
- connectionState?.status === "unauthenticated";
3424
+ const isSocketReady = connectionState?.status === "authenticated";
3122
3425
  // Hook for displaying user notifications
3123
3426
  const notify = useNotification();
3124
3427
  // Session state for default flow ID
@@ -3176,8 +3479,7 @@ const useCollections = () => {
3176
3479
  // Hook for displaying user notifications
3177
3480
  const notify = useNotification();
3178
3481
  // Only enable queries when socket is connected and ready
3179
- const isSocketReady = connectionState?.status === "authenticated" ||
3180
- connectionState?.status === "unauthenticated";
3482
+ const isSocketReady = connectionState?.status === "authenticated";
3181
3483
  /**
3182
3484
  * Query for fetching all collections from the collection management service
3183
3485
  * Uses React Query for caching and background refetching
@@ -3281,8 +3583,7 @@ const useNlpQuery = ({ flow } = {}) => {
3281
3583
  // Use explicit param if provided, otherwise fall back to session state
3282
3584
  const effectiveFlow = flow ?? sessionFlowId;
3283
3585
  // Only enable operations when socket is connected and ready
3284
- const isSocketReady = connectionState?.status === "authenticated" ||
3285
- connectionState?.status === "unauthenticated";
3586
+ const isSocketReady = connectionState?.status === "authenticated";
3286
3587
  // Mutation for converting natural language to GraphQL
3287
3588
  const nlpQueryMutation = reactQuery.useMutation({
3288
3589
  mutationFn: async ({ question, maxResults, }) => {
@@ -3332,8 +3633,7 @@ const useProcessing = () => {
3332
3633
  const socket = reactProvider.useSocket();
3333
3634
  const connectionState = reactProvider.useConnectionState();
3334
3635
  // Only enable queries when socket is connected and ready
3335
- const isSocketReady = connectionState?.status === "authenticated" ||
3336
- connectionState?.status === "unauthenticated";
3636
+ const isSocketReady = connectionState?.status === "authenticated";
3337
3637
  /**
3338
3638
  * Query for fetching all processing
3339
3639
  * Uses React Query for caching and background refetching
@@ -3376,8 +3676,7 @@ const useAgentTools = () => {
3376
3676
  // Notification system for user feedback
3377
3677
  const notify = useNotification();
3378
3678
  // Only enable queries when socket is connected and ready
3379
- const isSocketReady = connectionState?.status === "authenticated" ||
3380
- connectionState?.status === "unauthenticated";
3679
+ const isSocketReady = connectionState?.status === "authenticated";
3381
3680
  // Query to fetch all agent tools
3382
3681
  // Gets all tools directly from the 'tool' configuration type
3383
3682
  const toolsQuery = reactQuery.useQuery({
@@ -3539,8 +3838,7 @@ const useMcpTools = () => {
3539
3838
  // Notification system for user feedback
3540
3839
  const notify = useNotification();
3541
3840
  // Only enable queries when socket is connected and ready
3542
- const isSocketReady = connectionState?.status === "authenticated" ||
3543
- connectionState?.status === "unauthenticated";
3841
+ const isSocketReady = connectionState?.status === "authenticated";
3544
3842
  // Query to fetch all MCP tools
3545
3843
  // Uses the list operation to get all MCP tools directly
3546
3844
  const toolsQuery = reactQuery.useQuery({
@@ -3699,8 +3997,7 @@ const usePrompts = () => {
3699
3997
  // Notification system for user feedback
3700
3998
  const notify = useNotification();
3701
3999
  // Only enable queries when socket is connected and ready
3702
- const isSocketReady = connectionState?.status === "authenticated" ||
3703
- connectionState?.status === "unauthenticated";
4000
+ const isSocketReady = connectionState?.status === "authenticated";
3704
4001
  // Query to fetch the system prompt configuration
3705
4002
  // System prompt defines the AI assistant's behavior and instructions
3706
4003
  const systemPromptQuery = reactQuery.useQuery({
@@ -3720,22 +4017,21 @@ const usePrompts = () => {
3720
4017
  },
3721
4018
  });
3722
4019
  // Query to fetch all prompt templates
3723
- // First gets the template index (list of template IDs), then fetches each template's configuration
4020
+ // Lists prompt config keys, filters for template.* prefix, then fetches each template's configuration
3724
4021
  const promptsQuery = reactQuery.useQuery({
3725
4022
  queryKey: ["prompts"],
3726
4023
  enabled: isSocketReady,
3727
4024
  queryFn: () => {
3728
- // Step 1: Get the template index (array of template IDs)
3729
4025
  return socket
3730
4026
  .config()
3731
- .getConfig([{ type: "prompt", key: "template-index" }])
4027
+ .list("prompt")
3732
4028
  .then((res) => {
3733
- if (res["error"]) {
3734
- console.log("Error:", res);
3735
- throw res.error.message;
3736
- }
3737
- const promptIds = JSON.parse(res.values[0].value);
3738
- // Step 2: Fetch configuration for each template using their IDs
4029
+ const keys = res?.directory || [];
4030
+ const promptIds = keys
4031
+ .filter((k) => k.startsWith("template."))
4032
+ .map((k) => k.slice("template.".length));
4033
+ if (promptIds.length === 0)
4034
+ return [];
3739
4035
  return socket
3740
4036
  .config()
3741
4037
  .getConfig(promptIds.map((id) => ({
@@ -3747,7 +4043,6 @@ const usePrompts = () => {
3747
4043
  console.log("Error:", r);
3748
4044
  throw r.error.message;
3749
4045
  }
3750
- // Parse template configurations and pair them with their IDs
3751
4046
  const config = r.values.map((c) => JSON.parse(c.value));
3752
4047
  return promptIds.map((id, ix) => [id, config[ix]]);
3753
4048
  });
@@ -3820,41 +4115,24 @@ const usePrompts = () => {
3820
4115
  },
3821
4116
  });
3822
4117
  // Mutation for creating a new prompt template
3823
- // Updates both the template index and creates the template configuration
3824
4118
  const createPromptMutation = reactQuery.useMutation({
3825
4119
  mutationFn: ({ id, prompt, onSuccess }) => {
3826
- // Step 1: Get current template index
3827
4120
  return socket
3828
4121
  .config()
3829
- .getConfig([{ type: "prompt", key: "template-index" }])
3830
- .then((res) => JSON.parse(res.values[0].value))
3831
- .then((existingIds) => {
3832
- // Step 2: Add new template ID to the index
3833
- const newIds = [...existingIds, id];
3834
- // Step 3: Update both the template index and create the new template configuration
3835
- return socket
3836
- .config()
3837
- .putConfig([
3838
- {
3839
- type: "prompt",
3840
- key: "template-index",
3841
- value: JSON.stringify(newIds),
3842
- },
3843
- {
3844
- type: "prompt",
3845
- key: "template." + id,
3846
- value: JSON.stringify(prompt),
3847
- },
3848
- ])
3849
- .then((x) => {
3850
- if (x["error"]) {
3851
- console.log("Error:", x);
3852
- throw x.error.message;
3853
- }
3854
- // Execute callback if provided
3855
- if (onSuccess)
3856
- onSuccess();
3857
- });
4122
+ .putConfig([
4123
+ {
4124
+ type: "prompt",
4125
+ key: "template." + id,
4126
+ value: JSON.stringify(prompt),
4127
+ },
4128
+ ])
4129
+ .then((x) => {
4130
+ if (x["error"]) {
4131
+ console.log("Error:", x);
4132
+ throw x.error.message;
4133
+ }
4134
+ if (onSuccess)
4135
+ onSuccess();
3858
4136
  });
3859
4137
  },
3860
4138
  onError: (err) => {
@@ -3868,45 +4146,21 @@ const usePrompts = () => {
3868
4146
  },
3869
4147
  });
3870
4148
  // Mutation for deleting a prompt template
3871
- // Removes the template from both the index and deletes its configuration
3872
4149
  const deletePromptMutation = reactQuery.useMutation({
3873
4150
  mutationFn: ({ id, onSuccess }) => {
3874
- // Step 1: Get current template index
3875
4151
  return socket
3876
4152
  .config()
3877
- .getConfig([{ type: "prompt", key: "template-index" }])
3878
- .then((res) => JSON.parse(res.values[0].value))
3879
- .then((existingIds) => {
3880
- // Step 2: Remove the template ID from the index
3881
- const newIds = existingIds.filter((existingId) => existingId !== id);
3882
- // Step 3: Update the template index
3883
- return socket
3884
- .config()
3885
- .putConfig([
3886
- {
3887
- type: "prompt",
3888
- key: "template-index",
3889
- value: JSON.stringify(newIds),
3890
- },
3891
- ])
3892
- .then(() => {
3893
- // Step 4: Delete the template configuration
3894
- return socket.config().deleteConfig([
3895
- {
3896
- type: "prompt",
3897
- key: "template." + id,
3898
- },
3899
- ]);
3900
- })
3901
- .then((x) => {
3902
- if (x["error"]) {
3903
- console.log("Error:", x);
3904
- throw x.error.message;
3905
- }
3906
- // Execute callback if provided
3907
- if (onSuccess)
3908
- onSuccess();
3909
- });
4153
+ .deleteConfig({
4154
+ type: "prompt",
4155
+ key: "template." + id,
4156
+ })
4157
+ .then((x) => {
4158
+ if (x["error"]) {
4159
+ console.log("Error:", x);
4160
+ throw x.error.message;
4161
+ }
4162
+ if (onSuccess)
4163
+ onSuccess();
3910
4164
  });
3911
4165
  },
3912
4166
  onError: (err) => {
@@ -3961,8 +4215,7 @@ const useSchemas = () => {
3961
4215
  const queryClient = reactQuery.useQueryClient();
3962
4216
  const notify = useNotification();
3963
4217
  // Only enable queries when socket is connected and ready
3964
- const isSocketReady = connectionState?.status === "authenticated" ||
3965
- connectionState?.status === "unauthenticated";
4218
+ const isSocketReady = connectionState?.status === "authenticated";
3966
4219
  const schemasQuery = reactQuery.useQuery({
3967
4220
  queryKey: ["schemas"],
3968
4221
  enabled: isSocketReady,
@@ -4092,8 +4345,7 @@ const useOntologies = () => {
4092
4345
  const queryClient = reactQuery.useQueryClient();
4093
4346
  const notify = useNotification();
4094
4347
  // Only enable queries when socket is connected and ready
4095
- const isSocketReady = connectionState?.status === "authenticated" ||
4096
- connectionState?.status === "unauthenticated";
4348
+ const isSocketReady = connectionState?.status === "authenticated";
4097
4349
  const ontologiesQuery = reactQuery.useQuery({
4098
4350
  queryKey: ["ontologies"],
4099
4351
  enabled: isSocketReady,
@@ -4231,8 +4483,7 @@ const useKnowledgeCores = () => {
4231
4483
  // Hook for displaying user notifications
4232
4484
  const notify = useNotification();
4233
4485
  // Only enable queries when socket is connected and ready
4234
- const isSocketReady = connectionState?.status === "authenticated" ||
4235
- connectionState?.status === "unauthenticated";
4486
+ const isSocketReady = connectionState?.status === "authenticated";
4236
4487
  /**
4237
4488
  * Query for fetching all knowledge cores
4238
4489
  * Uses React Query for caching and background refetching
@@ -4334,8 +4585,7 @@ const useTokenCosts = () => {
4334
4585
  // Hook for displaying user notifications
4335
4586
  const notify = useNotification();
4336
4587
  // Only enable queries when socket is connected and ready
4337
- const isSocketReady = connectionState?.status === "authenticated" ||
4338
- connectionState?.status === "unauthenticated";
4588
+ const isSocketReady = connectionState?.status === "authenticated";
4339
4589
  /**
4340
4590
  * Query for fetching all token costs
4341
4591
  * Uses React Query for caching and background refetching
@@ -4466,8 +4716,7 @@ const useLLMModels = () => {
4466
4716
  const connectionState = reactProvider.useConnectionState();
4467
4717
  const queryClient = reactQuery.useQueryClient();
4468
4718
  const notify = useNotification();
4469
- const isSocketReady = connectionState?.status === "authenticated" ||
4470
- connectionState?.status === "unauthenticated";
4719
+ const isSocketReady = connectionState?.status === "authenticated";
4471
4720
  // Fetch the llm-model parameter type
4472
4721
  const paramTypesQuery = reactQuery.useQuery({
4473
4722
  queryKey: ["llm-models"],
@@ -4553,8 +4802,7 @@ const useFlowBlueprints = () => {
4553
4802
  // Hook for displaying user notifications
4554
4803
  const notify = useNotification();
4555
4804
  // Only enable queries when socket is connected and ready
4556
- const isSocketReady = connectionState?.status === "authenticated" ||
4557
- connectionState?.status === "unauthenticated";
4805
+ const isSocketReady = connectionState?.status === "authenticated";
4558
4806
  /**
4559
4807
  * Query for fetching all flow blueprintes
4560
4808
  * Uses React Query for caching and background refetching
@@ -4827,8 +5075,7 @@ const generateFlowBlueprintId = (baseName = "flow-class") => {
4827
5075
  const useFlowParameters = (flowBlueprintName) => {
4828
5076
  const socket = reactProvider.useSocket();
4829
5077
  const connectionState = reactProvider.useConnectionState();
4830
- const isSocketReady = connectionState?.status === "authenticated" ||
4831
- connectionState?.status === "unauthenticated";
5078
+ const isSocketReady = connectionState?.status === "authenticated";
4832
5079
  /**
4833
5080
  * Query for fetching parameter definitions for a flow blueprint
4834
5081
  */
@@ -5457,8 +5704,9 @@ const useNodeDetails = (nodeId, flowId) => {
5457
5704
  };
5458
5705
  };
5459
5706
 
5460
- // Default chunk size: 5MB (matches backend default)
5461
- const DEFAULT_CHUNK_SIZE$1 = 5 * 1024 * 1024;
5707
+ // Default chunk size: 2MB (base64 + JSON encoding inflates ~4x on the wire,
5708
+ // Pulsar message limit is around 3MB raw)
5709
+ const DEFAULT_CHUNK_SIZE$1 = 2 * 1024 * 1024;
5462
5710
  // Maximum parallel chunk uploads
5463
5711
  const DEFAULT_PARALLEL_UPLOADS = 3;
5464
5712
  /**
@@ -5575,8 +5823,7 @@ const useChunkedUpload = (options = {}) => {
5575
5823
  const upload = react.useCallback(async (params) => {
5576
5824
  const { file, title, comments = "", tags = [], collection, documentId } = params;
5577
5825
  // Validate connection
5578
- if (connectionState?.status !== "authenticated" &&
5579
- connectionState?.status !== "unauthenticated") {
5826
+ if (connectionState?.status !== "authenticated") {
5580
5827
  const error = "Not connected to server";
5581
5828
  updateProgress({ status: "error", error });
5582
5829
  onError?.(error);
@@ -5667,8 +5914,7 @@ const useChunkedUpload = (options = {}) => {
5667
5914
  const resume = react.useCallback(async (params) => {
5668
5915
  const { uploadId, file } = params;
5669
5916
  // Validate connection
5670
- if (connectionState?.status !== "authenticated" &&
5671
- connectionState?.status !== "unauthenticated") {
5917
+ if (connectionState?.status !== "authenticated") {
5672
5918
  const error = "Not connected to server";
5673
5919
  updateProgress({ status: "error", error });
5674
5920
  onError?.(error);
@@ -5887,8 +6133,7 @@ const useChunkedDownload = (options = {}) => {
5887
6133
  const download = react.useCallback((params) => {
5888
6134
  const { documentId, mimeType = "application/octet-stream", filename } = params;
5889
6135
  // Validate connection
5890
- if (connectionState?.status !== "authenticated" &&
5891
- connectionState?.status !== "unauthenticated") {
6136
+ if (connectionState?.status !== "authenticated") {
5892
6137
  const error = "Not connected to server";
5893
6138
  updateProgress({ status: "error", error });
5894
6139
  onError?.(error);
@@ -6013,8 +6258,7 @@ const useDocumentMetadata = (options = {}) => {
6013
6258
  const { documentId, enabled } = options;
6014
6259
  const socket = reactProvider.useSocket();
6015
6260
  const connectionState = reactProvider.useConnectionState();
6016
- const isSocketReady = connectionState?.status === "authenticated" ||
6017
- connectionState?.status === "unauthenticated";
6261
+ const isSocketReady = connectionState?.status === "authenticated";
6018
6262
  const query = reactQuery.useQuery({
6019
6263
  queryKey: ["document-metadata", documentId],
6020
6264
  enabled: isSocketReady && !!documentId && (enabled !== false),
@@ -6039,8 +6283,7 @@ const useDocumentsMetadata = (documentIds = []) => {
6039
6283
  const socket = reactProvider.useSocket();
6040
6284
  const connectionState = reactProvider.useConnectionState();
6041
6285
  const queryClient = reactQuery.useQueryClient();
6042
- const isSocketReady = connectionState?.status === "authenticated" ||
6043
- connectionState?.status === "unauthenticated";
6286
+ const isSocketReady = connectionState?.status === "authenticated";
6044
6287
  const query = reactQuery.useQuery({
6045
6288
  queryKey: ["documents-metadata", documentIds],
6046
6289
  enabled: isSocketReady && documentIds.length > 0,
@@ -6154,6 +6397,10 @@ Object.defineProperty(exports, "TG", {
6154
6397
  enumerable: true,
6155
6398
  get: function () { return client.TG; }
6156
6399
  });
6400
+ Object.defineProperty(exports, "TG_CONCEPT", {
6401
+ enumerable: true,
6402
+ get: function () { return client.TG_CONCEPT; }
6403
+ });
6157
6404
  Object.defineProperty(exports, "TG_CONTENT", {
6158
6405
  enumerable: true,
6159
6406
  get: function () { return client.TG_CONTENT; }
@@ -6174,14 +6421,14 @@ Object.defineProperty(exports, "TG_QUERY", {
6174
6421
  enumerable: true,
6175
6422
  get: function () { return client.TG_QUERY; }
6176
6423
  });
6177
- Object.defineProperty(exports, "TG_REASONING", {
6178
- enumerable: true,
6179
- get: function () { return client.TG_REASONING; }
6180
- });
6181
6424
  Object.defineProperty(exports, "TG_REIFIES", {
6182
6425
  enumerable: true,
6183
6426
  get: function () { return client.TG_REIFIES; }
6184
6427
  });
6428
+ Object.defineProperty(exports, "TG_SCORE", {
6429
+ enumerable: true,
6430
+ get: function () { return client.TG_SCORE; }
6431
+ });
6185
6432
  Object.defineProperty(exports, "TG_SELECTED_EDGE", {
6186
6433
  enumerable: true,
6187
6434
  get: function () { return client.TG_SELECTED_EDGE; }
@@ -6190,6 +6437,7 @@ exports.DEFAULT_SETTINGS = DEFAULT_SETTINGS;
6190
6437
  exports.NotificationProvider = NotificationProvider;
6191
6438
  exports.RDFS_LABEL = RDFS_LABEL;
6192
6439
  exports.SETTINGS_STORAGE_KEY = SETTINGS_STORAGE_KEY;
6440
+ exports.configureAuthApi = configureAuthApi;
6193
6441
  exports.createDocId = createDocId;
6194
6442
  exports.extractQuotedTriple = extractQuotedTriple;
6195
6443
  exports.fileToBase64 = fileToBase64;
@@ -6209,6 +6457,9 @@ exports.prepareMetadata = prepareMetadata;
6209
6457
  exports.textToBase64 = textToBase64;
6210
6458
  exports.useActivity = useActivity;
6211
6459
  exports.useAgentTools = useAgentTools;
6460
+ exports.useAuth = useAuth;
6461
+ exports.useAuthStore = useAuthStore;
6462
+ exports.useBootstrapStatus = useBootstrapStatus;
6212
6463
  exports.useChat = useChat;
6213
6464
  exports.useChatSession = useChatSession;
6214
6465
  exports.useChunkedDownload = useChunkedDownload;
@@ -6232,6 +6483,8 @@ exports.useKnowledgeCores = useKnowledgeCores;
6232
6483
  exports.useLLMModels = useLLMModels;
6233
6484
  exports.useLibrary = useLibrary;
6234
6485
  exports.useLoadStateStore = useLoadStateStore;
6486
+ exports.useLogin = useLogin;
6487
+ exports.useLogout = useLogout;
6235
6488
  exports.useMcpTools = useMcpTools;
6236
6489
  exports.useNlpQuery = useNlpQuery;
6237
6490
  exports.useNodeDetails = useNodeDetails;
@@ -6252,6 +6505,11 @@ exports.useStructuredQuery = useStructuredQuery;
6252
6505
  exports.useTokenCosts = useTokenCosts;
6253
6506
  exports.useTriples = useTriples;
6254
6507
  exports.useVectorSearch = useVectorSearch;
6508
+ exports.useWhoami = useWhoami;
6255
6509
  exports.useWorkbenchStateStore = useWorkbenchStateStore;
6510
+ exports.useWorkspace = useWorkspace;
6511
+ exports.useWorkspaceStore = useWorkspaceStore;
6512
+ exports.useWorkspaceSync = useWorkspaceSync;
6513
+ exports.useWorkspaces = useWorkspaces;
6256
6514
  exports.vectorSearch = vectorSearch;
6257
6515
  //# sourceMappingURL=index.cjs.map