@kortexya/reasoninglayer 1.3.0 → 1.4.0
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.cjs +177 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +169 -6
- package/dist/index.d.ts +169 -6
- package/dist/index.js +177 -28
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -7,7 +7,7 @@ var __export = (target, all) => {
|
|
|
7
7
|
};
|
|
8
8
|
|
|
9
9
|
// src/config.ts
|
|
10
|
-
var SDK_VERSION = "1.
|
|
10
|
+
var SDK_VERSION = "1.4.0";
|
|
11
11
|
function resolveConfig(config) {
|
|
12
12
|
if (!config.baseUrl) {
|
|
13
13
|
throw new Error("ClientConfig.baseUrl is required");
|
|
@@ -9070,6 +9070,7 @@ var TAGGED_VALUE_TYPES = /* @__PURE__ */ new Set([
|
|
|
9070
9070
|
"Boolean",
|
|
9071
9071
|
"Uninstantiated",
|
|
9072
9072
|
"Reference",
|
|
9073
|
+
"SortId",
|
|
9073
9074
|
"List",
|
|
9074
9075
|
"FuzzyScalar",
|
|
9075
9076
|
"FuzzyNumber",
|
|
@@ -9165,6 +9166,12 @@ function toUntaggedValue(value) {
|
|
|
9165
9166
|
};
|
|
9166
9167
|
}
|
|
9167
9168
|
if (isTaggedValueDto(value)) {
|
|
9169
|
+
if (value.type === "Reference") {
|
|
9170
|
+
return { termId: value.value };
|
|
9171
|
+
}
|
|
9172
|
+
if (value.type === "SortId") {
|
|
9173
|
+
return { sortRef: value.value };
|
|
9174
|
+
}
|
|
9168
9175
|
return value;
|
|
9169
9176
|
}
|
|
9170
9177
|
return value;
|
|
@@ -9577,6 +9584,9 @@ function FeatureInputValueDtoFromFrontToApi(value) {
|
|
|
9577
9584
|
...features ? { features } : {}
|
|
9578
9585
|
};
|
|
9579
9586
|
}
|
|
9587
|
+
if ("sortRef" in value) {
|
|
9588
|
+
return { sort_ref: value.sortRef };
|
|
9589
|
+
}
|
|
9580
9590
|
return { term_id: value.termId };
|
|
9581
9591
|
}
|
|
9582
9592
|
function featuresInputFromFrontToApi(features) {
|
|
@@ -20837,7 +20847,12 @@ var OptimizeClient = class {
|
|
|
20837
20847
|
sorts: [{ name: solutionSortName, parents: ["thing"] }]
|
|
20838
20848
|
});
|
|
20839
20849
|
const sortIdsMap = sortResponse.data.sort_ids;
|
|
20840
|
-
sortId =
|
|
20850
|
+
sortId = sortIdsMap[solutionSortName];
|
|
20851
|
+
if (!sortId) {
|
|
20852
|
+
throw new Error(
|
|
20853
|
+
`bulkCreateSorts did not return an id for '${solutionSortName}' (returned: ${Object.keys(sortIdsMap).join(", ")})`
|
|
20854
|
+
);
|
|
20855
|
+
}
|
|
20841
20856
|
const ruleResponse = await this.inferenceApi.addRule({
|
|
20842
20857
|
term: TermInputDtoFromFrontToApi(compiled.solutionTerm),
|
|
20843
20858
|
antecedents: compiled.antecedents.map(TermInputDtoFromFrontToApi),
|
|
@@ -23216,6 +23231,26 @@ var Value = {
|
|
|
23216
23231
|
reference(id) {
|
|
23217
23232
|
return { type: "Reference", value: id };
|
|
23218
23233
|
},
|
|
23234
|
+
/**
|
|
23235
|
+
* Create a reference to a sort by UUID.
|
|
23236
|
+
*
|
|
23237
|
+
* @param id - The UUID of the sort.
|
|
23238
|
+
* @returns A tagged `SortIdValue`: `{"type": "SortId", "value": "uuid"}`.
|
|
23239
|
+
*
|
|
23240
|
+
* @remarks
|
|
23241
|
+
* Used by homoiconic meta-constraints — primarily `Constraint.typeOf(...)`
|
|
23242
|
+
* — whose feature targets a sort as a first-class value. The chainer
|
|
23243
|
+
* dispatches this directly via `Value::SortId`.
|
|
23244
|
+
*
|
|
23245
|
+
* @example
|
|
23246
|
+
* ```typescript
|
|
23247
|
+
* Value.sortId("550e8400-e29b-41d4-a716-446655440000")
|
|
23248
|
+
* // { type: 'SortId', value: '550e8400-e29b-41d4-a716-446655440000' }
|
|
23249
|
+
* ```
|
|
23250
|
+
*/
|
|
23251
|
+
sortId(id) {
|
|
23252
|
+
return { type: "SortId", value: id };
|
|
23253
|
+
},
|
|
23219
23254
|
/**
|
|
23220
23255
|
* Create a fuzzy scalar with a value and membership degree.
|
|
23221
23256
|
*
|
|
@@ -23633,6 +23668,145 @@ var FuzzyShape = {
|
|
|
23633
23668
|
}
|
|
23634
23669
|
};
|
|
23635
23670
|
|
|
23671
|
+
// src/builders/psi.ts
|
|
23672
|
+
function psi(sortOrName, features) {
|
|
23673
|
+
if (typeof sortOrName === "string") {
|
|
23674
|
+
if (!features) {
|
|
23675
|
+
return { __psiTerm: true, sortName: sortOrName };
|
|
23676
|
+
}
|
|
23677
|
+
return {
|
|
23678
|
+
__psiTerm: true,
|
|
23679
|
+
sortName: sortOrName,
|
|
23680
|
+
features
|
|
23681
|
+
};
|
|
23682
|
+
}
|
|
23683
|
+
if (!features) {
|
|
23684
|
+
return { __psiTerm: true, sortId: sortOrName.sortId };
|
|
23685
|
+
}
|
|
23686
|
+
return {
|
|
23687
|
+
__psiTerm: true,
|
|
23688
|
+
sortId: sortOrName.sortId,
|
|
23689
|
+
features
|
|
23690
|
+
};
|
|
23691
|
+
}
|
|
23692
|
+
function constrained(name, constraint) {
|
|
23693
|
+
return { __constrainedVar: true, name, constraint };
|
|
23694
|
+
}
|
|
23695
|
+
|
|
23696
|
+
// src/builders/constraint.ts
|
|
23697
|
+
var ARITHMETIC_SORT = {
|
|
23698
|
+
"+": "plus_constraint",
|
|
23699
|
+
"-": "minus_constraint",
|
|
23700
|
+
"*": "times_constraint",
|
|
23701
|
+
"/": "div_constraint"
|
|
23702
|
+
};
|
|
23703
|
+
var Constraint = {
|
|
23704
|
+
/**
|
|
23705
|
+
* State that a variable is a term of a given sort. The chainer enumerates
|
|
23706
|
+
* every persisted term of that sort via backtracking.
|
|
23707
|
+
*
|
|
23708
|
+
* @param variable - Variable name (e.g. `'?E'`) or pre-built variable Ψ-term.
|
|
23709
|
+
* @param sortUuid - UUID of the target sort (resolve from
|
|
23710
|
+
* `client.inference.getMetaSorts()` or your own `createSort` response).
|
|
23711
|
+
* @returns A `sort_constraint` term.
|
|
23712
|
+
*/
|
|
23713
|
+
typeOf(variable, sortUuid) {
|
|
23714
|
+
return psi("sort_constraint", {
|
|
23715
|
+
var: variable,
|
|
23716
|
+
sort: { sortRef: sortUuid }
|
|
23717
|
+
});
|
|
23718
|
+
},
|
|
23719
|
+
/**
|
|
23720
|
+
* State that a variable's feature equals a target. The chainer unifies
|
|
23721
|
+
* the variable's feature value with the target.
|
|
23722
|
+
*
|
|
23723
|
+
* **Important**: the chainer's `feature_constraint` only unifies
|
|
23724
|
+
* term-references with term-references. The variable's feature on the
|
|
23725
|
+
* persisted side must itself be a `Value::Reference`. Comparing against
|
|
23726
|
+
* literals (e.g. `has('?N', 'name', 'S')` where `name` is stored as a
|
|
23727
|
+
* plain string) silently returns zero solutions — that's a chainer
|
|
23728
|
+
* design constraint, not a builder bug.
|
|
23729
|
+
*
|
|
23730
|
+
* @param variable - The owning variable (e.g. `'?Edge'`).
|
|
23731
|
+
* @param feature - The feature name (e.g. `'src'`).
|
|
23732
|
+
* @param target - The target — typically another variable (`'?Src'`)
|
|
23733
|
+
* or an existing term referenced by its UUID via `'!<uuid>'`.
|
|
23734
|
+
* @returns A `feature_constraint` term.
|
|
23735
|
+
*/
|
|
23736
|
+
has(variable, feature, target) {
|
|
23737
|
+
return psi("feature_constraint", {
|
|
23738
|
+
var: variable,
|
|
23739
|
+
feature,
|
|
23740
|
+
target
|
|
23741
|
+
});
|
|
23742
|
+
},
|
|
23743
|
+
/**
|
|
23744
|
+
* State a boolean comparison between two operands. The chainer
|
|
23745
|
+
* residuates the constraint until both sides are bound; when they are,
|
|
23746
|
+
* the comparison must hold or the proof branch fails.
|
|
23747
|
+
*
|
|
23748
|
+
* @param left - Left operand — variable, literal number, or term ref.
|
|
23749
|
+
* @param op - Comparison operator.
|
|
23750
|
+
* @param right - Right operand.
|
|
23751
|
+
* @returns A `guard_constraint` term.
|
|
23752
|
+
*/
|
|
23753
|
+
where(left, op, right) {
|
|
23754
|
+
return psi("guard_constraint", {
|
|
23755
|
+
left,
|
|
23756
|
+
operator: op,
|
|
23757
|
+
right
|
|
23758
|
+
});
|
|
23759
|
+
},
|
|
23760
|
+
/**
|
|
23761
|
+
* State that `result = left op right`. Selects the chainer sort by op:
|
|
23762
|
+
* `+` → `plus_constraint`, `-` → `minus_constraint`, `*` →
|
|
23763
|
+
* `times_constraint`, `/` → `div_constraint`. The chainer reads each
|
|
23764
|
+
* operand as either a Reference variable or a numeric literal, and can
|
|
23765
|
+
* run forward, reverse, or verify depending on which operands are
|
|
23766
|
+
* bound.
|
|
23767
|
+
*
|
|
23768
|
+
* @param result - Result variable or value (`z`).
|
|
23769
|
+
* @param op - Arithmetic operator.
|
|
23770
|
+
* @param left - Left operand (`x`).
|
|
23771
|
+
* @param right - Right operand (`y`).
|
|
23772
|
+
* @returns The appropriate arithmetic-constraint term.
|
|
23773
|
+
*/
|
|
23774
|
+
equation(result, op, left, right) {
|
|
23775
|
+
return psi(ARITHMETIC_SORT[op], { x: left, y: right, z: result });
|
|
23776
|
+
},
|
|
23777
|
+
/**
|
|
23778
|
+
* Constrain a variable to be an integer in the inclusive range
|
|
23779
|
+
* `[min, max]`. Required before the chainer's labeling step can assign
|
|
23780
|
+
* a concrete value via {@link Constraint.solveFor}.
|
|
23781
|
+
*
|
|
23782
|
+
* @param variable - Variable name to constrain.
|
|
23783
|
+
* @param min - Lower bound (inclusive).
|
|
23784
|
+
* @param max - Upper bound (inclusive).
|
|
23785
|
+
* @returns An `fd_domain_constraint` term.
|
|
23786
|
+
*/
|
|
23787
|
+
intRange(variable, min, max) {
|
|
23788
|
+
return psi("fd_domain_constraint", {
|
|
23789
|
+
var: variable,
|
|
23790
|
+
min,
|
|
23791
|
+
max
|
|
23792
|
+
});
|
|
23793
|
+
},
|
|
23794
|
+
/**
|
|
23795
|
+
* Search for concrete integer assignments to the listed variables that
|
|
23796
|
+
* satisfy every other constraint mentioning them. Place this at the END
|
|
23797
|
+
* of a clause body — it's the labeling/search step that turns a
|
|
23798
|
+
* constraint network into solutions.
|
|
23799
|
+
*
|
|
23800
|
+
* @param variables - Variable names to assign.
|
|
23801
|
+
* @returns An `fd_labeling_constraint` term.
|
|
23802
|
+
*/
|
|
23803
|
+
solveFor(...variables) {
|
|
23804
|
+
return psi("fd_labeling_constraint", {
|
|
23805
|
+
vars: variables
|
|
23806
|
+
});
|
|
23807
|
+
}
|
|
23808
|
+
};
|
|
23809
|
+
|
|
23636
23810
|
// src/builders/guard.ts
|
|
23637
23811
|
function guard(op, right) {
|
|
23638
23812
|
return {
|
|
@@ -23810,31 +23984,6 @@ var SortBuilder = class _SortBuilder {
|
|
|
23810
23984
|
}
|
|
23811
23985
|
};
|
|
23812
23986
|
|
|
23813
|
-
// src/builders/psi.ts
|
|
23814
|
-
function psi(sortOrName, features) {
|
|
23815
|
-
if (typeof sortOrName === "string") {
|
|
23816
|
-
if (!features) {
|
|
23817
|
-
return { __psiTerm: true, sortName: sortOrName };
|
|
23818
|
-
}
|
|
23819
|
-
return {
|
|
23820
|
-
__psiTerm: true,
|
|
23821
|
-
sortName: sortOrName,
|
|
23822
|
-
features
|
|
23823
|
-
};
|
|
23824
|
-
}
|
|
23825
|
-
if (!features) {
|
|
23826
|
-
return { __psiTerm: true, sortId: sortOrName.sortId };
|
|
23827
|
-
}
|
|
23828
|
-
return {
|
|
23829
|
-
__psiTerm: true,
|
|
23830
|
-
sortId: sortOrName.sortId,
|
|
23831
|
-
features
|
|
23832
|
-
};
|
|
23833
|
-
}
|
|
23834
|
-
function constrained(name, constraint) {
|
|
23835
|
-
return { __constrainedVar: true, name, constraint };
|
|
23836
|
-
}
|
|
23837
|
-
|
|
23838
23987
|
// src/builders/allen.ts
|
|
23839
23988
|
function allen(relation, intervalA, intervalBTermId) {
|
|
23840
23989
|
return {
|
|
@@ -24107,6 +24256,7 @@ exports.Cognitive = cognitive_exports;
|
|
|
24107
24256
|
exports.Collections = collections_exports;
|
|
24108
24257
|
exports.Communities = communities_exports;
|
|
24109
24258
|
exports.Compliance = compliance_exports;
|
|
24259
|
+
exports.Constraint = Constraint;
|
|
24110
24260
|
exports.ConstraintViolationError = ConstraintViolationError;
|
|
24111
24261
|
exports.Constraints = constraints_exports;
|
|
24112
24262
|
exports.Control = control_exports;
|