@carbonstopper/agent-mcp 0.1.47 → 0.1.49
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/AGENTS.md +2 -2
- package/README.md +36 -37
- package/dist/apipath.d.ts +31 -31
- package/dist/apipath.js +34 -33
- package/dist/apipath.js.map +1 -1
- package/dist/cbam-report-generation.d.ts +20 -0
- package/dist/cbam-report-generation.js +174 -0
- package/dist/cbam-report-generation.js.map +1 -0
- package/dist/client.d.ts +4 -0
- package/dist/client.js +8 -3
- package/dist/client.js.map +1 -1
- package/dist/logger.js +4 -3
- package/dist/logger.js.map +1 -1
- package/dist/response.d.ts +1 -1
- package/dist/response.js +23 -0
- package/dist/response.js.map +1 -1
- package/dist/server.js +25 -0
- package/dist/server.js.map +1 -1
- package/dist/tools.d.ts +4 -3
- package/dist/tools.js +319 -308
- package/dist/tools.js.map +1 -1
- package/docs/{cbam2-agent-integration-guide.md → cbam-agent-integration-guide.md} +196 -205
- package/docs/schema-audit.md +19 -20
- package/package.json +1 -1
package/dist/tools.js
CHANGED
|
@@ -516,36 +516,40 @@ const enterpriseEmissionComputationUpdateSchema = z.object({
|
|
|
516
516
|
unit: z.string().optional().describe("Total emission unit. Agent normally should omit this unless backend requires a known display unit."),
|
|
517
517
|
sourceList: z.array(enterpriseEmissionSourceUpdateSchema).min(1).describe("Emission source updates under this computation. Every item must include sourceId."),
|
|
518
518
|
});
|
|
519
|
-
const
|
|
519
|
+
const cbamLanguage = z.enum(["zh", "en"])
|
|
520
520
|
.optional()
|
|
521
|
-
.describe("Response language for this
|
|
522
|
-
const
|
|
521
|
+
.describe("Response language for this CBAM call. Omit to use Chinese; supported values are zh and en.");
|
|
522
|
+
const cbamCode = z.union([
|
|
523
523
|
z.number().int().nonnegative(),
|
|
524
524
|
z.string().trim().regex(/^\d+$/, "Expected a numeric CBAM code"),
|
|
525
525
|
]);
|
|
526
|
-
const
|
|
526
|
+
const cbamZeroOne = z.union([
|
|
527
527
|
z.literal(0),
|
|
528
528
|
z.literal(1),
|
|
529
529
|
z.literal("0"),
|
|
530
530
|
z.literal("1"),
|
|
531
531
|
]);
|
|
532
|
-
const
|
|
532
|
+
const cbamDate = z.string().trim()
|
|
533
533
|
.regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$/, "Expected yyyy-MM-dd")
|
|
534
534
|
.describe("Calendar date in yyyy-MM-dd format.");
|
|
535
|
-
const
|
|
535
|
+
const cbamReadFields = {
|
|
536
536
|
sessionId,
|
|
537
537
|
...skillTraceFields,
|
|
538
|
-
lang:
|
|
538
|
+
lang: cbamLanguage,
|
|
539
539
|
};
|
|
540
|
-
const
|
|
541
|
-
...
|
|
540
|
+
const cbamWriteFields = {
|
|
541
|
+
...cbamReadFields,
|
|
542
542
|
idempotencyKey: idempotencyKey.max(128),
|
|
543
543
|
};
|
|
544
|
-
const
|
|
545
|
-
|
|
546
|
-
|
|
544
|
+
const cbamApprovalFields = {
|
|
545
|
+
confirmed: z.boolean().optional()
|
|
546
|
+
.describe("Trusted Agent wrapper approval flag. For high-risk actions the wrapper must inject true only after the existing LangGraph approval interrupt is approved."),
|
|
547
547
|
};
|
|
548
|
-
const
|
|
548
|
+
const cbamConfirmedWriteFields = {
|
|
549
|
+
...cbamWriteFields,
|
|
550
|
+
...cbamApprovalFields,
|
|
551
|
+
};
|
|
552
|
+
const cbamReferenceType = z.enum([
|
|
549
553
|
"ORGANIZATION",
|
|
550
554
|
"FACTORY",
|
|
551
555
|
"COUNTRY",
|
|
@@ -559,7 +563,7 @@ const cbam2ReferenceType = z.enum([
|
|
|
559
563
|
"DEFAULT_SALE",
|
|
560
564
|
"CARBON_TAX_CANDIDATE",
|
|
561
565
|
]);
|
|
562
|
-
const
|
|
566
|
+
const cbamSection = z.enum([
|
|
563
567
|
"GENERAL_INFO",
|
|
564
568
|
"PROCESS",
|
|
565
569
|
"PRECURSOR",
|
|
@@ -572,7 +576,7 @@ const cbam2Section = z.enum([
|
|
|
572
576
|
"DATA_QUALITY",
|
|
573
577
|
"RESULT_SUMMARY",
|
|
574
578
|
]);
|
|
575
|
-
const
|
|
579
|
+
const cbamItemType = z.enum([
|
|
576
580
|
"PROCESS",
|
|
577
581
|
"PRECURSOR",
|
|
578
582
|
"SOURCE_FLOW",
|
|
@@ -581,30 +585,30 @@ const cbam2ItemType = z.enum([
|
|
|
581
585
|
"CARBON_TAX",
|
|
582
586
|
"DATA_QUALITY",
|
|
583
587
|
]);
|
|
584
|
-
function
|
|
588
|
+
function cbamCoordinate(minimum, maximum, name) {
|
|
585
589
|
return z.string().trim().min(1).max(50)
|
|
586
590
|
.refine((value) => Number.isFinite(Number(value)), `${name} must be a decimal number`)
|
|
587
591
|
.refine((value) => Number(value) >= minimum && Number(value) <= maximum, `${name} must be between ${minimum} and ${maximum}`);
|
|
588
592
|
}
|
|
589
|
-
const
|
|
593
|
+
const cbamFactoryForm = z.object({
|
|
590
594
|
factorName: z.string().trim().min(1).max(100).describe("Factory Chinese or local name."),
|
|
591
|
-
orgId: longId.describe("Organization id returned by
|
|
595
|
+
orgId: longId.describe("Organization id returned by cbam_reference_search with type ORGANIZATION."),
|
|
592
596
|
factoryCode: z.string().max(100).optional().describe("Optional globally unique factory code. Omit it on create to let the backend generate one; preserve the returned value on update."),
|
|
593
597
|
factoryNameEn: z.string().trim().min(1).max(200).describe("Factory English name."),
|
|
594
|
-
country: z.string().trim().min(1).max(100).describe("Country dictionary value returned by
|
|
598
|
+
country: z.string().trim().min(1).max(100).describe("Country dictionary value returned by cbam_reference_search with type COUNTRY."),
|
|
595
599
|
locationCode: z.string().trim().min(1).max(100).describe("UN/LOCODE or supported location code."),
|
|
596
600
|
city: z.string().trim().min(1).max(100),
|
|
597
601
|
detailedAddress: z.string().trim().min(1).max(500),
|
|
598
602
|
postalCode: z.string().trim().min(1).max(30),
|
|
599
603
|
postOfficeBox: z.string().trim().min(1).max(100),
|
|
600
|
-
longitude:
|
|
601
|
-
latitude:
|
|
604
|
+
longitude: cbamCoordinate(-180, 180, "longitude"),
|
|
605
|
+
latitude: cbamCoordinate(-90, 90, "latitude"),
|
|
602
606
|
economicActivity: z.string().max(1000).optional(),
|
|
603
607
|
authorizedRepresentative: z.string().max(100).optional(),
|
|
604
608
|
email: z.union([z.string().email().max(100), z.literal("")]).optional(),
|
|
605
609
|
mobile: z.string().max(50).optional(),
|
|
606
610
|
});
|
|
607
|
-
const
|
|
611
|
+
const cbamVerification = z.object({
|
|
608
612
|
corporateName: z.string().max(200).optional(),
|
|
609
613
|
detailedAddress: z.string().max(500).optional(),
|
|
610
614
|
city: z.string().max(100).optional(),
|
|
@@ -618,39 +622,39 @@ const cbam2Verification = z.object({
|
|
|
618
622
|
certificationName: z.string().max(200).optional(),
|
|
619
623
|
registrationNo: z.string().max(100).optional(),
|
|
620
624
|
});
|
|
621
|
-
const
|
|
625
|
+
const cbamReportForm = z.object({
|
|
622
626
|
reportName: z.string().trim().min(1).max(200),
|
|
623
627
|
orgId: longId.describe("Organization id for the report. It must be visible to the current user."),
|
|
624
|
-
startDate:
|
|
625
|
-
endDate:
|
|
626
|
-
factoryId: longId.describe("Factory id returned by
|
|
627
|
-
include:
|
|
628
|
-
verification:
|
|
628
|
+
startDate: cbamDate,
|
|
629
|
+
endDate: cbamDate,
|
|
630
|
+
factoryId: longId.describe("Factory id returned by cbam_reference_search or cbam_factory_save."),
|
|
631
|
+
include: cbamZeroOne.describe("Heat-power cogeneration flag. 0=include heat-power data; 1=do not include it, matching the migrated CBAM convention."),
|
|
632
|
+
verification: cbamVerification.optional().describe("Optional verification organization information. Omit on update to preserve the current verification record."),
|
|
629
633
|
});
|
|
630
|
-
const
|
|
634
|
+
const cbamProcessDefinition = z.object({
|
|
631
635
|
id: longId.optional().describe("Existing process id for update. Omit to create a new process."),
|
|
632
636
|
processName: z.string().trim().min(1).max(200),
|
|
633
|
-
productCategoryId: longId.describe("Product category id returned by
|
|
637
|
+
productCategoryId: longId.describe("Product category id returned by cbam_reference_search."),
|
|
634
638
|
preId: z.string().optional().describe("Comma-separated preceding process ids from this report. Use an empty string to clear."),
|
|
635
639
|
elseProduct: z.string().optional().describe("Comma-separated default-product ids for the selected category. Use an empty string to clear."),
|
|
636
640
|
preProcess: z.string().optional().describe("Comma-separated precursor ids from this report. Use an empty string to clear."),
|
|
637
641
|
orderNum: z.number().int().min(1).max(10).optional(),
|
|
638
|
-
productRoute: z.string().optional().describe("Comma-separated default-process route ids returned by
|
|
639
|
-
includeType:
|
|
642
|
+
productRoute: z.string().optional().describe("Comma-separated default-process route ids returned by cbam_reference_search."),
|
|
643
|
+
includeType: cbamZeroOne.optional().describe("Production-route selection mode: 0=automatic, 1=manual."),
|
|
640
644
|
});
|
|
641
|
-
const
|
|
645
|
+
const cbamPrecursorDefinition = z.object({
|
|
642
646
|
id: longId.optional().describe("Existing precursor id for update. Omit to create a new precursor."),
|
|
643
647
|
preName: z.string().trim().min(1).max(200),
|
|
644
|
-
productCategoryId: longId.describe("Product category id returned by
|
|
645
|
-
countryCode: z.string().max(100).optional().describe("Country dictionary value returned by
|
|
648
|
+
productCategoryId: longId.describe("Product category id returned by cbam_reference_search."),
|
|
649
|
+
countryCode: z.string().max(100).optional().describe("Country dictionary value returned by cbam_reference_search; omit or clear when not yet known."),
|
|
646
650
|
orderNum: z.number().int().min(1).max(20).optional(),
|
|
647
|
-
productRoute: z.string().optional().describe("Comma-separated default-process route ids returned by
|
|
651
|
+
productRoute: z.string().optional().describe("Comma-separated default-process route ids returned by cbam_reference_search."),
|
|
648
652
|
});
|
|
649
|
-
const
|
|
653
|
+
const cbamSourceFlow = z.object({
|
|
650
654
|
id: longId.optional().describe("Existing source-flow id for update. Omit to create a new row."),
|
|
651
655
|
productProcessId: longId.describe("Owning process id from the same report."),
|
|
652
|
-
processMethod:
|
|
653
|
-
sourceType:
|
|
656
|
+
processMethod: cbamCode.describe("Process-method code returned by CBAM_ENUM reference data."),
|
|
657
|
+
sourceType: cbamCode.describe("Source-flow type code returned by CBAM_ENUM reference data."),
|
|
654
658
|
sourceName: z.string().trim().min(1).max(200),
|
|
655
659
|
activityData: nonNegativeNumericValue.optional().describe("Activity amount. Required for sourceType=1 with processMethod 1/2/3 and for sourceType=2 with processMethod 4/5."),
|
|
656
660
|
activityUnit: z.string().max(100).optional().describe("Unit of activityData."),
|
|
@@ -660,7 +664,7 @@ const cbam2SourceFlow = z.object({
|
|
|
660
664
|
emissionCoefficientUnit: z.string().max(100).optional().describe("Emission-coefficient unit. For sourceType=1, value tCO2/TJ additionally requires lowHeat."),
|
|
661
665
|
conversionRate: nonNegativeNumericValue.optional().describe("Conversion factor for sourceType=1/processMethod=2; slope coefficient for sourceType=2/processMethod=4; average flue-gas flow for sourceType=3."),
|
|
662
666
|
oxRate: nonNegativeNumericValue.optional().describe("Oxidation rate for sourceType=1/processMethod=1; C2F6 fraction for sourceType=2/processMethod=4/5."),
|
|
663
|
-
carbon: nonNegativeNumericValue.optional().describe("Carbon content for sourceType=1/processMethod=3; PFC collection efficiency for sourceType=2. It is required and must be greater than zero for sourceType=2/processMethod=5. The backend defaults it only where the
|
|
667
|
+
carbon: nonNegativeNumericValue.optional().describe("Carbon content for sourceType=1/processMethod=3; PFC collection efficiency for sourceType=2. It is required and must be greater than zero for sourceType=2/processMethod=5. The backend defaults it only where the CBAM formula allows."),
|
|
664
668
|
carbonUnit: z.string().max(100).optional(),
|
|
665
669
|
conversionRateUnit: z.string().max(100).optional(),
|
|
666
670
|
biomassContent: nonNegativeNumericValue.optional().describe("Biomass content for sourceType=1; anode-effect overvoltage AEO for sourceType=2/processMethod=5; biomass share for sourceType=3."),
|
|
@@ -668,7 +672,7 @@ const cbam2SourceFlow = z.object({
|
|
|
668
672
|
carbonFossil: nonNegativeNumericValue.optional().describe("Non-zero anode-effect CE denominator, required only for sourceType=2/processMethod=5."),
|
|
669
673
|
carbonBiological: nonNegativeNumericValue.optional().describe("Overvoltage coefficient, required only for sourceType=2/processMethod=5."),
|
|
670
674
|
}).describe("Editable source-flow inputs. Valid combinations are sourceType=1 with processMethod=1/2/3, sourceType=2 with processMethod=4/5, or sourceType=3 with processMethod=6/7. energyFossil and attachments are backend-owned and are never accepted.");
|
|
671
|
-
const
|
|
675
|
+
const cbamHeatPowerData = z.object({
|
|
672
676
|
fuelIn: positiveNumericValue.describe("Fuel input; must be greater than zero."),
|
|
673
677
|
hotPer: positiveNumericValue.describe("Heat allocation parameter; must be greater than zero."),
|
|
674
678
|
elePer: positiveNumericValue.describe("Electricity allocation parameter; must be greater than zero."),
|
|
@@ -678,54 +682,54 @@ const cbam2HeatPowerData = z.object({
|
|
|
678
682
|
smokeOut: nonNegativeNumericValue,
|
|
679
683
|
inputFactor: nonNegativeNumericValue.optional(),
|
|
680
684
|
});
|
|
681
|
-
const
|
|
685
|
+
const cbamActivityRow = z.object({
|
|
682
686
|
relationId: longId.describe("Default-process id or related process id selected from the current item route."),
|
|
683
|
-
isDefault:
|
|
687
|
+
isDefault: cbamZeroOne.describe("0=default-process route row; 1=related in-report process row."),
|
|
684
688
|
emission: nonNegativeNumericValue.describe("Activity amount for this route row."),
|
|
685
689
|
});
|
|
686
|
-
const
|
|
687
|
-
id: longId.optional().describe("Existing attribution id returned by
|
|
688
|
-
emissionElement:
|
|
689
|
-
isExists:
|
|
690
|
+
const cbamProductAttribution = z.object({
|
|
691
|
+
id: longId.optional().describe("Existing attribution id returned by cbam_report_read. Omit for a new row."),
|
|
692
|
+
emissionElement: cbamCode.describe("Emission-element code returned by CBAM_ENUM reference data."),
|
|
693
|
+
isExists: cbamCode.describe("Whether this emission element is included; use the exact CBAM_ENUM code."),
|
|
690
694
|
inputPower: nonNegativeNumericValue.optional(),
|
|
691
695
|
inputFactor: nonNegativeNumericValue.optional(),
|
|
692
696
|
outPower: nonNegativeNumericValue.optional(),
|
|
693
697
|
outFactor: nonNegativeNumericValue.optional(),
|
|
694
|
-
emissionSource:
|
|
698
|
+
emissionSource: cbamCode.optional(),
|
|
695
699
|
eleSource: z.string().max(100).optional(),
|
|
696
|
-
eleChoose:
|
|
700
|
+
eleChoose: cbamCode.optional(),
|
|
697
701
|
defaultCnId: longId.optional(),
|
|
698
702
|
cnCode: z.string().max(100).optional(),
|
|
699
703
|
});
|
|
700
|
-
const
|
|
704
|
+
const cbamElectricityCalculator = z.object({
|
|
701
705
|
id: longId.optional(),
|
|
702
706
|
eleValue: nonNegativeNumericValue,
|
|
703
707
|
coefficient: nonNegativeNumericValue,
|
|
704
708
|
});
|
|
705
|
-
const
|
|
709
|
+
const cbamProcessProductData = z.object({
|
|
706
710
|
id: longId.describe("Existing process id from the same report."),
|
|
707
711
|
totalVolume: nonNegativeNumericValue.describe("Total output. Must satisfy totalVolume - salesVolume - nonProduct - sum(processList emission where isDefault=1) = 0 at six-decimal precision."),
|
|
708
712
|
salesVolume: nonNegativeNumericValue.describe("Sold output used in the process balance equation."),
|
|
709
713
|
nonProduct: nonNegativeNumericValue.optional().describe("Non-product output used in the process balance equation; omit to treat it as zero."),
|
|
710
|
-
processList: z.array(
|
|
711
|
-
productAttributionList: z.array(
|
|
712
|
-
eleCalculatorList: z.array(
|
|
714
|
+
processList: z.array(cbamActivityRow).max(100).optional().describe("Activity route rows. Rows with isDefault=1 are subtracted in the process balance equation."),
|
|
715
|
+
productAttributionList: z.array(cbamProductAttribution).max(100).optional(),
|
|
716
|
+
eleCalculatorList: z.array(cbamElectricityCalculator).max(100).optional(),
|
|
713
717
|
}).describe("Complete product activity/emission data for one existing process. The backend rejects an unbalanced item.");
|
|
714
|
-
const
|
|
718
|
+
const cbamPrecursorProductData = z.object({
|
|
715
719
|
id: longId.describe("Existing precursor id from the same report."),
|
|
716
720
|
purchaseVolume: nonNegativeNumericValue.optional(),
|
|
717
721
|
nonProduct: nonNegativeNumericValue.optional().describe("Non-product amount subtracted in the precursor balance equation."),
|
|
718
|
-
defaultReason:
|
|
719
|
-
isDefault:
|
|
720
|
-
processList: z.array(
|
|
721
|
-
productAttributionList: z.array(
|
|
722
|
+
defaultReason: cbamCode.optional(),
|
|
723
|
+
isDefault: cbamZeroOne.optional(),
|
|
724
|
+
processList: z.array(cbamActivityRow).max(100).optional().describe("Must satisfy sum(emission where isDefault=0) - sum(emission where isDefault=1) - nonProduct = 0 at six-decimal precision."),
|
|
725
|
+
productAttributionList: z.array(cbamProductAttribution).max(100).optional(),
|
|
722
726
|
}).describe("Complete activity/emission data for one existing precursor. The backend rejects an unbalanced item.");
|
|
723
|
-
const
|
|
727
|
+
const cbamSaleProduct = z.object({
|
|
724
728
|
id: longId.optional().describe("Existing sale-product id for update. Omit to create."),
|
|
725
729
|
cnCode: z.string().trim().min(1).max(100).describe("CN code valid for the selected process product category."),
|
|
726
730
|
processId: longId.describe("Owning process id from the same report."),
|
|
727
731
|
productName: z.string().trim().min(1).max(200),
|
|
728
|
-
reducing:
|
|
732
|
+
reducing: cbamCode.optional(),
|
|
729
733
|
steelCode: z.string().max(100).optional(),
|
|
730
734
|
mnPer: nonNegativeNumericValue.optional(),
|
|
731
735
|
crPer: nonNegativeNumericValue.optional(),
|
|
@@ -737,9 +741,9 @@ const cbam2SaleProduct = z.object({
|
|
|
737
741
|
wasteMaterial: nonNegativeNumericValue.optional(),
|
|
738
742
|
alUse: nonNegativeNumericValue.optional(),
|
|
739
743
|
nonAl: nonNegativeNumericValue.optional(),
|
|
740
|
-
clinker: nonNegativeNumericValue.describe("Cement clinker value required by the migrated
|
|
741
|
-
calcine:
|
|
742
|
-
solution: nonNegativeNumericValue.describe("Aqueous-solution concentration required by the migrated
|
|
744
|
+
clinker: nonNegativeNumericValue.describe("Cement clinker value required by the migrated CBAM form contract."),
|
|
745
|
+
calcine: cbamCode.describe("Calcination flag code required by the migrated CBAM form contract."),
|
|
746
|
+
solution: nonNegativeNumericValue.describe("Aqueous-solution concentration required by the migrated CBAM form contract."),
|
|
743
747
|
nitric: nonNegativeNumericValue.optional(),
|
|
744
748
|
urea: nonNegativeNumericValue.optional(),
|
|
745
749
|
nitrogen: nonNegativeNumericValue.optional(),
|
|
@@ -748,31 +752,31 @@ const cbam2SaleProduct = z.object({
|
|
|
748
752
|
urPer: nonNegativeNumericValue.optional(),
|
|
749
753
|
organic: nonNegativeNumericValue.optional(),
|
|
750
754
|
});
|
|
751
|
-
const
|
|
755
|
+
const cbamCarbonTax = z.object({
|
|
752
756
|
id: longId.optional().describe("Existing carbon-tax row id for update. Omit to create."),
|
|
753
757
|
saleProductId: longId.describe("Sale-product id from the same report."),
|
|
754
|
-
reportSelected:
|
|
755
|
-
emissionValueType:
|
|
756
|
-
emissionSourceType:
|
|
758
|
+
reportSelected: cbamZeroOne.optional(),
|
|
759
|
+
emissionValueType: cbamCode.optional(),
|
|
760
|
+
emissionSourceType: cbamCode.optional(),
|
|
757
761
|
emissionSourceSaleProductId: longId.optional(),
|
|
758
762
|
emissionSourceDefaultCnId: longId.optional(),
|
|
759
763
|
emissionSourceYear: z.number().int().min(1900).max(9999).optional(),
|
|
760
764
|
productBenchmarkId: longId.optional(),
|
|
761
|
-
productBenchmarkType:
|
|
765
|
+
productBenchmarkType: cbamCode.optional(),
|
|
762
766
|
cbamAdjustmentFactor: nonNegativeNumericValue.optional(),
|
|
763
767
|
paidCarbonPrice: nonNegativeNumericValue.optional(),
|
|
764
|
-
taxType:
|
|
768
|
+
taxType: cbamCode.optional(),
|
|
765
769
|
emissionPer: nonNegativeNumericValue.optional(),
|
|
766
|
-
currencyType: z.string().trim().min(1).max(100).describe("Currency dictionary value returned by
|
|
770
|
+
currencyType: z.string().trim().min(1).max(100).describe("Currency dictionary value returned by cbam_reference_search."),
|
|
767
771
|
taxValue: nonNegativeNumericValue.optional(),
|
|
768
|
-
offsetMethod:
|
|
772
|
+
offsetMethod: cbamCode.optional(),
|
|
769
773
|
offsetPer: nonNegativeNumericValue.optional(),
|
|
770
774
|
offsetPrice: nonNegativeNumericValue.optional(),
|
|
771
775
|
});
|
|
772
|
-
const
|
|
773
|
-
generalInformation:
|
|
774
|
-
defaultReason:
|
|
775
|
-
qualityAssurance:
|
|
776
|
+
const cbamDataQuality = z.object({
|
|
777
|
+
generalInformation: cbamCode.optional(),
|
|
778
|
+
defaultReason: cbamCode.optional(),
|
|
779
|
+
qualityAssurance: cbamCode.optional(),
|
|
776
780
|
carbonPrice: z.string().max(5000).optional(),
|
|
777
781
|
supplement: z.string().max(5000).optional(),
|
|
778
782
|
});
|
|
@@ -780,13 +784,13 @@ export const schemas = {
|
|
|
780
784
|
session_carbon_objects: z.object({
|
|
781
785
|
sessionId,
|
|
782
786
|
module: z
|
|
783
|
-
.enum(["all", "footprint3", "enterprise", "
|
|
787
|
+
.enum(["all", "footprint3", "enterprise", "cbam"])
|
|
784
788
|
.optional()
|
|
785
|
-
.describe("Optional module filter. Omit it or use all to return product-carbon, enterprise-carbon, and
|
|
789
|
+
.describe("Optional module filter. Omit it or use all to return product-carbon, enterprise-carbon, and CBAM objects."),
|
|
786
790
|
}),
|
|
787
|
-
|
|
788
|
-
...
|
|
789
|
-
types: z.array(
|
|
791
|
+
cbam_reference_search: z.object({
|
|
792
|
+
...cbamReadFields,
|
|
793
|
+
types: z.array(cbamReferenceType).min(1).max(12)
|
|
790
794
|
.describe("Only the reference-data families needed for the current step. CARBON_TAX_CANDIDATE additionally requires reportId."),
|
|
791
795
|
keyword: z.string().trim().max(200).optional(),
|
|
792
796
|
orgId: longId.optional(),
|
|
@@ -795,8 +799,8 @@ export const schemas = {
|
|
|
795
799
|
pageNum: z.number().int().min(1).optional(),
|
|
796
800
|
pageSize: z.number().int().min(1).max(200).optional(),
|
|
797
801
|
}),
|
|
798
|
-
|
|
799
|
-
...
|
|
802
|
+
cbam_report_search: z.object({
|
|
803
|
+
...cbamReadFields,
|
|
800
804
|
reportName: z.string().trim().max(200).optional(),
|
|
801
805
|
orgId: longId.optional(),
|
|
802
806
|
factoryId: longId.optional(),
|
|
@@ -804,94 +808,94 @@ export const schemas = {
|
|
|
804
808
|
pageNum: z.number().int().min(1).optional(),
|
|
805
809
|
pageSize: z.number().int().min(1).max(100).optional(),
|
|
806
810
|
}),
|
|
807
|
-
|
|
808
|
-
...
|
|
809
|
-
reportId: longId.describe("Exact
|
|
811
|
+
cbam_report_read: z.object({
|
|
812
|
+
...cbamReadFields,
|
|
813
|
+
reportId: longId.describe("Exact CBAM report id returned by cbam_report_search, cbam_report_save, or session_carbon_objects."),
|
|
810
814
|
view: z.enum(["snapshot", "section", "item", "result", "readiness", "carbon_tax_status"])
|
|
811
815
|
.describe("Read mode. snapshot=whole workflow overview; section=one form section; item=one child record; result=result summary; readiness=generation blockers; carbon_tax_status=asynchronous tax calculation status."),
|
|
812
|
-
section:
|
|
813
|
-
itemType:
|
|
816
|
+
section: cbamSection.optional().describe("Required only when view=section."),
|
|
817
|
+
itemType: cbamItemType.optional().describe("Required only when view=item."),
|
|
814
818
|
itemId: longId.optional().describe("Required only when view=item; must belong to reportId."),
|
|
815
819
|
}),
|
|
816
|
-
|
|
817
|
-
...
|
|
818
|
-
factoryId: longId.describe("Exact factory id returned by
|
|
820
|
+
cbam_factory_read: z.object({
|
|
821
|
+
...cbamReadFields,
|
|
822
|
+
factoryId: longId.describe("Exact factory id returned by cbam_reference_search or cbam_factory_save."),
|
|
819
823
|
}),
|
|
820
|
-
|
|
821
|
-
...
|
|
824
|
+
cbam_factory_save: z.object({
|
|
825
|
+
...cbamConfirmedWriteFields,
|
|
822
826
|
action: z.enum(["create", "update"]),
|
|
823
827
|
factoryId: longId.optional().describe("Required for action=update and omitted for action=create."),
|
|
824
|
-
factory:
|
|
828
|
+
factory: cbamFactoryForm.describe("Complete factory form. For update, first call cbam_factory_read and preserve unchanged fields and orgId."),
|
|
825
829
|
}),
|
|
826
|
-
|
|
827
|
-
...
|
|
830
|
+
cbam_report_save: z.object({
|
|
831
|
+
...cbamWriteFields,
|
|
828
832
|
action: z.enum(["create", "update"]),
|
|
829
833
|
reportId: longId.optional().describe("Required for action=update and omitted for action=create."),
|
|
830
|
-
report:
|
|
834
|
+
report: cbamReportForm.describe("Complete CBAM general-information form."),
|
|
831
835
|
}),
|
|
832
|
-
|
|
833
|
-
...
|
|
836
|
+
cbam_process_manage: z.object({
|
|
837
|
+
...cbamConfirmedWriteFields,
|
|
834
838
|
reportId: longId,
|
|
835
|
-
action: z.enum(["save", "delete", "reorder"]).describe("save requires items and forbids ids; delete requires
|
|
836
|
-
items: z.array(
|
|
839
|
+
action: z.enum(["save", "delete", "reorder"]).describe("save requires items and forbids ids; delete requires prior Agent approval and confirmed=true; reorder requires the complete ordered ids list and forbids items."),
|
|
840
|
+
items: z.array(cbamProcessDefinition).min(1).max(10).optional()
|
|
837
841
|
.describe("Required only for action=save. The report can contain at most 10 processes."),
|
|
838
842
|
ids: z.array(longId).min(1).max(10).optional()
|
|
839
843
|
.describe("Required for delete/reorder. Reorder must contain every report process exactly once in target order."),
|
|
840
844
|
}),
|
|
841
|
-
|
|
842
|
-
...
|
|
845
|
+
cbam_precursor_manage: z.object({
|
|
846
|
+
...cbamConfirmedWriteFields,
|
|
843
847
|
reportId: longId,
|
|
844
|
-
action: z.enum(["save", "delete"]).describe("save requires items and forbids ids; delete requires ids and
|
|
845
|
-
items: z.array(
|
|
848
|
+
action: z.enum(["save", "delete"]).describe("save requires items and forbids ids; delete requires ids plus prior Agent approval and confirmed=true."),
|
|
849
|
+
items: z.array(cbamPrecursorDefinition).min(1).max(20).optional()
|
|
846
850
|
.describe("Required only for action=save. The report can contain at most 20 manually entered precursors."),
|
|
847
851
|
ids: z.array(longId).min(1).max(20).optional().describe("Required only for action=delete."),
|
|
848
852
|
}),
|
|
849
|
-
|
|
850
|
-
...
|
|
853
|
+
cbam_source_flow_manage: z.object({
|
|
854
|
+
...cbamConfirmedWriteFields,
|
|
851
855
|
reportId: longId,
|
|
852
|
-
action: z.enum(["save", "delete"]).describe("save requires items and forbids ids; delete requires ids and
|
|
853
|
-
items: z.array(
|
|
856
|
+
action: z.enum(["save", "delete"]).describe("save requires items and forbids ids; delete requires ids plus prior Agent approval and confirmed=true."),
|
|
857
|
+
items: z.array(cbamSourceFlow).min(1).max(200).optional().describe("Required only for action=save."),
|
|
854
858
|
ids: z.array(longId).min(1).max(100).optional().describe("Required only for action=delete."),
|
|
855
859
|
}),
|
|
856
|
-
|
|
857
|
-
...
|
|
860
|
+
cbam_heat_power_update: z.object({
|
|
861
|
+
...cbamWriteFields,
|
|
858
862
|
reportId: longId,
|
|
859
|
-
data:
|
|
863
|
+
data: cbamHeatPowerData.describe("Complete heat-power input form. The backend calculates outPower and outFactor; never submit calculated outputs."),
|
|
860
864
|
}),
|
|
861
|
-
|
|
862
|
-
...
|
|
865
|
+
cbam_product_data_update: z.object({
|
|
866
|
+
...cbamWriteFields,
|
|
863
867
|
reportId: longId,
|
|
864
868
|
dataType: z.enum(["process", "precursor"])
|
|
865
869
|
.describe("Select process for self-produced process activity data or precursor for purchased-precursor activity/emission data."),
|
|
866
|
-
items: z.array(z.union([
|
|
870
|
+
items: z.array(z.union([cbamProcessProductData, cbamPrecursorProductData])).min(1).max(100),
|
|
867
871
|
}),
|
|
868
|
-
|
|
869
|
-
...
|
|
872
|
+
cbam_sale_product_manage: z.object({
|
|
873
|
+
...cbamConfirmedWriteFields,
|
|
870
874
|
reportId: longId,
|
|
871
|
-
action: z.enum(["save", "delete"]).describe("save requires items and forbids ids; delete requires ids and
|
|
872
|
-
items: z.array(
|
|
875
|
+
action: z.enum(["save", "delete"]).describe("save requires items and forbids ids; delete requires ids plus prior Agent approval and confirmed=true."),
|
|
876
|
+
items: z.array(cbamSaleProduct).min(1).max(100).optional().describe("Required only for action=save."),
|
|
873
877
|
ids: z.array(longId).min(1).max(100).optional().describe("Required only for action=delete."),
|
|
874
878
|
}),
|
|
875
|
-
|
|
876
|
-
...
|
|
879
|
+
cbam_carbon_tax_manage: z.object({
|
|
880
|
+
...cbamConfirmedWriteFields,
|
|
877
881
|
reportId: longId,
|
|
878
|
-
action: z.enum(["save", "delete", "calculate"]).describe("save requires items; delete requires ids
|
|
879
|
-
items: z.array(
|
|
882
|
+
action: z.enum(["save", "delete", "calculate"]).describe("save requires items; delete requires ids; calculate forbids items/ids. delete/calculate require prior Agent approval and confirmed=true."),
|
|
883
|
+
items: z.array(cbamCarbonTax).min(1).max(100).optional().describe("Required only for action=save."),
|
|
880
884
|
ids: z.array(longId).min(1).max(100).optional().describe("Required only for action=delete."),
|
|
881
885
|
}),
|
|
882
|
-
|
|
883
|
-
...
|
|
886
|
+
cbam_data_quality_update: z.object({
|
|
887
|
+
...cbamWriteFields,
|
|
884
888
|
reportId: longId,
|
|
885
|
-
data:
|
|
889
|
+
data: cbamDataQuality.describe("Complete data-quality form. Read DATA_QUALITY first and preserve fields the user did not change."),
|
|
886
890
|
}),
|
|
887
|
-
|
|
888
|
-
...
|
|
889
|
-
reportId: longId.describe("
|
|
891
|
+
cbam_report_generate: z.object({
|
|
892
|
+
...cbamConfirmedWriteFields,
|
|
893
|
+
reportId: longId.describe("CBAM report id to generate. Basic general information is sufficient to start; readiness reports optional missing sections separately."),
|
|
890
894
|
}),
|
|
891
|
-
|
|
892
|
-
...
|
|
895
|
+
cbam_report_generation_status: z.object({
|
|
896
|
+
...cbamReadFields,
|
|
893
897
|
reportId: longId,
|
|
894
|
-
generationId: longId.describe("Generation task id returned by
|
|
898
|
+
generationId: longId.describe("Generation task id returned by cbam_report_generate."),
|
|
895
899
|
}),
|
|
896
900
|
user_memory_recall: z.object({
|
|
897
901
|
sessionId,
|
|
@@ -1344,22 +1348,21 @@ export const schemas = {
|
|
|
1344
1348
|
schemas.enterprise_report_regenerate = schemas.enterprise_report_generate;
|
|
1345
1349
|
export const exposedToolNames = [
|
|
1346
1350
|
"session_carbon_objects",
|
|
1347
|
-
"
|
|
1348
|
-
"
|
|
1349
|
-
"
|
|
1350
|
-
"
|
|
1351
|
-
"
|
|
1352
|
-
"
|
|
1353
|
-
"
|
|
1354
|
-
"
|
|
1355
|
-
"
|
|
1356
|
-
"
|
|
1357
|
-
"
|
|
1358
|
-
"
|
|
1359
|
-
"
|
|
1360
|
-
"
|
|
1361
|
-
"
|
|
1362
|
-
"cbam2_report_generation_status",
|
|
1351
|
+
"cbam_reference_search",
|
|
1352
|
+
"cbam_report_search",
|
|
1353
|
+
"cbam_report_read",
|
|
1354
|
+
"cbam_factory_read",
|
|
1355
|
+
"cbam_factory_save",
|
|
1356
|
+
"cbam_report_save",
|
|
1357
|
+
"cbam_process_manage",
|
|
1358
|
+
"cbam_precursor_manage",
|
|
1359
|
+
"cbam_source_flow_manage",
|
|
1360
|
+
"cbam_heat_power_update",
|
|
1361
|
+
"cbam_product_data_update",
|
|
1362
|
+
"cbam_sale_product_manage",
|
|
1363
|
+
"cbam_carbon_tax_manage",
|
|
1364
|
+
"cbam_data_quality_update",
|
|
1365
|
+
"cbam_report_generate",
|
|
1363
1366
|
"user_memory_recall",
|
|
1364
1367
|
"user_memory_get",
|
|
1365
1368
|
"user_memory_upsert",
|
|
@@ -1416,23 +1419,23 @@ export const exposedToolNames = [
|
|
|
1416
1419
|
"enterprise_emission_batch_delete",
|
|
1417
1420
|
];
|
|
1418
1421
|
export const descriptions = {
|
|
1419
|
-
session_carbon_objects: "Recover product-carbon accounts, enterprise-carbon computations, and
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1422
|
+
session_carbon_objects: "Recover product-carbon accounts, enterprise-carbon computations, and CBAM reports bound to the current Agent session. Call this before guessing a lost business id. Omit module or use all for every family; module=footprint3 returns productCarbonAccounts, module=enterprise returns enterpriseCarbonComputations, and module=cbam returns cbamReports. One session may contain multiple CBAM reports, so match by reportName/org/factory and then pass the exact cbamReports[].reportId to every report-specific tool. Never substitute an enterprise year, product accountId, or another report id. This tool is read-only and requires sessionId.",
|
|
1423
|
+
cbam_reference_search: "Read CBAM reference data needed for the current step: accessible organizations and factories, countries, currencies, enum codes, product categories, default processes/precursors/products/CN/sale data, or report-scoped carbon-tax candidates. Request only needed types. Use returned ids/codes exactly and never invent dictionary or organization values. CARBON_TAX_CANDIDATE requires reportId. Large reference tables are paginated with pageNum/pageSize. Read-only.",
|
|
1424
|
+
cbam_report_search: "Search CBAM reports accessible to the current user by optional name, organization, factory, year, and pagination. Use this or session_carbon_objects to resolve an exact reportId. A single Agent session can create and work with multiple CBAM reports; never silently select the first result when several reports match. Read-only.",
|
|
1425
|
+
cbam_report_read: "Unified read-only CBAM report inspection. view=snapshot returns workflow overview/counts/readiness; section returns one complete editable section and requires section; item reads one child record and requires itemType+itemId; result returns result analysis; readiness returns generation blockers/warnings; carbon_tax_status returns asynchronous carbon-tax calculation state. itemId must belong to reportId. Call the corresponding read view before a full-form update so unchanged fields are preserved.",
|
|
1426
|
+
cbam_factory_read: "Read the complete accessible CBAM factory form by exact factoryId. Call before updating a shared factory because factory updates are full-form writes and orgId is immutable. Read-only.",
|
|
1427
|
+
cbam_factory_save: "Create or fully update a shared CBAM factory. action=create omits factoryId; action=update requires factoryId and must follow cbam_factory_read, preserving unchanged fields and orgId. Country and orgId must come from cbam_reference_search. Both actions are shared-data mutations: reuse the existing Agent approval interrupt, then have the trusted wrapper inject confirmed=true and idempotencyKey before this single MCP call. MCP never automatically retries this write.",
|
|
1428
|
+
cbam_report_save: "Create or fully update CBAM report general information. action=create omits reportId; every create call creates a NEW report and binds it to the same Agent session without replacing earlier CBAM reports. One session may therefore contain multiple reports. action=update requires an explicit reportId and should follow cbam_report_read view=section section=GENERAL_INFO. After more than one report exists, always pass the intended reportId to subsequent tools and ask the user when context is ambiguous. Basic general information is enough to create a report and later generate it; other sections are progressive supplements. Requires idempotencyKey.",
|
|
1429
|
+
cbam_process_manage: "Manage self-produced CBAM process definitions for one report. action=save batch-creates/updates complete definition rows; action=delete removes exact ids; action=reorder requires every current process id exactly once in target order. Read PROCESS before updates/deletes/reorder. A report supports at most 10 processes. Delete requires the existing Agent approval interrupt and wrapper-injected confirmed=true; save/reorder do not. Requires idempotencyKey; MCP never automatically retries.",
|
|
1430
|
+
cbam_precursor_manage: "Manage manually entered purchased-precursor definitions. action=save batch-creates/updates complete rows; action=delete removes exact precursor ids. Read PRECURSOR first, and resolve category/country/route values through cbam_reference_search. A report supports at most 20 precursors. Delete requires prior Agent approval and wrapper-injected confirmed=true. Requires idempotencyKey; MCP never automatically retries.",
|
|
1431
|
+
cbam_source_flow_manage: "Manage direct-emission source-flow rows under report processes. action=save creates/updates rows and the backend recalculates direct emissions; action=delete removes exact ids. Read SOURCE_FLOW first, use process ids from the same report, and use CBAM_ENUM codes for processMethod/sourceType. Calculated results and support files are backend-owned and are not accepted by this tool. Delete requires prior Agent approval and wrapper-injected confirmed=true. Requires idempotencyKey.",
|
|
1432
|
+
cbam_heat_power_update: "Update complete heat-power cogeneration inputs for a report whose include flag enables this section. Read HEAT_POWER first. Submit only input fields; the backend calculates outPower/outFactor and invalidates dependent sale calculations. Requires idempotencyKey.",
|
|
1433
|
+
cbam_product_data_update: "Update product activity/emission data for existing process or precursor rows. dataType=process requires process items with totalVolume and salesVolume; dataType=precursor requires precursor items. Read PROCESS_PRODUCT_DATA or PRECURSOR_PRODUCT_DATA first. The backend preserves definitions, validates report ownership and activity balances, replaces route rows transactionally, calculates dependent fields, and rejects server-owned result fields. Requires idempotencyKey.",
|
|
1434
|
+
cbam_sale_product_manage: "Manage sale products for one CBAM report. action=save batch-creates/updates complete form rows tied to exact report process ids; action=delete removes exact ids and dependent tax rows. Read SALE_PRODUCT first and use CN/category data from cbam_reference_search. Calculated emissions, versions, fill status, and payTax are backend-owned. Delete requires prior Agent approval and wrapper-injected confirmed=true. Requires idempotencyKey.",
|
|
1435
|
+
cbam_carbon_tax_manage: "Manage or calculate report carbon tax. action=save batch-creates/updates rows using exact saleProductId, currency, benchmark, and source candidates returned by CBAM reads/reference search; action=delete removes exact ids; action=calculate starts asynchronous calculation. Read CARBON_TAX and carbon-tax candidates first. delete and calculate require the existing Agent approval interrupt and wrapper-injected confirmed=true; after calculate succeeds, poll cbam_report_read with view=carbon_tax_status. Requires idempotencyKey and is never automatically retried.",
|
|
1436
|
+
cbam_data_quality_update: "Update the complete CBAM data-quality form. First call cbam_report_read view=section section=DATA_QUALITY and preserve fields the user did not change. Use CBAM_ENUM codes for enum fields. Requires idempotencyKey.",
|
|
1437
|
+
cbam_report_generate: "Generate the selected CBAM report and wait for the backend file result. General information alone is sufficient to request generation; optional missing sections remain visible through cbam_report_read view=readiness and may produce warnings or incomplete content according to backend rules. The backend creates the file, uploads it, and records it in Carbon Cloud download management; the Agent must not create a parallel spreadsheet. Reuse the existing Agent approval interrupt, then have the trusted wrapper inject confirmed=true and idempotencyKey before this single MCP call. The MCP server polls the internal generation status itself and normally returns COMPLETED with the download file. If it returns RUNNING with timedOut=true, call this same tool again with the same idempotencyKey to continue waiting without creating a duplicate task. The generation write is never automatically retried after timeout/network/5xx failures.",
|
|
1438
|
+
cbam_report_generation_status: "Internal-only CBAM report-generation status route used by cbam_report_generate. It is intentionally not exposed to the Agent.",
|
|
1436
1439
|
user_memory_recall: "Recall the current user's stored cross-session preferences, long-term constraints, carbon-domain habits, and response-style preferences. Call this when stable prior preferences can materially improve the current task, when the user asks what was remembered, and before user_memory_upsert or user_memory_forget if this turn has not already recalled the same target topic. A direct write or forget needs this lookup even when the current request supplies the new value, so the Agent can reuse an existing memoryKey and memoryId instead of creating a semantic duplicate. Do not repeatedly recall the same topic in one turn. Write query as a concise question about the preference or constraint needed now; never copy the full user message or include unrelated sensitive business data. Optional memoryTypes: preference=general preference, constraint=persistent rule or boundary, domain_habit=carbon-accounting/modeling/reporting workflow habit, format_habit=response language/structure/length/file-format habit. The response contains rules and items with memoryId, scope, type, memoryKey, normalized content, recallMode, version, and relevance metadata. count=0 is a successful empty recall; continue the task using current context. The current user request always overrides recalled memory, and current business data is authoritative. Treat recalled items as guidance, not authoritative business facts. Never reveal memory ids, versions, scores, source metadata, or internal implementation details to the user. Requires sessionId, a messageId belonging to that session, and query.",
|
|
1437
1440
|
user_memory_get: "Read exactly one current-user memory by the stable memoryId returned by user_memory_recall or a previous write. Use this immediately before updating or forgetting a memory to obtain its latest version and avoid stale writes. Do not enumerate, guess, or probe memory ids, and do not use this tool to access another user or project: authorization is derived from sessionId and messageId. The response is reduced to Agent-safe fields and must not be displayed as internal metadata to the user. Requires sessionId, a messageId belonging to that session, and memoryId.",
|
|
1438
1441
|
user_memory_upsert: "Create or update one stable long-term user memory. Call only when the user explicitly asks the Agent to remember a lasting preference/constraint, or after the user clearly confirms it; ordinary observations, one-off task details, sensitive data, changing business facts, account ids, emission values, and unconfirmed model inferences must not be stored. Before writing, call user_memory_recall once for the target topic unless the same topic was already recalled in this turn. If recall finds the same independently updatable slot, reuse its exact memoryKey; for an exact update, also reuse its memoryId, call user_memory_get, and preferably pass the latest positive version as expectedVersion. If recall finds no matching slot, omit memoryId and create by a new stable memoryKey. memoryId determines the operation: omit it or pass a blank value to create/upsert by memoryKey; pass a valid memoryId to update that exact item. For compatibility, expectedVersion may be omitted or 0 and the backend will use the latest version read at update time; never blindly retry a version conflict. expectedVersion is ignored when memoryId is absent. memoryKey represents one independently updatable slot: never include mutable attitude/state such as like/dislike or enabled/disabled. A single-valued attribute uses one fixed key without the changing value, such as preference.favorite_color or format.response.language. A multi-valued collection includes a canonical lowercase English object so values can coexist, such as preference.color.white and preference.color.red; liking and disliking white both reuse preference.color.white. Different wording or languages for the same slot or object must reuse the recalled key. USER applies across sessions; USER_PROJECT applies only to the current session project, which the backend derives automatically. Prefer source=EXPLICIT_USER for a direct request or CONFIRMED_CONVERSATION after confirmation. Use ALWAYS for persistent constraints/response-style rules and SEMANTIC for context-dependent preferences, or omit recallMode for the backend default. Requires sessionId, messageId, scope, type, memoryKey, and normalized content no longer than 120 characters. MCP never automatically retries this write.",
|
|
@@ -1501,134 +1504,139 @@ export const toolRoutes = {
|
|
|
1501
1504
|
method: "POST",
|
|
1502
1505
|
path: apipath.SessionBusinessRefs(),
|
|
1503
1506
|
bodyKind: "sessionContext",
|
|
1507
|
+
responseKind: "sessionCarbonObjects",
|
|
1504
1508
|
},
|
|
1505
|
-
|
|
1509
|
+
cbam_reference_search: {
|
|
1506
1510
|
method: "POST",
|
|
1507
|
-
path: apipath.
|
|
1508
|
-
bodyKind: "
|
|
1511
|
+
path: apipath.CbamReferenceSearch(),
|
|
1512
|
+
bodyKind: "cbam",
|
|
1509
1513
|
},
|
|
1510
|
-
|
|
1514
|
+
cbam_report_search: {
|
|
1511
1515
|
method: "POST",
|
|
1512
|
-
path: apipath.
|
|
1513
|
-
bodyKind: "
|
|
1516
|
+
path: apipath.CbamReportSearch(),
|
|
1517
|
+
bodyKind: "cbam",
|
|
1514
1518
|
},
|
|
1515
|
-
|
|
1519
|
+
cbam_report_read: {
|
|
1516
1520
|
method: "POST",
|
|
1517
1521
|
path: (args) => {
|
|
1518
1522
|
if (args.view === "section")
|
|
1519
|
-
return apipath.
|
|
1523
|
+
return apipath.CbamSectionSnapshot();
|
|
1520
1524
|
if (args.view === "item")
|
|
1521
|
-
return apipath.
|
|
1525
|
+
return apipath.CbamItemDetail();
|
|
1522
1526
|
if (args.view === "result")
|
|
1523
|
-
return apipath.
|
|
1527
|
+
return apipath.CbamResultSummary();
|
|
1524
1528
|
if (args.view === "readiness")
|
|
1525
|
-
return apipath.
|
|
1529
|
+
return apipath.CbamReportReadiness();
|
|
1526
1530
|
if (args.view === "carbon_tax_status")
|
|
1527
|
-
return apipath.
|
|
1528
|
-
return apipath.
|
|
1531
|
+
return apipath.CbamCarbonTaxStatus();
|
|
1532
|
+
return apipath.CbamReportSnapshot();
|
|
1529
1533
|
},
|
|
1530
|
-
bodyKind: "
|
|
1534
|
+
bodyKind: "cbam",
|
|
1531
1535
|
},
|
|
1532
|
-
|
|
1536
|
+
cbam_factory_read: {
|
|
1533
1537
|
method: "POST",
|
|
1534
|
-
path: apipath.
|
|
1535
|
-
bodyKind: "
|
|
1538
|
+
path: apipath.CbamFactoryDetail(),
|
|
1539
|
+
bodyKind: "cbam",
|
|
1536
1540
|
},
|
|
1537
|
-
|
|
1541
|
+
cbam_factory_save: {
|
|
1538
1542
|
method: "POST",
|
|
1539
1543
|
path: (args) => args.action === "update"
|
|
1540
|
-
? apipath.
|
|
1541
|
-
: apipath.
|
|
1542
|
-
bodyKind: "
|
|
1544
|
+
? apipath.CbamFactoryUpdate()
|
|
1545
|
+
: apipath.CbamFactoryCreate(),
|
|
1546
|
+
bodyKind: "cbam",
|
|
1543
1547
|
maxRetries: 0,
|
|
1544
1548
|
},
|
|
1545
|
-
|
|
1549
|
+
cbam_report_save: {
|
|
1546
1550
|
method: "POST",
|
|
1547
1551
|
path: (args) => args.action === "update"
|
|
1548
|
-
? apipath.
|
|
1549
|
-
: apipath.
|
|
1550
|
-
bodyKind: "
|
|
1552
|
+
? apipath.CbamReportUpdate()
|
|
1553
|
+
: apipath.CbamReportCreate(),
|
|
1554
|
+
bodyKind: "cbam",
|
|
1551
1555
|
maxRetries: 0,
|
|
1552
1556
|
},
|
|
1553
|
-
|
|
1557
|
+
cbam_process_manage: {
|
|
1554
1558
|
method: "POST",
|
|
1555
1559
|
path: (args) => {
|
|
1556
1560
|
if (args.action === "delete")
|
|
1557
|
-
return apipath.
|
|
1561
|
+
return apipath.CbamProcessBatchDelete();
|
|
1558
1562
|
if (args.action === "reorder")
|
|
1559
|
-
return apipath.
|
|
1560
|
-
return apipath.
|
|
1563
|
+
return apipath.CbamProcessReorder();
|
|
1564
|
+
return apipath.CbamProcessBatchSave();
|
|
1561
1565
|
},
|
|
1562
|
-
bodyKind: "
|
|
1566
|
+
bodyKind: "cbam",
|
|
1563
1567
|
maxRetries: 0,
|
|
1564
1568
|
},
|
|
1565
|
-
|
|
1569
|
+
cbam_precursor_manage: {
|
|
1566
1570
|
method: "POST",
|
|
1567
1571
|
path: (args) => args.action === "delete"
|
|
1568
|
-
? apipath.
|
|
1569
|
-
: apipath.
|
|
1570
|
-
bodyKind: "
|
|
1572
|
+
? apipath.CbamPrecursorBatchDelete()
|
|
1573
|
+
: apipath.CbamPrecursorBatchSave(),
|
|
1574
|
+
bodyKind: "cbam",
|
|
1571
1575
|
maxRetries: 0,
|
|
1572
1576
|
},
|
|
1573
|
-
|
|
1577
|
+
cbam_source_flow_manage: {
|
|
1574
1578
|
method: "POST",
|
|
1575
1579
|
path: (args) => args.action === "delete"
|
|
1576
|
-
? apipath.
|
|
1577
|
-
: apipath.
|
|
1578
|
-
bodyKind: "
|
|
1580
|
+
? apipath.CbamSourceFlowBatchDelete()
|
|
1581
|
+
: apipath.CbamSourceFlowBatchSave(),
|
|
1582
|
+
bodyKind: "cbam",
|
|
1579
1583
|
maxRetries: 0,
|
|
1580
1584
|
},
|
|
1581
|
-
|
|
1585
|
+
cbam_heat_power_update: {
|
|
1582
1586
|
method: "POST",
|
|
1583
|
-
path: apipath.
|
|
1584
|
-
bodyKind: "
|
|
1587
|
+
path: apipath.CbamHeatPowerUpdate(),
|
|
1588
|
+
bodyKind: "cbam",
|
|
1585
1589
|
maxRetries: 0,
|
|
1586
1590
|
},
|
|
1587
|
-
|
|
1591
|
+
cbam_product_data_update: {
|
|
1588
1592
|
method: "POST",
|
|
1589
1593
|
path: (args) => args.dataType === "precursor"
|
|
1590
|
-
? apipath.
|
|
1591
|
-
: apipath.
|
|
1592
|
-
bodyKind: "
|
|
1594
|
+
? apipath.CbamPrecursorProductBatchUpdate()
|
|
1595
|
+
: apipath.CbamProcessProductBatchUpdate(),
|
|
1596
|
+
bodyKind: "cbam",
|
|
1593
1597
|
maxRetries: 0,
|
|
1594
1598
|
},
|
|
1595
|
-
|
|
1599
|
+
cbam_sale_product_manage: {
|
|
1596
1600
|
method: "POST",
|
|
1597
1601
|
path: (args) => args.action === "delete"
|
|
1598
|
-
? apipath.
|
|
1599
|
-
: apipath.
|
|
1600
|
-
bodyKind: "
|
|
1602
|
+
? apipath.CbamSaleProductBatchDelete()
|
|
1603
|
+
: apipath.CbamSaleProductBatchSave(),
|
|
1604
|
+
bodyKind: "cbam",
|
|
1601
1605
|
maxRetries: 0,
|
|
1602
1606
|
},
|
|
1603
|
-
|
|
1607
|
+
cbam_carbon_tax_manage: {
|
|
1604
1608
|
method: "POST",
|
|
1605
1609
|
path: (args) => {
|
|
1606
1610
|
if (args.action === "delete")
|
|
1607
|
-
return apipath.
|
|
1611
|
+
return apipath.CbamCarbonTaxBatchDelete();
|
|
1608
1612
|
if (args.action === "calculate")
|
|
1609
|
-
return apipath.
|
|
1610
|
-
return apipath.
|
|
1613
|
+
return apipath.CbamCarbonTaxCalculate();
|
|
1614
|
+
return apipath.CbamCarbonTaxBatchSave();
|
|
1611
1615
|
},
|
|
1612
|
-
bodyKind: "
|
|
1616
|
+
bodyKind: "cbam",
|
|
1613
1617
|
maxRetries: 0,
|
|
1614
1618
|
},
|
|
1615
|
-
|
|
1619
|
+
cbam_data_quality_update: {
|
|
1616
1620
|
method: "POST",
|
|
1617
|
-
path: apipath.
|
|
1618
|
-
bodyKind: "
|
|
1621
|
+
path: apipath.CbamDataQualityUpdate(),
|
|
1622
|
+
bodyKind: "cbam",
|
|
1619
1623
|
maxRetries: 0,
|
|
1620
1624
|
},
|
|
1621
|
-
|
|
1625
|
+
cbam_report_generate: {
|
|
1622
1626
|
method: "POST",
|
|
1623
|
-
path: apipath.
|
|
1624
|
-
bodyKind: "
|
|
1625
|
-
|
|
1627
|
+
path: apipath.CbamReportGenerate(),
|
|
1628
|
+
bodyKind: "cbam",
|
|
1629
|
+
// This endpoint only creates the asynchronous generation task. The MCP
|
|
1630
|
+
// composite call owns a separate 120-second total start-and-poll budget.
|
|
1631
|
+
timeoutSeconds: 20,
|
|
1632
|
+
exactTimeout: true,
|
|
1626
1633
|
maxRetries: 0,
|
|
1627
1634
|
},
|
|
1628
|
-
|
|
1635
|
+
cbam_report_generation_status: {
|
|
1629
1636
|
method: "POST",
|
|
1630
|
-
path: apipath.
|
|
1631
|
-
bodyKind: "
|
|
1637
|
+
path: apipath.CbamReportGenerationStatus(),
|
|
1638
|
+
bodyKind: "cbam",
|
|
1639
|
+
maxRetries: 0,
|
|
1632
1640
|
},
|
|
1633
1641
|
user_memory_recall: {
|
|
1634
1642
|
method: "POST",
|
|
@@ -1942,7 +1950,7 @@ export const toolRoutes = {
|
|
|
1942
1950
|
},
|
|
1943
1951
|
};
|
|
1944
1952
|
export function buildBody(route, args) {
|
|
1945
|
-
if (route.bodyKind === "
|
|
1953
|
+
if (route.bodyKind === "cbam") {
|
|
1946
1954
|
const body = { ...args };
|
|
1947
1955
|
const action = body.action;
|
|
1948
1956
|
const view = body.view;
|
|
@@ -1971,18 +1979,21 @@ export function buildBody(route, args) {
|
|
|
1971
1979
|
delete body.items;
|
|
1972
1980
|
delete body.ids;
|
|
1973
1981
|
}
|
|
1974
|
-
const confirmationRequired = route === toolRoutes.
|
|
1975
|
-
|| route === toolRoutes.
|
|
1982
|
+
const confirmationRequired = route === toolRoutes.cbam_factory_save
|
|
1983
|
+
|| route === toolRoutes.cbam_report_generate
|
|
1976
1984
|
|| action === "delete"
|
|
1977
1985
|
|| action === "calculate";
|
|
1978
1986
|
if (!confirmationRequired) {
|
|
1979
1987
|
delete body.confirmed;
|
|
1980
|
-
delete body.pendingActionId;
|
|
1981
1988
|
}
|
|
1982
|
-
return
|
|
1989
|
+
return normalizeCbamCodes(normalizeIds(pickDefined(body)));
|
|
1983
1990
|
}
|
|
1984
1991
|
if (route.bodyKind === "sessionContext") {
|
|
1985
|
-
return pickDefined({
|
|
1992
|
+
return pickDefined({
|
|
1993
|
+
sessionId: args.sessionId,
|
|
1994
|
+
// The Agent-facing module is CBAM; the existing Java contract still uses cbam2.
|
|
1995
|
+
module: args.module === "cbam" ? "cbam2" : args.module,
|
|
1996
|
+
});
|
|
1986
1997
|
}
|
|
1987
1998
|
if (route.bodyKind === "projectRead") {
|
|
1988
1999
|
const projectTaskId = typeof args.projectTaskId === "string"
|
|
@@ -2228,7 +2239,7 @@ function normalizeEnterpriseEmissionSource(source, gasListField) {
|
|
|
2228
2239
|
function normalizeNumericCode(value) {
|
|
2229
2240
|
return typeof value === "string" && /^\d+$/.test(value) ? Number(value) : value;
|
|
2230
2241
|
}
|
|
2231
|
-
const
|
|
2242
|
+
const cbamNumericCodeFields = new Set([
|
|
2232
2243
|
"include",
|
|
2233
2244
|
"includeType",
|
|
2234
2245
|
"processMethod",
|
|
@@ -2252,22 +2263,22 @@ const cbam2NumericCodeFields = new Set([
|
|
|
2252
2263
|
"qualityAssurance",
|
|
2253
2264
|
"orderNum",
|
|
2254
2265
|
]);
|
|
2255
|
-
const
|
|
2256
|
-
function
|
|
2266
|
+
const cbamGenericIdFields = new Set(["id"]);
|
|
2267
|
+
function normalizeCbamCodes(value) {
|
|
2257
2268
|
if (Array.isArray(value))
|
|
2258
|
-
return value.map(
|
|
2269
|
+
return value.map(normalizeCbamCodes);
|
|
2259
2270
|
if (!value || typeof value !== "object")
|
|
2260
2271
|
return value;
|
|
2261
2272
|
const result = {};
|
|
2262
2273
|
for (const [key, childValue] of Object.entries(value)) {
|
|
2263
|
-
if (
|
|
2274
|
+
if (cbamNumericCodeFields.has(key)) {
|
|
2264
2275
|
result[key] = normalizeNumericCode(childValue);
|
|
2265
2276
|
}
|
|
2266
|
-
else if (
|
|
2277
|
+
else if (cbamGenericIdFields.has(key) && typeof childValue === "string" && /^\d+$/.test(childValue)) {
|
|
2267
2278
|
result[key] = normalizeNumericId(childValue);
|
|
2268
2279
|
}
|
|
2269
2280
|
else {
|
|
2270
|
-
result[key] =
|
|
2281
|
+
result[key] = normalizeCbamCodes(childValue);
|
|
2271
2282
|
}
|
|
2272
2283
|
}
|
|
2273
2284
|
return result;
|
|
@@ -2281,8 +2292,8 @@ function normalizeDecimalValue(value) {
|
|
|
2281
2292
|
return Number(normalized);
|
|
2282
2293
|
}
|
|
2283
2294
|
export function validateToolArgs(name, args) {
|
|
2284
|
-
if (name.startsWith("
|
|
2285
|
-
|
|
2295
|
+
if (name.startsWith("cbam_")) {
|
|
2296
|
+
validateCbamArgs(name, args);
|
|
2286
2297
|
return;
|
|
2287
2298
|
}
|
|
2288
2299
|
if (name === "enterprise_emission_batch_save" && Array.isArray(args.orgList)) {
|
|
@@ -2293,122 +2304,122 @@ export function validateToolArgs(name, args) {
|
|
|
2293
2304
|
validateEnterpriseEmissionUpdateArgs(args.computationList);
|
|
2294
2305
|
}
|
|
2295
2306
|
}
|
|
2296
|
-
function
|
|
2297
|
-
if (name === "
|
|
2307
|
+
function validateCbamArgs(name, args) {
|
|
2308
|
+
if (name === "cbam_reference_search") {
|
|
2298
2309
|
const types = Array.isArray(args.types) ? args.types.map(String) : [];
|
|
2299
2310
|
requireUniqueValues(types, "types");
|
|
2300
2311
|
if (types.includes("CARBON_TAX_CANDIDATE") && args.reportId === undefined) {
|
|
2301
|
-
|
|
2312
|
+
cbamInputError("REPORT_ID_REQUIRED", "reportId", "reportId is required when types contains CARBON_TAX_CANDIDATE");
|
|
2302
2313
|
}
|
|
2303
2314
|
return;
|
|
2304
2315
|
}
|
|
2305
|
-
if (name === "
|
|
2316
|
+
if (name === "cbam_report_read") {
|
|
2306
2317
|
if (args.view === "section" && args.section === undefined) {
|
|
2307
|
-
|
|
2318
|
+
cbamInputError("SECTION_REQUIRED", "section", "section is required when view=section");
|
|
2308
2319
|
}
|
|
2309
2320
|
if (args.view === "item") {
|
|
2310
2321
|
if (args.itemType === undefined)
|
|
2311
|
-
|
|
2322
|
+
cbamInputError("ITEM_TYPE_REQUIRED", "itemType", "itemType is required when view=item");
|
|
2312
2323
|
if (args.itemId === undefined)
|
|
2313
|
-
|
|
2324
|
+
cbamInputError("ITEM_ID_REQUIRED", "itemId", "itemId is required when view=item");
|
|
2314
2325
|
}
|
|
2315
2326
|
return;
|
|
2316
2327
|
}
|
|
2317
|
-
if (name === "
|
|
2328
|
+
if (name === "cbam_factory_save") {
|
|
2318
2329
|
validateCreateUpdateId(args, "factoryId");
|
|
2319
|
-
|
|
2330
|
+
validateCbamConfirmation(args, true);
|
|
2320
2331
|
return;
|
|
2321
2332
|
}
|
|
2322
|
-
if (name === "
|
|
2333
|
+
if (name === "cbam_report_save") {
|
|
2323
2334
|
validateCreateUpdateId(args, "reportId");
|
|
2324
2335
|
const report = args.report;
|
|
2325
2336
|
if (report)
|
|
2326
|
-
|
|
2337
|
+
validateCbamDateRange(report.startDate, report.endDate);
|
|
2327
2338
|
return;
|
|
2328
2339
|
}
|
|
2329
|
-
if (name === "
|
|
2330
|
-
|
|
2340
|
+
if (name === "cbam_process_manage") {
|
|
2341
|
+
validateCbamActionPayload(args, ["save", "delete", "reorder"]);
|
|
2331
2342
|
if (args.action === "reorder" || args.action === "delete")
|
|
2332
2343
|
requireUniqueIdArray(args.ids, "ids");
|
|
2333
2344
|
if (args.action === "save")
|
|
2334
2345
|
requireUniqueItemIds(args.items);
|
|
2335
|
-
|
|
2346
|
+
validateCbamConfirmation(args, args.action === "delete");
|
|
2336
2347
|
return;
|
|
2337
2348
|
}
|
|
2338
|
-
if (["
|
|
2339
|
-
|
|
2349
|
+
if (["cbam_precursor_manage", "cbam_source_flow_manage", "cbam_sale_product_manage"].includes(name)) {
|
|
2350
|
+
validateCbamActionPayload(args, ["save", "delete"]);
|
|
2340
2351
|
if (args.action === "delete")
|
|
2341
2352
|
requireUniqueIdArray(args.ids, "ids");
|
|
2342
2353
|
if (args.action === "save")
|
|
2343
2354
|
requireUniqueItemIds(args.items);
|
|
2344
|
-
if (name === "
|
|
2345
|
-
|
|
2355
|
+
if (name === "cbam_source_flow_manage" && args.action === "save") {
|
|
2356
|
+
validateCbamSourceFlows(args.items);
|
|
2346
2357
|
}
|
|
2347
|
-
|
|
2358
|
+
validateCbamConfirmation(args, args.action === "delete");
|
|
2348
2359
|
return;
|
|
2349
2360
|
}
|
|
2350
|
-
if (name === "
|
|
2351
|
-
|
|
2361
|
+
if (name === "cbam_carbon_tax_manage") {
|
|
2362
|
+
validateCbamActionPayload(args, ["save", "delete", "calculate"]);
|
|
2352
2363
|
if (args.action === "delete")
|
|
2353
2364
|
requireUniqueIdArray(args.ids, "ids");
|
|
2354
2365
|
if (args.action === "save")
|
|
2355
2366
|
requireUniqueItemIds(args.items);
|
|
2356
|
-
|
|
2367
|
+
validateCbamConfirmation(args, args.action === "delete" || args.action === "calculate");
|
|
2357
2368
|
return;
|
|
2358
2369
|
}
|
|
2359
|
-
if (name === "
|
|
2370
|
+
if (name === "cbam_product_data_update") {
|
|
2360
2371
|
const itemSchema = args.dataType === "precursor"
|
|
2361
|
-
?
|
|
2362
|
-
:
|
|
2372
|
+
? cbamPrecursorProductData
|
|
2373
|
+
: cbamProcessProductData;
|
|
2363
2374
|
const items = Array.isArray(args.items) ? args.items : [];
|
|
2364
2375
|
for (let index = 0; index < items.length; index++) {
|
|
2365
2376
|
if (!itemSchema.safeParse(items[index]).success) {
|
|
2366
|
-
|
|
2377
|
+
cbamInputError("PRODUCT_DATA_TYPE_MISMATCH", `items[${index}]`, `item does not match dataType=${String(args.dataType)}`);
|
|
2367
2378
|
}
|
|
2368
2379
|
}
|
|
2369
2380
|
requireUniqueItemIds(items);
|
|
2370
2381
|
return;
|
|
2371
2382
|
}
|
|
2372
|
-
if (name === "
|
|
2373
|
-
|
|
2383
|
+
if (name === "cbam_report_generate") {
|
|
2384
|
+
validateCbamConfirmation(args, true);
|
|
2374
2385
|
}
|
|
2375
2386
|
}
|
|
2376
2387
|
function validateCreateUpdateId(args, idField) {
|
|
2377
2388
|
if (args.action === "update" && args[idField] === undefined) {
|
|
2378
|
-
|
|
2389
|
+
cbamInputError("ID_REQUIRED", idField, `${idField} is required when action=update`);
|
|
2379
2390
|
}
|
|
2380
2391
|
if (args.action === "create" && args[idField] !== undefined) {
|
|
2381
|
-
|
|
2392
|
+
cbamInputError("ID_NOT_ALLOWED", idField, `${idField} must be omitted when action=create`);
|
|
2382
2393
|
}
|
|
2383
2394
|
}
|
|
2384
|
-
function
|
|
2395
|
+
function validateCbamActionPayload(args, supported) {
|
|
2385
2396
|
const action = String(args.action || "");
|
|
2386
2397
|
if (!supported.includes(action))
|
|
2387
|
-
|
|
2398
|
+
cbamInputError("INVALID_ACTION", "action", `unsupported action: ${action}`);
|
|
2388
2399
|
if (action === "save") {
|
|
2389
2400
|
requireNonEmptyArray(args.items, "items");
|
|
2390
2401
|
if (args.ids !== undefined)
|
|
2391
|
-
|
|
2402
|
+
cbamInputError("UNEXPECTED_IDS", "ids", "ids must be omitted when action=save");
|
|
2392
2403
|
}
|
|
2393
2404
|
else if (action === "delete" || action === "reorder") {
|
|
2394
2405
|
requireNonEmptyArray(args.ids, "ids");
|
|
2395
2406
|
if (args.items !== undefined)
|
|
2396
|
-
|
|
2407
|
+
cbamInputError("UNEXPECTED_ITEMS", "items", `items must be omitted when action=${action}`);
|
|
2397
2408
|
}
|
|
2398
2409
|
else if (action === "calculate") {
|
|
2399
2410
|
if (args.items !== undefined || args.ids !== undefined) {
|
|
2400
|
-
|
|
2411
|
+
cbamInputError("UNEXPECTED_PAYLOAD", "items", "items and ids must be omitted when action=calculate");
|
|
2401
2412
|
}
|
|
2402
2413
|
}
|
|
2403
2414
|
}
|
|
2404
|
-
function
|
|
2405
|
-
if (!required
|
|
2415
|
+
function validateCbamConfirmation(args, required) {
|
|
2416
|
+
if (!required)
|
|
2406
2417
|
return;
|
|
2407
|
-
if (
|
|
2408
|
-
|
|
2409
|
-
|
|
2418
|
+
if (args.confirmed === true)
|
|
2419
|
+
return;
|
|
2420
|
+
cbamInputError("CONFIRMATION_REQUIRED", "confirmed", "confirmed=true must be injected by the trusted Agent wrapper after user approval");
|
|
2410
2421
|
}
|
|
2411
|
-
function
|
|
2422
|
+
function validateCbamSourceFlows(value) {
|
|
2412
2423
|
if (!Array.isArray(value))
|
|
2413
2424
|
return;
|
|
2414
2425
|
for (let index = 0; index < value.length; index++) {
|
|
@@ -2420,45 +2431,45 @@ function validateCbam2SourceFlows(value) {
|
|
|
2420
2431
|
const processMethod = numericCode(source.processMethod);
|
|
2421
2432
|
const path = `items[${index}]`;
|
|
2422
2433
|
if (![1, 2, 3].includes(sourceType)) {
|
|
2423
|
-
|
|
2434
|
+
cbamInputError("INVALID_SOURCE_FLOW_TYPE", `${path}.sourceType`, "sourceType must be 1, 2, or 3");
|
|
2424
2435
|
}
|
|
2425
2436
|
if (![1, 2, 3, 4, 5, 6, 7].includes(processMethod)) {
|
|
2426
|
-
|
|
2437
|
+
cbamInputError("INVALID_PROCESS_METHOD", `${path}.processMethod`, "processMethod must be between 1 and 7");
|
|
2427
2438
|
}
|
|
2428
2439
|
if (sourceType === 1 && ![1, 2, 3].includes(processMethod)) {
|
|
2429
|
-
|
|
2440
|
+
cbamInputError("INVALID_SOURCE_FLOW_COMBINATION", `${path}.processMethod`, "sourceType=1 supports processMethod 1, 2, or 3");
|
|
2430
2441
|
}
|
|
2431
2442
|
if (sourceType === 2 && ![4, 5].includes(processMethod)) {
|
|
2432
|
-
|
|
2443
|
+
cbamInputError("INVALID_SOURCE_FLOW_COMBINATION", `${path}.processMethod`, "sourceType=2 supports processMethod 4 or 5");
|
|
2433
2444
|
}
|
|
2434
2445
|
if (sourceType === 3 && ![6, 7].includes(processMethod)) {
|
|
2435
|
-
|
|
2446
|
+
cbamInputError("INVALID_SOURCE_FLOW_COMBINATION", `${path}.processMethod`, "sourceType=3 supports processMethod 6 or 7");
|
|
2436
2447
|
}
|
|
2437
2448
|
if (sourceType === 1 && processMethod === 1) {
|
|
2438
|
-
|
|
2449
|
+
requireCbamFields(source, path, ["activityData", "emissionCoefficient", "oxRate"]);
|
|
2439
2450
|
requireLowHeatForEnergyUnit(source, path);
|
|
2440
2451
|
}
|
|
2441
2452
|
else if (sourceType === 1 && processMethod === 2) {
|
|
2442
|
-
|
|
2453
|
+
requireCbamFields(source, path, ["activityData", "emissionCoefficient", "conversionRate"]);
|
|
2443
2454
|
requireLowHeatForEnergyUnit(source, path);
|
|
2444
2455
|
}
|
|
2445
2456
|
else if (sourceType === 1 && processMethod === 3) {
|
|
2446
|
-
|
|
2457
|
+
requireCbamFields(source, path, ["activityData", "carbon", "biomassContent"]);
|
|
2447
2458
|
}
|
|
2448
2459
|
else if (sourceType === 2 && processMethod === 4) {
|
|
2449
|
-
|
|
2460
|
+
requireCbamFields(source, path, ["activityData", "lowHeat", "emissionCoefficient", "conversionRate", "oxRate"]);
|
|
2450
2461
|
}
|
|
2451
2462
|
else if (sourceType === 2 && processMethod === 5) {
|
|
2452
|
-
|
|
2463
|
+
requireCbamFields(source, path, ["activityData", "biomassContent", "carbon", "carbonFossil", "carbonBiological", "oxRate"]);
|
|
2453
2464
|
if (Number(source.carbonFossil) === 0) {
|
|
2454
|
-
|
|
2465
|
+
cbamInputError("INVALID_SOURCE_FLOW_VALUE", `${path}.carbonFossil`, "carbonFossil must be greater than zero for sourceType=2/processMethod=5");
|
|
2455
2466
|
}
|
|
2456
2467
|
if (Number(source.carbon) === 0) {
|
|
2457
|
-
|
|
2468
|
+
cbamInputError("INVALID_SOURCE_FLOW_VALUE", `${path}.carbon`, "carbon must be greater than zero for sourceType=2/processMethod=5");
|
|
2458
2469
|
}
|
|
2459
2470
|
}
|
|
2460
2471
|
else if (sourceType === 3 && [6, 7].includes(processMethod)) {
|
|
2461
|
-
|
|
2472
|
+
requireCbamFields(source, path, ["lowHeat", "emissionCoefficient", "conversionRate", "biomassContent"]);
|
|
2462
2473
|
}
|
|
2463
2474
|
}
|
|
2464
2475
|
}
|
|
@@ -2469,27 +2480,27 @@ function numericCode(value) {
|
|
|
2469
2480
|
return Number(value.trim());
|
|
2470
2481
|
return Number.NaN;
|
|
2471
2482
|
}
|
|
2472
|
-
function
|
|
2483
|
+
function requireCbamFields(item, path, fields) {
|
|
2473
2484
|
for (const field of fields) {
|
|
2474
2485
|
if (item[field] === undefined || item[field] === null || item[field] === "") {
|
|
2475
|
-
|
|
2486
|
+
cbamInputError("SOURCE_FLOW_FIELD_REQUIRED", `${path}.${field}`, `${field} is required for the selected sourceType/processMethod formula`);
|
|
2476
2487
|
}
|
|
2477
2488
|
}
|
|
2478
2489
|
}
|
|
2479
2490
|
function requireLowHeatForEnergyUnit(item, path) {
|
|
2480
2491
|
if (item.emissionCoefficientUnit === "tCO2/TJ") {
|
|
2481
|
-
|
|
2492
|
+
requireCbamFields(item, path, ["lowHeat"]);
|
|
2482
2493
|
}
|
|
2483
2494
|
}
|
|
2484
|
-
function
|
|
2495
|
+
function validateCbamDateRange(startValue, endValue) {
|
|
2485
2496
|
const start = String(startValue || "");
|
|
2486
2497
|
const end = String(endValue || "");
|
|
2487
2498
|
if (!isExactCalendarDate(start))
|
|
2488
|
-
|
|
2499
|
+
cbamInputError("INVALID_DATE", "report.startDate", "startDate must be a valid yyyy-MM-dd date");
|
|
2489
2500
|
if (!isExactCalendarDate(end))
|
|
2490
|
-
|
|
2501
|
+
cbamInputError("INVALID_DATE", "report.endDate", "endDate must be a valid yyyy-MM-dd date");
|
|
2491
2502
|
if (start > end)
|
|
2492
|
-
|
|
2503
|
+
cbamInputError("INVALID_PERIOD", "report.startDate", "startDate must not be after endDate");
|
|
2493
2504
|
}
|
|
2494
2505
|
function isExactCalendarDate(value) {
|
|
2495
2506
|
const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value);
|
|
@@ -2505,7 +2516,7 @@ function isExactCalendarDate(value) {
|
|
|
2505
2516
|
}
|
|
2506
2517
|
function requireNonEmptyArray(value, path) {
|
|
2507
2518
|
if (!Array.isArray(value) || value.length === 0) {
|
|
2508
|
-
|
|
2519
|
+
cbamInputError("NON_EMPTY_ARRAY_REQUIRED", path, `${path} must be a non-empty array`);
|
|
2509
2520
|
}
|
|
2510
2521
|
}
|
|
2511
2522
|
function requireUniqueIdArray(value, path) {
|
|
@@ -2527,11 +2538,11 @@ function requireUniqueValues(values, path) {
|
|
|
2527
2538
|
const seen = new Set();
|
|
2528
2539
|
for (const value of values) {
|
|
2529
2540
|
if (seen.has(value))
|
|
2530
|
-
|
|
2541
|
+
cbamInputError("DUPLICATE_VALUE", path, `${path} must not contain duplicate values`);
|
|
2531
2542
|
seen.add(value);
|
|
2532
2543
|
}
|
|
2533
2544
|
}
|
|
2534
|
-
function
|
|
2545
|
+
function cbamInputError(code, path, message) {
|
|
2535
2546
|
throw new ToolInputValidationError(code, path, message);
|
|
2536
2547
|
}
|
|
2537
2548
|
function validateEnterpriseEmissionSaveArgs(orgList) {
|