@tbox.cn/app-module-promotion 1.0.0-alpha.15 → 1.0.0-alpha.17
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/{chunk-2S7WUHX4.js → chunk-AVRCLENB.js} +83 -56
- package/dist/{chunk-HK4U3I7K.js → chunk-NJGYYTGM.js} +42 -5
- package/dist/client/index.js +1 -1
- package/dist/index.js +2 -2
- package/dist/server/index.d.ts +14 -8
- package/dist/server/index.js +1 -1
- package/package.json +6 -6
- package/skills/promotion/SKILL.md +9 -5
- package/src/client/cards/promotion-entitlement-list/index.tsx +46 -5
- package/src/server/cards/promotion-entitlement-list/samples.ts +3 -2
- package/src/server/handler.ts +28 -29
- package/src/server/index.ts +1 -1
- package/src/server/tools.ts +59 -27
- package/tests/cards-render.test.tsx +28 -4
- package/tests/promotion.test.ts +36 -0
|
@@ -408,6 +408,7 @@ var samples2 = [
|
|
|
408
408
|
note: "\u5F85\u4F7F\u7528\u3001\u5DF2\u4F7F\u7528\u3001\u5DF2\u8FC7\u671F\u4E09\u6001\u53CA\u52A8\u4F5C\u964D\u7EA7\u540C\u5C4F",
|
|
409
409
|
group: "\u6211\u7684\u5238",
|
|
410
410
|
data: {
|
|
411
|
+
showAlipayWallet: true,
|
|
411
412
|
items: [
|
|
412
413
|
{ entitlementRef: "ent:effective", title: "\u745E\u5E78\u5496\u5561\uFF5C30\u5143\u996E\u54C1\u4EE3\u91D1\u5238", imageUrl: IMG2.coffee, entitlementType: "COUPON", status: "EFFECTIVE", codeMasked: "**** 6688", benefitText: "\xA530", thresholdText: "\u65E0\u95E8\u69DB", usageNotice: "1F \xB7 \u5230\u5E97\u70B9\u5355\u53EF\u7528", validUntilText: "2026-09-27 \u5230\u671F" },
|
|
413
414
|
{ entitlementRef: "ent:used", title: "KKV 120\u5143\u4F18\u60E0\u5238", imageUrl: IMG2.lifestyle, entitlementType: "COUPON", status: "USED", codeMasked: "**** 1058", benefitText: "\xA5105 \xB7 8.8\u6298", usageNotice: "\u5DF2\u4E8E 2026-08-26 \u4F7F\u7528", validUntilText: "\u5DF2\u4F7F\u7528" },
|
|
@@ -424,9 +425,9 @@ var samples2 = [
|
|
|
424
425
|
},
|
|
425
426
|
{
|
|
426
427
|
label: "\u6211\u7684\u5238\xB7\u7A7A\u6001",
|
|
427
|
-
note: "\
|
|
428
|
+
note: "\u65E0\u5546\u573A\u5238\u65F6\u5728\u5361\u5934\u4E0B\u76F4\u63A5\u5C55\u793A\u901A\u680F\u5361\u5305\u5165\u53E3",
|
|
428
429
|
group: "\u6211\u7684\u5238",
|
|
429
|
-
data: { items: [],
|
|
430
|
+
data: { items: [], showAlipayWallet: true }
|
|
430
431
|
}
|
|
431
432
|
];
|
|
432
433
|
|
|
@@ -648,6 +649,21 @@ function toQueryContext(reqCtx) {
|
|
|
648
649
|
function withCards(facts, cardType, note) {
|
|
649
650
|
return { ...facts, cards: [{ cardType, data: facts, note }] };
|
|
650
651
|
}
|
|
652
|
+
function entitlementListResult(page, q) {
|
|
653
|
+
const facts = {
|
|
654
|
+
mallId: q.scope.mallId,
|
|
655
|
+
miniAppId: q.scope.miniAppId,
|
|
656
|
+
items: page.items.map(entitlementSummary),
|
|
657
|
+
...page.nextCursor ? { nextCursor: page.nextCursor } : {},
|
|
658
|
+
...page.showAlipayWallet ? { showAlipayWallet: true } : {},
|
|
659
|
+
...!page.items.length ? {
|
|
660
|
+
noResultsReason: page.showAlipayWallet ? "\u6682\u65E0\u5546\u573A\u4F18\u60E0\u5238" : "\u8FD8\u6CA1\u6709\u4F18\u60E0\u5238\uFF0C\u53EF\u8BA9\u6211\u5E2E\u4F60\u627E\u627E\u53EF\u9886\u4F18\u60E0"
|
|
661
|
+
} : {}
|
|
662
|
+
};
|
|
663
|
+
if (!facts.items.length && !page.showAlipayWallet) return { ...facts, cards: void 0 };
|
|
664
|
+
const first = facts.items[0];
|
|
665
|
+
return withCards(facts, "promotion-entitlement-list", first ? `\u6211\u7684\u4F18\u60E0\u5238 ${facts.items.length} \u5F20 \xB7 ${first.title}` : "\u6682\u65E0\u5546\u573A\u4F18\u60E0\u5238\uFF0C\u53EF\u53BB\u5361\u5305\u67E5\u770B\u795E\u5238");
|
|
666
|
+
}
|
|
651
667
|
function dateText(value) {
|
|
652
668
|
if (!value) return void 0;
|
|
653
669
|
const date = new Date(value);
|
|
@@ -871,6 +887,19 @@ var detailInput = coerce(z3.object({ offerRef: z3.string().optional(), keyword:
|
|
|
871
887
|
var activityDetailInput = coerce(
|
|
872
888
|
z3.object({ activityRef: z3.string().optional(), keyword: z3.string().optional() })
|
|
873
889
|
);
|
|
890
|
+
var needsSelection = { found: false, needsSelection: true, message: "\u8BF7\u5148\u786E\u8BA4\u5177\u4F53\u7684\u6D3B\u52A8\u6216\u4F18\u60E0\u540D\u79F0\uFF0C\u518D\u67E5\u8BE6\u60C5\u3002" };
|
|
891
|
+
function hasDetailTarget(ref, keyword) {
|
|
892
|
+
if (typeof ref === "string" && ref.trim()) return true;
|
|
893
|
+
if (typeof keyword !== "string" || !keyword.trim()) return false;
|
|
894
|
+
return !/^(?:刚才的?|上面的?|这(?:个|张|场|次)?|那(?:个|张|场|次)?|该|它)(?:活动|促销|优惠券?|券|专题|礼包)?[??。!!]*$/.test(keyword.trim());
|
|
895
|
+
}
|
|
896
|
+
function uniqueResult(page, keyword) {
|
|
897
|
+
if (!page.items.length) return null;
|
|
898
|
+
if (page.hasMore) return needsSelection;
|
|
899
|
+
if (page.items.length === 1) return page.items[0];
|
|
900
|
+
const exact = page.items.filter((item) => item.title === keyword.trim());
|
|
901
|
+
return exact.length === 1 ? exact[0] : needsSelection;
|
|
902
|
+
}
|
|
874
903
|
function createPromotionTools(opts) {
|
|
875
904
|
const delegateLinkedActivity2 = async (reqCtx) => {
|
|
876
905
|
const ctx = opts.getCtx();
|
|
@@ -887,23 +916,24 @@ function createPromotionTools(opts) {
|
|
|
887
916
|
};
|
|
888
917
|
const supportsAcquire = (service) => service.supportsAcquisition !== false;
|
|
889
918
|
const resolveOffer = async (service, q, args, offerTypes) => {
|
|
890
|
-
if (typeof args.offerRef === "string" && args.offerRef) {
|
|
919
|
+
if (typeof args.offerRef === "string" && args.offerRef.trim()) {
|
|
891
920
|
return service.getOfferDetail(q, { offerRef: args.offerRef });
|
|
892
921
|
}
|
|
893
922
|
const page = await service.searchOffers(q, {
|
|
894
923
|
keyword: args.keyword,
|
|
895
924
|
offerTypes,
|
|
896
|
-
limit:
|
|
925
|
+
limit: 2
|
|
897
926
|
});
|
|
898
|
-
return page.
|
|
927
|
+
return uniqueResult(page, String(args.keyword));
|
|
899
928
|
};
|
|
900
929
|
const resolveActivity = async (service, q, args) => {
|
|
901
930
|
if (typeof args.activityRef === "string" && args.activityRef) {
|
|
902
931
|
return service.getActivityDetail(q, args.activityRef);
|
|
903
932
|
}
|
|
904
|
-
const page = await service.listActivities(q, { keyword: args.keyword, limit:
|
|
905
|
-
const
|
|
906
|
-
|
|
933
|
+
const page = await service.listActivities(q, { keyword: args.keyword, limit: 2 });
|
|
934
|
+
const selected = uniqueResult(page, String(args.keyword));
|
|
935
|
+
if (!selected || "needsSelection" in selected) return selected;
|
|
936
|
+
return service.getActivityDetail(q, selected.activityRef);
|
|
907
937
|
};
|
|
908
938
|
const search = (service, q, args, offerTypes) => service.searchOffers(q, {
|
|
909
939
|
keyword: args.keyword,
|
|
@@ -912,7 +942,7 @@ function createPromotionTools(opts) {
|
|
|
912
942
|
limit: args.limit ? Number(args.limit) : 50,
|
|
913
943
|
offerTypes
|
|
914
944
|
});
|
|
915
|
-
const
|
|
945
|
+
const listOwnedCoupons = async (service, q, args, reqCtx) => {
|
|
916
946
|
const ctx = opts.getCtx();
|
|
917
947
|
const factory = ctx.services?.resolve?.("member.status");
|
|
918
948
|
const gate = reqCtx ? await resolveMemberGate(factory, reqCtx) : void 0;
|
|
@@ -928,13 +958,7 @@ function createPromotionTools(opts) {
|
|
|
928
958
|
cursor: args.cursor,
|
|
929
959
|
limit: args.limit ? Number(args.limit) : 50
|
|
930
960
|
});
|
|
931
|
-
return
|
|
932
|
-
mallId: q.scope.mallId,
|
|
933
|
-
miniAppId: q.scope.miniAppId,
|
|
934
|
-
items: page.items.map(entitlementSummary),
|
|
935
|
-
...page.nextCursor ? { nextCursor: page.nextCursor } : {},
|
|
936
|
-
...page.items.length === 0 ? { noResultsReason: "\u8FD8\u6CA1\u6709\u4F18\u60E0\u5238\uFF0C\u53EF\u8BA9\u6211\u5E2E\u4F60\u627E\u627E\u53EF\u9886\u4F18\u60E0" } : {}
|
|
937
|
-
};
|
|
961
|
+
return entitlementListResult(page, q);
|
|
938
962
|
};
|
|
939
963
|
const listActivityCategories = createTool2({
|
|
940
964
|
id: "listActivityCategories",
|
|
@@ -1010,12 +1034,14 @@ function createPromotionTools(opts) {
|
|
|
1010
1034
|
description: "\u67E5\u8BE2\u6307\u5B9A\u6D3B\u52A8\u8BE6\u60C5\u3001\u65F6\u95F4\u3001\u540D\u989D\u548C\u53C2\u4E0E\u6761\u4EF6\u3002",
|
|
1011
1035
|
inputSchema: activityDetailInput,
|
|
1012
1036
|
execute: async (args, execCtx) => {
|
|
1037
|
+
if (!hasDetailTarget(args.activityRef, args.keyword)) return needsSelection;
|
|
1013
1038
|
const reqCtx = requireToolRequestContext2(execCtx, "getActivityDetail");
|
|
1014
1039
|
const delegated = await delegateLinkedActivity2(reqCtx);
|
|
1015
1040
|
if (delegated) return delegated;
|
|
1016
1041
|
const { service, q } = await requireService(execCtx, resolvePromotionActivitiesPort);
|
|
1017
1042
|
const detail = await resolveActivity(service, q, args);
|
|
1018
1043
|
if (!detail) return { found: false, message: "\u672A\u627E\u5230\u8BE5\u6D3B\u52A8" };
|
|
1044
|
+
if ("needsSelection" in detail) return detail;
|
|
1019
1045
|
const facts = { found: true, ...activityDetail(detail, "detail") };
|
|
1020
1046
|
return withCards(facts, "promotion-activity-detail", `\u6D3B\u52A8\u8BE6\u60C5\uFF1A${detail.title}`);
|
|
1021
1047
|
}
|
|
@@ -1025,12 +1051,14 @@ function createPromotionTools(opts) {
|
|
|
1025
1051
|
description: "\u67E5\u8BE2\u6307\u5B9A\u6D3B\u52A8\u7684\u53EF\u9009\u573A\u6B21\uFF0C\u53EA\u8FD4\u56DE\u53EA\u8BFB\u72B6\u6001\uFF0C\u4E0D\u6267\u884C\u62A5\u540D\u3002",
|
|
1026
1052
|
inputSchema: activityDetailInput,
|
|
1027
1053
|
execute: async (args, execCtx) => {
|
|
1054
|
+
if (!hasDetailTarget(args.activityRef, args.keyword)) return needsSelection;
|
|
1028
1055
|
const reqCtx = requireToolRequestContext2(execCtx, "listActivitySessions");
|
|
1029
1056
|
const delegated = await delegateLinkedActivity2(reqCtx);
|
|
1030
1057
|
if (delegated) return delegated;
|
|
1031
1058
|
const { service, q } = await requireService(execCtx, resolvePromotionActivitiesPort);
|
|
1032
1059
|
const detail = await resolveActivity(service, q, args);
|
|
1033
1060
|
if (!detail) return { found: false, message: "\u672A\u627E\u5230\u8BE5\u6D3B\u52A8" };
|
|
1061
|
+
if ("needsSelection" in detail) return detail;
|
|
1034
1062
|
const sessions = service.listActivitySessions ? await service.listActivitySessions(q, detail.activityRef) : detail.sessions;
|
|
1035
1063
|
const facts = activityDetail({ ...detail, sessions }, "schedule");
|
|
1036
1064
|
return withCards(facts, "promotion-activity-detail", `\u6D3B\u52A8\u573A\u6B21\uFF1A${detail.title}`);
|
|
@@ -1041,12 +1069,14 @@ function createPromotionTools(opts) {
|
|
|
1041
1069
|
description: "\u67E5\u8BE2\u6307\u5B9A\u6D3B\u52A8\u7684\u62A5\u540D\u6761\u4EF6\u548C\u53C2\u4E0E\u6B65\u9AA4\uFF0C\u4E0D\u6267\u884C\u62A5\u540D\u3002",
|
|
1042
1070
|
inputSchema: activityDetailInput,
|
|
1043
1071
|
execute: async (args, execCtx) => {
|
|
1072
|
+
if (!hasDetailTarget(args.activityRef, args.keyword)) return needsSelection;
|
|
1044
1073
|
const reqCtx = requireToolRequestContext2(execCtx, "getActivityGuide");
|
|
1045
1074
|
const delegated = await delegateLinkedActivity2(reqCtx);
|
|
1046
1075
|
if (delegated) return delegated;
|
|
1047
1076
|
const { service, q } = await requireService(execCtx, resolvePromotionActivitiesPort);
|
|
1048
1077
|
const detail = await resolveActivity(service, q, args);
|
|
1049
1078
|
if (!detail) return { found: false, message: "\u672A\u627E\u5230\u8BE5\u6D3B\u52A8" };
|
|
1079
|
+
if ("needsSelection" in detail) return detail;
|
|
1050
1080
|
const facts = activityDetail(detail, "guide");
|
|
1051
1081
|
return withCards(facts, "promotion-activity-detail", `\u6D3B\u52A8\u53C2\u4E0E\u65B9\u5F0F\uFF1A${detail.title}`);
|
|
1052
1082
|
}
|
|
@@ -1075,6 +1105,7 @@ function createPromotionTools(opts) {
|
|
|
1075
1105
|
z3.object({ offerRef: z3.string().optional(), entitlementRef: z3.string().optional(), keyword: z3.string().optional() })
|
|
1076
1106
|
),
|
|
1077
1107
|
execute: async (args, execCtx) => {
|
|
1108
|
+
if (!args.entitlementRef && !hasDetailTarget(args.offerRef, args.keyword)) return needsSelection;
|
|
1078
1109
|
const { service, q, reqCtx } = await requireService(execCtx, resolvePromotionOffersPort);
|
|
1079
1110
|
if (typeof args.entitlementRef === "string" && args.entitlementRef) {
|
|
1080
1111
|
const ctx = opts.getCtx();
|
|
@@ -1103,12 +1134,7 @@ function createPromotionTools(opts) {
|
|
|
1103
1134
|
inputSchema: searchInput,
|
|
1104
1135
|
execute: async (args, execCtx) => {
|
|
1105
1136
|
const { service, q, reqCtx } = await requireService(execCtx, resolvePromotionEntitlementsPort);
|
|
1106
|
-
|
|
1107
|
-
return facts.items.length ? withCards(
|
|
1108
|
-
facts,
|
|
1109
|
-
"promotion-entitlement-list",
|
|
1110
|
-
`\u6211\u7684\u4F18\u60E0\u5238 ${facts.items.length} \u5F20${facts.items[0] ? ` \xB7 ${facts.items[0].title}` : ""}`
|
|
1111
|
-
) : facts;
|
|
1137
|
+
return listOwnedCoupons(service, q, args, reqCtx);
|
|
1112
1138
|
}
|
|
1113
1139
|
});
|
|
1114
1140
|
const listPromotions = createTool2({
|
|
@@ -1134,9 +1160,11 @@ function createPromotionTools(opts) {
|
|
|
1134
1160
|
description: "\u6309\u8425\u9500\u4E13\u9898\u6807\u8BC6\u6216\u5173\u952E\u8BCD\u7CBE\u786E\u67E5\u8BE2\u6D3B\u52A8\u8BE6\u60C5\u3002",
|
|
1135
1161
|
inputSchema: detailInput,
|
|
1136
1162
|
execute: async (args, execCtx) => {
|
|
1163
|
+
if (!hasDetailTarget(args.offerRef, args.keyword)) return needsSelection;
|
|
1137
1164
|
const { service, q } = await requireService(execCtx, resolvePromotionOffersPort);
|
|
1138
1165
|
const offer = await resolveOffer(service, q, args, ["PROMOTION"]);
|
|
1139
1166
|
if (!offer) return { found: false, message: "\u672A\u627E\u5230\u8BE5\u8425\u9500\u4E13\u9898" };
|
|
1167
|
+
if ("needsSelection" in offer) return offer;
|
|
1140
1168
|
const facts = { found: true, ...offerDetail(offer, false, "promotion") };
|
|
1141
1169
|
return withCards(facts, "promotion-offer-detail", `\u8425\u9500\u6D3B\u52A8\u8BE6\u60C5\uFF1A${offer.title}`);
|
|
1142
1170
|
}
|
|
@@ -1146,16 +1174,18 @@ function createPromotionTools(opts) {
|
|
|
1146
1174
|
description: "\u67E5\u8BE2\u8425\u9500\u4E13\u9898\u7684\u5382\u5546\u53C2\u4E0E\u6B65\u9AA4\uFF0C\u4E0D\u6267\u884C\u62A5\u540D\u6216\u9886\u53D6\u3002",
|
|
1147
1175
|
inputSchema: detailInput,
|
|
1148
1176
|
execute: async (args, execCtx) => {
|
|
1177
|
+
if (!hasDetailTarget(args.offerRef, args.keyword)) return needsSelection;
|
|
1149
1178
|
const { service, q } = await requireService(execCtx, resolvePromotionOffersPort);
|
|
1150
1179
|
const offer = await resolveOffer(service, q, args, ["PROMOTION"]);
|
|
1151
1180
|
if (!offer) return { found: false, message: "\u672A\u627E\u5230\u8BE5\u8425\u9500\u4E13\u9898" };
|
|
1181
|
+
if ("needsSelection" in offer) return offer;
|
|
1152
1182
|
const facts = { found: true, ...offerDetail(offer, false, "promotion-guide") };
|
|
1153
1183
|
return withCards(facts, "promotion-offer-detail", `\u53C2\u4E0E\u65B9\u5F0F\uFF1A${offer.title}`);
|
|
1154
1184
|
}
|
|
1155
1185
|
});
|
|
1156
1186
|
const listCoupons = createTool2({
|
|
1157
1187
|
id: "listCoupons",
|
|
1158
|
-
description: "\u67E5\u8BE2\u4F18\u60E0\u5238\u5217\u8868\u3002\u9ED8\u8BA4\u53EA\u67E5\u8BE2\u5F53\u524D\u53EF\u9886\u53D6\u4F18\u60E0\u5238\uFF08CLAIMABLE\uFF09\uFF1B\u53EA\u6709\u7528\u6237\u660E\u786E\u8BF4\u201C\u6211\u7684\u5238/\u5DF2\u9886\u53D6/\u5238\u5305\u201D\u65F6\u624D\u4F20 mode=OWNED\u3002mode=OWNED \u5DF2\u767B\u5F55\u672A\u5165\u4F1A\u65F6\u8FD4\u56DE\u5165\u4F1A\u5F15\u5BFC\u5361\uFF08member-enrollment-cta\uFF09\uFF0C\u65E0\u9700\u518D\u8C03 member \u57DF queryEnrollmentCta\u3002",
|
|
1188
|
+
description: "\u67E5\u8BE2\u4F18\u60E0\u5238\u5217\u8868\u3002\u9ED8\u8BA4\u53EA\u67E5\u8BE2\u5F53\u524D\u53EF\u9886\u53D6\u4F18\u60E0\u5238\uFF08CLAIMABLE\uFF09\uFF1B\u53EA\u6709\u7528\u6237\u660E\u786E\u8BF4\u201C\u6211\u6709\u4EC0\u4E48\u5361\u5238/\u6211\u7684\u5238/\u5DF2\u9886\u53D6/\u5238\u5305\u201D\u65F6\u624D\u4F20 mode=OWNED\u3002mode=OWNED \u5DF2\u767B\u5F55\u672A\u5165\u4F1A\u65F6\u8FD4\u56DE\u5165\u4F1A\u5F15\u5BFC\u5361\uFF08member-enrollment-cta\uFF09\uFF0C\u65E0\u9700\u518D\u8C03 member \u57DF queryEnrollmentCta\u3002",
|
|
1159
1189
|
inputSchema: coerce(
|
|
1160
1190
|
z3.object({
|
|
1161
1191
|
mode: z3.enum(["CLAIMABLE", "OWNED"]).default("CLAIMABLE"),
|
|
@@ -1167,8 +1197,7 @@ function createPromotionTools(opts) {
|
|
|
1167
1197
|
execute: async (args, execCtx) => {
|
|
1168
1198
|
if (args.mode === "OWNED") {
|
|
1169
1199
|
const { service: service2, q: q2, reqCtx: reqCtx2 } = await requireService(execCtx, resolvePromotionEntitlementsPort);
|
|
1170
|
-
|
|
1171
|
-
return facts2.items.length ? withCards(facts2, "promotion-entitlement-list", `\u6211\u7684\u4F18\u60E0\u5238 ${facts2.items.length} \u5F20${facts2.items[0] ? ` \xB7 ${facts2.items[0].title ?? ""}` : ""}`) : facts2;
|
|
1200
|
+
return listOwnedCoupons(service2, q2, args, reqCtx2);
|
|
1172
1201
|
}
|
|
1173
1202
|
const { service, q, reqCtx } = await requireService(execCtx, resolvePromotionOffersPort);
|
|
1174
1203
|
const [page, dealRecall] = await Promise.all([
|
|
@@ -1193,9 +1222,11 @@ function createPromotionTools(opts) {
|
|
|
1193
1222
|
description: "\u67E5\u8BE2\u7EC4\u5408\u793C\u5305\u53CA\u5176\u5B50\u6743\u76CA\u3002",
|
|
1194
1223
|
inputSchema: detailInput,
|
|
1195
1224
|
execute: async (args, execCtx) => {
|
|
1225
|
+
if (!hasDetailTarget(args.offerRef, args.keyword)) return needsSelection;
|
|
1196
1226
|
const { service, q } = await requireService(execCtx, resolvePromotionOffersPort);
|
|
1197
1227
|
const offer = await resolveOffer(service, q, args, ["BUNDLE"]);
|
|
1198
1228
|
if (!offer) return { found: false, message: "\u672A\u627E\u5230\u8BE5\u4F18\u60E0\u793C\u5305" };
|
|
1229
|
+
if ("needsSelection" in offer) return offer;
|
|
1199
1230
|
const facts = {
|
|
1200
1231
|
found: true,
|
|
1201
1232
|
...offerDetail(offer, supportsAcquire(service), "package")
|
|
@@ -1442,7 +1473,7 @@ import { matchIntent } from "@tbox.cn/app-agent-sdk-server";
|
|
|
1442
1473
|
import { resolveMemberGate as resolveMemberGate2, toMallQueryContext as toMallQueryContext3 } from "@tbox.cn/app-contracts-mall";
|
|
1443
1474
|
var PROMOTION_INTENTS = {
|
|
1444
1475
|
"list-entitlements": {
|
|
1445
|
-
patterns: ["\u6211\u7684\u4F18\u60E0\u5238", "\u6211\u7684\u5238\u5305", "\u6211\u7684\u5238", "\u5DF2\u9886\u53D6\u7684\u5238", "\u5DF2\u9886\u4F18\u60E0\u5238", "\u6301\u6709\u7684\u4F18\u60E0\u5238"],
|
|
1476
|
+
patterns: ["\u6211\u6709\u4EC0\u4E48\u5361\u5238", "\u6211\u6709\u54EA\u4E9B\u5361\u5238", "\u6211\u7684\u5361\u5238", "\u6211\u6709\u54EA\u4E9B\u5238", "\u6211\u6709\u4EC0\u4E48\u4F18\u60E0\u5238", "\u6211\u7684\u4F18\u60E0\u5238", "\u6211\u7684\u5238\u5305", "\u6211\u7684\u5238", "\u5DF2\u9886\u53D6\u7684\u5238", "\u5DF2\u9886\u4F18\u60E0\u5238", "\u6301\u6709\u7684\u4F18\u60E0\u5238"],
|
|
1446
1477
|
description: "\u67E5\u8BE2\u5F53\u524D\u4F1A\u5458\u5DF2\u62E5\u6709\u7684\u4F18\u60E0\u5238"
|
|
1447
1478
|
},
|
|
1448
1479
|
"search-offers": {
|
|
@@ -1474,7 +1505,7 @@ var PROMOTION_RESOLVE_ROUTES = [
|
|
|
1474
1505
|
action: "list-activities"
|
|
1475
1506
|
}
|
|
1476
1507
|
];
|
|
1477
|
-
var OWNED_INTENT_HINTS = ["\u6211\u7684\u4F18\u60E0\u5238", "\u6211\u7684\u5238\u5305", "\u6211\u7684\u5238", "\u5DF2\u9886\u53D6", "\u5DF2\u9886\u4F18\u60E0\u5238", "\u6301\u6709\u7684\u4F18\u60E0\u5238"];
|
|
1508
|
+
var OWNED_INTENT_HINTS = ["\u6211\u7684\u5361\u5238", "\u6211\u7684\u4F18\u60E0\u5238", "\u6211\u7684\u5238\u5305", "\u6211\u7684\u5238", "\u5DF2\u9886\u53D6", "\u5DF2\u9886\u4F18\u60E0\u5238", "\u6301\u6709\u7684\u4F18\u60E0\u5238"];
|
|
1478
1509
|
var CLAIMABLE_INTENT_HINTS = ["\u6709\u4EC0\u4E48\u4F18\u60E0", "\u53EF\u9886\u53D6", "\u53EF\u9886", "\u9886\u53D6\u4F18\u60E0\u5238", "\u9886\u5238"];
|
|
1479
1510
|
function intentContent(payload) {
|
|
1480
1511
|
if (typeof payload === "string") return payload;
|
|
@@ -1489,6 +1520,10 @@ function resolveIntent(payload) {
|
|
|
1489
1520
|
const navigation = parsePromotionNavigationQuery(content);
|
|
1490
1521
|
if (navigation) return navigation;
|
|
1491
1522
|
if (content.startsWith(NAVIGATION_SENTENCE_PREFIX)) return null;
|
|
1523
|
+
const phrase = content.trim().replace(/[??!!。]+$/u, "");
|
|
1524
|
+
if (PROMOTION_INTENTS["list-entitlements"].patterns.some((pattern) => pattern === phrase)) {
|
|
1525
|
+
return { kind: "list-entitlements" };
|
|
1526
|
+
}
|
|
1492
1527
|
const owned = OWNED_INTENT_HINTS.some((hint) => content.includes(hint));
|
|
1493
1528
|
const claimable = CLAIMABLE_INTENT_HINTS.some((hint) => content.includes(hint));
|
|
1494
1529
|
if (claimable && !owned) return { kind: "search-coupons" };
|
|
@@ -1692,36 +1727,28 @@ function createPromotionIntentHandler(ctx, { legacyActivities = true } = {}) {
|
|
|
1692
1727
|
if (gate) return { cards: gate.card ? [gate.card] : [], text: gate.notice };
|
|
1693
1728
|
const service = await resolvePromotionEntitlementsPort(reqCtx, ctx);
|
|
1694
1729
|
const page = await service.listEntitlements(q, { limit: 50 });
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
return {
|
|
1701
|
-
cards: [{ cardType: "promotion-offer-list", data: {
|
|
1702
|
-
presentation: "coupon",
|
|
1703
|
-
mode: "claimable",
|
|
1704
|
-
items: items.map(offerSummary)
|
|
1705
|
-
} }],
|
|
1706
|
-
text: `\u4F60\u7684\u5238\u5305\u91CC\u8FD8\u6CA1\u6709\u4F18\u60E0\u5238\uFF0C\u4E3A\u4F60\u627E\u5230 ${items.length} \u6761\u53EF\u9886\u4F18\u60E0`
|
|
1707
|
-
};
|
|
1730
|
+
const result = entitlementListResult(page, q);
|
|
1731
|
+
if (result.cards) {
|
|
1732
|
+
let text = `\u4F60\u7684\u5238\u5305\u91CC\u6709 ${page.items.length} \u5F20\u4F18\u60E0\u5238`;
|
|
1733
|
+
if (page.showAlipayWallet) {
|
|
1734
|
+
text = page.items.length ? `\u67E5\u5230 ${page.items.length} \u5F20\u5546\u573A\u4F18\u60E0\u5238\uFF0C\u795E\u5238\u53EF\u5230\u652F\u4ED8\u5B9D\u5361\u5305\u67E5\u770B\u3002` : "\u6682\u65E0\u5546\u573A\u4F18\u60E0\u5238\uFF0C\u4F60\u53EF\u4EE5\u53BB\u652F\u4ED8\u5B9D\u5361\u5305\u67E5\u770B\u795E\u5238\u3002";
|
|
1708
1735
|
}
|
|
1709
|
-
return { cards:
|
|
1736
|
+
return { cards: result.cards, text };
|
|
1710
1737
|
}
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
}
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
};
|
|
1738
|
+
const offersService = await resolvePromotionOffersPort(reqCtx, ctx);
|
|
1739
|
+
const offers = await offersService.searchOffers(q, { offerTypes: ["COUPON"], limit: 50 });
|
|
1740
|
+
const items = offers.items.filter((item) => item.availability.status === "AVAILABLE");
|
|
1741
|
+
if (items.length > 0) {
|
|
1742
|
+
return {
|
|
1743
|
+
cards: [{ cardType: "promotion-offer-list", data: {
|
|
1744
|
+
presentation: "coupon",
|
|
1745
|
+
mode: "claimable",
|
|
1746
|
+
items: items.map(offerSummary)
|
|
1747
|
+
} }],
|
|
1748
|
+
text: `\u4F60\u7684\u5238\u5305\u91CC\u8FD8\u6CA1\u6709\u4F18\u60E0\u5238\uFF0C\u4E3A\u4F60\u627E\u5230 ${items.length} \u6761\u53EF\u9886\u4F18\u60E0`
|
|
1749
|
+
};
|
|
1750
|
+
}
|
|
1751
|
+
return { cards: [], text: "\u4F60\u7684\u5238\u5305\u91CC\u8FD8\u6CA1\u6709\u4F18\u60E0\u5238\uFF0C\u5F53\u524D\u4E5F\u6CA1\u6709\u53EF\u9886\u53D6\u4F18\u60E0" };
|
|
1725
1752
|
}
|
|
1726
1753
|
case "list-activities": {
|
|
1727
1754
|
const delegated = await delegateLinkedActivity(ctx, payload, reqCtx);
|
|
@@ -1783,7 +1810,7 @@ var tools = {
|
|
|
1783
1810
|
};
|
|
1784
1811
|
var dealRecallTools = createDealRecallTools(getCtx);
|
|
1785
1812
|
var excludedDealIdsSchema = z5.array(z5.string().min(1).max(128)).default([]);
|
|
1786
|
-
var OWNED_INTENT_RE =
|
|
1813
|
+
var OWNED_INTENT_RE = /我的(?:优惠券|卡券|券)|已领|券包|券码|^我(?:有什么|有哪些)(?:优惠券|卡券|券)[??!!。]*$/u;
|
|
1787
1814
|
var EXTERNAL_DEAL_INTENT_RE = /支付宝神券|外部团购/;
|
|
1788
1815
|
var listCouponsPreTool = definePreTool(tools.listCoupons, {
|
|
1789
1816
|
routing: { mode: "keywords", terms: ["\u4F18\u60E0\u5238", "\u9886\u5238", "\u6709\u4EC0\u4E48\u5238", "\u53EF\u9886"] },
|
|
@@ -961,9 +961,9 @@ var promotion_offer_detail_default = PromotionOfferDetailCard;
|
|
|
961
961
|
markSelfRendering2(PromotionOfferDetailCard);
|
|
962
962
|
|
|
963
963
|
// src/client/cards/promotion-entitlement-list/index.tsx
|
|
964
|
-
import { CalendarBlank as CalendarBlank3, CaretDown as CaretDown3, Copy, MapPinLine, NavigationArrow, ShieldCheck, Ticket as Ticket4 } from "@phosphor-icons/react";
|
|
964
|
+
import { CalendarBlank as CalendarBlank3, CaretDown as CaretDown3, CaretRight, Copy, MapPinLine, NavigationArrow, ShieldCheck, Ticket as Ticket4, Wallet } from "@phosphor-icons/react";
|
|
965
965
|
import { useEffect as useEffect5, useRef as useRef5, useState as useState8 } from "react";
|
|
966
|
-
import { callJsapi, httpGet } from "@tbox.cn/app-agent-sdk-client";
|
|
966
|
+
import { callJsapi, httpGet, isInAlipayShell } from "@tbox.cn/app-agent-sdk-client";
|
|
967
967
|
|
|
968
968
|
// src/client/components/CouponQrCode.tsx
|
|
969
969
|
import QRCode from "qrcode";
|
|
@@ -1016,6 +1016,41 @@ function CouponBarcode(props) {
|
|
|
1016
1016
|
|
|
1017
1017
|
// src/client/cards/promotion-entitlement-list/index.tsx
|
|
1018
1018
|
import { Fragment as Fragment4, jsx as jsx10, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
1019
|
+
var ALIPAY_WALLET_APP_ID = "20000021";
|
|
1020
|
+
var ALIPAY_WALLET_QUERY = "tabPage=voucher";
|
|
1021
|
+
var ALIPAY_WALLET_URL = `alipays://platformapi/startapp?appId=${ALIPAY_WALLET_APP_ID}&${ALIPAY_WALLET_QUERY}`;
|
|
1022
|
+
function AlipayWalletLink() {
|
|
1023
|
+
const [failed, setFailed] = useState8(false);
|
|
1024
|
+
return /* @__PURE__ */ jsxs8("footer", { className: "px-3.5 py-3", children: [
|
|
1025
|
+
/* @__PURE__ */ jsxs8(
|
|
1026
|
+
"a",
|
|
1027
|
+
{
|
|
1028
|
+
href: ALIPAY_WALLET_URL,
|
|
1029
|
+
className: "flex min-h-12 w-full items-center justify-center gap-2 rounded-xl bg-[#edf3e7] px-4 py-3 text-sm font-semibold leading-5 text-[#355638] no-underline hover:brightness-[0.97] active:brightness-95 focus-visible:outline-2 focus-visible:outline-offset-[-3px]",
|
|
1030
|
+
onClick: async (event) => {
|
|
1031
|
+
if (!isInAlipayShell()) return;
|
|
1032
|
+
event.preventDefault();
|
|
1033
|
+
setFailed(false);
|
|
1034
|
+
try {
|
|
1035
|
+
await callJsapi("navigateToMiniProgram", { appId: ALIPAY_WALLET_APP_ID, query: ALIPAY_WALLET_QUERY });
|
|
1036
|
+
} catch {
|
|
1037
|
+
try {
|
|
1038
|
+
await callJsapi("ap.openURL", { url: ALIPAY_WALLET_URL });
|
|
1039
|
+
} catch {
|
|
1040
|
+
setFailed(true);
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
},
|
|
1044
|
+
children: [
|
|
1045
|
+
/* @__PURE__ */ jsx10(Wallet, { size: 18, weight: "duotone", "aria-hidden": "true" }),
|
|
1046
|
+
"\u53BB\u5361\u5305\u67E5\u770B\u795E\u5238",
|
|
1047
|
+
/* @__PURE__ */ jsx10(CaretRight, { size: 14, weight: "bold", "aria-hidden": "true" })
|
|
1048
|
+
]
|
|
1049
|
+
}
|
|
1050
|
+
),
|
|
1051
|
+
failed && /* @__PURE__ */ jsx10("p", { role: "status", className: "px-4 py-2 text-xs text-secondary-foreground", children: "\u6682\u65F6\u65E0\u6CD5\u6253\u5F00\uFF0C\u8BF7\u5728\u652F\u4ED8\u5B9D\u9996\u9875\u8FDB\u5165\u300C\u5361\u5305\u300D\u3002" })
|
|
1052
|
+
] });
|
|
1053
|
+
}
|
|
1019
1054
|
function PromotionEntitlementListCard(props) {
|
|
1020
1055
|
const { data, isHistory = false } = props;
|
|
1021
1056
|
const [openRef, setOpenRef] = useState8(null);
|
|
@@ -1068,12 +1103,13 @@ function PromotionEntitlementListCard(props) {
|
|
|
1068
1103
|
/* @__PURE__ */ jsx10(Ticket4, { weight: "fill" }),
|
|
1069
1104
|
/* @__PURE__ */ jsx10("h3", { className: "text-base font-bold leading-[21px] text-[#2f3a22] [overflow-wrap:anywhere]", children: "\u6211\u7684\u4F18\u60E0\u5238" })
|
|
1070
1105
|
] }),
|
|
1071
|
-
/* @__PURE__ */ jsx10("p", { className: "mt-1 text-xs leading-4 text-[#626b5c]", children: "\u5F53\u524D\u8D26\u6237 \xB7 \u5238\u5305\u6743\u76CA" })
|
|
1106
|
+
/* @__PURE__ */ jsx10("p", { className: "mt-1 text-xs leading-4 text-[#626b5c]", children: data.showAlipayWallet ? "\u6211\u7684\u5546\u573A\u5238" : "\u5F53\u524D\u8D26\u6237 \xB7 \u5238\u5305\u6743\u76CA" })
|
|
1072
1107
|
] }) }),
|
|
1073
|
-
!data.items.length
|
|
1108
|
+
!data.items.length && !data.showAlipayWallet && /* @__PURE__ */ jsxs8("div", { className: "promotion-card__empty flex min-h-[94px] items-center justify-center gap-2 p-5 text-xs leading-[normal] text-secondary-foreground", children: [
|
|
1074
1109
|
/* @__PURE__ */ jsx10(Ticket4, { size: 28, weight: "duotone" }),
|
|
1075
1110
|
/* @__PURE__ */ jsx10("span", { children: data.noResultsReason ?? "\u5F53\u524D\u8D26\u6237\u6682\u65E0\u53EF\u7528\u6743\u76CA" })
|
|
1076
|
-
] })
|
|
1111
|
+
] }),
|
|
1112
|
+
data.items.length > 0 && /* @__PURE__ */ jsx10("div", { ref: listRef, className: `promotion-list__items overflow-hidden px-3.5 ${data.showAlipayWallet && data.items.length <= maxItems ? "[&+footer]:pt-0.5" : "pb-1"} ${expanded ? " promotion-list__items--expanded transition-none" : " transition-[max-height] duration-[320ms] ease-[ease]"}`, style: { maxHeight }, onTransitionEnd, children: visibleItems.map((item) => /* @__PURE__ */ jsxs8(
|
|
1077
1113
|
"article",
|
|
1078
1114
|
{
|
|
1079
1115
|
className: `promotion-coupon-row relative grid min-h-[77px] w-full cursor-pointer grid-cols-[56px_minmax(0,1fr)_auto] items-center gap-x-2 gap-y-0 overflow-hidden border-t border-[#f0f1f4] py-[9px] text-left text-inherit first:border-t-0 focus-visible:rounded-[6px] focus-visible:outline-2 focus-visible:outline-offset-[-2px] focus-visible:outline-[#2368ec] ${item.status === "EFFECTIVE" ? "" : " promotion-coupon-row--disabled opacity-72"}`,
|
|
@@ -1122,6 +1158,7 @@ function PromotionEntitlementListCard(props) {
|
|
|
1122
1158
|
]
|
|
1123
1159
|
}
|
|
1124
1160
|
),
|
|
1161
|
+
data.showAlipayWallet && /* @__PURE__ */ jsx10(AlipayWalletLink, {}),
|
|
1125
1162
|
data.items.length > maxItems && /* @__PURE__ */ jsx10("div", { ref: bottomRef, className: "promotion-list__bottom-anchor h-0 flex-none scroll-mb-[max(96px,calc(var(--tbox-chat-bottom-height,0px)_+_24px))]", "aria-hidden": "true" }),
|
|
1126
1163
|
sheetTarget && (() => {
|
|
1127
1164
|
const facts = [
|
package/dist/client/index.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -7,11 +7,11 @@ import {
|
|
|
7
7
|
resolvePromotionEntitlementsPort,
|
|
8
8
|
resolvePromotionOffersPort,
|
|
9
9
|
serverModule
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-AVRCLENB.js";
|
|
11
11
|
import {
|
|
12
12
|
cards,
|
|
13
13
|
clientModule
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-NJGYYTGM.js";
|
|
15
15
|
export {
|
|
16
16
|
InMemoryPromotionService,
|
|
17
17
|
clientModule,
|
package/dist/server/index.d.ts
CHANGED
|
@@ -373,8 +373,8 @@ declare const promotionCards: {
|
|
|
373
373
|
title: string;
|
|
374
374
|
description?: string | undefined;
|
|
375
375
|
}[] | undefined;
|
|
376
|
-
subtitle?: string | undefined;
|
|
377
376
|
presentation?: "package" | "coupon" | "promotion" | "offer" | "promotion-guide" | undefined;
|
|
377
|
+
subtitle?: string | undefined;
|
|
378
378
|
imageUrl?: string | undefined;
|
|
379
379
|
usageRuleText?: string | undefined;
|
|
380
380
|
usageTimeText?: string | undefined;
|
|
@@ -418,8 +418,8 @@ declare const promotionCards: {
|
|
|
418
418
|
title: string;
|
|
419
419
|
description?: string | undefined;
|
|
420
420
|
}[] | undefined;
|
|
421
|
-
subtitle?: string | undefined;
|
|
422
421
|
presentation?: "package" | "coupon" | "promotion" | "offer" | "promotion-guide" | undefined;
|
|
422
|
+
subtitle?: string | undefined;
|
|
423
423
|
imageUrl?: string | undefined;
|
|
424
424
|
usageRuleText?: string | undefined;
|
|
425
425
|
usageTimeText?: string | undefined;
|
|
@@ -452,6 +452,7 @@ declare const promotionCards: {
|
|
|
452
452
|
unavailableReason?: string | undefined;
|
|
453
453
|
}>>;
|
|
454
454
|
readonly 'promotion-entitlement-list': _tbox_cn_app_contracts.CardMeta<zod.ZodObject<{
|
|
455
|
+
showAlipayWallet: zod.ZodOptional<zod.ZodBoolean>;
|
|
455
456
|
mallId: zod.ZodOptional<zod.ZodString>;
|
|
456
457
|
miniAppId: zod.ZodOptional<zod.ZodString>;
|
|
457
458
|
maxItems: zod.ZodOptional<zod.ZodNumber>;
|
|
@@ -657,6 +658,7 @@ declare const promotionCards: {
|
|
|
657
658
|
noResultsReason?: string | undefined;
|
|
658
659
|
maxItems?: number | undefined;
|
|
659
660
|
nextCursor?: string | undefined;
|
|
661
|
+
showAlipayWallet?: boolean | undefined;
|
|
660
662
|
}, {
|
|
661
663
|
items: {
|
|
662
664
|
status: "UNKNOWN" | "USED" | "EXPIRED" | "EFFECTIVE" | "INVALID";
|
|
@@ -703,6 +705,7 @@ declare const promotionCards: {
|
|
|
703
705
|
noResultsReason?: string | undefined;
|
|
704
706
|
maxItems?: number | undefined;
|
|
705
707
|
nextCursor?: string | undefined;
|
|
708
|
+
showAlipayWallet?: boolean | undefined;
|
|
706
709
|
}>>;
|
|
707
710
|
readonly 'promotion-activity-list': _tbox_cn_app_contracts.CardMeta<zod.ZodObject<{
|
|
708
711
|
items: zod.ZodArray<zod.ZodObject<{
|
|
@@ -915,8 +918,8 @@ declare const promotionCards: {
|
|
|
915
918
|
conditions: string[];
|
|
916
919
|
description?: string | undefined;
|
|
917
920
|
notice?: string | undefined;
|
|
918
|
-
subtitle?: string | undefined;
|
|
919
921
|
presentation?: "detail" | "schedule" | "guide" | undefined;
|
|
922
|
+
subtitle?: string | undefined;
|
|
920
923
|
location?: string | undefined;
|
|
921
924
|
coverUrl?: string | undefined;
|
|
922
925
|
jumpOnly?: boolean | undefined;
|
|
@@ -946,8 +949,8 @@ declare const promotionCards: {
|
|
|
946
949
|
conditions: string[];
|
|
947
950
|
description?: string | undefined;
|
|
948
951
|
notice?: string | undefined;
|
|
949
|
-
subtitle?: string | undefined;
|
|
950
952
|
presentation?: "detail" | "schedule" | "guide" | undefined;
|
|
953
|
+
subtitle?: string | undefined;
|
|
951
954
|
location?: string | undefined;
|
|
952
955
|
coverUrl?: string | undefined;
|
|
953
956
|
jumpOnly?: boolean | undefined;
|
|
@@ -1641,8 +1644,8 @@ declare const serverModule: {
|
|
|
1641
1644
|
title: string;
|
|
1642
1645
|
description?: string | undefined;
|
|
1643
1646
|
}[] | undefined;
|
|
1644
|
-
subtitle?: string | undefined;
|
|
1645
1647
|
presentation?: "package" | "coupon" | "promotion" | "offer" | "promotion-guide" | undefined;
|
|
1648
|
+
subtitle?: string | undefined;
|
|
1646
1649
|
imageUrl?: string | undefined;
|
|
1647
1650
|
usageRuleText?: string | undefined;
|
|
1648
1651
|
usageTimeText?: string | undefined;
|
|
@@ -1686,8 +1689,8 @@ declare const serverModule: {
|
|
|
1686
1689
|
title: string;
|
|
1687
1690
|
description?: string | undefined;
|
|
1688
1691
|
}[] | undefined;
|
|
1689
|
-
subtitle?: string | undefined;
|
|
1690
1692
|
presentation?: "package" | "coupon" | "promotion" | "offer" | "promotion-guide" | undefined;
|
|
1693
|
+
subtitle?: string | undefined;
|
|
1691
1694
|
imageUrl?: string | undefined;
|
|
1692
1695
|
usageRuleText?: string | undefined;
|
|
1693
1696
|
usageTimeText?: string | undefined;
|
|
@@ -1720,6 +1723,7 @@ declare const serverModule: {
|
|
|
1720
1723
|
unavailableReason?: string | undefined;
|
|
1721
1724
|
}>>;
|
|
1722
1725
|
readonly 'promotion-entitlement-list': _tbox_cn_app_contracts.CardMeta<z.ZodObject<{
|
|
1726
|
+
showAlipayWallet: z.ZodOptional<z.ZodBoolean>;
|
|
1723
1727
|
mallId: z.ZodOptional<z.ZodString>;
|
|
1724
1728
|
miniAppId: z.ZodOptional<z.ZodString>;
|
|
1725
1729
|
maxItems: z.ZodOptional<z.ZodNumber>;
|
|
@@ -1925,6 +1929,7 @@ declare const serverModule: {
|
|
|
1925
1929
|
noResultsReason?: string | undefined;
|
|
1926
1930
|
maxItems?: number | undefined;
|
|
1927
1931
|
nextCursor?: string | undefined;
|
|
1932
|
+
showAlipayWallet?: boolean | undefined;
|
|
1928
1933
|
}, {
|
|
1929
1934
|
items: {
|
|
1930
1935
|
status: "UNKNOWN" | "USED" | "EXPIRED" | "EFFECTIVE" | "INVALID";
|
|
@@ -1971,6 +1976,7 @@ declare const serverModule: {
|
|
|
1971
1976
|
noResultsReason?: string | undefined;
|
|
1972
1977
|
maxItems?: number | undefined;
|
|
1973
1978
|
nextCursor?: string | undefined;
|
|
1979
|
+
showAlipayWallet?: boolean | undefined;
|
|
1974
1980
|
}>>;
|
|
1975
1981
|
readonly 'promotion-activity-list': _tbox_cn_app_contracts.CardMeta<z.ZodObject<{
|
|
1976
1982
|
items: z.ZodArray<z.ZodObject<{
|
|
@@ -2183,8 +2189,8 @@ declare const serverModule: {
|
|
|
2183
2189
|
conditions: string[];
|
|
2184
2190
|
description?: string | undefined;
|
|
2185
2191
|
notice?: string | undefined;
|
|
2186
|
-
subtitle?: string | undefined;
|
|
2187
2192
|
presentation?: "detail" | "schedule" | "guide" | undefined;
|
|
2193
|
+
subtitle?: string | undefined;
|
|
2188
2194
|
location?: string | undefined;
|
|
2189
2195
|
coverUrl?: string | undefined;
|
|
2190
2196
|
jumpOnly?: boolean | undefined;
|
|
@@ -2214,8 +2220,8 @@ declare const serverModule: {
|
|
|
2214
2220
|
conditions: string[];
|
|
2215
2221
|
description?: string | undefined;
|
|
2216
2222
|
notice?: string | undefined;
|
|
2217
|
-
subtitle?: string | undefined;
|
|
2218
2223
|
presentation?: "detail" | "schedule" | "guide" | undefined;
|
|
2224
|
+
subtitle?: string | undefined;
|
|
2219
2225
|
location?: string | undefined;
|
|
2220
2226
|
coverUrl?: string | undefined;
|
|
2221
2227
|
jumpOnly?: boolean | undefined;
|
package/dist/server/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tbox.cn/app-module-promotion",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.17",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "商圈营销模块:资格校验、推荐降级链、券卡(codegen 源)。",
|
|
6
6
|
"exports": {
|
|
@@ -20,16 +20,16 @@
|
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"jsbarcode": "^3.12.3",
|
|
22
22
|
"qrcode": "^1.5.4",
|
|
23
|
-
"@tbox.cn/app-contracts
|
|
24
|
-
"@tbox.cn/app-agent-sdk-server": "1.0.0-alpha.
|
|
25
|
-
"@tbox.cn/app-agent-sdk-client": "1.0.0-alpha.
|
|
26
|
-
"@tbox.cn/app-contracts": "1.0.0-alpha.
|
|
23
|
+
"@tbox.cn/app-contracts": "1.0.0-alpha.17",
|
|
24
|
+
"@tbox.cn/app-agent-sdk-server": "1.0.0-alpha.17",
|
|
25
|
+
"@tbox.cn/app-agent-sdk-client": "1.0.0-alpha.17",
|
|
26
|
+
"@tbox.cn/app-contracts-mall": "1.0.0-alpha.17"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"@phosphor-icons/react": "2.1.10",
|
|
30
30
|
"react": "18.3.1",
|
|
31
31
|
"zod": "3.25.76",
|
|
32
|
-
"@tbox.cn/app-agent-ui-kit": "^1.0.0-alpha.
|
|
32
|
+
"@tbox.cn/app-agent-ui-kit": "^1.0.0-alpha.17"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@types/express": "4.17.25",
|
|
@@ -50,7 +50,7 @@ routingTerms:
|
|
|
50
50
|
|
|
51
51
|
触发:"有什么优惠""有没有券""现在有什么折扣""推荐优惠""有没有满减"。
|
|
52
52
|
|
|
53
|
-
用户问“有什么可领取/可领优惠券”时,必须调 `listCoupons` 且传 `mode=CLAIMABLE`,出可领取优惠券列表;不得调用 `listEntitlements
|
|
53
|
+
用户问“有什么可领取/可领优惠券”时,必须调 `listCoupons` 且传 `mode=CLAIMABLE`,出可领取优惠券列表;不得调用 `listEntitlements`,不得把已领取券包当作答案。只有出现“我的/我有什么卡券/已领取/券包/持有”才进入 OWNED 流程。泛优惠(包含活动、团购)才调 `searchOffers`。用户想了解某张券的详情(面额/门槛/有效期/适用规则)时,调 `getOfferDetail`。
|
|
54
54
|
|
|
55
55
|
**数据禁编**:面额、门槛、库存、有效期一律从工具返回读取,禁止推断或声称任何未查得数据——券规则说错一条,结账时就有一场纠纷。
|
|
56
56
|
|
|
@@ -79,9 +79,11 @@ routingTerms:
|
|
|
79
79
|
|
|
80
80
|
### 三:查"我的券"
|
|
81
81
|
|
|
82
|
-
触发:"我有哪些券""我的卡包""我领了什么券""券码是什么"。
|
|
82
|
+
触发:"我有什么卡券""我有哪些券""我的卡包""我领了什么券""券码是什么"。
|
|
83
83
|
|
|
84
|
-
调 `listEntitlements
|
|
84
|
+
调 `listEntitlements`,出参含 `promotion-entitlement-list` 时**必须**引用该卡。带 `showAlipayWallet` 的卡片有商场券时展示列表和「去卡包查看神券」入口,空列表时展示神券引导卡。正文可简述商场券查询结果,并引导前往支付宝卡包查看神券,不得只在正文列券而省略卡片引用。只有出现“我的/我有什么卡券/已领取/券包/券码”语义时才进入此流程;“可领取/有什么优惠”永远走上面的 CLAIMABLE 流程。
|
|
85
|
+
|
|
86
|
+
用户询问“刚才那张券领到了吗”时,先定位对应的券与领取记录。持有券列表为空仅表示当前没有查到商场券,不能据此断言上次领取失败;支付宝神券可到卡包核实。
|
|
85
87
|
|
|
86
88
|
**未入会分支**:用户已登录但未入会时,`listEntitlements`/`listCoupons(mode=OWNED)` 出参已含 `member-enrollment-cta` 引导卡——**直接引用该卡 id 即可**,无需再调 member 域 `queryEnrollmentCta`;正文简述“点击卡片完成入会后可查看券包”。
|
|
87
89
|
|
|
@@ -89,13 +91,15 @@ routingTerms:
|
|
|
89
91
|
|
|
90
92
|
触发:"哪个优惠最合适""满减怎么算最省""帮我算最优组合""怎么买划算"。
|
|
91
93
|
|
|
92
|
-
|
|
94
|
+
只有消费金额时先问打算在哪家店消费;已有门店或券时沿用,不重复问。用户问自己能用哪张券先查持有券,问可领或可购优惠则查对应列表。
|
|
95
|
+
有测算工具且条件齐全时,按工具支持的范围使用 `calculateBestDeal`(`currentAmountCents` 单位为分)。缺少测算能力时,仍可根据本轮查到的同一张券、适用门店、门槛和面额给出单券估算。付费购买的代金券需计入购券成本;券规则、可叠加性或适用时段未知时指出缺少的条件,最终金额以结算页为准。
|
|
96
|
+
“这张”“第二个”“还有吗”应对照上一轮展示顺序识别目标,再用本轮结果核实。候选有歧义时列出简称请用户选。仅推荐本次结果中确有的券,不把空结果解释成已下架,不推断售罄、可叠加或最低价。
|
|
93
97
|
|
|
94
98
|
### 五:查询活动
|
|
95
99
|
|
|
96
100
|
用户问「有什么活动」「活动中心」「查询活动列表」或活动详情时,使用活动玩法域的
|
|
97
101
|
`listActivityPlays` / `getActivityPlayDetail`,不使用优惠搜索或营销专题替代活动查询。
|
|
98
|
-
|
|
102
|
+
追问“这个活动”且上轮只有一个明确目标时沿用该活动标识;多个目标无法区分时先请用户选。活动玩法未装配或查询失败时如实说明,不返回演示活动。
|
|
99
103
|
|
|
100
104
|
### 六:查营销专题/促销活动
|
|
101
105
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { CalendarBlank, CaretDown, Copy, MapPinLine, NavigationArrow, ShieldCheck, Ticket } from '@phosphor-icons/react';
|
|
1
|
+
import { CalendarBlank, CaretDown, CaretRight, Copy, MapPinLine, NavigationArrow, ShieldCheck, Ticket, Wallet } from '@phosphor-icons/react';
|
|
2
2
|
import { useEffect, useRef, useState } from 'react';
|
|
3
|
-
import { callJsapi, httpGet } from '@tbox.cn/app-agent-sdk-client';
|
|
3
|
+
import { callJsapi, httpGet, isInAlipayShell } from '@tbox.cn/app-agent-sdk-client';
|
|
4
4
|
import type { PromotionEntitlementListCardData } from '@tbox.cn/app-contracts-mall';
|
|
5
5
|
import { CouponSheet } from '../../components/CouponSheet';
|
|
6
6
|
import { CouponBarcode, CouponQrCode } from '../../components/CouponQrCode';
|
|
@@ -14,6 +14,41 @@ import {
|
|
|
14
14
|
PROMOTION_CHIP_COUPON_OFF_CLASS,
|
|
15
15
|
} from '../../components/class-names';
|
|
16
16
|
|
|
17
|
+
const ALIPAY_WALLET_APP_ID = '20000021';
|
|
18
|
+
const ALIPAY_WALLET_QUERY = 'tabPage=voucher';
|
|
19
|
+
const ALIPAY_WALLET_URL = `alipays://platformapi/startapp?appId=${ALIPAY_WALLET_APP_ID}&${ALIPAY_WALLET_QUERY}`; // guard-vendor-neutrality: allow(支付宝公共卡包入口)
|
|
20
|
+
|
|
21
|
+
function AlipayWalletLink() {
|
|
22
|
+
const [failed, setFailed] = useState(false);
|
|
23
|
+
return (
|
|
24
|
+
<footer className="px-3.5 py-3">
|
|
25
|
+
<a
|
|
26
|
+
href={ALIPAY_WALLET_URL}
|
|
27
|
+
className="flex min-h-12 w-full items-center justify-center gap-2 rounded-xl bg-[#edf3e7] px-4 py-3 text-sm font-semibold leading-5 text-[#355638] no-underline hover:brightness-[0.97] active:brightness-95 focus-visible:outline-2 focus-visible:outline-offset-[-3px]"
|
|
28
|
+
onClick={async (event) => {
|
|
29
|
+
if (!isInAlipayShell()) return;
|
|
30
|
+
event.preventDefault();
|
|
31
|
+
setFailed(false);
|
|
32
|
+
try {
|
|
33
|
+
await callJsapi('navigateToMiniProgram', { appId: ALIPAY_WALLET_APP_ID, query: ALIPAY_WALLET_QUERY });
|
|
34
|
+
} catch {
|
|
35
|
+
try {
|
|
36
|
+
await callJsapi('ap.openURL', { url: ALIPAY_WALLET_URL });
|
|
37
|
+
} catch {
|
|
38
|
+
setFailed(true);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}}
|
|
42
|
+
>
|
|
43
|
+
<Wallet size={18} weight="duotone" aria-hidden="true" />
|
|
44
|
+
去卡包查看神券
|
|
45
|
+
<CaretRight size={14} weight="bold" aria-hidden="true" />
|
|
46
|
+
</a>
|
|
47
|
+
{failed && <p role="status" className="px-4 py-2 text-xs text-secondary-foreground">暂时无法打开,请在支付宝首页进入「卡包」。</p>}
|
|
48
|
+
</footer>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
17
52
|
export function PromotionEntitlementListCard(props: {
|
|
18
53
|
data: PromotionEntitlementListCardData;
|
|
19
54
|
cardId?: string;
|
|
@@ -63,11 +98,16 @@ export function PromotionEntitlementListCard(props: {
|
|
|
63
98
|
<Ticket weight="fill" />
|
|
64
99
|
<h3 className="text-base font-bold leading-[21px] text-[#2f3a22] [overflow-wrap:anywhere]">我的优惠券</h3>
|
|
65
100
|
</div>
|
|
66
|
-
<p className="mt-1 text-xs leading-4 text-[#626b5c]"
|
|
101
|
+
<p className="mt-1 text-xs leading-4 text-[#626b5c]">{data.showAlipayWallet ? '我的商场券' : '当前账户 · 券包权益'}</p>
|
|
67
102
|
</div>
|
|
68
103
|
</header>
|
|
69
|
-
{!data.items.length
|
|
70
|
-
<div
|
|
104
|
+
{!data.items.length && !data.showAlipayWallet && (
|
|
105
|
+
<div className="promotion-card__empty flex min-h-[94px] items-center justify-center gap-2 p-5 text-xs leading-[normal] text-secondary-foreground">
|
|
106
|
+
<Ticket size={28} weight="duotone" /><span>{data.noResultsReason ?? '当前账户暂无可用权益'}</span>
|
|
107
|
+
</div>
|
|
108
|
+
)}
|
|
109
|
+
{data.items.length > 0 && (
|
|
110
|
+
<div ref={listRef} className={`promotion-list__items overflow-hidden px-3.5 ${data.showAlipayWallet && data.items.length <= maxItems ? '[&+footer]:pt-0.5' : 'pb-1'} ${expanded ? ' promotion-list__items--expanded transition-none' : ' transition-[max-height] duration-[320ms] ease-[ease]'}`} style={{ maxHeight }} onTransitionEnd={onTransitionEnd}>
|
|
71
111
|
{visibleItems.map((item) => (
|
|
72
112
|
<article
|
|
73
113
|
key={item.entitlementRef}
|
|
@@ -109,6 +149,7 @@ export function PromotionEntitlementListCard(props: {
|
|
|
109
149
|
{expanded ? '收起' : `查看更多(${data.items.length - maxItems} 条)`}
|
|
110
150
|
</button>
|
|
111
151
|
)}
|
|
152
|
+
{data.showAlipayWallet && <AlipayWalletLink />}
|
|
112
153
|
{data.items.length > maxItems && <div ref={bottomRef} className="promotion-list__bottom-anchor h-0 flex-none scroll-mb-[max(96px,calc(var(--tbox-chat-bottom-height,0px)_+_24px))]" aria-hidden="true" />}
|
|
113
154
|
{sheetTarget && (() => {
|
|
114
155
|
const facts = [
|
|
@@ -29,6 +29,7 @@ export const samples: CardSample<PromotionEntitlementListCardData>[] = [
|
|
|
29
29
|
note: '待使用、已使用、已过期三态及动作降级同屏',
|
|
30
30
|
group: '我的券',
|
|
31
31
|
data: {
|
|
32
|
+
showAlipayWallet: true,
|
|
32
33
|
items: [
|
|
33
34
|
{ entitlementRef: 'ent:effective', title: '瑞幸咖啡|30元饮品代金券', imageUrl: IMG.coffee, entitlementType: 'COUPON', status: 'EFFECTIVE', codeMasked: '**** 6688', benefitText: '¥30', thresholdText: '无门槛', usageNotice: '1F · 到店点单可用', validUntilText: '2026-09-27 到期' },
|
|
34
35
|
{ entitlementRef: 'ent:used', title: 'KKV 120元优惠券', imageUrl: IMG.lifestyle, entitlementType: 'COUPON', status: 'USED', codeMasked: '**** 1058', benefitText: '¥105 · 8.8折', usageNotice: '已于 2026-08-26 使用', validUntilText: '已使用' },
|
|
@@ -45,8 +46,8 @@ export const samples: CardSample<PromotionEntitlementListCardData>[] = [
|
|
|
45
46
|
},
|
|
46
47
|
{
|
|
47
48
|
label: '我的券·空态',
|
|
48
|
-
note: '
|
|
49
|
+
note: '无商场券时在卡头下直接展示通栏卡包入口',
|
|
49
50
|
group: '我的券',
|
|
50
|
-
data: { items: [],
|
|
51
|
+
data: { items: [], showAlipayWallet: true },
|
|
51
52
|
},
|
|
52
53
|
];
|
package/src/server/handler.ts
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
activityDetail,
|
|
17
17
|
activitySummary,
|
|
18
18
|
entitlementSummary,
|
|
19
|
+
entitlementListResult,
|
|
19
20
|
offerDetail,
|
|
20
21
|
offerSummary,
|
|
21
22
|
} from './tools';
|
|
@@ -27,7 +28,7 @@ import { resolveDealRecallPort } from './deal-recall-tools';
|
|
|
27
28
|
* 为 QuickCommands 固定句补偿,「活动」子串保留于域内长词以维持卡按钮 value 路由) */
|
|
28
29
|
export const PROMOTION_INTENTS = {
|
|
29
30
|
'list-entitlements': {
|
|
30
|
-
patterns: ['我的优惠券', '我的券包', '我的券', '已领取的券', '已领优惠券', '持有的优惠券'],
|
|
31
|
+
patterns: ['我有什么卡券', '我有哪些卡券', '我的卡券', '我有哪些券', '我有什么优惠券', '我的优惠券', '我的券包', '我的券', '已领取的券', '已领优惠券', '持有的优惠券'],
|
|
31
32
|
description: '查询当前会员已拥有的优惠券',
|
|
32
33
|
},
|
|
33
34
|
'search-offers': {
|
|
@@ -62,7 +63,7 @@ const PROMOTION_RESOLVE_ROUTES: IntentRoute[] = [
|
|
|
62
63
|
},
|
|
63
64
|
];
|
|
64
65
|
|
|
65
|
-
const OWNED_INTENT_HINTS = ['我的优惠券', '我的券包', '我的券', '已领取', '已领优惠券', '持有的优惠券'];
|
|
66
|
+
const OWNED_INTENT_HINTS = ['我的卡券', '我的优惠券', '我的券包', '我的券', '已领取', '已领优惠券', '持有的优惠券'];
|
|
66
67
|
const CLAIMABLE_INTENT_HINTS = ['有什么优惠', '可领取', '可领', '领取优惠券', '领券'];
|
|
67
68
|
|
|
68
69
|
function intentContent(payload: unknown): string {
|
|
@@ -90,6 +91,10 @@ function resolveIntent(payload: unknown): ResolvedIntent | null {
|
|
|
90
91
|
// → 返回 null 由 handle 放行 LLM,不以 search-offers 兜底吞轮(bumpin/member/guide 同惯例)。
|
|
91
92
|
if (content.startsWith(NAVIGATION_SENTENCE_PREFIX)) return null;
|
|
92
93
|
// 先处理业务边界,再交给 BM25:可领取与已领取是互斥查询轴,避免“优惠券”宽词把首页入口落到券包。
|
|
94
|
+
const phrase = content.trim().replace(/[??!!。]+$/u, '');
|
|
95
|
+
if (PROMOTION_INTENTS['list-entitlements'].patterns.some((pattern) => pattern === phrase)) {
|
|
96
|
+
return { kind: 'list-entitlements' };
|
|
97
|
+
}
|
|
93
98
|
const owned = OWNED_INTENT_HINTS.some((hint) => content.includes(hint));
|
|
94
99
|
const claimable = CLAIMABLE_INTENT_HINTS.some((hint) => content.includes(hint));
|
|
95
100
|
if (claimable && !owned) return { kind: 'search-coupons' };
|
|
@@ -340,35 +345,29 @@ export function createPromotionIntentHandler(
|
|
|
340
345
|
if (gate) return { cards: gate.card ? [gate.card] : [], text: gate.notice };
|
|
341
346
|
const service = await resolvePromotionEntitlementsPort(reqCtx, ctx);
|
|
342
347
|
const page = await service.listEntitlements(q, { limit: 50 });
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
cards: [{ cardType: 'promotion-offer-list', data: {
|
|
351
|
-
presentation: 'coupon', mode: 'claimable', items: items.map(offerSummary),
|
|
352
|
-
} }],
|
|
353
|
-
text: `你的券包里还没有优惠券,为你找到 ${items.length} 条可领优惠`,
|
|
354
|
-
};
|
|
348
|
+
const result = entitlementListResult(page, q);
|
|
349
|
+
if (result.cards) {
|
|
350
|
+
let text = `你的券包里有 ${page.items.length} 张优惠券`;
|
|
351
|
+
if (page.showAlipayWallet) {
|
|
352
|
+
text = page.items.length
|
|
353
|
+
? `查到 ${page.items.length} 张商场优惠券,神券可到支付宝卡包查看。`
|
|
354
|
+
: '暂无商场优惠券,你可以去支付宝卡包查看神券。';
|
|
355
355
|
}
|
|
356
|
-
return { cards:
|
|
356
|
+
return { cards: result.cards, text };
|
|
357
357
|
}
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
};
|
|
358
|
+
// 空券降级推荐走 offers 槽(双槽分支:entitlements 查 + offers 推荐)
|
|
359
|
+
const offersService = await resolvePromotionOffersPort(reqCtx, ctx);
|
|
360
|
+
const offers = await offersService.searchOffers(q, { offerTypes: ['COUPON'], limit: 50 });
|
|
361
|
+
const items = offers.items.filter((item) => item.availability.status === 'AVAILABLE');
|
|
362
|
+
if (items.length > 0) {
|
|
363
|
+
return {
|
|
364
|
+
cards: [{ cardType: 'promotion-offer-list', data: {
|
|
365
|
+
presentation: 'coupon', mode: 'claimable', items: items.map(offerSummary),
|
|
366
|
+
} }],
|
|
367
|
+
text: `你的券包里还没有优惠券,为你找到 ${items.length} 条可领优惠`,
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
return { cards: [], text: '你的券包里还没有优惠券,当前也没有可领取优惠' };
|
|
372
371
|
}
|
|
373
372
|
case 'list-activities': {
|
|
374
373
|
const delegated = await delegateLinkedActivity(ctx, payload, reqCtx);
|
package/src/server/index.ts
CHANGED
|
@@ -65,7 +65,7 @@ const excludedDealIdsSchema = z.array(z.string().min(1).max(128)).default([]);
|
|
|
65
65
|
* - silent:不发前端事件;结果 reminder 注入 + cards 经 capture 入本轮候选池;
|
|
66
66
|
* - 出参体积门:CLAIMABLE 出参 build 期实测 ≤ 2KB(promotion pretool 测试断言),超限即撤本 preTool。
|
|
67
67
|
*/
|
|
68
|
-
const OWNED_INTENT_RE =
|
|
68
|
+
const OWNED_INTENT_RE = /我的(?:优惠券|卡券|券)|已领|券包|券码|^我(?:有什么|有哪些)(?:优惠券|卡券|券)[??!!。]*$/u;
|
|
69
69
|
const EXTERNAL_DEAL_INTENT_RE = /支付宝神券|外部团购/;
|
|
70
70
|
|
|
71
71
|
const listCouponsPreTool = definePreTool(tools.listCoupons, {
|
package/src/server/tools.ts
CHANGED
|
@@ -13,6 +13,7 @@ import type {
|
|
|
13
13
|
PromotionActivityPort,
|
|
14
14
|
PromotionEntitlement,
|
|
15
15
|
PromotionEntitlementPort,
|
|
16
|
+
PromotionEntitlementPage,
|
|
16
17
|
PromotionOffer,
|
|
17
18
|
PromotionOfferQueryPort,
|
|
18
19
|
PromotionQueryContext,
|
|
@@ -40,6 +41,22 @@ function withCards<T extends Record<string, unknown>>(facts: T, cardType: string
|
|
|
40
41
|
return { ...facts, cards: [{ cardType, data: facts, note }] };
|
|
41
42
|
}
|
|
42
43
|
|
|
44
|
+
export function entitlementListResult(page: PromotionEntitlementPage, q: PromotionQueryContext) {
|
|
45
|
+
const facts = {
|
|
46
|
+
mallId: q.scope.mallId,
|
|
47
|
+
miniAppId: q.scope.miniAppId,
|
|
48
|
+
items: page.items.map(entitlementSummary),
|
|
49
|
+
...(page.nextCursor ? { nextCursor: page.nextCursor } : {}),
|
|
50
|
+
...(page.showAlipayWallet ? { showAlipayWallet: true } : {}),
|
|
51
|
+
...(!page.items.length ? {
|
|
52
|
+
noResultsReason: page.showAlipayWallet ? '暂无商场优惠券' : '还没有优惠券,可让我帮你找找可领优惠',
|
|
53
|
+
} : {}),
|
|
54
|
+
};
|
|
55
|
+
if (!facts.items.length && !page.showAlipayWallet) return { ...facts, cards: undefined };
|
|
56
|
+
const first = facts.items[0];
|
|
57
|
+
return withCards(facts, 'promotion-entitlement-list', first ? `我的优惠券 ${facts.items.length} 张 · ${first.title}` : '暂无商场优惠券,可去卡包查看神券');
|
|
58
|
+
}
|
|
59
|
+
|
|
43
60
|
function dateText(value?: string): string | undefined {
|
|
44
61
|
if (!value) return undefined;
|
|
45
62
|
const date = new Date(value);
|
|
@@ -324,6 +341,23 @@ const activityDetailInput = coerce(
|
|
|
324
341
|
z.object({ activityRef: z.string().optional(), keyword: z.string().optional() }),
|
|
325
342
|
);
|
|
326
343
|
|
|
344
|
+
// Detail lookups need a reference selected by the user or a concrete name from the conversation.
|
|
345
|
+
const needsSelection = { found: false, needsSelection: true, message: '请先确认具体的活动或优惠名称,再查详情。' } as const;
|
|
346
|
+
|
|
347
|
+
function hasDetailTarget(ref: unknown, keyword: unknown): boolean {
|
|
348
|
+
if (typeof ref === 'string' && ref.trim()) return true;
|
|
349
|
+
if (typeof keyword !== 'string' || !keyword.trim()) return false;
|
|
350
|
+
return !/^(?:刚才的?|上面的?|这(?:个|张|场|次)?|那(?:个|张|场|次)?|该|它)(?:活动|促销|优惠券?|券|专题|礼包)?[??。!!]*$/.test(keyword.trim());
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
function uniqueResult<T extends { title: string }>(page: { items: readonly T[]; hasMore: boolean }, keyword: string) {
|
|
354
|
+
if (!page.items.length) return null;
|
|
355
|
+
if (page.hasMore) return needsSelection;
|
|
356
|
+
if (page.items.length === 1) return page.items[0];
|
|
357
|
+
const exact = page.items.filter((item) => item.title === keyword.trim());
|
|
358
|
+
return exact.length === 1 ? exact[0] : needsSelection;
|
|
359
|
+
}
|
|
360
|
+
|
|
327
361
|
export function createPromotionTools(opts: { getCtx: () => ServerContext }) {
|
|
328
362
|
/** 活动工具与确定性活动意图共用联单分流;未启用策略/未装模块返回 undefined。 */
|
|
329
363
|
const delegateLinkedActivity = async (reqCtx: RequestContext) => {
|
|
@@ -354,15 +388,15 @@ export function createPromotionTools(opts: { getCtx: () => ServerContext }) {
|
|
|
354
388
|
args: Record<string, unknown>,
|
|
355
389
|
offerTypes?: readonly OfferType[],
|
|
356
390
|
) => {
|
|
357
|
-
if (typeof args.offerRef === 'string' && args.offerRef) {
|
|
391
|
+
if (typeof args.offerRef === 'string' && args.offerRef.trim()) {
|
|
358
392
|
return service.getOfferDetail(q, { offerRef: args.offerRef });
|
|
359
393
|
}
|
|
360
394
|
const page = await service.searchOffers(q, {
|
|
361
395
|
keyword: args.keyword as string | undefined,
|
|
362
396
|
offerTypes,
|
|
363
|
-
limit:
|
|
397
|
+
limit: 2,
|
|
364
398
|
});
|
|
365
|
-
return page.
|
|
399
|
+
return uniqueResult(page, String(args.keyword));
|
|
366
400
|
};
|
|
367
401
|
const resolveActivity = async (
|
|
368
402
|
service: PromotionActivityPort,
|
|
@@ -372,9 +406,10 @@ export function createPromotionTools(opts: { getCtx: () => ServerContext }) {
|
|
|
372
406
|
if (typeof args.activityRef === 'string' && args.activityRef) {
|
|
373
407
|
return service.getActivityDetail(q, args.activityRef);
|
|
374
408
|
}
|
|
375
|
-
const page = await service.listActivities(q, { keyword: args.keyword as string
|
|
376
|
-
const
|
|
377
|
-
|
|
409
|
+
const page = await service.listActivities(q, { keyword: args.keyword as string, limit: 2 });
|
|
410
|
+
const selected = uniqueResult(page, String(args.keyword));
|
|
411
|
+
if (!selected || 'needsSelection' in selected) return selected;
|
|
412
|
+
return service.getActivityDetail(q, selected.activityRef);
|
|
378
413
|
};
|
|
379
414
|
const search = (
|
|
380
415
|
service: PromotionOfferQueryPort,
|
|
@@ -389,7 +424,7 @@ export function createPromotionTools(opts: { getCtx: () => ServerContext }) {
|
|
|
389
424
|
limit: args.limit ? Number(args.limit) : 50,
|
|
390
425
|
offerTypes,
|
|
391
426
|
});
|
|
392
|
-
const
|
|
427
|
+
const listOwnedCoupons = async (
|
|
393
428
|
service: PromotionEntitlementPort,
|
|
394
429
|
q: PromotionQueryContext,
|
|
395
430
|
args: Record<string, unknown>,
|
|
@@ -412,13 +447,7 @@ export function createPromotionTools(opts: { getCtx: () => ServerContext }) {
|
|
|
412
447
|
cursor: args.cursor as string | undefined,
|
|
413
448
|
limit: args.limit ? Number(args.limit) : 50,
|
|
414
449
|
});
|
|
415
|
-
return
|
|
416
|
-
mallId: q.scope.mallId,
|
|
417
|
-
miniAppId: q.scope.miniAppId,
|
|
418
|
-
items: page.items.map(entitlementSummary),
|
|
419
|
-
...(page.nextCursor ? { nextCursor: page.nextCursor } : {}),
|
|
420
|
-
...(page.items.length === 0 ? { noResultsReason: '还没有优惠券,可让我帮你找找可领优惠' } : {}),
|
|
421
|
-
};
|
|
450
|
+
return entitlementListResult(page, q);
|
|
422
451
|
};
|
|
423
452
|
|
|
424
453
|
const listActivityCategories = createTool({
|
|
@@ -499,12 +528,14 @@ export function createPromotionTools(opts: { getCtx: () => ServerContext }) {
|
|
|
499
528
|
description: '查询指定活动详情、时间、名额和参与条件。',
|
|
500
529
|
inputSchema: activityDetailInput,
|
|
501
530
|
execute: async (args: Record<string, unknown>, execCtx: ToolExecContextLike) => {
|
|
531
|
+
if (!hasDetailTarget(args.activityRef, args.keyword)) return needsSelection;
|
|
502
532
|
const reqCtx = requireToolRequestContext(execCtx, 'getActivityDetail');
|
|
503
533
|
const delegated = await delegateLinkedActivity(reqCtx);
|
|
504
534
|
if (delegated) return delegated;
|
|
505
535
|
const { service, q } = await requireService(execCtx, resolvePromotionActivitiesPort);
|
|
506
536
|
const detail = await resolveActivity(service, q, args);
|
|
507
537
|
if (!detail) return { found: false, message: '未找到该活动' };
|
|
538
|
+
if ('needsSelection' in detail) return detail;
|
|
508
539
|
const facts = { found: true as const, ...activityDetail(detail, 'detail') };
|
|
509
540
|
return withCards(facts, 'promotion-activity-detail', `活动详情:${detail.title}`);
|
|
510
541
|
},
|
|
@@ -515,12 +546,14 @@ export function createPromotionTools(opts: { getCtx: () => ServerContext }) {
|
|
|
515
546
|
description: '查询指定活动的可选场次,只返回只读状态,不执行报名。',
|
|
516
547
|
inputSchema: activityDetailInput,
|
|
517
548
|
execute: async (args: Record<string, unknown>, execCtx: ToolExecContextLike) => {
|
|
549
|
+
if (!hasDetailTarget(args.activityRef, args.keyword)) return needsSelection;
|
|
518
550
|
const reqCtx = requireToolRequestContext(execCtx, 'listActivitySessions');
|
|
519
551
|
const delegated = await delegateLinkedActivity(reqCtx);
|
|
520
552
|
if (delegated) return delegated;
|
|
521
553
|
const { service, q } = await requireService(execCtx, resolvePromotionActivitiesPort);
|
|
522
554
|
const detail = await resolveActivity(service, q, args);
|
|
523
555
|
if (!detail) return { found: false, message: '未找到该活动' };
|
|
556
|
+
if ('needsSelection' in detail) return detail;
|
|
524
557
|
const sessions = service.listActivitySessions
|
|
525
558
|
? await service.listActivitySessions(q, detail.activityRef)
|
|
526
559
|
: detail.sessions;
|
|
@@ -534,12 +567,14 @@ export function createPromotionTools(opts: { getCtx: () => ServerContext }) {
|
|
|
534
567
|
description: '查询指定活动的报名条件和参与步骤,不执行报名。',
|
|
535
568
|
inputSchema: activityDetailInput,
|
|
536
569
|
execute: async (args: Record<string, unknown>, execCtx: ToolExecContextLike) => {
|
|
570
|
+
if (!hasDetailTarget(args.activityRef, args.keyword)) return needsSelection;
|
|
537
571
|
const reqCtx = requireToolRequestContext(execCtx, 'getActivityGuide');
|
|
538
572
|
const delegated = await delegateLinkedActivity(reqCtx);
|
|
539
573
|
if (delegated) return delegated;
|
|
540
574
|
const { service, q } = await requireService(execCtx, resolvePromotionActivitiesPort);
|
|
541
575
|
const detail = await resolveActivity(service, q, args);
|
|
542
576
|
if (!detail) return { found: false, message: '未找到该活动' };
|
|
577
|
+
if ('needsSelection' in detail) return detail;
|
|
543
578
|
const facts = activityDetail(detail, 'guide');
|
|
544
579
|
return withCards(facts, 'promotion-activity-detail', `活动参与方式:${detail.title}`);
|
|
545
580
|
},
|
|
@@ -571,6 +606,7 @@ export function createPromotionTools(opts: { getCtx: () => ServerContext }) {
|
|
|
571
606
|
z.object({ offerRef: z.string().optional(), entitlementRef: z.string().optional(), keyword: z.string().optional() }),
|
|
572
607
|
),
|
|
573
608
|
execute: async (args: Record<string, unknown>, execCtx: ToolExecContextLike) => {
|
|
609
|
+
if (!args.entitlementRef && !hasDetailTarget(args.offerRef, args.keyword)) return needsSelection;
|
|
574
610
|
const { service, q, reqCtx } = await requireService(execCtx, resolvePromotionOffersPort);
|
|
575
611
|
// entitlementRef 反查 = 我的券详情(属人):仅该分支门禁;offerRef/keyword 公共反查不拦
|
|
576
612
|
if (typeof args.entitlementRef === 'string' && args.entitlementRef) {
|
|
@@ -601,14 +637,7 @@ export function createPromotionTools(opts: { getCtx: () => ServerContext }) {
|
|
|
601
637
|
inputSchema: searchInput,
|
|
602
638
|
execute: async (args: Record<string, unknown>, execCtx: ToolExecContextLike) => {
|
|
603
639
|
const { service, q, reqCtx } = await requireService(execCtx, resolvePromotionEntitlementsPort);
|
|
604
|
-
|
|
605
|
-
return facts.items.length
|
|
606
|
-
? withCards(
|
|
607
|
-
facts,
|
|
608
|
-
'promotion-entitlement-list',
|
|
609
|
-
`我的优惠券 ${facts.items.length} 张${facts.items[0] ? ` · ${facts.items[0].title}` : ''}`,
|
|
610
|
-
)
|
|
611
|
-
: facts;
|
|
640
|
+
return listOwnedCoupons(service, q, args, reqCtx);
|
|
612
641
|
},
|
|
613
642
|
});
|
|
614
643
|
|
|
@@ -636,9 +665,11 @@ export function createPromotionTools(opts: { getCtx: () => ServerContext }) {
|
|
|
636
665
|
description: '按营销专题标识或关键词精确查询活动详情。',
|
|
637
666
|
inputSchema: detailInput,
|
|
638
667
|
execute: async (args: Record<string, unknown>, execCtx: ToolExecContextLike) => {
|
|
668
|
+
if (!hasDetailTarget(args.offerRef, args.keyword)) return needsSelection;
|
|
639
669
|
const { service, q } = await requireService(execCtx, resolvePromotionOffersPort);
|
|
640
670
|
const offer = await resolveOffer(service, q, args, ['PROMOTION']);
|
|
641
671
|
if (!offer) return { found: false, message: '未找到该营销专题' };
|
|
672
|
+
if ('needsSelection' in offer) return offer;
|
|
642
673
|
const facts = { found: true as const, ...offerDetail(offer, false, 'promotion') };
|
|
643
674
|
return withCards(facts, 'promotion-offer-detail', `营销活动详情:${offer.title}`);
|
|
644
675
|
},
|
|
@@ -649,9 +680,11 @@ export function createPromotionTools(opts: { getCtx: () => ServerContext }) {
|
|
|
649
680
|
description: '查询营销专题的厂商参与步骤,不执行报名或领取。',
|
|
650
681
|
inputSchema: detailInput,
|
|
651
682
|
execute: async (args: Record<string, unknown>, execCtx: ToolExecContextLike) => {
|
|
683
|
+
if (!hasDetailTarget(args.offerRef, args.keyword)) return needsSelection;
|
|
652
684
|
const { service, q } = await requireService(execCtx, resolvePromotionOffersPort);
|
|
653
685
|
const offer = await resolveOffer(service, q, args, ['PROMOTION']);
|
|
654
686
|
if (!offer) return { found: false, message: '未找到该营销专题' };
|
|
687
|
+
if ('needsSelection' in offer) return offer;
|
|
655
688
|
const facts = { found: true as const, ...offerDetail(offer, false, 'promotion-guide') };
|
|
656
689
|
return withCards(facts, 'promotion-offer-detail', `参与方式:${offer.title}`);
|
|
657
690
|
},
|
|
@@ -659,7 +692,7 @@ export function createPromotionTools(opts: { getCtx: () => ServerContext }) {
|
|
|
659
692
|
|
|
660
693
|
const listCoupons = createTool({
|
|
661
694
|
id: 'listCoupons',
|
|
662
|
-
description: '查询优惠券列表。默认只查询当前可领取优惠券(CLAIMABLE
|
|
695
|
+
description: '查询优惠券列表。默认只查询当前可领取优惠券(CLAIMABLE);只有用户明确说“我有什么卡券/我的券/已领取/券包”时才传 mode=OWNED。mode=OWNED 已登录未入会时返回入会引导卡(member-enrollment-cta),无需再调 member 域 queryEnrollmentCta。',
|
|
663
696
|
inputSchema: coerce(
|
|
664
697
|
z.object({
|
|
665
698
|
mode: z.enum(['CLAIMABLE', 'OWNED']).default('CLAIMABLE'),
|
|
@@ -672,10 +705,7 @@ export function createPromotionTools(opts: { getCtx: () => ServerContext }) {
|
|
|
672
705
|
// 模式分流双槽(017):OWNED = 我的券 → entitlements 槽;CLAIMABLE = 可领券 → offers 槽
|
|
673
706
|
if (args.mode === 'OWNED') {
|
|
674
707
|
const { service, q, reqCtx } = await requireService(execCtx, resolvePromotionEntitlementsPort);
|
|
675
|
-
|
|
676
|
-
return facts.items.length
|
|
677
|
-
? withCards(facts, 'promotion-entitlement-list', `我的优惠券 ${facts.items.length} 张${facts.items[0] ? ` · ${facts.items[0].title ?? ''}` : ''}`)
|
|
678
|
-
: facts;
|
|
708
|
+
return listOwnedCoupons(service, q, args, reqCtx);
|
|
679
709
|
}
|
|
680
710
|
const { service, q, reqCtx } = await requireService(execCtx, resolvePromotionOffersPort);
|
|
681
711
|
const [page, dealRecall] = await Promise.all([
|
|
@@ -703,9 +733,11 @@ export function createPromotionTools(opts: { getCtx: () => ServerContext }) {
|
|
|
703
733
|
description: '查询组合礼包及其子权益。',
|
|
704
734
|
inputSchema: detailInput,
|
|
705
735
|
execute: async (args: Record<string, unknown>, execCtx: ToolExecContextLike) => {
|
|
736
|
+
if (!hasDetailTarget(args.offerRef, args.keyword)) return needsSelection;
|
|
706
737
|
const { service, q } = await requireService(execCtx, resolvePromotionOffersPort);
|
|
707
738
|
const offer = await resolveOffer(service, q, args, ['BUNDLE']);
|
|
708
739
|
if (!offer) return { found: false, message: '未找到该优惠礼包' };
|
|
740
|
+
if ('needsSelection' in offer) return offer;
|
|
709
741
|
const facts = {
|
|
710
742
|
found: true as const,
|
|
711
743
|
...offerDetail(offer, supportsAcquire(service), 'package'),
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { act, StrictMode } from 'react';
|
|
3
3
|
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
4
4
|
import { createRoot } from 'react-dom/client';
|
|
5
|
-
import { httpPost, navigateToAlipayPage, sendCardAction } from '@tbox.cn/app-agent-sdk-client';
|
|
5
|
+
import { callJsapi, isInAlipayShell, httpPost, navigateToAlipayPage, sendCardAction } from '@tbox.cn/app-agent-sdk-client';
|
|
6
6
|
import {
|
|
7
7
|
PromotionActivityCategoryListCard,
|
|
8
8
|
PromotionActivityDetailCard,
|
|
@@ -18,12 +18,14 @@ import { sanitizeActivityHtml } from '../src/client/utils/sanitize-activity-html
|
|
|
18
18
|
|
|
19
19
|
vi.mock('@tbox.cn/app-agent-sdk-client', async (importOriginal) => {
|
|
20
20
|
const mod = await importOriginal<typeof import('@tbox.cn/app-agent-sdk-client')>();
|
|
21
|
-
return { ...mod, httpPost: vi.fn(), navigateToAlipayPage: vi.fn(() => Promise.resolve()), sendCardAction: vi.fn() };
|
|
21
|
+
return { ...mod, isInAlipayShell: vi.fn(() => false), callJsapi: vi.fn(), httpPost: vi.fn(), navigateToAlipayPage: vi.fn(() => Promise.resolve()), sendCardAction: vi.fn() };
|
|
22
22
|
});
|
|
23
23
|
|
|
24
24
|
// 浮层 portal 到 body,用例间不清就会互相看见对方的残留
|
|
25
25
|
afterEach(() => {
|
|
26
26
|
document.body.innerHTML = '';
|
|
27
|
+
vi.mocked(isInAlipayShell).mockReturnValue(false);
|
|
28
|
+
vi.mocked(callJsapi).mockReset();
|
|
27
29
|
vi.mocked(httpPost).mockReset();
|
|
28
30
|
vi.mocked(sendCardAction).mockReset();
|
|
29
31
|
vi.mocked(navigateToAlipayPage).mockReset();
|
|
@@ -336,11 +338,12 @@ describe('legacy 19 个营销展示语义', () => {
|
|
|
336
338
|
});
|
|
337
339
|
|
|
338
340
|
it('entitlement-list 恢复钱包、状态、券码和安全提示', () => {
|
|
339
|
-
const host = render(<PromotionEntitlementListCard data={{ items: [{ entitlementRef: 'e1', title: '停车券', entitlementType: 'COUPON', status: 'EFFECTIVE', codeMasked: '****8888', validUntilText: '有效期至 2026-12-31' }] } as never} cardId="c1" />);
|
|
341
|
+
const host = render(<PromotionEntitlementListCard data={{ showAlipayWallet: true, items: [{ entitlementRef: 'e1', title: '停车券', entitlementType: 'COUPON', status: 'EFFECTIVE', codeMasked: '****8888', validUntilText: '有效期至 2026-12-31' }] } as never} cardId="c1" />);
|
|
340
342
|
expect(host.querySelector('.promotion-entitlements')?.classList.contains('promotion-list--coupon')).toBe(true);
|
|
341
343
|
expect(host.querySelector('.promotion-list--offers')).toBeNull();
|
|
342
344
|
expect(host.querySelector('.promotion-coupon__header')?.textContent).toContain('我的优惠券');
|
|
343
|
-
expect(host.querySelector('.promotion-coupon__header')?.textContent).toContain('
|
|
345
|
+
expect(host.querySelector('.promotion-coupon__header')?.textContent).toContain('我的商场券');
|
|
346
|
+
expect(host.querySelector('a')?.textContent).toContain('去卡包查看神券');
|
|
344
347
|
expect(host.querySelector('.promotion-activity__header-art')).toBeNull(); // 素材变量链:头图 img 已转 CSS background
|
|
345
348
|
// 券码不再摊在行上:一屏几张券,脱敏码谁也用不上,点开浮层才需要
|
|
346
349
|
expect(host.querySelector('.promotion-coupon-row')?.textContent).not.toContain('****8888');
|
|
@@ -351,6 +354,27 @@ describe('legacy 19 个营销展示语义', () => {
|
|
|
351
354
|
expect(host.querySelector('.promotion-card__footer')).toBeNull();
|
|
352
355
|
});
|
|
353
356
|
|
|
357
|
+
it('无商场券时展示卡包入口,支付宝壳优先唤起卡包,失败时回退并提示', async () => {
|
|
358
|
+
vi.mocked(isInAlipayShell).mockReturnValue(true);
|
|
359
|
+
vi.mocked(callJsapi).mockRejectedValue(new Error('unavailable'));
|
|
360
|
+
const host = render(<PromotionEntitlementListCard data={{ items: [], showAlipayWallet: true }} />);
|
|
361
|
+
expect(host.querySelector('.promotion-card__empty')).toBeNull();
|
|
362
|
+
expect(host.textContent).not.toContain('暂无商场优惠券');
|
|
363
|
+
expect(host.querySelector('.promotion-coupon__header')?.textContent).toContain('我的优惠券');
|
|
364
|
+
expect(host.querySelector('.promotion-list__items')).toBeNull();
|
|
365
|
+
const link = host.querySelector<HTMLAnchorElement>('header + footer a')!;
|
|
366
|
+
expect(link.textContent).toContain('去卡包查看神券');
|
|
367
|
+
expect(link.getAttribute('href')).toBe('alipays://platformapi/startapp?appId=20000021&tabPage=voucher'); // guard-vendor-neutrality: allow(支付宝公共卡包入口)
|
|
368
|
+
await act(async () => link.click());
|
|
369
|
+
expect(callJsapi).toHaveBeenNthCalledWith(1, 'navigateToMiniProgram', { appId: '20000021', query: 'tabPage=voucher' });
|
|
370
|
+
expect(callJsapi).toHaveBeenNthCalledWith(2, 'ap.openURL', { url: link.href });
|
|
371
|
+
expect(host.querySelector('[role=status]')).not.toBeNull();
|
|
372
|
+
vi.mocked(callJsapi).mockResolvedValueOnce({});
|
|
373
|
+
await act(async () => link.click());
|
|
374
|
+
expect(callJsapi).toHaveBeenCalledTimes(3);
|
|
375
|
+
expect(host.querySelector('[role=status]')).toBeNull();
|
|
376
|
+
});
|
|
377
|
+
|
|
354
378
|
it('我的优惠券默认最多展示 4 条,maxItems 可配置', () => {
|
|
355
379
|
const items = Array.from({ length: 5 }, (_, index) => ({
|
|
356
380
|
entitlementRef: `e${index}`,
|
package/tests/promotion.test.ts
CHANGED
|
@@ -285,6 +285,16 @@ describe('promotion 确定性意图路由', () => {
|
|
|
285
285
|
expect(otherProvider.cards[0]?.cardType).toBe('promotion-activity-list');
|
|
286
286
|
});
|
|
287
287
|
|
|
288
|
+
it('指代不明时不取第一场活动,不分流去首页的联单活动', async () => {
|
|
289
|
+
const server = createServerContext();
|
|
290
|
+
const tools = createPromotionTools({ getCtx: () => server });
|
|
291
|
+
for (const tool of [tools.getActivityDetail, tools.listActivitySessions, tools.getParticipationGuide]) {
|
|
292
|
+
const result = await tool.execute!({ keyword: '这个活动' } as never, createToolExecContext(testRequestContext()) as never);
|
|
293
|
+
expect(result).toMatchObject({ found: false, needsSelection: true });
|
|
294
|
+
expect(result).not.toHaveProperty('cards');
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
|
|
288
298
|
it('活动工具在专属策略下先分流,不依赖 promotion service 解析', async () => {
|
|
289
299
|
const ctx = createServerContext();
|
|
290
300
|
const alipayActivityHandler = {
|
|
@@ -400,6 +410,32 @@ describe('promotion 确定性意图路由', () => {
|
|
|
400
410
|
},
|
|
401
411
|
);
|
|
402
412
|
|
|
413
|
+
it.each([false, true])('卡包入口在空券和有券时随同一张权益卡返回(有券=%s)', async (hasCoupon) => {
|
|
414
|
+
const service = new InMemoryPromotionService();
|
|
415
|
+
if (hasCoupon) {
|
|
416
|
+
await service.acquire(q, { offerRef: 'demo:coupon:1001', externalMemberRef: 'm', idempotencyKey: 'wallet' });
|
|
417
|
+
}
|
|
418
|
+
const page = await service.listEntitlements(q, {});
|
|
419
|
+
vi.spyOn(service, 'listEntitlements').mockResolvedValue({ ...page, showAlipayWallet: true });
|
|
420
|
+
const search = vi.spyOn(service, 'searchOffers');
|
|
421
|
+
mockAllSlotsPersist(service);
|
|
422
|
+
const ctx = createPromotionTestContext();
|
|
423
|
+
const req = testRequestContext();
|
|
424
|
+
const exec = createToolExecContext(req) as never;
|
|
425
|
+
const tools = createPromotionTools({ getCtx: () => ctx });
|
|
426
|
+
expect(matchIntent(PROMOTION_TEST_ROUTES, '我有什么卡券')?.handlerId).toBe('promotion');
|
|
427
|
+
const expected = { cards: [{ cardType: 'promotion-entitlement-list', data: {
|
|
428
|
+
items: hasCoupon ? [expect.objectContaining({ title: '满 100 减 20 元券' })] : [],
|
|
429
|
+
showAlipayWallet: true,
|
|
430
|
+
} }] };
|
|
431
|
+
const direct = await createPromotionIntentHandler(ctx).handle('intent', { content: '我有什么卡券' }, ctx, req);
|
|
432
|
+
expect(direct).toMatchObject(expected);
|
|
433
|
+
expect(direct.text).toContain('支付宝卡包');
|
|
434
|
+
expect(await tools.listEntitlements.execute!({} as never, exec)).toMatchObject(expected);
|
|
435
|
+
expect(await tools.listCoupons.execute!({ mode: 'OWNED' } as never, exec)).toMatchObject(expected);
|
|
436
|
+
expect(search).not.toHaveBeenCalled();
|
|
437
|
+
});
|
|
438
|
+
|
|
403
439
|
it('“有什么优惠可以领取”直达可领取券列表,不查询已领取券包', async () => {
|
|
404
440
|
const service = new InMemoryPromotionService();
|
|
405
441
|
const listEntitlements = vi.spyOn(service, 'listEntitlements');
|