gm-mcp 1.3.9 → 1.3.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +5 -1
- package/dist/tools/lark-tool.d.ts +2 -0
- package/dist/tools/lark-tool.js +24 -8
- package/package.json +1 -1
- package/src/index.ts +5 -1
- package/src/tools/lark-tool.ts +27 -7
package/dist/index.js
CHANGED
|
@@ -86,6 +86,7 @@ exports.server.registerTool("debt_collection", {
|
|
|
86
86
|
- compnany name
|
|
87
87
|
- year (optional), if it is not provided use default value
|
|
88
88
|
- product (optional), if it is not provided use default value
|
|
89
|
+
- month (optinal), if it is not provided use default value
|
|
89
90
|
with optional criteria try to use default value, don't ask again
|
|
90
91
|
`,
|
|
91
92
|
inputSchema: v4_1.default.object({
|
|
@@ -100,13 +101,16 @@ exports.server.registerTool("debt_collection", {
|
|
|
100
101
|
.describe("Product type to get data one of follow values EWA 02 - 03 | EWA 04 | Lương X3 | Lương X3 - EVF ")
|
|
101
102
|
.default(product_type_1.PRODUCT_TYPE.EWA_02_03)
|
|
102
103
|
.optional(),
|
|
104
|
+
month: v4_1.default.string().describe("Month to get company debt collection").default("").optional(),
|
|
103
105
|
}),
|
|
104
106
|
}, (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
105
|
-
const { company_name, product_type } = args;
|
|
107
|
+
const { company_name, product_type, month, year } = args;
|
|
106
108
|
return (0, lark_tool_1.debtCollectionRateTool)({
|
|
107
109
|
sendMessageToLark: (0, env_1.getEnv)().SEND_MESSAGE_TO_LARK === "true",
|
|
108
110
|
companyName: company_name,
|
|
109
111
|
productType: product_type,
|
|
112
|
+
month,
|
|
113
|
+
year,
|
|
110
114
|
});
|
|
111
115
|
}));
|
|
112
116
|
// server.tool(
|
package/dist/tools/lark-tool.js
CHANGED
|
@@ -10,7 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.debtCollectionRateTool = debtCollectionRateTool;
|
|
13
|
-
const helpers_1 = require("../helpers");
|
|
14
13
|
const search_like_1 = require("../helpers/search-like");
|
|
15
14
|
const report_columns_1 = require("../services/constants/report-columns");
|
|
16
15
|
const lark_base_service_1 = require("../services/lark-base.service");
|
|
@@ -22,16 +21,26 @@ const debReductionMonthKey = "THÁNG CẮT NỢ";
|
|
|
22
21
|
const productKey = "Loại Sản phẩm";
|
|
23
22
|
const monthReductionDebtKey = "THÁNG CẮT NỢ";
|
|
24
23
|
const statusKey = "TRẠNG THÁI";
|
|
24
|
+
const VALID_YEARS = ["2025", "2026"];
|
|
25
25
|
function debtCollectionRateTool(options) {
|
|
26
26
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
27
|
var _c, _d;
|
|
28
|
-
const { sendMessageToLark, companyName, monthDate, productType } = options;
|
|
29
|
-
|
|
28
|
+
const { sendMessageToLark, companyName, monthDate, productType, month, year } = options;
|
|
29
|
+
if (!VALID_YEARS.includes(year || "")) {
|
|
30
|
+
yield (0, lark_service_1.sendReportOpsGroup)({
|
|
31
|
+
title: ["Tỉ lệ thu nợ", companyName].filter(Boolean).join(" - "),
|
|
32
|
+
message_content: `Rất tiếc tôi chưa có dữ liệu của năm ${year}, bạn hãy thử lại với năm ${VALID_YEARS.join(",")}`,
|
|
33
|
+
});
|
|
34
|
+
throw new Error("Year is invalid");
|
|
35
|
+
}
|
|
36
|
+
// const monthParts = !monthDate ? null : extractMonth(monthDate);
|
|
30
37
|
// if (monthParts === null) {
|
|
31
38
|
// return { content: [{ type: "text", text: `${monthDate} is invalid` }] };
|
|
32
39
|
// }
|
|
33
40
|
const fieldNames = report_columns_1.REPORT_COLUMS.map((item) => item.field_name);
|
|
34
41
|
try {
|
|
42
|
+
// @Todo find by year
|
|
43
|
+
//
|
|
35
44
|
const records = yield (0, lark_base_service_1.fetchDebtCollectionRecords)();
|
|
36
45
|
// console.log(records);
|
|
37
46
|
// Find by name first
|
|
@@ -46,10 +55,9 @@ function debtCollectionRateTool(options) {
|
|
|
46
55
|
// Then find by product
|
|
47
56
|
const foundRecords = companiesMatchName
|
|
48
57
|
.filter((item) => {
|
|
49
|
-
if (
|
|
58
|
+
if (!month) {
|
|
50
59
|
return true;
|
|
51
60
|
}
|
|
52
|
-
const { month } = monthParts;
|
|
53
61
|
return compareReductionDebtMonth(item.fields[debReductionMonthKey], month.toString());
|
|
54
62
|
})
|
|
55
63
|
.filter((item) => {
|
|
@@ -58,14 +66,22 @@ function debtCollectionRateTool(options) {
|
|
|
58
66
|
return true;
|
|
59
67
|
}
|
|
60
68
|
return ((_c = item.fields[productKey]) === null || _c === void 0 ? void 0 : _c.toLowerCase()) === productType.toLowerCase();
|
|
61
|
-
})
|
|
69
|
+
})
|
|
70
|
+
.sort((a, b) => b.fields[debReductionMonthKey].localeCompare(a.fields[debReductionMonthKey]));
|
|
62
71
|
// const foundMonth = searchLike(
|
|
63
72
|
// month.toString(),
|
|
64
73
|
// companiesMatchName.map((item) => item.fields["KỲ LƯƠNG"])
|
|
65
74
|
// )[0];
|
|
66
|
-
console.log(foundRecords);
|
|
75
|
+
// console.log(foundRecords);
|
|
67
76
|
// const finalCompnay = companiesMatchName.find((item) => item.fields["KỲ LƯƠNG"] === foundMonth);
|
|
68
77
|
// console.log(finalCompnay);
|
|
78
|
+
if (foundRecords.length === 0) {
|
|
79
|
+
yield (0, lark_service_1.sendReportOpsGroup)({
|
|
80
|
+
title: ["Tỉ lệ thu nợ", foundName, productType].filter(Boolean).join(" - "),
|
|
81
|
+
message_content: `Rất tiếc, Tôi chưa có thông tin`,
|
|
82
|
+
});
|
|
83
|
+
throw new Error("Data is not found");
|
|
84
|
+
}
|
|
69
85
|
const messages = [];
|
|
70
86
|
for (const item of foundRecords) {
|
|
71
87
|
messages.push([
|
|
@@ -92,7 +108,7 @@ function debtCollectionRateTool(options) {
|
|
|
92
108
|
// return {} as any;
|
|
93
109
|
if (sendMessageToLark) {
|
|
94
110
|
yield (0, lark_service_1.sendReportOpsGroup)({
|
|
95
|
-
title: [
|
|
111
|
+
title: ["Tỉ lệ thu nợ", foundName, productType].filter(Boolean).join(" - "),
|
|
96
112
|
message_content: messages.join("<hr>"),
|
|
97
113
|
});
|
|
98
114
|
}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -98,6 +98,7 @@ server.registerTool(
|
|
|
98
98
|
- compnany name
|
|
99
99
|
- year (optional), if it is not provided use default value
|
|
100
100
|
- product (optional), if it is not provided use default value
|
|
101
|
+
- month (optinal), if it is not provided use default value
|
|
101
102
|
with optional criteria try to use default value, don't ask again
|
|
102
103
|
`,
|
|
103
104
|
inputSchema: z.object({
|
|
@@ -112,14 +113,17 @@ server.registerTool(
|
|
|
112
113
|
.describe("Product type to get data one of follow values EWA 02 - 03 | EWA 04 | Lương X3 | Lương X3 - EVF ")
|
|
113
114
|
.default(PRODUCT_TYPE.EWA_02_03)
|
|
114
115
|
.optional(),
|
|
116
|
+
month: z.string().describe("Month to get company debt collection").default("").optional(),
|
|
115
117
|
}),
|
|
116
118
|
},
|
|
117
119
|
async (args) => {
|
|
118
|
-
const { company_name, product_type } = args;
|
|
120
|
+
const { company_name, product_type, month, year } = args;
|
|
119
121
|
return debtCollectionRateTool({
|
|
120
122
|
sendMessageToLark: getEnv().SEND_MESSAGE_TO_LARK === "true",
|
|
121
123
|
companyName: company_name,
|
|
122
124
|
productType: product_type,
|
|
125
|
+
month,
|
|
126
|
+
year,
|
|
123
127
|
});
|
|
124
128
|
}
|
|
125
129
|
);
|
package/src/tools/lark-tool.ts
CHANGED
|
@@ -13,19 +13,32 @@ const productKey = "Loại Sản phẩm";
|
|
|
13
13
|
const monthReductionDebtKey = "THÁNG CẮT NỢ";
|
|
14
14
|
const statusKey = "TRẠNG THÁI";
|
|
15
15
|
|
|
16
|
+
const VALID_YEARS = ["2025", "2026"];
|
|
17
|
+
|
|
16
18
|
export async function debtCollectionRateTool(options: {
|
|
17
19
|
sendMessageToLark: boolean;
|
|
18
20
|
companyName: string;
|
|
19
21
|
monthDate?: string;
|
|
20
22
|
productType?: string;
|
|
23
|
+
month?: string;
|
|
24
|
+
year?: string;
|
|
21
25
|
}): Promise<CallToolResult> {
|
|
22
|
-
const { sendMessageToLark, companyName, monthDate, productType } = options;
|
|
23
|
-
|
|
26
|
+
const { sendMessageToLark, companyName, monthDate, productType, month, year } = options;
|
|
27
|
+
if (!VALID_YEARS.includes(year || "")) {
|
|
28
|
+
await sendReportOpsGroup({
|
|
29
|
+
title: ["Tỉ lệ thu nợ", companyName].filter(Boolean).join(" - "),
|
|
30
|
+
message_content: `Rất tiếc tôi chưa có dữ liệu của năm ${year}, bạn hãy thử lại với năm ${VALID_YEARS.join(",")}`,
|
|
31
|
+
});
|
|
32
|
+
throw new Error("Year is invalid");
|
|
33
|
+
}
|
|
34
|
+
// const monthParts = !monthDate ? null : extractMonth(monthDate);
|
|
24
35
|
// if (monthParts === null) {
|
|
25
36
|
// return { content: [{ type: "text", text: `${monthDate} is invalid` }] };
|
|
26
37
|
// }
|
|
27
38
|
const fieldNames = REPORT_COLUMS.map((item) => item.field_name);
|
|
28
39
|
try {
|
|
40
|
+
// @Todo find by year
|
|
41
|
+
//
|
|
29
42
|
const records = await fetchDebtCollectionRecords();
|
|
30
43
|
// console.log(records);
|
|
31
44
|
|
|
@@ -42,10 +55,9 @@ export async function debtCollectionRateTool(options: {
|
|
|
42
55
|
// Then find by product
|
|
43
56
|
const foundRecords = companiesMatchName
|
|
44
57
|
.filter((item) => {
|
|
45
|
-
if (
|
|
58
|
+
if (!month) {
|
|
46
59
|
return true;
|
|
47
60
|
}
|
|
48
|
-
const { month } = monthParts;
|
|
49
61
|
return compareReductionDebtMonth(item.fields[debReductionMonthKey], month.toString());
|
|
50
62
|
})
|
|
51
63
|
.filter((item) => {
|
|
@@ -53,14 +65,22 @@ export async function debtCollectionRateTool(options: {
|
|
|
53
65
|
return true;
|
|
54
66
|
}
|
|
55
67
|
return (item.fields[productKey] as string)?.toLowerCase() === productType.toLowerCase();
|
|
56
|
-
})
|
|
68
|
+
})
|
|
69
|
+
.sort((a, b) => (b.fields[debReductionMonthKey] as string).localeCompare(a.fields[debReductionMonthKey]));
|
|
57
70
|
// const foundMonth = searchLike(
|
|
58
71
|
// month.toString(),
|
|
59
72
|
// companiesMatchName.map((item) => item.fields["KỲ LƯƠNG"])
|
|
60
73
|
// )[0];
|
|
61
|
-
console.log(foundRecords);
|
|
74
|
+
// console.log(foundRecords);
|
|
62
75
|
// const finalCompnay = companiesMatchName.find((item) => item.fields["KỲ LƯƠNG"] === foundMonth);
|
|
63
76
|
// console.log(finalCompnay);
|
|
77
|
+
if (foundRecords.length === 0) {
|
|
78
|
+
await sendReportOpsGroup({
|
|
79
|
+
title: ["Tỉ lệ thu nợ", foundName, productType].filter(Boolean).join(" - "),
|
|
80
|
+
message_content: `Rất tiếc, Tôi chưa có thông tin`,
|
|
81
|
+
});
|
|
82
|
+
throw new Error("Data is not found");
|
|
83
|
+
}
|
|
64
84
|
|
|
65
85
|
const messages: string[] = [];
|
|
66
86
|
for (const item of foundRecords) {
|
|
@@ -92,7 +112,7 @@ export async function debtCollectionRateTool(options: {
|
|
|
92
112
|
|
|
93
113
|
if (sendMessageToLark) {
|
|
94
114
|
await sendReportOpsGroup({
|
|
95
|
-
title: [
|
|
115
|
+
title: ["Tỉ lệ thu nợ", foundName, productType].filter(Boolean).join(" - "),
|
|
96
116
|
message_content: messages.join("<hr>"),
|
|
97
117
|
});
|
|
98
118
|
}
|