@tbox.cn/app-module-shopping-guide 1.0.0-alpha.15 → 1.0.0-alpha.17

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.
@@ -1,10 +1,14 @@
1
1
  import {
2
+ INDOOR_NAVIGATION_SERVICE,
3
+ createShoppingGuideRouter,
2
4
  createShoppingGuideTools,
3
5
  resolveShoppingGuidePorts,
4
6
  serverModule,
5
7
  shoppingGuideCards
6
- } from "../chunk-43AO3W7C.js";
8
+ } from "../chunk-B3SVEGHZ.js";
7
9
  export {
10
+ INDOOR_NAVIGATION_SERVICE,
11
+ createShoppingGuideRouter,
8
12
  createShoppingGuideTools,
9
13
  resolveShoppingGuidePorts,
10
14
  serverModule,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tbox.cn/app-module-shopping-guide",
3
- "version": "1.0.0-alpha.15",
3
+ "version": "1.0.0-alpha.17",
4
4
  "type": "module",
5
5
  "description": "门店导览模块:商品/商户搜索、推荐、对比、商场目录、人工导购、位置导航。",
6
6
  "exports": {
@@ -19,16 +19,16 @@
19
19
  "./package.json": "./package.json"
20
20
  },
21
21
  "dependencies": {
22
- "@tbox.cn/app-contracts": "1.0.0-alpha.15",
23
- "@tbox.cn/app-contracts-mall": "1.0.0-alpha.15",
24
- "@tbox.cn/app-agent-sdk-server": "1.0.0-alpha.15",
25
- "@tbox.cn/app-agent-sdk-client": "1.0.0-alpha.15"
22
+ "@tbox.cn/app-agent-sdk-client": "1.0.0-alpha.17",
23
+ "@tbox.cn/app-contracts-mall": "1.0.0-alpha.17",
24
+ "@tbox.cn/app-contracts": "1.0.0-alpha.17",
25
+ "@tbox.cn/app-agent-sdk-server": "1.0.0-alpha.17"
26
26
  },
27
27
  "peerDependencies": {
28
28
  "zod": "3.25.76",
29
29
  "react": "18.3.1",
30
30
  "@phosphor-icons/react": "2.1.10",
31
- "@tbox.cn/app-agent-ui-kit": "^1.0.0-alpha.15"
31
+ "@tbox.cn/app-agent-ui-kit": "^1.0.0-alpha.17"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@types/react": "18.3.31",
@@ -41,7 +41,9 @@
41
41
  "react-dom": "18.3.1",
42
42
  "@types/react-dom": "18.3.7",
43
43
  "express": "4.22.2",
44
- "@types/express": "4.17.25"
44
+ "@types/express": "4.17.25",
45
+ "supertest": "7.2.2",
46
+ "@types/supertest": "7.2.1"
45
47
  },
46
48
  "files": [
47
49
  "dist",
@@ -81,6 +81,11 @@ routingTerms:
81
81
 
82
82
  用户同时指定楼层和类目(如"3 楼有餐饮吗""2 楼有什么运动品牌""4 楼有吃饭的地方吗")时:同一个 `search-shops` 调用里同时填 `floorCode` + `businessCategory`,一次调用拿到该楼层下指定类目的门店。不要只填 floorCode 返回全量再自己筛——模型人肉筛选结果不会出对应的过滤卡片。类目编码从 mall-context 注入块(本轮或会话内历史轮均有效)的 `categories[].code` 取(如"吃饭/火锅/餐饮"→ `"餐饮"`),楼层编码从 `floors[].id` 取。
83
83
 
84
+ ### 换一批与条件延续
85
+
86
+ 用户说“还有别的吗”“换一批”时保留之前的楼层、楼栋、品类及同行人要求,只替换这次明确改变的条件。调用 `search-shops` 时用 `excludedMerchantIds` 排除先前已推荐的门店(包括正文和卡片预览);做小批量推荐时传小页长。只有用户同意才放宽条件。若当前条件确无新店,问愿意换楼层还是换品类。
87
+ 店名疑似错字时,给出本次结果中的实际品牌和位置供确认。距离远近、相邻关系、安静程度、价格、库存、儿童设施或食材均需有相应数据;仅有门店目录时可提供位置或已查到的联系方式。
88
+
84
89
  ### 行程规划
85
90
 
86
91
  用户要"规划行程""安排一天""推荐逛吃路线"时:先调 `search-shops`(无参数全量)拿本轮门店卡,再排时间线。正文只给时间线骨架(时段 + 楼层 + 一两个锚点品牌,如"11:30 上 2F 儿童区放电"),品牌清单交给卡片——行程里把各楼层品牌铺满正文,等于替用户逛完了卡片;吃喝优惠想提就再调促销工具,但门店总表这张卡不能省。历史轮查过的门店不能直接引用(旧 id 本轮失效),须本轮重查。
@@ -37,13 +37,18 @@ const DETAIL_DATA = {
37
37
  export const samples: CardSample<ShopDetailCardData>[] = [
38
38
  {
39
39
  label: '门店详情·完整信息',
40
- note: '使用门店导览中的星巴克身份,补充封面、简介、服务、营业时间与双动作',
40
+ note: '使用门店导览中的星巴克身份,补充封面、简介、服务、营业时间与双动作;当前商场已配置导航服务时携带 indoorNavigation(完整 HTTPS 跳转地址,样例用中立域名)',
41
41
  group: '门店详情',
42
- data: DETAIL_DATA,
42
+ data: {
43
+ ...DETAIL_DATA,
44
+ indoorNavigation: {
45
+ url: 'https://indoor-nav.example.cn/universal/#/ar_v4?sdk_version=v4&image_channel=1&third_id=demo-shop-1002',
46
+ },
47
+ } satisfies ShopDetailCardData,
43
48
  },
44
49
  {
45
50
  label: '门店详情·最小信息',
46
- note: '无封面、无门店图、无简介时保持紧凑结构',
51
+ note: '无封面、无门店图、无简介时保持紧凑结构(无 indoorNavigation = 当前商场未配置室内导航,省略字段)',
47
52
  group: '门店详情',
48
53
  data: {
49
54
  merchantId: 'demo-shop-1012',
@@ -13,11 +13,9 @@ import type {
13
13
  TypedBus,
14
14
  PreToolDef,
15
15
  } from '@tbox.cn/app-agent-sdk-server';
16
- import { definePreTool, loadModuleSkills, getRequestContext } from '@tbox.cn/app-agent-sdk-server';
17
- import { Router } from 'express';
18
- import type { Request, Response } from 'express';
19
- import { toMallQueryContext, withMallScopeFromQuery, mallSlot } from '@tbox.cn/app-contracts-mall';
20
- import type { MallEventMap, ShoppingQueryContext } from '@tbox.cn/app-contracts-mall';
16
+ import { definePreTool, loadModuleSkills } from '@tbox.cn/app-agent-sdk-server';
17
+ import { mallSlot } from '@tbox.cn/app-contracts-mall';
18
+ import type { MallEventMap } from '@tbox.cn/app-contracts-mall';
21
19
  import productListMeta from './cards/product-list/meta';
22
20
  import productDetailMeta from './cards/product-detail/meta';
23
21
  import shopListMeta from './cards/shop-list/meta';
@@ -31,14 +29,16 @@ import locationHandoffMeta from './cards/location-handoff/meta';
31
29
  import recommendMerchantsMeta from './cards/recommend-merchants/meta';
32
30
  import { createShoppingGuideTools, extractFloorMentions, extractCategoryMentions, CATEGORY_WORDS, FLOOR_MENTION_RE } from './tools';
33
31
  import { createShoppingGuideHandler } from './handler';
34
- import { resolveShoppingGuidePorts } from './ports';
35
- import { projectShopDetail } from './projections';
32
+ import { createShoppingGuideRouter } from './routes';
36
33
 
37
34
 
38
35
  export { shoppingGuideCards } from './cards';
39
36
  export { createShoppingGuideTools } from './tools';
40
37
  export type { ShoppingGuideTools, ShoppingGuideToolIds } from './tools';
41
38
  export { resolveShoppingGuidePorts } from './ports';
39
+ export { createShoppingGuideRouter } from './routes';
40
+ export { INDOOR_NAVIGATION_SERVICE } from './services/indoor-navigation';
41
+ export type { IndoorNavigationService } from './services/indoor-navigation';
42
42
 
43
43
  /** 模块级 ctx 引用(register 期绑定;execute 内读取——平台包实例分裂免疫:不 import SDK 全局单例) */
44
44
  let moduleCtx: ServerContext | undefined;
@@ -203,38 +203,7 @@ export const serverModule = {
203
203
  // GET /api/m/shopping-guide/shop-detail?shopId=xxx[&mallId=xxx]
204
204
  // 供客户端半屏 sheet 直接拉取完整门店详情数据,绕过 AI 对话链。
205
205
  // mallId 可选:有值时注入 scope(生产),缺省时走本地兜底(开发/演示)。
206
- const router = Router();
207
- router.get('/shop-detail', async (req: Request, res: Response) => {
208
- const shopId = typeof req.query['shopId'] === 'string' ? req.query['shopId'].trim() : '';
209
- if (!shopId) {
210
- res.status(400).json({ error: 'shopId required' });
211
- return;
212
- }
213
- try {
214
- const reqCtx = getRequestContext(req);
215
- if (!reqCtx) {
216
- res.status(401).json({ error: 'unauthorized' });
217
- return;
218
- }
219
- // query 契约键注入(唯一写入口):mallId 在 + miniAppId 双缺时不注入(显式降级)——
220
- // 修复「注入 {miniAppId:'', mallId} 后 parse 静默失败 → throw 500」:
221
- // ports 解析对无 scope 本就 fail-soft(mallId='none' 走本地兜底,guide 本地知识库可独立服务),
222
- // HTTP 数据路由不沿用工具面 strict throw 语义。
223
- const scopedReqCtx = withMallScopeFromQuery(reqCtx, req.query);
224
- const ports = await resolveShoppingGuidePorts(scopedReqCtx, ctx);
225
- const queryCtx: ShoppingQueryContext = toMallQueryContext(scopedReqCtx);
226
- const shop = await ports.shop.getShop(shopId, queryCtx);
227
- if (!shop) {
228
- res.status(404).json({ error: 'not_found' });
229
- return;
230
- }
231
- res.json({ data: projectShopDetail(shop) });
232
- } catch (err) {
233
- const message = err instanceof Error ? err.message : String(err);
234
- console.warn(`[shopping-guide] shop-detail route error shopId=${shopId}: ${message}`);
235
- res.status(500).json({ error: 'internal_error' });
236
- }
237
- });
238
- ctx.routes.register('shopping-guide', router);
206
+ // 路由体 = createShoppingGuideRouter 工厂(routes.ts——可测装配,activity-play 同模式)。
207
+ ctx.routes.register('shopping-guide', createShoppingGuideRouter(ctx));
239
208
  },
240
209
  } satisfies ServerModule;
@@ -0,0 +1,53 @@
1
+ /**
2
+ * module-shopping-guide HTTP 数据路由(平台侧挂 'shopping-guide' 前缀 → /api/m/shopping-guide/*)。
3
+ * GET /shop-detail?shopId=xxx[&mallId=xxx]:供客户端半屏 sheet 直接拉取完整门店详情数据,绕过 AI 对话链。
4
+ * - mallId 可选:有值时注入 scope(生产),缺省时走本地兜底(开发/演示);
5
+ * - 室内导航:与门店查询同一商场范围(同一 reqCtx 解析的 scope);与 get-shop 工具共用
6
+ * withIndoorNavigationTarget 单点——无有效跳转目标省略字段,详情照常返回(增强面 fail-soft)。
7
+ */
8
+ import type { ServerContext } from '@tbox.cn/app-agent-sdk-server';
9
+ import { getRequestContext } from '@tbox.cn/app-agent-sdk-server';
10
+ import { Router } from 'express';
11
+ import type { Request, Response } from 'express';
12
+ import { toMallQueryContext, withMallScopeFromQuery } from '@tbox.cn/app-contracts-mall';
13
+ import { resolveShoppingGuidePorts } from './ports';
14
+ import { projectShopDetail } from './projections';
15
+ import { withIndoorNavigationTarget } from './services/indoor-navigation';
16
+
17
+ export function createShoppingGuideRouter(ctx: ServerContext): Router {
18
+ const router = Router();
19
+ // query 契约键注入(唯一写入口):mallId 在 + miniAppId 双缺时不注入(显式降级)——
20
+ // 修复「注入 {miniAppId:'', mallId} 后 parse 静默失败 → throw 500」:
21
+ // ports 解析对无 scope 本就 fail-soft(mallId='none' 走本地兜底,guide 本地知识库可独立服务),
22
+ // HTTP 数据路由不沿用工具面 strict throw 语义。
23
+ router.get('/shop-detail', async (req: Request, res: Response) => {
24
+ const shopId = typeof req.query['shopId'] === 'string' ? req.query['shopId'].trim() : '';
25
+ if (!shopId) {
26
+ res.status(400).json({ error: 'shopId required' });
27
+ return;
28
+ }
29
+ try {
30
+ const reqCtx = getRequestContext(req);
31
+ if (!reqCtx) {
32
+ res.status(401).json({ error: 'unauthorized' });
33
+ return;
34
+ }
35
+ const scopedReqCtx = withMallScopeFromQuery(reqCtx, req.query);
36
+ const ports = await resolveShoppingGuidePorts(scopedReqCtx, ctx);
37
+ const queryCtx = toMallQueryContext(scopedReqCtx);
38
+ const shop = await ports.shop.getShop(shopId, queryCtx);
39
+ if (!shop) {
40
+ res.status(404).json({ error: 'not_found' });
41
+ return;
42
+ }
43
+ // 室内导航注入(与工具链共用单点):mallId 取门店查询同源 queryCtx 的商场范围
44
+ const data = await withIndoorNavigationTarget(projectShopDetail(shop), ctx, queryCtx.scope.mallId || undefined);
45
+ res.json({ data });
46
+ } catch (err) {
47
+ const message = err instanceof Error ? err.message : String(err);
48
+ console.warn(`[shopping-guide] shop-detail route error shopId=${shopId}: ${message}`);
49
+ res.status(500).json({ error: 'internal_error' });
50
+ }
51
+ });
52
+ return router;
53
+ }
@@ -0,0 +1,60 @@
1
+ /**
2
+ * 室内导航跳转目标解析(两条门店详情链路唯一共用入口)。
3
+ * - 服务接口与服务键 = TIER1 真源(@tbox.cn/app-contracts-mall services/shopping-guide——
4
+ * 实现方(任务 1)与本消费方(任务 2)共同引用,单侧改名结构类型与常量引用双钉死);
5
+ * 经 ctx.services 注册表解析(跨模块 Port + ctx 铁律——本模块零实现依赖,
6
+ * 与 mall-directory 服务同模式);实现归室内导航服务(任务 1),测试实现见 tests。
7
+ * - 导航为增强面(与 guide 槽 fail-soft 同语义):缺商场范围 / 服务未注册 / 服务无有效目标 /
8
+ * 服务异常 / URL 不符契约(indoorNavigationUrlSchema——完整 HTTPS,消费侧复用同一 schema
9
+ * safeParse 同源判定)→ 一律省略字段,门店详情照常返回。
10
+ * - merchantId 原样透传(如 '001' 不做任何归一——爱笔侧以 third_id 匹配门店);
11
+ * URL 由服务生成为完整 HTTPS 地址(含 third_id 业务参数),本层原样透传不拼接。
12
+ */
13
+ import type { ServerContext } from '@tbox.cn/app-agent-sdk-server';
14
+ import { INDOOR_NAVIGATION_SERVICE, indoorNavigationUrlSchema } from '@tbox.cn/app-contracts-mall';
15
+ import type { IndoorNavigationService, ShopDetailCardData } from '@tbox.cn/app-contracts-mall';
16
+
17
+ export { INDOOR_NAVIGATION_SERVICE };
18
+ export type { IndoorNavigationService };
19
+
20
+ /** 解析室内导航服务(未注册 → undefined) */
21
+ export function resolveIndoorNavigationService(ctx: ServerContext): IndoorNavigationService | undefined {
22
+ return ctx.services.resolve?.(INDOOR_NAVIGATION_SERVICE) as IndoorNavigationService | undefined;
23
+ }
24
+
25
+ /**
26
+ * 解析跳转地址(共用核心:get-shop 工具与 /shop-detail HTTP 共用)。
27
+ * mallId 必须与门店查询使用同一商场范围(调用方透传动线上同一 reqCtx 解析出的 scope)。
28
+ */
29
+ export async function resolveIndoorNavigationUrl(
30
+ ctx: ServerContext,
31
+ mallId: string | undefined,
32
+ merchantId: string,
33
+ ): Promise<string | undefined> {
34
+ if (!mallId || !merchantId) return undefined;
35
+ const service = resolveIndoorNavigationService(ctx);
36
+ if (!service) return undefined;
37
+ try {
38
+ const url = await service.resolveJumpUrl(mallId, merchantId);
39
+ // 完整 HTTPS URL 判定与契约字段同源(indoorNavigationUrlSchema.safeParse——
40
+ // 'https://' 残缺/非 https/超长一律视为无有效目标,省略字段)
41
+ return typeof url === 'string' && indoorNavigationUrlSchema.safeParse(url).success ? url : undefined;
42
+ } catch (err) {
43
+ const message = err instanceof Error ? err.message : String(err);
44
+ console.warn(`[shopping-guide] indoor navigation resolve error mallId=${mallId} merchantId=${merchantId}: ${message}`);
45
+ return undefined;
46
+ }
47
+ }
48
+
49
+ /**
50
+ * 门店详情数据装饰(两条链路唯一汇聚点):有有效跳转地址 → 注入 indoorNavigation;
51
+ * 否则原样返回(省略字段)。
52
+ */
53
+ export async function withIndoorNavigationTarget(
54
+ data: ShopDetailCardData,
55
+ ctx: ServerContext,
56
+ mallId: string | undefined,
57
+ ): Promise<ShopDetailCardData> {
58
+ const url = await resolveIndoorNavigationUrl(ctx, mallId, data.merchantId);
59
+ return url ? { ...data, indoorNavigation: { url } } : data;
60
+ }
@@ -6,7 +6,7 @@
6
6
  import { createTool, coerceStringifiedFields, requireToolRequestContext, withCardEmissionHint, internalTool } from '@tbox.cn/app-agent-sdk-server';
7
7
  import { z } from 'zod';
8
8
  import type { ServerContext, ToolExecContextLike } from '@tbox.cn/app-agent-sdk-server';
9
- import { mallSubjectIdOf } from '@tbox.cn/app-contracts-mall';
9
+ import { mallSubjectIdOf, toMallQueryContext } from '@tbox.cn/app-contracts-mall';
10
10
  import type {
11
11
  CommercialCategoryQueryPort,
12
12
  ShoppingPage,
@@ -18,6 +18,7 @@ import type { RequestContext } from '@tbox.cn/app-contracts';
18
18
  import { toShoppingQueryContext, scopeFromMallId } from '../domain/value-objects';
19
19
  import { resolveShoppingGuidePorts, type ShoppingGuidePorts } from '../ports';
20
20
  import { projectShopDetail, projectShopList } from '../projections';
21
+ import { withIndoorNavigationTarget } from '../services/indoor-navigation';
21
22
 
22
23
  export type ShoppingGuideToolIds =
23
24
  // | 'recommend' // 知识库未接入,暂停
@@ -206,12 +207,14 @@ const CATEGORY_SYNONYMS: Readonly<Record<string, readonly string[]>> = {
206
207
  * shopList 精简版:只含总数 + 每个门店的关键信息(名称/位置/类目/营业状态/优惠/电话),
207
208
  * 不含 logo/cover/actions 等前端展示字段——减少模型上下文占用(200 条全量 card data 约 80KB+,精简版约 20KB)。 */
208
209
  const summaries = {
209
- shopList: (d: import('@tbox.cn/app-contracts-mall').ShopListCardData, allItems?: readonly ShopRecord[]): string => {
210
+ shopList: (d: import('@tbox.cn/app-contracts-mall').ShopListCardData, allItems?: readonly ShopRecord[], nextPage?: number): string => {
210
211
  return JSON.stringify({
211
212
  total: d.pageInfo?.total ?? d.items.length,
212
213
  context: d.context,
214
+ ...(nextPage ? { nextPage } : {}),
213
215
  ...(d.summary ? { summary: d.summary } : {}),
214
216
  shops: (allItems ?? []).map((s) => ({
217
+ merchantId: s.merchantId,
215
218
  name: s.name,
216
219
  ...(s.brand ? { brand: s.brand } : {}),
217
220
  location: s.location?.displayText ?? s.location?.unitName,
@@ -299,7 +302,8 @@ export function createShoppingGuideTools(opts: {
299
302
  id: 'search-shops',
300
303
  description:
301
304
  '门店搜索/列表:按品牌词、类目、楼层、楼栋搜索或浏览门店。输出 shop-list(卡片自带类目 Tab)。\n' +
302
- '【零参数 = 探索性全量浏览】以下意图必须不传任何参数直接调用本工具:\n' +
305
+ '追问换一批时保留原筛选,传 excludedMerchantIds 排除已推荐店;不要执行下述首次搜索降级。\n' +
306
+ '【零参数 = 首次探索性全量浏览】以下意图必须不传任何参数直接调用本工具:\n' +
303
307
  ' "逛什么" / "有什么好逛的" / "随便逛逛" / "今天想逛逛" / "商场有什么" / "有哪些门店" / "有什么可逛的" / "帮我找找门店" / "看看有什么"\n' +
304
308
  ' → 返回全量门店列表,卡片自带类目 Tab,用户可在卡片上自行筛选,无需先列类目再追问。\n' +
305
309
  '结果已含门店名、品类、楼栋/楼层/铺位、营业状态、促销信息,无需再调 get-shop 补位置。\n' +
@@ -342,6 +346,8 @@ export function createShoppingGuideTools(opts: {
342
346
  businessCategory: optionalStr('类目编码(来自 pre-tool 上下文 categories[].code);按类目浏览时填写'),
343
347
  floorCode: optionalStr('楼层 ID(来自 pre-tool 上下文 floors[].id);按楼层筛选时填写'),
344
348
  buildingCode: optionalStr('楼栋 ID(来自 pre-tool 上下文 blocks[].id);按楼栋筛选时填写'),
349
+ excludedMerchantIds: coerce(z.array(z.string().min(1))).optional()
350
+ .describe('换一批时传已推荐门店的 merchantId,沿用楼层、楼栋、类目与关键词'),
345
351
  ...pageFields,
346
352
  }),
347
353
  execute: exec(async (ports, _ctx, args: Record<string, unknown>, execCtx: ToolExecContextLike) => {
@@ -366,7 +372,24 @@ export function createShoppingGuideTools(opts: {
366
372
  pageSize,
367
373
  };
368
374
  console.warn(`[search-shops] input keywords=${JSON.stringify(criteria.keywords)} businessCategory=${args.businessCategory ?? ''} floorCode=${args.floorCode ?? ''} buildingCode=${args.buildingCode ?? ''} page=${page}`);
369
- const result = await ports.shop.searchShops(criteria);
375
+ let result = await ports.shop.searchShops(criteria);
376
+ const excluded = new Set((args.excludedMerchantIds ?? []) as string[]);
377
+ if (excluded.size) {
378
+ // Keep provider pagination intact. Skip exhausted pages within a bounded read budget.
379
+ let items = result.items.filter((shop) => !excluded.has(shop.merchantId));
380
+ for (let offset = 1; !items.length && result.hasMore && offset < 3; offset++) {
381
+ result = await ports.shop.searchShops({ ...criteria, page: page + offset });
382
+ items = result.items.filter((shop) => !excluded.has(shop.merchantId));
383
+ }
384
+ const nextPage = result.hasMore ? result.page + 1 : undefined;
385
+ // The provider's total includes previously shown shops. This card represents this batch only.
386
+ const batch = { ...result, items, page: 1, total: items.length, hasMore: false };
387
+ const data = buildShopListCard(batch, q, false);
388
+ if (!items.length && nextPage) data.summary = '本批没有新店,可保留筛选条件继续查询下一页。';
389
+ const summary = summaries.shopList(data, items, nextPage);
390
+ if (!items.length) return { summary };
391
+ return withCards(data, 'shop-list', shopListNote(data, items.length), summary);
392
+ }
370
393
  console.warn(`[search-shops] output total=${result.total} items=${result.items.length} first=${result.items[0]?.name ?? '(empty)'}`);
371
394
  const data = buildShopListCard(result, q, !hasFilter);
372
395
  if (data.items.length === 0) return { summary: summaries.shopList(data) }; // 空结果不出卡
@@ -381,13 +404,22 @@ export function createShoppingGuideTools(opts: {
381
404
  inputSchema: z.object({ shopId: str('门店 ID(来自搜索结果卡)') }),
382
405
  execute: exec(async (ports, _ctx, args: Record<string, unknown>, execCtx: ToolExecContextLike) => {
383
406
  console.warn(`[get-shop] input shopId="${args.shopId}"`);
384
- const shop = await ports.shop.getShop(String(args.shopId), toContext(reqCtxOf(execCtx)));
407
+ // 缺商场范围降级(与 /shop-detail HTTP 同语义):toMallQueryContext 宽松组合单源——
408
+ // 有 scope 时与 toContext 同构;无 scope 空 mallId 兜底(ports 'none' 走本地兜底),
409
+ // 详情照常返回、mallId/导航省略,不再整链失败(strict 语义保留给检索类工具)。
410
+ const queryCtx = toMallQueryContext(reqCtxOf(execCtx));
411
+ const shop = await ports.shop.getShop(String(args.shopId), queryCtx);
385
412
  console.warn(`[get-shop] output found=${!!shop} name="${shop?.name ?? ''}"`);
386
413
  if (!shop) {
387
414
  return { summary: JSON.stringify({ error: 'not_found' }) }; // 无 cards:不出卡
388
415
  }
389
- const shopCtx = toContext(reqCtxOf(execCtx));
390
- const data = projectShopDetail(shop, shopCtx.scope.mallId || undefined, shopCtx.scope.miniAppId || undefined);
416
+ // 室内导航(与 /shop-detail HTTP 共用 withIndoorNavigationTarget 单点):
417
+ // mallId = 门店查询同源 mall 范围;无有效跳转目标省略字段,详情照常返回(增强面 fail-soft)
418
+ const data = await withIndoorNavigationTarget(
419
+ projectShopDetail(shop, queryCtx.scope.mallId || undefined, queryCtx.scope.miniAppId || undefined),
420
+ _ctx,
421
+ queryCtx.scope.mallId || undefined,
422
+ );
391
423
  return withCards(
392
424
  data,
393
425
  'shop-detail',