@kortexya/reasoninglayer 1.23.0 → 1.24.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 CHANGED
@@ -7,7 +7,7 @@ var __export = (target, all) => {
7
7
  };
8
8
 
9
9
  // src/config.ts
10
- var SDK_VERSION = "1.23.0";
10
+ var SDK_VERSION = "1.24.0";
11
11
  function resolveConfig(config) {
12
12
  if (!config.baseUrl) {
13
13
  throw new Error("ClientConfig.baseUrl is required");
@@ -1877,6 +1877,23 @@ var Inference = class {
1877
1877
  format: "json",
1878
1878
  ...params
1879
1879
  });
1880
+ /**
1881
+ * @description # The disposition is the caller's `?derivations=refuse` (the default) refuses while the rule still supports materialized conclusions and says how many; `?derivations=retract` withdraws them with it and reports the counts. A delete that silently drops derivations is as wrong as one that silently keeps them, so neither is the unnamed default. # Authorization Requires `X-Tenant-Id`. Runs the same delete guard as `DELETE /api/v1/terms/{id}` — a rule is a policy-relevant object, and withdrawing one changes what the engine will conclude. Honours `If-Match` against the conclusion's content ETag, and requires it under `OSFKB_REQUIRE_IF_MATCH=1`. Every request is captured by the audit middleware.
1882
+ *
1883
+ * @tags inference
1884
+ * @name DeleteRule
1885
+ * @summary Delete a rule.
1886
+ * @request DELETE:/api/v1/inference/rules/{id}
1887
+ * @secure
1888
+ */
1889
+ deleteRule = (id, query, params = {}) => this.http.request({
1890
+ path: `/api/v1/inference/rules/${id}`,
1891
+ method: "DELETE",
1892
+ query,
1893
+ secure: true,
1894
+ format: "json",
1895
+ ...params
1896
+ });
1880
1897
  /**
1881
1898
  * @description Never writes to the KB — returns validated drafts for human review.
1882
1899
  *
@@ -1999,16 +2016,16 @@ var Inference = class {
1999
2016
  ...params
2000
2017
  });
2001
2018
  /**
2002
- * @description # Authorization Requires X-Tenant-Id header.
2019
+ * @description # Authorization Requires X-Tenant-Id header, and the path tenant must equal it. # The path segment Named `{id}` because `DELETE` and `PUT` on the same path address ONE RULE by term id (#231), and one segment cannot carry two names. Here it is the tenant — and a redundant one, since any value but the authenticated principal is refused.
2003
2020
  *
2004
2021
  * @tags inference
2005
2022
  * @name GetRules
2006
2023
  * @summary Get all rules (clauses with antecedents) for a tenant
2007
- * @request GET:/api/v1/inference/rules/{tenant_id}
2024
+ * @request GET:/api/v1/inference/rules/{id}
2008
2025
  * @secure
2009
2026
  */
2010
- getRules = (tenantId, params = {}) => this.http.request({
2011
- path: `/api/v1/inference/rules/${tenantId}`,
2027
+ getRules = (id, params = {}) => this.http.request({
2028
+ path: `/api/v1/inference/rules/${id}`,
2012
2029
  method: "GET",
2013
2030
  secure: true,
2014
2031
  format: "json",
@@ -2066,6 +2083,24 @@ var Inference = class {
2066
2083
  format: "json",
2067
2084
  ...params
2068
2085
  });
2086
+ /**
2087
+ * @description # An edit addresses ONE clause "Edit the rule for X" is ambiguous, because the authoring UI's "add clause" writes a *second* rule with the same conclusion, OR-unioned with the first. The path names a single rule term — one disjunct — so a client cannot silently edit the wrong one. # The old rule is withdrawn, not amended Everything `DELETE` does happens, always with the retract disposition: an edit that leaves the pre-edit clause's conclusions standing is exactly the defect this route exists to fix. The replacement is created through the same code `POST /api/v1/inference/rules` runs, so creation's guards — #227's guard canonicalisation, #219's range restriction, #217's certainty distinction — hold for an edit too, and a rejected replacement leaves the rule base untouched because the build runs BEFORE the clause is de-indexed. The response carries `previous_rule_id` alongside the new rule: a rule's id is its conclusion term id, so an edit changes it by construction. When the replacement is content-addressed to the same id (identical conclusion under `OSFKB_RULE_STABLE_IDS=1`), the two are equal and the edit was applied in place — the outgoing clause's now-unused antecedents are still collected and deleted. # Authorization Identical to `DELETE`: the delete guard on the outgoing rule, `If-Match` against its conclusion, and audit capture.
2088
+ *
2089
+ * @tags inference
2090
+ * @name ReplaceRule
2091
+ * @summary Replace a rule.
2092
+ * @request PUT:/api/v1/inference/rules/{id}
2093
+ * @secure
2094
+ */
2095
+ replaceRule = (id, data, params = {}) => this.http.request({
2096
+ path: `/api/v1/inference/rules/${id}`,
2097
+ method: "PUT",
2098
+ body: data,
2099
+ secure: true,
2100
+ type: "application/json",
2101
+ format: "json",
2102
+ ...params
2103
+ });
2069
2104
  /**
2070
2105
  * @description In OSF/LIFE terms, the orchestrator pushes the conclusion gate and each antecedent gate toward the dual-weighted satisfaction objective `1 − ( w_D · K_D + w_K · K_K )` (paper eq. 4). Each call performs exactly one epoch over the supplied batch — the response carries the per-epoch metrics for that single epoch (multi-epoch aggregation is the caller's responsibility). # Authorization Requires `X-Tenant-Id` header.
2071
2106
  *
@@ -14306,6 +14341,35 @@ function GetRulesResponseFromApiToFront(dto) {
14306
14341
  rules: dto.rules.map(RuleEntryDtoFromApiToFront)
14307
14342
  };
14308
14343
  }
14344
+ function RuleWithdrawalReportFromApiToFront(dto) {
14345
+ return {
14346
+ ruleId: dto.rule_id,
14347
+ termsDeleted: dto.terms_deleted,
14348
+ termsRetainedShared: dto.terms_retained_shared,
14349
+ derivationsRemoved: dto.derivations_removed,
14350
+ derivationsWeakened: dto.derivations_weakened,
14351
+ derivationsTruncated: dto.derivations_truncated,
14352
+ consequencesInvalidated: dto.consequences_invalidated,
14353
+ queuedEventsCancelled: dto.queued_events_cancelled
14354
+ };
14355
+ }
14356
+ function RuleCertificationDeltaFromApiToFront(dto) {
14357
+ return {
14358
+ terminatedBefore: dto.terminated_before,
14359
+ terminatesAfter: dto.terminates_after,
14360
+ orderIndependentBefore: dto.order_independent_before,
14361
+ orderIndependentAfter: dto.order_independent_after,
14362
+ regressed: dto.regressed
14363
+ };
14364
+ }
14365
+ function ReplaceRuleResponseFromApiToFront(dto) {
14366
+ return {
14367
+ previousRuleId: dto.previous_rule_id,
14368
+ term: PsiTermDtoFromApiToFront(dto.term),
14369
+ withdrawal: RuleWithdrawalReportFromApiToFront(dto.withdrawal),
14370
+ certification: RuleCertificationDeltaFromApiToFront(dto.certification)
14371
+ };
14372
+ }
14309
14373
  function MetaSortsResponseFromApiToFront(dto) {
14310
14374
  return {
14311
14375
  absConstraint: dto.abs_constraint,
@@ -14793,6 +14857,89 @@ var InferenceClient = class {
14793
14857
  const response = await this.api.getRules(this.tenantId);
14794
14858
  return GetRulesResponseFromApiToFront(response.data);
14795
14859
  }
14860
+ /**
14861
+ * Withdraw one rule from the knowledge base.
14862
+ *
14863
+ * @param ruleId - Term id of the rule (its conclusion), as returned by
14864
+ * {@link InferenceClient.addRule} or {@link InferenceClient.getRules}.
14865
+ * @param options - `derivations` decides what happens to the conclusions the
14866
+ * rule derived. Defaults to `'refuse'`.
14867
+ * @returns What the withdrawal removed, tier by tier.
14868
+ * @throws {ApiError} 400 if the id names a fact rather than a rule, or if the
14869
+ * rule still supports derivations under the default `'refuse'`; 403 for a
14870
+ * system, plugin-owned or bootstrap rule; 404 if no such rule exists.
14871
+ *
14872
+ * @remarks
14873
+ * A rule is not a row. Withdrawing one deletes its conclusion AND the
14874
+ * antecedent pattern, guard and variable terms it exclusively owns — a
14875
+ * conclusion-only delete would leave those patterns readable as ordinary
14876
+ * facts — while keeping every term the rest of the knowledge base still
14877
+ * holds.
14878
+ *
14879
+ * `'refuse'` (the default) refuses while the rule still proves materialized
14880
+ * conclusions and says how many; `'retract'` withdraws them with it. A delete
14881
+ * that silently drops derivations is as wrong as one that silently keeps
14882
+ * them, so neither is the unnamed default.
14883
+ *
14884
+ * @example
14885
+ * ```typescript
14886
+ * const report = await client.inference.deleteRule(ruleId, { derivations: 'retract' });
14887
+ * console.log(report.termsDeleted, report.derivationsRemoved);
14888
+ * ```
14889
+ */
14890
+ async deleteRule(ruleId, options) {
14891
+ const response = await this.api.deleteRule(
14892
+ ruleId,
14893
+ options?.derivations === void 0 ? void 0 : { derivations: options.derivations }
14894
+ );
14895
+ return RuleWithdrawalReportFromApiToFront(response.data);
14896
+ }
14897
+ /**
14898
+ * Replace one rule with a new one.
14899
+ *
14900
+ * @param ruleId - Term id of the rule (its conclusion) to replace.
14901
+ * @param request - The replacement rule, in the same shape
14902
+ * {@link InferenceClient.addRule} takes.
14903
+ * @returns The replacement, the id it replaced, what the withdrawal removed,
14904
+ * and how the rule base's guarantees moved.
14905
+ * @throws {ApiError} 422 if the replacement is rejected by the authoring
14906
+ * guards — in which case the original rule is left live; 400/403/404 as for
14907
+ * {@link InferenceClient.deleteRule}.
14908
+ *
14909
+ * @remarks
14910
+ * A rule's id IS its conclusion term id, so an edit changes it by
14911
+ * construction. The response carries `previousRuleId` alongside the new
14912
+ * rule; a client holding the old id must adopt the new one.
14913
+ *
14914
+ * The path names ONE rule term — one disjunct. Two rules with the same
14915
+ * conclusion are OR-unioned, so "edit the rule for X" is ambiguous and this
14916
+ * addresses a single clause.
14917
+ *
14918
+ * @example
14919
+ * ```typescript
14920
+ * const result = await client.inference.replaceRule(ruleId, {
14921
+ * term: psi('retiree', { name: Var('N') }),
14922
+ * antecedents: [psi('person', { name: Var('N') })],
14923
+ * });
14924
+ * console.log(result.previousRuleId, '->', result.term.termId);
14925
+ * if (result.certification.regressed) {
14926
+ * console.warn('the edit weakened the rule base guarantees');
14927
+ * }
14928
+ * ```
14929
+ */
14930
+ async replaceRule(ruleId, request) {
14931
+ const wireRequest = {
14932
+ term: convertTermArg(request.term),
14933
+ antecedents: request.antecedents?.map(convertTermArg),
14934
+ certainty: request.certainty,
14935
+ aggregator: request.aggregator
14936
+ };
14937
+ const response = await this.api.replaceRule(
14938
+ ruleId,
14939
+ AddRuleRequestFromFrontToApi(wireRequest)
14940
+ );
14941
+ return ReplaceRuleResponseFromApiToFront(response.data);
14942
+ }
14796
14943
  /**
14797
14944
  * Query for matching data by searching rules and facts backwards from a goal pattern.
14798
14945
  *