@tbox.cn/app-module-promotion 1.0.0-alpha.16 → 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.
@@ -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: "\u8D26\u6237\u6CA1\u6709\u5238\u65F6\u4FDD\u7559\u53BB\u9886\u5238\u7684\u8BED\u4E49\u5F15\u5BFC",
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: [], noResultsReason: "\u8FD8\u6CA1\u6709\u4F18\u60E0\u5238\uFF0C\u5148\u53BB\u770B\u770B\u672C\u5468\u795E\u5238\u5427" }
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: 1
925
+ limit: 2
897
926
  });
898
- return page.items[0] ?? null;
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: 1 });
905
- const first = page.items[0];
906
- return first ? service.getActivityDetail(q, first.activityRef) : null;
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 entitlementFacts = async (service, q, args, reqCtx) => {
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
- const facts = await entitlementFacts(service, q, args, reqCtx);
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
- const facts2 = await entitlementFacts(service2, q2, args, reqCtx2);
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
- if (page.items.length === 0) {
1696
- const offersService = await resolvePromotionOffersPort(reqCtx, ctx);
1697
- const offers = await offersService.searchOffers(q, { offerTypes: ["COUPON"], limit: 50 });
1698
- const items = offers.items.filter((item) => item.availability.status === "AVAILABLE");
1699
- if (items.length > 0) {
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: [], text: "\u4F60\u7684\u5238\u5305\u91CC\u8FD8\u6CA1\u6709\u4F18\u60E0\u5238\uFF0C\u5F53\u524D\u4E5F\u6CA1\u6709\u53EF\u9886\u53D6\u4F18\u60E0" };
1736
+ return { cards: result.cards, text };
1710
1737
  }
1711
- return {
1712
- cards: [
1713
- {
1714
- cardType: "promotion-entitlement-list",
1715
- data: {
1716
- mallId: q.scope.mallId,
1717
- miniAppId: q.scope.miniAppId,
1718
- items: page.items.map(entitlementSummary),
1719
- ...page.nextCursor ? { nextCursor: page.nextCursor } : {}
1720
- }
1721
- }
1722
- ],
1723
- text: `\u4F60\u7684\u5238\u5305\u91CC\u6709 ${page.items.length} \u5F20\u4F18\u60E0\u5238`
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 ? /* @__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: [
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
- ] }) : /* @__PURE__ */ jsx10("div", { ref: listRef, className: `promotion-list__items overflow-hidden px-3.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(
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 = [
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  cards,
3
3
  clientModule
4
- } from "../chunk-HK4U3I7K.js";
4
+ } from "../chunk-NJGYYTGM.js";
5
5
  export {
6
6
  clientModule,
7
7
  cards as promotionClientCards
package/dist/index.js CHANGED
@@ -7,11 +7,11 @@ import {
7
7
  resolvePromotionEntitlementsPort,
8
8
  resolvePromotionOffersPort,
9
9
  serverModule
10
- } from "./chunk-2S7WUHX4.js";
10
+ } from "./chunk-AVRCLENB.js";
11
11
  import {
12
12
  cards,
13
13
  clientModule
14
- } from "./chunk-HK4U3I7K.js";
14
+ } from "./chunk-NJGYYTGM.js";
15
15
  export {
16
16
  InMemoryPromotionService,
17
17
  clientModule,