@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 +152 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +390 -32
- package/dist/index.d.ts +390 -32
- package/dist/index.js +152 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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.
|
|
8
|
+
var SDK_VERSION = "1.24.0";
|
|
9
9
|
function resolveConfig(config) {
|
|
10
10
|
if (!config.baseUrl) {
|
|
11
11
|
throw new Error("ClientConfig.baseUrl is required");
|
|
@@ -1875,6 +1875,23 @@ var Inference = class {
|
|
|
1875
1875
|
format: "json",
|
|
1876
1876
|
...params
|
|
1877
1877
|
});
|
|
1878
|
+
/**
|
|
1879
|
+
* @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.
|
|
1880
|
+
*
|
|
1881
|
+
* @tags inference
|
|
1882
|
+
* @name DeleteRule
|
|
1883
|
+
* @summary Delete a rule.
|
|
1884
|
+
* @request DELETE:/api/v1/inference/rules/{id}
|
|
1885
|
+
* @secure
|
|
1886
|
+
*/
|
|
1887
|
+
deleteRule = (id, query, params = {}) => this.http.request({
|
|
1888
|
+
path: `/api/v1/inference/rules/${id}`,
|
|
1889
|
+
method: "DELETE",
|
|
1890
|
+
query,
|
|
1891
|
+
secure: true,
|
|
1892
|
+
format: "json",
|
|
1893
|
+
...params
|
|
1894
|
+
});
|
|
1878
1895
|
/**
|
|
1879
1896
|
* @description Never writes to the KB — returns validated drafts for human review.
|
|
1880
1897
|
*
|
|
@@ -1997,16 +2014,16 @@ var Inference = class {
|
|
|
1997
2014
|
...params
|
|
1998
2015
|
});
|
|
1999
2016
|
/**
|
|
2000
|
-
* @description # Authorization Requires X-Tenant-Id header.
|
|
2017
|
+
* @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.
|
|
2001
2018
|
*
|
|
2002
2019
|
* @tags inference
|
|
2003
2020
|
* @name GetRules
|
|
2004
2021
|
* @summary Get all rules (clauses with antecedents) for a tenant
|
|
2005
|
-
* @request GET:/api/v1/inference/rules/{
|
|
2022
|
+
* @request GET:/api/v1/inference/rules/{id}
|
|
2006
2023
|
* @secure
|
|
2007
2024
|
*/
|
|
2008
|
-
getRules = (
|
|
2009
|
-
path: `/api/v1/inference/rules/${
|
|
2025
|
+
getRules = (id, params = {}) => this.http.request({
|
|
2026
|
+
path: `/api/v1/inference/rules/${id}`,
|
|
2010
2027
|
method: "GET",
|
|
2011
2028
|
secure: true,
|
|
2012
2029
|
format: "json",
|
|
@@ -2064,6 +2081,24 @@ var Inference = class {
|
|
|
2064
2081
|
format: "json",
|
|
2065
2082
|
...params
|
|
2066
2083
|
});
|
|
2084
|
+
/**
|
|
2085
|
+
* @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.
|
|
2086
|
+
*
|
|
2087
|
+
* @tags inference
|
|
2088
|
+
* @name ReplaceRule
|
|
2089
|
+
* @summary Replace a rule.
|
|
2090
|
+
* @request PUT:/api/v1/inference/rules/{id}
|
|
2091
|
+
* @secure
|
|
2092
|
+
*/
|
|
2093
|
+
replaceRule = (id, data, params = {}) => this.http.request({
|
|
2094
|
+
path: `/api/v1/inference/rules/${id}`,
|
|
2095
|
+
method: "PUT",
|
|
2096
|
+
body: data,
|
|
2097
|
+
secure: true,
|
|
2098
|
+
type: "application/json",
|
|
2099
|
+
format: "json",
|
|
2100
|
+
...params
|
|
2101
|
+
});
|
|
2067
2102
|
/**
|
|
2068
2103
|
* @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.
|
|
2069
2104
|
*
|
|
@@ -14304,6 +14339,35 @@ function GetRulesResponseFromApiToFront(dto) {
|
|
|
14304
14339
|
rules: dto.rules.map(RuleEntryDtoFromApiToFront)
|
|
14305
14340
|
};
|
|
14306
14341
|
}
|
|
14342
|
+
function RuleWithdrawalReportFromApiToFront(dto) {
|
|
14343
|
+
return {
|
|
14344
|
+
ruleId: dto.rule_id,
|
|
14345
|
+
termsDeleted: dto.terms_deleted,
|
|
14346
|
+
termsRetainedShared: dto.terms_retained_shared,
|
|
14347
|
+
derivationsRemoved: dto.derivations_removed,
|
|
14348
|
+
derivationsWeakened: dto.derivations_weakened,
|
|
14349
|
+
derivationsTruncated: dto.derivations_truncated,
|
|
14350
|
+
consequencesInvalidated: dto.consequences_invalidated,
|
|
14351
|
+
queuedEventsCancelled: dto.queued_events_cancelled
|
|
14352
|
+
};
|
|
14353
|
+
}
|
|
14354
|
+
function RuleCertificationDeltaFromApiToFront(dto) {
|
|
14355
|
+
return {
|
|
14356
|
+
terminatedBefore: dto.terminated_before,
|
|
14357
|
+
terminatesAfter: dto.terminates_after,
|
|
14358
|
+
orderIndependentBefore: dto.order_independent_before,
|
|
14359
|
+
orderIndependentAfter: dto.order_independent_after,
|
|
14360
|
+
regressed: dto.regressed
|
|
14361
|
+
};
|
|
14362
|
+
}
|
|
14363
|
+
function ReplaceRuleResponseFromApiToFront(dto) {
|
|
14364
|
+
return {
|
|
14365
|
+
previousRuleId: dto.previous_rule_id,
|
|
14366
|
+
term: PsiTermDtoFromApiToFront(dto.term),
|
|
14367
|
+
withdrawal: RuleWithdrawalReportFromApiToFront(dto.withdrawal),
|
|
14368
|
+
certification: RuleCertificationDeltaFromApiToFront(dto.certification)
|
|
14369
|
+
};
|
|
14370
|
+
}
|
|
14307
14371
|
function MetaSortsResponseFromApiToFront(dto) {
|
|
14308
14372
|
return {
|
|
14309
14373
|
absConstraint: dto.abs_constraint,
|
|
@@ -14791,6 +14855,89 @@ var InferenceClient = class {
|
|
|
14791
14855
|
const response = await this.api.getRules(this.tenantId);
|
|
14792
14856
|
return GetRulesResponseFromApiToFront(response.data);
|
|
14793
14857
|
}
|
|
14858
|
+
/**
|
|
14859
|
+
* Withdraw one rule from the knowledge base.
|
|
14860
|
+
*
|
|
14861
|
+
* @param ruleId - Term id of the rule (its conclusion), as returned by
|
|
14862
|
+
* {@link InferenceClient.addRule} or {@link InferenceClient.getRules}.
|
|
14863
|
+
* @param options - `derivations` decides what happens to the conclusions the
|
|
14864
|
+
* rule derived. Defaults to `'refuse'`.
|
|
14865
|
+
* @returns What the withdrawal removed, tier by tier.
|
|
14866
|
+
* @throws {ApiError} 400 if the id names a fact rather than a rule, or if the
|
|
14867
|
+
* rule still supports derivations under the default `'refuse'`; 403 for a
|
|
14868
|
+
* system, plugin-owned or bootstrap rule; 404 if no such rule exists.
|
|
14869
|
+
*
|
|
14870
|
+
* @remarks
|
|
14871
|
+
* A rule is not a row. Withdrawing one deletes its conclusion AND the
|
|
14872
|
+
* antecedent pattern, guard and variable terms it exclusively owns — a
|
|
14873
|
+
* conclusion-only delete would leave those patterns readable as ordinary
|
|
14874
|
+
* facts — while keeping every term the rest of the knowledge base still
|
|
14875
|
+
* holds.
|
|
14876
|
+
*
|
|
14877
|
+
* `'refuse'` (the default) refuses while the rule still proves materialized
|
|
14878
|
+
* conclusions and says how many; `'retract'` withdraws them with it. A delete
|
|
14879
|
+
* that silently drops derivations is as wrong as one that silently keeps
|
|
14880
|
+
* them, so neither is the unnamed default.
|
|
14881
|
+
*
|
|
14882
|
+
* @example
|
|
14883
|
+
* ```typescript
|
|
14884
|
+
* const report = await client.inference.deleteRule(ruleId, { derivations: 'retract' });
|
|
14885
|
+
* console.log(report.termsDeleted, report.derivationsRemoved);
|
|
14886
|
+
* ```
|
|
14887
|
+
*/
|
|
14888
|
+
async deleteRule(ruleId, options) {
|
|
14889
|
+
const response = await this.api.deleteRule(
|
|
14890
|
+
ruleId,
|
|
14891
|
+
options?.derivations === void 0 ? void 0 : { derivations: options.derivations }
|
|
14892
|
+
);
|
|
14893
|
+
return RuleWithdrawalReportFromApiToFront(response.data);
|
|
14894
|
+
}
|
|
14895
|
+
/**
|
|
14896
|
+
* Replace one rule with a new one.
|
|
14897
|
+
*
|
|
14898
|
+
* @param ruleId - Term id of the rule (its conclusion) to replace.
|
|
14899
|
+
* @param request - The replacement rule, in the same shape
|
|
14900
|
+
* {@link InferenceClient.addRule} takes.
|
|
14901
|
+
* @returns The replacement, the id it replaced, what the withdrawal removed,
|
|
14902
|
+
* and how the rule base's guarantees moved.
|
|
14903
|
+
* @throws {ApiError} 422 if the replacement is rejected by the authoring
|
|
14904
|
+
* guards — in which case the original rule is left live; 400/403/404 as for
|
|
14905
|
+
* {@link InferenceClient.deleteRule}.
|
|
14906
|
+
*
|
|
14907
|
+
* @remarks
|
|
14908
|
+
* A rule's id IS its conclusion term id, so an edit changes it by
|
|
14909
|
+
* construction. The response carries `previousRuleId` alongside the new
|
|
14910
|
+
* rule; a client holding the old id must adopt the new one.
|
|
14911
|
+
*
|
|
14912
|
+
* The path names ONE rule term — one disjunct. Two rules with the same
|
|
14913
|
+
* conclusion are OR-unioned, so "edit the rule for X" is ambiguous and this
|
|
14914
|
+
* addresses a single clause.
|
|
14915
|
+
*
|
|
14916
|
+
* @example
|
|
14917
|
+
* ```typescript
|
|
14918
|
+
* const result = await client.inference.replaceRule(ruleId, {
|
|
14919
|
+
* term: psi('retiree', { name: Var('N') }),
|
|
14920
|
+
* antecedents: [psi('person', { name: Var('N') })],
|
|
14921
|
+
* });
|
|
14922
|
+
* console.log(result.previousRuleId, '->', result.term.termId);
|
|
14923
|
+
* if (result.certification.regressed) {
|
|
14924
|
+
* console.warn('the edit weakened the rule base guarantees');
|
|
14925
|
+
* }
|
|
14926
|
+
* ```
|
|
14927
|
+
*/
|
|
14928
|
+
async replaceRule(ruleId, request) {
|
|
14929
|
+
const wireRequest = {
|
|
14930
|
+
term: convertTermArg(request.term),
|
|
14931
|
+
antecedents: request.antecedents?.map(convertTermArg),
|
|
14932
|
+
certainty: request.certainty,
|
|
14933
|
+
aggregator: request.aggregator
|
|
14934
|
+
};
|
|
14935
|
+
const response = await this.api.replaceRule(
|
|
14936
|
+
ruleId,
|
|
14937
|
+
AddRuleRequestFromFrontToApi(wireRequest)
|
|
14938
|
+
);
|
|
14939
|
+
return ReplaceRuleResponseFromApiToFront(response.data);
|
|
14940
|
+
}
|
|
14794
14941
|
/**
|
|
14795
14942
|
* Query for matching data by searching rules and facts backwards from a goal pattern.
|
|
14796
14943
|
*
|