@kortexya/reasoninglayer 3.1.0 → 3.2.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 +86 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +285 -27
- package/dist/index.d.ts +285 -27
- package/dist/index.js +86 -16
- 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 = "3.
|
|
8
|
+
var SDK_VERSION = "3.2.0";
|
|
9
9
|
function resolveConfig(config) {
|
|
10
10
|
if (!config.baseUrl) {
|
|
11
11
|
throw new Error("ClientConfig.baseUrl is required");
|
|
@@ -1308,7 +1308,7 @@ var Sorts = class {
|
|
|
1308
1308
|
...params
|
|
1309
1309
|
});
|
|
1310
1310
|
/**
|
|
1311
|
-
* @description A `Proposed` sort becomes `Active`; a sort only flagged `needs_review` has the flag cleared. Anything else is not awaiting approval (409). Requires `Manage` on the sort under a gateway policy
|
|
1311
|
+
* @description A `Proposed` sort becomes `Active`; a sort only flagged `needs_review` has the flag cleared. Anything else is not awaiting approval (409). Requires `Manage` on the sort under a gateway policy. Separation of duties is enforced here, by the engine that holds the proposal record: the acting user (`X-Authenticated-User`) who is the sort's recorded proposer (`SortStatus::Proposed { submitted_by }`) is refused with a coded 403 (`code: "separation_of_duties"`) naming the sort, and the refusal is recorded in the oversight ledger as a `rejected` decision on the action `sort.approve.refused` (#398). The gateway checks the steward permission at the project, where the roles live.
|
|
1312
1312
|
*
|
|
1313
1313
|
* @tags sorts
|
|
1314
1314
|
* @name ApproveSort
|
|
@@ -1461,7 +1461,7 @@ var Sorts = class {
|
|
|
1461
1461
|
...params
|
|
1462
1462
|
});
|
|
1463
1463
|
/**
|
|
1464
|
-
* @description Formal Concept Analysis over sort × feature declaration, each declaration taken whole (name, range or type, constraint, requiredness, bound): every set of at least `min_sorts` sorts sharing at least two identical declarations is a candidate mixin. Deterministic; never writes. Accepting a proposal is creating the mixin (as a `proposed` sort) and re-parenting the members — the caller's decision.
|
|
1464
|
+
* @description Formal Concept Analysis over sort × feature declaration, each declaration taken whole (name, range or type, constraint, requiredness, bound): every set of at least `min_sorts` sorts sharing at least two identical declarations is a candidate mixin. Deterministic; never writes. Accepting a proposal is creating the mixin (as a `proposed` sort) and re-parenting the members — the caller's decision: `POST /api/v1/scenarios/materialize` with the mixin and each member naming it as a parent does both, the moves going through the governed door of `POST /api/v1/sorts/{id}/parents`. A declaration a sort restates identically to an ancestor's is factored already and is never proposed again.
|
|
1465
1465
|
*
|
|
1466
1466
|
* @tags sorts
|
|
1467
1467
|
* @name FactorSortShapes
|
|
@@ -8842,7 +8842,7 @@ var Scenarios = class {
|
|
|
8842
8842
|
...params
|
|
8843
8843
|
});
|
|
8844
8844
|
/**
|
|
8845
|
-
* @description Materializes an already-generated GeneratedScenario verbatim (no LLM call): sorts, belief instances, rules, goal, and the ontology-declared engine pipeline. Used by the studio's build wizard to persist exactly what was reviewed so it is immediately queryable in chat.
|
|
8845
|
+
* @description Materializes an already-generated GeneratedScenario verbatim (no LLM call): sorts, belief instances, rules, goal, and the ontology-declared engine pipeline. Used by the studio's build wizard to persist exactly what was reviewed so it is immediately queryable in chat. An existing sort is reused and moved under any parent the scenario newly names for it, through the governed move of POST /sorts/{id}/parents; a refused move is reported in `warnings` and leaves the sort where it was.
|
|
8846
8846
|
*
|
|
8847
8847
|
* @tags scenarios
|
|
8848
8848
|
* @name MaterializeScenario
|
|
@@ -9447,7 +9447,7 @@ var Synthetic = class {
|
|
|
9447
9447
|
...params
|
|
9448
9448
|
});
|
|
9449
9449
|
/**
|
|
9450
|
-
* @description Uses principled strategies to create training examples that are negative (invalid) for specific, documented reasons: sort incompatibility, feature perturbation, cross-sort confusion, missing required features, and feature type mismatch. # Authorization Requires X-Tenant-Id header for tenant-scoped operations.
|
|
9450
|
+
* @description Uses principled strategies to create training examples that are negative (invalid) for specific, documented reasons: a violation of each declared feature constraint (named in `violated_constraint`), sort incompatibility, feature perturbation, cross-sort confusion, missing required features, and feature type mismatch. Proposed sorts are included — negatives exist to test a model before it is approved; deprecated sorts are not. # Authorization Requires X-Tenant-Id header for tenant-scoped operations.
|
|
9451
9451
|
*
|
|
9452
9452
|
* @tags synthetic
|
|
9453
9453
|
* @name GenerateNegatives
|
|
@@ -16232,8 +16232,10 @@ var SortsClient = class {
|
|
|
16232
16232
|
* @returns The approved sort, and how much suspended work its declaration
|
|
16233
16233
|
* released (`wokenResiduations`).
|
|
16234
16234
|
* @throws {ForbiddenError} 403 when the caller holds no Manage grant on the
|
|
16235
|
-
* sort —
|
|
16236
|
-
*
|
|
16235
|
+
* sort, or — with `code: "separation_of_duties"` in the body (see
|
|
16236
|
+
* `SortApprovalErrorCode`; read it with `errorBodyCode`) — when the
|
|
16237
|
+
* acting user (`authenticatedUser`) is the sort's recorded proposer.
|
|
16238
|
+
* Another steward can approve it.
|
|
16237
16239
|
* @throws {NotFoundError} 404 when the sort does not exist.
|
|
16238
16240
|
* @throws {ApiError} 409 when the sort is not awaiting approval.
|
|
16239
16241
|
*
|
|
@@ -16242,11 +16244,21 @@ var SortsClient = class {
|
|
|
16242
16244
|
* authenticated user as reviewer. This replaced `approveProposed` on
|
|
16243
16245
|
* {@link SortsClient.patchSort}, which the engine now refuses.
|
|
16244
16246
|
*
|
|
16247
|
+
* Separation of duties is enforced by the engine: the proposer's own
|
|
16248
|
+
* approval is refused with the coded 403 and recorded in the oversight
|
|
16249
|
+
* ledger as a `rejected` decision on `sort.approve.refused`.
|
|
16250
|
+
*
|
|
16245
16251
|
* @example
|
|
16246
16252
|
* ```typescript
|
|
16247
|
-
*
|
|
16248
|
-
*
|
|
16249
|
-
*
|
|
16253
|
+
* try {
|
|
16254
|
+
* const { sort, wokenResiduations } = await client.sorts.approveSort(sortId, {
|
|
16255
|
+
* reason: 'Matches the order lifecycle use case',
|
|
16256
|
+
* });
|
|
16257
|
+
* } catch (error) {
|
|
16258
|
+
* if (errorBodyCode(error) === 'separation_of_duties') {
|
|
16259
|
+
* // The acting user proposed this sort: ask another steward to approve it.
|
|
16260
|
+
* }
|
|
16261
|
+
* }
|
|
16250
16262
|
* ```
|
|
16251
16263
|
*/
|
|
16252
16264
|
async approveSort(sortId, request = {}, requestOptions) {
|
|
@@ -18884,7 +18896,8 @@ function RuleTermDraftDtoFromApiToFront(dto) {
|
|
|
18884
18896
|
// The engine types each value as a scalar (`RuleDraftFeatureValueDto`) and
|
|
18885
18897
|
// refuses a draft carrying anything else, so the map passes through; only
|
|
18886
18898
|
// the generated `Partial` is narrowed to a total record.
|
|
18887
|
-
features: definedRecordOrNullish(dto.features)
|
|
18899
|
+
features: definedRecordOrNullish(dto.features),
|
|
18900
|
+
...dto.negated === true ? { negated: true } : {}
|
|
18888
18901
|
};
|
|
18889
18902
|
}
|
|
18890
18903
|
function RuleDraftDtoFromApiToFront(dto) {
|
|
@@ -18959,9 +18972,16 @@ var InferenceClient = class {
|
|
|
18959
18972
|
* engine-side head aggregator (see {@link RuleAggregatorDto}).
|
|
18960
18973
|
* @returns The created rule wrapped in an AddRuleResponse.
|
|
18961
18974
|
* @throws {ApiError} If the rule is rejected or the request fails — 422 when
|
|
18962
|
-
* it is unusable as written
|
|
18963
|
-
*
|
|
18964
|
-
*
|
|
18975
|
+
* it is unusable as written: a head or body antecedent naming a sort or
|
|
18976
|
+
* term that does not exist (the message names it and its position — `the
|
|
18977
|
+
* head (conclusion)` or `body antecedent N`), a guard bound the declared
|
|
18978
|
+
* type cannot compare, a binder on the conclusion, or a rule that closes a
|
|
18979
|
+
* NEW cycle through negation (no stratification would order the program; a
|
|
18980
|
+
* cycle the program already had is not blamed on it). The refusal is a
|
|
18981
|
+
* plain {@link ApiError} with `status` 422 — not a `BadRequestError`
|
|
18982
|
+
* (earlier engines answered an unknown head sort with 400), and not a
|
|
18983
|
+
* `NamedConstraintViolationError`, which is reserved for a feature
|
|
18984
|
+
* constraint's refusal.
|
|
18965
18985
|
*
|
|
18966
18986
|
* @remarks
|
|
18967
18987
|
* **Serialization format**: untagged `TermInputDto` / `FeatureInputValueDto`.
|
|
@@ -19611,7 +19631,10 @@ var InferenceClient = class {
|
|
|
19611
19631
|
* `{"type": "String", "value": "..."}` envelope. The engine refuses a model answer that
|
|
19612
19632
|
* carries one, re-prompts, and answers 422 when the model keeps producing it. Each
|
|
19613
19633
|
* {@link RuleTermDraftDto} maps directly onto a `TermInputDto` inline-by-sort-name
|
|
19614
|
-
* term, so an approved draft can be handed straight to {@link addRule}
|
|
19634
|
+
* term, so an approved draft can be handed straight to {@link addRule} — except an
|
|
19635
|
+
* antecedent with `negated: true`, which must be wrapped in the `negation` carrier
|
|
19636
|
+
* (`not(psi(sortName, features))`); sent bare, it would assert the positive
|
|
19637
|
+
* condition.
|
|
19615
19638
|
*
|
|
19616
19639
|
* Drafting is multi-turn: if `status` is `'needs_clarification'`, answer each question
|
|
19617
19640
|
* and call again with the echoed `sessionId` and an `answers` map keyed by the question's
|
|
@@ -19854,6 +19877,7 @@ function NlQueryRequestFromFrontToApi(model) {
|
|
|
19854
19877
|
mode: model.mode,
|
|
19855
19878
|
tenant_id: model.tenantId,
|
|
19856
19879
|
conversation_history: model.conversationHistory ?? void 0,
|
|
19880
|
+
focus_sorts: model.focusSorts ?? void 0,
|
|
19857
19881
|
session_id: model.sessionId ?? void 0,
|
|
19858
19882
|
exclude_domains: model.excludeDomains ?? void 0,
|
|
19859
19883
|
focus_proposal: model.focusProposal ?? void 0,
|
|
@@ -20159,6 +20183,10 @@ var QueryClient = class {
|
|
|
20159
20183
|
* @remarks
|
|
20160
20184
|
* Plain JSON, no tagged/untagged value serialization.
|
|
20161
20185
|
*
|
|
20186
|
+
* In llm mode, `focusSorts` names the sorts the question is about: each is
|
|
20187
|
+
* always in the schema the translator sees, even a sort built a moment ago
|
|
20188
|
+
* with no records, which the record-count ranking would otherwise cut.
|
|
20189
|
+
*
|
|
20162
20190
|
* TRIZ mode (`mode: "triz"`) is multi-turn:
|
|
20163
20191
|
* 1. A request with no `sessionId` opens a session, structures the problem
|
|
20164
20192
|
* (reading any `images` first) and solves it. The response names the
|
|
@@ -31376,6 +31404,14 @@ var ScenariosClient = class {
|
|
|
31376
31404
|
* scenario's use cases and competency questions are recorded as `proposed`
|
|
31377
31405
|
* competency questions.
|
|
31378
31406
|
*
|
|
31407
|
+
* A sort (or fluent) may carry `provenance` — see {@link ScenarioSortProvenance} —
|
|
31408
|
+
* recorded as its origin; without it the sort is credited to the caller.
|
|
31409
|
+
*
|
|
31410
|
+
* An existing sort is reused, and moved under any parent the scenario newly names
|
|
31411
|
+
* for it through the same governed move as `SortsClient.editSortParents`. A move the
|
|
31412
|
+
* engine refuses leaves the sort where it was and is reported in `warnings`, not
|
|
31413
|
+
* as an error — read `warnings` after every call.
|
|
31414
|
+
*
|
|
31379
31415
|
* @example
|
|
31380
31416
|
* ```typescript
|
|
31381
31417
|
* const result = await client.scenarios.materializeScenario({ scenario: generated });
|
|
@@ -34384,6 +34420,14 @@ function CheckDiversityResponseFromApiToFront(dto) {
|
|
|
34384
34420
|
termsCompared: dto.terms_compared
|
|
34385
34421
|
};
|
|
34386
34422
|
}
|
|
34423
|
+
function ViolatedConstraintDtoFromApiToFront(dto) {
|
|
34424
|
+
return {
|
|
34425
|
+
feature: dto.feature,
|
|
34426
|
+
kind: dto.kind,
|
|
34427
|
+
...dto.constraint_name != null ? { constraintName: dto.constraint_name } : {},
|
|
34428
|
+
...dto.constraint_message != null ? { constraintMessage: dto.constraint_message } : {}
|
|
34429
|
+
};
|
|
34430
|
+
}
|
|
34387
34431
|
function NegativeExampleDtoFromApiToFront(dto) {
|
|
34388
34432
|
return {
|
|
34389
34433
|
explanation: dto.explanation,
|
|
@@ -34393,11 +34437,13 @@ function NegativeExampleDtoFromApiToFront(dto) {
|
|
|
34393
34437
|
termId: dto.term_id,
|
|
34394
34438
|
...dto.sort != null ? { sort: dto.sort } : {},
|
|
34395
34439
|
...dto.features != null ? { features: Object.fromEntries(Object.entries(dto.features)) } : {},
|
|
34396
|
-
...dto.world_mode != null ? { worldMode: dto.world_mode } : {}
|
|
34440
|
+
...dto.world_mode != null ? { worldMode: dto.world_mode } : {},
|
|
34441
|
+
...dto.violated_constraint != null ? { violatedConstraint: ViolatedConstraintDtoFromApiToFront(dto.violated_constraint) } : {}
|
|
34397
34442
|
};
|
|
34398
34443
|
}
|
|
34399
34444
|
function GenerateNegativesRequestFromFrontToApi(model) {
|
|
34400
34445
|
return {
|
|
34446
|
+
enable_constraint_violation: model.enableConstraintViolation,
|
|
34401
34447
|
enable_cross_sort_confusion: model.enableCrossSortConfusion,
|
|
34402
34448
|
enable_feature_perturbation: model.enableFeaturePerturbation,
|
|
34403
34449
|
enable_sort_incompatibility: model.enableSortIncompatibility,
|
|
@@ -34674,6 +34720,30 @@ var SyntheticClient = class {
|
|
|
34674
34720
|
* @param request - Negative generation parameters including target sorts and strategy flags.
|
|
34675
34721
|
* @returns Generated negative examples with provenance.
|
|
34676
34722
|
* @throws {ApiError} If the request fails.
|
|
34723
|
+
*
|
|
34724
|
+
* @remarks
|
|
34725
|
+
* Each negative is invalid for a documented reason, named by its
|
|
34726
|
+
* `strategy`: a violation of each declared feature constraint
|
|
34727
|
+
* (`ConstraintViolation`, one negative per enum / range / pattern /
|
|
34728
|
+
* maximum-cardinality constraint, with the constraint in
|
|
34729
|
+
* `violatedConstraint`), sort incompatibility, feature perturbation,
|
|
34730
|
+
* cross-sort confusion, a missing required feature, or a feature type
|
|
34731
|
+
* mismatch. Set `enableConstraintViolation: false` to skip the first.
|
|
34732
|
+
*
|
|
34733
|
+
* Proposed sorts are included — negatives exist to test a model before it
|
|
34734
|
+
* is approved; deprecated sorts are not.
|
|
34735
|
+
*
|
|
34736
|
+
* @example
|
|
34737
|
+
* ```typescript
|
|
34738
|
+
* const { negatives } = await client.synthetic.generateNegatives({
|
|
34739
|
+
* targetSorts: [pizzaSortId],
|
|
34740
|
+
* });
|
|
34741
|
+
* for (const n of negatives) {
|
|
34742
|
+
* if (n.violatedConstraint) {
|
|
34743
|
+
* console.log(n.violatedConstraint.feature, n.violatedConstraint.constraintMessage);
|
|
34744
|
+
* }
|
|
34745
|
+
* }
|
|
34746
|
+
* ```
|
|
34677
34747
|
*/
|
|
34678
34748
|
async generateNegatives(request, requestOptions) {
|
|
34679
34749
|
const response = await this.api.generateNegatives(
|