@harrylabsj/kiwi 0.12.30 → 0.12.31
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/a2a/server/merchant-handler.d.ts +22 -1
- package/dist/a2a/server/merchant-handler.js +222 -27
- package/dist/a2a/server/merchant-handler.js.map +1 -1
- package/dist/agent/buyer/buyer-tools.js +1 -2
- package/dist/agent/buyer/buyer-tools.js.map +1 -1
- package/dist/agent/buyer/search-loop.js +0 -1
- package/dist/agent/buyer/search-loop.js.map +1 -1
- package/dist/buyer-core/merchant-index.js +0 -1
- package/dist/buyer-core/merchant-index.js.map +1 -1
- package/dist/buyer-core/service.d.ts +1 -0
- package/dist/buyer-core/service.js +4 -3
- package/dist/buyer-core/service.js.map +1 -1
- package/dist/cli.js +123 -32
- package/dist/cli.js.map +1 -1
- package/dist/cloud/bootstrap.d.ts +1 -1
- package/dist/cloud/bootstrap.js +21 -28
- package/dist/cloud/bootstrap.js.map +1 -1
- package/dist/cloud/product-import-tabular.js +13 -5
- package/dist/cloud/product-import-tabular.js.map +1 -1
- package/dist/cloud/trade-platforms-client.d.ts +30 -0
- package/dist/cloud/trade-platforms-client.js +34 -1
- package/dist/cloud/trade-platforms-client.js.map +1 -1
- package/dist/handoff/trade-platform-rules.js +5 -2
- package/dist/handoff/trade-platform-rules.js.map +1 -1
- package/dist/http/merchant-management/api.d.ts +1 -1
- package/dist/http/merchant-management/api.js +28 -3
- package/dist/http/merchant-management/api.js.map +1 -1
- package/dist/http/merchant-management/page.js +83 -22
- package/dist/http/merchant-management/page.js.map +1 -1
- package/dist/mcp/tools.js +5 -2
- package/dist/mcp/tools.js.map +1 -1
- package/dist/merchant/workbench-server.d.ts +37 -0
- package/dist/merchant/workbench-server.js +254 -0
- package/dist/merchant/workbench-server.js.map +1 -0
- package/dist/merchant-gateway/catalog-tools.js +4 -2
- package/dist/merchant-gateway/catalog-tools.js.map +1 -1
- package/dist/product-buyer.d.ts +1 -0
- package/dist/product-buyer.js +0 -1
- package/dist/product-buyer.js.map +1 -1
- package/dist/product-cli.js +11 -1
- package/dist/product-cli.js.map +1 -1
- package/package.json +5 -3
- package/skills/kiwi-buyer/SKILL.md +1 -1
|
@@ -19,7 +19,7 @@ import { LedgerStore } from "../../negotiation/ledger/index.js";
|
|
|
19
19
|
import type { MerchantPolicy } from "../../config/profile.js";
|
|
20
20
|
import type { NegotiationApprovalStore } from "./negotiation-approvals.js";
|
|
21
21
|
import { type NegotiationAdvisor } from "./negotiation-advisor.js";
|
|
22
|
-
import type { InquiryInterpreter } from "./inquiry-interpreter.js";
|
|
22
|
+
import type { InquiryInterpreter, InquiryTopic } from "./inquiry-interpreter.js";
|
|
23
23
|
import type { ReceptionEngine } from "../reception/engine.js";
|
|
24
24
|
import type { A2AMessage } from "../client/types.js";
|
|
25
25
|
import type { NegotiationHandler } from "./types.js";
|
|
@@ -30,6 +30,27 @@ export declare const MERCHANT_OFFER_PRICE_MINOR = 85000;
|
|
|
30
30
|
export declare const MERCHANT_DEAL_PRICE_MINOR = 83500;
|
|
31
31
|
export declare const MERCHANT_QUANTITY = 200;
|
|
32
32
|
export declare function resolveDeliveryBefore(merchantPolicy: MerchantPolicy | undefined, now: string): string | undefined;
|
|
33
|
+
/** 买家文本是否中文(只影响回复语言,不影响任何事实/价格)。 */
|
|
34
|
+
export declare function prefersChineseText(text: string | undefined): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* 回复语言:有中文即中文;纯英文文本用英文;没有任何语言线索时按 Kiwi
|
|
37
|
+
* 中文市场默认中文(CNY/中文商家)。只影响措辞,不影响事实。
|
|
38
|
+
*/
|
|
39
|
+
export declare function replyLanguageOf(...texts: (string | undefined)[]): "zh" | "en";
|
|
40
|
+
/** 从买家 RFQ 的 requested_terms.delivery_before 取合法 ISO 时间。 */
|
|
41
|
+
export declare function requestedDeliveryBeforeOf(payload: unknown): string | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* 买家文本里的相对交期(“7天到中国”“两周内送达”)。只用于把买家的
|
|
44
|
+
* 时限与商家已配置的权威交期对齐;解析不出就不猜。
|
|
45
|
+
*/
|
|
46
|
+
export declare function requestedDeliveryDaysOf(text: string): number | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* 交期应答:买家给了明确时限时,必须回答“能否满足”,不能只说“待确认”。
|
|
49
|
+
* 事实只来自 merchant_policy.delivery_lead_days 或“未配置”这一事实。
|
|
50
|
+
*/
|
|
51
|
+
export declare function deliveryCommitmentNote(requestedBefore: string | undefined, promisedBefore: string | undefined, language: "zh" | "en"): string | undefined;
|
|
52
|
+
/** 从买家问题推断商业主题的确定性兜底(模型不可用时仍按问题作答)。 */
|
|
53
|
+
export declare function inferInquiryTopicsFromText(text: string): InquiryTopic[];
|
|
33
54
|
/** 批量促销默认门槛(merchant_policy.promos[sku].bulk_threshold 缺省值)。 */
|
|
34
55
|
export declare const DEFAULT_BULK_THRESHOLD = 100;
|
|
35
56
|
/**
|
|
@@ -75,6 +75,100 @@ export function resolveDeliveryBefore(merchantPolicy, now) {
|
|
|
75
75
|
return undefined;
|
|
76
76
|
return new Date(Date.parse(now) + leadDays * 86_400_000).toISOString();
|
|
77
77
|
}
|
|
78
|
+
const CJK_TEXT_RE = /[一-鿿]/;
|
|
79
|
+
/** 买家文本是否中文(只影响回复语言,不影响任何事实/价格)。 */
|
|
80
|
+
export function prefersChineseText(text) {
|
|
81
|
+
return text !== undefined && CJK_TEXT_RE.test(text);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* 回复语言:有中文即中文;纯英文文本用英文;没有任何语言线索时按 Kiwi
|
|
85
|
+
* 中文市场默认中文(CNY/中文商家)。只影响措辞,不影响事实。
|
|
86
|
+
*/
|
|
87
|
+
export function replyLanguageOf(...texts) {
|
|
88
|
+
const joined = texts
|
|
89
|
+
.filter((text) => text !== undefined && text.trim() !== "")
|
|
90
|
+
.join(" ")
|
|
91
|
+
.trim();
|
|
92
|
+
if (joined === "")
|
|
93
|
+
return "zh";
|
|
94
|
+
if (CJK_TEXT_RE.test(joined))
|
|
95
|
+
return "zh";
|
|
96
|
+
return /[A-Za-z]/.test(joined) ? "en" : "zh";
|
|
97
|
+
}
|
|
98
|
+
/** 从买家 RFQ 的 requested_terms.delivery_before 取合法 ISO 时间。 */
|
|
99
|
+
export function requestedDeliveryBeforeOf(payload) {
|
|
100
|
+
if (typeof payload !== "object" || payload === null)
|
|
101
|
+
return undefined;
|
|
102
|
+
const requested = payload.requested_terms;
|
|
103
|
+
if (typeof requested !== "object" || requested === null)
|
|
104
|
+
return undefined;
|
|
105
|
+
const value = requested.delivery_before;
|
|
106
|
+
if (typeof value !== "string" || value.trim() === "")
|
|
107
|
+
return undefined;
|
|
108
|
+
const parsed = Date.parse(value);
|
|
109
|
+
return Number.isFinite(parsed) ? new Date(parsed).toISOString() : undefined;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* 买家文本里的相对交期(“7天到中国”“两周内送达”)。只用于把买家的
|
|
113
|
+
* 时限与商家已配置的权威交期对齐;解析不出就不猜。
|
|
114
|
+
*/
|
|
115
|
+
export function requestedDeliveryDaysOf(text) {
|
|
116
|
+
const numeric = /(\d{1,3})\s*(?:个)?\s*(?:工作日|天|日)\s*(?:内|以内|到|到达|送到|送达|发到|发货|到货)?/.exec(text);
|
|
117
|
+
if (numeric !== null) {
|
|
118
|
+
const days = Number(numeric[1]);
|
|
119
|
+
return Number.isSafeInteger(days) && days > 0 ? days : undefined;
|
|
120
|
+
}
|
|
121
|
+
const chinese = /([一二两三四五六七八九十]+)\s*(?:个)?\s*(?:工作日|天|日)\s*(?:内|以内|到|到达|送到|送达|发到|发货|到货)?/.exec(text);
|
|
122
|
+
if (chinese === null)
|
|
123
|
+
return undefined;
|
|
124
|
+
const digits = {
|
|
125
|
+
一: 1, 二: 2, 两: 2, 三: 3, 四: 4, 五: 5, 六: 6, 七: 7, 八: 8, 九: 9, 十: 10,
|
|
126
|
+
};
|
|
127
|
+
const raw = chinese[1];
|
|
128
|
+
if (raw === "十")
|
|
129
|
+
return 10;
|
|
130
|
+
const tenIndex = raw.indexOf("十");
|
|
131
|
+
if (tenIndex === -1)
|
|
132
|
+
return raw.length === 1 ? digits[raw] : undefined;
|
|
133
|
+
const tens = tenIndex === 0 ? 1 : digits[raw.slice(0, tenIndex)];
|
|
134
|
+
const ones = tenIndex === raw.length - 1 ? 0 : digits[raw.slice(tenIndex + 1)];
|
|
135
|
+
return tens === undefined || ones === undefined ? undefined : tens * 10 + ones;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* 交期应答:买家给了明确时限时,必须回答“能否满足”,不能只说“待确认”。
|
|
139
|
+
* 事实只来自 merchant_policy.delivery_lead_days 或“未配置”这一事实。
|
|
140
|
+
*/
|
|
141
|
+
export function deliveryCommitmentNote(requestedBefore, promisedBefore, language) {
|
|
142
|
+
if (requestedBefore === undefined)
|
|
143
|
+
return undefined;
|
|
144
|
+
const requestedDay = requestedBefore.slice(0, 10);
|
|
145
|
+
if (promisedBefore === undefined) {
|
|
146
|
+
return language === "zh"
|
|
147
|
+
? `您要求不晚于 ${requestedDay} 到货;本店尚未配置可承诺的交期,无法确认该时限,请与商家确认。`
|
|
148
|
+
: `You asked for delivery by ${requestedDay}; this merchant has no committed lead time configured, so that deadline cannot be confirmed.`;
|
|
149
|
+
}
|
|
150
|
+
const promisedDay = promisedBefore.slice(0, 10);
|
|
151
|
+
if (Date.parse(promisedBefore) <= Date.parse(requestedBefore)) {
|
|
152
|
+
return language === "zh"
|
|
153
|
+
? `您要求不晚于 ${requestedDay} 到货;当前预计交期不晚于 ${promisedDay},可以满足。`
|
|
154
|
+
: `You asked for delivery by ${requestedDay}; the current estimate is by ${promisedDay}, which meets it.`;
|
|
155
|
+
}
|
|
156
|
+
return language === "zh"
|
|
157
|
+
? `您要求不晚于 ${requestedDay} 到货;当前预计交期不晚于 ${promisedDay},无法承诺该时限。`
|
|
158
|
+
: `You asked for delivery by ${requestedDay}; the current estimate is by ${promisedDay}, so that deadline cannot be committed.`;
|
|
159
|
+
}
|
|
160
|
+
/** 从买家问题推断商业主题的确定性兜底(模型不可用时仍按问题作答)。 */
|
|
161
|
+
export function inferInquiryTopicsFromText(text) {
|
|
162
|
+
const topics = new Set();
|
|
163
|
+
if (/价|多少钱|报价|便宜|优惠|折扣|price|cost|discount/i.test(text))
|
|
164
|
+
topics.add("price");
|
|
165
|
+
if (/库存|现货|有货|缺货|stock|inventory|availability/i.test(text))
|
|
166
|
+
topics.add("stock");
|
|
167
|
+
if (/交期|发货|送达|到货|多久|几天|多少天|\d+\s*(?:天|日)|delivery|eta|ship|lead.?time|arrive/i.test(text)) {
|
|
168
|
+
topics.add("delivery");
|
|
169
|
+
}
|
|
170
|
+
return [...topics];
|
|
171
|
+
}
|
|
78
172
|
/** 批量促销默认门槛(merchant_policy.promos[sku].bulk_threshold 缺省值)。 */
|
|
79
173
|
export const DEFAULT_BULK_THRESHOLD = 100;
|
|
80
174
|
/**
|
|
@@ -936,13 +1030,18 @@ export function createMerchantHandler(options) {
|
|
|
936
1030
|
}
|
|
937
1031
|
}
|
|
938
1032
|
const sku = structuredSku ?? interpreted?.sku;
|
|
1033
|
+
const language = interpreted?.language ?? replyLanguageOf(buyerMessage);
|
|
939
1034
|
if (sku === undefined) {
|
|
940
|
-
return textReply(
|
|
1035
|
+
return textReply(language === "zh"
|
|
1036
|
+
? "请提供商品 SKU、数量和单位,我才能按商品源给你正式报价。"
|
|
1037
|
+
: "Please provide a product SKU, quantity and declared unit for a source-backed quote.");
|
|
941
1038
|
}
|
|
942
1039
|
const topics = new Set(structuredTopics);
|
|
943
1040
|
for (const topic of interpreted?.topics ?? [])
|
|
944
1041
|
topics.add(topic);
|
|
945
|
-
|
|
1042
|
+
// 模型/解释器不可用时仍按买家原文识别主题,避免把具体问题答成模板。
|
|
1043
|
+
for (const topic of inferInquiryTopicsFromText(buyerMessage ?? ""))
|
|
1044
|
+
topics.add(topic);
|
|
946
1045
|
const resolved = await resolveProductOrDecline(sku);
|
|
947
1046
|
if ("declined" in resolved) {
|
|
948
1047
|
// 询价不是商业承诺:商品源确认不了就要求核对 SKU,不发 decline 信封。
|
|
@@ -978,13 +1077,32 @@ export function createMerchantHandler(options) {
|
|
|
978
1077
|
else if (topics.has("stock")) {
|
|
979
1078
|
lines.push(language === "zh" ? "库存状态待确认。" : "Stock status needs confirmation.");
|
|
980
1079
|
}
|
|
981
|
-
if (
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
1080
|
+
if (askAll || topics.has("delivery")) {
|
|
1081
|
+
const requestedDays = requestedDeliveryDaysOf(buyerMessage ?? "");
|
|
1082
|
+
if (delivery !== undefined) {
|
|
1083
|
+
const canMeet = requestedDays !== undefined &&
|
|
1084
|
+
Date.parse(delivery) <= Date.parse(now()) + requestedDays * 86_400_000;
|
|
1085
|
+
lines.push(requestedDays === undefined
|
|
1086
|
+
? language === "zh"
|
|
1087
|
+
? `预计交期不晚于 ${delivery.slice(0, 10)}。`
|
|
1088
|
+
: `Estimated delivery is by ${delivery.slice(0, 10)}.`
|
|
1089
|
+
: canMeet
|
|
1090
|
+
? language === "zh"
|
|
1091
|
+
? `您要求 ${requestedDays} 天到货;预计交期不晚于 ${delivery.slice(0, 10)},可以满足。`
|
|
1092
|
+
: `You asked for delivery within ${requestedDays} days; the estimate is by ${delivery.slice(0, 10)}, which meets it.`
|
|
1093
|
+
: language === "zh"
|
|
1094
|
+
? `您要求 ${requestedDays} 天到货;预计交期不晚于 ${delivery.slice(0, 10)},无法承诺 ${requestedDays} 天送达。`
|
|
1095
|
+
: `You asked for delivery within ${requestedDays} days; the estimate is by ${delivery.slice(0, 10)}, so that deadline cannot be committed.`);
|
|
1096
|
+
}
|
|
1097
|
+
else {
|
|
1098
|
+
lines.push(requestedDays !== undefined
|
|
1099
|
+
? language === "zh"
|
|
1100
|
+
? `您要求 ${requestedDays} 天到货;本店尚未配置可承诺的交期,无法确认 ${requestedDays} 天送达,请与商家确认。`
|
|
1101
|
+
: `You asked for delivery within ${requestedDays} days; this merchant has no committed lead time configured, so ${requestedDays}-day delivery cannot be confirmed.`
|
|
1102
|
+
: language === "zh"
|
|
1103
|
+
? "本店尚未配置可承诺的交期,交期待确认;请与商家确认。"
|
|
1104
|
+
: "Delivery timing needs confirmation with the merchant.");
|
|
1105
|
+
}
|
|
988
1106
|
}
|
|
989
1107
|
lines.push(language === "zh"
|
|
990
1108
|
? "以上为非约束性信息;请发送 RFQ(SKU、数量、单位)获取正式报价。"
|
|
@@ -1036,7 +1154,12 @@ export function createMerchantHandler(options) {
|
|
|
1036
1154
|
})
|
|
1037
1155
|
: undefined;
|
|
1038
1156
|
const quoteNote = quoteMessage(product);
|
|
1039
|
-
|
|
1157
|
+
// 买家在 RFQ 里声明了到货时限时必须逐条回应,不能只回价格。
|
|
1158
|
+
const language = replyLanguageOf(envelope.public_message, buyerMessage);
|
|
1159
|
+
const deliveryNote = deliveryCommitmentNote(requestedDeliveryBeforeOf(envelope.payload), deliveryBefore(), language);
|
|
1160
|
+
const publicMessage = [advisedMessage, quoteNote.public_message, deliveryNote]
|
|
1161
|
+
.filter((part) => part !== undefined && part.trim() !== "")
|
|
1162
|
+
.join(" ") || undefined;
|
|
1040
1163
|
const reply = seedEnvelope({
|
|
1041
1164
|
negotiation_id: negotiationId,
|
|
1042
1165
|
in_reply_to: inReplyTo,
|
|
@@ -1279,6 +1402,34 @@ export function createMerchantHandler(options) {
|
|
|
1279
1402
|
stock_available: product.stock !== undefined && quantity <= product.stock,
|
|
1280
1403
|
extraQuantities: [bulkThreshold],
|
|
1281
1404
|
});
|
|
1405
|
+
// 买家还价低于公开价但商家没有自动折扣时,不能只回一个相同价格——
|
|
1406
|
+
// 必须明确说明“为什么没降”,否则买家会认为商家没看懂还价。
|
|
1407
|
+
const counterMinor = typeof buyerCounterMinor === "number" && Number.isFinite(buyerCounterMinor)
|
|
1408
|
+
? buyerCounterMinor
|
|
1409
|
+
: undefined;
|
|
1410
|
+
const counterBelowPublic = authorizedMinor === undefined &&
|
|
1411
|
+
counterMinor !== undefined &&
|
|
1412
|
+
counterMinor < priceMinor &&
|
|
1413
|
+
counterMinor < publicBoundMinor;
|
|
1414
|
+
const counterLanguage = replyLanguageOf(envelope.public_message, buyerMessage);
|
|
1415
|
+
const counterNote = counterBelowPublic && counterMinor !== undefined
|
|
1416
|
+
? publicBoundMinor >= priceMinor
|
|
1417
|
+
? counterLanguage === "zh"
|
|
1418
|
+
? `您的还价 ${(counterMinor / 100).toFixed(2)} ${currency} 低于本店当前公开报价 ${(priceMinor / 100).toFixed(2)} ${currency};本店未配置自动折扣,本次仍按公开价报价。如需按数量或规格重新核价,请说明。`
|
|
1419
|
+
: `Your counter of ${(counterMinor / 100).toFixed(2)} ${currency} is below the merchant's current public price of ${(priceMinor / 100).toFixed(2)} ${currency}; no automatic discount is configured, so this reply keeps the public price.`
|
|
1420
|
+
: counterLanguage === "zh"
|
|
1421
|
+
? `您的还价 ${(counterMinor / 100).toFixed(2)} ${currency} 低于本店可自动确认的折扣范围;本次按可自动确认的价格报价,更低价需商家确认。`
|
|
1422
|
+
: `Your counter of ${(counterMinor / 100).toFixed(2)} ${currency} is below the merchant's automatic discount range; this reply uses the lowest automatically confirmable price, and any lower price needs merchant confirmation.`
|
|
1423
|
+
: undefined;
|
|
1424
|
+
const quoteNote = quoteMessage(product);
|
|
1425
|
+
const counterPublicMessage = [
|
|
1426
|
+
// 库存/来源未确认时的 needs_confirmation 安全文案必须保留。
|
|
1427
|
+
quoteNote.public_message,
|
|
1428
|
+
advisedMessage,
|
|
1429
|
+
counterNote,
|
|
1430
|
+
]
|
|
1431
|
+
.filter((part) => part !== undefined && part.trim() !== "")
|
|
1432
|
+
.join(" ") || undefined;
|
|
1282
1433
|
const reply = seedEnvelope({
|
|
1283
1434
|
negotiation_id: negotiationId,
|
|
1284
1435
|
in_reply_to: inReplyTo,
|
|
@@ -1327,8 +1478,8 @@ export function createMerchantHandler(options) {
|
|
|
1327
1478
|
]
|
|
1328
1479
|
: [],
|
|
1329
1480
|
},
|
|
1330
|
-
...(
|
|
1331
|
-
? { public_message:
|
|
1481
|
+
...(counterPublicMessage !== undefined
|
|
1482
|
+
? { public_message: counterPublicMessage }
|
|
1332
1483
|
: quoteMessage(product)),
|
|
1333
1484
|
});
|
|
1334
1485
|
conditionalByNegotiation.set(negotiationId, {
|
|
@@ -1358,31 +1509,75 @@ export function createMerchantHandler(options) {
|
|
|
1358
1509
|
// 所问。这里只回答**可公开且确定**的事实;价格边界、库存精确值
|
|
1359
1510
|
// 不在这里披露(价格仍走 counter_offer 的公开折扣边界)。
|
|
1360
1511
|
const promised = deliveryBefore();
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1512
|
+
// 语言只看人类可读文本(买家摘要/原文/问题理由),不看协议字段名。
|
|
1513
|
+
const questionText = questions
|
|
1514
|
+
.map((q) => q.reason ?? "")
|
|
1515
|
+
.filter((reason) => reason.trim() !== "")
|
|
1516
|
+
.join(" ");
|
|
1517
|
+
const clarificationText = [
|
|
1518
|
+
envelope.public_message,
|
|
1519
|
+
buyerMessage,
|
|
1520
|
+
questionText,
|
|
1521
|
+
]
|
|
1522
|
+
.filter((part) => part !== undefined && part.trim() !== "")
|
|
1523
|
+
.join(" ");
|
|
1524
|
+
const language = replyLanguageOf(clarificationText);
|
|
1525
|
+
const requestedDays = requestedDeliveryDaysOf(clarificationText);
|
|
1526
|
+
const deliveryAnswer = () => {
|
|
1527
|
+
if (promised === undefined) {
|
|
1528
|
+
return requestedDays !== undefined
|
|
1529
|
+
? language === "zh"
|
|
1530
|
+
? `您要求 ${requestedDays} 天到货;本店尚未配置可承诺的交期,无法确认 ${requestedDays} 天送达,请与商家确认`
|
|
1531
|
+
: `You asked for delivery within ${requestedDays} days; this merchant has no committed lead time configured, so ${requestedDays}-day delivery cannot be confirmed`
|
|
1532
|
+
: language === "zh"
|
|
1533
|
+
? "本店尚未配置可承诺的交期,交期待确认,请与商家确认"
|
|
1534
|
+
: "delivery timing is not configured and needs confirmation with the merchant";
|
|
1535
|
+
}
|
|
1536
|
+
const promisedDay = promised.slice(0, 10);
|
|
1537
|
+
if (requestedDays === undefined) {
|
|
1538
|
+
return language === "zh"
|
|
1539
|
+
? `预计交期不晚于 ${promisedDay}`
|
|
1540
|
+
: `delivery before ${promised}`;
|
|
1541
|
+
}
|
|
1542
|
+
const canMeet = Date.parse(promised) <= Date.parse(now()) + requestedDays * 86_400_000;
|
|
1543
|
+
if (canMeet) {
|
|
1544
|
+
return language === "zh"
|
|
1545
|
+
? `您要求 ${requestedDays} 天到货;预计交期不晚于 ${promisedDay},可以满足`
|
|
1546
|
+
: `you asked for delivery within ${requestedDays} days; the estimate is by ${promised}, which meets it`;
|
|
1547
|
+
}
|
|
1548
|
+
return language === "zh"
|
|
1549
|
+
? `您要求 ${requestedDays} 天到货;预计交期不晚于 ${promisedDay},无法承诺 ${requestedDays} 天送达`
|
|
1550
|
+
: `you asked for delivery within ${requestedDays} days; the estimate is by ${promised}, so that deadline cannot be committed`;
|
|
1551
|
+
};
|
|
1552
|
+
const answerFor = (field, reason) => {
|
|
1553
|
+
const key = `${field} ${reason}`.toLowerCase();
|
|
1554
|
+
if (/delivery|eta|ship|lead.?time|交期|发货|送达|到货|几天|多少天|\d+\s*(?:天|日)|arrive/.test(key)) {
|
|
1555
|
+
return deliveryAnswer();
|
|
1367
1556
|
}
|
|
1368
1557
|
if (/stock|inventory|availability|库存|现货/.test(key)) {
|
|
1369
|
-
return
|
|
1558
|
+
return language === "zh"
|
|
1559
|
+
? "库存状态需商家确认;报价按当前可得库存计算"
|
|
1560
|
+
: "stock level needs merchant confirmation; the quote assumes currently available inventory";
|
|
1370
1561
|
}
|
|
1371
1562
|
if (/price|discount|价格|优惠|便宜/.test(key)) {
|
|
1372
|
-
return
|
|
1563
|
+
return language === "zh"
|
|
1564
|
+
? "报价按本店当前公开价执行;更大折扣需商家确认(非约束性)"
|
|
1565
|
+
: "the price follows the published quote; larger discounts need merchant confirmation (nonbinding)";
|
|
1373
1566
|
}
|
|
1374
1567
|
if (/alternative|model|sku|spec|型号|规格|替代/.test(key)) {
|
|
1375
|
-
return
|
|
1568
|
+
return language === "zh"
|
|
1569
|
+
? "只能自动报价已列出的型号;其他规格需商家确认"
|
|
1570
|
+
: "only listed models can be quoted automatically; other specifications need merchant confirmation";
|
|
1376
1571
|
}
|
|
1377
|
-
return
|
|
1378
|
-
?
|
|
1379
|
-
: "
|
|
1572
|
+
return language === "zh"
|
|
1573
|
+
? "已记录您的问题;其他条款需商家确认(非约束性)"
|
|
1574
|
+
: "your question is recorded; other terms need merchant confirmation (nonbinding)";
|
|
1380
1575
|
};
|
|
1381
1576
|
const answers = questions.map((q) => ({
|
|
1382
1577
|
field: q.field ?? "…",
|
|
1383
|
-
answer: answerFor(q.field ?? ""),
|
|
1578
|
+
answer: answerFor(q.field ?? "", q.reason ?? ""),
|
|
1384
1579
|
}));
|
|
1385
|
-
const publicMessage = Array.from(new Set(answers.map((a) => a.answer))).join("; ");
|
|
1580
|
+
const publicMessage = Array.from(new Set(answers.map((a) => a.answer))).join(language === "zh" ? ";" : "; ");
|
|
1386
1581
|
const reply = seedEnvelope({
|
|
1387
1582
|
negotiation_id: negotiationId,
|
|
1388
1583
|
in_reply_to: inReplyTo,
|
|
@@ -1393,7 +1588,7 @@ export function createMerchantHandler(options) {
|
|
|
1393
1588
|
type: "clarification_response",
|
|
1394
1589
|
answers,
|
|
1395
1590
|
},
|
|
1396
|
-
public_message: `${publicMessage}
|
|
1591
|
+
public_message: `${publicMessage}${language === "zh" ? "。" : "."}`,
|
|
1397
1592
|
});
|
|
1398
1593
|
// 出站应答即恢复(restore 边,§21.2):顶层推进已把相位挂到
|
|
1399
1594
|
// AWAITING_CLARIFICATION,clarification_response 同轮弹回
|