@lucern/graph-primitives 0.3.0-alpha.5 → 0.3.0-alpha.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/dist/{beliefDecay-Q_26RTc-.d.ts → beliefDecay-DZ6tkLYq.d.ts} +1 -1
  2. package/dist/beliefDecay.d.ts +1 -1
  3. package/dist/beliefDecay.js +158 -47
  4. package/dist/beliefDecay.js.map +1 -1
  5. package/dist/{beliefEvidenceLinks-42FlR48t.d.ts → beliefEvidenceLinks-CWOXxxJg.d.ts} +1 -1
  6. package/dist/beliefEvidenceLinks.d.ts +1 -1
  7. package/dist/beliefEvidenceLinks.js +141 -45
  8. package/dist/beliefEvidenceLinks.js.map +1 -1
  9. package/dist/{beliefLifecycle-C-AehZgF.d.ts → beliefLifecycle-y8WLXqQj.d.ts} +1 -1
  10. package/dist/beliefLifecycle.d.ts +1 -1
  11. package/dist/confidencePropagationDispatch.d.ts +1 -1
  12. package/dist/confidencePropagationDispatch.js +1 -3
  13. package/dist/confidencePropagationDispatch.js.map +1 -1
  14. package/dist/{contradictions-Hdwl7zid.d.ts → contradictions-51VLsESq.d.ts} +1 -1
  15. package/dist/contradictions.d.ts +1 -1
  16. package/dist/contradictions.js +67 -8
  17. package/dist/contradictions.js.map +1 -1
  18. package/dist/debug.d.ts +4 -0
  19. package/dist/debug.js +34 -0
  20. package/dist/debug.js.map +1 -0
  21. package/dist/edges/contradicts.js.map +1 -1
  22. package/dist/edges/dependsOn.js.map +1 -1
  23. package/dist/edges/elaborates.js.map +1 -1
  24. package/dist/edges/index.js +1 -3
  25. package/dist/edges/index.js.map +1 -1
  26. package/dist/edges/informs.js +1 -3
  27. package/dist/edges/informs.js.map +1 -1
  28. package/dist/edges/refutes.js +1 -3
  29. package/dist/edges/refutes.js.map +1 -1
  30. package/dist/edges/supports.js.map +1 -1
  31. package/dist/edges/utils.d.ts +3 -3
  32. package/dist/edges/utils.js +2 -4
  33. package/dist/edges/utils.js.map +1 -1
  34. package/dist/embeddingTrigger.js +21 -1
  35. package/dist/embeddingTrigger.js.map +1 -1
  36. package/dist/entityBridge.js +1 -1
  37. package/dist/entityBridge.js.map +1 -1
  38. package/dist/{entityLifecycle-BkhRJ-XI.d.ts → entityLifecycle-CvgSK5FV.d.ts} +1 -1
  39. package/dist/entityLifecycle.d.ts +1 -1
  40. package/dist/entityLifecycle.js +134 -47
  41. package/dist/entityLifecycle.js.map +1 -1
  42. package/dist/{epistemicAnswers-DSP1slZ9.d.ts → epistemicAnswers-C5ib4z6_.d.ts} +1 -1
  43. package/dist/epistemicAnswers.d.ts +1 -1
  44. package/dist/epistemicAnswers.js +67 -8
  45. package/dist/epistemicAnswers.js.map +1 -1
  46. package/dist/{epistemicBeliefs-DtFVTp-k.d.ts → epistemicBeliefs-DzKjZAeC.d.ts} +3 -3
  47. package/dist/epistemicBeliefs.d.ts +2 -2
  48. package/dist/epistemicBeliefs.js +289 -114
  49. package/dist/epistemicBeliefs.js.map +1 -1
  50. package/dist/epistemicContracts.d.ts +1 -1
  51. package/dist/epistemicContracts.js +297 -115
  52. package/dist/epistemicContracts.js.map +1 -1
  53. package/dist/{epistemicEdges-DQKNJ04T.d.ts → epistemicEdges-CvlKnEyy.d.ts} +3 -3
  54. package/dist/epistemicEdges.d.ts +1 -1
  55. package/dist/epistemicEdges.js +192 -60
  56. package/dist/epistemicEdges.js.map +1 -1
  57. package/dist/{epistemicEvidence-Bo638XDP.d.ts → epistemicEvidence-xw6UUrwh.d.ts} +1 -1
  58. package/dist/epistemicEvidence.d.ts +1 -1
  59. package/dist/epistemicEvidence.js +163 -49
  60. package/dist/epistemicEvidence.js.map +1 -1
  61. package/dist/{epistemicHelpers-Bd9xbaib.d.ts → epistemicHelpers-DevrYgPN.d.ts} +1 -1
  62. package/dist/epistemicHelpers.d.ts +1 -1
  63. package/dist/{epistemicLinking-CyeLOIzN.d.ts → epistemicLinking-CfE00tHJ.d.ts} +1 -1
  64. package/dist/epistemicLinking.d.ts +1 -1
  65. package/dist/epistemicLinking.js +1 -1
  66. package/dist/{epistemicNodes-o5pqdCZQ.d.ts → epistemicNodes-DjSUfvyD.d.ts} +2 -2
  67. package/dist/epistemicNodes.d.ts +1 -1
  68. package/dist/epistemicNodes.js +163 -33
  69. package/dist/epistemicNodes.js.map +1 -1
  70. package/dist/{epistemicQuestions-CmEeY6zQ.d.ts → epistemicQuestions-B_nUclrH.d.ts} +1 -1
  71. package/dist/epistemicQuestions.d.ts +1 -1
  72. package/dist/epistemicQuestions.js +311 -62
  73. package/dist/epistemicQuestions.js.map +1 -1
  74. package/dist/{epistemicSources-ZazxHOK1.d.ts → epistemicSources-dlKj58Jp.d.ts} +1 -1
  75. package/dist/epistemicSources.d.ts +1 -1
  76. package/dist/epistemicSources.js +65 -8
  77. package/dist/epistemicSources.js.map +1 -1
  78. package/dist/evaluators/index.js +297 -115
  79. package/dist/evaluators/index.js.map +1 -1
  80. package/dist/evaluators/lintCheckerEvaluator.js.map +1 -1
  81. package/dist/evaluators/sentryCheckerEvaluator.js.map +1 -1
  82. package/dist/evaluators/shared.js +20 -1
  83. package/dist/evaluators/shared.js.map +1 -1
  84. package/dist/evaluators/testRunnerEvaluator.js +20 -1
  85. package/dist/evaluators/testRunnerEvaluator.js.map +1 -1
  86. package/dist/evaluators/tscCheckerEvaluator.js.map +1 -1
  87. package/dist/index.d.ts +20 -20
  88. package/dist/index.js +729 -206
  89. package/dist/index.js.map +1 -1
  90. package/dist/{ontology-matching-Buhu23ss.d.ts → ontology-matching-C6rrz2VP.d.ts} +1 -1
  91. package/dist/ontology-matching.d.ts +1 -1
  92. package/dist/{ontologyApproval-Ba0Jjk1k.d.ts → ontologyApproval-CFYmqKmk.d.ts} +1 -1
  93. package/dist/ontologyApproval.d.ts +1 -1
  94. package/dist/ontologyDefinitions.js +4 -3
  95. package/dist/ontologyDefinitions.js.map +1 -1
  96. package/dist/ontologyHelpers.d.ts +1 -1
  97. package/dist/ontologyHelpers.js +4 -3
  98. package/dist/ontologyHelpers.js.map +1 -1
  99. package/dist/{projectionReconciliation-CxrXYGaB.d.ts → projectionReconciliation-jww2fBI0.d.ts} +1 -1
  100. package/dist/projectionReconciliation.d.ts +1 -1
  101. package/dist/projectionReconciliation.js +14 -20
  102. package/dist/projectionReconciliation.js.map +1 -1
  103. package/dist/{projectionStaleness-CAdpIsaW.d.ts → projectionStaleness-CmdbpjVK.d.ts} +1 -1
  104. package/dist/projectionStaleness.d.ts +1 -1
  105. package/dist/{questionEvidenceLinks-BdQD0TkM.d.ts → questionEvidenceLinks-DFlyPpAj.d.ts} +1 -1
  106. package/dist/questionEvidenceLinks.d.ts +1 -1
  107. package/dist/questionEvidenceLinks.js +144 -45
  108. package/dist/questionEvidenceLinks.js.map +1 -1
  109. package/dist/resolvers.js +86 -37
  110. package/dist/resolvers.js.map +1 -1
  111. package/dist/scopeResolverCompat.js +64 -7
  112. package/dist/scopeResolverCompat.js.map +1 -1
  113. package/dist/{text-matching-CMn2WnVD.d.ts → text-matching-DNg4M5Wd.d.ts} +1 -1
  114. package/dist/text-matching.d.ts +1 -1
  115. package/dist/topicProjectOverlay.js +56 -13
  116. package/dist/topicProjectOverlay.js.map +1 -1
  117. package/dist/topicScope.js +55 -6
  118. package/dist/topicScope.js.map +1 -1
  119. package/dist/workflowBridge.js +55 -6
  120. package/dist/workflowBridge.js.map +1 -1
  121. package/dist/workspaceIsolation.js +55 -6
  122. package/dist/workspaceIsolation.js.map +1 -1
  123. package/package.json +5 -5
