@trustgraph/react-state 1.4.1 → 1.4.3

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.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { SocketProvider, SocketContext, ConnectionStateContext, } from "@trustgraph/react-provider";
2
2
  export type { SocketProviderProps } from "@trustgraph/react-provider";
3
- export type { BaseApi, Triple, Term, IriTerm, BlankTerm, LiteralTerm, TripleTerm, ConnectionState, StreamingMetadata, } from "@trustgraph/client";
3
+ export type { BaseApi, Triple, Term, IriTerm, BlankTerm, LiteralTerm, TripleTerm, ConnectionState, StreamingMetadata, RowEmbeddingsMatch, } from "@trustgraph/client";
4
4
  export { NotificationProvider } from "./NotificationProvider";
5
5
  export type { NotificationProviderProps } from "./NotificationProvider";
6
6
  export type { NotificationHandler } from "./types";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,cAAc,EACd,aAAa,EACb,sBAAsB,GACvB,MAAM,4BAA4B,CAAC;AACpC,YAAY,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAGtE,YAAY,EACV,OAAO,EACP,MAAM,EACN,IAAI,EACJ,OAAO,EACP,SAAS,EACT,WAAW,EACX,UAAU,EACV,eAAe,EACf,iBAAiB,GAClB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,YAAY,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AACxE,YAAY,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAGnD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGlD,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,YAAY,EAAE,aAAa,EAAE,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UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC/E,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACzE,YAAY,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC"}
package/dist/index.esm.js CHANGED
@@ -149,12 +149,7 @@ const useSessionStore = create()((set) => ({
149
149
  }));
150
150
 
