@trustgraph/react-state 1.4.0 → 1.4.2
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 +70 -6
- 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 +70 -7
- package/dist/index.esm.js.map +1 -1
- package/dist/state/conversation.d.ts.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/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -150,12 +150,7 @@ const useSessionStore = zustand.create()((set) => ({
|
|
|
150
150
|
}));
|
|
151
151
|
|
|
152
152
|
const useConversation = zustand.create()((set) => ({
|
|
153
|
-
messages: [
|
|
154
|
-
{
|
|
155
|
-
role: "ai",
|
|
156
|
-
text: "Welcome to the TrustGraph Test Suite. Use the chat interface to perform Graph RAG requests.",
|
|
157
|
-
},
|
|
158
|
-
],
|
|
153
|
+
messages: [],
|
|
159
154
|
input: "",
|
|
160
155
|
chatMode: "graph-rag",
|
|
161
156
|
setMessages: (v) => set(() => ({
|
|
@@ -2159,6 +2154,74 @@ const useStructuredQuery = () => {
|
|
|
2159
2154
|
};
|
|
2160
2155
|
};
|
|
2161
2156
|
|
|
2157
|
+
// @ts-nocheck
|
|
2158
|
+
// React Query hooks for data fetching and mutation management
|
|
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
|
|
2163
|
+
*/
|
|
2164
|
+
const useRowEmbeddingsQuery = () => {
|
|
2165
|
+
// Socket connection for API calls
|
|
2166
|
+
const socket = reactProvider.useSocket();
|
|
2167
|
+
const connectionState = reactProvider.useConnectionState();
|
|
2168
|
+
// Notification system for user feedback
|
|
2169
|
+
const notify = useNotification();
|
|
2170
|
+
// Session state for current flow ID
|
|
2171
|
+
const flowId = useSessionStore((state) => state.flowId);
|
|
2172
|
+
// Settings for default collection
|
|
2173
|
+
const { settings } = useSettings();
|
|
2174
|
+
// Only enable operations when socket is connected and ready
|
|
2175
|
+
const isSocketReady = connectionState?.status === "authenticated" ||
|
|
2176
|
+
connectionState?.status === "unauthenticated";
|
|
2177
|
+
// Mutation for executing row embeddings queries
|
|
2178
|
+
const rowEmbeddingsQueryMutation = reactQuery.useMutation({
|
|
2179
|
+
mutationFn: async ({ query, schemaName, collection, indexName, limit, }) => {
|
|
2180
|
+
if (!isSocketReady) {
|
|
2181
|
+
throw new Error("Socket connection not ready");
|
|
2182
|
+
}
|
|
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);
|
|
2188
|
+
},
|
|
2189
|
+
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}`);
|
|
2195
|
+
},
|
|
2196
|
+
onSuccess: (data) => {
|
|
2197
|
+
if (data && data.length > 0) {
|
|
2198
|
+
notify.success(`Found ${data.length} matching record${data.length !== 1 ? 's' : ''}`);
|
|
2199
|
+
}
|
|
2200
|
+
else {
|
|
2201
|
+
notify.info("No matching records found");
|
|
2202
|
+
}
|
|
2203
|
+
},
|
|
2204
|
+
});
|
|
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
|
|
2208
|
+
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
|
|
2221
|
+
isReady: isSocketReady,
|
|
2222
|
+
};
|
|
2223
|
+
};
|
|
2224
|
+
|
|
2162
2225
|
// React Query hooks for data fetching and mutation management
|
|
2163
2226
|
/**
|
|
2164
2227
|
* Custom hook for managing GraphQL rows queries
|
|
@@ -4622,6 +4685,7 @@ exports.useParameterValidation = useParameterValidation;
|
|
|
4622
4685
|
exports.useProcessing = useProcessing;
|
|
4623
4686
|
exports.useProgressStateStore = useProgressStateStore;
|
|
4624
4687
|
exports.usePrompts = usePrompts;
|
|
4688
|
+
exports.useRowEmbeddingsQuery = useRowEmbeddingsQuery;
|
|
4625
4689
|
exports.useRowsQuery = useRowsQuery;
|
|
4626
4690
|
exports.useSchemas = useSchemas;
|
|
4627
4691
|
exports.useSearchStateStore = useSearchStateStore;
|