@trustgraph/react-state 0.3.1 → 1.2.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 +282 -427
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +281 -426
- package/dist/index.esm.js.map +1 -1
- package/dist/model/settings-types.d.ts +2 -2
- package/dist/model/settings-types.d.ts.map +1 -1
- package/dist/state/chat-session.d.ts.map +1 -1
- package/dist/state/conversation.d.ts +1 -0
- package/dist/state/conversation.d.ts.map +1 -1
- package/dist/state/entity-query.d.ts +4 -11
- package/dist/state/entity-query.d.ts.map +1 -1
- package/dist/state/flow-blueprints.d.ts +63 -0
- package/dist/state/flow-blueprints.d.ts.map +1 -0
- package/dist/state/flow-parameters.d.ts +3 -3
- package/dist/state/flow-parameters.d.ts.map +1 -1
- package/dist/state/flows.d.ts +5 -5
- package/dist/state/flows.d.ts.map +1 -1
- package/dist/state/graph-embeddings.d.ts +7 -7
- package/dist/state/graph-embeddings.d.ts.map +1 -1
- package/dist/state/inference.d.ts +13 -3
- package/dist/state/inference.d.ts.map +1 -1
- package/dist/state/library.d.ts +11 -11
- package/dist/state/library.d.ts.map +1 -1
- package/dist/state/nlp-query.d.ts +9 -9
- package/dist/state/nlp-query.d.ts.map +1 -1
- package/dist/state/processing.d.ts +3 -3
- package/dist/state/processing.d.ts.map +1 -1
- package/dist/state/token-costs.d.ts +3 -11
- package/dist/state/token-costs.d.ts.map +1 -1
- package/dist/state/triples.d.ts +9 -9
- package/dist/state/triples.d.ts.map +1 -1
- package/dist/utils/row.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/index.esm.js
CHANGED
|
@@ -5,6 +5,7 @@ import { createContext, useContext, useEffect, useState, useMemo } from 'react';
|
|
|
5
5
|
import { create } from 'zustand';
|
|
6
6
|
import { useQueryClient, useQuery, useMutation } from '@tanstack/react-query';
|
|
7
7
|
import { v4 } from 'uuid';
|
|
8
|
+
import similarity from 'compute-cosine-similarity';
|
|
8
9
|
|
|
9
10
|
// Create context for notification handler
|
|
10
11
|
const NotificationContext = createContext(null);
|
|
@@ -169,6 +170,16 @@ const useConversation = create()((set) => ({
|
|
|
169
170
|
},
|
|
170
171
|
],
|
|
171
172
|
})),
|
|
173
|
+
updateLastMessage: (text) => set((state) => {
|
|
174
|
+
if (state.messages.length === 0)
|
|
175
|
+
return state;
|
|
176
|
+
const messages = [...state.messages];
|
|
177
|
+
messages[messages.length - 1] = {
|
|
178
|
+
...messages[messages.length - 1],
|
|
179
|
+
text: text,
|
|
180
|
+
};
|
|
181
|
+
return { messages };
|
|
182
|
+
}),
|
|
172
183
|
setInput: (v) => set(() => ({
|
|
173
184
|
input: v,
|
|
174
185
|
})),
|
|
@@ -301,8 +312,8 @@ const DEFAULT_SETTINGS = {
|
|
|
301
312
|
mcpTools: false, // Off by default
|
|
302
313
|
schemas: false, // Off by default
|
|
303
314
|
tokenCost: false, // Off by default
|
|
304
|
-
|
|
305
|
-
|
|
315
|
+
flowBlueprints: false, // Off by default
|
|
316
|
+
flowBlueprintEditor: false, // Off by default - experimental feature
|
|
306
317
|
structuredQuery: false, // Off by default
|
|
307
318
|
llmModels: false, // Off by default
|
|
308
319
|
},
|
|
@@ -535,19 +546,19 @@ const useFlows = () => {
|
|
|
535
546
|
},
|
|
536
547
|
});
|
|
537
548
|
/**
|
|
538
|
-
* Query for fetching all flow
|
|
549
|
+
* Query for fetching all flow blueprints
|
|
539
550
|
* Uses React Query for caching and background refetching
|
|
540
551
|
*/
|
|
541
|
-
const
|
|
542
|
-
queryKey: ["flow-
|
|
552
|
+
const flowBlueprintsQuery = useQuery({
|
|
553
|
+
queryKey: ["flow-blueprints"],
|
|
543
554
|
enabled: isSocketReady,
|
|
544
555
|
queryFn: () => {
|
|
545
556
|
return socket
|
|
546
557
|
.flows()
|
|
547
|
-
.
|
|
558
|
+
.getFlowBlueprints()
|
|
548
559
|
.then((cls) => Promise.all(cls.map((id) => socket
|
|
549
560
|
.flows()
|
|
550
|
-
.
|
|
561
|
+
.getFlowBlueprint(id)
|
|
551
562
|
.then((cls) => [id, cls]))));
|
|
552
563
|
},
|
|
553
564
|
});
|
|
@@ -555,10 +566,10 @@ const useFlows = () => {
|
|
|
555
566
|
* Mutation for starting a new flow for processing workflows
|
|
556
567
|
*/
|
|
557
568
|
const startFlowMutation = useMutation({
|
|
558
|
-
mutationFn: ({ id,
|
|
569
|
+
mutationFn: ({ id, blueprintName, description, parameters, onSuccess, }) => {
|
|
559
570
|
return socket
|
|
560
571
|
.flows()
|
|
561
|
-
.startFlow(id,
|
|
572
|
+
.startFlow(id, blueprintName, description, parameters)
|
|
562
573
|
.then(() => {
|
|
563
574
|
// Execute success callback if provided
|
|
564
575
|
if (onSuccess)
|
|
@@ -603,7 +614,7 @@ const useFlows = () => {
|
|
|
603
614
|
});
|
|
604
615
|
// Show loading indicators for long-running operations
|
|
605
616
|
useActivity(flowsQuery.isLoading, "Loading flows");
|
|
606
|
-
useActivity(
|
|
617
|
+
useActivity(flowBlueprintsQuery.isLoading, "Loading flow blueprints");
|
|
607
618
|
useActivity(startFlowMutation.isPending, "Starting flow");
|
|
608
619
|
useActivity(stopFlowMutation.isPending, "Stopping flows");
|
|
609
620
|
// Return flows state and operations for use in components
|
|
@@ -613,11 +624,11 @@ const useFlows = () => {
|
|
|
613
624
|
isLoading: flowsQuery.isLoading,
|
|
614
625
|
isError: flowsQuery.isError,
|
|
615
626
|
error: flowsQuery.error,
|
|
616
|
-
// Flow data and query state
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
627
|
+
// Flow blueprint data and query state
|
|
628
|
+
flowBlueprints: flowBlueprintsQuery.data,
|
|
629
|
+
isFlowBlueprintsLoading: flowBlueprintsQuery.isLoading,
|
|
630
|
+
isFlowBlueprintsError: flowBlueprintsQuery.isError,
|
|
631
|
+
flowBlueprintsError: flowBlueprintsQuery.error,
|
|
621
632
|
// Flow start operations
|
|
622
633
|
startFlow: startFlowMutation.mutate,
|
|
623
634
|
isStarting: startFlowMutation.isPending,
|
|
@@ -1408,273 +1419,6 @@ const useGraphEmbeddings = ({ flow, vecs, limit, collection }) => {
|
|
|
1408
1419
|
};
|
|
1409
1420
|
};
|
|
1410
1421
|
|
|
1411
|
-
function getDefaultExportFromCjs (x) {
|
|
1412
|
-
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
1413
|
-
}
|
|
1414
|
-
|
|
1415
|
-
/**
|
|
1416
|
-
* FUNCTION: isArray( value )
|
|
1417
|
-
* Validates if a value is an array.
|
|
1418
|
-
*
|
|
1419
|
-
* @param {*} value - value to be validated
|
|
1420
|
-
* @returns {Boolean} boolean indicating whether value is an array
|
|
1421
|
-
*/
|
|
1422
|
-
function isArray$3( value ) {
|
|
1423
|
-
return Object.prototype.toString.call( value ) === '[object Array]';
|
|
1424
|
-
} // end FUNCTION isArray()
|
|
1425
|
-
|
|
1426
|
-
// EXPORTS //
|
|
1427
|
-
|
|
1428
|
-
var lib$4 = Array.isArray || isArray$3;
|
|
1429
|
-
|
|
1430
|
-
/**
|
|
1431
|
-
*
|
|
1432
|
-
* VALIDATE: function
|
|
1433
|
-
*
|
|
1434
|
-
*
|
|
1435
|
-
* DESCRIPTION:
|
|
1436
|
-
* - Validates if a value is a function.
|
|
1437
|
-
*
|
|
1438
|
-
*
|
|
1439
|
-
* NOTES:
|
|
1440
|
-
* [1]
|
|
1441
|
-
*
|
|
1442
|
-
*
|
|
1443
|
-
* TODO:
|
|
1444
|
-
* [1]
|
|
1445
|
-
*
|
|
1446
|
-
*
|
|
1447
|
-
* LICENSE:
|
|
1448
|
-
* MIT
|
|
1449
|
-
*
|
|
1450
|
-
* Copyright (c) 2014. Athan Reines.
|
|
1451
|
-
*
|
|
1452
|
-
*
|
|
1453
|
-
* AUTHOR:
|
|
1454
|
-
* Athan Reines. kgryte@gmail.com. 2014.
|
|
1455
|
-
*
|
|
1456
|
-
*/
|
|
1457
|
-
|
|
1458
|
-
/**
|
|
1459
|
-
* FUNCTION: isFunction( value )
|
|
1460
|
-
* Validates if a value is a function.
|
|
1461
|
-
*
|
|
1462
|
-
* @param {*} value - value to be validated
|
|
1463
|
-
* @returns {Boolean} boolean indicating whether value is a function
|
|
1464
|
-
*/
|
|
1465
|
-
function isFunction$3( value ) {
|
|
1466
|
-
return ( typeof value === 'function' );
|
|
1467
|
-
} // end FUNCTION isFunction()
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
// EXPORTS //
|
|
1471
|
-
|
|
1472
|
-
var lib$3 = isFunction$3;
|
|
1473
|
-
|
|
1474
|
-
// MODULES //
|
|
1475
|
-
|
|
1476
|
-
var isArray$2 = lib$4,
|
|
1477
|
-
isFunction$2 = lib$3;
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
// DOT PRODUCT //
|
|
1481
|
-
|
|
1482
|
-
/**
|
|
1483
|
-
* FUNCTION: dot( x, y[, accessor] )
|
|
1484
|
-
* Computes the dot product between two arrays.
|
|
1485
|
-
*
|
|
1486
|
-
* @param {Array} x - input array
|
|
1487
|
-
* @param {Array} y - input array
|
|
1488
|
-
* @param {Function} [accessor] - accessor function for accessing array values
|
|
1489
|
-
* @returns {Number|Null} dot product
|
|
1490
|
-
*/
|
|
1491
|
-
function dot$1( x, y, clbk ) {
|
|
1492
|
-
if ( !isArray$2( x ) ) {
|
|
1493
|
-
throw new TypeError( 'dot()::invalid input argument. First argument must be an array. Value: `' + x + '`.' );
|
|
1494
|
-
}
|
|
1495
|
-
if ( !isArray$2( y ) ) {
|
|
1496
|
-
throw new TypeError( 'dot()::invalid input argument. Second argument must be an array. Value: `' + y + '`.' );
|
|
1497
|
-
}
|
|
1498
|
-
if ( arguments.length > 2 ) {
|
|
1499
|
-
if ( !isFunction$2( clbk ) ) {
|
|
1500
|
-
throw new TypeError( 'dot()::invalid input argument. Accessor must be a function. Value: `' + clbk + '`.' );
|
|
1501
|
-
}
|
|
1502
|
-
}
|
|
1503
|
-
var len = x.length,
|
|
1504
|
-
sum = 0,
|
|
1505
|
-
i;
|
|
1506
|
-
|
|
1507
|
-
if ( len !== y.length ) {
|
|
1508
|
-
throw new Error( 'dot()::invalid input argument. Arrays must be of equal length.' );
|
|
1509
|
-
}
|
|
1510
|
-
if ( !len ) {
|
|
1511
|
-
return null;
|
|
1512
|
-
}
|
|
1513
|
-
if ( clbk ) {
|
|
1514
|
-
for ( i = 0; i < len; i++ ) {
|
|
1515
|
-
sum += clbk( x[ i ], i, 0 ) * clbk( y[ i ], i, 1 );
|
|
1516
|
-
}
|
|
1517
|
-
} else {
|
|
1518
|
-
for ( i = 0; i < len; i++ ) {
|
|
1519
|
-
sum += x[ i ] * y[ i ];
|
|
1520
|
-
}
|
|
1521
|
-
}
|
|
1522
|
-
return sum;
|
|
1523
|
-
} // end FUNCTION dot()
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
// EXPORTS //
|
|
1527
|
-
|
|
1528
|
-
var lib$2 = dot$1;
|
|
1529
|
-
|
|
1530
|
-
// MODULES //
|
|
1531
|
-
|
|
1532
|
-
var isArray$1 = lib$4,
|
|
1533
|
-
isFunction$1 = lib$3;
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
// L2NORM //
|
|
1537
|
-
|
|
1538
|
-
/**
|
|
1539
|
-
* FUNCTION: l2norm( arr[, accessor] )
|
|
1540
|
-
* Calculates the L2 norm (Euclidean norm) of an array.
|
|
1541
|
-
*
|
|
1542
|
-
* @param {Array} arr - input array
|
|
1543
|
-
* @param {Function} [accessor] - accessor function for accessing array values
|
|
1544
|
-
* @returns {Number|Null} L2 norm or null
|
|
1545
|
-
*/
|
|
1546
|
-
function l2norm$1( arr, clbk ) {
|
|
1547
|
-
if ( !isArray$1( arr ) ) {
|
|
1548
|
-
throw new TypeError( 'l2norm()::invalid input argument. Must provide an array. Value: `' + arr + '`.' );
|
|
1549
|
-
}
|
|
1550
|
-
if ( arguments.length > 1 ) {
|
|
1551
|
-
if ( !isFunction$1( clbk ) ) {
|
|
1552
|
-
throw new TypeError( 'l2norm()::invalid input argument. Accessor must be a function. Value: `' + clbk + '`.' );
|
|
1553
|
-
}
|
|
1554
|
-
}
|
|
1555
|
-
var len = arr.length,
|
|
1556
|
-
t = 0,
|
|
1557
|
-
s = 1,
|
|
1558
|
-
r,
|
|
1559
|
-
val,
|
|
1560
|
-
abs,
|
|
1561
|
-
i;
|
|
1562
|
-
|
|
1563
|
-
if ( !len ) {
|
|
1564
|
-
return null;
|
|
1565
|
-
}
|
|
1566
|
-
if ( clbk ) {
|
|
1567
|
-
for ( i = 0; i < len; i++ ) {
|
|
1568
|
-
val = clbk( arr[ i ], i );
|
|
1569
|
-
abs = ( val < 0 ) ? -val : val;
|
|
1570
|
-
if ( abs > 0 ) {
|
|
1571
|
-
if ( abs > t ) {
|
|
1572
|
-
r = t / val;
|
|
1573
|
-
s = 1 + s*r*r;
|
|
1574
|
-
t = abs;
|
|
1575
|
-
} else {
|
|
1576
|
-
r = val / t;
|
|
1577
|
-
s = s + r*r;
|
|
1578
|
-
}
|
|
1579
|
-
}
|
|
1580
|
-
}
|
|
1581
|
-
} else {
|
|
1582
|
-
for ( i = 0; i < len; i++ ) {
|
|
1583
|
-
val = arr[ i ];
|
|
1584
|
-
abs = ( val < 0 ) ? -val : val;
|
|
1585
|
-
if ( abs > 0 ) {
|
|
1586
|
-
if ( abs > t ) {
|
|
1587
|
-
r = t / val;
|
|
1588
|
-
s = 1 + s*r*r;
|
|
1589
|
-
t = abs;
|
|
1590
|
-
} else {
|
|
1591
|
-
r = val / t;
|
|
1592
|
-
s = s + r*r;
|
|
1593
|
-
}
|
|
1594
|
-
}
|
|
1595
|
-
}
|
|
1596
|
-
}
|
|
1597
|
-
return t * Math.sqrt( s );
|
|
1598
|
-
} // end FUNCTION l2norm()
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
// EXPORTS //
|
|
1602
|
-
|
|
1603
|
-
var lib$1 = l2norm$1;
|
|
1604
|
-
|
|
1605
|
-
// MODULES //
|
|
1606
|
-
|
|
1607
|
-
var dot = lib$2,
|
|
1608
|
-
l2norm = lib$1,
|
|
1609
|
-
isArray = lib$4,
|
|
1610
|
-
isFunction = lib$3;
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
// FUNCTIONS //
|
|
1614
|
-
|
|
1615
|
-
/**
|
|
1616
|
-
* Partially applied function from the right.
|
|
1617
|
-
*
|
|
1618
|
-
* @private
|
|
1619
|
-
* @param {Function} fn - input function
|
|
1620
|
-
* @param {number} j - array index
|
|
1621
|
-
* @returns {Function} partially applied function
|
|
1622
|
-
*/
|
|
1623
|
-
function partial( fn, j ) {
|
|
1624
|
-
return function accessor( d, i ) {
|
|
1625
|
-
return fn( d, i, j );
|
|
1626
|
-
};
|
|
1627
|
-
}
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
// MAIN //
|
|
1631
|
-
|
|
1632
|
-
/**
|
|
1633
|
-
* Computes the cosine similarity between two arrays.
|
|
1634
|
-
*
|
|
1635
|
-
* @param {number[]|Array} x - input array
|
|
1636
|
-
* @param {number[]|Array} y - input array
|
|
1637
|
-
* @param {Function} [accessor] - accessor function for accessing array values
|
|
1638
|
-
* @returns {number|null} cosine similarity or null
|
|
1639
|
-
*/
|
|
1640
|
-
function similarity( x, y, clbk ) {
|
|
1641
|
-
var a, b, c;
|
|
1642
|
-
if ( !isArray( x ) ) {
|
|
1643
|
-
throw new TypeError( 'cosine-similarity()::invalid input argument. First argument must be an array. Value: `' + x + '`.' );
|
|
1644
|
-
}
|
|
1645
|
-
if ( !isArray( y ) ) {
|
|
1646
|
-
throw new TypeError( 'cosine-similarity()::invalid input argument. Second argument must be an array. Value: `' + y + '`.' );
|
|
1647
|
-
}
|
|
1648
|
-
if ( arguments.length > 2 ) {
|
|
1649
|
-
if ( !isFunction( clbk ) ) {
|
|
1650
|
-
throw new TypeError( 'cosine-similarity()::invalid input argument. Accessor must be a function. Value: `' + clbk + '`.' );
|
|
1651
|
-
}
|
|
1652
|
-
}
|
|
1653
|
-
if ( x.length !== y.length ) {
|
|
1654
|
-
throw new Error( 'cosine-similarity()::invalid input argument. Input arrays must have the same length.' );
|
|
1655
|
-
}
|
|
1656
|
-
if ( !x.length ) {
|
|
1657
|
-
return null;
|
|
1658
|
-
}
|
|
1659
|
-
if ( clbk ) {
|
|
1660
|
-
a = dot( x, y, clbk );
|
|
1661
|
-
b = l2norm( x, partial( clbk, 0 ) );
|
|
1662
|
-
c = l2norm( y, partial( clbk, 1 ) );
|
|
1663
|
-
} else {
|
|
1664
|
-
a = dot( x, y );
|
|
1665
|
-
b = l2norm( x );
|
|
1666
|
-
c = l2norm( y );
|
|
1667
|
-
}
|
|
1668
|
-
return a / ( b*c );
|
|
1669
|
-
}
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
// EXPORTS //
|
|
1673
|
-
|
|
1674
|
-
var lib = similarity;
|
|
1675
|
-
|
|
1676
|
-
var similarity$1 = /*@__PURE__*/getDefaultExportFromCjs(lib);
|
|
1677
|
-
|
|
1678
1422
|
// Take the embeddings, and lookup entities using graph
|
|
1679
1423
|
// embeddings, add embedding to each entity row, just an easy
|
|
1680
1424
|
// place to put it
|
|
@@ -1794,7 +1538,7 @@ const addRowEmbeddings = (socket, add, remove) => (entities) => {
|
|
|
1794
1538
|
};
|
|
1795
1539
|
// Rest of the procecess is not async, so not adding progress
|
|
1796
1540
|
const computeCosineSimilarity = () => (entities) => entities.map((ent) => {
|
|
1797
|
-
const sim = similarity
|
|
1541
|
+
const sim = similarity(ent.target, ent.embeddings);
|
|
1798
1542
|
return {
|
|
1799
1543
|
uri: ent.uri,
|
|
1800
1544
|
label: ent.label,
|
|
@@ -1964,11 +1708,27 @@ const useInference = () => {
|
|
|
1964
1708
|
* Graph RAG inference with entity discovery
|
|
1965
1709
|
*/
|
|
1966
1710
|
const graphRagMutation = useMutation({
|
|
1967
|
-
mutationFn: async ({ input, options, collection, }) => {
|
|
1968
|
-
//
|
|
1969
|
-
const response =
|
|
1970
|
-
|
|
1971
|
-
|
|
1711
|
+
mutationFn: async ({ input, options, collection, callbacks, }) => {
|
|
1712
|
+
// If callbacks provided, use streaming API
|
|
1713
|
+
const response = callbacks
|
|
1714
|
+
? await new Promise((resolve, reject) => {
|
|
1715
|
+
let accumulated = "";
|
|
1716
|
+
const onChunk = (chunk, complete) => {
|
|
1717
|
+
accumulated += chunk;
|
|
1718
|
+
callbacks?.onChunk?.(chunk, complete);
|
|
1719
|
+
if (complete) {
|
|
1720
|
+
resolve(accumulated);
|
|
1721
|
+
}
|
|
1722
|
+
};
|
|
1723
|
+
const onError = (error) => {
|
|
1724
|
+
callbacks?.onError?.(error);
|
|
1725
|
+
reject(new Error(error));
|
|
1726
|
+
};
|
|
1727
|
+
socket
|
|
1728
|
+
.flow(flowId)
|
|
1729
|
+
.graphRagStreaming(input, onChunk, onError, options, collection);
|
|
1730
|
+
})
|
|
1731
|
+
: await socket.flow(flowId).graphRag(input, options || {}, collection);
|
|
1972
1732
|
// Get embeddings for entity discovery
|
|
1973
1733
|
const embeddings = await socket.flow(flowId).embeddings(input);
|
|
1974
1734
|
// Query graph embeddings to find entities
|
|
@@ -1982,8 +1742,27 @@ const useInference = () => {
|
|
|
1982
1742
|
* Basic LLM text completion
|
|
1983
1743
|
*/
|
|
1984
1744
|
const textCompletionMutation = useMutation({
|
|
1985
|
-
mutationFn: async ({ systemPrompt, input, }) => {
|
|
1986
|
-
|
|
1745
|
+
mutationFn: async ({ systemPrompt, input, callbacks, }) => {
|
|
1746
|
+
// If callbacks provided, use streaming API
|
|
1747
|
+
return callbacks
|
|
1748
|
+
? await new Promise((resolve, reject) => {
|
|
1749
|
+
let accumulated = "";
|
|
1750
|
+
const onChunk = (chunk, complete) => {
|
|
1751
|
+
accumulated += chunk;
|
|
1752
|
+
callbacks?.onChunk?.(chunk, complete);
|
|
1753
|
+
if (complete) {
|
|
1754
|
+
resolve(accumulated);
|
|
1755
|
+
}
|
|
1756
|
+
};
|
|
1757
|
+
const onError = (error) => {
|
|
1758
|
+
callbacks?.onError?.(error);
|
|
1759
|
+
reject(new Error(error));
|
|
1760
|
+
};
|
|
1761
|
+
socket
|
|
1762
|
+
.flow(flowId)
|
|
1763
|
+
.textCompletionStreaming(systemPrompt, input, onChunk, onError);
|
|
1764
|
+
})
|
|
1765
|
+
: await socket.flow(flowId).textCompletion(systemPrompt, input);
|
|
1987
1766
|
},
|
|
1988
1767
|
});
|
|
1989
1768
|
/**
|
|
@@ -1992,15 +1771,19 @@ const useInference = () => {
|
|
|
1992
1771
|
const agentMutation = useMutation({
|
|
1993
1772
|
mutationFn: async ({ input, callbacks, }) => {
|
|
1994
1773
|
return new Promise((resolve, reject) => {
|
|
1995
|
-
|
|
1996
|
-
|
|
1774
|
+
let fullAnswer = "";
|
|
1775
|
+
const onThink = (thought, complete) => {
|
|
1776
|
+
callbacks?.onThink?.(thought, complete);
|
|
1997
1777
|
};
|
|
1998
|
-
const onObserve = (observation) => {
|
|
1999
|
-
callbacks?.onObserve?.(observation);
|
|
1778
|
+
const onObserve = (observation, complete) => {
|
|
1779
|
+
callbacks?.onObserve?.(observation, complete);
|
|
2000
1780
|
};
|
|
2001
|
-
const onAnswer = (answer) => {
|
|
2002
|
-
|
|
2003
|
-
|
|
1781
|
+
const onAnswer = (answer, complete) => {
|
|
1782
|
+
fullAnswer += answer;
|
|
1783
|
+
callbacks?.onAnswer?.(answer, complete);
|
|
1784
|
+
if (complete) {
|
|
1785
|
+
resolve(fullAnswer);
|
|
1786
|
+
}
|
|
2004
1787
|
};
|
|
2005
1788
|
const onError = (error) => {
|
|
2006
1789
|
callbacks?.onError?.(error);
|
|
@@ -2032,6 +1815,7 @@ const useChatSession = () => {
|
|
|
2032
1815
|
const notify = useNotification();
|
|
2033
1816
|
// Conversation state
|
|
2034
1817
|
const addMessage = useConversation((state) => state.addMessage);
|
|
1818
|
+
const updateLastMessage = useConversation((state) => state.updateLastMessage);
|
|
2035
1819
|
const setInput = useConversation((state) => state.setInput);
|
|
2036
1820
|
const chatMode = useConversation((state) => state.chatMode);
|
|
2037
1821
|
// Progress and activity management
|
|
@@ -2051,8 +1835,10 @@ const useChatSession = () => {
|
|
|
2051
1835
|
const ragActivity = "Graph RAG: " + input;
|
|
2052
1836
|
const embActivity = "Find entities: " + input;
|
|
2053
1837
|
addActivity(ragActivity);
|
|
1838
|
+
let accumulated = "";
|
|
1839
|
+
let messageAdded = false;
|
|
2054
1840
|
try {
|
|
2055
|
-
// Execute Graph RAG with entity discovery
|
|
1841
|
+
// Execute Graph RAG with streaming and entity discovery
|
|
2056
1842
|
const result = await inference.graphRag({
|
|
2057
1843
|
input,
|
|
2058
1844
|
options: {
|
|
@@ -2062,8 +1848,21 @@ const useChatSession = () => {
|
|
|
2062
1848
|
pathLength: settings.graphrag.pathLength,
|
|
2063
1849
|
},
|
|
2064
1850
|
collection: settings.collection,
|
|
1851
|
+
callbacks: {
|
|
1852
|
+
onChunk: (chunk, complete) => {
|
|
1853
|
+
accumulated += chunk;
|
|
1854
|
+
if (!messageAdded) {
|
|
1855
|
+
// Add empty message on first chunk
|
|
1856
|
+
addMessage("ai", accumulated);
|
|
1857
|
+
messageAdded = true;
|
|
1858
|
+
}
|
|
1859
|
+
else {
|
|
1860
|
+
// Update existing message with accumulated text
|
|
1861
|
+
updateLastMessage(accumulated);
|
|
1862
|
+
}
|
|
1863
|
+
},
|
|
1864
|
+
},
|
|
2065
1865
|
});
|
|
2066
|
-
addMessage("ai", result.response);
|
|
2067
1866
|
removeActivity(ragActivity);
|
|
2068
1867
|
// Start embeddings activity
|
|
2069
1868
|
addActivity(embActivity);
|
|
@@ -2107,12 +1906,27 @@ const useChatSession = () => {
|
|
|
2107
1906
|
const handleBasicLlm = async (input) => {
|
|
2108
1907
|
const activity = "Text completion: " + input;
|
|
2109
1908
|
addActivity(activity);
|
|
1909
|
+
let accumulated = "";
|
|
1910
|
+
let messageAdded = false;
|
|
2110
1911
|
try {
|
|
2111
1912
|
const response = await inference.textCompletion({
|
|
2112
1913
|
systemPrompt: "You are a helpful assistant. Provide clear and concise responses.",
|
|
2113
1914
|
input,
|
|
1915
|
+
callbacks: {
|
|
1916
|
+
onChunk: (chunk, complete) => {
|
|
1917
|
+
accumulated += chunk;
|
|
1918
|
+
if (!messageAdded) {
|
|
1919
|
+
// Add empty message on first chunk
|
|
1920
|
+
addMessage("ai", accumulated);
|
|
1921
|
+
messageAdded = true;
|
|
1922
|
+
}
|
|
1923
|
+
else {
|
|
1924
|
+
// Update existing message with accumulated text
|
|
1925
|
+
updateLastMessage(accumulated);
|
|
1926
|
+
}
|
|
1927
|
+
},
|
|
1928
|
+
},
|
|
2114
1929
|
});
|
|
2115
|
-
addMessage("ai", response);
|
|
2116
1930
|
removeActivity(activity);
|
|
2117
1931
|
setEntities([]);
|
|
2118
1932
|
return response;
|
|
@@ -2128,13 +1942,54 @@ const useChatSession = () => {
|
|
|
2128
1942
|
const handleAgent = async (input) => {
|
|
2129
1943
|
const activity = "Agent: " + input;
|
|
2130
1944
|
addActivity(activity);
|
|
1945
|
+
let thinkingAccumulated = "";
|
|
1946
|
+
let thinkingMessageAdded = false;
|
|
1947
|
+
let observationAccumulated = "";
|
|
1948
|
+
let observationMessageAdded = false;
|
|
1949
|
+
let answerAccumulated = "";
|
|
1950
|
+
let answerMessageAdded = false;
|
|
2131
1951
|
try {
|
|
2132
1952
|
const response = await inference.agent({
|
|
2133
1953
|
input,
|
|
2134
1954
|
callbacks: {
|
|
2135
|
-
onThink: (thought) =>
|
|
2136
|
-
|
|
2137
|
-
|
|
1955
|
+
onThink: (thought, complete) => {
|
|
1956
|
+
thinkingAccumulated += thought;
|
|
1957
|
+
if (!thinkingMessageAdded) {
|
|
1958
|
+
addMessage("ai", thinkingAccumulated, "thinking");
|
|
1959
|
+
thinkingMessageAdded = true;
|
|
1960
|
+
}
|
|
1961
|
+
else {
|
|
1962
|
+
updateLastMessage(thinkingAccumulated);
|
|
1963
|
+
}
|
|
1964
|
+
if (complete) {
|
|
1965
|
+
thinkingAccumulated = "";
|
|
1966
|
+
thinkingMessageAdded = false;
|
|
1967
|
+
}
|
|
1968
|
+
},
|
|
1969
|
+
onObserve: (observation, complete) => {
|
|
1970
|
+
observationAccumulated += observation;
|
|
1971
|
+
if (!observationMessageAdded) {
|
|
1972
|
+
addMessage("ai", observationAccumulated, "observation");
|
|
1973
|
+
observationMessageAdded = true;
|
|
1974
|
+
}
|
|
1975
|
+
else {
|
|
1976
|
+
updateLastMessage(observationAccumulated);
|
|
1977
|
+
}
|
|
1978
|
+
if (complete) {
|
|
1979
|
+
observationAccumulated = "";
|
|
1980
|
+
observationMessageAdded = false;
|
|
1981
|
+
}
|
|
1982
|
+
},
|
|
1983
|
+
onAnswer: (answer, complete) => {
|
|
1984
|
+
answerAccumulated += answer;
|
|
1985
|
+
if (!answerMessageAdded) {
|
|
1986
|
+
addMessage("ai", answerAccumulated, "answer");
|
|
1987
|
+
answerMessageAdded = true;
|
|
1988
|
+
}
|
|
1989
|
+
else {
|
|
1990
|
+
updateLastMessage(answerAccumulated);
|
|
1991
|
+
}
|
|
1992
|
+
},
|
|
2138
1993
|
},
|
|
2139
1994
|
});
|
|
2140
1995
|
removeActivity(activity);
|
|
@@ -3569,7 +3424,7 @@ const useTokenCosts = () => {
|
|
|
3569
3424
|
* Uses React Query for caching and background refetching
|
|
3570
3425
|
*/
|
|
3571
3426
|
const query = useQuery({
|
|
3572
|
-
queryKey: ["token-
|
|
3427
|
+
queryKey: ["token-cost"],
|
|
3573
3428
|
enabled: isSocketReady,
|
|
3574
3429
|
queryFn: () => {
|
|
3575
3430
|
return socket
|
|
@@ -3585,17 +3440,17 @@ const useTokenCosts = () => {
|
|
|
3585
3440
|
},
|
|
3586
3441
|
});
|
|
3587
3442
|
/**
|
|
3588
|
-
* Mutation for deleting a specific model's token
|
|
3443
|
+
* Mutation for deleting a specific model's token cost
|
|
3589
3444
|
* Removes the token cost configuration for a given model
|
|
3590
3445
|
*/
|
|
3591
|
-
const
|
|
3446
|
+
const deleteTokenCostMutation = useMutation({
|
|
3592
3447
|
mutationFn: ({ model, onSuccess }) => {
|
|
3593
3448
|
// Delete the token cost configuration for the specified model
|
|
3594
3449
|
return socket
|
|
3595
3450
|
.config()
|
|
3596
3451
|
.deleteConfig([
|
|
3597
3452
|
{
|
|
3598
|
-
type: "token-
|
|
3453
|
+
type: "token-cost",
|
|
3599
3454
|
key: model,
|
|
3600
3455
|
},
|
|
3601
3456
|
])
|
|
@@ -3616,20 +3471,20 @@ const useTokenCosts = () => {
|
|
|
3616
3471
|
},
|
|
3617
3472
|
onSuccess: () => {
|
|
3618
3473
|
// Invalidate cache to trigger refetch
|
|
3619
|
-
queryClient.invalidateQueries({ queryKey: ["token-
|
|
3474
|
+
queryClient.invalidateQueries({ queryKey: ["token-cost"] });
|
|
3620
3475
|
// Show success notification
|
|
3621
3476
|
notify.success("Successful deletion");
|
|
3622
3477
|
},
|
|
3623
3478
|
});
|
|
3624
3479
|
/**
|
|
3625
|
-
* Mutation for updating token
|
|
3480
|
+
* Mutation for updating token cost for a specific model
|
|
3626
3481
|
* Converts per-million token prices to per-token prices and saves
|
|
3627
3482
|
* configuration
|
|
3628
3483
|
*/
|
|
3629
3484
|
const updateTokenCostMutation = useMutation({
|
|
3630
3485
|
mutationFn: ({ model, input_price, output_price, onSuccess }) => {
|
|
3631
3486
|
// Convert per-million token prices to per-token prices
|
|
3632
|
-
const
|
|
3487
|
+
const tokenCosts = {
|
|
3633
3488
|
input_price: input_price / 1000000,
|
|
3634
3489
|
output_price: output_price / 1000000,
|
|
3635
3490
|
};
|
|
@@ -3638,9 +3493,9 @@ const useTokenCosts = () => {
|
|
|
3638
3493
|
.config()
|
|
3639
3494
|
.putConfig([
|
|
3640
3495
|
{
|
|
3641
|
-
type: "token-
|
|
3496
|
+
type: "token-cost",
|
|
3642
3497
|
key: model,
|
|
3643
|
-
value: JSON.stringify(
|
|
3498
|
+
value: JSON.stringify(tokenCosts),
|
|
3644
3499
|
},
|
|
3645
3500
|
])
|
|
3646
3501
|
.then((x) => {
|
|
@@ -3660,14 +3515,14 @@ const useTokenCosts = () => {
|
|
|
3660
3515
|
},
|
|
3661
3516
|
onSuccess: () => {
|
|
3662
3517
|
// Invalidate cache to refresh the token costs list
|
|
3663
|
-
queryClient.invalidateQueries({ queryKey: ["token-
|
|
3518
|
+
queryClient.invalidateQueries({ queryKey: ["token-cost"] });
|
|
3664
3519
|
notify.success("Token costs updated");
|
|
3665
3520
|
},
|
|
3666
3521
|
});
|
|
3667
3522
|
// Show loading indicators for long-running operations
|
|
3668
3523
|
useActivity(query.isLoading, "Loading token costs");
|
|
3669
|
-
useActivity(
|
|
3670
|
-
useActivity(updateTokenCostMutation.isPending, "Updating token
|
|
3524
|
+
useActivity(deleteTokenCostMutation.isPending, "Deleting token cost");
|
|
3525
|
+
useActivity(updateTokenCostMutation.isPending, "Updating token cost");
|
|
3671
3526
|
// Return token cost state and operations for use in components
|
|
3672
3527
|
return {
|
|
3673
3528
|
// Token cost query state
|
|
@@ -3676,9 +3531,9 @@ const useTokenCosts = () => {
|
|
|
3676
3531
|
isError: query.isError,
|
|
3677
3532
|
error: query.error,
|
|
3678
3533
|
// Token cost deletion operations
|
|
3679
|
-
|
|
3680
|
-
isDeleting:
|
|
3681
|
-
deleteError:
|
|
3534
|
+
deleteTokenCost: deleteTokenCostMutation.mutate,
|
|
3535
|
+
isDeleting: deleteTokenCostMutation.isPending,
|
|
3536
|
+
deleteError: deleteTokenCostMutation.error,
|
|
3682
3537
|
// Token cost update operations
|
|
3683
3538
|
updateTokenCost: updateTokenCostMutation.mutate,
|
|
3684
3539
|
isSubmitting: updateTokenCostMutation.isPending,
|
|
@@ -3703,7 +3558,7 @@ const useLLMModels = () => {
|
|
|
3703
3558
|
queryFn: async () => {
|
|
3704
3559
|
const response = await socket
|
|
3705
3560
|
.config()
|
|
3706
|
-
.getConfig([{ type: "parameter-
|
|
3561
|
+
.getConfig([{ type: "parameter-type", key: "llm-model" }]);
|
|
3707
3562
|
if (!response.values || response.values.length === 0) {
|
|
3708
3563
|
return [];
|
|
3709
3564
|
}
|
|
@@ -3739,7 +3594,7 @@ const useLLMModels = () => {
|
|
|
3739
3594
|
};
|
|
3740
3595
|
await socket.config().putConfig([
|
|
3741
3596
|
{
|
|
3742
|
-
type: "parameter-
|
|
3597
|
+
type: "parameter-type",
|
|
3743
3598
|
key: name,
|
|
3744
3599
|
value: JSON.stringify(updatedDef),
|
|
3745
3600
|
},
|
|
@@ -3768,11 +3623,11 @@ const useLLMModels = () => {
|
|
|
3768
3623
|
|
|
3769
3624
|
// @ts-nocheck
|
|
3770
3625
|
/**
|
|
3771
|
-
* Custom hook for managing flow
|
|
3772
|
-
* Provides functionality for fetching, creating, updating, and deleting flow
|
|
3773
|
-
* @returns {Object} Flow
|
|
3626
|
+
* Custom hook for managing flow blueprint operations
|
|
3627
|
+
* Provides functionality for fetching, creating, updating, and deleting flow blueprintes
|
|
3628
|
+
* @returns {Object} Flow blueprint state and operations
|
|
3774
3629
|
*/
|
|
3775
|
-
const
|
|
3630
|
+
const useFlowBlueprints = () => {
|
|
3776
3631
|
// WebSocket connection for communicating with the config service
|
|
3777
3632
|
const socket = useSocket();
|
|
3778
3633
|
const connectionState = useConnectionState();
|
|
@@ -3784,11 +3639,11 @@ const useFlowClasses = () => {
|
|
|
3784
3639
|
const isSocketReady = connectionState?.status === "authenticated" ||
|
|
3785
3640
|
connectionState?.status === "unauthenticated";
|
|
3786
3641
|
/**
|
|
3787
|
-
* Query for fetching all flow
|
|
3642
|
+
* Query for fetching all flow blueprintes
|
|
3788
3643
|
* Uses React Query for caching and background refetching
|
|
3789
3644
|
*/
|
|
3790
3645
|
const query = useQuery({
|
|
3791
|
-
queryKey: ["flow-
|
|
3646
|
+
queryKey: ["flow-blueprints"],
|
|
3792
3647
|
enabled: isSocketReady,
|
|
3793
3648
|
staleTime: 0, // Force fresh data
|
|
3794
3649
|
gcTime: 0, // Don't cache (React Query v5 uses gcTime instead of cacheTime)
|
|
@@ -3797,54 +3652,54 @@ const useFlowClasses = () => {
|
|
|
3797
3652
|
try {
|
|
3798
3653
|
const response = await socket.config().getConfigAll();
|
|
3799
3654
|
// Handle both array and object responses
|
|
3800
|
-
const config = response.config["flow-
|
|
3655
|
+
const config = response.config["flow-blueprints"];
|
|
3801
3656
|
if (Array.isArray(config)) {
|
|
3802
3657
|
// If it's already an array, check if it's an array of [key, value] pairs
|
|
3803
3658
|
if (config.length > 0 &&
|
|
3804
3659
|
Array.isArray(config[0]) &&
|
|
3805
3660
|
config[0].length === 2) {
|
|
3806
|
-
// It's an array of [id,
|
|
3807
|
-
const converted = config.map(([id,
|
|
3808
|
-
let
|
|
3809
|
-
// If the
|
|
3810
|
-
if (typeof
|
|
3661
|
+
// It's an array of [id, flowBlueprint] pairs - convert to objects
|
|
3662
|
+
const converted = config.map(([id, flowBlueprintData]) => {
|
|
3663
|
+
let flowBlueprint = flowBlueprintData;
|
|
3664
|
+
// If the flowBlueprint is a JSON string, parse it
|
|
3665
|
+
if (typeof flowBlueprintData === "string") {
|
|
3811
3666
|
try {
|
|
3812
|
-
|
|
3667
|
+
flowBlueprint = JSON.parse(flowBlueprintData);
|
|
3813
3668
|
}
|
|
3814
3669
|
catch (error) {
|
|
3815
|
-
console.error(`Failed to parse flow
|
|
3816
|
-
|
|
3670
|
+
console.error(`Failed to parse flow blueprint JSON for ${id}:`, error);
|
|
3671
|
+
flowBlueprint = flowBlueprintData;
|
|
3817
3672
|
}
|
|
3818
3673
|
}
|
|
3819
3674
|
return {
|
|
3820
3675
|
id,
|
|
3821
|
-
...
|
|
3676
|
+
...flowBlueprint,
|
|
3822
3677
|
};
|
|
3823
3678
|
});
|
|
3824
3679
|
return converted;
|
|
3825
3680
|
}
|
|
3826
3681
|
else {
|
|
3827
|
-
// It's already an array of flow
|
|
3682
|
+
// It's already an array of flow blueprint objects
|
|
3828
3683
|
return config;
|
|
3829
3684
|
}
|
|
3830
3685
|
}
|
|
3831
3686
|
else if (config && typeof config === "object") {
|
|
3832
|
-
// Convert object to array of flow
|
|
3833
|
-
const converted = Object.entries(config).map(([id,
|
|
3834
|
-
let
|
|
3835
|
-
// If the
|
|
3836
|
-
if (typeof
|
|
3687
|
+
// Convert object to array of flow blueprintes
|
|
3688
|
+
const converted = Object.entries(config).map(([id, flowBlueprintData]) => {
|
|
3689
|
+
let flowBlueprint = flowBlueprintData;
|
|
3690
|
+
// If the flowBlueprint is a JSON string, parse it
|
|
3691
|
+
if (typeof flowBlueprintData === "string") {
|
|
3837
3692
|
try {
|
|
3838
|
-
|
|
3693
|
+
flowBlueprint = JSON.parse(flowBlueprintData);
|
|
3839
3694
|
}
|
|
3840
3695
|
catch (error) {
|
|
3841
|
-
console.error(`Failed to parse flow
|
|
3842
|
-
|
|
3696
|
+
console.error(`Failed to parse flow blueprint JSON for ${id}:`, error);
|
|
3697
|
+
flowBlueprint = flowBlueprintData;
|
|
3843
3698
|
}
|
|
3844
3699
|
}
|
|
3845
3700
|
return {
|
|
3846
3701
|
id,
|
|
3847
|
-
...
|
|
3702
|
+
...flowBlueprint,
|
|
3848
3703
|
};
|
|
3849
3704
|
});
|
|
3850
3705
|
return converted;
|
|
@@ -3852,171 +3707,171 @@ const useFlowClasses = () => {
|
|
|
3852
3707
|
return [];
|
|
3853
3708
|
}
|
|
3854
3709
|
catch (error) {
|
|
3855
|
-
console.error("Failed to fetch flow
|
|
3856
|
-
throw new Error("Failed to fetch flow
|
|
3710
|
+
console.error("Failed to fetch flow blueprintes:", error);
|
|
3711
|
+
throw new Error("Failed to fetch flow blueprintes");
|
|
3857
3712
|
}
|
|
3858
3713
|
},
|
|
3859
3714
|
});
|
|
3860
3715
|
// Track loading state
|
|
3861
|
-
useActivity(query.isLoading, "Loading flow
|
|
3716
|
+
useActivity(query.isLoading, "Loading flow blueprintes");
|
|
3862
3717
|
/**
|
|
3863
|
-
* Mutation for creating a new flow
|
|
3718
|
+
* Mutation for creating a new flow blueprint
|
|
3864
3719
|
*/
|
|
3865
3720
|
const createMutation = useMutation({
|
|
3866
|
-
mutationFn: async ({ id,
|
|
3721
|
+
mutationFn: async ({ id, flowBlueprint, }) => {
|
|
3867
3722
|
try {
|
|
3868
3723
|
await socket.config().putConfig([
|
|
3869
3724
|
{
|
|
3870
|
-
type: "flow-
|
|
3725
|
+
type: "flow-blueprints",
|
|
3871
3726
|
key: id,
|
|
3872
|
-
value: JSON.stringify(
|
|
3727
|
+
value: JSON.stringify(flowBlueprint),
|
|
3873
3728
|
},
|
|
3874
3729
|
]);
|
|
3875
3730
|
return {
|
|
3876
3731
|
id,
|
|
3877
|
-
...
|
|
3732
|
+
...flowBlueprint,
|
|
3878
3733
|
};
|
|
3879
3734
|
}
|
|
3880
3735
|
catch (error) {
|
|
3881
|
-
console.error(`Failed to create flow
|
|
3882
|
-
throw new Error(`Failed to create flow
|
|
3736
|
+
console.error(`Failed to create flow blueprint ${id}:`, error);
|
|
3737
|
+
throw new Error(`Failed to create flow blueprint: ${id}`);
|
|
3883
3738
|
}
|
|
3884
3739
|
},
|
|
3885
|
-
onSuccess: (
|
|
3886
|
-
// Invalidate and refetch flow
|
|
3887
|
-
queryClient.invalidateQueries({ queryKey: ["flow-
|
|
3888
|
-
notify.success(`Flow
|
|
3740
|
+
onSuccess: (flowBlueprint) => {
|
|
3741
|
+
// Invalidate and refetch flow blueprintes
|
|
3742
|
+
queryClient.invalidateQueries({ queryKey: ["flow-blueprints"] });
|
|
3743
|
+
notify.success(`Flow blueprint "${flowBlueprint.id}" created successfully`);
|
|
3889
3744
|
},
|
|
3890
3745
|
onError: (error) => {
|
|
3891
|
-
notify.error(`Failed to create flow
|
|
3746
|
+
notify.error(`Failed to create flow blueprint: ${error.message}`);
|
|
3892
3747
|
},
|
|
3893
3748
|
});
|
|
3894
3749
|
/**
|
|
3895
|
-
* Mutation for updating an existing flow
|
|
3750
|
+
* Mutation for updating an existing flow blueprint
|
|
3896
3751
|
*/
|
|
3897
3752
|
const updateMutation = useMutation({
|
|
3898
|
-
mutationFn: async ({ id,
|
|
3753
|
+
mutationFn: async ({ id, flowBlueprint, }) => {
|
|
3899
3754
|
try {
|
|
3900
|
-
// Get current flow
|
|
3755
|
+
// Get current flow blueprint to merge changes
|
|
3901
3756
|
const currentResponse = await socket.config().getConfig([
|
|
3902
3757
|
{
|
|
3903
|
-
type: "flow-
|
|
3758
|
+
type: "flow-blueprints",
|
|
3904
3759
|
key: id,
|
|
3905
3760
|
},
|
|
3906
3761
|
]);
|
|
3907
|
-
const
|
|
3908
|
-
...currentResponse.config["flow-
|
|
3909
|
-
...
|
|
3762
|
+
const updatedFlowBlueprint = {
|
|
3763
|
+
...currentResponse.config["flow-blueprints"][id],
|
|
3764
|
+
...flowBlueprint,
|
|
3910
3765
|
};
|
|
3911
3766
|
await socket.config().putConfig([
|
|
3912
3767
|
{
|
|
3913
|
-
type: "flow-
|
|
3768
|
+
type: "flow-blueprints",
|
|
3914
3769
|
key: id,
|
|
3915
|
-
value: JSON.stringify(
|
|
3770
|
+
value: JSON.stringify(updatedFlowBlueprint),
|
|
3916
3771
|
},
|
|
3917
3772
|
]);
|
|
3918
3773
|
return {
|
|
3919
3774
|
id,
|
|
3920
|
-
...
|
|
3775
|
+
...updatedFlowBlueprint,
|
|
3921
3776
|
};
|
|
3922
3777
|
}
|
|
3923
3778
|
catch (error) {
|
|
3924
|
-
console.error(`Failed to update flow
|
|
3925
|
-
throw new Error(`Failed to update flow
|
|
3779
|
+
console.error(`Failed to update flow blueprint ${id}:`, error);
|
|
3780
|
+
throw new Error(`Failed to update flow blueprint: ${id}`);
|
|
3926
3781
|
}
|
|
3927
3782
|
},
|
|
3928
|
-
onSuccess: (
|
|
3783
|
+
onSuccess: (flowBlueprint) => {
|
|
3929
3784
|
// Update cache
|
|
3930
|
-
queryClient.invalidateQueries({ queryKey: ["flow-
|
|
3931
|
-
notify.success(`Flow
|
|
3785
|
+
queryClient.invalidateQueries({ queryKey: ["flow-blueprints"] });
|
|
3786
|
+
notify.success(`Flow blueprint "${flowBlueprint.id}" updated successfully`);
|
|
3932
3787
|
},
|
|
3933
3788
|
onError: (error) => {
|
|
3934
|
-
notify.error(`Failed to update flow
|
|
3789
|
+
notify.error(`Failed to update flow blueprint: ${error.message}`);
|
|
3935
3790
|
},
|
|
3936
3791
|
});
|
|
3937
3792
|
/**
|
|
3938
|
-
* Mutation for deleting a flow
|
|
3793
|
+
* Mutation for deleting a flow blueprint
|
|
3939
3794
|
*/
|
|
3940
3795
|
const deleteMutation = useMutation({
|
|
3941
3796
|
mutationFn: async (id) => {
|
|
3942
3797
|
try {
|
|
3943
|
-
await socket.flows().
|
|
3798
|
+
await socket.flows().deleteFlowBlueprint(id);
|
|
3944
3799
|
}
|
|
3945
3800
|
catch (error) {
|
|
3946
|
-
console.error(`Failed to delete flow
|
|
3801
|
+
console.error(`Failed to delete flow blueprint ${id}:`, error);
|
|
3947
3802
|
// Re-throw the original error to preserve the API error message
|
|
3948
3803
|
throw error;
|
|
3949
3804
|
}
|
|
3950
3805
|
},
|
|
3951
3806
|
onSuccess: (_, id) => {
|
|
3952
3807
|
// Remove from cache
|
|
3953
|
-
queryClient.invalidateQueries({ queryKey: ["flow-
|
|
3954
|
-
notify.success(`Flow
|
|
3808
|
+
queryClient.invalidateQueries({ queryKey: ["flow-blueprints"] });
|
|
3809
|
+
notify.success(`Flow blueprint "${id}" deleted successfully`);
|
|
3955
3810
|
},
|
|
3956
3811
|
onError: (error) => {
|
|
3957
3812
|
// Show the actual API error message without additional prefixes
|
|
3958
|
-
notify.error(error.message || "Unknown error occurred while deleting flow
|
|
3813
|
+
notify.error(error.message || "Unknown error occurred while deleting flow blueprint");
|
|
3959
3814
|
},
|
|
3960
3815
|
});
|
|
3961
3816
|
/**
|
|
3962
|
-
* Mutation for duplicating a flow
|
|
3817
|
+
* Mutation for duplicating a flow blueprint
|
|
3963
3818
|
*/
|
|
3964
3819
|
const duplicateMutation = useMutation({
|
|
3965
3820
|
mutationFn: async ({ sourceId, targetId, }) => {
|
|
3966
3821
|
try {
|
|
3967
|
-
// Get source flow
|
|
3822
|
+
// Get source flow blueprint
|
|
3968
3823
|
const sourceResponse = await socket.config().getConfig([
|
|
3969
3824
|
{
|
|
3970
|
-
type: "flow-
|
|
3825
|
+
type: "flow-blueprints",
|
|
3971
3826
|
key: sourceId,
|
|
3972
3827
|
},
|
|
3973
3828
|
]);
|
|
3974
|
-
const
|
|
3829
|
+
const sourceFlowBlueprint = sourceResponse.config["flow-blueprints"][sourceId];
|
|
3975
3830
|
// Create duplicate with updated description
|
|
3976
|
-
const
|
|
3977
|
-
...
|
|
3978
|
-
description: `${
|
|
3979
|
-
tags: [...(
|
|
3831
|
+
const duplicatedFlowBlueprint = {
|
|
3832
|
+
...sourceFlowBlueprint,
|
|
3833
|
+
description: `${sourceFlowBlueprint.description || sourceId} (Copy)`,
|
|
3834
|
+
tags: [...(sourceFlowBlueprint.tags || []), "copy"],
|
|
3980
3835
|
};
|
|
3981
|
-
// Save as new flow
|
|
3836
|
+
// Save as new flow blueprint
|
|
3982
3837
|
await socket.config().putConfig([
|
|
3983
3838
|
{
|
|
3984
|
-
type: "flow-
|
|
3839
|
+
type: "flow-blueprints",
|
|
3985
3840
|
key: targetId,
|
|
3986
|
-
value: JSON.stringify(
|
|
3841
|
+
value: JSON.stringify(duplicatedFlowBlueprint),
|
|
3987
3842
|
},
|
|
3988
3843
|
]);
|
|
3989
3844
|
return {
|
|
3990
3845
|
id: targetId,
|
|
3991
|
-
...
|
|
3846
|
+
...duplicatedFlowBlueprint,
|
|
3992
3847
|
};
|
|
3993
3848
|
}
|
|
3994
3849
|
catch (error) {
|
|
3995
|
-
console.error(`Failed to duplicate flow
|
|
3996
|
-
throw new Error(`Failed to duplicate flow
|
|
3850
|
+
console.error(`Failed to duplicate flow blueprint ${sourceId}:`, error);
|
|
3851
|
+
throw new Error(`Failed to duplicate flow blueprint: ${sourceId}`);
|
|
3997
3852
|
}
|
|
3998
3853
|
},
|
|
3999
|
-
onSuccess: (
|
|
4000
|
-
queryClient.invalidateQueries({ queryKey: ["flow-
|
|
4001
|
-
notify.success(`Flow
|
|
3854
|
+
onSuccess: (flowBlueprint) => {
|
|
3855
|
+
queryClient.invalidateQueries({ queryKey: ["flow-blueprints"] });
|
|
3856
|
+
notify.success(`Flow blueprint duplicated as "${flowBlueprint.id}"`);
|
|
4002
3857
|
},
|
|
4003
3858
|
onError: (error) => {
|
|
4004
|
-
notify.error(`Failed to duplicate flow
|
|
3859
|
+
notify.error(`Failed to duplicate flow blueprint: ${error.message}`);
|
|
4005
3860
|
},
|
|
4006
3861
|
});
|
|
4007
3862
|
// Track mutation loading states
|
|
4008
|
-
useActivity(createMutation.isPending, "Creating flow
|
|
4009
|
-
useActivity(updateMutation.isPending, "Updating flow
|
|
4010
|
-
useActivity(deleteMutation.isPending, "Deleting flow
|
|
4011
|
-
useActivity(duplicateMutation.isPending, "Duplicating flow
|
|
3863
|
+
useActivity(createMutation.isPending, "Creating flow blueprint");
|
|
3864
|
+
useActivity(updateMutation.isPending, "Updating flow blueprint");
|
|
3865
|
+
useActivity(deleteMutation.isPending, "Deleting flow blueprint");
|
|
3866
|
+
useActivity(duplicateMutation.isPending, "Duplicating flow blueprint");
|
|
4012
3867
|
return {
|
|
4013
3868
|
// Query state
|
|
4014
|
-
|
|
3869
|
+
flowBlueprints: query.data || [],
|
|
4015
3870
|
isLoading: query.isLoading,
|
|
4016
3871
|
error: query.error,
|
|
4017
3872
|
refetch: query.refetch,
|
|
4018
3873
|
// Utilities
|
|
4019
|
-
|
|
3874
|
+
getFlowBlueprint: (id) => {
|
|
4020
3875
|
const found = query.data?.find((fc) => {
|
|
4021
3876
|
return fc.id === id;
|
|
4022
3877
|
});
|
|
@@ -4026,10 +3881,10 @@ const useFlowClasses = () => {
|
|
|
4026
3881
|
return query.data?.some((fc) => fc.id === id) ?? false;
|
|
4027
3882
|
},
|
|
4028
3883
|
// Mutations
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
4032
|
-
|
|
3884
|
+
createFlowBlueprint: createMutation.mutateAsync,
|
|
3885
|
+
updateFlowBlueprint: updateMutation.mutateAsync,
|
|
3886
|
+
deleteFlowBlueprint: deleteMutation.mutateAsync,
|
|
3887
|
+
duplicateFlowBlueprint: duplicateMutation.mutateAsync,
|
|
4033
3888
|
// Mutation states
|
|
4034
3889
|
isCreating: createMutation.isPending,
|
|
4035
3890
|
isUpdating: updateMutation.isPending,
|
|
@@ -4038,9 +3893,9 @@ const useFlowClasses = () => {
|
|
|
4038
3893
|
};
|
|
4039
3894
|
};
|
|
4040
3895
|
/**
|
|
4041
|
-
* Generate a unique flow
|
|
3896
|
+
* Generate a unique flow blueprint ID
|
|
4042
3897
|
*/
|
|
4043
|
-
const
|
|
3898
|
+
const generateFlowBlueprintId = (baseName = "flow-class") => {
|
|
4044
3899
|
const timestamp = Date.now();
|
|
4045
3900
|
const random = Math.random().toString(36).substring(2, 8);
|
|
4046
3901
|
return `${baseName}-${timestamp}-${random}`;
|
|
@@ -4048,29 +3903,29 @@ const generateFlowClassId = (baseName = "flow-class") => {
|
|
|
4048
3903
|
|
|
4049
3904
|
// @ts-nocheck
|
|
4050
3905
|
/**
|
|
4051
|
-
* Custom hook for fetching parameter definitions for a flow
|
|
4052
|
-
* @param
|
|
3906
|
+
* Custom hook for fetching parameter definitions for a flow blueprint
|
|
3907
|
+
* @param flowBlueprintName - The name of the flow blueprint to fetch parameters for
|
|
4053
3908
|
* @returns Parameter definitions, mapping, and loading states
|
|
4054
3909
|
*/
|
|
4055
|
-
const useFlowParameters = (
|
|
3910
|
+
const useFlowParameters = (flowBlueprintName) => {
|
|
4056
3911
|
const socket = useSocket();
|
|
4057
3912
|
const connectionState = useConnectionState();
|
|
4058
3913
|
const isSocketReady = connectionState?.status === "authenticated" ||
|
|
4059
3914
|
connectionState?.status === "unauthenticated";
|
|
4060
3915
|
/**
|
|
4061
|
-
* Query for fetching parameter definitions for a flow
|
|
3916
|
+
* Query for fetching parameter definitions for a flow blueprint
|
|
4062
3917
|
*/
|
|
4063
3918
|
const parametersQuery = useQuery({
|
|
4064
|
-
queryKey: ["flow-parameters",
|
|
4065
|
-
enabled: isSocketReady && !!
|
|
3919
|
+
queryKey: ["flow-parameters", flowBlueprintName],
|
|
3920
|
+
enabled: isSocketReady && !!flowBlueprintName,
|
|
4066
3921
|
queryFn: async () => {
|
|
4067
|
-
if (!
|
|
3922
|
+
if (!flowBlueprintName)
|
|
4068
3923
|
return null;
|
|
4069
3924
|
try {
|
|
4070
|
-
// Get flow
|
|
4071
|
-
const
|
|
3925
|
+
// Get flow blueprint definition first
|
|
3926
|
+
const flowBlueprint = await socket.flows().getFlowBlueprint(flowBlueprintName);
|
|
4072
3927
|
// Extract parameter metadata with new structure
|
|
4073
|
-
const parameterMetadata =
|
|
3928
|
+
const parameterMetadata = flowBlueprint.parameters || {};
|
|
4074
3929
|
if (Object.keys(parameterMetadata).length === 0) {
|
|
4075
3930
|
return {
|
|
4076
3931
|
parameterDefinitions: {},
|
|
@@ -4086,14 +3941,14 @@ const useFlowParameters = (flowClassName) => {
|
|
|
4086
3941
|
// Fetch parameter definitions from config
|
|
4087
3942
|
const definitionNames = Object.values(parameterMapping);
|
|
4088
3943
|
const configKeys = definitionNames.map((name) => ({
|
|
4089
|
-
type: "parameter-
|
|
3944
|
+
type: "parameter-type",
|
|
4090
3945
|
key: name,
|
|
4091
3946
|
}));
|
|
4092
3947
|
const configResponse = await socket.config().getConfig(configKeys);
|
|
4093
3948
|
const parameterDefinitions = {};
|
|
4094
3949
|
// Parse config response to get parameter definitions
|
|
4095
3950
|
configResponse.values?.forEach((item) => {
|
|
4096
|
-
if (item.type === "parameter-
|
|
3951
|
+
if (item.type === "parameter-type") {
|
|
4097
3952
|
try {
|
|
4098
3953
|
parameterDefinitions[item.key] = JSON.parse(item.value);
|
|
4099
3954
|
}
|
|
@@ -4668,5 +4523,5 @@ const useNodeDetails = (nodeId, flowId) => {
|
|
|
4668
4523
|
};
|
|
4669
4524
|
};
|
|
4670
4525
|
|
|
4671
|
-
export { DEFAULT_SETTINGS, NotificationProvider, RDFS_LABEL, SETTINGS_STORAGE_KEY, createDocId, fileToBase64,
|
|
4526
|
+
export { DEFAULT_SETTINGS, NotificationProvider, RDFS_LABEL, SETTINGS_STORAGE_KEY, createDocId, fileToBase64, generateFlowBlueprintId, getTriples, prepareMetadata, textToBase64, useActivity, useAgentTools, useChat, useChatSession, useCollections, useConversation, useEmbeddings, useEntityDetail, useFlowBlueprints, useFlowParameters, useFlows, useGraphEmbeddings, useGraphSubgraph, useInference, useKnowledgeCores, useLLMModels, useLibrary, useLoadStateStore, useMcpTools, useNlpQuery, useNodeDetails, useNotification, useObjectsQuery, useOntologies, useParameterValidation, useProcessing, useProgressStateStore, usePrompts, useSchemas, useSearchStateStore, useSessionStore, useSettings, useStructuredQuery, useTokenCosts, useTriples, useVectorSearch, useWorkbenchStateStore, vectorSearch };
|
|
4672
4527
|
//# sourceMappingURL=index.esm.js.map
|