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

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 (47) hide show
  1. package/LICENSE +21 -0
  2. package/dist/chunk-AGBLC6XI.js +1294 -0
  3. package/dist/chunk-U4WDS5PQ.js +173 -0
  4. package/dist/client/index.d.ts +25 -0
  5. package/dist/client/index.js +6 -0
  6. package/dist/index.d.ts +8 -0
  7. package/dist/index.js +22 -0
  8. package/dist/server/index.d.ts +4098 -0
  9. package/dist/server/index.js +18 -0
  10. package/package.json +62 -0
  11. package/skills/shopping-guide/SKILL.md +36 -0
  12. package/skills/shopping-guide/references/comparison-format.md +5 -0
  13. package/skills/shopping-guide/references/faq-answers.md +5 -0
  14. package/skills/shopping-guide/references/floor-directory.md +4 -0
  15. package/skills/shopping-guide/references/intent-patterns.md +5 -0
  16. package/skills/shopping-guide/references/location-format.md +5 -0
  17. package/skills/shopping-guide/references/policy-lookup.md +5 -0
  18. package/skills/shopping-guide/references/product-search-tips.md +6 -0
  19. package/skills/shopping-guide/references/recommendation-style.md +5 -0
  20. package/src/client/cards/index.tsx +267 -0
  21. package/src/client/index.ts +39 -0
  22. package/src/index.ts +6 -0
  23. package/src/server/cards/category-list/meta.ts +19 -0
  24. package/src/server/cards/customer-service-faq/meta.ts +18 -0
  25. package/src/server/cards/human-guide-list/meta.ts +19 -0
  26. package/src/server/cards/index.ts +43 -0
  27. package/src/server/cards/location-handoff/meta.ts +20 -0
  28. package/src/server/cards/mall-directory/meta.ts +27 -0
  29. package/src/server/cards/merchant-detail/meta.ts +27 -0
  30. package/src/server/cards/merchant-list/meta.ts +31 -0
  31. package/src/server/cards/nearby-mall-list/meta.ts +17 -0
  32. package/src/server/cards/product-comparison/meta.ts +29 -0
  33. package/src/server/cards/product-detail/meta.ts +29 -0
  34. package/src/server/cards/product-list/meta.ts +32 -0
  35. package/src/server/domain/value-objects.ts +49 -0
  36. package/src/server/index.ts +180 -0
  37. package/src/server/integrations/joycity/adapter.ts +226 -0
  38. package/src/server/integrations/joycity/auth-strategy.ts +38 -0
  39. package/src/server/integrations/joycity/gateway.ts +128 -0
  40. package/src/server/ports/index.ts +151 -0
  41. package/src/server/ports/local-adapters.ts +90 -0
  42. package/src/server/projections/index.ts +253 -0
  43. package/src/server/tools/index.ts +407 -0
  44. package/tbox.component.json +48 -0
  45. package/tests/shopping-guide.test.ts +290 -0
  46. package/tsconfig.json +8 -0
  47. package/tsup.config.ts +29 -0
