@trustgraph/react-state 1.4.2 → 1.4.4

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.
package/dist/index.cjs CHANGED
@@ -926,17 +926,19 @@ const useTriples = ({ flow, s, p, o, limit, collection }) => {
926
926
  const notify = useNotification();
927
927
  // Settings for default collection
928
928
  const { settings } = useSettings();
929
- if (!flow)
930
- flow = "default";
929
+ // Session state for default flow ID
930
+ const sessionFlowId = useSessionStore((state) => state.flowId);
931
+ // Use explicit param if provided, otherwise fall back to session state
932
+ const effectiveFlow = flow ?? sessionFlowId;
931
933
  /**
932
934
  * Query for fetching all token costs
933
935
  * Uses React Query for caching and background refetching
934
936
  */
935
937
  const query = reactQuery.useQuery({
936
- queryKey: ["triples", { flow, s, p, o, limit }],
938
+ queryKey: ["triples", { flow: effectiveFlow, s, p, o, limit }],
937
939
  queryFn: () => {
938
940
  return socket
939
- .flow(flow)
941
+ .flow(effectiveFlow)
940
942
  .triplesQuery(s, p, o, limit, collection || settings.collection)
941
943
  .then((x) => {
942
944
  if (x["error"]) {
@@ -1302,13 +1304,17 @@ const updateSubgraphByRelationship = (socket, selectedNodeId, relationshipUri, d
1302
1304
  * Custom hook for managing graph visualization operations using React Query
1303
1305
  * Provides functionality for fetching and updating graph subgraphs
1304
1306
  * @param entityUri - The URI of the entity to build the graph around
1305
- * @param flowId - The flow ID to use for the query
1307
+ * @param flow - Optional flow ID to use for the query (defaults to session state)
1306
1308
  * @param collection - The collection to query
1307
1309
  * @returns {Object} Graph state and operations
1308
1310
  */
1309
- const useGraphSubgraph = (entityUri, flowId, collection) => {
1311
+ const useGraphSubgraph = ({ entityUri, flow, collection, }) => {
1310
1312
  // WebSocket connection for communicating with the graph service
1311
1313
  const socket = reactProvider.useSocket();
1314
+ // Session state for default flow ID
1315
+ const sessionFlowId = useSessionStore((state) => state.flowId);
1316
+ // Use explicit param if provided, otherwise fall back to session state
1317
+ const effectiveFlow = flow ?? sessionFlowId;
1312
1318
  const addActivity = useProgressStateStore((state) => state.addActivity);
1313
1319
  const removeActivity = useProgressStateStore((state) => state.removeActivity);
1314
1320
  // Hook for displaying user notifications
@@ -1320,29 +1326,29 @@ const useGraphSubgraph = (entityUri, flowId, collection) => {
1320
1326
  * Uses React Query for caching and background refetching
1321
1327
  */
1322
1328
  const query = reactQuery.useQuery({
1323
- queryKey: ["graph-subgraph", { entityUri, flowId, collection }],
1329
+ queryKey: ["graph-subgraph", { entityUri, flow: effectiveFlow, collection }],
1324
1330
  queryFn: async () => {
1325
1331
  if (!entityUri) {
1326
1332
  throw new Error("Entity URI is required");
1327
1333
  }
1328
1334
  const sg = createSubgraph();
1329
1335
  // Use the existing updateSubgraph utility function for initial load
1330
- const api = socket.flow(flowId);
1336
+ const api = socket.flow(effectiveFlow);
1331
1337
  return updateSubgraph(api, entityUri, sg, addActivity, removeActivity, collection);
1332
1338
  },
1333
- enabled: !!entityUri && !!flowId, // Only run query if both entityUri and flowId are available
1339
+ enabled: !!entityUri && !!effectiveFlow, // Only run query if both entityUri and effectiveFlow are available
1334
1340
  });
1335
1341
  /**
1336
1342
  * Mutation for updating the graph subgraph when nodes are clicked
1337
1343
  */
1338
1344
  const updateMutation = reactQuery.useMutation({
1339
1345
  mutationFn: async ({ nodeId, currentGraph, }) => {
1340
- const api = socket.flow(flowId);
1346
+ const api = socket.flow(effectiveFlow);
1341
1347
  return updateSubgraph(api, nodeId, currentGraph, addActivity, removeActivity);
1342
1348
  },
1343
1349
  onSuccess: (newGraph) => {
1344
1350
  // Update the cache with the new graph data
1345
- queryClient.setQueryData(["graph-subgraph", { entityUri, flowId, collection }], newGraph);
1351
+ queryClient.setQueryData(["graph-subgraph", { entityUri, flow: effectiveFlow, collection }], newGraph);
1346
1352
  },
1347
1353
  onError: (err) => {
1348
1354
  console.log("Graph update error:", err);
@@ -1354,12 +1360,12 @@ const useGraphSubgraph = (entityUri, flowId, collection) => {
1354
1360
  */
1355
1361
  const relationshipNavigationMutation = reactQuery.useMutation({
1356
1362
  mutationFn: async ({ selectedNodeId, relationshipUri, direction, currentGraph, }) => {
1357
- const api = socket.flow(flowId);
1363
+ const api = socket.flow(effectiveFlow);
1358
1364
  return updateSubgraphByRelationship(api, selectedNodeId, relationshipUri, direction, currentGraph, addActivity, removeActivity, collection);
1359
1365
  },
1360
1366
  onSuccess: (newGraph) => {
1361
1367
  // Update the cache with the new graph data
1362
- queryClient.setQueryData(["graph-subgraph", { entityUri, flowId, collection }], newGraph);
1368
+ queryClient.setQueryData(["graph-subgraph", { entityUri, flow: effectiveFlow, collection }], newGraph);
1363
1369
  },
1364
1370
  onError: (err) => {
1365
1371
  console.log("Relationship navigation error:", err);
@@ -1393,51 +1399,36 @@ const useGraphSubgraph = (entityUri, flowId, collection) => {
1393
1399
  };
1394
1400
 
1395
1401
  /**
1396
- * Custom hook for managing token cost operations
1397
- * Provides functionality for fetching, deleting, and updating token costs
1398
- * for AI models
1399
- * @returns {Object} Token cost state and operations
1402
+ * Custom hook for querying graph embeddings
1403
+ * Finds graph entities similar to the provided embedding vectors
1400
1404
  */
1401
- const useGraphEmbeddings = ({ flow, vecs, limit, collection }) => {
1402
- // WebSocket connection for communicating with the configuration service
1405
+ const useGraphEmbeddings = ({ flow, vecs, limit = 10, collection }) => {
1403
1406
  const socket = reactProvider.useSocket();
1404
- // Hook for displaying user notifications
1405
1407
  const notify = useNotification();
1406
- // Settings for default collection
1407
1408
  const { settings } = useSettings();
1408
- if (!flow)
1409
- flow = "default";
1410
- /**
1411
- * Query for fetching graph embeddings
1412
- * Uses React Query for caching and background refetching
1413
- */
1409
+ const sessionFlowId = useSessionStore((state) => state.flowId);
1410
+ const effectiveFlow = flow ?? sessionFlowId;
1411
+ const effectiveCollection = collection ?? settings.collection;
1414
1412
  const query = reactQuery.useQuery({
1415
- queryKey: ["graph-embeddings", { vecs, limit }],
1413
+ queryKey: ["graph-embeddings", { flow: effectiveFlow, vecs, limit, collection: effectiveCollection }],
1414
+ enabled: !!vecs && vecs.length > 0 && !!effectiveFlow,
1416
1415
  queryFn: () => {
1417
1416
  return socket
1418
- .flow(flow)
1419
- .graphEmbeddingsQuery(vecs, limit, collection || settings.collection)
1420
- .then((x) => {
1421
- return x;
1422
- })
1417
+ .flow(effectiveFlow)
1418
+ .graphEmbeddingsQuery(vecs, limit, effectiveCollection)
1423
1419
  .catch((err) => {
1424
- console.log("Error:", err);
1425
1420
  const message = err instanceof Error ? err.message : String(err);
1426
1421
  notify.error(message);
1427
1422
  throw err;
1428
1423
  });
1429
1424
  },
1430
1425
  });
1431
- // Show loading indicators for long-running operations
1432
1426
  useActivity(query.isLoading, "Loading graph embeddings");
1433
- // Return token cost state and operations for use in components
1434
1427
  return {
1435
- // Token cost query state
1436
1428
  graphEmbeddings: query.data,
1437
1429
  isLoading: query.isLoading,
1438
1430
  isError: query.isError,
1439
1431
  error: query.error,
1440
- // Manual refetch function
1441
1432
  refetch: query.refetch,
1442
1433
  };
1443
1434
  };
@@ -1621,6 +1612,8 @@ const useVectorSearch = () => {
1621
1612
  const removeActivity = useProgressStateStore((state) => state.removeActivity);
1622
1613
  // Hook for displaying user notifications
1623
1614
  const notify = useNotification();
1615
+ // Session state for default flow ID
1616
+ const sessionFlowId = useSessionStore((state) => state.flowId);
1624
1617
  // State to track current search parameters
1625
1618
  const [searchParams, setSearchParams] = react.useState(null);
1626
1619
  /**
@@ -1632,7 +1625,7 @@ const useVectorSearch = () => {
1632
1625
  enabled: !!searchParams?.term,
1633
1626
  queryFn: () => {
1634
1627
  const { flow, term, limit, collection } = searchParams;
1635
- return vectorSearch(socket, flow || "default", addActivity, removeActivity, term, collection, limit)
1628
+ return vectorSearch(socket, flow ?? sessionFlowId, addActivity, removeActivity, term, collection, limit)
1636
1629
  .then((x) => {
1637
1630
  if (x["error"]) {
1638
1631
  console.log("Error:", x);
@@ -1654,7 +1647,7 @@ const useVectorSearch = () => {
1654
1647
  return;
1655
1648
  }
1656
1649
  setSearchParams({
1657
- flow: flow || "default",
1650
+ flow: flow ?? sessionFlowId,
1658
1651
  term,
1659
1652
  limit: limit || 10,
1660
1653
  collection,
@@ -1678,13 +1671,17 @@ const useVectorSearch = () => {
1678
1671
  * Custom hook for managing entity detail operations using React Query
1679
1672
  * Provides functionality for fetching entity details and related triples
1680
1673
  * @param entityUri - The URI of the entity to fetch details for
1681
- * @param flowId - The flow ID to use for the query
1674
+ * @param flow - Optional flow ID to use for the query (defaults to session state)
1682
1675
  * @param collection - The collection to query
1683
1676
  * @returns {Object} Entity detail state and operations
1684
1677
  */
1685
- const useEntityDetail = (entityUri, flowId, collection) => {
1678
+ const useEntityDetail = ({ entityUri, flow, collection, }) => {
1686
1679
  // WebSocket connection for communicating with the graph service
1687
1680
  const socket = reactProvider.useSocket();
1681
+ // Session state for default flow ID
1682
+ const sessionFlowId = useSessionStore((state) => state.flowId);
1683
+ // Use explicit param if provided, otherwise fall back to session state
1684
+ const effectiveFlow = flow ?? sessionFlowId;
1688
1685
  const addActivity = useProgressStateStore((state) => state.addActivity);
1689
1686
  const removeActivity = useProgressStateStore((state) => state.removeActivity);
1690
1687
  // Hook for displaying user notifications
@@ -1694,17 +1691,17 @@ const useEntityDetail = (entityUri, flowId, collection) => {
1694
1691
  * Uses React Query for caching and background refetching
1695
1692
  */
1696
1693
  const query = reactQuery.useQuery({
1697
- queryKey: ["entity-detail", { entityUri, flowId, collection }],
1694
+ queryKey: ["entity-detail", { entityUri, flow: effectiveFlow, collection }],
1698
1695
  queryFn: async () => {
1699
1696
  if (!entityUri) {
1700
1697
  throw new Error("Entity URI is required");
1701
1698
  }
1702
1699
  // Use the existing getTriples utility function
1703
- const api = socket.flow(flowId);
1700
+ const api = socket.flow(effectiveFlow);
1704
1701
  return getTriples(api, entityUri, addActivity, removeActivity, undefined, collection);
1705
1702
  },
1706
- // Only run query if both entityUri and flowId are available
1707
- enabled: !!entityUri && !!flowId,
1703
+ // Only run query if both entityUri and effectiveFlow are available
1704
+ enabled: !!entityUri && !!effectiveFlow,
1708
1705
  });
1709
1706
  // Show loading indicators for long-running operations
1710
1707
  useActivity(query.isLoading, entityUri ? `Knowledge graph search: ${entityUri}` : "Loading entity");
@@ -1728,9 +1725,11 @@ const useEntityDetail = (entityUri, flowId, collection) => {
1728
1725
  * Hook providing low-level access to LLM inference services
1729
1726
  * No conversation state or side effects - just the API calls
1730
1727
  */
1731
- const useInference = () => {
1728
+ const useInference = ({ flow } = {}) => {
1732
1729
  const socket = reactProvider.useSocket();
1733
- const flowId = useSessionStore((state) => state.flowId);
1730
+ const sessionFlowId = useSessionStore((state) => state.flowId);
1731
+ // Use explicit param if provided, otherwise fall back to session state
1732
+ const effectiveFlow = flow ?? sessionFlowId;
1734
1733
  /**
1735
1734
  * Graph RAG inference with entity discovery
1736
1735
  */
@@ -1752,15 +1751,15 @@ const useInference = () => {
1752
1751
  reject(new Error(error));
1753
1752
  };
1754
1753
  socket
1755
- .flow(flowId)
1754
+ .flow(effectiveFlow)
1756
1755
  .graphRagStreaming(input, onChunk, onError, options, collection);
1757
1756
  })
1758
- : await socket.flow(flowId).graphRag(input, options || {}, collection);
1757
+ : await socket.flow(effectiveFlow).graphRag(input, options || {}, collection);
1759
1758
  // Get embeddings for entity discovery
1760
- const embeddings = await socket.flow(flowId).embeddings(input);
1759
+ const embeddings = await socket.flow(effectiveFlow).embeddings(input);
1761
1760
  // Query graph embeddings to find entities
1762
1761
  const entities = await socket
1763
- .flow(flowId)
1762
+ .flow(effectiveFlow)
1764
1763
  .graphEmbeddingsQuery(embeddings, options?.entityLimit || 10, collection);
1765
1764
  return { response, entities };
1766
1765
  },
@@ -1786,10 +1785,10 @@ const useInference = () => {
1786
1785
  reject(new Error(error));
1787
1786
  };
1788
1787
  socket
1789
- .flow(flowId)
1788
+ .flow(effectiveFlow)
1790
1789
  .textCompletionStreaming(systemPrompt, input, onChunk, onError);
1791
1790
  })
1792
- : await socket.flow(flowId).textCompletion(systemPrompt, input);
1791
+ : await socket.flow(effectiveFlow).textCompletion(systemPrompt, input);
1793
1792
  },
1794
1793
  });
1795
1794
  /**
@@ -1817,7 +1816,7 @@ const useInference = () => {
1817
1816
  reject(new Error(error));
1818
1817
  };
1819
1818
  socket
1820
- .flow(flowId)
1819
+ .flow(effectiveFlow)
1821
1820
  .agent(input, onThink, onObserve, onAnswer, onError);
1822
1821
  });
1823
1822
  },
@@ -1837,7 +1836,7 @@ const useInference = () => {
1837
1836
  * Combines conversation state with inference services
1838
1837
  * Handles routing, progress tracking, entity management, and notifications
1839
1838
  */
1840
- const useChatSession = () => {
1839
+ const useChatSession = ({ flow } = {}) => {
1841
1840
  const socket = reactProvider.useSocket();
1842
1841
  const notify = useNotification();
1843
1842
  // Conversation state
@@ -1849,12 +1848,14 @@ const useChatSession = () => {
1849
1848
  const addActivity = useProgressStateStore((state) => state.addActivity);
1850
1849
  const removeActivity = useProgressStateStore((state) => state.removeActivity);
1851
1850
  // Session and workbench state
1852
- const flowId = useSessionStore((state) => state.flowId);
1851
+ const sessionFlowId = useSessionStore((state) => state.flowId);
1853
1852
  const setEntities = useWorkbenchStateStore((state) => state.setEntities);
1853
+ // Use explicit param if provided, otherwise fall back to session state
1854
+ const effectiveFlow = flow ?? sessionFlowId;
1854
1855
  // Settings for GraphRAG configuration
1855
1856
  const { settings } = useSettings();
1856
1857
  // Inference services
1857
- const inference = useInference();
1858
+ const inference = useInference({ flow });
1858
1859
  /**
1859
1860
  * Graph RAG chat handling with entity discovery
1860
1861
  */
@@ -1899,7 +1900,7 @@ const useChatSession = () => {
1899
1900
  addActivity(labelActivity);
1900
1901
  try {
1901
1902
  const triples = await socket
1902
- .flow(flowId)
1903
+ .flow(effectiveFlow)
1903
1904
  .triplesQuery(entity, { t: "i", i: RDFS_LABEL }, undefined, 1, settings.collection);
1904
1905
  removeActivity(labelActivity);
1905
1906
  return triples;
@@ -2155,69 +2156,97 @@ const useStructuredQuery = () => {
2155
2156
  };
2156
2157
 
2157
2158
  // @ts-nocheck
2158
- // React Query hooks for data fetching and mutation management
2159
2159
  /**
2160
- * Custom hook for managing row embeddings query operations
2161
- * Provides functionality for executing semantic searches on structured data indexes
2162
- * First converts query text to embeddings, then searches for similar records
2160
+ * Custom hook for querying row embeddings using vectors.
2161
+ * Searches for similar records in structured data indexes.
2163
2162
  */
2164
- const useRowEmbeddingsQuery = () => {
2165
- // Socket connection for API calls
2163
+ const useRowEmbeddingsQuery = ({ flow } = {}) => {
2166
2164
  const socket = reactProvider.useSocket();
2167
2165
  const connectionState = reactProvider.useConnectionState();
2168
- // Notification system for user feedback
2169
2166
  const notify = useNotification();
2170
- // Session state for current flow ID
2171
- const flowId = useSessionStore((state) => state.flowId);
2172
- // Settings for default collection
2167
+ const sessionFlowId = useSessionStore((state) => state.flowId);
2173
2168
  const { settings } = useSettings();
2174
- // Only enable operations when socket is connected and ready
2169
+ const effectiveFlow = flow ?? sessionFlowId;
2175
2170
  const isSocketReady = connectionState?.status === "authenticated" ||
2176
2171
  connectionState?.status === "unauthenticated";
2177
- // Mutation for executing row embeddings queries
2178
- const rowEmbeddingsQueryMutation = reactQuery.useMutation({
2179
- mutationFn: async ({ query, schemaName, collection, indexName, limit, }) => {
2172
+ const mutation = reactQuery.useMutation({
2173
+ mutationFn: async ({ vectors, schemaName, collection, indexName, limit = 10, }) => {
2180
2174
  if (!isSocketReady) {
2181
2175
  throw new Error("Socket connection not ready");
2182
2176
  }
2183
- const flow = socket.flow(flowId);
2184
- // First, get embeddings for the query text
2185
- const vectors = await flow.embeddings(query);
2186
- // Then query row embeddings with those vectors
2187
- return flow.rowEmbeddingsQuery(vectors, schemaName, collection || settings.collection, indexName, limit || 10);
2177
+ return socket.flow(effectiveFlow).rowEmbeddingsQuery(vectors, schemaName, collection ?? settings.collection, indexName, limit);
2188
2178
  },
2189
2179
  onError: (err) => {
2190
- console.log("Row embeddings query error:", err);
2191
- const errorMessage = err instanceof Error
2192
- ? err.message
2193
- : err?.toString() || "Unknown error";
2194
- notify.error(`Row embeddings query failed: ${errorMessage}`);
2180
+ const message = err instanceof Error ? err.message : String(err);
2181
+ notify.error(`Row embeddings query failed: ${message}`);
2195
2182
  },
2196
2183
  onSuccess: (data) => {
2197
- if (data && data.length > 0) {
2198
- notify.success(`Found ${data.length} matching record${data.length !== 1 ? 's' : ''}`);
2184
+ const count = data?.length ?? 0;
2185
+ if (count > 0) {
2186
+ notify.success(`Found ${count} matching record${count !== 1 ? "s" : ""}`);
2199
2187
  }
2200
2188
  else {
2201
2189
  notify.info("No matching records found");
2202
2190
  }
2203
2191
  },
2204
2192
  });
2205
- // Show loading indicator for row embeddings query operations
2206
- useActivity(rowEmbeddingsQueryMutation.isPending, "Executing row embeddings query");
2207
- // Return the public API for the hook
2193
+ useActivity(mutation.isPending, "Querying row embeddings");
2208
2194
  return {
2209
- // Query execution
2210
- executeQuery: rowEmbeddingsQueryMutation.mutate,
2211
- executeQueryAsync: rowEmbeddingsQueryMutation.mutateAsync,
2212
- // Query state
2213
- isExecuting: rowEmbeddingsQueryMutation.isPending,
2214
- error: rowEmbeddingsQueryMutation.error,
2215
- // Results
2216
- matches: rowEmbeddingsQueryMutation.data || [],
2217
- hasResults: (rowEmbeddingsQueryMutation.data?.length || 0) > 0,
2218
- // Reset function to clear previous results
2219
- reset: rowEmbeddingsQueryMutation.reset,
2220
- // Socket readiness
2195
+ executeQuery: mutation.mutate,
2196
+ executeQueryAsync: mutation.mutateAsync,
2197
+ isExecuting: mutation.isPending,
2198
+ error: mutation.error,
2199
+ matches: mutation.data ?? [],
2200
+ hasResults: (mutation.data?.length ?? 0) > 0,
2201
+ reset: mutation.reset,
2202
+ isReady: isSocketReady,
2203
+ };
2204
+ };
2205
+
2206
+ // @ts-nocheck
2207
+ /**
2208
+ * Custom hook for querying document chunks using vectors.
2209
+ * Searches for document chunks with similar embeddings.
2210
+ */
2211
+ const useDocumentEmbeddingsQuery = ({ flow } = {}) => {
2212
+ const socket = reactProvider.useSocket();
2213
+ const connectionState = reactProvider.useConnectionState();
2214
+ const notify = useNotification();
2215
+ const sessionFlowId = useSessionStore((state) => state.flowId);
2216
+ const { settings } = useSettings();
2217
+ const effectiveFlow = flow ?? sessionFlowId;
2218
+ const isSocketReady = connectionState?.status === "authenticated" ||
2219
+ connectionState?.status === "unauthenticated";
2220
+ const mutation = reactQuery.useMutation({
2221
+ mutationFn: async ({ vectors, user, collection, limit = 10, }) => {
2222
+ if (!isSocketReady) {
2223
+ throw new Error("Socket connection not ready");
2224
+ }
2225
+ return socket.flow(effectiveFlow).documentEmbeddingsQuery(vectors, user ?? settings.user, collection ?? settings.collection, limit);
2226
+ },
2227
+ onError: (err) => {
2228
+ const message = err instanceof Error ? err.message : String(err);
2229
+ notify.error(`Document embeddings query failed: ${message}`);
2230
+ },
2231
+ onSuccess: (data) => {
2232
+ const count = Array.isArray(data) ? data.length : 0;
2233
+ if (count > 0) {
2234
+ notify.success(`Found ${count} matching chunk${count !== 1 ? "s" : ""}`);
2235
+ }
2236
+ else {
2237
+ notify.info("No matching document chunks found");
2238
+ }
2239
+ },
2240
+ });
2241
+ useActivity(mutation.isPending, "Searching document chunks");
2242
+ return {
2243
+ executeQuery: mutation.mutate,
2244
+ executeQueryAsync: mutation.mutateAsync,
2245
+ isExecuting: mutation.isPending,
2246
+ error: mutation.error,
2247
+ results: mutation.data ?? [],
2248
+ hasResults: Array.isArray(mutation.data) && mutation.data.length > 0,
2249
+ reset: mutation.reset,
2221
2250
  isReady: isSocketReady,
2222
2251
  };
2223
2252
  };
@@ -2227,14 +2256,16 @@ const useRowEmbeddingsQuery = () => {
2227
2256
  * Custom hook for managing GraphQL rows queries
2228
2257
  * Provides functionality for executing GraphQL queries against structured row data
2229
2258
  */
2230
- const useRowsQuery = () => {
2259
+ const useRowsQuery = ({ flow } = {}) => {
2231
2260
  // Socket connection for API calls
2232
2261
  const socket = reactProvider.useSocket();
2233
2262
  const connectionState = reactProvider.useConnectionState();
2234
2263
  // Notification system for user feedback
2235
2264
  const notify = useNotification();
2236
2265
  // Session state for current flow ID
2237
- const flowId = useSessionStore((state) => state.flowId);
2266
+ const sessionFlowId = useSessionStore((state) => state.flowId);
2267
+ // Use explicit param if provided, otherwise fall back to session state
2268
+ const effectiveFlow = flow ?? sessionFlowId;
2238
2269
  // Settings for default collection
2239
2270
  const { settings } = useSettings();
2240
2271
  // Only enable operations when socket is connected and ready
@@ -2247,7 +2278,7 @@ const useRowsQuery = () => {
2247
2278
  throw new Error("Socket connection not ready");
2248
2279
  }
2249
2280
  return socket
2250
- .flow(flowId)
2281
+ .flow(effectiveFlow)
2251
2282
  .rowsQuery(query, collection || settings.collection, variables, operationName);
2252
2283
  },
2253
2284
  onError: (err) => {
@@ -2293,18 +2324,20 @@ const useEmbeddings = ({ flow, term }) => {
2293
2324
  connectionState?.status === "unauthenticated";
2294
2325
  // Hook for displaying user notifications
2295
2326
  const notify = useNotification();
2296
- if (!flow)
2297
- flow = "default";
2327
+ // Session state for default flow ID
2328
+ const sessionFlowId = useSessionStore((state) => state.flowId);
2329
+ // Use explicit param if provided, otherwise fall back to session state
2330
+ const effectiveFlow = flow ?? sessionFlowId;
2298
2331
  /**
2299
2332
  * Query for fetching all token costs
2300
2333
  * Uses React Query for caching and background refetching
2301
2334
  */
2302
2335
  const query = reactQuery.useQuery({
2303
- queryKey: ["embeddings", { flow, term }],
2304
- enabled: isSocketReady && !!term && !!flow,
2336
+ queryKey: ["embeddings", { flow: effectiveFlow, term }],
2337
+ enabled: isSocketReady && !!term && !!effectiveFlow,
2305
2338
  queryFn: () => {
2306
2339
  return socket
2307
- .flow(flow)
2340
+ .flow(effectiveFlow)
2308
2341
  .embeddings(term)
2309
2342
  .then((x) => {
2310
2343
  if (x["error"]) {
@@ -2442,14 +2475,16 @@ const useCollections = () => {
2442
2475
  * Custom hook for managing NLP query operations
2443
2476
  * Provides functionality for converting natural language questions to GraphQL queries
2444
2477
  */
2445
- const useNlpQuery = () => {
2478
+ const useNlpQuery = ({ flow } = {}) => {
2446
2479
  // Socket connection for API calls
2447
2480
  const socket = reactProvider.useSocket();
2448
2481
  const connectionState = reactProvider.useConnectionState();
2449
2482
  // Notification system for user feedback
2450
2483
  const notify = useNotification();
2451
2484
  // Session state for current flow ID
2452
- const flowId = useSessionStore((state) => state.flowId);
2485
+ const sessionFlowId = useSessionStore((state) => state.flowId);
2486
+ // Use explicit param if provided, otherwise fall back to session state
2487
+ const effectiveFlow = flow ?? sessionFlowId;
2453
2488
  // Only enable operations when socket is connected and ready
2454
2489
  const isSocketReady = connectionState?.status === "authenticated" ||
2455
2490
  connectionState?.status === "unauthenticated";
@@ -2459,7 +2494,7 @@ const useNlpQuery = () => {
2459
2494
  if (!isSocketReady) {
2460
2495
  throw new Error("Socket connection not ready");
2461
2496
  }
2462
- return socket.flow(flowId).nlpQuery(question, maxResults);
2497
+ return socket.flow(effectiveFlow).nlpQuery(question, maxResults);
2463
2498
  },
2464
2499
  onError: (err) => {
2465
2500
  console.log("NLP query error:", err);
@@ -4664,6 +4699,7 @@ exports.useChat = useChat;
4664
4699
  exports.useChatSession = useChatSession;
4665
4700
  exports.useCollections = useCollections;
4666
4701
  exports.useConversation = useConversation;
4702
+ exports.useDocumentEmbeddingsQuery = useDocumentEmbeddingsQuery;
4667
4703
  exports.useEmbeddings = useEmbeddings;
4668
4704
  exports.useEntityDetail = useEntityDetail;
4669
4705
  exports.useFlowBlueprints = useFlowBlueprints;