@dxos/react-ui-rdf 0.0.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/LICENSE ADDED
@@ -0,0 +1,105 @@
1
+ # Functional Source License, Version 1.1, ALv2 Future License
2
+
3
+ ## Abbreviation
4
+
5
+ FSL-1.1-Apache-2.0
6
+
7
+ ## Notice
8
+
9
+ Copyright 2026 DXOS
10
+
11
+ ## Terms and Conditions
12
+
13
+ ### Licensor ("We")
14
+
15
+ The party offering the Software under these Terms and Conditions.
16
+
17
+ ### The Software
18
+
19
+ The "Software" is each version of the software that we make available under
20
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
21
+ Conditions with the Software.
22
+
23
+ ### License Grant
24
+
25
+ Subject to your compliance with this License Grant and the Patents,
26
+ Redistribution and Trademark clauses below, we hereby grant you the right to
27
+ use, copy, modify, create derivative works, publicly perform, publicly display
28
+ and redistribute the Software for any Permitted Purpose identified below.
29
+
30
+ ### Permitted Purpose
31
+
32
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
33
+ means making the Software available to others in a commercial product or
34
+ service that:
35
+
36
+ 1. substitutes for the Software;
37
+
38
+ 2. substitutes for any other product or service we offer using the Software
39
+ that exists as of the date we make the Software available; or
40
+
41
+ 3. offers the same or substantially similar functionality as the Software.
42
+
43
+ Permitted Purposes specifically include using the Software:
44
+
45
+ 1. for your internal use and access;
46
+
47
+ 2. for non-commercial education;
48
+
49
+ 3. for non-commercial research; and
50
+
51
+ 4. in connection with professional services that you provide to a licensee
52
+ using the Software in accordance with these Terms and Conditions.
53
+
54
+ ### Patents
55
+
56
+ To the extent your use for a Permitted Purpose would necessarily infringe our
57
+ patents, the license grant above includes a license under our patents. If you
58
+ make a claim against any party that the Software infringes or contributes to
59
+ the infringement of any patent, then your patent license to the Software ends
60
+ immediately.
61
+
62
+ ### Redistribution
63
+
64
+ The Terms and Conditions apply to all copies, modifications and derivatives of
65
+ the Software.
66
+
67
+ If you redistribute any copies, modifications or derivatives of the Software,
68
+ you must include a copy of or a link to these Terms and Conditions and not
69
+ remove any copyright notices provided in or with the Software.
70
+
71
+ ### Disclaimer
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
74
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
75
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
76
+
77
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
78
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
79
+ EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
80
+
81
+ ### Trademarks
82
+
83
+ Except for displaying the License Details and identifying us as the origin of
84
+ the Software, you have no right under these Terms and Conditions to use our
85
+ trademarks, trade names, service marks or product names.
86
+
87
+ ## Grant of Future License
88
+
89
+ We hereby irrevocably grant you an additional license to use the Software under
90
+ the Apache License, Version 2.0 that is effective on the second anniversary of
91
+ the date we make the Software available. On or after that date, you may use the
92
+ Software under the Apache License, Version 2.0, in which case the following
93
+ will apply:
94
+
95
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
96
+ this file except in compliance with the License.
97
+
98
+ You may obtain a copy of the License at
99
+
100
+ http://www.apache.org/licenses/LICENSE-2.0
101
+
102
+ Unless required by applicable law or agreed to in writing, software distributed
103
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
104
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
105
+ specific language governing permissions and limitations under the License.
@@ -0,0 +1,249 @@
1
+ // src/FactViewer.tsx
2
+ import React, { useMemo, useState } from "react";
3
+ import { buildFactGraph, factSourceFromFacts } from "@dxos/pipeline-rdf";
4
+ import { Icon, IconButton, Input, Panel, ScrollArea, Tag, Toolbar } from "@dxos/react-ui";
5
+ import { Tree } from "@dxos/react-ui-graph";
6
+ import { Empty, Listbox } from "@dxos/react-ui-list";
7
+ import { mx } from "@dxos/ui-theme";
8
+
9
+ // src/types.ts
10
+ var groupFacts = (facts, filter) => {
11
+ const needle = filter.trim().toLowerCase();
12
+ const filtered = needle ? facts.filter((fact) => {
13
+ const { subject, predicate, object } = fact.assertion;
14
+ return [
15
+ formatTerm(subject),
16
+ predicate,
17
+ formatTerm(object)
18
+ ].some((value) => value.toLowerCase().includes(needle));
19
+ }) : facts;
20
+ const bySubject = /* @__PURE__ */ new Map();
21
+ const labelByKey = /* @__PURE__ */ new Map();
22
+ for (const fact of filtered) {
23
+ const key = termKey(fact.assertion.subject);
24
+ const list = bySubject.get(key) ?? [];
25
+ list.push(fact);
26
+ bySubject.set(key, list);
27
+ if (!labelByKey.has(key)) {
28
+ labelByKey.set(key, formatTerm(fact.assertion.subject));
29
+ }
30
+ }
31
+ return [
32
+ ...bySubject.entries()
33
+ ].map(([key, groupFactsList]) => {
34
+ const subject = labelByKey.get(key) ?? key;
35
+ const byPredicate = /* @__PURE__ */ new Map();
36
+ for (const fact of groupFactsList) {
37
+ const list = byPredicate.get(fact.assertion.predicate) ?? [];
38
+ list.push(fact);
39
+ byPredicate.set(fact.assertion.predicate, list);
40
+ }
41
+ const conflictedIds = /* @__PURE__ */ new Set();
42
+ for (const list of byPredicate.values()) {
43
+ const objects = new Set(list.map((fact) => termKey(fact.assertion.object)));
44
+ if (objects.size > 1) {
45
+ for (const fact of list) {
46
+ conflictedIds.add(fact.id);
47
+ }
48
+ }
49
+ }
50
+ return {
51
+ subject,
52
+ facts: groupFactsList,
53
+ conflicted: conflictedIds.size > 0,
54
+ conflictedIds
55
+ };
56
+ });
57
+ };
58
+ var termKey = (term) => "entity" in term ? term.entity : term.literal;
59
+ var formatTerm = (term) => "entity" in term ? term.label ?? humanize(term.entity) : term.literal;
60
+ var graphToTreeNode = (graph, rootId) => {
61
+ const nodeById = new Map(graph.nodes.map((node) => [
62
+ node.id,
63
+ node
64
+ ]));
65
+ if (!nodeById.has(rootId)) {
66
+ return void 0;
67
+ }
68
+ const adjacency = /* @__PURE__ */ new Map();
69
+ const link = (from, to) => {
70
+ const list = adjacency.get(from) ?? [];
71
+ list.push(to);
72
+ adjacency.set(from, list);
73
+ };
74
+ for (const edge of graph.edges) {
75
+ link(edge.source, edge.target);
76
+ link(edge.target, edge.source);
77
+ }
78
+ const visited = /* @__PURE__ */ new Set([
79
+ rootId
80
+ ]);
81
+ const build = (id) => {
82
+ const children = [];
83
+ for (const neighbour of adjacency.get(id) ?? []) {
84
+ if (!visited.has(neighbour)) {
85
+ visited.add(neighbour);
86
+ children.push(build(neighbour));
87
+ }
88
+ }
89
+ return {
90
+ id,
91
+ label: nodeById.get(id)?.label ?? id,
92
+ ...children.length > 0 ? {
93
+ children
94
+ } : {}
95
+ };
96
+ };
97
+ return build(rootId);
98
+ };
99
+ var humanize = (value) => value.replace(/[-_]/g, " ").replace(/\b\w/g, (char) => char.toUpperCase());
100
+ var formatDate = (iso) => iso.slice(0, 10);
101
+ var factualityColor = (factuality) => {
102
+ switch (factuality) {
103
+ case "CT+":
104
+ return "emerald";
105
+ case "PR+":
106
+ return "amber";
107
+ case "PS+":
108
+ return "sky";
109
+ case "CT-":
110
+ case "PR-":
111
+ case "PS-":
112
+ return "red";
113
+ case "CTu":
114
+ case "Uu":
115
+ default:
116
+ return "neutral";
117
+ }
118
+ };
119
+
120
+ // src/FactViewer.tsx
121
+ var FactViewer = ({ classNames, facts, context, predicate }) => {
122
+ const [filter, setFilter] = useState("");
123
+ const [view, setView] = useState("list");
124
+ const scoped = useMemo(() => facts.filter((fact) => (context == null || termKey(fact.assertion.subject) === context || termKey(fact.assertion.object) === context) && (predicate == null || fact.assertion.predicate === predicate)), [
125
+ facts,
126
+ context,
127
+ predicate
128
+ ]);
129
+ const groups = useMemo(() => groupFacts(scoped, filter), [
130
+ scoped,
131
+ filter
132
+ ]);
133
+ const graph = useMemo(() => context == null ? void 0 : graphToTreeNode(buildFactGraph(context, factSourceFromFacts(facts)), context), [
134
+ facts,
135
+ context
136
+ ]);
137
+ return /* @__PURE__ */ React.createElement(Panel.Root, {
138
+ classNames
139
+ }, /* @__PURE__ */ React.createElement(Panel.Toolbar, {
140
+ asChild: true
141
+ }, /* @__PURE__ */ React.createElement(Toolbar.Root, null, /* @__PURE__ */ React.createElement(Input.Root, null, /* @__PURE__ */ React.createElement(Input.Label, {
142
+ srOnly: true
143
+ }, "Filter facts"), /* @__PURE__ */ React.createElement(Input.TextInput, {
144
+ placeholder: "Filter by entity or predicate\u2026",
145
+ value: filter,
146
+ onChange: (event) => setFilter(event.target.value)
147
+ })), /* @__PURE__ */ React.createElement("div", {
148
+ role: "none",
149
+ className: "grow"
150
+ }), /* @__PURE__ */ React.createElement(IconButton, {
151
+ icon: "ph--list--regular",
152
+ iconOnly: true,
153
+ label: "List view",
154
+ variant: view === "list" ? "primary" : "default",
155
+ onClick: () => setView("list")
156
+ }), /* @__PURE__ */ React.createElement(IconButton, {
157
+ icon: "ph--graph--regular",
158
+ iconOnly: true,
159
+ label: "Graph view",
160
+ variant: view === "graph" ? "primary" : "default",
161
+ onClick: () => setView("graph")
162
+ }))), view === "list" ? /* @__PURE__ */ React.createElement(Panel.Content, {
163
+ asChild: true
164
+ }, /* @__PURE__ */ React.createElement(ScrollArea.Root, {
165
+ padding: true
166
+ }, /* @__PURE__ */ React.createElement(ScrollArea.Viewport, {
167
+ classNames: "flex flex-col gap-2 py-1"
168
+ }, groups.length === 0 && /* @__PURE__ */ React.createElement(Empty, {
169
+ label: "No facts."
170
+ }), groups.map((group) => /* @__PURE__ */ React.createElement(SubjectGroup, {
171
+ key: group.subject,
172
+ group
173
+ }))))) : /* @__PURE__ */ React.createElement(Panel.Content, {
174
+ classNames: "overflow-hidden"
175
+ }, graph ? /* @__PURE__ */ React.createElement(Tree, {
176
+ data: graph,
177
+ variant: "tidy",
178
+ margin: 80,
179
+ classNames: "w-full h-full"
180
+ }) : /* @__PURE__ */ React.createElement(Empty, {
181
+ icon: "ph--graph--regular",
182
+ label: "Select an entity to root the graph."
183
+ })));
184
+ };
185
+ var SubjectGroup = ({ group }) => /* @__PURE__ */ React.createElement("div", {
186
+ className: "shrink-0 flex flex-col bg-card-surface border border-subdued-separator rounded-sm overflow-hidden"
187
+ }, /* @__PURE__ */ React.createElement("div", {
188
+ className: "flex px-3 py-1 items-center justify-between"
189
+ }, /* @__PURE__ */ React.createElement("h3", null, group.subject), group.conflicted && /* @__PURE__ */ React.createElement(Tag, {
190
+ hue: "warning"
191
+ }, /* @__PURE__ */ React.createElement("span", {
192
+ className: "flex items-center gap-1"
193
+ }, /* @__PURE__ */ React.createElement(Icon, {
194
+ icon: "ph--warning--regular",
195
+ size: 3
196
+ }), "conflict"))), /* @__PURE__ */ React.createElement(Listbox.Root, null, /* @__PURE__ */ React.createElement(Listbox.Content, {
197
+ "aria-label": group.subject
198
+ }, group.facts.map((fact) => /* @__PURE__ */ React.createElement(FactRow, {
199
+ key: fact.id,
200
+ fact,
201
+ conflicting: group.conflictedIds.has(fact.id)
202
+ })))));
203
+ var cellClassNames = "bg-input-surface border border-subdued-separator rounded-sm px-2 py-0.5 font-medium whitespace-nowrap truncate";
204
+ var FactRow = ({ fact, conflicting }) => {
205
+ const { assertion, factuality, attribution } = fact;
206
+ return /* @__PURE__ */ React.createElement(Listbox.Item, {
207
+ id: fact.id,
208
+ classNames: mx("flex flex-col items-stretch gap-2 px-3 py-1", conflicting && "border-is-2 border-warning-border")
209
+ }, assertion.quote && /* @__PURE__ */ React.createElement("div", {
210
+ className: "text-sm text-description italic"
211
+ }, '"', assertion.quote, '"'), /* @__PURE__ */ React.createElement("div", {
212
+ className: "grid grid-cols-[1fr_5rem] items-center justify-between gap-2"
213
+ }, /* @__PURE__ */ React.createElement("div", {
214
+ className: "w-full grid grid-cols-[1fr_1rem_1fr_1rem_1fr] items-center flex-wrap"
215
+ }, /* @__PURE__ */ React.createElement("span", {
216
+ className: mx(cellClassNames, "text-right")
217
+ }, formatTerm(assertion.subject)), /* @__PURE__ */ React.createElement("span", {
218
+ className: "border border-subdued-separator"
219
+ }), /* @__PURE__ */ React.createElement("span", {
220
+ className: mx(cellClassNames, "text-center text-description")
221
+ }, assertion.predicate), /* @__PURE__ */ React.createElement("span", {
222
+ className: "border border-subdued-separator"
223
+ }), /* @__PURE__ */ React.createElement("span", {
224
+ className: mx(cellClassNames)
225
+ }, formatTerm(assertion.object))), /* @__PURE__ */ React.createElement("div", {
226
+ className: "flex items-center justify-end gap-2 shrink-0"
227
+ }, factuality.confidence != null && /* @__PURE__ */ React.createElement("span", {
228
+ className: "text-xs text-subdued"
229
+ }, Math.round(factuality.confidence * 100), "%"), /* @__PURE__ */ React.createElement(Tag, {
230
+ hue: factualityColor(factuality.value)
231
+ }, factuality.value))), /* @__PURE__ */ React.createElement("div", {
232
+ className: "text-xs text-subdued text-right"
233
+ }, [
234
+ attribution.agent,
235
+ attribution.source,
236
+ formatDate(attribution.generatedAtTime)
237
+ ].filter(Boolean).join(" \xB7 ")));
238
+ };
239
+ export {
240
+ FactViewer,
241
+ factualityColor,
242
+ formatDate,
243
+ formatTerm,
244
+ graphToTreeNode,
245
+ groupFacts,
246
+ humanize,
247
+ termKey
248
+ };
249
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/FactViewer.tsx", "../../../src/types.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2026 DXOS.org\n//\n\nimport React, { useMemo, useState } from 'react';\n\nimport { type RDF, buildFactGraph, factSourceFromFacts } from '@dxos/pipeline-rdf';\nimport { Icon, IconButton, Input, Panel, ScrollArea, Tag, type ThemedClassName, Toolbar } from '@dxos/react-ui';\nimport { Tree } from '@dxos/react-ui-graph';\nimport { Empty, Listbox } from '@dxos/react-ui-list';\nimport { mx } from '@dxos/ui-theme';\n\nimport { Group, factualityColor, formatDate, formatTerm, graphToTreeNode, groupFacts, termKey } from './types';\n\ntype View = 'list' | 'graph';\n\nexport type FactViewerProps = ThemedClassName<{\n facts: RDF.Fact[];\n /** Context entity id; scopes the list and roots the graph. */\n context?: string;\n /** Predicate filter; when set, only facts with this predicate are shown. */\n predicate?: string;\n}>;\n\n/**\n * Viewer for extracted semantic facts with two views: a grouped **list** (by subject entity, with\n * conflicts highlighted) and a **graph** (tidy tree rooted at the context entity, exploring the fact\n * graph). A `context` entity scopes the list and roots the graph; a `predicate` further filters the\n * list. Pure/presentational.\n */\nexport const FactViewer = ({ classNames, facts, context, predicate }: FactViewerProps) => {\n const [filter, setFilter] = useState('');\n const [view, setView] = useState<View>('list');\n const scoped = useMemo(\n () =>\n facts.filter(\n (fact) =>\n (context == null ||\n termKey(fact.assertion.subject) === context ||\n termKey(fact.assertion.object) === context) &&\n (predicate == null || fact.assertion.predicate === predicate),\n ),\n [facts, context, predicate],\n );\n const groups = useMemo(() => groupFacts(scoped, filter), [scoped, filter]);\n const graph = useMemo(\n () => (context == null ? undefined : graphToTreeNode(buildFactGraph(context, factSourceFromFacts(facts)), context)),\n [facts, context],\n );\n\n return (\n <Panel.Root classNames={classNames}>\n <Panel.Toolbar asChild>\n <Toolbar.Root>\n <Input.Root>\n <Input.Label srOnly>Filter facts</Input.Label>\n <Input.TextInput\n placeholder='Filter by entity or predicate…'\n value={filter}\n onChange={(event) => setFilter(event.target.value)}\n />\n </Input.Root>\n <div role='none' className='grow' />\n <IconButton\n icon='ph--list--regular'\n iconOnly\n label='List view'\n variant={view === 'list' ? 'primary' : 'default'}\n onClick={() => setView('list')}\n />\n <IconButton\n icon='ph--graph--regular'\n iconOnly\n label='Graph view'\n variant={view === 'graph' ? 'primary' : 'default'}\n onClick={() => setView('graph')}\n />\n </Toolbar.Root>\n </Panel.Toolbar>\n {view === 'list' ? (\n <Panel.Content asChild>\n <ScrollArea.Root padding>\n <ScrollArea.Viewport classNames='flex flex-col gap-2 py-1'>\n {groups.length === 0 && <Empty label='No facts.' />}\n {groups.map((group) => (\n <SubjectGroup key={group.subject} group={group} />\n ))}\n </ScrollArea.Viewport>\n </ScrollArea.Root>\n </Panel.Content>\n ) : (\n <Panel.Content classNames='overflow-hidden'>\n {graph ? (\n <Tree data={graph} variant='tidy' margin={80} classNames='w-full h-full' />\n ) : (\n <Empty icon='ph--graph--regular' label='Select an entity to root the graph.' />\n )}\n </Panel.Content>\n )}\n </Panel.Root>\n );\n};\n\nconst SubjectGroup = ({ group }: { group: Group }) => (\n <div className='shrink-0 flex flex-col bg-card-surface border border-subdued-separator rounded-sm overflow-hidden'>\n <div className='flex px-3 py-1 items-center justify-between'>\n <h3>{group.subject}</h3>\n {group.conflicted && (\n <Tag hue='warning'>\n <span className='flex items-center gap-1'>\n <Icon icon='ph--warning--regular' size={3} />\n conflict\n </span>\n </Tag>\n )}\n </div>\n <Listbox.Root>\n <Listbox.Content aria-label={group.subject}>\n {group.facts.map((fact) => (\n <FactRow key={fact.id} fact={fact} conflicting={group.conflictedIds.has(fact.id)} />\n ))}\n </Listbox.Content>\n </Listbox.Root>\n </div>\n);\n\nconst cellClassNames =\n 'bg-input-surface border border-subdued-separator rounded-sm px-2 py-0.5 font-medium whitespace-nowrap truncate';\n\nconst FactRow = ({ fact, conflicting }: { fact: RDF.Fact; conflicting: boolean }) => {\n const { assertion, factuality, attribution } = fact;\n return (\n <Listbox.Item\n id={fact.id}\n classNames={mx('flex flex-col items-stretch gap-2 px-3 py-1', conflicting && 'border-is-2 border-warning-border')}\n >\n {assertion.quote && <div className='text-sm text-description italic'>\"{assertion.quote}\"</div>}\n\n <div className='grid grid-cols-[1fr_5rem] items-center justify-between gap-2'>\n <div className='w-full grid grid-cols-[1fr_1rem_1fr_1rem_1fr] items-center flex-wrap'>\n <span className={mx(cellClassNames, 'text-right')}>{formatTerm(assertion.subject)}</span>\n <span className='border border-subdued-separator'></span>\n <span className={mx(cellClassNames, 'text-center text-description')}>{assertion.predicate}</span>\n <span className='border border-subdued-separator'></span>\n <span className={mx(cellClassNames)}>{formatTerm(assertion.object)}</span>\n </div>\n\n <div className='flex items-center justify-end gap-2 shrink-0'>\n {factuality.confidence != null && (\n <span className='text-xs text-subdued'>{Math.round(factuality.confidence * 100)}%</span>\n )}\n <Tag hue={factualityColor(factuality.value)}>{factuality.value}</Tag>\n </div>\n </div>\n\n <div className='text-xs text-subdued text-right'>\n {[attribution.agent, attribution.source, formatDate(attribution.generatedAtTime)].filter(Boolean).join(' · ')}\n </div>\n </Listbox.Item>\n );\n};\n", "//\n// Copyright 2026 DXOS.org\n//\n\nimport { type FactGraph, type RDF } from '@dxos/pipeline-rdf';\nimport { type TreeNode } from '@dxos/react-ui-graph';\nimport { type ChromaticPalette, type MessageValence, type NeutralPalette } from '@dxos/ui-types';\n\nexport type Group = {\n subject: string;\n facts: RDF.Fact[];\n conflicted: boolean;\n conflictedIds: Set<string>;\n};\n\n/** Group facts by subject entity and flag predicate-level conflicts within each group. */\nexport const groupFacts = (facts: RDF.Fact[], filter: string): Group[] => {\n const needle = filter.trim().toLowerCase();\n const filtered = needle\n ? facts.filter((fact) => {\n const { subject, predicate, object } = fact.assertion;\n return [formatTerm(subject), predicate, formatTerm(object)].some((value) =>\n value.toLowerCase().includes(needle),\n );\n })\n : facts;\n\n // Group by the entity slug (so `DXOS`/`dxos` collapse) but remember a display label for the header.\n const bySubject = new Map<string, RDF.Fact[]>();\n const labelByKey = new Map<string, string>();\n for (const fact of filtered) {\n const key = termKey(fact.assertion.subject);\n const list = bySubject.get(key) ?? [];\n list.push(fact);\n bySubject.set(key, list);\n if (!labelByKey.has(key)) {\n labelByKey.set(key, formatTerm(fact.assertion.subject));\n }\n }\n\n return [...bySubject.entries()].map(([key, groupFactsList]) => {\n const subject = labelByKey.get(key) ?? key;\n const byPredicate = new Map<string, RDF.Fact[]>();\n for (const fact of groupFactsList) {\n const list = byPredicate.get(fact.assertion.predicate) ?? [];\n list.push(fact);\n byPredicate.set(fact.assertion.predicate, list);\n }\n\n const conflictedIds = new Set<string>();\n for (const list of byPredicate.values()) {\n const objects = new Set(list.map((fact) => termKey(fact.assertion.object)));\n if (objects.size > 1) {\n for (const fact of list) {\n conflictedIds.add(fact.id);\n }\n }\n }\n\n return {\n subject,\n facts: groupFactsList,\n conflicted: conflictedIds.size > 0,\n conflictedIds,\n };\n });\n};\n\n/** The join/grouping key: the entity slug (or literal). Casing variants collapse to one key. */\nexport const termKey = (term: RDF.Term): string => ('entity' in term ? term.entity : term.literal);\n\n/** Display form: the preserved surface label, else a prettified slug; literals render verbatim. */\nexport const formatTerm = (term: RDF.Term): string =>\n 'entity' in term ? (term.label ?? humanize(term.entity)) : term.literal;\n\n/**\n * Convert a {@link FactGraph} into a rooted {@link TreeNode} hierarchy for the tidy-tree renderer.\n * A fact graph is a general (cyclic) graph; the tidy tree needs a hierarchy, so this takes the BFS\n * spanning tree from `rootId` over the undirected edges (each node appears once). Returns `undefined`\n * if the root isn't in the graph.\n */\nexport const graphToTreeNode = (graph: FactGraph, rootId: string): TreeNode | undefined => {\n const nodeById = new Map(graph.nodes.map((node) => [node.id, node]));\n if (!nodeById.has(rootId)) {\n return undefined;\n }\n const adjacency = new Map<string, string[]>();\n const link = (from: string, to: string) => {\n const list = adjacency.get(from) ?? [];\n list.push(to);\n adjacency.set(from, list);\n };\n for (const edge of graph.edges) {\n link(edge.source, edge.target);\n link(edge.target, edge.source);\n }\n\n const visited = new Set<string>([rootId]);\n const build = (id: string): TreeNode => {\n const children: TreeNode[] = [];\n for (const neighbour of adjacency.get(id) ?? []) {\n if (!visited.has(neighbour)) {\n visited.add(neighbour);\n children.push(build(neighbour));\n }\n }\n return { id, label: nodeById.get(id)?.label ?? id, ...(children.length > 0 ? { children } : {}) };\n };\n return build(rootId);\n};\n\n/** Render ids like `q3-board-meeting` as `Q3 Board Meeting`. */\nexport const humanize = (value: string): string =>\n value.replace(/[-_]/g, ' ').replace(/\\b\\w/g, (char) => char.toUpperCase());\n\nexport const formatDate = (iso: string): string => iso.slice(0, 10);\n\n/** Map FactBank factuality to a real react-ui palette member. */\nexport const factualityColor = (\n factuality: RDF.FactualityValue,\n): NeutralPalette | ChromaticPalette | MessageValence => {\n switch (factuality) {\n case 'CT+':\n return 'emerald';\n case 'PR+':\n return 'amber';\n case 'PS+':\n return 'sky';\n case 'CT-':\n case 'PR-':\n case 'PS-':\n return 'red';\n case 'CTu':\n case 'Uu':\n default:\n return 'neutral';\n }\n};\n"],
5
+ "mappings": ";AAIA,OAAOA,SAASC,SAASC,gBAAgB;AAEzC,SAAmBC,gBAAgBC,2BAA2B;AAC9D,SAASC,MAAMC,YAAYC,OAAOC,OAAOC,YAAYC,KAA2BC,eAAe;AAC/F,SAASC,YAAY;AACrB,SAASC,OAAOC,eAAe;AAC/B,SAASC,UAAU;;;ACMZ,IAAMC,aAAa,CAACC,OAAmBC,WAAAA;AAC5C,QAAMC,SAASD,OAAOE,KAAI,EAAGC,YAAW;AACxC,QAAMC,WAAWH,SACbF,MAAMC,OAAO,CAACK,SAAAA;AACZ,UAAM,EAAEC,SAASC,WAAWC,OAAM,IAAKH,KAAKI;AAC5C,WAAO;MAACC,WAAWJ,OAAAA;MAAUC;MAAWG,WAAWF,MAAAA;MAASG,KAAK,CAACC,UAChEA,MAAMT,YAAW,EAAGU,SAASZ,MAAAA,CAAAA;EAEjC,CAAA,IACAF;AAGJ,QAAMe,YAAY,oBAAIC,IAAAA;AACtB,QAAMC,aAAa,oBAAID,IAAAA;AACvB,aAAWV,QAAQD,UAAU;AAC3B,UAAMa,MAAMC,QAAQb,KAAKI,UAAUH,OAAO;AAC1C,UAAMa,OAAOL,UAAUM,IAAIH,GAAAA,KAAQ,CAAA;AACnCE,SAAKE,KAAKhB,IAAAA;AACVS,cAAUQ,IAAIL,KAAKE,IAAAA;AACnB,QAAI,CAACH,WAAWO,IAAIN,GAAAA,GAAM;AACxBD,iBAAWM,IAAIL,KAAKP,WAAWL,KAAKI,UAAUH,OAAO,CAAA;IACvD;EACF;AAEA,SAAO;OAAIQ,UAAUU,QAAO;IAAIC,I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cAACzC,OAAAA;IAAIE,WAAU;KAAkC,KAAEzB,UAAUgE,OAAM,GAAA,GAEvF,sBAAA,cAACzC,OAAAA;IAAIE,WAAU;KACb,sBAAA,cAACF,OAAAA;IAAIE,WAAU;KACb,sBAAA,cAACwB,QAAAA;IAAKxB,WAAWsC,GAAGJ,gBAAgB,YAAA;KAAgBM,WAAWjE,UAAUC,OAAO,CAAA,GAChF,sBAAA,cAACgD,QAAAA;IAAKxB,WAAU;MAChB,sBAAA,cAACwB,QAAAA;IAAKxB,WAAWsC,GAAGJ,gBAAgB,8BAAA;KAAkC3D,UAAUV,SAAS,GACzF,sBAAA,cAAC2D,QAAAA;IAAKxB,WAAU;MAChB,sBAAA,cAACwB,QAAAA;IAAKxB,WAAWsC,GAAGJ,cAAAA;KAAkBM,WAAWjE,UAAUE,MAAM,CAAA,CAAA,GAGnE,sBAAA,cAACqB,OAAAA;IAAIE,WAAU;KACZmC,WAAWM,cAAc,QACxB,sBAAA,cAACjB,QAAAA;IAAKxB,WAAU;KAAwB0C,KAAKC,MAAMR,WAAWM,aAAa,GAAA,GAAK,GAAA,GAElF,sBAAA,cAACnB,KAAAA;IAAIC,KAAKqB,gBAAgBT,WAAWzC,KAAK;KAAIyC,WAAWzC,KAAK,CAAA,CAAA,GAIlE,sBAAA,cAACI,OAAAA;IAAIE,WAAU;KACZ;IAACoC,YAAYS;IAAOT,YAAYU;IAAQC,WAAWX,YAAYY,eAAe;IAAGlF,OAAOmF,OAAAA,EAASC,KAAK,QAAA,CAAA,CAAA;AAI/G;",
6
+ "names": ["React", "useMemo", "useState", "buildFactGraph", "factSourceFromFacts", "Icon", "IconButton", "Input", "Panel", "ScrollArea", "Tag", "Toolbar", "Tree", "Empty", "Listbox", "mx", "groupFacts", "facts", "filter", "needle", "trim", "toLowerCase", "filtered", "fact", "subject", "predicate", "object", "assertion", "formatTerm", "some", "value", "includes", "bySubject", "Map", "labelByKey", "key", "termKey", "list", "get", "push", "set", "has", "entries", "map", "groupFactsList", "byPredicate", "conflictedIds", "Set", "values", "objects", "size", "add", "id", "conflicted", "term", "entity", "literal", "label", "humanize", "graphToTreeNode", "graph", "rootId", "nodeById", "nodes", "node", "undefined", "adjacency", "link", "from", "to", "edge", "edges", "source", "target", "visited", "build", "children", "neighbour", "length", "replace", "char", "toUpperCase", "formatDate", "iso", "slice", "factualityColor", "factuality", "FactViewer", "classNames", "facts", "context", "predicate", "filter", "setFilter", "useState", "view", "setView", "scoped", "useMemo", "fact", "termKey", "assertion", "subject", "object", "groups", "groupFacts", "graph", "undefined", "graphToTreeNode", "buildFactGraph", "factSourceFromFacts", "Panel", "Root", "Toolbar", "asChild", "Input", "Label", "srOnly", "TextInput", "placeholder", "value", "onChange", "event", "target", "div", "role", "className", "IconButton", "icon", "iconOnly", "label", "variant", "onClick", "Content", "ScrollArea", "padding", "Viewport", "length", "Empty", "map", "group", "SubjectGroup", "key", "Tree", "data", "margin", "h3", "conflicted", "Tag", "hue", "span", "Icon", "size", "Listbox", "aria-label", "FactRow", "id", "conflicting", "conflictedIds", "has", "cellClassNames", "factuality", "attribution", "Item", "mx", "quote", "formatTerm", "confidence", "Math", "round", "factualityColor", "agent", "source", "formatDate", "generatedAtTime", "Boolean", "join"]
7
+ }
@@ -0,0 +1 @@
1
+ {"inputs":{"src/types.ts":{"bytes":15625,"imports":[],"format":"esm"},"src/FactViewer.tsx":{"bytes":21156,"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/pipeline-rdf","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui-graph","kind":"import-statement","external":true},{"path":"@dxos/react-ui-list","kind":"import-statement","external":true},{"path":"@dxos/ui-theme","kind":"import-statement","external":true},{"path":"src/types.ts","kind":"import-statement","original":"./types"}],"format":"esm"},"src/index.ts":{"bytes":463,"imports":[{"path":"src/FactViewer.tsx","kind":"import-statement","original":"./FactViewer"},{"path":"src/types.ts","kind":"import-statement","original":"./types"}],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":19168},"dist/lib/browser/index.mjs":{"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/pipeline-rdf","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui-graph","kind":"import-statement","external":true},{"path":"@dxos/react-ui-list","kind":"import-statement","external":true},{"path":"@dxos/ui-theme","kind":"import-statement","external":true}],"exports":["FactViewer","factualityColor","formatDate","formatTerm","graphToTreeNode","groupFacts","humanize","termKey"],"entryPoint":"src/index.ts","inputs":{"src/FactViewer.tsx":{"bytesInOutput":5991},"src/types.ts":{"bytesInOutput":3107},"src/index.ts":{"bytesInOutput":0}},"bytes":9323}}}
@@ -0,0 +1,251 @@
1
+ import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
+
3
+ // src/FactViewer.tsx
4
+ import React, { useMemo, useState } from "react";
5
+ import { buildFactGraph, factSourceFromFacts } from "@dxos/pipeline-rdf";
6
+ import { Icon, IconButton, Input, Panel, ScrollArea, Tag, Toolbar } from "@dxos/react-ui";
7
+ import { Tree } from "@dxos/react-ui-graph";
8
+ import { Empty, Listbox } from "@dxos/react-ui-list";
9
+ import { mx } from "@dxos/ui-theme";
10
+
11
+ // src/types.ts
12
+ var groupFacts = (facts, filter) => {
13
+ const needle = filter.trim().toLowerCase();
14
+ const filtered = needle ? facts.filter((fact) => {
15
+ const { subject, predicate, object } = fact.assertion;
16
+ return [
17
+ formatTerm(subject),
18
+ predicate,
19
+ formatTerm(object)
20
+ ].some((value) => value.toLowerCase().includes(needle));
21
+ }) : facts;
22
+ const bySubject = /* @__PURE__ */ new Map();
23
+ const labelByKey = /* @__PURE__ */ new Map();
24
+ for (const fact of filtered) {
25
+ const key = termKey(fact.assertion.subject);
26
+ const list = bySubject.get(key) ?? [];
27
+ list.push(fact);
28
+ bySubject.set(key, list);
29
+ if (!labelByKey.has(key)) {
30
+ labelByKey.set(key, formatTerm(fact.assertion.subject));
31
+ }
32
+ }
33
+ return [
34
+ ...bySubject.entries()
35
+ ].map(([key, groupFactsList]) => {
36
+ const subject = labelByKey.get(key) ?? key;
37
+ const byPredicate = /* @__PURE__ */ new Map();
38
+ for (const fact of groupFactsList) {
39
+ const list = byPredicate.get(fact.assertion.predicate) ?? [];
40
+ list.push(fact);
41
+ byPredicate.set(fact.assertion.predicate, list);
42
+ }
43
+ const conflictedIds = /* @__PURE__ */ new Set();
44
+ for (const list of byPredicate.values()) {
45
+ const objects = new Set(list.map((fact) => termKey(fact.assertion.object)));
46
+ if (objects.size > 1) {
47
+ for (const fact of list) {
48
+ conflictedIds.add(fact.id);
49
+ }
50
+ }
51
+ }
52
+ return {
53
+ subject,
54
+ facts: groupFactsList,
55
+ conflicted: conflictedIds.size > 0,
56
+ conflictedIds
57
+ };
58
+ });
59
+ };
60
+ var termKey = (term) => "entity" in term ? term.entity : term.literal;
61
+ var formatTerm = (term) => "entity" in term ? term.label ?? humanize(term.entity) : term.literal;
62
+ var graphToTreeNode = (graph, rootId) => {
63
+ const nodeById = new Map(graph.nodes.map((node) => [
64
+ node.id,
65
+ node
66
+ ]));
67
+ if (!nodeById.has(rootId)) {
68
+ return void 0;
69
+ }
70
+ const adjacency = /* @__PURE__ */ new Map();
71
+ const link = (from, to) => {
72
+ const list = adjacency.get(from) ?? [];
73
+ list.push(to);
74
+ adjacency.set(from, list);
75
+ };
76
+ for (const edge of graph.edges) {
77
+ link(edge.source, edge.target);
78
+ link(edge.target, edge.source);
79
+ }
80
+ const visited = /* @__PURE__ */ new Set([
81
+ rootId
82
+ ]);
83
+ const build = (id) => {
84
+ const children = [];
85
+ for (const neighbour of adjacency.get(id) ?? []) {
86
+ if (!visited.has(neighbour)) {
87
+ visited.add(neighbour);
88
+ children.push(build(neighbour));
89
+ }
90
+ }
91
+ return {
92
+ id,
93
+ label: nodeById.get(id)?.label ?? id,
94
+ ...children.length > 0 ? {
95
+ children
96
+ } : {}
97
+ };
98
+ };
99
+ return build(rootId);
100
+ };
101
+ var humanize = (value) => value.replace(/[-_]/g, " ").replace(/\b\w/g, (char) => char.toUpperCase());
102
+ var formatDate = (iso) => iso.slice(0, 10);
103
+ var factualityColor = (factuality) => {
104
+ switch (factuality) {
105
+ case "CT+":
106
+ return "emerald";
107
+ case "PR+":
108
+ return "amber";
109
+ case "PS+":
110
+ return "sky";
111
+ case "CT-":
112
+ case "PR-":
113
+ case "PS-":
114
+ return "red";
115
+ case "CTu":
116
+ case "Uu":
117
+ default:
118
+ return "neutral";
119
+ }
120
+ };
121
+
122
+ // src/FactViewer.tsx
123
+ var FactViewer = ({ classNames, facts, context, predicate }) => {
124
+ const [filter, setFilter] = useState("");
125
+ const [view, setView] = useState("list");
126
+ const scoped = useMemo(() => facts.filter((fact) => (context == null || termKey(fact.assertion.subject) === context || termKey(fact.assertion.object) === context) && (predicate == null || fact.assertion.predicate === predicate)), [
127
+ facts,
128
+ context,
129
+ predicate
130
+ ]);
131
+ const groups = useMemo(() => groupFacts(scoped, filter), [
132
+ scoped,
133
+ filter
134
+ ]);
135
+ const graph = useMemo(() => context == null ? void 0 : graphToTreeNode(buildFactGraph(context, factSourceFromFacts(facts)), context), [
136
+ facts,
137
+ context
138
+ ]);
139
+ return /* @__PURE__ */ React.createElement(Panel.Root, {
140
+ classNames
141
+ }, /* @__PURE__ */ React.createElement(Panel.Toolbar, {
142
+ asChild: true
143
+ }, /* @__PURE__ */ React.createElement(Toolbar.Root, null, /* @__PURE__ */ React.createElement(Input.Root, null, /* @__PURE__ */ React.createElement(Input.Label, {
144
+ srOnly: true
145
+ }, "Filter facts"), /* @__PURE__ */ React.createElement(Input.TextInput, {
146
+ placeholder: "Filter by entity or predicate\u2026",
147
+ value: filter,
148
+ onChange: (event) => setFilter(event.target.value)
149
+ })), /* @__PURE__ */ React.createElement("div", {
150
+ role: "none",
151
+ className: "grow"
152
+ }), /* @__PURE__ */ React.createElement(IconButton, {
153
+ icon: "ph--list--regular",
154
+ iconOnly: true,
155
+ label: "List view",
156
+ variant: view === "list" ? "primary" : "default",
157
+ onClick: () => setView("list")
158
+ }), /* @__PURE__ */ React.createElement(IconButton, {
159
+ icon: "ph--graph--regular",
160
+ iconOnly: true,
161
+ label: "Graph view",
162
+ variant: view === "graph" ? "primary" : "default",
163
+ onClick: () => setView("graph")
164
+ }))), view === "list" ? /* @__PURE__ */ React.createElement(Panel.Content, {
165
+ asChild: true
166
+ }, /* @__PURE__ */ React.createElement(ScrollArea.Root, {
167
+ padding: true
168
+ }, /* @__PURE__ */ React.createElement(ScrollArea.Viewport, {
169
+ classNames: "flex flex-col gap-2 py-1"
170
+ }, groups.length === 0 && /* @__PURE__ */ React.createElement(Empty, {
171
+ label: "No facts."
172
+ }), groups.map((group) => /* @__PURE__ */ React.createElement(SubjectGroup, {
173
+ key: group.subject,
174
+ group
175
+ }))))) : /* @__PURE__ */ React.createElement(Panel.Content, {
176
+ classNames: "overflow-hidden"
177
+ }, graph ? /* @__PURE__ */ React.createElement(Tree, {
178
+ data: graph,
179
+ variant: "tidy",
180
+ margin: 80,
181
+ classNames: "w-full h-full"
182
+ }) : /* @__PURE__ */ React.createElement(Empty, {
183
+ icon: "ph--graph--regular",
184
+ label: "Select an entity to root the graph."
185
+ })));
186
+ };
187
+ var SubjectGroup = ({ group }) => /* @__PURE__ */ React.createElement("div", {
188
+ className: "shrink-0 flex flex-col bg-card-surface border border-subdued-separator rounded-sm overflow-hidden"
189
+ }, /* @__PURE__ */ React.createElement("div", {
190
+ className: "flex px-3 py-1 items-center justify-between"
191
+ }, /* @__PURE__ */ React.createElement("h3", null, group.subject), group.conflicted && /* @__PURE__ */ React.createElement(Tag, {
192
+ hue: "warning"
193
+ }, /* @__PURE__ */ React.createElement("span", {
194
+ className: "flex items-center gap-1"
195
+ }, /* @__PURE__ */ React.createElement(Icon, {
196
+ icon: "ph--warning--regular",
197
+ size: 3
198
+ }), "conflict"))), /* @__PURE__ */ React.createElement(Listbox.Root, null, /* @__PURE__ */ React.createElement(Listbox.Content, {
199
+ "aria-label": group.subject
200
+ }, group.facts.map((fact) => /* @__PURE__ */ React.createElement(FactRow, {
201
+ key: fact.id,
202
+ fact,
203
+ conflicting: group.conflictedIds.has(fact.id)
204
+ })))));
205
+ var cellClassNames = "bg-input-surface border border-subdued-separator rounded-sm px-2 py-0.5 font-medium whitespace-nowrap truncate";
206
+ var FactRow = ({ fact, conflicting }) => {
207
+ const { assertion, factuality, attribution } = fact;
208
+ return /* @__PURE__ */ React.createElement(Listbox.Item, {
209
+ id: fact.id,
210
+ classNames: mx("flex flex-col items-stretch gap-2 px-3 py-1", conflicting && "border-is-2 border-warning-border")
211
+ }, assertion.quote && /* @__PURE__ */ React.createElement("div", {
212
+ className: "text-sm text-description italic"
213
+ }, '"', assertion.quote, '"'), /* @__PURE__ */ React.createElement("div", {
214
+ className: "grid grid-cols-[1fr_5rem] items-center justify-between gap-2"
215
+ }, /* @__PURE__ */ React.createElement("div", {
216
+ className: "w-full grid grid-cols-[1fr_1rem_1fr_1rem_1fr] items-center flex-wrap"
217
+ }, /* @__PURE__ */ React.createElement("span", {
218
+ className: mx(cellClassNames, "text-right")
219
+ }, formatTerm(assertion.subject)), /* @__PURE__ */ React.createElement("span", {
220
+ className: "border border-subdued-separator"
221
+ }), /* @__PURE__ */ React.createElement("span", {
222
+ className: mx(cellClassNames, "text-center text-description")
223
+ }, assertion.predicate), /* @__PURE__ */ React.createElement("span", {
224
+ className: "border border-subdued-separator"
225
+ }), /* @__PURE__ */ React.createElement("span", {
226
+ className: mx(cellClassNames)
227
+ }, formatTerm(assertion.object))), /* @__PURE__ */ React.createElement("div", {
228
+ className: "flex items-center justify-end gap-2 shrink-0"
229
+ }, factuality.confidence != null && /* @__PURE__ */ React.createElement("span", {
230
+ className: "text-xs text-subdued"
231
+ }, Math.round(factuality.confidence * 100), "%"), /* @__PURE__ */ React.createElement(Tag, {
232
+ hue: factualityColor(factuality.value)
233
+ }, factuality.value))), /* @__PURE__ */ React.createElement("div", {
234
+ className: "text-xs text-subdued text-right"
235
+ }, [
236
+ attribution.agent,
237
+ attribution.source,
238
+ formatDate(attribution.generatedAtTime)
239
+ ].filter(Boolean).join(" \xB7 ")));
240
+ };
241
+ export {
242
+ FactViewer,
243
+ factualityColor,
244
+ formatDate,
245
+ formatTerm,
246
+ graphToTreeNode,
247
+ groupFacts,
248
+ humanize,
249
+ termKey
250
+ };
251
+ //# sourceMappingURL=index.mjs.map