@lucern/graph-primitives 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -12
- package/dist/beliefDecay.js +24 -17
- package/dist/beliefDecay.js.map +1 -1
- package/dist/beliefEvidenceLinks.js +32 -8
- package/dist/beliefEvidenceLinks.js.map +1 -1
- package/dist/confidencePropagationDispatch.js.map +1 -1
- package/dist/contradictions.js +32 -9
- package/dist/contradictions.js.map +1 -1
- package/dist/convex.d.ts +55 -12
- package/dist/convex.js.map +1 -1
- package/dist/edgeValidation.d.ts +25 -2
- package/dist/edges/index.d.ts +9 -2
- package/dist/edges/index.js.map +1 -1
- package/dist/edges/propagationTypes.d.ts +2 -3
- package/dist/edges/propagationTypes.js.map +1 -1
- package/dist/entityBridge.js +10 -3
- package/dist/entityBridge.js.map +1 -1
- package/dist/entityLifecycle.js +15 -3
- package/dist/entityLifecycle.js.map +1 -1
- package/dist/epistemicAnswers.js.map +1 -1
- package/dist/epistemicBeliefs.admin.d.ts +36 -0
- package/dist/epistemicBeliefs.admin.js +745 -0
- package/dist/epistemicBeliefs.admin.js.map +1 -0
- package/dist/epistemicBeliefs.backfills.d.ts +62 -0
- package/dist/epistemicBeliefs.backfills.js +1004 -0
- package/dist/epistemicBeliefs.backfills.js.map +1 -0
- package/dist/epistemicBeliefs.confidence.d.ts +45 -0
- package/dist/epistemicBeliefs.confidence.js +1285 -0
- package/dist/epistemicBeliefs.confidence.js.map +1 -0
- package/dist/epistemicBeliefs.core.d.ts +35 -0
- package/dist/epistemicBeliefs.core.js +1508 -0
- package/dist/epistemicBeliefs.core.js.map +1 -0
- package/dist/epistemicBeliefs.d.ts +12 -3
- package/dist/epistemicBeliefs.helpers.d.ts +168 -0
- package/dist/epistemicBeliefs.helpers.js +1060 -0
- package/dist/epistemicBeliefs.helpers.js.map +1 -0
- package/dist/epistemicBeliefs.internal.d.ts +30 -0
- package/dist/epistemicBeliefs.internal.js +1329 -0
- package/dist/epistemicBeliefs.internal.js.map +1 -0
- package/dist/epistemicBeliefs.js +1196 -1184
- package/dist/epistemicBeliefs.js.map +1 -1
- package/dist/epistemicBeliefs.lifecycle.d.ts +19 -0
- package/dist/epistemicBeliefs.lifecycle.js +1608 -0
- package/dist/epistemicBeliefs.lifecycle.js.map +1 -0
- package/dist/epistemicBeliefs.links.d.ts +30 -0
- package/dist/epistemicBeliefs.links.js +761 -0
- package/dist/epistemicBeliefs.links.js.map +1 -0
- package/dist/epistemicBeliefs.queries.d.ts +16 -0
- package/dist/epistemicBeliefs.queries.js +90 -0
- package/dist/epistemicBeliefs.queries.js.map +1 -0
- package/dist/epistemicContractHelpers.d.ts +1 -1
- package/dist/epistemicContractHelpers.js +1 -1
- package/dist/epistemicContracts.d.ts +5 -76
- package/dist/epistemicContracts.evaluators.d.ts +36 -0
- package/dist/epistemicContracts.evaluators.js +2506 -0
- package/dist/epistemicContracts.evaluators.js.map +1 -0
- package/dist/epistemicContracts.handlers.d.ts +40 -0
- package/dist/epistemicContracts.handlers.js +3029 -0
- package/dist/epistemicContracts.handlers.js.map +1 -0
- package/dist/epistemicContracts.js +2006 -5281
- package/dist/epistemicContracts.js.map +1 -1
- package/dist/epistemicContracts.metrics.d.ts +26 -0
- package/dist/epistemicContracts.metrics.js +427 -0
- package/dist/epistemicContracts.metrics.js.map +1 -0
- package/dist/epistemicContracts.types.d.ts +159 -0
- package/dist/epistemicContracts.types.js +3 -0
- package/dist/epistemicContracts.types.js.map +1 -0
- package/dist/epistemicEdgeCreation.d.ts +73 -0
- package/dist/epistemicEdgeCreation.js +450 -0
- package/dist/epistemicEdgeCreation.js.map +1 -0
- package/dist/epistemicEdges-BF-cn4i3.d.ts +43 -0
- package/dist/epistemicEdges.d.ts +8 -1
- package/dist/epistemicEdges.handlers.d.ts +20 -0
- package/dist/epistemicEdges.handlers.js +289 -0
- package/dist/epistemicEdges.handlers.js.map +1 -0
- package/dist/epistemicEdges.helpers.d.ts +27 -0
- package/dist/epistemicEdges.helpers.js +162 -0
- package/dist/epistemicEdges.helpers.js.map +1 -0
- package/dist/epistemicEdges.js +797 -875
- package/dist/epistemicEdges.js.map +1 -1
- package/dist/epistemicEdges.mutations.d.ts +39 -0
- package/dist/epistemicEdges.mutations.js +1365 -0
- package/dist/epistemicEdges.mutations.js.map +1 -0
- package/dist/epistemicEdges.queries.d.ts +95 -0
- package/dist/epistemicEdges.queries.js +851 -0
- package/dist/epistemicEdges.queries.js.map +1 -0
- package/dist/epistemicEdges.types.d.ts +32 -0
- package/dist/epistemicEdges.types.js +3 -0
- package/dist/epistemicEdges.types.js.map +1 -0
- package/dist/epistemicEvidence-DvfchNt7.d.ts +46 -0
- package/dist/epistemicEvidence.d.ts +5 -2
- package/dist/epistemicEvidence.js +801 -807
- package/dist/epistemicEvidence.js.map +1 -1
- package/dist/epistemicEvidenceHelpers.d.ts +71 -0
- package/dist/epistemicEvidenceHelpers.js +769 -0
- package/dist/epistemicEvidenceHelpers.js.map +1 -0
- package/dist/epistemicEvidenceMutations.d.ts +10 -0
- package/dist/epistemicEvidenceMutations.js +1421 -0
- package/dist/epistemicEvidenceMutations.js.map +1 -0
- package/dist/epistemicEvidenceQueries.d.ts +10 -0
- package/dist/epistemicEvidenceQueries.js +1049 -0
- package/dist/epistemicEvidenceQueries.js.map +1 -0
- package/dist/epistemicHelpers.d.ts +4 -2
- package/dist/epistemicHelpers.js +132 -127
- package/dist/epistemicHelpers.js.map +1 -1
- package/dist/epistemicLayerRules.d.ts +138 -0
- package/dist/epistemicLayerRules.js +481 -0
- package/dist/epistemicLayerRules.js.map +1 -0
- package/dist/epistemicLinking.js +1 -1
- package/dist/epistemicLinking.js.map +1 -1
- package/dist/epistemicNodeCreation.d.ts +101 -0
- package/dist/epistemicNodeCreation.js +709 -0
- package/dist/epistemicNodeCreation.js.map +1 -0
- package/dist/epistemicNodes-BCQxpYx_.d.ts +54 -0
- package/dist/epistemicNodes.d.ts +5 -1
- package/dist/epistemicNodes.helpers.d.ts +51 -0
- package/dist/epistemicNodes.helpers.js +73 -0
- package/dist/epistemicNodes.helpers.js.map +1 -0
- package/dist/epistemicNodes.internal.d.ts +34 -0
- package/dist/epistemicNodes.internal.js +658 -0
- package/dist/epistemicNodes.internal.js.map +1 -0
- package/dist/epistemicNodes.js +698 -693
- package/dist/epistemicNodes.js.map +1 -1
- package/dist/epistemicNodes.mutations.d.ts +34 -0
- package/dist/epistemicNodes.mutations.js +1153 -0
- package/dist/epistemicNodes.mutations.js.map +1 -0
- package/dist/epistemicNodes.queries.d.ts +36 -0
- package/dist/epistemicNodes.queries.js +619 -0
- package/dist/epistemicNodes.queries.js.map +1 -0
- package/dist/epistemicNodes.validators.d.ts +23 -0
- package/dist/epistemicNodes.validators.js +105 -0
- package/dist/epistemicNodes.validators.js.map +1 -0
- package/dist/epistemicQuestions-bwHd2FWE.d.ts +68 -0
- package/dist/epistemicQuestions.conviction.d.ts +52 -0
- package/dist/epistemicQuestions.conviction.js +1389 -0
- package/dist/epistemicQuestions.conviction.js.map +1 -0
- package/dist/epistemicQuestions.create.d.ts +29 -0
- package/dist/epistemicQuestions.create.js +1300 -0
- package/dist/epistemicQuestions.create.js.map +1 -0
- package/dist/epistemicQuestions.d.ts +10 -2
- package/dist/epistemicQuestions.evidence.d.ts +22 -0
- package/dist/epistemicQuestions.evidence.js +929 -0
- package/dist/epistemicQuestions.evidence.js.map +1 -0
- package/dist/epistemicQuestions.helpers.d.ts +69 -0
- package/dist/epistemicQuestions.helpers.js +824 -0
- package/dist/epistemicQuestions.helpers.js.map +1 -0
- package/dist/epistemicQuestions.js +2435 -2430
- package/dist/epistemicQuestions.js.map +1 -1
- package/dist/epistemicQuestions.lifecycle.d.ts +24 -0
- package/dist/epistemicQuestions.lifecycle.js +838 -0
- package/dist/epistemicQuestions.lifecycle.js.map +1 -0
- package/dist/epistemicQuestions.queries.d.ts +41 -0
- package/dist/epistemicQuestions.queries.js +1013 -0
- package/dist/epistemicQuestions.queries.js.map +1 -0
- package/dist/epistemicQuestions.sprint.d.ts +22 -0
- package/dist/epistemicQuestions.sprint.js +757 -0
- package/dist/epistemicQuestions.sprint.js.map +1 -0
- package/dist/epistemicQuestions.tail.d.ts +42 -0
- package/dist/epistemicQuestions.tail.js +1345 -0
- package/dist/epistemicQuestions.tail.js.map +1 -0
- package/dist/epistemicSources.js +6 -2
- package/dist/epistemicSources.js.map +1 -1
- package/dist/evaluators/index.d.ts +2 -2
- package/dist/evaluators/index.js +45 -5320
- package/dist/evaluators/index.js.map +1 -1
- package/dist/evaluators/lintCheckerEvaluator.d.ts +1 -1
- package/dist/evaluators/sentryCheckerEvaluator.d.ts +1 -1
- package/dist/evaluators/testRunnerEvaluator.d.ts +1 -1
- package/dist/evaluators/tscCheckerEvaluator.d.ts +1 -1
- package/dist/{graphTypes-CpgIuCdo.d.ts → graphTypes-B8VaIjnl.d.ts} +1 -1
- package/dist/graphTypes.d.ts +1 -1
- package/dist/{helpers-BYHIk5vU.d.ts → helpers-DNYfg6mo.d.ts} +2 -3
- package/dist/helpers.d.ts +2 -2
- package/dist/helpers.js.map +1 -1
- package/dist/{index-Dq-7R-gi.d.ts → index-C-Kyd7hD.d.ts} +1 -1
- package/dist/index.d.ts +160 -14
- package/dist/index.js +12291 -13001
- package/dist/index.js.map +1 -1
- package/dist/logicalRoleInference.js.map +1 -1
- package/dist/ontologyApproval.js +1 -1
- package/dist/ontologyApproval.js.map +1 -1
- package/dist/ontologyDefinitions.js +25 -7
- package/dist/ontologyDefinitions.js.map +1 -1
- package/dist/ontologyRegistry.js.map +1 -1
- package/dist/projectionReconciliation.js.map +1 -1
- package/dist/questionEvidenceLinks.js +28 -7
- package/dist/questionEvidenceLinks.js.map +1 -1
- package/dist/resolvers.js.map +1 -1
- package/dist/scopeResolverCompat.js.map +1 -1
- package/dist/topicProjectOverlay.js.map +1 -1
- package/dist/topicScope.js.map +1 -1
- package/dist/workflowBridge.js.map +1 -1
- package/dist/workspaceIsolation.js.map +1 -1
- package/package.json +4 -5
- package/dist/edgeValidation-CeI0wc0r.d.ts +0 -35
- package/dist/epistemicBeliefs-DzKjZAeC.d.ts +0 -377
- package/dist/epistemicEdges-CvlKnEyy.d.ts +0 -191
- package/dist/epistemicEvidence-xw6UUrwh.d.ts +0 -128
- package/dist/epistemicHelpers-DevrYgPN.d.ts +0 -329
- package/dist/epistemicNodes-DjSUfvyD.d.ts +0 -167
- package/dist/epistemicQuestions-B_nUclrH.d.ts +0 -214
- package/dist/index-Dct1T70K.d.ts +0 -25
|
@@ -0,0 +1,709 @@
|
|
|
1
|
+
import { componentsGeneric, anyApi } from 'convex/server';
|
|
2
|
+
|
|
3
|
+
// src/globalId.ts
|
|
4
|
+
function generateGlobalId() {
|
|
5
|
+
const bytes = new Uint8Array(16);
|
|
6
|
+
crypto.getRandomValues(bytes);
|
|
7
|
+
bytes[6] = bytes[6] & 15 | 64;
|
|
8
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
9
|
+
const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join(
|
|
10
|
+
""
|
|
11
|
+
);
|
|
12
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
13
|
+
}
|
|
14
|
+
componentsGeneric();
|
|
15
|
+
var internal = anyApi;
|
|
16
|
+
|
|
17
|
+
// src/epistemicLayerRules.ts
|
|
18
|
+
function getNodeLayer(nodeType) {
|
|
19
|
+
switch (nodeType) {
|
|
20
|
+
// L4: Audit targets
|
|
21
|
+
case "decision":
|
|
22
|
+
return "L4";
|
|
23
|
+
// L3: Traversal anchors
|
|
24
|
+
case "belief":
|
|
25
|
+
case "question":
|
|
26
|
+
case "theme":
|
|
27
|
+
case "deal":
|
|
28
|
+
return "L3";
|
|
29
|
+
// L2: Compression boundary
|
|
30
|
+
case "claim":
|
|
31
|
+
case "evidence":
|
|
32
|
+
case "synthesis":
|
|
33
|
+
case "answer":
|
|
34
|
+
return "L2";
|
|
35
|
+
// L1: Terminal leaves
|
|
36
|
+
case "atomic_fact":
|
|
37
|
+
case "excerpt":
|
|
38
|
+
case "source":
|
|
39
|
+
return "L1";
|
|
40
|
+
// Ontological entities
|
|
41
|
+
case "company":
|
|
42
|
+
case "person":
|
|
43
|
+
case "investor":
|
|
44
|
+
case "function":
|
|
45
|
+
case "value_chain":
|
|
46
|
+
return "ontological";
|
|
47
|
+
// Organizational containers
|
|
48
|
+
case "topic":
|
|
49
|
+
return "organizational";
|
|
50
|
+
default:
|
|
51
|
+
console.warn(
|
|
52
|
+
`[EpistemicLayer] Unknown nodeType: ${nodeType}, defaulting to L2`
|
|
53
|
+
);
|
|
54
|
+
return "L2";
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
var EDGE_LAYER_RULES = {
|
|
58
|
+
// === L4 Decision Edges ===
|
|
59
|
+
based_on_belief: {
|
|
60
|
+
from: ["L4"],
|
|
61
|
+
to: ["L3"],
|
|
62
|
+
description: "Decision \u2192 Belief (L4 \u2192 L3)"
|
|
63
|
+
},
|
|
64
|
+
based_on_question: {
|
|
65
|
+
from: ["L4"],
|
|
66
|
+
to: ["L3"],
|
|
67
|
+
description: "Decision \u2192 Question (L4 \u2192 L3)"
|
|
68
|
+
},
|
|
69
|
+
blocked_by_contradiction: {
|
|
70
|
+
from: ["L4"],
|
|
71
|
+
to: ["L3"],
|
|
72
|
+
description: "Decision \u2192 Contradiction (L4 \u2192 L3)"
|
|
73
|
+
},
|
|
74
|
+
informed_by_theme: {
|
|
75
|
+
from: ["L4"],
|
|
76
|
+
to: ["L3"],
|
|
77
|
+
description: "Decision \u2192 Theme (L4 \u2192 L3)"
|
|
78
|
+
},
|
|
79
|
+
// === Evidence Flow (L2 → L3, L2 → L1) ===
|
|
80
|
+
derived_from: {
|
|
81
|
+
from: ["L2", "L3", "L4"],
|
|
82
|
+
to: ["L1", "L2", "L3"],
|
|
83
|
+
description: "A was produced from B (provenance chain)"
|
|
84
|
+
},
|
|
85
|
+
answers: {
|
|
86
|
+
from: ["L2"],
|
|
87
|
+
to: ["L3"],
|
|
88
|
+
description: "Evidence \u2192 Question (L2 \u2192 L3)"
|
|
89
|
+
},
|
|
90
|
+
responds_to: {
|
|
91
|
+
from: ["L2"],
|
|
92
|
+
to: ["L3"],
|
|
93
|
+
description: "Answer \u2192 Question (L2 \u2192 L3)"
|
|
94
|
+
},
|
|
95
|
+
informs: {
|
|
96
|
+
from: ["L2"],
|
|
97
|
+
to: ["L3"],
|
|
98
|
+
description: "Evidence \u2192 Belief (L2 \u2192 L3)"
|
|
99
|
+
},
|
|
100
|
+
qualifies: {
|
|
101
|
+
from: ["L2"],
|
|
102
|
+
to: ["L3"],
|
|
103
|
+
description: "Evidence \u2192 Belief (L2 \u2192 L3)"
|
|
104
|
+
},
|
|
105
|
+
// === Question → Belief (L3 → L3) ===
|
|
106
|
+
tests: {
|
|
107
|
+
from: ["L3"],
|
|
108
|
+
to: ["L3"],
|
|
109
|
+
description: "Question \u2192 Belief (L3 \u2192 L3)"
|
|
110
|
+
},
|
|
111
|
+
explores: {
|
|
112
|
+
from: ["L3"],
|
|
113
|
+
to: ["L3"],
|
|
114
|
+
description: "Question \u2192 Belief assumption (L3 \u2192 L3)"
|
|
115
|
+
},
|
|
116
|
+
// === Synthesis (L2 → L2, L2 → L1) ===
|
|
117
|
+
based_on: {
|
|
118
|
+
from: ["L2"],
|
|
119
|
+
to: ["L2", "L1"],
|
|
120
|
+
description: "Synthesis \u2192 Evidence/Source (L2 \u2192 L2/L1)"
|
|
121
|
+
},
|
|
122
|
+
// === Theme Relationships (L3 → L3) ===
|
|
123
|
+
relates_to_thesis: {
|
|
124
|
+
from: ["L3"],
|
|
125
|
+
to: ["L3"],
|
|
126
|
+
description: "Belief \u2192 Theme (L3 \u2192 L3)"
|
|
127
|
+
},
|
|
128
|
+
belongs_to: {
|
|
129
|
+
from: ["L3", "L2"],
|
|
130
|
+
// Can belong to theme from L3 or L2
|
|
131
|
+
to: ["L3"],
|
|
132
|
+
description: "Any \u2192 Theme (L3/L2 \u2192 L3)"
|
|
133
|
+
},
|
|
134
|
+
plays_theme: {
|
|
135
|
+
from: ["L3"],
|
|
136
|
+
to: ["L3"],
|
|
137
|
+
description: "Deal \u2192 Theme (L3 \u2192 L3)"
|
|
138
|
+
},
|
|
139
|
+
// === Topic Hierarchy (L3 → organizational) ===
|
|
140
|
+
scoped_by: {
|
|
141
|
+
from: ["L3"],
|
|
142
|
+
to: ["organizational"],
|
|
143
|
+
description: "Belief/Question \u2192 Topic (L3 \u2192 organizational)"
|
|
144
|
+
},
|
|
145
|
+
// === Deal/Company ===
|
|
146
|
+
evaluates: {
|
|
147
|
+
from: ["L3"],
|
|
148
|
+
to: ["ontological"],
|
|
149
|
+
description: "Deal \u2192 Company (L3 \u2192 ontological)"
|
|
150
|
+
},
|
|
151
|
+
// === People (ontological → ontological, ontological → L3) ===
|
|
152
|
+
perspective_on: {
|
|
153
|
+
from: ["ontological"],
|
|
154
|
+
to: ["L3"],
|
|
155
|
+
description: "Person \u2192 Belief/Theme (ontological \u2192 L3)"
|
|
156
|
+
},
|
|
157
|
+
works_at: {
|
|
158
|
+
from: ["ontological"],
|
|
159
|
+
to: ["ontological"],
|
|
160
|
+
description: "Person \u2192 Company (ontological \u2192 ontological)"
|
|
161
|
+
},
|
|
162
|
+
// === Value Chain (ontological) ===
|
|
163
|
+
participates_in: {
|
|
164
|
+
from: ["ontological"],
|
|
165
|
+
to: ["ontological"],
|
|
166
|
+
description: "Company \u2192 ValueChain (ontological \u2192 ontological)"
|
|
167
|
+
},
|
|
168
|
+
performs: {
|
|
169
|
+
from: ["ontological"],
|
|
170
|
+
to: ["ontological"],
|
|
171
|
+
description: "Company \u2192 Function (ontological \u2192 ontological)"
|
|
172
|
+
},
|
|
173
|
+
function_in: {
|
|
174
|
+
from: ["ontological"],
|
|
175
|
+
to: ["ontological"],
|
|
176
|
+
description: "Function \u2192 ValueChain (ontological \u2192 ontological)"
|
|
177
|
+
},
|
|
178
|
+
impacts: {
|
|
179
|
+
from: ["L3"],
|
|
180
|
+
to: ["ontological"],
|
|
181
|
+
description: "Theme \u2192 ValueChain (L3 \u2192 ontological)"
|
|
182
|
+
},
|
|
183
|
+
// === Investment (ontological) ===
|
|
184
|
+
invested_in: {
|
|
185
|
+
from: ["ontological"],
|
|
186
|
+
to: ["ontological"],
|
|
187
|
+
description: "Investor \u2192 Company (ontological \u2192 ontological)"
|
|
188
|
+
},
|
|
189
|
+
raised_from: {
|
|
190
|
+
from: ["ontological"],
|
|
191
|
+
to: ["ontological"],
|
|
192
|
+
description: "Company \u2192 Investor (ontological \u2192 ontological)"
|
|
193
|
+
},
|
|
194
|
+
// === Entity↔Belief Bridge (OE-B) ===
|
|
195
|
+
about_entity: {
|
|
196
|
+
from: ["L3"],
|
|
197
|
+
to: ["ontological"],
|
|
198
|
+
description: "Belief/Question/Theme \u2192 Entity (L3 \u2192 ontological)"
|
|
199
|
+
},
|
|
200
|
+
entity_referenced_in: {
|
|
201
|
+
from: ["ontological"],
|
|
202
|
+
to: ["L2"],
|
|
203
|
+
description: "Entity \u2192 Evidence (ontological \u2192 L2)"
|
|
204
|
+
},
|
|
205
|
+
mentioned_in: {
|
|
206
|
+
from: ["ontological"],
|
|
207
|
+
to: ["L1"],
|
|
208
|
+
description: "Entity \u2192 Source document (ontological \u2192 L1)"
|
|
209
|
+
},
|
|
210
|
+
founded_by: {
|
|
211
|
+
from: ["ontological"],
|
|
212
|
+
to: ["ontological"],
|
|
213
|
+
description: "Company \u2192 Person (ontological \u2192 ontological)"
|
|
214
|
+
},
|
|
215
|
+
competes_with: {
|
|
216
|
+
from: ["ontological"],
|
|
217
|
+
to: ["ontological"],
|
|
218
|
+
description: "Company \u2192 Company (ontological \u2192 ontological)"
|
|
219
|
+
},
|
|
220
|
+
contains: {
|
|
221
|
+
from: ["ontological"],
|
|
222
|
+
to: ["ontological"],
|
|
223
|
+
description: "ValueChain \u2192 Function (ontological \u2192 ontological)"
|
|
224
|
+
},
|
|
225
|
+
// === Lifecycle (same layer only) ===
|
|
226
|
+
supersedes: {
|
|
227
|
+
from: ["L4", "L3", "L2", "L1", "ontological", "organizational"],
|
|
228
|
+
to: ["L4", "L3", "L2", "L1", "ontological", "organizational"],
|
|
229
|
+
description: "NewNode \u2192 OldNode (same layer only - validated separately)"
|
|
230
|
+
},
|
|
231
|
+
same_as: {
|
|
232
|
+
from: ["L4", "L3", "L2", "L1", "ontological", "organizational"],
|
|
233
|
+
to: ["L4", "L3", "L2", "L1", "ontological", "organizational"],
|
|
234
|
+
description: "Duplicate detection (same layer only - validated separately)"
|
|
235
|
+
},
|
|
236
|
+
// === Same-Type: Belief ↔ Belief (L3 → L3) ===
|
|
237
|
+
depends_on: {
|
|
238
|
+
from: ["L3"],
|
|
239
|
+
to: ["L3"],
|
|
240
|
+
description: "Belief B requires Belief A (L3 \u2192 L3)"
|
|
241
|
+
},
|
|
242
|
+
reinforces: {
|
|
243
|
+
from: ["L3"],
|
|
244
|
+
to: ["L3"],
|
|
245
|
+
description: "Beliefs strengthen each other (L3 \u2192 L3)"
|
|
246
|
+
},
|
|
247
|
+
parent_of: {
|
|
248
|
+
from: ["L3", "organizational"],
|
|
249
|
+
to: ["L3", "organizational"],
|
|
250
|
+
description: "A is higher-level than B (L3 \u2192 L3, organizational \u2192 organizational)"
|
|
251
|
+
},
|
|
252
|
+
child_of: {
|
|
253
|
+
from: ["L3"],
|
|
254
|
+
to: ["L3"],
|
|
255
|
+
description: "Belief A is more specific (L3 \u2192 L3)"
|
|
256
|
+
},
|
|
257
|
+
// === Same-Type: Question ↔ Question (L3 → L3) ===
|
|
258
|
+
prerequisite_for: {
|
|
259
|
+
from: ["L3"],
|
|
260
|
+
to: ["L3"],
|
|
261
|
+
description: "Question A must be answered first (L3 \u2192 L3)"
|
|
262
|
+
},
|
|
263
|
+
parallel_to: {
|
|
264
|
+
from: ["L3"],
|
|
265
|
+
to: ["L3"],
|
|
266
|
+
description: "Same topic, different angles (L3 \u2192 L3)"
|
|
267
|
+
},
|
|
268
|
+
// === Same-Type: Evidence ↔ Evidence (L2 → L2) ===
|
|
269
|
+
corroborates: {
|
|
270
|
+
from: ["L2"],
|
|
271
|
+
to: ["L2"],
|
|
272
|
+
description: "Independent support (L2 \u2192 L2)"
|
|
273
|
+
},
|
|
274
|
+
extends: {
|
|
275
|
+
from: ["L2"],
|
|
276
|
+
to: ["L2"],
|
|
277
|
+
description: "Adds depth (L2 \u2192 L2)"
|
|
278
|
+
},
|
|
279
|
+
same_source_as: {
|
|
280
|
+
from: ["L2"],
|
|
281
|
+
to: ["L2"],
|
|
282
|
+
description: "Same document/study (L2 \u2192 L2)"
|
|
283
|
+
},
|
|
284
|
+
same_theme_as: {
|
|
285
|
+
from: ["L2"],
|
|
286
|
+
to: ["L2"],
|
|
287
|
+
description: "Same topic/entity (L2 \u2192 L2)"
|
|
288
|
+
},
|
|
289
|
+
// === NEW: Deep Epistemic Analysis Edges (Phase: Schema Upgrade) ===
|
|
290
|
+
assumes: {
|
|
291
|
+
from: ["L3"],
|
|
292
|
+
to: ["L3"],
|
|
293
|
+
description: "Hidden dependency - Belief B implicitly assumes Belief A (L3 \u2192 L3)"
|
|
294
|
+
},
|
|
295
|
+
would_predict: {
|
|
296
|
+
from: ["L3"],
|
|
297
|
+
to: ["L2"],
|
|
298
|
+
description: "Pre-registered prediction - If Belief true, expect Evidence (L3 \u2192 L2)"
|
|
299
|
+
},
|
|
300
|
+
analogous_to: {
|
|
301
|
+
from: ["L3"],
|
|
302
|
+
to: ["L3"],
|
|
303
|
+
description: "Explicit analogy - Belief A is like Belief B (L3 \u2192 L3)"
|
|
304
|
+
},
|
|
305
|
+
independent_of: {
|
|
306
|
+
from: ["L2"],
|
|
307
|
+
to: ["L2"],
|
|
308
|
+
description: "True evidence independence - Evidence A independent of B (L2 \u2192 L2)"
|
|
309
|
+
}
|
|
310
|
+
// NOTE: Deprecated edge types (supports, contradicts, derived_from, cites,
|
|
311
|
+
// summarizes, related_to, partially_answers, blocks, refines, branches_from)
|
|
312
|
+
// have been REMOVED from the system. Use compliant alternatives instead.
|
|
313
|
+
};
|
|
314
|
+
function validateEdgeLayers(edgeType, fromLayer, toLayer) {
|
|
315
|
+
const rules = EDGE_LAYER_RULES[edgeType];
|
|
316
|
+
if (!rules) {
|
|
317
|
+
console.warn(
|
|
318
|
+
`[EdgeValidation] Unknown edge type: ${edgeType}, allowing by default`
|
|
319
|
+
);
|
|
320
|
+
return { valid: true };
|
|
321
|
+
}
|
|
322
|
+
if (edgeType === "supersedes") {
|
|
323
|
+
if (fromLayer !== toLayer) {
|
|
324
|
+
return {
|
|
325
|
+
valid: false,
|
|
326
|
+
reason: `${edgeType} edges must be between nodes of the same layer. Got ${fromLayer} \u2192 ${toLayer}`
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
return { valid: true };
|
|
330
|
+
}
|
|
331
|
+
if (!rules.from.includes(fromLayer)) {
|
|
332
|
+
return {
|
|
333
|
+
valid: false,
|
|
334
|
+
reason: `Edge type '${edgeType}' does not allow source layer ${fromLayer}. Allowed: ${rules.from.join(", ")}`
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
if (!rules.to.includes(toLayer)) {
|
|
338
|
+
return {
|
|
339
|
+
valid: false,
|
|
340
|
+
reason: `Edge type '${edgeType}' does not allow target layer ${toLayer}. Allowed: ${rules.to.join(", ")}`
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
return { valid: true };
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// src/epistemicEdgeCreation.ts
|
|
347
|
+
async function createEpistemicEdge(ctx, params) {
|
|
348
|
+
const globalId = generateGlobalId();
|
|
349
|
+
const fromNode = await ctx.db.get(params.fromNodeId);
|
|
350
|
+
const toNode = await ctx.db.get(params.toNodeId);
|
|
351
|
+
if (!fromNode || !toNode) {
|
|
352
|
+
throw new Error("One or both nodes not found");
|
|
353
|
+
}
|
|
354
|
+
const fromLayer = fromNode.epistemicLayer || getNodeLayer(fromNode.nodeType);
|
|
355
|
+
const toLayer = toNode.epistemicLayer || getNodeLayer(toNode.nodeType);
|
|
356
|
+
if (!params.skipLayerValidation) {
|
|
357
|
+
const validation = validateEdgeLayers(params.edgeType, fromLayer, toLayer);
|
|
358
|
+
if (!validation.valid) {
|
|
359
|
+
throw new Error(
|
|
360
|
+
`[EdgeValidation] Invalid edge: ${validation.reason}. Attempted: ${params.edgeType} from ${fromNode.nodeType}(${fromLayer}) \u2192 ${toNode.nodeType}(${toLayer})`
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
await ctx.scheduler.runAfter(0, internal.neo4jEdgeAPI.createEdge, {
|
|
365
|
+
globalId,
|
|
366
|
+
fromGlobalId: fromNode.globalId,
|
|
367
|
+
toGlobalId: toNode.globalId,
|
|
368
|
+
edgeType: params.edgeType,
|
|
369
|
+
weight: params.weight,
|
|
370
|
+
confidence: params.confidence,
|
|
371
|
+
context: params.context,
|
|
372
|
+
createdBy: params.createdBy,
|
|
373
|
+
topicId: params.projectId ? String(params.projectId) : void 0,
|
|
374
|
+
fromNodeType: fromNode.nodeType,
|
|
375
|
+
toNodeType: toNode.nodeType,
|
|
376
|
+
fromLayer,
|
|
377
|
+
toLayer
|
|
378
|
+
});
|
|
379
|
+
return globalId;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// src/epistemicNodeCreation.ts
|
|
383
|
+
function generateContentHash(nodeType, text) {
|
|
384
|
+
const content = `${nodeType}:${normalizeText(text)}`;
|
|
385
|
+
let hash = 5381;
|
|
386
|
+
for (let i = 0; i < content.length; i++) {
|
|
387
|
+
hash = (hash << 5) + hash + content.charCodeAt(i);
|
|
388
|
+
hash &= hash;
|
|
389
|
+
}
|
|
390
|
+
const hashHex = Math.abs(hash).toString(16).padStart(8, "0");
|
|
391
|
+
const lengthHex = content.length.toString(16).padStart(4, "0");
|
|
392
|
+
const checksum = content.split("").reduce((a, c) => a + c.charCodeAt(0), 0).toString(16).padStart(8, "0");
|
|
393
|
+
return `${hashHex}${lengthHex}${checksum}`;
|
|
394
|
+
}
|
|
395
|
+
function normalizeText(text) {
|
|
396
|
+
return text.trim().toLowerCase().replace(/\s+/g, " ");
|
|
397
|
+
}
|
|
398
|
+
function mapInsightSourceType(sourceType) {
|
|
399
|
+
switch (sourceType) {
|
|
400
|
+
case "verified":
|
|
401
|
+
case "proprietary":
|
|
402
|
+
return "human";
|
|
403
|
+
case "ai_generated":
|
|
404
|
+
return "ai_generated";
|
|
405
|
+
default:
|
|
406
|
+
return "human";
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
function mapVerificationStatus(status) {
|
|
410
|
+
switch (status) {
|
|
411
|
+
case "manually_verified":
|
|
412
|
+
return "human_verified";
|
|
413
|
+
case "deep_verified":
|
|
414
|
+
case "pre_screened":
|
|
415
|
+
return "ai_verified";
|
|
416
|
+
default:
|
|
417
|
+
return "unverified";
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
async function createEpistemicNodeForInsight(ctx, _insightId, insight) {
|
|
421
|
+
const now = Date.now();
|
|
422
|
+
const globalId = generateGlobalId();
|
|
423
|
+
const contentHash = generateContentHash("evidence", insight.text);
|
|
424
|
+
const existing = await ctx.db.query("epistemicNodes").withIndex("by_contentHash", (q) => q.eq("contentHash", contentHash)).first();
|
|
425
|
+
if (existing && existing.status === "active") {
|
|
426
|
+
await ctx.db.patch(existing._id, {
|
|
427
|
+
updatedAt: now
|
|
428
|
+
});
|
|
429
|
+
return existing._id;
|
|
430
|
+
}
|
|
431
|
+
const nodeId = await ctx.db.insert("epistemicNodes", {
|
|
432
|
+
globalId,
|
|
433
|
+
nodeType: "evidence",
|
|
434
|
+
epistemicLayer: "L2",
|
|
435
|
+
// Evidence is at L2 (compression boundary)
|
|
436
|
+
canonicalText: insight.text,
|
|
437
|
+
contentHash,
|
|
438
|
+
title: insight.text.slice(0, 100) + (insight.text.length > 100 ? "..." : ""),
|
|
439
|
+
tags: insight.tags,
|
|
440
|
+
metadata: {
|
|
441
|
+
kind: insight.kind,
|
|
442
|
+
pillar: insight.tags?.find(
|
|
443
|
+
(t) => [
|
|
444
|
+
"market",
|
|
445
|
+
"competition",
|
|
446
|
+
"product",
|
|
447
|
+
"team",
|
|
448
|
+
"financials",
|
|
449
|
+
"regulatory",
|
|
450
|
+
"timing",
|
|
451
|
+
"customer",
|
|
452
|
+
"technology",
|
|
453
|
+
"distribution"
|
|
454
|
+
].includes(t)
|
|
455
|
+
),
|
|
456
|
+
// Include sourceArtifactId for source document panel
|
|
457
|
+
sourceArtifactId: insight.sourceArtifactId,
|
|
458
|
+
// Include sourceQuestionId if this evidence was created to answer a question
|
|
459
|
+
sourceQuestionId: insight.sourceQuestionId,
|
|
460
|
+
// Include sourceAnchor for linking evidence back to source documents
|
|
461
|
+
sourceAnchor: insight.sourceAnchor
|
|
462
|
+
},
|
|
463
|
+
sourceType: mapInsightSourceType(insight.sourceType),
|
|
464
|
+
aiProvider: insight.aiProvider,
|
|
465
|
+
confidence: insight.verificationStatus === "manually_verified" ? 0.9 : insight.verificationStatus === "deep_verified" ? 0.7 : insight.verificationStatus === "pre_screened" ? 0.5 : 0.3,
|
|
466
|
+
verificationStatus: mapVerificationStatus(insight.verificationStatus),
|
|
467
|
+
status: "active",
|
|
468
|
+
topicId: insight.projectId,
|
|
469
|
+
createdBy: insight.createdBy,
|
|
470
|
+
createdAt: now,
|
|
471
|
+
updatedAt: now
|
|
472
|
+
});
|
|
473
|
+
if (insight.sourceArtifactId) {
|
|
474
|
+
const sourceNode = await findOrCreateSourceNode(
|
|
475
|
+
ctx,
|
|
476
|
+
insight.sourceArtifactId,
|
|
477
|
+
insight.createdBy,
|
|
478
|
+
insight.projectId
|
|
479
|
+
);
|
|
480
|
+
if (sourceNode) {
|
|
481
|
+
await createEpistemicEdge(ctx, {
|
|
482
|
+
fromNodeId: nodeId,
|
|
483
|
+
toNodeId: sourceNode,
|
|
484
|
+
edgeType: "derived_from",
|
|
485
|
+
projectId: insight.projectId,
|
|
486
|
+
createdBy: insight.createdBy
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
return nodeId;
|
|
491
|
+
}
|
|
492
|
+
async function createEpistemicNodeForBelief(ctx, beliefId, belief) {
|
|
493
|
+
const now = Date.now();
|
|
494
|
+
const globalId = generateGlobalId();
|
|
495
|
+
const contentHash = generateContentHash("belief", belief.belief);
|
|
496
|
+
const existing = await ctx.db.query("epistemicNodes").withIndex("by_contentHash", (q) => q.eq("contentHash", contentHash)).first();
|
|
497
|
+
if (existing && existing.status === "active") {
|
|
498
|
+
await ctx.db.patch(existing._id, {
|
|
499
|
+
metadata: {
|
|
500
|
+
...existing.metadata || {},
|
|
501
|
+
sourceBeliefId: beliefId
|
|
502
|
+
},
|
|
503
|
+
updatedAt: now
|
|
504
|
+
});
|
|
505
|
+
return existing._id;
|
|
506
|
+
}
|
|
507
|
+
const nodeId = await ctx.db.insert("epistemicNodes", {
|
|
508
|
+
globalId,
|
|
509
|
+
nodeType: "belief",
|
|
510
|
+
epistemicLayer: "L3",
|
|
511
|
+
// Beliefs are at L3 (traversal anchors)
|
|
512
|
+
canonicalText: belief.belief,
|
|
513
|
+
contentHash,
|
|
514
|
+
content: belief.rationale,
|
|
515
|
+
title: belief.belief.slice(0, 100) + (belief.belief.length > 100 ? "..." : ""),
|
|
516
|
+
metadata: {
|
|
517
|
+
sourceBeliefId: beliefId,
|
|
518
|
+
beliefStatus: "assumption",
|
|
519
|
+
topic: belief.topic,
|
|
520
|
+
// Use 'topic' for consistency with legacy schema
|
|
521
|
+
pillar: belief.topic,
|
|
522
|
+
// Keep 'pillar' for backward compat with existing data
|
|
523
|
+
// No confidence/confidenceLevel — only set after sprint completion
|
|
524
|
+
rationale: belief.rationale,
|
|
525
|
+
status: "active",
|
|
526
|
+
// Include sourceAnchor for linking beliefs back to source documents
|
|
527
|
+
sourceAnchor: belief.sourceAnchor
|
|
528
|
+
},
|
|
529
|
+
beliefStatus: "assumption",
|
|
530
|
+
epistemicStatus: "assumption",
|
|
531
|
+
sourceType: "human",
|
|
532
|
+
confidence: void 0,
|
|
533
|
+
// No confidence until sprint completion
|
|
534
|
+
verificationStatus: "unverified",
|
|
535
|
+
status: "active",
|
|
536
|
+
topicId: belief.projectId,
|
|
537
|
+
createdBy: belief.createdBy,
|
|
538
|
+
createdAt: now,
|
|
539
|
+
updatedAt: now
|
|
540
|
+
});
|
|
541
|
+
return nodeId;
|
|
542
|
+
}
|
|
543
|
+
async function createEpistemicNodeForQuestion(ctx, _questionId, question) {
|
|
544
|
+
const now = Date.now();
|
|
545
|
+
const globalId = generateGlobalId();
|
|
546
|
+
const contentHash = generateContentHash("question", question.question);
|
|
547
|
+
const existing = await ctx.db.query("epistemicNodes").withIndex("by_contentHash", (q) => q.eq("contentHash", contentHash)).first();
|
|
548
|
+
if (existing && existing.status === "active") {
|
|
549
|
+
await ctx.db.patch(existing._id, {
|
|
550
|
+
updatedAt: now
|
|
551
|
+
});
|
|
552
|
+
return existing._id;
|
|
553
|
+
}
|
|
554
|
+
const sourceType = question.source === "manual" ? "human" : question.source === "ai_suggested" ? "ai_generated" : "ai_extracted";
|
|
555
|
+
const nodeId = await ctx.db.insert("epistemicNodes", {
|
|
556
|
+
globalId,
|
|
557
|
+
nodeType: "question",
|
|
558
|
+
epistemicLayer: "L3",
|
|
559
|
+
// Questions are at L3 (traversal anchors)
|
|
560
|
+
canonicalText: question.question,
|
|
561
|
+
contentHash,
|
|
562
|
+
title: question.question.slice(0, 100) + (question.question.length > 100 ? "..." : ""),
|
|
563
|
+
metadata: {
|
|
564
|
+
pillar: question.category,
|
|
565
|
+
priority: question.priority,
|
|
566
|
+
source: question.source,
|
|
567
|
+
// Include sourceAnchor for linking questions back to source documents
|
|
568
|
+
sourceAnchor: question.sourceAnchor
|
|
569
|
+
},
|
|
570
|
+
sourceType,
|
|
571
|
+
verificationStatus: "unverified",
|
|
572
|
+
status: "active",
|
|
573
|
+
topicId: question.projectId,
|
|
574
|
+
createdBy: question.createdBy,
|
|
575
|
+
createdAt: now,
|
|
576
|
+
updatedAt: now
|
|
577
|
+
});
|
|
578
|
+
return nodeId;
|
|
579
|
+
}
|
|
580
|
+
async function createEpistemicNodeForArtifact(ctx, artifactId, artifact) {
|
|
581
|
+
const now = Date.now();
|
|
582
|
+
const globalId = generateGlobalId();
|
|
583
|
+
let nodeType = "source";
|
|
584
|
+
const isSynthesis = artifact.isDeepResearch || artifact.type.includes("deep") || artifact.type.includes("research") || artifact.type.includes("primer");
|
|
585
|
+
if (isSynthesis) {
|
|
586
|
+
nodeType = "synthesis";
|
|
587
|
+
console.log(
|
|
588
|
+
`[EpistemicHelpers] Skipping synthesis node creation for "${artifact.type}" - will create when evidence is extracted`
|
|
589
|
+
);
|
|
590
|
+
const contentHash2 = generateContentHash(
|
|
591
|
+
nodeType,
|
|
592
|
+
artifact.title + artifact.content.slice(0, 500)
|
|
593
|
+
);
|
|
594
|
+
const existing2 = await ctx.db.query("epistemicNodes").withIndex("by_contentHash", (q) => q.eq("contentHash", contentHash2)).first();
|
|
595
|
+
if (existing2 && existing2.status === "active") {
|
|
596
|
+
return existing2._id;
|
|
597
|
+
}
|
|
598
|
+
throw new Error("SKIP_SYNTHESIS_NODE_CREATION");
|
|
599
|
+
}
|
|
600
|
+
const contentHash = generateContentHash(
|
|
601
|
+
nodeType,
|
|
602
|
+
artifact.title + artifact.content.slice(0, 500)
|
|
603
|
+
);
|
|
604
|
+
const existing = await ctx.db.query("epistemicNodes").withIndex("by_contentHash", (q) => q.eq("contentHash", contentHash)).first();
|
|
605
|
+
if (existing && existing.status === "active") {
|
|
606
|
+
await ctx.db.patch(existing._id, {
|
|
607
|
+
metadata: {
|
|
608
|
+
...existing.metadata || {},
|
|
609
|
+
legacyArtifactId: artifactId
|
|
610
|
+
},
|
|
611
|
+
updatedAt: now
|
|
612
|
+
});
|
|
613
|
+
return existing._id;
|
|
614
|
+
}
|
|
615
|
+
const epistemicLayer = "L1";
|
|
616
|
+
const nodeId = await ctx.db.insert("epistemicNodes", {
|
|
617
|
+
globalId,
|
|
618
|
+
nodeType,
|
|
619
|
+
epistemicLayer,
|
|
620
|
+
// Synthesis is L2, Source is L1
|
|
621
|
+
canonicalText: artifact.title,
|
|
622
|
+
contentHash,
|
|
623
|
+
content: artifact.content,
|
|
624
|
+
contentType: "markdown",
|
|
625
|
+
title: artifact.title,
|
|
626
|
+
metadata: {
|
|
627
|
+
legacyArtifactId: artifactId,
|
|
628
|
+
artifactType: artifact.type
|
|
629
|
+
},
|
|
630
|
+
sourceType: "ai_generated",
|
|
631
|
+
aiProvider: artifact.aiProvider || (artifact.isDeepResearch ? "gemini" : "anthropic"),
|
|
632
|
+
verificationStatus: "unverified",
|
|
633
|
+
status: "active",
|
|
634
|
+
topicId: artifact.projectId,
|
|
635
|
+
createdBy: artifact.createdBy,
|
|
636
|
+
createdAt: now,
|
|
637
|
+
updatedAt: now
|
|
638
|
+
});
|
|
639
|
+
return nodeId;
|
|
640
|
+
}
|
|
641
|
+
async function findOrCreateSourceNode(ctx, artifactId, createdBy, scopeProjectId) {
|
|
642
|
+
const artifact = await ctx.db.get(artifactId);
|
|
643
|
+
const effectiveProjectId = scopeProjectId || artifact?.projectId;
|
|
644
|
+
const effectiveTopicId = artifact?.topicId;
|
|
645
|
+
let existingNodes;
|
|
646
|
+
if (effectiveTopicId) {
|
|
647
|
+
existingNodes = await ctx.db.query("epistemicNodes").withIndex("by_topic", (q) => q.eq("topicId", effectiveTopicId)).collect();
|
|
648
|
+
} else {
|
|
649
|
+
existingNodes = await ctx.db.query("epistemicNodes").withIndex("by_nodeType", (q) => q.eq("nodeType", "source")).collect();
|
|
650
|
+
}
|
|
651
|
+
const existing = existingNodes.find((n) => {
|
|
652
|
+
if (effectiveProjectId && n.projectId && n.projectId !== effectiveProjectId) {
|
|
653
|
+
return false;
|
|
654
|
+
}
|
|
655
|
+
const metadata = n.metadata;
|
|
656
|
+
return metadata?.legacyArtifactId === artifactId;
|
|
657
|
+
});
|
|
658
|
+
if (existing) {
|
|
659
|
+
return existing._id;
|
|
660
|
+
}
|
|
661
|
+
if (!artifact) {
|
|
662
|
+
return null;
|
|
663
|
+
}
|
|
664
|
+
const now = Date.now();
|
|
665
|
+
const globalId = generateGlobalId();
|
|
666
|
+
const artifactType = artifact.metadata?.type || "";
|
|
667
|
+
const isDeepResearch = artifact.metadata?.isDeepResearch;
|
|
668
|
+
let nodeType = "source";
|
|
669
|
+
if (isDeepResearch || artifactType.includes("deep") || artifactType.includes("research")) {
|
|
670
|
+
nodeType = "synthesis";
|
|
671
|
+
} else if (artifactType.includes("primer")) {
|
|
672
|
+
nodeType = "synthesis";
|
|
673
|
+
}
|
|
674
|
+
const title = artifact.metadata?.title || artifact.metadata?.theme || "Untitled";
|
|
675
|
+
const contentHash = generateContentHash(
|
|
676
|
+
nodeType,
|
|
677
|
+
title + (artifact.content?.slice(0, 500) || "")
|
|
678
|
+
);
|
|
679
|
+
const epistemicLayer = nodeType === "synthesis" ? "L2" : "L1";
|
|
680
|
+
const nodeId = await ctx.db.insert("epistemicNodes", {
|
|
681
|
+
globalId,
|
|
682
|
+
nodeType,
|
|
683
|
+
epistemicLayer,
|
|
684
|
+
// Synthesis is L2, Source is L1
|
|
685
|
+
canonicalText: title,
|
|
686
|
+
contentHash,
|
|
687
|
+
content: artifact.content,
|
|
688
|
+
contentType: "markdown",
|
|
689
|
+
title,
|
|
690
|
+
metadata: {
|
|
691
|
+
legacyArtifactId: artifactId,
|
|
692
|
+
artifactType,
|
|
693
|
+
stage: artifact.stage
|
|
694
|
+
},
|
|
695
|
+
sourceType: isDeepResearch ? "ai_generated" : "ai_extracted",
|
|
696
|
+
aiProvider: isDeepResearch ? "gemini" : "anthropic",
|
|
697
|
+
verificationStatus: "unverified",
|
|
698
|
+
status: "active",
|
|
699
|
+
topicId: artifact.projectId,
|
|
700
|
+
createdBy,
|
|
701
|
+
createdAt: now,
|
|
702
|
+
updatedAt: now
|
|
703
|
+
});
|
|
704
|
+
return nodeId;
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
export { createEpistemicNodeForArtifact, createEpistemicNodeForBelief, createEpistemicNodeForInsight, createEpistemicNodeForQuestion };
|
|
708
|
+
//# sourceMappingURL=epistemicNodeCreation.js.map
|
|
709
|
+
//# sourceMappingURL=epistemicNodeCreation.js.map
|