151
151
  const useConversation = create()((set) => ({
152
- messages: [
153
- {
154
- role: "ai",
155
- text: "Welcome to the TrustGraph Test Suite. Use the chat interface to perform Graph RAG requests.",
156
- },
157
- ],
152
+ messages: [],
158
153
  input: "",
159
154
  chatMode: "graph-rag",
160
155
  setMessages: (v) => set(() => ({
@@ -930,17 +925,19 @@ const useTriples = ({ flow, s, p, o, limit, collection }) => {
930
925
  const notify = useNotification();
931
926
  // Settings for default collection
932
927
  const { settings } = useSettings();
933
- if (!flow)
934
- flow = "default";
928
+ // Session state for default flow ID
929
+ const sessionFlowId = useSessionStore((state) => state.flowId);
930
+ // Use explicit param if provided, otherwise fall back to session state
931
+ const effectiveFlow = flow ?? sessionFlowId;
935
932
  /**
936
933
  * Query for fetching all token costs
937
934
  * Uses React Query for caching and background refetching
938
935
  */
939
936
  const query = useQuery({
940
- queryKey: ["triples", { flow, s, p, o, limit }],
937
+ queryKey: ["triples", { flow: effectiveFlow, s, p, o, limit }],
941
938
  queryFn: () => {
942
939
  return socket
943
- .flow(flow)
940
+ .flow(effectiveFlow)
944
941
  .triplesQuery(s, p, o, limit, collection || settings.collection)
945
942
  .then((x) => {
946
943
  if (x["error"]) {
@@ -1306,13 +1303,17 @@ const updateSubgraphByRelationship = (socket, selectedNodeId, relationshipUri, d
1306
1303
  * Custom hook for managing graph visualization operations using React Query
1307
1304
  * Provides functionality for fetching and updating graph subgraphs
1308
1305
  * @param entityUri - The URI of the entity to build the graph around
1309
- * @param flowId - The flow ID to use for the query
1306
+ * @param flow - Optional flow ID to use for the query (defaults to session state)
1310
1307
  * @param collection - The collection to query
1311
1308
  * @returns {Object} Graph state and operations
1312
1309
  */
1313
- const useGraphSubgraph = (entityUri, flowId, collection) => {
1310
+ const useGraphSubgraph = ({ entityUri, flow, collection, }) => {
1314
1311
  // WebSocket connection for communicating with the graph service
1315
1312
  const socket = useSocket();
1313
+ // Session state for default flow ID
1314
+ const sessionFlowId = useSessionStore((state) => state.flowId);
1315
+ // Use explicit param if provided, otherwise fall back to session state
1316
+ const effectiveFlow = flow ?? sessionFlowId;
1316
1317
  const addActivity = useProgressStateStore((state) => state.addActivity);
1317
1318
  const removeActivity = useProgressStateStore((state) => state.removeActivity);
1318
1319
  // Hook for displaying user notifications
@@ -1324,29 +1325,29 @@ const useGraphSubgraph = (entityUri, flowId, collection) => {
1324
1325
  * Uses React Query for caching and background refetching
1325
1326
  */
1326
1327
  const query = useQuery({
1327
- queryKey: ["graph-subgraph", { entityUri, flowId, collection }],
1328
+ queryKey: ["graph-subgraph", { entityUri, flow: effectiveFlow, collection }],
1328
1329
  queryFn: async () => {
1329
1330
  if (!entityUri) {
1330
1331
  throw new Error("Entity URI is required");
1331
1332
  }
1332
1333
  const sg = createSubgraph();
1333
1334
  // Use the existing updateSubgraph utility function for initial load
1334
- const api = socket.flow(flowId);
1335
+ const api = socket.flow(effectiveFlow);
1335
1336
  return updateSubgraph(api, entityUri, sg, addActivity, removeActivity, collection);
1336
1337
  },
1337
- enabled: !!entityUri && !!flowId, // Only run query if both entityUri and flowId are available
1338
+ enabled: !!entityUri && !!effectiveFlow, // Only run query if both entityUri and effectiveFlow are available
1338
1339
  });
1339
1340
  /**
1340
1341
  * Mutation for updating the graph subgraph when nodes are clicked
1341
1342
  */
1342
1343
  const updateMutation = useMutation({
1343
1344
  mutationFn: async ({ nodeId, currentGraph, }) => {
1344
- const api = socket.flow(flowId);
1345
+ const api = socket.flow(effectiveFlow);
1345
1346
  return updateSubgraph(api, nodeId, currentGraph, addActivity, removeActivity);
1346
1347
  },
1347
1348
  onSuccess: (newGraph) => {
1348
1349
  // Update the cache with the new graph data
1349
- queryClient.setQueryData(["graph-subgraph", { entityUri, flowId, collection }], newGraph);
1350
+ queryClient.setQueryData(["graph-subgraph", { entityUri, flow: effectiveFlow, collection }], newGraph);
1350
1351
  },
1351
1352
  onError: (err) => {
1352
1353
  console.log("Graph update error:", err);
@@ -1358,12 +1359,12 @@ const useGraphSubgraph = (entityUri, flowId, collection) => {
1358
1359
  */
1359
1360
  const relationshipNavigationMutation = useMutation({
1360
1361
  mutationFn: async ({ selectedNodeId, relationshipUri, direction, currentGraph, }) => {
1361
- const api = socket.flow(flowId);
1362
+ const api = socket.flow(effectiveFlow);
1362
1363
  return updateSubgraphByRelationship(api, selectedNodeId, relationshipUri, direction, currentGraph, addActivity, removeActivity, collection);
1363
1364
  },
1364
1365
  onSuccess: (newGraph) => {
1365
1366
  // Update the cache with the new graph data
1366
- queryClient.setQueryData(["graph-subgraph", { entityUri, flowId, collection }], newGraph);
1367
+ queryClient.setQueryData(["graph-subgraph", { entityUri, flow: effectiveFlow, collection }], newGraph);
1367
1368
  },
1368
1369
  onError: (err) => {
1369
1370
  console.log("Relationship navigation error:", err);
@@ -1409,17 +1410,19 @@ const useGraphEmbeddings = ({ flow, vecs, limit, collection }) => {
1409
1410
  const notify = useNotification();
1410
1411
  // Settings for default collection
1411
1412
  const { settings } = useSettings();
1412
- if (!flow)
1413
- flow = "default";
1413
+ // Session state for default flow ID
1414
+ const sessionFlowId = useSessionStore((state) => state.flowId);
1415
+ // Use explicit param if provided, otherwise fall back to session state
1416
+ const effectiveFlow = flow ?? sessionFlowId;
1414
1417
  /**
1415
1418
  * Query for fetching graph embeddings
1416
1419
  * Uses React Query for caching and background refetching
1417
1420
  */
1418
1421
  const query = useQuery({
1419
- queryKey: ["graph-embeddings", { vecs, limit }],
1422
+ queryKey: ["graph-embeddings", { flow: effectiveFlow, vecs, limit }],
1420
1423
  queryFn: () => {
1421
1424
  return socket
1422
- .flow(flow)
1425
+ .flow(effectiveFlow)
1423
1426
  .graphEmbeddingsQuery(vecs, limit, collection || settings.collection)
1424
1427
  .then((x) => {
1425
1428
  return x;
@@ -1625,6 +1628,8 @@ const useVectorSearch = () => {
1625
1628
  const removeActivity = useProgressStateStore((state) => state.removeActivity);
1626
1629
  // Hook for displaying user notifications
1627
1630
  const notify = useNotification();
1631
+ // Session state for default flow ID
1632
+ const sessionFlowId = useSessionStore((state) => state.flowId);
1628
1633
  // State to track current search parameters
1629
1634
  const [searchParams, setSearchParams] = useState(null);
1630
1635
  /**
@@ -1636,7 +1641,7 @@ const useVectorSearch = () => {
1636
1641
  enabled: !!searchParams?.term,
1637
1642
  queryFn: () => {
1638
1643
  const { flow, term, limit, collection } = searchParams;
1639
- return vectorSearch(socket, flow || "default", addActivity, removeActivity, term, collection, limit)
1644
+ return vectorSearch(socket, flow ?? sessionFlowId, addActivity, removeActivity, term, collection, limit)
1640
1645
  .then((x) => {
1641
1646
  if (x["error"]) {
1642
1647
  console.log("Error:", x);
@@ -1658,7 +1663,7 @@ const useVectorSearch = () => {
1658
1663
  return;
1659
1664
  }
1660
1665
  setSearchParams({
1661
- flow: flow || "default",
1666
+ flow: flow ?? sessionFlowId,
1662
1667
  term,
1663
1668
  limit: limit || 10,
1664
1669
  collection,
@@ -1682,13 +1687,17 @@ const useVectorSearch = () => {
1682
1687
  * Custom hook for managing entity detail operations using React Query
1683
1688
  * Provides functionality for fetching entity details and related triples
1684
1689
  * @param entityUri - The URI of the entity to fetch details for
1685
- * @param flowId - The flow ID to use for the query
1690
+ * @param flow - Optional flow ID to use for the query (defaults to session state)
1686
1691
  * @param collection - The collection to query
1687
1692
  * @returns {Object} Entity detail state and operations
1688
1693
  */
1689
- const useEntityDetail = (entityUri, flowId, collection) => {
1694
+ const useEntityDetail = ({ entityUri, flow, collection, }) => {
1690
1695
  // WebSocket connection for communicating with the graph service
1691
1696
  const socket = useSocket();
1697
+ // Session state for default flow ID
1698
+ const sessionFlowId = useSessionStore((state) => state.flowId);
1699
+ // Use explicit param if provided, otherwise fall back to session state
1700
+ const effectiveFlow = flow ?? sessionFlowId;
1692
1701
  const addActivity = useProgressStateStore((state) => state.addActivity);
1693
1702
  const removeActivity = useProgressStateStore((state) => state.removeActivity);
1694
1703
  // Hook for displaying user notifications
@@ -1698,17 +1707,17 @@ const useEntityDetail = (entityUri, flowId, collection) => {
1698
1707
  * Uses React Query for caching and background refetching
1699
1708
  */
1700
1709
  const query = useQuery({
1701
- queryKey: ["entity-detail", { entityUri, flowId, collection }],
1710
+ queryKey: ["entity-detail", { entityUri, flow: effectiveFlow, collection }],
1702
1711
  queryFn: async () => {
1703
1712
  if (!entityUri) {
1704
1713
  throw new Error("Entity URI is required");
1705
1714
  }
1706
1715
  // Use the existing getTriples utility function
1707
- const api = socket.flow(flowId);
1716
+ const api = socket.flow(effectiveFlow);
1708
1717
  return getTriples(api, entityUri, addActivity, removeActivity, undefined, collection);
1709
1718
  },
1710
- // Only run query if both entityUri and flowId are available
1711
- enabled: !!entityUri && !!flowId,
1719
+ // Only run query if both entityUri and effectiveFlow are available
1720
+ enabled: !!entityUri && !!effectiveFlow,
1712
1721
  });
1713
1722
  // Show loading indicators for long-running operations
1714
1723
  useActivity(query.isLoading, entityUri ? `Knowledge graph search: ${entityUri}` : "Loading entity");
@@ -1732,9 +1741,11 @@ const useEntityDetail = (entityUri, flowId, collection) => {
1732
1741
  * Hook providing low-level access to LLM inference services
1733
1742
  * No conversation state or side effects - just the API calls
1734
1743
  */
1735
- const useInference = () => {
1744
+ const useInference = ({ flow } = {}) => {
1736
1745
  const socket = useSocket();
1737
- const flowId = useSessionStore((state) => state.flowId);
1746
+ const sessionFlowId = useSessionStore((state) => state.flowId);
1747
+ // Use explicit param if provided, otherwise fall back to session state
1748
+ const effectiveFlow = flow ?? sessionFlowId;
1738
1749
  /**
1739
1750
  * Graph RAG inference with entity discovery
1740
1751
  */
@@ -1756,15 +1767,15 @@ const useInference = () => {
1756
1767
  reject(new Error(error));
1757
1768
  };
1758
1769
  socket
1759
- .flow(flowId)
1770
+ .flow(effectiveFlow)
1760
1771
  .graphRagStreaming(input, onChunk, onError, options, collection);
1761
1772
  })
1762
- : await socket.flow(flowId).graphRag(input, options || {}, collection);
1773
+ : await socket.flow(effectiveFlow).graphRag(input, options || {}, collection);
1763
1774
  // Get embeddings for entity discovery
1764
- const embeddings = await socket.flow(flowId).embeddings(input);
1775
+ const embeddings = await socket.flow(effectiveFlow).embeddings(input);
1765
1776
  // Query graph embeddings to find entities
1766
1777
  const entities = await socket
1767
- .flow(flowId)
1778
+ .flow(effectiveFlow)
1768
1779
  .graphEmbeddingsQuery(embeddings, options?.entityLimit || 10, collection);
1769
1780
  return { response, entities };
1770
1781
  },
@@ -1790,10 +1801,10 @@ const useInference = () => {
1790
1801
  reject(new Error(error));
1791
1802
  };
1792
1803
  socket
1793
- .flow(flowId)
1804
+ .flow(effectiveFlow)
1794
1805
  .textCompletionStreaming(systemPrompt, input, onChunk, onError);
1795
1806
  })
1796
- : await socket.flow(flowId).textCompletion(systemPrompt, input);
1807
+ : await socket.flow(effectiveFlow).textCompletion(systemPrompt, input);
1797
1808
  },
1798
1809
  });
1799
1810
  /**
@@ -1821,7 +1832,7 @@ const useInference = () => {
1821
1832
  reject(new Error(error));
1822
1833
  };
1823
1834
  socket
1824
- .flow(flowId)
1835
+ .flow(effectiveFlow)
1825
1836
  .agent(input, onThink, onObserve, onAnswer, onError);
1826
1837
  });
1827
1838
  },
@@ -1841,7 +1852,7 @@ const useInference = () => {
1841
1852
  * Combines conversation state with inference services
1842
1853
  * Handles routing, progress tracking, entity management, and notifications
1843
1854
  */
1844
- const useChatSession = () => {
1855
+ const useChatSession = ({ flow } = {}) => {
1845
1856
  const socket = useSocket();
1846
1857
  const notify = useNotification();
1847
1858
  // Conversation state
@@ -1853,12 +1864,14 @@ const useChatSession = () => {
1853
1864
  const addActivity = useProgressStateStore((state) => state.addActivity);
1854
1865
  const removeActivity = useProgressStateStore((state) => state.removeActivity);
1855
1866
  // Session and workbench state
1856
- const flowId = useSessionStore((state) => state.flowId);
1867
+ const sessionFlowId = useSessionStore((state) => state.flowId);
1857
1868
  const setEntities = useWorkbenchStateStore((state) => state.setEntities);
1869
+ // Use explicit param if provided, otherwise fall back to session state
1870
+ const effectiveFlow = flow ?? sessionFlowId;
1858
1871
  // Settings for GraphRAG configuration
1859
1872
  const { settings } = useSettings();
1860
1873
  // Inference services
1861
- const inference = useInference();
1874
+ const inference = useInference({ flow });
1862
1875
  /**
1863
1876
  * Graph RAG chat handling with entity discovery
1864
1877
  */
@@ -1903,7 +1916,7 @@ const useChatSession = () => {
1903
1916
  addActivity(labelActivity);
1904
1917
  try {
1905
1918
  const triples = await socket
1906
- .flow(flowId)
1919
+ .flow(effectiveFlow)
1907
1920
  .triplesQuery(entity, { t: "i", i: RDFS_LABEL }, undefined, 1, settings.collection);
1908
1921
  removeActivity(labelActivity);
1909
1922
  return triples;
@@ -2165,16 +2178,18 @@ const useStructuredQuery = () => {
2165
2178
  * Provides functionality for executing semantic searches on structured data indexes
2166
2179
  * First converts query text to embeddings, then searches for similar records
2167
2180
  */
2168
- const useRowEmbeddingsQuery = () => {
2181
+ const useRowEmbeddingsQuery = ({ flow } = {}) => {
2169
2182
  // Socket connection for API calls
2170
2183
  const socket = useSocket();
2171
2184
  const connectionState = useConnectionState();
2172
2185
  // Notification system for user feedback
2173
2186
  const notify = useNotification();
2174
2187
  // Session state for current flow ID
2175
- const flowId = useSessionStore((state) => state.flowId);
2188
+ const sessionFlowId = useSessionStore((state) => state.flowId);
2176
2189
  // Settings for default collection
2177
2190
  const { settings } = useSettings();
2191
+ // Use explicit param if provided, otherwise fall back to session state
2192
+ const effectiveFlow = flow ?? sessionFlowId;
2178
2193
  // Only enable operations when socket is connected and ready
2179
2194
  const isSocketReady = connectionState?.status === "authenticated" ||
2180
2195
  connectionState?.status === "unauthenticated";
@@ -2184,11 +2199,11 @@ const useRowEmbeddingsQuery = () => {
2184
2199
  if (!isSocketReady) {
2185
2200
  throw new Error("Socket connection not ready");
2186
2201
  }
2187
- const flow = socket.flow(flowId);
2202
+ const flowApi = socket.flow(effectiveFlow);
2188
2203
  // First, get embeddings for the query text
2189
- const vectors = await flow.embeddings(query);
2204
+ const vectors = await flowApi.embeddings(query);
2190
2205
  // Then query row embeddings with those vectors
2191
- return flow.rowEmbeddingsQuery(vectors, schemaName, collection || settings.collection, indexName, limit || 10);
2206
+ return flowApi.rowEmbeddingsQuery(vectors, schemaName, collection || settings.collection, indexName, limit || 10);
2192
2207
  },
2193
2208
  onError: (err) => {
2194
2209
  console.log("Row embeddings query error:", err);
@@ -2231,14 +2246,16 @@ const useRowEmbeddingsQuery = () => {
2231
2246
  * Custom hook for managing GraphQL rows queries
2232
2247
  * Provides functionality for executing GraphQL queries against structured row data
2233
2248
  */
2234
- const useRowsQuery = () => {
2249
+ const useRowsQuery = ({ flow } = {}) => {
2235
2250
  // Socket connection for API calls
2236
2251
  const socket = useSocket();
2237
2252
  const connectionState = useConnectionState();
2238
2253
  // Notification system for user feedback
2239
2254
  const notify = useNotification();
2240
2255
  // Session state for current flow ID
2241
- const flowId = useSessionStore((state) => state.flowId);
2256
+ const sessionFlowId = useSessionStore((state) => state.flowId);
2257
+ // Use explicit param if provided, otherwise fall back to session state
2258
+ const effectiveFlow = flow ?? sessionFlowId;
2242
2259
  // Settings for default collection
2243
2260
  const { settings } = useSettings();
2244
2261
  // Only enable operations when socket is connected and ready
@@ -2251,7 +2268,7 @@ const useRowsQuery = () => {
2251
2268
  throw new Error("Socket connection not ready");
2252
2269
  }
2253
2270
  return socket
2254
- .flow(flowId)
2271
+ .flow(effectiveFlow)
2255
2272
  .rowsQuery(query, collection || settings.collection, variables, operationName);
2256
2273
  },
2257
2274
  onError: (err) => {
@@ -2297,18 +2314,20 @@ const useEmbeddings = ({ flow, term }) => {
2297
2314
  connectionState?.status === "unauthenticated";
2298
2315
  // Hook for displaying user notifications
2299
2316
  const notify = useNotification();
2300
- if (!flow)
2301
- flow = "default";
2317
+ // Session state for default flow ID
2318
+ const sessionFlowId = useSessionStore((state) => state.flowId);
2319
+ // Use explicit param if provided, otherwise fall back to session state
2320
+ const effectiveFlow = flow ?? sessionFlowId;
2302
2321
  /**
2303
2322
  * Query for fetching all token costs
2304
2323
  * Uses React Query for caching and background refetching
2305
2324
  */
2306
2325
  const query = useQuery({
2307
- queryKey: ["embeddings", { flow, term }],
2308
- enabled: isSocketReady && !!term && !!flow,
2326
+ queryKey: ["embeddings", { flow: effectiveFlow, term }],
2327
+ enabled: isSocketReady && !!term && !!effectiveFlow,
2309
2328
  queryFn: () => {
2310
2329
  return socket
2311
- .flow(flow)
2330
+ .flow(effectiveFlow)
2312
2331
  .embeddings(term)
2313
2332
  .then((x) => {
2314
2333
  if (x["error"]) {
@@ -2446,14 +2465,16 @@ const useCollections = () => {
2446
2465
  * Custom hook for managing NLP query operations
2447
2466
  * Provides functionality for converting natural language questions to GraphQL queries
2448
2467
  */
2449
- const useNlpQuery = () => {
2468
+ const useNlpQuery = ({ flow } = {}) => {
2450
2469
  // Socket connection for API calls
2451
2470
  const socket = useSocket();
2452
2471
  const connectionState = useConnectionState();
2453
2472
  // Notification system for user feedback
2454
2473
  const notify = useNotification();
2455
2474
  // Session state for current flow ID
2456
- const flowId = useSessionStore((state) => state.flowId);
2475
+ const sessionFlowId = useSessionStore((state) => state.flowId);
2476
+ // Use explicit param if provided, otherwise fall back to session state
2477
+ const effectiveFlow = flow ?? sessionFlowId;
2457
2478
  // Only enable operations when socket is connected and ready
2458
2479
  const isSocketReady = connectionState?.status === "authenticated" ||
2459
2480
  connectionState?.status === "unauthenticated";
@@ -2463,7 +2484,7 @@ const useNlpQuery = () => {
2463
2484
  if (!isSocketReady) {
2464
2485
  throw new Error("Socket connection not ready");
2465
2486
  }
2466
- return socket.flow(flowId).nlpQuery(question, maxResults);
2487
+ return socket.flow(effectiveFlow).nlpQuery(question, maxResults);
2467
2488
  },
2468
2489
  onError: (err) => {
2469
2490
  console.log("NLP query error:", err);