@kortexya/reasoninglayer 4.0.0 → 4.1.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.d.cts CHANGED
@@ -231,7 +231,7 @@ type JsonValue$1 = string | number | boolean | null | JsonValue$1[] | object;
231
231
  * This is the single source of truth for the version constant.
232
232
  * The `scripts/release.sh` script updates this value alongside `package.json`.
233
233
  */
234
- declare const SDK_VERSION = "4.0.0";
234
+ declare const SDK_VERSION = "4.1.0";
235
235
  /**
236
236
  * Authentication mode for the SDK.
237
237
  *
@@ -22103,16 +22103,24 @@ interface MaterializeScenarioRequest$1 {
22103
22103
  * refused with 409 (#470).
22104
22104
  */
22105
22105
  prefixes?: Partial<Record<string, string>>;
22106
- /** A GeneratedScenario: the `scenario` payload of POST /api/v1/ontology/generate, or a schema-only scenario built from an imported vocabulary. `sorts`, `beliefs` and `rules` are required (each may be empty). `goal` is optional: a scenario without one materializes no agent_goal term. Every other collection defaults to empty. Keys not listed here are ignored. */
22106
+ /** A GeneratedScenario: the `scenario` payload of POST /api/v1/ontology/generate, or a schema-only scenario built from an imported vocabulary. No key is required: every collection defaults to empty, so a vocabulary import sends `sorts` alone. `goal` is optional: a scenario without one materializes no agent_goal term. Keys not listed here are ignored. */
22107
22107
  scenario: {
22108
- /** Belief instances (typed facts) to assert. */
22109
- beliefs: object[];
22108
+ /** OWL 2 class axioms, each `{kind, classes?, class?, property?, n?, filler?}`: `disjoint_classes`, `min_cardinality`, `max_cardinality`, `exact_cardinality` or `all_values_from`. Written as the disjointness rule, feature bound or typed feature the engine enforces; an unknown kind is skipped with a warning. Defaults to empty. */
22109
+ axioms?: object[];
22110
+ /** Belief instances (typed facts) to assert. Defaults to empty. */
22111
+ beliefs?: object[];
22112
+ /** Competency questions, each `{question, use_case?, osfql?, sorts?}`, recorded as `proposed` competency questions. Defaults to empty. */
22113
+ competency_questions?: object[];
22114
+ /** Computed features, each `{sort, feature, function, arguments?, depends_on?, description?}`, declared as feature equations. Defaults to empty. */
22115
+ computed_features?: object[];
22110
22116
  /** Generic constraints, each `{sort, features}`. Defaults to empty. A feature reads the rule feature encoding: a bare "?X" is a variable, as are {"name": "?X"} and {"_var": "?X"}, and one name is one variable across all of `guardConstraints` and `constraints`; a literal that starts with `?` is {"type": "String", "value": "?x"}. A constraint whose feature does not decode is not written and is named in `warnings`. */
22111
22117
  constraints?: object[];
22112
22118
  /** Curriculum stages. Defaults to empty. */
22113
22119
  curriculum_stages?: object[];
22114
22120
  /** Tool registrations. Defaults to empty. */
22115
22121
  discovered_tools?: object[];
22122
+ /** Fluents, each `{name, of_sort, value_values?, event_sort, proposed?, provenance?}`: a fluent sort and its event sort, recorded as append-only state terms. Defaults to empty. */
22123
+ fluents?: object[];
22116
22124
  /** The agent's goal: `{sort, features?, priority?}`. Optional; omit it for a scenario with no agent. `features` reads the rule feature encoding: a bare "?X" is a variable; a literal that starts with `?` is {"type": "String", "value": "?x"}. A feature that does not decode refuses the scenario. */
22117
22125
  goal?: object;
22118
22126
  /** Concept groundings. Defaults to empty. */
@@ -22121,8 +22129,8 @@ interface MaterializeScenarioRequest$1 {
22121
22129
  guardConstraints?: object[];
22122
22130
  /** Engine pipeline stages. Defaults to empty. */
22123
22131
  pipelineStages?: object[];
22124
- /** Inference rules. Each rule is `{head: {sort, features}, antecedents: [{sort, features, negated?, binding?}], certainty?}`, authored through the rule door of POST /api/v1/inference/rules with its feature encoding and its checks. A bare string that starts with `?` ("?X") is a variable shared across the rule, as are {"name": "?X"} and {"_var": "?X"}; a literal that starts with `?` is written {"type": "String", "value": "?x"}. `negated: true` on an antecedent is negation as failure. A rule the door refuses is not written and is named in `warnings`: a conclusion variable that no antecedent binds, no antecedent, a new cycle through negation, or a feature value the door cannot read. A sort a rule names that `sorts` does not declare is created under `thing` before the rules are authored, so an unknown sort is not refused here (only PATCH /api/v1/scenarios/{id} `add_rules`, which is not normalized, refuses one). */
22125
- rules: {
22132
+ /** Inference rules. Defaults to empty. Each rule is `{head: {sort, features}, antecedents: [{sort, features, negated?, binding?}], certainty?}`, authored through the rule door of POST /api/v1/inference/rules with its feature encoding and its checks. A bare string that starts with `?` ("?X") is a variable shared across the rule, as are {"name": "?X"} and {"_var": "?X"}; a literal that starts with `?` is written {"type": "String", "value": "?x"}. `negated: true` on an antecedent is negation as failure. A rule the door refuses is not written and is named in `warnings`: a conclusion variable that no antecedent binds, no antecedent, a new cycle through negation, or a feature value the door cannot read. A sort a rule names that `sorts` does not declare is created under `thing` before the rules are authored, so an unknown sort is not refused here (only PATCH /api/v1/scenarios/{id} `add_rules`, which is not normalized, refuses one). */
22133
+ rules?: {
22126
22134
  /** The conditions. Defaults to empty. */
22127
22135
  antecedents?: {
22128
22136
  /** The antecedent's own identity, named ("?P", with or without the `?`) — OSFQL's `?P: pizza(...)`. On a positive antecedent every "?P" elsewhere in the rule references the term it matches; on a negated one it names the term the negation is about, which a positive antecedent must bind. Meaningless on a head. */
@@ -22148,12 +22156,16 @@ interface MaterializeScenarioRequest$1 {
22148
22156
  sort: string;
22149
22157
  };
22150
22158
  }[];
22159
+ /** The ontology's scope. Accepted and not written by this route: PUT /api/v1/ontology/scope stores a scope. */
22160
+ scope?: object;
22151
22161
  /** LLM sensor points. Defaults to empty. */
22152
22162
  sensorPoints?: object[];
22153
- /** Sorts to create or reuse. A sort may carry `provenance`, recorded as its origin: `{"kind": "model", "model"?: …}` (a model proposal, `LlmExtracted`) or `{"kind": "imported", "ontology": …, "original_id": …}` (`Imported`). Without it the sort is `Manual`, credited to the caller; `System` cannot be claimed. */
22154
- sorts: object[];
22163
+ /** Sorts to create or reuse. A sort may carry `provenance`, recorded as its origin: `{"kind": "model", "model"?: …}` (a model proposal, `LlmExtracted`) or `{"kind": "imported", "ontology": …, "original_id": …}` (`Imported`). Without it the sort is `Manual`, credited to the caller; `System` cannot be claimed. Defaults to empty. */
22164
+ sorts?: object[];
22155
22165
  /** Allen temporal constraints. Defaults to empty. */
22156
22166
  temporalConstraints?: object[];
22167
+ /** Use cases, each `{id, title?, description?}`, recorded as `proposed` competency questions of kind `use_case`. Defaults to empty. */
22168
+ use_cases?: object[];
22157
22169
  /** Webhook actions. Defaults to empty. */
22158
22170
  webhookActions?: object[];
22159
22171
  };
@@ -30369,6 +30381,20 @@ interface RuleEntryDto$1 {
30369
30381
  * @format double
30370
30382
  */
30371
30383
  certainty?: number | null;
30384
+ /**
30385
+ * The rule's content tag (`sha256-<hex>`): send it as `If-Match` on
30386
+ * `DELETE`/`PUT /api/v1/inference/rules/{id}` (#473).
30387
+ *
30388
+ * The same tag those routes judge the precondition against, read from
30389
+ * the same store. `GET /api/v1/terms/{id}` does not serve it, because a
30390
+ * rule's conclusion is the rule's own term and not a fact (#456), so this
30391
+ * listing is the read that publishes it.
30392
+ *
30393
+ * Present on every [`Self::withdrawable`] rule whose conclusion the
30394
+ * tenant's term service holds; absent on a rule no route withdraws,
30395
+ * which has no mutation to precondition.
30396
+ */
30397
+ etag?: string | null;
30372
30398
  /** The head (consequent) of the rule. */
30373
30399
  head: PsiTermDto$1;
30374
30400
  /**
@@ -41803,10 +41829,10 @@ interface TermResponse {
41803
41829
  * - a term answered straight from durable storage because the live store
41804
41830
  * did not hold it.
41805
41831
  *
41806
- * A rule's id is its conclusion TERM's id, and `getTerm(ruleId).etag` is the
41807
- * tag {@link InferenceClient.deleteRule} and
41808
- * {@link InferenceClient.replaceRule} compare `ifMatch` against — the rule
41809
- * routes themselves send no ETag.
41832
+ * A rule's tag is not read here: `getTerm(ruleId)` answers 404 for a rule.
41833
+ * The rule routes publish it — {@link AddRuleResponse.etag},
41834
+ * {@link ReplaceRuleResponse.etag} and the listing's
41835
+ * {@link RuleEntryDto.etag}.
41810
41836
  *
41811
41837
  * Not part of the response body: other routes that answer a `TermResponse`
41812
41838
  * never set it.
@@ -43291,6 +43317,17 @@ interface AddFactResponse {
43291
43317
  interface AddRuleResponse {
43292
43318
  /** The created rule as a PsiTerm. */
43293
43319
  term: PsiTermDto;
43320
+ /**
43321
+ * The rule's content tag (`sha256-<hex>`), from the `ETag` response header:
43322
+ * pass it as `ifMatch` to {@link InferenceClient.deleteRule} or
43323
+ * {@link InferenceClient.replaceRule}.
43324
+ *
43325
+ * @remarks
43326
+ * Not part of the response body. Absent when the engine sends no header:
43327
+ * the rule is written, but the read that tags the response failed after the
43328
+ * write committed. Read the tag from {@link RuleEntryDto.etag} then.
43329
+ */
43330
+ etag?: string;
43294
43331
  }
43295
43332
  /** One finding of a rule validation. */
43296
43333
  interface RuleIssue {
@@ -43534,6 +43571,17 @@ interface RuleEntryDto {
43534
43571
  body: PsiTermDto[];
43535
43572
  /** Optional certainty/confidence for the rule. */
43536
43573
  certainty?: number | null;
43574
+ /**
43575
+ * The rule's content tag (`sha256-<hex>`): pass it as `ifMatch` to
43576
+ * {@link InferenceClient.deleteRule} or {@link InferenceClient.replaceRule}.
43577
+ *
43578
+ * @remarks
43579
+ * The same tag those routes judge the precondition against. Present on a
43580
+ * {@link RuleEntryDto.withdrawable} rule; absent on a rule no route
43581
+ * withdraws, which has no mutation to precondition. `getTerm(ruleId)` does
43582
+ * not serve it: a rule's id answers 404 on the term route.
43583
+ */
43584
+ etag?: string;
43537
43585
  /**
43538
43586
  * Where this rule came from, from the reading tenant's point of view.
43539
43587
  *
@@ -43732,6 +43780,17 @@ interface ReplaceRuleResponse {
43732
43780
  previousRuleId: string;
43733
43781
  /** The replacement rule, as created. */
43734
43782
  term: PsiTermDto;
43783
+ /**
43784
+ * The REPLACEMENT rule's content tag (`sha256-<hex>`), from the `ETag`
43785
+ * response header: the `ifMatch` for the next edit or withdrawal.
43786
+ *
43787
+ * @remarks
43788
+ * Not part of the response body. Absent when the engine sends no header:
43789
+ * the replacement is written, but the read that tags the response failed
43790
+ * after the write committed. Read the tag from {@link RuleEntryDto.etag}
43791
+ * then.
43792
+ */
43793
+ etag?: string;
43735
43794
  /** What withdrawing the previous rule removed. */
43736
43795
  withdrawal: RuleWithdrawalReport;
43737
43796
  /** How the edit moved the rule base's guarantees. */
@@ -48353,10 +48412,11 @@ declare class TermsClient {
48353
48412
  * `etag` is optional in every case, not only for `asOf`. A historical read
48354
48413
  * carries none (a past state is not a representation `If-Match` can guard,
48355
48414
  * and a client that could capture one could overwrite the present with the
48356
- * past), and neither does a rule's conclusion or a term answered straight
48357
- * from durable storage. A rule's id is its conclusion term's id, so
48358
- * `getTerm(ruleId).etag` is the tag {@link InferenceClient.deleteRule} and
48359
- * {@link InferenceClient.replaceRule} take as `ifMatch`.
48415
+ * past), and neither does a term answered straight from durable storage.
48416
+ * A rule's id answers 404 here; read the tag
48417
+ * {@link InferenceClient.deleteRule} and {@link InferenceClient.replaceRule}
48418
+ * take as `ifMatch` from the rule routes ({@link AddRuleResponse.etag},
48419
+ * {@link RuleEntryDto.etag}).
48360
48420
  *
48361
48421
  * @example
48362
48422
  * ```typescript
@@ -48955,7 +49015,7 @@ declare class Inference<SecurityDataType = unknown> {
48955
49015
  */
48956
49016
  deleteGoal: (goalId: string, params?: RequestParams) => Promise<HttpResponse<DeleteGoalResponse$1, void>>;
48957
49017
  /**
48958
- * @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.
49018
+ * @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 — the tag [`rule_content_tag`] publishes on the rule routes (#473) — and requires it under `OSFKB_REQUIRE_IF_MATCH=1`. Every request is captured by the audit middleware.
48959
49019
  *
48960
49020
  * @tags inference
48961
49021
  * @name DeleteRule
@@ -49146,7 +49206,8 @@ declare class InferenceClient {
49146
49206
  *
49147
49207
  * @param request - Rule definition using TermInputDto. Set `aggregator` to declare an
49148
49208
  * engine-side head aggregator (see {@link RuleAggregatorDto}).
49149
- * @returns The created rule wrapped in an AddRuleResponse.
49209
+ * @returns The created rule wrapped in an AddRuleResponse, with its
49210
+ * {@link AddRuleResponse.etag} when the engine sends the `ETag` header.
49150
49211
  * @throws {ApiError} If the rule is rejected or the request fails — 422 when
49151
49212
  * it is unusable as written: a head or body antecedent naming a sort or
49152
49213
  * term that does not exist (the message names it and its position — `the
@@ -49169,6 +49230,9 @@ declare class InferenceClient {
49169
49230
  *
49170
49231
  * Ask {@link InferenceClient.validateRule} first to learn every reason the
49171
49232
  * write would refuse, without writing.
49233
+ * The `ETag` response header is the rule's content tag, folded into
49234
+ * `etag`: the `ifMatch` for {@link InferenceClient.deleteRule} and
49235
+ * {@link InferenceClient.replaceRule}.
49172
49236
  * A `{ termId }` reference to a term that is durable but not yet loaded
49173
49237
  * into the engine process resolves: the route loads the terms the request
49174
49238
  * names before it converts them.
@@ -49367,8 +49431,8 @@ declare class InferenceClient {
49367
49431
  * @param ruleId - Term id of the rule (its conclusion), as returned by
49368
49432
  * {@link InferenceClient.addRule} or {@link InferenceClient.getRules}.
49369
49433
  * @param options - `derivations` decides what happens to the conclusions the
49370
- * rule derived (defaults to `'refuse'`); `ifMatch` is the ETag of the
49371
- * rule's term, sent as the `If-Match` header.
49434
+ * rule derived (defaults to `'refuse'`); `ifMatch` is the rule's content
49435
+ * tag, sent as the `If-Match` header.
49372
49436
  * @param requestOptions - Per-call request options.
49373
49437
  * @returns What the withdrawal removed, tier by tier.
49374
49438
  * @throws {@link ApiError} 400 if the id names a fact rather than a rule, or
@@ -49397,14 +49461,16 @@ declare class InferenceClient {
49397
49461
  * conclusions are resident is refused too; `'retract'` removes them and
49398
49462
  * {@link RuleWithdrawalReport.consequencesInvalidated} counts them.
49399
49463
  *
49400
- * **Optimistic concurrency.** The rule routes send no ETag of their own.
49401
- * A rule's id is its conclusion term's id, so read the tag with
49402
- * `client.terms.getTerm(ruleId)` and pass its `etag` as `ifMatch`; a rule
49403
- * edited since answers 412.
49464
+ * **Optimistic concurrency.** Read the rule's tag from
49465
+ * {@link AddRuleResponse.etag}, {@link ReplaceRuleResponse.etag} or the
49466
+ * listing's {@link RuleEntryDto.etag} ({@link InferenceClient.getRules}),
49467
+ * and pass it as `ifMatch`; a rule edited since answers 412. The term route
49468
+ * does not serve it: `client.terms.getTerm(ruleId)` answers 404 for a rule.
49404
49469
  *
49405
49470
  * @example
49406
49471
  * ```typescript
49407
- * const { etag } = await client.terms.getTerm(ruleId);
49472
+ * const { rules } = await client.inference.getRules();
49473
+ * const etag = rules.find((rule) => rule.ruleId === ruleId)?.etag;
49408
49474
  * const report = await client.inference.deleteRule(ruleId, {
49409
49475
  * derivations: 'retract',
49410
49476
  * ifMatch: etag,
@@ -49421,11 +49487,12 @@ declare class InferenceClient {
49421
49487
  *
49422
49488
  * @param ruleId - Term id of the rule (its conclusion) to replace.
49423
49489
  * @param request - The replacement rule, in the same shape
49424
- * {@link InferenceClient.addRule} takes, plus `ifMatch`: the ETag of the
49425
- * outgoing rule's term, sent as the `If-Match` header and never in the body.
49490
+ * {@link InferenceClient.addRule} takes, plus `ifMatch`: the content tag
49491
+ * of the outgoing rule, sent as the `If-Match` header and never in the body.
49426
49492
  * @param requestOptions - Per-call request options.
49427
49493
  * @returns The replacement, the id it replaced, what the withdrawal removed,
49428
- * and how the rule base's guarantees moved.
49494
+ * and how the rule base's guarantees moved; `etag` is the replacement's
49495
+ * content tag when the engine sends the `ETag` header.
49429
49496
  * @throws {@link ApiError} 422 if the replacement is rejected by the
49430
49497
  * authoring guards — in which case the original rule is left live. An
49431
49498
  * empty `antecedents` list is one such refusal (`rule rejected: a rule
@@ -49448,16 +49515,23 @@ declare class InferenceClient {
49448
49515
  * addresses a single clause.
49449
49516
  *
49450
49517
  * `ifMatch` guards the edit exactly as it guards
49451
- * {@link InferenceClient.deleteRule}: read the tag with
49452
- * `client.terms.getTerm(ruleId)`.
49518
+ * {@link InferenceClient.deleteRule}: read the tag from
49519
+ * {@link AddRuleResponse.etag}, a previous {@link ReplaceRuleResponse.etag}
49520
+ * or the listing's {@link RuleEntryDto.etag}. The response's own `etag` is
49521
+ * the REPLACEMENT's tag, the `ifMatch` for the next edit.
49453
49522
  *
49454
49523
  * **Serialization format**: untagged `TermInputDto` / `FeatureInputValueDto`.
49455
49524
  *
49456
49525
  * @example
49457
49526
  * ```typescript
49458
- * const result = await client.inference.replaceRule(ruleId, {
49527
+ * const created = await client.inference.addRule({
49528
+ * term: psi('senior', { name: Var('N') }),
49529
+ * antecedents: [psi('person', { name: Var('N') })],
49530
+ * });
49531
+ * const result = await client.inference.replaceRule(created.term.termId, {
49459
49532
  * term: psi('retiree', { name: Var('N') }),
49460
49533
  * antecedents: [psi('person', { name: Var('N') })],
49534
+ * ifMatch: created.etag,
49461
49535
  * });
49462
49536
  * console.log(result.previousRuleId, '->', result.term.termId);
49463
49537
  * if (result.certification.regressed) {
@@ -71338,19 +71412,21 @@ type ScenarioSortProvenance = {
71338
71412
  * Sent byte for byte, so every key must be the engine's own spelling — and
71339
71413
  * the spellings are mixed:
71340
71414
  *
71341
- * - camelCase: `webhookActions`, `temporalConstraints`, `guardConstraints`,
71342
- * `pipelineStages`, `sensorPoints` (the engine also accepts their
71343
- * snake_case forms);
71415
+ * - camelCase only: `webhookActions`, `temporalConstraints`,
71416
+ * `guardConstraints`, `pipelineStages`, `sensorPoints`. Since engine #474
71417
+ * their snake_case forms (`webhook_actions`, …) are IGNORED, without an
71418
+ * error;
71344
71419
  * - snake_case only: `curriculum_stages`, `discovered_tools`, `use_cases`,
71345
71420
  * `competency_questions`, `computed_features`. A camelCase
71346
71421
  * `curriculumStages` or `discoveredTools` is IGNORED, without an error;
71347
71422
  * - one word: `sorts`, `beliefs`, `rules`, `goal`, `groundings`,
71348
71423
  * `constraints`, `fluents`, `axioms`, `scope`.
71349
71424
  *
71350
- * `sorts`, `beliefs` and `rules` are required, each possibly empty. `goal` is
71351
- * optional: a scenario without one materializes no agent goal
71352
- * ({@link MaterializeScenarioResponse.goalCreated} is `false`). Every other
71353
- * collection defaults to empty, and keys not listed here are ignored.
71425
+ * No key is required: every collection defaults to empty, so a vocabulary
71426
+ * import sends `sorts` alone. `goal` is optional: a scenario without one
71427
+ * materializes no agent goal
71428
+ * ({@link MaterializeScenarioResponse.goalCreated} is `false`). Keys not
71429
+ * listed here are ignored.
71354
71430
  *
71355
71431
  * The same rule holds inside the collections. A curriculum stage is
71356
71432
  * `{stage_number, name, concepts, prerequisites?, mastery_threshold?}`, a
@@ -71372,9 +71448,9 @@ interface GeneratedScenario {
71372
71448
  /**
71373
71449
  * Sorts to create or reuse. A sort may carry `provenance`
71374
71450
  * ({@link ScenarioSortProvenance}); without it the sort is credited to the
71375
- * caller.
71451
+ * caller. Defaults to empty.
71376
71452
  */
71377
- sorts: Record<string, unknown>[];
71453
+ sorts?: Record<string, unknown>[];
71378
71454
  /**
71379
71455
  * Belief instances (typed facts) to assert. Omit it for a schema-only
71380
71456
  * scenario: the engine builds sorts alone (a scenario needs at least one
@@ -71418,7 +71494,7 @@ interface GeneratedScenario {
71418
71494
  webhookActions?: Record<string, unknown>[];
71419
71495
  /** OWL-style axioms over sorts and features (staged builder). */
71420
71496
  axioms?: Record<string, unknown>[];
71421
- /** The model's declared scope (staged builder). */
71497
+ /** The model's declared scope. Accepted and not written by materialization: `ontology.putScope` stores a scope. */
71422
71498
  scope?: Record<string, unknown>;
71423
71499
  /** Use cases the model serves (staged builder). */
71424
71500
  use_cases?: Record<string, unknown>[];