@kortexya/reasoninglayer 1.2.0 → 1.3.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.2.0";
8
+ var SDK_VERSION = "1.3.0";
9
9
  function resolveConfig(config) {
10
10
  if (!config.baseUrl) {
11
11
  throw new Error("ClientConfig.baseUrl is required");
@@ -1062,6 +1062,20 @@ var Sorts = class {
1062
1062
  format: "json",
1063
1063
  ...params
1064
1064
  });
1065
+ /**
1066
+ * No description
1067
+ *
1068
+ * @tags sorts
1069
+ * @name SearchSortsByName
1070
+ * @request GET:/api/v1/sorts/search
1071
+ */
1072
+ searchSortsByName = (query, params = {}) => this.http.request({
1073
+ path: `/api/v1/sorts/search`,
1074
+ method: "GET",
1075
+ query,
1076
+ format: "json",
1077
+ ...params
1078
+ });
1065
1079
  /**
1066
1080
  * @description Similarity is symmetric: ∼(s₁, s₂) = ∼(s₂, s₁) Degree must be in [0, 1] range.
1067
1081
  *
@@ -1501,6 +1515,24 @@ var Inference = class {
1501
1515
  format: "json",
1502
1516
  ...params
1503
1517
  });
1518
+ /**
1519
+ * @description Phase 2 v2 entry point for retraction: 1. Removes each term from PG + in-memory stores via [`HomoiconicTermService::remove_term`](osfkb_application::services::HomoiconicTermService::remove_term). 2. When `state.use_plan_engine` is on, submits a single [`DeltaEvent::Retract`](osfkb_application::services::dataflow::DeltaEvent::Retract) to the per-tenant supervisor so the Backward/Forward backward chase decrements every dependent derived fact's `proof_count` (and deletes those whose count reaches zero). Symmetric to [`bulk_add_terms`]; idempotent (term ids absent from the working memory are silently skipped — same shape as [`delete_term`] returning 404, except in the bulk path the missing ids simply don't appear in `removed_term_ids`). Best-effort supervisor enqueue: a supervisor failure does NOT fail the 2xx response — the persist path has succeeded and a future bootstrap can recover any missed retraction. # Mid-batch error handling If `remove_term` fails for a term partway through the batch, the handler **stops accumulating successes**, runs cache invalidation for the prefix that did succeed, submits a single [`DeltaEvent::Retract`](osfkb_application::services::dataflow::DeltaEvent::Retract) covering that prefix, and **then** surfaces the error. This keeps the supervisor and the in-memory caches in sync with the actual store state — a leaked Retract event would orphan derived facts whose only antecedent is now removed, which is a critical correctness violation. # Authorization Requires `X-Tenant-Id` header. The `term_ids` are resolved against that tenant's working memory only — cross-tenant retraction is impossible by construction (the per-tenant `HomoiconicTermService` only sees its own tenant's terms).
1520
+ *
1521
+ * @tags inference
1522
+ * @name BulkRetractTerms
1523
+ * @summary Bulk-retract terms from the working memory.
1524
+ * @request POST:/api/v1/inference/facts/bulk-retract
1525
+ * @secure
1526
+ */
1527
+ bulkRetractTerms = (data, params = {}) => this.http.request({
1528
+ path: `/api/v1/inference/facts/bulk-retract`,
1529
+ method: "POST",
1530
+ body: data,
1531
+ secure: true,
1532
+ type: "application/json" /* Json */,
1533
+ format: "json",
1534
+ ...params
1535
+ });
1504
1536
  /**
1505
1537
  * @description # DEPRECATED This endpoint is deprecated. Use `DELETE /api/v1/terms/{term_id}` for individual terms. # TRUE HOMOICONIC API # Authorization Requires X-Tenant-Id header.
1506
1538
  *
@@ -7793,6 +7825,34 @@ var Admin = class {
7793
7825
  format: "json",
7794
7826
  ...params
7795
7827
  });
7828
+ /**
7829
+ * @description Truncates the derived_facts table for the given tenant and queues a BootstrapAll event covering every analyzed rule. Asynchronous: returns the queue depth and current materialization LSN, not the final state. Concurrent rebuilds for the same tenant are rejected with 409 (per-tenant mutex). Full operational runbook (prerequisites, timings, monitoring, failure recovery, known limitations) lives in .claude/SUB_MS_FORWARD_CHAINING_STATUS.md, section 'Operator runbook — derived-facts rebuild'.
7830
+ *
7831
+ * @tags admin
7832
+ * @name RebuildDerivedFacts
7833
+ * @summary Rebuild derived facts for a tenant
7834
+ * @request POST:/api/v1/admin/derived-facts/rebuild/{tenant_id}
7835
+ */
7836
+ rebuildDerivedFacts = (tenantId, params = {}) => this.http.request({
7837
+ path: `/api/v1/admin/derived-facts/rebuild/${tenantId}`,
7838
+ method: "POST",
7839
+ format: "json",
7840
+ ...params
7841
+ });
7842
+ /**
7843
+ * @description Returns event-processing counters (submitted/processed/failed/in-flight), the materialization LSN, the last handler error (if any, truncated to 512 chars), the per-tenant materialization sentinel, the current derived-facts row count, and a racy hint about whether a rebuild is in flight. Intended for operator dashboards; the supervisor itself does not depend on this endpoint.
7844
+ *
7845
+ * @tags admin
7846
+ * @name SupervisorStatus
7847
+ * @summary Get per-tenant supervisor + materialization status
7848
+ * @request GET:/api/v1/admin/derived-facts/status/{tenant_id}
7849
+ */
7850
+ supervisorStatus = (tenantId, params = {}) => this.http.request({
7851
+ path: `/api/v1/admin/derived-facts/status/${tenantId}`,
7852
+ method: "GET",
7853
+ format: "json",
7854
+ ...params
7855
+ });
7796
7856
  };
