@lucern/contracts 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/index.js CHANGED
@@ -48558,11 +48558,55 @@ var createEvidenceInputSchemaBase = z.object({
48558
48558
  metadata: jsonRecordSchema.optional(),
48559
48559
  trustedBypassAccessCheck: z.boolean().optional()
48560
48560
  }).passthrough();
48561
- var createEvidenceInputSchema = createEvidenceInputSchemaBase.refine(
48562
- (input) => Boolean(input.text ?? input.canonicalText),
48563
- {
48564
- message: "create_evidence requires text",
48565
- path: ["text"]
48561
+ function hasNonzeroWeight(value) {
48562
+ return typeof value === "number" && Number.isFinite(value) && value !== 0;
48563
+ }
48564
+ function hasRelationSignal(value, weight) {
48565
+ return Boolean(normalizeRelation(value, weight));
48566
+ }
48567
+ var createEvidenceInputSchema = createEvidenceInputSchemaBase.superRefine(
48568
+ (input, ctx) => {
48569
+ if (!input.text && !input.canonicalText) {
48570
+ ctx.addIssue({
48571
+ code: z.ZodIssueCode.custom,
48572
+ message: "create_evidence requires text",
48573
+ path: ["text"]
48574
+ });
48575
+ }
48576
+ const target = input.targetId ?? input.targetNodeId;
48577
+ const kind = targetKind(target);
48578
+ const linksPrimaryBelief = Boolean(
48579
+ input.linkedBeliefNodeId || kind === "belief" || kind === "unknown" && target
48580
+ );
48581
+ const weight = typeof input.weight === "number" ? input.weight : void 0;
48582
+ if (linksPrimaryBelief && !hasRelationSignal(input.evidenceRelation, weight)) {
48583
+ ctx.addIssue({
48584
+ code: z.ZodIssueCode.custom,
48585
+ message: "belief-targeted evidence requires evidenceRelation='supports'|'contradicts' or a nonzero signed weight",
48586
+ path: ["evidenceRelation"]
48587
+ });
48588
+ }
48589
+ input.beliefRelations?.forEach((relation, index) => {
48590
+ const beliefNodeId = relation.beliefNodeId ?? relation.beliefId ?? relation.targetId;
48591
+ if (!beliefNodeId) {
48592
+ ctx.addIssue({
48593
+ code: z.ZodIssueCode.custom,
48594
+ message: "beliefRelations entries require beliefId, beliefNodeId, or targetId",
48595
+ path: ["beliefRelations", index, "beliefNodeId"]
48596
+ });
48597
+ }
48598
+ const relationWeight = typeof relation.weight === "number" ? relation.weight : void 0;
48599
+ if (beliefNodeId && !hasRelationSignal(
48600
+ relation.evidenceRelation ?? relation.relation,
48601
+ relationWeight
48602
+ )) {
48603
+ ctx.addIssue({
48604
+ code: z.ZodIssueCode.custom,
48605
+ message: "beliefRelations entries require evidenceRelation='supports'|'contradicts' or a nonzero signed weight",
48606
+ path: ["beliefRelations", index, "evidenceRelation"]
48607
+ });
48608
+ }
48609
+ });
48566
48610
  }
48567
48611
  );
48568
48612
  function compactRecord(input) {
@@ -48621,7 +48665,7 @@ function normalizeRelation(value, weight) {
48621
48665
  if (value === "contradicts" || value === "contradicting") {
48622
48666
  return "contradicts";
48623
48667
  }
48624
- if (weight === void 0) {
48668
+ if (weight === void 0 || !hasNonzeroWeight(weight)) {
48625
48669
  return void 0;
48626
48670
  }
48627
48671
  return weight < 0 ? "contradicts" : "supports";