@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.cjs CHANGED
@@ -7,7 +7,7 @@ var __export = (target, all) => {
7
7
  };
8
8
 
9
9
  // src/config.ts
10
- var SDK_VERSION = "1.24.0";
10
+ var SDK_VERSION = "1.26.0";
11
11
  function resolveConfig(config) {
12
12
  if (!config.baseUrl) {
13
13
  throw new Error("ClientConfig.baseUrl is required");
@@ -8440,6 +8440,23 @@ var Functions = class {
8440
8440
  constructor(http) {
8441
8441
  this.http = http;
8442
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
+ });
8443
8460
  /**
8444
8461
  * @description Never writes to the KB — returns a validated draft for human review.
8445
8462
  *
@@ -8476,6 +8493,22 @@ var Functions = class {
8476
8493
  format: "json",
8477
8494
  ...params
8478
8495
  });
8496
+ /**
8497
+ * @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.
8498
+ *
8499
+ * @tags functions
8500
+ * @name GetFunction
8501
+ * @summary Read one registered function's definition.
8502
+ * @request GET:/api/v1/functions/{name}
8503
+ * @secure
8504
+ */
8505
+ getFunction = (name, params = {}) => this.http.request({
8506
+ path: `/api/v1/functions/${name}`,
8507
+ method: "GET",
8508
+ secure: true,
8509
+ format: "json",
8510
+ ...params
8511
+ });
8479
8512
  /**
8480
8513
  * @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.
8481
8514
  *
@@ -8510,6 +8543,24 @@ var Functions = class {
8510
8543
  format: "json",
8511
8544
  ...params
8512
8545
  });
8546
+ /**
8547
+ * @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.
8548
+ *
8549
+ * @tags functions
8550
+ * @name ReplaceFunction
8551
+ * @summary Replace a registered function's definition.
8552
+ * @request PUT:/api/v1/functions/{name}
8553
+ * @secure
8554
+ */
8555
+ replaceFunction = (name, data, params = {}) => this.http.request({
8556
+ path: `/api/v1/functions/${name}`,
8557
+ method: "PUT",
8558
+ body: data,
8559
+ secure: true,
8560
+ type: "application/json",
8561
+ format: "json",
8562
+ ...params
8563
+ });
8513
8564
  };
8514
8565
 
8515
8566
  // src/api-spec/generated/WebhookActions.ts
@@ -14332,7 +14383,13 @@ function RuleEntryDtoFromApiToFront(dto) {
14332
14383
  ruleId: dto.rule_id,
14333
14384
  head: PsiTermDtoFromApiToFront(dto.head),
14334
14385
  body: dto.body.map(PsiTermDtoFromApiToFront),
14335
- certainty: dto.certainty ?? void 0
14386
+ certainty: dto.certainty ?? void 0,
14387
+ origin: dto.origin,
14388
+ withdrawable: dto.withdrawable,
14389
+ notWithdrawable: dto.not_withdrawable ? {
14390
+ code: dto.not_withdrawable.code,
14391
+ reason: dto.not_withdrawable.reason
14392
+ } : void 0
14336
14393
  };
14337
14394
  }
14338
14395
  function GetRulesResponseFromApiToFront(dto) {
@@ -15231,7 +15288,8 @@ function FindBySortRequestFromFrontToApi(model) {
15231
15288
  return {
15232
15289
  sort_id: model.sortId ?? void 0,
15233
15290
  sort_name: model.sortName ?? void 0,
15234
- filter: model.filter ?? void 0
15291
+ filter: model.filter ?? void 0,
15292
+ limit: model.limit ?? void 0
15235
15293
  };
15236
15294
  }
15237
15295
  function OsfSearchRequestFromFrontToApi(model) {
@@ -17403,7 +17461,7 @@ var ConstraintsClient = class {
17403
17461
  type: "application/json",
17404
17462
  format: "json"
17405
17463
  });
17406
- return response.data;
17464
+ return ConstraintGraphResponseFromApiToFront(response.data);
17407
17465
  }
17408
17466
  // --- Session Management ---
