@manta-eu/client 0.2.1 → 0.4.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.
Files changed (52) hide show
  1. package/dist/generated/graphql.d.ts +176 -35
  2. package/dist/generated/graphql.d.ts.map +1 -1
  3. package/dist/generated/graphql.js +97 -14
  4. package/dist/generated/graphql.js.map +1 -1
  5. package/dist/shared/action-document.d.ts +13 -4
  6. package/dist/shared/action-document.d.ts.map +1 -1
  7. package/dist/shared/action-document.js +55 -24
  8. package/dist/shared/action-document.js.map +1 -1
  9. package/dist/shared/datastore-id.js +1 -1
  10. package/dist/shared/datastore-id.js.map +1 -1
  11. package/dist/shared/email.d.ts.map +1 -1
  12. package/dist/shared/email.js +19 -17
  13. package/dist/shared/email.js.map +1 -1
  14. package/dist/shared/memory-citation-sampling.d.ts +2 -1
  15. package/dist/shared/memory-citation-sampling.d.ts.map +1 -1
  16. package/dist/shared/memory-citation-sampling.js +5 -4
  17. package/dist/shared/memory-citation-sampling.js.map +1 -1
  18. package/dist/shared/memory-diversity.js +1 -1
  19. package/dist/shared/memory-diversity.js.map +1 -1
  20. package/dist/shared/memory-keyword-recall.d.ts +1 -0
  21. package/dist/shared/memory-keyword-recall.d.ts.map +1 -1
  22. package/dist/shared/memory-keyword-recall.js +2 -1
  23. package/dist/shared/memory-keyword-recall.js.map +1 -1
  24. package/dist/shared/rdf-namespaces.d.ts +1 -3
  25. package/dist/shared/rdf-namespaces.d.ts.map +1 -1
  26. package/dist/shared/rdf-namespaces.js +2 -4
  27. package/dist/shared/rdf-namespaces.js.map +1 -1
  28. package/dist/shared/tools/coercers.d.ts.map +1 -1
  29. package/dist/shared/tools/coercers.js +6 -3
  30. package/dist/shared/tools/coercers.js.map +1 -1
  31. package/dist/shared/tools/index.d.ts +1 -1
  32. package/dist/shared/tools/index.d.ts.map +1 -1
  33. package/dist/shared/tools/metadata.js +23 -23
  34. package/dist/shared/tools/metadata.js.map +1 -1
  35. package/dist/shared/tools/types.d.ts +24 -24
  36. package/dist/shared/tools/types.d.ts.map +1 -1
  37. package/dist/shared/writable-shape-query.js +2 -2
  38. package/dist/shared/writable-shape-query.js.map +1 -1
  39. package/package.json +5 -7
  40. package/src/generated/graphql.ts +342 -54
  41. package/src/shared/action-document.ts +88 -35
  42. package/src/shared/datastore-id.ts +1 -1
  43. package/src/shared/email.ts +23 -17
  44. package/src/shared/memory-citation-sampling.ts +5 -5
  45. package/src/shared/memory-diversity.ts +1 -1
  46. package/src/shared/memory-keyword-recall.ts +3 -1
  47. package/src/shared/rdf-namespaces.ts +2 -9
  48. package/src/shared/tools/coercers.ts +7 -4
  49. package/src/shared/tools/index.ts +8 -8
  50. package/src/shared/tools/metadata.ts +23 -23
  51. package/src/shared/tools/types.ts +30 -30
  52. package/src/shared/writable-shape-query.ts +2 -2
@@ -1,6 +1,9 @@
1
- import jsonld from "jsonld";
2
- import { encodeEntity, type Lens, type Schema } from "ldkit";
3
- import { xsd } from "ldkit/namespaces";
1
+ import { isPresent } from "@manta-eu/lib/present";
2
+ import { owlNothingIri } from "@manta-eu/rdf-lib/namespaces";
3
+ import { encodeEntity, type Identity, type Lens, type Property, type Schema, type SchemaInterface } from "ldkit";
4
+ import { rdf, xsd } from "ldkit/namespaces";
5
+ import { groupBy, uniq, uniqBy } from "ramda";
6
+ import type { GQLExecuteActionUpdateInput } from "../generated/graphql";
4
7
 
5
8
  export type DocumentTerm = { value: string; termType: string };
6
9
 
@@ -10,47 +13,97 @@ export type DocumentQuad = {
10
13
  object: DocumentTerm & { datatype?: { value: string }; language?: string };
11
14
  };
12
15
 
