@tbox.cn/app-module-promotion 1.0.0-alpha.8 → 1.0.0-alpha.9

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.
@@ -7,7 +7,7 @@ import {
7
7
  resolvePromotionEntitlementsPort,
8
8
  resolvePromotionOffersPort,
9
9
  serverModule
10
- } from "../chunk-ONDEOXMY.js";
10
+ } from "../chunk-5GWOZC6X.js";
11
11
  export {
12
12
  InMemoryPromotionService,
13
13
  inMemoryPromotion,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tbox.cn/app-module-promotion",
3
- "version": "1.0.0-alpha.8",
3
+ "version": "1.0.0-alpha.9",
4
4
  "type": "module",
5
5
  "description": "商圈营销模块:资格校验、推荐降级链、券卡(codegen 源)。",
6
6
  "exports": {
@@ -20,10 +20,10 @@
20
20
  "dependencies": {
21
21
  "jsbarcode": "^3.12.3",
22
22
  "qrcode": "^1.5.4",
23
- "@tbox.cn/app-contracts": "1.0.0-alpha.8",
24
- "@tbox.cn/app-agent-sdk-client": "1.0.0-alpha.8",
25
- "@tbox.cn/app-agent-sdk-server": "1.0.0-alpha.8",
26
- "@tbox.cn/app-contracts-mall": "1.0.0-alpha.8"
23
+ "@tbox.cn/app-contracts": "1.0.0-alpha.9",
24
+ "@tbox.cn/app-agent-sdk-server": "1.0.0-alpha.9",
25
+ "@tbox.cn/app-contracts-mall": "1.0.0-alpha.9",
26
+ "@tbox.cn/app-agent-sdk-client": "1.0.0-alpha.9"
27
27
  },
28
28
  "peerDependencies": {
29
29
  "@phosphor-icons/react": "2.1.10",
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: promotion
3
- description: 商圈营销 SOP——优惠券搜索/领取、我的券查询、最优优惠测算、营销活动与场次报名指引的标准流程。
3
+ description: 商圈营销 SOP——优惠券搜索/领取、我的券查询、最优优惠测算、营销专题查询的标准流程。
4
4
  routingTerms:
5
5
  - 领券
6
6
  - 优惠券
@@ -8,8 +8,6 @@ routingTerms:
8
8
  - 券
9
9
  - 折扣
10
10
  - 团购
11
- - 活动
12
- - 市集
13
11
  - 我的券
14
12
  - 券码
15
13
  - 满减
@@ -40,8 +38,6 @@ routingTerms:
40
38
  | 领券 | `listCoupons(mode=CLAIMABLE)`(用户在券行浮层内领取) | `promotion-offer-list` → `promotion-entitlement-list` |
41
39
  | 我的券/已领取/卡包 | `listEntitlements` 或 `listCoupons(mode=OWNED)` | `promotion-entitlement-list` |
42
40
  | 最优优惠测算 | `calculateBestDeal` | `promotion-best-deal` |
43
- | 活动列表/详情/场次/指南 | `listActivities` / `getActivityDetail` / `listActivitySessions` / `getActivityGuide` | 活动系列卡 |
44
- | 活动类型 | `listActivityCategories` | `promotion-activity-category-list` |
45
41
  | 营销专题 | `listPromotions` / `getPromotionDetail` / `getParticipationGuide` | 专题系列卡 |
46
42
 
47
43
  ## 出卡规则
@@ -95,17 +91,11 @@ routingTerms:
95
91
 
96
92
  调 `calculateBestDeal`(需传 `currentAmountCents` 消费金额)。厂商支持时返回确定性最优方案;厂商不支持时只返回文字说明,不得构造 `promotion-best-deal` 旧卡或伪造测算结论。
97
93
 
98
- ### 五:查活动/报名
94
+ ### 五:查询活动
99
95
 
100
- 触发:"商场有什么活动""本周活动""亲子活动""市集""活动怎么报名"。
101
-
102
- - 活动列表 → 调 `listActivities`,查"本周活动"时**必须传本周的 `startsAfter` 与 `endsBefore`**,不得把"当前活动"误当"本周活动";结果非空时**必须**出 `promotion-activity-list` 卡(不得用活动分类卡替代)
103
- - 活动详情 → 调 `getActivityDetail`
104
- - 可选场次 → 调 `listActivitySessions`(只读,不执行报名)
105
- - 参与步骤/报名条件 → 调 `getActivityGuide`
106
- - 用户只问活动有哪些类型 → 调 `listActivityCategories`,出 `promotion-activity-category-list` 卡
107
-
108
- **报名由用户在厂商页面确认**:活动详情卡提供报名入口,**模型不代用户报名**,结果以厂商页面为准。
96
+ 用户问「有什么活动」「活动中心」「查询活动列表」或活动详情时,使用活动玩法域的
97
+ `listActivityPlays` / `getActivityPlayDetail`,不使用优惠搜索或营销专题替代活动查询。
98
+ 活动玩法未装配或查询失败时如实说明,不返回演示活动。
109
99
 
110
100
  ### 六:查营销专题/促销活动
111
101
 
@@ -152,14 +152,19 @@ async function delegateLinkedActivity(
152
152
  return result.continueWith ? undefined : result;
153
153
  }
154
154
 
155
- export function createPromotionIntentHandler(ctx: ServerContext): HandlerDefinition {
155
+ export function createPromotionIntentHandler(
156
+ ctx: ServerContext,
157
+ { legacyActivities = true }: { legacyActivities?: boolean } = {},
158
+ ): HandlerDefinition {
156
159
  return {
157
160
  id: 'promotion',
158
161
  // 顶层意图 = 确定性触发器(exact 整句 + prefix 导航模板头):语义分类职责归
159
162
  // skill 路由与 LLM 工具编排(BM25 单标签 + 硬短路会截断复合句,如「推荐门店+领券」)。
160
163
  // QuickCommands 固定句(现在有什么优惠?/活动中心)随 exact 句面直出。
161
164
  intents: [
162
- ...Object.values(PROMOTION_INTENTS).map(({ patterns }) => ({ patterns: [...patterns], match: 'exact' as const })),
165
+ ...Object.entries(PROMOTION_INTENTS)
166
+ .filter(([id]) => legacyActivities || id !== 'list-activities')
167
+ .map(([, { patterns }]) => ({ patterns: [...patterns], match: 'exact' as const })),
163
168
  {
164
169
  // 卡片导航模板句(「查看「X」…」四式)前缀路由:handler 内
165
170
  // parsePromotionNavigationQuery 模板全等校验承接;未命中模板 → 洋葱放行(resolveIntent null)。
@@ -172,7 +177,9 @@ export function createPromotionIntentHandler(ctx: ServerContext): HandlerDefinit
172
177
  const q = toMallQueryContext(reqCtx);
173
178
 
174
179
  const resolved = resolveAction(action, payload);
175
- if (!resolved) {
180
+ if (!resolved || (!legacyActivities && (
181
+ resolved.kind === 'list-activities' || resolved.kind === 'activity-detail' || resolved.kind === 'activity-category'
182
+ ))) {
176
183
  // 洋葱守卫(洋葱定律 1:未识别 = 失败 = 放行不吞——同 bumpin/member/shopping-guide 惯例):
177
184
  // prefix 误延展或 action 无法分辨时交还 LLM 主路径(preTool/记忆/Skill 照常),不产卡不产兜底文案。
178
185
  return { cards: [], continueWith: { content: intentContent(payload) } };
@@ -38,7 +38,20 @@ const getCtx = (): ServerContext => {
38
38
  return serverCtx;
39
39
  };
40
40
 
41
- const tools = createPromotionTools({ getCtx });
41
+ // 旧活动工具保留在工厂中,仅注册优惠/权益/促销工具。
42
+ const allTools = createPromotionTools({ getCtx });
43
+ const tools = {
44
+ searchOffers: allTools.searchOffers,
45
+ getOfferDetail: allTools.getOfferDetail,
46
+ listEntitlements: allTools.listEntitlements,
47
+ listPromotions: allTools.listPromotions,
48
+ getPromotionDetail: allTools.getPromotionDetail,
49
+ getParticipationGuide: allTools.getParticipationGuide,
50
+ listCoupons: allTools.listCoupons,
51
+ getPackageDetail: allTools.getPackageDetail,
52
+ recommendOffers: allTools.recommendOffers,
53
+ calculateBestDeal: allTools.calculateBestDeal,
54
+ };
42
55
 
43
56
  /**
44
57
  * 可领券问句确定性预执行(2026-09-01):券意图轮零 LLM 预执行出券列表卡。
@@ -98,7 +111,7 @@ export const serverModule = {
98
111
  ctx.tools.register(tool);
99
112
  }
100
113
  ctx.cards.registerMap(cards);
101
- ctx.handlers.register(createPromotionIntentHandler(ctx));
114
+ ctx.handlers.register(createPromotionIntentHandler(ctx, { legacyActivities: false }));
102
115
 
103
116
  // 券码详情弹窗按需调用独立 provider 能力;列表接口只负责券包索引。
104
117
  const router = Router();
package/tbox.module.json CHANGED
@@ -26,11 +26,6 @@
26
26
  "promotion"
27
27
  ],
28
28
  "tools": [
29
- "listActivityCategories",
30
- "listActivities",
31
- "getActivityDetail",
32
- "listActivitySessions",
33
- "getActivityGuide",
34
29
  "searchOffers",
35
30
  "getOfferDetail",
36
31
  "listEntitlements",
@@ -0,0 +1,54 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { createServerContext } from '@tbox.cn/app-agent-sdk-server';
3
+ import { serverModule } from '../src/server/index';
4
+ import { createPromotionTools } from '../src/server/tools';
5
+ const testRequestContext = () => ({
6
+ identity: { userId: 'u_1', source: 'local' as const },
7
+ attributes: { mall: { miniAppId: 'app', mallId: 'mall-1' } },
8
+ });
9
+
10
+ const legacyIds = [
11
+ 'listActivityCategories', 'listActivities', 'getActivityDetail',
12
+ 'listActivitySessions', 'getActivityGuide',
13
+ ];
14
+
15
+ describe('旧活动能力隐藏', () => {
16
+ it('运行时不暴露旧活动工具,保留优惠工具和历史卡 renderer 元数据', () => {
17
+ const ctx = createServerContext();
18
+ serverModule.register(ctx);
19
+ const registered = ctx.tools.getAll();
20
+ for (const id of legacyIds) expect(registered[id]).toBeUndefined();
21
+ expect(Object.keys(registered)).toHaveLength(10);
22
+ expect(registered.listCoupons).toBeDefined();
23
+ expect(registered.listPromotions).toBeDefined();
24
+ expect(serverModule.cards['promotion-activity-list']).toBeDefined();
25
+ const retained = createPromotionTools({ getCtx: () => ctx });
26
+ for (const id of legacyIds) expect(retained[id as keyof typeof retained]).toBeDefined();
27
+ });
28
+
29
+ it('通用活动固定句不再进入旧活动直出路由', () => {
30
+ const ctx = createServerContext();
31
+ serverModule.register(ctx);
32
+ const handler = ctx.handlers.resolve('promotion')!;
33
+ const patterns = handler.intents?.flatMap((intent) => intent.patterns) ?? [];
34
+ expect(patterns).not.toContain('有什么活动');
35
+ expect(patterns).not.toContain('活动中心');
36
+ expect(patterns).toContain('我的券');
37
+ });
38
+
39
+ it.each([
40
+ ['intent', '有什么活动'],
41
+ ['intent', '活动中心'],
42
+ ['intent', '查看「示例活动」的活动详情'],
43
+ ['intent', '查看「亲子」分类的活动'],
44
+ ['list-activities', '查询活动列表'],
45
+ ])('旧入口 %s / %s 放行到模型且不查询演示活动', async (action, content) => {
46
+ const ctx = createServerContext();
47
+ serverModule.register(ctx);
48
+ const result = await ctx.handlers.resolve('promotion')!.handle(
49
+ action, { content }, ctx, testRequestContext(),
50
+ );
51
+ expect(result.cards).toEqual([]);
52
+ expect(result.continueWith?.content).toBe(content);
53
+ });
54
+ });