17409
17467
  /**
@@ -23478,9 +23536,11 @@ function StructuredIngestionStatsDtoFromApiToFront(dto) {
23478
23536
  elapsedMs: dto.elapsed_ms,
23479
23537
  entitiesCreated: dto.entities_created,
23480
23538
  entitiesExtracted: dto.entities_extracted,
23539
+ recordsAvailable: dto.records_available,
23481
23540
  recordsProcessed: dto.records_processed,
23482
23541
  relationsCreated: dto.relations_created,
23483
23542
  relationsDiscovered: dto.relations_discovered,
23543
+ rowsCollapsed: dto.rows_collapsed,
23484
23544
  sortsCreated: dto.sorts_created,
23485
23545
  tablesDiscovered: dto.tables_discovered,
23486
23546
  termsCreated: dto.terms_created,
@@ -26131,6 +26191,23 @@ function ExpressionDtoFromFrontToApi(model) {
26131
26191
  right: ExpressionDtoFromFrontToApi(model.right)
26132
26192
  };
26133
26193
  }
26194
+ if (model.type === "UnaryOp") {
26195
+ return {
26196
+ type: "UnaryOp",
26197
+ op: model.op,
26198
+ operand: ExpressionDtoFromFrontToApi(model.operand)
26199
+ };
26200
+ }
26201
+ if (model.type === "Conditional") {
26202
+ return {
26203
+ type: "Conditional",
26204
+ branches: model.branches.map((b) => ({
26205
+ when: ExpressionDtoFromFrontToApi(b.when),
26206
+ then: ExpressionDtoFromFrontToApi(b.then)
26207
+ })),
26208
+ default: model.default ? ExpressionDtoFromFrontToApi(model.default) : model.default
26209
+ };
26210
+ }
26134
26211
  return model;
26135
26212
  }
26136
26213
  function ExpressionDtoFromApiToFront(dto) {
@@ -26149,6 +26226,23 @@ function ExpressionDtoFromApiToFront(dto) {
26149
26226
  right: ExpressionDtoFromApiToFront(dto.right)
26150
26227
  };
26151
26228
  }
26229
+ if (dto.type === "UnaryOp") {
26230
+ return {
26231
+ type: "UnaryOp",
26232
+ op: dto.op,
26233
+ operand: ExpressionDtoFromApiToFront(dto.operand)
26234
+ };
26235
+ }
26236
+ if (dto.type === "Conditional") {
26237
+ return {
26238
+ type: "Conditional",
26239
+ branches: dto.branches.map((b) => ({
26240
+ when: ExpressionDtoFromApiToFront(b.when),
26241
+ then: ExpressionDtoFromApiToFront(b.then)
26242
+ })),
26243
+ default: dto.default ? ExpressionDtoFromApiToFront(dto.default) : dto.default
26244
+ };
26245
+ }
26152
26246
  return dto;
26153
26247
  }
26154
26248
  function FunctionBodyDtoFromFrontToApi(model) {
@@ -26337,6 +26431,54 @@ function DraftFunctionResponseFromApiToFront(dto) {
26337
26431
  warnings: dto.warnings
26338
26432
  };
26339
26433
  }
26434
+ function FunctionCallerFromApiToFront(dto) {
26435
+ return {
26436
+ kind: dto.kind,
26437
+ name: dto.name,
26438
+ termId: dto.term_id ?? void 0
26439
+ };
26440
+ }
26441
+ function FunctionWithdrawalReportFromApiToFront(dto) {
26442
+ return {
26443
+ name: dto.name,
26444
+ functionId: dto.function_id,
26445
+ carrierDeleted: dto.carrier_deleted,
26446
+ deregistered: dto.deregistered,
26447
+ // The wire omits the field when nothing was orphaned; the SDK always
26448
+ // hands back an array, so a caller never has to guard the read.
26449
+ callersOrphaned: (dto.callers_orphaned ?? []).map(FunctionCallerFromApiToFront)
26450
+ };
26451
+ }
26452
+ function ReplaceFunctionResponseFromApiToFront(dto) {
26453
+ return {
26454
+ name: dto.name,
26455
+ functionId: dto.function_id,
26456
+ previous: FunctionSummaryDtoFromApiToFront(dto.previous),
26457
+ current: FunctionSummaryDtoFromApiToFront(dto.current),
26458
+ arityChanged: dto.arity_changed,
26459
+ callers: (dto.callers ?? []).map(FunctionCallerFromApiToFront)
26460
+ };
26461
+ }
26462
+ function GetFunctionResponseFromApiToFront(dto) {
26463
+ const signature = {
26464
+ name: dto.name,
26465
+ functionId: dto.function_id,
26466
+ arity: dto.arity,
26467
+ kind: dto.kind,
26468
+ replaceable: dto.replaceable,
26469
+ notReplaceable: dto.not_replaceable ?? void 0,
26470
+ // The wire omits the field when nothing calls it; the SDK always hands
26471
+ // back an array, as the withdrawal report already does.
26472
+ callers: (dto.callers ?? []).map(FunctionCallerFromApiToFront)
26473
+ };
26474
+ if (dto.clauses == null) {
26475
+ return {
26476
+ ...signature,
26477
+ unrepresentable: dto.unrepresentable ?? "The engine returned no clauses for this function and gave no reason."
26478
+ };
26479
+ }
26480
+ return { ...signature, clauses: dto.clauses.map(FunctionClauseDtoFromApiToFront) };
26481
+ }
26340
26482
 
26341
26483
  // src/resources/functions.ts
26342
26484
  var FunctionsClient = class {
@@ -26400,7 +26542,9 @@ var FunctionsClient = class {
26400
26542
  * ```
26401
26543
  */