7797
7857
 
7798
7858
  // src/api-spec/generated/ImageExtraction.ts
@@ -20662,17 +20722,17 @@ function compileLinearExpression(expression, varRefs, nextVar) {
20662
20722
  const termResults = [];
20663
20723
  for (const [varName, coefficient] of Object.entries(expression)) {
20664
20724
  if (coefficient === 0) continue;
20665
- const varRef = varRefs[varName];
20666
- if (!varRef) continue;
20725
+ const varRef2 = varRefs[varName];
20726
+ if (!varRef2) continue;
20667
20727
  if (coefficient === 1) {
20668
- termResults.push(varRef);
20728
+ termResults.push(varRef2);
20669
20729
  } else {
20670
20730
  const resultVar = { name: nextVar() };
20671
20731
  antecedents.push({
20672
20732
  sortName: "real_times_constraint",
20673
20733
  features: {
20674
20734
  coefficient: numericTerm(coefficient),
20675
- variable: varRef,
20735
+ variable: varRef2,
20676
20736
  result: resultVar
20677
20737
  }
20678
20738
  });
@@ -23783,6 +23843,229 @@ function allen(relation, intervalA, intervalBTermId) {
23783
23843
  };
23784
23844
  }
23785
23845
 
23846
+ // src/builders/flow.ts
23847
+ function nodeVar(name) {
23848
+ const sanitized = name.replace(/[^A-Za-z0-9_]/g, "_");
23849
+ return { name: `?N_${sanitized}` };
23850
+ }
23851
+ function varRef(name) {
23852
+ return { name };
23853
+ }
23854
+ function freshVar(prefix, counter) {
23855
+ const name = `?${prefix}${counter.n}`;
23856
+ counter.n += 1;
23857
+ return name;
23858
+ }
23859
+ function normaliseEdge(e) {
23860
+ if (Array.isArray(e)) {
23861
+ const [from, to, cap, options] = e;
23862
+ return { from, to, cap, ...options ?? {} };
23863
+ }
23864
+ return e;
23865
+ }
23866
+ function buildEdges(edges, counter) {
23867
+ const edgeTerms = [];
23868
+ const edgeFlows = [];
23869
+ for (const raw of edges) {
23870
+ const e = normaliseEdge(raw);
23871
+ const flowVar = e.flow ?? freshVar("F", counter);
23872
+ edgeFlows.push({ from: e.from, to: e.to, var: flowVar });
23873
+ const features = {
23874
+ src: nodeVar(e.from),
23875
+ dst: nodeVar(e.to),
23876
+ cap: e.cap,
23877
+ flow: varRef(flowVar)
23878
+ };
23879
+ if (e.cost != null) features.cost = e.cost;
23880
+ if (e.label != null) features.label = e.label;
23881
+ edgeTerms.push(psi("flow_edge_constraint", features));
23882
+ }
23883
+ return { edgeTerms, edgeFlows };
23884
+ }
23885
+ function solveTerm(source, sink) {
23886
+ return psi("flow_solve_constraint", {
23887
+ source: nodeVar(source),
23888
+ sink: nodeVar(sink)
23889
+ });
23890
+ }
23891
+ var Flow = {
23892
+ /**
23893
+ * Build a max-flow problem.
23894
+ *
23895
+ * Emits one `flow_edge_constraint` per edge, one
23896
+ * `flow_max_constraint` with the requested output binding, and a
23897
+ * `flow_solve_constraint` trigger. Returns the constraint terms
23898
+ * plus the names of every output variable.
23899
+ */
23900
+ maxFlow(input) {
23901
+ const counter = { n: 0 };
23902
+ const { edgeTerms, edgeFlows } = buildEdges(input.edges, counter);
23903
+ const flowValue = input.flowValue ?? freshVar("V_flow", counter);
23904
+ const constraints = [
23905
+ ...edgeTerms,
23906
+ psi("flow_max_constraint", {
23907
+ source: nodeVar(input.source),
23908
+ sink: nodeVar(input.sink),
23909
+ flow_value: varRef(flowValue)
23910
+ }),
23911
+ solveTerm(input.source, input.sink)
23912
+ ];
23913
+ return { constraints, vars: { flowValue, edgeFlows } };
23914
+ },
23915
+ /**
23916
+ * Build a min-cut problem.
23917
+ *
23918
+ * Emits `flow_min_cut_constraint` and binds `cut_value`,
23919
+ * `cut_edges`, `source_side`, `sink_side` to the requested
23920
+ * variable names (auto-generated when omitted).
23921
+ */
23922
+ minCut(input) {
23923
+ const counter = { n: 0 };
23924
+ const { edgeTerms, edgeFlows } = buildEdges(input.edges, counter);
23925
+ const cutValue = input.cutValue ?? freshVar("CutValue", counter);
23926
+ const cutEdges = input.cutEdges ?? freshVar("CutEdges", counter);
23927
+ const sourceSide = input.sourceSide ?? freshVar("SrcSide", counter);
23928
+ const sinkSide = input.sinkSide ?? freshVar("SnkSide", counter);
23929
+ const constraints = [
23930
+ ...edgeTerms,
23931
+ psi("flow_min_cut_constraint", {
23932
+ source: nodeVar(input.source),
23933
+ sink: nodeVar(input.sink),
23934
+ cut_value: varRef(cutValue),
23935
+ cut_edges: varRef(cutEdges),
23936
+ source_side: varRef(sourceSide),
23937
+ sink_side: varRef(sinkSide)
23938
+ }),
23939
+ solveTerm(input.source, input.sink)
23940
+ ];
23941
+ return {
23942
+ constraints,
23943
+ vars: { cutValue, cutEdges, sourceSide, sinkSide, edgeFlows }
23944
+ };
23945
+ },
23946
+ /**
23947
+ * Build a min-cost-max-flow problem. Per-edge `cost` is required
23948
+ * for the optimisation to be meaningful (defaults to 0 if absent).
23949
+ */
23950
+ minCostMaxFlow(input) {
23951
+ const counter = { n: 0 };
23952
+ const { edgeTerms, edgeFlows } = buildEdges(input.edges, counter);
23953
+ const flowValue = input.flowValue ?? freshVar("V_flow", counter);
23954
+ const totalCost = input.totalCost ?? freshVar("Cost", counter);
23955
+ const constraints = [
23956
+ ...edgeTerms,
23957
+ psi("flow_min_cost_max_flow_constraint", {
23958
+ source: nodeVar(input.source),
23959
+ sink: nodeVar(input.sink),
23960
+ flow_value: varRef(flowValue),
23961
+ total_cost: varRef(totalCost)
23962
+ }),
23963
+ solveTerm(input.source, input.sink)
23964
+ ];
23965
+ return { constraints, vars: { flowValue, totalCost, edgeFlows } };
23966
+ },
23967
+ /**
23968
+ * Build a Dulmage-Mendelsohn edge-classification problem.
23969
+ *
23970
+ * Each edge is classified as `"always"`, `"never"`, or
23971
+ * `"sometimes"` used across the space of all max flows (or all
23972
+ * min-cost max flows when `optimal: true`).
23973
+ */
23974
+ classifyEdges(input) {
23975
+ const counter = { n: 0 };
23976
+ const { edgeTerms, edgeFlows } = buildEdges(input.edges, counter);
23977
+ const classifications = input.classifications ?? freshVar("Classes", counter);
23978
+ const objectiveFeatures = {
23979
+ source: nodeVar(input.source),
23980
+ sink: nodeVar(input.sink),
23981
+ classifications: varRef(classifications)
23982
+ };
23983
+ if (input.optimal) objectiveFeatures.optimal = true;
23984
+ const constraints = [
23985
+ ...edgeTerms,
23986
+ psi("flow_classify_edges_constraint", objectiveFeatures),
23987
+ solveTerm(input.source, input.sink)
23988
+ ];
23989
+ return { constraints, vars: { classifications, edgeFlows } };
23990
+ },
23991
+ /** Low-level: build a single `flow_edge_constraint` psi-term. */
23992
+ edge(from, to, cap, options = {}) {
23993
+ const features = {
23994
+ src: nodeVar(from),
23995
+ dst: nodeVar(to),
23996
+ cap
23997
+ };
23998
+ if (options.flow) features.flow = varRef(options.flow);
23999
+ if (options.cost != null) features.cost = options.cost;
24000
+ if (options.label != null) features.label = options.label;
24001
+ return psi("flow_edge_constraint", features);
24002
+ },
24003
+ /** Low-level: build a single `flow_solve_constraint` psi-term. */
24004
+ solve(source, sink) {
24005
+ return solveTerm(source, sink);
24006
+ },
24007
+ /**
24008
+ * Low-level: build a single `flow_max_constraint` psi-term.
24009
+ *
24010
+ * @example
24011
+ * ```typescript
24012
+ * const constraints = [
24013
+ * Flow.edge('s', 'a', 10),
24014
+ * Flow.edge('a', 't', 10),
24015
+ * Flow.maxObjective({ source: 's', sink: 't', flowValue: '?V' }),
24016
+ * Flow.solve('s', 't'),
24017
+ * ];
24018
+ * ```
24019
+ */
24020
+ maxObjective(opts) {
24021
+ return psi("flow_max_constraint", {
24022
+ source: nodeVar(opts.source),
24023
+ sink: nodeVar(opts.sink),
24024
+ flow_value: varRef(opts.flowValue)
24025
+ });
24026
+ },
24027
+ /** Low-level: build a single `flow_min_cut_constraint` psi-term. */
24028
+ minCutObjective(opts) {
24029
+ return psi("flow_min_cut_constraint", {
24030
+ source: nodeVar(opts.source),
24031
+ sink: nodeVar(opts.sink),
24032
+ cut_value: varRef(opts.cutValue),
24033
+ cut_edges: varRef(opts.cutEdges),
24034
+ source_side: varRef(opts.sourceSide),
24035
+ sink_side: varRef(opts.sinkSide)
24036
+ });
24037
+ },
24038
+ /** Low-level: build a single `flow_min_cost_max_flow_constraint` psi-term. */
24039
+ minCostMaxFlowObjective(opts) {
24040
+ return psi("flow_min_cost_max_flow_constraint", {
24041
+ source: nodeVar(opts.source),
24042
+ sink: nodeVar(opts.sink),
24043
+ flow_value: varRef(opts.flowValue),
24044
+ total_cost: varRef(opts.totalCost)
24045
+ });
24046
+ },
24047
+ /** Low-level: build a single `flow_classify_edges_constraint` psi-term. */
24048
+ classifyEdgesObjective(opts) {
24049
+ const features = {
24050
+ source: nodeVar(opts.source),
24051
+ sink: nodeVar(opts.sink),
24052
+ classifications: varRef(opts.classifications)
24053
+ };
24054
+ if (opts.optimal) features.optimal = true;
24055
+ return psi("flow_classify_edges_constraint", features);
24056
+ },
24057
+ /**
24058
+ * Low-level: get the node-variable reference used to identify a
24059
+ * node name in goals built by this builder. Exposed so callers
24060
+ * composing constraints by hand can refer to the same logical node
24061
+ * the high-level helpers would produce — e.g., to add a feature
24062
+ * test on the same node term inside the same goal.
24063
+ */
24064
+ node(name) {
24065
+ return nodeVar(name);
24066
+ }
24067
+ };
24068
+
23786
24069
  // src/utils/discrimination.ts
23787
24070
  var UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
23788
24071
  function isUuid(s) {
@@ -23809,6 +24092,6 @@ function discriminateFeatureValue(value) {
23809
24092
  );
23810
24093
  }
23811
24094
 
23812
- export { ANY_ROLE, action_reviews_exports as ActionReviews, admin_exports as Admin, analysis_exports as Analysis, ApiError, AuthenticationError, BadRequestError, cdl_exports as CDL, causal_exports as Causal, cognitive_exports as Cognitive, collections_exports as Collections, communities_exports as Communities, compliance_exports as Compliance, ConstraintViolationError, constraints_exports as Constraints, control_exports as Control, conversation_exports as Conversation, discovery_exports as Discovery, execution_exports as Execution, extract_exports as Extract, flow_networks_exports as FlowNetworks, ForbiddenError, functions_exports as Functions, fuzzy_exports as Fuzzy, FuzzyShape, generation_exports as Generation, health_exports as Health, homoiconic_exports as Homoiconic, ilp_exports as ILP, image_extraction_exports as ImageExtraction, inference_exports as Inference, ingestion_exports as Ingestion, IngestionFailedError, IngestionSession, InternalServerError, LP, namespaces_exports as Namespaces, NetworkError, neuro_symbolic_exports as NeuroSymbolic, NotFoundError, ontology_exports as Ontology, operations_exports as Operations, optimize_exports as Optimize, osfql_exports as Osfql, oversight_exports as Oversight, plain_values_exports as PlainValues, preferences_exports as Preferences, proof_engine_exports as ProofEngine, query_exports as Query, rag_exports as RAG, RateLimitError, reasoning_exports as Reasoning, ReasoningLayerClient, ReasoningLayerError, research_exports as Research, reviews_exports as Reviews, row_exports as Row, SDK_VERSION, scenarios_exports as Scenarios, scheduling_exports as Scheduling, SortBuilder, sorts_exports as Sorts, sources_exports as Sources, spaces_exports as Spaces, statistical_exports as Statistical, synthetic_exports as Synthetic, terms_exports as Terms, TimeoutError, utilities_exports as Utilities, ValidationError, Value, values_exports as Values, visualization_exports as Visualization, WebSocketClient, WebSocketConnection, webhook_actions_exports as WebhookActions, allen, constrained, discriminateFeatureValue, guard, isConstrainedPlainVar, isPsiTermInput, isTaggedValueDto, isUuid, psi, toTaggedFeatures, toTaggedValue, toTermInputDto, toUntaggedFeatures, toUntaggedValue };
24095
+ export { ANY_ROLE, action_reviews_exports as ActionReviews, admin_exports as Admin, analysis_exports as Analysis, ApiError, AuthenticationError, BadRequestError, cdl_exports as CDL, causal_exports as Causal, cognitive_exports as Cognitive, collections_exports as Collections, communities_exports as Communities, compliance_exports as Compliance, ConstraintViolationError, constraints_exports as Constraints, control_exports as Control, conversation_exports as Conversation, discovery_exports as Discovery, execution_exports as Execution, extract_exports as Extract, Flow, flow_networks_exports as FlowNetworks, ForbiddenError, functions_exports as Functions, fuzzy_exports as Fuzzy, FuzzyShape, generation_exports as Generation, health_exports as Health, homoiconic_exports as Homoiconic, ilp_exports as ILP, image_extraction_exports as ImageExtraction, inference_exports as Inference, ingestion_exports as Ingestion, IngestionFailedError, IngestionSession, InternalServerError, LP, namespaces_exports as Namespaces, NetworkError, neuro_symbolic_exports as NeuroSymbolic, NotFoundError, ontology_exports as Ontology, operations_exports as Operations, optimize_exports as Optimize, osfql_exports as Osfql, oversight_exports as Oversight, plain_values_exports as PlainValues, preferences_exports as Preferences, proof_engine_exports as ProofEngine, query_exports as Query, rag_exports as RAG, RateLimitError, reasoning_exports as Reasoning, ReasoningLayerClient, ReasoningLayerError, research_exports as Research, reviews_exports as Reviews, row_exports as Row, SDK_VERSION, scenarios_exports as Scenarios, scheduling_exports as Scheduling, SortBuilder, sorts_exports as Sorts, sources_exports as Sources, spaces_exports as Spaces, statistical_exports as Statistical, synthetic_exports as Synthetic, terms_exports as Terms, TimeoutError, utilities_exports as Utilities, ValidationError, Value, values_exports as Values, visualization_exports as Visualization, WebSocketClient, WebSocketConnection, webhook_actions_exports as WebhookActions, allen, constrained, discriminateFeatureValue, guard, isConstrainedPlainVar, isPsiTermInput, isTaggedValueDto, isUuid, psi, toTaggedFeatures, toTaggedValue, toTermInputDto, toUntaggedFeatures, toUntaggedValue };
23813
24096
  //# sourceMappingURL=index.js.map
23814
24097
  //# sourceMappingURL=index.js.map