@zerocarbon/erp-config-sdk 1.0.28 → 1.0.29
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/bulk-bill-agent.d.ts +33 -2
- package/dist/bulk-bill-agent.esm.js +350 -1
- package/dist/bulk-bill-agent.esm.js.map +1 -1
- package/dist/bulk-bill-agent.js +350 -0
- package/dist/bulk-bill-agent.js.map +1 -1
- package/dist/index.d.ts +33 -2
- package/dist/index.esm.js +350 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +350 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -980,6 +980,37 @@ declare const getBulkBillAgentProfilesForMappingContext: (context?: BulkBillAgen
|
|
|
980
980
|
}[];
|
|
981
981
|
declare const getPrimaryBulkBillAgentProfile: (context?: BulkBillAgentMappingContext, documentText?: string) => BulkBillAgentProfile;
|
|
982
982
|
declare const buildBulkBillAgentPromptConfig: (context?: BulkBillAgentMappingContext, documentText?: string) => BulkBillAgentPromptConfig;
|
|
983
|
+
interface BulkBillAgentProfilePage {
|
|
984
|
+
pageNumber: number | string;
|
|
985
|
+
text?: string;
|
|
986
|
+
}
|
|
987
|
+
interface BulkBillAgentProfileGroup {
|
|
988
|
+
groupId: string;
|
|
989
|
+
pageNumbers: Array<number | string>;
|
|
990
|
+
}
|
|
991
|
+
interface BulkBillAgentProfileCandidate {
|
|
992
|
+
candidateId: string;
|
|
993
|
+
groupId: string;
|
|
994
|
+
profileId: BulkBillAgentProfileId;
|
|
995
|
+
itemName: string;
|
|
996
|
+
quantity: string;
|
|
997
|
+
unit: string;
|
|
998
|
+
role: string;
|
|
999
|
+
confidence: number;
|
|
1000
|
+
pageNumber: number;
|
|
1001
|
+
evidenceText: string;
|
|
1002
|
+
matchedAllowedItemName?: string;
|
|
1003
|
+
matchedAllowedItemKey?: string;
|
|
1004
|
+
matchedAllowedItemSourceId?: string;
|
|
1005
|
+
mappingConfidence?: number;
|
|
1006
|
+
}
|
|
1007
|
+
interface BulkBillAgentProfileExtractionInput {
|
|
1008
|
+
mappingContext?: BulkBillAgentMappingContext;
|
|
1009
|
+
pages?: BulkBillAgentProfilePage[];
|
|
1010
|
+
group: BulkBillAgentProfileGroup;
|
|
1011
|
+
documentText?: string;
|
|
1012
|
+
}
|
|
1013
|
+
declare const extractBulkBillAgentProfileCandidates: ({ mappingContext, pages, group, documentText, }: BulkBillAgentProfileExtractionInput) => BulkBillAgentProfileCandidate[];
|
|
983
1014
|
|
|
984
1015
|
declare const getUserNameScopeConfig: <T = any>(scopeKey: "scope1" | "scope2" | "scope3" | "waterManagement", username?: string, defaultScope?: T) => T;
|
|
985
1016
|
type IndustryAdditionalScopeItem = {
|
|
@@ -6496,5 +6527,5 @@ declare namespace index {
|
|
|
6496
6527
|
};
|
|
6497
6528
|
}
|
|
6498
6529
|
|
|
6499
|
-
export { ALL_SCOPES_3_RCO, API_ENDPOINTS, API_SCOPE3_CEMENT_CONFIG, BILL_CALCULATION_CONFIGS, BULK_BILL_AGENT_PROFILES, BillManager, CCTS_ALLSCOPES_CEMENT, CCTS_CALCINATION_PRODUCTS, CCTS_ELECTRICITY_PRODUCTS, CCTS_FIRE_EXTINGUISHER_PRODUCTS, CCTS_FUEL_COMBUSTION_PRODUCTS, CCTS_LPG_PRODUCTS, CCTS_MINING_OPERATIONS_PRODUCTS, CCTS_ONSITE_POWER_PRODUCTS, CCTS_PURCHASED_ELECTRICITY, CCTS_REFRIGERANTS, CCTS_SCOPE1_CEMENT, CCTS_SCOPE2_CEMENT, CCTS_SF6_PRODUCTS, CCTS_TABLE_COLUMNS, DEFAULT_BILL_MATCHING_CONFIG, EmissionSourceGenerator, FRONTEND_INDUSTRY_CONFIGS, HTTP_STATUS, INDUSTRIES_CONFIG, INDUSTRY_MAPPING, INDUSTRY_SPECIFIC_FIELDS, INTENSITY_FIELD_LABELS, ISO_CATEGORIES_PACKAGING, index as Industries, UI_FEATURES, WATER_PRODUCTS$5 as WATER_PRODUCTS, addItemForUser, buildBulkBillAgentPromptConfig, buildUserConfigItemKey, calculateCCTSEmission, calculateIntensityMetrics, categorizeApiItem, cleanValue, createBillManager, createCapitalizedMonthMapping, createEmissionSourceGenerator, createMonthMapping, debugCarbonIntensityMapping, extractCarbonIntensityData, formatEmissionValue, formatIntensityValue, formatKPIEmission, formatMonthlyEmission, formatPercentage, getAllConfig, getApiIndustryType, getAvailableFieldsForIndustry, getBulkBillAgentProfile, getBulkBillAgentProfilesForMappingContext, getCombinedBackendConfig, getIndustryBackendConfig, getIndustryConfig$1 as getIndustryConfig, getIndustryFieldConfig, getIntensityFormulas, getItemsForUser, getPlantNameConfig, getPrimaryBulkBillAgentProfile, getRCOConfigByName, getScope3ConfigByName, getUserNameBackendConfig, getUserNameScopeConfig, hasIntensities, isUIFeatureEnabled, listBulkBillAgentProfiles, mapIndustryToApiType, mergeUserItemsIntoIndustryConfig, normalizeConfigKeyText, normalizeConfigText, resolveEmissionFactorsForUser, sameUserConfigText, sanitizeNumber, scoreBulkBillAgentProfile, supportsIntensityCalculations, updateItemEmissionFactorForUser, updateSdkItemEmissionFactorForUser, validateCarbonIntensityData };
|
|
6500
|
-
export type { AllConfigurations, AlloyRequest, AlloyResponse, AluminiumRequest, AluminiumResponse, ApiEndpointConfig, ApiResponse, AutomobileRequest, AutomobileResponse, AviationRequest, AviationResponse, BackendAdditionalScopeItem, BackendEmissionItem, BackendEmissions, BackendEquipmentCategory, BackendIndustries, BackendIndustryConfig, BackendProduct, BackendScope, BackendScope3Item, BackendUserConfig, BackendUserConfigs, BaseRequest, BaseResponse, Bill, BillCalculationConfig, BillFilterOptions, BillMatchingConfig, BulkBillAgentAllowedItem, BulkBillAgentMappingContext, BulkBillAgentProfile, BulkBillAgentProfileId, BulkBillAgentPromptConfig, BusinessTravelEmission, BusinessTravelEmissionAttributes, BusinessTravelEmissionsResponse, BillsAnalyzed$1 as CarbonIntensityBillsAnalyzed, Calculations$1 as CarbonIntensityCalculations, EmissionData$2 as CarbonIntensityEmissionData, ErrorResponse$1 as CarbonIntensityErrorResponse, CarbonIntensityRequest, CarbonIntensityResponse, ChemicalRequest, ChemicalResponse, DetailedCarbonIntensityResponse, EditableItem, EmissionData$3 as EmissionData, EmissionSource, Emissions$j as Emissions, EmissionsDataAttributes, EmissionsDataResponse, FieldConfig, FoodBeveragesRequest, FoodBeveragesResponse, FormData, FormValidationResult, FrontendIndustryConfig, HospitalityRequest, HospitalityResponse, IndustryConfig$1 as IndustryConfig, EmissionData as IndustryEmissionData, IndustryFieldConfig, IndustryFieldSection, ProductionData as IndustryProductionData, IndustryType, IntensityCalculation, IntensityValue, LogisticsRequest, LogisticsResponse, ManufacturingRequest, ManufacturingResponse, Meta, MetalEnergyRequest, MetalEnergyResponse, PackagingRequest, PackagingResponse, Pagination, PetrochemicalRequest, PetrochemicalResponse, PharmaRequest, PharmaResponse, PlantNameConfig, ProcessedEmissionCategory, ProcessedEmissionItem, ProcessedScope3Data, RealEstateRequest, RealEstateResponse, BillsAnalyzed as ResponseBillsAnalyzed, Calculations as ResponseCalculations, EmissionData$1 as ResponseEmissionData, ErrorResponse as ResponseErrorResponse, ScopeConfig, ScopeProduct, ShippingRequest, ShippingResponse, SteelRequest, SteelResponse, StrapiItem, StrapiResponse, TelecommunicationRequest, TelecommunicationResponse, TextileRequest, TextileResponse, TransportationEmission, TransportationEmissionAttributes, TransportationEmissionsResponse, UserConfigApiClient, UserConfigItem, UserData, UserEmissionFactorApprovalResponse, UserEmissionFactorResolution, UtilitiesRequest, UtilitiesResponse, ValidationError, VehicleEmission, VehicleEmissionAttributes, VehicleEmissionsResponse };
|
|
6530
|
+
export { ALL_SCOPES_3_RCO, API_ENDPOINTS, API_SCOPE3_CEMENT_CONFIG, BILL_CALCULATION_CONFIGS, BULK_BILL_AGENT_PROFILES, BillManager, CCTS_ALLSCOPES_CEMENT, CCTS_CALCINATION_PRODUCTS, CCTS_ELECTRICITY_PRODUCTS, CCTS_FIRE_EXTINGUISHER_PRODUCTS, CCTS_FUEL_COMBUSTION_PRODUCTS, CCTS_LPG_PRODUCTS, CCTS_MINING_OPERATIONS_PRODUCTS, CCTS_ONSITE_POWER_PRODUCTS, CCTS_PURCHASED_ELECTRICITY, CCTS_REFRIGERANTS, CCTS_SCOPE1_CEMENT, CCTS_SCOPE2_CEMENT, CCTS_SF6_PRODUCTS, CCTS_TABLE_COLUMNS, DEFAULT_BILL_MATCHING_CONFIG, EmissionSourceGenerator, FRONTEND_INDUSTRY_CONFIGS, HTTP_STATUS, INDUSTRIES_CONFIG, INDUSTRY_MAPPING, INDUSTRY_SPECIFIC_FIELDS, INTENSITY_FIELD_LABELS, ISO_CATEGORIES_PACKAGING, index as Industries, UI_FEATURES, WATER_PRODUCTS$5 as WATER_PRODUCTS, addItemForUser, buildBulkBillAgentPromptConfig, buildUserConfigItemKey, calculateCCTSEmission, calculateIntensityMetrics, categorizeApiItem, cleanValue, createBillManager, createCapitalizedMonthMapping, createEmissionSourceGenerator, createMonthMapping, debugCarbonIntensityMapping, extractBulkBillAgentProfileCandidates, extractCarbonIntensityData, formatEmissionValue, formatIntensityValue, formatKPIEmission, formatMonthlyEmission, formatPercentage, getAllConfig, getApiIndustryType, getAvailableFieldsForIndustry, getBulkBillAgentProfile, getBulkBillAgentProfilesForMappingContext, getCombinedBackendConfig, getIndustryBackendConfig, getIndustryConfig$1 as getIndustryConfig, getIndustryFieldConfig, getIntensityFormulas, getItemsForUser, getPlantNameConfig, getPrimaryBulkBillAgentProfile, getRCOConfigByName, getScope3ConfigByName, getUserNameBackendConfig, getUserNameScopeConfig, hasIntensities, isUIFeatureEnabled, listBulkBillAgentProfiles, mapIndustryToApiType, mergeUserItemsIntoIndustryConfig, normalizeConfigKeyText, normalizeConfigText, resolveEmissionFactorsForUser, sameUserConfigText, sanitizeNumber, scoreBulkBillAgentProfile, supportsIntensityCalculations, updateItemEmissionFactorForUser, updateSdkItemEmissionFactorForUser, validateCarbonIntensityData };
|
|
6531
|
+
export type { AllConfigurations, AlloyRequest, AlloyResponse, AluminiumRequest, AluminiumResponse, ApiEndpointConfig, ApiResponse, AutomobileRequest, AutomobileResponse, AviationRequest, AviationResponse, BackendAdditionalScopeItem, BackendEmissionItem, BackendEmissions, BackendEquipmentCategory, BackendIndustries, BackendIndustryConfig, BackendProduct, BackendScope, BackendScope3Item, BackendUserConfig, BackendUserConfigs, BaseRequest, BaseResponse, Bill, BillCalculationConfig, BillFilterOptions, BillMatchingConfig, BulkBillAgentAllowedItem, BulkBillAgentMappingContext, BulkBillAgentProfile, BulkBillAgentProfileCandidate, BulkBillAgentProfileExtractionInput, BulkBillAgentProfileGroup, BulkBillAgentProfileId, BulkBillAgentProfilePage, BulkBillAgentPromptConfig, BusinessTravelEmission, BusinessTravelEmissionAttributes, BusinessTravelEmissionsResponse, BillsAnalyzed$1 as CarbonIntensityBillsAnalyzed, Calculations$1 as CarbonIntensityCalculations, EmissionData$2 as CarbonIntensityEmissionData, ErrorResponse$1 as CarbonIntensityErrorResponse, CarbonIntensityRequest, CarbonIntensityResponse, ChemicalRequest, ChemicalResponse, DetailedCarbonIntensityResponse, EditableItem, EmissionData$3 as EmissionData, EmissionSource, Emissions$j as Emissions, EmissionsDataAttributes, EmissionsDataResponse, FieldConfig, FoodBeveragesRequest, FoodBeveragesResponse, FormData, FormValidationResult, FrontendIndustryConfig, HospitalityRequest, HospitalityResponse, IndustryConfig$1 as IndustryConfig, EmissionData as IndustryEmissionData, IndustryFieldConfig, IndustryFieldSection, ProductionData as IndustryProductionData, IndustryType, IntensityCalculation, IntensityValue, LogisticsRequest, LogisticsResponse, ManufacturingRequest, ManufacturingResponse, Meta, MetalEnergyRequest, MetalEnergyResponse, PackagingRequest, PackagingResponse, Pagination, PetrochemicalRequest, PetrochemicalResponse, PharmaRequest, PharmaResponse, PlantNameConfig, ProcessedEmissionCategory, ProcessedEmissionItem, ProcessedScope3Data, RealEstateRequest, RealEstateResponse, BillsAnalyzed as ResponseBillsAnalyzed, Calculations as ResponseCalculations, EmissionData$1 as ResponseEmissionData, ErrorResponse as ResponseErrorResponse, ScopeConfig, ScopeProduct, ShippingRequest, ShippingResponse, SteelRequest, SteelResponse, StrapiItem, StrapiResponse, TelecommunicationRequest, TelecommunicationResponse, TextileRequest, TextileResponse, TransportationEmission, TransportationEmissionAttributes, TransportationEmissionsResponse, UserConfigApiClient, UserConfigItem, UserData, UserEmissionFactorApprovalResponse, UserEmissionFactorResolution, UtilitiesRequest, UtilitiesResponse, ValidationError, VehicleEmission, VehicleEmissionAttributes, VehicleEmissionsResponse };
|
package/dist/index.esm.js
CHANGED
|
@@ -37898,6 +37898,355 @@ const buildBulkBillAgentPromptConfig = (context = {}, documentText = '') => {
|
|
|
37898
37898
|
},
|
|
37899
37899
|
};
|
|
37900
37900
|
};
|
|
37901
|
+
const numericPattern = /-?(?:(?:\d{1,3}(?:,\d{3})+)|\d+)(?:\.\d+)?/g;
|
|
37902
|
+
const physicalUnitPattern = /\b(kwh|kw\s*h|kvah|kva\s*h|mwh|kg|kgs|kilograms?|tonnes?|tons?|mt|kl|litres?|liters?|ltr?s?|m3|m³|scm|ncm|nm3|km|passenger[-\s]?km|room[-\s]?nights?|nights?|cyl(?:inders?)?|nos?|pcs|pieces?)\b/i;
|
|
37903
|
+
const metadataOnlyPattern = /(?:₹|rs\.?|inr|amount|payable|charge|tax|gst|duty|cess|rate|tariff|arrear|rebate|subsidy|surcharge|rent|total\s+amount|invoice\s*(?:no|number)|account\s*(?:no|number)|consumer\s*(?:no|number))/i;
|
|
37904
|
+
const compactKey = (value) => normalize(value).replace(/\s+/g, '');
|
|
37905
|
+
const canonicalActivityUnit = (unit) => {
|
|
37906
|
+
const value = compactKey(unit);
|
|
37907
|
+
if (value === 'kwh' || value === 'unit' || value === 'units')
|
|
37908
|
+
return 'kWh';
|
|
37909
|
+
if (value === 'kvah')
|
|
37910
|
+
return 'kVAh';
|
|
37911
|
+
if (value === 'mwh')
|
|
37912
|
+
return 'MWh';
|
|
37913
|
+
if (value === 'kg' || value === 'kgs' || value === 'kilogram' || value === 'kilograms')
|
|
37914
|
+
return 'Kg';
|
|
37915
|
+
if (value === 'tonne' || value === 'tonnes' || value === 'ton' || value === 'tons' || value === 'mt')
|
|
37916
|
+
return 'Tonnes';
|
|
37917
|
+
if (value === 'litre' || value === 'litres' || value === 'liter' || value === 'liters' || value === 'ltr' || value === 'ltrs')
|
|
37918
|
+
return 'Litre';
|
|
37919
|
+
if (value === 'kl')
|
|
37920
|
+
return 'KL';
|
|
37921
|
+
if (value === 'm3' || value === 'm³' || value === 'scm' || value === 'ncm' || value === 'nm3')
|
|
37922
|
+
return 'M3';
|
|
37923
|
+
if (value === 'km')
|
|
37924
|
+
return 'km';
|
|
37925
|
+
if (value === 'passengerkm')
|
|
37926
|
+
return 'passenger-km';
|
|
37927
|
+
if (value === 'night' || value === 'nights' || value === 'roomnight' || value === 'roomnights')
|
|
37928
|
+
return 'night';
|
|
37929
|
+
if (value === 'cyl' || value === 'cylinder' || value === 'cylinders')
|
|
37930
|
+
return 'Cyl';
|
|
37931
|
+
if (value === 'nos' || value === 'no' || value === 'pcs' || value === 'pieces')
|
|
37932
|
+
return 'Nos';
|
|
37933
|
+
return unit;
|
|
37934
|
+
};
|
|
37935
|
+
const parsePositiveNumbers = (line) => [...line.matchAll(numericPattern)]
|
|
37936
|
+
.map((match) => ({
|
|
37937
|
+
value: match[0],
|
|
37938
|
+
index: match.index || 0,
|
|
37939
|
+
number: Number(match[0].replace(/,/g, '')),
|
|
37940
|
+
}))
|
|
37941
|
+
.filter((entry) => Number.isFinite(entry.number) && entry.number > 0 && !/[A-Za-z]/.test(line[entry.index - 1] || ''));
|
|
37942
|
+
const adjacentActivityUnit = (line, numberIndex, valueLength) => {
|
|
37943
|
+
var _a, _b, _c;
|
|
37944
|
+
const after = line.slice(numberIndex + valueLength, numberIndex + valueLength + 18);
|
|
37945
|
+
const right = ((_a = after.match(/^\s*([A-Za-z³][-A-Za-z0-9³ ]{0,16})/i)) === null || _a === void 0 ? void 0 : _a[1]) || '';
|
|
37946
|
+
const rightUnit = (_b = right.match(physicalUnitPattern)) === null || _b === void 0 ? void 0 : _b[1];
|
|
37947
|
+
if (rightUnit)
|
|
37948
|
+
return canonicalActivityUnit(rightUnit);
|
|
37949
|
+
const before = line.slice(Math.max(0, numberIndex - 18), numberIndex);
|
|
37950
|
+
const beforeUnit = (_c = before.match(new RegExp(`(${physicalUnitPattern.source})\\s*$`, 'i'))) === null || _c === void 0 ? void 0 : _c[1];
|
|
37951
|
+
return beforeUnit ? canonicalActivityUnit(beforeUnit) : '';
|
|
37952
|
+
};
|
|
37953
|
+
const candidateAllowedScore = (query, item) => {
|
|
37954
|
+
const queryKey = normalize(query);
|
|
37955
|
+
const text = itemText(item);
|
|
37956
|
+
if (!queryKey || !text)
|
|
37957
|
+
return 0;
|
|
37958
|
+
const itemNameKey = normalize(item.itemName);
|
|
37959
|
+
if (itemNameKey && (queryKey.includes(itemNameKey) || itemNameKey.includes(queryKey)))
|
|
37960
|
+
return 1;
|
|
37961
|
+
const queryTokens = queryKey.split(' ').filter((token) => token.length > 1);
|
|
37962
|
+
const itemTokens = text.split(' ').filter((token) => token.length > 1);
|
|
37963
|
+
if (!queryTokens.length || !itemTokens.length)
|
|
37964
|
+
return 0;
|
|
37965
|
+
const matched = itemTokens.filter((token) => queryTokens.some((candidate) => token === candidate || token.includes(candidate) || candidate.includes(token))).length;
|
|
37966
|
+
return matched / itemTokens.length;
|
|
37967
|
+
};
|
|
37968
|
+
const bestAllowedItemForQuery = (query, allowedItems) => {
|
|
37969
|
+
const best = allowedItems
|
|
37970
|
+
.map((item) => ({ item, score: candidateAllowedScore(query, item) }))
|
|
37971
|
+
.sort((left, right) => right.score - left.score)[0];
|
|
37972
|
+
return best && best.score >= 0.34 ? best : null;
|
|
37973
|
+
};
|
|
37974
|
+
const profileTextLines = (pages = [], group, documentText = '') => {
|
|
37975
|
+
const wanted = new Set(group.pageNumbers.map(Number));
|
|
37976
|
+
const selectedPages = pages.filter((page) => wanted.has(Number(page.pageNumber)));
|
|
37977
|
+
if (!selectedPages.length && documentText) {
|
|
37978
|
+
return documentText.split(/\n+/).map((text, lineIndex) => ({
|
|
37979
|
+
pageNumber: 1,
|
|
37980
|
+
lineIndex,
|
|
37981
|
+
text: text.replace(/\s+/g, ' ').trim(),
|
|
37982
|
+
}));
|
|
37983
|
+
}
|
|
37984
|
+
return selectedPages.flatMap((page) => String(page.text || '').split(/\n+/).map((text, lineIndex) => ({
|
|
37985
|
+
pageNumber: Number(page.pageNumber),
|
|
37986
|
+
lineIndex,
|
|
37987
|
+
text: text.replace(/\s+/g, ' ').trim(),
|
|
37988
|
+
})));
|
|
37989
|
+
};
|
|
37990
|
+
const buildProfileCandidate = ({ group, profileId, pageNumber, lineIndex, numberIndex, itemName, quantity, unit, evidenceText, allowedMatch, role = 'item_table_quantity', confidence = 0.76, }) => ({
|
|
37991
|
+
candidateId: `${group.groupId}-${profileId}-${pageNumber}-${lineIndex}-${numberIndex}-${compactKey(itemName).slice(0, 24)}`,
|
|
37992
|
+
groupId: group.groupId,
|
|
37993
|
+
profileId,
|
|
37994
|
+
itemName: (allowedMatch === null || allowedMatch === void 0 ? void 0 : allowedMatch.item.itemName) || itemName,
|
|
37995
|
+
quantity: quantity.replace(/,/g, ''),
|
|
37996
|
+
unit,
|
|
37997
|
+
role,
|
|
37998
|
+
confidence: Math.min(0.98, confidence + ((allowedMatch === null || allowedMatch === void 0 ? void 0 : allowedMatch.score) || 0) * 0.14),
|
|
37999
|
+
pageNumber,
|
|
38000
|
+
evidenceText,
|
|
38001
|
+
matchedAllowedItemName: allowedMatch === null || allowedMatch === void 0 ? void 0 : allowedMatch.item.itemName,
|
|
38002
|
+
matchedAllowedItemKey: allowedMatch === null || allowedMatch === void 0 ? void 0 : allowedMatch.item.itemKey,
|
|
38003
|
+
matchedAllowedItemSourceId: allowedMatch === null || allowedMatch === void 0 ? void 0 : allowedMatch.item.sourceId,
|
|
38004
|
+
mappingConfidence: (allowedMatch === null || allowedMatch === void 0 ? void 0 : allowedMatch.score) || undefined,
|
|
38005
|
+
});
|
|
38006
|
+
const refrigerantLabel = (line) => {
|
|
38007
|
+
const match = line.match(/\b(?:hfc[-\s]*)?r[-\s]?(?:410\s*a?|32|134\s*a?|22|404\s*a?|125|407\s*c?)\b/i);
|
|
38008
|
+
if (!match)
|
|
38009
|
+
return '';
|
|
38010
|
+
return match[0].toUpperCase().replace(/\s+/g, ' ').replace(/^R\s*/, 'R-').replace(/R-410A$/, 'R-410 A');
|
|
38011
|
+
};
|
|
38012
|
+
const industrialGasLabel = (line) => {
|
|
38013
|
+
if (/\b(?:o2|0?2\s*gas|oxygen)\b/i.test(line))
|
|
38014
|
+
return 'Oxygen Gas';
|
|
38015
|
+
if (/\b(?:co2|c0?2|carbon\s+dioxide)\b/i.test(line))
|
|
38016
|
+
return 'CO2 Gas';
|
|
38017
|
+
if (/\bnitrogen\b/i.test(line))
|
|
38018
|
+
return 'Nitrogen Gas';
|
|
38019
|
+
if (/\bargon\b/i.test(line))
|
|
38020
|
+
return 'Argon Gas';
|
|
38021
|
+
if (/\bacetylene\b/i.test(line))
|
|
38022
|
+
return 'Acetylene';
|
|
38023
|
+
return '';
|
|
38024
|
+
};
|
|
38025
|
+
const fuelLabel = (line) => {
|
|
38026
|
+
if (/\b(?:hsd|diesel)\b/i.test(line))
|
|
38027
|
+
return 'Diesel';
|
|
38028
|
+
if (/\bpetrol\b/i.test(line))
|
|
38029
|
+
return 'Petrol';
|
|
38030
|
+
if (/\bcng\b/i.test(line))
|
|
38031
|
+
return 'CNG';
|
|
38032
|
+
if (/\bfurnace\s+oil\b/i.test(line))
|
|
38033
|
+
return 'Furnace Oil';
|
|
38034
|
+
if (/\b(?:petroleum\s+coke|petcoke|coke)\b/i.test(line))
|
|
38035
|
+
return 'Petroleum Coke';
|
|
38036
|
+
if (/\bcoal\b/i.test(line))
|
|
38037
|
+
return 'Coal';
|
|
38038
|
+
if (/\b(?:lpg|liquefied\s+petroleum)\b/i.test(line))
|
|
38039
|
+
return 'LPG';
|
|
38040
|
+
if (/\b(?:lubrication\s+oil|lube\s+oil|grease)\b/i.test(line))
|
|
38041
|
+
return 'Lubrication Oil';
|
|
38042
|
+
if (/\bkerosene\b/i.test(line))
|
|
38043
|
+
return 'Kerosene';
|
|
38044
|
+
return '';
|
|
38045
|
+
};
|
|
38046
|
+
const fireExtinguisherLabel = (line) => /\b(?:fire\s+extinguisher|extinguisher|refill|refilling)\b/i.test(line) ? 'Fire Extinguisher Refilling' : '';
|
|
38047
|
+
const sf6Label = (line) => /\b(?:sf6|sulph?ur\s+hexafluoride)\b/i.test(line) ? 'SF6 Usage' : '';
|
|
38048
|
+
const waterLabel = (line) => {
|
|
38049
|
+
if (/\b(?:tanker)\b/i.test(line))
|
|
38050
|
+
return 'Tanker Water';
|
|
38051
|
+
if (/\b(?:municipal|corporation|utility)\b/i.test(line))
|
|
38052
|
+
return 'Municipal Water';
|
|
38053
|
+
if (/\b(?:ground\s*water|borewell|bore\s*well)\b/i.test(line))
|
|
38054
|
+
return 'Groundwater';
|
|
38055
|
+
if (/\b(?:wastewater|effluent|sewage)\b/i.test(line))
|
|
38056
|
+
return 'Wastewater';
|
|
38057
|
+
return /\bwater\b/i.test(line) ? 'Water' : '';
|
|
38058
|
+
};
|
|
38059
|
+
const wasteLabel = (line) => {
|
|
38060
|
+
if (/\bhazardous\b/i.test(line))
|
|
38061
|
+
return 'Hazardous Waste';
|
|
38062
|
+
if (/\b(?:recycl|scrap)\b/i.test(line))
|
|
38063
|
+
return 'Recycled Waste';
|
|
38064
|
+
if (/\bcompost\b/i.test(line))
|
|
38065
|
+
return 'Composted Waste';
|
|
38066
|
+
if (/\blandfill\b/i.test(line))
|
|
38067
|
+
return 'Landfill Waste';
|
|
38068
|
+
return /\bwaste\b/i.test(line) ? 'Waste Generated in Operations' : '';
|
|
38069
|
+
};
|
|
38070
|
+
const businessTravelLabel = (line) => {
|
|
38071
|
+
if (/\b(?:flight|airline|air\s+travel)\b/i.test(line))
|
|
38072
|
+
return 'Air Travel';
|
|
38073
|
+
if (/\b(?:train|rail|metro)\b/i.test(line))
|
|
38074
|
+
return 'Rail Travel';
|
|
38075
|
+
if (/\b(?:hotel|room\s*night|nights?)\b/i.test(line))
|
|
38076
|
+
return 'Hotel Stay';
|
|
38077
|
+
if (/\b(?:taxi|cab|rental\s+car|car\s+rental)\b/i.test(line))
|
|
38078
|
+
return 'Rental Car';
|
|
38079
|
+
return '';
|
|
38080
|
+
};
|
|
38081
|
+
const processEmissionLabel = (line) => {
|
|
38082
|
+
if (/\bclinker\b/i.test(line))
|
|
38083
|
+
return 'Clinker';
|
|
38084
|
+
if (/\bcalcination\b/i.test(line))
|
|
38085
|
+
return 'Calcination Process';
|
|
38086
|
+
if (/\b(?:limestone|dolomite|flux)\b/i.test(line))
|
|
38087
|
+
return 'Flux calcination';
|
|
38088
|
+
if (/\b(?:hot\s+metal|ironmaking)\b/i.test(line))
|
|
38089
|
+
return 'Process Emissions- Ironmaking';
|
|
38090
|
+
if (/\bsteelmaking\b/i.test(line))
|
|
38091
|
+
return 'Process Emissions- Steelmaking';
|
|
38092
|
+
return '';
|
|
38093
|
+
};
|
|
38094
|
+
const genericMaterialLabel = (line, allowedItems) => {
|
|
38095
|
+
if (metadataOnlyPattern.test(line) && !physicalUnitPattern.test(line))
|
|
38096
|
+
return '';
|
|
38097
|
+
const best = bestAllowedItemForQuery(line, allowedItems);
|
|
38098
|
+
return (best === null || best === void 0 ? void 0 : best.item.itemName) || line.split('|').map((part) => part.trim()).find((part) => /[A-Za-z]/.test(part) && !metadataOnlyPattern.test(part)) || '';
|
|
38099
|
+
};
|
|
38100
|
+
const commuteModeLabel = (line) => {
|
|
38101
|
+
const text = normalize(line);
|
|
38102
|
+
if (/\b(bike|bikt|motorcycle)\b/.test(text))
|
|
38103
|
+
return 'Motorcycle';
|
|
38104
|
+
if (/\b(scooty|scoow|scooter)\b/.test(text))
|
|
38105
|
+
return 'Scooter';
|
|
38106
|
+
if (/\b(auto|byauto|auio)\b/.test(text))
|
|
38107
|
+
return 'Small Car Gasoline';
|
|
38108
|
+
if (/\b(car|eycar|hatchback)\b/.test(text))
|
|
38109
|
+
return 'Hatchback Gasoline';
|
|
38110
|
+
if (/\b(metro|14etro|train|rail)\b/.test(text))
|
|
38111
|
+
return 'Train Domestic Electric';
|
|
38112
|
+
if (/\b(cycle|cycl|cyct)\b/.test(text))
|
|
38113
|
+
return 'Employee commute cycle';
|
|
38114
|
+
if (/\b(bus)\b/.test(text))
|
|
38115
|
+
return 'Bus';
|
|
38116
|
+
return '';
|
|
38117
|
+
};
|
|
38118
|
+
const extractNamedQuantityCandidates = ({ profileId, group, lines, allowedItems, labelForLine, }) => lines.flatMap(({ pageNumber, lineIndex, text }) => {
|
|
38119
|
+
if (!text || (metadataOnlyPattern.test(text) && !physicalUnitPattern.test(text)))
|
|
38120
|
+
return [];
|
|
38121
|
+
const itemName = labelForLine(text, allowedItems);
|
|
38122
|
+
if (!itemName)
|
|
38123
|
+
return [];
|
|
38124
|
+
return parsePositiveNumbers(text).flatMap((entry, numberIndex) => {
|
|
38125
|
+
const unit = adjacentActivityUnit(text, entry.index, entry.value.length);
|
|
38126
|
+
if (!unit)
|
|
38127
|
+
return [];
|
|
38128
|
+
const allowedMatch = bestAllowedItemForQuery(`${itemName} ${text}`, allowedItems);
|
|
38129
|
+
return [buildProfileCandidate({
|
|
38130
|
+
group,
|
|
38131
|
+
profileId,
|
|
38132
|
+
pageNumber,
|
|
38133
|
+
lineIndex,
|
|
38134
|
+
numberIndex,
|
|
38135
|
+
itemName,
|
|
38136
|
+
quantity: entry.value,
|
|
38137
|
+
unit,
|
|
38138
|
+
evidenceText: text,
|
|
38139
|
+
allowedMatch,
|
|
38140
|
+
})];
|
|
38141
|
+
});
|
|
38142
|
+
});
|
|
38143
|
+
const extractElectricityCandidates = (group, lines, allowedItems) => {
|
|
38144
|
+
const electricityLine = /\b(?:net\s+cons\.?\s+for\s+billing|billed\s+units?|billing\s+units?|units\s+consumed|energy\s+consumption|import|export|generation|solar|renewable)\b/i;
|
|
38145
|
+
return lines.flatMap(({ pageNumber, lineIndex, text }) => {
|
|
38146
|
+
if (!electricityLine.test(text) || metadataOnlyPattern.test(text))
|
|
38147
|
+
return [];
|
|
38148
|
+
return parsePositiveNumbers(text).flatMap((entry, numberIndex) => {
|
|
38149
|
+
const unit = adjacentActivityUnit(text, entry.index, entry.value.length) || (/\bunits?\b/i.test(text) ? 'kWh' : '');
|
|
38150
|
+
if (!unit || !/\b(?:kwh|kvah|mwh)\b/i.test(unit))
|
|
38151
|
+
return [];
|
|
38152
|
+
const role = /\b(?:solar|renewable|generation|export)\b/i.test(text) ? 'component_consumption' : 'bill_level_consumption';
|
|
38153
|
+
const allowedMatch = bestAllowedItemForQuery(text, allowedItems);
|
|
38154
|
+
return [buildProfileCandidate({
|
|
38155
|
+
group,
|
|
38156
|
+
profileId: 'electricity',
|
|
38157
|
+
pageNumber,
|
|
38158
|
+
lineIndex,
|
|
38159
|
+
numberIndex,
|
|
38160
|
+
itemName: (allowedMatch === null || allowedMatch === void 0 ? void 0 : allowedMatch.item.itemName) || 'Electricity Purchased from Grid',
|
|
38161
|
+
quantity: entry.value,
|
|
38162
|
+
unit,
|
|
38163
|
+
evidenceText: text,
|
|
38164
|
+
allowedMatch,
|
|
38165
|
+
role,
|
|
38166
|
+
confidence: role === 'bill_level_consumption' ? 0.86 : 0.78,
|
|
38167
|
+
})];
|
|
38168
|
+
});
|
|
38169
|
+
});
|
|
38170
|
+
};
|
|
38171
|
+
const extractEmployeeCommutingCandidates = (group, lines, allowedItems) => {
|
|
38172
|
+
const totals = new Map();
|
|
38173
|
+
for (const { pageNumber, text } of lines) {
|
|
38174
|
+
const mode = commuteModeLabel(text);
|
|
38175
|
+
if (!mode)
|
|
38176
|
+
continue;
|
|
38177
|
+
const distanceValues = parsePositiveNumbers(text)
|
|
38178
|
+
.filter((entry) => /\bkm\b/i.test(text.slice(entry.index, entry.index + 24)) || /\bkm\b/i.test(text));
|
|
38179
|
+
const value = distanceValues.length ? distanceValues[distanceValues.length - 1].number : null;
|
|
38180
|
+
if (!value)
|
|
38181
|
+
continue;
|
|
38182
|
+
const current = totals.get(mode) || { total: 0, evidence: [], pageNumber };
|
|
38183
|
+
current.total += value;
|
|
38184
|
+
if (current.evidence.length < 4)
|
|
38185
|
+
current.evidence.push(text);
|
|
38186
|
+
totals.set(mode, current);
|
|
38187
|
+
}
|
|
38188
|
+
return [...totals.entries()].map(([mode, aggregate], index) => {
|
|
38189
|
+
const allowedMatch = bestAllowedItemForQuery(mode, allowedItems);
|
|
38190
|
+
return buildProfileCandidate({
|
|
38191
|
+
group,
|
|
38192
|
+
profileId: 'employee_commuting',
|
|
38193
|
+
pageNumber: aggregate.pageNumber,
|
|
38194
|
+
lineIndex: index,
|
|
38195
|
+
numberIndex: 0,
|
|
38196
|
+
itemName: mode,
|
|
38197
|
+
quantity: String(Number(aggregate.total.toFixed(5))),
|
|
38198
|
+
unit: 'km',
|
|
38199
|
+
evidenceText: aggregate.evidence.join(' | '),
|
|
38200
|
+
allowedMatch,
|
|
38201
|
+
role: 'aggregated_distance',
|
|
38202
|
+
confidence: 0.88,
|
|
38203
|
+
});
|
|
38204
|
+
});
|
|
38205
|
+
};
|
|
38206
|
+
const extractForProfile = (profileId, group, lines, allowedItems) => {
|
|
38207
|
+
if (profileId === 'electricity')
|
|
38208
|
+
return extractElectricityCandidates(group, lines, allowedItems);
|
|
38209
|
+
if (profileId === 'employee_commuting')
|
|
38210
|
+
return extractEmployeeCommutingCandidates(group, lines, allowedItems);
|
|
38211
|
+
const labelForProfile = {
|
|
38212
|
+
fuel_combustion: (line) => fuelLabel(line),
|
|
38213
|
+
lpg_usage: (line) => fuelLabel(line),
|
|
38214
|
+
refrigerants: (line) => refrigerantLabel(line),
|
|
38215
|
+
industrial_gases: (line) => industrialGasLabel(line),
|
|
38216
|
+
business_travel: (line) => businessTravelLabel(line),
|
|
38217
|
+
fire_extinguisher: (line) => fireExtinguisherLabel(line),
|
|
38218
|
+
sf6_usage: (line) => sf6Label(line),
|
|
38219
|
+
water: (line) => waterLabel(line),
|
|
38220
|
+
waste: (line) => wasteLabel(line),
|
|
38221
|
+
process_emissions: (line) => processEmissionLabel(line),
|
|
38222
|
+
purchased_goods: genericMaterialLabel,
|
|
38223
|
+
generic_material: genericMaterialLabel,
|
|
38224
|
+
};
|
|
38225
|
+
const labelForLine = labelForProfile[profileId] || genericMaterialLabel;
|
|
38226
|
+
return extractNamedQuantityCandidates({ profileId, group, lines, allowedItems, labelForLine });
|
|
38227
|
+
};
|
|
38228
|
+
const extractBulkBillAgentProfileCandidates = ({ mappingContext = {}, pages = [], group, documentText = '', }) => {
|
|
38229
|
+
const allowedItems = Array.isArray(mappingContext.allowedItems) ? mappingContext.allowedItems : [];
|
|
38230
|
+
const lines = profileTextLines(pages, group, documentText);
|
|
38231
|
+
const groupText = documentText || lines.map((line) => line.text).join('\n');
|
|
38232
|
+
const primaryProfile = getPrimaryBulkBillAgentProfile(mappingContext, groupText);
|
|
38233
|
+
const profiles = getBulkBillAgentProfilesForMappingContext(mappingContext, groupText)
|
|
38234
|
+
.map((entry) => entry.profile.id)
|
|
38235
|
+
.filter((profileId, index, profileIds) => profileIds.indexOf(profileId) === index);
|
|
38236
|
+
const extractionProfiles = profiles.length ? profiles : [primaryProfile.id];
|
|
38237
|
+
const candidates = extractionProfiles.flatMap((profileId) => extractForProfile(profileId, group, lines, allowedItems));
|
|
38238
|
+
const seen = new Set();
|
|
38239
|
+
return candidates
|
|
38240
|
+
.sort((left, right) => right.confidence - left.confidence)
|
|
38241
|
+
.filter((candidate) => {
|
|
38242
|
+
const key = [candidate.profileId, candidate.matchedAllowedItemKey || candidate.itemName, candidate.quantity, candidate.unit, candidate.pageNumber].join('|');
|
|
38243
|
+
if (seen.has(key))
|
|
38244
|
+
return false;
|
|
38245
|
+
seen.add(key);
|
|
38246
|
+
return true;
|
|
38247
|
+
})
|
|
38248
|
+
.slice(0, 30);
|
|
38249
|
+
};
|
|
37901
38250
|
|
|
37902
38251
|
// User-specific configurations mapping
|
|
37903
38252
|
const USER_CONFIGS = {
|
|
@@ -44701,5 +45050,5 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
44701
45050
|
getRCOConfigByName: getRCOConfigByName
|
|
44702
45051
|
});
|
|
44703
45052
|
|
|
44704
|
-
export { ALL_SCOPES_3_RCO, API_ENDPOINTS, API_SCOPE3_CEMENT_CONFIG, BILL_CALCULATION_CONFIGS, BULK_BILL_AGENT_PROFILES, BillManager, CCTS_ALLSCOPES_CEMENT, CCTS_CALCINATION_PRODUCTS, CCTS_ELECTRICITY_PRODUCTS, CCTS_FIRE_EXTINGUISHER_PRODUCTS, CCTS_FUEL_COMBUSTION_PRODUCTS, CCTS_LPG_PRODUCTS, CCTS_MINING_OPERATIONS_PRODUCTS, CCTS_ONSITE_POWER_PRODUCTS, CCTS_PURCHASED_ELECTRICITY, CCTS_REFRIGERANTS, CCTS_SCOPE1_CEMENT, CCTS_SCOPE2_CEMENT, CCTS_SF6_PRODUCTS, CCTS_TABLE_COLUMNS, DEFAULT_BILL_MATCHING_CONFIG, EmissionSourceGenerator, FRONTEND_INDUSTRY_CONFIGS, HTTP_STATUS, INDUSTRIES_CONFIG, INDUSTRY_MAPPING, INDUSTRY_SPECIFIC_FIELDS, INTENSITY_FIELD_LABELS, ISO_CATEGORIES_PACKAGING, index as Industries, UI_FEATURES, WATER_PRODUCTS$2 as WATER_PRODUCTS, addItemForUser, buildBulkBillAgentPromptConfig, buildUserConfigItemKey, calculateCCTSEmission, calculateIntensityMetrics, categorizeApiItem, cleanValue, createBillManager, createCapitalizedMonthMapping, createEmissionSourceGenerator, createMonthMapping, debugCarbonIntensityMapping, extractCarbonIntensityData, formatEmissionValue, formatIntensityValue, formatKPIEmission, formatMonthlyEmission, formatPercentage, getAllConfig, getApiIndustryType, getAvailableFieldsForIndustry, getBulkBillAgentProfile, getBulkBillAgentProfilesForMappingContext, getCombinedBackendConfig, getIndustryBackendConfig, getIndustryConfig, getIndustryFieldConfig, getIntensityFormulas, getItemsForUser, getPlantNameConfig, getPrimaryBulkBillAgentProfile, getRCOConfigByName, getScope3ConfigByName, getUserNameBackendConfig, getUserNameScopeConfig, hasIntensities, isUIFeatureEnabled, listBulkBillAgentProfiles, mapIndustryToApiType, mergeUserItemsIntoIndustryConfig, normalizeConfigKeyText, normalizeConfigText, resolveEmissionFactorsForUser, sameUserConfigText, sanitizeNumber, scoreBulkBillAgentProfile, supportsIntensityCalculations, updateItemEmissionFactorForUser, updateSdkItemEmissionFactorForUser, validateCarbonIntensityData };
|
|
45053
|
+
export { ALL_SCOPES_3_RCO, API_ENDPOINTS, API_SCOPE3_CEMENT_CONFIG, BILL_CALCULATION_CONFIGS, BULK_BILL_AGENT_PROFILES, BillManager, CCTS_ALLSCOPES_CEMENT, CCTS_CALCINATION_PRODUCTS, CCTS_ELECTRICITY_PRODUCTS, CCTS_FIRE_EXTINGUISHER_PRODUCTS, CCTS_FUEL_COMBUSTION_PRODUCTS, CCTS_LPG_PRODUCTS, CCTS_MINING_OPERATIONS_PRODUCTS, CCTS_ONSITE_POWER_PRODUCTS, CCTS_PURCHASED_ELECTRICITY, CCTS_REFRIGERANTS, CCTS_SCOPE1_CEMENT, CCTS_SCOPE2_CEMENT, CCTS_SF6_PRODUCTS, CCTS_TABLE_COLUMNS, DEFAULT_BILL_MATCHING_CONFIG, EmissionSourceGenerator, FRONTEND_INDUSTRY_CONFIGS, HTTP_STATUS, INDUSTRIES_CONFIG, INDUSTRY_MAPPING, INDUSTRY_SPECIFIC_FIELDS, INTENSITY_FIELD_LABELS, ISO_CATEGORIES_PACKAGING, index as Industries, UI_FEATURES, WATER_PRODUCTS$2 as WATER_PRODUCTS, addItemForUser, buildBulkBillAgentPromptConfig, buildUserConfigItemKey, calculateCCTSEmission, calculateIntensityMetrics, categorizeApiItem, cleanValue, createBillManager, createCapitalizedMonthMapping, createEmissionSourceGenerator, createMonthMapping, debugCarbonIntensityMapping, extractBulkBillAgentProfileCandidates, extractCarbonIntensityData, formatEmissionValue, formatIntensityValue, formatKPIEmission, formatMonthlyEmission, formatPercentage, getAllConfig, getApiIndustryType, getAvailableFieldsForIndustry, getBulkBillAgentProfile, getBulkBillAgentProfilesForMappingContext, getCombinedBackendConfig, getIndustryBackendConfig, getIndustryConfig, getIndustryFieldConfig, getIntensityFormulas, getItemsForUser, getPlantNameConfig, getPrimaryBulkBillAgentProfile, getRCOConfigByName, getScope3ConfigByName, getUserNameBackendConfig, getUserNameScopeConfig, hasIntensities, isUIFeatureEnabled, listBulkBillAgentProfiles, mapIndustryToApiType, mergeUserItemsIntoIndustryConfig, normalizeConfigKeyText, normalizeConfigText, resolveEmissionFactorsForUser, sameUserConfigText, sanitizeNumber, scoreBulkBillAgentProfile, supportsIntensityCalculations, updateItemEmissionFactorForUser, updateSdkItemEmissionFactorForUser, validateCarbonIntensityData };
|
|
44705
45054
|
//# sourceMappingURL=index.esm.js.map
|