@tbox.cn/app-module-shopping-guide 0.2.1 → 0.8.3

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 (85) hide show
  1. package/AGENTS.md +16 -0
  2. package/README.md +96 -0
  3. package/dist/chunk-AYQZO2FV.js +1496 -0
  4. package/dist/chunk-VKDA6RXQ.js +1676 -0
  5. package/dist/client/index.d.ts +3 -3
  6. package/dist/client/index.js +1 -1
  7. package/dist/index.d.ts +1 -1
  8. package/dist/index.js +2 -8
  9. package/dist/server/index.d.ts +2512 -608
  10. package/dist/server/index.js +1 -7
  11. package/dist/shopping-guide-EGRHPEDA.css +2598 -0
  12. package/package.json +25 -16
  13. package/skills/shopping-guide/SKILL.md +127 -24
  14. package/src/client/cards/category-list/index.tsx +113 -0
  15. package/src/client/cards/human-guide-list/index.tsx +72 -0
  16. package/src/client/cards/index.ts +14 -0
  17. package/src/client/cards/location-handoff/index.tsx +52 -0
  18. package/src/client/cards/mall-directory/index.tsx +77 -0
  19. package/src/client/cards/nearby-mall-list/index.tsx +40 -0
  20. package/src/client/cards/product-comparison/index.tsx +100 -0
  21. package/src/client/cards/product-detail/index.tsx +97 -0
  22. package/src/client/cards/product-list/index.tsx +223 -0
  23. package/src/client/cards/recommend-merchants/index.tsx +147 -0
  24. package/src/client/cards/shop-detail/index.tsx +133 -0
  25. package/src/client/cards/shop-list/index.tsx +216 -0
  26. package/src/client/cards/view.ts +147 -0
  27. package/src/client/categories.ts +38 -0
  28. package/src/client/components/ImageWithFallback.tsx +34 -0
  29. package/src/client/components/MerchantRow.tsx +78 -0
  30. package/src/client/components/ShopDetailSheet.tsx +383 -0
  31. package/src/client/components/ShopGuideHeader.tsx +23 -0
  32. package/src/client/components/ShopGuideSectionLabel.tsx +10 -0
  33. package/src/client/components/ShopListSheet.tsx +293 -0
  34. package/src/client/index.ts +8 -6
  35. package/src/client/styles/shopping-guide.css +2598 -0
  36. package/src/client/types/css.d.ts +2 -0
  37. package/src/server/cards/category-list/meta.ts +0 -2
  38. package/src/server/cards/human-guide-list/meta.ts +0 -2
  39. package/src/server/cards/index.ts +10 -10
  40. package/src/server/cards/location-handoff/meta.ts +0 -2
  41. package/src/server/cards/mall-directory/meta.ts +0 -2
  42. package/src/server/cards/nearby-mall-list/meta.ts +1 -3
  43. package/src/server/cards/product-comparison/meta.ts +0 -2
  44. package/src/server/cards/product-detail/meta.ts +0 -2
  45. package/src/server/cards/product-list/meta.ts +0 -2
  46. package/src/server/cards/recommend-merchants/meta.ts +37 -0
  47. package/src/server/cards/recommend-merchants/samples.ts +189 -0
  48. package/src/server/cards/{merchant-detail → shop-detail}/meta.ts +6 -6
  49. package/src/server/cards/shop-detail/samples.ts +72 -0
  50. package/src/server/cards/{merchant-list → shop-list}/meta.ts +9 -9
  51. package/src/server/cards/shop-list/samples.ts +154 -0
  52. package/src/server/domain/value-objects.ts +1 -2
  53. package/src/server/handler.ts +63 -0
  54. package/src/server/index.ts +161 -101
  55. package/src/server/ports/index.ts +120 -91
  56. package/src/server/ports/local-adapters.ts +5 -55
  57. package/src/server/projections/index.ts +159 -41
  58. package/src/server/tools/index.ts +590 -315
  59. package/tbox.module.json +137 -0
  60. package/tests/cards-render.test.tsx +830 -0
  61. package/tests/floor-pretool.test.ts +275 -0
  62. package/tests/handler.test.ts +259 -0
  63. package/tests/merchant-list-limit.test.ts +53 -0
  64. package/tests/ports-resolve.test.ts +112 -0
  65. package/tests/samples.test.ts +71 -0
  66. package/tests/shopping-guide.test.ts +402 -234
  67. package/tests/skill.test.ts +86 -0
  68. package/tests/view.test.ts +42 -0
  69. package/tsup.config.ts +9 -1
  70. package/dist/chunk-AGBLC6XI.js +0 -1294
  71. package/dist/chunk-U4WDS5PQ.js +0 -173
  72. package/skills/shopping-guide/references/comparison-format.md +0 -5
  73. package/skills/shopping-guide/references/faq-answers.md +0 -5
  74. package/skills/shopping-guide/references/floor-directory.md +0 -4
  75. package/skills/shopping-guide/references/intent-patterns.md +0 -5
  76. package/skills/shopping-guide/references/location-format.md +0 -5
  77. package/skills/shopping-guide/references/policy-lookup.md +0 -5
  78. package/skills/shopping-guide/references/product-search-tips.md +0 -6
  79. package/skills/shopping-guide/references/recommendation-style.md +0 -5
  80. package/src/client/cards/index.tsx +0 -267
  81. package/src/server/cards/customer-service-faq/meta.ts +0 -18
  82. package/src/server/integrations/joycity/adapter.ts +0 -226
  83. package/src/server/integrations/joycity/auth-strategy.ts +0 -38
  84. package/src/server/integrations/joycity/gateway.ts +0 -128
  85. package/tbox.component.json +0 -48
