@lucern/events 1.0.13 → 1.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/webhooks.js CHANGED
@@ -11627,11 +11627,55 @@ var createEvidenceInputSchemaBase = z.object({
11627
11627
  metadata: jsonRecordSchema.optional(),
11628
11628
  trustedBypassAccessCheck: z.boolean().optional()
11629
11629
  }).passthrough();
11630
- var createEvidenceInputSchema = createEvidenceInputSchemaBase.refine(
11631
- (input) => Boolean(input.text ?? input.canonicalText),
11632
- {
11633
- message: "create_evidence requires text",
11634
- path: ["text"]
11630
+ function hasNonzeroWeight(value) {
11631
+ return typeof value === "number" && Number.isFinite(value) && value !== 0;
11632
+ }
11633
+ function hasRelationSignal(value, weight) {
11634
+ return Boolean(normalizeRelation(value, weight));
11635
+ }
11636
+ var createEvidenceInputSchema = createEvidenceInputSchemaBase.superRefine(
11637
+ (input, ctx) => {
11638
+ if (!input.text && !input.canonicalText) {
11639
+ ctx.addIssue({
11640
+ code: z.ZodIssueCode.custom,
11641
+ message: "create_evidence requires text",
11642
+ path: ["text"]
11643
+ });
11644
+ }
11645
+ const target = input.targetId ?? input.targetNodeId;
11646
+ const kind = targetKind(target);
11647
+ const linksPrimaryBelief = Boolean(
11648
+ input.linkedBeliefNodeId || kind === "belief" || kind === "unknown" && target
11649
+ );
11650
+ const weight = typeof input.weight === "number" ? input.weight : void 0;
11651
+ if (linksPrimaryBelief && !hasRelationSignal(input.evidenceRelation, weight)) {
11652
+ ctx.addIssue({
11653
+ code: z.ZodIssueCode.custom,
11654
+ message: "belief-targeted evidence requires evidenceRelation='supports'|'contradicts' or a nonzero signed weight",
11655
+ path: ["evidenceRelation"]
11656
+ });
11657
+ }
11658
+ input.beliefRelations?.forEach((relation, index) => {
11659
+ const beliefNodeId = relation.beliefNodeId ?? relation.beliefId ?? relation.targetId;
11660
+ if (!beliefNodeId) {
11661
+ ctx.addIssue({
11662
+ code: z.ZodIssueCode.custom,
11663
+ message: "beliefRelations entries require beliefId, beliefNodeId, or targetId",
11664
+ path: ["beliefRelations", index, "beliefNodeId"]
11665
+ });
11666
+ }
11667
+ const relationWeight2 = typeof relation.weight === "number" ? relation.weight : void 0;
11668
+ if (beliefNodeId && !hasRelationSignal(
11669
+ relation.evidenceRelation ?? relation.relation,
11670
+ relationWeight2
11671
+ )) {
11672
+ ctx.addIssue({
11673
+ code: z.ZodIssueCode.custom,
11674
+ message: "beliefRelations entries require evidenceRelation='supports'|'contradicts' or a nonzero signed weight",
11675
+ path: ["beliefRelations", index, "evidenceRelation"]
11676
+ });
11677
+ }
11678
+ });
11635
11679
  }
11636
11680
  );
11637
11681
  function compactRecord(input) {
@@ -11690,7 +11734,7 @@ function normalizeRelation(value, weight) {
11690
11734
  if (value === "contradicts" || value === "contradicting") {
11691
11735
  return "contradicts";
11692
11736
  }
11693
- if (weight === void 0) {
11737
+ if (weight === void 0 || !hasNonzeroWeight(weight)) {
11694
11738
  return void 0;
11695
11739
  }
11696
11740
  return weight < 0 ? "contradicts" : "supports";
@@ -13199,14 +13243,18 @@ var createEvidenceArgs = z.object({
13199
13243
  text: z.string().describe("Canonical evidence text."),
13200
13244
  source: z.string().optional().describe("Source URL or source label."),
13201
13245
  sourceUrl: z.string().optional().describe("Canonical source URL."),
13202
- targetId: z.string().optional().describe("Belief, question, or worktree identifier to link or preserve on the evidence record."),
13246
+ targetId: z.string().optional().describe(
13247
+ "Belief, question, or worktree identifier to link or preserve on the evidence record. Belief targets require evidenceRelation or a nonzero signed weight."
13248
+ ),
13203
13249
  linkedBeliefNodeId: z.string().optional().describe("Belief node this evidence bears on."),
13204
- evidenceRelation: evidenceRelationSchema2.optional().describe("How the evidence relates to the linked belief."),
13250
+ evidenceRelation: evidenceRelationSchema2.optional().describe(
13251
+ "How the evidence relates to the linked belief. Use supports for proof/fixes; use contradicts for bugs, regressions, or falsifying observations."
13252
+ ),
13205
13253
  beliefRelations: z.array(beliefRelationSchema2).optional().describe(
13206
13254
  "Additional belief relations for one evidence record. Use when the same evidence supports or contradicts multiple beliefs."
13207
13255
  ),
13208
13256
  confidence: z.number().optional().describe("Confidence in the evidence relation."),
13209
- weight: z.number().optional().describe("Support weight from -1.0 to +1.0."),
13257
+ weight: z.number().optional().describe("Nonzero support weight from -1.0 to +1.0."),
13210
13258
  metadata: jsonRecordSchema4.optional().describe("Metadata merged into the canonical evidence node."),
13211
13259
  rationale: z.string().describe("Why this evidence should enter the reasoning graph."),
13212
13260
  reasoning: z.string().optional().describe("Reasoning note preserved in evidence metadata."),
@@ -13248,13 +13296,18 @@ var createEvidenceInput = (input, context) => {
13248
13296
  );
13249
13297
  };
13250
13298
  function relationWeight(input) {
13251
- if (typeof input.weight === "number") {
13299
+ if (typeof input.weight === "number" && Number.isFinite(input.weight) && input.weight !== 0) {
13252
13300
  return input.weight;
13253
13301
  }
13254
- const confidence = typeof input.confidence === "number" ? Math.max(0, Math.min(1, input.confidence)) : 0.7;
13255
13302
  const relation = String(
13256
13303
  input.evidenceRelation ?? input.relation ?? input.type ?? ""
13257
13304
  );
13305
+ if (relation !== "supports" && relation !== "supporting" && relation !== "contradicts" && relation !== "contradicting") {
13306
+ throw new Error(
13307
+ "Belief evidence links require evidenceRelation='supports'|'contradicts' or a nonzero signed weight."
13308
+ );
13309
+ }
13310
+ const confidence = typeof input.confidence === "number" ? Math.max(0, Math.min(1, input.confidence)) : 0.7;
13258
13311
  return relation === "contradicts" || relation === "contradicting" ? -confidence : confidence;
13259
13312
  }
13260
13313
  var linkEvidenceToBeliefInput = (input, context) => {
@@ -13281,7 +13334,7 @@ var linkEvidenceToBeliefEdgeInput = (input, context) => withCreatedBy(
13281
13334
  )}:${String(
13282
13335
  input.beliefNodeId ?? input.beliefId ?? input.targetId
13283
13336
  )}:informs`,
13284
- weight: typeof input.weight === "number" ? input.weight : input.type === "contradicting" ? -1 : 1,
13337
+ weight: relationWeight(input),
13285
13338
  context: input.rationale ?? input.context,
13286
13339
  skipLayerValidation: true,
13287
13340
  topicId: input.topicId,