@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.js CHANGED
@@ -5,7 +5,7 @@ var __export = (target, all) => {
5
5
  };
6
6
 
7
7
  // src/config.ts
8
- var SDK_VERSION = "1.3.0";
8
+ var SDK_VERSION = "1.4.0";
9
9
  function resolveConfig(config) {
10
10
  if (!config.baseUrl) {
11
11
  throw new Error("ClientConfig.baseUrl is required");
@@ -9068,6 +9068,7 @@ var TAGGED_VALUE_TYPES = /* @__PURE__ */ new Set([
9068
9068
  "Boolean",
9069
9069
  "Uninstantiated",
9070
9070
  "Reference",
9071
+ "SortId",
9071
9072
  "List",
9072
9073
  "FuzzyScalar",
9073
9074
  "FuzzyNumber",
@@ -9163,6 +9164,12 @@ function toUntaggedValue(value) {
9163
9164
  };
9164
9165
  }
9165
9166
  if (isTaggedValueDto(value)) {
9167
+ if (value.type === "Reference") {
9168
+ return { termId: value.value };
9169
+ }
9170
+ if (value.type === "SortId") {
9171
+ return { sortRef: value.value };
9172
+ }
9166
9173
  return value;
9167
9174
  }
9168
9175
  return value;
@@ -9575,6 +9582,9 @@ function FeatureInputValueDtoFromFrontToApi(value) {
9575
9582
  ...features ? { features } : {}
9576
9583
  };
9577
9584
  }
9585
+ if ("sortRef" in value) {
9586
+ return { sort_ref: value.sortRef };
9587
+ }
9578
9588
  return { term_id: value.termId };
9579
9589
  }
9580
9590
  function featuresInputFromFrontToApi(features) {
@@ -20835,7 +20845,12 @@ var OptimizeClient = class {
20835
20845
  sorts: [{ name: solutionSortName, parents: ["thing"] }]
20836
20846
  });
20837
20847
  const sortIdsMap = sortResponse.data.sort_ids;
20838
- sortId = Object.values(sortIdsMap)[0];
20848
+ sortId = sortIdsMap[solutionSortName];
20849
+ if (!sortId) {
20850
+ throw new Error(
20851
+ `bulkCreateSorts did not return an id for '${solutionSortName}' (returned: ${Object.keys(sortIdsMap).join(", ")})`
20852
+ );
20853
+ }
20839
20854
  const ruleResponse = await this.inferenceApi.addRule({
20840
20855
  term: TermInputDtoFromFrontToApi(compiled.solutionTerm),
20841
20856
  antecedents: compiled.antecedents.map(TermInputDtoFromFrontToApi),
@@ -23214,6 +23229,26 @@ var Value = {
23214
23229
  reference(id) {
23215
23230
  return { type: "Reference", value: id };
23216
23231
  },
23232
+ /**
23233
+ * Create a reference to a sort by UUID.
23234
+ *
23235
+ * @param id - The UUID of the sort.
23236
+ * @returns A tagged `SortIdValue`: `{"type": "SortId", "value": "uuid"}`.
23237
+ *
23238
+ * @remarks
23239
+ * Used by homoiconic meta-constraints — primarily `Constraint.typeOf(...)`
23240
+ * — whose feature targets a sort as a first-class value. The chainer
23241
+ * dispatches this directly via `Value::SortId`.
23242
+ *
23243
+ * @example
23244
+ * ```typescript
23245
+ * Value.sortId("550e8400-e29b-41d4-a716-446655440000")
23246
+ * // { type: 'SortId', value: '550e8400-e29b-41d4-a716-446655440000' }
23247
+ * ```
23248
+ */
23249
+ sortId(id) {
23250
+ return { type: "SortId", value: id };
23251
+ },
23217
23252
  /**
23218
23253
  * Create a fuzzy scalar with a value and membership degree.
23219
23254
  *
@@ -23631,6 +23666,145 @@ var FuzzyShape = {
23631
23666
  }
23632
23667
  };
23633
23668
 
23669
+ // src/builders/psi.ts
23670
+ function psi(sortOrName, features) {
23671
+ if (typeof sortOrName === "string") {
23672
+ if (!features) {
23673
+ return { __psiTerm: true, sortName: sortOrName };
23674
+ }
23675
+ return {
23676
+ __psiTerm: true,
23677
+ sortName: sortOrName,
23678
+ features
23679
+ };
23680
+ }
23681
+ if (!features) {
23682
+ return { __psiTerm: true, sortId: sortOrName.sortId };
23683
+ }
23684
+ return {
23685
+ __psiTerm: true,
23686
+ sortId: sortOrName.sortId,
23687
+ features
23688
+ };
23689
+ }
23690
+ function constrained(name, constraint) {
23691
+ return { __constrainedVar: true, name, constraint };
23692
+ }
23693
+
23694
+ // src/builders/constraint.ts
23695
+ var ARITHMETIC_SORT = {
23696
+ "+": "plus_constraint",
23697
+ "-": "minus_constraint",
23698
+ "*": "times_constraint",
23699
+ "/": "div_constraint"
23700
+ };
23701
+ var Constraint = {
23702
+ /**
23703
+ * State that a variable is a term of a given sort. The chainer enumerates
23704
+ * every persisted term of that sort via backtracking.
23705
+ *
23706
+ * @param variable - Variable name (e.g. `'?E'`) or pre-built variable Ψ-term.
23707
+ * @param sortUuid - UUID of the target sort (resolve from
23708
+ * `client.inference.getMetaSorts()` or your own `createSort` response).
23709
+ * @returns A `sort_constraint` term.
23710
+ */
23711
+ typeOf(variable, sortUuid) {
23712
+ return psi("sort_constraint", {
23713
+ var: variable,
23714
+ sort: { sortRef: sortUuid }
23715
+ });
23716
+ },
23717
+ /**
23718
+ * State that a variable's feature equals a target. The chainer unifies
23719
+ * the variable's feature value with the target.
23720
+ *
23721
+ * **Important**: the chainer's `feature_constraint` only unifies
23722
+ * term-references with term-references. The variable's feature on the
23723
+ * persisted side must itself be a `Value::Reference`. Comparing against
23724
+ * literals (e.g. `has('?N', 'name', 'S')` where `name` is stored as a
23725
+ * plain string) silently returns zero solutions — that's a chainer
23726
+ * design constraint, not a builder bug.
23727
+ *
23728
+ * @param variable - The owning variable (e.g. `'?Edge'`).
23729
+ * @param feature - The feature name (e.g. `'src'`).
23730
+ * @param target - The target — typically another variable (`'?Src'`)
23731
+ * or an existing term referenced by its UUID via `'!<uuid>'`.
23732
+ * @returns A `feature_constraint` term.
23733
+ */
23734
+ has(variable, feature, target) {
23735
+ return psi("feature_constraint", {
23736
+ var: variable,
23737
+ feature,
23738
+ target
23739
+ });
23740
+ },
23741
+ /**
23742
+ * State a boolean comparison between two operands. The chainer
23743
+ * residuates the constraint until both sides are bound; when they are,
23744
+ * the comparison must hold or the proof branch fails.
23745
+ *
23746
+ * @param left - Left operand — variable, literal number, or term ref.
23747
+ * @param op - Comparison operator.
23748
+ * @param right - Right operand.
23749
+ * @returns A `guard_constraint` term.
23750
+ */
23751
+ where(left, op, right) {
23752
+ return psi("guard_constraint", {
23753
+ left,
23754
+ operator: op,
23755
+ right
23756
+ });
23757
+ },
23758
+ /**
23759
+ * State that `result = left op right`. Selects the chainer sort by op:
23760
+ * `+` → `plus_constraint`, `-` → `minus_constraint`, `*` →
23761
+ * `times_constraint`, `/` → `div_constraint`. The chainer reads each
23762
+ * operand as either a Reference variable or a numeric literal, and can
23763
+ * run forward, reverse, or verify depending on which operands are
23764
+ * bound.
23765
+ *
23766
+ * @param result - Result variable or value (`z`).
23767
+ * @param op - Arithmetic operator.
23768
+ * @param left - Left operand (`x`).
23769
+ * @param right - Right operand (`y`).
23770
+ * @returns The appropriate arithmetic-constraint term.
23771
+ */
23772
+ equation(result, op, left, right) {
23773
+ return psi(ARITHMETIC_SORT[op], { x: left, y: right, z: result });
23774
+ },
23775
+ /**
23776
+ * Constrain a variable to be an integer in the inclusive range
23777
+ * `[min, max]`. Required before the chainer's labeling step can assign
23778
+ * a concrete value via {@link Constraint.solveFor}.
23779
+ *
23780
+ * @param variable - Variable name to constrain.
23781
+ * @param min - Lower bound (inclusive).
23782
+ * @param max - Upper bound (inclusive).
23783
+ * @returns An `fd_domain_constraint` term.
23784
+ */
23785
+ intRange(variable, min, max) {
23786
+ return psi("fd_domain_constraint", {
23787
+ var: variable,
23788
+ min,
23789
+ max
23790
+ });
23791
+ },
23792
+ /**
23793
+ * Search for concrete integer assignments to the listed variables that
23794
+ * satisfy every other constraint mentioning them. Place this at the END
23795
+ * of a clause body — it's the labeling/search step that turns a
23796
+ * constraint network into solutions.
23797
+ *
23798
+ * @param variables - Variable names to assign.
23799
+ * @returns An `fd_labeling_constraint` term.
23800
+ */
23801
+ solveFor(...variables) {
23802
+ return psi("fd_labeling_constraint", {
23803
+ vars: variables
23804
+ });
23805
+ }
23806
+ };
23807
+
23634
23808
  // src/builders/guard.ts
23635
23809
  function guard(op, right) {
23636
23810
  return {
@@ -23808,31 +23982,6 @@ var SortBuilder = class _SortBuilder {
23808
23982
  }
23809
23983
  };
23810
23984
 
23811
- // src/builders/psi.ts
23812
- function psi(sortOrName, features) {
23813
- if (typeof sortOrName === "string") {
23814
- if (!features) {
23815
- return { __psiTerm: true, sortName: sortOrName };
23816
- }
23817
- return {
23818
- __psiTerm: true,
23819
- sortName: sortOrName,
23820
- features
23821
- };
23822
- }
23823
- if (!features) {
23824
- return { __psiTerm: true, sortId: sortOrName.sortId };
23825
- }
23826
- return {
23827
- __psiTerm: true,
23828
- sortId: sortOrName.sortId,
23829
- features
23830
- };
23831
- }
23832
- function constrained(name, constraint) {
23833
- return { __constrainedVar: true, name, constraint };
23834
- }
23835
-
23836
23985
  // src/builders/allen.ts
23837
23986
  function allen(relation, intervalA, intervalBTermId) {
23838
23987
  return {
@@ -24092,6 +24241,6 @@ function discriminateFeatureValue(value) {
24092
24241
  );
24093
24242
  }
24094
24243
 
24095
- export { ANY_ROLE, action_reviews_exports as ActionReviews, admin_exports as Admin, analysis_exports as Analysis, ApiError, AuthenticationError, BadRequestError, cdl_exports as CDL, causal_exports as Causal, cognitive_exports as Cognitive, collections_exports as Collections, communities_exports as Communities, compliance_exports as Compliance, ConstraintViolationError, constraints_exports as Constraints, control_exports as Control, conversation_exports as Conversation, discovery_exports as Discovery, execution_exports as Execution, extract_exports as Extract, Flow, flow_networks_exports as FlowNetworks, ForbiddenError, functions_exports as Functions, fuzzy_exports as Fuzzy, FuzzyShape, generation_exports as Generation, health_exports as Health, homoiconic_exports as Homoiconic, ilp_exports as ILP, image_extraction_exports as ImageExtraction, inference_exports as Inference, ingestion_exports as Ingestion, IngestionFailedError, IngestionSession, InternalServerError, LP, namespaces_exports as Namespaces, NetworkError, neuro_symbolic_exports as NeuroSymbolic, NotFoundError, ontology_exports as Ontology, operations_exports as Operations, optimize_exports as Optimize, osfql_exports as Osfql, oversight_exports as Oversight, plain_values_exports as PlainValues, preferences_exports as Preferences, proof_engine_exports as ProofEngine, query_exports as Query, rag_exports as RAG, RateLimitError, reasoning_exports as Reasoning, ReasoningLayerClient, ReasoningLayerError, research_exports as Research, reviews_exports as Reviews, row_exports as Row, SDK_VERSION, scenarios_exports as Scenarios, scheduling_exports as Scheduling, SortBuilder, sorts_exports as Sorts, sources_exports as Sources, spaces_exports as Spaces, statistical_exports as Statistical, synthetic_exports as Synthetic, terms_exports as Terms, TimeoutError, utilities_exports as Utilities, ValidationError, Value, values_exports as Values, visualization_exports as Visualization, WebSocketClient, WebSocketConnection, webhook_actions_exports as WebhookActions, allen, constrained, discriminateFeatureValue, guard, isConstrainedPlainVar, isPsiTermInput, isTaggedValueDto, isUuid, psi, toTaggedFeatures, toTaggedValue, toTermInputDto, toUntaggedFeatures, toUntaggedValue };
24244
+ export { ANY_ROLE, action_reviews_exports as ActionReviews, admin_exports as Admin, analysis_exports as Analysis, ApiError, AuthenticationError, BadRequestError, cdl_exports as CDL, causal_exports as Causal, cognitive_exports as Cognitive, collections_exports as Collections, communities_exports as Communities, compliance_exports as Compliance, Constraint, ConstraintViolationError, constraints_exports as Constraints, control_exports as Control, conversation_exports as Conversation, discovery_exports as Discovery, execution_exports as Execution, extract_exports as Extract, Flow, flow_networks_exports as FlowNetworks, ForbiddenError, functions_exports as Functions, fuzzy_exports as Fuzzy, FuzzyShape, generation_exports as Generation, health_exports as Health, homoiconic_exports as Homoiconic, ilp_exports as ILP, image_extraction_exports as ImageExtraction, inference_exports as Inference, ingestion_exports as Ingestion, IngestionFailedError, IngestionSession, InternalServerError, LP, namespaces_exports as Namespaces, NetworkError, neuro_symbolic_exports as NeuroSymbolic, NotFoundError, ontology_exports as Ontology, operations_exports as Operations, optimize_exports as Optimize, osfql_exports as Osfql, oversight_exports as Oversight, plain_values_exports as PlainValues, preferences_exports as Preferences, proof_engine_exports as ProofEngine, query_exports as Query, rag_exports as RAG, RateLimitError, reasoning_exports as Reasoning, ReasoningLayerClient, ReasoningLayerError, research_exports as Research, reviews_exports as Reviews, row_exports as Row, SDK_VERSION, scenarios_exports as Scenarios, scheduling_exports as Scheduling, SortBuilder, sorts_exports as Sorts, sources_exports as Sources, spaces_exports as Spaces, statistical_exports as Statistical, synthetic_exports as Synthetic, terms_exports as Terms, TimeoutError, utilities_exports as Utilities, ValidationError, Value, values_exports as Values, visualization_exports as Visualization, WebSocketClient, WebSocketConnection, webhook_actions_exports as WebhookActions, allen, constrained, discriminateFeatureValue, guard, isConstrainedPlainVar, isPsiTermInput, isTaggedValueDto, isUuid, psi, toTaggedFeatures, toTaggedValue, toTermInputDto, toUntaggedFeatures, toUntaggedValue };
24096
24245
  //# sourceMappingURL=index.js.map
24097
24246
  //# sourceMappingURL=index.js.map