@trustgraph/react-state 1.2.2 → 1.3.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/dist/index.cjs +134 -85
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +134 -86
- package/dist/index.esm.js.map +1 -1
- package/dist/model/document-metadata.d.ts +1 -1
- package/dist/model/document-metadata.d.ts.map +1 -1
- package/dist/state/inference.d.ts +2 -2
- package/dist/state/inference.d.ts.map +1 -1
- package/dist/state/node-details.d.ts.map +1 -1
- package/dist/utils/knowledge-graph-viz.d.ts.map +1 -1
- package/dist/utils/knowledge-graph.d.ts +17 -7
- package/dist/utils/knowledge-graph.d.ts.map +1 -1
- package/dist/utils/row.d.ts.map +1 -1
- package/package.json +9 -5
- package/dist/index.js +0 -6018
- package/dist/index.js.map +0 -1
- package/dist/state/chat-query.d.ts +0 -13
- package/dist/state/chat-query.d.ts.map +0 -1
- package/dist/state/chat.d.ts +0 -13
- package/dist/state/chat.d.ts.map +0 -1
- package/dist/state/flow-classes.d.ts +0 -63
- package/dist/state/flow-classes.d.ts.map +0 -1
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,
|
|
3
|
+
export type { BaseApi, Triple, Term, IriTerm, BlankTerm, LiteralTerm, TripleTerm, ConnectionState, StreamingMetadata, } from "@trustgraph/client";
|
|
4
4
|
export { NotificationProvider } from "./NotificationProvider";
|
|
5
5
|
export type { NotificationProviderProps } from "./NotificationProvider";
|
|
6
6
|
export type { NotificationHandler } from "./types";
|
|
@@ -54,7 +54,8 @@ export { DEFAULT_SETTINGS, SETTINGS_STORAGE_KEY, } from "./model/settings-types"
|
|
|
54
54
|
export type { LLMModelParameter, EnumOption } from "./model/llm-models";
|
|
55
55
|
export { fileToBase64, textToBase64 } from "./utils/document-encoding";
|
|
56
56
|
export { vectorSearch } from "./utils/vector-search";
|
|
57
|
-
export { getTriples, RDFS_LABEL } from "./utils/knowledge-graph";
|
|
57
|
+
export { getTriples, getTermValue, RDFS_LABEL } from "./utils/knowledge-graph";
|
|
58
|
+
export type { LabeledTerm, LabeledTriple } from "./utils/knowledge-graph";
|
|
58
59
|
export { prepareMetadata, createDocId } from "./model/document-metadata";
|
|
59
60
|
export type { DocumentParameters } from "./model/document-metadata";
|
|
60
61
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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,
|
|
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,CA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AChB,oBAAoB,GACrB,MAAM,wBAAwB,CAAC;AAChC,YAAY,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGxE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,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
|
@@ -696,36 +696,36 @@ const createDocId = () => {
|
|
|
696
696
|
const prepareMetadata = (doc_id, params) => {
|
|
697
697
|
let doc_meta = [
|
|
698
698
|
{
|
|
699
|
-
s: {
|
|
700
|
-
p: {
|
|
701
|
-
o: {
|
|
699
|
+
s: { t: "i", i: doc_id },
|
|
700
|
+
p: { t: "i", i: RDF_TYPE },
|
|
701
|
+
o: { t: "i", i: DIGITAL_DOCUMENT },
|
|
702
702
|
},
|
|
703
703
|
];
|
|
704
704
|
if (params.title != "")
|
|
705
705
|
doc_meta = [
|
|
706
706
|
...doc_meta,
|
|
707
707
|
{
|
|
708
|
-
s: {
|
|
709
|
-
p: {
|
|
710
|
-
o: { v: params.title
|
|
708
|
+
s: { t: "i", i: doc_id },
|
|
709
|
+
p: { t: "i", i: RDFS_LABEL$1 },
|
|
710
|
+
o: { t: "l", v: params.title ?? "" },
|
|
711
711
|
},
|
|
712
712
|
];
|
|
713
713
|
if (params.url != "")
|
|
714
714
|
doc_meta = [
|
|
715
715
|
...doc_meta,
|
|
716
716
|
{
|
|
717
|
-
s: {
|
|
718
|
-
p: {
|
|
719
|
-
o: {
|
|
717
|
+
s: { t: "i", i: doc_id },
|
|
718
|
+
p: { t: "i", i: SCHEMA_URL },
|
|
719
|
+
o: { t: "i", i: params.url ?? "" },
|
|
720
720
|
},
|
|
721
721
|
];
|
|
722
|
-
for (const keyword of params.keywords)
|
|
722
|
+
for (const keyword of params.keywords ?? [])
|
|
723
723
|
doc_meta = [
|
|
724
724
|
...doc_meta,
|
|
725
725
|
{
|
|
726
|
-
s: {
|
|
727
|
-
p: {
|
|
728
|
-
o: {
|
|
726
|
+
s: { t: "i", i: doc_id },
|
|
727
|
+
p: { t: "i", i: SCHEMA_KEYWORDS },
|
|
728
|
+
o: { t: "l", v: keyword },
|
|
729
729
|
},
|
|
730
730
|
];
|
|
731
731
|
return doc_meta;
|
|
@@ -969,6 +969,18 @@ const useTriples = ({ flow, s, p, o, limit, collection }) => {
|
|
|
969
969
|
};
|
|
970
970
|
};
|
|
971
971
|
|
|
972
|
+
// Helper to get the string value from a Term (IRI or Literal)
|
|
973
|
+
const getTermValue$2 = (term) => {
|
|
974
|
+
if (term.t === "i")
|
|
975
|
+
return term.i;
|
|
976
|
+
if (term.t === "l")
|
|
977
|
+
return term.v;
|
|
978
|
+
if (term.t === "b")
|
|
979
|
+
return term.d;
|
|
980
|
+
return "";
|
|
981
|
+
};
|
|
982
|
+
// Helper to check if a Term is an IRI
|
|
983
|
+
const isIri$2 = (term) => term.t === "i";
|
|
972
984
|
const RDFS_LABEL = "http://www.w3.org/2000/01/rdf-schema#label";
|
|
973
985
|
const SKOS_DEFINITION = "http://www.w3.org/2004/02/skos/core#definition";
|
|
974
986
|
const SCHEMAORG_SUBJECT_OF = "https://schema.org/subjectOf";
|
|
@@ -1000,7 +1012,7 @@ const queryS = (socket, uri, add, remove, limit, collection) => {
|
|
|
1000
1012
|
const act = "Query S: " + uri;
|
|
1001
1013
|
add(act);
|
|
1002
1014
|
return socket
|
|
1003
|
-
.triplesQuery({
|
|
1015
|
+
.triplesQuery({ t: "i", i: uri }, undefined, undefined, limit ? limit : LIMIT, collection)
|
|
1004
1016
|
.then((x) => {
|
|
1005
1017
|
remove(act);
|
|
1006
1018
|
return x;
|
|
@@ -1015,7 +1027,7 @@ const queryP = (socket, uri, add, remove, limit, collection) => {
|
|
|
1015
1027
|
const act = "Query P: " + uri;
|
|
1016
1028
|
add(act);
|
|
1017
1029
|
return socket
|
|
1018
|
-
.triplesQuery(undefined, {
|
|
1030
|
+
.triplesQuery(undefined, { t: "i", i: uri }, undefined, limit ? limit : LIMIT, collection)
|
|
1019
1031
|
.then((x) => {
|
|
1020
1032
|
remove(act);
|
|
1021
1033
|
return x;
|
|
@@ -1030,7 +1042,7 @@ const queryO = (socket, uri, add, remove, limit, collection) => {
|
|
|
1030
1042
|
const act = "Query O: " + uri;
|
|
1031
1043
|
add(act);
|
|
1032
1044
|
return socket
|
|
1033
|
-
.triplesQuery(undefined, undefined, {
|
|
1045
|
+
.triplesQuery(undefined, undefined, { t: "i", i: uri }, limit ? limit : LIMIT, collection)
|
|
1034
1046
|
.then((x) => {
|
|
1035
1047
|
remove(act);
|
|
1036
1048
|
return x;
|
|
@@ -1072,12 +1084,12 @@ const queryLabel = (socket, uri, add, remove, collection) => {
|
|
|
1072
1084
|
add(act);
|
|
1073
1085
|
// Search tthe graph for the URI->label relationship
|
|
1074
1086
|
return socket
|
|
1075
|
-
.triplesQuery({
|
|
1087
|
+
.triplesQuery({ t: "i", i: uri }, { t: "i", i: RDFS_LABEL }, undefined, 1, collection)
|
|
1076
1088
|
.then((triples) => {
|
|
1077
1089
|
// If got a result, return the label, otherwise the URI
|
|
1078
1090
|
// can be its own label
|
|
1079
1091
|
if (triples.length > 0)
|
|
1080
|
-
return triples[0].o
|
|
1092
|
+
return getTermValue$2(triples[0].o);
|
|
1081
1093
|
else
|
|
1082
1094
|
return uri;
|
|
1083
1095
|
})
|
|
@@ -1094,7 +1106,7 @@ const queryLabel = (socket, uri, add, remove, collection) => {
|
|
|
1094
1106
|
// Returns a promise
|
|
1095
1107
|
const labelS = (socket, triples, add, remove, collection) => {
|
|
1096
1108
|
return Promise.all(triples.map((t) => {
|
|
1097
|
-
return queryLabel(socket, t.s
|
|
1109
|
+
return queryLabel(socket, getTermValue$2(t.s), add, remove, collection).then((label) => {
|
|
1098
1110
|
return {
|
|
1099
1111
|
...t,
|
|
1100
1112
|
s: {
|
|
@@ -1109,7 +1121,7 @@ const labelS = (socket, triples, add, remove, collection) => {
|
|
|
1109
1121
|
// Returns a promise
|
|
1110
1122
|
const labelP = (socket, triples, add, remove, collection) => {
|
|
1111
1123
|
return Promise.all(triples.map((t) => {
|
|
1112
|
-
return queryLabel(socket, t.p
|
|
1124
|
+
return queryLabel(socket, getTermValue$2(t.p), add, remove, collection).then((label) => {
|
|
1113
1125
|
return {
|
|
1114
1126
|
...t,
|
|
1115
1127
|
p: {
|
|
@@ -1124,10 +1136,10 @@ const labelP = (socket, triples, add, remove, collection) => {
|
|
|
1124
1136
|
// Returns a promise
|
|
1125
1137
|
const labelO = (socket, triples, add, remove, collection) => {
|
|
1126
1138
|
return Promise.all(triples.map((t) => {
|
|
1127
|
-
// If the 'o' element is
|
|
1139
|
+
// If the 'o' element is an IRI, do a label lookup, else
|
|
1128
1140
|
// just use the literal value for its label
|
|
1129
|
-
if (t.o
|
|
1130
|
-
return queryLabel(socket, t.o.
|
|
1141
|
+
if (isIri$2(t.o))
|
|
1142
|
+
return queryLabel(socket, t.o.i, add, remove, collection).then((label) => {
|
|
1131
1143
|
return {
|
|
1132
1144
|
...t,
|
|
1133
1145
|
o: {
|
|
@@ -1142,7 +1154,7 @@ const labelO = (socket, triples, add, remove, collection) => {
|
|
|
1142
1154
|
...t,
|
|
1143
1155
|
o: {
|
|
1144
1156
|
...t.o,
|
|
1145
|
-
label: t.o
|
|
1157
|
+
label: getTermValue$2(t.o),
|
|
1146
1158
|
},
|
|
1147
1159
|
});
|
|
1148
1160
|
});
|
|
@@ -1150,7 +1162,7 @@ const labelO = (socket, triples, add, remove, collection) => {
|
|
|
1150
1162
|
};
|
|
1151
1163
|
// Filter out 'structural' edges nobody needs to see
|
|
1152
1164
|
const filterInternals = (triples) => triples.filter((t) => {
|
|
1153
|
-
if (t.p
|
|
1165
|
+
if (isIri$2(t.p) && t.p.i == RDFS_LABEL)
|
|
1154
1166
|
return false;
|
|
1155
1167
|
return true;
|
|
1156
1168
|
});
|
|
@@ -1177,6 +1189,18 @@ const getTriples = (socket, uri, add, remove, limit, collection) => {
|
|
|
1177
1189
|
|
|
1178
1190
|
// Functionality here helps construct subgraphs for react-force-graph
|
|
1179
1191
|
// visualisation
|
|
1192
|
+
// Helper to get the string value from a Term (IRI or Literal)
|
|
1193
|
+
const getTermValue$1 = (term) => {
|
|
1194
|
+
if (term.t === "i")
|
|
1195
|
+
return term.i;
|
|
1196
|
+
if (term.t === "l")
|
|
1197
|
+
return term.v;
|
|
1198
|
+
if (term.t === "b")
|
|
1199
|
+
return term.d;
|
|
1200
|
+
return "";
|
|
1201
|
+
};
|
|
1202
|
+
// Helper to check if a Term is an IRI
|
|
1203
|
+
const isIri$1 = (term) => term.t === "i";
|
|
1180
1204
|
const createSubgraph = () => {
|
|
1181
1205
|
return {
|
|
1182
1206
|
nodes: [],
|
|
@@ -1190,19 +1214,20 @@ const updateSubgraphTriples = (sg, triples) => {
|
|
|
1190
1214
|
for (const t of triples) {
|
|
1191
1215
|
// Skip triples where the object is a literal (property edges)
|
|
1192
1216
|
// These are now shown in the node details drawer instead
|
|
1193
|
-
if (!t.o
|
|
1217
|
+
if (!isIri$1(t.o)) {
|
|
1194
1218
|
continue;
|
|
1195
1219
|
}
|
|
1196
1220
|
// Source has a URI, that can be its unique ID
|
|
1197
|
-
const sourceId = t.s
|
|
1221
|
+
const sourceId = getTermValue$1(t.s);
|
|
1198
1222
|
// Target is always an entity now (we filtered out literals above)
|
|
1199
|
-
const targetId = t.o
|
|
1223
|
+
const targetId = getTermValue$1(t.o);
|
|
1200
1224
|
// Links have an ID so that this edge is unique
|
|
1201
|
-
const linkId = t.s
|
|
1225
|
+
const linkId = getTermValue$1(t.s) + "@@" + getTermValue$1(t.p) + "@@" + getTermValue$1(t.o);
|
|
1202
1226
|
if (!nodeIds.has(sourceId)) {
|
|
1227
|
+
const sLabeled = t.s;
|
|
1203
1228
|
const n = {
|
|
1204
1229
|
id: sourceId,
|
|
1205
|
-
label:
|
|
1230
|
+
label: sLabeled.label ? sLabeled.label : "unknown",
|
|
1206
1231
|
group: groupId,
|
|
1207
1232
|
};
|
|
1208
1233
|
nodeIds.add(sourceId);
|
|
@@ -1212,9 +1237,10 @@ const updateSubgraphTriples = (sg, triples) => {
|
|
|
1212
1237
|
};
|
|
1213
1238
|
}
|
|
1214
1239
|
if (!nodeIds.has(targetId)) {
|
|
1240
|
+
const oLabeled = t.o;
|
|
1215
1241
|
const n = {
|
|
1216
1242
|
id: targetId,
|
|
1217
|
-
label:
|
|
1243
|
+
label: oLabeled.label ? oLabeled.label : "unknown",
|
|
1218
1244
|
group: groupId,
|
|
1219
1245
|
};
|
|
1220
1246
|
nodeIds.add(targetId);
|
|
@@ -1224,11 +1250,12 @@ const updateSubgraphTriples = (sg, triples) => {
|
|
|
1224
1250
|
};
|
|
1225
1251
|
}
|
|
1226
1252
|
if (!linkIds.has(linkId)) {
|
|
1253
|
+
const pLabeled = t.p;
|
|
1227
1254
|
const l = {
|
|
1228
1255
|
source: sourceId,
|
|
1229
1256
|
target: targetId,
|
|
1230
1257
|
id: linkId,
|
|
1231
|
-
label:
|
|
1258
|
+
label: pLabeled.label ? pLabeled.label : "unknown",
|
|
1232
1259
|
value: 1,
|
|
1233
1260
|
};
|
|
1234
1261
|
linkIds.add(linkId);
|
|
@@ -1253,14 +1280,14 @@ const updateSubgraphByRelationship = (socket, selectedNodeId, relationshipUri, d
|
|
|
1253
1280
|
add(activityName);
|
|
1254
1281
|
// Build the query based on direction
|
|
1255
1282
|
const queryPromise = direction === "outgoing"
|
|
1256
|
-
? socket.triplesQuery({
|
|
1257
|
-
{
|
|
1283
|
+
? socket.triplesQuery({ t: "i", i: selectedNodeId }, // s = selectedNode
|
|
1284
|
+
{ t: "i", i: relationshipUri }, // p = relationship
|
|
1258
1285
|
undefined, // o = ??? (what we want to find)
|
|
1259
1286
|
20, // Limit results
|
|
1260
1287
|
collection)
|
|
1261
1288
|
: socket.triplesQuery(undefined, // s = ??? (what we want to find)
|
|
1262
|
-
{
|
|
1263
|
-
{
|
|
1289
|
+
{ t: "i", i: relationshipUri }, // p = relationship
|
|
1290
|
+
{ t: "i", i: selectedNodeId }, // o = selectedNode
|
|
1264
1291
|
20, // Limit results
|
|
1265
1292
|
collection);
|
|
1266
1293
|
return queryPromise
|
|
@@ -1433,8 +1460,10 @@ const getGraphEmbeddings = (socket, add, remove, limit, collection) => {
|
|
|
1433
1460
|
.graphEmbeddingsQuery(vecs, limit , collection)
|
|
1434
1461
|
.then((ents) => {
|
|
1435
1462
|
remove(act);
|
|
1436
|
-
return ents
|
|
1437
|
-
|
|
1463
|
+
return ents
|
|
1464
|
+
.filter((ent) => ent.t === "i")
|
|
1465
|
+
.map((ent) => {
|
|
1466
|
+
return { uri: ent.i, target: vecs[0] };
|
|
1438
1467
|
});
|
|
1439
1468
|
})
|
|
1440
1469
|
.catch((err) => {
|
|
@@ -1449,7 +1478,7 @@ const addRowLabels = (socket, add, remove, collection) => (entities) => {
|
|
|
1449
1478
|
const act = "Label " + ent.uri;
|
|
1450
1479
|
add(act);
|
|
1451
1480
|
return socket
|
|
1452
|
-
.triplesQuery({
|
|
1481
|
+
.triplesQuery({ t: "i", i: ent.uri }, { t: "i", i: RDFS_LABEL }, undefined, 1, collection)
|
|
1453
1482
|
.then((t) => {
|
|
1454
1483
|
if (t.length < 1) {
|
|
1455
1484
|
remove(act);
|
|
@@ -1461,9 +1490,10 @@ const addRowLabels = (socket, add, remove, collection) => (entities) => {
|
|
|
1461
1490
|
}
|
|
1462
1491
|
else {
|
|
1463
1492
|
remove(act);
|
|
1493
|
+
const obj = t[0].o;
|
|
1464
1494
|
return {
|
|
1465
1495
|
uri: ent.uri,
|
|
1466
|
-
label:
|
|
1496
|
+
label: obj.v,
|
|
1467
1497
|
target: ent.target,
|
|
1468
1498
|
};
|
|
1469
1499
|
}
|
|
@@ -1482,7 +1512,7 @@ const addRowDefinitions = (socket, add, remove, collection) =>
|
|
|
1482
1512
|
const act = "Description " + ent.uri;
|
|
1483
1513
|
add(act);
|
|
1484
1514
|
return socket
|
|
1485
|
-
.triplesQuery({
|
|
1515
|
+
.triplesQuery({ t: "i", i: ent.uri }, { t: "i", i: SKOS_DEFINITION }, undefined, 1, collection)
|
|
1486
1516
|
.then((t) => {
|
|
1487
1517
|
if (t.length < 1) {
|
|
1488
1518
|
remove(act);
|
|
@@ -1490,9 +1520,10 @@ const addRowDefinitions = (socket, add, remove, collection) =>
|
|
|
1490
1520
|
}
|
|
1491
1521
|
else {
|
|
1492
1522
|
remove(act);
|
|
1523
|
+
const obj = t[0].o;
|
|
1493
1524
|
return {
|
|
1494
1525
|
...ent,
|
|
1495
|
-
description:
|
|
1526
|
+
description: obj.v,
|
|
1496
1527
|
};
|
|
1497
1528
|
}
|
|
1498
1529
|
})
|
|
@@ -1868,12 +1899,12 @@ const useChatSession = () => {
|
|
|
1868
1899
|
addActivity(embActivity);
|
|
1869
1900
|
// Get labels for each entity
|
|
1870
1901
|
const labelPromises = result.entities.map(async (entity) => {
|
|
1871
|
-
const labelActivity = "Label " + entity
|
|
1902
|
+
const labelActivity = "Label " + getTermValue$2(entity);
|
|
1872
1903
|
addActivity(labelActivity);
|
|
1873
1904
|
try {
|
|
1874
1905
|
const triples = await socket
|
|
1875
1906
|
.flow(flowId)
|
|
1876
|
-
.triplesQuery(entity, {
|
|
1907
|
+
.triplesQuery(entity, { t: "i", i: RDFS_LABEL }, undefined, 1, settings.collection);
|
|
1877
1908
|
removeActivity(labelActivity);
|
|
1878
1909
|
return triples;
|
|
1879
1910
|
}
|
|
@@ -1887,8 +1918,8 @@ const useChatSession = () => {
|
|
|
1887
1918
|
const entityList = labelResponses
|
|
1888
1919
|
.filter((resp) => resp && resp.length > 0)
|
|
1889
1920
|
.map((resp) => ({
|
|
1890
|
-
label: resp[0].o
|
|
1891
|
-
uri: resp[0].s
|
|
1921
|
+
label: getTermValue$2(resp[0].o),
|
|
1922
|
+
uri: getTermValue$2(resp[0].s),
|
|
1892
1923
|
}));
|
|
1893
1924
|
setEntities(entityList);
|
|
1894
1925
|
removeActivity(embActivity);
|
|
@@ -4079,6 +4110,18 @@ const useParameterValidation = (parameterDefinitions, parameterMapping, paramete
|
|
|
4079
4110
|
]);
|
|
4080
4111
|
};
|
|
4081
4112
|
|
|
4113
|
+
// Helper to get the string value from a Term (IRI or Literal)
|
|
4114
|
+
const getTermValue = (term) => {
|
|
4115
|
+
if (term.t === "i")
|
|
4116
|
+
return term.i;
|
|
4117
|
+
if (term.t === "l")
|
|
4118
|
+
return term.v;
|
|
4119
|
+
if (term.t === "b")
|
|
4120
|
+
return term.d;
|
|
4121
|
+
return "";
|
|
4122
|
+
};
|
|
4123
|
+
// Helper to check if a Term is an IRI
|
|
4124
|
+
const isIri = (term) => term.t === "i";
|
|
4082
4125
|
/**
|
|
4083
4126
|
* Standard URI to label mappings
|
|
4084
4127
|
* These common URIs are mapped directly without knowledge graph queries
|
|
@@ -4129,10 +4172,10 @@ const useNodeDetails = (nodeId, flowId) => {
|
|
|
4129
4172
|
if (!nodeId) {
|
|
4130
4173
|
throw new Error("Node ID is required");
|
|
4131
4174
|
}
|
|
4132
|
-
const
|
|
4175
|
+
const subjectTerm = { t: "i", i: nodeId };
|
|
4133
4176
|
return socket
|
|
4134
4177
|
.flow(flowId)
|
|
4135
|
-
.triplesQuery(
|
|
4178
|
+
.triplesQuery(subjectTerm, undefined, undefined, 20, settings.collection)
|
|
4136
4179
|
.then((triples) => {
|
|
4137
4180
|
if (!Array.isArray(triples)) {
|
|
4138
4181
|
console.error("Expected triples array, got:", triples);
|
|
@@ -4158,10 +4201,10 @@ const useNodeDetails = (nodeId, flowId) => {
|
|
|
4158
4201
|
if (!nodeId) {
|
|
4159
4202
|
throw new Error("Node ID is required");
|
|
4160
4203
|
}
|
|
4161
|
-
const
|
|
4204
|
+
const objectTerm = { t: "i", i: nodeId };
|
|
4162
4205
|
return socket
|
|
4163
4206
|
.flow(flowId)
|
|
4164
|
-
.triplesQuery(undefined, undefined,
|
|
4207
|
+
.triplesQuery(undefined, undefined, objectTerm, 20, settings.collection)
|
|
4165
4208
|
.then((triples) => {
|
|
4166
4209
|
if (!Array.isArray(triples)) {
|
|
4167
4210
|
console.error("Expected triples array, got:", triples);
|
|
@@ -4187,17 +4230,17 @@ const useNodeDetails = (nodeId, flowId) => {
|
|
|
4187
4230
|
if (!nodeId) {
|
|
4188
4231
|
throw new Error("Node ID is required");
|
|
4189
4232
|
}
|
|
4190
|
-
const
|
|
4233
|
+
const subjectTerm = { t: "i", i: nodeId };
|
|
4191
4234
|
return socket
|
|
4192
4235
|
.flow(flowId)
|
|
4193
|
-
.triplesQuery(
|
|
4236
|
+
.triplesQuery(subjectTerm, undefined, undefined, 50, settings.collection) // More limit for properties
|
|
4194
4237
|
.then((triples) => {
|
|
4195
4238
|
if (!Array.isArray(triples)) {
|
|
4196
4239
|
console.error("Expected triples array, got:", triples);
|
|
4197
4240
|
throw new Error("Invalid triples response");
|
|
4198
4241
|
}
|
|
4199
|
-
// Filter for properties (where o.e
|
|
4200
|
-
return triples.filter((triple) => triple.o && triple.o
|
|
4242
|
+
// Filter for properties (where o is not an IRI, i.e., literals)
|
|
4243
|
+
return triples.filter((triple) => triple.o && !isIri(triple.o));
|
|
4201
4244
|
})
|
|
4202
4245
|
.catch((err) => {
|
|
4203
4246
|
console.error("Error fetching properties:", err);
|
|
@@ -4209,7 +4252,7 @@ const useNodeDetails = (nodeId, flowId) => {
|
|
|
4209
4252
|
});
|
|
4210
4253
|
/**
|
|
4211
4254
|
* Process outbound triples to extract navigable relationships
|
|
4212
|
-
* Filters for entity relationships (o
|
|
4255
|
+
* Filters for entity relationships (where o is an IRI) and removes duplicates
|
|
4213
4256
|
*/
|
|
4214
4257
|
const outboundRelationships = useMemo(() => {
|
|
4215
4258
|
if (!outboundTriplesQuery.data)
|
|
@@ -4217,9 +4260,9 @@ const useNodeDetails = (nodeId, flowId) => {
|
|
|
4217
4260
|
// Filter for entity relationships and extract unique predicates
|
|
4218
4261
|
const uniqueRelationships = new Set();
|
|
4219
4262
|
outboundTriplesQuery.data.forEach((triple) => {
|
|
4220
|
-
// Check if object is an
|
|
4221
|
-
if (triple.o && triple.o
|
|
4222
|
-
uniqueRelationships.add(triple.p.
|
|
4263
|
+
// Check if object is an IRI (entity)
|
|
4264
|
+
if (triple.o && isIri(triple.o) && triple.p && isIri(triple.p)) {
|
|
4265
|
+
uniqueRelationships.add(triple.p.i);
|
|
4223
4266
|
}
|
|
4224
4267
|
});
|
|
4225
4268
|
// Convert Set to array
|
|
@@ -4227,7 +4270,7 @@ const useNodeDetails = (nodeId, flowId) => {
|
|
|
4227
4270
|
}, [outboundTriplesQuery.data]);
|
|
4228
4271
|
/**
|
|
4229
4272
|
* Process inbound triples to extract navigable relationships
|
|
4230
|
-
* Filters for entity relationships (s
|
|
4273
|
+
* Filters for entity relationships (where s is an IRI) and removes duplicates
|
|
4231
4274
|
*/
|
|
4232
4275
|
const inboundRelationships = useMemo(() => {
|
|
4233
4276
|
if (!inboundTriplesQuery.data)
|
|
@@ -4235,9 +4278,9 @@ const useNodeDetails = (nodeId, flowId) => {
|
|
|
4235
4278
|
// Filter for entity relationships and extract unique predicates
|
|
4236
4279
|
const uniqueRelationships = new Set();
|
|
4237
4280
|
inboundTriplesQuery.data.forEach((triple) => {
|
|
4238
|
-
// Check if subject is an
|
|
4239
|
-
if (triple.s && triple.s
|
|
4240
|
-
uniqueRelationships.add(triple.p.
|
|
4281
|
+
// Check if subject is an IRI (entity)
|
|
4282
|
+
if (triple.s && isIri(triple.s) && triple.p && isIri(triple.p)) {
|
|
4283
|
+
uniqueRelationships.add(triple.p.i);
|
|
4241
4284
|
}
|
|
4242
4285
|
});
|
|
4243
4286
|
// Convert Set to array
|
|
@@ -4245,7 +4288,7 @@ const useNodeDetails = (nodeId, flowId) => {
|
|
|
4245
4288
|
}, [inboundTriplesQuery.data]);
|
|
4246
4289
|
/**
|
|
4247
4290
|
* Process properties to extract unique property URIs
|
|
4248
|
-
* Properties are triples where o
|
|
4291
|
+
* Properties are triples where o is a literal (not an IRI)
|
|
4249
4292
|
*/
|
|
4250
4293
|
const propertyURIs = useMemo(() => {
|
|
4251
4294
|
if (!propertiesQuery.data)
|
|
@@ -4253,8 +4296,8 @@ const useNodeDetails = (nodeId, flowId) => {
|
|
|
4253
4296
|
// Extract unique property predicates
|
|
4254
4297
|
const uniqueProperties = new Set();
|
|
4255
4298
|
propertiesQuery.data.forEach((triple) => {
|
|
4256
|
-
if (triple.p && triple.p
|
|
4257
|
-
uniqueProperties.add(triple.p.
|
|
4299
|
+
if (triple.p && isIri(triple.p)) {
|
|
4300
|
+
uniqueProperties.add(triple.p.i);
|
|
4258
4301
|
}
|
|
4259
4302
|
});
|
|
4260
4303
|
// Convert Set to array
|
|
@@ -4283,14 +4326,14 @@ const useNodeDetails = (nodeId, flowId) => {
|
|
|
4283
4326
|
}
|
|
4284
4327
|
// If not in standard mappings, query the knowledge graph
|
|
4285
4328
|
try {
|
|
4286
|
-
const
|
|
4287
|
-
const
|
|
4329
|
+
const subjectTerm = { t: "i", i: relationshipURI };
|
|
4330
|
+
const predicateTerm = { t: "i", i: RDFS_LABEL };
|
|
4288
4331
|
const labelTriples = await socket
|
|
4289
4332
|
.flow(flowId)
|
|
4290
|
-
.triplesQuery(
|
|
4333
|
+
.triplesQuery(subjectTerm, predicateTerm, undefined, 1, settings.collection);
|
|
4291
4334
|
// Extract label from the first result, or use URI as fallback
|
|
4292
4335
|
if (labelTriples && labelTriples.length > 0 && labelTriples[0].o) {
|
|
4293
|
-
labelMap[relationshipURI] = labelTriples[0].o
|
|
4336
|
+
labelMap[relationshipURI] = getTermValue(labelTriples[0].o);
|
|
4294
4337
|
}
|
|
4295
4338
|
else {
|
|
4296
4339
|
labelMap[relationshipURI] = relationshipURI;
|
|
@@ -4328,14 +4371,14 @@ const useNodeDetails = (nodeId, flowId) => {
|
|
|
4328
4371
|
}
|
|
4329
4372
|
// If not in standard mappings, query the knowledge graph
|
|
4330
4373
|
try {
|
|
4331
|
-
const
|
|
4332
|
-
const
|
|
4374
|
+
const subjectTerm = { t: "i", i: relationshipURI };
|
|
4375
|
+
const predicateTerm = { t: "i", i: RDFS_LABEL };
|
|
4333
4376
|
const labelTriples = await socket
|
|
4334
4377
|
.flow(flowId)
|
|
4335
|
-
.triplesQuery(
|
|
4378
|
+
.triplesQuery(subjectTerm, predicateTerm, undefined, 1, settings.collection);
|
|
4336
4379
|
// Extract label from the first result, or use URI as fallback
|
|
4337
4380
|
if (labelTriples && labelTriples.length > 0 && labelTriples[0].o) {
|
|
4338
|
-
labelMap[relationshipURI] = labelTriples[0].o
|
|
4381
|
+
labelMap[relationshipURI] = getTermValue(labelTriples[0].o);
|
|
4339
4382
|
}
|
|
4340
4383
|
else {
|
|
4341
4384
|
labelMap[relationshipURI] = relationshipURI;
|
|
@@ -4373,14 +4416,14 @@ const useNodeDetails = (nodeId, flowId) => {
|
|
|
4373
4416
|
}
|
|
4374
4417
|
// If not in standard mappings, query the knowledge graph
|
|
4375
4418
|
try {
|
|
4376
|
-
const
|
|
4377
|
-
const
|
|
4419
|
+
const subjectTerm = { t: "i", i: propertyURI };
|
|
4420
|
+
const predicateTerm = { t: "i", i: RDFS_LABEL };
|
|
4378
4421
|
const labelTriples = await socket
|
|
4379
4422
|
.flow(flowId)
|
|
4380
|
-
.triplesQuery(
|
|
4423
|
+
.triplesQuery(subjectTerm, predicateTerm, undefined, 1, settings.collection);
|
|
4381
4424
|
// Extract label from the first result, or use URI as fallback
|
|
4382
4425
|
if (labelTriples && labelTriples.length > 0 && labelTriples[0].o) {
|
|
4383
|
-
labelMap[propertyURI] = labelTriples[0].o
|
|
4426
|
+
labelMap[propertyURI] = getTermValue(labelTriples[0].o);
|
|
4384
4427
|
}
|
|
4385
4428
|
else {
|
|
4386
4429
|
labelMap[propertyURI] = propertyURI;
|
|
@@ -4427,15 +4470,20 @@ const useNodeDetails = (nodeId, flowId) => {
|
|
|
4427
4470
|
return propertiesQuery.data
|
|
4428
4471
|
.filter((triple) => {
|
|
4429
4472
|
// Exclude label properties (RDFS_LABEL) since node label is already shown
|
|
4430
|
-
|
|
4473
|
+
const pUri = triple.p && isIri(triple.p) ? triple.p.i : "";
|
|
4474
|
+
return pUri !== RDFS_LABEL;
|
|
4431
4475
|
})
|
|
4432
|
-
.map((triple) =>
|
|
4433
|
-
|
|
4434
|
-
|
|
4435
|
-
|
|
4436
|
-
|
|
4437
|
-
|
|
4438
|
-
|
|
4476
|
+
.map((triple) => {
|
|
4477
|
+
const pUri = triple.p && isIri(triple.p) ? triple.p.i : "";
|
|
4478
|
+
const oValue = triple.o ? getTermValue(triple.o) : "";
|
|
4479
|
+
return {
|
|
4480
|
+
predicate: {
|
|
4481
|
+
uri: pUri,
|
|
4482
|
+
label: propertyLabelsQuery.data?.[pUri] || pUri,
|
|
4483
|
+
},
|
|
4484
|
+
value: oValue,
|
|
4485
|
+
};
|
|
4486
|
+
});
|
|
4439
4487
|
}, [propertiesQuery.data, propertyLabelsQuery.data]);
|
|
4440
4488
|
// Show loading indicators for long-running operations
|
|
4441
4489
|
useActivity(outboundTriplesQuery.isLoading ||
|
|
@@ -4523,5 +4571,5 @@ const useNodeDetails = (nodeId, flowId) => {
|
|
|
4523
4571
|
};
|
|
4524
4572
|
};
|
|
4525
4573
|
|
|
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 };
|
|
4574
|
+
export { DEFAULT_SETTINGS, NotificationProvider, RDFS_LABEL, SETTINGS_STORAGE_KEY, createDocId, fileToBase64, generateFlowBlueprintId, getTermValue$2 as getTermValue, 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 };
|
|
4527
4575
|
//# sourceMappingURL=index.esm.js.map
|