@tbox.cn/app-module-shopping-guide 0.2.1 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +16 -0
- package/README.md +96 -0
- package/dist/chunk-AYQZO2FV.js +1496 -0
- package/dist/chunk-QDTU2FRN.js +1682 -0
- package/dist/client/index.d.ts +3 -3
- package/dist/client/index.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -8
- package/dist/server/index.d.ts +2512 -608
- package/dist/server/index.js +1 -7
- package/dist/shop-guide-header-art-pea-v2-OME4MKBW.jpg +0 -0
- package/dist/shopping-guide-OQ2SSHXL.css +2593 -0
- package/package.json +25 -16
- package/skills/shopping-guide/SKILL.md +127 -24
- package/src/client/assets/shop-guide-header-art-pea-v2.jpg +0 -0
- package/src/client/assets/shop-guide-header-art.png +0 -0
- package/src/client/assets.d.ts +10 -0
- package/src/client/cards/category-list/index.tsx +113 -0
- package/src/client/cards/human-guide-list/index.tsx +72 -0
- package/src/client/cards/index.ts +14 -0
- package/src/client/cards/location-handoff/index.tsx +52 -0
- package/src/client/cards/mall-directory/index.tsx +77 -0
- package/src/client/cards/nearby-mall-list/index.tsx +40 -0
- package/src/client/cards/product-comparison/index.tsx +100 -0
- package/src/client/cards/product-detail/index.tsx +97 -0
- package/src/client/cards/product-list/index.tsx +223 -0
- package/src/client/cards/recommend-merchants/index.tsx +147 -0
- package/src/client/cards/shop-detail/index.tsx +133 -0
- package/src/client/cards/shop-list/index.tsx +216 -0
- package/src/client/cards/view.ts +147 -0
- package/src/client/categories.ts +38 -0
- package/src/client/components/ImageWithFallback.tsx +34 -0
- package/src/client/components/MerchantRow.tsx +78 -0
- package/src/client/components/ShopDetailSheet.tsx +383 -0
- package/src/client/components/ShopGuideHeader.tsx +24 -0
- package/src/client/components/ShopGuideSectionLabel.tsx +10 -0
- package/src/client/components/ShopListSheet.tsx +293 -0
- package/src/client/index.ts +8 -6
- package/src/client/styles/shopping-guide.css +2593 -0
- package/src/client/types/css.d.ts +2 -0
- package/src/server/cards/category-list/meta.ts +0 -2
- package/src/server/cards/human-guide-list/meta.ts +0 -2
- package/src/server/cards/index.ts +10 -10
- package/src/server/cards/location-handoff/meta.ts +0 -2
- package/src/server/cards/mall-directory/meta.ts +0 -2
- package/src/server/cards/nearby-mall-list/meta.ts +1 -3
- package/src/server/cards/product-comparison/meta.ts +0 -2
- package/src/server/cards/product-detail/meta.ts +0 -2
- package/src/server/cards/product-list/meta.ts +0 -2
- package/src/server/cards/recommend-merchants/meta.ts +37 -0
- package/src/server/cards/recommend-merchants/samples.ts +189 -0
- package/src/server/cards/{merchant-detail → shop-detail}/meta.ts +6 -6
- package/src/server/cards/shop-detail/samples.ts +72 -0
- package/src/server/cards/{merchant-list → shop-list}/meta.ts +9 -9
- package/src/server/cards/shop-list/samples.ts +154 -0
- package/src/server/domain/value-objects.ts +1 -2
- package/src/server/handler.ts +63 -0
- package/src/server/index.ts +161 -101
- package/src/server/ports/index.ts +120 -91
- package/src/server/ports/local-adapters.ts +5 -55
- package/src/server/projections/index.ts +159 -41
- package/src/server/tools/index.ts +590 -315
- package/tbox.module.json +137 -0
- package/tests/cards-render.test.tsx +830 -0
- package/tests/floor-pretool.test.ts +275 -0
- package/tests/handler.test.ts +259 -0
- package/tests/merchant-list-limit.test.ts +53 -0
- package/tests/ports-resolve.test.ts +112 -0
- package/tests/samples.test.ts +71 -0
- package/tests/shopping-guide.test.ts +402 -234
- package/tests/skill.test.ts +86 -0
- package/tests/view.test.ts +42 -0
- package/tsup.config.ts +9 -1
- package/dist/chunk-AGBLC6XI.js +0 -1294
- package/dist/chunk-U4WDS5PQ.js +0 -173
- package/skills/shopping-guide/references/comparison-format.md +0 -5
- package/skills/shopping-guide/references/faq-answers.md +0 -5
- package/skills/shopping-guide/references/floor-directory.md +0 -4
- package/skills/shopping-guide/references/intent-patterns.md +0 -5
- package/skills/shopping-guide/references/location-format.md +0 -5
- package/skills/shopping-guide/references/policy-lookup.md +0 -5
- package/skills/shopping-guide/references/product-search-tips.md +0 -6
- package/skills/shopping-guide/references/recommendation-style.md +0 -5
- package/src/client/cards/index.tsx +0 -267
- package/src/server/cards/customer-service-faq/meta.ts +0 -18
- package/src/server/integrations/joycity/adapter.ts +0 -226
- package/src/server/integrations/joycity/auth-strategy.ts +0 -38
- package/src/server/integrations/joycity/gateway.ts +0 -128
- package/tbox.component.json +0 -48
|
@@ -1,106 +1,146 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* 导购 Port
|
|
3
|
-
*
|
|
2
|
+
* 导购 Port 聚合解析(017 槽位原子化)+ mall-directory 消费接口。
|
|
3
|
+
* 远程检索域四槽独立解析(catalog/shops/categories/directory);navigation 恒本地。
|
|
4
|
+
* - integrations 在场 → 四槽独立解析远程检索域;预期缺席或 PROVIDER_NOT_IMPLEMENTED
|
|
5
|
+
* → 本地空数据兜底(guide 域远程检索为增强面,缺席不阻断导览问答)
|
|
6
|
+
* ——与 member 的 fail-fast 语义区分:guide 本地知识库可独立服务。
|
|
7
|
+
* - 未装配 integrations(模块单测/本地演示):本地知识库 + 空数据 adapter。
|
|
4
8
|
*/
|
|
5
9
|
import type {
|
|
6
|
-
AssistanceQueryPort,
|
|
7
10
|
CatalogQueryPort,
|
|
8
11
|
CommercialCategoryQueryPort,
|
|
9
12
|
MallDirectoryQueryPort,
|
|
10
|
-
|
|
13
|
+
ShopDirectoryQueryPort,
|
|
11
14
|
NavigationPort,
|
|
12
15
|
} from '@tbox.cn/app-contracts-mall';
|
|
13
16
|
import type { ServerContext } from '@tbox.cn/app-sdk/server';
|
|
14
|
-
import { createKnowledgeClient } from '@tbox.cn/app-sdk/server';
|
|
15
|
-
import { parseMallScope } from '@tbox.cn/app-contracts-mall';
|
|
16
17
|
import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
18
|
+
mallScopeOf,
|
|
19
|
+
parseMallScope,
|
|
20
|
+
SHOPPING_CATALOG_SERVICE,
|
|
21
|
+
SHOPPING_CATEGORIES_SERVICE,
|
|
22
|
+
SHOPPING_DIRECTORY_SERVICE,
|
|
23
|
+
SHOPPING_SHOPS_SERVICE,
|
|
24
|
+
} from '@tbox.cn/app-contracts-mall';
|
|
25
|
+
import { isExpectedProviderAbsence, type RequestContext } from '@tbox.cn/app-contracts';
|
|
26
|
+
import { LocalNavigationAdapter } from './local-adapters';
|
|
27
27
|
export interface ShoppingGuidePorts {
|
|
28
28
|
catalog: CatalogQueryPort;
|
|
29
|
-
|
|
29
|
+
shop: ShopDirectoryQueryPort;
|
|
30
30
|
category: CommercialCategoryQueryPort;
|
|
31
31
|
directory: MallDirectoryQueryPort;
|
|
32
|
-
assistance: AssistanceQueryPort;
|
|
33
32
|
navigation: NavigationPort;
|
|
34
33
|
}
|
|
35
34
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
35
|
+
export async function resolveShoppingGuidePorts(reqCtx: RequestContext, ctx: ServerContext): Promise<ShoppingGuidePorts> {
|
|
36
|
+
const mallId = currentMallId(reqCtx) ?? 'none';
|
|
37
|
+
const local = await localPorts(ctx, mallId);
|
|
38
|
+
if (!ctx.integrations) {
|
|
39
|
+
return {
|
|
40
|
+
catalog: new EmptyCatalogAdapter(),
|
|
41
|
+
shop: new EmptyShopAdapter(),
|
|
42
|
+
category: new EmptyCategoryAdapter(),
|
|
43
|
+
directory: new EmptyDirectoryAdapter(),
|
|
44
|
+
...local,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
const [catalog, shop, category, directory] = await Promise.all([
|
|
48
|
+
resolveGuideSlot<CatalogQueryPort>(SHOPPING_CATALOG_SERVICE, reqCtx, ctx, new EmptyCatalogAdapter()),
|
|
49
|
+
resolveGuideSlot<ShopDirectoryQueryPort>(SHOPPING_SHOPS_SERVICE, reqCtx, ctx, new EmptyShopAdapter()),
|
|
50
|
+
resolveGuideSlot<CommercialCategoryQueryPort>(SHOPPING_CATEGORIES_SERVICE, reqCtx, ctx, new EmptyCategoryAdapter()),
|
|
51
|
+
resolveGuideSlot<MallDirectoryQueryPort>(SHOPPING_DIRECTORY_SERVICE, reqCtx, ctx, new EmptyDirectoryAdapter()),
|
|
52
|
+
]);
|
|
53
|
+
return { catalog, shop, category, directory, ...local };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** guide 槽位解析公共体:预期缺席 + NOT_IMPLEMENTED → 本地兜底(增强面语义);其余上抛 */
|
|
57
|
+
async function resolveGuideSlot<T>(
|
|
58
|
+
service: string,
|
|
59
|
+
reqCtx: RequestContext,
|
|
60
|
+
ctx: ServerContext,
|
|
61
|
+
fallback: T,
|
|
62
|
+
): Promise<T> {
|
|
63
|
+
try {
|
|
64
|
+
return (await ctx.integrations!.resolveService({
|
|
65
|
+
service,
|
|
66
|
+
scope: mallScopeOf(reqCtx),
|
|
67
|
+
request: reqCtx,
|
|
68
|
+
})) as T;
|
|
69
|
+
} catch (e) {
|
|
70
|
+
if (isExpectedProviderAbsence(e)) return fallback;
|
|
71
|
+
const code = (e as { code?: string }).code;
|
|
72
|
+
if (code === 'PROVIDER_NOT_IMPLEMENTED') return fallback; // 远程检索为增强面
|
|
73
|
+
throw e; // 其余错误上抛(配置即声明,F5 起无探测链回退)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
45
76
|
|
|
46
77
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* - 未装配 providers(模块单测/本地演示):本地知识库 + 空数据 adapter。
|
|
78
|
+
* mall-directory 服务消费接口(015 S7:模板注册,deployment.malls 单一来源;
|
|
79
|
+
* 模块只依赖此结构类型——不进 TIER1 公共契约)。
|
|
50
80
|
*/
|
|
51
|
-
export
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
81
|
+
export interface MallDirectoryService {
|
|
82
|
+
nearbyMalls(q?: { query?: string }): Array<{
|
|
83
|
+
mallId: string;
|
|
84
|
+
name: string;
|
|
85
|
+
address: string;
|
|
86
|
+
distanceKm?: number;
|
|
87
|
+
status: { code: 'open' | 'closed' | 'unknown'; label: string };
|
|
88
|
+
}>;
|
|
89
|
+
contactPhone(mallId: string): string | undefined;
|
|
90
|
+
}
|
|
55
91
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
scope: mallId !== 'none' ? { mallId } : {},
|
|
61
|
-
});
|
|
62
|
-
gateway = new JoyCityTransportGateway(resolved.transport);
|
|
63
|
-
} catch {
|
|
64
|
-
gateway = undefined; // 未装配 provider → 本地降级
|
|
65
|
-
}
|
|
92
|
+
/** 解析模板注入的 mall-directory 服务(未注册 → undefined) */
|
|
93
|
+
export function resolveMallDirectory(ctx: ServerContext): MallDirectoryService | undefined {
|
|
94
|
+
return ctx.services.resolve?.('mall-directory') as MallDirectoryService | undefined;
|
|
95
|
+
}
|
|
66
96
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
directory: new JoyCityMallDirectoryAdapter(gateway),
|
|
73
|
-
assistance: createLocalAssistance(),
|
|
74
|
-
navigation: new LocalNavigationAdapter(),
|
|
75
|
-
}
|
|
76
|
-
: {
|
|
77
|
-
catalog: new EmptyCatalogAdapter(),
|
|
78
|
-
merchant: new EmptyMerchantAdapter(),
|
|
79
|
-
category: new EmptyCategoryAdapter(),
|
|
80
|
-
directory: new EmptyDirectoryAdapter(),
|
|
81
|
-
assistance: createLocalAssistance(),
|
|
82
|
-
navigation: new LocalNavigationAdapter(),
|
|
83
|
-
};
|
|
84
|
-
portCache.set(mallId, { ports, at: Date.now() });
|
|
85
|
-
return ports;
|
|
97
|
+
/** mall scope 的 contactPhone(faq 拨打条目数据源;上下文统一化:mallId 显式 reqCtx、目录经 ctx 解析) */
|
|
98
|
+
export function currentContactPhone(reqCtx: RequestContext | undefined, ctx: ServerContext): string | undefined {
|
|
99
|
+
const mallId = currentMallId(reqCtx);
|
|
100
|
+
if (!mallId) return undefined;
|
|
101
|
+
return resolveMallDirectory(ctx)?.contactPhone(mallId);
|
|
86
102
|
}
|
|
87
103
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
/** navigation decorator:mall-directory 服务注入时 listNearbyMalls 优先服务数据源 */
|
|
107
|
+
function withMallDirectoryNavigation(base: NavigationPort, ctx: ServerContext): NavigationPort {
|
|
108
|
+
const directory = resolveMallDirectory(ctx);
|
|
109
|
+
if (!directory) return base;
|
|
110
|
+
return {
|
|
111
|
+
...base,
|
|
112
|
+
async listNearbyMalls(q, query) {
|
|
113
|
+
const fromService = directory.nearbyMalls(query ? { query } : {});
|
|
114
|
+
if (fromService.length > 0) return fromService;
|
|
115
|
+
return base.listNearbyMalls(q, query);
|
|
116
|
+
},
|
|
117
|
+
};
|
|
99
118
|
}
|
|
100
119
|
|
|
101
|
-
|
|
120
|
+
/** 上下文统一化:显式入参 reqCtx(调用方透传;经 TIER1 parseMallScope 解析) */
|
|
121
|
+
function currentMallId(reqCtx: RequestContext | undefined): string | undefined {
|
|
102
122
|
// 011 评审 6.1:经 TIER1 parseMallScope 解析(不手解 attributes 原始形状)
|
|
103
|
-
return parseMallScope(
|
|
123
|
+
return parseMallScope(reqCtx?.attributes)?.mallId;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* 011 G3:模块级 connector 缓存(key = mallId;无 mall → 'none')。
|
|
128
|
+
* 注意:gateway 含用户态 token,不做全局缓存;仅本地 adapter(navigation)
|
|
129
|
+
* 以 mallId 为 key 按 TTL 缓存。
|
|
130
|
+
*/
|
|
131
|
+
const LOCAL_ADAPTER_CACHE_TTL_MS = 30 * 60 * 1000;
|
|
132
|
+
const localAdapterCache = new Map<string, { navigation: NavigationPort; at: number }>();
|
|
133
|
+
|
|
134
|
+
/** 本地 ports(navigation:恒本地装配——与 provider 供给面正交;assistance 域已拆分至客服模块) */
|
|
135
|
+
async function localPorts(ctx: ServerContext, mallId: string): Promise<{ navigation: NavigationPort }> {
|
|
136
|
+
const cachedLocal = localAdapterCache.get(mallId);
|
|
137
|
+
if (cachedLocal && Date.now() - cachedLocal.at < LOCAL_ADAPTER_CACHE_TTL_MS) {
|
|
138
|
+
return cachedLocal;
|
|
139
|
+
}
|
|
140
|
+
const baseNav = withMallDirectoryNavigation(new LocalNavigationAdapter(), ctx);
|
|
141
|
+
const local = { navigation: baseNav as NavigationPort };
|
|
142
|
+
localAdapterCache.set(mallId, { ...local, at: Date.now() });
|
|
143
|
+
return local;
|
|
104
144
|
}
|
|
105
145
|
|
|
106
146
|
// ===== 空实现(未装配 Provider / 未配置平台凭据时的降级) =====
|
|
@@ -117,11 +157,11 @@ class EmptyCatalogAdapter implements CatalogQueryPort {
|
|
|
117
157
|
}
|
|
118
158
|
}
|
|
119
159
|
|
|
120
|
-
class
|
|
121
|
-
async
|
|
160
|
+
class EmptyShopAdapter implements ShopDirectoryQueryPort {
|
|
161
|
+
async searchShops() {
|
|
122
162
|
return { items: [], page: 1, pageSize: 10, total: 0, hasMore: false };
|
|
123
163
|
}
|
|
124
|
-
async
|
|
164
|
+
async getShop() {
|
|
125
165
|
return null;
|
|
126
166
|
}
|
|
127
167
|
}
|
|
@@ -137,15 +177,4 @@ class EmptyDirectoryAdapter implements MallDirectoryQueryPort {
|
|
|
137
177
|
return null;
|
|
138
178
|
}
|
|
139
179
|
}
|
|
140
|
-
|
|
141
|
-
class EmptyAssistanceAdapter implements AssistanceQueryPort {
|
|
142
|
-
async searchFaq() {
|
|
143
|
-
return [];
|
|
144
|
-
}
|
|
145
|
-
async searchKnowledge() {
|
|
146
|
-
return [];
|
|
147
|
-
}
|
|
148
|
-
async listHumanGuides() {
|
|
149
|
-
return [];
|
|
150
|
-
}
|
|
151
|
-
}
|
|
180
|
+
// EmptyAssistanceAdapter 随客服承接拆分迁至 module-customer-service(2026-08-31)
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* 导航本地 Port 实现(011 K6):附近商场/浏览历史/位置为本地实现(真实数据源接入点)。
|
|
3
|
+
* FAQ/知识库域已拆分至 module-customer-service(2026-08-31,KnowledgeAssistanceAdapter 迁出)。
|
|
4
4
|
*/
|
|
5
5
|
import type {
|
|
6
|
-
AssistanceQueryPort,
|
|
7
|
-
FaqEntry,
|
|
8
|
-
HumanGuideRecord,
|
|
9
|
-
KnowledgeEntry,
|
|
10
6
|
MerchantLocationRecord,
|
|
11
7
|
NavigationPort,
|
|
12
8
|
NearbyMallRecord,
|
|
@@ -14,54 +10,13 @@ import type {
|
|
|
14
10
|
ShoppingPage,
|
|
15
11
|
ShoppingQueryContext,
|
|
16
12
|
} from '@tbox.cn/app-contracts-mall';
|
|
17
|
-
import type { KnowledgeClient } from '@tbox.cn/app-sdk/server';
|
|
18
|
-
|
|
19
|
-
export class KnowledgeAssistanceAdapter implements AssistanceQueryPort {
|
|
20
|
-
constructor(private readonly knowledge: KnowledgeClient) {}
|
|
21
|
-
|
|
22
|
-
async searchFaq(
|
|
23
|
-
_ctx: ShoppingQueryContext,
|
|
24
|
-
query: string,
|
|
25
|
-
topK = 3,
|
|
26
|
-
): Promise<readonly FaqEntry[]> {
|
|
27
|
-
const results = await this.knowledge.search({ datasetId: 'faq', query, topK });
|
|
28
|
-
return results.map((hit) => ({
|
|
29
|
-
question: query,
|
|
30
|
-
answer: summarize(hit.content),
|
|
31
|
-
...(hit.originFileName ? { category: hit.originFileName } : {}),
|
|
32
|
-
relevanceScore: hit.score,
|
|
33
|
-
}));
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
async searchKnowledge(
|
|
37
|
-
_ctx: ShoppingQueryContext,
|
|
38
|
-
query: string,
|
|
39
|
-
topK = 3,
|
|
40
|
-
): Promise<readonly KnowledgeEntry[]> {
|
|
41
|
-
const results = await this.knowledge.search({ datasetId: 'mall-knowledge', query, topK });
|
|
42
|
-
return results.map((hit) => ({
|
|
43
|
-
content: hit.content,
|
|
44
|
-
score: hit.score,
|
|
45
|
-
...(hit.originFileName ? { title: hit.originFileName } : {}),
|
|
46
|
-
}));
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
async listHumanGuides(
|
|
50
|
-
merchantId: string,
|
|
51
|
-
_ctx: ShoppingQueryContext,
|
|
52
|
-
): Promise<readonly HumanGuideRecord[]> {
|
|
53
|
-
// 真实数据源接入点:JoyCity 导购员列表 API(二期);当前返回空集
|
|
54
|
-
void merchantId;
|
|
55
|
-
return [];
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
13
|
|
|
59
14
|
export class LocalNavigationAdapter implements NavigationPort {
|
|
60
15
|
async getLocation(
|
|
61
16
|
_merchantId: string,
|
|
62
17
|
_ctx: ShoppingQueryContext,
|
|
63
18
|
): Promise<MerchantLocationRecord | null> {
|
|
64
|
-
// 位置信息已内嵌 merchant.search 结果;单独查询由
|
|
19
|
+
// 位置信息已内嵌 merchant.search 结果;单独查询由 provider merchant adapter 补充(二期)
|
|
65
20
|
return null;
|
|
66
21
|
}
|
|
67
22
|
|
|
@@ -81,10 +36,5 @@ export class LocalNavigationAdapter implements NavigationPort {
|
|
|
81
36
|
}
|
|
82
37
|
}
|
|
83
38
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
.replace(/^#+\s+/gm, '')
|
|
87
|
-
.replace(/\s+/g, ' ')
|
|
88
|
-
.trim()
|
|
89
|
-
.slice(0, 320);
|
|
90
|
-
}
|
|
39
|
+
// listHumanGuides 实现(导购员列表 API,二期)随 AssistanceQueryPort 契约保留:
|
|
40
|
+
// 工具 list-human-guides 暂停中,恢复时在本地 adapter 补实现(契约见 contracts-mall)。
|
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 导购投影层(011 S7):contracts-mall record → 卡数据(zod 校验形状)。
|
|
3
|
-
* 每卡一个投影函数,工具 execute
|
|
3
|
+
* 每卡一个投影函数,工具 execute 调用后包入出参 cards 字段(v2 出卡契约)出卡。
|
|
4
4
|
*/
|
|
5
5
|
import type {
|
|
6
6
|
CategoryRecord,
|
|
7
|
-
FaqEntry,
|
|
8
7
|
KnowledgeEntry,
|
|
9
8
|
MallDirectoryRecord,
|
|
10
|
-
|
|
9
|
+
ShopRecord,
|
|
11
10
|
NearbyMallRecord,
|
|
12
11
|
ProductRecord,
|
|
13
12
|
ShoppingPage,
|
|
13
|
+
RecommendMerchantsCardData,
|
|
14
14
|
} from '@tbox.cn/app-contracts-mall';
|
|
15
15
|
import type {
|
|
16
16
|
CategoryListCardData,
|
|
17
|
-
CustomerServiceFaqCardData,
|
|
18
17
|
HumanGuideListCardData,
|
|
19
18
|
LocationHandoffCardData,
|
|
20
19
|
MallDirectoryCardData,
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
ShopDetailCardData,
|
|
21
|
+
ShopListCardData,
|
|
23
22
|
NearbyMallListCardData,
|
|
24
23
|
ProductComparisonCardData,
|
|
25
24
|
ProductDetailCardData,
|
|
@@ -27,6 +26,20 @@ import type {
|
|
|
27
26
|
} from '@tbox.cn/app-contracts-mall';
|
|
28
27
|
import { nowIso } from '../domain/value-objects';
|
|
29
28
|
|
|
29
|
+
/**
|
|
30
|
+
* itemActions 填充(015 S5/F1:判别联合 send/link 两变体)。
|
|
31
|
+
* - send:发消息(value 缺省 = label);link:打开 URL(tel:/https:)。
|
|
32
|
+
* - 导航 link 用高德分享 URL search 模板(零坐标依赖,POC bridge 导航体系不迁,R5)。
|
|
33
|
+
*/
|
|
34
|
+
function amapSearchUrl(keyword: string): string {
|
|
35
|
+
return `https://uri.amap.com/search?keyword=${encodeURIComponent(keyword)}`;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function mapLinkForLocation(mallNameFallback: string, location?: { displayText: string; buildingName?: string; floorName?: string }): string {
|
|
39
|
+
const keyword = [mallNameFallback, location?.buildingName, location?.floorName].filter(Boolean).join(' ');
|
|
40
|
+
return amapSearchUrl(keyword || mallNameFallback);
|
|
41
|
+
}
|
|
42
|
+
|
|
30
43
|
export function projectProductList(
|
|
31
44
|
context: ProductListCardData['context'],
|
|
32
45
|
page: ShoppingPage<ProductRecord>,
|
|
@@ -51,7 +64,10 @@ export function projectProductList(
|
|
|
51
64
|
},
|
|
52
65
|
badges: [...p.labels],
|
|
53
66
|
caveats: [],
|
|
54
|
-
itemActions: [
|
|
67
|
+
itemActions: [
|
|
68
|
+
{ kind: 'send', label: '查看详情', value: `查看商品「${p.name}」详情` },
|
|
69
|
+
...(p.merchant.name ? [{ kind: 'send', label: '问问这家店', value: `${p.merchant.name}的${p.name}怎么样` } as const] : []),
|
|
70
|
+
],
|
|
55
71
|
})),
|
|
56
72
|
...(noResultsReason ? { noResultsReason } : {}),
|
|
57
73
|
...(page.items.length > 0
|
|
@@ -80,19 +96,33 @@ export function projectProductDetail(p: ProductRecord): ProductDetailCardData {
|
|
|
80
96
|
promotionFacts: [...p.promotionFacts],
|
|
81
97
|
evidence: [],
|
|
82
98
|
humanGuideAvailable: false,
|
|
83
|
-
itemActions: [],
|
|
99
|
+
itemActions: [{ kind: 'send', label: '问问导购', value: `帮我介绍下${p.name}` }],
|
|
84
100
|
};
|
|
85
101
|
}
|
|
86
102
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
103
|
+
/** 列表卡密度上限:卡片 data.items 不截断(前端卡片预览 3 条 + "查看全部"浮层展示全量)。
|
|
104
|
+
* pageSize=200 限制单页数据量,投影层不再二次截断。
|
|
105
|
+
* (2026-09-02 由 4→20→200:原 4 实证丢失可见性——「查看全部门店」浮层只展示截断后 items,
|
|
106
|
+
* 第 5 家起用户永远看不到;远程 PR #200 进一步取 200 取消二次截断。 */
|
|
107
|
+
export const MAX_MERCHANT_CARD_ITEMS = 200;
|
|
108
|
+
|
|
109
|
+
export function projectShopList(
|
|
110
|
+
context: ShopListCardData['context'],
|
|
111
|
+
page: ShoppingPage<ShopRecord>,
|
|
90
112
|
summary?: string,
|
|
91
|
-
|
|
113
|
+
categoryTabs?: readonly { code: string; name: string }[],
|
|
114
|
+
mallId?: string,
|
|
115
|
+
miniAppId?: string,
|
|
116
|
+
maxItems: number = MAX_MERCHANT_CARD_ITEMS,
|
|
117
|
+
): ShopListCardData {
|
|
118
|
+
const visible = page.items.slice(0, maxItems);
|
|
92
119
|
return {
|
|
93
120
|
context,
|
|
121
|
+
...(mallId ? { mallId } : {}),
|
|
122
|
+
...(miniAppId ? { miniAppId } : {}),
|
|
94
123
|
...(summary ? { summary } : {}),
|
|
95
|
-
|
|
124
|
+
...(categoryTabs && categoryTabs.length > 0 ? { categoryTabs: categoryTabs.map((t) => ({ code: t.code, name: t.name })) } : {}),
|
|
125
|
+
items: visible.map((m) => ({
|
|
96
126
|
merchantId: m.merchantId,
|
|
97
127
|
name: m.name,
|
|
98
128
|
...(m.logoUrl ? { logoUrl: m.logoUrl } : {}),
|
|
@@ -101,21 +131,33 @@ export function projectMerchantList(
|
|
|
101
131
|
businessCategories: [...m.businessCategories],
|
|
102
132
|
location: m.location,
|
|
103
133
|
status: m.status,
|
|
134
|
+
...(m.contactInfo && m.contactInfo.length > 0 ? { contactInfo: [...m.contactInfo] } : {}),
|
|
104
135
|
services: [...m.services],
|
|
105
136
|
promotionFacts: [...m.promotionFacts],
|
|
106
|
-
itemActions: [
|
|
137
|
+
itemActions: [
|
|
138
|
+
// 「查看详情」改为客户端整行点击发 visible:false 静默消息触发——不在 itemActions 挂按钮
|
|
139
|
+
{ kind: 'link', label: '导航', url: mapLinkForLocation(m.name, m.location) },
|
|
140
|
+
],
|
|
107
141
|
})),
|
|
108
|
-
...(
|
|
142
|
+
...(visible.length > 0
|
|
109
143
|
? { pageInfo: { page: page.page, pageSize: page.pageSize, total: page.total, hasMore: page.hasMore } }
|
|
110
144
|
: {}),
|
|
111
145
|
refinements: [],
|
|
112
146
|
};
|
|
113
147
|
}
|
|
148
|
+
/** @deprecated 使用 projectShopList */
|
|
149
|
+
export const projectMerchantList = projectShopList;
|
|
114
150
|
|
|
115
|
-
export function
|
|
151
|
+
export function projectShopDetail(
|
|
152
|
+
m: ShopRecord,
|
|
153
|
+
mallId?: string,
|
|
154
|
+
miniAppId?: string,
|
|
155
|
+
): ShopDetailCardData {
|
|
116
156
|
return {
|
|
117
157
|
merchantId: m.merchantId,
|
|
118
158
|
name: m.name,
|
|
159
|
+
...(mallId ? { mallId } : {}),
|
|
160
|
+
...(miniAppId ? { miniAppId } : {}),
|
|
119
161
|
...(m.logoUrl ? { logoUrl: m.logoUrl } : {}),
|
|
120
162
|
coverUrls: [...m.coverUrls],
|
|
121
163
|
...(m.brand ? { brand: m.brand } : {}),
|
|
@@ -126,20 +168,59 @@ export function projectMerchantDetail(m: MerchantRecord): MerchantDetailCardData
|
|
|
126
168
|
...(m.contactInfo ? { contactInfo: [...m.contactInfo] } : {}),
|
|
127
169
|
services: [...m.services],
|
|
128
170
|
promotionFacts: [...m.promotionFacts],
|
|
171
|
+
...(m.coupons && m.coupons.length > 0 ? { coupons: m.coupons.map((c) => ({ ...c })) } : {}),
|
|
129
172
|
evidence: [],
|
|
130
|
-
itemActions: [
|
|
173
|
+
itemActions: [
|
|
174
|
+
{ kind: 'link', label: '导航', url: mapLinkForLocation(m.name, m.location) },
|
|
175
|
+
],
|
|
131
176
|
};
|
|
132
177
|
}
|
|
178
|
+
/** @deprecated 使用 projectShopDetail */
|
|
179
|
+
export const projectMerchantDetail = projectShopDetail;
|
|
180
|
+
|
|
181
|
+
export function projectCategoryList(
|
|
182
|
+
categories: readonly CategoryRecord[],
|
|
183
|
+
directory?: MallDirectoryRecord | null,
|
|
184
|
+
): CategoryListCardData {
|
|
185
|
+
const buildings = directory?.buildings.map((b) => ({
|
|
186
|
+
buildingCode: b.buildingCode,
|
|
187
|
+
buildingName: b.buildingName,
|
|
188
|
+
floors: b.floors.map((f) => ({
|
|
189
|
+
floorCode: f.floorCode,
|
|
190
|
+
floorName: f.floorName,
|
|
191
|
+
businessCategories: [...f.businessCategories],
|
|
192
|
+
merchantCount: f.merchantCount,
|
|
193
|
+
itemActions: [
|
|
194
|
+
{
|
|
195
|
+
kind: 'send' as const,
|
|
196
|
+
label: `看看${f.floorName}`,
|
|
197
|
+
value: `展示商场${b.buildingName}${f.floorName}的门店列表`,
|
|
198
|
+
visibleValue: `${f.floorName}门店`,
|
|
199
|
+
},
|
|
200
|
+
],
|
|
201
|
+
})),
|
|
202
|
+
}));
|
|
133
203
|
|
|
134
|
-
export function projectCategoryList(categories: readonly CategoryRecord[]): CategoryListCardData {
|
|
135
204
|
return {
|
|
136
205
|
categories: categories.map((c) => ({
|
|
137
206
|
code: c.code,
|
|
138
207
|
name: c.name,
|
|
139
208
|
...(c.description ? { description: c.description } : {}),
|
|
209
|
+
// iconUrl 有值则透传;无值不写字段,前端卡片侧展示默认图标
|
|
210
|
+
...(c.iconUrl ? { iconUrl: c.iconUrl } : {}),
|
|
140
211
|
merchantCount: c.merchantCount,
|
|
141
212
|
...(c.subCategories ? { subCategories: [...c.subCategories] } : {}),
|
|
213
|
+
// 点击类目走 search-shops(按类目 code 筛选门店列表)
|
|
214
|
+
itemActions: [
|
|
215
|
+
{
|
|
216
|
+
kind: 'send',
|
|
217
|
+
label: c.name,
|
|
218
|
+
value: `展示商场里${c.name}的门店列表`,
|
|
219
|
+
visibleValue: `查看${c.name}门店`,
|
|
220
|
+
},
|
|
221
|
+
],
|
|
142
222
|
})),
|
|
223
|
+
...(buildings && buildings.length > 0 ? { buildings } : {}),
|
|
143
224
|
observedAt: nowIso(),
|
|
144
225
|
};
|
|
145
226
|
}
|
|
@@ -191,27 +272,13 @@ export function projectNearbyMalls(
|
|
|
191
272
|
address: m.address,
|
|
192
273
|
...(m.distanceKm !== undefined ? { distanceKm: m.distanceKm } : {}),
|
|
193
274
|
status: m.status,
|
|
194
|
-
itemActions
|
|
275
|
+
// R6:切商场不进 itemActions(无该变体);「有什么店」话术替代
|
|
276
|
+
itemActions: [{ kind: 'send', label: `${m.name}有什么店`, value: `${m.name}里有什么店` }],
|
|
195
277
|
})),
|
|
196
278
|
};
|
|
197
279
|
}
|
|
198
280
|
|
|
199
|
-
|
|
200
|
-
query: string,
|
|
201
|
-
faqs: readonly FaqEntry[],
|
|
202
|
-
noResultsReason?: string,
|
|
203
|
-
): CustomerServiceFaqCardData {
|
|
204
|
-
return {
|
|
205
|
-
query,
|
|
206
|
-
faqs: faqs.map((f) => ({
|
|
207
|
-
question: f.question,
|
|
208
|
-
answer: f.answer,
|
|
209
|
-
...(f.category ? { category: f.category } : {}),
|
|
210
|
-
relevanceScore: f.relevanceScore,
|
|
211
|
-
})),
|
|
212
|
-
...(noResultsReason ? { noResultsReason } : {}),
|
|
213
|
-
};
|
|
214
|
-
}
|
|
281
|
+
// projectCustomerServiceFaq:客服承接已拆分至 module-customer-service(2026-08-31)
|
|
215
282
|
|
|
216
283
|
export function projectHumanGuideList(
|
|
217
284
|
merchantId: string,
|
|
@@ -228,19 +295,22 @@ export function projectHumanGuideList(
|
|
|
228
295
|
...(g.avatarUrl ? { avatarUrl: g.avatarUrl } : {}),
|
|
229
296
|
...(g.contactInfo ? { contactInfo: [...g.contactInfo] } : {}),
|
|
230
297
|
available: g.available,
|
|
231
|
-
itemActions: [],
|
|
298
|
+
itemActions: [{ kind: 'send', label: `联系${g.name}`, value: `我想联系${merchantName}的导购${g.name}` }],
|
|
232
299
|
})),
|
|
233
300
|
};
|
|
234
301
|
}
|
|
235
302
|
|
|
236
303
|
export function projectLocationHandoff(
|
|
237
|
-
|
|
304
|
+
shop: ShopRecord,
|
|
238
305
|
): LocationHandoffCardData {
|
|
239
306
|
return {
|
|
240
|
-
merchantId:
|
|
241
|
-
merchantName:
|
|
242
|
-
location:
|
|
243
|
-
|
|
307
|
+
merchantId: shop.merchantId,
|
|
308
|
+
merchantName: shop.name,
|
|
309
|
+
location: shop.location,
|
|
310
|
+
...(shop.location.poiId || shop.location.displayText
|
|
311
|
+
? { mapUrl: mapLinkForLocation(shop.name, shop.location) }
|
|
312
|
+
: {}),
|
|
313
|
+
itemActions: [{ kind: 'link', label: '开始导航', url: mapLinkForLocation(shop.name, shop.location) }],
|
|
244
314
|
};
|
|
245
315
|
}
|
|
246
316
|
|
|
@@ -251,3 +321,51 @@ export function projectKnowledge(knowledge: readonly KnowledgeEntry[]): string {
|
|
|
251
321
|
.map((k) => `${k.title ? `【${k.title}】` : ''}${k.content}`.slice(0, 500))
|
|
252
322
|
.join('\n\n');
|
|
253
323
|
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* recommend-merchants 投影:门店列表 → 推荐门店卡数据(含类目 Tab)。
|
|
327
|
+
* - categoryTabs:来自 list-categories 的类目列表(可选)
|
|
328
|
+
* - summary:答话摘要(可选)
|
|
329
|
+
* - items:按 merchant 投影,itemActions 包含「问问导购」send action
|
|
330
|
+
*/
|
|
331
|
+
export function projectRecommendMerchants(
|
|
332
|
+
shops: readonly ShopRecord[],
|
|
333
|
+
categoryTabs?: readonly { code: string; name: string }[],
|
|
334
|
+
summary?: string,
|
|
335
|
+
): RecommendMerchantsCardData {
|
|
336
|
+
return {
|
|
337
|
+
...(summary ? { summary } : {}),
|
|
338
|
+
...(categoryTabs && categoryTabs.length > 0
|
|
339
|
+
? { categoryTabs: categoryTabs.map((tab) => ({ code: tab.code, name: tab.name })) }
|
|
340
|
+
: {}),
|
|
341
|
+
items: shops.map((m) => {
|
|
342
|
+
const mExt = m as ShopRecord & { operatingStatus?: string; rating?: string; avgSpend?: string };
|
|
343
|
+
return {
|
|
344
|
+
merchantId: m.merchantId,
|
|
345
|
+
name: m.name,
|
|
346
|
+
...(m.logoUrl ? { logoUrl: m.logoUrl } : {}),
|
|
347
|
+
...(m.coverUrls[0] ? { coverUrl: m.coverUrls[0] } : {}),
|
|
348
|
+
...(m.brand ? { brand: m.brand } : {}),
|
|
349
|
+
businessCategories: [...m.businessCategories],
|
|
350
|
+
location: m.location,
|
|
351
|
+
status: m.status,
|
|
352
|
+
...(m.description ? { description: m.description } : {}),
|
|
353
|
+
...(m.contactInfo ? { contactInfo: [...m.contactInfo] } : {}),
|
|
354
|
+
services: [...m.services],
|
|
355
|
+
...(mExt.operatingStatus ? { operatingStatus: mExt.operatingStatus } : {}),
|
|
356
|
+
...(mExt.rating ? { rating: mExt.rating } : {}),
|
|
357
|
+
...(mExt.avgSpend ? { avgSpend: mExt.avgSpend } : {}),
|
|
358
|
+
promotionFacts: [...m.promotionFacts],
|
|
359
|
+
itemActions: [
|
|
360
|
+
{
|
|
361
|
+
kind: 'send',
|
|
362
|
+
label: '问问导购',
|
|
363
|
+
value: `帮我介绍下「${m.name}」`,
|
|
364
|
+
visibleValue: '问问导购',
|
|
365
|
+
},
|
|
366
|
+
],
|
|
367
|
+
};
|
|
368
|
+
}),
|
|
369
|
+
observedAt: nowIso(),
|
|
370
|
+
};
|
|
371
|
+
}
|