13
- export type InsertEntity<S extends Schema> = Parameters<Lens<S>["insert"]>[number];
16
+ type InsertEntity<S extends Schema> = Parameters<Lens<S>["insert"]>[number];
14
17
 
15
- // jsonld keeps the `_:` prefix in a blank node value
16
- function jsonldTerm(term: DocumentTerm): DocumentTerm {
17
- return { termType: term.termType, value: term.termType === "BlankNode" ? `_:${term.value}` : term.value };
18
+ export type ActionSchema = Schema & { "@type": string };
19
+
20
+ export type Writable<T> = T extends readonly (infer E)[]
21
+ ? Writable<E>[]
22
+ : T extends Record<string, unknown>
23
+ ? { [K in keyof T]?: Writable<T[K]> }
24
+ : T;
25
+
26
+ export type ActionEntity<S extends Schema> = Identity &
27
+ (string extends keyof S ? Record<string, unknown> : Writable<Omit<SchemaInterface<S>, "$id">>);
28
+
29
+ export type ActionInput = GQLExecuteActionUpdateInput;
30
+
31
+ const termKey = (term: DocumentTerm): string => (term.termType === "BlankNode" ? `_:${term.value}` : term.value);
32
+
33
+ const objectKey = ({ object }: DocumentQuad): string =>
34
+ `${termKey(object)} ${object.datatype?.value ?? ""} ${object.language ?? ""}`;
35
+
36
+ const oneOrMany = (values: readonly unknown[]): unknown => (values.length === 1 ? values[0] : values);
37
+
38
+ function literal(object: DocumentQuad["object"]): unknown {
39
+ const datatype = object.datatype?.value ?? xsd.string;
40
+
41
+ if (isPresent(object.language)) return { "@value": object.value, "@language": object.language };
42
+ if (datatype === xsd.string) return object.value;
43
+ return { "@value": object.value, "@type": datatype };
18
44
  }
19
45
 
20
- function jsonldQuad(quad: DocumentQuad) {
21
- const { subject, predicate, object } = quad;
22
-
23
- return {
24
- subject: jsonldTerm(subject),
25
- predicate: { termType: "NamedNode", value: predicate.value },
26
- object:
27
- object.termType === "Literal"
28
- ? {
29
- termType: "Literal",
30
- value: object.value,
31
- language: object.language,
32
- datatype: { value: object.datatype?.value ?? xsd.string },
33
- }
34
- : jsonldTerm(object),
35
- graph: { termType: "DefaultGraph", value: "" },
46
+ export function documentFromQuads(quads: readonly DocumentQuad[], subjectIri: string): Record<string, unknown> {
47
+ const described = quads.filter(({ subject }) => subject.value === subjectIri || subject.termType === "BlankNode");
48
+ const bySubject = groupBy((quad: DocumentQuad) => termKey(quad.subject), described);
49
+ const blankObjects = described.flatMap(({ object }) => (object.termType === "BlankNode" ? [termKey(object)] : []));
50
+ const shared = new Set(blankObjects.filter((key, index) => blankObjects.indexOf(key) !== index));
51
+ const labels = new Map<string, string>();
52
+
53
+ const label = (key: string): string => {
54
+ if (!labels.has(key)) labels.set(key, `_:b${labels.size}`);
55
+ return labels.get(key) ?? key;
36
56
  };
57
+
58
+ const value = (object: DocumentQuad["object"], path: readonly string[]): unknown => {
59
+ const key = termKey(object);
60
+
61
+ if (object.termType === "Literal") return literal(object);
62
+ if (object.termType !== "BlankNode") return { "@id": key };
63
+ if (path.includes(key)) return { "@id": label(key) };
64
+ return node(key, [...path, key]);
65
+ };
66
+
67
+ const node = (key: string, path: readonly string[]): Record<string, unknown> => {
68
+ const own = bySubject[key] ?? [];
69
+ const types = own.filter(({ predicate }) => predicate.value === rdf.type).map(({ object }) => termKey(object));
70
+ const others = own.filter(({ predicate }) => predicate.value !== rdf.type);
71
+ const byPredicate = groupBy((quad: DocumentQuad) => quad.predicate.value, others);
72
+
73
+ return {
74
+ ...(shared.has(key) && { "@id": label(key) }),
75
+ ...(isPresent(types) && { "@type": oneOrMany(uniq(types)) }),
76
+ ...Object.fromEntries(
77
+ Object.entries(byPredicate).map(([predicate, values = []]) => [
78
+ predicate,
79
+ oneOrMany(uniqBy(objectKey, values).map(({ object }) => value(object, path))),
80
+ ]),
81
+ ),
82
+ };
83
+ };
84
+
85
+ return { "@id": subjectIri, ...node(subjectIri, [subjectIri]) };
37
86
  }
38
87
 
39
- export async function documentFromQuads(
40
- quads: readonly DocumentQuad[],
41
- subjectIri: string,
42
- ): Promise<Record<string, unknown>> {
43
- const described = quads.filter(({ subject }) => subject.value === subjectIri || subject.termType === "BlankNode");
44
- const flattened = await jsonld.fromRDF(described.map(jsonldQuad));
88
+ export function entityActionDocument<S extends Schema>(schema: S, entity: ActionEntity<S>): Record<string, unknown> {
89
+ const quads = encodeEntity(schema, entity as unknown as InsertEntity<S>).filter(
90
+ (quad) => quad.object.termType !== "Variable",
91
+ );
45
92
 
46
- return jsonld.frame(flattened, { "@id": subjectIri, "@embed": "@always" });
93
+ return documentFromQuads(quads, entity.$id);
47
94
  }
48
95
 
49
- export function entityActionDocument<S extends Schema>(
96
+ const propertyIri = (definition: Property | string | readonly string[] | undefined): string =>
97
+ typeof definition === "object" && "@id" in definition ? definition["@id"] : String(definition);
98
+
99
+ export function entityActionInput<S extends ActionSchema>(
50
100
  schema: S,
51
- entity: InsertEntity<S>,
52
- ): Promise<Record<string, unknown>> {
53
- const quads = encodeEntity(schema, entity).filter((quad) => quad.object.termType !== "Variable");
101
+ actionShape: string,
102
+ entity: ActionEntity<S>,
103
+ cleared: readonly (Exclude<keyof S, "@type"> & string)[] = [],
104
+ ): ActionInput {
105
+ const document = entityActionDocument(schema, entity);
106
+ const nothing = Object.fromEntries(cleared.map((key) => [propertyIri(schema[key]), { "@id": owlNothingIri }]));
54
107
 
55
- return documentFromQuads(quads, entity.$id);
108
+ return { subjectIri: entity.$id, rdfType: schema["@type"], actionShape, properties: { ...document, ...nothing } };
56
109
  }
@@ -17,7 +17,7 @@ export function deriveDatastoreId(organizationName: string, segments: string[]):
17
17
  );
18
18
  }
19
19
 
20
- // Validated before reaching Infisical/KGC/RDFox since the Keycloak attribute is admin-settable.
20
+ // Validated before reaching Infisical, KGC or the datastore, since the Keycloak attribute is admin-settable.
21
21
  const datastoreIdPattern = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
22
22
 
23
23
  export function isValidDatastoreId(id: string): boolean {
@@ -1,6 +1,9 @@
1
- import { nco, nmo } from "@manta-eu/ldo/namespaces";
1
+ import { NcoEmailAddressSchema } from "@manta-eu/ldo/schemas/nco";
2
+ import { NmoEmailSchema } from "@manta-eu/ldo/schemas/nmo";
2
3
  import { isPresent } from "@manta-eu/lib/present";
4
+ import type { Schema } from "ldkit";
3
5
  import { ExecuteAgentActionAdditionDocument, type GQLExecuteAgentActionAdditionMutation } from "../generated/graphql";
6
+ import { entityActionInput } from "./action-document";
4
7
 
5
8
  export type EmailGraphql = (document: string, variables: Record<string, unknown>) => Promise<unknown>;
6
9
 
@@ -16,22 +19,25 @@ export type RenderedEmail = {
16
19
 
17
20
  export type EmailStart = { ok: true; plan: string } | { ok: false; error: string };
18
21
 
19
- function renderedEmailAddition(terms: RealmEmailTerms, email: RenderedEmail) {
20
- return {
21
- subjectIri: email.subjectIri,
22
- rdfType: nmo.Email,
23
- actionShape: terms.emailMessageShape,
24
- properties: {
25
- "@id": email.subjectIri,
26
- "@type": nmo.Email,
27
- [nmo.messageFrom]: { "@type": nco.EmailAddress, [nco.emailAddress]: email.from },
28
- [nmo.emailTo]: { "@type": nco.EmailAddress, [nco.emailAddress]: email.to },
29
- [nmo.messageSubject]: email.subject,
30
- [nmo.contentMimeType]: "text/html",
31
- [terms.renderedFrom]: { "@id": email.renderedFrom },
32
- },
33
- };
34
- }
22
+ const renderedEmailSchema = (terms: RealmEmailTerms) =>
23
+ ({
24
+ "@type": NmoEmailSchema["@type"],
25
+ from: { "@id": NmoEmailSchema.messageFrom["@id"], "@schema": NcoEmailAddressSchema },
26
+ to: { "@id": NmoEmailSchema.emailTo["@id"], "@schema": NcoEmailAddressSchema },
27
+ subject: NmoEmailSchema.messageSubject,
28
+ contentMimeType: NmoEmailSchema.contentMimeType,
29
+ renderedFrom: { ...NmoEmailSchema.renderedFrom, "@id": terms.renderedFrom },
30
+ }) as const satisfies Schema;
31
+
32
+ const renderedEmailAddition = (terms: RealmEmailTerms, email: RenderedEmail) =>
33
+ entityActionInput(renderedEmailSchema(terms), terms.emailMessageShape, {
34
+ $id: email.subjectIri,
35
+ from: { emailAddress: email.from },
36
+ to: { emailAddress: email.to },
37
+ subject: email.subject,
38
+ contentMimeType: "text/html",
39
+ renderedFrom: email.renderedFrom,
40
+ });
35
41
 
36
42
  export async function startRenderedEmail(
37
43
  graphql: EmailGraphql,
@@ -9,18 +9,18 @@ export function shouldRequestCitations(seed: string, rate: number = memoryCitati
9
9
 
10
10
  export type CitationRequestTurn = {
11
11
  hasPersonalPreload: boolean;
12
+ hasPersonalRecall: boolean;
12
13
  hasSharedSections: boolean;
13
14
  seed: string;
14
15
  };
15
16
 
16
17
  export type CitationDecision =
17
18
  | { requested: false; reason: "none" }
18
- | { requested: true; reason: "personal" | "sampled" };
19
+ | { requested: true; reason: "personal" | "recalled" | "sampled" };
19
20
 
20
21
  export function citationDecisionForTurn(turn: CitationRequestTurn, rate?: number): CitationDecision {
21
22
  if (turn.hasPersonalPreload) return { requested: true, reason: "personal" };
22
- if (turn.hasSharedSections && shouldRequestCitations(turn.seed, rate)) {
23
- return { requested: true, reason: "sampled" };
24
- }
25
- return { requested: false, reason: "none" };
23
+ if (!turn.hasPersonalRecall && !turn.hasSharedSections) return { requested: false, reason: "none" };
24
+ if (!shouldRequestCitations(turn.seed, rate)) return { requested: false, reason: "none" };
25
+ return { requested: true, reason: turn.hasPersonalRecall ? "recalled" : "sampled" };
26
26
  }
@@ -7,7 +7,7 @@ export type DiversityCandidate = {
7
7
  description?: string | null;
8
8
  };
9
9
 
10
- const tokenPattern = /[a-z0-9]+/g;
10
+ const tokenPattern = /[\p{L}\p{N}]+/gu;
11
11
 
12
12
  const minimumTokenLength = 3;
13
13
 
@@ -5,6 +5,8 @@ export const rankFusionConstant = 60;
5
5
 
6
6
  export const maxKeywordTerms = 8;
7
7
 
8
+ export const maxKeywordTermLength = 40;
9
+
8
10
  export type KeywordCandidate = DiversityCandidate & { iri: string };
9
11
 
10
12
  // A term feeds a SPARQL CONTAINS that admits rows, so a stray function word like "the" would widen the pool to the
@@ -103,7 +105,7 @@ const stopWords = new Set([
103
105
 
104
106
  export function keywordTerms(text: string, limit: number = maxKeywordTerms): string[] {
105
107
  return [...memoryTokens({ label: text })]
106
- .filter((token) => !stopWords.has(token))
108
+ .filter((token) => !stopWords.has(token) && token.length <= maxKeywordTermLength)
107
109
  .sort((a, b) => b.length - a.length || a.localeCompare(b))
108
110
  .slice(0, limit);
109
111
  }
@@ -3,12 +3,8 @@ import {
3
3
  expandPrefix as expandPrefixIri,
4
4
  iriLocalName as iriLocalNameValue,
5
5
  iriNamespace as iriNamespaceValue,
6
- rdfoxDefaultBaseIri as rdfoxDefaultBaseIriValue,
7
- shaclGraphIri as shaclGraphIriValue,
8
6
  } from "@manta-eu/rdf-lib/namespaces";
9
7
 
10
- export const rulesGraphIri = `${rdfoxDefaultBaseIriValue}rules`;
11
-
12
8
  // KGC uploads the realm ontology here (kgc/kgc/realms/lib/ontology.py: realm_base + "ontology").
13
9
  export const ontologyGraphIri = expandPrefixIri(":ontology");
14
10
 
@@ -19,8 +15,6 @@ export const writeLifecycle = {
19
15
  createOnly: expandPrefixIri("relay:CreateOnly"),
20
16
  };
21
17
 
22
- export const nonDataGraphIris = [ontologyGraphIri, shaclGraphIriValue, rulesGraphIri];
23
-
24
18
  export function mintInstanceIri(classIri: string, localId: string): string {
25
19
  return `${iriNamespaceValue(classIri)}${encodeIriLocalNameValue(`${iriLocalNameValue(classIri)}_${localId}`)}`;
26
20
  }
@@ -33,7 +27,7 @@ export {
33
27
  encodeIriUnsafeChars,
34
28
  expandPrefix,
35
29
  formatEntityName,
36
- formatIriForRdfox,
30
+ formatIriForSparql,
37
31
  getNamespaceValues,
38
32
  isFullIri,
39
33
  isValidFullIri,
@@ -52,8 +46,7 @@ export {
52
46
  nfo,
53
47
  parseEntityUri,
54
48
  prependMissingSparqlPrefixes,
55
- rdfoxDefaultBaseIri,
56
- shaclGraphIri,
49
+ shaclGraph,
57
50
  sh,
58
51
  toTurtlePrefixes,
59
52
  validateFullIri,
@@ -1,5 +1,5 @@
1
1
  import type {
2
- RDFoxFactsOutput,
2
+ QueryKnowledgeGraphOutput,
3
3
  ShowEntitiesOutput,
4
4
  SparqlJsonResults,
5
5
  ToolErrorResult,
@@ -43,8 +43,11 @@ function coerceWith<T>(
43
43
  return { is_error: true, content: `Unexpected ${toolName} output format` };
44
44
  }
45
45
 
46
- function coerceRDFoxFactsOutput(raw: unknown): RDFoxFactsOutput {
47
- return coerceWith<RDFoxFactsOutput>("getRDFoxFacts", raw, [isSparqlJsonResults, isJsonLdGraphDocument]);
46
+ function coerceQueryKnowledgeGraphOutput(raw: unknown): QueryKnowledgeGraphOutput {
47
+ return coerceWith<QueryKnowledgeGraphOutput>("queryKnowledgeGraph", raw, [
48
+ isSparqlJsonResults,
49
+ isJsonLdGraphDocument,
50
+ ]);
48
51
  }
49
52
 
50
53
  export function isShowEntitiesResult(data: unknown): data is Exclude<ShowEntitiesOutput, ToolErrorResult> {
@@ -62,7 +65,7 @@ function coerceShowEntitiesOutput(raw: unknown): ShowEntitiesOutput {
62
65
  }
63
66
 
64
67
  const coercers: Partial<Record<ToolName, ToolOutputCoercer<ToolName>>> = {
65
- getRDFoxFacts: coerceRDFoxFactsOutput as ToolOutputCoercer<"getRDFoxFacts">,
68
+ queryKnowledgeGraph: coerceQueryKnowledgeGraphOutput as ToolOutputCoercer<"queryKnowledgeGraph">,
66
69
  showEntities: coerceShowEntitiesOutput as ToolOutputCoercer<"showEntities">,
67
70
  };
68
71
 
@@ -13,22 +13,22 @@ export type {
13
13
  ActionPlanShowcaseInput,
14
14
  ActionPlanShowcaseOutput,
15
15
  ActionPlanStatus,
16
- AddRDFoxFactsInput,
17
- AddRDFoxFactsOutput,
16
+ AddFactsInput,
17
+ AddFactsOutput,
18
18
  CancelScheduleInput,
19
19
  CancelScheduleOutput,
20
20
  ExecuteActionPlanInput,
21
21
  ExecuteActionPlanOutput,
22
- ExplainRDFoxRulesInput,
23
- ExplainRDFoxRulesOutput,
22
+ ExplainFactToolInput,
23
+ ExplainFactToolOutput,
24
24
  GenerateChartInput,
25
25
  GenerateChartOutput,
26
- GetRDFoxRulesInput,
27
- GetRDFoxRulesOutput,
26
+ GetRulesInput,
27
+ GetRulesOutput,
28
28
  ListScheduledTasksInput,
29
29
  ListScheduledTasksOutput,
30
- RDFoxFactsInput,
31
- RDFoxFactsOutput,
30
+ QueryKnowledgeGraphInput,
31
+ QueryKnowledgeGraphOutput,
32
32
  ScheduleTaskInput,
33
33
  ScheduleTaskOutput,
34
34
  ShowEntitiesInput,
@@ -6,30 +6,30 @@ import { iriLocalName } from "../rdf-namespaces";
6
6
  import type { ToolMetadata, ToolName } from "./types";
7
7
 
8
8
  export const toolMetadata: ToolMetadata = {
9
- getRDFoxFacts: {
10
- name: "getRDFoxFacts",
11
- category: "rdfox",
9
+ queryKnowledgeGraph: {
10
+ name: "queryKnowledgeGraph",
11
+ category: "knowledge-graph",
12
12
  humanName: "Query knowledge base",
13
- description: "Retrieve facts from RDFox knowledge base using SPARQL",
13
+ description: "Retrieve facts from the knowledge graph using SPARQL",
14
14
  getHumanName: (input) => {
15
15
  return input?.humanIntent || "Querying...";
16
16
  },
17
17
  },
18
- addRDFoxFacts: {
19
- name: "addRDFoxFacts",
20
- category: "rdfox",
18
+ addFacts: {
19
+ name: "addFacts",
20
+ category: "knowledge-graph",
21
21
  humanName: "Add facts",
22
- description: "Add facts to RDFox knowledge base as Turtle",
22
+ description: "Add facts to the knowledge graph as Turtle",
23
23
  getHumanName: (input) => {
24
24
  return input?.humanIntent || "Adding facts...";
25
25
  },
26
26
  },
27
- getRDFoxRules: {
28
- name: "getRDFoxRules",
29
- category: "rdfox",
27
+ getRules: {
28
+ name: "getRules",
29
+ category: "knowledge-graph",
30
30
  humanName: "Check rules",
31
31
  description:
32
- "Retrieve Datalog rules from RDFox with optional filters (named graph, rdf:type, limit) to avoid context overflow",
32
+ "Retrieve Datalog rules from the knowledge graph with optional filters (named graph, rdf:type, limit) to avoid context overflow",
33
33
  getHumanName: (input) => {
34
34
  const parts: string[] = [];
35
35
  if (input?.namedGraphIri) parts.push(`plan: ${input.namedGraphIri}`);
@@ -38,9 +38,9 @@ export const toolMetadata: ToolMetadata = {
38
38
  return `Checking rules ${parts.join(" + ")}`;
39
39
  },
40
40
  },
41
- explainRDFoxRules: {
42
- name: "explainRDFoxRules",
43
- category: "rdfox",
41
+ explainFact: {
42
+ name: "explainFact",
43
+ category: "knowledge-graph",
44
44
  humanName: "Explain reasoning",
45
45
  description: "Explain how facts are derived using rules",
46
46
  getHumanName: () => "Explaining reasoning...",
@@ -88,20 +88,20 @@ export const toolMetadata: ToolMetadata = {
88
88
  return input?.namedGraphIri ? `Execute plan: ${input.namedGraphIri}` : "Executing action plan...";
89
89
  },
90
90
  },
91
- manageRDFoxRules: {
92
- name: "manageRDFoxRules",
93
- category: "rdfox",
91
+ manageRules: {
92
+ name: "manageRules",
93
+ category: "knowledge-graph",
94
94
  humanName: "Manage rules",
95
- description: "Add, change, or remove Datalog rules in RDFox knowledge base",
95
+ description: "Add, change, or remove Datalog rules in the knowledge graph",
96
96
  getHumanName: (input) => {
97
97
  return input?.humanIntent || "Managing rules...";
98
98
  },
99
99
  },
100
- manageRDFoxFacts: {
101
- name: "manageRDFoxFacts",
102
- category: "rdfox",
100
+ manageFacts: {
101
+ name: "manageFacts",
102
+ category: "knowledge-graph",
103
103
  humanName: "Manage facts",
104
- description: "Add, change facts in RDFox knowledge",
104
+ description: "Add or change facts in the knowledge graph",
105
105
  getHumanName: (input) => {
106
106
  return input?.humanIntent || "Managing facts...";
107
107
  },
@@ -10,17 +10,17 @@ export type { TestTripleInput };
10
10
  export type SparqlJsonBinding = SparqlBinding;
11
11
 
12
12
  export type ToolName =
13
- | "getRDFoxFacts"
14
- | "addRDFoxFacts"
15
- | "getRDFoxRules"
16
- | "explainRDFoxRules"
13
+ | "queryKnowledgeGraph"
14
+ | "addFacts"
15
+ | "getRules"
16
+ | "explainFact"
17
17
  | "scheduleTask"
18
18
  | "listScheduledTasks"
19
19
  | "cancelSchedule"
20
20
  | "generateChart"
21
21
  | "executeActionPlan"
22
- | "manageRDFoxRules"
23
- | "manageRDFoxFacts"
22
+ | "manageRules"
23
+ | "manageFacts"
24
24
  | "actionPlanShowcase"
25
25
  | "showEntities"
26
26
  | "checkAutoPilotStatus"
@@ -28,7 +28,7 @@ export type ToolName =
28
28
  | "markAsLowRisk"
29
29
  | "readUploadedFile";
30
30
 
31
- export type ToolCategory = "rdfox" | "scheduler" | "charts" | "action" | "auto-pilot";
31
+ export type ToolCategory = "knowledge-graph" | "scheduler" | "charts" | "action" | "auto-pilot";
32
32
 
33
33
  export type ToolInputSchema<T = unknown> = z.ZodSchema<T>;
34
34
 
@@ -39,36 +39,36 @@ export type ToolErrorResult = {
39
39
  content: string;
40
40
  };
41
41
 
42
- export type RDFoxFactsInput = {
42
+ export type QueryKnowledgeGraphInput = {
43
43
  humanIntent: string;
44
44
  sparql: string;
45
45
  keepPrefixes?: boolean;
46
46
  };
47
47
 
48
- export type RDFoxFactsOutput = JsonLdGraphDocument | SparqlJsonResults | ToolErrorResult;
48
+ export type QueryKnowledgeGraphOutput = JsonLdGraphDocument | SparqlJsonResults | ToolErrorResult;
49
49
 
50
- export type AddRDFoxFactsInput = {
50
+ export type AddFactsInput = {
51
51
  facts: string;
52
52
  humanIntent: string;
53
53
  };
54
54
 
55
- export type AddRDFoxFactsOutput = string | ToolErrorResult;
55
+ export type AddFactsOutput = string | ToolErrorResult;
56
56
 
57
- export type GetRDFoxRulesInput = {
57
+ export type GetRulesInput = {
58
58
  namedGraphIri?: string;
59
59
  rdfTypes?: string[];
60
60
  limit?: number;
61
61
  };
62
62
 
63
- export type GetRDFoxRulesOutputSuccess = {
63
+ export type GetRulesOutputSuccess = {
64
64
  rules: string[] | string | Record<string, unknown>[]; // TODO: standardize on RuleInfo type
65
65
  totalCount: number;
66
66
  truncated?: boolean;
67
67
  };
68
68
 
69
- export type GetRDFoxRulesOutput = GetRDFoxRulesOutputSuccess | ToolErrorResult;
69
+ export type GetRulesOutput = GetRulesOutputSuccess | ToolErrorResult;
70
70
 
71
- export type ExplainRDFoxRulesInput = {
71
+ export type ExplainFactToolInput = {
72
72
  subject: string;
73
73
  predicate?: string;
74
74
  object: string;
@@ -76,7 +76,7 @@ export type ExplainRDFoxRulesInput = {
76
76
 
77
77
  export type ToolObjectOutput = object | ToolErrorResult;
78
78
 
79
- export type ExplainRDFoxRulesOutput = ToolObjectOutput;
79
+ export type ExplainFactToolOutput = ToolObjectOutput;
80
80
 
81
81
  export type ScheduleTaskInput = {
82
82
  when: "scheduled" | "delayed" | "cron";
@@ -151,7 +151,7 @@ export type ExecuteActionPlanOutput =
151
151
  }
152
152
  | ToolErrorResult;
153
153
 
154
- export type ManageRDFoxRulesInput = {
154
+ export type ManageRulesInput = {
155
155
  humanIntent: string;
156
156
  operation: "add" | "change" | "remove";
157
157
  ruleIri?: string;
@@ -161,17 +161,17 @@ export type ManageRDFoxRulesInput = {
161
161
  dryRun?: boolean;
162
162
  stageOnly?: boolean;
163
163
  };
164
- export type ManageRDFoxRulesSuccess = {
164
+ export type ManageRulesSuccess = {
165
165
  success: true;
166
166
  ruleIri: string;
167
167
  parsedRule: DatalogRule | null;
168
168
  content: string;
169
169
  };
170
170
 
171
- export type ManageRDFoxRulesOutput =
172
- | (ManageRDFoxRulesSuccess & { dryRun: true })
173
- | (ManageRDFoxRulesSuccess & { staged: true })
174
- | (ManageRDFoxRulesSuccess & {
171
+ export type ManageRulesOutput =
172
+ | (ManageRulesSuccess & { dryRun: true })
173
+ | (ManageRulesSuccess & { staged: true })
174
+ | (ManageRulesSuccess & {
175
175
  ruleText: string;
176
176
  inferenceVerified: boolean;
177
177
  inferenceVerification: InferenceVerificationResult | null;
@@ -183,7 +183,7 @@ export type ManageRDFoxRulesOutput =
183
183
  })
184
184
  | ToolErrorResult;
185
185
 
186
- export type ManageRDFoxFactsInput = {
186
+ export type ManageFactsInput = {
187
187
  humanIntent: string;
188
188
  facts: string;
189
189
  namedGraphIri?: string;
@@ -191,7 +191,7 @@ export type ManageRDFoxFactsInput = {
191
191
  etag?: string;
192
192
  };
193
193
 
194
- export type ManageRDFoxFactsOutput =
194
+ export type ManageFactsOutput =
195
195
  | {
196
196
  content: string;
197
197
  is_error: boolean;
@@ -265,17 +265,17 @@ export type AutoPilotOutput = ({ success: true } & AutoPilotActionPlan) | ToolEr
265
265
  export type CheckAutoPilotStatusOutput = AutoPilotActionPlan | ToolErrorResult;
266
266
 
267
267
  export type ToolDefinitions = {
268
- getRDFoxFacts: ToolDefinition<RDFoxFactsInput, RDFoxFactsOutput>;
269
- addRDFoxFacts: ToolDefinition<AddRDFoxFactsInput, AddRDFoxFactsOutput>;
270
- getRDFoxRules: ToolDefinition<GetRDFoxRulesInput, GetRDFoxRulesOutput>;
271
- explainRDFoxRules: ToolDefinition<ExplainRDFoxRulesInput, ExplainRDFoxRulesOutput>;
268
+ queryKnowledgeGraph: ToolDefinition<QueryKnowledgeGraphInput, QueryKnowledgeGraphOutput>;
269
+ addFacts: ToolDefinition<AddFactsInput, AddFactsOutput>;
270
+ getRules: ToolDefinition<GetRulesInput, GetRulesOutput>;
271
+ explainFact: ToolDefinition<ExplainFactToolInput, ExplainFactToolOutput>;
272
272
  scheduleTask: ToolDefinition<ScheduleTaskInput, ScheduleTaskOutput>;
273
273
  listScheduledTasks: ToolDefinition<ListScheduledTasksInput, ListScheduledTasksOutput>;
274
274
  cancelSchedule: ToolDefinition<CancelScheduleInput, CancelScheduleOutput>;
275
275
  generateChart: ToolDefinition<GenerateChartInput, GenerateChartOutput>;
276
276
  executeActionPlan: ToolDefinition<ExecuteActionPlanInput, ExecuteActionPlanOutput>;
277
- manageRDFoxRules: ToolDefinition<ManageRDFoxRulesInput, ManageRDFoxRulesOutput>;
278
- manageRDFoxFacts: ToolDefinition<ManageRDFoxFactsInput, ManageRDFoxFactsOutput>;
277
+ manageRules: ToolDefinition<ManageRulesInput, ManageRulesOutput>;
278
+ manageFacts: ToolDefinition<ManageFactsInput, ManageFactsOutput>;
279
279
  actionPlanShowcase: ToolDefinition<ActionPlanShowcaseInput, ActionPlanShowcaseOutput>;
280
280
  showEntities: ToolDefinition<ShowEntitiesInput, ShowEntitiesOutput>;
281
281
  checkAutoPilotStatus: ToolDefinition<AutoPilotInput, CheckAutoPilotStatusOutput>;
@@ -1,6 +1,6 @@
1
1
  import { DataFactory } from "ldkit/rdf";
2
2
  import { SELECT } from "ldkit/sparql";
3
- import { sh, shaclGraphIri, writeLifecycle } from "./rdf-namespaces";
3
+ import { sh, shaclGraph, writeLifecycle } from "./rdf-namespaces";
4
4
 
5
5
  const dataFactory = new DataFactory();
6
6
  const property = dataFactory.namedNode(sh.property);
@@ -12,7 +12,7 @@ export function buildActionShapePropertyQuery(actionShapeIris: string[]): string
12
12
  const actionShapes = actionShapeIris.map((iri) => dataFactory.namedNode(iri));
13
13
 
14
14
  return SELECT`DISTINCT ?actionShape ?parent ?path ?node ?flag`.WHERE`
15
- GRAPH ${dataFactory.namedNode(shaclGraphIri)} {
15
+ GRAPH ${dataFactory.namedNode(shaclGraph)} {
16
16
  VALUES ?actionShape { ${actionShapes} }
17
17
  ?actionShape (${property}/${node})* ?parent .
18
18
  ?parent ${property} ?propertyShape .