@@ -2,7 +2,7 @@ import { v } from 'convex/values';
2
2
  import { checkProjectAccess } from '@lucern/access-control/access';
3
3
  import { getCurrentUserId } from '@lucern/access-control/auth';
4
4
  import { permissiveReturn } from '@lucern/contracts/schema-helpers/validators';
5
- import { componentsGeneric, queryGeneric, mutationGeneric, anyApi } from 'convex/server';
5
+ import { componentsGeneric, anyApi, queryGeneric, mutationGeneric } from 'convex/server';
6
6
 
7
7
  // src/entityLifecycle.ts
8
8
  var api = anyApi;
@@ -151,6 +151,18 @@ async function validateEntityTypeForTopic(ctx, topicId, nodeType) {
151
151
  };
152
152
  }
153
153
 
154
+ // src/debug.ts
155
+ function isGraphPrimitiveDebugEnabled() {
156
+ const env = globalThis.process?.env;
157
+ return env?.LUCERN_COMPAT_FALLBACK_DEBUG === "1" || env?.LUCERN_GRAPH_DEBUG === "1";
158
+ }
159
+ function debugGraphPrimitiveFallback(message, context) {
160
+ if (!isGraphPrimitiveDebugEnabled()) {
161
+ return;
162
+ }
163
+ console.debug(message, context ?? {});
164
+ }
165
+
154
166
  // src/topicProjectOverlay.ts
