@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,1496 @@
1
+ // src/server/index.ts
2
+ import { definePreTool, loadModuleSkills, getRequestContext } from "@tbox.cn/app-sdk/server";
3
+ import { Router } from "express";
4
+ import { toMallQueryContext, withMallScopeFromQuery, mallSlot } from "@tbox.cn/app-contracts-mall";
5
+
6
+ // src/server/cards/product-list/meta.ts
7
+ import { productListCardDataSchema } from "@tbox.cn/app-contracts-mall";
8
+
9
+ // src/server/domain/value-objects.ts
10
+ import { parseMallScope } from "@tbox.cn/app-contracts-mall";
11
+ function toShoppingQueryContext(requestContext, subjectId) {
12
+ const scope = parseMallScope(requestContext.attributes);
13
+ if (!scope) {
14
+ throw new Error("\u7F3A\u5C11 mall scope\uFF08\u5DE5\u5177\u9700\u5728 mall \u4F1A\u8BDD\u5185\u8C03\u7528\uFF09");
15
+ }
16
+ return {
17
+ scope,
18
+ ...subjectId ? { subjectId } : {},
19
+ requestContext
20
+ };
21
+ }
22
+ function scopeFromMallId(requestContext, overrideMallId) {
23
+ const scope = toShoppingQueryContext(requestContext).scope;
24
+ if (overrideMallId && overrideMallId !== scope.mallId) {
25
+ return { ...scope, mallId: overrideMallId };
26
+ }
27
+ return scope;
28
+ }
29
+ function nowIso() {
30
+ return (/* @__PURE__ */ new Date()).toISOString().replace(/\.\d{3}Z$/, "Z");
31
+ }
32
+
33
+ // src/server/cards/product-list/meta.ts
34
+ var meta = {
35
+ cardType: "product-list",
36
+ dataSchema: productListCardDataSchema,
37
+ displayName: "\u5546\u54C1\u5217\u8868",
38
+ description: "\u63A8\u8350/\u641C\u7D22/\u5386\u53F2\u5546\u54C1\u5217\u8868\uFF08\u542B\u4EF7\u683C\u3001\u5E93\u5B58\u3001\u95E8\u5E97\uFF09",
39
+ sampleData: {
40
+ context: "search",
41
+ items: [
42
+ {
43
+ productId: "p1",
44
+ name: "\u793A\u4F8B\u8DD1\u978B",
45
+ categoryPath: ["\u8FD0\u52A8", "\u8DD1\u6B65"],
46
+ price: { sale: { currency: "CNY", amountMinor: 39900, display: "\xA5399.00" } },
47
+ availability: { status: "in_stock", label: "\u6709\u8D27", marketable: true, observedAt: nowIso() },
48
+ merchant: { merchantId: "m1", name: "\u793A\u4F8B\u95E8\u5E97" },
49
+ badges: ["\u70ED\u5356"],
50
+ caveats: [],
51
+ itemActions: []
52
+ }
53
+ ],
54
+ refinements: []
55
+ },
56
+ schemaVersion: 1
57
+ };
58
+ var meta_default = meta;
59
+
60
+ // src/server/cards/product-detail/meta.ts
61
+ import { productDetailCardDataSchema } from "@tbox.cn/app-contracts-mall";
62
+ var meta2 = {
63
+ cardType: "product-detail",
64
+ dataSchema: productDetailCardDataSchema,
65
+ displayName: "\u5546\u54C1\u8BE6\u60C5",
66
+ description: "\u5355\u4E2A\u5546\u54C1\u7684\u5B8C\u6574\u5FEB\u7167\uFF08\u4EF7\u683C/\u5E93\u5B58/\u5C5E\u6027/\u5546\u6237\uFF09",
67
+ sampleData: {
68
+ productId: "p1",
69
+ name: "\u793A\u4F8B\u8DD1\u978B",
70
+ imageUrls: [],
71
+ categoryPath: ["\u8FD0\u52A8"],
72
+ price: {},
73
+ availability: { status: "unknown", label: "\u672A\u77E5", marketable: false, observedAt: nowIso() },
74
+ merchant: { merchantId: "m1", name: "\u793A\u4F8B\u95E8\u5E97" },
75
+ attributes: [],
76
+ promotionFacts: [],
77
+ evidence: [],
78
+ humanGuideAvailable: false,
79
+ itemActions: []
80
+ },
81
+ schemaVersion: 1
82
+ };
83
+ var meta_default2 = meta2;
84
+
85
+ // src/server/cards/shop-list/meta.ts
86
+ import { shopListCardDataSchema } from "@tbox.cn/app-contracts-mall";
87
+
88
+ // src/server/cards/shop-list/samples.ts
89
+ var OBSERVED_AT = "2026-08-28T00:00:00.000Z";
90
+ var ASSET = {
91
+ coffeeLogo: "https://gallery.invalid/brand-guide/coffee-photo.png",
92
+ diningLogo: "https://gallery.invalid/brand-guide/dining-photo.png",
93
+ lifestyleLogo: "https://gallery.invalid/brand-guide/lifestyle-photo.png"
94
+ };
95
+ var BROWSE_DATA = {
96
+ context: "search",
97
+ summary: "\u6309\u60F3\u901B\u7684\u54C1\u7C7B\u5FEB\u901F\u627E\u5230\u5408\u9002\u95E8\u5E97",
98
+ categoryTabs: [
99
+ { code: "food", name: "\u9910\u996E" },
100
+ { code: "coffee", name: "\u5496\u5561" },
101
+ { code: "fashion", name: "\u670D\u9970" },
102
+ { code: "lifestyle", name: "\u751F\u6D3B\u65B9\u5F0F" },
103
+ { code: "sports", name: "\u8FD0\u52A8" }
104
+ ],
105
+ items: [
106
+ {
107
+ merchantId: "shop-coffee",
108
+ name: "\u65E5\u5149\u5496\u5561\u5B9E\u9A8C\u5BA4",
109
+ logoUrl: ASSET.coffeeLogo,
110
+ brand: "\u65E5\u5149\u5496\u5561",
111
+ businessCategories: ["\u5496\u5561", "\u9910\u996E"],
112
+ location: { buildingName: "A \u5EA7", floorName: "L1", unitName: "A117", displayText: "A \u5EA7 L1 A117" },
113
+ status: { code: "enabled", label: "\u8425\u4E1A\u4E2D", observedAt: OBSERVED_AT },
114
+ contactInfo: [{ channel: "phone", value: "400-000-1122" }],
115
+ services: ["\u5802\u98DF", "\u5916\u5E26"],
116
+ promotionFacts: [],
117
+ itemActions: [{ kind: "send", label: "\u67E5\u770B\u8BE6\u60C5", value: "\u4ECB\u7ECD\u4E00\u4E0B\u65E5\u5149\u5496\u5561\u5B9E\u9A8C\u5BA4" }]
118
+ },
119
+ {
120
+ merchantId: "shop-fashion",
121
+ name: "\u7EC7\u91CE\u57CE\u5E02\u751F\u6D3B\u9986",
122
+ logoUrl: ASSET.lifestyleLogo,
123
+ brand: "\u7EC7\u91CE",
124
+ businessCategories: ["\u670D\u9970", "\u751F\u6D3B\u65B9\u5F0F"],
125
+ location: { buildingName: "A \u5EA7", floorName: "L2", unitName: "A238", displayText: "A \u5EA7 L2 A238" },
126
+ status: { code: "disabled", label: "\u4F11\u606F\u4E2D", observedAt: OBSERVED_AT },
127
+ services: ["\u5230\u5E97\u81EA\u63D0"],
128
+ promotionFacts: [],
129
+ itemActions: [{ kind: "send", label: "\u54C1\u724C\u4ECB\u7ECD", value: "\u4ECB\u7ECD\u4E00\u4E0B\u7EC7\u91CE\u57CE\u5E02\u751F\u6D3B\u9986" }]
130
+ },
131
+ {
132
+ merchantId: "shop-sport",
133
+ name: "\u8DC3\u52A8\u8FD0\u52A8\u96C6\u5408\u7A7A\u95F4\u65D7\u8230\u4F53\u9A8C\u5E97",
134
+ businessCategories: ["\u8FD0\u52A8"],
135
+ location: { displayText: "\u4F4D\u7F6E\u5F85\u786E\u8BA4" },
136
+ status: { code: "unknown", label: "\u72B6\u6001\u5F85\u786E\u8BA4", observedAt: OBSERVED_AT },
137
+ services: [],
138
+ promotionFacts: [],
139
+ itemActions: []
140
+ },
141
+ {
142
+ merchantId: "shop-family",
143
+ name: "\u5C0F\u5C0F\u661F\u7403\u4EB2\u5B50\u6210\u957F\u7A7A\u95F4",
144
+ logoUrl: ASSET.lifestyleLogo,
145
+ businessCategories: ["\u4EB2\u5B50", "\u5A31\u4E50"],
146
+ location: { buildingName: "B \u5EA7", floorName: "L4", unitName: "B408", displayText: "B \u5EA7 L4 B408" },
147
+ status: { code: "enabled", label: "\u8425\u4E1A\u4E2D", observedAt: OBSERVED_AT },
148
+ services: ["\u4EB2\u5B50\u53CB\u597D"],
149
+ promotionFacts: [],
150
+ itemActions: []
151
+ },
152
+ {
153
+ merchantId: "shop-dining",
154
+ name: "\u6696\u5C7F\u5BB6\u5EAD\u9910\u5385",
155
+ logoUrl: ASSET.diningLogo,
156
+ businessCategories: ["\u9910\u996E"],
157
+ location: { buildingName: "B \u5EA7", floorName: "L3", unitName: "B305", displayText: "B \u5EA7 L3 B305" },
158
+ status: { code: "unknown", label: "\u72B6\u6001\u5F85\u786E\u8BA4", observedAt: OBSERVED_AT },
159
+ services: [],
160
+ promotionFacts: [],
161
+ itemActions: []
162
+ },
163
+ {
164
+ merchantId: "shop-bakery",
165
+ name: "\u9EA6\u753A\u70D8\u7119\u5DE5\u623F",
166
+ logoUrl: ASSET.coffeeLogo,
167
+ businessCategories: ["\u5496\u5561", "\u9910\u996E"],
168
+ location: { buildingName: "A \u5EA7", floorName: "L1", unitName: "A106", displayText: "A \u5EA7 L1 A106" },
169
+ status: { code: "enabled", label: "\u8425\u4E1A\u4E2D", observedAt: OBSERVED_AT },
170
+ services: ["\u5916\u5E26"],
171
+ promotionFacts: [],
172
+ itemActions: []
173
+ }
174
+ ],
175
+ pageInfo: { page: 1, pageSize: 10, total: 18, hasMore: true },
176
+ refinements: [
177
+ { label: "\u53EA\u770B\u8425\u4E1A\u4E2D", queryText: "\u53EA\u770B\u73B0\u5728\u8425\u4E1A\u7684\u95E8\u5E97" },
178
+ { label: "\u67E5\u770B L1", queryText: "\u67E5\u770B L1 \u7684\u95E8\u5E97" }
179
+ ]
180
+ };
181
+ var samples = [
182
+ {
183
+ label: "\u95E8\u5E97\u5217\u8868\xB7\u5B8C\u6574\u6D4F\u89C8",
184
+ note: "\u9ED8\u8BA4\u95E8\u5E97\u5BFC\u89C8\u5165\u53E3\uFF1B\u56DB\u4E2A\u7C7B\u76EE Tab\u3001\u4E09\u79CD\u8425\u4E1A\u72B6\u6001\u3001\u7535\u8BDD\u4E0E\u7B5B\u9009\u5EFA\u8BAE\uFF08\u7B2C\u4E09\u884C\u65E0 logo \u8D70\u515C\u5E95\uFF1B\u5951\u7EA6\u5F3A\u5236 https \u56FE\u4F4D \u2192 \u9884\u89C8\u9875\u6052\u7F3A\u56FE\u515C\u5E95\uFF0C\u6709\u56FE\u5F62\u6001\u9700\u771F\u673A\u6570\u636E\uFF09",
185
+ group: "\u95E8\u5E97\u5BFC\u89C8\uFF08\u9ED8\u8BA4\u5165\u53E3\uFF09",
186
+ data: BROWSE_DATA
187
+ },
188
+ {
189
+ label: "\u95E8\u5E97\u5217\u8868\xB7\u641C\u7D22\u7ED3\u679C",
190
+ note: "\u65E0 Tab \u5934\u7684\u5B9A\u5411\u641C\u7D22\u6001\uFF0C\u957F\u540D\u79F0\u4E0E\u65E0 Logo \u4F7F\u7528\u7A33\u5B9A\u515C\u5E95",
191
+ group: "\u95E8\u5E97\u5BFC\u89C8\uFF08\u9ED8\u8BA4\u5165\u53E3\uFF09",
192
+ data: {
193
+ ...BROWSE_DATA,
194
+ summary: "\u627E\u5230 1 \u5BB6\u8FD0\u52A8\u54C1\u724C\u95E8\u5E97",
195
+ categoryTabs: void 0,
196
+ items: [BROWSE_DATA.items[2]],
197
+ pageInfo: { page: 1, pageSize: 10, total: 1, hasMore: false },
198
+ refinements: []
199
+ }
200
+ },
201
+ {
202
+ label: "\u95E8\u5E97\u5217\u8868\xB7\u7A7A\u6001",
203
+ note: "\u7B5B\u9009\u65E0\u7ED3\u679C\u65F6\u4FDD\u7559\u660E\u786E\u539F\u56E0\uFF0C\u4E0D\u6E32\u67D3\u5217\u8868\u4E0E\u52A8\u4F5C\u533A",
204
+ group: "\u95E8\u5E97\u5BFC\u89C8\uFF08\u9ED8\u8BA4\u5165\u53E3\uFF09",
205
+ data: {
206
+ context: "search",
207
+ summary: "\u641C\u7D22\u300C\u6DF1\u591C\u8425\u4E1A\u300D",
208
+ items: [],
209
+ noResultsReason: "\u6682\u65F6\u6CA1\u6709\u7B26\u5408\u6761\u4EF6\u7684\u95E8\u5E97\uFF0C\u6362\u4E2A\u54C1\u7C7B\u8BD5\u8BD5",
210
+ refinements: [{ label: "\u67E5\u770B\u5168\u90E8\u95E8\u5E97", queryText: "\u67E5\u770B\u5168\u90E8\u95E8\u5E97" }]
211
+ }
212
+ },
213
+ {
214
+ label: "\u95E8\u5E97\u5217\u8868\xB7\u5386\u53F2\u5361",
215
+ note: "\u5386\u53F2\u6D88\u606F\u4E2D\u7684\u7C7B\u76EE\u3001\u7535\u8BDD\u3001\u7B5B\u9009\u548C\u6761\u76EE\u52A8\u4F5C\u5747\u4E0D\u53EF\u7EE7\u7EED\u64CD\u4F5C",
216
+ group: "\u95E8\u5E97\u5BFC\u89C8\uFF08\u9ED8\u8BA4\u5165\u53E3\uFF09",
217
+ data: BROWSE_DATA,
218
+ isHistory: true
219
+ }
220
+ ];
221
+
222
+ // src/server/cards/shop-list/meta.ts
223
+ var meta3 = {
224
+ cardType: "shop-list",
225
+ dataSchema: shopListCardDataSchema,
226
+ displayName: "\u95E8\u5E97\u5BFC\u89C8",
227
+ description: "\u63A8\u8350/\u641C\u7D22\u95E8\u5E97\u5217\u8868\uFF08\u542B\u4F4D\u7F6E\u4E0E\u8425\u4E1A\u72B6\u6001\uFF09",
228
+ sampleData: {
229
+ context: "search",
230
+ items: [
231
+ {
232
+ merchantId: "m1",
233
+ name: "\u793A\u4F8B\u95E8\u5E97",
234
+ businessCategories: ["\u9910\u996E"],
235
+ location: { displayText: "A \u680B 3 \u697C 301" },
236
+ status: { code: "enabled", label: "\u8425\u4E1A\u4E2D", observedAt: nowIso() },
237
+ services: ["\u5802\u98DF"],
238
+ promotionFacts: [],
239
+ itemActions: []
240
+ }
241
+ ],
242
+ refinements: []
243
+ },
244
+ samples,
245
+ schemaVersion: 1
246
+ };
247
+ var meta_default3 = meta3;
248
+
249
+ // src/server/cards/shop-detail/meta.ts
250
+ import { shopDetailCardDataSchema } from "@tbox.cn/app-contracts-mall";
251
+
252
+ // src/server/cards/shop-detail/samples.ts
253
+ var OBSERVED_AT2 = "2026-08-28T00:00:00.000Z";
254
+ var ASSET2 = {
255
+ coffeeLogo: "https://gallery.invalid/brand-guide/coffee-photo.png",
256
+ detailCover: "https://gallery.invalid/brand-guide/detail-cover.png"
257
+ };
258
+ var DETAIL_DATA = {
259
+ merchantId: "detail-coffee",
260
+ name: "\u65E5\u5149\u5496\u5561\u5B9E\u9A8C\u5BA4",
261
+ logoUrl: ASSET2.coffeeLogo,
262
+ coverUrls: [ASSET2.detailCover],
263
+ brand: "\u65E5\u5149\u5496\u5561",
264
+ businessCategories: ["\u5496\u5561", "\u8F7B\u98DF"],
265
+ location: { buildingName: "A \u5EA7", floorName: "L1", unitName: "A117", displayText: "A \u5EA7 L1 A117" },
266
+ status: { code: "enabled", label: "\u8425\u4E1A\u4E2D", observedAt: OBSERVED_AT2 },
267
+ description: "\u4EE5\u5F53\u5B63\u5496\u5561\u8C46\u548C\u57CE\u5E02\u7075\u611F\u996E\u54C1\u4E3A\u7279\u8272\uFF0C\u63D0\u4F9B\u9002\u5408\u77ED\u6682\u505C\u7559\u4E0E\u670B\u53CB\u5C0F\u805A\u7684\u660E\u4EAE\u7A7A\u95F4\u3002",
268
+ contactInfo: [
269
+ { channel: "\u8425\u4E1A\u65F6\u95F4", value: "10:00\u201322:00" },
270
+ { channel: "\u7535\u8BDD", value: "tel:4000001122" }
271
+ ],
272
+ services: ["\u5802\u98DF", "\u5916\u5E26", "\u5145\u7535\u63D2\u5EA7", "\u65E0\u969C\u788D\u901A\u884C"],
273
+ promotionFacts: [],
274
+ evidence: [],
275
+ itemActions: [
276
+ { kind: "send", label: "\u67E5\u770B\u63A8\u8350", value: "\u65E5\u5149\u5496\u5561\u6709\u54EA\u4E9B\u62DB\u724C\u63A8\u8350" },
277
+ { kind: "send", label: "\u600E\u4E48\u53BB", value: "\u5E26\u6211\u53BB\u65E5\u5149\u5496\u5561\u5B9E\u9A8C\u5BA4" }
278
+ ]
279
+ };
280
+ var samples2 = [
281
+ {
282
+ label: "\u95E8\u5E97\u8BE6\u60C5\xB7\u5B8C\u6574\u4FE1\u606F",
283
+ note: "\u5C01\u9762\u4E0E\u95E8\u5E97\u56FE\uFF08https \u5360\u4F4D\uFF09\u3001\u7B80\u4ECB\u3001\u670D\u52A1\u3001\u8425\u4E1A\u65F6\u95F4\u3001\u7535\u8BDD\u4E0E\u53CC\u52A8\u4F5C\u5B8C\u6574\u5448\u73B0\uFF08\u5951\u7EA6\u5F3A\u5236 https \u2192 \u9884\u89C8\u9875\u56FE\u4F4D\u8D70\u7F3A\u56FE\u515C\u5E95\uFF09",
284
+ group: "\u95E8\u5E97\u8BE6\u60C5",
285
+ data: DETAIL_DATA
286
+ },
287
+ {
288
+ label: "\u95E8\u5E97\u8BE6\u60C5\xB7\u6700\u5C0F\u4FE1\u606F",
289
+ note: "\u65E0\u5C01\u9762\u3001\u65E0\u95E8\u5E97\u56FE\u3001\u65E0\u7B80\u4ECB\u65F6\u4FDD\u6301\u7D27\u51D1\u7ED3\u6784",
290
+ group: "\u95E8\u5E97\u8BE6\u60C5",
291
+ data: {
292
+ merchantId: "detail-minimal",
293
+ name: "\u4E00\u65B9\u5C0F\u5E97",
294
+ coverUrls: [],
295
+ businessCategories: ["\u751F\u6D3B\u65B9\u5F0F"],
296
+ location: { displayText: "B \u5EA7 L3" },
297
+ status: { code: "unknown", label: "\u72B6\u6001\u5F85\u786E\u8BA4", observedAt: OBSERVED_AT2 },
298
+ services: [],
299
+ promotionFacts: [],
300
+ evidence: [],
301
+ itemActions: []
302
+ }
303
+ },
304
+ {
305
+ label: "\u95E8\u5E97\u8BE6\u60C5\xB7\u5386\u53F2\u5361",
306
+ note: "\u5386\u53F2\u6D88\u606F\u4FDD\u7559\u5B8C\u6574\u4FE1\u606F\uFF0C\u4F46\u7535\u8BDD\u548C\u5361\u5185\u52A8\u4F5C\u4E0D\u53EF\u70B9\u51FB",
307
+ group: "\u95E8\u5E97\u8BE6\u60C5",
308
+ data: DETAIL_DATA,
309
+ isHistory: true
310
+ }
311
+ ];
312
+
313
+ // src/server/cards/shop-detail/meta.ts
314
+ var meta4 = {
315
+ cardType: "shop-detail",
316
+ dataSchema: shopDetailCardDataSchema,
317
+ displayName: "\u95E8\u5E97\u8BE6\u60C5",
318
+ description: "\u5355\u4E2A\u95E8\u5E97\u5B8C\u6574\u5FEB\u7167\uFF08\u56FE\u7247/\u7B80\u4ECB/\u8054\u7CFB\u65B9\u5F0F\uFF09",
319
+ sampleData: {
320
+ merchantId: "m1",
321
+ name: "\u793A\u4F8B\u95E8\u5E97",
322
+ coverUrls: [],
323
+ businessCategories: ["\u9910\u996E"],
324
+ location: { displayText: "A \u680B 3 \u697C" },
325
+ status: { code: "enabled", label: "\u8425\u4E1A\u4E2D", observedAt: nowIso() },
326
+ services: [],
327
+ promotionFacts: [],
328
+ evidence: [],
329
+ itemActions: []
330
+ },
331
+ samples: samples2,
332
+ schemaVersion: 1
333
+ };
334
+ var meta_default4 = meta4;
335
+
336
+ // src/server/cards/category-list/meta.ts
337
+ import { categoryListCardDataSchema } from "@tbox.cn/app-contracts-mall";
338
+ var meta5 = {
339
+ cardType: "category-list",
340
+ dataSchema: categoryListCardDataSchema,
341
+ displayName: "\u4E1A\u6001\u5206\u7C7B\u76EE\u5F55",
342
+ description: "\u5546\u573A\u5168\u90E8\u4E1A\u6001\u5206\u7C7B\uFF08\u9910\u996E/\u96F6\u552E/\u5A31\u4E50\u7B49\uFF09",
343
+ sampleData: {
344
+ categories: [{ code: "c1", name: "\u9910\u996E", merchantCount: 42 }],
345
+ observedAt: nowIso()
346
+ },
347
+ schemaVersion: 1
348
+ };
349
+ var meta_default5 = meta5;
350
+
351
+ // src/server/cards/product-comparison/meta.ts
352
+ import { productComparisonCardDataSchema } from "@tbox.cn/app-contracts-mall";
353
+ var meta6 = {
354
+ cardType: "product-comparison",
355
+ dataSchema: productComparisonCardDataSchema,
356
+ displayName: "\u5546\u54C1\u5BF9\u6BD4",
357
+ description: "2-4 \u4E2A\u5546\u54C1\u4EF7\u683C/\u5C5E\u6027/\u5E93\u5B58\u5E76\u6392\u5BF9\u6BD4",
358
+ sampleData: {
359
+ products: [
360
+ {
361
+ productId: "p1",
362
+ name: "\u5546\u54C1 A",
363
+ price: {},
364
+ availability: { status: "unknown", label: "\u672A\u77E5", marketable: false, observedAt: nowIso() },
365
+ merchant: { merchantId: "m1", name: "\u95E8\u5E97" },
366
+ attributes: [],
367
+ caveats: []
368
+ }
369
+ ],
370
+ observedAt: nowIso()
371
+ },
372
+ schemaVersion: 1
373
+ };
374
+ var meta_default6 = meta6;
375
+
376
+ // src/server/cards/mall-directory/meta.ts
377
+ import { mallDirectoryCardDataSchema } from "@tbox.cn/app-contracts-mall";
378
+ var meta7 = {
379
+ cardType: "mall-directory",
380
+ dataSchema: mallDirectoryCardDataSchema,
381
+ displayName: "\u5546\u573A\u697C\u5C42\u76EE\u5F55",
382
+ description: "\u697C\u680B-\u697C\u5C42\u7ED3\u6784\uFF08\u51E0\u697C\u6709\u4EC0\u4E48\uFF09",
383
+ sampleData: {
384
+ mallId: "mall-1",
385
+ mallName: "\u793A\u4F8B\u5546\u573A",
386
+ buildings: [
387
+ {
388
+ buildingCode: "A",
389
+ buildingName: "A \u680B",
390
+ floors: [{ floorCode: "3F", floorName: "3 \u697C", businessCategories: ["\u9910\u996E"], merchantCount: 12 }]
391
+ }
392
+ ],
393
+ observedAt: nowIso()
394
+ },
395
+ schemaVersion: 1
396
+ };
397
+ var meta_default7 = meta7;
398
+
399
+ // src/server/cards/nearby-mall-list/meta.ts
400
+ import { nearbyMallListCardDataSchema } from "@tbox.cn/app-contracts-mall";
401
+ var meta8 = {
402
+ cardType: "nearby-mall-list",
403
+ dataSchema: nearbyMallListCardDataSchema,
404
+ displayName: "\u9644\u8FD1\u5546\u573A",
405
+ description: "\u9644\u8FD1\u53EF\u5207\u6362\u7684\u95E8\u5E97\u5217\u8868",
406
+ sampleData: {
407
+ malls: [{ mallId: "mall-1", name: "\u793A\u4F8B\u5546\u573A", address: "\u793A\u4F8B\u5730\u5740", status: { code: "open", label: "\u8425\u4E1A\u4E2D" }, itemActions: [] }]
408
+ },
409
+ schemaVersion: 1
410
+ };
411
+ var meta_default8 = meta8;
412
+
413
+ // src/server/cards/human-guide-list/meta.ts
414
+ import { humanGuideListCardDataSchema } from "@tbox.cn/app-contracts-mall";
415
+ var meta9 = {
416
+ cardType: "human-guide-list",
417
+ dataSchema: humanGuideListCardDataSchema,
418
+ displayName: "\u4EBA\u5DE5\u5BFC\u8D2D",
419
+ description: "\u6307\u5B9A\u95E8\u5E97\u53EF\u8054\u7CFB\u7684\u5BFC\u8D2D\u5458\u5217\u8868",
420
+ sampleData: {
421
+ merchantId: "m1",
422
+ merchantName: "\u793A\u4F8B\u95E8\u5E97",
423
+ guides: [{ guideId: "g1", name: "\u5C0F\u5BFC", available: true, itemActions: [] }]
424
+ },
425
+ schemaVersion: 1
426
+ };
427
+ var meta_default9 = meta9;
428
+
429
+ // src/server/cards/location-handoff/meta.ts
430
+ import { locationHandoffCardDataSchema } from "@tbox.cn/app-contracts-mall";
431
+ var meta10 = {
432
+ cardType: "location-handoff",
433
+ dataSchema: locationHandoffCardDataSchema,
434
+ displayName: "\u4F4D\u7F6E\u5BFC\u822A",
435
+ description: "\u95E8\u5E97\u4F4D\u7F6E\u4E0E\u5BFC\u822A\u80FD\u529B",
436
+ sampleData: {
437
+ merchantId: "m1",
438
+ merchantName: "\u793A\u4F8B\u95E8\u5E97",
439
+ location: { displayText: "A \u680B 3 \u697C 301" },
440
+ itemActions: []
441
+ },
442
+ schemaVersion: 1
443
+ };
444
+ var meta_default10 = meta10;
445
+
446
+ // src/server/cards/recommend-merchants/meta.ts
447
+ import { recommendMerchantsCardDataSchema } from "@tbox.cn/app-contracts-mall";
448
+
449
+ // src/server/cards/recommend-merchants/samples.ts
450
+ var OBSERVED_AT3 = "2026-08-28T00:00:00.000Z";
451
+ var ASSET3 = {
452
+ coffeeLogo: "https://gallery.invalid/brand-guide/coffee-photo.png",
453
+ diningLogo: "https://gallery.invalid/brand-guide/dining-photo.png",
454
+ lifestyleLogo: "https://gallery.invalid/brand-guide/lifestyle-photo.png",
455
+ detailCover: "https://gallery.invalid/brand-guide/detail-cover.png"
456
+ };
457
+ var RECOMMENDATION_DATA = {
458
+ summary: "\u4EB2\u5B50\u73A9\u4E50 \xB7 \u793A\u4F8B\u5E7F\u573A",
459
+ categoryTabs: [
460
+ { code: "food", name: "\u9910\u996E" },
461
+ { code: "coffee", name: "\u5496\u5561" },
462
+ { code: "fashion", name: "\u670D\u9970" },
463
+ { code: "lifestyle", name: "\u751F\u6D3B\u65B9\u5F0F" },
464
+ { code: "sports", name: "\u8FD0\u52A8" }
465
+ ],
466
+ items: [
467
+ {
468
+ merchantId: "recommend-coffee",
469
+ name: "\u65E5\u5149\u5496\u5561\u5B9E\u9A8C\u5BA4",
470
+ logoUrl: ASSET3.coffeeLogo,
471
+ coverUrl: ASSET3.detailCover,
472
+ brand: "\u65E5\u5149\u5496\u5561",
473
+ businessCategories: ["\u5496\u5561", "\u9910\u996E"],
474
+ location: { floorName: "L1", displayText: "A \u5EA7 L1" },
475
+ status: { code: "enabled", label: "\u8425\u4E1A\u4E2D", observedAt: OBSERVED_AT3 },
476
+ operatingStatus: "\u8425\u4E1A\u81F3 22:00",
477
+ rating: "4.8",
478
+ avgSpend: "\xA536",
479
+ description: "\u4EE5\u5F53\u5B63\u5496\u5561\u8C46\u548C\u57CE\u5E02\u7075\u611F\u996E\u54C1\u4E3A\u7279\u8272\uFF0C\u63D0\u4F9B\u9002\u5408\u77ED\u6682\u505C\u7559\u4E0E\u670B\u53CB\u5C0F\u805A\u7684\u660E\u4EAE\u7A7A\u95F4\u3002",
480
+ contactInfo: [
481
+ { channel: "\u8425\u4E1A\u65F6\u95F4", value: "10:00\u201322:00" },
482
+ { channel: "\u7535\u8BDD", value: "tel:4000001122" }
483
+ ],
484
+ services: ["\u5802\u98DF", "\u5916\u5E26"],
485
+ promotionFacts: [],
486
+ itemActions: []
487
+ },
488
+ {
489
+ merchantId: "recommend-fashion",
490
+ name: "\u7EC7\u91CE\u57CE\u5E02\u751F\u6D3B\u9986",
491
+ logoUrl: ASSET3.lifestyleLogo,
492
+ coverUrl: ASSET3.lifestyleLogo,
493
+ businessCategories: ["\u670D\u9970", "\u751F\u6D3B\u65B9\u5F0F"],
494
+ location: { floorName: "L2", displayText: "A \u5EA7 L2" },
495
+ status: { code: "disabled", label: "\u4F11\u606F\u4E2D", observedAt: OBSERVED_AT3 },
496
+ operatingStatus: "10:00 \u5F00\u59CB\u8425\u4E1A",
497
+ rating: "4.6",
498
+ avgSpend: "\xA5128",
499
+ services: ["\u5230\u5E97\u81EA\u63D0"],
500
+ promotionFacts: [],
501
+ itemActions: []
502
+ },
503
+ {
504
+ merchantId: "recommend-dining",
505
+ name: "\u6696\u5C7F\u5BB6\u5EAD\u9910\u5385",
506
+ logoUrl: ASSET3.diningLogo,
507
+ coverUrl: ASSET3.diningLogo,
508
+ businessCategories: ["\u9910\u996E"],
509
+ location: { floorName: "L3", displayText: "B \u5EA7 L3" },
510
+ status: { code: "enabled", label: "\u8425\u4E1A\u4E2D", observedAt: OBSERVED_AT3 },
511
+ operatingStatus: "\u8425\u4E1A\u81F3 21:30",
512
+ rating: "4.7",
513
+ avgSpend: "\xA582",
514
+ contactInfo: [{ channel: "\u7535\u8BDD", value: "tel:4000002233" }],
515
+ services: ["\u513F\u7AE5\u5EA7\u6905", "\u5802\u98DF"],
516
+ promotionFacts: [],
517
+ itemActions: []
518
+ },
519
+ {
520
+ merchantId: "recommend-family",
521
+ name: "\u5C0F\u5C0F\u661F\u7403\u4EB2\u5B50\u6210\u957F\u7A7A\u95F4",
522
+ logoUrl: ASSET3.lifestyleLogo,
523
+ businessCategories: ["\u4EB2\u5B50", "\u5A31\u4E50"],
524
+ location: { floorName: "L4", displayText: "B \u5EA7 L4" },
525
+ status: { code: "enabled", label: "\u8425\u4E1A\u4E2D", observedAt: OBSERVED_AT3 },
526
+ rating: "4.9",
527
+ avgSpend: "\xA596",
528
+ services: ["\u4EB2\u5B50\u53CB\u597D"],
529
+ promotionFacts: [],
530
+ itemActions: []
531
+ },
532
+ {
533
+ merchantId: "recommend-bakery",
534
+ name: "\u9EA6\u753A\u70D8\u7119\u5DE5\u623F",
535
+ logoUrl: ASSET3.coffeeLogo,
536
+ businessCategories: ["\u5496\u5561", "\u9910\u996E"],
537
+ location: { floorName: "L1", displayText: "B \u5EA7 L1" },
538
+ status: { code: "enabled", label: "\u8425\u4E1A\u4E2D", observedAt: OBSERVED_AT3 },
539
+ rating: "4.5",
540
+ avgSpend: "\xA542",
541
+ services: ["\u5916\u5E26"],
542
+ promotionFacts: [],
543
+ itemActions: []
544
+ },
545
+ {
546
+ merchantId: "recommend-sport",
547
+ name: "\u8DC3\u52A8\u8FD0\u52A8\u96C6\u5408\u7A7A\u95F4\u65D7\u8230\u4F53\u9A8C\u5E97",
548
+ businessCategories: ["\u8FD0\u52A8"],
549
+ location: { floorName: "L5", displayText: "A \u5EA7 L5 \u4E2D\u5EAD\u65C1" },
550
+ status: { code: "unknown", label: "\u72B6\u6001\u5F85\u786E\u8BA4", observedAt: OBSERVED_AT3 },
551
+ promotionFacts: [],
552
+ itemActions: []
553
+ },
554
+ {
555
+ merchantId: "recommend-dining-two",
556
+ name: "\u8C37\u5DDD\u6599\u7406\u98DF\u5802",
557
+ logoUrl: ASSET3.diningLogo,
558
+ businessCategories: ["\u9910\u996E"],
559
+ location: { floorName: "L3", displayText: "A \u5EA7 L3 A318" },
560
+ status: { code: "enabled", label: "\u8425\u4E1A\u4E2D", observedAt: OBSERVED_AT3 },
561
+ promotionFacts: [],
562
+ itemActions: []
563
+ },
564
+ {
565
+ merchantId: "recommend-shopping-two",
566
+ name: "\u4E00\u65B9\u751F\u6D3B\u9009\u7269",
567
+ logoUrl: ASSET3.lifestyleLogo,
568
+ businessCategories: ["\u670D\u9970", "\u751F\u6D3B\u65B9\u5F0F"],
569
+ location: { floorName: "L2", displayText: "B \u5EA7 L2 B216" },
570
+ status: { code: "disabled", label: "\u4F11\u606F\u4E2D", observedAt: OBSERVED_AT3 },
571
+ promotionFacts: [],
572
+ itemActions: []
573
+ }
574
+ ],
575
+ observedAt: OBSERVED_AT3
576
+ };
577
+ var samples3 = [
578
+ {
579
+ label: "\u95E8\u5E97\u63A8\u8350\xB7\u5B8C\u6574\u4FE1\u606F",
580
+ note: "\u6700\u591A\u5C55\u793A\u56DB\u4E2A\u7C7B\u76EE Tab\uFF1B\u8BC4\u5206\u3001\u4EBA\u5747\u3001\u8425\u4E1A\u72B6\u6001\u4E0E\u697C\u5C42\u4FE1\u606F\u540C\u5C4F\uFF08\u5951\u7EA6\u5F3A\u5236 https \u56FE\u4F4D \u2192 \u9884\u89C8\u9875\u6052\u7F3A\u56FE\u515C\u5E95\uFF0C\u6709\u56FE\u5F62\u6001\u9700\u771F\u673A\u6570\u636E\uFF09",
581
+ group: "\u95E8\u5E97\u504F\u597D\u63A8\u8350",
582
+ data: RECOMMENDATION_DATA
583
+ },
584
+ {
585
+ label: "\u95E8\u5E97\u63A8\u8350\xB7\u8F7B\u91CF\u4FE1\u606F",
586
+ note: "\u65E0\u8BC4\u5206\u3001\u65E0\u5BA2\u5355\u4EF7\u3001\u65E0 Logo \u7684\u957F\u540D\u79F0\u95E8\u5E97\uFF0C\u9A8C\u8BC1\u53EF\u9009\u5B57\u6BB5\u6536\u7F29",
587
+ group: "\u95E8\u5E97\u504F\u597D\u63A8\u8350",
588
+ data: {
589
+ summary: "\u9002\u5408\u968F\u4FBF\u901B\u901B\u7684\u751F\u6D3B\u65B9\u5F0F\u54C1\u724C",
590
+ categoryTabs: [],
591
+ items: [{
592
+ merchantId: "recommend-minimal",
593
+ name: "\u7F13\u6162\u751F\u957F\u57CE\u5E02\u751F\u6D3B\u65B9\u5F0F\u4E0E\u624B\u4F5C\u96C6\u5408\u7A7A\u95F4",
594
+ businessCategories: ["\u751F\u6D3B\u65B9\u5F0F"],
595
+ location: { floorName: "L3", displayText: "B \u5EA7 L3 \u4E2D\u5EAD\u65C1" },
596
+ status: { code: "unknown", label: "\u72B6\u6001\u5F85\u786E\u8BA4", observedAt: OBSERVED_AT3 },
597
+ promotionFacts: [],
598
+ itemActions: []
599
+ }],
600
+ observedAt: OBSERVED_AT3
601
+ }
602
+ },
603
+ {
604
+ label: "\u95E8\u5E97\u63A8\u8350\xB7\u7A7A\u6001",
605
+ note: "\u63A8\u8350\u7ED3\u679C\u4E3A\u7A7A\u65F6\u5C55\u793A\u89E3\u91CA\u6587\u6848\uFF0C\u4E0D\u663E\u793A\u95E8\u5E97\u8BA1\u6570",
606
+ group: "\u95E8\u5E97\u504F\u597D\u63A8\u8350",
607
+ data: {
608
+ summary: "\u6839\u636E\u5F53\u524D\u504F\u597D\u63A8\u8350",
609
+ categoryTabs: [],
610
+ items: [],
611
+ noResultsReason: "\u6682\u65F6\u6CA1\u6709\u5339\u914D\u7684\u54C1\u724C\uFF0C\u8BD5\u8BD5\u653E\u5BBD\u504F\u597D",
612
+ observedAt: OBSERVED_AT3
613
+ }
614
+ },
615
+ {
616
+ label: "\u95E8\u5E97\u63A8\u8350\xB7\u5386\u53F2\u5361",
617
+ note: "\u5386\u53F2\u6001\u7981\u7528\u7C7B\u76EE Tab\u3001\u95E8\u5E97\u884C\u548C\u6761\u76EE\u52A8\u4F5C",
618
+ group: "\u95E8\u5E97\u504F\u597D\u63A8\u8350",
619
+ data: RECOMMENDATION_DATA,
620
+ isHistory: true
621
+ }
622
+ ];
623
+
624
+ // src/server/cards/recommend-merchants/meta.ts
625
+ var meta11 = {
626
+ cardType: "recommend-merchants",
627
+ dataSchema: recommendMerchantsCardDataSchema,
628
+ displayName: "\u95E8\u5E97\u5BFC\u89C8",
629
+ description: "\u6309\u7C7B\u76EE\u7B5B\u9009\u7684\u63A8\u8350\u95E8\u5E97\u5217\u8868",
630
+ sampleData: {
631
+ summary: "\u4E3A\u60A8\u63A8\u8350\u4EE5\u4E0B\u95E8\u5E97",
632
+ categoryTabs: [
633
+ { code: "food", name: "\u9910\u996E" },
634
+ { code: "fashion", name: "\u670D\u9970" }
635
+ ],
636
+ items: [
637
+ {
638
+ merchantId: "m1",
639
+ name: "\u793A\u4F8B\u95E8\u5E97",
640
+ logoUrl: "https://example.com/logo.png",
641
+ brand: "\u793A\u4F8B\u54C1\u724C",
642
+ businessCategories: ["\u9910\u996E"],
643
+ location: { displayText: "A \u680B 3 \u697C 301", floorName: "3F", buildingName: "A \u680B" },
644
+ status: { code: "enabled", label: "\u8425\u4E1A\u4E2D", observedAt: nowIso() },
645
+ promotionFacts: [],
646
+ itemActions: []
647
+ }
648
+ ],
649
+ noResultsReason: void 0,
650
+ observedAt: nowIso()
651
+ },
652
+ samples: samples3,
653
+ schemaVersion: 1
654
+ };
655
+ var meta_default11 = meta11;
656
+
657
+ // src/server/tools/index.ts
658
+ import { createTool, coerceStringifiedFields, requireToolRequestContext, withCardEmissionHint, internalTool } from "@tbox.cn/app-sdk/server";
659
+ import { z } from "zod";
660
+ import { mallSubjectIdOf } from "@tbox.cn/app-contracts-mall";
661
+
662
+ // src/server/ports/index.ts
663
+ import {
664
+ mallScopeOf,
665
+ parseMallScope as parseMallScope2,
666
+ SHOPPING_CATALOG_SERVICE,
667
+ SHOPPING_CATEGORIES_SERVICE,
668
+ SHOPPING_DIRECTORY_SERVICE,
669
+ SHOPPING_SHOPS_SERVICE
670
+ } from "@tbox.cn/app-contracts-mall";
671
+ import { isExpectedProviderAbsence } from "@tbox.cn/app-contracts";
672
+
673
+ // src/server/ports/local-adapters.ts
674
+ var LocalNavigationAdapter = class {
675
+ async getLocation(_merchantId, _ctx) {
676
+ return null;
677
+ }
678
+ async listNearbyMalls(_ctx, _query) {
679
+ return [];
680
+ }
681
+ async listBrowsingHistory(_ctx, _page, _pageSize) {
682
+ return { items: [], page: 1, pageSize: 10, total: 0, hasMore: false };
683
+ }
684
+ };
685
+
686
+ // src/server/ports/index.ts
687
+ async function resolveShoppingGuidePorts(reqCtx, ctx) {
688
+ const mallId = currentMallId(reqCtx) ?? "none";
689
+ const local = await localPorts(ctx, mallId);
690
+ if (!ctx.integrations) {
691
+ return {
692
+ catalog: new EmptyCatalogAdapter(),
693
+ shop: new EmptyShopAdapter(),
694
+ category: new EmptyCategoryAdapter(),
695
+ directory: new EmptyDirectoryAdapter(),
696
+ ...local
697
+ };
698
+ }
699
+ const [catalog, shop, category, directory] = await Promise.all([
700
+ resolveGuideSlot(SHOPPING_CATALOG_SERVICE, reqCtx, ctx, new EmptyCatalogAdapter()),
701
+ resolveGuideSlot(SHOPPING_SHOPS_SERVICE, reqCtx, ctx, new EmptyShopAdapter()),
702
+ resolveGuideSlot(SHOPPING_CATEGORIES_SERVICE, reqCtx, ctx, new EmptyCategoryAdapter()),
703
+ resolveGuideSlot(SHOPPING_DIRECTORY_SERVICE, reqCtx, ctx, new EmptyDirectoryAdapter())
704
+ ]);
705
+ return { catalog, shop, category, directory, ...local };
706
+ }
707
+ async function resolveGuideSlot(service, reqCtx, ctx, fallback) {
708
+ try {
709
+ return await ctx.integrations.resolveService({
710
+ service,
711
+ scope: mallScopeOf(reqCtx),
712
+ request: reqCtx
713
+ });
714
+ } catch (e) {
715
+ if (isExpectedProviderAbsence(e)) return fallback;
716
+ const code = e.code;
717
+ if (code === "PROVIDER_NOT_IMPLEMENTED") return fallback;
718
+ throw e;
719
+ }
720
+ }
721
+ function resolveMallDirectory(ctx) {
722
+ return ctx.services.resolve?.("mall-directory");
723
+ }
724
+ function withMallDirectoryNavigation(base, ctx) {
725
+ const directory = resolveMallDirectory(ctx);
726
+ if (!directory) return base;
727
+ return {
728
+ ...base,
729
+ async listNearbyMalls(q, query) {
730
+ const fromService = directory.nearbyMalls(query ? { query } : {});
731
+ if (fromService.length > 0) return fromService;
732
+ return base.listNearbyMalls(q, query);
733
+ }
734
+ };
735
+ }
736
+ function currentMallId(reqCtx) {
737
+ return parseMallScope2(reqCtx?.attributes)?.mallId;
738
+ }
739
+ var LOCAL_ADAPTER_CACHE_TTL_MS = 30 * 60 * 1e3;
740
+ var localAdapterCache = /* @__PURE__ */ new Map();
741
+ async function localPorts(ctx, mallId) {
742
+ const cachedLocal = localAdapterCache.get(mallId);
743
+ if (cachedLocal && Date.now() - cachedLocal.at < LOCAL_ADAPTER_CACHE_TTL_MS) {
744
+ return cachedLocal;
745
+ }
746
+ const baseNav = withMallDirectoryNavigation(new LocalNavigationAdapter(), ctx);
747
+ const local = { navigation: baseNav };
748
+ localAdapterCache.set(mallId, { ...local, at: Date.now() });
749
+ return local;
750
+ }
751
+ var EmptyCatalogAdapter = class {
752
+ async searchProducts() {
753
+ return { items: [], page: 1, pageSize: 10, total: 0, hasMore: false };
754
+ }
755
+ async getProduct() {
756
+ return null;
757
+ }
758
+ async getFacets() {
759
+ return { brands: [], categories: [], priceRanges: [], floors: [] };
760
+ }
761
+ };
762
+ var EmptyShopAdapter = class {
763
+ async searchShops() {
764
+ return { items: [], page: 1, pageSize: 10, total: 0, hasMore: false };
765
+ }
766
+ async getShop() {
767
+ return null;
768
+ }
769
+ };
770
+ var EmptyCategoryAdapter = class {
771
+ async listCategories() {
772
+ return [];
773
+ }
774
+ };
775
+ var EmptyDirectoryAdapter = class {
776
+ async getDirectory() {
777
+ return null;
778
+ }
779
+ };
780
+
781
+ // src/server/projections/index.ts
782
+ function amapSearchUrl(keyword) {
783
+ return `https://uri.amap.com/search?keyword=${encodeURIComponent(keyword)}`;
784
+ }
785
+ function mapLinkForLocation(mallNameFallback, location) {
786
+ const keyword = [mallNameFallback, location?.buildingName, location?.floorName].filter(Boolean).join(" ");
787
+ return amapSearchUrl(keyword || mallNameFallback);
788
+ }
789
+ var MAX_MERCHANT_CARD_ITEMS = 200;
790
+ function projectShopList(context, page, summary, categoryTabs, mallId, miniAppId, maxItems = MAX_MERCHANT_CARD_ITEMS) {
791
+ const visible = page.items.slice(0, maxItems);
792
+ return {
793
+ context,
794
+ ...mallId ? { mallId } : {},
795
+ ...miniAppId ? { miniAppId } : {},
796
+ ...summary ? { summary } : {},
797
+ ...categoryTabs && categoryTabs.length > 0 ? { categoryTabs: categoryTabs.map((t) => ({ code: t.code, name: t.name })) } : {},
798
+ items: visible.map((m) => ({
799
+ merchantId: m.merchantId,
800
+ name: m.name,
801
+ ...m.logoUrl ? { logoUrl: m.logoUrl } : {},
802
+ ...m.coverUrls[0] ? { coverUrl: m.coverUrls[0] } : {},
803
+ ...m.brand ? { brand: m.brand } : {},
804
+ businessCategories: [...m.businessCategories],
805
+ location: m.location,
806
+ status: m.status,
807
+ ...m.contactInfo && m.contactInfo.length > 0 ? { contactInfo: [...m.contactInfo] } : {},
808
+ services: [...m.services],
809
+ promotionFacts: [...m.promotionFacts],
810
+ itemActions: [
811
+ // 「查看详情」改为客户端整行点击发 visible:false 静默消息触发——不在 itemActions 挂按钮
812
+ { kind: "link", label: "\u5BFC\u822A", url: mapLinkForLocation(m.name, m.location) }
813
+ ]
814
+ })),
815
+ ...visible.length > 0 ? { pageInfo: { page: page.page, pageSize: page.pageSize, total: page.total, hasMore: page.hasMore } } : {},
816
+ refinements: []
817
+ };
818
+ }
819
+ function projectShopDetail(m, mallId, miniAppId) {
820
+ return {
821
+ merchantId: m.merchantId,
822
+ name: m.name,
823
+ ...mallId ? { mallId } : {},
824
+ ...miniAppId ? { miniAppId } : {},
825
+ ...m.logoUrl ? { logoUrl: m.logoUrl } : {},
826
+ coverUrls: [...m.coverUrls],
827
+ ...m.brand ? { brand: m.brand } : {},
828
+ businessCategories: [...m.businessCategories],
829
+ location: m.location,
830
+ status: m.status,
831
+ ...m.description ? { description: m.description } : {},
832
+ ...m.contactInfo ? { contactInfo: [...m.contactInfo] } : {},
833
+ services: [...m.services],
834
+ promotionFacts: [...m.promotionFacts],
835
+ ...m.coupons && m.coupons.length > 0 ? { coupons: m.coupons.map((c) => ({ ...c })) } : {},
836
+ evidence: [],
837
+ itemActions: [
838
+ { kind: "link", label: "\u5BFC\u822A", url: mapLinkForLocation(m.name, m.location) }
839
+ ]
840
+ };
841
+ }
842
+
843
+ // src/server/tools/index.ts
844
+ var str = (desc) => z.string().describe(desc);
845
+ var optionalStr = (desc) => z.string().optional().describe(desc);
846
+ function coerce(schema) {
847
+ return z.preprocess(coerceStringifiedFields, schema);
848
+ }
849
+ function toContext(reqCtx) {
850
+ return toShoppingQueryContext(reqCtx, mallSubjectIdOf(reqCtx));
851
+ }
852
+ function reqCtxOf(execCtx) {
853
+ return requireToolRequestContext(execCtx);
854
+ }
855
+ function contextWithMallId(reqCtx, mallId) {
856
+ const base = toContext(reqCtx);
857
+ const override = typeof mallId === "string" && mallId.trim() ? mallId.trim() : void 0;
858
+ if (!override || override === base.scope.mallId) return base;
859
+ return { ...base, scope: scopeFromMallId(reqCtx, override) };
860
+ }
861
+ var pageFields = {
862
+ page: z.string().optional().describe("\u9875\u7801\uFF08\u4ECE 1 \u5F00\u59CB\uFF0C\u5B57\u7B26\u4E32\uFF09"),
863
+ pageSize: z.string().optional().describe("\u6BCF\u9875\u6761\u6570\uFF08\u5B57\u7B26\u4E32\uFF0C\u7F3A\u7701 200\uFF09")
864
+ };
865
+ function parsePage(page, pageSize) {
866
+ const p = Math.max(1, Number(page) || 1);
867
+ const s = Math.min(200, Math.max(1, Number(pageSize) || 200));
868
+ return { page: p, pageSize: s };
869
+ }
870
+ var KEYWORD_FANOUT_MAX = 3;
871
+ function withCards(data, cardType, note, summary) {
872
+ return { summary, cards: [{ cardType, data, note }] };
873
+ }
874
+ function shopListNote(data, total) {
875
+ const visible = data.items.length;
876
+ const all = total ?? visible;
877
+ const heads = data.items.slice(0, 3).map((m) => m.location.floorName ? `${m.name}\uFF08${m.location.floorName}\uFF09` : m.name);
878
+ if (heads.length === 0) return `${all} \u5BB6\u95E8\u5E97`;
879
+ const countTail = all > visible ? `\uFF08\u5171 ${all} \u5BB6\u95E8\u5E97\uFF0C\u5F53\u524D\u5C55\u793A\u524D ${visible} \u5BB6\uFF09` : visible > 3 ? ` \u7B49 ${visible} \u5BB6\u95E8\u5E97` : "";
880
+ return heads.join("\u3001") + countTail;
881
+ }
882
+ var CN_FLOOR_NUM = {
883
+ \u4E00: 1,
884
+ \u4E8C: 2,
885
+ \u4E09: 3,
886
+ \u56DB: 4,
887
+ \u4E94: 5,
888
+ \u516D: 6,
889
+ \u4E03: 7,
890
+ \u516B: 8,
891
+ \u4E5D: 9,
892
+ \u5341: 10
893
+ };
894
+ function normalizeFloorKey(text) {
895
+ const t = text.trim().toUpperCase().replace(/\s+/g, "");
896
+ if (!t) return void 0;
897
+ const neg = t.match(/^(?:B|负)(\d+)(?:楼|层|F)?$/);
898
+ if (neg) return `B${Number(neg[1])}`;
899
+ const negCn = t.match(/^负([一二三四五六七八九十])楼?$/);
900
+ if (negCn) return `B${CN_FLOOR_NUM[negCn[1]]}`;
901
+ const pos = t.match(/^(?:第)?(\d+)(?:楼|层|F)?$/);
902
+ if (pos) return `${Number(pos[1])}`;
903
+ const posCn = t.match(/^(?:第)?([一二三四五六七八九十])(?:楼|层)?$/);
904
+ if (posCn) return `${CN_FLOOR_NUM[posCn[1]]}`;
905
+ return void 0;
906
+ }
907
+ var FLOOR_MENTION_RE = /B\s*\d+\s*(?:楼|层)?|负\s*[一二三四五六七八九十\d]+\s*(?:楼|层)?|第\s*[一二三四五六七八九十\d]+\s*[楼层]|[一二三四五六七八九十\d]+\s*(?:楼|层|F\b)/g;
908
+ function extractFloorMentions(text) {
909
+ const seen = /* @__PURE__ */ new Set();
910
+ const out = [];
911
+ for (const m of text.matchAll(FLOOR_MENTION_RE)) {
912
+ const raw = m[0].trim();
913
+ const key = normalizeFloorKey(raw);
914
+ if (key && !seen.has(key)) {
915
+ seen.add(key);
916
+ out.push(raw);
917
+ }
918
+ }
919
+ return out.slice(0, 3);
920
+ }
921
+ var CATEGORY_WORDS = [
922
+ "\u8D2D\u7269",
923
+ "\u9910\u996E",
924
+ "\u7F8E\u98DF",
925
+ "\u751F\u6D3B",
926
+ "\u5A31\u4E50",
927
+ "\u513F\u7AE5",
928
+ "\u4EB2\u5B50",
929
+ "\u670D\u9970",
930
+ "\u670D\u88C5",
931
+ "\u8FD0\u52A8",
932
+ "\u7F8E\u5986",
933
+ "\u73E0\u5B9D",
934
+ "\u8D85\u5E02",
935
+ "\u5F71\u9662",
936
+ "\u5065\u8EAB",
937
+ "\u96F6\u552E",
938
+ "\u4F11\u95F2"
939
+ ];
940
+ function extractCategoryMentions(text) {
941
+ const seen = /* @__PURE__ */ new Set();
942
+ const out = [];
943
+ for (const w of CATEGORY_WORDS) {
944
+ if (text.includes(w) && !seen.has(w)) {
945
+ seen.add(w);
946
+ out.push(w);
947
+ }
948
+ }
949
+ return out.slice(0, 3);
950
+ }
951
+ var CATEGORY_SYNONYMS = {
952
+ \u7F8E\u98DF: ["\u9910\u996E"],
953
+ \u4EB2\u5B50: ["\u513F\u7AE5"],
954
+ \u670D\u9970: ["\u670D\u88C5"],
955
+ \u96F6\u552E: ["\u8D2D\u7269"],
956
+ \u4F11\u95F2: ["\u5A31\u4E50"]
957
+ };
958
+ var summaries = {
959
+ shopList: (d, allItems) => {
960
+ return JSON.stringify({
961
+ total: d.pageInfo?.total ?? d.items.length,
962
+ context: d.context,
963
+ ...d.summary ? { summary: d.summary } : {},
964
+ shops: (allItems ?? []).map((s) => ({
965
+ name: s.name,
966
+ ...s.brand ? { brand: s.brand } : {},
967
+ location: s.location?.displayText ?? s.location?.unitName,
968
+ categories: s.businessCategories,
969
+ ...s.status?.label ? { status: s.status.label } : {},
970
+ ...s.promotionFacts?.length ? { promotions: s.promotionFacts } : {},
971
+ ...s.services?.length ? { services: s.services } : {},
972
+ ...s.description ? { description: s.description } : {},
973
+ ...s.contactInfo?.length ? { phone: s.contactInfo.map((c) => c.value).join(", ") } : {},
974
+ ...s.coupons?.length ? { coupons: s.coupons.map((c) => ({ name: c.name, ...c.faceValue !== void 0 ? { faceValue: c.faceValue } : {}, ...c.salePrice !== void 0 ? { salePrice: c.salePrice } : {} })) } : {}
975
+ }))
976
+ });
977
+ },
978
+ shopDetail: (d) => JSON.stringify(d)
979
+ };
980
+ function buildShopListCard(result, q, noFilter, maxItems) {
981
+ const data = projectShopList(
982
+ "search",
983
+ result,
984
+ result.items.length === 0 ? "\u672A\u627E\u5230\u5339\u914D\u7684\u95E8\u5E97\u3002" : void 0,
985
+ void 0,
986
+ q.scope.mallId || void 0,
987
+ q.scope.miniAppId || void 0,
988
+ maxItems
989
+ );
990
+ if (noFilter && data.items.length > 0) {
991
+ const tabs = [...new Set(data.items.flatMap((m) => m.businessCategories))].filter((name) => name && !name.includes("\u6D4B\u8BD5") && !name.includes("erp") && !name.includes("\u672A\u5F52\u7C7B")).slice(0, 6).map((name) => ({ code: name, name }));
992
+ if (tabs.length > 0) data.categoryTabs = tabs;
993
+ }
994
+ return data;
995
+ }
996
+ function createShoppingGuideTools(opts) {
997
+ const portsOf = (execCtx) => {
998
+ const ctx = opts.getCtx();
999
+ return resolveShoppingGuidePorts(requireToolRequestContext(execCtx), ctx);
1000
+ };
1001
+ const exec = (fn) => {
1002
+ return async (args, execCtx) => {
1003
+ const ctx = opts.getCtx();
1004
+ try {
1005
+ return await fn(await portsOf(execCtx), ctx, args, execCtx);
1006
+ } catch (err) {
1007
+ const message = err instanceof Error ? err.message : String(err);
1008
+ console.warn(`[shopping-guide] tool exec error: ${message}`);
1009
+ return { found: false, message: "\u6682\u65F6\u65E0\u6CD5\u67E5\u8BE2\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5" };
1010
+ }
1011
+ };
1012
+ };
1013
+ const searchShops = createTool({
1014
+ id: "search-shops",
1015
+ description: '\u95E8\u5E97\u641C\u7D22/\u5217\u8868\uFF1A\u6309\u54C1\u724C\u8BCD\u3001\u7C7B\u76EE\u3001\u697C\u5C42\u3001\u697C\u680B\u641C\u7D22\u6216\u6D4F\u89C8\u95E8\u5E97\u3002\u8F93\u51FA shop-list\uFF08\u5361\u7247\u81EA\u5E26\u7C7B\u76EE Tab\uFF09\u3002\n\u3010\u96F6\u53C2\u6570 = \u63A2\u7D22\u6027\u5168\u91CF\u6D4F\u89C8\u3011\u4EE5\u4E0B\u610F\u56FE\u5FC5\u987B\u4E0D\u4F20\u4EFB\u4F55\u53C2\u6570\u76F4\u63A5\u8C03\u7528\u672C\u5DE5\u5177\uFF1A\n "\u901B\u4EC0\u4E48" / "\u6709\u4EC0\u4E48\u597D\u901B\u7684" / "\u968F\u4FBF\u901B\u901B" / "\u4ECA\u5929\u60F3\u901B\u901B" / "\u5546\u573A\u6709\u4EC0\u4E48" / "\u6709\u54EA\u4E9B\u95E8\u5E97" / "\u6709\u4EC0\u4E48\u53EF\u901B\u7684" / "\u5E2E\u6211\u627E\u627E\u95E8\u5E97" / "\u770B\u770B\u6709\u4EC0\u4E48"\n \u2192 \u8FD4\u56DE\u5168\u91CF\u95E8\u5E97\u5217\u8868\uFF0C\u5361\u7247\u81EA\u5E26\u7C7B\u76EE Tab\uFF0C\u7528\u6237\u53EF\u5728\u5361\u7247\u4E0A\u81EA\u884C\u7B5B\u9009\uFF0C\u65E0\u9700\u5148\u5217\u7C7B\u76EE\u518D\u8FFD\u95EE\u3002\n\u7ED3\u679C\u5DF2\u542B\u95E8\u5E97\u540D\u3001\u54C1\u7C7B\u3001\u697C\u680B/\u697C\u5C42/\u94FA\u4F4D\u3001\u8425\u4E1A\u72B6\u6001\u3001\u4FC3\u9500\u4FE1\u606F\uFF0C\u65E0\u9700\u518D\u8C03 get-shop \u8865\u4F4D\u7F6E\u3002\n\u3010\u53C2\u6570\u586B\u5145\u89C4\u5219\u3011businessCategory/floorCode/buildingCode \u7684\u5408\u6CD5\u503C\u6765\u81EA mall-context \u6CE8\u5165\u5757\uFF08\u672C\u8F6E\u6216\u4F1A\u8BDD\u5185\u5386\u53F2\u8F6E\u5747\u6709\u6548\u2014\u2014\u697C\u680B/\u697C\u5C42/\u7C7B\u76EE\u7F16\u7801\u4F1A\u8BDD\u5185\u4E0D\u53D8\uFF09\uFF1A\n - businessCategory = categories[].code\uFF08\u7C7B\u76EE\u7F16\u7801\uFF09\n - floorCode = floors[].id\uFF08\u697C\u5C42 ID\uFF09\n - buildingCode = blocks[].id\uFF08\u697C\u680B ID\uFF09\n\u3010\u8DEF\u7531\u903B\u8F91\u3011\u6709\u54C1\u724C/\u5E97\u540D\u5173\u952E\u8BCD \u2192 \u586B keywords\uFF1B\u7EAF\u6309\u7C7B\u76EE/\u697C\u5C42\u7B5B \u2192 \u53EA\u586B\u5BF9\u5E94\u7F16\u7801\uFF1B\u697C\u5C42+\u7C7B\u76EE\u7EC4\u5408\uFF08\u5982"3\u697C\u6709\u9910\u996E\u5417"\uFF09\u2192 \u540C\u65F6\u586B floorCode + businessCategory\uFF0C\u4E00\u6B21\u8C03\u7528\u62FF\u5230\u8BE5\u697C\u5C42\u6307\u5B9A\u7C7B\u76EE\u95E8\u5E97\u3002\n\u3010\u68C0\u7D22\u5F15\u5BFC\u3011\u9996\u6B21\u641C\u7D22\uFF1A\u53EA\u586B keywords\uFF08\u884C\u4E1A\u901A\u79F0\u5E76\u5217\u540C\u4E49\u8BCD\uFF0C\u5982 ["\u7F8E\u5986","\u5F69\u5986"] \u6216 ["\u751C\u54C1","\u86CB\u7CD5"]\uFF1B\u54C1\u724C\u540D\u5FC5\u987B\u4E2D\u82F1\u6587/\u522B\u540D\u5E76\u5217\u591A\u89D2\u5EA6\u2014\u2014["\u80AF\u5FB7\u57FA","KFC"]\u3001["\u661F\u5DF4\u514B","Starbucks"]\u3001["\u9EA6\u5F53\u52B3","\u91D1\u62F1\u95E8"]\uFF0C\u9AD8\u9891\u8FDE\u9501\u54C1\u724C\u5E97\u540D\u5E38\u53EA\u7F72\u82F1\u6587\u540D\uFF0C\u53EA\u4F20\u4E2D\u6587\u540D\u4F1A\u6F0F\u53EC\u56DE\uFF09\uFF0C\u4E0D\u8981\u540C\u65F6\u586B businessCategory\u2014\u2014\u9996\u6B21\u53EA\u7528\u5173\u952E\u8BCD\u641C\u3002\u96F6\u7ED3\u679C\u540E\u7981\u6B62\u518D\u6362\u540C\u4E49\u8BCD\u91CD\u8BD5\uFF0C\u6309\u4EE5\u4E0B\u987A\u5E8F\u964D\u7EA7\uFF08\u6BCF\u6B21\u53EA\u7528\u4E00\u4E2A\u53C2\u6570\uFF0C\u4E0D\u8981\u6DF7\u586B\uFF09\uFF1A\u2460\u5C06\u7528\u6237\u610F\u56FE\u6620\u5C04\u5230 mall-context \u7C7B\u76EE\u7F16\u7801\uFF08\u5982"\u4E70\u978B/\u4E70\u8863\u670D"\u2192 categories[].code "\u8D2D\u7269"\uFF0C"\u5403\u996D/\u706B\u9505/\u751C\u54C1"\u2192 "\u9910\u996E"\uFF09\uFF0C\u4EC5\u4F20 businessCategory \u91CD\u67E5\uFF08\u4E0D\u52A0 keywords\uFF0C\u8BA9\u8BE5\u7C7B\u76EE\u4E0B\u95E8\u5E97\u5168\u91CF\u8FD4\u56DE\uFF09\uFF1B\u2461\u4ECD\u65E0\u7ED3\u679C\u6539\u7528\u65E0\u53C2\u6570\u5168\u91CF\u6D4F\u89C8\uFF08\u5361\u7247\u81EA\u5E26\u7C7B\u76EE Tab \u4F9B\u7528\u6237\u81EA\u884C\u7B5B\u9009\uFF09\u3002\u540C\u4E00\u67E5\u8BE2\u6700\u591A\u8C03\u7528\u672C\u5DE5\u5177 2 \u6B21\uFF08\u9996\u6B21 + 1 \u6B21\u964D\u7EA7\uFF09\uFF0C\u7981\u6B62\u53CD\u590D\u8BD5\u53C2\u3002',
1016
+ // W2(2026-09-01):机制句(标签语法/出卡规则)归平台段单源——此处由 wrap 追加预告知句,删除【出卡规则】整段
1017
+ inputSchema: z.object({
1018
+ keywords: z.preprocess(
1019
+ // LLM 有时输出裸字符串(如 "美妆")而非数组,统一包成数组再走 coerce
1020
+ (val) => {
1021
+ if (typeof val === "string") {
1022
+ try {
1023
+ return JSON.parse(val);
1024
+ } catch {
1025
+ return [val];
1026
+ }
1027
+ }
1028
+ return val;
1029
+ },
1030
+ coerce(
1031
+ // F5a:max 提至 10(模型偶尔列 4-5 个相关词,max(5) 会硬拒触发校验重试浪费整轮;
1032
+ // describe 明写「最多 3 个超出取前 3」+ execute 软截 KEYWORD_FANOUT_MAX=3——接受面与硬限对齐)
1033
+ z.array(z.string()).min(1).max(10).describe(
1034
+ '\u54C1\u724C\u540D/\u5E97\u540D/\u4E1A\u6001\u5173\u952E\u8BCD\u6570\u7EC4\uFF0C\u6700\u591A 3 \u4E2A\uFF08\u8D85\u51FA\u4EC5\u53D6\u524D 3\uFF09\uFF0C\u5982 ["\u7F8E\u5986","\u5F69\u5986"] \u6216 ["\u513F\u7AE5\u670D\u88C5","\u5496\u5561"]\u3002\u3010\u5408\u5E76\u89C4\u5219\u3011\u7528\u6237\u4E00\u6761\u8BF7\u6C42\u63D0\u5230\u7684\u591A\u4E2A\u54C1\u7C7B/\u54C1\u724C/\u5E97\u540D\u5E76\u5165\u540C\u4E00\u6B21\u8C03\u7528\u2014\u2014\u7ED3\u679C\u5408\u5E76\u4E3A\u4E00\u5F20\u5361\u5E76\u81EA\u5E26\u54C1\u7C7B Tab\uFF1B\u4EC5\u5F53\u4E0D\u540C\u8BC9\u6C42\u9700\u8981\u4E0D\u540C\u7684\u697C\u5C42/\u697C\u680B/\u7C7B\u76EE\u7B5B\u9009\u65F6\u624D\u62C6\u5206\u8C03\u7528\u3002\u3010\u91CD\u8981\u3011\u5FC5\u987B\u662F\u5408\u6CD5 JSON \u5B57\u7B26\u4E32\u6570\u7EC4\uFF0C\u6BCF\u4E2A\u5143\u7D20\u52A0\u53CC\u5F15\u53F7\uFF0C\u7981\u6B62\u5199\u88F8\u5B57\u7B26\u4E32\uFF08\u5982 \u7F8E\u5986\uFF09\u3002\u7EAF\u6309\u7C7B\u76EE/\u697C\u5C42\u6D4F\u89C8\u65F6\u4E0D\u586B\u6B64\u5B57\u6BB5\u3002'
1035
+ ).optional()
1036
+ ).optional()
1037
+ ),
1038
+ businessCategory: optionalStr("\u7C7B\u76EE\u7F16\u7801\uFF08\u6765\u81EA pre-tool \u4E0A\u4E0B\u6587 categories[].code\uFF09\uFF1B\u6309\u7C7B\u76EE\u6D4F\u89C8\u65F6\u586B\u5199"),
1039
+ floorCode: optionalStr("\u697C\u5C42 ID\uFF08\u6765\u81EA pre-tool \u4E0A\u4E0B\u6587 floors[].id\uFF09\uFF1B\u6309\u697C\u5C42\u7B5B\u9009\u65F6\u586B\u5199"),
1040
+ buildingCode: optionalStr("\u697C\u680B ID\uFF08\u6765\u81EA pre-tool \u4E0A\u4E0B\u6587 blocks[].id\uFF09\uFF1B\u6309\u697C\u680B\u7B5B\u9009\u65F6\u586B\u5199"),
1041
+ ...pageFields
1042
+ }),
1043
+ execute: exec(async (ports, _ctx, args, execCtx) => {
1044
+ const q = toContext(reqCtxOf(execCtx));
1045
+ const { page, pageSize } = parsePage(args.page, args.pageSize);
1046
+ const rawKeywords = args.keywords;
1047
+ const keywords = (rawKeywords ?? []).slice(0, KEYWORD_FANOUT_MAX);
1048
+ if ((rawKeywords?.length ?? 0) > KEYWORD_FANOUT_MAX) {
1049
+ console.warn(`[search-shops] keywords \u8D85\u91CF\uFF08${rawKeywords.length}\uFF09\uFF0C\u622A\u65AD\u81F3\u524D ${KEYWORD_FANOUT_MAX}\uFF1A\u4E22\u5F03 ${JSON.stringify(rawKeywords.slice(KEYWORD_FANOUT_MAX))}`);
1050
+ }
1051
+ const hasFilter = keywords.length || args.businessCategory || args.floorCode || args.buildingCode;
1052
+ const criteria = {
1053
+ ctx: q,
1054
+ // keywords 数组为唯一真源(provider 逐词扇出/单值直通;不再 join 拼串——
1055
+ // 厂商单值模糊匹配下拼串必不命中,契约注释已封堵)
1056
+ keywords,
1057
+ ...args.businessCategory ? { businessCategory: String(args.businessCategory) } : {},
1058
+ ...args.floorCode ? { floorCode: String(args.floorCode) } : {},
1059
+ ...args.buildingCode ? { buildingCode: String(args.buildingCode) } : {},
1060
+ page,
1061
+ pageSize
1062
+ };
1063
+ console.warn(`[search-shops] input keywords=${JSON.stringify(criteria.keywords)} businessCategory=${args.businessCategory ?? ""} floorCode=${args.floorCode ?? ""} buildingCode=${args.buildingCode ?? ""} page=${page}`);
1064
+ const result = await ports.shop.searchShops(criteria);
1065
+ console.warn(`[search-shops] output total=${result.total} items=${result.items.length} first=${result.items[0]?.name ?? "(empty)"}`);
1066
+ const data = buildShopListCard(result, q, !hasFilter);
1067
+ if (data.items.length === 0) return { summary: summaries.shopList(data) };
1068
+ return withCards(data, "shop-list", shopListNote(data, result.total), summaries.shopList(data, result.items));
1069
+ })
1070
+ });
1071
+ const getShop = createTool({
1072
+ id: "get-shop",
1073
+ description: "\u95E8\u5E97\u8BE6\u60C5\uFF1A\u52A0\u8F7D\u5355\u4E2A\u95E8\u5E97\u7684\u5B8C\u6574\u5FEB\u7167\uFF08\u56FE\u7247/\u7B80\u4ECB/\u8054\u7CFB\u65B9\u5F0F\uFF09\u3002\u4EC5\u5F53\u7528\u6237\u70B9\u51FB\u95E8\u5E97\u5361\u7247\u8981\u770B\u8BE6\u60C5\u65F6\u8C03\u7528\u3002\u8F93\u51FA shop-detail\u3002",
1074
+ inputSchema: z.object({ shopId: str("\u95E8\u5E97 ID\uFF08\u6765\u81EA\u641C\u7D22\u7ED3\u679C\u5361\uFF09") }),
1075
+ execute: exec(async (ports, _ctx, args, execCtx) => {
1076
+ console.warn(`[get-shop] input shopId="${args.shopId}"`);
1077
+ const shop = await ports.shop.getShop(String(args.shopId), toContext(reqCtxOf(execCtx)));
1078
+ console.warn(`[get-shop] output found=${!!shop} name="${shop?.name ?? ""}"`);
1079
+ if (!shop) {
1080
+ return { summary: JSON.stringify({ error: "not_found" }) };
1081
+ }
1082
+ const shopCtx = toContext(reqCtxOf(execCtx));
1083
+ const data = projectShopDetail(shop, shopCtx.scope.mallId || void 0, shopCtx.scope.miniAppId || void 0);
1084
+ return withCards(
1085
+ data,
1086
+ "shop-detail",
1087
+ `${data.name}\uFF08${data.location?.displayText ?? "\u95E8\u5E97\u8BE6\u60C5"}\uFF09`,
1088
+ summaries.shopDetail(data)
1089
+ );
1090
+ })
1091
+ });
1092
+ const mallContext = createTool({
1093
+ id: "mall-context",
1094
+ description: "\u3010\u5185\u90E8\u5DE5\u5177\uFF0C\u6A21\u578B\u52FF\u8C03\u7528\u3011\u9884\u52A0\u8F7D\u5546\u573A\u697C\u680B+\u7C7B\u76EE\u4E0A\u4E0B\u6587\uFF0C\u4F9B search-shops \u53C2\u6570\u586B\u5145\u3002",
1095
+ // B3:mallId 入参化——decide 自 mallSlot.read(attributes) 注入;去重键随 mallId 变更自动换键
1096
+ inputSchema: z.object({ mallId: str("\u5546\u5708 ID\uFF08pre-tool decide \u6CE8\u5165\uFF09") }),
1097
+ execute: exec(async (ports, _ctx, args, execCtx) => {
1098
+ const q = contextWithMallId(reqCtxOf(execCtx), args.mallId);
1099
+ const categoryPort = ports.category;
1100
+ const [tagsResult, directory] = await Promise.allSettled([
1101
+ categoryPort.listTags?.(q) ?? ports.category.listCategories(q).then((cs) => cs.map((c) => c.name)),
1102
+ ports.directory.getDirectory(q)
1103
+ ]);
1104
+ const tagList = tagsResult.status === "fulfilled" ? tagsResult.value : [];
1105
+ const dir = directory.status === "fulfilled" ? directory.value : null;
1106
+ const cats = tagList.map((name) => ({ code: name, name }));
1107
+ const floors = dir?.buildings?.flatMap(
1108
+ (b) => b.floors.map((f) => ({ id: f.floorCode ?? f.floorName, name: f.floorName, building: b.buildingName }))
1109
+ ) ?? [];
1110
+ const blocks = dir?.buildings?.map((b) => ({ id: b.buildingCode ?? b.buildingName, name: b.buildingName })) ?? [];
1111
+ console.warn(`[mall-context] preloaded categories=${cats.length} floors=${floors.length} blocks=${blocks.length}`);
1112
+ return { categories: cats, floors, blocks };
1113
+ })
1114
+ });
1115
+ const floorShops = createTool({
1116
+ id: "floor-shops",
1117
+ description: "\u3010\u5185\u90E8\u5DE5\u5177\uFF0C\u6A21\u578B\u52FF\u8C03\u7528\u3011\u697C\u5C42\u95EE\u53E5\u786E\u5B9A\u6027\u9884\u6267\u884C\uFF1A\u6309\u697C\u5C42\u5F15\u7528\u9884\u67E5\u95E8\u5E97\uFF0C\u51FA shop-list\u3002",
1118
+ inputSchema: z.object({ floorQuery: str('\u697C\u5C42\u5F15\u7528\u6587\u672C\uFF08\u9017\u53F7\u5206\u9694\u591A\u697C\u5C42\uFF0C\u5982 "3\u697C,4\u697C"\uFF09') }),
1119
+ execute: exec(async (ports, _ctx, args, execCtx) => {
1120
+ const q = toContext(reqCtxOf(execCtx));
1121
+ const floorQuery = String(args.floorQuery ?? "").trim();
1122
+ if (!floorQuery) return { summary: JSON.stringify({ error: "floor_query_empty" }) };
1123
+ const directory = await ports.directory.getDirectory(q).catch(() => null);
1124
+ if (!directory) {
1125
+ return { summary: JSON.stringify({ error: "directory_unavailable", floorQuery }) };
1126
+ }
1127
+ const wantKeys = [
1128
+ ...new Set(
1129
+ floorQuery.split(/[,,、/]/).map((s) => s.trim()).filter(Boolean).map(normalizeFloorKey).filter((k) => !!k)
1130
+ )
1131
+ ];
1132
+ if (wantKeys.length === 0) {
1133
+ return { summary: JSON.stringify({ error: "floor_query_unparsed", floorQuery }) };
1134
+ }
1135
+ const resolved = [];
1136
+ for (const b of directory.buildings ?? []) {
1137
+ for (const f of b.floors ?? []) {
1138
+ const floorId = f.floorCode ?? f.floorName;
1139
+ const key = normalizeFloorKey(floorId) ?? normalizeFloorKey(f.floorName);
1140
+ if (key && wantKeys.includes(key) && !resolved.some((r) => r.key === key)) {
1141
+ resolved.push({ floorId, floorName: f.floorName, key });
1142
+ }
1143
+ }
1144
+ }
1145
+ if (resolved.length === 0) {
1146
+ return { summary: JSON.stringify({ error: "floor_not_found", floorQuery }) };
1147
+ }
1148
+ console.warn(`[floor-shops] input floorQuery="${floorQuery}" resolved=${resolved.map((r) => r.floorName).join("/")}`);
1149
+ const results = await Promise.all(
1150
+ resolved.map(
1151
+ (r) => ports.shop.searchShops({
1152
+ ctx: q,
1153
+ keyword: "",
1154
+ keywords: [],
1155
+ floorCode: r.floorId,
1156
+ page: 1,
1157
+ pageSize: 200
1158
+ })
1159
+ )
1160
+ );
1161
+ const merged = {
1162
+ items: results.flatMap((r) => r.items),
1163
+ page: 1,
1164
+ pageSize: 50,
1165
+ total: results.reduce((s, r) => s + r.total, 0),
1166
+ hasMore: results.some((r) => r.hasMore)
1167
+ };
1168
+ console.warn(`[floor-shops] output total=${merged.total} items=${merged.items.length}`);
1169
+ const data = projectShopList(
1170
+ "search",
1171
+ merged,
1172
+ merged.items.length === 0 ? "\u8BE5\u697C\u5C42\u6682\u65E0\u5728\u8425\u5546\u6237\u3002" : void 0,
1173
+ void 0,
1174
+ q.scope.mallId || void 0,
1175
+ q.scope.miniAppId || void 0
1176
+ );
1177
+ if (data.items.length === 0) return { summary: JSON.stringify({ floors: resolved.map((r) => r.floorName), total: 0 }) };
1178
+ return withCards(data, "shop-list", shopListNote(data, merged.total), summaries.shopList(data, merged.items));
1179
+ })
1180
+ });
1181
+ const categoryShops = createTool({
1182
+ id: "category-shops",
1183
+ description: "\u3010\u5185\u90E8\u5DE5\u5177\uFF0C\u6A21\u578B\u52FF\u8C03\u7528\u3011\u7C7B\u76EE\u95EE\u53E5\u786E\u5B9A\u6027\u9884\u6267\u884C\uFF1A\u7C7B\u76EE\u8BCD\u5F52\u4E00 \u2192 \u8BE5\u7C7B\u76EE\u95E8\u5E97\u5217\u8868 \u2192 shop-list\u3002",
1184
+ inputSchema: z.object({ categoryQuery: str('\u7C7B\u76EE\u8BCD\uFF08\u9017\u53F7\u5206\u9694\u591A\u7C7B\u76EE\uFF0C\u5982 "\u8D2D\u7269,\u9910\u996E"\uFF09') }),
1185
+ execute: exec(async (ports, _ctx, args, execCtx) => {
1186
+ const q = toContext(reqCtxOf(execCtx));
1187
+ const categoryQuery = String(args.categoryQuery ?? "").trim();
1188
+ if (!categoryQuery) return { summary: JSON.stringify({ error: "category_query_empty" }) };
1189
+ const categoryPort = ports.category;
1190
+ let cats = [];
1191
+ try {
1192
+ const tags = await categoryPort.listTags?.(q);
1193
+ if (tags && tags.length > 0) {
1194
+ cats = tags.map((name) => ({ code: name, name }));
1195
+ }
1196
+ } catch {
1197
+ }
1198
+ if (cats.length === 0) {
1199
+ try {
1200
+ cats = (await ports.category.listCategories(q)).map((c) => ({ code: c.code ?? c.name, name: c.name }));
1201
+ } catch {
1202
+ }
1203
+ }
1204
+ if (cats.length === 0) return { summary: JSON.stringify({ error: "categories_unavailable", categoryQuery }) };
1205
+ const words = [...new Set(
1206
+ categoryQuery.split(/[,,、/]/).map((s) => s.trim()).filter(Boolean)
1207
+ )];
1208
+ const matched = [];
1209
+ for (const w of words) {
1210
+ const candidates = [w, ...CATEGORY_SYNONYMS[w] ?? []];
1211
+ let hit;
1212
+ for (const c of candidates) {
1213
+ hit = cats.find((x) => x.code === c || x.name === c);
1214
+ if (hit) break;
1215
+ }
1216
+ if (!hit) {
1217
+ for (const c of candidates) {
1218
+ hit = cats.find((x) => x.name.includes(c) || c.includes(x.code) || c.includes(x.name));
1219
+ if (hit) break;
1220
+ }
1221
+ }
1222
+ if (hit && !matched.some((m) => m.code === hit.code)) matched.push(hit);
1223
+ }
1224
+ if (matched.length === 0) {
1225
+ return { summary: JSON.stringify({ error: "category_unresolved", categoryQuery, available: cats.map((c) => c.name) }) };
1226
+ }
1227
+ console.warn(`[category-shops] input categoryQuery="${categoryQuery}" resolved=${matched.map((m) => m.name).join("/")}`);
1228
+ const results = await Promise.all(
1229
+ matched.map(
1230
+ (m) => ports.shop.searchShops({
1231
+ ctx: q,
1232
+ keyword: "",
1233
+ keywords: [],
1234
+ businessCategory: m.code,
1235
+ page: 1,
1236
+ pageSize: 200
1237
+ })
1238
+ )
1239
+ );
1240
+ const merged = {
1241
+ items: results.flatMap((r) => r.items),
1242
+ page: 1,
1243
+ pageSize: 50,
1244
+ total: results.reduce((s, r) => s + r.total, 0),
1245
+ hasMore: results.some((r) => r.hasMore)
1246
+ };
1247
+ console.warn(`[category-shops] output total=${merged.total} items=${merged.items.length}`);
1248
+ const data = projectShopList(
1249
+ "search",
1250
+ merged,
1251
+ merged.items.length === 0 ? "\u8BE5\u7C7B\u76EE\u6682\u65E0\u5728\u8425\u5546\u6237\u3002" : void 0,
1252
+ void 0,
1253
+ q.scope.mallId || void 0,
1254
+ q.scope.miniAppId || void 0
1255
+ );
1256
+ if (data.items.length === 0) return { summary: JSON.stringify({ categories: matched.map((m) => m.name), total: 0 }) };
1257
+ return withCards(data, "shop-list", shopListNote(data, merged.total), summaries.shopList(data, merged.items));
1258
+ })
1259
+ });
1260
+ const mallOverview = createTool({
1261
+ id: "mall-overview",
1262
+ description: "\u3010\u5185\u90E8\u5DE5\u5177\uFF0C\u6A21\u578B\u52FF\u8C03\u7528\u3011\u5546\u573A\u6982\u89C8\uFF08\u54C1\u724C\u5BFC\u89C8\u805A\u5408\uFF09\uFF1A\u697C\u5C42 + \u4E1A\u6001\uFF08\u6743\u5A01\u8BA1\u6570\uFF09+ \u9884\u89C8\u95E8\u5E97 \u2192 shop-list \u6982\u89C8\u5361\u3002",
1263
+ // B3:mallId 入参化(同 mall-context——dedup 键随 mallId 变更自动换键)
1264
+ inputSchema: z.object({ mallId: str("\u5546\u5708 ID\uFF08pre-tool decide \u6CE8\u5165\uFF09") }),
1265
+ execute: exec(async (ports, _ctx, args, execCtx) => {
1266
+ const q = contextWithMallId(reqCtxOf(execCtx), args.mallId);
1267
+ const overviewPort = ports.shop;
1268
+ const overview = await overviewPort.fetchStoreOverview?.(q).catch(() => null);
1269
+ if (overview && overview.stores.length > 0) {
1270
+ const page = {
1271
+ items: overview.stores,
1272
+ page: 1,
1273
+ pageSize: overview.stores.length,
1274
+ total: overview.stores.length,
1275
+ hasMore: false
1276
+ };
1277
+ const data2 = projectShopList(
1278
+ "search",
1279
+ page,
1280
+ "\u5546\u573A\u95E8\u5E97\u6982\u89C8",
1281
+ void 0,
1282
+ q.scope.mallId || void 0,
1283
+ q.scope.miniAppId || void 0
1284
+ );
1285
+ const tagText = overview.categories.map((c) => `${c.name} ${c.merchantCount} \u5BB6`).join("\u3001");
1286
+ const note = `\u5546\u573A\u6982\u89C8\uFF1A${overview.floors.length} \u5C42\uFF08${overview.floors.join("/")}\uFF09\uFF1B\u4E1A\u6001\uFF1A${tagText}\uFF1B\u5F53\u524D\u5C55\u793A\u5176\u4E2D ${overview.stores.length} \u5BB6\u95E8\u5E97`;
1287
+ return withCards(data2, "shop-list", note, summaries.shopList(data2, overview.stores));
1288
+ }
1289
+ console.warn("[mall-overview] fetchStoreOverview \u7F3A\u5E2D/\u7A7A \u2192 \u964D\u7EA7 searchShops \u96F6\u53C2");
1290
+ const result = await ports.shop.searchShops({ ctx: q, keyword: "", keywords: [], page: 1, pageSize: 50 });
1291
+ const data = buildShopListCard(result, q, true);
1292
+ if (data.items.length === 0) return { summary: summaries.shopList(data) };
1293
+ return withCards(data, "shop-list", shopListNote(data, result.total), summaries.shopList(data, result.items));
1294
+ })
1295
+ });
1296
+ return {
1297
+ searchShops: withCardEmissionHint(searchShops),
1298
+ getShop: withCardEmissionHint(getShop),
1299
+ mallContext: internalTool(mallContext),
1300
+ floorShops: internalTool(floorShops),
1301
+ categoryShops: internalTool(categoryShops),
1302
+ mallOverview: internalTool(mallOverview)
1303
+ };
1304
+ }
1305
+
1306
+ // src/server/handler.ts
1307
+ import { parseMallScope as parseMallScope3 } from "@tbox.cn/app-contracts-mall";
1308
+ var BRAND_GUIDE_QUERY = "\u54C1\u724C\u5BFC\u89C8";
1309
+ var BRAND_GUIDE_PAGE_SIZE = 200;
1310
+ function createShoppingGuideHandler() {
1311
+ return {
1312
+ id: "shopping-guide",
1313
+ // match:'exact':常驻按钮发出固定整句(chat.json query),整句全等命中不入 BM25 词袋
1314
+ //(误吞免疫:用户长句「我想看看品牌导览」不命中 → 走 LLM 正常路径由 search-shops 工具承接)
1315
+ intents: [{ patterns: [BRAND_GUIDE_QUERY], match: "exact" }],
1316
+ handle: async (action, payload, ctx, reqCtx) => {
1317
+ if (action !== "intent") {
1318
+ return { cards: [], text: "\u5BFC\u8D2D\u670D\u52A1\u5DF2\u5C31\u7EEA\uFF0C\u53EF\u95EE\u6211\u95E8\u5E97\u3001\u697C\u5C42\u3001\u7C7B\u76EE\u6216\u5BA2\u670D\u95EE\u9898" };
1319
+ }
1320
+ const content = typeof payload?.content === "string" ? payload.content.trim() : "";
1321
+ if (content !== BRAND_GUIDE_QUERY) return { cards: [], continueWith: { content } };
1322
+ if (!reqCtx) return { cards: [], text: "\u5BFC\u8D2D\u670D\u52A1\u4E0D\u53EF\u7528\uFF08\u7F3A\u5C11\u8FD0\u884C\u4E0A\u4E0B\u6587\uFF09" };
1323
+ const scope = parseMallScope3(reqCtx.attributes);
1324
+ if (!scope?.mallId) return { cards: [], text: "\u5546\u573A\u4E0A\u4E0B\u6587\u7F3A\u5931\uFF0C\u6682\u65F6\u65E0\u6CD5\u83B7\u53D6\u54C1\u724C\u5BFC\u89C8" };
1325
+ const ports = await resolveShoppingGuidePorts(reqCtx, ctx);
1326
+ const q = toContext(reqCtx);
1327
+ const result = await ports.shop.searchShops({
1328
+ ctx: q,
1329
+ keyword: "",
1330
+ keywords: [],
1331
+ page: 1,
1332
+ pageSize: BRAND_GUIDE_PAGE_SIZE
1333
+ });
1334
+ if (result.items.length === 0) {
1335
+ return { cards: [], text: "\u95E8\u5E97\u4FE1\u606F\u6682\u672A\u5C31\u7EEA\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5" };
1336
+ }
1337
+ const data = buildShopListCard(result, q, true, BRAND_GUIDE_PAGE_SIZE);
1338
+ return {
1339
+ cards: [{ cardType: "shop-list", data }],
1340
+ // 固定通用文案(A):N 取接口分页字段 total(非本地 items.length——截断/分页下仍为全馆事实数)
1341
+ text: `\u5168\u5546\u573A\u5171 ${result.total} \u5BB6\u5728\u8425\u95E8\u5E97\uFF0C\u4E0B\u6ED1\u770B\u770B\u6709\u54EA\u4E9B\u54C1\u724C\uFF0C\u4E5F\u53EF\u6309\u7C7B\u76EE\u7B5B\u9009\uFF5E`
1342
+ };
1343
+ }
1344
+ };
1345
+ }
1346
+
1347
+ // src/server/cards/index.ts
1348
+ var shoppingGuideCards = {
1349
+ "product-list": meta_default,
1350
+ "product-detail": meta_default2,
1351
+ "shop-list": meta_default3,
1352
+ "shop-detail": meta_default4,
1353
+ "category-list": meta_default5,
1354
+ "product-comparison": meta_default6,
1355
+ "mall-directory": meta_default7,
1356
+ "nearby-mall-list": meta_default8,
1357
+ "human-guide-list": meta_default9,
1358
+ "location-handoff": meta_default10,
1359
+ "recommend-merchants": meta_default11
1360
+ };
1361
+
1362
+ // src/server/index.ts
1363
+ var moduleCtx;
1364
+ var tools = createShoppingGuideTools({ getCtx: () => moduleCtx });
1365
+ var mallContextPreTool = definePreTool(tools.mallContext, {
1366
+ routing: { mode: "always" },
1367
+ // 上下文统一化:连接级领域属性经 decide 入参 attributes 判定(不读 ctx.auth 全局单例)
1368
+ decide: ({ attributes }) => {
1369
+ const scope = mallSlot.read(attributes);
1370
+ if (!scope) return { decision: "skip", reason: "\u65E0 mall scope\uFF08attributes \u7F3A\u5E2D/\u89E3\u6790\u5931\u8D25\uFF09" };
1371
+ return { decision: "run", args: { mallId: scope.mallId } };
1372
+ },
1373
+ silent: true,
1374
+ dedup: {
1375
+ accepts: (result) => Array.isArray(result?.categories) && result.categories.length > 0
1376
+ }
1377
+ });
1378
+ var FLOOR_PURE_QUERY_RE = /^(有什么|有啥|有哪些|有哪些店|有哪些店铺|有什么店|逛什么|逛逛|逛逛啥|看看|看一下|看看有啥|有啥好逛的|有什么好逛的|有什么可以逛的)?[呢吗啊呀哦吧]*$/;
1379
+ var floorShopsPreTool = definePreTool(tools.floorShops, {
1380
+ routing: { mode: "always" },
1381
+ decide: ({ text }) => {
1382
+ if (!text || !text.trim()) return { decision: "skip", reason: "\u7A7A\u6587\u672C" };
1383
+ const mentions = extractFloorMentions(text);
1384
+ if (mentions.length === 0) return { decision: "skip", reason: "\u65E0\u697C\u5C42\u5F15\u7528" };
1385
+ const stripped = text.replace(FLOOR_MENTION_RE, "").trim();
1386
+ if (!FLOOR_PURE_QUERY_RE.test(stripped)) {
1387
+ return { decision: "skip", reason: `\u697C\u5C42+\u989D\u5916\u7B5B\u9009\u610F\u56FE\uFF08"${stripped}"\uFF09\uFF0C\u8BA9\u6A21\u578B\u8C03 search-shops` };
1388
+ }
1389
+ return { decision: "run", args: { floorQuery: mentions.join(",") } };
1390
+ },
1391
+ silent: true
1392
+ });
1393
+ var OVERVIEW_STRUCT_RE = /业态|类目|分类|几层|多少层|楼层|楼栋/;
1394
+ var categoryShopsPreTool = definePreTool(tools.categoryShops, {
1395
+ routing: { mode: "keywords", terms: [...CATEGORY_WORDS] },
1396
+ decide: ({ text }) => {
1397
+ if (!text || !text.trim()) return { decision: "skip", reason: "\u7A7A\u6587\u672C" };
1398
+ if (extractFloorMentions(text).length > 0) return { decision: "skip", reason: "\u697C\u5C42\u95EE\u53E5\u5F52 floor-shops" };
1399
+ if (OVERVIEW_STRUCT_RE.test(text)) return { decision: "skip", reason: "\u7ED3\u6784\u95EE\u53E5\u5F52 mall-overview" };
1400
+ const mentions = extractCategoryMentions(text);
1401
+ if (mentions.length === 0) return { decision: "skip", reason: "\u65E0\u7C7B\u76EE\u63D0\u53CA" };
1402
+ return { decision: "run", args: { categoryQuery: mentions.join(",") } };
1403
+ },
1404
+ silent: true
1405
+ });
1406
+ var mallOverviewPreTool = definePreTool(tools.mallOverview, {
1407
+ routing: { mode: "keywords", terms: ["\u4E1A\u6001", "\u7C7B\u76EE", "\u5206\u7C7B", "\u51E0\u5C42", "\u591A\u5C11\u5C42", "\u697C\u5C42", "\u697C\u5C42\u5206\u5E03", "\u697C\u680B\u5206\u5E03", "\u597D\u901B", "\u53EF\u4EE5\u901B", "\u53EF\u901B", "\u901B\u4EC0\u4E48", "\u60F3\u901B", "\u968F\u4FBF\u901B", "\u901B\u901B"] },
1408
+ decide: ({ text, attributes }) => {
1409
+ if (!text || !text.trim()) return { decision: "skip", reason: "\u7A7A\u6587\u672C" };
1410
+ if (extractFloorMentions(text).length > 0) return { decision: "skip", reason: "\u697C\u5C42\u95EE\u53E5\u5F52 floor-shops" };
1411
+ const scope = mallSlot.read(attributes);
1412
+ if (!scope) return { decision: "skip", reason: "\u65E0 mall scope" };
1413
+ return { decision: "run", args: { mallId: scope.mallId } };
1414
+ },
1415
+ silent: true,
1416
+ // B3 dedup:accepts 不配——失败路径(execute throw / 空结果)经引擎不落键天然下轮重试;
1417
+ // 概览数字(层数/业态计数)会话级稳定,staleness 边界可接受
1418
+ dedup: {}
1419
+ });
1420
+ var preTools = {
1421
+ "mall-context": mallContextPreTool,
1422
+ "floor-shops": floorShopsPreTool,
1423
+ "category-shops": categoryShopsPreTool,
1424
+ "mall-overview": mallOverviewPreTool
1425
+ };
1426
+ var skills = Object.fromEntries(
1427
+ (await loadModuleSkills("@tbox.cn/app-module-shopping-guide", import.meta.url)).map((s) => [s.name, s])
1428
+ );
1429
+ var serverModule = {
1430
+ declaration: {
1431
+ moduleId: "shopping-guide"
1432
+ },
1433
+ cards: {
1434
+ "product-list": meta_default,
1435
+ "product-detail": meta_default2,
1436
+ "shop-list": meta_default3,
1437
+ "shop-detail": meta_default4,
1438
+ "category-list": meta_default5,
1439
+ "product-comparison": meta_default6,
1440
+ "mall-directory": meta_default7,
1441
+ "nearby-mall-list": meta_default8,
1442
+ "human-guide-list": meta_default9,
1443
+ "location-handoff": meta_default10,
1444
+ "recommend-merchants": meta_default11
1445
+ },
1446
+ skills,
1447
+ preTools,
1448
+ register(ctx) {
1449
+ moduleCtx = ctx;
1450
+ ctx.cards.registerMap(serverModule.cards);
1451
+ for (const tool of Object.values(tools)) {
1452
+ ctx.tools.register(tool);
1453
+ }
1454
+ ctx.handlers.register(createShoppingGuideHandler());
1455
+ const mallBus = ctx.bus;
1456
+ mallBus.subscribe("member.level.changed", ({ userId }) => {
1457
+ void userId;
1458
+ });
1459
+ const router = Router();
1460
+ router.get("/shop-detail", async (req, res) => {
1461
+ const shopId = typeof req.query["shopId"] === "string" ? req.query["shopId"].trim() : "";
1462
+ if (!shopId) {
1463
+ res.status(400).json({ error: "shopId required" });
1464
+ return;
1465
+ }
1466
+ try {
1467
+ const reqCtx = getRequestContext(req);
1468
+ if (!reqCtx) {
1469
+ res.status(401).json({ error: "unauthorized" });
1470
+ return;
1471
+ }
1472
+ const scopedReqCtx = withMallScopeFromQuery(reqCtx, req.query);
1473
+ const ports = await resolveShoppingGuidePorts(scopedReqCtx, ctx);
1474
+ const queryCtx = toMallQueryContext(scopedReqCtx);
1475
+ const shop = await ports.shop.getShop(shopId, queryCtx);
1476
+ if (!shop) {
1477
+ res.status(404).json({ error: "not_found" });
1478
+ return;
1479
+ }
1480
+ res.json({ data: projectShopDetail(shop) });
1481
+ } catch (err) {
1482
+ const message = err instanceof Error ? err.message : String(err);
1483
+ console.warn(`[shopping-guide] shop-detail route error shopId=${shopId}: ${message}`);
1484
+ res.status(500).json({ error: "internal_error" });
1485
+ }
1486
+ });
1487
+ ctx.routes.register("shopping-guide", router);
1488
+ }
1489
+ };
1490
+
1491
+ export {
1492
+ resolveShoppingGuidePorts,
1493
+ createShoppingGuideTools,
1494
+ shoppingGuideCards,
1495
+ serverModule
1496
+ };