@kortexya/reasoninglayer 1.23.0 → 1.25.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.25.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
  *
@@ -8405,6 +8440,23 @@ var Functions = class {
8405
8440
  constructor(http) {
8406
8441
  this.http = http;
8407
8442
  }
8443
+ /**
8444
+ * @description # The disposition is the caller's `?callers=refuse` (the default) refuses while anything calls the function and names every caller; `?callers=orphan` withdraws it anyway and reports the callers left naming something that no longer resolves. A withdrawal that silently orphans its callers is the state the missing route already produced. # Authorization Requires `X-Tenant-Id`. The function store is tenant-keyed, so another tenant's function is `404` rather than forbidden. Every request is captured by the audit middleware.
8445
+ *
8446
+ * @tags functions
8447
+ * @name DeleteFunction
8448
+ * @summary Withdraw a registered function.
8449
+ * @request DELETE:/api/v1/functions/{name}
8450
+ * @secure
8451
+ */
8452
+ deleteFunction = (name, query, params = {}) => this.http.request({
8453
+ path: `/api/v1/functions/${name}`,
8454
+ method: "DELETE",
8455
+ query,
8456
+ secure: true,
8457
+ format: "json",
8458
+ ...params
8459
+ });
8408
8460
  /**
8409
8461
  * @description Never writes to the KB — returns a validated draft for human review.
8410
8462
  *
@@ -8475,6 +8527,24 @@ var Functions = class {
8475
8527
  format: "json",
8476
8528
  ...params
8477
8529
  });
8530
+ /**
8531
+ * @description # Why this is not `POST /functions/register` Registration already replaces by name — silently, reporting nothing about what it displaced. `PUT` is the operation that says so: it refuses when nothing is registered under the name (that is registration's job), and answers with the previous signature, the new one, whether the arity moved, and everything that calls the function. # The arity is the hazard A function's identity is its NAME, so a replacement keeps every caller's reference valid — nothing dangles. That is exactly why an arity change is dangerous rather than merely breaking: every call still resolves, and one passing the old number of arguments starts failing at evaluation time. Reported, not refused: the caller may be replacing the function precisely because its signature was wrong. # Authorization Identical to `DELETE`: tenant-keyed, plugin-owned functions refused, audited.
8532
+ *
8533
+ * @tags functions
8534
+ * @name ReplaceFunction
8535
+ * @summary Replace a registered function's definition.
8536
+ * @request PUT:/api/v1/functions/{name}
8537
+ * @secure
8538
+ */
8539
+ replaceFunction = (name, data, params = {}) => this.http.request({
8540
+ path: `/api/v1/functions/${name}`,
8541
+ method: "PUT",
8542
+ body: data,
8543
+ secure: true,
8544
+ type: "application/json",
8545
+ format: "json",
8546
+ ...params
8547
+ });
8478
8548
  };
8479
8549
 
8480
8550
  // src/api-spec/generated/WebhookActions.ts
@@ -14297,7 +14367,13 @@ function RuleEntryDtoFromApiToFront(dto) {
14297
14367
  ruleId: dto.rule_id,
14298
14368
  head: PsiTermDtoFromApiToFront(dto.head),
14299
14369
  body: dto.body.map(PsiTermDtoFromApiToFront),
14300
- certainty: dto.certainty ?? void 0
14370
+ certainty: dto.certainty ?? void 0,
14371
+ origin: dto.origin,
14372
+ withdrawable: dto.withdrawable,
14373
+ notWithdrawable: dto.not_withdrawable ? {
14374
+ code: dto.not_withdrawable.code,
14375
+ reason: dto.not_withdrawable.reason
14376
+ } : void 0
14301
14377
  };
14302
14378
  }
14303
14379
  function GetRulesResponseFromApiToFront(dto) {
@@ -14306,6 +14382,35 @@ function GetRulesResponseFromApiToFront(dto) {
14306
14382
  rules: dto.rules.map(RuleEntryDtoFromApiToFront)
14307
14383
  };
14308
14384
  }