@@ -0,0 +1,128 @@
1
+ /**
2
+ * JoyCity 商业网关(011 K6):AuthenticatedTransport 之上的薄 DTO 网关。
3
+ * 签名由 ProviderAuthStrategy(transport 层)完成;本网关只负责路径/请求/响应解包。
4
+ */
5
+ import type { AuthenticatedTransport } from '@tbox.cn/app-contracts';
6
+
7
+ interface JoyCityResponse<T> {
8
+ readonly Code: number;
9
+ readonly Data: T;
10
+ }
11
+
12
+ export const JOYCITY_READ_OPERATIONS = {
13
+ listMerchants: '/api/merchant/list',
14
+ getMerchant: '/api/merchant/detail',
15
+ listCategories: '/api/category/list',
16
+ searchProducts: '/api/product/search',
17
+ getProduct: '/api/product/detail',
18
+ mallDirectory: '/api/mall/directory',
19
+ nearbyMalls: '/api/mall/nearby',
20
+ } as const;
21
+
22
+ // ===== DTO 形状(joycity 上游;模块内部使用,不对外) =====
23
+
24
+ export interface JoyCityMerchantListItemDto {
25
+ readonly MerchantID?: number;
26
+ readonly Name?: string;
27
+ readonly LogoUrl?: string;
28
+ readonly CoverUrl?: string;
29
+ readonly BrandName?: string;
30
+ readonly CommercialTypeID?: number;
31
+ readonly CommercialTypeName?: string;
32
+ readonly BuildingName?: string;
33
+ readonly FloorName?: string;
34
+ readonly UnitName?: string;
35
+ readonly Status?: number;
36
+ readonly Services?: readonly string[];
37
+ readonly PromotionFacts?: readonly string[];
38
+ }
39
+
40
+ export interface JoyCityMerchantDetailDto extends JoyCityMerchantListItemDto {
41
+ readonly Description?: string;
42
+ readonly ContactInfo?: ReadonlyArray<{ readonly Channel?: string; readonly Value?: string }>;
43
+ }
44
+
45
+ export interface JoyCityCategoryDto {
46
+ readonly CategoryID?: number;
47
+ readonly Name?: string;
48
+ readonly Description?: string;
49
+ readonly MerchantCount?: number;
50
+ readonly SubCategories?: readonly JoyCityCategoryDto[];
51
+ }
52
+
53
+ export interface JoyCityProductDto {
54
+ readonly ProductID?: number;
55
+ readonly Name?: string;
56
+ readonly Description?: string;
57
+ readonly ImageUrl?: string;
58
+ readonly BrandName?: string;
59
+ readonly CategoryPath?: readonly string[];
60
+ readonly PriceYuan?: number;
61
+ readonly OriginalPriceYuan?: number;
62
+ readonly StockStatus?: string;
63
+ readonly StockLabel?: string;
64
+ readonly Marketable?: boolean;
65
+ readonly MerchantID?: number;
66
+ readonly MerchantName?: string;
67
+ readonly BuildingName?: string;
68
+ readonly FloorName?: string;
69
+ readonly UnitName?: string;
70
+ readonly Labels?: readonly string[];
71
+ readonly PromotionFacts?: readonly string[];
72
+ }
73
+
74
+ export interface JoyCityMallDirectoryDto {
75
+ readonly MallID?: string;
76
+ readonly MallName?: string;
77
+ readonly Buildings?: ReadonlyArray<{
78
+ readonly BuildingCode?: string;
79
+ readonly BuildingName?: string;
80
+ readonly Floors?: ReadonlyArray<{
81
+ readonly FloorCode?: string;
82
+ readonly FloorName?: string;
83
+ readonly BusinessCategories?: readonly string[];
84
+ readonly MerchantCount?: number;
85
+ }>;
86
+ }>;
87
+ }
88
+
89
+ export class JoyCityTransportGateway {
90
+ readonly #transport: AuthenticatedTransport;
91
+
92
+ constructor(transport: AuthenticatedTransport) {
93
+ this.#transport = transport;
94
+ Object.freeze(this);
95
+ }
96
+
97
+ async listMerchants(body: Record<string, unknown>): Promise<readonly JoyCityMerchantListItemDto[]> {
98
+ return this.#post<readonly JoyCityMerchantListItemDto[]>(JOYCITY_READ_OPERATIONS.listMerchants, body);
99
+ }
100
+
101
+ async getMerchant(body: Record<string, unknown>): Promise<JoyCityMerchantDetailDto | null> {
102
+ return this.#post<JoyCityMerchantDetailDto | null>(JOYCITY_READ_OPERATIONS.getMerchant, body);
103
+ }
104
+
105
+ async listCategories(body: Record<string, unknown>): Promise<readonly JoyCityCategoryDto[]> {
106
+ return this.#post<readonly JoyCityCategoryDto[]>(JOYCITY_READ_OPERATIONS.listCategories, body);
107
+ }
108
+
109
+ async searchProducts(body: Record<string, unknown>): Promise<readonly JoyCityProductDto[]> {
110
+ return this.#post<readonly JoyCityProductDto[]>(JOYCITY_READ_OPERATIONS.searchProducts, body);
111
+ }
112
+
113
+ async getProduct(body: Record<string, unknown>): Promise<JoyCityProductDto | null> {
114
+ return this.#post<JoyCityProductDto | null>(JOYCITY_READ_OPERATIONS.getProduct, body);
115
+ }
116
+
117
+ async getMallDirectory(body: Record<string, unknown>): Promise<JoyCityMallDirectoryDto | null> {
118
+ return this.#post<JoyCityMallDirectoryDto | null>(JOYCITY_READ_OPERATIONS.mallDirectory, body);
119
+ }
120
+
121
+ async #post<T>(path: string, body: Record<string, unknown>): Promise<T> {
122
+ const response = (await this.#transport.request({ path, body })) as JoyCityResponse<T>;
123
+ if (response.Code !== 1) {
124
+ throw new Error(`JoyCity API 错误:Code=${response.Code}`);
125
+ }
126
+ return response.Data;
127
+ }
128
+ }
@@ -0,0 +1,151 @@
1
+ /**
2
+ * 导购 Port 聚合(011 S7):joycity adapter + 本地 adapter 组合。
3
+ * 模块内工具经 resolveShoppingPorts(ctx) 解析;服务实例模块包顶层单例。
4
+ */
5
+ import type {
6
+ AssistanceQueryPort,
7
+ CatalogQueryPort,
8
+ CommercialCategoryQueryPort,
9
+ MallDirectoryQueryPort,
10
+ MerchantDirectoryQueryPort,
11
+ NavigationPort,
12
+ } from '@tbox.cn/app-contracts-mall';
13
+ 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
+ import {
17
+ JoyCityCatalogAdapter,
18
+ JoyCityCategoryAdapter,
19
+ JoyCityMallDirectoryAdapter,
20
+ JoyCityMerchantAdapter,
21
+ } from '../integrations/joycity/adapter';
22
+ import { JoyCityTransportGateway } from '../integrations/joycity/gateway';
23
+ import { KnowledgeAssistanceAdapter, LocalNavigationAdapter } from './local-adapters';
24
+
25
+ export const SHOPPING_GUIDE_PROVIDER_TEMPLATE_ID = 'joycity-commercial@1';
26
+
27
+ export interface ShoppingGuidePorts {
28
+ catalog: CatalogQueryPort;
29
+ merchant: MerchantDirectoryQueryPort;
30
+ category: CommercialCategoryQueryPort;
31
+ directory: MallDirectoryQueryPort;
32
+ assistance: AssistanceQueryPort;
33
+ navigation: NavigationPort;
34
+ }
35
+
36
+ /**
37
+ * 011 G3:模块级 connector 缓存(key = mallId;无 mall → 'none')。
38
+ * 全图(gateway + 4 adapter + knowledge client)单例——transport 本身由 SDK registry 缓存,
39
+ * credentialVersion 变更在 SDK 层失效,本图无需感知。
40
+ * 011 评审 7.3:TTL 30min——provider 实例集 reload(config 变更)后窗口期内自动重解析
41
+ * (凭证轮换即时性由 SDK transport 层保证;baseUrl 等实例配置变更经 TTL 生效)。
42
+ */
43
+ const PORT_CACHE_TTL_MS = 30 * 60 * 1000;
44
+ const portCache = new Map<string, { ports: ShoppingGuidePorts; at: number }>();
45
+
46
+ /**
47
+ * 解析导购 Port 集合(运行期调用;register 只注册不解析——铁律)。
48
+ * - providers 注入(模板装配):走 ctx.providers.resolve(SDK 缓存 transport);
49
+ * - 未装配 providers(模块单测/本地演示):本地知识库 + 空数据 adapter。
50
+ */
51
+ export async function resolveShoppingGuidePorts(ctx: ServerContext): Promise<ShoppingGuidePorts> {
52
+ const mallId = currentMallId(ctx) ?? 'none';
53
+ const cached = portCache.get(mallId);
54
+ if (cached && Date.now() - cached.at < PORT_CACHE_TTL_MS) return cached.ports;
55
+
56
+ let gateway: JoyCityTransportGateway | undefined;
57
+ try {
58
+ const resolved = await ctx.providers.resolve({
59
+ templateId: SHOPPING_GUIDE_PROVIDER_TEMPLATE_ID,
60
+ scope: mallId !== 'none' ? { mallId } : {},
61
+ });
62
+ gateway = new JoyCityTransportGateway(resolved.transport);
63
+ } catch {
64
+ gateway = undefined; // 未装配 provider → 本地降级
65
+ }
66
+
67
+ const ports: ShoppingGuidePorts = gateway
68
+ ? {
69
+ catalog: new JoyCityCatalogAdapter(gateway),
70
+ merchant: new JoyCityMerchantAdapter(gateway),
71
+ category: new JoyCityCategoryAdapter(gateway),
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;
86
+ }
87
+
88
+ let _localAssistance: AssistanceQueryPort | undefined;
89
+ function createLocalAssistance(): AssistanceQueryPort {
90
+ // 011 I7:knowledge client 单例(避免每工具调用重建)
91
+ if (_localAssistance) return _localAssistance;
92
+ try {
93
+ _localAssistance = new KnowledgeAssistanceAdapter(createKnowledgeClient());
94
+ } catch {
95
+ // TBOX_API_KEY 未配置 → 空 FAQ(静默降级)
96
+ _localAssistance = new EmptyAssistanceAdapter();
97
+ }
98
+ return _localAssistance;
99
+ }
100
+
101
+ function currentMallId(ctx: ServerContext): string | undefined {
102
+ // 011 评审 6.1:经 TIER1 parseMallScope 解析(不手解 attributes 原始形状)
103
+ return parseMallScope(ctx.auth.getContext()?.attributes)?.mallId;
104
+ }
105
+
106
+ // ===== 空实现(未装配 Provider / 未配置平台凭据时的降级) =====
107
+
108
+ class EmptyCatalogAdapter implements CatalogQueryPort {
109
+ async searchProducts() {
110
+ return { items: [], page: 1, pageSize: 10, total: 0, hasMore: false };
111
+ }
112
+ async getProduct() {
113
+ return null;
114
+ }
115
+ async getFacets() {
116
+ return { brands: [], categories: [], priceRanges: [], floors: [] };
117
+ }
118
+ }
119
+
120
+ class EmptyMerchantAdapter implements MerchantDirectoryQueryPort {
121
+ async searchMerchants() {
122
+ return { items: [], page: 1, pageSize: 10, total: 0, hasMore: false };
123
+ }
124
+ async getMerchant() {
125
+ return null;
126
+ }
127
+ }
128
+
129
+ class EmptyCategoryAdapter implements CommercialCategoryQueryPort {
130
+ async listCategories() {
131
+ return [];
132
+ }
133
+ }
134
+
135
+ class EmptyDirectoryAdapter implements MallDirectoryQueryPort {
136
+ async getDirectory() {
137
+ return null;
138
+ }
139
+ }
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
+ }
@@ -0,0 +1,90 @@
1
+ /**
2
+ * 本地协助/导航 Port 实现(011 K6):FAQ/知识库走 SDK KnowledgeClient;
3
+ * 人工导购/附近商场/浏览历史为本地实现(真实数据源接入点)。
4
+ */
5
+ import type {
6
+ AssistanceQueryPort,
7
+ FaqEntry,
8
+ HumanGuideRecord,
9
+ KnowledgeEntry,
10
+ MerchantLocationRecord,
11
+ NavigationPort,
12
+ NearbyMallRecord,
13
+ ProductRecord,
14
+ ShoppingPage,
15
+ ShoppingQueryContext,
16
+ } 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
+
59
+ export class LocalNavigationAdapter implements NavigationPort {
60
+ async getLocation(
61
+ _merchantId: string,
62
+ _ctx: ShoppingQueryContext,
63
+ ): Promise<MerchantLocationRecord | null> {
64
+ // 位置信息已内嵌 merchant.search 结果;单独查询由 joycity merchant adapter 补充(二期)
65
+ return null;
66
+ }
67
+
68
+ async listNearbyMalls(
69
+ _ctx: ShoppingQueryContext,
70
+ _query?: string,
71
+ ): Promise<readonly NearbyMallRecord[]> {
72
+ return [];
73
+ }
74
+
75
+ async listBrowsingHistory(
76
+ _ctx: ShoppingQueryContext,
77
+ _page: number,
78
+ _pageSize: number,
79
+ ): Promise<ShoppingPage<ProductRecord>> {
80
+ return { items: [], page: 1, pageSize: 10, total: 0, hasMore: false };
81
+ }
82
+ }
83
+
84
+ function summarize(content: string): string {
85
+ return content
86
+ .replace(/^#+\s+/gm, '')
87
+ .replace(/\s+/g, ' ')
88
+ .trim()
89
+ .slice(0, 320);
90
+ }
@@ -0,0 +1,253 @@
1
+ /**
2
+ * 导购投影层(011 S7):contracts-mall record → 卡数据(zod 校验形状)。
3
+ * 每卡一个投影函数,工具 execute 调用后经 cardResolver(allowedTools 绑定)出卡。
4
+ */
5
+ import type {
6
+ CategoryRecord,
7
+ FaqEntry,
8
+ KnowledgeEntry,
9
+ MallDirectoryRecord,
10
+ MerchantRecord,
11
+ NearbyMallRecord,
12
+ ProductRecord,
13
+ ShoppingPage,
14
+ } from '@tbox.cn/app-contracts-mall';
15
+ import type {
16
+ CategoryListCardData,
17
+ CustomerServiceFaqCardData,
18
+ HumanGuideListCardData,
19
+ LocationHandoffCardData,
20
+ MallDirectoryCardData,
21
+ MerchantDetailCardData,
22
+ MerchantListCardData,
23
+ NearbyMallListCardData,
24
+ ProductComparisonCardData,
25
+ ProductDetailCardData,
26
+ ProductListCardData,
27
+ } from '@tbox.cn/app-contracts-mall';
28
+ import { nowIso } from '../domain/value-objects';
29
+
30
+ export function projectProductList(
31
+ context: ProductListCardData['context'],
32
+ page: ShoppingPage<ProductRecord>,
33
+ summary?: string,
34
+ noResultsReason?: string,
35
+ ): ProductListCardData {
36
+ return {
37
+ context,
38
+ ...(summary ? { summary } : {}),
39
+ items: page.items.map((p) => ({
40
+ productId: p.productId,
41
+ name: p.name,
42
+ ...(p.imageUrls[0] ? { imageUrl: p.imageUrls[0] } : {}),
43
+ ...(p.brand ? { brand: p.brand } : {}),
44
+ categoryPath: [...p.categoryPath],
45
+ price: p.price,
46
+ availability: p.availability,
47
+ merchant: {
48
+ merchantId: p.merchant.merchantId,
49
+ name: p.merchant.name,
50
+ ...(p.merchant.location ? { location: p.merchant.location } : {}),
51
+ },
52
+ badges: [...p.labels],
53
+ caveats: [],
54
+ itemActions: [],
55
+ })),
56
+ ...(noResultsReason ? { noResultsReason } : {}),
57
+ ...(page.items.length > 0
58
+ ? { pageInfo: { page: page.page, pageSize: page.pageSize, total: page.total, hasMore: page.hasMore } }
59
+ : {}),
60
+ refinements: [],
61
+ };
62
+ }
63
+
64
+ export function projectProductDetail(p: ProductRecord): ProductDetailCardData {
65
+ return {
66
+ productId: p.productId,
67
+ name: p.name,
68
+ ...(p.description ? { description: p.description } : {}),
69
+ imageUrls: [...p.imageUrls],
70
+ ...(p.brand ? { brand: p.brand } : {}),
71
+ categoryPath: [...p.categoryPath],
72
+ price: p.price,
73
+ availability: p.availability,
74
+ merchant: {
75
+ merchantId: p.merchant.merchantId,
76
+ name: p.merchant.name,
77
+ ...(p.merchant.location ? { location: p.merchant.location } : {}),
78
+ },
79
+ attributes: [...p.attributes],
80
+ promotionFacts: [...p.promotionFacts],
81
+ evidence: [],
82
+ humanGuideAvailable: false,
83
+ itemActions: [],
84
+ };
85
+ }
86
+
87
+ export function projectMerchantList(
88
+ context: MerchantListCardData['context'],
89
+ page: ShoppingPage<MerchantRecord>,
90
+ summary?: string,
91
+ ): MerchantListCardData {
92
+ return {
93
+ context,
94
+ ...(summary ? { summary } : {}),
95
+ items: page.items.map((m) => ({
96
+ merchantId: m.merchantId,
97
+ name: m.name,
98
+ ...(m.logoUrl ? { logoUrl: m.logoUrl } : {}),
99
+ ...(m.coverUrls[0] ? { coverUrl: m.coverUrls[0] } : {}),
100
+ ...(m.brand ? { brand: m.brand } : {}),
101
+ businessCategories: [...m.businessCategories],
102
+ location: m.location,
103
+ status: m.status,
104
+ services: [...m.services],
105
+ promotionFacts: [...m.promotionFacts],
106
+ itemActions: [],
107
+ })),
108
+ ...(page.items.length > 0
109
+ ? { pageInfo: { page: page.page, pageSize: page.pageSize, total: page.total, hasMore: page.hasMore } }
110
+ : {}),
111
+ refinements: [],
112
+ };
113
+ }
114
+
115
+ export function projectMerchantDetail(m: MerchantRecord): MerchantDetailCardData {
116
+ return {
117
+ merchantId: m.merchantId,
118
+ name: m.name,
119
+ ...(m.logoUrl ? { logoUrl: m.logoUrl } : {}),
120
+ coverUrls: [...m.coverUrls],
121
+ ...(m.brand ? { brand: m.brand } : {}),
122
+ businessCategories: [...m.businessCategories],
123
+ location: m.location,
124
+ status: m.status,
125
+ ...(m.description ? { description: m.description } : {}),
126
+ ...(m.contactInfo ? { contactInfo: [...m.contactInfo] } : {}),
127
+ services: [...m.services],
128
+ promotionFacts: [...m.promotionFacts],
129
+ evidence: [],
130
+ itemActions: [],
131
+ };
132
+ }
133
+
134
+ export function projectCategoryList(categories: readonly CategoryRecord[]): CategoryListCardData {
135
+ return {
136
+ categories: categories.map((c) => ({
137
+ code: c.code,
138
+ name: c.name,
139
+ ...(c.description ? { description: c.description } : {}),
140
+ merchantCount: c.merchantCount,
141
+ ...(c.subCategories ? { subCategories: [...c.subCategories] } : {}),
142
+ })),
143
+ observedAt: nowIso(),
144
+ };
145
+ }
146
+
147
+ export function projectProductComparison(products: readonly ProductRecord[]): ProductComparisonCardData {
148
+ return {
149
+ products: products.map((p) => ({
150
+ productId: p.productId,
151
+ name: p.name,
152
+ ...(p.imageUrls[0] ? { imageUrl: p.imageUrls[0] } : {}),
153
+ ...(p.brand ? { brand: p.brand } : {}),
154
+ price: p.price,
155
+ availability: p.availability,
156
+ merchant: { merchantId: p.merchant.merchantId, name: p.merchant.name },
157
+ attributes: [...p.attributes],
158
+ caveats: [],
159
+ })),
160
+ observedAt: nowIso(),
161
+ };
162
+ }
163
+
164
+ export function projectMallDirectory(d: MallDirectoryRecord): MallDirectoryCardData {
165
+ return {
166
+ mallId: d.mallId,
167
+ mallName: d.mallName,
168
+ buildings: d.buildings.map((b) => ({
169
+ buildingCode: b.buildingCode,
170
+ buildingName: b.buildingName,
171
+ floors: b.floors.map((f) => ({
172
+ floorCode: f.floorCode,
173
+ floorName: f.floorName,
174
+ businessCategories: [...f.businessCategories],
175
+ merchantCount: f.merchantCount,
176
+ })),
177
+ })),
178
+ observedAt: d.observedAt,
179
+ };
180
+ }
181
+
182
+ export function projectNearbyMalls(
183
+ malls: readonly NearbyMallRecord[],
184
+ query?: string,
185
+ ): NearbyMallListCardData {
186
+ return {
187
+ ...(query ? { query } : {}),
188
+ malls: malls.map((m) => ({
189
+ mallId: m.mallId,
190
+ name: m.name,
191
+ address: m.address,
192
+ ...(m.distanceKm !== undefined ? { distanceKm: m.distanceKm } : {}),
193
+ status: m.status,
194
+ itemActions: [],
195
+ })),
196
+ };
197
+ }
198
+
199
+ export function projectCustomerServiceFaq(
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
+ }
215
+
216
+ export function projectHumanGuideList(
217
+ merchantId: string,
218
+ merchantName: string,
219
+ guides: readonly import('@tbox.cn/app-contracts-mall').HumanGuideRecord[],
220
+ ): HumanGuideListCardData {
221
+ return {
222
+ merchantId,
223
+ merchantName,
224
+ guides: guides.map((g) => ({
225
+ guideId: g.guideId,
226
+ name: g.name,
227
+ ...(g.title ? { title: g.title } : {}),
228
+ ...(g.avatarUrl ? { avatarUrl: g.avatarUrl } : {}),
229
+ ...(g.contactInfo ? { contactInfo: [...g.contactInfo] } : {}),
230
+ available: g.available,
231
+ itemActions: [],
232
+ })),
233
+ };
234
+ }
235
+
236
+ export function projectLocationHandoff(
237
+ merchant: MerchantRecord,
238
+ ): LocationHandoffCardData {
239
+ return {
240
+ merchantId: merchant.merchantId,
241
+ merchantName: merchant.name,
242
+ location: merchant.location,
243
+ itemActions: [],
244
+ };
245
+ }
246
+
247
+ /** 知识检索结果投影(search-knowledge 工具:非卡输出,text 汇总) */
248
+ export function projectKnowledge(knowledge: readonly KnowledgeEntry[]): string {
249
+ if (knowledge.length === 0) return '未检索到相关知识内容。';
250
+ return knowledge
251
+ .map((k) => `${k.title ? `【${k.title}】` : ''}${k.content}`.slice(0, 500))
252
+ .join('\n\n');
253
+ }