155
167
  var LEGACY_SCOPE_FIELD = "graphScopeProjectId";
156
168
  function readNonEmptyString(value) {
@@ -196,19 +208,37 @@ function isProjectLikeTopic(topic) {
196
208
  return topic.type === "theme" || topic.type === "thematic" || topic.type === "deal" || topic.type === "monitoring" || readLegacyProjectId(topic) !== void 0 || readNonEmptyString(metadata.projectType) !== void 0;
197
209
  }
198
210
  function isMissingLucernChildComponentError(error) {
199
- const message = error instanceof Error ? error.message : String(error);
211
+ const message = getErrorMessage(error);
200
212
  return message.includes(
201
213
  'Child component ComponentName(Identifier("lucern")) not found'
202
214
  ) || message.includes("Child component") && message.includes("lucern") && message.includes("not found");
203
215
  }
216
+ function getErrorMessage(error) {
217
+ if (error instanceof Error) {
218
+ return error.message;
219
+ }
220
+ if (typeof error === "object" && error !== null && "message" in error && typeof error.message === "string") {
221
+ return error.message;
222
+ }
223
+ return "unknown error";
224
+ }
204
225
  async function resolveTopicDoc(ctx, scopeId) {
205
226
  if (ctx?.db && typeof ctx.db.get === "function") {
206
227
  try {
207
- const directTopic = await ctx.db.get(scopeId);
228
+ const directTopic = await ctx.db.get(
229
+ scopeId
230
+ );
208
231
  if (directTopic) {
209
232
  return directTopic;
210
233
  }
211
- } catch {
234
+ } catch (error) {
235
+ debugGraphPrimitiveFallback(
236
+ "[topicProjectOverlay] Failed to resolve topic by direct ID",
237
+ {
238
+ error,
239
+ scopeId
240
+ }
241
+ );
212
242
  }
213
243
  }
214
244
  if (typeof ctx.runQuery !== "function") {
@@ -221,7 +251,14 @@ async function resolveTopicDoc(ctx, scopeId) {
221
251
  if (topic?.name !== void 0 && topic?.type !== void 0) {
222
252
  return topic;
223
253
  }
224
- } catch {
254
+ } catch (error) {
255
+ debugGraphPrimitiveFallback(
256
+ "[topicProjectOverlay] Failed to resolve topic by ID query",
257
+ {
258
+ error,
259
+ scopeId
260
+ }
261
+ );
225
262
  }
226
263
  try {
227
264
  const topic = await ctx.runQuery(api.topics.getByLegacyScopeId, {
@@ -230,7 +267,11 @@ async function resolveTopicDoc(ctx, scopeId) {
230
267
  if (topic?.name !== void 0 && topic?.type !== void 0) {
231
268
  return topic;
232
269
  }
233
- } catch {
270
+ } catch (error) {
271
+ debugGraphPrimitiveFallback(
272
+ "[topicProjectOverlay] Failed to resolve topic by legacy scope ID",
273
+ { error, scopeId }
274
+ );
234
275
  }
235
276
  return null;
236
277
  }
@@ -284,7 +325,11 @@ async function listTopicProjectOverlays(ctx, options = {}) {
284
325
  if (ctx?.db?.query && typeof ctx.db.query === "function") {
285
326
  try {
286
327
  allTopics = await ctx.db.query("topics").collect();
287
- } catch {
328
+ } catch (error) {
329
+ debugGraphPrimitiveFallback(
330
+ "[topicProjectOverlay] Failed to read topics table; falling back to API",
331
+ { error }
332
+ );
288
333
  allTopics = [];
289
334
  }
290
335
  }
@@ -379,19 +424,28 @@ async function patchTopicProjectOverlay(ctx, scopeId, value) {
379
424
  "Cannot patch topic without component adapter (ctx.runMutation unavailable)"
380
425
  );
381
426
  }
382
- return materializeTopicProjectOverlay(
383
- {
384
- ...topic,
385
- ...patch,
386
- metadata: nextMetadata
387
- }
388
- );
427
+ return materializeTopicProjectOverlay({
428
+ ...topic,
429
+ ...patch,
430
+ metadata: nextMetadata
431
+ });
389
432
  }
390
433
 
391
434
  // src/resolvers.ts
392
435
  function isMissingLucernChildComponentError2(error) {
393
- const message = error instanceof Error ? error.message : String(error);
394
- return message.includes('Child component ComponentName(Identifier("lucern")) not found') || message.includes("Child component") && message.includes("lucern") && message.includes("not found");
436
+ const message = getErrorMessage2(error);
437
+ return message.includes(
438
+ 'Child component ComponentName(Identifier("lucern")) not found'
439
+ ) || message.includes("Child component") && message.includes("lucern") && message.includes("not found");
440
+ }
441
+ function getErrorMessage2(error) {
442
+ if (error instanceof Error) {
443
+ return error.message;
444
+ }
445
+ if (typeof error === "object" && error !== null && "message" in error && typeof error.message === "string") {
446
+ return error.message;
447
+ }
448
+ return "unknown error";
395
449
  }
396
450
  function isAdvisoryTopicPatch(value) {
397
451
  const advisoryKeys = /* @__PURE__ */ new Set(["lastActivityAt", "updatedAt"]);
@@ -405,32 +459,27 @@ async function patchProjectWithTolerance(ctx, projectId, value) {
405
459
  if (!isAdvisoryTopicPatch(value) || !isMissingLucernChildComponentError2(error)) {
406
460
  throw error;
407
461
  }
408
- console.warn("[lucern graph-primitives] Non-fatal advisory topic patch failure", {
409
- projectId,
410
- keys: Object.keys(value),
411
- error: error instanceof Error ? error.message : error
412
- });
462
+ console.warn(
463
+ "[lucern graph-primitives] Non-fatal advisory topic patch failure",
464
+ {
465
+ projectId,
466
+ keys: Object.keys(value),
467
+ error: getErrorMessage2(error)
468
+ }
469
+ );
413
470
  }
414
471
  }
415
472
  function defaultResolvers() {
416
473
  return {
417
- async getProject(ctx, projectId) {
418
- return await resolveTopicProjectOverlay(ctx, projectId, {
419
- idMode: "legacy",
420
- projectLikeOnly: false
421
- });
422
- },
423
- async patchProject(ctx, projectId, value) {
424
- await patchProjectWithTolerance(ctx, projectId, value);
425
- },
426
- async listTopics(ctx) {
427
- return await listTopicProjectOverlays(ctx, {
428
- idMode: "legacy"
429
- });
430
- },
431
- async getFinalArtifact(ctx, artifactId) {
432
- return await ctx.db.get(artifactId);
433
- }
474
+ getProject: (ctx, projectId) => resolveTopicProjectOverlay(ctx, projectId, {
475
+ idMode: "legacy",
476
+ projectLikeOnly: false
477
+ }),
478
+ patchProject: (ctx, projectId, value) => patchProjectWithTolerance(ctx, projectId, value),
479
+ listTopics: (ctx) => listTopicProjectOverlays(ctx, {
480
+ idMode: "legacy"
481
+ }),
482
+ getFinalArtifact: (ctx, artifactId) => ctx.db.get(artifactId)
434
483
  };
435
484
  }
436
485
  var resolverOverrides = {};
@@ -481,7 +530,14 @@ async function findTopicsByScopeAlias(ctx, scopeId) {
481
530
  "by_graph_scope_project",
482
531
  (q) => q.eq(LEGACY_SCOPE_FIELD2, scopeId)
483
532
  ).collect();
484
- } catch {
533
+ } catch (error) {
534
+ debugGraphPrimitiveFallback(
535
+ "[topicScope] Failed to resolve scope alias via index",
536
+ {
537
+ error,
538
+ scopeId
539
+ }
540
+ );
485
541
  const topics = await ctx.db.query("topics").collect();
486
542
  return topics.filter((topic) => {
487
543
  const normalizedGlobalId = normalizeScopeValue(topic.globalId);
@@ -498,7 +554,14 @@ async function tryResolveHostTopicById(ctx, topicId) {
498
554
  return await ctx.runQuery(api.topics.get, {
499
555
  id: topicId
500
556
  }) ?? null;
501
- } catch {
557
+ } catch (error) {
558
+ debugGraphPrimitiveFallback(
559
+ "[topicScope] Failed to resolve topic by host query",
560
+ {
561
+ error,
562
+ topicId
563
+ }
564
+ );
502
565
  return null;
503
566
  }
504
567
  }
@@ -510,7 +573,14 @@ async function tryResolveHostTopicByLegacyScope(ctx, legacyScopeId) {
510
573
  return await ctx.runQuery(api.topics.getByLegacyScopeId, {
511
574
  projectId: legacyScopeId
512
575
  }) ?? null;
513
- } catch {
576
+ } catch (error) {
577
+ debugGraphPrimitiveFallback(
578
+ "[topicScope] Failed to resolve topic by legacy scope",
579
+ {
580
+ error,
581
+ legacyScopeId
582
+ }
583
+ );
514
584
  return null;
515
585
  }
516
586
  }
@@ -539,8 +609,17 @@ async function resolveTopicProjectScope(ctx, args) {
539
609
  if (args.topicId) {
540
610
  let topic = null;
541
611
  try {
542
- topic = await ctx.db.get(args.topicId);
543
- } catch {
612
+ topic = await ctx.db.get(
613
+ args.topicId
614
+ );
615
+ } catch (error) {
616
+ debugGraphPrimitiveFallback(
617
+ "[topicScope] Failed to load topic by direct id",
618
+ {
619
+ error,
620
+ topicId: args.topicId
621
+ }
622
+ );
544
623
  }
545
624
  if (!topic) {
546
625
  topic = await tryResolveHostTopicById(ctx, String(args.topicId));
@@ -577,7 +656,14 @@ async function resolveTopicProjectScope(ctx, args) {
577
656
  directTopic = await ctx.db.get(
578
657
  args.projectId
579
658
  );
580
- } catch {
659
+ } catch (error) {
660
+ debugGraphPrimitiveFallback(
661
+ "[topicScope] Failed to load direct project topic",
662
+ {
663
+ error,
664
+ projectId: args.projectId
665
+ }
666
+ );
581
667
  }
582
668
  if (directTopic) {
583
669
  const inherited = await resolveInheritedWorkspaceScope(ctx, directTopic);
@@ -679,9 +765,10 @@ var ONTOLOGICAL_NODE_TYPES = [
679
765
  "function",
680
766
  "value_chain"
681
767
  ];
682
- function isOntologicalNodeType(nodeType) {
683
- return ONTOLOGICAL_NODE_TYPES.includes(nodeType);
684
- }
768
+ var ONTOLOGICAL_NODE_TYPE_SET = new Set(ONTOLOGICAL_NODE_TYPES);
769
+ var isOntologicalNodeType = ONTOLOGICAL_NODE_TYPE_SET.has.bind(
770
+ ONTOLOGICAL_NODE_TYPE_SET
771
+ );
685
772
  function normalizeCanonicalEntityText(value) {
686
773
  return value.trim().toLowerCase().replace(/\s+/g, " ");
687
774
  }