@lucern/graph-primitives 1.0.0 → 1.0.2
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,43 @@
|
|
|
1
|
+
import { findContradictions, findSupport, get, getBetween, getByGlobalId, getByNodes, getByProject, getByProjectAndType, getBySourceNode, getByTargetNode, getClusterEdges, getEvidenceForBelief, getFromNode, getLineage, getToNode, listAll } from './epistemicEdges.queries.js';
|
|
2
|
+
import { batchCreate, cleanupDeprecatedEdges, create, deleteEdges, remove, removeBetween, update } from './epistemicEdges.mutations.js';
|
|
3
|
+
import { deleteEdgeFromConvex, mirrorEdgeToConvex, updateEdgeInConvex } from './epistemicEdges.handlers.js';
|
|
4
|
+
import { edgeTypeValidator, epistemicLayerValidator } from './epistemicEdges.helpers.js';
|
|
5
|
+
|
|
6
|
+
/** Facade for split epistemic edge primitives and public edge operations. */
|
|
7
|
+
|
|
8
|
+
declare const getByTopic: any;
|
|
9
|
+
|
|
10
|
+
declare const epistemicEdges_batchCreate: typeof batchCreate;
|
|
11
|
+
declare const epistemicEdges_cleanupDeprecatedEdges: typeof cleanupDeprecatedEdges;
|
|
12
|
+
declare const epistemicEdges_create: typeof create;
|
|
13
|
+
declare const epistemicEdges_deleteEdgeFromConvex: typeof deleteEdgeFromConvex;
|
|
14
|
+
declare const epistemicEdges_deleteEdges: typeof deleteEdges;
|
|
15
|
+
declare const epistemicEdges_edgeTypeValidator: typeof edgeTypeValidator;
|
|
16
|
+
declare const epistemicEdges_epistemicLayerValidator: typeof epistemicLayerValidator;
|
|
17
|
+
declare const epistemicEdges_findContradictions: typeof findContradictions;
|
|
18
|
+
declare const epistemicEdges_findSupport: typeof findSupport;
|
|
19
|
+
declare const epistemicEdges_get: typeof get;
|
|
20
|
+
declare const epistemicEdges_getBetween: typeof getBetween;
|
|
21
|
+
declare const epistemicEdges_getByGlobalId: typeof getByGlobalId;
|
|
22
|
+
declare const epistemicEdges_getByNodes: typeof getByNodes;
|
|
23
|
+
declare const epistemicEdges_getByProject: typeof getByProject;
|
|
24
|
+
declare const epistemicEdges_getByProjectAndType: typeof getByProjectAndType;
|
|
25
|
+
declare const epistemicEdges_getBySourceNode: typeof getBySourceNode;
|
|
26
|
+
declare const epistemicEdges_getByTargetNode: typeof getByTargetNode;
|
|
27
|
+
declare const epistemicEdges_getByTopic: typeof getByTopic;
|
|
28
|
+
declare const epistemicEdges_getClusterEdges: typeof getClusterEdges;
|
|
29
|
+
declare const epistemicEdges_getEvidenceForBelief: typeof getEvidenceForBelief;
|
|
30
|
+
declare const epistemicEdges_getFromNode: typeof getFromNode;
|
|
31
|
+
declare const epistemicEdges_getLineage: typeof getLineage;
|
|
32
|
+
declare const epistemicEdges_getToNode: typeof getToNode;
|
|
33
|
+
declare const epistemicEdges_listAll: typeof listAll;
|
|
34
|
+
declare const epistemicEdges_mirrorEdgeToConvex: typeof mirrorEdgeToConvex;
|
|
35
|
+
declare const epistemicEdges_remove: typeof remove;
|
|
36
|
+
declare const epistemicEdges_removeBetween: typeof removeBetween;
|
|
37
|
+
declare const epistemicEdges_update: typeof update;
|
|
38
|
+
declare const epistemicEdges_updateEdgeInConvex: typeof updateEdgeInConvex;
|
|
39
|
+
declare namespace epistemicEdges {
|
|
40
|
+
export { epistemicEdges_batchCreate as batchCreate, epistemicEdges_cleanupDeprecatedEdges as cleanupDeprecatedEdges, epistemicEdges_create as create, epistemicEdges_deleteEdgeFromConvex as deleteEdgeFromConvex, epistemicEdges_deleteEdges as deleteEdges, epistemicEdges_edgeTypeValidator as edgeTypeValidator, epistemicEdges_epistemicLayerValidator as epistemicLayerValidator, epistemicEdges_findContradictions as findContradictions, epistemicEdges_findSupport as findSupport, epistemicEdges_get as get, epistemicEdges_getBetween as getBetween, epistemicEdges_getByGlobalId as getByGlobalId, epistemicEdges_getByNodes as getByNodes, epistemicEdges_getByProject as getByProject, epistemicEdges_getByProjectAndType as getByProjectAndType, epistemicEdges_getBySourceNode as getBySourceNode, epistemicEdges_getByTargetNode as getByTargetNode, epistemicEdges_getByTopic as getByTopic, epistemicEdges_getClusterEdges as getClusterEdges, epistemicEdges_getEvidenceForBelief as getEvidenceForBelief, epistemicEdges_getFromNode as getFromNode, epistemicEdges_getLineage as getLineage, epistemicEdges_getToNode as getToNode, epistemicEdges_listAll as listAll, epistemicEdges_mirrorEdgeToConvex as mirrorEdgeToConvex, epistemicEdges_remove as remove, epistemicEdges_removeBetween as removeBetween, epistemicEdges_update as update, epistemicEdges_updateEdgeInConvex as updateEdgeInConvex };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { epistemicEdges as e, getByTopic as g };
|
package/dist/epistemicEdges.d.ts
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
|
+
export { findContradictions, findSupport, get, getBetween, getByGlobalId, getByNodes, getByProject, getByProjectAndType, getBySourceNode, getByTargetNode, getClusterEdges, getEvidenceForBelief, getFromNode, getLineage, getToNode, listAll } from './epistemicEdges.queries.js';
|
|
2
|
+
export { batchCreate, cleanupDeprecatedEdges, create, deleteEdges, remove, removeBetween, update } from './epistemicEdges.mutations.js';
|
|
3
|
+
export { deleteEdgeFromConvex, mirrorEdgeToConvex, updateEdgeInConvex } from './epistemicEdges.handlers.js';
|
|
4
|
+
export { edgeTypeValidator, epistemicLayerValidator } from './epistemicEdges.helpers.js';
|
|
5
|
+
export { g as getByTopic } from './epistemicEdges-BF-cn4i3.js';
|
|
1
6
|
import 'convex/values';
|
|
2
|
-
|
|
7
|
+
import './epistemicEdges.types.js';
|
|
8
|
+
import './topicScope-By_zp4tt.js';
|
|
9
|
+
import './convex.js';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal mutations for Neo4j/Convex dual-write edge mirroring.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Internal mutation to mirror a Neo4j edge to Convex for reactive UI.
|
|
6
|
+
* Called by createEdge action for edge types that need reactive UI updates.
|
|
7
|
+
*/
|
|
8
|
+
declare const mirrorEdgeToConvex: any;
|
|
9
|
+
/**
|
|
10
|
+
* Internal mutation to delete a mirrored edge from Convex.
|
|
11
|
+
* Called by deleteEdge action to maintain Convex mirror consistency.
|
|
12
|
+
*/
|
|
13
|
+
declare const deleteEdgeFromConvex: any;
|
|
14
|
+
/**
|
|
15
|
+
* Internal mutation to update a mirrored edge in Convex.
|
|
16
|
+
* Called by updateEdge action to maintain Convex mirror consistency.
|
|
17
|
+
*/
|
|
18
|
+
declare const updateEdgeInConvex: any;
|
|
19
|
+
|
|
20
|
+
export { deleteEdgeFromConvex, mirrorEdgeToConvex, updateEdgeInConvex };
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import { v } from 'convex/values';
|
|
2
|
+
import { permissiveReturn } from '@lucern/contracts/schema-helpers/validators';
|
|
3
|
+
import { componentsGeneric, internalMutationGeneric } from 'convex/server';
|
|
4
|
+
|
|
5
|
+
// src/epistemicEdges.handlers.ts
|
|
6
|
+
v.union(
|
|
7
|
+
v.literal("L4"),
|
|
8
|
+
v.literal("L3"),
|
|
9
|
+
v.literal("L2"),
|
|
10
|
+
v.literal("L1"),
|
|
11
|
+
v.literal("ontological"),
|
|
12
|
+
v.literal("organizational")
|
|
13
|
+
);
|
|
14
|
+
var subjectiveOpinionValidator = v.object({
|
|
15
|
+
b: v.number(),
|
|
16
|
+
d: v.number(),
|
|
17
|
+
u: v.number(),
|
|
18
|
+
a: v.number()
|
|
19
|
+
});
|
|
20
|
+
v.union(
|
|
21
|
+
// --- L4 Decision Edges (Phase 2A) ---
|
|
22
|
+
v.literal("based_on_belief"),
|
|
23
|
+
v.literal("based_on_question"),
|
|
24
|
+
v.literal("blocked_by_contradiction"),
|
|
25
|
+
v.literal("informed_by_theme"),
|
|
26
|
+
// --- Evidence Flow (L2 → L3, L2 → L1) ---
|
|
27
|
+
v.literal("derived_from"),
|
|
28
|
+
v.literal("responds_to"),
|
|
29
|
+
v.literal("informs"),
|
|
30
|
+
v.literal("tests"),
|
|
31
|
+
v.literal("explores"),
|
|
32
|
+
v.literal("qualifies"),
|
|
33
|
+
// --- Synthesis (L2 → L2, L2 → L1) ---
|
|
34
|
+
// "based_on" removed — use "derived_from" instead
|
|
35
|
+
// --- Theme Relationships (L3 → L3) ---
|
|
36
|
+
v.literal("relates_to_thesis"),
|
|
37
|
+
v.literal("belongs_to"),
|
|
38
|
+
v.literal("plays_theme"),
|
|
39
|
+
v.literal("scoped_by"),
|
|
40
|
+
// --- Deal/Company ---
|
|
41
|
+
v.literal("evaluates"),
|
|
42
|
+
// --- People (ontological → ontological, ontological → L3) ---
|
|
43
|
+
v.literal("perspective_on"),
|
|
44
|
+
v.literal("works_at"),
|
|
45
|
+
v.literal("mentioned_in"),
|
|
46
|
+
v.literal("founded_by"),
|
|
47
|
+
// --- Value Chain (ontological → ontological) ---
|
|
48
|
+
v.literal("participates_in"),
|
|
49
|
+
v.literal("performs"),
|
|
50
|
+
v.literal("function_in"),
|
|
51
|
+
v.literal("impacts"),
|
|
52
|
+
// --- Investment (ontological → ontological) ---
|
|
53
|
+
v.literal("invested_in"),
|
|
54
|
+
v.literal("raised_from"),
|
|
55
|
+
// --- Lifecycle (same layer only) ---
|
|
56
|
+
v.literal("supersedes"),
|
|
57
|
+
v.literal("same_as"),
|
|
58
|
+
// --- Same-Type Relationships: Belief ↔ Belief (L3 → L3) ---
|
|
59
|
+
v.literal("depends_on"),
|
|
60
|
+
v.literal("supports"),
|
|
61
|
+
v.literal("contains"),
|
|
62
|
+
// --- Belief Cluster Mapping (L3 → L3) ---
|
|
63
|
+
v.literal("counterfactual_of"),
|
|
64
|
+
v.literal("cascade_to"),
|
|
65
|
+
v.literal("cascade_from"),
|
|
66
|
+
v.literal("mutually_exclusive"),
|
|
67
|
+
v.literal("correlates_with"),
|
|
68
|
+
v.literal("amplifies"),
|
|
69
|
+
v.literal("precondition_for"),
|
|
70
|
+
v.literal("in_tension_with"),
|
|
71
|
+
// --- Belief ↔ Belief: Epistemic Impact (Confidence Propagation) ---
|
|
72
|
+
v.literal("falsified_by"),
|
|
73
|
+
v.literal("exclusive_with"),
|
|
74
|
+
v.literal("contradicts"),
|
|
75
|
+
v.literal("collapses_if"),
|
|
76
|
+
v.literal("strengthened_by"),
|
|
77
|
+
v.literal("weakened_by"),
|
|
78
|
+
v.literal("alternative_to"),
|
|
79
|
+
v.literal("subsumes"),
|
|
80
|
+
v.literal("validated_by"),
|
|
81
|
+
v.literal("required_for"),
|
|
82
|
+
v.literal("blocks"),
|
|
83
|
+
// --- Same-Type Relationships: Question ↔ Question (L3 → L3) ---
|
|
84
|
+
v.literal("prerequisite_for"),
|
|
85
|
+
v.literal("parallel_to"),
|
|
86
|
+
// --- Same-Type Relationships: Evidence ↔ Evidence (L2 → L2) ---
|
|
87
|
+
v.literal("corroborates"),
|
|
88
|
+
v.literal("extends"),
|
|
89
|
+
v.literal("same_source_as"),
|
|
90
|
+
v.literal("same_theme_as"),
|
|
91
|
+
// --- NEW: Deep Epistemic Analysis Edges (Phase: Schema Upgrade) ---
|
|
92
|
+
v.literal("assumes"),
|
|
93
|
+
v.literal("would_predict"),
|
|
94
|
+
v.literal("analogous_to"),
|
|
95
|
+
v.literal("independent_of"),
|
|
96
|
+
// --- Entity↔Belief Bridge (OE-B) ---
|
|
97
|
+
v.literal("competes_with")
|
|
98
|
+
);
|
|
99
|
+
function buildEdgeStatusSuccessResult() {
|
|
100
|
+
return { success: true };
|
|
101
|
+
}
|
|
102
|
+
function buildEdgeMirrorSkippedResult() {
|
|
103
|
+
return {
|
|
104
|
+
success: false,
|
|
105
|
+
reason: "source_not_in_convex"
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function buildEdgeMirrorMissingResult() {
|
|
109
|
+
return {
|
|
110
|
+
success: false,
|
|
111
|
+
reason: "not_found"
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
function buildEdgeMirrorWriteResult(edgeId, existed) {
|
|
115
|
+
return {
|
|
116
|
+
success: true,
|
|
117
|
+
edgeId,
|
|
118
|
+
existed
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
componentsGeneric();
|
|
122
|
+
var internalMutation = internalMutationGeneric;
|
|
123
|
+
|
|
124
|
+
// src/topicScope.ts
|
|
125
|
+
var optionalScopeArgs = {
|
|
126
|
+
projectId: v.optional(v.string()),
|
|
127
|
+
topicId: v.optional(v.string())
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
// src/epistemicEdges.handlers.ts
|
|
131
|
+
var mirrorEdgeToConvex = internalMutation({
|
|
132
|
+
args: {
|
|
133
|
+
globalId: v.string(),
|
|
134
|
+
fromGlobalId: v.string(),
|
|
135
|
+
toGlobalId: v.string(),
|
|
136
|
+
edgeType: v.string(),
|
|
137
|
+
weight: v.optional(v.number()),
|
|
138
|
+
confidence: v.optional(v.number()),
|
|
139
|
+
context: v.optional(v.string()),
|
|
140
|
+
derivationType: v.optional(v.string()),
|
|
141
|
+
createdBy: v.string(),
|
|
142
|
+
...optionalScopeArgs,
|
|
143
|
+
fromLayer: v.optional(v.string()),
|
|
144
|
+
toLayer: v.optional(v.string()),
|
|
145
|
+
fromNodeType: v.optional(v.string()),
|
|
146
|
+
toNodeType: v.optional(v.string()),
|
|
147
|
+
reasoningMethod: v.optional(v.string()),
|
|
148
|
+
logicalRole: v.optional(v.string()),
|
|
149
|
+
temporalClass: v.optional(v.string()),
|
|
150
|
+
validFrom: v.optional(v.number()),
|
|
151
|
+
validUntil: v.optional(v.number()),
|
|
152
|
+
constraint: v.optional(v.string()),
|
|
153
|
+
propagation: v.optional(v.string()),
|
|
154
|
+
blocking: v.optional(v.boolean()),
|
|
155
|
+
implicit: v.optional(v.boolean()),
|
|
156
|
+
conditionalA: v.optional(subjectiveOpinionValidator),
|
|
157
|
+
conditionalNotA: v.optional(subjectiveOpinionValidator)
|
|
158
|
+
},
|
|
159
|
+
returns: permissiveReturn,
|
|
160
|
+
handler: async (ctx, args) => {
|
|
161
|
+
const fromNode = await ctx.db.query("epistemicNodes").withIndex("by_globalId", (q) => q.eq("globalId", args.fromGlobalId)).first();
|
|
162
|
+
if (!fromNode) {
|
|
163
|
+
console.log(
|
|
164
|
+
`[Dual-Write] Skipping mirror - source node not in Convex: ${args.fromGlobalId}`
|
|
165
|
+
);
|
|
166
|
+
return buildEdgeMirrorSkippedResult();
|
|
167
|
+
}
|
|
168
|
+
const toNode = await ctx.db.query("epistemicNodes").withIndex("by_globalId", (q) => q.eq("globalId", args.toGlobalId)).first();
|
|
169
|
+
const existing = await ctx.db.query("epistemicEdges").withIndex("by_globalId", (q) => q.eq("globalId", args.globalId)).first();
|
|
170
|
+
if (existing) {
|
|
171
|
+
console.log(`[Dual-Write] Edge already exists: ${args.globalId}`);
|
|
172
|
+
return buildEdgeMirrorWriteResult(existing._id, true);
|
|
173
|
+
}
|
|
174
|
+
const now = Date.now();
|
|
175
|
+
const edgeId = await ctx.db.insert("epistemicEdges", {
|
|
176
|
+
globalId: args.globalId,
|
|
177
|
+
fromNodeId: fromNode._id,
|
|
178
|
+
toNodeId: toNode?._id,
|
|
179
|
+
sourceGlobalId: args.fromGlobalId,
|
|
180
|
+
targetGlobalId: args.toGlobalId,
|
|
181
|
+
// Preserve the canonical string value even when the local schema lags.
|
|
182
|
+
edgeType: args.edgeType,
|
|
183
|
+
weight: args.weight,
|
|
184
|
+
confidence: args.confidence,
|
|
185
|
+
context: args.context,
|
|
186
|
+
derivationType: args.derivationType,
|
|
187
|
+
constraint: args.constraint,
|
|
188
|
+
propagation: args.propagation,
|
|
189
|
+
blocking: args.blocking,
|
|
190
|
+
implicit: args.implicit,
|
|
191
|
+
conditionalA: args.conditionalA,
|
|
192
|
+
conditionalNotA: args.conditionalNotA,
|
|
193
|
+
createdBy: args.createdBy,
|
|
194
|
+
createdAt: now,
|
|
195
|
+
updatedAt: now,
|
|
196
|
+
topicId: args.projectId,
|
|
197
|
+
fromLayer: args.fromLayer,
|
|
198
|
+
toLayer: args.toLayer,
|
|
199
|
+
fromNodeType: args.fromNodeType,
|
|
200
|
+
toNodeType: args.toNodeType,
|
|
201
|
+
reasoningMethod: args.reasoningMethod,
|
|
202
|
+
logicalRole: args.logicalRole,
|
|
203
|
+
temporalClass: args.temporalClass,
|
|
204
|
+
validFrom: args.validFrom,
|
|
205
|
+
validUntil: args.validUntil
|
|
206
|
+
});
|
|
207
|
+
console.log(
|
|
208
|
+
`[Dual-Write] Mirrored edge to Convex: ${args.globalId} (${args.edgeType})`
|
|
209
|
+
);
|
|
210
|
+
return buildEdgeMirrorWriteResult(edgeId, false);
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
var deleteEdgeFromConvex = internalMutation({
|
|
214
|
+
args: {
|
|
215
|
+
globalId: v.string()
|
|
216
|
+
},
|
|
217
|
+
returns: permissiveReturn,
|
|
218
|
+
handler: async (ctx, args) => {
|
|
219
|
+
const existing = await ctx.db.query("epistemicEdges").withIndex("by_globalId", (q) => q.eq("globalId", args.globalId)).first();
|
|
220
|
+
if (!existing) {
|
|
221
|
+
return buildEdgeMirrorMissingResult();
|
|
222
|
+
}
|
|
223
|
+
await ctx.db.delete(existing._id);
|
|
224
|
+
console.log(`[Dual-Write] Deleted edge from Convex: ${args.globalId}`);
|
|
225
|
+
return buildEdgeStatusSuccessResult();
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
var updateEdgeInConvex = internalMutation({
|
|
229
|
+
args: {
|
|
230
|
+
globalId: v.string(),
|
|
231
|
+
weight: v.optional(v.number()),
|
|
232
|
+
confidence: v.optional(v.number()),
|
|
233
|
+
context: v.optional(v.string()),
|
|
234
|
+
derivationType: v.optional(v.string()),
|
|
235
|
+
constraint: v.optional(v.string()),
|
|
236
|
+
propagation: v.optional(v.string()),
|
|
237
|
+
blocking: v.optional(v.boolean()),
|
|
238
|
+
implicit: v.optional(v.boolean()),
|
|
239
|
+
conditionalA: v.optional(subjectiveOpinionValidator),
|
|
240
|
+
conditionalNotA: v.optional(subjectiveOpinionValidator)
|
|
241
|
+
},
|
|
242
|
+
returns: permissiveReturn,
|
|
243
|
+
handler: async (ctx, args) => {
|
|
244
|
+
const existing = await ctx.db.query("epistemicEdges").withIndex("by_globalId", (q) => q.eq("globalId", args.globalId)).first();
|
|
245
|
+
if (!existing) {
|
|
246
|
+
return buildEdgeMirrorMissingResult();
|
|
247
|
+
}
|
|
248
|
+
const updates = {
|
|
249
|
+
updatedAt: Date.now()
|
|
250
|
+
};
|
|
251
|
+
if (args.weight !== void 0) {
|
|
252
|
+
updates.weight = args.weight;
|
|
253
|
+
}
|
|
254
|
+
if (args.confidence !== void 0) {
|
|
255
|
+
updates.confidence = args.confidence;
|
|
256
|
+
}
|
|
257
|
+
if (args.context !== void 0) {
|
|
258
|
+
updates.context = args.context;
|
|
259
|
+
}
|
|
260
|
+
if (args.derivationType !== void 0) {
|
|
261
|
+
updates.derivationType = args.derivationType;
|
|
262
|
+
}
|
|
263
|
+
if (args.constraint !== void 0) {
|
|
264
|
+
updates.constraint = args.constraint;
|
|
265
|
+
}
|
|
266
|
+
if (args.propagation !== void 0) {
|
|
267
|
+
updates.propagation = args.propagation;
|
|
268
|
+
}
|
|
269
|
+
if (args.blocking !== void 0) {
|
|
270
|
+
updates.blocking = args.blocking;
|
|
271
|
+
}
|
|
272
|
+
if (args.implicit !== void 0) {
|
|
273
|
+
updates.implicit = args.implicit;
|
|
274
|
+
}
|
|
275
|
+
if (args.conditionalA !== void 0) {
|
|
276
|
+
updates.conditionalA = args.conditionalA;
|
|
277
|
+
}
|
|
278
|
+
if (args.conditionalNotA !== void 0) {
|
|
279
|
+
updates.conditionalNotA = args.conditionalNotA;
|
|
280
|
+
}
|
|
281
|
+
await ctx.db.patch(existing._id, updates);
|
|
282
|
+
console.log(`[Dual-Write] Updated edge in Convex: ${args.globalId}`);
|
|
283
|
+
return buildEdgeStatusSuccessResult();
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
export { deleteEdgeFromConvex, mirrorEdgeToConvex, updateEdgeInConvex };
|
|
288
|
+
//# sourceMappingURL=epistemicEdges.handlers.js.map
|
|
289
|
+
//# sourceMappingURL=epistemicEdges.handlers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/epistemicEdges.helpers.ts","../src/convex.ts","../src/topicScope.ts","../src/epistemicEdges.handlers.ts"],"names":["v"],"mappings":";;;;;AAiBuC,CAAA,CAAE,KAAA;AAAA,EACvC,CAAA,CAAE,QAAQ,IAAI,CAAA;AAAA,EACd,CAAA,CAAE,QAAQ,IAAI,CAAA;AAAA,EACd,CAAA,CAAE,QAAQ,IAAI,CAAA;AAAA,EACd,CAAA,CAAE,QAAQ,IAAI,CAAA;AAAA,EACd,CAAA,CAAE,QAAQ,aAAa,CAAA;AAAA,EACvB,CAAA,CAAE,QAAQ,gBAAgB;AAC5B;AAEO,IAAM,0BAAA,GAA6B,EAAE,MAAA,CAAO;AAAA,EACjD,CAAA,EAAG,EAAE,MAAA,EAAO;AAAA,EACZ,CAAA,EAAG,EAAE,MAAA,EAAO;AAAA,EACZ,CAAA,EAAG,EAAE,MAAA,EAAO;AAAA,EACZ,CAAA,EAAG,EAAE,MAAA;AACP,CAA4D,CAAA;AAE3B,CAAA,CAAE,KAAA;AAAA;AAAA,EAEjC,CAAA,CAAE,QAAQ,iBAAiB,CAAA;AAAA,EAC3B,CAAA,CAAE,QAAQ,mBAAmB,CAAA;AAAA,EAC7B,CAAA,CAAE,QAAQ,0BAA0B,CAAA;AAAA,EACpC,CAAA,CAAE,QAAQ,mBAAmB,CAAA;AAAA;AAAA,EAG7B,CAAA,CAAE,QAAQ,cAAc,CAAA;AAAA,EACxB,CAAA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K,UAAA;AAAA,IAC5B;AACA,IAAA,IAAI,IAAA,CAAK,gBAAgB,MAAA,EAAW;AAClC,MAAA,OAAA,CAAQ,cAAc,IAAA,CAAK,WAAA;AAAA,IAC7B;AACA,IAAA,IAAI,IAAA,CAAK,aAAa,MAAA,EAAW;AAC/B,MAAA,OAAA,CAAQ,WAAW,IAAA,CAAK,QAAA;AAAA,IAC1B;AACA,IAAA,IAAI,IAAA,CAAK,aAAa,MAAA,EAAW;AAC/B,MAAA,OAAA,CAAQ,WAAW,IAAA,CAAK,QAAA;AAAA,IAC1B;AACA,IAAA,IAAI,IAAA,CAAK,iBAAiB,MAAA,EAAW;AACnC,MAAA,OAAA,CAAQ,eAAe,IAAA,CAAK,YAAA;AAAA,IAC9B;AACA,IAAA,IAAI,IAAA,CAAK,oBAAoB,MAAA,EAAW;AACtC,MAAA,OAAA,CAAQ,kBAAkB,IAAA,CAAK,eAAA;AAAA,IACjC;AAEA,IAAA,MAAM,GAAA,CAAI,EAAA,CAAG,KAAA,CAAM,QAAA,CAAS,KAAK,OAAO,CAAA;AACxC,IAAA,OAAA,CAAQ,GAAA,CAAI,CAAA,qCAAA,EAAwC,IAAA,CAAK,QAAQ,CAAA,CAAE,CAAA;AAEnE,IAAA,OAAO,4BAAA,EAA6B;AAAA,EACtC;AACF,CAAC","file":"epistemicEdges.handlers.js","sourcesContent":["/**\n * Shared validators and private helpers for epistemic edge operations.\n */\n\nimport { v } from \"convex/values\";\nimport type {\n EdgeStatusResult,\n SubjectiveOpinionDocument,\n WorkspaceEdgeScope,\n WorkspaceScopedEdge,\n} from \"./epistemicEdges.types\";\nimport type { Id, QueryCtx } from \"./convex\";\n\ntype TopicIndexQuery = {\n eq(field: string, value: unknown): TopicIndexQuery;\n};\n\nexport const epistemicLayerValidator = v.union(\n v.literal(\"L4\"),\n v.literal(\"L3\"),\n v.literal(\"L2\"),\n v.literal(\"L1\"),\n v.literal(\"ontological\"),\n v.literal(\"organizational\"),\n);\n\nexport const subjectiveOpinionValidator = v.object({\n b: v.number(),\n d: v.number(),\n u: v.number(),\n a: v.number(),\n} satisfies Record<keyof SubjectiveOpinionDocument, unknown>);\n\nexport const edgeTypeValidator = v.union(\n // --- L4 Decision Edges (Phase 2A) ---\n v.literal(\"based_on_belief\"),\n v.literal(\"based_on_question\"),\n v.literal(\"blocked_by_contradiction\"),\n v.literal(\"informed_by_theme\"),\n\n // --- Evidence Flow (L2 → L3, L2 → L1) ---\n v.literal(\"derived_from\"),\n v.literal(\"responds_to\"),\n v.literal(\"informs\"),\n v.literal(\"tests\"),\n v.literal(\"explores\"),\n v.literal(\"qualifies\"),\n\n // --- Synthesis (L2 → L2, L2 → L1) ---\n // \"based_on\" removed — use \"derived_from\" instead\n\n // --- Theme Relationships (L3 → L3) ---\n v.literal(\"relates_to_thesis\"),\n v.literal(\"belongs_to\"),\n v.literal(\"plays_theme\"),\n v.literal(\"scoped_by\"),\n\n // --- Deal/Company ---\n v.literal(\"evaluates\"),\n\n // --- People (ontological → ontological, ontological → L3) ---\n v.literal(\"perspective_on\"),\n v.literal(\"works_at\"),\n v.literal(\"mentioned_in\"),\n v.literal(\"founded_by\"),\n\n // --- Value Chain (ontological → ontological) ---\n v.literal(\"participates_in\"),\n v.literal(\"performs\"),\n v.literal(\"function_in\"),\n v.literal(\"impacts\"),\n\n // --- Investment (ontological → ontological) ---\n v.literal(\"invested_in\"),\n v.literal(\"raised_from\"),\n\n // --- Lifecycle (same layer only) ---\n v.literal(\"supersedes\"),\n v.literal(\"same_as\"),\n\n // --- Same-Type Relationships: Belief ↔ Belief (L3 → L3) ---\n v.literal(\"depends_on\"),\n v.literal(\"supports\"),\n v.literal(\"contains\"),\n\n // --- Belief Cluster Mapping (L3 → L3) ---\n v.literal(\"counterfactual_of\"),\n v.literal(\"cascade_to\"),\n v.literal(\"cascade_from\"),\n v.literal(\"mutually_exclusive\"),\n v.literal(\"correlates_with\"),\n v.literal(\"amplifies\"),\n v.literal(\"precondition_for\"),\n v.literal(\"in_tension_with\"),\n\n // --- Belief ↔ Belief: Epistemic Impact (Confidence Propagation) ---\n v.literal(\"falsified_by\"),\n v.literal(\"exclusive_with\"),\n v.literal(\"contradicts\"),\n v.literal(\"collapses_if\"),\n v.literal(\"strengthened_by\"),\n v.literal(\"weakened_by\"),\n v.literal(\"alternative_to\"),\n v.literal(\"subsumes\"),\n v.literal(\"validated_by\"),\n v.literal(\"required_for\"),\n v.literal(\"blocks\"),\n\n // --- Same-Type Relationships: Question ↔ Question (L3 → L3) ---\n v.literal(\"prerequisite_for\"),\n v.literal(\"parallel_to\"),\n\n // --- Same-Type Relationships: Evidence ↔ Evidence (L2 → L2) ---\n v.literal(\"corroborates\"),\n v.literal(\"extends\"),\n v.literal(\"same_source_as\"),\n v.literal(\"same_theme_as\"),\n\n // --- NEW: Deep Epistemic Analysis Edges (Phase: Schema Upgrade) ---\n v.literal(\"assumes\"),\n v.literal(\"would_predict\"),\n v.literal(\"analogous_to\"),\n v.literal(\"independent_of\"),\n\n // --- Entity↔Belief Bridge (OE-B) ---\n v.literal(\"competes_with\"),\n);\n\nexport function buildEdgeStatusSuccessResult(): EdgeStatusResult {\n return { success: true };\n}\n\nexport function buildEdgeNotFoundResult(): EdgeStatusResult {\n const result = {} as Extract<\n EdgeStatusResult,\n { success: false; error: \"Edge not found\" }\n >;\n result.success = false;\n result.error = \"Edge not found\";\n return result;\n}\n\nexport function buildEdgeMirrorSkippedResult(): EdgeStatusResult {\n return {\n success: false,\n reason: \"source_not_in_convex\",\n };\n}\n\nexport function buildEdgeMirrorMissingResult(): EdgeStatusResult {\n return {\n success: false,\n reason: \"not_found\",\n };\n}\n\nexport function buildEdgeMirrorWriteResult(\n edgeId: Id<\"epistemicEdges\">,\n existed: boolean,\n): EdgeStatusResult {\n return {\n success: true,\n edgeId,\n existed,\n };\n}\n\nexport function edgeMatchesWorkspaceReasoningScope(\n edge: Pick<WorkspaceScopedEdge, \"topicId\" | \"projectId\">,\n scope: WorkspaceEdgeScope,\n): boolean {\n return (\n (scope.topicId !== undefined && edge.topicId === scope.topicId) ||\n (scope.projectId !== undefined && edge.projectId === scope.projectId)\n );\n}\n\nexport async function collectScopedEdges(\n ctx: QueryCtx,\n scope: WorkspaceEdgeScope,\n scanLimit: number,\n): Promise<WorkspaceScopedEdge[]> {\n const queries: Promise<WorkspaceScopedEdge[]>[] = [];\n\n if (scope.topicId) {\n queries.push(\n ctx.db\n .query(\"epistemicEdges\")\n .withIndex(\"by_topic\", (q: TopicIndexQuery) =>\n q.eq(\"topicId\", scope.topicId),\n )\n .order(\"desc\")\n .take(scanLimit) as Promise<WorkspaceScopedEdge[]>,\n );\n }\n\n // Kernel v2: also check edges scoped to projectId (many edges still have\n // topicId=s97 scope while UI passes projectId=n97). Query both to catch all.\n if (scope.projectId) {\n queries.push(\n ctx.db\n .query(\"epistemicEdges\")\n .withIndex(\"by_topic\", (q: TopicIndexQuery) =>\n q.eq(\"topicId\", scope.projectId),\n )\n .order(\"desc\")\n .take(scanLimit) as Promise<WorkspaceScopedEdge[]>,\n );\n }\n\n const seen = new Set<string>();\n const deduped: WorkspaceScopedEdge[] = [];\n\n const flattened = (await Promise.all(queries)).flat();\n for (const edge of flattened) {\n const key = String(edge._id);\n if (seen.has(key)) {\n continue;\n }\n seen.add(key);\n deduped.push(edge);\n }\n\n return deduped;\n}\n","import {\n actionGeneric,\n anyApi,\n componentsGeneric,\n httpActionGeneric,\n internalActionGeneric,\n internalMutationGeneric,\n internalQueryGeneric,\n mutationGeneric,\n queryGeneric,\n} from \"convex/server\";\nimport type { GenericId } from \"convex/values\";\n\nexport const api = anyApi as any;\nexport const components = componentsGeneric() as any;\nexport const internal = anyApi as any;\n\nexport type TableNames = string;\nexport type Id<TableName extends TableNames = string> = GenericId<TableName>;\nexport type Doc<TableName extends TableNames = string> = any;\nexport type DataModel = any;\ntype IndexRangeBuilder = {\n field(fieldName: string): string;\n eq(fieldName: string, value: unknown): IndexRangeBuilder;\n gt(fieldName: string, value: unknown): IndexRangeBuilder;\n gte(fieldName: string, value: unknown): IndexRangeBuilder;\n lt(fieldName: string, value: unknown): IndexRangeBuilder;\n lte(fieldName: string, value: unknown): IndexRangeBuilder;\n};\ntype FilterBuilder = {\n eq(left: unknown, right: unknown): unknown;\n neq(left: unknown, right: unknown): unknown;\n gt(left: unknown, right: unknown): unknown;\n gte(left: unknown, right: unknown): unknown;\n lt(left: unknown, right: unknown): unknown;\n lte(left: unknown, right: unknown): unknown;\n and(...clauses: unknown[]): unknown;\n or(...clauses: unknown[]): unknown;\n field(fieldName: string): unknown;\n};\ntype QueryInitializer<TableName extends TableNames> = {\n withIndex(\n indexName: string,\n range?: (q: any) => unknown\n ): QueryInitializer<TableName>;\n filter(predicate: (q: any) => unknown): QueryInitializer<TableName>;\n order(direction: \"asc\" | \"desc\"): QueryInitializer<TableName>;\n collect(): Promise<Doc<TableName>[]>;\n take(limit: number): Promise<Doc<TableName>[]>;\n first(): Promise<Doc<TableName> | null>;\n unique(): Promise<Doc<TableName> | null>;\n};\nexport type DatabaseReader = {\n get<TableName extends TableNames>(\n id: Id<TableName>\n ): Promise<Doc<TableName> | null>;\n query<TableName extends TableNames>(\n tableName: TableName\n ): QueryInitializer<TableName>;\n normalizeId?<TableName extends TableNames>(\n tableName: TableName,\n id: string\n ): Id<TableName> | null;\n};\nexport type DatabaseWriter = DatabaseReader & {\n insert<TableName extends TableNames>(\n tableName: TableName,\n value: Record<string, unknown>\n ): Promise<Id<TableName>>;\n patch<TableName extends TableNames>(\n id: Id<TableName>,\n value: Record<string, unknown>\n ): Promise<void>;\n replace<TableName extends TableNames>(\n id: Id<TableName>,\n value: Record<string, unknown>\n ): Promise<void>;\n delete<TableName extends TableNames>(id: Id<TableName>): Promise<void>;\n};\ntype Scheduler = {\n runAfter(delayMs: number, functionReference: unknown, args?: unknown): Promise<void>;\n};\ntype AuthReader = {\n getUserIdentity(): Promise<unknown>;\n};\ntype RuntimeInvoker = {\n runQuery(functionReference: unknown, args?: unknown): Promise<any>;\n runMutation(functionReference: unknown, args?: unknown): Promise<any>;\n runAction(functionReference: unknown, args?: unknown): Promise<any>;\n};\nexport type QueryCtx = RuntimeInvoker & {\n auth: AuthReader;\n db: DatabaseReader;\n scheduler: Scheduler;\n};\nexport type MutationCtx = RuntimeInvoker & {\n auth: AuthReader;\n db: DatabaseWriter;\n scheduler: Scheduler;\n};\nexport type ActionCtx = RuntimeInvoker & {\n auth: AuthReader;\n scheduler: Scheduler;\n};\n\ntype ConvexFunctionBuilder<Ctx> = <\n Definition extends { handler?: (ctx: Ctx, args: any) => any },\n>(\n definition: Definition\n) => any;\n\nexport const action = actionGeneric as unknown as ConvexFunctionBuilder<ActionCtx>;\nexport const httpAction =\n httpActionGeneric as unknown as ConvexFunctionBuilder<ActionCtx>;\nexport const internalAction =\n internalActionGeneric as unknown as ConvexFunctionBuilder<ActionCtx>;\nexport const internalMutation =\n internalMutationGeneric as unknown as ConvexFunctionBuilder<MutationCtx>;\nexport const internalQuery =\n internalQueryGeneric as unknown as ConvexFunctionBuilder<QueryCtx>;\nexport const mutation =\n mutationGeneric as unknown as ConvexFunctionBuilder<MutationCtx>;\nexport const query = queryGeneric as unknown as ConvexFunctionBuilder<QueryCtx>;\n","/** Topic-scope resolution helpers for graph-primitive operations. */\nimport { v } from \"convex/values\";\nimport { api as appApi } from \"./convex\";\nimport type { Id } from \"./convex\";\nimport { debugGraphPrimitiveFallback } from \"./debug\";\n\nconst LEGACY_SCOPE_FIELD = \"graphScope\" + \"ProjectId\";\n\ntype TopicDoc = Record<string, unknown> & {\n _id: Id<\"topics\">;\n globalId?: string;\n name?: string;\n depth?: number;\n createdAt?: number;\n parentTopicId?: Id<\"topics\">;\n tenantId?: string;\n workspaceId?: string;\n metadata?: Record<string, unknown>;\n};\n\nexport type TopicProjectScope = {\n topicId: Id<\"topics\">;\n projectId?: string;\n tenantId?: string;\n workspaceId?: string;\n source: \"topic\" | \"project_mapped_topic\" | \"topic_inferred\";\n};\n\ntype MaterializedTopicNodeDoc = {\n _id: string | Id<\"epistemicNodes\">;\n metadata?: Record<string, unknown>;\n};\n\nfunction asMappedProjectId(\n topic: TopicDoc | null | undefined,\n): string | undefined {\n if (!topic) {\n return;\n }\n const directLegacyProjectId = normalizeScopeValue(topic[LEGACY_SCOPE_FIELD]);\n if (directLegacyProjectId) {\n return directLegacyProjectId;\n }\n const metadata = (topic.metadata || {}) as Record<string, unknown>;\n const candidate =\n (metadata[LEGACY_SCOPE_FIELD] as string | undefined) ||\n (metadata.legacyProjectId as string | undefined) ||\n (metadata.projectId as string | undefined) ||\n (metadata.scopeProjectId as string | undefined);\n return candidate ? (candidate as string) : undefined;\n}\n\nfunction normalizeScopeValue(value: unknown): string | undefined {\n if (typeof value !== \"string\") {\n return;\n }\n const normalized = value.trim();\n return normalized.length > 0 ? normalized : undefined;\n}\n\nfunction pickPrimaryTopic(candidates: TopicDoc[]): TopicDoc | undefined {\n return [...candidates].sort((a, b) => {\n const depthA = a.depth ?? 9999;\n const depthB = b.depth ?? 9999;\n if (depthA !== depthB) {\n return depthA - depthB;\n }\n const createdA = a.createdAt ?? Number.MAX_SAFE_INTEGER;\n const createdB = b.createdAt ?? Number.MAX_SAFE_INTEGER;\n if (createdA !== createdB) {\n return createdA - createdB;\n }\n return String(a.name || \"\").localeCompare(String(b.name || \"\"));\n })[0];\n}\n\nasync function findTopicsByScopeAlias(\n ctx: any,\n scopeId: string,\n): Promise<TopicDoc[]> {\n try {\n return (await ctx.db\n .query(\"topics\")\n .withIndex(\"by_graph_scope_project\", (q: any) =>\n q.eq(LEGACY_SCOPE_FIELD, scopeId),\n )\n .collect()) as TopicDoc[];\n } catch (error) {\n debugGraphPrimitiveFallback(\n \"[topicScope] Failed to resolve scope alias via index\",\n {\n error,\n scopeId,\n },\n );\n // Older Lucern dev deployments can lag index backfills while still carrying\n // the underlying topics table. Scan and filter so scope resolution keeps\n // working during the rollout.\n const topics = (await ctx.db.query(\"topics\").collect()) as TopicDoc[];\n return topics.filter((topic) => {\n const normalizedGlobalId = normalizeScopeValue(topic.globalId);\n const mappedProjectId = asMappedProjectId(topic);\n return (\n String(topic._id) === scopeId ||\n normalizedGlobalId === scopeId ||\n mappedProjectId === scopeId\n );\n });\n }\n}\n\nasync function tryResolveHostTopicById(\n ctx: any,\n topicId: string,\n): Promise<TopicDoc | null> {\n if (typeof ctx.runQuery !== \"function\") {\n return null;\n }\n try {\n return ((await ctx.runQuery(appApi.topics.get as any, {\n id: topicId,\n })) ?? null) as TopicDoc | null;\n } catch (error) {\n debugGraphPrimitiveFallback(\n \"[topicScope] Failed to resolve topic by host query\",\n {\n error,\n topicId,\n },\n );\n return null;\n }\n}\n\nasync function tryResolveHostTopicByLegacyScope(\n ctx: any,\n legacyScopeId: string,\n): Promise<TopicDoc | null> {\n if (typeof ctx.runQuery !== \"function\") {\n return null;\n }\n try {\n return ((await ctx.runQuery(appApi.topics.getByLegacyScopeId as any, {\n projectId: legacyScopeId,\n })) ?? null) as TopicDoc | null;\n } catch (error) {\n debugGraphPrimitiveFallback(\n \"[topicScope] Failed to resolve topic by legacy scope\",\n {\n error,\n legacyScopeId,\n },\n );\n return null;\n }\n}\n\nexport function readMaterializedTopicTableId(\n topicNode: MaterializedTopicNodeDoc | null | undefined,\n): string | undefined {\n if (!topicNode) {\n return;\n }\n\n const metadata = (topicNode.metadata || {}) as Record<string, unknown>;\n const topicTableId =\n (metadata.topicTableId as string | undefined) ||\n (metadata.topicId as string | undefined);\n\n return typeof topicTableId === \"string\" && topicTableId.trim().length > 0\n ? topicTableId.trim()\n : undefined;\n}\n\n/**\n * Walk the topic parent chain to find inherited workspaceId and tenantId.\n * Mirrors the pattern used by resolveTopicOntology for ontologyId inheritance.\n * Max depth: 10 (defensive limit against pathological nesting).\n */\nasync function resolveInheritedWorkspaceScope(\n ctx: any,\n topic: TopicDoc,\n): Promise<{ tenantId?: string; workspaceId?: string }> {\n const MAX_DEPTH = 10;\n let tenantId = normalizeScopeValue(topic.tenantId);\n let workspaceId = normalizeScopeValue(topic.workspaceId);\n\n if (tenantId && workspaceId) {\n return { tenantId, workspaceId };\n }\n\n let current: TopicDoc | null = topic;\n for (let i = 0; i < MAX_DEPTH && current?.parentTopicId; i++) {\n current = (await ctx.db.get(current.parentTopicId)) as TopicDoc | null;\n if (!current) break;\n\n if (!tenantId) {\n tenantId = normalizeScopeValue(current.tenantId);\n }\n if (!workspaceId) {\n workspaceId = normalizeScopeValue(current.workspaceId);\n }\n if (tenantId && workspaceId) break;\n }\n\n return { tenantId, workspaceId };\n}\n\nexport async function resolveTopicProjectScope(\n ctx: any,\n args: { topicId?: Id<\"topics\"> | string; projectId?: string },\n): Promise<TopicProjectScope> {\n if (args.topicId) {\n // Try direct lookup, fall back to the legacy mapped-project bridge\n let topic: TopicDoc | null = null;\n try {\n topic = (await ctx.db.get(\n args.topicId as Id<\"topics\">,\n )) as TopicDoc | null;\n } catch (error) {\n debugGraphPrimitiveFallback(\n \"[topicScope] Failed to load topic by direct id\",\n {\n error,\n topicId: args.topicId,\n },\n );\n // Not a valid topics table ID\n }\n if (!topic) {\n topic = await tryResolveHostTopicById(ctx, String(args.topicId));\n }\n if (!topic) {\n // Try as legacy projectId / globalId via the mapped-project bridge.\n topic =\n pickPrimaryTopic(\n await findTopicsByScopeAlias(ctx, String(args.topicId)),\n ) ?? null;\n }\n if (!topic) {\n throw new Error(`Topic not found: ${String(args.topicId)}`);\n }\n const inherited = await resolveInheritedWorkspaceScope(ctx, topic);\n const mapped = asMappedProjectId(topic);\n if (mapped) {\n return {\n topicId: topic._id,\n projectId: mapped,\n tenantId: inherited.tenantId,\n workspaceId: inherited.workspaceId,\n source: \"topic\",\n };\n }\n return {\n topicId: topic._id,\n tenantId: inherited.tenantId,\n workspaceId: inherited.workspaceId,\n source: \"topic\",\n };\n }\n\n if (args.projectId) {\n let directTopic: TopicDoc | null = null;\n try {\n directTopic = (await ctx.db.get(\n args.projectId as Id<\"topics\">,\n )) as TopicDoc | null;\n } catch (error) {\n debugGraphPrimitiveFallback(\n \"[topicScope] Failed to load direct project topic\",\n {\n error,\n projectId: args.projectId,\n },\n );\n // Not a valid topics table ID, continue to legacy graph-scope lookup.\n }\n\n if (directTopic) {\n const inherited = await resolveInheritedWorkspaceScope(ctx, directTopic);\n const mapped = asMappedProjectId(directTopic);\n return {\n topicId: directTopic._id,\n projectId: mapped ?? args.projectId,\n tenantId: inherited.tenantId,\n workspaceId: inherited.workspaceId,\n source: \"topic_inferred\",\n };\n }\n\n directTopic = await tryResolveHostTopicByLegacyScope(ctx, args.projectId);\n if (directTopic) {\n const inherited = await resolveInheritedWorkspaceScope(ctx, directTopic);\n const mapped = asMappedProjectId(directTopic);\n return {\n topicId: directTopic._id,\n projectId: mapped ?? args.projectId,\n tenantId: inherited.tenantId,\n workspaceId: inherited.workspaceId,\n source: \"topic_inferred\",\n };\n }\n\n const topics = await findTopicsByScopeAlias(ctx, args.projectId);\n const primary = pickPrimaryTopic(topics);\n if (primary) {\n const inherited = await resolveInheritedWorkspaceScope(ctx, primary);\n return {\n topicId: primary._id,\n projectId: args.projectId,\n tenantId: inherited.tenantId,\n workspaceId: inherited.workspaceId,\n source: \"project_mapped_topic\",\n };\n }\n throw new Error(\n `Legacy project scope ${String(args.projectId)} has no mapped topic.`,\n );\n }\n\n throw new Error(\n \"Missing scope: provide topicId (preferred) or legacy projectId alias.\",\n );\n}\n\n/** Shared scope args for graph-primitive functions. topicId is canonical; projectId is a legacy alias. */\nexport const optionalScopeArgs = {\n projectId: v.optional(v.string()),\n topicId: v.optional(v.string()),\n} as const;\n","/**\n * Internal mutations for Neo4j/Convex dual-write edge mirroring.\n */\n\nimport { v } from \"convex/values\";\nimport { permissiveReturn } from \"@lucern/contracts/schema-helpers/validators\";\nimport {\n buildEdgeMirrorMissingResult,\n buildEdgeMirrorSkippedResult,\n buildEdgeMirrorWriteResult,\n buildEdgeStatusSuccessResult,\n subjectiveOpinionValidator,\n} from \"./epistemicEdges.helpers\";\nimport { optionalScopeArgs } from \"./topicScope\";\nimport { internalMutation } from \"./convex\";\n\n/**\n * Internal mutation to mirror a Neo4j edge to Convex for reactive UI.\n * Called by createEdge action for edge types that need reactive UI updates.\n */\nexport const mirrorEdgeToConvex = internalMutation({\n args: {\n globalId: v.string(),\n fromGlobalId: v.string(),\n toGlobalId: v.string(),\n edgeType: v.string(),\n weight: v.optional(v.number()),\n confidence: v.optional(v.number()),\n context: v.optional(v.string()),\n derivationType: v.optional(v.string()),\n createdBy: v.string(),\n ...optionalScopeArgs,\n fromLayer: v.optional(v.string()),\n toLayer: v.optional(v.string()),\n fromNodeType: v.optional(v.string()),\n toNodeType: v.optional(v.string()),\n reasoningMethod: v.optional(v.string()),\n logicalRole: v.optional(v.string()),\n temporalClass: v.optional(v.string()),\n validFrom: v.optional(v.number()),\n validUntil: v.optional(v.number()),\n constraint: v.optional(v.string()),\n propagation: v.optional(v.string()),\n blocking: v.optional(v.boolean()),\n implicit: v.optional(v.boolean()),\n conditionalA: v.optional(subjectiveOpinionValidator),\n conditionalNotA: v.optional(subjectiveOpinionValidator),\n },\n returns: permissiveReturn,\n handler: async (ctx, args) => {\n const fromNode = await ctx.db\n .query(\"epistemicNodes\")\n .withIndex(\"by_globalId\", (q) => q.eq(\"globalId\", args.fromGlobalId))\n .first();\n\n if (!fromNode) {\n console.log(\n `[Dual-Write] Skipping mirror - source node not in Convex: ${args.fromGlobalId}`,\n );\n return buildEdgeMirrorSkippedResult();\n }\n\n const toNode = await ctx.db\n .query(\"epistemicNodes\")\n .withIndex(\"by_globalId\", (q) => q.eq(\"globalId\", args.toGlobalId))\n .first();\n\n const existing = await ctx.db\n .query(\"epistemicEdges\")\n .withIndex(\"by_globalId\", (q) => q.eq(\"globalId\", args.globalId))\n .first();\n\n if (existing) {\n console.log(`[Dual-Write] Edge already exists: ${args.globalId}`);\n return buildEdgeMirrorWriteResult(existing._id, true);\n }\n\n const now = Date.now();\n const edgeId = await ctx.db.insert(\"epistemicEdges\", {\n globalId: args.globalId,\n fromNodeId: fromNode._id,\n toNodeId: toNode?._id,\n sourceGlobalId: args.fromGlobalId,\n targetGlobalId: args.toGlobalId,\n // Preserve the canonical string value even when the local schema lags.\n edgeType: args.edgeType as string,\n weight: args.weight,\n confidence: args.confidence,\n context: args.context,\n derivationType: args.derivationType,\n constraint: args.constraint as\n | \"xor\"\n | \"alternative\"\n | \"counterfactual\"\n | undefined,\n propagation: args.propagation as \"threshold\" | \"continuous\" | undefined,\n blocking: args.blocking,\n implicit: args.implicit,\n conditionalA: args.conditionalA,\n conditionalNotA: args.conditionalNotA,\n createdBy: args.createdBy,\n createdAt: now,\n updatedAt: now,\n topicId: args.projectId as string | undefined,\n fromLayer: args.fromLayer as\n | \"L4\"\n | \"L3\"\n | \"L2\"\n | \"L1\"\n | \"ontological\"\n | undefined,\n toLayer: args.toLayer as\n | \"L4\"\n | \"L3\"\n | \"L2\"\n | \"L1\"\n | \"ontological\"\n | undefined,\n fromNodeType: args.fromNodeType,\n toNodeType: args.toNodeType,\n reasoningMethod: args.reasoningMethod as\n | \"deductive\"\n | \"causal\"\n | \"inductive\"\n | \"abductive\"\n | \"statistical\"\n | \"analogical\"\n | \"correlational\"\n | \"testimonial\"\n | \"implicit\"\n | \"pattern_match\"\n | undefined,\n logicalRole: args.logicalRole as\n | \"necessary\"\n | \"sufficient\"\n | \"necessary_sufficient\"\n | \"contributory\"\n | \"corroborative\"\n | undefined,\n temporalClass: args.temporalClass as\n | \"structural\"\n | \"cyclical\"\n | \"transient\"\n | \"point_in_time\"\n | undefined,\n validFrom: args.validFrom,\n validUntil: args.validUntil,\n });\n\n console.log(\n `[Dual-Write] Mirrored edge to Convex: ${args.globalId} (${args.edgeType})`,\n );\n return buildEdgeMirrorWriteResult(edgeId, false);\n },\n});\n\n/**\n * Internal mutation to delete a mirrored edge from Convex.\n * Called by deleteEdge action to maintain Convex mirror consistency.\n */\nexport const deleteEdgeFromConvex = internalMutation({\n args: {\n globalId: v.string(),\n },\n returns: permissiveReturn,\n handler: async (ctx, args) => {\n const existing = await ctx.db\n .query(\"epistemicEdges\")\n .withIndex(\"by_globalId\", (q) => q.eq(\"globalId\", args.globalId))\n .first();\n\n if (!existing) {\n return buildEdgeMirrorMissingResult();\n }\n\n await ctx.db.delete(existing._id);\n console.log(`[Dual-Write] Deleted edge from Convex: ${args.globalId}`);\n return buildEdgeStatusSuccessResult();\n },\n});\n\n/**\n * Internal mutation to update a mirrored edge in Convex.\n * Called by updateEdge action to maintain Convex mirror consistency.\n */\nexport const updateEdgeInConvex = internalMutation({\n args: {\n globalId: v.string(),\n weight: v.optional(v.number()),\n confidence: v.optional(v.number()),\n context: v.optional(v.string()),\n derivationType: v.optional(v.string()),\n constraint: v.optional(v.string()),\n propagation: v.optional(v.string()),\n blocking: v.optional(v.boolean()),\n implicit: v.optional(v.boolean()),\n conditionalA: v.optional(subjectiveOpinionValidator),\n conditionalNotA: v.optional(subjectiveOpinionValidator),\n },\n returns: permissiveReturn,\n handler: async (ctx, args) => {\n const existing = await ctx.db\n .query(\"epistemicEdges\")\n .withIndex(\"by_globalId\", (q) => q.eq(\"globalId\", args.globalId))\n .first();\n\n if (!existing) {\n return buildEdgeMirrorMissingResult();\n }\n\n const updates: Record<string, unknown> = {\n updatedAt: Date.now(),\n };\n\n if (args.weight !== undefined) {\n updates.weight = args.weight;\n }\n if (args.confidence !== undefined) {\n updates.confidence = args.confidence;\n }\n if (args.context !== undefined) {\n updates.context = args.context;\n }\n if (args.derivationType !== undefined) {\n updates.derivationType = args.derivationType;\n }\n if (args.constraint !== undefined) {\n updates.constraint = args.constraint;\n }\n if (args.propagation !== undefined) {\n updates.propagation = args.propagation;\n }\n if (args.blocking !== undefined) {\n updates.blocking = args.blocking;\n }\n if (args.implicit !== undefined) {\n updates.implicit = args.implicit;\n }\n if (args.conditionalA !== undefined) {\n updates.conditionalA = args.conditionalA;\n }\n if (args.conditionalNotA !== undefined) {\n updates.conditionalNotA = args.conditionalNotA;\n }\n\n await ctx.db.patch(existing._id, updates);\n console.log(`[Dual-Write] Updated edge in Convex: ${args.globalId}`);\n\n return buildEdgeStatusSuccessResult();\n },\n});\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as convex_values from 'convex/values';
|
|
2
|
+
import { EdgeStatusResult, WorkspaceEdgeScope, WorkspaceScopedEdge } from './epistemicEdges.types.js';
|
|
3
|
+
import { Id, QueryCtx } from './convex.js';
|
|
4
|
+
import './topicScope-By_zp4tt.js';
|
|
5
|
+
|
|
6
|
+
declare const epistemicLayerValidator: convex_values.VUnion<"ontological" | "L4" | "L3" | "L2" | "L1" | "organizational", [convex_values.VLiteral<"L4", "required">, convex_values.VLiteral<"L3", "required">, convex_values.VLiteral<"L2", "required">, convex_values.VLiteral<"L1", "required">, convex_values.VLiteral<"ontological", "required">, convex_values.VLiteral<"organizational", "required">], "required", never>;
|
|
7
|
+
declare const subjectiveOpinionValidator: convex_values.VObject<{
|
|
8
|
+
b: number;
|
|
9
|
+
d: number;
|
|
10
|
+
u: number;
|
|
11
|
+
a: number;
|
|
12
|
+
}, {
|
|
13
|
+
b: convex_values.VFloat64<number, "required">;
|
|
14
|
+
d: convex_values.VFloat64<number, "required">;
|
|
15
|
+
u: convex_values.VFloat64<number, "required">;
|
|
16
|
+
a: convex_values.VFloat64<number, "required">;
|
|
17
|
+
}, "required", "b" | "d" | "u" | "a">;
|
|
18
|
+
declare const edgeTypeValidator: convex_values.VUnion<"contains" | "evaluates" | "perspective_on" | "impacts" | "mentioned_in" | "works_at" | "participates_in" | "performs" | "function_in" | "invested_in" | "raised_from" | "founded_by" | "competes_with" | "derived_from" | "supports" | "informs" | "depends_on" | "tests" | "based_on_belief" | "based_on_question" | "blocked_by_contradiction" | "informed_by_theme" | "supersedes" | "responds_to" | "belongs_to" | "relates_to_thesis" | "plays_theme" | "contradicts" | "prerequisite_for" | "parallel_to" | "corroborates" | "extends" | "same_source_as" | "same_theme_as" | "qualifies" | "explores" | "scoped_by" | "same_as" | "assumes" | "would_predict" | "analogous_to" | "independent_of" | "counterfactual_of" | "cascade_to" | "mutually_exclusive" | "correlates_with" | "amplifies" | "precondition_for" | "in_tension_with" | "cascade_from" | "falsified_by" | "exclusive_with" | "collapses_if" | "strengthened_by" | "weakened_by" | "alternative_to" | "subsumes" | "validated_by" | "required_for" | "blocks", [convex_values.VLiteral<"based_on_belief", "required">, convex_values.VLiteral<"based_on_question", "required">, convex_values.VLiteral<"blocked_by_contradiction", "required">, convex_values.VLiteral<"informed_by_theme", "required">, convex_values.VLiteral<"derived_from", "required">, convex_values.VLiteral<"responds_to", "required">, convex_values.VLiteral<"informs", "required">, convex_values.VLiteral<"tests", "required">, convex_values.VLiteral<"explores", "required">, convex_values.VLiteral<"qualifies", "required">, convex_values.VLiteral<"relates_to_thesis", "required">, convex_values.VLiteral<"belongs_to", "required">, convex_values.VLiteral<"plays_theme", "required">, convex_values.VLiteral<"scoped_by", "required">, convex_values.VLiteral<"evaluates", "required">, convex_values.VLiteral<"perspective_on", "required">, convex_values.VLiteral<"works_at", "required">, convex_values.VLiteral<"mentioned_in", "required">, convex_values.VLiteral<"founded_by", "required">, convex_values.VLiteral<"participates_in", "required">, convex_values.VLiteral<"performs", "required">, convex_values.VLiteral<"function_in", "required">, convex_values.VLiteral<"impacts", "required">, convex_values.VLiteral<"invested_in", "required">, convex_values.VLiteral<"raised_from", "required">, convex_values.VLiteral<"supersedes", "required">, convex_values.VLiteral<"same_as", "required">, convex_values.VLiteral<"depends_on", "required">, convex_values.VLiteral<"supports", "required">, convex_values.VLiteral<"contains", "required">, convex_values.VLiteral<"counterfactual_of", "required">, convex_values.VLiteral<"cascade_to", "required">, convex_values.VLiteral<"cascade_from", "required">, convex_values.VLiteral<"mutually_exclusive", "required">, convex_values.VLiteral<"correlates_with", "required">, convex_values.VLiteral<"amplifies", "required">, convex_values.VLiteral<"precondition_for", "required">, convex_values.VLiteral<"in_tension_with", "required">, convex_values.VLiteral<"falsified_by", "required">, convex_values.VLiteral<"exclusive_with", "required">, convex_values.VLiteral<"contradicts", "required">, convex_values.VLiteral<"collapses_if", "required">, convex_values.VLiteral<"strengthened_by", "required">, convex_values.VLiteral<"weakened_by", "required">, convex_values.VLiteral<"alternative_to", "required">, convex_values.VLiteral<"subsumes", "required">, convex_values.VLiteral<"validated_by", "required">, convex_values.VLiteral<"required_for", "required">, convex_values.VLiteral<"blocks", "required">, convex_values.VLiteral<"prerequisite_for", "required">, convex_values.VLiteral<"parallel_to", "required">, convex_values.VLiteral<"corroborates", "required">, convex_values.VLiteral<"extends", "required">, convex_values.VLiteral<"same_source_as", "required">, convex_values.VLiteral<"same_theme_as", "required">, convex_values.VLiteral<"assumes", "required">, convex_values.VLiteral<"would_predict", "required">, convex_values.VLiteral<"analogous_to", "required">, convex_values.VLiteral<"independent_of", "required">, convex_values.VLiteral<"competes_with", "required">], "required", never>;
|
|
19
|
+
declare function buildEdgeStatusSuccessResult(): EdgeStatusResult;
|
|
20
|
+
declare function buildEdgeNotFoundResult(): EdgeStatusResult;
|
|
21
|
+
declare function buildEdgeMirrorSkippedResult(): EdgeStatusResult;
|
|
22
|
+
declare function buildEdgeMirrorMissingResult(): EdgeStatusResult;
|
|
23
|
+
declare function buildEdgeMirrorWriteResult(edgeId: Id<"epistemicEdges">, existed: boolean): EdgeStatusResult;
|
|
24
|
+
declare function edgeMatchesWorkspaceReasoningScope(edge: Pick<WorkspaceScopedEdge, "topicId" | "projectId">, scope: WorkspaceEdgeScope): boolean;
|
|
25
|
+
declare function collectScopedEdges(ctx: QueryCtx, scope: WorkspaceEdgeScope, scanLimit: number): Promise<WorkspaceScopedEdge[]>;
|
|
26
|
+
|
|
27
|
+
export { buildEdgeMirrorMissingResult, buildEdgeMirrorSkippedResult, buildEdgeMirrorWriteResult, buildEdgeNotFoundResult, buildEdgeStatusSuccessResult, collectScopedEdges, edgeMatchesWorkspaceReasoningScope, edgeTypeValidator, epistemicLayerValidator, subjectiveOpinionValidator };
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { v } from 'convex/values';
|
|
2
|
+
|
|
3
|
+
// src/epistemicEdges.helpers.ts
|
|
4
|
+
var epistemicLayerValidator = v.union(
|
|
5
|
+
v.literal("L4"),
|
|
6
|
+
v.literal("L3"),
|
|
7
|
+
v.literal("L2"),
|
|
8
|
+
v.literal("L1"),
|
|
9
|
+
v.literal("ontological"),
|
|
10
|
+
v.literal("organizational")
|
|
11
|
+
);
|
|
12
|
+
var subjectiveOpinionValidator = v.object({
|
|
13
|
+
b: v.number(),
|
|
14
|
+
d: v.number(),
|
|
15
|
+
u: v.number(),
|
|
16
|
+
a: v.number()
|
|
17
|
+
});
|
|
18
|
+
var edgeTypeValidator = v.union(
|
|
19
|
+
// --- L4 Decision Edges (Phase 2A) ---
|
|
20
|
+
v.literal("based_on_belief"),
|
|
21
|
+
v.literal("based_on_question"),
|
|
22
|
+
v.literal("blocked_by_contradiction"),
|
|
23
|
+
v.literal("informed_by_theme"),
|
|
24
|
+
// --- Evidence Flow (L2 → L3, L2 → L1) ---
|
|
25
|
+
v.literal("derived_from"),
|
|
26
|
+
v.literal("responds_to"),
|
|
27
|
+
v.literal("informs"),
|
|
28
|
+
v.literal("tests"),
|
|
29
|
+
v.literal("explores"),
|
|
30
|
+
v.literal("qualifies"),
|
|
31
|
+
// --- Synthesis (L2 → L2, L2 → L1) ---
|
|
32
|
+
// "based_on" removed — use "derived_from" instead
|
|
33
|
+
// --- Theme Relationships (L3 → L3) ---
|
|
34
|
+
v.literal("relates_to_thesis"),
|
|
35
|
+
v.literal("belongs_to"),
|
|
36
|
+
v.literal("plays_theme"),
|
|
37
|
+
v.literal("scoped_by"),
|
|
38
|
+
// --- Deal/Company ---
|
|
39
|
+
v.literal("evaluates"),
|
|
40
|
+
// --- People (ontological → ontological, ontological → L3) ---
|
|
41
|
+
v.literal("perspective_on"),
|
|
42
|
+
v.literal("works_at"),
|
|
43
|
+
v.literal("mentioned_in"),
|
|
44
|
+
v.literal("founded_by"),
|
|
45
|
+
// --- Value Chain (ontological → ontological) ---
|
|
46
|
+
v.literal("participates_in"),
|
|
47
|
+
v.literal("performs"),
|
|
48
|
+
v.literal("function_in"),
|
|
49
|
+
v.literal("impacts"),
|
|
50
|
+
// --- Investment (ontological → ontological) ---
|
|
51
|
+
v.literal("invested_in"),
|
|
52
|
+
v.literal("raised_from"),
|
|
53
|
+
// --- Lifecycle (same layer only) ---
|
|
54
|
+
v.literal("supersedes"),
|
|
55
|
+
v.literal("same_as"),
|
|
56
|
+
// --- Same-Type Relationships: Belief ↔ Belief (L3 → L3) ---
|
|
57
|
+
v.literal("depends_on"),
|
|
58
|
+
v.literal("supports"),
|
|
59
|
+
v.literal("contains"),
|
|
60
|
+
// --- Belief Cluster Mapping (L3 → L3) ---
|
|
61
|
+
v.literal("counterfactual_of"),
|
|
62
|
+
v.literal("cascade_to"),
|
|
63
|
+
v.literal("cascade_from"),
|
|
64
|
+
v.literal("mutually_exclusive"),
|
|
65
|
+
v.literal("correlates_with"),
|
|
66
|
+
v.literal("amplifies"),
|
|
67
|
+
v.literal("precondition_for"),
|
|
68
|
+
v.literal("in_tension_with"),
|
|
69
|
+
// --- Belief ↔ Belief: Epistemic Impact (Confidence Propagation) ---
|
|
70
|
+
v.literal("falsified_by"),
|
|
71
|
+
v.literal("exclusive_with"),
|
|
72
|
+
v.literal("contradicts"),
|
|
73
|
+
v.literal("collapses_if"),
|
|
74
|
+
v.literal("strengthened_by"),
|
|
75
|
+
v.literal("weakened_by"),
|
|
76
|
+
v.literal("alternative_to"),
|
|
77
|
+
v.literal("subsumes"),
|
|
78
|
+
v.literal("validated_by"),
|
|
79
|
+
v.literal("required_for"),
|
|
80
|
+
v.literal("blocks"),
|
|
81
|
+
// --- Same-Type Relationships: Question ↔ Question (L3 → L3) ---
|
|
82
|
+
v.literal("prerequisite_for"),
|
|
83
|
+
v.literal("parallel_to"),
|
|
84
|
+
// --- Same-Type Relationships: Evidence ↔ Evidence (L2 → L2) ---
|
|
85
|
+
v.literal("corroborates"),
|
|
86
|
+
v.literal("extends"),
|
|
87
|
+
v.literal("same_source_as"),
|
|
88
|
+
v.literal("same_theme_as"),
|
|
89
|
+
// --- NEW: Deep Epistemic Analysis Edges (Phase: Schema Upgrade) ---
|
|
90
|
+
v.literal("assumes"),
|
|
91
|
+
v.literal("would_predict"),
|
|
92
|
+
v.literal("analogous_to"),
|
|
93
|
+
v.literal("independent_of"),
|
|
94
|
+
// --- Entity↔Belief Bridge (OE-B) ---
|
|
95
|
+
v.literal("competes_with")
|
|
96
|
+
);
|
|
97
|
+
function buildEdgeStatusSuccessResult() {
|
|
98
|
+
return { success: true };
|
|
99
|
+
}
|
|
100
|
+
function buildEdgeNotFoundResult() {
|
|
101
|
+
const result = {};
|
|
102
|
+
result.success = false;
|
|
103
|
+
result.error = "Edge not found";
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
106
|
+
function buildEdgeMirrorSkippedResult() {
|
|
107
|
+
return {
|
|
108
|
+
success: false,
|
|
109
|
+
reason: "source_not_in_convex"
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function buildEdgeMirrorMissingResult() {
|
|
113
|
+
return {
|
|
114
|
+
success: false,
|
|
115
|
+
reason: "not_found"
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function buildEdgeMirrorWriteResult(edgeId, existed) {
|
|
119
|
+
return {
|
|
120
|
+
success: true,
|
|
121
|
+
edgeId,
|
|
122
|
+
existed
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function edgeMatchesWorkspaceReasoningScope(edge, scope) {
|
|
126
|
+
return scope.topicId !== void 0 && edge.topicId === scope.topicId || scope.projectId !== void 0 && edge.projectId === scope.projectId;
|
|
127
|
+
}
|
|
128
|
+
async function collectScopedEdges(ctx, scope, scanLimit) {
|
|
129
|
+
const queries = [];
|
|
130
|
+
if (scope.topicId) {
|
|
131
|
+
queries.push(
|
|
132
|
+
ctx.db.query("epistemicEdges").withIndex(
|
|
133
|
+
"by_topic",
|
|
134
|
+
(q) => q.eq("topicId", scope.topicId)
|
|
135
|
+
).order("desc").take(scanLimit)
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
if (scope.projectId) {
|
|
139
|
+
queries.push(
|
|
140
|
+
ctx.db.query("epistemicEdges").withIndex(
|
|
141
|
+
"by_topic",
|
|
142
|
+
(q) => q.eq("topicId", scope.projectId)
|
|
143
|
+
).order("desc").take(scanLimit)
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
const seen = /* @__PURE__ */ new Set();
|
|
147
|
+
const deduped = [];
|
|
148
|
+
const flattened = (await Promise.all(queries)).flat();
|
|
149
|
+
for (const edge of flattened) {
|
|
150
|
+
const key = String(edge._id);
|
|
151
|
+
if (seen.has(key)) {
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
seen.add(key);
|
|
155
|
+
deduped.push(edge);
|
|
156
|
+
}
|
|
157
|
+
return deduped;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export { buildEdgeMirrorMissingResult, buildEdgeMirrorSkippedResult, buildEdgeMirrorWriteResult, buildEdgeNotFoundResult, buildEdgeStatusSuccessResult, collectScopedEdges, edgeMatchesWorkspaceReasoningScope, edgeTypeValidator, epistemicLayerValidator, subjectiveOpinionValidator };
|
|
161
|
+
//# sourceMappingURL=epistemicEdges.helpers.js.map
|
|
162
|
+
//# sourceMappingURL=epistemicEdges.helpers.js.map
|