@tiangong-lca/foundry 0.1.18 → 0.1.20
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/README.md +5 -3
- package/docs/architecture.md +5 -3
- package/docs/foundry-task-contracts.md +2 -0
- package/docs/package-distribution-contract.md +10 -8
- package/docs/public-runtime-contract.md +53 -3
- package/docs/runtime-context-contract.md +7 -3
- package/docs/task-authorization-contract.md +2 -0
- package/package-dist/assets/foundry-package-descriptor.json +374 -136
- package/package-dist/scripts/foundry-facade.d.ts +6 -0
- package/package-dist/scripts/foundry-facade.js +38 -0
- package/package-dist/scripts/foundry-runtime.d.ts +3 -2
- package/package-dist/scripts/lib/decision-owners/identity-preflight.js +3 -1
- package/package-dist/scripts/lib/final-delivery-manifest.d.ts +40 -0
- package/package-dist/scripts/lib/final-delivery-manifest.js +145 -0
- package/package-dist/scripts/lib/final-delivery-review.d.ts +37 -0
- package/package-dist/scripts/lib/final-delivery-review.js +108 -0
- package/package-dist/scripts/lib/finalize-owners/cli-wrappers.d.ts +72 -1
- package/package-dist/scripts/lib/finalize-owners/cli-wrappers.js +123 -3
- package/package-dist/scripts/lib/finalize-owners/native-draft-handoff.js +4 -3
- package/package-dist/scripts/lib/finalize-owners/post-authoring.d.ts +9 -0
- package/package-dist/scripts/lib/finalize-owners/post-authoring.js +37 -8
- package/package-dist/scripts/lib/foundry-authentication-environment.js +1 -1
- package/package-dist/scripts/lib/foundry-curation-queue.d.ts +73 -0
- package/package-dist/scripts/lib/foundry-curation-queue.js +261 -0
- package/package-dist/scripts/lib/foundry-edge-draft-admission.d.ts +17 -0
- package/package-dist/scripts/lib/foundry-edge-draft-admission.js +94 -0
- package/package-dist/scripts/lib/foundry-edge-identity-preflight.d.ts +47 -0
- package/package-dist/scripts/lib/foundry-edge-identity-preflight.js +268 -0
- package/package-dist/scripts/lib/foundry-edge-oauth.d.ts +4 -0
- package/package-dist/scripts/lib/foundry-edge-oauth.js +154 -0
- package/package-dist/scripts/lib/foundry-edge-reference-intent.d.ts +51 -0
- package/package-dist/scripts/lib/foundry-edge-reference-intent.js +184 -0
- package/package-dist/scripts/lib/foundry-edge-repair-preparation.d.ts +24 -0
- package/package-dist/scripts/lib/foundry-edge-repair-preparation.js +209 -0
- package/package-dist/scripts/lib/foundry-edge-session.d.ts +32 -0
- package/package-dist/scripts/lib/foundry-edge-session.js +203 -0
- package/package-dist/scripts/lib/foundry-edge-support-plan.d.ts +69 -0
- package/package-dist/scripts/lib/foundry-edge-support-plan.js +245 -0
- package/package-dist/scripts/lib/foundry-edge-support-planning.d.ts +115 -0
- package/package-dist/scripts/lib/foundry-edge-support-planning.js +259 -0
- package/package-dist/scripts/lib/foundry-edge-support.d.ts +19 -0
- package/package-dist/scripts/lib/foundry-edge-support.js +188 -0
- package/package-dist/scripts/lib/foundry-execution-admission.d.ts +4 -2
- package/package-dist/scripts/lib/foundry-execution-admission.js +24 -2
- package/package-dist/scripts/lib/foundry-finalize-edge-identity.d.ts +30 -0
- package/package-dist/scripts/lib/foundry-finalize-edge-identity.js +102 -0
- package/package-dist/scripts/lib/foundry-finalize-owners.d.ts +1 -0
- package/package-dist/scripts/lib/foundry-finalize-owners.js +68 -2
- package/package-dist/scripts/lib/foundry-interaction-input.js +2 -2
- package/package-dist/scripts/lib/foundry-managed-authentication.js +1 -1
- package/package-dist/scripts/lib/foundry-operation-result.d.ts +1 -1
- package/package-dist/scripts/lib/foundry-operation-result.js +1 -0
- package/package-dist/scripts/lib/foundry-owner-execution-store.d.ts +16 -16
- package/package-dist/scripts/lib/foundry-owner-execution-store.js +34 -7
- package/package-dist/scripts/lib/foundry-owner-readback.d.ts +21 -0
- package/package-dist/scripts/lib/foundry-owner-readback.js +61 -0
- package/package-dist/scripts/lib/foundry-package-contract.d.ts +4 -4
- package/package-dist/scripts/lib/foundry-package-contract.js +8 -2
- package/package-dist/scripts/lib/foundry-preparation-cli-validation.js +71 -0
- package/package-dist/scripts/lib/foundry-process-mass-balance.d.ts +64 -0
- package/package-dist/scripts/lib/foundry-process-mass-balance.js +224 -0
- package/package-dist/scripts/lib/foundry-process-qa.d.ts +19 -0
- package/package-dist/scripts/lib/foundry-process-qa.js +423 -0
- package/package-dist/scripts/lib/foundry-repair-census.d.ts +82 -0
- package/package-dist/scripts/lib/foundry-repair-census.js +574 -0
- package/package-dist/scripts/lib/foundry-repair-execution.js +13 -2
- package/package-dist/scripts/lib/foundry-repair-scope.d.ts +15 -2
- package/package-dist/scripts/lib/foundry-repair-scope.js +62 -10
- package/package-dist/scripts/lib/foundry-runtime-environment.d.ts +2 -0
- package/package-dist/scripts/lib/foundry-runtime-environment.js +18 -0
- package/package-dist/scripts/lib/foundry-runtime-identity.d.ts +1 -0
- package/package-dist/scripts/lib/foundry-runtime-identity.js +19 -1
- package/package-dist/scripts/lib/foundry-runtime-qualification.js +2 -2
- package/package-dist/scripts/lib/foundry-runtime-utils.d.ts +1 -0
- package/package-dist/scripts/lib/foundry-runtime-utils.js +1 -1
- package/package-dist/scripts/lib/foundry-scientific-repair.d.ts +38 -0
- package/package-dist/scripts/lib/foundry-scientific-repair.js +438 -0
- package/package-dist/scripts/lib/foundry-semantic-input.js +1 -1
- package/package-dist/scripts/lib/foundry-task-input-preparation.d.ts +4 -0
- package/package-dist/scripts/lib/foundry-task-input-preparation.js +160 -0
- package/package-dist/scripts/lib/foundry-task-registration.js +19 -1
- package/package-dist/scripts/lib/foundry-task-types.d.ts +2 -0
- package/package-dist/scripts/lib/foundry-typed-authoring-patch.d.ts +76 -0
- package/package-dist/scripts/lib/foundry-typed-authoring-patch.js +237 -0
- package/package-dist/scripts/lib/foundry-typed-context.d.ts +11 -0
- package/package-dist/scripts/lib/foundry-typed-context.js +79 -0
- package/package-dist/scripts/lib/foundry-typed-flow-qa.d.ts +166 -0
- package/package-dist/scripts/lib/foundry-typed-flow-qa.js +226 -0
- package/package-dist/scripts/lib/foundry-typed-model-write.d.ts +6 -0
- package/package-dist/scripts/lib/foundry-typed-model-write.js +59 -0
- package/package-dist/scripts/lib/foundry-workflow-assessment.js +67 -29
- package/package-dist/scripts/lib/foundry-workflow-authorization.js +82 -1
- package/package-dist/scripts/lib/foundry-workflow-context.js +59 -18
- package/package-dist/scripts/lib/foundry-workflow-execution.js +57 -5
- package/package-dist/scripts/lib/foundry-workflow-finalize.js +27 -3
- package/package-dist/scripts/lib/foundry-workflow-identity-stage.js +202 -161
- package/package-dist/scripts/lib/foundry-workflow-identity.js +16 -10
- package/package-dist/scripts/lib/foundry-workflow-io.js +27 -6
- package/package-dist/scripts/lib/foundry-workflow-reference-verify.js +102 -29
- package/package-dist/scripts/lib/foundry-workflow-repair.d.ts +5 -0
- package/package-dist/scripts/lib/foundry-workflow-repair.js +204 -2
- package/package-dist/scripts/lib/foundry-workflow-semantic.js +41 -21
- package/package-dist/scripts/lib/identity-preflight-proof.d.ts +1 -0
- package/package-dist/scripts/lib/identity-preflight-proof.js +19 -12
- package/package-dist/scripts/lib/import-curation/internal/context-inputs.js +1 -1
- package/package-dist/scripts/public-api.d.ts +6 -0
- package/package-dist/scripts/runtime-entry.js +15 -6
- package/package.json +5 -2
- package/specs/schemas/foundry-interaction-draft.schema.json +323 -0
- package/specs/schemas/foundry-managed-runtime.schema.json +1 -1
- package/specs/schemas/foundry-operation-result.schema.json +1 -0
- package/specs/schemas/foundry-package-descriptor.schema.json +5 -2
- package/specs/schemas/foundry-scientific-repair.schema.json +66 -0
- package/specs/schemas/foundry-semantic-draft.schema.json +50 -0
- package/specs/schemas/foundry-task-start.schema.json +10 -2
- package/specs/schemas/runtime-qualification.schema.json +1 -1
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
type JsonObject = Record<string, unknown>;
|
|
2
|
+
type ReferenceKind = "flow" | "flowproperty" | "unitgroup";
|
|
3
|
+
type Dimension = "mass" | "count" | "energy" | "length" | "area" | "volume" | "time" | "area_time";
|
|
4
|
+
type Unit = {
|
|
5
|
+
name: string;
|
|
6
|
+
dimension: Dimension;
|
|
7
|
+
kilograms: number | null;
|
|
8
|
+
};
|
|
9
|
+
type EvidenceRow = {
|
|
10
|
+
payload: JsonObject;
|
|
11
|
+
sha256: string;
|
|
12
|
+
};
|
|
13
|
+
export type MassReferenceEvidence = {
|
|
14
|
+
rows: Map<string, EvidenceRow>;
|
|
15
|
+
};
|
|
16
|
+
export type MassExchangeObservation = {
|
|
17
|
+
exchange_index: number;
|
|
18
|
+
exchange_internal_id: string;
|
|
19
|
+
amount: number | null;
|
|
20
|
+
unit: Unit | null;
|
|
21
|
+
mass_kg: number | null;
|
|
22
|
+
references: {
|
|
23
|
+
kind: ReferenceKind;
|
|
24
|
+
id: string;
|
|
25
|
+
version: string;
|
|
26
|
+
payload_sha256: string;
|
|
27
|
+
}[];
|
|
28
|
+
error: string | null;
|
|
29
|
+
};
|
|
30
|
+
export type ProcessMassBalance = {
|
|
31
|
+
process_file: string;
|
|
32
|
+
process_payload_sha256: string;
|
|
33
|
+
status: "applicable" | "not_applicable" | "unresolved";
|
|
34
|
+
unit: "kg";
|
|
35
|
+
reference_exchange_id: string | null;
|
|
36
|
+
exchanges: MassExchangeObservation[];
|
|
37
|
+
raw_input: number | null;
|
|
38
|
+
product: number | null;
|
|
39
|
+
byproduct: number | null;
|
|
40
|
+
waste: number | null;
|
|
41
|
+
other_output: number | null;
|
|
42
|
+
energy_excluded: null;
|
|
43
|
+
input_mass_kg: number | null;
|
|
44
|
+
output_mass_kg: number | null;
|
|
45
|
+
delta: number | null;
|
|
46
|
+
relative_deviation: number | null;
|
|
47
|
+
findings: {
|
|
48
|
+
code: string;
|
|
49
|
+
message: string;
|
|
50
|
+
exchange_index?: number;
|
|
51
|
+
}[];
|
|
52
|
+
};
|
|
53
|
+
export declare function assessProcessMassBalance(input: {
|
|
54
|
+
processFile: string;
|
|
55
|
+
processPayload: JsonObject;
|
|
56
|
+
exchanges: readonly JsonObject[];
|
|
57
|
+
referenceFlowId: string | null;
|
|
58
|
+
references: MassReferenceEvidence;
|
|
59
|
+
classify: (exchange: JsonObject) => {
|
|
60
|
+
classification: string;
|
|
61
|
+
uoms: readonly string[];
|
|
62
|
+
};
|
|
63
|
+
}): ProcessMassBalance;
|
|
64
|
+
export {};
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
// Deterministic Process QA retained from TianGong LCA CLI 0.1.28 (MIT).
|
|
2
|
+
import { datasetRoot } from "./import-curation/internal/dataset-payload.js";
|
|
3
|
+
import { sha256Json } from "./identity-preflight-proof.js";
|
|
4
|
+
const isRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
5
|
+
const token = (value) => typeof value === "string" || typeof value === "number" ? String(value).trim() : "";
|
|
6
|
+
const object = (value) => (isRecord(value) ? value : {});
|
|
7
|
+
const array = (value) => Array.isArray(value) ? value : value === undefined ? [] : [value];
|
|
8
|
+
function requireValue(condition, message) {
|
|
9
|
+
if (!condition)
|
|
10
|
+
throw new Error(message);
|
|
11
|
+
}
|
|
12
|
+
function numeric(value) {
|
|
13
|
+
if ((typeof value !== "number" && typeof value !== "string") || !token(value))
|
|
14
|
+
return null;
|
|
15
|
+
const number = Number(value);
|
|
16
|
+
return Number.isFinite(number) && number >= 0 ? number : null;
|
|
17
|
+
}
|
|
18
|
+
function recognizedUnit(value) {
|
|
19
|
+
// SI symbols retain case and token boundaries; descriptive names may be case folded.
|
|
20
|
+
const name = token(value).normalize("NFKC");
|
|
21
|
+
const lowerName = name.toLowerCase();
|
|
22
|
+
const massSymbols = {
|
|
23
|
+
kg: 1,
|
|
24
|
+
g: 1e-3,
|
|
25
|
+
mg: 1e-6,
|
|
26
|
+
ug: 1e-9,
|
|
27
|
+
μg: 1e-9,
|
|
28
|
+
Mg: 1e3,
|
|
29
|
+
t: 1e3,
|
|
30
|
+
};
|
|
31
|
+
const massNames = {
|
|
32
|
+
kilogram: 1,
|
|
33
|
+
kilograms: 1,
|
|
34
|
+
gram: 1e-3,
|
|
35
|
+
grams: 1e-3,
|
|
36
|
+
milligram: 1e-6,
|
|
37
|
+
milligrams: 1e-6,
|
|
38
|
+
microgram: 1e-9,
|
|
39
|
+
micrograms: 1e-9,
|
|
40
|
+
megagram: 1e3,
|
|
41
|
+
tonne: 1e3,
|
|
42
|
+
tonnes: 1e3,
|
|
43
|
+
};
|
|
44
|
+
const kilograms = Object.hasOwn(massSymbols, name)
|
|
45
|
+
? massSymbols[name]
|
|
46
|
+
: Object.hasOwn(massNames, lowerName)
|
|
47
|
+
? massNames[lowerName]
|
|
48
|
+
: null;
|
|
49
|
+
if (kilograms !== null)
|
|
50
|
+
return { name, dimension: "mass", kilograms };
|
|
51
|
+
const dimensions = [
|
|
52
|
+
[
|
|
53
|
+
"count",
|
|
54
|
+
["1"],
|
|
55
|
+
["item", "items", "item(s)", "piece", "pieces", "unit", "units", "unit(s)", "count"],
|
|
56
|
+
],
|
|
57
|
+
["energy", ["J", "kJ", "MJ", "GJ", "mJ", "Wh", "kWh", "MWh"], []],
|
|
58
|
+
["length", ["m", "km", "cm", "mm"], []],
|
|
59
|
+
["area", ["m2", "km2", "ha"], []],
|
|
60
|
+
["volume", ["m3", "cm3", "l", "L"], ["litre", "liter"]],
|
|
61
|
+
[
|
|
62
|
+
"time",
|
|
63
|
+
["s", "min", "h", "d", "a", "yr"],
|
|
64
|
+
["second", "seconds", "hour", "hours", "year", "years"],
|
|
65
|
+
],
|
|
66
|
+
["area_time", ["m2*a"], []],
|
|
67
|
+
];
|
|
68
|
+
const matched = dimensions.find(([, symbols, names]) => symbols.includes(name) || names.includes(lowerName));
|
|
69
|
+
return matched ? { name, dimension: matched[0], kilograms: null } : null;
|
|
70
|
+
}
|
|
71
|
+
function resolveExchange(evidence, exchange, index, uoms) {
|
|
72
|
+
const observation = {
|
|
73
|
+
exchange_index: index,
|
|
74
|
+
exchange_internal_id: token(exchange["@dataSetInternalID"]),
|
|
75
|
+
amount: numeric(exchange.meanAmount ?? exchange.resultingAmount),
|
|
76
|
+
unit: null,
|
|
77
|
+
mass_kg: null,
|
|
78
|
+
references: [],
|
|
79
|
+
error: null,
|
|
80
|
+
};
|
|
81
|
+
const select = (value, kind) => {
|
|
82
|
+
const ref = object(value), id = token(ref["@refObjectId"]), version = token(ref["@version"]);
|
|
83
|
+
requireValue(id && version, "An exact reference UUID and version are required.");
|
|
84
|
+
const type = {
|
|
85
|
+
flow: "flow data set",
|
|
86
|
+
flowproperty: "flow property data set",
|
|
87
|
+
unitgroup: "unit group data set",
|
|
88
|
+
}[kind];
|
|
89
|
+
requireValue(ref["@type"] === undefined || ref["@type"] === type, "Reference type contradicts its physical-unit chain.");
|
|
90
|
+
const row = evidence.rows.get(`${kind}/${id}/${version}`);
|
|
91
|
+
requireValue(row, "The exact reference payload is missing from selected evidence.");
|
|
92
|
+
observation.references.push({ kind, id, version, payload_sha256: row.sha256 });
|
|
93
|
+
return datasetRoot(row.payload, kind);
|
|
94
|
+
};
|
|
95
|
+
try {
|
|
96
|
+
requireValue(observation.amount !== null, "Exchange quantity must be finite and nonnegative.");
|
|
97
|
+
const flow = select(exchange.referenceToFlowDataSet, "flow");
|
|
98
|
+
const referenceProperty = token(object(object(flow.flowInformation).quantitativeReference).referenceToReferenceFlowProperty);
|
|
99
|
+
const properties = array(object(flow.flowProperties).flowProperty)
|
|
100
|
+
.map(object)
|
|
101
|
+
.filter((value) => token(value["@dataSetInternalID"]) === referenceProperty);
|
|
102
|
+
requireValue(referenceProperty && properties.length === 1, "Flow reference property must select one exact property occurrence.");
|
|
103
|
+
requireValue(numeric(properties[0].meanValue) === 1, "The reference flow property must have meanValue one.");
|
|
104
|
+
const property = select(properties[0].referenceToFlowPropertyDataSet, "flowproperty");
|
|
105
|
+
const group = select(object(object(property.flowPropertiesInformation).quantitativeReference)
|
|
106
|
+
.referenceToReferenceUnitGroup, "unitgroup");
|
|
107
|
+
const referenceUnit = token(object(object(group.unitGroupInformation).quantitativeReference).referenceToReferenceUnit);
|
|
108
|
+
const units = array(object(group.units).unit)
|
|
109
|
+
.map(object)
|
|
110
|
+
.filter((value) => token(value["@dataSetInternalID"]) === referenceUnit);
|
|
111
|
+
requireValue(referenceUnit && units.length === 1, "Unit Group reference unit must select one exact unit occurrence.");
|
|
112
|
+
requireValue(numeric(units[0].meanValue) === 1, "The reference unit must have meanValue one.");
|
|
113
|
+
const unit = recognizedUnit(units[0].name);
|
|
114
|
+
requireValue(unit, "The exact reference unit has an unknown or ambiguous physical dimension.");
|
|
115
|
+
for (const tag of uoms) {
|
|
116
|
+
const tagged = recognizedUnit(tag);
|
|
117
|
+
requireValue(tagged && tagged.dimension === unit.dimension && tagged.kilograms === unit.kilograms, "Exchange unit tag conflicts with exact reference-unit evidence.");
|
|
118
|
+
}
|
|
119
|
+
observation.unit = unit;
|
|
120
|
+
if (unit.kilograms !== null) {
|
|
121
|
+
observation.mass_kg = observation.amount * unit.kilograms;
|
|
122
|
+
requireValue(Number.isFinite(observation.mass_kg), "Normalized mass quantity overflows.");
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
observation.mass_kg = null;
|
|
127
|
+
observation.error = String(error);
|
|
128
|
+
}
|
|
129
|
+
return observation;
|
|
130
|
+
}
|
|
131
|
+
export function assessProcessMassBalance(input) {
|
|
132
|
+
const categories = input.exchanges.map(input.classify);
|
|
133
|
+
const observations = input.exchanges.map((exchange, index) => resolveExchange(input.references, exchange, index, categories[index].uoms));
|
|
134
|
+
const findings = observations.flatMap((observation) => observation.error
|
|
135
|
+
? [
|
|
136
|
+
{
|
|
137
|
+
code: "process_mass_unit_unresolved",
|
|
138
|
+
message: observation.error,
|
|
139
|
+
exchange_index: observation.exchange_index,
|
|
140
|
+
},
|
|
141
|
+
]
|
|
142
|
+
: []);
|
|
143
|
+
const reference = observations.filter((observation) => input.referenceFlowId !== null && observation.exchange_internal_id === input.referenceFlowId);
|
|
144
|
+
const result = {
|
|
145
|
+
process_file: input.processFile,
|
|
146
|
+
process_payload_sha256: sha256Json(input.processPayload),
|
|
147
|
+
status: "unresolved",
|
|
148
|
+
unit: "kg",
|
|
149
|
+
reference_exchange_id: input.referenceFlowId,
|
|
150
|
+
exchanges: observations,
|
|
151
|
+
raw_input: null,
|
|
152
|
+
product: null,
|
|
153
|
+
byproduct: null,
|
|
154
|
+
waste: null,
|
|
155
|
+
other_output: null,
|
|
156
|
+
energy_excluded: null,
|
|
157
|
+
input_mass_kg: null,
|
|
158
|
+
output_mass_kg: null,
|
|
159
|
+
delta: null,
|
|
160
|
+
relative_deviation: null,
|
|
161
|
+
findings,
|
|
162
|
+
};
|
|
163
|
+
if (reference.length !== 1) {
|
|
164
|
+
findings.push({
|
|
165
|
+
code: "process_mass_reference_unresolved",
|
|
166
|
+
message: "Physical mass applicability requires one exact reference exchange.",
|
|
167
|
+
});
|
|
168
|
+
return result;
|
|
169
|
+
}
|
|
170
|
+
if (reference[0].unit && reference[0].unit.dimension !== "mass" && !reference[0].error) {
|
|
171
|
+
result.status = "not_applicable";
|
|
172
|
+
return result;
|
|
173
|
+
}
|
|
174
|
+
if (findings.length)
|
|
175
|
+
return result;
|
|
176
|
+
let raw = 0, product = 0, byproduct = 0, waste = 0, other = 0;
|
|
177
|
+
for (const [index, observation] of observations.entries()) {
|
|
178
|
+
if (observation.mass_kg === null)
|
|
179
|
+
continue;
|
|
180
|
+
const direction = token(input.exchanges[index].exchangeDirection).toLowerCase();
|
|
181
|
+
if (direction === "input")
|
|
182
|
+
raw += observation.mass_kg;
|
|
183
|
+
else if (direction === "output") {
|
|
184
|
+
const category = categories[index].classification;
|
|
185
|
+
if (category === "product_output")
|
|
186
|
+
product += observation.mass_kg;
|
|
187
|
+
else if (category === "byproduct_output")
|
|
188
|
+
byproduct += observation.mass_kg;
|
|
189
|
+
else if (category === "waste_output")
|
|
190
|
+
waste += observation.mass_kg;
|
|
191
|
+
else
|
|
192
|
+
other += observation.mass_kg;
|
|
193
|
+
}
|
|
194
|
+
else
|
|
195
|
+
findings.push({
|
|
196
|
+
code: "process_mass_direction_unresolved",
|
|
197
|
+
message: "Mass exchange direction must be Input or Output.",
|
|
198
|
+
exchange_index: index,
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
const output = product + byproduct + waste + other, delta = output - raw;
|
|
202
|
+
const deviation = raw > 0 ? Math.abs(delta) / raw : null;
|
|
203
|
+
if (![raw, output, delta].every(Number.isFinite) ||
|
|
204
|
+
(deviation !== null && !Number.isFinite(deviation)))
|
|
205
|
+
findings.push({
|
|
206
|
+
code: "process_mass_sum_overflow",
|
|
207
|
+
message: "Mass inventory aggregation must remain finite.",
|
|
208
|
+
});
|
|
209
|
+
if (findings.length)
|
|
210
|
+
return result;
|
|
211
|
+
Object.assign(result, {
|
|
212
|
+
status: "applicable",
|
|
213
|
+
raw_input: raw,
|
|
214
|
+
product,
|
|
215
|
+
byproduct,
|
|
216
|
+
waste,
|
|
217
|
+
other_output: other,
|
|
218
|
+
input_mass_kg: raw,
|
|
219
|
+
output_mass_kg: output,
|
|
220
|
+
delta,
|
|
221
|
+
relative_deviation: deviation,
|
|
222
|
+
});
|
|
223
|
+
return result;
|
|
224
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type MassReferenceEvidence } from "./foundry-process-mass-balance.ts";
|
|
2
|
+
type JsonRecord = Record<string, unknown>;
|
|
3
|
+
type ProcessQaFinding = {
|
|
4
|
+
process_file: string;
|
|
5
|
+
severity: "info" | "warning" | "blocker";
|
|
6
|
+
code: string;
|
|
7
|
+
methodology_rule_id: string | null;
|
|
8
|
+
message: string;
|
|
9
|
+
source: "rule";
|
|
10
|
+
evidence?: JsonRecord;
|
|
11
|
+
};
|
|
12
|
+
export declare function foundryProcessQa(rows: readonly unknown[], references: MassReferenceEvidence): {
|
|
13
|
+
status: string;
|
|
14
|
+
policy_decision_owner: string;
|
|
15
|
+
qa_mode: string;
|
|
16
|
+
mass_balance: import("./foundry-process-mass-balance.ts").ProcessMassBalance[];
|
|
17
|
+
findings: ProcessQaFinding[];
|
|
18
|
+
};
|
|
19
|
+
export {};
|