@tbox.cn/app-module-shopping-guide 0.9.4 → 0.9.6

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.
Files changed (35) hide show
  1. package/AGENTS.md +6 -8
  2. package/INTEGRATION.md +20 -0
  3. package/dist/{chunk-V777N5YK.js → chunk-XRXDTTFY.js} +217 -66
  4. package/dist/index.js +1 -1
  5. package/dist/server/index.d.ts +814 -814
  6. package/dist/server/index.js +1 -1
  7. package/package.json +7 -6
  8. package/src/client/cards/category-list/index.tsx +1 -1
  9. package/src/client/cards/human-guide-list/index.tsx +1 -1
  10. package/src/client/cards/index.ts +1 -1
  11. package/src/client/cards/location-handoff/index.tsx +1 -1
  12. package/src/client/cards/mall-directory/index.tsx +1 -1
  13. package/src/client/cards/nearby-mall-list/index.tsx +1 -1
  14. package/src/client/cards/product-comparison/index.tsx +2 -2
  15. package/src/client/cards/product-detail/index.tsx +1 -1
  16. package/src/client/cards/product-list/index.tsx +1 -1
  17. package/src/client/cards/shop-detail/index.tsx +1 -1
  18. package/src/client/cards/shop-list/index.tsx +1 -1
  19. package/src/client/cards/view.ts +1 -1
  20. package/src/client/components/ImageWithFallback.tsx +1 -1
  21. package/src/client/index.ts +1 -1
  22. package/src/client/types/css.d.ts +1 -1
  23. package/src/server/cards/recommend-merchants/samples.ts +1 -0
  24. package/src/server/cards/shop-detail/meta.ts +4 -3
  25. package/src/server/cards/shop-detail/samples.ts +19 -22
  26. package/src/server/cards/shop-list/meta.ts +138 -2
  27. package/src/server/cards/shop-list/samples.ts +45 -26
  28. package/src/server/domain/value-objects.ts +2 -2
  29. package/src/server/handler.ts +1 -1
  30. package/src/server/index.ts +3 -3
  31. package/src/server/ports/index.ts +3 -3
  32. package/src/server/ports/local-adapters.ts +1 -1
  33. package/src/server/projections/index.ts +4 -4
  34. package/src/server/tools/index.ts +8 -8
  35. package/tests/samples.test.ts +49 -3
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 导购域值对象与运行时上下文(011 S7)。
2
+ * 导购域值对象与运行时上下文。
3
3
  * 域模型类型直接复用 contracts-mall Port 的 record 类型(TIER1 单一来源),
4
4
  * 模块内不重复声明领域形状。
5
5
  *
@@ -30,7 +30,7 @@ export function toShoppingQueryContext(
30
30
  };
31
31
  }
32
32
 
