@kortexya/reasoninglayer 1.2.1 → 1.4.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 +465 -31
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +693 -7
- package/dist/index.d.ts +693 -7
- package/dist/index.js +464 -32
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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.
|
|
8
|
+
var SDK_VERSION = "1.4.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
|
|
@@ -9008,6 +9068,7 @@ var TAGGED_VALUE_TYPES = /* @__PURE__ */ new Set([
|
|
|
9008
9068
|
"Boolean",
|
|
9009
9069
|
"Uninstantiated",
|
|
9010
9070
|
"Reference",
|
|
9071
|
+
"SortId",
|
|
9011
9072
|
"List",
|
|
9012
9073
|
"FuzzyScalar",
|
|
9013
9074
|
"FuzzyNumber",
|
|
@@ -9103,6 +9164,12 @@ function toUntaggedValue(value) {
|
|
|
9103
9164
|
};
|
|
9104
9165
|
}
|
|
9105
9166
|
if (isTaggedValueDto(value)) {
|
|
9167
|
+
if (value.type === "Reference") {
|
|
9168
|
+
return { termId: value.value };
|
|
9169
|
+
}
|
|
9170
|
+
if (value.type === "SortId") {
|
|
9171
|
+
return { sortRef: value.value };
|
|
9172
|
+
}
|
|
9106
9173
|
return value;
|
|
9107
9174
|
}
|
|
9108
9175
|
return value;
|
|
@@ -9515,6 +9582,9 @@ function FeatureInputValueDtoFromFrontToApi(value) {
|
|
|
9515
9582
|
...features ? { features } : {}
|
|
9516
9583
|
};
|
|
9517
9584
|
}
|
|
9585
|
+
if ("sortRef" in value) {
|
|
9586
|
+
return { sort_ref: value.sortRef };
|
|
9587
|
+
}
|
|
9518
9588
|
return { term_id: value.termId };
|
|
9519
9589
|
}
|
|
9520
9590
|
function featuresInputFromFrontToApi(features) {
|
|
@@ -20662,17 +20732,17 @@ function compileLinearExpression(expression, varRefs, nextVar) {
|
|
|
20662
20732
|
const termResults = [];
|
|
20663
20733
|
for (const [varName, coefficient] of Object.entries(expression)) {
|
|
20664
20734
|
if (coefficient === 0) continue;
|
|
20665
|
-
const
|
|
20666
|
-
if (!
|
|
20735
|
+
const varRef2 = varRefs[varName];
|
|
20736
|
+
if (!varRef2) continue;
|
|
20667
20737
|
if (coefficient === 1) {
|
|
20668
|
-
termResults.push(
|
|
20738
|
+
termResults.push(varRef2);
|
|
20669
20739
|
} else {
|
|
20670
20740
|
const resultVar = { name: nextVar() };
|
|
20671
20741
|
antecedents.push({
|
|
20672
20742
|
sortName: "real_times_constraint",
|
|
20673
20743
|
features: {
|
|
20674
20744
|
coefficient: numericTerm(coefficient),
|
|
20675
|
-
variable:
|
|
20745
|
+
variable: varRef2,
|
|
20676
20746
|
result: resultVar
|
|
20677
20747
|
}
|
|
20678
20748
|
});
|
|
@@ -20775,7 +20845,12 @@ var OptimizeClient = class {
|
|
|
20775
20845
|
sorts: [{ name: solutionSortName, parents: ["thing"] }]
|
|
20776
20846
|
});
|
|
20777
20847
|
const sortIdsMap = sortResponse.data.sort_ids;
|
|
20778
|
-
sortId =
|
|
20848
|
+
sortId = sortIdsMap[solutionSortName];
|
|
20849
|
+
if (!sortId) {
|
|
20850
|
+
throw new Error(
|
|
20851
|
+
`bulkCreateSorts did not return an id for '${solutionSortName}' (returned: ${Object.keys(sortIdsMap).join(", ")})`
|
|
20852
|
+
);
|
|
20853
|
+
}
|
|
20779
20854
|
const ruleResponse = await this.inferenceApi.addRule({
|
|
20780
20855
|
term: TermInputDtoFromFrontToApi(compiled.solutionTerm),
|
|
20781
20856
|
antecedents: compiled.antecedents.map(TermInputDtoFromFrontToApi),
|
|
@@ -23154,6 +23229,26 @@ var Value = {
|
|
|
23154
23229
|
reference(id) {
|
|
23155
23230
|
return { type: "Reference", value: id };
|
|
23156
23231
|
},
|
|
23232
|
+
/**
|
|
23233
|
+
* Create a reference to a sort by UUID.
|
|
23234
|
+
*
|
|
23235
|
+
* @param id - The UUID of the sort.
|
|
23236
|
+
* @returns A tagged `SortIdValue`: `{"type": "SortId", "value": "uuid"}`.
|
|
23237
|
+
*
|
|
23238
|
+
* @remarks
|
|
23239
|
+
* Used by homoiconic meta-constraints — primarily `Constraint.typeOf(...)`
|
|
23240
|
+
* — whose feature targets a sort as a first-class value. The chainer
|
|
23241
|
+
* dispatches this directly via `Value::SortId`.
|
|
23242
|
+
*
|
|
23243
|
+
* @example
|
|
23244
|
+
* ```typescript
|
|
23245
|
+
* Value.sortId("550e8400-e29b-41d4-a716-446655440000")
|
|
23246
|
+
* // { type: 'SortId', value: '550e8400-e29b-41d4-a716-446655440000' }
|
|
23247
|
+
* ```
|
|
23248
|
+
*/
|
|
23249
|
+
sortId(id) {
|
|
23250
|
+
return { type: "SortId", value: id };
|
|
23251
|
+
},
|
|
23157
23252
|
/**
|
|
23158
23253
|
* Create a fuzzy scalar with a value and membership degree.
|
|
23159
23254
|
*
|
|
@@ -23571,6 +23666,145 @@ var FuzzyShape = {
|
|
|
23571
23666
|
}
|
|
23572
23667
|
};
|
|
23573
23668
|
|
|
23669
|
+
// src/builders/psi.ts
|
|
23670
|
+
function psi(sortOrName, features) {
|
|
23671
|
+
if (typeof sortOrName === "string") {
|
|
23672
|
+
if (!features) {
|
|
23673
|
+
return { __psiTerm: true, sortName: sortOrName };
|
|
23674
|
+
}
|
|
23675
|
+
return {
|
|
23676
|
+
__psiTerm: true,
|
|
23677
|
+
sortName: sortOrName,
|
|
23678
|
+
features
|
|
23679
|
+
};
|
|
23680
|
+
}
|
|
23681
|
+
if (!features) {
|
|
23682
|
+
return { __psiTerm: true, sortId: sortOrName.sortId };
|
|
23683
|
+
}
|
|
23684
|
+
return {
|
|
23685
|
+
__psiTerm: true,
|
|
23686
|
+
sortId: sortOrName.sortId,
|
|
23687
|
+
features
|
|
23688
|
+
};
|
|
23689
|
+
}
|
|
23690
|
+
function constrained(name, constraint) {
|
|
23691
|
+
return { __constrainedVar: true, name, constraint };
|
|
23692
|
+
}
|
|
23693
|
+
|
|
23694
|
+
// src/builders/constraint.ts
|
|
23695
|
+
var ARITHMETIC_SORT = {
|
|
23696
|
+
"+": "plus_constraint",
|
|
23697
|
+
"-": "minus_constraint",
|
|
23698
|
+
"*": "times_constraint",
|
|
23699
|
+
"/": "div_constraint"
|
|
23700
|
+
};
|
|
23701
|
+
var Constraint = {
|
|
23702
|
+
/**
|
|
23703
|
+
* State that a variable is a term of a given sort. The chainer enumerates
|
|
23704
|
+
* every persisted term of that sort via backtracking.
|
|
23705
|
+
*
|
|
23706
|
+
* @param variable - Variable name (e.g. `'?E'`) or pre-built variable Ψ-term.
|
|
23707
|
+
* @param sortUuid - UUID of the target sort (resolve from
|
|
23708
|
+
* `client.inference.getMetaSorts()` or your own `createSort` response).
|
|
23709
|
+
* @returns A `sort_constraint` term.
|
|
23710
|
+
*/
|
|
23711
|
+
typeOf(variable, sortUuid) {
|
|
23712
|
+
return psi("sort_constraint", {
|
|
23713
|
+
var: variable,
|
|
23714
|
+
sort: { sortRef: sortUuid }
|
|
23715
|
+
});
|
|
23716
|
+
},
|
|
23717
|
+
/**
|
|
23718
|
+
* State that a variable's feature equals a target. The chainer unifies
|
|
23719
|
+
* the variable's feature value with the target.
|
|
23720
|
+
*
|
|
23721
|
+
* **Important**: the chainer's `feature_constraint` only unifies
|
|
23722
|
+
* term-references with term-references. The variable's feature on the
|
|
23723
|
+
* persisted side must itself be a `Value::Reference`. Comparing against
|
|
23724
|
+
* literals (e.g. `has('?N', 'name', 'S')` where `name` is stored as a
|
|
23725
|
+
* plain string) silently returns zero solutions — that's a chainer
|
|
23726
|
+
* design constraint, not a builder bug.
|
|
23727
|
+
*
|
|
23728
|
+
* @param variable - The owning variable (e.g. `'?Edge'`).
|
|
23729
|
+
* @param feature - The feature name (e.g. `'src'`).
|
|
23730
|
+
* @param target - The target — typically another variable (`'?Src'`)
|
|
23731
|
+
* or an existing term referenced by its UUID via `'!<uuid>'`.
|
|
23732
|
+
* @returns A `feature_constraint` term.
|
|
23733
|
+
*/
|
|
23734
|
+
has(variable, feature, target) {
|
|
23735
|
+
return psi("feature_constraint", {
|
|
23736
|
+
var: variable,
|
|
23737
|
+
feature,
|
|
23738
|
+
target
|
|
23739
|
+
});
|
|
23740
|
+
},
|
|
23741
|
+
/**
|
|
23742
|
+
* State a boolean comparison between two operands. The chainer
|
|
23743
|
+
* residuates the constraint until both sides are bound; when they are,
|
|
23744
|
+
* the comparison must hold or the proof branch fails.
|
|
23745
|
+
*
|
|
23746
|
+
* @param left - Left operand — variable, literal number, or term ref.
|
|
23747
|
+
* @param op - Comparison operator.
|
|
23748
|
+
* @param right - Right operand.
|
|
23749
|
+
* @returns A `guard_constraint` term.
|
|
23750
|
+
*/
|
|
23751
|
+
where(left, op, right) {
|
|
23752
|
+
return psi("guard_constraint", {
|
|
23753
|
+
left,
|
|
23754
|
+
operator: op,
|
|
23755
|
+
right
|
|
23756
|
+
});
|
|
23757
|
+
},
|
|
23758
|
+
/**
|
|
23759
|
+
* State that `result = left op right`. Selects the chainer sort by op:
|
|
23760
|
+
* `+` → `plus_constraint`, `-` → `minus_constraint`, `*` →
|
|
23761
|
+
* `times_constraint`, `/` → `div_constraint`. The chainer reads each
|
|
23762
|
+
* operand as either a Reference variable or a numeric literal, and can
|
|
23763
|
+
* run forward, reverse, or verify depending on which operands are
|
|
23764
|
+
* bound.
|
|
23765
|
+
*
|
|
23766
|
+
* @param result - Result variable or value (`z`).
|
|
23767
|
+
* @param op - Arithmetic operator.
|
|
23768
|
+
* @param left - Left operand (`x`).
|
|
23769
|
+
* @param right - Right operand (`y`).
|
|
23770
|
+
* @returns The appropriate arithmetic-constraint term.
|
|
23771
|
+
*/
|
|
23772
|
+
equation(result, op, left, right) {
|
|
23773
|
+
return psi(ARITHMETIC_SORT[op], { x: left, y: right, z: result });
|
|
23774
|
+
},
|
|
23775
|
+
/**
|
|
23776
|
+
* Constrain a variable to be an integer in the inclusive range
|
|
23777
|
+
* `[min, max]`. Required before the chainer's labeling step can assign
|
|
23778
|
+
* a concrete value via {@link Constraint.solveFor}.
|
|
23779
|
+
*
|
|
23780
|
+
* @param variable - Variable name to constrain.
|
|
23781
|
+
* @param min - Lower bound (inclusive).
|
|
23782
|
+
* @param max - Upper bound (inclusive).
|
|
23783
|
+
* @returns An `fd_domain_constraint` term.
|
|
23784
|
+
*/
|
|
23785
|
+
intRange(variable, min, max) {
|
|
23786
|
+
return psi("fd_domain_constraint", {
|
|
23787
|
+
var: variable,
|
|
23788
|
+
min,
|
|
23789
|
+
max
|
|
23790
|
+
});
|
|
23791
|
+
},
|
|
23792
|
+
/**
|
|
23793
|
+
* Search for concrete integer assignments to the listed variables that
|
|
23794
|
+
* satisfy every other constraint mentioning them. Place this at the END
|
|
23795
|
+
* of a clause body — it's the labeling/search step that turns a
|
|
23796
|
+
* constraint network into solutions.
|
|
23797
|
+
*
|
|
23798
|
+
* @param variables - Variable names to assign.
|
|
23799
|
+
* @returns An `fd_labeling_constraint` term.
|
|
23800
|
+
*/
|
|
23801
|
+
solveFor(...variables) {
|
|
23802
|
+
return psi("fd_labeling_constraint", {
|
|
23803
|
+
vars: variables
|
|
23804
|
+
});
|
|
23805
|
+
}
|
|
23806
|
+
};
|
|
23807
|
+
|
|
23574
23808
|
// src/builders/guard.ts
|
|
23575
23809
|
function guard(op, right) {
|
|
23576
23810
|
return {
|
|
@@ -23748,31 +23982,6 @@ var SortBuilder = class _SortBuilder {
|
|
|
23748
23982
|
}
|
|
23749
23983
|
};
|
|
23750
23984
|
|
|
23751
|
-
// src/builders/psi.ts
|
|
23752
|
-
function psi(sortOrName, features) {
|
|
23753
|
-
if (typeof sortOrName === "string") {
|
|
23754
|
-
if (!features) {
|
|
23755
|
-
return { __psiTerm: true, sortName: sortOrName };
|
|
23756
|
-
}
|
|
23757
|
-
return {
|
|
23758
|
-
__psiTerm: true,
|
|
23759
|
-
sortName: sortOrName,
|
|
23760
|
-
features
|
|
23761
|
-
};
|
|
23762
|
-
}
|
|
23763
|
-
if (!features) {
|
|
23764
|
-
return { __psiTerm: true, sortId: sortOrName.sortId };
|
|
23765
|
-
}
|
|
23766
|
-
return {
|
|
23767
|
-
__psiTerm: true,
|
|
23768
|
-
sortId: sortOrName.sortId,
|
|
23769
|
-
features
|
|
23770
|
-
};
|
|
23771
|
-
}
|
|
23772
|
-
function constrained(name, constraint) {
|
|
23773
|
-
return { __constrainedVar: true, name, constraint };
|
|
23774
|
-
}
|
|
23775
|
-
|
|
23776
23985
|
// src/builders/allen.ts
|
|
23777
23986
|
function allen(relation, intervalA, intervalBTermId) {
|
|
23778
23987
|
return {
|
|
@@ -23783,6 +23992,229 @@ function allen(relation, intervalA, intervalBTermId) {
|
|
|
23783
23992
|
};
|
|
23784
23993
|
}
|
|
23785
23994
|
|
|
23995
|
+
// src/builders/flow.ts
|
|
23996
|
+
function nodeVar(name) {
|
|
23997
|
+
const sanitized = name.replace(/[^A-Za-z0-9_]/g, "_");
|
|
23998
|
+
return { name: `?N_${sanitized}` };
|
|
23999
|
+
}
|
|
24000
|
+
function varRef(name) {
|
|
24001
|
+
return { name };
|
|
24002
|
+
}
|
|
24003
|
+
function freshVar(prefix, counter) {
|
|
24004
|
+
const name = `?${prefix}${counter.n}`;
|
|
24005
|
+
counter.n += 1;
|
|
24006
|
+
return name;
|
|
24007
|
+
}
|
|
24008
|
+
function normaliseEdge(e) {
|
|
24009
|
+
if (Array.isArray(e)) {
|
|
24010
|
+
const [from, to, cap, options] = e;
|
|
24011
|
+
return { from, to, cap, ...options ?? {} };
|
|
24012
|
+
}
|
|
24013
|
+
return e;
|
|
24014
|
+
}
|
|
24015
|
+
function buildEdges(edges, counter) {
|
|
24016
|
+
const edgeTerms = [];
|
|
24017
|
+
const edgeFlows = [];
|
|
24018
|
+
for (const raw of edges) {
|
|
24019
|
+
const e = normaliseEdge(raw);
|
|
24020
|
+
const flowVar = e.flow ?? freshVar("F", counter);
|
|
24021
|
+
edgeFlows.push({ from: e.from, to: e.to, var: flowVar });
|
|
24022
|
+
const features = {
|
|
24023
|
+
src: nodeVar(e.from),
|
|
24024
|
+
dst: nodeVar(e.to),
|
|
24025
|
+
cap: e.cap,
|
|
24026
|
+
flow: varRef(flowVar)
|
|
24027
|
+
};
|
|
24028
|
+
if (e.cost != null) features.cost = e.cost;
|
|
24029
|
+
if (e.label != null) features.label = e.label;
|
|
24030
|
+
edgeTerms.push(psi("flow_edge_constraint", features));
|
|
24031
|
+
}
|
|
24032
|
+
return { edgeTerms, edgeFlows };
|
|
24033
|
+
}
|
|
24034
|
+
function solveTerm(source, sink) {
|
|
24035
|
+
return psi("flow_solve_constraint", {
|
|
24036
|
+
source: nodeVar(source),
|
|
24037
|
+
sink: nodeVar(sink)
|
|
24038
|
+
});
|
|
24039
|
+
}
|
|
24040
|
+
var Flow = {
|
|
24041
|
+
/**
|
|
24042
|
+
* Build a max-flow problem.
|
|
24043
|
+
*
|
|
24044
|
+
* Emits one `flow_edge_constraint` per edge, one
|
|
24045
|
+
* `flow_max_constraint` with the requested output binding, and a
|
|
24046
|
+
* `flow_solve_constraint` trigger. Returns the constraint terms
|
|
24047
|
+
* plus the names of every output variable.
|
|
24048
|
+
*/
|
|
24049
|
+
maxFlow(input) {
|
|
24050
|
+
const counter = { n: 0 };
|
|
24051
|
+
const { edgeTerms, edgeFlows } = buildEdges(input.edges, counter);
|
|
24052
|
+
const flowValue = input.flowValue ?? freshVar("V_flow", counter);
|
|
24053
|
+
const constraints = [
|
|
24054
|
+
...edgeTerms,
|
|
24055
|
+
psi("flow_max_constraint", {
|
|
24056
|
+
source: nodeVar(input.source),
|
|
24057
|
+
sink: nodeVar(input.sink),
|
|
24058
|
+
flow_value: varRef(flowValue)
|
|
24059
|
+
}),
|
|
24060
|
+
solveTerm(input.source, input.sink)
|
|
24061
|
+
];
|
|
24062
|
+
return { constraints, vars: { flowValue, edgeFlows } };
|
|
24063
|
+
},
|
|
24064
|
+
/**
|
|
24065
|
+
* Build a min-cut problem.
|
|
24066
|
+
*
|
|
24067
|
+
* Emits `flow_min_cut_constraint` and binds `cut_value`,
|
|
24068
|
+
* `cut_edges`, `source_side`, `sink_side` to the requested
|
|
24069
|
+
* variable names (auto-generated when omitted).
|
|
24070
|
+
*/
|
|
24071
|
+
minCut(input) {
|
|
24072
|
+
const counter = { n: 0 };
|
|
24073
|
+
const { edgeTerms, edgeFlows } = buildEdges(input.edges, counter);
|
|
24074
|
+
const cutValue = input.cutValue ?? freshVar("CutValue", counter);
|
|
24075
|
+
const cutEdges = input.cutEdges ?? freshVar("CutEdges", counter);
|
|
24076
|
+
const sourceSide = input.sourceSide ?? freshVar("SrcSide", counter);
|
|
24077
|
+
const sinkSide = input.sinkSide ?? freshVar("SnkSide", counter);
|
|
24078
|
+
const constraints = [
|
|
24079
|
+
...edgeTerms,
|
|
24080
|
+
psi("flow_min_cut_constraint", {
|
|
24081
|
+
source: nodeVar(input.source),
|
|
24082
|
+
sink: nodeVar(input.sink),
|
|
24083
|
+
cut_value: varRef(cutValue),
|
|
24084
|
+
cut_edges: varRef(cutEdges),
|
|
24085
|
+
source_side: varRef(sourceSide),
|
|
24086
|
+
sink_side: varRef(sinkSide)
|
|
24087
|
+
}),
|
|
24088
|
+
solveTerm(input.source, input.sink)
|
|
24089
|
+
];
|
|
24090
|
+
return {
|
|
24091
|
+
constraints,
|
|
24092
|
+
vars: { cutValue, cutEdges, sourceSide, sinkSide, edgeFlows }
|
|
24093
|
+
};
|
|
24094
|
+
},
|
|
24095
|
+
/**
|
|
24096
|
+
* Build a min-cost-max-flow problem. Per-edge `cost` is required
|
|
24097
|
+
* for the optimisation to be meaningful (defaults to 0 if absent).
|
|
24098
|
+
*/
|
|
24099
|
+
minCostMaxFlow(input) {
|
|
24100
|
+
const counter = { n: 0 };
|
|
24101
|
+
const { edgeTerms, edgeFlows } = buildEdges(input.edges, counter);
|
|
24102
|
+
const flowValue = input.flowValue ?? freshVar("V_flow", counter);
|
|
24103
|
+
const totalCost = input.totalCost ?? freshVar("Cost", counter);
|
|
24104
|
+
const constraints = [
|
|
24105
|
+
...edgeTerms,
|
|
24106
|
+
psi("flow_min_cost_max_flow_constraint", {
|
|
24107
|
+
source: nodeVar(input.source),
|
|
24108
|
+
sink: nodeVar(input.sink),
|
|
24109
|
+
flow_value: varRef(flowValue),
|
|
24110
|
+
total_cost: varRef(totalCost)
|
|
24111
|
+
}),
|
|
24112
|
+
solveTerm(input.source, input.sink)
|
|
24113
|
+
];
|
|
24114
|
+
return { constraints, vars: { flowValue, totalCost, edgeFlows } };
|
|
24115
|
+
},
|
|
24116
|
+
/**
|
|
24117
|
+
* Build a Dulmage-Mendelsohn edge-classification problem.
|
|
24118
|
+
*
|
|
24119
|
+
* Each edge is classified as `"always"`, `"never"`, or
|
|
24120
|
+
* `"sometimes"` used across the space of all max flows (or all
|
|
24121
|
+
* min-cost max flows when `optimal: true`).
|
|
24122
|
+
*/
|
|
24123
|
+
classifyEdges(input) {
|
|
24124
|
+
const counter = { n: 0 };
|
|
24125
|
+
const { edgeTerms, edgeFlows } = buildEdges(input.edges, counter);
|
|
24126
|
+
const classifications = input.classifications ?? freshVar("Classes", counter);
|
|
24127
|
+
const objectiveFeatures = {
|
|
24128
|
+
source: nodeVar(input.source),
|
|
24129
|
+
sink: nodeVar(input.sink),
|
|
24130
|
+
classifications: varRef(classifications)
|
|
24131
|
+
};
|
|
24132
|
+
if (input.optimal) objectiveFeatures.optimal = true;
|
|
24133
|
+
const constraints = [
|
|
24134
|
+
...edgeTerms,
|
|
24135
|
+
psi("flow_classify_edges_constraint", objectiveFeatures),
|
|
24136
|
+
solveTerm(input.source, input.sink)
|
|
24137
|
+
];
|
|
24138
|
+
return { constraints, vars: { classifications, edgeFlows } };
|
|
24139
|
+
},
|
|
24140
|
+
/** Low-level: build a single `flow_edge_constraint` psi-term. */
|
|
24141
|
+
edge(from, to, cap, options = {}) {
|
|
24142
|
+
const features = {
|
|
24143
|
+
src: nodeVar(from),
|
|
24144
|
+
dst: nodeVar(to),
|
|
24145
|
+
cap
|
|
24146
|
+
};
|
|
24147
|
+
if (options.flow) features.flow = varRef(options.flow);
|
|
24148
|
+
if (options.cost != null) features.cost = options.cost;
|
|
24149
|
+
if (options.label != null) features.label = options.label;
|
|
24150
|
+
return psi("flow_edge_constraint", features);
|
|
24151
|
+
},
|
|
24152
|
+
/** Low-level: build a single `flow_solve_constraint` psi-term. */
|
|
24153
|
+
solve(source, sink) {
|
|
24154
|
+
return solveTerm(source, sink);
|
|
24155
|
+
},
|
|
24156
|
+
/**
|
|
24157
|
+
* Low-level: build a single `flow_max_constraint` psi-term.
|
|
24158
|
+
*
|
|
24159
|
+
* @example
|
|
24160
|
+
* ```typescript
|
|
24161
|
+
* const constraints = [
|
|
24162
|
+
* Flow.edge('s', 'a', 10),
|
|
24163
|
+
* Flow.edge('a', 't', 10),
|
|
24164
|
+
* Flow.maxObjective({ source: 's', sink: 't', flowValue: '?V' }),
|
|
24165
|
+
* Flow.solve('s', 't'),
|
|
24166
|
+
* ];
|
|
24167
|
+
* ```
|
|
24168
|
+
*/
|
|
24169
|
+
maxObjective(opts) {
|
|
24170
|
+
return psi("flow_max_constraint", {
|
|
24171
|
+
source: nodeVar(opts.source),
|
|
24172
|
+
sink: nodeVar(opts.sink),
|
|
24173
|
+
flow_value: varRef(opts.flowValue)
|
|
24174
|
+
});
|
|
24175
|
+
},
|
|
24176
|
+
/** Low-level: build a single `flow_min_cut_constraint` psi-term. */
|
|
24177
|
+
minCutObjective(opts) {
|
|
24178
|
+
return psi("flow_min_cut_constraint", {
|
|
24179
|
+
source: nodeVar(opts.source),
|
|
24180
|
+
sink: nodeVar(opts.sink),
|
|
24181
|
+
cut_value: varRef(opts.cutValue),
|
|
24182
|
+
cut_edges: varRef(opts.cutEdges),
|
|
24183
|
+
source_side: varRef(opts.sourceSide),
|
|
24184
|
+
sink_side: varRef(opts.sinkSide)
|
|
24185
|
+
});
|
|
24186
|
+
},
|
|
24187
|
+
/** Low-level: build a single `flow_min_cost_max_flow_constraint` psi-term. */
|
|
24188
|
+
minCostMaxFlowObjective(opts) {
|
|
24189
|
+
return psi("flow_min_cost_max_flow_constraint", {
|
|
24190
|
+
source: nodeVar(opts.source),
|
|
24191
|
+
sink: nodeVar(opts.sink),
|
|
24192
|
+
flow_value: varRef(opts.flowValue),
|
|
24193
|
+
total_cost: varRef(opts.totalCost)
|
|
24194
|
+
});
|
|
24195
|
+
},
|
|
24196
|
+
/** Low-level: build a single `flow_classify_edges_constraint` psi-term. */
|
|
24197
|
+
classifyEdgesObjective(opts) {
|
|
24198
|
+
const features = {
|
|
24199
|
+
source: nodeVar(opts.source),
|
|
24200
|
+
sink: nodeVar(opts.sink),
|
|
24201
|
+
classifications: varRef(opts.classifications)
|
|
24202
|
+
};
|
|
24203
|
+
if (opts.optimal) features.optimal = true;
|
|
24204
|
+
return psi("flow_classify_edges_constraint", features);
|
|
24205
|
+
},
|
|
24206
|
+
/**
|
|
24207
|
+
* Low-level: get the node-variable reference used to identify a
|
|
24208
|
+
* node name in goals built by this builder. Exposed so callers
|
|
24209
|
+
* composing constraints by hand can refer to the same logical node
|
|
24210
|
+
* the high-level helpers would produce — e.g., to add a feature
|
|
24211
|
+
* test on the same node term inside the same goal.
|
|
24212
|
+
*/
|
|
24213
|
+
node(name) {
|
|
24214
|
+
return nodeVar(name);
|
|
24215
|
+
}
|
|
24216
|
+
};
|
|
24217
|
+
|
|
23786
24218
|
// src/utils/discrimination.ts
|
|
23787
24219
|
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
24220
|
function isUuid(s) {
|
|
@@ -23809,6 +24241,6 @@ function discriminateFeatureValue(value) {
|
|
|
23809
24241
|
);
|
|
23810
24242
|
}
|
|
23811
24243
|
|
|
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 };
|
|
24244
|
+
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, Constraint, 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
24245
|
//# sourceMappingURL=index.js.map
|
|
23814
24246
|
//# sourceMappingURL=index.js.map
|