@@ -0,0 +1,86 @@
1
+ /**
2
+ * shopping-guide 文件 skill 装配 + routingTerms 对齐回归锁(反幻觉 L3)。
3
+ *
4
+ * 缺陷背景:复测会话 20260903bXjo50449795 三轮(购物有哪些/服饰呢/餐饮有哪些)
5
+ * journal 均 skill_injection action=none——类目问句不含原 routingTerms 任何词,
6
+ * SOP「正文只说 3-5 家、完整列表交给卡片」整轮缺席,正文自由罗列。
7
+ *
8
+ * 锚定三层:
9
+ * 1. 装配锚——loadModuleSkills 经 workspace link 解析包根 skills/,声明式通道回填;
10
+ * 2. 双源回归锁——类目词 ∈ routingTerms(category-shops preTool 词表高频子集):
11
+ * 词表静默漂移即红(faq-pretool-terms 双源漂移教训的机械防线);
12
+ * 3. 真管线路由锚——decideSkillInjection(SDK 路由真源,BM25 + satisfiesRoutingRule):
13
+ * 类目问句命中注入、闲聊/客服域不误注。
14
+ *
15
+ * 词表范围裁定(收缩版 16 词):
16
+ * - 营业时间移除——客服 FAQ 域词(误注 SOP 膨胀上下文;漏注后果仅话术退化,
17
+ * preTool 数据面已闭环);
18
+ * - 逛族词(好逛/可逛/可以逛/想逛/逛什么)不入表——BM25 索引侧 R1 规则排除
19
+ * 含 BROAD 拆字的 bigram(好←你好/可←可以/想←想要),这些词在 skill 路由
20
+ * 结构性无效(preTool terms 是子串直配,不受影响);
21
+ * - 稀疏类目词(运动/美妆/珠宝/超市/影院/健身/零售/休闲)暂缓——句式稀疏,
22
+ * 实证出现后再补(证据驱动)。
23
+ */
24
+ import { describe, expect, it } from 'vitest';
25
+ import { decideSkillInjection } from '@tbox.cn/app-sdk/server';
26
+ import { serverModule } from '../src/server/index';
27
+
28
+ type LoadedSkill = {
29
+ name: string;
30
+ description: string;
31
+ routingTerms: string[];
32
+ instructions: string;
33
+ };
34
+
35
+ /** trace 实证 7 问句全覆盖 + 高频变体的类目词子集(category-shops prePool 词表 ⊂ 本表) */
36
+ const CATEGORY_ROUTE_TERMS = ['购物', '餐饮', '美食', '生活', '娱乐', '儿童', '亲子', '服饰', '服装'] as const;
37
+
38
+ describe('shopping-guide skills 装配与 routingTerms 对齐', () => {
39
+ const skills = ((serverModule as { skills?: Record<string, LoadedSkill> }).skills ?? {});
40
+ const skill = skills['shopping-guide']!;
41
+
42
+ it('skills 含 shopping-guide(frontmatter name + 目录名一致)', () => {
43
+ expect(Object.keys(skills)).toContain('shopping-guide');
44
+ expect(skill.description.length).toBeGreaterThan(0);
45
+ expect(skill.instructions).toContain('3-5 家');
46
+ });
47
+
48
+ it('routingTerms 双源回归锁:类目词在场(preTool 词表漂移防线)', () => {
49
+ const terms = new Set(skill.routingTerms);
50
+ for (const word of CATEGORY_ROUTE_TERMS) {
51
+ expect(terms.has(word)).toBe(true);
52
+ }
53
+ });
54
+
55
+ it('routingTerms 不含跨域词(营业时间归客服 FAQ 域)', () => {
56
+ const crossDomain = ['营业时间', '客服', '退换货', '投诉', '发票', '停车', '领券', '优惠券', '会员', '积分'];
57
+ expect(skill.routingTerms.some((t) => crossDomain.includes(t))).toBe(false);
58
+ });
59
+
60
+ describe('真管线路由锚(decideSkillInjection)', () => {
61
+ const localSkills = Object.values(skills) as unknown as Parameters<typeof decideSkillInjection>[0]['skills'];
62
+ const history: [] = [];
63
+
64
+ it.each([
65
+ ['购物有哪些', '类目问句(本次缺陷复现锚——复测会话 skill_injection none 根因)'],
66
+ ['餐饮有哪些', '类目问句'],
67
+ ['美食有哪些', '类目问句(同义词)'],
68
+ ['儿童有哪些', '类目问句'],
69
+ ['商场里卖服装的店多吗', '类目长句'],
70
+ ['3F 有哪些门店', '原 routingTerms 既有承接面不回归'],
71
+ ])('%s → injected(%s)', (text) => {
72
+ const decision = decideSkillInjection({ text, history, skills: localSkills });
73
+ expect(decision.action).toBe('injected');
74
+ });
75
+
76
+ it('今天天气怎么样 → none(闲聊不误注)', () => {
77
+ const decision = decideSkillInjection({ text: '今天天气怎么样', history, skills: localSkills });
78
+ expect(decision.action).toBe('none');
79
+ });
80
+
81
+ it('营业时间到几点 → none(客服域词已移除,不注导购 SOP)', () => {
82
+ const decision = decideSkillInjection({ text: '营业时间到几点', history, skills: localSkills });
83
+ expect(decision.action).toBe('none');
84
+ });
85
+ });
86
+ });
@@ -0,0 +1,42 @@
1
+ /**
2
+ * shopping-guide view.ts 纯函数单测(0.4.0 D6:node 环境,无 DOM)。
3
+ */
4
+ import { describe, expect, it } from 'vitest';
5
+ import { categoryIcon, deriveLocationLevel, formatDistance } from '../src/client/cards/view';
6
+
7
+ describe('formatDistance', () => {
8
+ it('缺省与非法值 → —', () => {
9
+ expect(formatDistance(undefined)).toBe('—');
10
+ expect(formatDistance(-1)).toBe('—');
11
+ });
12
+ it('<1km → 米整数', () => {
13
+ expect(formatDistance(0.4)).toBe('400m');
14
+ });
15
+ it('≥1km → x.x km', () => {
16
+ expect(formatDistance(2.35)).toBe('2.4 km');
17
+ expect(formatDistance(1)).toBe('1.0 km');
18
+ });
19
+ });
20
+
21
+ describe('deriveLocationLevel 三级降级', () => {
22
+ const loc = (displayText?: string) => ({ displayText: displayText ?? '' });
23
+ it('itemActions 含 link → route_available', () => {
24
+ expect(deriveLocationLevel({ location: loc('A 馆'), itemActions: [{ kind: 'link', label: '导航', url: 'https://x' }] })).toBe('route_available');
25
+ });
26
+ it('有地址无导航 → location_only', () => {
27
+ expect(deriveLocationLevel({ location: loc('A 馆'), itemActions: [] })).toBe('location_only');
28
+ });
29
+ it('地址不完整 → unavailable', () => {
30
+ expect(deriveLocationLevel({ location: loc(''), itemActions: [] })).toBe('unavailable');
31
+ });
32
+ });
33
+
34
+ describe('categoryIcon', () => {
35
+ it('精确匹配与前缀匹配', () => {
36
+ expect(categoryIcon('food')).toBe('🍜');
37
+ expect(categoryIcon('FOOD_AND_BEVERAGE')).toBe('🍜');
38
+ });
39
+ it('未知类别回退 🏪(未归类图标)', () => {
40
+ expect(categoryIcon('quantum_lab')).toBe('🏪');
41
+ });
42
+ });
package/tsup.config.ts CHANGED
@@ -12,7 +12,9 @@ export default defineConfig({
12
12
  outDir: 'dist',
13
13
  clean: true,
14
14
  sourcemap: false,
15
- dts: true,
15
+ // dts worker 以命令行式传参会撞 TS5074(incremental 需单文件 emit 或 tsBuildInfoFile);
16
+ // 声明产物一次性构建无需增量——仅 dts 关闭,typecheck 的增量缓存不受影响。
17
+ dts: { compilerOptions: { incremental: false } },
16
18
  external: [
17
19
  '@tbox.cn/app-sdk',
18
20
  '@tbox.cn/app-contracts',
@@ -22,7 +24,13 @@ export default defineConfig({
22
24
  'zod',
23
25
  '@mastra/core',
24
26
  'express',
27
+ '@phosphor-icons/react',
25
28
  ],
29
+ // 0.3.2/0.4.0 D1:模块自持 CSS 出货链。
30
+ // 顶层 loader 写法(实测:esbuildOptions 内设 loader 被 tsup 覆盖失效——CSS 提取断链静默丢失)。
31
+ loader: {
32
+ '.css': 'copy',
33
+ },
26
34
  esbuildOptions(options) {
27
35
  options.jsx = 'automatic';
28
36
  },