@kortexya/reasoninglayer 1.24.0 → 1.26.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.js CHANGED
@@ -5,7 +5,7 @@ var __export = (target, all) => {
5
5
  };
6
6
 
7
7
  // src/config.ts
8
- var SDK_VERSION = "1.24.0";
8
+ var SDK_VERSION = "1.26.0";
9
9
  function resolveConfig(config) {
10
10
  if (!config.baseUrl) {
11
11
  throw new Error("ClientConfig.baseUrl is required");
@@ -8438,6 +8438,23 @@ var Functions = class {
8438
8438
  constructor(http) {
8439
8439
  this.http = http;
8440
8440
  }
8441
+ /**
8442
+ * @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.
8443
+ *
8444
+ * @tags functions
8445
+ * @name DeleteFunction
8446
+ * @summary Withdraw a registered function.
8447
+ * @request DELETE:/api/v1/functions/{name}
8448
+ * @secure
8449
+ */
8450
+ deleteFunction = (name, query, params = {}) => this.http.request({
8451
+ path: `/api/v1/functions/${name}`,
8452
+ method: "DELETE",
8453
+ query,
8454
+ secure: true,
8455
+ format: "json",
8456
+ ...params
8457
+ });
8441
8458
  /**
8442
8459
  * @description Never writes to the KB — returns a validated draft for human review.
8443
8460
  *
@@ -8474,6 +8491,22 @@ var Functions = class {
8474
8491
  format: "json",
8475
8492
  ...params
8476
8493
  });
8494
+ /**
8495
+ * @description # Why this route had to exist `/api/v1/functions` had five routes and none of them returned a definition: the listing answers summaries (`name`, `arity`, `clauses_count`, `kind`), and `GET /api/v1/functions/{name}` was a `405`. So `PUT` replaced a definition its caller could not see — a client fixing one clause of a three-clause function had to remember the other two or lose them, and the route made a partial edit look like a whole one (#235). # The clauses come back in the shape `PUT` takes [`GetFunctionResponse::clauses`] is the exact `clauses` payload `POST /functions/register` and `PUT /functions/{name}` accept, so a read-modify-write needs no translation layer that could drop a body variant on the way through. Making that true meant widening the request shape: `BinaryOperatorDto` carried four of the domain's thirteen operators and `ExpressionDto` was missing `UnaryOp` and `Conditional`, while OSFQL `DERIVE` builds function bodies with every one of them. A read in the old shape would have had to drop a `CASE WHEN` or lie about a `%`. # Reading is not changing A plugin-contributed function is refused by `DELETE` and `PUT` and **returned** by this route, with `replaceable: false` and the refusal the mutation would answer with. The listing already admits it exists; refusing to describe it would leave a client unable to show what the plugin contributed while still showing its name. The refusal is read from the same walk the mutation routes run, so the two cannot disagree. # Authorization Requires `X-Tenant-Id`. The function store is tenant-keyed, so another tenant's function is `404` rather than forbidden — saying anything else would confirm the name exists somewhere.
8496
+ *
8497
+ * @tags functions
8498
+ * @name GetFunction
8499
+ * @summary Read one registered function's definition.
8500
+ * @request GET:/api/v1/functions/{name}
8501
+ * @secure
8502
+ */
8503
+ getFunction = (name, params = {}) => this.http.request({
8504
+ path: `/api/v1/functions/${name}`,
8505
+ method: "GET",
8506
+ secure: true,
8507
+ format: "json",
8508
+ ...params
8509
+ });
8477
8510
  /**
8478
8511
  * @description This is the discovery counterpart to `register_function`/`evaluate_function`: it projects the tenant's slice of the function sub-lattice into a list of typed signatures (name + arity + clause count) without evaluating anything. The tenant is taken from the authenticated principal (never a body field), honouring the tenancy-scoping invariant.
8479
8512
  *
@@ -8508,6 +8541,24 @@ var Functions = class {
8508
8541
  format: "json",
8509
8542
  ...params
8510
8543
  });
8544
+ /**
8545
+ * @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.
8546
+ *
8547
+ * @tags functions
8548
+ * @name ReplaceFunction
8549
+ * @summary Replace a registered function's definition.
8550
+ * @request PUT:/api/v1/functions/{name}
8551
+ * @secure
8552
+ */
8553
+ replaceFunction = (name, data, params = {}) => this.http.request({
8554
+ path: `/api/v1/functions/${name}`,
8555
+ method: "PUT",
8556
+ body: data,
8557
+ secure: true,
8558
+ type: "application/json",
8559
+ format: "json",
8560
+ ...params
8561
+ });
8511
8562
  };
8512
8563
 
8513
8564
  // src/api-spec/generated/WebhookActions.ts
@@ -14330,7 +14381,13 @@ function RuleEntryDtoFromApiToFront(dto) {
14330
14381
  ruleId: dto.rule_id,
14331
14382
  head: PsiTermDtoFromApiToFront(dto.head),
14332
14383
  body: dto.body.map(PsiTermDtoFromApiToFront),
14333
- certainty: dto.certainty ?? void 0
14384
+ certainty: dto.certainty ?? void 0,
14385
+ origin: dto.origin,
14386
+ withdrawable: dto.withdrawable,
14387
+ notWithdrawable: dto.not_withdrawable ? {
14388
+ code: dto.not_withdrawable.code,
14389
+ reason: dto.not_withdrawable.reason
14390
+ } : void 0
14334
14391
  };
14335
14392
  }
14336
14393
  function GetRulesResponseFromApiToFront(dto) {
@@ -15229,7 +15286,8 @@ function FindBySortRequestFromFrontToApi(model) {
15229
15286
  return {
15230
15287
  sort_id: model.sortId ?? void 0,
15231
15288
  sort_name: model.sortName ?? void 0,
15232
- filter: model.filter ?? void 0
15289
+ filter: model.filter ?? void 0,
15290
+ limit: model.limit ?? void 0
15233
15291
  };
15234
15292
  }
15235
15293
  function OsfSearchRequestFromFrontToApi(model) {
@@ -17401,7 +17459,7 @@ var ConstraintsClient = class {
17401
17459
  type: "application/json",
17402
17460
  format: "json"
17403
17461
  });
17404
- return response.data;
17462
+ return ConstraintGraphResponseFromApiToFront(response.data);
17405
17463
  }
17406
17464
  // --- Session Management ---
17407
17465
  /**
@@ -23476,9 +23534,11 @@ function StructuredIngestionStatsDtoFromApiToFront(dto) {
23476
23534
  elapsedMs: dto.elapsed_ms,
23477
23535
  entitiesCreated: dto.entities_created,
23478
23536
  entitiesExtracted: dto.entities_extracted,
23537
+ recordsAvailable: dto.records_available,
23479
23538
  recordsProcessed: dto.records_processed,
23480
23539
  relationsCreated: dto.relations_created,
23481
23540
  relationsDiscovered: dto.relations_discovered,
23541
+ rowsCollapsed: dto.rows_collapsed,
23482
23542
  sortsCreated: dto.sorts_created,
23483
23543
  tablesDiscovered: dto.tables_discovered,
23484
23544
  termsCreated: dto.terms_created,
@@ -26129,6 +26189,23 @@ function ExpressionDtoFromFrontToApi(model) {
26129
26189
  right: ExpressionDtoFromFrontToApi(model.right)
26130
26190
  };
26131
26191
  }
26192
+ if (model.type === "UnaryOp") {
26193
+ return {
26194
+ type: "UnaryOp",
26195
+ op: model.op,
26196
+ operand: ExpressionDtoFromFrontToApi(model.operand)
26197
+ };
26198
+ }
26199
+ if (model.type === "Conditional") {
26200
+ return {
26201
+ type: "Conditional",
26202
+ branches: model.branches.map((b) => ({
26203
+ when: ExpressionDtoFromFrontToApi(b.when),
26204
+ then: ExpressionDtoFromFrontToApi(b.then)
26205
+ })),
26206
+ default: model.default ? ExpressionDtoFromFrontToApi(model.default) : model.default
26207
+ };
26208
+ }
26132
26209
  return model;
26133
26210
  }
26134
26211
  function ExpressionDtoFromApiToFront(dto) {
@@ -26147,6 +26224,23 @@ function ExpressionDtoFromApiToFront(dto) {
26147
26224
  right: ExpressionDtoFromApiToFront(dto.right)
26148
26225
  };
26149
26226
  }
26227
+ if (dto.type === "UnaryOp") {
26228
+ return {
26229
+ type: "UnaryOp",
26230
+ op: dto.op,
26231
+ operand: ExpressionDtoFromApiToFront(dto.operand)
26232
+ };
26233
+ }
26234
+ if (dto.type === "Conditional") {
26235
+ return {
26236
+ type: "Conditional",
26237
+ branches: dto.branches.map((b) => ({
26238
+ when: ExpressionDtoFromApiToFront(b.when),
26239
+ then: ExpressionDtoFromApiToFront(b.then)
26240
+ })),
26241
+ default: dto.default ? ExpressionDtoFromApiToFront(dto.default) : dto.default
26242
+ };
26243
+ }
26150
26244
  return dto;
26151
26245
  }
26152
26246
  function FunctionBodyDtoFromFrontToApi(model) {
@@ -26335,6 +26429,54 @@ function DraftFunctionResponseFromApiToFront(dto) {
26335
26429
  warnings: dto.warnings
26336
26430
  };
26337
26431
  }
26432
+ function FunctionCallerFromApiToFront(dto) {
26433
+ return {
26434
+ kind: dto.kind,
26435
+ name: dto.name,
26436
+ termId: dto.term_id ?? void 0
26437
+ };
26438
+ }
26439
+ function FunctionWithdrawalReportFromApiToFront(dto) {
26440
+ return {
26441
+ name: dto.name,
26442
+ functionId: dto.function_id,
26443
+ carrierDeleted: dto.carrier_deleted,
26444
+ deregistered: dto.deregistered,
26445
+ // The wire omits the field when nothing was orphaned; the SDK always
26446
+ // hands back an array, so a caller never has to guard the read.
26447
+ callersOrphaned: (dto.callers_orphaned ?? []).map(FunctionCallerFromApiToFront)
26448
+ };
26449
+ }
26450
+ function ReplaceFunctionResponseFromApiToFront(dto) {
26451
+ return {
26452
+ name: dto.name,
26453
+ functionId: dto.function_id,
26454
+ previous: FunctionSummaryDtoFromApiToFront(dto.previous),
26455
+ current: FunctionSummaryDtoFromApiToFront(dto.current),
26456
+ arityChanged: dto.arity_changed,
26457
+ callers: (dto.callers ?? []).map(FunctionCallerFromApiToFront)
26458
+ };
26459
+ }
26460
+ function GetFunctionResponseFromApiToFront(dto) {
26461
+ const signature = {
26462
+ name: dto.name,
26463
+ functionId: dto.function_id,
26464
+ arity: dto.arity,
26465
+ kind: dto.kind,
26466
+ replaceable: dto.replaceable,
26467
+ notReplaceable: dto.not_replaceable ?? void 0,
26468
+ // The wire omits the field when nothing calls it; the SDK always hands
26469
+ // back an array, as the withdrawal report already does.
26470
+ callers: (dto.callers ?? []).map(FunctionCallerFromApiToFront)
26471
+ };
26472
+ if (dto.clauses == null) {
26473
+ return {
26474
+ ...signature,
26475
+ unrepresentable: dto.unrepresentable ?? "The engine returned no clauses for this function and gave no reason."
26476
+ };
26477
+ }
26478
+ return { ...signature, clauses: dto.clauses.map(FunctionClauseDtoFromApiToFront) };
26479
+ }
26338
26480
 
26339
26481
  // src/resources/functions.ts
26340
26482
  var FunctionsClient = class {
@@ -26398,7 +26540,9 @@ var FunctionsClient = class {
26398
26540
  * ```
26399
26541
  */
26400
26542
  async registerFunction(request) {
26401
- const response = await this.api.registerFunction(RegisterFunctionRequestFromFrontToApi(request));
26543
+ const response = await this.api.registerFunction(
26544
+ RegisterFunctionRequestFromFrontToApi(request)
26545
+ );
26402
26546
  return RegisterFunctionResponseFromApiToFront(response.data);
26403
26547
  }
26404
26548
  /**
@@ -26449,7 +26593,9 @@ var FunctionsClient = class {
26449
26593
  * ```
26450
26594
  */
26451
26595
  async evaluateFunction(request) {
26452
- const response = await this.api.evaluateFunction(EvaluateFunctionRequestFromFrontToApi(request));
26596
+ const response = await this.api.evaluateFunction(
26597
+ EvaluateFunctionRequestFromFrontToApi(request)
26598
+ );
26453
26599
  return EvaluateFunctionResponseFromApiToFront(response.data);
26454
26600
  }
26455
26601
  /**
@@ -26479,6 +26625,128 @@ var FunctionsClient = class {
26479
26625
  const response = await this.api.listFunctions();
26480
26626
  return ListFunctionsResponseFromApiToFront(response.data);
26481
26627
  }
26628
+ /**
26629
+ * Read one registered function's definition.
26630
+ *
26631
+ * @param name - The registered function's name — its identity.
26632
+ * @returns The signature, everything that calls it, whether a `PUT` would
26633
+ * act or refuse, and the clauses in the shape a replacement takes.
26634
+ * @throws {ApiError} 404 if nothing is registered under that name for the
26635
+ * authenticated tenant. Another tenant's function is 404 too — saying
26636
+ * anything else would confirm the name exists somewhere.
26637
+ *
26638
+ * @remarks
26639
+ * This is what makes {@link FunctionsClient.replaceFunction} an edit. `PUT`
26640
+ * replaces the WHOLE definition, so without a read a client fixing one
26641
+ * clause of a three-clause function had to re-author the other two from
26642
+ * memory, and any it forgot were deleted.
26643
+ *
26644
+ * `clauses` and `unrepresentable` are exclusive: a definition holding a
26645
+ * construct the register shape cannot express comes back with no clauses and
26646
+ * a reason, because a degraded read written back would destroy the real
26647
+ * definition. Narrow on `clauses === undefined` before using them.
26648
+ *
26649
+ * A plugin-contributed function is refused by `DELETE`/`PUT` and returned
26650
+ * here, with `replaceable: false` and the refusal the mutation would give.
26651
+ *
26652
+ * @example
26653
+ * ```typescript
26654
+ * const definition = await client.functions.getFunction('scale');
26655
+ * if (definition.clauses === undefined) {
26656
+ * throw new Error(`scale cannot be edited: ${definition.unrepresentable}`);
26657
+ * }
26658
+ * if (!definition.replaceable) {
26659
+ * throw new Error(definition.notReplaceable?.reason);
26660
+ * }
26661
+ * await client.functions.replaceFunction('scale', {
26662
+ * arity: definition.arity,
26663
+ * clauses: definition.clauses.map(tweak),
26664
+ * });
26665
+ * ```
26666
+ */
26667
+ async getFunction(name) {
26668
+ const response = await this.api.getFunction(name);
26669
+ return GetFunctionResponseFromApiToFront(response.data);
26670
+ }
26671
+ /**
26672
+ * Withdraw a registered function.
26673
+ *
26674
+ * @param name - The registered function's name — its identity.
26675
+ * @param options - `callers` decides what happens to the things that call
26676
+ * it. Defaults to `'refuse'`.
26677
+ * @returns What the withdrawal removed, in each representation that held it.
26678
+ * @throws {ApiError} 400 if something still calls the function under the
26679
+ * default `'refuse'` (the body carries `code: 'function_has_callers'` and
26680
+ * the caller list); 403 for a plugin-contributed function; 404 if nothing
26681
+ * is registered under that name.
26682
+ *
26683
+ * @remarks
26684
+ * A function is carried twice — the durable `meta.function` carrier that is
26685
+ * the source of truth, and the evaluator's own registry used for dispatch
26686
+ * and recursive cross-calls — and the report names both, because forgetting
26687
+ * either leaves it half-alive: still evaluable, or back after a restart.
26688
+ *
26689
+ * `'refuse'` names every caller; `'orphan'` withdraws anyway and reports the
26690
+ * callers left naming something that no longer resolves.
26691
+ *
26692
+ * @example
26693
+ * ```typescript
26694
+ * const report = await client.functions.deleteFunction('scale', { callers: 'orphan' });
26695
+ * for (const orphan of report.callersOrphaned) {
26696
+ * console.warn(`${orphan.kind} ${orphan.name} now calls a function that is gone`);
26697
+ * }
26698
+ * ```
26699
+ */
26700
+ async deleteFunction(name, options) {
26701
+ const response = await this.api.deleteFunction(
26702
+ name,
26703
+ options?.callers === void 0 ? void 0 : { callers: options.callers }
26704
+ );
26705
+ return FunctionWithdrawalReportFromApiToFront(response.data);
26706
+ }
26707
+ /**
26708
+ * Replace a registered function's definition.
26709
+ *
26710
+ * @param name - The registered function's name. Unchanged by the
26711
+ * replacement — the name IS the identity.
26712
+ * @param request - The replacement's arity and clauses.
26713
+ * @returns Both signatures, whether the arity moved, and everything that
26714
+ * calls the function.
26715
+ * @throws {ApiError} 400 if the replacement's clauses are rejected — in
26716
+ * which case the registration is left exactly as it was; 403 for a
26717
+ * plugin-contributed function; 404 if nothing is registered under that
26718
+ * name (creating one is {@link FunctionsClient.registerFunction}'s job).
26719
+ *
26720
+ * @remarks
26721
+ * `registerFunction` already replaces by name — silently, reporting nothing
26722
+ * about what it displaced. This is the operation that says so.
26723
+ *
26724
+ * A function's identity is its NAME, so a replacement keeps every caller's
26725
+ * reference valid: nothing dangles. That is exactly why an arity change is
26726
+ * the dangerous edit — every call still resolves, and one passing the old
26727
+ * argument count starts failing at evaluation time. `arityChanged` is
26728
+ * reported rather than refused, because a caller may be replacing the
26729
+ * function precisely because its signature was wrong.
26730
+ *
26731
+ * @example
26732
+ * ```typescript
26733
+ * const result = await client.functions.replaceFunction('scale', {
26734
+ * arity: 2,
26735
+ * clauses: [multiplyClause],
26736
+ * });
26737
+ * if (result.arityChanged) {
26738
+ * console.warn(`arity ${result.previous.arity} -> ${result.current.arity};`,
26739
+ * `${result.callers.length} caller(s) were written against the old one`);
26740
+ * }
26741
+ * ```
26742
+ */
26743
+ async replaceFunction(name, request) {
26744
+ const response = await this.api.replaceFunction(name, {
26745
+ arity: request.arity,
26746
+ clauses: request.clauses.map(FunctionClauseDtoFromFrontToApi)
26747
+ });
26748
+ return ReplaceFunctionResponseFromApiToFront(response.data);
26749
+ }
26482
26750
  /**
26483
26751
  * Draft a user-defined function from a natural-language description.
26484
26752
  *
@@ -27732,6 +28000,7 @@ function ClearTenantResponseFromApiToFront(dto) {
27732
28000
  sortsDeleted: dto.sorts_deleted,
27733
28001
  inferenceStateCleared: dto.inference_state_cleared,
27734
28002
  cacheInvalidated: dto.cache_invalidated,
28003
+ vectorsDeleted: dto.vectors_deleted,
27735
28004
  pluginInstallsDeleted: dto.plugin_installs_deleted
27736
28005
  };
27737
28006
  }
@@ -32896,7 +33165,14 @@ function BindingSummaryDtoFromApiToFront(dto) {
32896
33165
  keyColumns: dto.key_columns,
32897
33166
  sortId: dto.sort_id,
32898
33167
  sourceId: dto.source_id,
32899
- tableName: dto.table_name
33168
+ tableName: dto.table_name,
33169
+ keyProvenance: {
33170
+ source: dto.key_provenance.source,
33171
+ chosenBy: dto.key_provenance.chosen_by,
33172
+ explanation: dto.key_provenance.explanation,
33173
+ guaranteedUnique: dto.key_provenance.guaranteed_unique,
33174
+ durability: dto.key_provenance.durability
33175
+ }
32900
33176
  };
32901
33177
  }
32902
33178
  function ListBindingsResponseFromApiToFront(dto) {