33
- /** 工具入参中的 mall scope 兜底解析(D11 字符串化后仍可能缺失) */
33
+ /** 工具入参中的 mall scope 兜底解析(字符串化后仍可能缺失) */
34
34
  export function scopeFromMallId(
35
35
  requestContext: RequestContext,
36
36
  overrideMallId?: string,
@@ -11,7 +11,7 @@ import { parseMallScope } from '@tbox.cn/app-contracts-mall';
11
11
  import { resolveShoppingGuidePorts } from './ports';
12
12
  import { buildShopListCard, toContext } from './tools';
13
13
 
14
- /** 品牌导览按钮整句(templates/template-agent/profiles/mall/config/chat.json QuickCommands query——exact 全等唯一入口;W4 前在 template-agent-mall) */
14
+ /** 品牌导览按钮整句(templates/template-agent/profiles/mall/config/chat.json QuickCommands query——exact 全等唯一入口; 前在 template-agent-mall) */
15
15
  const BRAND_GUIDE_QUERY = '品牌导览';
16
16
 
17
17
  /** 常驻入口全量页大小:LLM 面 search-shops 工具 pageSize 钳 50(提示词防爆护栏),此通道直调 port 特批 200 */
@@ -1,11 +1,11 @@
1
1
  /**
2
- * module-shopping-guide 服务端入口(011 K1:自注册闭环)。
2
+ * module-shopping-guide 服务端入口(双端自注册闭环——见模块 AGENTS.md 与 INTEGRATION.md)。
3
3
  * - 10 卡声明(key = cardType)+ 工具(6 创建:search-shops/get-shop + 4 内部)+ 四个 silent preTool
4
4
  * (商场上下文 always / 楼层问句 always 正则门控 / 类目问句 keywords 词族 2026-09-03 / 结构概问 keywords)
5
5
  * + 品牌导览 exact 意图 handler(首页常驻按钮零 LLM 直出全量门店卡);
6
6
  * 客服 FAQ/知识库域已拆分至 module-customer-service(2026-08-31);
7
7
  * - register 只注册不解析(resolveShoppingGuidePorts 仅 handle/execute 内调用);
8
- * - 模块级单例:工具实例顶层创建(010 实例一致性),register 幂等。
8
+ * - 模块级单例:工具实例顶层创建,register 幂等。
9
9
  */
10
10
  import type {
11
11
  ServerContext,
@@ -78,7 +78,7 @@ const mallContextPreTool = definePreTool(tools.mallContext, {
78
78
  * - 仅纯楼层浏览问句 run("X楼有什么""X楼呢""X楼逛什么"…);楼层+类目/品牌等额外筛选意图 → skip
79
79
  * (让模型调 search-shops(floorCode + businessCategory) 做精准过滤,preTool 不包揽组合筛选);
80
80
  * - silent:不发前端事件;结果 reminder 注入 + cards 经 capture 入本轮候选池
81
- * (池非空时模型零工具调用也有 P0-A 兜底出卡,promisedNoTool 观测同步归零);
81
+ * (池非空时模型零工具调用也有-A 兜底出卡,promisedNoTool 观测同步归零);
82
82
  * - 楼层引用 → 目录归一解析在工具 execute 内完成(跨 provider floorCode 格式免疫);
83
83
  * - 失败语义 = 无卡 summary(模型经 reminder 看到失败事实,自行降级调用 search-shops)。
84
84
  */
@@ -70,12 +70,12 @@ async function resolveGuideSlot<T>(
70
70
  if (isExpectedProviderAbsence(e)) return fallback;
71
71
  const code = (e as { code?: string }).code;
72
72
  if (code === 'PROVIDER_NOT_IMPLEMENTED') return fallback; // 远程检索为增强面
73
- throw e; // 其余错误上抛(配置即声明,F5 起无探测链回退)
73
+ throw e; // 其余错误上抛(配置即声明, 起无探测链回退)
74
74
  }
75
75
  }
76
76
 
77
77
  /**
78
- * mall-directory 服务消费接口(015 S7:模板注册,deployment.malls 单一来源;
78
+ * mall-directory 服务消费接口(模板注册,deployment.malls 单一来源;
79
79
  * 模块只依赖此结构类型——不进 TIER1 公共契约)。
80
80
  */
81
81
  export interface MallDirectoryService {
@@ -124,7 +124,7 @@ function currentMallId(reqCtx: RequestContext | undefined): string | undefined {
124
124
  }
125
125
 
126
126
  /**
127
- * 011 G3:模块级 connector 缓存(key = mallId;无 mall → 'none')。
127
+ * 模块级 connector 缓存(key = mallId;无 mall → 'none')。
128
128
  * 注意:gateway 含用户态 token,不做全局缓存;仅本地 adapter(navigation)
129
129
  * 以 mallId 为 key 按 TTL 缓存。
130
130
  */
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 导航本地 Port 实现(011 K6):附近商场/浏览历史/位置为本地实现(真实数据源接入点)。
2
+ * 导航本地 Port 实现:附近商场/浏览历史/位置为本地实现(真实数据源接入点)。
3
3
  * FAQ/知识库域已拆分至 module-customer-service(2026-08-31,KnowledgeAssistanceAdapter 迁出)。
4
4
  */
5
5
  import type {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 导购投影层(011 S7):contracts-mall record → 卡数据(zod 校验形状)。
2
+ * 导购投影层:contracts-mall record → 卡数据(zod 校验形状)。
3
3
  * 每卡一个投影函数,工具 execute 调用后包入出参 cards 字段(v2 出卡契约)出卡。
4
4
  */
5
5
  import type {
@@ -27,9 +27,9 @@ import type {
27
27
  import { nowIso } from '../domain/value-objects';
28
28
 
29
29
  /**
30
- * itemActions 填充(015 S5/F1:判别联合 send/link 两变体)。
30
+ * itemActions 填充(/判别联合 send/link 两变体)。
31
31
  * - send:发消息(value 缺省 = label);link:打开 URL(tel:/https:)。
32
- * - 导航 link 用高德分享 URL search 模板(零坐标依赖,POC bridge 导航体系不迁,R5)。
32
+ * - 导航 link 用高德分享 URL search 模板(零坐标依赖,POC bridge 导航体系不迁)。
33
33
  */
34
34
  function amapSearchUrl(keyword: string): string {
35
35
  return `https://uri.amap.com/search?keyword=${encodeURIComponent(keyword)}`;
@@ -272,7 +272,7 @@ export function projectNearbyMalls(
272
272
  address: m.address,
273
273
  ...(m.distanceKm !== undefined ? { distanceKm: m.distanceKm } : {}),
274
274
  status: m.status,
275
- // R6:切商场不进 itemActions(无该变体);「有什么店」话术替代
275
+ // 切商场不进 itemActions(无该变体);「有什么店」话术替代
276
276
  itemActions: [{ kind: 'send', label: `${m.name}有什么店`, value: `${m.name}里有什么店` }],
277
277
  })),
278
278
  };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 导购 15 工具(011 K5:D11 字符串化 inputSchema——仅 string / map<string,string>)。
2
+ * 导购 15 工具(字符串化 inputSchema——仅 string / map<string,string>)。
3
3
  * 全部经 createTool;coerceStringifiedFields 首行转换(JSON 字符串化数值/数组还原)。
4
4
  * 出卡见文件头注释(v2 出参 cards 契约);product-facets 返回分面原始数据、search-knowledge 返回 text 汇总。
5
5
  */
@@ -43,7 +43,7 @@ export type ShoppingGuideToolIds =
43
43
  const str = (desc: string) => z.string().describe(desc);
44
44
  const optionalStr = (desc: string) => z.string().optional().describe(desc);
45
45
 
46
- /** z.preprocess(coerce, schema):D11 字符串化兜底(LLM 传 JSON 字符串/数组) */
46
+ /** z.preprocess(coerce, schema): 字符串化兜底(LLM 传 JSON 字符串/数组) */
47
47
  function coerce<T extends z.ZodTypeAny>(schema: T): T {
48
48
  return z.preprocess(coerceStringifiedFields, schema) as unknown as T;
49
49
  }
@@ -75,7 +75,7 @@ function contextWithMallId(reqCtx: RequestContext, mallId: unknown): ShoppingQue
75
75
  return { ...base, scope: scopeFromMallId(reqCtx, override) };
76
76
  }
77
77
 
78
- // D11:纯字符串字段不做 coerce(coerce 会把 "1" 还原成 number 反破坏 string 期望);
78
+ // 纯字符串字段不做 coerce(coerce 会把 "1" 还原成 number 反破坏 string 期望);
79
79
  // 仅结构字段(keywords/productIds 数组)走 coerce(LLM 可能传 JSON 编码字符串)。
80
80
  const pageFields = {
81
81
  page: z.string().optional().describe('页码(从 1 开始,字符串)'),
@@ -92,7 +92,7 @@ function parsePage(page?: string, pageSize?: string): { page: number; pageSize:
92
92
  const KEYWORD_FANOUT_MAX = 3;
93
93
 
94
94
  /** 出卡出参组装(v2 契约,模式 B):summary 透传完整 JSON 数据 + cards 声明(data = 投影卡数据)。
95
- * W7(2026-09-01):note 参数复活(原 _note 死参数完全丢弃 note → 全部回退 displayName 静态值)——
95
+ * (2026-09-01):note 参数复活(原 _note 死参数完全丢弃 note → 全部回退 displayName 静态值)——
96
96
  * note 是模型可见唯一卡片内容摘要,按契约传「主体+关键事实」。 */
97
97
  function withCards<T extends Record<string, unknown>>(
98
98
  data: T,
@@ -105,7 +105,7 @@ function withCards<T extends Record<string, unknown>>(
105
105
 
106
106
  /**
107
107
  * shop-list 出卡 note(模型可见唯一卡片摘要,search-shops 与 floor-shops 共用单源):
108
- * 店名(楼层)主体前置(至多 3 个——W7,模型凭 descriptor 区分同型候选、答话与卡内容对齐)+
108
+ * 店名(楼层)主体前置(至多 3 个——,模型凭 descriptor 区分同型候选、答话与卡内容对齐)+
109
109
  * 计数恒由 total 派生(密度截断后 items.length 只是可见面,不是全量事实——
110
110
  * 截断发生时以尾缀显式声明,对齐 merchant-list-limit 测试头注释「头部句由 pageInfo.total 派生」)。
111
111
  * 120 字符预算由 SDK buildNote 统一截断,此处只组装内容。
@@ -315,7 +315,7 @@ export function createShoppingGuideTools(opts: {
315
315
  '①将用户意图映射到 mall-context 类目编码(如"买鞋/买衣服"→ categories[].code "购物","吃饭/火锅/甜品"→ "餐饮"),仅传 businessCategory 重查(不加 keywords,让该类目下门店全量返回);' +
316
316
  '②仍无结果改用无参数全量浏览(卡片自带类目 Tab 供用户自行筛选)。' +
317
317
  '同一查询最多调用本工具 2 次(首次 + 1 次降级),禁止反复试参。',
318
- // W2(2026-09-01):机制句(标签语法/出卡规则)归平台段单源——此处由 wrap 追加预告知句,删除【出卡规则】整段
318
+ //(2026-09-01):机制句(标签语法/出卡规则)归平台段单源——此处由 wrap 追加预告知句,删除【出卡规则】整段
319
319
  inputSchema: z.object({
320
320
  keywords: z.preprocess(
321
321
  // LLM 有时输出裸字符串(如 "美妆")而非数组,统一包成数组再走 coerce
@@ -664,10 +664,10 @@ export function createShoppingGuideTools(opts: {
664
664
 
665
665
  // customerServiceFaq:客服承接已拆分至 module-customer-service(2026-08-31)
666
666
 
667
- // W2(2026-09-01):出卡工具创建点单点 wrap(description 追加预告知句)——
667
+ //(2026-09-01):出卡工具创建点单点 wrap(description 追加预告知句)——
668
668
  // 注册与 preTool 声明均使用 wrapped 实例;mall-context/floor-shops 内部工具不 wrap。
669
669
  // B3:四个内部工具 internalTool 原实例标记——Agent 模型面剔除(omitInternal),
670
- // preTool 路径与 D9 实例一致性校验不受影响(标记不换实例)。
670
+ // preTool 路径与 实例一致性校验不受影响(标记不换实例)。
671
671
  return {
672
672
  searchShops: withCardEmissionHint(searchShops),
673
673
  getShop: withCardEmissionHint(getShop),
@@ -13,6 +13,52 @@ import recommendMerchantsMeta from '../src/server/cards/recommend-merchants/meta
13
13
  const metas = [shopListMeta, recommendMerchantsMeta, shopDetailMeta];
14
14
 
15
15
  describe('shopping-guide samples 双断言(样本即契约)', () => {
16
+ it('shop-list 初始态过 schema,覆盖 12 家门店、5 个楼层和两种营业状态', () => {
17
+ expect(shopListMeta.dataSchema.safeParse(shopListMeta.sampleData).success).toBe(true);
18
+
19
+ const items = shopListMeta.sampleData.items;
20
+ expect(items).toHaveLength(12);
21
+ expect(new Set(items.map((item) => item.location.floorName))).toEqual(
22
+ new Set(['B1', '1 楼', '2 楼', '3 楼', '4 楼']),
23
+ );
24
+ expect(new Set(items.map((item) => item.status.code))).toEqual(
25
+ new Set(['enabled', 'disabled']),
26
+ );
27
+ });
28
+
29
+ it('shop-list 附加状态与 shop-detail 统一使用初始态门店身份', () => {
30
+ const initialById = new Map(
31
+ shopListMeta.sampleData.items.map((item) => [item.merchantId, item]),
32
+ );
33
+
34
+ for (const sample of shopListMeta.samples ?? []) {
35
+ const data = sample.data as { items: typeof shopListMeta.sampleData.items };
36
+ for (const item of data.items) {
37
+ const initial = initialById.get(item.merchantId);
38
+ expect(initial, `${sample.label}/${item.merchantId}`).toBeDefined();
39
+ expect(item.name).toBe(initial?.name);
40
+ expect(item.location).toEqual(initial?.location);
41
+ expect(item.status.code).toBe(initial?.status.code);
42
+ }
43
+ }
44
+
45
+ for (const data of [shopDetailMeta.sampleData, ...(shopDetailMeta.samples ?? []).map((s) => s.data)]) {
46
+ const initial = initialById.get(data.merchantId);
47
+ expect(initial, `shop-detail/${data.merchantId}`).toBeDefined();
48
+ expect(data.name).toBe(initial?.name);
49
+ expect(data.location).toEqual(initial?.location);
50
+ expect(data.status.code).toBe(initial?.status.code);
51
+ }
52
+ });
53
+
54
+ it('全部门店卡历史样本保留质量检查但不进入 Preview', () => {
55
+ for (const meta of [shopListMeta, shopDetailMeta, recommendMerchantsMeta]) {
56
+ const history = meta.samples?.find((sample) => sample.isHistory === true);
57
+ expect(history, `${meta.cardType} history sample`).toBeDefined();
58
+ expect(history?.hidden).toBe(true);
59
+ }
60
+ });
61
+
16
62
  for (const meta of metas) {
17
63
  it(`${meta.cardType}: 全样本过 schema + shape 无越界`, () => {
18
64
  expect(meta.samples?.length ?? 0).toBeGreaterThan(0);
@@ -54,11 +100,11 @@ describe('shopping-guide samples 双断言(样本即契约)', () => {
54
100
  }
55
101
  }
56
102
 
57
- const withoutImages = (metas[0].samples ?? []).filter((s) => {
103
+ const hasMissingImageBranch = metas.some((meta) => (meta.samples ?? []).some((s) => {
58
104
  const data = s.data as { logoUrl?: string; items?: readonly { logoUrl?: string }[] };
59
105
  return !data.logoUrl && (!data.items || data.items.some((entry) => !entry.logoUrl));
60
- });
61
- expect(withoutImages.length).toBeGreaterThan(0);
106
+ }));
107
+ expect(hasMissingImageBranch).toBe(true);
62
108
  });
63
109
 
64
110
  it('无促销态:promotionFacts 恒空、文案不含促销词汇', () => {