@trustgraph/react-state 1.5.4 → 1.6.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.
- package/dist/index.cjs +45 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +45 -2
- package/dist/index.esm.js.map +1 -1
- package/dist/state/inference.d.ts +16 -0
- package/dist/state/inference.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1808,10 +1808,45 @@ const useInference = ({ flow } = {}) => {
|
|
|
1808
1808
|
},
|
|
1809
1809
|
});
|
|
1810
1810
|
/**
|
|
1811
|
-
*
|
|
1811
|
+
* Document RAG inference with optional explainability
|
|
1812
|
+
*/
|
|
1813
|
+
const documentRagMutation = reactQuery.useMutation({
|
|
1814
|
+
mutationFn: async ({ input, collection, docLimit, callbacks, }) => {
|
|
1815
|
+
const wantsExplainability = !!callbacks?.onExplain;
|
|
1816
|
+
const explainEvents = wantsExplainability ? [] : undefined;
|
|
1817
|
+
const response = await new Promise((resolve, reject) => {
|
|
1818
|
+
let accumulated = "";
|
|
1819
|
+
const onChunk = (chunk, complete) => {
|
|
1820
|
+
accumulated += chunk;
|
|
1821
|
+
callbacks?.onChunk?.(chunk, complete);
|
|
1822
|
+
if (complete) {
|
|
1823
|
+
resolve(accumulated);
|
|
1824
|
+
}
|
|
1825
|
+
};
|
|
1826
|
+
const onError = (error) => {
|
|
1827
|
+
callbacks?.onError?.(error);
|
|
1828
|
+
reject(new Error(error));
|
|
1829
|
+
};
|
|
1830
|
+
const onExplain = wantsExplainability
|
|
1831
|
+
? (event) => {
|
|
1832
|
+
explainEvents.push(event);
|
|
1833
|
+
callbacks.onExplain(event);
|
|
1834
|
+
}
|
|
1835
|
+
: undefined;
|
|
1836
|
+
socket
|
|
1837
|
+
.flow(effectiveFlow)
|
|
1838
|
+
.documentRagStreaming(input, onChunk, onError, docLimit, collection, onExplain);
|
|
1839
|
+
});
|
|
1840
|
+
return { response, explainEvents };
|
|
1841
|
+
},
|
|
1842
|
+
});
|
|
1843
|
+
/**
|
|
1844
|
+
* Agent inference with streaming callbacks and optional explainability
|
|
1812
1845
|
*/
|
|
1813
1846
|
const agentMutation = reactQuery.useMutation({
|
|
1814
1847
|
mutationFn: async ({ input, callbacks, }) => {
|
|
1848
|
+
const wantsExplainability = !!callbacks?.onExplain;
|
|
1849
|
+
const explainEvents = wantsExplainability ? [] : undefined;
|
|
1815
1850
|
return new Promise((resolve, reject) => {
|
|
1816
1851
|
let fullAnswer = "";
|
|
1817
1852
|
const onThink = (thought, complete) => {
|
|
@@ -1831,17 +1866,25 @@ const useInference = ({ flow } = {}) => {
|
|
|
1831
1866
|
callbacks?.onError?.(error);
|
|
1832
1867
|
reject(new Error(error));
|
|
1833
1868
|
};
|
|
1869
|
+
const onExplain = wantsExplainability
|
|
1870
|
+
? (event) => {
|
|
1871
|
+
explainEvents.push(event);
|
|
1872
|
+
callbacks.onExplain(event);
|
|
1873
|
+
}
|
|
1874
|
+
: undefined;
|
|
1834
1875
|
socket
|
|
1835
1876
|
.flow(effectiveFlow)
|
|
1836
|
-
.agent(input, onThink, onObserve, onAnswer, onError);
|
|
1877
|
+
.agent(input, onThink, onObserve, onAnswer, onError, onExplain);
|
|
1837
1878
|
});
|
|
1838
1879
|
},
|
|
1839
1880
|
});
|
|
1840
1881
|
return {
|
|
1841
1882
|
graphRag: graphRagMutation.mutateAsync,
|
|
1883
|
+
documentRag: documentRagMutation.mutateAsync,
|
|
1842
1884
|
textCompletion: textCompletionMutation.mutateAsync,
|
|
1843
1885
|
agent: agentMutation.mutateAsync,
|
|
1844
1886
|
isLoading: graphRagMutation.isPending ||
|
|
1887
|
+
documentRagMutation.isPending ||
|
|
1845
1888
|
textCompletionMutation.isPending ||
|
|
1846
1889
|
agentMutation.isPending,
|
|
1847
1890
|
};
|