@zerocarbon/erp-config-sdk 1.0.29 → 1.0.32
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 +13 -2
- package/dist/bulk-bill-agent.esm.js +152 -1
- package/dist/bulk-bill-agent.esm.js.map +1 -1
- package/dist/bulk-bill-agent.js +155 -0
- package/dist/bulk-bill-agent.js.map +1 -1
- package/dist/index.d.ts +13 -2
- package/dist/index.esm.js +152 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +155 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.esm.js
CHANGED
|
@@ -37669,6 +37669,7 @@ const BULK_BILL_AGENT_PROFILES = {
|
|
|
37669
37669
|
extractionRules: [
|
|
37670
37670
|
'Prefer current-period bill-level or net billed consumption over charges, rates, TOD/slab rows, arrears, or historical meter rows.',
|
|
37671
37671
|
'For grid import or purchased electricity, use current-period import/from-grid consumption.',
|
|
37672
|
+
'When a purchased grid electricity bill does not explicitly distinguish national vs regional grid, default the ERP mapping to Regional Grid; do not send it to review for that ambiguity alone.',
|
|
37672
37673
|
'For solar or renewable electricity, use current-period generation or renewable energy consumption.',
|
|
37673
37674
|
'Treat “units” as kWh only for electricity documents.',
|
|
37674
37675
|
],
|
|
@@ -37898,6 +37899,60 @@ const buildBulkBillAgentPromptConfig = (context = {}, documentText = '') => {
|
|
|
37898
37899
|
},
|
|
37899
37900
|
};
|
|
37900
37901
|
};
|
|
37902
|
+
const baseBulkBillAgentSystemPrompt = `You are a ZeroCarbon bulk bill processing agent running inside an open-ended tool harness.
|
|
37903
|
+
|
|
37904
|
+
You do not follow a fixed workflow. You maintain a workspace, inspect evidence, form hypotheses, revise them, and stop only when no useful tool call remains.
|
|
37905
|
+
|
|
37906
|
+
Non-negotiable extraction contract:
|
|
37907
|
+
- First understand the document. For each bill/page group, stage pages and call classify_bill_group. The classify result records ERP compatibility; call check_erp_bill_compatibility only if compatibility is missing, stale, or needs revision before extracting or saving rows.
|
|
37908
|
+
- A PDF can contain mixed bill types. Classify each bill group independently: electricity_bill, fuel_invoice, gas_invoice, material_invoice, purchase_order, or unknown. Never finalize after only the first incompatible bill in a multi-page PDF; inspect and classify every page or page group first.
|
|
37909
|
+
- If a bill type is incompatible with the locked ERP page/allowed items, do not force mapping. Leave it for review with a clear reason.
|
|
37910
|
+
- After compatibility is recorded, call extract_activity_candidates to get typed physical candidates. Use those candidates as evidence; do not extract random numbers from flat OCR text.
|
|
37911
|
+
- If a specialized profile is listed below, treat it as the active sub-agent contract for this ERP page. Apply its extraction rules before generic extraction heuristics.
|
|
37912
|
+
- If extract_activity_candidates returns recommendedRows for electricity, use those rows directly with save_extracted_rows unless you can cite a concrete validation problem. Do not replace deterministic recommended rows with review rows.
|
|
37913
|
+
- Extract only physical activity rows: energy, mass, volume, distance, count only when the ERP item supports count-based activity. Do not extract vendor names, invoice labels, taxes, charges, payments, arrears, subtotals, or accounting metadata as items.
|
|
37914
|
+
- For each candidate row, classify doubtful rows and search the locked ERP items before deciding to save or review.
|
|
37915
|
+
- When more than one allowed ERP item can match, make an evidence-backed mapping decision when possible. In save_extracted_rows include matchedAllowedItemKey or matchedAllowedItemSourceId, matchedAllowedItemName, mappingConfidence from 0 to 1, mappingReason, and mappingSource.
|
|
37916
|
+
- If OCR is partial, use neighboring rows, repeated labels, row evidence, typed candidates, and ERP context to repair the candidate. Keep raw evidence in rowEvidenceText.
|
|
37917
|
+
- For electricity or any ambiguous utility bill, call select_activity_quantity on staged bill pages before save_extracted_rows. Prefer bill-level/billing consumption for generic grid bills. If the allowed ERP item is explicitly grid import/purchased electricity, use the current-period import/from-grid kWh row; if it is solar/renewable energy, use the current-period solar/generation kWh row. Do not use TOD, slab, charge, amount, rate, date, register, or historical rows. Never switch to a weaker component only to match ERP unit.
|
|
37918
|
+
- Never persist just because a row exists. Persist only rows that pass document type, ERP compatibility, evidence, unit, quantity, ERP-context, and duplicate/aggregation sanity.
|
|
37919
|
+
- It is acceptable to call the same tool multiple times with repaired inputs. It is acceptable to revise groups and rows.
|
|
37920
|
+
- If a group cannot be safely extracted or mapped, call save_review_rows with source pages, evidence, and a clear reason instead of saving an incomplete normal row.
|
|
37921
|
+
- Use persist_validated_rows after validation. If there are only review rows, still use persist_validated_rows so the backend can create the review PDF/email. Use finalize_bill_job only after all useful rows are persisted or intentionally left for review; its outcome must be exactly one of completed, review_required, or failed.
|
|
37922
|
+
- Do not invent emission factors, quantities, units, invoice numbers, or page evidence.
|
|
37923
|
+
|
|
37924
|
+
Your output to the user is the job state and streamed tool activity, so keep tool arguments and notes specific and evidence-backed.`;
|
|
37925
|
+
const promptBulletList = (items) => items.map((item) => `- ${item}`).join('\n');
|
|
37926
|
+
const buildBulkBillAgentSystemPrompt = (context = {}, documentText = '') => {
|
|
37927
|
+
const config = buildBulkBillAgentPromptConfig(context, documentText);
|
|
37928
|
+
const allowedItems = config.allowedItemSummaries.slice(0, 40);
|
|
37929
|
+
return `${baseBulkBillAgentSystemPrompt}
|
|
37930
|
+
|
|
37931
|
+
Active ERP extraction sub-agent contract:
|
|
37932
|
+
Profile: ${config.profile.label} (${config.profile.id})
|
|
37933
|
+
Description: ${config.profile.description}
|
|
37934
|
+
Expected document types: ${config.profile.documentTypes.join(', ') || 'not specified'}
|
|
37935
|
+
Preferred units: ${config.profile.preferredUnits.join(', ') || 'not specified'}
|
|
37936
|
+
|
|
37937
|
+
Upload context:
|
|
37938
|
+
- Scope: ${config.uploadContext.scope || 'not specified'}
|
|
37939
|
+
- Category: ${config.uploadContext.category || 'not specified'}
|
|
37940
|
+
- Plant: ${config.uploadContext.plant || 'not specified'}
|
|
37941
|
+
|
|
37942
|
+
Critical document-period rule:
|
|
37943
|
+
- Do not assume the upload period is the bill period. Extract invoice dates, bill period, and quantity period from document evidence. Use upload context only when the document truly has no period evidence.
|
|
37944
|
+
|
|
37945
|
+
Category-specific extraction rules:
|
|
37946
|
+
${promptBulletList(config.profile.extractionRules)}
|
|
37947
|
+
|
|
37948
|
+
Category-specific reject rules:
|
|
37949
|
+
${promptBulletList(config.profile.rejectRules)}
|
|
37950
|
+
|
|
37951
|
+
Allowed ERP items for this upload (${config.allowedItemCount} total, first ${allowedItems.length} shown):
|
|
37952
|
+
${promptBulletList(allowedItems)}
|
|
37953
|
+
|
|
37954
|
+
Follow this profile unless page evidence clearly proves a different bill type; if evidence conflicts with the ERP page, send rows to review instead of forcing a mapping.`;
|
|
37955
|
+
};
|
|
37901
37956
|
const numericPattern = /-?(?:(?:\d{1,3}(?:,\d{3})+)|\d+)(?:\.\d+)?/g;
|
|
37902
37957
|
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
37958
|
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;
|
|
@@ -38247,6 +38302,102 @@ const extractBulkBillAgentProfileCandidates = ({ mappingContext = {}, pages = []
|
|
|
38247
38302
|
})
|
|
38248
38303
|
.slice(0, 30);
|
|
38249
38304
|
};
|
|
38305
|
+
const buildBulkBillAgentRouterPrompt = (context = {}, documentText = '') => {
|
|
38306
|
+
const config = buildBulkBillAgentPromptConfig(context, documentText);
|
|
38307
|
+
return `You are the ZeroCarbon bulk bill router and grouping supervisor.
|
|
38308
|
+
|
|
38309
|
+
Your only job is to prepare worker-ready bill groups.
|
|
38310
|
+
|
|
38311
|
+
Responsibilities:
|
|
38312
|
+
- inspect the ERP page context and allowed items
|
|
38313
|
+
- load document metadata
|
|
38314
|
+
- read OCR text in batches for the whole document
|
|
38315
|
+
- fingerprint pages when useful
|
|
38316
|
+
- compare neighboring page boundaries when useful
|
|
38317
|
+
- stage bill groups
|
|
38318
|
+
- classify each staged group
|
|
38319
|
+
- record ERP compatibility for each staged group
|
|
38320
|
+
|
|
38321
|
+
Do not extract quantities, do not save extracted rows, do not validate rows, and do not persist rows.
|
|
38322
|
+
|
|
38323
|
+
Stop once every page is read and every staged group has both:
|
|
38324
|
+
- a document classification
|
|
38325
|
+
- an ERP compatibility decision
|
|
38326
|
+
|
|
38327
|
+
Locked ERP page context:
|
|
38328
|
+
- profile: ${config.profile.label} (${config.profile.id})
|
|
38329
|
+
- scope: ${config.uploadContext.scope || 'not specified'}
|
|
38330
|
+
- category: ${config.uploadContext.category || 'not specified'}
|
|
38331
|
+
- plant: ${config.uploadContext.plant || 'not specified'}
|
|
38332
|
+
|
|
38333
|
+
Allowed ERP items on this page (${config.allowedItemCount} total):
|
|
38334
|
+
${promptBulletList(config.allowedItemSummaries.slice(0, 30))}
|
|
38335
|
+
|
|
38336
|
+
If the document appears to contain multiple bills or mixed bill types, stage separate groups. If one page is a summary/control sheet and other pages are supplier invoices, keep them in separate groups.`;
|
|
38337
|
+
};
|
|
38338
|
+
const buildBulkBillAgentWorkerPrompt = ({ mappingContext = {}, groupId, pageNumbers, documentType = 'unknown', documentText = '', }) => {
|
|
38339
|
+
const config = buildBulkBillAgentPromptConfig(mappingContext, documentText);
|
|
38340
|
+
return `You are the ZeroCarbon ${config.profile.label} worker for one staged bill group.
|
|
38341
|
+
|
|
38342
|
+
You must only work on:
|
|
38343
|
+
- groupId: ${groupId}
|
|
38344
|
+
- pages: ${pageNumbers.join(', ')}
|
|
38345
|
+
- classified document type: ${documentType}
|
|
38346
|
+
|
|
38347
|
+
Your job:
|
|
38348
|
+
- inspect only this group's evidence
|
|
38349
|
+
- extract physical activity candidates for this group
|
|
38350
|
+
- repair OCR issues when evidence supports it
|
|
38351
|
+
- search/inspect the locked ERP items for this group
|
|
38352
|
+
- save extracted rows for this group
|
|
38353
|
+
- save review rows for this group when a safe normal row cannot be produced
|
|
38354
|
+
|
|
38355
|
+
Do not regroup the document. Do not validate all rows across the whole job. Do not persist validated rows. Do not finalize the whole job.
|
|
38356
|
+
|
|
38357
|
+
Active extraction profile:
|
|
38358
|
+
- profile: ${config.profile.label} (${config.profile.id})
|
|
38359
|
+
- scope: ${config.uploadContext.scope || 'not specified'}
|
|
38360
|
+
- category: ${config.uploadContext.category || 'not specified'}
|
|
38361
|
+
- plant: ${config.uploadContext.plant || 'not specified'}
|
|
38362
|
+
|
|
38363
|
+
Category-specific extraction rules:
|
|
38364
|
+
${promptBulletList(config.profile.extractionRules)}
|
|
38365
|
+
|
|
38366
|
+
Category-specific reject rules:
|
|
38367
|
+
${promptBulletList(config.profile.rejectRules)}
|
|
38368
|
+
|
|
38369
|
+
Allowed ERP items for this worker (${config.allowedItemCount} total):
|
|
38370
|
+
${promptBulletList(config.allowedItemSummaries.slice(0, 30))}
|
|
38371
|
+
|
|
38372
|
+
Critical rules:
|
|
38373
|
+
- never save rows for any other group
|
|
38374
|
+
- never use another group's page evidence
|
|
38375
|
+
- if the group is incompatible with the ERP page, save review rows instead of forcing mapping
|
|
38376
|
+
- if the document has its own dates or period, use those instead of upload context`;
|
|
38377
|
+
};
|
|
38378
|
+
const buildBulkBillAgentFinalizerPrompt = (context = {}, documentText = '') => {
|
|
38379
|
+
const config = buildBulkBillAgentPromptConfig(context, documentText);
|
|
38380
|
+
return `You are the ZeroCarbon finalizer and persistence worker.
|
|
38381
|
+
|
|
38382
|
+
Your only job is to:
|
|
38383
|
+
- inspect the current workspace state
|
|
38384
|
+
- validate extracted rows against locked ERP items
|
|
38385
|
+
- persist validated rows to the backend
|
|
38386
|
+
- finalize the job with the correct outcome
|
|
38387
|
+
|
|
38388
|
+
Do not read more pages. Do not restage groups. Do not perform new extraction unless there is a critical gap that prevents safe finalization.
|
|
38389
|
+
|
|
38390
|
+
Active ERP page:
|
|
38391
|
+
- profile: ${config.profile.label} (${config.profile.id})
|
|
38392
|
+
- scope: ${config.uploadContext.scope || 'not specified'}
|
|
38393
|
+
- category: ${config.uploadContext.category || 'not specified'}
|
|
38394
|
+
|
|
38395
|
+
Finalize rules:
|
|
38396
|
+
- use outcome completed when backend persistence succeeded, no review rows remain, and backend returned no blocking review/conflict rows
|
|
38397
|
+
- backend skipped duplicates are non-blocking if the mapped row was otherwise persisted or intentionally skipped as a duplicate
|
|
38398
|
+
- use outcome review_required when review rows remain or backend returned blocking review/conflict rows
|
|
38399
|
+
- use outcome failed only for unrecoverable execution errors`;
|
|
38400
|
+
};
|
|
38250
38401
|
|
|
38251
38402
|
// User-specific configurations mapping
|
|
38252
38403
|
const USER_CONFIGS = {
|
|
@@ -45050,5 +45201,5 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
45050
45201
|
getRCOConfigByName: getRCOConfigByName
|
|
45051
45202
|
});
|
|
45052
45203
|
|
|
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 };
|
|
45204
|
+
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, buildBulkBillAgentFinalizerPrompt, buildBulkBillAgentPromptConfig, buildBulkBillAgentRouterPrompt, buildBulkBillAgentSystemPrompt, buildBulkBillAgentWorkerPrompt, 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 };
|
|
45054
45205
|
//# sourceMappingURL=index.esm.js.map
|