@tbox.cn/app-module-promotion 1.0.0-alpha.12 → 1.0.0-alpha.14
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/INTEGRATION.md +1 -0
- package/dist/{chunk-5GWOZC6X.js → chunk-2S7WUHX4.js} +225 -81
- package/dist/chunk-HK4U3I7K.js +1547 -0
- package/dist/client/index.d.ts +2 -0
- package/dist/client/index.js +1 -1
- package/dist/index.js +2 -2
- package/dist/server/index.d.ts +376 -263
- package/dist/server/index.js +1 -1
- package/package.json +6 -6
- package/src/client/cards/index.ts +1 -0
- package/src/client/cards/promotion-deal-recall/index.tsx +60 -0
- package/src/client/cards/promotion-entitlement-list/index.tsx +10 -30
- package/src/client/cards/promotion-offer-list/NearbyDealsPanel.tsx +120 -0
- package/src/client/cards/promotion-offer-list/index.tsx +57 -68
- package/src/client/components/CouponListRow.tsx +51 -0
- package/src/client/components/CouponListToggle.tsx +22 -0
- package/src/client/components/use-coupon-list-expansion.ts +41 -0
- package/src/client/index.ts +2 -0
- package/src/deal-recall-card.ts +17 -0
- package/src/server/cards/index.ts +2 -0
- package/src/server/cards/promotion-deal-recall/meta.ts +16 -0
- package/src/server/deal-recall-tools.ts +70 -0
- package/src/server/handler.ts +10 -3
- package/src/server/index.ts +36 -1
- package/src/server/tools.ts +10 -3
- package/tbox.module.json +14 -1
- package/tests/cards-render.test.tsx +152 -3
- package/tests/promotion.test.ts +23 -0
- package/dist/chunk-OCTPGK3E.js +0 -1340
package/INTEGRATION.md
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
- **四槽全必选**:promotion.offers / promotion.entitlements / promotion.activities /
|
|
9
9
|
promotion.acquisition(`optional:false`)——同一后端四槽共享一个 provider 名。
|
|
10
|
+
- **外部团购召回** `promotion.deal-recall` 是独立的可选只读槽,提供附近商品和已映射门店两类查询。启用后,「今日优惠」默认通过鉴权后的 `POST /api/m/promotion/nearby-deals` 查询神券,原有商场优惠显示在第二个页签。继续召回时通过 `excludedDealIds` 提交已显示的商品 ID。
|
|
10
11
|
- **读→写顺序**:领取写链(acquisition.acquire)入参 `offerRef` 由 offers 槽搜索/详情下发;
|
|
11
12
|
领取成功后模块经 entitlements 槽拉券包(最终一致性容忍:150ms×3 重试)——你的后端
|
|
12
13
|
领取写入后券列表应尽快可见。
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// src/server/index.ts
|
|
2
2
|
import { definePreTool, getRequestContext, loadModuleSkills } from "@tbox.cn/app-agent-sdk-server";
|
|
3
3
|
import { Router } from "express";
|
|
4
|
-
import {
|
|
4
|
+
import { z as z5 } from "zod";
|
|
5
|
+
import { PROMOTION_DEAL_RECALL_SERVICE as PROMOTION_DEAL_RECALL_SERVICE2, toMallQueryContext as toMallQueryContext4, withMallScopeFromQuery } from "@tbox.cn/app-contracts-mall";
|
|
5
6
|
|
|
6
7
|
// src/server/ports.ts
|
|
7
8
|
import {
|
|
@@ -514,11 +515,111 @@ var meta7 = {
|
|
|
514
515
|
};
|
|
515
516
|
var meta_default7 = meta7;
|
|
516
517
|
|
|
518
|
+
// src/deal-recall-card.ts
|
|
519
|
+
import { z } from "zod";
|
|
520
|
+
var dealRecallCardSchema = z.object({
|
|
521
|
+
title: z.string(),
|
|
522
|
+
partial: z.boolean().optional(),
|
|
523
|
+
items: z.array(z.object({
|
|
524
|
+
id: z.string(),
|
|
525
|
+
kind: z.enum(["item", "shop"]),
|
|
526
|
+
title: z.string(),
|
|
527
|
+
subtitle: z.string().optional(),
|
|
528
|
+
imageUrl: z.string().max(2048).startsWith("https://").optional(),
|
|
529
|
+
price: z.string().optional(),
|
|
530
|
+
url: z.string().max(2048).startsWith("alipays://platformapi/startapp?").optional()
|
|
531
|
+
})).min(1).max(6)
|
|
532
|
+
});
|
|
533
|
+
|
|
534
|
+
// src/server/cards/promotion-deal-recall/meta.ts
|
|
535
|
+
var meta8 = {
|
|
536
|
+
cardType: "promotion-deal-recall",
|
|
537
|
+
schemaVersion: 1,
|
|
538
|
+
displayName: "\u56E2\u8D2D\u63A8\u8350",
|
|
539
|
+
description: "\u9644\u8FD1\u7684\u56E2\u8D2D\u5546\u54C1\u6216\u6307\u5B9A\u95E8\u5E97\u7684\u56E2\u8D2D\u5217\u8868",
|
|
540
|
+
dataSchema: dealRecallCardSchema,
|
|
541
|
+
sampleData: {
|
|
542
|
+
title: "\u9644\u8FD1\u56E2\u8D2D",
|
|
543
|
+
items: [{ id: "item:demo", kind: "item", title: "\u53CC\u4EBA\u4E0B\u5348\u8336", subtitle: "\u793A\u4F8B\u95E8\u5E97", price: "\xA529.90" }]
|
|
544
|
+
}
|
|
545
|
+
};
|
|
546
|
+
var meta_default8 = meta8;
|
|
547
|
+
|
|
548
|
+
// src/server/deal-recall-tools.ts
|
|
549
|
+
import { isExpectedProviderAbsence as isExpectedProviderAbsence2 } from "@tbox.cn/app-contracts";
|
|
550
|
+
import { mallScopeOf as mallScopeOf2, PROMOTION_DEAL_RECALL_SERVICE } from "@tbox.cn/app-contracts-mall";
|
|
551
|
+
import { createTool, requireToolRequestContext, withCardEmissionHint } from "@tbox.cn/app-agent-sdk-server";
|
|
552
|
+
import { z as z2 } from "zod";
|
|
553
|
+
var dealRecallNotices = {
|
|
554
|
+
disabled: "\u5F53\u524D\u5546\u573A\u6682\u672A\u5F00\u901A\u5916\u90E8\u56E2\u8D2D\u63A8\u8350\u3002",
|
|
555
|
+
"login-required": "\u8BF7\u5148\u5728\u652F\u4ED8\u5B9D\u5185\u767B\u5F55\uFF0C\u518D\u67E5\u8BE2\u56E2\u8D2D\u3002",
|
|
556
|
+
"location-required": "\u56E2\u8D2D\u63A8\u8350\u9700\u8981\u57CE\u5E02\u548C\u4F4D\u7F6E\uFF0C\u8BF7\u5728\u652F\u4ED8\u5B9D\u5185\u5141\u8BB8\u5B9A\u4F4D\u540E\u518D\u8BD5\u3002",
|
|
557
|
+
"mall-location-required": "\u6682\u65F6\u65E0\u6CD5\u786E\u8BA4\u5546\u573A\u4F4D\u7F6E\uFF0C\u65E0\u6CD5\u67E5\u8BE2\u9644\u8FD1\u795E\u5238\u3002",
|
|
558
|
+
"shop-unmapped": "\u8FD9\u5BB6\u95E8\u5E97\u6682\u672A\u5F00\u901A\u5B9A\u5411\u56E2\u8D2D\u67E5\u8BE2\uFF0C\u53EF\u4EE5\u95EE\u6211\u9644\u8FD1\u6709\u4EC0\u4E48\u56E2\u8D2D\u3002",
|
|
559
|
+
unavailable: "\u56E2\u8D2D\u670D\u52A1\u6682\u4E0D\u53EF\u7528\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5\u3002"
|
|
560
|
+
};
|
|
561
|
+
async function resolveDealRecallPort(ctx, request) {
|
|
562
|
+
const integrations = ctx.integrations;
|
|
563
|
+
if (!integrations?.raw?.config.services[PROMOTION_DEAL_RECALL_SERVICE]) return;
|
|
564
|
+
try {
|
|
565
|
+
return await integrations.resolveService({
|
|
566
|
+
service: PROMOTION_DEAL_RECALL_SERVICE,
|
|
567
|
+
scope: mallScopeOf2(request),
|
|
568
|
+
request
|
|
569
|
+
});
|
|
570
|
+
} catch (error) {
|
|
571
|
+
if (!isExpectedProviderAbsence2(error)) throw error;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
function createDealRecallTools(getCtx2) {
|
|
575
|
+
const run = async (input, execution) => {
|
|
576
|
+
const reqCtx = requireToolRequestContext(execution);
|
|
577
|
+
try {
|
|
578
|
+
const service = await resolveDealRecallPort(getCtx2(), reqCtx);
|
|
579
|
+
if (!service) return { found: false, message: dealRecallNotices.disabled };
|
|
580
|
+
const result = await service.recall(input);
|
|
581
|
+
if (result.status !== "ok") return { found: false, message: dealRecallNotices[result.status] };
|
|
582
|
+
if (!result.items.length) return { found: false, message: "\u6682\u672A\u627E\u5230\u5339\u914D\u7684\u56E2\u8D2D\uFF0C\u53EF\u4EE5\u6362\u4E2A\u6761\u4EF6\u8BD5\u8BD5\u3002" };
|
|
583
|
+
return {
|
|
584
|
+
found: true,
|
|
585
|
+
count: result.items.length,
|
|
586
|
+
partial: result.partial === true,
|
|
587
|
+
cards: [{
|
|
588
|
+
cardType: "promotion-deal-recall",
|
|
589
|
+
data: { title: input.shopName ? "\u95E8\u5E97\u56E2\u8D2D" : "\u9644\u8FD1\u56E2\u8D2D", items: result.items, partial: result.partial },
|
|
590
|
+
note: `${input.shopName ? "\u6307\u5B9A\u95E8\u5E97" : "\u9644\u8FD1"}\u56E2\u8D2D\u7ED3\u679C ${result.items.length} \u6761`
|
|
591
|
+
}]
|
|
592
|
+
};
|
|
593
|
+
} catch {
|
|
594
|
+
return { found: false, message: dealRecallNotices.unavailable };
|
|
595
|
+
}
|
|
596
|
+
};
|
|
597
|
+
const nearbyInput = z2.object({
|
|
598
|
+
query: z2.string().trim().min(1).max(200),
|
|
599
|
+
search: z2.boolean().optional().describe("\u53EA\u6709\u7528\u6237\u7ED9\u51FA\u5177\u4F53\u5546\u54C1\u6216\u54C1\u7C7B\u6761\u4EF6\u65F6\u8BBE\u4E3A true\uFF1B\u6CDB\u63A8\u8350\u65F6\u53EF\u7701\u7565\u3002")
|
|
600
|
+
});
|
|
601
|
+
const shopInput = z2.object({ shopName: z2.string().trim().min(1).max(80) });
|
|
602
|
+
return {
|
|
603
|
+
recallNearbyDeals: withCardEmissionHint(createTool({
|
|
604
|
+
id: "recallNearbyDeals",
|
|
605
|
+
description: "\u67E5\u8BE2\u9644\u8FD1\u53EF\u8DF3\u8F6C\u5B98\u65B9\u9875\u67E5\u770B\u7684\u5916\u90E8\u56E2\u8D2D\u5957\u9910\u3002\u53EA\u8FD4\u56DE\u63A8\u8350\uFF0C\u53EF\u7528\u4E8E\u7528\u6237\u660E\u786E\u8BF7\u6C42\u5916\u90E8\u56E2\u8D2D\u7684\u573A\u666F\u3002",
|
|
606
|
+
inputSchema: nearbyInput,
|
|
607
|
+
execute: (input, execution) => run(nearbyInput.parse(input), execution)
|
|
608
|
+
})),
|
|
609
|
+
recallShopDeals: withCardEmissionHint(createTool({
|
|
610
|
+
id: "recallShopDeals",
|
|
611
|
+
description: "\u67E5\u8BE2\u7528\u6237\u6307\u5B9A\u95E8\u5E97\u7684\u5916\u90E8\u56E2\u8D2D\u5957\u9910\u3002\u4F7F\u7528\u95E8\u5E97\u540D\u79F0\uFF0C\u670D\u52A1\u7AEF\u6821\u9A8C\u95E8\u5E97\u6620\u5C04\u3002",
|
|
612
|
+
inputSchema: shopInput,
|
|
613
|
+
execute: (input, execution) => run({ query: "", ...shopInput.parse(input) }, execution)
|
|
614
|
+
}))
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
|
|
517
618
|
// src/server/tools.ts
|
|
518
|
-
import { createTool, coerceStringifiedFields, withCardEmissionHint } from "@tbox.cn/app-agent-sdk-server";
|
|
519
|
-
import { requireToolRequestContext } from "@tbox.cn/app-agent-sdk-server";
|
|
619
|
+
import { createTool as createTool2, coerceStringifiedFields, withCardEmissionHint as withCardEmissionHint2 } from "@tbox.cn/app-agent-sdk-server";
|
|
620
|
+
import { requireToolRequestContext as requireToolRequestContext2 } from "@tbox.cn/app-agent-sdk-server";
|
|
520
621
|
import { resolveMemberGate, toMallQueryContext } from "@tbox.cn/app-contracts-mall";
|
|
521
|
-
import { z } from "zod";
|
|
622
|
+
import { z as z3 } from "zod";
|
|
522
623
|
|
|
523
624
|
// src/server/navigation.ts
|
|
524
625
|
var promotionNavigationQuery = {
|
|
@@ -539,7 +640,7 @@ function parsePromotionNavigationQuery(text) {
|
|
|
539
640
|
|
|
540
641
|
// src/server/tools.ts
|
|
541
642
|
function coerce(schema) {
|
|
542
|
-
return
|
|
643
|
+
return z3.preprocess(coerceStringifiedFields, schema);
|
|
543
644
|
}
|
|
544
645
|
function toQueryContext(reqCtx) {
|
|
545
646
|
return { q: toMallQueryContext(reqCtx), reqCtx };
|
|
@@ -759,16 +860,16 @@ function activityDetail(detail, presentation = "detail") {
|
|
|
759
860
|
};
|
|
760
861
|
}
|
|
761
862
|
var searchInput = coerce(
|
|
762
|
-
|
|
763
|
-
keyword:
|
|
764
|
-
scene:
|
|
765
|
-
cursor:
|
|
766
|
-
limit:
|
|
863
|
+
z3.object({
|
|
864
|
+
keyword: z3.string().optional(),
|
|
865
|
+
scene: z3.string().optional(),
|
|
866
|
+
cursor: z3.string().optional(),
|
|
867
|
+
limit: z3.string().optional()
|
|
767
868
|
})
|
|
768
869
|
);
|
|
769
|
-
var detailInput = coerce(
|
|
870
|
+
var detailInput = coerce(z3.object({ offerRef: z3.string().optional(), keyword: z3.string().optional() }));
|
|
770
871
|
var activityDetailInput = coerce(
|
|
771
|
-
|
|
872
|
+
z3.object({ activityRef: z3.string().optional(), keyword: z3.string().optional() })
|
|
772
873
|
);
|
|
773
874
|
function createPromotionTools(opts) {
|
|
774
875
|
const delegateLinkedActivity2 = async (reqCtx) => {
|
|
@@ -780,7 +881,7 @@ function createPromotionTools(opts) {
|
|
|
780
881
|
};
|
|
781
882
|
const requireService = async (execCtx, resolve) => {
|
|
782
883
|
const ctx = opts.getCtx();
|
|
783
|
-
const reqCtx =
|
|
884
|
+
const reqCtx = requireToolRequestContext2(execCtx);
|
|
784
885
|
const context = toQueryContext(reqCtx);
|
|
785
886
|
return { service: await resolve(context.reqCtx, ctx), q: context.q, reqCtx: context.reqCtx };
|
|
786
887
|
};
|
|
@@ -835,12 +936,12 @@ function createPromotionTools(opts) {
|
|
|
835
936
|
...page.items.length === 0 ? { noResultsReason: "\u8FD8\u6CA1\u6709\u4F18\u60E0\u5238\uFF0C\u53EF\u8BA9\u6211\u5E2E\u4F60\u627E\u627E\u53EF\u9886\u4F18\u60E0" } : {}
|
|
836
937
|
};
|
|
837
938
|
};
|
|
838
|
-
const listActivityCategories =
|
|
939
|
+
const listActivityCategories = createTool2({
|
|
839
940
|
id: "listActivityCategories",
|
|
840
941
|
description: "\u67E5\u8BE2\u5F53\u524D\u5546\u573A\u5168\u90E8\u6D3B\u52A8\u5206\u7C7B\uFF0C\u7528\u4E8E\u4EB2\u5B50\u3001\u5E02\u96C6\u3001\u7F8E\u98DF\u7B49\u6D3B\u52A8\u7B5B\u9009\u3002",
|
|
841
|
-
inputSchema: coerce(
|
|
942
|
+
inputSchema: coerce(z3.object({})),
|
|
842
943
|
execute: async (_args, execCtx) => {
|
|
843
|
-
const reqCtx =
|
|
944
|
+
const reqCtx = requireToolRequestContext2(execCtx, "listActivityCategories");
|
|
844
945
|
const delegated = await delegateLinkedActivity2(reqCtx);
|
|
845
946
|
if (delegated) return delegated;
|
|
846
947
|
const { service } = await requireService(execCtx, resolvePromotionActivitiesPort);
|
|
@@ -861,23 +962,23 @@ function createPromotionTools(opts) {
|
|
|
861
962
|
return items.length ? withCards(facts, "promotion-activity-category-list", `\u6D3B\u52A8\u5206\u7C7B ${items.length} \u4E2A${items[0] ? ` \xB7 \u542B${items[0].name}` : ""}`) : facts;
|
|
862
963
|
}
|
|
863
964
|
});
|
|
864
|
-
const listActivities =
|
|
965
|
+
const listActivities = createTool2({
|
|
865
966
|
id: "listActivities",
|
|
866
967
|
description: "\u6309\u5206\u7C7B\u3001\u5173\u952E\u8BCD\u3001\u5F53\u524D/\u5F80\u671F\u3001\u62A5\u540D\u8981\u6C42\u548C\u65E5\u671F\u8303\u56F4\u67E5\u8BE2\u5546\u573A\u6D3B\u52A8\uFF1B\u67E5\u8BE2\u672C\u5468\u6D3B\u52A8\u65F6\u4F20\u672C\u5468\u65E5\u671F\u8303\u56F4\u3002",
|
|
867
968
|
inputSchema: coerce(
|
|
868
|
-
|
|
869
|
-
categoryId:
|
|
870
|
-
keyword:
|
|
871
|
-
dataScope:
|
|
872
|
-
registrationRequired:
|
|
873
|
-
startsAfter:
|
|
874
|
-
endsBefore:
|
|
875
|
-
cursor:
|
|
876
|
-
limit:
|
|
969
|
+
z3.object({
|
|
970
|
+
categoryId: z3.string().optional(),
|
|
971
|
+
keyword: z3.string().optional(),
|
|
972
|
+
dataScope: z3.enum(["CURRENT", "HISTORY"]).optional(),
|
|
973
|
+
registrationRequired: z3.string().optional(),
|
|
974
|
+
startsAfter: z3.string().optional(),
|
|
975
|
+
endsBefore: z3.string().optional(),
|
|
976
|
+
cursor: z3.string().optional(),
|
|
977
|
+
limit: z3.string().optional()
|
|
877
978
|
})
|
|
878
979
|
),
|
|
879
980
|
execute: async (args, execCtx) => {
|
|
880
|
-
const reqCtx =
|
|
981
|
+
const reqCtx = requireToolRequestContext2(execCtx, "listActivities");
|
|
881
982
|
const delegated = await delegateLinkedActivity2(reqCtx);
|
|
882
983
|
if (delegated) return delegated;
|
|
883
984
|
const { service, q } = await requireService(execCtx, resolvePromotionActivitiesPort);
|
|
@@ -904,12 +1005,12 @@ function createPromotionTools(opts) {
|
|
|
904
1005
|
return page.items.length ? withCards(facts, "promotion-activity-list", `\u5546\u573A\u6D3B\u52A8 ${page.items.length} \u573A${page.items[0] ? ` \xB7 ${page.items[0].title}` : ""}`) : facts;
|
|
905
1006
|
}
|
|
906
1007
|
});
|
|
907
|
-
const getActivityDetail =
|
|
1008
|
+
const getActivityDetail = createTool2({
|
|
908
1009
|
id: "getActivityDetail",
|
|
909
1010
|
description: "\u67E5\u8BE2\u6307\u5B9A\u6D3B\u52A8\u8BE6\u60C5\u3001\u65F6\u95F4\u3001\u540D\u989D\u548C\u53C2\u4E0E\u6761\u4EF6\u3002",
|
|
910
1011
|
inputSchema: activityDetailInput,
|
|
911
1012
|
execute: async (args, execCtx) => {
|
|
912
|
-
const reqCtx =
|
|
1013
|
+
const reqCtx = requireToolRequestContext2(execCtx, "getActivityDetail");
|
|
913
1014
|
const delegated = await delegateLinkedActivity2(reqCtx);
|
|
914
1015
|
if (delegated) return delegated;
|
|
915
1016
|
const { service, q } = await requireService(execCtx, resolvePromotionActivitiesPort);
|
|
@@ -919,12 +1020,12 @@ function createPromotionTools(opts) {
|
|
|
919
1020
|
return withCards(facts, "promotion-activity-detail", `\u6D3B\u52A8\u8BE6\u60C5\uFF1A${detail.title}`);
|
|
920
1021
|
}
|
|
921
1022
|
});
|
|
922
|
-
const listActivitySessions =
|
|
1023
|
+
const listActivitySessions = createTool2({
|
|
923
1024
|
id: "listActivitySessions",
|
|
924
1025
|
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",
|
|
925
1026
|
inputSchema: activityDetailInput,
|
|
926
1027
|
execute: async (args, execCtx) => {
|
|
927
|
-
const reqCtx =
|
|
1028
|
+
const reqCtx = requireToolRequestContext2(execCtx, "listActivitySessions");
|
|
928
1029
|
const delegated = await delegateLinkedActivity2(reqCtx);
|
|
929
1030
|
if (delegated) return delegated;
|
|
930
1031
|
const { service, q } = await requireService(execCtx, resolvePromotionActivitiesPort);
|
|
@@ -935,12 +1036,12 @@ function createPromotionTools(opts) {
|
|
|
935
1036
|
return withCards(facts, "promotion-activity-detail", `\u6D3B\u52A8\u573A\u6B21\uFF1A${detail.title}`);
|
|
936
1037
|
}
|
|
937
1038
|
});
|
|
938
|
-
const getActivityGuide =
|
|
1039
|
+
const getActivityGuide = createTool2({
|
|
939
1040
|
id: "getActivityGuide",
|
|
940
1041
|
description: "\u67E5\u8BE2\u6307\u5B9A\u6D3B\u52A8\u7684\u62A5\u540D\u6761\u4EF6\u548C\u53C2\u4E0E\u6B65\u9AA4\uFF0C\u4E0D\u6267\u884C\u62A5\u540D\u3002",
|
|
941
1042
|
inputSchema: activityDetailInput,
|
|
942
1043
|
execute: async (args, execCtx) => {
|
|
943
|
-
const reqCtx =
|
|
1044
|
+
const reqCtx = requireToolRequestContext2(execCtx, "getActivityGuide");
|
|
944
1045
|
const delegated = await delegateLinkedActivity2(reqCtx);
|
|
945
1046
|
if (delegated) return delegated;
|
|
946
1047
|
const { service, q } = await requireService(execCtx, resolvePromotionActivitiesPort);
|
|
@@ -950,7 +1051,7 @@ function createPromotionTools(opts) {
|
|
|
950
1051
|
return withCards(facts, "promotion-activity-detail", `\u6D3B\u52A8\u53C2\u4E0E\u65B9\u5F0F\uFF1A${detail.title}`);
|
|
951
1052
|
}
|
|
952
1053
|
});
|
|
953
|
-
const searchOffers =
|
|
1054
|
+
const searchOffers = createTool2({
|
|
954
1055
|
id: "searchOffers",
|
|
955
1056
|
description: "\u641C\u7D22\u5F53\u524D\u5546\u573A\u4F18\u60E0\u3001\u6298\u6263\u3001\u56E2\u8D2D\u5E76\u652F\u6301\u5206\u9875\u3002",
|
|
956
1057
|
inputSchema: searchInput,
|
|
@@ -967,11 +1068,11 @@ function createPromotionTools(opts) {
|
|
|
967
1068
|
return page.items.length ? withCards(facts, "promotion-offer-list", `\u4F18\u60E0\u641C\u7D22 ${page.items.length} \u6761${page.items[0] ? ` \xB7 ${page.items[0].title}` : ""}`) : facts;
|
|
968
1069
|
}
|
|
969
1070
|
});
|
|
970
|
-
const getOfferDetail =
|
|
1071
|
+
const getOfferDetail = createTool2({
|
|
971
1072
|
id: "getOfferDetail",
|
|
972
1073
|
description: "\u67E5\u8BE2\u901A\u7528\u4F18\u60E0\u8BE6\u60C5\u5361\uFF08\u89C4\u5219\u3001\u95E8\u69DB\u3001\u6709\u6548\u671F\u53CA\u9886\u53D6\u72B6\u6001\uFF09\uFF0C\u652F\u6301 offerRef\u3001entitlementRef \u6216\u5173\u952E\u8BCD\u53CD\u67E5\u3002",
|
|
973
1074
|
inputSchema: coerce(
|
|
974
|
-
|
|
1075
|
+
z3.object({ offerRef: z3.string().optional(), entitlementRef: z3.string().optional(), keyword: z3.string().optional() })
|
|
975
1076
|
),
|
|
976
1077
|
execute: async (args, execCtx) => {
|
|
977
1078
|
const { service, q, reqCtx } = await requireService(execCtx, resolvePromotionOffersPort);
|
|
@@ -996,7 +1097,7 @@ function createPromotionTools(opts) {
|
|
|
996
1097
|
return withCards(facts, "promotion-offer-detail", `\u4F18\u60E0\u8BE6\u60C5\uFF1A${offer.title}`);
|
|
997
1098
|
}
|
|
998
1099
|
});
|
|
999
|
-
const listEntitlements =
|
|
1100
|
+
const listEntitlements = createTool2({
|
|
1000
1101
|
id: "listEntitlements",
|
|
1001
1102
|
description: "\u4EC5\u67E5\u8BE2\u5F53\u524D\u767B\u5F55\u4F1A\u5458\u5DF2\u7ECF\u9886\u53D6/\u62E5\u6709\u7684\u4F18\u60E0\u6743\u76CA\u548C\u5238\u5305\uFF1B\u7528\u6237\u95EE\u201C\u6709\u4EC0\u4E48\u53EF\u9886\u53D6/\u53EF\u9886\u4F18\u60E0\u5238\u201D\u65F6\u7981\u6B62\u8C03\u7528\uFF0C\u6539\u7528 listCoupons(mode=CLAIMABLE)\u3002\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",
|
|
1002
1103
|
inputSchema: searchInput,
|
|
@@ -1010,7 +1111,7 @@ function createPromotionTools(opts) {
|
|
|
1010
1111
|
) : facts;
|
|
1011
1112
|
}
|
|
1012
1113
|
});
|
|
1013
|
-
const listPromotions =
|
|
1114
|
+
const listPromotions = createTool2({
|
|
1014
1115
|
id: "listPromotions",
|
|
1015
1116
|
description: "\u67E5\u8BE2\u672C\u5468\u8425\u9500\u4E13\u9898\u548C\u4FC3\u9500\u6D3B\u52A8\u3002",
|
|
1016
1117
|
inputSchema: searchInput,
|
|
@@ -1028,7 +1129,7 @@ function createPromotionTools(opts) {
|
|
|
1028
1129
|
return page.items.length ? withCards(facts, "promotion-offer-list", `\u8425\u9500\u4E13\u9898 ${page.items.length} \u4E2A${page.items[0] ? ` \xB7 ${page.items[0].title}` : ""}`) : facts;
|
|
1029
1130
|
}
|
|
1030
1131
|
});
|
|
1031
|
-
const getPromotionDetail =
|
|
1132
|
+
const getPromotionDetail = createTool2({
|
|
1032
1133
|
id: "getPromotionDetail",
|
|
1033
1134
|
description: "\u6309\u8425\u9500\u4E13\u9898\u6807\u8BC6\u6216\u5173\u952E\u8BCD\u7CBE\u786E\u67E5\u8BE2\u6D3B\u52A8\u8BE6\u60C5\u3002",
|
|
1034
1135
|
inputSchema: detailInput,
|
|
@@ -1040,7 +1141,7 @@ function createPromotionTools(opts) {
|
|
|
1040
1141
|
return withCards(facts, "promotion-offer-detail", `\u8425\u9500\u6D3B\u52A8\u8BE6\u60C5\uFF1A${offer.title}`);
|
|
1041
1142
|
}
|
|
1042
1143
|
});
|
|
1043
|
-
const getParticipationGuide =
|
|
1144
|
+
const getParticipationGuide = createTool2({
|
|
1044
1145
|
id: "getParticipationGuide",
|
|
1045
1146
|
description: "\u67E5\u8BE2\u8425\u9500\u4E13\u9898\u7684\u5382\u5546\u53C2\u4E0E\u6B65\u9AA4\uFF0C\u4E0D\u6267\u884C\u62A5\u540D\u6216\u9886\u53D6\u3002",
|
|
1046
1147
|
inputSchema: detailInput,
|
|
@@ -1052,38 +1153,42 @@ function createPromotionTools(opts) {
|
|
|
1052
1153
|
return withCards(facts, "promotion-offer-detail", `\u53C2\u4E0E\u65B9\u5F0F\uFF1A${offer.title}`);
|
|
1053
1154
|
}
|
|
1054
1155
|
});
|
|
1055
|
-
const listCoupons =
|
|
1156
|
+
const listCoupons = createTool2({
|
|
1056
1157
|
id: "listCoupons",
|
|
1057
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",
|
|
1058
1159
|
inputSchema: coerce(
|
|
1059
|
-
|
|
1060
|
-
mode:
|
|
1061
|
-
keyword:
|
|
1062
|
-
cursor:
|
|
1063
|
-
limit:
|
|
1160
|
+
z3.object({
|
|
1161
|
+
mode: z3.enum(["CLAIMABLE", "OWNED"]).default("CLAIMABLE"),
|
|
1162
|
+
keyword: z3.string().optional(),
|
|
1163
|
+
cursor: z3.string().optional(),
|
|
1164
|
+
limit: z3.string().optional()
|
|
1064
1165
|
})
|
|
1065
1166
|
),
|
|
1066
1167
|
execute: async (args, execCtx) => {
|
|
1067
1168
|
if (args.mode === "OWNED") {
|
|
1068
|
-
const { service: service2, q: q2, reqCtx } = await requireService(execCtx, resolvePromotionEntitlementsPort);
|
|
1069
|
-
const facts2 = await entitlementFacts(service2, q2, args,
|
|
1169
|
+
const { service: service2, q: q2, reqCtx: reqCtx2 } = await requireService(execCtx, resolvePromotionEntitlementsPort);
|
|
1170
|
+
const facts2 = await entitlementFacts(service2, q2, args, reqCtx2);
|
|
1070
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;
|
|
1071
1172
|
}
|
|
1072
|
-
const { service, q } = await requireService(execCtx, resolvePromotionOffersPort);
|
|
1073
|
-
const page = await
|
|
1173
|
+
const { service, q, reqCtx } = await requireService(execCtx, resolvePromotionOffersPort);
|
|
1174
|
+
const [page, dealRecall] = await Promise.all([
|
|
1175
|
+
search(service, q, args, ["COUPON"]),
|
|
1176
|
+
resolveDealRecallPort(opts.getCtx(), reqCtx).catch(() => void 0)
|
|
1177
|
+
]);
|
|
1074
1178
|
const items = page.items.filter((item) => item.availability.status === "AVAILABLE");
|
|
1075
1179
|
const facts = {
|
|
1076
1180
|
presentation: "coupon",
|
|
1077
1181
|
mode: "claimable",
|
|
1078
1182
|
summary: "\u53EF\u9886\u53D6\u4F18\u60E0\u5238",
|
|
1183
|
+
...dealRecall?.enabled ? { showDealRecall: true } : {},
|
|
1079
1184
|
items: items.map(offerSummary),
|
|
1080
1185
|
...page.nextCursor ? { nextCursor: page.nextCursor } : {},
|
|
1081
1186
|
...items.length === 0 ? { noResultsReason: "\u5F53\u524D\u5546\u573A\u6682\u672A\u8FD4\u56DE\u53EF\u9886\u4F18\u60E0\u5238" } : {}
|
|
1082
1187
|
};
|
|
1083
|
-
return items.length ? withCards(facts, "promotion-offer-list", `\u53EF\u9886\u4F18\u60E0\u5238 ${items.length} \u5F20${items[0] ? ` \xB7 ${items[0].title}` : ""}`) : facts;
|
|
1188
|
+
return items.length || dealRecall?.enabled ? withCards(facts, "promotion-offer-list", `\u53EF\u9886\u4F18\u60E0\u5238 ${items.length} \u5F20${items[0] ? ` \xB7 ${items[0].title}` : ""}`) : facts;
|
|
1084
1189
|
}
|
|
1085
1190
|
});
|
|
1086
|
-
const getPackageDetail =
|
|
1191
|
+
const getPackageDetail = createTool2({
|
|
1087
1192
|
id: "getPackageDetail",
|
|
1088
1193
|
description: "\u67E5\u8BE2\u7EC4\u5408\u793C\u5305\u53CA\u5176\u5B50\u6743\u76CA\u3002",
|
|
1089
1194
|
inputSchema: detailInput,
|
|
@@ -1098,7 +1203,7 @@ function createPromotionTools(opts) {
|
|
|
1098
1203
|
return withCards(facts, "promotion-offer-detail", `\u4F18\u60E0\u793C\u5305\uFF1A${offer.title}`);
|
|
1099
1204
|
}
|
|
1100
1205
|
});
|
|
1101
|
-
const recommendOffers =
|
|
1206
|
+
const recommendOffers = createTool2({
|
|
1102
1207
|
id: "recommendOffers",
|
|
1103
1208
|
description: "\u6309\u8D44\u683C\u3001\u53EF\u7528\u6027\u4E0E\u9884\u8BA1\u8282\u7701\u989D\u63A8\u8350\u5F53\u524D\u5546\u573A\u4F18\u60E0\u3002",
|
|
1104
1209
|
inputSchema: searchInput,
|
|
@@ -1120,11 +1225,11 @@ function createPromotionTools(opts) {
|
|
|
1120
1225
|
return items.length ? withCards(facts, "promotion-offer-list", `\u63A8\u8350\u4F18\u60E0 ${items.length} \u6761${items[0] ? ` \xB7 ${items[0].title}` : ""}`) : facts;
|
|
1121
1226
|
}
|
|
1122
1227
|
});
|
|
1123
|
-
const calculateBestDeal =
|
|
1228
|
+
const calculateBestDeal = createTool2({
|
|
1124
1229
|
id: "calculateBestDeal",
|
|
1125
1230
|
description: "\u8C03\u7528\u5DF2\u88C5\u914D\u5382\u5546\u80FD\u529B\u8FDB\u884C\u4F18\u60E0\u6D4B\u7B97\uFF1B\u672A\u88C5\u914D\u6D4B\u7B97\u80FD\u529B\u65F6\u4EC5\u8FD4\u56DE\u6587\u5B57\u8BF4\u660E\uFF0C\u4E0D\u51FA\u6D4B\u7B97\u5361\u3002",
|
|
1126
1231
|
inputSchema: coerce(
|
|
1127
|
-
|
|
1232
|
+
z3.object({ currentAmountCents: z3.string(), candidateOfferRefs: z3.array(z3.string()).optional() })
|
|
1128
1233
|
),
|
|
1129
1234
|
execute: async (args, execCtx) => {
|
|
1130
1235
|
const { service, q } = await requireService(execCtx, resolvePromotionOffersPort);
|
|
@@ -1154,28 +1259,28 @@ function createPromotionTools(opts) {
|
|
|
1154
1259
|
}
|
|
1155
1260
|
});
|
|
1156
1261
|
return {
|
|
1157
|
-
listActivityCategories:
|
|
1158
|
-
listActivities:
|
|
1159
|
-
getActivityDetail:
|
|
1160
|
-
listActivitySessions:
|
|
1161
|
-
getActivityGuide:
|
|
1162
|
-
searchOffers:
|
|
1163
|
-
getOfferDetail:
|
|
1164
|
-
listEntitlements:
|
|
1165
|
-
listPromotions:
|
|
1166
|
-
getPromotionDetail:
|
|
1167
|
-
getParticipationGuide:
|
|
1168
|
-
listCoupons:
|
|
1169
|
-
getPackageDetail:
|
|
1170
|
-
recommendOffers:
|
|
1171
|
-
calculateBestDeal:
|
|
1262
|
+
listActivityCategories: withCardEmissionHint2(listActivityCategories),
|
|
1263
|
+
listActivities: withCardEmissionHint2(listActivities),
|
|
1264
|
+
getActivityDetail: withCardEmissionHint2(getActivityDetail),
|
|
1265
|
+
listActivitySessions: withCardEmissionHint2(listActivitySessions),
|
|
1266
|
+
getActivityGuide: withCardEmissionHint2(getActivityGuide),
|
|
1267
|
+
searchOffers: withCardEmissionHint2(searchOffers),
|
|
1268
|
+
getOfferDetail: withCardEmissionHint2(getOfferDetail, { actions: true }),
|
|
1269
|
+
listEntitlements: withCardEmissionHint2(listEntitlements),
|
|
1270
|
+
listPromotions: withCardEmissionHint2(listPromotions),
|
|
1271
|
+
getPromotionDetail: withCardEmissionHint2(getPromotionDetail),
|
|
1272
|
+
getParticipationGuide: withCardEmissionHint2(getParticipationGuide),
|
|
1273
|
+
listCoupons: withCardEmissionHint2(listCoupons, { actions: true }),
|
|
1274
|
+
getPackageDetail: withCardEmissionHint2(getPackageDetail, { actions: true }),
|
|
1275
|
+
recommendOffers: withCardEmissionHint2(recommendOffers),
|
|
1276
|
+
calculateBestDeal: withCardEmissionHint2(calculateBestDeal)
|
|
1172
1277
|
};
|
|
1173
1278
|
}
|
|
1174
1279
|
|
|
1175
1280
|
// src/server/actions.ts
|
|
1176
1281
|
import { randomUUID } from "crypto";
|
|
1177
1282
|
import { memberGateCardOf, externalMemberRefOf, toMallQueryContext as toMallQueryContext2 } from "@tbox.cn/app-contracts-mall";
|
|
1178
|
-
import { z as
|
|
1283
|
+
import { z as z4 } from "zod";
|
|
1179
1284
|
async function listEntitlementsAfterAcquire(service, q) {
|
|
1180
1285
|
for (let attempt = 0; attempt < 3; attempt += 1) {
|
|
1181
1286
|
const page = await service.listEntitlements(q, { limit: 10 });
|
|
@@ -1287,7 +1392,7 @@ function createPromotionActions(ctx) {
|
|
|
1287
1392
|
cardType: "promotion-offer-detail",
|
|
1288
1393
|
label: "\u7ACB\u5373\u9886\u53D6",
|
|
1289
1394
|
singleUse: true,
|
|
1290
|
-
inputSchema:
|
|
1395
|
+
inputSchema: z4.object({ offerRef: z4.string().min(1) }),
|
|
1291
1396
|
execute: executeAcquire
|
|
1292
1397
|
},
|
|
1293
1398
|
// 列表内浮层的领取入口:一张列表卡对应 N 张券,令牌必须可重复使用——
|
|
@@ -1299,7 +1404,7 @@ function createPromotionActions(ctx) {
|
|
|
1299
1404
|
cardType: "promotion-offer-list",
|
|
1300
1405
|
label: "\u9886\u53D6",
|
|
1301
1406
|
singleUse: false,
|
|
1302
|
-
inputSchema:
|
|
1407
|
+
inputSchema: z4.object({ offerRef: z4.string().min(1) }),
|
|
1303
1408
|
execute: executeAcquire
|
|
1304
1409
|
},
|
|
1305
1410
|
// 门店券行领取入口(2026-09-02):couponList 携 offerRef 的券——与优惠列表领取逐字同链路
|
|
@@ -1312,7 +1417,7 @@ function createPromotionActions(ctx) {
|
|
|
1312
1417
|
cardType: "shop-detail",
|
|
1313
1418
|
label: "\u9886\u53D6",
|
|
1314
1419
|
singleUse: false,
|
|
1315
|
-
inputSchema:
|
|
1420
|
+
inputSchema: z4.object({ offerRef: z4.string().min(1) }),
|
|
1316
1421
|
execute: executeAcquire
|
|
1317
1422
|
},
|
|
1318
1423
|
acquireFromShopList: {
|
|
@@ -1321,7 +1426,7 @@ function createPromotionActions(ctx) {
|
|
|
1321
1426
|
cardType: "shop-list",
|
|
1322
1427
|
label: "\u9886\u53D6",
|
|
1323
1428
|
singleUse: false,
|
|
1324
|
-
inputSchema:
|
|
1429
|
+
inputSchema: z4.object({ offerRef: z4.string().min(1) }),
|
|
1325
1430
|
execute: executeAcquire
|
|
1326
1431
|
}
|
|
1327
1432
|
};
|
|
@@ -1563,16 +1668,20 @@ function createPromotionIntentHandler(ctx, { legacyActivities = true } = {}) {
|
|
|
1563
1668
|
}
|
|
1564
1669
|
case "search-coupons": {
|
|
1565
1670
|
const service = await resolvePromotionOffersPort(reqCtx, ctx);
|
|
1566
|
-
const page = await
|
|
1671
|
+
const [page, dealRecall] = await Promise.all([
|
|
1672
|
+
service.searchOffers(q, { offerTypes: ["COUPON"], limit: 50 }),
|
|
1673
|
+
resolveDealRecallPort(ctx, reqCtx).catch(() => void 0)
|
|
1674
|
+
]);
|
|
1567
1675
|
const items = page.items.filter((item) => item.availability.status === "AVAILABLE");
|
|
1568
|
-
if (items.length === 0) return { cards: [], text: "\u5F53\u524D\u5546\u573A\u6682\u672A\u627E\u5230\u53EF\u9886\u53D6\u4F18\u60E0\u5238" };
|
|
1676
|
+
if (items.length === 0 && !dealRecall?.enabled) return { cards: [], text: "\u5F53\u524D\u5546\u573A\u6682\u672A\u627E\u5230\u53EF\u9886\u53D6\u4F18\u60E0\u5238" };
|
|
1569
1677
|
return {
|
|
1570
1678
|
cards: [{ cardType: "promotion-offer-list", data: {
|
|
1571
1679
|
presentation: "coupon",
|
|
1572
1680
|
mode: "claimable",
|
|
1573
|
-
items: items.map(offerSummary)
|
|
1681
|
+
items: items.map(offerSummary),
|
|
1682
|
+
...dealRecall?.enabled ? { showDealRecall: true } : {}
|
|
1574
1683
|
} }],
|
|
1575
|
-
text: `\u4E3A\u4F60\u627E\u5230 ${items.length} \u5F20\u53EF\u9886\u53D6\u4F18\u60E0\u5238`
|
|
1684
|
+
text: dealRecall?.enabled ? dealRecall.offersIntro ?? "\u4ECA\u65E5\u4F18\u60E0\u53EF\u4EE5\u6309\u795E\u5238\u548C\u5546\u573A\u4F18\u60E0\u67E5\u770B\u3002" : `\u4E3A\u4F60\u627E\u5230 ${items.length} \u5F20\u53EF\u9886\u53D6\u4F18\u60E0\u5238`
|
|
1576
1685
|
};
|
|
1577
1686
|
}
|
|
1578
1687
|
case "list-entitlements": {
|
|
@@ -1649,7 +1758,8 @@ var promotionCards = {
|
|
|
1649
1758
|
"promotion-activity-list": meta_default4,
|
|
1650
1759
|
"promotion-activity-detail": meta_default5,
|
|
1651
1760
|
"promotion-activity-category-list": meta_default6,
|
|
1652
|
-
"promotion-best-deal": meta_default7
|
|
1761
|
+
"promotion-best-deal": meta_default7,
|
|
1762
|
+
"promotion-deal-recall": meta_default8
|
|
1653
1763
|
};
|
|
1654
1764
|
|
|
1655
1765
|
// src/server/index.ts
|
|
@@ -1671,12 +1781,18 @@ var tools = {
|
|
|
1671
1781
|
recommendOffers: allTools.recommendOffers,
|
|
1672
1782
|
calculateBestDeal: allTools.calculateBestDeal
|
|
1673
1783
|
};
|
|
1784
|
+
var dealRecallTools = createDealRecallTools(getCtx);
|
|
1785
|
+
var excludedDealIdsSchema = z5.array(z5.string().min(1).max(128)).default([]);
|
|
1674
1786
|
var OWNED_INTENT_RE = /我的券|已领|券包|券码/;
|
|
1787
|
+
var EXTERNAL_DEAL_INTENT_RE = /支付宝神券|外部团购/;
|
|
1675
1788
|
var listCouponsPreTool = definePreTool(tools.listCoupons, {
|
|
1676
1789
|
routing: { mode: "keywords", terms: ["\u4F18\u60E0\u5238", "\u9886\u5238", "\u6709\u4EC0\u4E48\u5238", "\u53EF\u9886"] },
|
|
1677
1790
|
decide: ({ text }) => {
|
|
1678
1791
|
if (!text?.trim()) return { decision: "skip", reason: "\u7A7A\u6587\u672C" };
|
|
1679
1792
|
if (OWNED_INTENT_RE.test(text)) return { decision: "skip", reason: "OWNED \u610F\u56FE\uFF08\u6A21\u578B\u4F20 mode\uFF09" };
|
|
1793
|
+
if (EXTERNAL_DEAL_INTENT_RE.test(text) && serverCtx?.integrations?.raw?.config.services[PROMOTION_DEAL_RECALL_SERVICE2]) {
|
|
1794
|
+
return { decision: "skip", reason: "\u5916\u90E8\u56E2\u8D2D\u610F\u56FE" };
|
|
1795
|
+
}
|
|
1680
1796
|
return { decision: "run", args: { mode: "CLAIMABLE" } };
|
|
1681
1797
|
},
|
|
1682
1798
|
silent: true
|
|
@@ -1691,7 +1807,8 @@ var cards = {
|
|
|
1691
1807
|
"promotion-activity-list": meta_default4,
|
|
1692
1808
|
"promotion-activity-detail": meta_default5,
|
|
1693
1809
|
"promotion-activity-category-list": meta_default6,
|
|
1694
|
-
"promotion-best-deal": meta_default7
|
|
1810
|
+
"promotion-best-deal": meta_default7,
|
|
1811
|
+
"promotion-deal-recall": meta_default8
|
|
1695
1812
|
};
|
|
1696
1813
|
var skills = Object.fromEntries(
|
|
1697
1814
|
(await loadModuleSkills("@tbox.cn/app-module-promotion", import.meta.url)).map((s) => [s.name, s])
|
|
@@ -1709,9 +1826,36 @@ var serverModule = {
|
|
|
1709
1826
|
for (const tool of Object.values(tools)) {
|
|
1710
1827
|
ctx.tools.register(tool);
|
|
1711
1828
|
}
|
|
1829
|
+
if (ctx.integrations?.raw?.config.services[PROMOTION_DEAL_RECALL_SERVICE2]) {
|
|
1830
|
+
for (const tool of Object.values(dealRecallTools)) ctx.tools.register(tool);
|
|
1831
|
+
}
|
|
1712
1832
|
ctx.cards.registerMap(cards);
|
|
1713
1833
|
ctx.handlers.register(createPromotionIntentHandler(ctx, { legacyActivities: false }));
|
|
1714
1834
|
const router = Router();
|
|
1835
|
+
router.post("/nearby-deals", async (req, res) => {
|
|
1836
|
+
const request = getRequestContext(req);
|
|
1837
|
+
res.setHeader("Cache-Control", "no-store");
|
|
1838
|
+
if (!request || request.identity.source === "anonymous") {
|
|
1839
|
+
res.status(401).json({ status: "login-required", message: dealRecallNotices["login-required"] });
|
|
1840
|
+
return;
|
|
1841
|
+
}
|
|
1842
|
+
const excludedDealIds = excludedDealIdsSchema.safeParse(req.body?.excludedDealIds);
|
|
1843
|
+
if (!excludedDealIds.success) {
|
|
1844
|
+
res.status(400).json({ error: "invalid_excluded_deal_ids" });
|
|
1845
|
+
return;
|
|
1846
|
+
}
|
|
1847
|
+
try {
|
|
1848
|
+
const service = await resolveDealRecallPort(ctx, request);
|
|
1849
|
+
const result = service ? await service.recall({
|
|
1850
|
+
query: "\u9644\u8FD1\u6709\u4EC0\u4E48\u56E2\u8D2D",
|
|
1851
|
+
limit: 20,
|
|
1852
|
+
excludedDealIds: excludedDealIds.data
|
|
1853
|
+
}) : { status: "disabled" };
|
|
1854
|
+
res.json(result.status === "ok" ? result : { status: result.status, message: dealRecallNotices[result.status] });
|
|
1855
|
+
} catch {
|
|
1856
|
+
res.status(503).json({ status: "unavailable", message: dealRecallNotices.unavailable });
|
|
1857
|
+
}
|
|
1858
|
+
});
|
|
1715
1859
|
router.get("/entitlement-detail", async (req, res) => {
|
|
1716
1860
|
const entitlementRef = typeof req.query["entitlementRef"] === "string" ? req.query["entitlementRef"].trim() : "";
|
|
1717
1861
|
if (!entitlementRef) {
|