26402
26544
  async registerFunction(request) {
26403
- const response = await this.api.registerFunction(RegisterFunctionRequestFromFrontToApi(request));
26545
+ const response = await this.api.registerFunction(
26546
+ RegisterFunctionRequestFromFrontToApi(request)
26547
+ );
26404
26548
  return RegisterFunctionResponseFromApiToFront(response.data);
26405
26549
  }
26406
26550
  /**
@@ -26451,7 +26595,9 @@ var FunctionsClient = class {
26451
26595
  * ```
26452
26596
  */
26453
26597
  async evaluateFunction(request) {
26454
- const response = await this.api.evaluateFunction(EvaluateFunctionRequestFromFrontToApi(request));
26598
+ const response = await this.api.evaluateFunction(
26599
+ EvaluateFunctionRequestFromFrontToApi(request)
26600
+ );
26455
26601
  return EvaluateFunctionResponseFromApiToFront(response.data);
26456
26602
  }
26457
26603
  /**
@@ -26481,6 +26627,128 @@ var FunctionsClient = class {
26481
26627
  const response = await this.api.listFunctions();
26482
26628
  return ListFunctionsResponseFromApiToFront(response.data);
26483
26629
  }
26630
+ /**
26631
+ * Read one registered function's definition.
26632
+ *
26633
+ * @param name - The registered function's name — its identity.
26634
+ * @returns The signature, everything that calls it, whether a `PUT` would
26635
+ * act or refuse, and the clauses in the shape a replacement takes.
26636
+ * @throws {ApiError} 404 if nothing is registered under that name for the
26637
+ * authenticated tenant. Another tenant's function is 404 too — saying
26638
+ * anything else would confirm the name exists somewhere.
26639
+ *
26640
+ * @remarks
26641
+ * This is what makes {@link FunctionsClient.replaceFunction} an edit. `PUT`
26642
+ * replaces the WHOLE definition, so without a read a client fixing one
26643
+ * clause of a three-clause function had to re-author the other two from
26644
+ * memory, and any it forgot were deleted.
26645
+ *
26646
+ * `clauses` and `unrepresentable` are exclusive: a definition holding a
26647
+ * construct the register shape cannot express comes back with no clauses and
26648
+ * a reason, because a degraded read written back would destroy the real
26649
+ * definition. Narrow on `clauses === undefined` before using them.
26650
+ *
26651
+ * A plugin-contributed function is refused by `DELETE`/`PUT` and returned
26652
+ * here, with `replaceable: false` and the refusal the mutation would give.
26653
+ *
26654
+ * @example
26655
+ * ```typescript
26656
+ * const definition = await client.functions.getFunction('scale');
26657
+ * if (definition.clauses === undefined) {
26658
+ * throw new Error(`scale cannot be edited: ${definition.unrepresentable}`);
26659
+ * }
26660
+ * if (!definition.replaceable) {
26661
+ * throw new Error(definition.notReplaceable?.reason);
26662
+ * }
26663
+ * await client.functions.replaceFunction('scale', {
26664
+ * arity: definition.arity,
26665
+ * clauses: definition.clauses.map(tweak),
26666
+ * });
26667
+ * ```
26668
+ */
26669
+ async getFunction(name) {
26670
+ const response = await this.api.getFunction(name);
26671
+ return GetFunctionResponseFromApiToFront(response.data);
26672
+ }
26673
+ /**
26674
+ * Withdraw a registered function.
26675
+ *
26676
+ * @param name - The registered function's name — its identity.
26677
+ * @param options - `callers` decides what happens to the things that call
26678
+ * it. Defaults to `'refuse'`.
26679
+ * @returns What the withdrawal removed, in each representation that held it.
26680
+ * @throws {ApiError} 400 if something still calls the function under the
26681
+ * default `'refuse'` (the body carries `code: 'function_has_callers'` and
26682
+ * the caller list); 403 for a plugin-contributed function; 404 if nothing
26683
+ * is registered under that name.
26684
+ *
26685
+ * @remarks
26686
+ * A function is carried twice — the durable `meta.function` carrier that is
26687
+ * the source of truth, and the evaluator's own registry used for dispatch
26688
+ * and recursive cross-calls — and the report names both, because forgetting
26689
+ * either leaves it half-alive: still evaluable, or back after a restart.
26690
+ *
26691
+ * `'refuse'` names every caller; `'orphan'` withdraws anyway and reports the
26692
+ * callers left naming something that no longer resolves.
26693
+ *
26694
+ * @example
26695
+ * ```typescript
26696
+ * const report = await client.functions.deleteFunction('scale', { callers: 'orphan' });
26697
+ * for (const orphan of report.callersOrphaned) {
26698
+ * console.warn(`${orphan.kind} ${orphan.name} now calls a function that is gone`);
26699
+ * }
26700
+ * ```
26701
+ */
26702
+ async deleteFunction(name, options) {
26703
+ const response = await this.api.deleteFunction(
26704
+ name,
26705
+ options?.callers === void 0 ? void 0 : { callers: options.callers }
26706
+ );
26707
+ return FunctionWithdrawalReportFromApiToFront(response.data);
26708
+ }
26709
+ /**
26710
+ * Replace a registered function's definition.
26711
+ *
26712
+ * @param name - The registered function's name. Unchanged by the
26713
+ * replacement — the name IS the identity.
26714
+ * @param request - The replacement's arity and clauses.
26715
+ * @returns Both signatures, whether the arity moved, and everything that
26716
+ * calls the function.
26717
+ * @throws {ApiError} 400 if the replacement's clauses are rejected — in
26718
+ * which case the registration is left exactly as it was; 403 for a
26719
+ * plugin-contributed function; 404 if nothing is registered under that
26720
+ * name (creating one is {@link FunctionsClient.registerFunction}'s job).
26721
+ *
26722
+ * @remarks
26723
+ * `registerFunction` already replaces by name — silently, reporting nothing
26724
+ * about what it displaced. This is the operation that says so.
26725
+ *
26726
+ * A function's identity is its NAME, so a replacement keeps every caller's
26727
+ * reference valid: nothing dangles. That is exactly why an arity change is
26728
+ * the dangerous edit — every call still resolves, and one passing the old
26729
+ * argument count starts failing at evaluation time. `arityChanged` is
26730
+ * reported rather than refused, because a caller may be replacing the
26731
+ * function precisely because its signature was wrong.
26732
+ *
26733
+ * @example
26734
+ * ```typescript
26735
+ * const result = await client.functions.replaceFunction('scale', {
26736
+ * arity: 2,
26737
+ * clauses: [multiplyClause],
26738
+ * });
26739
+ * if (result.arityChanged) {
26740
+ * console.warn(`arity ${result.previous.arity} -> ${result.current.arity};`,
26741
+ * `${result.callers.length} caller(s) were written against the old one`);
26742
+ * }
26743
+ * ```
26744
+ */
26745
+ async replaceFunction(name, request) {
26746
+ const response = await this.api.replaceFunction(name, {
26747
+ arity: request.arity,
26748
+ clauses: request.clauses.map(FunctionClauseDtoFromFrontToApi)
26749
+ });
26750
+ return ReplaceFunctionResponseFromApiToFront(response.data);
26751
+ }
26484
26752
  /**
26485
26753
  * Draft a user-defined function from a natural-language description.
26486
26754
  *
@@ -27734,6 +28002,7 @@ function ClearTenantResponseFromApiToFront(dto) {
27734
28002
  sortsDeleted: dto.sorts_deleted,
27735
28003
  inferenceStateCleared: dto.inference_state_cleared,
27736
28004
  cacheInvalidated: dto.cache_invalidated,
28005
+ vectorsDeleted: dto.vectors_deleted,
27737
28006
  pluginInstallsDeleted: dto.plugin_installs_deleted
27738
28007
  };
27739
28008
  }
@@ -32898,7 +33167,14 @@ function BindingSummaryDtoFromApiToFront(dto) {
32898
33167
  keyColumns: dto.key_columns,
32899
33168
  sortId: dto.sort_id,
32900
33169
  sourceId: dto.source_id,
32901
- tableName: dto.table_name
33170
+ tableName: dto.table_name,
33171
+ keyProvenance: {
33172
+ source: dto.key_provenance.source,
33173
+ chosenBy: dto.key_provenance.chosen_by,
33174
+ explanation: dto.key_provenance.explanation,
33175
+ guaranteedUnique: dto.key_provenance.guaranteed_unique,
33176
+ durability: dto.key_provenance.durability
33177
+ }
32902
33178
  };
32903
33179
  }
32904
33180
  function ListBindingsResponseFromApiToFront(dto) {