14385
+ function RuleWithdrawalReportFromApiToFront(dto) {
14386
+ return {
14387
+ ruleId: dto.rule_id,
14388
+ termsDeleted: dto.terms_deleted,
14389
+ termsRetainedShared: dto.terms_retained_shared,
14390
+ derivationsRemoved: dto.derivations_removed,
14391
+ derivationsWeakened: dto.derivations_weakened,
14392
+ derivationsTruncated: dto.derivations_truncated,
14393
+ consequencesInvalidated: dto.consequences_invalidated,
14394
+ queuedEventsCancelled: dto.queued_events_cancelled
14395
+ };
14396
+ }
14397
+ function RuleCertificationDeltaFromApiToFront(dto) {
14398
+ return {
14399
+ terminatedBefore: dto.terminated_before,
14400
+ terminatesAfter: dto.terminates_after,
14401
+ orderIndependentBefore: dto.order_independent_before,
14402
+ orderIndependentAfter: dto.order_independent_after,
14403
+ regressed: dto.regressed
14404
+ };
14405
+ }
14406
+ function ReplaceRuleResponseFromApiToFront(dto) {
14407
+ return {
14408
+ previousRuleId: dto.previous_rule_id,
14409
+ term: PsiTermDtoFromApiToFront(dto.term),
14410
+ withdrawal: RuleWithdrawalReportFromApiToFront(dto.withdrawal),
14411
+ certification: RuleCertificationDeltaFromApiToFront(dto.certification)
14412
+ };
14413
+ }
14309
14414
  function MetaSortsResponseFromApiToFront(dto) {
14310
14415
  return {
14311
14416
  absConstraint: dto.abs_constraint,
@@ -14793,6 +14898,89 @@ var InferenceClient = class {
14793
14898
  const response = await this.api.getRules(this.tenantId);
14794
14899
  return GetRulesResponseFromApiToFront(response.data);
14795
14900
  }
14901
+ /**
14902
+ * Withdraw one rule from the knowledge base.
14903
+ *
14904
+ * @param ruleId - Term id of the rule (its conclusion), as returned by
14905
+ * {@link InferenceClient.addRule} or {@link InferenceClient.getRules}.
14906
+ * @param options - `derivations` decides what happens to the conclusions the
14907
+ * rule derived. Defaults to `'refuse'`.
14908
+ * @returns What the withdrawal removed, tier by tier.
14909
+ * @throws {ApiError} 400 if the id names a fact rather than a rule, or if the
14910
+ * rule still supports derivations under the default `'refuse'`; 403 for a
14911
+ * system, plugin-owned or bootstrap rule; 404 if no such rule exists.
14912
+ *
14913
+ * @remarks
14914
+ * A rule is not a row. Withdrawing one deletes its conclusion AND the
14915
+ * antecedent pattern, guard and variable terms it exclusively owns — a
14916
+ * conclusion-only delete would leave those patterns readable as ordinary
14917
+ * facts — while keeping every term the rest of the knowledge base still
14918
+ * holds.
14919
+ *
14920
+ * `'refuse'` (the default) refuses while the rule still proves materialized
14921
+ * conclusions and says how many; `'retract'` withdraws them with it. A delete
14922
+ * that silently drops derivations is as wrong as one that silently keeps
14923
+ * them, so neither is the unnamed default.
14924
+ *
14925
+ * @example
14926
+ * ```typescript
14927
+ * const report = await client.inference.deleteRule(ruleId, { derivations: 'retract' });
14928
+ * console.log(report.termsDeleted, report.derivationsRemoved);
14929
+ * ```
14930
+ */
14931
+ async deleteRule(ruleId, options) {
14932
+ const response = await this.api.deleteRule(
14933
+ ruleId,
14934
+ options?.derivations === void 0 ? void 0 : { derivations: options.derivations }
14935
+ );
14936
+ return RuleWithdrawalReportFromApiToFront(response.data);
14937
+ }
14938
+ /**
14939
+ * Replace one rule with a new one.
14940
+ *
14941
+ * @param ruleId - Term id of the rule (its conclusion) to replace.
14942
+ * @param request - The replacement rule, in the same shape
14943
+ * {@link InferenceClient.addRule} takes.
14944
+ * @returns The replacement, the id it replaced, what the withdrawal removed,
14945
+ * and how the rule base's guarantees moved.
14946
+ * @throws {ApiError} 422 if the replacement is rejected by the authoring
14947
+ * guards — in which case the original rule is left live; 400/403/404 as for
14948
+ * {@link InferenceClient.deleteRule}.
14949
+ *
14950
+ * @remarks
14951
+ * A rule's id IS its conclusion term id, so an edit changes it by
14952
+ * construction. The response carries `previousRuleId` alongside the new
14953
+ * rule; a client holding the old id must adopt the new one.
14954
+ *
14955
+ * The path names ONE rule term — one disjunct. Two rules with the same
14956
+ * conclusion are OR-unioned, so "edit the rule for X" is ambiguous and this
14957
+ * addresses a single clause.
14958
+ *
14959
+ * @example
14960
+ * ```typescript
14961
+ * const result = await client.inference.replaceRule(ruleId, {
14962
+ * term: psi('retiree', { name: Var('N') }),
14963
+ * antecedents: [psi('person', { name: Var('N') })],
14964
+ * });
14965
+ * console.log(result.previousRuleId, '->', result.term.termId);
14966
+ * if (result.certification.regressed) {
14967
+ * console.warn('the edit weakened the rule base guarantees');
14968
+ * }
14969
+ * ```
14970
+ */
14971
+ async replaceRule(ruleId, request) {
14972
+ const wireRequest = {
14973
+ term: convertTermArg(request.term),
14974
+ antecedents: request.antecedents?.map(convertTermArg),
14975
+ certainty: request.certainty,
14976
+ aggregator: request.aggregator
14977
+ };
14978
+ const response = await this.api.replaceRule(
14979
+ ruleId,
14980
+ AddRuleRequestFromFrontToApi(wireRequest)
14981
+ );
14982
+ return ReplaceRuleResponseFromApiToFront(response.data);
14983
+ }
14796
14984
  /**
14797
14985
  * Query for matching data by searching rules and facts backwards from a goal pattern.
14798
14986
  *
@@ -15084,7 +15272,8 @@ function FindBySortRequestFromFrontToApi(model) {
15084
15272
  return {
15085
15273
  sort_id: model.sortId ?? void 0,
15086
15274
  sort_name: model.sortName ?? void 0,
15087
- filter: model.filter ?? void 0
15275
+ filter: model.filter ?? void 0,
15276
+ limit: model.limit ?? void 0
15088
15277
  };
15089
15278
  }
15090
15279
  function OsfSearchRequestFromFrontToApi(model) {
@@ -17256,7 +17445,7 @@ var ConstraintsClient = class {
17256
17445
  type: "application/json",
17257
17446
  format: "json"
17258
17447
  });
17259
- return response.data;
17448
+ return ConstraintGraphResponseFromApiToFront(response.data);
17260
17449
  }
17261
17450
  // --- Session Management ---
17262
17451
  /**
@@ -23331,9 +23520,11 @@ function StructuredIngestionStatsDtoFromApiToFront(dto) {
23331
23520
  elapsedMs: dto.elapsed_ms,
23332
23521
  entitiesCreated: dto.entities_created,
23333
23522
  entitiesExtracted: dto.entities_extracted,
23523
+ recordsAvailable: dto.records_available,
23334
23524
  recordsProcessed: dto.records_processed,
23335
23525
  relationsCreated: dto.relations_created,
23336
23526
  relationsDiscovered: dto.relations_discovered,
23527
+ rowsCollapsed: dto.rows_collapsed,
23337
23528
  sortsCreated: dto.sorts_created,
23338
23529
  tablesDiscovered: dto.tables_discovered,
23339
23530
  termsCreated: dto.terms_created,
@@ -26190,6 +26381,34 @@ function DraftFunctionResponseFromApiToFront(dto) {
26190
26381
  warnings: dto.warnings
26191
26382
  };
26192
26383
  }
26384
+ function FunctionCallerFromApiToFront(dto) {
26385
+ return {
26386
+ kind: dto.kind,
26387
+ name: dto.name,
26388
+ termId: dto.term_id ?? void 0
26389
+ };
26390
+ }
26391
+ function FunctionWithdrawalReportFromApiToFront(dto) {
26392
+ return {
26393
+ name: dto.name,
26394
+ functionId: dto.function_id,
26395
+ carrierDeleted: dto.carrier_deleted,
26396
+ deregistered: dto.deregistered,
26397
+ // The wire omits the field when nothing was orphaned; the SDK always
26398
+ // hands back an array, so a caller never has to guard the read.
26399
+ callersOrphaned: (dto.callers_orphaned ?? []).map(FunctionCallerFromApiToFront)
26400
+ };
26401
+ }
26402
+ function ReplaceFunctionResponseFromApiToFront(dto) {
26403
+ return {
26404
+ name: dto.name,
26405
+ functionId: dto.function_id,
26406
+ previous: FunctionSummaryDtoFromApiToFront(dto.previous),
26407
+ current: FunctionSummaryDtoFromApiToFront(dto.current),
26408
+ arityChanged: dto.arity_changed,
26409
+ callers: (dto.callers ?? []).map(FunctionCallerFromApiToFront)
26410
+ };
26411
+ }
26193
26412
 
26194
26413
  // src/resources/functions.ts
26195
26414
  var FunctionsClient = class {
@@ -26334,6 +26553,85 @@ var FunctionsClient = class {
26334
26553
  const response = await this.api.listFunctions();
26335
26554
  return ListFunctionsResponseFromApiToFront(response.data);
26336
26555
  }
26556
+ /**
26557
+ * Withdraw a registered function.
26558
+ *
26559
+ * @param name - The registered function's name — its identity.
26560
+ * @param options - `callers` decides what happens to the things that call
26561
+ * it. Defaults to `'refuse'`.
26562
+ * @returns What the withdrawal removed, in each representation that held it.
26563
+ * @throws {ApiError} 400 if something still calls the function under the
26564
+ * default `'refuse'` (the body carries `code: 'function_has_callers'` and
26565
+ * the caller list); 403 for a plugin-contributed function; 404 if nothing
26566
+ * is registered under that name.
26567
+ *
26568
+ * @remarks
26569
+ * A function is carried twice — the durable `meta.function` carrier that is
26570
+ * the source of truth, and the evaluator's own registry used for dispatch
26571
+ * and recursive cross-calls — and the report names both, because forgetting
26572
+ * either leaves it half-alive: still evaluable, or back after a restart.
26573
+ *
26574
+ * `'refuse'` names every caller; `'orphan'` withdraws anyway and reports the
26575
+ * callers left naming something that no longer resolves.
26576
+ *
26577
+ * @example
26578
+ * ```typescript
26579
+ * const report = await client.functions.deleteFunction('scale', { callers: 'orphan' });
26580
+ * for (const orphan of report.callersOrphaned) {
26581
+ * console.warn(`${orphan.kind} ${orphan.name} now calls a function that is gone`);
26582
+ * }
26583
+ * ```
26584
+ */
26585
+ async deleteFunction(name, options) {
26586
+ const response = await this.api.deleteFunction(
26587
+ name,
26588
+ options?.callers === void 0 ? void 0 : { callers: options.callers }
26589
+ );
26590
+ return FunctionWithdrawalReportFromApiToFront(response.data);
26591
+ }
26592
+ /**
26593
+ * Replace a registered function's definition.
26594
+ *
26595
+ * @param name - The registered function's name. Unchanged by the
26596
+ * replacement — the name IS the identity.
26597
+ * @param request - The replacement's arity and clauses.
26598
+ * @returns Both signatures, whether the arity moved, and everything that
26599
+ * calls the function.
26600
+ * @throws {ApiError} 400 if the replacement's clauses are rejected — in
26601
+ * which case the registration is left exactly as it was; 403 for a
26602
+ * plugin-contributed function; 404 if nothing is registered under that
26603
+ * name (creating one is {@link FunctionsClient.registerFunction}'s job).
26604
+ *
26605
+ * @remarks
26606
+ * `registerFunction` already replaces by name — silently, reporting nothing
26607
+ * about what it displaced. This is the operation that says so.
26608
+ *
26609
+ * A function's identity is its NAME, so a replacement keeps every caller's
26610
+ * reference valid: nothing dangles. That is exactly why an arity change is
26611
+ * the dangerous edit — every call still resolves, and one passing the old
26612
+ * argument count starts failing at evaluation time. `arityChanged` is
26613
+ * reported rather than refused, because a caller may be replacing the
26614
+ * function precisely because its signature was wrong.
26615
+ *
26616
+ * @example
26617
+ * ```typescript
26618
+ * const result = await client.functions.replaceFunction('scale', {
26619
+ * arity: 2,
26620
+ * clauses: [multiplyClause],
26621
+ * });
26622
+ * if (result.arityChanged) {
26623
+ * console.warn(`arity ${result.previous.arity} -> ${result.current.arity};`,
26624
+ * `${result.callers.length} caller(s) were written against the old one`);
26625
+ * }
26626
+ * ```
26627
+ */
26628
+ async replaceFunction(name, request) {
26629
+ const response = await this.api.replaceFunction(name, {
26630
+ arity: request.arity,
26631
+ clauses: request.clauses.map(FunctionClauseDtoFromFrontToApi)
26632
+ });
26633
+ return ReplaceFunctionResponseFromApiToFront(response.data);
26634
+ }
26337
26635
  /**
26338
26636
  * Draft a user-defined function from a natural-language description.
26339
26637
  *
@@ -27587,6 +27885,7 @@ function ClearTenantResponseFromApiToFront(dto) {
27587
27885
  sortsDeleted: dto.sorts_deleted,
27588
27886
  inferenceStateCleared: dto.inference_state_cleared,
27589
27887
  cacheInvalidated: dto.cache_invalidated,
27888
+ vectorsDeleted: dto.vectors_deleted,
27590
27889
  pluginInstallsDeleted: dto.plugin_installs_deleted
27591
27890
  };
27592
27891
  }
@@ -32751,7 +33050,14 @@ function BindingSummaryDtoFromApiToFront(dto) {
32751
33050
  keyColumns: dto.key_columns,
32752
33051
  sortId: dto.sort_id,
32753
33052
  sourceId: dto.source_id,
32754
- tableName: dto.table_name
33053
+ tableName: dto.table_name,
33054
+ keyProvenance: {
33055
+ source: dto.key_provenance.source,
33056
+ chosenBy: dto.key_provenance.chosen_by,
33057
+ explanation: dto.key_provenance.explanation,
33058
+ guaranteedUnique: dto.key_provenance.guaranteed_unique,
33059
+ durability: dto.key_provenance.durability
33060
+ }
32755
33061
  };
32756
33062
  }
32757
33063
  function ListBindingsResponseFromApiToFront(dto) {