@tbox.cn/app-module-promotion 0.10.8 → 1.0.0-alpha.10
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/AGENTS.md +3 -3
- package/README.md +4 -0
- package/dist/{chunk-ONDEOXMY.js → chunk-5GWOZC6X.js} +17 -5
- package/dist/chunk-OCTPGK3E.js +1340 -0
- package/dist/client/index.d.ts +1 -0
- package/dist/client/index.js +1 -1
- package/dist/index.js +2 -2
- package/dist/server/index.d.ts +260 -260
- package/dist/server/index.js +1 -1
- package/package.json +12 -9
- package/skills/promotion/SKILL.md +5 -15
- package/src/client/cards/promotion-activity-category-list/index.tsx +14 -10
- package/src/client/cards/promotion-activity-detail/index.tsx +42 -30
- package/src/client/cards/promotion-activity-list/index.tsx +16 -12
- package/src/client/cards/promotion-best-deal/index.tsx +4 -4
- package/src/client/cards/promotion-entitlement-list/index.tsx +24 -20
- package/src/client/cards/promotion-offer-detail/index.tsx +47 -37
- package/src/client/cards/promotion-offer-list/index.tsx +69 -53
- package/src/client/components/CouponQrCode.tsx +2 -2
- package/src/client/components/CouponSheet.tsx +35 -62
- package/src/client/components/ImageWithFallback.tsx +1 -1
- package/src/client/components/class-names.ts +57 -0
- package/src/client/index.ts +1 -2
- package/src/server/handler.ts +10 -3
- package/src/server/index.ts +15 -2
- package/tbox.module.json +0 -6
- package/tests/activity-visibility.test.ts +54 -0
- package/tests/cards-render.test.tsx +3 -1
- package/tsup.config.ts +0 -5
- package/dist/chunk-HZIEXNVQ.js +0 -1332
- package/dist/promotion-ESTNS7IL.css +0 -2139
- package/src/client/styles/promotion.css +0 -2139
- package/src/client/types/css.d.ts +0 -2
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* promotion 卡片共用的工具类字面量(迁移自原模块样式表的 `.promotion-status` / `.promotion-chip*` 族)。
|
|
3
|
+
*
|
|
4
|
+
* 为什么集中在这里:状态徽章与动作 chip 由 4 张卡复用同一副骨架,而 Tailwind 只认完整字面量
|
|
5
|
+
* (禁 `bg-${x}` 拼接)。hook 类(`promotion-status` / `promotion-chip*` 等 BEM)仍写在组件里,
|
|
6
|
+
* 这里只放视觉工具类;色调走 Record 映射(同 MallHome 的 AREA_TONE_CLASS 范式)。
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** `.promotion-status` 骨架(原 font-size 18px / padding 8px 14px) */
|
|
10
|
+
export const PROMOTION_STATUS_CLASS = 'inline-flex flex-none items-center gap-[3px] whitespace-nowrap rounded-full px-[7px] py-1 text-xs font-bold not-italic leading-[normal]';
|
|
11
|
+
|
|
12
|
+
/** `.promotion-status--*` 色调;未知 tone 不落任何色(等价旧 CSS 无匹配修饰符) */
|
|
13
|
+
export const PROMOTION_STATUS_TONE_CLASS: Record<string, string> = {
|
|
14
|
+
available: 'bg-[#eaf8f1] text-[#128356]',
|
|
15
|
+
requires_action: 'bg-[var(--tbox-domain-promotion-surface,#fff1f3)] text-[#a43d25]',
|
|
16
|
+
unavailable: 'bg-[#f0f3f2] text-secondary-foreground',
|
|
17
|
+
unknown: 'bg-[#f0f3f2] text-secondary-foreground',
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* `.promotion-chip` 骨架(原 min-width 104px / height 40px,含 `::after` 箭头)。
|
|
22
|
+
* `[font-family:inherit]` 对应旧 `.promotion-card button { font: inherit }`。
|
|
23
|
+
*/
|
|
24
|
+
export const PROMOTION_CHIP_CLASS = 'inline-flex h-5 w-auto min-w-[52px] cursor-pointer items-center justify-center rounded-full border border-[#d9e0ea] bg-[#f4f8ff] px-[7px] text-xs font-bold leading-none text-[#2368ec] [font-family:inherit] transition-[border-color,color,background-color] duration-[160ms] ease-[ease] after:ml-1 after:content-[\'→\'] after:text-xs after:leading-none hover:not-disabled:border-[#2368ec] hover:not-disabled:bg-[#2368ec] hover:not-disabled:text-white hover:not-disabled:shadow-[0_3px_8px_rgba(35,104,236,0.18)] focus-visible:outline-3 focus-visible:outline-offset-2 focus-visible:outline-[rgba(255,111,31,0.22)] disabled:cursor-not-allowed disabled:opacity-45';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 活动卡内的 chip:`.promotion-activity button:focus-visible`(绿描边、offset 3px)
|
|
28
|
+
* 在旧 CSS 里以 (0,2,1) 压过 `.promotion-chip:focus-visible` (0,2,0),这里写成同一条字面量。
|
|
29
|
+
*/
|
|
30
|
+
export const PROMOTION_CHIP_ACTIVITY_CLASS = 'inline-flex h-5 w-auto min-w-[52px] cursor-pointer items-center justify-center rounded-full border border-[#d9e0ea] bg-[#f4f8ff] px-[7px] text-xs font-bold leading-none text-[#2368ec] [font-family:inherit] transition-[border-color,color,background-color] duration-[160ms] ease-[ease] after:ml-1 after:content-[\'→\'] after:text-xs after:leading-none hover:not-disabled:border-[#2368ec] hover:not-disabled:bg-[#2368ec] hover:not-disabled:text-white hover:not-disabled:shadow-[0_3px_8px_rgba(35,104,236,0.18)] focus-visible:outline-3 focus-visible:outline-offset-3 focus-visible:outline-[#0b8b70] disabled:cursor-not-allowed disabled:opacity-45';
|
|
31
|
+
|
|
32
|
+
/** `.promotion-chip--coupon`(米金实心胶囊,height 64px / min-width 96px) */
|
|
33
|
+
export const PROMOTION_CHIP_COUPON_CLASS = 'inline-flex h-8 w-auto min-w-[48px] cursor-pointer items-center justify-center rounded-full border-0 bg-[linear-gradient(160deg,#c3ad78_0%,#a89058_100%)] px-[7.5px] text-xs font-bold leading-none tracking-[1px] text-white shadow-none [font-family:inherit] after:hidden hover:not-disabled:border-0 hover:not-disabled:bg-[linear-gradient(160deg,#b39d68_0%,#967f4a_100%)] hover:not-disabled:text-white hover:not-disabled:shadow-none focus-visible:outline-none focus-visible:shadow-[inset_0_0_0_3px_#fff,inset_0_0_0_6px_#5f101d] disabled:cursor-not-allowed disabled:opacity-45';
|
|
34
|
+
|
|
35
|
+
/** `.promotion-chip--coupon-lg`(浮层底部主按钮:min-width 240px / height 84px) */
|
|
36
|
+
export const PROMOTION_CHIP_COUPON_LG_CLASS = 'inline-flex h-[42px] w-auto min-w-[120px] cursor-pointer items-center justify-center rounded-full border-0 bg-[linear-gradient(160deg,#c3ad78_0%,#a89058_100%)] px-[7.5px] text-sm font-bold leading-none tracking-[1px] text-white shadow-none [font-family:inherit] after:hidden hover:not-disabled:border-0 hover:not-disabled:bg-[linear-gradient(160deg,#b39d68_0%,#967f4a_100%)] hover:not-disabled:text-white hover:not-disabled:shadow-none focus-visible:outline-none focus-visible:shadow-[inset_0_0_0_3px_#fff,inset_0_0_0_6px_#5f101d] disabled:cursor-not-allowed disabled:opacity-45';
|
|
37
|
+
|
|
38
|
+
/** `.promotion-chip--coupon-off`(不可再用:退成描边灰,压过米金实心) */
|
|
39
|
+
export const PROMOTION_CHIP_COUPON_OFF_CLASS = 'inline-flex h-8 w-auto min-w-[48px] items-center justify-center rounded-full border-0 bg-[#f5f5f7] px-[7.5px] text-xs font-bold leading-none tracking-[1px] text-[rgba(11,15,23,0.45)] shadow-[inset_0_0_0_1px_#e3e4e8] [font-family:inherit] after:hidden hover:not-disabled:bg-[#f5f5f7] hover:not-disabled:text-[rgba(11,15,23,0.45)] hover:not-disabled:shadow-[inset_0_0_0_1px_#e3e4e8] focus-visible:outline-none focus-visible:shadow-[inset_0_0_0_3px_#fff,inset_0_0_0_6px_#5f101d]';
|
|
40
|
+
|
|
41
|
+
/** `.promotion-activity__status`(活动条目/封面上的状态胶囊) */
|
|
42
|
+
export const PROMOTION_ACTIVITY_STATUS_CLASS = 'inline-flex items-center whitespace-nowrap rounded-full border border-[rgba(10,133,103,0.16)] bg-[rgba(235,250,244,0.92)] px-[6px] py-[3.5px] text-xs font-bold leading-3 text-[#08745f] backdrop-blur-[6px]';
|
|
43
|
+
|
|
44
|
+
/** `.promotion-activity__status--*` 色调(AVAILABLE/UNKNOWN 无修饰符,沿用骨架色) */
|
|
45
|
+
export const PROMOTION_ACTIVITY_STATUS_TONE_CLASS: Record<string, string> = {
|
|
46
|
+
full: 'border-[rgba(80,91,87,0.12)] bg-[rgba(245,247,246,0.94)] text-[#687570]',
|
|
47
|
+
ended: 'border-[rgba(80,91,87,0.12)] bg-[rgba(245,247,246,0.94)] text-[#687570]',
|
|
48
|
+
upcoming: 'border-[rgba(184,134,46,0.18)] bg-[rgba(255,246,223,0.94)] text-[#92600e]',
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/** `.promotion-activity__category-icon` 四色编码(index % 4;0 = 基座) */
|
|
52
|
+
export const PROMOTION_CATEGORY_ICON_TONE_CLASS: Record<number, string> = {
|
|
53
|
+
0: 'text-[#08775f] bg-[#dff6ed]',
|
|
54
|
+
1: 'text-[#9b6814] bg-[#fff0cb]',
|
|
55
|
+
2: 'text-[#b44333] bg-[#ffebe7]',
|
|
56
|
+
3: 'text-[#0d7384] bg-[#e1f5f7]',
|
|
57
|
+
};
|
package/src/client/index.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* module-promotion 客户端入口:9 个稳定传输卡型,renderer 内覆盖多个展示语义。
|
|
3
|
+
* 样式:全部规则已迁到卡内 Tailwind 工具类,模块不再携带自持样式表与副作用 import。
|
|
3
4
|
*/
|
|
4
|
-
import './styles/promotion.css'; // 0.4.0 模块自持 CSS(副作用 import,首行保证先行加载)
|
|
5
|
-
|
|
6
5
|
import type { CardComponent } from '@tbox.cn/app-contracts';
|
|
7
6
|
import type { ClientContext, ClientModule } from '@tbox.cn/app-agent-sdk-client';
|
|
8
7
|
import {
|
package/src/server/handler.ts
CHANGED
|
@@ -152,14 +152,19 @@ async function delegateLinkedActivity(
|
|
|
152
152
|
return result.continueWith ? undefined : result;
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
-
export function createPromotionIntentHandler(
|
|
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.
|
|
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) } };
|
package/src/server/index.ts
CHANGED
|
@@ -38,7 +38,20 @@ const getCtx = (): ServerContext => {
|
|
|
38
38
|
return serverCtx;
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
-
|
|
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
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
"id": "module-promotion",
|
|
4
4
|
"name": "营销活动",
|
|
5
5
|
"description": "活动、优惠、权益、套餐查询与券领取,最划算计算",
|
|
6
|
-
"version": "0.10.1",
|
|
7
6
|
"hidden": true,
|
|
8
7
|
"kind": "business",
|
|
9
8
|
"risk": {
|
|
@@ -27,11 +26,6 @@
|
|
|
27
26
|
"promotion"
|
|
28
27
|
],
|
|
29
28
|
"tools": [
|
|
30
|
-
"listActivityCategories",
|
|
31
|
-
"listActivities",
|
|
32
|
-
"getActivityDetail",
|
|
33
|
-
"listActivitySessions",
|
|
34
|
-
"getActivityGuide",
|
|
35
29
|
"searchOffers",
|
|
36
30
|
"getOfferDetail",
|
|
37
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
|
+
});
|
|
@@ -433,7 +433,9 @@ describe('优惠券链路视觉状态语义', () => {
|
|
|
433
433
|
const sheet = document.querySelector('.promotion-sheet') as HTMLElement;
|
|
434
434
|
const close = sheet.querySelector('[aria-label="关闭详情"]') as HTMLButtonElement;
|
|
435
435
|
act(() => close.click());
|
|
436
|
-
|
|
436
|
+
// 关闭态由弹层内核的 data-state 表达(退出动画期间仍挂载,但已不是对话框)
|
|
437
|
+
expect(sheet.getAttribute('data-state')).toBe('closed');
|
|
438
|
+
expect(document.querySelector('[role="dialog"]')).toBeNull();
|
|
437
439
|
expect(document.querySelector('.promotion-sheet')).not.toBeNull();
|
|
438
440
|
act(() => sheet.dispatchEvent(new Event('animationend', { bubbles: true })));
|
|
439
441
|
expect(document.querySelector('.promotion-sheet')).toBeNull();
|
package/tsup.config.ts
CHANGED
|
@@ -27,11 +27,6 @@ export default defineConfig({
|
|
|
27
27
|
'express',
|
|
28
28
|
'@phosphor-icons/react',
|
|
29
29
|
],
|
|
30
|
-
// 0.3.2/0.4.0 D1:模块自持 CSS 出货链。
|
|
31
|
-
// 顶层 loader 写法(实测:esbuildOptions 内设 loader 被 tsup 覆盖失效——CSS 提取断链静默丢失)。
|
|
32
|
-
loader: {
|
|
33
|
-
'.css': 'copy',
|
|
34
|
-
},
|
|
35
30
|
esbuildOptions(options) {
|
|
36
31
|
options.jsx = 'automatic';
|
|
37
32
|
},
|