@powerhousedao/knowledge-note 1.0.1 → 1.0.3
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/editors/health-report-editor/editor.d.ts.map +1 -1
- package/dist/editors/health-report-editor/editor.js +100 -17
- package/dist/editors/knowledge-note-editor/editor.d.ts.map +1 -1
- package/dist/editors/knowledge-note-editor/editor.js +12 -3
- package/dist/editors/knowledge-vault/components/DriveExplorer.d.ts.map +1 -1
- package/dist/editors/knowledge-vault/components/GettingStarted.js +26 -7
- package/dist/editors/knowledge-vault/components/GraphView.d.ts +1 -1
- package/dist/editors/knowledge-vault/components/GraphView.d.ts.map +1 -1
- package/dist/editors/knowledge-vault/components/GraphView.js +211 -33
- package/dist/editors/knowledge-vault/components/HealthDashboard.d.ts.map +1 -1
- package/dist/editors/knowledge-vault/components/HealthDashboard.js +16 -4
- package/dist/editors/knowledge-vault/components/NoteList.d.ts.map +1 -1
- package/dist/editors/knowledge-vault/components/NoteList.js +13 -16
- package/dist/editors/knowledge-vault/hooks/use-drive-init.d.ts.map +1 -1
- package/dist/editors/knowledge-vault/hooks/use-drive-init.js +14 -6
- package/dist/editors/moc-editor/editor.d.ts.map +1 -1
- package/dist/editors/moc-editor/editor.js +13 -4
- package/dist/editors/tension-editor/editor.d.ts.map +1 -1
- package/dist/editors/tension-editor/editor.js +60 -9
- package/dist/package.json +2 -2
- package/dist/processors/factory.d.ts.map +1 -1
- package/dist/processors/factory.js +0 -3
- package/dist/processors/graph-indexer/index.d.ts.map +1 -1
- package/dist/processors/graph-indexer/index.js +5 -8
- package/dist/processors/graph-indexer/query.d.ts.map +1 -1
- package/dist/processors/graph-indexer/query.js +2 -1
- package/dist/style.css +82 -0
- package/dist/subgraphs/index.d.ts +0 -1
- package/dist/subgraphs/index.d.ts.map +1 -1
- package/dist/subgraphs/index.js +0 -1
- package/dist/subgraphs/knowledge-graph/subgraph.d.ts +28 -13
- package/dist/subgraphs/knowledge-graph/subgraph.d.ts.map +1 -1
- package/dist/subgraphs/knowledge-graph/subgraph.js +144 -22
- package/dist/tests/processor/graph-indexer.test.js +8 -2
- package/dist/tests/unit/knowledge-note-reducers.test.js +4 -1
- package/dist/tests/unit/lifecycle-state-machine.test.js +16 -4
- package/dist/tests/unit/moc-reducers.test.js +1 -1
- package/dist/tests/unit/pipeline-queue-reducers.test.js +10 -2
- package/package.json +3 -3
- package/dist/processors/methodology-indexer/factory.d.ts +0 -4
- package/dist/processors/methodology-indexer/factory.d.ts.map +0 -1
- package/dist/processors/methodology-indexer/factory.js +0 -23
- package/dist/processors/methodology-indexer/index.d.ts +0 -11
- package/dist/processors/methodology-indexer/index.d.ts.map +0 -1
- package/dist/processors/methodology-indexer/index.js +0 -118
- package/dist/processors/methodology-indexer/migrations.d.ts +0 -4
- package/dist/processors/methodology-indexer/migrations.d.ts.map +0 -1
- package/dist/processors/methodology-indexer/migrations.js +0 -39
- package/dist/processors/methodology-indexer/query.d.ts +0 -35
- package/dist/processors/methodology-indexer/query.d.ts.map +0 -1
- package/dist/processors/methodology-indexer/query.js +0 -102
- package/dist/processors/methodology-indexer/schema.d.ts +0 -22
- package/dist/processors/methodology-indexer/schema.d.ts.map +0 -1
- package/dist/processors/methodology-indexer/schema.js +0 -1
- package/dist/subgraphs/methodology/index.d.ts +0 -2
- package/dist/subgraphs/methodology/index.d.ts.map +0 -1
- package/dist/subgraphs/methodology/index.js +0 -1
- package/dist/subgraphs/methodology/subgraph.d.ts +0 -47
- package/dist/subgraphs/methodology/subgraph.d.ts.map +0 -1
- package/dist/subgraphs/methodology/subgraph.js +0 -87
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { gql } from "graphql-tag";
|
|
2
|
-
import { BaseSubgraph
|
|
2
|
+
import { BaseSubgraph } from "@powerhousedao/reactor-api";
|
|
3
3
|
import { GraphIndexerProcessor } from "../../processors/graph-indexer/index.js";
|
|
4
4
|
import { createGraphQuery } from "../../processors/graph-indexer/query.js";
|
|
5
5
|
export class KnowledgeGraphSubgraph extends BaseSubgraph {
|
|
@@ -50,16 +50,31 @@ export class KnowledgeGraphSubgraph extends BaseSubgraph {
|
|
|
50
50
|
documentId: String!
|
|
51
51
|
depth: Int
|
|
52
52
|
): [ConnectionResult!]!
|
|
53
|
-
knowledgeGraphNodesByStatus(
|
|
54
|
-
|
|
53
|
+
knowledgeGraphNodesByStatus(
|
|
54
|
+
driveId: ID!
|
|
55
|
+
status: String!
|
|
56
|
+
): [KnowledgeGraphNode!]!
|
|
57
|
+
knowledgeGraphBacklinks(
|
|
58
|
+
driveId: ID!
|
|
59
|
+
documentId: String!
|
|
60
|
+
): [KnowledgeGraphEdge!]!
|
|
55
61
|
knowledgeGraphDensity(driveId: ID!): Float!
|
|
56
62
|
|
|
57
|
-
knowledgeGraphSearch(
|
|
63
|
+
knowledgeGraphSearch(
|
|
64
|
+
driveId: ID!
|
|
65
|
+
query: String!
|
|
66
|
+
limit: Int
|
|
67
|
+
): [KnowledgeGraphNode!]!
|
|
58
68
|
knowledgeGraphTriangles(driveId: ID!, limit: Int): [Triangle!]!
|
|
59
69
|
knowledgeGraphBridges(driveId: ID!): [KnowledgeGraphNode!]!
|
|
60
|
-
knowledgeGraphForwardLinks(
|
|
70
|
+
knowledgeGraphForwardLinks(
|
|
71
|
+
driveId: ID!
|
|
72
|
+
documentId: String!
|
|
73
|
+
): [KnowledgeGraphEdge!]!
|
|
61
74
|
|
|
62
|
-
"""
|
|
75
|
+
"""
|
|
76
|
+
Debug: raw processor DB tables
|
|
77
|
+
"""
|
|
63
78
|
knowledgeGraphDebug(driveId: ID!): GraphDebugInfo!
|
|
64
79
|
}
|
|
65
80
|
|
|
@@ -76,8 +91,25 @@ export class KnowledgeGraphSubgraph extends BaseSubgraph {
|
|
|
76
91
|
rawEdges: [KnowledgeGraphEdge!]!
|
|
77
92
|
processorNamespace: String!
|
|
78
93
|
}
|
|
94
|
+
|
|
95
|
+
type ReindexResult {
|
|
96
|
+
indexedNodes: Int!
|
|
97
|
+
indexedEdges: Int!
|
|
98
|
+
errors: [String!]!
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
extend type Mutation {
|
|
102
|
+
"""
|
|
103
|
+
Backfill the graph index by reading all bai/knowledge-note documents
|
|
104
|
+
in the drive. Use when the processor missed historical operations.
|
|
105
|
+
"""
|
|
106
|
+
knowledgeGraphReindex(driveId: ID!): ReindexResult!
|
|
107
|
+
}
|
|
79
108
|
`;
|
|
80
109
|
resolvers = {
|
|
110
|
+
Mutation: {
|
|
111
|
+
knowledgeGraphReindex: (_, args) => this.reindexDrive(args.driveId),
|
|
112
|
+
},
|
|
81
113
|
Query: {
|
|
82
114
|
knowledgeGraphNodes: async (_, args) => {
|
|
83
115
|
await this.ensureGraphDoc(args.driveId);
|
|
@@ -125,7 +157,11 @@ export class KnowledgeGraphSubgraph extends BaseSubgraph {
|
|
|
125
157
|
knowledgeGraphTriangles: async (_, args) => {
|
|
126
158
|
const query = this.getQuery(args.driveId);
|
|
127
159
|
const triangles = await query.triangles(args.limit ?? 20);
|
|
128
|
-
return triangles.map((t) => ({
|
|
160
|
+
return triangles.map((t) => ({
|
|
161
|
+
noteA: t.a,
|
|
162
|
+
noteB: t.b,
|
|
163
|
+
sharedTarget: t.sharedTarget,
|
|
164
|
+
}));
|
|
129
165
|
},
|
|
130
166
|
knowledgeGraphBridges: async (_, args) => {
|
|
131
167
|
const query = this.getQuery(args.driveId);
|
|
@@ -138,11 +174,12 @@ export class KnowledgeGraphSubgraph extends BaseSubgraph {
|
|
|
138
174
|
knowledgeGraphDebug: async (_, args) => {
|
|
139
175
|
const namespace = GraphIndexerProcessor.getNamespace(args.driveId);
|
|
140
176
|
try {
|
|
141
|
-
const
|
|
177
|
+
const db = this.getDb(args.driveId);
|
|
178
|
+
const rawNodes = await db
|
|
142
179
|
.selectFrom("graph_nodes")
|
|
143
180
|
.selectAll()
|
|
144
181
|
.execute();
|
|
145
|
-
const rawEdges = await
|
|
182
|
+
const rawEdges = await db
|
|
146
183
|
.selectFrom("graph_edges")
|
|
147
184
|
.selectAll()
|
|
148
185
|
.execute();
|
|
@@ -150,14 +187,21 @@ export class KnowledgeGraphSubgraph extends BaseSubgraph {
|
|
|
150
187
|
rawNodeCount: rawNodes.length,
|
|
151
188
|
rawEdgeCount: rawEdges.length,
|
|
152
189
|
rawNodes: rawNodes.map((r) => ({
|
|
153
|
-
id: r.id,
|
|
154
|
-
|
|
155
|
-
|
|
190
|
+
id: r.id,
|
|
191
|
+
documentId: r.document_id,
|
|
192
|
+
title: r.title,
|
|
193
|
+
description: r.description,
|
|
194
|
+
noteType: r.note_type,
|
|
195
|
+
status: r.status,
|
|
196
|
+
updatedAt: r.updated_at,
|
|
156
197
|
})),
|
|
157
198
|
rawEdges: rawEdges.map((r) => ({
|
|
158
|
-
id: r.id,
|
|
159
|
-
|
|
160
|
-
|
|
199
|
+
id: r.id,
|
|
200
|
+
sourceDocumentId: r.source_document_id,
|
|
201
|
+
targetDocumentId: r.target_document_id,
|
|
202
|
+
linkType: r.link_type,
|
|
203
|
+
targetTitle: r.target_title,
|
|
204
|
+
updatedAt: r.updated_at,
|
|
161
205
|
})),
|
|
162
206
|
processorNamespace: namespace,
|
|
163
207
|
};
|
|
@@ -165,8 +209,10 @@ export class KnowledgeGraphSubgraph extends BaseSubgraph {
|
|
|
165
209
|
catch (err) {
|
|
166
210
|
console.warn(`[KnowledgeGraphSubgraph] Debug query failed for ${namespace}:`, err);
|
|
167
211
|
return {
|
|
168
|
-
rawNodeCount: 0,
|
|
169
|
-
|
|
212
|
+
rawNodeCount: 0,
|
|
213
|
+
rawEdgeCount: 0,
|
|
214
|
+
rawNodes: [],
|
|
215
|
+
rawEdges: [],
|
|
170
216
|
processorNamespace: namespace,
|
|
171
217
|
};
|
|
172
218
|
}
|
|
@@ -176,11 +222,15 @@ export class KnowledgeGraphSubgraph extends BaseSubgraph {
|
|
|
176
222
|
constructor(args) {
|
|
177
223
|
super(args);
|
|
178
224
|
}
|
|
225
|
+
/**
|
|
226
|
+
* Returns a Kysely<DB> instance scoped to the processor's namespace
|
|
227
|
+
* for the given drive. Centralizes the Legacy → IRelationalDb cast.
|
|
228
|
+
*/
|
|
229
|
+
getDb(driveId) {
|
|
230
|
+
return GraphIndexerProcessor.query(driveId, this.relationalDb);
|
|
231
|
+
}
|
|
179
232
|
getQuery(driveId) {
|
|
180
|
-
|
|
181
|
-
// (same pattern as the working workstreams example)
|
|
182
|
-
const queryBuilder = GraphIndexerProcessor.query(driveId, this.relationalDb);
|
|
183
|
-
return createGraphQuery(queryBuilder);
|
|
233
|
+
return createGraphQuery(this.getDb(driveId));
|
|
184
234
|
}
|
|
185
235
|
/**
|
|
186
236
|
* Ensures a bai/knowledge-graph document exists in the given drive.
|
|
@@ -188,6 +238,76 @@ export class KnowledgeGraphSubgraph extends BaseSubgraph {
|
|
|
188
238
|
* requiring the Connect UI to have initialized the drive first.
|
|
189
239
|
*/
|
|
190
240
|
ensuredDrives = new Set();
|
|
241
|
+
async reindexDrive(driveId) {
|
|
242
|
+
const errors = [];
|
|
243
|
+
let indexedNodes = 0;
|
|
244
|
+
let indexedEdges = 0;
|
|
245
|
+
try {
|
|
246
|
+
const drive = await this.reactorClient.get(driveId);
|
|
247
|
+
const nodes = drive.state.global.nodes;
|
|
248
|
+
const noteNodes = nodes.filter((n) => n.kind === "file" && n.documentType === "bai/knowledge-note");
|
|
249
|
+
const db = this.getDb(driveId);
|
|
250
|
+
const now = new Date().toISOString();
|
|
251
|
+
for (const node of noteNodes) {
|
|
252
|
+
try {
|
|
253
|
+
const doc = await this.reactorClient.get(node.id);
|
|
254
|
+
const state = doc.state;
|
|
255
|
+
const global = state.global;
|
|
256
|
+
await db
|
|
257
|
+
.insertInto("graph_nodes")
|
|
258
|
+
.values({
|
|
259
|
+
id: node.id,
|
|
260
|
+
document_id: node.id,
|
|
261
|
+
title: global.title ?? null,
|
|
262
|
+
description: global.description ?? null,
|
|
263
|
+
note_type: global.noteType ?? null,
|
|
264
|
+
status: global.status ?? "DRAFT",
|
|
265
|
+
updated_at: now,
|
|
266
|
+
})
|
|
267
|
+
.onConflict((oc) => oc.column("document_id").doUpdateSet({
|
|
268
|
+
title: global.title ?? null,
|
|
269
|
+
description: global.description ?? null,
|
|
270
|
+
note_type: global.noteType ?? null,
|
|
271
|
+
status: global.status ?? "DRAFT",
|
|
272
|
+
updated_at: now,
|
|
273
|
+
}))
|
|
274
|
+
.execute();
|
|
275
|
+
indexedNodes++;
|
|
276
|
+
// Reconcile edges
|
|
277
|
+
await db
|
|
278
|
+
.deleteFrom("graph_edges")
|
|
279
|
+
.where("source_document_id", "=", node.id)
|
|
280
|
+
.execute();
|
|
281
|
+
const links = global.links ?? [];
|
|
282
|
+
if (links.length > 0) {
|
|
283
|
+
await db
|
|
284
|
+
.insertInto("graph_edges")
|
|
285
|
+
.values(links.map((link) => ({
|
|
286
|
+
id: link.id ??
|
|
287
|
+
`${node.id}-${link.targetDocumentId}`,
|
|
288
|
+
source_document_id: node.id,
|
|
289
|
+
target_document_id: link.targetDocumentId ?? "",
|
|
290
|
+
link_type: link.linkType ?? null,
|
|
291
|
+
target_title: link.targetTitle ?? null,
|
|
292
|
+
updated_at: now,
|
|
293
|
+
})))
|
|
294
|
+
.execute();
|
|
295
|
+
indexedEdges += links.length;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
catch (err) {
|
|
299
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
300
|
+
errors.push(`${node.id}: ${msg}`);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
console.log(`[KnowledgeGraphSubgraph] Reindex complete: ${indexedNodes} nodes, ${indexedEdges} edges, ${errors.length} errors`);
|
|
304
|
+
}
|
|
305
|
+
catch (err) {
|
|
306
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
307
|
+
errors.push(`Drive read failed: ${msg}`);
|
|
308
|
+
}
|
|
309
|
+
return { indexedNodes, indexedEdges, errors };
|
|
310
|
+
}
|
|
191
311
|
async ensureGraphDoc(driveId) {
|
|
192
312
|
if (this.ensuredDrives.has(driveId))
|
|
193
313
|
return;
|
|
@@ -205,7 +325,9 @@ export class KnowledgeGraphSubgraph extends BaseSubgraph {
|
|
|
205
325
|
parentIdentifier: parentFolder ?? driveId,
|
|
206
326
|
});
|
|
207
327
|
console.log(`[KnowledgeGraphSubgraph] Auto-created KnowledgeGraph in drive ${driveId}` +
|
|
208
|
-
(parentFolder
|
|
328
|
+
(parentFolder
|
|
329
|
+
? ` (folder: /self/)`
|
|
330
|
+
: ` (drive root — /self/ folder not found)`));
|
|
209
331
|
}
|
|
210
332
|
}
|
|
211
333
|
catch (err) {
|
|
@@ -41,7 +41,10 @@ describe("graph_nodes table", () => {
|
|
|
41
41
|
expect(row.status).toBe("CANONICAL");
|
|
42
42
|
expect(row.updated_at).toBe("2024-01-01T00:00:00Z");
|
|
43
43
|
// cleanup
|
|
44
|
-
await db
|
|
44
|
+
await db
|
|
45
|
+
.deleteFrom("graph_nodes")
|
|
46
|
+
.where("document_id", "=", "doc-1")
|
|
47
|
+
.execute();
|
|
45
48
|
});
|
|
46
49
|
});
|
|
47
50
|
describe("graph_edges table", () => {
|
|
@@ -232,7 +235,10 @@ describe("upsert on conflict", () => {
|
|
|
232
235
|
expect(rows[0].status).toBe("CANONICAL");
|
|
233
236
|
expect(rows[0].updated_at).toBe("2024-06-01T00:00:00Z");
|
|
234
237
|
// cleanup
|
|
235
|
-
await db
|
|
238
|
+
await db
|
|
239
|
+
.deleteFrom("graph_nodes")
|
|
240
|
+
.where("document_id", "=", docId)
|
|
241
|
+
.execute();
|
|
236
242
|
});
|
|
237
243
|
});
|
|
238
244
|
describe("edge reconciliation", () => {
|
|
@@ -4,7 +4,10 @@ import { reducer, utils, actions, } from "@powerhousedao/knowledge-note/document
|
|
|
4
4
|
describe("Content module — state mutations", () => {
|
|
5
5
|
it("SET_TITLE — updates state.global.title", () => {
|
|
6
6
|
const document = utils.createDocument();
|
|
7
|
-
const updated = reducer(document, actions.setTitle({
|
|
7
|
+
const updated = reducer(document, actions.setTitle({
|
|
8
|
+
title: "My Note Title",
|
|
9
|
+
updatedAt: "2026-01-01T00:00:00Z",
|
|
10
|
+
}));
|
|
8
11
|
expect(updated.state.global.title).toBe("My Note Title");
|
|
9
12
|
});
|
|
10
13
|
it("SET_DESCRIPTION — updates state.global.description", () => {
|
|
@@ -204,9 +204,21 @@ describe("Lifecycle state machine — DRAFT → IN_REVIEW → CANONICAL → ARCH
|
|
|
204
204
|
expect(restored.state.global.status).toBe("DRAFT");
|
|
205
205
|
expect(restored.state.global.lifecycleEvents).toHaveLength(4);
|
|
206
206
|
const events = restored.state.global.lifecycleEvents;
|
|
207
|
-
expect(events[0]).toMatchObject({
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
207
|
+
expect(events[0]).toMatchObject({
|
|
208
|
+
fromStatus: "DRAFT",
|
|
209
|
+
toStatus: "IN_REVIEW",
|
|
210
|
+
});
|
|
211
|
+
expect(events[1]).toMatchObject({
|
|
212
|
+
fromStatus: "IN_REVIEW",
|
|
213
|
+
toStatus: "CANONICAL",
|
|
214
|
+
});
|
|
215
|
+
expect(events[2]).toMatchObject({
|
|
216
|
+
fromStatus: "CANONICAL",
|
|
217
|
+
toStatus: "ARCHIVED",
|
|
218
|
+
});
|
|
219
|
+
expect(events[3]).toMatchObject({
|
|
220
|
+
fromStatus: "ARCHIVED",
|
|
221
|
+
toStatus: "DRAFT",
|
|
222
|
+
});
|
|
211
223
|
});
|
|
212
224
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { reducer, utils, actions } from "@powerhousedao/knowledge-note/document-models/moc/v1";
|
|
2
|
+
import { reducer, utils, actions, } from "@powerhousedao/knowledge-note/document-models/moc/v1";
|
|
3
3
|
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
|
4
4
|
/** Create a fresh MOC document with CREATE_MOC already applied. */
|
|
5
5
|
function makeInitialisedMoc() {
|
|
@@ -89,7 +89,10 @@ describe("PipelineQueue — queue management reducers", () => {
|
|
|
89
89
|
completedAt: "2026-01-01T03:00:00Z",
|
|
90
90
|
},
|
|
91
91
|
}));
|
|
92
|
-
expect(after2.state.global.tasks[0].completedPhases).toEqual([
|
|
92
|
+
expect(after2.state.global.tasks[0].completedPhases).toEqual([
|
|
93
|
+
"create",
|
|
94
|
+
"reflect",
|
|
95
|
+
]);
|
|
93
96
|
expect(after2.state.global.tasks[0].currentPhase).toBe("reweave");
|
|
94
97
|
});
|
|
95
98
|
// ── Test 4 ──────────────────────────────────────────────────────────────────
|
|
@@ -144,7 +147,12 @@ describe("PipelineQueue — queue management reducers", () => {
|
|
|
144
147
|
const task = completed.state.global.tasks[0];
|
|
145
148
|
expect(task.status).toBe("DONE");
|
|
146
149
|
expect(task.currentPhase).toBeNull();
|
|
147
|
-
expect(task.completedPhases).toEqual([
|
|
150
|
+
expect(task.completedPhases).toEqual([
|
|
151
|
+
"create",
|
|
152
|
+
"reflect",
|
|
153
|
+
"reweave",
|
|
154
|
+
"verify",
|
|
155
|
+
]);
|
|
148
156
|
expect(completed.state.global.completedCount).toBe(1);
|
|
149
157
|
expect(completed.state.global.activeCount).toBe(0);
|
|
150
158
|
});
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powerhousedao/knowledge-note",
|
|
3
3
|
"description": "Knowledge Note document model package for Powerhouse",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.3",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"files": [
|
|
8
8
|
"/dist"
|
|
9
9
|
],
|
|
10
|
-
|
|
10
|
+
"publishConfig": {
|
|
11
11
|
"access": "public"
|
|
12
12
|
},
|
|
13
13
|
"exports": {
|
|
@@ -113,7 +113,7 @@
|
|
|
113
113
|
"@powerhousedao/document-engineering": "1.40.1",
|
|
114
114
|
"@powerhousedao/vetra": "6.0.0-dev.105",
|
|
115
115
|
"cytoscape": "^3.33.1",
|
|
116
|
-
"cytoscape-
|
|
116
|
+
"cytoscape-fcose": "^2.2.0",
|
|
117
117
|
"document-model": "6.0.0-dev.105",
|
|
118
118
|
"graphql": "16.12.0",
|
|
119
119
|
"graphql-tag": "^2.12.6",
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { ProcessorRecord, IProcessorHostModule } from "@powerhousedao/reactor-browser";
|
|
2
|
-
import type { PHDocumentHeader } from "document-model";
|
|
3
|
-
export declare const methodologyIndexerProcessorFactory: (module: IProcessorHostModule) => (driveHeader: PHDocumentHeader) => Promise<ProcessorRecord[]>;
|
|
4
|
-
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../processors/methodology-indexer/factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,oBAAoB,EACrB,MAAM,gCAAgC,CAAC;AAExC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGvD,eAAO,MAAM,kCAAkC,GAC5C,QAAQ,oBAAoB,MACtB,aAAa,gBAAgB,KAAG,OAAO,CAAC,eAAe,EAAE,CAoC/D,CAAC"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import {} from "@powerhousedao/shared/processors";
|
|
2
|
-
import { MethodologyIndexerProcessor } from "./index.js";
|
|
3
|
-
export const methodologyIndexerProcessorFactory = (module) => async (driveHeader) => {
|
|
4
|
-
const namespace = MethodologyIndexerProcessor.getNamespace(driveHeader.id);
|
|
5
|
-
console.log(`[MethodologyIndexer] Factory called for drive: ${driveHeader.id}, namespace: ${namespace}`);
|
|
6
|
-
const store = await module.relationalDb.createNamespace(namespace);
|
|
7
|
-
const filter = {
|
|
8
|
-
branch: ["main"],
|
|
9
|
-
documentId: ["*"],
|
|
10
|
-
documentType: ["bai/research-claim", "powerhouse/document-drive"],
|
|
11
|
-
scope: ["global"],
|
|
12
|
-
};
|
|
13
|
-
const processor = new MethodologyIndexerProcessor(namespace, filter, store);
|
|
14
|
-
await processor.initAndUpgrade();
|
|
15
|
-
console.log(`[MethodologyIndexer] Processor created for drive: ${driveHeader.id}`);
|
|
16
|
-
return [
|
|
17
|
-
{
|
|
18
|
-
processor,
|
|
19
|
-
filter,
|
|
20
|
-
startFrom: "beginning",
|
|
21
|
-
},
|
|
22
|
-
];
|
|
23
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { RelationalDbProcessor } from "@powerhousedao/shared/processors";
|
|
2
|
-
import type { OperationWithContext } from "@powerhousedao/shared/document-model";
|
|
3
|
-
import type { MethodologyDB } from "./schema.js";
|
|
4
|
-
export declare class MethodologyIndexerProcessor extends RelationalDbProcessor<MethodologyDB> {
|
|
5
|
-
static getNamespace(driveId: string): string;
|
|
6
|
-
initAndUpgrade(): Promise<void>;
|
|
7
|
-
onOperations(operations: OperationWithContext[]): Promise<void>;
|
|
8
|
-
onDisconnect(): Promise<void>;
|
|
9
|
-
private deleteClaim;
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../processors/methodology-indexer/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AACzE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAEjF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,qBAAa,2BAA4B,SAAQ,qBAAqB,CAAC,aAAa,CAAC;WACnE,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAItC,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAI/B,YAAY,CACzB,UAAU,EAAE,oBAAoB,EAAE,GACjC,OAAO,CAAC,IAAI,CAAC;IAsGV,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;YAcrB,WAAW;CAkB1B"}
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { RelationalDbProcessor } from "@powerhousedao/shared/processors";
|
|
2
|
-
import { up } from "./migrations.js";
|
|
3
|
-
export class MethodologyIndexerProcessor extends RelationalDbProcessor {
|
|
4
|
-
static getNamespace(driveId) {
|
|
5
|
-
return super.getNamespace(driveId);
|
|
6
|
-
}
|
|
7
|
-
async initAndUpgrade() {
|
|
8
|
-
await up(this.relationalDb);
|
|
9
|
-
}
|
|
10
|
-
async onOperations(operations) {
|
|
11
|
-
if (operations.length === 0)
|
|
12
|
-
return;
|
|
13
|
-
const lastByDocument = new Map();
|
|
14
|
-
for (const entry of operations) {
|
|
15
|
-
const { operation, context } = entry;
|
|
16
|
-
const documentId = context.documentId;
|
|
17
|
-
// Handle deletion from drive
|
|
18
|
-
if (context.documentType === "powerhouse/document-drive" &&
|
|
19
|
-
operation.action.type === "DELETE_NODE") {
|
|
20
|
-
const deleteInput = operation.action.input;
|
|
21
|
-
await this.deleteClaim(deleteInput.id);
|
|
22
|
-
lastByDocument.delete(deleteInput.id);
|
|
23
|
-
continue;
|
|
24
|
-
}
|
|
25
|
-
// Only process research-claim documents
|
|
26
|
-
if (context.documentType !== "bai/research-claim")
|
|
27
|
-
continue;
|
|
28
|
-
if (context.resultingState) {
|
|
29
|
-
lastByDocument.set(documentId, entry);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
for (const [documentId, entry] of lastByDocument) {
|
|
33
|
-
try {
|
|
34
|
-
const stateJson = entry.context.resultingState;
|
|
35
|
-
if (!stateJson)
|
|
36
|
-
continue;
|
|
37
|
-
const parsed = JSON.parse(stateJson);
|
|
38
|
-
const global = (parsed.global ?? parsed);
|
|
39
|
-
const now = new Date().toISOString();
|
|
40
|
-
// Upsert claim
|
|
41
|
-
const topics = global.topics ?? [];
|
|
42
|
-
const methodology = global.methodology ?? [];
|
|
43
|
-
await this.relationalDb
|
|
44
|
-
.insertInto("methodology_claims")
|
|
45
|
-
.values({
|
|
46
|
-
id: documentId,
|
|
47
|
-
document_id: documentId,
|
|
48
|
-
title: global.title ?? null,
|
|
49
|
-
description: global.description ?? null,
|
|
50
|
-
kind: global.kind ?? null,
|
|
51
|
-
topics: JSON.stringify(topics),
|
|
52
|
-
methodology: JSON.stringify(methodology),
|
|
53
|
-
updated_at: now,
|
|
54
|
-
})
|
|
55
|
-
.onConflict((oc) => oc.column("document_id").doUpdateSet({
|
|
56
|
-
title: global.title ?? null,
|
|
57
|
-
description: global.description ?? null,
|
|
58
|
-
kind: global.kind ?? null,
|
|
59
|
-
topics: JSON.stringify(topics),
|
|
60
|
-
methodology: JSON.stringify(methodology),
|
|
61
|
-
updated_at: now,
|
|
62
|
-
}))
|
|
63
|
-
.execute();
|
|
64
|
-
// Reconcile connections
|
|
65
|
-
await this.relationalDb
|
|
66
|
-
.deleteFrom("methodology_connections")
|
|
67
|
-
.where("source_document_id", "=", documentId)
|
|
68
|
-
.execute();
|
|
69
|
-
const connections = global.connections ?? [];
|
|
70
|
-
if (connections.length > 0) {
|
|
71
|
-
await this.relationalDb
|
|
72
|
-
.insertInto("methodology_connections")
|
|
73
|
-
.values(connections.map((conn) => ({
|
|
74
|
-
id: conn.id ??
|
|
75
|
-
`${documentId}-${conn.targetRef}`,
|
|
76
|
-
source_document_id: documentId,
|
|
77
|
-
target_ref: conn.targetRef ?? "",
|
|
78
|
-
context_phrase: conn.contextPhrase ?? null,
|
|
79
|
-
updated_at: now,
|
|
80
|
-
})))
|
|
81
|
-
.execute();
|
|
82
|
-
}
|
|
83
|
-
console.log(`[MethodologyIndexer] Reconciled ${documentId}: ${connections.length} connections`);
|
|
84
|
-
}
|
|
85
|
-
catch (err) {
|
|
86
|
-
console.error(`[MethodologyIndexer] Error reconciling ${documentId}:`, err);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
async onDisconnect() {
|
|
91
|
-
try {
|
|
92
|
-
await this.relationalDb
|
|
93
|
-
.deleteFrom("methodology_connections")
|
|
94
|
-
.execute();
|
|
95
|
-
await this.relationalDb.deleteFrom("methodology_claims").execute();
|
|
96
|
-
console.log(`[MethodologyIndexer] Cleaned up namespace: ${this.namespace}`);
|
|
97
|
-
}
|
|
98
|
-
catch (err) {
|
|
99
|
-
console.error(`[MethodologyIndexer] Error cleaning up:`, err);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
async deleteClaim(documentId) {
|
|
103
|
-
try {
|
|
104
|
-
await this.relationalDb
|
|
105
|
-
.deleteFrom("methodology_connections")
|
|
106
|
-
.where("source_document_id", "=", documentId)
|
|
107
|
-
.execute();
|
|
108
|
-
await this.relationalDb
|
|
109
|
-
.deleteFrom("methodology_claims")
|
|
110
|
-
.where("document_id", "=", documentId)
|
|
111
|
-
.execute();
|
|
112
|
-
console.log(`[MethodologyIndexer] Deleted claim ${documentId}`);
|
|
113
|
-
}
|
|
114
|
-
catch (err) {
|
|
115
|
-
console.error(`[MethodologyIndexer] Error deleting claim ${documentId}:`, err);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../../../processors/methodology-indexer/migrations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AAEtE,wBAAsB,EAAE,CAAC,EAAE,EAAE,aAAa,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAqC9D;AAED,wBAAsB,IAAI,CAAC,EAAE,EAAE,aAAa,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAGhE"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
export async function up(db) {
|
|
2
|
-
await db.schema
|
|
3
|
-
.createTable("methodology_claims")
|
|
4
|
-
.addColumn("id", "varchar(255)", (col) => col.primaryKey())
|
|
5
|
-
.addColumn("document_id", "varchar(255)", (col) => col.notNull().unique())
|
|
6
|
-
.addColumn("title", "varchar(1024)")
|
|
7
|
-
.addColumn("description", "text")
|
|
8
|
-
.addColumn("kind", "varchar(100)")
|
|
9
|
-
.addColumn("topics", "text") // JSON array as string
|
|
10
|
-
.addColumn("methodology", "text") // JSON array as string
|
|
11
|
-
.addColumn("updated_at", "varchar(50)", (col) => col.notNull())
|
|
12
|
-
.ifNotExists()
|
|
13
|
-
.execute();
|
|
14
|
-
await db.schema
|
|
15
|
-
.createTable("methodology_connections")
|
|
16
|
-
.addColumn("id", "varchar(255)", (col) => col.primaryKey())
|
|
17
|
-
.addColumn("source_document_id", "varchar(255)", (col) => col.notNull())
|
|
18
|
-
.addColumn("target_ref", "varchar(255)", (col) => col.notNull())
|
|
19
|
-
.addColumn("context_phrase", "text")
|
|
20
|
-
.addColumn("updated_at", "varchar(50)", (col) => col.notNull())
|
|
21
|
-
.ifNotExists()
|
|
22
|
-
.execute();
|
|
23
|
-
await db.schema
|
|
24
|
-
.createIndex("idx_methodology_claims_kind")
|
|
25
|
-
.on("methodology_claims")
|
|
26
|
-
.column("kind")
|
|
27
|
-
.ifNotExists()
|
|
28
|
-
.execute();
|
|
29
|
-
await db.schema
|
|
30
|
-
.createIndex("idx_methodology_connections_source")
|
|
31
|
-
.on("methodology_connections")
|
|
32
|
-
.column("source_document_id")
|
|
33
|
-
.ifNotExists()
|
|
34
|
-
.execute();
|
|
35
|
-
}
|
|
36
|
-
export async function down(db) {
|
|
37
|
-
await db.schema.dropTable("methodology_connections").ifExists().execute();
|
|
38
|
-
await db.schema.dropTable("methodology_claims").ifExists().execute();
|
|
39
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { Kysely } from "kysely";
|
|
2
|
-
import type { MethodologyDB } from "./schema.js";
|
|
3
|
-
export interface ClaimResult {
|
|
4
|
-
id: string;
|
|
5
|
-
documentId: string;
|
|
6
|
-
title: string | null;
|
|
7
|
-
description: string | null;
|
|
8
|
-
kind: string | null;
|
|
9
|
-
topics: string[];
|
|
10
|
-
methodology: string[];
|
|
11
|
-
updatedAt: string;
|
|
12
|
-
}
|
|
13
|
-
export interface ConnectionResult {
|
|
14
|
-
id: string;
|
|
15
|
-
sourceDocumentId: string;
|
|
16
|
-
targetRef: string;
|
|
17
|
-
contextPhrase: string | null;
|
|
18
|
-
updatedAt: string;
|
|
19
|
-
}
|
|
20
|
-
export declare function createMethodologyQuery(db: Kysely<MethodologyDB>): {
|
|
21
|
-
allClaims(): Promise<ClaimResult[]>;
|
|
22
|
-
claimCount(): Promise<number>;
|
|
23
|
-
claimByDocumentId(documentId: string): Promise<ClaimResult | undefined>;
|
|
24
|
-
claimsByKind(kind: string): Promise<ClaimResult[]>;
|
|
25
|
-
searchClaims(query: string, limit?: number): Promise<ClaimResult[]>;
|
|
26
|
-
claimsByTopic(topic: string): Promise<ClaimResult[]>;
|
|
27
|
-
connectionsFrom(documentId: string): Promise<ConnectionResult[]>;
|
|
28
|
-
connectionsTo(targetRef: string): Promise<ConnectionResult[]>;
|
|
29
|
-
stats(): Promise<{
|
|
30
|
-
claimCount: number;
|
|
31
|
-
connectionCount: number;
|
|
32
|
-
kindDistribution: Record<string, number>;
|
|
33
|
-
}>;
|
|
34
|
-
};
|
|
35
|
-
//# sourceMappingURL=query.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../../processors/methodology-indexer/query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EAAE,aAAa,EAA2C,MAAM,aAAa,CAAC;AAE1F,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,gBAAgB,EAAE,MAAM,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAC;CACnB;AAyBD,wBAAgB,sBAAsB,CAAC,EAAE,EAAE,MAAM,CAAC,aAAa,CAAC;iBAEzC,OAAO,CAAC,WAAW,EAAE,CAAC;kBAKrB,OAAO,CAAC,MAAM,CAAC;kCAKC,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;uBASpD,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;wBAS9B,MAAM,mBAAe,OAAO,CAAC,WAAW,EAAE,CAAC;yBAiB1C,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;gCAUxB,MAAM,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;6BASvC,MAAM,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;aASpD,OAAO,CAAC;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,eAAe,EAAE,MAAM,CAAC;QAAC,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE,CAAC;EAiBpH"}
|