@trustgraph/react-state 1.3.1 → 1.4.1
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/README.md +1 -1
- package/dist/index.cjs +84 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +83 -15
- package/dist/index.esm.js.map +1 -1
- package/dist/state/row-embeddings-query.d.ts +29 -0
- package/dist/state/row-embeddings-query.d.ts.map +1 -0
- package/dist/state/{objects-query.d.ts → rows-query.d.ts} +4 -4
- package/dist/state/rows-query.d.ts.map +1 -0
- package/package.json +5 -5
- package/dist/state/objects-query.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -156,7 +156,7 @@ const handler: NotificationHandler = {
|
|
|
156
156
|
- `useChat()` - Chat interface operations
|
|
157
157
|
- `useChatQuery()` - Chat query management
|
|
158
158
|
- `useStructuredQuery()` - Structured query operations
|
|
159
|
-
- `
|
|
159
|
+
- `useRowsQuery()` - Row queries
|
|
160
160
|
- `useNlpQuery()` - Natural language processing queries
|
|
161
161
|
|
|
162
162
|
#### Configuration
|
package/dist/index.cjs
CHANGED
|
@@ -2159,12 +2159,80 @@ const useStructuredQuery = () => {
|
|
|
2159
2159
|
};
|
|
2160
2160
|
};
|
|
2161
2161
|
|
|
2162
|
+
// @ts-nocheck
|
|
2163
|
+
// React Query hooks for data fetching and mutation management
|
|
2164
|
+
/**
|
|
2165
|
+
* Custom hook for managing row embeddings query operations
|
|
2166
|
+
* Provides functionality for executing semantic searches on structured data indexes
|
|
2167
|
+
* First converts query text to embeddings, then searches for similar records
|
|
2168
|
+
*/
|
|
2169
|
+
const useRowEmbeddingsQuery = () => {
|
|
2170
|
+
// Socket connection for API calls
|
|
2171
|
+
const socket = reactProvider.useSocket();
|
|
2172
|
+
const connectionState = reactProvider.useConnectionState();
|
|
2173
|
+
// Notification system for user feedback
|
|
2174
|
+
const notify = useNotification();
|
|
2175
|
+
// Session state for current flow ID
|
|
2176
|
+
const flowId = useSessionStore((state) => state.flowId);
|
|
2177
|
+
// Settings for default collection
|
|
2178
|
+
const { settings } = useSettings();
|
|
2179
|
+
// Only enable operations when socket is connected and ready
|
|
2180
|
+
const isSocketReady = connectionState?.status === "authenticated" ||
|
|
2181
|
+
connectionState?.status === "unauthenticated";
|
|
2182
|
+
// Mutation for executing row embeddings queries
|
|
2183
|
+
const rowEmbeddingsQueryMutation = reactQuery.useMutation({
|
|
2184
|
+
mutationFn: async ({ query, schemaName, collection, indexName, limit, }) => {
|
|
2185
|
+
if (!isSocketReady) {
|
|
2186
|
+
throw new Error("Socket connection not ready");
|
|
2187
|
+
}
|
|
2188
|
+
const flow = socket.flow(flowId);
|
|
2189
|
+
// First, get embeddings for the query text
|
|
2190
|
+
const vectors = await flow.embeddings(query);
|
|
2191
|
+
// Then query row embeddings with those vectors
|
|
2192
|
+
return flow.rowEmbeddingsQuery(vectors, schemaName, collection || settings.collection, indexName, limit || 10);
|
|
2193
|
+
},
|
|
2194
|
+
onError: (err) => {
|
|
2195
|
+
console.log("Row embeddings query error:", err);
|
|
2196
|
+
const errorMessage = err instanceof Error
|
|
2197
|
+
? err.message
|
|
2198
|
+
: err?.toString() || "Unknown error";
|
|
2199
|
+
notify.error(`Row embeddings query failed: ${errorMessage}`);
|
|
2200
|
+
},
|
|
2201
|
+
onSuccess: (data) => {
|
|
2202
|
+
if (data && data.length > 0) {
|
|
2203
|
+
notify.success(`Found ${data.length} matching record${data.length !== 1 ? 's' : ''}`);
|
|
2204
|
+
}
|
|
2205
|
+
else {
|
|
2206
|
+
notify.info("No matching records found");
|
|
2207
|
+
}
|
|
2208
|
+
},
|
|
2209
|
+
});
|
|
2210
|
+
// Show loading indicator for row embeddings query operations
|
|
2211
|
+
useActivity(rowEmbeddingsQueryMutation.isPending, "Executing row embeddings query");
|
|
2212
|
+
// Return the public API for the hook
|
|
2213
|
+
return {
|
|
2214
|
+
// Query execution
|
|
2215
|
+
executeQuery: rowEmbeddingsQueryMutation.mutate,
|
|
2216
|
+
executeQueryAsync: rowEmbeddingsQueryMutation.mutateAsync,
|
|
2217
|
+
// Query state
|
|
2218
|
+
isExecuting: rowEmbeddingsQueryMutation.isPending,
|
|
2219
|
+
error: rowEmbeddingsQueryMutation.error,
|
|
2220
|
+
// Results
|
|
2221
|
+
matches: rowEmbeddingsQueryMutation.data || [],
|
|
2222
|
+
hasResults: (rowEmbeddingsQueryMutation.data?.length || 0) > 0,
|
|
2223
|
+
// Reset function to clear previous results
|
|
2224
|
+
reset: rowEmbeddingsQueryMutation.reset,
|
|
2225
|
+
// Socket readiness
|
|
2226
|
+
isReady: isSocketReady,
|
|
2227
|
+
};
|
|
2228
|
+
};
|
|
2229
|
+
|
|
2162
2230
|
// React Query hooks for data fetching and mutation management
|
|
2163
2231
|
/**
|
|
2164
|
-
* Custom hook for managing GraphQL
|
|
2165
|
-
* Provides functionality for executing GraphQL queries against structured data
|
|
2232
|
+
* Custom hook for managing GraphQL rows queries
|
|
2233
|
+
* Provides functionality for executing GraphQL queries against structured row data
|
|
2166
2234
|
*/
|
|
2167
|
-
const
|
|
2235
|
+
const useRowsQuery = () => {
|
|
2168
2236
|
// Socket connection for API calls
|
|
2169
2237
|
const socket = reactProvider.useSocket();
|
|
2170
2238
|
const connectionState = reactProvider.useConnectionState();
|
|
@@ -2177,18 +2245,18 @@ const useObjectsQuery = () => {
|
|
|
2177
2245
|
// Only enable operations when socket is connected and ready
|
|
2178
2246
|
const isSocketReady = connectionState?.status === "authenticated" ||
|
|
2179
2247
|
connectionState?.status === "unauthenticated";
|
|
2180
|
-
// Mutation for executing GraphQL
|
|
2181
|
-
const
|
|
2248
|
+
// Mutation for executing GraphQL rows queries
|
|
2249
|
+
const rowsQueryMutation = reactQuery.useMutation({
|
|
2182
2250
|
mutationFn: async ({ query, collection, variables, operationName, }) => {
|
|
2183
2251
|
if (!isSocketReady) {
|
|
2184
2252
|
throw new Error("Socket connection not ready");
|
|
2185
2253
|
}
|
|
2186
2254
|
return socket
|
|
2187
2255
|
.flow(flowId)
|
|
2188
|
-
.
|
|
2256
|
+
.rowsQuery(query, collection || settings.collection, variables, operationName);
|
|
2189
2257
|
},
|
|
2190
2258
|
onError: (err) => {
|
|
2191
|
-
console.log("
|
|
2259
|
+
console.log("Rows query error:", err);
|
|
2192
2260
|
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
2193
2261
|
notify.error(`GraphQL query failed: ${errorMessage}`);
|
|
2194
2262
|
},
|
|
@@ -2197,18 +2265,18 @@ const useObjectsQuery = () => {
|
|
|
2197
2265
|
},
|
|
2198
2266
|
});
|
|
2199
2267
|
// Show loading indicator for query operations
|
|
2200
|
-
useActivity(
|
|
2268
|
+
useActivity(rowsQueryMutation.isPending, "Executing GraphQL query");
|
|
2201
2269
|
// Return the public API for the hook
|
|
2202
2270
|
return {
|
|
2203
2271
|
// Query execution
|
|
2204
|
-
executeQuery:
|
|
2205
|
-
executeQueryAsync:
|
|
2272
|
+
executeQuery: rowsQueryMutation.mutate,
|
|
2273
|
+
executeQueryAsync: rowsQueryMutation.mutateAsync,
|
|
2206
2274
|
// Query state
|
|
2207
|
-
isExecuting:
|
|
2208
|
-
error:
|
|
2209
|
-
data:
|
|
2275
|
+
isExecuting: rowsQueryMutation.isPending,
|
|
2276
|
+
error: rowsQueryMutation.error,
|
|
2277
|
+
data: rowsQueryMutation.data,
|
|
2210
2278
|
// Reset function to clear previous results
|
|
2211
|
-
reset:
|
|
2279
|
+
reset: rowsQueryMutation.reset,
|
|
2212
2280
|
// Socket readiness
|
|
2213
2281
|
isReady: isSocketReady,
|
|
2214
2282
|
};
|
|
@@ -4617,12 +4685,13 @@ exports.useMcpTools = useMcpTools;
|
|
|
4617
4685
|
exports.useNlpQuery = useNlpQuery;
|
|
4618
4686
|
exports.useNodeDetails = useNodeDetails;
|
|
4619
4687
|
exports.useNotification = useNotification;
|
|
4620
|
-
exports.useObjectsQuery = useObjectsQuery;
|
|
4621
4688
|
exports.useOntologies = useOntologies;
|
|
4622
4689
|
exports.useParameterValidation = useParameterValidation;
|
|
4623
4690
|
exports.useProcessing = useProcessing;
|
|
4624
4691
|
exports.useProgressStateStore = useProgressStateStore;
|
|
4625
4692
|
exports.usePrompts = usePrompts;
|
|
4693
|
+
exports.useRowEmbeddingsQuery = useRowEmbeddingsQuery;
|
|
4694
|
+
exports.useRowsQuery = useRowsQuery;
|
|
4626
4695
|
exports.useSchemas = useSchemas;
|
|
4627
4696
|
exports.useSearchStateStore = useSearchStateStore;
|
|
4628
4697
|
exports.useSessionStore = useSessionStore;
|